agentgui 1.0.274 → 1.0.275
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/CLAUDE.md +280 -280
- package/IPFS_DOWNLOADER.md +277 -277
- package/TASK_2C_COMPLETION.md +334 -334
- package/bin/gmgui.cjs +54 -54
- package/build-portable.js +3 -42
- package/database.js +1422 -1406
- package/lib/claude-runner.js +1130 -1130
- package/lib/ipfs-downloader.js +459 -459
- package/lib/speech.js +152 -152
- package/package.json +1 -1
- package/readme.md +76 -76
- package/server.js +3787 -3794
- package/setup-npm-token.sh +68 -68
- package/static/app.js +773 -773
- package/static/event-rendering-showcase.html +708 -708
- package/static/index.html +3178 -3180
- package/static/js/agent-auth.js +298 -298
- package/static/js/audio-recorder-processor.js +18 -18
- package/static/js/client.js +2656 -2656
- package/static/js/conversations.js +583 -583
- package/static/js/dialogs.js +267 -267
- package/static/js/event-consolidator.js +101 -101
- package/static/js/event-filter.js +311 -311
- package/static/js/event-processor.js +452 -452
- package/static/js/features.js +413 -413
- package/static/js/kalman-filter.js +67 -67
- package/static/js/progress-dialog.js +130 -130
- package/static/js/script-runner.js +219 -219
- package/static/js/streaming-renderer.js +2123 -2120
- package/static/js/syntax-highlighter.js +269 -269
- package/static/js/tts-websocket-handler.js +152 -152
- package/static/js/ui-components.js +431 -431
- package/static/js/voice.js +849 -849
- package/static/js/websocket-manager.js +596 -596
- package/static/templates/INDEX.html +465 -465
- package/static/templates/README.md +190 -190
- package/static/templates/agent-capabilities.html +56 -56
- package/static/templates/agent-metadata-panel.html +44 -44
- package/static/templates/agent-status-badge.html +30 -30
- package/static/templates/code-annotation-panel.html +155 -155
- package/static/templates/code-suggestion-panel.html +184 -184
- package/static/templates/command-header.html +77 -77
- package/static/templates/command-output-scrollable.html +118 -118
- package/static/templates/elapsed-time.html +54 -54
- package/static/templates/error-alert.html +106 -106
- package/static/templates/error-history-timeline.html +160 -160
- package/static/templates/error-recovery-options.html +109 -109
- package/static/templates/error-stack-trace.html +95 -95
- package/static/templates/error-summary.html +80 -80
- package/static/templates/event-counter.html +48 -48
- package/static/templates/execution-actions.html +97 -97
- package/static/templates/execution-progress-bar.html +80 -80
- package/static/templates/execution-stepper.html +120 -120
- package/static/templates/file-breadcrumb.html +118 -118
- package/static/templates/file-diff-viewer.html +121 -121
- package/static/templates/file-metadata.html +133 -133
- package/static/templates/file-read-panel.html +66 -66
- package/static/templates/file-write-panel.html +120 -120
- package/static/templates/git-branch-remote.html +107 -107
- package/static/templates/git-diff-list.html +101 -101
- package/static/templates/git-log-visualization.html +153 -153
- package/static/templates/git-status-panel.html +115 -115
- package/static/templates/quality-metrics-display.html +170 -170
- package/static/templates/terminal-output-panel.html +87 -87
- package/static/templates/test-results-display.html +144 -144
- package/static/theme.js +72 -72
- package/test-download-progress.js +223 -223
- package/test-websocket-broadcast.js +147 -147
- package/tests/ipfs-downloader.test.js +370 -370
|
@@ -1,583 +1,583 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversations Module
|
|
3
|
-
* Manages conversation list sidebar with real-time updates
|
|
4
|
-
* Includes folder browser for selecting working directory on new conversation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function pathSplit(p) {
|
|
8
|
-
return p.split(/[\/\\]/).filter(Boolean);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function pathBasename(p) {
|
|
12
|
-
const parts = pathSplit(p);
|
|
13
|
-
return parts.length ? parts.pop() : '';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class ConversationManager {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.conversations = [];
|
|
19
|
-
this.activeId = null;
|
|
20
|
-
this.listEl = document.querySelector('[data-conversation-list]');
|
|
21
|
-
this.emptyEl = document.querySelector('[data-conversation-empty]');
|
|
22
|
-
this.newBtn = document.querySelector('[data-new-conversation]');
|
|
23
|
-
this.sidebarEl = document.querySelector('[data-sidebar]');
|
|
24
|
-
this.streamingConversations = new Set();
|
|
25
|
-
this.agents = new Map();
|
|
26
|
-
|
|
27
|
-
this.folderBrowser = {
|
|
28
|
-
modal: null,
|
|
29
|
-
listEl: null,
|
|
30
|
-
breadcrumbEl: null,
|
|
31
|
-
currentPath: '~',
|
|
32
|
-
homePath: '~',
|
|
33
|
-
cwdPath: null,
|
|
34
|
-
homePathReady: null
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (!this.listEl) return;
|
|
38
|
-
|
|
39
|
-
this.init();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async init() {
|
|
43
|
-
this.newBtn?.addEventListener('click', () => this.openFolderBrowser());
|
|
44
|
-
this.setupDelegatedListeners();
|
|
45
|
-
await this.loadAgents();
|
|
46
|
-
this.loadConversations();
|
|
47
|
-
this.setupWebSocketListener();
|
|
48
|
-
this.setupFolderBrowser();
|
|
49
|
-
this.setupCloneUI();
|
|
50
|
-
|
|
51
|
-
this._pollInterval = setInterval(() => this.loadConversations(), 30000);
|
|
52
|
-
|
|
53
|
-
window.addEventListener('beforeunload', () => this.destroy());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
destroy() {
|
|
57
|
-
if (this._pollInterval) {
|
|
58
|
-
clearInterval(this._pollInterval);
|
|
59
|
-
this._pollInterval = null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async loadAgents() {
|
|
64
|
-
try {
|
|
65
|
-
const res = await fetch((window.__BASE_URL || '') + '/api/agents');
|
|
66
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
67
|
-
const data = await res.json();
|
|
68
|
-
for (const agent of data.agents || []) {
|
|
69
|
-
this.agents.set(agent.id, agent);
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.error('[ConversationManager] Error loading agents:', err);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getAgentDisplayName(agentId) {
|
|
77
|
-
if (!agentId) return 'Unknown';
|
|
78
|
-
const agent = this.agents.get(agentId);
|
|
79
|
-
return agent?.name || agentId;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
setupDelegatedListeners() {
|
|
83
|
-
this.listEl.addEventListener('click', (e) => {
|
|
84
|
-
const deleteBtn = e.target.closest('[data-delete-conv]');
|
|
85
|
-
if (deleteBtn) {
|
|
86
|
-
e.stopPropagation();
|
|
87
|
-
const convId = deleteBtn.dataset.deleteConv;
|
|
88
|
-
const conv = this.conversations.find(c => c.id === convId);
|
|
89
|
-
this.confirmDelete(convId, conv?.title || 'Untitled');
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const item = e.target.closest('[data-conv-id]');
|
|
93
|
-
if (item) {
|
|
94
|
-
this.select(item.dataset.convId);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
setupFolderBrowser() {
|
|
100
|
-
this.folderBrowser.modal = document.getElementById('folderBrowserModal');
|
|
101
|
-
this.folderBrowser.listEl = document.getElementById('folderList');
|
|
102
|
-
this.folderBrowser.breadcrumbEl = document.getElementById('folderBreadcrumb');
|
|
103
|
-
|
|
104
|
-
if (!this.folderBrowser.modal) return;
|
|
105
|
-
|
|
106
|
-
const closeBtn = this.folderBrowser.modal.querySelector('[data-folder-close]');
|
|
107
|
-
const cancelBtn = this.folderBrowser.modal.querySelector('[data-folder-cancel]');
|
|
108
|
-
const selectBtn = this.folderBrowser.modal.querySelector('[data-folder-select]');
|
|
109
|
-
|
|
110
|
-
closeBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
111
|
-
cancelBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
112
|
-
selectBtn?.addEventListener('click', () => this.confirmFolderSelection());
|
|
113
|
-
|
|
114
|
-
this.folderBrowser.modal.addEventListener('click', (e) => {
|
|
115
|
-
if (e.target === this.folderBrowser.modal) this.closeFolderBrowser();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
this.folderBrowser.homePathReady = this.fetchHomePath();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async fetchHomePath() {
|
|
122
|
-
try {
|
|
123
|
-
const res = await fetch((window.__BASE_URL || '') + '/api/home');
|
|
124
|
-
if (res.ok) {
|
|
125
|
-
const data = await res.json();
|
|
126
|
-
this.folderBrowser.homePath = data.home || '~';
|
|
127
|
-
this.folderBrowser.cwdPath = data.cwd || null;
|
|
128
|
-
}
|
|
129
|
-
} catch (e) {
|
|
130
|
-
console.error('Failed to fetch home path:', e);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async openFolderBrowser() {
|
|
135
|
-
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
136
|
-
if (!this.folderBrowser.modal) {
|
|
137
|
-
this.createNew();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (this.folderBrowser.homePathReady) {
|
|
141
|
-
await this.folderBrowser.homePathReady;
|
|
142
|
-
}
|
|
143
|
-
const startPath = this.folderBrowser.cwdPath || '~';
|
|
144
|
-
this.folderBrowser.currentPath = startPath;
|
|
145
|
-
this.folderBrowser.modal.classList.add('visible');
|
|
146
|
-
this.loadFolders(startPath);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
closeFolderBrowser() {
|
|
150
|
-
this.folderBrowser.modal?.classList.remove('visible');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async loadFolders(dirPath) {
|
|
154
|
-
this.folderBrowser.currentPath = dirPath;
|
|
155
|
-
this.renderBreadcrumb(dirPath);
|
|
156
|
-
|
|
157
|
-
if (!this.folderBrowser.listEl) return;
|
|
158
|
-
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-loading">Loading...</li>';
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
const res = await fetch((window.__BASE_URL || '') + '/api/folders', {
|
|
162
|
-
method: 'POST',
|
|
163
|
-
headers: { 'Content-Type': 'application/json' },
|
|
164
|
-
body: JSON.stringify({ path: dirPath })
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
if (!res.ok) {
|
|
168
|
-
const errData = await res.json().catch(() => ({}));
|
|
169
|
-
throw new Error(errData.error || `HTTP ${res.status}`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const data = await res.json();
|
|
173
|
-
const folders = data.folders || [];
|
|
174
|
-
|
|
175
|
-
this.folderBrowser.listEl.innerHTML = '';
|
|
176
|
-
|
|
177
|
-
if (dirPath !== '~' && dirPath !== '/' && dirPath !== this.folderBrowser.homePath) {
|
|
178
|
-
const parentPath = this.getParentPath(dirPath);
|
|
179
|
-
const upItem = document.createElement('li');
|
|
180
|
-
upItem.className = 'folder-list-item';
|
|
181
|
-
upItem.innerHTML = '<span class="folder-list-item-icon">..</span><span class="folder-list-item-name">Parent Directory</span>';
|
|
182
|
-
upItem.addEventListener('click', () => this.loadFolders(parentPath));
|
|
183
|
-
this.folderBrowser.listEl.appendChild(upItem);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (folders.length === 0 && this.folderBrowser.listEl.children.length === 0) {
|
|
187
|
-
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-empty">No subdirectories</li>';
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
for (const folder of folders) {
|
|
192
|
-
const li = document.createElement('li');
|
|
193
|
-
li.className = 'folder-list-item';
|
|
194
|
-
li.innerHTML = `<span class="folder-list-item-icon">📁</span><span class="folder-list-item-name">${this.escapeHtml(folder.name)}</span>`;
|
|
195
|
-
li.addEventListener('click', () => {
|
|
196
|
-
const expandedBase = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
197
|
-
const separator = expandedBase.includes('\\') ? '\\' : '/';
|
|
198
|
-
const newPath = expandedBase + separator + folder.name;
|
|
199
|
-
this.loadFolders(newPath);
|
|
200
|
-
});
|
|
201
|
-
this.folderBrowser.listEl.appendChild(li);
|
|
202
|
-
}
|
|
203
|
-
} catch (err) {
|
|
204
|
-
console.error('Failed to load folders:', err);
|
|
205
|
-
this.folderBrowser.listEl.innerHTML = `<li class="folder-list-error">Error: ${this.escapeHtml(err.message)}</li>`;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
getParentPath(dirPath) {
|
|
210
|
-
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
211
|
-
const parts = pathSplit(expanded);
|
|
212
|
-
if (parts.length <= 1) {
|
|
213
|
-
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
214
|
-
return separator;
|
|
215
|
-
}
|
|
216
|
-
parts.pop();
|
|
217
|
-
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
218
|
-
return separator + parts.join(separator);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
renderBreadcrumb(dirPath) {
|
|
222
|
-
if (!this.folderBrowser.breadcrumbEl) return;
|
|
223
|
-
|
|
224
|
-
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
225
|
-
const parts = pathSplit(expanded);
|
|
226
|
-
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
227
|
-
|
|
228
|
-
let html = '';
|
|
229
|
-
html += `<span class="folder-breadcrumb-segment" data-path="${separator}">${separator} </span>`;
|
|
230
|
-
|
|
231
|
-
let accumulated = '';
|
|
232
|
-
for (let i = 0; i < parts.length; i++) {
|
|
233
|
-
accumulated += separator + parts[i];
|
|
234
|
-
const isLast = i === parts.length - 1;
|
|
235
|
-
html += `<span class="folder-breadcrumb-separator">${separator}</span>`;
|
|
236
|
-
html += `<span class="folder-breadcrumb-segment${isLast ? '' : ''}" data-path="${this.escapeHtml(accumulated)}">${this.escapeHtml(parts[i])}</span>`;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
this.folderBrowser.breadcrumbEl.innerHTML = html;
|
|
240
|
-
|
|
241
|
-
this.folderBrowser.breadcrumbEl.querySelectorAll('.folder-breadcrumb-segment').forEach(seg => {
|
|
242
|
-
seg.addEventListener('click', () => {
|
|
243
|
-
const p = seg.dataset.path;
|
|
244
|
-
if (p) this.loadFolders(p);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
confirmFolderSelection() {
|
|
250
|
-
const currentPath = this.folderBrowser.currentPath;
|
|
251
|
-
const expanded = currentPath === '~' ? this.folderBrowser.homePath : currentPath;
|
|
252
|
-
this.closeFolderBrowser();
|
|
253
|
-
|
|
254
|
-
const dirName = pathBasename(expanded) || 'root';
|
|
255
|
-
window.dispatchEvent(new CustomEvent('create-new-conversation', {
|
|
256
|
-
detail: { workingDirectory: expanded, title: dirName }
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
setupCloneUI() {
|
|
261
|
-
this.cloneBtn = document.getElementById('cloneRepoBtn');
|
|
262
|
-
this.cloneBar = document.getElementById('cloneInputBar');
|
|
263
|
-
this.cloneInput = document.getElementById('cloneRepoInput');
|
|
264
|
-
this.cloneGoBtn = document.getElementById('cloneGoBtn');
|
|
265
|
-
this.cloneCancelBtn = document.getElementById('cloneCancelBtn');
|
|
266
|
-
|
|
267
|
-
if (!this.cloneBtn || !this.cloneBar) return;
|
|
268
|
-
|
|
269
|
-
this.cloneBtn.addEventListener('click', () => this.toggleCloneBar());
|
|
270
|
-
|
|
271
|
-
this.cloneCancelBtn?.addEventListener('click', () => this.hideCloneBar());
|
|
272
|
-
|
|
273
|
-
this.cloneGoBtn?.addEventListener('click', () => this.performClone());
|
|
274
|
-
|
|
275
|
-
this.cloneInput?.addEventListener('keydown', (e) => {
|
|
276
|
-
if (e.key === 'Enter') this.performClone();
|
|
277
|
-
if (e.key === 'Escape') this.hideCloneBar();
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
toggleCloneBar() {
|
|
282
|
-
if (!this.cloneBar) return;
|
|
283
|
-
const visible = this.cloneBar.style.display !== 'none';
|
|
284
|
-
if (visible) {
|
|
285
|
-
this.hideCloneBar();
|
|
286
|
-
} else {
|
|
287
|
-
this.cloneBar.style.display = 'flex';
|
|
288
|
-
this.cloneInput.value = '';
|
|
289
|
-
this.cloneInput.focus();
|
|
290
|
-
this.removeCloneStatus();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
hideCloneBar() {
|
|
295
|
-
if (this.cloneBar) this.cloneBar.style.display = 'none';
|
|
296
|
-
this.removeCloneStatus();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
removeCloneStatus() {
|
|
300
|
-
const existing = this.sidebarEl?.querySelector('.clone-status');
|
|
301
|
-
if (existing) existing.remove();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
showCloneStatus(message, type) {
|
|
305
|
-
this.removeCloneStatus();
|
|
306
|
-
const statusEl = document.createElement('div');
|
|
307
|
-
statusEl.className = `clone-status ${type}`;
|
|
308
|
-
statusEl.textContent = message;
|
|
309
|
-
if (this.cloneBar && this.cloneBar.parentNode) {
|
|
310
|
-
this.cloneBar.parentNode.insertBefore(statusEl, this.cloneBar.nextSibling);
|
|
311
|
-
}
|
|
312
|
-
if (type === 'clone-success' || type === 'clone-error') {
|
|
313
|
-
setTimeout(() => statusEl.remove(), 5000);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
async performClone() {
|
|
318
|
-
const repo = (this.cloneInput?.value || '').trim();
|
|
319
|
-
if (!repo) return;
|
|
320
|
-
if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(repo)) {
|
|
321
|
-
this.showCloneStatus('Invalid format. Use org/repo', 'clone-error');
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this.cloneGoBtn.disabled = true;
|
|
326
|
-
this.cloneInput.disabled = true;
|
|
327
|
-
this.showCloneStatus(`Cloning ${repo}...`, 'cloning');
|
|
328
|
-
|
|
329
|
-
try {
|
|
330
|
-
const res = await fetch((window.__BASE_URL || '') + '/api/clone', {
|
|
331
|
-
method: 'POST',
|
|
332
|
-
headers: { 'Content-Type': 'application/json' },
|
|
333
|
-
body: JSON.stringify({ repo })
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
const data = await res.json();
|
|
337
|
-
|
|
338
|
-
if (!res.ok) {
|
|
339
|
-
this.showCloneStatus(data.error || 'Clone failed', 'clone-error');
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
this.showCloneStatus(`Cloned ${data.name}`, 'clone-success');
|
|
344
|
-
this.hideCloneBar();
|
|
345
|
-
|
|
346
|
-
window.dispatchEvent(new CustomEvent('create-new-conversation', {
|
|
347
|
-
detail: { workingDirectory: data.path, title: data.name }
|
|
348
|
-
}));
|
|
349
|
-
} catch (err) {
|
|
350
|
-
this.showCloneStatus('Network error: ' + err.message, 'clone-error');
|
|
351
|
-
} finally {
|
|
352
|
-
if (this.cloneGoBtn) this.cloneGoBtn.disabled = false;
|
|
353
|
-
if (this.cloneInput) this.cloneInput.disabled = false;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async loadConversations() {
|
|
358
|
-
try {
|
|
359
|
-
const res = await fetch((window.__BASE_URL || '') + '/api/conversations');
|
|
360
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
361
|
-
|
|
362
|
-
const data = await res.json();
|
|
363
|
-
this.conversations = data.conversations || [];
|
|
364
|
-
|
|
365
|
-
for (const conv of this.conversations) {
|
|
366
|
-
if (conv.isStreaming === 1 || conv.isStreaming === true) {
|
|
367
|
-
this.streamingConversations.add(conv.id);
|
|
368
|
-
} else {
|
|
369
|
-
this.streamingConversations.delete(conv.id);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
this.render();
|
|
374
|
-
} catch (err) {
|
|
375
|
-
console.error('Failed to load conversations:', err);
|
|
376
|
-
this.showEmpty('Failed to load conversations');
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
render() {
|
|
381
|
-
if (!this.listEl) return;
|
|
382
|
-
|
|
383
|
-
if (this.conversations.length === 0) {
|
|
384
|
-
this.showEmpty();
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
this.emptyEl.style.display = 'none';
|
|
389
|
-
|
|
390
|
-
const sorted = [...this.conversations].sort((a, b) =>
|
|
391
|
-
new Date(b.createdAt || 0) - new Date(a.createdAt || 0)
|
|
392
|
-
);
|
|
393
|
-
|
|
394
|
-
const existingMap = {};
|
|
395
|
-
for (const child of Array.from(this.listEl.children)) {
|
|
396
|
-
const cid = child.dataset.convId;
|
|
397
|
-
if (cid) existingMap[cid] = child;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const frag = document.createDocumentFragment();
|
|
401
|
-
for (const conv of sorted) {
|
|
402
|
-
const existing = existingMap[conv.id];
|
|
403
|
-
if (existing) {
|
|
404
|
-
this.updateConversationItem(existing, conv);
|
|
405
|
-
delete existingMap[conv.id];
|
|
406
|
-
frag.appendChild(existing);
|
|
407
|
-
} else {
|
|
408
|
-
frag.appendChild(this.createConversationItem(conv));
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
for (const orphan of Object.values(existingMap)) orphan.remove();
|
|
413
|
-
this.listEl.appendChild(frag);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
updateConversationItem(el, conv) {
|
|
417
|
-
const isActive = conv.id === this.activeId;
|
|
418
|
-
el.classList.toggle('active', isActive);
|
|
419
|
-
|
|
420
|
-
const isStreaming = this.streamingConversations.has(conv.id);
|
|
421
|
-
const title = conv.title || `Conversation ${conv.id.slice(0, 8)}`;
|
|
422
|
-
const timestamp = conv.created_at ? new Date(conv.created_at).toLocaleDateString() : 'Unknown';
|
|
423
|
-
const agent = this.getAgentDisplayName(conv.agentType);
|
|
424
|
-
const modelLabel = conv.model ? ` (${conv.model})` : '';
|
|
425
|
-
const wd = conv.workingDirectory ? pathBasename(conv.workingDirectory) : '';
|
|
426
|
-
const metaParts = [agent + modelLabel, timestamp];
|
|
427
|
-
if (wd) metaParts.push(wd);
|
|
428
|
-
|
|
429
|
-
const titleEl = el.querySelector('.conversation-item-title');
|
|
430
|
-
if (titleEl) {
|
|
431
|
-
const badgeHtml = isStreaming
|
|
432
|
-
? '<span class="conversation-streaming-badge" title="Streaming in progress"><span class="streaming-dot"></span></span>'
|
|
433
|
-
: '';
|
|
434
|
-
titleEl.innerHTML = `${badgeHtml}${this.escapeHtml(title)}`;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
const metaEl = el.querySelector('.conversation-item-meta');
|
|
438
|
-
if (metaEl) metaEl.textContent = metaParts.join(' \u2022 ');
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
createConversationItem(conv) {
|
|
442
|
-
const li = document.createElement('li');
|
|
443
|
-
li.className = 'conversation-item';
|
|
444
|
-
li.dataset.convId = conv.id;
|
|
445
|
-
if (conv.id === this.activeId) li.classList.add('active');
|
|
446
|
-
|
|
447
|
-
const isStreaming = this.streamingConversations.has(conv.id);
|
|
448
|
-
|
|
449
|
-
const title = conv.title || `Conversation ${conv.id.slice(0, 8)}`;
|
|
450
|
-
const timestamp = conv.created_at ? new Date(conv.created_at).toLocaleDateString() : 'Unknown';
|
|
451
|
-
const agent = this.getAgentDisplayName(conv.agentType);
|
|
452
|
-
const modelLabel = conv.model ? ` (${conv.model})` : '';
|
|
453
|
-
const wd = conv.workingDirectory ? conv.workingDirectory.split('/').pop() : '';
|
|
454
|
-
const metaParts = [agent + modelLabel, timestamp];
|
|
455
|
-
if (wd) metaParts.push(wd);
|
|
456
|
-
|
|
457
|
-
const streamingBadge = isStreaming
|
|
458
|
-
? '<span class="conversation-streaming-badge" title="Streaming in progress"><span class="streaming-dot"></span></span>'
|
|
459
|
-
: '';
|
|
460
|
-
|
|
461
|
-
li.innerHTML = `
|
|
462
|
-
<div class="conversation-item-content">
|
|
463
|
-
<div class="conversation-item-title">${streamingBadge}${this.escapeHtml(title)}</div>
|
|
464
|
-
<div class="conversation-item-meta">${metaParts.join(' • ')}</div>
|
|
465
|
-
</div>
|
|
466
|
-
<button class="conversation-item-delete" title="Delete conversation" data-delete-conv="${conv.id}">
|
|
467
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
468
|
-
<polyline points="3 6 5 6 21 6"></polyline>
|
|
469
|
-
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
|
470
|
-
</svg>
|
|
471
|
-
</button>
|
|
472
|
-
`;
|
|
473
|
-
|
|
474
|
-
return li;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
async confirmDelete(convId, title) {
|
|
478
|
-
const confirmed = await window.UIDialog.confirm(
|
|
479
|
-
`Delete conversation "${title || 'Untitled'}"?\n\nThis will also delete any associated Claude Code session data. This action cannot be undone.`,
|
|
480
|
-
'Delete Conversation'
|
|
481
|
-
);
|
|
482
|
-
if (!confirmed) return;
|
|
483
|
-
|
|
484
|
-
try {
|
|
485
|
-
const res = await fetch((window.__BASE_URL || '') + `/api/conversations/${convId}`, {
|
|
486
|
-
method: 'DELETE',
|
|
487
|
-
headers: { 'Content-Type': 'application/json' }
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
if (res.ok) {
|
|
491
|
-
console.log(`[ConversationManager] Deleted conversation ${convId}`);
|
|
492
|
-
this.deleteConversation(convId);
|
|
493
|
-
} else {
|
|
494
|
-
const error = await res.json().catch(() => ({ error: 'Failed to delete' }));
|
|
495
|
-
window.UIDialog.alert('Failed to delete conversation: ' + (error.error || 'Unknown error'), 'Error');
|
|
496
|
-
}
|
|
497
|
-
} catch (err) {
|
|
498
|
-
console.error('[ConversationManager] Delete error:', err);
|
|
499
|
-
window.UIDialog.alert('Failed to delete conversation: ' + err.message, 'Error');
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
select(convId) {
|
|
504
|
-
this.activeId = convId;
|
|
505
|
-
|
|
506
|
-
document.querySelectorAll('.conversation-item').forEach(item => {
|
|
507
|
-
item.classList.remove('active');
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
const active = document.querySelector(`[data-conv-id="${convId}"]`);
|
|
511
|
-
if (active) active.classList.add('active');
|
|
512
|
-
|
|
513
|
-
window.dispatchEvent(new CustomEvent('conversation-selected', {
|
|
514
|
-
detail: { conversationId: convId }
|
|
515
|
-
}));
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
createNew() {
|
|
519
|
-
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
520
|
-
window.dispatchEvent(new CustomEvent('create-new-conversation'));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
showEmpty(message = 'No conversations yet') {
|
|
524
|
-
if (!this.listEl) return;
|
|
525
|
-
this.listEl.innerHTML = '';
|
|
526
|
-
this.emptyEl.textContent = message;
|
|
527
|
-
this.emptyEl.style.display = 'block';
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
addConversation(conv) {
|
|
531
|
-
if (this.conversations.some(c => c.id === conv.id)) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
this.conversations.unshift(conv);
|
|
535
|
-
this.render();
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
updateConversation(convId, updates) {
|
|
539
|
-
const conv = this.conversations.find(c => c.id === convId);
|
|
540
|
-
if (conv) {
|
|
541
|
-
Object.assign(conv, updates);
|
|
542
|
-
this.render();
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
deleteConversation(convId) {
|
|
547
|
-
this.conversations = this.conversations.filter(c => c.id !== convId);
|
|
548
|
-
if (this.activeId === convId) this.activeId = null;
|
|
549
|
-
this.render();
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
setupWebSocketListener() {
|
|
553
|
-
window.addEventListener('ws-message', (event) => {
|
|
554
|
-
const msg = event.detail;
|
|
555
|
-
|
|
556
|
-
if (msg.type === 'conversation_created') {
|
|
557
|
-
this.addConversation(msg.conversation);
|
|
558
|
-
} else if (msg.type === 'conversation_updated') {
|
|
559
|
-
this.updateConversation(msg.conversation.id, msg.conversation);
|
|
560
|
-
} else if (msg.type === 'conversation_deleted') {
|
|
561
|
-
this.deleteConversation(msg.conversationId);
|
|
562
|
-
} else if (msg.type === 'streaming_start' && msg.conversationId) {
|
|
563
|
-
this.streamingConversations.add(msg.conversationId);
|
|
564
|
-
this.render();
|
|
565
|
-
} else if ((msg.type === 'streaming_complete' || msg.type === 'streaming_error') && msg.conversationId) {
|
|
566
|
-
this.streamingConversations.delete(msg.conversationId);
|
|
567
|
-
this.render();
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
escapeHtml(text) {
|
|
573
|
-
return window._escHtml(text);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (document.readyState === 'loading') {
|
|
578
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
579
|
-
window.conversationManager = new ConversationManager();
|
|
580
|
-
});
|
|
581
|
-
} else {
|
|
582
|
-
window.conversationManager = new ConversationManager();
|
|
583
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Conversations Module
|
|
3
|
+
* Manages conversation list sidebar with real-time updates
|
|
4
|
+
* Includes folder browser for selecting working directory on new conversation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function pathSplit(p) {
|
|
8
|
+
return p.split(/[\/\\]/).filter(Boolean);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function pathBasename(p) {
|
|
12
|
+
const parts = pathSplit(p);
|
|
13
|
+
return parts.length ? parts.pop() : '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class ConversationManager {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.conversations = [];
|
|
19
|
+
this.activeId = null;
|
|
20
|
+
this.listEl = document.querySelector('[data-conversation-list]');
|
|
21
|
+
this.emptyEl = document.querySelector('[data-conversation-empty]');
|
|
22
|
+
this.newBtn = document.querySelector('[data-new-conversation]');
|
|
23
|
+
this.sidebarEl = document.querySelector('[data-sidebar]');
|
|
24
|
+
this.streamingConversations = new Set();
|
|
25
|
+
this.agents = new Map();
|
|
26
|
+
|
|
27
|
+
this.folderBrowser = {
|
|
28
|
+
modal: null,
|
|
29
|
+
listEl: null,
|
|
30
|
+
breadcrumbEl: null,
|
|
31
|
+
currentPath: '~',
|
|
32
|
+
homePath: '~',
|
|
33
|
+
cwdPath: null,
|
|
34
|
+
homePathReady: null
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (!this.listEl) return;
|
|
38
|
+
|
|
39
|
+
this.init();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async init() {
|
|
43
|
+
this.newBtn?.addEventListener('click', () => this.openFolderBrowser());
|
|
44
|
+
this.setupDelegatedListeners();
|
|
45
|
+
await this.loadAgents();
|
|
46
|
+
this.loadConversations();
|
|
47
|
+
this.setupWebSocketListener();
|
|
48
|
+
this.setupFolderBrowser();
|
|
49
|
+
this.setupCloneUI();
|
|
50
|
+
|
|
51
|
+
this._pollInterval = setInterval(() => this.loadConversations(), 30000);
|
|
52
|
+
|
|
53
|
+
window.addEventListener('beforeunload', () => this.destroy());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
destroy() {
|
|
57
|
+
if (this._pollInterval) {
|
|
58
|
+
clearInterval(this._pollInterval);
|
|
59
|
+
this._pollInterval = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async loadAgents() {
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch((window.__BASE_URL || '') + '/api/agents');
|
|
66
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
67
|
+
const data = await res.json();
|
|
68
|
+
for (const agent of data.agents || []) {
|
|
69
|
+
this.agents.set(agent.id, agent);
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error('[ConversationManager] Error loading agents:', err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getAgentDisplayName(agentId) {
|
|
77
|
+
if (!agentId) return 'Unknown';
|
|
78
|
+
const agent = this.agents.get(agentId);
|
|
79
|
+
return agent?.name || agentId;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setupDelegatedListeners() {
|
|
83
|
+
this.listEl.addEventListener('click', (e) => {
|
|
84
|
+
const deleteBtn = e.target.closest('[data-delete-conv]');
|
|
85
|
+
if (deleteBtn) {
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
const convId = deleteBtn.dataset.deleteConv;
|
|
88
|
+
const conv = this.conversations.find(c => c.id === convId);
|
|
89
|
+
this.confirmDelete(convId, conv?.title || 'Untitled');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const item = e.target.closest('[data-conv-id]');
|
|
93
|
+
if (item) {
|
|
94
|
+
this.select(item.dataset.convId);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setupFolderBrowser() {
|
|
100
|
+
this.folderBrowser.modal = document.getElementById('folderBrowserModal');
|
|
101
|
+
this.folderBrowser.listEl = document.getElementById('folderList');
|
|
102
|
+
this.folderBrowser.breadcrumbEl = document.getElementById('folderBreadcrumb');
|
|
103
|
+
|
|
104
|
+
if (!this.folderBrowser.modal) return;
|
|
105
|
+
|
|
106
|
+
const closeBtn = this.folderBrowser.modal.querySelector('[data-folder-close]');
|
|
107
|
+
const cancelBtn = this.folderBrowser.modal.querySelector('[data-folder-cancel]');
|
|
108
|
+
const selectBtn = this.folderBrowser.modal.querySelector('[data-folder-select]');
|
|
109
|
+
|
|
110
|
+
closeBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
111
|
+
cancelBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
112
|
+
selectBtn?.addEventListener('click', () => this.confirmFolderSelection());
|
|
113
|
+
|
|
114
|
+
this.folderBrowser.modal.addEventListener('click', (e) => {
|
|
115
|
+
if (e.target === this.folderBrowser.modal) this.closeFolderBrowser();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
this.folderBrowser.homePathReady = this.fetchHomePath();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async fetchHomePath() {
|
|
122
|
+
try {
|
|
123
|
+
const res = await fetch((window.__BASE_URL || '') + '/api/home');
|
|
124
|
+
if (res.ok) {
|
|
125
|
+
const data = await res.json();
|
|
126
|
+
this.folderBrowser.homePath = data.home || '~';
|
|
127
|
+
this.folderBrowser.cwdPath = data.cwd || null;
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.error('Failed to fetch home path:', e);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async openFolderBrowser() {
|
|
135
|
+
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
136
|
+
if (!this.folderBrowser.modal) {
|
|
137
|
+
this.createNew();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (this.folderBrowser.homePathReady) {
|
|
141
|
+
await this.folderBrowser.homePathReady;
|
|
142
|
+
}
|
|
143
|
+
const startPath = this.folderBrowser.cwdPath || '~';
|
|
144
|
+
this.folderBrowser.currentPath = startPath;
|
|
145
|
+
this.folderBrowser.modal.classList.add('visible');
|
|
146
|
+
this.loadFolders(startPath);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
closeFolderBrowser() {
|
|
150
|
+
this.folderBrowser.modal?.classList.remove('visible');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async loadFolders(dirPath) {
|
|
154
|
+
this.folderBrowser.currentPath = dirPath;
|
|
155
|
+
this.renderBreadcrumb(dirPath);
|
|
156
|
+
|
|
157
|
+
if (!this.folderBrowser.listEl) return;
|
|
158
|
+
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-loading">Loading...</li>';
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const res = await fetch((window.__BASE_URL || '') + '/api/folders', {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: { 'Content-Type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({ path: dirPath })
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (!res.ok) {
|
|
168
|
+
const errData = await res.json().catch(() => ({}));
|
|
169
|
+
throw new Error(errData.error || `HTTP ${res.status}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const data = await res.json();
|
|
173
|
+
const folders = data.folders || [];
|
|
174
|
+
|
|
175
|
+
this.folderBrowser.listEl.innerHTML = '';
|
|
176
|
+
|
|
177
|
+
if (dirPath !== '~' && dirPath !== '/' && dirPath !== this.folderBrowser.homePath) {
|
|
178
|
+
const parentPath = this.getParentPath(dirPath);
|
|
179
|
+
const upItem = document.createElement('li');
|
|
180
|
+
upItem.className = 'folder-list-item';
|
|
181
|
+
upItem.innerHTML = '<span class="folder-list-item-icon">..</span><span class="folder-list-item-name">Parent Directory</span>';
|
|
182
|
+
upItem.addEventListener('click', () => this.loadFolders(parentPath));
|
|
183
|
+
this.folderBrowser.listEl.appendChild(upItem);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (folders.length === 0 && this.folderBrowser.listEl.children.length === 0) {
|
|
187
|
+
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-empty">No subdirectories</li>';
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
for (const folder of folders) {
|
|
192
|
+
const li = document.createElement('li');
|
|
193
|
+
li.className = 'folder-list-item';
|
|
194
|
+
li.innerHTML = `<span class="folder-list-item-icon">📁</span><span class="folder-list-item-name">${this.escapeHtml(folder.name)}</span>`;
|
|
195
|
+
li.addEventListener('click', () => {
|
|
196
|
+
const expandedBase = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
197
|
+
const separator = expandedBase.includes('\\') ? '\\' : '/';
|
|
198
|
+
const newPath = expandedBase + separator + folder.name;
|
|
199
|
+
this.loadFolders(newPath);
|
|
200
|
+
});
|
|
201
|
+
this.folderBrowser.listEl.appendChild(li);
|
|
202
|
+
}
|
|
203
|
+
} catch (err) {
|
|
204
|
+
console.error('Failed to load folders:', err);
|
|
205
|
+
this.folderBrowser.listEl.innerHTML = `<li class="folder-list-error">Error: ${this.escapeHtml(err.message)}</li>`;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getParentPath(dirPath) {
|
|
210
|
+
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
211
|
+
const parts = pathSplit(expanded);
|
|
212
|
+
if (parts.length <= 1) {
|
|
213
|
+
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
214
|
+
return separator;
|
|
215
|
+
}
|
|
216
|
+
parts.pop();
|
|
217
|
+
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
218
|
+
return separator + parts.join(separator);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
renderBreadcrumb(dirPath) {
|
|
222
|
+
if (!this.folderBrowser.breadcrumbEl) return;
|
|
223
|
+
|
|
224
|
+
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
225
|
+
const parts = pathSplit(expanded);
|
|
226
|
+
const separator = expanded.includes('\\') ? '\\' : '/';
|
|
227
|
+
|
|
228
|
+
let html = '';
|
|
229
|
+
html += `<span class="folder-breadcrumb-segment" data-path="${separator}">${separator} </span>`;
|
|
230
|
+
|
|
231
|
+
let accumulated = '';
|
|
232
|
+
for (let i = 0; i < parts.length; i++) {
|
|
233
|
+
accumulated += separator + parts[i];
|
|
234
|
+
const isLast = i === parts.length - 1;
|
|
235
|
+
html += `<span class="folder-breadcrumb-separator">${separator}</span>`;
|
|
236
|
+
html += `<span class="folder-breadcrumb-segment${isLast ? '' : ''}" data-path="${this.escapeHtml(accumulated)}">${this.escapeHtml(parts[i])}</span>`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
this.folderBrowser.breadcrumbEl.innerHTML = html;
|
|
240
|
+
|
|
241
|
+
this.folderBrowser.breadcrumbEl.querySelectorAll('.folder-breadcrumb-segment').forEach(seg => {
|
|
242
|
+
seg.addEventListener('click', () => {
|
|
243
|
+
const p = seg.dataset.path;
|
|
244
|
+
if (p) this.loadFolders(p);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
confirmFolderSelection() {
|
|
250
|
+
const currentPath = this.folderBrowser.currentPath;
|
|
251
|
+
const expanded = currentPath === '~' ? this.folderBrowser.homePath : currentPath;
|
|
252
|
+
this.closeFolderBrowser();
|
|
253
|
+
|
|
254
|
+
const dirName = pathBasename(expanded) || 'root';
|
|
255
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation', {
|
|
256
|
+
detail: { workingDirectory: expanded, title: dirName }
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
setupCloneUI() {
|
|
261
|
+
this.cloneBtn = document.getElementById('cloneRepoBtn');
|
|
262
|
+
this.cloneBar = document.getElementById('cloneInputBar');
|
|
263
|
+
this.cloneInput = document.getElementById('cloneRepoInput');
|
|
264
|
+
this.cloneGoBtn = document.getElementById('cloneGoBtn');
|
|
265
|
+
this.cloneCancelBtn = document.getElementById('cloneCancelBtn');
|
|
266
|
+
|
|
267
|
+
if (!this.cloneBtn || !this.cloneBar) return;
|
|
268
|
+
|
|
269
|
+
this.cloneBtn.addEventListener('click', () => this.toggleCloneBar());
|
|
270
|
+
|
|
271
|
+
this.cloneCancelBtn?.addEventListener('click', () => this.hideCloneBar());
|
|
272
|
+
|
|
273
|
+
this.cloneGoBtn?.addEventListener('click', () => this.performClone());
|
|
274
|
+
|
|
275
|
+
this.cloneInput?.addEventListener('keydown', (e) => {
|
|
276
|
+
if (e.key === 'Enter') this.performClone();
|
|
277
|
+
if (e.key === 'Escape') this.hideCloneBar();
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
toggleCloneBar() {
|
|
282
|
+
if (!this.cloneBar) return;
|
|
283
|
+
const visible = this.cloneBar.style.display !== 'none';
|
|
284
|
+
if (visible) {
|
|
285
|
+
this.hideCloneBar();
|
|
286
|
+
} else {
|
|
287
|
+
this.cloneBar.style.display = 'flex';
|
|
288
|
+
this.cloneInput.value = '';
|
|
289
|
+
this.cloneInput.focus();
|
|
290
|
+
this.removeCloneStatus();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
hideCloneBar() {
|
|
295
|
+
if (this.cloneBar) this.cloneBar.style.display = 'none';
|
|
296
|
+
this.removeCloneStatus();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
removeCloneStatus() {
|
|
300
|
+
const existing = this.sidebarEl?.querySelector('.clone-status');
|
|
301
|
+
if (existing) existing.remove();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
showCloneStatus(message, type) {
|
|
305
|
+
this.removeCloneStatus();
|
|
306
|
+
const statusEl = document.createElement('div');
|
|
307
|
+
statusEl.className = `clone-status ${type}`;
|
|
308
|
+
statusEl.textContent = message;
|
|
309
|
+
if (this.cloneBar && this.cloneBar.parentNode) {
|
|
310
|
+
this.cloneBar.parentNode.insertBefore(statusEl, this.cloneBar.nextSibling);
|
|
311
|
+
}
|
|
312
|
+
if (type === 'clone-success' || type === 'clone-error') {
|
|
313
|
+
setTimeout(() => statusEl.remove(), 5000);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async performClone() {
|
|
318
|
+
const repo = (this.cloneInput?.value || '').trim();
|
|
319
|
+
if (!repo) return;
|
|
320
|
+
if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(repo)) {
|
|
321
|
+
this.showCloneStatus('Invalid format. Use org/repo', 'clone-error');
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.cloneGoBtn.disabled = true;
|
|
326
|
+
this.cloneInput.disabled = true;
|
|
327
|
+
this.showCloneStatus(`Cloning ${repo}...`, 'cloning');
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const res = await fetch((window.__BASE_URL || '') + '/api/clone', {
|
|
331
|
+
method: 'POST',
|
|
332
|
+
headers: { 'Content-Type': 'application/json' },
|
|
333
|
+
body: JSON.stringify({ repo })
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
const data = await res.json();
|
|
337
|
+
|
|
338
|
+
if (!res.ok) {
|
|
339
|
+
this.showCloneStatus(data.error || 'Clone failed', 'clone-error');
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
this.showCloneStatus(`Cloned ${data.name}`, 'clone-success');
|
|
344
|
+
this.hideCloneBar();
|
|
345
|
+
|
|
346
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation', {
|
|
347
|
+
detail: { workingDirectory: data.path, title: data.name }
|
|
348
|
+
}));
|
|
349
|
+
} catch (err) {
|
|
350
|
+
this.showCloneStatus('Network error: ' + err.message, 'clone-error');
|
|
351
|
+
} finally {
|
|
352
|
+
if (this.cloneGoBtn) this.cloneGoBtn.disabled = false;
|
|
353
|
+
if (this.cloneInput) this.cloneInput.disabled = false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
async loadConversations() {
|
|
358
|
+
try {
|
|
359
|
+
const res = await fetch((window.__BASE_URL || '') + '/api/conversations');
|
|
360
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
361
|
+
|
|
362
|
+
const data = await res.json();
|
|
363
|
+
this.conversations = data.conversations || [];
|
|
364
|
+
|
|
365
|
+
for (const conv of this.conversations) {
|
|
366
|
+
if (conv.isStreaming === 1 || conv.isStreaming === true) {
|
|
367
|
+
this.streamingConversations.add(conv.id);
|
|
368
|
+
} else {
|
|
369
|
+
this.streamingConversations.delete(conv.id);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this.render();
|
|
374
|
+
} catch (err) {
|
|
375
|
+
console.error('Failed to load conversations:', err);
|
|
376
|
+
this.showEmpty('Failed to load conversations');
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
render() {
|
|
381
|
+
if (!this.listEl) return;
|
|
382
|
+
|
|
383
|
+
if (this.conversations.length === 0) {
|
|
384
|
+
this.showEmpty();
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this.emptyEl.style.display = 'none';
|
|
389
|
+
|
|
390
|
+
const sorted = [...this.conversations].sort((a, b) =>
|
|
391
|
+
new Date(b.createdAt || 0) - new Date(a.createdAt || 0)
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
const existingMap = {};
|
|
395
|
+
for (const child of Array.from(this.listEl.children)) {
|
|
396
|
+
const cid = child.dataset.convId;
|
|
397
|
+
if (cid) existingMap[cid] = child;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const frag = document.createDocumentFragment();
|
|
401
|
+
for (const conv of sorted) {
|
|
402
|
+
const existing = existingMap[conv.id];
|
|
403
|
+
if (existing) {
|
|
404
|
+
this.updateConversationItem(existing, conv);
|
|
405
|
+
delete existingMap[conv.id];
|
|
406
|
+
frag.appendChild(existing);
|
|
407
|
+
} else {
|
|
408
|
+
frag.appendChild(this.createConversationItem(conv));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
for (const orphan of Object.values(existingMap)) orphan.remove();
|
|
413
|
+
this.listEl.appendChild(frag);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
updateConversationItem(el, conv) {
|
|
417
|
+
const isActive = conv.id === this.activeId;
|
|
418
|
+
el.classList.toggle('active', isActive);
|
|
419
|
+
|
|
420
|
+
const isStreaming = this.streamingConversations.has(conv.id);
|
|
421
|
+
const title = conv.title || `Conversation ${conv.id.slice(0, 8)}`;
|
|
422
|
+
const timestamp = conv.created_at ? new Date(conv.created_at).toLocaleDateString() : 'Unknown';
|
|
423
|
+
const agent = this.getAgentDisplayName(conv.agentType);
|
|
424
|
+
const modelLabel = conv.model ? ` (${conv.model})` : '';
|
|
425
|
+
const wd = conv.workingDirectory ? pathBasename(conv.workingDirectory) : '';
|
|
426
|
+
const metaParts = [agent + modelLabel, timestamp];
|
|
427
|
+
if (wd) metaParts.push(wd);
|
|
428
|
+
|
|
429
|
+
const titleEl = el.querySelector('.conversation-item-title');
|
|
430
|
+
if (titleEl) {
|
|
431
|
+
const badgeHtml = isStreaming
|
|
432
|
+
? '<span class="conversation-streaming-badge" title="Streaming in progress"><span class="streaming-dot"></span></span>'
|
|
433
|
+
: '';
|
|
434
|
+
titleEl.innerHTML = `${badgeHtml}${this.escapeHtml(title)}`;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const metaEl = el.querySelector('.conversation-item-meta');
|
|
438
|
+
if (metaEl) metaEl.textContent = metaParts.join(' \u2022 ');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
createConversationItem(conv) {
|
|
442
|
+
const li = document.createElement('li');
|
|
443
|
+
li.className = 'conversation-item';
|
|
444
|
+
li.dataset.convId = conv.id;
|
|
445
|
+
if (conv.id === this.activeId) li.classList.add('active');
|
|
446
|
+
|
|
447
|
+
const isStreaming = this.streamingConversations.has(conv.id);
|
|
448
|
+
|
|
449
|
+
const title = conv.title || `Conversation ${conv.id.slice(0, 8)}`;
|
|
450
|
+
const timestamp = conv.created_at ? new Date(conv.created_at).toLocaleDateString() : 'Unknown';
|
|
451
|
+
const agent = this.getAgentDisplayName(conv.agentType);
|
|
452
|
+
const modelLabel = conv.model ? ` (${conv.model})` : '';
|
|
453
|
+
const wd = conv.workingDirectory ? conv.workingDirectory.split('/').pop() : '';
|
|
454
|
+
const metaParts = [agent + modelLabel, timestamp];
|
|
455
|
+
if (wd) metaParts.push(wd);
|
|
456
|
+
|
|
457
|
+
const streamingBadge = isStreaming
|
|
458
|
+
? '<span class="conversation-streaming-badge" title="Streaming in progress"><span class="streaming-dot"></span></span>'
|
|
459
|
+
: '';
|
|
460
|
+
|
|
461
|
+
li.innerHTML = `
|
|
462
|
+
<div class="conversation-item-content">
|
|
463
|
+
<div class="conversation-item-title">${streamingBadge}${this.escapeHtml(title)}</div>
|
|
464
|
+
<div class="conversation-item-meta">${metaParts.join(' • ')}</div>
|
|
465
|
+
</div>
|
|
466
|
+
<button class="conversation-item-delete" title="Delete conversation" data-delete-conv="${conv.id}">
|
|
467
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
468
|
+
<polyline points="3 6 5 6 21 6"></polyline>
|
|
469
|
+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
|
470
|
+
</svg>
|
|
471
|
+
</button>
|
|
472
|
+
`;
|
|
473
|
+
|
|
474
|
+
return li;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async confirmDelete(convId, title) {
|
|
478
|
+
const confirmed = await window.UIDialog.confirm(
|
|
479
|
+
`Delete conversation "${title || 'Untitled'}"?\n\nThis will also delete any associated Claude Code session data. This action cannot be undone.`,
|
|
480
|
+
'Delete Conversation'
|
|
481
|
+
);
|
|
482
|
+
if (!confirmed) return;
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
const res = await fetch((window.__BASE_URL || '') + `/api/conversations/${convId}`, {
|
|
486
|
+
method: 'DELETE',
|
|
487
|
+
headers: { 'Content-Type': 'application/json' }
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
if (res.ok) {
|
|
491
|
+
console.log(`[ConversationManager] Deleted conversation ${convId}`);
|
|
492
|
+
this.deleteConversation(convId);
|
|
493
|
+
} else {
|
|
494
|
+
const error = await res.json().catch(() => ({ error: 'Failed to delete' }));
|
|
495
|
+
window.UIDialog.alert('Failed to delete conversation: ' + (error.error || 'Unknown error'), 'Error');
|
|
496
|
+
}
|
|
497
|
+
} catch (err) {
|
|
498
|
+
console.error('[ConversationManager] Delete error:', err);
|
|
499
|
+
window.UIDialog.alert('Failed to delete conversation: ' + err.message, 'Error');
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
select(convId) {
|
|
504
|
+
this.activeId = convId;
|
|
505
|
+
|
|
506
|
+
document.querySelectorAll('.conversation-item').forEach(item => {
|
|
507
|
+
item.classList.remove('active');
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const active = document.querySelector(`[data-conv-id="${convId}"]`);
|
|
511
|
+
if (active) active.classList.add('active');
|
|
512
|
+
|
|
513
|
+
window.dispatchEvent(new CustomEvent('conversation-selected', {
|
|
514
|
+
detail: { conversationId: convId }
|
|
515
|
+
}));
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
createNew() {
|
|
519
|
+
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
520
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation'));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
showEmpty(message = 'No conversations yet') {
|
|
524
|
+
if (!this.listEl) return;
|
|
525
|
+
this.listEl.innerHTML = '';
|
|
526
|
+
this.emptyEl.textContent = message;
|
|
527
|
+
this.emptyEl.style.display = 'block';
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
addConversation(conv) {
|
|
531
|
+
if (this.conversations.some(c => c.id === conv.id)) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
this.conversations.unshift(conv);
|
|
535
|
+
this.render();
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
updateConversation(convId, updates) {
|
|
539
|
+
const conv = this.conversations.find(c => c.id === convId);
|
|
540
|
+
if (conv) {
|
|
541
|
+
Object.assign(conv, updates);
|
|
542
|
+
this.render();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
deleteConversation(convId) {
|
|
547
|
+
this.conversations = this.conversations.filter(c => c.id !== convId);
|
|
548
|
+
if (this.activeId === convId) this.activeId = null;
|
|
549
|
+
this.render();
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
setupWebSocketListener() {
|
|
553
|
+
window.addEventListener('ws-message', (event) => {
|
|
554
|
+
const msg = event.detail;
|
|
555
|
+
|
|
556
|
+
if (msg.type === 'conversation_created') {
|
|
557
|
+
this.addConversation(msg.conversation);
|
|
558
|
+
} else if (msg.type === 'conversation_updated') {
|
|
559
|
+
this.updateConversation(msg.conversation.id, msg.conversation);
|
|
560
|
+
} else if (msg.type === 'conversation_deleted') {
|
|
561
|
+
this.deleteConversation(msg.conversationId);
|
|
562
|
+
} else if (msg.type === 'streaming_start' && msg.conversationId) {
|
|
563
|
+
this.streamingConversations.add(msg.conversationId);
|
|
564
|
+
this.render();
|
|
565
|
+
} else if ((msg.type === 'streaming_complete' || msg.type === 'streaming_error') && msg.conversationId) {
|
|
566
|
+
this.streamingConversations.delete(msg.conversationId);
|
|
567
|
+
this.render();
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
escapeHtml(text) {
|
|
573
|
+
return window._escHtml(text);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (document.readyState === 'loading') {
|
|
578
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
579
|
+
window.conversationManager = new ConversationManager();
|
|
580
|
+
});
|
|
581
|
+
} else {
|
|
582
|
+
window.conversationManager = new ConversationManager();
|
|
583
|
+
}
|