aegiscode 7.0.25 → 7.0.26

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 (113) hide show
  1. package/package.json +7 -3
  2. package/scripts/check.mjs +52 -1
  3. package/scripts/demo.mjs +94 -1
  4. package/scripts/predist.mjs +75 -1
  5. package/scripts/runtests.mjs +56 -1
  6. package/scripts/seal-gate.mjs +74 -1
  7. package/src/agents.js +139 -1
  8. package/src/app.js +2957 -1
  9. package/src/art.js +289 -1
  10. package/src/chatflow.js +3023 -1
  11. package/src/checkpoint.js +90 -1
  12. package/src/clipboard.js +424 -1
  13. package/src/cloudsync.js +528 -1
  14. package/src/commands.js +4089 -1
  15. package/src/config.js +581 -1
  16. package/src/connect.js +349 -1
  17. package/src/credentials.js +33 -1
  18. package/src/deps.js +232 -1
  19. package/src/devrun.js +187 -1
  20. package/src/diff.js +333 -1
  21. package/src/diffview.js +296 -1
  22. package/src/engine.js +297 -1
  23. package/src/entitlement.js +355 -1
  24. package/src/events.js +707 -1
  25. package/src/export.js +67 -1
  26. package/src/filepreview.js +153 -1
  27. package/src/fingerprint.js +592 -1
  28. package/src/format.js +259 -1
  29. package/src/fuzzy.js +119 -1
  30. package/src/history.js +423 -1
  31. package/src/init.js +175 -1
  32. package/src/input.js +139 -1
  33. package/src/keys.js +183 -1
  34. package/src/markdown.js +306 -1
  35. package/src/models.js +507 -1
  36. package/src/naming.js +57 -1
  37. package/src/overlays.js +462 -1
  38. package/src/panels.js +1418 -1
  39. package/src/ping.js +226 -1
  40. package/src/presence.js +238 -1
  41. package/src/render.js +516 -1
  42. package/src/screen.js +518 -1
  43. package/src/screens.js +896 -1
  44. package/src/secret.js +59 -1
  45. package/src/securefs.js +359 -1
  46. package/src/settings.js +155 -1
  47. package/src/shared.js +52 -1
  48. package/src/sharedpaths.js +53 -1
  49. package/src/signup.js +156 -1
  50. package/src/summarize.js +95 -1
  51. package/src/sysdiag.js +585 -1
  52. package/src/system.js +40 -1
  53. package/src/theme.js +570 -1
  54. package/src/title.js +220 -1
  55. package/src/todos.js +115 -1
  56. package/src/tokens.js +263 -1
  57. package/src/topup.js +210 -1
  58. package/src/update.js +191 -1
  59. package/vendor/client/aegis.js +2441 -1
  60. package/vendor/client/attest.js +518 -1
  61. package/vendor/client/authorship-key.js +410 -1
  62. package/vendor/client/auto-provision.js +134 -1
  63. package/vendor/client/brain-catalog.js +268 -1
  64. package/vendor/client/byok-catalog.js +199 -1
  65. package/vendor/client/catalog-client.js +487 -1
  66. package/vendor/client/conversation-export.js +177 -1
  67. package/vendor/client/credentials.js +494 -1
  68. package/vendor/client/device-fingerprint.js +141 -1
  69. package/vendor/client/drive-connect.js +110 -1
  70. package/vendor/client/drive-upload.js +234 -1
  71. package/vendor/client/env-file.js +1273 -1
  72. package/vendor/client/fingerprint.js +1064 -1
  73. package/vendor/client/foreign-memory.js +669 -1
  74. package/vendor/client/google-signin.js +133 -1
  75. package/vendor/client/hooks.js +430 -1
  76. package/vendor/client/model-discovery.js +373 -1
  77. package/vendor/client/naming.js +283 -1
  78. package/vendor/client/platform.js +937 -1
  79. package/vendor/client/prefs.js +351 -1
  80. package/vendor/client/presence-constants.js +107 -1
  81. package/vendor/client/presence.js +438 -1
  82. package/vendor/client/record-vault.js +1055 -3
  83. package/vendor/client/session-store.js +575 -1
  84. package/vendor/client/topup.js +297 -1
  85. package/vendor/client/touch.js +458 -1
  86. package/vendor/client/update.js +763 -1
  87. package/vendor/client/user-models.js +381 -1
  88. package/vendor/desktop/lib/local/agents.js +105 -1
  89. package/vendor/desktop/lib/local/attachments.js +276 -1
  90. package/vendor/desktop/lib/local/autonomous.js +1045 -1
  91. package/vendor/desktop/lib/local/claude-pro.js +1028 -1
  92. package/vendor/desktop/lib/local/context.js +125 -1
  93. package/vendor/desktop/lib/local/engine.js +3666 -1
  94. package/vendor/desktop/lib/local/entitlement.js +660 -1
  95. package/vendor/desktop/lib/local/git-scope.js +228 -1
  96. package/vendor/desktop/lib/local/local.js +2145 -1
  97. package/vendor/desktop/lib/local/prompt.js +280 -1
  98. package/vendor/desktop/lib/local/queue.js +560 -1
  99. package/vendor/desktop/lib/local/session-rounds.js +238 -1
  100. package/vendor/desktop/lib/local/spill.js +75 -1
  101. package/vendor/desktop/lib/local/turn-guard.js +300 -1
  102. package/vendor/desktop/lib/local/worktree-lock.js +235 -1
  103. package/vendor/desktop/lib/settings.js +890 -1
  104. package/vendor/desktop/renderer/usage.js +1239 -1
  105. package/vendor/hosts/install.js +638 -1
  106. package/vendor/hosts/openai-shim.js +515 -1
  107. package/vendor/hosts/spec.js +164 -1
  108. package/vendor/hosts/targets.js +346 -1
  109. package/vendor/mcp/server.js +221 -1
  110. package/vendor/mcp/tools.js +408 -1
  111. package/vendor/one/src/child.js +285 -1
  112. package/vendor/one/src/permissions.js +383 -1
  113. package/SOURCE-OFFER.txt +0 -9
package/src/models.js CHANGED
@@ -1,3 +1,509 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const path=require("node:path"),{resolveShared:resolveShared}=require("./sharedpaths.js"),{offerableCatalog:offerableCatalog}=require(resolveShared(path.join("client","brain-catalog.js"))),envFile=require(resolveShared(path.join("client","env-file.js"))),claudePro=require(resolveShared(path.join("desktop","lib","local","claude-pro.js")));function claudeProLoggedIn(){try{return!!claudePro.claudeProStatus({env:process.env}).loggedIn}catch{return!1}}const NO_PIN=null,ID_NOTES=Object.freeze({"openai-gpt4o-mini":"OpenAI gpt-4o-mini, pooled","anthropic-haiku":"Anthropic Haiku, pooled","nexus-brain":"pooled brain · multi-call fan-out, sized by /effort"});function normalizeModel(e){const o="string"==typeof e?{id:e}:e;if(!o||"object"!=typeof o)return null;const r="string"==typeof o.id?o.id.trim():"";if(!r)return null;const n="string"==typeof o.alias_of&&o.alias_of.trim()?o.alias_of.trim():null,i=Array.isArray(o.capabilities)?o.capabilities.filter((e=>"string"==typeof e&&e)):[],t={id:r,label:"string"==typeof o.label&&o.label.trim()||"string"==typeof o.name&&o.name.trim()||r,note:("string"==typeof o.note&&o.note.trim()?o.note.trim():"")||(n?`alias of ${n}`:ID_NOTES[r]||i.join(", ")),hidden:!0===o.hidden,aliasOf:n,capabilities:i};return"string"==typeof o.provider&&o.provider.trim()&&(t.provider=o.provider.trim()),!0===o.configured&&(t.configured=!0),"string"==typeof o.cls&&o.cls.trim()&&(t.cls=o.cls.trim()),t}function normalizeModelCatalog(e){const o=Array.isArray(e)?e:Array.isArray(e&&e.models)?e.models:[],r=[],n=new Set;for(const e of o){const o=normalizeModel(e);o&&!n.has(o.id)&&(n.add(o.id),r.push(o))}return r}function pickerEntries(e){const o=Array.isArray(e)?e.filter(Boolean):[],r=offerableCatalog(o).map(normalizeModel).filter(Boolean);if(r.length)return r;const n=o.filter((e=>!e.aliasOf));return n.length?n:o}function findModel(e,o){const r="string"==typeof o?o.trim():"";return r&&(Array.isArray(e)?e:[]).find((e=>e&&e.id===r))||null}function catalogIds(e){return new Set((Array.isArray(e)?e:[]).map((e=>String(e&&e.id||"").toLowerCase())).filter(Boolean))}function modelKeyPlan(e,o={}){const r=e&&e.id||"",n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return{needed:!1,env:"",provider:"",pooled:n.pooled,status:null,why:"this id has no key variable"};if(n.foreign){const e=!!envFile.resolveForeignSecret(n.env)||claudeProLoggedIn();return{needed:!e,env:n.env,provider:"",pooled:!1,status:{present:e,inFile:e,source:e?"file":"none"},why:e?`${n.env} is already set aside for Claude Code Pro`:`no ${n.env} is set aside for Claude Code Pro`}}const i=envFile.keyStatus(n.env);if(n.pooled){const e=!i.present&&!o.accountConfigured;return{needed:e,env:n.env,provider:"",pooled:!0,status:i,why:e?`no ${n.env} is set on this machine`:`account key present (${o.accountConfigured&&!i.present?"credentials.json":i.source})`}}const t=!i.inFile&&!o.hasStored;return{needed:t,env:n.env,provider:n.provider,pooled:!1,status:i,why:t?`no ${n.env} is stored for provider "${n.provider}"`:`${n.env} is already stored (${i.inFile?i.source:"provider store"})`}}function modelKeyQueue(e,o={}){const r=e&&e.id||"";if(!String(r).trim())return[];const n=envFile.keyForModelId(r,e&&e.cls);if(!n.env)return[];if(n.foreign)return envFile.resolveForeignSecret(n.env)||claudeProLoggedIn()?[]:[{env:n.env,provider:"",vendor:"",role:"claude-pro",needed:!0,status:{present:!1},why:`no ${n.env} is set aside for Claude Code Pro`}];const i=[],t=envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);t.present||o.accountConfigured||i.push({env:envFile.ACCOUNT_ENV_VAR,provider:"",vendor:"",role:"account",needed:!0,status:t,why:`no ${envFile.ACCOUNT_ENV_VAR} is set on this machine`});const l=n.vendor||"",d=l?envFile.envVarFor(l):"",s=!(!l||"function"!=typeof o.hasStoredFor||!o.hasStoredFor(l));if(d){const e=envFile.keyStatus(d);e.inFile||s||i.push({env:d,provider:l,vendor:l,role:"provider",needed:!0,status:e,why:e.present?`${d} is exported in this shell only — the desktop cannot see it`:`no ${d} is stored for provider "${l}"`})}return i}function storeModelKey(e,o,r={}){const n=envFile.keyForModelId(e&&e.id,e&&e.cls),i=String(r.env||"").trim()||n.env;if(!i)return{ok:!1,file:"",changed:!1,error:`cannot name a key variable for "${e&&e.id||""}"`,env:"",provider:"",pooled:n.pooled};const t={...r};delete t.env;const l=n.foreign?envFile.setForeignSecret(i,o,t):envFile.setEnvValue(i,o,t),d=!n.foreign&&i===envFile.ACCOUNT_ENV_VAR;return{...l,env:i,provider:i===n.env?n.provider:"",pooled:d,foreign:!!n.foreign}}function keyVarForModel(e){return envFile.keyForModelId(e&&e.id,e&&e.cls).env}function providerForModel(e){const o=String(e&&e.id||"").trim();return o&&(envFile.keyForModelId(o,e&&e.cls).provider||envFile.providerForModelId(o,e&&e.cls))||""}module.exports={NO_PIN:null,ID_NOTES:ID_NOTES,normalizeModel:normalizeModel,normalizeModelCatalog:normalizeModelCatalog,pickerEntries:pickerEntries,findModel:findModel,catalogIds:catalogIds,modelKeyPlan:modelKeyPlan,modelKeyQueue:modelKeyQueue,storeModelKey:storeModelKey,keyVarForModel:keyVarForModel,providerForModel:providerForModel,claudeProLoggedIn:claudeProLoggedIn};
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.
6
+ 'use strict';
7
+
8
+ /**
9
+ * AEGIS Cloud model catalog shaping — the one place `/model`, the alt+p picker
10
+ * and `/models` agree on what a pinnable model is.
11
+ *
12
+ * The ids a user may pin are the *server's*, never ours: the pool adds, renames
13
+ * and retires providers without a client release, so the catalog is fetched
14
+ * (`client.listModels()` → GET /api/v1/models on aegiscloud.org) and this module
15
+ * only normalises the payload. It deliberately invents no id, and has no
16
+ * fallback list: an offline client offers nothing rather than a model name that
17
+ * would silently route somewhere else.
18
+ *
19
+ * WHAT IS OFFERED on the AEGIS (pooled) class is the server's FULL catalog: the
20
+ * brain first, under its one name (Nexus), then every other model the account
21
+ * can pin.
22
+ *
23
+ * The single-Nexus-row collapse was shipped here and is now reverted, because
24
+ * the report it produced is exactly the defect that shape creates: "there are
25
+ * only 2 models left in models" — one version back the picker listed them all.
26
+ * Removing the choice was never the fix for the two hosts disagreeing about the
27
+ * brain's five spellings; `offerableCatalog` ends that disagreement by folding
28
+ * only the *aliases*, which is what this module now calls. A funded account can
29
+ * pin the deepseek or anthropic model it actually pays for instead of having
30
+ * one chosen for it, while `nexus-brain` still paints as one row and not five.
31
+ *
32
+ * The rule lives in `client/brain-catalog.js`, shared with the desktop through
33
+ * the same `resolveShared` path, so the two hosts cannot drift — that one-copy
34
+ * guarantee is the part of the earlier change that stays.
35
+ *
36
+ * A payload with no brain tier at all (the BYOK listing, which is per-provider
37
+ * models) never had a brain row to collapse, and stays offered in full: BYOK is
38
+ * unaffected by this — see `offerableCatalog`'s own doc for the alias-only case.
39
+ *
40
+ * Offering is still not the same as accepting: `/model deepseek` still
41
+ * validates against the full catalog through `findModel`/`catalogIds`, so a
42
+ * scripted pin is not refused — only the interactive picker is narrowed.
43
+ */
44
+
45
+ const path = require('node:path');
46
+
47
+ const { resolveShared } = require('./sharedpaths.js');
48
+
49
+ /**
50
+ * The shared selection rule — required at load time and by EXISTENCE, never
51
+ * with a fallback copy here: a silently divergent local implementation is the
52
+ * precise defect this file was changed to remove. A missing module is a loud
53
+ * error naming the file, which is what `resolveShared` throws.
54
+ */
55
+ const { offerableCatalog } = require(resolveShared(path.join('client', 'brain-catalog.js')));
56
+
57
+ /**
58
+ * The shared env-file module, required through the same `resolveShared` path the
59
+ * desktop uses, for the same reason: the file the key is WRITTEN to must be the
60
+ * file both hosts READ from, and a second implementation of "where does a key
61
+ * go" is exactly how the CLI and the desktop ended up each holding a private
62
+ * copy of the same provider key.
63
+ */
64
+ const envFile = require(resolveShared(path.join('client', 'env-file.js')));
65
+
66
+ /**
67
+ * The Claude Code Pro transport, required the same way — so the 'pro' class's
68
+ * OWN foreign-secret check (below) can ask the same question `engine.js`'s
69
+ * `listModels('pro')` already answers for the row's `configured` flag:
70
+ * `claudeProStatus().loggedIn`, not only "is a token set aside in
71
+ * secrets.env". Without this, a machine signed in through the ordinary
72
+ * `claude login` flow (credentials.json, no `claude setup-token` ever run)
73
+ * reads as unconfigured here while the picker paints the same row
74
+ * `configured: true` — the picker says "ready", `/model` prompts for a token
75
+ * anyway.
76
+ */
77
+ const claudePro = require(resolveShared(path.join('desktop', 'lib', 'local', 'claude-pro.js')));
78
+
79
+ /** Whether this machine is already signed into Claude Code Pro/Max, any way
80
+ * `claudeProStatus` recognizes (credentials.json OAuth or API-key form, or
81
+ * `CLAUDE_CODE_OAUTH_TOKEN` already in the environment) — broader than the
82
+ * foreign-secret file alone, and the same check the picker's `configured`
83
+ * flag is built from. */
84
+ function claudeProLoggedIn() {
85
+ try {
86
+ return !!claudePro.claudeProStatus({ env: process.env }).loggedIn;
87
+ } catch {
88
+ return false;
89
+ }
90
+ }
91
+
92
+ /** A pinned id of `null` means "no pin — let the pool choose" (the server's own default). */
93
+ const NO_PIN = null;
94
+
95
+ /**
96
+ * Labels for catalog ids the platform advertises without capabilities or a
97
+ * label of their own — `openai-gpt4o-mini` reads like a typo next to `openai`,
98
+ * and the brain tier is the one id whose *cost shape* a user needs before
99
+ * pinning it: verified live 2026-09-14, `model: "nexus-brain"` streams
100
+ * `pool-brain: 3 workers · effort=high · tier=brain · passes=4`, i.e. four
101
+ * billed provider calls per turn, where a provider id is one. That count is
102
+ * not fixed — the endpoint sizes the fan-out from the ask and the /effort rung
103
+ * (aegis1 services/pool_brain.py estimate_workers + EFFORT_MAX_WORKERS), so the
104
+ * label states the shape (fan-out, sized by effort) rather than a number that
105
+ * only held for one prompt.
106
+ */
107
+ const ID_NOTES = Object.freeze({
108
+ 'openai-gpt4o-mini': 'OpenAI gpt-4o-mini, pooled',
109
+ 'anthropic-haiku': 'Anthropic Haiku, pooled',
110
+ 'nexus-brain': 'pooled brain · multi-call fan-out, sized by /effort',
111
+ });
112
+
113
+ /** One raw entry (string id or object) → a catalog entry, or null when unusable. */
114
+ function normalizeModel(entry) {
115
+ const m = typeof entry === 'string' ? { id: entry } : entry;
116
+ if (!m || typeof m !== 'object') return null;
117
+ const id = typeof m.id === 'string' ? m.id.trim() : '';
118
+ if (!id) return null;
119
+ const aliasOf =
120
+ typeof m.alias_of === 'string' && m.alias_of.trim() ? m.alias_of.trim() : null;
121
+ const capabilities = Array.isArray(m.capabilities)
122
+ ? m.capabilities.filter((c) => typeof c === 'string' && c)
123
+ : [];
124
+ const label =
125
+ (typeof m.label === 'string' && m.label.trim()) ||
126
+ (typeof m.name === 'string' && m.name.trim()) ||
127
+ id;
128
+ // The picker's right-hand column: what this entry *is*. An alias says so —
129
+ // otherwise a user reads five brain tiers and assumes five different models.
130
+ //
131
+ // A CALLER's own note wins over the derived one, and that precedence is the
132
+ // fix for a real defect: `app.js` builds the BYOK rows with the note the
133
+ // renderers paint ('key on this machine' / 'no key — /byok-key openai') and
134
+ // then passes them through `pickerEntries` → here, which used to re-derive the
135
+ // note from `capabilities` — empty for a byok row — so every row's note became
136
+ // blank and the picker could not say which providers this machine is ready to
137
+ // call. A note someone deliberately set is information; the derived string is
138
+ // a default, and a default must never overwrite it.
139
+ const given = typeof m.note === 'string' && m.note.trim() ? m.note.trim() : '';
140
+ const note = given || (aliasOf ? `alias of ${aliasOf}` : ID_NOTES[id] || capabilities.join(', '));
141
+ const out = {
142
+ id,
143
+ label,
144
+ note,
145
+ hidden: m.hidden === true,
146
+ aliasOf,
147
+ capabilities,
148
+ };
149
+ // Pass-through fields this module does not own but must not eat. They are the
150
+ // byok half of the list's whole content:
151
+ // - `provider` — which provider's key the relay will ask for (`collectKeyFor`
152
+ // read it, and `/byok-key` addresses the row by it);
153
+ // - `configured` — whether that key is on this machine, which is what paints
154
+ // the `[key needed]` flag and what tells a user whether a pick will work;
155
+ // - `cls` — the class the row belongs to, which ENTER switches on.
156
+ // Dropping them (as this did) meant `m.configured` was `undefined` for every
157
+ // row, so the flag fired on rows that were fully configured and the list could
158
+ // not distinguish "ready" from "needs a key".
159
+ if (typeof m.provider === 'string' && m.provider.trim()) out.provider = m.provider.trim();
160
+ if (m.configured === true) out.configured = true;
161
+ if (typeof m.cls === 'string' && m.cls.trim()) out.cls = m.cls.trim();
162
+ return out;
163
+ }
164
+
165
+ /** Normalise a raw `/api/v1/models` payload (`{models: [...]}` or the array). */
166
+ function normalizeModelCatalog(raw) {
167
+ const list = Array.isArray(raw) ? raw : Array.isArray(raw && raw.models) ? raw.models : [];
168
+ const out = [];
169
+ const seen = new Set();
170
+ for (const entry of list) {
171
+ const m = normalizeModel(entry);
172
+ if (!m || seen.has(m.id)) continue;
173
+ seen.add(m.id);
174
+ out.push(m);
175
+ }
176
+ return out;
177
+ }
178
+
179
+ /**
180
+ * The entries the picker and `/models` offer.
181
+ *
182
+ * The selection itself is not decided here — it is `offerableCatalog` in
183
+ * `client/brain-catalog.js`, which the desktop requires through the same
184
+ * `resolveShared` path (and its own staged `vendor/` copy). Two hosts, one
185
+ * function: that is the part that must not be re-implemented, and the reason
186
+ * this is a thin call rather than a second copy of the rule.
187
+ *
188
+ * `offerableCatalog` offers every id the payload advertises, with the brain's
189
+ * spellings folded into the one row labelled Nexus and listed first — so a
190
+ * catalog naming a brain tier no longer collapses to that row alone. The
191
+ * fallback below still covers a payload whose entries survive as bare strings
192
+ * or as aliases the shared rule dropped: an empty picker would tell the user
193
+ * there are no models when the server just named them, so a list of aliases is
194
+ * a better answer than nothing.
195
+ *
196
+ * Re-normalised afterwards so renderers keep the `label`/`note`/`id` columns
197
+ * they already expect, and so the brain's cost shape still reaches the picker's
198
+ * right-hand column.
199
+ */
200
+ function pickerEntries(catalog) {
201
+ const all = Array.isArray(catalog) ? catalog.filter(Boolean) : [];
202
+ const offered = offerableCatalog(all).map(normalizeModel).filter(Boolean);
203
+ if (offered.length) return offered;
204
+ const distinct = all.filter((m) => !m.aliasOf);
205
+ return distinct.length ? distinct : all;
206
+ }
207
+
208
+ /** The catalog entry for `id`, or null — the "is this a real id?" question. */
209
+ function findModel(catalog, id) {
210
+ const want = typeof id === 'string' ? id.trim() : '';
211
+ if (!want) return null;
212
+ return (Array.isArray(catalog) ? catalog : []).find((m) => m && m.id === want) || null;
213
+ }
214
+
215
+ /**
216
+ * The set of ids the server accepts, lower-cased: a catalog id and a pinned id
217
+ * are the same thing only when they match byte-for-byte, but `/model Nexus-Brain`
218
+ * is a typo a user will make and the server's routing is case-insensitive
219
+ * enough that warning about it would be noise.
220
+ */
221
+ function catalogIds(catalog) {
222
+ return new Set((Array.isArray(catalog) ? catalog : []).map((m) => String((m && m.id) || '').toLowerCase()).filter(Boolean));
223
+ }
224
+
225
+ /**
226
+ * What key a catalog entry needs, and whether a DURABLE copy already exists —
227
+ * the question the model picker asks before it may send a turn on that id.
228
+ *
229
+ * Picking a model is the moment the answer matters: the turn goes out
230
+ * immediately, so a missing key has to be collected HERE, and stored where both
231
+ * hosts look (`~/.aegiscode/.env`), or the user types the same key twice — once
232
+ * in the terminal and once in the desktop — which is the defect this exists to
233
+ * end.
234
+ *
235
+ * `keyStatus().inFile` is the half that decides it, not `.present`. A key
236
+ * exported in the shell belongs to the process that launched this host: it is
237
+ * gone next session and invisible to the desktop, so "present" is not "stored".
238
+ *
239
+ * Two classes are exempt, and neither exemption is a heuristic:
240
+ *
241
+ * - the POOLED class, when the account is already signed in. Its credential is
242
+ * the AEGIS account key, which `aegiscode login` also keeps in
243
+ * credentials.json (client/credentials.js resolves that FIRST), a file both
244
+ * hosts share. Prompting for it on every pooled pick would be asking for a
245
+ * key the machine demonstrably has, so `accountConfigured` short-circuits.
246
+ * - a BYOK provider whose key is already in the provider store
247
+ * (`byok:<provider>`, engine.js byokNamespace — the rows the desktop's
248
+ * Provider settings write), passed in as `hasStored`.
249
+ *
250
+ * @param {object} entry a picker row ({id, cls})
251
+ * @param {object} [o]
252
+ * @param {boolean} [o.accountConfigured] the account key resolves somewhere
253
+ * @param {boolean} [o.hasStored] the provider key is already in the store
254
+ * @returns {{needed:boolean, env:string, provider:string, pooled:boolean,
255
+ * status:object|null, why:string}}
256
+ */
257
+ function modelKeyPlan(entry, o = {}) {
258
+ const id = (entry && entry.id) || '';
259
+ const plan = envFile.keyForModelId(id, entry && entry.cls);
260
+ if (!plan.env) {
261
+ // No id, no key to ask for. Never prompt on a row we cannot name a variable
262
+ // for — an unanswerable prompt is worse than a turn that 400s with the id.
263
+ return { needed: false, env: '', provider: '', pooled: plan.pooled, status: null, why: 'this id has no key variable' };
264
+ }
265
+ if (plan.foreign) {
266
+ // Claude Code Pro: the credential lives in secrets.env (or an unmigrated
267
+ // .env line, or a real shell export), never in process.env at large — so
268
+ // `keyStatus` (which reads `.env`/process.env only) cannot answer this one;
269
+ // `resolveForeignSecret` is the function built to check every place it
270
+ // might actually be. See client/env-file.js keyForModelId.
271
+ //
272
+ // That alone is a narrower question than "is this machine signed in,
273
+ // though" — a plain `claude login` writes credentials.json and never
274
+ // touches secrets.env, so `claudeProLoggedIn()` is checked too; it is the
275
+ // same source `engine.js listModels('pro')` already paints the row's own
276
+ // `configured` flag from, so the two cannot disagree about one row.
277
+ const present = !!envFile.resolveForeignSecret(plan.env) || claudeProLoggedIn();
278
+ return {
279
+ needed: !present,
280
+ env: plan.env,
281
+ provider: '',
282
+ pooled: false,
283
+ status: { present, inFile: present, source: present ? 'file' : 'none' },
284
+ why: present
285
+ ? `${plan.env} is already set aside for Claude Code Pro`
286
+ : `no ${plan.env} is set aside for Claude Code Pro`,
287
+ };
288
+ }
289
+ const status = envFile.keyStatus(plan.env);
290
+ if (plan.pooled) {
291
+ const needed = !status.present && !o.accountConfigured;
292
+ return {
293
+ needed,
294
+ env: plan.env,
295
+ provider: '',
296
+ pooled: true,
297
+ status,
298
+ why: needed
299
+ ? `no ${plan.env} is set on this machine`
300
+ : `account key present (${o.accountConfigured && !status.present ? 'credentials.json' : status.source})`,
301
+ };
302
+ }
303
+ const needed = !status.inFile && !o.hasStored;
304
+ return {
305
+ needed,
306
+ env: plan.env,
307
+ provider: plan.provider,
308
+ pooled: false,
309
+ status,
310
+ why: needed
311
+ ? `no ${plan.env} is stored for provider "${plan.provider}"`
312
+ : `${plan.env} is already stored (${!status.inFile ? 'provider store' : status.source})`,
313
+ };
314
+ }
315
+
316
+ /**
317
+ * EVERY key a just-picked model needs, in the order to ask for them.
318
+ *
319
+ * `modelKeyPlan` answers with the one credential the ROUTE needs and stops
320
+ * there. That is the wrong answer at the picker, and it is the defect the report
321
+ * "I picked deepseek and it still failed" names: a pooled row named after a
322
+ * vendor is billed to the AEGIS account, so the route's credential is
323
+ * `AEGIS_API_KEY` — but the pool calls `deepseek` with a provider key, and when
324
+ * this machine holds none, the turn fails at the pool with nothing the user can
325
+ * act on. One prompt was not enough, and the missing one was never offered.
326
+ *
327
+ * So the order is fixed and it is the order the two keys are actually needed in:
328
+ *
329
+ * 1. `AEGIS_API_KEY` — the account key. Nothing works without it: it is what
330
+ * authenticates the catalog read that listed the row at all, and it is the
331
+ * pooled route's identity. Asked first, and asked on every class, because
332
+ * a byok listing cannot be read without it either.
333
+ * 2. the VENDOR key for the row (`DEEPSEEK_API_KEY` for `deepseek` or
334
+ * `deepseek:…`) — what actually calls the model. Asked second, and only
335
+ * when the row names a vendor `client/env-file.js` knows a variable for:
336
+ * `nexus-brain` names none, so it produces no second step rather than an
337
+ * invented `NEXUS_API_KEY`.
338
+ *
339
+ * A step is emitted only when its key is genuinely MISSING on this machine —
340
+ * `keyStatus().inFile` for a durable copy, plus the caller's `accountConfigured`
341
+ * / `hasStoredFor` for the two stores that are not the env file
342
+ * (`credentials.json` for the account, `byok:<provider>` rows for a vendor, both
343
+ * written by the other host). An empty array means "nothing to ask for", which
344
+ * is the common case and must stay silent.
345
+ *
346
+ * @param {object} entry a picker row ({id, cls, provider?})
347
+ * @param {object} [o]
348
+ * @param {boolean} [o.accountConfigured] the account key resolves somewhere
349
+ * @param {(vendor:string)=>boolean} [o.hasStoredFor] that vendor's key is in
350
+ * the provider store
351
+ * @returns {Array<{env:string, provider:string, vendor:string, role:string,
352
+ * needed:boolean, status:object|null, why:string}>} in ask order
353
+ */
354
+ function modelKeyQueue(entry, o = {}) {
355
+ const id = (entry && entry.id) || '';
356
+ // No id at all: there is no row to make callable, so there is nothing to ask
357
+ // for. Checked on the ID and not on `plan.env`, because an empty id still
358
+ // derives a perfectly nameable variable (the account key) — the pooled branch
359
+ // of `keyForModelId` ignores the id — and prompting for the account key off a
360
+ // row that names no model is exactly the unanswerable prompt this refuses.
361
+ if (!String(id).trim()) return [];
362
+ const plan = envFile.keyForModelId(id, entry && entry.cls);
363
+ // A non-empty id that yields no variable cannot be asked about either: an
364
+ // unanswerable prompt is worse than a turn that 400s with the id in it.
365
+ if (!plan.env) return [];
366
+
367
+ if (plan.foreign) {
368
+ // Claude Code Pro bills nobody through AEGIS and calls no vendor API, so
369
+ // neither the account key nor a vendor key belongs in this queue — the
370
+ // ONE credential this route needs is the subscription's own OAuth token.
371
+ // There is no dedicated command for it (no `/byok-key` equivalent): it is
372
+ // asked for here, the same place every other row's key is asked for.
373
+ //
374
+ // `claudeProLoggedIn()` catches the plain `claude login` case the bare
375
+ // secrets.env check misses — see the matching note in `modelKeyPlan`.
376
+ if (envFile.resolveForeignSecret(plan.env) || claudeProLoggedIn()) return [];
377
+ return [{
378
+ env: plan.env,
379
+ provider: '',
380
+ vendor: '',
381
+ role: 'claude-pro',
382
+ needed: true,
383
+ status: { present: false },
384
+ why: `no ${plan.env} is set aside for Claude Code Pro`,
385
+ }];
386
+ }
387
+
388
+ const steps = [];
389
+ const account = envFile.keyStatus(envFile.ACCOUNT_ENV_VAR);
390
+ if (!account.present && !o.accountConfigured) {
391
+ steps.push({
392
+ env: envFile.ACCOUNT_ENV_VAR,
393
+ provider: '',
394
+ vendor: '',
395
+ role: 'account',
396
+ needed: true,
397
+ status: account,
398
+ why: `no ${envFile.ACCOUNT_ENV_VAR} is set on this machine`,
399
+ });
400
+ }
401
+
402
+ // The vendor the row names. For byok that is the id's own `<provider>` half;
403
+ // for a pooled id it is the vendor spelled into the id (`deepseek`), and it is
404
+ // the same variable either way — one key, one file, whichever class reads it.
405
+ const vendor = plan.vendor || '';
406
+ const vendorEnv = vendor ? envFile.envVarFor(vendor) : '';
407
+ const stored = vendor && typeof o.hasStoredFor === 'function' ? !!o.hasStoredFor(vendor) : false;
408
+ if (vendorEnv) {
409
+ const status = envFile.keyStatus(vendorEnv);
410
+ // `inFile` rather than `present` for the same reason as modelKeyPlan: a
411
+ // shell export belongs to this process, and the desktop — the other host
412
+ // that has to make this call — cannot see it. The provider store counts as
413
+ // stored (`hasStoredFor`), because that is the row the desktop writes.
414
+ if (!status.inFile && !stored) {
415
+ steps.push({
416
+ env: vendorEnv,
417
+ provider: vendor,
418
+ vendor,
419
+ role: 'provider',
420
+ needed: true,
421
+ status,
422
+ why: status.present
423
+ ? `${vendorEnv} is exported in this shell only — the desktop cannot see it`
424
+ : `no ${vendorEnv} is stored for provider "${vendor}"`,
425
+ });
426
+ }
427
+ }
428
+ return steps;
429
+ }
430
+
431
+ /**
432
+ * Store a key collected at the picker, in the one file every host reads.
433
+ *
434
+ * Returns `setEnvValue`'s result plus the resolved variable name, so a caller
435
+ * can report WHERE the key went without re-deriving it (and re-deriving it is
436
+ * how the two hosts would end up disagreeing about the name).
437
+ *
438
+ * `o.env` overrides the derived variable, and it is how a QUEUE step is stored:
439
+ * a pooled row has two keys (the account's and the vendor's), so the row alone
440
+ * cannot say which one this value is for — the step can. Without it the
441
+ * derivation is `keyForModelId`, which is the right answer for a single-key
442
+ * caller and unchanged.
443
+ *
444
+ * @param {object} entry the row the key was collected for
445
+ * @param {string} key the secret
446
+ * @param {object} [o] `setEnvValue` options; `env` names the variable to write
447
+ * @returns {{ok:boolean, file:string, changed:boolean, error:string,
448
+ * env:string, provider:string, pooled:boolean}}
449
+ */
450
+ function storeModelKey(entry, key, o = {}) {
451
+ const plan = envFile.keyForModelId(entry && entry.id, entry && entry.cls);
452
+ const env = String(o.env || '').trim() || plan.env;
453
+ if (!env) {
454
+ return { ok: false, file: '', changed: false, error: `cannot name a key variable for "${(entry && entry.id) || ''}"`, env: '', provider: '', pooled: plan.pooled };
455
+ }
456
+ const opts = { ...o };
457
+ delete opts.env;
458
+ // A foreign name (CLAUDE_CODE_OAUTH_TOKEN) goes to secrets.env, never .env —
459
+ // setEnvValue refuses it outright (client/env-file.js FOREIGN_SECRET_NAMES),
460
+ // and writing it there would be the exact ambient exposure the split ends.
461
+ const res = plan.foreign ? envFile.setForeignSecret(env, key, opts) : envFile.setEnvValue(env, key, opts);
462
+ // `pooled` describes the VARIABLE that was written, not the class of the row:
463
+ // the account key is the pooled route's credential wherever it is stored,
464
+ // while a vendor key written for a pooled row is still the user's own vendor
465
+ // key. Reading it off the row (as this once did) reported DEEPSEEK_API_KEY as
466
+ // pooled, which told the caller the pool held a key the user had just supplied.
467
+ const pooled = !plan.foreign && env === envFile.ACCOUNT_ENV_VAR;
468
+ return { ...res, env, provider: env === plan.env ? plan.provider : '', pooled, foreign: !!plan.foreign };
469
+ }
470
+
471
+ /** The env var name a key for `entry` belongs in ('' when there is none). */
472
+ function keyVarForModel(entry) {
473
+ return envFile.keyForModelId(entry && entry.id, entry && entry.cls).env;
474
+ }
475
+
476
+ /**
477
+ * The PROVIDER a model id names, for a caller that has only the id.
478
+ *
479
+ * Two namespaces answer this question and they are not the same one: a `byok:`
480
+ * id carries its vendor as a prefix (`deepseek:deepseek-v4-flash`), while a
481
+ * pooled id names the vendor in its spelling (`deepseek-flash`). `keyForModelId`
482
+ * reports the first as `provider` and the second as `vendor`, so reading only
483
+ * one of them reported a provider for BYOK rows and '' for every pooled one —
484
+ * which is most rows. Falls back to the vendor derivation so the answer is "the
485
+ * provider this turn ran on" either way, and '' when the id names none (the
486
+ * pool's own `nexus-*` ids), because an invented provider is not evidence.
487
+ */
488
+ function providerForModel(entry) {
489
+ const id = String((entry && entry.id) || '').trim();
490
+ if (!id) return '';
491
+ const plan = envFile.keyForModelId(id, entry && entry.cls);
492
+ return plan.provider || envFile.providerForModelId(id, entry && entry.cls) || '';
493
+ }
494
+
495
+ module.exports = {
496
+ NO_PIN,
497
+ ID_NOTES,
498
+ normalizeModel,
499
+ normalizeModelCatalog,
500
+ pickerEntries,
501
+ findModel,
502
+ catalogIds,
503
+ modelKeyPlan,
504
+ modelKeyQueue,
505
+ storeModelKey,
506
+ keyVarForModel,
507
+ providerForModel,
508
+ claudeProLoggedIn,
509
+ };
package/src/naming.js CHANGED
@@ -1,3 +1,59 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const fs=require("node:fs"),path=require("node:path"),CANDIDATES=[path.join(__dirname,"..","..","client","naming.js"),path.join(__dirname,"..","vendor","client","naming.js"),path.join(__dirname,"..","vendor","naming.js")];let resolved=null;for(const e of CANDIDATES)if(fs.existsSync(e)){resolved=e;break}if(!resolved)throw new Error("aegiscode: cannot find client/naming.js. Expected it beside cli/ (in the repo) or under cli/vendor/ (installed package). Reinstall the package, or run `node scripts/predist.mjs` from cli/ if this is a source checkout.");module.exports=require(resolved);
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.
6
+ 'use strict';
7
+
8
+ /**
9
+ * The naming ladder — now shared with the desktop face.
10
+ *
11
+ * This file carried the rules (GENERIC_TITLE, isTopicless, looksLikeEcho,
12
+ * deriveTitle, refineTitle) and the window had none of them: it named a thread
13
+ * `prompt.slice(0, 60)`, so the same conversation was "Fix the desktop
14
+ * binaries" in a terminal and "can you fix the binaries for aegis-desktop. why
15
+ * is old" in the sidebar.
16
+ *
17
+ * Rather than teach the window a second copy of these rules — which is how the
18
+ * two hosts drift apart again — the implementation moved to
19
+ * `client/naming.js`, the shared tree both faces already stage. This module
20
+ * stays as the CLI's name for it so `app.js`, `chatflow.js` and
21
+ * `test/cli-naming.test.mjs` keep their imports, and so there is exactly one
22
+ * place the ladder can be edited.
23
+ *
24
+ * Two layouts must work, exactly as `sharedpaths.js` documents:
25
+ *
26
+ * in-repo <repo>/cli/src/naming.js -> <repo>/client/naming.js
27
+ * npm <pkg>/src/naming.js -> <pkg>/vendor/client/naming.js
28
+ *
29
+ * Resolution is by existence, and a missing module is a loud error rather than
30
+ * a silent fallback to a second copy — the same rule every shared module here
31
+ * follows, because duplicate implementations are how the desktop and the
32
+ * terminal drift apart.
33
+ */
34
+
35
+ const fs = require('node:fs');
36
+ const path = require('node:path');
37
+
38
+ const CANDIDATES = [
39
+ path.join(__dirname, '..', '..', 'client', 'naming.js'), // in-repo layout
40
+ path.join(__dirname, '..', 'vendor', 'client', 'naming.js'), // npm layout (mirror)
41
+ path.join(__dirname, '..', 'vendor', 'naming.js'), // npm layout (flat)
42
+ ];
43
+
44
+ let resolved = null;
45
+ for (const candidate of CANDIDATES) {
46
+ if (fs.existsSync(candidate)) {
47
+ resolved = candidate;
48
+ break;
49
+ }
50
+ }
51
+ if (!resolved) {
52
+ throw new Error(
53
+ 'aegiscode: cannot find client/naming.js. Expected it beside cli/ (in the repo) or ' +
54
+ 'under cli/vendor/ (installed package). Reinstall the package, or run ' +
55
+ '`node scripts/predist.mjs` from cli/ if this is a source checkout.'
56
+ );
57
+ }
58
+
59
+ module.exports = require(resolved);