aegisone 1.0.22 → 1.0.24

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 (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -939
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -369
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/bin/aegiscode.js +2 -914
  17. package/vendor/cli/package.json +3 -7
  18. package/vendor/cli/scripts/check.mjs +1 -52
  19. package/vendor/cli/scripts/demo.mjs +1 -94
  20. package/vendor/cli/scripts/predist.mjs +1 -75
  21. package/vendor/cli/scripts/runtests.mjs +1 -56
  22. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  23. package/vendor/cli/src/agents.js +1 -139
  24. package/vendor/cli/src/app.js +1 -2932
  25. package/vendor/cli/src/art.js +1 -289
  26. package/vendor/cli/src/autonomous.js +1 -515
  27. package/vendor/cli/src/caps.js +1 -879
  28. package/vendor/cli/src/chatflow.js +1 -3020
  29. package/vendor/cli/src/checkpoint.js +1 -90
  30. package/vendor/cli/src/clipboard.js +1 -424
  31. package/vendor/cli/src/cloudsync.js +1 -528
  32. package/vendor/cli/src/commands.js +1 -4003
  33. package/vendor/cli/src/config.js +1 -581
  34. package/vendor/cli/src/connect.js +1 -349
  35. package/vendor/cli/src/credentials.js +1 -33
  36. package/vendor/cli/src/deps.js +1 -232
  37. package/vendor/cli/src/devrun.js +1 -187
  38. package/vendor/cli/src/diff.js +1 -333
  39. package/vendor/cli/src/diffview.js +1 -296
  40. package/vendor/cli/src/engine.js +1 -297
  41. package/vendor/cli/src/entitlement.js +1 -355
  42. package/vendor/cli/src/events.js +1 -707
  43. package/vendor/cli/src/export.js +1 -67
  44. package/vendor/cli/src/fingerprint.js +1 -592
  45. package/vendor/cli/src/format.js +1 -259
  46. package/vendor/cli/src/fuzzy.js +1 -119
  47. package/vendor/cli/src/gate.js +1 -55
  48. package/vendor/cli/src/history.js +1 -401
  49. package/vendor/cli/src/init.js +1 -175
  50. package/vendor/cli/src/input.js +1 -139
  51. package/vendor/cli/src/keys.js +1 -183
  52. package/vendor/cli/src/limits.js +1 -190
  53. package/vendor/cli/src/markdown.js +1 -306
  54. package/vendor/cli/src/mcp.js +1 -694
  55. package/vendor/cli/src/models.js +1 -487
  56. package/vendor/cli/src/naming.js +1 -229
  57. package/vendor/cli/src/overlays.js +1 -461
  58. package/vendor/cli/src/panels.js +1 -1418
  59. package/vendor/cli/src/permissions.js +1 -290
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/provenance.js +2 -182
  63. package/vendor/cli/src/render.js +1 -515
  64. package/vendor/cli/src/screen.js +1 -518
  65. package/vendor/cli/src/screens.js +1 -896
  66. package/vendor/cli/src/secret.js +1 -59
  67. package/vendor/cli/src/securefs.js +1 -359
  68. package/vendor/cli/src/settings.js +1 -155
  69. package/vendor/cli/src/shared.js +1 -52
  70. package/vendor/cli/src/sharedpaths.js +1 -53
  71. package/vendor/cli/src/signup.js +1 -156
  72. package/vendor/cli/src/summarize.js +1 -95
  73. package/vendor/cli/src/sysdiag.js +1 -585
  74. package/vendor/cli/src/system.js +1 -40
  75. package/vendor/cli/src/theme.js +1 -570
  76. package/vendor/cli/src/title.js +1 -220
  77. package/vendor/cli/src/todos.js +1 -115
  78. package/vendor/cli/src/tokens.js +1 -263
  79. package/vendor/cli/src/topup.js +1 -210
  80. package/vendor/cli/src/update.js +1 -181
  81. package/vendor/cli/vendor/client/aegis.js +1 -2179
  82. package/vendor/cli/vendor/client/attest.js +1 -442
  83. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  84. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  85. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  86. package/vendor/cli/vendor/client/byok-catalog.js +1 -230
  87. package/vendor/cli/vendor/client/credentials.js +1 -494
  88. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  89. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  90. package/vendor/cli/vendor/client/drive-upload.js +1 -174
  91. package/vendor/cli/vendor/client/env-file.js +1 -1273
  92. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  93. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  94. package/vendor/cli/vendor/client/google-signin.js +1 -133
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  97. package/vendor/cli/vendor/client/platform.js +1 -937
  98. package/vendor/cli/vendor/client/prefs.js +1 -351
  99. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  100. package/vendor/cli/vendor/client/presence.js +1 -438
  101. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  102. package/vendor/cli/vendor/client/session-store.js +1 -548
  103. package/vendor/cli/vendor/client/topup.js +1 -297
  104. package/vendor/cli/vendor/client/touch.js +1 -458
  105. package/vendor/cli/vendor/client/update.js +1 -704
  106. package/vendor/cli/vendor/client/user-models.js +1 -381
  107. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  108. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  109. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
  110. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
  111. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3301
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  113. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  114. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
  115. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
  116. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  117. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
  118. package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
  119. package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
  120. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  121. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  122. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  123. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  124. package/vendor/cli/vendor/hosts/install.js +1 -638
  125. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  126. package/vendor/cli/vendor/hosts/spec.js +1 -164
  127. package/vendor/cli/vendor/hosts/targets.js +1 -346
  128. package/vendor/cli/vendor/mcp/server.js +1 -221
  129. package/vendor/cli/vendor/mcp/tools.js +1 -408
  130. package/vendor/cli/vendor/one/src/child.js +1 -285
  131. package/vendor/cli/vendor/one/src/permissions.js +1 -369
  132. package/vendor/desktop/bin/aegis.js +1 -32
  133. package/vendor/desktop/lib/account-key.js +1 -56
  134. package/vendor/desktop/lib/auto.js +1 -430
  135. package/vendor/desktop/lib/avatar/companion.js +1 -698
  136. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  137. package/vendor/desktop/lib/avatar/events.js +1 -344
  138. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  139. package/vendor/desktop/lib/avatar/holders.js +1 -612
  140. package/vendor/desktop/lib/avatar/identity.js +1 -641
  141. package/vendor/desktop/lib/avatar/level.js +1 -368
  142. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  143. package/vendor/desktop/lib/avatar/persona.js +1 -388
  144. package/vendor/desktop/lib/avatar/profile.js +1 -977
  145. package/vendor/desktop/lib/avatar/register.js +1 -307
  146. package/vendor/desktop/lib/avatar/store.js +1 -472
  147. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  148. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  149. package/vendor/desktop/lib/avatar/turn.js +1 -216
  150. package/vendor/desktop/lib/avatar/voice.js +1 -328
  151. package/vendor/desktop/lib/avatar/xp.js +1 -404
  152. package/vendor/desktop/lib/deep-link.js +1 -120
  153. package/vendor/desktop/lib/fingerprint.js +2 -347
  154. package/vendor/desktop/lib/google-connect.js +1 -227
  155. package/vendor/desktop/lib/local/agents.js +1 -105
  156. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  157. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  158. package/vendor/desktop/lib/local/context.js +1 -95
  159. package/vendor/desktop/lib/local/engine.js +1 -3301
  160. package/vendor/desktop/lib/local/entitlement.js +1 -660
  161. package/vendor/desktop/lib/local/git-scope.js +1 -228
  162. package/vendor/desktop/lib/local/local.js +1 -2135
  163. package/vendor/desktop/lib/local/prompt.js +1 -275
  164. package/vendor/desktop/lib/local/queue.js +1 -560
  165. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  166. package/vendor/desktop/lib/local/shell.js +1 -680
  167. package/vendor/desktop/lib/local/telemetry.js +1 -470
  168. package/vendor/desktop/lib/local/tools.js +1 -1238
  169. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  170. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  171. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  172. package/vendor/desktop/lib/quick-launcher.js +1 -84
  173. package/vendor/desktop/lib/settings.js +1 -890
  174. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  175. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  176. package/vendor/desktop/lib/sync/sessions.js +1 -106
  177. package/vendor/desktop/lib/window-state.js +1 -66
  178. package/vendor/desktop/main.js +1 -4529
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -636
  181. package/vendor/desktop/renderer/app.js +1 -6660
  182. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  183. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  184. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  185. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  186. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  187. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  188. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  189. package/vendor/desktop/renderer/budget.js +1 -168
  190. package/vendor/desktop/renderer/companion.js +1 -223
  191. package/vendor/desktop/renderer/diff.js +1 -359
  192. package/vendor/desktop/renderer/diffview.js +1 -336
  193. package/vendor/desktop/renderer/fingerprint.js +3 -736
  194. package/vendor/desktop/renderer/markdown.js +1 -168
  195. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  196. package/vendor/desktop/renderer/providers.js +1 -259
  197. package/vendor/desktop/renderer/quick.js +1 -191
  198. package/vendor/desktop/renderer/stream-policy.js +1 -306
  199. package/vendor/desktop/renderer/transcript-view.js +1 -323
  200. package/vendor/desktop/renderer/usage.js +1 -1239
  201. package/vendor/desktop/vendor/aegis.js +1 -2179
  202. package/vendor/desktop/vendor/attest.js +1 -442
  203. package/vendor/desktop/vendor/authorship-key.js +1 -410
  204. package/vendor/desktop/vendor/auto-provision.js +1 -134
  205. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  206. package/vendor/desktop/vendor/byok-catalog.js +1 -230
  207. package/vendor/desktop/vendor/credentials.js +1 -494
  208. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  209. package/vendor/desktop/vendor/drive-connect.js +1 -110
  210. package/vendor/desktop/vendor/drive-upload.js +1 -174
  211. package/vendor/desktop/vendor/env-file.js +1 -1273
  212. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  213. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  214. package/vendor/desktop/vendor/google-signin.js +1 -133
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -373
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -548
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -704
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,308 +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
- // Minimal markdown → styled span lines, in the spirit of Claude Code's
9
- // transcript rendering (monokai-flavored code, bold text, inline code).
10
- //
11
- // Ported from the upstream engine reference (ESM → CommonJS). The one
12
- // structural change: instead of importing `span`/`w` from screen.js — which a
13
- // concurrent workstream is rewriting — this module carries a local cell-width
14
- // function and a local `span()` that produce the *same* shape the rest of the
15
- // design system consumes: { t: text, s: style-prefix, w: cell-width }. That
16
- // shape is a contract with whoever renders these lines.
17
- //
18
- // Colours come from the theme tokens (via themeOf(ctx)) rather than a bare
19
- // palette, so light/dark both work.
20
-
21
- const {
22
- BOLD,
23
- BOLD_OFF,
24
- DIM,
25
- ITALIC,
26
- ITALIC_OFF,
27
- RESET_BG,
28
- RESET_FG,
29
- themeOf,
30
- } = require('./theme.js');
31
-
32
- // Real terminal cell width, mirroring the upstream engine's w():
33
- // combining marks / variation selectors are zero-width, CJK fullwidth forms and
34
- // emoji are two cells, everything else one. A plain codepoint count misaligns
35
- // every width decision the moment a line contains CJK or emoji.
36
- const RE_ZERO = /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F]/u;
37
- const RE_WIDE = /[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA000-\uA4CF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6\u{1F1E6}-\u{1F1FF}\u{1F300}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}\u{1FA70}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u;
38
- function w(t) {
39
- let n = 0;
40
- for (const ch of String(t == null ? '' : t)) {
41
- if (RE_ZERO.test(ch)) continue;
42
- n += RE_WIDE.test(ch) ? 2 : 1;
43
- }
44
- return n;
45
- }
46
-
47
- /** A styled text run. Shape { t, s, w } is shared with the render model. */
48
- function span(style, t) {
49
- return { t, s: style, w: w(t) };
50
- }
51
-
52
- // Turn an fg colour token into its background twin (38;2;R;G;B → 48;2;R;G;B),
53
- // so a code block sits on the theme's own code-block tint without typing a
54
- // colour inline — it stays theme-aware for free.
55
- function asBg(fgSgr) {
56
- return fgSgr.replace('[38;2;', '[48;2;');
57
- }
58
-
59
- // Rendering rules verified against a live capture of Claude Code 2.1.211:
60
- // - code lines: two-space indent, no fence label; a theme-tinted background
61
- // so the block reads as a distinct surface
62
- // - "- item" → " - item" (hyphen kept, two-space indent)
63
- // - "> quote" → " ▎ quote" (dim ▎, italic text)
64
- function renderMarkdown(text, width, ctx) {
65
- const t = themeOf(ctx);
66
- const codeStyle = asBg(t.black) + t.white; // code-block surface
67
- const lines = String(text == null ? '' : text).split('\n');
68
- const out = [];
69
- let inCode = false;
70
- for (const raw of lines) {
71
- const line = raw.replace(/\r$/, '');
72
- if (line.startsWith('```')) {
73
- inCode = !inCode;
74
- continue; // fences are not rendered
75
- }
76
- if (inCode) {
77
- out.push([span(codeStyle, ' ' + (line || ''))]);
78
- continue;
79
- }
80
- out.push(...inlineLine(line, width, t));
81
- }
82
- return out;
83
- }
84
-
85
- // Render one plain line with inline **bold** / `code` / "- " bullets / quotes.
86
- function inlineLine(text, width, t) {
87
- const ts = text.trimStart();
88
- let body = text;
89
- let prefix = null;
90
- let isQuote = false;
91
- // "- item" → " - item": keep the hyphen marker with a two-space indent.
92
- if (ts.startsWith('- ')) {
93
- prefix = span(t.white, ' - ');
94
- body = ts.slice(2);
95
- } else if (ts.startsWith(' - ')) {
96
- prefix = span(t.white, ' - ');
97
- body = ts.slice(4);
98
- } else if (ts.startsWith('> ')) {
99
- // "> quote" → " ▎ quote" (dim bar, italic body).
100
- prefix = span(DIM, ' ▎ ');
101
- body = ts.slice(2);
102
- isQuote = true;
103
- }
104
-
105
- const spans = [];
106
- const re = /(\*\*[^*]+\*\*|`[^`]+`)/g;
107
- let last = 0;
108
- let m;
109
- while ((m = re.exec(body))) {
110
- if (m.index > last) pushText(spans, body.slice(last, m.index), t);
111
- const tok = m[0];
112
- if (tok.startsWith('**')) pushText(spans, tok.slice(2, -2), t, BOLD);
113
- else pushText(spans, tok.slice(1, -1), t, t.green);
114
- last = m.index + tok.length;
115
- }
116
- if (last < body.length) pushText(spans, body.slice(last), t);
117
- if (isQuote) {
118
- // italicize the body of a quote line
119
- for (const sp of spans) sp.s = ITALIC + sp.s + ITALIC_OFF;
120
- }
121
- return wrapInline(spans, width, prefix);
122
- }
123
-
124
- function pushText(spans, text, t, style) {
125
- // Emit only non-space words; wrapInline adds separators. This avoids
126
- // double-spacing when text arrives in chunks.
127
- const s = style == null ? t.white : style;
128
- const parts = text.split(/[ \t]+/).filter(Boolean);
129
- for (const p of parts) {
130
- spans.push(span(s, p));
131
- }
132
- }
133
-
134
- // Wrap the word spans, prepending `prefix` verbatim to the first line only
135
- // (so " - " / " ▎ " markers keep their exact spacing).
136
- function wrapInline(line, width, prefix) {
137
- const res = [];
138
- let cur = prefix ? [prefix] : [];
139
- let curW = prefix ? prefix.w : 0;
140
- // Does the accumulator's last character end in whitespace? This mirrors the
141
- // old /\s$/.test(cur.map(join)) check but tracks incrementally — the join
142
- // version was O(line) PER WORD, making a paragraph render O(n²) and freezing
143
- // the UI on long streaming answers.
144
- let endsSpace = prefix ? /\s$/.test(prefix.t) : false;
145
- const flush = () => {
146
- if (cur.length) {
147
- res.push(cur);
148
- cur = [];
149
- curW = 0;
150
- endsSpace = false;
151
- }
152
- };
153
- for (const sp of line) {
154
- const words = sp.t.split(' ');
155
- for (let i = 0; i < words.length; i++) {
156
- const word = words[i];
157
- const ww = w(word);
158
- // Only insert a separator between words when nothing before already
159
- // ends in whitespace (prevents "· " + word becoming "· word").
160
- const needSep = curW > 0 && i === 0 && /^\S/.test(word) && !endsSpace;
161
- if (curW + ww + (needSep ? 1 : 0) > width && curW > 0) {
162
- flush();
163
- }
164
- if (ww > width) {
165
- // An unbreakable token wider than the terminal: emit one width-sized
166
- // row per piece. Slice once into code-point arrays (O(n)) rather than
167
- // re-slicing the remainder each piece (O(n²)), and cap the rows so a
168
- // pathological token can't balloon the transcript either.
169
- const chars = [...word];
170
- const cws = chars.map((c) => w(c)); // cell width per code point, once
171
- let total = 0;
172
- for (const cw of cws) total += cw;
173
- const MAX_PIECES = 400;
174
- let j = 0;
175
- let piece = 0;
176
- while (total > width) {
177
- // Take whole code points until the row is full — a codepoint slice
178
- // (width chars) would split 2-cell CJK/emoji mid-glyph.
179
- let take = 0;
180
- let hw = 0;
181
- while (j + take < chars.length && hw + cws[j + take] <= width) {
182
- hw += cws[j + take];
183
- take++;
184
- }
185
- if (!take) take = 1; // single glyph wider than the terminal
186
- const head = chars.slice(j, j + take).join('');
187
- if (curW) {
188
- cur.push(span('', ' '));
189
- curW++;
190
- endsSpace = true;
191
- }
192
- cur.push(span(sp.s, head));
193
- curW += hw;
194
- flush();
195
- j += take;
196
- total -= hw;
197
- if (++piece >= MAX_PIECES) {
198
- if (curW) {
199
- cur.push(span('', ' '));
200
- curW++;
201
- }
202
- cur.push(span(sp.s, '…'));
203
- flush();
204
- return res.length ? res : [[span('', '')]];
205
- }
206
- }
207
- const rest = chars.slice(j).join('');
208
- if (rest) {
209
- cur.push(span(sp.s, rest));
210
- curW += w(rest);
211
- endsSpace = /\s$/.test(rest);
212
- }
213
- } else {
214
- if (curW > 0 && needSep) {
215
- cur.push(span('', ' '));
216
- curW++;
217
- endsSpace = true;
218
- }
219
- cur.push(span(sp.s, word));
220
- curW += ww;
221
- endsSpace = /\s$/.test(word);
222
- }
223
- }
224
- }
225
- flush();
226
- return res.length ? res : [[span('', '')]];
227
- }
228
-
229
- // The Monokai Extended diff preview shown on the theme picker (verbatim from
230
- // the reference capture; the literals are that theme's colours, not this one's).
231
- function renderDiffPreview(width, ctx) {
232
- const t = themeOf(ctx);
233
- const div = '╌'.repeat(Math.max(10, width - 4));
234
- const num = (s) => span(t.gray + '\x1b[2m', s);
235
- const plain = (s) => span(t.white, s);
236
- const kw = (s) => span(RGB_LEGACY(102, 217, 239), s); // monokai: function
237
- const fn = (s) => span(RGB_LEGACY(166, 226, 46), s);
238
- const str = (s) => span(RGB_LEGACY(230, 219, 116), s);
239
- const del = (s) => span('\x1b[38;2;220;90;90m\x1b[48;2;61;1;0m', s);
240
- const delHi = (s) => span('\x1b[38;2;248;248;242m\x1b[48;2;92;2;0m', s);
241
- const add = (s) => span('\x1b[38;2;80;200;80m\x1b[48;2;2;40;0m', s);
242
- const addHi = (s) => span('\x1b[38;2;255;255;255m\x1b[48;2;4;71;0m', s);
243
-
244
- const W = Math.max(28, width - 8);
245
- const padBg = (spans, bg) => {
246
- let cur = 0;
247
- const out = [...spans];
248
- for (const sp of out) cur += sp.w;
249
- if (cur < W) out.push(span(bg + ' ', ' '.repeat(W - cur)));
250
- out.push(span(RESET_BG, ''));
251
- return out;
252
- };
253
-
254
- const lines = [];
255
- lines.push([span(t.dim, div)]);
256
- lines.push([num(' 1 '), kw('function'), plain(' '), fn('greet'), plain('()'), span(t.white, '{')]);
257
- lines.push(
258
- padBg(
259
- [
260
- num(' 2 '),
261
- del('-'),
262
- plain(' '),
263
- del('console'),
264
- span('\x1b[38;2;166;226;46m\x1b[48;2;61;1;0m', '.log'),
265
- del('('),
266
- str('"Hello, '),
267
- delHi('World'),
268
- del('!");'),
269
- ],
270
- '\x1b[48;2;61;1;0m'
271
- )
272
- );
273
- lines.push(
274
- padBg(
275
- [
276
- num(' 2 '),
277
- add('+'),
278
- plain(' '),
279
- add('console'),
280
- span('\x1b[38;2;166;226;46m\x1b[48;2;2;40;0m', '.log'),
281
- add('('),
282
- str('"Hello, '),
283
- addHi('Claude'),
284
- add('!");'),
285
- ],
286
- '\x1b[48;2;2;40;0m'
287
- )
288
- );
289
- lines.push([num(' 3 '), plain('}')]);
290
- lines.push([span(t.dim, div)]);
291
- return lines;
292
- }
293
-
294
- function RGB_LEGACY(r, g, b) {
295
- return `\x1b[38;2;${r};${g};${b}m`;
296
- }
297
-
298
- module.exports = {
299
- renderMarkdown,
300
- renderDiffPreview,
301
- // Re-exported style tokens the reference exposed for legacy consumers.
302
- RESET_FG,
303
- BOLD,
304
- BOLD_OFF,
305
- // Also expose the local model helpers so consumers/tests can reuse them.
306
- span,
307
- w,
308
- };
3
+ "use strict";const{BOLD:BOLD,BOLD_OFF:BOLD_OFF,DIM:DIM,ITALIC:ITALIC,ITALIC_OFF:ITALIC_OFF,RESET_BG:RESET_BG,RESET_FG:RESET_FG,themeOf:themeOf}=require("./theme.js"),RE_ZERO=/[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F]/u,RE_WIDE=/[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA000-\uA4CF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6\u{1F1E6}-\u{1F1FF}\u{1F300}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}\u{1FA70}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u;function w(n){let s=0;for(const t of String(null==n?"":n))RE_ZERO.test(t)||(s+=RE_WIDE.test(t)?2:1);return s}function span(n,s){return{t:s,s:n,w:w(s)}}function asBg(n){return n.replace("[38;2;","[48;2;")}function renderMarkdown(n,s,t){const e=themeOf(t),u=asBg(e.black)+e.white,F=String(null==n?"":n).split("\n"),r=[];let o=!1;for(const n of F){const t=n.replace(/\r$/,"");t.startsWith("```")?o=!o:o?r.push([span(u," "+(t||""))]):r.push(...inlineLine(t,s,e))}return r}function inlineLine(n,s,t){const e=n.trimStart();let u=n,F=null,r=!1;e.startsWith("- ")?(F=span(t.white," - "),u=e.slice(2)):e.startsWith(" - ")?(F=span(t.white," - "),u=e.slice(4)):e.startsWith("> ")&&(F=span(DIM," ▎ "),u=e.slice(2),r=!0);const o=[],p=/(\*\*[^*]+\*\*|`[^`]+`)/g;let i,a=0;for(;i=p.exec(u);){i.index>a&&pushText(o,u.slice(a,i.index),t);const n=i[0];n.startsWith("**")?pushText(o,n.slice(2,-2),t,BOLD):pushText(o,n.slice(1,-1),t,t.green),a=i.index+n.length}if(a<u.length&&pushText(o,u.slice(a),t),r)for(const n of o)n.s=ITALIC+n.s+ITALIC_OFF;return wrapInline(o,s,F)}function pushText(n,s,t,e){const u=null==e?t.white:e,F=s.split(/[ \t]+/).filter(Boolean);for(const s of F)n.push(span(u,s))}function wrapInline(n,s,t){const e=[];let u=t?[t]:[],F=t?t.w:0,r=!!t&&/\s$/.test(t.t);const o=()=>{u.length&&(e.push(u),u=[],F=0,r=!1)};for(const t of n){const n=t.t.split(" ");for(let p=0;p<n.length;p++){const i=n[p],a=w(i),l=F>0&&0===p&&/^\S/.test(i)&&!r;if(F+a+(l?1:0)>s&&F>0&&o(),a>s){const n=[...i],p=n.map((n=>w(n)));let a=0;for(const n of p)a+=n;const l=400;let c=0,h=0;for(;a>s;){let i=0,f=0;for(;c+i<n.length&&f+p[c+i]<=s;)f+=p[c+i],i++;i||(i=1);const E=n.slice(c,c+i).join("");if(F&&(u.push(span(""," ")),F++,r=!0),u.push(span(t.s,E)),F+=f,o(),c+=i,a-=f,++h>=l)return F&&(u.push(span(""," ")),F++),u.push(span(t.s,"…")),o(),e.length?e:[[span("","")]]}const f=n.slice(c).join("");f&&(u.push(span(t.s,f)),F+=w(f),r=/\s$/.test(f))}else F>0&&l&&(u.push(span(""," ")),F++,r=!0),u.push(span(t.s,i)),F+=a,r=/\s$/.test(i)}}return o(),e.length?e:[[span("","")]]}function renderDiffPreview(n,s){const t=themeOf(s),e="╌".repeat(Math.max(10,n-4)),u=n=>span(t.gray+"",n),F=n=>span(t.white,n),r=n=>span(RGB_LEGACY(230,219,116),n),o=n=>span("",n),p=n=>span("",n),i=Math.max(28,n-8),a=(n,s)=>{let t=0;const e=[...n];for(const n of e)t+=n.w;return t<i&&e.push(span(s+" "," ".repeat(i-t))),e.push(span(RESET_BG,"")),e},l=[];return l.push([span(t.dim,e)]),l.push([u(" 1 "),span(RGB_LEGACY(102,217,239),"function"),F(" "),span(RGB_LEGACY(166,226,46),"greet"),F("()"),span(t.white,"{")]),l.push(a([u(" 2 "),o("-"),F(" "),o("console"),span("",".log"),o("("),r('"Hello, '),span("","World"),o('!");')],"")),l.push(a([u(" 2 "),p("+"),F(" "),p("console"),span("",".log"),p("("),r('"Hello, '),span("","Claude"),p('!");')],"")),l.push([u(" 3 "),F("}")]),l.push([span(t.dim,e)]),l}function RGB_LEGACY(n,s,t){return`[38;2;${n};${s};${t}m`}module.exports={renderMarkdown:renderMarkdown,renderDiffPreview:renderDiffPreview,RESET_FG:RESET_FG,BOLD:BOLD,BOLD_OFF:BOLD_OFF,span:span,w:w};