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(agent): preserve task summary when simplify step runs

Adam Eivy0108f4b48ecd
diff --git a/server/cos-runner/index.js b/server/cos-runner/index.js
index 9335ce5ac9..863517447d 100644
--- a/server/cos-runner/index.js
+++ b/server/cos-runner/index.js
@@ -104,8 +104,21 @@ function createStreamJsonParser() {
let lineBuffer = '';
let finalResult = '';
let textBuffer = '';
+ // Track text across all conversation turns so multi-step agents (e.g., task + /simplify)
+ // preserve all summaries instead of only the final one
+ const textSections = [];
+ let currentTextSection = '';
const activeTools = new Map();
+ // Flush accumulated text into a section boundary (tool call start, result event, or stream end)
+ const commitSection = () => {
+ const section = currentTextSection.trim();
+ if (section) {
+ textSections.push(section);
+ currentTextSection = '';
+ }
+ };
+
const processChunk = (rawData) => {
const lines = [];
lineBuffer += rawData;
@@ -126,6 +139,7 @@ function createStreamJsonParser() {
if (event?.type === 'content_block_delta' && event.delta?.type === 'text_delta') {
const text = event.delta.text;
textBuffer += text;
+ currentTextSection += text;
const textLines = textBuffer.split('\n');
textBuffer = textLines.pop() || '';
for (const tl of textLines) {
@@ -145,6 +159,7 @@ function createStreamJsonParser() {
const idx = event.index;
activeTools.set(idx, { name: toolName, inputJson: '' });
lines.push(`🔧 Using ${toolName}...`);
+ commitSection();
}
// Emit detailed summary when tool input is complete
if (event?.type === 'content_block_stop') {
@@ -184,6 +199,7 @@ function createStreamJsonParser() {
lines.push(textBuffer);
textBuffer = '';
}
+ commitSection();
finalResult = parsed.result || '';
}
}
@@ -197,10 +213,18 @@ function createStreamJsonParser() {
lines.push(textBuffer);
textBuffer = '';
}
+ commitSection();
return lines;
};
- const getFinalResult = () => finalResult;
+ // Multi-section: return all text turns combined (e.g., task summary + simplify summary)
+ // Single-section: return the CLI result field (cleaner, no tool call noise)
+ const getFinalResult = () => {
+ if (textSections.length > 1) {
+ return textSections.join('\n\n');
+ }
+ return finalResult;
+ };
return { processChunk, flush, getFinalResult };
}
diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.js
index 18023a2667..560b911601 100644
--- a/server/services/subAgentSpawner.js
+++ b/server/services/subAgentSpawner.js
@@ -2256,9 +2256,22 @@ function createStreamJsonParser() {
let lineBuffer = '';
let finalResult = '';
let textBuffer = '';
+ // Track text across all conversation turns so multi-step agents (e.g., task + /simplify)
+ // preserve all summaries instead of only the final one
+ const textSections = [];
+ let currentTextSection = '';
// 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)
+ const commitSection = () => {
+ const section = currentTextSection.trim();
+ if (section) {
+ textSections.push(section);
+ currentTextSection = '';
+ }
+ };
+
const processChunk = (rawData) => {
const lines = [];
lineBuffer += rawData;
@@ -2284,6 +2297,7 @@ function createStreamJsonParser() {
if (event?.type === 'content_block_delta' && event.delta?.type === 'text_delta') {
const text = event.delta.text;
textBuffer += text;
+ currentTextSection += text;
// Emit complete lines for readability, accumulate partial
const textLines = textBuffer.split('\n');
textBuffer = textLines.pop() || '';
@@ -2305,6 +2319,7 @@ function createStreamJsonParser() {
const idx = event.index;
activeTools.set(idx, { name: toolName, inputJson: '' });
lines.push(`🔧 Using ${toolName}...`);
+ commitSection();
}
// When tool input is complete, emit a detailed summary line
if (event?.type === 'content_block_stop') {
@@ -2331,7 +2346,6 @@ function createStreamJsonParser() {
if (Array.isArray(content)) {
for (const block of content) {
if (block.type === 'tool_result' && typeof block.content === 'string') {
- // Summarize tool results (first line only to avoid noise)
const firstLine = block.content.split('\n')[0]?.substring(0, 200);
if (firstLine) {
lines.push(` ↳ ${firstLine}`);
@@ -2343,11 +2357,11 @@ function createStreamJsonParser() {
// Capture final result text for output file
if (parsed.type === 'result') {
- // Flush any remaining text buffer
if (textBuffer) {
lines.push(textBuffer);
textBuffer = '';
}
+ commitSection();
finalResult = parsed.result || '';
}
}
@@ -2361,10 +2375,18 @@ function createStreamJsonParser() {
lines.push(textBuffer);
textBuffer = '';
}
+ commitSection();
return lines;
};
- const getFinalResult = () => finalResult;
+ // Multi-section: return all text turns combined (e.g., task summary + simplify summary)
+ // Single-section: return the CLI result field (cleaner, no tool call noise)
+ const getFinalResult = () => {
+ if (textSections.length > 1) {
+ return textSections.join('\n\n');
+ }
+ return finalResult;
+ };
return { processChunk, flush, getFinalResult };
}