-
Notifications
You must be signed in to change notification settings - Fork 98
feat: add machine-readable worktree creation for agents #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # AI Agent Usage | ||
|
|
||
| Shell-capable coding agents can call `git gtr` directly. A separate MCP server | ||
| is not necessary for creating, locating, using, and removing worktrees. | ||
|
|
||
| ## Machine-readable creation | ||
|
|
||
| Create a worktree with stable output: | ||
|
|
||
| ```bash | ||
| git gtr new agent/my-task --porcelain | ||
| ``` | ||
|
|
||
| The command writes exactly three tab-separated records to stdout: | ||
|
|
||
| ```text | ||
| path /absolute/path/to/repo-worktrees/agent-my-task | ||
| branch agent/my-task | ||
| hook_status ran | ||
| ``` | ||
|
|
||
| Values escape backslashes, tabs, and newlines as `\\`, `\t`, and `\n`. | ||
| Progress messages, warnings, and hook output go to stderr. `--porcelain` implies | ||
| `--yes` and cannot be combined with `--editor` or `--ai`. | ||
|
|
||
| `hook_status` is one of: | ||
|
|
||
| | Value | Meaning | | ||
| | --- | --- | | ||
| | `disabled` | Hooks were disabled with `--no-hooks`. | | ||
| | `none` | No post-create hooks were configured. | | ||
| | `ran` | All configured post-create hooks were trusted and ran successfully. | | ||
| | `skipped-untrusted` | Only untrusted `.gtrconfig` hooks were configured, so none ran. | | ||
| | `partial` | Trusted hooks ran, while untrusted `.gtrconfig` hooks were skipped. | | ||
|
|
||
| A non-zero exit means creation or a post-create hook failed. No success records | ||
| are emitted in that case. | ||
|
|
||
| ## Recommended agent lifecycle | ||
|
|
||
| 1. Inspect existing worktrees with `git gtr list --porcelain`. | ||
| 2. Create an isolated worktree with `git gtr new <branch> --porcelain`. | ||
| 3. Parse the `path` record and perform all task work inside that directory. | ||
| 4. Before handing off, run `git status --short --branch` in the worktree and | ||
| report its branch, changes, and validation results. | ||
| 5. Remove the worktree only when the user explicitly asks for cleanup. | ||
|
|
||
| Agents should not run `git gtr trust`. Trusting committed `.gtrconfig` commands | ||
| authorizes code execution and requires human review. Agents should also avoid | ||
| `git gtr rm --force`, `--delete-branch`, and `git gtr clean` unless the user has | ||
| explicitly authorized the destructive scope. | ||
|
|
||
| ## `AGENTS.md` example | ||
|
|
||
| ```markdown | ||
| ## Worktree policy | ||
|
|
||
| - Use `git gtr list --porcelain` to inspect worktrees. | ||
| - For implementation tasks, create an isolated worktree with | ||
| `git gtr new <branch> --porcelain` and work only in the returned `path`. | ||
| - Treat a non-zero exit as failure; do not infer success from human-readable logs. | ||
| - If `hook_status` is `skipped-untrusted` or `partial`, report it. Never run | ||
| `git gtr trust` on the user's behalf. | ||
| - Do not remove worktrees, force cleanup, or delete branches without explicit | ||
| user authorization. | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.