Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: pipe history shows tool calls instead of empty bubbles

Louis Beaumontce59063b095b
diff --git a/apps/screenpipe-app-tauri/components/__tests__/pipe-ndjson-to-chat.test.ts b/apps/screenpipe-app-tauri/components/__tests__/pipe-ndjson-to-chat.test.ts
index d2ce69185..b6117efdf 100644
--- a/apps/screenpipe-app-tauri/components/__tests__/pipe-ndjson-to-chat.test.ts
+++ b/apps/screenpipe-app-tauri/components/__tests__/pipe-ndjson-to-chat.test.ts
@@ -81,18 +81,18 @@ describe("parsePipeNdjsonToMessages", () => {
const assistant = msgs[1];
expect(assistant.role).toBe("assistant");
expect(assistant.contentBlocks).toBeDefined();
- // Should have: text block + tool_use block
+ // Should have: text block + tool block
const textBlock = assistant.contentBlocks!.find(
(b: any) => b.type === "text"
);
const toolBlock = assistant.contentBlocks!.find(
- (b: any) => b.type === "tool_use"
+ (b: any) => b.type === "tool"
);
expect(textBlock).toBeDefined();
expect(textBlock.text).toBe("Let me search.");
expect(toolBlock).toBeDefined();
- expect(toolBlock.name).toBe("bash");
- expect(toolBlock.input).toContain("curl");
+ expect(toolBlock.toolCall.toolName).toBe("bash");
+ expect(JSON.stringify(toolBlock.toolCall.args)).toContain("curl");
});
// ─── tool results ─────────────────────────────────────────────────
@@ -110,14 +110,14 @@ describe("parsePipeNdjsonToMessages", () => {
const msgs = parsePipeNdjsonToMessages(stdout);
expect(msgs.length).toBeGreaterThanOrEqual(1);
- // The assistant message should have tool_result in contentBlocks
+ // The assistant message should have tool block with result attached
const assistant = msgs.find((m) => m.role === "assistant");
expect(assistant).toBeDefined();
- const resultBlock = assistant!.contentBlocks?.find(
- (b: any) => b.type === "tool_result"
+ const toolBlock = assistant!.contentBlocks?.find(
+ (b: any) => b.type === "tool" && b.toolCall?.result
);
- expect(resultBlock).toBeDefined();
- expect(resultBlock.content).toContain("file1.txt");
+ expect(toolBlock).toBeDefined();
+ expect(toolBlock.toolCall.result).toContain("file1.txt");
});
it("truncates large tool results to 2000 chars", () => {
@@ -125,18 +125,20 @@ describe("parsePipeNdjsonToMessages", () => {
const stdout = [
'{"type":"message_start","message":{"role":"assistant","content":[]}}',
'{"type":"message_update","assistantMessageEvent":{"type":"text_delta","contentIndex":0,"delta":"Working.","partial":{}}}',
- `{"type":"tool_execution_end","toolCallId":"t1","toolName":"bash","result":{"content":[{"type":"text","text":"${bigResult}"}]},"isError":false}`,
+ '{"type":"message_update","assistantMessageEvent":{"type":"toolcall_start","contentIndex":1,"toolName":"bash","partial":{}}}',
+ '{"type":"message_update","assistantMessageEvent":{"type":"toolcall_end","contentIndex":1,"toolCall":{"type":"toolCall","id":"t1","name":"bash","arguments":{"command":"big"}},"partial":{}}}',
'{"type":"message_end","message":{"role":"assistant","content":[],"stopReason":"stop"}}',
+ `{"type":"tool_execution_end","toolCallId":"t1","toolName":"bash","result":{"content":[{"type":"text","text":"${bigResult}"}]},"isError":false}`,
].join("\n");
const msgs = parsePipeNdjsonToMessages(stdout);
const assistant = msgs.find((m) => m.role === "assistant");
- const resultBlock = assistant?.contentBlocks?.find(
- (b: any) => b.type === "tool_result"
+ const toolBlock = assistant?.contentBlocks?.find(
+ (b: any) => b.type === "tool" && b.toolCall?.result
);
- expect(resultBlock).toBeDefined();
- expect(resultBlock.content.length).toBeLessThan(2100);
- expect(resultBlock.content).toContain("... (truncated)");
+ expect(toolBlock).toBeDefined();
+ expect(toolBlock.toolCall.result.length).toBeLessThan(2100);
+ expect(toolBlock.toolCall.result).toContain("... (truncated)");
});
// ─── thinking blocks ──────────────────────────────────────────────
@@ -197,11 +199,11 @@ describe("parsePipeNdjsonToMessages", () => {
// First assistant has tool call
expect(msgs[1].role).toBe("assistant");
expect(msgs[1].contentBlocks).toBeDefined();
- const toolUse = msgs[1].contentBlocks!.find(
- (b: any) => b.type === "tool_use"
+ const toolBlock = msgs[1].contentBlocks!.find(
+ (b: any) => b.type === "tool"
);
- expect(toolUse).toBeDefined();
- expect(toolUse.name).toBe("bash");
+ expect(toolBlock).toBeDefined();
+ expect(toolBlock.toolCall.toolName).toBe("bash");
// Second assistant has final text
const lastAssistant = msgs[msgs.length - 1];
@@ -332,11 +334,11 @@ describe("parsePipeNdjsonToMessages", () => {
// Second: assistant with tool call to read SKILL.md
expect(msgs[1].role).toBe("assistant");
expect(msgs[1].contentBlocks).toBeDefined();
- const toolUse = msgs[1].contentBlocks!.find(
- (b: any) => b.type === "tool_use"
+ const toolBlock = msgs[1].contentBlocks!.find(
+ (b: any) => b.type === "tool"
);
- expect(toolUse).toBeDefined();
- expect(toolUse.name).toBe("read");
+ expect(toolBlock).toBeDefined();
+ expect(toolBlock.toolCall.toolName).toBe("read");
// Last: assistant with final verdict
const lastMsg = msgs[msgs.length - 1];
@@ -382,11 +384,13 @@ describe("parsePipeNdjsonToMessages", () => {
const firstAssistant = msgs[1];
expect(firstAssistant.role).toBe("assistant");
expect(firstAssistant.contentBlocks).toBeDefined();
- // Should have text, tool_use, and tool_result blocks
+ // Should have text and tool blocks (tool_result is attached to the tool block)
const blockTypes = firstAssistant.contentBlocks!.map((b: any) => b.type);
expect(blockTypes).toContain("text");
- expect(blockTypes).toContain("tool_use");
- expect(blockTypes).toContain("tool_result");
+ expect(blockTypes).toContain("tool");
+ // Tool result should be attached to the tool block
+ const toolBlock = firstAssistant.contentBlocks!.find((b: any) => b.type === "tool");
+ expect(toolBlock.toolCall.result).toContain("WezTerm");
const lastAssistant = msgs[msgs.length - 1];
expect(lastAssistant.role).toBe("assistant");
diff --git a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
index 835a3c611..f3de52326 100644
--- a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
+++ b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
@@ -66,12 +66,27 @@ export function parsePipeNdjsonToMessages(raw: string): ChatMessage[] {
.join("\n");
}
if (text.trim()) {
- messages.push({
+ // Detect pipe system prompts and give them a short display label
+ const isPipePrompt = text.includes("Time range:") && text.includes("Execute the pipe now.");
+ const msg: any = {
id: `pipe-msg-${messageCounter++}`,
role: "user",
content: text.trim(),
timestamp: turnTimestamp,
- });
+ };
+ if (isPipePrompt) {
+ // Extract just the time range for the label
+ const match = text.match(/Time range: (\S+) to (\S+)/);
+ if (match) {
+ const start = new Date(match[1]);
+ const end = new Date(match[2]);
+ const fmt = (d: Date) => d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" });
+ msg.displayContent = `pipe executed (${fmt(start)} – ${fmt(end)})`;
+ } else {
+ msg.displayContent = "pipe executed";
+ }
+ }
+ messages.push(msg);
}
continue;
}
@@ -105,14 +120,42 @@ export function parsePipeNdjsonToMessages(raw: string): ChatMessage[] {
currentBlocks.push({ type: "text", text: currentText.trim() });
currentText = "";
}
- currentToolCall = { name: ae.toolName || "unknown", input: "" };
+ // toolName may be on the event or inside partial.content[].name
+ let toolName = ae.toolName || "unknown";
+ if (toolName === "unknown" && ae.partial?.content) {
+ for (const c of ae.partial.content) {
+ if (c.type === "toolCall" && c.name) { toolName = c.name; break; }
+ }
+ }
+ currentToolCall = { name: toolName, input: "" };
} else if (ae.type === "toolcall_delta" && ae.delta && currentToolCall) {
currentToolCall.input += ae.delta;
- } else if (ae.type === "toolcall_end" && currentToolCall) {
+ } else if (ae.type === "toolcall_end") {
+ // Parse args: try accumulated delta input first, then fall back to partial
+ let args: Record<string, any> = {};
+ const rawInput = currentToolCall?.input || "";
+ if (rawInput) {
+ try { args = JSON.parse(rawInput); } catch { args = { raw: rawInput }; }
+ } else if (ae.partial?.content) {
+ for (const c of ae.partial.content) {
+ if (c.type === "toolCall" && c.arguments) { args = c.arguments; break; }
+ }
+ }
+ // Also grab tool name from end event if we missed it at start
+ let toolName = currentToolCall?.name || "unknown";
+ if (toolName === "unknown" && ae.partial?.content) {
+ for (const c of ae.partial.content) {
+ if (c.type === "toolCall" && c.name) { toolName = c.name; break; }
+ }
+ }
currentBlocks.push({
- type: "tool_use",
- name: currentToolCall.name,
- input: currentToolCall.input,
+ type: "tool",
+ toolCall: {
+ id: `pipe-tool-${messageCounter}-${currentBlocks.length}`,
+ toolName,
+ args,
+ isRunning: false,
+ },
});
currentToolCall = null;
}
@@ -131,12 +174,14 @@ export function parsePipeNdjsonToMessages(raw: string): ChatMessage[] {
.map((b: any) => b.text)
.join("\n");
if (resultText) {
- currentBlocks.push({
- type: "tool_result",
- content: resultText.length > 2000
- ? resultText.slice(0, 2000) + "\n... (truncated)"
- : resultText,
- });
+ const truncated = resultText.length > 2000
+ ? resultText.slice(0, 2000) + "\n... (truncated)"
+ : resultText;
+ // Attach result to the last tool block if possible
+ const lastBlock = currentBlocks[currentBlocks.length - 1];
+ if (lastBlock?.type === "tool" && lastBlock.toolCall && !lastBlock.toolCall.result) {
+ lastBlock.toolCall.result = truncated;
+ }
}
}
continue;