AIX: Anthropic: trace bash_code_execution ops

This commit is contained in:
Enrico Ros
2026-03-28 02:35:45 -07:00
parent a7495bd4cf
commit 5f6f7086d0
2 changed files with 12 additions and 4 deletions
@@ -397,8 +397,9 @@ export function createAnthropicMessageParser(): ChatGenerateParseFunction {
if (stoppedBlock.input)
try {
const input = typeof stoppedBlock.input === 'string' ? JSON.parse(stoppedBlock.input) : stoppedBlock.input;
if (typeof input === 'object' && typeof input.code === 'string')
iTexts = [_ellipsizeContext(input.code)];
const codeOrCommandText = typeof input === 'object' ? (typeof input.code === 'string' ? input.code : typeof input.command === 'string' ? input.command : undefined) : undefined;
if (codeOrCommandText)
iTexts = [_ellipsizeContext(codeOrCommandText)];
} catch { /* ignore parse errors */ }
const execText = stoppedBlock.name === 'bash_code_execution' ? 'Executing bash script...' : 'Executing code...';
pt.sendOperationState('code-exec', execText, { opId: stoppedBlock.id, ...iTexts && { iTexts } });
@@ -826,7 +827,12 @@ function _handleCBS_BashCodeExecutionToolResult(pt: IParticleTransmitter, block:
const opId = block.tool_use_id;
switch (block.content.type) {
case 'bash_code_execution_result':
pt.sendOperationState('code-exec', 'Bash executed', { opId, state: 'done' });
const oTexts: string[] = [];
if (block.content.stdout)
oTexts.push(_ellipsizeContext(block.content.stdout));
if (block.content.stderr)
oTexts.push('stderr: ' + _ellipsizeContext(block.content.stderr));
pt.sendOperationState('code-exec', 'Bash executed', { opId, state: 'done', ...oTexts.length ? { oTexts } : undefined });
// add text if there are generated files in content array
const fileIds: string[] = [];
@@ -274,7 +274,9 @@ export namespace AnthropicWire_Blocks {
input: z.union([
z.object({ query: z.string() }), // web_search
z.object({ url: z.string() }), // web_fetch
z.object({ code: z.string() }), // code_execution, bash_code_execution, text_editor_code_execution
z.object({ code: z.string() }), // code_execution
z.object({ command: z.string() }), // bash_code_execution
// we don't know about the text_editor_code_execution and others
]).or(z.any()), // see the comment on ToolUseBlock_schema.input
caller: _ToolUseCaller_schema.optional(),
});