aegiscode 7.0.13 → 7.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +3 -2
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2932
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3008
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -3987
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/fingerprint.js +1 -592
  28. package/src/format.js +1 -259
  29. package/src/fuzzy.js +1 -119
  30. package/src/history.js +1 -401
  31. package/src/init.js +1 -175
  32. package/src/input.js +1 -139
  33. package/src/keys.js +1 -183
  34. package/src/markdown.js +1 -306
  35. package/src/models.js +1 -487
  36. package/src/naming.js +1 -229
  37. package/src/overlays.js +1 -461
  38. package/src/panels.js +1 -1418
  39. package/src/ping.js +1 -226
  40. package/src/presence.js +1 -238
  41. package/src/render.js +1 -515
  42. package/src/screen.js +1 -518
  43. package/src/screens.js +1 -896
  44. package/src/secret.js +1 -59
  45. package/src/securefs.js +1 -359
  46. package/src/settings.js +1 -155
  47. package/src/shared.js +1 -52
  48. package/src/sharedpaths.js +1 -53
  49. package/src/signup.js +1 -156
  50. package/src/summarize.js +1 -95
  51. package/src/sysdiag.js +1 -585
  52. package/src/system.js +1 -40
  53. package/src/theme.js +1 -570
  54. package/src/title.js +1 -220
  55. package/src/todos.js +1 -115
  56. package/src/tokens.js +1 -263
  57. package/src/topup.js +1 -210
  58. package/src/update.js +1 -181
  59. package/vendor/client/aegis.js +1 -2054
  60. package/vendor/client/attest.js +1 -442
  61. package/vendor/client/authorship-key.js +1 -410
  62. package/vendor/client/auto-provision.js +1 -134
  63. package/vendor/client/brain-catalog.js +1 -268
  64. package/vendor/client/byok-catalog.js +1 -230
  65. package/vendor/client/credentials.js +1 -494
  66. package/vendor/client/device-fingerprint.js +1 -141
  67. package/vendor/client/drive-connect.js +1 -85
  68. package/vendor/client/drive-upload.js +1 -174
  69. package/vendor/client/env-file.js +1 -1273
  70. package/vendor/client/fingerprint.js +1 -1064
  71. package/vendor/client/foreign-memory.js +1 -669
  72. package/vendor/client/google-signin.js +1 -125
  73. package/vendor/client/hooks.js +1 -430
  74. package/vendor/client/model-discovery.js +1 -330
  75. package/vendor/client/platform.js +1 -937
  76. package/vendor/client/prefs.js +1 -351
  77. package/vendor/client/presence-constants.js +1 -107
  78. package/vendor/client/presence.js +1 -438
  79. package/vendor/client/record-vault.js +3 -1055
  80. package/vendor/client/session-store.js +1 -548
  81. package/vendor/client/topup.js +1 -297
  82. package/vendor/client/touch.js +1 -458
  83. package/vendor/client/update.js +1 -704
  84. package/vendor/client/user-models.js +1 -381
  85. package/vendor/desktop/lib/local/agents.js +1 -105
  86. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  87. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  88. package/vendor/desktop/lib/local/context.js +1 -95
  89. package/vendor/desktop/lib/local/engine.js +1 -3228
  90. package/vendor/desktop/lib/local/entitlement.js +1 -654
  91. package/vendor/desktop/lib/local/git-scope.js +1 -228
  92. package/vendor/desktop/lib/local/local.js +1 -2135
  93. package/vendor/desktop/lib/local/prompt.js +1 -275
  94. package/vendor/desktop/lib/local/queue.js +1 -560
  95. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  96. package/vendor/desktop/lib/local/shell.js +1 -680
  97. package/vendor/desktop/lib/local/tools.js +1 -1238
  98. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  99. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  100. package/vendor/desktop/lib/settings.js +1 -890
  101. package/vendor/desktop/renderer/usage.js +1 -1239
  102. package/vendor/hosts/install.js +1 -638
  103. package/vendor/hosts/openai-shim.js +1 -515
  104. package/vendor/hosts/spec.js +1 -164
  105. package/vendor/hosts/targets.js +1 -346
  106. package/vendor/mcp/server.js +1 -221
  107. package/vendor/mcp/tools.js +1 -408
  108. package/vendor/one/src/child.js +1 -285
  109. package/vendor/one/src/permissions.js +1 -369
package/src/input.js CHANGED
@@ -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};
package/src/keys.js CHANGED
@@ -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};
package/src/markdown.js CHANGED
@@ -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 "),("function",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};