aegiscode 7.0.6 → 7.0.8
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 +136 -12
- package/src/chatflow.js +119 -8
- package/src/commands.js +68 -4
- package/src/deps.js +28 -2
- package/src/engine.js +8 -1
- package/src/models.js +78 -3
- package/src/topup.js +1 -1
- package/vendor/client/aegis.js +119 -5
- package/vendor/client/auto-provision.js +54 -7
- package/vendor/client/credentials.js +8 -2
- package/vendor/client/device-fingerprint.js +1 -8
- package/vendor/client/env-file.js +262 -8
- package/vendor/desktop/lib/local/claude-pro.js +755 -0
- package/vendor/desktop/lib/local/engine.js +329 -12
- package/vendor/mcp/server.js +1 -1
- package/vendor/one/src/child.js +287 -0
- package/vendor/one/src/permissions.js +371 -0
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.8",
|
|
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",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"license": "AGPL-3.0-or-later",
|
|
11
11
|
"homepage": "https://aegiscloud.org",
|
|
12
12
|
"bin": {
|
|
13
|
-
"aegiscode": "bin/aegiscode.js"
|
|
13
|
+
"aegiscode": "bin/aegiscode.js",
|
|
14
|
+
"aegiscodex": "bin/aegiscode.js"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"bin",
|
package/src/app.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
const readline = require('node:readline');
|
|
27
27
|
const os = require('node:os');
|
|
28
28
|
const { randomUUID } = require('node:crypto');
|
|
29
|
-
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, provisionFailureText, hostEnv, autonomous } = require('./deps.js');
|
|
29
|
+
const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, provisionFailureText, trialNote, hostEnv, autonomous, claudePro } = require('./deps.js');
|
|
30
30
|
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung } = 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');
|
|
@@ -158,7 +158,7 @@ function createApp(options = {}) {
|
|
|
158
158
|
let provisionAttempted = false;
|
|
159
159
|
let keyFailure = '';
|
|
160
160
|
async function provisionDeviceKey() {
|
|
161
|
-
const result = await autoProvisionApiKey(client, credentials);
|
|
161
|
+
const result = await autoProvisionApiKey(client, credentials, { app: 'cli' });
|
|
162
162
|
keyFailure = result.key ? '' : provisionFailureText(result);
|
|
163
163
|
return result;
|
|
164
164
|
}
|
|
@@ -171,8 +171,13 @@ function createApp(options = {}) {
|
|
|
171
171
|
render.renderNotice(
|
|
172
172
|
ctx(),
|
|
173
173
|
'info',
|
|
174
|
-
`
|
|
174
|
+
`auto-provisioned a free account` +
|
|
175
175
|
(result.ok ? ` (saved to ${credentials.credentialsPath()})` : ' (could not save it — reconfigure with /key)') +
|
|
176
|
+
// Shared clause: covers the withheld case AND the reused one (a
|
|
177
|
+
// returning fingerprint gets its old account, never a second
|
|
178
|
+
// trial). Inline here it only knew `trialGranted`, so a
|
|
179
|
+
// re-registered machine read as a clean first install.
|
|
180
|
+
trialNote(result) +
|
|
176
181
|
`. Fund it at ${client.promptUrl('topup', 'device_autoprovision')} or run /byok to use your own key.`
|
|
177
182
|
)
|
|
178
183
|
);
|
|
@@ -663,7 +668,38 @@ function createApp(options = {}) {
|
|
|
663
668
|
/* no pooled catalog to read — byok rows stand alone */
|
|
664
669
|
}
|
|
665
670
|
}
|
|
666
|
-
|
|
671
|
+
// `want`, not the live class: this call is answering for the class it
|
|
672
|
+
// was ASKED about. See classScopedModels.
|
|
673
|
+
return classScopedModels(byok, want);
|
|
674
|
+
}
|
|
675
|
+
if (want === 'pro') {
|
|
676
|
+
// The Claude Code Pro class' rows come from the engine itself (the
|
|
677
|
+
// CLI's own aliases, claude-pro.js PRO_MODELS) rather than from a
|
|
678
|
+
// fetched catalog, so they are read straight off listModels('pro') —
|
|
679
|
+
// one source, the same one the desktop's picker reads.
|
|
680
|
+
//
|
|
681
|
+
// NOT gated on the subscription already being present — that gate used
|
|
682
|
+
// to hide every pro row until `~/.claude/.credentials.json` (or
|
|
683
|
+
// CLAUDE_CODE_OAUTH_TOKEN) already existed, which made the row
|
|
684
|
+
// impossible to ever reach from THIS picker: there was no way to pick
|
|
685
|
+
// "Claude Code Pro" to set the credential up in the first place, only
|
|
686
|
+
// to confirm one that was already there. A byok row offers exactly the
|
|
687
|
+
// same way with no key either, and picking it is what collects one
|
|
688
|
+
// (`collectKeyFor`, chatflow.js) — a pro row now does the same,
|
|
689
|
+
// through the very token `modelKeyQueue` asks for (client/env-file.js
|
|
690
|
+
// keyForModelId's `foreign: true` branch). `configured` on each row
|
|
691
|
+
// still states whether a turn would succeed RIGHT NOW; listing is a
|
|
692
|
+
// separate question from being ready.
|
|
693
|
+
const info = await engine.listModels('pro');
|
|
694
|
+
return (info && info.models) || [];
|
|
695
|
+
}
|
|
696
|
+
// Anything else is asked of the engine by name — 'local' especially,
|
|
697
|
+
// which used to fall through to the pooled catalog below and so answered
|
|
698
|
+
// "here are the AEGIS Cloud models" to a question about the free local
|
|
699
|
+
// class. Only 'aegis' (the pool) is read from the cached client fetch.
|
|
700
|
+
if (want !== 'aegis') {
|
|
701
|
+
const info = await engine.listModels(want);
|
|
702
|
+
return (info && info.models) || [];
|
|
667
703
|
}
|
|
668
704
|
return await loadModels();
|
|
669
705
|
} catch {
|
|
@@ -681,6 +717,19 @@ function createApp(options = {}) {
|
|
|
681
717
|
return pickerEntries(byokCache.models).map((m) => ({ ...m, cls: 'byok' }));
|
|
682
718
|
}
|
|
683
719
|
|
|
720
|
+
/**
|
|
721
|
+
* The Claude Code Pro class' rows, tagged the same way as the two above. The
|
|
722
|
+
* list is the CLI's own aliases (PRO_MODELS), which is why there is no cache
|
|
723
|
+
* here: nothing is fetched, so nothing can go stale or be missing offline.
|
|
724
|
+
*/
|
|
725
|
+
function proRows() {
|
|
726
|
+
return pickerEntries(claudePro.PRO_MODELS.map((m) => ({
|
|
727
|
+
id: m.id,
|
|
728
|
+
label: m.label,
|
|
729
|
+
note: m.note,
|
|
730
|
+
}))).map((m) => ({ ...m, cls: 'pro' }));
|
|
731
|
+
}
|
|
732
|
+
|
|
684
733
|
/**
|
|
685
734
|
* The class-scoped model list — `state().models`, `/models`, the alt+p chord
|
|
686
735
|
* and the `/class` auto-pick all read it, so it is one list and not four.
|
|
@@ -711,25 +760,63 @@ function createApp(options = {}) {
|
|
|
711
760
|
*
|
|
712
761
|
* @param {Array<object>} [byokOverride] rows already fetched by an async
|
|
713
762
|
* caller, so an awaiting caller does not re-read a cache it just filled.
|
|
763
|
+
* @param {string} [cls] the class to answer FOR. Defaults to the live class,
|
|
764
|
+
* which is what `state().models` wants — but not what `/model` wants.
|
|
765
|
+
*
|
|
766
|
+
* THE CLASS ASKED IS NOT THE CLASS LIVE, and conflating them is what emptied
|
|
767
|
+
* the picker. `mergedPickerModels` (commands.js) asks this module for all
|
|
768
|
+
* three classes in one turn — it opens ONE list containing pooled, byok and
|
|
769
|
+
* Pro rows so a model in another class is reachable without knowing to run
|
|
770
|
+
* `/class` first. Answering every one of those asks from the LIVE class made
|
|
771
|
+
* that merge a lie: on the default `aegis` class the byok ask came back with
|
|
772
|
+
* the pooled rows again (tagged `byok`, so the picker painted Nexus and
|
|
773
|
+
* deepseek twice and the provider ids never at all), and on the `pro` class
|
|
774
|
+
* the pooled ask came back with Pro's aliases — the list a user reads as
|
|
775
|
+
* "only pool and sonnet, where are the rest of my models?". The requested
|
|
776
|
+
* class is the parameter precisely so a caller may ask about a class it is
|
|
777
|
+
* not on; only an absent/unknown `cls` may fall back to the live one.
|
|
714
778
|
*/
|
|
715
|
-
function classScopedModels(byokOverride) {
|
|
716
|
-
|
|
779
|
+
function classScopedModels(byokOverride, cls) {
|
|
780
|
+
const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
|
|
781
|
+
// The Pro class' list is its own alias set, never the pooled catalog: a
|
|
782
|
+
// pooled id pinned under pro would be sent to `claude --model`, which
|
|
783
|
+
// resolves aliases and real model names, not AEGIS ids — the same
|
|
784
|
+
// cross-class mismatch the byok branch below is shaped to prevent. It is
|
|
785
|
+
// checked before the pooled default for exactly that reason.
|
|
786
|
+
if (want === 'pro') return proRows();
|
|
787
|
+
if (want !== 'byok') return pooledRows();
|
|
717
788
|
const byok = Array.isArray(byokOverride)
|
|
718
789
|
? byokOverride.map((m) => ({ ...m, cls: 'byok' }))
|
|
719
790
|
: byokRows();
|
|
720
791
|
return [...pooledRows(), ...byok];
|
|
721
792
|
}
|
|
722
793
|
|
|
794
|
+
/**
|
|
795
|
+
* The ids the Pro class can address: claude-pro.js's PRO_MODELS, lowercased
|
|
796
|
+
* once. Read from the module rather than re-listed, because the transport
|
|
797
|
+
* spawns `claude --model <id>` with these exact strings — a second list here
|
|
798
|
+
* could offer a row the child rejects, which is the cross-class defect the
|
|
799
|
+
* byok rule below is shaped to prevent.
|
|
800
|
+
*/
|
|
801
|
+
function proModelIds() {
|
|
802
|
+
return new Set(claudePro.PRO_MODELS.map((m) => String(m.id).toLowerCase()));
|
|
803
|
+
}
|
|
804
|
+
|
|
723
805
|
/**
|
|
724
806
|
* Whether a pinned id can run on `cls`, decided synchronously (switchClass is
|
|
725
|
-
* not async). byok ids are `provider:model`; aegis
|
|
726
|
-
* not — the pooled catalog is validated separately, at launch, by
|
|
727
|
-
* validatePinnedModel.
|
|
807
|
+
* not async). byok ids are `provider:model`; aegis and local take anything
|
|
808
|
+
* that is not — the pooled catalog is validated separately, at launch, by
|
|
809
|
+
* validatePinnedModel. pro takes ONLY its own aliases.
|
|
728
810
|
*/
|
|
729
811
|
function pinBelongsToClass(cls, id) {
|
|
730
812
|
const s = String(id == null ? '' : id);
|
|
731
813
|
if (cls === 'byok') return s.includes(':');
|
|
732
|
-
//
|
|
814
|
+
// pro: `claude --model` resolves these aliases and full model names, and
|
|
815
|
+
// AEGIS ids are neither. Without this rule a pooled id ("deepseek") pinned
|
|
816
|
+
// under pro is handed to the child, which fails the turn with a message
|
|
817
|
+
// about a model rather than about the class the user is on.
|
|
818
|
+
if (cls === 'pro') return proModelIds().has(s.toLowerCase());
|
|
819
|
+
// aegis/local: not a byok id.
|
|
733
820
|
return !s.includes(':');
|
|
734
821
|
}
|
|
735
822
|
|
|
@@ -813,6 +900,25 @@ function createApp(options = {}) {
|
|
|
813
900
|
);
|
|
814
901
|
return pinned;
|
|
815
902
|
}
|
|
903
|
+
// A Pro pin is validated against the child's OWN alias list, locally, and
|
|
904
|
+
// never against the pooled catalog: that catalogue cannot contain these
|
|
905
|
+
// aliases, so checking it here would clear every legitimate Pro pin on every
|
|
906
|
+
// launch. There is no fetch on this path either — the list is a constant, so
|
|
907
|
+
// this is the one class whose validation cannot be defeated by being offline.
|
|
908
|
+
if (commandCtx.modelClass === 'pro') {
|
|
909
|
+
if (proModelIds().has(String(pinned).toLowerCase())) return null;
|
|
910
|
+
commandCtx.model = null;
|
|
911
|
+
updateConfig({ model: null, currentModelId: null });
|
|
912
|
+
emit(
|
|
913
|
+
render.renderNotice(
|
|
914
|
+
ctx(),
|
|
915
|
+
'warn',
|
|
916
|
+
`pinned model "${pinned}" is not one the Claude Code CLI resolves — pin cleared, ` +
|
|
917
|
+
`the CLI will choose; /models lists the aliases (${claudePro.PRO_MODELS.map((m) => m.id).join(', ')}).`
|
|
918
|
+
)
|
|
919
|
+
);
|
|
920
|
+
return pinned;
|
|
921
|
+
}
|
|
816
922
|
let models;
|
|
817
923
|
try {
|
|
818
924
|
models = await loadModels();
|
|
@@ -1063,6 +1169,12 @@ function createApp(options = {}) {
|
|
|
1063
1169
|
// `--no-stream` and piped runs get a single body rather than SSE.
|
|
1064
1170
|
stream: commandCtx.stream !== false,
|
|
1065
1171
|
sessionId,
|
|
1172
|
+
// The CONVERSATION id, which `sessionId` above is not — that one is
|
|
1173
|
+
// minted fresh for THIS turn so a cancel can target it. Memory that
|
|
1174
|
+
// has to outlive a turn (the Pro class's `claude` child session) is
|
|
1175
|
+
// keyed by this one instead, so a thread keeps its context and
|
|
1176
|
+
// `/new` or `/resume` genuinely starts/continues a different one.
|
|
1177
|
+
sessionKey: commandCtx.sessionId,
|
|
1066
1178
|
// Opt-in to the round-horizon dialog (see engine.js requestRoundsAsk)
|
|
1067
1179
|
// only when there is actually a `rounds` prompter to answer it — a
|
|
1068
1180
|
// one-shot `-p` run or any other caller with no presenter keeps the
|
|
@@ -1501,6 +1613,17 @@ function createApp(options = {}) {
|
|
|
1501
1613
|
get: () => commandCtx.sessionId,
|
|
1502
1614
|
set: (v) => { commandCtx.sessionId = v; },
|
|
1503
1615
|
});
|
|
1616
|
+
// Drop whatever a transport remembered ABOUT this conversation, as opposed
|
|
1617
|
+
// to what this host keeps in `transcript`. `/clear` empties the transcript,
|
|
1618
|
+
// but the Pro class's memory lives in the `claude` child's own session —
|
|
1619
|
+
// reattaching to it afterwards would answer from turns the user just
|
|
1620
|
+
// erased, which reads as the clear having failed. Keyed by session id, the
|
|
1621
|
+
// same id `sessionKey` travels as, so the two cannot drift.
|
|
1622
|
+
c.clearConversationMemory = () => {
|
|
1623
|
+
if (engine && typeof engine.clearSessionApprovals === 'function') {
|
|
1624
|
+
engine.clearSessionApprovals(commandCtx.sessionId);
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1504
1627
|
return c;
|
|
1505
1628
|
}
|
|
1506
1629
|
|
|
@@ -1692,11 +1815,12 @@ function createApp(options = {}) {
|
|
|
1692
1815
|
// always goes to `err` regardless of `json`.
|
|
1693
1816
|
if (!client.apiKey && !provisionAttempted) {
|
|
1694
1817
|
provisionAttempted = true;
|
|
1695
|
-
const result = await autoProvisionApiKey(client, credentials);
|
|
1818
|
+
const result = await autoProvisionApiKey(client, credentials, { app: 'cli' });
|
|
1696
1819
|
if (result.key) {
|
|
1697
1820
|
err.write(
|
|
1698
|
-
`aegiscode:
|
|
1821
|
+
`aegiscode: auto-provisioned a free account` +
|
|
1699
1822
|
(result.ok ? ` (saved to ${credentials.credentialsPath()})` : ' (could not save it — reconfigure with /key)') +
|
|
1823
|
+
trialNote(result) +
|
|
1700
1824
|
`. Fund it at ${client.promptUrl('topup', 'device_autoprovision')} or run /byok to use your own key.\n`
|
|
1701
1825
|
);
|
|
1702
1826
|
}
|
package/src/chatflow.js
CHANGED
|
@@ -54,6 +54,9 @@ const { LineEditor } = require('./input.js');
|
|
|
54
54
|
const { renderMarkdown } = require('./markdown.js');
|
|
55
55
|
const overlays = require('./overlays.js');
|
|
56
56
|
const models = require('./models.js');
|
|
57
|
+
const { resolveShared } = require('./sharedpaths.js');
|
|
58
|
+
const { validateApiKey } = require(resolveShared(require('node:path').join('client', 'credentials.js')));
|
|
59
|
+
const claudePro = require(resolveShared(require('node:path').join('desktop', 'lib', 'local', 'claude-pro.js')));
|
|
57
60
|
const fuzzy = require('./fuzzy.js');
|
|
58
61
|
const { fmtTokens, fmtEur, fmtElapsed, fmtUsageSplit, displayTokens, pathName, feeBillable } = require('./format.js');
|
|
59
62
|
const { editPreview } = require('./diff.js');
|
|
@@ -254,6 +257,61 @@ function historyPairs(rows) {
|
|
|
254
257
|
.map((m) => ({ role: m.role, content: m.text }));
|
|
255
258
|
}
|
|
256
259
|
|
|
260
|
+
// A byok "anthropic:<model>" id's model half → the PRO_MODELS alias it reads
|
|
261
|
+
// closest to. 'default' when nothing matches, which is every dated/snapshot
|
|
262
|
+
// id (`claude-sonnet-4-20250514`) as much as a name this table has not been
|
|
263
|
+
// taught — the subscription's own default is a safer landing than guessing
|
|
264
|
+
// wrong.
|
|
265
|
+
const PRO_ALIAS_KEYWORDS = Object.freeze(['opus', 'haiku', 'sonnet']);
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A picked "anthropic:<model>" byok row this machine has no console key for,
|
|
269
|
+
* but IS already signed into Claude Code Pro/Max for, is better served by the
|
|
270
|
+
* subscription it already pays for than by a prompt for a second credential
|
|
271
|
+
* it does not have — `engine.js`'s own refusal message for this exact state
|
|
272
|
+
* already says so ("Use the subscription instead: /class pro"); this is that
|
|
273
|
+
* suggestion applied at pick time instead of left for the user to notice in
|
|
274
|
+
* an error and type a second command.
|
|
275
|
+
*
|
|
276
|
+
* A row with a real console key already stored takes that key, unchanged —
|
|
277
|
+
* the override only fires when `modelKeyPlan` would otherwise have to ask for
|
|
278
|
+
* one. Pure and unit-testable: every fact it needs (whether a key is already
|
|
279
|
+
* stored, whether the subscription is signed in, the PRO_MODELS table) is
|
|
280
|
+
* injected rather than read from a live host/environment.
|
|
281
|
+
*
|
|
282
|
+
* @param {object} chosen a picker row ({id, cls, ...})
|
|
283
|
+
* @param {object} o
|
|
284
|
+
* @param {boolean} o.hasStored the byok provider store already holds an
|
|
285
|
+
* anthropic key (desktop Provider settings / `/byok-key anthropic`)
|
|
286
|
+
* @param {boolean} o.proLoggedIn this machine is signed into Claude Code Pro
|
|
287
|
+
* @param {Array<{id:string,label:string,note:string}>} o.proModels
|
|
288
|
+
* `claudePro.PRO_MODELS`, injected rather than required here
|
|
289
|
+
* @returns {{row:object, message:string|null}} the row to actually pin (the
|
|
290
|
+
* original, unchanged, when the override does not apply) and a note to
|
|
291
|
+
* surface when it does
|
|
292
|
+
*/
|
|
293
|
+
function overrideAnthropicByokWithPro(chosen, o = {}) {
|
|
294
|
+
if (!chosen || chosen.cls !== 'byok') return { row: chosen, message: null };
|
|
295
|
+
const id = String(chosen.id || '');
|
|
296
|
+
const colon = id.indexOf(':');
|
|
297
|
+
if (colon < 0 || id.slice(0, colon).trim().toLowerCase() !== 'anthropic') {
|
|
298
|
+
return { row: chosen, message: null };
|
|
299
|
+
}
|
|
300
|
+
if (!o.needsKey) return { row: chosen, message: null }; // a real console key is already usable
|
|
301
|
+
if (!o.proLoggedIn) return { row: chosen, message: null }; // no subscription either — the normal prompt stands
|
|
302
|
+
const modelPart = id.slice(colon + 1).toLowerCase();
|
|
303
|
+
const proModels = Array.isArray(o.proModels) && o.proModels.length ? o.proModels : [{ id: 'default', label: 'Default', note: '' }];
|
|
304
|
+
const aliasId = PRO_ALIAS_KEYWORDS.find((kw) => modelPart.includes(kw)) || 'default';
|
|
305
|
+
const row = proModels.find((m) => m.id === aliasId) || proModels[0];
|
|
306
|
+
return {
|
|
307
|
+
row: { id: row.id, label: row.label, note: row.note, cls: 'pro' },
|
|
308
|
+
message:
|
|
309
|
+
`${id} has no Anthropic console key on this machine, but Claude Code Pro is signed in — ` +
|
|
310
|
+
`using the subscription instead (claude --model ${row.id}). Add a real console key any ` +
|
|
311
|
+
`time with /byok-key anthropic <key> to run this row directly.`,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
257
315
|
/**
|
|
258
316
|
* Palette ranking query for a typed command line: "/memory tiers" must keep
|
|
259
317
|
* ranking on "memory" so the command stays listed while the user finishes the
|
|
@@ -1994,10 +2052,15 @@ async function runSession(host) {
|
|
|
1994
2052
|
return;
|
|
1995
2053
|
}
|
|
1996
2054
|
for (const step of queue) {
|
|
1997
|
-
// Pooled rows bill the account; a vendor step names its provider
|
|
1998
|
-
//
|
|
1999
|
-
//
|
|
2000
|
-
|
|
2055
|
+
// Pooled rows bill the account; a vendor step names its provider; the
|
|
2056
|
+
// Claude Code Pro step has neither — it is the subscription's own OAuth
|
|
2057
|
+
// token, minted with `claude setup-token` (or lifted from wherever it is
|
|
2058
|
+
// already set aside). The label says WHICH key is wanted, because two
|
|
2059
|
+
// prompts in a row for the same row must not read as the same question
|
|
2060
|
+
// asked twice.
|
|
2061
|
+
const label = step.role === 'account' ? 'AEGIS account key'
|
|
2062
|
+
: step.role === 'claude-pro' ? 'Claude Code OAuth token (`claude setup-token` mints one)'
|
|
2063
|
+
: `${step.provider} key`;
|
|
2001
2064
|
const key = String(
|
|
2002
2065
|
(await c.readSecret(`${label} → ${step.env} (kept off screen, Enter to skip): `)) || ''
|
|
2003
2066
|
).trim();
|
|
@@ -2008,15 +2071,38 @@ async function runSession(host) {
|
|
|
2008
2071
|
note(`no key given — ${step.env} is still unset, so ${chosen.id} will fail until it is.`);
|
|
2009
2072
|
continue;
|
|
2010
2073
|
}
|
|
2074
|
+
// Shape check before it ever touches disk: this is the same structural
|
|
2075
|
+
// check the account-key login flow has always had (empty / whitespace /
|
|
2076
|
+
// under 16 chars), now applied here too. Without it a truncated paste
|
|
2077
|
+
// (a 2-char clipboard miss, once landed as a literal ANTHROPIC_API_KEY)
|
|
2078
|
+
// writes straight to .env, reads as "configured" to every status check
|
|
2079
|
+
// that only asks `inFile`, and the row fails upstream on every real turn
|
|
2080
|
+
// with an opaque provider error — "key needed" never shows again because
|
|
2081
|
+
// the picker believes it already has one.
|
|
2082
|
+
const shapeLabel = step.role === 'account' ? 'AEGIS'
|
|
2083
|
+
: step.role === 'claude-pro' ? 'Claude Code OAuth'
|
|
2084
|
+
: step.provider || 'that provider';
|
|
2085
|
+
const shape = validateApiKey(key, { label: shapeLabel });
|
|
2086
|
+
if (!shape.ok) {
|
|
2087
|
+
note(`not saved — ${shape.message}. ${step.env} is still unset.`);
|
|
2088
|
+
continue;
|
|
2089
|
+
}
|
|
2011
2090
|
// `env: step.env` is what makes a per-step store possible at all: the row
|
|
2012
2091
|
// alone cannot say which of its two keys this value is for.
|
|
2013
|
-
const res = models.storeModelKey(chosen, key, { env: step.env });
|
|
2092
|
+
const res = models.storeModelKey(chosen, shape.key, { env: step.env });
|
|
2014
2093
|
if (!res.ok) {
|
|
2015
2094
|
note(`could not save the key: ${res.error || 'unknown error'}`);
|
|
2016
2095
|
continue;
|
|
2017
2096
|
}
|
|
2097
|
+
// A foreign secret (CLAUDE_CODE_OAUTH_TOKEN) lands in secrets.env, which
|
|
2098
|
+
// is read explicitly by the one transport that needs it — not loaded
|
|
2099
|
+
// ambiently at start-up the way `.env` is — so it gets its own wording
|
|
2100
|
+
// rather than the "both hosts read that file" line, which is true of
|
|
2101
|
+
// `.env` and would overstate what secrets.env actually does.
|
|
2018
2102
|
note(res.changed
|
|
2019
|
-
?
|
|
2103
|
+
? res.foreign
|
|
2104
|
+
? `${step.env} saved to ${res.file} (0600) — read only by the Claude Code Pro transport, never exported.`
|
|
2105
|
+
: `${step.env} saved to ${res.file} (0600) — both hosts read that file; nothing to export.`
|
|
2020
2106
|
: `${step.env} was already set in ${res.file}.`);
|
|
2021
2107
|
}
|
|
2022
2108
|
};
|
|
@@ -2032,10 +2118,34 @@ async function runSession(host) {
|
|
|
2032
2118
|
*/
|
|
2033
2119
|
const applyModelRow = async (chosen) => {
|
|
2034
2120
|
if (!chosen) return;
|
|
2035
|
-
|
|
2121
|
+
{
|
|
2122
|
+
// Swap an anthropic byok row for the equivalent Claude Code Pro alias
|
|
2123
|
+
// when this machine is signed into the subscription and holds no real
|
|
2124
|
+
// console key — see `overrideAnthropicByokWithPro` (module scope, pure)
|
|
2125
|
+
// for the full reasoning.
|
|
2126
|
+
const plan = models.modelKeyPlan(chosen, {
|
|
2127
|
+
hasStored: host.hasProviderKey ? !!host.hasProviderKey('anthropic') : false,
|
|
2128
|
+
});
|
|
2129
|
+
const { row, message } = overrideAnthropicByokWithPro(chosen, {
|
|
2130
|
+
needsKey: !!(plan && plan.needed),
|
|
2131
|
+
proLoggedIn: models.claudeProLoggedIn(),
|
|
2132
|
+
proModels: claudePro.PRO_MODELS,
|
|
2133
|
+
});
|
|
2134
|
+
chosen = row;
|
|
2135
|
+
if (message) note(message);
|
|
2136
|
+
}
|
|
2137
|
+
// A row that belongs to another class moves the session to that class
|
|
2138
|
+
// BEFORE the pin is stored, for the same reason byok's row does (and it is
|
|
2139
|
+
// the same one-line rule, not a second copy of it): a pro alias pinned while
|
|
2140
|
+
// the session sits on aegis would be sent to the pool as an AEGIS id, and
|
|
2141
|
+
// an AEGIS id pinned under pro would be handed to `claude --model`. Both
|
|
2142
|
+
// fail on the next turn, with a message about a model rather than the class.
|
|
2143
|
+
if (chosen.cls && chosen.cls !== 'aegis' && ctx.modelClass !== chosen.cls) {
|
|
2144
|
+
await dispatch(`/class ${chosen.cls}`);
|
|
2145
|
+
}
|
|
2036
2146
|
ctx.model = chosen.id;
|
|
2037
2147
|
host.updateConfig({ model: chosen.id, currentModelId: chosen.id, modelClass: ctx.modelClass });
|
|
2038
|
-
note(`model: ${chosen.id}${chosen.cls === 'byok' ? ' (byok)' : ''}`);
|
|
2148
|
+
note(`model: ${chosen.id}${chosen.cls === 'byok' ? ' (byok)' : chosen.cls === 'pro' ? ' (Claude Code Pro)' : ''}`);
|
|
2039
2149
|
await collectKeyFor(chosen);
|
|
2040
2150
|
};
|
|
2041
2151
|
|
|
@@ -2729,6 +2839,7 @@ module.exports = {
|
|
|
2729
2839
|
summarizeTurnTools,
|
|
2730
2840
|
finalizeTurnText,
|
|
2731
2841
|
historyPairs,
|
|
2842
|
+
overrideAnthropicByokWithPro,
|
|
2732
2843
|
paletteQuery,
|
|
2733
2844
|
headerLine,
|
|
2734
2845
|
separatorLine,
|
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
|
/**
|
|
@@ -988,6 +1022,12 @@ const COMMANDS = [
|
|
|
988
1022
|
c.transcript.length = 0;
|
|
989
1023
|
// Prune the session's history rows so /cost resets with /clear.
|
|
990
1024
|
pruneSessionHistory(c.sessionId);
|
|
1025
|
+
// Emptying the transcript is only half a clear: a transport that keeps
|
|
1026
|
+
// its own memory of this conversation (the Pro class's `claude` child
|
|
1027
|
+
// session) still holds the turns that were just erased, and would answer
|
|
1028
|
+
// from them on the next turn. Clearing the transcript our loop reads is
|
|
1029
|
+
// exactly the case where the other half must be dropped too.
|
|
1030
|
+
if (typeof c.clearConversationMemory === 'function') c.clearConversationMemory();
|
|
991
1031
|
note(c, 'Session cleared — transcript empty.');
|
|
992
1032
|
c.render();
|
|
993
1033
|
return true;
|
|
@@ -1400,7 +1440,10 @@ const COMMANDS = [
|
|
|
1400
1440
|
// Say why, and what unblocks it: an unreachable catalog is almost
|
|
1401
1441
|
// always a missing key or no network, and "no models advertised"
|
|
1402
1442
|
// read as "the platform has none" rather than "this client could not
|
|
1403
|
-
// ask".
|
|
1443
|
+
// ask". Reachable only when even Claude Code Pro's static alias rows
|
|
1444
|
+
// are absent — PRO_MODELS is a non-empty constant, so in practice
|
|
1445
|
+
// this is the full-outage fallback, not the common "no AEGIS key"
|
|
1446
|
+
// case that used to land here (see the branch just below).
|
|
1404
1447
|
note(c, c.state().online
|
|
1405
1448
|
? 'Could not read the model catalog (offline, or the server refused it) — /models retries.'
|
|
1406
1449
|
: // The key travels in the environment only (client/aegis.js reads
|
|
@@ -1410,6 +1453,16 @@ const COMMANDS = [
|
|
|
1410
1453
|
c.render();
|
|
1411
1454
|
return true;
|
|
1412
1455
|
}
|
|
1456
|
+
// AEGIS Cloud and byok both need a key this machine does not have:
|
|
1457
|
+
// almost always a missing AEGIS_API_KEY or no network. Claude Code Pro
|
|
1458
|
+
// needs neither (it is the subscription's own OAuth token, collected
|
|
1459
|
+
// when a pro row is picked), so its rows still show — the picker opens
|
|
1460
|
+
// with what IS available rather than blocking on what is not.
|
|
1461
|
+
if (!models.some((m) => m.cls === 'aegis' || m.cls === 'byok')) {
|
|
1462
|
+
note(c, c.state().online
|
|
1463
|
+
? 'Could not read the AEGIS Cloud catalog (offline, or the server refused it) — showing Claude Code Pro only; /models retries.'
|
|
1464
|
+
: `No AEGIS API key set, so the AEGIS Cloud catalog cannot be read (free key: ${signupUrl('model_blocked')}) — showing Claude Code Pro only.`);
|
|
1465
|
+
}
|
|
1413
1466
|
// A pin that is not in the catalog is not honoured — the pool answers
|
|
1414
1467
|
// from its own default with no error. Say so where the pin is visible
|
|
1415
1468
|
// rather than letting the reply look like the pinned model. On byok the
|
|
@@ -2155,6 +2208,11 @@ const COMMANDS = [
|
|
|
2155
2208
|
desc: 'Start a new session (clears the transcript, fresh session id)',
|
|
2156
2209
|
handler: async (c) => {
|
|
2157
2210
|
c.transcript.length = 0;
|
|
2211
|
+
// Release the conversation being left behind BEFORE the id changes — a
|
|
2212
|
+
// new session id is a new key, so the old entry would otherwise sit in
|
|
2213
|
+
// the engine's map for the life of the process, holding a `claude` child
|
|
2214
|
+
// session nobody can reach or clear again.
|
|
2215
|
+
if (typeof c.clearConversationMemory === 'function') c.clearConversationMemory();
|
|
2158
2216
|
const id = 'aegis-' + Math.random().toString(36).slice(2, 10);
|
|
2159
2217
|
c.sessionId = id;
|
|
2160
2218
|
c.ctx.sessionId = id;
|
|
@@ -2708,7 +2766,13 @@ const COMMANDS = [
|
|
|
2708
2766
|
if (lower === 'register') {
|
|
2709
2767
|
const res = await c.registerAccount();
|
|
2710
2768
|
if (res.alreadyKeyed) {
|
|
2711
|
-
|
|
2769
|
+
// Registration is per machine fingerprint and the welcome trial is
|
|
2770
|
+
// granted once per machine, ever, so this branch can never produce a
|
|
2771
|
+
// new trial however many times it is run — and a user who wiped their
|
|
2772
|
+
// credential store lands here precisely expecting one. Say so, and
|
|
2773
|
+
// name the two paths that actually do something, rather than a
|
|
2774
|
+
// no-op notice that reads like a refusal for no reason.
|
|
2775
|
+
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
2776
|
} else if (res.key && res.ok) {
|
|
2713
2777
|
done(c, 'AEGIS account key provisioned and saved');
|
|
2714
2778
|
} else if (res.key) {
|
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
|
/**
|