Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor: split the leave-open completion option into humanLandsPr and prStaysOpen (#12401)
[._.]/ Adam Eivycb39f944e12e
diff --git a/server/lib/README.md b/server/lib/README.mdindex ef0aab2bc6..7efc0b1c1f 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -736,7 +736,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `asyncApiSpec.js` | Builds the AsyncAPI 3 Socket.IO document from the generated event catalog with direction-aware operations and explicit modeled/generated payload status. || `mergeGateContract.js` | `buildManagedGithubMergeScript()` emits the shared claim merge block with verified allowed-method selection, fresh head/check/admission gates and fail-closed mutation readback. `MANAGED_WORKTREE_CLEANUP_CONTRACT` and its `MANAGED_WORKTREE_COMPLETION_HANDOFF` share head-pinned, checkout-preserving merge and archive/ownership-gated explicit cleanup instructions. `mergeGateOwed({taskOpenPR, rendersInlinePrLifecycle, leaveOpen})` decides whether a completing run actually owed its own PR merge — only the INLINE (`git`/`gh`) prompt renders a Merge Gate section, so a `/do:pr` run is inert here; `resolveMergeGateVerdict({prProbe, summary})` classifies a run that did (`merged` / `auto-merge-enabled` / `merge-handoff-queued` / `no-pr-action` / `leave-open-stated` / `needs-reprompt`) from the PR's live state and the agent's own sentinel text; `summaryStatesLeaveOpen` and `buildMergeGateReprompt` are its text-matching and corrective-prompt helpers. `buildAutoMergeHandoffInstructions(prRef)` shares the verified GitHub pending-CI handoff across generated merge workflows. `hasHealthyAutoMergeRequest(pr, now?)` bounds pending handoffs to one hour with readable, non-failed CI; `prProbe` also verifies the local head matches GitHub before accepting `autoMergeEnabled` or a pending-merge receipt (`mergeHandoffQueued`). Pure — the PR lookup lives in `../services/prProbe.js`, the re-prompt delivery in `agentTuiSpawning.js`. || `preflightPlan.js` | The programmatic phase of a user-triggered pipeline run, as renderable data. `preflightStepPlan(taskType)` is the step list (generic queued/prepare/dispatch, plus pr-reviewer's own cadence → list-PRs → in-flight → hidden-Unicode/prompt-injection screening → snapshot); `createPreflightState` opens it, `applyPreflightStep` advances one step and closes every earlier unfinished one, `finalizePreflight` closes it `handed-off`/`programmatic`/`nothing-to-do`/`failed`/`interrupted` (first close wins), and `preflightHeadline` names where the run is. Persisted onto a task card by `services/preflightTaskCard.js` and rendered by the Tasks page, so a Run Now is visible before any agent exists. Pure. |-| `prDisposition.js` | `resolveAppPrCompletion(app, metadata)` supplies the reviewed automatic merge default for new tasks while preserving explicit managed-app choices and legacy review toggles. `PR_MISSING_CATEGORY` shares the missing-PR verdict between finalization and cleanup. `resolvePrCompletion(metadata)` resolves the explicit `review-then-merge` / `merge-on-green` / `leave-open` policy, with legacy `reviewLoop` fallback; `explicitPrCompletion(task)` retains only explicit authority (defaults never release a handoff); `leavesPrForHuman(task)` + `PR_STAYS_OPEN_TASK_TYPES` keep JIRA hand-offs open. Shared by the agent prompt builder and `agentWorktreeCleanup` so both halves agree. `resolvePrCreation({taskOpenPR, agentOpensOwnPr, prClaimVerified})` → a `PR_CREATION` tri-state (`never` / `if-missing` / `always`) naming who opens the change request for a completing worktree agent, so the runner, TUI, and direct-CLI completion paths cannot drift into double-firing `gh pr create`. |+| `prDisposition.js` | `resolveAppPrCompletion(app, metadata)` supplies the reviewed automatic merge default for new tasks while preserving explicit managed-app choices and legacy review toggles. `PR_MISSING_CATEGORY` shares the missing-PR verdict between finalization and cleanup. `resolvePrCompletion(metadata)` resolves the explicit `review-then-merge` / `merge-on-green` / `leave-open` policy, with legacy `reviewLoop` fallback; `explicitPrCompletion(task)` retains only explicit authority (defaults never release a handoff); `leavesPrForHuman(task)` + `PR_STAYS_OPEN_TASK_TYPES` keep JIRA hand-offs open; `prStaysOpen(task)` is the combined policy-or-human verdict. Shared by the agent prompt builder and `agentWorktreeCleanup` so both halves agree. `resolvePrCreation({taskOpenPR, agentOpensOwnPr, prClaimVerified})` → a `PR_CREATION` tri-state (`never` / `if-missing` / `always`) naming who opens the change request for a completing worktree agent, so the runner, TUI, and direct-CLI completion paths cannot drift into double-firing `gh pr create`. || `recoveryMergeTarget.js` | `repositoryCleanupMergeTarget(task)` → the `{ url, branch }` parent PR a repository-cleanup recovery was filed to land, or null (#12251). A claimed target only: merge admission also requires the completed parent's server-written backlink to that exact task, branch and PR. || `prHandbackPolicy.js` | Whose turn it is on a public PR the pr-reviewer coordinator reviewed but did not merge. `resolvePullRequestWriteAccess(pr)` reads `isCrossRepository`/`maintainerCanModify` into a `PR_WRITE_ACCESS` reason, failing closed on an unknown head-repository relationship; `resolveHandbackDisposition({requestedChanges, notMergeReady, downgraded, deferred, canEdit, remediationExhausted})` returns a `PR_HANDBACK` verdict — `remediate` (PortOS pushes the fixes and lands it), `assign-opener` (the PR goes to its author queue), or `none`. A deferred or unanchorable review never becomes an agent work order. Pure. || `prReviewContent.js` | The one definition of the external pull-request content PortOS screens. `screenedPullRequestContent(pr, diff, commits?)` builds the contributor-authored surface — title, description, commit log, unified diff — and `screenedPullRequestFingerprint(pr, diff, commits?)` hashes it to a stable identity for one head commit, returning null when the commit log is missing rather than matching by omission. Both take the PR row, because the pr-reviewer preflight STAMPS that fingerprint and the coordinator RECOMPUTES it from a fresh forge read before it reviews, rebases, or merges: when the two hand-written field projections drifted apart, every approved review was dropped. Never rebuild either shape at a call site. Pure. |diff --git a/server/lib/prDisposition.js b/server/lib/prDisposition.jsindex 71a1923ddc..f234cf165b 100644--- a/server/lib/prDisposition.js+++ b/server/lib/prDisposition.js@@ -127,6 +127,17 @@ export function leavesPrForHuman(task) {return PR_STAYS_OPEN_SET.has(metadata.analysisType) || !!metadata.jiraTicketId;}+/**+ * True when the PR stays open for either reason: a human lands it (`leavesPrForHuman`)+ * or the resolved policy is leave-open (draft included). The one verdict callers+ * that do not need to distinguish the two should use.+ * @param {Object|null} task - the CoS task (or its metadata holder).+ * @returns {boolean}+ */+export function prStaysOpen(task) {+ return resolvePrCompletion(task?.metadata) === PR_COMPLETIONS.LEAVE_OPEN || leavesPrForHuman(task);+}+/** Explicit task authority only: defaults must never release a human handoff. */export function explicitPrCompletion(task) {const metadata = task?.metadata || {};diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex a03b85de62..5def9660d6 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -22,7 +22,7 @@ import { canTypeSlashCommands, PR_OPENED_BY, SLASHDO_INLINE_BUDGET_CHARS } fromimport { getDigitalTwinForPrompt } from './digital-twin.js';import { TASK_PROMPT_KEY, taskContextBlock } from '../lib/cosTaskPrompt.js';import { injectReconcileAgentId } from '../lib/claimContinuation.js';-import { PR_COMPLETIONS, leavesPrForHuman, resolvePrCompletion } from '../lib/prDisposition.js';+import { PR_COMPLETIONS, leavesPrForHuman, prStaysOpen, resolvePrCompletion } from '../lib/prDisposition.js';import { repositoryCleanupMergeTarget } from '../lib/recoveryMergeTarget.js';// Shared with cosTaskGenerator.js, which stamps the same set as metadata.claimFlow.import { isClaimFlowDispatch, resolveTaskHookType } from './taskTypeHooks.js';@@ -574,7 +574,7 @@ ${buildResumeSection(task, worktreeInfo)}` : '';mode: completionMode, whenDone,tuiCompletionCommand,worktreeInfo, willOpenPR, prCompletion, noChangeSuccess,- leavePrOpen: leavesPrForHuman(task),+ humanLandsPr: leavesPrForHuman(task),});const completionBullet = guidelineBullet ? `- ${guidelineBullet}` : '';// Which completion section this mode gets. A mode with no entry renders@@ -588,8 +588,8 @@ ${buildResumeSection(task, worktreeInfo)}` : '';[COMPLETION_MODES.DISCARD_WORKTREE]: () => buildProgrammaticOutputCompletionSection(sentinelPath),[COMPLETION_MODES.CLAIM_FLOW]: () => buildClaimFlowCompletionSection({isTui, sentinelPath, reviewersCsv: claimReviewersCsv(task, codeReviewDefaults, defaultReviewers),- leavePrOpen: resolvePrCompletion(task.metadata) === PR_COMPLETIONS.LEAVE_OPEN || leavesPrForHuman(task),- prCompletion: task.metadata?.prCompletion || null,+ prStaysOpen: prStaysOpen(task),+ rawPrCompletion: task.metadata?.prCompletion || null,claimResume: claimResumeContext(task, worktreeInfo),agentId,}),@@ -1107,12 +1107,12 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, { isTui = tsentinelPath: lightSentinelPath(),branchName: worktreeInfo?.branchName || null,baseBranch: worktreeInfo?.baseBranch || null,- leavePrOpen: leavesPrForHuman(task),+ humanLandsPr: leavesPrForHuman(task),reviewPolicy,forgeCli: resolvedForgeCli, localReviewSection, localReviewRequired, postPrReview: rendersInlinePrLifecycle ? runsPrSideReviewLoop : null,mergeAdmission: mergesOwnPr,}));- const pushCliCompletion = () => contractSections.push(buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletion, mode: completionMode, canTypeSlashCommands: canTypeSlash, rendersInlinePrLifecycle, simplifyEnabled, noChangeSuccess, leavePrOpen: leavesPrForHuman(task), reviewPolicy, forgeCli: resolvedForgeCli, localReviewSection, localReviewRequired, postPrReview: rendersInlinePrLifecycle ? runsPrSideReviewLoop : null, mergeAdmission: mergesOwnPr }));+ const pushCliCompletion = () => contractSections.push(buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletion, mode: completionMode, canTypeSlashCommands: canTypeSlash, rendersInlinePrLifecycle, simplifyEnabled, noChangeSuccess, humanLandsPr: leavesPrForHuman(task), reviewPolicy, forgeCli: resolvedForgeCli, localReviewSection, localReviewRequired, postPrReview: rendersInlinePrLifecycle ? runsPrSideReviewLoop : null, mergeAdmission: mergesOwnPr }));// Ahead of the completion workflow, whose TUI form ends on the sentinel write.// A repository-cleanup recovery lands its parent PR under the same lease (#12251).if (mergesOwnPr || repositoryCleanupMergeTarget(task)) contractSections.push(buildMergeAdmissionSection(agentId));@@ -1128,8 +1128,8 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, { isTui = t[COMPLETION_MODES.DISCARD_WORKTREE]: () => contractSections.push(buildProgrammaticOutputCompletionSection(lightSentinelPath())),[COMPLETION_MODES.CLAIM_FLOW]: () => contractSections.push(buildClaimFlowCompletionSection({isTui, sentinelPath: lightSentinelPath(), reviewersCsv: claimReviewersCsv(task, codeReviewDefaults, defaultReviewers),- leavePrOpen: resolvePrCompletion(task.metadata) === PR_COMPLETIONS.LEAVE_OPEN || leavesPrForHuman(task),- prCompletion: task.metadata?.prCompletion || null,+ prStaysOpen: prStaysOpen(task),+ rawPrCompletion: task.metadata?.prCompletion || null,claimResume: claimResumeContext(task, worktreeInfo),agentId,})),diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 879acd85be..5e355f2b3b 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -3032,7 +3032,7 @@ describe('buildCompletionGuidelineBullet', () => {// ...unless the PR is a human's to land, where the bullet must not promise a merge.const jiraBullet = buildCompletionGuidelineBullet({mode: resolveCompletionMode({ worktreeInfo: { worktreePath: '/wt' }, willOpenPR: true }),- tuiCompletionCommand: '/do:pr', worktreeInfo: { worktreePath: '/wt' }, willOpenPR: true, leavePrOpen: true,+ tuiCompletionCommand: '/do:pr', worktreeInfo: { worktreePath: '/wt' }, willOpenPR: true, humanLandsPr: true,});expect(jiraBullet).toMatch(/left OPEN for a human/);expect(jiraBullet).not.toMatch(/merges the PR once CI is green/);diff --git a/server/services/promptSections/completion.js b/server/services/promptSections/completion.jsindex 53a9a175d3..eeb42c21ac 100644--- a/server/services/promptSections/completion.js+++ b/server/services/promptSections/completion.js@@ -110,7 +110,7 @@ const DISCARD_WORKTREE_HYGIENE = '- **Do NOT commit, push, or open a PR.** Thisexport function buildCompletionGuidelineBullet({mode, tuiCompletionCommand,worktreeInfo, willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN,- leavePrOpen = false, noChangeSuccess = false, whenDone = null,+ humanLandsPr = false, noChangeSuccess = false, whenDone = null,}) {// NOTE: the TUI arms are only reachable from the full/api prompt path, where// `isTui` is currently always false (TUI providers route through@@ -150,7 +150,7 @@ export function buildCompletionGuidelineBullet({const runsReviewLoop = prCompletion === PR_COMPLETIONS.REVIEW_THEN_MERGE;const reviewSuffix = policyLeavesOpen? ' This task is configured to leave the PR OPEN for you to inspect — no follow-up agent will review or merge it automatically.'- : leavePrOpen+ : humanLandsPr? ' This task is tracked in JIRA, so the PR is left OPEN for a human to land alongside the ticket — nothing merges it automatically.' + (runsReviewLoop ? ' A follow-up agent still runs the configured reviewers against it.' : ''): runsReviewLoop? ' For GitHub PRs, a Copilot code review will also be requested automatically (skipped on GitLab and other non-GitHub forges) — do NOT run `/do:rpr` or attempt to address review comments yourself; you will have already exited.'@@ -533,7 +533,7 @@ export function claimReviewersCsv(task, codeReviewDefaults, defaultReviewers) {** @param {string} [reviewersCsv] - the emitted `--review-with` token list to pin;* empty suppresses the block (`buildReviewerPinNote` returns '').- * @param {boolean} [leavePrOpen] - keep reviews and CI, but hand off before merge.+ * @param {boolean} [prStaysOpen] - keep reviews and CI, but hand off before merge (a human lands it, or the policy leaves it open).* @param {string|null} [prCompletion] - the claim's PR completion policy* (`PR_COMPLETIONS`): `MERGE_ON_GREEN` suppresses the reviewer pin and emits* the merge-on-green handoff instead; any other value keeps the pin.@@ -647,17 +647,17 @@ export function buildMergeAdmissionSection(agentId) {].join('\n');}-export function buildClaimFlowCompletionSection({ isTui = false, sentinelPath = null, reviewersCsv = '', leavePrOpen = false, prCompletion = null, claimResume = null, agentId = null } = {}) {- const isMergeOnGreen = prCompletion === PR_COMPLETIONS.MERGE_ON_GREEN;+export function buildClaimFlowCompletionSection({ isTui = false, sentinelPath = null, reviewersCsv = '', prStaysOpen = false, rawPrCompletion = null, claimResume = null, agentId = null } = {}) {+ const isMergeOnGreen = rawPrCompletion === PR_COMPLETIONS.MERGE_ON_GREEN;const pin = isMergeOnGreen ? '' : buildReviewerPinNote(reviewersCsv);const resumeOverride = buildClaimResumeOverride(claimResume || {});const lines = [...(resumeOverride ? [resumeOverride, ''] : []),...(pin ? [pin, ''] : []),buildClaimOwnershipSection(agentId), '',- ...(!leavePrOpen ? [buildAutoMergeHandoffInstructions('"<PR_URL>"'), '', buildMergeAdmissionSection(agentId), ''] : []),+ ...(!prStaysOpen ? [buildAutoMergeHandoffInstructions('"<PR_URL>"'), '', buildMergeAdmissionSection(agentId), ''] : []),'## Claim Workflow Handoff',- ...(leavePrOpen ? [+ ...(prStaysOpen ? ['PR completion policy: LEAVE OPEN for further human review. This overrides any merge, auto-merge, issue-close, or merged-branch cleanup instruction in the claim prompt and delegated slashdo commands. Do not pass --merge, enable auto-merge, merge the PR/MR, or close the issue/ticket.','Complete implementation, configured reviews, publication, and CI checks as usual. Once those gates pass, leave the PR/MR open, report its URL and review/CI results, and preserve the claim markers, issue state, branch, and worktree for the human handoff. This is a successful completion; do not wait for a human or require MERGED status. Apply this policy to every child claim in a swarm.','',@@ -901,14 +901,15 @@ function localReviewCompletionInstruction(localReviewRequired = true) {* this IS a Claude session, so `/simplify` and `/do:pr` are both safe to emit* without a second provider check.*/-export function buildTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN, simplifyEnabled, sentinelPath, mode = COMPLETION_MODES.TUI, rendersInlinePrLifecycle = false, portosMergesBranch = false, branchName = null, baseBranch = null, leavePrOpen = false, reviewPolicy, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null, mergeAdmission = false }) {+export function buildTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN, simplifyEnabled, sentinelPath, mode = COMPLETION_MODES.TUI, rendersInlinePrLifecycle = false, portosMergesBranch = false, branchName = null, baseBranch = null, humanLandsPr = false, reviewPolicy, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null, mergeAdmission = false }) {const policyLeavesOpen = prCompletion === PR_COMPLETIONS.LEAVE_OPEN;const runsReviewLoop = prCompletion === PR_COMPLETIONS.REVIEW_THEN_MERGE;+ const prStaysOpen = humanLandsPr || policyLeavesOpen;if (mode === COMPLETION_MODES.TUI_SLASHDO_FREE) {// Plain `git`/`gh` instead of `/do:pr` — but still the whole lifecycle when// the session is a real coding harness (`rendersInlinePrLifecycle`); the reviewer// procedure it needs is inlined in the Review Loop section that follows.- return buildManualTuiCompletionSection({ willOpenPR, prCompletion, simplifyEnabled, sentinelPath, branchName, baseBranch, leavePrOpen, rendersInlinePrLifecycle, forgeCli, noChangeSuccess, localReviewSection, localReviewRequired, postPrReview });+ return buildManualTuiCompletionSection({ willOpenPR, prCompletion, simplifyEnabled, sentinelPath, branchName, baseBranch, humanLandsPr, rendersInlinePrLifecycle, forgeCli, noChangeSuccess, localReviewSection, localReviewRequired, postPrReview });}const cmd = willOpenPR ? '/do:pr' : '/do:push';// `/do:pr` may inherit a saved `review-with` default. Explicitly opt out@@ -920,7 +921,7 @@ export function buildTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLE// stay open — dropping our own merge steps isn't enough, `/do:pr` has to be// told not to merge (see lib/prDisposition.js). Under merge admission the// gate below merges inside the lease, so `/do:pr` must not merge first.- const mergeArg = (willOpenPR && (leavePrOpen || policyLeavesOpen || mergeAdmission)) ? ' --no-merge' : '';+ const mergeArg = (willOpenPR && (prStaysOpen || mergeAdmission)) ? ' --no-merge' : '';const reviewerArg = (reviewArgs ? ` ${reviewArgs}` : '') + mergeArg;const copilotOnly = reviewers.length === 1 && reviewers[0] === DEFAULT_REVIEWER && reviewUsernames.length === 0;const reviewerListLabel = [...reviewers, ...reviewUsernames.map(u => `@${u}`)].join(', ');@@ -948,9 +949,9 @@ export function buildTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLE// A PR gets merge steps — gated on the review verdict when a loop runs, on CI// alone when it doesn't (nothing else merges a no-review-loop PR). The one// exception is a PR a human lands (JIRA-tracked; see lib/prDisposition.js).- const merge = (willOpenPR && !leavePrOpen && !policyLeavesOpen)+ const merge = (willOpenPR && !prStaysOpen)? buildPostPRMergeSteps(3, { prCompletion, reviewPolicy, forgeCli, mergeAdmission })- : { lines: (leavePrOpen || policyLeavesOpen) && willOpenPR ? [LEAVE_PR_OPEN_STEP(3, leavePrOpen)] : [], nextStep: (leavePrOpen || policyLeavesOpen) && willOpenPR ? 4 : 3 };+ : { lines: prStaysOpen && willOpenPR ? [LEAVE_PR_OPEN_STEP(3, humanLandsPr)] : [], nextStep: prStaysOpen && willOpenPR ? 4 : 3 };const sentinelStep = merge.nextStep;return [@@ -1099,7 +1100,7 @@ function buildManualPrCreateStep(step, { branchName, baseBranch, forgeCli = 'gh'* commit and stop, PortOS owns the post-exit push / PR / review / merge* lifecycle.*/-function buildManualTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLETIONS.REVIEW_THEN_MERGE, simplifyEnabled, sentinelPath, branchName = null, baseBranch = null, leavePrOpen = false, rendersInlinePrLifecycle = false, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null }) {+function buildManualTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLETIONS.REVIEW_THEN_MERGE, simplifyEnabled, sentinelPath, branchName = null, baseBranch = null, humanLandsPr = false, rendersInlinePrLifecycle = false, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null }) {const policyLeavesOpen = prCompletion === PR_COMPLETIONS.LEAVE_OPEN;const runsReviewLoop = postPrReview ?? (prCompletion === PR_COMPLETIONS.REVIEW_THEN_MERGE);// `rendersInlinePrLifecycle` already folds in `willOpenPR`, the worktree, and@@ -1141,7 +1142,7 @@ function buildManualTuiCompletionSection({ willOpenPR, prCompletion = PR_COMPLET} else if (willOpenPR) {const handoff = policyLeavesOpen? 'PortOS will push the branch, create a pull request with your completion summary as its description, and leave it open for inspection.'- : leavePrOpen+ : humanLandsPr? 'PortOS will push the branch and create a pull request for the JIRA-linked human handoff.': runsReviewLoop? 'PortOS will push the branch, create a pull request with your completion summary as its description, run the configured reviewer follow-up, and merge only after review and CI pass.'@@ -1292,9 +1293,10 @@ export function buildInlineReviewLoopSection({* (`lib/agentCompletionMode.js`) rather than re-testing `worktreeInfo` /* `willOpenPR` — the caller already resolved those into `mode`.*/-export function buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN, mode = null, canTypeSlashCommands = false, rendersInlinePrLifecycle = false, simplifyEnabled = false, leavePrOpen = false, reviewPolicy, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null, mergeAdmission = false }) {+export function buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN, mode = null, canTypeSlashCommands = false, rendersInlinePrLifecycle = false, simplifyEnabled = false, humanLandsPr = false, reviewPolicy, forgeCli = 'gh', noChangeSuccess = false, localReviewSection = '', localReviewRequired = true, postPrReview = null, mergeAdmission = false }) {const policyLeavesOpen = prCompletion === PR_COMPLETIONS.LEAVE_OPEN;const runsReviewLoop = postPrReview ?? (prCompletion === PR_COMPLETIONS.REVIEW_THEN_MERGE);+ const prStaysOpen = humanLandsPr || policyLeavesOpen;if (canTypeSlashCommands && mode === COMPLETION_MODES.WORKTREE_NO_PUSH) {const lines = ['## Completion', ...(noChangeSuccess ? ['', NO_CHANGE_AUDIT_GUIDANCE, ''] : []), 'When finished, run these in order:'];let step = 1;@@ -1306,7 +1308,7 @@ export function buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompleti// `--no-merge` overrides a saved slashdo `merge: true` default, which would// otherwise merge a PR this task must leave open (see lib/prDisposition.js)// or merge outside the admission lease the merge steps below acquire.- const reviewerArg = (reviewArgs ? ` ${reviewArgs}` : '') + ((leavePrOpen || policyLeavesOpen || mergeAdmission) ? ' --no-merge' : '');+ const reviewerArg = (reviewArgs ? ` ${reviewArgs}` : '') + ((prStaysOpen || mergeAdmission) ? ' --no-merge' : '');const completionNote = runsReviewLoop? ((reviewers.length === 1 && reviewers[0] === DEFAULT_REVIEWER && reviewUsernames.length === 0)? 'and drives the Copilot review loop until clean.'@@ -1322,8 +1324,8 @@ export function buildCliCompletionSection({ worktreeInfo, willOpenPR, prCompletiif (effortNote) lines.push(` ${effortNote}`);// Merge steps follow — review-gated with a loop, CI-gated without one — unless// this PR is a human's to land (JIRA-tracked; see lib/prDisposition.js).- if (leavePrOpen || policyLeavesOpen) {- lines.push(LEAVE_PR_OPEN_STEP(step, leavePrOpen));+ if (prStaysOpen) {+ lines.push(LEAVE_PR_OPEN_STEP(step, humanLandsPr));} else {const merge = buildPostPRMergeSteps(step, { prCompletion, reviewPolicy, forgeCli, mergeAdmission });lines.push(...merge.lines);diff --git a/server/services/promptSections/completion.test.js b/server/services/promptSections/completion.test.jsindex 4bc6c2df86..77a9f912f7 100644--- a/server/services/promptSections/completion.test.js+++ b/server/services/promptSections/completion.test.js@@ -62,8 +62,8 @@ describe('review-enabled completion merge gate', () => {describe('claim ownership binding instructions (#10089)', () => {it('binds every branch the run checks out before its worktree exists, whatever the completion policy', () => {- for (const leavePrOpen of [false, true]) {- const prompt = buildClaimFlowCompletionSection({ agentId: 'parent-example', leavePrOpen });+ for (const prStaysOpen of [false, true]) {+ const prompt = buildClaimFlowCompletionSection({ agentId: 'parent-example', prStaysOpen });expect(prompt).toContain('"agentId":"parent-example","action":"bind","branch":"BRANCH"');expect(prompt).toContain('a tracking epic');expect(prompt).toContain('do not create or enter that worktree');@@ -98,7 +98,7 @@ describe('claim parent merge admission instructions', () => {expect(prompt).not.toMatch(/Keep admission through[^.]*CI/i);expect(prompt).not.toContain('if it moved, sync again');expect(buildClaimFlowCompletionSection()).toContain('do not merge');- expect(buildClaimFlowCompletionSection({ agentId: 'parent-example', leavePrOpen: true })).not.toContain('/merge-admission');+ expect(buildClaimFlowCompletionSection({ agentId: 'parent-example', prStaysOpen: true })).not.toContain('/merge-admission');});});@@ -110,7 +110,7 @@ describe('pending-merge handoff instructions (#12247)', () => {expect(prompt.indexOf('/api/cos/merge-handoff')).toBeLessThan(prompt.indexOf('Once required CI is green'));expect(prompt).toContain('NOT yet merged');expect(prompt).toContain('A refusal never permits merging without admission');- expect(buildClaimFlowCompletionSection({ agentId: 'parent-example', leavePrOpen: true })).not.toContain('/merge-handoff');+ expect(buildClaimFlowCompletionSection({ agentId: 'parent-example', prStaysOpen: true })).not.toContain('/merge-handoff');});// The recorded line must be the one shape cosMergeHandoff reads: REVIEW_STATUS