@causyne/agent 1.20.0 → 1.20.7
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/README.md +13 -9
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/client.js +176 -26
- package/src/acp/client.ts +167 -25
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +681 -245
- package/src/agentLoop.ts +708 -262
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +173 -18
- package/src/providers/acp.ts +169 -19
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +674 -34
- package/src/providers/antigravity.ts +707 -35
- package/src/providers/base.d.ts +10 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +161 -0
- package/src/providers/pi.ts +148 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +23 -0
- package/src/tui/chatRenderer.js +49 -49
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +132 -0
- package/src/tui/codeStreamRenderer.ts +141 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +131 -0
- package/src/tui/composerControls.ts +184 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +175 -101
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +6 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { padEnd, safeDisplay, truncate } from './text.js';
|
|
2
|
+
// The terminal theme is still a standalone JavaScript module in the TS migration.
|
|
3
|
+
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
4
|
+
import { bold, dim, fill, paint } from './theme.js';
|
|
5
|
+
export const SIDEBAR_WIDTH = 42;
|
|
6
|
+
export const SIDEBAR_THRESHOLD = 120;
|
|
7
|
+
/** A side panel is useful only when a readable conversation column remains. */
|
|
8
|
+
export function sidebarVisible(columns, home = false) {
|
|
9
|
+
return !home && Number.isFinite(columns) && columns > SIDEBAR_THRESHOLD;
|
|
10
|
+
}
|
|
11
|
+
/** Reserve the last terminal column so a wide row cannot wrap the stage. */
|
|
12
|
+
export function sessionMainWidth(columns, home = false) {
|
|
13
|
+
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
14
|
+
return sidebarVisible(width, home) ? width - SIDEBAR_WIDTH - 1 : width;
|
|
15
|
+
}
|
|
16
|
+
/** The session input uses the available conversation column, with a small inset. */
|
|
17
|
+
export function sessionComposerWidth(columns) {
|
|
18
|
+
return Number.isFinite(columns) ? Math.max(20, Math.floor(columns) - 3) : 77;
|
|
19
|
+
}
|
|
20
|
+
/** Render only facts the runtime can actually report. */
|
|
21
|
+
export function sessionSidebarRows(facts, height) {
|
|
22
|
+
const inner = SIDEBAR_WIDTH - 4;
|
|
23
|
+
const rows = [];
|
|
24
|
+
const line = (value = '') => {
|
|
25
|
+
const text = truncate(safeDisplay(value), inner, '…');
|
|
26
|
+
rows.push(fill('surface', `${paint('rule', '│')} ${padEnd(text, inner)} `));
|
|
27
|
+
};
|
|
28
|
+
const styled = (value) => {
|
|
29
|
+
rows.push(fill('surface', `${paint('rule', '│')} ${padEnd(truncate(value, inner, '…'), inner)} `));
|
|
30
|
+
};
|
|
31
|
+
line();
|
|
32
|
+
styled(bold(safeDisplay(facts.title?.trim() || 'Untitled')));
|
|
33
|
+
if (facts.id)
|
|
34
|
+
line(facts.id);
|
|
35
|
+
line();
|
|
36
|
+
styled(bold('Context'));
|
|
37
|
+
const limit = Number.isFinite(facts.contextLimit) ? Number(facts.contextLimit) : 0;
|
|
38
|
+
const used = Number.isFinite(facts.contextChars) ? Number(facts.contextChars) : 0;
|
|
39
|
+
if (limit > 0) {
|
|
40
|
+
const percent = Math.max(0, Math.min(100, Math.round((used / limit) * 100)));
|
|
41
|
+
styled(dim(`${percent}% of available window`));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
styled(dim('No context measurement yet'));
|
|
45
|
+
}
|
|
46
|
+
line();
|
|
47
|
+
styled(bold('Model'));
|
|
48
|
+
line([facts.provider, facts.model].filter(Boolean).join(' / ') || 'Not configured');
|
|
49
|
+
line();
|
|
50
|
+
styled(bold('Workspace'));
|
|
51
|
+
line(facts.cwd || 'Unknown');
|
|
52
|
+
if (facts.plan?.length) {
|
|
53
|
+
const completed = facts.plan.filter(item => item.status === 'completed').length;
|
|
54
|
+
line();
|
|
55
|
+
styled(bold(`Plan ${completed}/${facts.plan.length}`));
|
|
56
|
+
for (const item of facts.plan) {
|
|
57
|
+
const mark = item.status === 'completed' ? '✓' : item.status === 'in_progress' ? '▸' : '·';
|
|
58
|
+
line(`${mark} ${item.text || item.step || ''}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const count = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 1;
|
|
62
|
+
const visible = rows.slice(0, count);
|
|
63
|
+
while (visible.length < count - 1)
|
|
64
|
+
lineFor(visible);
|
|
65
|
+
if (visible.length < count)
|
|
66
|
+
visible.push(fill('surface', `${paint('rule', '│')} ${padEnd(dim('Causyne Agent'), inner)} `));
|
|
67
|
+
return visible;
|
|
68
|
+
}
|
|
69
|
+
function lineFor(rows) {
|
|
70
|
+
rows.push(fill('surface', `${paint('rule', '│')}${' '.repeat(SIDEBAR_WIDTH - 1)}`));
|
|
71
|
+
}
|
|
72
|
+
/** Compose the panel beside the viewport and input without exceeding terminal width. */
|
|
73
|
+
export function joinSessionSidebar(mainRows, sideRows, mainWidth) {
|
|
74
|
+
return mainRows.map((row, index) => {
|
|
75
|
+
const main = padEnd(truncate(row, Math.max(1, mainWidth), ''), mainWidth);
|
|
76
|
+
return main + (sideRows[index] || ' '.repeat(SIDEBAR_WIDTH));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { padEnd, safeDisplay, truncate } from './text.js';
|
|
2
|
+
// The terminal theme is still a standalone JavaScript module in the TS migration.
|
|
3
|
+
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
4
|
+
import { bold, dim, fill, paint } from './theme.js';
|
|
5
|
+
|
|
6
|
+
export const SIDEBAR_WIDTH = 42;
|
|
7
|
+
export const SIDEBAR_THRESHOLD = 120;
|
|
8
|
+
|
|
9
|
+
export interface SidebarFacts {
|
|
10
|
+
title?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
provider?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
contextChars?: number;
|
|
16
|
+
contextLimit?: number;
|
|
17
|
+
plan?: Array<{ text?: string; step?: string; status?: string }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A side panel is useful only when a readable conversation column remains. */
|
|
21
|
+
export function sidebarVisible(columns: number, home = false): boolean {
|
|
22
|
+
return !home && Number.isFinite(columns) && columns > SIDEBAR_THRESHOLD;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Reserve the last terminal column so a wide row cannot wrap the stage. */
|
|
26
|
+
export function sessionMainWidth(columns: number, home = false): number {
|
|
27
|
+
const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
28
|
+
return sidebarVisible(width, home) ? width - SIDEBAR_WIDTH - 1 : width;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The session input uses the available conversation column, with a small inset. */
|
|
32
|
+
export function sessionComposerWidth(columns: number): number {
|
|
33
|
+
return Number.isFinite(columns) ? Math.max(20, Math.floor(columns) - 3) : 77;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render only facts the runtime can actually report. */
|
|
37
|
+
export function sessionSidebarRows(facts: SidebarFacts, height: number): string[] {
|
|
38
|
+
const inner = SIDEBAR_WIDTH - 4;
|
|
39
|
+
const rows: string[] = [];
|
|
40
|
+
const line = (value = ''): void => {
|
|
41
|
+
const text = truncate(safeDisplay(value), inner, '…');
|
|
42
|
+
rows.push(fill('surface', `${paint('rule', '│')} ${padEnd(text, inner)} `));
|
|
43
|
+
};
|
|
44
|
+
const styled = (value: string): void => {
|
|
45
|
+
rows.push(fill('surface', `${paint('rule', '│')} ${padEnd(truncate(value, inner, '…'), inner)} `));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
line();
|
|
49
|
+
styled(bold(safeDisplay(facts.title?.trim() || 'Untitled')));
|
|
50
|
+
if (facts.id) line(facts.id);
|
|
51
|
+
line();
|
|
52
|
+
styled(bold('Context'));
|
|
53
|
+
const limit = Number.isFinite(facts.contextLimit) ? Number(facts.contextLimit) : 0;
|
|
54
|
+
const used = Number.isFinite(facts.contextChars) ? Number(facts.contextChars) : 0;
|
|
55
|
+
if (limit > 0) {
|
|
56
|
+
const percent = Math.max(0, Math.min(100, Math.round((used / limit) * 100)));
|
|
57
|
+
styled(dim(`${percent}% of available window`));
|
|
58
|
+
} else {
|
|
59
|
+
styled(dim('No context measurement yet'));
|
|
60
|
+
}
|
|
61
|
+
line();
|
|
62
|
+
styled(bold('Model'));
|
|
63
|
+
line([facts.provider, facts.model].filter(Boolean).join(' / ') || 'Not configured');
|
|
64
|
+
line();
|
|
65
|
+
styled(bold('Workspace'));
|
|
66
|
+
line(facts.cwd || 'Unknown');
|
|
67
|
+
|
|
68
|
+
if (facts.plan?.length) {
|
|
69
|
+
const completed = facts.plan.filter(item => item.status === 'completed').length;
|
|
70
|
+
line();
|
|
71
|
+
styled(bold(`Plan ${completed}/${facts.plan.length}`));
|
|
72
|
+
for (const item of facts.plan) {
|
|
73
|
+
const mark = item.status === 'completed' ? '✓' : item.status === 'in_progress' ? '▸' : '·';
|
|
74
|
+
line(`${mark} ${item.text || item.step || ''}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const count = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 1;
|
|
79
|
+
const visible = rows.slice(0, count);
|
|
80
|
+
while (visible.length < count - 1) lineFor(visible);
|
|
81
|
+
if (visible.length < count) visible.push(fill('surface', `${paint('rule', '│')} ${padEnd(dim('Causyne Agent'), inner)} `));
|
|
82
|
+
return visible;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function lineFor(rows: string[]): void {
|
|
86
|
+
rows.push(fill('surface', `${paint('rule', '│')}${' '.repeat(SIDEBAR_WIDTH - 1)}`));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Compose the panel beside the viewport and input without exceeding terminal width. */
|
|
90
|
+
export function joinSessionSidebar(mainRows: string[], sideRows: string[], mainWidth: number): string[] {
|
|
91
|
+
return mainRows.map((row, index) => {
|
|
92
|
+
const main = padEnd(truncate(row, Math.max(1, mainWidth), ''), mainWidth);
|
|
93
|
+
return main + (sideRows[index] || ' '.repeat(SIDEBAR_WIDTH));
|
|
94
|
+
});
|
|
95
|
+
}
|
package/src/tui/setup.js
CHANGED
|
@@ -5,7 +5,7 @@ const customProviders = new Set(['openai-compatible', 'dashscope-byok', 'ollama'
|
|
|
5
5
|
/** Peers and Antigravity authenticate through their own CLI, not a stored key. */
|
|
6
6
|
function isLocalAgent(providerId) {
|
|
7
7
|
return providerId === 'acp' || providerId.startsWith('acp/')
|
|
8
|
-
|| providerId === 'antigravity' || providerId === 'agy';
|
|
8
|
+
|| providerId === 'antigravity' || providerId === 'agy' || providerId === 'pi';
|
|
9
9
|
}
|
|
10
10
|
const defaults = {
|
|
11
11
|
ollama: 'http://localhost:11434/api/chat',
|
package/src/tui/setup.ts
CHANGED
|
@@ -14,7 +14,7 @@ const customProviders = new Set(['openai-compatible', 'dashscope-byok', 'ollama'
|
|
|
14
14
|
/** Peers and Antigravity authenticate through their own CLI, not a stored key. */
|
|
15
15
|
function isLocalAgent(providerId: string): boolean {
|
|
16
16
|
return providerId === 'acp' || providerId.startsWith('acp/')
|
|
17
|
-
|| providerId === 'antigravity' || providerId === 'agy';
|
|
17
|
+
|| providerId === 'antigravity' || providerId === 'agy' || providerId === 'pi';
|
|
18
18
|
}
|
|
19
19
|
const defaults: Record<string, string> = {
|
|
20
20
|
ollama: 'http://localhost:11434/api/chat',
|
package/src/tui/stageSurface.js
CHANGED
|
@@ -25,8 +25,15 @@ import { Stage, stageHeight } from './stage.js';
|
|
|
25
25
|
import { Transcript } from './transcript.js';
|
|
26
26
|
import { Viewport, ScrollAcceleration, DEFAULT_SCROLL_SPEED } from './viewport.js';
|
|
27
27
|
import { paint, GLYPHS } from './theme.js';
|
|
28
|
+
import { markHoveredMessage } from './messageInteraction.js';
|
|
29
|
+
import { placeMessageActionPanel } from './messageActionPlacement.js';
|
|
28
30
|
import { mouseTracking } from './keys.js';
|
|
31
|
+
import { mouseHoverTracking } from './mouseHover.js';
|
|
29
32
|
import { truncate, padEnd, visibleWidth } from './text.js';
|
|
33
|
+
import { composerWidth } from './layout.js';
|
|
34
|
+
import { placeHome, placeDialog } from './homeView.js';
|
|
35
|
+
import { sidebarVisible, sessionMainWidth, sessionComposerWidth, sessionSidebarRows, joinSessionSidebar } from './sessionSidebar.js';
|
|
36
|
+
import { sessionStageHeight, alignTranscriptRows } from './sessionLayout.js';
|
|
30
37
|
|
|
31
38
|
// Rows of evicted transcript held for the exit log. Eviction only happens after
|
|
32
39
|
// MAX_FRAMES, so this is a bound on a pathological session, not a working limit.
|
|
@@ -36,24 +43,6 @@ const MAX_EVICTED_ROWS = 40000;
|
|
|
36
43
|
// shown at all — which is a broken screen, so the prompt is trimmed instead.
|
|
37
44
|
const MIN_VIEWPORT_ROWS = 2;
|
|
38
45
|
|
|
39
|
-
// Fallback measure for the opening composition, used only when the caller does
|
|
40
|
-
// not hand over the banner's real width.
|
|
41
|
-
//
|
|
42
|
-
// The session banner comes out ~82 columns wide (the wordmark beside its facts
|
|
43
|
-
// column, and the workspace path under it). While the input box stretched the
|
|
44
|
-
// full width of a large terminal, the two read as unrelated objects — a thin line
|
|
45
|
-
// pulled across a wide emptiness under a block that stops two-thirds of the way.
|
|
46
|
-
// Ninety sits just above the banner and just below the 100-column prose measure
|
|
47
|
-
// theme.js already uses, so the opening reads as ONE panel.
|
|
48
|
-
//
|
|
49
|
-
// It applies ONLY while the transcript is empty. The session input box keeps
|
|
50
|
-
// filling the window, which is an established layout invariant — tuiWidth
|
|
51
|
-
// asserts "the input box fills a stretched terminal" after a hardcoded 120-column
|
|
52
|
-
// ceiling was torn out of three modules for leaving a wide terminal two-thirds
|
|
53
|
-
// covered. This does not reopen that: it is a different rule for a different
|
|
54
|
-
// moment, and it lifts the instant a session begins.
|
|
55
|
-
const OPENING_FALLBACK_WIDTH = 100;
|
|
56
|
-
|
|
57
46
|
// The rail costs a column plus a column of air. On a narrow terminal those two
|
|
58
47
|
// are worth more as text, so it turns itself off rather than crowding the
|
|
59
48
|
// transcript it exists to help you navigate.
|
|
@@ -159,6 +148,7 @@ export class StageSurface {
|
|
|
159
148
|
onEvict: (rows) => this.absorbEvicted(rows),
|
|
160
149
|
onChange: () => this.handleChange()
|
|
161
150
|
});
|
|
151
|
+
this.transcript.surface = this;
|
|
162
152
|
const tuning = scrollSettings(env, config);
|
|
163
153
|
this.viewport = new Viewport({
|
|
164
154
|
transcript: this.transcript,
|
|
@@ -182,44 +172,57 @@ export class StageSurface {
|
|
|
182
172
|
// in the way of.
|
|
183
173
|
this.mouseWanted = String(env.CAUSYNE_MOUSE ?? '1') !== '0';
|
|
184
174
|
this.mouseOn = false;
|
|
175
|
+
this.mouseCaptured = false;
|
|
176
|
+
this.detached = false;
|
|
185
177
|
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
// applies.
|
|
178
|
+
// Retained for callers that pass a measured header width. The composer now
|
|
179
|
+
// uses a stable readable width even after the first transcript entry.
|
|
189
180
|
this.openingWidth = Number.isFinite(openingWidth) && openingWidth > 0
|
|
190
181
|
? Math.floor(openingWidth)
|
|
191
182
|
: 0;
|
|
192
183
|
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
// NOT the same question as "is the transcript empty", and the difference is
|
|
196
|
-
// a real defect: /print and ctrl+L empty the transcript, so keying on
|
|
197
|
-
// emptiness narrowed the input box back to the banner's measure long after
|
|
198
|
-
// the banner had scrolled out of view — the box visibly shrinking for a
|
|
199
|
-
// reason the user cannot see. The opening measure belongs to THE opening,
|
|
200
|
-
// once, not to every empty moment after it.
|
|
184
|
+
// Tracks whether this session has ever received transcript content.
|
|
201
185
|
this.opened = false;
|
|
186
|
+
this.homeInfo = null;
|
|
187
|
+
this.homeSessionSelected = false;
|
|
188
|
+
this.sessionInfo = null;
|
|
189
|
+
this.sidebarStatus = null;
|
|
190
|
+
this.sidebarPlan = [];
|
|
191
|
+
this.fullSession = false;
|
|
192
|
+
this.lastPromptRows = [];
|
|
193
|
+
this.lastPromptCaret = null;
|
|
194
|
+
this.messageActionOverlay = null;
|
|
202
195
|
}
|
|
203
196
|
|
|
204
197
|
get width() {
|
|
205
198
|
return this.stage.width();
|
|
206
199
|
}
|
|
207
200
|
|
|
208
|
-
/**
|
|
209
|
-
* The width the prompt block should be composed to.
|
|
210
|
-
*
|
|
211
|
-
* Deliberately NOT centred, which is where Causyne parts company with the
|
|
212
|
-
* reference on purpose. opencode centres its logo and prompt because its logo
|
|
213
|
-
* is centred in a screen it owns (routes/home.tsx:72-90). Causyne's banner is
|
|
214
|
-
* left-aligned in the user's real scrollback, so a centred input box below it
|
|
215
|
-
* would be misaligned with the very thing it is supposed to belong to. Same
|
|
216
|
-
* origin, same measure: the opening reads as a document block, not a splash.
|
|
217
|
-
*/
|
|
201
|
+
/** Home is compact; a session uses its full conversation column. */
|
|
218
202
|
composeWidth() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
203
|
+
return this.homeInfo
|
|
204
|
+
? composerWidth(this.width)
|
|
205
|
+
: sessionComposerWidth(sessionMainWidth(this.width));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Keep Home distinct from a selected or newly started conversation. */
|
|
209
|
+
enterHome(info) {
|
|
210
|
+
this.homeInfo = info;
|
|
211
|
+
this.homeSessionSelected = false;
|
|
212
|
+
this.sessionInfo = { title: 'Untitled', cwd: info?.cwd, provider: info?.provider, model: info?.model };
|
|
213
|
+
this.fullSession = true;
|
|
214
|
+
this.stage.invalidate();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
leaveHome(sessionSelected = false) {
|
|
218
|
+
if (this.homeInfo) this.stage.invalidate();
|
|
219
|
+
this.homeInfo = null;
|
|
220
|
+
if (sessionSelected) this.homeSessionSelected = true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setSessionInfo(info) {
|
|
224
|
+
this.sessionInfo = { ...this.sessionInfo, ...info };
|
|
225
|
+
this.stage.invalidate();
|
|
223
226
|
}
|
|
224
227
|
|
|
225
228
|
/**
|
|
@@ -247,6 +250,7 @@ export class StageSurface {
|
|
|
247
250
|
enableMouse() {
|
|
248
251
|
if (!this.mouseWanted || this.mouseOn) return false;
|
|
249
252
|
this.out.write(mouseTracking(true));
|
|
253
|
+
this.out.write(mouseHoverTracking(true, this.env));
|
|
250
254
|
this.mouseCaptured = true;
|
|
251
255
|
this.mouseOn = true;
|
|
252
256
|
return true;
|
|
@@ -254,6 +258,7 @@ export class StageSurface {
|
|
|
254
258
|
|
|
255
259
|
disableMouse() {
|
|
256
260
|
if (!this.mouseOn) return false;
|
|
261
|
+
this.out.write(mouseHoverTracking(false, this.env));
|
|
257
262
|
this.out.write(mouseTracking(false));
|
|
258
263
|
this.mouseCaptured = false;
|
|
259
264
|
this.mouseOn = false;
|
|
@@ -338,7 +343,9 @@ export class StageSurface {
|
|
|
338
343
|
handleChange() {
|
|
339
344
|
if (!this.transcript.isEmpty()) this.opened = true;
|
|
340
345
|
const before = this.lastHeight;
|
|
341
|
-
const
|
|
346
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
347
|
+
const contentWidth = this.railEnabled(mainWidth) ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
|
|
348
|
+
const after = this.transcript.height(contentWidth);
|
|
342
349
|
this.lastHeight = after;
|
|
343
350
|
// Growth is what drives auto-scroll. Handing the delta over is also what
|
|
344
351
|
// lets the "N new below" affordance count only what arrived while the user
|
|
@@ -365,22 +372,37 @@ export class StageSurface {
|
|
|
365
372
|
present(promptRows, caret = null) {
|
|
366
373
|
if (!this.stage.reserved) return 0;
|
|
367
374
|
|
|
375
|
+
if (!this.messageActionOverlay) {
|
|
376
|
+
this.lastPromptRows = promptRows;
|
|
377
|
+
this.lastPromptCaret = caret;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (this.homeInfo || (caret?.modal && !caret?.inline)) {
|
|
381
|
+
if (this.stage.height < this.stage.maxHeight) {
|
|
382
|
+
this.stage.grow(this.stage.maxHeight - this.stage.height);
|
|
383
|
+
}
|
|
384
|
+
const view = caret?.modal
|
|
385
|
+
? placeDialog(promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0)
|
|
386
|
+
: placeHome(this.homeInfo, promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0);
|
|
387
|
+
return this.stage.paint(view.rows, { row: view.caretRow, col: view.caretCol });
|
|
388
|
+
}
|
|
389
|
+
|
|
368
390
|
const width = this.width;
|
|
369
|
-
const
|
|
370
|
-
const
|
|
391
|
+
const sidebar = sidebarVisible(width);
|
|
392
|
+
const mainWidth = sessionMainWidth(width);
|
|
393
|
+
const rail = this.railEnabled(mainWidth);
|
|
394
|
+
const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
|
|
371
395
|
|
|
372
396
|
let block = promptRows;
|
|
373
397
|
let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
|
|
374
398
|
|
|
375
399
|
// Grow the band to what there is to show, before deciding anything else.
|
|
376
400
|
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
//
|
|
380
|
-
// never shrinks, because shrinking would mean erasing rows the diff believes
|
|
381
|
-
// it owns and fighting the resize path for them.
|
|
401
|
+
// Direct chat keeps its printed header and grows with content. A session
|
|
402
|
+
// entered from Home occupies the available height at every terminal width.
|
|
403
|
+
// Its short transcript is placed next to the input below.
|
|
382
404
|
const contentRows = this.transcript.height(contentWidth);
|
|
383
|
-
const desired =
|
|
405
|
+
const desired = sessionStageHeight(this.stage.maxHeight, block.length, contentRows, this.fullSession || caret?.inline);
|
|
384
406
|
if (desired > this.stage.height) this.stage.grow(desired - this.stage.height);
|
|
385
407
|
|
|
386
408
|
const height = this.stage.height;
|
|
@@ -390,7 +412,9 @@ export class StageSurface {
|
|
|
390
412
|
// footer and the caret row are the last rows and the ones worth keeping,
|
|
391
413
|
// and an input box that has scrolled its own oldest row off is a smaller lie
|
|
392
414
|
// than a transcript that has vanished.
|
|
393
|
-
const floor = contentRows > 0
|
|
415
|
+
const floor = contentRows > 0
|
|
416
|
+
? Math.max(MIN_VIEWPORT_ROWS, this.messageActionOverlay?.panel.length || 0)
|
|
417
|
+
: 0;
|
|
394
418
|
const maxBlock = Math.max(1, height - floor);
|
|
395
419
|
if (block.length > maxBlock) {
|
|
396
420
|
const cut = block.length - maxBlock;
|
|
@@ -402,9 +426,18 @@ export class StageSurface {
|
|
|
402
426
|
let rows = [];
|
|
403
427
|
if (budget > 0) {
|
|
404
428
|
this.viewport.resize({ height: budget, width: contentWidth });
|
|
405
|
-
rows = this.viewport.rows();
|
|
429
|
+
rows = alignTranscriptRows(this.viewport.rows(), contentRows);
|
|
406
430
|
this.decorate(rows, contentWidth);
|
|
431
|
+
markHoveredMessage(rows, this, contentWidth);
|
|
407
432
|
if (rail) this.attachRail(rows, contentWidth);
|
|
433
|
+
if (this.messageActionOverlay) {
|
|
434
|
+
const overlay = this.messageActionOverlay;
|
|
435
|
+
const placed = placeMessageActionPanel(rows, overlay.panel, contentWidth,
|
|
436
|
+
(this.out.rows || height) - height, overlay.layer.anchorY,
|
|
437
|
+
overlay.layer.items.length);
|
|
438
|
+
rows = placed.rows;
|
|
439
|
+
overlay.layer.actionLayout = placed.layout;
|
|
440
|
+
}
|
|
408
441
|
}
|
|
409
442
|
|
|
410
443
|
// DO NOT PAINT WHILE THE TERMINAL OWNS THE SCROLL.
|
|
@@ -422,12 +455,33 @@ export class StageSurface {
|
|
|
422
455
|
// left it, so every write would land somewhere wrong.
|
|
423
456
|
if (this.detached) return false;
|
|
424
457
|
|
|
425
|
-
|
|
458
|
+
const mainRows = rows.concat(block);
|
|
459
|
+
const panelRows = sidebar ? sessionSidebarRows({
|
|
460
|
+
...this.sessionInfo,
|
|
461
|
+
cwd: this.sidebarStatus?.cwd || this.sessionInfo?.cwd,
|
|
462
|
+
provider: this.sidebarStatus?.provider || this.sessionInfo?.provider,
|
|
463
|
+
model: this.sidebarStatus?.model || this.sessionInfo?.model,
|
|
464
|
+
contextChars: this.sidebarStatus?.contextChars,
|
|
465
|
+
contextLimit: this.sidebarStatus?.contextLimit,
|
|
466
|
+
plan: this.sidebarPlan
|
|
467
|
+
}, mainRows.length) : [];
|
|
468
|
+
const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
|
|
469
|
+
return this.stage.paint(painted, {
|
|
426
470
|
row: rows.length + caretRow,
|
|
427
471
|
col: caret ? caret.col : 0
|
|
428
472
|
});
|
|
429
473
|
}
|
|
430
474
|
|
|
475
|
+
/** Draw message actions over the transcript while retaining the live composer. */
|
|
476
|
+
presentMessageActions(panel, layer) {
|
|
477
|
+
this.messageActionOverlay = { panel, layer };
|
|
478
|
+
try {
|
|
479
|
+
return this.present(this.lastPromptRows, this.lastPromptCaret);
|
|
480
|
+
} finally {
|
|
481
|
+
this.messageActionOverlay = null;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
431
485
|
/**
|
|
432
486
|
* The one thing on screen that opencode does not have: while the view is held
|
|
433
487
|
* away from the bottom, say so and say how much arrived.
|
|
@@ -475,7 +529,11 @@ export class StageSurface {
|
|
|
475
529
|
this.transcript.clear();
|
|
476
530
|
this.lastHeight = 0;
|
|
477
531
|
this.stage.invalidate();
|
|
478
|
-
this.viewport
|
|
532
|
+
if (this.viewport) {
|
|
533
|
+
this.viewport.manual = false;
|
|
534
|
+
this.viewport.unseen = 0;
|
|
535
|
+
this.viewport.toBottom();
|
|
536
|
+
}
|
|
479
537
|
}
|
|
480
538
|
|
|
481
539
|
/**
|
|
@@ -496,8 +554,10 @@ export class StageSurface {
|
|
|
496
554
|
this.stage.invalidate();
|
|
497
555
|
// Re-derive from the new geometry: growing the viewport lowers maxScrollTop,
|
|
498
556
|
// and leaving scrollTop above it would read as "the user scrolled away".
|
|
499
|
-
|
|
500
|
-
|
|
557
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
558
|
+
const contentWidth = this.railEnabled(mainWidth) ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
|
|
559
|
+
this.viewport.resize({ height: Math.max(MIN_VIEWPORT_ROWS, this.stage.height - 2), width: contentWidth });
|
|
560
|
+
this.lastHeight = this.transcript.height(contentWidth);
|
|
501
561
|
return this.stage.reserved;
|
|
502
562
|
}
|
|
503
563
|
|
|
@@ -581,6 +641,7 @@ export class StageSurface {
|
|
|
581
641
|
*/
|
|
582
642
|
releaseMouse() {
|
|
583
643
|
if (!this.mouseCaptured) return false;
|
|
644
|
+
this.out.write(mouseHoverTracking(false, this.env));
|
|
584
645
|
this.out.write(mouseTracking(false));
|
|
585
646
|
this.mouseCaptured = false;
|
|
586
647
|
this.detached = true;
|
|
@@ -591,6 +652,7 @@ export class StageSurface {
|
|
|
591
652
|
captureMouse() {
|
|
592
653
|
if (this.mouseCaptured) return false;
|
|
593
654
|
this.out.write(mouseTracking(true));
|
|
655
|
+
this.out.write(mouseHoverTracking(true, this.env));
|
|
594
656
|
this.mouseCaptured = true;
|
|
595
657
|
this.detached = false;
|
|
596
658
|
// Every row the diff remembers is stale — the terminal has scrolled under
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function safeDisplay(value: string): string;
|
|
2
|
+
export function truncate(value: string, width: number, ellipsis?: string): string;
|
|
3
|
+
export function padEnd(value: string, width: number): string;
|
|
4
|
+
export function visibleWidth(value: string): number;
|
|
5
|
+
export function wrap(value: string, width: number, options?: { hang?: number }): string[];
|
|
6
|
+
export function wrapBlock(value: string, width: number, options?: { hang?: number }): string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { visibleWidth, wrap } from './text.js';
|
|
2
|
+
// The terminal palette remains a JavaScript module during the TypeScript migration.
|
|
3
|
+
// @ts-expect-error theme.js does not have a declaration yet.
|
|
4
|
+
import { paint } from './theme.js';
|
|
5
|
+
/** Width of text inside the current conversation column, with room for its inset. */
|
|
6
|
+
export function chatTextWidth(columns) {
|
|
7
|
+
const available = Number.isFinite(columns) ? Math.floor(columns) : 80;
|
|
8
|
+
return Math.max(8, available - 4);
|
|
9
|
+
}
|
|
10
|
+
/** Widen prose gradually on large screens so lines remain readable. */
|
|
11
|
+
export function chatProseWidth(columns) {
|
|
12
|
+
const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
13
|
+
if (available <= 100)
|
|
14
|
+
return available;
|
|
15
|
+
return Math.min(chatTextWidth(available), Math.round(100 + 24 * Math.log2(available / 100)));
|
|
16
|
+
}
|
|
17
|
+
/** Keep every line of a labeled message visible when the terminal is resized. */
|
|
18
|
+
export function wrappedChatRows(message, columns, prefix, tone) {
|
|
19
|
+
const inset = visibleWidth(prefix);
|
|
20
|
+
const room = Math.max(1, chatTextWidth(columns) - inset);
|
|
21
|
+
const continuation = ' '.repeat(inset);
|
|
22
|
+
return wrap(message, room).map((line, index) => `${index === 0 ? prefix : continuation}${paint(tone, line)}`);
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { visibleWidth, wrap } from './text.js';
|
|
2
|
+
// The terminal palette remains a JavaScript module during the TypeScript migration.
|
|
3
|
+
// @ts-expect-error theme.js does not have a declaration yet.
|
|
4
|
+
import { paint } from './theme.js';
|
|
5
|
+
|
|
6
|
+
export type MessageTone = 'danger' | 'warn' | 'muted' | 'accent';
|
|
7
|
+
|
|
8
|
+
/** Width of text inside the current conversation column, with room for its inset. */
|
|
9
|
+
export function chatTextWidth(columns: number): number {
|
|
10
|
+
const available = Number.isFinite(columns) ? Math.floor(columns) : 80;
|
|
11
|
+
return Math.max(8, available - 4);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Widen prose gradually on large screens so lines remain readable. */
|
|
15
|
+
export function chatProseWidth(columns: number): number {
|
|
16
|
+
const available = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
|
|
17
|
+
if (available <= 100) return available;
|
|
18
|
+
return Math.min(chatTextWidth(available), Math.round(100 + 24 * Math.log2(available / 100)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Keep every line of a labeled message visible when the terminal is resized. */
|
|
22
|
+
export function wrappedChatRows(message: string, columns: number, prefix: string, tone: MessageTone): string[] {
|
|
23
|
+
const inset = visibleWidth(prefix);
|
|
24
|
+
const room = Math.max(1, chatTextWidth(columns) - inset);
|
|
25
|
+
const continuation = ' '.repeat(inset);
|
|
26
|
+
return wrap(message, room).map((line: string, index: number) =>
|
|
27
|
+
`${index === 0 ? prefix : continuation}${paint(tone, line)}`);
|
|
28
|
+
}
|