Repository navigation
fix(bootstrap): emit AGENTS.md instead of lowercase agents.md - #301
Conversation
`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
left a comment
There was a problem hiding this comment.
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 isexisting.includes(marker)against body strings (DO NOT add instructions to this file), never the H1. Legacy files titled# agents.mdstay recognised.adf-compile.ts:203divergentRetainedHeadings→retainedSectionMap(:172) only opens a section online.trim().startsWith('## '), and lines before the first##are dropped by theif (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:320extractBeyondPointeralso takesPOINTER_AGENTS_MD. It uses it only as a presence check (if (!template) return '') — bloat detection is structural (:335skips anytrimmed.startsWith('#') && !trimmed.startsWith('## ')), so# agents.mdand# AGENTS.mdare discarded identically. No spurioustotalExtracted, no heading routed into a.adfmodule. 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-commitis re-run, so no repo regresses on upgrade alone. charter adf tidyrun directly still covers it —adf-tidy.ts:34-35deliberately keeps both spellings, anddoctor.ts:245detects 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:914guards withexistsSyncandisAlreadyThinPointer, so nothing is clobbered and no data is at risk. A two-stepgit mvis 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-35lists both spellings today, socharter adf tidyalready walks the same physical file twice on macOS/WSL. AddingAGENTS.mdto the migrate lists without de-duplication would spread that. Correctly deferred.For the follow-up: after this PR, a hand-written uppercase
AGENTS.mdon a case-sensitive filesystem reaches a dead end —bootstrap.ts:917warns "runcharter adf migratefirst", butAGENT_CONFIG_FILESnever scansAGENTS.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.
Closes #297
Problem
charter bootstrapandcharter adf init --emit-pointerswrote the agent pointer as lowercaseagents.md, whilecharter adf compile --target agents --writewritesAGENTS.md— the name inTARGET_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 isAGENTS.md. A repo bootstrapped on Windows or macOS and then cloned on Linux silently loses its agent instructions.Reproduced on a fresh
bootstrap --yesfollowed byadf compile --target all --write: the tree ends up holding bothagents.md(pointer) andAGENTS.md(compiled) side by side.Changes
packages/cli/src/commands/bootstrap.ts:908agents.md→AGENTS.md(name and label)packages/cli/src/commands/bootstrap.ts:376AGENTS.md, plusGEMINI.mdandcopilot-instructions.mdpackages/cli/src/commands/adf.ts:442adf init --emit-pointerswritesAGENTS.md— same bug, second entry pointpackages/cli/src/commands/adf.ts:351POINTER_AGENTS_MDtitled# AGENTS.mdto match the file it fillspackages/cli/src/commands/adf.ts:865--emit-pointershelp textpackages/cli/src/commands/hook.ts:47VENDOR_FILESlistsAGENTS.mdonlypackages/cli/src/commands/hook.ts:328docs/cli-reference.md:200--emit-pointersoutput description.githooks/pre-commit:10The next-steps line at
bootstrap.ts:376also omittedGEMINI.md, which bootstrap writes. That is the second item of #295, split here deliberately from the already-merged #300. I have addedcopilot-instructions.mdfor 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 againstPOINTER_MARKERS, not template equality. The retained-section comparison inadf-compile.ts:203maps##headings only, so the#title is not part of it. Existing files carrying the old# agents.mdtitle stay recognised.Known tradeoff — legacy repos and the pre-commit hook
The hook matches with
grep -qx "$vf"againstgit diff --cached --name-only, which reports git's recorded path. A repo that already tracks lowercaseagents.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 tidyrun directly still handles it:adf-tidy.tsdeliberately keeps both spellings in its ownVENDOR_FILES. Such repos shouldgit mvto 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 oldercharter hook installkeeps the oldVENDOR_FILESline untilcharter hook install --pre-commitis re-run — socharter doctoron an existing repo will still print both spellings after upgrading. That is expected, not a failed fix.This repo's own
.githooks/pre-commitis hand-maintained (extratscstep, no Charter marker) rather than generated, so it is updated directly in the second commit; its line now matcheshook.ts:47byte for byte.Deliberately out of scope
agents.md(issue's suggested fix fix: cross-platform parity (ADX-005), bump v0.5.0 #2). On a case-insensitive filesystem bootstrap'sexistsSync('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-stepgit mvhas 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_FILESinadf-migrate.ts:44andbootstrap.ts:960scan lowercase only, soadf migratenever picks up a custom-content uppercaseAGENTS.mdon 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.CHANGELOG.md(historical record),papers/(archived write-ups), and the migrate-scan lists inpackages/cli/README.md:330/docs/cli-reference.md:252— those describe legacy inputs to migration, where the lowercase name is correct.score.tsanddoctor.tslist both spellings for legacy detection, which is also correct.Tests
Five regression tests added, in
bootstrap.test.tsandadf-init.test.ts.A test using
fs.existsSyncwould be worthless here — CI and local WSL/mnt/cdisagree about case, andexistsSyncis case-blind on the latter. These assert on the strings the code produces: the pointer labels in the bootstrap JSON report,fs.readdirSyncentries (which report the case a file was created with), and the template title — each compared againstTARGET_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.No pre-existing test was skipped or weakened.
packages/cli/src/__tests__/integration/precommit-hook.test.ts:104is a hand-built fixture, not compared againsthook.ts, so it did not fail either way; updated so it does not drift from the real hook.🤖 Generated with Claude Code