aegiscode 6.8.37 → 7.0.1

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.
Files changed (110) hide show
  1. package/README.md +39 -1
  2. package/bin/aegiscode.js +137 -0
  3. package/package.json +1 -1
  4. package/scripts/check.mjs +5 -0
  5. package/scripts/demo.mjs +5 -0
  6. package/scripts/predist.mjs +29 -2
  7. package/scripts/runtests.mjs +5 -0
  8. package/scripts/seal-gate.mjs +76 -0
  9. package/src/agents.js +5 -0
  10. package/src/app.js +59 -1
  11. package/src/art.js +5 -0
  12. package/src/autonomous.js +23 -0
  13. package/src/caps.js +5 -0
  14. package/src/chatflow.js +104 -31
  15. package/src/checkpoint.js +5 -0
  16. package/src/clipboard.js +5 -0
  17. package/src/cloudsync.js +5 -0
  18. package/src/commands.js +487 -4
  19. package/src/config.js +5 -0
  20. package/src/credentials.js +5 -0
  21. package/src/deps.js +5 -0
  22. package/src/devrun.js +5 -0
  23. package/src/diff.js +5 -0
  24. package/src/diffview.js +5 -0
  25. package/src/engine.js +5 -0
  26. package/src/entitlement.js +5 -0
  27. package/src/events.js +15 -0
  28. package/src/export.js +5 -0
  29. package/src/fingerprint.js +5 -0
  30. package/src/format.js +5 -0
  31. package/src/fuzzy.js +5 -0
  32. package/src/gate.js +12 -0
  33. package/src/history.js +5 -0
  34. package/src/init.js +5 -0
  35. package/src/input.js +5 -0
  36. package/src/keys.js +29 -2
  37. package/src/limits.js +192 -0
  38. package/src/markdown.js +5 -0
  39. package/src/mcp.js +13 -0
  40. package/src/models.js +5 -0
  41. package/src/naming.js +5 -0
  42. package/src/overlays.js +7 -2
  43. package/src/panels.js +5 -0
  44. package/src/permissions.js +56 -1
  45. package/src/ping.js +5 -0
  46. package/src/presence.js +5 -0
  47. package/src/provenance.js +238 -0
  48. package/src/provenance.lock.json +36 -0
  49. package/src/render.js +5 -0
  50. package/src/screen.js +5 -0
  51. package/src/screens.js +48 -37
  52. package/src/secret.js +5 -0
  53. package/src/securefs.js +5 -0
  54. package/src/settings.js +5 -0
  55. package/src/shared.js +5 -0
  56. package/src/sharedpaths.js +5 -0
  57. package/src/signup.js +5 -0
  58. package/src/summarize.js +5 -0
  59. package/src/sysdiag.js +582 -0
  60. package/src/system.js +5 -0
  61. package/src/theme.js +5 -0
  62. package/src/title.js +5 -0
  63. package/src/todos.js +5 -0
  64. package/src/tokens.js +5 -0
  65. package/src/topup.js +5 -0
  66. package/src/update.js +5 -0
  67. package/vendor/client/aegis.js +27 -0
  68. package/vendor/client/attest.js +5 -0
  69. package/vendor/client/authorship-key.js +5 -0
  70. package/vendor/client/auto-provision.js +5 -0
  71. package/vendor/client/brain-catalog.js +5 -0
  72. package/vendor/client/byok-catalog.js +48 -8
  73. package/vendor/client/credentials.js +5 -0
  74. package/vendor/client/device-fingerprint.js +5 -0
  75. package/vendor/client/env-file.js +5 -0
  76. package/vendor/client/fingerprint.js +5 -0
  77. package/vendor/client/foreign-memory.js +5 -0
  78. package/vendor/client/hooks.js +5 -0
  79. package/vendor/client/model-discovery.js +332 -0
  80. package/vendor/client/platform.js +5 -0
  81. package/vendor/client/prefs.js +5 -0
  82. package/vendor/client/presence-constants.js +5 -0
  83. package/vendor/client/presence.js +5 -0
  84. package/vendor/client/record-vault.js +5 -0
  85. package/vendor/client/session-store.js +5 -0
  86. package/vendor/client/topup.js +5 -0
  87. package/vendor/client/touch.js +5 -0
  88. package/vendor/client/update.js +5 -0
  89. package/vendor/client/user-models.js +383 -0
  90. package/vendor/desktop/lib/local/aegis-seal.mjs +5 -0
  91. package/vendor/desktop/lib/local/agents.js +5 -0
  92. package/vendor/desktop/lib/local/autonomous.js +86 -0
  93. package/vendor/desktop/lib/local/context.js +5 -0
  94. package/vendor/desktop/lib/local/covenant.js +5 -0
  95. package/vendor/desktop/lib/local/engine.js +463 -12
  96. package/vendor/desktop/lib/local/entitlement.js +5 -0
  97. package/vendor/desktop/lib/local/git-scope.js +5 -0
  98. package/vendor/desktop/lib/local/local.js +5 -0
  99. package/vendor/desktop/lib/local/prompt.js +5 -0
  100. package/vendor/desktop/lib/local/queue.js +5 -0
  101. package/vendor/desktop/lib/local/session-rounds.js +5 -0
  102. package/vendor/desktop/lib/local/shell.js +88 -9
  103. package/vendor/desktop/lib/local/tools.js +13 -6
  104. package/vendor/desktop/lib/local/turn-guard.js +5 -0
  105. package/vendor/desktop/lib/local/worktree-lock.js +5 -0
  106. package/vendor/desktop/lib/settings.js +5 -0
  107. package/vendor/desktop/renderer/usage.js +73 -1
  108. package/vendor/mcp/server.js +5 -0
  109. package/vendor/mcp/tools.js +5 -0
  110. package/vendor/tools/agent-gate.mjs +23 -0
package/src/commands.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
@@ -93,6 +98,9 @@ const { pickerEntries } = require('./models.js');
93
98
  const { resolveShared } = require('./sharedpaths.js');
94
99
  const { createCliEntitlement, paymentView, probeFee } = require('./entitlement.js');
95
100
  const { openUrl, URLS } = require('./system.js');
101
+ // The machine checks behind `/doctor system` — see cli/src/sysdiag.js for why
102
+ // they exist and why they never mutate anything.
103
+ const sysdiag = require('./sysdiag.js');
96
104
  const { sniffProject, buildAegisMd } = require('./init.js');
97
105
  const { upgradeAdvice, latestPublishedVersion } = require('./update.js');
98
106
  const {
@@ -396,6 +404,134 @@ const cloudReady = () => credentials.hasApiKey();
396
404
  */
397
405
  const { withByokAdditions } = require(resolveShared(path.join('client', 'byok-catalog.js')));
398
406
 
407
+ /**
408
+ * The models the USER declares (`client/user-models.js`) — the same file the
409
+ * desktop's Settings row writes, resolved by existence through the same
410
+ * `resolveShared` path and for the same reason: one store, three writers.
411
+ *
412
+ * `/byok` and `/models` read it here, and the CLI's own engine
413
+ * (`desktop/lib/local/engine.js` `listModels('byok')`, vendored into this
414
+ * package) applies it too, so the terminal's listing and the terminal's picker
415
+ * cannot disagree about which ids this machine offers.
416
+ */
417
+ const {
418
+ withUserModels,
419
+ addUserModel,
420
+ removeUserModel,
421
+ userModelIdsFor,
422
+ userModelsPath,
423
+ } = require(resolveShared(path.join('client', 'user-models.js')));
424
+
425
+ /**
426
+ * Ask the VENDOR what it serves (`client/model-discovery.js`), so `/model-add`
427
+ * can offer a list instead of asking the user to recall an id.
428
+ *
429
+ * Same `resolveShared` resolution as its two siblings above: one implementation
430
+ * of "what does this provider's key actually reach", read by both faces. It is
431
+ * loaded at module scope rather than lazily inside the handler because the
432
+ * command needs it to decide what to PROMPT with — a discovery module that
433
+ * loads only after discovery was decided to be possible would be circular.
434
+ *
435
+ * The module does no I/O at load (no key store, no network), so pulling it in
436
+ * with `/help` costs a `require` and nothing else.
437
+ */
438
+ const {
439
+ discoverModels: discoverVendorModels,
440
+ endpointFor: vendorEndpointFor,
441
+ discoverableProviders,
442
+ } = require(resolveShared(path.join('client', 'model-discovery.js')));
443
+
444
+ /**
445
+ * The vendor key for a provider, resolved the way the engine resolves it:
446
+ * the saved provider-key row first, then `~/.aegiscode/.env` (and the shell).
447
+ *
448
+ * Deliberately the same ORDER as `desktop/lib/local/engine.js`'s
449
+ * `providerKeyFromEnv` + `byok:<provider>` lookup, because discovery must use
450
+ * the key the NEXT TURN will use — a listing fetched with a different key than
451
+ * the one the call runs on is a listing of somebody else's catalog. This is
452
+ * read-only: it never writes a key, never logs one, and returns '' when the
453
+ * machine has none, which the caller reports as "no key to ask with".
454
+ */
455
+ function byokKeyForProvider(c, provider) {
456
+ const id = String(provider || '').trim().toLowerCase();
457
+ if (!id) return '';
458
+ try {
459
+ const store = c && c.settings && c.settings();
460
+ if (store && typeof store.rawKey === 'function' && typeof c.byokNamespace === 'function') {
461
+ const saved = store.rawKey(c.byokNamespace(id));
462
+ if (typeof saved === 'string' && saved.trim()) return saved.trim();
463
+ }
464
+ } catch {
465
+ /* a store that throws is a store with no key, not a reason to stop */
466
+ }
467
+ try {
468
+ const { providerKeyFromEnv } = require(resolveShared(path.join('client', 'env-file.js')));
469
+ return (providerKeyFromEnv(id) || {}).key || '';
470
+ } catch {
471
+ return '';
472
+ }
473
+ }
474
+
475
+ /**
476
+ * Ask the provider's own list endpoint, if this machine can. Never throws.
477
+ *
478
+ * `fetchImpl` is injectable through the context so the CLI tests drive a stub
479
+ * and never open a socket; `c.fetchImpl` is undefined in a real run, which is
480
+ * the module's normal `fetch`.
481
+ */
482
+ async function discoverProviderModels(c, provider, key) {
483
+ try {
484
+ return await discoverVendorModels(provider, { key, fetchImpl: c && c.fetchImpl });
485
+ } catch (err) {
486
+ return { ok: false, provider, supported: true, error: (err && err.message) || String(err) };
487
+ }
488
+ }
489
+
490
+ /**
491
+ * The provider's own catalog, best-effort, as `[ids]`. Undefined when the
492
+ * vendor could not be asked — the caller then falls back to a free-form id
493
+ * prompt, because that path works and must keep working offline.
494
+ */
495
+ async function offeredModelIds(c, provider, key) {
496
+ const res = await discoverProviderModels(c, provider, key);
497
+ return res && res.ok && Array.isArray(res.ids) && res.ids.length ? res.ids : undefined;
498
+ }
499
+
500
+ /**
501
+ * Declare ids into the store, skipping the ones already there. Returns the
502
+ * count added, plus what was skipped and WHY, so the caller can say
503
+ * "3 added, 2 already declared" instead of claiming work it did not do.
504
+ *
505
+ * The cap matters here more than anywhere else: a vendor's list endpoint
506
+ * answers with everything it serves — OpenAI currently returns 100 ids — and
507
+ * the store holds at most 32 per provider by design. Without this the bulk
508
+ * path would report sixty-eight "refused" models, which reads as sixty-eight
509
+ * broken ids rather than one deliberate ceiling. So the cap ends the batch and
510
+ * is reported as itself.
511
+ */
512
+ function addManyUserModels(provider, ids) {
513
+ let added = 0;
514
+ let capped = 0;
515
+ const already = [];
516
+ const failed = [];
517
+ for (const id of ids) {
518
+ try {
519
+ if (addUserModel(provider, id).added) added += 1;
520
+ else already.push(id);
521
+ } catch (err) {
522
+ const message = (err && err.message) || String(err);
523
+ if (/the cap/.test(message)) {
524
+ // Every remaining id would hit the same wall, so stop rather than
525
+ // loop sixty more times to collect sixty copies of one message.
526
+ capped = ids.length - added - already.length - failed.length;
527
+ break;
528
+ }
529
+ failed.push({ id, reason: message });
530
+ }
531
+ }
532
+ return { added, already, failed, capped };
533
+ }
534
+
399
535
  /**
400
536
  * The server's BYOK provider catalog, or null when it cannot be reached.
401
537
  *
@@ -410,7 +546,13 @@ async function byokCatalog(client) {
410
546
  if (!client || typeof client.byokProviders !== 'function') return null;
411
547
  try {
412
548
  const data = await client.byokProviders();
413
- const providers = withByokAdditions((data && data.providers) || []);
549
+ // Two layers, in this order and for the same reason both exist: the
550
+ // shipped additions this repo maintains (`withByokAdditions`) and then the
551
+ // USER's own declarations (`withUserModels`). The user's layer is applied
552
+ // last because it is the most specific opinion — and because a user who
553
+ // declares an id the shipped list also carries still gets ONE row (both
554
+ // functions append only what is missing).
555
+ const providers = withUserModels(withByokAdditions((data && data.providers) || []));
414
556
  return providers.length ? providers : null;
415
557
  } catch {
416
558
  return null;
@@ -1608,12 +1750,12 @@ const COMMANDS = [
1608
1750
  },
1609
1751
  },
1610
1752
  {
1611
- name: 'doctor', args: ['action'], hint: '[fix]', category: 'support',
1753
+ name: 'doctor', args: ['action'], hint: '[fix|system]', category: 'support',
1612
1754
  desc: 'Run diagnostic checks on this environment',
1613
1755
  handler: async (c, args) => {
1614
1756
  const action = ((args && args.action) || '').toLowerCase();
1615
- if (action && action !== 'fix') {
1616
- note(c, 'Usage: /doctor [fix] — "fix" re-tightens the data dir to 0700/0600');
1757
+ if (action && action !== 'fix' && action !== 'system') {
1758
+ note(c, 'Usage: /doctor [fix|system] — "fix" re-tightens the data dir to 0700/0600, "system" checks the machine itself');
1617
1759
  c.render();
1618
1760
  return true;
1619
1761
  }
@@ -1688,6 +1830,29 @@ const COMMANDS = [
1688
1830
  repaired.failed.map((f) => `${f.rel}: ${f.reason}`).join(', ')
1689
1831
  );
1690
1832
  }
1833
+ // `/doctor system` — the machine, not the checkout. Read-only by design:
1834
+ // cli/src/sysdiag.js holds the nine checks and each one's remedy, and
1835
+ // nothing here executes a remedy, because all of them need elevation and
1836
+ // the ordering matters (VSS has to survive DoSnapshotSet before a restore
1837
+ // point can exist). An unread probe is its own state, never a ✔.
1838
+ let systemReport = null;
1839
+ if (action === 'system') {
1840
+ const probe = sysdiag.collect();
1841
+ if (!probe.ok) {
1842
+ ok(
1843
+ 'machine checks',
1844
+ false,
1845
+ probe.reason === 'not-windows'
1846
+ ? 'not available on this platform — the machine audit is Windows-only (cli/src/sysdiag.js)'
1847
+ : `could not run: ${probe.reason}`,
1848
+ );
1849
+ } else {
1850
+ systemReport = sysdiag.assess(probe.data);
1851
+ for (const f of systemReport.findings) ok(`${f.title} (${f.severity})`, false, `${f.detail} → ${f.remedyText}`);
1852
+ for (const p of systemReport.clean) ok(p.title, true, p.detail);
1853
+ for (const u of systemReport.unassessed) ok(`${u.title} (unassessed)`, false, u.reason);
1854
+ }
1855
+ }
1691
1856
  const lines = [[span(C.gold + BOLD, 'Doctor'), span(BOLD_OFF, '')], [span(C.gray, '─'.repeat(30))]];
1692
1857
  for (const [good, label, detail] of checks) {
1693
1858
  lines.push([
@@ -1696,6 +1861,15 @@ const COMMANDS = [
1696
1861
  span(C.gray, String(detail)),
1697
1862
  ]);
1698
1863
  }
1864
+ if (systemReport && systemReport.findings.length) {
1865
+ const s = systemReport.summary;
1866
+ lines.push([
1867
+ span(C.gold, ' Remedy'),
1868
+ span(C.gray, ` — ${s.findings} finding(s) across ${s.assessed}/${s.total} measured checks.`),
1869
+ ]);
1870
+ lines.push([span(C.gray, ' Run in an ELEVATED PowerShell. AEGIS diagnoses this; it does not change your machine.')]);
1871
+ for (const line of sysdiag.remedyScript().split('\n')) lines.push([span(C.gray, ` ${line}`)]);
1872
+ }
1699
1873
  panel(c, lines);
1700
1874
  c.render();
1701
1875
  return true;
@@ -2159,6 +2333,17 @@ const COMMANDS = [
2159
2333
  // through the one writer, so the window's switch shows it and the two
2160
2334
  // faces cannot disagree.
2161
2335
  setConfirmPosture(!want);
2336
+ // …and the SESSION's own half. The posture answers "does the window's
2337
+ // switch say don't ask"; the session flag answers "did this sitting start
2338
+ // in auto mode". They are two facts (the upstream engine keeps them apart:
2339
+ // AEGIS_AUTO_ROUNDS=0 starts manual without touching any stored posture),
2340
+ // and with an env opt-out standing, writing only the posture made this
2341
+ // command — and the `→` chord that dispatches it — a no-op that reported
2342
+ // success: the store said "off", the chip still read "manual mode on", and
2343
+ // the tool gate in app.js's isYolo kept asking. Moving both here is what
2344
+ // makes the opt-out escapable at the prompt instead of for the life of the
2345
+ // process. Guarded because an injected/older context may not carry it.
2346
+ if (typeof c.setAutoRounds === 'function') c.setAutoRounds(want);
2162
2347
  if (want) panel(c, panels.buildAutomode(c.state(), c.ctx));
2163
2348
  else note(c, 'automode off — confirmations restored.');
2164
2349
  c.render();
@@ -2960,6 +3145,304 @@ const COMMANDS = [
2960
3145
  return true;
2961
3146
  },
2962
3147
  },
3148
+ {
3149
+ // ── the user's own model declarations ──────────────────────────────────
3150
+ //
3151
+ // The ONE thing this repo could not do before: a provider ships a model on
3152
+ // Tuesday and the user can call it from a BYOK key that same day. The BYOK
3153
+ // relay is a stateless pass-through — the caller's own vendor key
3154
+ // authenticates upstream and AEGIS forwards whatever model string it was
3155
+ // given — so any id the vendor serves is callable the moment this machine
3156
+ // offers it as a row, and this command is how it becomes one without a
3157
+ // release.
3158
+ //
3159
+ // Written through `client/user-models.js`, which is also what the desktop's
3160
+ // Settings row writes and what the shared engine applies to
3161
+ // `listModels('byok')`, so `/models` and the alt+p picker show the row on
3162
+ // the next refresh and the window shows it on ITS next refresh. The file is
3163
+ // printed on success, because a hand-edit is the bulk path and a store the
3164
+ // user cannot find is a store they will not use.
3165
+ name: 'model-add', aliases: ['add-model'], args: ['provider'], hint: '<provider> [model-id|*]',
3166
+ category: 'model',
3167
+ desc: 'Offer a model id the AEGIS catalog does not name (asks the vendor when it can)',
3168
+ handler: async (c, a) => {
3169
+ const args = a || {};
3170
+ const typed = String(args.provider || '').trim();
3171
+ if (!typed) {
3172
+ c.push({ role: 'error', text: 'Usage: /model-add <provider> <model-id> — /byok lists the providers.' });
3173
+ return true;
3174
+ }
3175
+ const rest = String(args._rest || '').trim();
3176
+ const sp = rest.indexOf(' ');
3177
+ let model = sp === -1 ? '' : rest.slice(sp + 1).trim();
3178
+ // Resolve the provider against the relay's catalog first. A slug the
3179
+ // server does not list can never be attached to a key, so storing it
3180
+ // would produce a declaration that is invisible in every picker — the
3181
+ // silent no-op this whole path is meant to avoid. When the catalog is
3182
+ // unreachable the declaration is kept and SAID to be unverified, because
3183
+ // refusing to work offline is worse than a row that appears later.
3184
+ const providers = await byokCatalog(c.client);
3185
+ const match = providers ? findByokProvider(providers, typed) : null;
3186
+ if (match && match.ambiguous) {
3187
+ c.push({ role: 'error', text: `"${typed}" matches ${match.ambiguous.join(', ')} — retype the exact id.` });
3188
+ return true;
3189
+ }
3190
+ if (providers && !(match && match.provider)) {
3191
+ c.push({
3192
+ role: 'error',
3193
+ text: `no provider "${typed}" in the relay's catalog — /byok lists the ones it takes a key for.`,
3194
+ });
3195
+ return true;
3196
+ }
3197
+ const id = (match && match.provider && match.provider.id) || typed.toLowerCase();
3198
+ // ── what the vendor says, before we ask the user to remember it ──────
3199
+ //
3200
+ // The whole cost of this feature used to be "know the vendor's model id",
3201
+ // which is the release-lag problem handed to the user instead of solved.
3202
+ // When this machine holds a key for the provider, its own list endpoint
3203
+ // answers that in one request. Best-effort by construction: no key, no
3204
+ // endpoint, no network or an unparseable reply all fall through to the
3205
+ // free-form prompt below, which is the path that already worked offline.
3206
+ const key = byokKeyForProvider(c, id);
3207
+ const offered = await offeredModelIds(c, id, key);
3208
+
3209
+ // `*` is the bulk path: declare everything the vendor currently serves.
3210
+ // Only the CHAT rows are declared (an embeddings or TTS id in a model
3211
+ // picker is a row nobody can run), and only after the vendor answered —
3212
+ // with no list there is nothing to take all of, and saying so is the
3213
+ // honest outcome rather than an empty success.
3214
+ if (model === '*') {
3215
+ if (!offered) {
3216
+ const why = await discoverProviderModels(c, id, key);
3217
+ c.push({
3218
+ role: 'error',
3219
+ text: `cannot list ${id}: ${(why && why.error) || 'no list available'} — type the ids instead: /model-add ${id} <model-id>`,
3220
+ });
3221
+ return true;
3222
+ }
3223
+ const bulk = addManyUserModels(id, offered);
3224
+ if (typeof c.refreshByokModels === 'function') {
3225
+ try { await c.refreshByokModels(); } catch { /* the next refresh reads the file anyway */ }
3226
+ }
3227
+ c.push({
3228
+ role: 'done',
3229
+ text: `added ${bulk.added} of the ${offered.length} model ids ${id} serves${bulk.already.length ? ` (${bulk.already.length} were already declared)` : ''}.`,
3230
+ });
3231
+ if (bulk.capped) {
3232
+ // The store's per-provider ceiling, named as a ceiling. A vendor list
3233
+ // is a hundred rows; this is one deliberate limit, not sixty broken
3234
+ // ids, and the two must not read the same in the transcript.
3235
+ c.push({
3236
+ role: 'note',
3237
+ text: `stopped at the store's per-provider cap (32) — ${bulk.capped} more id(s) were left out; /model-add ${id} <model-id> stores a specific one, /model-rm frees a slot.`,
3238
+ });
3239
+ }
3240
+ if (bulk.failed.length) {
3241
+ c.push({ role: 'note', text: `${bulk.failed.length} id(s) were refused: ${bulk.failed.map((f) => f.id).join(', ')}` });
3242
+ }
3243
+ c.push({ role: 'note', text: `stored in ${userModelsPath()} — the desktop reads the same file. /model-discover ${id} lists what the vendor serves.` });
3244
+ return true;
3245
+ }
3246
+
3247
+ if (!model) {
3248
+ // Plain inline input, NOT readSecret: a model id is not a secret, and
3249
+ // hiding it would make a typo unreviewable before it is stored.
3250
+ if (offered) {
3251
+ c.push({ role: 'note', text: `${id} serves ${offered.length} model ids — ${offered.slice(0, 12).join(', ')}${offered.length > 12 ? ', …' : ''}` });
3252
+ }
3253
+ const typedId = String((await c.askInput(
3254
+ offered
3255
+ ? `model id for ${id} (1-${offered.length}, or type one): `
3256
+ : `model id for ${id}: `
3257
+ )) || '').trim();
3258
+ // A bare number picks the row it is listed under. Only an in-range
3259
+ // integer is read that way, so an id that happens to start with a digit
3260
+ // is still stored verbatim unless it is exactly a listed position.
3261
+ const n = /^\d+$/.test(typedId) ? Number(typedId) : 0;
3262
+ model = n >= 1 && n <= offered.length ? offered[n - 1] : typedId;
3263
+ }
3264
+ if (!model) {
3265
+ c.push({ role: 'note', text: 'nothing saved.' });
3266
+ return true;
3267
+ }
3268
+ let res;
3269
+ try {
3270
+ res = addUserModel(id, model);
3271
+ } catch (err) {
3272
+ c.push({ role: 'error', text: (err && err.message) || String(err) });
3273
+ return true;
3274
+ }
3275
+ // The picker's cache (app.js `byokCache`, 5 minutes) is older than the
3276
+ // file the instant it is written, so refresh it here: a user who adds a
3277
+ // model and types `/models` must see it, not "already listed" five
3278
+ // minutes later.
3279
+ if (typeof c.refreshByokModels === 'function') {
3280
+ try {
3281
+ await c.refreshByokModels();
3282
+ } catch {
3283
+ /* the next refresh reads the file anyway */
3284
+ }
3285
+ }
3286
+ const rows = (typeof c.listModelsFor === 'function' ? (await c.listModelsFor('byok')) : []) || [];
3287
+ const row = rows.find((m) => m && m.id === `${id}:${model}`);
3288
+ c.push({
3289
+ role: res.added ? 'done' : 'note',
3290
+ text: res.added
3291
+ ? `added ${id}:${model} — offered on this machine now, in the CLI and the desktop.`
3292
+ : `${id}:${model} was already declared.`,
3293
+ });
3294
+ if (!providers) {
3295
+ c.push({
3296
+ role: 'note',
3297
+ text: `the relay's catalog could not be read, so "${id}" is unverified — if it does not appear in /models, /byok lists the provider ids it takes.`,
3298
+ });
3299
+ }
3300
+ if (res.added && !row) {
3301
+ c.push({
3302
+ role: 'note',
3303
+ text: `saved, but no row will be offered for "${id}" yet — the relay lists no provider of that id (or that provider lists no models).`,
3304
+ });
3305
+ }
3306
+ if (res.added && offered) {
3307
+ // The vendor was asked and it lists more than the one id just stored.
3308
+ // Naming the size of that list is the difference between "the picker has
3309
+ // four models" and "this vendor ships forty and you have one of them".
3310
+ c.push({
3311
+ role: 'note',
3312
+ text: `${id} currently serves ${offered.length} model ids — /model-discover ${id} lists them, /model-add ${id} '*' takes them all.`,
3313
+ });
3314
+ }
3315
+ c.push({ role: 'note', text: `stored in ${res.file} — the desktop reads the same file.` });
3316
+ return true;
3317
+ },
3318
+ },
3319
+ {
3320
+ // ── what the vendor serves, right now ─────────────────────────────────
3321
+ //
3322
+ // `/model-add` answers "store THIS id"; this answers "which ids are there",
3323
+ // which is the question a user actually has when a vendor ships something
3324
+ // on a Tuesday. It reads the same key `client/env-file.js` and the provider
3325
+ // CRUD share (saved row first, `~/.aegiscode/.env` second) and hits the
3326
+ // vendor's own list endpoint, so the answer cannot be stale by
3327
+ // construction — that is the whole point of asking instead of shipping
3328
+ // another hand-copied list.
3329
+ //
3330
+ // Offline, keyless and shape-changed are all REPORTED, never thrown: this
3331
+ // command sits beside a manual path that works, so its worst case has to be
3332
+ // a sentence, not a stack trace.
3333
+ name: 'model-discover', aliases: ['discover-models', 'vendor-models'], args: ['provider'], hint: '<provider>',
3334
+ category: 'model',
3335
+ desc: "List the model ids your provider's own API serves",
3336
+ handler: async (c, a) => {
3337
+ const args = a || {};
3338
+ const typed = String(args.provider || '').trim();
3339
+ if (!typed) {
3340
+ c.push({
3341
+ role: 'error',
3342
+ text: `Usage: /model-discover <provider> — this client can ask: ${discoverableProviders().join(', ')}`,
3343
+ });
3344
+ return true;
3345
+ }
3346
+ // Resolve the alias against the relay's catalog when it is reachable, so
3347
+ // `/model-discover xai` and `/model-discover grok` are one request.
3348
+ const providers = await byokCatalog(c.client);
3349
+ const match = providers ? findByokProvider(providers, typed) : null;
3350
+ const id = ((match && match.provider && match.provider.id) || typed).toLowerCase();
3351
+ const entry = vendorEndpointFor(id);
3352
+ if (!entry) {
3353
+ c.push({
3354
+ role: 'error',
3355
+ text: `no list endpoint for "${id}" in this client — /model-add ${id} <model-id> stores an id you already know. Providers it can ask: ${discoverableProviders().join(', ')}`,
3356
+ });
3357
+ return true;
3358
+ }
3359
+ const key = byokKeyForProvider(c, id);
3360
+ if (!key) {
3361
+ c.push({
3362
+ role: 'error',
3363
+ text: `no ${id} key on this machine — /byok-key ${id} saves one (or put it in ~/.aegiscode/.env), then this lists what the key reaches.`,
3364
+ });
3365
+ return true;
3366
+ }
3367
+ const res = await discoverProviderModels(c, id, key);
3368
+ if (!res || !res.ok) {
3369
+ c.push({ role: 'error', text: `could not list ${id}: ${(res && res.error) || 'no answer'}` });
3370
+ return true;
3371
+ }
3372
+ // Where the user stands: which of these are already offered here.
3373
+ const declared = new Set(userModelIdsFor(id));
3374
+ const known = new Set(
3375
+ ((match && match.provider && match.provider.models) || []).map((m) => String(m))
3376
+ );
3377
+ c.push({ role: 'note', text: `${id} at ${entry.url}${entry.note ? ` (${entry.note})` : ''}` });
3378
+ c.push({
3379
+ role: 'note',
3380
+ text: `${res.count} chat model id(s) the vendor serves — mark: [seen] the relay already lists it, [your] you declared it, [new] this machine does not offer it yet.`,
3381
+ });
3382
+ const lines = res.ids.map((m, i) => {
3383
+ const mark = declared.has(m) ? '[your]' : known.has(m) ? '[seen]' : '[new]';
3384
+ return `${String(i + 1).padStart(3)}. ${mark} ${m}`;
3385
+ });
3386
+ if (lines.length) c.push({ role: 'panel', lines });
3387
+ if (!lines.length) {
3388
+ c.push({ role: 'note', text: `the vendor answered with no chat models — /model-add ${id} <model-id> stores one by hand.` });
3389
+ }
3390
+ if (res.others.length) {
3391
+ // Named, not hidden. "the vendor lists 60 and you were shown 12" is a
3392
+ // fact the user is owed; a silent filter is how a picker looks empty
3393
+ // for a reason nobody can see.
3394
+ c.push({
3395
+ role: 'note',
3396
+ text: `${res.others.length} id(s) are not chat models (embeddings, audio, moderation or an unsupported method) and are left out: ${res.others.slice(0, 8).join(', ')}${res.others.length > 8 ? ', …' : ''}`,
3397
+ });
3398
+ }
3399
+ const fresh = res.ids.filter((m) => !declared.has(m) && !known.has(m));
3400
+ if (fresh.length) {
3401
+ c.push({
3402
+ role: 'note',
3403
+ text: `${fresh.length} of them are not offered on this machine yet — /model-add ${id} '<model-id>' stores one, /model-add ${id} '*' stores every chat model the vendor serves.`,
3404
+ });
3405
+ }
3406
+ return true;
3407
+ },
3408
+ },
3409
+ {
3410
+ name: 'model-rm', aliases: ['rm-model'], args: ['provider'], hint: '<provider> <model-id>',
3411
+ category: 'model',
3412
+ desc: 'Forget a model id you added with /model-add',
3413
+ handler: async (c, a) => {
3414
+ const args = a || {};
3415
+ const typed = String(args.provider || '').trim();
3416
+ const rest = String(args._rest || '').trim();
3417
+ const sp = rest.indexOf(' ');
3418
+ const model = sp === -1 ? '' : rest.slice(sp + 1).trim();
3419
+ if (!typed || !model) {
3420
+ c.push({ role: 'error', text: 'Usage: /model-rm <provider> <model-id> — /model-add lists what you added.' });
3421
+ return true;
3422
+ }
3423
+ let res;
3424
+ try {
3425
+ res = removeUserModel(typed, model);
3426
+ } catch (err) {
3427
+ c.push({ role: 'error', text: (err && err.message) || String(err) });
3428
+ return true;
3429
+ }
3430
+ if (typeof c.refreshByokModels === 'function') {
3431
+ try {
3432
+ await c.refreshByokModels();
3433
+ } catch {
3434
+ /* the next refresh reads the file anyway */
3435
+ }
3436
+ }
3437
+ c.push({
3438
+ role: res.removed ? 'done' : 'note',
3439
+ text: res.removed
3440
+ ? `removed ${res.provider}:${res.model} — the picker stops offering it on the next refresh.`
3441
+ : `${res.provider}:${res.model} was not declared on this machine.`,
3442
+ });
3443
+ return true;
3444
+ },
3445
+ },
2963
3446
  {
2964
3447
  name: 'tool', args: ['name', 'json'], hint: '<name> [json]', category: 'aegis',
2965
3448
  desc: 'Call any registry tool directly (escape hatch for new tools)',
package/src/config.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/deps.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/devrun.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/diff.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/diffview.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/engine.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
package/src/events.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**
@@ -405,6 +410,16 @@ function feed(c) {
405
410
  }
406
411
  clearTimeout(escTimer);
407
412
  seq = '';
413
+ // ESC followed by CR is the legacy spelling of shift+Enter, and it is the
414
+ // only spelling some terminals have. Without this it fell through to the
415
+ // generic Alt chord ({name:'alt', ch:'\r'}), which nothing handled — so the
416
+ // chord the palette advertises was dead on exactly the terminals that need
417
+ // it. The kitty/modifyOtherKeys spelling (`CSI 13;2 u`) is decoded in
418
+ // keys.js; both have to land on the same key name.
419
+ if (c === '\r' || c === '\n') {
420
+ dispatch({ name: 'shift-enter' });
421
+ return;
422
+ }
408
423
  dispatch({ name: 'alt', ch: c });
409
424
  return;
410
425
  }
package/src/export.js CHANGED
@@ -1,3 +1,8 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
+ // Conveying a modified copy, or running one as a network service, owes the
5
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
1
6
  'use strict';
2
7
 
3
8
  /**