* Handle codegraph_status
(args: Record<string, unknown>)
| 8556 | * Handle codegraph_status |
| 8557 | */ |
| 8558 | private async handleStatus(args: Record<string, unknown>): Promise<ToolResult> { |
| 8559 | let cg = this.getCodeGraph(args.projectPath as string | undefined); |
| 8560 | // Same trick as withStalenessNotice — when an explicit projectPath |
| 8561 | // resolves to the same project as the default session cg, prefer the |
| 8562 | // default so getPendingFiles() (only populated by the default's watcher) |
| 8563 | // is non-empty when there are pending edits. |
| 8564 | if (this.cg && cg !== this.cg) { |
| 8565 | try { |
| 8566 | if (resolvePath(this.cg.getProjectRoot()) === resolvePath(cg.getProjectRoot())) { |
| 8567 | cg = this.cg; |
| 8568 | } |
| 8569 | } catch { /* closed instance — leave as is */ } |
| 8570 | } |
| 8571 | const stats = cg.getStats(); |
| 8572 | const buildInfo = cg.getIndexBuildInfo(); |
| 8573 | const reindexRecommended = cg.isIndexStale(); |
| 8574 | const indexBuildLabel = cg.getLastIndexedAt() == null |
| 8575 | ? 'not indexed yet' |
| 8576 | : formatIndexBuildVersion(buildInfo); |
| 8577 | |
| 8578 | // Warn when this index actually belongs to a different git working tree |
| 8579 | // (e.g. the server resolved up from a nested worktree to the main checkout). |
| 8580 | // Queries then reflect that tree's branch, not the worktree being edited. |
| 8581 | // status shows the verbose, multi-line form; the read tools get the compact |
| 8582 | // one-liner via withWorktreeNotice. Both share the cached detection, and |
| 8583 | // both are worded for the agent: the user can index the worktree, the |
| 8584 | // agent doesn't. |
| 8585 | const mismatch = this.worktreeMismatchFor(args.projectPath as string | undefined); |
| 8586 | |
| 8587 | const lines: string[] = [ |
| 8588 | '**CodeGraph Status**', |
| 8589 | '', |
| 8590 | ]; |
| 8591 | if (mismatch) { |
| 8592 | lines.push(`> ⚠ ${worktreeMismatchWarning(mismatch, 'agent').replace(/\n/g, '\n> ')}`, ''); |
| 8593 | } |
| 8594 | lines.push( |
| 8595 | `**Files indexed:** ${stats.fileCount}`, |
| 8596 | `**Total nodes:** ${stats.nodeCount}`, |
| 8597 | `**Total edges:** ${stats.edgeCount}`, |
| 8598 | `**Database size:** ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`, |
| 8599 | ); |
| 8600 | |
| 8601 | // Exact CLI-parity change counts are measured on a worker: Git or the |
| 8602 | // filesystem fallback can stall on a large/busy checkout, but status must |
| 8603 | // not block the shared daemon's transport (#1959). Unknown is never zero. |
| 8604 | const lastIndexedAt = cg.getLastIndexedAt(); |
| 8605 | const changes = await measurePendingChanges(cg.getProjectRoot()); |
| 8606 | lines.push( |
| 8607 | `**Latest file indexed:** ${lastIndexedAt == null ? 'never' : new Date(lastIndexedAt).toISOString()}`, |
| 8608 | changes |
| 8609 | ? `**Changes since index:** ${changes.added} added, ${changes.modified} modified, ${changes.removed} removed` |
| 8610 | : '**Changes since index:** unknown (measurement timed out or failed; do not assume the index is current)', |
| 8611 | ); |
| 8612 | |
| 8613 | // Surface the active SQLite backend (node:sqlite, Node's built-in real |
| 8614 | // SQLite — full WAL + FTS5, no native build). |
| 8615 | lines.push(`**Backend:** node:sqlite (Node built-in) — full WAL + FTS5`); |
no test coverage detected