Skip to content

fix(bootstrap): emit AGENTS.md instead of lowercase agents.md - #301

Merged
stackbilt-admin merged 2 commits into
mainfrom
auto/bugfix/issue-297
Sep 20, 2026
Merged

stackbilt-admin merged 2 commits into
mainfrom
auto/bugfix/issue-297

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Closes #297

Problem

charter bootstrap and charter adf init --emit-pointers wrote the agent pointer as lowercase agents.md, while charter adf compile --target agents --write writes AGENTS.md — the name in TARGET_FILENAMES.agents (packages/adf/src/compiler.ts:69).

On a case-insensitive filesystem (macOS default, WSL /mnt/c) these are the same file, so the inconsistency is invisible and git records whichever case landed first. On a case-sensitive checkout they are two files, and the one every harness reads is AGENTS.md. A repo bootstrapped on Windows or macOS and then cloned on Linux silently loses its agent instructions.

Reproduced on a fresh bootstrap --yes followed by adf compile --target all --write: the tree ends up holding both agents.md (pointer) and AGENTS.md (compiled) side by side.

Changes

File Change
packages/cli/src/commands/bootstrap.ts:908 pointer entry agents.md → AGENTS.md (name and label)
packages/cli/src/commands/bootstrap.ts:376 "Next steps" git add line now lists AGENTS.md, plus GEMINI.md and copilot-instructions.md
packages/cli/src/commands/adf.ts:442 adf init --emit-pointers writes AGENTS.md — same bug, second entry point
packages/cli/src/commands/adf.ts:351 POINTER_AGENTS_MD titled # AGENTS.md to match the file it fills
packages/cli/src/commands/adf.ts:865 --emit-pointers help text
packages/cli/src/commands/hook.ts:47 pre-commit VENDOR_FILES lists AGENTS.md only
packages/cli/src/commands/hook.ts:328 hook help text
docs/cli-reference.md:200 --emit-pointers output description
.githooks/pre-commit:10 this repo's own hook, synced to the generator (second commit)

The next-steps line at bootstrap.ts:376 also omitted GEMINI.md, which bootstrap writes. That is the second item of #295, split here deliberately from the already-merged #300. I have added copilot-instructions.md for the same reason — bootstrap writes it at the repo root and the line omitted it. Please close #295 by hand; this PR does not.

Why retitling the template is safe

Pointer recognition everywhere (adf-compile.ts:243, adf-tidy.ts:243, adf-migrate.ts:220, doctor.ts:251, score.ts:1041, bootstrap.ts:1304) is a substring test against POINTER_MARKERS, not template equality. The retained-section comparison in adf-compile.ts:203 maps ## headings only, so the # title is not part of it. Existing files carrying the old # agents.md title stay recognised.

Known tradeoff — legacy repos and the pre-commit hook

The hook matches with grep -qx "$vf" against git diff --cached --name-only, which reports git's recorded path. A repo that already tracks lowercase agents.md (as the reporter's does) will, after this change, no longer trigger hook auto-tidy when that file is staged — on any filesystem. charter adf tidy run directly still handles it: adf-tidy.ts deliberately keeps both spellings in its own VENDOR_FILES. Such repos should git mv to uppercase to regain hook coverage.

This is the intended consequence of removing the duplicate spelling the issue calls out, but it is worth stating plainly rather than leaving it to be discovered.

Note for reviewers testing locally

The fix is in the generator, not in already-generated hooks. A checkout whose .git/hooks/pre-commit (or .githooks/pre-commit) was written by an older charter hook install keeps the old VENDOR_FILES line until charter hook install --pre-commit is re-run — so charter doctor on an existing repo will still print both spellings after upgrading. That is expected, not a failed fix.

This repo's own .githooks/pre-commit is hand-maintained (extra tsc step, no Charter marker) rather than generated, so it is updated directly in the second commit; its line now matches hook.ts:47 byte for byte.

Deliberately out of scope

  • Auto-migration of an existing lowercase agents.md (issue's suggested fix fix: cross-platform parity (ADX-005), bump v0.5.0 #2). On a case-insensitive filesystem bootstrap's existsSync('AGENTS.md') already matches the lowercase file and skips it, so no duplicate is created; on a case-sensitive one you get two files. A case-safe two-step git mv has its own failure modes (dirty index, untracked file, non-git directory) and is a feature, not part of this fix. Nothing is deleted or renamed here. Worth a follow-up issue.
  • AGENT_CONFIG_FILES in adf-migrate.ts:44 and bootstrap.ts:960 scan lowercase only, so adf migrate never picks up a custom-content uppercase AGENTS.md on a case-sensitive filesystem. Adding 'AGENTS.md' risks double-processing the same file on a case-insensitive one, so it needs its own de-duplication design. Follow-up.
  • Left as-is intentionally: CHANGELOG.md (historical record), papers/ (archived write-ups), and the migrate-scan lists in packages/cli/README.md:330 / docs/cli-reference.md:252 — those describe legacy inputs to migration, where the lowercase name is correct. score.ts and doctor.ts list both spellings for legacy detection, which is also correct.

Tests

Five regression tests added, in bootstrap.test.ts and adf-init.test.ts.

A test using fs.existsSync would be worthless here — CI and local WSL /mnt/c disagree about case, and existsSync is case-blind on the latter. These assert on the strings the code produces: the pointer labels in the bootstrap JSON report, fs.readdirSync entries (which report the case a file was created with), and the template title — each compared against TARGET_FILENAMES.agents, so the test and the compiler cannot drift apart.

Verified they fail for the right reason: with the lowercase spelling temporarily reintroduced, all 5 fail (expected [ 'agents.md' ] to deeply equal [ 'AGENTS.md' ] and similar). With the fix, green.

pnpm run typecheck   clean
pnpm test            62 files, 887 passed (882 on main + 5 new)

No pre-existing test was skipped or weakened. packages/cli/src/__tests__/integration/precommit-hook.test.ts:104 is a hand-built fixture, not compared against hook.ts, so it did not fail either way; updated so it does not drift from the real hook.

🤖 Generated with Claude Code

stackbilt-admin and others added 2 commits September 19, 2026 20:05
`charter bootstrap` and `charter adf init --emit-pointers` wrote the agent
pointer as lowercase `agents.md`, while `charter adf compile --target agents`
writes `AGENTS.md` (TARGET_FILENAMES.agents). On a case-insensitive filesystem
these are one file and the mismatch is invisible; on a case-sensitive checkout
they are two, and harnesses read the uppercase one — so a repo bootstrapped on
Windows or macOS silently loses its agent instructions when cloned on Linux.

- bootstrap and `adf init --emit-pointers` now write `AGENTS.md`
- POINTER_AGENTS_MD is titled `# AGENTS.md` to match the file it fills
- the pre-commit hook's VENDOR_FILES lists `AGENTS.md` only, so doctor and the
  hook stop printing both spellings in one line
- the bootstrap "Next steps" git add line lists AGENTS.md, and now also
  GEMINI.md and copilot-instructions.md, which bootstrap writes but the line
  omitted

Pointer detection is substring-based on POINTER_MARKERS, not template equality,
so the retitled template is still recognised by compile, tidy, migrate, doctor
and score.

Regression tests assert on the names the code produces — pointer labels and
readdir entries compared against TARGET_FILENAMES — rather than fs.existsSync,
which cannot distinguish the two spellings on this filesystem.

Resolves-Request: #297

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
.githooks/pre-commit is hand-maintained (it carries an extra tsc step and no
Charter marker) but mirrors the tidy block that hook.ts generates. Without this
the repo's own hook keeps printing both spellings after the generator stopped —
the self-disagreement #297 reports. This repo tracks uppercase AGENTS.md, so
nothing loses hook coverage.

Resolves-Request: #297

Co-Authored-By: Claude Opus 5 (1M context) <[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.

APPROVED

Verified on auto/bugfix/issue-297 at d4d7ea9 against a WSL /mnt/c checkout. pnpm test 62 files / 887 passed (882 on main + 5), tsc --noEmit clean via the repo's own hook. Working tree left untouched.

Scope expansions — all three endorsed

1. adf.ts:442 (adf init --emit-pointers) — correct to include. It is the identical bug at a second entry point; fixing only bootstrap.ts:908 would have shipped a half fix that the issue's "emit AGENTS.md everywhere" explicitly asks against.

The POINTER_AGENTS_MD retitle (adf.ts:351) is safe, and I checked all three consumers rather than the two the PR body names:

  • POINTER_MARKERS (adf.ts:291-300) — recognition is existing.includes(marker) against body strings (DO NOT add instructions to this file), never the H1. Legacy files titled # agents.md stay recognised.
  • adf-compile.ts:203 divergentRetainedHeadings → retainedSectionMap (:172) only opens a section on line.trim().startsWith('## '), and lines before the first ## are dropped by the if (heading) guard at :185. readRetainedSections (adf-tidy.ts:292) filters the same way one layer earlier. The # title cannot reach the comparison. The #300 retained-section logic is unaffected.
  • Third consumer, not in the PR body: adf-tidy.ts:320 extractBeyondPointer also takes POINTER_AGENTS_MD. It uses it only as a presence check (if (!template) return '') — bloat detection is structural (:335 skips any trimmed.startsWith('#') && !trimmed.startsWith('## ')), so # agents.md and # AGENTS.md are discarded identically. No spurious totalExtracted, no heading routed into a .adf module. Worth adding to the PR body since it is the one path that could have bitten.

2. copilot-instructions.md in the next-steps line (bootstrap.ts:376) — endorsed. bootstrap.ts:909 writes it at the repo root; omitting it from git add left a bootstrapped file untracked. Correctly scoped.

3. .githooks/pre-commit:10 — endorsed, verified. diff of the VENDOR_FILES= line against hook.ts:47 is byte-identical. bash -n clean. Ran the hook end-to-end: tsc --noEmit + evidence checks, Verdict: PASS, exit 0. This repo tracks uppercase AGENTS.md (git ls-files), so the removal of the lowercase entry has zero local blast radius here.

4. Hook auto-tidy regression — real, not blocking

Confirmed empirically in a scratch repo: stage a tracked lowercase agents.md, and the new VENDOR_FILES matches nothing where the old list matched. git diff --cached --name-only reports git's recorded path, so this bites on any filesystem.

Not blocking, for three reasons that hold together:

  • Generated hooks do not change until charter hook install --pre-commit is re-run, so no repo regresses on upgrade alone.
  • charter adf tidy run directly still covers it — adf-tidy.ts:34-35 deliberately keeps both spellings, and doctor.ts:245 detects both.
  • The issue explicitly asked for the duplicate spelling to go ("the tool disagreeing with itself in one line of output"). Keeping a compat entry would re-introduce exactly what was reported.

One request before merge (non-blocking): the PR body says the case-safe git mv migration is "worth a follow-up issue" but links none. That migration is the issue's own suggested fix #2, and the reporter's repo is the affected population — they get this fix and silently lose hook tidy on that file. Please file and link the follow-up so the deferral is tracked rather than lost.

5. Test quality — independently re-verified, and the concern was justified

I confirmed on this mount that fs.existsSync would be worthless here: creating agents.md under /mnt/c makes existsSync('AGENTS.md') return true, while readdirSync returns [ 'agents.md' ]. The mount is case-insensitive but case-preserving, so readdirSync genuinely discriminates where existsSync cannot. The test design is right.

I re-ran the negative result myself rather than taking it on trust — temporarily reintroducing the lowercase spelling at all four sites (bootstrap.ts:376, :908, adf.ts:351, :442), then fully reverting (git status clean, confirmed):

× emits the agents pointer at the exact name the compiler targets
× titles the agents pointer template with the uppercase filename
× labels the emitted agents pointer with TARGET_FILENAMES.agents, not agents.md
× writes the pointer at the exact on-disk name the compiler targets
× names AGENTS.md and GEMINI.md in the git add next step
  Tests  5 failed | 25 passed (30)

Exactly 5 fail, for the right reasons (expected [ 'agents.md' ] to deeply equal [ 'AGENTS.md' ]), and no other test is disturbed. Comparing against TARGET_FILENAMES rather than a literal is the right call — test and compiler cannot drift.

Minor gap: bootstrap.test.ts:470-480 asserts AGENTS.md and GEMINI.md in the git-add line but not copilot-instructions.md, which is the thing scope item 2 added. One more toContain would pin it.

6. Deferred items — both deferrals correct

  • Auto-migration of a lowercase agents.md: agreed, out of scope. bootstrap.ts:914 guards with existsSync and isAlreadyThinPointer, so nothing is clobbered and no data is at risk. A two-step git mv is a feature with its own failure modes.

  • AGENT_CONFIG_FILES (adf-migrate.ts:44, bootstrap.ts:960): the double-processing concern is legitimate and already demonstrable — adf-tidy.ts:34-35 lists both spellings today, so charter adf tidy already walks the same physical file twice on macOS/WSL. Adding AGENTS.md to the migrate lists without de-duplication would spread that. Correctly deferred.

    For the follow-up: after this PR, a hand-written uppercase AGENTS.md on a case-sensitive filesystem reaches a dead end — bootstrap.ts:917 warns "run charter adf migrate first", but AGENT_CONFIG_FILES never scans AGENTS.md, so migrate is a no-op for it. Pre-existing, newly more reachable; belongs in the same de-dup follow-up.

7. Sweep — clean, nothing missed

Ran git grep unfiltered plus a recursive grep with no --include over .github, .githooks, .charter, scripts and all extensionless files. scripts/smart-commit.sh:110 was already uppercase-only. Every surviving lowercase reference is correct by intent: adf-tidy.ts:34/adf-migrate.ts:44 (legacy inputs), score.ts:387/:846 and doctor.ts:245 (legacy detection, both spellings), CHANGELOG.md and papers/ (historical), README.md:330/cli-reference.md:252 (migrate-scan inputs). The only cosmetic leftover: tidying a legacy lowercase agents.md now writes a # AGENTS.md title into it via restorePointer (adf-tidy.ts:510) — harmless, and it resolves itself on the git mv.

Good defensive work on the test design and on stating the tradeoff in §"Known tradeoff" rather than letting it be discovered. Approving; please link the migration follow-up issue before merge.

@stackbilt-admin

Copy link
Copy Markdown
Member Author

Deferred migration work filed as #302 (existing lowercase agents.md loses hook auto-tidy; AGENTS.md missing from the migrate scan lists; de-dup needed before adding it). Linked per review condition prior to merge.

The compile-side follow-up from PR #300's review is filed as #303.

@stackbilt-admin
stackbilt-admin merged commit 148724d into main Sep 20, 2026
5 checks passed
@stackbilt-admin
stackbilt-admin deleted the auto/bugfix/issue-297 branch September 20, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant