Repository navigation
fix(cli): snapshot freshness fingerprint for context-refresh --once and charter_context (#440) - #462
Merged
Merged
Conversation
…erved as fresh (#440) context-refresh --once now skips only when the TTL holds and the stored git fingerprint (branch, full HEAD SHA, dirty-file set + per-file size/mtime digest) matches live. Charter's own generated files (.ai/context.snapshot.json, .ai/context.adf, .charter/telemetry/, .charter/repo-intel/, the --output mirror) are excluded so a refresh never invalidates itself. The snapshot gains additive sources.git.head (full SHA), gitFingerprint, stale and staleReasons. charter_context / loadCharterContextSnapshot recompute stale/staleReasons against live git and return them both at top level and on the snapshot object. New module commands/git-fingerprint.ts exports readGitFingerprint() ({ available, root, head, branch, dirty, dirtyFiles, dirtyDigest, checkedLive: true }) for the preflight "Fresh:" line, plus assessSnapshotFreshness() and compareGitFingerprint(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ngerprint (#440) The dirty-set exclusion hardcoded .charter/telemetry/ and .charter/repo-intel/ at the repo root. Run from a subdirectory or with --config, the telemetry append after every command changed the dirty digest, so --once never skipped and charter_context reported a false stale signal right after a refresh. - Exclude <configPath>/telemetry/ and <cwd>/.charter/repo-intel/ as directory prefixes and persist them in gitFingerprint.ignored. - Stale reasons name new, cleaned, or modified-since-snapshot dirty files. - Snapshot file carries staleCheckedLive:false; charter_context sets true. - charter_context fingerprints the repo holding aiDir, not process.cwd(). - Freshness tests get a 20s timeout; add subdirectory, --config, cwd and reason-text cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 28, 2026
Open
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
context-refresh --onceandcharter_contextno longer present a stale snapshot as fresh after a branch switch, a new commit or a working-tree edit.packages/cli/src/commands/git-fingerprint.ts:readGitFingerprint(cwd, { ignore? })returns{ available, root, head (full SHA), branch, dirty, dirtyFiles, dirtyDigest, checkedLive: true }. It runs two local git processes (rev-parse --show-toplevel,status --porcelain=v2 --branch -z --untracked-files=all) and makes no network calls. It took about 350ms on this repo on Windows. The later preflight "Fresh:" line can call it directly.assessSnapshotFreshness(snapshot, cwd)returns{ stale, staleReasons, live }.compareGitFingerprint()returns the reasons the stored and live fingerprints differ.charterRuntimeIgnorePaths(cwd, configPath)returns the directories Charter writes on every run, which depend on cwd and--config:<configPath>/telemetry/and<cwd>/.charter/repo-intel/.Charter's own generated files don't count as dirty. The excluded paths are:
.ai/context.snapshot.jsonand.ai/context.adf, plus the custom--ai-dirand--outputpaths for that refresh.<configPath>/telemetry/and<cwd>/.charter/repo-intel/, excluded as directory prefixes. They stay correct when charter runs from a subdirectory or with a non-default--config..charter/telemetry/and.charter/repo-intel/at the repo root.The runtime paths are stored in the fingerprint's
ignoredlist, so readers apply the same exclusions. A refresh therefore never invalidates itself.The dirty digest covers the status code, path, size and mtime of each file. A second edit to a file that is already dirty is also detected.
--onceskips only if the TTL holds and the stored fingerprint matches the live one.sources.git.head(full SHA),gitFingerprint,stale: false,staleReasons: []andstaleCheckedLive: false.staleCheckedLive: falsemarks the file'sstalevalue as valid only as ofgeneratedAt. An agent reading.ai/context.snapshot.jsondirectly can see the value was not checked against live git.staleandstaleReasons.loadCharterContextSnapshotand thecharter_contextdescription.staleandstaleReasons. The returnedsnapshotobject gets the same values plusstaleCheckedLive: true.aiDir, notprocess.cwd(). This keeps it correct when serve starts elsewhere with an absolute--ai-dir.branch_changed: a -> bhead_changed: abc1234 -> def5678dirty_files_changed: N -> M (new: ...; clean: ...), or(modified since snapshot: ...)when the set is unchanged but a dirty file was edited againno_fingerprint: ...git_unavailable: ...ttl_expired: ..., which applies only when github or repo-intel data is in the snapshot. Git-only snapshots are judged by fingerprint alone.All new fields are additive. Existing keys, shapes and exit codes are unchanged.
Review round 1
--configused to make every--oncerefresh, and right after a refreshcharter_contextreturned a falsedirty_files_changed: 2 -> 2. I confirmed the new tests fail without the fix (2 of 11 fail) and pass with it.staleCheckedLive.aiDir.Verified (local, Windows; Actions is not running)
pnpm install --frozen-lockfile: okpnpm exec tsc --build tsconfig.build.json: okpnpm exec tsc --noEmit -p tsconfig.json: exit 0pnpm exec vitest run packages/cli/src/__tests__/context-refresh-freshness.test.ts: 11/11 pass. The tests cover:--onceskips 3 times in a row, andcharter_contextreports no stale reasons)--config cfgtelemetry is ignored, and a real edit is still caughtpnpm exec vitest run(full suite): 2179 passed, 7 failed, 2 skipped.adf-vendor-legacy"is idempotent" andintegration/bootstrap-reset-cliadf populate re-adds deleted default CONSTRAINTS bullets on every bootstrap #371. Both pass when re-run on their own, and this PR doesn't touch either.node packages/cli/dist/bin.js adf evidence --auto-measure --ci --format text: Verdict: PASS. The only warning is the existingadf_migrate_loc 792/792, which this PR doesn't touch.context-refresh --sources git, thencheckout -b scratch/x HEAD~1, thenecho "// wip" >> a.ts, thencontext-refresh --once --format json. Result:"status":"ok","reason":"refreshed". Before this fix the same steps reportedskipped / fresh_snapshot.--configcases, because the sandbox blocks git outside the worktree. The new tests cover those cases with real git repos in temp dirs, callingcontextRefreshCommandandloadCharterContextSnapshotdirectly.Not done
readGitFingerprint()call.sources.git.dirtyanddirtyFiles(git status --short) are unchanged for contract stability. They can still list Charter's generated files; the newgitFingerprintexcludes them.Closes #440
Part of #437
🤖 Generated with Claude Code