Repository navigation
fix(adf): stop tidy ingesting compiled vendor output - #319
Conversation
POINTER_MARKERS answered two incompatible questions with one list, and COMPILE_BANNER_MARKER was a member of it. `adf compile --write` renders the whole ruleset into CLAUDE.md behind that banner, so `adf tidy` read the artifact as a thin pointer and treated the compiled copy of .ai/ as content added beyond the pointer — folding .ai/ back into itself and resurrecting deliberately deleted rules. Split the constant: - POINTER_MARKERS — "is this a thin pointer?" (shape). Excludes the banner. Used only by adf-tidy. - CHARTER_OWNED_MARKERS — "did Charter author this?" (ownership). Banner plus every pointer marker. Used by adf-compile's overwrite guard, adf-migrate, bootstrap, doctor and score, all of which keep their current behavior. tidy now skips a compiled file and says so, naming `adf compile --write` as the way to regenerate it, rather than skipping in silence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The comment cited "#295's sibling case", which does not exist — both #295 entries are about pointer stubs, and the banner-only check predates #295. State what narrowing the guard would actually do, and name the test that pins it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
stackbilt-admin
left a comment
There was a problem hiding this comment.
APPROVED
Reviewed at 2c1186e (= PR head = local HEAD); base compared against origin/main @ ba616de (local main confirmed identical, not stale). All findings below are NITs; none block.
The central claim is proven: only adf tidy changes behavior
Ordered set-equality holds. Extracted both arrays programmatically:
main:packages/cli/src/commands/adf.tsPOINTER_MARKERS= 8 elements, index 0COMPILE_BANNER_MARKER+ 7 string literals.- branch
CHARTER_OWNED_MARKERS=[COMPILE_BANNER_MARKER, ...POINTER_MARKERS]expands to the same 8 elements in the same order.JSON.stringifycomparison:true.
Order is moot anyway. Every consumer of either list is .some(marker => ...) (adf-compile.ts:249, adf-migrate.ts:220, doctor.ts:313, doctor.ts:402, bootstrap.ts:1076, bootstrap.ts:1403, adf-tidy.ts:268, adf-tidy.ts:366) or a full-array for...of + replaceAll (score.ts:1085). No .findIndex, no [0], no first-match dependence anywhere in the repo. Grepped POINTER_MARKERS|CHARTER_OWNED_MARKERS|COMPILE_BANNER_MARKER across all .ts/.js/.mjs/.sh outside node_modules/dist — no other consumer exists.
Relocation table verified independently, all nine sites:
| site | question | list | equivalent to main? |
|---|---|---|---|
adf-compile.ts:249 |
ownership (overwrite guard, #295) | CHARTER_OWNED_MARKERS |
yes |
adf-tidy.ts:268 |
shape (the fix) | POINTER_MARKERS narrowed |
no — this is the intended change |
adf-tidy.ts:366 |
shape (preamble skip) | POINTER_MARKERS narrowed |
yes, unreachable for compiled files — see below |
adf-migrate.ts:220 |
ownership (don't ingest) | CHARTER_OWNED_MARKERS |
yes |
doctor.ts:313 |
ownership (don't advise migrate) | CHARTER_OWNED_MARKERS |
yes |
doctor.ts:402 |
boilerplate filter | CHARTER_OWNED_MARKERS |
yes |
score.ts:1085 |
boilerplate filter | CHARTER_OWNED_MARKERS |
yes |
bootstrap.ts:1076 |
ownership (migrate source selection) | CHARTER_OWNED_MARKERS |
yes |
bootstrap.ts:1403 |
ownership — ruled below | CHARTER_OWNED_MARKERS |
yes |
adf-tidy.ts:366 call-graph claim confirmed. extractBeyondPointer has exactly one caller: adf-tidy.ts:273, inside analyzeVendorFile, after the compiled early-return at adf-tidy.ts:263. The only other textual hit is a comment at adf-tidy.ts:568. A compiled file can never reach the preamble-skip loop, so the banner line never stops being skipped as preamble. Claim holds.
bootstrap.ts:1403 isAlreadyThinPointer — ruled: ownership is correct, the name is wrong. Its sole caller is bootstrap.ts:1021, the else if (!isAlreadyThinPointer(pointerPath)) arm of a chain where both remaining branches skip writing the pointer. The list only selects which warning text is emitted:
CHARTER_OWNED_MARKERS(this PR, == main) →"CLAUDE.md already exists; skipping (use --force to overwrite)".- narrowed
POINTER_MARKERS→"CLAUDE.md has custom content; skipping pointer (run 'charter adf migrate' first…)"— which would be actively wrong advice, becauseadf-migrate.ts:220correctly refuses to ingest a compile artifact. The user would be sent to a command that no-ops.
So the question being asked is "is this Charter's file, so don't tell the user to migrate it?" — ownership. Not a latent bug. See NIT 5 for the name.
The fix actually stops the round trip — reproduced both directions
I ran the branch's vendor-bloat.test.ts against main's source (all seven changed command files reverted with git restore --source=main --worktree, tests left on the branch):
main: Tests 3 failed | 7 passed (10)
branch: Tests 10 passed (10)
Exactly the claimed split. All three new tests are genuine detectors; none passes vacuously on main.
The deleted-rule test is the one that matters most, and it pins the real defect:
AssertionError: expected 'ADF: 0.1\n\n📐 RULES:\n - Database a…' not to contain 'Never import from dist'
Two things follow. First, the rule the user deleted from .ai/core.adf was genuinely resurrected on main — so it was demonstrably absent from existingAdf, and dedup cannot be what makes it pass on the branch. Second, note the module it landed in: the rule was deleted from core.adf CONSTRAINTS and came back under a RULES: section of a different module. The test therefore pins the cross-contamination symptom as well as the resurrection.
The byte-identity test (vendor-bloat.test.ts:363) snapshots every file in .ai/ plus CLAUDE.md and asserts toEqual/toBe after a full compile --write → tidy cycle. It fails on main with a 5-key object mismatch.
The #295/#300 guard is real, and stronger than claimed
I narrowed adf-compile.ts:249 back to POINTER_MARKERS in a scratch state and ran adf-compile.test.ts:
Tests 3 failed | 30 passed (33)
× overwrites an existing compile artifact without --force (adf-compile.test.ts:320)
× overwrites a previous compile artifact without --force (adf-compile.test.ts:384)
× does not flag a re-compile of an existing artifact (adf-compile.test.ts:512)
The implementer cited :320 and :384; a third test at :512 also fails. The guard is not imaginary and is broader than stated. Source restored byte-for-byte afterwards.
The inverse direction is also guarded: reverting adf-tidy.ts alone fails the three new #296 tests. And re-merging the lists in adf.ts would not resurrect the bug on its own, because the explicit banner check at adf-tidy.ts:263 runs before the pointer test — the fix is defended twice over.
Also ran
- Full CLI suite on the branch: 343 passed (31 files), 0 failed.
pnpm exec tsc --noEmitat repo root: exit 0.
Findings
-
[NIT]
.githooks/pre-commit:16andpackages/cli/src/commands/hook.ts:53-59— the compiled-file skip in both hooks is dead code, and that is why #296 escaped the hook. The loopcontinues past a compiled vendor file so it never entersSTAGED_VENDORS, but the tidy invocation two lines later (.githooks/pre-commit:26,hook.ts:62) passes no--source.adfTidyCommandatpackages/cli/src/commands/adf-tidy.ts:106-108falls back toVENDOR_FILES.filter(existsSync)— every vendor file on disk, regardless of what the hook filtered. The grep has never protected anything; it only suppressed the reporting path. Pre-existing, not introduced here, and now genuinely redundant sinceadf-tidy.ts:263does the real work. Worth naming because it is the reason the guard was believed to exist. Either delete both greps or pass--sourceper staged file; a follow-up, not this PR. -
[NIT]
harness/types.ts:43mirrorsTidyFileResult['status']and is now stale — it still reads'clean' | 'tidied' | 'not-found'and lacks'compiled'. Harmless in practice: the roottsconfig.jsonincludeis["packages/**/*.ts"], soharness/is not covered by the pre-committsc --noEmit; and nothing inharness/*.tsswitches onstatus— the only reads aretotalExtracted(harness/evaluator.ts:44,harness/runner.ts:197,355,489,494) andmodulesModified.harness/types.ts:54-60TidyOutputlikewise omits the newwarningsarray, andharness/runner.ts:145already constructs a fallback missingmoduleWarnings, so the mirror was drifting before this PR. Documentation drift only. -
[NIT] Nothing else parses
TidyResultpositionally or switches exhaustively onstatus. Checked the fourth-value question explicitly..githooks/pre-commit:27greps"totalExtracted": *[0-9]+out of the JSON — key-based, unaffected by the newwarningsarray or the newstatusvalue, and the compiled path contributesitemsExtracted: 0sototalExtractedstays 0 and the hook correctly reports clean.precommit-hook.test.ts:117pins that same grep string and still passes.--ci(adf-tidy.ts:230) gates ontotalExtracted > 0 && dryRun, so a compiled-only run exits SUCCESS — correct, a compile artifact is not a CI failure. -
[NIT] The bare
content.includes(COMPILE_BANNER_MARKER)substring test atadf-tidy.ts:263is reachable in principle but the failure mode is acceptable. A hand-authored thin pointer that quotes the literal stringGENERATED by charter adf compile— in documentation, an example, or a quoted remedy — would be classified as compile output and skipped. Three things make a stricter top-of-file/first-N-lines check not worth requiring here: (a) the skip is loud, not silent —adf-tidy.ts:135-141names the file and explains why, andprintTextResultprints it before the early return, so the user sees it every run; (b)doctor.ts:367and both hooks already use the byte-identical test, so tightening one without the others would create a three-way disagreement about what "compiled" means, which is a worse version of the #296 conflation; (c) the new warning text itself containscharter adf compile --write, not the banner marker, so tidy's own output cannot self-trigger the check if pasted into a vendor file. Behavior is also strictly better than main for this case, where such a file was treated as a pointer and its content ingested. If this is ever tightened, tighten all three sites in one change. -
[NIT]
bootstrap.ts:1400isAlreadyThinPointeris misnamed for what it now asks. It usesCHARTER_OWNED_MARKERSand answers "did Charter author this?", but the name asks the shape question the PR just spent its comment block separating. A compile artifact makes it returntruewhile not being a thin pointer. Behavior is correct (see ruling above) and identical to main; only the name perpetuates the conflation. SuggestisCharterOwnedFile. -
[NIT]
doctor.ts:313/doctor.ts:329report a compile artifact as a "thin pointer".isPointeris computed from the ownership list, and the PASS detail reads"N agent config file(s) are thin pointers to .ai/.". For a compiledCLAUDE.mdthat sentence is false. The classification itself is right — a compile artifact must not triggerRun: charter adf migrate --dry-run— anddoctor.ts:367already skips compiled files before the bloat scan, so only the message wording is inaccurate. Pre-existing and identical to main; noted because it is the same conflation this PR is about.
Working-tree hygiene
Verified after both scratch experiments. git status --porcelain reports only:
?? .ai/context.adf
?? .ai/context.snapshot.json
and git diff --quiet exits 0. No tracked file modified, nothing staged, none of CLAUDE.md / AGENTS.md / .cursorrules / GEMINI.md touched. The compile-guard experiment restored adf-compile.ts from a scratchpad copy taken before editing; the main-repro used git restore --source=main --worktree (index untouched) and was undone with git restore --worktree packages/cli/src/commands/. Both restorations confirmed by a clean git diff --stat. All scratch artifacts live outside the repo. Nothing committed or pushed.
…arity (#336) #320 read the compiled-file grep in the pre-commit hooks as dead since tidy skips compiled files itself (#319). It is not: the grep keeps compiled files out of STAGED_VENDORS, which gates the whole tidy block, so a compile-only commit skips tidy and the .ai/*.adf re-stage. Deleting it would sweep unrelated module edits into those commits. Keep it, make the comment say so in both copies, and add a test pinning the grep and the parity between .githooks/pre-commit and the generated hook. Refs #320 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #296
The bug
POINTER_MARKERSwas one constant answering two incompatible questions, andCOMPILE_BANNER_MARKERwas its first element:adf-compile.tsasks "did Charter write this file, so is it safe to overwrite?" — the compile banner must count. That inclusion is deliberate (bug(adf compile): refuses to overwrite the vendor files bootstrap just generated, requiring --force on first compile #295 / fix(adf): accept charter pointer stubs in compile overwrite guard #300).adf-tidy.ts(analyzeVendorFile) asks "is this a thin pointer whose extra content is un-ingested bloat?" — the compile banner must not count. Compiled output is derived from.ai/, so treating it as a pointer madeextractBeyondPointerclassify the entire compiled ruleset as "content added beyond the pointer" and fold.ai/back into itself.Reported consequences, all committed silently by the pre-commit hook: HTML marker comments arriving as CONTEXT bullets,
METRICS/ the module index /state.adf'sSTATElanding insidecore.adfCONSTRAINTS, a deliberately deleted rule restored to[load-bearing], and a hand-authored 26-linecore.adfreaching 66 lines.The fix
Split the constant, with a note at the definition explaining why the two must not be merged again:
POINTER_MARKERS— pointer shape. No longer containsCOMPILE_BANNER_MARKER.CHARTER_OWNED_MARKERS— ownership.COMPILE_BANNER_MARKERplus every pointer marker.Every current consumer was classified deliberately:
adf-compile.ts:243overwrite guardCHARTER_OWNED_MARKERSadf-tidy.ts:243analyzeVendorFilePOINTER_MARKERS+ explicit banner checkadf-tidy.ts:341pointer-preamble line skipPOINTER_MARKERS<!--/#rules, and compiled files no longer reach this functionadf-migrate.ts:220"already a thin pointer"CHARTER_OWNED_MARKERSmigrateingest compiled output — the same bug in a second commanddoctor.ts:313agent-config pointer checkCHARTER_OWNED_MARKERSdoctor.ts:402keyword-density line filterCHARTER_OWNED_MARKERSscore.ts:1085isSubstantiveInstructionCHARTER_OWNED_MARKERSbootstrap.ts:1076migrate-source selectionadf-migrateCHARTER_OWNED_MARKERSbootstrap.ts:1403isAlreadyThinPointerCHARTER_OWNED_MARKERSOnly
adf tidychanges behavior. Everything else keeps the superset and is byte-for-byte equivalent to today.Skip and warn, not a silent skip. A silent skip leaves a user running
charter adf tidywith an unexplained "nothing to do". Tidy now reports the file withstatus: "compiled", adds awarnings[]entry toTidyResult(JSON and text), and namescharter adf compile --writeas the way to regenerate it. The text-mode warning prints beforeprintTextResult's early return, which would otherwise have said "all clean" about a run that skipped a file.Tests
Three new tests in
packages/cli/src/__tests__/integration/vendor-bloat.test.ts. Measured against this branch's parent (ba616de), all three fail on main and pass with the fix — 3 failed / 7 passed → 10 passed.Genuine bug detectors:
CLAUDE.md, then tidy; every file in.ai/andCLAUDE.mditself must be byte-identical. On main, tidy reportsCLAUDE.md: 5 items → core.adf (5)and rewrites both.core.adfcarrying two load-bearing rules, delete one from.ai/, then tidy. On main the deleted rule comes back from the stale artifact, along with the manifest'sBUDGETandstate.adf'sSTATE. This is the issue's most damaging symptom and the most reliable red, because the deleted rule is absent fromexistingAdfand so cannot be dedup'd away.Existing guards against an over-eager fix, unchanged and still passing:
adf-compile.test.ts"overwrites an existing compile artifact without--force" and "overwrites a previous compile artifact without--force" pin the banner's membership in the ownership set, so narrowingadf-compile.ts:243toPOINTER_MARKERSwould fail them.vendor-bloat.test.tsscenarios 4 and 5 pin that an ordinary bloated thin pointer is still tidied and routed.pnpm test953/953 (950 baseline + 3),pnpm run typecheckclean (exit 0), ADF evidence gate PASS (adf_commands_loc1017/1041).Deliberately not in this PR
.githooks/pre-commit:14-19workaround stays. It greps for the banner andcontinues — the same test in the wrong layer. It should be removed after this ships, separately, so the two cannot drift silently in the meantime.compile --checkreporting thin pointers as permanently stale,adf sync --writewriting an empty lock, and whether vendor mode deserves a config setting. Not implemented here; referenced in the CHANGELOG entry.Reviewer notes
doctor's bloat analysis (doctor.ts:390+) already runs its section-overlap and keyword-density checks on compiled files, since a compile artifact has been inpointerFilesever since the banner joinedPOINTER_MARKERS. That can produce false WARNs on the rendered ruleset. Pre-existing, orthogonal to bug(adf tidy): ingests compiled vendor output back into core.adf, duplicating content and reverting deliberate deletions #296, untouched here.adf-migrate'sskipReason: 'Already a thin pointer'is now imprecise for compiled input. Pre-existing wording, left alone to avoid touching assertions.bootstrap'sisAlreadyThinPointername now answers the ownership question rather than the shape question. A rename is cheap but was left out to keep the diff to the bug.🤖 Generated with Claude Code