@causyne/agent 1.20.36 → 1.20.39
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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/decisionPolicy.js +1 -1
- package/src/decisionPolicy.ts +1 -1
- package/src/plugins/pluginsFactory.js +4 -0
- package/src/plugins/pluginsFactory.ts +6 -0
- package/src/pluginsFactory/costEstimate.js +89 -0
- package/src/pluginsFactory/costEstimate.ts +110 -0
- package/src/pluginsFactory/discovery.js +97 -0
- package/src/pluginsFactory/discovery.ts +114 -0
- package/src/pluginsFactory/index.js +9 -0
- package/src/pluginsFactory/index.ts +11 -0
- package/src/pluginsFactory/pluginsFactory.js +250 -0
- package/src/pluginsFactory/pluginsFactory.ts +302 -0
- package/src/pluginsFactory/strategy.js +93 -0
- package/src/pluginsFactory/strategy.ts +106 -0
- package/src/pluginsFactory/templates.js +592 -0
- package/src/pluginsFactory/templates.ts +631 -0
- package/src/pluginsFactory/types.js +12 -0
- package/src/pluginsFactory/types.ts +107 -0
- package/src/stallGuard.js +1 -0
- package/src/stallGuard.ts +1 -0
- package/src/toolPacks.js +1 -0
- package/src/toolPacks.ts +1 -0
- package/src/tools/pluginsFactory.js +202 -0
- package/src/tools/pluginsFactory.ts +246 -0
- package/src/tools/registry.js +2 -1
- package/src/tools/sysRun.js +22 -6
- package/src/tools/sysRun.ts +23 -6
- package/src/toolsList.js +1 -0
- package/src/toolsList.ts +1 -0
- package/src/tui/chatRenderer.js +5 -4
- package/src/tui/homeView.js +0 -1
- package/src/tui/homeView.ts +0 -1
- package/src/tui/markdownMath.js +250 -0
- package/src/tui/markdownMath.ts +263 -0
- package/src/tui/messageActionPlacement.js +79 -8
- package/src/tui/messageActionPlacement.ts +102 -9
- package/src/tui/messageInteraction.js +43 -9
- package/src/tui/messageInteraction.ts +51 -17
- package/src/tui/overlay.js +191 -192
- package/src/tui/overlay.ts +320 -0
- package/src/tui/prompt.js +4 -1
- package/src/tui/stageSurface.js +4 -1
- package/src/tui/text.js +204 -208
- package/src/tui/text.ts +360 -0
- package/src/tui/toolOutputNormalizer.js +3 -1
- package/src/tui/toolOutputNormalizer.ts +3 -1
- package/src/tui/turnRail.js +11 -1
- package/src/tui/turnRail.ts +11 -1
- package/src/tui/text.d.ts +0 -7
package/src/tui/overlay.js
CHANGED
|
@@ -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
|
-
|
|
23
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
*
|
|
217
|
-
*
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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 };
|