Skip to content

feat(cli): surface codegraphVersion + lastIndexedAt in status --json (#329)#480

Open
eddieran wants to merge 1 commit into
colbymchenry:mainfrom
eddieran:feat/status-json-version-and-last-indexed
Open

feat(cli): surface codegraphVersion + lastIndexedAt in status --json (#329)#480
eddieran wants to merge 1 commit into
colbymchenry:mainfrom
eddieran:feat/status-json-version-and-last-indexed

Conversation

@eddieran
Copy link
Copy Markdown
Contributor

Summary

Closes #329.

codegraph status --json already shipped a rich JSON payload, but two fields the issue called out — a CLI version pin and an actual last-indexed timestamp — were missing, forcing CI consumers to either shell out to a second codegraph --version or peek at the SQLite file directly to assert freshness. This PR adds them.

New JSON fields

Field Type Notes
codegraphVersion string Read from package.json. Present in both the initialized and not-initialized branches so CI can verify the running CLI matches what it expects regardless of project state.
lastIndexedAt number | null ms-since-epoch of MAX(indexed_at) from the files table (single indexed aggregate, no per-file scan). null when no files are tracked.
lastIndexedAtIso string | null ISO-8601 mirror of the same instant, for human/log consumers.

Example (this repo):

{
  "codegraphVersion": "0.9.6",
  "initialized": true,
  "projectPath": "/Users/.../codegraph",
  "fileCount": 192,
  "nodeCount": 2964,
  "edgeCount": 7935,
  "lastIndexedAt": 1779841639913,
  "lastIndexedAtIso": "2026-05-27T00:27:19.913Z",
  ...
}

Library-level API

A matching public method, CodeGraph.getLastIndexedAt(): number | null, lets library consumers do the same freshness check without spawning the CLI. It delegates to a new QueryBuilder.getLastIndexedAt() that runs one indexed SELECT MAX(indexed_at) FROM files. The existing GraphStats shape is deliberately untouched — adding a sibling method is cheaper and avoids the breaking-change footprint of a typed-field addition.

Test plan

New __tests__/status-json.test.ts covers four cases:

  • getLastIndexedAt() returns null on a fresh project (no indexAll yet).
  • getLastIndexedAt() returns a timestamp inside the Date.now() window the test spent in indexAll.
  • codegraph status --json on an uninitialized project includes codegraphVersion (and initialized: false).
  • codegraph status --json on an indexed project includes codegraphVersion, lastIndexedAt (within a 5-minute window), and a lastIndexedAtIso that round-trips back to lastIndexedAt.

The CLI-level tests exec the built binary (dist/bin/codegraph.js) end-to-end through process.execPath so the JSON shape survives future refactors of the underlying plumbing.

Full suite:

Test Files  49 passed (49)
     Tests  1036 passed | 2 skipped (1038)

(+4 new tests over main; no regressions.)

Notes for review

  • The version field is named codegraphVersion rather than version to leave room for a future schemaVersion field if/when DB-format pins matter (schema_versions already tracks this internally). Happy to rename if you'd prefer just version.
  • Both lastIndexedAt (raw ms) and lastIndexedAtIso are emitted because the issue suggested ISO but the rest of the JSON payload uses raw numeric values (dbSizeBytes, counts). Easy to drop either if you'd prefer just one.

colbymchenry#329)

CI scripts that parse `codegraph status --json` can now assert both the
running CLI version and index freshness without an extra `codegraph
--version` call or a SQLite shell-out:

  * codegraphVersion — read from package.json, included in both the
    initialized and not-initialized branches.
  * lastIndexedAt — ms-since-epoch from `MAX(indexed_at) FROM files`,
    or null when the project tracks no files.
  * lastIndexedAtIso — the ISO-8601 mirror, for human/log consumers.

Library consumers get the same value via a new public method
`CodeGraph.getLastIndexedAt(): number | null`, kept narrow so it can be
implemented as a single indexed aggregate query without touching the
existing GraphStats shape.

Closes colbymchenry#329.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --json flag to codegraph status for CI/scripting

1 participant