Seed AGENTS.md at the container root only, not in each worktree#16
Conversation
The AGENTS.md template describes the bare-repo + worktree layout as a whole — where trees-bare.git lives, that sibling worktrees exist, not to cd above the repo root. That is container-level guidance, so it belongs beside the bare store and nowhere else. `add` was also copying it into every new worktree, which left an untracked AGENTS.md in every `git status` and invited committing container-level instructions into project history. Remove the copy from `cmd_add`. Factor the copy into `_seed_agents` and add `root --agents` to seed containers that `init` did not create; the notice goes to stderr so the path on stdout stays usable in `$(git trees root)`. `cmd_root` gains an option parse loop, replacing the hard `$# -gt 1` rejection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. 📝 WalkthroughWalkthroughThe change adds conditional root-level ChangesAGENTS.md root seeding
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant cmd_root
participant GitStore
participant _seed_agents
Caller->>cmd_root: invoke root [dir] --agents
cmd_root->>GitStore: discover project root
GitStore-->>cmd_root: return discovered root
cmd_root->>_seed_agents: seed discovered root
_seed_agents-->>Caller: write notice to stderr when copied
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@git-trees`:
- Around line 108-119: The _seed_agents function must avoid TOCTOU races and
never overwrite an existing destination, including symlinks. Replace the
separate -f check and plain cp with an exclusive creation strategy that treats
any existing path (-e or -L) as occupied, and emit the stderr notice only after
this invocation successfully creates AGENTS.md.
- Line 192: Update cmd_init and both cmd_root branches to explicitly check the
status returned by _seed_agents and immediately propagate a nonzero result
instead of reporting success; apply the same guarded handling to the
worktree-enclosing root branch, preserving successful execution when seeding
completes.
- Around line 202-215: Update the argument-validation branches in cmd_root so
both unknown-option and unexpected-argument failures print the subcommand usage
to stderr before returning 1. Preserve the existing error messages and
successful parsing behavior.
In `@install.sh`:
- Line 33: Update the echo message in install.sh to describe $CFG/AGENTS.md as a
template used by init or root --agents to seed the container root, rather than
implying the installer creates the root-level file directly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7bbf26d0-1e37-4d2e-8d0a-c5d5e2755ebe
📒 Files selected for processing (3)
README.mdgit-treesinstall.sh
Address CodeRabbit review: noclobber create, propagate seed errors, print usage on bad root args, and clarify the installer template message. Co-authored-by: Cursor <cursoragent@cursor.com>
Problem
git trees add <branch>copied\$TREES_AGENTS_TEMPLATEinto the new worktree:But that template describes the bare-repo + worktree layout as a whole — where
trees-bare.gitlives, that sibling worktrees exist, not tocdabove the repo root. It is container-level guidance addressed to an agent working inside a container, so it belongs beside the bare store and nowhere else.Copying it per-worktree meant:
?? AGENTS.mdin every worktree'sgit statusReported after
git trees add beer-july-26-outline-update beer-july-26dropped a copy into the new worktree, byte-identical to~/.config/git-trees/AGENTS.md.Changes
cmd_add. Worktrees are left alone._seed_agents, next to the other_-prefixed internals — no-op when the template is unconfigured or the file already exists. The notice goes to stderr, since callers print paths on stdout.cmd_inituses the helper; behavior unchanged (it already refused to run against an existing directory).git trees root [dir] [--agents]— opt-in seeding for containersinitdid not create (hand-built or adopted).cmd_rootgains an option parse loop in the stylecmd_addalready uses, replacing the hard$# -gt 1rejection. Without the flag,rootbehaves exactly as before.usage(), README layout diagram /rootsection / env table, and theinstall.shmessage.Verification
No test framework; verified against a throwaway fixture per
CLAUDE.md, plusbash -nandshellcheck(clean in the changed functions).Core fix:
addon an existing remote branch and on a new branch → noAGENTS.md,git statusemptyorigin/brandnew, notorigin/main— the--no-trackregression stays fixed--agents:rootwithout the flag does not seed; with it, seeds and matches the template$(git trees root --agents)returns exactly the root path — notice does not pollute stdoutArg parsing:
--bogusand an extra positional both exit 1 with a message;root . --agentsandroot --agents .both work; nonexistent dir and non-trees dir still error as before.init(needs network, so outside the usual recipe) verified over afile://URL: seeds the root, and a subsequentaddinto it leaves the worktree clean.Other regression checks from
CLAUDE.mdre-run and passing:--print-pathstdout purity,list --jsonvalidity, a freshly cut branch not reported as merged, clean nonzero exit outside a repo.Note for existing users
This does not clean up already-copied files. Any stray
AGENTS.mdin a worktree is untracked and safe to delete by hand; the one at the container root should stay.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--agentsflag togit trees rootto seedAGENTS.mdat the project root.AGENTS.mdat the container root when configured.Bug Fixes
AGENTS.mdin every new worktree.Documentation
AGENTS.mdseeding.