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

Method handleStatus

src/mcp/tools.ts:9017–9175  ·  view source on GitHub ↗

* Handle codegraph_status

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

9015 * Handle codegraph_status
9016 */
9017 private async handleStatus(args: Record<string, unknown>): Promise<ToolResult> {
9018 let cg = this.getCodeGraph(args.projectPath as string | undefined);
9019 // Same trick as withStalenessNotice — when an explicit projectPath
9020 // resolves to the same project as the default session cg, prefer the
9021 // default so getPendingFiles() (only populated by the default's watcher)
9022 // is non-empty when there are pending edits.
9023 if (this.cg && cg !== this.cg) {
9024 try {
9025 if (resolvePath(this.cg.getProjectRoot()) === resolvePath(cg.getProjectRoot())) {
9026 cg = this.cg;
9027 }
9028 } catch { /* closed instance — leave as is */ }
9029 }
9030 const stats = cg.getStats();
9031 const buildInfo = cg.getIndexBuildInfo();
9032 const reindexRecommended = cg.isIndexStale();
9033 const indexBuildLabel = cg.getLastIndexedAt() == null
9034 ? 'not indexed yet'
9035 : formatIndexBuildVersion(buildInfo);
9036
9037 // Warn when this index actually belongs to a different git working tree
9038 // (e.g. the server resolved up from a nested worktree to the main checkout).
9039 // Queries then reflect that tree's branch, not the worktree being edited.
9040 // status shows the verbose, multi-line form; the read tools get the compact
9041 // one-liner via withWorktreeNotice. Both share the cached detection, and
9042 // both are worded for the agent: the user can index the worktree, the
9043 // agent doesn't.
9044 const mismatch = this.worktreeMismatchFor(args.projectPath as string | undefined);
9045
9046 const lines: string[] = [
9047 '**CodeGraph Status**',
9048 '',
9049 ];
9050 if (mismatch) {
9051 lines.push(`> ⚠ ${worktreeMismatchWarning(mismatch, 'agent').replace(/\n/g, '\n> ')}`, '');
9052 }
9053 lines.push(
9054 `**Files indexed:** ${stats.fileCount}`,
9055 `**Total nodes:** ${stats.nodeCount}`,
9056 `**Total edges:** ${stats.edgeCount}`,
9057 `**Database size:** ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`,
9058 );
9059
9060 // Exact CLI-parity change counts are measured on a worker: Git or the
9061 // filesystem fallback can stall on a large/busy checkout, but status must
9062 // not block the shared daemon's transport (#1959). Unknown is never zero.
9063 const lastIndexedAt = cg.getLastIndexedAt();
9064 const changes = await measurePendingChanges(cg.getProjectRoot());
9065 lines.push(
9066 `**Latest file indexed:** ${lastIndexedAt == null ? 'never' : new Date(lastIndexedAt).toISOString()}`,
9067 changes
9068 ? `**Changes since index:** ${changes.added} added, ${changes.modified} modified, ${changes.removed} removed`
9069 : '**Changes since index:** unknown (measurement timed out or failed; do not assume the index is current)',
9070 );
9071
9072 // Surface the active SQLite backend (node:sqlite, Node's built-in real
9073 // SQLite — full WAL + FTS5, no native build).
9074 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