Skip to content

fix(bin): keep a project's existing agent guide in place instead of relocating it - #3

Merged
karimghabra merged 3 commits into
mainfrom
fm/fm-agents-md-scaffold-scope
Sep 11, 2026
Merged

karimghabra merged 3 commits into
mainfrom
fm/fm-agents-md-scaffold-scope

Conversation

@karimghabra

@karimghabra karimghabra commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Intent

Twice in one day a ship worker relocated a project's CLAUDE.md into a new AGENTS.md and left a two-line import behind, on branches that had nothing to do with documentation layout. Both times the review correctly flagged it as unrequested by the stated intent. On the first branch firstmate accepted it because that branch was already large and the marginal cost was near zero; on the second it was the majority of the diff, in a production repository the captain reviews personally, and firstmate had it reverted.

Neither worker overreached. The prompt comes from firstmate's own generated ship brief, which instructs a worker to run bin/fm-ensure-agents-md.sh whenever AGENTS.md or CLAUDE.md exists. The worker reads that as licence to restructure a working file.

The instruction is trying to do something good: make sure a project has a guide, and give durable knowledge a home. It is the relocation that is unwanted.

What Changed

  • bin/fm-ensure-agents-md.sh no longer moves an existing guide. A real CLAUDE.md with its own content stays the project's guide at its current path and only gets the ## Maintaining this file section added. A correct CLAUDE.md -> AGENTS.md symlink stays a symlink. The helper still creates AGENTS.md and the @AGENTS.md pointer when a project has no working guide, and still adds a missing pointer next to an existing AGENTS.md. Every successful run now ends with a guide: <absolute path> line naming the file to write knowledge into. The conflict messages (case-variant agents.md, two real guide files) now say to record the knowledge by hand where it already lives, and to rename or merge files only in a separate change.
  • The ship brief's "Project memory" section in bin/fm-brief.sh now tells the worker to run the helper only when the task produced durable project knowledge, not whenever AGENTS.md or CLAUDE.md exists. The worker records that knowledge in the file the guide: line names. The brief also forbids relocating, renaming, merging, or restructuring an existing AGENTS.md/CLAUDE.md as part of the task.
  • AGENTS.md, the stow skill, docs/architecture.md, and docs/scripts.md now say "agent guide" instead of a project's AGENTS.md, and state that moving a working guide is a change of its own. In tests/, the old promotion and symlink-migration cases are replaced with cases where an existing CLAUDE.md stays at its path and knowledge reaches the existing guide. There is also a new brief test that the ship prompt keeps an existing CLAUDE.md in place.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is limited to a crewmate worktree helper, the ship-brief wording, and prose; the helper no longer has any path that moves a real CLAUDE.md or replaces a working symlink; the recorded round-1 decisions are fully applied (the --migrate-layout flag is gone and default mode adds the missing pointer); and every success path ends with the guide line and is covered by behavior tests.

Testing

I drove the real helper CLI and the real brief generator in isolated temporary git projects and FM_HOME directories, comparing the base commit with the target commit. Base: a CLAUDE.md-only project was promoted to AGENTS.md with a pointer left behind, and a correct symlink was replaced by a pointer file. Target: CLAUDE.md stays in place with only the self-governance section appended, and the symlink stays a symlink. AGENTS.md-only still gains the pointer, as the user decided. No-guide and pointer-only projects still get the full scaffold. The conflict cases still refuse and touch nothing, and their messages now say to leave the guide where it is. Reruns change nothing, CRLF line endings are preserved, the project mark is respected, and --migrate-layout is rejected. The generated target ship brief ties the helper to durable knowledge only and forbids relocation. A worker who follows the brief's own command in a CLAUDE.md-only repo produces a diff that touches only CLAUDE.md plus their unrelated work, with no AGENTS.md. Both targeted test files pass on the target. Run against the base tree, they fail. This is a CLI and generated-text change, so text transcripts are the right evidence; there is no UI to screenshot. The overall result is go.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Project whose only guide is a real CLAUDE.md: the helper keeps it in place, only appends the self-governance section, creates no AGENTS.md, and prints guide: <abs>/CLAUDE.md (the base helper relocated… ✅ pass live helper-layout-transcript.txt (claude-only base vs target); helper-edge-cases-transcript.txt (git diff shows appended lines only)
Correct CLAUDE.md -> AGENTS.md symlink: stays a symlink, AGENTS.md gains the section, guide line names AGENTS.md (the base helper replaced the symlink with a pointer file) ✅ pass live helper-layout-transcript.txt (claude-symlink); helper-edge-cases-transcript.txt (second run unchanged, still lrwxrwxrwx CLAUDE.md -> AGENTS.md)
AGENTS.md with no CLAUDE.md: the helper still adds the two-line CLAUDE.md @AGENTS.md pointer and moves nothing (user decision) ✅ pass live helper-layout-transcript.txt (agents-only target: wrote pointer, guide: AGENTS.md)
Project with no guide, or with only the canonical pointer: the helper still creates the AGENTS.md skeleton and pointer and names AGENTS.md ✅ pass live helper-layout-transcript.txt (none, pointer-only)
Adversarial: both real files, lowercase agents.md, or a wrong symlink: the helper refuses with a conflict, touches no file, and the message says not to relocate inside the task ✅ pass live helper-layout-transcript.txt (both-real, lowercase-agents, wrong-symlink: exit 1, git status empty)
Adversarial: running the removed --migrate-layout flag on a CLAUDE.md-only project is rejected and relocates nothing ✅ pass live helper-edge-cases-transcript.txt (usage printed or 'not a directory', exit 1, only CLAUDE.md remains)
Rerunning the helper on a kept guide is a no-op (no duplicate section, clean git status); CRLF and project-marked guides are preserved ✅ pass live helper-edge-cases-transcript.txt (idempotence, CRLF lines-without-CR=0); helper-layout-transcript.txt (claude-only-marked unchanged)
Generated ship brief no longer tells workers to run the helper just because AGENTS.md or CLAUDE.md exists: it runs only for durable knowledge and forbids relocating or restructuring an existing guide ✅ pass live brief-project-memory-base-vs-target.txt; bash tests/fm-brief.test.sh
Worker follows the brief's own command during unrelated work in a CLAUDE.md-only production repo: the branch diff touches only CLAUDE.md (knowledge appended) and the worker's own files, with no AGENTS… ✅ pass live worker-follows-brief-e2e.txt; bash tests/fm-brief.test.sh (test_ship_project_memory_command_keeps_existing_claude_md)
Evidence: Helper layout transcript: base vs target across 10 guide layouts

Source: Helper layout transcript: base vs target across 10 guide layouts

=== [base] case: claude-only
  before:
    CLAUDE.md (regular file, 4 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | promoted: moved CLAUDE.md to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-claude-only
  after:
    AGENTS.md (regular file, 11 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M CLAUDE.md ?? AGENTS.md 
=== [target] case: claude-only
  before:
    CLAUDE.md (regular file, 4 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to CLAUDE.md in /tmp/fm-agents-live.xf2a/target-claude-only
    | guide: /tmp/fm-agents-live.xf2a/target-claude-only/CLAUDE.md
  after:
    CLAUDE.md (regular file, 11 lines, maint-sections=1)
    git status:  M CLAUDE.md 

=== [base] case: claude-only-crlf
  before:
    CLAUDE.md (regular file, 3 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | promoted: moved CLAUDE.md to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-claude-only-crlf
  after:
    AGENTS.md (regular file, 10 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M CLAUDE.md ?? AGENTS.md 
=== [target] case: claude-only-crlf
  before:
    CLAUDE.md (regular file, 3 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to CLAUDE.md in /tmp/fm-agents-live.xf2a/target-claude-only-crlf
    | guide: /tmp/fm-agents-live.xf2a/target-claude-only-crlf/CLAUDE.md
  after:
    CLAUDE.md (regular file, 10 lines, maint-sections=1)
    git status:  M CLAUDE.md 

=== [base] case: claude-only-marked
  before:
    CLAUDE.md (regular file, 4 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | promoted: moved CLAUDE.md to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-claude-only-marked
  after:
    AGENTS.md (regular file, 4 lines, maint-sections=0)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M CLAUDE.md ?? AGENTS.md 
=== [target] case: claude-only-marked
  before:
    CLAUDE.md (regular file, 4 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | unchanged: CLAUDE.md in /tmp/fm-agents-live.xf2a/target-claude-only-marked
    | guide: /tmp/fm-agents-live.xf2a/target-claude-only-marked/CLAUDE.md
  after:
    CLAUDE.md (regular file, 4 lines, maint-sections=0)
    git status: 

=== [base] case: claude-symlink
  before:
    AGENTS.md (regular file, 3 lines, maint-sections=0)
    CLAUDE.md -> symlink to AGENTS.md
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-claude-symlink
  after:
    AGENTS.md (regular file, 10 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M AGENTS.md  T CLAUDE.md 
=== [target] case: claude-symlink
  before:
    AGENTS.md (regular file, 3 lines, maint-sections=0)
    CLAUDE.md -> symlink to AGENTS.md
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to AGENTS.md in /tmp/fm-agents-live.xf2a/target-claude-symlink
    | guide: /tmp/fm-agents-live.xf2a/target-claude-symlink/AGENTS.md
  after:
    AGENTS.md (regular file, 10 lines, maint-sections=1)
    CLAUDE.md -> symlink to AGENTS.md
    git status:  M AGENTS.md 

=== [base] case: agents-only
  before:
    AGENTS.md (regular file, 3 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-agents-only
  after:
    AGENTS.md (regular file, 10 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M AGENTS.md ?? CLAUDE.md 
=== [target] case: agents-only
  before:
    AGENTS.md (regular file, 3 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | updated: added ## Maintaining this file to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/target-agents-only
    | guide: /tmp/fm-agents-live.xf2a/target-agents-only/AGENTS.md
  after:
    AGENTS.md (regular file, 10 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status:  M AGENTS.md ?? CLAUDE.md 

=== [base] case: none
  before:
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | created: AGENTS.md and CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-none
  after:
    AGENTS.md (regular file, 12 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: ?? AGENTS.md ?? CLAUDE.md 
=== [target] case: none
  before:
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | created: AGENTS.md and CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/target-none
    | guide: /tmp/fm-agents-live.xf2a/target-none/AGENTS.md
  after:
    AGENTS.md (regular file, 12 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: ?? AGENTS.md ?? CLAUDE.md 

=== [base] case: pointer-only
  before:
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | created: AGENTS.md and kept CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/base-pointer-only
  after:
    AGENTS.md (regular file, 12 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: ?? AGENTS.md 
=== [target] case: pointer-only
  before:
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 0)
    | created: AGENTS.md and kept CLAUDE.md @AGENTS.md pointer in /tmp/fm-agents-live.xf2a/target-pointer-only
    | guide: /tmp/fm-agents-live.xf2a/target-pointer-only/AGENTS.md
  after:
    AGENTS.md (regular file, 12 lines, maint-sections=1)
    CLAUDE.md (regular file, 2 lines, maint-sections=0)
    git status: ?? AGENTS.md 

=== [base] case: both-real
  before:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: both AGENTS.md and CLAUDE.md are real files in /tmp/fm-agents-live.xf2a/base-both-real; reconcile them manually
  after:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
=== [target] case: both-real
  before:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: both AGENTS.md and CLAUDE.md are real guide files in /tmp/fm-agents-live.xf2a/target-both-real; record knowledge by hand in the one the project uses for it, and merge them only in a change of its own
  after:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 

=== [base] case: lowercase-agents
  before:
    agents.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: memory file is named agents.md in /tmp/fm-agents-live.xf2a/base-lowercase-agents but the convention is AGENTS.md; rename it to AGENTS.md so CLAUDE.md's @AGENTS.md pointer resolves portably
  after:
    agents.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
=== [target] case: lowercase-agents
  before:
    agents.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: memory file is named agents.md in /tmp/fm-agents-live.xf2a/target-lowercase-agents but the convention is AGENTS.md; record knowledge by hand in agents.md where it is, and rename it to AGENTS.md only in a change of its own so CLAUDE.md's @AGENTS.md pointer resolves portably
  after:
    agents.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md (regular file, 1 lines, maint-sections=0)
    git status: 

=== [base] case: wrong-symlink
  before:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md -> symlink to OTHER.md
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: CLAUDE.md is a symlink in /tmp/fm-agents-live.xf2a/base-wrong-symlink but does not point to AGENTS.md
  after:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md -> symlink to OTHER.md
    git status: 
=== [target] case: wrong-symlink
  before:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md -> symlink to OTHER.md
    git status: 
  $ fm-ensure-agents-md.sh .   (exit 1)
    | conflict: CLAUDE.md is a symlink in /tmp/fm-agents-live.xf2a/target-wrong-symlink but does not point to AGENTS.md
  after:
    AGENTS.md (regular file, 1 lines, maint-sections=0)
    CLAUDE.md -> symlink to OTHER.md
    git status: 
Evidence: Helper edge cases: append-only diff, CRLF, rerun, removed --migrate-layout, --help

Source: Helper edge cases: append-only diff, CRLF, rerun, removed --migrate-layout, --help

\### Kept CLAUDE.md: git diff after first run (existing content untouched, only appended)
diff --git a/CLAUDE.md b/CLAUDE.md
index ad236d2..2d6c701 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2,3 +2,10 @@
 
 Run tests with make test.
 Deploy with ./deploy.sh.
+
+## Maintaining this file
+
+Keep this file for knowledge useful to almost every future agent session in this project.
+Do not repeat what the codebase already shows; point to the authoritative file or command instead.
+Prefer rewriting or pruning existing entries over appending new ones.
+When updating this file, preserve this bar for all agents and keep entries concise.

\### CRLF CLAUDE.md: every line keeps CRLF (count of lines lacking \r)
lines total=10 lines-without-CR=0

\### Idempotence: second run on kept CLAUDE.md
unchanged: CLAUDE.md in /tmp/fm-agents-live.xf2a/target-claude-only
guide: /tmp/fm-agents-live.xf2a/target-claude-only/CLAUDE.md
exit 0
maint-sections=1
git status: []
CLAUDE.md

\### Idempotence: second run on kept CLAUDE.md -> AGENTS.md symlink
unchanged: AGENTS.md in /tmp/fm-agents-live.xf2a/target-claude-symlink
guide: /tmp/fm-agents-live.xf2a/target-claude-symlink/AGENTS.md
exit 0
lrwxrwxrwx CLAUDE.md -> AGENTS.md
git status: []

\### Removed flag: --migrate-layout on a CLAUDE.md-only project
usage: fm-ensure-agents-md.sh [repo-or-worktree-dir]

The helper creates AGENTS.md and a CLAUDE.md @AGENTS.md pointer when the
project has no agent guide, adds a missing pointer beside an existing AGENTS.md,
and otherwise keeps the existing guide at its path, only adding the
self-governance section to it. It never moves a guide. The final
"guide: <path>" line names the file to record durable project knowledge in.

To retain equivalent project-owned maintenance guidance without adding the
canonical section, use this exact first line of the guide (LF or CRLF):
<!-- firstmate:maintained-by-project -->
The mark declares retained guidance, not permission to remove governance.
Without the first-line mark or exact canonical heading, the helper adds the section.
exit 1
CLAUDE.md
error: not a directory: --migrate-layout
exit 1
CLAUDE.md

\### Directory argument from elsewhere (brief uses '.', but path arg must work too)
updated: added ## Maintaining this file to CLAUDE.md in /tmp/fm-agents-live.xf2a/target-arg
guide: /tmp/fm-agents-live.xf2a/target-arg/CLAUDE.md
exit 0
CLAUDE.md

\### --help text
usage: fm-ensure-agents-md.sh [repo-or-worktree-dir]

The helper creates AGENTS.md and a CLAUDE.md @AGENTS.md pointer when the
project has no agent guide, adds a missing pointer beside an existing AGENTS.md,
and otherwise keeps the existing guide at its path, only adding the
self-governance section to it. It never moves a guide. The final
"guide: <path>" line names the file to record durable project knowledge in.

To retain equivalent project-owned maintenance guidance without adding the
canonical section, use this exact first line of the guide (LF or CRLF):
<!-- firstmate:maintained-by-project -->
The mark declares retained guidance, not permission to remove governance.
Without the first-line mark or exact canonical heading, the helper adds the section.
Evidence: Generated ship brief '# Project memory' section, base vs target

Source: Generated ship brief '# Project memory' section, base vs target

===== [base] generated ship brief: '# Project memory' section (/tmp/fm-agents-live.xf2a/brief-home-base/data/live-brief-base/brief.md)
# Project memory
If `AGENTS.md` or `CLAUDE.md` already exists, or if this task produced durable project-intrinsic knowledge, run `/tmp/fm-agents-live.xf2a/base-tree/bin/fm-ensure-agents-md.sh .` in the worktree.
Record only project knowledge useful to almost every future session.
For anything the codebase already shows, prefer a pointer to the authoritative file, command, or doc over copying the detail.
If you touch a project `AGENTS.md`, follow `/tmp/fm-agents-live.xf2a/base-tree/bin/fm-ensure-agents-md.sh`'s self-governance contract in the same pass.
Keep it proportionate: skip `AGENTS.md` edits for trivial tasks that produced no durable project knowledge.


===== [target] generated ship brief: '# Project memory' section (/tmp/fm-agents-live.xf2a/brief-home-target/data/live-brief-target/brief.md)
# Project memory
If this task produced durable project-intrinsic knowledge, run `~/.no-mistakes/worktrees/a8c0c72d0935/01M28052W3RM6R1YPGVSBKVPD8/bin/fm-ensure-agents-md.sh .` in the worktree and record that knowledge in the file its final `guide:` line names, at that existing path; if it reports a conflict instead, record the knowledge by hand in the guide file the project already uses.
Never relocate, rename, merge, or restructure an existing `AGENTS.md` or `CLAUDE.md` in this task: a guide-layout change is a change of its own, never part of unrelated work.
Record only project knowledge useful to almost every future session.
For anything the codebase already shows, prefer a pointer to the authoritative file, command, or doc over copying the detail.
When you touch the project guide, follow `~/.no-mistakes/worktrees/a8c0c72d0935/01M28052W3RM6R1YPGVSBKVPD8/bin/fm-ensure-agents-md.sh`'s self-governance contract in the same pass.
Keep it proportionate: skip the helper and the guide entirely for tasks that produced no durable project knowledge.
Evidence: Worker follows the brief's command in a CLAUDE.md-only repo: resulting diff

Source: Worker follows the brief's command in a CLAUDE.md-only repo: resulting diff

\### Worker follows the generated ship brief's project-memory command in a CLAUDE.md-only production repo
command extracted from brief: ~/.no-mistakes/worktrees/a8c0c72d0935/01M28052W3RM6R1YPGVSBKVPD8/bin/fm-ensure-agents-md.sh .
(unrelated work) editing src/app.py
  | updated: added ## Maintaining this file to CLAUDE.md in /tmp/fm-agents-live.xf2a/worker-e2e
  | guide: /tmp/fm-agents-live.xf2a/worker-e2e/CLAUDE.md
recorded knowledge into: /tmp/fm-agents-live.xf2a/worker-e2e/CLAUDE.md
--- git status --porcelain (branch diff a reviewer would see)
 M CLAUDE.md
 M src/app.py
--- git diff --stat
 CLAUDE.md  | 8 ++++++++
 src/app.py | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)
--- AGENTS.md exists? no
Evidence: New tests fail against the base helper and brief (regression reproduced)

Source: New tests fail against the base helper and brief (regression reproduced)

\### target-branch tests run against the BASE (6705ed2) helper and brief - expected to fail
not ok - a created guide was not named as the file to record knowledge in (expected '/tmp/fm-ensure-agents-md.iDhBLd/new-project/AGENTS.md', got '')
exit 1
not ok - project-memory contract no longer ties the helper to durable knowledge
Evidence: Live driver script used for the layout transcript

Source: Live driver script used for the layout transcript

#!/usr/bin/env bash
# Live driver: runs bin/fm-ensure-agents-md.sh (target) and the base-commit
# helper against fresh git project fixtures and prints a transcript of the
# resulting file layout for each guide shape.
set -u
WT=~/.no-mistakes/worktrees/a8c0c72d0935/01M28052W3RM6R1YPGVSBKVPD8
NEW="$WT/bin/fm-ensure-agents-md.sh"
BASE="$1"
SCRATCH="$2"

layout() {
  local d=$1
  (cd "$d" && for f in AGENTS.md agents.md CLAUDE.md; do
    if [ -L "$f" ]; then echo "    $f -> symlink to $(readlink "$f")";
    elif [ -f "$f" ]; then echo "    $f (regular file, $(wc -l < "$f") lines, maint-sections=$(grep -c '^## Maintaining this file' "$f"))";
    fi
  done)
  echo "    git status: $(cd "$d" && git status --porcelain | tr '\n' ' ')"
}

mkproj() {
  local d=$1
  rm -rf "$d"; mkdir -p "$d"
  (cd "$d" && git init -q && git config user.email t@t && git config user.name t)
}

commit() { (cd "$1" && git add -A && git commit -qm seed); }

setup_case() {
  local name=$1 d=$2
  mkproj "$d"
  case "$name" in
    claude-only)
      printf '# Project guide\n\nRun tests with make test.\nDeploy with ./deploy.sh.\n' > "$d/CLAUDE.md" ;;
    claude-only-crlf)
      printf '# Project guide\r\n\r\nRun tests with make test.\r\n' > "$d/CLAUDE.md" ;;
    claude-only-marked)
      printf '<!-- firstmate:maintained-by-project -->\n# Guide\n\nOwn maintenance rules.\n' > "$d/CLAUDE.md" ;;
    claude-symlink)
      printf '# Agents guide\n\nUse pnpm.\n' > "$d/AGENTS.md"; ln -s AGENTS.md "$d/CLAUDE.md" ;;
    agents-only)
      printf '# Agents guide\n\nUse pnpm.\n' > "$d/AGENTS.md" ;;
    none)
      printf 'hello\n' > "$d/README.md" ;;
    pointer-only)
      printf '<!-- Points Claude at AGENTS.md via import; edit AGENTS.md, not this file. -->\[email protected]\n' > "$d/CLAUDE.md" ;;
    both-real)
      printf '# Agents\n' > "$d/AGENTS.md"; printf '# Claude\n' > "$d/CLAUDE.md" ;;
    lowercase-agents)
      printf '# agents lower\n' > "$d/agents.md"; printf '# Claude guide\n' > "$d/CLAUDE.md" ;;
    wrong-symlink)
      printf '# Other\n' > "$d/OTHER.md"; printf '# Agents\n' > "$d/AGENTS.md"; ln -s OTHER.md "$d/CLAUDE.md" ;;
  esac
  commit "$d"
}

run_case() {
  local name=$1 helper=$2 label=$3
  local d="$SCRATCH/$label-$name"
  setup_case "$name" "$d"
  echo "=== [$label] case: $name"
  echo "  before:"; layout "$d"
  local out rc
  out=$(cd "$d" && "$helper" . 2>&1); rc=$?
  echo "  \$ fm-ensure-agents-md.sh .   (exit $rc)"
  printf '%s\n' "$out" | sed 's/^/    | /'
  echo "  after:"; layout "$d"
}

for c in claude-only claude-only-crlf claude-only-marked claude-symlink agents-only none pointer-only both-real lowercase-agents wrong-symlink; do
  run_case "$c" "$BASE" base
  run_case "$c" "$NEW" target
  echo
done
Evidence: Key before/after: CLAUDE.md-only project
[base] promoted: moved CLAUDE.md to AGENTS.md and wrote CLAUDE.md @AGENTS.md pointer -> git status: M CLAUDE.md ?? AGENTS.md
[target] updated: added ## Maintaining this file to CLAUDE.md
guide: .../target-claude-only/CLAUDE.md -> git status: M CLAUDE.md (no AGENTS.md)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Project whose only guide is a real CLAUDE.md: the helper keeps it in place, only appends the self-governance section, creates no AGENTS.md, and prints guide: <abs>/CLAUDE.md (the base helper relocated… ✅ pass live helper-layout-transcript.txt (claude-only base vs target); helper-edge-cases-transcript.txt (git diff shows appended lines only)
Correct CLAUDE.md -> AGENTS.md symlink: stays a symlink, AGENTS.md gains the section, guide line names AGENTS.md (the base helper replaced the symlink with a pointer file) ✅ pass live helper-layout-transcript.txt (claude-symlink); helper-edge-cases-transcript.txt (second run unchanged, still lrwxrwxrwx CLAUDE.md -> AGENTS.md)
AGENTS.md with no CLAUDE.md: the helper still adds the two-line CLAUDE.md @AGENTS.md pointer and moves nothing (user decision) ✅ pass live helper-layout-transcript.txt (agents-only target: wrote pointer, guide: AGENTS.md)
Project with no guide, or with only the canonical pointer: the helper still creates the AGENTS.md skeleton and pointer and names AGENTS.md ✅ pass live helper-layout-transcript.txt (none, pointer-only)
Adversarial: both real files, lowercase agents.md, or a wrong symlink: the helper refuses with a conflict, touches no file, and the message says not to relocate inside the task ✅ pass live helper-layout-transcript.txt (both-real, lowercase-agents, wrong-symlink: exit 1, git status empty)
Adversarial: running the removed --migrate-layout flag on a CLAUDE.md-only project is rejected and relocates nothing ✅ pass live helper-edge-cases-transcript.txt (usage printed or 'not a directory', exit 1, only CLAUDE.md remains)
Rerunning the helper on a kept guide is a no-op (no duplicate section, clean git status); CRLF and project-marked guides are preserved ✅ pass live helper-edge-cases-transcript.txt (idempotence, CRLF lines-without-CR=0); helper-layout-transcript.txt (claude-only-marked unchanged)
Generated ship brief no longer tells workers to run the helper just because AGENTS.md or CLAUDE.md exists: it runs only for durable knowledge and forbids relocating or restructuring an existing guide ✅ pass live brief-project-memory-base-vs-target.txt; bash tests/fm-brief.test.sh
Worker follows the brief's own command during unrelated work in a CLAUDE.md-only production repo: the branch diff touches only CLAUDE.md (knowledge appended) and the worker's own files, with no AGENTS… ✅ pass live worker-follows-brief-e2e.txt; bash tests/fm-brief.test.sh (test_ship_project_memory_command_keeps_existing_claude_md)
  • bash drive-helper.sh (evidence dir): ran the base (6705ed2) and target helpers on fresh git projects covering 10 layouts: claude-only, claude-only CRLF, claude-only with the project mark, correct CLAUDE.md symlink, agents-only, no guide, pointer-only, both real, lowercase agents.md, wrong symlink
  • Checked the kept CLAUDE.md with git diff (only appended), checked CRLF preservation, ran the helper twice on the kept CLAUDE.md and on the symlink layout, ran --migrate-layout (with and without a directory), passed a directory path from another cwd, and ran --help
  • FM_HOME=&lt;isolated&gt; bin/fm-brief.sh live-brief-&lt;label&gt; some-proj --mode no-mistakes with both the base and target trees, then compared the '# Project memory' sections
  • Worker end-to-end: ran the command taken from the generated target brief in a CLAUDE.md-only repo during unrelated work, recorded knowledge at the named guide: path, then checked git status and git diff --stat
  • bash tests/fm-ensure-agents-md.test.sh
  • bash tests/fm-brief.test.sh
  • Ran the target branch's tests/fm-ensure-agents-md.test.sh and tests/fm-brief.test.sh against the base tree to confirm they fail there
  • grep -rn fm-ensure-agents-md across bin/docs/skills to confirm no other caller still runs the helper whenever a guide exists
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ating it

The ship brief told workers to run fm-ensure-agents-md.sh whenever AGENTS.md
or CLAUDE.md existed, and the helper itself moved a real CLAUDE.md into a new
AGENTS.md and left a two-line import behind. Following the brief exactly
therefore bundled a guide relocation into unrelated feature branches.

The helper now creates AGENTS.md and the CLAUDE.md pointer only when a project
has no working guide, keeps an existing guide at its path (adding only the
self-governance section), and names the file to record knowledge in on a final
guide: line. Relocation, adding a pointer beside an existing AGENTS.md, and
replacing a CLAUDE.md symlink move behind an explicit --migrate-layout flag for
a change whose purpose is that relocation.

The brief now runs the helper only when the task produced durable knowledge,
records it in the guide the helper names, and forbids relocating or
restructuring an existing guide inside the task.
@karimghabra
karimghabra force-pushed the fm/fm-agents-md-scaffold-scope branch from 176df07 to 7059cb4 Compare September 11, 2026 09:51
@karimghabra
karimghabra merged commit 11556d1 into main Sep 11, 2026
27 of 28 checks passed
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.

1 participant