aegiscode 7.0.14 → 7.0.16

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 (109) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +4 -7
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2932
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3020
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4003
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/fingerprint.js +1 -592
  28. package/src/format.js +1 -259
  29. package/src/fuzzy.js +1 -119
  30. package/src/history.js +1 -401
  31. package/src/init.js +1 -175
  32. package/src/input.js +1 -139
  33. package/src/keys.js +1 -183
  34. package/src/markdown.js +1 -306
  35. package/src/models.js +1 -487
  36. package/src/naming.js +1 -229
  37. package/src/overlays.js +1 -461
  38. package/src/panels.js +1 -1418
  39. package/src/ping.js +1 -226
  40. package/src/presence.js +1 -238
  41. package/src/render.js +1 -515
  42. package/src/screen.js +1 -518
  43. package/src/screens.js +1 -896
  44. package/src/secret.js +1 -59
  45. package/src/securefs.js +1 -359
  46. package/src/settings.js +1 -155
  47. package/src/shared.js +1 -52
  48. package/src/sharedpaths.js +1 -53
  49. package/src/signup.js +1 -156
  50. package/src/summarize.js +1 -95
  51. package/src/sysdiag.js +1 -585
  52. package/src/system.js +1 -40
  53. package/src/theme.js +1 -570
  54. package/src/title.js +1 -220
  55. package/src/todos.js +1 -115
  56. package/src/tokens.js +1 -263
  57. package/src/topup.js +1 -210
  58. package/src/update.js +1 -181
  59. package/vendor/client/aegis.js +1 -2179
  60. package/vendor/client/attest.js +1 -442
  61. package/vendor/client/authorship-key.js +1 -410
  62. package/vendor/client/auto-provision.js +1 -134
  63. package/vendor/client/brain-catalog.js +1 -268
  64. package/vendor/client/byok-catalog.js +1 -230
  65. package/vendor/client/credentials.js +1 -494
  66. package/vendor/client/device-fingerprint.js +1 -141
  67. package/vendor/client/drive-connect.js +1 -110
  68. package/vendor/client/drive-upload.js +1 -174
  69. package/vendor/client/env-file.js +1 -1273
  70. package/vendor/client/fingerprint.js +1 -1064
  71. package/vendor/client/foreign-memory.js +1 -669
  72. package/vendor/client/google-signin.js +1 -133
  73. package/vendor/client/hooks.js +1 -430
  74. package/vendor/client/model-discovery.js +1 -373
  75. package/vendor/client/platform.js +1 -937
  76. package/vendor/client/prefs.js +1 -351
  77. package/vendor/client/presence-constants.js +1 -107
  78. package/vendor/client/presence.js +1 -438
  79. package/vendor/client/record-vault.js +3 -1055
  80. package/vendor/client/session-store.js +1 -548
  81. package/vendor/client/topup.js +1 -297
  82. package/vendor/client/touch.js +1 -458
  83. package/vendor/client/update.js +1 -704
  84. package/vendor/client/user-models.js +1 -381
  85. package/vendor/desktop/lib/local/agents.js +1 -105
  86. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  87. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  88. package/vendor/desktop/lib/local/context.js +1 -95
  89. package/vendor/desktop/lib/local/engine.js +1 -3301
  90. package/vendor/desktop/lib/local/entitlement.js +1 -660
  91. package/vendor/desktop/lib/local/git-scope.js +1 -228
  92. package/vendor/desktop/lib/local/local.js +1 -2135
  93. package/vendor/desktop/lib/local/prompt.js +1 -275
  94. package/vendor/desktop/lib/local/queue.js +1 -560
  95. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  96. package/vendor/desktop/lib/local/shell.js +1 -680
  97. package/vendor/desktop/lib/local/tools.js +1 -1238
  98. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  99. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  100. package/vendor/desktop/lib/settings.js +1 -890
  101. package/vendor/desktop/renderer/usage.js +1 -1239
  102. package/vendor/hosts/install.js +1 -638
  103. package/vendor/hosts/openai-shim.js +1 -515
  104. package/vendor/hosts/spec.js +1 -164
  105. package/vendor/hosts/targets.js +1 -346
  106. package/vendor/mcp/server.js +1 -221
  107. package/vendor/mcp/tools.js +1 -408
  108. package/vendor/one/src/child.js +1 -285
  109. package/vendor/one/src/permissions.js +1 -369
package/src/overlays.js CHANGED
@@ -1,463 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * Overlay renderers — the "/" command palette, the alt+p model picker, the
10
- * /effort picker and the /resume session list. Ported from
11
- * the upstream engine reference (which mirrors live captures of Claude Code
12
- * 2.1.228: a gray `─` rule, a lavender `❯` cursor, a blue selected row, a
13
- * `⎿ Usage: /x hint` hook under the focused command and a `·`-separated footer).
14
- *
15
- * Every renderer here is PURE. It receives the data it draws — a command list, a
16
- * model list, an item list, a selection index, a width and a height — and
17
- * returns an array of span lines (`{ t, s, w }`, see screen.js). It imports no
18
- * registry, no session state and no key handling; the session loop owns those.
19
- * The palette's command list is the array the concurrent workstream owns:
20
- * `{ name, aliases?, help|desc, args?, category?, hint?, tool?|local?|unavailable? }`.
21
- *
22
- * Filtering reuses `./fuzzy.js` (fuzzyRankWithAliases + fuzzyMatchPositions).
23
- * The require is guarded: if that module is absent the palette falls back to a
24
- * substring filter so this file still loads and `node --check` still passes.
25
- */
26
-
27
- const { span, padLine } = require('./screen.js');
28
- const { C, BOLD, BOLD_OFF, GLYPH } = require('./theme.js');
29
-
30
- // ── fuzzy.js (guarded require — a concurrent workstream owns it) ─────────────
31
- let fuzzy = null;
32
- try {
33
- // eslint-disable-next-line global-require
34
- fuzzy = require('./fuzzy.js');
35
- } catch {
36
- fuzzy = null;
37
- }
38
-
39
- /** Rank palette commands by query (aliases count, like the reference). */
40
- function rankCommands(query, commands) {
41
- if (fuzzy && typeof fuzzy.fuzzyRankWithAliases === 'function') {
42
- return fuzzy.fuzzyRankWithAliases(query, commands, (c) => c.name, (c) => c.aliases || []);
43
- }
44
- // Fallback: plain case-insensitive substring across name + aliases.
45
- const q = String(query || '').toLowerCase();
46
- if (!q) return commands;
47
- return commands.filter((c) =>
48
- `${c.name} ${(c.aliases || []).join(' ')}`.toLowerCase().includes(q)
49
- );
50
- }
51
-
52
- /** The short description a registry entry carries (help or desc). */
53
- const descOf = (c) => c.help != null ? c.help : (c.desc != null ? c.desc : '');
54
- /** The usage hint shown on the selected row's `⎿` hook (hint, else args). */
55
- const hintOf = (c) => (c.hint != null ? c.hint : (c.args != null ? c.args : ''));
56
-
57
- /** Pad (and, if needed, truncate) every line to `width` cells so an overlay can
58
- * never paint wider than the terminal. */
59
- function fit(lines, width) {
60
- return lines.map((l) => padLine(l, width));
61
- }
62
-
63
- /** A full-width blank row. */
64
- const blank = (width) => [span('', ' '.repeat(Math.max(0, width)))];
65
-
66
- // Split a command name into spans that bold the
67
- // characters which matched the query; the selected row reads blue.
68
- function boldMatched(query, name, colour) {
69
- const pos = fuzzy && typeof fuzzy.fuzzyMatchPositions === 'function'
70
- ? fuzzy.fuzzyMatchPositions(query, name)
71
- : [];
72
- if (!pos || !pos.length) return [span(colour, name)];
73
- const segs = [];
74
- let last = 0;
75
- for (const p of pos) {
76
- if (p > last) segs.push(span(colour, name.slice(last, p)));
77
- segs.push(span(colour + BOLD, name[p]));
78
- last = p + 1;
79
- }
80
- if (last < name.length) segs.push(span(colour, name.slice(last)));
81
- return segs;
82
- }
83
-
84
- // ── Palette overlay (/) ──────────────────────────────────────────────────────
85
-
86
- /**
87
- * @param {Array|{commands:Array, query?:string, sel?:number}} commands
88
- * the registry command list (or a state object carrying it as `.commands`)
89
- * @param {{query?:string, sel?:number}} [state]
90
- * @param {number} [width]
91
- * @param {number} [height]
92
- */
93
- function renderPalette(commands, state = {}, width = 80, height = 24) {
94
- // Accept either `renderPalette(list, {query, sel}, w, h)` or the reference's
95
- // `renderPalette({commands, query, sel}, w, h)`.
96
- if (!Array.isArray(commands) && commands && typeof commands === 'object') {
97
- state = commands;
98
- commands = Array.isArray(commands.commands) ? commands.commands : [];
99
- }
100
- const list = rankCommands(state.query || '', commands || []);
101
- const sel = Number.isInteger(state.sel) ? state.sel : 0;
102
- const total = list.length;
103
- const per = Math.max(1, Math.min(12, height - 8));
104
- const start = Math.max(0, Math.min(sel - Math.floor(per / 2), Math.max(0, total - per)));
105
- const visible = list.slice(start, start + per);
106
-
107
- const lines = [];
108
- lines.push(blank(width));
109
- lines.push([span(C.gray, ' ' + '─'.repeat(Math.max(10, width - 4)))]);
110
- for (let i = 0; i < visible.length; i++) {
111
- const c = visible[i];
112
- const idx = start + i;
113
- const active = idx === sel;
114
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
115
- const row = active ? C.blue : C.white;
116
- const name = [span(row, '/'), ...boldMatched(state.query || '', c.name, row)];
117
- const pad = ' '.repeat(Math.max(1, 22 - [...c.name].length));
118
- lines.push([
119
- span('', ' '),
120
- left,
121
- span('', ' '),
122
- ...name,
123
- span(c.unavailable ? C.dim : C.gray, pad + descOf(c)),
124
- ]);
125
- if (active && hintOf(c)) {
126
- lines.push([span('', ' '), span(C.gray, `${GLYPH.hook} Usage: /${c.name} ${hintOf(c)}`)]);
127
- }
128
- }
129
- while (lines.length < 4 + per * 2) lines.push(blank(width));
130
- lines.push([span(C.gray, ' ' + '─'.repeat(Math.max(10, width - 4)))]);
131
- lines.push([
132
- span(
133
- C.gray,
134
- ` type to filter ${GLYPH.bullet} shift+enter runs the top row ${GLYPH.bullet} enter runs ${GLYPH.bullet} esc closes`
135
- ),
136
- ]);
137
- return fit(lines, width);
138
- }
139
-
140
- // ── Model picker overlay (alt+p) ─────────────────────────────────────────────
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
-
159
- /**
160
- * @param {Array} models entries ({id, label?, name?, note?, model?})
161
- * @param {number} sel selected index
162
- * @param {number} width
163
- * @param {number} height
164
- * @param {string|null} current the currently-pinned model id
165
- * @param {string} [cls] which class the next turn runs on ('aegis' | 'byok').
166
- * The rows are already class-scoped by the caller (app.js listModelsFor), but
167
- * the copy must be too: "manage the list with /model add|remove" is true of
168
- * the pooled catalog and meaningless on BYOK, where the list is not a stored
169
- * list at all but a function of which provider keys this machine holds — so
170
- * the subtitle names the command that actually changes it.
171
- * @param {(cls: string) => string} [classLabel] the caller's label table
172
- * (engine.js CLASS_LABELS, via app.js) so the class is named one way in every
173
- * surface rather than re-spelled here.
174
- */
175
- function renderModelPicker(models, sel = 0, width = 80, height = 24, current = null, cls = null, classLabel = null) {
176
- const lines = [];
177
- const label = typeof classLabel === 'function' && cls ? classLabel(cls) : null;
178
- lines.push(blank(width));
179
- lines.push([
180
- span('', ' '), span(C.white + BOLD, 'Select model'), span(BOLD_OFF, ''),
181
- ...(label ? [span(C.gray, ` — running on ${label}`)] : []),
182
- ]);
183
- lines.push([span('', ' '), span(C.gray, 'Switch between models. Your pick becomes the default for new sessions.')]);
184
- lines.push([
185
- span('', ' '),
186
- // The list mixes both classes: Nexus runs pooled (your AEGIS account
187
- // pays); every other row relays through your own provider key, and
188
- // picking one prompts for that key right here if this machine has none
189
- // saved yet — no need to run /byok-key first.
190
- span(C.gray, 'Nexus is pooled; any other row prompts for its provider key on pick.'),
191
- ]);
192
- lines.push(blank(width));
193
- // The list is the FULL catalog now (models.js pickerEntries), which is more
194
- // rows than any terminal has: ~40 ids against the 16 a 24-row window has left
195
- // once the title, subtitle and hint are paid for. Without a window the
196
- // selected row walked off the bottom of the frame while `sel` kept moving, so
197
- // arrow-DOWN looked broken — the row WAS selected, just never painted.
198
- //
199
- // The window keeps the selection as close to the middle as it can, clamped so
200
- // it never runs past either end, and states the number of hidden rows on the
201
- // side they are hidden. Row format and widths are unchanged: this is the same
202
- // line the un-windowed loop drew, over a slice of the list.
203
- const rows = Math.max(1, (height || 24) - 8);
204
- const count = models.length;
205
- const start = count > rows ? Math.min(Math.max(0, sel - Math.floor(rows / 2)), count - rows) : 0;
206
- const end = Math.min(count, start + rows);
207
- if (start > 0) lines.push([span('', ' '), span(C.gray, `↑ ${start} more above`)]);
208
- for (let i = start; i < end; i++) {
209
- const m = models[i] || {};
210
- const label = m.label || m.name || m.id || '';
211
- const active = i === sel;
212
- const cur = current != null && m.id === current;
213
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
214
- const num = span(C.gray, `${i + 1}.`);
215
- const nameSpan = active ? span(C.lavender, label) : span(C.white, label);
216
- const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
217
- const pad = ' '.repeat(Math.max(1, 22 - [...label].length));
218
- // A byok row not yet configured on this machine gets a visible flag ahead
219
- // of its note, so "needs a key" is legible without reading the whole line.
220
- const flag = m.cls === 'byok' && !m.configured ? '[key needed] ' : '';
221
- lines.push([
222
- span('', ' '),
223
- left,
224
- span('', ' '),
225
- num,
226
- span('', ' '),
227
- nameSpan,
228
- mark,
229
- span(C.gray, pad + flag + (m.note || m.model || '')),
230
- ]);
231
- }
232
- if (end < count) lines.push([span('', ' '), span(C.gray, `↓ ${count - end} more below`)]);
233
- lines.push(blank(width));
234
- lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
235
- return fit(lines, width);
236
- }
237
-
238
- // ── Effort picker overlay (/effort) ──────────────────────────────────────────
239
-
240
- // The three rungs, in the order the picker draws them. `High` is the default
241
- // (config.js seeds `effort: 'high'`, and engine.js/desktop/renderer both resolve
242
- // an unknown rung to high), so the list is exactly the levels that can be in
243
- // force — there is no fourth "auto" row any more. "auto" was not a level: it
244
- // meant "send no rung", and because it was the default, a fresh install sent no
245
- // effort at all and the knob did nothing until it was set by hand.
246
- const EFFORT_LEVELS = [
247
- { label: 'Low', note: 'Fastest, cheapest budget' },
248
- { label: 'Medium', note: 'Balanced' },
249
- { label: 'High', note: 'Highest budget, slowest (default)' },
250
- ];
251
-
252
- // The picker's order reduced to the values a selection means, so the row a user
253
- // picks and the value the session stores can never come from two different
254
- // lists (commands.js validates against this, chatflow.js resolves the overlay
255
- // through it).
256
- const EFFORT_VALUES = EFFORT_LEVELS.map((lv) => (lv.value === undefined ? lv.label.toLowerCase() : lv.value));
257
-
258
- /**
259
- * @param {number} sel selected index
260
- * @param {number} width
261
- * @param {string|null} current the currently-selected effort level (null = the
262
- * high default, which is what the engine applies)
263
- * @param {Array} [levels] override the level table
264
- */
265
- function renderEffortPicker(sel = 0, width = 80, current = null, levels = EFFORT_LEVELS) {
266
- const lines = [];
267
- lines.push(blank(width));
268
- lines.push([span('', ' '), span(C.white + BOLD, 'Select effort'), span(BOLD_OFF, '')]);
269
- lines.push([span('', ' '), span(C.gray, 'Sets the token budget the pool sizes each turn from.')]);
270
- lines.push(blank(width));
271
- for (let i = 0; i < levels.length; i++) {
272
- const lv = levels[i];
273
- const active = i === sel;
274
- // `current == null` means no rung is stored, which is the high default the
275
- // engine resolves — so the check mark lands on High rather than on nothing.
276
- const cur = String(current || 'high').toLowerCase() === String(lv.label).toLowerCase();
277
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
278
- const nameSpan = active ? span(C.lavender, lv.label) : span(C.white, lv.label);
279
- const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
280
- const pad = ' '.repeat(Math.max(1, 12 - [...lv.label].length));
281
- lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + lv.note)]);
282
- }
283
- lines.push(blank(width));
284
- lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
285
- return fit(lines, width);
286
- }
287
-
288
- // ── Class picker overlay (/class) ────────────────────────────────────────────
289
-
290
- /**
291
- * @param {Array} classes entries ({class, configured?})
292
- * @param {number} sel selected index
293
- * @param {number} width
294
- * @param {string|null} current the live class id
295
- * @param {(cls: string) => string} [classLabel] the caller's label table, so
296
- * the class is named one way in every surface rather than re-spelled here.
297
- */
298
- function renderClassPicker(classes, sel = 0, width = 80, current = null, classLabel = null) {
299
- const list = Array.isArray(classes) ? classes : [];
300
- const label = (id) => (typeof classLabel === 'function' ? classLabel(id) : id) || id;
301
- const lines = [];
302
- lines.push(blank(width));
303
- lines.push([span('', ' '), span(C.white + BOLD, 'Select class'), span(BOLD_OFF, '')]);
304
- lines.push([span('', ' '), span(C.gray, 'Which route the next turn takes — who pays, and with which credential.')]);
305
- lines.push(blank(width));
306
- for (let i = 0; i < list.length; i++) {
307
- const k = list[i] || {};
308
- const id = k.class;
309
- const active = i === sel;
310
- const cur = current != null && id === current;
311
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
312
- const name = label(id);
313
- const nameSpan = active ? span(C.lavender, name) : span(C.white, name);
314
- const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
315
- const pad = ' '.repeat(Math.max(1, 14 - [...name].length));
316
- // Same distinction /class's static panel used to draw: who pays, and with
317
- // which credential, so the picker says exactly what the printed table did.
318
- const note =
319
- id === 'byok'
320
- ? k.configured
321
- ? 'your key, relayed by AEGIS — billed a handling fee'
322
- : 'needs a provider key: /byok-key <provider>'
323
- : 'the pool — your AEGIS account key pays for it';
324
- lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + note)]);
325
- }
326
- lines.push(blank(width));
327
- lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
328
- return fit(lines, width);
329
- }
330
-
331
- // ── Resume-list overlay (/resume) ────────────────────────────────────────────
332
-
333
- /**
334
- * @param {Array} items entries ({own?, summary?, cwd?, time?})
335
- * @param {number} sel selected index
336
- * @param {number} width
337
- * @param {number} height
338
- */
339
- function renderResumeList(items, sel = 0, width = 80, height = 24) {
340
- const list = Array.isArray(items) ? items : [];
341
- const lines = [];
342
- lines.push(blank(width));
343
- lines.push([span('', ' '), span(C.gray, '─'.repeat(Math.max(10, width - 4)))]);
344
- lines.push([
345
- span('', ' '),
346
- span(C.white + BOLD, 'Resume session'),
347
- span(C.gray, ` (${sel + 1} of ${Math.max(1, list.length)})`),
348
- span(BOLD_OFF, ''),
349
- ]);
350
- // search box
351
- const boxW = Math.max(10, width - 4);
352
- lines.push([span('', ' '), span(C.gray, '╭' + '─'.repeat(Math.max(0, boxW - 2)) + '╮')]);
353
- lines.push([
354
- span('', ' '),
355
- span(C.gray, '│'),
356
- span(C.white, '⌕ Search…'),
357
- span('', ' '.repeat(Math.max(0, boxW - 9))),
358
- span(C.gray, '│'),
359
- ]);
360
- lines.push([span('', ' '), span(C.gray, '╰' + '─'.repeat(Math.max(0, boxW - 2)) + '╯')]);
361
- lines.push(blank(width));
362
- const per = Math.max(2, Math.min(6, height - 16));
363
- const start = Math.max(0, Math.min(sel - Math.floor(per / 2), Math.max(0, list.length - per)));
364
- const visible = list.slice(start, start + per);
365
- for (let i = 0; i < visible.length; i++) {
366
- const it = visible[i] || {};
367
- const idx = start + i;
368
- const active = idx === sel;
369
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
370
- const tag = it.own ? span(C.green, GLYPH.star + ' ') : span(C.gray, GLYPH.bullet + ' ');
371
- const title = active
372
- ? span(C.white + BOLD, it.summary || '(untitled)')
373
- : span(C.white, it.summary || '(untitled)');
374
- lines.push([span('', ' '), left, span('', ' '), tag, title]);
375
- lines.push([span('', ' '), span(C.gray, `${it.cwd || '~'} ${GLYPH.bullet} ${ago(it.time)}`)]);
376
- }
377
- while (lines.length < 6 + per * 2) lines.push(blank(width));
378
- lines.push([span('', ' '), span(C.gray, '─'.repeat(Math.max(10, width - 4)))]);
379
- lines.push([
380
- span('', ' '),
381
- span(
382
- C.gray,
383
- `Ctrl+A all projects ${GLYPH.bullet} Space to preview ${GLYPH.bullet} Type to search ${GLYPH.bullet} Esc to cancel`
384
- ),
385
- ]);
386
- return fit(lines, width);
387
- }
388
-
389
- function ago(ts) {
390
- if (!ts) return '';
391
- const ms = Date.now() - new Date(String(ts)).getTime();
392
- if (!(ms >= 0) || Number.isNaN(ms)) return '';
393
- if (ms < 60_000) return `${Math.max(1, Math.round(ms / 1000))}s ago`;
394
- if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m ago`;
395
- if (ms < 86_400_000) return `${Math.round(ms / 3_600_000)}h ago`;
396
- return `${Math.round(ms / 86_400_000)}d ago`;
397
- }
398
-
399
- // ── BYOK provider picker overlay (/byok-set, /byok-key with no argument) ────
400
-
401
- /**
402
- * The picker `/byok-set <provider>` draws when no provider was typed.
403
- *
404
- * The provider id was the one thing this flow asked the user to RECALL: `/byok`
405
- * listed ~20 ids, and storing a key meant reading one off that list and typing
406
- * it back — retyped wrong, it either matched nothing ("unknown provider") or,
407
- * worse, matched an alias of another vendor. The rows are the catalog's own,
408
- * so the id Enter sends is the id the relay will be asked for.
409
- *
410
- * @param {Array} providers catalog rows ({id, label?, configured?, masked?})
411
- * @param {number} sel selected index
412
- * @param {number} width
413
- * @param {string|null} [current] the provider already set on this machine, if
414
- * any (marked, not selected — "set" is shown per row anyway)
415
- * @param {string} [hint] the footer line; differs between `/byok-set` (the
416
- * account-side store) and `/byok-key` (this machine's store)
417
- */
418
- function renderProviderPicker(providers, sel = 0, width = 80, current = null, hint = null) {
419
- const list = Array.isArray(providers) ? providers : [];
420
- const lines = [];
421
- lines.push(blank(width));
422
- lines.push([span('', ' '), span(C.white + BOLD, 'Select provider'), span(BOLD_OFF, '')]);
423
- lines.push([span('', ' '), span(C.gray, 'Which vendor the key you are about to paste belongs to.')]);
424
- lines.push(blank(width));
425
- for (let i = 0; i < list.length; i++) {
426
- const p = list[i] || {};
427
- const id = String(p.id || '');
428
- if (!id) continue;
429
- const active = i === sel;
430
- const cur = current != null && id === current;
431
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
432
- const nameSpan = active ? span(C.lavender, id) : span(C.white, id);
433
- const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
434
- const name = String(p.label || '');
435
- const pad = ' '.repeat(Math.max(1, 16 - [...id].length));
436
- const state = p.configured
437
- ? span(C.green, `set${p.masked ? ` (${p.masked})` : ''}`)
438
- : span(C.gray, 'not set');
439
- lines.push([
440
- span('', ' '), left, span('', ' '), nameSpan, mark,
441
- span(C.gray, pad + (name ? `${name} · ` : '')), state,
442
- ]);
443
- }
444
- lines.push(blank(width));
445
- lines.push([
446
- span('', ' '),
447
- span(C.gray, hint || `↑↓ or tab move ${GLYPH.bullet} enter picks ${GLYPH.bullet} esc cancels`),
448
- ]);
449
- return fit(lines, width);
450
- }
451
-
452
- module.exports = {
453
- boldMatched,
454
- renderPalette,
455
- renderModelPicker,
456
- renderEffortPicker,
457
- renderClassPicker,
458
- renderProviderPicker,
459
- renderResumeList,
460
- EFFORT_LEVELS,
461
- EFFORT_VALUES,
462
- PICKER_HINT,
463
- };
3
+ "use strict";const{span:span,padLine:padLine}=require("./screen.js"),{C:C,BOLD:BOLD,BOLD_OFF:BOLD_OFF,GLYPH:GLYPH}=require("./theme.js");let fuzzy=null;try{fuzzy=require("./fuzzy.js")}catch{fuzzy=null}function rankCommands(e,a){if(fuzzy&&"function"==typeof fuzzy.fuzzyRankWithAliases)return fuzzy.fuzzyRankWithAliases(e,a,(e=>e.name),(e=>e.aliases||[]));const n=String(e||"").toLowerCase();return n?a.filter((e=>`${e.name} ${(e.aliases||[]).join(" ")}`.toLowerCase().includes(n))):a}const descOf=e=>null!=e.help?e.help:null!=e.desc?e.desc:"",hintOf=e=>null!=e.hint?e.hint:null!=e.args?e.args:"";function fit(e,a){return e.map((e=>padLine(e,a)))}const blank=e=>[span(""," ".repeat(Math.max(0,e)))];function boldMatched(e,a,n){const s=fuzzy&&"function"==typeof fuzzy.fuzzyMatchPositions?fuzzy.fuzzyMatchPositions(e,a):[];if(!s||!s.length)return[span(n,a)];const t=[];let r=0;for(const e of s)e>r&&t.push(span(n,a.slice(r,e))),t.push(span(n+BOLD,a[e])),r=e+1;return r<a.length&&t.push(span(n,a.slice(r))),t}function renderPalette(e,a={},n=80,s=24){!Array.isArray(e)&&e&&"object"==typeof e&&(a=e,e=Array.isArray(e.commands)?e.commands:[]);const t=rankCommands(a.query||"",e||[]),r=Number.isInteger(a.sel)?a.sel:0,p=t.length,l=Math.max(1,Math.min(12,s-8)),o=Math.max(0,Math.min(r-Math.floor(l/2),Math.max(0,p-l))),u=t.slice(o,o+l),h=[];h.push(blank(n)),h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]);for(let e=0;e<u.length;e++){const n=u[e],s=o+e===r,t=s?span(C.lavender,GLYPH.cursor):span(""," "),p=s?C.blue:C.white,l=[span(p,"/"),...boldMatched(a.query||"",n.name,p)],i=" ".repeat(Math.max(1,22-[...n.name].length));h.push([span(""," "),t,span(""," "),...l,span(n.unavailable?C.dim:C.gray,i+descOf(n))]),s&&hintOf(n)&&h.push([span(""," "),span(C.gray,`${GLYPH.hook} Usage: /${n.name} ${hintOf(n)}`)])}for(;h.length<4+2*l;)h.push(blank(n));return h.push([span(C.gray," "+"─".repeat(Math.max(10,n-4)))]),h.push([span(C.gray,` type to filter ${GLYPH.bullet} shift+enter runs the top row ${GLYPH.bullet} enter runs ${GLYPH.bullet} esc closes`)]),fit(h,n)}const PICKER_HINT=`↑↓ or tab move ${GLYPH.bullet} enter pins ${GLYPH.bullet} shift+↑↓ pins at once ${GLYPH.bullet} esc cancels`;function renderModelPicker(e,a=0,n=80,s=24,t=null,r=null,p=null){const l=[],o="function"==typeof p&&r?p(r):null;l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select model"),span(BOLD_OFF,""),...o?[span(C.gray,` — running on ${o}`)]:[]]),l.push([span(""," "),span(C.gray,"Switch between models. Your pick becomes the default for new sessions.")]),l.push([span(""," "),span(C.gray,"Nexus is pooled; any other row prompts for its provider key on pick.")]),l.push(blank(n));const u=Math.max(1,(s||24)-8),h=e.length,i=h>u?Math.min(Math.max(0,a-Math.floor(u/2)),h-u):0,c=Math.min(h,i+u);i>0&&l.push([span(""," "),span(C.gray,`↑ ${i} more above`)]);for(let n=i;n<c;n++){const s=e[n]||{},r=s.label||s.name||s.id||"",p=n===a,o=null!=t&&s.id===t,u=p?span(C.lavender,GLYPH.cursor):span(""," "),h=span(C.gray,`${n+1}.`),i=span(p?C.lavender:C.white,r),c=o?span(C.green," "+GLYPH.check):span("",""),d=" ".repeat(Math.max(1,22-[...r].length)),g="byok"!==s.cls||s.configured?"":"[key needed] ";l.push([span(""," "),u,span(""," "),h,span(""," "),i,c,span(C.gray,d+g+(s.note||s.model||""))])}return c<h&&l.push([span(""," "),span(C.gray,`↓ ${h-c} more below`)]),l.push(blank(n)),l.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(l,n)}const EFFORT_LEVELS=[{label:"Low",note:"Fastest, cheapest budget"},{label:"Medium",note:"Balanced"},{label:"High",note:"Highest budget, slowest (default)"}],EFFORT_VALUES=EFFORT_LEVELS.map((e=>void 0===e.value?e.label.toLowerCase():e.value));function renderEffortPicker(e=0,a=80,n=null,s=EFFORT_LEVELS){const t=[];t.push(blank(a)),t.push([span(""," "),span(C.white+BOLD,"Select effort"),span(BOLD_OFF,"")]),t.push([span(""," "),span(C.gray,"Sets the token budget the pool sizes each turn from.")]),t.push(blank(a));for(let a=0;a<s.length;a++){const r=s[a],p=a===e,l=String(n||"high").toLowerCase()===String(r.label).toLowerCase(),o=p?span(C.lavender,GLYPH.cursor):span(""," "),u=span(p?C.lavender:C.white,r.label),h=l?span(C.green," "+GLYPH.check):span("",""),i=" ".repeat(Math.max(1,12-[...r.label].length));t.push([span(""," "),o,span(""," "),u,h,span(C.gray,i+r.note)])}return t.push(blank(a)),t.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(t,a)}function renderClassPicker(e,a=0,n=80,s=null,t=null){const r=Array.isArray(e)?e:[],p=e=>("function"==typeof t?t(e):e)||e,l=[];l.push(blank(n)),l.push([span(""," "),span(C.white+BOLD,"Select class"),span(BOLD_OFF,"")]),l.push([span(""," "),span(C.gray,"Which route the next turn takes — who pays, and with which credential.")]),l.push(blank(n));for(let e=0;e<r.length;e++){const n=r[e]||{},t=n.class,o=e===a,u=null!=s&&t===s,h=o?span(C.lavender,GLYPH.cursor):span(""," "),i=p(t),c=span(o?C.lavender:C.white,i),d=u?span(C.green," "+GLYPH.check):span("",""),g=" ".repeat(Math.max(1,14-[...i].length)),y="byok"===t?n.configured?"your key, relayed by AEGIS — billed a handling fee":"needs a provider key: /byok-key <provider>":"the pool — your AEGIS account key pays for it";l.push([span(""," "),h,span(""," "),c,d,span(C.gray,g+y)])}return l.push(blank(n)),l.push([span(""," "),span(C.gray,PICKER_HINT)]),fit(l,n)}function renderResumeList(e,a=0,n=80,s=24){const t=Array.isArray(e)?e:[],r=[];r.push(blank(n)),r.push([span(""," "),span(C.gray,"─".repeat(Math.max(10,n-4)))]),r.push([span(""," "),span(C.white+BOLD,"Resume session"),span(C.gray,` (${a+1} of ${Math.max(1,t.length)})`),span(BOLD_OFF,"")]);const p=Math.max(10,n-4);r.push([span(""," "),span(C.gray,"╭"+"─".repeat(Math.max(0,p-2))+"╮")]),r.push([span(""," "),span(C.gray,"│"),span(C.white,"⌕ Search…"),span(""," ".repeat(Math.max(0,p-9))),span(C.gray,"│")]),r.push([span(""," "),span(C.gray,"╰"+"─".repeat(Math.max(0,p-2))+"╯")]),r.push(blank(n));const l=Math.max(2,Math.min(6,s-16)),o=Math.max(0,Math.min(a-Math.floor(l/2),Math.max(0,t.length-l))),u=t.slice(o,o+l);for(let e=0;e<u.length;e++){const n=u[e]||{},s=o+e===a,t=s?span(C.lavender,GLYPH.cursor):span(""," "),p=n.own?span(C.green,GLYPH.star+" "):span(C.gray,GLYPH.bullet+" "),l=span(s?C.white+BOLD:C.white,n.summary||"(untitled)");r.push([span(""," "),t,span(""," "),p,l]),r.push([span(""," "),span(C.gray,`${n.cwd||"~"} ${GLYPH.bullet} ${ago(n.time)}`)])}for(;r.length<6+2*l;)r.push(blank(n));return r.push([span(""," "),span(C.gray,"─".repeat(Math.max(10,n-4)))]),r.push([span(""," "),span(C.gray,`Ctrl+A all projects ${GLYPH.bullet} Space to preview ${GLYPH.bullet} Type to search ${GLYPH.bullet} Esc to cancel`)]),fit(r,n)}function ago(e){if(!e)return"";const a=Date.now()-new Date(String(e)).getTime();return a>=0&&!Number.isNaN(a)?a<6e4?`${Math.max(1,Math.round(a/1e3))}s ago`:a<36e5?`${Math.round(a/6e4)}m ago`:a<864e5?`${Math.round(a/36e5)}h ago`:`${Math.round(a/864e5)}d ago`:""}function renderProviderPicker(e,a=0,n=80,s=null,t=null){const r=Array.isArray(e)?e:[],p=[];p.push(blank(n)),p.push([span(""," "),span(C.white+BOLD,"Select provider"),span(BOLD_OFF,"")]),p.push([span(""," "),span(C.gray,"Which vendor the key you are about to paste belongs to.")]),p.push(blank(n));for(let e=0;e<r.length;e++){const n=r[e]||{},t=String(n.id||"");if(!t)continue;const l=e===a,o=null!=s&&t===s,u=l?span(C.lavender,GLYPH.cursor):span(""," "),h=span(l?C.lavender:C.white,t),i=o?span(C.green," "+GLYPH.check):span("",""),c=String(n.label||""),d=" ".repeat(Math.max(1,16-[...t].length)),g=n.configured?span(C.green,"set"+(n.masked?` (${n.masked})`:"")):span(C.gray,"not set");p.push([span(""," "),u,span(""," "),h,i,span(C.gray,d+(c?`${c} · `:"")),g])}return p.push(blank(n)),p.push([span(""," "),span(C.gray,t||`↑↓ or tab move ${GLYPH.bullet} enter picks ${GLYPH.bullet} esc cancels`)]),fit(p,n)}module.exports={boldMatched:boldMatched,renderPalette:renderPalette,renderModelPicker:renderModelPicker,renderEffortPicker:renderEffortPicker,renderClassPicker:renderClassPicker,renderProviderPicker:renderProviderPicker,renderResumeList:renderResumeList,EFFORT_LEVELS:EFFORT_LEVELS,EFFORT_VALUES:EFFORT_VALUES,PICKER_HINT:PICKER_HINT};