code-ollama 0.1.1 → 0.2.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 (2) hide show
  1. package/dist/cli.js +54 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -8,7 +8,7 @@ import { exec } from "node:child_process";
8
8
  import { promisify } from "node:util";
9
9
  //#endregion
10
10
  //#region src/constants/package.ts
11
- var VERSION = "0.1.1";
11
+ var VERSION = "0.2.0";
12
12
  //#endregion
13
13
  //#region src/constants/prompt.ts
14
14
  var BASE_SYSTEM_PROMPT = `You are a coding assistant that helps users write, edit, and understand code. You have access to tools for reading files, writing files, running shell commands, and searching code
@@ -25,7 +25,7 @@ When tools return results, incorporate them into your response naturally`;
25
25
  var TOOL_INSTRUCTIONS = `Available tools:
26
26
  - read_file: Read file contents at a path
27
27
  - write_file: Write content to a file (requires approval)
28
- - edit_file: Make precise edits to a file
28
+ - edit_file: Replace one exact text match in a file (requires approval)
29
29
  - list_dir: List files in a directory
30
30
  - grep_search: Search code with regex
31
31
  - run_shell: Execute shell commands (requires approval)
@@ -47,6 +47,7 @@ var ROLE = {
47
47
  var NAME = {
48
48
  READ_FILE: "read_file",
49
49
  WRITE_FILE: "write_file",
50
+ EDIT_FILE: "edit_file",
50
51
  RUN_SHELL: "run_shell",
51
52
  LIST_DIR: "list_dir",
52
53
  GREP_SEARCH: "grep_search",
@@ -178,6 +179,24 @@ var TOOLS = [
178
179
  description: "The content to write to the file"
179
180
  }
180
181
  }, ["path", "content"]),
182
+ defineTool(NAME.EDIT_FILE, "Replace one exact text match in an existing file at the specified path", {
183
+ path: {
184
+ type: "string",
185
+ description: "The path to the file to edit"
186
+ },
187
+ oldText: {
188
+ type: "string",
189
+ description: "The exact existing text to replace"
190
+ },
191
+ newText: {
192
+ type: "string",
193
+ description: "The replacement text to write in place of oldText"
194
+ }
195
+ }, [
196
+ "path",
197
+ "oldText",
198
+ "newText"
199
+ ]),
181
200
  defineTool(NAME.RUN_SHELL, "Execute a shell command", { command: {
182
201
  type: "string",
183
202
  description: "The shell command to execute"
@@ -215,7 +234,11 @@ var TOOLS = [
215
234
  "end"
216
235
  ])
217
236
  ];
218
- var TOOLS_REQUIRING_APPROVAL = new Set([NAME.WRITE_FILE, NAME.RUN_SHELL]);
237
+ var TOOLS_REQUIRING_APPROVAL = new Set([
238
+ NAME.WRITE_FILE,
239
+ NAME.EDIT_FILE,
240
+ NAME.RUN_SHELL
241
+ ]);
219
242
  /**
220
243
  * Execute a tool by name with arguments
221
244
  */
@@ -223,6 +246,7 @@ async function executeTool(name, args) {
223
246
  switch (name) {
224
247
  case NAME.READ_FILE: return readFile(args.path);
225
248
  case NAME.WRITE_FILE: return writeFile(args.path, args.content);
249
+ case NAME.EDIT_FILE: return editFile(args.path, args.oldText, args.newText);
226
250
  case NAME.RUN_SHELL: return runShell(args.command);
227
251
  case NAME.LIST_DIR: return listDir(args.path);
228
252
  case NAME.GREP_SEARCH: return await grepSearch(args.pattern, args.path);
@@ -264,6 +288,33 @@ function writeFile(filePath, content) {
264
288
  };
265
289
  }
266
290
  }
291
+ /**
292
+ * Replace one exact text match in an existing file
293
+ */
294
+ function editFile(filePath, oldText, newText) {
295
+ try {
296
+ if (!existsSync(filePath)) return {
297
+ content: "",
298
+ error: `File not found: ${filePath}`
299
+ };
300
+ const content = readFileSync(filePath, "utf8");
301
+ if (!content.includes(oldText)) return {
302
+ content: "",
303
+ error: `Exact text not found in file: ${filePath}`
304
+ };
305
+ if (content.split(oldText).length - 1 > 1) return {
306
+ content: "",
307
+ error: `Exact text matched multiple locations in file: ${filePath}`
308
+ };
309
+ writeFileSync(filePath, content.replace(oldText, newText), "utf8");
310
+ return { content: `File edited successfully: ${filePath}` };
311
+ } catch (error) {
312
+ return {
313
+ content: "",
314
+ error: `Failed to edit file: ${error instanceof Error ? error.message : String(error)}`
315
+ };
316
+ }
317
+ }
267
318
  var SHELL_EXEC_OPTIONS = {
268
319
  timeout: 3e4,
269
320
  maxBuffer: 1024 * 1024
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-ollama",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Ollama coding agent that runs in your terminal",
5
5
  "author": "Mark <mark@remarkablemark.org> (https://remarkablemark.org)",
6
6
  "type": "module",