@causyne/agent 1.20.36 → 1.20.38

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.
@@ -13,15 +13,13 @@
13
13
  // the conversation legible underneath.
14
14
  //
15
15
  // Pure Node over ./screen.js, ./theme.js and ./text.js. No dependency, no shell.
16
-
17
- import { paint, bold, dim, GLYPHS, HAS_COLOR, HAS_UNICODE } from './theme.js';
16
+ // @ts-expect-error theme.js has no TypeScript declaration yet.
17
+ import { paint, bold, dim, fill, GLYPHS, HAS_COLOR, HAS_UNICODE } from './theme.js';
18
18
  import { truncate, visibleWidth } from './text.js';
19
-
20
19
  // Box-drawing set, degrading with the rest of the glyphs.
21
20
  export const FRAME = HAS_UNICODE
22
- ? { tl: '╭', tr: '╮', bl: '╰', br: '╯', h: '─', v: '│' }
23
- : { tl: '+', tr: '+', bl: '+', br: '+', h: '-', v: '|' };
24
-
21
+ ? { tl: '╭', tr: '╮', bl: '╰', br: '╯', h: '─', v: '│' }
22
+ : { tl: '+', tr: '+', bl: '+', br: '+', h: '-', v: '|' };
25
23
  /**
26
24
  * Add the SGR dim attribute to every cell in a region.
27
25
  *
@@ -29,24 +27,30 @@ export const FRAME = HAS_UNICODE
29
27
  * conversation stays readable behind a dialog instead of being erased.
30
28
  */
31
29
  export function dimBackdrop(screen, viewport, hole) {
32
- if (!HAS_COLOR) return;
33
- for (let row = viewport.y; row < viewport.y + viewport.height; row++) {
34
- if (row < 0 || row >= screen.height) continue;
35
- for (let column = viewport.x; column < viewport.x + viewport.width; column++) {
36
- if (column < 0 || column >= screen.width) continue;
37
- if (hole
38
- && row >= hole.y && row < hole.y + hole.height
39
- && column >= hole.x && column < hole.x + hole.width) continue;
40
-
41
- const cell = screen.cells[row * screen.width + column];
42
- if (cell.ch === ' ' && !cell.style) continue;
43
- const parts = cell.style ? cell.style.split(';') : [];
44
- if (!parts.includes('2')) parts.push('2');
45
- cell.style = parts.join(';');
30
+ if (!HAS_COLOR)
31
+ return;
32
+ for (let row = viewport.y; row < viewport.y + viewport.height; row++) {
33
+ if (row < 0 || row >= screen.height)
34
+ continue;
35
+ for (let column = viewport.x; column < viewport.x + viewport.width; column++) {
36
+ if (column < 0 || column >= screen.width)
37
+ continue;
38
+ if (hole
39
+ && row >= hole.y && row < hole.y + hole.height
40
+ && column >= hole.x && column < hole.x + hole.width)
41
+ continue;
42
+ const cell = screen.cells[row * screen.width + column];
43
+ if (!cell)
44
+ continue;
45
+ if (cell.ch === ' ' && !cell.style)
46
+ continue;
47
+ const parts = cell.style ? cell.style.split(';') : [];
48
+ if (!parts.includes('2'))
49
+ parts.push('2');
50
+ cell.style = parts.join(';');
51
+ }
46
52
  }
47
- }
48
53
  }
49
-
50
54
  /**
51
55
  * Draw a framed panel and return the rect available INSIDE it.
52
56
  *
@@ -54,44 +58,37 @@ export function dimBackdrop(screen, viewport, hole) {
54
58
  * the transcript bleeding through the gaps between its rows.
55
59
  */
56
60
  export function drawPanel(screen, rect, { title = '', footer = '' } = {}) {
57
- if (rect.width < 4 || rect.height < 3) return { x: rect.x, y: rect.y, width: 0, height: 0 };
58
-
59
- screen.fill(rect.x, rect.y, rect.width, rect.height, '');
60
-
61
- const inner = rect.width - 2;
62
- const line = FRAME.h.repeat(inner);
63
-
64
- // Title sits in the top border, the way every terminal dialog has since curses.
65
- let top = FRAME.tl + line + FRAME.tr;
66
- if (title) {
67
- const label = ` ${truncate(title, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
68
- const width = visibleWidth(label);
69
- top = FRAME.tl + FRAME.h + label + FRAME.h.repeat(Math.max(0, inner - width - 1)) + FRAME.tr;
70
- }
71
-
72
- let bottom = FRAME.bl + line + FRAME.br;
73
- if (footer) {
74
- const label = ` ${truncate(footer, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
75
- const width = visibleWidth(label);
76
- bottom = FRAME.bl + FRAME.h.repeat(Math.max(0, inner - width - 1)) + label + FRAME.h + FRAME.br;
77
- }
78
-
79
- screen.put(rect.x, rect.y, paint('rule', top), rect.width);
80
- screen.put(rect.x, rect.y + rect.height - 1, paint('rule', bottom), rect.width);
81
-
82
- for (let row = rect.y + 1; row < rect.y + rect.height - 1; row++) {
83
- screen.put(rect.x, row, paint('rule', FRAME.v), 1);
84
- screen.put(rect.x + rect.width - 1, row, paint('rule', FRAME.v), 1);
85
- }
86
-
87
- return {
88
- x: rect.x + 2,
89
- y: rect.y + 1,
90
- width: Math.max(0, rect.width - 4),
91
- height: Math.max(0, rect.height - 2)
92
- };
61
+ if (rect.width < 4 || rect.height < 3)
62
+ return { x: rect.x, y: rect.y, width: 0, height: 0 };
63
+ screen.fill(rect.x, rect.y, rect.width, rect.height, '');
64
+ const inner = rect.width - 2;
65
+ const line = FRAME.h.repeat(inner);
66
+ // Title sits in the top border, the way every terminal dialog has since curses.
67
+ let top = FRAME.tl + line + FRAME.tr;
68
+ if (title) {
69
+ const label = ` ${truncate(title, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
70
+ const width = visibleWidth(label);
71
+ top = FRAME.tl + FRAME.h + label + FRAME.h.repeat(Math.max(0, inner - width - 1)) + FRAME.tr;
72
+ }
73
+ let bottom = FRAME.bl + line + FRAME.br;
74
+ if (footer) {
75
+ const label = ` ${truncate(footer, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
76
+ const width = visibleWidth(label);
77
+ bottom = FRAME.bl + FRAME.h.repeat(Math.max(0, inner - width - 1)) + label + FRAME.h + FRAME.br;
78
+ }
79
+ screen.put(rect.x, rect.y, paint('rule', top), rect.width);
80
+ screen.put(rect.x, rect.y + rect.height - 1, paint('rule', bottom), rect.width);
81
+ for (let row = rect.y + 1; row < rect.y + rect.height - 1; row++) {
82
+ screen.put(rect.x, row, paint('rule', FRAME.v), 1);
83
+ screen.put(rect.x + rect.width - 1, row, paint('rule', FRAME.v), 1);
84
+ }
85
+ return {
86
+ x: rect.x + 2,
87
+ y: rect.y + 1,
88
+ width: Math.max(0, rect.width - 4),
89
+ height: Math.max(0, rect.height - 2)
90
+ };
93
91
  }
94
-
95
92
  /**
96
93
  * A layer on the stack.
97
94
  *
@@ -102,108 +99,109 @@ export function drawPanel(screen, rect, { title = '', footer = '' } = {}) {
102
99
  * the layer chose to ignore it.
103
100
  */
104
101
  export class Layer {
105
- constructor(options = {}) {
106
- this.title = options.title || '';
107
- this.footer = options.footer || '';
108
- this.width = options.width || 64;
109
- this.height = options.height || 16;
110
- this.onClose = options.onClose || null;
111
- this.onSelect = options.onSelect || null;
112
- this.cursor = null;
113
- }
114
-
115
- /**
116
- * Rows this layer would like, given its content.
117
- *
118
- * A dialog padded out to a fixed height with blank rows looks unfinished —
119
- * it is the single clearest tell between a prototype and a shipped tool. Every
120
- * layer reports what it actually needs and the frame shrinks to it.
121
- */
122
- preferredHeight() { return this.height; }
123
-
124
- /** Panel rect, centred and clamped to the viewport. */
125
- rect(viewport) {
126
- const width = Math.min(this.width, Math.max(20, viewport.width - 4));
127
- const wanted = Math.max(5, Math.min(this.preferredHeight(), this.height));
128
- const height = Math.min(wanted, Math.max(5, viewport.height - 4));
129
- return {
130
- x: viewport.x + Math.floor((viewport.width - width) / 2),
131
- // A quarter down reads as centred; dead centre sits visually too low.
132
- y: viewport.y + Math.max(1, Math.floor((viewport.height - height) / 4)),
133
- width,
134
- height
135
- };
136
- }
137
-
138
- body() { return []; }
139
- key() { return null; }
102
+ title;
103
+ footer;
104
+ width;
105
+ height;
106
+ borderRole;
107
+ surfaceRole;
108
+ onClose;
109
+ onSelect;
110
+ cursor;
111
+ constructor(options = {}) {
112
+ this.title = options.title || '';
113
+ this.footer = options.footer || '';
114
+ this.width = options.width || 64;
115
+ this.height = options.height || 16;
116
+ this.onClose = options.onClose || null;
117
+ this.onSelect = options.onSelect || null;
118
+ this.cursor = null;
119
+ }
120
+ /**
121
+ * Rows this layer would like, given its content.
122
+ *
123
+ * A dialog padded out to a fixed height with blank rows looks unfinished —
124
+ * it is the single clearest tell between a prototype and a shipped tool. Every
125
+ * layer reports what it actually needs and the frame shrinks to it.
126
+ */
127
+ preferredHeight() { return this.height; }
128
+ /** Panel rect, centred and clamped to the viewport. */
129
+ rect(viewport) {
130
+ const width = Math.min(this.width, Math.max(20, viewport.width - 4));
131
+ const wanted = Math.max(5, Math.min(this.preferredHeight(), this.height));
132
+ const height = Math.min(wanted, Math.max(5, viewport.height - 4));
133
+ return {
134
+ x: viewport.x + Math.floor((viewport.width - width) / 2),
135
+ // A quarter down reads as centred; dead centre sits visually too low.
136
+ y: viewport.y + Math.max(1, Math.floor((viewport.height - height) / 4)),
137
+ width,
138
+ height
139
+ };
140
+ }
141
+ body(_width, _height) { return []; }
142
+ key(_event) { return null; }
140
143
  }
141
-
142
144
  export class OverlayStack {
143
- constructor() {
144
- this.layers = [];
145
- }
146
-
147
- get top() { return this.layers.length > 0 ? this.layers[this.layers.length - 1] : null; }
148
- get active() { return this.layers.length > 0; }
149
- get depth() { return this.layers.length; }
150
-
151
- push(layer) {
152
- this.layers.push(layer);
153
- return layer;
154
- }
155
-
156
- /** Pop exactly one layer. Nested dialogs unwind one esc at a time. */
157
- pop() {
158
- const layer = this.layers.pop();
159
- if (layer && layer.onClose) layer.onClose();
160
- return layer || null;
161
- }
162
-
163
- clear() {
164
- while (this.layers.length > 0) this.pop();
165
- }
166
-
167
- /**
168
- * Route a key.
169
- *
170
- * Returns true when a modal consumed it — which is ALWAYS, while one is open.
171
- * The caller uses that to decide whether the prompt beneath ever sees the key,
172
- * and the answer while a dialog is up must be no.
173
- */
174
- handleKey(key) {
175
- const layer = this.top;
176
- if (!layer) return false;
177
-
178
- const result = layer.key(key);
179
- if (result === 'close') this.pop();
180
- return true;
181
- }
182
-
183
- /** Paint every layer bottom to top, dimming what is behind the topmost. */
184
- paint(screen, viewport) {
185
- for (let index = 0; index < this.layers.length; index++) {
186
- const layer = this.layers[index];
187
- const rect = layer.rect(viewport);
188
-
189
- dimBackdrop(screen, viewport, rect);
190
- const inner = drawPanel(screen, rect, { title: layer.title, footer: layer.footer });
191
- if (inner.height <= 0) continue;
192
-
193
- const rows = layer.body(inner.width, inner.height) || [];
194
- for (let row = 0; row < Math.min(rows.length, inner.height); row++) {
195
- screen.put(inner.x, inner.y + row, rows[row], inner.width);
196
- }
197
-
198
- // Only the topmost layer may own the caret.
199
- if (index === this.layers.length - 1 && layer.cursor) {
200
- screen.setCursor(inner.x + layer.cursor.x, inner.y + layer.cursor.y);
201
- }
145
+ layers;
146
+ constructor() {
147
+ this.layers = [];
148
+ }
149
+ get top() { return this.layers.length > 0 ? (this.layers[this.layers.length - 1] ?? null) : null; }
150
+ get active() { return this.layers.length > 0; }
151
+ get depth() { return this.layers.length; }
152
+ push(layer) {
153
+ this.layers.push(layer);
154
+ return layer;
155
+ }
156
+ /** Pop exactly one layer. Nested dialogs unwind one esc at a time. */
157
+ pop() {
158
+ const layer = this.layers.pop();
159
+ if (layer && layer.onClose)
160
+ layer.onClose();
161
+ return layer || null;
162
+ }
163
+ clear() {
164
+ while (this.layers.length > 0)
165
+ this.pop();
166
+ }
167
+ /**
168
+ * Route a key.
169
+ *
170
+ * Returns true when a modal consumed it — which is ALWAYS, while one is open.
171
+ * The caller uses that to decide whether the prompt beneath ever sees the key,
172
+ * and the answer while a dialog is up must be no.
173
+ */
174
+ handleKey(key) {
175
+ const layer = this.top;
176
+ if (!layer)
177
+ return false;
178
+ const result = layer.key(key);
179
+ if (result === 'close')
180
+ this.pop();
181
+ return true;
182
+ }
183
+ /** Paint every layer bottom to top, dimming what is behind the topmost. */
184
+ paint(screen, viewport) {
185
+ for (let index = 0; index < this.layers.length; index++) {
186
+ const layer = this.layers[index];
187
+ if (!layer)
188
+ continue;
189
+ const rect = layer.rect(viewport);
190
+ dimBackdrop(screen, viewport, rect);
191
+ const inner = drawPanel(screen, rect, { title: layer.title, footer: layer.footer });
192
+ if (inner.height <= 0)
193
+ continue;
194
+ const rows = layer.body(inner.width, inner.height) || [];
195
+ for (let row = 0; row < Math.min(rows.length, inner.height); row++) {
196
+ screen.put(inner.x, inner.y + row, rows[row] ?? '', inner.width);
197
+ }
198
+ // Only the topmost layer may own the caret.
199
+ if (index === this.layers.length - 1 && layer.cursor) {
200
+ screen.setCursor(inner.x + layer.cursor.x, inner.y + layer.cursor.y);
201
+ }
202
+ }
202
203
  }
203
- }
204
204
  }
205
-
206
- /** Shared footer text so every dialog teaches the same keys. */
207
205
  /**
208
206
  * A layer as framed rows, for a normal-buffer live region.
209
207
  *
@@ -213,44 +211,45 @@ export class OverlayStack {
213
211
  * append. It is the shape openclaw draws its pickers in: extra lines in the
214
212
  * composed frame, not a floating window.
215
213
  *
216
- * There is deliberately no backdrop dim: a line already committed to the user's
217
- * scrollback cannot be restyled, and pretending otherwise would corrupt it.
214
+ * Every row is wrapped with `fill('surface', ...)` so that when a panel (such as
215
+ * Message Actions) is overlaid onto the transcript viewport, its interior has an
216
+ * opaque surface background and legible header/footer typography.
218
217
  */
219
218
  export function panelRows(layer, width, maxHeight) {
220
- const frameWidth = Math.max(8, width);
221
- const inner = frameWidth - 4; // two borders, one pad each side
222
- const bodyHeight = Math.max(1, Math.min(layer.preferredHeight(), maxHeight) - 2);
223
- const body = layer.body(inner, bodyHeight);
224
-
225
- const line = FRAME.h.repeat(frameWidth - 2);
226
-
227
- let top = FRAME.tl + line + FRAME.tr;
228
- if (layer.title) {
229
- const label = ` ${truncate(layer.title, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
230
- top = FRAME.tl + FRAME.h + label + FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label))) + FRAME.tr;
231
- }
232
-
233
- let bottom = FRAME.bl + line + FRAME.br;
234
- if (layer.footer) {
235
- const label = ` ${truncate(layer.footer, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
236
- bottom = FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label))) + label + FRAME.h + FRAME.br;
237
- }
238
-
239
- const edge = paint('rule', FRAME.v);
240
- const rows = [paint('rule', top)];
241
- for (let index = 0; index < bodyHeight; index++) {
242
- const content = truncate(body[index] || '', inner, GLYPHS.ellipsis);
243
- const pad = ' '.repeat(Math.max(0, inner - visibleWidth(content)));
244
- rows.push(`${edge} ${content}${pad} ${edge}`);
245
- }
246
- rows.push(paint('rule', bottom));
247
- return rows;
219
+ const frameWidth = Math.max(8, width);
220
+ const inner = frameWidth - 4; // two borders, one pad each side
221
+ const bodyHeight = Math.max(1, Math.min(layer.preferredHeight(), maxHeight) - 2);
222
+ const body = layer.body(inner, bodyHeight);
223
+ const borderRole = layer.borderRole || 'rule';
224
+ const surfaceRole = layer.surfaceRole || 'surface';
225
+ const line = FRAME.h.repeat(frameWidth - 2);
226
+ let top = paint(borderRole, FRAME.tl + line + FRAME.tr);
227
+ if (layer.title) {
228
+ const label = ` ${truncate(layer.title, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
229
+ const trail = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
230
+ top = paint(borderRole, FRAME.tl + FRAME.h) + bold(paint('ink', label)) + paint(borderRole, trail + FRAME.tr);
231
+ }
232
+ let bottom = paint(borderRole, FRAME.bl + line + FRAME.br);
233
+ if (layer.footer) {
234
+ const label = ` ${truncate(layer.footer, Math.max(0, inner - 4), GLYPHS.ellipsis)} `;
235
+ const lead = FRAME.h.repeat(Math.max(0, frameWidth - 3 - visibleWidth(label)));
236
+ bottom = paint(borderRole, FRAME.bl + lead) + dim(label) + paint(borderRole, FRAME.h + FRAME.br);
237
+ }
238
+ const edge = paint(borderRole, FRAME.v);
239
+ const rows = [fill(surfaceRole, top)];
240
+ for (let index = 0; index < bodyHeight; index++) {
241
+ const content = truncate(body[index] || '', inner, GLYPHS.ellipsis);
242
+ const pad = ' '.repeat(Math.max(0, inner - visibleWidth(content)));
243
+ rows.push(fill(surfaceRole, `${edge} ${content}${pad} ${edge}`));
244
+ }
245
+ rows.push(fill(surfaceRole, bottom));
246
+ return rows;
248
247
  }
249
-
248
+ /** Shared footer text so every dialog teaches the same keys. */
250
249
  export function dialogHint(extra = '') {
251
- const parts = ['↑↓ move', 'enter select', 'esc close'];
252
- if (extra) parts.push(extra);
253
- return parts.join(` ${GLYPHS.dot} `);
250
+ const parts = ['↑↓ move', 'enter select', 'esc close'];
251
+ if (extra)
252
+ parts.push(extra);
253
+ return parts.join(` ${GLYPHS.dot} `);
254
254
  }
255
-
256
255
  export { bold, dim };