beads/cmd/bd/setup
matt wilkie 21ca92db6b
fix(setup): don't read a fenced @AGENTS.md example as a redirect stub (#5222)
#4838 taught `bd setup claude` to detect a CLAUDE.md that is a thin stub
importing AGENTS.md, and to write the managed beads block to AGENTS.md instead.
isAgentsImportStub decides that by scanning for "@AGENTS.md" on its own line,
with no notion of code blocks — so a CLAUDE.md that merely *documents* the
pattern in a fenced example is classified as a stub.

That is not a cosmetic misread. Once the redirect activates, stripStaleClaudeBlock
removes the managed block from CLAUDE.md, on the reasoning that AGENTS.md now
owns it. For a file that was in fact authoritative, a documentation example
silently moves the block out of it. The new end-to-end test is the one that
matters here: against the parent commit it fails with

    CLAUDE.md is authoritative and must carry the beads block;
    a fenced example redirected it away

Skipping fenced regions also matches the semantics being detected: Claude Code
does not expand an @-import shown as code, so a fenced directive was never going
to make the file a stub in the first place.

Deliberately narrow in two places, both pinned by tests:

- Four-space-indented lines are still scanned. Indentation is ambiguous in a way
  a fence is not — it is equally a list continuation, which is a plausible home
  for a real directive — so treating it as code would trade this false positive
  for a false negative. "indented directive still counts" pins that.
- A closing fence must match the character that opened the block, so ``` inside a
  ~~~ block does not terminate it and let a following directive leak through.
  An unterminated fence swallows the rest of the file, which is also what a
  Markdown renderer does, so the conservative answer there is the correct one
  rather than an accident. Both are pinned.

Five of the seven new unit cases fail against the parent commit; the two that
pass in both directions are the over-correction guards ("real directive after a
fenced example still counts", "indented directive still counts") and exist so a
future fix cannot go too far the other way.

This closes the last of the two nits left open on #4838's review; the other
(path-qualified "@./AGENTS.md") was already handled before that PR merged.

Note for whoever looks at CI: `main` is currently red on Test (macos-latest) for
three unrelated failures — see #5210 and #5220. This branch touches only
cmd/bd/setup and does not go near them.

Agent-Signature: claude-opus-5-high on behalf of maphew
2026-08-02 02:04:56 -07:00
..
agent_skill.go cleanup: remove unused private helpers (#4205) 2026-05-27 17:53:16 -07:00
agents.go test(dolt): add TestNoPushSkipsDoltPush for push guard coverage (#4323) 2026-06-20 13:23:40 -07:00
agents_marker_test.go fix(setup): clarify symlinked agents skip 2026-05-27 12:51:57 -07:00
aider.go fix(cli): printed doc paths point at the new docs locations 2026-07-12 10:37:17 -07:00
aider_test.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
claude.go fix(setup): don't read a fenced @AGENTS.md example as a redirect stub (#5222) 2026-08-02 02:04:56 -07:00
claude_test.go fix(setup): don't read a fenced @AGENTS.md example as a redirect stub (#5222) 2026-08-02 02:04:56 -07:00
codex.go fix(setup): migrate legacy Codex session hook (#4953) 2026-07-22 21:20:04 -07:00
codex_test.go fix(setup): migrate legacy Codex session hook (#4953) 2026-07-22 21:20:04 -07:00
constants.go feat: add context optimization features for AI agents (#297) 2025-11-12 10:48:36 -08:00
cursor.go feat(cursor): bring Cursor integration to parity with Claude/Codex (#4649) 2026-07-10 13:10:46 -07:00
cursor_test.go feat(cursor): bring Cursor integration to parity with Claude/Codex (#4649) 2026-07-10 13:10:46 -07:00
exit.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
factory.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
factory_test.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
gemini.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
gemini_test.go fix(setup): finish hook JSON migration 2026-05-08 09:21:39 -07:00
hooks_json.go feat(cursor): bring Cursor integration to parity with Claude/Codex (#4649) 2026-07-10 13:10:46 -07:00
junie.go feat: add bd unclaim command to release stuck issues (replaces #3694) (#4614) 2026-07-06 22:51:35 -07:00
junie_test.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
mux.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
mux_test.go fix(setup): harden symlink follow-up handling 2026-05-27 13:32:00 -07:00
opencode.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
opencode_test.go feat: add OpenCode recipe to bd setup 2026-03-03 13:39:56 -07:00
plugin_layout_test.go fix(plugin): make command argument hints strings (#4969) 2026-07-22 21:48:45 -07:00
setup_test_helpers.go : refactor to use RunE, emit usage metrics, skip metrics in CI 2026-06-22 20:44:43 +00:00
utils.go fix(setup): harden symlink follow-up handling 2026-05-27 13:32:00 -07:00
utils_test.go fix(setup): harden symlink follow-up handling 2026-05-27 13:32:00 -07:00