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

fix(cos): drop interim narration from PR body via stream-parser change

Adam Eivy0aeaf1de40b5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 230c91180b..ce2fd636b9 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -12,6 +12,7 @@
## Fixed
- **CoS on-demand task triggers no longer silently drop when the master Improve toggle is off.** Triggering a scheduled task (e.g. `feature-ideas` for `critical-mass`) showed a "queued" toast but nothing ever ran — the only log was `On-demand task requested: <type>`. Root cause: `dequeueNextTask`/`evaluateTasks` cleared the request and `continue`d without logging when `state.config.improvementEnabled` was `false`, and `triggerOnDemandTask` only validated the per-task-type `enabled` flag, so the request was accepted then quietly dropped downstream. Fix: (1) `triggerOnDemandTask` now checks the master flag and rejects with `Improvement is disabled — enable it in CoS → Config to run on-demand tasks`; the trigger route propagates that as HTTP 409 so the user sees a real error toast. (2) The two silent-drop branches now `emitLog('warn', …)` so any path that bypasses the trigger guard is still visible. (3) `getScheduleStatus` now returns `improvementEnabled` so the Schedule tab can render a banner ("Improvement is disabled — enable it in CoS → Config") and disable every Run Now / Run on App button (with an explanatory tooltip) instead of letting users queue requests that won't run. (4) Extracted `isImprovementEnabled(state)` in `cosState.js` to replace the same nullish-coalesce expression duplicated 6× across `cos.js` and `taskSchedule.js`. Files: `server/services/cosState.js`, `server/services/taskSchedule.js`, `server/services/cos.js`, `server/routes/cosScheduleRoutes.js`, `server/routes/cosScheduleRoutes.test.js`, `client/src/components/cos/tabs/ScheduleTab.jsx`.
+- **CoS agent PRs no longer dump the entire thought-process narration into the PR body.** PR [#172](https://github.com/atomantic/PortOS/pull/172) is the canonical example: instead of just the agent's `## Summary` block, the PR description prepended every interim "Now I have all the info…" / "Now let me run the relevant tests…" / "Branch pushed successfully. Task complete." line. Root cause was in `createStreamJsonParser` in `server/services/agentCliSpawning.js` (and the mirrored copy in `server/cos-runner/index.js`): the parser called `commitSection()` on every `content_block_start` for a `tool_use`, which pushed the text accumulated *between* tool calls into `textSections`. A multi-tool task ended up with one section per pre-tool narration plus the final summary; `getFinalResult()` joined them all with `\n\n` (the multi-section path is intentional — it's how `task summary + /simplify summary` are preserved across turns) and that joined blob replaced `outputBuffer`, stripping all `🔧`/`→`/`↳` markers from `output.txt`. Downstream `git.extractAgentSummary()` then had no markers to anchor on and emitted everything verbatim. Fix: at tool-start, *discard* `currentTextSection` instead of committing it — interim narration leading up to a tool call is superseded by whatever the agent says after the tool returns, so only the post-last-tool wrap-up survives into `textSections`. Result events still commit (preserves task-then-/simplify two-result-event scenarios). 3 new regression tests in `server/services/agentCliSpawning.test.js` (new) cover the multi-tool single-turn case, the multi-result task+/simplify case, and the single-result baseline; full server suite green at 2778/2778. Files: `server/services/agentCliSpawning.js`, `server/cos-runner/index.js`, `server/services/agentCliSpawning.test.js` (new).
- **Sidebar nav labels truncate instead of pushing the container wider.** Long nav labels (e.g. third-party app names) could force the sidebar's flex container to overflow horizontally on narrower viewports, distorting the rest of the layout. Added `min-w-0` to every flex parent in the nav row tree and `truncate` to the label `<span>` elements (top-level links, section buttons, and child links), plus `shrink-0` on the child icon so it can't be squeezed out, and `overflow-x-hidden min-w-0` on the `<nav>` itself so the scroll axis stays vertical. File: `client/src/components/Layout.jsx`.
- **CoS agent PRs now actually open.** Every recent CoS-agent automation that finished its work and pushed its branch was failing at the PR-creation step with `Failed to create PR for <branch>: spawn is not defined`, then triggering `[Recovery] Investigate and retry failed PR for branch …` recovery tasks for the orchestrator to clean up. Root cause: a refactor (commit `17311282`) extracted `execGit` to `server/lib/execGit.js` and dropped the `import { spawn } from 'child_process'` line from `server/services/git.js` — but `createPR()` still calls `spawn('gh', …)` directly, so every PR creation hit a `ReferenceError`. The existing `cleanupAgentWorktree` test suite mocked `git.createPR` so the bug never surfaced in CI. Restored the import and added `server/services/git.test.js` with a regression test that calls the real `createPR` against a non-existent path: success path returns `{ success: false, error: '<gh failure>' }` instead of throwing. The recovery flow continues to work as a safety net, but agents will now hit the happy path and open the PR directly. Files: `server/services/git.js`, `server/services/git.test.js` (new).
diff --git a/server/cos-runner/index.js b/server/cos-runner/index.js
index d06b41a7c9..7f06fd8040 100644
--- a/server/cos-runner/index.js
+++ b/server/cos-runner/index.js
@@ -112,7 +112,8 @@ function createStreamJsonParser() {
let currentTextSection = '';
const activeTools = new Map();
- // Flush accumulated text into a section boundary (tool call start, result event, or stream end)
+ // Commit accumulated text as a section (called at result events and stream end).
+ // The committed section represents an agent turn's final wrap-up.
const commitSection = () => {
const section = currentTextSection.trim();
if (section) {
@@ -121,6 +122,11 @@ function createStreamJsonParser() {
}
};
+ // At a tool-call boundary the accumulated text is interim narration ("Now let me…")
+ // that gets superseded by whatever the agent says after the tool returns. Discard it
+ // so only the final post-last-tool wrap-up survives into textSections.
+ const discardSection = () => { currentTextSection = ''; };
+
const processChunk = (rawData) => {
const lines = [];
lineBuffer += rawData;
@@ -161,7 +167,7 @@ function createStreamJsonParser() {
const idx = event.index;
activeTools.set(idx, { name: toolName, inputJson: '' });
lines.push(`🔧 Using ${toolName}...`);
- commitSection();
+ discardSection();
}
// Emit detailed summary when tool input is complete
if (event?.type === 'content_block_stop') {
diff --git a/server/services/agentCliSpawning.js b/server/services/agentCliSpawning.js
index 2ee5b7e081..0d5ece40ab 100644
--- a/server/services/agentCliSpawning.js
+++ b/server/services/agentCliSpawning.js
@@ -92,7 +92,8 @@ export function createStreamJsonParser() {
// Track active tool blocks by index for input accumulation
const activeTools = new Map(); // index -> { name, inputJson }
- // Flush accumulated text into a section boundary (tool call start, result event, or stream end)
+ // Commit accumulated text as a section (called at result events and stream end).
+ // The committed section represents an agent turn's final wrap-up.
const commitSection = () => {
const section = currentTextSection.trim();
if (section) {
@@ -101,6 +102,11 @@ export function createStreamJsonParser() {
}
};
+ // At a tool-call boundary the accumulated text is interim narration ("Now let me…")
+ // that gets superseded by whatever the agent says after the tool returns. Discard it
+ // so only the final post-last-tool wrap-up survives into textSections.
+ const discardSection = () => { currentTextSection = ''; };
+
const processChunk = (rawData) => {
const lines = [];
lineBuffer += rawData;
@@ -147,7 +153,7 @@ export function createStreamJsonParser() {
const idx = event.index;
activeTools.set(idx, { name: toolName, inputJson: '' });
lines.push(`🔧 Using ${toolName}...`);
- commitSection();
+ discardSection();
}
// When tool input is complete, emit a detailed summary line
if (event?.type === 'content_block_stop') {
diff --git a/server/services/agentCliSpawning.test.js b/server/services/agentCliSpawning.test.js
new file mode 100644
index 0000000000..d2d0694155
--- /dev/null
+++ b/server/services/agentCliSpawning.test.js
@@ -0,0 +1,87 @@
+import { describe, it, expect } from 'vitest';
+import { createStreamJsonParser } from './agentCliSpawning.js';
+
+// Helper: feed the parser a sequence of stream-json lines
+function runStream(parser, events) {
+ for (const ev of events) {
+ parser.processChunk(JSON.stringify(ev) + '\n');
+ }
+ parser.flush();
+}
+
+const textDelta = (text) => ({
+ type: 'stream_event',
+ event: { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text } }
+});
+
+const toolStart = (index, name) => ({
+ type: 'stream_event',
+ event: { type: 'content_block_start', index, content_block: { type: 'tool_use', name } }
+});
+
+const toolStop = (index) => ({
+ type: 'stream_event',
+ event: { type: 'content_block_stop', index }
+});
+
+const resultEvent = (result) => ({ type: 'result', result });
+
+describe('createStreamJsonParser.getFinalResult', () => {
+ it('returns only the final wrap-up — interim narrations between tool calls are discarded', () => {
+ const parser = createStreamJsonParser();
+ runStream(parser, [
+ textDelta('Now I have all the info I need. Let me make the changes:\n'),
+ toolStart(1, 'Read'),
+ toolStop(1),
+ textDelta('Now let me run the relevant tests to verify nothing broke:\n'),
+ toolStart(2, 'Bash'),
+ toolStop(2),
+ textDelta('Changes look clean. Now let me update the changelog and commit:\n'),
+ toolStart(3, 'Edit'),
+ toolStop(3),
+ textDelta('## Summary\n\nAdded a `/do:replan` button to the Agent Operations section.'),
+ resultEvent('## Summary\n\nAdded a `/do:replan` button to the Agent Operations section.')
+ ]);
+
+ const finalResult = parser.getFinalResult();
+ expect(finalResult).toContain('## Summary');
+ expect(finalResult).toContain('Added a `/do:replan` button');
+ expect(finalResult).not.toContain('Now I have all the info');
+ expect(finalResult).not.toContain('Now let me run the relevant tests');
+ expect(finalResult).not.toContain('Changes look clean');
+ });
+
+ it('preserves both summaries across multiple result events (e.g., task + /simplify)', () => {
+ const parser = createStreamJsonParser();
+ runStream(parser, [
+ textDelta('Investigating the bug.\n'),
+ toolStart(1, 'Read'),
+ toolStop(1),
+ textDelta('Task summary: fixed the bug.'),
+ resultEvent('Task summary: fixed the bug.'),
+ textDelta('Now running /simplify.\n'),
+ toolStart(2, 'Read'),
+ toolStop(2),
+ textDelta('Simplify summary: code is clean.'),
+ resultEvent('Simplify summary: code is clean.')
+ ]);
+
+ const finalResult = parser.getFinalResult();
+ expect(finalResult).toContain('Task summary: fixed the bug.');
+ expect(finalResult).toContain('Simplify summary: code is clean.');
+ expect(finalResult).not.toContain('Investigating the bug');
+ expect(finalResult).not.toContain('Now running /simplify');
+ });
+
+ it('returns the CLI result field for a single-turn task with no interim narration', () => {
+ const parser = createStreamJsonParser();
+ runStream(parser, [
+ toolStart(1, 'Read'),
+ toolStop(1),
+ textDelta('Done. All tests pass.'),
+ resultEvent('Done. All tests pass.')
+ ]);
+
+ expect(parser.getFinalResult()).toBe('Done. All tests pass.');
+ });
+});