From 975a0cfcdae9f3ef2b17faee60d16cf163b0a31b Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 31 May 2026 10:02:05 +0800 Subject: [PATCH] feat(agent): add structured error logging to sandboxed-bash tool --- src/agent/tools/sandboxed-bash.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/agent/tools/sandboxed-bash.ts b/src/agent/tools/sandboxed-bash.ts index fe4bc465..b3ac78e7 100644 --- a/src/agent/tools/sandboxed-bash.ts +++ b/src/agent/tools/sandboxed-bash.ts @@ -2,6 +2,7 @@ import { SandboxManager } from '@anthropic-ai/sandbox-runtime' import { type AgentTool, type AgentToolResult } from '@earendil-works/pi-agent-core' import { Type } from '@sinclair/typebox' import { spawn } from 'node:child_process' +import { logger } from '@/logger' const BashParameters = Type.Object({ command: Type.String({ description: 'The bash command to execute.' }), @@ -81,6 +82,7 @@ export const createSandboxedBashTool = ( child.on('error', (err) => { if (timeoutHandle) clearTimeout(timeoutHandle) signal?.removeEventListener('abort', onAbort) + logger.error({ err, command, stdout, stderr }, 'Sandboxed bash command encountered process error') reject(err) }) @@ -89,10 +91,13 @@ export const createSandboxedBashTool = ( signal?.removeEventListener('abort', onAbort) if (signal?.aborted) { + logger.error({ command, stdout, stderr }, 'Sandboxed bash command aborted') reject(new Error('aborted')) } else if (timedOut) { + logger.error({ timeout, command, stdout, stderr }, 'Sandboxed bash command timed out') reject(new Error(`bash command timed out after ${timeout} seconds`)) } else if (code !== 0 && code !== null) { + logger.error({ exitCode: code, command, stdout, stderr }, 'Sandboxed bash command exited with failure code') reject(new Error(`bash command exited with code ${code}`)) } else { const output = stdout + stderr