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
@@ -0,0 +1,383 @@
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.
6
+ 'use strict';
7
+
8
+ /**
9
+ * user-models.js — the models the USER declares, in one file every host reads.
10
+ *
11
+ * ── the problem this module removes ────────────────────────────────────────
12
+ *
13
+ * `client/byok-catalog.js` is the list of vendor ids the server's catalog does
14
+ * not name but the relay forwards. It is a *shipping* artifact: every entry is
15
+ * a code change, a review, a release, and a desktop rebuild — and the file's own
16
+ * doc says so ("the durable fix for any of them is the server's MODEL_CATALOG").
17
+ * That is the right shape for the ids AEGIS should be offering everybody. It is
18
+ * the wrong shape for an id one user can call today: a freshly shipped model, a
19
+ * fine-tune, a preview id behind their own vendor key, a Together/Groq/OpenRouter
20
+ * route the relay forwards and the catalog simply has not caught up with.
21
+ *
22
+ * The BYOK relay is a stateless pass-through (`services/byok_service.py`): the
23
+ * caller's own vendor key authenticates upstream and AEGIS forwards the model
24
+ * string it was handed. So for a provider the account holds a key for, an id the
25
+ * VENDOR serves is callable whether or not this repo has ever heard of it. The
26
+ * only thing missing was a way for the user to say so without waiting for us.
27
+ *
28
+ * ── what a user does now ───────────────────────────────────────────────────
29
+ *
30
+ * CLI `/model-add <provider> <model-id>` (and `/model-rm …`)
31
+ * Desktop Settings → "Add a model" → provider + id
32
+ * Either hand-edit `$AEGISCODE_HOME/models.json` (default `~/.aegiscode`)
33
+ *
34
+ * All three end up in the same file, and the file is the whole state:
35
+ * `{ "deepseek": ["deepseek-v4.2-preview"], "anthropic": ["claude-opus-9-1"] }`.
36
+ * Because the CLI and the desktop both read it at the moment they build the
37
+ * picker, a model added in the terminal is in the window's list on its next
38
+ * refresh, with no restart and no release. That is the whole point of putting
39
+ * it in the shared data dir rather than in each host's own config.
40
+ *
41
+ * ── the rules this module keeps (the same ones byok-catalog.js keeps) ──────
42
+ *
43
+ * - NEVER invent a provider. User models are applied only to a provider row
44
+ * the server's catalog already lists. A row this file fabricated would
45
+ * invite a key for a slug the relay may not accept, and the failure would
46
+ * land on the user's first turn — so a declaration naming an unknown
47
+ * provider is preserved in the file and REPORTED (`unmatchedUserProviders`),
48
+ * never rendered as a picker row.
49
+ * - ONE spelling per route. Declarations are de-duplicated on add and again
50
+ * when they are applied, so the same id added twice — or added while the
51
+ * server has started listing it itself — paints one row, not two.
52
+ * - Idempotent and non-mutating. `withUserModels` returns a NEW array, shares
53
+ * the provider objects that gained nothing, and appends after the server's
54
+ * own models so the server's `default_model` keeps its first position (the
55
+ * default is what a bare provider id runs).
56
+ * - Validated, not trusted. A model id is a string the relay forwards to a
57
+ * vendor: a typo does not error here, it 404s upstream on the user's first
58
+ * turn. So ids and provider slugs are shape-checked on write (and re-checked
59
+ * on read, because the file is hand-editable), and a bad row is dropped with
60
+ * a reason rather than silently stored.
61
+ * - Never secret. Only provider slugs and model ids belong here — the file is
62
+ * written 0600 anyway, next to the credential store, because provider/model
63
+ * choice is not the kind of thing another local account should be able to
64
+ * rewrite.
65
+ */
66
+
67
+ const fs = require('node:fs');
68
+ const path = require('node:path');
69
+
70
+ const credentials = require('./credentials.js');
71
+
72
+ /** The file the CLI, the desktop and the MCP host all read. */
73
+ const USER_MODELS_FILE = 'models.json';
74
+ const FILE_MODE = 0o600;
75
+ /** A ceiling, not a policy: enough for a real vendor lineup, small enough that
76
+ * a runaway script cannot turn the picker into a wall of rows. */
77
+ const MAX_MODELS_PER_PROVIDER = 32;
78
+ const MAX_PROVIDERS = 64;
79
+
80
+ /**
81
+ * The provider slug shape the relay addresses (`deepseek`, `together-ai`,
82
+ * `openai-gpt4o-mini`). Lowercase on purpose: `/byok-key OpenAI` resolves to
83
+ * `openai` through the server's catalog, and two spellings of one provider id
84
+ * is exactly how a stored user model comes to never match the row it was meant
85
+ * for.
86
+ */
87
+ const PROVIDER_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
88
+ /**
89
+ * The model id shape. Deliberately permissive across vendors (dots for Claude,
90
+ * dashes for DeepSeek, slashes for the org-prefixed routes OpenRouter and
91
+ * Together use) and deliberately exclusive of two things: whitespace, because a
92
+ * model id with a space in it is a paste accident, and `:`, because
93
+ * `provider:model` is the id the picker and the engine already speak — a model
94
+ * id containing a colon would make that split ambiguous.
95
+ */
96
+ const MODEL_RE = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,95}$/;
97
+
98
+ /** The data dir (`$AEGISCODE_HOME` or `~/.aegiscode`), from the ONE definition. */
99
+ function userModelsDir(opts) {
100
+ return (opts && opts.dir) || credentials.aegisHome(opts && opts.env);
101
+ }
102
+
103
+ /** The absolute path of the shared user-model file. */
104
+ function userModelsPath(opts) {
105
+ return path.join(userModelsDir(opts), USER_MODELS_FILE);
106
+ }
107
+
108
+ /** Throw a message that says what to type instead. */
109
+ function badValue(what, raw, why) {
110
+ return new Error(
111
+ `aegiscode: ${what} ${JSON.stringify(String(raw))} is not usable — ${why}`
112
+ );
113
+ }
114
+
115
+ /** One provider slug, validated. Accepts the server's own spelling idempotently. */
116
+ function sanitizeProvider(raw) {
117
+ const s = String(raw == null ? '' : raw).trim().toLowerCase();
118
+ if (!s) throw badValue('provider', raw, 'the provider id is empty');
119
+ if (!PROVIDER_RE.test(s)) {
120
+ throw badValue(
121
+ 'provider',
122
+ raw,
123
+ 'a provider id is lowercase letters, digits, dot, dash or underscore ' +
124
+ '(the id `/byok` prints)'
125
+ );
126
+ }
127
+ return s;
128
+ }
129
+
130
+ /** One model id, validated. Ids are compared verbatim — never case-folded. */
131
+ function sanitizeModel(raw) {
132
+ const s = String(raw == null ? '' : raw).trim();
133
+ if (!s) throw badValue('model id', raw, 'the model id is empty');
134
+ if (/:/.test(s)) {
135
+ throw badValue(
136
+ 'model id',
137
+ raw,
138
+ "'provider:model' is how a picked model is addressed, so a model id cannot contain a colon"
139
+ );
140
+ }
141
+ if (!MODEL_RE.test(s)) {
142
+ throw badValue(
143
+ 'model id',
144
+ raw,
145
+ 'a model id has no spaces — it is the string sent to the vendor ' +
146
+ '(e.g. deepseek-v4.2-preview, claude-opus-9-1)'
147
+ );
148
+ }
149
+ return s;
150
+ }
151
+
152
+ /** True when `value` is a plain object (never an array, never null). */
153
+ function isPlainObject(value) {
154
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
155
+ }
156
+
157
+ /**
158
+ * Read the file and return BOTH the usable map and what was dropped.
159
+ *
160
+ * Never throws: a corrupt, unreadable or hand-mangled file reads as "no user
161
+ * models", because a declaration store must not be able to take the model
162
+ * picker down. But it does not lie about it either — `invalid` carries one
163
+ * `{ provider, model, reason }` per row that was skipped, which is what the
164
+ * hosts surface so a hand-edited typo is visible instead of looking like "the
165
+ * feature did nothing".
166
+ */
167
+ function load(opts) {
168
+ const file = userModelsPath(opts);
169
+ const invalid = [];
170
+ let raw;
171
+ try {
172
+ raw = JSON.parse(fs.readFileSync(file, 'utf8'));
173
+ } catch (err) {
174
+ // ENOENT is the normal state of a fresh install, not a problem to report.
175
+ if (err && err.code === 'ENOENT') return { dir: userModelsDir(opts), file, map: {}, invalid };
176
+ invalid.push({ provider: null, model: null, reason: `unreadable: ${(err && err.message) || err}` });
177
+ return { dir: userModelsDir(opts), file, map: {}, invalid };
178
+ }
179
+ const map = {};
180
+ if (!isPlainObject(raw)) {
181
+ invalid.push({ provider: null, model: null, reason: 'the file must be an object of provider → [model ids]' });
182
+ return { dir: userModelsDir(opts), file, map, invalid };
183
+ }
184
+ for (const [providerRaw, modelsRaw] of Object.entries(raw)) {
185
+ if (providerRaw === 'version' || providerRaw === '$schema') continue;
186
+ let provider;
187
+ try {
188
+ provider = sanitizeProvider(providerRaw);
189
+ } catch (err) {
190
+ invalid.push({ provider: providerRaw, model: null, reason: err.message });
191
+ continue;
192
+ }
193
+ const list = Array.isArray(modelsRaw) ? modelsRaw : [modelsRaw];
194
+ const seen = new Set();
195
+ const keep = [];
196
+ for (const m of list) {
197
+ let model;
198
+ try {
199
+ model = sanitizeModel(m);
200
+ } catch (err) {
201
+ invalid.push({ provider, model: m, reason: err.message });
202
+ continue;
203
+ }
204
+ if (seen.has(model)) continue; // one spelling per route, in the file too
205
+ seen.add(model);
206
+ keep.push(model);
207
+ }
208
+ if (keep.length) map[provider] = keep;
209
+ }
210
+ return { dir: userModelsDir(opts), file, map, invalid };
211
+ }
212
+
213
+ /** Just the usable provider → [ids] map (`load()` without the report). */
214
+ function readUserModels(opts) {
215
+ return load(opts).map;
216
+ }
217
+
218
+ /** The ids declared for one provider (an empty array when there are none). */
219
+ function userModelIdsFor(provider, opts) {
220
+ let id;
221
+ try {
222
+ id = sanitizeProvider(provider);
223
+ } catch {
224
+ return [];
225
+ }
226
+ const map = readUserModels(opts);
227
+ return Array.isArray(map[id]) ? map[id].slice() : [];
228
+ }
229
+
230
+ /** Write the map atomically, 0600, pretty-printed so it stays hand-editable. */
231
+ function writeMap(map, opts) {
232
+ const file = userModelsPath(opts);
233
+ fs.mkdirSync(path.dirname(file), { recursive: true });
234
+ const tmp = `${file}.tmp-${process.pid}`;
235
+ fs.writeFileSync(tmp, JSON.stringify(map, null, 2) + '\n', { mode: FILE_MODE });
236
+ fs.renameSync(tmp, file);
237
+ try {
238
+ fs.chmodSync(file, FILE_MODE);
239
+ } catch {
240
+ /* Windows: POSIX modes are a no-op and ACLs are the OS's business */
241
+ }
242
+ return map;
243
+ }
244
+
245
+ /**
246
+ * Declare one model id for one provider.
247
+ *
248
+ * Returns `{ file, provider, model, added, models }` — `added: false` when the
249
+ * id was already declared, so the caller can say "already there" instead of
250
+ * claiming a change it did not make. Rejects a provider or id that fails the
251
+ * shape checks above, and refuses to grow a single provider past the ceiling.
252
+ */
253
+ function addUserModel(provider, model, opts) {
254
+ const id = sanitizeProvider(provider);
255
+ const modelId = sanitizeModel(model);
256
+ const map = readUserModels(opts);
257
+ const have = Array.isArray(map[id]) ? map[id].slice() : [];
258
+ if (have.includes(modelId)) {
259
+ return { file: userModelsPath(opts), provider: id, model: modelId, added: false, models: have };
260
+ }
261
+ if (have.length >= MAX_MODELS_PER_PROVIDER) {
262
+ throw new Error(
263
+ `aegiscode: ${id} already carries ${have.length} user models (the cap) — ` +
264
+ 'remove one with /model-rm before adding another.'
265
+ );
266
+ }
267
+ if (!map[id] && Object.keys(map).length >= MAX_PROVIDERS) {
268
+ throw new Error(
269
+ `aegiscode: ${Object.keys(map).length} providers already carry user models (the cap).`
270
+ );
271
+ }
272
+ const models = [...have, modelId];
273
+ const next = { ...map, [id]: models };
274
+ writeMap(next, opts);
275
+ return { file: userModelsPath(opts), provider: id, model: modelId, added: true, models };
276
+ }
277
+
278
+ /**
279
+ * Retire one declaration. Returns `{ …, removed }`; `removed: false` means it
280
+ * was not declared, which is a report and not an error (the file is shared, so
281
+ * another host may have removed it a moment ago).
282
+ */
283
+ function removeUserModel(provider, model, opts) {
284
+ const id = sanitizeProvider(provider);
285
+ const modelId = sanitizeModel(model);
286
+ const map = readUserModels(opts);
287
+ const have = Array.isArray(map[id]) ? map[id].slice() : [];
288
+ if (!have.includes(modelId)) {
289
+ return { file: userModelsPath(opts), provider: id, model: modelId, removed: false, models: have };
290
+ }
291
+ const models = have.filter((m) => m !== modelId);
292
+ const next = { ...map };
293
+ if (models.length) next[id] = models;
294
+ else delete next[id];
295
+ writeMap(next, opts);
296
+ return { file: userModelsPath(opts), provider: id, model: modelId, removed: true, models };
297
+ }
298
+
299
+ /** The model ids an entry names, tolerating the server's two shapes. */
300
+ function modelIdsOf(provider) {
301
+ return (Array.isArray(provider && provider.models) ? provider.models : [])
302
+ .map((m) => (typeof m === 'string' ? m : m && m.id))
303
+ .map((m) => (typeof m === 'string' ? m.trim() : ''))
304
+ .filter(Boolean);
305
+ }
306
+
307
+ /** The provider array out of either shape the server sends (or `[]`). */
308
+ function providerArray(providers) {
309
+ if (Array.isArray(providers)) return providers;
310
+ if (Array.isArray(providers && providers.providers)) return providers.providers;
311
+ return null;
312
+ }
313
+
314
+ /**
315
+ * The server's BYOK catalog with the USER's declared models applied.
316
+ *
317
+ * @param {Array<object>|object} providers the payload (array, or `{providers}`)
318
+ * @param {object} [extra] an explicit provider → [ids] map. Omitted by every
319
+ * host (they want the file); passing it is what makes this function pure and
320
+ * therefore testable without touching a real data dir.
321
+ * @returns {Array<object>} a NEW array. Providers that gained nothing come back
322
+ * as the SAME objects, an unknown provider is never fabricated, and an
323
+ * empty/absent payload returns `[]` rather than a list invented from the file.
324
+ */
325
+ function withUserModels(providers, extra) {
326
+ const raw = providerArray(providers);
327
+ if (!raw) return [];
328
+ const map = extra === undefined ? readUserModels() : isPlainObject(extra) ? extra : {};
329
+ const out = [];
330
+ for (const p of raw) {
331
+ if (!p || typeof p !== 'object') continue;
332
+ const id = typeof p.id === 'string' ? p.id.trim() : '';
333
+ const declared = id && Array.isArray(map[id]) ? map[id] : null;
334
+ if (!declared || !declared.length) {
335
+ out.push(p);
336
+ continue;
337
+ }
338
+ const have = new Set(modelIdsOf(p));
339
+ const missing = declared
340
+ .map((m) => String(m).trim())
341
+ .filter((m) => m && !have.has(m));
342
+ // Nothing to add — hand back the SAME object, so a complete payload is
343
+ // byte-identical after this pass and a caller cannot tell it ran.
344
+ if (!missing.length) {
345
+ out.push(p);
346
+ continue;
347
+ }
348
+ const models = Array.isArray(p.models) ? p.models : [];
349
+ out.push({ ...p, models: [...models, ...missing] });
350
+ }
351
+ return out;
352
+ }
353
+
354
+ /**
355
+ * Declared providers the payload does NOT list — the honest half of the rules
356
+ * above. A host reports these ("no provider row for `foo` — the relay takes
357
+ * keys for: …") instead of either hiding the declaration or showing a row that
358
+ * would 401 on its first turn.
359
+ */
360
+ function unmatchedUserProviders(providers, extra) {
361
+ const raw = providerArray(providers) || [];
362
+ const map = extra === undefined ? readUserModels() : isPlainObject(extra) ? extra : {};
363
+ const known = new Set(
364
+ raw.map((p) => (p && typeof p.id === 'string' ? p.id.trim() : '')).filter(Boolean)
365
+ );
366
+ return Object.keys(map).filter((id) => !known.has(id));
367
+ }
368
+
369
+ module.exports = {
370
+ USER_MODELS_FILE,
371
+ MAX_MODELS_PER_PROVIDER,
372
+ userModelsDir,
373
+ userModelsPath,
374
+ sanitizeProvider,
375
+ sanitizeModel,
376
+ load,
377
+ readUserModels,
378
+ userModelIdsFor,
379
+ addUserModel,
380
+ removeUserModel,
381
+ withUserModels,
382
+ unmatchedUserProviders,
383
+ };
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env node
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
4
+ // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
5
+ // Conveying a modified copy, or running one as a network service, owes the
6
+ // corresponding source under this licence (§5/§13) — see LICENSING.md.
2
7
  /**
3
8
  * aegis-seal.mjs — codec for ÆL/1 (AEGIS Encoded Language)
4
9
  *
@@ -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
  /**
@@ -73,6 +78,83 @@ const MAX_ROUND_STOPS = 3;
73
78
  */
74
79
  const WRITE_TOOLS = new Set(['writeFile', 'editFile']);
75
80
 
81
+ // ── Auto mode and the round horizon ─────────────────────────────────────────
82
+ //
83
+ // The two halves of "auto mode" the upstream engine (aegiscodex-dev) defines
84
+ // are independent, and a host that wires only one of them is *not* running auto
85
+ // mode — it is running "no approval cards", which is half the feature and all
86
+ // the friction:
87
+ //
88
+ // 1. no approval keystroke per mutating tool call;
89
+ // 2. a turn that hits its round horizon is EXTENDED silently a few times
90
+ // before a human is asked.
91
+ //
92
+ // (1) is the posture (the desktop's Tool-approvals switch, the CLI's
93
+ // /automode); (2) needs the arithmetic below, and the plugin's Electron host
94
+ // had none of it — with auto mode ON, every horizon hit still raised the
95
+ // blocking round card, which is precisely the question auto mode exists to stop
96
+ // asking ("12 rounds — keep going?" answered the same way every time).
97
+ //
98
+ // Ported verbatim from the engine's src/autonomous.js (DEFAULT_AUTO_CONTINUES,
99
+ // autoContinueLimit, autoRoundsDefault, autoContinuePlan) rather than vendored,
100
+ // because this repo hosts no build of that ESM module — but with the SAME
101
+ // numbers and the SAME env knobs, so a turn behaves identically in either
102
+ // client. cli/src/chatflow.js carries the third copy, which is what the CLI
103
+ // presenter uses to answer the ask.
104
+
105
+ /** Automatic continuations an attended turn may take while auto mode is on. */
106
+ const DEFAULT_AUTO_CONTINUES = 3;
107
+
108
+ /**
109
+ * The auto-continue allowance, honouring AEGIS_AUTO_CONTINUE_MAX.
110
+ *
111
+ * Bounded and pure, and a garbage value falls back to the default rather than
112
+ * to 0: an unparseable env var must not silently switch auto mode off, because
113
+ * the visible symptom of that ("why is it asking me again?") points nowhere
114
+ * near the environment.
115
+ */
116
+ function autoContinueLimit(env = process.env) {
117
+ const n = Number.parseInt(env && env.AEGIS_AUTO_CONTINUE_MAX, 10);
118
+ return Number.isFinite(n) && n > 0 ? n : DEFAULT_AUTO_CONTINUES;
119
+ }
120
+
121
+ /**
122
+ * Values of AEGIS_AUTO_ROUNDS that mean "start in manual mode". Anything else —
123
+ * unset, empty, a typo like `flase` — leaves auto mode's default in place, so a
124
+ * misspelt opt-out cannot silently disable the mode the operator asked for.
125
+ * Same set, same reasoning, as the engine's AUTO_ROUNDS_OFF.
126
+ */
127
+ const AUTO_ROUNDS_OFF = new Set(['0', 'false', 'off', 'no']);
128
+
129
+ /** False only when AEGIS_AUTO_ROUNDS explicitly says so. */
130
+ function autoRoundsDefault(env = process.env) {
131
+ const raw = env && env.AEGIS_AUTO_ROUNDS;
132
+ if (raw === undefined || raw === null) return true;
133
+ const val = String(raw).trim().toLowerCase();
134
+ if (!val) return true;
135
+ return !AUTO_ROUNDS_OFF.has(val);
136
+ }
137
+
138
+ /**
139
+ * Decide what one round-horizon ask becomes while auto mode is on.
140
+ *
141
+ * Pure, because this is budget arithmetic on a keystroke-less path: the caller
142
+ * only renders the answer and must not be trusted to keep the count. `used` is
143
+ * the running tally the caller holds and echoes back, so an ask that IS shown
144
+ * to the human resets it — the human was asked, so the next block of automatic
145
+ * continuations starts clean.
146
+ *
147
+ * { auto: true, used: n } → answer the ask "yes" without a dialog
148
+ * { auto: false, used: n } → show the real ask (allowance spent, or off)
149
+ */
150
+ function autoContinuePlan({ on = false, used = 0, limit = DEFAULT_AUTO_CONTINUES } = {}) {
151
+ const cap = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : DEFAULT_AUTO_CONTINUES;
152
+ const spent = Number.isFinite(used) && used > 0 ? Math.floor(used) : 0;
153
+ if (!on) return { auto: false, used: spent, cap };
154
+ if (spent >= cap) return { auto: false, used: 0, cap };
155
+ return { auto: true, used: spent + 1, cap };
156
+ }
157
+
76
158
  /** The path a file-writing tool call names, in either spelling the engine uses. */
77
159
  function writtenPath(tool) {
78
160
  const args = (tool && tool.args) || {};
@@ -906,6 +988,10 @@ module.exports = {
906
988
  isAutonomousRequest,
907
989
  maxRounds,
908
990
  withRoundHorizon,
991
+ DEFAULT_AUTO_CONTINUES,
992
+ autoContinueLimit,
993
+ autoRoundsDefault,
994
+ autoContinuePlan,
909
995
  resolveModel,
910
996
  ignoredEnvModel,
911
997
  resolveEffort,
@@ -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
  /**