aegisone 1.0.5 → 1.0.8

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 (45) hide show
  1. package/README.md +2 -2
  2. package/bin/aegis.js +28 -3
  3. package/package.json +1 -1
  4. package/scripts/predist.mjs +230 -0
  5. package/src/permissions.js +134 -7
  6. package/src/release.js +14 -5
  7. package/vendor/cli/README.md +42 -3
  8. package/vendor/cli/bin/aegiscode.js +15 -3
  9. package/vendor/cli/package.json +1 -1
  10. package/vendor/cli/src/app.js +167 -37
  11. package/vendor/cli/src/chatflow.js +285 -39
  12. package/vendor/cli/src/commands.js +251 -30
  13. package/vendor/cli/src/config.js +41 -11
  14. package/vendor/cli/src/engine.js +33 -4
  15. package/vendor/cli/src/entitlement.js +30 -1
  16. package/vendor/cli/src/format.js +175 -3
  17. package/vendor/cli/src/overlays.js +13 -9
  18. package/vendor/cli/src/panels.js +19 -6
  19. package/vendor/cli/src/render.js +49 -14
  20. package/vendor/cli/src/screen.js +12 -1
  21. package/vendor/cli/src/screens.js +118 -25
  22. package/vendor/cli/src/todos.js +7 -4
  23. package/vendor/cli/src/tokens.js +31 -1
  24. package/vendor/cli/vendor/client/aegis.js +22 -0
  25. package/vendor/cli/vendor/client/byok-catalog.js +43 -8
  26. package/vendor/cli/vendor/client/user-models.js +378 -0
  27. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +81 -0
  28. package/vendor/cli/vendor/desktop/lib/local/engine.js +447 -14
  29. package/vendor/cli/vendor/desktop/renderer/usage.js +274 -21
  30. package/vendor/cli/vendor/mcp/tools.js +1 -1
  31. package/vendor/desktop/README.md +11 -0
  32. package/vendor/desktop/lib/deep-link.js +35 -1
  33. package/vendor/desktop/lib/local/autonomous.js +81 -0
  34. package/vendor/desktop/lib/local/engine.js +447 -14
  35. package/vendor/desktop/main.js +271 -6
  36. package/vendor/desktop/package.json +1 -1
  37. package/vendor/desktop/preload.js +18 -0
  38. package/vendor/desktop/renderer/app.js +631 -43
  39. package/vendor/desktop/renderer/index.html +4 -5
  40. package/vendor/desktop/renderer/stream-policy.js +24 -2
  41. package/vendor/desktop/renderer/style.css +81 -7
  42. package/vendor/desktop/renderer/usage.js +274 -21
  43. package/vendor/desktop/vendor/aegis.js +22 -0
  44. package/vendor/desktop/vendor/byok-catalog.js +43 -8
  45. package/vendor/desktop/vendor/user-models.js +378 -0
@@ -56,7 +56,7 @@ const {
56
56
  // ON8 / D8 rule 1: the posture writers. Every "confirmations on/off" command
57
57
  // below goes through these rather than writing `defaultMode` itself, so the
58
58
  // window's switch and this face's gate cannot end up holding two answers.
59
- setConfirmPosture, setPermissionDefaultMode,
59
+ setConfirmPosture, setPermissionDefaultMode, confirmPosture,
60
60
  memoryPersistState, setMemoryPersist,
61
61
  } = require('./config.js');
62
62
  const { auditExposure, repairExposure } = require('./securefs.js');
@@ -66,6 +66,10 @@ const { signupUrl, goUrl } = require('./signup.js');
66
66
  const screens = require('./screens.js');
67
67
  const { summarizeTranscript, recapLine } = require('./summarize.js');
68
68
  const { sessionAccounting, accountingFromUsage, estimateTokens } = require('./tokens.js');
69
+ // The one effort normaliser, so `/config effort <x>` writes the same rung the
70
+ // turn will send (see effortRung in engine.js — it is what app.js puts on the
71
+ // request).
72
+ const { effortRung } = require('./engine.js');
69
73
  const { transcriptToMarkdown, transcriptToJSON, writeExportFile, lastAssistantText } = require('./export.js');
70
74
  const { detectDevCommand, runDevServer } = require('./devrun.js');
71
75
  // /ping — the terminal half of the desktop's "reply ready" alert. Pure and
@@ -129,7 +133,7 @@ const categoryLabel = (id) => (CATEGORIES.find((cat) => cat.id === id) || {}).la
129
133
  // strings, and overlays.js's label/note rows — so adding a level meant editing
130
134
  // three places, and the index a picker row reported was mapped back to a value
131
135
  // through whichever list happened to be in scope. EFFORT_VALUES is the picker's
132
- // own order, `null` first for "auto".
136
+ // own order: the three rungs, with no `auto` entry any more.
133
137
  const EFFORT_LEVELS = overlays.EFFORT_VALUES;
134
138
 
135
139
  // ── Small handler helpers ─────────────────────────────────────────────────────
@@ -145,7 +149,7 @@ const done = (c, text) => c.push({ role: 'done', text });
145
149
  // (single-model — the reference fans it out)" and handed the raw task to
146
150
  // c.runPrompt — a single turn, not a fan-out — while /multiyolo printed the
147
151
  // paste-ready panel and never executed anything at all, so its `savePermissions
148
- // ({ defaultMode: 'allow' })` turned YOLO on and then did nothing with it.
152
+ // ({ defaultMode: 'allow' })` turned automode on and then did nothing with it.
149
153
  //
150
154
  // The upstream engine calls `multiData(task, { signal })`, which
151
155
  // shells out to aegis-cli (`aegis --print "/multi <task>"`) because the fan-out
@@ -207,7 +211,7 @@ async function multiData(c, task) {
207
211
  }
208
212
 
209
213
  /**
210
- * Drive one of the three fan-out commands end to end. `yolo` is /multiyolo's
214
+ * Drive one of the three fan-out commands end to end. `automode` is /multiyolo's
211
215
  * edge: the permission mode is set to allow *and* the task then executes under
212
216
  * it (previously it was set and never used).
213
217
  */
@@ -217,7 +221,7 @@ async function runMultiCommand(c, task, { yolo = false, title = 'ÆGIS Multi' }
217
221
  // means "stop confirming", and that is now ONE fact in two stores rather than
218
222
  // a rule-file edit the window would never see.
219
223
  setConfirmPosture(false);
220
- panel(c, panels.buildYolo(c.state(), c.ctx));
224
+ panel(c, panels.buildAutomode(c.state(), c.ctx));
221
225
  }
222
226
  note(c, 'Running the multi-agent fan-out — the engine delegates to specialist subagents (headless: this skips aegis-cli\'s own confirmation step).');
223
227
  c.render();
@@ -392,6 +396,22 @@ const cloudReady = () => credentials.hasApiKey();
392
396
  */
393
397
  const { withByokAdditions } = require(resolveShared(path.join('client', 'byok-catalog.js')));
394
398
 
399
+ /**
400
+ * The models the USER declares (`client/user-models.js`) — the same file the
401
+ * desktop's Settings row writes, resolved by existence through the same
402
+ * `resolveShared` path and for the same reason: one store, three writers.
403
+ *
404
+ * `/byok` and `/models` read it here, and the CLI's own engine
405
+ * (`desktop/lib/local/engine.js` `listModels('byok')`, vendored into this
406
+ * package) applies it too, so the terminal's listing and the terminal's picker
407
+ * cannot disagree about which ids this machine offers.
408
+ */
409
+ const {
410
+ withUserModels,
411
+ addUserModel,
412
+ removeUserModel,
413
+ } = require(resolveShared(path.join('client', 'user-models.js')));
414
+
395
415
  /**
396
416
  * The server's BYOK provider catalog, or null when it cannot be reached.
397
417
  *
@@ -406,7 +426,13 @@ async function byokCatalog(client) {
406
426
  if (!client || typeof client.byokProviders !== 'function') return null;
407
427
  try {
408
428
  const data = await client.byokProviders();
409
- const providers = withByokAdditions((data && data.providers) || []);
429
+ // Two layers, in this order and for the same reason both exist: the
430
+ // shipped additions this repo maintains (`withByokAdditions`) and then the
431
+ // USER's own declarations (`withUserModels`). The user's layer is applied
432
+ // last because it is the most specific opinion — and because a user who
433
+ // declares an id the shipped list also carries still gets ONE row (both
434
+ // functions append only what is missing).
435
+ const providers = withUserModels(withByokAdditions((data && data.providers) || []));
410
436
  return providers.length ? providers : null;
411
437
  } catch {
412
438
  return null;
@@ -1056,6 +1082,25 @@ const COMMANDS = [
1056
1082
  // A model/class/effort change is a live session decision, not just a file
1057
1083
  // write; say so rather than leaving the user to wonder when it applies.
1058
1084
  if (['model', 'currentModelId', 'modelClass', 'effort', 'themeIndex', 'vim'].includes(res.key)) {
1085
+ // ...and for `effort` the session value is written here, not just
1086
+ // promised. `setConfigValue` touches the file only, so the note used to
1087
+ // announce a change that the very next turn did NOT make: the session
1088
+ // kept its old rung until a relaunch, which is one more way `/effort`
1089
+ // appeared to do nothing. Floored through effortRung, so a hand-written
1090
+ // `/config effort ultra` cannot put a rung on the wire that the engine
1091
+ // does not know.
1092
+ if (res.key === 'effort') {
1093
+ c.ctx.effort = effortRung(res.value);
1094
+ // Persist the FLOORED rung, not the raw argument: `effort` is a
1095
+ // shared key AEGIS Desktop reads too, and writing `bogus` would put a
1096
+ // level in that file which every reader has to floor again. rungTaken
1097
+ // reports the correction rather than letting the note claim a value
1098
+ // the turn did not take.
1099
+ if (c.ctx.effort !== String(res.value).toLowerCase()) {
1100
+ c.saveConfig({ effort: c.ctx.effort });
1101
+ note(c, ` "${res.value}" is not a level this build sends — recorded as ${c.ctx.effort}.`);
1102
+ }
1103
+ }
1059
1104
  note(c, ` This takes effect on the next turn; /${res.key === 'currentModelId' ? 'model' : res.key} shows the live session value.`);
1060
1105
  }
1061
1106
  c.render();
@@ -1063,27 +1108,35 @@ const COMMANDS = [
1063
1108
  },
1064
1109
  },
1065
1110
  {
1066
- name: 'effort', args: ['level'], hint: '[auto|low|medium|high]', category: 'model',
1111
+ name: 'effort', args: ['level'], hint: '[low|medium|high]', category: 'model',
1067
1112
  desc: 'Set the token budget the pool sizes each turn from',
1068
1113
  handler: async (c, args) => {
1069
1114
  const level = (args.level || '').toLowerCase();
1115
+ // Validated against EFFORT_LEVELS, which IS the picker's value list
1116
+ // (overlays.EFFORT_VALUES, aliased above) — the same array the rows are
1117
+ // drawn from, so a level the picker offers can never be rejected here.
1070
1118
  if (level && level !== 'auto' && !EFFORT_LEVELS.includes(level)) {
1071
- note(c, `Unknown effort level "${args.level}". Use auto, ${EFFORT_LEVELS.filter(Boolean).join(', ')}.`);
1119
+ note(c, `Unknown effort level "${args.level}". Use ${EFFORT_LEVELS.join(', ')}.`);
1072
1120
  c.render();
1073
1121
  return true;
1074
1122
  }
1075
1123
  if (!level) {
1076
- c.openOverlay({ type: 'effort', sel: Math.max(0, EFFORT_LEVELS.indexOf(c.ctx.effort)) });
1124
+ // The picker opens on the rung actually in force; a session whose
1125
+ // config predates the default lands on high, which is what the engine
1126
+ // applies to an unstored value.
1127
+ c.openOverlay({ type: 'effort', sel: Math.max(0, EFFORT_LEVELS.indexOf(c.ctx.effort || 'high')) });
1077
1128
  return true;
1078
1129
  }
1079
- // 'auto' is the absence of a pin, not a fourth rung: it is stored as null
1080
- // so nothing is sent and the server sizes the turn from the ask.
1081
- const pinned = level === 'auto' ? null : level;
1130
+ // `auto` is retired, not a fourth rung: it pinned nothing, and a fresh
1131
+ // install therefore sent no effort and the knob did nothing. It is still
1132
+ // ACCEPTED so an old habit (or a script) is not a hard error — it now
1133
+ // resolves to the default rung, and says so.
1134
+ const pinned = level === 'auto' ? 'high' : level;
1082
1135
  c.ctx.effort = pinned;
1083
1136
  c.saveConfig({ effort: pinned });
1084
- note(c, pinned
1085
- ? `Effort level: ${pinned} — the pool sizes this turn's token budget from it`
1086
- : 'Effort level: auto — the pool sizes each turn from the ask');
1137
+ note(c, level === 'auto'
1138
+ ? `effort: auto is retired — high is the default, and it is what this session now sends`
1139
+ : `Effort level: ${pinned} — the pool sizes this turn's token budget from it`);
1087
1140
  c.render();
1088
1141
  return true;
1089
1142
  },
@@ -2086,10 +2139,21 @@ const COMMANDS = [
2086
2139
  name: 'confirm', aliases: ['confirmations'], args: ['mode'], hint: '[on|off]', category: 'model',
2087
2140
  desc: 'Toggle tool-call confirmation prompts',
2088
2141
  handler: async (c, args) => {
2089
- const rules = loadPermissions();
2090
2142
  const mode = (args.mode || '').toLowerCase();
2091
2143
  if (mode && !['on', 'off'].includes(mode)) { note(c, 'Usage: /confirm [on|off]'); c.render(); return true; }
2092
- const want = mode === 'on' ? true : mode === 'off' ? false : rules.defaultMode !== 'allow';
2144
+ // ON8: the bare toggle reads the POSTURE (the shared `confirmMode` key
2145
+ // both faces write), never the rule file's `defaultMode`.
2146
+ //
2147
+ // Two reasons, and the second one is the user-visible bug. (1) Since ON8
2148
+ // the rule file holds the *residual* (`ask`/`allow`/`deny`) and the shared
2149
+ // key holds the posture — reading the residual would answer a question the
2150
+ // user did not ask, and `defaultMode: 'deny'` would read as "on". (2) The
2151
+ // old spelling (`rules.defaultMode !== 'allow'`) could be turned ON and
2152
+ // never OFF from the keyboard: `defaultMode` ships as 'ask', so a fresh
2153
+ // install already read as "on" and a bare `/confirm` wrote `ask` — the
2154
+ // same state it had just read — leaving prompts on with no way to toggle
2155
+ // them off. `confirmPosture()` is the one read, exactly like the engine's.
2156
+ const want = mode === 'on' ? true : mode === 'off' ? false : !confirmPosture().enabled;
2093
2157
  // ON8: one writer for the posture — the shared key the window's switch
2094
2158
  // reads, plus the rule residual this face's gate reads.
2095
2159
  setConfirmPosture(want);
@@ -2099,31 +2163,50 @@ const COMMANDS = [
2099
2163
  },
2100
2164
  },
2101
2165
  {
2102
- name: 'yolo', args: ['mode'], hint: '[on|off]', category: 'model',
2103
- desc: 'Toggle YOLO mode — auto-approve all tool executions',
2166
+ name: 'automode', aliases: ['yolo'], args: ['mode'], hint: '[on|off]', category: 'model',
2167
+ desc: 'Toggle automode — auto-approve all tool executions',
2104
2168
  handler: async (c, args) => {
2105
- const rules = loadPermissions();
2106
2169
  const mode = (args.mode || '').toLowerCase();
2107
- if (mode && !['on', 'off'].includes(mode)) { note(c, 'Usage: /yolo [on|off]'); c.render(); return true; }
2108
- const want = mode === 'on' ? true : mode === 'off' ? false : rules.defaultMode !== 'allow';
2109
- // ON8: `/yolo` is the posture's OFF state, written through the one writer,
2110
- // so the window's switch shows it and the two faces cannot disagree.
2170
+ if (mode && !['on', 'off'].includes(mode)) { note(c, 'Usage: /automode [on|off]'); c.render(); return true; }
2171
+ // Same one read as `/confirm` above, with the polarity this command's
2172
+ // label implies: "automode" IS confirmations-off, so the bare toggle is
2173
+ // `!automode` == the posture itself. Reading the rule file here wrongly
2174
+ // reported automode as already-on for a fresh install (whose residual
2175
+ // ships as 'ask'), so the first bare `/automode` turned it OFF — the
2176
+ // opposite of what the word means to the person typing it — and the
2177
+ // inverse mistake (`!confirmPosture().enabled`) made the first press a
2178
+ // no-op with confirmations on. Both spellings are gone.
2179
+ const want = mode === 'on' ? true : mode === 'off' ? false : confirmPosture().enabled;
2180
+ // ON8: `/automode` (alias `/yolo`) is the posture's OFF state, written
2181
+ // through the one writer, so the window's switch shows it and the two
2182
+ // faces cannot disagree.
2111
2183
  setConfirmPosture(!want);
2112
- if (want) panel(c, panels.buildYolo(c.state(), c.ctx));
2113
- else note(c, 'YOLO mode off — confirmations restored.');
2184
+ // …and the SESSION's own half. The posture answers "does the window's
2185
+ // switch say don't ask"; the session flag answers "did this sitting start
2186
+ // in auto mode". They are two facts (the upstream engine keeps them apart:
2187
+ // AEGIS_AUTO_ROUNDS=0 starts manual without touching any stored posture),
2188
+ // and with an env opt-out standing, writing only the posture made this
2189
+ // command — and the `→` chord that dispatches it — a no-op that reported
2190
+ // success: the store said "off", the chip still read "manual mode on", and
2191
+ // the tool gate in app.js's isYolo kept asking. Moving both here is what
2192
+ // makes the opt-out escapable at the prompt instead of for the life of the
2193
+ // process. Guarded because an injected/older context may not carry it.
2194
+ if (typeof c.setAutoRounds === 'function') c.setAutoRounds(want);
2195
+ if (want) panel(c, panels.buildAutomode(c.state(), c.ctx));
2196
+ else note(c, 'automode off — confirmations restored.');
2114
2197
  c.render();
2115
2198
  return true;
2116
2199
  },
2117
2200
  },
2118
2201
  {
2119
- name: 'multiyolo', args: ['task'], hint: '<task>', category: 'session',
2120
- desc: 'Multi-agent orchestration with YOLO mode — /multiyolo <task>',
2202
+ name: 'multiyolo', aliases: ['multiauto'], args: ['task'], hint: '<task>', category: 'session',
2203
+ desc: 'Multi-agent orchestration with automode — /multiyolo <task>',
2121
2204
  handler: async (c, args) => {
2122
2205
  const task = (args._rest || args.task || '').trim();
2123
2206
  if (!task) { note(c, 'Usage: /multiyolo <task>'); c.render(); return true; }
2124
- // YOLO is the point of this alias: auto-approve, then actually run the
2207
+ // automode is the point of this alias: auto-approve, then actually run the
2125
2208
  // fan-out. Composing the text and stopping (what this used to do) left the
2126
- // user with an enabled YOLO mode and an unexecuted task.
2209
+ // user with an enabled automode and an unexecuted task.
2127
2210
  return runMultiCommand(c, task, { yolo: true });
2128
2211
  },
2129
2212
  },
@@ -2910,6 +2993,144 @@ const COMMANDS = [
2910
2993
  return true;
2911
2994
  },
2912
2995
  },
2996
+ {
2997
+ // ── the user's own model declarations ──────────────────────────────────
2998
+ //
2999
+ // The ONE thing this repo could not do before: a provider ships a model on
3000
+ // Tuesday and the user can call it from a BYOK key that same day. The BYOK
3001
+ // relay is a stateless pass-through — the caller's own vendor key
3002
+ // authenticates upstream and AEGIS forwards whatever model string it was
3003
+ // given — so any id the vendor serves is callable the moment this machine
3004
+ // offers it as a row, and this command is how it becomes one without a
3005
+ // release.
3006
+ //
3007
+ // Written through `client/user-models.js`, which is also what the desktop's
3008
+ // Settings row writes and what the shared engine applies to
3009
+ // `listModels('byok')`, so `/models` and the alt+p picker show the row on
3010
+ // the next refresh and the window shows it on ITS next refresh. The file is
3011
+ // printed on success, because a hand-edit is the bulk path and a store the
3012
+ // user cannot find is a store they will not use.
3013
+ name: 'model-add', aliases: ['add-model'], args: ['provider'], hint: '<provider> <model-id>',
3014
+ category: 'model',
3015
+ desc: 'Offer a model id the AEGIS catalog does not name (your key, both faces)',
3016
+ handler: async (c, a) => {
3017
+ const args = a || {};
3018
+ const typed = String(args.provider || '').trim();
3019
+ if (!typed) {
3020
+ c.push({ role: 'error', text: 'Usage: /model-add <provider> <model-id> — /byok lists the providers.' });
3021
+ return true;
3022
+ }
3023
+ const rest = String(args._rest || '').trim();
3024
+ const sp = rest.indexOf(' ');
3025
+ let model = sp === -1 ? '' : rest.slice(sp + 1).trim();
3026
+ if (!model) {
3027
+ // Plain inline input, NOT readSecret: a model id is not a secret, and
3028
+ // hiding it would make a typo unreviewable before it is stored.
3029
+ model = String((await c.askInput(`model id for ${typed}: `)) || '').trim();
3030
+ }
3031
+ if (!model) {
3032
+ c.push({ role: 'note', text: 'nothing saved.' });
3033
+ return true;
3034
+ }
3035
+ // Resolve the provider against the relay's catalog first. A slug the
3036
+ // server does not list can never be attached to a key, so storing it
3037
+ // would produce a declaration that is invisible in every picker — the
3038
+ // silent no-op this whole path is meant to avoid. When the catalog is
3039
+ // unreachable the declaration is kept and SAID to be unverified, because
3040
+ // refusing to work offline is worse than a row that appears later.
3041
+ const providers = await byokCatalog(c.client);
3042
+ const match = providers ? findByokProvider(providers, typed) : null;
3043
+ if (match && match.ambiguous) {
3044
+ c.push({ role: 'error', text: `"${typed}" matches ${match.ambiguous.join(', ')} — retype the exact id.` });
3045
+ return true;
3046
+ }
3047
+ if (providers && !(match && match.provider)) {
3048
+ c.push({
3049
+ role: 'error',
3050
+ text: `no provider "${typed}" in the relay's catalog — /byok lists the ones it takes a key for.`,
3051
+ });
3052
+ return true;
3053
+ }
3054
+ const id = (match && match.provider && match.provider.id) || typed.toLowerCase();
3055
+ let res;
3056
+ try {
3057
+ res = addUserModel(id, model);
3058
+ } catch (err) {
3059
+ c.push({ role: 'error', text: (err && err.message) || String(err) });
3060
+ return true;
3061
+ }
3062
+ // The picker's cache (app.js `byokCache`, 5 minutes) is older than the
3063
+ // file the instant it is written, so refresh it here: a user who adds a
3064
+ // model and types `/models` must see it, not "already listed" five
3065
+ // minutes later.
3066
+ if (typeof c.refreshByokModels === 'function') {
3067
+ try {
3068
+ await c.refreshByokModels();
3069
+ } catch {
3070
+ /* the next refresh reads the file anyway */
3071
+ }
3072
+ }
3073
+ const rows = (typeof c.listModelsFor === 'function' ? (await c.listModelsFor('byok')) : []) || [];
3074
+ const row = rows.find((m) => m && m.id === `${id}:${model}`);
3075
+ c.push({
3076
+ role: res.added ? 'done' : 'note',
3077
+ text: res.added
3078
+ ? `added ${id}:${model} — offered on this machine now, in the CLI and the desktop.`
3079
+ : `${id}:${model} was already declared.`,
3080
+ });
3081
+ if (!providers) {
3082
+ c.push({
3083
+ role: 'note',
3084
+ text: `the relay's catalog could not be read, so "${id}" is unverified — if it does not appear in /models, /byok lists the provider ids it takes.`,
3085
+ });
3086
+ }
3087
+ if (res.added && !row) {
3088
+ c.push({
3089
+ role: 'note',
3090
+ text: `saved, but no row will be offered for "${id}" yet — the relay lists no provider of that id (or that provider lists no models).`,
3091
+ });
3092
+ }
3093
+ c.push({ role: 'note', text: `stored in ${res.file} — the desktop reads the same file.` });
3094
+ return true;
3095
+ },
3096
+ },
3097
+ {
3098
+ name: 'model-rm', aliases: ['rm-model'], args: ['provider'], hint: '<provider> <model-id>',
3099
+ category: 'model',
3100
+ desc: 'Forget a model id you added with /model-add',
3101
+ handler: async (c, a) => {
3102
+ const args = a || {};
3103
+ const typed = String(args.provider || '').trim();
3104
+ const rest = String(args._rest || '').trim();
3105
+ const sp = rest.indexOf(' ');
3106
+ const model = sp === -1 ? '' : rest.slice(sp + 1).trim();
3107
+ if (!typed || !model) {
3108
+ c.push({ role: 'error', text: 'Usage: /model-rm <provider> <model-id> — /model-add lists what you added.' });
3109
+ return true;
3110
+ }
3111
+ let res;
3112
+ try {
3113
+ res = removeUserModel(typed, model);
3114
+ } catch (err) {
3115
+ c.push({ role: 'error', text: (err && err.message) || String(err) });
3116
+ return true;
3117
+ }
3118
+ if (typeof c.refreshByokModels === 'function') {
3119
+ try {
3120
+ await c.refreshByokModels();
3121
+ } catch {
3122
+ /* the next refresh reads the file anyway */
3123
+ }
3124
+ }
3125
+ c.push({
3126
+ role: res.removed ? 'done' : 'note',
3127
+ text: res.removed
3128
+ ? `removed ${res.provider}:${res.model} — the picker stops offering it on the next refresh.`
3129
+ : `${res.provider}:${res.model} was not declared on this machine.`,
3130
+ });
3131
+ return true;
3132
+ },
3133
+ },
2913
3134
  {
2914
3135
  name: 'tool', args: ['name', 'json'], hint: '<name> [json]', category: 'aegis',
2915
3136
  desc: 'Call any registry tool directly (escape hatch for new tools)',
@@ -89,12 +89,15 @@ const DEFAULT_CONFIG = {
89
89
  // aegiscode- name so /model add/remove/switch stay compatible both ways.
90
90
  models: null,
91
91
  currentModelId: null,
92
- // `null` = no effort pinned, i.e. "auto": each turn is sized by the server
93
- // from the ask itself (aegis1 services/pool_brain.py estimate_effort). The
94
- // old 'high' was a *pin* on the top rung of the budget ladder — the most the
95
- // server can grant — so the CLI's default turn was the most expensive one it
96
- // could make, and /effort could only ever move it down.
97
- effort: null,
92
+ // The effort rung every turn is sized from, stored as a real level so the
93
+ // value read back is the value sent. It used to be `null` ("auto": send no
94
+ // rung and let the server infer one from the ask), which made the DEFAULT a
95
+ // no-op — a fresh install carried no effort at all, so low/medium/high only
96
+ // ever changed the status line. `high` is the rung the engine and the desktop
97
+ // resolve an absent value to, so the default is now stated rather than
98
+ // implied. Anything unreadable (null, a stale 'auto', junk) is coerced to
99
+ // `high` by effortRung() in cli/src/engine.js before it reaches the wire.
100
+ effort: 'high',
98
101
  vim: false,
99
102
  lastCwd: '',
100
103
  };
@@ -279,7 +282,7 @@ function loadConfig() {
279
282
  * have written `undefined` — which `prefs.set()` drops. Every unrelated config
280
283
  * save (`/theme`, onboarding, an update-check cache write) would then DELETE the
281
284
  * gate's one shared copy, silently reverting the window's switch and the shell's
282
- * `/yolo` to the rule file on the next launch. And filling it with `true` instead
285
+ * `/automode` (alias `/yolo`) to the rule file on the next launch. And filling it with `true` instead
283
286
  * would be worse, not better: an install whose desktop still holds a legacy
284
287
  * `__confirmMode: { enabled: false }` would be flipped ON by the first CLI save,
285
288
  * which is exactly the migration `client/prefs.js`'s `adopt()` exists to get
@@ -390,6 +393,32 @@ function savePermissions(rules) {
390
393
  return rules;
391
394
  }
392
395
 
396
+ /**
397
+ * Write the rule file's residual mode WITHOUT the DERIVED `explicitAsk` field.
398
+ *
399
+ * `explicitAsk` is computed by loadPermissions() from `defaultMode`; it is a
400
+ * read-time derivation, not stored state. Spreading `{ ...loadPermissions() }`
401
+ * carries the value derived from the file being replaced, so `/confirm on` used
402
+ * to leave `{"defaultMode":"ask","explicitAsk":false}` — a file that denies the
403
+ * very field it sets — and `/confirm off` left `{"defaultMode":"allow",
404
+ * "explicitAsk":true}`, which is worse: two fields disagreeing about whether
405
+ * the user ever asked to be prompted.
406
+ *
407
+ * Harmless only while every reader recomputes (loadPermissions does), and a real
408
+ * bug the moment one does not: `one/src/permissions.js` builds its rule set from
409
+ * the file's `explicitAsk` as well as its `defaultMode`, and an operator reading
410
+ * permissions.json to answer "is confirmation on?" reads the stale line. Every
411
+ * writer here goes through this, so the file always says exactly one thing.
412
+ *
413
+ * This mirrors the engine's `persistRules` (aegiscodex-dev src/registry.js,
414
+ * commit e7bb9db, "a switch that turns off"); the plugin's CLI face was the copy
415
+ * that never got it.
416
+ */
417
+ function saveRuleMode(mode) {
418
+ const { explicitAsk, ...rest } = loadPermissions();
419
+ return savePermissions({ ...rest, defaultMode: mode });
420
+ }
421
+
393
422
  /**
394
423
  * Add a rule to a permission list if not already present.
395
424
  * Returns { added, rules } — added is false when the rule already exists.
@@ -466,8 +495,8 @@ function confirmPosture() {
466
495
  /**
467
496
  * Set the posture: the shared key (both faces) + the rule file's residual.
468
497
  *
469
- * Called by every command that means "confirmations on/off" — /confirm, /yolo,
470
- * /multiyolo and the flag the desktop's switch mirrors — so there is exactly one
498
+ * Called by every command that means "confirmations on/off" — /confirm,
499
+ * /automode (alias /yolo), /multiyolo and the flag the desktop's switch mirrors — so there is exactly one
471
500
  * writer per fact and no command can leave the two stores disagreeing.
472
501
  */
473
502
  function setConfirmPosture(enabled) {
@@ -477,7 +506,7 @@ function setConfirmPosture(enabled) {
477
506
  } catch (e) {
478
507
  if (process.env.AEGIS_HIST_DEBUG) console.error('[prefs] write failed:', e);
479
508
  }
480
- savePermissions({ ...loadPermissions(), defaultMode: want ? 'ask' : 'allow' });
509
+ saveRuleMode(want ? 'ask' : 'allow');
481
510
  return want;
482
511
  }
483
512
 
@@ -497,7 +526,7 @@ function setPermissionDefaultMode(mode) {
497
526
  } catch (e) {
498
527
  if (process.env.AEGIS_HIST_DEBUG) console.error('[prefs] write failed:', e);
499
528
  }
500
- savePermissions({ ...loadPermissions(), defaultMode: want });
529
+ saveRuleMode(want);
501
530
  return want;
502
531
  }
503
532
 
@@ -519,6 +548,7 @@ module.exports = {
519
548
  DEFAULT_PERMISSIONS,
520
549
  loadPermissions,
521
550
  savePermissions,
551
+ saveRuleMode,
522
552
  addPermissionRule,
523
553
  removePermissionRule,
524
554
  confirmPosture,
@@ -63,7 +63,7 @@ const CLASS_LABELS = Object.freeze({
63
63
  * @param {object} client A client from client/aegis.js (createClient()).
64
64
  * @param {() => boolean} getConfirmMode Whether mutating tools (exec,
65
65
  * writeFile, editFile) require approval before running. Read per call, so
66
- * toggling it (/permissions, /yolo) takes effect on the next tool round.
66
+ * toggling it (/permissions, /automode) takes effect on the next tool round.
67
67
  * @param {() => string} getClass Which class the next turn runs on — read per
68
68
  * call for the same reason getConfirmMode is: /class must take effect on the
69
69
  * very next turn, not on the next launch.
@@ -71,8 +71,9 @@ const CLASS_LABELS = Object.freeze({
71
71
  * (and by app.js, so one store serves both the engine and the commands);
72
72
  * otherwise created against the CLI's data dir.
73
73
  * @returns {{chat: Function, cancel: Function, respondApproval: Function,
74
- * clearSessionApprovals: Function, listClasses: Function, listModels: Function,
75
- * classLabel: Function, getClass: Function, setClass: Function, settings: object}}
74
+ * respondRoundsAsk: Function, clearSessionApprovals: Function, listClasses: Function,
75
+ * listModels: Function, classLabel: Function, getClass: Function, setClass: Function,
76
+ * settings: object}}
76
77
  */
77
78
  function createEngine({ client, getConfirmMode, getClass, settings: injectedSettings } = {}) {
78
79
  const settings = injectedSettings || createSettingsStore({ dir: credentials.aegisHome() });
@@ -114,6 +115,7 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
114
115
  chat,
115
116
  cancel: local.cancel,
116
117
  respondApproval: local.respondApproval,
118
+ respondRoundsAsk: local.respondRoundsAsk,
117
119
  clearSessionApprovals: local.clearSessionApprovals,
118
120
  // The engine's own class table, narrowed to the ones this host runs — so a
119
121
  // UI built from listClasses() can never offer a class that would throw.
@@ -139,4 +141,31 @@ function byokNamespace(provider) {
139
141
  return `byok:${provider}`;
140
142
  }
141
143
 
142
- module.exports = { createEngine, HOST_CLASSES, DEFAULT_CLASS, CLASS_LABELS, byokNamespace };
144
+ /**
145
+ * The effort rung a turn travels with: always 'low' | 'medium' | 'high'.
146
+ *
147
+ * This host has exactly three levels and every one of them must reach the wire,
148
+ * so the normalisation lives here — on the path from session state to request —
149
+ * rather than in the renderers. An absent, empty, `null` or retired `auto`
150
+ * value resolves to `high`, the rung the desktop's select defaults to and the
151
+ * one the shared engine applies to an unstated effort (desktop/lib/local/
152
+ * engine.js reasoningBudget/nativeEffort both floor to high).
153
+ *
154
+ * WHY THIS IS NOT OPTIONAL: the pooled dispatch in the shared engine states the
155
+ * rung conditionally (`...(opts.effort ? { effort: opts.effort } : {})`), and
156
+ * the BYOK dispatch translates it (nativeEffort). A falsy value therefore is
157
+ * not "the default" — it is "state no opinion", and the server then sizes the
158
+ * turn itself. `auto` was the CLI's DEFAULT, so the default turn was the one
159
+ * turn that sent nothing: /effort changed the status line and nothing else.
160
+ *
161
+ * Mirrors effortRung() in desktop/renderer/budget.js (and the `=== 'low' ||
162
+ * === 'medium' ? : 'high'` floor in the shared engine). Carried rather than
163
+ * shared because the CLI must not require the renderer bundle — the same reason
164
+ * cli/src/tokens.js re-exports the shared usage folds instead of reaching into
165
+ * desktop/.
166
+ */
167
+ function effortRung(effort) {
168
+ return effort === 'low' || effort === 'medium' ? effort : 'high';
169
+ }
170
+
171
+ module.exports = { createEngine, HOST_CLASSES, DEFAULT_CLASS, CLASS_LABELS, byokNamespace, effortRung };
@@ -44,6 +44,10 @@
44
44
  */
45
45
 
46
46
  const { resolveShared } = require('./sharedpaths.js');
47
+ // The renderers' waiver rule, published to on every reading this gate takes —
48
+ // see `createCliEntitlement` below. `format.js` requires nothing from here, so
49
+ // this is a one-way edge and not a cycle.
50
+ const { noteTier } = require('./format.js');
47
51
 
48
52
  /** The shared decision, resolved by existence (repo checkout or staged tree). */
49
53
  function loadModule() {
@@ -97,12 +101,37 @@ function buildProbe(aegis) {
97
101
  function createCliEntitlement({ aegis, now, ttlMs } = {}) {
98
102
  const mod = loadModule();
99
103
  const client = aegis || loadClient();
100
- return mod.createEntitlement({
104
+ const gate = mod.createEntitlement({
101
105
  probe: buildProbe(client),
102
106
  host: 'cli',
103
107
  ...(now ? { now } : {}),
104
108
  ...(ttlMs ? { ttlMs } : {}),
105
109
  });
110
+ // Publish every reading this gate takes to the renderers' waiver rule
111
+ // (`format.js` → `feeWaived`). The gate is what decides whether a turn is
112
+ // ALLOWED; the waiver decides whether a `€0.0031` is PRINTED under it, and the
113
+ // two reading different tiers is how a trial account ended up shown a fee it
114
+ // does not owe. Wrapping the instance rather than returning a copy keeps the
115
+ // method identity the rest of the host already holds a reference to.
116
+ if (gate && typeof gate.current === 'function') {
117
+ const read = gate.current.bind(gate);
118
+ try {
119
+ gate.current = (...args) => {
120
+ const snap = read(...args);
121
+ noteTier(snap);
122
+ return snap;
123
+ };
124
+ if (typeof gate.refresh === 'function') {
125
+ const refresh = gate.refresh.bind(gate);
126
+ gate.refresh = async (...args) => {
127
+ const out = await refresh(...args);
128
+ try { noteTier(read()); } catch { /* a failed read publishes nothing */ }
129
+ return out;
130
+ };
131
+ }
132
+ } catch { /* a frozen instance is readable, just not publishable */ }
133
+ }
134
+ return gate;
106
135
  }
107
136
 
108
137
  // ── the payment surface ─────────────────────────────────────────────────────