aegiscode 7.0.25 → 7.0.26
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 +7 -3
- package/scripts/check.mjs +52 -1
- package/scripts/demo.mjs +94 -1
- package/scripts/predist.mjs +75 -1
- package/scripts/runtests.mjs +56 -1
- package/scripts/seal-gate.mjs +74 -1
- package/src/agents.js +139 -1
- package/src/app.js +2957 -1
- package/src/art.js +289 -1
- package/src/chatflow.js +3023 -1
- package/src/checkpoint.js +90 -1
- package/src/clipboard.js +424 -1
- package/src/cloudsync.js +528 -1
- package/src/commands.js +4089 -1
- package/src/config.js +581 -1
- package/src/connect.js +349 -1
- package/src/credentials.js +33 -1
- package/src/deps.js +232 -1
- package/src/devrun.js +187 -1
- package/src/diff.js +333 -1
- package/src/diffview.js +296 -1
- package/src/engine.js +297 -1
- package/src/entitlement.js +355 -1
- package/src/events.js +707 -1
- package/src/export.js +67 -1
- package/src/filepreview.js +153 -1
- package/src/fingerprint.js +592 -1
- package/src/format.js +259 -1
- package/src/fuzzy.js +119 -1
- package/src/history.js +423 -1
- package/src/init.js +175 -1
- package/src/input.js +139 -1
- package/src/keys.js +183 -1
- package/src/markdown.js +306 -1
- package/src/models.js +507 -1
- package/src/naming.js +57 -1
- package/src/overlays.js +462 -1
- package/src/panels.js +1418 -1
- package/src/ping.js +226 -1
- package/src/presence.js +238 -1
- package/src/render.js +516 -1
- package/src/screen.js +518 -1
- package/src/screens.js +896 -1
- package/src/secret.js +59 -1
- package/src/securefs.js +359 -1
- package/src/settings.js +155 -1
- package/src/shared.js +52 -1
- package/src/sharedpaths.js +53 -1
- package/src/signup.js +156 -1
- package/src/summarize.js +95 -1
- package/src/sysdiag.js +585 -1
- package/src/system.js +40 -1
- package/src/theme.js +570 -1
- package/src/title.js +220 -1
- package/src/todos.js +115 -1
- package/src/tokens.js +263 -1
- package/src/topup.js +210 -1
- package/src/update.js +191 -1
- package/vendor/client/aegis.js +2441 -1
- package/vendor/client/attest.js +518 -1
- package/vendor/client/authorship-key.js +410 -1
- package/vendor/client/auto-provision.js +134 -1
- package/vendor/client/brain-catalog.js +268 -1
- package/vendor/client/byok-catalog.js +199 -1
- package/vendor/client/catalog-client.js +487 -1
- package/vendor/client/conversation-export.js +177 -1
- package/vendor/client/credentials.js +494 -1
- package/vendor/client/device-fingerprint.js +141 -1
- package/vendor/client/drive-connect.js +110 -1
- package/vendor/client/drive-upload.js +234 -1
- package/vendor/client/env-file.js +1273 -1
- package/vendor/client/fingerprint.js +1064 -1
- package/vendor/client/foreign-memory.js +669 -1
- package/vendor/client/google-signin.js +133 -1
- package/vendor/client/hooks.js +430 -1
- package/vendor/client/model-discovery.js +373 -1
- package/vendor/client/naming.js +283 -1
- package/vendor/client/platform.js +937 -1
- package/vendor/client/prefs.js +351 -1
- package/vendor/client/presence-constants.js +107 -1
- package/vendor/client/presence.js +438 -1
- package/vendor/client/record-vault.js +1055 -3
- package/vendor/client/session-store.js +575 -1
- package/vendor/client/topup.js +297 -1
- package/vendor/client/touch.js +458 -1
- package/vendor/client/update.js +763 -1
- package/vendor/client/user-models.js +381 -1
- package/vendor/desktop/lib/local/agents.js +105 -1
- package/vendor/desktop/lib/local/attachments.js +276 -1
- package/vendor/desktop/lib/local/autonomous.js +1045 -1
- package/vendor/desktop/lib/local/claude-pro.js +1028 -1
- package/vendor/desktop/lib/local/context.js +125 -1
- package/vendor/desktop/lib/local/engine.js +3666 -1
- package/vendor/desktop/lib/local/entitlement.js +660 -1
- package/vendor/desktop/lib/local/git-scope.js +228 -1
- package/vendor/desktop/lib/local/local.js +2145 -1
- package/vendor/desktop/lib/local/prompt.js +280 -1
- package/vendor/desktop/lib/local/queue.js +560 -1
- package/vendor/desktop/lib/local/session-rounds.js +238 -1
- package/vendor/desktop/lib/local/spill.js +75 -1
- package/vendor/desktop/lib/local/turn-guard.js +300 -1
- package/vendor/desktop/lib/local/worktree-lock.js +235 -1
- package/vendor/desktop/lib/settings.js +890 -1
- package/vendor/desktop/renderer/usage.js +1239 -1
- package/vendor/hosts/install.js +638 -1
- package/vendor/hosts/openai-shim.js +515 -1
- package/vendor/hosts/spec.js +164 -1
- package/vendor/hosts/targets.js +346 -1
- package/vendor/mcp/server.js +221 -1
- package/vendor/mcp/tools.js +408 -1
- package/vendor/one/src/child.js +285 -1
- package/vendor/one/src/permissions.js +383 -1
- package/SOURCE-OFFER.txt +0 -9
|
@@ -1,3 +1,237 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
3
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
4
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cross-process lock on a git working tree.
|
|
10
|
+
*
|
|
11
|
+
* Ported from the upstream engine reference (ESM → CommonJS).
|
|
12
|
+
*
|
|
13
|
+
* Bug this exists for: nothing keyed on *the working tree*. A session-scoped
|
|
14
|
+
* lock only stops two processes resuming the SAME transcript, so three
|
|
15
|
+
* different sessions in one checkout are three different ids and therefore
|
|
16
|
+
* all legal. A queue-worker lock only serialises queue drains. An interactive
|
|
17
|
+
* session took no lock at all.
|
|
18
|
+
*
|
|
19
|
+
* So N agents editing one checkout was, by every existing lock, correct
|
|
20
|
+
* behaviour — and it is destructive. It happened for real: one session ran
|
|
21
|
+
* `git checkout HEAD --` against a file a second session was mid-edit on
|
|
22
|
+
* (destroying it), a third ran `git stash` and parked everybody's tree, and a
|
|
23
|
+
* test run on that shared tree reported failures belonging to a half-built
|
|
24
|
+
* feature that was not the caller's. Git has no advisory locking, so none of
|
|
25
|
+
* it produced an error — just unexplained file changes, which is exactly the
|
|
26
|
+
* kind of evidence that gets misread as "my tool lied to me".
|
|
27
|
+
*
|
|
28
|
+
* Fix: a lock keyed on the repository root — the resource actually contended
|
|
29
|
+
* — taken by every host that runs a turn (the desktop app and the CLI both
|
|
30
|
+
* reach this file through desktop/lib/local/engine.js). Same atomic-marker +
|
|
31
|
+
* PID-liveness pattern as the session lock, so a crashed holder is reclaimed
|
|
32
|
+
* with no staleness window to tune and no manual cleanup.
|
|
33
|
+
*
|
|
34
|
+
* This lock is advisory and cooperative: it cannot stop a writer that does
|
|
35
|
+
* not take it (a plain `git` in a terminal, another harness, an editor). Its
|
|
36
|
+
* value is that our own hosts stop racing each other, and that a caller
|
|
37
|
+
* receiving `null` knows to back off instead of writing blind.
|
|
38
|
+
*
|
|
39
|
+
* The stronger fix is one worktree per agent (`git worktree add`), which
|
|
40
|
+
* removes the shared mutable tree entirely. This lock is what makes the
|
|
41
|
+
* single-tree case safe when that is not available.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const fs = require('node:fs');
|
|
45
|
+
const path = require('node:path');
|
|
46
|
+
const os = require('node:os');
|
|
47
|
+
const crypto = require('node:crypto');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Where lock files live.
|
|
51
|
+
*
|
|
52
|
+
* The plugin's data dir is ~/.aegiscode ($AEGISCODE_HOME), per config.js's
|
|
53
|
+
* `aegisDir()` convention — but the dev engine's ~/.aegiscodex is honoured
|
|
54
|
+
* too, and either `*_WORKTREE_LOCK_DIR` override points every host at ONE
|
|
55
|
+
* directory. That override is the interlock: two separate tools disagreeing
|
|
56
|
+
* about where the lock file goes is the same as having no lock, so operators
|
|
57
|
+
* running the GUI, the CLI and the dev engine against one checkout should set
|
|
58
|
+
* AEGISCODE_WORKTREE_LOCK_DIR (or AEGISCODEX_WORKTREE_LOCK_DIR) to a shared
|
|
59
|
+
* path. Within this repo the desktop and CLI hosts always agree, because both
|
|
60
|
+
* resolve this same helper.
|
|
61
|
+
*/
|
|
62
|
+
function worktreeLockDir() {
|
|
63
|
+
if (process.env.AEGISCODE_WORKTREE_LOCK_DIR) return process.env.AEGISCODE_WORKTREE_LOCK_DIR;
|
|
64
|
+
if (process.env.AEGISCODEX_WORKTREE_LOCK_DIR) return process.env.AEGISCODEX_WORKTREE_LOCK_DIR;
|
|
65
|
+
const home = process.env.AEGISCODE_HOME
|
|
66
|
+
|| process.env.AEGISCODEX_HOME
|
|
67
|
+
|| path.join(os.homedir(), '.aegiscode');
|
|
68
|
+
return path.join(home, 'worktree-locks');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Default wait: a live holder is bounded by its own turn watchdog, so
|
|
72
|
+
* waiting slightly past that lets a legitimate queued turn run once the
|
|
73
|
+
* holder's deadline fires, rather than failing right as the tree is about to
|
|
74
|
+
* free up. */
|
|
75
|
+
const DEFAULT_WORKTREE_WAIT_MS = 11 * 60 * 1000;
|
|
76
|
+
|
|
77
|
+
/** Sentinel token for the "not in a repo" no-op path — always truthy, never
|
|
78
|
+
* matches a real acquisition, so a stray release() can't release anything. */
|
|
79
|
+
const NOOP_TOKEN = '(no-worktree)';
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Canonicalise the root so two paths to one repo — a symlink, a trailing
|
|
83
|
+
* slash, a relative path, `/tmp/../repo` — agree on a single lock file.
|
|
84
|
+
* Falls back to the resolved path when realpath fails.
|
|
85
|
+
*/
|
|
86
|
+
function canonical(root) {
|
|
87
|
+
if (!root) return null;
|
|
88
|
+
const abs = path.resolve(String(root));
|
|
89
|
+
try { return fs.realpathSync(abs); } catch { return abs; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The lock file for `root`. The path is hashed so an arbitrarily long or
|
|
93
|
+
* awkward root maps to one flat, safe filename; the root itself is written
|
|
94
|
+
* inside the file for humans reading the lock dir. */
|
|
95
|
+
function worktreeLockPath(root) {
|
|
96
|
+
if (!root) return null;
|
|
97
|
+
const key = crypto.createHash('sha1').update(canonical(root)).digest('hex').slice(0, 16);
|
|
98
|
+
return path.join(worktreeLockDir(), key + '.lock');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function pidAlive(pid) {
|
|
102
|
+
try { process.kill(pid, 0); return true; } catch { return false; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function readHolder(root) {
|
|
106
|
+
try { return JSON.parse(fs.readFileSync(worktreeLockPath(root), 'utf8')); } catch { return null; }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The current holder of `root`'s lock, or null. Never throws and never
|
|
111
|
+
* clears a stale lock — use `isWorktreeLocked` for the reclaiming check.
|
|
112
|
+
*/
|
|
113
|
+
function worktreeLockHolder(root) {
|
|
114
|
+
if (!root) return null;
|
|
115
|
+
const h = readHolder(root);
|
|
116
|
+
if (!h) return null;
|
|
117
|
+
return {
|
|
118
|
+
pid: h.pid, token: h.token, since: h.since,
|
|
119
|
+
root: h.root || canonical(root), session: h.session || null,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* True if `root` is held by a live process (any process, including this one
|
|
125
|
+
* — two concurrent callers inside one process must still queue behind each
|
|
126
|
+
* other). A lock file whose PID is dead or unparsable is stale and cleared as
|
|
127
|
+
* a side effect, so callers never special-case it.
|
|
128
|
+
*/
|
|
129
|
+
function isWorktreeLocked(root) {
|
|
130
|
+
if (!root) return false;
|
|
131
|
+
const holder = readHolder(root);
|
|
132
|
+
// `Number(null)` is 0 and `process.kill(0, 0)` targets the caller's process
|
|
133
|
+
// GROUP, so it succeeds — a missing lock file would otherwise read as a live
|
|
134
|
+
// holder forever. Require a real pid. (The session lock has the same latent
|
|
135
|
+
// trap; it never surfaced there only because it is called after EEXIST.)
|
|
136
|
+
const pid = Number(holder && holder.pid);
|
|
137
|
+
if (!Number.isInteger(pid) || pid <= 0 || !pidAlive(pid)) {
|
|
138
|
+
try { fs.unlinkSync(worktreeLockPath(root)); } catch {}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Exclusive-create the lock file for `token`. Returns true on success.
|
|
145
|
+
* Best-effort: a data-dir failure other than "already exists" fails OPEN so a
|
|
146
|
+
* broken filesystem can never block a turn that would otherwise run fine. */
|
|
147
|
+
function tryAcquire(root, token, meta) {
|
|
148
|
+
try {
|
|
149
|
+
fs.mkdirSync(worktreeLockDir(), { recursive: true });
|
|
150
|
+
const fd = fs.openSync(worktreeLockPath(root), 'wx');
|
|
151
|
+
fs.writeFileSync(fd, JSON.stringify({
|
|
152
|
+
pid: process.pid,
|
|
153
|
+
token,
|
|
154
|
+
since: Date.now(),
|
|
155
|
+
root: canonical(root),
|
|
156
|
+
session: (meta && meta.session) || null,
|
|
157
|
+
}));
|
|
158
|
+
fs.closeSync(fd);
|
|
159
|
+
return true;
|
|
160
|
+
} catch (e) {
|
|
161
|
+
if (e && e.code === 'EEXIST') return false;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Release `root`'s lock — only if `token` matches the current holder, so
|
|
167
|
+
* releasing a lock you don't (or no longer) own can never clobber whoever
|
|
168
|
+
* holds it now. No-op on a falsy root/token or any filesystem error
|
|
169
|
+
* (best-effort, like the rest of this repo's persistence helpers). */
|
|
170
|
+
function releaseWorktreeLock(root, token) {
|
|
171
|
+
if (!root || !token || token === NOOP_TOKEN) return;
|
|
172
|
+
const holder = readHolder(root);
|
|
173
|
+
if (holder && holder.token === token) {
|
|
174
|
+
try { fs.unlinkSync(worktreeLockPath(root)); } catch {}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Acquire `root`'s lock, waiting out a live holder instead of racing it.
|
|
180
|
+
* Resolves a truthy opaque token once acquired — pass it back to
|
|
181
|
+
* `releaseWorktreeLock` — or `null` if `waitMs` elapses or `signal` aborts
|
|
182
|
+
* first; either way the caller must not write. A falsy `root` (not inside a
|
|
183
|
+
* git work tree — nothing shared to collide over) resolves the sentinel
|
|
184
|
+
* immediately with no file touched.
|
|
185
|
+
*/
|
|
186
|
+
async function acquireWorktreeLock(root, {
|
|
187
|
+
waitMs = DEFAULT_WORKTREE_WAIT_MS, pollMs = 200, signal, session = null,
|
|
188
|
+
} = {}) {
|
|
189
|
+
if (!root) return NOOP_TOKEN;
|
|
190
|
+
const token = crypto.randomUUID();
|
|
191
|
+
const deadline = Date.now() + waitMs;
|
|
192
|
+
for (;;) {
|
|
193
|
+
if (signal && signal.aborted) return null;
|
|
194
|
+
if (tryAcquire(root, token, { session })) return token;
|
|
195
|
+
// Was stale, just reclaimed by clearing — retry now.
|
|
196
|
+
if (!isWorktreeLocked(root)) continue;
|
|
197
|
+
if (Date.now() >= deadline) return null;
|
|
198
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Run `fn` holding `root`'s lock, releasing it on every exit path. Throws
|
|
204
|
+
* `WorktreeBusyError` (rather than running unprotected) if the lock can't be
|
|
205
|
+
* taken, because proceeding without it is the bug this module exists to
|
|
206
|
+
* prevent.
|
|
207
|
+
*/
|
|
208
|
+
class WorktreeBusyError extends Error {
|
|
209
|
+
constructor(root, holder) {
|
|
210
|
+
super(`working tree ${root} is locked by pid ${holder ? holder.pid : '?'}`);
|
|
211
|
+
this.name = 'WorktreeBusyError';
|
|
212
|
+
this.root = root;
|
|
213
|
+
this.holder = holder || null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function withWorktreeLock(root, opts, fn) {
|
|
218
|
+
const token = await acquireWorktreeLock(root, opts);
|
|
219
|
+
if (!token) throw new WorktreeBusyError(root, worktreeLockHolder(root));
|
|
220
|
+
try {
|
|
221
|
+
return await fn();
|
|
222
|
+
} finally {
|
|
223
|
+
releaseWorktreeLock(root, token);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
module.exports = {
|
|
228
|
+
DEFAULT_WORKTREE_WAIT_MS,
|
|
229
|
+
worktreeLockDir,
|
|
230
|
+
worktreeLockPath,
|
|
231
|
+
worktreeLockHolder,
|
|
232
|
+
isWorktreeLocked,
|
|
233
|
+
releaseWorktreeLock,
|
|
234
|
+
acquireWorktreeLock,
|
|
235
|
+
WorktreeBusyError,
|
|
236
|
+
withWorktreeLock,
|
|
237
|
+
};
|