Skip to content

feat(bin): encode project AGENTS.md authoring bar with canonical self-governance section - #307

Merged
kunchenguid merged 6 commits into
mainfrom
fm/fm-briefbar-a3
Jul 7, 2026
Merged

kunchenguid merged 6 commits into
mainfrom
fm/fm-briefbar-a3

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Encode the captain's 2026-07-06 AGENTS.md authoring bar into firstmate's shared tracked surfaces so every firstmate user inherits it. The intended contract is that project AGENTS.md files are only for knowledge useful to almost every future session, should not repeat details already discoverable from the codebase except as pointers to authoritative files or commands, should prefer rewriting or pruning over appending, and should instruct all agents how to maintain that bar. Keep the canonical short self-governance wording in bin/fm-ensure-agents-md.sh as the one owner, update bin/fm-brief.sh so ship briefs tell crewmates to apply the bar and add the self-governance section when touching project AGENTS.md files that lack it, and add only a concise principle plus pointer in shared AGENTS.md section 6. Extend colocated tests for fm-ensure-agents-md.sh and fm-brief.sh, keep additions tight, preserve one-sentence-per-line tracked Markdown and plain dashes, and ensure bin/.sh, bin/backends/.sh, and tests/*.sh pass shellcheck. This run includes the no-mistakes review fix that promotes existing CLAUDE.md files with the same canonical maintenance section instead of limiting the wording to newly created AGENTS.md files.

What Changed

  • bin/fm-ensure-agents-md.sh now owns the canonical ## Maintaining this file self-governance wording for project AGENTS.md files, appending it when creating the skeleton and when promoting an existing CLAUDE.md; the append is idempotent (already-present sections succeed as a no-op) and inserts a blank-line separator even when the promoted file lacks a trailing newline.
  • bin/fm-brief.sh ship briefs' Project memory section now states the authoring bar - record only knowledge useful to almost every future session, prefer pointers to authoritative files or commands over copied detail - and instructs crewmates to add the self-governance section from fm-ensure-agents-md.sh when a touched project AGENTS.md lacks it.
  • Shared AGENTS.md section 6, docs/architecture.md, and docs/scripts.md record the principle and point to the script as the one owner of the wording; new colocated tests cover skeleton creation, CLAUDE.md promotion, the newline-less separator case (asserting the heading is actually present), and the new ship-brief wording.

Risk Assessment

✅ Low: Well-bounded additive change (docs, one idempotent newline-safe script function, brief wording, colocated tests) already hardened through three review-fix rounds, with no remaining correctness, security, or behavioral risks found.

Testing

Baseline full test suite passed before this run; I re-ran the two colocated test files for the changed scripts (7 tests, all green) and then exercised the change the way a crewmate would experience it, capturing CLI transcripts: fm-ensure-agents-md.sh creates AGENTS.md with the canonical "## Maintaining this file" section, promotes an existing CLAUDE.md with the section appended (including the newline-less edge case with a proper blank-line separator), and is idempotent on re-run; a freshly scaffolded ship brief carries the authoring-bar and add-the-section-if-lacking wording; and shared AGENTS.md section 6 contains the principle plus pointer. No visual artifact applies since this is a CLI/markdown-contract change with no rendered UI surface; transcripts are the product-level evidence. No failures found.

Evidence: fm-ensure-agents-md.sh E2E transcript (create, promote, newline-less separator, idempotency)
=== E2E demo: bin/fm-ensure-agents-md.sh AGENTS.md authoring bar ===

--- Case 1: empty project (no AGENTS.md, no CLAUDE.md) ---
$ fm-ensure-agents-md.sh /tmp/fm-agents-bar-demo.P4wMh4/new-project
created: AGENTS.md and CLAUDE.md -> AGENTS.md in /private/tmp/fm-agents-bar-demo.P4wMh4/new-project

$ ls -l new-project
total 8
-rw-r--r--@ 1 kunchen  wheel  651 Jul  6 19:20 AGENTS.md
lrwxr-xr-x@ 1 kunchen  wheel    9 Jul  6 19:20 CLAUDE.md -> AGENTS.md

$ cat new-project/AGENTS.md
# Project agent memory

This file is the project's committed home for project-intrinsic agent knowledge: build, test, release, architecture, and sharp-edge notes that should travel with the code.

- Add durable project-specific notes here as they are discovered through real work.

## 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.

--- Case 2: existing hand-written CLAUDE.md gets promoted WITH the maintenance section ---
$ cat claude-project/CLAUDE.md (before)
# Existing agent memory

Run tests with `make test`.

$ fm-ensure-agents-md.sh /tmp/fm-agents-bar-demo.P4wMh4/claude-project
promoted: moved CLAUDE.md to AGENTS.md and symlinked CLAUDE.md -> AGENTS.md in /private<scratch>/claude-project

$ ls -l claude-project
total 8
-rw-r--r--@ 1 kunchen  wheel  423 Jul  6 19:20 AGENTS.md
lrwxr-xr-x@ 1 kunchen  wheel    9 Jul  6 19:20 CLAUDE.md -> AGENTS.md

$ cat claude-project/AGENTS.md (after promotion)
# Existing agent memory

Run tests with `make test`.

## 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.

--- Case 3: CLAUDE.md WITHOUT trailing newline still gets a clean blank-line separator ---
$ fm-ensure-agents-md.sh /tmp/fm-agents-bar-demo.P4wMh4/no-newline-project
promoted: moved CLAUDE.md to AGENTS.md and symlinked CLAUDE.md -> AGENTS.md in /private<scratch>/no-newline-project

$ cat no-newline-project/AGENTS.md
# Existing agent memory

Run tests with make test.

## 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.

--- Case 4: idempotency - re-running on an already-promoted project keeps exactly one section ---
$ fm-ensure-agents-md.sh /tmp/fm-agents-bar-demo.P4wMh4/claude-project  (second run)
unchanged: AGENTS.md with CLAUDE.md -> AGENTS.md in /private<scratch>/claude-project
$ grep -c '## Maintaining this file' claude-project/AGENTS.md
1
Evidence: fm-brief.sh generated ship brief Project-memory section + shared AGENTS.md section 6 wording
=== E2E demo: bin/fm-brief.sh ship brief carries the AGENTS.md authoring bar ===

$ FM_HOME=<scratch>/fmhome fm-brief.sh demo-task-x1 some-proj
warn: no registry at <scratch>/fmhome/data/projects.md; defaulting some-proj to no-mistakes off
scaffolded: <scratch>/fmhome/data/demo-task-x1/brief.md (ship, mode=no-mistakes; replace {TASK})

$ sed -n '/# Project memory/,/^$/p' <scratch>/fmhome/data/demo-task-x1/brief.md
# Project memory
If `AGENTS.md` or `CLAUDE.md` already exists, or if this task produced durable project-intrinsic knowledge, run `<FM_ROOT>/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` that lacks `## Maintaining this file`, add that short self-governance section from `<FM_ROOT>/bin/fm-ensure-agents-md.sh` in the same pass.
Keep it proportionate: skip `AGENTS.md` edits for trivial tasks that produced no durable project knowledge.


=== Shared AGENTS.md section 6 principle + pointer (added lines in context) ===

$ grep -n -A2 'only for knowledge useful to almost every future session' AGENTS.md
357:A project's `AGENTS.md` is only for knowledge useful to almost every future session in that repo.
358-Prefer a pointer to the authoritative file, command, or doc over repeating what the codebase already shows, and rewrite or prune stale entries instead of appending by default.
359-The canonical self-governance wording for project `AGENTS.md` files lives in `bin/fm-ensure-agents-md.sh`; this section states the principle and points there.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (3) ✅
  • ℹ️ bin/fm-brief.sh:259 - The canonical self-governance section is auto-appended only on AGENTS.md creation and CLAUDE.md promotion; for an existing AGENTS.md that lacks it (the most common fleet case), the ship brief tells crewmates to hand-transcribe the wording from the script's heredoc. There is no script-side append or --print-section accessor for that path, so each manual transcription is a drift vector against the stated one-owner goal. Consider a flag that prints or appends the canonical section so crewmates never copy prose by hand.
  • ℹ️ bin/fm-ensure-agents-md.sh:45 - ensure_maintenance_section returns 1 when the section already exists, but no caller consumes that value - both call sites must add '|| true' to survive set -eu, and a future unguarded call would silently abort the script mid-flow on the benign already-present case. Returning 0 unconditionally removes the set -e trap and the '|| true' noise.

🔧 Fix: make ensure_maintenance_section idempotent-success, drop || true guards
1 info still open:

  • ℹ️ bin/fm-ensure-agents-md.sh:48 - When a promoted CLAUDE.md lacks a trailing newline, the appended section's printf &#39;\n&#39; only terminates the dangling last line, so the ## Maintaining this file heading is glued directly to the previous content line with no blank separator (verified by running the script on such a file). Still parses as an ATX heading, but produces a malformed-looking committed file. Fix mechanically: if the file is non-empty and its last byte is not a newline, emit two newlines before the section instead of one.

🔧 Fix: separate appended maintenance section on newline-less CLAUDE.md promotion
1 info still open:

  • ℹ️ tests/fm-ensure-agents-md.test.sh:62 - The newline-less-promotion separator test passes vacuously if the maintenance section is never appended: when the heading is absent, grep -B1 -Fx produces no output, before is empty, and [ -z &#34;$before&#34; ] succeeds. Assert the heading is present (e.g. assert_grep &#39;## Maintaining this file&#39; &#34;$agents&#34; ...) before the blank-separator check so a section-not-appended regression on this path fails the test instead of slipping through.

🔧 Fix: assert maintenance heading present before separator check in test
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • Baseline (pre-run): full suite for t in tests/*.test.sh; do bash &#34;$t&#34;; done passed
  • bash tests/fm-ensure-agents-md.test.sh - 3 behavior tests for creation, promotion, and newline-less separator, all pass
  • bash tests/fm-brief.test.sh - 4 tests including the new ship project-memory wording test, all pass
  • Manual E2E: ran bin/fm-ensure-agents-md.sh against a fresh empty project - AGENTS.md created with the full ## Maintaining this file section and CLAUDE.md symlink
  • Manual E2E: ran it against a hand-written CLAUDE.md - promoted to AGENTS.md with original content preserved plus exactly one appended maintenance section
  • Manual E2E: ran it against a CLAUDE.md with no trailing newline - blank-line separator inserted before the maintenance heading
  • Manual E2E: re-ran on the promoted project - reports unchanged, section count stays 1 (idempotent)
  • Manual E2E: scaffolded a real ship brief via FM_HOME=&lt;tmp&gt; bin/fm-brief.sh demo-task-x1 some-proj and inspected its # Project memory section for the authoring-bar and add-if-lacking wording
  • Inspected shared AGENTS.md section 6 for the added principle and pointer lines (AGENTS.md:357-359)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.