netheriteai-code 0.3.0 → 0.3.3
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/package.json +1 -1
- package/src/cli.js +50 -73
- package/src/ollama.js +1 -1
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import readline from "node:readline";
|
|
4
|
-
import { execFile } from "node:child_process";
|
|
4
|
+
import { execFile, execSync, spawn } from "node:child_process";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { runAgentTurn } from "./agent.js";
|
|
7
7
|
import { listModels, pickDefaultModel } from "./ollama.js";
|
|
@@ -11,6 +11,55 @@ import { printTable, resolveWorkspaceRoot } from "./utils.js";
|
|
|
11
11
|
|
|
12
12
|
const execFileAsync = promisify(execFile);
|
|
13
13
|
|
|
14
|
+
const VERSION = "0.3.3";
|
|
15
|
+
|
|
16
|
+
async function handleAutoUpdate() {
|
|
17
|
+
try {
|
|
18
|
+
const latest = execSync("npm view netheriteai-code version", {
|
|
19
|
+
encoding: "utf8",
|
|
20
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
21
|
+
timeout: 3000,
|
|
22
|
+
}).trim();
|
|
23
|
+
|
|
24
|
+
if (latest && latest !== VERSION) {
|
|
25
|
+
const cols = process.stdout.columns || 80;
|
|
26
|
+
const rows = process.stdout.rows || 24;
|
|
27
|
+
const msg = "Updating NetheriteAI:Code...";
|
|
28
|
+
const x = Math.max(1, Math.floor((cols - msg.length) / 2));
|
|
29
|
+
const y = Math.max(1, Math.floor(rows / 2));
|
|
30
|
+
|
|
31
|
+
process.stdout.write("\u001b[?1049h\u001b[2J\u001b[H");
|
|
32
|
+
process.stdout.write(`\u001b[${y};${x}H\u001b[1m${msg}\u001b[0m`);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
execSync("npm install -g netheriteai-code", { stdio: "ignore" });
|
|
36
|
+
} catch {
|
|
37
|
+
if (process.platform !== "win32") {
|
|
38
|
+
process.stdout.write("\u001b[2J\u001b[H");
|
|
39
|
+
const sudoMsg = "Permission required. Please enter password to update:";
|
|
40
|
+
const sx = Math.max(1, Math.floor((cols - sudoMsg.length) / 2));
|
|
41
|
+
process.stdout.write(`\u001b[${y};${sx}H\u001b[1m${sudoMsg}\u001b[0m\n\n`);
|
|
42
|
+
execSync("sudo npm install -g netheriteai-code", { stdio: "inherit" });
|
|
43
|
+
} else {
|
|
44
|
+
process.stdout.write("\u001b[?1049l");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
process.stdout.write("\u001b[2J\u001b[H");
|
|
50
|
+
const doneMsg = "Update complete! Restarting...";
|
|
51
|
+
const dx = Math.max(1, Math.floor((cols - doneMsg.length) / 2));
|
|
52
|
+
process.stdout.write(`\u001b[${y};${dx}H\u001b[1m${doneMsg}\u001b[0m`);
|
|
53
|
+
process.stdout.write("\u001b[?1049l");
|
|
54
|
+
|
|
55
|
+
spawn(process.argv[0], process.argv.slice(1), { stdio: "inherit", detached: false });
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// Silent fail
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
14
63
|
function displayModelName(model) {
|
|
15
64
|
const name = String(model || "");
|
|
16
65
|
if (name.toLowerCase().includes("glm5") || name.toLowerCase().includes("glm-5")) return "NetheriteAI:Code";
|
|
@@ -402,77 +451,5 @@ export async function main() {
|
|
|
402
451
|
return;
|
|
403
452
|
}
|
|
404
453
|
|
|
405
|
-
printHelp();
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
await submit(prompt);
|
|
410
|
-
rl.prompt();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
export async function main() {
|
|
415
|
-
const { positional, flags } = parseArgs(process.argv.slice(2));
|
|
416
|
-
const command = positional[0] || "tui";
|
|
417
|
-
const requestedWorkspaceRoot = resolveWorkspaceRoot(flags.dir || flags.d || process.cwd());
|
|
418
|
-
|
|
419
|
-
if (!fs.existsSync(requestedWorkspaceRoot)) {
|
|
420
|
-
throw new Error(`Workspace does not exist: ${requestedWorkspaceRoot}`);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
if (command === "help" || flags.help || flags.h) {
|
|
424
|
-
printHelp();
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
if (command === "tools") {
|
|
429
|
-
printToolList();
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
let session = null;
|
|
434
|
-
let workspaceRoot = requestedWorkspaceRoot;
|
|
435
|
-
|
|
436
|
-
if (command === "session") {
|
|
437
|
-
const sessionId = positional[1];
|
|
438
|
-
if (!sessionId) {
|
|
439
|
-
throw new Error("Usage: netheritecode session <id>");
|
|
440
|
-
}
|
|
441
|
-
session = loadSessionById(sessionId);
|
|
442
|
-
if (!session) {
|
|
443
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
444
|
-
}
|
|
445
|
-
workspaceRoot = session.workspaceRoot;
|
|
446
|
-
} else {
|
|
447
|
-
session = createSession(workspaceRoot);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const model = await resolveModel(flags.model || flags.m);
|
|
451
|
-
setSelectedModel(model);
|
|
452
|
-
|
|
453
|
-
if (command === "chat") {
|
|
454
|
-
await runChatSession({ workspaceRoot, model, useTui: false, session });
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (command === "tui" || command === "session") {
|
|
459
|
-
await runChatSession({ workspaceRoot, model, useTui: true, session });
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
if (!command.startsWith("-")) {
|
|
464
|
-
const prompt = positional.join(" ");
|
|
465
|
-
const result = await runAgentTurn({
|
|
466
|
-
workspaceRoot,
|
|
467
|
-
model,
|
|
468
|
-
history: session.messages,
|
|
469
|
-
userPrompt: prompt,
|
|
470
|
-
});
|
|
471
|
-
session.messages = result.messages;
|
|
472
|
-
saveSession(session);
|
|
473
|
-
console.log(result.reply);
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
454
|
printHelp();
|
|
478
455
|
}
|
package/src/ollama.js
CHANGED
|
@@ -132,7 +132,7 @@ function createTaggedStreamParser({ onContent, onReasoning }) {
|
|
|
132
132
|
|
|
133
133
|
export async function chatStream({ model, messages, tools, onChunk, onReasoningChunk, signal }) {
|
|
134
134
|
const body = { model, messages, stream: true };
|
|
135
|
-
if (tools && tools.length) body.tools = tools;
|
|
135
|
+
if (tools && tools.length && model !== "glm-5:cloud") body.tools = tools;
|
|
136
136
|
|
|
137
137
|
const response = await request("/api/chat", body, signal);
|
|
138
138
|
|