aegiscode 7.0.26 → 7.0.27
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/SOURCE-OFFER.txt +9 -0
- package/package.json +4 -7
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2957
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3023
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -4089
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/filepreview.js +1 -153
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -423
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -507
- package/src/naming.js +1 -57
- package/src/overlays.js +1 -462
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -516
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -191
- package/vendor/client/aegis.js +1 -2441
- package/vendor/client/attest.js +1 -518
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -199
- package/vendor/client/catalog-client.js +1 -487
- package/vendor/client/conversation-export.js +1 -177
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -110
- package/vendor/client/drive-upload.js +1 -234
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -133
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -373
- package/vendor/client/naming.js +1 -283
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -575
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -763
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/attachments.js +1 -276
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -1028
- package/vendor/desktop/lib/local/context.js +1 -125
- package/vendor/desktop/lib/local/engine.js +1 -3666
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/exec-plan.js +1 -269
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/integrity.js +1 -163
- package/vendor/desktop/lib/local/local.js +1 -2145
- package/vendor/desktop/lib/local/prompt.js +1 -280
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -238
- package/vendor/desktop/lib/local/shell.js +1 -712
- package/vendor/desktop/lib/local/spill.js +1 -75
- package/vendor/desktop/lib/local/tools.js +1 -1328
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/main.js +3 -4890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -383
package/src/overlays.js
CHANGED
|
@@ -1,464 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
{ label: 'Max', note: 'Deepest reasoning where the model defines it; same budget as high' },
|
|
251
|
-
];
|
|
252
|
-
|
|
253
|
-
// The picker's order reduced to the values a selection means, so the row a user
|
|
254
|
-
// picks and the value the session stores can never come from two different
|
|
255
|
-
// lists (commands.js validates against this, chatflow.js resolves the overlay
|
|
256
|
-
// through it).
|
|
257
|
-
const EFFORT_VALUES = EFFORT_LEVELS.map((lv) => (lv.value === undefined ? lv.label.toLowerCase() : lv.value));
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @param {number} sel selected index
|
|
261
|
-
* @param {number} width
|
|
262
|
-
* @param {string|null} current the currently-selected effort level (null = the
|
|
263
|
-
* high default, which is what the engine applies)
|
|
264
|
-
* @param {Array} [levels] override the level table
|
|
265
|
-
*/
|
|
266
|
-
function renderEffortPicker(sel = 0, width = 80, current = null, levels = EFFORT_LEVELS) {
|
|
267
|
-
const lines = [];
|
|
268
|
-
lines.push(blank(width));
|
|
269
|
-
lines.push([span('', ' '), span(C.white + BOLD, 'Select effort'), span(BOLD_OFF, '')]);
|
|
270
|
-
lines.push([span('', ' '), span(C.gray, 'Sets the token budget the pool sizes each turn from.')]);
|
|
271
|
-
lines.push(blank(width));
|
|
272
|
-
for (let i = 0; i < levels.length; i++) {
|
|
273
|
-
const lv = levels[i];
|
|
274
|
-
const active = i === sel;
|
|
275
|
-
// `current == null` means no rung is stored, which is the high default the
|
|
276
|
-
// engine resolves — so the check mark lands on High rather than on nothing.
|
|
277
|
-
const cur = String(current || 'high').toLowerCase() === String(lv.label).toLowerCase();
|
|
278
|
-
const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
|
|
279
|
-
const nameSpan = active ? span(C.lavender, lv.label) : span(C.white, lv.label);
|
|
280
|
-
const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
|
|
281
|
-
const pad = ' '.repeat(Math.max(1, 12 - [...lv.label].length));
|
|
282
|
-
lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + lv.note)]);
|
|
283
|
-
}
|
|
284
|
-
lines.push(blank(width));
|
|
285
|
-
lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
|
|
286
|
-
return fit(lines, width);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// ── Class picker overlay (/class) ────────────────────────────────────────────
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* @param {Array} classes entries ({class, configured?})
|
|
293
|
-
* @param {number} sel selected index
|
|
294
|
-
* @param {number} width
|
|
295
|
-
* @param {string|null} current the live class id
|
|
296
|
-
* @param {(cls: string) => string} [classLabel] the caller's label table, so
|
|
297
|
-
* the class is named one way in every surface rather than re-spelled here.
|
|
298
|
-
*/
|
|
299
|
-
function renderClassPicker(classes, sel = 0, width = 80, current = null, classLabel = null) {
|
|
300
|
-
const list = Array.isArray(classes) ? classes : [];
|
|
301
|
-
const label = (id) => (typeof classLabel === 'function' ? classLabel(id) : id) || id;
|
|
302
|
-
const lines = [];
|
|
303
|
-
lines.push(blank(width));
|
|
304
|
-
lines.push([span('', ' '), span(C.white + BOLD, 'Select class'), span(BOLD_OFF, '')]);
|
|
305
|
-
lines.push([span('', ' '), span(C.gray, 'Which route the next turn takes — who pays, and with which credential.')]);
|
|
306
|
-
lines.push(blank(width));
|
|
307
|
-
for (let i = 0; i < list.length; i++) {
|
|
308
|
-
const k = list[i] || {};
|
|
309
|
-
const id = k.class;
|
|
310
|
-
const active = i === sel;
|
|
311
|
-
const cur = current != null && id === current;
|
|
312
|
-
const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
|
|
313
|
-
const name = label(id);
|
|
314
|
-
const nameSpan = active ? span(C.lavender, name) : span(C.white, name);
|
|
315
|
-
const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
|
|
316
|
-
const pad = ' '.repeat(Math.max(1, 14 - [...name].length));
|
|
317
|
-
// Same distinction /class's static panel used to draw: who pays, and with
|
|
318
|
-
// which credential, so the picker says exactly what the printed table did.
|
|
319
|
-
const note =
|
|
320
|
-
id === 'byok'
|
|
321
|
-
? k.configured
|
|
322
|
-
? 'your key, relayed by AEGIS — billed a handling fee'
|
|
323
|
-
: 'needs a provider key: /byok-key <provider>'
|
|
324
|
-
: 'the pool — your AEGIS account key pays for it';
|
|
325
|
-
lines.push([span('', ' '), left, span('', ' '), nameSpan, mark, span(C.gray, pad + note)]);
|
|
326
|
-
}
|
|
327
|
-
lines.push(blank(width));
|
|
328
|
-
lines.push([span('', ' '), span(C.gray, PICKER_HINT)]);
|
|
329
|
-
return fit(lines, width);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// ── Resume-list overlay (/resume) ────────────────────────────────────────────
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @param {Array} items entries ({own?, summary?, cwd?, time?})
|
|
336
|
-
* @param {number} sel selected index
|
|
337
|
-
* @param {number} width
|
|
338
|
-
* @param {number} height
|
|
339
|
-
*/
|
|
340
|
-
function renderResumeList(items, sel = 0, width = 80, height = 24) {
|
|
341
|
-
const list = Array.isArray(items) ? items : [];
|
|
342
|
-
const lines = [];
|
|
343
|
-
lines.push(blank(width));
|
|
344
|
-
lines.push([span('', ' '), span(C.gray, '─'.repeat(Math.max(10, width - 4)))]);
|
|
345
|
-
lines.push([
|
|
346
|
-
span('', ' '),
|
|
347
|
-
span(C.white + BOLD, 'Resume session'),
|
|
348
|
-
span(C.gray, ` (${sel + 1} of ${Math.max(1, list.length)})`),
|
|
349
|
-
span(BOLD_OFF, ''),
|
|
350
|
-
]);
|
|
351
|
-
// search box
|
|
352
|
-
const boxW = Math.max(10, width - 4);
|
|
353
|
-
lines.push([span('', ' '), span(C.gray, '╭' + '─'.repeat(Math.max(0, boxW - 2)) + '╮')]);
|
|
354
|
-
lines.push([
|
|
355
|
-
span('', ' '),
|
|
356
|
-
span(C.gray, '│'),
|
|
357
|
-
span(C.white, '⌕ Search…'),
|
|
358
|
-
span('', ' '.repeat(Math.max(0, boxW - 9))),
|
|
359
|
-
span(C.gray, '│'),
|
|
360
|
-
]);
|
|
361
|
-
lines.push([span('', ' '), span(C.gray, '╰' + '─'.repeat(Math.max(0, boxW - 2)) + '╯')]);
|
|
362
|
-
lines.push(blank(width));
|
|
363
|
-
const per = Math.max(2, Math.min(6, height - 16));
|
|
364
|
-
const start = Math.max(0, Math.min(sel - Math.floor(per / 2), Math.max(0, list.length - per)));
|
|
365
|
-
const visible = list.slice(start, start + per);
|
|
366
|
-
for (let i = 0; i < visible.length; i++) {
|
|
367
|
-
const it = visible[i] || {};
|
|
368
|
-
const idx = start + i;
|
|
369
|
-
const active = idx === sel;
|
|
370
|
-
const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
|
|
371
|
-
const tag = it.own ? span(C.green, GLYPH.star + ' ') : span(C.gray, GLYPH.bullet + ' ');
|
|
372
|
-
const title = active
|
|
373
|
-
? span(C.white + BOLD, it.summary || '(untitled)')
|
|
374
|
-
: span(C.white, it.summary || '(untitled)');
|
|
375
|
-
lines.push([span('', ' '), left, span('', ' '), tag, title]);
|
|
376
|
-
lines.push([span('', ' '), span(C.gray, `${it.cwd || '~'} ${GLYPH.bullet} ${ago(it.time)}`)]);
|
|
377
|
-
}
|
|
378
|
-
while (lines.length < 6 + per * 2) lines.push(blank(width));
|
|
379
|
-
lines.push([span('', ' '), span(C.gray, '─'.repeat(Math.max(10, width - 4)))]);
|
|
380
|
-
lines.push([
|
|
381
|
-
span('', ' '),
|
|
382
|
-
span(
|
|
383
|
-
C.gray,
|
|
384
|
-
`Ctrl+A all projects ${GLYPH.bullet} Space to preview ${GLYPH.bullet} Type to search ${GLYPH.bullet} Esc to cancel`
|
|
385
|
-
),
|
|
386
|
-
]);
|
|
387
|
-
return fit(lines, width);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function ago(ts) {
|
|
391
|
-
if (!ts) return '';
|
|
392
|
-
const ms = Date.now() - new Date(String(ts)).getTime();
|
|
393
|
-
if (!(ms >= 0) || Number.isNaN(ms)) return '';
|
|
394
|
-
if (ms < 60_000) return `${Math.max(1, Math.round(ms / 1000))}s ago`;
|
|
395
|
-
if (ms < 3_600_000) return `${Math.round(ms / 60_000)}m ago`;
|
|
396
|
-
if (ms < 86_400_000) return `${Math.round(ms / 3_600_000)}h ago`;
|
|
397
|
-
return `${Math.round(ms / 86_400_000)}d ago`;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// ── BYOK provider picker overlay (/byok-set, /byok-key with no argument) ────
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* The picker `/byok-set <provider>` draws when no provider was typed.
|
|
404
|
-
*
|
|
405
|
-
* The provider id was the one thing this flow asked the user to RECALL: `/byok`
|
|
406
|
-
* listed ~20 ids, and storing a key meant reading one off that list and typing
|
|
407
|
-
* it back — retyped wrong, it either matched nothing ("unknown provider") or,
|
|
408
|
-
* worse, matched an alias of another vendor. The rows are the catalog's own,
|
|
409
|
-
* so the id Enter sends is the id the relay will be asked for.
|
|
410
|
-
*
|
|
411
|
-
* @param {Array} providers catalog rows ({id, label?, configured?, masked?})
|
|
412
|
-
* @param {number} sel selected index
|
|
413
|
-
* @param {number} width
|
|
414
|
-
* @param {string|null} [current] the provider already set on this machine, if
|
|
415
|
-
* any (marked, not selected — "set" is shown per row anyway)
|
|
416
|
-
* @param {string} [hint] the footer line; differs between `/byok-set` (the
|
|
417
|
-
* account-side store) and `/byok-key` (this machine's store)
|
|
418
|
-
*/
|
|
419
|
-
function renderProviderPicker(providers, sel = 0, width = 80, current = null, hint = null) {
|
|
420
|
-
const list = Array.isArray(providers) ? providers : [];
|
|
421
|
-
const lines = [];
|
|
422
|
-
lines.push(blank(width));
|
|
423
|
-
lines.push([span('', ' '), span(C.white + BOLD, 'Select provider'), span(BOLD_OFF, '')]);
|
|
424
|
-
lines.push([span('', ' '), span(C.gray, 'Which vendor the key you are about to paste belongs to.')]);
|
|
425
|
-
lines.push(blank(width));
|
|
426
|
-
for (let i = 0; i < list.length; i++) {
|
|
427
|
-
const p = list[i] || {};
|
|
428
|
-
const id = String(p.id || '');
|
|
429
|
-
if (!id) continue;
|
|
430
|
-
const active = i === sel;
|
|
431
|
-
const cur = current != null && id === current;
|
|
432
|
-
const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
|
|
433
|
-
const nameSpan = active ? span(C.lavender, id) : span(C.white, id);
|
|
434
|
-
const mark = cur ? span(C.green, ' ' + GLYPH.check) : span('', '');
|
|
435
|
-
const name = String(p.label || '');
|
|
436
|
-
const pad = ' '.repeat(Math.max(1, 16 - [...id].length));
|
|
437
|
-
const state = p.configured
|
|
438
|
-
? span(C.green, `set${p.masked ? ` (${p.masked})` : ''}`)
|
|
439
|
-
: span(C.gray, 'not set');
|
|
440
|
-
lines.push([
|
|
441
|
-
span('', ' '), left, span('', ' '), nameSpan, mark,
|
|
442
|
-
span(C.gray, pad + (name ? `${name} · ` : '')), state,
|
|
443
|
-
]);
|
|
444
|
-
}
|
|
445
|
-
lines.push(blank(width));
|
|
446
|
-
lines.push([
|
|
447
|
-
span('', ' '),
|
|
448
|
-
span(C.gray, hint || `↑↓ or tab move ${GLYPH.bullet} enter picks ${GLYPH.bullet} esc cancels`),
|
|
449
|
-
]);
|
|
450
|
-
return fit(lines, width);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
module.exports = {
|
|
454
|
-
boldMatched,
|
|
455
|
-
renderPalette,
|
|
456
|
-
renderModelPicker,
|
|
457
|
-
renderEffortPicker,
|
|
458
|
-
renderClassPicker,
|
|
459
|
-
renderProviderPicker,
|
|
460
|
-
renderResumeList,
|
|
461
|
-
EFFORT_LEVELS,
|
|
462
|
-
EFFORT_VALUES,
|
|
463
|
-
PICKER_HINT,
|
|
464
|
-
};
|
|
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)"},{label:"Max",note:"Deepest reasoning where the model defines it; same budget as high"}],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)),f="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+f)])}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};
|