Skip to content

feat(#1199): configurable worktree root - #1226

Merged
admarble merged 6 commits into
mainfrom
feature/1199-feat-worktree-configurable-worktree-root
Sep 30, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/1199-feat-worktree-configurable-worktree-root

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Configurable worktree root (AC-1). run.worktreeRoot (settings) and SEQUANT_WORKTREE_ROOT (env, which wins) set where issue worktrees go. Without either, the default is still <parent of repo>/worktrees. A relative value resolves against the main repo root. ~ is not expanded, and a blank env var counts as unset.
    • TS: resolveWorktreeRoot() in worktree-manager.ts, threaded through ensureWorktree/ensureWorktrees/ensureWorktreesChain from settings.run.worktreeRoot in run-orchestrator.ts.
    • Shell: templates/scripts/new-feature.sh uses the same precedence, and scripts/new-feature.sh is a symlink to it. The git worktree add hint and the SEQUANT_NPM_CACHE dir follow the root.
    • Read strategy for new-feature.sh: a JSONC-tolerant text match, not env-only. Nothing in TS invokes new-feature.sh; users and skills call it directly. With env-only, the setting half of AC-1 would silently do nothing for the script. Lines starting with // are dropped, newlines are collapsed, and the first "worktreeRoot": "…" is taken. Known trade-off: a key inside a /* */ block would still match. The packageManager read makes the same trade-off.
  • Detection by git, not path (AC-2). The pre-tool.sh WORKTREE_WARNING check and quality-checks.sh's verify_build_against_main now compare the absolute git rev-parse --git-dir with --git-common-dir instead of matching worktrees/feature/ / *"/worktrees/"*. The hook also checks the command's own directory now: a resolvable cd target, else the payload cwd. Before, it checked the hook process's pwd. All 3 copies of each file are byte-identical.
  • As the spec notes, this detects any linked worktree, including .exec-agents/ sub-worktrees and other tools' worktrees. That is correct for a warn-only commit check and a find-the-main-repo lookup.
  • Docs: docs/guides/git-workflows.md (Worktree Locations), the generated settings reference row, and CHANGELOG.

Hook rollout: the repo's pre-tool.sh and the plugin-cache copy both fire. Plugin users get the AC-2 change only after a plugin version bump.

Hook verdicts changed: none (npx tsx scripts/hook-corpus.ts --diff origin/main → 0 verdict changes)

Possible follow-up (out of scope per owner): these still print ../worktrees/feature/<issue>-*/, but they are guidance text only: src/lib/locks/checkout-lock.ts:182,187, pre-tool.sh:1057, the worktree-resolver.ts prose, and the SKILL.md text. Also, quality-checks.sh could derive main_repo_dir from --git-common-dir instead of the grep [main] heuristic.

AC verification

AC Source Status Evidence
AC-1 Original ✅ resolveWorktreeRoot + call site; src/lib/workflow/worktree-manager.test.ts (precedence unit cases + ensureWorktree run in a scratch repo via a child process)
AC-2 Original ✅ hooks/pre-tool.sh in_linked_worktree; __tests__/pre-tool-hook.integration.test.ts #1199 block (×3 copies)
AC-3 Derived ✅ __tests__/new-feature-worktree-root.integration.test.ts: env root, JSONC setting with a // decoy, default
AC-4 Derived ✅ __tests__/quality-checks-worktree-root.integration.test.ts: function extracted from each copy, run from a custom-root worktree

Mutation record

Mutation-verified: AC-1 — call site reverted to path.join(path.dirname(gitRoot), "worktrees"); both ensureWorktree cases failed; restored.

Mutation-verified: AC-2 — hook check reverted to grep -qE 'worktrees/feature/'; the two no-warn cases failed; restored.

Mutation-verified: AC-3 — setting read in new-feature.sh replaced with an empty value; JSONC case failed; restored.

Mutation-verified: AC-4 — quality-checks condition reverted to *"/worktrees/"*; custom-root case failed; restored.

Test plan

  • npm run build, npm run lint: clean
  • Targeted suites, run with SEQUANT_* unset: 20 files, 1640 tests passed. They cover worktree-manager, pre-tool-hook, new-feature-{worktree-root,checkout-guard,frozen-install}, quality-checks-worktree-root, settings*, run-orchestrator*, hook-corpus, tautology-detector-cli and skill-sync.
  • The full npm test was not run, per the owner's standard block for this issue. CI runs it.

Closes #1199
Refs #1203

🤖 Generated with Claude Code

Entire-Checkpoint: 16f7fd2ac03d
Entire-Checkpoint: 012056b4b7d2
Entire-Checkpoint: e3ad69ffa738
Entire-Checkpoint: 5f97cfc65cbf
Entire-Checkpoint: 71edacfb1811
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.

feat(worktree): configurable worktree root

1 participant