harma-kit 0.0.0-stage → 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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/bin/harma.mjs +4 -0
- package/data/catalog.json +1085 -0
- package/docs/agents-and-sessions.md +55 -0
- package/docs/choosing-models.md +83 -0
- package/docs/commands.md +103 -0
- package/docs/development.md +42 -0
- package/docs/how-harma-decides.md +71 -0
- package/docs/troubleshooting.md +41 -0
- package/package.json +49 -4
- package/skill/SKILL.md +122 -0
- package/skill/references/commands.md +49 -0
- package/skill/references/troubleshooting.md +37 -0
- package/src/backends.mjs +233 -0
- package/src/catalog.mjs +54 -0
- package/src/cli.mjs +98 -0
- package/src/commands.mjs +680 -0
- package/src/credits.mjs +101 -0
- package/src/harness.mjs +94 -0
- package/src/install.mjs +106 -0
- package/src/inventory.mjs +72 -0
- package/src/rank.mjs +102 -0
- package/src/roster.mjs +177 -0
- package/src/route.mjs +69 -0
- package/src/state.mjs +134 -0
- package/src/tui.mjs +345 -0
- package/src/usage.mjs +127 -0
- package/src/util.mjs +90 -0
package/src/util.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readFileSync, existsSync, accessSync, constants } from 'node:fs';
|
|
3
|
+
import { delimiter, join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const now = () => new Date().toISOString();
|
|
6
|
+
|
|
7
|
+
/** Run a program without a shell. Never throws: returns {ok, code, stdout, stderr}. */
|
|
8
|
+
export function run(cmd, args = [], { timeout = 60_000, env, cwd, input } = {}) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const child = execFile(cmd, args, {
|
|
11
|
+
timeout, env: env ?? process.env, cwd, maxBuffer: 64 * 1024 * 1024,
|
|
12
|
+
}, (err, stdout, stderr) => {
|
|
13
|
+
resolve({
|
|
14
|
+
ok: !err,
|
|
15
|
+
code: err ? (typeof err.code === 'number' ? err.code : 1) : 0,
|
|
16
|
+
stdout: String(stdout ?? ''), stderr: String(stderr ?? ''),
|
|
17
|
+
error: err && typeof err.code === 'string' ? err.code : undefined,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
if (input !== undefined) child.stdin.end(input);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Absolute path of a program on PATH, or null. */
|
|
25
|
+
export function which(bin, env = process.env) {
|
|
26
|
+
for (const dir of (env.PATH ?? '').split(delimiter)) {
|
|
27
|
+
if (!dir) continue;
|
|
28
|
+
const p = join(dir, bin);
|
|
29
|
+
try { accessSync(p, constants.X_OK); return p; } catch { /* next */ }
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readJson(path, fallback = null) {
|
|
35
|
+
try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return fallback; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function parseJson(text) {
|
|
39
|
+
try { return JSON.parse(text); } catch { return null; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Read a JSONL file into an array of objects, skipping bad lines. */
|
|
43
|
+
export function readJsonl(path) {
|
|
44
|
+
if (!existsSync(path)) return [];
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const line of readFileSync(path, 'utf8').split('\n')) {
|
|
47
|
+
if (!line.trim()) continue;
|
|
48
|
+
try { out.push(JSON.parse(line)); } catch { /* skip */ }
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Minimal fixed-width table for terminal output. */
|
|
54
|
+
export function table(rows, columns) {
|
|
55
|
+
if (!rows.length) return '(nessuna riga)';
|
|
56
|
+
const cols = columns ?? Object.keys(rows[0]);
|
|
57
|
+
const cell = (v) => (v === null || v === undefined ? '—' : String(v));
|
|
58
|
+
const widths = cols.map((c) => Math.max(c.length, ...rows.map((r) => cell(r[c]).length)));
|
|
59
|
+
const line = (vals) => vals.map((v, i) => v.padEnd(widths[i])).join(' ').trimEnd();
|
|
60
|
+
return [line(cols), line(widths.map((w) => '-'.repeat(w))), ...rows.map((r) => line(cols.map((c) => cell(r[c]))))].join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const EFFORT_ORDER = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'];
|
|
64
|
+
|
|
65
|
+
/** Keys that identify a person or account; stripped from anything harma stores or prints. */
|
|
66
|
+
const IDENTITY_KEYS = new Set([
|
|
67
|
+
'accountEmail', 'signedInEmail', 'email', 'accountID', 'accountId', 'identity',
|
|
68
|
+
'userId', 'user_id', 'organizationId', 'orgId', 'apiKey', 'api_key', 'token', 'cookie',
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
export function stripIdentity(value) {
|
|
72
|
+
if (Array.isArray(value)) return value.map(stripIdentity);
|
|
73
|
+
if (value && typeof value === 'object') {
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [k, v] of Object.entries(value)) {
|
|
76
|
+
if (IDENTITY_KEYS.has(k)) continue;
|
|
77
|
+
out[k] = stripIdentity(v);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class HarmaError extends Error {
|
|
85
|
+
constructor(message, { exitCode = 1, hint } = {}) {
|
|
86
|
+
super(message);
|
|
87
|
+
this.exitCode = exitCode;
|
|
88
|
+
this.hint = hint;
|
|
89
|
+
}
|
|
90
|
+
}
|