aegiscode 6.8.31 → 6.8.33

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.
@@ -97,48 +97,100 @@ function writtenPath(tool) {
97
97
  const DEFAULT_MODEL = 'nexus-brain';
98
98
 
99
99
  /**
100
- * THE QUEUE RUNS ON AEGIS CLOUD, AND NOTHING ELSE.
100
+ * THE QUEUE RUNS ON WHATEVER CLASS THE TASK NAMES — aegis, byok, or local —
101
+ * the same three classes engine.js's interactive turns serve (engine.js's
102
+ * exported `CLASSES`). This module does not `require('./engine.js')` to read
103
+ * that list itself (same reason queue.js stays engine-free): duplicating the
104
+ * three names here keeps both modules testable with no Electron, no network,
105
+ * and no model.
101
106
  *
102
- * A queued task is billed to the AEGIS pool and every turn it makes goes out
103
- * with `class: 'aegis'` (see runTask below) — the pool is the only backend this
104
- * worker can reach. So a model id here has to be one the *pool* serves. A
105
- * direct-provider id is not a cheaper option the queue could fall back to; it
106
- * is a request the pool cannot honour, or worse, a per-provider spelling
107
- * (`anthropic`, `groq`, …) that quietly pins one upstream instead of letting
108
- * the pool auto-route across whichever providers hold a live key.
107
+ * This used to be Aegis Cloud only, because runTask sent every turn out with
108
+ * a hardcoded `class: 'aegis'` — a byok or local model id would have gone out
109
+ * under the wrong transport and failed at the server, or worse, silently
110
+ * picked up the wrong provider's key. Now `class` travels with the task
111
+ * (`item.class`, defaulted to 'aegis' for every task that predates this field
112
+ * — the CLI, a hand-written queue file, the old desktop card), and runTask
113
+ * forwards it verbatim instead of overwriting it.
109
114
  *
110
- * The accept-list is therefore the pooled-brain tier family — the one entry
111
- * engine.js's offerableCatalog offers for the Aegis Cloud class, plus the
112
- * `-smart`/`-neo` tier spellings the server still serves as aliases of it. This
113
- * mirrors selectBrainEntry() there rather than re-deriving "anything starting
114
- * with nexus-": `nexus-fast` is not a tier the catalog has ever served, and
115
- * accepting a made-up id means a queued task that fails at the server after
116
- * being picked up, or runs on a tier nobody chose.
115
+ * Each class validates differently, because each has a different notion of
116
+ * "no model stated is fine":
117
+ * - 'aegis' has a real default (the pooled brain), so a blank model is
118
+ * accepted and resolveModel fills it in. The accept-list is the
119
+ * pooled-brain tier family — the one entry engine.js's offerableCatalog
120
+ * offers for the Aegis Cloud class, plus the `-smart`/`-neo` tier
121
+ * spellings the server still serves as aliases of it (mirrors
122
+ * selectBrainEntry() there rather than re-deriving "anything starting
123
+ * with nexus-": `nexus-fast` is not a tier the catalog has ever served).
124
+ * - 'byok' and 'local' have no such default: a blank byok model cannot be
125
+ * "whichever provider the pool picks" (there is no pool), and a blank
126
+ * local model cannot be "whichever model is pulled" when the answer
127
+ * depends on what the user's own daemon happens to have. Both REQUIRE an
128
+ * explicit model, refused by name instead of silently resolving to
129
+ * something nobody chose.
117
130
  */
131
+ const MODEL_CLASSES = Object.freeze(['aegis', 'byok', 'local']);
132
+
118
133
  const AEGIS_MODEL_RE = /^(?:nexus|aegis)-brain(?:-(?:smart|neo))?$/;
119
134
  const AEGIS_MODEL_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
120
135
 
121
- /** True when `id` names an AEGIS Cloud pooled-brain tier (the queue's only models). */
136
+ /** True when `id` names an AEGIS Cloud pooled-brain tier. */
122
137
  function isAegisModel(id) {
123
138
  return AEGIS_MODEL_RE.test(String(id == null ? '' : id).trim());
124
139
  }
125
140
 
126
141
  /**
127
- * Why a STATED model id cannot be queued, or '' when it can. Blank is not a
128
- * refusal — "no pick" is the default model, which resolveModel supplies.
142
+ * Normalize a task's stated class to one this module (and engine.js) knows.
143
+ * Blank or absent — every task queued before this field existed — defaults to
144
+ * 'aegis', the only class the queue ever ran before today.
145
+ */
146
+ function normalizeClass(cls) {
147
+ const stated = String(cls == null ? '' : cls).trim().toLowerCase();
148
+ return stated || 'aegis';
149
+ }
150
+
151
+ /**
152
+ * Whether `id` is shaped "<provider>:<model>" — the only form engine.js's
153
+ * byok class accepts (splitByokModel). Not re-deriving the live provider list
154
+ * here (that is a catalog call, `listModels('byok')`, this module has no
155
+ * business caching) — just enough of a shape check that a malformed id is
156
+ * refused at the door instead of failing splitByokModel at the server with no
157
+ * context.
158
+ */
159
+ function looksLikeByokModel(id) {
160
+ const s = String(id == null ? '' : id).trim();
161
+ const i = s.indexOf(':');
162
+ return i > 0 && i < s.length - 1;
163
+ }
164
+
165
+ /**
166
+ * Why a STATED (model, class) pair cannot be queued, or '' when it can.
129
167
  *
130
- * The message names the pool, because the failure it prevents ("queued on
131
- * claude-sonnet-4, ran on — or was billed to — something else") is invisible
132
- * otherwise: `class: 'aegis'` would be sent with an id the server does not
133
- * serve, and the task would come back as an opaque error minutes later.
168
+ * `cls` defaults to 'aegis' when omitted, so every existing caller of
169
+ * `modelRefusal(id)` keeps its old behaviour verbatim.
134
170
  */
135
- function modelRefusal(id) {
171
+ function modelRefusal(id, cls) {
136
172
  const stated = String(id == null ? '' : id).trim();
137
- if (!stated || isAegisModel(stated)) return '';
138
- return (
139
- `the autonomous queue runs Aegis Cloud models only (${DEFAULT_MODEL}, ` +
140
- `${AEGIS_MODEL_IDS.join('/')} aliases); "${stated}" is not one`
141
- );
173
+ const normalized = normalizeClass(cls);
174
+ if (!MODEL_CLASSES.includes(normalized)) {
175
+ return `"${cls}" is not a model class the queue serves (${MODEL_CLASSES.join('/')})`;
176
+ }
177
+ if (normalized === 'aegis') {
178
+ if (!stated || isAegisModel(stated)) return '';
179
+ return (
180
+ `the autonomous queue's Aegis Cloud class runs pooled-brain models only (${DEFAULT_MODEL}, ` +
181
+ `${AEGIS_MODEL_IDS.join('/')} aliases); "${stated}" is not one`
182
+ );
183
+ }
184
+ if (normalized === 'byok') {
185
+ if (!stated) return 'a byok task needs a model, as "<provider>:<model>" (pick one from /models)';
186
+ if (!looksLikeByokModel(stated)) {
187
+ return `"${stated}" is not a byok model id — it must be "<provider>:<model>" (pick one from /models)`;
188
+ }
189
+ return '';
190
+ }
191
+ // normalized === 'local'
192
+ if (!stated) return 'a local task needs a model — the tag of whatever is pulled into the local daemon';
193
+ return '';
142
194
  }
143
195
 
144
196
  /** Phrase match for "work autonomously" in a prompt or a queued task. */
@@ -239,10 +291,14 @@ function withRoundHorizon(rounds, env, fn) {
239
291
  * task over it would break drains for a reason that is not the task's
240
292
  * fault; a fallback to the pooled brain keeps the drain honest and on-cloud.
241
293
  */
242
- function resolveModel({ model, env } = {}) {
243
- const e = env || process.env;
294
+ function resolveModel({ model, env, cls } = {}) {
244
295
  const picked = String(model || '').trim();
296
+ // byok/local have no cloud default to fall back to — modelRefusal already
297
+ // guaranteed a non-empty, shaped model at queue time, so the task's own pick
298
+ // is the only answer for either class.
299
+ if (normalizeClass(cls) !== 'aegis') return picked;
245
300
  if (picked) return picked;
301
+ const e = env || process.env;
246
302
  const fromEnv = String(e.AEGIS_AUTONOMOUS_MODEL || e.AEGIS_MODEL || '').trim();
247
303
  return isAegisModel(fromEnv) ? fromEnv : DEFAULT_MODEL;
248
304
  }
@@ -255,7 +311,8 @@ function resolveModel({ model, env } = {}) {
255
311
  * it: the queue falls back to the pool, and the one place that says so is this
256
312
  * string, which runTask emits as a note and the desktop card shows.
257
313
  */
258
- function ignoredEnvModel({ model, env } = {}) {
314
+ function ignoredEnvModel({ model, env, cls } = {}) {
315
+ if (normalizeClass(cls) !== 'aegis') return ''; // AEGIS_AUTONOMOUS_MODEL is an Aegis-only pin
259
316
  if (String(model || '').trim()) return ''; // the task's own pick is what counts
260
317
  const e = env || process.env;
261
318
  const fromEnv = String(e.AEGIS_AUTONOMOUS_MODEL || e.AEGIS_MODEL || '').trim();
@@ -462,16 +519,23 @@ function createQueueWorker({
462
519
  // pool does not serve: billed work if it happens to be a per-provider
463
520
  // spelling, an opaque server error otherwise. Failing here names the model
464
521
  // and the allowed ones, and costs nothing.
465
- const refusal = modelRefusal(item.model);
522
+ const cls = normalizeClass(item.class);
523
+ const refusal = modelRefusal(item.model, cls);
466
524
  if (refusal) {
467
- const failed = { ok: false, error: refusal, model: item.model, ms: 0 };
525
+ const failed = { ok: false, error: refusal, model: item.model, class: cls, ms: 0 };
468
526
  emit({ type: 'finish', taskId: item.id, ok: false, result: failed });
469
527
  return failed;
470
528
  }
471
- const model = resolveModel({ model: item.model, env });
472
- const ignored = ignoredEnvModel({ model: item.model, env });
529
+ const model = resolveModel({ model: item.model, env, cls });
530
+ const ignored = ignoredEnvModel({ model: item.model, env, cls });
473
531
  if (ignored) emit({ type: 'note', taskId: item.id, note: ignored });
474
- const fanoutAsked = resolveFanout(item, env);
532
+ // The pooled-brain fan-out is an Aegis Cloud mechanism (aegis1
533
+ // services/pool_brain.py) — engine.js itself only honours `autonomous`
534
+ // under `cls === 'aegis'` (engine.js:1524), so a byok/local task asking for
535
+ // it is forced to a plain single pass HERE rather than relying on that
536
+ // silent no-op, which would otherwise size the task's effort/round
537
+ // reporting as if a fan-out it never got had been granted.
538
+ const fanoutAsked = cls === 'aegis' && resolveFanout(item, env);
475
539
  // The clamp. `canFanOut()` is the entitlement answer (true everywhere
476
540
  // except a non-Pro desktop session), and it can only ever take a fan-out
477
541
  // AWAY: a task the session is not entitled to fan out runs as one plain
@@ -526,14 +590,14 @@ function createQueueWorker({
526
590
  const wantCommit = commit === undefined ? Boolean(item.commit) : Boolean(commit);
527
591
  const before = wantCommit ? safe(() => git.gitStatusSnapshot(cwd), null) : null;
528
592
 
529
- emit({ type: 'start', taskId: item.id, model, cwd, rounds, fanout, effort });
593
+ emit({ type: 'start', taskId: item.id, model, class: cls, cwd, rounds, fanout, effort });
530
594
  const started = now();
531
595
  let result;
532
596
  try {
533
597
  const res = await withRoundHorizon(rounds, env, () =>
534
598
  engine.chat(
535
599
  {
536
- class: 'aegis',
600
+ class: cls,
537
601
  model,
538
602
  prompt: taskPrompt(item, { carry, rounds }),
539
603
  // The pooled-brain fan-out ("fan out this turn" in the GUI chat
@@ -831,8 +895,11 @@ module.exports = {
831
895
  DEFAULT_MODEL,
832
896
  DEFAULT_ROUNDS,
833
897
  MAX_ROUND_STOPS,
898
+ MODEL_CLASSES,
834
899
  AEGIS_MODEL_IDS,
835
900
  isAegisModel,
901
+ normalizeClass,
902
+ looksLikeByokModel,
836
903
  modelRefusal,
837
904
  WRITE_TOOLS,
838
905
  writtenPath,
@@ -968,6 +968,19 @@ function createLocalEngine({
968
968
  // reverse its verdict. An approval that could waive Λ2 would be the exact
969
969
  // capture K3 describes. To change what is permitted, the covenant text
970
970
  // itself has to be re-sealed — which no runtime input can do.
971
+ //
972
+ // DO NOT MOVE THIS BELOW A SHORT-CIRCUIT. It sits above every `return` of
973
+ // the confirmation gate on purpose (ON8/D8 rule 2): `gatedExecuteTool`
974
+ // short-circuits on `!confirmModeEnabled()`, on a remembered session
975
+ // "allow", and on a `/permissions` skip — and since ON8 the confirm-mode
976
+ // preference is the SHARED store's, i.e. the same value the terminal face
977
+ // reads, and `--dangerously-skip-permissions` can arrive in that store as
978
+ // well. A refactor that hoists this below any of those three would make
979
+ // the covenant waivable by a setting a user can write, which is the one
980
+ // thing D8 rule 2 forbids outright. The frozen classes
981
+ // (`write`/`shell`/`network`/`offDevice`, always `'ask'`; see
982
+ // lib/avatar/level.js `LEVEL_INDEPENDENT_APPROVALS`) have the same floor
983
+ // and are asserted beside this one by one/test/permissions.test.mjs.
971
984
  const cv = covenant.preActionAssert({ tool: name, args: args || {} });
972
985
  if (!cv.allowed) {
973
986
  // Non-silent (never a quiet no-op) and bound for Λ4 accountability.
@@ -176,34 +176,38 @@ function upsert(items, entry) {
176
176
 
177
177
  /**
178
178
  * Queue a task. `cwd` is where the work happens (the worker runs the turn
179
- * with it as the tool loop's working directory), `model` is the AEGIS Cloud
180
- * model id to run it on, and `commit` asks the worker to commit what the task
181
- * changed (scoped — see autonomous.js).
179
+ * with it as the tool loop's working directory), `class` + `model` are the
180
+ * same pair engine.js's interactive turns use ('aegis'/'byok'/'local' and the
181
+ * model id that class expects), and `commit` asks the worker to commit what
182
+ * the task changed (scoped — see autonomous.js).
182
183
  *
183
- * AEGIS CLOUD ONLY, REFUSED AT THE DOOR. The worker sends every task out as
184
- * `class: 'aegis'`, so a model the pool does not serve cannot run here at all —
185
- * it is a task that fails minutes into a drain, after being picked up, with an
186
- * opaque server error. `model: null` stays legal: that is "no pick", and
187
- * autonomous.resolveModel fills in the pooled brain. Anything else has to pass
188
- * that module's own accept-list, so the CLI (`aegiscode autonomous add
189
- * --model`), the desktop card and a hand-written queue file are all held to the
190
- * same rule. Required lazily: queue.js is a dependency of autonomous.js, and
191
- * this check must not turn that into a load-order cycle.
184
+ * REFUSED AT THE DOOR, not three stages into a drain. `class` defaults to
185
+ * 'aegis' (every task queued before this field existed), and the (model,
186
+ * class) pair has to pass autonomous.js's own accept-list — the CLI
187
+ * (`aegiscode autonomous add --model`), the desktop card and a hand-written
188
+ * queue file are all held to the same rule, so a bad row fails here with a
189
+ * reason instead of coming back as an opaque server error after being picked
190
+ * up. `model: null` stays legal for the 'aegis' class only: that is "no
191
+ * pick", and autonomous.resolveModel fills in the pooled brain. 'byok' and
192
+ * 'local' have no such default and are refused if blank — see
193
+ * autonomous.modelRefusal. Required lazily: queue.js is a dependency of
194
+ * autonomous.js, and this check must not turn that into a load-order cycle.
192
195
  */
193
196
  function addTask(env, opts = {}) {
194
197
  const task = String(opts.task == null ? '' : opts.task).trim();
195
198
  if (!task) throw new Error('queue: a task needs text');
199
+ const autonomousMod = require('./autonomous.js');
200
+ const cls = autonomousMod.normalizeClass(opts.class);
196
201
  const statedModel = String(opts.model == null ? '' : opts.model).trim();
197
- if (statedModel) {
198
- const refusal = require('./autonomous.js').modelRefusal(statedModel);
199
- if (refusal) throw new Error(`queue: ${refusal}`);
200
- }
202
+ const refusal = autonomousMod.modelRefusal(statedModel, cls);
203
+ if (refusal) throw new Error(`queue: ${refusal}`);
201
204
  const items = loadQueue(env);
202
205
  const now = opts.now || Date.now();
203
206
  const entry = {
204
207
  id: nextId(items),
205
208
  task,
206
209
  cwd: opts.cwd || process.cwd(),
210
+ class: cls,
207
211
  model: statedModel || null,
208
212
  effort: opts.effort || null,
209
213
  workers: Number.isInteger(opts.workers) ? opts.workers : null,
@@ -270,6 +270,15 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
270
270
  try {
271
271
  return prefs.adopt({ dir: sharedDir, legacyDir: dir });
272
272
  } catch (err) {
273
+ // Best-effort, but NOT silent (AEGISONE ON8). Swallowing this throw is how
274
+ // `prefs.adopt()`'s refusal to write its own ledger went unnoticed — the
275
+ // migration failed for every install that had something to adopt, and the
276
+ // store reported a healthy `adopted: false`. A failed migration is a
277
+ // preference a user set that this launch did not honor, so it is reported
278
+ // where a developer will see it; a store must still open either way.
279
+ if (process.env.AEGISCODE_DEBUG || process.env.AEGIS_HIST_DEBUG) {
280
+ process.stderr.write(`aegis-desktop: shared-preference adoption failed: ${err.message}\n`);
281
+ }
273
282
  return { adopted: false, keys: [], reason: `adoption failed: ${err.message}` };
274
283
  }
275
284
  })();
@@ -525,26 +534,50 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
525
534
  return quickLauncherConfig();
526
535
  }
527
536
 
528
- // --- Confirm mode: reserved namespace, plain (unencrypted) preference ----
529
- // "Confirm before running tools" — the ON/OFF switch for the renderer's
530
- // tool-call approval gate (desktop/lib/local/engine.js gatedExecuteTool).
531
- // ON (default, and the behaviour shipped so far) means every mutating tool
532
- // call — exec / writeFile / editFile — is previewed and approved by the user
533
- // first. OFF means the engine runs them straight through, like a tool the
534
- // session already allowed. Nothing secret is stored here, so no encryption.
537
+ // --- Confirm mode: SHARED preference (AEGISONE ON8, decision D8 rule 1) --
538
+ // "Confirm before running tools" — the switch for the renderer's tool-call
539
+ // approval gate (desktop/lib/local/engine.js gatedExecuteTool). ON (default,
540
+ // and the behaviour shipped so far) means every mutating tool call — exec /
541
+ // writeFile / editFile — is previewed and approved by the user first. OFF
542
+ // means the engine runs them straight through, like a tool the session
543
+ // already allowed. Nothing secret is stored here, so no encryption.
544
+ //
545
+ // This preference MOVED to the shared store (`confirmMode`) because D8 rule 1
546
+ // is "one posture, two faces": a rule set in the window has to be the rule the
547
+ // shell honors. The pre-ON8 `__confirmMode` namespace in `<userData>` is
548
+ // adopted once (client/prefs.js `extractNonSecretHalf`) and still read as a
549
+ // fallback, never written — a second writer is the split-brain this replaced.
550
+ // The gate's polarity is unchanged: ON when unset, in both places, so an
551
+ // install that never touched the switch keeps the gate exactly as it was.
552
+
553
+ function confirmModeState() {
554
+ const shared = loadShared();
555
+ if (typeof shared.confirmMode === 'boolean') {
556
+ return { enabled: shared.confirmMode, source: 'config' };
557
+ }
558
+ const cfg = load()[CONFIRM_MODE_NAMESPACE] || {};
559
+ if (cfg.enabled === undefined) return { enabled: true, source: 'default' };
560
+ return { enabled: Boolean(cfg.enabled), source: 'config' };
561
+ }
535
562
 
536
563
  function getConfirmMode() {
537
- const cfg = load()[CONFIRM_MODE_NAMESPACE] || {};
538
- // Unset === true: an existing install that never touched the toggle keeps
539
- // the gate exactly as it was.
540
- return cfg.enabled === undefined ? true : Boolean(cfg.enabled);
564
+ return confirmModeState().enabled;
541
565
  }
542
566
 
543
567
  function setConfirmMode(enabled) {
568
+ prefs.set({ confirmMode: Boolean(enabled) }, { dir: sharedDir });
569
+ // One-way: retire the legacy copy in the same breath, so the posture exists
570
+ // in exactly one place from here on (the same retirement the memory-persist
571
+ // preference below does).
544
572
  const data = load();
545
- data[CONFIRM_MODE_NAMESPACE] = { enabled: Boolean(enabled) };
546
- save(data);
547
- return getConfirmMode();
573
+ if (data[CONFIRM_MODE_NAMESPACE] !== undefined) {
574
+ delete data[CONFIRM_MODE_NAMESPACE];
575
+ save(data);
576
+ }
577
+ // The boolean, not the state record: main.js's IPC reply is `{ enabled }`
578
+ // and it wraps the return value itself, so widening this would have put an
579
+ // object inside an object on the wire.
580
+ return confirmModeState().enabled;
548
581
  }
549
582
 
550
583
  // --- Telemetry: reserved namespace, plain preference, DEFAULT OFF --------
@@ -771,6 +804,7 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
771
804
  setQuickLauncherConfig,
772
805
  getConfirmMode,
773
806
  setConfirmMode,
807
+ confirmModeState,
774
808
  getTelemetryOptIn,
775
809
  setTelemetryOptIn,
776
810
  getMemoryPersist,