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(cos): trim plan-task prompt and TUI Completion Workflow
[._.]/ Adam Eivyd8e29287e984
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 45c7d853a4..bb40d77dd9 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -18,6 +18,8 @@- **Pipeline series arc — inline theme editing.** Theme pills on the Series Arc card are now directly editable: click a pill to rename, hover for the × to remove, click the dashed "+ Add theme" chip to append (up to 20 themes, 100 chars each — matching `ARC_LIMITS` on the server). Writes are optimistic with a single-flight save gate so a blur-then-click sequence can't double-persist against stale state. The redundant comma-separated themes input was removed from the "Edit arc" form; logline / summary / protagonist arc / shape still live there.- **Universe Builder — unify style/negative prompts with the embrace/avoid chip editor.** The prose `stylePrompt` and `negativePrompt` textareas have been removed; the universe's style + negative prompts now live as draggable token lists in `influences.embrace` / `influences.avoid` and are the single editing surface (relabeled in the UI as "Style prompt (embrace)" and "Negative prompt (avoid)"). The renderer joins each list verbatim into the rendered prompt the same way the prose fields used to compose. Existing universes auto-migrate on first read: prose tokens are split on commas, deduped case-insensitively against any pre-existing chips, capped at 30 per list, and persisted (`schemaVersion` bumped to 3). The LLM expand + refine flows now emit `influences` only — no more separate `stylePrompt`/`negativePrompt` keys. Stale-client PATCH payloads still carrying prose fields are absorbed into the chip lists server-side so a stale browser tab doesn't 400.+- **CoS prompts — trimmed plan-task template and TUI Completion Workflow preamble.** The `plan-task` default prompt (`server/services/taskSchedule.js`) dropped its `## Constraints` section (redundant with the Phase 1 strict-executor framing), all `Repository: {repoPath}` / `from {repoPath}` / `in {repoPath}` references (the agent is already cwd'd into the worktree), and the duplicated `/simplify` + explicit commit steps that the Completion Workflow already drives — bumped `PROMPT_VERSIONS['plan-task']` to v3 so existing installs with the v2 default auto-upgrade. The shared TUI Completion Workflow (`server/services/agentPromptBuilder.js`, both the inline full-context block and the `buildTuiCompletionSection` helper) lost its "You own the entire commit → push → PR sequence — PortOS will NOT push or open a PR on your behalf" preamble and the PR-body advice paragraph, collapsed to one line ("When the task is complete, run these in order:") followed by the four functional steps (`/simplify` → `/do:pr` → `.agent-done` sentinel → `/quit`). All 19 `agentPromptBuilder` tests still pass.+## Fixed- **Pipeline arc regenerate — preserve child issues when the LLM mints fresh season uuids.** The follow-up to the `arc/resolve` remap shipped earlier today: the "Regenerate arc" button (`POST /api/pipeline/series/:id/arc/generate` with `commit:true`) was writing brand-new season ids on every run without remapping child issues — every regenerate stranded every issue behind a defunct `seasonId`. Hoisted the resolve path's remap+reassign body into a shared `commitSeasonsWithRemap(currentSeries, { arc, seasons })` helper on `arcPlanner`; the `/arc/generate` commit branch now routes through it, so a regenerate now reattaches existing issues to the new seasons by normalized title → unique `number` → positional fallback (exact mirror of the resolve path). Also added `scripts/repair-orphaned-issues.js --series=<id>` as a one-shot data tool for installs already affected by the gap — runs dry-run by default, requires `--apply` to write, refuses non-1:1 orphan/season counts.diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex da3a9d3cef..eadea4ff8f 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -258,11 +258,11 @@ After completing your work and before committing, run \`/simplify\` to review thconst tuiCompletionCommand = willOpenPR ? '/do:pr' : '/do:push';const tuiCompletionSection = isTui ? `## Completion Workflow-You are running inside the Claude Code TUI, which has the project's slashdo commands available as slash commands. **You own the entire commit → push → ${willOpenPR ? 'PR' : 'push'} sequence — PortOS will NOT push or open a PR on your behalf.** When your task is complete, run the following — in order — without further user input:+When the task is complete, run these in order:-1. ${simplifyEnabled ? '`/simplify` — review the changed code for reuse, quality, and efficiency, and fix any issues it surfaces.' : '(simplify is disabled for this task — skip step 1)'}-2. \`${tuiCompletionCommand}\` — commits${willOpenPR ? `, pushes, and opens a pull request against the default branch. Write the PR title and body yourself based on the actual changes you made; do NOT let any tool auto-generate the body from terminal output.${willReviewLoop ? ' After the PR is open, request a Copilot review (e.g. via `gh` if available).' : ''}` : ' and pushes the branch'}.-3. Write your task summary to the completion sentinel as a SHORT markdown report — this becomes the task summary PortOS displays in the agent card and feeds into downstream features (memory extraction, completion hooks, etc.). Aim for ~5–15 lines. Use this exact shell-quoted heredoc form:+1. ${simplifyEnabled ? '`/simplify`' : '(simplify is disabled — skip)'}+2. \`${tuiCompletionCommand}\`${willReviewLoop && willOpenPR ? ' — after the PR opens, request a Copilot review (e.g. via `gh`).' : ''}+3. Write a short markdown summary (~5–15 lines) to the completion sentinel — PortOS polls this every 2s; without it the agent sits idle until a 3-minute fallback fires.\`\`\`bashcat > "${worktreeInfo?.worktreePath || workspaceDir}/.agent-done" <<'EOF'@@ -276,11 +276,7 @@ You are running inside the Claude Code TUI, which has the project's slashdo comm${willOpenPR ? '## PR\n <PR URL>' : '## Branch\n <branch name>'}EOF\`\`\`-- PortOS polls for this file every 2 seconds; without it the agent will sit idle until the 3-minute fallback timer fires.-4. Run \`/quit\` to exit the Claude Code session cleanly.--Do not wait for further user input between these steps — run them in sequence as soon as the implementation work is finished.+4. \`/quit\`.` : '';// Build review loop section if enabled. The agent itself does NOT open the PR@@ -642,24 +638,18 @@ function worktreeCommitGuidance({ isTui, hasSlashdo, isWorktreeOnExistingBranch,*/function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabled, sentinelPath }) {const cmd = willOpenPR ? '/do:pr' : '/do:push';- const verb = willOpenPR ? 'PR' : 'push';- const cmdEffect = willOpenPR- ? ', pushes, and opens a PR against the default branch. Write the PR title and body yourself; do NOT let any tool auto-generate from terminal output'- : ' and pushes the branch';const reviewSuffix = willOpenPR && willReviewLoop- ? ' After the PR is open, request a Copilot review (e.g. via `gh`).' : '';- const simplifyStep = simplifyEnabled- ? '1. `/simplify` — review the changed code for reuse/quality/efficiency and fix any findings.'- : '1. (simplify disabled — skip)';+ ? ' — after the PR opens, request a Copilot review (e.g. via `gh`).' : '';+ const simplifyStep = simplifyEnabled ? '1. `/simplify`' : '1. (simplify disabled — skip)';const sentinelTail = willOpenPR ? ' ## PR\n <PR URL>' : ' ## Branch\n <branch name>';return ['## Completion Workflow',- `You own the entire commit → push → ${verb} sequence. PortOS will NOT push or open a PR for you. When the task is complete, run these in order without further user input:`,+ 'When the task is complete, run these in order:','',simplifyStep,- `2. \`${cmd}\` — commits${cmdEffect}.${reviewSuffix}`,- '3. Write the completion sentinel as a SHORT markdown report (~5–15 lines):',+ `2. \`${cmd}\`${reviewSuffix}`,+ '3. Write a short markdown summary (~5–15 lines) to the completion sentinel — PortOS polls this every 2s; without it the agent sits idle until a 3-minute fallback fires.','',' ```bash',` cat > "${sentinelPath}" <<'EOF'`,@@ -672,9 +662,7 @@ function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabledsentinelTail,' EOF',' ```',- '',- ' PortOS polls for this file every 2 seconds; without it the agent sits idle until the 3-minute fallback fires.',- '4. Run `/quit` to exit cleanly.'+ '4. `/quit`.'].join('\n');}diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 892c5fcc8d..e9ece6e29b 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -396,39 +396,31 @@ When PLAN.md is missing, empty, or fully completed, brainstorm and implement a n'plan-task': `[Plan Task: {appName}] Execute Next PLAN.md Item-Your goal is to implement the next unchecked item from PLAN.md and archive it to DONE.md in the same commit. No brainstorming, no scope expansion — just execute what is already planned.--Repository: {repoPath}+Implement the next unchecked item from PLAN.md and archive it to DONE.md. No brainstorming, no scope expansion — just execute what is already planned.## Phase 1 — Find the Next Task-1. Read PLAN.md from {repoPath}-2. Read DONE.md from {repoPath} (if it exists) so you understand the archive format-3. Find the first unchecked item (\`- [ ]\`) that does NOT have a \`<!-- NEEDS_INPUT -->\` annotation-4. If PLAN.md is missing, has no unchecked items, or every unchecked item is annotated \`<!-- NEEDS_INPUT -->\`, **stop here** — exit cleanly without commits or PR. This task is a strict executor of planned work; brainstorming is handled by the \`feature-ideas\` task.+1. Read PLAN.md and DONE.md (if present, for archive-format reference).+2. Pick the first unchecked item (\`- [ ]\`) that does NOT have a \`<!-- NEEDS_INPUT -->\` annotation.+3. If PLAN.md is missing, has no unchecked items, or every unchecked item is annotated \`<!-- NEEDS_INPUT -->\`, **stop here** — exit cleanly without commits or PR. Brainstorming is handled by the \`feature-ideas\` task.-Capture the exact text of the item you selected (without the leading \`- [ ]\`) — you will need it verbatim for the DONE.md entry.+Capture the exact text of the selected item (without the leading \`- [ ]\`) verbatim — DONE.md will reuse it.-## Phase 2 — Evaluate Feasibility+## Phase 2 — Decide-5. Read relevant source files to understand the scope of the item-6. Decide: can this be implemented without user clarification? (requirements clear, no ambiguous design choices, no blocking external decisions)+Read relevant source files. Can this be implemented without user clarification (requirements clear, no ambiguous design choices, no blocking external decisions)?## Phase 3a — Implement (if feasible)-7. Implement the change:- - Write clean, tested code following existing patterns- - Run tests to ensure nothing is broken-8. Run \`/simplify\` to review changed code for reuse, quality, and efficiency. Fix any issues found in the same diff.-9. **Move the item from PLAN.md to DONE.md (do NOT leave a checked \`- [x]\` behind in PLAN.md):**- - Remove the item's line(s) from PLAN.md entirely. If the item was a nested bullet under a heading and removing it leaves the surrounding section empty, leave the heading alone — separate plan curation is the \`do-replan\` task's job.- - Append a corresponding entry to DONE.md under today's date heading (\`## YYYY-MM-DD\`). Insert today's date heading directly below the top-of-file preamble if no section for today exists; otherwise append under the existing section.- - DONE.md entry format: \`- **<short title pulled from the PLAN.md item>** — <1–3 sentences describing what was actually implemented, key files touched, and any caveats>\`. Mirror the prose style of recent DONE.md entries.-10. Commit the code change, the PLAN.md removal, and the DONE.md append **together in a single commit**. Commit message should reference the PLAN.md item title.+1. Implement the change. Write clean, tested code following existing patterns and run tests.+2. **Move the item from PLAN.md to DONE.md (do NOT leave a checked \`- [x]\` behind in PLAN.md):**+ - Remove the item's line(s) from PLAN.md entirely. If removing it leaves a heading empty, leave the heading alone — plan curation is the \`do-replan\` task's job.+ - Append the entry to DONE.md under today's date heading (\`## YYYY-MM-DD\`). Insert today's heading directly below the top-of-file preamble if it doesn't exist yet.+ - Entry format: \`- **<short title from the PLAN.md item>** — <1–3 sentences on what was implemented, key files touched, and any caveats>\`. Mirror the prose style of recent DONE.md entries.## Phase 3b — Request Clarification (if not feasible)-7. Create a file named \`.plan-questions.md\` in {repoPath} with this format:+1. Create \`.plan-questions.md\`:\`\`\`# Plan Question: <short title summarizing the PLAN.md item>@@ -439,15 +431,7 @@ Capture the exact text of the item you selected (without the leading \`- [ ]\`)- <question 1>- <question 2>\`\`\`-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 — either the implementation PR (Phase 3a) or the clarification PR (Phase 3b).`,+2. **Move the unchecked item to the bottom of PLAN.md and annotate it with \` <!-- NEEDS_INPUT -->\`** — remove from its current position and append at the end with the annotation. This keeps the queue moving so the next \`plan-task\` run picks up a different actionable item.`,'code-reviewer-review': `[Review: {appName}] Deep Codebase Review (Stage 1)@@ -1079,7 +1063,7 @@ For each reference above:// Only non-customized prompts (promptCustomized !== true) are upgraded.const PROMPT_VERSIONS = {'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+ 'plan-task': 3, // v3: drop Constraints section + {repoPath} refs + commit/simplify steps already covered by the Completion Workflow'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)