feat(cli): surface codegraphVersion + lastIndexedAt in status --json (#329)#480
Open
eddieran wants to merge 1 commit into
Open
feat(cli): surface codegraphVersion + lastIndexedAt in status --json (#329)#480eddieran wants to merge 1 commit into
status --json (#329)#480eddieran wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #329.
codegraph status --jsonalready 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 secondcodegraph --versionor peek at the SQLite file directly to assert freshness. This PR adds them.New JSON fields
codegraphVersionstringpackage.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.lastIndexedAtnumber | nullMAX(indexed_at)from thefilestable (single indexed aggregate, no per-file scan).nullwhen no files are tracked.lastIndexedAtIsostring | nullExample (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 newQueryBuilder.getLastIndexedAt()that runs one indexedSELECT MAX(indexed_at) FROM files. The existingGraphStatsshape 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.tscovers four cases:getLastIndexedAt()returnsnullon a fresh project (noindexAllyet).getLastIndexedAt()returns a timestamp inside theDate.now()window the test spent inindexAll.codegraph status --jsonon an uninitialized project includescodegraphVersion(andinitialized: false).codegraph status --jsonon an indexed project includescodegraphVersion,lastIndexedAt(within a 5-minute window), and alastIndexedAtIsothat round-trips back tolastIndexedAt.The CLI-level tests exec the built binary (
dist/bin/codegraph.js) end-to-end throughprocess.execPathso the JSON shape survives future refactors of the underlying plumbing.Full suite:
(+4 new tests over
main; no regressions.)Notes for review
versionfield is namedcodegraphVersionrather thanversionto leave room for a futureschemaVersionfield if/when DB-format pins matter (schema_versionsalready tracks this internally). Happy to rename if you'd prefer justversion.lastIndexedAt(raw ms) andlastIndexedAtIsoare 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.