Enforce branches-only worktrees for all LLM task mutations #274

Closed
opened 2026-07-06 13:03:11 -05:00 by jcwalker3 · 3 comments
Owner

LLMs must never perform issue, PR, feature, bugfix, review-fix, or implementation work directly in the main project checkout.

This rule applies to every repository/project, not only Gitea-Tools.

The main project folder is the stable control checkout. It must remain on the project’s configured stable branch, normally master, main, or dev. It should only be updated after PRs are merged or when explicitly performing control-checkout maintenance.

All LLM task work must happen in an isolated worktree under that project’s branches/ directory.

Examples:

/project-root/                  # stable control checkout: master/main/dev only
/project-root/branches/task-a/  # allowed task worktree
/project-root/branches/task-b/  # allowed task worktree

Required rule:

Before any mutation, the LLM must prove it is working inside the project’s branches/ directory.
If not inside branches/, mutation is forbidden.

Mutation includes, but is not limited to:

  • editing files
  • creating files
  • deleting files
  • running formatters that write files
  • running tests that generate or modify files
  • changing branches
  • committing
  • rebasing
  • merging
  • applying patches
  • resolving conflicts
  • creating PR branches
  • fixing review comments
  • preparing merge cleanup
  • modifying MCP/server/config files
  • running cleanup tools

Allowed operations in the main checkout:

  1. Read-only inspection.
  2. Checking status.
  3. Fetching from remotes.
  4. Updating the stable checkout after a PR has already merged.
  5. Creating or locating an isolated worktree under branches/.
  6. Explicit control-checkout repair when the user specifically asks to repair the main checkout.

Hard requirements:

  1. Every LLM session must identify:

    • project root
    • current working directory
    • stable branch for the main checkout
    • intended task branch
    • intended branches/ worktree path
  2. If the current working directory is the project root and not inside branches/, the LLM must stop before mutation.

  3. If the main checkout is on a task branch, the LLM must stop and report that the control checkout has drifted.

  4. If the main checkout is dirty, the LLM must stop and produce a repair handoff.

  5. If a branches/ worktree does not exist for the task, the LLM must create one before doing work.

  6. If the LLM cannot prove it is inside branches/, it must not mutate anything.

  7. PR review, review-fix, merge-prep, conflict resolution, and issue implementation all require a branches/ worktree.

  8. No LLM may treat “small fix,” “quick edit,” “just one file,” “documentation only,” “test only,” “cleanup only,” or “emergency” as an exception.

  9. Final reports and handoffs must include the actual worktree path used.

  10. Any tool or prompt that allows mutation outside branches/ is considered unsafe and must be fixed.

Implementation requirements:

  • Add a preflight check that detects whether the current path is inside the repository’s branches/ directory.
  • Add a fail-closed guard before mutation tools.
  • Add prompt/template language requiring branches-only work.
  • Add tests for:
    • mutation attempted from project root
    • mutation attempted from stable checkout
    • mutation attempted from wrong sibling directory
    • mutation allowed inside branches/<task-worktree>
    • main checkout dirty state
    • main checkout on task branch
    • final report missing worktree path

Acceptance criteria:

  • LLMs cannot edit, commit, test-write, merge, rebase, or cleanup from the main project checkout.
  • Main checkout remains on master, main, or dev, depending on project configuration.
  • All task work happens under branches/.
  • Any attempted mutation outside branches/ fails before the command runs.
  • The failure message tells the LLM to create or switch to a branches/ worktree.
  • Every handoff/final report includes the worktree path.
  • This rule applies globally across projects, not only one repository.
LLMs must never perform issue, PR, feature, bugfix, review-fix, or implementation work directly in the main project checkout. This rule applies to every repository/project, not only Gitea-Tools. The main project folder is the stable control checkout. It must remain on the project’s configured stable branch, normally `master`, `main`, or `dev`. It should only be updated after PRs are merged or when explicitly performing control-checkout maintenance. All LLM task work must happen in an isolated worktree under that project’s `branches/` directory. Examples: ```text /project-root/ # stable control checkout: master/main/dev only /project-root/branches/task-a/ # allowed task worktree /project-root/branches/task-b/ # allowed task worktree ``` Required rule: ```text Before any mutation, the LLM must prove it is working inside the project’s branches/ directory. If not inside branches/, mutation is forbidden. ``` Mutation includes, but is not limited to: * editing files * creating files * deleting files * running formatters that write files * running tests that generate or modify files * changing branches * committing * rebasing * merging * applying patches * resolving conflicts * creating PR branches * fixing review comments * preparing merge cleanup * modifying MCP/server/config files * running cleanup tools Allowed operations in the main checkout: 1. Read-only inspection. 2. Checking status. 3. Fetching from remotes. 4. Updating the stable checkout after a PR has already merged. 5. Creating or locating an isolated worktree under `branches/`. 6. Explicit control-checkout repair when the user specifically asks to repair the main checkout. Hard requirements: 1. Every LLM session must identify: * project root * current working directory * stable branch for the main checkout * intended task branch * intended `branches/` worktree path 2. If the current working directory is the project root and not inside `branches/`, the LLM must stop before mutation. 3. If the main checkout is on a task branch, the LLM must stop and report that the control checkout has drifted. 4. If the main checkout is dirty, the LLM must stop and produce a repair handoff. 5. If a `branches/` worktree does not exist for the task, the LLM must create one before doing work. 6. If the LLM cannot prove it is inside `branches/`, it must not mutate anything. 7. PR review, review-fix, merge-prep, conflict resolution, and issue implementation all require a `branches/` worktree. 8. No LLM may treat “small fix,” “quick edit,” “just one file,” “documentation only,” “test only,” “cleanup only,” or “emergency” as an exception. 9. Final reports and handoffs must include the actual worktree path used. 10. Any tool or prompt that allows mutation outside `branches/` is considered unsafe and must be fixed. Implementation requirements: * Add a preflight check that detects whether the current path is inside the repository’s `branches/` directory. * Add a fail-closed guard before mutation tools. * Add prompt/template language requiring branches-only work. * Add tests for: * mutation attempted from project root * mutation attempted from stable checkout * mutation attempted from wrong sibling directory * mutation allowed inside `branches/<task-worktree>` * main checkout dirty state * main checkout on task branch * final report missing worktree path Acceptance criteria: * LLMs cannot edit, commit, test-write, merge, rebase, or cleanup from the main project checkout. * Main checkout remains on `master`, `main`, or `dev`, depending on project configuration. * All task work happens under `branches/`. * Any attempted mutation outside `branches/` fails before the command runs. * The failure message tells the LLM to create or switch to a `branches/` worktree. * Every handoff/final report includes the worktree path. * This rule applies globally across projects, not only one repository.
jcwalker3 added the status:in-progress label 2026-07-07 04:43:33 -05:00
Author
Owner

Issue claim heartbeat

<!-- gitea-issue-claim-heartbeat:v1 --> **Issue claim heartbeat** - kind: progress - issue: #274 - branch: feat/issue-274-branches-only-worktrees - phase: pr-opened - profile: prgs-author - pr: pending - blocker: none - next_action: await review
Author
Owner

Progress update

PR opened: #374feat/issue-274-branches-only-worktreesmaster

  • Commit: 6779d90 — branches-only author mutation worktree guard
  • Tests: test_author_mutation_worktree.py, preflight integration, issue write gates (all passing)
  • PR mergeable: yes

Ready for review.

**Progress update** PR opened: **#374** — `feat/issue-274-branches-only-worktrees` → `master` - Commit: `6779d90` — branches-only author mutation worktree guard - Tests: `test_author_mutation_worktree.py`, preflight integration, issue write gates (all passing) - PR mergeable: yes Ready for review.
sysadmin removed the status:in-progress label 2026-07-07 09:33:20 -05:00
jcwalker3 added the status:in-progress label 2026-07-07 13:39:19 -05:00
Author
Owner

Issue claim heartbeat

<!-- gitea-issue-claim-heartbeat:v1 --> **Issue claim heartbeat** - kind: claim - issue: #274 - branch: feat/issue-274-branches-only-guard-hardening - phase: claimed - profile: prgs-author - pr: none - blocker: none - next_action: create worktree and begin implementation
sysadmin removed the status:in-progress label 2026-07-07 16:48:02 -05:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Scaled-Tech-Consulting/Gitea-Tools#274