ai-agent-test 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +86 -0
  2. package/bin/ai +3 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +250 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/tools/ask_user_followup.d.ts +14 -0
  8. package/dist/tools/ask_user_followup.d.ts.map +1 -0
  9. package/dist/tools/ask_user_followup.js +21 -0
  10. package/dist/tools/ask_user_followup.js.map +1 -0
  11. package/dist/tools/bash.d.ts +21 -0
  12. package/dist/tools/bash.d.ts.map +1 -0
  13. package/dist/tools/bash.js +31 -0
  14. package/dist/tools/bash.js.map +1 -0
  15. package/dist/tools/compilation_check.d.ts +21 -0
  16. package/dist/tools/compilation_check.d.ts.map +1 -0
  17. package/dist/tools/compilation_check.js +39 -0
  18. package/dist/tools/compilation_check.js.map +1 -0
  19. package/dist/tools/edit.d.ts +34 -0
  20. package/dist/tools/edit.d.ts.map +1 -0
  21. package/dist/tools/edit.js +60 -0
  22. package/dist/tools/edit.js.map +1 -0
  23. package/dist/tools/index.d.ts +173 -0
  24. package/dist/tools/index.d.ts.map +1 -0
  25. package/dist/tools/index.js +29 -0
  26. package/dist/tools/index.js.map +1 -0
  27. package/dist/tools/internet_search.d.ts +27 -0
  28. package/dist/tools/internet_search.d.ts.map +1 -0
  29. package/dist/tools/internet_search.js +73 -0
  30. package/dist/tools/internet_search.js.map +1 -0
  31. package/dist/tools/read.d.ts +23 -0
  32. package/dist/tools/read.d.ts.map +1 -0
  33. package/dist/tools/read.js +67 -0
  34. package/dist/tools/read.js.map +1 -0
  35. package/dist/tools/record_progress.d.ts +14 -0
  36. package/dist/tools/record_progress.d.ts.map +1 -0
  37. package/dist/tools/record_progress.js +15 -0
  38. package/dist/tools/record_progress.js.map +1 -0
  39. package/dist/tools/write.d.ts +26 -0
  40. package/dist/tools/write.d.ts.map +1 -0
  41. package/dist/tools/write.js +39 -0
  42. package/dist/tools/write.js.map +1 -0
  43. package/dist/utils/system.d.ts +4 -0
  44. package/dist/utils/system.d.ts.map +1 -0
  45. package/dist/utils/system.js +34 -0
  46. package/dist/utils/system.js.map +1 -0
  47. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # AI Agent Test
2
+
3
+ A lightweight, extensible agentic workflow system built with TypeScript and the AI SDK. This project serves as a testbed for implementing mini agentic flows with support for small-sized local LLMs (30B-80B parameters) and few tool integrations.
4
+
5
+ ## 🌟 Features
6
+
7
+ - **Agentic Architecture**: Multi-iteration agent loop with tool calling capabilities
8
+ - **Local LLM Support**: Connect to any OpenAI-compatible API endpoint or Google Generative AI
9
+ - **Extensible Tools**: Built-in tools for file operations, bash execution, web search, and more
10
+ - See [src/tools/](./src/tools/) for all available tools
11
+ - **Interactive CLI**: Real-time chat interface with streaming responses
12
+ - **Debug Mode**: Inspect conversation history and token usage
13
+ - **Logging**: Session logging to track agent behavior and progress
14
+
15
+ ## 🛠️ Prerequisites
16
+
17
+ - A local LLM server (e.g., LM Studio, Ollama) or cloud API key
18
+
19
+ ## 📦 Installation
20
+
21
+ ### As a CLI tool (global)
22
+
23
+ ```bash
24
+ npm install -g ai-agent-test
25
+ # Create ~/.ai/models.json with your configuration (see Configuration section below)
26
+ ```
27
+
28
+ Then run:
29
+
30
+ ```bash
31
+ ai
32
+ ```
33
+
34
+ ### Development installation
35
+
36
+ ```bash
37
+ npm install
38
+ # Create ~/.ai/models.json with your configuration (see Configuration section below)
39
+ ```
40
+
41
+ ## ⚙️ Configuration
42
+
43
+ ### Model Configuration
44
+
45
+ Create a JSON configuration file at `~/.ai/models.json` with an array of model configurations:
46
+
47
+ ```json
48
+ [
49
+ {
50
+ "modelApiType": "openai",
51
+ "modelName": "qwen3-coder-next",
52
+ "apiBaseUrl": "http://localhost:8090/v1",
53
+ "apiKey": "dummy",
54
+ "braveApiKey": "your_brave_api_key_here"
55
+ },
56
+ {
57
+ "modelApiType": "google",
58
+ "modelName": "gemini-2.5-flash",
59
+ "apiBaseUrl": "https://generativelanguage.googleapis.com/v1beta",
60
+ "apiKey": "your_google_api_key_here",
61
+ "braveApiKey": "your_brave_api_key_here"
62
+ }
63
+ ]
64
+ ```
65
+
66
+ Set the environment variable in your terminal before running (Default to 0):
67
+
68
+ ```bash
69
+ export AI_MODEL_INDEX=0 # Use the first model in models.json (default)
70
+ npx tsx src/index.ts
71
+ ```
72
+
73
+ Or set it inline:
74
+
75
+ ```bash
76
+ AI_MODEL_INDEX=0 npx tsx src/index.ts
77
+ ```
78
+
79
+ ### CLI Commands
80
+
81
+ When installed globally, run `ai` to start the interactive CLI:
82
+
83
+ - Type your prompt and press Enter to start the agent loop
84
+ - `exit` or `quit` to terminate the session
85
+ - `debug <n>` to view last n messages (or all if no number provided)
86
+ - ESC key to interrupt the current agent iteration
package/bin/ai ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import('../dist/index.js');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,250 @@
1
+ import { streamText } from "ai";
2
+ import { createOpenAI } from "@ai-sdk/openai";
3
+ import * as readline from "readline";
4
+ import { toolNames, tools } from "./tools/index.js";
5
+ import chalk from "chalk";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import { fileURLToPath } from "url";
9
+ import { readFileSync } from "fs";
10
+ import { homedir } from "os";
11
+ import { join, dirname } from "path";
12
+ import { createGoogleGenerativeAI } from "@ai-sdk/google";
13
+ import { logToFile, logMessages } from "./utils/system.js";
14
+ // Get the directory of this module (works with ES modules)
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ // Load configuration from ~/.ai/models.json
18
+ const modelsFile = join(homedir(), ".ai", "models.json");
19
+ let config;
20
+ try {
21
+ const fileContent = readFileSync(modelsFile, "utf-8");
22
+ const models = JSON.parse(fileContent);
23
+ const modelIndex = parseInt(process.env.AI_MODEL_INDEX || "0", 10);
24
+ config = models[modelIndex];
25
+ }
26
+ catch (error) {
27
+ console.error(chalk.red(`Failed to load configuration from ${modelsFile}: ${error.message}`));
28
+ const sampleConfig = [
29
+ {
30
+ modelApiType: "openai (openai or google)",
31
+ modelName: "gpt-4o",
32
+ apiBaseUrl: "https://api.openai.com/v1",
33
+ apiKey: "your-api-key-here",
34
+ },
35
+ ];
36
+ console.log(chalk.yellow("\nPlease create a ~/.ai/models.json file with the following format:"));
37
+ console.log(chalk.yellow(JSON.stringify(sampleConfig, null, 2)));
38
+ process.exit(1);
39
+ }
40
+ const { modelApiType: modelProvider, modelName, apiBaseUrl: baseUrl, apiKey, } = config;
41
+ let model;
42
+ if (modelProvider === "google") {
43
+ model = createGoogleGenerativeAI({
44
+ baseURL: baseUrl,
45
+ apiKey: apiKey,
46
+ }).chat(modelName);
47
+ }
48
+ else {
49
+ model = createOpenAI({
50
+ baseURL: baseUrl,
51
+ apiKey: apiKey,
52
+ }).chat(modelName);
53
+ }
54
+ const systemPromptPath = path.join(__dirname, "../SYSTEM.md");
55
+ let systemPrompt = fs.readFileSync(systemPromptPath, "utf-8");
56
+ systemPrompt = systemPrompt
57
+ .replace("{date}", new Date().toLocaleString())
58
+ .replace("{pwd}", process.cwd());
59
+ const rl = readline.createInterface({
60
+ input: process.stdin,
61
+ output: process.stdout,
62
+ terminal: false,
63
+ });
64
+ let interruptRequested = false;
65
+ async function askQuestion(prompt) {
66
+ return new Promise((resolve) => {
67
+ process.stdout.write(prompt);
68
+ rl.once("line", (answer) => resolve(answer));
69
+ });
70
+ }
71
+ const messages = [];
72
+ async function runLoop(prompt) {
73
+ messages.push({
74
+ role: "user",
75
+ content: prompt,
76
+ });
77
+ logToFile(`User prompt: ${prompt.substring(0, 200)}...`);
78
+ // Reset interrupt flag
79
+ interruptRequested = false;
80
+ // Set up ESC key listener
81
+ const setupEscListener = () => {
82
+ if (process.stdin.isTTY) {
83
+ process.stdin.setRawMode(true);
84
+ process.stdin.resume();
85
+ process.stdin.on("data", onKeyPress);
86
+ }
87
+ };
88
+ const cleanupEscListener = () => {
89
+ if (process.stdin.isTTY) {
90
+ process.stdin.removeListener("data", onKeyPress);
91
+ process.stdin.setRawMode(false);
92
+ }
93
+ };
94
+ const onKeyPress = (key) => {
95
+ // ESC key is 0x1b
96
+ if (key[0] === 0x1b) {
97
+ console.log(chalk.magenta("\n\n[Interrupt requested]"));
98
+ interruptRequested = true;
99
+ }
100
+ };
101
+ setupEscListener();
102
+ while (true) {
103
+ const res = await streamText({
104
+ model,
105
+ messages,
106
+ tools,
107
+ system: systemPrompt,
108
+ });
109
+ const assistantContent = [];
110
+ let fullText = "";
111
+ for await (const part of res.textStream) {
112
+ if (interruptRequested) {
113
+ cleanupEscListener();
114
+ logToFile("=== break loop: user interrupted with ESC key ===");
115
+ return;
116
+ }
117
+ if (part) {
118
+ if (!fullText) {
119
+ process.stdout.write(chalk.cyan("\nAssistant: "));
120
+ }
121
+ process.stdout.write(part);
122
+ fullText += part;
123
+ }
124
+ }
125
+ if (fullText) {
126
+ assistantContent.push({ type: "text", text: fullText });
127
+ }
128
+ const toolResults = await res.toolResults;
129
+ const toolCalls = await res.toolCalls;
130
+ const usage = await res.usage;
131
+ for (const toolCall of toolCalls || []) {
132
+ assistantContent.push({
133
+ type: "tool-call",
134
+ toolCallId: toolCall.toolCallId,
135
+ toolName: toolCall.toolName,
136
+ input: toolCall.input,
137
+ });
138
+ }
139
+ if (assistantContent.length > 0) {
140
+ messages.push({
141
+ role: "assistant",
142
+ content: assistantContent,
143
+ });
144
+ logToFile("Added assistant message with content");
145
+ }
146
+ const toolResultContent = [];
147
+ for (const toolResult of toolResults || []) {
148
+ const output = toolResult.output;
149
+ if (output && output.success) {
150
+ toolResultContent.push({
151
+ type: "tool-result",
152
+ toolCallId: toolResult.toolCallId,
153
+ toolName: toolResult.toolName,
154
+ output: {
155
+ type: "text",
156
+ value: output.output +
157
+ `\n\n[Tool execution metadata: ${JSON.stringify(output.metadata || {})}]`,
158
+ },
159
+ });
160
+ }
161
+ else {
162
+ toolResultContent.push({
163
+ type: "tool-result",
164
+ toolCallId: toolResult.toolCallId,
165
+ toolName: toolResult.toolName,
166
+ output: {
167
+ type: "text",
168
+ value: output.stderr || output.error || "Unknown error",
169
+ },
170
+ });
171
+ }
172
+ }
173
+ if (toolResultContent.length > 0) {
174
+ messages.push({
175
+ role: "tool",
176
+ content: toolResultContent,
177
+ });
178
+ logToFile(`Added ${toolResultContent.length} tool result(s)`);
179
+ }
180
+ // Display token usage
181
+ console.log(chalk.gray(`\n\n[${modelName}] Token: ${usage.totalTokens || 0} (${usage.inputTokens || 0} + ${usage.outputTokens || 0})`));
182
+ logToFile(`Iteration complete. Tool calls: ${toolCalls?.length || 0}, Tool results: ${toolResultContent.length}`);
183
+ logMessages(messages);
184
+ if (toolCalls.length === 0) {
185
+ logToFile("=== break loop: no tool calls ===");
186
+ break;
187
+ }
188
+ const progressRes = toolResults.find((result) => result.toolName === toolNames.recordProgress);
189
+ if (progressRes && progressRes.output === 100) {
190
+ console.log("\nTask completed with 100% progress!");
191
+ logToFile("=== break loop: task completed with 100% progress ===");
192
+ break;
193
+ }
194
+ const followUpRes = toolResults.find((result) => result.toolName === toolNames.askUserFollowup);
195
+ if (followUpRes) {
196
+ console.log(chalk.yellow("\n--- Waiting for user input ---"));
197
+ logToFile("=== break loop: asked user followup ===");
198
+ break;
199
+ }
200
+ if (interruptRequested) {
201
+ logToFile("=== break loop: user interrupted with ESC key ===");
202
+ break;
203
+ }
204
+ }
205
+ cleanupEscListener();
206
+ }
207
+ async function main() {
208
+ logToFile("\n========== Session Started ==========");
209
+ console.log(chalk.cyan(`AI Agent Ready at ${process.cwd()}!\n`));
210
+ console.log(chalk.cyan("interrupt: ESC, exit: 'exit' or 'quit', debug: 'debug [num]'"));
211
+ console.log(chalk.cyan("============================================================\n"));
212
+ while (true) {
213
+ const userPrompt = await askQuestion("\nPrompt: ");
214
+ if (userPrompt.toLowerCase() === "exit" ||
215
+ userPrompt.toLowerCase() === "quit") {
216
+ logToFile("User exited the session");
217
+ logToFile("========== Session Ended ==========\n");
218
+ rl.close();
219
+ break;
220
+ }
221
+ // TODO: print debug
222
+ if (userPrompt.toLowerCase().startsWith("debug")) {
223
+ console.log("\n--- Debug Info ---");
224
+ const parts = userPrompt.trim().split(/\s+/);
225
+ const tailNumStr = parts.length > 1 ? parts[1] : "";
226
+ const tailNum = tailNumStr ? parseInt(tailNumStr, 10) : undefined;
227
+ if (tailNum && !isNaN(tailNum)) {
228
+ console.log(`Last ${tailNum} message(s):`);
229
+ const messagesToDisplay = tailNum > 0 ? messages.slice(-tailNum) : [];
230
+ console.log(JSON.stringify(messagesToDisplay, null, 2));
231
+ }
232
+ else {
233
+ console.log("All messages:");
234
+ console.log(JSON.stringify(messages, null, 2));
235
+ }
236
+ console.log("--- End Debug Info ---\n");
237
+ continue;
238
+ }
239
+ try {
240
+ await runLoop(userPrompt);
241
+ }
242
+ catch (error) {
243
+ console.error(chalk.red(`Error in main loop: ${error.message}`));
244
+ console.log(JSON.stringify(messages.slice(-10), null, 2));
245
+ throw error;
246
+ }
247
+ }
248
+ }
249
+ main();
250
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuC,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,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,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ export declare const askUserFollowup: {
3
+ description: string;
4
+ inputSchema: z.ZodObject<{
5
+ question: z.ZodString;
6
+ }, z.core.$strip>;
7
+ execute: ({ question }: {
8
+ question: string;
9
+ }) => Promise<{
10
+ success: boolean;
11
+ output: string;
12
+ }>;
13
+ };
14
+ //# sourceMappingURL=ask_user_followup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask_user_followup.d.ts","sourceRoot":"","sources":["../../src/tools/ask_user_followup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,eAAe;;;;;4BAgBI;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;;;;CAInD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ import chalk from "chalk";
3
+ export const askUserFollowup = {
4
+ description: "Use this to ask the user a follow-up question when you need specific information to proceed with their request. " +
5
+ "Use this tool when:\n" +
6
+ "- The user's request is ambiguous or missing key details\n" +
7
+ "- You need clarification on requirements or preferences\n" +
8
+ "- Multiple options are available and you need the user to make a choice\n" +
9
+ "\nDo NOT use this for general conversation or as a replacement for direct responses.",
10
+ inputSchema: z.object({
11
+ question: z
12
+ .string()
13
+ .min(10, "Question must be at least 10 characters")
14
+ .describe("Your follow-up question for the user. Make it clear, specific, and focused on getting the information you need to proceed."),
15
+ }),
16
+ execute: async ({ question }) => {
17
+ console.log(chalk.yellow(`\n[tool calling - ask_user_followup] ${question}`));
18
+ return { success: true, output: `Asked user: ${question}` };
19
+ },
20
+ };
21
+ //# sourceMappingURL=ask_user_followup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask_user_followup.js","sourceRoot":"","sources":["../../src/tools/ask_user_followup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW,EACT,kHAAkH;QAClH,uBAAuB;QACvB,4DAA4D;QAC5D,2DAA2D;QAC3D,2EAA2E;QAC3E,sFAAsF;IACxF,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,CAAC;aACR,MAAM,EAAE;aACR,GAAG,CAAC,EAAE,EAAE,yCAAyC,CAAC;aAClD,QAAQ,CACP,4HAA4H,CAC7H;KACJ,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAwB,EAAE,EAAE;QACpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,wCAAwC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,QAAQ,EAAE,EAAE,CAAC;IAC9D,CAAC;CACF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ export declare const bashTool: {
3
+ description: string;
4
+ inputSchema: z.ZodObject<{
5
+ command: z.ZodString;
6
+ }, z.core.$strip>;
7
+ execute: ({ command }: {
8
+ command: string;
9
+ }) => Promise<{
10
+ success: boolean;
11
+ output: string;
12
+ error?: never;
13
+ stderr?: never;
14
+ } | {
15
+ success: boolean;
16
+ error: any;
17
+ stderr: any;
18
+ output?: never;
19
+ }>;
20
+ };
21
+ //# sourceMappingURL=bash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../src/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,QAAQ;;;;;2BAMU;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;CAwBjD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ import { execSync } from "child_process";
3
+ import chalk from "chalk";
4
+ export const bashTool = {
5
+ description: "Execute a bash command and return its output. This should be useful to find which files to read when exploring the codebase, find variables, and run CLI tools or bash commands.",
6
+ inputSchema: z.object({
7
+ command: z.string().describe("The bash command to execute"),
8
+ }),
9
+ execute: async ({ command }) => {
10
+ console.log(chalk.yellow(`\n[tool calling - bash] Executing command: ${command}`));
11
+ try {
12
+ const result = execSync(command, {
13
+ encoding: "utf-8",
14
+ stdio: "pipe",
15
+ });
16
+ return {
17
+ success: true,
18
+ output: `result: ${result}\n\nPrint this output as they are`,
19
+ };
20
+ }
21
+ catch (error) {
22
+ console.error(chalk.red(`[tool calling - bash] ⚠️ Command failed: ${error.message}`));
23
+ return {
24
+ success: false,
25
+ error: error.message,
26
+ stderr: error.stderr?.toString() || "",
27
+ };
28
+ }
29
+ },
30
+ };
31
+ //# sourceMappingURL=bash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,WAAW,EACT,kLAAkL;IACpL,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;KAC5D,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAuB,EAAE,EAAE;QAClD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CAAC,8CAA8C,OAAO,EAAE,CAAC,CACtE,CAAC;QACF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE;gBAC/B,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,MAAM;aACd,CAAC,CAAC;YACH,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,WAAW,MAAM,mCAAmC;aAC7D,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,4CAA4C,KAAK,CAAC,OAAO,EAAE,CAAC,CACvE,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;aACvC,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ export declare const compilationCheckTool: {
3
+ description: string;
4
+ inputSchema: z.ZodObject<{
5
+ command: z.ZodString;
6
+ }, z.core.$strip>;
7
+ execute: ({ command }: {
8
+ command: string;
9
+ }) => Promise<{
10
+ success: boolean;
11
+ output: string;
12
+ error?: never;
13
+ stderr?: never;
14
+ } | {
15
+ success: boolean;
16
+ error: any;
17
+ output: any;
18
+ stderr: any;
19
+ }>;
20
+ };
21
+ //# sourceMappingURL=compilation_check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilation_check.d.ts","sourceRoot":"","sources":["../../src/tools/compilation_check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,oBAAoB;;;;;2BAMF;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;CAoCjD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { execSync } from "child_process";
3
+ import chalk from "chalk";
4
+ export const compilationCheckTool = {
5
+ description: "Run a compilation check command to verify code quality and catch errors. Useful for TypeScript (npx tsc --noEmit), JavaScript (npm run lint or similar), or other languages. This helps ensure changes don't break the build before committing.",
6
+ inputSchema: z.object({
7
+ command: z.string().describe("The compilation check command to execute, e.g., 'npx tsc --noEmit' for TypeScript or 'npm run lint' for JavaScript"),
8
+ }),
9
+ execute: async ({ command }) => {
10
+ console.log(chalk.yellow(`\n[tool calling - compilationCheck] Running compilation check: ${command}`));
11
+ try {
12
+ const result = execSync(command, {
13
+ encoding: "utf-8",
14
+ stdio: "pipe",
15
+ });
16
+ if (result.includes("error") || result.includes("Error")) {
17
+ console.warn(chalk.yellow(`[tool calling - compilationCheck] ⚠️ Compilation check found issues.`));
18
+ return {
19
+ success: false,
20
+ output: "Compilation check found errors:\n" + result,
21
+ };
22
+ }
23
+ return {
24
+ success: true,
25
+ output: "Compilation check passed successfully.\n" + result,
26
+ };
27
+ }
28
+ catch (error) {
29
+ console.error(chalk.red(`[tool calling - compilationCheck] ⚠️ Compilation check failed: ${error.message}`));
30
+ return {
31
+ success: false,
32
+ error: error.message,
33
+ output: error.stdout?.toString() || "",
34
+ stderr: error.stderr?.toString() || "",
35
+ };
36
+ }
37
+ },
38
+ };
39
+ //# sourceMappingURL=compilation_check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilation_check.js","sourceRoot":"","sources":["../../src/tools/compilation_check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW,EACT,iPAAiP;IACnP,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oHAAoH,CAAC;KACnJ,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAuB,EAAE,EAAE;QAClD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CAAC,kEAAkE,OAAO,EAAE,CAAC,CAC1F,CAAC;QACF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE;gBAC/B,QAAQ,EAAE,OAAO;gBACjB,KAAK,EAAE,MAAM;aACd,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzD,OAAO,CAAC,IAAI,CACV,KAAK,CAAC,MAAM,CAAC,sEAAsE,CAAC,CACrF,CAAC;gBACF,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC,GAAG,MAAM;iBACrD,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,0CAA0C,GAAG,MAAM;aAC5D,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,kEAAkE,KAAK,CAAC,OAAO,EAAE,CAAC,CAC7F,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACtC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;aACvC,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ export interface Edit {
3
+ oldText: string;
4
+ newText: string;
5
+ }
6
+ export declare const editTool: {
7
+ description: string;
8
+ inputSchema: z.ZodObject<{
9
+ path: z.ZodString;
10
+ edits: z.ZodArray<z.ZodObject<{
11
+ oldText: z.ZodString;
12
+ newText: z.ZodString;
13
+ }, z.core.$strip>>;
14
+ }, z.core.$strip>;
15
+ execute: ({ path: filePath, edits, }: {
16
+ path: string;
17
+ edits: Edit[];
18
+ }) => Promise<{
19
+ success: boolean;
20
+ output: string;
21
+ metadata: {
22
+ path: string;
23
+ editsCount: number;
24
+ totalEdits: number;
25
+ };
26
+ error?: never;
27
+ } | {
28
+ success: boolean;
29
+ error: any;
30
+ output?: never;
31
+ metadata?: never;
32
+ }>;
33
+ };
34
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,QAAQ;;;;;;;;;0CAqBhB;QACD,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,IAAI,EAAE,CAAC;KACf;;;;;;;;;;;;;;;CA0DF,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { z } from "zod";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import chalk from "chalk";
5
+ export const editTool = {
6
+ description: "Make precise, targeted edits to existing files. Replace specific text patterns without rewriting the entire file. Use this for modifications when you want to keep most of the file intact and only change specific lines or sections.",
7
+ inputSchema: z.object({
8
+ path: z.string().describe("The path to the file to edit"),
9
+ edits: z
10
+ .array(z.object({
11
+ oldText: z
12
+ .string()
13
+ .describe("The exact text for JS's `replace()` function"),
14
+ newText: z.string().describe("The new text to insert"),
15
+ }))
16
+ .describe("Array of edits, each containing oldText and newText for exact match replacement"),
17
+ }),
18
+ execute: async ({ path: filePath, edits, }) => {
19
+ console.log(chalk.yellow(`\n[tool calling - edit] Editing file: ${filePath} (edits: ${edits.length})`));
20
+ try {
21
+ const fullPath = path.resolve(filePath);
22
+ if (!fs.existsSync(fullPath)) {
23
+ return {
24
+ success: false,
25
+ error: `File not found: ${fullPath}`,
26
+ };
27
+ }
28
+ let content = fs.readFileSync(fullPath, "utf-8");
29
+ let editsApplied = 0;
30
+ for (const edit of edits) {
31
+ const existingContent = content;
32
+ content = content.replace(edit.oldText, edit.newText);
33
+ if (content !== existingContent) {
34
+ editsApplied++;
35
+ }
36
+ else {
37
+ console.warn(chalk.yellow(`[tool calling - edit] ⚠️ oldText not found in file: ${edit.oldText.substring(0, 50)}...`));
38
+ }
39
+ }
40
+ fs.writeFileSync(fullPath, content, "utf-8");
41
+ return {
42
+ success: true,
43
+ output: `File "${fullPath}" edited successfully.\nEdits applied: ${editsApplied} out of ${edits.length}`,
44
+ metadata: {
45
+ path: fullPath,
46
+ editsCount: editsApplied,
47
+ totalEdits: edits.length,
48
+ },
49
+ };
50
+ }
51
+ catch (error) {
52
+ console.error(chalk.red(`[tool calling - edit] ⚠️ Failed to edit file: ${error.message}`));
53
+ return {
54
+ success: false,
55
+ error: error.message,
56
+ };
57
+ }
58
+ },
59
+ };
60
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,WAAW,EACT,wOAAwO;IAC1O,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QACzD,KAAK,EAAE,CAAC;aACL,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;iBACP,MAAM,EAAE;iBACR,QAAQ,CAAC,8CAA8C,CAAC;Y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