aegiscode 6.8.5 → 6.8.7
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 +2 -2
- package/scripts/predist.mjs +12 -0
- package/scripts/runtests.mjs +54 -0
- package/src/app.js +36 -2
- package/src/autonomous.js +93 -3
- package/src/chatflow.js +29 -15
- package/src/checkpoint.js +4 -2
- package/src/clipboard.js +89 -13
- package/src/commands.js +47 -3
- package/src/config.js +8 -9
- package/src/deps.js +7 -1
- package/src/diffview.js +10 -3
- package/src/entitlement.js +108 -0
- package/src/events.js +27 -1
- package/src/history.js +5 -3
- package/src/securefs.js +319 -0
- package/vendor/client/aegis.js +162 -3
- package/vendor/client/auto-provision.js +52 -0
- package/vendor/client/credentials.js +4 -0
- package/vendor/client/device-fingerprint.js +63 -0
- package/vendor/desktop/lib/local/autonomous.js +69 -2
- package/vendor/desktop/lib/local/engine.js +10 -0
- package/vendor/desktop/lib/local/entitlement.js +487 -0
- package/vendor/desktop/lib/settings.js +33 -0
- package/vendor/mcp/server.js +33 -2
- package/vendor/mcp/tools.js +9 -1
package/vendor/client/aegis.js
CHANGED
|
@@ -134,9 +134,41 @@ function createClient(opts = {}) {
|
|
|
134
134
|
const memoryToken =
|
|
135
135
|
opts.memoryToken !== undefined ? opts.memoryToken : envVar('AEGIS_MEMORY_TOKEN');
|
|
136
136
|
const clientVersion = opts.clientVersion || CLIENT_VERSION;
|
|
137
|
+
// Which host is asking, purely so an upgrade prompt raised from inside this
|
|
138
|
+
// shared client is filed against the right product. aegis1 stores an
|
|
139
|
+
// unrecognised source as NULL and reports it as `direct`, so an unknown
|
|
140
|
+
// value here is a silently destroyed datapoint rather than a visible error —
|
|
141
|
+
// hence the allowlist rather than trusting the caller.
|
|
142
|
+
const channel = opts.channel === 'cli' ? 'cli' : 'desktop';
|
|
137
143
|
|
|
138
144
|
let memoryTokenCache = null;
|
|
139
145
|
|
|
146
|
+
/**
|
|
147
|
+
* A campaign-tagged upgrade link. Never hand-build a `/subscribe` URL in a
|
|
148
|
+
* prompt: the bare form carries no attribution, so the click arrives as
|
|
149
|
+
* `direct` and the surface that produced it can never be credited.
|
|
150
|
+
* The campaign must be one of the ids fixed in `docs/upgrade-conversion-plan.md`
|
|
151
|
+
* §1 (`welcome_cloud`, `queue_cap`, `memory_quota`, `status_card`,
|
|
152
|
+
* `topup_bank`) — a sixth id invented here is a row no report or allowlist
|
|
153
|
+
* knows about, which is the same destroyed datapoint as an untagged link.
|
|
154
|
+
* The slug is checked against aegis1's `_sanitize_signup_slug` shape rather
|
|
155
|
+
* than an allowlist, because this module is shared by every host and cannot
|
|
156
|
+
* know the server's current list.
|
|
157
|
+
* Returns '' if the base is not a parseable absolute URL, so a caller can
|
|
158
|
+
* fall back to plain text instead of rendering "undefined" at a user.
|
|
159
|
+
*/
|
|
160
|
+
function promptUrl(page, campaign) {
|
|
161
|
+
try {
|
|
162
|
+
const url = new URL(`/go/${String(page || 'upgrade').replace(/^\/+|\/+$/g, '')}`, apiBase);
|
|
163
|
+
url.searchParams.set('s', channel);
|
|
164
|
+
const c = String(campaign || '').trim().toLowerCase();
|
|
165
|
+
if (/^[a-z0-9][a-z0-9_-]{0,63}$/.test(c)) url.searchParams.set('c', c);
|
|
166
|
+
return url.toString();
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return '';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
140
172
|
// -------------------------------------------------------------------------
|
|
141
173
|
// HTTP helpers
|
|
142
174
|
// -------------------------------------------------------------------------
|
|
@@ -157,11 +189,12 @@ function createClient(opts = {}) {
|
|
|
157
189
|
return headers;
|
|
158
190
|
}
|
|
159
191
|
|
|
160
|
-
async function apiPost(path, body, headers) {
|
|
192
|
+
async function apiPost(path, body, headers, opts) {
|
|
161
193
|
const res = await fetch(`${apiBase}${path}`, {
|
|
162
194
|
method: 'POST',
|
|
163
195
|
headers: headers || authHeaders(),
|
|
164
196
|
body: JSON.stringify(body || {}),
|
|
197
|
+
signal: opts && opts.signal,
|
|
165
198
|
});
|
|
166
199
|
return parseResponse(res);
|
|
167
200
|
}
|
|
@@ -174,6 +207,63 @@ function createClient(opts = {}) {
|
|
|
174
207
|
return parseResponse(res);
|
|
175
208
|
}
|
|
176
209
|
|
|
210
|
+
/**
|
|
211
|
+
* A 426 `version_mismatch` from either server gate: this client is too old
|
|
212
|
+
* to be served. The body carries the minimum it failed (`required`), the
|
|
213
|
+
* npm dist-tags to move to (`latest_cli`/`latest_desktop`) and where to get
|
|
214
|
+
* them, so a host can show an upgrade prompt naming a target instead of a
|
|
215
|
+
* bare "connection refused".
|
|
216
|
+
*
|
|
217
|
+
* Surfaced as a typed error (`code` + `upgrade`) rather than only a message
|
|
218
|
+
* so hosts can branch on it without parsing prose, and so the desktop/MCP
|
|
219
|
+
* shells can open the upgrade panel with a version already filled in.
|
|
220
|
+
*
|
|
221
|
+
* The upgrade link is rebuilt through promptUrl() rather than trusting
|
|
222
|
+
* `update_url` verbatim: a server-supplied bare URL carries no `?s=`/`?c=`,
|
|
223
|
+
* so the click is filed as `direct` and the surface that hit the gate can
|
|
224
|
+
* never be credited for the conversion it caused. The server value is kept
|
|
225
|
+
* as a fallback for hosts reaching a base we cannot parse.
|
|
226
|
+
*/
|
|
227
|
+
function versionGateError(data, status) {
|
|
228
|
+
const body = data || {};
|
|
229
|
+
const latestCli = body.latest_cli || '';
|
|
230
|
+
const latestDesktop = body.latest_desktop || '';
|
|
231
|
+
// Prefer a real published version; fall back to the minimum so the
|
|
232
|
+
// message always names something the user can act on.
|
|
233
|
+
const target = latestCli || latestDesktop || body.required || '';
|
|
234
|
+
const err = new Error(
|
|
235
|
+
target
|
|
236
|
+
? `This client (v${clientVersion}) is out of date — upgrade to v${target}.`
|
|
237
|
+
: `This client (v${clientVersion}) is out of date.`
|
|
238
|
+
);
|
|
239
|
+
err.status = status;
|
|
240
|
+
err.code = 'version_mismatch';
|
|
241
|
+
err.data = body;
|
|
242
|
+
err.upgrade = {
|
|
243
|
+
required: body.required || '',
|
|
244
|
+
latestCli,
|
|
245
|
+
latestDesktop,
|
|
246
|
+
// Campaign is `version_gate`: a refusal to serve is its own reason to
|
|
247
|
+
// pay, distinct from a quota wall, and summing them hides which lever
|
|
248
|
+
// the upgrade prompt is actually pulling.
|
|
249
|
+
//
|
|
250
|
+
// Guarded on typeof, not called directly: the attribution helper is a
|
|
251
|
+
// separate concern from the gate, and a gate that throws because the
|
|
252
|
+
// campaign tagger is absent would turn "your client is old" into
|
|
253
|
+
// "undefined is not a function" on the one path whose whole job is to
|
|
254
|
+
// tell the user what to do. Falls back to the server's own update_url.
|
|
255
|
+
url: (typeof promptUrl === 'function' ? promptUrl('upgrade', 'version_gate') : '')
|
|
256
|
+
|| body.update_url
|
|
257
|
+
|| '',
|
|
258
|
+
};
|
|
259
|
+
return err;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Is this error body the version gate rather than a normal failure? */
|
|
263
|
+
function isVersionGate(status, data) {
|
|
264
|
+
return status === 426 || (data && data.code === 'version_mismatch');
|
|
265
|
+
}
|
|
266
|
+
|
|
177
267
|
async function parseResponse(res) {
|
|
178
268
|
const text = await res.text();
|
|
179
269
|
let data;
|
|
@@ -183,6 +273,9 @@ function createClient(opts = {}) {
|
|
|
183
273
|
data = { raw: text };
|
|
184
274
|
}
|
|
185
275
|
if (!res.ok) {
|
|
276
|
+
if (isVersionGate(res.status, data)) {
|
|
277
|
+
throw versionGateError(data, res.status);
|
|
278
|
+
}
|
|
186
279
|
const msg =
|
|
187
280
|
(data && (data.error?.message || data.error || data.message)) ||
|
|
188
281
|
`HTTP ${res.status}`;
|
|
@@ -191,6 +284,12 @@ function createClient(opts = {}) {
|
|
|
191
284
|
err.data = data;
|
|
192
285
|
throw err;
|
|
193
286
|
}
|
|
287
|
+
// A 2xx carrying a version gate body: some streaming endpoints answer
|
|
288
|
+
// JSON with a real status mid-stream. Without this the gate would be
|
|
289
|
+
// invisible on exactly those paths.
|
|
290
|
+
if (data && data.code === 'version_mismatch') {
|
|
291
|
+
throw versionGateError(data, res.status);
|
|
292
|
+
}
|
|
194
293
|
return data;
|
|
195
294
|
}
|
|
196
295
|
|
|
@@ -209,6 +308,12 @@ function createClient(opts = {}) {
|
|
|
209
308
|
/** Throw an Error carrying status/data from a 2xx body that still has an
|
|
210
309
|
* error field (seen on streaming endpoints that answer JSON mid-stream). */
|
|
211
310
|
function throwErrorFrom(data, status) {
|
|
311
|
+
// Keep the gate typed on this path too: it is the one that carries JSON
|
|
312
|
+
// errors inside an otherwise-successful stream, which is where a gate
|
|
313
|
+
// response would otherwise be flattened into a generic message.
|
|
314
|
+
if (data && data.code === 'version_mismatch') {
|
|
315
|
+
throw versionGateError(data, status || 426);
|
|
316
|
+
}
|
|
212
317
|
const msg = errorMessageOf(data);
|
|
213
318
|
if (!msg) return;
|
|
214
319
|
const err = new Error(msg);
|
|
@@ -223,8 +328,16 @@ function createClient(opts = {}) {
|
|
|
223
328
|
if (memoryTokenCache) return memoryTokenCache;
|
|
224
329
|
const info = await apiPost('/api/verify-api-key', { api_key: apiKey });
|
|
225
330
|
if (!info || !info.memory_token) {
|
|
331
|
+
// The campaign is Phase 1's `memory_quota`, not a new `memory_token`: the
|
|
332
|
+
// prompt family (memory cap notice, memory list, memory view) files under
|
|
333
|
+
// one id so the funnel keeps one row per prompt intent, and the plan's
|
|
334
|
+
// five ids are what the telemetry allowlist and the baseline table carry.
|
|
335
|
+
const link = promptUrl('upgrade', 'memory_quota');
|
|
226
336
|
throw new Error(
|
|
227
|
-
'This AEGIS account has no memory token.
|
|
337
|
+
'This AEGIS account has no memory token. '
|
|
338
|
+
+ (link
|
|
339
|
+
? `Enable cloud memory at ${link}`
|
|
340
|
+
: 'Enable cloud memory in your AEGIS account settings.')
|
|
228
341
|
);
|
|
229
342
|
}
|
|
230
343
|
memoryTokenCache = info.memory_token;
|
|
@@ -259,6 +372,19 @@ function createClient(opts = {}) {
|
|
|
259
372
|
return apiPost('/api/verify-api-key', { api_key: apiKey });
|
|
260
373
|
}
|
|
261
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Ask aegis1 for a free device key when the caller has none configured yet
|
|
377
|
+
* (`POST /api/v1/auth/register-device`). Idempotent server-side on
|
|
378
|
+
* `fingerprint` — the same fingerprint always returns the same account's
|
|
379
|
+
* key rather than minting a new one. The account starts at zero token-bank
|
|
380
|
+
* balance: this hands out an account, not free inference, so the existing
|
|
381
|
+
* balance=0 gate on `/api/v1/chat/completions` still applies unchanged.
|
|
382
|
+
* Sends no API key of its own — there isn't one yet.
|
|
383
|
+
*/
|
|
384
|
+
async function registerDevice(fingerprint, opts) {
|
|
385
|
+
return apiPost('/api/v1/auth/register-device', { fingerprint }, undefined, opts);
|
|
386
|
+
}
|
|
387
|
+
|
|
262
388
|
/** Build the OpenAI-style messages array from either a full history or the
|
|
263
389
|
* single-shot { system, prompt } shorthand.
|
|
264
390
|
*
|
|
@@ -464,6 +590,23 @@ function createClient(opts = {}) {
|
|
|
464
590
|
throw err; // network-level failure; nothing to fall back to
|
|
465
591
|
}
|
|
466
592
|
|
|
593
|
+
// A version gate is a pre-flight refusal, not a schema complaint: the
|
|
594
|
+
// server rejects *every* shape of this request with 426, so the
|
|
595
|
+
// `stream_options` retry below and the `stream: false` fallback after it
|
|
596
|
+
// each buy a wasted round-trip and then report an opaque status. Fail on
|
|
597
|
+
// the first one. Checked by status alone (no body read) so the happy path
|
|
598
|
+
// pays nothing for this.
|
|
599
|
+
if (!res.ok && res.status === 426) {
|
|
600
|
+
let gateData = {};
|
|
601
|
+
try {
|
|
602
|
+
const t = await res.text();
|
|
603
|
+
gateData = t ? JSON.parse(t) : {};
|
|
604
|
+
} catch {
|
|
605
|
+
gateData = {}; // a gate with an unreadable body is still a gate
|
|
606
|
+
}
|
|
607
|
+
throw versionGateError(gateData, res.status);
|
|
608
|
+
}
|
|
609
|
+
|
|
467
610
|
// Ask for the token count, but never at the cost of the stream: a server
|
|
468
611
|
// that predates `stream_options` rejects the request outright, so drop that
|
|
469
612
|
// one hint and put it back on the wire before falling back to a non-stream
|
|
@@ -860,7 +1003,12 @@ function createClient(opts = {}) {
|
|
|
860
1003
|
get clientVersion() {
|
|
861
1004
|
return clientVersion;
|
|
862
1005
|
},
|
|
1006
|
+
get channel() {
|
|
1007
|
+
return channel;
|
|
1008
|
+
},
|
|
1009
|
+
promptUrl,
|
|
863
1010
|
verifyApiKey,
|
|
1011
|
+
registerDevice,
|
|
864
1012
|
chatCompletion,
|
|
865
1013
|
byokChatCompletion,
|
|
866
1014
|
listModels,
|
|
@@ -951,7 +1099,18 @@ function idleBudgetFor(res, requestedMs) {
|
|
|
951
1099
|
return header && String(header).trim() ? Math.max(base, brainFloor) : base;
|
|
952
1100
|
}
|
|
953
1101
|
|
|
954
|
-
|
|
1102
|
+
/**
|
|
1103
|
+
* Host-facing predicate: does a thrown error mean "upgrade this client"?
|
|
1104
|
+
*
|
|
1105
|
+
* Hosts catch from a shared client, and a bare `err.status === 426` check
|
|
1106
|
+
* misses the gate bodies that arrive inside an otherwise-200 stream. Matched
|
|
1107
|
+
* on the typed `code` the client sets, so a host never has to parse prose.
|
|
1108
|
+
*/
|
|
1109
|
+
function isVersionGateError(err) {
|
|
1110
|
+
return !!(err && err.code === 'version_mismatch');
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const api = { createClient, envVar, randomUUID, DEFAULT_API_BASE, CLIENT_VERSION, isVersionGateError, idleBudgetFor, SSE_IDLE_TIMEOUT_MS, BRAIN_IDLE_TIMEOUT_MS };
|
|
955
1114
|
|
|
956
1115
|
// Node / Electron (CommonJS): the MCP plugin and desktop shell require() this.
|
|
957
1116
|
if (typeof module !== 'undefined' && module.exports) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auto-provision a free aegis1 device key when a host finds no key configured
|
|
5
|
+
* anywhere (env, the shared 0600 store, legacy config.json). One
|
|
6
|
+
* implementation shared by every host (MCP plugin, desktop, CLI) — see
|
|
7
|
+
* client/credentials.js's own header for why that matters here: three copies
|
|
8
|
+
* of the same timeout/endpoint/save logic is how they drift.
|
|
9
|
+
*
|
|
10
|
+
* Calls aegis1's `POST /api/v1/auth/register-device` (see client/aegis.js's
|
|
11
|
+
* `registerDevice`), idempotent per machine fingerprint (client/
|
|
12
|
+
* device-fingerprint.js) so a wiped credential store still resolves back to
|
|
13
|
+
* the same account rather than minting a new, unfunded one.
|
|
14
|
+
*
|
|
15
|
+
* The provisioned account starts at ZERO token-bank balance server-side, and
|
|
16
|
+
* aegis1 additionally requires an upgraded (paid, active) plan to use pooled
|
|
17
|
+
* aegiscloud models at all (nexus_chat_completions' is_pro() gate) — this
|
|
18
|
+
* only unblocks BYOK and account status/settings until the account is funded
|
|
19
|
+
* and/or upgraded. It is account creation, not a grant of free inference.
|
|
20
|
+
*/
|
|
21
|
+
const { machineFingerprint } = require('./device-fingerprint.js');
|
|
22
|
+
|
|
23
|
+
const DEVICE_REGISTER_TIMEOUT_MS = 8000;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} aegisClient A client from client/aegis.js (createClient()).
|
|
27
|
+
* @param {object} credentials client/credentials.js (or a compatible double).
|
|
28
|
+
* @returns {Promise<{ok: boolean, key: string, error?: Error}>}
|
|
29
|
+
* `ok` is true only when a usable key was obtained AND persisted to the
|
|
30
|
+
* shared store; `aegisClient.setApiKey()` has already been called on
|
|
31
|
+
* success, so the caller's client is immediately usable either way it
|
|
32
|
+
* inspects `ok`.
|
|
33
|
+
*/
|
|
34
|
+
async function autoProvisionApiKey(aegisClient, credentials) {
|
|
35
|
+
if (aegisClient.apiKey) return { ok: true, key: aegisClient.apiKey };
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const timer = setTimeout(() => controller.abort(), DEVICE_REGISTER_TIMEOUT_MS);
|
|
38
|
+
try {
|
|
39
|
+
const data = await aegisClient.registerDevice(machineFingerprint(), { signal: controller.signal });
|
|
40
|
+
const key = data && typeof data.api_key === 'string' ? data.api_key.trim() : '';
|
|
41
|
+
if (!key) return { ok: false, key: '' };
|
|
42
|
+
const saved = credentials.saveApiKey(key);
|
|
43
|
+
aegisClient.setApiKey(key);
|
|
44
|
+
return { ok: !!saved.ok, key };
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return { ok: false, key: '', error: err };
|
|
47
|
+
} finally {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { autoProvisionApiKey, DEVICE_REGISTER_TIMEOUT_MS };
|
|
@@ -307,6 +307,10 @@ function clientOptions(o = {}) {
|
|
|
307
307
|
const opts = {};
|
|
308
308
|
if (key) opts.apiKey = key;
|
|
309
309
|
if (token) opts.memoryToken = token;
|
|
310
|
+
// The host names itself so upgrade prompts raised inside the shared client
|
|
311
|
+
// are attributed to the right product. Unset means desktop, which matches
|
|
312
|
+
// createClient's own default.
|
|
313
|
+
if (o.channel) opts.channel = o.channel;
|
|
310
314
|
return opts;
|
|
311
315
|
}
|
|
312
316
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A stable per-machine identifier, used ONLY to ask aegis1 for a free device
|
|
5
|
+
* key (`POST /api/v1/auth/register-device`) when no key is configured yet. It
|
|
6
|
+
* is not a credential itself — the endpoint treats it as an idempotency key,
|
|
7
|
+
* so a wiped `~/.aegiscode` still resolves back to the same aegis1 account
|
|
8
|
+
* (and whatever balance it holds) instead of minting a fresh, unfunded one.
|
|
9
|
+
*
|
|
10
|
+
* Derivation mirrors ae-guix's `getMachineFingerprint()` (main.js) so the two
|
|
11
|
+
* hosts don't invent divergent conventions for the same idea: the OS's own
|
|
12
|
+
* machine identity where one exists, hashed with a purpose-specific prefix so
|
|
13
|
+
* it can never collide with a fingerprint minted for another purpose.
|
|
14
|
+
*/
|
|
15
|
+
const crypto = require('node:crypto');
|
|
16
|
+
const os = require('node:os');
|
|
17
|
+
|
|
18
|
+
/** Best-effort OS machine identity. Empty string, never throws, if none is reachable. */
|
|
19
|
+
function readMachineId() {
|
|
20
|
+
try {
|
|
21
|
+
if (process.platform === 'linux') {
|
|
22
|
+
const fs = require('node:fs');
|
|
23
|
+
try {
|
|
24
|
+
return fs.readFileSync('/etc/machine-id', 'utf8').trim();
|
|
25
|
+
} catch {
|
|
26
|
+
return fs.readFileSync('/var/lib/dbus/machine-id', 'utf8').trim();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (process.platform === 'darwin') {
|
|
30
|
+
const { execSync } = require('node:child_process');
|
|
31
|
+
const out = execSync('ioreg -rd1 -c IOPlatformExpertDevice', {
|
|
32
|
+
encoding: 'utf8',
|
|
33
|
+
timeout: 3000,
|
|
34
|
+
});
|
|
35
|
+
const m = out.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);
|
|
36
|
+
if (m) return m[1];
|
|
37
|
+
}
|
|
38
|
+
if (process.platform === 'win32') {
|
|
39
|
+
const { execSync } = require('node:child_process');
|
|
40
|
+
const out = execSync('reg query HKLM\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid', {
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
timeout: 3000,
|
|
43
|
+
});
|
|
44
|
+
const m = out.match(/MachineGuid\s+REG_SZ\s+(\S+)/);
|
|
45
|
+
if (m) return m[1];
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
/* no reachable machine id on this host — the caller falls back below */
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* sha256("aegiscode-plugin-device-v1:" + machine identity), hex.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} [overrideId] - test-only override for the raw machine identity.
|
|
57
|
+
*/
|
|
58
|
+
function machineFingerprint(overrideId) {
|
|
59
|
+
const id = overrideId || readMachineId() || `${os.hostname()}:${os.platform()}:${os.arch()}`;
|
|
60
|
+
return crypto.createHash('sha256').update(`aegiscode-plugin-device-v1:${id}`).digest('hex');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { machineFingerprint, readMachineId };
|
|
@@ -402,7 +402,28 @@ function errorText(err) {
|
|
|
402
402
|
* @param {object} [opts.git] Injectable git-scope (tests).
|
|
403
403
|
* @param {function} [opts.now] Clock.
|
|
404
404
|
*/
|
|
405
|
-
function createQueueWorker({
|
|
405
|
+
function createQueueWorker({
|
|
406
|
+
engine,
|
|
407
|
+
env = process.env,
|
|
408
|
+
log = () => {},
|
|
409
|
+
git = gitScope,
|
|
410
|
+
now = Date.now,
|
|
411
|
+
// May a task fan out AT ALL this session? The default preserves every host's
|
|
412
|
+
// behaviour (a CLI drain, a systemd timer: no entitlement, no clamp), and
|
|
413
|
+
// main.js passes the queue's entitlement gate — see
|
|
414
|
+
// desktop/lib/local/entitlement.js and Phase 4 of
|
|
415
|
+
// docs/upgrade-conversion-plan.md.
|
|
416
|
+
//
|
|
417
|
+
// This exists because the fan-out is otherwise reachable around the desktop's
|
|
418
|
+
// IPC gate: a task queued by the CLI or written into queue.jsonl by hand
|
|
419
|
+
// carries `singlePass: false`, and main.js had already accepted it long
|
|
420
|
+
// before anyone asked about entitlement. Refusing the whole task would be
|
|
421
|
+
// worse than the leak (the free tier keeps working — that is a promise), so
|
|
422
|
+
// the request is honoured as a SINGLE PASS and said out loud via a `note`
|
|
423
|
+
// frame: the run is clamped, never silently different from what the card
|
|
424
|
+
// shows.
|
|
425
|
+
canFanOut = () => true,
|
|
426
|
+
} = {}) {
|
|
406
427
|
if (!engine || typeof engine.chat !== 'function') {
|
|
407
428
|
throw new Error('autonomous: a local engine with chat() is required');
|
|
408
429
|
}
|
|
@@ -415,6 +436,18 @@ function createQueueWorker({ engine, env = process.env, log = () => {}, git = gi
|
|
|
415
436
|
}
|
|
416
437
|
};
|
|
417
438
|
|
|
439
|
+
/** `canFanOut` is host-supplied, so it is treated like any other injected
|
|
440
|
+
* seam: a predicate that throws must not abort a drain — it fails CLOSED
|
|
441
|
+
* (no fan-out), because the alternative is spending the multiplier the gate
|
|
442
|
+
* exists to withhold. */
|
|
443
|
+
const safeCanFanOut = () => {
|
|
444
|
+
try {
|
|
445
|
+
return canFanOut() !== false;
|
|
446
|
+
} catch {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
418
451
|
/**
|
|
419
452
|
* Run ONE queued task. Never throws: a failed task is data (so the drain can
|
|
420
453
|
* decide whether to continue), not an exception that aborts the queue.
|
|
@@ -437,7 +470,21 @@ function createQueueWorker({ engine, env = process.env, log = () => {}, git = gi
|
|
|
437
470
|
const model = resolveModel({ model: item.model, env });
|
|
438
471
|
const ignored = ignoredEnvModel({ model: item.model, env });
|
|
439
472
|
if (ignored) emit({ type: 'note', taskId: item.id, note: ignored });
|
|
440
|
-
const
|
|
473
|
+
const fanoutAsked = resolveFanout(item, env);
|
|
474
|
+
// The clamp. `canFanOut()` is the entitlement answer (true everywhere
|
|
475
|
+
// except a non-Pro desktop session), and it can only ever take a fan-out
|
|
476
|
+
// AWAY: a task the session is not entitled to fan out runs as one plain
|
|
477
|
+
// turn on the same tier, exactly like a `singlePass` task.
|
|
478
|
+
const fanout = fanoutAsked && safeCanFanOut();
|
|
479
|
+
if (fanoutAsked && !fanout) {
|
|
480
|
+
emit({
|
|
481
|
+
type: 'note',
|
|
482
|
+
taskId: item.id,
|
|
483
|
+
note:
|
|
484
|
+
'fan-out needs Pro (the cloud drain that keeps running after you close ' +
|
|
485
|
+
'the laptop) — this task ran as a single pass',
|
|
486
|
+
});
|
|
487
|
+
}
|
|
441
488
|
const effort = resolveEffort({ effort: item.effort, env, fanout });
|
|
442
489
|
const rounds = maxRounds(env, item.maxRounds);
|
|
443
490
|
// Approval requests have no one to answer them here; see the header.
|
|
@@ -496,6 +543,26 @@ function createQueueWorker({ engine, env = process.env, log = () => {}, git = gi
|
|
|
496
543
|
// the default for exactly that reason; the retry/write-up passes in
|
|
497
544
|
// the engine send `brain: false` for the same one-call reason.
|
|
498
545
|
autonomous: fanout,
|
|
546
|
+
// THE OPT-OUT HAS TO BE SAID OUT LOUD, or the clamp above is
|
|
547
|
+
// decoration. `autonomous: false` does NOT reach the wire as a
|
|
548
|
+
// "no fan-out": engine.js derives its brain flag as
|
|
549
|
+
// `opts.singlePass ? false : opts.autonomous ? true : undefined`, so
|
|
550
|
+
// false-and-not-singlePass evaluates to `undefined`, and an absent
|
|
551
|
+
// `brain` means "leave the model id's own default alone". The model
|
|
552
|
+
// here IS `nexus-brain`, and aegis1 services/pool_brain.py
|
|
553
|
+
// parse_brain_request enables the fan-out when
|
|
554
|
+
// `is_brain_model(spec)` — no flag or worker count required:
|
|
555
|
+
//
|
|
556
|
+
// enabled = not flag_off and (is_brain_model(spec) or flag_on or ...)
|
|
557
|
+
//
|
|
558
|
+
// So a clamped task went out asking for the full workers+1
|
|
559
|
+
// fan-out and got it, while the log said it ran as a single pass.
|
|
560
|
+
// `brain: false` is the only instruction that outranks the model id
|
|
561
|
+
// (pool_brain's own docstring: "the only way to ask for one provider
|
|
562
|
+
// call on a brain id"), and `singlePass: true` is how a caller
|
|
563
|
+
// produces it. This also fixes the plain `--single-pass` task, which
|
|
564
|
+
// never reached the wire as one for the same reason.
|
|
565
|
+
singlePass: !fanout,
|
|
499
566
|
effort,
|
|
500
567
|
workers: fanout ? item.workers || undefined : undefined,
|
|
501
568
|
// The turn's working directory rides on `env`: engine.js reads the
|
|
@@ -1296,6 +1296,16 @@ function createLocalEngine({
|
|
|
1296
1296
|
// field is off, which is what keeps every existing caller (the
|
|
1297
1297
|
// renderer's IPC payloads included) on the cheap read.
|
|
1298
1298
|
recallDeep: payload && payload.recallDeep === true,
|
|
1299
|
+
// The fan-out opt-out, and it must be an explicit `true` for the same
|
|
1300
|
+
// reason `recallDeep` is. `undefined` is NOT an opt-out: the wire flag
|
|
1301
|
+
// below is `singlePass ? false : autonomous ? true : undefined`, and an
|
|
1302
|
+
// absent `brain` flag lets the *model id* turn the fan-out on by itself
|
|
1303
|
+
// (aegis1 pool_brain.parse_brain_request: `is_brain_model(spec)` alone
|
|
1304
|
+
// enables it). So a clamped task on a brain model fanned out anyway
|
|
1305
|
+
// while the log claimed a single pass — the caller's intent never
|
|
1306
|
+
// reached the wire. Forwarding it here is what lets the refusal be real
|
|
1307
|
+
// rather than a local boolean nobody downstream could see.
|
|
1308
|
+
singlePass: payload && payload.singlePass === true,
|
|
1299
1309
|
onReasoning,
|
|
1300
1310
|
idleTimeoutMs: autonomous ? AUTONOMOUS_IDLE_TIMEOUT_MS : undefined,
|
|
1301
1311
|
// A caller with no live streaming surface (a `--no-stream` CLI flag, a
|