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 { resetProcessRegistryForTests } from "./bash-process-registry.js";
import {
bashTool,
createBashTool,
createProcessTool,
processTool,
} from "./bash-tools.js";
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -97,7 +97,7 @@ describe("bash tool backgrounding", () => {
const customProcess = createProcessTool();
const result = await customBash.execute("call1", {
command: "node -e \"setInterval(() => {}, 1000)\"",
command: 'node -e "setInterval(() => {}, 1000)"',
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 { StringEnum } from "@mariozechner/pi-ai";
import { Type } from "@sinclair/typebox";
import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import {
addSession,
@@ -17,7 +17,11 @@ import {
markExited,
setJobTtlMs,
} 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 DEFAULT_MAX_OUTPUT = clampNumber(
@@ -97,7 +101,7 @@ export function createBashTool(
description:
"Execute bash with background continuation. Use yieldMs/background to continue later via process tool.",
parameters: bashSchema,
execute: async (toolCallId, args, signal, onUpdate) => {
execute: async (_toolCallId, args, signal, onUpdate) => {
const params = args as {
command: string;
workdir?: string;
@@ -179,7 +183,9 @@ export function createBashTool(
};
if (signal?.aborted) onAbort();
else if (signal) signal.addEventListener("abort", onAbort, { once: true });
else if (signal) {
signal.addEventListener("abort", onAbort, { once: true });
}
const effectiveTimeout =
typeof params.timeout === "number" ? params.timeout : defaultTimeoutSec;
@@ -287,7 +293,9 @@ export function createBashTool(
: code === null
? "Command aborted before exit code was captured"
: `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)));
return;
}
@@ -552,7 +560,8 @@ export function createProcessTool(
params.offset,
params.limit,
);
const status = finished.status === "completed" ? "completed" : "failed";
const status =
finished.status === "completed" ? "completed" : "failed";
return {
content: [
{ type: "text", text: slice || "(no output recorded)" },
@@ -572,7 +581,10 @@ export function createProcessTool(
}
return {
content: [
{ type: "text", text: `No session found for ${params.sessionId}` },
{
type: "text",
text: `No session found for ${params.sessionId}`,
},
],
details: { status: "failed" },
};
@@ -582,7 +594,10 @@ export function createProcessTool(
if (!session) {
return {
content: [
{ type: "text", text: `No active session found for ${params.sessionId}` },
{
type: "text",
text: `No active session found for ${params.sessionId}`,
},
],
details: { status: "failed" },
};
@@ -639,7 +654,10 @@ export function createProcessTool(
if (!session) {
return {
content: [
{ type: "text", text: `No active session found for ${params.sessionId}` },
{
type: "text",
text: `No active session found for ${params.sessionId}`,
},
],
details: { status: "failed" },
};
@@ -718,7 +736,10 @@ export function createProcessTool(
}
return {
content: [
{ type: "text", text: `No session found for ${params.sessionId}` },
{
type: "text",
text: `No session found for ${params.sessionId}`,
},
],
details: { status: "failed" },
};
@@ -816,7 +837,7 @@ function tokenizeCommand(command: string): string[] {
function stripQuotes(value: string): string {
const trimmed = value.trim();
if (
(trimmed.startsWith("\"") && trimmed.endsWith("\"")) ||
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
(trimmed.startsWith("'") && trimmed.endsWith("'"))
) {
return trimmed.slice(1, -1);