Repository navigation
Conversation
…xt#1312) Closes CodeGraphContext#1312. Adds `cgc snapshot save [--name]`, `cgc snapshot list` and `cgc diff [--against]`, so a graph state can be captured before a change and compared afterwards instead of re-querying by hand. A snapshot is a lightweight JSON manifest (`~/.codegraphcontext/snapshots/<name>.json`, `format: cgc-snapshot`, `format_version: 1`), not a `.cgc` bundle: a diff needs identities and content digests, not the payload, so the manifest stays small enough to keep around. Identities come from `CGCBundle._PK_MAP`/`_UID_PARTS` — the same primary keys bundle export uses, so both documents agree on what a node is — and digests strip volatile properties (`Repository.indexed_at`), so two snapshots of untouched code compare equal. Because a node `uid` embeds `line_number`, typing a line above a function re-keys it; a naive set diff would report that as one deletion plus one identical addition and bury everything real under churn. `graph_snapshot` therefore pairs unambiguous matches by a name/path/ownership signature (a shifted node reports as `moved`, not as churn), leaves genuinely ambiguous pairs alone rather than guessing, folds an edge retarget into one `target changed` row only when the new target already existed in the base graph, and qualifies owner-scoped names (`pay.amount`) so same-named parameters stay distinguishable. The product goes to stdout — `cgc diff --json > changes.json` parses — with init chatter and errors on stderr, following the CodeGraphContext#1725 split. Exit codes: 0 no differences (or no gate requested), 1 differences under `--fail-on-changes` and snapshot/initialisation errors, 2 bad usage. Human output is ASCII so redirected output survives a non-UTF-8 console. Scoped to the CLI layer: `core/graph_snapshot.py`, `cli/snapshot_commands.py` and the Typer wiring in `cli/main.py`. Covered by `tests/unit/core/test_graph_snapshot.py`, `tests/integration/test_snapshot_diff_cli.py`, and three new entries in the canonical command matrix.
|
@yashraj4 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
Shashankss1205
left a comment
Collaborator
There was a problem hiding this comment.
Substantial snapshot-diff CLI feature. Local octopus integration with other drafts fails in parity verification code despite stale mergeability metadata. Rebase individually, validate snapshot path/graph semantics, then review when marked ready.
This branch has not been deployed
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.
Closes #1312.
Implements
cgc snapshot save [--name],cgc snapshot listandcgc diff [--against] [--json] [--limit] [--fail-on-changes], so a graph state can be captured before a change and compared afterwards instead of re-querying by hand.Format decision, JSON schema and exit codes were posted in the issue first, as requested: #1312 (comment)
Snapshot format
A snapshot is a lightweight JSON manifest, not a
.cgcbundle, stored at~/.codegraphcontext/snapshots/<name>.json(format: cgc-snapshot,format_version: 1, checked on read like bundle files):cgc diffneeds identity + content digest, not the payload, so manifests stay small enough to keep around (14-node probe repo → ~22 KB), and reading one never mutates the database the way loading a bundle would.idis the graph's own primary key (CGCBundle._PK_MAP/_UID_PARTS, includinguidsynthesis for backends that do not persist it), so snapshots agree withcgc bundle exportand across Neo4j/Kùzu.digeststrips volatile properties (Repository.indexed_at), so untouched code diffs to nothing.^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$, existing names need--force.JSON documents and exit codes
cgc diff --json→cgc-diffv1:base{},current{},summary{nodes, edges, total},nodes{added, removed, changed},edges{added, removed, changed};changedrows carryreason(properties|moved|target),before/afterandchanged_properties[].cgc snapshot save --json→cgc-snapshot-savereceipt (summary, not the manifest);cgc snapshot list --json→cgc-snapshot-list(unreadable files become anerrorentry instead of hiding the rest).--fail-on-changesor a snapshot/initialisation error, 2 bad usage (invalid name, negative--limit).Streams
Product on stdout —
cgc diff --json > changes.jsonparses — init chatter and errors on stderr, following the #1725 split. Human output is ASCII only (+ - ~,->,|), because a non-ASCII glyph raisesUnicodeEncodeErroron a cp1252 console the moment output is redirected.Diff semantics
uidembedsline_number, so typing a line above a function re-keys it; a naive set diff would report one deletion plus one identical addition. Unambiguous matches pair on alabel + name + path + ownership chainsignature and report as~ … (moved, …); ambiguous pairs (two same-named functions in one file) stay add/remove rather than being guessed.~ CALLS a -> b (target changed)row only when exactly one removed and one added edge share source/type and the new target already existed in the base graph, so a file that gainedrefundwhile losinglegacy_checkoutdoes not claim itsCONTAINSedge was retargeted.pay.amount), so same-named parameters stay distinguishable — via ownership edges only, so aCALLSedge never re-labels its callee.Scope
CLI layer only:
core/graph_snapshot.py(format/diff/render logic),cli/snapshot_commands.py(paths, orchestration,print()to stdout), Typer wiring incli/main.py. No MCP tool, UI, database or bundle changes.Tests
tests/unit/core/test_graph_snapshot.py— identity, pairing/ambiguity, retarget rules, documents, ASCII rendering, limit truncation.tests/integration/test_snapshot_diff_cli.py— index → save → edit → re-index → diff, JSON parse, exit codes, stdout/stderr split (list-argv subprocesses, so it runs on Windows too).tests/integration/cli/test_cli_commands.py— three new canonical-matrix entries, with the fake session answering the snapshot queries, so the inventory meta-test covers the new commands.ruffclean on all new/changed files;tests/unitmatches the pre-existing baseline (8 known failures, verified againsta864a9f).