aegiscode 6.8.3 → 6.8.5
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/README.md +2 -2
- package/bin/aegiscode.js +35 -5
- package/package.json +1 -6
- package/scripts/predist.mjs +99 -0
- package/src/agents.js +1 -1
- package/src/app.js +41 -9
- package/src/caps.js +1 -1
- package/src/chatflow.js +182 -34
- package/src/checkpoint.js +1 -1
- package/src/clipboard.js +1 -1
- package/src/commands.js +158 -21
- package/src/config.js +2 -2
- package/src/deps.js +2 -1
- package/src/devrun.js +1 -1
- package/src/diff.js +1 -1
- package/src/events.js +38 -15
- package/src/export.js +1 -1
- package/src/fuzzy.js +1 -1
- package/src/history.js +3 -3
- package/src/init.js +1 -1
- package/src/input.js +1 -1
- package/src/keys.js +1 -1
- package/src/markdown.js +2 -2
- package/src/mcp.js +683 -0
- package/src/overlays.js +2 -2
- package/src/panels.js +52 -19
- package/src/permissions.js +2 -2
- package/src/render.js +2 -2
- package/src/screen.js +133 -8
- package/src/screens.js +1 -1
- package/src/summarize.js +1 -1
- package/src/system.js +2 -2
- package/src/theme.js +6 -6
- package/src/title.js +217 -0
- package/src/tokens.js +75 -96
- package/src/update.js +75 -1
- package/vendor/desktop/lib/local/agents.js +1 -1
- package/vendor/desktop/lib/local/autonomous.js +1 -1
- package/vendor/desktop/lib/local/engine.js +32 -8
- package/vendor/desktop/lib/local/git-scope.js +1 -1
- package/vendor/desktop/lib/local/prompt.js +3 -3
- package/vendor/desktop/lib/local/queue.js +2 -2
- package/vendor/desktop/lib/local/shell.js +1 -1
- package/vendor/desktop/lib/local/tools.js +2 -2
- package/vendor/desktop/lib/local/turn-guard.js +1 -1
- package/vendor/desktop/lib/local/worktree-lock.js +1 -1
- package/vendor/desktop/lib/settings.js +67 -0
- package/vendor/desktop/renderer/usage.js +377 -46
- package/vendor/hosts/install.js +638 -0
- package/vendor/hosts/openai-shim.js +419 -0
- package/vendor/hosts/spec.js +164 -0
- package/vendor/hosts/targets.js +346 -0
- package/vendor/mcp/server.js +186 -0
package/src/panels.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Panel builders — the bodies that slash-commands print.
|
|
5
5
|
*
|
|
6
|
-
* Ported from
|
|
6
|
+
* Ported from the upstream engine reference (868 lines), keeping its layouts
|
|
7
7
|
* and copy wherever the capability exists in this client. Everything here is
|
|
8
8
|
* PURE: a builder receives all of its data as arguments and returns an array of
|
|
9
9
|
* span lines (each line an array of `{ t, s, w }`, see `screen.js`). No stdout
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* module-scoped palette. Money is euro: `fmtEur` renders 4dp below a cent (a
|
|
15
15
|
* pooled call settles near €0.0007) and 2dp at or above it, so a real charge
|
|
16
16
|
* never reads as "€0.00". The reference printed USD; every `$` became `€`.
|
|
17
|
-
* Claude/Anthropic names became AEGIS (`aegiscode`, `aegiscloud.org
|
|
18
|
-
*
|
|
17
|
+
* Claude/Anthropic names became AEGIS (`aegiscode`, `aegiscloud.org`)
|
|
18
|
+
* and `~/.aegiscodex` became
|
|
19
19
|
* `~/.aegiscode`.
|
|
20
20
|
*
|
|
21
21
|
* Every builder is defensive: a missing field is omitted, never rendered as
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
*
|
|
35
35
|
* ── Honest stubs (capability absent in this client) ──────────────────────────
|
|
36
36
|
* buildDoctor — needs the local environment diagnostic suite (runDoctor),
|
|
37
|
-
* which belongs to
|
|
37
|
+
* which belongs to the upstream engine; /doctor is unavailable.
|
|
38
38
|
* buildBuildPanel — needs a local multi-model agent build loop this client
|
|
39
39
|
* does not host.
|
|
40
40
|
*/
|
|
@@ -60,6 +60,30 @@ function str(v) {
|
|
|
60
60
|
return v == null ? '' : String(v);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The four token buckets these panels render, in the shared shape.
|
|
65
|
+
*
|
|
66
|
+
* `input` is the MISS half only — that is what `usageBuckets` normalises it to
|
|
67
|
+
* for every provider, and what the ledger rows and the desktop roll store — so
|
|
68
|
+
* the prompt a context window actually holds is `input + cacheRead +
|
|
69
|
+
* cacheWrite`, NOT `input` alone. Totalling `input + output` (what this file
|
|
70
|
+
* did before) therefore silently dropped the entire cached prompt: the exact
|
|
71
|
+
* turns where the cache was working and the context was largest were the turns
|
|
72
|
+
* the meter under-reported.
|
|
73
|
+
*
|
|
74
|
+
* `tok.total` wins when a caller supplies one (the live session tally does), so
|
|
75
|
+
* this fallback can only ever add information, never overwrite it. One formula,
|
|
76
|
+
* one place: /cost, /context and /tokens must not disagree about the same turn.
|
|
77
|
+
*/
|
|
78
|
+
function tokenBuckets(tok) {
|
|
79
|
+
const input = num(tok.input);
|
|
80
|
+
const output = num(tok.output);
|
|
81
|
+
const cacheRead = num(tok.cacheRead);
|
|
82
|
+
const cacheWrite = num(tok.cacheWrite);
|
|
83
|
+
const prompt = input + cacheRead + cacheWrite;
|
|
84
|
+
return { input, output, cacheRead, cacheWrite, prompt, total: num(tok.total) || prompt + output };
|
|
85
|
+
}
|
|
86
|
+
|
|
63
87
|
/** Group digits: 1562 -> "1,562". Matches the CLI's format.js rule. */
|
|
64
88
|
function fmtTokens(n) {
|
|
65
89
|
const v = Number(n);
|
|
@@ -267,9 +291,7 @@ function buildCost(state, ctx = {}) {
|
|
|
267
291
|
const { cols } = getSize();
|
|
268
292
|
const W = Math.max(30, cols - 2);
|
|
269
293
|
const tok = s.tokens && typeof s.tokens === 'object' ? s.tokens : {};
|
|
270
|
-
const input =
|
|
271
|
-
const output = num(tok.output);
|
|
272
|
-
const total = num(tok.total) || input + output;
|
|
294
|
+
const { input, output, cacheRead, cacheWrite, prompt, total } = tokenBuckets(tok);
|
|
273
295
|
const cost = num(s.costEur);
|
|
274
296
|
const model = str(s.model) || 'the pinned model';
|
|
275
297
|
const window = num(s.contextWindow) || 200000;
|
|
@@ -290,7 +312,14 @@ function buildCost(state, ctx = {}) {
|
|
|
290
312
|
lines.push([span('', ' '), span(t.white, 'Turns:'), span(t.gray, ` ${num(s.turns)} turns · ${num(s.calls)} calls`)]);
|
|
291
313
|
}
|
|
292
314
|
lines.push([span('', ' '), span(t.white, ' Usage by model:')]);
|
|
293
|
-
|
|
315
|
+
// The prompt, not the miss. `input` is the miss half only (see tokenBuckets),
|
|
316
|
+
// so printing it as "input" reported 1.2k for a turn that had sent 31.2k —
|
|
317
|
+
// the same under-report /context was fixed for, in the panel that sits right
|
|
318
|
+
// next to it. With a cache in play the row is a sum, so show the split too.
|
|
319
|
+
lines.push([span('', ' '), span(t.gray, ` ${model}: ${fmtTokens(prompt)} input, ${fmtTokens(output)} output (${fmtEur(cost)})`)]);
|
|
320
|
+
if (cacheRead || cacheWrite) {
|
|
321
|
+
lines.push([span('', ' '), span(t.dim, ` ↳ miss ${fmtTokens(input)} · cache read ${fmtTokens(cacheRead)} · cache write ${fmtTokens(cacheWrite)}`)]);
|
|
322
|
+
}
|
|
294
323
|
lines.push([span('', ' ')]);
|
|
295
324
|
lines.push([span('', ' '), span(t.white + BOLD, 'Current session'), span(BOLD_OFF, '')]);
|
|
296
325
|
lines.push(contextBar(total, window, t));
|
|
@@ -309,9 +338,7 @@ function buildContext(state, ctx = {}) {
|
|
|
309
338
|
const { cols } = getSize();
|
|
310
339
|
const W = Math.max(30, cols - 2);
|
|
311
340
|
const tok = s.tokens && typeof s.tokens === 'object' ? s.tokens : {};
|
|
312
|
-
const input =
|
|
313
|
-
const output = num(tok.output);
|
|
314
|
-
const total = num(tok.total) || input + output;
|
|
341
|
+
const { input, output, cacheRead, cacheWrite, prompt, total } = tokenBuckets(tok);
|
|
315
342
|
const window = num(s.contextWindow) || 200000;
|
|
316
343
|
|
|
317
344
|
const lines = [];
|
|
@@ -324,7 +351,17 @@ function buildContext(state, ctx = {}) {
|
|
|
324
351
|
span('', ' '.repeat(Math.max(1, 10 - fmtTokens(tokens).length))),
|
|
325
352
|
...contextBar(tokens, window, t),
|
|
326
353
|
];
|
|
327
|
-
lines.push(row('Prompt tokens',
|
|
354
|
+
lines.push(row('Prompt tokens', prompt));
|
|
355
|
+
// With a cache in play the prompt row is a SUM, and a sum hides the one thing
|
|
356
|
+
// the operator is looking for: how much of the prompt was re-sent at full
|
|
357
|
+
// price. Show the split, so "280.0k" cannot be misread as 280k of fresh
|
|
358
|
+
// input. Absent a cache the row is byte-identical to before.
|
|
359
|
+
if (cacheRead || cacheWrite) {
|
|
360
|
+
lines.push([
|
|
361
|
+
span('', ' '),
|
|
362
|
+
span(t.dim, ` ↳ miss ${fmtTokens(input)} · cache read ${fmtTokens(cacheRead)} · cache write ${fmtTokens(cacheWrite)}`),
|
|
363
|
+
]);
|
|
364
|
+
}
|
|
328
365
|
lines.push(row('Output tokens', output));
|
|
329
366
|
lines.push([span('', ' ')]);
|
|
330
367
|
lines.push([span('', ' '), span(t.gray, '─'.repeat(Math.max(1, W - 2)))]);
|
|
@@ -574,7 +611,7 @@ function buildTroubleshooting(state, ctx = {}) {
|
|
|
574
611
|
lines.push([span('', ' '), span(t.gray, fix)]);
|
|
575
612
|
}
|
|
576
613
|
lines.push([span('', '')]);
|
|
577
|
-
lines.push([span(t.gray, 'Run /status for account state. Help: https://
|
|
614
|
+
lines.push([span(t.gray, 'Run /status for account state. Help: https://aegiscloud.org')]);
|
|
578
615
|
return lines;
|
|
579
616
|
}
|
|
580
617
|
|
|
@@ -896,11 +933,7 @@ function buildTokens(state, ctx = {}) {
|
|
|
896
933
|
const { cols } = getSize();
|
|
897
934
|
const W = Math.max(24, cols - 2);
|
|
898
935
|
const tok = s.tokens && typeof s.tokens === 'object' ? s.tokens : {};
|
|
899
|
-
const input =
|
|
900
|
-
const output = num(tok.output);
|
|
901
|
-
const cacheRead = num(tok.cacheRead);
|
|
902
|
-
const cacheWrite = num(tok.cacheWrite);
|
|
903
|
-
const total = num(tok.total) || input + output;
|
|
936
|
+
const { input, output, cacheRead, cacheWrite, total } = tokenBuckets(tok);
|
|
904
937
|
const cost = num(s.costEur);
|
|
905
938
|
const window = num(s.contextWindow) || 200000;
|
|
906
939
|
const pct = window > 0 ? Math.min(100, Math.round((total / window) * 100)) : 0;
|
|
@@ -1220,7 +1253,7 @@ function buildReleaseNotes(state, ctx = {}) {
|
|
|
1220
1253
|
out.push([span(t.gray, ` ${counts.n} commands across ${counts.cats} categories — /help lists them.`)]);
|
|
1221
1254
|
}
|
|
1222
1255
|
out.push([span(t.gray, ' The version above is read from the package; the prose is not.')]);
|
|
1223
|
-
out.push([span(t.gray, ' Repo:
|
|
1256
|
+
out.push([span(t.gray, ' Repo: https://aegiscloud.org')]);
|
|
1224
1257
|
return out;
|
|
1225
1258
|
}
|
|
1226
1259
|
|
package/src/permissions.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* approval UX from the real binary, so this only applies to
|
|
7
7
|
* Bash/Read/Write/Edit/Glob/Grep run by a provider model.
|
|
8
8
|
*
|
|
9
|
-
* Scope decision
|
|
9
|
+
* Scope decision: the multi-directory-change Bash heuristic,
|
|
10
10
|
* explicit /permissions allow|deny|ask rules, and `defaultMode: 'ask'` when
|
|
11
11
|
* the permissions file *explicitly* writes it (rules.explicitAsk) are
|
|
12
12
|
* enforced here. The file-free default ('ask' in DEFAULT_PERMISSIONS) is
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* imported so this module has no import-cycle with tools.js (executeTool's
|
|
25
25
|
* home, which calls into this one).
|
|
26
26
|
*
|
|
27
|
-
* Ported from
|
|
27
|
+
* Ported from the upstream engine reference (ESM → CommonJS).
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
const RULE_RE = /^(\w+)(?:\((.*)\))?$/;
|
package/src/render.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The CLI's renderers — the start-up banner, transcript turns, the per-turn
|
|
5
5
|
* accounting line, the status bar, the live working line and the transcript's
|
|
6
6
|
* markdown body. The presentation layer is a fidelity port of
|
|
7
|
-
*
|
|
7
|
+
* the upstream engine: gold `━`/`─` rules, the one-ink ÆGIS wordmark (box runes,
|
|
8
8
|
* in gold), the coral-bold welcome title, the `❯` prompt, the
|
|
9
9
|
* `⎿` hook rows, the `●` answer/stream cursor and the `✻` done glyph.
|
|
10
10
|
*
|
|
@@ -397,7 +397,7 @@ function renderToolResult(ctx, name, text, width = 80) {
|
|
|
397
397
|
/**
|
|
398
398
|
* The tool-approval card: the mutating call the model wants to run (a diff
|
|
399
399
|
* for writeFile/editFile, the command for exec) and the three answers. One
|
|
400
|
-
* inline question, matching
|
|
400
|
+
* inline question, matching the upstream engine's Bash/edit approval dialog.
|
|
401
401
|
*/
|
|
402
402
|
function renderApproval(ctx, info = {}, width = 80) {
|
|
403
403
|
const t = themeOf(ctx);
|
package/src/screen.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* wrapping, and the ephemeral "live" region the CLI redraws while a call is in
|
|
6
6
|
* flight.
|
|
7
7
|
*
|
|
8
|
-
* The render model is
|
|
8
|
+
* The render model is the upstream engine's: a line is an array of spans
|
|
9
9
|
* `{ t: text, s: style-prefix, w: cell-width }`, built with `span()`, measured
|
|
10
10
|
* with `lineWidth()`, padded/truncated with `padLine()`, and painted with
|
|
11
11
|
* `paint()`. Two width functions exist because they have different callers:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* per-codepoint maths for a span line (the overlays use it).
|
|
15
15
|
*
|
|
16
16
|
* Design note — this CLI is a LINEAR transcript, not a full-screen alt-buffer
|
|
17
|
-
* TUI (which is what Claude Code and
|
|
17
|
+
* TUI (which is what Claude Code and the upstream engine are). Finished turns are
|
|
18
18
|
* written once to scrollback, so output stays selectable, pipeable and
|
|
19
19
|
* scrollback-searchable; only the one live status/spinner line is redrawn. The
|
|
20
20
|
* main session loop deliberately does NOT enter the alternate screen — `--print`
|
|
@@ -224,11 +224,129 @@ const isAltScreen = () => inAlt;
|
|
|
224
224
|
const enableBracketedPaste = () => process.stdout.write('\x1b[?2004h');
|
|
225
225
|
const disableBracketedPaste = () => process.stdout.write('\x1b[?2004l');
|
|
226
226
|
|
|
227
|
-
// Mouse
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
227
|
+
// Mouse tracking + SGR coordinates. DECSET 1000 is the press/wheel report the
|
|
228
|
+
// click-to-toggle path needs; 1002 adds DRAG reports, without which a
|
|
229
|
+
// drag-to-mark gesture is invisible — the terminal reports the press and the
|
|
230
|
+
// release and nothing in between, so a sweep over three lines arrives as a
|
|
231
|
+
// single-cell marking. The terminal's own selection can't substitute for it:
|
|
232
|
+
// the alt screen has no scrollback for the terminal to select from. Disabled on
|
|
233
|
+
// exit so the shell we return to isn't left forwarding raw wheel bytes as input.
|
|
234
|
+
const enableMouseTracking = () => process.stdout.write('\x1b[?1000h\x1b[?1002h\x1b[?1006h');
|
|
235
|
+
const disableMouseTracking = () => process.stdout.write('\x1b[?1000l\x1b[?1002l\x1b[?1006l');
|
|
236
|
+
|
|
237
|
+
// Reverse video, used to paint a mouse marking (text selection) over the
|
|
238
|
+
// already-styled grid: the selected slice keeps its own colors and inverts its
|
|
239
|
+
// background. SELECT_OFF (SGR 27) turns inversion back off for the spans that
|
|
240
|
+
// follow the selection on the same row — paint() only resets attributes at the
|
|
241
|
+
// start of a row, so a leftover inverse would wash out the row's tail.
|
|
242
|
+
const SELECT_ON = '\x1b[7m';
|
|
243
|
+
const SELECT_OFF = '\x1b[27m';
|
|
244
|
+
|
|
245
|
+
// ── mouse marking (text selection) ─────────────────────────────────────────
|
|
246
|
+
// The TUI owns the alternate screen, so the terminal's own drag-to-select is
|
|
247
|
+
// unreachable — a marking has to be built from the SGR drag stream (events.js)
|
|
248
|
+
// against the grid the last frame painted (chatflow.js keeps it as
|
|
249
|
+
// `frameLines`). All of it is pure and cell-based: coordinates are grid row +
|
|
250
|
+
// CELL column (0-based), never string indices, so wide glyphs and padded rows
|
|
251
|
+
// can't shift the selection off the text the reader is pointing at.
|
|
252
|
+
// Ported from the upstream engine reference so both hosts mark identically.
|
|
253
|
+
|
|
254
|
+
/** Two drag endpoints → the same range in reading order (top-left first). */
|
|
255
|
+
function selectionRange(a, b) {
|
|
256
|
+
if (a.row < b.row || (a.row === b.row && a.col <= b.col)) {
|
|
257
|
+
return { startRow: a.row, startCol: a.col, endRow: b.row, endCol: b.col };
|
|
258
|
+
}
|
|
259
|
+
return { startRow: b.row, startCol: b.col, endRow: a.row, endCol: a.col };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Clip a span line to the cell range [from, to). Edges are cut on whole code
|
|
264
|
+
* points via w() — slicing by character index would split a 2-cell glyph and
|
|
265
|
+
* shift every later column by one. Spans keep their own style, so a marking
|
|
266
|
+
* across a colored diff block stays colored.
|
|
267
|
+
*/
|
|
268
|
+
function sliceLine(line, from, to) {
|
|
269
|
+
const out = [];
|
|
270
|
+
let col = 0;
|
|
271
|
+
for (const sp of line) {
|
|
272
|
+
const start = col;
|
|
273
|
+
col += sp.w;
|
|
274
|
+
if (col <= from || start >= to) continue;
|
|
275
|
+
let text = sp.t;
|
|
276
|
+
let seen = start; // cell column of text[0]
|
|
277
|
+
if (seen < from) {
|
|
278
|
+
const drop = from - seen;
|
|
279
|
+
let acc = 0;
|
|
280
|
+
let cut = 0;
|
|
281
|
+
for (const ch of text) {
|
|
282
|
+
if (acc >= drop) break;
|
|
283
|
+
acc += w(ch);
|
|
284
|
+
cut += ch.length;
|
|
285
|
+
}
|
|
286
|
+
text = text.slice(cut);
|
|
287
|
+
seen += acc;
|
|
288
|
+
}
|
|
289
|
+
if (seen + w(text) > to) {
|
|
290
|
+
let acc = 0;
|
|
291
|
+
let keep = '';
|
|
292
|
+
for (const ch of text) {
|
|
293
|
+
const cw = w(ch);
|
|
294
|
+
if (seen + acc + cw > to) break;
|
|
295
|
+
keep += ch;
|
|
296
|
+
acc += cw;
|
|
297
|
+
}
|
|
298
|
+
text = keep;
|
|
299
|
+
}
|
|
300
|
+
if (text) out.push({ t: text, s: sp.s, w: w(text) });
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The text a marking covers, read as a terminal would copy it: hard newlines
|
|
307
|
+
* between rows, trailing padding trimmed (rows are padded to the full width,
|
|
308
|
+
* and nobody wants 200 spaces per line on the clipboard), leading/trailing
|
|
309
|
+
* blank rows dropped.
|
|
310
|
+
*/
|
|
311
|
+
function selectionText(lines, sel) {
|
|
312
|
+
const rows = [];
|
|
313
|
+
for (let r = sel.startRow; r <= sel.endRow; r++) {
|
|
314
|
+
const line = lines[r] || [];
|
|
315
|
+
const from = r === sel.startRow ? sel.startCol : 0;
|
|
316
|
+
const to = r === sel.endRow ? sel.endCol : Infinity;
|
|
317
|
+
rows.push(sliceLine(line, from, to).map((sp) => sp.t).join('').replace(/[ \t]+$/, ''));
|
|
318
|
+
}
|
|
319
|
+
while (rows.length && rows[0] === '') rows.shift();
|
|
320
|
+
while (rows.length && rows[rows.length - 1] === '') rows.pop();
|
|
321
|
+
return rows.join('\n');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* A copy of `lines` with the marked cells wrapped in reverse video. Rows
|
|
326
|
+
* outside the range are shared, not cloned — a marking repaints up to ~30x/sec
|
|
327
|
+
* during a sweep and only the rows it touches should allocate. Each is padded
|
|
328
|
+
* first so a short row's selection is still painted over the blank cells the
|
|
329
|
+
* reader dragged across.
|
|
330
|
+
*/
|
|
331
|
+
function applySelection(lines, sel, width) {
|
|
332
|
+
const out = lines.slice();
|
|
333
|
+
for (let r = sel.startRow; r <= sel.endRow; r++) {
|
|
334
|
+
if (r < 0 || r >= out.length) continue;
|
|
335
|
+
const line = padLine(out[r] || [], width);
|
|
336
|
+
const from = r === sel.startRow ? sel.startCol : 0;
|
|
337
|
+
const to = r === sel.endRow ? sel.endCol : width;
|
|
338
|
+
const mid = sliceLine(line, from, to);
|
|
339
|
+
if (!mid.length) continue;
|
|
340
|
+
out[r] = [
|
|
341
|
+
...sliceLine(line, 0, from),
|
|
342
|
+
{ t: '', s: SELECT_ON, w: 0 },
|
|
343
|
+
...mid,
|
|
344
|
+
{ t: '', s: SELECT_OFF, w: 0 },
|
|
345
|
+
...sliceLine(line, to, width),
|
|
346
|
+
];
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
232
350
|
|
|
233
351
|
/**
|
|
234
352
|
* Paint span lines top-aligned and clear the rest of the frame. Used by the
|
|
@@ -326,7 +444,7 @@ module.exports = {
|
|
|
326
444
|
stripAnsi,
|
|
327
445
|
wrapLine,
|
|
328
446
|
wrapBlock,
|
|
329
|
-
// span/line render model (from
|
|
447
|
+
// span/line render model (from the upstream engine)
|
|
330
448
|
span,
|
|
331
449
|
lineWidth,
|
|
332
450
|
padLine,
|
|
@@ -346,6 +464,13 @@ module.exports = {
|
|
|
346
464
|
disableBracketedPaste,
|
|
347
465
|
enableMouseTracking,
|
|
348
466
|
disableMouseTracking,
|
|
467
|
+
// mouse marking (text selection)
|
|
468
|
+
SELECT_ON,
|
|
469
|
+
SELECT_OFF,
|
|
470
|
+
selectionRange,
|
|
471
|
+
sliceLine,
|
|
472
|
+
selectionText,
|
|
473
|
+
applySelection,
|
|
349
474
|
// the live region + sizing (app/bin)
|
|
350
475
|
LiveRegion,
|
|
351
476
|
termWidth,
|
package/src/screens.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Onboarding screens — trust check, theme picker, welcome.
|
|
5
5
|
*
|
|
6
|
-
* A direct port of
|
|
6
|
+
* A direct port of the upstream engine reference, which is where the
|
|
7
7
|
* reference's session actually begins: a genuine first run is
|
|
8
8
|
*
|
|
9
9
|
* showTrustCheck(ctx) → showThemePicker(ctx) → updateConfig() → welcome
|
package/src/summarize.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Transcript summarization for /compact and /recap.
|
|
5
5
|
*
|
|
6
|
-
* Dependency-free port of
|
|
6
|
+
* Dependency-free port of the upstream engine reference. The reference
|
|
7
7
|
* spawns `claude -p "Summarize…"` (via platform.resolveExecutable); here the
|
|
8
8
|
* backend is *injected* instead, so this module pulls in nothing but tokens.js:
|
|
9
9
|
*
|
package/src/system.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Small system helpers: best-effort URL opening (never blocks or errors) and
|
|
5
5
|
* a few constants shared by the support/easter-egg commands.
|
|
6
6
|
*
|
|
7
|
-
* Ported from
|
|
7
|
+
* Ported from the upstream engine reference (ESM → CommonJS). The URLS table
|
|
8
8
|
* pointed at Anthropic/Claude support endpoints; those are re-homed to the
|
|
9
9
|
* AEGIS base (https://aegiscloud.org) and the project repo. Deep paths that
|
|
10
10
|
* had no AEGIS equivalent collapse to the base rather than inventing a route.
|
|
@@ -29,7 +29,7 @@ function openUrl(url) {
|
|
|
29
29
|
const URLS = {
|
|
30
30
|
troubleshooting: 'https://aegiscloud.org',
|
|
31
31
|
feedback: 'https://aegiscloud.org',
|
|
32
|
-
issues: 'https://
|
|
32
|
+
issues: 'https://aegiscloud.org',
|
|
33
33
|
docs: 'https://aegiscloud.org',
|
|
34
34
|
radio: 'https://www.youtube.com/watch?v=cP8jB6YQWbQ',
|
|
35
35
|
};
|
package/src/theme.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Design tokens — the
|
|
4
|
+
* Design tokens — the upstream engine design system, adopted wholesale, and
|
|
5
5
|
* resolved through the terminal's capabilities (`caps.js`) rather than the
|
|
6
6
|
* platform the process happens to run on.
|
|
7
7
|
*
|
|
8
|
-
* Every colour value below is copied verbatim from
|
|
8
|
+
* Every colour value below is copied verbatim from the upstream engine's theme,
|
|
9
9
|
* which extracted them from the live ANSI stream of Claude Code: gold 255,193,7
|
|
10
10
|
* · coral 215,119,87 · lavender 177,185,249 · blue 120,160,250 · green 78,186,101
|
|
11
11
|
* · red 220,90,90 · gray 153,153,153 · dim 80,80,80. `test/cli-conformance.test.mjs`
|
|
12
|
-
* pins them to
|
|
12
|
+
* pins them to the upstream engine's source and reads them back out of a truecolor
|
|
13
13
|
* SGR prefix, so the design cannot drift.
|
|
14
14
|
*
|
|
15
15
|
* What DOES change per terminal is how those triples reach the screen:
|
|
@@ -61,7 +61,7 @@ const BG = (r, g, b) => bg(r, g, b);
|
|
|
61
61
|
// capability change keeps the key set identical (the conformance guard pins
|
|
62
62
|
// `Object.keys(C)`) while the escapes follow the new depth.
|
|
63
63
|
|
|
64
|
-
/** The dark palette. Role names match
|
|
64
|
+
/** The dark palette. Role names match the upstream engine exactly. */
|
|
65
65
|
const C = {};
|
|
66
66
|
/** Light-theme approximations, true to the dark palette's hue mapping. */
|
|
67
67
|
const LIGHT = {};
|
|
@@ -148,7 +148,7 @@ function buildAnsiLight() {
|
|
|
148
148
|
/**
|
|
149
149
|
* Diff palette for edit blocks in the transcript — Monokai Extended, taken
|
|
150
150
|
* verbatim from the theme picker's preview (also `renderDiffPreview` in
|
|
151
|
-
*
|
|
151
|
+
* the upstream engine's markdown renderer) so the two can never drift apart: dim
|
|
152
152
|
* red/green backgrounds per row, the bright variant for the token that
|
|
153
153
|
* actually changed inside the row, and the monokai syntax colors for the code
|
|
154
154
|
* itself.
|
|
@@ -217,7 +217,7 @@ const THEMES = { dark: C, light: LIGHT };
|
|
|
217
217
|
* remapped anyway — the whole point being that the *terminal* decides, not us.
|
|
218
218
|
*/
|
|
219
219
|
/**
|
|
220
|
-
* The theme picker's table, copied from
|
|
220
|
+
* The theme picker's table, copied from the upstream engine's screens THEMES
|
|
221
221
|
* (names and notes verbatim). `light` is the flag the reference sets on commit
|
|
222
222
|
* (`ctx.light = sel === 2 || sel === 4 || sel === 6`); `palette` is what this
|
|
223
223
|
* client resolves the row to, since it has no terminal-background probe and so
|
package/src/title.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The terminal title bar — the session's *topic*.
|
|
5
|
+
*
|
|
6
|
+
* Claude Code keeps the window/tab title pointed at what the session is about
|
|
7
|
+
* ("✳ Fixing the nexus hang") rather than at a static product string, so a row
|
|
8
|
+
* of terminal tabs is readable at a glance. This host shipped the static half
|
|
9
|
+
* only: `chatflow.js`'s `setTitle()` wrote "AEGIS Code" forever, spinning a
|
|
10
|
+
* braille frame while a turn ran and never naming the work. Every tab of every
|
|
11
|
+
* session read the same, which is exactly the problem the topic solves.
|
|
12
|
+
*
|
|
13
|
+
* The topic is derived from the user's own prompt, locally — no model call, so
|
|
14
|
+
* it costs nothing, adds no latency to the first frame, and cannot invent a
|
|
15
|
+
* task the user never asked for. It is re-derived per prompt and adopted only
|
|
16
|
+
* when the ask is about something new (`adoptTopic`), so a follow-up like
|
|
17
|
+
* "now add a test for that" keeps the title it inherited.
|
|
18
|
+
*
|
|
19
|
+
* Everything here is pure and returns strings, so the whole surface is
|
|
20
|
+
* assertable without a TTY; `writeTitle` is the one function that touches a
|
|
21
|
+
* stream, and it swallows a non-writable one.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** The title the app wears before a topic exists (and after one is cleared). */
|
|
25
|
+
const DEFAULT_TITLE = 'AEGIS Code';
|
|
26
|
+
|
|
27
|
+
/** The braille frames the title spins while a turn runs (the reference's). */
|
|
28
|
+
const TITLE_SPIN = ['⠐', '⠂', '⠄', '⠆', '⠈', '⠠', '⠰', '⠁'];
|
|
29
|
+
|
|
30
|
+
/** Longest topic, in cells, before it is clipped on a word boundary. */
|
|
31
|
+
const TOPIC_MAX = 48;
|
|
32
|
+
|
|
33
|
+
/** Longest string that ever reaches the terminal (topic + " · AEGIS Code"). */
|
|
34
|
+
const TITLE_MAX = 96;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Politeness and throat-clearing, stripped from the front of a prompt so the
|
|
38
|
+
* title says "Add a retry to the fetcher" instead of "Please can you add a
|
|
39
|
+
* retry to the fetcher". Applied repeatedly — "ok so please can you…" is one
|
|
40
|
+
* habit, not four.
|
|
41
|
+
*/
|
|
42
|
+
const FILLER =
|
|
43
|
+
/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and|i'?m trying to|i am trying to|i'?m working on|i am working on)\b[\s,:;-]*/i;
|
|
44
|
+
|
|
45
|
+
/** Leading markdown/list/quote noise: `> `, `- `, `1. `, `## `. */
|
|
46
|
+
const LEADING_NOISE = /^(?:[>#*•·\-–—]+|\d+[.)])\s*/;
|
|
47
|
+
|
|
48
|
+
/** Words that carry no topic signal when comparing two asks. */
|
|
49
|
+
const STOPWORDS = new Set([
|
|
50
|
+
'the', 'and', 'for', 'with', 'that', 'this', 'these', 'those', 'you', 'your', 'yours',
|
|
51
|
+
'can', 'could', 'would', 'should', 'will', 'please', 'pls', 'hey', 'now', 'then',
|
|
52
|
+
'from', 'into', 'onto', 'over', 'under', 'about', 'also', 'just', 'like', 'want',
|
|
53
|
+
'need', 'make', 'made', 'use', 'using', 'get', 'got', 'let', 'lets', 'its', 'it',
|
|
54
|
+
'are', 'was', 'were', 'been', 'has', 'have', 'had', 'but', 'not', 'all', 'any',
|
|
55
|
+
'how', 'what', 'when', 'where', 'which', 'who', 'why', 'there', 'here', 'some',
|
|
56
|
+
'one', 'two', 'add', 'new', 'fix', 'fixing', 'help', 'doing', 'does', 'did', 'me',
|
|
57
|
+
'my', 'our', 'we', 'i', 'a', 'an', 'to', 'of', 'in', 'on', 'at', 'is', 'be', 'do',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
/** Strip anything that could break out of the OSC title sequence. */
|
|
61
|
+
function sanitize(text, max = TITLE_MAX) {
|
|
62
|
+
const flat = String(text == null ? '' : text)
|
|
63
|
+
// Control chars (including ESC, BEL, CR, LF, TAB) become a space, so a
|
|
64
|
+
// prompt can never inject an escape sequence into the title bar — the one
|
|
65
|
+
// place in this UI where user text reaches the terminal unsanitized.
|
|
66
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
67
|
+
.replace(/\s+/g, ' ')
|
|
68
|
+
.trim();
|
|
69
|
+
if (flat.length <= max) return flat;
|
|
70
|
+
return `${flat.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A short, single-line topic for a user prompt.
|
|
75
|
+
*
|
|
76
|
+
* Uses the first line that has anything on it (a pasted block's first line is
|
|
77
|
+
* its subject), drops politeness and list noise, collapses whitespace, and
|
|
78
|
+
* clips on a word boundary with an ellipsis. Returns '' when there is nothing
|
|
79
|
+
* to say — the caller then keeps the title it already had.
|
|
80
|
+
*/
|
|
81
|
+
function topicFrom(text, { max = TOPIC_MAX } = {}) {
|
|
82
|
+
if (text == null) return '';
|
|
83
|
+
const lines = String(text).split(/[\r\n]+/);
|
|
84
|
+
let line = '';
|
|
85
|
+
for (const raw of lines) {
|
|
86
|
+
const cleaned = sanitize(raw, 4_000).replace(LEADING_NOISE, '').trim();
|
|
87
|
+
// A pasted block's fence marker is not the topic; the code under it is.
|
|
88
|
+
if (!cleaned || /^```/.test(cleaned)) continue;
|
|
89
|
+
line = cleaned;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (!line) return '';
|
|
93
|
+
let body = line;
|
|
94
|
+
for (let i = 0; i < 6; i++) {
|
|
95
|
+
const next = body.replace(FILLER, '');
|
|
96
|
+
if (next === body) break;
|
|
97
|
+
body = next.replace(LEADING_NOISE, '').trim();
|
|
98
|
+
}
|
|
99
|
+
body = body.replace(/[.!?]+$/, '').trim();
|
|
100
|
+
if (!body) body = line;
|
|
101
|
+
if (/^[a-z]/.test(body)) body = body[0].toUpperCase() + body.slice(1);
|
|
102
|
+
return sanitize(body, max);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Topic-defining words of a phrase: lowercase, deduped, stopwords dropped. */
|
|
106
|
+
function keywords(phrase) {
|
|
107
|
+
const out = new Set();
|
|
108
|
+
for (const word of String(phrase || '').toLowerCase().match(/[\p{L}\p{N}_]+/gu) || []) {
|
|
109
|
+
if (word.length < 3 || STOPWORDS.has(word)) continue;
|
|
110
|
+
out.add(word);
|
|
111
|
+
}
|
|
112
|
+
return [...out];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Does `next` read as a *different* task from `prev`?
|
|
117
|
+
*
|
|
118
|
+
* The overlap is measured against the shorter keyword set, so a long follow-up
|
|
119
|
+
* that repeats the subject ("also add a test for the config loader") is not
|
|
120
|
+
* mistaken for a new task, while a genuinely unrelated ask ("now write the
|
|
121
|
+
* changelog") is. An empty `next` is never a shift — it means "no topic", and
|
|
122
|
+
* the caller keeps what it had.
|
|
123
|
+
*/
|
|
124
|
+
function titleShift(prev, next, { threshold = 0.34 } = {}) {
|
|
125
|
+
if (!next) return false;
|
|
126
|
+
if (!prev) return true;
|
|
127
|
+
const a = keywords(prev);
|
|
128
|
+
const b = keywords(next);
|
|
129
|
+
if (!a.length || !b.length) return true;
|
|
130
|
+
const set = new Set(a);
|
|
131
|
+
let hits = 0;
|
|
132
|
+
for (const word of b) if (set.has(word)) hits++;
|
|
133
|
+
return hits / Math.min(a.length, b.length) < threshold;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The topic after this prompt: the new one only when it is a new task. */
|
|
137
|
+
function adoptTopic(prev, prompt, opts) {
|
|
138
|
+
const next = topicFrom(prompt);
|
|
139
|
+
if (!next) return prev || '';
|
|
140
|
+
return titleShift(prev, next, opts) ? next : prev || '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The composed title.
|
|
145
|
+
*
|
|
146
|
+
* working, with topic `⠂ Fixing the config loader`
|
|
147
|
+
* idle, with topic `Fixing the config loader · AEGIS Code`
|
|
148
|
+
* no topic `AEGIS Code`
|
|
149
|
+
*
|
|
150
|
+
* The idle form keeps the product name so a tab is still identifiable as this
|
|
151
|
+
* CLI; the working form is the topic alone, which is what Claude Code shows
|
|
152
|
+
* while a turn runs.
|
|
153
|
+
*/
|
|
154
|
+
function titleText({ topic = '', frame = null, app = DEFAULT_TITLE } = {}) {
|
|
155
|
+
const clean = sanitize(topic, TOPIC_MAX);
|
|
156
|
+
if (!clean) return sanitize(app, TITLE_MAX) || DEFAULT_TITLE;
|
|
157
|
+
const head = frame ? `${frame} ` : '';
|
|
158
|
+
return sanitize(frame ? `${head}${clean}` : `${clean} · ${app}`, TITLE_MAX);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Truthiness for the env flags: `1`, `true`, `yes`, `on` (any case). */
|
|
162
|
+
function flagOn(value) {
|
|
163
|
+
if (value === true) return true;
|
|
164
|
+
if (value == null || value === false) return false;
|
|
165
|
+
return /^(?:1|true|yes|on)$/i.test(String(value).trim());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Is the title bar ours to write?
|
|
170
|
+
*
|
|
171
|
+
* On by default — a title that follows the work is the feature. Off via
|
|
172
|
+
* `AEGIS_DISABLE_TERMINAL_TITLE=1` (and Claude Code's own
|
|
173
|
+
* `CLAUDE_CODE_DISABLE_TERMINAL_TITLE`, so a shell configured for the
|
|
174
|
+
* reference behaves the same here), or `terminalTitle: false` in config.json.
|
|
175
|
+
* `AEGIS_TERMINAL_TITLE=1` wins over the config, for a one-off run.
|
|
176
|
+
*/
|
|
177
|
+
function titleEnabled(env = {}, config = {}) {
|
|
178
|
+
const e = env || {};
|
|
179
|
+
if (flagOn(e.AEGIS_TERMINAL_TITLE)) return true;
|
|
180
|
+
if (flagOn(e.AEGIS_DISABLE_TERMINAL_TITLE)) return false;
|
|
181
|
+
if (flagOn(e.CLAUDE_CODE_DISABLE_TERMINAL_TITLE)) return false;
|
|
182
|
+
const cfg = config || {};
|
|
183
|
+
if (cfg.terminalTitle === false || cfg.terminalTitleBar === false) return false;
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Write one title to a stream as an OSC 0 sequence. `''` clears it (what the
|
|
189
|
+
* teardown wants, so the shell that gets the terminal back is not left wearing
|
|
190
|
+
* this app's title). Never throws: a stubbed, closed or non-TTY stream is a
|
|
191
|
+
* missing nicety, not a reason to lose a turn.
|
|
192
|
+
*/
|
|
193
|
+
function writeTitle(text, out) {
|
|
194
|
+
const stream = out || process.stdout;
|
|
195
|
+
if (!stream || typeof stream.write !== 'function') return false;
|
|
196
|
+
try {
|
|
197
|
+
stream.write(`\x1b]0;${sanitize(text, TITLE_MAX)}\x07`);
|
|
198
|
+
return true;
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
module.exports = {
|
|
205
|
+
DEFAULT_TITLE,
|
|
206
|
+
TITLE_SPIN,
|
|
207
|
+
TOPIC_MAX,
|
|
208
|
+
TITLE_MAX,
|
|
209
|
+
sanitize,
|
|
210
|
+
topicFrom,
|
|
211
|
+
keywords,
|
|
212
|
+
titleShift,
|
|
213
|
+
adoptTopic,
|
|
214
|
+
titleText,
|
|
215
|
+
titleEnabled,
|
|
216
|
+
writeTitle,
|
|
217
|
+
};
|