aegiscode 7.0.24 → 7.0.26

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 (113) hide show
  1. package/package.json +7 -3
  2. package/scripts/check.mjs +52 -1
  3. package/scripts/demo.mjs +94 -1
  4. package/scripts/predist.mjs +75 -1
  5. package/scripts/runtests.mjs +56 -1
  6. package/scripts/seal-gate.mjs +74 -1
  7. package/src/agents.js +139 -1
  8. package/src/app.js +2957 -1
  9. package/src/art.js +289 -1
  10. package/src/chatflow.js +3023 -1
  11. package/src/checkpoint.js +90 -1
  12. package/src/clipboard.js +424 -1
  13. package/src/cloudsync.js +528 -1
  14. package/src/commands.js +4089 -1
  15. package/src/config.js +581 -1
  16. package/src/connect.js +349 -1
  17. package/src/credentials.js +33 -1
  18. package/src/deps.js +232 -1
  19. package/src/devrun.js +187 -1
  20. package/src/diff.js +333 -1
  21. package/src/diffview.js +296 -1
  22. package/src/engine.js +297 -1
  23. package/src/entitlement.js +355 -1
  24. package/src/events.js +707 -1
  25. package/src/export.js +67 -1
  26. package/src/filepreview.js +153 -1
  27. package/src/fingerprint.js +592 -1
  28. package/src/format.js +259 -1
  29. package/src/fuzzy.js +119 -1
  30. package/src/history.js +423 -1
  31. package/src/init.js +175 -1
  32. package/src/input.js +139 -1
  33. package/src/keys.js +183 -1
  34. package/src/markdown.js +306 -1
  35. package/src/models.js +507 -1
  36. package/src/naming.js +57 -1
  37. package/src/overlays.js +462 -1
  38. package/src/panels.js +1418 -1
  39. package/src/ping.js +226 -1
  40. package/src/presence.js +238 -1
  41. package/src/render.js +516 -1
  42. package/src/screen.js +518 -1
  43. package/src/screens.js +896 -1
  44. package/src/secret.js +59 -1
  45. package/src/securefs.js +359 -1
  46. package/src/settings.js +155 -1
  47. package/src/shared.js +52 -1
  48. package/src/sharedpaths.js +53 -1
  49. package/src/signup.js +156 -1
  50. package/src/summarize.js +95 -1
  51. package/src/sysdiag.js +585 -1
  52. package/src/system.js +40 -1
  53. package/src/theme.js +570 -1
  54. package/src/title.js +220 -1
  55. package/src/todos.js +115 -1
  56. package/src/tokens.js +263 -1
  57. package/src/topup.js +210 -1
  58. package/src/update.js +191 -1
  59. package/vendor/client/aegis.js +2441 -1
  60. package/vendor/client/attest.js +518 -1
  61. package/vendor/client/authorship-key.js +410 -1
  62. package/vendor/client/auto-provision.js +134 -1
  63. package/vendor/client/brain-catalog.js +268 -1
  64. package/vendor/client/byok-catalog.js +199 -1
  65. package/vendor/client/catalog-client.js +487 -1
  66. package/vendor/client/conversation-export.js +177 -1
  67. package/vendor/client/credentials.js +494 -1
  68. package/vendor/client/device-fingerprint.js +141 -1
  69. package/vendor/client/drive-connect.js +110 -1
  70. package/vendor/client/drive-upload.js +234 -1
  71. package/vendor/client/env-file.js +1273 -1
  72. package/vendor/client/fingerprint.js +1064 -1
  73. package/vendor/client/foreign-memory.js +669 -1
  74. package/vendor/client/google-signin.js +133 -1
  75. package/vendor/client/hooks.js +430 -1
  76. package/vendor/client/model-discovery.js +373 -1
  77. package/vendor/client/naming.js +283 -1
  78. package/vendor/client/platform.js +937 -1
  79. package/vendor/client/prefs.js +351 -1
  80. package/vendor/client/presence-constants.js +107 -1
  81. package/vendor/client/presence.js +438 -1
  82. package/vendor/client/record-vault.js +1055 -3
  83. package/vendor/client/session-store.js +575 -1
  84. package/vendor/client/topup.js +297 -1
  85. package/vendor/client/touch.js +458 -1
  86. package/vendor/client/update.js +763 -1
  87. package/vendor/client/user-models.js +381 -1
  88. package/vendor/desktop/lib/local/agents.js +105 -1
  89. package/vendor/desktop/lib/local/attachments.js +276 -1
  90. package/vendor/desktop/lib/local/autonomous.js +1045 -1
  91. package/vendor/desktop/lib/local/claude-pro.js +1028 -1
  92. package/vendor/desktop/lib/local/context.js +125 -1
  93. package/vendor/desktop/lib/local/engine.js +3666 -1
  94. package/vendor/desktop/lib/local/entitlement.js +660 -1
  95. package/vendor/desktop/lib/local/git-scope.js +228 -1
  96. package/vendor/desktop/lib/local/local.js +2145 -1
  97. package/vendor/desktop/lib/local/prompt.js +280 -1
  98. package/vendor/desktop/lib/local/queue.js +560 -1
  99. package/vendor/desktop/lib/local/session-rounds.js +238 -1
  100. package/vendor/desktop/lib/local/spill.js +75 -1
  101. package/vendor/desktop/lib/local/turn-guard.js +300 -1
  102. package/vendor/desktop/lib/local/worktree-lock.js +235 -1
  103. package/vendor/desktop/lib/settings.js +890 -1
  104. package/vendor/desktop/renderer/usage.js +1239 -1
  105. package/vendor/hosts/install.js +638 -1
  106. package/vendor/hosts/openai-shim.js +515 -1
  107. package/vendor/hosts/spec.js +164 -1
  108. package/vendor/hosts/targets.js +346 -1
  109. package/vendor/mcp/server.js +221 -1
  110. package/vendor/mcp/tools.js +408 -1
  111. package/vendor/one/src/child.js +285 -1
  112. package/vendor/one/src/permissions.js +383 -1
  113. package/SOURCE-OFFER.txt +0 -9
package/src/render.js CHANGED
@@ -1,3 +1,518 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
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"),{extractPreview:extractPreview,renderFilePreview:renderFilePreview,extractNewContent:extractNewContent}=require("./filepreview.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),l=t.label&&(t.label.includes("writeFile")||t.label.includes("Write"));if(l&&t.args){const n=extractNewContent(t.label.split(/\s+/)[1],t.args);if(n){const s=t.args.file_path||t.args.path,o=extractPreview(s,n);o&&a.push(...renderFilePreview(o,e,r))}}t.diff&&!l?a.push(...renderDiffBlock(t.diff,e,r,{open:!!t.diffOpen})):o&&!l&&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};
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
+
294
+ // An editFile/writeFile turn carries a diff preview (app.js builds it from
295
+ // the tool call's `run` frame). Paint the colored block instead of the gray
296
+ // `$ {args}` row, so an edit shows *what* changed, not just that something
297
+ // did. The summary row is unconditional; the body follows when the block is
298
+ // open, which the click handler toggles. The `$ args` row stays the fallback
299
+ // for every non-edit tool and for a turn with no preview.
300
+ if (turn.diff) {
301
+ lines.push(...renderDiffBlock(turn.diff, ctx, width, { open: !!turn.diffOpen }));
302
+ } else if (args) {
303
+ lines.push(` ${t.gray}${GLYPH.hook} $ ${clip(args, Math.max(0, width - 6))}${RESET}`);
304
+ }
305
+ } else if (role === 'error') {
306
+ lines.push(`${t.red}${errMark()} ${text}${RESET}`);
307
+ } else {
308
+ for (const l of wrapBlock(text, Math.max(8, width - 2))) lines.push(`${t.white}${l}${RESET}`);
309
+ }
310
+
311
+ if (turn.meta) {
312
+ const m = renderMeta(ctx, turn.meta, width);
313
+ if (m) lines.push(m);
314
+ }
315
+ return lines;
316
+ }
317
+
318
+ /**
319
+ * The per-turn accounting line — what the turn produced beside what it cost, in
320
+ * the `⎿` hook row style, e.g. `⎿ 312 out · €0.0007 · 4.2s`. The figure is
321
+ * labelled and is the OUTPUT half alone (see `fmtUsageSplit`).
322
+ */
323
+ function renderMeta(ctx, meta = {}, width = 80) {
324
+ const t = themeOf(ctx);
325
+ const bits = [];
326
+ if (meta.model) bits.push(`${t.blue}${meta.model}${RESET}`);
327
+ // The producer (chatflow.js's accounting row) pushes the pair flat, as
328
+ // `input`/`output` — reading it as `meta.usage.input` here meant the pair was
329
+ // never printed on this path even though the docstring above promises it.
330
+ // Both shapes are accepted: `usage` is what the desktop's renderer hands over.
331
+ const split = meta.usage && typeof meta.usage === 'object' ? meta.usage : meta;
332
+ // The row's token figure is what the turn PRODUCED, and it is the only one it
333
+ // prints: labelled `tokens`, in this theme's strongest token — the figure the row
334
+ // exists to report. The input half is gone deliberately, not by omission. It
335
+ // is the prompt restated, on a cached turn it is the larger number by an order
336
+ // of magnitude, and it is the one figure in the row nobody can act on: you
337
+ // change what a turn costs by changing what it PRODUCES. Leading with it made
338
+ // the row read as a runaway (`156,189 tok · 151,175 in · 5,014 tokens`) while
339
+ // saying nothing about the answer. Its one remaining reader is `/cost`, which
340
+ // carries the full miss/hit breakdown — a panel you open, not a line painted
341
+ // under every answer.
342
+ //
343
+ // This is the twin of chatflow.js's accounting row (see `metaBits`): the two
344
+ // render the same row through different plumbing, so they state the same
345
+ // figure. The total does NOT stand in when no output figure arrived: `tokens`
346
+ // is input + output, so the fallback that used to sit here printed a turn's
347
+ // prompt back at it under an unlabelled figure — the exact reading this row
348
+ // exists to remove, and the one the desktop already refuses in
349
+ // `displayTokens` (desktop/renderer/usage.js). An unmeasurable output leaves
350
+ // the figure off rather than stating a total, and `0 tokens` is refused for the
351
+ // reason `fmtRoll` refuses `0 tokens`: it states a figure the provider never
352
+ // reported.
353
+ const parts = fmtUsageSplit(split);
354
+ if (parts) bits.push(`${t.white}${parts.output}${RESET}`);
355
+ else {
356
+ const produced = displayTokens(split);
357
+ if (produced != null) bits.push(`${t.white}${fmtTokens(produced)} tokens${RESET}`);
358
+ }
359
+ // No money on a tier AEGIS bills no fee to, and none from a snapshot that has
360
+ // not proven a fee is owed — the desktop's rule, and now this host's too
361
+ // (`feeBillable`). The token figure above stays either way: what the turn
362
+ // produced is not a price, and hiding it would leave an Unlimited account with
363
+ // no meter at all.
364
+ if (meta.eur != null && feeBillable()) bits.push(`${meta.eur > 0 ? t.coral : t.green}${fmtEur(meta.eur)}${RESET}`);
365
+ if (meta.ms != null) bits.push(`${t.gray}${fmtElapsed(meta.ms)}${RESET}`);
366
+ if (meta.calls > 1) bits.push(`${t.gray}${meta.calls} calls${RESET}`);
367
+ if (!bits.length) return '';
368
+ const sep = `${t.dim} ${GLYPH.bullet} ${RESET}`;
369
+ return `${t.dim}${GLYPH.hook} ${RESET}${bits.join(sep)}`;
370
+ }
371
+
372
+ /**
373
+ * The bottom bar: segments packed left, the hint right-aligned, always exactly
374
+ * `width` cells (clipped, never wrapped, so a narrow terminal degrades instead
375
+ * of corrupting the transcript). No background — the CLI stays pipeable.
376
+ */
377
+ function renderStatus(ctx, state = {}, width = 80) {
378
+ const t = themeOf(ctx);
379
+ const left = ['aegis'];
380
+ if (state.model) left.push(state.model);
381
+ if (state.tokens != null) left.push(`${fmtTokens(state.tokens)} tokens`);
382
+ if (state.spend != null) left.push(fmtEur(state.spend));
383
+ if (state.mode) left.push(state.mode);
384
+
385
+ const right = state.hint || 'ctrl+c quit';
386
+ const body = ` ${left.join(` ${GLYPH.bullet} `)} `;
387
+ const gap = width - w(body) - w(right) - 1;
388
+ const content = gap > 0 ? body + ' '.repeat(gap) + right + ' ' : clip(body, width);
389
+ return `${t.gray}${pad(content, width)}${RESET}`;
390
+ }
391
+
392
+ /**
393
+ * The working line (drawn in the live region, then replaced by the turn):
394
+ * the `✻`-family spinner cycling with a VERBS entry. With `state.done`, the
395
+ * completion line `✻ <DoneVerb> for Ns` in gray (Churned after a chat turn,
396
+ * Worked after a turn that used tools).
397
+ */
398
+ function renderWorking(ctx, state = {}) {
399
+ const t = themeOf(ctx);
400
+ if (state.done) {
401
+ const verb = state.verb || DONE_VERBS[state.tools ? 1 : 0] || DONE_VERBS[0];
402
+ const secs =
403
+ state.secs != null ? state.secs : Math.max(1, Math.round((state.elapsedMs || 0) / 1000));
404
+ return `${t.gray}${GLYPH.bloom} ${verb} for ${secs}s${RESET}`;
405
+ }
406
+ const frame = GLYPH.spin[Math.abs(Math.floor(state.tick || 0)) % GLYPH.spin.length];
407
+ const verb = state.verb || VERBS[0];
408
+ const tail = [];
409
+ if (state.elapsedMs != null) tail.push(fmtElapsed(state.elapsedMs));
410
+ // `streamedFloor` marks a figure that has folded in Anthropic's own
411
+ // `thinking_delta.estimated_tokens` (desktop/lib/local/claude-pro.js) — a
412
+ // running count that measurement showed landing under the real billed
413
+ // thinking-token total (1900 vs 1943, 1800 vs 1832, 250 vs 339). Flagged
414
+ // with `≥` rather than shown as an exact figure, because the true number
415
+ // only arrives with the turn's final `usage`.
416
+ if (state.streamed != null) {
417
+ tail.push(`↓${state.streamedFloor ? '≥' : ''}${fmtTokens(state.streamed)} tokens`);
418
+ }
419
+ const tailStr = tail.length ? ` ${t.gray}(${tail.join(` ${GLYPH.bullet} `)})${RESET}` : '';
420
+ return (
421
+ `${t.coral}${frame}${RESET} ${t.white}${verb}${RESET}${t.white}…${RESET}${tailStr}` +
422
+ `${t.dim} esc to interrupt${RESET}`
423
+ );
424
+ }
425
+
426
+ /** A ruled section header used by command output (`/help`, `/cost`). */
427
+ function renderHeading(ctx, text, width = 80) {
428
+ const t = themeOf(ctx);
429
+ const label = ` ${text} `;
430
+ const fill = Math.max(0, width - w(label));
431
+ const left = Math.floor(fill / 2);
432
+ const rule = GLYPH.rule;
433
+ return (
434
+ `${t.gray}${rule.repeat(left)}${RESET}${t.gold}${BOLD}${label}${RESET}` +
435
+ `${t.gray}${rule.repeat(Math.max(0, fill - left))}${RESET}`
436
+ );
437
+ }
438
+
439
+ /** Render a tool result body: heading + indented lines, no role gutter. */
440
+ function renderToolResult(ctx, name, text, width = 80) {
441
+ const t = themeOf(ctx);
442
+ const lines = [renderHeading(ctx, name, width)];
443
+ for (const l of wrapBlock(String(text == null ? '' : text), Math.max(8, width - 2))) {
444
+ lines.push(l ? ` ${t.white}${l}${RESET}` : '');
445
+ }
446
+ return lines;
447
+ }
448
+
449
+ /**
450
+ * The tool-approval card: the mutating call the model wants to run (a diff
451
+ * for writeFile/editFile, the command for exec) and the three answers. One
452
+ * inline question, matching the upstream engine's Bash/edit approval dialog.
453
+ */
454
+ function renderApproval(ctx, info = {}, width = 80) {
455
+ const t = themeOf(ctx);
456
+ const lines = [renderHeading(ctx, `confirm ${info.tool || 'tool'}`, width)];
457
+ const body = info.diff
458
+ ? info.diff
459
+ : info.args == null
460
+ ? ''
461
+ : typeof info.args === 'string'
462
+ ? info.args
463
+ : JSON.stringify(info.args);
464
+ for (const l of wrapBlock(body, Math.max(8, width - 2))) {
465
+ lines.push(l ? ` ${t.gray}${l}${RESET}` : '');
466
+ }
467
+ lines.push('');
468
+ lines.push(
469
+ ` ${t.coral}${GLYPH.bullet}${RESET} ${t.white}y${RESET}es once` +
470
+ ` ${t.dim}${GLYPH.bullet}${RESET} ${t.white}s${RESET}ession` +
471
+ ` ${t.dim}${GLYPH.bullet}${RESET} ${t.white}n${RESET}o ${t.dim}(default)${RESET}`
472
+ );
473
+ return lines;
474
+ }
475
+
476
+ /** A transient notice. Kinds map gray / coral / red / green with the matching
477
+ * glyph: info `·`, warn `⚠`, error `✗`, ok `✔` — all four read from the shared
478
+ * table at call time, so `--ascii` swaps them along with the rest of the UI. */
479
+ const NOTICE = {
480
+ info: ['gray', () => GLYPH.bullet],
481
+ warn: ['coral', warnMark],
482
+ error: ['red', errMark],
483
+ ok: ['green', () => GLYPH.check],
484
+ };
485
+
486
+ function renderNotice(ctx, kind, text) {
487
+ const t = themeOf(ctx);
488
+ const [token, mark] = NOTICE[kind] || NOTICE.info;
489
+ return `${t[token]}${mark()} ${text}${RESET}`;
490
+ }
491
+
492
+ module.exports = {
493
+ renderBanner,
494
+ renderIdentityBox,
495
+ renderTurn,
496
+ renderMeta,
497
+ renderStatus,
498
+ renderWorking,
499
+ renderHeading,
500
+ renderToolResult,
501
+ renderApproval,
502
+ renderNotice,
503
+ mdLines,
504
+ inline,
505
+ // Welcome-mark pieces, shared with the onboarding screens so there is exactly
506
+ // one renderer for the mascot/moon/whale mark rather than two that can drift.
507
+ artRow,
508
+ tintWhale,
509
+ // Style helpers kept for legacy consumers.
510
+ fg,
511
+ bg,
512
+ UNDER,
513
+ ITALIC,
514
+ RESET_FG,
515
+ RESET_BG,
516
+ pad,
517
+ padStart,
518
+ };