@causyne/agent 1.19.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 +66 -37
- package/src/commands.js +343 -72
- package/src/config.js +22 -12
- package/src/continuum/ingest.js +1 -1
- package/src/continuum/ingest.ts +1 -1
- 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 +36 -8
- 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 +66 -10
- package/src/sessionJournal.ts +84 -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 +118 -45
- 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 +13 -0
- package/src/tui/modelPicker.ts +12 -0
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +199 -52
- 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 +280 -0
- package/src/tui/sessionPicker.ts +364 -0
- 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 +128 -57
- package/src/tui/statusLine.js +5 -5
- 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,364 @@
|
|
|
1
|
+
// Sovereign Interactive Session Picker — modal dialog for listing, switching, and creating sessions.
|
|
2
|
+
// Authored in Strict TypeScript for Causyne Agent.
|
|
3
|
+
// Source-available under BUSL-1.1.
|
|
4
|
+
|
|
5
|
+
// @ts-expect-error untyped local TUI dialogs
|
|
6
|
+
import { SelectLayer } from './dialogs.js';
|
|
7
|
+
// @ts-expect-error untyped local TUI theme
|
|
8
|
+
import { GLYPHS } from './theme.js';
|
|
9
|
+
import {
|
|
10
|
+
listSessions,
|
|
11
|
+
getActiveSessionId,
|
|
12
|
+
switchSession,
|
|
13
|
+
createSession,
|
|
14
|
+
forkSession,
|
|
15
|
+
type SessionRecord
|
|
16
|
+
} from '../sessionJournal.js';
|
|
17
|
+
import { revokeAllAlways } from '../approvalGrants.js';
|
|
18
|
+
|
|
19
|
+
export interface SessionPickerItemValue {
|
|
20
|
+
type: 'new' | 'switch' | 'fork';
|
|
21
|
+
id?: string | undefined;
|
|
22
|
+
title?: string | undefined;
|
|
23
|
+
workspace?: string | undefined;
|
|
24
|
+
messageCount?: number | undefined;
|
|
25
|
+
isCurrent?: boolean | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SessionPickerItem {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
category: string;
|
|
32
|
+
description: string;
|
|
33
|
+
searchText?: string;
|
|
34
|
+
value: SessionPickerItemValue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface InteractiveSessionPickerOptions {
|
|
38
|
+
loop?: {
|
|
39
|
+
taskId?: string;
|
|
40
|
+
messages?: Array<{ role: string; content?: unknown }>;
|
|
41
|
+
tokenTracker?: { reset?: () => void; sessionTokens?: number };
|
|
42
|
+
resetApprovalScope?: () => void;
|
|
43
|
+
memoryManager?: {
|
|
44
|
+
startNewSession?: (title?: string) => any;
|
|
45
|
+
useSession?: (id: string) => any;
|
|
46
|
+
forkSession?: (title?: string) => any;
|
|
47
|
+
loadHistory?: () => Array<{ role: string; content?: unknown }>;
|
|
48
|
+
sessionId?: string | null;
|
|
49
|
+
session?: any;
|
|
50
|
+
};
|
|
51
|
+
} | undefined;
|
|
52
|
+
workspace?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The divider counts conversation turns that the history renderer can show. */
|
|
56
|
+
function visibleHistoryCount(messages: Array<{ role: string; content?: unknown }>): number {
|
|
57
|
+
return messages.filter((message) => {
|
|
58
|
+
if (message.role !== 'user' && message.role !== 'assistant') return false;
|
|
59
|
+
if (typeof message.content === 'string') return message.content.trim().length > 0;
|
|
60
|
+
if (Array.isArray(message.content)) {
|
|
61
|
+
return message.content.some((part: unknown) =>
|
|
62
|
+
typeof part === 'string' && part.trim().length > 0
|
|
63
|
+
|| !!part && typeof part === 'object' && 'text' in part
|
|
64
|
+
&& typeof part.text === 'string' && part.text.trim().length > 0);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}).length;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function formatTimeAgo(timestamp: number): string {
|
|
71
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
72
|
+
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
73
|
+
if (minutes < 1) return 'just now';
|
|
74
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
75
|
+
const hours = Math.floor(minutes / 60);
|
|
76
|
+
if (hours < 24) return `${hours}h ago`;
|
|
77
|
+
const days = Math.floor(hours / 24);
|
|
78
|
+
return `${days}d ago`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function dateGroup(timestamp: number): string {
|
|
82
|
+
const date = new Date(timestamp);
|
|
83
|
+
if (!Number.isFinite(date.getTime())) return 'Unknown date';
|
|
84
|
+
const today = new Date();
|
|
85
|
+
if (date.toDateString() === today.toDateString()) return 'Today';
|
|
86
|
+
const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1);
|
|
87
|
+
return date.toDateString() === yesterday.toDateString() ? 'Yesterday' : date.toDateString();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function shortenPath(p: string | undefined): string {
|
|
91
|
+
if (!p) return '(default)';
|
|
92
|
+
const home = process.env.HOME || '';
|
|
93
|
+
if (home && p.startsWith(home)) {
|
|
94
|
+
return '~' + p.slice(home.length);
|
|
95
|
+
}
|
|
96
|
+
return p.split('/').pop() || p;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Build item list for SelectLayer modal.
|
|
101
|
+
* The top item is always "+ New Session" to guarantee clean separation and quick reset.
|
|
102
|
+
*/
|
|
103
|
+
export function buildSessionPickerItems(
|
|
104
|
+
sessions: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }>,
|
|
105
|
+
activeId: string | null,
|
|
106
|
+
currentWorkspace: string
|
|
107
|
+
): SessionPickerItem[] {
|
|
108
|
+
const items: SessionPickerItem[] = [];
|
|
109
|
+
|
|
110
|
+
// Pinned item 0: Create new clean conversation
|
|
111
|
+
items.push({
|
|
112
|
+
id: '__NEW_SESSION__',
|
|
113
|
+
label: '+ New Session (Start fresh conversation)',
|
|
114
|
+
category: 'Actions',
|
|
115
|
+
description: 'Begin a clean session in this workspace without previous context',
|
|
116
|
+
searchText: 'new session fresh clear reset start',
|
|
117
|
+
value: {
|
|
118
|
+
type: 'new'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Pinned item 1: Fork active conversation if available
|
|
123
|
+
if (activeId) {
|
|
124
|
+
const active = sessions.find(s => s.id === activeId);
|
|
125
|
+
if (active) {
|
|
126
|
+
items.push({
|
|
127
|
+
id: '__FORK_SESSION__',
|
|
128
|
+
label: `Branch / Fork Current Session ("${active.title}")`,
|
|
129
|
+
category: 'Actions',
|
|
130
|
+
description: 'Copy conversation history into a new branch without copying permissions',
|
|
131
|
+
searchText: 'fork branch clone copy session fresh permissions',
|
|
132
|
+
value: {
|
|
133
|
+
type: 'fork',
|
|
134
|
+
id: activeId,
|
|
135
|
+
title: active.title
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const s of [...sessions].sort((a, b) => b.updatedAt - a.updatedAt)) {
|
|
142
|
+
// A session without any turns has no conversation to resume. Keep the
|
|
143
|
+
// active one available, but do not fill the picker with abandoned starts.
|
|
144
|
+
if (s.messageCount === 0 && s.id !== activeId) continue;
|
|
145
|
+
const isCurrent = s.id === activeId;
|
|
146
|
+
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
147
|
+
const wsLabel = shortenPath(s.workspace);
|
|
148
|
+
const msgCount = `${s.messageCount} msg${s.messageCount === 1 ? '' : 's'}`;
|
|
149
|
+
|
|
150
|
+
const category = dateGroup(s.updatedAt);
|
|
151
|
+
|
|
152
|
+
const mark = isCurrent ? `● ` : ` `;
|
|
153
|
+
const tag = isCurrent ? ` [active]` : '';
|
|
154
|
+
|
|
155
|
+
items.push({
|
|
156
|
+
id: s.id,
|
|
157
|
+
label: `${mark}${s.title}${tag}`,
|
|
158
|
+
category,
|
|
159
|
+
description: `${msgCount} ${GLYPHS.dot} ${timeAgo} ${GLYPHS.dot} ${wsLabel}${s.workspace === currentWorkspace ? ' (current)' : ''}`,
|
|
160
|
+
searchText: `${s.title} ${s.id} ${s.workspace || ''} ${category}`,
|
|
161
|
+
value: {
|
|
162
|
+
type: 'switch',
|
|
163
|
+
id: s.id,
|
|
164
|
+
title: s.title,
|
|
165
|
+
workspace: s.workspace,
|
|
166
|
+
messageCount: s.messageCount,
|
|
167
|
+
isCurrent
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return items;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Launch the interactive Session Picker modal.
|
|
177
|
+
* Single Enter switches session or creates a new one immediately.
|
|
178
|
+
*/
|
|
179
|
+
export async function runInteractiveSessionPicker(
|
|
180
|
+
prompt: {
|
|
181
|
+
openLayer: (layer: unknown) => void;
|
|
182
|
+
editor?: { clear: () => void };
|
|
183
|
+
scheduleDraw?: () => void;
|
|
184
|
+
updateModel?: (provider?: string, model?: string) => void;
|
|
185
|
+
renderer?: { status?: { setSession: (info: any) => void } };
|
|
186
|
+
},
|
|
187
|
+
options: InteractiveSessionPickerOptions = {}
|
|
188
|
+
): Promise<string> {
|
|
189
|
+
const workspace = options.workspace || process.cwd();
|
|
190
|
+
const sessions = listSessions();
|
|
191
|
+
const activeId = getActiveSessionId();
|
|
192
|
+
|
|
193
|
+
const items = buildSessionPickerItems(sessions, activeId, workspace);
|
|
194
|
+
const conversationCount = items.filter(item => item.value.type === 'switch').length;
|
|
195
|
+
|
|
196
|
+
const cleanPrompt = () => {
|
|
197
|
+
if (prompt.editor && typeof prompt.editor.clear === 'function') {
|
|
198
|
+
prompt.editor.clear();
|
|
199
|
+
if (typeof prompt.scheduleDraw === 'function') prompt.scheduleDraw();
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const picked = await new Promise<SessionPickerItem | null>((resolve) => {
|
|
204
|
+
const layer = new SelectLayer({
|
|
205
|
+
title: `Sessions (${conversationCount})`,
|
|
206
|
+
placeholder: 'search sessions by title, id, or workspace...',
|
|
207
|
+
emptyText: 'no matching sessions found',
|
|
208
|
+
width: 78,
|
|
209
|
+
height: 20,
|
|
210
|
+
footer: `enter select session ${GLYPHS.dot} esc cancel`,
|
|
211
|
+
items,
|
|
212
|
+
onPick: (item: SessionPickerItem | null) => {
|
|
213
|
+
resolve(item || null);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
// Opening the picker should highlight a conversation, not an action that
|
|
217
|
+
// creates a new one. Actions remain available above the dated list.
|
|
218
|
+
const selected = items.findIndex(item => item.id === activeId);
|
|
219
|
+
const firstConversation = items.findIndex(item => item.value.type === 'switch');
|
|
220
|
+
layer.list.moveTo(selected >= 0 ? selected : Math.max(0, firstConversation), 15);
|
|
221
|
+
prompt.openLayer(layer);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
cleanPrompt();
|
|
225
|
+
|
|
226
|
+
if (!picked || !picked.value) {
|
|
227
|
+
return 'Cancelled. Session was not changed.';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Case 1: Start fresh new session
|
|
231
|
+
if (picked.value.type === 'new') {
|
|
232
|
+
let newSession: SessionRecord;
|
|
233
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.startNewSession === 'function') {
|
|
234
|
+
newSession = options.loop.memoryManager.startNewSession('Untitled');
|
|
235
|
+
} else {
|
|
236
|
+
newSession = createSession(workspace, 'Untitled', true);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (options.loop) {
|
|
240
|
+
options.loop.messages = [];
|
|
241
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
242
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
243
|
+
options.loop.tokenTracker.reset();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const renderer = (prompt as any).renderer || (options.loop as any)?.connection?.renderer;
|
|
248
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
249
|
+
renderer.renderSessionHistory([], {
|
|
250
|
+
id: newSession.id,
|
|
251
|
+
title: newSession.title,
|
|
252
|
+
messagesCount: 0
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if ((prompt as any).surface?.viewport && typeof (prompt as any).surface.viewport.toBottom === 'function') {
|
|
256
|
+
(prompt as any).surface.viewport.toBottom();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
cleanPrompt();
|
|
260
|
+
return `Started new session: "${newSession.title}" (${newSession.id}) in ${shortenPath(workspace)}.`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Case 2: Fork session into a new branch without copying permissions
|
|
264
|
+
if (picked.value.type === 'fork') {
|
|
265
|
+
const sourceId = picked.value.id || activeId;
|
|
266
|
+
if (!sourceId) {
|
|
267
|
+
return 'Cancelled. No session to fork.';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let forked: SessionRecord | null = null;
|
|
271
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.forkSession === 'function') {
|
|
272
|
+
forked = options.loop.memoryManager.forkSession();
|
|
273
|
+
} else {
|
|
274
|
+
forked = forkSession(sourceId, { makeActive: true });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (!forked) {
|
|
278
|
+
cleanPrompt();
|
|
279
|
+
return `Could not fork session "${sourceId}".`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// CRITICAL SECURITY INVARIANT (Claude Code Architecture, p. 24):
|
|
283
|
+
// Permissions and allowlists MUST NOT be copied across the fork.
|
|
284
|
+
revokeAllAlways();
|
|
285
|
+
if (options.loop && typeof options.loop.resetApprovalScope === 'function') {
|
|
286
|
+
options.loop.resetApprovalScope();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const historyMessages = options.loop?.memoryManager && typeof options.loop.memoryManager.loadHistory === 'function'
|
|
290
|
+
? options.loop.memoryManager.loadHistory()
|
|
291
|
+
: forked.messages.filter(m => m.role !== 'system');
|
|
292
|
+
|
|
293
|
+
if (options.loop) {
|
|
294
|
+
options.loop.messages = historyMessages;
|
|
295
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
296
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
297
|
+
options.loop.tokenTracker.reset();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const renderer = (prompt as any).renderer || (options.loop as any)?.connection?.renderer;
|
|
302
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
303
|
+
renderer.renderSessionHistory(historyMessages, {
|
|
304
|
+
id: forked.id,
|
|
305
|
+
title: forked.title,
|
|
306
|
+
messagesCount: visibleHistoryCount(historyMessages)
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if ((prompt as any).surface?.viewport && typeof (prompt as any).surface.viewport.toBottom === 'function') {
|
|
311
|
+
(prompt as any).surface.viewport.toBottom();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
cleanPrompt();
|
|
315
|
+
return `Forked into "${forked.title}" (${forked.messages.length} messages, ${forked.id}). Permissions and standing approvals were reset; any gated actions will request authorization anew.`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Case 3: Switch to selected session
|
|
319
|
+
const targetId = picked.value.id;
|
|
320
|
+
if (!targetId) {
|
|
321
|
+
return 'Cancelled. No session selected.';
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
let switched: SessionRecord | null = null;
|
|
325
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.useSession === 'function') {
|
|
326
|
+
switched = options.loop.memoryManager.useSession(targetId);
|
|
327
|
+
} else {
|
|
328
|
+
switched = switchSession(targetId);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (!switched) {
|
|
332
|
+
cleanPrompt();
|
|
333
|
+
return `⚠️ Could not switch to session "${targetId}". File may have been removed.`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const historyMessages = options.loop?.memoryManager && typeof options.loop.memoryManager.loadHistory === 'function'
|
|
337
|
+
? options.loop.memoryManager.loadHistory()
|
|
338
|
+
: switched.messages.filter(m => m.role !== 'system');
|
|
339
|
+
|
|
340
|
+
if (options.loop) {
|
|
341
|
+
options.loop.messages = historyMessages;
|
|
342
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
343
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
344
|
+
options.loop.tokenTracker.reset();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Render the conversation history to the transcript & viewport
|
|
349
|
+
const renderer = (prompt as any).renderer || (options.loop as any)?.connection?.renderer;
|
|
350
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
351
|
+
renderer.renderSessionHistory(historyMessages, {
|
|
352
|
+
id: switched.id,
|
|
353
|
+
title: switched.title,
|
|
354
|
+
messagesCount: visibleHistoryCount(historyMessages)
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if ((prompt as any).surface?.viewport && typeof (prompt as any).surface.viewport.toBottom === 'function') {
|
|
359
|
+
(prompt as any).surface.viewport.toBottom();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
cleanPrompt();
|
|
363
|
+
return `Switched to "${switched.title}" (${switched.messages.length} messages, ${switched.id}).`;
|
|
364
|
+
}
|
|
@@ -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',
|