aegiscode 6.8.18 → 6.8.20
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 +4 -2
- package/scripts/check.mjs +50 -0
- package/scripts/predist.mjs +11 -0
- package/src/app.js +23 -0
- package/src/chatflow.js +48 -21
- package/src/commands.js +41 -35
- package/src/devrun.js +80 -6
- package/src/models.js +166 -33
- package/src/panels.js +2 -1
- package/src/summarize.js +3 -1
- package/vendor/client/aegis.js +13 -0
- package/vendor/client/authorship-key.js +45 -4
- package/vendor/client/byok-catalog.js +49 -1
- package/vendor/client/credentials.js +94 -6
- package/vendor/client/env-file.js +161 -5
- package/vendor/client/hooks.js +427 -0
- package/vendor/client/platform.js +410 -0
- package/vendor/desktop/lib/local/engine.js +114 -39
- package/vendor/desktop/lib/local/shell.js +393 -39
- package/vendor/desktop/lib/local/tools.js +156 -13
- package/vendor/desktop/lib/settings.js +36 -1
- package/vendor/desktop/renderer/usage.js +30 -0
- package/vendor/tools/agent-gate.mjs +81 -13
package/src/models.js
CHANGED
|
@@ -11,27 +11,26 @@
|
|
|
11
11
|
* fallback list: an offline client offers nothing rather than a model name that
|
|
12
12
|
* would silently route somewhere else.
|
|
13
13
|
*
|
|
14
|
-
* WHAT IS OFFERED on the AEGIS (pooled) class is
|
|
14
|
+
* WHAT IS OFFERED on the AEGIS (pooled) class is the server's FULL catalog: the
|
|
15
|
+
* brain first, under its one name (Nexus), then every other model the account
|
|
16
|
+
* can pin.
|
|
15
17
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* so `pickerEntries` is back on `filterAegisCatalog`, the shared rule's
|
|
25
|
-
* single-row collapse, for this class.
|
|
18
|
+
* The single-Nexus-row collapse was shipped here and is now reverted, because
|
|
19
|
+
* the report it produced is exactly the defect that shape creates: "there are
|
|
20
|
+
* only 2 models left in models" — one version back the picker listed them all.
|
|
21
|
+
* Removing the choice was never the fix for the two hosts disagreeing about the
|
|
22
|
+
* brain's five spellings; `offerableCatalog` ends that disagreement by folding
|
|
23
|
+
* only the *aliases*, which is what this module now calls. A funded account can
|
|
24
|
+
* pin the deepseek or anthropic model it actually pays for instead of having
|
|
25
|
+
* one chosen for it, while `nexus-brain` still paints as one row and not five.
|
|
26
26
|
*
|
|
27
27
|
* The rule lives in `client/brain-catalog.js`, shared with the desktop through
|
|
28
|
-
* the same `resolveShared` path, so the
|
|
29
|
-
*
|
|
28
|
+
* the same `resolveShared` path, so the two hosts cannot drift — that one-copy
|
|
29
|
+
* guarantee is the part of the earlier change that stays.
|
|
30
30
|
*
|
|
31
31
|
* A payload with no brain tier at all (the BYOK listing, which is per-provider
|
|
32
|
-
* models) never had a brain row to collapse, and stays offered in full: BYOK
|
|
33
|
-
*
|
|
34
|
-
* collapse result there falls through to the full distinct list.
|
|
32
|
+
* models) never had a brain row to collapse, and stays offered in full: BYOK is
|
|
33
|
+
* unaffected by this — see `offerableCatalog`'s own doc for the alias-only case.
|
|
35
34
|
*
|
|
36
35
|
* Offering is still not the same as accepting: `/model deepseek` still
|
|
37
36
|
* validates against the full catalog through `findModel`/`catalogIds`, so a
|
|
@@ -48,7 +47,7 @@ const { resolveShared } = require('./sharedpaths.js');
|
|
|
48
47
|
* precise defect this file was changed to remove. A missing module is a loud
|
|
49
48
|
* error naming the file, which is what `resolveShared` throws.
|
|
50
49
|
*/
|
|
51
|
-
const {
|
|
50
|
+
const { offerableCatalog } = require(resolveShared(path.join('client', 'brain-catalog.js')));
|
|
52
51
|
|
|
53
52
|
/**
|
|
54
53
|
* The shared env-file module, required through the same `resolveShared` path the
|
|
@@ -97,10 +96,18 @@ function normalizeModel(entry) {
|
|
|
97
96
|
id;
|
|
98
97
|
// The picker's right-hand column: what this entry *is*. An alias says so —
|
|
99
98
|
// otherwise a user reads five brain tiers and assumes five different models.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
//
|
|
100
|
+
// A CALLER's own note wins over the derived one, and that precedence is the
|
|
101
|
+
// fix for a real defect: `app.js` builds the BYOK rows with the note the
|
|
102
|
+
// renderers paint ('key on this machine' / 'no key — /byok-key openai') and
|
|
103
|
+
// then passes them through `pickerEntries` → here, which used to re-derive the
|
|
104
|
+
// note from `capabilities` — empty for a byok row — so every row's note became
|
|
105
|
+
// blank and the picker could not say which providers this machine is ready to
|
|
106
|
+
// call. A note someone deliberately set is information; the derived string is
|
|
107
|
+
// a default, and a default must never overwrite it.
|
|
108
|
+
const given = typeof m.note === 'string' && m.note.trim() ? m.note.trim() : '';
|
|
109
|
+
const note = given || (aliasOf ? `alias of ${aliasOf}` : ID_NOTES[id] || capabilities.join(', '));
|
|
110
|
+
const out = {
|
|
104
111
|
id,
|
|
105
112
|
label,
|
|
106
113
|
note,
|
|
@@ -108,6 +115,20 @@ function normalizeModel(entry) {
|
|
|
108
115
|
aliasOf,
|
|
109
116
|
capabilities,
|
|
110
117
|
};
|
|
118
|
+
// Pass-through fields this module does not own but must not eat. They are the
|
|
119
|
+
// byok half of the list's whole content:
|
|
120
|
+
// - `provider` — which provider's key the relay will ask for (`collectKeyFor`
|
|
121
|
+
// read it, and `/byok-key` addresses the row by it);
|
|
122
|
+
// - `configured` — whether that key is on this machine, which is what paints
|
|
123
|
+
// the `[key needed]` flag and what tells a user whether a pick will work;
|
|
124
|
+
// - `cls` — the class the row belongs to, which ENTER switches on.
|
|
125
|
+
// Dropping them (as this did) meant `m.configured` was `undefined` for every
|
|
126
|
+
// row, so the flag fired on rows that were fully configured and the list could
|
|
127
|
+
// not distinguish "ready" from "needs a key".
|
|
128
|
+
if (typeof m.provider === 'string' && m.provider.trim()) out.provider = m.provider.trim();
|
|
129
|
+
if (m.configured === true) out.configured = true;
|
|
130
|
+
if (typeof m.cls === 'string' && m.cls.trim()) out.cls = m.cls.trim();
|
|
131
|
+
return out;
|
|
111
132
|
}
|
|
112
133
|
|
|
113
134
|
/** Normalise a raw `/api/v1/models` payload (`{models: [...]}` or the array). */
|
|
@@ -127,26 +148,27 @@ function normalizeModelCatalog(raw) {
|
|
|
127
148
|
/**
|
|
128
149
|
* The entries the picker and `/models` offer.
|
|
129
150
|
*
|
|
130
|
-
* The selection itself is not decided here — it is `
|
|
151
|
+
* The selection itself is not decided here — it is `offerableCatalog` in
|
|
131
152
|
* `client/brain-catalog.js`, which the desktop requires through the same
|
|
132
153
|
* `resolveShared` path (and its own staged `vendor/` copy). Two hosts, one
|
|
133
154
|
* function: that is the part that must not be re-implemented, and the reason
|
|
134
155
|
* this is a thin call rather than a second copy of the rule.
|
|
135
156
|
*
|
|
136
|
-
*
|
|
137
|
-
* one row
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
157
|
+
* `offerableCatalog` offers every id the payload advertises, with the brain's
|
|
158
|
+
* spellings folded into the one row labelled Nexus and listed first — so a
|
|
159
|
+
* catalog naming a brain tier no longer collapses to that row alone. The
|
|
160
|
+
* fallback below still covers a payload whose entries survive as bare strings
|
|
161
|
+
* or as aliases the shared rule dropped: an empty picker would tell the user
|
|
162
|
+
* there are no models when the server just named them, so a list of aliases is
|
|
163
|
+
* a better answer than nothing.
|
|
141
164
|
*
|
|
142
165
|
* Re-normalised afterwards so renderers keep the `label`/`note`/`id` columns
|
|
143
166
|
* they already expect, and so the brain's cost shape still reaches the picker's
|
|
144
|
-
* right-hand column.
|
|
145
|
-
* bare strings or survive as pure aliases.
|
|
167
|
+
* right-hand column.
|
|
146
168
|
*/
|
|
147
169
|
function pickerEntries(catalog) {
|
|
148
170
|
const all = Array.isArray(catalog) ? catalog.filter(Boolean) : [];
|
|
149
|
-
const offered =
|
|
171
|
+
const offered = offerableCatalog(all).map(normalizeModel).filter(Boolean);
|
|
150
172
|
if (offered.length) return offered;
|
|
151
173
|
const distinct = all.filter((m) => !m.aliasOf);
|
|
152
174
|
return distinct.length ? distinct : all;
|
|
@@ -236,6 +258,100 @@ function modelKeyPlan(entry, o = {}) {
|
|
|
236
258
|
};
|
|
237
259
|
}
|
|
238
260
|
|
|
261
|
+
/**
|
|
262
|
+
* EVERY key a just-picked model needs, in the order to ask for them.
|
|
263
|
+
*
|
|
264
|
+
* `modelKeyPlan` answers with the one credential the ROUTE needs and stops
|
|
265
|
+
* there. That is the wrong answer at the picker, and it is the defect the report
|
|
266
|
+
* "I picked deepseek and it still failed" names: a pooled row named after a
|
|
267
|
+
* vendor is billed to the AEGIS account, so the route's credential is
|
|
268
|
+
* `AEGIS_API_KEY` — but the pool calls `deepseek` with a provider key, and when
|
|
269
|
+
* this machine holds none, the turn fails at the pool with nothing the user can
|
|
270
|
+
* act on. One prompt was not enough, and the missing one was never offered.
|
|
271
|
+
*
|
|
272
|
+
* So the order is fixed and it is the order the two keys are actually needed in:
|
|
273
|
+
*
|
|
274
|
+
* 1. `AEGIS_API_KEY` — the account key. Nothing works without it: it is what
|
|
275
|
+
* authenticates the catalog read that listed the row at all, and it is the
|
|
276
|
+
* pooled route's identity. Asked first, and asked on every class, because
|
|
277
|
+
* a byok listing cannot be read without it either.
|
|
278
|
+
* 2. the VENDOR key for the row (`DEEPSEEK_API_KEY` for `deepseek` or
|
|
279
|
+
* `deepseek:…`) — what actually calls the model. Asked second, and only
|
|
280
|
+
* when the row names a vendor `client/env-file.js` knows a variable for:
|
|
281
|
+
* `nexus-brain` names none, so it produces no second step rather than an
|
|
282
|
+
* invented `NEXUS_API_KEY`.
|
|
283
|
+
*
|
|
284
|
+
* A step is emitted only when its key is genuinely MISSING on this machine —
|
|
285
|
+
* `keyStatus().inFile` for a durable copy, plus the caller's `accountConfigured`
|
|
286
|
+
* / `hasStoredFor` for the two stores that are not the env file
|
|
287
|
+
* (`credentials.json` for the account, `byok:<provider>` rows for a vendor, both
|
|
288
|
+
* written by the other host). An empty array means "nothing to ask for", which
|
|
289
|
+
* is the common case and must stay silent.
|
|
290
|
+
*
|
|
291
|
+
* @param {object} entry a picker row ({id, cls, provider?})
|
|
292
|
+
* @param {object} [o]
|
|
293
|
+
* @param {boolean} [o.accountConfigured] the account key resolves somewhere
|
|
294
|
+
* @param {(vendor:string)=>boolean} [o.hasStoredFor] that vendor's key is in
|
|
295
|
+
* the provider store
|
|
296
|
+
* @returns {Array<{env:string, provider:string, vendor:string, role:string,
|
|
297
|
+
* needed:boolean, status:object|null, why:string}>} in ask order
|
|
298
|
+
*/
|
|
299
|
+
function modelKeyQueue(entry, o = {}) {
|
|
300
|
+
const id = (entry && entry.id) || '';
|
|
301
|
+
// No id at all: there is no row to make callable, so there is nothing to ask
|
|
302
|
+
// for. Checked on the ID and not on `plan.env`, because an empty id still
|
|
303
|
+
// derives a perfectly nameable variable (the account key) — the pooled branch
|
|
304
|
+
// of `keyForModelId` ignores the id — and prompting for the account key off a
|
|
305
|
+
// row that names no model is exactly the unanswerable prompt this refuses.
|
|
306
|
+
if (!String(id).trim()) return [];
|
|
307
|
+
const plan = envFile.keyForModelId(id, entry && entry.cls);
|
|
308
|
+
// A non-empty id that yields no variable cannot be asked about either: an
|
|
309
|
+
// unanswerable prompt is worse than a turn that 400s with the id in it.
|
|
310
|
+
if (!plan.env) return [];
|
|
311
|
+
|
|
312
|
+
const steps = [];
|
|
313
|
+
const account = envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);
|
|
314
|
+
if (!account.present && !o.accountConfigured) {
|
|
315
|
+
steps.push({
|
|
316
|
+
env: envFile.ACCOUNT_ENV_VAR,
|
|
317
|
+
provider: '',
|
|
318
|
+
vendor: '',
|
|
319
|
+
role: 'account',
|
|
320
|
+
needed: true,
|
|
321
|
+
status: account,
|
|
322
|
+
why: `no ${envFile.ACCOUNT_ENV_VAR} is set on this machine`,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// The vendor the row names. For byok that is the id's own `<provider>` half;
|
|
327
|
+
// for a pooled id it is the vendor spelled into the id (`deepseek`), and it is
|
|
328
|
+
// the same variable either way — one key, one file, whichever class reads it.
|
|
329
|
+
const vendor = plan.vendor || '';
|
|
330
|
+
const vendorEnv = vendor ? envFile.envVarFor(vendor) : '';
|
|
331
|
+
const stored = vendor && typeof o.hasStoredFor === 'function' ? !!o.hasStoredFor(vendor) : false;
|
|
332
|
+
if (vendorEnv) {
|
|
333
|
+
const status = envFile.keyStatus(vendorEnv);
|
|
334
|
+
// `inFile` rather than `present` for the same reason as modelKeyPlan: a
|
|
335
|
+
// shell export belongs to this process, and the desktop — the other host
|
|
336
|
+
// that has to make this call — cannot see it. The provider store counts as
|
|
337
|
+
// stored (`hasStoredFor`), because that is the row the desktop writes.
|
|
338
|
+
if (!status.inFile && !stored) {
|
|
339
|
+
steps.push({
|
|
340
|
+
env: vendorEnv,
|
|
341
|
+
provider: vendor,
|
|
342
|
+
vendor,
|
|
343
|
+
role: 'provider',
|
|
344
|
+
needed: true,
|
|
345
|
+
status,
|
|
346
|
+
why: status.present
|
|
347
|
+
? `${vendorEnv} is exported in this shell only — the desktop cannot see it`
|
|
348
|
+
: `no ${vendorEnv} is stored for provider "${vendor}"`,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return steps;
|
|
353
|
+
}
|
|
354
|
+
|
|
239
355
|
/**
|
|
240
356
|
* Store a key collected at the picker, in the one file every host reads.
|
|
241
357
|
*
|
|
@@ -243,18 +359,34 @@ function modelKeyPlan(entry, o = {}) {
|
|
|
243
359
|
* can report WHERE the key went without re-deriving it (and re-deriving it is
|
|
244
360
|
* how the two hosts would end up disagreeing about the name).
|
|
245
361
|
*
|
|
362
|
+
* `o.env` overrides the derived variable, and it is how a QUEUE step is stored:
|
|
363
|
+
* a pooled row has two keys (the account's and the vendor's), so the row alone
|
|
364
|
+
* cannot say which one this value is for — the step can. Without it the
|
|
365
|
+
* derivation is `keyForModelId`, which is the right answer for a single-key
|
|
366
|
+
* caller and unchanged.
|
|
367
|
+
*
|
|
246
368
|
* @param {object} entry the row the key was collected for
|
|
247
369
|
* @param {string} key the secret
|
|
370
|
+
* @param {object} [o] `setEnvValue` options; `env` names the variable to write
|
|
248
371
|
* @returns {{ok:boolean, file:string, changed:boolean, error:string,
|
|
249
372
|
* env:string, provider:string, pooled:boolean}}
|
|
250
373
|
*/
|
|
251
374
|
function storeModelKey(entry, key, o = {}) {
|
|
252
375
|
const plan = envFile.keyForModelId(entry && entry.id, entry && entry.cls);
|
|
253
|
-
|
|
376
|
+
const env = String(o.env || '').trim() || plan.env;
|
|
377
|
+
if (!env) {
|
|
254
378
|
return { ok: false, file: '', changed: false, error: `cannot name a key variable for "${(entry && entry.id) || ''}"`, env: '', provider: '', pooled: plan.pooled };
|
|
255
379
|
}
|
|
256
|
-
const
|
|
257
|
-
|
|
380
|
+
const opts = { ...o };
|
|
381
|
+
delete opts.env;
|
|
382
|
+
const res = envFile.setEnvValue(env, key, opts);
|
|
383
|
+
// `pooled` describes the VARIABLE that was written, not the class of the row:
|
|
384
|
+
// the account key is the pooled route's credential wherever it is stored,
|
|
385
|
+
// while a vendor key written for a pooled row is still the user's own vendor
|
|
386
|
+
// key. Reading it off the row (as this once did) reported DEEPSEEK_API_KEY as
|
|
387
|
+
// pooled, which told the caller the pool held a key the user had just supplied.
|
|
388
|
+
const pooled = env === envFile.ACCOUNT_ENV_VAR;
|
|
389
|
+
return { ...res, env, provider: env === plan.env ? plan.provider : '', pooled };
|
|
258
390
|
}
|
|
259
391
|
|
|
260
392
|
/** The env var name a key for `entry` belongs in ('' when there is none). */
|
|
@@ -271,6 +403,7 @@ module.exports = {
|
|
|
271
403
|
findModel,
|
|
272
404
|
catalogIds,
|
|
273
405
|
modelKeyPlan,
|
|
406
|
+
modelKeyQueue,
|
|
274
407
|
storeModelKey,
|
|
275
408
|
keyVarForModel,
|
|
276
409
|
};
|
package/src/panels.js
CHANGED
|
@@ -586,7 +586,8 @@ function buildHooksStatus(stats, ctx = {}) {
|
|
|
586
586
|
lines.push([span(t.dim, fromPaths.length
|
|
587
587
|
? `Settings: ${fromPaths.join(', ')}`
|
|
588
588
|
: 'Settings: no settings.json with hooks found (checked ~/.aegis, .aegis, ~/.aegiscode, .aegiscode, ~/.claude)')]);
|
|
589
|
-
lines.push([span(t.gray, '
|
|
589
|
+
lines.push([span(t.gray, 'Config hooks are read, not managed — edit the files above.')]);
|
|
590
|
+
lines.push([span(t.gray, 'The repo guard hooks (.githooks/) are installed by /hooks install.')]);
|
|
590
591
|
return lines;
|
|
591
592
|
}
|
|
592
593
|
|
package/src/summarize.js
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* Transcript summarization for /compact and /recap.
|
|
5
5
|
*
|
|
6
6
|
* Dependency-free port of the upstream engine reference. The reference
|
|
7
|
-
* spawns `claude -p "Summarize…"` (via
|
|
7
|
+
* spawns `claude -p "Summarize…"` (via `resolveExecutable()` in
|
|
8
|
+
* client/platform.js — the shared module this repo actually ships, staged into
|
|
9
|
+
* cli/vendor/client/platform.js); here the
|
|
8
10
|
* backend is *injected* instead, so this module pulls in nothing but tokens.js:
|
|
9
11
|
*
|
|
10
12
|
* async summarizeTranscript(transcript, { callModel, model, signal } = {})
|
package/vendor/client/aegis.js
CHANGED
|
@@ -737,6 +737,8 @@ function createClient(opts = {}) {
|
|
|
737
737
|
prompt,
|
|
738
738
|
system,
|
|
739
739
|
maxTokens,
|
|
740
|
+
effort,
|
|
741
|
+
reasoningEffort,
|
|
740
742
|
stream = false,
|
|
741
743
|
onStream,
|
|
742
744
|
signal,
|
|
@@ -759,6 +761,17 @@ function createClient(opts = {}) {
|
|
|
759
761
|
provider,
|
|
760
762
|
messages: buildMessages(messages, system, prompt),
|
|
761
763
|
...(maxTokens ? { max_tokens: maxTokens } : {}),
|
|
764
|
+
// Native effort knobs, forwarded verbatim and ONLY when a caller states
|
|
765
|
+
// one — never invented here, because a made-up level overrides the
|
|
766
|
+
// vendor's own default. The field name is not portable: DeepSeek's
|
|
767
|
+
// Anthropic-compatible surface takes `effort` (low|high|max), while the
|
|
768
|
+
// OpenAI-shaped vendors take `reasoning_effort` (low|medium|high). The
|
|
769
|
+
// caller translates the rung per dialect and names the field, so neither
|
|
770
|
+
// field is ever sent blind to a strict validator — Groq answers 400 for
|
|
771
|
+
// any level outside a model's supported set, so a misfiled knob is a
|
|
772
|
+
// failed turn, not a harmless extra key.
|
|
773
|
+
...(effort ? { effort } : {}),
|
|
774
|
+
...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
|
|
762
775
|
};
|
|
763
776
|
if (model) body.model = model;
|
|
764
777
|
const headers = {
|
|
@@ -227,6 +227,48 @@ function resolveKey(o = {}) {
|
|
|
227
227
|
* @returns {{out: string, created: boolean, replaced: boolean,
|
|
228
228
|
* keyFingerprint: string, bytes: number, secretPrinted: false, mode: string}}
|
|
229
229
|
*/
|
|
230
|
+
/**
|
|
231
|
+
* Write a secret to `file`, creating its parent directory, and translate the
|
|
232
|
+
* filesystem errnos a user actually hits into a sentence that names the fix.
|
|
233
|
+
*
|
|
234
|
+
* `keygen` is the first command a new install runs, and its failure mode on a
|
|
235
|
+
* locked-down or full disk used to be the bare kernel message — `EACCES:
|
|
236
|
+
* permission denied, open '/home/u/.aegiscode/keys/authorship.key'`. That says
|
|
237
|
+
* what broke and not what to do, and the remedy is not guessable from it: the
|
|
238
|
+
* unwritable thing is the *directory*, which the path in the message never
|
|
239
|
+
* names. Found by the `unwritable-home` usertest profile, which reported it
|
|
240
|
+
* three times across as many commits before it was treated as a defect.
|
|
241
|
+
*
|
|
242
|
+
* Only the three errnos with an unambiguous remedy are rewritten. Everything
|
|
243
|
+
* else propagates untouched — inventing advice for an errno we do not recognise
|
|
244
|
+
* would be worse than the errno.
|
|
245
|
+
*/
|
|
246
|
+
function writeSecret(file, secret) {
|
|
247
|
+
try {
|
|
248
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: DIR_MODE });
|
|
249
|
+
fs.writeFileSync(file, secret + '\n', { mode: KEY_FILE_MODE });
|
|
250
|
+
} catch (e) {
|
|
251
|
+
const errno = e && e.code;
|
|
252
|
+
const dir = path.dirname(file);
|
|
253
|
+
if (errno === 'EACCES' || errno === 'EPERM') {
|
|
254
|
+
throw new Error(
|
|
255
|
+
`authorship-key: cannot write ${file} — ${dir} is not writable by this user (${errno}). ` +
|
|
256
|
+
`Fix it with: chmod u+rwx ${dir}`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (errno === 'EROFS') {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`authorship-key: cannot write ${file} — ${dir} is on a read-only filesystem (EROFS). ` +
|
|
262
|
+
'Point --out (or $AEGIS_HOME) at a writable location.',
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (errno === 'ENOSPC') {
|
|
266
|
+
throw new Error(`authorship-key: cannot write ${file} — the disk is full (ENOSPC).`);
|
|
267
|
+
}
|
|
268
|
+
throw e;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
230
272
|
function keygen(o = {}) {
|
|
231
273
|
const argv = o.argv || [];
|
|
232
274
|
const env = o.env || process.env;
|
|
@@ -244,8 +286,7 @@ function keygen(o = {}) {
|
|
|
244
286
|
}
|
|
245
287
|
|
|
246
288
|
const secret = crypto.randomBytes(KEY_BYTES).toString('base64url');
|
|
247
|
-
|
|
248
|
-
fs.writeFileSync(out, secret + '\n', { mode: KEY_FILE_MODE });
|
|
289
|
+
writeSecret(out, secret);
|
|
249
290
|
// writeFileSync's mode is ANDed with the complement of the umask, so a 0022
|
|
250
291
|
// umask turns 0600 into 0644 and the call still "succeeds". Set it outright.
|
|
251
292
|
fs.chmodSync(out, KEY_FILE_MODE);
|
|
@@ -311,7 +352,7 @@ function backup(o = {}) {
|
|
|
311
352
|
assertPrivate(from);
|
|
312
353
|
|
|
313
354
|
const destDir = path.resolve(to);
|
|
314
|
-
|
|
355
|
+
|
|
315
356
|
const name = flag(argv, '--name') || path.basename(from);
|
|
316
357
|
const dest = path.join(destDir, name);
|
|
317
358
|
|
|
@@ -327,7 +368,7 @@ function backup(o = {}) {
|
|
|
327
368
|
}
|
|
328
369
|
|
|
329
370
|
const secret = readSecretFile(from);
|
|
330
|
-
|
|
371
|
+
writeSecret(dest, secret);
|
|
331
372
|
fs.chmodSync(dest, KEY_FILE_MODE);
|
|
332
373
|
if (!isWin && modeOf(dest) !== KEY_FILE_MODE) {
|
|
333
374
|
throw new Error(`authorship-key: ${dest} landed mode ${modeString(modeOf(dest))}, expected 600`);
|
|
@@ -79,7 +79,55 @@ const BYOK_MODEL_ADDITIONS = Object.freeze({
|
|
|
79
79
|
// current API uses and the one this repo's rate table, token-budget and
|
|
80
80
|
// reasoning-model regexes all already key off; `deepseek-v4.1-flash` is the
|
|
81
81
|
// retired alias for the same route and is NOT listed separately.
|
|
82
|
-
deepseek: Object.freeze([
|
|
82
|
+
deepseek: Object.freeze([
|
|
83
|
+
'deepseek-flash',
|
|
84
|
+
// DeepSeek-V4-Pro — a DISTINCT, pricier Pro route (not an alias of Flash),
|
|
85
|
+
// which DeepSeek's current API serves as `deepseek-v4-pro` alongside
|
|
86
|
+
// `deepseek-flash`. The server's BYOK catalog still advertises only the
|
|
87
|
+
// legacy `deepseek-v4-flash` alias, so without this row a DeepSeek key can
|
|
88
|
+
// never pin the Pro model from the picker even though the rate table
|
|
89
|
+
// (desktop/renderer/usage.js `deepseek-v4-pro`) and the reasoning regex
|
|
90
|
+
// already know it. Added here rather than behind the server because the
|
|
91
|
+
// relay forwards whatever model the caller names.
|
|
92
|
+
'deepseek-v4-pro',
|
|
93
|
+
]),
|
|
94
|
+
// Anthropic's `anthropic` descriptor (aegis1 services/nexus_provider/
|
|
95
|
+
// catalog.py) pins exactly one default_model, `claude-sonnet-5`, and
|
|
96
|
+
// `anthropic-haiku` pins `claude-haiku-4-5` as its own provider row — so
|
|
97
|
+
// between them an Anthropic BYOK key could pin Sonnet or Haiku but never
|
|
98
|
+
// Opus or Fable, the other two members of the current Claude 5 lineup the
|
|
99
|
+
// vendor already serves. Both ids already have a priced rate row
|
|
100
|
+
// (desktop/renderer/usage.js `opus`/`fable`, matched by family substring),
|
|
101
|
+
// so the picker just had no way to offer them, not an unpriced gap. Listed
|
|
102
|
+
// under the `anthropic` provider id because that is the row the server
|
|
103
|
+
// advertises a configured Anthropic key against — the relay forwards
|
|
104
|
+
// whichever of the two names the caller actually pins.
|
|
105
|
+
anthropic: Object.freeze(['claude-opus-5', 'claude-fable-5']),
|
|
106
|
+
// xAI's `grok` descriptor still pins `grok-4.5` as default_model — current
|
|
107
|
+
// when that descriptor was written, but xAI has since shipped grok-4.6 and
|
|
108
|
+
// grok-4.7 (flagship, Sept 2026) on the same `grok-4.5`-shaped id
|
|
109
|
+
// (api.x.ai/v1, model=`grok-4.7`). A Grok BYOK key could not reach either
|
|
110
|
+
// newer model from the picker even though the relay forwards whatever name
|
|
111
|
+
// it is given. Only the current flagship is listed — 4.6 sits strictly
|
|
112
|
+
// between the already-offered 4.5 and 4.7 at the same per-token rate as 4.7,
|
|
113
|
+
// so a second row would not unlock any capability or price point 4.7 doesn't.
|
|
114
|
+
grok: Object.freeze(['grok-4.7']),
|
|
115
|
+
// Google's `gemini` descriptor pins `gemini-3.5-flash`. Google has since
|
|
116
|
+
// shipped gemini-3.6-flash, gemini-3.7-flash and gemini-3.8-flash (GA,
|
|
117
|
+
// 2026-09-02) on the same family; no Gemini 3.x Pro tier has shipped (the
|
|
118
|
+
// announced 3.5 Pro was delayed indefinitely), so Flash is the whole
|
|
119
|
+
// lineup. Only the current GA flagship is listed, for the same "one
|
|
120
|
+
// spelling per route" reason as the others above.
|
|
121
|
+
gemini: Object.freeze(['gemini-3.8-flash']),
|
|
122
|
+
// OpenAI's `openai` and `openai-gpt4o-mini` descriptors both pin
|
|
123
|
+
// `gpt-5-mini` — a cheap/fast tier, not the general-purpose flagship. An
|
|
124
|
+
// OpenAI BYOK key could pin the mini tier but never the current flagship
|
|
125
|
+
// chat model, `gpt-5.5` (api.openai.com/v1, released 2026-04-23). The two
|
|
126
|
+
// provider ids share one credential and one model, so the server's BYOK
|
|
127
|
+
// catalog already lists `gpt-5-mini` twice for one OpenAI key; listed under
|
|
128
|
+
// `openai` only, not also under `openai-gpt4o-mini`, so this addition does
|
|
129
|
+
// not compound that into two flagship rows for the same key.
|
|
130
|
+
openai: Object.freeze(['gpt-5.5']),
|
|
83
131
|
});
|
|
84
132
|
|
|
85
133
|
/** The extras to offer for one provider id (an empty array when there are none). */
|
|
@@ -18,10 +18,18 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Resolution order, first hit wins:
|
|
20
20
|
*
|
|
21
|
-
* 1. `AEGIS_API_KEY`
|
|
22
|
-
*
|
|
23
|
-
* 2. `credentials.json` in the data dir, mode 0600. The writable store
|
|
24
|
-
*
|
|
21
|
+
* 1. `AEGIS_API_KEY` **exported by the launching shell** — so CI and an
|
|
22
|
+
* explicit export keep working.
|
|
23
|
+
* 2. `credentials.json` in the data dir, mode 0600. The writable store, and
|
|
24
|
+
* the record of a key the user deliberately saved (`aegiscode login`, the
|
|
25
|
+
* CLI's `/key`, the desktop's Settings pane).
|
|
26
|
+
* 3. `AEGIS_API_KEY` from `~/.aegiscode/.env` — the documented place to put a
|
|
27
|
+
* key, but a FALLBACK rather than a decision: no save stamp, shared by
|
|
28
|
+
* every host, hand-edited. Both rungs read the same variable, which is why
|
|
29
|
+
* `isFromEnvFile()` exists — without it a leftover line in that file
|
|
30
|
+
* outranked rung 2 forever and a freshly saved key was silently ignored
|
|
31
|
+
* while every host reported it as saved. See `resolveApiKey`.
|
|
32
|
+
* 4. `config.json`'s `aegiscloud.api_key` / `memory.token` — the shape an
|
|
25
33
|
* earlier AEGIS CLI left in the same data dir. Read, never written, and
|
|
26
34
|
* never deleted: it is another product's file and the user's key is in
|
|
27
35
|
* it. When one is found it is *also* copied into credentials.json so the
|
|
@@ -189,21 +197,79 @@ function adoptLegacy(dir) {
|
|
|
189
197
|
return { adopted: Object.keys(patch) };
|
|
190
198
|
}
|
|
191
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Was this environment value put there by `~/.aegiscode/.env`, rather than
|
|
202
|
+
* exported by the launching shell?
|
|
203
|
+
*
|
|
204
|
+
* The env object is passed through: provenance is a property of the object the
|
|
205
|
+
* value was loaded INTO, so a caller resolving from an injected `{ env }` (every
|
|
206
|
+
* test, and any host that scopes its environment) must be answered about that
|
|
207
|
+
* object rather than about `process.env`.
|
|
208
|
+
*
|
|
209
|
+
* Loaded lazily and defensively: this module is deliberately dependency-free
|
|
210
|
+
* (it is copied into hosts that bundle no other file), so an absent env-file
|
|
211
|
+
* module simply means "nothing is file-sourced" — which is the pre-existing
|
|
212
|
+
* behaviour, not a failure.
|
|
213
|
+
*/
|
|
214
|
+
function fromEnvFile(name, value, env) {
|
|
215
|
+
try {
|
|
216
|
+
const envFile = require('./env-file.js');
|
|
217
|
+
return (
|
|
218
|
+
typeof envFile.isFromEnvFile === 'function' &&
|
|
219
|
+
envFile.isFromEnvFile(name, value, env ? { env } : undefined)
|
|
220
|
+
);
|
|
221
|
+
} catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
192
226
|
/**
|
|
193
227
|
* The key to use, and where it came from.
|
|
194
228
|
*
|
|
195
|
-
*
|
|
229
|
+
* Order, and the one asymmetry that matters:
|
|
230
|
+
*
|
|
231
|
+
* 1. `AEGIS_API_KEY` **exported by the launching shell** — unchanged, and
|
|
232
|
+
* still first, so CI and an explicit `AEGIS_API_KEY=… aegiscode` keep
|
|
233
|
+
* working.
|
|
234
|
+
* 2. `credentials.json` — a key the user explicitly saved with
|
|
235
|
+
* `aegiscode login`, the CLI's `/key`, or the desktop's Settings pane.
|
|
236
|
+
* 3. `AEGIS_API_KEY` **from `~/.aegiscode/.env`** — the documented place to
|
|
237
|
+
* put a key, but a fallback rather than a decision: it carries no save
|
|
238
|
+
* stamp and the file is shared by every host and hand-edited by users.
|
|
239
|
+
* 4. `config.json`'s legacy `aegiscloud.api_key`.
|
|
240
|
+
*
|
|
241
|
+
* Rungs 1 and 3 are the same variable, which is exactly the bug this ordering
|
|
242
|
+
* fixes. `env-file.js` copies the file into `process.env` at host start-up, so a
|
|
243
|
+
* leftover line — a rotated key that was never cleaned up, a value from an
|
|
244
|
+
* older install, a provider row mirrored into the wrong name — became
|
|
245
|
+
* indistinguishable from a deliberate export and permanently outranked the file
|
|
246
|
+
* the user had just written. The symptom is the one that gets reported as
|
|
247
|
+
* "it says the key is saved but it is not using it": `aegiscode login` prints
|
|
248
|
+
* `key saved`, the desktop prints `saved (aegis_••••1234)`, `key status` reads
|
|
249
|
+
* back the new key — and every request authenticates with the stale one, so the
|
|
250
|
+
* account check 401s and nothing names the cause. `env-file.js`'s own contract
|
|
251
|
+
* is that the file is "a convenience for the common case, not a way for a stale
|
|
252
|
+
* file to shadow an explicit" setting; `isFromEnvFile()` is what makes that
|
|
253
|
+
* true for a save as well as for an export.
|
|
254
|
+
*
|
|
255
|
+
* @returns {{key:string, source:'env'|'credentials'|'envfile'|'config'|'none', from:string}}
|
|
196
256
|
*/
|
|
197
257
|
function resolveApiKey(o = {}) {
|
|
198
258
|
const env = o.env || process.env;
|
|
199
259
|
const dir = o.dir;
|
|
200
260
|
const fromEnv = normalizeApiKey(env && env[KEY_ENV]);
|
|
201
|
-
|
|
261
|
+
// An explicit export wins outright. A value the env FILE supplied does not:
|
|
262
|
+
// it is held back to rung 3 so an explicit save outranks it.
|
|
263
|
+
if (fromEnv && !fromEnvFile(KEY_ENV, env && env[KEY_ENV], env)) {
|
|
264
|
+
return { key: fromEnv, source: 'env', from: KEY_ENV };
|
|
265
|
+
}
|
|
202
266
|
|
|
203
267
|
const creds = readCredentials(dir);
|
|
204
268
|
const stored = normalizeApiKey(creds.aegisApiKey);
|
|
205
269
|
if (stored) return { key: stored, source: 'credentials', from: credentialsPath(dir) };
|
|
206
270
|
|
|
271
|
+
if (fromEnv) return { key: fromEnv, source: 'envfile', from: envFileLabel(env, dir) };
|
|
272
|
+
|
|
207
273
|
const legacy = readLegacyConfig(dir).apiKey;
|
|
208
274
|
if (legacy) return { key: legacy, source: 'config', from: configPath(dir) };
|
|
209
275
|
|
|
@@ -318,10 +384,30 @@ function clientOptions(o = {}) {
|
|
|
318
384
|
const SOURCE_LABEL = {
|
|
319
385
|
env: `${KEY_ENV}`,
|
|
320
386
|
credentials: 'saved key file',
|
|
387
|
+
envfile: `~/.aegiscode/.env (${KEY_ENV})`,
|
|
321
388
|
config: 'config.json (aegis CLI)',
|
|
322
389
|
none: 'not set',
|
|
323
390
|
};
|
|
324
391
|
|
|
392
|
+
/**
|
|
393
|
+
* The env file a value came from, for the `envfile` status line. Resolved
|
|
394
|
+
* through env-file.js when it is present so the answer is the real path
|
|
395
|
+
* (`$AEGISCODE_HOME/.env` included) rather than a guess.
|
|
396
|
+
*/
|
|
397
|
+
function envFileLabel(env, dir) {
|
|
398
|
+
try {
|
|
399
|
+
const envFile = require('./env-file.js');
|
|
400
|
+
if (typeof envFile.envFileFor === 'function') return envFile.envFileFor(dir);
|
|
401
|
+
} catch {}
|
|
402
|
+
return envFileForFallback(dir);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** `~/.aegiscode/.env`, built here so the label survives a host that ships no
|
|
406
|
+
* env-file module (same rule aegisHome() exists for). */
|
|
407
|
+
function envFileForFallback(dir) {
|
|
408
|
+
return path.join(dir || aegisHome(), '.env');
|
|
409
|
+
}
|
|
410
|
+
|
|
325
411
|
function sourceLabel(source) {
|
|
326
412
|
return SOURCE_LABEL[source] || SOURCE_LABEL.none;
|
|
327
413
|
}
|
|
@@ -377,6 +463,8 @@ module.exports = {
|
|
|
377
463
|
adoptLegacy,
|
|
378
464
|
resolveApiKey,
|
|
379
465
|
hasApiKey,
|
|
466
|
+
fromEnvFile,
|
|
467
|
+
envFileForFallback,
|
|
380
468
|
saveApiKey,
|
|
381
469
|
clearApiKey,
|
|
382
470
|
resolveMemoryToken,
|