feat(cli): add version, indexPath, lastIndexed to status --json (#329)
Adds `version`, `indexPath`, and an ISO `lastIndexed` to `codegraph status --json`, plus a `CodeGraph.getLastIndexedAt()` library method. `agentCount` dropped (no clear consumer). Reworked from contributor PRs #333 and #480. Co-Authored-By: Javier Gómez <199902626+12122J@users.noreply.github.com> Co-Authored-By: Ran <8403607+eddieran@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Javier Gómez
Ran
Claude Opus 4.8
parent
ddb1a8f72d
commit
7b62356f53
+11
-1
@@ -676,7 +676,13 @@ program
|
||||
try {
|
||||
if (!isInitialized(projectPath)) {
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify({ initialized: false, projectPath }));
|
||||
console.log(JSON.stringify({
|
||||
initialized: false,
|
||||
version: packageJson.version,
|
||||
projectPath,
|
||||
indexPath: getCodeGraphDir(projectPath),
|
||||
lastIndexed: null,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
console.log(chalk.bold('\nCodeGraph Status\n'));
|
||||
@@ -695,9 +701,13 @@ program
|
||||
|
||||
// JSON output mode
|
||||
if (options.json) {
|
||||
const lastIndexedMs = cg.getLastIndexedAt();
|
||||
console.log(JSON.stringify({
|
||||
initialized: true,
|
||||
version: packageJson.version,
|
||||
projectPath,
|
||||
indexPath: getCodeGraphDir(projectPath),
|
||||
lastIndexed: lastIndexedMs != null ? new Date(lastIndexedMs).toISOString() : null,
|
||||
fileCount: stats.fileCount,
|
||||
nodeCount: stats.nodeCount,
|
||||
edgeCount: stats.edgeCount,
|
||||
|
||||
@@ -1421,6 +1421,17 @@ export class QueryBuilder {
|
||||
return rows.map(rowToFileRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Most recent index timestamp (ms since epoch) across all tracked files, or
|
||||
* null when nothing is indexed yet. One indexed aggregate, no per-row scan. (#329)
|
||||
*/
|
||||
getLastIndexedAt(): number | null {
|
||||
const row = this.db
|
||||
.prepare('SELECT MAX(indexed_at) AS last FROM files')
|
||||
.get() as { last: number | null } | undefined;
|
||||
return row?.last ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files that need re-indexing (hash changed)
|
||||
*/
|
||||
|
||||
@@ -576,6 +576,15 @@ export class CodeGraph {
|
||||
return this.orchestrator.getChangedFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Most recent index timestamp (ms since epoch) across all tracked files, or
|
||||
* null when nothing is indexed yet. Lets library consumers check index
|
||||
* freshness without shelling out to `codegraph status --json`. (#329)
|
||||
*/
|
||||
getLastIndexedAt(): number | null {
|
||||
return this.queries.getLastIndexedAt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract nodes and edges from source code (without storing)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user