@causyne/agent 1.20.111 → 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/home.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SelectLayer, InputLayer } from './dialogs.js';
|
|
4
4
|
import { paint, dim, bold, badge, GLYPHS } from './theme.js';
|
|
5
|
+
import { safeDisplay } from './text.js';
|
|
5
6
|
import { runSetup } from './setup.js';
|
|
6
7
|
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
7
8
|
import { isAcpProvider } from '../providers/acp.js';
|
|
@@ -9,14 +10,21 @@ import { isAntigravityProvider, resolveAgyBinary } from '../providers/antigravit
|
|
|
9
10
|
import { isPiProvider, PI_SETUP_PROVIDER } from '../providers/pi.js';
|
|
10
11
|
import { isBinaryOnPath } from '../acp/agentCatalog.js';
|
|
11
12
|
|
|
13
|
+
function cleanSingleLine(value) {
|
|
14
|
+
return safeDisplay(typeof value === 'string' ? value : '').replace(/[\r\n]+/g, ' ').trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/** Local runtime and provider summary. */
|
|
13
18
|
export function homeStatusLine(arg = {}) {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
19
|
+
const rawObj = arg && typeof arg === 'object' ? arg : {};
|
|
20
|
+
const config = rawObj.config && typeof rawObj.config === 'object' ? rawObj.config : rawObj;
|
|
21
|
+
const provider = cleanSingleLine(config.provider);
|
|
22
|
+
const modelName = cleanSingleLine(config.model);
|
|
23
|
+
const hasProvider = Boolean(provider && provider !== 'unconfigured');
|
|
16
24
|
const model = hasProvider
|
|
17
|
-
? (
|
|
25
|
+
? (modelName ? `${provider}/${modelName}` : provider)
|
|
18
26
|
: 'no provider configured';
|
|
19
|
-
const configured = Boolean((hasProvider && config.apiKey) ||
|
|
27
|
+
const configured = Boolean((hasProvider && config.apiKey) || provider === 'ollama' || isAcpProvider(provider) || isAntigravityProvider(provider) || isPiProvider(provider));
|
|
20
28
|
return ' ' + [
|
|
21
29
|
paint('success', `${GLYPHS.bullet} local desktop`),
|
|
22
30
|
configured
|
|
@@ -118,7 +126,7 @@ export function moreLayer(onPick) {
|
|
|
118
126
|
category: action.category,
|
|
119
127
|
value: action
|
|
120
128
|
})),
|
|
121
|
-
onPick: (item) => onPick(item && item.value)
|
|
129
|
+
onPick: (item) => { if (typeof onPick === 'function') onPick(item && item.value); }
|
|
122
130
|
});
|
|
123
131
|
}
|
|
124
132
|
|
|
@@ -190,14 +198,18 @@ export async function mcpPicker(prompt, onAction) {
|
|
|
190
198
|
|
|
191
199
|
prompt.openLayer(new SelectLayer({
|
|
192
200
|
title: 'MCP servers',
|
|
193
|
-
items: rows.map((server) =>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
items: rows.map((server) => {
|
|
202
|
+
const name = cleanSingleLine(server?.name) || 'server';
|
|
203
|
+
const target = cleanSingleLine(server?.target);
|
|
204
|
+
return {
|
|
205
|
+
id: name,
|
|
206
|
+
label: name,
|
|
207
|
+
description: `${server?.granted ? 'granted' : 'not granted'}${target ? ` ${GLYPHS.dot} ${target}` : ''}`,
|
|
208
|
+
category: server?.granted ? 'granted' : 'available',
|
|
209
|
+
value: server
|
|
210
|
+
};
|
|
211
|
+
}),
|
|
212
|
+
onPick: (item) => { if (item && typeof onAction === 'function') onAction(item.value); }
|
|
201
213
|
}));
|
|
202
214
|
return { empty: false };
|
|
203
215
|
}
|
package/src/tui/homeView.js
CHANGED
|
@@ -12,43 +12,61 @@ export function isStartupDialog(surface) {
|
|
|
12
12
|
}
|
|
13
13
|
/** Keep startup pickers readable without letting a long catalogue resize the UI. */
|
|
14
14
|
export function startupDialogView(layer, columns, terminalRows) {
|
|
15
|
+
const safeLayer = layer && typeof layer === 'object' ? layer : {};
|
|
15
16
|
const availableWidth = Number.isFinite(columns) ? Math.max(8, Math.floor(columns) - 1) : 79;
|
|
16
17
|
const availableHeight = Number.isFinite(terminalRows) ? Math.max(4, Math.floor(terminalRows) - 2) : 20;
|
|
17
|
-
const
|
|
18
|
+
const requestedWidth = typeof safeLayer.width === 'number' && Number.isFinite(safeLayer.width) ? Math.floor(safeLayer.width) : 0;
|
|
19
|
+
const width = Math.min(availableWidth, 96, Math.max(88, requestedWidth));
|
|
18
20
|
const height = Math.min(availableHeight, 30);
|
|
19
21
|
const measuredLayer = {
|
|
20
|
-
title:
|
|
21
|
-
footer:
|
|
22
|
-
preferredHeight: () =>
|
|
23
|
-
|
|
22
|
+
title: safeLayer.title,
|
|
23
|
+
footer: safeLayer.footer,
|
|
24
|
+
preferredHeight: () => {
|
|
25
|
+
const raw = typeof safeLayer.preferredHeight === 'function' ? safeLayer.preferredHeight() : 14;
|
|
26
|
+
return Math.max(10, Number.isFinite(raw) ? raw : 14);
|
|
27
|
+
},
|
|
28
|
+
body: (innerWidth, bodyHeight) => typeof safeLayer.body === 'function' ? safeLayer.body(innerWidth, bodyHeight) : []
|
|
24
29
|
};
|
|
25
|
-
const centered = centerRows(panelRows(measuredLayer, width, height),
|
|
26
|
-
const cursor =
|
|
30
|
+
const centered = centerRows(panelRows(measuredLayer, width, height), availableWidth + 1);
|
|
31
|
+
const cursor = safeLayer.cursor;
|
|
32
|
+
const safeCursorY = cursor && Number.isFinite(cursor.y) ? Math.max(0, Math.floor(cursor.y)) : null;
|
|
33
|
+
const safeCursorX = cursor && Number.isFinite(cursor.x) ? Math.max(0, Math.floor(cursor.x)) : null;
|
|
34
|
+
const maxRow = Math.max(0, centered.rows.length - 1);
|
|
35
|
+
const maxCol = Math.max(0, availableWidth - 1);
|
|
27
36
|
return {
|
|
28
37
|
rows: centered.rows,
|
|
29
|
-
caretRow:
|
|
30
|
-
caretCol: centered.inset + (
|
|
38
|
+
caretRow: safeCursorY !== null ? Math.min(maxRow, 1 + safeCursorY) : 0,
|
|
39
|
+
caretCol: Math.max(0, Math.min(maxCol, centered.inset + (safeCursorX !== null ? 2 + safeCursorX : 0)))
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
/** Center a temporary dialog in the available terminal region. */
|
|
34
43
|
export function placeDialog(rows, columns, height, caretRow, caretCol) {
|
|
35
|
-
const available = Math.max(1, Math.floor(height));
|
|
36
|
-
const
|
|
44
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 1;
|
|
45
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(2, Math.floor(columns)) : 80;
|
|
46
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
47
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
48
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
49
|
+
const shown = safeRows.slice(0, available);
|
|
37
50
|
const top = Math.max(0, Math.floor((available - shown.length) / 2));
|
|
38
51
|
return {
|
|
39
52
|
rows: [...Array(top).fill(''), ...shown],
|
|
40
|
-
caretRow: top + Math.min(Math.max(0,
|
|
41
|
-
caretCol: Math.max(0, Math.min(
|
|
53
|
+
caretRow: top + Math.max(0, Math.min(safeCaretRow, Math.max(0, shown.length - 1))),
|
|
54
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, safeColumns - 2))
|
|
42
55
|
};
|
|
43
56
|
}
|
|
44
57
|
/** A clean first screen; session messages are intentionally absent. */
|
|
45
58
|
export function placeHome(info, promptRows, columns, height, caretRow, caretCol) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
59
|
+
const safeInfo = info && typeof info === 'object' ? info : {};
|
|
60
|
+
const safePromptRows = Array.isArray(promptRows) ? promptRows : [];
|
|
61
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
62
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 24;
|
|
63
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
64
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
65
|
+
const logo = centerRows(sessionBanner(safeInfo, safeColumns, { height: available }), safeColumns).rows;
|
|
48
66
|
const spacer = available >= 25 ? 2 : 1;
|
|
49
67
|
// When the window is short, preserve the composer and editing caret first.
|
|
50
68
|
// The logo yields height; it must never push a wrapped draft off-screen.
|
|
51
|
-
const fitted = fitHomeContent(logo,
|
|
69
|
+
const fitted = fitHomeContent(logo, safePromptRows, available, safeCaretRow, spacer);
|
|
52
70
|
const required = fitted.logoRows.length + fitted.spacer + fitted.promptRows.length;
|
|
53
71
|
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
54
72
|
const rows = [
|
|
@@ -57,9 +75,10 @@ export function placeHome(info, promptRows, columns, height, caretRow, caretCol)
|
|
|
57
75
|
...Array(fitted.spacer).fill(''),
|
|
58
76
|
...fitted.promptRows
|
|
59
77
|
];
|
|
78
|
+
const maxRow = Math.max(0, rows.length - 1);
|
|
60
79
|
return {
|
|
61
80
|
rows,
|
|
62
|
-
caretRow: top + fitted.logoRows.length + fitted.spacer + fitted.caretRow,
|
|
63
|
-
caretCol: Math.max(0, Math.min(
|
|
81
|
+
caretRow: Math.max(0, Math.min(maxRow, top + fitted.logoRows.length + fitted.spacer + fitted.caretRow)),
|
|
82
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, Math.max(0, safeColumns - 2)))
|
|
64
83
|
};
|
|
65
84
|
}
|
package/src/tui/homeView.ts
CHANGED
|
@@ -32,34 +32,48 @@ export function isStartupDialog(surface: StartupSurface | null | undefined): boo
|
|
|
32
32
|
|
|
33
33
|
/** Keep startup pickers readable without letting a long catalogue resize the UI. */
|
|
34
34
|
export function startupDialogView(layer: StartupLayer, columns: number, terminalRows: number): PlacedView {
|
|
35
|
+
const safeLayer: Partial<StartupLayer> = layer && typeof layer === 'object' ? layer : {};
|
|
35
36
|
const availableWidth = Number.isFinite(columns) ? Math.max(8, Math.floor(columns) - 1) : 79;
|
|
36
37
|
const availableHeight = Number.isFinite(terminalRows) ? Math.max(4, Math.floor(terminalRows) - 2) : 20;
|
|
37
|
-
const
|
|
38
|
+
const requestedWidth = typeof safeLayer.width === 'number' && Number.isFinite(safeLayer.width) ? Math.floor(safeLayer.width) : 0;
|
|
39
|
+
const width = Math.min(availableWidth, 96, Math.max(88, requestedWidth));
|
|
38
40
|
const height = Math.min(availableHeight, 30);
|
|
39
41
|
const measuredLayer = {
|
|
40
|
-
title:
|
|
41
|
-
footer:
|
|
42
|
-
preferredHeight: () =>
|
|
43
|
-
|
|
42
|
+
title: safeLayer.title,
|
|
43
|
+
footer: safeLayer.footer,
|
|
44
|
+
preferredHeight: () => {
|
|
45
|
+
const raw = typeof safeLayer.preferredHeight === 'function' ? safeLayer.preferredHeight() : 14;
|
|
46
|
+
return Math.max(10, Number.isFinite(raw) ? raw : 14);
|
|
47
|
+
},
|
|
48
|
+
body: (innerWidth: number, bodyHeight: number) =>
|
|
49
|
+
typeof safeLayer.body === 'function' ? safeLayer.body(innerWidth, bodyHeight) : []
|
|
44
50
|
};
|
|
45
|
-
const centered = centerRows(panelRows(measuredLayer, width, height) as string[],
|
|
46
|
-
const cursor =
|
|
51
|
+
const centered = centerRows(panelRows(measuredLayer, width, height) as string[], availableWidth + 1);
|
|
52
|
+
const cursor = safeLayer.cursor;
|
|
53
|
+
const safeCursorY = cursor && Number.isFinite(cursor.y) ? Math.max(0, Math.floor(cursor.y)) : null;
|
|
54
|
+
const safeCursorX = cursor && Number.isFinite(cursor.x) ? Math.max(0, Math.floor(cursor.x)) : null;
|
|
55
|
+
const maxRow = Math.max(0, centered.rows.length - 1);
|
|
56
|
+
const maxCol = Math.max(0, availableWidth - 1);
|
|
47
57
|
return {
|
|
48
58
|
rows: centered.rows,
|
|
49
|
-
caretRow:
|
|
50
|
-
caretCol: centered.inset + (
|
|
59
|
+
caretRow: safeCursorY !== null ? Math.min(maxRow, 1 + safeCursorY) : 0,
|
|
60
|
+
caretCol: Math.max(0, Math.min(maxCol, centered.inset + (safeCursorX !== null ? 2 + safeCursorX : 0)))
|
|
51
61
|
};
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
/** Center a temporary dialog in the available terminal region. */
|
|
55
65
|
export function placeDialog(rows: string[], columns: number, height: number, caretRow: number, caretCol: number): PlacedView {
|
|
56
|
-
const available = Math.max(1, Math.floor(height));
|
|
57
|
-
const
|
|
66
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 1;
|
|
67
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(2, Math.floor(columns)) : 80;
|
|
68
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
69
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
70
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
71
|
+
const shown = safeRows.slice(0, available);
|
|
58
72
|
const top = Math.max(0, Math.floor((available - shown.length) / 2));
|
|
59
73
|
return {
|
|
60
74
|
rows: [...Array<string>(top).fill(''), ...shown],
|
|
61
|
-
caretRow: top + Math.min(Math.max(0,
|
|
62
|
-
caretCol: Math.max(0, Math.min(
|
|
75
|
+
caretRow: top + Math.max(0, Math.min(safeCaretRow, Math.max(0, shown.length - 1))),
|
|
76
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, safeColumns - 2))
|
|
63
77
|
};
|
|
64
78
|
}
|
|
65
79
|
|
|
@@ -72,12 +86,17 @@ export function placeHome(
|
|
|
72
86
|
caretRow: number,
|
|
73
87
|
caretCol: number
|
|
74
88
|
): PlacedView {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
89
|
+
const safeInfo: BannerInfo = info && typeof info === 'object' ? info : {};
|
|
90
|
+
const safePromptRows = Array.isArray(promptRows) ? promptRows : [];
|
|
91
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
92
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 24;
|
|
93
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
94
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
95
|
+
const logo = centerRows(sessionBanner(safeInfo, safeColumns, { height: available }), safeColumns).rows;
|
|
77
96
|
const spacer = available >= 25 ? 2 : 1;
|
|
78
97
|
// When the window is short, preserve the composer and editing caret first.
|
|
79
98
|
// The logo yields height; it must never push a wrapped draft off-screen.
|
|
80
|
-
const fitted = fitHomeContent(logo,
|
|
99
|
+
const fitted = fitHomeContent(logo, safePromptRows, available, safeCaretRow, spacer);
|
|
81
100
|
const required = fitted.logoRows.length + fitted.spacer + fitted.promptRows.length;
|
|
82
101
|
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
83
102
|
const rows = [
|
|
@@ -86,9 +105,10 @@ export function placeHome(
|
|
|
86
105
|
...Array<string>(fitted.spacer).fill(''),
|
|
87
106
|
...fitted.promptRows
|
|
88
107
|
];
|
|
108
|
+
const maxRow = Math.max(0, rows.length - 1);
|
|
89
109
|
return {
|
|
90
110
|
rows,
|
|
91
|
-
caretRow: top + fitted.logoRows.length + fitted.spacer + fitted.caretRow,
|
|
92
|
-
caretCol: Math.max(0, Math.min(
|
|
111
|
+
caretRow: Math.max(0, Math.min(maxRow, top + fitted.logoRows.length + fitted.spacer + fitted.caretRow)),
|
|
112
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, Math.max(0, safeColumns - 2)))
|
|
93
113
|
};
|
|
94
114
|
}
|
package/src/tui/inlineSlash.js
CHANGED
|
@@ -17,19 +17,20 @@ const COMMAND = /(?:^|[ \t\r\n])\/([a-z0-9_?-]*)$/i;
|
|
|
17
17
|
export function detectInlineSlashTrigger(text, cursor) {
|
|
18
18
|
if (typeof text !== 'string' || !Number.isFinite(cursor))
|
|
19
19
|
return null;
|
|
20
|
-
|
|
20
|
+
const position = Math.trunc(cursor);
|
|
21
|
+
if (position < 0 || position > text.length)
|
|
21
22
|
return null;
|
|
22
|
-
const before = text.slice(0,
|
|
23
|
+
const before = text.slice(0, position);
|
|
23
24
|
const argument = ARGUMENT.exec(before);
|
|
24
25
|
if (argument) {
|
|
25
26
|
const fragment = argument[0];
|
|
26
|
-
const offset =
|
|
27
|
+
const offset = position - fragment.length + fragment.indexOf('/');
|
|
27
28
|
const query = argument[2] ?? '';
|
|
28
29
|
return {
|
|
29
30
|
kind: 'command-argument',
|
|
30
31
|
command: argument[1] ?? '',
|
|
31
32
|
query,
|
|
32
|
-
start:
|
|
33
|
+
start: position - query.length,
|
|
33
34
|
tokenStart: offset,
|
|
34
35
|
inline: before.slice(0, offset).trim().length > 0
|
|
35
36
|
};
|
|
@@ -38,7 +39,7 @@ export function detectInlineSlashTrigger(text, cursor) {
|
|
|
38
39
|
if (!command)
|
|
39
40
|
return null;
|
|
40
41
|
const fragment = command[0];
|
|
41
|
-
const offset =
|
|
42
|
+
const offset = position - fragment.length + fragment.indexOf('/');
|
|
42
43
|
return {
|
|
43
44
|
kind: 'command',
|
|
44
45
|
query: command[1] ?? '',
|
package/src/tui/inlineSlash.ts
CHANGED
|
@@ -40,19 +40,20 @@ const COMMAND = /(?:^|[ \t\r\n])\/([a-z0-9_?-]*)$/i;
|
|
|
40
40
|
*/
|
|
41
41
|
export function detectInlineSlashTrigger(text: string, cursor: number): SlashTrigger | null {
|
|
42
42
|
if (typeof text !== 'string' || !Number.isFinite(cursor)) return null;
|
|
43
|
-
|
|
43
|
+
const position = Math.trunc(cursor);
|
|
44
|
+
if (position < 0 || position > text.length) return null;
|
|
44
45
|
|
|
45
|
-
const before = text.slice(0,
|
|
46
|
+
const before = text.slice(0, position);
|
|
46
47
|
const argument = ARGUMENT.exec(before);
|
|
47
48
|
if (argument) {
|
|
48
49
|
const fragment = argument[0];
|
|
49
|
-
const offset =
|
|
50
|
+
const offset = position - fragment.length + fragment.indexOf('/');
|
|
50
51
|
const query = argument[2] ?? '';
|
|
51
52
|
return {
|
|
52
53
|
kind: 'command-argument',
|
|
53
54
|
command: argument[1] ?? '',
|
|
54
55
|
query,
|
|
55
|
-
start:
|
|
56
|
+
start: position - query.length,
|
|
56
57
|
tokenStart: offset,
|
|
57
58
|
inline: before.slice(0, offset).trim().length > 0
|
|
58
59
|
};
|
|
@@ -61,7 +62,7 @@ export function detectInlineSlashTrigger(text: string, cursor: number): SlashTri
|
|
|
61
62
|
const command = COMMAND.exec(before);
|
|
62
63
|
if (!command) return null;
|
|
63
64
|
const fragment = command[0];
|
|
64
|
-
const offset =
|
|
65
|
+
const offset = position - fragment.length + fragment.indexOf('/');
|
|
65
66
|
return {
|
|
66
67
|
kind: 'command',
|
|
67
68
|
query: command[1] ?? '',
|
package/src/tui/keys.js
CHANGED
|
@@ -64,11 +64,16 @@ function applyModifier(key, modifier) {
|
|
|
64
64
|
*/
|
|
65
65
|
function utf8Length(buffer, offset) {
|
|
66
66
|
const byte = buffer[offset];
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
if (byte < 0x80) return 1;
|
|
68
|
+
// Continuation bytes, overlong C0/C1, and > U+10FFFF lead bytes (>= F5)
|
|
69
|
+
// are never valid multi-byte starts; consume one byte rather than wedging input.
|
|
70
|
+
if (byte < 0xc2 || byte > 0xf4) return 1;
|
|
71
|
+
const needed = byte >= 0xf0 ? 4 : byte >= 0xe0 ? 3 : 2;
|
|
72
|
+
for (let i = 1; i < needed; i++) {
|
|
73
|
+
if (offset + i >= buffer.length) return 0;
|
|
74
|
+
if ((buffer[offset + i] & 0xc0) !== 0x80) return 1;
|
|
75
|
+
}
|
|
76
|
+
return needed;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
@@ -311,20 +316,21 @@ export class KeyDecoder {
|
|
|
311
316
|
const final = text[index];
|
|
312
317
|
const params = text.slice(2, index);
|
|
313
318
|
const sequence = text.slice(0, index + 1);
|
|
319
|
+
const byteLength = Buffer.byteLength(sequence, 'utf8');
|
|
314
320
|
const numbers = params.split(/[;:]/).map((part) => parseInt(part, 10));
|
|
315
321
|
|
|
316
322
|
// SGR mouse: ESC [ < b ; x ; y M|m. `<` is 0x3C, outside the @..~ final
|
|
317
323
|
// range, so the scan above already found the right final byte.
|
|
318
324
|
if ((final === 'M' || final === 'm') && params.startsWith('<')) {
|
|
319
325
|
return this.emitMouse(params.slice(1).split(';').map((n) => parseInt(n, 10)),
|
|
320
|
-
final === 'M', sequence, events);
|
|
326
|
+
final === 'M', sequence, events, byteLength);
|
|
321
327
|
}
|
|
322
328
|
|
|
323
329
|
if (final === '~') {
|
|
324
330
|
const name = CSI_TILDE_NAMES[numbers[0]];
|
|
325
331
|
if (name) {
|
|
326
332
|
events.push(applyModifier(makeKey(name, { sequence }), numbers[1]));
|
|
327
|
-
return
|
|
333
|
+
return byteLength;
|
|
328
334
|
}
|
|
329
335
|
} else if (final === 'u') {
|
|
330
336
|
// Kitty keyboard protocol: ESC [ codepoint ; modifiers u
|
|
@@ -338,9 +344,14 @@ export class KeyDecoder {
|
|
|
338
344
|
}[codepoint];
|
|
339
345
|
if (controlName) {
|
|
340
346
|
events.push(applyModifier(makeKey(controlName, { sequence }), numbers[1]));
|
|
341
|
-
return
|
|
347
|
+
return byteLength;
|
|
342
348
|
}
|
|
343
|
-
if (
|
|
349
|
+
if (
|
|
350
|
+
Number.isFinite(codepoint) &&
|
|
351
|
+
codepoint >= 32 &&
|
|
352
|
+
codepoint <= 0x10ffff &&
|
|
353
|
+
(codepoint < 0xd800 || codepoint > 0xdfff)
|
|
354
|
+
) {
|
|
344
355
|
const character = String.fromCodePoint(codepoint);
|
|
345
356
|
const key = applyModifier(
|
|
346
357
|
makeKey('char', { sequence, text: character }),
|
|
@@ -350,7 +361,7 @@ export class KeyDecoder {
|
|
|
350
361
|
if (key.ctrl || key.alt) key.text = '';
|
|
351
362
|
if (key.name === 'char' && !key.text) key.name = character.toLowerCase();
|
|
352
363
|
events.push(key);
|
|
353
|
-
return
|
|
364
|
+
return byteLength;
|
|
354
365
|
}
|
|
355
366
|
} else if (CSI_FINAL_NAMES[final]) {
|
|
356
367
|
const key = applyModifier(
|
|
@@ -360,13 +371,13 @@ export class KeyDecoder {
|
|
|
360
371
|
// ESC [ Z is Shift+Tab and carries no modifier parameter of its own.
|
|
361
372
|
if (final === 'Z') key.shift = true;
|
|
362
373
|
events.push(key);
|
|
363
|
-
return
|
|
374
|
+
return byteLength;
|
|
364
375
|
}
|
|
365
376
|
|
|
366
377
|
// Unknown but well-formed: consume it so it can never reach the buffer as
|
|
367
378
|
// literal text and corrupt the line the user is editing.
|
|
368
379
|
events.push(makeKey('unknown', { sequence }));
|
|
369
|
-
return
|
|
380
|
+
return byteLength;
|
|
370
381
|
}
|
|
371
382
|
|
|
372
383
|
stepX10Mouse(buffer, offset, events) {
|
|
@@ -389,11 +400,11 @@ export class KeyDecoder {
|
|
|
389
400
|
* reaching the line the user is editing, and naming it lets a caller act on
|
|
390
401
|
* it later without another decoder change.
|
|
391
402
|
*/
|
|
392
|
-
emitMouse(numbers, pressed, sequence, events) {
|
|
403
|
+
emitMouse(numbers, pressed, sequence, events, byteLength = sequence.length) {
|
|
393
404
|
const [code, column, row] = numbers;
|
|
394
405
|
if (!Number.isFinite(code) || !Number.isFinite(column) || !Number.isFinite(row)) {
|
|
395
406
|
events.push(makeKey('unknown', { sequence }));
|
|
396
|
-
return
|
|
407
|
+
return byteLength;
|
|
397
408
|
}
|
|
398
409
|
|
|
399
410
|
// Modifier bits live in the button code for mouse reports, not in a CSI
|
|
@@ -404,14 +415,14 @@ export class KeyDecoder {
|
|
|
404
415
|
ctrl: (code & 16) !== 0
|
|
405
416
|
};
|
|
406
417
|
// Wire coordinates are 1-based.
|
|
407
|
-
const at = { x: column - 1, y: row - 1 };
|
|
418
|
+
const at = { x: Math.max(0, column - 1), y: Math.max(0, row - 1) };
|
|
408
419
|
|
|
409
420
|
if ((code & 64) !== 0) {
|
|
410
421
|
const direction = ['up', 'down', 'left', 'right'][code & 3];
|
|
411
422
|
// A wheel report arrives as a press; there is no release to pair it with.
|
|
412
423
|
if (pressed) {
|
|
413
424
|
events.push(makeKey('wheel', { sequence, ...modifiers, wheel: { direction, ...at } }));
|
|
414
|
-
return
|
|
425
|
+
return byteLength;
|
|
415
426
|
}
|
|
416
427
|
}
|
|
417
428
|
|
|
@@ -419,7 +430,7 @@ export class KeyDecoder {
|
|
|
419
430
|
sequence, ...modifiers,
|
|
420
431
|
mouse: { button: code & 3, pressed, ...at }
|
|
421
432
|
}));
|
|
422
|
-
return
|
|
433
|
+
return byteLength;
|
|
423
434
|
}
|
|
424
435
|
|
|
425
436
|
stepSS3(buffer, offset, events) {
|
|
@@ -501,6 +512,11 @@ export function bracketedPaste(enabled) {
|
|
|
501
512
|
* @param {string} letter Single character to test, case-insensitive.
|
|
502
513
|
* @returns {boolean}
|
|
503
514
|
*/
|
|
515
|
+
export function isMouseMotion(sequence) {
|
|
516
|
+
const code = Number(/^\x1b\[<(\d+);/.exec(sequence || '')?.[1]);
|
|
517
|
+
return Number.isFinite(code) && (code & 32) !== 0;
|
|
518
|
+
}
|
|
519
|
+
|
|
504
520
|
export function isChar(event, letter) {
|
|
505
521
|
if (!event || event.ctrl || event.alt || event.meta) return false;
|
|
506
522
|
const typed = typeof event.text === 'string' && event.text.length > 0
|
package/src/tui/layout.js
CHANGED
|
@@ -6,41 +6,59 @@ export function composerWidth(columns) {
|
|
|
6
6
|
}
|
|
7
7
|
/** Center one content column without centering each line independently. */
|
|
8
8
|
export function centerRows(rows, columns) {
|
|
9
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
9
10
|
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
10
|
-
const
|
|
11
|
+
const maxContent = Math.max(1, available - 1);
|
|
12
|
+
const occupied = safeRows.reduce((widest, row) => Math.max(widest, Math.min(maxContent, visibleWidth(row))), 0);
|
|
11
13
|
const inset = Math.max(0, Math.floor((available - occupied) / 2));
|
|
12
14
|
const prefix = ' '.repeat(inset);
|
|
13
|
-
|
|
15
|
+
const limit = Math.max(1, available - inset - 1);
|
|
16
|
+
return {
|
|
17
|
+
rows: safeRows.map(row => (row ? prefix + truncate(row, limit, '') : '')),
|
|
18
|
+
inset
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
21
|
/** Conversation content starts at the left margin while Home stays centered. */
|
|
16
22
|
export function sessionRows(rows, columns) {
|
|
23
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
17
24
|
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
18
25
|
const inset = Math.min(3, Math.max(0, available - 3));
|
|
19
26
|
const prefix = ' '.repeat(inset);
|
|
20
27
|
return {
|
|
21
|
-
rows:
|
|
28
|
+
rows: safeRows.map(row => row ? prefix + truncate(row, Math.max(1, available - inset - 1), '') : ''),
|
|
22
29
|
inset
|
|
23
30
|
};
|
|
24
31
|
}
|
|
25
32
|
/** Leave room for a centered home composition without overflowing small terminals. */
|
|
26
33
|
export function openingTopGap(rows, introRows) {
|
|
27
|
-
if (!Number.isFinite(rows) || rows < 40)
|
|
34
|
+
if (!Number.isFinite(rows) || rows < 40 || introRows === Number.POSITIVE_INFINITY)
|
|
28
35
|
return 0;
|
|
29
|
-
|
|
36
|
+
const safeRows = Math.floor(rows);
|
|
37
|
+
const safeIntro = Number.isFinite(introRows) ? Math.max(0, Math.floor(introRows)) : 0;
|
|
38
|
+
return Math.max(0, Math.min(40, Math.floor((safeRows - safeIntro - 8) / 2)));
|
|
30
39
|
}
|
|
31
40
|
/** Place the home composition as one centered group, with room for the composer below. */
|
|
32
41
|
export function openingRows(rows, columns, terminalRows) {
|
|
42
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
43
|
+
if (safeRows.length === 0)
|
|
44
|
+
return [];
|
|
33
45
|
return [
|
|
34
|
-
...Array(openingTopGap(terminalRows,
|
|
35
|
-
...centerRows(
|
|
46
|
+
...Array(openingTopGap(terminalRows, safeRows.length)).fill(''),
|
|
47
|
+
...centerRows(safeRows, columns).rows
|
|
36
48
|
];
|
|
37
49
|
}
|
|
50
|
+
function positiveRequested(requested, fallback) {
|
|
51
|
+
if (!Number.isFinite(requested))
|
|
52
|
+
return fallback;
|
|
53
|
+
const floored = Math.floor(requested);
|
|
54
|
+
return floored > 0 ? floored : fallback;
|
|
55
|
+
}
|
|
38
56
|
/** Fit every dialog, including text reports, inside the current terminal width. */
|
|
39
57
|
export function dialogWidth(columns, requested) {
|
|
40
58
|
const available = Number.isFinite(columns) ? Math.max(4, Math.floor(columns) - 1) : 79;
|
|
41
|
-
return Math.max(4, Math.min(available,
|
|
59
|
+
return Math.max(4, Math.min(available, positiveRequested(requested, available)));
|
|
42
60
|
}
|
|
43
61
|
export function dialogHeight(available, requested) {
|
|
44
62
|
const room = Number.isFinite(available) ? Math.max(4, Math.floor(available) - 1) : 20;
|
|
45
|
-
return Math.max(4, Math.min(20, room,
|
|
63
|
+
return Math.max(4, Math.min(20, room, positiveRequested(requested, room)));
|
|
46
64
|
}
|
package/src/tui/layout.ts
CHANGED
|
@@ -8,45 +8,62 @@ export function composerWidth(columns: number): number {
|
|
|
8
8
|
|
|
9
9
|
/** Center one content column without centering each line independently. */
|
|
10
10
|
export function centerRows(rows: string[], columns: number): { rows: string[]; inset: number } {
|
|
11
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
11
12
|
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
12
|
-
const
|
|
13
|
+
const maxContent = Math.max(1, available - 1);
|
|
14
|
+
const occupied = safeRows.reduce((widest, row) => Math.max(widest, Math.min(maxContent, visibleWidth(row))), 0);
|
|
13
15
|
const inset = Math.max(0, Math.floor((available - occupied) / 2));
|
|
14
16
|
const prefix = ' '.repeat(inset);
|
|
15
|
-
|
|
17
|
+
const limit = Math.max(1, available - inset - 1);
|
|
18
|
+
return {
|
|
19
|
+
rows: safeRows.map(row => (row ? prefix + truncate(row, limit, '') : '')),
|
|
20
|
+
inset
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
/** Conversation content starts at the left margin while Home stays centered. */
|
|
19
25
|
export function sessionRows(rows: string[], columns: number): { rows: string[]; inset: number } {
|
|
26
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
20
27
|
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
21
28
|
const inset = Math.min(3, Math.max(0, available - 3));
|
|
22
29
|
const prefix = ' '.repeat(inset);
|
|
23
30
|
return {
|
|
24
|
-
rows:
|
|
31
|
+
rows: safeRows.map(row => row ? prefix + truncate(row, Math.max(1, available - inset - 1), '') : ''),
|
|
25
32
|
inset
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
/** Leave room for a centered home composition without overflowing small terminals. */
|
|
30
37
|
export function openingTopGap(rows: number, introRows: number): number {
|
|
31
|
-
if (!Number.isFinite(rows) || rows < 40) return 0;
|
|
32
|
-
|
|
38
|
+
if (!Number.isFinite(rows) || rows < 40 || introRows === Number.POSITIVE_INFINITY) return 0;
|
|
39
|
+
const safeRows = Math.floor(rows);
|
|
40
|
+
const safeIntro = Number.isFinite(introRows) ? Math.max(0, Math.floor(introRows)) : 0;
|
|
41
|
+
return Math.max(0, Math.min(40, Math.floor((safeRows - safeIntro - 8) / 2)));
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
/** Place the home composition as one centered group, with room for the composer below. */
|
|
36
45
|
export function openingRows(rows: string[], columns: number, terminalRows: number): string[] {
|
|
46
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
47
|
+
if (safeRows.length === 0) return [];
|
|
37
48
|
return [
|
|
38
|
-
...Array<string>(openingTopGap(terminalRows,
|
|
39
|
-
...centerRows(
|
|
49
|
+
...Array<string>(openingTopGap(terminalRows, safeRows.length)).fill(''),
|
|
50
|
+
...centerRows(safeRows, columns).rows
|
|
40
51
|
];
|
|
41
52
|
}
|
|
42
53
|
|
|
54
|
+
function positiveRequested(requested: number, fallback: number): number {
|
|
55
|
+
if (!Number.isFinite(requested)) return fallback;
|
|
56
|
+
const floored = Math.floor(requested);
|
|
57
|
+
return floored > 0 ? floored : fallback;
|
|
58
|
+
}
|
|
59
|
+
|
|
43
60
|
/** Fit every dialog, including text reports, inside the current terminal width. */
|
|
44
61
|
export function dialogWidth(columns: number, requested: number): number {
|
|
45
62
|
const available = Number.isFinite(columns) ? Math.max(4, Math.floor(columns) - 1) : 79;
|
|
46
|
-
return Math.max(4, Math.min(available,
|
|
63
|
+
return Math.max(4, Math.min(available, positiveRequested(requested, available)));
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
export function dialogHeight(available: number, requested: number): number {
|
|
50
67
|
const room = Number.isFinite(available) ? Math.max(4, Math.floor(available) - 1) : 20;
|
|
51
|
-
return Math.max(4, Math.min(20, room,
|
|
68
|
+
return Math.max(4, Math.min(20, room, positiveRequested(requested, room)));
|
|
52
69
|
}
|