aegiscode 7.0.7 → 7.0.9
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 +3 -2
- package/src/app.js +164 -13
- package/src/chatflow.js +135 -10
- package/src/commands.js +240 -11
- package/src/deps.js +28 -2
- package/src/engine.js +8 -1
- package/src/models.js +78 -3
- package/src/render.js +9 -1
- package/vendor/client/aegis.js +122 -3
- package/vendor/client/auto-provision.js +42 -3
- package/vendor/client/credentials.js +8 -2
- package/vendor/client/env-file.js +262 -8
- package/vendor/client/user-models.js +1 -1
- package/vendor/desktop/lib/local/claude-pro.js +872 -0
- package/vendor/desktop/lib/local/engine.js +444 -16
- package/vendor/desktop/renderer/usage.js +25 -6
- package/vendor/one/src/child.js +287 -0
- package/vendor/one/src/permissions.js +371 -0
package/src/commands.js
CHANGED
|
@@ -339,8 +339,42 @@ async function loadModels(c) {
|
|
|
339
339
|
async function mergedPickerModels(c) {
|
|
340
340
|
const live = (c.ctx && c.ctx.modelClass) || 'aegis';
|
|
341
341
|
const aegis = pickerEntries(await loadModelsFor(c, 'aegis', live)).map((m) => ({ ...m, cls: 'aegis' }));
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
// `m.cls ||` and not `cls:`: the byok list carries rows that belong to
|
|
343
|
+
// another class (the pooled lane's, prepended by classScopedModels), and
|
|
344
|
+
// their own tag is the truth about where a pick of them runs.
|
|
345
|
+
const byok = pickerEntries(await loadModelsFor(c, 'byok', live)).map((m) => ({ ...m, cls: m.cls || 'byok' }));
|
|
346
|
+
// The Pro class' aliases are a third disjoint id space — `claude --model`
|
|
347
|
+
// resolves them, the pooled catalog and the relay do not — so they are merged
|
|
348
|
+
// into the same list for the same reason byok's are: a class the picker omits
|
|
349
|
+
// is a class the user cannot switch to from the surface that exists to switch
|
|
350
|
+
// models. Each row carries its own `cls`, exactly as the other two do, which
|
|
351
|
+
// is what ENTER reads to move the session BEFORE the pin applies.
|
|
352
|
+
const pro = pickerEntries(await loadModelsFor(c, 'pro', live)).map((m) => ({ ...m, cls: 'pro' }));
|
|
353
|
+
|
|
354
|
+
// One row per id, and a row's OWN class tag wins over the group it arrived
|
|
355
|
+
// in. Both halves are corrections, not tidying:
|
|
356
|
+
//
|
|
357
|
+
// - The byok group is not all byok. `classScopedModels` prepends the pooled
|
|
358
|
+
// rows to it on purpose, so that a session sitting on byok can still see
|
|
359
|
+
// the way back to the pooled lane — and this function's per-group
|
|
360
|
+
// `.map(m => ({...m, cls}))` overwrote that tag, so the SAME Nexus row
|
|
361
|
+
// arrived twice (the pooled group's, and a copy tagged `byok`). ENTER
|
|
362
|
+
// reads `cls` to decide which class to switch to before the pin applies,
|
|
363
|
+
// so the copy was not merely a duplicate line: picking it pinned a pooled
|
|
364
|
+
// id while leaving the session on byok, where the relay parses a bare id
|
|
365
|
+
// as a provider name and 400s.
|
|
366
|
+
// - Deduping by id (first wins, so the class-scoped groups lead) is what
|
|
367
|
+
// keeps that copy off the screen, and what stops any other id being
|
|
368
|
+
// offered twice when two classes advertise it.
|
|
369
|
+
const out = [];
|
|
370
|
+
const seen = new Set();
|
|
371
|
+
for (const row of [...aegis, ...byok, ...pro]) {
|
|
372
|
+
const id = String((row && row.id) || '');
|
|
373
|
+
if (!id || seen.has(id)) continue;
|
|
374
|
+
seen.add(id);
|
|
375
|
+
out.push(row);
|
|
376
|
+
}
|
|
377
|
+
return out;
|
|
344
378
|
}
|
|
345
379
|
|
|
346
380
|
/**
|
|
@@ -497,6 +531,63 @@ async function offeredModelIds(c, provider, key) {
|
|
|
497
531
|
return res && res.ok && Array.isArray(res.ids) && res.ids.length ? res.ids : undefined;
|
|
498
532
|
}
|
|
499
533
|
|
|
534
|
+
/**
|
|
535
|
+
* One argument string, tokenized with the SAME quote rule the app's own parser
|
|
536
|
+
* uses (`app.js` tokenize): a quoted run is one token and the quotes are not
|
|
537
|
+
* part of it.
|
|
538
|
+
*
|
|
539
|
+
* `_rest` is the raw remainder of the line (app.js parseArgs keeps it
|
|
540
|
+
* verbatim), so the only unambiguous way to type a base URL — `/model-add
|
|
541
|
+
* custom "https://my-vllm.example/v1" sk-… llama-3-70b` — arrives here still
|
|
542
|
+
* wrapped in its quotes. Splitting on whitespace alone stores the quote
|
|
543
|
+
* characters as part of the URL: the row then looks saved while every call on
|
|
544
|
+
* it is refused upstream, which is the silent no-op this whole command exists
|
|
545
|
+
* to avoid. The app's tokenizer is not reachable from here (it is a closure in
|
|
546
|
+
* app.js), so the rule is restated once, beside the only command that needs it.
|
|
547
|
+
*/
|
|
548
|
+
function splitCommandWords(rest) {
|
|
549
|
+
const out = [];
|
|
550
|
+
let cur = '';
|
|
551
|
+
let quote = null;
|
|
552
|
+
let has = false;
|
|
553
|
+
for (const ch of String(rest == null ? '' : rest)) {
|
|
554
|
+
if (quote) {
|
|
555
|
+
if (ch === quote) quote = null;
|
|
556
|
+
else cur += ch;
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (ch === '"' || ch === "'") { quote = ch; has = true; continue; }
|
|
560
|
+
if (/\s/.test(ch)) {
|
|
561
|
+
if (cur || has) { out.push(cur); cur = ''; has = false; }
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
cur += ch;
|
|
565
|
+
has = true;
|
|
566
|
+
}
|
|
567
|
+
if (cur || has) out.push(cur);
|
|
568
|
+
return out;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* The base URL this machine already holds for a provider, or ''.
|
|
573
|
+
*
|
|
574
|
+
* Only `custom` needs it, and only to answer one question: `/model-add custom
|
|
575
|
+
* <word>` with a single leftover word is ambiguous on a machine with no
|
|
576
|
+
* endpoint configured — the word could be the base URL (key and model still to
|
|
577
|
+
* come) or a model id for an endpoint nobody has named — and unambiguous once
|
|
578
|
+
* one IS configured, because then the word can be nothing but a model id.
|
|
579
|
+
*/
|
|
580
|
+
function savedByokBaseURL(c, provider) {
|
|
581
|
+
try {
|
|
582
|
+
const store = c && c.settings && c.settings();
|
|
583
|
+
if (!store || typeof store.get !== 'function' || typeof c.byokNamespace !== 'function') return '';
|
|
584
|
+
const row = store.get(c.byokNamespace(provider)) || {};
|
|
585
|
+
return String(row.baseURL || '').trim();
|
|
586
|
+
} catch {
|
|
587
|
+
return '';
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
500
591
|
/**
|
|
501
592
|
* Declare ids into the store, skipping the ones already there. Returns the
|
|
502
593
|
* count added, plus what was skipped and WHY, so the caller can say
|
|
@@ -988,6 +1079,12 @@ const COMMANDS = [
|
|
|
988
1079
|
c.transcript.length = 0;
|
|
989
1080
|
// Prune the session's history rows so /cost resets with /clear.
|
|
990
1081
|
pruneSessionHistory(c.sessionId);
|
|
1082
|
+
// Emptying the transcript is only half a clear: a transport that keeps
|
|
1083
|
+
// its own memory of this conversation (the Pro class's `claude` child
|
|
1084
|
+
// session) still holds the turns that were just erased, and would answer
|
|
1085
|
+
// from them on the next turn. Clearing the transcript our loop reads is
|
|
1086
|
+
// exactly the case where the other half must be dropped too.
|
|
1087
|
+
if (typeof c.clearConversationMemory === 'function') c.clearConversationMemory();
|
|
991
1088
|
note(c, 'Session cleared — transcript empty.');
|
|
992
1089
|
c.render();
|
|
993
1090
|
return true;
|
|
@@ -1400,7 +1497,10 @@ const COMMANDS = [
|
|
|
1400
1497
|
// Say why, and what unblocks it: an unreachable catalog is almost
|
|
1401
1498
|
// always a missing key or no network, and "no models advertised"
|
|
1402
1499
|
// read as "the platform has none" rather than "this client could not
|
|
1403
|
-
// ask".
|
|
1500
|
+
// ask". Reachable only when even Claude Code Pro's static alias rows
|
|
1501
|
+
// are absent — PRO_MODELS is a non-empty constant, so in practice
|
|
1502
|
+
// this is the full-outage fallback, not the common "no AEGIS key"
|
|
1503
|
+
// case that used to land here (see the branch just below).
|
|
1404
1504
|
note(c, c.state().online
|
|
1405
1505
|
? 'Could not read the model catalog (offline, or the server refused it) — /models retries.'
|
|
1406
1506
|
: // The key travels in the environment only (client/aegis.js reads
|
|
@@ -1410,6 +1510,16 @@ const COMMANDS = [
|
|
|
1410
1510
|
c.render();
|
|
1411
1511
|
return true;
|
|
1412
1512
|
}
|
|
1513
|
+
// AEGIS Cloud and byok both need a key this machine does not have:
|
|
1514
|
+
// almost always a missing AEGIS_API_KEY or no network. Claude Code Pro
|
|
1515
|
+
// needs neither (it is the subscription's own OAuth token, collected
|
|
1516
|
+
// when a pro row is picked), so its rows still show — the picker opens
|
|
1517
|
+
// with what IS available rather than blocking on what is not.
|
|
1518
|
+
if (!models.some((m) => m.cls === 'aegis' || m.cls === 'byok')) {
|
|
1519
|
+
note(c, c.state().online
|
|
1520
|
+
? 'Could not read the AEGIS Cloud catalog (offline, or the server refused it) — showing Claude Code Pro only; /models retries.'
|
|
1521
|
+
: `No AEGIS API key set, so the AEGIS Cloud catalog cannot be read (free key: ${signupUrl('model_blocked')}) — showing Claude Code Pro only.`);
|
|
1522
|
+
}
|
|
1413
1523
|
// A pin that is not in the catalog is not honoured — the pool answers
|
|
1414
1524
|
// from its own default with no error. Say so where the pin is visible
|
|
1415
1525
|
// rather than letting the reply look like the pinned model. On byok the
|
|
@@ -2155,6 +2265,11 @@ const COMMANDS = [
|
|
|
2155
2265
|
desc: 'Start a new session (clears the transcript, fresh session id)',
|
|
2156
2266
|
handler: async (c) => {
|
|
2157
2267
|
c.transcript.length = 0;
|
|
2268
|
+
// Release the conversation being left behind BEFORE the id changes — a
|
|
2269
|
+
// new session id is a new key, so the old entry would otherwise sit in
|
|
2270
|
+
// the engine's map for the life of the process, holding a `claude` child
|
|
2271
|
+
// session nobody can reach or clear again.
|
|
2272
|
+
if (typeof c.clearConversationMemory === 'function') c.clearConversationMemory();
|
|
2158
2273
|
const id = 'aegis-' + Math.random().toString(36).slice(2, 10);
|
|
2159
2274
|
c.sessionId = id;
|
|
2160
2275
|
c.ctx.sessionId = id;
|
|
@@ -2708,7 +2823,13 @@ const COMMANDS = [
|
|
|
2708
2823
|
if (lower === 'register') {
|
|
2709
2824
|
const res = await c.registerAccount();
|
|
2710
2825
|
if (res.alreadyKeyed) {
|
|
2711
|
-
|
|
2826
|
+
// Registration is per machine fingerprint and the welcome trial is
|
|
2827
|
+
// granted once per machine, ever, so this branch can never produce a
|
|
2828
|
+
// new trial however many times it is run — and a user who wiped their
|
|
2829
|
+
// credential store lands here precisely expecting one. Say so, and
|
|
2830
|
+
// name the two paths that actually do something, rather than a
|
|
2831
|
+
// no-op notice that reads like a refusal for no reason.
|
|
2832
|
+
note(c, 'this machine already has an AEGIS key — /key status shows it. Re-registering cannot mint a new welcome trial: that is granted once per machine, ever. For a fresh trial, sign up at aegiscloud.org; to point this session at a different key, /key clear first.');
|
|
2712
2833
|
} else if (res.key && res.ok) {
|
|
2713
2834
|
done(c, 'AEGIS account key provisioned and saved');
|
|
2714
2835
|
} else if (res.key) {
|
|
@@ -3176,19 +3297,33 @@ const COMMANDS = [
|
|
|
3176
3297
|
// the next refresh and the window shows it on ITS next refresh. The file is
|
|
3177
3298
|
// printed on success, because a hand-edit is the bulk path and a store the
|
|
3178
3299
|
// user cannot find is a store they will not use.
|
|
3179
|
-
name: 'model-add', aliases: ['add-model'], args: ['provider'],
|
|
3300
|
+
name: 'model-add', aliases: ['add-model'], args: ['provider'],
|
|
3301
|
+
hint: '<provider> [api-key] [model-id|*] (custom: <base-url> <api-key> [model-id|*])',
|
|
3180
3302
|
category: 'model',
|
|
3181
|
-
desc: '
|
|
3303
|
+
desc: 'Save a provider key and offer a model id in one step (asks the vendor when it can)',
|
|
3182
3304
|
handler: async (c, a) => {
|
|
3183
3305
|
const args = a || {};
|
|
3184
3306
|
const typed = String(args.provider || '').trim();
|
|
3185
3307
|
if (!typed) {
|
|
3186
|
-
c.push({
|
|
3308
|
+
c.push({
|
|
3309
|
+
role: 'error',
|
|
3310
|
+
text: 'Usage: /model-add <provider> [api-key] <model-id> — /byok lists the providers. '
|
|
3311
|
+
+ 'A vendor this catalog does not name yet: /model-add custom <https-base-url> <api-key> <model-id>. '
|
|
3312
|
+
+ 'Example: /model-add deepseek sk-xxxxxxxx deepseek-v4.3-preview',
|
|
3313
|
+
});
|
|
3187
3314
|
return true;
|
|
3188
3315
|
}
|
|
3189
3316
|
const rest = String(args._rest || '').trim();
|
|
3190
|
-
|
|
3191
|
-
|
|
3317
|
+
// Quote-aware, because the one word on this line that MAY need quoting is
|
|
3318
|
+
// the base URL — see splitCommandWords.
|
|
3319
|
+
const words = splitCommandWords(rest);
|
|
3320
|
+
// `words[0]` is the provider token itself, echoed into `_rest` the same
|
|
3321
|
+
// way `/byok-key` reads it — everything after it is ours to read. A
|
|
3322
|
+
// `_rest` without it (a caller that passes only the trailing words) is
|
|
3323
|
+
// tolerated rather than misread as the provider being the model id.
|
|
3324
|
+
let extra = words.length && words[0].toLowerCase() === typed.toLowerCase()
|
|
3325
|
+
? words.slice(1)
|
|
3326
|
+
: words;
|
|
3192
3327
|
// Resolve the provider against the relay's catalog first. A slug the
|
|
3193
3328
|
// server does not list can never be attached to a key, so storing it
|
|
3194
3329
|
// would produce a declaration that is invisible in every picker — the
|
|
@@ -3209,6 +3344,95 @@ const COMMANDS = [
|
|
|
3209
3344
|
return true;
|
|
3210
3345
|
}
|
|
3211
3346
|
const id = (match && match.provider && match.provider.id) || typed.toLowerCase();
|
|
3347
|
+
// ── fold the key-save step in, so one command does both ──────────────
|
|
3348
|
+
//
|
|
3349
|
+
// Before this, a never-configured provider needed /byok-key THEN
|
|
3350
|
+
// /model-add — two commands for one outcome the user has in mind as
|
|
3351
|
+
// one. Two extra words can only mean key-then-model (the one-word shape
|
|
3352
|
+
// just below is already the model-id-alone case this command always
|
|
3353
|
+
// had, and guessing "key or model id" from a single token is the
|
|
3354
|
+
// ambiguity this rule avoids rather than resolves): `/model-add
|
|
3355
|
+
// deepseek sk-… deepseek-v4.3-preview` saves the key and declares the
|
|
3356
|
+
// model in the same breath, and shows up in the picker right after —
|
|
3357
|
+
// no separate /byok-key round trip.
|
|
3358
|
+
//
|
|
3359
|
+
// "custom" (a vendor this catalog does not name, or a self-hosted
|
|
3360
|
+
// OpenAI-compatible endpoint) reads one word EARLIER than every other
|
|
3361
|
+
// provider: the base URL aegis1 has no constant for and must be told
|
|
3362
|
+
// per call (`_byok_custom_base_url` there validates it — https, no
|
|
3363
|
+
// loopback/private/link-local target). It gets its own branch rather
|
|
3364
|
+
// than folding into the generic rule below, because with the base URL
|
|
3365
|
+
// in play a lone leftover word is still ambiguous between "no model"
|
|
3366
|
+
// and "no key" in a way the generic one-word-is-the-model-id rule
|
|
3367
|
+
// cannot resolve.
|
|
3368
|
+
let typedBaseURL = '';
|
|
3369
|
+
let typedKey = '';
|
|
3370
|
+
if (id === 'custom') {
|
|
3371
|
+
// ONE leftover word for `custom` is genuinely ambiguous, so it is
|
|
3372
|
+
// refused rather than guessed: with no endpoint on this machine the
|
|
3373
|
+
// word could be the base URL (key and model still to come) or a model
|
|
3374
|
+
// id for an endpoint nobody has named — and the guess that writes a
|
|
3375
|
+
// model row against no endpoint is a row that cannot be called. Once an
|
|
3376
|
+
// endpoint IS saved the ambiguity is gone, because a second endpoint
|
|
3377
|
+
// needs its key with it (the two-word branch below), so a lone word can
|
|
3378
|
+
// only be a model id. Named, not silently dropped.
|
|
3379
|
+
if (extra.length === 1 && !savedByokBaseURL(c, id)) {
|
|
3380
|
+
c.push({
|
|
3381
|
+
role: 'error',
|
|
3382
|
+
text: 'one word cannot say whether it is the URL or the model id — nothing was saved. '
|
|
3383
|
+
+ 'Type the endpoint first: /model-add custom <https-base-url> <api-key> [model-id]',
|
|
3384
|
+
});
|
|
3385
|
+
return true;
|
|
3386
|
+
}
|
|
3387
|
+
if (extra.length >= 2) {
|
|
3388
|
+
typedBaseURL = extra.shift();
|
|
3389
|
+
typedKey = extra.shift();
|
|
3390
|
+
}
|
|
3391
|
+
} else if (extra.length >= 2) {
|
|
3392
|
+
typedKey = extra.shift();
|
|
3393
|
+
}
|
|
3394
|
+
let model = extra.join(' ').trim();
|
|
3395
|
+
if (typedKey) {
|
|
3396
|
+
const keyStore = c.settings && c.settings();
|
|
3397
|
+
if (!keyStore || typeof keyStore.set !== 'function') {
|
|
3398
|
+
c.push({ role: 'error', text: 'this client has no provider-key store.' });
|
|
3399
|
+
return true;
|
|
3400
|
+
}
|
|
3401
|
+
const p = match && match.provider;
|
|
3402
|
+
if (p && p.key_prefix && !typedKey.startsWith(p.key_prefix)) {
|
|
3403
|
+
c.push({ role: 'note', text: `heads up: ${id} keys normally start with "${p.key_prefix}" — saved anyway.` });
|
|
3404
|
+
}
|
|
3405
|
+
if (typedBaseURL && !/^https:\/\//i.test(typedBaseURL)) {
|
|
3406
|
+
c.push({ role: 'note', text: `heads up: aegis1 only dials an https:// base_url — saved anyway, but calls on it will be refused.` });
|
|
3407
|
+
}
|
|
3408
|
+
keyStore.set(c.byokNamespace(id), { key: typedKey, ...(typedBaseURL ? { baseURL: typedBaseURL } : {}) });
|
|
3409
|
+
// Mirror it into ~/.aegiscode/.env too — the same file the model picker
|
|
3410
|
+
// writes (models.js storeModelKey) and byokKeyForProvider() already
|
|
3411
|
+
// falls back to reading. Without this a key saved here was invisible to
|
|
3412
|
+
// anything that only reads process.env/.env (a shell, the other host
|
|
3413
|
+
// before its settings store syncs), even though the two files name the
|
|
3414
|
+
// same provider through the identical envVarFor() mapping. Best-effort:
|
|
3415
|
+
// the settings-store save above is the row of record, so a failure here
|
|
3416
|
+
// (e.g. an unwritable .env) is reported but never undoes it.
|
|
3417
|
+
try {
|
|
3418
|
+
const { envVarFor, setEnvValue } = require(resolveShared(path.join('client', 'env-file.js')));
|
|
3419
|
+
const envName = envVarFor(id);
|
|
3420
|
+
if (envName) {
|
|
3421
|
+
const res = setEnvValue(envName, typedKey);
|
|
3422
|
+
if (!res.ok) {
|
|
3423
|
+
c.push({ role: 'note', text: `heads up: could not mirror the key into ~/.aegiscode/.env (${res.error}).` });
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
} catch {
|
|
3427
|
+
/* the settings-store save is the row of record; this mirror is best-effort */
|
|
3428
|
+
}
|
|
3429
|
+
c.push({
|
|
3430
|
+
role: 'done',
|
|
3431
|
+
text: typedBaseURL
|
|
3432
|
+
? `saved a ${id} key and base URL (${typedBaseURL}) on this machine.`
|
|
3433
|
+
: `saved a ${id} key on this machine.`,
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3212
3436
|
// ── what the vendor says, before we ask the user to remember it ──────
|
|
3213
3437
|
//
|
|
3214
3438
|
// The whole cost of this feature used to be "know the vendor's model id",
|
|
@@ -3272,8 +3496,13 @@ const COMMANDS = [
|
|
|
3272
3496
|
// A bare number picks the row it is listed under. Only an in-range
|
|
3273
3497
|
// integer is read that way, so an id that happens to start with a digit
|
|
3274
3498
|
// is still stored verbatim unless it is exactly a listed position.
|
|
3275
|
-
|
|
3276
|
-
|
|
3499
|
+
// `offered` is undefined whenever the vendor could not be asked (no
|
|
3500
|
+
// key, no endpoint, no network) — reading `.length` off it here threw a
|
|
3501
|
+
// TypeError out of the handler, which reads to the user as the command
|
|
3502
|
+
// crashing rather than as the id being stored, so the position rule is
|
|
3503
|
+
// applied only when there is a list to be a position IN.
|
|
3504
|
+
const n = offered && /^\d+$/.test(typedId) ? Number(typedId) : 0;
|
|
3505
|
+
model = offered && n >= 1 && n <= offered.length ? offered[n - 1] : typedId;
|
|
3277
3506
|
}
|
|
3278
3507
|
if (!model) {
|
|
3279
3508
|
c.push({ role: 'note', text: 'nothing saved.' });
|
package/src/deps.js
CHANGED
|
@@ -58,6 +58,16 @@ const agentsPath = resolveShared(path.join('desktop', 'lib', 'local', 'agents.js
|
|
|
58
58
|
// running shell commands. Same file as the GUI, for the same reason engine.js
|
|
59
59
|
// is: two personas would drift, and only one of them would get fixed.
|
|
60
60
|
const promptPath = resolveShared(path.join('desktop', 'lib', 'local', 'prompt.js'));
|
|
61
|
+
// The Claude Code Pro class' transport — the user's own subscription, spent by
|
|
62
|
+
// spawning the `claude` CLI (desktop/lib/local/claude-pro.js). Shared with the
|
|
63
|
+
// desktop host rather than re-implemented, for the reason engine.js is: one
|
|
64
|
+
// module owns the child argv, the credential read and the stream-json parser,
|
|
65
|
+
// so the GUI and the terminal cannot disagree about what a Pro turn was allowed
|
|
66
|
+
// to do or which models the subscription can address. The CLI needs it for the
|
|
67
|
+
// picker's rows and the pin rules, which must read the SAME alias list the
|
|
68
|
+
// transport does — a second copy here is exactly the drift this file exists to
|
|
69
|
+
// prevent.
|
|
70
|
+
const claudeProPath = resolveShared(path.join('desktop', 'lib', 'local', 'claude-pro.js'));
|
|
61
71
|
// The npm update checker, shared with the desktop host: two package names, one
|
|
62
72
|
// implementation, so a fix to the check reaches both.
|
|
63
73
|
const updatePath = resolveShared(path.join('client', 'update.js'));
|
|
@@ -80,10 +90,19 @@ const { createLocalEngine, hostEnv } = require(enginePath);
|
|
|
80
90
|
const { createSettingsStore, isReservedNamespace } = require(settingsPath);
|
|
81
91
|
const { agentRoles, agentRoleLabel } = require(agentsPath);
|
|
82
92
|
const { buildSystemPrompt } = require(promptPath);
|
|
93
|
+
const claudePro = require(claudeProPath);
|
|
83
94
|
const updater = require(updatePath);
|
|
84
95
|
const queue = require(queuePath);
|
|
85
96
|
const autonomous = require(autonomousPath);
|
|
86
|
-
const { autoProvisionApiKey, provisionFailureText } = require(autoProvisionPath);
|
|
97
|
+
const { autoProvisionApiKey, provisionFailureText, trialOutcomeNote } = require(autoProvisionPath);
|
|
98
|
+
|
|
99
|
+
// The trial clause is shared so the CLI's two notice sites and the desktop
|
|
100
|
+
// cannot word the same outcome differently — but a staged/vendored copy of
|
|
101
|
+
// client/auto-provision.js can lag the canonical one (desktop/vendor and
|
|
102
|
+
// cli/vendor are generated, and a shipped tree may predate trialOutcomeNote).
|
|
103
|
+
// Missing it must degrade to silence, not to a TypeError on the very path that
|
|
104
|
+
// has just successfully provisioned a key.
|
|
105
|
+
const trialNote = typeof trialOutcomeNote === 'function' ? trialOutcomeNote : () => '';
|
|
87
106
|
|
|
88
107
|
module.exports = {
|
|
89
108
|
resolveShared,
|
|
@@ -102,11 +121,18 @@ module.exports = {
|
|
|
102
121
|
agentRoles,
|
|
103
122
|
agentRoleLabel,
|
|
104
123
|
buildSystemPrompt,
|
|
124
|
+
claudePro,
|
|
105
125
|
updater,
|
|
106
126
|
queue,
|
|
107
127
|
autonomous,
|
|
108
128
|
autoProvisionApiKey,
|
|
109
129
|
provisionFailureText,
|
|
110
|
-
|
|
130
|
+
// The shared welcome-trial clause ('' when there is nothing to say, and ''
|
|
131
|
+
// rather than a throw when a staged copy predates it). Exported so app.js
|
|
132
|
+
// does not re-implement the three-way outcome inline — the inline version
|
|
133
|
+
// only knew about `trialGranted`, which is why a re-registered machine got a
|
|
134
|
+
// first-install notice and no word about the trial it did not receive.
|
|
135
|
+
trialNote,
|
|
136
|
+
paths: { client: clientPath, tools: toolsPath, usage: usagePath, engine: enginePath, settings: settingsPath, agents: agentsPath, prompt: promptPath, claudePro: claudeProPath, update: updatePath, queue: queuePath, autonomous: autonomousPath, autoProvision: autoProvisionPath },
|
|
111
137
|
roots,
|
|
112
138
|
};
|
package/src/engine.js
CHANGED
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
* turn, which is exactly what makes BYOK billable traffic instead of a
|
|
23
23
|
* free ride — and why the key must never be handed to a direct provider
|
|
24
24
|
* call from here.
|
|
25
|
+
* pro the user's own Claude Code Pro/Max subscription, spent by spawning
|
|
26
|
+
* the `claude` CLI. Unchanged from the tunnel repo's claude-pro.js: no
|
|
27
|
+
* relay, no AEGIS key, no vendor key, and therefore nothing to bill.
|
|
25
28
|
*
|
|
26
29
|
* Ollama stays a stub that throws if the engine ever calls it: it needs an
|
|
27
30
|
* endpoint surface this host does not offer, and a stub is proof that a code
|
|
@@ -51,8 +54,11 @@ const VERSION = require('../package.json').version;
|
|
|
51
54
|
* local — a model on hardware you own, over loopback. Bills nobody because
|
|
52
55
|
* there is no vendor; refused outright if the base URL is not local
|
|
53
56
|
* (desktop/lib/local/local.js remoteRefusal, fail-closed).
|
|
57
|
+
* pro — your own Claude Code Pro/Max subscription, spent by spawning the
|
|
58
|
+
* `claude` CLI (desktop/lib/local/claude-pro.js). Bills nobody:
|
|
59
|
+
* no relay is involved and no AEGIS endpoint is called.
|
|
54
60
|
*/
|
|
55
|
-
const HOST_CLASSES = Object.freeze(['aegis', 'byok', 'local']);
|
|
61
|
+
const HOST_CLASSES = Object.freeze(['aegis', 'byok', 'local', 'pro']);
|
|
56
62
|
|
|
57
63
|
/** The class a turn runs on when nothing else is said. */
|
|
58
64
|
const DEFAULT_CLASS = 'aegis';
|
|
@@ -62,6 +68,7 @@ const CLASS_LABELS = Object.freeze({
|
|
|
62
68
|
aegis: 'AEGIS Cloud (pooled)',
|
|
63
69
|
byok: 'Bring your own key (relayed, billed)',
|
|
64
70
|
local: 'Local model (your own machine, free)',
|
|
71
|
+
pro: 'Claude Code Pro (your own subscription)',
|
|
65
72
|
});
|
|
66
73
|
|
|
67
74
|
/**
|
package/src/models.js
CHANGED
|
@@ -63,6 +63,32 @@ const { offerableCatalog } = require(resolveShared(path.join('client', 'brain-ca
|
|
|
63
63
|
*/
|
|
64
64
|
const envFile = require(resolveShared(path.join('client', 'env-file.js')));
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The Claude Code Pro transport, required the same way — so the 'pro' class's
|
|
68
|
+
* OWN foreign-secret check (below) can ask the same question `engine.js`'s
|
|
69
|
+
* `listModels('pro')` already answers for the row's `configured` flag:
|
|
70
|
+
* `claudeProStatus().loggedIn`, not only "is a token set aside in
|
|
71
|
+
* secrets.env". Without this, a machine signed in through the ordinary
|
|
72
|
+
* `claude login` flow (credentials.json, no `claude setup-token` ever run)
|
|
73
|
+
* reads as unconfigured here while the picker paints the same row
|
|
74
|
+
* `configured: true` — the picker says "ready", `/model` prompts for a token
|
|
75
|
+
* anyway.
|
|
76
|
+
*/
|
|
77
|
+
const claudePro = require(resolveShared(path.join('desktop', 'lib', 'local', 'claude-pro.js')));
|
|
78
|
+
|
|
79
|
+
/** Whether this machine is already signed into Claude Code Pro/Max, any way
|
|
80
|
+
* `claudeProStatus` recognizes (credentials.json OAuth or API-key form, or
|
|
81
|
+
* `CLAUDE_CODE_OAUTH_TOKEN` already in the environment) — broader than the
|
|
82
|
+
* foreign-secret file alone, and the same check the picker's `configured`
|
|
83
|
+
* flag is built from. */
|
|
84
|
+
function claudeProLoggedIn() {
|
|
85
|
+
try {
|
|
86
|
+
return !!claudePro.claudeProStatus({ env: process.env }).loggedIn;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
66
92
|
/** A pinned id of `null` means "no pin — let the pool choose" (the server's own default). */
|
|
67
93
|
const NO_PIN = null;
|
|
68
94
|
|
|
@@ -236,6 +262,30 @@ function modelKeyPlan(entry, o = {}) {
|
|
|
236
262
|
// for — an unanswerable prompt is worse than a turn that 400s with the id.
|
|
237
263
|
return { needed: false, env: '', provider: '', pooled: plan.pooled, status: null, why: 'this id has no key variable' };
|
|
238
264
|
}
|
|
265
|
+
if (plan.foreign) {
|
|
266
|
+
// Claude Code Pro: the credential lives in secrets.env (or an unmigrated
|
|
267
|
+
// .env line, or a real shell export), never in process.env at large — so
|
|
268
|
+
// `keyStatus` (which reads `.env`/process.env only) cannot answer this one;
|
|
269
|
+
// `resolveForeignSecret` is the function built to check every place it
|
|
270
|
+
// might actually be. See client/env-file.js keyForModelId.
|
|
271
|
+
//
|
|
272
|
+
// That alone is a narrower question than "is this machine signed in,
|
|
273
|
+
// though" — a plain `claude login` writes credentials.json and never
|
|
274
|
+
// touches secrets.env, so `claudeProLoggedIn()` is checked too; it is the
|
|
275
|
+
// same source `engine.js listModels('pro')` already paints the row's own
|
|
276
|
+
// `configured` flag from, so the two cannot disagree about one row.
|
|
277
|
+
const present = !!envFile.resolveForeignSecret(plan.env) || claudeProLoggedIn();
|
|
278
|
+
return {
|
|
279
|
+
needed: !present,
|
|
280
|
+
env: plan.env,
|
|
281
|
+
provider: '',
|
|
282
|
+
pooled: false,
|
|
283
|
+
status: { present, inFile: present, source: present ? 'file' : 'none' },
|
|
284
|
+
why: present
|
|
285
|
+
? `${plan.env} is already set aside for Claude Code Pro`
|
|
286
|
+
: `no ${plan.env} is set aside for Claude Code Pro`,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
239
289
|
const status = envFile.keyStatus(plan.env);
|
|
240
290
|
if (plan.pooled) {
|
|
241
291
|
const needed = !status.present && !o.accountConfigured;
|
|
@@ -314,6 +364,27 @@ function modelKeyQueue(entry, o = {}) {
|
|
|
314
364
|
// unanswerable prompt is worse than a turn that 400s with the id in it.
|
|
315
365
|
if (!plan.env) return [];
|
|
316
366
|
|
|
367
|
+
if (plan.foreign) {
|
|
368
|
+
// Claude Code Pro bills nobody through AEGIS and calls no vendor API, so
|
|
369
|
+
// neither the account key nor a vendor key belongs in this queue — the
|
|
370
|
+
// ONE credential this route needs is the subscription's own OAuth token.
|
|
371
|
+
// There is no dedicated command for it (no `/byok-key` equivalent): it is
|
|
372
|
+
// asked for here, the same place every other row's key is asked for.
|
|
373
|
+
//
|
|
374
|
+
// `claudeProLoggedIn()` catches the plain `claude login` case the bare
|
|
375
|
+
// secrets.env check misses — see the matching note in `modelKeyPlan`.
|
|
376
|
+
if (envFile.resolveForeignSecret(plan.env) || claudeProLoggedIn()) return [];
|
|
377
|
+
return [{
|
|
378
|
+
env: plan.env,
|
|
379
|
+
provider: '',
|
|
380
|
+
vendor: '',
|
|
381
|
+
role: 'claude-pro',
|
|
382
|
+
needed: true,
|
|
383
|
+
status: { present: false },
|
|
384
|
+
why: `no ${plan.env} is set aside for Claude Code Pro`,
|
|
385
|
+
}];
|
|
386
|
+
}
|
|
387
|
+
|
|
317
388
|
const steps = [];
|
|
318
389
|
const account = envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);
|
|
319
390
|
if (!account.present && !o.accountConfigured) {
|
|
@@ -384,14 +455,17 @@ function storeModelKey(entry, key, o = {}) {
|
|
|
384
455
|
}
|
|
385
456
|
const opts = { ...o };
|
|
386
457
|
delete opts.env;
|
|
387
|
-
|
|
458
|
+
// A foreign name (CLAUDE_CODE_OAUTH_TOKEN) goes to secrets.env, never .env —
|
|
459
|
+
// setEnvValue refuses it outright (client/env-file.js FOREIGN_SECRET_NAMES),
|
|
460
|
+
// and writing it there would be the exact ambient exposure the split ends.
|
|
461
|
+
const res = plan.foreign ? envFile.setForeignSecret(env, key, opts) : envFile.setEnvValue(env, key, opts);
|
|
388
462
|
// `pooled` describes the VARIABLE that was written, not the class of the row:
|
|
389
463
|
// the account key is the pooled route's credential wherever it is stored,
|
|
390
464
|
// while a vendor key written for a pooled row is still the user's own vendor
|
|
391
465
|
// key. Reading it off the row (as this once did) reported DEEPSEEK_API_KEY as
|
|
392
466
|
// pooled, which told the caller the pool held a key the user had just supplied.
|
|
393
|
-
const pooled = env === envFile.ACCOUNT_ENV_VAR;
|
|
394
|
-
return { ...res, env, provider: env === plan.env ? plan.provider : '', pooled };
|
|
467
|
+
const pooled = !plan.foreign && env === envFile.ACCOUNT_ENV_VAR;
|
|
468
|
+
return { ...res, env, provider: env === plan.env ? plan.provider : '', pooled, foreign: !!plan.foreign };
|
|
395
469
|
}
|
|
396
470
|
|
|
397
471
|
/** The env var name a key for `entry` belongs in ('' when there is none). */
|
|
@@ -411,4 +485,5 @@ module.exports = {
|
|
|
411
485
|
modelKeyQueue,
|
|
412
486
|
storeModelKey,
|
|
413
487
|
keyVarForModel,
|
|
488
|
+
claudeProLoggedIn,
|
|
414
489
|
};
|
package/src/render.js
CHANGED
|
@@ -406,7 +406,15 @@ function renderWorking(ctx, state = {}) {
|
|
|
406
406
|
const verb = state.verb || VERBS[0];
|
|
407
407
|
const tail = [];
|
|
408
408
|
if (state.elapsedMs != null) tail.push(fmtElapsed(state.elapsedMs));
|
|
409
|
-
|
|
409
|
+
// `streamedFloor` marks a figure that has folded in Anthropic's own
|
|
410
|
+
// `thinking_delta.estimated_tokens` (desktop/lib/local/claude-pro.js) — a
|
|
411
|
+
// running count that measurement showed landing under the real billed
|
|
412
|
+
// thinking-token total (1900 vs 1943, 1800 vs 1832, 250 vs 339). Flagged
|
|
413
|
+
// with `≥` rather than shown as an exact figure, because the true number
|
|
414
|
+
// only arrives with the turn's final `usage`.
|
|
415
|
+
if (state.streamed != null) {
|
|
416
|
+
tail.push(`↓${state.streamedFloor ? '≥' : ''}${fmtTokens(state.streamed)} tokens`);
|
|
417
|
+
}
|
|
410
418
|
const tailStr = tail.length ? ` ${t.gray}(${tail.join(` ${GLYPH.bullet} `)})${RESET}` : '';
|
|
411
419
|
return (
|
|
412
420
|
`${t.coral}${frame}${RESET} ${t.white}${verb}${RESET}${t.white}…${RESET}${tailStr}` +
|