netheriteai-code 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.
- package/README.md +48 -0
- package/bin/netheriteai-code.js +8 -0
- package/hi.txt +1 -0
- package/package.json +18 -0
- package/src/agent.js +285 -0
- package/src/cli.js +405 -0
- package/src/ollama.js +252 -0
- package/src/state.js +100 -0
- package/src/tools.js +455 -0
- package/src/tui.js +1490 -0
- package/src/utils.js +83 -0
package/src/utils.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export function resolveWorkspaceRoot(input) {
|
|
6
|
+
return path.resolve(input || process.cwd());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ensureDir(dirPath) {
|
|
10
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getAppDir() {
|
|
14
|
+
const dir = path.join(os.homedir(), ".netheriteai-code");
|
|
15
|
+
ensureDir(dir);
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getStateFile() {
|
|
20
|
+
return path.join(getAppDir(), "state.json");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function loadJson(filePath, fallback) {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
26
|
+
} catch {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function saveJson(filePath, value) {
|
|
32
|
+
ensureDir(path.dirname(filePath));
|
|
33
|
+
fs.writeFileSync(filePath, JSON.stringify(value, null, 2));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function clampText(input, max = 12000) {
|
|
37
|
+
if (input.length <= max) return input;
|
|
38
|
+
return `${input.slice(0, max)}\n... [truncated ${input.length - max} chars]`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function formatBytes(bytes) {
|
|
42
|
+
if (!Number.isFinite(bytes) || bytes < 1) return "0 B";
|
|
43
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
44
|
+
let value = bytes;
|
|
45
|
+
let index = 0;
|
|
46
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
47
|
+
value /= 1024;
|
|
48
|
+
index += 1;
|
|
49
|
+
}
|
|
50
|
+
return `${value.toFixed(value >= 10 || index === 0 ? 0 : 1)} ${units[index]}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function relativeToRoot(root, target) {
|
|
54
|
+
return path.relative(root, target) || ".";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isInsideRoot(root, target) {
|
|
58
|
+
const rel = path.relative(root, target);
|
|
59
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function toAbsoluteInsideRoot(root, candidate) {
|
|
63
|
+
const absolute = path.resolve(root, candidate);
|
|
64
|
+
if (!isInsideRoot(root, absolute)) {
|
|
65
|
+
throw new Error(`Path escapes workspace root: ${candidate}`);
|
|
66
|
+
}
|
|
67
|
+
return absolute;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function printTable(rows) {
|
|
71
|
+
if (!rows.length) return "";
|
|
72
|
+
const widths = [];
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
row.forEach((cell, index) => {
|
|
75
|
+
widths[index] = Math.max(widths[index] || 0, String(cell).length);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return rows
|
|
79
|
+
.map((row) =>
|
|
80
|
+
row.map((cell, index) => String(cell).padEnd(widths[index])).join(" "),
|
|
81
|
+
)
|
|
82
|
+
.join("\n");
|
|
83
|
+
}
|