code-ollama 0.1.0 → 0.1.1
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.
- package/dist/assets/tui-DSR1MJGd.js +438 -0
- package/dist/cli.js +420 -42
- package/package.json +2 -2
- package/dist/tui-Bu6wAbeu.js +0 -559
- package/dist/utils-DBXrYZEs.js +0 -283
package/dist/utils-DBXrYZEs.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { existsSync as e, mkdirSync as t, readFileSync as n, readdirSync as r, writeFileSync as i } from "node:fs";
|
|
2
|
-
import { join as a } from "node:path";
|
|
3
|
-
import { homedir as o } from "node:os";
|
|
4
|
-
import { Ollama as s } from "ollama";
|
|
5
|
-
import { exec as c } from "node:child_process";
|
|
6
|
-
import { promisify as l } from "node:util";
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/constants/package.ts
|
|
9
|
-
var u = "0.1.0", d = "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\n\nFollow these rules:\n1. Always use available tools rather than guessing file contents or code behavior\n2. Read files before editing them to understand context\n3. When writing files, provide complete, working code\n4. Explain your reasoning when making non-trivial changes\n5. Prefer minimal changes that achieve the goal\n6. Confirm with the user before destructive operations\n\nWhen tools return results, incorporate them into your response naturally", f = "Available tools:\n- read_file: Read file contents at a path\n- write_file: Write content to a file (requires approval)\n- edit_file: Make precise edits to a file\n- list_dir: List files in a directory\n- grep_search: Search code with regex\n- run_shell: Execute shell commands (requires approval)\n\nAlways use tools when you need to:\n- Check file contents before referencing them\n- Make file changes\n- Explore project structure\n- Search the codebase", p = {
|
|
10
|
-
USER: "user",
|
|
11
|
-
ASSISTANT: "assistant",
|
|
12
|
-
SYSTEM: "system"
|
|
13
|
-
}, m = {
|
|
14
|
-
READ_FILE: "read_file",
|
|
15
|
-
WRITE_FILE: "write_file",
|
|
16
|
-
RUN_SHELL: "run_shell",
|
|
17
|
-
LIST_DIR: "list_dir",
|
|
18
|
-
GREP_SEARCH: "grep_search",
|
|
19
|
-
VIEW_RANGE: "view_range"
|
|
20
|
-
}, h = "AGENTS.md";
|
|
21
|
-
function g() {
|
|
22
|
-
let t = a(process.cwd(), h);
|
|
23
|
-
if (!e(t)) return null;
|
|
24
|
-
try {
|
|
25
|
-
return n(t, "utf8");
|
|
26
|
-
} catch {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function _() {
|
|
31
|
-
let e = [d], t = g();
|
|
32
|
-
return t && e.push("\n\nProject context from AGENTS.md:\n", t), e.push("\n\n", f), e.join("");
|
|
33
|
-
}
|
|
34
|
-
function v() {
|
|
35
|
-
return {
|
|
36
|
-
role: p.SYSTEM,
|
|
37
|
-
content: _()
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/utils/config.ts
|
|
42
|
-
var y = a(o(), ".code-ollama"), b = a(y, "config.json"), x = {
|
|
43
|
-
host: "http://localhost:11434",
|
|
44
|
-
model: "gemma4"
|
|
45
|
-
};
|
|
46
|
-
function S() {
|
|
47
|
-
if (!e(b)) return {};
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(n(b, "utf8"));
|
|
50
|
-
} catch {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function C() {
|
|
55
|
-
let e = S();
|
|
56
|
-
return {
|
|
57
|
-
host: process.env.OLLAMA_HOST ?? e.host ?? x.host,
|
|
58
|
-
model: process.env.OLLAMA_MODEL ?? e.model ?? x.model
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function w(e) {
|
|
62
|
-
let n = {
|
|
63
|
-
...S(),
|
|
64
|
-
...e
|
|
65
|
-
};
|
|
66
|
-
t(y, { recursive: !0 }), i(b, JSON.stringify(n, null, 2) + "\n", "utf8");
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/utils/ollama.ts
|
|
70
|
-
var { host: T, model: E } = C(), D = new s({ host: T });
|
|
71
|
-
async function* O(e, t = E, n) {
|
|
72
|
-
let r = await D.chat({
|
|
73
|
-
model: t,
|
|
74
|
-
messages: e,
|
|
75
|
-
stream: !0,
|
|
76
|
-
tools: n
|
|
77
|
-
});
|
|
78
|
-
for await (let e of r) e.message.content && (yield {
|
|
79
|
-
type: "content",
|
|
80
|
-
content: e.message.content
|
|
81
|
-
}), e.message.tool_calls && (yield {
|
|
82
|
-
type: "tool_calls",
|
|
83
|
-
tool_calls: e.message.tool_calls
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async function k() {
|
|
87
|
-
let { models: e } = await D.list();
|
|
88
|
-
return e.map(({ name: e }) => e);
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/utils/screen.ts
|
|
92
|
-
var A = "\x1Bc";
|
|
93
|
-
function j() {
|
|
94
|
-
process.stdout.write(A);
|
|
95
|
-
}
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/utils/tools.ts
|
|
98
|
-
var M = l(c);
|
|
99
|
-
function N(e, t, n, r) {
|
|
100
|
-
return {
|
|
101
|
-
type: "function",
|
|
102
|
-
function: {
|
|
103
|
-
name: e,
|
|
104
|
-
description: t,
|
|
105
|
-
parameters: {
|
|
106
|
-
type: "object",
|
|
107
|
-
properties: n,
|
|
108
|
-
required: r
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
var P = [
|
|
114
|
-
N(m.READ_FILE, "Read the contents of a file at the specified path", { path: {
|
|
115
|
-
type: "string",
|
|
116
|
-
description: "The path to the file to read"
|
|
117
|
-
} }, ["path"]),
|
|
118
|
-
N(m.WRITE_FILE, "Write content to a file at the specified path", {
|
|
119
|
-
path: {
|
|
120
|
-
type: "string",
|
|
121
|
-
description: "The path to the file to write"
|
|
122
|
-
},
|
|
123
|
-
content: {
|
|
124
|
-
type: "string",
|
|
125
|
-
description: "The content to write to the file"
|
|
126
|
-
}
|
|
127
|
-
}, ["path", "content"]),
|
|
128
|
-
N(m.RUN_SHELL, "Execute a shell command", { command: {
|
|
129
|
-
type: "string",
|
|
130
|
-
description: "The shell command to execute"
|
|
131
|
-
} }, ["command"]),
|
|
132
|
-
N(m.LIST_DIR, "List the contents of a directory", { path: {
|
|
133
|
-
type: "string",
|
|
134
|
-
description: "The path to the directory to list"
|
|
135
|
-
} }, ["path"]),
|
|
136
|
-
N(m.GREP_SEARCH, "Search for a pattern in files within a directory", {
|
|
137
|
-
pattern: {
|
|
138
|
-
type: "string",
|
|
139
|
-
description: "The regex pattern to search for"
|
|
140
|
-
},
|
|
141
|
-
path: {
|
|
142
|
-
type: "string",
|
|
143
|
-
description: "The directory path to search in"
|
|
144
|
-
}
|
|
145
|
-
}, ["pattern", "path"]),
|
|
146
|
-
N(m.VIEW_RANGE, "View a specific range of lines from a file", {
|
|
147
|
-
path: {
|
|
148
|
-
type: "string",
|
|
149
|
-
description: "The path to the file"
|
|
150
|
-
},
|
|
151
|
-
start: {
|
|
152
|
-
type: "number",
|
|
153
|
-
description: "The starting line number (1-indexed)"
|
|
154
|
-
},
|
|
155
|
-
end: {
|
|
156
|
-
type: "number",
|
|
157
|
-
description: "The ending line number (inclusive)"
|
|
158
|
-
}
|
|
159
|
-
}, [
|
|
160
|
-
"path",
|
|
161
|
-
"start",
|
|
162
|
-
"end"
|
|
163
|
-
])
|
|
164
|
-
], F = new Set([m.WRITE_FILE, m.RUN_SHELL]);
|
|
165
|
-
async function I(e, t) {
|
|
166
|
-
switch (e) {
|
|
167
|
-
case m.READ_FILE: return L(t.path);
|
|
168
|
-
case m.WRITE_FILE: return R(t.path, t.content);
|
|
169
|
-
case m.RUN_SHELL: return V(t.command);
|
|
170
|
-
case m.LIST_DIR: return H(t.path);
|
|
171
|
-
case m.GREP_SEARCH: return await U(t.pattern, t.path);
|
|
172
|
-
case m.VIEW_RANGE: return W(t.path, t.start, t.end);
|
|
173
|
-
default: return {
|
|
174
|
-
content: "",
|
|
175
|
-
error: `Unknown tool: ${e}`
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function L(t) {
|
|
180
|
-
try {
|
|
181
|
-
return e(t) ? { content: n(t, "utf8") } : {
|
|
182
|
-
content: "",
|
|
183
|
-
error: `File not found: ${t}`
|
|
184
|
-
};
|
|
185
|
-
} catch (e) {
|
|
186
|
-
return {
|
|
187
|
-
content: "",
|
|
188
|
-
error: `Failed to read file: ${e instanceof Error ? e.message : String(e)}`
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
function R(e, t) {
|
|
193
|
-
try {
|
|
194
|
-
return i(e, t, "utf8"), { content: `File written successfully: ${e}` };
|
|
195
|
-
} catch (e) {
|
|
196
|
-
return {
|
|
197
|
-
content: "",
|
|
198
|
-
error: `Failed to write file: ${e instanceof Error ? e.message : String(e)}`
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
var z = {
|
|
203
|
-
timeout: 3e4,
|
|
204
|
-
maxBuffer: 1024 * 1024
|
|
205
|
-
};
|
|
206
|
-
function B(e) {
|
|
207
|
-
return M(e, z);
|
|
208
|
-
}
|
|
209
|
-
async function V(e) {
|
|
210
|
-
try {
|
|
211
|
-
let { stdout: t, stderr: n } = await B(e);
|
|
212
|
-
return { content: t || n };
|
|
213
|
-
} catch (e) {
|
|
214
|
-
return {
|
|
215
|
-
content: "",
|
|
216
|
-
error: `Command failed: ${e instanceof Error ? e.message : String(e)}`
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function H(t) {
|
|
221
|
-
try {
|
|
222
|
-
return e(t) ? { content: r(t, { withFileTypes: !0 }).map((e) => `[${e.isDirectory() ? "d" : "f"}] ${e.name}`).join("\n") } : {
|
|
223
|
-
content: "",
|
|
224
|
-
error: `Directory not found: ${t}`
|
|
225
|
-
};
|
|
226
|
-
} catch (e) {
|
|
227
|
-
return {
|
|
228
|
-
content: "",
|
|
229
|
-
error: `Failed to list directory: ${e instanceof Error ? e.message : String(e)}`
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async function U(t, i) {
|
|
234
|
-
try {
|
|
235
|
-
let { stdout: e } = await B(`rg --line-number --no-heading --smart-case "${t.replace(/"/g, "\\\"")}" "${i}"`);
|
|
236
|
-
// v8 ignore next
|
|
237
|
-
return { content: e || "No matches found" };
|
|
238
|
-
} catch {}
|
|
239
|
-
try {
|
|
240
|
-
if (!e(i)) return {
|
|
241
|
-
content: "",
|
|
242
|
-
error: `Directory not found: ${i}`
|
|
243
|
-
};
|
|
244
|
-
let o = new RegExp(t, "g"), s = [];
|
|
245
|
-
function c(e) {
|
|
246
|
-
let t = r(e, { withFileTypes: !0 });
|
|
247
|
-
for (let r of t) {
|
|
248
|
-
let t = a(e, r.name);
|
|
249
|
-
if (r.isDirectory()) !r.name.startsWith(".") && r.name !== "node_modules" && c(t);
|
|
250
|
-
else if (r.isFile()) try {
|
|
251
|
-
let e = n(t, "utf8").split("\n");
|
|
252
|
-
for (let n = 0; n < e.length; n++) o.test(e[n]) && s.push(`${t}:${(n + 1).toString()}: ${e[n].trim()}`), o.lastIndex = 0;
|
|
253
|
-
} catch {}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return c(i), s.length === 0 ? { content: "No matches found" } : { content: s.join("\n") };
|
|
257
|
-
} catch (e) {
|
|
258
|
-
return {
|
|
259
|
-
content: "",
|
|
260
|
-
error: `Search failed: ${e instanceof Error ? e.message : String(e)}`
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function W(t, r, i) {
|
|
265
|
-
try {
|
|
266
|
-
if (!e(t)) return {
|
|
267
|
-
content: "",
|
|
268
|
-
error: `File not found: ${t}`
|
|
269
|
-
};
|
|
270
|
-
let a = n(t, "utf8").split("\n"), o = Math.max(0, r - 1), s = Math.min(a.length, i);
|
|
271
|
-
return o >= a.length || o > s ? {
|
|
272
|
-
content: "",
|
|
273
|
-
error: "Invalid line range"
|
|
274
|
-
} : { content: a.slice(o, s).join("\n") };
|
|
275
|
-
} catch (e) {
|
|
276
|
-
return {
|
|
277
|
-
content: "",
|
|
278
|
-
error: `Failed to view range: ${e instanceof Error ? e.message : String(e)}`
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
//#endregion
|
|
283
|
-
export { k as a, w as c, u as d, j as i, v as l, F as n, O as o, I as r, C as s, P as t, p as u };
|