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

Method handleStatus

src/mcp/tools.ts:8705–8863  ·  view source on GitHub ↗

* Handle codegraph_status

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

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