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
feat(cos): Claude Code CLI owns push+PR; Phase 3b opens clarification PR
[._.]/ Adam Eivyebd2802b5f50
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 9a5a1ec1b9..f86227c2d8 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1133,6 +1133,37 @@## Changed+- **CoS agent prompts: Claude Code CLI owns push + PR; Phase 3b opens a+ clarification PR.** Two coupled changes to the planned-work CoS templates+ (`feature-ideas`, `plan-task`) and the runtime CLI completion block:+ (1) When the provider is Claude Code (`claude-code` / `claude-code-bedrock`)+ and the task uses a worktree with `openPR`, the runtime "## Completion"+ section now instructs the agent to run `/simplify` (when enabled) and then+ `/do:pr` itself instead of "commit and let PortOS push" — and+ `cleanupAgentWorktree` is gated to skip its post-exit `git push` + `gh pr+ create` for those runs (mirrors the existing TUI cleanup contract) so the+ agent and PortOS don't both try to create the PR. Codex / Gemini and other+ CLI providers keep the previous "commit only, PortOS handles push+PR" block+ because they don't have slashdo commands available. (2) Phase 3b+ ("Request Clarification") no longer ends with "Do NOT open a PR — stop+ here" — that was orphaning the worktree on every `<!-- NEEDS_INPUT -->`+ flag. The agent now moves the flagged item to the bottom of PLAN.md+ (so subsequent runs pick up a different actionable item), commits the+ `.plan-questions.md` file + the PLAN.md move with `chore: flag PLAN.md+ item needing user input`, and proceeds to the Completion section so a+ clarification PR is opened for review. `PROMPT_VERSIONS` bumped+ (`feature-ideas` 6→7, `plan-task` 1→2) to auto-upgrade non-customized+ configs. `buildAgentPrompt` / `buildLightContextPrompt` now take a+ `providerId` option; covered by four new tests in+ `server/services/agentPromptBuilder.test.js` (slashdo Completion with+ `/simplify` enabled/disabled, `/do:push` fallback when `openPR` is false,+ unchanged behavior for non-Claude CLI providers). Touches:+ `server/services/agentPromptBuilder.js`,+ `server/services/agentPromptBuilder.test.js`,+ `server/services/agentLifecycle.js`,+ `server/services/agentCliSpawning.js`,+ `server/services/taskSchedule.js`.+- **CoS agent prompts: light vs full context split.** Codex / Claude Code /Gemini agents (`provider.type` ∈ {`tui`, `cli`}) now receive a minimalruntime-built prompt — just task description, attached context, screenshotdiff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.jsindex beb6d017e4..5c6243e67f 100644--- a/server/services/agentCliSpawning.js+++ b/server/services/agentCliSpawning.js@@ -568,13 +568,17 @@ export async function spawnDirectly(agentId, task, prompt, workspacePath, model,// Process memory extraction and app cooldownawait processAgentCompletion(agentId, task, success, outputBuffer);- // Clean up worktree if agent was using one+ // Clean up worktree if agent was using one. Claude Code CLI agents run+ // `/simplify` + `/do:pr` themselves (see buildCliCompletionSection in+ // agentPromptBuilder.js) — mirror the TUI cleanup contract so PortOS+ // doesn't double-fire push+PR creation.const directOpenPR = isTruthyMetaFn(task.metadata?.openPR);const directReviewLoopFollowUp = isTruthyMetaFn(task.metadata?.reviewLoopFollowUp);+ const directAgentOwnsPR = directOpenPR && (provider?.id === 'claude-code' || provider?.id === 'claude-code-bedrock');await cleanupWorktreeFn(agentId, success, {- openPR: directOpenPR,- requestCopilotReview: directOpenPR && isTruthyMetaFn(task.metadata?.reviewLoop),- skipMerge: directReviewLoopFollowUp,+ openPR: directAgentOwnsPR ? false : directOpenPR,+ requestCopilotReview: !directAgentOwnsPR && directOpenPR && isTruthyMetaFn(task.metadata?.reviewLoop),+ skipMerge: directReviewLoopFollowUp || directAgentOwnsPR,description: task.description,agentOutput: outputBuffer,originalTask: taskdiff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 6a49788ee3..b877abf890 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -436,7 +436,8 @@ export async function spawnAgentForTask(task) {// Build the agent prompt. `provider.type` drives the light-vs-full split// inside buildAgentPrompt — see its doc comment.const prompt = await buildAgentPrompt(task, config, workspacePath, worktreeInfo, isTruthyMeta, {- providerType: provider.type+ providerType: provider.type,+ providerId: provider.id});// Create agent directory@@ -1133,10 +1134,16 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration// body — re-merging the worktree branch into the source workspace would// duplicate the squashed commits, so suppress the auto-merge fallback.const taskReviewLoopFollowUp = isTruthyMeta(agent.task?.metadata?.reviewLoopFollowUp);+ // Claude Code CLI agents run `/simplify` + `/do:pr` themselves (see+ // buildCliCompletionSection in agentPromptBuilder.js) — they push the+ // branch and open the PR on their own. Mirror the TUI cleanup contract+ // so PortOS doesn't double-fire `gh pr create` ("a pull request already+ // exists" would preserve the worktree as a false-positive failure).+ const agentOwnsPR = taskOpenPR && (agent.providerId === 'claude-code' || agent.providerId === 'claude-code-bedrock');const cleanupWarnings = await cleanupAgentWorktree(agentId, success, {- openPR: taskOpenPR,- requestCopilotReview: taskOpenPR && taskReviewLoop,- skipMerge: taskReviewLoopFollowUp,+ openPR: agentOwnsPR ? false : taskOpenPR,+ requestCopilotReview: !agentOwnsPR && taskOpenPR && taskReviewLoop,+ skipMerge: taskReviewLoopFollowUp || agentOwnsPR,description: task?.description,agentOutput: outputBuffer,originalTask: taskdiff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex 0236e96de9..601832195c 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -174,13 +174,19 @@ const LIGHT_CONTEXT_PROVIDER_TYPES = new Set(['tui', 'cli']);* @param {Function} isTruthyMetaFn - isTruthyMeta function (passed to avoid circular dep)* @param {Object} options* @param {string} [options.providerType='api'] - `'tui' | 'cli' | 'api'`+ * @param {string} [options.providerId] - Provider id (e.g. `'claude-code'`). When the+ * CLI provider has access to the project's slashdo commands (Claude Code), the+ * light prompt instructs the agent to run `/simplify` and `/do:pr` itself+ * instead of relying on PortOS's post-exit push+PR. The spawner must then+ * pass `openPR: false` to `cleanupAgentWorktree` to avoid double-firing.*/export async function buildAgentPrompt(task, config, workspaceDir, worktreeInfo = null, isTruthyMetaFn = (v) => v === true || v === 'true', options = {}) {const providerType = options.providerType || 'api';+ const providerId = options.providerId || null;const isTui = providerType === 'tui';if (LIGHT_CONTEXT_PROVIDER_TYPES.has(providerType)) {- return buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui });+ return buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui, providerId });}// Full path: API providers don't read CLAUDE.md natively, so always include it.@@ -489,13 +495,18 @@ Begin working on the task now.`;* Falls back gracefully when worktree/jira/pipeline metadata is absent — only* the present sections render.*/-export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui = true } = {}) {+export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui = true, providerId = null } = {}) {const willOpenPR = isTruthyMetaFn(task.metadata?.openPR);const willReviewLoop = isTruthyMetaFn(task.metadata?.reviewLoop);const simplifyEnabled = isTruthyMetaFn(task.metadata?.simplify);const isReadOnly = isTruthyMetaFn(task.metadata?.readOnly);const isReviewLoopFollowUp = isTruthyMetaFn(task.metadata?.reviewLoopFollowUp);const isWorktreeOnExistingBranch = worktreeInfo?.existingBranch === true;+ // Claude Code CLI providers can drive `/simplify` + `/do:pr` themselves+ // (the slashdo submodule mounts those as project-level slash commands).+ // Other CLI providers (codex, gemini) can't — they get the legacy+ // commit-only block where PortOS handles push+PR on exit.+ const hasSlashdo = !isTui && (providerId === 'claude-code' || providerId === 'claude-code-bedrock');const sections = [];@@ -532,7 +543,7 @@ export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTrut`- **Path**: \`${worktreeInfo.worktreePath}\``,worktreeInfo.baseBranch ? `- **Based on**: \`${worktreeInfo.baseBranch}\`` : null,'',- worktreeCommitGuidance({ isTui, isWorktreeOnExistingBranch, willOpenPR }),+ worktreeCommitGuidance({ isTui, hasSlashdo, isWorktreeOnExistingBranch, willOpenPR }),'Do NOT manually switch branches or modify the worktree configuration.'].filter(Boolean).join('\n'));}@@ -595,7 +606,7 @@ export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTrutwillOpenPR, willReviewLoop, simplifyEnabled, sentinelPath: `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`}));} else {- sections.push(buildCliCompletionSection({ worktreeInfo, willOpenPR }));+ sections.push(buildCliCompletionSection({ worktreeInfo, willOpenPR, hasSlashdo, simplifyEnabled }));}sections.push('Begin working on the task now.');@@ -605,14 +616,20 @@ export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTrut/*** Worktree commit-guidance helper for the light prompt. Picks the right* single-sentence instruction based on whether the agent will run its own- * push workflow (TUI), reuse an existing PR branch (review fixes), or hand- * off to PortOS's post-exit push.+ * push workflow (TUI or Claude Code CLI with slashdo), reuse an existing PR+ * branch (review fixes), or hand off to PortOS's post-exit push.*/-function worktreeCommitGuidance({ isTui, isWorktreeOnExistingBranch, willOpenPR }) {+function worktreeCommitGuidance({ isTui, hasSlashdo, isWorktreeOnExistingBranch, willOpenPR }) {if (isTui) return 'Commit your changes to this branch — see **Completion Workflow** below.';if (isWorktreeOnExistingBranch) {return 'Commit and **push** any review-fix commits to this branch (the PR points at it). Use `git pull --rebase` before pushing if needed.';}+ if (hasSlashdo && willOpenPR) {+ return 'Commit your changes here — the **Completion** section below drives the push and PR. PortOS will NOT push or open a PR on your behalf.';+ }+ if (hasSlashdo) {+ return 'Commit your changes here — the **Completion** section below drives the push. PortOS will NOT push on your behalf.';+ }if (willOpenPR) {return 'Commit your changes here. The system will push and open a PR after you exit — do NOT push or open a PR yourself.';}@@ -662,11 +679,36 @@ function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabled}/**- * CLI (non-TUI) completion block. CLI agents (codex exec / claude -p /- * gemini one-shot) don't have slashdo commands available — they commit and- * PortOS handles the push/PR after exit.+ * CLI (non-TUI) completion block.+ *+ * Claude Code CLI agents have slashdo commands available (the submodule+ * mounts them as project-level slash commands), so when `hasSlashdo` is+ * true and a PR is expected, the agent owns the full `/simplify` → `/do:pr`+ * sequence and PortOS skips its post-exit push+PR. Codex/Gemini and other+ * CLI providers fall through to the legacy commit-only block where PortOS+ * handles push+PR on exit.*/-function buildCliCompletionSection({ worktreeInfo, willOpenPR }) {+function buildCliCompletionSection({ worktreeInfo, willOpenPR, hasSlashdo = false, simplifyEnabled = false }) {+ if (hasSlashdo && worktreeInfo && willOpenPR) {+ const lines = ['## Completion', 'When finished, run these in order without further user input:'];+ let step = 1;+ if (simplifyEnabled) {+ lines.push(`${step++}. \`/simplify\` — review the changed code for reuse, quality, and efficiency, and fix any findings.`);+ }+ lines.push(`${step++}. \`/do:pr\` — commits your changes, pushes the branch, and opens a pull request against the default branch.`);+ lines.push('', 'PortOS will NOT push or open a PR on your behalf.');+ return lines.join('\n');+ }+ if (hasSlashdo && worktreeInfo) {+ const lines = ['## Completion', 'When finished, run these in order without further user input:'];+ let step = 1;+ if (simplifyEnabled) {+ lines.push(`${step++}. \`/simplify\` — review the changed code for reuse, quality, and efficiency, and fix any findings.`);+ }+ lines.push(`${step++}. \`/do:push\` — commits your changes and pushes the branch.`);+ lines.push('', 'PortOS will NOT push on your behalf.');+ return lines.join('\n');+ }let body;if (worktreeInfo && willOpenPR) {body = 'Commit your changes (stage specific files, `feat:`/`fix:` prefix, no Co-Authored-By). Do NOT push — PortOS will push and open the PR after you exit.';diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 54bb6ad2a8..6672b56183 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -134,7 +134,7 @@ describe('buildLightContextPrompt', () => {expect(prompt).not.toMatch(/`\/do:pr`/);});- it('emits a non-TUI "Completion" block (no slashdo) for CLI agents', () => {+ it('emits a non-TUI "Completion" block (no slashdo) for non-Claude CLI agents', () => {const prompt = buildLightContextPrompt(makeTask({ metadata: { openPR: true } }),'/r',@@ -147,6 +147,42 @@ describe('buildLightContextPrompt', () => {expect(prompt).toMatch(/PortOS will push and open the PR/);});+ it('emits a slashdo Completion block (/simplify + /do:pr) for Claude Code CLI + openPR', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { openPR: true, simplify: true } }),+ '/r',+ { branchName: 'b', worktreePath: '/tmp/wt' },+ isTruthyMeta,+ { isTui: false, providerId: 'claude-code' });+ expect(prompt).toMatch(/^## Completion$/m);+ expect(prompt).toMatch(/`\/simplify`/);+ expect(prompt).toMatch(/`\/do:pr`/);+ expect(prompt).toMatch(/PortOS will NOT push or open a PR on your behalf/);+ expect(prompt).not.toMatch(/`\/quit`/);+ });++ it('skips /simplify in the slashdo Completion block when simplify is disabled', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { openPR: true, simplify: false } }),+ '/r',+ { branchName: 'b', worktreePath: '/tmp/wt' },+ isTruthyMeta,+ { isTui: false, providerId: 'claude-code' });+ expect(prompt).toMatch(/`\/do:pr`/);+ expect(prompt).not.toMatch(/`\/simplify`/);+ });++ it('uses /do:push (not /do:pr) for Claude Code CLI when openPR is false', () => {+ const prompt = buildLightContextPrompt(+ makeTask({ metadata: { openPR: false, simplify: true } }),+ '/r',+ { branchName: 'b', worktreePath: '/tmp/wt' },+ isTruthyMeta,+ { isTui: false, providerId: 'claude-code' });+ expect(prompt).toMatch(/`\/do:push`/);+ expect(prompt).not.toMatch(/`\/do:pr`/);+ });+it('suppresses the completion block and warns when readOnly is set', () => {const prompt = buildLightContextPrompt(makeTask({ metadata: { readOnly: true } }),diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex cf4ac9d58d..892c5fcc8d 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -367,9 +367,8 @@ Repository: {repoPath}- <question 1>- <question 2>\`\`\`-9. Annotate the PLAN.md item by appending \` <!-- NEEDS_INPUT -->\` to its line-10. Commit both changes with message "chore: flag PLAN.md item needing user input"-11. Do NOT open a PR — stop here+9. **Move the unchecked item to the bottom of PLAN.md and annotate it with \` <!-- NEEDS_INPUT -->\`** — remove the line from its current position and append it at the end of the file with the annotation. This keeps the queue moving so the next \`feature-ideas\` run picks up a different actionable item instead of repeatedly tripping on this one.+10. Commit both changes (the new \`.plan-questions.md\` file and the PLAN.md move) with message \`chore: flag PLAN.md item needing user input\`. Then proceed to the **Completion** section below so the clarification PR is opened for the user to review — do NOT leave the worktree orphaned.## Phase 4 — Brainstorm a New Feature@@ -440,16 +439,15 @@ Capture the exact text of the item you selected (without the leading \`- [ ]\`)- <question 1>- <question 2>\`\`\`-8. Annotate the PLAN.md item by appending \` <!-- NEEDS_INPUT -->\` to its line (do NOT remove it from PLAN.md)-9. Commit both changes with message \`chore: flag PLAN.md item needing user input\`-10. Do NOT open a PR — stop here+8. **Move the unchecked item to the bottom of PLAN.md and annotate it with \` <!-- NEEDS_INPUT -->\`** — remove the line from its current position and append it at the end of the file with the annotation. This keeps the queue moving so the next \`plan-task\` run picks up a different actionable item instead of repeatedly tripping on this one.+9. Commit both changes (the new \`.plan-questions.md\` file and the PLAN.md move) with message \`chore: flag PLAN.md item needing user input\`. Then proceed to the **Completion** section below so the clarification PR is opened for the user to review — do NOT leave the worktree orphaned.## Constraints- This task has **no \`runAfter\` dependencies** — it runs independently of \`do-replan\`, \`pr-reviewer\`, etc.- Do NOT brainstorm new features. Do NOT propose items not already in PLAN.md.- Do NOT touch unrelated PLAN.md items, even to tidy them.-- One commit. One PR (or no PR if clarification was needed).`,+- One commit. One PR — either the implementation PR (Phase 3a) or the clarification PR (Phase 3b).`,'code-reviewer-review': `[Review: {appName}] Deep Codebase Review (Stage 1)@@ -1080,8 +1078,8 @@ For each reference above:// Prompt versions — bump when a default prompt changes so existing instances auto-upgrade.// Only non-customized prompts (promptCustomized !== true) are upgraded.const PROMPT_VERSIONS = {- 'feature-ideas': 6, // v6: remove hardcoded worktree language (worktree context injected by agentPromptBuilder)- 'plan-task': 1, // v1: strict PLAN.md executor — move item to DONE.md in same commit, no brainstorm fallback, no runAfter deps+ 'feature-ideas': 7, // v7: Phase 3b reorders item to bottom + commits clarification PR instead of orphaning the worktree+ 'plan-task': 2, // v2: Phase 3b reorders item to bottom + commits clarification PR instead of orphaning the worktree'pr-reviewer': 3, // v3: multi-stage pipeline (security scan → code review + merge)'code-reviewer-a': 1, // v1: 2-stage pipeline (codebase review → triage & implement)'code-reviewer-b': 1, // v1: 2-stage pipeline (codebase review → triage & implement)