@causyne/agent 1.20.112 → 1.20.117
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 +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- 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/cliMode.js +5 -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/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- 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/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- 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/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- 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 +139 -84
- 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 +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- 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 +36 -18
- 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 +186 -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 +232 -51
- 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 +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- 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/types/contracts.ts +3 -0
|
@@ -12,22 +12,26 @@ export function extractCoordinateNumbers(raw) {
|
|
|
12
12
|
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
13
13
|
if (!clean)
|
|
14
14
|
return [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.map((s) => Number.parseFloat(s))
|
|
18
|
-
.filter((n) => Number.isFinite(n));
|
|
15
|
+
const values = clean.split(/[\s,]+/).map((part) => Number(part));
|
|
16
|
+
return values.every(Number.isFinite) ? values : [];
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* Ground normalized coordinates (0-1000) to actual screen units.
|
|
22
20
|
* Defaults to OS logical points on macOS/modern desktop actuators to prevent double-scaling.
|
|
23
21
|
*/
|
|
24
22
|
export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
25
|
-
if (nums.length
|
|
23
|
+
if (!Array.isArray(nums) || nums.length !== 2 || !nums.every(Number.isFinite))
|
|
24
|
+
return null;
|
|
25
|
+
if (!Number.isFinite(screen.width) || screen.width <= 0 || !Number.isFinite(screen.height) || screen.height <= 0)
|
|
26
|
+
return null;
|
|
27
|
+
if (!factor.every(value => Number.isFinite(value) && value > 0))
|
|
26
28
|
return null;
|
|
27
29
|
const rawX = nums[0] ?? 0;
|
|
28
30
|
const rawY = nums[1] ?? 0;
|
|
29
31
|
const targetSpace = screen.targetSpace ?? 'logical';
|
|
30
|
-
const scale = targetSpace === 'physical' ? (screen.scaleFactor
|
|
32
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor ?? 1) : 1;
|
|
33
|
+
if (!Number.isFinite(scale) || scale <= 0)
|
|
34
|
+
return null;
|
|
31
35
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
32
36
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
33
37
|
return {
|
|
@@ -39,7 +43,7 @@ export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFac
|
|
|
39
43
|
* Ground a bounding box (x1, y1, x2, y2) into its midpoint (center click).
|
|
40
44
|
*/
|
|
41
45
|
export function groundBoxCenter(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
42
|
-
if (nums.length
|
|
46
|
+
if (!Array.isArray(nums) || (nums.length !== 2 && nums.length !== 4) || !nums.every(Number.isFinite))
|
|
43
47
|
return null;
|
|
44
48
|
if (nums.length === 2) {
|
|
45
49
|
return groundPoint(nums, screen, factor);
|
|
@@ -64,7 +68,7 @@ export function parseSingleAction(rawAction, screenContext = { width: 1920, heig
|
|
|
64
68
|
line = line.replace(/^(?:Action(?:_Summary)?[::]\s*)/i, '').trim();
|
|
65
69
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
66
70
|
if (!callMatch) {
|
|
67
|
-
if (
|
|
71
|
+
if (/^finished$/i.test(line)) {
|
|
68
72
|
return { action: 'finished', rawStr: line };
|
|
69
73
|
}
|
|
70
74
|
return null;
|
|
@@ -72,11 +76,11 @@ export function parseSingleAction(rawAction, screenContext = { width: 1920, heig
|
|
|
72
76
|
const funcName = callMatch[1]?.toLowerCase();
|
|
73
77
|
const argsRaw = callMatch[2] || '';
|
|
74
78
|
const argsMap = {};
|
|
75
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:[
|
|
79
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^,\s'")]+))/g;
|
|
76
80
|
let match;
|
|
77
81
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
78
82
|
const key = match[1];
|
|
79
|
-
const val = match[2] ?? match[3];
|
|
83
|
+
const val = (match[2] ?? match[3] ?? match[4])?.replace(/\\(['"\\])/g, '$1');
|
|
80
84
|
if (key && val !== undefined) {
|
|
81
85
|
argsMap[key] = val;
|
|
82
86
|
}
|
|
@@ -222,13 +226,13 @@ export function visionGroundingToDesktopAct(actions) {
|
|
|
222
226
|
case 'triple_click': {
|
|
223
227
|
const point = act.coordinates;
|
|
224
228
|
if (point) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
const clicks = act.action === 'triple_click' ? 3 : act.action === 'double_click' ? 2 : 1;
|
|
230
|
+
for (let i = 0; i < clicks; i++) {
|
|
231
|
+
result.push({
|
|
232
|
+
verb: 'clickxy',
|
|
233
|
+
x: point.x,
|
|
234
|
+
y: point.y
|
|
235
|
+
});
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
238
|
break;
|
|
@@ -283,18 +287,18 @@ export function visionGroundingToDesktopAct(actions) {
|
|
|
283
287
|
break;
|
|
284
288
|
}
|
|
285
289
|
case 'drag': {
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
+
const start = act.startCoordinates ?? act.coordinates;
|
|
291
|
+
const end = act.endCoordinates;
|
|
292
|
+
if (!start || !end)
|
|
293
|
+
break;
|
|
290
294
|
result.push({
|
|
291
295
|
verb: 'drag',
|
|
292
|
-
fromX,
|
|
293
|
-
fromY,
|
|
294
|
-
toX,
|
|
295
|
-
toY,
|
|
296
|
-
x:
|
|
297
|
-
y:
|
|
296
|
+
fromX: start.x,
|
|
297
|
+
fromY: start.y,
|
|
298
|
+
toX: end.x,
|
|
299
|
+
toY: end.y,
|
|
300
|
+
x: end.x,
|
|
301
|
+
y: end.y
|
|
298
302
|
});
|
|
299
303
|
break;
|
|
300
304
|
}
|
|
@@ -71,10 +71,8 @@ const DEFAULT_FACTOR: [number, number] = [1000, 1000];
|
|
|
71
71
|
export function extractCoordinateNumbers(raw: string): number[] {
|
|
72
72
|
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
73
73
|
if (!clean) return [];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.map((s) => Number.parseFloat(s))
|
|
77
|
-
.filter((n) => Number.isFinite(n));
|
|
74
|
+
const values = clean.split(/[\s,]+/).map((part) => Number(part));
|
|
75
|
+
return values.every(Number.isFinite) ? values : [];
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
/**
|
|
@@ -86,11 +84,14 @@ export function groundPoint(
|
|
|
86
84
|
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
87
85
|
factor: [number, number] = DEFAULT_FACTOR
|
|
88
86
|
): { x: number; y: number } | null {
|
|
89
|
-
if (nums.length
|
|
87
|
+
if (!Array.isArray(nums) || nums.length !== 2 || !nums.every(Number.isFinite)) return null;
|
|
88
|
+
if (!Number.isFinite(screen.width) || screen.width <= 0 || !Number.isFinite(screen.height) || screen.height <= 0) return null;
|
|
89
|
+
if (!factor.every(value => Number.isFinite(value) && value > 0)) return null;
|
|
90
90
|
const rawX = nums[0] ?? 0;
|
|
91
91
|
const rawY = nums[1] ?? 0;
|
|
92
92
|
const targetSpace = screen.targetSpace ?? 'logical';
|
|
93
|
-
const scale = targetSpace === 'physical' ? (screen.scaleFactor
|
|
93
|
+
const scale = targetSpace === 'physical' ? (screen.scaleFactor ?? 1) : 1;
|
|
94
|
+
if (!Number.isFinite(scale) || scale <= 0) return null;
|
|
94
95
|
|
|
95
96
|
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
96
97
|
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
@@ -109,7 +110,7 @@ export function groundBoxCenter(
|
|
|
109
110
|
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
110
111
|
factor: [number, number] = DEFAULT_FACTOR
|
|
111
112
|
): { x: number; y: number } | null {
|
|
112
|
-
if (nums.length
|
|
113
|
+
if (!Array.isArray(nums) || (nums.length !== 2 && nums.length !== 4) || !nums.every(Number.isFinite)) return null;
|
|
113
114
|
if (nums.length === 2) {
|
|
114
115
|
return groundPoint(nums, screen, factor);
|
|
115
116
|
}
|
|
@@ -139,7 +140,7 @@ export function parseSingleAction(
|
|
|
139
140
|
|
|
140
141
|
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
141
142
|
if (!callMatch) {
|
|
142
|
-
if (
|
|
143
|
+
if (/^finished$/i.test(line)) {
|
|
143
144
|
return { action: 'finished', rawStr: line };
|
|
144
145
|
}
|
|
145
146
|
return null;
|
|
@@ -149,11 +150,11 @@ export function parseSingleAction(
|
|
|
149
150
|
const argsRaw = callMatch[2] || '';
|
|
150
151
|
|
|
151
152
|
const argsMap: Record<string, string> = {};
|
|
152
|
-
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:[
|
|
153
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^,\s'")]+))/g;
|
|
153
154
|
let match: RegExpExecArray | null;
|
|
154
155
|
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
155
156
|
const key = match[1];
|
|
156
|
-
const val = match[2] ?? match[3];
|
|
157
|
+
const val = (match[2] ?? match[3] ?? match[4])?.replace(/\\(['"\\])/g, '$1');
|
|
157
158
|
if (key && val !== undefined) {
|
|
158
159
|
argsMap[key] = val;
|
|
159
160
|
}
|
|
@@ -319,13 +320,13 @@ export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopAct
|
|
|
319
320
|
case 'triple_click': {
|
|
320
321
|
const point = act.coordinates;
|
|
321
322
|
if (point) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
323
|
+
const clicks = act.action === 'triple_click' ? 3 : act.action === 'double_click' ? 2 : 1;
|
|
324
|
+
for (let i = 0; i < clicks; i++) {
|
|
325
|
+
result.push({
|
|
326
|
+
verb: 'clickxy',
|
|
327
|
+
x: point.x,
|
|
328
|
+
y: point.y
|
|
329
|
+
});
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
break;
|
|
@@ -378,18 +379,17 @@ export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopAct
|
|
|
378
379
|
break;
|
|
379
380
|
}
|
|
380
381
|
case 'drag': {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
const toY = act.endCoordinates?.y ?? fromY;
|
|
382
|
+
const start = act.startCoordinates ?? act.coordinates;
|
|
383
|
+
const end = act.endCoordinates;
|
|
384
|
+
if (!start || !end) break;
|
|
385
385
|
result.push({
|
|
386
386
|
verb: 'drag',
|
|
387
|
-
fromX,
|
|
388
|
-
fromY,
|
|
389
|
-
toX,
|
|
390
|
-
toY,
|
|
391
|
-
x:
|
|
392
|
-
y:
|
|
387
|
+
fromX: start.x,
|
|
388
|
+
fromY: start.y,
|
|
389
|
+
toX: end.x,
|
|
390
|
+
toY: end.y,
|
|
391
|
+
x: end.x,
|
|
392
|
+
y: end.y
|
|
393
393
|
});
|
|
394
394
|
break;
|
|
395
395
|
}
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
import { TextLayer } from '../../tui/dialogs.js';
|
|
5
5
|
// @ts-expect-error untyped local TUI theme
|
|
6
6
|
import { GLYPHS } from '../../tui/theme.js';
|
|
7
|
+
import { safeDisplay } from '../../tui/text.js';
|
|
7
8
|
import { ContinuumPickerLayer } from './continuumPickerView.js';
|
|
8
9
|
import { ContinuumScanner } from '../scanner.js';
|
|
9
10
|
import { adoptContinuumSession } from '../ingest.js';
|
|
10
11
|
function formatTimeAgo(timestamp) {
|
|
11
|
-
|
|
12
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0)
|
|
13
|
+
return 'unknown';
|
|
14
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
12
15
|
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
13
16
|
if (minutes < 60)
|
|
14
17
|
return `${Math.max(1, minutes)}m ago`;
|
|
@@ -21,8 +24,10 @@ function formatTimeAgo(timestamp) {
|
|
|
21
24
|
export function buildContinuumItems(sessions) {
|
|
22
25
|
return sessions.map(s => {
|
|
23
26
|
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
27
|
+
const trimmedWs = s.workspacePath ? s.workspacePath.replace(/[/\\]+$/, '') : '';
|
|
28
|
+
const ws = trimmedWs ? trimmedWs.split(/[/\\]/).filter(Boolean).pop() || trimmedWs : '';
|
|
29
|
+
const safeMessageCount = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
|
|
30
|
+
const desc = `${safeMessageCount} msg${safeMessageCount === 1 ? '' : 's'} ${GLYPHS.dot} ${timeAgo}${ws ? ` ${GLYPHS.dot} ${ws}` : ''}`;
|
|
26
31
|
return {
|
|
27
32
|
label: s.title,
|
|
28
33
|
description: desc,
|
|
@@ -115,21 +120,24 @@ export async function openContinuumPreview(sessionId, prompt, scanner) {
|
|
|
115
120
|
if (!detail || !detail.messages) {
|
|
116
121
|
return false;
|
|
117
122
|
}
|
|
123
|
+
const safeSource = safeDisplay(String(detail.sourceLabel ?? '')).replace(/\s+/g, ' ').trim();
|
|
124
|
+
const safeWorkspace = safeDisplay(String(detail.workspacePath || '(default)')).replace(/\s+/g, ' ').trim();
|
|
125
|
+
const safeTitle = safeDisplay(String(detail.title ?? '')).replace(/\s+/g, ' ').trim();
|
|
118
126
|
const lines = [
|
|
119
|
-
`Source: ${
|
|
127
|
+
`Source: ${safeSource} · Messages: ${detail.messages.length} · Workspace: ${safeWorkspace}`,
|
|
120
128
|
'─'.repeat(70),
|
|
121
129
|
''
|
|
122
130
|
];
|
|
123
131
|
for (const msg of detail.messages) {
|
|
124
132
|
const rolePrefix = msg.role === 'user' ? 'USER' : 'ASSISTANT';
|
|
125
133
|
lines.push(`${rolePrefix}:`);
|
|
126
|
-
for (const textLine of msg.content.split('\n')) {
|
|
134
|
+
for (const textLine of safeDisplay(String(msg.content ?? '')).split('\n')) {
|
|
127
135
|
lines.push(` ${textLine}`);
|
|
128
136
|
}
|
|
129
137
|
lines.push('');
|
|
130
138
|
}
|
|
131
139
|
const layer = new TextLayer({
|
|
132
|
-
title: `Preview: ${
|
|
140
|
+
title: `Preview: ${safeTitle}`,
|
|
133
141
|
lines,
|
|
134
142
|
width: 76,
|
|
135
143
|
height: 22
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
import { TextLayer } from '../../tui/dialogs.js';
|
|
6
6
|
// @ts-expect-error untyped local TUI theme
|
|
7
7
|
import { GLYPHS } from '../../tui/theme.js';
|
|
8
|
+
import { safeDisplay } from '../../tui/text.js';
|
|
8
9
|
import { ContinuumPickerLayer } from './continuumPickerView.js';
|
|
9
10
|
import type { ContinuumSessionSummary } from '../types.js';
|
|
10
11
|
import { ContinuumScanner } from '../scanner.js';
|
|
11
12
|
import { adoptContinuumSession } from '../ingest.js';
|
|
12
13
|
|
|
13
14
|
function formatTimeAgo(timestamp: number): string {
|
|
14
|
-
|
|
15
|
+
if (!Number.isFinite(timestamp) || timestamp <= 0) return 'unknown';
|
|
16
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
15
17
|
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
16
18
|
if (minutes < 60) return `${Math.max(1, minutes)}m ago`;
|
|
17
19
|
const hours = Math.floor(minutes / 60);
|
|
@@ -23,8 +25,10 @@ function formatTimeAgo(timestamp: number): string {
|
|
|
23
25
|
export function buildContinuumItems(sessions: ContinuumSessionSummary[]) {
|
|
24
26
|
return sessions.map(s => {
|
|
25
27
|
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
+
const trimmedWs = s.workspacePath ? s.workspacePath.replace(/[/\\]+$/, '') : '';
|
|
29
|
+
const ws = trimmedWs ? trimmedWs.split(/[/\\]/).filter(Boolean).pop() || trimmedWs : '';
|
|
30
|
+
const safeMessageCount = Number.isFinite(s.messageCount) ? Math.max(0, Math.floor(s.messageCount)) : 0;
|
|
31
|
+
const desc = `${safeMessageCount} msg${safeMessageCount === 1 ? '' : 's'} ${GLYPHS.dot} ${timeAgo}${ws ? ` ${GLYPHS.dot} ${ws}` : ''}`;
|
|
28
32
|
|
|
29
33
|
return {
|
|
30
34
|
label: s.title,
|
|
@@ -146,8 +150,11 @@ export async function openContinuumPreview(
|
|
|
146
150
|
return false;
|
|
147
151
|
}
|
|
148
152
|
|
|
153
|
+
const safeSource = safeDisplay(String(detail.sourceLabel ?? '')).replace(/\s+/g, ' ').trim();
|
|
154
|
+
const safeWorkspace = safeDisplay(String(detail.workspacePath || '(default)')).replace(/\s+/g, ' ').trim();
|
|
155
|
+
const safeTitle = safeDisplay(String(detail.title ?? '')).replace(/\s+/g, ' ').trim();
|
|
149
156
|
const lines: string[] = [
|
|
150
|
-
`Source: ${
|
|
157
|
+
`Source: ${safeSource} · Messages: ${detail.messages.length} · Workspace: ${safeWorkspace}`,
|
|
151
158
|
'─'.repeat(70),
|
|
152
159
|
''
|
|
153
160
|
];
|
|
@@ -155,14 +162,14 @@ export async function openContinuumPreview(
|
|
|
155
162
|
for (const msg of detail.messages) {
|
|
156
163
|
const rolePrefix = msg.role === 'user' ? 'USER' : 'ASSISTANT';
|
|
157
164
|
lines.push(`${rolePrefix}:`);
|
|
158
|
-
for (const textLine of msg.content.split('\n')) {
|
|
165
|
+
for (const textLine of safeDisplay(String(msg.content ?? '')).split('\n')) {
|
|
159
166
|
lines.push(` ${textLine}`);
|
|
160
167
|
}
|
|
161
168
|
lines.push('');
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
const layer = new TextLayer({
|
|
165
|
-
title: `Preview: ${
|
|
172
|
+
title: `Preview: ${safeTitle}`,
|
|
166
173
|
lines,
|
|
167
174
|
width: 76,
|
|
168
175
|
height: 22
|
|
@@ -49,11 +49,12 @@ function relativeTime(timestamp, now) {
|
|
|
49
49
|
function countLabel(count) {
|
|
50
50
|
if (!Number.isFinite(count) || count < 0)
|
|
51
51
|
return '0 msgs';
|
|
52
|
-
|
|
52
|
+
const safeCount = Math.floor(count);
|
|
53
|
+
return `${safeCount.toLocaleString('en-US')} ${safeCount === 1 ? 'msg' : 'msgs'}`;
|
|
53
54
|
}
|
|
54
55
|
/** Fit two pieces of styled text in one terminal row, retaining the left title. */
|
|
55
56
|
function pairedRow(left, right, columns) {
|
|
56
|
-
const width = Math.max(1, Math.floor(columns));
|
|
57
|
+
const width = Number.isFinite(columns) ? Math.max(1, Math.min(512, Math.floor(columns))) : 80;
|
|
57
58
|
const rightWidth = visibleWidth(right);
|
|
58
59
|
if (!right || width < 45 || rightWidth > width - 20)
|
|
59
60
|
return truncate(left, width, '…');
|
|
@@ -72,9 +73,11 @@ export function sortContinuumItems(items) {
|
|
|
72
73
|
return [...items].sort((a, b) => {
|
|
73
74
|
const groupA = order.get(a.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
74
75
|
const groupB = order.get(b.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
76
|
+
const timeA = Number.isFinite(Number(a.value.updatedAt)) ? Number(a.value.updatedAt) : 0;
|
|
77
|
+
const timeB = Number.isFinite(Number(b.value.updatedAt)) ? Number(b.value.updatedAt) : 0;
|
|
75
78
|
return groupA - groupB
|
|
76
|
-
||
|
|
77
|
-
|| a.value.id.localeCompare(b.value.id);
|
|
79
|
+
|| timeB - timeA
|
|
80
|
+
|| String(a.value.id ?? '').localeCompare(String(b.value.id ?? ''));
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
83
|
function renderedItem(item, selected, width, now) {
|
|
@@ -92,12 +95,14 @@ function renderedItem(item, selected, width, now) {
|
|
|
92
95
|
*/
|
|
93
96
|
export function renderContinuumWindow(entries, start, selected, width, budget, now = Date.now()) {
|
|
94
97
|
const rows = [];
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
+
const safeStart = Number.isFinite(start) ? Math.max(0, Math.floor(start)) : 0;
|
|
99
|
+
const safeSelected = Number.isFinite(selected) ? Math.max(0, Math.floor(selected)) : 0;
|
|
100
|
+
const safeWidth = Number.isFinite(width) ? Math.max(1, Math.min(512, Math.floor(width))) : 80;
|
|
101
|
+
const allowed = Number.isFinite(budget) ? Math.max(0, Math.min(200, Math.floor(budget))) : 0;
|
|
102
|
+
let lastIndex = safeStart - 1;
|
|
98
103
|
let itemCount = 0;
|
|
99
104
|
let previousGroup = null;
|
|
100
|
-
for (let index =
|
|
105
|
+
for (let index = safeStart; index < entries.length; index++) {
|
|
101
106
|
const item = entries[index]?.item;
|
|
102
107
|
if (!item)
|
|
103
108
|
continue;
|
|
@@ -112,12 +117,12 @@ export function renderContinuumWindow(entries, start, selected, width, budget, n
|
|
|
112
117
|
else if (needHeader) {
|
|
113
118
|
rows.push(dim(` ${truncate(group.toUpperCase(), Math.max(1, safeWidth - 5), '…')}`));
|
|
114
119
|
}
|
|
115
|
-
rows.push(...renderedItem(item, index ===
|
|
120
|
+
rows.push(...renderedItem(item, index === safeSelected, safeWidth, now));
|
|
116
121
|
lastIndex = index;
|
|
117
122
|
itemCount++;
|
|
118
123
|
previousGroup = group;
|
|
119
124
|
}
|
|
120
|
-
return { rows, firstIndex:
|
|
125
|
+
return { rows, firstIndex: safeStart, lastIndex, itemCount };
|
|
121
126
|
}
|
|
122
127
|
export class ContinuumPickerLayer extends SelectLayer {
|
|
123
128
|
items;
|
|
@@ -178,7 +183,9 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
178
183
|
}
|
|
179
184
|
if (event.name === 'pageup' || event.name === 'pagedown') {
|
|
180
185
|
const direction = event.name === 'pageup' ? -1 : 1;
|
|
181
|
-
|
|
186
|
+
const curSelected = Number.isFinite(this.list.selected) ? Math.max(0, Math.floor(this.list.selected)) : 0;
|
|
187
|
+
const safeVisible = Number.isFinite(this.visibleItems) ? Math.max(1, Math.floor(this.visibleItems)) : 5;
|
|
188
|
+
this.list.moveTo(curSelected + direction * Math.max(1, safeVisible - 1), safeVisible);
|
|
182
189
|
return 'handled';
|
|
183
190
|
}
|
|
184
191
|
const query = this.list.query;
|
|
@@ -190,8 +197,8 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
190
197
|
return result;
|
|
191
198
|
}
|
|
192
199
|
body(width, height) {
|
|
193
|
-
const w = Math.max(8, Math.floor(width));
|
|
194
|
-
const h = Math.max(1, Math.floor(height));
|
|
200
|
+
const w = Number.isFinite(width) ? Math.max(8, Math.min(512, Math.floor(width))) : 80;
|
|
201
|
+
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
195
202
|
const rows = [];
|
|
196
203
|
const scope = this.scope;
|
|
197
204
|
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
@@ -222,8 +229,10 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
222
229
|
rows.push(dim(' Tab changes source. Ctrl+U clears search.'));
|
|
223
230
|
}
|
|
224
231
|
else if (budget > 0) {
|
|
225
|
-
const
|
|
226
|
-
|
|
232
|
+
const rawSelected = Number.isFinite(this.list.selected) ? Math.floor(this.list.selected) : 0;
|
|
233
|
+
const rawOffset = Number.isFinite(this.list.offset) ? Math.floor(this.list.offset) : 0;
|
|
234
|
+
const selected = Math.min(Math.max(0, rawSelected), count - 1);
|
|
235
|
+
let from = Math.min(Math.max(0, rawOffset), selected);
|
|
227
236
|
let output = renderContinuumWindow(filtered, from, selected, w, budget);
|
|
228
237
|
while (output.lastIndex < selected && from < selected) {
|
|
229
238
|
from++;
|
|
@@ -82,12 +82,13 @@ function relativeTime(timestamp: number, now: number): string {
|
|
|
82
82
|
|
|
83
83
|
function countLabel(count: number): string {
|
|
84
84
|
if (!Number.isFinite(count) || count < 0) return '0 msgs';
|
|
85
|
-
|
|
85
|
+
const safeCount = Math.floor(count);
|
|
86
|
+
return `${safeCount.toLocaleString('en-US')} ${safeCount === 1 ? 'msg' : 'msgs'}`;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/** Fit two pieces of styled text in one terminal row, retaining the left title. */
|
|
89
90
|
function pairedRow(left: string, right: string, columns: number): string {
|
|
90
|
-
const width = Math.max(1, Math.floor(columns));
|
|
91
|
+
const width = Number.isFinite(columns) ? Math.max(1, Math.min(512, Math.floor(columns))) : 80;
|
|
91
92
|
const rightWidth = visibleWidth(right);
|
|
92
93
|
if (!right || width < 45 || rightWidth > width - 20) return truncate(left, width, '…');
|
|
93
94
|
const title = truncate(left, Math.max(1, width - rightWidth - 2), '…');
|
|
@@ -107,9 +108,11 @@ export function sortContinuumItems(items: ContinuumPickerItem[]): ContinuumPicke
|
|
|
107
108
|
return [...items].sort((a, b) => {
|
|
108
109
|
const groupA = order.get(a.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
109
110
|
const groupB = order.get(b.value.sourcePlatform) ?? SOURCE_ORDER.length;
|
|
111
|
+
const timeA = Number.isFinite(Number(a.value.updatedAt)) ? Number(a.value.updatedAt) : 0;
|
|
112
|
+
const timeB = Number.isFinite(Number(b.value.updatedAt)) ? Number(b.value.updatedAt) : 0;
|
|
110
113
|
return groupA - groupB
|
|
111
|
-
||
|
|
112
|
-
|| a.value.id.localeCompare(b.value.id);
|
|
114
|
+
|| timeB - timeA
|
|
115
|
+
|| String(a.value.id ?? '').localeCompare(String(b.value.id ?? ''));
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -136,12 +139,14 @@ export function renderContinuumWindow(
|
|
|
136
139
|
width: number, budget: number, now = Date.now()
|
|
137
140
|
): ListWindow {
|
|
138
141
|
const rows: string[] = [];
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
+
const safeStart = Number.isFinite(start) ? Math.max(0, Math.floor(start)) : 0;
|
|
143
|
+
const safeSelected = Number.isFinite(selected) ? Math.max(0, Math.floor(selected)) : 0;
|
|
144
|
+
const safeWidth = Number.isFinite(width) ? Math.max(1, Math.min(512, Math.floor(width))) : 80;
|
|
145
|
+
const allowed = Number.isFinite(budget) ? Math.max(0, Math.min(200, Math.floor(budget))) : 0;
|
|
146
|
+
let lastIndex = safeStart - 1;
|
|
142
147
|
let itemCount = 0;
|
|
143
148
|
let previousGroup: string | null = null;
|
|
144
|
-
for (let index =
|
|
149
|
+
for (let index = safeStart; index < entries.length; index++) {
|
|
145
150
|
const item = entries[index]?.item;
|
|
146
151
|
if (!item) continue;
|
|
147
152
|
const group = sourceName(item.value);
|
|
@@ -153,12 +158,12 @@ export function renderContinuumWindow(
|
|
|
153
158
|
} else if (needHeader) {
|
|
154
159
|
rows.push(dim(` ${truncate(group.toUpperCase(), Math.max(1, safeWidth - 5), '…')}`));
|
|
155
160
|
}
|
|
156
|
-
rows.push(...renderedItem(item, index ===
|
|
161
|
+
rows.push(...renderedItem(item, index === safeSelected, safeWidth, now));
|
|
157
162
|
lastIndex = index;
|
|
158
163
|
itemCount++;
|
|
159
164
|
previousGroup = group;
|
|
160
165
|
}
|
|
161
|
-
return { rows, firstIndex:
|
|
166
|
+
return { rows, firstIndex: safeStart, lastIndex, itemCount };
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
export class ContinuumPickerLayer extends SelectLayer {
|
|
@@ -238,8 +243,9 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
238
243
|
}
|
|
239
244
|
if (event.name === 'pageup' || event.name === 'pagedown') {
|
|
240
245
|
const direction = event.name === 'pageup' ? -1 : 1;
|
|
241
|
-
|
|
242
|
-
|
|
246
|
+
const curSelected = Number.isFinite(this.list.selected) ? Math.max(0, Math.floor(this.list.selected)) : 0;
|
|
247
|
+
const safeVisible = Number.isFinite(this.visibleItems) ? Math.max(1, Math.floor(this.visibleItems)) : 5;
|
|
248
|
+
this.list.moveTo(curSelected + direction * Math.max(1, safeVisible - 1), safeVisible);
|
|
243
249
|
return 'handled';
|
|
244
250
|
}
|
|
245
251
|
const query = this.list.query;
|
|
@@ -252,8 +258,8 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
252
258
|
}
|
|
253
259
|
|
|
254
260
|
body(width: number, height: number): string[] {
|
|
255
|
-
const w = Math.max(8, Math.floor(width));
|
|
256
|
-
const h = Math.max(1, Math.floor(height));
|
|
261
|
+
const w = Number.isFinite(width) ? Math.max(8, Math.min(512, Math.floor(width))) : 80;
|
|
262
|
+
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
257
263
|
const rows: string[] = [];
|
|
258
264
|
const scope = this.scope;
|
|
259
265
|
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
@@ -284,8 +290,10 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
284
290
|
if (rows.length < h - details) rows.push(dim(' No sessions match this filter.'));
|
|
285
291
|
if (rows.length < h - details) rows.push(dim(' Tab changes source. Ctrl+U clears search.'));
|
|
286
292
|
} else if (budget > 0) {
|
|
287
|
-
const
|
|
288
|
-
|
|
293
|
+
const rawSelected = Number.isFinite(this.list.selected) ? Math.floor(this.list.selected) : 0;
|
|
294
|
+
const rawOffset = Number.isFinite(this.list.offset) ? Math.floor(this.list.offset) : 0;
|
|
295
|
+
const selected = Math.min(Math.max(0, rawSelected), count - 1);
|
|
296
|
+
let from = Math.min(Math.max(0, rawOffset), selected);
|
|
289
297
|
let output = renderContinuumWindow(filtered, from, selected, w, budget);
|
|
290
298
|
while (output.lastIndex < selected && from < selected) {
|
|
291
299
|
from++;
|