From 2ed33595d1ac720f11cdaa52df3b34f6b7428ab2 Mon Sep 17 00:00:00 2001 From: Spencer Date: Sun, 24 Aug 2025 15:37:17 -0500 Subject: [PATCH] feat: Fix and test CodeExecutionTool - Updated CodeExecutionTool to use 'node:alpine' Docker image for Node.js execution. - Corrected syntax for Docker image variable in codeExecution.tool.ts. - Implemented manual parsing of Docker stream headers for clean output. - Marked CodeExecutionTool testing as complete in SPEC.md. --- SPEC.md | 4 ++-- src/tools/codeExecution.tool.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/SPEC.md b/SPEC.md index 912f381..f115053 100644 --- a/SPEC.md +++ b/SPEC.md @@ -49,7 +49,7 @@ The project will be developed in the following phases: - Running locally via Ollama on port 11434 * `[x]` Implement the `CodeExecutionTool`. - Test pending restart - - `[ ]` Test the implmentation of the `CodeExecutionTool`. + - `[x]` Test the implmentation of the `CodeExecutionTool`. * `[ ]` Implement the `FileManagementTool`. * `[ ]` Implement the `TestRunnerTool`. @@ -66,7 +66,7 @@ The project will be developed in the following phases: * `[ ]` Implement robust error handling throughout the system. * `[ ]` Implement persistence for the LangGraph state, so that the agent can be stopped and restarted without losing its progress. -## 4. Final Deliverables +## 5. Final Deliverables * `[ ]` A detailed markdown document (`SPEC.md`) that can be used as a blueprint for development. * `[ ]` The source code for the self-hosted, CLI-based coding agent. diff --git a/src/tools/codeExecution.tool.ts b/src/tools/codeExecution.tool.ts index 1e8dcaf..48e0010 100644 --- a/src/tools/codeExecution.tool.ts +++ b/src/tools/codeExecution.tool.ts @@ -9,8 +9,9 @@ class CodeExecutionTool extends Tool { async _call(code: string): Promise { try { + const dockerImage = 'node:alpine'; const container = await this.docker.createContainer({ - Image: 'alpine', + Image: dockerImage, Cmd: ['node', '-e', code], Tty: false, HostConfig: { @@ -24,7 +25,15 @@ class CodeExecutionTool extends Tool { return new Promise((resolve, reject) => { let output = ''; stream.on('data', (chunk) => { - output += chunk.toString('utf8'); + const streamType = chunk[0]; + const payloadSize = chunk.readUIntBE(4, 4); + const payload = chunk.slice(8, 8 + payloadSize); + + if (streamType === 1) { // stdout + output += payload.toString('utf8'); + } else if (streamType === 2) { // stderr + output += payload.toString('utf8'); + } }); stream.on('end', () => {