repoburg 1.3.185 → 1.3.188
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/agent-pane/backend/package-lock.json +2359 -0
- package/agent-pane/backend/package.json +29 -0
- package/agent-pane/backend/src/codex/codex-provider.ts +363 -0
- package/agent-pane/backend/src/codex/item-mapper.ts +59 -0
- package/agent-pane/backend/src/db/index.ts +91 -0
- package/agent-pane/backend/src/db/schema.ts +76 -0
- package/agent-pane/backend/src/index.ts +57 -0
- package/agent-pane/backend/src/routes/sessions.ts +134 -0
- package/agent-pane/backend/src/routes/turns.ts +60 -0
- package/agent-pane/backend/src/routes/workspaces.ts +110 -0
- package/agent-pane/backend/src/ws/index.ts +43 -0
- package/agent-pane/backend/tsconfig.json +23 -0
- package/agent-pane/frontend/index.html +18 -0
- package/agent-pane/frontend/package-lock.json +1948 -0
- package/agent-pane/frontend/package.json +28 -0
- package/agent-pane/frontend/src/App.tsx +44 -0
- package/agent-pane/frontend/src/AppInitializer.tsx +46 -0
- package/agent-pane/frontend/src/api/client.ts +41 -0
- package/agent-pane/frontend/src/api/sessions.ts +47 -0
- package/agent-pane/frontend/src/api/websocket.ts +149 -0
- package/agent-pane/frontend/src/api/workspaces.ts +24 -0
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +50 -0
- package/agent-pane/frontend/src/components/CommandInputBar.tsx +42 -0
- package/agent-pane/frontend/src/components/CommandPalette.tsx +207 -0
- package/agent-pane/frontend/src/components/DiffViewer.tsx +27 -0
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +25 -0
- package/agent-pane/frontend/src/components/NewSessionDialog.tsx +84 -0
- package/agent-pane/frontend/src/components/RenderArea.tsx +170 -0
- package/agent-pane/frontend/src/components/RightPanel.tsx +40 -0
- package/agent-pane/frontend/src/components/RuntimeIcon.tsx +16 -0
- package/agent-pane/frontend/src/components/SessionTabs.tsx +44 -0
- package/agent-pane/frontend/src/components/StatusBar.tsx +68 -0
- package/agent-pane/frontend/src/components/StatusDot.tsx +13 -0
- package/agent-pane/frontend/src/components/Toast.tsx +80 -0
- package/agent-pane/frontend/src/components/TurnContent.tsx +294 -0
- package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +350 -0
- package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +81 -0
- package/agent-pane/frontend/src/components/panels/LogsPanel.tsx +25 -0
- package/agent-pane/frontend/src/components/panels/MetricsPanel.tsx +82 -0
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +45 -0
- package/agent-pane/frontend/src/main.tsx +10 -0
- package/agent-pane/frontend/src/store/store.ts +635 -0
- package/agent-pane/frontend/src/styles/app.css +365 -0
- package/agent-pane/frontend/src/styles/tokens.css +62 -0
- package/agent-pane/frontend/src/types/index.ts +153 -0
- package/agent-pane/frontend/tsconfig.json +22 -0
- package/agent-pane/frontend/vite.config.ts +16 -0
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { marked } from 'marked';
|
|
2
|
+
import DOMPurify from 'dompurify';
|
|
3
|
+
import { memo, useState, useEffect } from 'react';
|
|
4
|
+
import { Layers, ChevronRight } from 'lucide-react';
|
|
5
|
+
import type { Turn, Item } from '../types/index.ts';
|
|
6
|
+
import CollapsibleToolCalls, { isToolItem } from './CollapsibleToolCalls.tsx';
|
|
7
|
+
|
|
8
|
+
marked.setOptions({ breaks: true, gfm: true });
|
|
9
|
+
|
|
10
|
+
function renderMarkdown(content: string): string {
|
|
11
|
+
const raw = marked.parse(content) as string;
|
|
12
|
+
return DOMPurify.sanitize(raw);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Extract text from item data (agent_message / reasoning have {text}). */
|
|
16
|
+
function itemText(item: Item): string {
|
|
17
|
+
if (item.data?.text) return item.data.text as string;
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Render a single item as a turn card. */
|
|
22
|
+
function ItemCard({ item }: { item: Item }) {
|
|
23
|
+
const isRunning = item.status === 'in_progress';
|
|
24
|
+
|
|
25
|
+
switch (item.type) {
|
|
26
|
+
case 'agent_message': {
|
|
27
|
+
return (
|
|
28
|
+
<div className="render-content">
|
|
29
|
+
<div className="turn-header">
|
|
30
|
+
<span className="turn-header-icon ic-codex">CX</span>
|
|
31
|
+
<span className="turn-header-title">Agent</span>
|
|
32
|
+
{isRunning && <span className="turn-header-meta">writing…</span>}
|
|
33
|
+
</div>
|
|
34
|
+
<div dangerouslySetInnerHTML={{ __html: renderMarkdown(itemText(item) || '…') }} />
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
case 'reasoning': {
|
|
40
|
+
return (
|
|
41
|
+
<div className="render-content">
|
|
42
|
+
<div className="turn-header">
|
|
43
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>💭</span>
|
|
44
|
+
<span className="turn-header-title">Reasoning</span>
|
|
45
|
+
</div>
|
|
46
|
+
<div dangerouslySetInnerHTML={{ __html: renderMarkdown(itemText(item)) }} />
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
case 'command_execution': {
|
|
52
|
+
const data = item.data || {};
|
|
53
|
+
const command = (data.command as string) || '';
|
|
54
|
+
const output = (data.aggregated_output as string) || '';
|
|
55
|
+
const exitCode = data.exit_code as number | null;
|
|
56
|
+
const summary = isRunning ? 'running…' : (exitCode !== null ? `exit ${exitCode}` : '');
|
|
57
|
+
return (
|
|
58
|
+
<div className="render-content">
|
|
59
|
+
<div className="turn-header">
|
|
60
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>🔧</span>
|
|
61
|
+
<span className="turn-header-title">Command</span>
|
|
62
|
+
{summary && <span className="turn-header-meta">{summary}</span>}
|
|
63
|
+
</div>
|
|
64
|
+
<pre className="cmd-block"><code>{command}</code></pre>
|
|
65
|
+
{output && <pre className="cmd-output"><code>{output}</code></pre>}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case 'file_change': {
|
|
71
|
+
const changes = (item.data?.changes as Array<{ path: string; kind: string }>) || [];
|
|
72
|
+
const summary = `${changes.length} file${changes.length !== 1 ? 's' : ''}`;
|
|
73
|
+
return (
|
|
74
|
+
<div className="render-content">
|
|
75
|
+
<div className="turn-header">
|
|
76
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>📁</span>
|
|
77
|
+
<span className="turn-header-title">File Changes</span>
|
|
78
|
+
<span className="turn-header-meta">{summary}</span>
|
|
79
|
+
</div>
|
|
80
|
+
<div className="file-change-list">
|
|
81
|
+
{changes.map((c, i) => {
|
|
82
|
+
const statusChar = c.kind === 'add' ? 'A' : c.kind === 'delete' ? 'D' : 'M';
|
|
83
|
+
const statusClass = c.kind === 'add' ? 'fc-add' : c.kind === 'delete' ? 'fc-del' : 'fc-mod';
|
|
84
|
+
return (
|
|
85
|
+
<div key={i} className="file-change">
|
|
86
|
+
<span className={`fc-status ${statusClass}`}>{statusChar}</span>
|
|
87
|
+
<span className="fc-name">{c.path}</span>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
})}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
case 'mcp_tool_call': {
|
|
97
|
+
const data = item.data || {};
|
|
98
|
+
const tool = (data.tool as string) || 'mcp';
|
|
99
|
+
const server = (data.server as string) || '';
|
|
100
|
+
return (
|
|
101
|
+
<div className="render-content">
|
|
102
|
+
<div className="turn-header">
|
|
103
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>🔌</span>
|
|
104
|
+
<span className="turn-header-title">MCP: {tool}</span>
|
|
105
|
+
{server && <span className="turn-header-meta">{server}</span>}
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
case 'web_search': {
|
|
112
|
+
const query = (item.data?.query as string) || '';
|
|
113
|
+
return (
|
|
114
|
+
<div className="render-content">
|
|
115
|
+
<div className="turn-header">
|
|
116
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>🔍</span>
|
|
117
|
+
<span className="turn-header-title">Web Search</span>
|
|
118
|
+
</div>
|
|
119
|
+
<p className="user-message">{query}</p>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
case 'todo_list': {
|
|
125
|
+
const items = (item.data?.items as Array<{ text: string; completed: boolean }>) || [];
|
|
126
|
+
return (
|
|
127
|
+
<div className="render-content">
|
|
128
|
+
<div className="turn-header">
|
|
129
|
+
<span className="turn-header-icon" style={{ background: 'var(--surface-2)', color: 'var(--text-3)' }}>📋</span>
|
|
130
|
+
<span className="turn-header-title">Todo List</span>
|
|
131
|
+
</div>
|
|
132
|
+
<ul className="todo-list">
|
|
133
|
+
{items.map((t, i) => (
|
|
134
|
+
<li key={i} className={t.completed ? 'todo-done' : 'todo-pending'}>
|
|
135
|
+
{t.completed ? '✅' : '⬜'} {t.text}
|
|
136
|
+
</li>
|
|
137
|
+
))}
|
|
138
|
+
</ul>
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
case 'error': {
|
|
144
|
+
const msg = (item.data?.message as string) || 'Unknown error';
|
|
145
|
+
return (
|
|
146
|
+
<div className="render-content">
|
|
147
|
+
<div className="turn-header">
|
|
148
|
+
<span className="turn-header-icon" style={{ background: 'var(--red)', color: '#fff' }}>!</span>
|
|
149
|
+
<span className="turn-header-title">Error</span>
|
|
150
|
+
</div>
|
|
151
|
+
<pre className="cmd-output" style={{ color: 'var(--red)' }}><code>{msg}</code></pre>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
default:
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const MemoItemCard = memo(ItemCard);
|
|
162
|
+
export { MemoItemCard };
|
|
163
|
+
|
|
164
|
+
interface Props {
|
|
165
|
+
turn: Turn;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function TurnContentBase({ turn }: Props) {
|
|
169
|
+
const [intermediateExpanded, setIntermediateExpanded] = useState(false);
|
|
170
|
+
|
|
171
|
+
// Auto-expand Level 1 when turn is running/pending, auto-collapse when completed
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (turn.status === 'running' || turn.status === 'pending') {
|
|
174
|
+
setIntermediateExpanded(true);
|
|
175
|
+
} else if (turn.status === 'completed') {
|
|
176
|
+
setIntermediateExpanded(false);
|
|
177
|
+
}
|
|
178
|
+
}, [turn.status]);
|
|
179
|
+
|
|
180
|
+
// Find the last agent_message item — that is the final response
|
|
181
|
+
let lastAgentIdx = -1;
|
|
182
|
+
for (let i = turn.items.length - 1; i >= 0; i--) {
|
|
183
|
+
if (turn.items[i].type === 'agent_message') {
|
|
184
|
+
lastAgentIdx = i;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const hasFinalResponse = lastAgentIdx >= 0;
|
|
190
|
+
// Intermediate = everything before final agent_message (or ALL items if running)
|
|
191
|
+
const intermediateItems = hasFinalResponse
|
|
192
|
+
? turn.items.slice(0, lastAgentIdx)
|
|
193
|
+
: turn.items;
|
|
194
|
+
|
|
195
|
+
// Group intermediate items into segments by agent_message boundaries
|
|
196
|
+
// Each segment: one agent_message + following tool/non-tool items until next agent_message
|
|
197
|
+
interface Segment {
|
|
198
|
+
agentMessage: Item | null;
|
|
199
|
+
toolItems: Item[];
|
|
200
|
+
otherItems: Item[];
|
|
201
|
+
}
|
|
202
|
+
const segments: Segment[] = [];
|
|
203
|
+
let currentSeg: Segment | null = null;
|
|
204
|
+
for (const item of intermediateItems) {
|
|
205
|
+
if (item.type === 'agent_message') {
|
|
206
|
+
if (currentSeg) segments.push(currentSeg);
|
|
207
|
+
currentSeg = { agentMessage: item, toolItems: [], otherItems: [] };
|
|
208
|
+
} else {
|
|
209
|
+
if (!currentSeg) currentSeg = { agentMessage: null, toolItems: [], otherItems: [] };
|
|
210
|
+
if (isToolItem(item)) currentSeg.toolItems.push(item);
|
|
211
|
+
else currentSeg.otherItems.push(item);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (currentSeg) segments.push(currentSeg);
|
|
215
|
+
|
|
216
|
+
const intermediateCount = intermediateItems.length;
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<div className="turn-group">
|
|
220
|
+
{/* User prompt — always visible at top */}
|
|
221
|
+
<div className="render-content">
|
|
222
|
+
<div className="turn-header">
|
|
223
|
+
<span className="turn-header-icon" style={{ background: 'var(--amber)', color: '#fff' }}>U</span>
|
|
224
|
+
<span className="turn-header-title">You</span>
|
|
225
|
+
</div>
|
|
226
|
+
<p className="user-message">{turn.user_prompt}</p>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
{/* Level 1: Intermediate steps — collapsible (auto-expand while running, auto-collapse on complete) */}
|
|
230
|
+
{intermediateCount > 0 && (
|
|
231
|
+
<div className="tool-calls">
|
|
232
|
+
<div className="tool-calls-header" onClick={() => setIntermediateExpanded((e) => !e)}>
|
|
233
|
+
<span className="tool-calls-icon">
|
|
234
|
+
<Layers size={12} />
|
|
235
|
+
</span>
|
|
236
|
+
<span className="tool-calls-summary">
|
|
237
|
+
{intermediateCount} intermediate step{intermediateCount > 1 ? 's' : ''}
|
|
238
|
+
</span>
|
|
239
|
+
<ChevronRight
|
|
240
|
+
size={14}
|
|
241
|
+
className="tool-calls-chevron"
|
|
242
|
+
style={{ transform: intermediateExpanded ? 'rotate(90deg)' : 'none' }}
|
|
243
|
+
/>
|
|
244
|
+
</div>
|
|
245
|
+
{intermediateExpanded && (
|
|
246
|
+
<div className="tool-calls-body">
|
|
247
|
+
{segments.map((seg, i) => (
|
|
248
|
+
<div key={i} className="intermediate-segment">
|
|
249
|
+
{/* Agent message for this segment */}
|
|
250
|
+
{seg.agentMessage && <MemoItemCard item={seg.agentMessage} />}
|
|
251
|
+
{/* Non-tool items inline (reasoning, etc.) */}
|
|
252
|
+
{seg.otherItems.map((item) => (
|
|
253
|
+
<MemoItemCard key={item.id} item={item} />
|
|
254
|
+
))}
|
|
255
|
+
{/* Level 2: Tool calls for this segment — collapsed by default */}
|
|
256
|
+
{seg.toolItems.length > 0 && <CollapsibleToolCalls items={seg.toolItems} />}
|
|
257
|
+
</div>
|
|
258
|
+
))}
|
|
259
|
+
</div>
|
|
260
|
+
)}
|
|
261
|
+
</div>
|
|
262
|
+
)}
|
|
263
|
+
|
|
264
|
+
{/* Final agent message — always visible */}
|
|
265
|
+
{hasFinalResponse && (
|
|
266
|
+
<MemoItemCard key={turn.items[lastAgentIdx].id} item={turn.items[lastAgentIdx]} />
|
|
267
|
+
)}
|
|
268
|
+
|
|
269
|
+
{/* Items after final agent message (rare — errors, etc.) */}
|
|
270
|
+
{hasFinalResponse && turn.items.slice(lastAgentIdx + 1).map((item) => (
|
|
271
|
+
<MemoItemCard key={item.id} item={item} />
|
|
272
|
+
))}
|
|
273
|
+
|
|
274
|
+
{/* Pending state (no items at all) */}
|
|
275
|
+
{turn.items.length === 0 && !turn.error && (turn.status === 'pending' || turn.status === 'running') && (
|
|
276
|
+
<div className="render-content">
|
|
277
|
+
<p style={{ color: 'var(--text-muted)', fontStyle: 'italic' }}>
|
|
278
|
+
{turn.status === 'running' ? 'Agent is thinking…' : 'Waiting to start…'}
|
|
279
|
+
</p>
|
|
280
|
+
</div>
|
|
281
|
+
)}
|
|
282
|
+
|
|
283
|
+
{/* Turn error (if any) */}
|
|
284
|
+
{turn.error && (
|
|
285
|
+
<div className="render-content">
|
|
286
|
+
<pre className="cmd-output" style={{ color: 'var(--red)' }}><code>{turn.error}</code></pre>
|
|
287
|
+
</div>
|
|
288
|
+
)}
|
|
289
|
+
</div>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const TurnContent = memo(TurnContentBase);
|
|
294
|
+
export default TurnContent;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { useStore } from '../store/store.ts';
|
|
3
|
+
import { statusToDot, runtimeIcon } from '../types/index.ts';
|
|
4
|
+
import type { Session, Workspace } from '../types/index.ts';
|
|
5
|
+
import StatusDot from './StatusDot.tsx';
|
|
6
|
+
import RuntimeIcon from './RuntimeIcon.tsx';
|
|
7
|
+
import { Plus, ChevronDown, Folder, FolderPlus, Trash2, Edit3, CheckCircle2, RotateCcw } from 'lucide-react';
|
|
8
|
+
|
|
9
|
+
interface ContextMenuState {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
type: 'workspace' | 'session';
|
|
13
|
+
path?: string;
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
sessionTitle?: string | null;
|
|
16
|
+
sessionLifecycle?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface WorkspaceGroup {
|
|
20
|
+
path: string;
|
|
21
|
+
label: string;
|
|
22
|
+
sessions: Session[];
|
|
23
|
+
workspace: Workspace | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Build workspace groups from active workspaces + session cwd values.
|
|
27
|
+
* Deleted workspace paths are excluded from implicit groups. */
|
|
28
|
+
function buildGroups(workspaces: Workspace[], sessions: Session[]): WorkspaceGroup[] {
|
|
29
|
+
const sessionByCwd = new Map<string, Session[]>();
|
|
30
|
+
|
|
31
|
+
for (const s of sessions) {
|
|
32
|
+
const key = s.cwd || '(no directory)';
|
|
33
|
+
const list = sessionByCwd.get(key) ?? [];
|
|
34
|
+
list.push(s);
|
|
35
|
+
sessionByCwd.set(key, list);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const seenPaths = new Set<string>();
|
|
39
|
+
const deletedPaths = new Set(workspaces.filter((w) => w.deleted === 1).map((w) => w.path));
|
|
40
|
+
const groups: WorkspaceGroup[] = [];
|
|
41
|
+
|
|
42
|
+
// Active explicit workspaces first (deleted = 0)
|
|
43
|
+
for (const ws of workspaces) {
|
|
44
|
+
if (ws.deleted === 1) {
|
|
45
|
+
seenPaths.add(ws.path);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
seenPaths.add(ws.path);
|
|
49
|
+
groups.push({
|
|
50
|
+
path: ws.path,
|
|
51
|
+
label: ws.label || ws.path.split('/').pop() || ws.path,
|
|
52
|
+
sessions: sessionByCwd.get(ws.path) ?? [],
|
|
53
|
+
workspace: ws,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Implicit groups — session cwd values not in any workspace (active or deleted)
|
|
58
|
+
for (const [path, sess] of sessionByCwd) {
|
|
59
|
+
if (seenPaths.has(path) || deletedPaths.has(path)) continue;
|
|
60
|
+
groups.push({
|
|
61
|
+
path,
|
|
62
|
+
label: path === '(no directory)' ? 'Other' : path.split('/').pop() || path,
|
|
63
|
+
sessions: sess,
|
|
64
|
+
workspace: null,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return groups;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default function WorkspaceSidebar() {
|
|
72
|
+
const { sessions, workspaces, activeSessionId, selectSession, deleteSession, removeWorkspace, createSessionInWorkspace, pickAndAddWorkspace, renameSession, markFinished, reopenSession } = useStore();
|
|
73
|
+
const [collapsed, setCollapsed] = useState<Set<string>>(new Set());
|
|
74
|
+
const [subCollapsed, setSubCollapsed] = useState<Set<string>>(new Set());
|
|
75
|
+
const [ctxMenu, setCtxMenu] = useState<ContextMenuState | null>(null);
|
|
76
|
+
const [renamingId, setRenamingId] = useState<string | null>(null);
|
|
77
|
+
const [renameValue, setRenameValue] = useState('');
|
|
78
|
+
const ctxRef = useRef<HTMLDivElement>(null);
|
|
79
|
+
const renameRef = useRef<HTMLInputElement>(null);
|
|
80
|
+
|
|
81
|
+
function toggleSection(path: string) {
|
|
82
|
+
setCollapsed((prev) => {
|
|
83
|
+
const next = new Set(prev);
|
|
84
|
+
if (next.has(path)) next.delete(path);
|
|
85
|
+
else next.add(path);
|
|
86
|
+
return next;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function toggleSubGroup(key: string) {
|
|
91
|
+
setSubCollapsed((prev) => {
|
|
92
|
+
const next = new Set(prev);
|
|
93
|
+
if (next.has(key)) next.delete(key);
|
|
94
|
+
else next.add(key);
|
|
95
|
+
return next;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Close context menu on outside click or Escape
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!ctxMenu) return;
|
|
102
|
+
function handleClick(e: MouseEvent) {
|
|
103
|
+
if (ctxRef.current && !ctxRef.current.contains(e.target as Node)) {
|
|
104
|
+
setCtxMenu(null);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function handleEscape(e: KeyboardEvent) {
|
|
108
|
+
if (e.key === 'Escape') setCtxMenu(null);
|
|
109
|
+
}
|
|
110
|
+
document.addEventListener('mousedown', handleClick);
|
|
111
|
+
document.addEventListener('keydown', handleEscape);
|
|
112
|
+
return () => {
|
|
113
|
+
document.removeEventListener('mousedown', handleClick);
|
|
114
|
+
document.removeEventListener('keydown', handleEscape);
|
|
115
|
+
};
|
|
116
|
+
}, [ctxMenu]);
|
|
117
|
+
|
|
118
|
+
// Focus rename input when it appears
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (renamingId && renameRef.current) {
|
|
121
|
+
renameRef.current.focus();
|
|
122
|
+
renameRef.current.select();
|
|
123
|
+
}
|
|
124
|
+
}, [renamingId]);
|
|
125
|
+
|
|
126
|
+
function startRename(id: string, currentTitle: string) {
|
|
127
|
+
setRenamingId(id);
|
|
128
|
+
setRenameValue(currentTitle || id.slice(0, 8));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function confirmRename() {
|
|
132
|
+
if (renamingId) {
|
|
133
|
+
renameSession(renamingId, renameValue);
|
|
134
|
+
}
|
|
135
|
+
setRenamingId(null);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function cancelRename() {
|
|
139
|
+
setRenamingId(null);
|
|
140
|
+
setRenameValue('');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const groups = buildGroups(workspaces, sessions);
|
|
144
|
+
|
|
145
|
+
function renderSession(s: Session) {
|
|
146
|
+
const isActive = activeSessionId === s.id;
|
|
147
|
+
const isFinished = s.lifecycle === 'finished';
|
|
148
|
+
const dot = statusToDot(s.status, s.is_running === 1, s.has_unreviewed === 1, s.lifecycle);
|
|
149
|
+
const ri = runtimeIcon(s.runtime_type);
|
|
150
|
+
return (
|
|
151
|
+
<div
|
|
152
|
+
key={s.id}
|
|
153
|
+
className={`tree-item ${isActive ? 'active' : ''} ${isFinished ? 'tree-item-finished' : ''}`}
|
|
154
|
+
onClick={() => selectSession(s.id)}
|
|
155
|
+
onContextMenu={(e) => {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
setCtxMenu({ x: e.clientX, y: e.clientY, type: 'session', sessionId: s.id, sessionTitle: s.title, sessionLifecycle: s.lifecycle });
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
<RuntimeIcon iconClass={ri.iconClass} iconText={ri.iconText} size={16} />
|
|
161
|
+
{renamingId === s.id ? (
|
|
162
|
+
<input
|
|
163
|
+
ref={renameRef}
|
|
164
|
+
className="tree-rename-input"
|
|
165
|
+
value={renameValue}
|
|
166
|
+
onChange={(e) => setRenameValue(e.target.value)}
|
|
167
|
+
onClick={(e) => e.stopPropagation()}
|
|
168
|
+
onKeyDown={(e) => {
|
|
169
|
+
if (e.key === 'Enter') confirmRename();
|
|
170
|
+
if (e.key === 'Escape') cancelRename();
|
|
171
|
+
}}
|
|
172
|
+
onBlur={confirmRename}
|
|
173
|
+
/>
|
|
174
|
+
) : (
|
|
175
|
+
<span className="tree-label">{s.title || s.id.slice(0, 8)}</span>
|
|
176
|
+
)}
|
|
177
|
+
{dot && <StatusDot status={dot} />}
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div className="ide-sidebar">
|
|
184
|
+
<div className="sidebar-header">
|
|
185
|
+
<span className="sidebar-header-title">Workspaces</span>
|
|
186
|
+
<button className="sidebar-add" title="Add workspace" onClick={() => pickAndAddWorkspace()}>
|
|
187
|
+
<Plus size={14} />
|
|
188
|
+
</button>
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
{groups.length === 0 ? (
|
|
192
|
+
<div className="empty-state" style={{ padding: '16px' }}>
|
|
193
|
+
No workspaces yet. Click + to add one.
|
|
194
|
+
</div>
|
|
195
|
+
) : (
|
|
196
|
+
groups.map((group) => {
|
|
197
|
+
const isCollapsed = collapsed.has(group.path);
|
|
198
|
+
const workingSessions = group.sessions.filter((s) => s.lifecycle !== 'finished');
|
|
199
|
+
const finishedSessions = group.sessions.filter((s) => s.lifecycle === 'finished');
|
|
200
|
+
const finishedKey = `${group.path}:finished`;
|
|
201
|
+
const finishedCollapsed = subCollapsed.has(finishedKey);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div key={group.path} className={`tree-section ${isCollapsed ? 'collapsed' : ''}`}>
|
|
205
|
+
<div
|
|
206
|
+
className="tree-section-header"
|
|
207
|
+
onClick={() => toggleSection(group.path)}
|
|
208
|
+
onContextMenu={(e) => {
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
setCtxMenu({ x: e.clientX, y: e.clientY, type: 'workspace', path: group.path });
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
<ChevronDown size={9} className="tree-chevron" />
|
|
214
|
+
<Folder size={14} />
|
|
215
|
+
<span className="tree-section-label">{group.label}</span>
|
|
216
|
+
<button
|
|
217
|
+
className="tree-section-add"
|
|
218
|
+
title="New session in this workspace"
|
|
219
|
+
onClick={(e) => {
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
createSessionInWorkspace(group.path);
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
<Plus size={11} />
|
|
225
|
+
</button>
|
|
226
|
+
<span className="tree-count">{group.sessions.length}</span>
|
|
227
|
+
</div>
|
|
228
|
+
<div className="tree-children">
|
|
229
|
+
{/* Working sessions — rendered directly, no sub-group header */}
|
|
230
|
+
{workingSessions.length === 0 && finishedSessions.length === 0 ? (
|
|
231
|
+
<div className="tree-empty">No sessions</div>
|
|
232
|
+
) : (
|
|
233
|
+
workingSessions.map(renderSession)
|
|
234
|
+
)}
|
|
235
|
+
|
|
236
|
+
{/* Finished sub-group — only show if there are finished sessions */}
|
|
237
|
+
{finishedSessions.length > 0 && (
|
|
238
|
+
<div className={`tree-subgroup ${finishedCollapsed ? 'collapsed' : ''}`}>
|
|
239
|
+
<div className="tree-subgroup-header" onClick={() => toggleSubGroup(finishedKey)}>
|
|
240
|
+
<ChevronDown size={8} className="tree-chevron" />
|
|
241
|
+
<span className="tree-subgroup-label">Finished</span>
|
|
242
|
+
<span className="tree-subgroup-count">{finishedSessions.length}</span>
|
|
243
|
+
</div>
|
|
244
|
+
{!finishedCollapsed && (
|
|
245
|
+
<div className="tree-subgroup-items">
|
|
246
|
+
{finishedSessions.map(renderSession)}
|
|
247
|
+
</div>
|
|
248
|
+
)}
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
})
|
|
255
|
+
)}
|
|
256
|
+
|
|
257
|
+
<div className="sidebar-footer" onClick={() => pickAndAddWorkspace()}>
|
|
258
|
+
<FolderPlus size={14} />
|
|
259
|
+
<span>Add workspace</span>
|
|
260
|
+
</div>
|
|
261
|
+
|
|
262
|
+
{ctxMenu && (
|
|
263
|
+
<div
|
|
264
|
+
ref={ctxRef}
|
|
265
|
+
className="ctx-menu"
|
|
266
|
+
style={{ position: 'fixed', left: ctxMenu.x, top: ctxMenu.y, zIndex: 500 }}
|
|
267
|
+
>
|
|
268
|
+
{ctxMenu.type === 'workspace' && (
|
|
269
|
+
<>
|
|
270
|
+
<div
|
|
271
|
+
className="ctx-menu-item"
|
|
272
|
+
onClick={() => {
|
|
273
|
+
createSessionInWorkspace(ctxMenu.path!);
|
|
274
|
+
setCtxMenu(null);
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
<Plus size={12} /> New Session
|
|
278
|
+
</div>
|
|
279
|
+
<div
|
|
280
|
+
className="ctx-menu-item ctx-danger"
|
|
281
|
+
onClick={() => {
|
|
282
|
+
removeWorkspace(ctxMenu.path!);
|
|
283
|
+
setCtxMenu(null);
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
<Trash2 size={12} /> Hide Workspace
|
|
287
|
+
</div>
|
|
288
|
+
</>
|
|
289
|
+
)}
|
|
290
|
+
{ctxMenu.type === 'session' && (
|
|
291
|
+
<>
|
|
292
|
+
{ctxMenu.sessionLifecycle !== 'finished' ? (
|
|
293
|
+
<>
|
|
294
|
+
<div
|
|
295
|
+
className="ctx-menu-item"
|
|
296
|
+
onClick={() => {
|
|
297
|
+
startRename(ctxMenu.sessionId!, ctxMenu.sessionTitle ?? '');
|
|
298
|
+
setCtxMenu(null);
|
|
299
|
+
}}
|
|
300
|
+
>
|
|
301
|
+
<Edit3 size={12} /> Rename
|
|
302
|
+
</div>
|
|
303
|
+
<div
|
|
304
|
+
className="ctx-menu-item"
|
|
305
|
+
onClick={() => {
|
|
306
|
+
markFinished(ctxMenu.sessionId!);
|
|
307
|
+
setCtxMenu(null);
|
|
308
|
+
}}
|
|
309
|
+
>
|
|
310
|
+
<CheckCircle2 size={12} /> Mark as Finished
|
|
311
|
+
</div>
|
|
312
|
+
<div
|
|
313
|
+
className="ctx-menu-item ctx-danger"
|
|
314
|
+
onClick={() => {
|
|
315
|
+
deleteSession(ctxMenu.sessionId!);
|
|
316
|
+
setCtxMenu(null);
|
|
317
|
+
}}
|
|
318
|
+
>
|
|
319
|
+
<Trash2 size={12} /> Delete Session
|
|
320
|
+
</div>
|
|
321
|
+
</>
|
|
322
|
+
) : (
|
|
323
|
+
<>
|
|
324
|
+
<div
|
|
325
|
+
className="ctx-menu-item"
|
|
326
|
+
onClick={() => {
|
|
327
|
+
reopenSession(ctxMenu.sessionId!);
|
|
328
|
+
setCtxMenu(null);
|
|
329
|
+
}}
|
|
330
|
+
>
|
|
331
|
+
<RotateCcw size={12} /> Reopen
|
|
332
|
+
</div>
|
|
333
|
+
<div
|
|
334
|
+
className="ctx-menu-item ctx-danger"
|
|
335
|
+
onClick={() => {
|
|
336
|
+
deleteSession(ctxMenu.sessionId!);
|
|
337
|
+
setCtxMenu(null);
|
|
338
|
+
}}
|
|
339
|
+
>
|
|
340
|
+
<Trash2 size={12} /> Delete Session
|
|
341
|
+
</div>
|
|
342
|
+
</>
|
|
343
|
+
)}
|
|
344
|
+
</>
|
|
345
|
+
)}
|
|
346
|
+
</div>
|
|
347
|
+
)}
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|