aegiscode 6.8.18 → 6.8.20
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 +4 -2
- package/scripts/check.mjs +50 -0
- package/scripts/predist.mjs +11 -0
- package/src/app.js +23 -0
- package/src/chatflow.js +48 -21
- package/src/commands.js +41 -35
- package/src/devrun.js +80 -6
- package/src/models.js +166 -33
- package/src/panels.js +2 -1
- package/src/summarize.js +3 -1
- package/vendor/client/aegis.js +13 -0
- package/vendor/client/authorship-key.js +45 -4
- package/vendor/client/byok-catalog.js +49 -1
- package/vendor/client/credentials.js +94 -6
- package/vendor/client/env-file.js +161 -5
- package/vendor/client/hooks.js +427 -0
- package/vendor/client/platform.js +410 -0
- package/vendor/desktop/lib/local/engine.js +114 -39
- package/vendor/desktop/lib/local/shell.js +393 -39
- package/vendor/desktop/lib/local/tools.js +156 -13
- package/vendor/desktop/lib/settings.js +36 -1
- package/vendor/desktop/renderer/usage.js +30 -0
- package/vendor/tools/agent-gate.mjs +81 -13
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* platform.js — the ONE place in this repo that knows which OS it is running on.
|
|
5
|
+
*
|
|
6
|
+
* Phase 30.1. Every platform-dependent decision used to be made inline against
|
|
7
|
+
* `process.platform`, which meant two things: the decision was duplicated
|
|
8
|
+
* wherever it was needed (a private `shellSpec()` here, an `IS_WIN32` there),
|
|
9
|
+
* and — the real cost — its win32 half could only ever be exercised on a
|
|
10
|
+
* Windows host. Nothing on this Linux CI could prove the Windows branch even
|
|
11
|
+
* parses, let alone behaves.
|
|
12
|
+
*
|
|
13
|
+
* So every function here takes an explicit options bag:
|
|
14
|
+
*
|
|
15
|
+
* { platform, env, exists, probe }
|
|
16
|
+
*
|
|
17
|
+
* each entry defaulting to the real process environment:
|
|
18
|
+
*
|
|
19
|
+
* platform process.platform 'win32' | 'darwin' | 'linux' | …
|
|
20
|
+
* env process.env looked up case-insensitively on win32
|
|
21
|
+
* exists (file) => boolean real statSync probe of the filesystem
|
|
22
|
+
* probe (cmd, args) => string|null spawns cmd; stdout on exit 0, else null
|
|
23
|
+
*
|
|
24
|
+
* Passing a different bag is the whole point: `killTree(child, { platform:
|
|
25
|
+
* 'win32', run })` exercises the Windows path on Linux, and the test suite
|
|
26
|
+
* (test/platform.test.mjs) does exactly that for every branch below. This is
|
|
27
|
+
* the seam the engine gained in its Phase 21b `resolveShell({env, platform})`
|
|
28
|
+
* and that this repo's private `shellSpec()` lacked.
|
|
29
|
+
*
|
|
30
|
+
* Rules for this file:
|
|
31
|
+
* - no branch may be reachable ONLY on a foreign host — if it is, the branch
|
|
32
|
+
* is untestable and will rot, so it takes an injected seam above;
|
|
33
|
+
* - nothing here throws: each function returns a value, or an `{ ok:false,
|
|
34
|
+
* error }` result the caller must look at. A swallowed failure is how a
|
|
35
|
+
* Windows dev server was orphaned by an empty `catch {}` (plan F3).
|
|
36
|
+
*
|
|
37
|
+
* Zero dependencies (node builtins only) so it can be vendored byte-identically
|
|
38
|
+
* into both the desktop app dir and the CLI package by the two predist scripts.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const fs = require('node:fs');
|
|
42
|
+
const path = require('node:path');
|
|
43
|
+
const { spawnSync } = require('node:child_process');
|
|
44
|
+
|
|
45
|
+
/** The host's real answer. Import this only when a real OS answer is wanted. */
|
|
46
|
+
const IS_WIN32 = process.platform === 'win32';
|
|
47
|
+
|
|
48
|
+
/** Windows' default executable extensions, used when PATHEXT is absent. */
|
|
49
|
+
const DEFAULT_PATHEXT = '.COM;.EXE;.BAT;.CMD';
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Defaults for the injected seams
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
function defaultExists(file) {
|
|
56
|
+
try {
|
|
57
|
+
return fs.statSync(file).isFile();
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Run a probe command synchronously. Returns stdout on exit 0 and `null` for
|
|
65
|
+
* every other outcome (command missing, non-zero exit, timeout) — a probe
|
|
66
|
+
* answers "is this true", and `null` is the one honest way to say "no".
|
|
67
|
+
*/
|
|
68
|
+
function defaultProbe(cmd, args = [], opts = {}) {
|
|
69
|
+
try {
|
|
70
|
+
const res = spawnSync(cmd, args, {
|
|
71
|
+
encoding: 'utf8',
|
|
72
|
+
timeout: opts.timeout || 5000,
|
|
73
|
+
windowsHide: true,
|
|
74
|
+
env: opts.env,
|
|
75
|
+
});
|
|
76
|
+
if (res.error || res.status !== 0) return null;
|
|
77
|
+
return typeof res.stdout === 'string' ? res.stdout : '';
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Run a command for its side effect. Never throws; `{ ok, error, output }`. */
|
|
84
|
+
function defaultRun(cmd, args = [], opts = {}) {
|
|
85
|
+
try {
|
|
86
|
+
const res = spawnSync(cmd, args, {
|
|
87
|
+
encoding: 'utf8',
|
|
88
|
+
windowsHide: true,
|
|
89
|
+
timeout: opts.timeout || 10000,
|
|
90
|
+
env: opts.env,
|
|
91
|
+
});
|
|
92
|
+
if (res.error) return { ok: false, error: res.error, output: '' };
|
|
93
|
+
if (res.status !== 0) {
|
|
94
|
+
const stderr = String(res.stderr || '').trim();
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: new Error(`${cmd} exited ${res.status}${stderr ? `: ${stderr}` : ''}`),
|
|
98
|
+
status: res.status,
|
|
99
|
+
output: String(res.stdout || ''),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return { ok: true, error: null, output: String(res.stdout || '') };
|
|
103
|
+
} catch (err) {
|
|
104
|
+
return { ok: false, error: err, output: '' };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resolve the options bag. `probe` defaults to the REAL probe, so a caller that
|
|
110
|
+
* passes nothing gets real answers; branches that would otherwise have to spawn
|
|
111
|
+
* something consult the probe only when the caller supplied one, which is why
|
|
112
|
+
* `injectedProbe` is reported separately from `probe`.
|
|
113
|
+
*/
|
|
114
|
+
function seams(options) {
|
|
115
|
+
const o = options && typeof options === 'object' ? options : {};
|
|
116
|
+
const platform = typeof o.platform === 'string' && o.platform ? o.platform : process.platform;
|
|
117
|
+
const env = o.env && typeof o.env === 'object' ? o.env : process.env;
|
|
118
|
+
return {
|
|
119
|
+
o,
|
|
120
|
+
platform,
|
|
121
|
+
env,
|
|
122
|
+
win32: platform === 'win32',
|
|
123
|
+
exists: typeof o.exists === 'function' ? o.exists : defaultExists,
|
|
124
|
+
probe: typeof o.probe === 'function' ? o.probe : defaultProbe,
|
|
125
|
+
injectedProbe: typeof o.probe === 'function',
|
|
126
|
+
kill: typeof o.kill === 'function' ? o.kill : (...args) => process.kill(...args),
|
|
127
|
+
run: typeof o.run === 'function' ? o.run : defaultRun,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Environment lookup. Windows environment names are case-insensitive
|
|
133
|
+
* (`ComSpec` and `COMSPEC` are the same variable; PATH is often `Path`), so on
|
|
134
|
+
* win32 fall back to a case-insensitive scan after the exact and upper-case
|
|
135
|
+
* keys both miss.
|
|
136
|
+
*/
|
|
137
|
+
function envValue(env, name, platform) {
|
|
138
|
+
if (!env || typeof env !== 'object') return undefined;
|
|
139
|
+
const direct = env[name] !== undefined ? env[name] : env[name.toUpperCase()];
|
|
140
|
+
if (direct !== undefined) return direct;
|
|
141
|
+
if (platform !== 'win32') return undefined;
|
|
142
|
+
const want = name.toLowerCase();
|
|
143
|
+
for (const key of Object.keys(env)) {
|
|
144
|
+
if (key.toLowerCase() === want) return env[key];
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function pathEntries(env, platform, cwd, P) {
|
|
150
|
+
const raw = String(envValue(env, 'PATH', platform) || '');
|
|
151
|
+
const parts = raw.split(platform === 'win32' ? ';' : ':');
|
|
152
|
+
const out = [];
|
|
153
|
+
for (const part of parts) {
|
|
154
|
+
const dir = part.trim().replace(/^"|"$/g, '');
|
|
155
|
+
if (!dir) continue;
|
|
156
|
+
out.push(P.isAbsolute(dir) ? dir : P.join(cwd, dir));
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function extList(env, platform) {
|
|
162
|
+
const raw = String(envValue(env, 'PATHEXT', platform) || DEFAULT_PATHEXT);
|
|
163
|
+
const exts = raw
|
|
164
|
+
.split(';')
|
|
165
|
+
.map((e) => e.trim())
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.map((e) => (e.startsWith('.') ? e : `.${e}`));
|
|
168
|
+
return exts.length ? exts : DEFAULT_PATHEXT.split(';');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// resolveExecutable
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Resolve a command name to a path this host can actually spawn, or `null`.
|
|
177
|
+
*
|
|
178
|
+
* resolveExecutable('claude') -> '/usr/local/bin/claude'
|
|
179
|
+
* resolveExecutable('node', { platform:'win32',
|
|
180
|
+
* env:{ Path:'C:\\bin', PATHEXT:'.EXE' },
|
|
181
|
+
* exists:(f)=>f==='C:\\bin\\node.EXE' })
|
|
182
|
+
* -> 'C:\\bin\\node.EXE'
|
|
183
|
+
*
|
|
184
|
+
* Names containing a separator (or a drive letter on win32) are treated as
|
|
185
|
+
* paths and resolved against `cwd`; bare names are searched along PATH, in
|
|
186
|
+
* order, trying the name itself first and then each PATHEXT extension on
|
|
187
|
+
* win32 — which is what `cmd` itself does, and the difference between finding
|
|
188
|
+
* `npm.cmd` and reporting "npm not found" on a Windows host.
|
|
189
|
+
*
|
|
190
|
+
* Returns a string, or `null` when nothing matches: a caller can spawn a path
|
|
191
|
+
* or report that the program is missing, and cannot mistake one for the other.
|
|
192
|
+
*/
|
|
193
|
+
function resolveExecutable(name, options = {}) {
|
|
194
|
+
const { platform, env, exists, win32, o } = seams(options);
|
|
195
|
+
if (typeof name !== 'string' || !name.trim()) return null;
|
|
196
|
+
const raw = name.trim();
|
|
197
|
+
const cwd = typeof o.cwd === 'string' && o.cwd ? o.cwd : process.cwd();
|
|
198
|
+
// Path SEMANTICS follow the platform being asked about, not the host running
|
|
199
|
+
// the code: `path.win32.join('C:\\Tools', 'npm.EXE')` is the answer a Windows
|
|
200
|
+
// host gives, and using the host's own `path` here would make the win32
|
|
201
|
+
// branch produce posix paths on Linux — which is exactly the difference this
|
|
202
|
+
// module exists to make testable rather than platform-only.
|
|
203
|
+
const P = win32 ? path.win32 : path;
|
|
204
|
+
|
|
205
|
+
const looksLikePath = win32
|
|
206
|
+
? raw.includes('/') || raw.includes('\\') || /^[a-zA-Z]:/.test(raw)
|
|
207
|
+
: raw.includes('/');
|
|
208
|
+
if (looksLikePath) {
|
|
209
|
+
const full = P.isAbsolute(raw) ? raw : P.join(cwd, raw);
|
|
210
|
+
return exists(full) ? full : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const exts = win32 ? ['', ...extList(env, platform)] : [''];
|
|
214
|
+
for (const dir of pathEntries(env, platform, cwd, P)) {
|
|
215
|
+
for (const ext of exts) {
|
|
216
|
+
const candidate = P.join(dir, raw + ext);
|
|
217
|
+
if (exists(candidate)) return candidate;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
// shellSpec
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The shell one-shot commands run in: `cmd.exe` on Windows, `$SHELL` (or
|
|
229
|
+
* `/bin/sh`) elsewhere.
|
|
230
|
+
*
|
|
231
|
+
* { cmd, arg, kind } kind: 'cmd' | 'posix'
|
|
232
|
+
*
|
|
233
|
+
* `{ cmd, arg }` is the shape the caller needs for `spawn(cmd, [arg, script])`;
|
|
234
|
+
* `kind` is there so a caller can stop re-deriving `platform === 'win32'` at
|
|
235
|
+
* every site that needs to know which dialect it just got.
|
|
236
|
+
*
|
|
237
|
+
* This replaces the private copy that lived at desktop/lib/local/tools.js:630
|
|
238
|
+
* and read `process.platform` directly. It is deliberately NOT a `$SHELL`
|
|
239
|
+
* allowlist: which shells are POSIX enough for a given script is the script's
|
|
240
|
+
* problem (plan 30.3), not this resolver's.
|
|
241
|
+
*/
|
|
242
|
+
function shellSpec(options = {}) {
|
|
243
|
+
const { platform, env, win32 } = seams(options);
|
|
244
|
+
if (win32) {
|
|
245
|
+
const cmd = envValue(env, 'ComSpec', platform) || envValue(env, 'COMSPEC', platform) || 'cmd.exe';
|
|
246
|
+
return { cmd, arg: '/d /s /c', kind: 'cmd' };
|
|
247
|
+
}
|
|
248
|
+
const cmd = envValue(env, 'SHELL', platform) || '/bin/sh';
|
|
249
|
+
return { cmd, arg: '-c', kind: 'posix' };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// killTree
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Kill a child process AND its descendants.
|
|
258
|
+
*
|
|
259
|
+
* { ok, method: 'group'|'signal'|'taskkill'|'none', pid, error, groupError, gone }
|
|
260
|
+
*
|
|
261
|
+
* posix: the child is spawned `detached`, so it leads its own process group and
|
|
262
|
+
* `kill(-pid)` reaches the whole tree; a group the caller never created (or one
|
|
263
|
+
* already reaped) answers ESRCH/EPERM, and the fallback is a plain single-pid
|
|
264
|
+
* signal. Anything else is reported, not swallowed.
|
|
265
|
+
*
|
|
266
|
+
* win32: there is no process group to signal, so it is `taskkill /PID <pid> /T
|
|
267
|
+
* /F` — `/T` for the tree, `/F` because a Windows console app can ignore the
|
|
268
|
+
* graceful message and stay alive.
|
|
269
|
+
*
|
|
270
|
+
* `ok:false` always carries an `error`; `gone:true` marks the "already dead"
|
|
271
|
+
* case so a caller can treat it as done without guessing from a message string.
|
|
272
|
+
*/
|
|
273
|
+
function killTree(target, options = {}) {
|
|
274
|
+
const { platform, env, win32, kill, run, o } = seams(options);
|
|
275
|
+
const pid = typeof target === 'number' ? target : target && target.pid;
|
|
276
|
+
const signal = o.signal || 'SIGTERM';
|
|
277
|
+
const detached = o.detached !== false;
|
|
278
|
+
const timeout = o.timeout || 10000;
|
|
279
|
+
|
|
280
|
+
if (!Number.isInteger(pid) || pid <= 0) {
|
|
281
|
+
return {
|
|
282
|
+
ok: false,
|
|
283
|
+
method: 'none',
|
|
284
|
+
pid: Number.isInteger(pid) ? pid : null,
|
|
285
|
+
error: new Error(`killTree: no usable pid (got ${JSON.stringify(target && target.pid)})`),
|
|
286
|
+
gone: false,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (win32) {
|
|
291
|
+
const res = run('taskkill', ['/PID', String(pid), '/T', '/F'], { env, platform, timeout }) || {};
|
|
292
|
+
if (res.ok === false) {
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
method: 'taskkill',
|
|
296
|
+
pid,
|
|
297
|
+
error: res.error || new Error('taskkill failed'),
|
|
298
|
+
gone: false,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { ok: true, method: 'taskkill', pid, error: null, gone: false };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let groupError = null;
|
|
305
|
+
if (detached) {
|
|
306
|
+
try {
|
|
307
|
+
kill(-pid, signal);
|
|
308
|
+
return { ok: true, method: 'group', pid, error: null, gone: false };
|
|
309
|
+
} catch (err) {
|
|
310
|
+
groupError = err;
|
|
311
|
+
const code = err && err.code;
|
|
312
|
+
if (code !== 'ESRCH' && code !== 'EPERM') {
|
|
313
|
+
return {
|
|
314
|
+
ok: false,
|
|
315
|
+
method: 'group',
|
|
316
|
+
pid,
|
|
317
|
+
error: err,
|
|
318
|
+
gone: false,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
kill(pid, signal);
|
|
326
|
+
return { ok: true, method: 'signal', pid, error: null, groupError, gone: false };
|
|
327
|
+
} catch (err) {
|
|
328
|
+
const code = err && err.code;
|
|
329
|
+
return {
|
|
330
|
+
ok: false,
|
|
331
|
+
method: 'signal',
|
|
332
|
+
pid,
|
|
333
|
+
error: err,
|
|
334
|
+
groupError,
|
|
335
|
+
gone: code === 'ESRCH',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ---------------------------------------------------------------------------
|
|
341
|
+
// isAlive
|
|
342
|
+
// ---------------------------------------------------------------------------
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Is that pid still running? Never throws.
|
|
346
|
+
*
|
|
347
|
+
* posix: `kill(pid, 0)` — ESRCH means gone, EPERM means it exists but belongs
|
|
348
|
+
* to someone else, and "exists but not ours" is alive.
|
|
349
|
+
*
|
|
350
|
+
* win32: signal 0 is not a portable existence test there, so ask the OS
|
|
351
|
+
* directly — `tasklist /FI "PID eq <pid>"` — and match the pid in the output.
|
|
352
|
+
* The probe is the injected seam, so this branch is exercised on Linux by
|
|
353
|
+
* feeding it fabricated tasklist output rather than by waiting for a Windows
|
|
354
|
+
* runner that, by configuration, does not exist (plan F6).
|
|
355
|
+
*/
|
|
356
|
+
function isAlive(pid, options = {}) {
|
|
357
|
+
const { platform, env, win32, probe, kill } = seams(options);
|
|
358
|
+
const label = typeof pid === 'number' ? pid : Number(pid);
|
|
359
|
+
if (!Number.isInteger(label) || label <= 0) return false;
|
|
360
|
+
|
|
361
|
+
if (win32) {
|
|
362
|
+
const out = probe('tasklist', ['/FI', `PID eq ${label}`, '/NH', '/FO', 'CSV'], { env, platform });
|
|
363
|
+
if (out === null || out === undefined) return false;
|
|
364
|
+
const text = String(out).trim();
|
|
365
|
+
if (!text) return false;
|
|
366
|
+
return new RegExp(`(^|[^0-9])${label}([^0-9]|$)`).test(text);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
kill(label, 0);
|
|
371
|
+
return true;
|
|
372
|
+
} catch (err) {
|
|
373
|
+
return Boolean(err && err.code === 'EPERM');
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ---------------------------------------------------------------------------
|
|
378
|
+
// hasDisplay
|
|
379
|
+
// ---------------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Can this process reach a graphical display? (i.e. may a host open a window,
|
|
383
|
+
* a browser or an Electron window here?)
|
|
384
|
+
*
|
|
385
|
+
* Windows and macOS: yes — an interactive session always has one, and a
|
|
386
|
+
* headless service session is out of scope for this product.
|
|
387
|
+
* Linux/BSD: only if `DISPLAY` or `WAYLAND_DISPLAY` says so. When neither is
|
|
388
|
+
* set the answer is `false` rather than a guess, and a caller that has a
|
|
389
|
+
* better oracle (a live X socket, a container's own check) can inject `probe`
|
|
390
|
+
* to override it — the probe is consulted ONLY when injected, so this function
|
|
391
|
+
* never spawns anything behind a caller's back.
|
|
392
|
+
*/
|
|
393
|
+
function hasDisplay(options = {}) {
|
|
394
|
+
const { platform, env, win32, probe, injectedProbe } = seams(options);
|
|
395
|
+
if (win32 || platform === 'darwin') return true;
|
|
396
|
+
if (envValue(env, 'DISPLAY', platform) || envValue(env, 'WAYLAND_DISPLAY', platform)) return true;
|
|
397
|
+
if (injectedProbe) return probe('xdpyinfo', [], { env, platform }) !== null;
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const api = {
|
|
402
|
+
IS_WIN32,
|
|
403
|
+
resolveExecutable,
|
|
404
|
+
shellSpec,
|
|
405
|
+
killTree,
|
|
406
|
+
isAlive,
|
|
407
|
+
hasDisplay,
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
module.exports = api;
|
|
@@ -240,6 +240,57 @@ function providerKeyFromEnv(provider) {
|
|
|
240
240
|
const DEEPSEEK_REASONING_MODEL_RE = /^deepseek-(v4(\.\d+)?-(flash|pro)|flash|pro|reasoner)$/;
|
|
241
241
|
const EFFORT_TOKEN_BUDGET = { low: 8192, medium: 16384, high: 32768 };
|
|
242
242
|
|
|
243
|
+
/**
|
|
244
|
+
* DeepSeek native reasoning level per config rung.
|
|
245
|
+
*
|
|
246
|
+
* The field is `reasoning_effort`, NOT `effort`. Verified live 2026-10-02: a
|
|
247
|
+
* DeepSeek body carrying `effort` returns HTTP 200 and is ignored, while
|
|
248
|
+
* `reasoning_effort` binds and rejects an unknown value with a 422 naming its
|
|
249
|
+
* enum (none|minimal|low|medium|high|xhigh|ultra|max). Behaviourally,
|
|
250
|
+
* `reasoning_effort:"none"` produced 0 reasoning_content chars and `"max"`
|
|
251
|
+
* produced 138, whereas `effort:"none"` still produced 112 — thinking stayed
|
|
252
|
+
* on. So the old field was inert on every turn, and inertness is the worst
|
|
253
|
+
* failure here: it 200s, nothing surfaces, and the model merely thinks at the
|
|
254
|
+
* wrong depth.
|
|
255
|
+
*
|
|
256
|
+
* Every rung of the knob has a namesake in that enum, so the map is 1:1 rather
|
|
257
|
+
* than the earlier (low|max, no medium) fold, which rested on the mistaken
|
|
258
|
+
* belief that DeepSeek had no `medium`. `max_tokens` (EFFORT_TOKEN_BUDGET)
|
|
259
|
+
* still scales as the output ceiling, since hidden chain-of-thought shares that
|
|
260
|
+
* budget on DeepSeek.
|
|
261
|
+
*
|
|
262
|
+
* Mirrors the upstream engine's src/backend.js DEEPSEEK_EFFORT verbatim;
|
|
263
|
+
* desktop/renderer/budget.js carries the renderer's copy for the same
|
|
264
|
+
* no-drift guarantee as DEEPSEEK_REASONING_MODEL_RE above.
|
|
265
|
+
*/
|
|
266
|
+
const DEEPSEEK_EFFORT = { low: 'low', medium: 'medium', high: 'high' };
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Per-family effort translation, mirroring the upstream engine's
|
|
270
|
+
* EFFORT_DIALECTS. The knob is one rung here (low|medium|high) but it is NOT
|
|
271
|
+
* portable across vendors, and passing it through untranslated is a correctness
|
|
272
|
+
* bug rather than a no-op: Groq 400s any level outside a model's supported set,
|
|
273
|
+
* and Gemini 3 fails on `medium` outright while low/high succeed. So each
|
|
274
|
+
* family states its own wire field and level map, and a family with no such
|
|
275
|
+
* field gets NOTHING — an unknown body field either 400s or is silently
|
|
276
|
+
* dropped, and both are worse than stating no opinion.
|
|
277
|
+
*
|
|
278
|
+
* xAI's `*-non-reasoning` row is left alone entirely: the model exists to not
|
|
279
|
+
* reason, and sending it an effort field is precisely the request the user
|
|
280
|
+
* picked that row to avoid. grok-4.20 and gemini-2.0 stay bare too — no
|
|
281
|
+
* documented level field exists for them, and guessing on a strict validator
|
|
282
|
+
* is a 400 rather than an upgrade.
|
|
283
|
+
*/
|
|
284
|
+
const EFFORT_IDENTITY = { low: 'low', medium: 'medium', high: 'high' };
|
|
285
|
+
const EFFORT_INERT_RE = /non-reasoning/i;
|
|
286
|
+
const EFFORT_DIALECTS = [
|
|
287
|
+
{ provider: 'deepseek', re: DEEPSEEK_REASONING_MODEL_RE, field: 'reasoning_effort', map: DEEPSEEK_EFFORT },
|
|
288
|
+
{ provider: 'openai', re: /^(gpt-5|o[0-9])/i, field: 'reasoning_effort', map: EFFORT_IDENTITY },
|
|
289
|
+
{ provider: 'groq', re: /^(openai\/gpt-oss|qwen\/qwen3)/i, field: 'reasoning_effort', map: EFFORT_IDENTITY },
|
|
290
|
+
{ provider: 'xai', re: /^grok-(4\.[5-9]|[5-9])/, field: 'reasoning_effort', map: EFFORT_IDENTITY },
|
|
291
|
+
{ provider: 'google', re: /^gemini-(2\.5|3|[4-9])/, field: 'reasoning_effort', map: { ...EFFORT_IDENTITY, medium: 'high' } },
|
|
292
|
+
];
|
|
293
|
+
|
|
243
294
|
/**
|
|
244
295
|
* Idle-stream budget for a pooled brain call ("work autonomously"). The
|
|
245
296
|
* generic watchdog in vendor/aegis.js kills a stream that goes 60s without a
|
|
@@ -296,6 +347,24 @@ function reasoningBudget(model, maxTokens, effort) {
|
|
|
296
347
|
return undefined;
|
|
297
348
|
}
|
|
298
349
|
|
|
350
|
+
/**
|
|
351
|
+
* The native effort verdict for this provider+model: `{ field, level }`, or
|
|
352
|
+
* `undefined` when the family has no effort knob. `undefined` means "say
|
|
353
|
+
* nothing", never "send a default" — inventing a level is how the knob silently
|
|
354
|
+
* overrides the vendor's own default. Supersedes the DeepSeek-only
|
|
355
|
+
* deepseekEffort() it replaces: same DeepSeek mapping, now stated for every
|
|
356
|
+
* family that has one instead of only the one that used to be wired.
|
|
357
|
+
*/
|
|
358
|
+
function nativeEffort(provider, model, effort) {
|
|
359
|
+
const m = String(model || '');
|
|
360
|
+
if (EFFORT_INERT_RE.test(m)) return undefined;
|
|
361
|
+
const eff = effort === 'low' || effort === 'medium' ? effort : 'high';
|
|
362
|
+
for (const d of EFFORT_DIALECTS) {
|
|
363
|
+
if (d.provider === provider && d.re.test(m)) return { field: d.field, level: d.map[eff] };
|
|
364
|
+
}
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
|
|
299
368
|
/** Relay model entries arrive as ids or objects; keep only real model ids. */
|
|
300
369
|
function normalizeCatalog(models) {
|
|
301
370
|
if (!Array.isArray(models)) return [];
|
|
@@ -307,35 +376,32 @@ function normalizeCatalog(models) {
|
|
|
307
376
|
/**
|
|
308
377
|
* The Aegis Cloud (pooled) dropdown.
|
|
309
378
|
*
|
|
310
|
-
* It offers
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
379
|
+
* It offers the server's whole catalog (`/api/v1/models`): the pooled brain
|
|
380
|
+
* first, under its one name (Nexus), then every per-provider id the account can
|
|
381
|
+
* pin (`deepseek`, `anthropic`, `groq`, `openai`, ...).
|
|
382
|
+
*
|
|
383
|
+
* Two narrower shapes were shipped here and both are reverted, because both
|
|
384
|
+
* produced the same report — a user asking where the models went. First the
|
|
385
|
+
* class collapsed to a single "Nexus" row (`filterAegisCatalog`), which ended
|
|
386
|
+
* the two-host disagreement about the brain's five tier spellings by removing
|
|
387
|
+
* the choice: a funded account had `deepseek` advertised to it and no way to
|
|
388
|
+
* pin it. Then it offered nothing at all — `omitAegisCloudModels` composed with
|
|
389
|
+
* that collapse returns `[]`, because the omission removes the only entry the
|
|
390
|
+
* collapse looks for. The rule both hosts call now is `offerableCatalog`:
|
|
391
|
+
* everything the server advertises, the tier spellings folded into the one row
|
|
392
|
+
* they point at.
|
|
319
393
|
*
|
|
320
394
|
* What is NOT changed: the account key, and everything the key is *for* — the
|
|
321
395
|
* pooled turn itself, cloud memory sync, and the BYOK handling fee that is
|
|
322
|
-
* billed to this account (see the byok branch below
|
|
323
|
-
* provider id the server's catalog names). Omitting a model list is not
|
|
324
|
-
* disconnecting the lane.
|
|
325
|
-
*
|
|
326
|
-
* The omission itself is one shared rule (`omitAegisCloudModels`, and the
|
|
327
|
-
* collapse it is composed with) in `client/brain-catalog.js`, shared with the
|
|
328
|
-
* CLI: two copies is how this host and the terminal previously came to offer
|
|
329
|
-
* the same account two different model lists. Resolved the two ways this repo
|
|
330
|
-
* resolves every shared module — repo-relative in a checkout, and this app's
|
|
331
|
-
* staged vendor/ tree.
|
|
396
|
+
* billed to this account (see the byok branch below).
|
|
332
397
|
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
398
|
+
* The list itself is one shared rule in `client/brain-catalog.js`, shared with
|
|
399
|
+
* the CLI: two copies is how this host and the terminal previously came to
|
|
400
|
+
* offer the same account two different model lists. Resolved the two ways this
|
|
401
|
+
* repo resolves every shared module — repo-relative in a checkout, and this
|
|
402
|
+
* app's staged vendor/ tree.
|
|
337
403
|
*/
|
|
338
|
-
const {
|
|
404
|
+
const { offerableCatalog } = requireSharedBrain();
|
|
339
405
|
|
|
340
406
|
/**
|
|
341
407
|
* The BYOK additions, applied to the server's provider catalog below. Same
|
|
@@ -744,7 +810,7 @@ function createLocalEngine({
|
|
|
744
810
|
// direction too: a path wrongly claimed stops being reported as foreign.
|
|
745
811
|
const result = await T.executeTool(name, args, toolCtx);
|
|
746
812
|
if (guard && (name === 'writeFile' || name === 'editFile') && result && result.ok !== false) {
|
|
747
|
-
recordWrite(guard, args && args.
|
|
813
|
+
recordWrite(guard, args && args.file_path);
|
|
748
814
|
}
|
|
749
815
|
return result;
|
|
750
816
|
}
|
|
@@ -793,7 +859,7 @@ function createLocalEngine({
|
|
|
793
859
|
// unconditionally, making every line below it unreachable — the
|
|
794
860
|
// approved-write path recorded nothing at all.)
|
|
795
861
|
if (res && res.ok !== false && toolCtx && toolCtx.guard) {
|
|
796
|
-
recordWrite(toolCtx.guard, args && args.
|
|
862
|
+
recordWrite(toolCtx.guard, args && args.file_path);
|
|
797
863
|
}
|
|
798
864
|
return res;
|
|
799
865
|
}
|
|
@@ -855,20 +921,16 @@ function createLocalEngine({
|
|
|
855
921
|
// entry so the class is usable the moment a key lands.
|
|
856
922
|
if (!aegis.apiKey) return { class: cls, models: [], needsKey: true };
|
|
857
923
|
const data = await aegis.listModels();
|
|
858
|
-
//
|
|
859
|
-
//
|
|
860
|
-
// emptied, which is why `needsKey` keeps its meaning and the renderer's
|
|
861
|
-
// hint for this class is unchanged.
|
|
924
|
+
// The whole catalog, aliases folded — see the rule above. What the list
|
|
925
|
+
// contains does not touch `needsKey` or the renderer's per-class hint.
|
|
862
926
|
return {
|
|
863
927
|
class: cls,
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
//
|
|
868
|
-
//
|
|
869
|
-
|
|
870
|
-
// case the rule exists to catch.
|
|
871
|
-
models: filterAegisCatalog(omitAegisCloudModels(normalizeCatalog(data && data.models))),
|
|
928
|
+
// One call, because the folding has to see the payload's own `alias_of`
|
|
929
|
+
// bookkeeping: a pre-collapsed row IS the selection, so a renderer must
|
|
930
|
+
// not filter it back out as a hidden alias, and folding what has already
|
|
931
|
+
// been folded would leave a renamed tier (`nexus-brain-v2`, an alias OF
|
|
932
|
+
// the brain under a spelling this release has never seen) on screen.
|
|
933
|
+
models: offerableCatalog(normalizeCatalog(data && data.models)),
|
|
872
934
|
};
|
|
873
935
|
}
|
|
874
936
|
if (cls === 'byok') {
|
|
@@ -1153,6 +1215,12 @@ function createLocalEngine({
|
|
|
1153
1215
|
// automatically by byokChatCompletion() as X-AEGIS-Key so the account
|
|
1154
1216
|
// gets billed the handling fee; see client/aegis.js.
|
|
1155
1217
|
const { provider, model: bareModel } = splitByokModel(opts.model);
|
|
1218
|
+
// Translate the rung for THIS vendor once, and carry the verdict rather
|
|
1219
|
+
// than a bare level: the relay validates strictly upstream and the field
|
|
1220
|
+
// name is not portable (DeepSeek's OpenAI-compatible surface takes
|
|
1221
|
+
// `reasoning_effort`, same spelling as OpenAI's). Undefined for a family
|
|
1222
|
+
// with no dialect, which the transport then omits entirely.
|
|
1223
|
+
const effort = nativeEffort(provider, bareModel, opts.effort);
|
|
1156
1224
|
try {
|
|
1157
1225
|
return await aegis.byokChatCompletion({
|
|
1158
1226
|
provider,
|
|
@@ -1162,6 +1230,13 @@ function createLocalEngine({
|
|
|
1162
1230
|
system: opts.system,
|
|
1163
1231
|
messages: opts.messages,
|
|
1164
1232
|
maxTokens: opts.maxTokens,
|
|
1233
|
+
// Native effort knob, field and level both from the dialect table.
|
|
1234
|
+
// `bareModel` is already provider-less, so it matches the dialect
|
|
1235
|
+
// regexes without further stripping. Only a dialect whose field is
|
|
1236
|
+
// `reasoning_effort` is forwarded: DeepSeek used to ride a separate
|
|
1237
|
+
// `effort` body key, which the API 200s and ignores, so that whole
|
|
1238
|
+
// second channel is gone rather than left as a way to reintroduce it.
|
|
1239
|
+
reasoningEffort: effort && effort.field === 'reasoning_effort' ? effort.level : undefined,
|
|
1165
1240
|
stream: true,
|
|
1166
1241
|
onStream: opts.onDelta,
|
|
1167
1242
|
signal: opts.signal,
|
|
@@ -1863,4 +1938,4 @@ function createLocalEngine({
|
|
|
1863
1938
|
};
|
|
1864
1939
|
}
|
|
1865
1940
|
|
|
1866
|
-
module.exports = { CLASSES, createLocalEngine, extractToolCalls, parseArgs, reasoningBudget };
|
|
1941
|
+
module.exports = { CLASSES, createLocalEngine, extractToolCalls, parseArgs, reasoningBudget, nativeEffort };
|