Skip to content

feat(worktrees): default implementation to task worktree - #153

Merged
datacas merged 6 commits into
mainfrom
issue-151-worktree-default
Oct 5, 2026
Merged

datacas merged 6 commits into
mainfrom
issue-151-worktree-default

Conversation

@datacas

@datacas datacas commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Closes #151

Summary

  • Default issue implementation and orchestration to an isolated task-specific linked worktree; retain the selected checkout across mutating stages and diff collection.
  • Reuse only a worktree with an exact delimited task ID or a PR linked to this work item; reject substring matches such as issue-1510.
  • Support --workspace current as the explicit per-run opt-out. Local-only runs require that opt-out before selection, avoiding worktree creation before a blocked stop.
  • Resolve the configured worktree base from the main repository root, including when reusing a linked worktree.
  • In Herdr, use herdr worktree create or open with the current repository as --cwd, the configured location as --path, and --no-focus; block on failure without silently falling back to Git.

Diagnosis

Issue #151 is a feature request: implementation workflows could use the invoking checkout even though #143 and merged PR #149 established code_cycle.worktree_dir. Reproduction does not apply. The invariant is that all code-mutating stages for one work item use the same isolated linked worktree and PR branch, and the invoking checkout is changed only when workspace=current is explicitly selected. A bug cause hypothesis does not apply because the issue did not propose a bug mechanism. Widened related-work search found #143 (closed; implemented by PR #149) and adjacent open issue #141; the recent workspace/progress work in #140 / PR #152 was checked and is distinct. No competing open PR was found. Reviews caught and verified three implementation defects during the cycle: the runtime did not enforce task-worktree selection, substring IDs could reuse another task's branch, and reusing a linked worktree derived a nested worktree base. The final fix enforces selection at the runtime boundary, verifies same-item reuse, and resolves the base from the main repository root.

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 Select and retain the task worktree, support the explicit current-workspace opt-out, validate same-item reuse, preserve the repository worktree base, and apply Herdr create/open behavior. scripts/run_cycle.py; docs/configuration.md; docs/instrumentation.md; docs/workflows.md; docs/skills.md; skills/cc-implement-issue/SKILL.md; skills/cc-orchestrator/SKILL.md; skills/cc-orca-orchestrator/SKILL.md; tests/test_run_cycle.py; tests/test_installed_cycle.py; tests/test_issue_review.py; tests/test_cycle_progress.py; tests/test_validate_package.py Runtime workspace-selection and CLI boundary regression tests; package validation; complete unit suite on GitHub's Linux and Windows runners Local package validator passed; read-only workspace-selection reproductions passed. Local focused tests were blocked before assertions because this sandbox has no usable temporary directory. GitHub ran 1,027 tests and package validation; all four current-head checks passed. Independent

Verification

  • python3 scripts/validate-package.py — passed locally.
  • Read-only reproduction on the final linked checkout — passed: selected checkout, repository-level worktree base, prompt base, and delimited work-item matching were observed.
  • git diff --check 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b ea708ba37b97bac9346f4821e29b882ac589e0a9 — passed.
  • The local WorkspaceSelectionTests run could not reach assertions because the sandbox has no usable temporary directory. This is not counted as a local test pass.
  • A fake Herdr executable returning nonzero was blocked without a Git fallback.
  • Final rereview confirmed no remaining open findings and approved the current head.

Herdr behavior

When running inside Herdr, create or open task worktrees through Herdr. This task worktree was opened with herdr worktree open --cwd /home/datacas/www/code-cycle-toolkit --path /home/datacas/www/code-cycle-toolkit/.worktree/issue-151-worktree-default --no-focus.

Checks of pushed head

Head SHA: ea708ba37b97bac9346f4821e29b882ac589e0a9

  • Skills, manifests, and Bash installer — pass (run 37318464645).
  • Skills, manifests, and Bash installer — pass (run 37318458109).
  • PowerShell installer — pass (run 37318464645).
  • PowerShell installer — pass (run 37318458109).

PR remains open for manual merge.

@datacas

datacas commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

Initial review — CHANGES_REQUESTED

Reviewed PR #153 at a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f against merge base 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b. The supplied accumulated diff was read in two sections (237 lines; SHA-256 37c2b26c475d74c631cd2a2bc169f015b7010901d4cacfe15f9b47b2870830ce). Scope: worktree policy in three skills, the runtime prompt, documentation, and tests for issue #151.

[REV-001] · high · open · - · blocks:yes — Runtime does not select and retain the default task worktree

scripts/run_cycle.py:700 adds a prompt telling a worker to use a task worktree, but the driver still defaults --cwd to None (line 2043), passes that value unchanged into run_cycle (line 2115), dispatches every stage with the same cwd (lines 1172–1200), and creates later review diffs from it (lines 1186–1191). A cycle launched from the invoking checkout has no driver-enforced worktree selection. If implementation moves to a child worktree, later stages can still run or diff from the original checkout. The new runtime documentation also presents workspace=current as an invocation opt-out, but python3 scripts/run_cycle.py --task 151 --workspace current exits 2 with “unrecognized arguments.” Select and validate the task workspace before mutating dispatch, retain its path across stages and diff collection, and cover the default, opt-out, and unavailable-worktree paths with behavior tests.

[REV-002] · medium · open · - · blocks:yes — Substring issue IDs can select another task's worktree

skills/cc-implement-issue/SKILL.md:199 permits reuse when the branch “contains this work item's identifier”; the same rule appears in skills/cc-orchestrator/SKILL.md:506 and skills/cc-orca-orchestrator/SKILL.md:220. For item 151, branch issue-1510 contains 151 but belongs to another item. Reusing it would mix changes and break the same-item isolation requirement. Require an exact work-item association, such as a delimited identifier or the linked change request, before reuse.

Security triage

No custom security_review.always_when rule is configured. The built-in path, filename, and label rule matched none of the nine changed paths or PR labels. The reviewer requested a security pass because the change directs worktree command execution and writable checkout selection. The audit found no confirmed authentication, secret, injection, path traversal, or data exposure vulnerability. The cross-task integrity risk is recorded as REV-002.

Verification and CI

  • Targeted prompt and documentation tests: 2 passed (exit 0).
  • PYTHONDONTWRITEBYTECODE=1 python3 scripts/validate-package.py: passed (exit 0).
  • CLI --help: passed (exit 0); --workspace current is rejected as above.
  • Full local suite: 1,011 tests started, 560 errors (exit 1), because this read-only environment has no usable temporary directory. This is an environment limitation, so the full suite is unverified locally.
  • GitHub checks at the reviewed head: “Skills, manifests, and Bash installer” and “PowerShell installer” each passed in both reported runs. No check is pending, failed, cancelled, or skipped.

Real implementation and resolution dispatch across worktrees, including Herdr selection, was not run here. The passing CI validates the existing suite but its new tests assert prompt and documentation strings, not workspace behavior. The review verdict is CHANGES_REQUESTED for REV-001 and REV-002.

@datacas

datacas commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-001] · deep_coder · openai/gpt-6-luna→? · max · triaged:a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f · schema:1

Resolution — PR #153

Both valid findings were resolved from triage head a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f. The implementation is in 6d50eb5783f7a9db606e6989bd9e4ab2a339e034; follow-up commits update legacy CLI fixtures and make path assertions portable across Windows. Current head: 940adaec846c3e5c5ce8f1c42fafd9457e18ed7c.

[REV-001] · high · resolved · valid · blocks:yes — Runtime does not select and retain the default task worktree

Default task mode selects a task-specific linked worktree, reuses a matching worktree or a PR branch linked to the work item, and keeps the selected checkout for later stages and diff collection. --workspace current explicitly opts into the invoking checkout. Local-only rehearsal requires that opt-out before selection, so a rejected run cannot create another task worktree.

[REV-002] · medium · resolved · valid · blocks:yes — Substring issue IDs can select another task's worktree

Work-item branch matching now requires the ID to be delimited, so issue-1510 does not match item 151. A PR branch is reused only after confirming that the PR is linked to the same work item.

Verification

  • python3 scripts/validate-package.py — passed.
  • python3 -m unittest discover -s tests -v — 1,027 tests passed.
  • python3 -m unittest test_run_cycle.WorkspaceSelectionTests -v — 15 tests passed.
  • git diff --check — passed.
  • CLI boundary check confirmed local-only without --workspace current exits with the expected BLOCKED result before creating a task worktree or telemetry database. A fake Herdr executable returning nonzero was also blocked without a Git fallback.
  • GitHub checks on head 940adaec846c3e5c5ce8f1c42fafd9457e18ed7c: 4 passed, 0 failed, 0 pending.
  • Security review: no confirmed vulnerabilities. No unresolved risks identified.

@datacas

datacas commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-001] · deep_coder · openai/gpt-6-luna→? · max · triaged:a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f · schema:1

[CCR-20261005-002] · reviewer · openai/gpt-6-sol→? · high · schema:1

Rereview — CHANGES_REQUESTED

Reviewed head 940adaec846c3e5c5ce8f1c42fafd9457e18ed7c against merge base 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b. The supplied accumulated diff matched 1,178 lines and SHA-256 e27b3b120e41abb78a38880b3c52e20e357f9ff82bcbbae6a7d410916b16607b; I read it in sections. Since the initial review at a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f, the change adds runtime workspace selection, CLI opt-out, worktree reuse checks, and behavior tests.

[REV-001] · high · resolved · valid · blocks:yes — Runtime does not select and retain the default task worktree

select_workspace now runs before dispatch, and its selected path is passed through run_cycle; --workspace current is explicit. The related runtime tests passed (168 tests).

[REV-002] · medium · resolved · valid · blocks:yes — Substring issue IDs can select another task's worktree

branch_identifies_work_item requires delimited identifiers. The test confirms issue-1510 is not reused for item 151; the related runtime tests passed.

[REV-003] · medium · open · - · blocks:yes — Reused worktree supplies a nested base directory to the implementer

scripts/run_cycle.py:1020-1021 resolves code_cycle.worktree_dir against repository_root when the invoking checkout is the selected linked worktree. In a direct execution from .worktree/issue-151-worktree-default, the selected checkout is correctly reused, but the returned base is .worktree/issue-151-worktree-default/.worktree instead of the configured repository base .worktree. The generated implementation prompt then requires that nested path for persistent worktrees, conflicting with the no-nesting policy and risking another child worktree inside the selected checkout. Resolve the configured base against main_root on this reuse path and test both the returned base and generated prompt.

Security triage activated an audit because this change selects writable checkouts and runs Git/Herdr commands. The audit found no confirmed injection, path escape, secret exposure, or authentication issue; REV-003 is a worktree-location integrity issue.

Verification: python3 -m unittest discover -s tests -p 'test_run_cycle.py' -q passed (168); python3 scripts/validate-package.py passed; python3 -m unittest discover -s tests -q passed (1,027); git diff --check origin/main...HEAD passed. The REV-003 path and prompt were reproduced by executing select_workspace and compose from the current linked worktree. A live implementation/resolution dispatch was not run.

GitHub CI on this head: both Skills, manifests, and Bash installer jobs and both PowerShell installer jobs passed. Residual risk: a run launched inside its task worktree gives the implementer the wrong persistent base. Verdict: CHANGES_REQUESTED pending REV-003.

@datacas

datacas commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-001] · deep_coder · openai/gpt-6-luna→? · max · triaged:a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f · schema:1

[CCR-20261005-002] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-002] · deep_coder · openai/gpt-6-luna→? · max · triaged:940adaec846c3e5c5ce8f1c42fafd9457e18ed7c · schema:1

Triage — PR #153

All findings were reconciled against head 940adaec846c3e5c5ce8f1c42fafd9457e18ed7c before editing. The earlier valid dispositions remain frozen.

[REV-001] · high · resolved · valid · blocks:yes — Runtime does not select and retain the default task worktree

The latest rereview confirms the runtime selects a task worktree before dispatch and carries its selected checkout through later stages. The existing valid disposition is preserved.

[REV-002] · medium · resolved · valid · blocks:yes — Substring issue IDs can select another task's worktree

The branch matcher requires a delimited work-item identifier, and pull-request branch reuse checks the linked work item. The existing valid disposition is preserved.

[REV-003] · medium · open · valid · blocks:yes — Reused worktree supplies a nested base directory to the implementer

Confirmed against the triage head: when the matching linked worktree is the current checkout, select_workspace resolves the configured base against that checkout and returns <checkout>/.worktree. A direct reproduction also showed the generated resolution prompt requires that nested base. The configured base must resolve from the main repository root so reuse does not direct later workers to nest another worktree. This finding is valid and remains open pending the targeted fix.

@datacas

datacas commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-001] · deep_coder · openai/gpt-6-luna→? · max · triaged:a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f · schema:1

[CCR-20261005-002] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-002] · deep_coder · openai/gpt-6-luna→? · max · triaged:940adaec846c3e5c5ce8f1c42fafd9457e18ed7c · schema:1

Resolution summary — PR #153

Resolved all three valid findings recovered from review. The working branch remains issue-151-worktree-default; commit ea708ba37b97bac9346f4821e29b882ac589e0a9 is pushed to this PR. The fix resolves the configured worker-worktree base from the main repository root when the current checkout is the matching linked worktree, preventing the generated prompt from nesting .worktree inside the task worktree. The regression test checks both the selected base and generated prompt.

[REV-001] · high · resolved · valid · blocks:yes — Runtime does not select and retain the default task worktree

Resolved in prior commit 6d50eb5783f7a9db606e6989bd9e4ab2a339e034; preserved as resolved after rereview.

[REV-002] · medium · resolved · valid · blocks:yes — Substring issue IDs can select another task's worktree

Resolved in prior commit 6d50eb5783f7a9db606e6989bd9e4ab2a339e034; preserved as resolved after rereview.

[REV-003] · medium · resolved · valid · blocks:yes — Reused worktree supplies a nested base directory to the implementer

select_workspace now resolves the configured base from the main repository root for the matching active linked worktree. The regression test verifies the base is the repository-level .worktree and that the generated resolution prompt does not name <task-worktree>/.worktree.

Verification

  • python3 -m unittest discover -s tests -p 'test_run_cycle.py' -k matching_active_task_worktree_uses_repository_base_in_prompt -v — passed, 1 test.
  • env -u HERDR_ENV PYTHONPATH=tests python3 -m unittest test_run_cycle.WorkspaceSelectionTests -q — passed, 15 tests.
  • env -u HERDR_ENV PYTHONPATH=tests python3 -m unittest test_run_cycle.RepeatedFindingTests -q — passed, 14 tests; the one unrelated failure seen in the broader run also passed in isolation.
  • env -u HERDR_ENV python3 -m unittest discover -s tests -p 'test_validate_package.py' -q — passed, 59 tests.
  • python3 scripts/validate-package.py — passed.
  • git diff --check 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b — passed.
  • CLI boundary harness with HERDR_ENV=1 — passed; it exercised real argument parsing and Git worktree selection and confirmed dispatch used the matching checkout plus the main-root .worktree base.
  • GitHub checks on ea708ba37b97bac9346f4821e29b882ac589e0a9 — 4/4 passed: two “Skills, manifests, and Bash installer” jobs and two “PowerShell installer” jobs.

Verification reservation: the host inherited HERDR_ENV=1, and a broader runtime-file run under that setting hit five environment permission errors while tests attempted Herdr operations on temporary worktrees. With HERDR_ENV unset, the 168-test runtime-file run had one unrelated failure (RepeatedFindingTests.test_an_unknown_head_is_never_no_progress); that test passed alone and its full 14-test class passed. The full repository suite was not run.

The change is limited to worktree-base selection and its regression test. The post-fix security review found no confirmed vulnerability.

@datacas

datacas commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261005-001] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-001] · deep_coder · openai/gpt-6-luna→? · max · triaged:a4fc00343ecb305f7823f1befb0f0c4b6e7e0a0f · schema:1

[CCR-20261005-002] · reviewer · openai/gpt-6-sol→? · high · schema:1

[CCT-20261005-002] · deep_coder · openai/gpt-6-luna→? · max · triaged:940adaec846c3e5c5ce8f1c42fafd9457e18ed7c · schema:1

[CCR-20261005-003] · reviewer · openai/gpt-6-sol→? · high · schema:1

Rereview — APPROVED

Reviewed PR #153 at ea708ba37b97bac9346f4821e29b882ac589e0a9 against merge base 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b. The supplied accumulated diff was confirmed as 1,188 lines with SHA-256 7620623e324a2d70175568d56c7c44c6ae6f5f3b00ce67d8cbcae955f8557a82 and read in sections. Since the prior rereview at 940adaec846c3e5c5ce8f1c42fafd9457e18ed7c, the fix changes the reused-worktree path to resolve code_cycle.worktree_dir from the main repository root and adds a regression test for the base and generated prompt. The accumulated change remains within issue #151's workspace-selection scope.

[REV-001] · high · resolved · valid · blocks:yes — Runtime does not select and retain the default task worktree

Corrected and verified by execution. The earlier rereview exercised the runtime tests; at this head, a read-only select_workspace call from the task's linked checkout selected that checkout, and the current-head GitHub suite passed. The runtime still passes the selected path into run_cycle, and the explicit workspace=current opt-out remains present.

[REV-002] · medium · resolved · valid · blocks:yes — Substring issue IDs can select another task's worktree

Corrected and verified by execution. On the current head, branch_identifies_work_item('issue-1510', '151') returned False, while the delimited issue-151-worktree-default returned True. The current-head GitHub suite passed.

[REV-003] · medium · resolved · valid · blocks:yes — Reused worktree supplies a nested base directory to the implementer

Corrected and verified by execution. From the existing linked worktree, select_workspace('151', ...) returned the main repository's .worktree as the base. compose('resolve', ...) named that base and did not name a nested .worktree under the task checkout. The new regression test covers both outputs, and the current-head GitHub suite passed.

Security triage

No custom security_review.always_when rule or matching sensitive path/label was configured. A security audit was activated by reviewer judgement because the change selects writable checkouts and invokes Git/Herdr. The accumulated code uses argument lists for subprocesses, sanitizes generated worktree names, checks the selected path against its configured base, and blocks on selection errors. No confirmed injection, path escape, secret exposure, authentication, or authorization vulnerability was found.

Verification and CI

  • Read-only reproduction on the current linked checkout: passed (exit 0); selected checkout, main-root base, prompt base, and delimited ID behavior observed.
  • env -u HERDR_ENV PYTHONDONTWRITEBYTECODE=1 python3 scripts/validate-package.py: passed (exit 0).
  • git diff --check 7ca83f6b792eb80c5092fce627f7fe8f87a79c1b ea708ba37b97bac9346f4821e29b882ac589e0a9: passed (exit 0).
  • Local WorkspaceSelectionTests: 15 environment errors before assertions because this sandbox has no usable temporary directory. This is not a code test result; the suite remains unverified locally.
  • GitHub's current-head Validate package workflow runs package validation and python3 -m unittest discover -s tests -v. Both “Skills, manifests, and Bash installer” jobs and both “PowerShell installer” jobs passed. No current check is pending, failed, cancelled, or skipped.

A live implementation/resolution dispatch through Herdr was not run in this rereview. The direct worktree/prompt reproduction and current-head CI provide the available execution evidence. No finding remains open or blocks approval. Verdict: APPROVED for the current head.

@datacas
datacas merged commit 426ae2e into main Oct 5, 2026
4 checks passed
@datacas
datacas deleted the issue-151-worktree-default branch October 6, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use a Git worktree by default for implementation

1 participant