Skip to content

feat(config): targetBranch — build into a branch other than the default - #15

Merged
matthewtsmith merged 12 commits into
mainfrom
feat/target-branch
Nov 20, 2026
Merged

matthewtsmith merged 12 commits into
mainfrom
feat/target-branch

Conversation

@aicorey

@aicorey aicorey commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds an optional .foreman/config.json key, targetBranch, so the foreman can build into a long-lived branch (MC v2 on v2) 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.

  • Resolution: targetBranch ?? gh.defaultBranch(); Ctx.defaultBranch renamed targetBranch. Without the key, a failed default-branch lookup no longer guesses main: the tick parks with could not resolve the default branch and retries next tick.
  • Prompts: {{targetBranch}} placeholder; builder gh pr create --base {{targetBranch}} and every git merge origin/{{targetBranch}}; planner plan PR --base {{targetBranch}}; phase-closer looks up merged PRs by --base first (GitHub only links closing PRs for the default branch).
  • Only PRs into the target, from a non-protected head, exist for the foreman (workablePR): base must be the target, head must not be the target, main or master. Applied in buildSnapshot and runRole's lookup; planPR filters by base; mergeDecision refuses a base mismatch. A human PR to main saying Closes #N is never paired, reviewed, rebased, rerun or merged.
  • Session denies: the 7 main/master deny rules are generated for the target branch too (skipped when the target is main/master).
  • Preflight parks with target branch <t> not found on origin (exit 2 of ls-remote --exit-code --heads origin refs/heads/<t>) or could not reach origin to check target branch <t>.
  • epic new checks the spec on the target branch (?ref=). Branch name is validated. New worktree branches use --no-track.
  • README: config row and "Building on a branch other than the default" (dedicated clone on the target branch, CI must run on PRs to it, Closes #N does not auto-close, branch protection can refuse a merge).

Behaviour changes without the key

  • A PR whose base is not the default branch (stacked or human PRs) is now ignored; a PR from main/master is ignored.
  • A default branch not named main/master now gets the same session push denies.
  • Role prompts say "the target branch (main)" where they said "the default branch".
  • An In Review task whose only open PR is aimed at a branch other than the default (or comes from main/master) is now blocked with PR #<n> targets <base>, not <default>; re-aim it … and press Unblock instead of stalling silently; a builder pr_opened on such a PR blocks at once.
  • A plan PR aimed at a branch other than the default now gets a plan-stuck comment on its epic, once per push (naming the re-aim command and warning that a hand merge lands it on the wrong branch), and shows under Waiting.

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)
  • Two review rounds, including a reproduced "PR from main → builder pushes to main" path, now closed
  • foreman -p mc-v2 run --once --dry-run against apptreesoftware/maintenanceconnection-r7 with targetBranch: v2: preflight ok, MC's three open PRs into develop ignored, idle(nothing eligible)
  • First live run on MC v2 (P0 plan) — after merge

Known minor gap: with the key set and a default branch that is neither main nor master, a PR from that default branch is not on the protected-head list (does not affect MC, whose default is main).

🤖 Generated with Claude Code

aicorey and others added 10 commits November 19, 2026 11:08
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>
Comment thread src/loop.ts Outdated
// 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),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

aicorey and others added 2 commits November 19, 2026 15:25
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>
@matthewtsmith
matthewtsmith merged commit c32dc1f into main Nov 20, 2026
1 check 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.

2 participants