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/src/art.js CHANGED
@@ -1,5 +1,22 @@
1
1
  'use strict';
2
2
 
3
+ const { caps, detect, cells, padCells } = require('./caps.js');
4
+
5
+ /**
6
+ * Resolve a stencil target — nothing at all, a `process.platform` name, or a
7
+ * whole caps object — to the capabilities that decide the pass.
8
+ *
9
+ * A platform *name* is still accepted because it is the shape a test wants when
10
+ * it is asking "what would the mark look like on that host?"; it is resolved
11
+ * through the same `detect()` the live process uses, so a platform string is a
12
+ * convenience alias for a capability probe, never a second decision path.
13
+ */
14
+ function capsOf(target) {
15
+ if (!target) return caps();
16
+ if (typeof target === 'string') return detect(process.env, process.stdout, target);
17
+ return target;
18
+ }
19
+
3
20
  /**
4
21
  * Welcome art — the aegiscodex-dev mark, adopted wholesale.
5
22
  *
@@ -13,6 +30,9 @@
13
30
  * `joinSideBySide()` stay exact. `test/cli-conformance.test.mjs` asserts both
14
31
  * that property and that these rows still match aegiscodex-dev's source, so the
15
32
  * mark can't drift.
33
+ *
34
+ * Which pass is applied is decided by the terminal's capabilities, not by
35
+ * `process.platform` — see the portability section below and `caps.js`.
16
36
  */
17
37
 
18
38
  // The mascot face — exact glyphs from the binary (msS template).
@@ -84,100 +104,137 @@ const WELCOME_BACK = 'Welcome back!';
84
104
  const TAGLINE = 'Cloud brain in your shell.';
85
105
 
86
106
  // ── Terminal portability ─────────────────────────────────────────────────────
87
- // The block-glyph palette and ✦ stars are single-width on Linux terminals, but
88
- // not everywhere: Windows fonts often lack the U+259B..U+259F face edges and
89
- // mangle █▓▒░ entirely; on macOS ✦ renders as a double-width emoji. Each pass
90
- // swaps offending code points 1:1 (same character count per row) so the width
91
- // maths stays exact and the mark keeps its shape.
107
+ // The block-glyph palette and ✦ stars are single-width on most terminals, but
108
+ // not everywhere: a legacy Windows console font lacks the U+259B..U+259F face
109
+ // edges and mangles █▓▒░ entirely; Terminal.app has no quartile edges and
110
+ // renders ✦ through the two-cell emoji fallback. Each pass swaps offending code
111
+ // points 1:1 (same character count per row) so the width maths stays exact and
112
+ // the mark keeps its shape.
113
+ //
114
+ // The pass is keyed on the terminal's CAPABILITIES (`caps.js`), never on
115
+ // `process.platform`. That distinction is the whole point: PowerShell inside
116
+ // Windows Terminal draws this mark exactly as zsh does, and it used to be
117
+ // handed the hyphen-and-hash ASCII version purely because the *process* was
118
+ // win32. The three passes below compose — a Windows VT host needs the star
119
+ // narrow but keeps the native block palette, which no single platform-keyed
120
+ // table could express.
92
121
  //
93
122
  // This table is the ONE stencil source of truth for the product. `theme.js`
94
- // resolves `GLYPH.star` through `stencilGlyph(STAR, platform)` rather than
95
- // carrying its own `'✦' → '*'` rule, and `render.js` builds the mark's tint map
96
- // by stencilling its runes — both had a private copy of the same decision, which
123
+ // resolves `GLYPH.star` through `stencilGlyph(STAR, caps)` rather than carrying
124
+ // its own `'✦' → '*'` rule, and `render.js` builds the mark's tint map by
125
+ // stencilling its runes — both had a private copy of the same decision, which
97
126
  // is how a stencil edit here could leave the star wide on macOS or the whale
98
- // untinted on Windows. `test/cli-art-platform.test.mjs` pins all of it.
127
+ // untinted on Windows. `test/cli-terminal-caps.test.mjs` pins all of it.
99
128
  const STAR = '✦';
100
129
 
130
+ /** The quartile/quadrant face edges — the runes Apple and older Windows fonts lack. */
131
+ const EDGE_RUNES = ['▐', '▛', '▜', '▌', '▝', '▘'];
132
+
133
+ /** Full ASCII pass: the block palette, the face edges, the star, the mid-dot. */
101
134
  const ASCII_STENCIL = new Map([
102
135
  ['█', '#'],
103
136
  ['▓', '@'],
104
137
  ['▒', '='],
105
138
  ['░', '.'],
106
- ['▐', '#'],
107
- ['▛', '#'],
108
- ['▜', '#'],
109
- ['▌', '#'],
110
- ['▝', '#'],
111
- ['▘', '#'],
139
+ ...EDGE_RUNES.map((c) => [c, '#']),
112
140
  [STAR, '*'],
113
141
  ['·', '.'],
114
142
  ]);
115
143
 
116
- const DARWIN_STENCIL = new Map([
117
- ['▐', '#'],
118
- ['▛', '#'],
119
- ['▜', '#'],
120
- ['▌', '#'],
121
- ['▝', '#'],
122
- ['▘', '#'],
123
- [STAR, '*'],
124
- ]);
144
+ /** Unicode pass for fonts that carry █▓▒░ but not the face edges (Apple, old Consolas). */
145
+ const EDGE_STENCIL = new Map(EDGE_RUNES.map((c) => [c, '#']));
125
146
 
126
- /** The platforms this mark has a pass for. Linux needs none (see `stencilFor`). */
127
- const PLATFORMS = ['linux', 'darwin', 'win32'];
147
+ /** ✦ alone: a font that falls back to a *two-cell* emoji glyph for it. */
148
+ const STAR_STENCIL = new Map([[STAR, '*']]);
128
149
 
129
- /** Every pass, keyed by `process.platform`; a platform with no entry is native. */
130
- const STENCILS = { darwin: DARWIN_STENCIL, win32: ASCII_STENCIL };
150
+ /**
151
+ * The named passes. They compose rather than being picked one-of-three: a
152
+ * Windows VT host takes `star` only (native palette, narrow star) and
153
+ * Terminal.app takes `edges` + `star`.
154
+ */
155
+ const STENCILS = { ascii: ASCII_STENCIL, edges: EDGE_STENCIL, star: STAR_STENCIL };
131
156
 
132
157
  /**
133
- * The stencil for a platform, or `null` when its runes need no pass.
134
- * @param {string} platform a `process.platform` string
158
+ * The capability classes this mark has a pass for, and the one that needs none.
159
+ * Kept as a name list so a caller (and the test) can enumerate the matrix
160
+ * without restating the pass table.
135
161
  */
136
- function stencilFor(platform) {
137
- return STENCILS[platform] || null;
162
+ const PASSES = ['native', 'star', 'edges', 'ascii'];
163
+
164
+
165
+ /**
166
+ * The stencil for a terminal, or `null` when its runes need no pass.
167
+ *
168
+ * `glyphs: 'ascii'` is the full pass and subsumes the others — a terminal with
169
+ * no block glyphs certainly has no quartile edges and no ✦ either, so it must
170
+ * not be handed a partial map that leaves ░▒▓◧ on screen.
171
+ *
172
+ * @param {string|object|null} [target] a caps object, a `process.platform` name,
173
+ * or nothing for the live process's resolved capabilities.
174
+ * @returns {Map<string,string>|null}
175
+ */
176
+ function stencilFor(target = null) {
177
+ const c = capsOf(target);
178
+ if (c.glyphs === 'ascii') return ASCII_STENCIL;
179
+ const pass = new Map();
180
+ if (c.face === 'edges') for (const [k, v] of EDGE_STENCIL) pass.set(k, v);
181
+ if (c.star === 'narrow') for (const [k, v] of STAR_STENCIL) pass.set(k, v);
182
+ return pass.size ? pass : null;
138
183
  }
139
184
 
140
185
  /**
141
- * One rune as `platform` renders it — the identity when that platform is native.
186
+ * One rune as the terminal renders it — the identity when it is native.
142
187
  * Exported so `theme.js`'s glyph table and `render.js`'s tint map are derived
143
188
  * from the stencil instead of restating it.
144
189
  * @param {string} ch
145
- * @param {string} [platform]
190
+ * @param {string|object} [target] a caps object, a platform name, or nothing
146
191
  */
147
- function stencilGlyph(ch, platform = process.platform) {
148
- const s = stencilFor(platform);
192
+ function stencilGlyph(ch, target = null) {
193
+ const s = stencilFor(target);
149
194
  return (s && s.get(ch)) || ch;
150
195
  }
151
196
 
152
- /** One platform pass over an art block, for an explicit platform. */
153
- function portabilityFor(rows, platform) {
154
- const s = stencilFor(platform);
197
+ /** One pass over an art block, for an explicit target (caps object or platform). */
198
+ function portabilityFor(rows, target = null) {
199
+ const s = stencilFor(target);
155
200
  if (!s) return rows;
156
201
  return rows.map((r) => [...r].map((ch) => s.get(ch) ?? ch).join(''));
157
202
  }
158
203
 
159
- /** The mark as the terminal running this process will render it. */
204
+ /**
205
+ * The mark as the terminal running this process will render it.
206
+ *
207
+ * Deliberately NOT memoised: `aegiscode --ascii` and `/terminal ascii` re-resolve
208
+ * the capabilities mid-session, and a cached mark would keep drawing the
209
+ * previous terminal's runes until the process restarted.
210
+ */
160
211
  function portability(rows) {
161
- return portabilityFor(rows, process.platform);
212
+ return portabilityFor(rows, null);
162
213
  }
163
214
 
164
215
  /** The mark that fits the current terminal: side-by-side when there's room. */
165
216
  function welcomeArtFor(cols) {
166
217
  const wide = portability(WELCOME_ART);
167
218
  const stacked = portability(WELCOME_ART_STACKED);
168
- const W = Math.max(...wide.map((r) => [...r].length));
219
+ const W = Math.max(...wide.map(cells));
169
220
  return cols >= W + 4 ? wide : stacked;
170
221
  }
171
222
 
172
223
  /**
173
224
  * Split the mark into its two halves so each can carry its own theme ink.
225
+ *
226
+ * Rows are padded to a whole-cell width with `padCells()`, not `padEnd()`: a
227
+ * terminal that draws a rune two cells wide (`AEGIS_WIDE_RUNES=✦`, or a font
228
+ * that falls back to an emoji glyph) would otherwise be padded by *code point*
229
+ * and every row after it would drift one cell to the right of the one above.
230
+ *
174
231
  * @returns {{rows: Array<[string,string]>, width: number, gutter: number}}
175
232
  */
176
233
  function welcomeArtParts(cols) {
177
234
  const mascot = portability(MASCOT_ART);
178
235
  const moonWhale = portability(MOON_WHALE);
179
- const L = Math.max(...mascot.map((r) => [...r].length));
180
- const R = Math.max(...moonWhale.map((r) => [...r].length));
236
+ const L = Math.max(...mascot.map(cells));
237
+ const R = Math.max(...moonWhale.map(cells));
181
238
  const wide = cols >= L + R + 2 + 4;
182
239
  const gutter = wide ? 2 : 1;
183
240
  if (wide) {
@@ -190,13 +247,12 @@ function welcomeArtParts(cols) {
190
247
  // Same bottom-align rule as joinSideBySide — subtract the offset.
191
248
  const li = i - (n - mascot.length);
192
249
  const ri = i - (n - moonWhale.length);
193
- rows.push([(mascot[li] ?? '').padEnd(L), (moonWhale[ri] ?? '').padEnd(R)]);
250
+ rows.push([padCells(mascot[li] ?? '', L), padCells(moonWhale[ri] ?? '', R)]);
194
251
  }
195
252
  return { rows, width: L + gutter + R, gutter };
196
253
  }
197
254
  const w = Math.max(L, R);
198
- const centerBlock = (rows) =>
199
- rows.map((r) => ' '.repeat(Math.max(0, Math.floor((w - [...r].length) / 2))) + r);
255
+ const centerBlock = (rows) => rows.map((r) => ' '.repeat(Math.max(0, Math.floor((w - cells(r)) / 2))) + r);
200
256
  return {
201
257
  rows: [
202
258
  ...centerBlock(mascot).map((c) => [c, '']),
@@ -210,19 +266,16 @@ function welcomeArtParts(cols) {
210
266
 
211
267
  /** Stack two art blocks vertically, each centred, separated by `gap` rows. */
212
268
  function stackVertical(top, bottom, gap = 1) {
213
- const w = Math.max(...[...top, ...bottom].map((r) => [...r].length));
269
+ const w = Math.max(...[...top, ...bottom].map(cells));
214
270
  const centerBlock = (rows) =>
215
- rows.map((r) => {
216
- const pad = Math.max(0, Math.floor((w - [...r].length) / 2));
217
- return ' '.repeat(pad) + r;
218
- });
271
+ rows.map((r) => ' '.repeat(Math.max(0, Math.floor((w - cells(r)) / 2))) + r);
219
272
  return [...centerBlock(top), ...Array(gap).fill(''), ...centerBlock(bottom)];
220
273
  }
221
274
 
222
275
  /** Join two art stacks row-aligned (bottom-aligned by default). */
223
276
  function joinSideBySide(left, right, gutter = 2, align = 'bottom') {
224
- const L = Math.max(...left.map((r) => [...r].length));
225
- const R = Math.max(...right.map((r) => [...r].length));
277
+ const L = Math.max(...left.map(cells));
278
+ const R = Math.max(...right.map(cells));
226
279
  const n = Math.max(left.length, right.length);
227
280
  return Array.from({ length: n }, (_, i) => {
228
281
  // Bottom-align puts each block's LAST row on the output's last row, so a
@@ -233,8 +286,8 @@ function joinSideBySide(left, right, gutter = 2, align = 'bottom') {
233
286
  // hung two rows below the baseline.
234
287
  const li = align === 'bottom' ? i - (n - left.length) : i;
235
288
  const ri = align === 'bottom' ? i - (n - right.length) : i;
236
- const l = (left[li] ?? '').padEnd(L);
237
- const r = (right[ri] ?? '').padEnd(R);
289
+ const l = padCells(left[li] ?? '', L);
290
+ const r = padCells(right[ri] ?? '', R);
238
291
  return l + ' '.repeat(gutter) + r;
239
292
  });
240
293
  }
@@ -242,14 +295,14 @@ function joinSideBySide(left, right, gutter = 2, align = 'bottom') {
242
295
  /** Centre every row of an art block inside `width` (left pad + right fill). */
243
296
  function center(rows, width) {
244
297
  return rows.map((r) => {
245
- const pad = Math.max(0, Math.floor((width - [...r].length) / 2));
246
- return ' '.repeat(pad) + r + ' '.repeat(Math.max(0, width - [...r].length - pad));
298
+ const pad = Math.max(0, Math.floor((width - cells(r)) / 2));
299
+ return ' '.repeat(pad) + padCells(r, width - pad);
247
300
  });
248
301
  }
249
302
 
250
303
  /** Centre each row against the block's own max width (no trailing fill). */
251
304
  function padBoth(rows, width) {
252
- const w = Math.max(...rows.map((r) => [...r].length));
305
+ const w = Math.max(...rows.map(cells));
253
306
  return rows.map((r) => {
254
307
  const pad = Math.floor((width - w) / 2);
255
308
  return ' '.repeat(Math.max(0, pad)) + r;
@@ -269,7 +322,8 @@ module.exports = {
269
322
  WELCOME_BACK,
270
323
  TAGLINE,
271
324
  STAR,
272
- PLATFORMS,
325
+ EDGE_RUNES,
326
+ PASSES,
273
327
  STENCILS,
274
328
  stencilFor,
275
329
  stencilGlyph,
package/src/autonomous.js CHANGED
@@ -100,8 +100,14 @@ function describeCounts(items) {
100
100
  */
101
101
  function printRunReport(ran, io) {
102
102
  for (const r of ran) {
103
- const mark = r.ok ? '✓' : '✗';
104
- io.stdout.write(`aegiscode: ${mark} #${r.id} ${r.ok ? 'done' : 'failed'} (${fmtElapsed(r.ms)})`);
103
+ // stoppedOnRounds + ok means the task hit its tool-round horizon, not
104
+ // that it finished — the queue item is left 'pending' (autonomous.js's
105
+ // runOne) so a later proceed() resumes it. Calling that "done" would
106
+ // hide the exact case this whole mechanism exists to make visible.
107
+ const paused = Boolean(r.ok && r.stoppedOnRounds);
108
+ const mark = paused ? '⏸' : r.ok ? '✓' : '✗';
109
+ const label = paused ? 'paused — will resume' : r.ok ? 'done' : 'failed';
110
+ io.stdout.write(`aegiscode: ${mark} #${r.id} ${label} (${fmtElapsed(r.ms)})`);
105
111
  if (r.commit && r.commit.ok && r.commit.staged) {
106
112
  io.stdout.write(` — committed ${r.commit.staged} path(s)`);
107
113
  } else if (r.commit && r.commit.skipped && r.commit.reason) {