Skip to content

feat(#605): --stacked flag — chain-mode PR base to predecessor branch - #630

Merged
admarble merged 3 commits into
mainfrom
feature/605-feat-cli-stacked-flag-set-chain-mode-pr-base-to-pr
May 13, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/605-feat-cli-stacked-flag-set-chain-mode-pr-base-to-pr

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in --stacked flag to sequant run that implies --chain and changes only one thing: non-first PRs target their predecessor branch instead of main. The final PR still targets main so partial progress can land. Each PR body gets a stack manifest line:

Part of stack: #100 → #101 (this) → #102

Status note (PARK context)

This issue was PARKED 3× by /assess pending chain-mode reliability improvement. The user explicitly re-invoked /exec 605; this PR implements the feature as specified. --stacked is opt-in and inherits chain-mode's ~29% whole-chain success rate (#604); docs flag this explicitly.

AC Coverage

AC Status Evidence
AC-1: --stacked flag, implies --chain, error with --no-chain ✅ bin/cli.ts:223, src/commands/run.ts:51
AC-2: createPR uses predecessor branch for non-first issues ✅ src/lib/workflow/batch-executor.ts:995, worktree-manager.ts:1397
AC-3: First issue still targets main ✅ run-orchestrator.ts:executeSequential i > 0 guard
AC-4: PR body includes stack manifest ✅ worktree-manager.ts bodyLines + buildStackManifest
AC-5: Documented in chain-mode docs ✅ docs/reference/run-command.md "Stacked PRs" section
AC-6: merger skill warns on out-of-order stacked merges ✅ .claude/skills/merger/SKILL.md "Stacked PR Detection"

Open question resolution: Final-PR base defaults to main (the spec's preferred option — easier to land partial progress).

Plumbing Path

RunOptions.stacked → IssueExecutionContext.chain.{predecessorBranch, stackManifest} → createPR → GitHubProvider.createPRCliSync(... base?). Predecessor branch is computed only for non-first, non-last positions. Existing chain rebase logic (!chainMode || isLastInChain) is unchanged, so intermediate branches stay based on their predecessor.

Test plan

  • npm run build — clean
  • npm run lint — clean
  • npx vitest run src/lib/workflow/ src/commands/ __tests__/ — 1,696 tests pass
  • npx tsx bin/cli.ts run --help shows --stacked entry
  • Live verification: sequant run A B C --stacked --dry-run on a real 2-issue chain (deferred — requires real worktree setup)

Files changed (13)

  • bin/cli.ts — register --stacked
  • src/commands/run.ts — validate --stacked + --no-chain conflict; auto-enable --chain
  • src/lib/workflow/types.ts — add RunOptions.stacked; extend IssueExecutionContext.chain
  • src/lib/workflow/run-orchestrator.ts — buildStackManifest; predecessor wiring in executeSequential
  • src/lib/workflow/batch-executor.ts — pass stackOptions to createPR
  • src/lib/workflow/worktree-manager.ts — createPR accepts stackOptions; embeds manifest in body
  • src/lib/workflow/platforms/github.ts — createPRCliSync(... base?)
  • docs/reference/run-command.md — "Stacked PRs" section + flag-table entry
  • .claude/skills/merger/SKILL.md — "Stacked PR Detection" + out-of-order warning template
  • CHANGELOG.md — [Unreleased] entry
  • 3 test files (unit + integration coverage)

Closes #605

🤖 Generated with Claude Code

…anch

Adds an opt-in `--stacked` flag to `sequant run` that implies `--chain` and
changes only one thing: non-first PRs target their predecessor branch via
`gh pr create --base <prev-branch>` instead of `main`. The final PR still
targets `main` so partial progress can land. Each PR body includes a stack
manifest line so reviewers see the chain at a glance.

The plumbing path is `RunOptions.stacked` → `IssueExecutionContext.chain.
{predecessorBranch, stackManifest}` → `createPR` → `GitHubProvider.
createPRCliSync(... base?)`. The orchestrator computes the predecessor
branch from `worktreeMap.get(issueNumbers[i-1])?.branch` only for non-first,
non-last positions; existing rebase logic (`!chainMode || isLastInChain`)
is unchanged.

Includes a `/merger` skill section warning about out-of-order stack merges
(GitHub auto-updates dependent PR bases when predecessors merge, so order
matters) and updates `docs/reference/run-command.md` with the standard
chain-mode reliability caveat (~29% whole-chain success rate).

Tests:
- buildStackManifest pure-fn tests (first/middle/last/degenerate cases)
- Orchestrator chain-context plumbing for --stacked vs plain --chain
- createPR `--base` passing + manifest embedding + non-stacked omission
admarble added 2 commits May 12, 2026 23:20
…veats, skill mirrors

- bin/cli.ts: --stacked help text now reflects that the last PR also targets
  main (previously implied all non-first PRs targeted predecessor)
- src/lib/workflow/platforms/github.ts: async createPR(opts) now forwards
  opts.base to gh pr create (pre-existing latent gap; CreatePROptions.base is
  a required field but was silently dropped)
- docs/reference/run-command.md: add Caveats subsection covering 2-issue
  stack manifest-only behavior and final-PR cumulative diff
- src/lib/workflow/run-orchestrator.ts: document the worktreeMap.get()
  invariant so a future refactor of the chain-break path can't silently
  violate AC-2
- skills/merger, templates/skills/merger: mirror the merger skill (including
  the new Stacked PR Detection subsection) so it deploys via sequant init
…stacked-flag-set-chain-mode-pr-base-to-pr

# Conflicts:
#	CHANGELOG.md
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(cli): --stacked flag — set chain-mode PR base to predecessor branch

1 participant