aegiscode 6.8.4 → 6.8.6
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/README.md +2 -2
- package/package.json +1 -6
- package/scripts/predist.mjs +7 -0
- package/src/agents.js +1 -1
- package/src/app.js +2 -2
- package/src/autonomous.js +93 -3
- package/src/caps.js +1 -1
- package/src/chatflow.js +1 -1
- package/src/checkpoint.js +1 -1
- package/src/clipboard.js +1 -1
- package/src/commands.js +5 -5
- package/src/config.js +2 -2
- package/src/devrun.js +1 -1
- package/src/diff.js +1 -1
- package/src/entitlement.js +108 -0
- package/src/events.js +2 -2
- package/src/export.js +1 -1
- package/src/fuzzy.js +1 -1
- package/src/history.js +3 -3
- package/src/init.js +1 -1
- package/src/input.js +1 -1
- package/src/keys.js +1 -1
- package/src/markdown.js +2 -2
- package/src/overlays.js +2 -2
- package/src/panels.js +6 -6
- package/src/permissions.js +2 -2
- package/src/render.js +2 -2
- package/src/screen.js +4 -4
- package/src/screens.js +1 -1
- package/src/summarize.js +1 -1
- package/src/system.js +2 -2
- package/src/theme.js +6 -6
- package/src/tokens.js +2 -2
- package/src/update.js +1 -1
- package/vendor/client/aegis.js +146 -2
- package/vendor/client/credentials.js +4 -0
- package/vendor/desktop/lib/local/agents.js +1 -1
- package/vendor/desktop/lib/local/autonomous.js +70 -3
- package/vendor/desktop/lib/local/engine.js +19 -9
- package/vendor/desktop/lib/local/entitlement.js +487 -0
- package/vendor/desktop/lib/local/git-scope.js +1 -1
- package/vendor/desktop/lib/local/prompt.js +3 -3
- package/vendor/desktop/lib/local/queue.js +2 -2
- package/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/desktop/lib/local/tools.js +2 -2
- package/vendor/desktop/lib/local/turn-guard.js +1 -1
- package/vendor/desktop/lib/local/worktree-lock.js +1 -1
- package/vendor/desktop/lib/settings.js +36 -3
- package/vendor/desktop/renderer/usage.js +6 -6
- package/vendor/mcp/tools.js +9 -1
package/src/render.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The CLI's renderers — the start-up banner, transcript turns, the per-turn
|
|
5
5
|
* accounting line, the status bar, the live working line and the transcript's
|
|
6
6
|
* markdown body. The presentation layer is a fidelity port of
|
|
7
|
-
*
|
|
7
|
+
* the upstream engine: gold `━`/`─` rules, the one-ink ÆGIS wordmark (box runes,
|
|
8
8
|
* in gold), the coral-bold welcome title, the `❯` prompt, the
|
|
9
9
|
* `⎿` hook rows, the `●` answer/stream cursor and the `✻` done glyph.
|
|
10
10
|
*
|
|
@@ -397,7 +397,7 @@ function renderToolResult(ctx, name, text, width = 80) {
|
|
|
397
397
|
/**
|
|
398
398
|
* The tool-approval card: the mutating call the model wants to run (a diff
|
|
399
399
|
* for writeFile/editFile, the command for exec) and the three answers. One
|
|
400
|
-
* inline question, matching
|
|
400
|
+
* inline question, matching the upstream engine's Bash/edit approval dialog.
|
|
401
401
|
*/
|
|
402
402
|
function renderApproval(ctx, info = {}, width = 80) {
|
|
403
403
|
const t = themeOf(ctx);
|
package/src/screen.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* wrapping, and the ephemeral "live" region the CLI redraws while a call is in
|
|
6
6
|
* flight.
|
|
7
7
|
*
|
|
8
|
-
* The render model is
|
|
8
|
+
* The render model is the upstream engine's: a line is an array of spans
|
|
9
9
|
* `{ t: text, s: style-prefix, w: cell-width }`, built with `span()`, measured
|
|
10
10
|
* with `lineWidth()`, padded/truncated with `padLine()`, and painted with
|
|
11
11
|
* `paint()`. Two width functions exist because they have different callers:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* per-codepoint maths for a span line (the overlays use it).
|
|
15
15
|
*
|
|
16
16
|
* Design note — this CLI is a LINEAR transcript, not a full-screen alt-buffer
|
|
17
|
-
* TUI (which is what Claude Code and
|
|
17
|
+
* TUI (which is what Claude Code and the upstream engine are). Finished turns are
|
|
18
18
|
* written once to scrollback, so output stays selectable, pipeable and
|
|
19
19
|
* scrollback-searchable; only the one live status/spinner line is redrawn. The
|
|
20
20
|
* main session loop deliberately does NOT enter the alternate screen — `--print`
|
|
@@ -249,7 +249,7 @@ const SELECT_OFF = '\x1b[27m';
|
|
|
249
249
|
// `frameLines`). All of it is pure and cell-based: coordinates are grid row +
|
|
250
250
|
// CELL column (0-based), never string indices, so wide glyphs and padded rows
|
|
251
251
|
// can't shift the selection off the text the reader is pointing at.
|
|
252
|
-
// Ported from
|
|
252
|
+
// Ported from the upstream engine reference so both hosts mark identically.
|
|
253
253
|
|
|
254
254
|
/** Two drag endpoints → the same range in reading order (top-left first). */
|
|
255
255
|
function selectionRange(a, b) {
|
|
@@ -444,7 +444,7 @@ module.exports = {
|
|
|
444
444
|
stripAnsi,
|
|
445
445
|
wrapLine,
|
|
446
446
|
wrapBlock,
|
|
447
|
-
// span/line render model (from
|
|
447
|
+
// span/line render model (from the upstream engine)
|
|
448
448
|
span,
|
|
449
449
|
lineWidth,
|
|
450
450
|
padLine,
|
package/src/screens.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Onboarding screens — trust check, theme picker, welcome.
|
|
5
5
|
*
|
|
6
|
-
* A direct port of
|
|
6
|
+
* A direct port of the upstream engine reference, which is where the
|
|
7
7
|
* reference's session actually begins: a genuine first run is
|
|
8
8
|
*
|
|
9
9
|
* showTrustCheck(ctx) → showThemePicker(ctx) → updateConfig() → welcome
|
package/src/summarize.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Transcript summarization for /compact and /recap.
|
|
5
5
|
*
|
|
6
|
-
* Dependency-free port of
|
|
6
|
+
* Dependency-free port of the upstream engine reference. The reference
|
|
7
7
|
* spawns `claude -p "Summarize…"` (via platform.resolveExecutable); here the
|
|
8
8
|
* backend is *injected* instead, so this module pulls in nothing but tokens.js:
|
|
9
9
|
*
|
package/src/system.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Small system helpers: best-effort URL opening (never blocks or errors) and
|
|
5
5
|
* a few constants shared by the support/easter-egg commands.
|
|
6
6
|
*
|
|
7
|
-
* Ported from
|
|
7
|
+
* Ported from the upstream engine reference (ESM → CommonJS). The URLS table
|
|
8
8
|
* pointed at Anthropic/Claude support endpoints; those are re-homed to the
|
|
9
9
|
* AEGIS base (https://aegiscloud.org) and the project repo. Deep paths that
|
|
10
10
|
* had no AEGIS equivalent collapse to the base rather than inventing a route.
|
|
@@ -29,7 +29,7 @@ function openUrl(url) {
|
|
|
29
29
|
const URLS = {
|
|
30
30
|
troubleshooting: 'https://aegiscloud.org',
|
|
31
31
|
feedback: 'https://aegiscloud.org',
|
|
32
|
-
issues: 'https://
|
|
32
|
+
issues: 'https://aegiscloud.org',
|
|
33
33
|
docs: 'https://aegiscloud.org',
|
|
34
34
|
radio: 'https://www.youtube.com/watch?v=cP8jB6YQWbQ',
|
|
35
35
|
};
|
package/src/theme.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Design tokens — the
|
|
4
|
+
* Design tokens — the upstream engine design system, adopted wholesale, and
|
|
5
5
|
* resolved through the terminal's capabilities (`caps.js`) rather than the
|
|
6
6
|
* platform the process happens to run on.
|
|
7
7
|
*
|
|
8
|
-
* Every colour value below is copied verbatim from
|
|
8
|
+
* Every colour value below is copied verbatim from the upstream engine's theme,
|
|
9
9
|
* which extracted them from the live ANSI stream of Claude Code: gold 255,193,7
|
|
10
10
|
* · coral 215,119,87 · lavender 177,185,249 · blue 120,160,250 · green 78,186,101
|
|
11
11
|
* · red 220,90,90 · gray 153,153,153 · dim 80,80,80. `test/cli-conformance.test.mjs`
|
|
12
|
-
* pins them to
|
|
12
|
+
* pins them to the upstream engine's source and reads them back out of a truecolor
|
|
13
13
|
* SGR prefix, so the design cannot drift.
|
|
14
14
|
*
|
|
15
15
|
* What DOES change per terminal is how those triples reach the screen:
|
|
@@ -61,7 +61,7 @@ const BG = (r, g, b) => bg(r, g, b);
|
|
|
61
61
|
// capability change keeps the key set identical (the conformance guard pins
|
|
62
62
|
// `Object.keys(C)`) while the escapes follow the new depth.
|
|
63
63
|
|
|
64
|
-
/** The dark palette. Role names match
|
|
64
|
+
/** The dark palette. Role names match the upstream engine exactly. */
|
|
65
65
|
const C = {};
|
|
66
66
|
/** Light-theme approximations, true to the dark palette's hue mapping. */
|
|
67
67
|
const LIGHT = {};
|
|
@@ -148,7 +148,7 @@ function buildAnsiLight() {
|
|
|
148
148
|
/**
|
|
149
149
|
* Diff palette for edit blocks in the transcript — Monokai Extended, taken
|
|
150
150
|
* verbatim from the theme picker's preview (also `renderDiffPreview` in
|
|
151
|
-
*
|
|
151
|
+
* the upstream engine's markdown renderer) so the two can never drift apart: dim
|
|
152
152
|
* red/green backgrounds per row, the bright variant for the token that
|
|
153
153
|
* actually changed inside the row, and the monokai syntax colors for the code
|
|
154
154
|
* itself.
|
|
@@ -217,7 +217,7 @@ const THEMES = { dark: C, light: LIGHT };
|
|
|
217
217
|
* remapped anyway — the whole point being that the *terminal* decides, not us.
|
|
218
218
|
*/
|
|
219
219
|
/**
|
|
220
|
-
* The theme picker's table, copied from
|
|
220
|
+
* The theme picker's table, copied from the upstream engine's screens THEMES
|
|
221
221
|
* (names and notes verbatim). `light` is the flag the reference sets on commit
|
|
222
222
|
* (`ctx.light = sel === 2 || sel === 4 || sel === 6`); `palette` is what this
|
|
223
223
|
* client resolves the row to, since it has no terminal-background probe and so
|
package/src/tokens.js
CHANGED
|
@@ -144,7 +144,7 @@ function sessionAccounting(transcript, model = 'sonnet') {
|
|
|
144
144
|
// the wall clock for peak/off-peak, so two evaluations straddling a peak
|
|
145
145
|
// boundary would report a peak cost with an off-peak basis (or vice versa) —
|
|
146
146
|
// two different claims about the same number, which is the thing this return
|
|
147
|
-
// shape exists to prevent.
|
|
147
|
+
// shape exists to prevent. The upstream engine's sessionAccounting is written the
|
|
148
148
|
// same way; if one host folds this into two calls again the two will disagree
|
|
149
149
|
// about the same turn, which is how the rate table split in the first place.
|
|
150
150
|
const breakdown = costBreakdown(usage, model);
|
|
@@ -166,7 +166,7 @@ function sessionAccounting(transcript, model = 'sonnet') {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
169
|
+
* Build the same accounting shape from summed history.jsonl token
|
|
170
170
|
* records (live usage numbers when `real`, estimated otherwise). Real usage
|
|
171
171
|
* already includes system prompt + tools in cacheRead, so `used` counts
|
|
172
172
|
* input + output + cache instead of re-adding the constants.
|
package/src/update.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* On top of the shared checker this module carries the three pieces /upgrade
|
|
12
12
|
* needs — `compareVersions`, `upgradeAdvice` and `latestPublishedVersion` —
|
|
13
|
-
* ported from the reference
|
|
13
|
+
* ported from the upstream engine reference. They belong
|
|
14
14
|
* here, next to `isNewer`/`updateLine`, so the CLI has ONE idea of "is there a
|
|
15
15
|
* newer published version": the welcome-box notice and /upgrade now answer
|
|
16
16
|
* from the same place and compare versions the same way. The shared module's
|
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
|
// -------------------------------------------------------------------------
|
|
@@ -174,6 +206,63 @@ function createClient(opts = {}) {
|
|
|
174
206
|
return parseResponse(res);
|
|
175
207
|
}
|
|
176
208
|
|
|
209
|
+
/**
|
|
210
|
+
* A 426 `version_mismatch` from either server gate: this client is too old
|
|
211
|
+
* to be served. The body carries the minimum it failed (`required`), the
|
|
212
|
+
* npm dist-tags to move to (`latest_cli`/`latest_desktop`) and where to get
|
|
213
|
+
* them, so a host can show an upgrade prompt naming a target instead of a
|
|
214
|
+
* bare "connection refused".
|
|
215
|
+
*
|
|
216
|
+
* Surfaced as a typed error (`code` + `upgrade`) rather than only a message
|
|
217
|
+
* so hosts can branch on it without parsing prose, and so the desktop/MCP
|
|
218
|
+
* shells can open the upgrade panel with a version already filled in.
|
|
219
|
+
*
|
|
220
|
+
* The upgrade link is rebuilt through promptUrl() rather than trusting
|
|
221
|
+
* `update_url` verbatim: a server-supplied bare URL carries no `?s=`/`?c=`,
|
|
222
|
+
* so the click is filed as `direct` and the surface that hit the gate can
|
|
223
|
+
* never be credited for the conversion it caused. The server value is kept
|
|
224
|
+
* as a fallback for hosts reaching a base we cannot parse.
|
|
225
|
+
*/
|
|
226
|
+
function versionGateError(data, status) {
|
|
227
|
+
const body = data || {};
|
|
228
|
+
const latestCli = body.latest_cli || '';
|
|
229
|
+
const latestDesktop = body.latest_desktop || '';
|
|
230
|
+
// Prefer a real published version; fall back to the minimum so the
|
|
231
|
+
// message always names something the user can act on.
|
|
232
|
+
const target = latestCli || latestDesktop || body.required || '';
|
|
233
|
+
const err = new Error(
|
|
234
|
+
target
|
|
235
|
+
? `This client (v${clientVersion}) is out of date — upgrade to v${target}.`
|
|
236
|
+
: `This client (v${clientVersion}) is out of date.`
|
|
237
|
+
);
|
|
238
|
+
err.status = status;
|
|
239
|
+
err.code = 'version_mismatch';
|
|
240
|
+
err.data = body;
|
|
241
|
+
err.upgrade = {
|
|
242
|
+
required: body.required || '',
|
|
243
|
+
latestCli,
|
|
244
|
+
latestDesktop,
|
|
245
|
+
// Campaign is `version_gate`: a refusal to serve is its own reason to
|
|
246
|
+
// pay, distinct from a quota wall, and summing them hides which lever
|
|
247
|
+
// the upgrade prompt is actually pulling.
|
|
248
|
+
//
|
|
249
|
+
// Guarded on typeof, not called directly: the attribution helper is a
|
|
250
|
+
// separate concern from the gate, and a gate that throws because the
|
|
251
|
+
// campaign tagger is absent would turn "your client is old" into
|
|
252
|
+
// "undefined is not a function" on the one path whose whole job is to
|
|
253
|
+
// tell the user what to do. Falls back to the server's own update_url.
|
|
254
|
+
url: (typeof promptUrl === 'function' ? promptUrl('upgrade', 'version_gate') : '')
|
|
255
|
+
|| body.update_url
|
|
256
|
+
|| '',
|
|
257
|
+
};
|
|
258
|
+
return err;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Is this error body the version gate rather than a normal failure? */
|
|
262
|
+
function isVersionGate(status, data) {
|
|
263
|
+
return status === 426 || (data && data.code === 'version_mismatch');
|
|
264
|
+
}
|
|
265
|
+
|
|
177
266
|
async function parseResponse(res) {
|
|
178
267
|
const text = await res.text();
|
|
179
268
|
let data;
|
|
@@ -183,6 +272,9 @@ function createClient(opts = {}) {
|
|
|
183
272
|
data = { raw: text };
|
|
184
273
|
}
|
|
185
274
|
if (!res.ok) {
|
|
275
|
+
if (isVersionGate(res.status, data)) {
|
|
276
|
+
throw versionGateError(data, res.status);
|
|
277
|
+
}
|
|
186
278
|
const msg =
|
|
187
279
|
(data && (data.error?.message || data.error || data.message)) ||
|
|
188
280
|
`HTTP ${res.status}`;
|
|
@@ -191,6 +283,12 @@ function createClient(opts = {}) {
|
|
|
191
283
|
err.data = data;
|
|
192
284
|
throw err;
|
|
193
285
|
}
|
|
286
|
+
// A 2xx carrying a version gate body: some streaming endpoints answer
|
|
287
|
+
// JSON with a real status mid-stream. Without this the gate would be
|
|
288
|
+
// invisible on exactly those paths.
|
|
289
|
+
if (data && data.code === 'version_mismatch') {
|
|
290
|
+
throw versionGateError(data, res.status);
|
|
291
|
+
}
|
|
194
292
|
return data;
|
|
195
293
|
}
|
|
196
294
|
|
|
@@ -209,6 +307,12 @@ function createClient(opts = {}) {
|
|
|
209
307
|
/** Throw an Error carrying status/data from a 2xx body that still has an
|
|
210
308
|
* error field (seen on streaming endpoints that answer JSON mid-stream). */
|
|
211
309
|
function throwErrorFrom(data, status) {
|
|
310
|
+
// Keep the gate typed on this path too: it is the one that carries JSON
|
|
311
|
+
// errors inside an otherwise-successful stream, which is where a gate
|
|
312
|
+
// response would otherwise be flattened into a generic message.
|
|
313
|
+
if (data && data.code === 'version_mismatch') {
|
|
314
|
+
throw versionGateError(data, status || 426);
|
|
315
|
+
}
|
|
212
316
|
const msg = errorMessageOf(data);
|
|
213
317
|
if (!msg) return;
|
|
214
318
|
const err = new Error(msg);
|
|
@@ -223,8 +327,16 @@ function createClient(opts = {}) {
|
|
|
223
327
|
if (memoryTokenCache) return memoryTokenCache;
|
|
224
328
|
const info = await apiPost('/api/verify-api-key', { api_key: apiKey });
|
|
225
329
|
if (!info || !info.memory_token) {
|
|
330
|
+
// The campaign is Phase 1's `memory_quota`, not a new `memory_token`: the
|
|
331
|
+
// prompt family (memory cap notice, memory list, memory view) files under
|
|
332
|
+
// one id so the funnel keeps one row per prompt intent, and the plan's
|
|
333
|
+
// five ids are what the telemetry allowlist and the baseline table carry.
|
|
334
|
+
const link = promptUrl('upgrade', 'memory_quota');
|
|
226
335
|
throw new Error(
|
|
227
|
-
'This AEGIS account has no memory token.
|
|
336
|
+
'This AEGIS account has no memory token. '
|
|
337
|
+
+ (link
|
|
338
|
+
? `Enable cloud memory at ${link}`
|
|
339
|
+
: 'Enable cloud memory in your AEGIS account settings.')
|
|
228
340
|
);
|
|
229
341
|
}
|
|
230
342
|
memoryTokenCache = info.memory_token;
|
|
@@ -464,6 +576,23 @@ function createClient(opts = {}) {
|
|
|
464
576
|
throw err; // network-level failure; nothing to fall back to
|
|
465
577
|
}
|
|
466
578
|
|
|
579
|
+
// A version gate is a pre-flight refusal, not a schema complaint: the
|
|
580
|
+
// server rejects *every* shape of this request with 426, so the
|
|
581
|
+
// `stream_options` retry below and the `stream: false` fallback after it
|
|
582
|
+
// each buy a wasted round-trip and then report an opaque status. Fail on
|
|
583
|
+
// the first one. Checked by status alone (no body read) so the happy path
|
|
584
|
+
// pays nothing for this.
|
|
585
|
+
if (!res.ok && res.status === 426) {
|
|
586
|
+
let gateData = {};
|
|
587
|
+
try {
|
|
588
|
+
const t = await res.text();
|
|
589
|
+
gateData = t ? JSON.parse(t) : {};
|
|
590
|
+
} catch {
|
|
591
|
+
gateData = {}; // a gate with an unreadable body is still a gate
|
|
592
|
+
}
|
|
593
|
+
throw versionGateError(gateData, res.status);
|
|
594
|
+
}
|
|
595
|
+
|
|
467
596
|
// Ask for the token count, but never at the cost of the stream: a server
|
|
468
597
|
// that predates `stream_options` rejects the request outright, so drop that
|
|
469
598
|
// one hint and put it back on the wire before falling back to a non-stream
|
|
@@ -860,6 +989,10 @@ function createClient(opts = {}) {
|
|
|
860
989
|
get clientVersion() {
|
|
861
990
|
return clientVersion;
|
|
862
991
|
},
|
|
992
|
+
get channel() {
|
|
993
|
+
return channel;
|
|
994
|
+
},
|
|
995
|
+
promptUrl,
|
|
863
996
|
verifyApiKey,
|
|
864
997
|
chatCompletion,
|
|
865
998
|
byokChatCompletion,
|
|
@@ -951,7 +1084,18 @@ function idleBudgetFor(res, requestedMs) {
|
|
|
951
1084
|
return header && String(header).trim() ? Math.max(base, brainFloor) : base;
|
|
952
1085
|
}
|
|
953
1086
|
|
|
954
|
-
|
|
1087
|
+
/**
|
|
1088
|
+
* Host-facing predicate: does a thrown error mean "upgrade this client"?
|
|
1089
|
+
*
|
|
1090
|
+
* Hosts catch from a shared client, and a bare `err.status === 426` check
|
|
1091
|
+
* misses the gate bodies that arrive inside an otherwise-200 stream. Matched
|
|
1092
|
+
* on the typed `code` the client sets, so a host never has to parse prose.
|
|
1093
|
+
*/
|
|
1094
|
+
function isVersionGateError(err) {
|
|
1095
|
+
return !!(err && err.code === 'version_mismatch');
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
const api = { createClient, envVar, randomUUID, DEFAULT_API_BASE, CLIENT_VERSION, isVersionGateError, idleBudgetFor, SSE_IDLE_TIMEOUT_MS, BRAIN_IDLE_TIMEOUT_MS };
|
|
955
1099
|
|
|
956
1100
|
// Node / Electron (CommonJS): the MCP plugin and desktop shell require() this.
|
|
957
1101
|
if (typeof module !== 'undefined' && module.exports) {
|
|
@@ -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
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* agents.js — subagent prompt presets for the desktop `task` tool, ported
|
|
5
|
-
* from
|
|
5
|
+
* from the upstream engine reference (same roles, same synthesis presets).
|
|
6
6
|
* A preset is a system prompt: `task` runs it through the normal engine.chat
|
|
7
7
|
* loop as a nested turn (its own tool rounds, same model class), not a
|
|
8
8
|
* separate runtime, so the presets are pure prompt composition.
|
|
@@ -311,7 +311,7 @@ function resolveEffort({ effort, env, fanout } = {}) {
|
|
|
311
311
|
|
|
312
312
|
/**
|
|
313
313
|
* The operating directive injected as the autonomous turn's prompt preamble.
|
|
314
|
-
* Ported verbatim in spirit from
|
|
314
|
+
* Ported verbatim in spirit from the upstream engine reference so both
|
|
315
315
|
* clients behave the same; duplicated rather than vendored because the plugin
|
|
316
316
|
* hosts no ESM build of that module.
|
|
317
317
|
*/
|
|
@@ -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
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* chosen class is the user's explicit selection.
|
|
9
9
|
*
|
|
10
10
|
* Since the tool-calling port it ALSO owns the agent loop (the client half of
|
|
11
|
-
*
|
|
11
|
+
* the upstream engine's src/backend.js runProvider): every turn carries a real
|
|
12
12
|
* system prompt (prompt.js) and the builtin tool schemas (tools.js), and when
|
|
13
13
|
* a provider answers with tool calls the loop executes them in-process and
|
|
14
14
|
* feeds the results back for as many rounds as the model keeps calling tools
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* executor never has to be exposed to the renderer.
|
|
28
28
|
*
|
|
29
29
|
* Two turn-scoped resources ride along with the loop, mirroring
|
|
30
|
-
*
|
|
30
|
+
* the upstream engine's runProvider exactly:
|
|
31
31
|
* - a lazily-started ShellSession (shell.js) that the `exec` tool shares,
|
|
32
32
|
* so cd/export state persists across calls within one turn instead of
|
|
33
33
|
* each call spawning a fresh process;
|
|
@@ -159,7 +159,7 @@ function providerKeyFromEnv(provider) {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
* Mirrors
|
|
162
|
+
* Mirrors the upstream engine's src/backend.js DEEPSEEK_REASONING_MODEL_RE +
|
|
163
163
|
* EFFORT_TOKEN_BUDGET verbatim. DeepSeek's reasoning models (deepseek-flash,
|
|
164
164
|
* i.e. "Flash 4.1", deepseek-v4-pro, the deprecated deepseek-reasoner, and the
|
|
165
165
|
* legacy v4-flash/v4.1-flash aliases some configs still carry) spend part of
|
|
@@ -170,7 +170,7 @@ function providerKeyFromEnv(provider) {
|
|
|
170
170
|
* tool calls, just a turn that "completes" with nothing to show for it (the
|
|
171
171
|
* empty-response bug). A user pointing the Custom OpenAI-compatible class
|
|
172
172
|
* straight at DeepSeek's API hits exactly this, so the request is sized by the
|
|
173
|
-
* same effort budget
|
|
173
|
+
* same effort budget the upstream engine uses for its own direct DeepSeek calls.
|
|
174
174
|
*
|
|
175
175
|
* desktop/renderer/budget.js carries the renderer's copy of these two
|
|
176
176
|
* constants plus budgetFor() below; test/budget.test.mjs requires both and
|
|
@@ -437,7 +437,7 @@ function createLocalEngine({
|
|
|
437
437
|
settings,
|
|
438
438
|
tools,
|
|
439
439
|
promptBuilder,
|
|
440
|
-
//
|
|
440
|
+
// The level's recall breadth, injected by the host that owns the
|
|
441
441
|
// avatar ledger (desktop/main.js builds one from lib/avatar/turn.js). It is a
|
|
442
442
|
// SEAM rather than a call into lib/avatar/* because this engine is shared with
|
|
443
443
|
// the CLI (cli/src/deps.js loads this file): the engine must not grow a
|
|
@@ -920,7 +920,7 @@ function createLocalEngine({
|
|
|
920
920
|
// that used to claim a figure for the pooled class is gone — see
|
|
921
921
|
// desktop/renderer/budget.js). Omitting the field is
|
|
922
922
|
// what tells aegis1 "no cap stated — let effort decide", the same
|
|
923
|
-
// contract
|
|
923
|
+
// contract the upstream engine sends.
|
|
924
924
|
//
|
|
925
925
|
// A cap the caller DID state is a different thing, and dropping it was
|
|
926
926
|
// a bug: aegis1 reads a body max_tokens as a ceiling over its ladder,
|
|
@@ -960,7 +960,7 @@ function createLocalEngine({
|
|
|
960
960
|
//
|
|
961
961
|
// Writing is still available, explicitly: the aegis_memory_save tool
|
|
962
962
|
// (mcp/tools.js; the CLI exposes it as /memory). Recall on every turn,
|
|
963
|
-
// store only what the user asks for — which is what
|
|
963
|
+
// store only what the user asks for — which is what the upstream engine's
|
|
964
964
|
// own cross-session memory does, and what this comment claimed to
|
|
965
965
|
// match while sending both halves.
|
|
966
966
|
//
|
|
@@ -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
|
|
@@ -1324,7 +1334,7 @@ function createLocalEngine({
|
|
|
1324
1334
|
let truncationRetried = false;
|
|
1325
1335
|
let synthesisDone = false;
|
|
1326
1336
|
|
|
1327
|
-
// Round cap —
|
|
1337
|
+
// Round cap — a bound the upstream engine has had all along and this engine
|
|
1328
1338
|
// did not. Removing the old fixed cap (12) was right in spirit and wrong
|
|
1329
1339
|
// in effect: it left the turn with NO horizon, and on 2026-09-15 the
|
|
1330
1340
|
// question "can you check the plan" ran ~70 rounds, grew the context
|
|
@@ -1333,7 +1343,7 @@ function createLocalEngine({
|
|
|
1333
1343
|
// re-sends the whole conversation, so an unbounded loop gets more
|
|
1334
1344
|
// expensive the longer it runs.
|
|
1335
1345
|
//
|
|
1336
|
-
// The numbers match
|
|
1346
|
+
// The numbers match the upstream engine's (src/autonomous.js) so both clients
|
|
1337
1347
|
// behave the same: 24 rounds for a chat turn, 40 for an autonomous one.
|
|
1338
1348
|
// Env-overridable for a deliberately long job.
|
|
1339
1349
|
// A stated horizon (env) still wins outright — an explicit number is the
|