@arthovlabs/liber 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +348 -2
- package/bin/liber +706 -0
- package/bin/liber-tui +244 -0
- package/bin/liber-tui.py +825 -0
- package/bin/liberd-entry +17 -0
- package/liber.yaml +84 -0
- package/package.json +43 -4
- package/resources/icons/appIcon.png +0 -0
- package/resources/icons/appIcon.svg +20 -0
- package/resources/icons/appIcon@512.png +0 -0
- package/resources/icons/atom-transparent-256.png +0 -0
- package/resources/icons/atom-transparent.png +0 -0
- package/resources/icons/atom-transparent.svg +19 -0
- package/resources/icons/make-atom.js +168 -0
- package/src/cli/ui.js +520 -0
- package/src/daemon/core/auth.js +217 -0
- package/src/daemon/core/automations.js +130 -0
- package/src/daemon/core/budget.js +145 -0
- package/src/daemon/core/circuit-breaker.js +31 -0
- package/src/daemon/core/config-apply.js +223 -0
- package/src/daemon/core/connectors.js +131 -0
- package/src/daemon/core/engine.js +1029 -0
- package/src/daemon/core/evidence.js +306 -0
- package/src/daemon/core/executor.js +10 -0
- package/src/daemon/core/grounding.js +420 -0
- package/src/daemon/core/injection.js +24 -0
- package/src/daemon/core/journal.js +81 -0
- package/src/daemon/core/liber-soul.js +157 -0
- package/src/daemon/core/lock.js +32 -0
- package/src/daemon/core/memory.js +106 -0
- package/src/daemon/core/model-switch.js +58 -0
- package/src/daemon/core/policy.js +102 -0
- package/src/daemon/core/providers.js +503 -0
- package/src/daemon/core/registry.js +356 -0
- package/src/daemon/core/secrets.js +35 -0
- package/src/daemon/core/skills.js +264 -0
- package/src/daemon/core/tools/browser-tool.js +280 -0
- package/src/daemon/core/tools/file-tools.js +277 -0
- package/src/daemon/core/tools/memory-tool.js +127 -0
- package/src/daemon/core/tools/skill-tool.js +44 -0
- package/src/daemon/core/tools/task-tool.js +41 -0
- package/src/daemon/core/tools/terminal-tool.js +449 -0
- package/src/daemon/core/tools/todo-tool.js +100 -0
- package/src/daemon/core/tools/web-tool.js +181 -0
- package/src/daemon/core/trace.js +40 -0
- package/src/daemon/core/validate.js +105 -0
- package/src/daemon/core/vault.js +158 -0
- package/src/daemon/core/verifier.js +98 -0
- package/src/daemon/core/voice.js +83 -0
- package/src/daemon/core/workspace.js +199 -0
- package/src/daemon/liberd.js +1343 -0
- package/src/daemon/llm/adapters/anthropic-adapter.js +190 -0
- package/src/daemon/llm/adapters/gemini-adapter.js +148 -0
- package/src/daemon/llm/adapters/ollama-adapter.js +74 -0
- package/src/daemon/llm/adapters/openai-adapter.js +148 -0
- package/src/daemon/llm/base.js +31 -0
- package/src/daemon/llm/manager.js +134 -0
- package/src/utils/config-loader.js +109 -0
- package/src/utils/logger.js +56 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// src/daemon/core/evidence.js — Receipt ledger: every tool result becomes auditable evidence.
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const KIND_BY_TOOL = {
|
|
6
|
+
read_file: 'read',
|
|
7
|
+
write_file: 'write',
|
|
8
|
+
patch: 'patch',
|
|
9
|
+
search_files: 'search',
|
|
10
|
+
terminal: 'command',
|
|
11
|
+
memory: 'memory',
|
|
12
|
+
todo_list: 'todo',
|
|
13
|
+
fetch_url: 'fetch',
|
|
14
|
+
web_search: 'search',
|
|
15
|
+
task: 'task',
|
|
16
|
+
tasks: 'task'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Verification-by-execution: a green test/build/lint run proves the tree is sound.
|
|
20
|
+
const EXEC_VERIFICATION = /\b(npm|pnpm|yarn|bun)\s+(run\s+)?(test|build|lint|typecheck|check)\b|\b(node\s+--test|jest|vitest|mocha|pytest|go\s+test|cargo\s+test|dotnet\s+test|tsc|eslint|ruff|mypy)\b/i;
|
|
21
|
+
|
|
22
|
+
function hashOf(value) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = typeof value === 'string' ? value : JSON.stringify(value);
|
|
25
|
+
return crypto.createHash('sha256').update(raw || '').digest('hex').slice(0, 12);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normPath(p) {
|
|
32
|
+
if (!p) return null;
|
|
33
|
+
const raw = String(p).replace(/[\\/]+/g, path.sep);
|
|
34
|
+
try {
|
|
35
|
+
return path.resolve(process.cwd(), raw).replace(/\\/g, '/').toLowerCase();
|
|
36
|
+
} catch {
|
|
37
|
+
return raw.replace(/\\/g, '/').toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function basenameOf(p) {
|
|
42
|
+
const n = normPath(p);
|
|
43
|
+
return n ? n.split('/').pop() : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class EvidenceLedger {
|
|
47
|
+
constructor(agentId = 'agent') {
|
|
48
|
+
this.agentId = agentId;
|
|
49
|
+
this.entries = [];
|
|
50
|
+
this.seq = 0;
|
|
51
|
+
// path -> { path, evId, tool } : mutations awaiting read-back / execution proof
|
|
52
|
+
this.pendingVerification = new Map();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
nextId() {
|
|
56
|
+
return `E${++this.seq}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
classify(tool) {
|
|
60
|
+
return KIND_BY_TOOL[tool] || 'other';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isOk(kind, result, meta) {
|
|
64
|
+
if (!result || meta.denied) return false;
|
|
65
|
+
if (typeof result === 'object' && result.error) return false;
|
|
66
|
+
if (result.validation_failed) return false;
|
|
67
|
+
if (kind === 'command') return result.exit_code === 0;
|
|
68
|
+
if (kind === 'read') return !result.error && typeof result.content === 'string';
|
|
69
|
+
if (kind === 'search') return !result.error;
|
|
70
|
+
if (kind === 'write') return result.success === true;
|
|
71
|
+
if (kind === 'patch') return result.success === true;
|
|
72
|
+
if (kind === 'fetch') return typeof result.status === 'number' && result.status >= 200 && result.status < 400;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
targetOf(kind, args, result) {
|
|
77
|
+
switch (kind) {
|
|
78
|
+
case 'read':
|
|
79
|
+
case 'write':
|
|
80
|
+
case 'patch':
|
|
81
|
+
return args.path || null;
|
|
82
|
+
case 'command':
|
|
83
|
+
return args.command || null;
|
|
84
|
+
case 'search':
|
|
85
|
+
return args.pattern || args.query || null;
|
|
86
|
+
case 'fetch':
|
|
87
|
+
return result.final_url || args.url || null;
|
|
88
|
+
case 'memory':
|
|
89
|
+
return args.key || args.action || null;
|
|
90
|
+
default:
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
excerptOf(kind, result) {
|
|
96
|
+
if (!result || typeof result !== 'object') return String(result || '').slice(0, 200);
|
|
97
|
+
switch (kind) {
|
|
98
|
+
case 'read':
|
|
99
|
+
return `${result.lines_read ?? '?'} lines · total ${result.total_lines ?? '?'}`;
|
|
100
|
+
case 'write':
|
|
101
|
+
return `${result.bytes_written ?? 0} bytes written`;
|
|
102
|
+
case 'patch':
|
|
103
|
+
return `strategy=${result.strategy || '?'} · ${result.occurrences_replaced ?? 0} replaced`;
|
|
104
|
+
case 'search':
|
|
105
|
+
return `${result.total_found ?? result.total ?? 0} matches`;
|
|
106
|
+
case 'command':
|
|
107
|
+
return `exit ${result.exit_code} · ${String(result.output || result.error || '').replace(/\s+/g, ' ').slice(0, 160)}`;
|
|
108
|
+
case 'fetch':
|
|
109
|
+
return `HTTP ${result.status} · ${result.chars ?? 0} chars`;
|
|
110
|
+
case 'memory':
|
|
111
|
+
return `${result.message || (result.found === false ? 'not found' : 'ok')}`;
|
|
112
|
+
default:
|
|
113
|
+
return String(result.message || result.error || JSON.stringify(result)).slice(0, 160);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Verbatim evidence for the semantic auditor (bounded, head AND tail kept).
|
|
119
|
+
* Head-only truncation was a root cause of false semantic failures: test
|
|
120
|
+
* summaries ("pass 145") sit at the END of long command output.
|
|
121
|
+
*/
|
|
122
|
+
detailOf(kind, result) {
|
|
123
|
+
if (!result || typeof result !== 'object') return String(result || '').slice(0, 700);
|
|
124
|
+
const headTail = (text, head, tail) => {
|
|
125
|
+
const s = String(text || '');
|
|
126
|
+
if (s.length <= head + tail + 24) return s;
|
|
127
|
+
return `${s.slice(0, head)}\n… [${s.length - head - tail} chars omitted] …\n${s.slice(-tail)}`;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* A JSON API answer has to keep the fields the model will cite, and a raw
|
|
131
|
+
* JSON.stringify puts them behind whatever the API ordered first. Flatten
|
|
132
|
+
* every scalar leaf to `path=value` so "default_branch=main" is present no
|
|
133
|
+
* matter where the object put it.
|
|
134
|
+
*/
|
|
135
|
+
const flatten = (value, prefix = '', out = []) => {
|
|
136
|
+
if (out.length > 400) return out;
|
|
137
|
+
if (value === null || value === undefined) { out.push(`${prefix}=${value}`); return out; }
|
|
138
|
+
if (Array.isArray(value)) {
|
|
139
|
+
value.slice(0, 25).forEach((v, i) => flatten(v, `${prefix}[${i}]`, out));
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
if (typeof value === 'object') {
|
|
143
|
+
for (const [k, v] of Object.entries(value)) flatten(v, prefix ? `${prefix}.${k}` : k, out);
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
out.push(`${prefix}=${value}`);
|
|
147
|
+
return out;
|
|
148
|
+
};
|
|
149
|
+
const asJson = (text) => {
|
|
150
|
+
try { const parsed = JSON.parse(String(text)); return flatten(parsed).join('\n'); } catch { return null; }
|
|
151
|
+
};
|
|
152
|
+
switch (kind) {
|
|
153
|
+
case 'read':
|
|
154
|
+
return headTail(result.content || '', 1400, 1000);
|
|
155
|
+
case 'command':
|
|
156
|
+
return headTail(result.output || result.error || '', 1200, 1200);
|
|
157
|
+
case 'write':
|
|
158
|
+
return String(result.message || '').slice(0, 400);
|
|
159
|
+
case 'patch':
|
|
160
|
+
return headTail(result.diff_preview || result.message || '', 1000, 500);
|
|
161
|
+
case 'search':
|
|
162
|
+
return JSON.stringify((result.matches || result.results || []).slice(0, 5)).slice(0, 700);
|
|
163
|
+
case 'fetch': {
|
|
164
|
+
const flat = asJson(result.content);
|
|
165
|
+
if (flat) return headTail(flat, 3000, 1500);
|
|
166
|
+
return headTail(result.content || '', 1000, 600);
|
|
167
|
+
}
|
|
168
|
+
case 'memory':
|
|
169
|
+
return JSON.stringify(result).slice(0, 400);
|
|
170
|
+
default: {
|
|
171
|
+
if (result.message || result.error) return headTail(result.message || result.error, 400, 200);
|
|
172
|
+
const flat = flatten(result).join('\n');
|
|
173
|
+
return headTail(flat, 3000, 1500);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
record(tool, args = {}, result = {}, meta = {}) {
|
|
179
|
+
const kind = this.classify(tool);
|
|
180
|
+
const ok = this.isOk(kind, result, meta);
|
|
181
|
+
const entry = {
|
|
182
|
+
id: this.nextId(),
|
|
183
|
+
tool,
|
|
184
|
+
kind,
|
|
185
|
+
ok,
|
|
186
|
+
target: this.targetOf(kind, args, result),
|
|
187
|
+
ts: Date.now(),
|
|
188
|
+
exit_code: typeof (result && result.exit_code) === 'number' ? result.exit_code : null,
|
|
189
|
+
hash: hashOf(result),
|
|
190
|
+
excerpt: this.excerptOf(kind, result),
|
|
191
|
+
detail: this.detailOf(kind, result),
|
|
192
|
+
meta: { ...meta }
|
|
193
|
+
};
|
|
194
|
+
this.entries.push(entry);
|
|
195
|
+
if (ok) this.trackVerification(entry, args);
|
|
196
|
+
return entry;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
trackVerification(entry, args) {
|
|
200
|
+
const p = args.path ? normPath(args.path) : null;
|
|
201
|
+
|
|
202
|
+
if (entry.kind === 'write' || entry.kind === 'patch') {
|
|
203
|
+
if (p) this.pendingVerification.set(p, { path: args.path, evId: entry.id, tool: entry.tool });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (entry.kind === 'read' && p) {
|
|
208
|
+
this.pendingVerification.delete(p);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (entry.kind === 'command') {
|
|
213
|
+
const cmd = String(args.command || '');
|
|
214
|
+
if (EXEC_VERIFICATION.test(cmd)) {
|
|
215
|
+
this.pendingVerification.clear();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (const [key, pending] of this.pendingVerification.entries()) {
|
|
219
|
+
const base = basenameOf(pending.path);
|
|
220
|
+
const normalizedCmd = cmd.replace(/\\/g, '/').toLowerCase();
|
|
221
|
+
if ((base && normalizedCmd.includes(base.toLowerCase())) || normalizedCmd.includes(key)) {
|
|
222
|
+
this.pendingVerification.delete(key);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
get(id) {
|
|
229
|
+
const n = String(id).replace(/^E/i, '');
|
|
230
|
+
return this.entries.find(e => e.id === `E${n}`) || null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
hasReceipt(id) {
|
|
234
|
+
return !!this.get(id);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
lastMutation() {
|
|
238
|
+
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
239
|
+
const e = this.entries[i];
|
|
240
|
+
if (e.ok && (e.kind === 'write' || e.kind === 'patch')) return e;
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
mutationCount() {
|
|
246
|
+
return this.entries.filter(e => e.ok && (e.kind === 'write' || e.kind === 'patch')).length;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
okEntries() {
|
|
250
|
+
return this.entries.filter(e => e.ok);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
unresolvedPending() {
|
|
254
|
+
return Array.from(this.pendingVerification.values());
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Compact digest injected into the system prompt every iteration.
|
|
259
|
+
*/
|
|
260
|
+
digest(maxEntries = 24) {
|
|
261
|
+
const list = this.entries.slice(-maxEntries);
|
|
262
|
+
if (list.length === 0) return '(empty — no tool receipts yet this turn)';
|
|
263
|
+
return list
|
|
264
|
+
.map(e => `${e.id} ${e.tool} ${e.ok ? 'ok' : 'FAILED'}${e.exit_code !== null ? `(exit ${e.exit_code})` : ''} — ${String(e.target || '').slice(0, 90)} — ${e.excerpt}`)
|
|
265
|
+
.join('\n');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
toJSON() {
|
|
269
|
+
return {
|
|
270
|
+
agentId: this.agentId,
|
|
271
|
+
receipts: this.entries.map(e => ({
|
|
272
|
+
id: e.id,
|
|
273
|
+
tool: e.tool,
|
|
274
|
+
kind: e.kind,
|
|
275
|
+
ok: e.ok,
|
|
276
|
+
target: e.target,
|
|
277
|
+
exit_code: e.exit_code,
|
|
278
|
+
hash: e.hash,
|
|
279
|
+
excerpt: e.excerpt,
|
|
280
|
+
detail: e.detail
|
|
281
|
+
})),
|
|
282
|
+
pending_verification: this.unresolvedPending()
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
static fromJSON(data = {}) {
|
|
287
|
+
const ledger = new EvidenceLedger(data.agentId || 'agent');
|
|
288
|
+
ledger.entries = Array.isArray(data.receipts) ? data.receipts.map(e => ({ ...e, meta: e.meta || {} })) : [];
|
|
289
|
+
ledger.seq = ledger.entries.reduce(
|
|
290
|
+
(max, e) => Math.max(max, parseInt(String(e.id).replace(/^E/i, ''), 10) || 0),
|
|
291
|
+
0
|
|
292
|
+
);
|
|
293
|
+
ledger.pendingVerification = new Map(
|
|
294
|
+
(Array.isArray(data.pending_verification) ? data.pending_verification : [])
|
|
295
|
+
.filter(p => p && p.path)
|
|
296
|
+
.map(p => [normPath(p.path), p])
|
|
297
|
+
);
|
|
298
|
+
return ledger;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
module.exports = {
|
|
303
|
+
EvidenceLedger,
|
|
304
|
+
hashOf,
|
|
305
|
+
normPath
|
|
306
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/daemon/core/executor.js — Backward compatibility facade for terminal-tool
|
|
2
|
+
const { runTerminal } = require('./tools/terminal-tool');
|
|
3
|
+
|
|
4
|
+
class ToolExecutor {
|
|
5
|
+
async execute(command) {
|
|
6
|
+
return await runTerminal({ command });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = new ToolExecutor();
|