Skip to content

bug(adf tidy): ingests compiled vendor output back into core.adf, duplicating content and reverting deliberate deletions #296

Closed

Description

@stackbilt-admin

Problem

Following the README's own sequence, then committing, corrupts .ai/core.adf:

npx @stackbilt/cli bootstrap --yes
npx charter adf compile --target all --write --force   # README step 3
npx charter hook install --pre-commit
git commit                                             # hook runs `charter adf tidy`

compile --write writes full rule content into CLAUDE.md / AGENTS.md / .cursorrules / GEMINI.md. The pre-commit hook then runs charter adf tidy, which treats that generated content as "content added beyond the thin pointer" and ingests it back into .ai/core.adf. The two commands are mutually incompatible: one expands .ai/ into the vendor files, the other folds the vendor files back into .ai/.

What the round trip produced

core.adf after one commit (hand-authored file was 26 lines; it became 66):

📋 CONTEXT:
  - <!-- agents-modules -->
  - Read the matching file before working in these areas:
  - <!-- /agents-modules -->
  - # agents-modules
  - Read the matching file before working in these areas:
  - # /agents-modules
  - <!-- agents-modules -->          <- same marker block, 4 copies
  ...
⚠ CONSTRAINTS [load-bearing]:
  ...
  - `entry_loc`: 0 / 500 [lines]     <- METRICS captured as a constraint bullet
  - **CURRENT**: Charter initialized — node, react, vite project   <- state.adf content, 3 copies
  - `.ai/frontend.adf` — Triggers: React, CSS, UI, ...             <- the manifest module index

Three distinct failures:

  1. HTML marker comments become list bullets (<!-- agents-modules -->), and accumulate a copy per run.
  2. Sections cross-contaminate: the module index, METRICS and state.adf's STATE all land inside core.adf's CONSTRAINTS.
  3. A deliberate deletion was silently reverted. I had removed the bootstrap-generated rule Use .js extensions for all ESM imports because it is wrong for this Vite/TS repo (see bug(bootstrap): injects a stack-incorrect ESM extension rule as a load-bearing constraint #294). tidy read it back out of the compiled CLAUDE.md and restored it to [load-bearing]. state.adf was likewise reverted to its bootstrap placeholder, discarding the authored STATE.

The corruption was committed, because it happens during the pre-commit hook. Nothing in the output said a source file had been rewritten.

Why it matters

This is the failure mode a governance tool exists to prevent: unattended, silent edits to the source of truth, including undoing a human's considered decision. An agent that bootstraps, compiles and commits — exactly the documented path — ends up with an .ai/ that is worse on every commit and does not notice.

Related symptom: check and sync can't agree

Once vendor files are pointers (tidy's model), charter adf compile --target all --check reports all four stale forever, and its remediation line is wrong:

[stale] GEMINI.md — out of date with .ai/ source.
        Run: charter adf compile --target gemini --write

Running that produces byte-identical files (verified: same md5 over three runs) and --check still reports stale. charter adf sync --write, which sounds like the fix, writes an empty lock and changes nothing:

[ok] Wrote empty lock file at .ai/.adf.lock (no SYNC entries declared).
$ cat .ai/.adf.lock
{}

So compile --check is unusable as a CI gate in pointer mode.

Suggested fixes

  1. Make the two modes explicit and mutually exclusive. A repo is either compiled (vendor files hold content, tidy must skip them) or pointer (vendor files are stubs, compile --write must refuse). Record the mode in .charter/config.json and have each command respect it. The compile banner already identifies generated files — tidy should skip anything carrying it.
  2. Never let tidy write to .adf sources from a hook without saying so. At minimum print the diff summary; ideally require --write and run --dry-run in hooks.
  3. Never re-add a bullet that a previous tidy removed. A small ledger of ingested-then-deleted lines would prevent silently reverting human edits.
  4. Filter marker comments and section-specific content (<!-- ... -->, module index tables, METRICS lines) from ingestion.
  5. Fix compile --check's remediation message so it names a command that actually resolves the state, or exclude pointer-mode files from the check.

Environment

@stackbilt/[email protected], Node 22.14, WSL2 (case-insensitive /mnt/c mount), fresh repo, no pre-existing agent config files.

Activity

  1. stackbilt-admin commented on Sep 20, 2026

    @stackbilt-admin
    MemberAuthor

    Docs sweep update — 2026-09-19

    Still present on main at 1856a64. Confirmed the exact mechanism while documenting adf tidy:

    adf-tidy.ts:243 gates on POINTER_MARKERS:

    if (!POINTER_MARKERS.some(marker => content.includes(marker))) {
      return null;   // not a thin pointer — skip
    }

    POINTER_MARKERS[0] is COMPILE_BANNER_MARKER (adf.ts:291-292). So a compiled vendor file does not fail that test — it passes it, and tidy proceeds to treat compiler output as a thin pointer and fold it back into .ai/. There is no banner-specific skip anywhere in adf-tidy.ts.

    The protection that exists today lives one level up, in the generated pre-commit hook (hook.ts:53), which greps for the banner and drops those files from STAGED_VENDORS before tidy is invoked. That is what CHANGELOG 1.9.2's "pre-commit auto-tidy now ignores files produced by charter adf compile" describes — the hook, not the command.

    Consequence: the bug is latent rather than fixed. Anyone running charter adf tidy directly, or through any path that is not the generated hook, still gets the round-trip corruption this issue reports.

    Note the interaction with #295 / PR #300, now merged: adf compile --write refuses to overwrite a pointer carrying retained content, so the compile direction is protected. The tidy direction is not.

    Documented as current behavior in docs/cli-reference.md under charter adf tidy rather than described as fixed.

    Auto-updated by /docs skill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions