aegisone 1.0.10 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/scripts/predist.mjs +19 -0
- package/src/child.js +121 -2
- package/vendor/cli/package.json +3 -2
- package/vendor/cli/src/app.js +176 -13
- package/vendor/cli/src/chatflow.js +193 -38
- package/vendor/cli/src/commands.js +82 -4
- package/vendor/cli/src/deps.js +29 -2
- package/vendor/cli/src/engine.js +8 -1
- package/vendor/cli/src/models.js +78 -3
- package/vendor/cli/src/overlays.js +20 -7
- package/vendor/cli/src/topup.js +1 -1
- package/vendor/cli/vendor/client/aegis.js +119 -5
- package/vendor/cli/vendor/client/auto-provision.js +89 -17
- package/vendor/cli/vendor/client/credentials.js +8 -2
- package/vendor/cli/vendor/client/device-fingerprint.js +1 -8
- package/vendor/cli/vendor/client/env-file.js +262 -8
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +755 -0
- package/vendor/cli/vendor/desktop/lib/local/engine.js +329 -12
- package/vendor/cli/vendor/mcp/server.js +1 -1
- package/vendor/cli/vendor/one/src/child.js +287 -0
- package/vendor/cli/vendor/one/src/permissions.js +371 -0
- package/vendor/desktop/lib/account-key.js +60 -0
- package/vendor/desktop/lib/local/claude-pro.js +755 -0
- package/vendor/desktop/lib/local/engine.js +329 -12
- package/vendor/desktop/main.js +109 -33
- package/vendor/desktop/package.json +4 -3
- package/vendor/desktop/preload.js +8 -0
- package/vendor/desktop/renderer/app.js +50 -0
- package/vendor/desktop/renderer/index.html +11 -0
- package/vendor/desktop/vendor/aegis.js +119 -5
- package/vendor/desktop/vendor/auto-provision.js +89 -17
- package/vendor/desktop/vendor/credentials.js +8 -2
- package/vendor/desktop/vendor/device-fingerprint.js +1 -8
- package/vendor/desktop/vendor/env-file.js +262 -8
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegisone",
|
|
3
3
|
"productName": "AEGISONE",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.16",
|
|
5
5
|
"description": "AEGISONE — one product, two faces. `aegis` opens the window when there is nothing else to do and runs the terminal otherwise; `aegiscode` keeps behaving exactly as it always has.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
package/scripts/predist.mjs
CHANGED
|
@@ -158,6 +158,25 @@ export const MANIFEST = [
|
|
|
158
158
|
note: 'the pure usage mapping shared by the window and the terminal' },
|
|
159
159
|
{ src: 'desktop/lib/local/engine.js', shapes: ['mirror'],
|
|
160
160
|
note: 'the agent loop, reused as-is (one loop, not a second one drifting)' },
|
|
161
|
+
// engine.js requires ./claude-pro.js at load (the Claude Code Pro class'
|
|
162
|
+
// transport), exactly as local.js requires ./context.js — and with exactly
|
|
163
|
+
// the same consequence when the row is absent: the staged engine throws
|
|
164
|
+
// MODULE_NOT_FOUND from inside vendor/, and the packaged CLI does not load at
|
|
165
|
+
// all. test/one-manifest-complete.test.mjs derives the dependency, so this is
|
|
166
|
+
// a red line there rather than a mystery in cli-package.
|
|
167
|
+
{ src: 'desktop/lib/local/claude-pro.js', shapes: ['mirror'],
|
|
168
|
+
note: 'the Claude Code Pro transport; requires ./../../one/src/child.js at call time' },
|
|
169
|
+
// The Pro class' argv half. claude-pro.js resolves these at CALL time through
|
|
170
|
+
// path.join (not a relative require), so the manifest-completeness scan cannot
|
|
171
|
+
// see them — which is why they are written down here by hand and why they were
|
|
172
|
+
// missed. `one/src/permissions.js` reaches the CLI's own rule evaluator at
|
|
173
|
+
// cli/src/permissions.js, itself resolved through the staged `../vendor/cli/`
|
|
174
|
+
// layout ('mirror' stages them at cli/vendor/cli/src/…, which is the second
|
|
175
|
+
// candidate that module looks in).
|
|
176
|
+
{ src: 'one/src/child.js', shapes: ['mirror'],
|
|
177
|
+
note: 'the ONE claude-child argv builder (rule 4); resolved by claude-pro.js at call time' },
|
|
178
|
+
{ src: 'one/src/permissions.js', shapes: ['mirror'],
|
|
179
|
+
note: 'resolvePosture() — the permission half of the argv, resolved at call time' },
|
|
161
180
|
{ src: 'desktop/lib/local/local.js', shapes: ['mirror'],
|
|
162
181
|
note: 'the local model transport and its fail-closed base-URL check' },
|
|
163
182
|
// The row whose ABSENCE broke the packaged CLI: `local.js` requires
|
package/src/child.js
CHANGED
|
@@ -60,8 +60,62 @@ const FLAGS = Object.freeze({
|
|
|
60
60
|
print: '-p',
|
|
61
61
|
outputFormat: '--output-format',
|
|
62
62
|
model: '--model',
|
|
63
|
+
// Conversation continuity for the Pro child (see `sessionId` below). Both
|
|
64
|
+
// spellings are the CLI's own (claude 2.1.228 --help): `--session-id <uuid>`
|
|
65
|
+
// names the session a NEW conversation runs in, `--resume <id>` reattaches to
|
|
66
|
+
// an existing one, which is what carries the prior turns' context across
|
|
67
|
+
// separate child processes.
|
|
68
|
+
sessionId: '--session-id',
|
|
69
|
+
resume: '--resume',
|
|
70
|
+
// The extra working directories the child may touch (claude 2.1.228 --help:
|
|
71
|
+
// "Additional directories to allow tool …"). See addDirArgs() — the spelling
|
|
72
|
+
// here is deliberately the EQUALS form and that is not cosmetic.
|
|
73
|
+
addDir: '--add-dir',
|
|
63
74
|
});
|
|
64
75
|
|
|
76
|
+
/**
|
|
77
|
+
* `--add-dir` is the child's own sandbox boundary: by default a headless child
|
|
78
|
+
* resolves every relative path and every tool's root against the directory it
|
|
79
|
+
* was spawned in, so a turn started in `repo/cli/` cannot read, run or even
|
|
80
|
+
* SEE `repo/test/` — the exact "outside the sandboxed directory" wall a real
|
|
81
|
+
* session reported from this product.
|
|
82
|
+
*
|
|
83
|
+
* ── why the EQUALS form, and why one flag per directory ─────────────────────
|
|
84
|
+
*
|
|
85
|
+
* `--add-dir` is VARIADIC: the child keeps consuming the words after it as
|
|
86
|
+
* directories. So the obvious `['--add-dir', dir, prompt]` is not merely
|
|
87
|
+
* fragile, it is broken — and this was measured against the installed binary
|
|
88
|
+
* (2.1.228), not reasoned about:
|
|
89
|
+
*
|
|
90
|
+
* claude -p --add-dir /tmp "do the thing" → Error: Input must be provided
|
|
91
|
+
* either through stdin or as a
|
|
92
|
+
* prompt argument when using --print
|
|
93
|
+
* claude -p --add-dir=/tmp "do the thing" → runs
|
|
94
|
+
*
|
|
95
|
+
* The prompt is the LAST item of the argv (rule 4 keeps it there, because the
|
|
96
|
+
* child reads it as the initial message). A space-form `--add-dir` immediately
|
|
97
|
+
* before it therefore swallows the user's prompt into the directory list, and
|
|
98
|
+
* the turn dies as an empty-input error before the model is ever reached.
|
|
99
|
+
* Attaching the value to the flag with `=` terminates the variadic run, so the
|
|
100
|
+
* prompt survives, and one flag per directory keeps a directory whose name
|
|
101
|
+
* begins with `-` from being re-read as another option. Empty and duplicate
|
|
102
|
+
* entries are dropped here rather than passed on: the list reaches the child's
|
|
103
|
+
* sandbox, so what it contains is a decision, not a formality.
|
|
104
|
+
*/
|
|
105
|
+
function addDirArgs(dirs) {
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const dir of unique(dirs)) out.push(`${FLAGS.addDir}=${dir}`);
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A UUID, as `--session-id` requires. The CLI rejects anything else, and it
|
|
113
|
+
* rejects it AFTER the spawn — an argv that cannot work must not be built, so
|
|
114
|
+
* this returns null and the caller throws rather than typing a value the child
|
|
115
|
+
* will refuse while the turn looks as if it started.
|
|
116
|
+
*/
|
|
117
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
118
|
+
|
|
65
119
|
const DEFAULT_OUTPUT_FORMAT = 'stream-json';
|
|
66
120
|
|
|
67
121
|
/** Dedupe while keeping the user's own rule order (rules are read top-down). */
|
|
@@ -87,12 +141,22 @@ function unique(list) {
|
|
|
87
141
|
* @param {string} [descriptor.outputFormat] headless only; defaults to stream-json
|
|
88
142
|
* @param {string} [descriptor.permissionMode] explicit passthrough, one of
|
|
89
143
|
* PERMISSION_MODES (else throw)
|
|
144
|
+
* @param {string} [descriptor.resumeSessionId] reattach to an existing child
|
|
145
|
+
* session → `--resume <uuid>`
|
|
146
|
+
* @param {string} [descriptor.sessionId] name a NEW child session, so a
|
|
147
|
+
* LATER turn can `--resume` it
|
|
148
|
+
* @param {string[]} [descriptor.addDir] extra directories the child may
|
|
149
|
+
* work in → `--add-dir=<dir>` each
|
|
90
150
|
* @param {string[]} [descriptor.extra] extra argv items, appended last
|
|
91
151
|
* @returns {{argv: string[], record: object}} both frozen
|
|
92
152
|
* @throws when `permissionMode` is set to something Claude does not accept —
|
|
93
153
|
* a mode we cannot name is a mode we must not silently drop, because
|
|
94
154
|
* the run log would then record "no passthrough" for a run that asked
|
|
95
155
|
* for one.
|
|
156
|
+
* @throws when a session id is given that is not a UUID. Same reason, harder:
|
|
157
|
+
* `claude` refuses a malformed `--session-id` itself, after the spawn,
|
|
158
|
+
* so passing one through would turn a continuity bug into an opaque
|
|
159
|
+
* failed turn.
|
|
96
160
|
*/
|
|
97
161
|
function claudeArgv(descriptor = {}) {
|
|
98
162
|
const posture = descriptor.posture;
|
|
@@ -123,15 +187,49 @@ function claudeArgv(descriptor = {}) {
|
|
|
123
187
|
// would be a refusal the user never asked for.
|
|
124
188
|
const unmappedAsk = unique(rules.ask);
|
|
125
189
|
|
|
190
|
+
// ── conversation continuity ───────────────────────────────────────────────
|
|
191
|
+
//
|
|
192
|
+
// The Pro child runs its own agent loop, so the engine does not replay the
|
|
193
|
+
// transcript into it (engine.js's `pro` branch). Continuity therefore has to
|
|
194
|
+
// come from the CLI's own session store, or every turn is a new conversation
|
|
195
|
+
// with no memory of the last one — which is exactly what it was.
|
|
196
|
+
//
|
|
197
|
+
// `resumeSessionId` wins over `sessionId`: a reattach to a session we already
|
|
198
|
+
// had is the same conversation, and naming a NEW id while resuming would
|
|
199
|
+
// start a second thread beside the live one. Both are validated as UUIDs
|
|
200
|
+
// before they reach argv, because the CLI's own rejection lands after the
|
|
201
|
+
// spawn.
|
|
202
|
+
const wantedResumeId = descriptor.resumeSessionId ? String(descriptor.resumeSessionId).trim() : '';
|
|
203
|
+
const wantedNewId = descriptor.sessionId ? String(descriptor.sessionId).trim() : '';
|
|
204
|
+
const resumeId = wantedResumeId || null;
|
|
205
|
+
const newId = !resumeId && wantedNewId ? wantedNewId : null;
|
|
206
|
+
for (const [label, value] of [['resumeSessionId', resumeId], ['sessionId', newId]]) {
|
|
207
|
+
if (value && !UUID_RE.test(value)) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`${label} ${JSON.stringify(value)} is not a UUID — refusing to pass it to ` +
|
|
210
|
+
'--resume/--session-id, which the child rejects after the spawn (turning a ' +
|
|
211
|
+
'continuity bug into an opaque failed turn).'
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
126
216
|
const argv = [];
|
|
127
217
|
if (headless) {
|
|
128
218
|
argv.push(FLAGS.print, FLAGS.outputFormat, String(descriptor.outputFormat || DEFAULT_OUTPUT_FORMAT));
|
|
129
219
|
}
|
|
130
220
|
if (descriptor.model) argv.push(FLAGS.model, String(descriptor.model));
|
|
221
|
+
// The widened sandbox, before the permission flags: what the child may reach
|
|
222
|
+
// is decided here, and the prompt stays last (see addDirArgs).
|
|
223
|
+
const addDir = addDirArgs(descriptor.addDir);
|
|
224
|
+
argv.push(...addDir);
|
|
131
225
|
if (allowedTools.length) argv.push(FLAGS.allowedTools, allowedTools.join(','));
|
|
132
226
|
if (disallowedTools.length) argv.push(FLAGS.disallowedTools, disallowedTools.join(','));
|
|
133
227
|
if (modeGiven) argv.push(FLAGS.permissionMode, mode);
|
|
134
228
|
if (posture.child && posture.child.flag) argv.push(posture.child.flag);
|
|
229
|
+
// Before `extra` (the transport's own flags) and before the prompt, which
|
|
230
|
+
// must stay last so the child reads it as the initial message.
|
|
231
|
+
if (resumeId) argv.push(FLAGS.resume, resumeId);
|
|
232
|
+
else if (newId) argv.push(FLAGS.sessionId, newId);
|
|
135
233
|
if (Array.isArray(descriptor.extra)) argv.push(...descriptor.extra.map(String));
|
|
136
234
|
if (descriptor.prompt !== undefined && descriptor.prompt !== null) argv.push(String(descriptor.prompt));
|
|
137
235
|
|
|
@@ -146,6 +244,15 @@ function claudeArgv(descriptor = {}) {
|
|
|
146
244
|
allowedTools: Object.freeze(allowedTools),
|
|
147
245
|
disallowedTools: Object.freeze(disallowedTools),
|
|
148
246
|
unmappedAsk: Object.freeze(unmappedAsk),
|
|
247
|
+
// Recorded, not inferred, exactly like the argv: an install that WIDENED its
|
|
248
|
+
// sandbox for the child is the one thing a later reader of the run log must
|
|
249
|
+
// not have to reconstruct from the argv's shape.
|
|
250
|
+
addDir: Object.freeze(addDir.map((a) => a.slice(FLAGS.addDir.length + 1))),
|
|
251
|
+
// Continuity, recorded the same way the mode is: which of the two happened
|
|
252
|
+
// (reattached vs. named a new session) is part of what this turn asked for,
|
|
253
|
+
// and a caller reading only the argv would have to infer it from position.
|
|
254
|
+
resumeSessionId: resumeId,
|
|
255
|
+
sessionId: newId,
|
|
149
256
|
argv: Object.freeze(argv.slice()),
|
|
150
257
|
});
|
|
151
258
|
|
|
@@ -161,8 +268,20 @@ function childRecordLine(record) {
|
|
|
161
268
|
return (
|
|
162
269
|
`aegis: claude child [${record.kind}] ${record.skipFlag || 'no permission flag'} · ${mode} · ` +
|
|
163
270
|
`allowedTools=[${record.allowedTools.join(', ')}] disallowedTools=[${record.disallowedTools.join(', ')}]` +
|
|
164
|
-
(record.unmappedAsk.length ? ` (ask rules recorded, unmapped: ${record.unmappedAsk.join(', ')})` : '')
|
|
271
|
+
(record.unmappedAsk.length ? ` (ask rules recorded, unmapped: ${record.unmappedAsk.join(', ')})` : '') +
|
|
272
|
+
// The widened sandbox, named for the same reason the mode is: "the child
|
|
273
|
+
// could only see its own directory" is otherwise indistinguishable, in a
|
|
274
|
+
// transcript, from "the model chose not to look".
|
|
275
|
+
(record.addDir && record.addDir.length ? ` · addDir=[${record.addDir.join(', ')}]` : '') +
|
|
276
|
+
// The continuity half, named rather than left to be read off the argv:
|
|
277
|
+
// "resumed" and "new id" are the two things a turn can mean here, and a
|
|
278
|
+
// turn that silently did neither is the bug this line makes visible.
|
|
279
|
+
(record.resumeSessionId
|
|
280
|
+
? ` · resumed session ${record.resumeSessionId}`
|
|
281
|
+
: record.sessionId
|
|
282
|
+
? ` · new session ${record.sessionId}`
|
|
283
|
+
: ' · no session id (each turn is a new conversation)')
|
|
165
284
|
);
|
|
166
285
|
}
|
|
167
286
|
|
|
168
|
-
module.exports = { FLAGS, DEFAULT_OUTPUT_FORMAT, claudeArgv, childRecordLine };
|
|
287
|
+
module.exports = { FLAGS, DEFAULT_OUTPUT_FORMAT, claudeArgv, addDirArgs, childRecordLine };
|
package/vendor/cli/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/vendor/cli/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, 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');
|
|
@@ -145,27 +145,39 @@ function createApp(options = {}) {
|
|
|
145
145
|
// With no key configured anywhere, ask aegis1 for a free device key before
|
|
146
146
|
// ever showing "no key" — same shared helper (client/auto-provision.js) the
|
|
147
147
|
// MCP plugin and the desktop app use, so all three ask for the same account
|
|
148
|
-
// on the same machine. One
|
|
149
|
-
// call: register-device is rate-limited server-side, and a session that
|
|
148
|
+
// on the same machine. One provisioning per `createApp()` instance, not one
|
|
149
|
+
// per call: register-device is rate-limited server-side, and a session that
|
|
150
150
|
// fires several turns before noticing a failure must not retry the same
|
|
151
|
-
// failing call each time. A
|
|
151
|
+
// failing call each time. A transient failure gets a few bounded retries
|
|
152
|
+
// inside that one provisioning. A brand-new fingerprint comes back with aegis1's
|
|
152
153
|
// one-time 30-day welcome-trial `unlimited` entitlement (token-bank credit
|
|
153
154
|
// plus a `subscriptions` row) granted in the same request — aegis1 commit
|
|
154
155
|
// 4372830 — so the account is usable pooled right away rather than starting
|
|
155
156
|
// at zero. The credit is finite: once it is spent or the trial lapses, the
|
|
156
157
|
// usual plan/balance gate applies.
|
|
157
158
|
let provisionAttempted = false;
|
|
159
|
+
let keyFailure = '';
|
|
160
|
+
async function provisionDeviceKey() {
|
|
161
|
+
const result = await autoProvisionApiKey(client, credentials, { app: 'cli' });
|
|
162
|
+
keyFailure = result.key ? '' : provisionFailureText(result);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
158
165
|
async function ensureApiKey() {
|
|
159
166
|
if (client.apiKey || provisionAttempted) return;
|
|
160
167
|
provisionAttempted = true;
|
|
161
|
-
const result = await
|
|
168
|
+
const result = await provisionDeviceKey();
|
|
162
169
|
if (result.key) {
|
|
163
170
|
emit(
|
|
164
171
|
render.renderNotice(
|
|
165
172
|
ctx(),
|
|
166
173
|
'info',
|
|
167
|
-
`
|
|
174
|
+
`auto-provisioned a free account` +
|
|
168
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) +
|
|
169
181
|
`. Fund it at ${client.promptUrl('topup', 'device_autoprovision')} or run /byok to use your own key.`
|
|
170
182
|
)
|
|
171
183
|
);
|
|
@@ -543,6 +555,12 @@ function createApp(options = {}) {
|
|
|
543
555
|
return res;
|
|
544
556
|
}
|
|
545
557
|
|
|
558
|
+
/** Explicit `/key register`: unlike the automatic path, this runs again after a failure. */
|
|
559
|
+
async function registerAccount() {
|
|
560
|
+
if (client.apiKey) return { alreadyKeyed: true };
|
|
561
|
+
return provisionDeviceKey();
|
|
562
|
+
}
|
|
563
|
+
|
|
546
564
|
/**
|
|
547
565
|
* The persisting-memory gate — the WRITE half of aegis_memory, and now ON by
|
|
548
566
|
* default for every account (see config.js `memoryPersistState` for the
|
|
@@ -650,7 +668,38 @@ function createApp(options = {}) {
|
|
|
650
668
|
/* no pooled catalog to read — byok rows stand alone */
|
|
651
669
|
}
|
|
652
670
|
}
|
|
653
|
-
|
|
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) || [];
|
|
654
703
|
}
|
|
655
704
|
return await loadModels();
|
|
656
705
|
} catch {
|
|
@@ -668,6 +717,19 @@ function createApp(options = {}) {
|
|
|
668
717
|
return pickerEntries(byokCache.models).map((m) => ({ ...m, cls: 'byok' }));
|
|
669
718
|
}
|
|
670
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
|
+
|
|
671
733
|
/**
|
|
672
734
|
* The class-scoped model list — `state().models`, `/models`, the alt+p chord
|
|
673
735
|
* and the `/class` auto-pick all read it, so it is one list and not four.
|
|
@@ -698,25 +760,63 @@ function createApp(options = {}) {
|
|
|
698
760
|
*
|
|
699
761
|
* @param {Array<object>} [byokOverride] rows already fetched by an async
|
|
700
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.
|
|
701
778
|
*/
|
|
702
|
-
function classScopedModels(byokOverride) {
|
|
703
|
-
|
|
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();
|
|
704
788
|
const byok = Array.isArray(byokOverride)
|
|
705
789
|
? byokOverride.map((m) => ({ ...m, cls: 'byok' }))
|
|
706
790
|
: byokRows();
|
|
707
791
|
return [...pooledRows(), ...byok];
|
|
708
792
|
}
|
|
709
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
|
+
|
|
710
805
|
/**
|
|
711
806
|
* Whether a pinned id can run on `cls`, decided synchronously (switchClass is
|
|
712
|
-
* not async). byok ids are `provider:model`; aegis
|
|
713
|
-
* not — the pooled catalog is validated separately, at launch, by
|
|
714
|
-
* 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.
|
|
715
810
|
*/
|
|
716
811
|
function pinBelongsToClass(cls, id) {
|
|
717
812
|
const s = String(id == null ? '' : id);
|
|
718
813
|
if (cls === 'byok') return s.includes(':');
|
|
719
|
-
//
|
|
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.
|
|
720
820
|
return !s.includes(':');
|
|
721
821
|
}
|
|
722
822
|
|
|
@@ -800,6 +900,25 @@ function createApp(options = {}) {
|
|
|
800
900
|
);
|
|
801
901
|
return pinned;
|
|
802
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
|
+
}
|
|
803
922
|
let models;
|
|
804
923
|
try {
|
|
805
924
|
models = await loadModels();
|
|
@@ -1050,6 +1169,12 @@ function createApp(options = {}) {
|
|
|
1050
1169
|
// `--no-stream` and piped runs get a single body rather than SSE.
|
|
1051
1170
|
stream: commandCtx.stream !== false,
|
|
1052
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,
|
|
1053
1178
|
// Opt-in to the round-horizon dialog (see engine.js requestRoundsAsk)
|
|
1054
1179
|
// only when there is actually a `rounds` prompter to answer it — a
|
|
1055
1180
|
// one-shot `-p` run or any other caller with no presenter keeps the
|
|
@@ -1475,6 +1600,7 @@ function createApp(options = {}) {
|
|
|
1475
1600
|
keyStatus: () => credentials.keyStatus(),
|
|
1476
1601
|
setApiKey: (raw, o) => setApiKey(raw, o),
|
|
1477
1602
|
forgetApiKey: () => forgetApiKey(),
|
|
1603
|
+
registerAccount: () => registerAccount(),
|
|
1478
1604
|
readSecret: (text) => readSecret(text, { stdin: process.stdin, stdout: out }),
|
|
1479
1605
|
cloudsync,
|
|
1480
1606
|
cloudSyncEnabled: () => cloudSyncEnabled(),
|
|
@@ -1487,6 +1613,17 @@ function createApp(options = {}) {
|
|
|
1487
1613
|
get: () => commandCtx.sessionId,
|
|
1488
1614
|
set: (v) => { commandCtx.sessionId = v; },
|
|
1489
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
|
+
};
|
|
1490
1627
|
return c;
|
|
1491
1628
|
}
|
|
1492
1629
|
|
|
@@ -1663,6 +1800,31 @@ function createApp(options = {}) {
|
|
|
1663
1800
|
/** Non-interactive: one prompt, plain output, exit code. */
|
|
1664
1801
|
async function runOnce(prompt, { json = false } = {}) {
|
|
1665
1802
|
adoptLegacyKeyOnce();
|
|
1803
|
+
// Same self-service a fresh `aegiscode -p ...` deserves as a fresh
|
|
1804
|
+
// interactive session (runInteractive) or a fresh `/ask` (runPrompt):
|
|
1805
|
+
// this path used to skip straight to the "no key" refusal below, so
|
|
1806
|
+
// every headless/scripted first run (CI, docker, a README one-liner)
|
|
1807
|
+
// left an installed-but-never-registered machine with no account row
|
|
1808
|
+
// and no welcome trial, instead of the free device key auto-provision
|
|
1809
|
+
// was built to hand it.
|
|
1810
|
+
//
|
|
1811
|
+
// Not the shared `ensureApiKey()` helper: it reports through `emit()`,
|
|
1812
|
+
// which writes to `out` — the same stream `--json` puts its one machine-
|
|
1813
|
+
// readable line on. A notice ahead of that line would break every script
|
|
1814
|
+
// piping `-p ... --json` into a JSON parser, so this path's own notice
|
|
1815
|
+
// always goes to `err` regardless of `json`.
|
|
1816
|
+
if (!client.apiKey && !provisionAttempted) {
|
|
1817
|
+
provisionAttempted = true;
|
|
1818
|
+
const result = await autoProvisionApiKey(client, credentials, { app: 'cli' });
|
|
1819
|
+
if (result.key) {
|
|
1820
|
+
err.write(
|
|
1821
|
+
`aegiscode: auto-provisioned a free account` +
|
|
1822
|
+
(result.ok ? ` (saved to ${credentials.credentialsPath()})` : ' (could not save it — reconfigure with /key)') +
|
|
1823
|
+
trialNote(result) +
|
|
1824
|
+
`. Fund it at ${client.promptUrl('topup', 'device_autoprovision')} or run /byok to use your own key.\n`
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1666
1828
|
if (!client.apiKey) {
|
|
1667
1829
|
err.write(`aegiscode: no AEGIS account key. ${credentials.HOW_TO_SET}, or set $${credentials.KEY_ENV}.\n`);
|
|
1668
1830
|
return 2;
|
|
@@ -1998,6 +2160,7 @@ function createApp(options = {}) {
|
|
|
1998
2160
|
wantExit = true;
|
|
1999
2161
|
},
|
|
2000
2162
|
wantsExit: () => wantExit,
|
|
2163
|
+
keyNotice: () => (client.apiKey ? '' : keyFailure),
|
|
2001
2164
|
isYolo: () => {
|
|
2002
2165
|
// Both halves, in the order the desktop host reads them
|
|
2003
2166
|
// (main.js autoRoundsOn): "this session runs auto mode" AND "the
|