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/render.js CHANGED
@@ -1,517 +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
- * The CLI's renderers — the start-up banner, transcript turns, the per-turn
10
- * accounting line, the status bar, the live working line and the transcript's
11
- * markdown body. The presentation layer is a fidelity port of
12
- * the upstream engine: gold `━`/`─` rules, the one-ink ÆGIS wordmark (box runes,
13
- * in gold), the coral-bold welcome title, the `❯` prompt, the
14
- * `⎿` hook rows, the `●` answer/stream cursor and the `✻` done glyph.
15
- *
16
- * Every function returns lines (strings carrying SGR escapes) rather than
17
- * writing to stdout, so the whole surface is assertable from a plain Node test
18
- * with no TTY and no child process — the same split the desktop uses for its
19
- * pure renderer modules. The markdown body is delegated to `./markdown.js`
20
- * (returning span lines); the require is guarded so this file always loads even
21
- * if that module is absent, falling back to the built-in `mdLines`.
22
- */
23
-
24
- const {
25
- RGB,
26
- BG,
27
- RESET,
28
- BOLD,
29
- DIM,
30
- ITALIC,
31
- UNDER,
32
- RESET_FG,
33
- RESET_BG,
34
- GLYPH,
35
- VERBS,
36
- DONE_VERBS,
37
- themeOf,
38
- } = require('./theme.js');
39
- const { WELCOME_TITLE, WELCOME_BACK, TAGLINE, STAR, stencilGlyph, welcomeArtParts } = require('./art.js');
40
- const { w, pad, padStart, wrapBlock, clip, span } = require('./screen.js');
41
- const { fmtTokens, fmtEur, fmtElapsed, fmtUsageSplit, displayTokens, feeBillable } = require('./format.js');
42
- const { renderDiffBlock } = require('./diffview.js');
43
-
44
- // Guarded: a concurrent workstream owns ./markdown.js.
45
- let markdown = null;
46
- try {
47
- // eslint-disable-next-line global-require
48
- markdown = require('./markdown.js');
49
- } catch {
50
- markdown = null;
51
- }
52
-
53
- // The failed-check `✗` and warning `⚠` marks now come from the shared glyph
54
- // table (`GLYPH.err` / `GLYPH.warn`), which downgrades them to `x` / `!` on a
55
- // terminal with no Unicode claim. They used to be two file-local constants
56
- // here, so a legacy Windows console printed U+2717 and U+26A0 into a font that
57
- // has neither — the notice rows were the last place the ASCII pass could not
58
- // reach. Read them at CALL time: `GLYPH` is mutated in place by `/terminal`, so
59
- // a value captured at require time would survive the switch.
60
- const errMark = () => GLYPH.err;
61
- const warnMark = () => GLYPH.warn;
62
-
63
- const fg = (t, c) => `${c}`;
64
- const bg = (c) => BG(...c);
65
-
66
- /** Flatten a span line back to an ANSI string (what the transcript emits). */
67
- const spansToString = (line) => line.map((sp) => (sp.s || '') + sp.t).join('') + RESET;
68
-
69
- /** Centre plain `text` inside `width`, painted with `style` (never overflows). */
70
- function centerStyled(text, width, style) {
71
- const tt = clip(text, width);
72
- const p = Math.max(0, Math.floor((width - w(tt)) / 2));
73
- return ' '.repeat(p) + style + tt + RESET;
74
- }
75
-
76
- /** The right (moon + whale) half of the mark: ▓ blue, ▒ lavender, ░ dim,
77
- * eye white, stars gold.
78
- *
79
- * The keys are the runes as `art.js` drew them, then run through the stencil:
80
- * `artRow` is handed rows that have *already* been stencilled for this
81
- * platform, so a raw-rune table silently matched nothing on win32/darwin and
82
- * the whole moon/whale half rendered uncoloured there — the mark looked
83
- * different on two of the three platforms it ships to. */
84
- function tintWhale(str, t) {
85
- const byRune = { '▓': t.blue, '▒': t.lavender, '░': t.dim, '█': t.white, [STAR]: t.gold, '·': t.dim };
86
- const map = {};
87
- for (const rune of Object.keys(byRune)) map[stencilGlyph(rune)] = byRune[rune];
88
- const spans = [];
89
- let cur = null;
90
- let style = '';
91
- for (const ch of str) {
92
- const s = map[ch] != null ? map[ch] : '';
93
- if (cur !== null && s === style) {
94
- cur += ch;
95
- } else {
96
- if (cur !== null) spans.push(span(style, cur));
97
- cur = ch;
98
- style = s;
99
- }
100
- }
101
- if (cur !== null) spans.push(span(style, cur));
102
- return spans;
103
- }
104
-
105
- /** One centred welcome-art row: the gold wordmark on the left, and (when a
106
- * two-tone mark returns) the tinted right half. */
107
- function artRow(ctx, row, parts, leftPad) {
108
- const t = themeOf(ctx);
109
- const left = row[0] || '';
110
- const right = row[1] || '';
111
- const spans = [span('', ' '.repeat(leftPad))];
112
- if (left && right) {
113
- spans.push(span(t.gold, left));
114
- spans.push(span('', ' '.repeat(parts.gutter)));
115
- spans.push(...tintWhale(right, t));
116
- } else if (left) {
117
- spans.push(span(t.gold, left));
118
- if (w(left) < parts.width) spans.push(span('', ' '.repeat(parts.width - w(left))));
119
- } else if (right) {
120
- spans.push(...tintWhale(right, t));
121
- if (w(right) < parts.width) spans.push(span('', ' '.repeat(parts.width - w(right))));
122
- } else {
123
- spans.push(span('', ' '.repeat(parts.width)));
124
- }
125
- return spansToString(spans);
126
- }
127
-
128
- /**
129
- * The start-up banner: a gold `━`+`─` rule across the full terminal, the
130
- * centred welcome mark (the ÆGIS wordmark, in gold — the same mark and the same
131
- * ink the desktop app draws), the coral-bold welcome title and a version line,
132
- * then the compact identity block.
133
- */
134
- function renderBanner(ctx, info = {}) {
135
- const t = themeOf(ctx);
136
- const width = Math.max(20, Number(info.width) || 80);
137
- const lines = [];
138
-
139
- // Full-width gold header rule — the heavy/light pair from the shared glyph
140
- // table, so the frame is `━───━` on a Unicode terminal and `=---=` on a
141
- // legacy console instead of printing two box-drawing runes it cannot draw.
142
- lines.push(
143
- `${t.gold}${GLYPH.ruleHeavy}${GLYPH.rule.repeat(Math.max(0, width - 2))}${GLYPH.ruleHeavy}${RESET}`
144
- );
145
- lines.push('');
146
-
147
- const parts = welcomeArtParts();
148
- if (width >= parts.width + 2) {
149
- const leftPad = Math.max(0, Math.floor((width - parts.width) / 2));
150
- for (const row of parts.rows) lines.push(artRow(ctx, row, parts, leftPad));
151
- } else {
152
- // Too narrow for the mark: a compact gold wordmark keeps every row in width.
153
- lines.push(centerStyled('AEGIS CODE', width, t.gold + BOLD));
154
- }
155
- lines.push('');
156
-
157
- const title = info.firstRun === false ? WELCOME_BACK : WELCOME_TITLE;
158
- lines.push(centerStyled(title, width, t.coral + BOLD));
159
- const verLine = [info.version ? `v${info.version}` : null, TAGLINE].filter(Boolean).join(` ${GLYPH.bullet} `);
160
- lines.push(centerStyled(verLine, width, t.gray));
161
- lines.push('');
162
-
163
- lines.push(...renderIdentityBox(ctx, info, width));
164
- return lines;
165
- }
166
-
167
- /** The identity panel: what you are talking to, and as what. Routed through
168
- * renderHeading so it shares the CLI's ruled-section look (no rounded frame). */
169
- function renderIdentityBox(ctx, info = {}, width = 80) {
170
- const t = themeOf(ctx);
171
- const lines = [renderHeading(ctx, 'aegiscode', width)];
172
-
173
- const rows = [
174
- ['version', info.version ? `v${info.version}` : null],
175
- ['model', info.model || 'server default'],
176
- ['base', info.base || ''],
177
- ['key', info.key || 'not set'],
178
- ['render', info.stream === false ? 'buffered' : 'streaming'],
179
- ].filter(([, v]) => v);
180
-
181
- for (const [k, v] of rows) {
182
- const value = clip(String(v), Math.max(0, width - 12));
183
- lines.push(` ${t.gray}${k.padEnd(8)}${RESET}${t.white}${value}${RESET}`);
184
- }
185
- const hint = clip(` type /help for commands ${GLYPH.bullet} /quit to exit`, width);
186
- lines.push('');
187
- lines.push(`${t.dim}${hint}${RESET}`);
188
- return lines;
189
- }
190
-
191
- /** Markdown-lite body (fallback when ./markdown.js is unavailable): fenced
192
- * code, bullets, headings, inline code/bold. */
193
- function mdLines(text, width, ctx) {
194
- const t = themeOf(ctx);
195
- const out = [];
196
- let inFence = false;
197
- const bodyW = Math.max(20, width - 4);
198
-
199
- for (const raw of String(text == null ? '' : text).split('\n')) {
200
- const fence = /^\s*```/.test(raw);
201
- if (fence) {
202
- inFence = !inFence;
203
- continue;
204
- }
205
- if (inFence) {
206
- for (const l of wrapBlock(raw, bodyW)) out.push(`${t.gray} ${l}${RESET}`);
207
- continue;
208
- }
209
- if (raw.trim() === '') {
210
- out.push('');
211
- continue;
212
- }
213
- const bullet = /^(\s*)[-*]\s+(.*)$/.exec(raw);
214
- if (bullet) {
215
- const indent = ' '.repeat(Math.min(6, bullet[1].length));
216
- for (const l of wrapBlock(inline(bullet[2], ctx), bodyW - 2)) {
217
- out.push(`${indent}${t.gray}${GLYPH.bullet}${RESET} ${l}`);
218
- }
219
- continue;
220
- }
221
- const heading = /^(#{1,6})\s+(.*)$/.exec(raw);
222
- if (heading) {
223
- out.push(`${t.gold}${BOLD}${inline(heading[2], ctx)}${RESET}`);
224
- continue;
225
- }
226
- for (const l of wrapBlock(inline(raw, ctx), bodyW, '')) out.push(l);
227
- }
228
- return out;
229
- }
230
-
231
- /** Inline span treatment: `code` in green, **bold** in bold. */
232
- function inline(text, ctx) {
233
- const t = themeOf(ctx);
234
- return String(text == null ? '' : text)
235
- .replace(/`([^`]+)`/g, (_, code) => `${t.green}${code}${RESET}`)
236
- .replace(/\*\*([^*]+)\*\*/g, (_, bold) => `${BOLD}${bold}${RESET}`);
237
- }
238
-
239
- /** Assistant body: ./markdown.js span lines flattened to ANSI strings, else the
240
- * plain mdLines fallback. */
241
- function assistantLines(ctx, text, width) {
242
- if (markdown && typeof markdown.renderMarkdown === 'function') {
243
- return markdown.renderMarkdown(String(text == null ? '' : text), width, ctx).map(spansToString);
244
- }
245
- return mdLines(text, width, ctx);
246
- }
247
-
248
- /**
249
- * One transcript turn: a `❯`-prefixed user line, an assistant answer whose
250
- * first line carries the `●` marker (and, on a multi-line streaming answer, a
251
- * `●` cursor on its last line), a tool line with its `⎿ $ …` hook row, and
252
- * each turn's accounting line beneath.
253
- */
254
- function renderTurn(ctx, turn, width = 80) {
255
- const t = themeOf(ctx);
256
- const role = turn.role || 'assistant';
257
- const text = String(turn.text == null ? '' : turn.text);
258
- const lines = [];
259
-
260
- if (role === 'user') {
261
- const body = wrapBlock(text, Math.max(8, width - 2));
262
- body.forEach((l, i) => {
263
- if (i === 0) lines.push(`${t.gray}${GLYPH.cursor}${RESET} ${t.white}${l}${RESET}`);
264
- else lines.push(` ${t.white}${l}${RESET}`);
265
- });
266
- } else if (role === 'assistant' || role === 'system') {
267
- const body = assistantLines(ctx, text, Math.max(8, width - 2));
268
- if (!body.length) body.push('');
269
- body[0] = `${t.white}${GLYPH.block}${RESET} ` + body[0];
270
- // No trailing cursor, deliberately — the twin of the rule in chatflow.js's
271
- // `rowLines`. Appending one to the last line only when the message ran past
272
- // one row made the glyph count depend on the text's WRAP (`● Working` at one
273
- // line, `● Working●` at two), so the extra dot appeared on exactly the long
274
- // answers a reader is likeliest to look at. The head marker is the answer's
275
- // gutter, not half of a bracket, and it is the same glyph the finished row
276
- // keeps — the live turn is the working line's job to advertise.
277
- lines.push(...body);
278
- } else if (role === 'tool') {
279
- // turn.ok is only known once the call has actually run (the agent loop's
280
- // tool-activity event fires after execution); undefined means "no result
281
- // yet to report" (the plain registry-tool path, which never set it).
282
- const status = turn.ok === undefined ? '' : turn.ok ? ` ${t.green}${GLYPH.check}${RESET}` : ` ${t.red}${errMark()}${RESET}`;
283
- // A tool row is a running command, not a bullet in a list — it carries no
284
- // leading `●` mark. Only the assistant's answer keeps that marker (see the
285
- // role branch above), so the two row kinds no longer look interchangeable.
286
- lines.push(`${t.gray}${turn.label || 'tool'}${RESET}${status}`);
287
- const args =
288
- turn.args == null
289
- ? ''
290
- : typeof turn.args === 'string'
291
- ? turn.args
292
- : JSON.stringify(turn.args);
293
- // An editFile/writeFile turn carries a diff preview (app.js builds it from
294
- // the tool call's `run` frame). Paint the colored block instead of the gray
295
- // `$ {args}` row, so an edit shows *what* changed, not just that something
296
- // did. The summary row is unconditional; the body follows when the block is
297
- // open, which the click handler toggles. The `$ args` row stays the fallback
298
- // for every non-edit tool and for a turn with no preview.
299
- if (turn.diff) {
300
- lines.push(...renderDiffBlock(turn.diff, ctx, width, { open: !!turn.diffOpen }));
301
- } else if (args) {
302
- lines.push(` ${t.gray}${GLYPH.hook} $ ${clip(args, Math.max(0, width - 6))}${RESET}`);
303
- }
304
- } else if (role === 'error') {
305
- lines.push(`${t.red}${errMark()} ${text}${RESET}`);
306
- } else {
307
- for (const l of wrapBlock(text, Math.max(8, width - 2))) lines.push(`${t.white}${l}${RESET}`);
308
- }
309
-
310
- if (turn.meta) {
311
- const m = renderMeta(ctx, turn.meta, width);
312
- if (m) lines.push(m);
313
- }
314
- return lines;
315
- }
316
-
317
- /**
318
- * The per-turn accounting line — what the turn produced beside what it cost, in
319
- * the `⎿` hook row style, e.g. `⎿ 312 out · €0.0007 · 4.2s`. The figure is
320
- * labelled and is the OUTPUT half alone (see `fmtUsageSplit`).
321
- */
322
- function renderMeta(ctx, meta = {}, width = 80) {
323
- const t = themeOf(ctx);
324
- const bits = [];
325
- if (meta.model) bits.push(`${t.blue}${meta.model}${RESET}`);
326
- // The producer (chatflow.js's accounting row) pushes the pair flat, as
327
- // `input`/`output` — reading it as `meta.usage.input` here meant the pair was
328
- // never printed on this path even though the docstring above promises it.
329
- // Both shapes are accepted: `usage` is what the desktop's renderer hands over.
330
- const split = meta.usage && typeof meta.usage === 'object' ? meta.usage : meta;
331
- // The row's token figure is what the turn PRODUCED, and it is the only one it
332
- // prints: labelled `tokens`, in this theme's strongest token — the figure the row
333
- // exists to report. The input half is gone deliberately, not by omission. It
334
- // is the prompt restated, on a cached turn it is the larger number by an order
335
- // of magnitude, and it is the one figure in the row nobody can act on: you
336
- // change what a turn costs by changing what it PRODUCES. Leading with it made
337
- // the row read as a runaway (`156,189 tok · 151,175 in · 5,014 tokens`) while
338
- // saying nothing about the answer. Its one remaining reader is `/cost`, which
339
- // carries the full miss/hit breakdown — a panel you open, not a line painted
340
- // under every answer.
341
- //
342
- // This is the twin of chatflow.js's accounting row (see `metaBits`): the two
343
- // render the same row through different plumbing, so they state the same
344
- // figure. The total does NOT stand in when no output figure arrived: `tokens`
345
- // is input + output, so the fallback that used to sit here printed a turn's
346
- // prompt back at it under an unlabelled figure — the exact reading this row
347
- // exists to remove, and the one the desktop already refuses in
348
- // `displayTokens` (desktop/renderer/usage.js). An unmeasurable output leaves
349
- // the figure off rather than stating a total, and `0 tokens` is refused for the
350
- // reason `fmtRoll` refuses `0 tokens`: it states a figure the provider never
351
- // reported.
352
- const parts = fmtUsageSplit(split);
353
- if (parts) bits.push(`${t.white}${parts.output}${RESET}`);
354
- else {
355
- const produced = displayTokens(split);
356
- if (produced != null) bits.push(`${t.white}${fmtTokens(produced)} tokens${RESET}`);
357
- }
358
- // No money on a tier AEGIS bills no fee to, and none from a snapshot that has
359
- // not proven a fee is owed — the desktop's rule, and now this host's too
360
- // (`feeBillable`). The token figure above stays either way: what the turn
361
- // produced is not a price, and hiding it would leave an Unlimited account with
362
- // no meter at all.
363
- if (meta.eur != null && feeBillable()) bits.push(`${meta.eur > 0 ? t.coral : t.green}${fmtEur(meta.eur)}${RESET}`);
364
- if (meta.ms != null) bits.push(`${t.gray}${fmtElapsed(meta.ms)}${RESET}`);
365
- if (meta.calls > 1) bits.push(`${t.gray}${meta.calls} calls${RESET}`);
366
- if (!bits.length) return '';
367
- const sep = `${t.dim} ${GLYPH.bullet} ${RESET}`;
368
- return `${t.dim}${GLYPH.hook} ${RESET}${bits.join(sep)}`;
369
- }
370
-
371
- /**
372
- * The bottom bar: segments packed left, the hint right-aligned, always exactly
373
- * `width` cells (clipped, never wrapped, so a narrow terminal degrades instead
374
- * of corrupting the transcript). No background — the CLI stays pipeable.
375
- */
376
- function renderStatus(ctx, state = {}, width = 80) {
377
- const t = themeOf(ctx);
378
- const left = ['aegis'];
379
- if (state.model) left.push(state.model);
380
- if (state.tokens != null) left.push(`${fmtTokens(state.tokens)} tokens`);
381
- if (state.spend != null) left.push(fmtEur(state.spend));
382
- if (state.mode) left.push(state.mode);
383
-
384
- const right = state.hint || 'ctrl+c quit';
385
- const body = ` ${left.join(` ${GLYPH.bullet} `)} `;
386
- const gap = width - w(body) - w(right) - 1;
387
- const content = gap > 0 ? body + ' '.repeat(gap) + right + ' ' : clip(body, width);
388
- return `${t.gray}${pad(content, width)}${RESET}`;
389
- }
390
-
391
- /**
392
- * The working line (drawn in the live region, then replaced by the turn):
393
- * the `✻`-family spinner cycling with a VERBS entry. With `state.done`, the
394
- * completion line `✻ <DoneVerb> for Ns` in gray (Churned after a chat turn,
395
- * Worked after a turn that used tools).
396
- */
397
- function renderWorking(ctx, state = {}) {
398
- const t = themeOf(ctx);
399
- if (state.done) {
400
- const verb = state.verb || DONE_VERBS[state.tools ? 1 : 0] || DONE_VERBS[0];
401
- const secs =
402
- state.secs != null ? state.secs : Math.max(1, Math.round((state.elapsedMs || 0) / 1000));
403
- return `${t.gray}${GLYPH.bloom} ${verb} for ${secs}s${RESET}`;
404
- }
405
- const frame = GLYPH.spin[Math.abs(Math.floor(state.tick || 0)) % GLYPH.spin.length];
406
- const verb = state.verb || VERBS[0];
407
- const tail = [];
408
- if (state.elapsedMs != null) tail.push(fmtElapsed(state.elapsedMs));
409
- // `streamedFloor` marks a figure that has folded in Anthropic's own
410
- // `thinking_delta.estimated_tokens` (desktop/lib/local/claude-pro.js) — a
411
- // running count that measurement showed landing under the real billed
412
- // thinking-token total (1900 vs 1943, 1800 vs 1832, 250 vs 339). Flagged
413
- // with `≥` rather than shown as an exact figure, because the true number
414
- // only arrives with the turn's final `usage`.
415
- if (state.streamed != null) {
416
- tail.push(`↓${state.streamedFloor ? '≥' : ''}${fmtTokens(state.streamed)} tokens`);
417
- }
418
- const tailStr = tail.length ? ` ${t.gray}(${tail.join(` ${GLYPH.bullet} `)})${RESET}` : '';
419
- return (
420
- `${t.coral}${frame}${RESET} ${t.white}${verb}${RESET}${t.white}…${RESET}${tailStr}` +
421
- `${t.dim} esc to interrupt${RESET}`
422
- );
423
- }
424
-
425
- /** A ruled section header used by command output (`/help`, `/cost`). */
426
- function renderHeading(ctx, text, width = 80) {
427
- const t = themeOf(ctx);
428
- const label = ` ${text} `;
429
- const fill = Math.max(0, width - w(label));
430
- const left = Math.floor(fill / 2);
431
- const rule = GLYPH.rule;
432
- return (
433
- `${t.gray}${rule.repeat(left)}${RESET}${t.gold}${BOLD}${label}${RESET}` +
434
- `${t.gray}${rule.repeat(Math.max(0, fill - left))}${RESET}`
435
- );
436
- }
437
-
438
- /** Render a tool result body: heading + indented lines, no role gutter. */
439
- function renderToolResult(ctx, name, text, width = 80) {
440
- const t = themeOf(ctx);
441
- const lines = [renderHeading(ctx, name, width)];
442
- for (const l of wrapBlock(String(text == null ? '' : text), Math.max(8, width - 2))) {
443
- lines.push(l ? ` ${t.white}${l}${RESET}` : '');
444
- }
445
- return lines;
446
- }
447
-
448
- /**
449
- * The tool-approval card: the mutating call the model wants to run (a diff
450
- * for writeFile/editFile, the command for exec) and the three answers. One
451
- * inline question, matching the upstream engine's Bash/edit approval dialog.
452
- */
453
- function renderApproval(ctx, info = {}, width = 80) {
454
- const t = themeOf(ctx);
455
- const lines = [renderHeading(ctx, `confirm ${info.tool || 'tool'}`, width)];
456
- const body = info.diff
457
- ? info.diff
458
- : info.args == null
459
- ? ''
460
- : typeof info.args === 'string'
461
- ? info.args
462
- : JSON.stringify(info.args);
463
- for (const l of wrapBlock(body, Math.max(8, width - 2))) {
464
- lines.push(l ? ` ${t.gray}${l}${RESET}` : '');
465
- }
466
- lines.push('');
467
- lines.push(
468
- ` ${t.coral}${GLYPH.bullet}${RESET} ${t.white}y${RESET}es once` +
469
- ` ${t.dim}${GLYPH.bullet}${RESET} ${t.white}s${RESET}ession` +
470
- ` ${t.dim}${GLYPH.bullet}${RESET} ${t.white}n${RESET}o ${t.dim}(default)${RESET}`
471
- );
472
- return lines;
473
- }
474
-
475
- /** A transient notice. Kinds map gray / coral / red / green with the matching
476
- * glyph: info `·`, warn `⚠`, error `✗`, ok `✔` — all four read from the shared
477
- * table at call time, so `--ascii` swaps them along with the rest of the UI. */
478
- const NOTICE = {
479
- info: ['gray', () => GLYPH.bullet],
480
- warn: ['coral', warnMark],
481
- error: ['red', errMark],
482
- ok: ['green', () => GLYPH.check],
483
- };
484
-
485
- function renderNotice(ctx, kind, text) {
486
- const t = themeOf(ctx);
487
- const [token, mark] = NOTICE[kind] || NOTICE.info;
488
- return `${t[token]}${mark()} ${text}${RESET}`;
489
- }
490
-
491
- module.exports = {
492
- renderBanner,
493
- renderIdentityBox,
494
- renderTurn,
495
- renderMeta,
496
- renderStatus,
497
- renderWorking,
498
- renderHeading,
499
- renderToolResult,
500
- renderApproval,
501
- renderNotice,
502
- mdLines,
503
- inline,
504
- // Welcome-mark pieces, shared with the onboarding screens so there is exactly
505
- // one renderer for the mascot/moon/whale mark rather than two that can drift.
506
- artRow,
507
- tintWhale,
508
- // Style helpers kept for legacy consumers.
509
- fg,
510
- bg,
511
- UNDER,
512
- ITALIC,
513
- RESET_FG,
514
- RESET_BG,
515
- pad,
516
- padStart,
517
- };
3
+ "use strict";const{RGB:RGB,BG:BG,RESET:RESET,BOLD:BOLD,DIM:DIM,ITALIC:ITALIC,UNDER:UNDER,RESET_FG:RESET_FG,RESET_BG:RESET_BG,GLYPH:GLYPH,VERBS:VERBS,DONE_VERBS:DONE_VERBS,themeOf:themeOf}=require("./theme.js"),{WELCOME_TITLE:WELCOME_TITLE,WELCOME_BACK:WELCOME_BACK,TAGLINE:TAGLINE,STAR:STAR,stencilGlyph:stencilGlyph,welcomeArtParts:welcomeArtParts}=require("./art.js"),{w:w,pad:pad,padStart:padStart,wrapBlock:wrapBlock,clip:clip,span:span}=require("./screen.js"),{fmtTokens:fmtTokens,fmtEur:fmtEur,fmtElapsed:fmtElapsed,fmtUsageSplit:fmtUsageSplit,displayTokens:displayTokens,feeBillable:feeBillable}=require("./format.js"),{renderDiffBlock:renderDiffBlock}=require("./diffview.js");let markdown=null;try{markdown=require("./markdown.js")}catch{markdown=null}const errMark=()=>GLYPH.err,warnMark=()=>GLYPH.warn,fg=(e,t)=>`${t}`,bg=e=>BG(...e),spansToString=e=>e.map((e=>(e.s||"")+e.t)).join("")+RESET;function centerStyled(e,t,r){const n=clip(e,t),s=Math.max(0,Math.floor((t-w(n))/2));return" ".repeat(s)+r+n+RESET}function tintWhale(e,t){const r={"▓":t.blue,"▒":t.lavender,"░":t.dim,"█":t.white,[STAR]:t.gold,"·":t.dim},n={};for(const e of Object.keys(r))n[stencilGlyph(e)]=r[e];const s=[];let o=null,a="";for(const t of e){const e=null!=n[t]?n[t]:"";null!==o&&e===a?o+=t:(null!==o&&s.push(span(a,o)),o=t,a=e)}return null!==o&&s.push(span(a,o)),s}function artRow(e,t,r,n){const s=themeOf(e),o=t[0]||"",a=t[1]||"",l=[span(""," ".repeat(n))];return o&&a?(l.push(span(s.gold,o)),l.push(span(""," ".repeat(r.gutter))),l.push(...tintWhale(a,s))):o?(l.push(span(s.gold,o)),w(o)<r.width&&l.push(span(""," ".repeat(r.width-w(o))))):a?(l.push(...tintWhale(a,s)),w(a)<r.width&&l.push(span(""," ".repeat(r.width-w(a))))):l.push(span(""," ".repeat(r.width))),spansToString(l)}function renderBanner(e,t={}){const r=themeOf(e),n=Math.max(20,Number(t.width)||80),s=[];s.push(`${r.gold}${GLYPH.ruleHeavy}${GLYPH.rule.repeat(Math.max(0,n-2))}${GLYPH.ruleHeavy}${RESET}`),s.push("");const o=welcomeArtParts();if(n>=o.width+2){const t=Math.max(0,Math.floor((n-o.width)/2));for(const r of o.rows)s.push(artRow(e,r,o,t))}else s.push(centerStyled("AEGIS CODE",n,r.gold+BOLD));s.push("");const a=!1===t.firstRun?WELCOME_BACK:WELCOME_TITLE;s.push(centerStyled(a,n,r.coral+BOLD));const l=[t.version?`v${t.version}`:null,TAGLINE].filter(Boolean).join(` ${GLYPH.bullet} `);return s.push(centerStyled(l,n,r.gray)),s.push(""),s.push(...renderIdentityBox(e,t,n)),s}function renderIdentityBox(e,t={},r=80){const n=themeOf(e),s=[renderHeading(e,"aegiscode",r)],o=[["version",t.version?`v${t.version}`:null],["model",t.model||"server default"],["base",t.base||""],["key",t.key||"not set"],["render",!1===t.stream?"buffered":"streaming"]].filter((([,e])=>e));for(const[e,t]of o){const o=clip(String(t),Math.max(0,r-12));s.push(` ${n.gray}${e.padEnd(8)}${RESET}${n.white}${o}${RESET}`)}const a=clip(` type /help for commands ${GLYPH.bullet} /quit to exit`,r);return s.push(""),s.push(`${n.dim}${a}${RESET}`),s}function mdLines(e,t,r){const n=themeOf(r),s=[];let o=!1;const a=Math.max(20,t-4);for(const t of String(null==e?"":e).split("\n")){if(/^\s*```/.test(t)){o=!o;continue}if(o){for(const e of wrapBlock(t,a))s.push(`${n.gray} ${e}${RESET}`);continue}if(""===t.trim()){s.push("");continue}const e=/^(\s*)[-*]\s+(.*)$/.exec(t);if(e){const t=" ".repeat(Math.min(6,e[1].length));for(const o of wrapBlock(inline(e[2],r),a-2))s.push(`${t}${n.gray}${GLYPH.bullet}${RESET} ${o}`);continue}const l=/^(#{1,6})\s+(.*)$/.exec(t);if(l)s.push(`${n.gold}${BOLD}${inline(l[2],r)}${RESET}`);else for(const e of wrapBlock(inline(t,r),a,""))s.push(e)}return s}function inline(e,t){const r=themeOf(t);return String(null==e?"":e).replace(/`([^`]+)`/g,((e,t)=>`${r.green}${t}${RESET}`)).replace(/\*\*([^*]+)\*\*/g,((e,t)=>`${BOLD}${t}${RESET}`))}function assistantLines(e,t,r){return markdown&&"function"==typeof markdown.renderMarkdown?markdown.renderMarkdown(String(null==t?"":t),r,e).map(spansToString):mdLines(t,r,e)}function renderTurn(e,t,r=80){const n=themeOf(e),s=t.role||"assistant",o=String(null==t.text?"":t.text),a=[];if("user"===s)wrapBlock(o,Math.max(8,r-2)).forEach(((e,t)=>{0===t?a.push(`${n.gray}${GLYPH.cursor}${RESET} ${n.white}${e}${RESET}`):a.push(` ${n.white}${e}${RESET}`)}));else if("assistant"===s||"system"===s){const t=assistantLines(e,o,Math.max(8,r-2));t.length||t.push(""),t[0]=`${n.white}${GLYPH.block}${RESET} `+t[0],a.push(...t)}else if("tool"===s){const s=void 0===t.ok?"":t.ok?` ${n.green}${GLYPH.check}${RESET}`:` ${n.red}${errMark()}${RESET}`;a.push(`${n.gray}${t.label||"tool"}${RESET}${s}`);const o=null==t.args?"":"string"==typeof t.args?t.args:JSON.stringify(t.args);t.diff?a.push(...renderDiffBlock(t.diff,e,r,{open:!!t.diffOpen})):o&&a.push(` ${n.gray}${GLYPH.hook} $ ${clip(o,Math.max(0,r-6))}${RESET}`)}else if("error"===s)a.push(`${n.red}${errMark()} ${o}${RESET}`);else for(const e of wrapBlock(o,Math.max(8,r-2)))a.push(`${n.white}${e}${RESET}`);if(t.meta){const n=renderMeta(e,t.meta,r);n&&a.push(n)}return a}function renderMeta(e,t={},r=80){const n=themeOf(e),s=[];t.model&&s.push(`${n.blue}${t.model}${RESET}`);const o=t.usage&&"object"==typeof t.usage?t.usage:t,a=fmtUsageSplit(o);if(a)s.push(`${n.white}${a.output}${RESET}`);else{const e=displayTokens(o);null!=e&&s.push(`${n.white}${fmtTokens(e)} tokens${RESET}`)}if(null!=t.eur&&feeBillable()&&s.push(`${t.eur>0?n.coral:n.green}${fmtEur(t.eur)}${RESET}`),null!=t.ms&&s.push(`${n.gray}${fmtElapsed(t.ms)}${RESET}`),t.calls>1&&s.push(`${n.gray}${t.calls} calls${RESET}`),!s.length)return"";const l=`${n.dim} ${GLYPH.bullet} ${RESET}`;return`${n.dim}${GLYPH.hook} ${RESET}${s.join(l)}`}function renderStatus(e,t={},r=80){const n=themeOf(e),s=["aegis"];t.model&&s.push(t.model),null!=t.tokens&&s.push(`${fmtTokens(t.tokens)} tokens`),null!=t.spend&&s.push(fmtEur(t.spend)),t.mode&&s.push(t.mode);const o=t.hint||"ctrl+c quit",a=` ${s.join(` ${GLYPH.bullet} `)} `,l=r-w(a)-w(o)-1,i=l>0?a+" ".repeat(l)+o+" ":clip(a,r);return`${n.gray}${pad(i,r)}${RESET}`}function renderWorking(e,t={}){const r=themeOf(e);if(t.done){const e=t.verb||DONE_VERBS[t.tools?1:0]||DONE_VERBS[0],n=null!=t.secs?t.secs:Math.max(1,Math.round((t.elapsedMs||0)/1e3));return`${r.gray}${GLYPH.bloom} ${e} for ${n}s${RESET}`}const n=GLYPH.spin[Math.abs(Math.floor(t.tick||0))%GLYPH.spin.length],s=t.verb||VERBS[0],o=[];null!=t.elapsedMs&&o.push(fmtElapsed(t.elapsedMs)),null!=t.streamed&&o.push(`↓${t.streamedFloor?"≥":""}${fmtTokens(t.streamed)} tokens`);const a=o.length?` ${r.gray}(${o.join(` ${GLYPH.bullet} `)})${RESET}`:"";return`${r.coral}${n}${RESET} ${r.white}${s}${RESET}${r.white}…${RESET}${a}${r.dim} esc to interrupt${RESET}`}function renderHeading(e,t,r=80){const n=themeOf(e),s=` ${t} `,o=Math.max(0,r-w(s)),a=Math.floor(o/2),l=GLYPH.rule;return`${n.gray}${l.repeat(a)}${RESET}${n.gold}${BOLD}${s}${RESET}${n.gray}${l.repeat(Math.max(0,o-a))}${RESET}`}function renderToolResult(e,t,r,n=80){const s=themeOf(e),o=[renderHeading(e,t,n)];for(const e of wrapBlock(String(null==r?"":r),Math.max(8,n-2)))o.push(e?` ${s.white}${e}${RESET}`:"");return o}function renderApproval(e,t={},r=80){const n=themeOf(e),s=[renderHeading(e,`confirm ${t.tool||"tool"}`,r)],o=t.diff?t.diff:null==t.args?"":"string"==typeof t.args?t.args:JSON.stringify(t.args);for(const e of wrapBlock(o,Math.max(8,r-2)))s.push(e?` ${n.gray}${e}${RESET}`:"");return s.push(""),s.push(` ${n.coral}${GLYPH.bullet}${RESET} ${n.white}y${RESET}es once ${n.dim}${GLYPH.bullet}${RESET} ${n.white}s${RESET}ession ${n.dim}${GLYPH.bullet}${RESET} ${n.white}n${RESET}o ${n.dim}(default)${RESET}`),s}const NOTICE={info:["gray",()=>GLYPH.bullet],warn:["coral",warnMark],error:["red",errMark],ok:["green",()=>GLYPH.check]};function renderNotice(e,t,r){const n=themeOf(e),[s,o]=NOTICE[t]||NOTICE.info;return`${n[s]}${o()} ${r}${RESET}`}module.exports={renderBanner:renderBanner,renderIdentityBox:renderIdentityBox,renderTurn:renderTurn,renderMeta:renderMeta,renderStatus:renderStatus,renderWorking:renderWorking,renderHeading:renderHeading,renderToolResult:renderToolResult,renderApproval:renderApproval,renderNotice:renderNotice,mdLines:mdLines,inline:inline,artRow:artRow,tintWhale:tintWhale,fg:fg,bg:bg,UNDER:UNDER,ITALIC:ITALIC,RESET_FG:RESET_FG,RESET_BG:RESET_BG,pad:pad,padStart:padStart};