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