aegiscode 6.7.0 → 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/src/commands.js CHANGED
@@ -45,6 +45,9 @@ const { execSync } = require('node:child_process');
45
45
 
46
46
  const { span } = require('./screen.js');
47
47
  const { C, BOLD, BOLD_OFF } = require('./theme.js');
48
+ // `caps.js` is dependency-free (it requires nothing), so this cannot cycle the
49
+ // way a `theme.js` → `art.js` → `theme.js` require would.
50
+ const { caps, setCaps, resetCaps, describe } = require('./caps.js');
48
51
  const panels = require('./panels.js');
49
52
  const overlays = require('./overlays.js');
50
53
  const {
@@ -890,7 +893,7 @@ const COMMANDS = [
890
893
  // This client's /status surface is the account-status tool (the same
891
894
  // tool /aegis-status names) plus the local session panel below it.
892
895
  await c.runTool('aegis_status', {});
893
- panel(c, panels.buildStatus(c.state(), c.ctx));
896
+ panel(c, panels.buildStatus(c.state(), Object.assign({}, c.ctx, { caps: describe() })));
894
897
  c.render();
895
898
  return true;
896
899
  },
@@ -926,6 +929,87 @@ const COMMANDS = [
926
929
  return true;
927
930
  },
928
931
  },
932
+ {
933
+ name: 'terminal', aliases: ['tty'], args: ['mode', 'mode2'],
934
+ hint: '[ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]', category: 'model',
935
+ desc: 'Show or override how this terminal is drawn (mark, colour, width)',
936
+ handler: async (c, args) => {
937
+ // The same report `aegiscode --terminal` prints, and the same switch the
938
+ // `--ascii` flag sets — so a session can be re-styled without restarting
939
+ // when a paste from PowerShell turns out to render badly in this host.
940
+ // `args` is positional (app.js `parseArgs`), so the second token is
941
+ // `mode2` for both `star narrow` and `width 100`.
942
+ const sub = (args.mode || '').toLowerCase();
943
+ const second = args.mode2 != null ? String(args.mode2).trim() : '';
944
+
945
+ if (sub === '' || sub === 'status') {
946
+ panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
947
+ c.render();
948
+ return true;
949
+ }
950
+
951
+ // The patch pins every *axis* but never the frame: `cols`/`rows` must stay
952
+ // absent so `setCaps` leaves `sizePinned` false and a live resize keeps
953
+ // re-reading the stream (see caps.js). Copying the whole caps object here
954
+ // would freeze the width at the moment the command ran.
955
+ const cur = caps();
956
+ const axes = {
957
+ glyphs: cur.glyphs, face: cur.face, star: cur.star,
958
+ depth: cur.depth, vt: cur.vt, wideRunes: cur.wideRunes,
959
+ reasons: Object.assign({}, cur.reasons),
960
+ };
961
+
962
+ if (sub === 'auto') {
963
+ // Drop every override, including any the session inherited from the
964
+ // flags/env it was started with — "auto" means "probe again", not
965
+ // "restore what you were launched with".
966
+ resetCaps();
967
+ note(c, 'Terminal: auto — capabilities re-probed from the environment.');
968
+ c.render();
969
+ return true;
970
+ }
971
+ // `why` in the report must describe what the session is actually doing,
972
+ // not the probe it started from: after `/terminal ascii` on a truecolor
973
+ // host, `why: TERM=xterm-256color` would contradict `mark: ascii`.
974
+ if (sub === 'ascii' || sub === 'unicode') {
975
+ axes.glyphs = sub === 'ascii' ? 'ascii' : 'unicode';
976
+ axes.face = sub === 'ascii' ? 'edges' : 'native';
977
+ axes.star = sub === 'ascii' ? 'narrow' : 'native';
978
+ if (axes.reasons) axes.reasons.glyphs = `/terminal ${sub}`;
979
+ } else if (sub === 'color' || sub === 'no-color' || sub === 'nocolor') {
980
+ axes.depth = sub === 'color' ? 24 : 0;
981
+ if (axes.reasons) axes.reasons.depth = `/terminal ${sub}`;
982
+ } else if (sub === 'star') {
983
+ const want = second.toLowerCase();
984
+ if (!['native', 'narrow'].includes(want)) { note(c, 'Usage: /terminal star <native|narrow>'); c.render(); return true; }
985
+ axes.star = want;
986
+ if (axes.reasons) axes.reasons.star = `/terminal star ${want}`;
987
+ } else if (sub === 'width') {
988
+ // A pinned width is a frame override, so it goes in as cols — the one
989
+ // key that deliberately trips `sizePinned`.
990
+ const width = Number(second);
991
+ if (!Number.isFinite(width) || width < 20) { note(c, 'Usage: /terminal width <cols> (>= 20)'); c.render(); return true; }
992
+ setCaps(Object.assign({}, axes, { cols: Math.round(width) }));
993
+ note(c, `Terminal: width pinned to ${Math.round(width)} columns.`);
994
+ panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
995
+ c.render();
996
+ return true;
997
+ } else {
998
+ note(c, 'Usage: /terminal [ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]');
999
+ c.render();
1000
+ return true;
1001
+ }
1002
+
1003
+ setCaps(axes);
1004
+ panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
1005
+ // Already-painted scrollback keeps the glyphs it was drawn with — a
1006
+ // terminal has no way to rewrite what it has scrolled past. Everything
1007
+ // from here on (and this viewport) uses the new mark.
1008
+ note(c, 'Terminal updated — the current viewport is redrawn; text already scrolled past keeps its old glyphs.');
1009
+ c.render();
1010
+ return true;
1011
+ },
1012
+ },
929
1013
  {
930
1014
  name: 'version', aliases: ['v'], hint: '', category: 'session',
931
1015
  desc: 'Show version',
package/src/panels.js CHANGED
@@ -186,7 +186,11 @@ function buildHelp(commands, ctx = {}) {
186
186
 
187
187
  // ── /status ──────────────────────────────────────────────────────────────────
188
188
 
189
- /** @param {object} state session state (see the module header in the task) */
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
@@ -45,10 +45,15 @@ try {
45
45
  markdown = null;
46
46
  }
47
47
 
48
- /** Error mark — the reference's failed-check glyph (theme.js has no GLYPH.err). */
49
- const ERR = '✗';
50
- /** Warning mark — the reference's ⚠ (theme.js has no GLYPH.warn). */
51
- const WARN = '⚠';
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;
52
57
 
53
58
  const fg = (t, c) => `${c}`;
54
59
  const bg = (c) => BG(...c);
@@ -125,8 +130,12 @@ function renderBanner(ctx, info = {}) {
125
130
  const width = Math.max(20, Number(info.width) || 80);
126
131
  const lines = [];
127
132
 
128
- // Full-width gold header rule.
129
- lines.push(`${t.gold}━${'─'.repeat(Math.max(0, width - 2))}━${RESET}`);
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
+ );
130
139
  lines.push('');
131
140
 
132
141
  const parts = welcomeArtParts(width);
@@ -257,7 +266,7 @@ function renderTurn(ctx, turn, width = 80) {
257
266
  // turn.ok is only known once the call has actually run (the agent loop's
258
267
  // tool-activity event fires after execution); undefined means "no result
259
268
  // yet to report" (the plain registry-tool path, which never set it).
260
- const status = turn.ok === undefined ? '' : turn.ok ? ` ${t.green}✓${RESET}` : ` ${t.red}${ERR}${RESET}`;
269
+ const status = turn.ok === undefined ? '' : turn.ok ? ` ${t.green}${GLYPH.check}${RESET}` : ` ${t.red}${errMark()}${RESET}`;
261
270
  lines.push(`${t.white}${GLYPH.block}${RESET} ${t.gray}${turn.label || 'tool'}${RESET}${status}`);
262
271
  const args =
263
272
  turn.args == null
@@ -277,7 +286,7 @@ function renderTurn(ctx, turn, width = 80) {
277
286
  lines.push(` ${t.gray}${GLYPH.hook} $ ${clip(args, Math.max(0, width - 6))}${RESET}`);
278
287
  }
279
288
  } else if (role === 'error') {
280
- lines.push(`${t.red}${ERR} ${text}${RESET}`);
289
+ lines.push(`${t.red}${errMark()} ${text}${RESET}`);
281
290
  } else {
282
291
  for (const l of wrapBlock(text, Math.max(8, width - 2))) lines.push(`${t.white}${l}${RESET}`);
283
292
  }
@@ -367,9 +376,10 @@ function renderHeading(ctx, text, width = 80) {
367
376
  const label = ` ${text} `;
368
377
  const fill = Math.max(0, width - w(label));
369
378
  const left = Math.floor(fill / 2);
379
+ const rule = GLYPH.rule;
370
380
  return (
371
- `${t.gray}${'─'.repeat(left)}${RESET}${t.gold}${BOLD}${label}${RESET}` +
372
- `${t.gray}${'─'.repeat(Math.max(0, fill - left))}${RESET}`
381
+ `${t.gray}${rule.repeat(left)}${RESET}${t.gold}${BOLD}${label}${RESET}` +
382
+ `${t.gray}${rule.repeat(Math.max(0, fill - left))}${RESET}`
373
383
  );
374
384
  }
375
385
 
@@ -411,18 +421,19 @@ function renderApproval(ctx, info = {}, width = 80) {
411
421
  }
412
422
 
413
423
  /** A transient notice. Kinds map gray / coral / red / green with the matching
414
- * 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. */
415
426
  const NOTICE = {
416
- info: ['gray', GLYPH.bullet],
417
- warn: ['coral', WARN],
418
- error: ['red', ERR],
419
- ok: ['green', GLYPH.check],
427
+ info: ['gray', () => GLYPH.bullet],
428
+ warn: ['coral', warnMark],
429
+ error: ['red', errMark],
430
+ ok: ['green', () => GLYPH.check],
420
431
  };
421
432
 
422
433
  function renderNotice(ctx, kind, text) {
423
434
  const t = themeOf(ctx);
424
435
  const [token, mark] = NOTICE[kind] || NOTICE.info;
425
- return `${t[token]}${mark} ${text}${RESET}`;
436
+ return `${t[token]}${mark()} ${text}${RESET}`;
426
437
  }
427
438
 
428
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
- // Real terminal cell width (wcwidth-style). Combining marks and variation
31
- // selectors occupy no cell; CJK fullwidth forms and emoji-presentation glyphs
32
- // occupy two; everything else one. A plain code-point count misaligns every
33
- // width decision — padding, wrapping, cursor placement — the moment a line
34
- // contains CJK or emoji, because the terminal draws those two cells wide.
35
- // (Regexes copied verbatim from aegiscodex-dev/src/screen.js.)
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
- /** 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
- const getSize = () => ({
132
- cols: Math.max(20, (process.stdout && process.stdout.columns) || 80),
133
- rows: Math.max(5, (process.stdout && process.stdout.rows) || 24),
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
- return Math.max(20, (process.stdout && process.stdout.columns) || fallback);
279
+ const { cols } = getSize();
280
+ return cols > 0 ? cols : Math.max(20, fallback);
281
281
  }
282
282
 
283
283
  /**