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', () => {