( source: string, pluginPath: string, )
| 620 | * Check if an MCPB source has changed and needs re-extraction |
| 621 | */ |
| 622 | export async function checkMcpbChanged( |
| 623 | source: string, |
| 624 | pluginPath: string, |
| 625 | ): Promise<boolean> { |
| 626 | const fs = getFsImplementation() |
| 627 | const cacheDir = getMcpbCacheDir(pluginPath) |
| 628 | const metadata = await loadCacheMetadata(cacheDir, source) |
| 629 | |
| 630 | if (!metadata) { |
| 631 | // No cache metadata, needs loading |
| 632 | return true |
| 633 | } |
| 634 | |
| 635 | // Check if extraction directory still exists |
| 636 | try { |
| 637 | await fs.stat(metadata.extractedPath) |
| 638 | } catch (error) { |
| 639 | const code = getErrnoCode(error) |
| 640 | if (code === 'ENOENT') { |
| 641 | logForDebugging(`MCPB extraction path missing: ${metadata.extractedPath}`) |
| 642 | } else { |
| 643 | logForDebugging( |
| 644 | `MCPB extraction path inaccessible: ${metadata.extractedPath}: ${error}`, |
| 645 | { level: 'error' }, |
| 646 | ) |
| 647 | } |
| 648 | return true |
| 649 | } |
| 650 | |
| 651 | // For local files, check mtime |
| 652 | if (!isUrl(source)) { |
| 653 | const localPath = join(pluginPath, source) |
| 654 | let stats |
| 655 | try { |
| 656 | stats = await fs.stat(localPath) |
| 657 | } catch (error) { |
| 658 | const code = getErrnoCode(error) |
| 659 | if (code === 'ENOENT') { |
| 660 | logForDebugging(`MCPB source file missing: ${localPath}`) |
| 661 | } else { |
| 662 | logForDebugging( |
| 663 | `MCPB source file inaccessible: ${localPath}: ${error}`, |
| 664 | { level: 'error' }, |
| 665 | ) |
| 666 | } |
| 667 | return true |
| 668 | } |
| 669 | |
| 670 | const cachedTime = new Date(metadata.cachedAt).getTime() |
| 671 | // Floor to match the ms precision of cachedAt (ISO string). Sub-ms |
| 672 | // precision on mtimeMs would make a freshly-cached file appear "newer" |
| 673 | // than its own cache timestamp when both happen in the same millisecond. |
| 674 | const fileTime = Math.floor(stats.mtimeMs) |
| 675 | |
| 676 | if (fileTime > cachedTime) { |
| 677 | logForDebugging( |
| 678 | `MCPB file modified: ${new Date(fileTime)} > ${new Date(cachedTime)}`, |
| 679 | ) |
no test coverage detected