Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/services/auto-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function getAIResponseMessages(messages: any[], promptMessageId: string): any[]
return responseMessages;
}

function extractAIContent(messages: any[]): {
export function extractAIContent(messages: any[]): {
textResponses: string[];
toolCalls: ToolCallInfo[];
} {
Expand All @@ -293,7 +293,7 @@ function extractAIContent(messages: any[]): {

const toolParts = msg.parts.filter((p: any) => p.type === "tool");
for (const tool of toolParts) {
const name = tool.tool || "unknown";
const name = tool.name || tool.tool || "unknown";
let input = "";

if (tool.state?.input) {
Expand Down
52 changes: 52 additions & 0 deletions tests/auto-capture-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test";
import {
buildBoundedSummaryPrompt,
buildMarkdownContext,
extractAIContent,
getAutoCaptureMarkdownBudget,
} from "../src/services/auto-capture.js";
import { utf8ByteLength } from "../src/utils/context-limit.js";
Expand Down Expand Up @@ -96,3 +97,54 @@ describe("buildMarkdownContext budgeting (#232)", () => {
expect(userPrompt).toContain("truncated to autoCaptureMaxContextBytes");
});
});

describe("extractAIContent tool calls", () => {
it("extracts tool names from v2-shaped parts", () => {
const { toolCalls } = extractAIContent([
{
info: { role: "assistant" },
parts: [
{
type: "tool",
id: "t1",
name: "bash",
state: { status: "completed", input: { command: "ls" } },
},
],
},
]);

expect(toolCalls).toHaveLength(1);
expect(toolCalls[0]?.name).toBe("bash");
expect(toolCalls[0]?.input).toContain('command: "ls"');
});

it("keeps extracting tool names from v1-shaped parts", () => {
const { toolCalls } = extractAIContent([
{
info: { role: "assistant" },
parts: [
{
type: "tool",
callID: "call_1",
tool: "read",
state: { input: { path: "/tmp/x" } },
},
],
},
]);

expect(toolCalls[0]?.name).toBe("read");
});

it("falls back to unknown when a tool part has no name", () => {
const { toolCalls } = extractAIContent([
{
info: { role: "assistant" },
parts: [{ type: "tool", state: { input: {} } }],
},
]);

expect(toolCalls[0]?.name).toBe("unknown");
});
});
Loading