Skip to content

feat(sc-git-worktree): stack-aware worktree creation (0.14.0) - #110

Merged
randlee merged 2 commits into
refactoryfrom
feature/sc-git-worktree-stack-aware
Sep 23, 2026
Merged

randlee merged 2 commits into
refactoryfrom
feature/sc-git-worktree-stack-aware

Conversation

@randlee

@randlee randlee commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Parent: refactory @ 75fd333
Task: make /sc-git-worktree stack-aware with surgical changes (no redesign)
Fence: packages/sc-git-worktree/**, tests/test_sc_prefix_validation.py, registries

What

  • New sc-worktree-create-stacked agent + --create-stacked <layer> <parent> <trunk> [--above <layer>]: cuts a gh-stack layer from origin/<parent> with --no-track, validates the cut before any mutation, records parent_sha, returns a stack_handoff (push, PR base, link / mid-stack insert sequence, writer rules) to paste into the worker agent's prompt.
  • Plain sc-worktree-create agent untouched; SKILL.md and the command route stack layers to the new agent.
  • Cleanup/abort: STACK.HAS_CHILDREN guard (batch stack_blocked) unless git shows a merge-commit landing.
  • Scan: stack_parent_advanced / stack_parent_landed issues + recommendations.
  • Tracking rows gain optional stack metadata; old rows load unchanged.
  • references/stack-layers.md documents the worktree side of the stack model and the writer contract.

Fixes to the stable skill

  • Remote-ref base no longer becomes the new branch's upstream (--no-track), so git push / --force-with-lease cannot target the base.
  • is_branch_merged now strips git's + marker for branches checked out in other worktrees; single-branch cleanup of a landed branch that still has a worktree no longer reports it unmerged.

Verification

  • packages/sc-git-worktree/tests: 165 passed (32 new real-git tests in test_stack_aware.py).
  • Full suite: 1476 passed, 12 skipped. scripts/validate-all.py: 9/9 PASS.
  • Smoke-tested top cut, insert cut, all refusal paths, abort/cleanup guards and scan issues in a throwaway repo with a bare origin.

Stacked on #84 (refactory); trunk develop.

🤖 Generated with Claude Code

New `sc-worktree-create-stacked` agent and `--create-stacked <layer> <parent> <trunk> [--above <layer>]`:
cut a gh-stack layer from the parent's PUSHED head with --no-track, refuse bad cuts before any
mutation (layer exists, parent not pushed / landed / off trunk, insert target not stacked on the
parent), record parent_sha in tracking, and return a stack_handoff block (push, PR base, link or
mid-stack insert sequence, writer rules) for the agent that works in the worktree. The plain
create agent is untouched; the skill and command route stack layers to the new agent.

Cleanup/abort refuse to delete a branch that live layers were cut from unless git shows a merge
commit landing (STACK.HAS_CHILDREN, batch `stack_blocked`). Scan reports stack_parent_advanced /
stack_parent_landed on layer rows.

Fixes: remote-ref bases no longer become the new branch's upstream (--no-track); merge detection
recognises the `+` marker for branches checked out in other worktrees.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@randlee
randlee added this pull request to stack #111 September 23, 2026 05:56
…handoff and guards

- stack_handoff split by role: `writer` (WIP commit first, push -u, one rebase rule, no gh
  stack write commands) and `stack_writer` (PR with base = parent, gh stack checkout in the
  new worktree, link on top, or the insert sequence with merge-forward by EVERY layer above)
- STACK.PARENT_HAS_CHILD: refuse an append onto a parent that already has a live layer
- find_stack_children checks liveness against git/filesystem and treats the layer an
  inserted layer sits under (`stack.above`) as its child; is_landed_by_merge fails closed
  when its first-parent window is exhausted
- cleanup judges landing against origin/<children's trunk>, only when children exist; batch
  cleanup never sweeps a fresh layer with no commits; actionable reconcile hints
- scan: parent_advanced now means "layer does not contain origin/<parent>" (clears after the
  writer's rebase or a merge-forward); landed recommendation adds the diff-before-reset rule
- shell-safe handoff commands (quoted heredoc PR body, quoted paths)
- docs aligned (agent, reference, skill, command, changelog); sc-gh-stack recipe-cut-layer
  points at --create-stacked (sc-gh-stack 0.1.1)
- tests: 42 real-git stack tests; package tests added to local pytest testpaths

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@randlee
randlee merged commit 12ddf09 into develop Sep 23, 2026
14 checks passed
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.

1 participant