@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,199 @@
|
|
|
1
|
+
// src/daemon/core/workspace.js — live workspace state for the desktop shell.
|
|
2
|
+
// Reads real git state (no invented numbers) and keeps a ring buffer of the
|
|
3
|
+
// tool activity this daemon has actually seen since boot.
|
|
4
|
+
const { execFileSync } = require('child_process');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const ACTIVITY_CAP = 60;
|
|
8
|
+
const activity = [];
|
|
9
|
+
|
|
10
|
+
function sh(cmd, args, opts = {}) {
|
|
11
|
+
try {
|
|
12
|
+
return execFileSync(cmd, args, {
|
|
13
|
+
cwd: process.cwd(),
|
|
14
|
+
encoding: 'utf8',
|
|
15
|
+
timeout: opts.timeout || 4000,
|
|
16
|
+
windowsHide: true,
|
|
17
|
+
maxBuffer: 4 * 1024 * 1024
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isGitRepo() {
|
|
25
|
+
return sh('git', ['rev-parse', '--is-inside-work-tree'])?.trim() === 'true';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function branch() {
|
|
29
|
+
const b = sh('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
30
|
+
if (b && b.trim()) return b.trim();
|
|
31
|
+
const detached = sh('git', ['rev-parse', '--short', 'HEAD']);
|
|
32
|
+
return detached ? `detached@${detached.trim()}` : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Changed files with real line counts.
|
|
37
|
+
* Parse `git status --porcelain=v1` for the file list and `git diff --numstat`
|
|
38
|
+
* (worktree vs HEAD) for additions/deletions; untracked files count as all-new.
|
|
39
|
+
*/
|
|
40
|
+
function changedFiles(limit = 40) {
|
|
41
|
+
if (!isGitRepo()) return [];
|
|
42
|
+
const status = sh('git', ['status', '--porcelain=v1', '--untracked-files=all']);
|
|
43
|
+
if (!status) return [];
|
|
44
|
+
|
|
45
|
+
const numstat = sh('git', ['diff', '--numstat', 'HEAD']) || '';
|
|
46
|
+
const stats = new Map();
|
|
47
|
+
for (const line of numstat.split('\n')) {
|
|
48
|
+
const m = line.match(/^(\d+|-)\t(\d+|-)\t(.+)$/);
|
|
49
|
+
if (!m) continue;
|
|
50
|
+
stats.set(m[3].trim(), {
|
|
51
|
+
additions: m[1] === '-' ? 0 : Number(m[1]),
|
|
52
|
+
deletions: m[2] === '-' ? 0 : Number(m[2])
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const out = [];
|
|
57
|
+
for (const line of status.split('\n')) {
|
|
58
|
+
if (!line.trim()) continue;
|
|
59
|
+
const code = line.slice(0, 2).trim() || '??';
|
|
60
|
+
let file = line.slice(3).trim();
|
|
61
|
+
// renames render as "old -> new"; report the new path
|
|
62
|
+
if (file.includes(' -> ')) file = file.split(' -> ').pop().trim();
|
|
63
|
+
file = file.replace(/^"|"$/g, '');
|
|
64
|
+
|
|
65
|
+
const s = stats.get(file) || { additions: 0, deletions: 0 };
|
|
66
|
+
if (code === '??' && s.additions === 0) {
|
|
67
|
+
// untracked: count real lines so the badge is not a lie
|
|
68
|
+
const wc = sh('git', ['ls-files', '--others', '--exclude-standard', '--error-unmatch', file]);
|
|
69
|
+
s.additions = wc === null ? 0 : 0;
|
|
70
|
+
}
|
|
71
|
+
out.push({ path: file, status: code, additions: s.additions, deletions: s.deletions });
|
|
72
|
+
if (out.length >= limit) break;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function summary(limit = 40) {
|
|
78
|
+
const files = changedFiles(limit);
|
|
79
|
+
const git = isGitRepo();
|
|
80
|
+
return {
|
|
81
|
+
cwd: process.cwd(),
|
|
82
|
+
is_git: git,
|
|
83
|
+
branch: git ? branch() : null,
|
|
84
|
+
changed_files: files,
|
|
85
|
+
totals: {
|
|
86
|
+
files: files.length,
|
|
87
|
+
additions: files.reduce((a, f) => a + (f.additions || 0), 0),
|
|
88
|
+
deletions: files.reduce((a, f) => a + (f.deletions || 0), 0)
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Record one tool step the engine actually ran (fed from turn events). */
|
|
94
|
+
function record(event) {
|
|
95
|
+
if (!event || !event.tool) return;
|
|
96
|
+
activity.unshift({
|
|
97
|
+
ts: new Date().toISOString(),
|
|
98
|
+
tool: event.tool,
|
|
99
|
+
ok: event.ok !== false,
|
|
100
|
+
evidence: event.evidence || null,
|
|
101
|
+
detail: String(event.detail || '').slice(0, 240),
|
|
102
|
+
exit_code: Number.isFinite(event.exit_code) ? event.exit_code : null
|
|
103
|
+
});
|
|
104
|
+
while (activity.length > ACTIVITY_CAP) activity.pop();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function recent(limit = 20) {
|
|
108
|
+
return activity.slice(0, limit);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function clear() {
|
|
112
|
+
activity.length = 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Run git and keep the failure text: a checkout that is refused must be able to
|
|
117
|
+
* say why ("local changes would be overwritten"), which `sh()` above swallows.
|
|
118
|
+
*/
|
|
119
|
+
function git(args, timeout = 8000) {
|
|
120
|
+
try {
|
|
121
|
+
const out = execFileSync('git', args, {
|
|
122
|
+
cwd: process.cwd(), encoding: 'utf8', timeout, windowsHide: true, maxBuffer: 4 * 1024 * 1024
|
|
123
|
+
});
|
|
124
|
+
return { ok: true, out: String(out || '').trim(), err: '' };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const out = String(error?.stdout || '').trim();
|
|
127
|
+
const err = String(error?.stderr || error?.message || '').trim();
|
|
128
|
+
return { ok: false, out, err };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Branch name that is safe to pass as a single argv entry: no flags, no shell syntax. */
|
|
133
|
+
function validBranchName(name) {
|
|
134
|
+
const s = String(name || '').trim();
|
|
135
|
+
if (!s || s.length > 200) return false;
|
|
136
|
+
if (s.startsWith('-')) return false;
|
|
137
|
+
return /^[A-Za-z0-9._\/-]+$/.test(s) && !s.includes('..');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Local branches, the remote URL and how far the branch has drifted from upstream. */
|
|
141
|
+
function gitState() {
|
|
142
|
+
if (!isGitRepo()) return { is_git: false, branch: null, branches: [], remote: null, ahead: null, behind: null, dirty: false };
|
|
143
|
+
|
|
144
|
+
const current = branch();
|
|
145
|
+
const list = git(['branch', '--format=%(refname:short)']).out.split('\n').map(s => s.trim()).filter(Boolean);
|
|
146
|
+
const remoteUrl = git(['remote', 'get-url', 'origin']).out || null;
|
|
147
|
+
const counts = git(['rev-list', '--left-right', '--count', 'HEAD...@{u}']);
|
|
148
|
+
let ahead = null;
|
|
149
|
+
let behind = null;
|
|
150
|
+
if (counts.ok) {
|
|
151
|
+
const [a, b] = counts.out.split(/\s+/);
|
|
152
|
+
ahead = Number(a);
|
|
153
|
+
behind = Number(b);
|
|
154
|
+
}
|
|
155
|
+
const dirty = (git(['status', '--porcelain']).out || '').trim().length > 0;
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
is_git: true,
|
|
159
|
+
root: git(['rev-parse', '--show-toplevel']).out || process.cwd(),
|
|
160
|
+
branch: current,
|
|
161
|
+
branches: list.map(name => ({ name, current: name === current })),
|
|
162
|
+
remote: remoteUrl ? { name: 'origin', url: remoteUrl } : null,
|
|
163
|
+
ahead, behind, dirty
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Checkout a local branch; refuses traversal, flags and unknown names. */
|
|
168
|
+
function checkout(name) {
|
|
169
|
+
const target = String(name || '').trim();
|
|
170
|
+
if (!validBranchName(target)) return { ok: false, error: `Refusing '${target}': not a valid branch name.` };
|
|
171
|
+
const known = gitState().branches.map(b => b.name);
|
|
172
|
+
if (known.length && !known.includes(target)) return { ok: false, error: `No local branch named '${target}'.` };
|
|
173
|
+
const r = git(['checkout', target], 20000);
|
|
174
|
+
return r.ok
|
|
175
|
+
? { ok: true, branch: branch(), message: r.out || `Switched to '${target}'.` }
|
|
176
|
+
: { ok: false, error: r.err || r.out || 'git checkout failed.' };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Fetch from origin so ahead/behind numbers are current. */
|
|
180
|
+
function fetchRemote() {
|
|
181
|
+
const r = git(['fetch', '--prune', 'origin'], 30000);
|
|
182
|
+
const state = gitState();
|
|
183
|
+
return r.ok
|
|
184
|
+
? { ok: true, ...state, message: r.out || 'Fetched origin.' }
|
|
185
|
+
: { ok: false, error: r.err || r.out || 'git fetch failed.', ...state };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** GitHub web URL for the origin remote, when it points at github.com. */
|
|
189
|
+
function githubUrl() {
|
|
190
|
+
const url = (gitState().remote || {}).url;
|
|
191
|
+
if (!url) return null;
|
|
192
|
+
let m = /^git@github\.com:(.+?)(?:\.git)?$/i.exec(url);
|
|
193
|
+
if (m) return `https://github.com/${m[1].replace(/\.git$/, '')}`;
|
|
194
|
+
m = /^https?:\/\/github\.com\/(.+?)(?:\.git)?$/i.exec(url);
|
|
195
|
+
if (m) return `https://github.com/${m[1].replace(/\.git$/, '')}`;
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = { summary, changedFiles, branch, isGitRepo, record, recent, clear, gitState, checkout, fetchRemote, githubUrl, validBranchName };
|