fix(agents-init): require a git repo to scaffold, and anchor the .gitignore fallback match #153

Merged
rootiest merged 2 commits from fix/agents-init-nongit-and-gitignore-anchor into main 2026-09-16 23:09:01 +00:00
Owner

Tasks 10 and 11 of AGENTS/plans/2026-09-02-agent-memory-vault.md. Both were deliberately held back from feat/agent-memory-vault because their tests need tests/test-agents-vault.fish, which only existed on that branch. The vault PR has merged, so they can land now.

The plan asked for two branches. Both fixes are one-liners in the same function family, so they share this branch as two separate commits.

1. Only scaffold inside a git repository

functions/agents-init.fish resolved its target root to (pwd) whenever git rev-parse --show-toplevel came up empty. Because the function runs from an agent-CLI wrapper, something as incidental as claude --version in an arbitrary directory created an AGENTS/ git repo, an AGENTS.md, two root symlinks, and a docs/ tree there.

Scaffolding now requires either a git repository or a directory that already has an AGENTS.md, CLAUDE.md, or AGENTS/ — the pre-existing-file case keeps working for projects that are intentionally not under git. Anywhere else the function is a no-op that returns 0, printing a dim skip line in verbose mode only.

2. Anchor the .gitignore fallback match

functions/_agents_init_ensure_gitignore.fish uses git check-ignore for accurate rule matching, but falls back to a plain grep -qF when the root is not a git repository. A substring match treats a negation line such as !AGENTS/foo as proof that the pattern AGENTS/ is already ignored, so the real rule was never appended. The fallback now matches whole lines (grep -qxF).

Verification

Three new checks in tests/test-agents-vault.fish, each confirmed failing before its fix and passing after:

  • no scaffold in a non-git dir
  • an existing AGENTS.md still scaffolds
  • negation does not count as ignored
fish tests/test-agents-vault.fish   320/320 passed   (was 318/320 with the new tests failing)
fish tests/run-tests.fish           TOTAL: 753/753 assertions passed
python3 docs/verify-manual.py       84/84 passed

Section 5 of the manual is generated from the function headers, and both headers were updated in place; no prose page in docs/manual/** references agents-init.

Follow-up: the run-tests.fish line above was misread — the driver exited 1 on an indent lint failure despite the passing assertion total, which broke CI on main. Fixed in #154.

Tasks 10 and 11 of `AGENTS/plans/2026-09-02-agent-memory-vault.md`. Both were deliberately held back from `feat/agent-memory-vault` because their tests need `tests/test-agents-vault.fish`, which only existed on that branch. The vault PR has merged, so they can land now. The plan asked for two branches. Both fixes are one-liners in the same function family, so they share this branch as two separate commits. ## 1. Only scaffold inside a git repository `functions/agents-init.fish` resolved its target root to `(pwd)` whenever `git rev-parse --show-toplevel` came up empty. Because the function runs from an agent-CLI wrapper, something as incidental as `claude --version` in an arbitrary directory created an `AGENTS/` git repo, an `AGENTS.md`, two root symlinks, and a `docs/` tree there. Scaffolding now requires either a git repository or a directory that already has an `AGENTS.md`, `CLAUDE.md`, or `AGENTS/` — the pre-existing-file case keeps working for projects that are intentionally not under git. Anywhere else the function is a no-op that returns 0, printing a dim skip line in verbose mode only. ## 2. Anchor the .gitignore fallback match `functions/_agents_init_ensure_gitignore.fish` uses `git check-ignore` for accurate rule matching, but falls back to a plain `grep -qF` when the root is not a git repository. A substring match treats a negation line such as `!AGENTS/foo` as proof that the pattern `AGENTS/` is already ignored, so the real rule was never appended. The fallback now matches whole lines (`grep -qxF`). ## Verification Three new checks in `tests/test-agents-vault.fish`, each confirmed failing before its fix and passing after: - `no scaffold in a non-git dir` - `an existing AGENTS.md still scaffolds` - `negation does not count as ignored` ``` fish tests/test-agents-vault.fish 320/320 passed (was 318/320 with the new tests failing) fish tests/run-tests.fish TOTAL: 753/753 assertions passed python3 docs/verify-manual.py 84/84 passed ``` Section 5 of the manual is generated from the function headers, and both headers were updated in place; no prose page in `docs/manual/**` references `agents-init`. **Follow-up:** the `run-tests.fish` line above was misread — the driver exited 1 on an indent lint failure despite the passing assertion total, which broke CI on `main`. Fixed in #154.
rootiest added the Kind/BugArea/FunctionsArea/Tests labels 2026-09-16 23:07:58 +00:00
rootiest added 2 commits 2026-09-16 23:07:59 +00:00
Resolving the root to (pwd) meant running an agent CLI anywhere created an
AGENTS/ git repo, an AGENTS.md, two root symlinks, and a docs/ tree in that
directory. Scaffolding now requires a git repo or a pre-existing agent file
(AGENTS.md, CLAUDE.md, or AGENTS/); elsewhere it is a no-op.
The non-git fallback used a substring match, so a negation line such as
!AGENTS/foo counted as the pattern AGENTS/ already being ignored and the
real rule was never appended.
rootiest merged commit acbbd8d9e1 into main 2026-09-16 23:09:01 +00:00
rootiest deleted branch fix/agents-init-nongit-and-gitignore-anchor 2026-09-16 23:09:02 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rootiest/fish-config#153