MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / handleStatus

Method handleStatus

src/mcp/tools.ts:8731–8889  ·  view source on GitHub ↗

* Handle codegraph_status

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

8729 * Handle codegraph_status
8730 */
8731 private async handleStatus(args: Record<string, unknown>): Promise<ToolResult> {
8732 let cg = this.getCodeGraph(args.projectPath as string | undefined);
8733 // Same trick as withStalenessNotice — when an explicit projectPath
8734 // resolves to the same project as the default session cg, prefer the
8735 // default so getPendingFiles() (only populated by the default's watcher)
8736 // is non-empty when there are pending edits.
8737 if (this.cg && cg !== this.cg) {
8738 try {
8739 if (resolvePath(this.cg.getProjectRoot()) === resolvePath(cg.getProjectRoot())) {
8740 cg = this.cg;
8741 }
8742 } catch { /* closed instance — leave as is */ }
8743 }
8744 const stats = cg.getStats();
8745 const buildInfo = cg.getIndexBuildInfo();
8746 const reindexRecommended = cg.isIndexStale();
8747 const indexBuildLabel = cg.getLastIndexedAt() == null
8748 ? 'not indexed yet'
8749 : formatIndexBuildVersion(buildInfo);
8750
8751 // Warn when this index actually belongs to a different git working tree
8752 // (e.g. the server resolved up from a nested worktree to the main checkout).
8753 // Queries then reflect that tree's branch, not the worktree being edited.
8754 // status shows the verbose, multi-line form; the read tools get the compact
8755 // one-liner via withWorktreeNotice. Both share the cached detection, and
8756 // both are worded for the agent: the user can index the worktree, the
8757 // agent doesn't.
8758 const mismatch = this.worktreeMismatchFor(args.projectPath as string | undefined);
8759
8760 const lines: string[] = [
8761 '**CodeGraph Status**',
8762 '',
8763 ];
8764 if (mismatch) {
8765 lines.push(`> ⚠ ${worktreeMismatchWarning(mismatch, 'agent').replace(/\n/g, '\n> ')}`, '');
8766 }
8767 lines.push(
8768 `**Files indexed:** ${stats.fileCount}`,
8769 `**Total nodes:** ${stats.nodeCount}`,
8770 `**Total edges:** ${stats.edgeCount}`,
8771 `**Database size:** ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`,
8772 );
8773
8774 // Exact CLI-parity change counts are measured on a worker: Git or the
8775 // filesystem fallback can stall on a large/busy checkout, but status must
8776 // not block the shared daemon's transport (#1959). Unknown is never zero.
8777 const lastIndexedAt = cg.getLastIndexedAt();
8778 const changes = await measurePendingChanges(cg.getProjectRoot());
8779 lines.push(
8780 `**Latest file indexed:** ${lastIndexedAt == null ? 'never' : new Date(lastIndexedAt).toISOString()}`,
8781 changes
8782 ? `**Changes since index:** ${changes.added} added, ${changes.modified} modified, ${changes.removed} removed`
8783 : '**Changes since index:** unknown (measurement timed out or failed; do not assume the index is current)',
8784 );
8785
8786 // Surface the active SQLite backend (node:sqlite, Node's built-in real
8787 // SQLite — full WAL + FTS5, no native build).
8788 lines.push(`**Backend:** node:sqlite (Node built-in) — full WAL + FTS5`);

Callers 1

executeMethod · 0.95

Calls 15

getCodeGraphMethod · 0.95
worktreeMismatchForMethod · 0.95
textResultMethod · 0.95
formatIndexBuildVersionFunction · 0.90
worktreeMismatchWarningFunction · 0.90
measurePendingChangesFunction · 0.90
formatRunningVersionFunction · 0.90
getUpdateNoticeFunction · 0.90
getIndexBuildInfoMethod · 0.80
isIndexStaleMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected