style: fix bash tools lint

This commit is contained in:
Peter Steinberger
2025-12-25 20:20:38 +00:00
parent c860573f13
commit 474180c112
2 changed files with 164 additions and 143 deletions

View File

@@ -1,11 +1,11 @@
import { beforeEach, describe, expect, it } from "vitest"; import { beforeEach, describe, expect, it } from "vitest";
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
import { import {
bashTool, bashTool,
createBashTool, createBashTool,
createProcessTool, createProcessTool,
processTool, processTool,
} from "./bash-tools.js"; } from "./bash-tools.js";
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -97,7 +97,7 @@ describe("bash tool backgrounding", () => {
const customProcess = createProcessTool(); const customProcess = createProcessTool();
const result = await customBash.execute("call1", { const result = await customBash.execute("call1", {
command: "node -e \"setInterval(() => {}, 1000)\"", command: 'node -e "setInterval(() => {}, 1000)"',
background: true, background: true,
}); });

View File

@@ -1,8 +1,8 @@
import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-ai"; import type { AgentTool, AgentToolResult } from "@mariozechner/pi-ai";
import { StringEnum } from "@mariozechner/pi-ai"; import { StringEnum } from "@mariozechner/pi-ai";
import { Type } from "@sinclair/typebox"; import { Type } from "@sinclair/typebox";
import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { import {
addSession, addSession,
@@ -17,7 +17,11 @@ import {
markExited, markExited,
setJobTtlMs, setJobTtlMs,
} from "./bash-process-registry.js"; } from "./bash-process-registry.js";
import { getShellConfig, killProcessTree, sanitizeBinaryOutput } from "./shell-utils.js"; import {
getShellConfig,
killProcessTree,
sanitizeBinaryOutput,
} from "./shell-utils.js";
const CHUNK_LIMIT = 8 * 1024; const CHUNK_LIMIT = 8 * 1024;
const DEFAULT_MAX_OUTPUT = clampNumber( const DEFAULT_MAX_OUTPUT = clampNumber(
@@ -97,7 +101,7 @@ export function createBashTool(
description: description:
"Execute bash with background continuation. Use yieldMs/background to continue later via process tool.", "Execute bash with background continuation. Use yieldMs/background to continue later via process tool.",
parameters: bashSchema, parameters: bashSchema,
execute: async (toolCallId, args, signal, onUpdate) => { execute: async (_toolCallId, args, signal, onUpdate) => {
const params = args as { const params = args as {
command: string; command: string;
workdir?: string; workdir?: string;
@@ -179,7 +183,9 @@ export function createBashTool(
}; };
if (signal?.aborted) onAbort(); if (signal?.aborted) onAbort();
else if (signal) signal.addEventListener("abort", onAbort, { once: true }); else if (signal) {
signal.addEventListener("abort", onAbort, { once: true });
}
const effectiveTimeout = const effectiveTimeout =
typeof params.timeout === "number" ? params.timeout : defaultTimeoutSec; typeof params.timeout === "number" ? params.timeout : defaultTimeoutSec;
@@ -287,7 +293,9 @@ export function createBashTool(
: code === null : code === null
? "Command aborted before exit code was captured" ? "Command aborted before exit code was captured"
: `Command exited with code ${code}`; : `Command exited with code ${code}`;
const message = aggregated ? `${aggregated}\n\n${reason}` : reason; const message = aggregated
? `${aggregated}\n\n${reason}`
: reason;
settle(() => reject(new Error(message))); settle(() => reject(new Error(message)));
return; return;
} }
@@ -552,7 +560,8 @@ export function createProcessTool(
params.offset, params.offset,
params.limit, params.limit,
); );
const status = finished.status === "completed" ? "completed" : "failed"; const status =
finished.status === "completed" ? "completed" : "failed";
return { return {
content: [ content: [
{ type: "text", text: slice || "(no output recorded)" }, { type: "text", text: slice || "(no output recorded)" },
@@ -572,7 +581,10 @@ export function createProcessTool(
} }
return { return {
content: [ content: [
{ type: "text", text: `No session found for ${params.sessionId}` }, {
type: "text",
text: `No session found for ${params.sessionId}`,
},
], ],
details: { status: "failed" }, details: { status: "failed" },
}; };
@@ -582,7 +594,10 @@ export function createProcessTool(
if (!session) { if (!session) {
return { return {
content: [ content: [
{ type: "text", text: `No active session found for ${params.sessionId}` }, {
type: "text",
text: `No active session found for ${params.sessionId}`,
},
], ],
details: { status: "failed" }, details: { status: "failed" },
}; };
@@ -639,7 +654,10 @@ export function createProcessTool(
if (!session) { if (!session) {
return { return {
content: [ content: [
{ type: "text", text: `No active session found for ${params.sessionId}` }, {
type: "text",
text: `No active session found for ${params.sessionId}`,
},
], ],
details: { status: "failed" }, details: { status: "failed" },
}; };
@@ -718,7 +736,10 @@ export function createProcessTool(
} }
return { return {
content: [ content: [
{ type: "text", text: `No session found for ${params.sessionId}` }, {
type: "text",
text: `No session found for ${params.sessionId}`,
},
], ],
details: { status: "failed" }, details: { status: "failed" },
}; };
@@ -816,7 +837,7 @@ function tokenizeCommand(command: string): string[] {
function stripQuotes(value: string): string { function stripQuotes(value: string): string {
const trimmed = value.trim(); const trimmed = value.trim();
if ( if (
(trimmed.startsWith("\"") && trimmed.endsWith("\"")) || (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
(trimmed.startsWith("'") && trimmed.endsWith("'")) (trimmed.startsWith("'") && trimmed.endsWith("'"))
) { ) {
return trimmed.slice(1, -1); return trimmed.slice(1, -1);