diff --git a/.claude/checkpoints/1755025976.json b/.claude/checkpoints/1755025976.json new file mode 100644 index 0000000000..48be718935 --- /dev/null +++ b/.claude/checkpoints/1755025976.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250812-191256", "file": "/workspaces/claude-code-flow/src/cli/simple-commands/stream-chain.js", "timestamp": "2025-08-12T19:12:56Z", "type": "pre-edit", "original_branch": "alpha-89"} diff --git a/.claude/checkpoints/1755025978.json b/.claude/checkpoints/1755025978.json new file mode 100644 index 0000000000..a26740b7c7 --- /dev/null +++ b/.claude/checkpoints/1755025978.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250812-191257", "file": "/workspaces/claude-code-flow/src/cli/simple-commands/stream-chain.js", "timestamp": "2025-08-12T19:12:58Z", "type": "post-edit", "branch": "alpha-89", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 7274 ++---------------------------- .claude-flow/metrics/task-metrics.json | 6 +- .claude/checkpoints/task-1755025932.json | 1 + claude-flow-wiki | 0 src/cli/simple-commands/stream-chain.js | 37 +- 6 files changed, 442 insertions(+), 6878 deletions(-) "} diff --git a/src/cli/simple-commands/stream-chain.js b/src/cli/simple-commands/stream-chain.js index 4b657d741d..1cdf97cbd9 100644 --- a/src/cli/simple-commands/stream-chain.js +++ b/src/cli/simple-commands/stream-chain.js @@ -68,22 +68,24 @@ async function executeRealChain(prompts, flags = {}) { } /** - * Filter stream-json to remove system messages and keep only user/assistant/result + * Transform stream-json output to create proper input for next step + * This converts the previous assistant's output into a user message for chaining */ -function filterStreamJson(rawOutput) { +function transformStreamForChaining(rawOutput, nextPrompt) { const lines = rawOutput.split('\n').filter(line => line.trim()); - const filtered = []; + const messages = []; + let assistantContent = ''; + // Extract the assistant's response from the stream for (const line of lines) { try { const json = JSON.parse(line); - // Keep only message types that --input-format accepts - if (json.type === 'message' || json.type === 'tool_use' || json.type === 'tool_result' || json.type === 'result') { - // For messages, ensure they have user or assistant role - if (json.type === 'message' && json.role !== 'system') { - filtered.push(line); - } else if (json.type !== 'message') { - filtered.push(line); + if (json.type === 'message' && json.role === 'assistant' && json.content) { + // Extract text content from assistant messages + for (const content of json.content) { + if (content.type === 'text' && content.text) { + assistantContent += content.text + '\n'; + } } } } catch (e) { @@ -91,7 +93,29 @@ function filterStreamJson(rawOutput) { } } - return filtered.join('\n'); + // Create a user message with the previous output and new prompt + if (assistantContent) { + const userMessage = { + type: 'message', + role: 'user', + content: [{ + type: 'text', + text: `Previous step output:\n${assistantContent.trim()}\n\nNext step: ${nextPrompt}` + }] + }; + return JSON.stringify(userMessage); + } + + // Fallback: just create a user message with the prompt + const fallbackMessage = { + type: 'message', + role: 'user', + content: [{ + type: 'text', + text: nextPrompt + }] + }; + return JSON.stringify(fallbackMessage); } /**