diff --git a/src/agents/pi.ts b/src/agents/pi.ts index 4b35965da..195315ffc 100644 --- a/src/agents/pi.ts +++ b/src/agents/pi.ts @@ -23,17 +23,12 @@ type PiAssistantMessage = { }; function inferToolName(msg: PiAssistantMessage): string | undefined { - const candidates = [ - msg.toolName, - msg.name, - msg.toolCallId, - msg.tool_call_id, - ] + const candidates = [msg.toolName, msg.name, msg.toolCallId, msg.tool_call_id] .map((c) => (typeof c === "string" ? c.trim() : "")) .filter(Boolean); if (candidates.length) return candidates[0]; - if (msg.role && msg.role.includes(":")) { + if (msg.role?.includes(":")) { const suffix = msg.role.split(":").slice(1).join(":").trim(); if (suffix) return suffix; } @@ -43,10 +38,16 @@ function inferToolName(msg: PiAssistantMessage): string | undefined { function deriveToolMeta(msg: PiAssistantMessage): string | undefined { const details = msg.details ?? msg.arguments; - const pathVal = details && typeof details.path === "string" ? details.path : undefined; - const offset = details && typeof details.offset === "number" ? details.offset : undefined; - const limit = details && typeof details.limit === "number" ? details.limit : undefined; - const command = details && typeof details.command === "string" ? details.command : undefined; + const pathVal = + details && typeof details.path === "string" ? details.path : undefined; + const offset = + details && typeof details.offset === "number" ? details.offset : undefined; + const limit = + details && typeof details.limit === "number" ? details.limit : undefined; + const command = + details && typeof details.command === "string" + ? details.command + : undefined; if (pathVal) { if (offset !== undefined && limit !== undefined) { diff --git a/src/auto-reply/command-reply.ts b/src/auto-reply/command-reply.ts index de3c7a3ee..d27797c51 100644 --- a/src/auto-reply/command-reply.ts +++ b/src/auto-reply/command-reply.ts @@ -13,11 +13,9 @@ import type { runCommandWithTimeout } from "../process/exec.js"; import { runPiRpc } from "../process/tau-rpc.js"; import { applyTemplate, type TemplateContext } from "./templating.js"; import { - TOOL_RESULT_DEBOUNCE_MS, - createToolDebouncer, formatToolAggregate, - formatToolPrefix, shortenMeta, + TOOL_RESULT_DEBOUNCE_MS, } from "./tool-meta.js"; import type { ReplyPayload } from "./types.js"; @@ -60,9 +58,6 @@ export type CommandReplyResult = { meta: CommandReplyMeta; }; -// Debounce window for coalescing successive tool_result messages (ms) -const TOOL_RESULT_DEBOUNCE_MS = 1000; - type ToolMessageLike = { name?: string; toolName?: string; @@ -85,7 +80,7 @@ function inferToolName(message?: ToolMessageLike): string | undefined { .filter(Boolean); if (candidates.length) return candidates[0]; - if (message.role && message.role.includes(":")) { + if (message.role?.includes(":")) { const suffix = message.role.split(":").slice(1).join(":").trim(); if (suffix) return suffix; } @@ -95,10 +90,16 @@ function inferToolName(message?: ToolMessageLike): string | undefined { function inferToolMeta(message?: ToolMessageLike): string | undefined { if (!message) return undefined; const details = message.details ?? message.arguments; - const pathVal = details && typeof details.path === "string" ? details.path : undefined; - const offset = details && typeof details.offset === "number" ? details.offset : undefined; - const limit = details && typeof details.limit === "number" ? details.limit : undefined; - const command = details && typeof details.command === "string" ? details.command : undefined; + const pathVal = + details && typeof details.path === "string" ? details.path : undefined; + const offset = + details && typeof details.offset === "number" ? details.offset : undefined; + const limit = + details && typeof details.limit === "number" ? details.limit : undefined; + const command = + details && typeof details.command === "string" + ? details.command + : undefined; const formatPath = shortenPath; diff --git a/src/auto-reply/tool-meta.ts b/src/auto-reply/tool-meta.ts index 7f6b4f525..d1e6e29e7 100644 --- a/src/auto-reply/tool-meta.ts +++ b/src/auto-reply/tool-meta.ts @@ -2,7 +2,8 @@ export const TOOL_RESULT_DEBOUNCE_MS = 1000; function shortenPath(p: string): string { const home = process.env.HOME; - if (home && (p === home || p.startsWith(`${home}/`))) return p.replace(home, "~"); + if (home && (p === home || p.startsWith(`${home}/`))) + return p.replace(home, "~"); return p; } @@ -31,9 +32,11 @@ export function formatToolAggregate( if (parts.length > 1) { const dir = parts.slice(0, -1).join("/"); const base = parts.at(-1) ?? m; - (grouped[dir] ||= []).push(base); + if (!grouped[dir]) grouped[dir] = []; + grouped[dir].push(base); } else { - (grouped["."] ||= []).push(m); + if (!grouped["."]) grouped["."] = []; + grouped["."].push(m); } }