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

Method handleStatus

src/mcp/tools.ts:8980–9138  ·  view source on GitHub ↗

* Handle codegraph_status

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

8978 * Handle codegraph_status
8979 */
8980 private async handleStatus(args: Record<string, unknown>): Promise<ToolResult> {
8981 let cg = this.getCodeGraph(args.projectPath as string | undefined);
8982 // Same trick as withStalenessNotice — when an explicit projectPath
8983 // resolves to the same project as the default session cg, prefer the
8984 // default so getPendingFiles() (only populated by the default's watcher)
8985 // is non-empty when there are pending edits.
8986 if (this.cg && cg !== this.cg) {
8987 try {
8988 if (resolvePath(this.cg.getProjectRoot()) === resolvePath(cg.getProjectRoot())) {
8989 cg = this.cg;
8990 }
8991 } catch { /* closed instance — leave as is */ }
8992 }
8993 const stats = cg.getStats();
8994 const buildInfo = cg.getIndexBuildInfo();
8995 const reindexRecommended = cg.isIndexStale();
8996 const indexBuildLabel = cg.getLastIndexedAt() == null
8997 ? 'not indexed yet'
8998 : formatIndexBuildVersion(buildInfo);
8999
9000 // Warn when this index actually belongs to a different git working tree
9001 // (e.g. the server resolved up from a nested worktree to the main checkout).
9002 // Queries then reflect that tree's branch, not the worktree being edited.
9003 // status shows the verbose, multi-line form; the read tools get the compact
9004 // one-liner via withWorktreeNotice. Both share the cached detection, and
9005 // both are worded for the agent: the user can index the worktree, the
9006 // agent doesn't.
9007 const mismatch = this.worktreeMismatchFor(args.projectPath as string | undefined);
9008
9009 const lines: string[] = [
9010 '**CodeGraph Status**',
9011 '',
9012 ];
9013 if (mismatch) {
9014 lines.push(`> ⚠ ${worktreeMismatchWarning(mismatch, 'agent').replace(/\n/g, '\n> ')}`, '');
9015 }
9016 lines.push(
9017 `**Files indexed:** ${stats.fileCount}`,
9018 `**Total nodes:** ${stats.nodeCount}`,
9019 `**Total edges:** ${stats.edgeCount}`,
9020 `**Database size:** ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`,
9021 );
9022
9023 // Exact CLI-parity change counts are measured on a worker: Git or the
9024 // filesystem fallback can stall on a large/busy checkout, but status must
9025 // not block the shared daemon's transport (#1959). Unknown is never zero.
9026 const lastIndexedAt = cg.getLastIndexedAt();
9027 const changes = await measurePendingChanges(cg.getProjectRoot());
9028 lines.push(
9029 `**Latest file indexed:** ${lastIndexedAt == null ? 'never' : new Date(lastIndexedAt).toISOString()}`,
9030 changes
9031 ? `**Changes since index:** ${changes.added} added, ${changes.modified} modified, ${changes.removed} removed`
9032 : '**Changes since index:** unknown (measurement timed out or failed; do not assume the index is current)',
9033 );
9034
9035 // Surface the active SQLite backend (node:sqlite, Node's built-in real
9036 // SQLite — full WAL + FTS5, no native build).
9037 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