Chore: satisfy lint after tool-meta refactor

main
Peter Steinberger 2025-12-03 10:42:10 +00:00
parent 597e7e6f13
commit e34d0d69aa
3 changed files with 30 additions and 25 deletions

View File

@ -23,17 +23,12 @@ type PiAssistantMessage = {
}; };
function inferToolName(msg: PiAssistantMessage): string | undefined { function inferToolName(msg: PiAssistantMessage): string | undefined {
const candidates = [ const candidates = [msg.toolName, msg.name, msg.toolCallId, msg.tool_call_id]
msg.toolName,
msg.name,
msg.toolCallId,
msg.tool_call_id,
]
.map((c) => (typeof c === "string" ? c.trim() : "")) .map((c) => (typeof c === "string" ? c.trim() : ""))
.filter(Boolean); .filter(Boolean);
if (candidates.length) return candidates[0]; 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(); const suffix = msg.role.split(":").slice(1).join(":").trim();
if (suffix) return suffix; if (suffix) return suffix;
} }
@ -43,10 +38,16 @@ function inferToolName(msg: PiAssistantMessage): string | undefined {
function deriveToolMeta(msg: PiAssistantMessage): string | undefined { function deriveToolMeta(msg: PiAssistantMessage): string | undefined {
const details = msg.details ?? msg.arguments; const details = msg.details ?? msg.arguments;
const pathVal = details && typeof details.path === "string" ? details.path : undefined; const pathVal =
const offset = details && typeof details.offset === "number" ? details.offset : undefined; details && typeof details.path === "string" ? details.path : undefined;
const limit = details && typeof details.limit === "number" ? details.limit : undefined; const offset =
const command = details && typeof details.command === "string" ? details.command : undefined; 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 (pathVal) {
if (offset !== undefined && limit !== undefined) { if (offset !== undefined && limit !== undefined) {

View File

@ -13,11 +13,9 @@ import type { runCommandWithTimeout } from "../process/exec.js";
import { runPiRpc } from "../process/tau-rpc.js"; import { runPiRpc } from "../process/tau-rpc.js";
import { applyTemplate, type TemplateContext } from "./templating.js"; import { applyTemplate, type TemplateContext } from "./templating.js";
import { import {
TOOL_RESULT_DEBOUNCE_MS,
createToolDebouncer,
formatToolAggregate, formatToolAggregate,
formatToolPrefix,
shortenMeta, shortenMeta,
TOOL_RESULT_DEBOUNCE_MS,
} from "./tool-meta.js"; } from "./tool-meta.js";
import type { ReplyPayload } from "./types.js"; import type { ReplyPayload } from "./types.js";
@ -60,9 +58,6 @@ export type CommandReplyResult = {
meta: CommandReplyMeta; meta: CommandReplyMeta;
}; };
// Debounce window for coalescing successive tool_result messages (ms)
const TOOL_RESULT_DEBOUNCE_MS = 1000;
type ToolMessageLike = { type ToolMessageLike = {
name?: string; name?: string;
toolName?: string; toolName?: string;
@ -85,7 +80,7 @@ function inferToolName(message?: ToolMessageLike): string | undefined {
.filter(Boolean); .filter(Boolean);
if (candidates.length) return candidates[0]; 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(); const suffix = message.role.split(":").slice(1).join(":").trim();
if (suffix) return suffix; if (suffix) return suffix;
} }
@ -95,10 +90,16 @@ function inferToolName(message?: ToolMessageLike): string | undefined {
function inferToolMeta(message?: ToolMessageLike): string | undefined { function inferToolMeta(message?: ToolMessageLike): string | undefined {
if (!message) return undefined; if (!message) return undefined;
const details = message.details ?? message.arguments; const details = message.details ?? message.arguments;
const pathVal = details && typeof details.path === "string" ? details.path : undefined; const pathVal =
const offset = details && typeof details.offset === "number" ? details.offset : undefined; details && typeof details.path === "string" ? details.path : undefined;
const limit = details && typeof details.limit === "number" ? details.limit : undefined; const offset =
const command = details && typeof details.command === "string" ? details.command : undefined; 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; const formatPath = shortenPath;

View File

@ -2,7 +2,8 @@ export const TOOL_RESULT_DEBOUNCE_MS = 1000;
function shortenPath(p: string): string { function shortenPath(p: string): string {
const home = process.env.HOME; 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; return p;
} }
@ -31,9 +32,11 @@ export function formatToolAggregate(
if (parts.length > 1) { if (parts.length > 1) {
const dir = parts.slice(0, -1).join("/"); const dir = parts.slice(0, -1).join("/");
const base = parts.at(-1) ?? m; const base = parts.at(-1) ?? m;
(grouped[dir] ||= []).push(base); if (!grouped[dir]) grouped[dir] = [];
grouped[dir].push(base);
} else { } else {
(grouped["."] ||= []).push(m); if (!grouped["."]) grouped["."] = [];
grouped["."].push(m);
} }
} }