Skip to content

feat(adf)!: compile and tidy read the vendor mode record (#318 2/6) - #352

Merged
stackbilt-admin merged 2 commits into
mainfrom
auto/feature/issue-318-compile-tidy
Oct 16, 2026
Merged

stackbilt-admin merged 2 commits into
mainfrom
auto/feature/issue-318-compile-tidy

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Closes #318

Breaking: charter adf compile --write no longer converts pointer files to compiled output unless you pass --mode compiled.

  • Old behavior: after charter bootstrap, charter adf compile --target all --write (the README quickstart's step 3) replaced every thin pointer with compiled output, silently changing each file's mode. A single --target X --write did the same, and --force overwrote hand-authored files.
  • New behavior: under --target all, pointer and unmanaged targets are skipped and left untouched, and the exit code is 0. Each skipped target prints a [skip] line naming the exact command. When every target is skipped, compile says nothing was written, why, and how to switch. A single pointer or unmanaged --target is refused with exit 1. --force alone never changes a file's mode.
  • Migration: run charter adf compile --target all --write --mode compiled, or record the mode once with charter adf vendor set <file> compiled. After that, a plain --write re-renders the file.
  • This changes documented 1.x behavior, so it warrants 2.0.0 or explicit 1.x release notes. Package versions are not bumped here; the release is the operator's call.

Summary

PR 2 of 6 for #318. adf compile (--check and --write) and adf tidy now read the VENDORS mode record that #350 added. When a file has no entry, its mode is inferred from its markers.

  • compile state: each target is in the recorded mode, or the inferred one, or absent-unrecorded. The resolver's "absent means unmanaged" fallback is not reused, so a fresh repo still compiles.
  • --mode compiled: this is the only accepted value, and it is valid only with --write. Misuse exits 2. The record is upserted before the file is written, after the content guards and after rendering. If the upsert is skipped, the result is refused-record and nothing is written.
  • --check: each target is checked by its mode and gets one of seven statuses. No remedy suggests a mode-changing compile --write.
  • tidy: processes pointers only. The banner check still runs first, and recorded-compiled and unmanaged files are skipped with a skipReason. Files are discovered through discoverAgentConfigFiles, so the AGENTS.md/agents.md double walk on case-insensitive filesystems is gone (AGENTS.md migration gaps for repos bootstrapped before #297 #302 gap 3).
  • sync: with no SYNC entries, text and JSON now point to charter adf vendor status.
  • Docs: README quickstart step 3, the task table row and the command list are updated. docs/cli-reference.md gets compile mode and status tables, plus updated tidy, sync and vendor sections. The CHANGELOG has a ### Changed BREAKING: entry and a ### Fixed entry.

Also fixed (found during E2E; needed by this PR)

fileIdentity (adf-migrate.ts, used by discoverAgentConfigFiles and the PR1 vendor grouping) compared the number inode. NTFS file indexes exceed 2^53, so in a fresh bootstrap on Windows, CLAUDE.md and .cursorrules got the same identity. Three things followed:

  • bootstrap never recorded .cursorrules
  • --check compared .cursorrules as if it were CLAUDE.md
  • tidy dropped .cursorrules as a duplicate

It now uses statSync(..., { bigint: true }). file-identity.test.ts mocks statSync with inodes 2^53 and 2^53+1, which collapse to one JS number. It is deterministic on every OS and fails on the old code.

Before → after

Command State main @ 555711a this PR
compile --check pointer, clean [stale], exit 1, suggests --write pointer-ok, exit 0
compile --check pointer with bloat [stale], exit 1 pointer-bloated, exit 1, suggests adf tidy --source F
compile --check hand-authored [stale], exit 1 skipped-unmanaged, exit 0
compile --check recorded pointer, has banner [ok] or [stale] mode-drift, exit 1, both remedies
compile --check compiled or absent fresh, stale or missing unchanged (missing now prints a Run: line)
compile --write --target all pointer overwritten skipped-mode, exit 0, file untouched
compile --write --target X pointer overwritten refused-mode-change, exit 1
compile --write --mode compiled pointer (no flag) record upserted first, then Written F (mode: pointer -> compiled)
compile --write --force unmanaged overwritten skipped or refused; also needs --mode compiled
compile --write compiled or absent written written (unchanged)
tidy hand-authored not-found unmanaged, inferred-unmanaged
tidy recorded compiled, no banner tidied as a pointer compiled, recorded-compiled, skipped
tidy AGENTS.md and agents.md are one file walked twice walked once

JSON changes are additions only. Write output adds skipped and targets[]. Check output adds skipped and targets[], and its stale key now also lists bloated and drifted files. Tidy rows add vendorFile, mode, source and skipReason, and their status can now also be unmanaged.

Invariants and where they are tested

New tests are in packages/cli/src/__tests__/adf-vendor-consumers.test.ts unless noted.

Invariant Test
INV-P2-1: no mode-changing remedy INV-P2-1: no remedy suggests a mode-changing compile --write…. It also checks --write remedies and nextActions.
INV-P2-2: --force alone never converts INV-P2-2: --force alone never converts…, and adf-compile.test.ts --mode compiled --force overwrites…
INV-P2-3: upsert before write; a skipped upsert writes nothing INV-P2-3: a skipped record upsert means no file write (refused-record), and INV-P2-3: the record is upserted before the file is written (a read-only target makes the write fail after the upsert)
INV-P2-4: never prints "record kept" INV-P2-4: no write path prints…, and adf-vendor.test.ts adf compile --write refuses a recorded pointer…
INV-P2-5: the banner wins in tidy INV-P2-5: the banner wins over a recorded pointer…
INV-P2-6: read-only paths never write the manifest INV-P2-6: tidy --dry-run, compile --check and compile stdout never write manifest.adf
INV-P2-7: no-VENDORS tidy behaves as before INV-P2-7: …, INV-P2-8 (tidy half), and E2E (e)
INV-P2-8: no-VENDORS compile behaves as before INV-P2-8: --write, --check and tidy text match the pre-#318 output, and E2E (e)
INV-P2-9: legacy JSON keys gives each of the seven statuses… and the decision-table tests; the existing adf-compile.test.ts JSON tests still pass
INV-P2-10: pointer-only names are never targets handles a pointer-only name by mode (INV-P2-10)
INV-P2-11: no entry-problem warnings INV-P2-11: compile and tidy print no VENDORS entry-problem warnings
INV-P2-12: hooks byte-identical git diff origin/main -- .githooks packages/cli/src/commands/hook.ts is empty. Hook parity and precommit-hook.test.ts are unchanged.

The scope tests are also covered:

  • the seven --check statuses
  • every decision-table row, including mixed --target all (exit 0), single pointer (exit 1) and --mode misuse (exit 2)
  • refused-record
  • tidy's banner, recorded-compiled, unmanaged, non-vendor --source and double-walk cases
  • the sync hint in text and JSON

Contract amendments (review round 1)

  • Content-preserving remedies first (amends MSG.tidyRecordedCompiled and the checkModeDrift keep/restore lines). Take a file that is recorded compiled but has no banner and does carry pointer content. Both remedies now list charter adf vendor set F pointer, then charter adf tidy --source F first. Regenerating comes second and says how many items it would discard. A hand-authored file gets vendor set F unmanaged first. Tests follow the first-listed commands and assert that the content ends up in .ai/.
  • Per-target write recovery. When a file write fails, the run no longer aborts, and that target is reported as refused-record. The write-target row gains writeError, a new nullable field. A --mode compiled upsert that was already made is reverted with the same writer, to the state before the run. A file that had no entry is left recorded as its inferred mode. If the revert fails, a warning names the exact vendor set fix. The remaining targets and the pending add-if-absent entries are still processed, and the exit code is 1.
  • Remedy and nextActions adjustments:
    • refusedModeChange and skippedMode add --force for an existing hand-authored unmanaged file, so the remedy is one step.
    • Under --target all, check-JSON nextActions collapse to the legacy ["charter adf compile --target all --write"] when every failing target is a stale or missing compiled file.
    • Stdout-mode nextActions are mode-aware.

Not changed yet

These stay out of PR2 by design:

  • PR3: doctor, score and bootstrap consumers
  • PR4: hook --source; both hooks stay byte-identical here
  • PR5: preserving retained sections and adding replacedPointers
  • PR6: legacy agents.md

The retained-section guard from #295 still refuses a pointer with user content, including under --mode compiled. PR5 replaces it with preservation.

Implemented via constellation-loop against a locked blueprint.

🤖 Generated with Claude Code

BREAKING CHANGE: adf compile --write no longer converts pointer files without --mode compiled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@stackbilt-admin stackbilt-admin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGES_REQUESTED

Adversarial review of #352 (PR 2/6 for #318), checked against the locked addendum pr2-compile-tidy.contract.ts and pr2-scope.md.

The behavior is right. Every decision-table row, exit code and invariant I checked holds end to end. The four required changes are in docs and tests: the npm-facing quickstart is still broken, the bigint regression test does not test the fix, and two docs items need fixing.

Required changes

  1. packages/cli/README.md:19, :43, :79: the npm package README still has the old quickstart.

    • Each of these lines tells users to run bootstrap --yes and then charter adf compile --target all --write. After this PR that second command skips every file and writes nothing.
    • This README is the one published to npmjs for @stackbilt/cli, so it is the quickstart most new users read. The operator ruling asked for README and docs to be updated, and only the root README.md was.
    • Fix: apply the same --mode compiled change as root README.md:40 to lines 19 and 43. Reword line 79 the way root README.md:291-292 does.
  2. packages/cli/src/__tests__/adf-migrate-discovery.test.ts:94-104: the new fileIdentity test passes on the old code.

    • I copied the test into a main worktree (number ino). It passes there: 6 passed.
    • The test only fails when the real temp-dir inodes exceed 2^53 and are not exactly representable. On this Windows machine, files in os.tmpdir() get inodes around 2.5e15 to 3.6e15, below 2^53. Repo files reach 1.27e16 (README.md: number 12666373958243488, bigint 12666373958243487), so the bug is real.
    • CI runs on ubuntu-latest, where inodes are small, so CI can never catch a revert.
    • Fix: make the test deterministic. Mock statSync (for example vi.mock('node:fs', …)) to return bigint stats for two different files whose inodes collapse to the same number, such as 2n**53n and 2n**53n + 1n. Assert that fileIdentity tells them apart and that discoverAgentConfigFiles() keeps both.
  3. CHANGELOG.md:9-11: the Breaking marker does not follow repo precedent.

    • The repo's only other breaking release, ## [1.0.0] at CHANGELOG.md:206, puts a standalone **Breaking:** … lead paragraph directly under the version heading, before the ### subsections.
    • Here the marker is a - **BREAKING: …** bullet buried in ### Changed, and it runs to about 400 words.
    • Fix: add a one-to-two-sentence **Breaking:** lead paragraph under ## [Unreleased], with the migration line (charter adf compile --target all --write --mode compiled). Keep the detailed bullet where it is. I verified the migration text is correct. Both routes work: --mode compiled, and vendor set <f> compiled followed by a plain --write.
  4. docs/cli-reference.md:626: one statement is now false.

    • The line says "a failed record write is only a warning". Under --mode compiled, a failed record write is now refused-record, exit 1, and nothing is written. Your own --mode compiled bullet at about line 488 says so.
    • Fix: qualify the line, for example "…only a warning, except under adf compile --write --mode compiled, where the target is refused (refused-record)".

Verified (temp worktrees of the PR head 1ff3ef0 and origin/main 555711a, Windows + Git Bash)

  • Build, typecheck, verify:adf, CI.
    • Build and typecheck are clean.
    • pnpm run verify:adf passes. adf_commands_loc is 1027/1041 and adf_sync_loc is 219/250.
    • The full suite has 5 failures, and they are the same 5 on main: Windows path-separator tests in context-refresh, serve-context and bootstrap #307, plus precommit-hook.test.ts ×2. They are not caused by this PR, and CI on Linux is green.
  • Hooks. git diff origin/main -- .githooks packages/cli/src/commands/hook.ts is empty (INV-P2-12).
  • Decision table (E2E). All four shipped pointers (CLAUDE.md, AGENTS.md, .cursorrules, GEMINI.md), recorded or inferred:
    • --target all --write: [skip] ×4 plus nothingCompiled, exit 0, md5 of every file unchanged.
    • Single --target claude --write, with or without --force: refused, exit 1, file untouched.
    • --mode pointer, a bare trailing --mode, and --mode with --check: exit 2 with the contract text.
    • --mode compiled: record upserted, then Written CLAUDE.md (mode: pointer -> compiled).
    • Mixed --target all (one compiled, three pointers): writes one, skips three, exit 0. JSON written, refused, skipped and targets are correct.
    • Unmanaged with --mode compiled: refused hand-authored, record untouched. With --force it is written as unmanaged -> compiled.
    • The #295 retained guard still refuses under --mode compiled and records nothing.
    • "record kept" never appears. On main it is printed four times for the same scenario.
  • refused-record. I made the CLAUDE.md entry malformed (- CLAUDE.md pointer) and ran --write --mode compiled. Result: exit 1, both the file's and the manifest's md5 unchanged, and JSON status: refused-record, recordedMode: null.
  • No-VENDORS compiled-only regression (adf init → compile --write → strip VENDORS), diffed against main:
    • Text output of --check (fresh and stale), --write (all and single) and tidy is identical to main.
    • The exceptions are intended or additive:
      • tidy no longer double-walks agents.md, which is the intended de-dup.
      • A missing file gains a Run: line.
      • The JSON output only gains keys.
    • All-banner files with no VENDORS: --target all --write writes all four with no new notes and records them as compiled.
    • With no vendor files on disk, all four are written and recorded compiled.
  • Pre-commit hook totalExtracted, main vs PR.
    • A bloated pointer repo gives 3 vs 3, recorded or not.
    • Compiled repos give 0 vs 0.
    • Whole-tree tidy on a hand-authored, unrecorded file prints the same text as main (quiet). The status is unmanaged, and the warning appears only with --source.
  • README.md quickstart, followed literally.
    • On a fresh repo: bootstrap --yes, then compile --target all --write --mode compiled (four switched), then compile --target all --check, which exits 0.
    • copilot-instructions.md stays recorded as pointer.
  • tidy. The banner wins over a recorded pointer (status: compiled, skipReason: banner). A recorded-compiled file with no banner is skipped. A recorded pointer with no marker is skipped with a warning.
  • bigint fileIdentity is correct on every OS.
    • ${bigint} stringifies as plain decimal with no n.
    • if (st.ino) handles 0n, so the realpath fallback still works.
    • adf-migrate.ts:68 is the only place that compares inodes, and identity strings are never persisted or mixed with number-based ones.
    • Only the test is a problem (required change 2).

Rulings on the implementation's judgement calls

  • #295 retained guard kept for no-banner recorded-compiled files: accept. It protects user content, and PR5 replaces it.
  • Render before upsert: accept. A compile error then leaves both the record and the file untouched.
  • Inferred-unmanaged warns only with --source: accept. Whole-tree output is byte-identical to main, as INV-P2-7 requires.
  • checkMissingCompiled Run: line: accept. It is the contract literal and the only text change on compiled-only repos.
  • nextActions dedupe and fallback: accept. See the second non-blocking note.
  • mode-drift remedy holds the keep-the-file command, with the restore command only in nextActions: accept.
  • Rewritten PR1 tests: accept.
    • The removed INV-1 compile and tidy compare tests are replaced by literal-text pins (INV-P2-7 and INV-P2-8).
    • The INV-9 test was narrowed to legacy keys, which is fine because targets is new.
    • adf-vendor.test.ts now pins refusal with no "record kept".
    • adf-compile.test.ts's --force test now also pins INV-P2-2.

Non-blocking notes

  1. A recorded-compiled pointer with bloat loses that content (follow-up for PR3/PR5).
    • Setup: VENDORS says compiled, and the file is a pointer with a ## Architecture section.
    • tidy skips it with "Regenerate it from .ai/: charter adf compile --target claude --write", and the mode-drift restore line says the same.
    • Running that command overwrites the file, and the non-retained bloat is lost ([ok] Written CLAUDE.md). On main, tidy and the hook would have extracted it first.
    • This follows the contract literally, but the remedy is destructive for exactly the post-bootstrap --force case recorded-compiled was designed for.
  2. Check-JSON nextActions on a compiled-only stale repo. It used to be ["charter adf compile --target all --write"]. It is now four per-target lines. The contract allows it, but it is a visible change for legacy consumers. Consider collapsing to --target all --write when every remedy is a compile of a compiled target under --target all.
  3. A write failure after the upsert aborts the run.
    • Example: a read-only CLAUDE.md under --mode compiled throws EPERM and exits 2. The record is already compiled, so the file now drifts.
    • Under --target all, the remaining targets and the pending add-if-absent entries are never processed.
    • The ordering is mandated by the contract, but catching the write error per target (and reverting the upsert, or reporting a row) would be kinder.
  4. Two-step remedy for an existing unmanaged file. refusedModeChange suggests --write --mode compiled, which then refuses for lack of --force. Consider adding --force to the suggestion when the state is unmanaged and the file exists. The JSON remedy for refused-hand-authored already does this.
  5. adf-compile.ts:203-204: stdout-mode JSON nextActions still suggest --target X --write and --target all --write without regard to mode. For a pointer target those are now refused or skipped. Out of scope for INV-P2-1, but it leads nowhere.
  6. The docs/cli-reference --write table row "compiled, or absent | written" reads as if any absent file is written. A recorded-pointer file that is absent is skipped or refused. Say "absent and unrecorded".
  7. refused-record prints the record writer's entry-malformed warning, a VENDORS entry problem (INV-P2-11, strictly). Acceptable, because it is the reason for the refusal.
  8. On a case-insensitive filesystem with agents.md: pointer recorded, --target agents --write --mode compiled resolves to agents.md, hits mode-not-allowed, and ends as refused-record with a generic message. This belongs to PR6.
  9. The bigint fix has no CHANGELOG line. The bug never shipped (#343 and PR1 are unreleased), so this is optional. A clause on the #343 entry would help.
  10. Stale marketing docs. docs/launch/charter-announcement.md:42 and docs/launch-playbook.md:42 still show the bare --target all --write. They are historical, so updating them is optional.

@stackbilt-admin
stackbilt-admin merged commit 9ce61b4 into main Oct 16, 2026
5 checks passed
@stackbilt-admin
stackbilt-admin deleted the auto/feature/issue-318-compile-tidy branch October 16, 2026 02:56
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.

adf: no repo records whether vendor files are compiled or pointers, so compile --check and tidy disagree forever

2 participants