aegiscode 7.0.25 → 7.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -3
- package/scripts/check.mjs +52 -1
- package/scripts/demo.mjs +94 -1
- package/scripts/predist.mjs +75 -1
- package/scripts/runtests.mjs +56 -1
- package/scripts/seal-gate.mjs +74 -1
- package/src/agents.js +139 -1
- package/src/app.js +2957 -1
- package/src/art.js +289 -1
- package/src/chatflow.js +3023 -1
- package/src/checkpoint.js +90 -1
- package/src/clipboard.js +424 -1
- package/src/cloudsync.js +528 -1
- package/src/commands.js +4089 -1
- package/src/config.js +581 -1
- package/src/connect.js +349 -1
- package/src/credentials.js +33 -1
- package/src/deps.js +232 -1
- package/src/devrun.js +187 -1
- package/src/diff.js +333 -1
- package/src/diffview.js +296 -1
- package/src/engine.js +297 -1
- package/src/entitlement.js +355 -1
- package/src/events.js +707 -1
- package/src/export.js +67 -1
- package/src/filepreview.js +153 -1
- package/src/fingerprint.js +592 -1
- package/src/format.js +259 -1
- package/src/fuzzy.js +119 -1
- package/src/history.js +423 -1
- package/src/init.js +175 -1
- package/src/input.js +139 -1
- package/src/keys.js +183 -1
- package/src/markdown.js +306 -1
- package/src/models.js +507 -1
- package/src/naming.js +57 -1
- package/src/overlays.js +462 -1
- package/src/panels.js +1418 -1
- package/src/ping.js +226 -1
- package/src/presence.js +238 -1
- package/src/render.js +516 -1
- package/src/screen.js +518 -1
- package/src/screens.js +896 -1
- package/src/secret.js +59 -1
- package/src/securefs.js +359 -1
- package/src/settings.js +155 -1
- package/src/shared.js +52 -1
- package/src/sharedpaths.js +53 -1
- package/src/signup.js +156 -1
- package/src/summarize.js +95 -1
- package/src/sysdiag.js +585 -1
- package/src/system.js +40 -1
- package/src/theme.js +570 -1
- package/src/title.js +220 -1
- package/src/todos.js +115 -1
- package/src/tokens.js +263 -1
- package/src/topup.js +210 -1
- package/src/update.js +191 -1
- package/vendor/client/aegis.js +2441 -1
- package/vendor/client/attest.js +518 -1
- package/vendor/client/authorship-key.js +410 -1
- package/vendor/client/auto-provision.js +134 -1
- package/vendor/client/brain-catalog.js +268 -1
- package/vendor/client/byok-catalog.js +199 -1
- package/vendor/client/catalog-client.js +487 -1
- package/vendor/client/conversation-export.js +177 -1
- package/vendor/client/credentials.js +494 -1
- package/vendor/client/device-fingerprint.js +141 -1
- package/vendor/client/drive-connect.js +110 -1
- package/vendor/client/drive-upload.js +234 -1
- package/vendor/client/env-file.js +1273 -1
- package/vendor/client/fingerprint.js +1064 -1
- package/vendor/client/foreign-memory.js +669 -1
- package/vendor/client/google-signin.js +133 -1
- package/vendor/client/hooks.js +430 -1
- package/vendor/client/model-discovery.js +373 -1
- package/vendor/client/naming.js +283 -1
- package/vendor/client/platform.js +937 -1
- package/vendor/client/prefs.js +351 -1
- package/vendor/client/presence-constants.js +107 -1
- package/vendor/client/presence.js +438 -1
- package/vendor/client/record-vault.js +1055 -3
- package/vendor/client/session-store.js +575 -1
- package/vendor/client/topup.js +297 -1
- package/vendor/client/touch.js +458 -1
- package/vendor/client/update.js +763 -1
- package/vendor/client/user-models.js +381 -1
- package/vendor/desktop/lib/local/agents.js +105 -1
- package/vendor/desktop/lib/local/attachments.js +276 -1
- package/vendor/desktop/lib/local/autonomous.js +1045 -1
- package/vendor/desktop/lib/local/claude-pro.js +1028 -1
- package/vendor/desktop/lib/local/context.js +125 -1
- package/vendor/desktop/lib/local/engine.js +3666 -1
- package/vendor/desktop/lib/local/entitlement.js +660 -1
- package/vendor/desktop/lib/local/git-scope.js +228 -1
- package/vendor/desktop/lib/local/local.js +2145 -1
- package/vendor/desktop/lib/local/prompt.js +280 -1
- package/vendor/desktop/lib/local/queue.js +560 -1
- package/vendor/desktop/lib/local/session-rounds.js +238 -1
- package/vendor/desktop/lib/local/spill.js +75 -1
- package/vendor/desktop/lib/local/turn-guard.js +300 -1
- package/vendor/desktop/lib/local/worktree-lock.js +235 -1
- package/vendor/desktop/lib/settings.js +890 -1
- package/vendor/desktop/renderer/usage.js +1239 -1
- package/vendor/hosts/install.js +638 -1
- package/vendor/hosts/openai-shim.js +515 -1
- package/vendor/hosts/spec.js +164 -1
- package/vendor/hosts/targets.js +346 -1
- package/vendor/mcp/server.js +221 -1
- package/vendor/mcp/tools.js +408 -1
- package/vendor/one/src/child.js +285 -1
- package/vendor/one/src/permissions.js +383 -1
- package/SOURCE-OFFER.txt +0 -9
package/src/input.js
CHANGED
|
@@ -1,3 +1,141 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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 };
|
package/src/keys.js
CHANGED
|
@@ -1,3 +1,185 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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 };
|
package/src/markdown.js
CHANGED
|
@@ -1,3 +1,308 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
+
};
|