aegisone 1.0.34 → 1.0.35

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 -976
  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 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  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 -575
  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 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,141 +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
- * Line editor with history — the input line's buffer, cursor and recall.
10
- *
11
- * Ported from the upstream engine reference. The one thing worth knowing before
12
- * touching it: `cursor` is a **codepoint** index, not a UTF-16 index. Slicing
13
- * `buf` directly corrupts a surrogate pair the moment one has been inserted
14
- * (the next insert's slice lands mid-pair and leaves a lone surrogate, which
15
- * renders as U+FFFD), so every mutation splices on `[...buf]` instead.
16
- */
17
-
18
- class LineEditor {
19
- constructor() {
20
- this.buf = '';
21
- this.cursor = 0;
22
- this.history = [];
23
- this.hi = -1;
24
- this.draft = '';
25
- }
26
-
27
- reset() {
28
- this.buf = '';
29
- this.cursor = 0;
30
- this.hi = -1;
31
- this.draft = '';
32
- }
33
-
34
- insert(ch) {
35
- const arr = [...this.buf];
36
- arr.splice(this.cursor, 0, ...ch);
37
- this.buf = arr.join('');
38
- this.cursor += [...ch].length;
39
- }
40
-
41
- left() {
42
- if (this.cursor > 0) this.cursor--;
43
- }
44
-
45
- right() {
46
- if (this.cursor < [...this.buf].length) this.cursor++;
47
- }
48
-
49
- home() {
50
- this.cursor = 0;
51
- }
52
-
53
- end() {
54
- this.cursor = [...this.buf].length;
55
- }
56
-
57
- backspace() {
58
- if (this.cursor === 0) return;
59
- const arr = [...this.buf];
60
- arr.splice(this.cursor - 1, 1);
61
- this.buf = arr.join('');
62
- this.cursor--;
63
- }
64
-
65
- delete() {
66
- if (this.cursor >= [...this.buf].length) return;
67
- const arr = [...this.buf];
68
- arr.splice(this.cursor, 1);
69
- this.buf = arr.join('');
70
- }
71
-
72
- /** vim `s` — delete the char under the cursor (caller switches to insert). */
73
- substChar() {
74
- if (this.cursor >= [...this.buf].length) return false;
75
- this.delete();
76
- return true;
77
- }
78
-
79
- /** vim `S` — clear the whole line (caller switches to insert). */
80
- substLine() {
81
- const had = this.buf.length > 0;
82
- this.buf = '';
83
- this.cursor = 0;
84
- return had;
85
- }
86
-
87
- killToEnd() {
88
- this.buf = [...this.buf].slice(0, this.cursor).join('');
89
- }
90
-
91
- wordBack() {
92
- const arr = [...this.buf];
93
- let i = this.cursor;
94
- while (i > 0 && arr[i - 1] === ' ') i--;
95
- while (i > 0 && arr[i - 1] !== ' ') i--;
96
- this.cursor = i;
97
- }
98
-
99
- wordDelete() {
100
- const arr = [...this.buf];
101
- let i = this.cursor;
102
- while (i < arr.length && arr[i] === ' ') i++;
103
- while (i < arr.length && arr[i] !== ' ') i++;
104
- this.buf = arr.slice(0, this.cursor).join('') + arr.slice(i).join('');
105
- }
106
-
107
- historyUp() {
108
- if (!this.history.length) return;
109
- if (this.hi === -1) {
110
- this.draft = this.buf;
111
- this.hi = this.history.length - 1;
112
- } else if (this.hi > 0) this.hi--;
113
- this.buf = this.history[this.hi];
114
- this.end();
115
- }
116
-
117
- historyDown() {
118
- if (this.hi === -1) return;
119
- if (this.hi < this.history.length - 1) {
120
- this.hi++;
121
- this.buf = this.history[this.hi];
122
- } else {
123
- this.hi = -1;
124
- this.buf = this.draft;
125
- }
126
- this.end();
127
- }
128
-
129
- /** Commit the buffer. Returns the trimmed text and clears the line, or null
130
- * when there was nothing to submit (a bare Enter must not become a turn). */
131
- submit() {
132
- const text = this.buf.trim();
133
- if (!text) return null;
134
- this.history.push(text);
135
- if (this.history.length > 500) this.history.shift();
136
- this.reset();
137
- return text;
138
- }
139
- }
140
-
141
- module.exports = { LineEditor };
3
+ "use strict";class LineEditor{constructor(){this.buf="",this.cursor=0,this.history=[],this.hi=-1,this.draft=""}reset(){this.buf="",this.cursor=0,this.hi=-1,this.draft=""}insert(s){const t=[...this.buf];t.splice(this.cursor,0,...s),this.buf=t.join(""),this.cursor+=[...s].length}left(){this.cursor>0&&this.cursor--}right(){this.cursor<[...this.buf].length&&this.cursor++}home(){this.cursor=0}end(){this.cursor=[...this.buf].length}backspace(){if(0===this.cursor)return;const s=[...this.buf];s.splice(this.cursor-1,1),this.buf=s.join(""),this.cursor--}delete(){if(this.cursor>=[...this.buf].length)return;const s=[...this.buf];s.splice(this.cursor,1),this.buf=s.join("")}substChar(){return!(this.cursor>=[...this.buf].length||(this.delete(),0))}substLine(){const s=this.buf.length>0;return this.buf="",this.cursor=0,s}killToEnd(){this.buf=[...this.buf].slice(0,this.cursor).join("")}wordBack(){const s=[...this.buf];let t=this.cursor;for(;t>0&&" "===s[t-1];)t--;for(;t>0&&" "!==s[t-1];)t--;this.cursor=t}wordDelete(){const s=[...this.buf];let t=this.cursor;for(;t<s.length&&" "===s[t];)t++;for(;t<s.length&&" "!==s[t];)t++;this.buf=s.slice(0,this.cursor).join("")+s.slice(t).join("")}historyUp(){this.history.length&&(-1===this.hi?(this.draft=this.buf,this.hi=this.history.length-1):this.hi>0&&this.hi--,this.buf=this.history[this.hi],this.end())}historyDown(){-1!==this.hi&&(this.hi<this.history.length-1?(this.hi++,this.buf=this.history[this.hi]):(this.hi=-1,this.buf=this.draft),this.end())}submit(){const s=this.buf.trim();return s?(this.history.push(s),this.history.length>500&&this.history.shift(),this.reset(),s):null}}module.exports={LineEditor:LineEditor};
@@ -1,185 +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
- * Raw key decoding for the terminal (raw-mode stdin).
10
- *
11
- * Ported from the upstream engine reference so the aegiscode CLI and the
12
- * reference client decode the same bytes into the same key names — the
13
- * chatflow's key handling (history recall, vim motions, Esc-to-interrupt) is
14
- * only correct if the decoder agrees with it.
15
- *
16
- * Two entry points:
17
- * decodePlain(c) one character with no ESC prefix
18
- * decodeEscSequence(s) a complete CSI (\x1b[…X) or SS3 (\x1bOX) sequence
19
- *
20
- * Both return either `null` (nothing to do) or a key object `{name, ch?}`.
21
- */
22
-
23
- const KEY = Object.freeze({
24
- UP: 'up',
25
- DOWN: 'down',
26
- LEFT: 'left',
27
- RIGHT: 'right',
28
- ENTER: 'enter',
29
- TAB: 'tab',
30
- ESC: 'esc',
31
- BACKSPACE: 'backspace',
32
- DELETE: 'delete',
33
- HOME: 'home',
34
- END: 'end',
35
- PAGE_UP: 'pageup',
36
- PAGE_DOWN: 'pagedown',
37
- CTRL_C: 'ctrl-c',
38
- CTRL_D: 'ctrl-d',
39
- CTRL_L: 'ctrl-l',
40
- CTRL_R: 'ctrl-r',
41
- CTRL_U: 'ctrl-u',
42
- CTRL_A: 'ctrl-a',
43
- CTRL_E: 'ctrl-e',
44
- CTRL_K: 'ctrl-k',
45
- CTRL_W: 'ctrl-w',
46
- CTRL_T: 'ctrl-t',
47
- CTRL_N: 'ctrl-n',
48
- CTRL_P: 'ctrl-p',
49
- CTRL_O: 'ctrl-o',
50
- CTRL_V: 'ctrl-v',
51
- CTRL_B: 'ctrl-b',
52
- CTRL_LEFT: 'ctrl-left',
53
- CTRL_RIGHT: 'ctrl-right',
54
- // Shift is a MODIFIER here, not a duplicate of the bare key: the pickers bind
55
- // shift+arrow to "move the highlight and commit it", so decoding mod 2 as the
56
- // plain arrow (which is what this decoder did) would make shift silently
57
- // identical to an unmodified arrow — the chord the status line advertises
58
- // would do nothing the arrow does not. `SHIFT_ENTER` is here for the palettes
59
- // that want a non-Enter commit; it arrives in two spellings (see
60
- // decodeEscSequence) because terminals disagree about which one to send.
61
- SHIFT_UP: 'shift-up',
62
- SHIFT_DOWN: 'shift-down',
63
- SHIFT_ENTER: 'shift-enter',
64
- });
65
-
66
- /** Decode a bare character (no escape prefix) into a key object. */
67
- function decodePlain(chunk) {
68
- switch (chunk) {
69
- case '\r':
70
- case '\n':
71
- return { name: KEY.ENTER };
72
- case '\t':
73
- return { name: KEY.TAB };
74
- case '\x03':
75
- return { name: KEY.CTRL_C };
76
- case '\x04':
77
- return { name: KEY.CTRL_D };
78
- case '\x0c':
79
- return { name: KEY.CTRL_L };
80
- case '\x12':
81
- return { name: KEY.CTRL_R };
82
- case '\x15':
83
- return { name: KEY.CTRL_U };
84
- case '\x01':
85
- return { name: KEY.CTRL_A };
86
- case '\x05':
87
- return { name: KEY.CTRL_E };
88
- case '\x0b':
89
- return { name: KEY.CTRL_K };
90
- case '\x17':
91
- return { name: KEY.CTRL_W };
92
- case '\x14':
93
- return { name: KEY.CTRL_T };
94
- case '\x0e':
95
- return { name: KEY.CTRL_N };
96
- case '\x10':
97
- return { name: KEY.CTRL_P };
98
- case '\x0f':
99
- return { name: KEY.CTRL_O };
100
- // Ctrl+V pastes the clipboard (image → a saved path, else its text) and
101
- // Ctrl+B copies the whole conversation. Both were dead letters here: `\x16`
102
- // and `\x02` fell into the "any other control char" branch below and
103
- // decoded as ESC — so Ctrl+V did nothing on every platform, and Ctrl+B
104
- // aborted a running turn. The upstream engine names both keys; this host
105
- // now does too.
106
- case '\x16':
107
- return { name: KEY.CTRL_V };
108
- case '\x02':
109
- return { name: KEY.CTRL_B };
110
- case '\x7f':
111
- case '\x08':
112
- return { name: KEY.BACKSPACE };
113
- default: {
114
- // Any other control char is meaningless here; printable is a char.
115
- const code = chunk.charCodeAt(0);
116
- if (code < 32 || code === 127) return { name: KEY.ESC };
117
- return { name: 'char', ch: chunk };
118
- }
119
- }
120
- }
121
-
122
- /** Decode a complete CSI/SS3 escape sequence into a key object (or null). */
123
- function decodeEscSequence(seq) {
124
- if (seq.startsWith('\x1b[')) {
125
- const body = seq.slice(2);
126
- // CSI with modifier params, e.g. 1;5C = ctrl+right.
127
- const m = body.match(/^([0-9;]*)([A-Za-z~])$/);
128
- if (m) {
129
- const params = m[1] ? m[1].split(';') : [];
130
- const mod = params.length > 1 ? parseInt(params[1], 10) : 0;
131
- switch (m[2]) {
132
- // Modifier 2 is shift (`1;2A` = shift+up). It has to be named, not
133
- // folded into the bare arrow: the /model picker binds shift+arrow to
134
- // "move the highlight and pin it", so decoding it as a plain arrow is
135
- // what made the advertised chord indistinguishable from the arrow.
136
- case 'A':
137
- return { name: mod === 2 ? KEY.SHIFT_UP : KEY.UP };
138
- case 'B':
139
- return { name: mod === 2 ? KEY.SHIFT_DOWN : KEY.DOWN };
140
- case 'C':
141
- return mod === 5 ? { name: KEY.CTRL_RIGHT } : { name: KEY.RIGHT };
142
- case 'D':
143
- return mod === 5 ? { name: KEY.CTRL_LEFT } : { name: KEY.LEFT };
144
- case 'H':
145
- return { name: KEY.HOME };
146
- case 'F':
147
- return { name: KEY.END };
148
- case 'u': {
149
- // Kitty/modifyOtherKeys spelling: `CSI <codepoint> ; <modifier> u`.
150
- // A terminal in that mode sends shift+enter as `\x1b[13;2u` rather
151
- // than the legacy `\x1b\r`, and both have to land on the same key
152
- // name or the chord works on one terminal and not the next.
153
- const code = parseInt(params[0] || '0', 10);
154
- if (code === 13 && mod === 2) return { name: KEY.SHIFT_ENTER };
155
- return null;
156
- }
157
- case '~': {
158
- const n = parseInt(params[0] || '0', 10);
159
- if (n === 3) return { name: KEY.DELETE };
160
- if (n === 5) return { name: KEY.PAGE_UP };
161
- if (n === 6) return { name: KEY.PAGE_DOWN };
162
- if (n === 1 || n === 7) return { name: KEY.HOME };
163
- if (n === 4 || n === 8) return { name: KEY.END };
164
- return null;
165
- }
166
- default:
167
- return null;
168
- }
169
- }
170
- return null;
171
- }
172
- if (seq.startsWith('\x1bO')) {
173
- const c = seq[2];
174
- if (c === 'H') return { name: KEY.HOME };
175
- if (c === 'F') return { name: KEY.END };
176
- return null;
177
- }
178
- // The legacy spelling of shift+enter, for terminals that never send the CSI
179
- // `u` form above. `\x1b\r` is only ever shift+enter (a bare `\r` is ENTER and
180
- // arrives without the ESC), so it cannot be confused with anything else.
181
- if (seq === '\x1b\r' || seq === '\x1b\n') return { name: KEY.SHIFT_ENTER };
182
- return { name: KEY.ESC };
183
- }
184
-
185
- module.exports = { KEY, decodePlain, decodeEscSequence };
3
+ "use strict";const KEY=Object.freeze({UP:"up",DOWN:"down",LEFT:"left",RIGHT:"right",ENTER:"enter",TAB:"tab",ESC:"esc",BACKSPACE:"backspace",DELETE:"delete",HOME:"home",END:"end",PAGE_UP:"pageup",PAGE_DOWN:"pagedown",CTRL_C:"ctrl-c",CTRL_D:"ctrl-d",CTRL_L:"ctrl-l",CTRL_R:"ctrl-r",CTRL_U:"ctrl-u",CTRL_A:"ctrl-a",CTRL_E:"ctrl-e",CTRL_K:"ctrl-k",CTRL_W:"ctrl-w",CTRL_T:"ctrl-t",CTRL_N:"ctrl-n",CTRL_P:"ctrl-p",CTRL_O:"ctrl-o",CTRL_V:"ctrl-v",CTRL_B:"ctrl-b",CTRL_LEFT:"ctrl-left",CTRL_RIGHT:"ctrl-right",SHIFT_UP:"shift-up",SHIFT_DOWN:"shift-down",SHIFT_ENTER:"shift-enter"});function decodePlain(e){switch(e){case"\r":case"\n":return{name:KEY.ENTER};case"\t":return{name:KEY.TAB};case"":return{name:KEY.CTRL_C};case"":return{name:KEY.CTRL_D};case"\f":return{name:KEY.CTRL_L};case"":return{name:KEY.CTRL_R};case"":return{name:KEY.CTRL_U};case"":return{name:KEY.CTRL_A};case"":return{name:KEY.CTRL_E};case"\v":return{name:KEY.CTRL_K};case"":return{name:KEY.CTRL_W};case"":return{name:KEY.CTRL_T};case"":return{name:KEY.CTRL_N};case"":return{name:KEY.CTRL_P};case"":return{name:KEY.CTRL_O};case"":return{name:KEY.CTRL_V};case"":return{name:KEY.CTRL_B};case"":case"\b":return{name:KEY.BACKSPACE};default:{const n=e.charCodeAt(0);return n<32||127===n?{name:KEY.ESC}:{name:"char",ch:e}}}}function decodeEscSequence(e){if(e.startsWith("[")){const n=e.slice(2).match(/^([0-9;]*)([A-Za-z~])$/);if(n){const e=n[1]?n[1].split(";"):[],r=e.length>1?parseInt(e[1],10):0;switch(n[2]){case"A":return{name:2===r?KEY.SHIFT_UP:KEY.UP};case"B":return{name:2===r?KEY.SHIFT_DOWN:KEY.DOWN};case"C":return 5===r?{name:KEY.CTRL_RIGHT}:{name:KEY.RIGHT};case"D":return 5===r?{name:KEY.CTRL_LEFT}:{name:KEY.LEFT};case"H":return{name:KEY.HOME};case"F":return{name:KEY.END};case"u":return 13===parseInt(e[0]||"0",10)&&2===r?{name:KEY.SHIFT_ENTER}:null;case"~":{const n=parseInt(e[0]||"0",10);return 3===n?{name:KEY.DELETE}:5===n?{name:KEY.PAGE_UP}:6===n?{name:KEY.PAGE_DOWN}:1===n||7===n?{name:KEY.HOME}:4===n||8===n?{name:KEY.END}:null}default:return null}}return null}if(e.startsWith("O")){const n=e[2];return"H"===n?{name:KEY.HOME}:"F"===n?{name:KEY.END}:null}return"\r"===e||"\n"===e?{name:KEY.SHIFT_ENTER}:{name:KEY.ESC}}module.exports={KEY:KEY,decodePlain:decodePlain,decodeEscSequence:decodeEscSequence};
@@ -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};