@causyne/agent 1.18.0 → 1.20.0
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/package.json +1 -1
- package/src/agentLoop.js +2348 -2531
- package/src/agentLoop.ts +2865 -0
- package/src/checkpoints.d.ts +4 -0
- package/src/cliMode.js +30 -17
- package/src/commands.js +307 -57
- package/src/config.js +22 -0
- package/src/contextManager.d.ts +10 -0
- package/src/continuum/adapters/antigravity.js +193 -0
- package/src/continuum/adapters/antigravity.ts +204 -0
- package/src/continuum/adapters/base.js +48 -0
- package/src/continuum/adapters/base.ts +57 -0
- package/src/continuum/adapters/causyne.js +66 -0
- package/src/continuum/adapters/causyne.ts +72 -0
- package/src/continuum/adapters/claudeCode.js +171 -0
- package/src/continuum/adapters/claudeCode.ts +179 -0
- package/src/continuum/adapters/codex.js +181 -0
- package/src/continuum/adapters/codex.ts +193 -0
- package/src/continuum/adapters/opencode.js +134 -0
- package/src/continuum/adapters/opencode.ts +153 -0
- package/src/continuum/compactor.js +54 -0
- package/src/continuum/compactor.ts +83 -0
- package/src/continuum/index.js +8 -0
- package/src/continuum/index.ts +9 -0
- package/src/continuum/ingest.js +63 -0
- package/src/continuum/ingest.ts +89 -0
- package/src/continuum/sanitizer.js +55 -0
- package/src/continuum/sanitizer.ts +59 -0
- package/src/continuum/scanner.js +86 -0
- package/src/continuum/scanner.ts +106 -0
- package/src/continuum/types.js +3 -0
- package/src/continuum/types.ts +51 -0
- package/src/continuum/ui/continuumPicker.js +111 -0
- package/src/continuum/ui/continuumPicker.ts +145 -0
- package/src/cortex/autoCondenser.d.ts +2 -0
- package/src/cortex/vectorDb.d.ts +1 -0
- package/src/designPalettes.d.ts +2 -0
- package/src/devMode.d.ts +1 -0
- package/src/dynamicCatalogue.js +5 -3
- package/src/dynamicCatalogue.ts +7 -4
- package/src/embodimentSession.d.ts +2 -0
- package/src/entrypoint.js +12 -0
- package/src/memory.d.ts +1 -0
- package/src/memoryManager.d.ts +1 -0
- package/src/memoryManager.js +10 -6
- package/src/modelIds.d.ts +2 -0
- package/src/outputStore.d.ts +4 -0
- package/src/providers/acp.js +320 -299
- package/src/providers/acp.ts +360 -0
- package/src/providers/antigravity.js +387 -278
- package/src/providers/antigravity.ts +450 -0
- package/src/providers/base.d.ts +68 -0
- package/src/providers/factory.d.ts +1 -0
- package/src/provisioning/capabilityProvisioner.d.ts +2 -0
- package/src/sandbox.d.ts +1 -0
- package/src/sessionJournal.js +14 -1
- package/src/sessionJournal.ts +21 -1
- package/src/skillsManager.d.ts +3 -0
- package/src/slopDetector.d.ts +3 -0
- package/src/taskBuffer.d.ts +1 -0
- package/src/tokenTracker.d.ts +1 -0
- package/src/toolPacks.d.ts +8 -0
- package/src/tools/registry.d.ts +4 -0
- package/src/tui/chatRenderer.js +148 -8
- package/src/tui/clipboardSync.js +36 -0
- package/src/tui/clipboardSync.ts +36 -0
- package/src/tui/dialogs.js +15 -2
- package/src/tui/home.js +2 -1
- package/src/tui/modelPicker.js +254 -0
- package/src/tui/modelPicker.ts +318 -0
- package/src/tui/prompt.js +90 -8
- package/src/tui/selectList.js +20 -0
- package/src/tui/sessionPicker.js +185 -0
- package/src/tui/sessionPicker.ts +259 -0
- package/src/tui/stageSurface.js +9 -0
- package/src/tui/statusLine.js +5 -5
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
// @ts-expect-error untyped local TUI dialogs
|
|
5
|
+
import { SelectLayer } from './dialogs.js';
|
|
6
|
+
// @ts-expect-error untyped local TUI theme
|
|
7
|
+
import { GLYPHS } from './theme.js';
|
|
8
|
+
import { listSessions, getActiveSessionId, switchSession, createSession } from '../sessionJournal.js';
|
|
9
|
+
function formatTimeAgo(timestamp) {
|
|
10
|
+
const diffMs = Date.now() - timestamp;
|
|
11
|
+
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
12
|
+
if (minutes < 1)
|
|
13
|
+
return 'just now';
|
|
14
|
+
if (minutes < 60)
|
|
15
|
+
return `${minutes}m ago`;
|
|
16
|
+
const hours = Math.floor(minutes / (60 * 60 * 1000));
|
|
17
|
+
if (hours < 24)
|
|
18
|
+
return `${hours}h ago`;
|
|
19
|
+
const days = Math.floor(hours / (24 * 60 * 60 * 1000));
|
|
20
|
+
return `${days}d ago`;
|
|
21
|
+
}
|
|
22
|
+
function shortenPath(p) {
|
|
23
|
+
if (!p)
|
|
24
|
+
return '(default)';
|
|
25
|
+
const home = process.env.HOME || '';
|
|
26
|
+
if (home && p.startsWith(home)) {
|
|
27
|
+
return '~' + p.slice(home.length);
|
|
28
|
+
}
|
|
29
|
+
return p.split('/').pop() || p;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build item list for SelectLayer modal.
|
|
33
|
+
* The top item is always "+ New Session" to guarantee clean separation and quick reset.
|
|
34
|
+
*/
|
|
35
|
+
export function buildSessionPickerItems(sessions, activeId, currentWorkspace) {
|
|
36
|
+
const items = [];
|
|
37
|
+
// Pinned item 0: Create new clean conversation
|
|
38
|
+
items.push({
|
|
39
|
+
id: '__NEW_SESSION__',
|
|
40
|
+
label: '+ New Session (Start fresh conversation)',
|
|
41
|
+
category: 'Actions',
|
|
42
|
+
description: 'Begin a clean session in this workspace without previous context',
|
|
43
|
+
searchText: 'new session fresh clear reset start',
|
|
44
|
+
value: {
|
|
45
|
+
type: 'new'
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
for (const s of sessions) {
|
|
49
|
+
const isCurrent = s.id === activeId;
|
|
50
|
+
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
51
|
+
const wsLabel = shortenPath(s.workspace);
|
|
52
|
+
const msgCount = `${s.messageCount} msg${s.messageCount === 1 ? '' : 's'}`;
|
|
53
|
+
let category = 'Other Workspaces';
|
|
54
|
+
if (s.workspace === currentWorkspace || !s.workspace) {
|
|
55
|
+
category = 'Current Workspace';
|
|
56
|
+
}
|
|
57
|
+
if (s.title.startsWith('[Adopted]')) {
|
|
58
|
+
category = 'Continuum (Peer Agent)';
|
|
59
|
+
}
|
|
60
|
+
const mark = isCurrent ? `● ` : ` `;
|
|
61
|
+
const tag = isCurrent ? ` [active]` : '';
|
|
62
|
+
items.push({
|
|
63
|
+
id: s.id,
|
|
64
|
+
label: `${mark}${s.title}${tag}`,
|
|
65
|
+
category,
|
|
66
|
+
description: `${msgCount} ${GLYPHS.dot} ${timeAgo} ${GLYPHS.dot} ${wsLabel} ${GLYPHS.dot} ${s.id}`,
|
|
67
|
+
searchText: `${s.title} ${s.id} ${s.workspace || ''} ${category}`,
|
|
68
|
+
value: {
|
|
69
|
+
type: 'switch',
|
|
70
|
+
id: s.id,
|
|
71
|
+
title: s.title,
|
|
72
|
+
workspace: s.workspace,
|
|
73
|
+
messageCount: s.messageCount,
|
|
74
|
+
isCurrent
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return items;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Launch the interactive Session Picker modal.
|
|
82
|
+
* Single Enter switches session or creates a new one immediately.
|
|
83
|
+
*/
|
|
84
|
+
export async function runInteractiveSessionPicker(prompt, options = {}) {
|
|
85
|
+
const workspace = options.workspace || process.cwd();
|
|
86
|
+
const sessions = listSessions();
|
|
87
|
+
const activeId = getActiveSessionId();
|
|
88
|
+
const items = buildSessionPickerItems(sessions, activeId, workspace);
|
|
89
|
+
const cleanPrompt = () => {
|
|
90
|
+
if (prompt.editor && typeof prompt.editor.clear === 'function') {
|
|
91
|
+
prompt.editor.clear();
|
|
92
|
+
if (typeof prompt.scheduleDraw === 'function')
|
|
93
|
+
prompt.scheduleDraw();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const picked = await new Promise((resolve) => {
|
|
97
|
+
const layer = new SelectLayer({
|
|
98
|
+
title: `Sessions · Manage & Switch Conversations (${sessions.length})`,
|
|
99
|
+
placeholder: 'search sessions by title, id, or workspace...',
|
|
100
|
+
emptyText: 'no matching sessions found',
|
|
101
|
+
width: 78,
|
|
102
|
+
height: 20,
|
|
103
|
+
footer: `enter select session ${GLYPHS.dot} esc cancel`,
|
|
104
|
+
items,
|
|
105
|
+
onPick: (item) => {
|
|
106
|
+
resolve(item || null);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
prompt.openLayer(layer);
|
|
110
|
+
});
|
|
111
|
+
cleanPrompt();
|
|
112
|
+
if (!picked || !picked.value) {
|
|
113
|
+
return 'Cancelled. Session was not changed.';
|
|
114
|
+
}
|
|
115
|
+
// Case 1: Start fresh new session
|
|
116
|
+
if (picked.value.type === 'new') {
|
|
117
|
+
let newSession;
|
|
118
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.startNewSession === 'function') {
|
|
119
|
+
newSession = options.loop.memoryManager.startNewSession('Untitled');
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
newSession = createSession(workspace, 'Untitled', true);
|
|
123
|
+
}
|
|
124
|
+
if (options.loop) {
|
|
125
|
+
options.loop.messages = [];
|
|
126
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
127
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
128
|
+
options.loop.tokenTracker.reset();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const renderer = prompt.renderer || options.loop?.connection?.renderer;
|
|
132
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
133
|
+
renderer.renderSessionHistory([], {
|
|
134
|
+
id: newSession.id,
|
|
135
|
+
title: newSession.title,
|
|
136
|
+
messagesCount: 0
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (prompt.surface?.viewport && typeof prompt.surface.viewport.toBottom === 'function') {
|
|
140
|
+
prompt.surface.viewport.toBottom();
|
|
141
|
+
}
|
|
142
|
+
cleanPrompt();
|
|
143
|
+
return `Started new session: "${newSession.title}" (${newSession.id}) in ${shortenPath(workspace)}.`;
|
|
144
|
+
}
|
|
145
|
+
// Case 2: Switch to selected session
|
|
146
|
+
const targetId = picked.value.id;
|
|
147
|
+
if (!targetId) {
|
|
148
|
+
return 'Cancelled. No session selected.';
|
|
149
|
+
}
|
|
150
|
+
let switched = null;
|
|
151
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.useSession === 'function') {
|
|
152
|
+
switched = options.loop.memoryManager.useSession(targetId);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
switched = switchSession(targetId);
|
|
156
|
+
}
|
|
157
|
+
if (!switched) {
|
|
158
|
+
cleanPrompt();
|
|
159
|
+
return `⚠️ Could not switch to session "${targetId}". File may have been removed.`;
|
|
160
|
+
}
|
|
161
|
+
const historyMessages = options.loop?.memoryManager && typeof options.loop.memoryManager.loadHistory === 'function'
|
|
162
|
+
? options.loop.memoryManager.loadHistory()
|
|
163
|
+
: switched.messages.filter(m => m.role !== 'system');
|
|
164
|
+
if (options.loop) {
|
|
165
|
+
options.loop.messages = historyMessages;
|
|
166
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
167
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
168
|
+
options.loop.tokenTracker.reset();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Render the conversation history to the transcript & viewport
|
|
172
|
+
const renderer = prompt.renderer || options.loop?.connection?.renderer;
|
|
173
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
174
|
+
renderer.renderSessionHistory(historyMessages, {
|
|
175
|
+
id: switched.id,
|
|
176
|
+
title: switched.title,
|
|
177
|
+
messagesCount: switched.messages.length
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (prompt.surface?.viewport && typeof prompt.surface.viewport.toBottom === 'function') {
|
|
181
|
+
prompt.surface.viewport.toBottom();
|
|
182
|
+
}
|
|
183
|
+
cleanPrompt();
|
|
184
|
+
return `Switched to "${switched.title}" (${switched.messages.length} messages, ${switched.id}).`;
|
|
185
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
type SessionRecord
|
|
15
|
+
} from '../sessionJournal.js';
|
|
16
|
+
|
|
17
|
+
export interface SessionPickerItemValue {
|
|
18
|
+
type: 'new' | 'switch';
|
|
19
|
+
id?: string | undefined;
|
|
20
|
+
title?: string | undefined;
|
|
21
|
+
workspace?: string | undefined;
|
|
22
|
+
messageCount?: number | undefined;
|
|
23
|
+
isCurrent?: boolean | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SessionPickerItem {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
category: string;
|
|
30
|
+
description: string;
|
|
31
|
+
searchText?: string;
|
|
32
|
+
value: SessionPickerItemValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface InteractiveSessionPickerOptions {
|
|
36
|
+
loop?: {
|
|
37
|
+
taskId?: string;
|
|
38
|
+
messages?: Array<{ role: string; content?: unknown }>;
|
|
39
|
+
tokenTracker?: { reset?: () => void; sessionTokens?: number };
|
|
40
|
+
memoryManager?: {
|
|
41
|
+
startNewSession?: (title?: string) => any;
|
|
42
|
+
useSession?: (id: string) => any;
|
|
43
|
+
loadHistory?: () => Array<{ role: string; content?: unknown }>;
|
|
44
|
+
sessionId?: string | null;
|
|
45
|
+
session?: any;
|
|
46
|
+
};
|
|
47
|
+
} | undefined;
|
|
48
|
+
workspace?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatTimeAgo(timestamp: number): string {
|
|
52
|
+
const diffMs = Date.now() - timestamp;
|
|
53
|
+
const minutes = Math.floor(diffMs / (60 * 1000));
|
|
54
|
+
if (minutes < 1) return 'just now';
|
|
55
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
56
|
+
const hours = Math.floor(minutes / (60 * 60 * 1000));
|
|
57
|
+
if (hours < 24) return `${hours}h ago`;
|
|
58
|
+
const days = Math.floor(hours / (24 * 60 * 60 * 1000));
|
|
59
|
+
return `${days}d ago`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function shortenPath(p: string | undefined): string {
|
|
63
|
+
if (!p) return '(default)';
|
|
64
|
+
const home = process.env.HOME || '';
|
|
65
|
+
if (home && p.startsWith(home)) {
|
|
66
|
+
return '~' + p.slice(home.length);
|
|
67
|
+
}
|
|
68
|
+
return p.split('/').pop() || p;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Build item list for SelectLayer modal.
|
|
73
|
+
* The top item is always "+ New Session" to guarantee clean separation and quick reset.
|
|
74
|
+
*/
|
|
75
|
+
export function buildSessionPickerItems(
|
|
76
|
+
sessions: Array<Omit<SessionRecord, 'messages'> & { messageCount: number }>,
|
|
77
|
+
activeId: string | null,
|
|
78
|
+
currentWorkspace: string
|
|
79
|
+
): SessionPickerItem[] {
|
|
80
|
+
const items: SessionPickerItem[] = [];
|
|
81
|
+
|
|
82
|
+
// Pinned item 0: Create new clean conversation
|
|
83
|
+
items.push({
|
|
84
|
+
id: '__NEW_SESSION__',
|
|
85
|
+
label: '+ New Session (Start fresh conversation)',
|
|
86
|
+
category: 'Actions',
|
|
87
|
+
description: 'Begin a clean session in this workspace without previous context',
|
|
88
|
+
searchText: 'new session fresh clear reset start',
|
|
89
|
+
value: {
|
|
90
|
+
type: 'new'
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
for (const s of sessions) {
|
|
95
|
+
const isCurrent = s.id === activeId;
|
|
96
|
+
const timeAgo = formatTimeAgo(s.updatedAt);
|
|
97
|
+
const wsLabel = shortenPath(s.workspace);
|
|
98
|
+
const msgCount = `${s.messageCount} msg${s.messageCount === 1 ? '' : 's'}`;
|
|
99
|
+
|
|
100
|
+
let category = 'Other Workspaces';
|
|
101
|
+
if (s.workspace === currentWorkspace || !s.workspace) {
|
|
102
|
+
category = 'Current Workspace';
|
|
103
|
+
}
|
|
104
|
+
if (s.title.startsWith('[Adopted]')) {
|
|
105
|
+
category = 'Continuum (Peer Agent)';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const mark = isCurrent ? `● ` : ` `;
|
|
109
|
+
const tag = isCurrent ? ` [active]` : '';
|
|
110
|
+
|
|
111
|
+
items.push({
|
|
112
|
+
id: s.id,
|
|
113
|
+
label: `${mark}${s.title}${tag}`,
|
|
114
|
+
category,
|
|
115
|
+
description: `${msgCount} ${GLYPHS.dot} ${timeAgo} ${GLYPHS.dot} ${wsLabel} ${GLYPHS.dot} ${s.id}`,
|
|
116
|
+
searchText: `${s.title} ${s.id} ${s.workspace || ''} ${category}`,
|
|
117
|
+
value: {
|
|
118
|
+
type: 'switch',
|
|
119
|
+
id: s.id,
|
|
120
|
+
title: s.title,
|
|
121
|
+
workspace: s.workspace,
|
|
122
|
+
messageCount: s.messageCount,
|
|
123
|
+
isCurrent
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return items;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Launch the interactive Session Picker modal.
|
|
133
|
+
* Single Enter switches session or creates a new one immediately.
|
|
134
|
+
*/
|
|
135
|
+
export async function runInteractiveSessionPicker(
|
|
136
|
+
prompt: {
|
|
137
|
+
openLayer: (layer: unknown) => void;
|
|
138
|
+
editor?: { clear: () => void };
|
|
139
|
+
scheduleDraw?: () => void;
|
|
140
|
+
updateModel?: (provider?: string, model?: string) => void;
|
|
141
|
+
renderer?: { status?: { setSession: (info: any) => void } };
|
|
142
|
+
},
|
|
143
|
+
options: InteractiveSessionPickerOptions = {}
|
|
144
|
+
): Promise<string> {
|
|
145
|
+
const workspace = options.workspace || process.cwd();
|
|
146
|
+
const sessions = listSessions();
|
|
147
|
+
const activeId = getActiveSessionId();
|
|
148
|
+
|
|
149
|
+
const items = buildSessionPickerItems(sessions, activeId, workspace);
|
|
150
|
+
|
|
151
|
+
const cleanPrompt = () => {
|
|
152
|
+
if (prompt.editor && typeof prompt.editor.clear === 'function') {
|
|
153
|
+
prompt.editor.clear();
|
|
154
|
+
if (typeof prompt.scheduleDraw === 'function') prompt.scheduleDraw();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const picked = await new Promise<SessionPickerItem | null>((resolve) => {
|
|
159
|
+
const layer = new SelectLayer({
|
|
160
|
+
title: `Sessions · Manage & Switch Conversations (${sessions.length})`,
|
|
161
|
+
placeholder: 'search sessions by title, id, or workspace...',
|
|
162
|
+
emptyText: 'no matching sessions found',
|
|
163
|
+
width: 78,
|
|
164
|
+
height: 20,
|
|
165
|
+
footer: `enter select session ${GLYPHS.dot} esc cancel`,
|
|
166
|
+
items,
|
|
167
|
+
onPick: (item: SessionPickerItem | null) => {
|
|
168
|
+
resolve(item || null);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
prompt.openLayer(layer);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
cleanPrompt();
|
|
175
|
+
|
|
176
|
+
if (!picked || !picked.value) {
|
|
177
|
+
return 'Cancelled. Session was not changed.';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Case 1: Start fresh new session
|
|
181
|
+
if (picked.value.type === 'new') {
|
|
182
|
+
let newSession: SessionRecord;
|
|
183
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.startNewSession === 'function') {
|
|
184
|
+
newSession = options.loop.memoryManager.startNewSession('Untitled');
|
|
185
|
+
} else {
|
|
186
|
+
newSession = createSession(workspace, 'Untitled', true);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (options.loop) {
|
|
190
|
+
options.loop.messages = [];
|
|
191
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
192
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
193
|
+
options.loop.tokenTracker.reset();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const renderer = (prompt as any).renderer || (options.loop as any)?.connection?.renderer;
|
|
198
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
199
|
+
renderer.renderSessionHistory([], {
|
|
200
|
+
id: newSession.id,
|
|
201
|
+
title: newSession.title,
|
|
202
|
+
messagesCount: 0
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if ((prompt as any).surface?.viewport && typeof (prompt as any).surface.viewport.toBottom === 'function') {
|
|
206
|
+
(prompt as any).surface.viewport.toBottom();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
cleanPrompt();
|
|
210
|
+
return `Started new session: "${newSession.title}" (${newSession.id}) in ${shortenPath(workspace)}.`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Case 2: Switch to selected session
|
|
214
|
+
const targetId = picked.value.id;
|
|
215
|
+
if (!targetId) {
|
|
216
|
+
return 'Cancelled. No session selected.';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let switched: SessionRecord | null = null;
|
|
220
|
+
if (options.loop?.memoryManager && typeof options.loop.memoryManager.useSession === 'function') {
|
|
221
|
+
switched = options.loop.memoryManager.useSession(targetId);
|
|
222
|
+
} else {
|
|
223
|
+
switched = switchSession(targetId);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!switched) {
|
|
227
|
+
cleanPrompt();
|
|
228
|
+
return `⚠️ Could not switch to session "${targetId}". File may have been removed.`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const historyMessages = options.loop?.memoryManager && typeof options.loop.memoryManager.loadHistory === 'function'
|
|
232
|
+
? options.loop.memoryManager.loadHistory()
|
|
233
|
+
: switched.messages.filter(m => m.role !== 'system');
|
|
234
|
+
|
|
235
|
+
if (options.loop) {
|
|
236
|
+
options.loop.messages = historyMessages;
|
|
237
|
+
options.loop.taskId = `cli_chat_${Date.now()}`;
|
|
238
|
+
if (options.loop.tokenTracker && typeof options.loop.tokenTracker.reset === 'function') {
|
|
239
|
+
options.loop.tokenTracker.reset();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Render the conversation history to the transcript & viewport
|
|
244
|
+
const renderer = (prompt as any).renderer || (options.loop as any)?.connection?.renderer;
|
|
245
|
+
if (renderer && typeof renderer.renderSessionHistory === 'function') {
|
|
246
|
+
renderer.renderSessionHistory(historyMessages, {
|
|
247
|
+
id: switched.id,
|
|
248
|
+
title: switched.title,
|
|
249
|
+
messagesCount: switched.messages.length
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if ((prompt as any).surface?.viewport && typeof (prompt as any).surface.viewport.toBottom === 'function') {
|
|
254
|
+
(prompt as any).surface.viewport.toBottom();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
cleanPrompt();
|
|
258
|
+
return `Switched to "${switched.title}" (${switched.messages.length} messages, ${switched.id}).`;
|
|
259
|
+
}
|
package/src/tui/stageSurface.js
CHANGED
|
@@ -469,6 +469,15 @@ export class StageSurface {
|
|
|
469
469
|
return rows.length;
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
/** Clear the transcript without printing through to scrollback (for session switching). */
|
|
473
|
+
clearTranscript() {
|
|
474
|
+
this.evicted = [];
|
|
475
|
+
this.transcript.clear();
|
|
476
|
+
this.lastHeight = 0;
|
|
477
|
+
this.stage.invalidate();
|
|
478
|
+
this.viewport.toBottom();
|
|
479
|
+
}
|
|
480
|
+
|
|
472
481
|
/**
|
|
473
482
|
* The terminal changed size. Callers must debounce — ChatPrompt already
|
|
474
483
|
* settles resize at RESIZE_SETTLE_MS.
|
package/src/tui/statusLine.js
CHANGED
|
@@ -80,14 +80,14 @@ export class StatusLine {
|
|
|
80
80
|
|
|
81
81
|
/** Session-lifetime facts, set once from the same info as the header. */
|
|
82
82
|
setSession(info = {}) {
|
|
83
|
-
this.model = shortModel(info.model);
|
|
84
|
-
this.provider = info.provider ? String(info.provider) : '';
|
|
85
|
-
this.tier = info.tier ? String(info.tier) : '';
|
|
83
|
+
if (info.model !== undefined) this.model = shortModel(info.model);
|
|
84
|
+
if (info.provider !== undefined) this.provider = info.provider ? String(info.provider) : '';
|
|
85
|
+
if (info.tier !== undefined) this.tier = info.tier ? String(info.tier) : '';
|
|
86
86
|
// The idle footer answers "where am I and how much room is left", which is
|
|
87
87
|
// what opencode's permanent footer shows (cwd left, context right). Neither
|
|
88
88
|
// fact was reachable once the session header had scrolled away.
|
|
89
|
-
this.cwd = info.cwd ? String(info.cwd) : '';
|
|
90
|
-
this.contextLimit = Number(info.contextLimit) || 0;
|
|
89
|
+
if (info.cwd !== undefined) this.cwd = info.cwd ? String(info.cwd) : '';
|
|
90
|
+
if (info.contextLimit !== undefined) this.contextLimit = Number(info.contextLimit) || 0;
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
93
93
|
|