From 9a176a7735c720d8b679daf92d6b65817489884c Mon Sep 17 00:00:00 2001 From: Spencer Date: Sun, 24 Aug 2025 15:16:02 -0500 Subject: [PATCH] Basic Structure --- .gitignore | 13 ++++++++++ AGENTS.md | 9 ++++--- PROMPT.md | 2 +- README.md | 1 + SPEC.md | 20 ++++++++++++--- jest.config.js | 4 +++ package.json | 29 ++++++++++++++++++++++ src/index.ts | 1 + src/tools/codeExecution.test.ts | 10 ++++++++ src/tools/codeExecution.tool.ts | 44 +++++++++++++++++++++++++++++++++ tsconfig.json | 14 +++++++++++ 11 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 src/tools/codeExecution.test.ts create mode 100644 src/tools/codeExecution.tool.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c68cc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Dependencies +/node_modules + +# Build output +/dist + +# Environment variables +.env +package-lock.json + +# Gemini files +GEMINI.md +PROGRESS.md diff --git a/AGENTS.md b/AGENTS.md index 21a28f1..0b63c39 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,9 +4,12 @@ This document outlines the operational constraints and directives for the AI age ## Core Directives -* [ ] **Task Completion:** Upon completing a task listed in `SPEC.md` or `PROGRESS.md`, I will mark the corresponding checkbox as completed (`[x]`) -* [ ] **Self-Correction:** If a test fails, I will analyze the error and attempt to fix the code until the test passes. -* [ ] **Continuous Improvement:** I will update this file (`AGENTS.md`) with any new constraints or core files that are added to the project. +* **Task Completion:** Upon completing a task listed in `SPEC.md` or `PROGRESS.md`, I will mark the corresponding checkbox as completed (`[x]`) +* **Self-Correction:** If a test fails, I will analyze the error and attempt to fix the code until the test passes. +* **Continuous Improvement:** I will update this file (`AGENTS.md`) with any new constraints or core files that are added to the project. +* **Git Commits** After each task is completed, I will add and commit relevant files, generating a commit message depending on what changes were made. +* **Documentation Generation** I will update the `SPEC.md` file with a detailed record of the changes, and the `README.md` file with any relevant changes or instructions. + ## File-Specific Directives diff --git a/PROMPT.md b/PROMPT.md index 22b3851..4ae98f5 100644 --- a/PROMPT.md +++ b/PROMPT.md @@ -15,7 +15,7 @@ Project Plan Requirements: Your plan must include the following sections, detailing the architecture and implementation steps: 1. Architectural Design & Workflow (LangGraph Graph): -Describe the agent's core logic as a directed graph using LangGraph. Define the key nodes and edges, and how they connect to enable the required looping behavior. +Describe the agent's core logic as a directed graph using LangGraph. Define the keys and edges, and how they connect to enable the required looping behavior. Nodes: Define nodes for each distinct step in the agent's process. At a minimum, include: diff --git a/README.md b/README.md new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/SPEC.md b/SPEC.md index 3451040..912f381 100644 --- a/SPEC.md +++ b/SPEC.md @@ -30,14 +30,26 @@ The agent will be equipped with the following tools: * `[ ]` **FileManagementTool**: A set of tools for reading and writing files to the local filesystem. This will be necessary for the agent to create, modify, and save the code scripts it is working on. * `[ ]` **TestRunnerTool**: A tool for running specific test cases against the generated code. This will be used to verify the correctness of the code. -## 3. Development Phases & Milestones +## 3. Technology Stack + +* **Language:** TypeScript +* **Framework:** LangChain.js with LangGraph +* **CLI Framework:** Commander.js +* **Local LLM Runner:** Ollama +* **Code Execution Sandbox:** Docker +* **Testing:** Jest + +## 4. Development Phases & Milestones The project will be developed in the following phases: * **Phase 1: Foundation & Tooling** - * `[ ]` Set up the local development environment. - * `[ ]` Download and set up the Phi4-mini model. - * `[ ]` Implement the `CodeExecutionTool`. + * `[x]` Set up the local development environment. + * `[x]` Download and set up the Phi4-mini model. + - Running locally via Ollama on port 11434 + * `[x]` Implement the `CodeExecutionTool`. + - Test pending restart + - `[ ]` Test the implmentation of the `CodeExecutionTool`. * `[ ]` Implement the `FileManagementTool`. * `[ ]` Implement the `TestRunnerTool`. diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..4a5b465 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..7116e93 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "blight", + "version": "1.0.0", + "description": "TODO", + "main": "index.js", + "scripts": { + "start": "npx tsc && node dist/index.js", + "test": "jest" + }, + "repository": { + "type": "git", + "url": "http://192.168.2.114:3000/artanis/Blight.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "devDependencies": { + "@types/dockerode": "^3.3.43", + "@types/jest": "^30.0.0", + "jest": "^30.0.5", + "ts-jest": "^29.4.1", + "typescript": "^5.9.2" + }, + "dependencies": { + "dockerode": "^4.0.7", + "langchain": "^0.3.31" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..a8141d3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +console.log("Hello, world!"); diff --git a/src/tools/codeExecution.test.ts b/src/tools/codeExecution.test.ts new file mode 100644 index 0000000..6255a15 --- /dev/null +++ b/src/tools/codeExecution.test.ts @@ -0,0 +1,10 @@ +import { CodeExecutionTool } from "./codeExecution.tool"; + +describe("CodeExecutionTool", () => { + it("should execute code and return the output", async () => { + const tool = new CodeExecutionTool(); + const code = "console.log('Hello, world!');"; + const result = await tool._call(code); + expect(result).toBe("Hello, world!\n"); + }); +}); diff --git a/src/tools/codeExecution.tool.ts b/src/tools/codeExecution.tool.ts new file mode 100644 index 0000000..1e8dcaf --- /dev/null +++ b/src/tools/codeExecution.tool.ts @@ -0,0 +1,44 @@ +import { Tool } from "langchain/tools"; +import Docker from 'dockerode'; + +class CodeExecutionTool extends Tool { + name = "code-execution"; + description = "A tool for executing code in a sandboxed environment."; + + private docker = new Docker(); + + async _call(code: string): Promise { + try { + const container = await this.docker.createContainer({ + Image: 'alpine', + Cmd: ['node', '-e', code], + Tty: false, + HostConfig: { + AutoRemove: true, + } + }); + + const stream = await container.attach({ stream: true, stdout: true, stderr: true }); + await container.start(); + + return new Promise((resolve, reject) => { + let output = ''; + stream.on('data', (chunk) => { + output += chunk.toString('utf8'); + }); + + stream.on('end', () => { + resolve(output); + }); + + stream.on('error', (err) => { + reject(err); + }); + }); + } catch (err: any) { + return `Error executing code: ${err.message}`; + } + } +} + +export { CodeExecutionTool }; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b3e86ef --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": "./src", + "outDir": "./dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "sourceMap": true + } +}