@causyne/agent 1.20.112 → 1.20.116
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/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/tui/CausyneRotor.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* interval-based renderer.
|
|
10
10
|
*/
|
|
11
11
|
import { stdout } from 'node:process';
|
|
12
|
+
import { safeDisplay } from './text.js';
|
|
12
13
|
const BRAILLE_DOTS = [
|
|
13
14
|
[0, 0, 0x01], [0, 1, 0x02], [0, 2, 0x04], [0, 3, 0x40],
|
|
14
15
|
[1, 0, 0x08], [1, 1, 0x10], [1, 2, 0x20], [1, 3, 0x80],
|
|
@@ -53,8 +54,12 @@ function smoothstep(t) {
|
|
|
53
54
|
const x = Math.max(0, Math.min(1, t));
|
|
54
55
|
return x * x * (3 - 2 * x);
|
|
55
56
|
}
|
|
57
|
+
function clampRotorRange(value, min, max, fallback) {
|
|
58
|
+
const numeric = Number(value ?? fallback);
|
|
59
|
+
return Number.isFinite(numeric) ? Math.max(min, Math.min(max, Math.floor(numeric))) : fallback;
|
|
60
|
+
}
|
|
56
61
|
export function getAngle(elapsedMs, motion = 'heavy') {
|
|
57
|
-
const t = Math.max(0, elapsedMs);
|
|
62
|
+
const t = Number.isFinite(elapsedMs) ? Math.max(0, elapsedMs) : 0;
|
|
58
63
|
if (motion === 'smooth')
|
|
59
64
|
return (t / 4200) * TAU;
|
|
60
65
|
if (motion === 'pulse') {
|
|
@@ -94,8 +99,8 @@ function paint(text, kind, color) {
|
|
|
94
99
|
* Intended for an existing TUI's render() method.
|
|
95
100
|
*/
|
|
96
101
|
export function renderCausyneRotor(elapsedMs, options = {}) {
|
|
97
|
-
const columns =
|
|
98
|
-
const rows =
|
|
102
|
+
const columns = clampRotorRange(options.columns, 12, 56, 24);
|
|
103
|
+
const rows = clampRotorRange(options.rows, 6, 28, 12);
|
|
99
104
|
const color = options.color ?? true;
|
|
100
105
|
const angle = getAngle(elapsedMs, options.motion ?? 'heavy');
|
|
101
106
|
const blades = Array.from({ length: 6 }, (_, i) => {
|
|
@@ -144,7 +149,10 @@ export function renderCausyneRotor(elapsedMs, options = {}) {
|
|
|
144
149
|
lines.push(line);
|
|
145
150
|
}
|
|
146
151
|
if (options.label !== '') {
|
|
147
|
-
const
|
|
152
|
+
const cleanLabel = options.label === undefined
|
|
153
|
+
? 'working'
|
|
154
|
+
: safeDisplay(options.label).replace(/\s+/g, ' ').trim();
|
|
155
|
+
const label = cleanLabel || 'working';
|
|
148
156
|
const status = color
|
|
149
157
|
? `${COLORS.lime}●${COLORS.reset} ${COLORS.text}${label}${COLORS.reset}`
|
|
150
158
|
: `● ${label}`;
|
|
@@ -160,10 +168,13 @@ export function renderCausyneRotor(elapsedMs, options = {}) {
|
|
|
160
168
|
export function startCausyneRotor(options = {}) {
|
|
161
169
|
const color = options.color ?? (Boolean(stdout.isTTY) && !process.env.NO_COLOR && !process.env.CAUSYNE_NO_COLOR);
|
|
162
170
|
if (!stdout.isTTY) {
|
|
163
|
-
|
|
171
|
+
const label = options.label === undefined
|
|
172
|
+
? 'working'
|
|
173
|
+
: safeDisplay(options.label).replace(/\s+/g, ' ').trim();
|
|
174
|
+
stdout.write(label + '\n');
|
|
164
175
|
return { stop() { } };
|
|
165
176
|
}
|
|
166
|
-
const fps =
|
|
177
|
+
const fps = clampRotorRange(options.fps, 4, 30, 16);
|
|
167
178
|
const started = Date.now();
|
|
168
179
|
let stopped = false;
|
|
169
180
|
let lastLines = 0;
|
|
@@ -217,18 +228,21 @@ export function getRotorSpinnerFrames(color = true, unicode = true) {
|
|
|
217
228
|
}
|
|
218
229
|
export function getRotorSpinnerFrame(tick, color = true, unicode = true) {
|
|
219
230
|
const frames = getRotorSpinnerFrames(color, unicode);
|
|
220
|
-
const
|
|
231
|
+
const safeTick = Number.isFinite(tick) ? Math.abs(Math.floor(tick)) : 0;
|
|
232
|
+
const index = safeTick % frames.length;
|
|
221
233
|
return frames[index] ?? frames[0] ?? '⠇⠙';
|
|
222
234
|
}
|
|
223
235
|
const DOT_FRAMES = [' ', '. ', '.. ', '...'];
|
|
224
236
|
export function getAnimatedDots(tick) {
|
|
225
|
-
const
|
|
237
|
+
const safeTick = Number.isFinite(tick) ? Math.abs(Math.floor(tick)) : 0;
|
|
238
|
+
const stage = Math.floor(safeTick / 2) % DOT_FRAMES.length;
|
|
226
239
|
return DOT_FRAMES[stage] ?? ' ';
|
|
227
240
|
}
|
|
228
241
|
export function formatAnimatedStatus(message, tick) {
|
|
229
|
-
let base = (message
|
|
242
|
+
let base = safeDisplay(message ?? '').replace(/\s+/g, ' ').trimEnd();
|
|
230
243
|
while (base.endsWith('.') || base.endsWith('…')) {
|
|
231
244
|
base = base.slice(0, -1).trimEnd();
|
|
232
245
|
}
|
|
233
|
-
|
|
246
|
+
const label = base.trim().length > 0 ? base : 'working';
|
|
247
|
+
return `${label}${getAnimatedDots(tick)}`;
|
|
234
248
|
}
|
package/src/tui/CausyneRotor.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { stdout } from 'node:process';
|
|
13
|
+
import { safeDisplay } from './text.js';
|
|
13
14
|
|
|
14
15
|
export type RotorMotion = 'heavy' | 'smooth' | 'pulse';
|
|
15
16
|
|
|
@@ -83,8 +84,13 @@ function smoothstep(t: number): number {
|
|
|
83
84
|
return x * x * (3 - 2 * x);
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
function clampRotorRange(value: number | undefined, min: number, max: number, fallback: number): number {
|
|
88
|
+
const numeric = Number(value ?? fallback);
|
|
89
|
+
return Number.isFinite(numeric) ? Math.max(min, Math.min(max, Math.floor(numeric))) : fallback;
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
export function getAngle(elapsedMs: number, motion: RotorMotion = 'heavy'): number {
|
|
87
|
-
const t = Math.max(0, elapsedMs);
|
|
93
|
+
const t = Number.isFinite(elapsedMs) ? Math.max(0, elapsedMs) : 0;
|
|
88
94
|
if (motion === 'smooth') return (t / 4200) * TAU;
|
|
89
95
|
if (motion === 'pulse') {
|
|
90
96
|
const cycle = t / 1000;
|
|
@@ -129,8 +135,8 @@ export function renderCausyneRotor(
|
|
|
129
135
|
elapsedMs: number,
|
|
130
136
|
options: RotorOptions = {},
|
|
131
137
|
): string {
|
|
132
|
-
const columns =
|
|
133
|
-
const rows =
|
|
138
|
+
const columns = clampRotorRange(options.columns, 12, 56, 24);
|
|
139
|
+
const rows = clampRotorRange(options.rows, 6, 28, 12);
|
|
134
140
|
const color = options.color ?? true;
|
|
135
141
|
const angle = getAngle(elapsedMs, options.motion ?? 'heavy');
|
|
136
142
|
const blades = Array.from({ length: 6 }, (_, i) => {
|
|
@@ -177,7 +183,10 @@ export function renderCausyneRotor(
|
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
if (options.label !== '') {
|
|
180
|
-
const
|
|
186
|
+
const cleanLabel = options.label === undefined
|
|
187
|
+
? 'working'
|
|
188
|
+
: safeDisplay(options.label).replace(/\s+/g, ' ').trim();
|
|
189
|
+
const label = cleanLabel || 'working';
|
|
181
190
|
const status = color
|
|
182
191
|
? `${COLORS.lime}●${COLORS.reset} ${COLORS.text}${label}${COLORS.reset}`
|
|
183
192
|
: `● ${label}`;
|
|
@@ -196,11 +205,14 @@ export function startCausyneRotor(options: RotorOptions & { fps?: number | undef
|
|
|
196
205
|
} {
|
|
197
206
|
const color = options.color ?? (Boolean(stdout.isTTY) && !process.env.NO_COLOR && !process.env.CAUSYNE_NO_COLOR);
|
|
198
207
|
if (!stdout.isTTY) {
|
|
199
|
-
|
|
208
|
+
const label = options.label === undefined
|
|
209
|
+
? 'working'
|
|
210
|
+
: safeDisplay(options.label).replace(/\s+/g, ' ').trim();
|
|
211
|
+
stdout.write(label + '\n');
|
|
200
212
|
return { stop() {} };
|
|
201
213
|
}
|
|
202
214
|
|
|
203
|
-
const fps =
|
|
215
|
+
const fps = clampRotorRange(options.fps, 4, 30, 16);
|
|
204
216
|
const started = Date.now();
|
|
205
217
|
let stopped = false;
|
|
206
218
|
let lastLines = 0;
|
|
@@ -260,21 +272,24 @@ export function getRotorSpinnerFrames(color = true, unicode = true): readonly st
|
|
|
260
272
|
|
|
261
273
|
export function getRotorSpinnerFrame(tick: number, color = true, unicode = true): string {
|
|
262
274
|
const frames = getRotorSpinnerFrames(color, unicode);
|
|
263
|
-
const
|
|
275
|
+
const safeTick = Number.isFinite(tick) ? Math.abs(Math.floor(tick)) : 0;
|
|
276
|
+
const index = safeTick % frames.length;
|
|
264
277
|
return frames[index] ?? frames[0] ?? '⠇⠙';
|
|
265
278
|
}
|
|
266
279
|
|
|
267
280
|
const DOT_FRAMES = [' ', '. ', '.. ', '...'] as const;
|
|
268
281
|
|
|
269
282
|
export function getAnimatedDots(tick: number): string {
|
|
270
|
-
const
|
|
283
|
+
const safeTick = Number.isFinite(tick) ? Math.abs(Math.floor(tick)) : 0;
|
|
284
|
+
const stage = Math.floor(safeTick / 2) % DOT_FRAMES.length;
|
|
271
285
|
return DOT_FRAMES[stage] ?? ' ';
|
|
272
286
|
}
|
|
273
287
|
|
|
274
288
|
export function formatAnimatedStatus(message: string, tick: number): string {
|
|
275
|
-
let base = (message
|
|
289
|
+
let base = safeDisplay(message ?? '').replace(/\s+/g, ' ').trimEnd();
|
|
276
290
|
while (base.endsWith('.') || base.endsWith('…')) {
|
|
277
291
|
base = base.slice(0, -1).trimEnd();
|
|
278
292
|
}
|
|
279
|
-
|
|
293
|
+
const label = base.trim().length > 0 ? base : 'working';
|
|
294
|
+
return `${label}${getAnimatedDots(tick)}`;
|
|
280
295
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
|
|
1
|
+
import { safeDisplay, truncate, visibleWidth, wrap, wrapBlock } from './text.js';
|
|
2
2
|
/** Render provider activity inside the conversation column, including multiline commands. */
|
|
3
3
|
export function activityRows(message, columns, prefix = '▸ ') {
|
|
4
|
-
const width = Number.isFinite(columns) ? Math.max(
|
|
5
|
-
const
|
|
4
|
+
const width = Number.isFinite(columns) ? Math.max(4, Math.floor(columns)) : 80;
|
|
5
|
+
const safePrefix = truncate(safeDisplay(String(prefix ?? '')).replace(/\r?\n/g, ' '), Math.max(1, width - 2), '');
|
|
6
|
+
const inset = visibleWidth(safePrefix);
|
|
6
7
|
const bodyWidth = Math.max(1, width - inset - 1);
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// wrapBlock keeps indentation but assumes at least eight columns.
|
|
9
|
+
// Hard-wrap its output when the actual conversation width is narrower.
|
|
10
|
+
const lines = wrapBlock(safeDisplay(String(message ?? '')).trim(), bodyWidth, { hang: 0 })
|
|
11
|
+
.flatMap(line => wrap(line, bodyWidth));
|
|
12
|
+
return lines.map((line, index) => `${index === 0 ? safePrefix : ' '.repeat(inset)}${line}`);
|
|
9
13
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
|
|
1
|
+
import { safeDisplay, truncate, visibleWidth, wrap, wrapBlock } from './text.js';
|
|
2
2
|
|
|
3
3
|
/** Render provider activity inside the conversation column, including multiline commands. */
|
|
4
4
|
export function activityRows(message: string, columns: number, prefix = '▸ '): string[] {
|
|
5
|
-
const width = Number.isFinite(columns) ? Math.max(
|
|
6
|
-
const
|
|
5
|
+
const width = Number.isFinite(columns) ? Math.max(4, Math.floor(columns)) : 80;
|
|
6
|
+
const safePrefix = truncate(safeDisplay(String(prefix ?? '')).replace(/\r?\n/g, ' '), Math.max(1, width - 2), '');
|
|
7
|
+
const inset = visibleWidth(safePrefix);
|
|
7
8
|
const bodyWidth = Math.max(1, width - inset - 1);
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
// wrapBlock keeps indentation but assumes at least eight columns.
|
|
10
|
+
// Hard-wrap its output when the actual conversation width is narrower.
|
|
11
|
+
const lines = wrapBlock(safeDisplay(String(message ?? '')).trim(), bodyWidth, { hang: 0 })
|
|
12
|
+
.flatMap(line => wrap(line, bodyWidth));
|
|
13
|
+
return lines.map((line, index) => `${index === 0 ? safePrefix : ' '.repeat(inset)}${line}`);
|
|
10
14
|
}
|
package/src/tui/ask.js
CHANGED
|
@@ -72,10 +72,20 @@ export function canAskInPanel() {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/** Plain readline, for pipes, CI and any terminal that refuses raw mode. */
|
|
75
|
-
function fallbackQuestion(question, { mask = false } = {}) {
|
|
75
|
+
export function fallbackQuestion(question, { mask = false, input = process.stdin, output = process.stdout } = {}) {
|
|
76
76
|
return new Promise((resolve) => {
|
|
77
|
-
|
|
78
|
-
rl
|
|
77
|
+
let settled = false;
|
|
78
|
+
const rl = readline.createInterface({ input, output });
|
|
79
|
+
const done = (value) => {
|
|
80
|
+
if (settled) return;
|
|
81
|
+
settled = true;
|
|
82
|
+
resolve(value);
|
|
83
|
+
};
|
|
84
|
+
rl.once('close', () => done(null));
|
|
85
|
+
rl.question(`${question} `, (answer) => {
|
|
86
|
+
rl.close();
|
|
87
|
+
done(answer);
|
|
88
|
+
});
|
|
79
89
|
if (mask) {
|
|
80
90
|
// Suppress the echo of what is typed. `_writeToOutput` is readline's own
|
|
81
91
|
// hook for exactly this; the prompt itself still has to be drawn or the
|
|
@@ -95,8 +105,9 @@ function fallbackQuestion(question, { mask = false } = {}) {
|
|
|
95
105
|
* @param {Array} options.items `{ id, label, description }`
|
|
96
106
|
* @returns {Promise<object|null>} the chosen item, or null if dismissed
|
|
97
107
|
*/
|
|
98
|
-
export async function askSelect(
|
|
99
|
-
|
|
108
|
+
export async function askSelect(options = {}) {
|
|
109
|
+
const { title = '', items = [] } = options && typeof options === 'object' ? options : {};
|
|
110
|
+
if (!Array.isArray(items) || items.length === 0) return null;
|
|
100
111
|
|
|
101
112
|
if (canAskInPanel()) {
|
|
102
113
|
const answer = await hostOneLayer((resolve) => new SelectLayer({
|
|
@@ -113,6 +124,7 @@ export async function askSelect({ title = '', items = [] } = {}) {
|
|
|
113
124
|
console.log(` ${String(index + 1).padStart(2)}. ${item.label}${item.description ? ` — ${item.description}` : ''}`);
|
|
114
125
|
});
|
|
115
126
|
const raw = await fallbackQuestion(`Choose 1-${items.length}:`);
|
|
127
|
+
if (raw === null) return null;
|
|
116
128
|
const choice = Number(String(raw).trim());
|
|
117
129
|
return Number.isInteger(choice) && choice >= 1 && choice <= items.length ? items[choice - 1] : null;
|
|
118
130
|
}
|
|
@@ -122,7 +134,10 @@ export async function askSelect({ title = '', items = [] } = {}) {
|
|
|
122
134
|
*
|
|
123
135
|
* @returns {Promise<string|null>} the answer, or null if dismissed
|
|
124
136
|
*/
|
|
125
|
-
export async function askText(
|
|
137
|
+
export async function askText(options = {}) {
|
|
138
|
+
let { title = '', lines = [], value = '', placeholder = '', mask = false, validate = null } =
|
|
139
|
+
options && typeof options === 'object' ? options : {};
|
|
140
|
+
lines = Array.isArray(lines) ? lines : [];
|
|
126
141
|
while (true) {
|
|
127
142
|
let answer;
|
|
128
143
|
|
|
@@ -160,6 +175,7 @@ export async function askConfirm(message) {
|
|
|
160
175
|
if (answer !== undefined) return Boolean(answer);
|
|
161
176
|
}
|
|
162
177
|
const raw = await fallbackQuestion(`${message} [y/N]`);
|
|
178
|
+
if (raw === null) return false;
|
|
163
179
|
return /^y(es)?$/i.test(String(raw).trim());
|
|
164
180
|
}
|
|
165
181
|
|
|
@@ -170,33 +186,37 @@ export async function askConfirm(message) {
|
|
|
170
186
|
* never grants a tool the right to mutate files or execute a command.
|
|
171
187
|
*/
|
|
172
188
|
export async function askDecision(request = {}) {
|
|
173
|
-
const
|
|
189
|
+
const safeRequest = request && typeof request === 'object' ? request : {};
|
|
190
|
+
const options = Array.isArray(safeRequest.options) ? safeRequest.options : [];
|
|
191
|
+
if (options.length === 0 && safeRequest.allowCustom === false) return null;
|
|
174
192
|
|
|
175
193
|
if (canAskInPanel()) {
|
|
176
194
|
const answer = await hostOneLayer((resolve) => new DecisionLayer({
|
|
177
|
-
request,
|
|
195
|
+
request: safeRequest,
|
|
178
196
|
onAnswer: resolve
|
|
179
197
|
}));
|
|
180
198
|
if (answer !== undefined) return answer;
|
|
181
199
|
}
|
|
182
200
|
|
|
183
201
|
const custom = { id: '__custom__', label: 'Type your own answer', description: '' };
|
|
202
|
+
const items = safeRequest.allowCustom === false ? options : [...options, custom];
|
|
203
|
+
if (items.length === 0 || (options.length === 0 && !safeRequest.id && !safeRequest.question)) return null;
|
|
184
204
|
const selected = await askSelect({
|
|
185
|
-
title:
|
|
186
|
-
items
|
|
205
|
+
title: safeRequest.header || 'Decision required',
|
|
206
|
+
items
|
|
187
207
|
});
|
|
188
208
|
if (!selected) return null;
|
|
189
209
|
if (selected.id === custom.id) {
|
|
190
210
|
const label = await askText({
|
|
191
|
-
title:
|
|
192
|
-
lines:
|
|
211
|
+
title: safeRequest.question || 'Describe the direction you want',
|
|
212
|
+
lines: safeRequest.reason ? [safeRequest.reason] : [],
|
|
193
213
|
validate: (value) => String(value).trim() ? null : 'An answer is required.'
|
|
194
214
|
});
|
|
195
215
|
if (!label) return null;
|
|
196
|
-
return { requestId:
|
|
216
|
+
return { requestId: safeRequest.id, optionId: null, label: String(label).trim(), custom: true };
|
|
197
217
|
}
|
|
198
218
|
return {
|
|
199
|
-
requestId:
|
|
219
|
+
requestId: safeRequest.id,
|
|
200
220
|
optionId: selected.id,
|
|
201
221
|
label: selected.label,
|
|
202
222
|
custom: false
|
package/src/tui/banner.js
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* CAUSYNE_ASCII=1 (7-bit only), and CAUSYNE_NO_ANIM=1.
|
|
8
8
|
*/
|
|
9
9
|
import { homedir } from 'node:os';
|
|
10
|
+
import { safeDisplay } from './text.js';
|
|
11
|
+
function cleanMeta(value) {
|
|
12
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? ''))
|
|
13
|
+
.replace(/[\r\n]+/g, ' ')
|
|
14
|
+
.trim();
|
|
15
|
+
}
|
|
10
16
|
export const TAGLINE = 'From intention to meaningful progress.';
|
|
11
17
|
// ---- Logo -----------------------------------------------------------------------------------------------
|
|
12
18
|
// One character = one "pixel". A terminal cell holds two stacked pixels (drawn with the half blocks ▀ ▄ █).
|
|
@@ -109,16 +115,25 @@ function pickVariant(c) {
|
|
|
109
115
|
return 'compact';
|
|
110
116
|
return 'full';
|
|
111
117
|
}
|
|
118
|
+
const VALID_COLORS = new Set(['truecolor', '256', '16', 'none']);
|
|
119
|
+
const VALID_VARIANTS = new Set(['full', 'compact', 'mini']);
|
|
112
120
|
export function detect(o = {}, stream = process.stdout) {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
121
|
+
const opts = o && typeof o === 'object' ? o : {};
|
|
122
|
+
const safeStream = stream && typeof stream === 'object' ? stream : {};
|
|
123
|
+
const env = process.env, tty = Boolean(safeStream.isTTY);
|
|
124
|
+
const positiveDim = (v, fallback) => {
|
|
125
|
+
const n = Number(v);
|
|
126
|
+
return Number.isFinite(n) && n >= 1 ? Math.floor(n) : fallback;
|
|
127
|
+
};
|
|
128
|
+
const width = positiveDim(opts.width, positiveDim(safeStream.columns, 80));
|
|
129
|
+
const height = positiveDim(opts.height, positiveDim(safeStream.rows, 24));
|
|
130
|
+
const want = opts.color;
|
|
116
131
|
let color;
|
|
117
132
|
if (want === true)
|
|
118
133
|
color = 'truecolor';
|
|
119
134
|
else if (want === false)
|
|
120
135
|
color = 'none';
|
|
121
|
-
else if (want
|
|
136
|
+
else if (typeof want === 'string' && VALID_COLORS.has(want))
|
|
122
137
|
color = want;
|
|
123
138
|
else {
|
|
124
139
|
const f = env['FORCE_COLOR'];
|
|
@@ -129,17 +144,19 @@ export function detect(o = {}, stream = process.stdout) {
|
|
|
129
144
|
else if (!tty || env['TERM'] === 'dumb')
|
|
130
145
|
color = 'none';
|
|
131
146
|
else {
|
|
132
|
-
const d =
|
|
147
|
+
const d = safeStream.getColorDepth?.() ?? 4;
|
|
133
148
|
color = /truecolor|24bit/i.test(env['COLORTERM'] ?? '') || d >= 24 ? 'truecolor' : d >= 8 ? '256' : d >= 4 ? '16' : 'none';
|
|
134
149
|
}
|
|
135
150
|
}
|
|
136
|
-
let unicode =
|
|
151
|
+
let unicode = opts.unicode;
|
|
137
152
|
if (unicode === undefined) {
|
|
138
153
|
const loc = env['LC_ALL'] || env['LC_CTYPE'] || env['LANG'] || '', ascii = env['CAUSYNE_ASCII'];
|
|
139
154
|
unicode = !(ascii && ascii !== '0') && !(process.platform !== 'win32' && loc !== '' && !/utf-?8/i.test(loc));
|
|
140
155
|
}
|
|
141
|
-
const caps = { tty, width, height, color, unicode, variant: 'full' };
|
|
142
|
-
caps.variant =
|
|
156
|
+
const caps = { tty, width, height, color, unicode: Boolean(unicode), variant: 'full' };
|
|
157
|
+
caps.variant = typeof opts.variant === 'string' && VALID_VARIANTS.has(opts.variant)
|
|
158
|
+
? opts.variant
|
|
159
|
+
: pickVariant(caps);
|
|
143
160
|
return caps;
|
|
144
161
|
}
|
|
145
162
|
// ---- Pixel canvas -> terminal cells ---------------------------------------------------------------------
|
|
@@ -220,8 +237,13 @@ function cells(px, caps) {
|
|
|
220
237
|
return lines;
|
|
221
238
|
}
|
|
222
239
|
function txt(str, key, caps, maxw, bold) {
|
|
223
|
-
if (maxw !== undefined
|
|
224
|
-
|
|
240
|
+
if (maxw !== undefined) {
|
|
241
|
+
const limit = Number.isFinite(maxw) ? Math.floor(maxw) : maxw === Number.POSITIVE_INFINITY ? str.length : 0;
|
|
242
|
+
if (limit <= 0)
|
|
243
|
+
return '';
|
|
244
|
+
if (str.length > limit)
|
|
245
|
+
str = str.slice(0, Math.max(0, limit - 1)) + (caps.unicode ? '…' : '~');
|
|
246
|
+
}
|
|
225
247
|
if (caps.color === 'none')
|
|
226
248
|
return str;
|
|
227
249
|
return ESC + (bold ? '1;' : '') + fgCode(key, caps.color) + 'm' + str + RESET;
|
|
@@ -237,13 +259,18 @@ function shortPath(p, maxw) {
|
|
|
237
259
|
}
|
|
238
260
|
function statusLine(info, maxw, unicode) {
|
|
239
261
|
const sep = unicode ? ' · ' : ' | ';
|
|
240
|
-
const
|
|
262
|
+
const safeProvider = cleanMeta(info.provider);
|
|
263
|
+
const safeModel = cleanMeta(info.model);
|
|
264
|
+
const safeVersion = cleanMeta(info.version).replace(/^v/, '');
|
|
265
|
+
const safeMode = cleanMeta(info.mode);
|
|
266
|
+
const safeCwd = cleanMeta(info.cwd);
|
|
267
|
+
const providerModel = [safeProvider, safeModel].filter(Boolean).join('/');
|
|
241
268
|
const providerPart = providerModel || 'select provider';
|
|
242
|
-
const parts = [
|
|
269
|
+
const parts = [safeVersion ? 'v' + safeVersion : '', providerPart, safeMode, safeCwd].filter(Boolean);
|
|
243
270
|
const fits = () => parts.join(sep).length <= maxw;
|
|
244
|
-
if (!fits() &&
|
|
271
|
+
if (!fits() && safeCwd) {
|
|
245
272
|
const others = parts.slice(0, -1).join(sep).length + (parts.length > 1 ? sep.length : 0);
|
|
246
|
-
parts[parts.length - 1] = shortPath(
|
|
273
|
+
parts[parts.length - 1] = shortPath(safeCwd, Math.max(8, maxw - others));
|
|
247
274
|
}
|
|
248
275
|
while (!fits() && parts.length > 1)
|
|
249
276
|
parts.pop();
|
|
@@ -283,7 +310,8 @@ function layoutCompact(caps, info, active) {
|
|
|
283
310
|
});
|
|
284
311
|
}
|
|
285
312
|
function layoutMini(caps, info) {
|
|
286
|
-
const
|
|
313
|
+
const safeVer = cleanMeta(info.version).replace(/^v/, '');
|
|
314
|
+
const ver = safeVer ? ' v' + safeVer : '';
|
|
287
315
|
let line = txt(caps.unicode ? '■' : '#', 'lime', caps) + ' ' + txt('CAUSYNE', 'white', caps, undefined, true) + txt(' AGENT', 'lime', caps, undefined, true);
|
|
288
316
|
if (ver && 'x CAUSYNE AGENT'.length + ver.length <= caps.width - 2)
|
|
289
317
|
line += txt(ver, 'dim', caps);
|
|
@@ -402,9 +430,18 @@ export function pickExample() {
|
|
|
402
430
|
/** Drop complete hint fragments until the remaining line fits. */
|
|
403
431
|
export function fitHints(parts, width, fallback) {
|
|
404
432
|
const separator = ' · ';
|
|
405
|
-
const
|
|
406
|
-
|
|
433
|
+
const safeParts = Array.isArray(parts) ? parts : [];
|
|
434
|
+
if (!Number.isFinite(width))
|
|
435
|
+
return width === Number.POSITIVE_INFINITY ? safeParts.join(separator) : '';
|
|
436
|
+
const limit = Math.floor(width);
|
|
437
|
+
if (limit <= 0)
|
|
438
|
+
return '';
|
|
439
|
+
const kept = safeParts.slice();
|
|
440
|
+
while (kept.length > 1 && kept.join(separator).length > limit)
|
|
407
441
|
kept.pop();
|
|
408
442
|
const line = kept.join(separator);
|
|
409
|
-
|
|
443
|
+
if (line.length <= limit)
|
|
444
|
+
return line;
|
|
445
|
+
const safeFallback = typeof fallback === 'string' ? fallback : '';
|
|
446
|
+
return safeFallback.length <= limit ? safeFallback : safeFallback.slice(0, limit);
|
|
410
447
|
}
|
package/src/tui/banner.ts
CHANGED
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
* CAUSYNE_ASCII=1 (7-bit only), and CAUSYNE_NO_ANIM=1.
|
|
8
8
|
*/
|
|
9
9
|
import { homedir } from 'node:os';
|
|
10
|
+
import { safeDisplay } from './text.js';
|
|
11
|
+
|
|
12
|
+
function cleanMeta(value: unknown): string {
|
|
13
|
+
return safeDisplay(typeof value === 'string' ? value : String(value ?? ''))
|
|
14
|
+
.replace(/[\r\n]+/g, ' ')
|
|
15
|
+
.trim();
|
|
16
|
+
}
|
|
10
17
|
|
|
11
18
|
export type ColorMode = 'truecolor' | '256' | '16' | 'none';
|
|
12
19
|
export type Variant = 'full' | 'compact' | 'mini';
|
|
@@ -147,31 +154,43 @@ function pickVariant(c: Pick<Caps, 'width' | 'height' | 'unicode'>): Variant {
|
|
|
147
154
|
if (c.width < 80 || c.height < 24 || !c.unicode) return 'compact';
|
|
148
155
|
return 'full';
|
|
149
156
|
}
|
|
157
|
+
const VALID_COLORS = new Set<ColorMode>(['truecolor', '256', '16', 'none']);
|
|
158
|
+
const VALID_VARIANTS = new Set<Variant>(['full', 'compact', 'mini']);
|
|
159
|
+
|
|
150
160
|
export function detect(o: BannerOptions = {}, stream: TermStream = process.stdout): Caps {
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const
|
|
161
|
+
const opts: BannerOptions = o && typeof o === 'object' ? o : {};
|
|
162
|
+
const safeStream: Partial<TermStream> = stream && typeof stream === 'object' ? stream : {};
|
|
163
|
+
const env = process.env, tty = Boolean(safeStream.isTTY);
|
|
164
|
+
const positiveDim = (v: unknown, fallback: number): number => {
|
|
165
|
+
const n = Number(v);
|
|
166
|
+
return Number.isFinite(n) && n >= 1 ? Math.floor(n) : fallback;
|
|
167
|
+
};
|
|
168
|
+
const width = positiveDim(opts.width, positiveDim(safeStream.columns, 80));
|
|
169
|
+
const height = positiveDim(opts.height, positiveDim(safeStream.rows, 24));
|
|
170
|
+
const want = opts.color;
|
|
154
171
|
let color: ColorMode;
|
|
155
172
|
if (want === true) color = 'truecolor';
|
|
156
173
|
else if (want === false) color = 'none';
|
|
157
|
-
else if (want
|
|
174
|
+
else if (typeof want === 'string' && VALID_COLORS.has(want as ColorMode)) color = want as ColorMode;
|
|
158
175
|
else {
|
|
159
176
|
const f = env['FORCE_COLOR'];
|
|
160
177
|
if (f !== undefined && f !== '') color = FORCE[f] ?? '16';
|
|
161
178
|
else if (env['NO_COLOR'] || env['CAUSYNE_NO_COLOR'] === '1') color = 'none';
|
|
162
179
|
else if (!tty || env['TERM'] === 'dumb') color = 'none';
|
|
163
180
|
else {
|
|
164
|
-
const d =
|
|
181
|
+
const d = safeStream.getColorDepth?.() ?? 4;
|
|
165
182
|
color = /truecolor|24bit/i.test(env['COLORTERM'] ?? '') || d >= 24 ? 'truecolor' : d >= 8 ? '256' : d >= 4 ? '16' : 'none';
|
|
166
183
|
}
|
|
167
184
|
}
|
|
168
|
-
let unicode =
|
|
185
|
+
let unicode = opts.unicode;
|
|
169
186
|
if (unicode === undefined) {
|
|
170
187
|
const loc = env['LC_ALL'] || env['LC_CTYPE'] || env['LANG'] || '', ascii = env['CAUSYNE_ASCII'];
|
|
171
188
|
unicode = !(ascii && ascii !== '0') && !(process.platform !== 'win32' && loc !== '' && !/utf-?8/i.test(loc));
|
|
172
189
|
}
|
|
173
|
-
const caps: Caps = { tty, width, height, color, unicode, variant: 'full' };
|
|
174
|
-
caps.variant =
|
|
190
|
+
const caps: Caps = { tty, width, height, color, unicode: Boolean(unicode), variant: 'full' };
|
|
191
|
+
caps.variant = typeof opts.variant === 'string' && VALID_VARIANTS.has(opts.variant as Variant)
|
|
192
|
+
? (opts.variant as Variant)
|
|
193
|
+
: pickVariant(caps);
|
|
175
194
|
return caps;
|
|
176
195
|
}
|
|
177
196
|
|
|
@@ -226,7 +245,11 @@ function cells(px: Canvas, caps: Caps): string[] {
|
|
|
226
245
|
return lines;
|
|
227
246
|
}
|
|
228
247
|
function txt(str: string, key: Key, caps: Caps, maxw?: number, bold?: boolean): string {
|
|
229
|
-
if (maxw !== undefined
|
|
248
|
+
if (maxw !== undefined) {
|
|
249
|
+
const limit = Number.isFinite(maxw) ? Math.floor(maxw) : maxw === Number.POSITIVE_INFINITY ? str.length : 0;
|
|
250
|
+
if (limit <= 0) return '';
|
|
251
|
+
if (str.length > limit) str = str.slice(0, Math.max(0, limit - 1)) + (caps.unicode ? '…' : '~');
|
|
252
|
+
}
|
|
230
253
|
if (caps.color === 'none') return str;
|
|
231
254
|
return ESC + (bold ? '1;' : '') + fgCode(key, caps.color) + 'm' + str + RESET;
|
|
232
255
|
}
|
|
@@ -240,13 +263,18 @@ function shortPath(p: string, maxw: number): string {
|
|
|
240
263
|
}
|
|
241
264
|
function statusLine(info: BannerInfo, maxw: number, unicode: boolean): string {
|
|
242
265
|
const sep = unicode ? ' · ' : ' | ';
|
|
243
|
-
const
|
|
266
|
+
const safeProvider = cleanMeta(info.provider);
|
|
267
|
+
const safeModel = cleanMeta(info.model);
|
|
268
|
+
const safeVersion = cleanMeta(info.version).replace(/^v/, '');
|
|
269
|
+
const safeMode = cleanMeta(info.mode);
|
|
270
|
+
const safeCwd = cleanMeta(info.cwd);
|
|
271
|
+
const providerModel = [safeProvider, safeModel].filter(Boolean).join('/');
|
|
244
272
|
const providerPart = providerModel || 'select provider';
|
|
245
|
-
const parts = [
|
|
273
|
+
const parts = [safeVersion ? 'v' + safeVersion : '', providerPart, safeMode, safeCwd].filter(Boolean);
|
|
246
274
|
const fits = (): boolean => parts.join(sep).length <= maxw;
|
|
247
|
-
if (!fits() &&
|
|
275
|
+
if (!fits() && safeCwd) {
|
|
248
276
|
const others = parts.slice(0, -1).join(sep).length + (parts.length > 1 ? sep.length : 0);
|
|
249
|
-
parts[parts.length - 1] = shortPath(
|
|
277
|
+
parts[parts.length - 1] = shortPath(safeCwd, Math.max(8, maxw - others));
|
|
250
278
|
}
|
|
251
279
|
while (!fits() && parts.length > 1) parts.pop();
|
|
252
280
|
return parts.join(sep);
|
|
@@ -281,7 +309,8 @@ function layoutCompact(caps: Caps, info: BannerInfo, active: number): string[] {
|
|
|
281
309
|
});
|
|
282
310
|
}
|
|
283
311
|
function layoutMini(caps: Caps, info: BannerInfo): string[] {
|
|
284
|
-
const
|
|
312
|
+
const safeVer = cleanMeta(info.version).replace(/^v/, '');
|
|
313
|
+
const ver = safeVer ? ' v' + safeVer : '';
|
|
285
314
|
let line = txt(caps.unicode ? '■' : '#', 'lime', caps) + ' ' + txt('CAUSYNE', 'white', caps, undefined, true) + txt(' AGENT', 'lime', caps, undefined, true);
|
|
286
315
|
if (ver && 'x CAUSYNE AGENT'.length + ver.length <= caps.width - 2) line += txt(ver, 'dim', caps);
|
|
287
316
|
return [' ' + line];
|
|
@@ -408,8 +437,14 @@ export function pickExample(): string {
|
|
|
408
437
|
/** Drop complete hint fragments until the remaining line fits. */
|
|
409
438
|
export function fitHints(parts: string[], width: number, fallback: string): string {
|
|
410
439
|
const separator = ' · ';
|
|
411
|
-
const
|
|
412
|
-
|
|
440
|
+
const safeParts = Array.isArray(parts) ? parts : [];
|
|
441
|
+
if (!Number.isFinite(width)) return width === Number.POSITIVE_INFINITY ? safeParts.join(separator) : '';
|
|
442
|
+
const limit = Math.floor(width);
|
|
443
|
+
if (limit <= 0) return '';
|
|
444
|
+
const kept = safeParts.slice();
|
|
445
|
+
while (kept.length > 1 && kept.join(separator).length > limit) kept.pop();
|
|
413
446
|
const line = kept.join(separator);
|
|
414
|
-
|
|
447
|
+
if (line.length <= limit) return line;
|
|
448
|
+
const safeFallback = typeof fallback === 'string' ? fallback : '';
|
|
449
|
+
return safeFallback.length <= limit ? safeFallback : safeFallback.slice(0, limit);
|
|
415
450
|
}
|