aegiscode 6.7.7 → 6.8.0
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 +35 -51
- package/bin/aegiscode.js +24 -0
- package/package.json +1 -1
- package/scripts/predist.mjs +11 -7
- package/src/app.js +7 -46
- package/src/commands.js +40 -159
- package/src/config.js +0 -10
- package/src/deps.js +5 -30
- package/src/engine.js +18 -83
- package/src/sharedpaths.js +50 -0
- package/vendor/client/env-file.js +182 -0
- package/vendor/desktop/lib/local/engine.js +225 -128
- package/vendor/desktop/lib/local/local.js +433 -0
- package/vendor/desktop/lib/local/tools.js +7 -56
- package/vendor/desktop/lib/settings.js +33 -0
- package/vendor/desktop/renderer/usage.js +4 -4
- package/src/custommodels.js +0 -198
- package/vendor/desktop/lib/local/providers.js +0 -679
package/README.md
CHANGED
|
@@ -90,9 +90,36 @@ older AEGIS CLI left in `~/.aegiscode/config.json` is picked up and copied into
|
|
|
90
90
|
the 0600 store automatically — `/cloud status` says so if the plaintext copy is
|
|
91
91
|
still there.
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
## One file for every key
|
|
94
|
+
|
|
95
|
+
`~/.aegiscode/.env` is read into the environment once at startup by the CLI, the
|
|
96
|
+
desktop app and the MCP server. It is the shortest way to configure the account
|
|
97
|
+
key *and* every BYOK provider at the same time:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# ~/.aegiscode/.env
|
|
101
|
+
AEGIS_API_KEY=aegis_...
|
|
102
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
103
|
+
OPENAI_API_KEY=sk-...
|
|
104
|
+
DEEPSEEK_API_KEY=sk-...
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
That file alone is enough — no `login`, no `/byok-key <provider>` prompt per
|
|
108
|
+
provider. Both resolution paths already read these names out of the environment;
|
|
109
|
+
the file is just what fills it. `AEGIS_API_KEY` is entry one in the credential
|
|
110
|
+
order below, and a BYOK provider resolves `<PROVIDER>_API_KEY` (upper snake case,
|
|
111
|
+
with a short alias table for the ids that would spell it differently — `google`
|
|
112
|
+
and `gemini` → `GEMINI_API_KEY`, `xai` → `XAI_API_KEY`, `huggingface` →
|
|
113
|
+
`HF_TOKEN`).
|
|
114
|
+
|
|
115
|
+
Two rules it obeys: a variable **already exported in the launching shell always
|
|
116
|
+
wins**, so a stale file can never shadow `AEGIS_API_KEY=… aegiscode` in CI; and
|
|
117
|
+
the loader only ever reads. If the file is group- or world-readable you are told,
|
|
118
|
+
not silently fixed — the 0600 store stays the only secret this repo writes.
|
|
119
|
+
|
|
120
|
+
That one file is shared: the MCP plugin and AEGIS Desktop read the same store and
|
|
121
|
+
the same `.env`, so signing in here signs you in everywhere (see [One memory,
|
|
122
|
+
shared with AEGIS Desktop](#one-memory-shared-with-aegis-desktop)).
|
|
96
123
|
|
|
97
124
|
## Launch options
|
|
98
125
|
|
|
@@ -224,7 +251,6 @@ Three layers, from broadest to narrowest. You only need the first one.
|
|
|
224
251
|
/class # show the picker
|
|
225
252
|
/class aegis # pooled AEGIS Cloud (the default)
|
|
226
253
|
/class byok # your own provider key, relayed by AEGIS
|
|
227
|
-
/class custom # your own endpoint, called by aegiscode directly
|
|
228
254
|
```
|
|
229
255
|
|
|
230
256
|
A class is *whose credential pays and who talks to the vendor*, not a model.
|
|
@@ -236,7 +262,6 @@ restart.
|
|
|
236
262
|
|---|---|---|
|
|
237
263
|
| `aegis` *(default)* | the AEGIS pool — one id, `nexus-brain` (alias `aegis-brain`), auto-routed server-side across whichever providers are live | your AEGIS account balance |
|
|
238
264
|
| `byok` | your provider key, relayed via `POST /api/v1/byok/chat/completions` | your provider direct, **plus** a small AEGIS handling fee on your account |
|
|
239
|
-
| `custom` | your own base URL, called **directly** by aegiscode — nothing is relayed | your provider direct. No AEGIS fee, no margin, no account balance |
|
|
240
265
|
|
|
241
266
|
**2. The model id — what to pin.**
|
|
242
267
|
|
|
@@ -247,10 +272,10 @@ restart.
|
|
|
247
272
|
/model - # clear the pin, back to the class default
|
|
248
273
|
```
|
|
249
274
|
|
|
250
|
-
`/models` is class-aware: it answers from the pool catalogue under `aegis`,
|
|
251
|
-
the models your saved keys actually unlock under `byok
|
|
252
|
-
|
|
253
|
-
|
|
275
|
+
`/models` is class-aware: it answers from the pool catalogue under `aegis`, and
|
|
276
|
+
from the models your saved keys actually unlock under `byok`. A pin is
|
|
277
|
+
**cleared with a reason** if you switch to a class it does not belong to,
|
|
278
|
+
instead of failing later at the route.
|
|
254
279
|
|
|
255
280
|
Under `byok` every id is compound — `provider:model`:
|
|
256
281
|
|
|
@@ -259,17 +284,9 @@ Under `byok` every id is compound — `provider:model`:
|
|
|
259
284
|
/model anthropic:claude-sonnet-4-5
|
|
260
285
|
```
|
|
261
286
|
|
|
262
|
-
Under `custom` the id is whatever you named the entry:
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
/models # e.g. local-llama, work-gateway
|
|
266
|
-
/model local-llama
|
|
267
|
-
```
|
|
268
|
-
|
|
269
287
|
```bash
|
|
270
288
|
aegiscode -m nexus-brain -p "…" # pin at launch
|
|
271
289
|
aegiscode -m anthropic:claude-sonnet-4-5 -p "…" # a BYOK id at launch
|
|
272
|
-
aegiscode -m local-llama -p "…" # a custom id at launch
|
|
273
290
|
```
|
|
274
291
|
|
|
275
292
|
**3. Effort — how hard it reasons.**
|
|
@@ -286,37 +303,7 @@ the per-provider mechanics).
|
|
|
286
303
|
> **A `byok` turn is single-shot.** The relay takes no `tools` parameter, so the
|
|
287
304
|
> agentic tool loop is off by construction — no file edits, no shell, no
|
|
288
305
|
> subagents, no approval cards. `/class` says so rather than letting you discover
|
|
289
|
-
> it mid-task.
|
|
290
|
-
> endpoint itself, so the full tool loop works normally.
|
|
291
|
-
|
|
292
|
-
## Custom models — your endpoint, called directly
|
|
293
|
-
|
|
294
|
-
`/model add` teaches aegiscode about an endpoint AEGIS never sees. There is no
|
|
295
|
-
relay, no handling fee and no margin: the request goes straight from your machine
|
|
296
|
-
to the base URL you gave, with the key you gave.
|
|
297
|
-
|
|
298
|
-
```bash
|
|
299
|
-
/model add local-llama "Local Llama" llama-3.3-70b http://localhost:11434/v1
|
|
300
|
-
/model add work-gw "Work gateway" gpt-4o https://gw.corp/v1 openai
|
|
301
|
-
/model key local-llama # set or replace the key later (prompted, masked)
|
|
302
|
-
/class custom # route turns through these
|
|
303
|
-
/model local-llama # pin one
|
|
304
|
-
/model remove local-llama # drop the entry and its key
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
The wire protocol is detected from the base URL — `anthropic.com` gets the
|
|
308
|
-
Messages API, everything else the OpenAI-compatible one — or you can pass
|
|
309
|
-
`openai` / `anthropic` explicitly to override it.
|
|
310
|
-
|
|
311
|
-
Where things are stored, and why it is split:
|
|
312
|
-
|
|
313
|
-
| What | Where | Why |
|
|
314
|
-
|---|---|---|
|
|
315
|
-
| name, model, base URL, wire | `~/.aegiscode/config.json` | it is configuration, and it is not secret |
|
|
316
|
-
| the API key | `~/.aegiscode/settings.json` (mode `0600`) | secrets belong in the file we chmod, keyed `custom:<id>` |
|
|
317
|
-
|
|
318
|
-
The key is never written into `config.json`. A local endpoint that needs no key
|
|
319
|
-
is fine — omit it and no `Authorization` header is sent.
|
|
306
|
+
> it mid-task.
|
|
320
307
|
|
|
321
308
|
## Bring your own key
|
|
322
309
|
|
|
@@ -423,9 +410,6 @@ echo "why is the sky blue" | aegiscode -p -
|
|
|
423
410
|
/models # what that key unlocks
|
|
424
411
|
/model openai:gpt-4o # pin one
|
|
425
412
|
/class aegis # back to the pool
|
|
426
|
-
|
|
427
|
-
/model add local-llama "Local Llama" llama-3.3-70b http://localhost:11434/v1
|
|
428
|
-
/class custom # or call your own endpoint directly
|
|
429
413
|
```
|
|
430
414
|
|
|
431
415
|
### Control the budget
|
package/bin/aegiscode.js
CHANGED
|
@@ -376,6 +376,30 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
376
376
|
return 0;
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
+
// ── the shared env file, before any credential is resolved ───────────────
|
|
380
|
+
//
|
|
381
|
+
// `~/.aegiscode/.env` read into process.env once. This is what makes key
|
|
382
|
+
// setup ONE instruction in every host — "put it in ~/.aegiscode/.env" —
|
|
383
|
+
// instead of a `login` plus a `/byok-key <provider>` prompt per provider:
|
|
384
|
+
// both resolution paths already read AEGIS_API_KEY and <PROVIDER>_API_KEY
|
|
385
|
+
// out of the environment (src/credentials.js, the byok class in the shared
|
|
386
|
+
// engine), they simply had nothing filling it. A variable already exported
|
|
387
|
+
// in the launching shell always wins. Placed AFTER the help/version
|
|
388
|
+
// early-exits so those stay instant, and before caps because everything
|
|
389
|
+
// below this point may resolve a credential.
|
|
390
|
+
try {
|
|
391
|
+
const { resolveClientModule } = require('../src/shared.js');
|
|
392
|
+
const envResult = require(resolveClientModule('env-file.js')).loadEnvFile();
|
|
393
|
+
if (envResult.loose) {
|
|
394
|
+
process.stderr.write(
|
|
395
|
+
`aegiscode: ${envResult.file} is readable by other accounts ` +
|
|
396
|
+
`(mode ${envResult.mode.toString(8)}) — consider \`chmod 600\` on it.\n`
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
} catch (e) {
|
|
400
|
+
process.stderr.write(`aegiscode: could not read ~/.aegiscode/.env: ${e && e.message}\n`);
|
|
401
|
+
}
|
|
402
|
+
|
|
379
403
|
// ── terminal capabilities, resolved before anything else is loaded ────────
|
|
380
404
|
//
|
|
381
405
|
// Ordering is the whole point. `theme.js` materialises its palettes and its
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.8.0",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
package/scripts/predist.mjs
CHANGED
|
@@ -44,6 +44,12 @@ const FILES = [
|
|
|
44
44
|
// list; `src/shared.js` resolves them from here in an installed package.
|
|
45
45
|
'client/credentials.js',
|
|
46
46
|
'client/session-store.js',
|
|
47
|
+
// The shared `~/.aegiscode/.env` loader. bin/aegiscode.js resolves it through
|
|
48
|
+
// resolveClientModule in src/shared.js and calls it before any credential is
|
|
49
|
+
// read, so a key lives in ONE file for every host. (No apostrophes in the
|
|
50
|
+
// comments in this array: test/packaging.test.mjs parses it by pairing single
|
|
51
|
+
// quotes, and one stray one silently swallows the next real entry.)
|
|
52
|
+
'client/env-file.js',
|
|
47
53
|
'mcp/tools.js',
|
|
48
54
|
'desktop/renderer/usage.js',
|
|
49
55
|
// The agent-loop engine (persistent shell, editFile/grep/exec, Task
|
|
@@ -51,6 +57,11 @@ const FILES = [
|
|
|
51
57
|
// reuses it as-is, scoped to the 'aegis' class only (see src/engine.js) —
|
|
52
58
|
// one tool loop implementation, not a second one drifting alongside it.
|
|
53
59
|
'desktop/lib/local/engine.js',
|
|
60
|
+
// engine.js and settings.js both require this at load time: it is the local
|
|
61
|
+
// model transport, and the module that owns the fail-closed check deciding
|
|
62
|
+
// whether a base URL is on this machine. Leaving it out stages a vendor tree
|
|
63
|
+
// whose engine throws MODULE_NOT_FOUND before it can answer anything.
|
|
64
|
+
'desktop/lib/local/local.js',
|
|
54
65
|
// engine.js requires this at load time to hold a turn cut off at its tool
|
|
55
66
|
// horizon: the interruption is filed against the session and the next turn
|
|
56
67
|
// resumes it instead of starting cold. Staging engine.js without it ships a
|
|
@@ -61,13 +72,6 @@ const FILES = [
|
|
|
61
72
|
'desktop/lib/local/shell.js',
|
|
62
73
|
'desktop/lib/local/agents.js',
|
|
63
74
|
'desktop/lib/local/prompt.js',
|
|
64
|
-
// The direct-provider transport (openaiCompatible + anthropicMessages) the
|
|
65
|
-
// desktop injects into the engine for its custom-endpoint classes. The CLI's
|
|
66
|
-
// `custom` class (src/engine.js, the /model add catalog) now injects the same
|
|
67
|
-
// real transport instead of the throwing stub it used to, so a user's own
|
|
68
|
-
// base URL + key is called directly with the full tool loop — so this file
|
|
69
|
-
// must ship. Pure node builtins (fetch), stages cleanly.
|
|
70
|
-
'desktop/lib/local/providers.js',
|
|
71
75
|
// The provider-config store: one row per provider (base URL + key), and the
|
|
72
76
|
// row the 'byok' class reads for a per-provider key. The CLI now selects that
|
|
73
77
|
// class (src/engine.js), so it needs the same store the desktop writes —
|
package/src/app.js
CHANGED
|
@@ -40,7 +40,6 @@ const {
|
|
|
40
40
|
const credentials = require('./credentials.js');
|
|
41
41
|
const cloudsync = require('./cloudsync.js');
|
|
42
42
|
const { readSecret } = require('./secret.js');
|
|
43
|
-
const customModelsCatalog = require('./custommodels.js');
|
|
44
43
|
const { normalizeModelCatalog, pickerEntries, catalogIds } = require('./models.js');
|
|
45
44
|
const { appendHistory, readSessionTranscript, readOwnSessions } = require('./history.js');
|
|
46
45
|
const { snapshotCheckpoint } = require('./checkpoint.js');
|
|
@@ -494,20 +493,10 @@ function createApp(options = {}) {
|
|
|
494
493
|
* offer": a catalog is a convenience, and an offline client must still be
|
|
495
494
|
* able to chat on the server's own default.
|
|
496
495
|
*/
|
|
497
|
-
async function loadCustomModels() {
|
|
498
|
-
// The `custom` catalog is local (config.json + the 0600 key store), so this
|
|
499
|
-
// never touches the network and needs no cache. The engine already returns
|
|
500
|
-
// the picker/`/models` shape ({id, label, note, configured, wire}).
|
|
501
|
-
if (typeof engine.listModels !== 'function') return [];
|
|
502
|
-
const res = await engine.listModels('custom');
|
|
503
|
-
return (res && res.models) || [];
|
|
504
|
-
}
|
|
505
|
-
|
|
506
496
|
async function listModelsFor(cls) {
|
|
507
497
|
const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
|
|
508
498
|
try {
|
|
509
499
|
if (want === 'byok') return await loadByokModels();
|
|
510
|
-
if (want === 'custom') return await loadCustomModels();
|
|
511
500
|
return await loadModels();
|
|
512
501
|
} catch {
|
|
513
502
|
return [];
|
|
@@ -516,30 +505,27 @@ function createApp(options = {}) {
|
|
|
516
505
|
|
|
517
506
|
/**
|
|
518
507
|
* Whether a pinned id can run on `cls`, decided synchronously (switchClass is
|
|
519
|
-
* not async). byok ids are `provider:model`;
|
|
520
|
-
*
|
|
521
|
-
*
|
|
508
|
+
* not async). byok ids are `provider:model`; aegis takes anything that is
|
|
509
|
+
* not — the pooled catalog is validated separately, at launch, by
|
|
510
|
+
* validatePinnedModel.
|
|
522
511
|
*/
|
|
523
512
|
function pinBelongsToClass(cls, id) {
|
|
524
513
|
const s = String(id == null ? '' : id);
|
|
525
514
|
if (cls === 'byok') return s.includes(':');
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
return !s.includes(':') && !customModelsCatalog.getCustom(s);
|
|
515
|
+
// aegis: not a byok id.
|
|
516
|
+
return !s.includes(':');
|
|
529
517
|
}
|
|
530
518
|
|
|
531
519
|
/**
|
|
532
520
|
* Switch the live class. Refuses anything this host cannot run (engine.js's
|
|
533
|
-
* HOST_CLASSES is the authority
|
|
521
|
+
* HOST_CLASSES is the authority).
|
|
534
522
|
*
|
|
535
523
|
* A pin is cleared when it does not belong to the class being entered: a
|
|
536
524
|
* pooled id pinned under byok would be parsed as provider `<pooled id>` and
|
|
537
525
|
* fail at the relay with a confusing "no key saved for …" instead of here,
|
|
538
526
|
* with a reason. Symmetrically, `anthropic:claude-…` under aegis is an id the
|
|
539
527
|
* pooled catalog does not advertise, which is the silent-fallback case
|
|
540
|
-
* validatePinnedModel exists to prevent.
|
|
541
|
-
* space (the /model add catalog, resolvable synchronously from config.json),
|
|
542
|
-
* so a pin belongs to it exactly when it is one of those ids.
|
|
528
|
+
* validatePinnedModel exists to prevent.
|
|
543
529
|
*/
|
|
544
530
|
function switchClass(next) {
|
|
545
531
|
const want = String(next == null ? '' : next).trim().toLowerCase();
|
|
@@ -610,31 +596,6 @@ function createApp(options = {}) {
|
|
|
610
596
|
);
|
|
611
597
|
return pinned;
|
|
612
598
|
}
|
|
613
|
-
// A custom pin is validated against the local catalog, never the pooled one:
|
|
614
|
-
// its ids are the user's own (from /model add) and the pool has never heard
|
|
615
|
-
// of them, so checking the pooled catalog would clear every custom pin on
|
|
616
|
-
// launch. An empty catalog clears nothing (offline-safe like the pooled path).
|
|
617
|
-
if (commandCtx.modelClass === 'custom') {
|
|
618
|
-
let customModels;
|
|
619
|
-
try {
|
|
620
|
-
customModels = await loadCustomModels();
|
|
621
|
-
} catch {
|
|
622
|
-
return null;
|
|
623
|
-
}
|
|
624
|
-
if (!customModels.length) return null;
|
|
625
|
-
if (customModels.some((m) => m.id === pinned)) return null;
|
|
626
|
-
commandCtx.model = null;
|
|
627
|
-
updateConfig({ model: null, currentModelId: null });
|
|
628
|
-
emit(
|
|
629
|
-
render.renderNotice(
|
|
630
|
-
ctx(),
|
|
631
|
-
'warn',
|
|
632
|
-
`pinned model "${pinned}" is not in your custom catalog — pin cleared; ` +
|
|
633
|
-
'/models lists your endpoints, /model add registers one.'
|
|
634
|
-
)
|
|
635
|
-
);
|
|
636
|
-
return pinned;
|
|
637
|
-
}
|
|
638
599
|
let models;
|
|
639
600
|
try {
|
|
640
601
|
models = await loadModels();
|
package/src/commands.js
CHANGED
|
@@ -65,6 +65,7 @@ const { detectDevCommand, runDevServer } = require('./devrun.js');
|
|
|
65
65
|
const credentials = require('./credentials.js');
|
|
66
66
|
const cloudsync = require('./cloudsync.js');
|
|
67
67
|
const { maskKey, fmtTokens } = require('./format.js');
|
|
68
|
+
const { pickerEntries } = require('./models.js');
|
|
68
69
|
const { openUrl, URLS } = require('./system.js');
|
|
69
70
|
const { sniffProject, buildAegisMd } = require('./init.js');
|
|
70
71
|
const {
|
|
@@ -73,10 +74,6 @@ const {
|
|
|
73
74
|
const {
|
|
74
75
|
aggregateSessionUsage, pruneSessionHistory, readResumeList,
|
|
75
76
|
} = require('./history.js');
|
|
76
|
-
// The custom-endpoint catalog behind the `custom` class and /model add|key|remove.
|
|
77
|
-
const customModelsCatalog = require('./custommodels.js');
|
|
78
|
-
const { VALID_WIRES } = customModelsCatalog;
|
|
79
|
-
|
|
80
77
|
// Guarded: a concurrent workstream owns ./markdown.js.
|
|
81
78
|
let markdownModule = null;
|
|
82
79
|
try {
|
|
@@ -114,61 +111,31 @@ const EFFORT_LEVELS = overlays.EFFORT_VALUES;
|
|
|
114
111
|
|
|
115
112
|
// ── Small handler helpers ─────────────────────────────────────────────────────
|
|
116
113
|
|
|
117
|
-
/**
|
|
118
|
-
* Split a command's raw tail into tokens, honouring double quotes so a model
|
|
119
|
-
* name or id with a space stays one token
|
|
120
|
-
* (`/model add local "Llama 3 70B" http://…`). Backslash escapes a quote or a
|
|
121
|
-
* backslash inside a quoted run. Never throws — an unclosed quote simply ends
|
|
122
|
-
* at the end of the line.
|
|
123
|
-
*/
|
|
124
|
-
function splitArgs(raw) {
|
|
125
|
-
const text = String(raw == null ? '' : raw);
|
|
126
|
-
const out = [];
|
|
127
|
-
let cur = '';
|
|
128
|
-
let quoted = false;
|
|
129
|
-
let started = false;
|
|
130
|
-
for (let i = 0; i < text.length; i++) {
|
|
131
|
-
const ch = text[i];
|
|
132
|
-
if (ch === '\\' && quoted && i + 1 < text.length && (text[i + 1] === '"' || text[i + 1] === '\\')) {
|
|
133
|
-
cur += text[++i];
|
|
134
|
-
started = true;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (ch === '"') {
|
|
138
|
-
quoted = !quoted;
|
|
139
|
-
// A quoted empty string ("") is a real, intentional token.
|
|
140
|
-
started = true;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (!quoted && /\s/.test(ch)) {
|
|
144
|
-
if (started) out.push(cur);
|
|
145
|
-
cur = '';
|
|
146
|
-
started = false;
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
cur += ch;
|
|
150
|
-
started = true;
|
|
151
|
-
}
|
|
152
|
-
if (started) out.push(cur);
|
|
153
|
-
return out;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
114
|
const note = (c, text) => c.push({ role: 'note', text });const panel = (c, lines) => c.push({ role: 'panel', lines });
|
|
157
115
|
const tip = (c, text) => c.push({ role: 'tip', text });
|
|
158
116
|
const done = (c, text) => c.push({ role: 'done', text });
|
|
159
117
|
const shortCwd = () => process.cwd().split('/').filter(Boolean).pop() || '~';
|
|
160
118
|
|
|
161
119
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
120
|
+
* The pinnable-model list for the class the session is on, fetched fresh.
|
|
121
|
+
*
|
|
122
|
+
* `c.loadModels()` on the command context is `() => listModelsFor(cls)` — it
|
|
123
|
+
* already returns the class-scoped rows (the pooled catalog on aegis, the
|
|
124
|
+
* `provider:model` ids this machine can relay on byok). This helper must
|
|
125
|
+
* RETURN that value.
|
|
126
|
+
*
|
|
127
|
+
* It used to `await` it and discard the result, leaving every caller to read
|
|
128
|
+
* `c.state().models` instead, which went stale the moment the live class
|
|
129
|
+
* changed. Best-effort on failure: offline, the caller falls through to the
|
|
130
|
+
* honest empty note rather than opening an empty picker.
|
|
131
|
+
* @returns {Promise<Array<{id:string,label:string,note:string}>>}
|
|
167
132
|
*/
|
|
168
133
|
async function loadModels(c) {
|
|
169
134
|
try {
|
|
170
|
-
await c.loadModels();
|
|
171
|
-
} catch {
|
|
135
|
+
return (await c.loadModels()) || [];
|
|
136
|
+
} catch {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
172
139
|
}
|
|
173
140
|
|
|
174
141
|
/**
|
|
@@ -330,10 +297,12 @@ async function applyAccountKey(c, raw, { label = 'AEGIS API key' } = {}) {
|
|
|
330
297
|
const acct = (res.account && (res.account.email || res.account.plan)) || null;
|
|
331
298
|
done(c, `AEGIS key saved to ${res.path}${acct ? ` — signed in as ${acct}` : ' and verified'}`);
|
|
332
299
|
// The catalog is key-gated, so a freshly authenticated session should offer
|
|
333
|
-
// /model's picker without the user having to know to re-run it.
|
|
300
|
+
// /model's picker without the user having to know to re-run it. Counted from
|
|
301
|
+
// the loader's return value (through pickerEntries, the same filter the
|
|
302
|
+
// picker applies) rather than `c.state().models`, so the number matches what
|
|
303
|
+
// the picker will actually offer.
|
|
334
304
|
try {
|
|
335
|
-
await
|
|
336
|
-
const n = (c.state().models || []).length;
|
|
305
|
+
const n = pickerEntries(await loadModels(c)).length;
|
|
337
306
|
if (n) note(c, `${n} pinnable model${n === 1 ? '' : 's'} available — /model to pin one`);
|
|
338
307
|
} catch {}
|
|
339
308
|
return res;
|
|
@@ -848,24 +817,25 @@ const COMMANDS = [
|
|
|
848
817
|
// will actually take (app.js's buildState().models is class-scoped too).
|
|
849
818
|
const cls = (c.ctx && c.ctx.modelClass) || 'aegis';
|
|
850
819
|
const byok = cls === 'byok';
|
|
851
|
-
// The sub-command token, lower-cased: `add` / `key` / `remove` are the
|
|
852
|
-
// custom-endpoint catalog's verbs. A model id is never one of these in
|
|
853
|
-
// practice, and `list` already shadows a real id the same way.
|
|
854
|
-
const sub = id.toLowerCase();
|
|
855
820
|
if (!id) {
|
|
856
821
|
note(c, `model: ${c.ctx.model || 'server default'}`);
|
|
857
|
-
// Populate the picker
|
|
858
|
-
//
|
|
859
|
-
//
|
|
860
|
-
|
|
861
|
-
|
|
822
|
+
// Populate the picker for the LIVE class first. The list is the return
|
|
823
|
+
// value, not `c.state().models`: that field is rebuilt from a cache the
|
|
824
|
+
// current class may not populate, so reading it rendered an empty
|
|
825
|
+
// picker on a class whose models are local and always readable.
|
|
826
|
+
//
|
|
827
|
+
// `pickerEntries` is the same filter app.js's buildState() applies to
|
|
828
|
+
// that field, and it has to be applied here for the same reason it is
|
|
829
|
+
// applied there: the loader returns the catalog — aliases included —
|
|
830
|
+
// and an alias row is not a pinnable entry, so listing it puts a
|
|
831
|
+
// duplicate in the picker that pins the id it points at.
|
|
832
|
+
const models = pickerEntries(await loadModels(c));
|
|
862
833
|
if (!models.length) {
|
|
863
834
|
// Say why, and what unblocks it: an unreachable catalog is almost
|
|
864
835
|
// always a missing key or no network, and "no models advertised"
|
|
865
836
|
// read as "the platform has none" rather than "this client could not
|
|
866
|
-
// ask". On byok "no models"
|
|
867
|
-
//
|
|
868
|
-
// which is exactly what /byok-key fixes.
|
|
837
|
+
// ask". On byok "no models" means this machine simply holds no
|
|
838
|
+
// provider key yet, which is exactly what /byok-key fixes.
|
|
869
839
|
note(c, byok
|
|
870
840
|
? 'No relayable models — this machine holds no provider key yet. Save one with /byok-key <provider>, then retry /model.'
|
|
871
841
|
: c.state().online
|
|
@@ -881,15 +851,12 @@ const COMMANDS = [
|
|
|
881
851
|
// from its own default with no error. Say so where the pin is visible
|
|
882
852
|
// rather than letting the reply look like the pinned model. On byok the
|
|
883
853
|
// failure mode is different and louder (the relay 400s on a provider it
|
|
884
|
-
// has no key for)
|
|
854
|
+
// has no key for).
|
|
885
855
|
if (c.ctx.model && !models.some((m) => m.id === c.ctx.model)) {
|
|
886
856
|
note(c, byok
|
|
887
857
|
? `pinned model "${c.ctx.model}" is not one this machine can relay — pick from the list below.`
|
|
888
858
|
: `pinned model "${c.ctx.model}" is not in the catalog — the pool will answer with its own default; pick one below.`);
|
|
889
859
|
}
|
|
890
|
-
// The overlay's own copy promises /model add|remove (overlays.js, a
|
|
891
|
-
// separate workstream); this build refuses both, so say here how a
|
|
892
|
-
// model is actually selected.
|
|
893
860
|
note(c, byok
|
|
894
861
|
? '/model <id> pins one for this session; /models lists what this machine can relay.'
|
|
895
862
|
: '/model <id> pins one for this session; /models lists what the server advertises.');
|
|
@@ -899,99 +866,14 @@ const COMMANDS = [
|
|
|
899
866
|
return true;
|
|
900
867
|
}
|
|
901
868
|
if (id === 'list') {
|
|
902
|
-
|
|
903
|
-
|
|
869
|
+
// Filtered like the picker above: the panel lists what can be pinned,
|
|
870
|
+
// so it cannot carry the alias rows the loader returns alongside them.
|
|
871
|
+
const models = pickerEntries(await loadModels(c));
|
|
904
872
|
if (!models.length) note(c, 'No pinnable models advertised — /models lists the server\'s ids.');
|
|
905
873
|
else panel(c, panels.buildModelList(c.ctx.model, models, c.ctx));
|
|
906
874
|
c.render();
|
|
907
875
|
return true;
|
|
908
876
|
}
|
|
909
|
-
// The /model add catalog — the aegiscodex-dev concept ported in. A user
|
|
910
|
-
// registers their own endpoint (own base URL, own model string, own key)
|
|
911
|
-
// and the CLI calls it DIRECTLY through the desktop transport, the full
|
|
912
|
-
// tool loop and all: no pooled route, no BYOK relay, no fee or margin.
|
|
913
|
-
// The classic entry form is the positional one
|
|
914
|
-
// /model add <id> <name> <model> <baseURL> [wire]
|
|
915
|
-
// with the key prompted for (masked) right after, or supplied inline
|
|
916
|
-
// /model add <id> <name> <model> <baseURL> [wire] <key>
|
|
917
|
-
// (the scriptable spelling, like /byok-key's second token).
|
|
918
|
-
if (sub === 'add') {
|
|
919
|
-
const parts = splitArgs(args._rest);
|
|
920
|
-
// `sub` itself is the first token of _rest, so drop its own copy.
|
|
921
|
-
const rest = parts[0] === 'add' ? parts.slice(1) : parts;
|
|
922
|
-
// The wire name is optional and only recognised when it is one of the
|
|
923
|
-
// two transports — otherwise that token is the key (so
|
|
924
|
-
// `/model add id name model url sk-…` needs no placeholder).
|
|
925
|
-
let at = 4;
|
|
926
|
-
let wire;
|
|
927
|
-
if (VALID_WIRES.includes(String(rest[at] || '').toLowerCase())) {
|
|
928
|
-
wire = String(rest[at]).toLowerCase();
|
|
929
|
-
at += 1;
|
|
930
|
-
}
|
|
931
|
-
const fields = { id: rest[0], name: rest[1], model: rest[2], baseURL: rest[3], wire };
|
|
932
|
-
if (!fields.id || !fields.model || !fields.baseURL) {
|
|
933
|
-
note(c, 'Usage: /model add <id> <name> <model> <baseURL> [openai|anthropic] [key]');
|
|
934
|
-
note(c, ' e.g. /model add local Llama-3 "meta-llama/Llama-3-70b" http://localhost:8080/v1');
|
|
935
|
-
note(c, ' the key is prompted for and stored 0600 on this machine — never in config.json.');
|
|
936
|
-
c.render();
|
|
937
|
-
return true;
|
|
938
|
-
}
|
|
939
|
-
const inlineKey = rest[at] || '';
|
|
940
|
-
const store = c.settings && c.settings();
|
|
941
|
-
const res = customModelsCatalog.addCustom({ ...fields, key: null }, store);
|
|
942
|
-
if (res.error) {
|
|
943
|
-
c.push({ role: 'error', text: `couldn't add "${fields.id}": ${res.error}` });
|
|
944
|
-
return true;
|
|
945
|
-
}
|
|
946
|
-
const entry = res.entry;
|
|
947
|
-
let key = inlineKey || '';
|
|
948
|
-
if (!key) {
|
|
949
|
-
note(c, `storing a key for "${entry.id}" — leave it blank to add it later with /model key ${entry.id}.`);
|
|
950
|
-
c.render();
|
|
951
|
-
key = String((await c.readSecret(`${entry.id} key: `)) || '').trim();
|
|
952
|
-
}
|
|
953
|
-
if (key) {
|
|
954
|
-
customModelsCatalog.setCustomKey(entry.id, key, store);
|
|
955
|
-
}
|
|
956
|
-
note(c, `added "${entry.id}" → ${entry.model} at ${entry.baseURL} (${entry.wire} wire)${key ? '' : ' — no key yet'}.`);
|
|
957
|
-
note(c, key
|
|
958
|
-
? `run it with /class custom (then /model ${entry.id}), or /model ${entry.id} while on the custom class.`
|
|
959
|
-
: `add its key with /model key ${entry.id}, then /class custom runs it.`);
|
|
960
|
-
c.render();
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
if (sub === 'key') {
|
|
964
|
-
const target = splitArgs(args._rest)[1];
|
|
965
|
-
if (!target) { note(c, 'Usage: /model key <id> — /models lists your custom endpoints.'); c.render(); return true; }
|
|
966
|
-
const entry = customModelsCatalog.getCustom(target);
|
|
967
|
-
if (!entry) { note(c, `no custom endpoint "${target}" — /model add registers one.`); c.render(); return true; }
|
|
968
|
-
const store = c.settings && c.settings();
|
|
969
|
-
note(c, `storing a key for "${entry.id}" — blank clears it.`);
|
|
970
|
-
c.render();
|
|
971
|
-
const key = String((await c.readSecret(`${entry.id} key: `)) || '').trim();
|
|
972
|
-
if (!key) { note(c, 'nothing saved.'); c.render(); return true; }
|
|
973
|
-
customModelsCatalog.setCustomKey(entry.id, key, store);
|
|
974
|
-
note(c, `saved a key for "${entry.id}" on this machine — /class custom runs it.`);
|
|
975
|
-
c.render();
|
|
976
|
-
return true;
|
|
977
|
-
}
|
|
978
|
-
if (sub === 'remove' || sub === 'rm') {
|
|
979
|
-
const target = splitArgs(args._rest)[1];
|
|
980
|
-
if (!target) { note(c, 'Usage: /model remove <id>'); c.render(); return true; }
|
|
981
|
-
const store = c.settings && c.settings();
|
|
982
|
-
const { removed } = customModelsCatalog.removeCustom(target, store);
|
|
983
|
-
if (!removed) { note(c, `no custom endpoint "${target}" — /models lists your endpoints.`); c.render(); return true; }
|
|
984
|
-
// A pin on the row we just deleted would otherwise outlive its entry and
|
|
985
|
-
// fail at the next send with "no model … in the catalog".
|
|
986
|
-
if (String(c.ctx.model || '') === String(target)) {
|
|
987
|
-
c.ctx.model = null;
|
|
988
|
-
c.saveConfig({ model: null, currentModelId: null });
|
|
989
|
-
note(c, `unpinned "${target}" (its catalog entry is gone).`);
|
|
990
|
-
}
|
|
991
|
-
note(c, `removed "${target}" and forgot its key.`);
|
|
992
|
-
c.render();
|
|
993
|
-
return true;
|
|
994
|
-
}
|
|
995
877
|
if (id === '-') {
|
|
996
878
|
c.ctx.model = null;
|
|
997
879
|
c.saveConfig({ model: null, currentModelId: null });
|
|
@@ -1020,8 +902,7 @@ const COMMANDS = [
|
|
|
1020
902
|
// so a pooled id becomes "no key saved for <that id>" at the relay.
|
|
1021
903
|
// Warn, never refuse: the catalog is cached, and refusing would break a
|
|
1022
904
|
// pin made against a server that is briefly unreachable.
|
|
1023
|
-
await loadModels(c);
|
|
1024
|
-
const models = c.state().models || [];
|
|
905
|
+
const models = (await loadModels(c)) || [];
|
|
1025
906
|
if (models.length && !models.some((m) => m.id === id)) {
|
|
1026
907
|
note(c, byok
|
|
1027
908
|
? `"${id}" is not one this machine can relay — a byok id is "<provider>:<model>", and the relay will refuse anything else. /models lists the real ids.`
|
package/src/config.js
CHANGED
|
@@ -73,16 +73,6 @@ const DEFAULT_CONFIG = {
|
|
|
73
73
|
// aegiscode- name so /model add/remove/switch stay compatible both ways.
|
|
74
74
|
models: null,
|
|
75
75
|
currentModelId: null,
|
|
76
|
-
// The named custom-model catalog behind the `custom` class — the
|
|
77
|
-
// aegiscodex-dev `/model add` concept: each entry names an endpoint the user
|
|
78
|
-
// brings themselves (own base URL + own key), called DIRECTLY through the
|
|
79
|
-
// desktop transport (providers.openaiCompatible / anthropicMessages), tools
|
|
80
|
-
// and all, never through the pooled route or the BYOK relay. Only the
|
|
81
|
-
// non-secret metadata lives here; the key is in the 0600 settings store under
|
|
82
|
-
// `custom:<id>` (engine.js), never in this file (config.json is not 0600 and
|
|
83
|
-
// participates in cloud sync). Shape: [{ id, name, model, baseURL, wire }],
|
|
84
|
-
// wire ∈ {'openai','anthropic'}.
|
|
85
|
-
customModels: [],
|
|
86
76
|
// `null` = no effort pinned, i.e. "auto": each turn is sized by the server
|
|
87
77
|
// from the ask itself (aegis1 services/pool_brain.py estimate_effort). The
|
|
88
78
|
// old 'high' was a *pin* on the top rung of the budget ladder — the most the
|