@causyne/agent 1.20.0 → 1.20.5
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 +0 -18
- package/package.json +1 -1
- package/src/acp/client.js +2 -1
- package/src/acp/client.ts +2 -1
- 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 +505 -241
- package/src/agentLoop.ts +527 -258
- 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 +67 -1
- package/src/providers/acp.ts +65 -2
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +643 -32
- package/src/providers/antigravity.ts +671 -33
- package/src/providers/base.d.ts +9 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +157 -0
- package/src/providers/pi.ts +144 -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/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +21 -0
- package/src/tui/chatRenderer.js +34 -47
- 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 +116 -0
- package/src/tui/codeStreamRenderer.ts +124 -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 +66 -0
- package/src/tui/composerControls.ts +78 -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 +152 -76
- 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 +5 -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,66 @@
|
|
|
1
|
+
import { loadConfig, saveConfig } from '../config.js';
|
|
2
|
+
import { getAvailableProvidersOverview } from '../dynamicCatalogue.js';
|
|
3
|
+
// @ts-expect-error dialogs.js is awaiting TypeScript migration.
|
|
4
|
+
import { SelectLayer } from './dialogs.js';
|
|
5
|
+
export function openModeControl(prompt, loop) {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const current = String(config.autonomyMode || 'B').toUpperCase();
|
|
8
|
+
prompt.openLayer(new SelectLayer({
|
|
9
|
+
title: 'Autonomy mode',
|
|
10
|
+
items: [
|
|
11
|
+
{ id: 'A', label: 'A · Ask', description: 'Review actions before execution', value: 'A' },
|
|
12
|
+
{ id: 'B', label: 'B · Balanced', description: 'Work independently within permission boundaries', value: 'B' },
|
|
13
|
+
{ id: 'C', label: 'C · Autonomous', description: 'Continue within the selected workspace and policy', value: 'C' }
|
|
14
|
+
].map(item => ({ ...item, label: `${item.label}${item.value === current ? ' (active)' : ''}` })),
|
|
15
|
+
onPick: (item) => {
|
|
16
|
+
if (!item?.value)
|
|
17
|
+
return;
|
|
18
|
+
config.autonomyMode = item.value;
|
|
19
|
+
saveConfig(config);
|
|
20
|
+
loop.setAutonomyMode(item.value);
|
|
21
|
+
prompt.notice = `Mode ${item.value} active`;
|
|
22
|
+
prompt.scheduleDraw();
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
/** Only offer sibling variants the selected provider actually advertises. */
|
|
27
|
+
export function availableModelVariants(config) {
|
|
28
|
+
const current = String(config.model || '');
|
|
29
|
+
const match = current.match(/^(.*)\s\(([^()]+)\)$/);
|
|
30
|
+
if (!match)
|
|
31
|
+
return [];
|
|
32
|
+
const overview = getAvailableProvidersOverview(config);
|
|
33
|
+
const provider = String(config.provider || '');
|
|
34
|
+
const advertised = overview.acp.find(peer => peer.providerKey === provider)?.models
|
|
35
|
+
?? overview.byok.find(item => item.id === provider)?.models
|
|
36
|
+
?? [];
|
|
37
|
+
return advertised.filter(model => {
|
|
38
|
+
const sibling = model.match(/^(.*)\s\(([^()]+)\)$/);
|
|
39
|
+
return sibling?.[1] === match[1];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function openVariantControl(prompt) {
|
|
43
|
+
const config = loadConfig();
|
|
44
|
+
const variants = availableModelVariants(config);
|
|
45
|
+
if (variants.length < 2) {
|
|
46
|
+
prompt.notice = 'This provider has no advertised model variants';
|
|
47
|
+
prompt.scheduleDraw();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
prompt.openLayer(new SelectLayer({
|
|
51
|
+
title: 'Model variant',
|
|
52
|
+
items: variants.map(model => ({
|
|
53
|
+
id: model,
|
|
54
|
+
label: `${model}${model === config.model ? ' (active)' : ''}`,
|
|
55
|
+
description: String(config.provider || ''),
|
|
56
|
+
value: model
|
|
57
|
+
})),
|
|
58
|
+
onPick: (item) => {
|
|
59
|
+
if (!item?.value || item.value === config.model)
|
|
60
|
+
return;
|
|
61
|
+
prompt.deliver(`/model ${String(config.provider)}/${item.value}`);
|
|
62
|
+
prompt.notice = 'Model variant change queued';
|
|
63
|
+
prompt.scheduleDraw();
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { loadConfig, saveConfig } from '../config.js';
|
|
2
|
+
import { getAvailableProvidersOverview } from '../dynamicCatalogue.js';
|
|
3
|
+
// @ts-expect-error dialogs.js is awaiting TypeScript migration.
|
|
4
|
+
import { SelectLayer } from './dialogs.js';
|
|
5
|
+
|
|
6
|
+
interface ControlPrompt {
|
|
7
|
+
openLayer(layer: unknown): void;
|
|
8
|
+
deliver(command: string): boolean;
|
|
9
|
+
scheduleDraw(): void;
|
|
10
|
+
notice: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ControlLoop {
|
|
14
|
+
config: Record<string, unknown>;
|
|
15
|
+
setAutonomyMode(mode: string): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function openModeControl(prompt: ControlPrompt, loop: ControlLoop): void {
|
|
19
|
+
const config = loadConfig();
|
|
20
|
+
const current = String(config.autonomyMode || 'B').toUpperCase();
|
|
21
|
+
prompt.openLayer(new SelectLayer({
|
|
22
|
+
title: 'Autonomy mode',
|
|
23
|
+
items: [
|
|
24
|
+
{ id: 'A', label: 'A · Ask', description: 'Review actions before execution', value: 'A' },
|
|
25
|
+
{ id: 'B', label: 'B · Balanced', description: 'Work independently within permission boundaries', value: 'B' },
|
|
26
|
+
{ id: 'C', label: 'C · Autonomous', description: 'Continue within the selected workspace and policy', value: 'C' }
|
|
27
|
+
].map(item => ({ ...item, label: `${item.label}${item.value === current ? ' (active)' : ''}` })),
|
|
28
|
+
onPick: (item: { value?: string } | null) => {
|
|
29
|
+
if (!item?.value) return;
|
|
30
|
+
config.autonomyMode = item.value;
|
|
31
|
+
saveConfig(config);
|
|
32
|
+
loop.setAutonomyMode(item.value);
|
|
33
|
+
prompt.notice = `Mode ${item.value} active`;
|
|
34
|
+
prompt.scheduleDraw();
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Only offer sibling variants the selected provider actually advertises. */
|
|
40
|
+
export function availableModelVariants(config: Record<string, unknown>): string[] {
|
|
41
|
+
const current = String(config.model || '');
|
|
42
|
+
const match = current.match(/^(.*)\s\(([^()]+)\)$/);
|
|
43
|
+
if (!match) return [];
|
|
44
|
+
const overview = getAvailableProvidersOverview(config);
|
|
45
|
+
const provider = String(config.provider || '');
|
|
46
|
+
const advertised = overview.acp.find(peer => peer.providerKey === provider)?.models
|
|
47
|
+
?? overview.byok.find(item => item.id === provider)?.models
|
|
48
|
+
?? [];
|
|
49
|
+
return advertised.filter(model => {
|
|
50
|
+
const sibling = model.match(/^(.*)\s\(([^()]+)\)$/);
|
|
51
|
+
return sibling?.[1] === match[1];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function openVariantControl(prompt: ControlPrompt): void {
|
|
56
|
+
const config = loadConfig();
|
|
57
|
+
const variants = availableModelVariants(config);
|
|
58
|
+
if (variants.length < 2) {
|
|
59
|
+
prompt.notice = 'This provider has no advertised model variants';
|
|
60
|
+
prompt.scheduleDraw();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
prompt.openLayer(new SelectLayer({
|
|
64
|
+
title: 'Model variant',
|
|
65
|
+
items: variants.map(model => ({
|
|
66
|
+
id: model,
|
|
67
|
+
label: `${model}${model === config.model ? ' (active)' : ''}`,
|
|
68
|
+
description: String(config.provider || ''),
|
|
69
|
+
value: model
|
|
70
|
+
})),
|
|
71
|
+
onPick: (item: { value?: string } | null) => {
|
|
72
|
+
if (!item?.value || item.value === config.model) return;
|
|
73
|
+
prompt.deliver(`/model ${String(config.provider)}/${item.value}`);
|
|
74
|
+
prompt.notice = 'Model variant change queued';
|
|
75
|
+
prompt.scheduleDraw();
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
}
|
package/src/tui/home.js
CHANGED
|
@@ -6,6 +6,7 @@ import { runSetup } from './setup.js';
|
|
|
6
6
|
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
7
7
|
import { isAcpProvider } from '../providers/acp.js';
|
|
8
8
|
import { isAntigravityProvider, resolveAgyBinary } from '../providers/antigravity.js';
|
|
9
|
+
import { isPiProvider, PI_SETUP_PROVIDER } from '../providers/pi.js';
|
|
9
10
|
import { isBinaryOnPath } from '../acp/agentCatalog.js';
|
|
10
11
|
|
|
11
12
|
/** Local runtime and provider summary. */
|
|
@@ -15,7 +16,7 @@ export function homeStatusLine(arg = {}) {
|
|
|
15
16
|
const model = hasProvider
|
|
16
17
|
? (config.model ? `${config.provider}/${config.model}` : config.provider)
|
|
17
18
|
: 'no provider configured';
|
|
18
|
-
const configured = Boolean((hasProvider && config.apiKey) || config.provider === 'ollama' || isAcpProvider(config.provider) || isAntigravityProvider(config.provider));
|
|
19
|
+
const configured = Boolean((hasProvider && config.apiKey) || config.provider === 'ollama' || isAcpProvider(config.provider) || isAntigravityProvider(config.provider) || isPiProvider(config.provider));
|
|
19
20
|
return ' ' + [
|
|
20
21
|
paint('success', `${GLYPHS.bullet} local desktop`),
|
|
21
22
|
configured
|
|
@@ -149,6 +150,7 @@ export const PROVIDERS = [
|
|
|
149
150
|
{ id: 'openai-compatible', label: 'OpenAI-compatible endpoint', hint: 'custom base URL', category: 'BYOK (Custom)' },
|
|
150
151
|
{ id: 'ollama', label: 'Ollama', hint: 'local / offline', category: 'BYOK (Local Server)' },
|
|
151
152
|
{ id: 'antigravity', label: 'Google Antigravity (AGY)', hint: resolveAgyBinary() ? 'local AGY · Gemini & Claude (ready)' : 'local AGY · (not installed)', category: 'ACP (Peer Agent)' },
|
|
153
|
+
PI_SETUP_PROVIDER,
|
|
152
154
|
{ id: 'acp/opencode', label: 'OpenCode', hint: isBinaryOnPath('opencode') ? 'ACP · free models (ready)' : 'ACP · (not installed)', category: 'ACP (Peer Agent)' },
|
|
153
155
|
{ id: 'acp/claude', label: 'Claude Code', hint: isBinaryOnPath('claude') ? 'ACP · Anthropic subscription (ready)' : 'ACP · (not installed)', category: 'ACP (Peer Agent)' },
|
|
154
156
|
{ id: 'acp/codex', label: 'Codex CLI', hint: isBinaryOnPath('codex') ? 'ACP · OpenAI login (ready)' : 'ACP · (not installed)', category: 'ACP (Peer Agent)' },
|
|
@@ -160,7 +162,7 @@ export const PROVIDERS = [
|
|
|
160
162
|
{ id: 'acp/goose', label: 'Goose', hint: isBinaryOnPath('goose') ? 'ACP · configured providers (ready)' : 'ACP · (not installed)', category: 'ACP (Peer Agent)' },
|
|
161
163
|
{ id: 'acp/hermes', label: 'Hermes Agent', hint: isBinaryOnPath('hermes') ? 'ACP · Nous Research (ready)' : 'ACP · (not installed)', category: 'ACP (Peer Agent)' },
|
|
162
164
|
{ id: 'acp', label: 'ACP peer agent (custom)', hint: 'any ACP-compatible CLI', category: 'ACP (Custom)' }
|
|
163
|
-
].map((entry) => ({ ...entry, model: DEFAULT_MODEL_BY_PROVIDER[entry.id] ?? '' }));
|
|
165
|
+
].map((entry) => ({ ...entry, model: entry.model ?? DEFAULT_MODEL_BY_PROVIDER[entry.id] ?? '' }));
|
|
164
166
|
|
|
165
167
|
/** Run the shared setup transaction inside the existing prompt. */
|
|
166
168
|
export function configureInPrompt(prompt, store) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Preserve a chosen session; a direct first prompt starts fresh. */
|
|
2
|
+
export class HomeTransition {
|
|
3
|
+
started = false;
|
|
4
|
+
openedHome;
|
|
5
|
+
surface;
|
|
6
|
+
constructor(openedHome, surface) {
|
|
7
|
+
this.openedHome = openedHome;
|
|
8
|
+
this.surface = surface;
|
|
9
|
+
}
|
|
10
|
+
beginTurn(loop) {
|
|
11
|
+
if (!this.openedHome || this.started)
|
|
12
|
+
return;
|
|
13
|
+
this.started = true;
|
|
14
|
+
if (this.surface?.homeSessionSelected)
|
|
15
|
+
return;
|
|
16
|
+
this.surface?.leaveHome?.();
|
|
17
|
+
loop.memoryManager?.startNewSession('Untitled');
|
|
18
|
+
loop.messages = [];
|
|
19
|
+
loop.tokenTracker?.reset?.();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface HomeLoop {
|
|
2
|
+
memoryManager?: { startNewSession: (title: string) => unknown };
|
|
3
|
+
messages: unknown[];
|
|
4
|
+
tokenTracker?: { reset?: () => void };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Preserve a chosen session; a direct first prompt starts fresh. */
|
|
8
|
+
export class HomeTransition {
|
|
9
|
+
private started = false;
|
|
10
|
+
private readonly openedHome: boolean;
|
|
11
|
+
private readonly surface: { homeSessionSelected?: boolean; leaveHome?: () => void } | null;
|
|
12
|
+
|
|
13
|
+
constructor(openedHome: boolean, surface: { homeSessionSelected?: boolean; leaveHome?: () => void } | null) {
|
|
14
|
+
this.openedHome = openedHome;
|
|
15
|
+
this.surface = surface;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
beginTurn(loop: HomeLoop): void {
|
|
19
|
+
if (!this.openedHome || this.started) return;
|
|
20
|
+
this.started = true;
|
|
21
|
+
if (this.surface?.homeSessionSelected) return;
|
|
22
|
+
this.surface?.leaveHome?.();
|
|
23
|
+
loop.memoryManager?.startNewSession('Untitled');
|
|
24
|
+
loop.messages = [];
|
|
25
|
+
loop.tokenTracker?.reset?.();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { sessionBanner } from './banner.js';
|
|
2
|
+
import { centerRows } from './layout.js';
|
|
3
|
+
// @ts-expect-error overlay.js is awaiting TypeScript migration.
|
|
4
|
+
import { panelRows } from './overlay.js';
|
|
5
|
+
/** A modal before the first conversation belongs to the centered home view. */
|
|
6
|
+
export function isStartupDialog(surface) {
|
|
7
|
+
if (!surface)
|
|
8
|
+
return false;
|
|
9
|
+
if (surface.homeInfo)
|
|
10
|
+
return true;
|
|
11
|
+
return !surface.transcript?.frames?.some(frame => frame.kind === 'user' || frame.kind === 'assistant');
|
|
12
|
+
}
|
|
13
|
+
/** Keep startup pickers readable without letting a long catalogue resize the UI. */
|
|
14
|
+
export function startupDialogView(layer, columns, terminalRows) {
|
|
15
|
+
const availableWidth = Number.isFinite(columns) ? Math.max(8, Math.floor(columns) - 1) : 79;
|
|
16
|
+
const availableHeight = Number.isFinite(terminalRows) ? Math.max(4, Math.floor(terminalRows) - 2) : 20;
|
|
17
|
+
const width = Math.min(availableWidth, 96, Math.max(88, Math.floor(layer.width || 0)));
|
|
18
|
+
const height = Math.min(availableHeight, 30);
|
|
19
|
+
const measuredLayer = {
|
|
20
|
+
title: layer.title,
|
|
21
|
+
footer: layer.footer,
|
|
22
|
+
preferredHeight: () => Math.max(10, layer.preferredHeight()),
|
|
23
|
+
body: (innerWidth, bodyHeight) => layer.body(innerWidth, bodyHeight)
|
|
24
|
+
};
|
|
25
|
+
const centered = centerRows(panelRows(measuredLayer, width, height), columns);
|
|
26
|
+
const cursor = layer.cursor;
|
|
27
|
+
return {
|
|
28
|
+
rows: centered.rows,
|
|
29
|
+
caretRow: cursor ? 1 + cursor.y : 0,
|
|
30
|
+
caretCol: centered.inset + (cursor ? 2 + cursor.x : 0)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Center a temporary dialog in the available terminal region. */
|
|
34
|
+
export function placeDialog(rows, columns, height, caretRow, caretCol) {
|
|
35
|
+
const available = Math.max(1, Math.floor(height));
|
|
36
|
+
const shown = rows.slice(0, available);
|
|
37
|
+
const top = Math.max(0, Math.floor((available - shown.length) / 2));
|
|
38
|
+
return {
|
|
39
|
+
rows: [...Array(top).fill(''), ...shown],
|
|
40
|
+
caretRow: top + Math.min(Math.max(0, caretRow), shown.length - 1),
|
|
41
|
+
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** A clean first screen; session messages are intentionally absent. */
|
|
45
|
+
export function placeHome(info, promptRows, columns, height, caretRow, caretCol) {
|
|
46
|
+
const available = Math.max(1, Math.floor(height));
|
|
47
|
+
const logo = centerRows(sessionBanner(info, columns, { height: available }), columns).rows;
|
|
48
|
+
const spacer = available >= 25 ? 2 : 1;
|
|
49
|
+
const required = logo.length + spacer + promptRows.length;
|
|
50
|
+
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
51
|
+
const rows = [
|
|
52
|
+
...Array(top).fill(''),
|
|
53
|
+
...logo,
|
|
54
|
+
...Array(spacer).fill(''),
|
|
55
|
+
...promptRows
|
|
56
|
+
];
|
|
57
|
+
return {
|
|
58
|
+
rows: rows.slice(0, available),
|
|
59
|
+
caretRow: Math.min(available - 1, top + logo.length + spacer + Math.max(0, caretRow)),
|
|
60
|
+
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { sessionBanner, type BannerInfo } from './banner.js';
|
|
2
|
+
import { centerRows } from './layout.js';
|
|
3
|
+
// @ts-expect-error overlay.js is awaiting TypeScript migration.
|
|
4
|
+
import { panelRows } from './overlay.js';
|
|
5
|
+
|
|
6
|
+
export interface PlacedView {
|
|
7
|
+
rows: string[];
|
|
8
|
+
caretRow: number;
|
|
9
|
+
caretCol: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface StartupSurface {
|
|
13
|
+
homeInfo?: unknown;
|
|
14
|
+
transcript?: { frames?: Array<{ kind?: string }> };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface StartupLayer {
|
|
18
|
+
title?: string;
|
|
19
|
+
footer?: string;
|
|
20
|
+
width?: number;
|
|
21
|
+
cursor?: { x: number; y: number } | null;
|
|
22
|
+
preferredHeight(): number;
|
|
23
|
+
body(width: number, height: number): string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A modal before the first conversation belongs to the centered home view. */
|
|
27
|
+
export function isStartupDialog(surface: StartupSurface | null | undefined): boolean {
|
|
28
|
+
if (!surface) return false;
|
|
29
|
+
if (surface.homeInfo) return true;
|
|
30
|
+
return !surface.transcript?.frames?.some(frame => frame.kind === 'user' || frame.kind === 'assistant');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Keep startup pickers readable without letting a long catalogue resize the UI. */
|
|
34
|
+
export function startupDialogView(layer: StartupLayer, columns: number, terminalRows: number): PlacedView {
|
|
35
|
+
const availableWidth = Number.isFinite(columns) ? Math.max(8, Math.floor(columns) - 1) : 79;
|
|
36
|
+
const availableHeight = Number.isFinite(terminalRows) ? Math.max(4, Math.floor(terminalRows) - 2) : 20;
|
|
37
|
+
const width = Math.min(availableWidth, 96, Math.max(88, Math.floor(layer.width || 0)));
|
|
38
|
+
const height = Math.min(availableHeight, 30);
|
|
39
|
+
const measuredLayer = {
|
|
40
|
+
title: layer.title,
|
|
41
|
+
footer: layer.footer,
|
|
42
|
+
preferredHeight: () => Math.max(10, layer.preferredHeight()),
|
|
43
|
+
body: (innerWidth: number, bodyHeight: number) => layer.body(innerWidth, bodyHeight)
|
|
44
|
+
};
|
|
45
|
+
const centered = centerRows(panelRows(measuredLayer, width, height) as string[], columns);
|
|
46
|
+
const cursor = layer.cursor;
|
|
47
|
+
return {
|
|
48
|
+
rows: centered.rows,
|
|
49
|
+
caretRow: cursor ? 1 + cursor.y : 0,
|
|
50
|
+
caretCol: centered.inset + (cursor ? 2 + cursor.x : 0)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Center a temporary dialog in the available terminal region. */
|
|
55
|
+
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 shown = rows.slice(0, available);
|
|
58
|
+
const top = Math.max(0, Math.floor((available - shown.length) / 2));
|
|
59
|
+
return {
|
|
60
|
+
rows: [...Array<string>(top).fill(''), ...shown],
|
|
61
|
+
caretRow: top + Math.min(Math.max(0, caretRow), shown.length - 1),
|
|
62
|
+
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A clean first screen; session messages are intentionally absent. */
|
|
67
|
+
export function placeHome(
|
|
68
|
+
info: BannerInfo,
|
|
69
|
+
promptRows: string[],
|
|
70
|
+
columns: number,
|
|
71
|
+
height: number,
|
|
72
|
+
caretRow: number,
|
|
73
|
+
caretCol: number
|
|
74
|
+
): PlacedView {
|
|
75
|
+
const available = Math.max(1, Math.floor(height));
|
|
76
|
+
const logo = centerRows(sessionBanner(info, columns, { height: available }), columns).rows;
|
|
77
|
+
const spacer = available >= 25 ? 2 : 1;
|
|
78
|
+
const required = logo.length + spacer + promptRows.length;
|
|
79
|
+
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
80
|
+
const rows = [
|
|
81
|
+
...Array<string>(top).fill(''),
|
|
82
|
+
...logo,
|
|
83
|
+
...Array<string>(spacer).fill(''),
|
|
84
|
+
...promptRows
|
|
85
|
+
];
|
|
86
|
+
return {
|
|
87
|
+
rows: rows.slice(0, available),
|
|
88
|
+
caretRow: Math.min(available - 1, top + logo.length + spacer + Math.max(0, caretRow)),
|
|
89
|
+
caretCol: Math.max(0, Math.min(caretCol, columns - 2))
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { visibleWidth, truncate } from './text.js';
|
|
2
|
+
/** Keep the composer readable on wide terminals and usable on narrow ones. */
|
|
3
|
+
export function composerWidth(columns) {
|
|
4
|
+
const width = Number.isFinite(columns) ? Math.floor(columns) : 80;
|
|
5
|
+
return Math.max(20, Math.min(82, width - 2));
|
|
6
|
+
}
|
|
7
|
+
/** Center one content column without centering each line independently. */
|
|
8
|
+
export function centerRows(rows, columns) {
|
|
9
|
+
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
10
|
+
const occupied = rows.reduce((widest, row) => Math.max(widest, visibleWidth(row)), 0);
|
|
11
|
+
const inset = Math.max(0, Math.floor((available - occupied) / 2));
|
|
12
|
+
const prefix = ' '.repeat(inset);
|
|
13
|
+
return { rows: rows.map(row => row ? prefix + row : ''), inset };
|
|
14
|
+
}
|
|
15
|
+
/** Conversation content starts at the left margin while Home stays centered. */
|
|
16
|
+
export function sessionRows(rows, columns) {
|
|
17
|
+
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
18
|
+
const inset = Math.min(2, Math.max(0, available - 2));
|
|
19
|
+
const prefix = ' '.repeat(inset);
|
|
20
|
+
return {
|
|
21
|
+
rows: rows.map(row => row ? prefix + truncate(row, Math.max(1, available - inset - 1), '') : ''),
|
|
22
|
+
inset
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Leave room for a centered home composition without overflowing small terminals. */
|
|
26
|
+
export function openingTopGap(rows, introRows) {
|
|
27
|
+
if (!Number.isFinite(rows) || rows < 40)
|
|
28
|
+
return 0;
|
|
29
|
+
return Math.max(0, Math.min(40, Math.floor((rows - introRows - 8) / 2)));
|
|
30
|
+
}
|
|
31
|
+
/** Place the home composition as one centered group, with room for the composer below. */
|
|
32
|
+
export function openingRows(rows, columns, terminalRows) {
|
|
33
|
+
return [
|
|
34
|
+
...Array(openingTopGap(terminalRows, rows.length)).fill(''),
|
|
35
|
+
...centerRows(rows, columns).rows
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
/** Fit every dialog, including text reports, inside the current terminal width. */
|
|
39
|
+
export function dialogWidth(columns, requested) {
|
|
40
|
+
const available = Number.isFinite(columns) ? Math.max(4, Math.floor(columns) - 1) : 79;
|
|
41
|
+
return Math.max(4, Math.min(available, Math.floor(requested) || available));
|
|
42
|
+
}
|
|
43
|
+
export function dialogHeight(available, requested) {
|
|
44
|
+
const room = Number.isFinite(available) ? Math.max(4, Math.floor(available) - 1) : 20;
|
|
45
|
+
return Math.max(4, Math.min(20, room, Math.floor(requested) || room));
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { visibleWidth, truncate } from './text.js';
|
|
2
|
+
|
|
3
|
+
/** Keep the composer readable on wide terminals and usable on narrow ones. */
|
|
4
|
+
export function composerWidth(columns: number): number {
|
|
5
|
+
const width = Number.isFinite(columns) ? Math.floor(columns) : 80;
|
|
6
|
+
return Math.max(20, Math.min(82, width - 2));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Center one content column without centering each line independently. */
|
|
10
|
+
export function centerRows(rows: string[], columns: number): { rows: string[]; inset: number } {
|
|
11
|
+
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
12
|
+
const occupied = rows.reduce((widest, row) => Math.max(widest, visibleWidth(row)), 0);
|
|
13
|
+
const inset = Math.max(0, Math.floor((available - occupied) / 2));
|
|
14
|
+
const prefix = ' '.repeat(inset);
|
|
15
|
+
return { rows: rows.map(row => row ? prefix + row : ''), inset };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Conversation content starts at the left margin while Home stays centered. */
|
|
19
|
+
export function sessionRows(rows: string[], columns: number): { rows: string[]; inset: number } {
|
|
20
|
+
const available = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
21
|
+
const inset = Math.min(2, Math.max(0, available - 2));
|
|
22
|
+
const prefix = ' '.repeat(inset);
|
|
23
|
+
return {
|
|
24
|
+
rows: rows.map(row => row ? prefix + truncate(row, Math.max(1, available - inset - 1), '') : ''),
|
|
25
|
+
inset
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Leave room for a centered home composition without overflowing small terminals. */
|
|
30
|
+
export function openingTopGap(rows: number, introRows: number): number {
|
|
31
|
+
if (!Number.isFinite(rows) || rows < 40) return 0;
|
|
32
|
+
return Math.max(0, Math.min(40, Math.floor((rows - introRows - 8) / 2)));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Place the home composition as one centered group, with room for the composer below. */
|
|
36
|
+
export function openingRows(rows: string[], columns: number, terminalRows: number): string[] {
|
|
37
|
+
return [
|
|
38
|
+
...Array<string>(openingTopGap(terminalRows, rows.length)).fill(''),
|
|
39
|
+
...centerRows(rows, columns).rows
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Fit every dialog, including text reports, inside the current terminal width. */
|
|
44
|
+
export function dialogWidth(columns: number, requested: number): number {
|
|
45
|
+
const available = Number.isFinite(columns) ? Math.max(4, Math.floor(columns) - 1) : 79;
|
|
46
|
+
return Math.max(4, Math.min(available, Math.floor(requested) || available));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function dialogHeight(available: number, requested: number): number {
|
|
50
|
+
const room = Number.isFinite(available) ? Math.max(4, Math.floor(available) - 1) : 20;
|
|
51
|
+
return Math.max(4, Math.min(20, room, Math.floor(requested) || room));
|
|
52
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { truncate, visibleWidth } from './text.js';
|
|
2
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message. */
|
|
3
|
+
export function placeMessageActionPanel(viewportRows, panel, contentWidth, stageTop, anchorY, count) {
|
|
4
|
+
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
5
|
+
return { rows: viewportRows, layout: null };
|
|
6
|
+
}
|
|
7
|
+
const width = Math.min(contentWidth, Math.max(...panel.map(visibleWidth)));
|
|
8
|
+
const x = Math.max(0, Math.floor((contentWidth - width) / 2));
|
|
9
|
+
const anchor = anchorY === null ? Math.floor(viewportRows.length / 2) : anchorY - stageTop;
|
|
10
|
+
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
11
|
+
const rows = viewportRows.slice();
|
|
12
|
+
for (let i = 0; i < panel.length; i++) {
|
|
13
|
+
rows[y + i] = `${' '.repeat(x)}${truncate(panel[i] ?? '', width, '')}`;
|
|
14
|
+
}
|
|
15
|
+
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { truncate, visibleWidth } from './text.js';
|
|
2
|
+
|
|
3
|
+
export interface MessageActionPlacement {
|
|
4
|
+
rows: string[];
|
|
5
|
+
layout: { x: number; y: number; width: number; count: number } | null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message. */
|
|
9
|
+
export function placeMessageActionPanel(
|
|
10
|
+
viewportRows: string[], panel: string[], contentWidth: number,
|
|
11
|
+
stageTop: number, anchorY: number | null, count: number
|
|
12
|
+
): MessageActionPlacement {
|
|
13
|
+
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
14
|
+
return { rows: viewportRows, layout: null };
|
|
15
|
+
}
|
|
16
|
+
const width = Math.min(contentWidth, Math.max(...panel.map(visibleWidth)));
|
|
17
|
+
const x = Math.max(0, Math.floor((contentWidth - width) / 2));
|
|
18
|
+
const anchor = anchorY === null ? Math.floor(viewportRows.length / 2) : anchorY - stageTop;
|
|
19
|
+
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
20
|
+
const rows = viewportRows.slice();
|
|
21
|
+
for (let i = 0; i < panel.length; i++) {
|
|
22
|
+
rows[y + i] = `${' '.repeat(x)}${truncate(panel[i] ?? '', width, '')}`;
|
|
23
|
+
}
|
|
24
|
+
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
25
|
+
}
|