mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 12:54:55 +00:00
feat(agent): add structured error logging to sandboxed-bash tool
This commit is contained in:
@@ -2,6 +2,7 @@ import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
|
|||||||
import { type AgentTool, type AgentToolResult } from '@earendil-works/pi-agent-core'
|
import { type AgentTool, type AgentToolResult } from '@earendil-works/pi-agent-core'
|
||||||
import { Type } from '@sinclair/typebox'
|
import { Type } from '@sinclair/typebox'
|
||||||
import { spawn } from 'node:child_process'
|
import { spawn } from 'node:child_process'
|
||||||
|
import { logger } from '@/logger'
|
||||||
|
|
||||||
const BashParameters = Type.Object({
|
const BashParameters = Type.Object({
|
||||||
command: Type.String({ description: 'The bash command to execute.' }),
|
command: Type.String({ description: 'The bash command to execute.' }),
|
||||||
@@ -81,6 +82,7 @@ export const createSandboxedBashTool = (
|
|||||||
child.on('error', (err) => {
|
child.on('error', (err) => {
|
||||||
if (timeoutHandle) clearTimeout(timeoutHandle)
|
if (timeoutHandle) clearTimeout(timeoutHandle)
|
||||||
signal?.removeEventListener('abort', onAbort)
|
signal?.removeEventListener('abort', onAbort)
|
||||||
|
logger.error({ err, command, stdout, stderr }, 'Sandboxed bash command encountered process error')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -89,10 +91,13 @@ export const createSandboxedBashTool = (
|
|||||||
signal?.removeEventListener('abort', onAbort)
|
signal?.removeEventListener('abort', onAbort)
|
||||||
|
|
||||||
if (signal?.aborted) {
|
if (signal?.aborted) {
|
||||||
|
logger.error({ command, stdout, stderr }, 'Sandboxed bash command aborted')
|
||||||
reject(new Error('aborted'))
|
reject(new Error('aborted'))
|
||||||
} else if (timedOut) {
|
} else if (timedOut) {
|
||||||
|
logger.error({ timeout, command, stdout, stderr }, 'Sandboxed bash command timed out')
|
||||||
reject(new Error(`bash command timed out after ${timeout} seconds`))
|
reject(new Error(`bash command timed out after ${timeout} seconds`))
|
||||||
} else if (code !== 0 && code !== null) {
|
} 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}`))
|
reject(new Error(`bash command exited with code ${code}`))
|
||||||
} else {
|
} else {
|
||||||
const output = stdout + stderr
|
const output = stdout + stderr
|
||||||
|
|||||||
Reference in New Issue
Block a user