Skip to content

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

feat(tui): capture agent task summary via .agent-done sentinel

[._.]/ Adam Eivy83cd02ee867b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 0c4e424485..7fe7892208 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -932,6 +932,22 @@
## Changed
+- **TUI agents now write a markdown task summary into `.agent-done` and
+ PortOS ingests it as the agent's `outputBuffer`.** With per-line PTY
+ capture off, the agent card's "Show output" panel only showed
+ lifecycle events — no view of what the agent actually accomplished,
+ and downstream consumers (`extractFinalSummary`, memory extraction,
+ completion hooks) had nothing to work with. The Completion Workflow
+ prompt section now instructs the agent to `cat > .agent-done <<EOF
+ …` a short markdown report (Summary / Changes / PR sections) instead
+ of just `echo "done"`. The spawner's sentinel watcher reads that
+ content, line-feeds it through `appendLine` so it lands in both
+ `outputBuffer` and `output.txt`, and caps the ingested content at 4 KB
+ so a runaway agent that dumps an entire diff doesn't bloat the agent
+ record or downstream memory prompts. Headless CLI agents still capture
+ their summary the old way (Claude's stdout response trailer); only the
+ TUI path needed the explicit sentinel pivot.
+
- **Claude Code TUI is now the default enabled provider in the base PortOS
config.** Fresh installs get `activeProvider: "claude-code-tui"` with
`claude-code-tui.enabled: true` out of the seed JSON. The headless
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index b8c6e567fa..4dbe9ba2f0 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -233,7 +233,22 @@ You are running inside the Claude Code TUI, which has the project's slashdo comm
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 the completion sentinel so PortOS knows you finished: \`echo "done" > "${worktreeInfo?.worktreePath || workspaceDir}/.agent-done"\` (PortOS polls for this file; without it the agent will sit idle until the 3-minute fallback timer fires).
+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:
+
+ \`\`\`bash
+ cat > "${worktreeInfo?.worktreePath || workspaceDir}/.agent-done" <<'EOF'
+ ## Summary
+ <one-sentence statement of what was accomplished>
+
+ ## Changes
+ - <key file or area>: <what changed and why>
+ - <…>
+
+ ${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.
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index ba70239eba..e734f4b565 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -417,9 +417,13 @@ export async function spawnTuiAgent(agentId, task, prompt, workspacePath, model,
}, 5000);
// Sentinel-file watcher. The agent's prompt instructs it to write
- // .agent-done in the workspace after running /simplify + /do:pr; that's
- // the primary completion signal (idle-complete is just the fallback for
- // an agent that didn't comply).
+ // .agent-done in the workspace after running /simplify + /do:pr; the file
+ // contains a markdown task summary that we ingest line-by-line into the
+ // agent's outputBuffer so downstream code (extractFinalSummary,
+ // persistSimplifySummaries, completion hooks, the agent card) gets the
+ // same `outputBuffer.tail = summary` shape it used to get from headless
+ // CLI runs. Idle-complete is just the fallback for an agent that didn't
+ // comply.
const doneSentinelPath = workspacePath ? join(workspacePath, DONE_SENTINEL_NAME) : null;
const doneSentinelTimer = doneSentinelPath ? setInterval(() => {
if (finalized) return;
@@ -428,7 +432,13 @@ export async function spawnTuiAgent(agentId, task, prompt, workspacePath, model,
readFile(doneSentinelPath, 'utf8')
.then(contents => {
const trimmed = contents.trim();
- if (trimmed) appendLine(`✅ Agent signaled completion: ${trimmed.slice(0, 200)}`);
+ if (!trimmed) return;
+ appendLine(`✅ Agent signaled completion`);
+ // Cap at 4 KB so a runaway agent that pasted the entire diff into
+ // the sentinel doesn't blow up the agent record / downstream
+ // memory-extraction prompts.
+ const truncated = trimmed.length > 4096 ? `${trimmed.slice(0, 4096)}\n…[truncated]` : trimmed;
+ for (const line of truncated.split('\n')) appendLine(line);
})
.catch(() => {})
.finally(() => {