aegiscode 7.0.4 → 7.0.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "7.0.4",
4
+ "version": "7.0.6",
5
5
  "description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
package/src/app.js CHANGED
@@ -26,7 +26,7 @@
26
26
  const readline = require('node:readline');
27
27
  const os = require('node:os');
28
28
  const { randomUUID } = require('node:crypto');
29
- const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, hostEnv, autonomous } = require('./deps.js');
29
+ const { createTools, createClient, usageTokens, usageBuckets, buildSystemPrompt, autoProvisionApiKey, provisionFailureText, hostEnv, autonomous } = require('./deps.js');
30
30
  const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace, effortRung } = require('./engine.js');
31
31
  const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE, AUTO_THEME_INDEX, themeIsLight, reconcileThemeIndex } = require('./theme.js');
32
32
  const { probeTerminalBackground } = require('./caps.js');
@@ -145,20 +145,27 @@ function createApp(options = {}) {
145
145
  // With no key configured anywhere, ask aegis1 for a free device key before
146
146
  // ever showing "no key" — same shared helper (client/auto-provision.js) the
147
147
  // MCP plugin and the desktop app use, so all three ask for the same account
148
- // on the same machine. One attempt per `createApp()` instance, not one per
149
- // call: register-device is rate-limited server-side, and a session that
148
+ // on the same machine. One provisioning per `createApp()` instance, not one
149
+ // per call: register-device is rate-limited server-side, and a session that
150
150
  // fires several turns before noticing a failure must not retry the same
151
- // failing call each time. A brand-new fingerprint comes back with aegis1's
151
+ // failing call each time. A transient failure gets a few bounded retries
152
+ // inside that one provisioning. A brand-new fingerprint comes back with aegis1's
152
153
  // one-time 30-day welcome-trial `unlimited` entitlement (token-bank credit
153
154
  // plus a `subscriptions` row) granted in the same request — aegis1 commit
154
155
  // 4372830 — so the account is usable pooled right away rather than starting
155
156
  // at zero. The credit is finite: once it is spent or the trial lapses, the
156
157
  // usual plan/balance gate applies.
157
158
  let provisionAttempted = false;
159
+ let keyFailure = '';
160
+ async function provisionDeviceKey() {
161
+ const result = await autoProvisionApiKey(client, credentials);
162
+ keyFailure = result.key ? '' : provisionFailureText(result);
163
+ return result;
164
+ }
158
165
  async function ensureApiKey() {
159
166
  if (client.apiKey || provisionAttempted) return;
160
167
  provisionAttempted = true;
161
- const result = await autoProvisionApiKey(client, credentials);
168
+ const result = await provisionDeviceKey();
162
169
  if (result.key) {
163
170
  emit(
164
171
  render.renderNotice(
@@ -543,6 +550,12 @@ function createApp(options = {}) {
543
550
  return res;
544
551
  }
545
552
 
553
+ /** Explicit `/key register`: unlike the automatic path, this runs again after a failure. */
554
+ async function registerAccount() {
555
+ if (client.apiKey) return { alreadyKeyed: true };
556
+ return provisionDeviceKey();
557
+ }
558
+
546
559
  /**
547
560
  * The persisting-memory gate — the WRITE half of aegis_memory, and now ON by
548
561
  * default for every account (see config.js `memoryPersistState` for the
@@ -1475,6 +1488,7 @@ function createApp(options = {}) {
1475
1488
  keyStatus: () => credentials.keyStatus(),
1476
1489
  setApiKey: (raw, o) => setApiKey(raw, o),
1477
1490
  forgetApiKey: () => forgetApiKey(),
1491
+ registerAccount: () => registerAccount(),
1478
1492
  readSecret: (text) => readSecret(text, { stdin: process.stdin, stdout: out }),
1479
1493
  cloudsync,
1480
1494
  cloudSyncEnabled: () => cloudSyncEnabled(),
@@ -2022,6 +2036,7 @@ function createApp(options = {}) {
2022
2036
  wantExit = true;
2023
2037
  },
2024
2038
  wantsExit: () => wantExit,
2039
+ keyNotice: () => (client.apiKey ? '' : keyFailure),
2025
2040
  isYolo: () => {
2026
2041
  // Both halves, in the order the desktop host reads them
2027
2042
  // (main.js autoRoundsOn): "this session runs auto mode" AND "the
package/src/chatflow.js CHANGED
@@ -353,6 +353,8 @@ function statusLine(state, cols, ctx) {
353
353
  left = [span(t.gray, ` ${GLYPH.bullet} esc to interrupt`)];
354
354
  } else if (state.streamJob) {
355
355
  left = [span(t.gray, `${GLYPH.bullet} esc to stop`)];
356
+ } else if (state.keyNotice) {
357
+ left = [span(t.gray, ` ${GLYPH.bullet} no AEGIS key: ${state.keyNotice} ${GLYPH.bullet} /key register to retry`)];
356
358
  } else if (state.yolo) {
357
359
  left = [span(t.gray, `${GLYPH.bullet} automode on ${GLYPH.bullet} ${autoContinueLimit()} rounds then it asks ${GLYPH.bullet} ? for shortcuts ${GLYPH.bullet} ${GLYPH.rightarrow} for manual mode`)];
358
360
  } else {
@@ -1150,7 +1152,7 @@ async function runSession(host) {
1150
1152
  );
1151
1153
  lines.push(inp.line);
1152
1154
  lines.push(separatorLine(cols, ctx));
1153
- lines.push(statusLine({ working, inputPrompt, streamJob, yolo: host.isYolo && host.isYolo() }, cols, ctx));
1155
+ lines.push(statusLine({ working, inputPrompt, streamJob, yolo: host.isYolo && host.isYolo(), keyNotice: host.keyNotice && host.keyNotice() }, cols, ctx));
1154
1156
  return { lines, inputCol: inp.cursorCol, rows, inputRow: rows - 2 };
1155
1157
  };
1156
1158
 
@@ -1935,7 +1937,7 @@ async function runSession(host) {
1935
1937
  ).length;
1936
1938
  }
1937
1939
  if (overlay.type === 'model' || overlay.type === 'resume') return (overlay.items || []).length;
1938
- if (overlay.type === 'effort') return 3;
1940
+ if (overlay.type === 'effort') return overlays.EFFORT_VALUES.length;
1939
1941
  return 0;
1940
1942
  };
1941
1943
 
@@ -2037,6 +2039,26 @@ async function runSession(host) {
2037
2039
  await collectKeyFor(chosen);
2038
2040
  };
2039
2041
 
2042
+ /**
2043
+ * Pin an effort rung — the ONE path a rung is applied through, shared by
2044
+ * Enter, shift+enter and the shift+arrow chords.
2045
+ *
2046
+ * It resolves the row through the picker's OWN table (overlays.EFFORT_VALUES),
2047
+ * which is the point: this used to re-declare ['low','medium','high'] at each
2048
+ * commit site while the picker drew its own list, so the row a user picked and
2049
+ * the value the session stored came from two different lists. A rung the
2050
+ * picker does not draw can no longer be stored, and a row it does draw can no
2051
+ * longer store a different value than the one it painted.
2052
+ */
2053
+ const applyEffortRow = (sel) => {
2054
+ const chosen = overlays.EFFORT_VALUES[sel || 0];
2055
+ overlay = null;
2056
+ ctx.effort = chosen || 'high';
2057
+ host.updateConfig({ effort: ctx.effort });
2058
+ note(`effort: ${ctx.effort}`);
2059
+ render();
2060
+ };
2061
+
2040
2062
  const handleOverlayKey = async (key) => {
2041
2063
  const type = overlay.type;
2042
2064
  if (key.name === KEY.ESC || key.name === KEY.CTRL_C) {
@@ -2062,11 +2084,16 @@ async function runSession(host) {
2062
2084
  }
2063
2085
  return;
2064
2086
  }
2065
- if (key.name === KEY.TAB && type === 'model') {
2087
+ if (key.name === KEY.TAB && (type === 'model' || type === 'effort')) {
2066
2088
  // Reference parity (aegiscodex-dev/src/main.js's model overlay cycles on
2067
- // Tab). It is also the one way to walk the list that survives a link
2089
+ // Tab). It is also the one way to walk either picker that survives a link
2068
2090
  // where arrow escapes are eaten, since Tab is a single control byte.
2069
- const n = (overlay.items || []).length;
2091
+ // Both lists are addressed the one way each of them can be: the catalogue
2092
+ // lives in `overlay.items`, while the rungs are the picker's own table —
2093
+ // the same table Enter and shift+enter resolve through.
2094
+ const n = type === 'model'
2095
+ ? (overlay.items || []).length
2096
+ : overlays.EFFORT_VALUES.length;
2070
2097
  if (n) {
2071
2098
  overlay.sel = ((overlay.sel || 0) + 1) % n;
2072
2099
  render();
@@ -2098,13 +2125,8 @@ async function runSession(host) {
2098
2125
  // The picker's own order, not a second copy of the level names: this
2099
2126
  // used to re-declare ['low','medium','high'] here while the picker drew
2100
2127
  // its own table, so the row a user picked and the value it stored were
2101
- // resolved through different lists.
2102
- const chosen = overlays.EFFORT_VALUES[overlay.sel || 0];
2103
- overlay = null;
2104
- ctx.effort = chosen || 'high';
2105
- host.updateConfig({ effort: ctx.effort });
2106
- note(`effort: ${ctx.effort}`);
2107
- render();
2128
+ // resolved through different lists. (See applyEffortRow.)
2129
+ applyEffortRow(overlay.sel || 0);
2108
2130
  return;
2109
2131
  }
2110
2132
  if (type === 'resume') {
@@ -2138,12 +2160,7 @@ async function runSession(host) {
2138
2160
  return;
2139
2161
  }
2140
2162
  if (type === 'effort') {
2141
- const chosen = overlays.EFFORT_VALUES[overlay.sel || 0];
2142
- overlay = null;
2143
- ctx.effort = chosen || 'high';
2144
- host.updateConfig({ effort: ctx.effort });
2145
- note(`effort: ${ctx.effort}`);
2146
- render();
2163
+ applyEffortRow(overlay.sel || 0);
2147
2164
  return;
2148
2165
  }
2149
2166
  render();
@@ -2171,12 +2188,7 @@ async function runSession(host) {
2171
2188
  return;
2172
2189
  }
2173
2190
  if (type === 'effort') {
2174
- const chosen = overlays.EFFORT_VALUES[overlay.sel || 0];
2175
- overlay = null;
2176
- ctx.effort = chosen || 'high';
2177
- host.updateConfig({ effort: ctx.effort });
2178
- note(`effort: ${ctx.effort}`);
2179
- render();
2191
+ applyEffortRow(overlay.sel || 0);
2180
2192
  return;
2181
2193
  }
2182
2194
  return;
@@ -2204,25 +2216,17 @@ async function runSession(host) {
2204
2216
  render();
2205
2217
  return;
2206
2218
  }
2219
+ // There is deliberately NO shift+w / shift+s chord here. It existed (it
2220
+ // arrived as the bare chars 'W'/'S' — a real signal that survives links
2221
+ // which eat CSI arrow escapes) and it was removed on request: one
2222
+ // navigation binding is all these pickers need, and Tab already is that
2223
+ // binding — a single control byte, so it survives the same transports the
2224
+ // letter chord was there for, without a second way to move that then has
2225
+ // to be kept in step with the first. Tab cycles (above), Enter pins,
2226
+ // shift+↑/↓ pins as it moves for terminals that send CSI modifier 2, and
2227
+ // a plain uppercase letter in a picker now does nothing at all — it falls
2228
+ // through to the row-number branch below, which correctly ignores it.
2207
2229
  if (type === 'model') {
2208
- // Shift+W / Shift+S arrive as the plain chars 'W'/'S' — unlike a bare
2209
- // Shift press, shift+letter is a real, universally-sent terminal
2210
- // signal (the terminal just sends the uppercase letter), so this is
2211
- // the one "shift + something" chord that works everywhere arrow keys
2212
- // might not (e.g. over some remote links/multiplexers that eat CSI
2213
- // arrow sequences but pass plain chars through fine). Routes through
2214
- // the same move-and-pin step the arrow keys use.
2215
- if (key.ch === 'W' || key.ch === 'S') {
2216
- const step = key.ch === 'W' ? -1 : 1;
2217
- const max = Math.max(0, overlayRowCount() - 1);
2218
- overlay.sel = Math.min(max, Math.max(0, (overlay.sel || 0) + step));
2219
- const chosen = (overlay.items || [])[overlay.sel || 0];
2220
- overlay = null;
2221
- render();
2222
- await applyModelRow(chosen);
2223
- render();
2224
- return;
2225
- }
2226
2230
  const idx = parseInt(key.ch, 10);
2227
2231
  const items = overlay.items || [];
2228
2232
  if (Number.isFinite(idx) && idx >= 1 && idx <= items.length) {
@@ -2232,8 +2236,14 @@ async function runSession(host) {
2232
2236
  return;
2233
2237
  }
2234
2238
  if (type === 'effort' || type === 'resume') {
2239
+ // Bounded by the same row count every other mover is bounded by. A row
2240
+ // number past the end used to be accepted unseen (`sel = idx - 1` with
2241
+ // no upper clamp), so '9' in /effort parked the highlight off the list
2242
+ // and Enter then stored the 'high' fallback for a row that was never
2243
+ // drawn — silently, since nothing was highlighted to contradict it.
2235
2244
  const idx = parseInt(key.ch, 10);
2236
- if (Number.isFinite(idx) && idx >= 1) {
2245
+ const n = overlayRowCount();
2246
+ if (Number.isFinite(idx) && idx >= 1 && idx <= n) {
2237
2247
  overlay.sel = idx - 1;
2238
2248
  render();
2239
2249
  }
package/src/commands.js CHANGED
@@ -2695,7 +2695,7 @@ const COMMANDS = [
2695
2695
  },
2696
2696
  },
2697
2697
  {
2698
- name: 'key', aliases: ['apikey', 'api-key'], args: ['value'], hint: '[<api_key>|status|clear]', category: 'auth',
2698
+ name: 'key', aliases: ['apikey', 'api-key'], args: ['value'], hint: '[<api_key>|status|clear|register]', category: 'auth',
2699
2699
  desc: 'Save or show the AEGIS account key',
2700
2700
  handler: async (c, args) => {
2701
2701
  const arg = String(args.value || args._rest || '').trim();
@@ -2705,6 +2705,20 @@ const COMMANDS = [
2705
2705
  c.render();
2706
2706
  return true;
2707
2707
  }
2708
+ if (lower === 'register') {
2709
+ const res = await c.registerAccount();
2710
+ if (res.alreadyKeyed) {
2711
+ note(c, 'this machine already has an AEGIS key — /key status shows it');
2712
+ } else if (res.key && res.ok) {
2713
+ done(c, 'AEGIS account key provisioned and saved');
2714
+ } else if (res.key) {
2715
+ note(c, 'the account was created but its key could not be saved — run /key <api_key> with the key from aegiscloud.org');
2716
+ } else {
2717
+ note(c, `could not register this machine: ${res.error ? res.error.message : 'the server returned no account key'}`);
2718
+ }
2719
+ c.render();
2720
+ return true;
2721
+ }
2708
2722
  if (lower === 'clear' || lower === 'remove' || lower === 'rm') {
2709
2723
  const res = c.forgetApiKey();
2710
2724
  done(c, res.cleared ? `key removed from ${res.path}` : 'there was no saved key to remove');
package/src/deps.js CHANGED
@@ -83,7 +83,7 @@ const { buildSystemPrompt } = require(promptPath);
83
83
  const updater = require(updatePath);
84
84
  const queue = require(queuePath);
85
85
  const autonomous = require(autonomousPath);
86
- const { autoProvisionApiKey } = require(autoProvisionPath);
86
+ const { autoProvisionApiKey, provisionFailureText } = require(autoProvisionPath);
87
87
 
88
88
  module.exports = {
89
89
  resolveShared,
@@ -106,6 +106,7 @@ module.exports = {
106
106
  queue,
107
107
  autonomous,
108
108
  autoProvisionApiKey,
109
+ provisionFailureText,
109
110
  paths: { client: clientPath, tools: toolsPath, usage: usagePath, engine: enginePath, settings: settingsPath, agents: agentsPath, prompt: promptPath, update: updatePath, queue: queuePath, autonomous: autonomousPath, autoProvision: autoProvisionPath },
110
111
  roots,
111
112
  };
package/src/overlays.js CHANGED
@@ -139,6 +139,23 @@ function renderPalette(commands, state = {}, width = 80, height = 24) {
139
139
 
140
140
  // ── Model picker overlay (alt+p) ─────────────────────────────────────────────
141
141
 
142
+ // The one hint line the two setting-writing pickers (/model and /effort) share.
143
+ //
144
+ // It is ONE string reused, not a line typed twice, because a hint that
145
+ // advertises a binding the other picker does not have is how /effort ended up
146
+ // with no chord at all while /model had three: nothing forced the two to say
147
+ // the same thing, so they didn't. Both handlers consume these bindings now
148
+ // (chatflow.js handleOverlayKey), and both paint this sentence.
149
+ //
150
+ // Length is load-bearing: padLine() truncates at the terminal width with no
151
+ // ellipsis, and a longer wording loses its second half at 80 columns — exactly
152
+ // the half naming the chords — so the clause explaining the pin-as-you-move
153
+ // chord gets cut to "…pins" and the sentence is worse than useless. The
154
+ // removed shift+w/s chord was dropped from this string for the same reason it
155
+ // was dropped from the handler: Tab is the single arrow-free binding. Keep the
156
+ // whole line under 78 cells, plus the leading space.
157
+ const PICKER_HINT = `↑↓ or tab move ${GLYPH.bullet} enter pins ${GLYPH.bullet} shift+↑↓ pins at once ${GLYPH.bullet} esc cancels`;
158
+
142
159
  /**
143
160
  * @param {Array} models entries ({id, label?, name?, note?, model?})
144
161
  * @param {number} sel selected index
@@ -214,12 +231,7 @@ function renderModelPicker(models, sel = 0, width = 80, height = 24, current = n
214
231
  }
215
232
  if (end < count) lines.push([span('', ' '), span(C.gray, `↓ ${count - end} more below`)]);
216
233
  lines.push(blank(width));
217
- // ↑/↓/tab move the highlight — they do not apply. This is the reference's
218
- // binding (aegiscodex-dev/src/main.js navList: arrows point, Enter commits),
219
- // and the two chords that DO apply as they move are spelled out separately:
220
- // shift+↑/↓ for terminals that send CSI modifier 2, and shift+w/shift+s as
221
- // plain chars ('W'/'S') for links that eat arrow escapes but pass letters.
222
- lines.push([span('', ' '), span(C.gray, `↑↓ or tab move ${GLYPH.bullet} enter pins ${GLYPH.bullet} shift+↑↓/shift+w/s pins at once ${GLYPH.bullet} esc cancels`)]);
234
+ lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
223
235
  return fit(lines, width);
224
236
  }
225
237
 
@@ -269,7 +281,7 @@ function renderEffortPicker(sel = 0, width = 80, current = null, levels = EFFORT
269
281
  lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + lv.note)]);
270
282
  }
271
283
  lines.push(blank(width));
272
- lines.push([span('', ' '), span(C.gray, `arrow keys to navigate ${GLYPH.bullet} enter to select ${GLYPH.bullet} esc to cancel`)]);
284
+ lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
273
285
  return fit(lines, width);
274
286
  }
275
287
 
@@ -349,4 +361,5 @@ module.exports = {
349
361
  renderResumeList,
350
362
  EFFORT_LEVELS,
351
363
  EFFORT_VALUES,
364
+ PICKER_HINT,
352
365
  };
@@ -33,32 +33,57 @@
33
33
  const { machineFingerprint } = require('./device-fingerprint.js');
34
34
 
35
35
  const DEVICE_REGISTER_TIMEOUT_MS = 8000;
36
+ const DEVICE_REGISTER_RETRY_DELAYS_MS = [1000, 3000];
37
+
38
+ // Network failure, timeout (status 0), 408, or 5xx. A 4xx — including 429, the
39
+ // server's per-IP registration cap — is a refusal, and retrying it only spends
40
+ // more of that cap.
41
+ function isTransientRegisterError(err) {
42
+ const status = err && err.status;
43
+ return !status || status === 408 || status >= 500;
44
+ }
45
+
46
+ // Why automatic registration gave up, in words a host can show the user.
47
+ function provisionFailureText(result) {
48
+ const err = result && result.error;
49
+ if (!err) return 'the server returned no account key';
50
+ if (err.status === 429) return 'too many sign-ups from this network — try again later';
51
+ if (isTransientRegisterError(err)) return 'could not reach aegiscloud.org';
52
+ return `the server refused the request (HTTP ${err.status})`;
53
+ }
36
54
 
37
55
  /**
38
56
  * @param {object} aegisClient A client from client/aegis.js (createClient()).
39
57
  * @param {object} credentials client/credentials.js (or a compatible double).
58
+ * @param {number[]} [retryDelaysMs] Wait before each retry of a transient failure.
40
59
  * @returns {Promise<{ok: boolean, key: string, error?: Error}>}
41
60
  * `ok` is true only when a usable key was obtained AND persisted to the
42
61
  * shared store; `aegisClient.setApiKey()` has already been called on
43
62
  * success, so the caller's client is immediately usable either way it
44
63
  * inspects `ok`.
45
64
  */
46
- async function autoProvisionApiKey(aegisClient, credentials) {
65
+ async function autoProvisionApiKey(aegisClient, credentials, retryDelaysMs = DEVICE_REGISTER_RETRY_DELAYS_MS) {
47
66
  if (aegisClient.apiKey) return { ok: true, key: aegisClient.apiKey };
48
- const controller = new AbortController();
49
- const timer = setTimeout(() => controller.abort(), DEVICE_REGISTER_TIMEOUT_MS);
50
- try {
51
- const data = await aegisClient.registerDevice(machineFingerprint(), { signal: controller.signal });
52
- const key = data && typeof data.api_key === 'string' ? data.api_key.trim() : '';
53
- if (!key) return { ok: false, key: '' };
54
- const saved = credentials.saveApiKey(key);
55
- aegisClient.setApiKey(key);
56
- return { ok: !!saved.ok, key };
57
- } catch (err) {
58
- return { ok: false, key: '', error: err };
59
- } finally {
60
- clearTimeout(timer);
67
+ let lastError = null;
68
+ for (let attempt = 0; attempt <= retryDelaysMs.length; attempt++) {
69
+ if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, retryDelaysMs[attempt - 1]));
70
+ const controller = new AbortController();
71
+ const timer = setTimeout(() => controller.abort(), DEVICE_REGISTER_TIMEOUT_MS);
72
+ try {
73
+ const data = await aegisClient.registerDevice(machineFingerprint(), { signal: controller.signal });
74
+ const key = data && typeof data.api_key === 'string' ? data.api_key.trim() : '';
75
+ if (!key) return { ok: false, key: '' };
76
+ const saved = credentials.saveApiKey(key);
77
+ aegisClient.setApiKey(key);
78
+ return { ok: !!saved.ok, key };
79
+ } catch (err) {
80
+ lastError = err;
81
+ if (!isTransientRegisterError(err)) break;
82
+ } finally {
83
+ clearTimeout(timer);
84
+ }
61
85
  }
86
+ return { ok: false, key: '', error: lastError };
62
87
  }
63
88
 
64
- module.exports = { autoProvisionApiKey, DEVICE_REGISTER_TIMEOUT_MS };
89
+ module.exports = { autoProvisionApiKey, provisionFailureText, DEVICE_REGISTER_TIMEOUT_MS, DEVICE_REGISTER_RETRY_DELAYS_MS };