aegiscode 6.6.1 → 6.7.1
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/README.md +46 -0
- package/bin/aegiscode.js +87 -0
- package/package.json +1 -1
- package/src/app.js +156 -11
- package/src/art.js +114 -60
- package/src/autonomous.js +8 -2
- package/src/caps.js +597 -0
- package/src/chatflow.js +59 -6
- package/src/cloudsync.js +86 -6
- package/src/commands.js +243 -23
- package/src/config.js +87 -0
- package/src/diff.js +330 -0
- package/src/diffview.js +286 -0
- package/src/events.js +21 -10
- package/src/panels.js +59 -1
- package/src/render.js +39 -17
- package/src/screen.js +20 -20
- package/src/theme.js +334 -125
- package/vendor/desktop/lib/local/autonomous.js +45 -4
- package/vendor/desktop/lib/local/engine.js +38 -0
- package/vendor/desktop/lib/local/queue.js +4 -0
- package/vendor/desktop/lib/local/session-rounds.js +19 -2
package/src/diffview.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The edit block's paint layer: a one-line summary row plus, when the block is
|
|
5
|
+
* open, the diff itself in Monokai Extended colors.
|
|
6
|
+
*
|
|
7
|
+
* Two shapes, driven by one boolean (`open`):
|
|
8
|
+
*
|
|
9
|
+
* collapsed ● editFile
|
|
10
|
+
* ⎿ Update(src/diff.js) +12 -3 · click to view diff
|
|
11
|
+
*
|
|
12
|
+
* open ● editFile
|
|
13
|
+
* ⎿ Update(src/diff.js) +12 -3 · click to collapse
|
|
14
|
+
* 12 const a = 1;
|
|
15
|
+
* 13 - const b = 2;
|
|
16
|
+
* 13 + const b = 3;
|
|
17
|
+
*
|
|
18
|
+
* Small diffs open themselves (AUTO_OPEN_ROWS) so the common one-line edit is
|
|
19
|
+
* readable with no gesture at all — and that is not a nicety on this host: the
|
|
20
|
+
* CLI writes finished turns once to scrollback (screen.js's design note), so
|
|
21
|
+
* an edit the user has to ask for twice is an edit they will not read. Anything
|
|
22
|
+
* bigger starts collapsed so a 300-line rewrite cannot bury the transcript.
|
|
23
|
+
*
|
|
24
|
+
* Width safety is a hard requirement here, not a preference: `cli-render.test.mjs`
|
|
25
|
+
* pins that no emitted row exceeds the terminal width, because one row that
|
|
26
|
+
* wraps corrupts the cursor arithmetic of every row after it. Every row this
|
|
27
|
+
* module returns is therefore built from `clip()`-measured plain text and
|
|
28
|
+
* closed with RESET, so an add/del background can never bleed into the next
|
|
29
|
+
* line of scrollback.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const { DIM, RESET, GLYPH, themeOf, diffOf } = require('./theme.js');
|
|
33
|
+
const { w, clip } = require('./screen.js');
|
|
34
|
+
|
|
35
|
+
/** Diff body rows at or below this size open without a gesture. */
|
|
36
|
+
const AUTO_OPEN_ROWS = 30;
|
|
37
|
+
/** Rows painted inside one open block before the "… more diff lines" footer. */
|
|
38
|
+
const MAX_BLOCK_ROWS = 200;
|
|
39
|
+
|
|
40
|
+
/** " ⎿ " is five cells, so block rows indent under the summary's text. */
|
|
41
|
+
const INDENT = ' ';
|
|
42
|
+
|
|
43
|
+
const KEYWORDS = new Set([
|
|
44
|
+
'const', 'let', 'var', 'function', 'return', 'if', 'else', 'for', 'while', 'do', 'switch',
|
|
45
|
+
'case', 'break', 'continue', 'import', 'export', 'from', 'default', 'class', 'extends',
|
|
46
|
+
'new', 'try', 'catch', 'finally', 'throw', 'async', 'await', 'yield', 'static', 'typeof',
|
|
47
|
+
'instanceof', 'in', 'of', 'delete', 'this', 'super', 'null', 'undefined', 'true', 'false',
|
|
48
|
+
'def', 'elif', 'lambda', 'pass', 'raise', 'with', 'as', 'not', 'and', 'or', 'is', 'None',
|
|
49
|
+
'True', 'False', 'self', 'fn', 'mut', 'pub', 'impl', 'struct', 'enum', 'trait', 'match',
|
|
50
|
+
'package', 'func', 'defer', 'chan', 'nil', 'echo', 'local', 'then', 'fi', 'esac',
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Split one line of code into colored tokens. Deliberately line-local and cheap
|
|
55
|
+
* — it runs on every changed row of every block — so it colors comments,
|
|
56
|
+
* strings, numbers, keywords and called functions and leaves the rest plain,
|
|
57
|
+
* which is all the tinted diff rows need to read as code.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} text
|
|
60
|
+
* @param {object} [d] Diff palette (defaults to the dark one).
|
|
61
|
+
* @returns {Array<{t: string, c: string}>} tokens; `c` is a foreground color.
|
|
62
|
+
*/
|
|
63
|
+
function highlightLine(text, d) {
|
|
64
|
+
const D = d || diffOf(null);
|
|
65
|
+
const out = [];
|
|
66
|
+
const src = String(text == null ? '' : text);
|
|
67
|
+
const re = /(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?)|([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
68
|
+
const push = (t, c) => { if (t) out.push({ t, c }); };
|
|
69
|
+
let last = 0;
|
|
70
|
+
let m;
|
|
71
|
+
while ((m = re.exec(src))) {
|
|
72
|
+
if (m.index > last) push(src.slice(last, m.index), D.codeFg);
|
|
73
|
+
if (m[1]) push(m[1], D.comment);
|
|
74
|
+
else if (m[2]) push(m[2], D.str);
|
|
75
|
+
else if (m[3]) push(m[3], D.num);
|
|
76
|
+
else {
|
|
77
|
+
const word = m[4];
|
|
78
|
+
const isCall = /^\s*\(/.test(src.slice(m.index + word.length));
|
|
79
|
+
push(word, KEYWORDS.has(word) ? D.kw : isCall ? D.fn : D.codeFg);
|
|
80
|
+
}
|
|
81
|
+
last = m.index + m[0].length;
|
|
82
|
+
}
|
|
83
|
+
if (last < src.length) push(src.slice(last), D.codeFg);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Pair a run of removed rows with the added run that follows it and mark the
|
|
89
|
+
* slice that actually differs, so the changed word renders in the bright
|
|
90
|
+
* variant of the diff color. Equal run lengths only, and only when the shared
|
|
91
|
+
* prefix+suffix dominates the line — otherwise the mark would land on
|
|
92
|
+
* unrelated text. Mutates rows in place, adding `hi = {start, end}` in
|
|
93
|
+
* code-point offsets.
|
|
94
|
+
*/
|
|
95
|
+
function markIntraLine(rows) {
|
|
96
|
+
for (let i = 0; i < rows.length; i++) {
|
|
97
|
+
if (rows[i].sign !== '-') continue;
|
|
98
|
+
let d = i;
|
|
99
|
+
while (d < rows.length && rows[d].sign === '-') d++;
|
|
100
|
+
let a = d;
|
|
101
|
+
while (a < rows.length && rows[a].sign === '+') a++;
|
|
102
|
+
const delCount = d - i;
|
|
103
|
+
const addCount = a - d;
|
|
104
|
+
if (delCount && delCount === addCount) {
|
|
105
|
+
for (let k = 0; k < delCount; k++) {
|
|
106
|
+
const pair = intraLine(rows[i + k].text, rows[d + k].text);
|
|
107
|
+
if (!pair) continue;
|
|
108
|
+
rows[i + k].hi = { start: pair.delStart, end: pair.delEnd, side: 'del' };
|
|
109
|
+
rows[d + k].hi = { start: pair.addStart, end: pair.addEnd, side: 'add' };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
i = a - 1;
|
|
113
|
+
}
|
|
114
|
+
return rows;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function intraLine(delText, addText) {
|
|
118
|
+
const d = [...String(delText == null ? '' : delText)];
|
|
119
|
+
const a = [...String(addText == null ? '' : addText)];
|
|
120
|
+
let pre = 0;
|
|
121
|
+
while (pre < d.length && pre < a.length && d[pre] === a[pre]) pre++;
|
|
122
|
+
let post = 0;
|
|
123
|
+
while (post < d.length - pre && post < a.length - pre && d[d.length - 1 - post] === a[a.length - 1 - post]) post++;
|
|
124
|
+
const shared = pre + post;
|
|
125
|
+
const longest = Math.max(d.length, a.length) || 1;
|
|
126
|
+
if (shared < longest * 0.4) return null;
|
|
127
|
+
return {
|
|
128
|
+
delStart: pre,
|
|
129
|
+
delEnd: d.length - post,
|
|
130
|
+
addStart: pre,
|
|
131
|
+
addEnd: a.length - post,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Should this preview start open? Small diffs (the routine edit) do, so the
|
|
137
|
+
* change is readable immediately; a big one stays a one-line summary.
|
|
138
|
+
*/
|
|
139
|
+
function defaultOpen(preview) {
|
|
140
|
+
if (!preview || !preview.rows) return false;
|
|
141
|
+
return preview.rows.length <= AUTO_OPEN_ROWS;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The summary row: ` ⎿ Update(src/diff.js) +12 -3 · click to view diff`.
|
|
146
|
+
*
|
|
147
|
+
* @param {object} preview From diff.js's editPreview().
|
|
148
|
+
* @param {object} ctx App context (selects the light/dark diff palette).
|
|
149
|
+
*/
|
|
150
|
+
function diffSummaryRow(preview, ctx) {
|
|
151
|
+
const t = themeOf(ctx);
|
|
152
|
+
const D = diffOf(ctx);
|
|
153
|
+
const bits = [` ${t.gray}${GLYPH.hook} ${RESET}`];
|
|
154
|
+
bits.push(`${t.lavender}${preview.kind}(${preview.short})${RESET}`);
|
|
155
|
+
if (preview.adds) bits.push(`${D.addFg} +${preview.adds}${RESET}`);
|
|
156
|
+
if (preview.dels) bits.push(`${D.delFg} -${preview.dels}${RESET}`);
|
|
157
|
+
if (!preview.adds && !preview.dels) bits.push(`${t.gray} no line changes${RESET}`);
|
|
158
|
+
if (preview.misses) bits.push(`${t.gold} ${preview.misses} edit(s) not applied${RESET}`);
|
|
159
|
+
return bits.join('');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Everything the transcript paints for one edit block: the summary row, plus
|
|
164
|
+
* the colored diff body when open.
|
|
165
|
+
*
|
|
166
|
+
* @param {object} preview From diff.js's editPreview().
|
|
167
|
+
* @param {object} ctx App context (selects the light/dark diff palette).
|
|
168
|
+
* @param {number} cols Terminal width — the add/del backgrounds run the full
|
|
169
|
+
* width, which is what makes the rows read as one block rather than as loose
|
|
170
|
+
* colored text.
|
|
171
|
+
* @param {{open?: boolean}} [opts]
|
|
172
|
+
* @returns {string[]} ANSI rows, each at most `cols` cells wide and RESET-closed.
|
|
173
|
+
*/
|
|
174
|
+
function renderDiffBlock(preview, ctx, cols, opts = {}) {
|
|
175
|
+
const width = Math.max(8, Number(cols) || 80);
|
|
176
|
+
const D = diffOf(ctx);
|
|
177
|
+
const t = themeOf(ctx);
|
|
178
|
+
const out = [clipRow(diffSummaryRow(preview, ctx), width)];
|
|
179
|
+
if (!opts.open || !preview || !preview.rows || !preview.rows.length) return out;
|
|
180
|
+
|
|
181
|
+
const rows = markIntraLine(preview.rows.slice(0, MAX_BLOCK_ROWS).map((r) => Object.assign({}, r)));
|
|
182
|
+
let maxNo = 1;
|
|
183
|
+
for (const r of rows) if (r.no && r.no > maxNo) maxNo = r.no;
|
|
184
|
+
const gutterW = Math.max(2, String(maxNo).length);
|
|
185
|
+
// INDENT + gutter + one separating space + the sign and its space.
|
|
186
|
+
const codeWidth = Math.max(4, width - (INDENT.length + gutterW + 3));
|
|
187
|
+
|
|
188
|
+
for (const r of rows) {
|
|
189
|
+
if (r.marker) {
|
|
190
|
+
out.push(clipRow(`${DIM}${INDENT}… ${r.note == null ? '' : r.note}${RESET}`, width));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const side = r.sign === '-' ? 'del' : r.sign === '+' ? 'add' : 'ctx';
|
|
194
|
+
const bg = side === 'del' ? D.delBg : side === 'add' ? D.addBg : '';
|
|
195
|
+
const hiBg = side === 'del' ? D.delHiBg : D.addHiBg;
|
|
196
|
+
const hiFg = side === 'del' ? D.delHiFg : D.addHiFg;
|
|
197
|
+
const fg = side === 'del' ? D.delFg : side === 'add' ? D.addFg : DIM;
|
|
198
|
+
|
|
199
|
+
const lead = `${bg}${D.gutter}${INDENT}${String(r.no == null ? '' : r.no).padStart(gutterW)} ${RESET}`;
|
|
200
|
+
const sign = `${bg}${fg}${r.sign === ' ' ? ' ' : r.sign} ${RESET}`;
|
|
201
|
+
// Clip the CODE, never the finished row: clipping the painted string would
|
|
202
|
+
// count escape bytes as cells and could also cut mid-sequence, leaving the
|
|
203
|
+
// terminal in the add/del background for the rest of the scrollback.
|
|
204
|
+
const body = codeRow(clip(String(r.text == null ? '' : r.text), codeWidth), bg, hiBg, hiFg, D, r.hi);
|
|
205
|
+
const used = w(`${INDENT}${String(r.no == null ? '' : r.no).padStart(gutterW)} `) + 2 + w(clip(String(r.text == null ? '' : r.text), codeWidth));
|
|
206
|
+
const fill = bg && used < width ? `${bg}${' '.repeat(width - used)}${RESET}` : '';
|
|
207
|
+
out.push(lead + sign + body + fill + RESET);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const hidden = preview.rows.length - MAX_BLOCK_ROWS;
|
|
211
|
+
if (hidden > 0) out.push(clipRow(`${DIM}${INDENT}… ${hidden} more diff lines${RESET}`, width));
|
|
212
|
+
if (preview.truncated) {
|
|
213
|
+
out.push(clipRow(`${DIM}${INDENT}… diff truncated (file too large to compare in full)${RESET}`, width));
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Colored code tokens for one diff row, with the changed slice highlighted. */
|
|
219
|
+
function codeRow(text, bg, hiBg, hiFg, D, hi) {
|
|
220
|
+
const out = [];
|
|
221
|
+
let idx = 0;
|
|
222
|
+
for (const tk of highlightLine(text, D)) {
|
|
223
|
+
const chars = [...tk.t];
|
|
224
|
+
const start = idx;
|
|
225
|
+
const end = idx + chars.length;
|
|
226
|
+
idx = end;
|
|
227
|
+
if (!hi || end <= hi.start || start >= hi.end) {
|
|
228
|
+
out.push(`${bg}${tk.c}${tk.t}`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const a = Math.max(hi.start, start) - start;
|
|
232
|
+
const b = Math.min(hi.end, end) - start;
|
|
233
|
+
if (a > 0) out.push(`${bg}${tk.c}${chars.slice(0, a).join('')}`);
|
|
234
|
+
if (b > a) out.push(`${hiBg}${hiFg}${chars.slice(a, b).join('')}`);
|
|
235
|
+
if (b < chars.length) out.push(`${bg}${tk.c}${chars.slice(b).join('')}`);
|
|
236
|
+
}
|
|
237
|
+
return out.join('');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Clip a painted row to `width` cells, measuring only its visible text. */
|
|
241
|
+
function clipRow(row, width) {
|
|
242
|
+
if (w(row) <= width) return row;
|
|
243
|
+
// Rebuild from the plain text so the escapes stay paired with the cells that
|
|
244
|
+
// survive the cut; the last segment ends with RESET below.
|
|
245
|
+
return clipVisible(row, width) + RESET;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Truncate a painted row to `width` visible cells, keeping the escape
|
|
250
|
+
* sequences it passes and never splitting one. Reuse the per-character width
|
|
251
|
+
* rule that `w()`/`clip()` use so a CJK or emoji cell can't be cut in half.
|
|
252
|
+
*/
|
|
253
|
+
function clipVisible(row, width) {
|
|
254
|
+
let used = 0;
|
|
255
|
+
let out = '';
|
|
256
|
+
let i = 0;
|
|
257
|
+
const s = String(row);
|
|
258
|
+
while (i < s.length) {
|
|
259
|
+
if (s[i] === '\x1b' && s[i + 1] === '[') {
|
|
260
|
+
const close = s.indexOf('m', i);
|
|
261
|
+
if (close === -1) break;
|
|
262
|
+
out += s.slice(i, close + 1);
|
|
263
|
+
i = close + 1;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const cp = s.codePointAt(i);
|
|
267
|
+
const ch = String.fromCodePoint(cp);
|
|
268
|
+
i += ch.length;
|
|
269
|
+
const cw = w(ch);
|
|
270
|
+
if (used + cw > width) break;
|
|
271
|
+
out += ch;
|
|
272
|
+
used += cw;
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
module.exports = {
|
|
278
|
+
AUTO_OPEN_ROWS,
|
|
279
|
+
MAX_BLOCK_ROWS,
|
|
280
|
+
INDENT,
|
|
281
|
+
defaultOpen,
|
|
282
|
+
highlightLine,
|
|
283
|
+
markIntraLine,
|
|
284
|
+
diffSummaryRow,
|
|
285
|
+
renderDiffBlock,
|
|
286
|
+
};
|
package/src/events.js
CHANGED
|
@@ -168,10 +168,13 @@ function feed(c) {
|
|
|
168
168
|
seq += c;
|
|
169
169
|
if (/[A-Za-z~]/.test(c)) {
|
|
170
170
|
clearTimeout(escTimer);
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
171
|
+
const mouse = parseSgrMouse(seq);
|
|
172
|
+
if (mouse) {
|
|
173
173
|
seq = '';
|
|
174
|
-
|
|
174
|
+
// Wheel decodes to a direction string; a left press to a {name,col,row}
|
|
175
|
+
// event. Both are returned by parseSgrMouse so the caller stays a
|
|
176
|
+
// one-line dispatch.
|
|
177
|
+
dispatch(typeof mouse === 'string' ? { name: 'wheel', dir: mouse } : mouse);
|
|
175
178
|
return;
|
|
176
179
|
}
|
|
177
180
|
const k = decodeEscSequence(seq);
|
|
@@ -185,19 +188,27 @@ function feed(c) {
|
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
/**
|
|
188
|
-
* SGR mouse
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
191
|
+
* SGR mouse event → decoded value. Wheel codes 64/65 decode to 'up'/'down'
|
|
192
|
+
* (modifier bits masked off so Shift+wheel still scrolls). A left button PRESS
|
|
193
|
+
* decodes to `{name:'click', col, row}` with 1-based coordinates from the
|
|
194
|
+
* payload. Everything else — a release (`m`), a drag, another button, or a
|
|
195
|
+
* horizontal wheel — returns null, and the caller's CSI decoder ignores it, so
|
|
196
|
+
* stray mouse bytes can neither type into the editor nor abort a turn.
|
|
192
197
|
*/
|
|
193
198
|
function parseSgrMouse(seq) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const code = parseInt(
|
|
199
|
+
const m = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(seq);
|
|
200
|
+
if (!m) return null;
|
|
201
|
+
const code = parseInt(m[1], 10);
|
|
197
202
|
if (!Number.isFinite(code)) return null;
|
|
198
203
|
const base = code & ~0b111100;
|
|
199
204
|
if (base === 64) return 'up';
|
|
200
205
|
if (base === 65) return 'down';
|
|
206
|
+
// Left press only: button bits 0-1 clear, wheel bits (0b1100000) clear, no
|
|
207
|
+
// motion bit, and the `M` (press) terminator — a release or drag toggles
|
|
208
|
+
// nothing.
|
|
209
|
+
if (m[4] === 'M' && (code & 3) === 0 && (code & 0b1100000) === 0 && (code & 0b100000) === 0) {
|
|
210
|
+
return { name: 'click', col: parseInt(m[2], 10), row: parseInt(m[3], 10) };
|
|
211
|
+
}
|
|
201
212
|
return null;
|
|
202
213
|
}
|
|
203
214
|
|
package/src/panels.js
CHANGED
|
@@ -186,7 +186,11 @@ function buildHelp(commands, ctx = {}) {
|
|
|
186
186
|
|
|
187
187
|
// ── /status ──────────────────────────────────────────────────────────────────
|
|
188
188
|
|
|
189
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* @param {object} state session state (see the module header in the task)
|
|
191
|
+
* @param {{light?: boolean, caps?: Array<[string,string]>}} [ctx] `caps` is the
|
|
192
|
+
* `caps.describe()` row list, rendered as the terminal-capability rows.
|
|
193
|
+
*/
|
|
190
194
|
function buildStatus(state, ctx = {}) {
|
|
191
195
|
const t = themeOf(ctx);
|
|
192
196
|
const s = obj(state);
|
|
@@ -219,6 +223,21 @@ function buildStatus(state, ctx = {}) {
|
|
|
219
223
|
if (s.version != null) add('Version', 'v' + str(s.version));
|
|
220
224
|
add('Node', process.version);
|
|
221
225
|
add('Platform', `${process.platform} ${process.arch}`);
|
|
226
|
+
// Terminal capabilities, read off the same `caps.describe()` rows `/terminal`
|
|
227
|
+
// renders — passed in on `ctx` so this builder stays pure (no caps.js require)
|
|
228
|
+
// and the two reports cannot drift. Absent in tests and headless runs; `add()`
|
|
229
|
+
// skips empty values, so the rows simply do not appear.
|
|
230
|
+
const capsRows = Array.isArray(ctx.caps) ? ctx.caps : [];
|
|
231
|
+
const cap = (k) => {
|
|
232
|
+
const hit = capsRows.find((r) => Array.isArray(r) && String(r[0]) === k);
|
|
233
|
+
return hit ? str(hit[1]) : '';
|
|
234
|
+
};
|
|
235
|
+
add('Terminal', cap('terminal'));
|
|
236
|
+
add('Mark', cap('mark'));
|
|
237
|
+
add('Star', cap('star'));
|
|
238
|
+
add('Color', cap('color'));
|
|
239
|
+
add('Control', cap('control'));
|
|
240
|
+
add('Frame', cap('size'));
|
|
222
241
|
|
|
223
242
|
for (const l of kv(t, rows, { keyStyle: t.gray, valStyle: t.white })) lines.push(l);
|
|
224
243
|
|
|
@@ -601,6 +620,44 @@ function buildTerminalSetup(state, ctx = {}) {
|
|
|
601
620
|
return lines;
|
|
602
621
|
}
|
|
603
622
|
|
|
623
|
+
// ── /terminal ────────────────────────────────────────────────────────────────
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* The capability report — the same rows `aegiscode --terminal` prints, because
|
|
627
|
+
* both render `caps.describe()`. Taking the rows as an argument keeps this
|
|
628
|
+
* builder pure (see the module header): no `require('./caps.js')` here, so
|
|
629
|
+
* `/terminal` and the launcher flag cannot drift into two different reports.
|
|
630
|
+
*
|
|
631
|
+
* This is the panel the CLI help promised at `aegiscode.js:63` ("`/terminal
|
|
632
|
+
* ascii` toggles it mid-session") long before the command existed.
|
|
633
|
+
*
|
|
634
|
+
* @param {Array<[string,string]>} report rows from `caps.describe()`
|
|
635
|
+
* @param {{pinned?: boolean, light?: boolean}} [ctx] `pinned` adds the warning
|
|
636
|
+
* shown after `/terminal width`, which turns off resize re-reads.
|
|
637
|
+
*/
|
|
638
|
+
function buildTerminalCaps(report, ctx = {}) {
|
|
639
|
+
const t = themeOf(ctx);
|
|
640
|
+
const rows = (Array.isArray(report) ? report : [])
|
|
641
|
+
.filter((r) => Array.isArray(r) && r.length >= 2)
|
|
642
|
+
.map(([k, v]) => [str(k), str(v)]);
|
|
643
|
+
const lines = [];
|
|
644
|
+
lines.push([span(t.gold + BOLD, 'Terminal capabilities'), span(BOLD_OFF, '')]);
|
|
645
|
+
if (!rows.length) {
|
|
646
|
+
lines.push([span('', ' '), span(t.gray, 'No capability report available.')]);
|
|
647
|
+
return lines;
|
|
648
|
+
}
|
|
649
|
+
for (const l of kv(t, rows, { keyStyle: t.white, valStyle: t.gray })) lines.push(l);
|
|
650
|
+
lines.push([span('', '')]);
|
|
651
|
+
if (ctx && ctx.pinned) {
|
|
652
|
+
lines.push([span(t.coral, GLYPH.warn), span(t.gold, ' width is pinned — resizes are ignored until /terminal auto')]);
|
|
653
|
+
lines.push([span('', '')]);
|
|
654
|
+
}
|
|
655
|
+
lines.push([span(t.gray, 'Override: /terminal ascii | unicode | color | no-color | star <native|narrow>')]);
|
|
656
|
+
lines.push([span(t.gray, ' /terminal width <cols> | auto | status')]);
|
|
657
|
+
lines.push([span(t.gray, 'At launch: --ascii --unicode --no-color --width <cols> --terminal')]);
|
|
658
|
+
return lines;
|
|
659
|
+
}
|
|
660
|
+
|
|
604
661
|
function buildPRs(ghOutput, ctx = {}) {
|
|
605
662
|
const t = themeOf(ctx);
|
|
606
663
|
const lines = [];
|
|
@@ -1142,6 +1199,7 @@ module.exports = {
|
|
|
1142
1199
|
buildOnboarding,
|
|
1143
1200
|
buildShellCompletion,
|
|
1144
1201
|
buildTerminalSetup,
|
|
1202
|
+
buildTerminalCaps,
|
|
1145
1203
|
buildPRs,
|
|
1146
1204
|
buildBenchmark,
|
|
1147
1205
|
buildWaifu,
|
package/src/render.js
CHANGED
|
@@ -34,6 +34,7 @@ const {
|
|
|
34
34
|
const { WELCOME_TITLE, WELCOME_BACK, TAGLINE, STAR, stencilGlyph, welcomeArtParts } = require('./art.js');
|
|
35
35
|
const { w, pad, padStart, wrapBlock, clip, span } = require('./screen.js');
|
|
36
36
|
const { fmtTokens, fmtEur, fmtElapsed } = require('./format.js');
|
|
37
|
+
const { renderDiffBlock } = require('./diffview.js');
|
|
37
38
|
|
|
38
39
|
// Guarded: a concurrent workstream owns ./markdown.js.
|
|
39
40
|
let markdown = null;
|
|
@@ -44,10 +45,15 @@ try {
|
|
|
44
45
|
markdown = null;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
// The failed-check `✗` and warning `⚠` marks now come from the shared glyph
|
|
49
|
+
// table (`GLYPH.err` / `GLYPH.warn`), which downgrades them to `x` / `!` on a
|
|
50
|
+
// terminal with no Unicode claim. They used to be two file-local constants
|
|
51
|
+
// here, so a legacy Windows console printed U+2717 and U+26A0 into a font that
|
|
52
|
+
// has neither — the notice rows were the last place the ASCII pass could not
|
|
53
|
+
// reach. Read them at CALL time: `GLYPH` is mutated in place by `/terminal`, so
|
|
54
|
+
// a value captured at require time would survive the switch.
|
|
55
|
+
const errMark = () => GLYPH.err;
|
|
56
|
+
const warnMark = () => GLYPH.warn;
|
|
51
57
|
|
|
52
58
|
const fg = (t, c) => `${c}`;
|
|
53
59
|
const bg = (c) => BG(...c);
|
|
@@ -124,8 +130,12 @@ function renderBanner(ctx, info = {}) {
|
|
|
124
130
|
const width = Math.max(20, Number(info.width) || 80);
|
|
125
131
|
const lines = [];
|
|
126
132
|
|
|
127
|
-
// Full-width gold header rule
|
|
128
|
-
|
|
133
|
+
// Full-width gold header rule — the heavy/light pair from the shared glyph
|
|
134
|
+
// table, so the frame is `━───━` on a Unicode terminal and `=---=` on a
|
|
135
|
+
// legacy console instead of printing two box-drawing runes it cannot draw.
|
|
136
|
+
lines.push(
|
|
137
|
+
`${t.gold}${GLYPH.ruleHeavy}${GLYPH.rule.repeat(Math.max(0, width - 2))}${GLYPH.ruleHeavy}${RESET}`
|
|
138
|
+
);
|
|
129
139
|
lines.push('');
|
|
130
140
|
|
|
131
141
|
const parts = welcomeArtParts(width);
|
|
@@ -256,7 +266,7 @@ function renderTurn(ctx, turn, width = 80) {
|
|
|
256
266
|
// turn.ok is only known once the call has actually run (the agent loop's
|
|
257
267
|
// tool-activity event fires after execution); undefined means "no result
|
|
258
268
|
// yet to report" (the plain registry-tool path, which never set it).
|
|
259
|
-
const status = turn.ok === undefined ? '' : turn.ok ? ` ${t.green}
|
|
269
|
+
const status = turn.ok === undefined ? '' : turn.ok ? ` ${t.green}${GLYPH.check}${RESET}` : ` ${t.red}${errMark()}${RESET}`;
|
|
260
270
|
lines.push(`${t.white}${GLYPH.block}${RESET} ${t.gray}${turn.label || 'tool'}${RESET}${status}`);
|
|
261
271
|
const args =
|
|
262
272
|
turn.args == null
|
|
@@ -264,9 +274,19 @@ function renderTurn(ctx, turn, width = 80) {
|
|
|
264
274
|
: typeof turn.args === 'string'
|
|
265
275
|
? turn.args
|
|
266
276
|
: JSON.stringify(turn.args);
|
|
267
|
-
|
|
277
|
+
// An editFile/writeFile turn carries a diff preview (app.js builds it from
|
|
278
|
+
// the tool call's `run` frame). Paint the colored block instead of the gray
|
|
279
|
+
// `$ {args}` row, so an edit shows *what* changed, not just that something
|
|
280
|
+
// did. The summary row is unconditional; the body follows when the block is
|
|
281
|
+
// open, which the click handler toggles. The `$ args` row stays the fallback
|
|
282
|
+
// for every non-edit tool and for a turn with no preview.
|
|
283
|
+
if (turn.diff) {
|
|
284
|
+
lines.push(...renderDiffBlock(turn.diff, ctx, width, { open: !!turn.diffOpen }));
|
|
285
|
+
} else if (args) {
|
|
286
|
+
lines.push(` ${t.gray}${GLYPH.hook} $ ${clip(args, Math.max(0, width - 6))}${RESET}`);
|
|
287
|
+
}
|
|
268
288
|
} else if (role === 'error') {
|
|
269
|
-
lines.push(`${t.red}${
|
|
289
|
+
lines.push(`${t.red}${errMark()} ${text}${RESET}`);
|
|
270
290
|
} else {
|
|
271
291
|
for (const l of wrapBlock(text, Math.max(8, width - 2))) lines.push(`${t.white}${l}${RESET}`);
|
|
272
292
|
}
|
|
@@ -356,9 +376,10 @@ function renderHeading(ctx, text, width = 80) {
|
|
|
356
376
|
const label = ` ${text} `;
|
|
357
377
|
const fill = Math.max(0, width - w(label));
|
|
358
378
|
const left = Math.floor(fill / 2);
|
|
379
|
+
const rule = GLYPH.rule;
|
|
359
380
|
return (
|
|
360
|
-
`${t.gray}${
|
|
361
|
-
`${t.gray}${
|
|
381
|
+
`${t.gray}${rule.repeat(left)}${RESET}${t.gold}${BOLD}${label}${RESET}` +
|
|
382
|
+
`${t.gray}${rule.repeat(Math.max(0, fill - left))}${RESET}`
|
|
362
383
|
);
|
|
363
384
|
}
|
|
364
385
|
|
|
@@ -400,18 +421,19 @@ function renderApproval(ctx, info = {}, width = 80) {
|
|
|
400
421
|
}
|
|
401
422
|
|
|
402
423
|
/** A transient notice. Kinds map gray / coral / red / green with the matching
|
|
403
|
-
* glyph: info `·`, warn `⚠`, error `✗`, ok
|
|
424
|
+
* glyph: info `·`, warn `⚠`, error `✗`, ok `✔` — all four read from the shared
|
|
425
|
+
* table at call time, so `--ascii` swaps them along with the rest of the UI. */
|
|
404
426
|
const NOTICE = {
|
|
405
|
-
info: ['gray', GLYPH.bullet],
|
|
406
|
-
warn: ['coral',
|
|
407
|
-
error: ['red',
|
|
408
|
-
ok: ['green', GLYPH.check],
|
|
427
|
+
info: ['gray', () => GLYPH.bullet],
|
|
428
|
+
warn: ['coral', warnMark],
|
|
429
|
+
error: ['red', errMark],
|
|
430
|
+
ok: ['green', () => GLYPH.check],
|
|
409
431
|
};
|
|
410
432
|
|
|
411
433
|
function renderNotice(ctx, kind, text) {
|
|
412
434
|
const t = themeOf(ctx);
|
|
413
435
|
const [token, mark] = NOTICE[kind] || NOTICE.info;
|
|
414
|
-
return `${t[token]}${mark} ${text}${RESET}`;
|
|
436
|
+
return `${t[token]}${mark()} ${text}${RESET}`;
|
|
415
437
|
}
|
|
416
438
|
|
|
417
439
|
module.exports = {
|
package/src/screen.js
CHANGED
|
@@ -27,16 +27,14 @@
|
|
|
27
27
|
|
|
28
28
|
const ANSI_RE = /\x1b\[[0-9;]*[A-Za-z]/g;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
/** Cell width of one code point. */
|
|
39
|
-
const cwidth = (ch) => (RE_ZERO.test(ch) ? 0 : RE_WIDE.test(ch) ? 2 : 1);
|
|
30
|
+
const { caps, cellWidth } = require('./caps.js');
|
|
31
|
+
|
|
32
|
+
// Real terminal cell width (wcwidth-style) comes from `caps.js`, which is the
|
|
33
|
+
// one place the table lives: a platform that draws a rune two cells wide that
|
|
34
|
+
// wcwidth does not know about (`AEGIS_WIDE_RUNES=✦`) has to shift *every* width
|
|
35
|
+
// decision at once, and a second copy of the table here is exactly how the
|
|
36
|
+
// transcript pads to one width while the overlay pads to another.
|
|
37
|
+
const cwidth = (ch) => cellWidth(ch);
|
|
40
38
|
|
|
41
39
|
function stripAnsi(s) {
|
|
42
40
|
return String(s).replace(ANSI_RE, '');
|
|
@@ -47,10 +45,7 @@ function stripAnsi(s) {
|
|
|
47
45
|
* previous revision so callers measuring render output stay correct. */
|
|
48
46
|
function w(s) {
|
|
49
47
|
let n = 0;
|
|
50
|
-
for (const ch of stripAnsi(s))
|
|
51
|
-
if (RE_ZERO.test(ch)) continue;
|
|
52
|
-
n += RE_WIDE.test(ch) ? 2 : 1;
|
|
53
|
-
}
|
|
48
|
+
for (const ch of stripAnsi(s)) n += cwidth(ch);
|
|
54
49
|
return n;
|
|
55
50
|
}
|
|
56
51
|
|
|
@@ -127,11 +122,15 @@ function padLine(line, width) {
|
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
/** Term size, clamped so a zero-column report (CI, redirected stdout) still
|
|
130
|
-
* yields a paintable frame.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
* yields a paintable frame. Resolved through `caps.js` so `AEGIS_WIDTH` and
|
|
126
|
+
* `--width` reach every caller — the overlays used to read
|
|
127
|
+
* `process.stdout.columns` directly, which is 0 on a redirected run and left
|
|
128
|
+
* the frame 80 columns wide while the transcript had already been told
|
|
129
|
+
* otherwise. */
|
|
130
|
+
const getSize = () => {
|
|
131
|
+
const c = caps();
|
|
132
|
+
return { cols: c.cols, rows: c.rows };
|
|
133
|
+
};
|
|
135
134
|
|
|
136
135
|
// ── wrapping (plain strings; the string renderers use these) ─────────────────
|
|
137
136
|
|
|
@@ -277,7 +276,8 @@ function paintFrom(lines, startRow) {
|
|
|
277
276
|
}
|
|
278
277
|
|
|
279
278
|
function termWidth(fallback = 80) {
|
|
280
|
-
|
|
279
|
+
const { cols } = getSize();
|
|
280
|
+
return cols > 0 ? cols : Math.max(20, fallback);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|