Repository navigation
feat(config): targetBranch — build into a branch other than the default - #15
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An optional .foreman/config.json key. Absent, the daemon and ctl resolve the GitHub default branch as before; set, it is used as written with no gh call. Ctx.defaultBranch becomes Ctx.targetBranch, and the dispatch helpers take the same name. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A {{targetBranch}} placeholder, filled per dispatch. The builder merges
origin/{{targetBranch}} and opens its PR with --base {{targetBranch}};
the planner's plan PR does the same. Ground rules, reviewer, planner and
phase-closer name the target branch where they said the default branch,
and the session header says "Never touch <target>". The phase-closer
leads with a base-filtered merged-PR search, because GitHub records
closing PRs only for the default branch.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
writeSessionFiles appends push, HEAD:<t>, checkout, switch and branch -D denies for the target branch next to the worktree denies, mirroring the static main/master rules in settings/headless.json, which stay. Nothing is added when the target is main or master. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
listOpenPRs requests baseRefName. buildSnapshot keeps only PRs whose base
is the target and records the target on the snapshot, so pairing, picks,
CI reruns, merges and the idle fingerprint never see the rest. planPR
filters by base too, runRole only borrows a head branch from a PR on the
target, and mergeDecision refuses a base mismatch as a guard in depth
("targets <base>, not <target>"). Conflict reasons, the waiting text and
the plan-apply logs name the target instead of main.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
With targetBranch set, preflight runs git ls-remote --exit-code --heads origin <target> in repoDir and parks with "target branch <name> not found on origin" when it fails, instead of every issue blocking at worktree setup. With the key absent, no call is made. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
fileOnDefaultBranch takes an optional ref, sent as ?ref=<ref> on the contents API. epic new passes the repository's targetBranch, so the spec must exist where the foreman builds; with the key absent the call is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The config row, a section on building into a branch other than the default (a dedicated clone checked out on it, .foreman/ only there), and the three limits: CI must run on PRs to the target, Closes #N does not auto-close or link, and branch protection can refuse a merge. Default-branch wording elsewhere now says target branch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…he name - buildSnapshot and runRole's lookup keep a PR only when its base is the target and its head is none of the target, main or master. A "merge main into v2" PR naming a task would otherwise be paired with it, and a fix or rebase round would build on main and push there. - Preflight asks ls-remote for refs/heads/<t>, so release/v2 does not satisfy v2. Exit 2 is "not found on origin"; any other failure is "could not reach origin to check target branch <t>". - targetBranch must be a plain name: [A-Za-z0-9._/-] only, no leading -, no refs/ or origin/ prefix. The daemon refuses anything else, naming the file, as for any bad key. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ault - ensureWorktree creates a new branch with --no-track, so it never tracks origin/<target> and a bare git push cannot land there. Nothing depended on that upstream: the builder's first git push -u sets the real one, and a reused worktree's pull --ff-only before that push now warns and carries on instead of fast-forwarding to the target. - With targetBranch absent and gh.defaultBranch() failing at startup, the daemon no longer assumes main for its whole life. ctx.targetBranch stays empty; runOnce retries the lookup after preflight passes and parks with "could not resolve the default branch" until it succeeds. realCtx's plan-file and worktree closures read ctx.targetBranch when they run, and buildSnapshot refuses to run without a target. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| // it is never paired with a task, reviewed, rebased, rerun or merged, and never moves the idle | ||
| // fingerprint. | ||
| const prs = (await ctx.gh.listOpenPRs()).filter( | ||
| (p) => !p.isDraft && workablePR(p, ctx.targetBranch), |
There was a problem hiding this comment.
PR on the wrong base silently stalls its task forever. A PR that does not target the target branch is dropped here without any signal. But the builder's pr_opened outcome still moves the issue to In Review (loop.ts, case "pr_opened"). From then on jobCandidates, mergeActions and describeWaiting all iterate s.prs, so the issue gets no review, merge or rebase, and no Waiting item appears. Its phase can never close.
Scenario: targetBranch is v2. A builder runs gh pr create without --base because a house rule or habit overrode the role prompt, so gh defaults to main. The task then stalls silently. The same thing happens to tasks whose PRs were already open against main when targetBranch was switched. It also happens to a plan PR opened on the wrong base: planPR finds nothing, so the plan is never merged.
Suggest: on pr_opened, check the PR's base and block with a reason if it is wrong, or surface off-target PRs that reference a task as a human Waiting item instead of dropping them silently.
There was a problem hiding this comment.
Fixed in 998fccb: a builder pr_opened now reads the PR's base and head and, if the PR targets another branch or comes from a protected one, blocks the task with PR #<n> targets <base>, not <target>; re-aim it (gh pr edit <n> --base <target>) and press Unblock instead of moving it to In Review. Already-open off-target PRs are kept on the snapshot, so an In Review task whose only PR is off-target gets one block, and an off-target plan PR is reported through plan_pr_stuck once per head sha.
There was a problem hiding this comment.
Follow-up in c8c66b3: an off-target plan PR's comment now names the re-aim command and warns that merging by hand lands it on the wrong base, it shows under Waiting, and the task block reason also offers dropping the task from the PR body.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…er Waiting Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Summary
Adds an optional
.foreman/config.jsonkey,targetBranch, so the foreman can build into a long-lived branch (MC v2 onv2) while the GitHub default branch keeps shipping. Absent, the foreman targets the default branch as before. Design:docs/superpowers/specs/2026-11-19-target-branch-design.md.targetBranch ?? gh.defaultBranch();Ctx.defaultBranchrenamedtargetBranch. Without the key, a failed default-branch lookup no longer guessesmain: the tick parks withcould not resolve the default branchand retries next tick.{{targetBranch}}placeholder; buildergh pr create --base {{targetBranch}}and everygit merge origin/{{targetBranch}}; planner plan PR--base {{targetBranch}}; phase-closer looks up merged PRs by--basefirst (GitHub only links closing PRs for the default branch).workablePR): base must be the target, head must not be the target,mainormaster. Applied inbuildSnapshotandrunRole's lookup;planPRfilters by base;mergeDecisionrefuses a base mismatch. A human PR tomainsayingCloses #Nis never paired, reviewed, rebased, rerun or merged.target branch <t> not found on origin(exit 2 ofls-remote --exit-code --heads origin refs/heads/<t>) orcould not reach origin to check target branch <t>.epic newchecks the spec on the target branch (?ref=). Branch name is validated. New worktree branches use--no-track.Closes #Ndoes not auto-close, branch protection can refuse a merge).Behaviour changes without the key
main/masteris ignored.main)" where they said "the default branch".main/master) is now blocked withPR #<n> targets <base>, not <default>; re-aim it … and press Unblockinstead of stalling silently; a builderpr_openedon such a PR blocks at once.Test plan
pnpm lint && pnpm typecheck && pnpm test && pnpm build(782 tests; 818 merged with feat(decisions): closing a decision as completed unblocks its task #14, both green)foreman -p mc-v2 run --once --dry-runagainstapptreesoftware/maintenanceconnection-r7withtargetBranch: v2: preflight ok, MC's three open PRs intodevelopignored,idle(nothing eligible)Known minor gap: with the key set and a default branch that is neither
mainnormaster, a PR from that default branch is not on the protected-head list (does not affect MC, whose default ismain).🤖 Generated with Claude Code