aegiscode 7.0.10 → 7.0.11
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 +1 -1
- package/src/app.js +125 -8
- package/src/autonomous.js +19 -2
- package/src/chatflow.js +77 -4
- package/src/commands.js +175 -5
- package/src/config.js +14 -0
- package/src/deps.js +97 -1
- package/src/engine.js +84 -8
- package/src/limits.js +1 -1
- package/src/overlays.js +54 -0
- package/src/provenance.lock.json +2 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.11",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
package/src/app.js
CHANGED
|
@@ -27,7 +27,7 @@ const readline = require('node:readline');
|
|
|
27
27
|
const os = require('node:os');
|
|
28
28
|
const { randomUUID } = require('node:crypto');
|
|
29
29
|
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, provisionFailureText, trialNote, hostEnv, autonomous, claudePro } = require('./deps.js');
|
|
30
|
-
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung } = require('./engine.js');
|
|
30
|
+
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung, offeredClasses, proEnabled } = require('./engine.js');
|
|
31
31
|
const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE, AUTO_THEME_INDEX, themeIsLight, reconcileThemeIndex } = require('./theme.js');
|
|
32
32
|
const { probeTerminalBackground } = require('./caps.js');
|
|
33
33
|
const { LiveRegion, termWidth, w } = require('./screen.js');
|
|
@@ -225,6 +225,18 @@ function createApp(options = {}) {
|
|
|
225
225
|
// reason confirmMode is a callback: a captured value made `/class`
|
|
226
226
|
// cosmetic, changing the panel and not what the next turn ran on.
|
|
227
227
|
getClass: () => commandCtx.modelClass,
|
|
228
|
+
// Whether the `pro` class is enabled (config.js `proEnabled`, off by
|
|
229
|
+
// default). Read per call for the same reason getClass is: `/class pro
|
|
230
|
+
// off` must remove it from the picker and stop the very next turn, not
|
|
231
|
+
// the next launch. A read failure answers "off" — fail closed, because
|
|
232
|
+
// the alternative spends a subscription nobody opted into.
|
|
233
|
+
getProEnabled: () => {
|
|
234
|
+
try {
|
|
235
|
+
return proEnabled(loadConfig());
|
|
236
|
+
} catch {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
228
240
|
getConfirmMode: () => {
|
|
229
241
|
if (options.confirmMode !== undefined) return confirmMode;
|
|
230
242
|
// AEGISONE D8 rule 5 — the skip posture, resolved by the SAME function
|
|
@@ -652,7 +664,14 @@ function createApp(options = {}) {
|
|
|
652
664
|
* able to chat on the server's own default.
|
|
653
665
|
*/
|
|
654
666
|
async function listModelsFor(cls) {
|
|
655
|
-
|
|
667
|
+
// The OFFERED set, not HOST_CLASSES: a class that is not selectable (a
|
|
668
|
+
// disabled `pro`) yields NOTHING rather than the live class's rows. The
|
|
669
|
+
// merged picker tags whatever comes back as belonging to the class it
|
|
670
|
+
// asked about, so substituting pooled rows here would paint pooled ids as
|
|
671
|
+
// Pro rows — and pinning one would move the session onto the subscription.
|
|
672
|
+
const allowed = selectableClasses();
|
|
673
|
+
if (cls && !allowed.includes(cls) && HOST_CLASSES.includes(cls)) return [];
|
|
674
|
+
const want = allowed.includes(cls) ? cls : commandCtx.modelClass;
|
|
656
675
|
try {
|
|
657
676
|
if (want === 'byok') {
|
|
658
677
|
const byok = await loadByokModels();
|
|
@@ -777,7 +796,13 @@ function createApp(options = {}) {
|
|
|
777
796
|
* not on; only an absent/unknown `cls` may fall back to the live one.
|
|
778
797
|
*/
|
|
779
798
|
function classScopedModels(byokOverride, cls) {
|
|
780
|
-
const
|
|
799
|
+
const allowed = selectableClasses();
|
|
800
|
+
const want = allowed.includes(cls) ? cls : commandCtx.modelClass;
|
|
801
|
+
// A disabled `pro` yields no rows at all — not the pooled ones either,
|
|
802
|
+
// because the caller asked for pro's id space and answering with pooled ids
|
|
803
|
+
// is the cross-class mix-up this branch exists to prevent (the merged
|
|
804
|
+
// picker would tag them `pro`).
|
|
805
|
+
if (cls === 'pro' && !allowed.includes('pro')) return [];
|
|
781
806
|
// The Pro class' list is its own alias set, never the pooled catalog: a
|
|
782
807
|
// pooled id pinned under pro would be sent to `claude --model`, which
|
|
783
808
|
// resolves aliases and real model names, not AEGIS ids — the same
|
|
@@ -820,9 +845,25 @@ function createApp(options = {}) {
|
|
|
820
845
|
return !s.includes(':');
|
|
821
846
|
}
|
|
822
847
|
|
|
848
|
+
/**
|
|
849
|
+
* The classes selectable right now. `pro` is behind the `proEnabled` gate
|
|
850
|
+
* (config.js, default off): HOST_CLASSES says this host CAN run it, this says
|
|
851
|
+
* whether it has been opted into. Every surface that lists or validates a
|
|
852
|
+
* class reads this, so the gate cannot be honoured in one place and ignored
|
|
853
|
+
* in another. A config read failure answers "pro is off" (fail closed).
|
|
854
|
+
*/
|
|
855
|
+
function selectableClasses() {
|
|
856
|
+
try {
|
|
857
|
+
return offeredClasses(proEnabled(loadConfig()));
|
|
858
|
+
} catch {
|
|
859
|
+
return offeredClasses(false);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
823
863
|
/**
|
|
824
864
|
* Switch the live class. Refuses anything this host cannot run (engine.js's
|
|
825
|
-
* HOST_CLASSES is the authority)
|
|
865
|
+
* HOST_CLASSES is the authority) and anything it does not offer — `pro` needs
|
|
866
|
+
* a one-time `/class pro on` first.
|
|
826
867
|
*
|
|
827
868
|
* A pin is cleared when it does not belong to the class being entered: a
|
|
828
869
|
* pooled id pinned under byok would be parsed as provider `<pooled id>` and
|
|
@@ -833,8 +874,17 @@ function createApp(options = {}) {
|
|
|
833
874
|
*/
|
|
834
875
|
function switchClass(next) {
|
|
835
876
|
const want = String(next == null ? '' : next).trim().toLowerCase();
|
|
836
|
-
|
|
837
|
-
|
|
877
|
+
const allowed = selectableClasses();
|
|
878
|
+
if (!allowed.includes(want)) {
|
|
879
|
+
if (want === 'pro') {
|
|
880
|
+
return {
|
|
881
|
+
ok: false,
|
|
882
|
+
error:
|
|
883
|
+
'the pro class (your Claude Code subscription) is off by default — ' +
|
|
884
|
+
'enable it once with `/class pro on`',
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
return { ok: false, error: `unknown class "${next}" — classes: ${allowed.join(', ')}` };
|
|
838
888
|
}
|
|
839
889
|
const prev = commandCtx.modelClass;
|
|
840
890
|
commandCtx.modelClass = want;
|
|
@@ -1518,6 +1568,7 @@ function createApp(options = {}) {
|
|
|
1518
1568
|
else if (o.type === 'model') lines = overlays.renderModelPicker(o.items || [], o.sel || 0, W, rows, o.current != null ? o.current : commandCtx.model, o.cls || commandCtx.modelClass, classLabelOf);
|
|
1519
1569
|
else if (o.type === 'effort') lines = overlays.renderEffortPicker(o.sel || 0, W, commandCtx.effort);
|
|
1520
1570
|
else if (o.type === 'class') lines = overlays.renderClassPicker(o.items || [], o.sel || 0, W, o.current || commandCtx.modelClass, classLabelOf);
|
|
1571
|
+
else if (o.type === 'provider') lines = overlays.renderProviderPicker(o.items || [], o.sel || 0, W, o.current, o.hint);
|
|
1521
1572
|
else if (o.type === 'resume') lines = overlays.renderResumeList(o.items || [], o.sel || 0, W, rows);
|
|
1522
1573
|
else if (o.type === 'confirm') lines = render.renderApproval(ctx(), o.info || {}, W).map((s) => [spanRow(s)]);
|
|
1523
1574
|
if (!lines) return;
|
|
@@ -1838,8 +1889,54 @@ function createApp(options = {}) {
|
|
|
1838
1889
|
|
|
1839
1890
|
// --- entry points ---------------------------------------------------------
|
|
1840
1891
|
|
|
1892
|
+
/**
|
|
1893
|
+
* Give the local lane back its hardware, on the way out.
|
|
1894
|
+
*
|
|
1895
|
+
* The desktop has done this from its quit path since the class shipped
|
|
1896
|
+
* (`main.js` before-quit -> `engine.unloadLocalModels` -> local.js
|
|
1897
|
+
* `unloadAll`): "closing the app closes the model". The CLI had no equivalent
|
|
1898
|
+
* at all, so exiting a session after a `local` turn left the weights resident
|
|
1899
|
+
* for the remainder of the pin the turn itself set — `DEFAULT_WARM_SECS` is
|
|
1900
|
+
* 1800 (local.js), i.e. up to thirty minutes of a loaded model on hardware
|
|
1901
|
+
* nobody was using anymore, which is the one cost this lane exists to not
|
|
1902
|
+
* have.
|
|
1903
|
+
*
|
|
1904
|
+
* Best-effort by construction: `unloadAll` never throws and each request is
|
|
1905
|
+
* bounded by `UNLOAD_TIMEOUT_MS` (4s) inside the transport, so a daemon that
|
|
1906
|
+
* is slow, wedged or already gone cannot turn a clean exit into a hang or a
|
|
1907
|
+
* crash. Called from every exit path of every entry point below — INCLUDING
|
|
1908
|
+
* `-p`, whose whole life may be one local turn.
|
|
1909
|
+
*
|
|
1910
|
+
* Deliberately not a `process.on('exit')` handler: that callback cannot
|
|
1911
|
+
* await, so the request would be issued into a process that is already
|
|
1912
|
+
* tearing the socket down. Awaiting at the end of the session is what makes
|
|
1913
|
+
* the eviction actually reach the daemon.
|
|
1914
|
+
*/
|
|
1915
|
+
async function releaseLocalModel() {
|
|
1916
|
+
if (!engine || typeof engine.unloadLocalModels !== 'function') return;
|
|
1917
|
+
try {
|
|
1918
|
+
await engine.unloadLocalModels();
|
|
1919
|
+
} catch {
|
|
1920
|
+
/* the model's own keep-alive lapses; never fail an exit over cleanup */
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* One-shot run: the turn itself (`runOnceTurn`), then the local lane handed
|
|
1926
|
+
* back even if that turn threw. A `-p` run can BE a whole local session, so
|
|
1927
|
+
* it needs the same closing the interactive loop gets — see
|
|
1928
|
+
* `releaseLocalModel`.
|
|
1929
|
+
*/
|
|
1930
|
+
async function runOnce(prompt, opts = {}) {
|
|
1931
|
+
try {
|
|
1932
|
+
return await runOnceTurn(prompt, opts);
|
|
1933
|
+
} finally {
|
|
1934
|
+
await releaseLocalModel();
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1841
1938
|
/** Non-interactive: one prompt, plain output, exit code. */
|
|
1842
|
-
async function
|
|
1939
|
+
async function runOnceTurn(prompt, { json = false } = {}) {
|
|
1843
1940
|
adoptLegacyKeyOnce();
|
|
1844
1941
|
// Same self-service a fresh `aegiscode -p ...` deserves as a fresh
|
|
1845
1942
|
// interactive session (runInteractive) or a fresh `/ask` (runPrompt):
|
|
@@ -2296,7 +2393,12 @@ function createApp(options = {}) {
|
|
|
2296
2393
|
}
|
|
2297
2394
|
// The class first: a stored BYOK pin is only meaningful under byok, and the
|
|
2298
2395
|
// pin check right after this reads whichever class won.
|
|
2299
|
-
|
|
2396
|
+
//
|
|
2397
|
+
// Gated on the OFFERED set, not HOST_CLASSES: a config written while `pro`
|
|
2398
|
+
// was enabled must not restore a subscription session onto a machine where
|
|
2399
|
+
// it has been turned off, or where this install never opted in. Such a
|
|
2400
|
+
// stored value falls back to the live default rather than being trusted.
|
|
2401
|
+
if (selectableClasses().includes(cfg.modelClass)) commandCtx.modelClass = cfg.modelClass;
|
|
2300
2402
|
if (!opts.model && cfg.model) commandCtx.model = cfg.model;
|
|
2301
2403
|
// Restored through effortRung(), so a config written by an older build is
|
|
2302
2404
|
// never a value this one does not send: `null`, `''` and the retired
|
|
@@ -2366,7 +2468,22 @@ function createApp(options = {}) {
|
|
|
2366
2468
|
* injected readline, `--print` — it stays the linear loop, so output remains
|
|
2367
2469
|
* pipeable and scriptable.
|
|
2368
2470
|
*/
|
|
2471
|
+
/**
|
|
2472
|
+
* Interactive session: the loop itself (`runInteractiveSession`), then the
|
|
2473
|
+
* local lane handed back. Wrapped for the same reason `runOnce` is: the loop
|
|
2474
|
+
* has several exits (a declined onboarding, `/quit`, a reset key stream, the
|
|
2475
|
+
* linear REPL), and "closing the session closes the model" must hold on all
|
|
2476
|
+
* of them rather than on the one path a `return` happens to reach.
|
|
2477
|
+
*/
|
|
2369
2478
|
async function runInteractive() {
|
|
2479
|
+
try {
|
|
2480
|
+
return await runInteractiveSession();
|
|
2481
|
+
} finally {
|
|
2482
|
+
await releaseLocalModel();
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
async function runInteractiveSession() {
|
|
2370
2487
|
const tty =
|
|
2371
2488
|
!options.readline &&
|
|
2372
2489
|
options.chatflow !== false &&
|
package/src/autonomous.js
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
const path = require('node:path');
|
|
34
34
|
|
|
35
35
|
const { queue, autonomous } = require('./deps.js');
|
|
36
|
-
const { createEngine } = require('./engine.js');
|
|
36
|
+
const { createEngine, proEnabled } = require('./engine.js');
|
|
37
|
+
const { loadConfig } = require('./config.js');
|
|
37
38
|
const { fmtElapsed } = require('./format.js');
|
|
38
39
|
const limits = require('./limits.js');
|
|
39
40
|
|
|
@@ -154,7 +155,23 @@ function buildEngine({ io, quiet = false }) {
|
|
|
154
155
|
if (!client.apiKey) {
|
|
155
156
|
return { error: `no AEGIS account key — ${credentials.HOW_TO_SET}, or set ${credentials.KEY_ENV}` };
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
// No `getClass` — deliberate (see engine.js chat()'s comment): a drain has
|
|
159
|
+
// no interactive session to read, so a queued task's own stated class is
|
|
160
|
+
// what runs. `getProEnabled` IS required even so, because liveClasses()
|
|
161
|
+
// treats a missing one as "off" and would strip `pro` out of the allowed
|
|
162
|
+
// set before the stated class is ever checked against it — leaving a
|
|
163
|
+
// `--class pro` task silently downgraded to DEFAULT_CLASS on every drain.
|
|
164
|
+
const engine = createEngine({
|
|
165
|
+
client,
|
|
166
|
+
getConfirmMode: () => false,
|
|
167
|
+
getProEnabled: () => {
|
|
168
|
+
try {
|
|
169
|
+
return proEnabled(loadConfig());
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
});
|
|
158
175
|
// The Pro gate (Phase 7). Built from the SAME shared decision the desktop
|
|
159
176
|
// uses, bound to this host's channel so a refusal links `?s=cli` and not
|
|
160
177
|
// `?s=desktop` — see cli/src/entitlement.js. Passed to the worker below as
|
package/src/chatflow.js
CHANGED
|
@@ -284,6 +284,9 @@ const PRO_ALIAS_KEYWORDS = Object.freeze(['opus', 'haiku', 'sonnet']);
|
|
|
284
284
|
* @param {boolean} o.hasStored the byok provider store already holds an
|
|
285
285
|
* anthropic key (desktop Provider settings / `/byok-key anthropic`)
|
|
286
286
|
* @param {boolean} o.proLoggedIn this machine is signed into Claude Code Pro
|
|
287
|
+
* @param {boolean} o.proEnabled the `pro` class is enabled for this install
|
|
288
|
+
* (`/class pro on`); anything but `true` leaves the byok row untouched, so a
|
|
289
|
+
* disabled subscription can never be reached by this reroute
|
|
287
290
|
* @param {Array<{id:string,label:string,note:string}>} o.proModels
|
|
288
291
|
* `claudePro.PRO_MODELS`, injected rather than required here
|
|
289
292
|
* @returns {{row:object, message:string|null}} the row to actually pin (the
|
|
@@ -299,6 +302,14 @@ function overrideAnthropicByokWithPro(chosen, o = {}) {
|
|
|
299
302
|
}
|
|
300
303
|
if (!o.needsKey) return { row: chosen, message: null }; // a real console key is already usable
|
|
301
304
|
if (!o.proLoggedIn) return { row: chosen, message: null }; // no subscription either — the normal prompt stands
|
|
305
|
+
// The `pro` class ships disabled (config.js `proEnabled`, `/class pro on`).
|
|
306
|
+
// This override silently MOVES a byok pick onto the subscription, so it must
|
|
307
|
+
// obey the same gate the picker and `/class` do — otherwise the one path a
|
|
308
|
+
// user never asked for is the path that still routes turns onto a
|
|
309
|
+
// subscription whose Claude Code access may be revoked, failing the turn with
|
|
310
|
+
// `oauth_org_not_allowed` after the pick already looked successful. Absent
|
|
311
|
+
// means "not stated" and is treated as disabled: fail closed.
|
|
312
|
+
if (o.proEnabled !== true) return { row: chosen, message: null };
|
|
302
313
|
const modelPart = id.slice(colon + 1).toLowerCase();
|
|
303
314
|
const proModels = Array.isArray(o.proModels) && o.proModels.length ? o.proModels : [{ id: 'default', label: 'Default', note: '' }];
|
|
304
315
|
const aliasId = PRO_ALIAS_KEYWORDS.find((kw) => modelPart.includes(kw)) || 'default';
|
|
@@ -1271,6 +1282,14 @@ async function runSession(host) {
|
|
|
1271
1282
|
overlay.items || [], overlay.sel || 0, cols, overlay.current || ctx.modelClass,
|
|
1272
1283
|
typeof host.classLabel === 'function' ? host.classLabel : null
|
|
1273
1284
|
);
|
|
1285
|
+
} else if (overlay.type === 'provider') {
|
|
1286
|
+
// The BYOK provider picker (/byok-set with no argument, /byok-key with
|
|
1287
|
+
// no argument). Same overlay machinery as /model and /class — arrow or
|
|
1288
|
+
// Tab to move, Enter to pick — so choosing WHICH vendor a key belongs to
|
|
1289
|
+
// is a highlight rather than a provider id retyped from memory.
|
|
1290
|
+
ol = overlays.renderProviderPicker(
|
|
1291
|
+
overlay.items || [], overlay.sel || 0, cols, overlay.current, overlay.hint
|
|
1292
|
+
);
|
|
1274
1293
|
} else if (overlay.type === 'resume') {
|
|
1275
1294
|
ol = overlays.renderResumeList(overlay.items || [], overlay.sel || 0, cols, termRows);
|
|
1276
1295
|
} else if (overlay.type === 'shortcuts') {
|
|
@@ -2028,7 +2047,7 @@ async function runSession(host) {
|
|
|
2028
2047
|
(c) => c.aliases || []
|
|
2029
2048
|
).length;
|
|
2030
2049
|
}
|
|
2031
|
-
if (overlay.type === 'model' || overlay.type === 'resume' || overlay.type === 'class') return (overlay.items || []).length;
|
|
2050
|
+
if (overlay.type === 'model' || overlay.type === 'resume' || overlay.type === 'class' || overlay.type === 'provider') return (overlay.items || []).length;
|
|
2032
2051
|
if (overlay.type === 'effort') return overlays.EFFORT_VALUES.length;
|
|
2033
2052
|
return 0;
|
|
2034
2053
|
};
|
|
@@ -2163,6 +2182,15 @@ async function runSession(host) {
|
|
|
2163
2182
|
const { row, message } = overrideAnthropicByokWithPro(chosen, {
|
|
2164
2183
|
needsKey: !!(plan && plan.needed),
|
|
2165
2184
|
proLoggedIn: models.claudeProLoggedIn(),
|
|
2185
|
+
// The same gate `/class pro on` writes: a disabled subscription is not
|
|
2186
|
+
// reachable by this reroute either.
|
|
2187
|
+
proEnabled: (() => {
|
|
2188
|
+
try {
|
|
2189
|
+
return loadConfig().proEnabled === true;
|
|
2190
|
+
} catch {
|
|
2191
|
+
return false;
|
|
2192
|
+
}
|
|
2193
|
+
})(),
|
|
2166
2194
|
proModels: claudePro.PRO_MODELS,
|
|
2167
2195
|
});
|
|
2168
2196
|
chosen = row;
|
|
@@ -2239,14 +2267,14 @@ async function runSession(host) {
|
|
|
2239
2267
|
}
|
|
2240
2268
|
return;
|
|
2241
2269
|
}
|
|
2242
|
-
if (key.name === KEY.TAB && (type === 'model' || type === 'effort' || type === 'class')) {
|
|
2270
|
+
if (key.name === KEY.TAB && (type === 'model' || type === 'effort' || type === 'class' || type === 'provider')) {
|
|
2243
2271
|
// Reference parity (aegiscodex-dev/src/main.js's model overlay cycles on
|
|
2244
2272
|
// Tab). It is also the one way to walk either picker that survives a link
|
|
2245
2273
|
// where arrow escapes are eaten, since Tab is a single control byte.
|
|
2246
2274
|
// Both lists are addressed the one way each of them can be: the catalogue
|
|
2247
2275
|
// lives in `overlay.items`, while the rungs are the picker's own table —
|
|
2248
2276
|
// the same table Enter and shift+enter resolve through.
|
|
2249
|
-
const n = type === 'model' || type === 'class'
|
|
2277
|
+
const n = type === 'model' || type === 'class' || type === 'provider'
|
|
2250
2278
|
? (overlay.items || []).length
|
|
2251
2279
|
: overlays.EFFORT_VALUES.length;
|
|
2252
2280
|
if (n) {
|
|
@@ -2292,6 +2320,21 @@ async function runSession(host) {
|
|
|
2292
2320
|
render();
|
|
2293
2321
|
return;
|
|
2294
2322
|
}
|
|
2323
|
+
if (type === 'provider') {
|
|
2324
|
+
// The BYOK provider pick: run the command that opened this picker with
|
|
2325
|
+
// the highlighted provider's own catalog id, so the id that reaches the
|
|
2326
|
+
// store is the id the relay is asked for — never a hand-retyped alias
|
|
2327
|
+
// (the `findByokProvider` loose match this replaces could land on the
|
|
2328
|
+
// wrong vendor, which is the failure the whole path exists to prevent).
|
|
2329
|
+
// `overlay.command` names the command to re-enter: /byok-key stores on
|
|
2330
|
+
// this machine, /byok-set stores on the account.
|
|
2331
|
+
const chosen = (overlay.items || [])[overlay.sel || 0];
|
|
2332
|
+
const cmd = overlay.command || 'byok-key';
|
|
2333
|
+
overlay = null;
|
|
2334
|
+
render();
|
|
2335
|
+
if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2295
2338
|
if (type === 'resume') {
|
|
2296
2339
|
const chosen = (overlay.items || [])[overlay.sel || 0];
|
|
2297
2340
|
overlay = null;
|
|
@@ -2330,6 +2373,21 @@ async function runSession(host) {
|
|
|
2330
2373
|
render();
|
|
2331
2374
|
return;
|
|
2332
2375
|
}
|
|
2376
|
+
if (type === 'provider') {
|
|
2377
|
+
// The BYOK provider pick: run the command that opened this picker with
|
|
2378
|
+
// the highlighted provider's own catalog id, so the id that reaches the
|
|
2379
|
+
// store is the id the relay is asked for — never a hand-retyped alias
|
|
2380
|
+
// (the `findByokProvider` loose match this replaces could land on the
|
|
2381
|
+
// wrong vendor, which is the failure the whole path exists to prevent).
|
|
2382
|
+
// `overlay.command` names the command to re-enter: /byok-key stores on
|
|
2383
|
+
// this machine, /byok-set stores on the account.
|
|
2384
|
+
const chosen = (overlay.items || [])[overlay.sel || 0];
|
|
2385
|
+
const cmd = overlay.command || 'byok-key';
|
|
2386
|
+
overlay = null;
|
|
2387
|
+
render();
|
|
2388
|
+
if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2333
2391
|
if (type === 'effort') {
|
|
2334
2392
|
applyEffortRow(overlay.sel || 0);
|
|
2335
2393
|
return;
|
|
@@ -2366,6 +2424,21 @@ async function runSession(host) {
|
|
|
2366
2424
|
render();
|
|
2367
2425
|
return;
|
|
2368
2426
|
}
|
|
2427
|
+
if (type === 'provider') {
|
|
2428
|
+
// The BYOK provider pick: run the command that opened this picker with
|
|
2429
|
+
// the highlighted provider's own catalog id, so the id that reaches the
|
|
2430
|
+
// store is the id the relay is asked for — never a hand-retyped alias
|
|
2431
|
+
// (the `findByokProvider` loose match this replaces could land on the
|
|
2432
|
+
// wrong vendor, which is the failure the whole path exists to prevent).
|
|
2433
|
+
// `overlay.command` names the command to re-enter: /byok-key stores on
|
|
2434
|
+
// this machine, /byok-set stores on the account.
|
|
2435
|
+
const chosen = (overlay.items || [])[overlay.sel || 0];
|
|
2436
|
+
const cmd = overlay.command || 'byok-key';
|
|
2437
|
+
overlay = null;
|
|
2438
|
+
render();
|
|
2439
|
+
if (chosen && chosen.id) await dispatch(`/${cmd} ${chosen.id}`);
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2369
2442
|
if (type === 'effort') {
|
|
2370
2443
|
applyEffortRow(overlay.sel || 0);
|
|
2371
2444
|
return;
|
|
@@ -2414,7 +2487,7 @@ async function runSession(host) {
|
|
|
2414
2487
|
}
|
|
2415
2488
|
return;
|
|
2416
2489
|
}
|
|
2417
|
-
if (type === 'effort' || type === 'resume' || type === 'class') {
|
|
2490
|
+
if (type === 'effort' || type === 'resume' || type === 'class' || type === 'provider') {
|
|
2418
2491
|
// Bounded by the same row count every other mover is bounded by. A row
|
|
2419
2492
|
// number past the end used to be accepted unseen (`sel = idx - 1` with
|
|
2420
2493
|
// no upper clamp), so '9' in /effort parked the highlight off the list
|
package/src/commands.js
CHANGED
|
@@ -3004,7 +3004,11 @@ const COMMANDS = [
|
|
|
3004
3004
|
[span(C.gray, '─'.repeat(34))],
|
|
3005
3005
|
[
|
|
3006
3006
|
span(set ? C.green : C.gray, ` ${set} of ${providers.length} providers set`),
|
|
3007
|
-
|
|
3007
|
+
// Name the PICKER first: the id is the one thing this screen was
|
|
3008
|
+
// asking the reader to copy by eye, and `/byok-list` removes that
|
|
3009
|
+
// step. The typed form stays beside it for scripts and for anyone who
|
|
3010
|
+
// already knows the id.
|
|
3011
|
+
span(C.gray, ' — /byok-list picks one, or /byok-key <provider>'),
|
|
3008
3012
|
],
|
|
3009
3013
|
'',
|
|
3010
3014
|
...byokProviderLines(providers),
|
|
@@ -3077,13 +3081,48 @@ const COMMANDS = [
|
|
|
3077
3081
|
build: (arg) => ({ provider: String(arg || '').trim() }),
|
|
3078
3082
|
},
|
|
3079
3083
|
{
|
|
3080
|
-
name: 'class', args: ['class'], hint: '[aegis|byok]', category: 'model',
|
|
3081
|
-
desc: 'Show or switch which class turns run on
|
|
3084
|
+
name: 'class', args: ['class', 'mode'], hint: '[aegis|byok|local|pro [on|off]]', category: 'model',
|
|
3085
|
+
desc: 'Show or switch which class turns run on; pro (your Claude subscription) needs a one-time "on"',
|
|
3082
3086
|
handler: async (c, a) => {
|
|
3083
3087
|
const args = a || {};
|
|
3084
3088
|
const cur = (c.ctx && c.ctx.modelClass) || 'aegis';
|
|
3085
3089
|
const label = (id) => (c.classLabel ? c.classLabel(id) : id);
|
|
3086
3090
|
const want = String(args.class || '').trim().toLowerCase();
|
|
3091
|
+
// `/class pro on|off` — the one-time opt-in for the subscription class.
|
|
3092
|
+
//
|
|
3093
|
+
// `pro` spends a real Claude Code Pro/Max subscription by spawning the
|
|
3094
|
+
// `claude` CLI, and an account whose organization has disabled Claude
|
|
3095
|
+
// Code answers every such turn with `oauth_org_not_allowed`, which this
|
|
3096
|
+
// repo cannot fix. So `pro` ships DISABLED (config.js `proEnabled: false`)
|
|
3097
|
+
// and this is the only way in: an explicit, deliberate word from the
|
|
3098
|
+
// user. Written through saveConfig so it survives a restart — an opt-in
|
|
3099
|
+
// that reverted on the next launch would put the class back out of reach
|
|
3100
|
+
// with no way to tell why.
|
|
3101
|
+
if (want === 'pro' && args.mode) {
|
|
3102
|
+
const mode = String(args.mode).trim().toLowerCase();
|
|
3103
|
+
if (mode !== 'on' && mode !== 'off') {
|
|
3104
|
+
c.push({ role: 'error', text: `usage: /class pro [on|off] — got "${args.mode}"` });
|
|
3105
|
+
return true;
|
|
3106
|
+
}
|
|
3107
|
+
const on = mode === 'on';
|
|
3108
|
+
c.saveConfig({ proEnabled: on });
|
|
3109
|
+
c.push({
|
|
3110
|
+
role: on ? 'done' : 'note',
|
|
3111
|
+
text: on
|
|
3112
|
+
? 'pro class enabled — /class pro switches to your Claude Code subscription. ' +
|
|
3113
|
+
'It runs only if that subscription has Claude Code access.'
|
|
3114
|
+
: 'pro class disabled — it is no longer offered by /class or the model picker.',
|
|
3115
|
+
});
|
|
3116
|
+
// Turning it off while sitting on it would leave the session pointing
|
|
3117
|
+
// at a class that can no longer run: fall back to the default class
|
|
3118
|
+
// through the same path `/class aegis` takes, so the pin rules and the
|
|
3119
|
+
// stored config are updated rather than only the panel.
|
|
3120
|
+
if (!on && cur === 'pro') {
|
|
3121
|
+
const back = c.switchClass('aegis');
|
|
3122
|
+
if (back.ok) c.push({ role: 'note', text: `class: ${back.class} — ${label(back.class)}` });
|
|
3123
|
+
}
|
|
3124
|
+
return true;
|
|
3125
|
+
}
|
|
3087
3126
|
if (!want) {
|
|
3088
3127
|
// Awaited: the engine's listClasses() is async (it probes for a local
|
|
3089
3128
|
// Ollama before answering), and a context that offers no class surface
|
|
@@ -3176,6 +3215,45 @@ const COMMANDS = [
|
|
|
3176
3215
|
return true;
|
|
3177
3216
|
},
|
|
3178
3217
|
},
|
|
3218
|
+
{
|
|
3219
|
+
// `/byok-list` — pick a provider from the catalog and store its key on THIS
|
|
3220
|
+
// machine, the same route `/byok-key` takes once a provider is named. The
|
|
3221
|
+
// picker is the point: the provider id was the one thing this flow asked
|
|
3222
|
+
// the user to recall and retype, and a retyped or alias-matched id either
|
|
3223
|
+
// matched nothing or matched another vendor. Arrow or Tab moves the
|
|
3224
|
+
// highlight, Enter picks, and the id dispatched is the catalog's own — so
|
|
3225
|
+
// the key lands under the id the relay will be asked for, and that
|
|
3226
|
+
// provider's models then show up in `/model`.
|
|
3227
|
+
name: 'byok-list', aliases: ['byok-pick'], hint: '', category: 'auth',
|
|
3228
|
+
desc: 'Pick a provider to set a key for, then its models appear in /model',
|
|
3229
|
+
handler: async (c) => {
|
|
3230
|
+
const providers = await byokCatalog(c.client);
|
|
3231
|
+
if (!providers || !providers.length) {
|
|
3232
|
+
c.push({
|
|
3233
|
+
role: 'error',
|
|
3234
|
+
text: 'Could not read the provider catalog (offline, or no AEGIS key) — /byok lists what is known.',
|
|
3235
|
+
});
|
|
3236
|
+
return true;
|
|
3237
|
+
}
|
|
3238
|
+
if (typeof c.openOverlay !== 'function') {
|
|
3239
|
+
// No interactive host: fall back to the printable list rather than a
|
|
3240
|
+
// picker nothing can draw.
|
|
3241
|
+
c.push({ role: 'note', text: '/byok-key <provider> — /byok lists the providers.' });
|
|
3242
|
+
return true;
|
|
3243
|
+
}
|
|
3244
|
+
const cur = (providers.find((p) => p.configured) || {}).id || null;
|
|
3245
|
+
const sel = Math.max(0, providers.findIndex((p) => p.configured));
|
|
3246
|
+
c.openOverlay({
|
|
3247
|
+
type: 'provider',
|
|
3248
|
+
command: 'byok-key',
|
|
3249
|
+
items: providers,
|
|
3250
|
+
sel,
|
|
3251
|
+
current: cur,
|
|
3252
|
+
hint: '↑↓ or tab move · enter picks · the key is stored on this machine',
|
|
3253
|
+
});
|
|
3254
|
+
return true;
|
|
3255
|
+
},
|
|
3256
|
+
},
|
|
3179
3257
|
{
|
|
3180
3258
|
name: 'byok-key', args: ['provider'], hint: '<provider> [key]', category: 'auth',
|
|
3181
3259
|
desc: 'Save YOUR provider key on THIS MACHINE — the key the byok class sends',
|
|
@@ -3183,7 +3261,33 @@ const COMMANDS = [
|
|
|
3183
3261
|
const args = a || {};
|
|
3184
3262
|
const typed = String(args.provider || '').trim().toLowerCase();
|
|
3185
3263
|
if (!typed) {
|
|
3186
|
-
|
|
3264
|
+
// No provider typed: open the picker instead of printing a usage line.
|
|
3265
|
+
// The id was the one thing this flow asked the user to RECALL, and a
|
|
3266
|
+
// mistyped or alias-matched id either matched nothing or — worse —
|
|
3267
|
+
// matched another vendor's row. Arrow or Tab moves, Enter picks, and
|
|
3268
|
+
// the id Enter dispatches is the catalog's own, so the key lands under
|
|
3269
|
+
// the id the relay will actually be asked for.
|
|
3270
|
+
const providers = await byokCatalog(c.client);
|
|
3271
|
+
if (!providers || !providers.length) {
|
|
3272
|
+
c.push({ role: 'error', text: 'Usage: /byok-key <provider> — /byok lists the providers.' });
|
|
3273
|
+
return true;
|
|
3274
|
+
}
|
|
3275
|
+
if (typeof c.openOverlay !== 'function') {
|
|
3276
|
+
// No interactive host (a piped run): the old usage line, which at
|
|
3277
|
+
// least names the command that lists the ids.
|
|
3278
|
+
c.push({ role: 'error', text: 'Usage: /byok-key <provider> — /byok lists the providers.' });
|
|
3279
|
+
return true;
|
|
3280
|
+
}
|
|
3281
|
+
const cur = (providers.find((p) => p.configured) || {}).id || null;
|
|
3282
|
+
const sel = Math.max(0, providers.findIndex((p) => p.configured));
|
|
3283
|
+
c.openOverlay({
|
|
3284
|
+
type: 'provider',
|
|
3285
|
+
command: 'byok-key',
|
|
3286
|
+
items: providers,
|
|
3287
|
+
sel,
|
|
3288
|
+
current: cur,
|
|
3289
|
+
hint: '↑↓ or tab move · enter picks · the key is stored on this machine',
|
|
3290
|
+
});
|
|
3187
3291
|
return true;
|
|
3188
3292
|
}
|
|
3189
3293
|
const store = c.settings && c.settings();
|
|
@@ -3237,9 +3341,75 @@ const COMMANDS = [
|
|
|
3237
3341
|
c.push({ role: 'note', text: `heads up: ${id} keys normally start with "${p.key_prefix}" — saved anyway.` });
|
|
3238
3342
|
}
|
|
3239
3343
|
store.set(c.byokNamespace(id), { key });
|
|
3344
|
+
|
|
3345
|
+
// MIRROR IT INTO ~/.aegiscode/.env — the file every host (this CLI, the
|
|
3346
|
+
// desktop, the MCP plugin) loads at start-up, and the one the shared
|
|
3347
|
+
// engine's `providerKeyFromEnv` reads. The settings store alone made the
|
|
3348
|
+
// key a private fact of this process's data dir: the next launch of the
|
|
3349
|
+
// SAME host found it, but nothing else did, and the byok model list is
|
|
3350
|
+
// built from a key the engine resolves through both. `/model-add` writes
|
|
3351
|
+
// both stores for this exact reason (see its `setEnvValue` call), and a
|
|
3352
|
+
// key entered here must not be the one row that behaves differently.
|
|
3353
|
+
// Best-effort: the store row above is the row of record, so a failure to
|
|
3354
|
+
// write the file is reported and never undoes the save.
|
|
3355
|
+
let envWritten = '';
|
|
3356
|
+
try {
|
|
3357
|
+
const { envVarFor, setEnvValue } = require(resolveShared(path.join('client', 'env-file.js')));
|
|
3358
|
+
const name = envVarFor(id);
|
|
3359
|
+
if (name) {
|
|
3360
|
+
const res = setEnvValue(name, key);
|
|
3361
|
+
if (res.ok) envWritten = name;
|
|
3362
|
+
else c.push({ role: 'note', text: `heads up: could not write ${name} to ~/.aegiscode/.env (${res.error}).` });
|
|
3363
|
+
}
|
|
3364
|
+
} catch {
|
|
3365
|
+
/* the settings-store save is the row of record; this mirror is best-effort */
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
// Then make the models it unlocks VISIBLE where the user asked for them:
|
|
3369
|
+
// the byok model list is cached for five minutes (app.js MODEL_CACHE_MS),
|
|
3370
|
+
// so without this the key is saved and `/model` keeps offering the list
|
|
3371
|
+
// computed before it existed — the "I set a key and nothing new appeared"
|
|
3372
|
+
// report. The refresh is forced, and its rows are what get pinned below.
|
|
3373
|
+
let rows = [];
|
|
3374
|
+
if (typeof c.refreshByokModels === 'function') {
|
|
3375
|
+
try { rows = (await c.refreshByokModels()) || []; } catch { rows = []; }
|
|
3376
|
+
}
|
|
3377
|
+
if (!rows.length && typeof c.listModelsFor === 'function') {
|
|
3378
|
+
// Hosts that expose the class surface but not the cache invalidation
|
|
3379
|
+
// (an embedding) still get an answer: ask for the byok class directly.
|
|
3380
|
+
try {
|
|
3381
|
+
rows = ((await c.listModelsFor('byok')) || []).filter((m) => !m.cls || m.cls === 'byok');
|
|
3382
|
+
} catch { rows = []; }
|
|
3383
|
+
}
|
|
3384
|
+
const mine = rows.filter((m) => m && (m.provider === id || String(m.id || '').startsWith(`${id}:`)));
|
|
3385
|
+
|
|
3386
|
+
// Move onto the byok class — the key just saved can only be spent there,
|
|
3387
|
+
// and a session sitting on `aegis` would show these rows in /model and
|
|
3388
|
+
// then send the pinned `provider:model` id to the pool. Before the pin,
|
|
3389
|
+
// so switchClass's own pin rules run on the id we are about to store.
|
|
3390
|
+
let onByok = ((c.ctx && c.ctx.modelClass) || '') === 'byok';
|
|
3391
|
+
if (!onByok && typeof c.switchClass === 'function') {
|
|
3392
|
+
const sw = c.switchClass('byok');
|
|
3393
|
+
if (sw && sw.ok) {
|
|
3394
|
+
onByok = true;
|
|
3395
|
+
c.push({ role: 'note', text: `class: byok — ${c.classLabel ? c.classLabel('byok') : 'your own key'}` });
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
// Pin it and PERSIST it, which is what makes the pick survive a restart:
|
|
3400
|
+
// app.js's restorePrefs() reads config.model/modelClass back. Only on
|
|
3401
|
+
// success — this whole block is the success path, after the key landed.
|
|
3402
|
+
const pickId = mine.length ? String(mine[0].id) : '';
|
|
3403
|
+
if (pickId && c.ctx) {
|
|
3404
|
+
c.ctx.model = pickId;
|
|
3405
|
+
c.saveConfig({ model: pickId, currentModelId: pickId, ...(onByok ? { modelClass: 'byok' } : {}) });
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3240
3408
|
c.push({
|
|
3241
3409
|
role: 'done',
|
|
3242
|
-
text:
|
|
3410
|
+
text: pickId
|
|
3411
|
+
? `saved a ${id} key on this machine${envWritten ? ` (${envWritten} in ~/.aegiscode/.env, so it is there next time)` : ''} — model ${pickId} pinned, /model lists the rest.`
|
|
3412
|
+
: `saved a ${id} key on this machine${envWritten ? ` (${envWritten} in ~/.aegiscode/.env, so it is there next time)` : ''} — /models lists its models, /class byok runs on it.`,
|
|
3243
3413
|
});
|
|
3244
3414
|
return true;
|
|
3245
3415
|
},
|
package/src/config.js
CHANGED
|
@@ -89,6 +89,20 @@ const DEFAULT_CONFIG = {
|
|
|
89
89
|
// back to. Defaulted to the pooled class, which is the only one an account
|
|
90
90
|
// key alone can run.
|
|
91
91
|
modelClass: 'aegis',
|
|
92
|
+
// Whether the `pro` class may be selected at all. OFF by default, and it
|
|
93
|
+
// takes a deliberate `/class pro on` to turn it on — this is a one-time
|
|
94
|
+
// opt-in, not a preference that drifts back.
|
|
95
|
+
//
|
|
96
|
+
// The reason is the failure this flag exists to prevent: `pro` spends a real
|
|
97
|
+
// Claude Code Pro/Max subscription by spawning the `claude` CLI, and an
|
|
98
|
+
// account whose organization has disabled Claude Code access answers every
|
|
99
|
+
// such turn with `oauth_org_not_allowed` ("Your organization has disabled
|
|
100
|
+
// Claude subscription access"). Nothing in this repo can re-enable that, so
|
|
101
|
+
// a default of "offered" meant the Class picker, the `/model` list and the
|
|
102
|
+
// anthropic→pro override all steered users into turns that could only fail.
|
|
103
|
+
// Off by default means a machine that never asked for the subscription route
|
|
104
|
+
// never lands on it; `/class pro on` is the single, explicit way in.
|
|
105
|
+
proEnabled: false,
|
|
92
106
|
// The full model table (seeded from src/models.js MODELS on first
|
|
93
107
|
// read by pickerModels()). 'currentModelId' mirrors `model` under the
|
|
94
108
|
// aegiscode- name so /model add/remove/switch stay compatible both ways.
|
package/src/deps.js
CHANGED
|
@@ -93,7 +93,103 @@ const { buildSystemPrompt } = require(promptPath);
|
|
|
93
93
|
const claudePro = require(claudeProPath);
|
|
94
94
|
const updater = require(updatePath);
|
|
95
95
|
const queue = require(queuePath);
|
|
96
|
-
const
|
|
96
|
+
const autonomousModule = require(autonomousPath);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The shared worker factory, wrapped so a drain closes the model it warmed.
|
|
100
|
+
*
|
|
101
|
+
* ## Why the wrapper lives here and not at the call site
|
|
102
|
+
*
|
|
103
|
+
* The desktop's rule is "closing this host closes the model" (`main.js`
|
|
104
|
+
* before-quit -> `engine.unloadLocalModels` -> `local.js unloadAll`). The chat
|
|
105
|
+
* surfaces on this host have it since `app.js` `releaseLocalModel`, but the
|
|
106
|
+
* unattended drain did not: `aegiscode autonomous proceed` builds the same
|
|
107
|
+
* engine, runs N turns on the local lane and then exits, leaving whatever it
|
|
108
|
+
* warmed resident for the rest of the pin the FIRST turn paid for
|
|
109
|
+
* (`DEFAULT_WARM_SECS` = 1800 in local.js, i.e. up to thirty minutes). A queue
|
|
110
|
+
* drained from a systemd timer is the worst case, not an edge case: nothing is
|
|
111
|
+
* watching the tray, and the timer re-arms every few minutes, so the weights can
|
|
112
|
+
* be kept hot indefinitely by a process that exited long ago. The local class
|
|
113
|
+
* bills nobody because the compute is already bought — a loaded model with no
|
|
114
|
+
* user is the one cost it was meant never to have.
|
|
115
|
+
*
|
|
116
|
+
* The fix belongs here because `createQueueWorker` does not hand its engine
|
|
117
|
+
* back: it returns `{ runTask, runOne, proceed, reconcile, cancel,
|
|
118
|
+
* sessionIdFor, resolveModel }` and nothing else, so the caller holds no handle
|
|
119
|
+
* to unload. This module is the seam that SUPPLIES that engine (it is built
|
|
120
|
+
* from `cli/src/engine.js`, which now carries `unloadLocalModels`), and it is
|
|
121
|
+
* the one place on the drain path that is not a sealed unit — `bin/aegiscode.js`
|
|
122
|
+
* is provenance p1 and `src/autonomous.js` is p6, both of which a real fix
|
|
123
|
+
* there would require resealing deliberately, with a version bump.
|
|
124
|
+
*
|
|
125
|
+
* ## What is wrapped, and why exactly those
|
|
126
|
+
*
|
|
127
|
+
* Only the two calls that are a whole DRAIN: `proceed` (which `run` and `retry`
|
|
128
|
+
* reach, since `src/autonomous.js` routes `run` to `proceed({ max: 1 })`) and
|
|
129
|
+
* `reconcile` (which queues a plan and then drains it in the same call —
|
|
130
|
+
* `await proceed(...)` inside the shared worker — so it warms a model exactly
|
|
131
|
+
* like `proceed` does).
|
|
132
|
+
*
|
|
133
|
+
* `runOne` is deliberately NOT wrapped, even though it also runs a turn. A
|
|
134
|
+
* drain calls it once per task, so a release there would evict the model
|
|
135
|
+
* between tasks of the SAME drain and make every task after the first pay the
|
|
136
|
+
* cold prefill the pin exists to avoid. The release belongs at the boundary of
|
|
137
|
+
* the drain, not at each turn inside it.
|
|
138
|
+
*
|
|
139
|
+
* Both wrappers release in a `finally`, so a WARMED-BUT-FAILED drain still
|
|
140
|
+
* closes its model — the case most likely to leave weights behind, since the
|
|
141
|
+
* successful path at least had a user watching it.
|
|
142
|
+
*
|
|
143
|
+
* A fire-and-forget `process.on('exit')` would NOT work here and is not used:
|
|
144
|
+
* that callback cannot await, and the bin hard-exits (`process.exit(code)` in
|
|
145
|
+
* `bin/aegiscode.js`), which skips `beforeExit` entirely — a handler registered
|
|
146
|
+
* for it would never run for the drain. Awaiting in a `finally` before the exit
|
|
147
|
+
* code is returned is the only ordering that actually issues the request.
|
|
148
|
+
*
|
|
149
|
+
* Best-effort by construction: a release that throws must never turn a drain
|
|
150
|
+
* that did its work into a failed one, and a worker built against a much older
|
|
151
|
+
* engine simply has nothing to release.
|
|
152
|
+
*/
|
|
153
|
+
function withModelRelease(worker, engine) {
|
|
154
|
+
const release = async () => {
|
|
155
|
+
try {
|
|
156
|
+
if (engine && typeof engine.unloadLocalModels === 'function') {
|
|
157
|
+
await engine.unloadLocalModels();
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// A teardown that crashes is worse than a residency window that lapses on
|
|
161
|
+
// its own (see cli/src/engine.js's `unloadLocalModels` note).
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const wrapDrain = (name) => {
|
|
166
|
+
const original = worker[name];
|
|
167
|
+
if (typeof original !== 'function') return original;
|
|
168
|
+
return async (...args) => {
|
|
169
|
+
try {
|
|
170
|
+
return await original.apply(worker, args);
|
|
171
|
+
} finally {
|
|
172
|
+
await release();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
...worker,
|
|
179
|
+
proceed: wrapDrain('proceed'),
|
|
180
|
+
reconcile: wrapDrain('reconcile'),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const autonomous = {
|
|
185
|
+
...autonomousModule,
|
|
186
|
+
createQueueWorker: (opts = {}) =>
|
|
187
|
+
autonomousModule.createQueueWorker
|
|
188
|
+
? withModelRelease(autonomousModule.createQueueWorker(opts), opts && opts.engine)
|
|
189
|
+
// A staged/vendored shared module older than the worker factory itself:
|
|
190
|
+
// degrade to whatever it exports rather than throwing on the drain path.
|
|
191
|
+
: autonomousModule.createQueueWorker,
|
|
192
|
+
};
|
|
97
193
|
const { autoProvisionApiKey, provisionFailureText, trialOutcomeNote } = require(autoProvisionPath);
|
|
98
194
|
|
|
99
195
|
// The trial clause is shared so the CLI's two notice sites and the desktop
|
package/src/engine.js
CHANGED
|
@@ -60,6 +60,29 @@ const VERSION = require('../package.json').version;
|
|
|
60
60
|
*/
|
|
61
61
|
const HOST_CLASSES = Object.freeze(['aegis', 'byok', 'local', 'pro']);
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The classes this host will actually OFFER, given the `proEnabled` gate.
|
|
65
|
+
*
|
|
66
|
+
* `pro` is in HOST_CLASSES because this host can run it; it is NOT offered
|
|
67
|
+
* unless the user opted in with `/class pro on` (config.js `proEnabled`,
|
|
68
|
+
* default false). Every surface that lists, validates or auto-selects a class
|
|
69
|
+
* goes through this list, so the gate cannot be honoured by `/class` while the
|
|
70
|
+
* `/model` picker and the anthropic→pro override still route turns onto a
|
|
71
|
+
* subscription the user never enabled.
|
|
72
|
+
*
|
|
73
|
+
* @param {boolean|{proEnabled?: boolean}} [want] `true`, or a config object.
|
|
74
|
+
* @returns {ReadonlyArray<string>}
|
|
75
|
+
*/
|
|
76
|
+
function offeredClasses(want) {
|
|
77
|
+
const on = want === true || (want && want.proEnabled === true);
|
|
78
|
+
return on ? HOST_CLASSES : HOST_CLASSES.filter((c) => c !== 'pro');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Whether the `pro` class may be selected on this host. */
|
|
82
|
+
function proEnabled(cfg) {
|
|
83
|
+
return cfg === true || (!!cfg && cfg.proEnabled === true);
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
/** The class a turn runs on when nothing else is said. */
|
|
64
87
|
const DEFAULT_CLASS = 'aegis';
|
|
65
88
|
|
|
@@ -79,15 +102,19 @@ const CLASS_LABELS = Object.freeze({
|
|
|
79
102
|
* @param {() => string} getClass Which class the next turn runs on — read per
|
|
80
103
|
* call for the same reason getConfirmMode is: /class must take effect on the
|
|
81
104
|
* very next turn, not on the next launch.
|
|
105
|
+
* @param {() => boolean} [getProEnabled] Whether the `pro` class is enabled for
|
|
106
|
+
* this install (config.js `proEnabled`, `/class pro on`). Read per call, like
|
|
107
|
+
* getClass, so turning it off takes effect on the very next turn rather than
|
|
108
|
+
* on the next launch — a stale `pro` session state must not survive it.
|
|
82
109
|
* @param {object} [settings] The provider-config store. Injected by tests
|
|
83
110
|
* (and by app.js, so one store serves both the engine and the commands);
|
|
84
111
|
* otherwise created against the CLI's data dir.
|
|
85
112
|
* @returns {{chat: Function, cancel: Function, respondApproval: Function,
|
|
86
113
|
* respondRoundsAsk: Function, clearSessionApprovals: Function, listClasses: Function,
|
|
87
114
|
* listModels: Function, classLabel: Function, getClass: Function, setClass: Function,
|
|
88
|
-
* settings: object}}
|
|
115
|
+
* unloadLocalModels: () => Promise<void>, settings: object}}
|
|
89
116
|
*/
|
|
90
|
-
function createEngine({ client, getConfirmMode, getClass, settings: injectedSettings } = {}) {
|
|
117
|
+
function createEngine({ client, getConfirmMode, getClass, getProEnabled, settings: injectedSettings } = {}) {
|
|
91
118
|
const settings = injectedSettings || createSettingsStore({ dir: credentials.aegisHome() });
|
|
92
119
|
|
|
93
120
|
const local = createLocalEngine({
|
|
@@ -109,10 +136,17 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
|
|
|
109
136
|
getConfirmMode,
|
|
110
137
|
});
|
|
111
138
|
|
|
112
|
-
/** The
|
|
139
|
+
/** The classes this host offers right now — `pro` only once enabled. */
|
|
140
|
+
function liveClasses() {
|
|
141
|
+
const on = typeof getProEnabled === 'function' ? !!getProEnabled() : false;
|
|
142
|
+
return offeredClasses(on);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The live class, clamped to what this host can run AND offers. */
|
|
113
146
|
function currentClass() {
|
|
114
147
|
const asked = typeof getClass === 'function' ? getClass() : null;
|
|
115
|
-
|
|
148
|
+
const allowed = liveClasses();
|
|
149
|
+
return allowed.includes(asked) ? asked : DEFAULT_CLASS;
|
|
116
150
|
}
|
|
117
151
|
|
|
118
152
|
function chat(payload, onDelta) {
|
|
@@ -141,9 +175,14 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
|
|
|
141
175
|
// payload's own class through, and then only one this host can run.
|
|
142
176
|
const live = typeof getClass === 'function' ? getClass() : null;
|
|
143
177
|
const stated = payload && payload.class;
|
|
144
|
-
|
|
178
|
+
// The offered set, not HOST_CLASSES: a `pro` turn must not run through the
|
|
179
|
+
// subscription unless it was explicitly enabled, and that holds for a
|
|
180
|
+
// payload that names its own class too (the queue stamps the class a task
|
|
181
|
+
// was queued on, which may predate the gate).
|
|
182
|
+
const allowed = liveClasses();
|
|
183
|
+
const cls = allowed.includes(live)
|
|
145
184
|
? live
|
|
146
|
-
:
|
|
185
|
+
: allowed.includes(stated)
|
|
147
186
|
? stated
|
|
148
187
|
: DEFAULT_CLASS;
|
|
149
188
|
return local.chat({ ...payload, class: cls }, onDelta);
|
|
@@ -155,15 +194,43 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
|
|
|
155
194
|
respondApproval: local.respondApproval,
|
|
156
195
|
respondRoundsAsk: local.respondRoundsAsk,
|
|
157
196
|
clearSessionApprovals: local.clearSessionApprovals,
|
|
197
|
+
// "Closing this host closes the model", the rule the desktop has enforced
|
|
198
|
+
// on its quit path (`main.js` before-quit -> engine.unloadLocalModels ->
|
|
199
|
+
// local.js unloadAll) since the lane shipped — and the one the CLI was
|
|
200
|
+
// missing entirely. Without this passthrough a local turn left the weights
|
|
201
|
+
// resident on the user's own hardware for the full length of the pin
|
|
202
|
+
// (local.js DEFAULT_WARM_SECS = 1800, i.e. 30 minutes) after the process
|
|
203
|
+
// was gone: the local lane exists to bill nothing because the compute is
|
|
204
|
+
// already paid for, and a model nobody is using anymore is the one cost it
|
|
205
|
+
// was supposed never to have.
|
|
206
|
+
//
|
|
207
|
+
// Wrapped rather than forwarded bare because this host is also built
|
|
208
|
+
// against a VENDORED copy of the shared engine (cli/scripts/predist.mjs
|
|
209
|
+
// stages desktop/lib/local/* into cli/vendor), so an install staged from a
|
|
210
|
+
// tree that predates `unloadLocalModels` must degrade to a no-op instead of
|
|
211
|
+
// throwing on the exit path — a teardown that crashes is worse than a
|
|
212
|
+
// residency window that lapses on its own.
|
|
213
|
+
unloadLocalModels: () =>
|
|
214
|
+
typeof local.unloadLocalModels === 'function'
|
|
215
|
+
? local.unloadLocalModels()
|
|
216
|
+
: Promise.resolve(),
|
|
158
217
|
// The engine's own class table, narrowed to the ones this host runs — so a
|
|
159
218
|
// UI built from listClasses() can never offer a class that would throw.
|
|
160
219
|
// Async, like the local engine's: listClasses() probes Ollama (a live
|
|
161
220
|
// HTTP round-trip) before it can answer, so returning the raw promise made
|
|
162
221
|
// `/class` throw "filter is not a function". The caller awaits it.
|
|
163
|
-
|
|
222
|
+
// The offered set, not HOST_CLASSES: `/class`, `/models` and the pickers are
|
|
223
|
+
// built from this, so a disabled `pro` cannot be listed or entered.
|
|
224
|
+
listClasses: async () => {
|
|
225
|
+
const allowed = liveClasses();
|
|
226
|
+
return (await local.listClasses()).filter((c) => allowed.includes(c.class));
|
|
227
|
+
},
|
|
164
228
|
listModels: (cls) => local.listModels(cls || currentClass()),
|
|
165
229
|
classLabel: (cls) => CLASS_LABELS[cls] || CLASS_LABELS[DEFAULT_CLASS],
|
|
166
230
|
getClass: currentClass,
|
|
231
|
+
/** The classes selectable right now (see offeredClasses) — for surfaces
|
|
232
|
+
* that validate a class without instantiating a turn. */
|
|
233
|
+
offeredClasses: () => liveClasses(),
|
|
167
234
|
settings,
|
|
168
235
|
};
|
|
169
236
|
}
|
|
@@ -206,4 +273,13 @@ function effortRung(effort) {
|
|
|
206
273
|
return effort === 'low' || effort === 'medium' ? effort : 'high';
|
|
207
274
|
}
|
|
208
275
|
|
|
209
|
-
module.exports = {
|
|
276
|
+
module.exports = {
|
|
277
|
+
createEngine,
|
|
278
|
+
HOST_CLASSES,
|
|
279
|
+
DEFAULT_CLASS,
|
|
280
|
+
CLASS_LABELS,
|
|
281
|
+
offeredClasses,
|
|
282
|
+
proEnabled,
|
|
283
|
+
byokNamespace,
|
|
284
|
+
effortRung,
|
|
285
|
+
};
|
package/src/limits.js
CHANGED
|
@@ -101,7 +101,7 @@ const UNITS = Object.freeze([
|
|
|
101
101
|
* The masked digest of the sealed set. Rewritten ONLY by
|
|
102
102
|
* `node tools/provenance.mjs seal --write`, never by hand.
|
|
103
103
|
*/
|
|
104
|
-
const SEALED = '
|
|
104
|
+
const SEALED = '4affd4840744736343e06c20f92b51d4e16cd061faa9539e46d9965b06dda04b';
|
|
105
105
|
|
|
106
106
|
/** Subcommands that a build failing this check does not get to run. */
|
|
107
107
|
const PRIVILEGED = Object.freeze(['gate', 'provenance', 'mcp']);
|
package/src/overlays.js
CHANGED
|
@@ -396,12 +396,66 @@ function ago(ts) {
|
|
|
396
396
|
return `${Math.round(ms / 86_400_000)}d ago`;
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
+
// ── BYOK provider picker overlay (/byok-set, /byok-key with no argument) ────
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The picker `/byok-set <provider>` draws when no provider was typed.
|
|
403
|
+
*
|
|
404
|
+
* The provider id was the one thing this flow asked the user to RECALL: `/byok`
|
|
405
|
+
* listed ~20 ids, and storing a key meant reading one off that list and typing
|
|
406
|
+
* it back — retyped wrong, it either matched nothing ("unknown provider") or,
|
|
407
|
+
* worse, matched an alias of another vendor. The rows are the catalog's own,
|
|
408
|
+
* so the id Enter sends is the id the relay will be asked for.
|
|
409
|
+
*
|
|
410
|
+
* @param {Array} providers catalog rows ({id, label?, configured?, masked?})
|
|
411
|
+
* @param {number} sel selected index
|
|
412
|
+
* @param {number} width
|
|
413
|
+
* @param {string|null} [current] the provider already set on this machine, if
|
|
414
|
+
* any (marked, not selected — "set" is shown per row anyway)
|
|
415
|
+
* @param {string} [hint] the footer line; differs between `/byok-set` (the
|
|
416
|
+
* account-side store) and `/byok-key` (this machine's store)
|
|
417
|
+
*/
|
|
418
|
+
function renderProviderPicker(providers, sel = 0, width = 80, current = null, hint = null) {
|
|
419
|
+
const list = Array.isArray(providers) ? providers : [];
|
|
420
|
+
const lines = [];
|
|
421
|
+
lines.push(blank(width));
|
|
422
|
+
lines.push([span('', ' '), span(C.white + BOLD, 'Select provider'), span(BOLD_OFF, '')]);
|
|
423
|
+
lines.push([span('', ' '), span(C.gray, 'Which vendor the key you are about to paste belongs to.')]);
|
|
424
|
+
lines.push(blank(width));
|
|
425
|
+
for (let i = 0; i < list.length; i++) {
|
|
426
|
+
const p = list[i] || {};
|
|
427
|
+
const id = String(p.id || '');
|
|
428
|
+
if (!id) continue;
|
|
429
|
+
const active = i === sel;
|
|
430
|
+
const cur = current != null && id === current;
|
|
431
|
+
const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
|
|
432
|
+
const nameSpan = active ? span(C.lavender, id) : span(C.white, id);
|
|
433
|
+
const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
|
|
434
|
+
const name = String(p.label || '');
|
|
435
|
+
const pad = ' '.repeat(Math.max(1, 16 - [...id].length));
|
|
436
|
+
const state = p.configured
|
|
437
|
+
? span(C.green, `set${p.masked ? ` (${p.masked})` : ''}`)
|
|
438
|
+
: span(C.gray, 'not set');
|
|
439
|
+
lines.push([
|
|
440
|
+
span('', ' '), left, span('', ' '), nameSpan, mark,
|
|
441
|
+
span(C.gray, pad + (name ? `${name} · ` : '')), state,
|
|
442
|
+
]);
|
|
443
|
+
}
|
|
444
|
+
lines.push(blank(width));
|
|
445
|
+
lines.push([
|
|
446
|
+
span('', ' '),
|
|
447
|
+
span(C.gray, hint || `↑↓ or tab move ${GLYPH.bullet} enter picks ${GLYPH.bullet} esc cancels`),
|
|
448
|
+
]);
|
|
449
|
+
return fit(lines, width);
|
|
450
|
+
}
|
|
451
|
+
|
|
399
452
|
module.exports = {
|
|
400
453
|
boldMatched,
|
|
401
454
|
renderPalette,
|
|
402
455
|
renderModelPicker,
|
|
403
456
|
renderEffortPicker,
|
|
404
457
|
renderClassPicker,
|
|
458
|
+
renderProviderPicker,
|
|
405
459
|
renderResumeList,
|
|
406
460
|
EFFORT_LEVELS,
|
|
407
461
|
EFFORT_VALUES,
|
package/src/provenance.lock.json
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"p3": "ff962ac8dbf42cecb2477e2f77bf5ec61f88aa1751b0d4e506bf030fbc5fc6c6",
|
|
30
30
|
"p4": "2e8385c3a653a2af324050b4b92aeb9d142fc6765c91a13ccc928c5d4a2dbedb",
|
|
31
31
|
"p5": "408d67f78f31f6d637a26d2852e0c809a260544e613afdc64b731401c0ba3801",
|
|
32
|
-
"p6": "
|
|
33
|
-
"p7": "
|
|
32
|
+
"p6": "22bcd0b5dc1afad8d870652fbf1fd25bd0a547be9d8700161449cafa35bab6eb",
|
|
33
|
+
"p7": "1ff7c8ddf9f2f2f15d60a9c40ab5ab777bfa4e0e69e5876f65073535ce6790f2",
|
|
34
34
|
"p8": "3cc054d06715e065fe635b37b7d1bb98bf7989d64453a572ddbb77cec5b830e7"
|
|
35
35
|
}
|
|
36
36
|
}
|