agentgui 1.0.820 → 1.0.822
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/static/index.html +4 -0
- package/static/js/conv-list-renderer.js +197 -0
- package/static/js/conv-sidebar-actions.js +184 -0
- package/static/js/conv-sidebar-clone.js +91 -0
- package/static/js/conversations.js +116 -736
- package/static/js/ui-components.js +88 -187
- package/static/js/websocket-manager.js +107 -642
- package/static/js/ws-core.js +162 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## 2026-04-11
|
|
2
|
+
- refactor: split conversations.js (742L→116L) into conv-sidebar-actions.js (prototype extension: drag/drop, bulk actions, folder browser), conv-list-renderer.js (loadConversations, render, vnode), conv-sidebar-clone.js (clone UI, delete-all); all ≤200 lines
|
|
3
|
+
- refactor: split websocket-manager.js (643L) into ws-core.js (class constructor, connect, onOpen, onMessage, reconnect), websocket-manager.js (sendMessage, subscriptions, state); ws-latency/connection/heartbeat empty stubs deleted
|
|
4
|
+
- refactor: split event-filter.js into event-filter.js + event-filter-config.js (window export/CSV/Markdown helpers)
|
|
5
|
+
- refactor: split agent-auth.js into agent-auth.js + agent-auth-oauth.js (IIFE, OAuth modal flows)
|
|
6
|
+
- refactor: fix index.html script load order — ws-core.js before websocket-manager.js; remove empty stub script tags (ws-connection, ws-latency, ws-heartbeat)
|
|
7
|
+
|
|
1
8
|
## 2026-04-11
|
|
2
9
|
- refactor: split jsonl-watcher.js parse/event logic into jsonl-parser.js; watcher retains file watching/polling only
|
|
3
10
|
- refactor: split tool-version.js into tool-version-check.js (sync) and tool-version-fetch.js (async/network)
|
package/package.json
CHANGED
package/static/index.html
CHANGED
|
@@ -293,7 +293,11 @@
|
|
|
293
293
|
<script defer src="/gm/js/recording-machine.js"></script>
|
|
294
294
|
<script defer src="/gm/js/terminal-machine.js"></script>
|
|
295
295
|
<script defer src="/gm/js/conversations.js"></script>
|
|
296
|
+
<script defer src="/gm/js/conv-sidebar-actions.js"></script>
|
|
297
|
+
<script defer src="/gm/js/conv-list-renderer.js"></script>
|
|
298
|
+
<script defer src="/gm/js/conv-sidebar-clone.js"></script>
|
|
296
299
|
<script defer src="/gm/lib/msgpackr.min.js"></script>
|
|
300
|
+
<script defer src="/gm/js/ws-core.js"></script>
|
|
297
301
|
<script defer src="/gm/js/websocket-manager.js"></script>
|
|
298
302
|
<script defer src="/gm/js/ws-client.js"></script>
|
|
299
303
|
<script defer src="/gm/js/syntax-highlighter.js"></script>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Object.assign(ConversationManager.prototype, {
|
|
2
|
+
async loadConversations() {
|
|
3
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'LOAD_START' });
|
|
4
|
+
try {
|
|
5
|
+
const base = window.__BASE_URL || '/gm';
|
|
6
|
+
const res = await fetch(base + '/api/conversations');
|
|
7
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
8
|
+
const data = await res.json();
|
|
9
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'LOAD_DONE', conversations: data.conversations || [] });
|
|
10
|
+
const cliStreaming = window.agentGuiClient?.state?.streamingConversations;
|
|
11
|
+
for (const conv of this.conversations) {
|
|
12
|
+
const streaming = conv.isStreaming === 1 || conv.isStreaming === true || (cliStreaming ? cliStreaming.has(conv.id) : false);
|
|
13
|
+
window.convListMachineAPI?.send({ type: streaming ? 'SET_STREAMING' : 'CLEAR_STREAMING', id: conv.id });
|
|
14
|
+
}
|
|
15
|
+
this.render();
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error('Failed to load conversations:', err);
|
|
18
|
+
window.convListMachineAPI?.send({ type: 'LOAD_ERROR' });
|
|
19
|
+
if (this.conversations.length === 0) this.showEmpty('Failed to load conversations');
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
_convVnode(conv) {
|
|
24
|
+
const h = window.webjsx?.createElement;
|
|
25
|
+
if (!h) return null;
|
|
26
|
+
const isActive = conv.id === this.activeId;
|
|
27
|
+
const isStreaming = this.streamingConversations.has(conv.id);
|
|
28
|
+
const title = conv.title || `Conversation ${conv.id.slice(0, 8)}`;
|
|
29
|
+
const timestamp = conv.created_at ? new Date(conv.created_at).toLocaleDateString() : 'Unknown';
|
|
30
|
+
const agent = this.getAgentDisplayName(conv.agentId || conv.agentType);
|
|
31
|
+
const modelLabel = this.formatModelLabel(conv.model);
|
|
32
|
+
const wd = conv.workingDirectory ? pathBasename(conv.workingDirectory) : '';
|
|
33
|
+
const metaParts = [agent + modelLabel, timestamp];
|
|
34
|
+
if (wd) metaParts.push(wd);
|
|
35
|
+
const badge = isStreaming ? h('span', { class: 'conversation-streaming-badge', title: 'Streaming in progress' }, h('span', { class: 'streaming-dot' })) : null;
|
|
36
|
+
const dragAttrs = conv.pinned ? { draggable: 'true', 'data-drag-conv': conv.id } : {};
|
|
37
|
+
return h('li', { class: 'conversation-item' + (isActive ? ' active' : '') + (conv.pinned ? ' pinned' : ''), 'data-conv-id': conv.id, ...dragAttrs },
|
|
38
|
+
h('div', { class: 'conversation-item-content' },
|
|
39
|
+
h('div', { class: 'conversation-item-title' }, ...(badge ? [badge, title] : [title])),
|
|
40
|
+
h('div', { class: 'conversation-item-meta' }, metaParts.join(' • '))
|
|
41
|
+
),
|
|
42
|
+
h('input', { type: 'checkbox', class: 'conversation-item-checkbox', 'data-bulk-check': conv.id, title: 'Select for bulk action', onclick: 'event.stopPropagation()' }),
|
|
43
|
+
h('button', { class: 'conversation-item-export', title: 'Export as markdown', 'data-export-conv': conv.id },
|
|
44
|
+
h('svg', { width: '14', height: '14', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' },
|
|
45
|
+
h('path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' }),
|
|
46
|
+
h('polyline', { points: '7 10 12 15 17 10' }),
|
|
47
|
+
h('line', { x1: '12', y1: '15', x2: '12', y2: '3' }))),
|
|
48
|
+
h('button', { class: 'conversation-item-archive', title: 'Archive conversation', 'data-archive-conv': conv.id },
|
|
49
|
+
h('svg', { width: '14', height: '14', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' },
|
|
50
|
+
h('path', { d: 'M21 8v13H3V8' }), h('path', { d: 'M1 3h22v5H1z' }), h('path', { d: 'M10 12h4' }))),
|
|
51
|
+
h('button', { class: 'conversation-item-delete', title: 'Delete conversation', 'data-delete-conv': conv.id },
|
|
52
|
+
h('svg', { width: '14', height: '14', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2' },
|
|
53
|
+
h('polyline', { points: '3 6 5 6 21 6' }),
|
|
54
|
+
h('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' })))
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
render() {
|
|
59
|
+
if (!this.listEl) return;
|
|
60
|
+
if (this.conversations.length === 0) { this.showEmpty(); return; }
|
|
61
|
+
this.emptyEl.style.display = 'none';
|
|
62
|
+
const sorted = [...this.conversations].sort((a, b) => new Date(b.createdAt || 0) - new Date(a.createdAt || 0));
|
|
63
|
+
if (window.webjsx?.applyDiff) {
|
|
64
|
+
window.webjsx.applyDiff(this.listEl, sorted.map(conv => this._convVnode(conv)).filter(Boolean));
|
|
65
|
+
} else {
|
|
66
|
+
this._renderFallback(sorted);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
_renderFallback(sorted) {
|
|
71
|
+
const existingMap = {};
|
|
72
|
+
for (const child of Array.from(this.listEl.children)) {
|
|
73
|
+
if (child.dataset.convId) existingMap[child.dataset.convId] = child;
|
|
74
|
+
}
|
|
75
|
+
const frag = document.createDocumentFragment();
|
|
76
|
+
for (const conv of sorted) {
|
|
77
|
+
const el = existingMap[conv.id] || document.createElement('li');
|
|
78
|
+
el.className = 'conversation-item' + (conv.id === this.activeId ? ' active' : '');
|
|
79
|
+
el.dataset.convId = conv.id;
|
|
80
|
+
delete existingMap[conv.id];
|
|
81
|
+
frag.appendChild(el);
|
|
82
|
+
}
|
|
83
|
+
for (const orphan of Object.values(existingMap)) orphan.remove();
|
|
84
|
+
this.listEl.appendChild(frag);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async confirmDelete(convId, title) {
|
|
88
|
+
const confirmed = await window.UIDialog.confirm(`Delete conversation "${title || 'Untitled'}"?\n\nThis will also delete any associated Claude Code session data. This action cannot be undone.`, 'Delete Conversation');
|
|
89
|
+
if (!confirmed) return;
|
|
90
|
+
try {
|
|
91
|
+
await window.wsClient.rpc('conv.del', { id: convId });
|
|
92
|
+
this.deleteConversation(convId);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
window.UIDialog.alert('Failed to delete conversation: ' + (err.message || 'Unknown error'), 'Error');
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
select(convId) {
|
|
99
|
+
const result = window.ConversationState?.selectConversation(convId, 'user_click', 1) || { success: false };
|
|
100
|
+
if (!result.success && result.reason !== 'already_selected') { console.error('[ConvMgr] activeId mutation rejected:', result.reason); return; }
|
|
101
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'SELECT', id: convId });
|
|
102
|
+
document.querySelectorAll('.conversation-item').forEach(item => item.classList.remove('active'));
|
|
103
|
+
const active = document.querySelector(`[data-conv-id="${convId}"]`);
|
|
104
|
+
if (active) active.classList.add('active');
|
|
105
|
+
window.dispatchEvent(new CustomEvent('conversation-selected', { detail: { conversationId: convId } }));
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
createNew() {
|
|
109
|
+
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
110
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation'));
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
showEmpty(message = 'No conversations yet') {
|
|
114
|
+
if (!this.listEl) return;
|
|
115
|
+
this.listEl.innerHTML = '';
|
|
116
|
+
this.emptyEl.textContent = message;
|
|
117
|
+
this.emptyEl.style.display = 'block';
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
addConversation(conv) {
|
|
121
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'ADD', conversation: conv });
|
|
122
|
+
this.render();
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
updateConversation(convId, updates) {
|
|
126
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'UPDATE', conversation: Object.assign({ id: convId }, updates) });
|
|
127
|
+
this.render();
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
deleteConversation(convId) {
|
|
131
|
+
const wasActive = this.activeId === convId;
|
|
132
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'DELETE', id: convId });
|
|
133
|
+
if (wasActive) { window.ConversationState?.deleteConversation(convId, 1); window.dispatchEvent(new CustomEvent('conversation-deselected')); }
|
|
134
|
+
this.render();
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
getSelectedIds() {
|
|
138
|
+
return [...this.listEl.querySelectorAll('.conversation-item-checkbox:checked')].map(cb => cb.dataset.bulkCheck);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
async bulkArchive() {
|
|
142
|
+
const ids = this.getSelectedIds();
|
|
143
|
+
if (ids.length === 0) return;
|
|
144
|
+
if (!await window.UIDialog?.confirm(`Archive ${ids.length} conversation(s)?`, 'Bulk Archive')) return;
|
|
145
|
+
const base = window.__BASE_URL || '';
|
|
146
|
+
for (const id of ids) {
|
|
147
|
+
try { await fetch(`${base}/api/conversations/${id}/archive`, { method: 'POST' }); } catch (_) {}
|
|
148
|
+
this.deleteConversation(id);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
async bulkDelete() {
|
|
153
|
+
const ids = this.getSelectedIds();
|
|
154
|
+
if (ids.length === 0) return;
|
|
155
|
+
if (!await window.UIDialog?.confirm(`Permanently delete ${ids.length} conversation(s)?`, 'Bulk Delete')) return;
|
|
156
|
+
for (const id of ids) this.confirmDelete(id, '');
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
async exportConversation(convId) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await window.wsClient.rpc('conv.export', { id: convId, format: 'markdown' });
|
|
162
|
+
const blob = new Blob([result.markdown], { type: 'text/markdown' });
|
|
163
|
+
const url = URL.createObjectURL(blob);
|
|
164
|
+
const a = document.createElement('a');
|
|
165
|
+
a.href = url; a.download = (result.title || 'conversation').replace(/[^a-zA-Z0-9_-]/g, '_') + '.md';
|
|
166
|
+
a.click(); URL.revokeObjectURL(url);
|
|
167
|
+
} catch (e) { console.error('[export] Failed:', e.message); }
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
async archiveConversation(convId) {
|
|
171
|
+
try {
|
|
172
|
+
const resp = await fetch(`${window.__BASE_URL || ''}/api/conversations/${convId}/archive`, { method: 'POST' });
|
|
173
|
+
if (!resp.ok) return;
|
|
174
|
+
this.deleteConversation(convId);
|
|
175
|
+
} catch (e) { console.error('[archive] Failed:', e.message); }
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
setupWebSocketListener() {
|
|
179
|
+
window.addEventListener('ws-message', (event) => {
|
|
180
|
+
const msg = event.detail;
|
|
181
|
+
if (msg.type === 'conversation_created') { this.addConversation(msg.conversation); }
|
|
182
|
+
else if (msg.type === 'conversation_updated') { this.updateConversation(msg.conversation.id, msg.conversation); }
|
|
183
|
+
else if (msg.type === 'conversation_deleted') { this.deleteConversation(msg.conversationId); }
|
|
184
|
+
else if (msg.type === 'all_conversations_deleted') {
|
|
185
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'CLEAR_ALL' });
|
|
186
|
+
window.ConversationState?.clear('all_deleted');
|
|
187
|
+
this.showEmpty('No conversations yet');
|
|
188
|
+
} else if (msg.type === 'streaming_start' && msg.conversationId) {
|
|
189
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'SET_STREAMING', id: msg.conversationId });
|
|
190
|
+
this.render();
|
|
191
|
+
} else if ((msg.type === 'streaming_complete' || msg.type === 'streaming_error') && msg.conversationId) {
|
|
192
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'CLEAR_STREAMING', id: msg.conversationId });
|
|
193
|
+
this.render();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Object.assign(ConversationManager.prototype, {
|
|
2
|
+
setupDelegatedListeners() {
|
|
3
|
+
let draggedId = null;
|
|
4
|
+
this.listEl.addEventListener('dragstart', (e) => {
|
|
5
|
+
const item = e.target.closest('[data-drag-conv]');
|
|
6
|
+
if (!item) return;
|
|
7
|
+
draggedId = item.dataset.dragConv;
|
|
8
|
+
item.style.opacity = '0.5';
|
|
9
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
10
|
+
});
|
|
11
|
+
this.listEl.addEventListener('dragend', (e) => {
|
|
12
|
+
const item = e.target.closest('[data-drag-conv]');
|
|
13
|
+
if (item) item.style.opacity = '';
|
|
14
|
+
draggedId = null;
|
|
15
|
+
});
|
|
16
|
+
this.listEl.addEventListener('dragover', (e) => {
|
|
17
|
+
const item = e.target.closest('[data-drag-conv]');
|
|
18
|
+
if (item && draggedId) { e.preventDefault(); e.dataTransfer.dropEffect = 'move'; }
|
|
19
|
+
});
|
|
20
|
+
this.listEl.addEventListener('drop', (e) => {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
const target = e.target.closest('[data-drag-conv]');
|
|
23
|
+
if (!target || !draggedId || target.dataset.dragConv === draggedId) return;
|
|
24
|
+
const pinnedItems = [...this.listEl.querySelectorAll('[data-drag-conv]')];
|
|
25
|
+
const draggedEl = pinnedItems.find(el => el.dataset.dragConv === draggedId);
|
|
26
|
+
if (!draggedEl) return;
|
|
27
|
+
this.listEl.insertBefore(draggedEl, target);
|
|
28
|
+
const newOrder = [...this.listEl.querySelectorAll('[data-drag-conv]')].map(el => el.dataset.dragConv);
|
|
29
|
+
window.wsClient?.rpc('conv.reorder', { order: newOrder }).catch(() => {});
|
|
30
|
+
});
|
|
31
|
+
const bulkBar = document.getElementById('bulkActionBar');
|
|
32
|
+
const bulkCount = document.getElementById('bulkCount');
|
|
33
|
+
const updateBulkBar = () => {
|
|
34
|
+
const checked = this.getSelectedIds().length;
|
|
35
|
+
if (bulkBar) bulkBar.style.display = checked > 0 ? 'flex' : 'none';
|
|
36
|
+
if (bulkCount) bulkCount.textContent = `${checked} selected`;
|
|
37
|
+
};
|
|
38
|
+
this.listEl.addEventListener('change', (e) => {
|
|
39
|
+
if (e.target.matches('.conversation-item-checkbox')) updateBulkBar();
|
|
40
|
+
});
|
|
41
|
+
document.getElementById('bulkArchiveBtn')?.addEventListener('click', () => this.bulkArchive());
|
|
42
|
+
document.getElementById('bulkDeleteBtn')?.addEventListener('click', () => this.bulkDelete());
|
|
43
|
+
this.listEl.addEventListener('click', (e) => {
|
|
44
|
+
const exportBtn = e.target.closest('[data-export-conv]');
|
|
45
|
+
if (exportBtn) { e.stopPropagation(); this.exportConversation(exportBtn.dataset.exportConv); return; }
|
|
46
|
+
const archiveBtn = e.target.closest('[data-archive-conv]');
|
|
47
|
+
if (archiveBtn) { e.stopPropagation(); this.archiveConversation(archiveBtn.dataset.archiveConv); return; }
|
|
48
|
+
const deleteBtn = e.target.closest('[data-delete-conv]');
|
|
49
|
+
if (deleteBtn) {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
const convId = deleteBtn.dataset.deleteConv;
|
|
52
|
+
const conv = this.conversations.find(c => c.id === convId);
|
|
53
|
+
this.confirmDelete(convId, conv?.title || 'Untitled');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const item = e.target.closest('[data-conv-id]');
|
|
57
|
+
if (item) this.select(item.dataset.convId);
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
setupFolderBrowser() {
|
|
62
|
+
this.folderBrowser.modal = document.getElementById('folderBrowserModal');
|
|
63
|
+
this.folderBrowser.listEl = document.getElementById('folderList');
|
|
64
|
+
this.folderBrowser.breadcrumbEl = document.getElementById('folderBreadcrumb');
|
|
65
|
+
if (!this.folderBrowser.modal) return;
|
|
66
|
+
const closeBtn = this.folderBrowser.modal.querySelector('[data-folder-close]');
|
|
67
|
+
const cancelBtn = this.folderBrowser.modal.querySelector('[data-folder-cancel]');
|
|
68
|
+
const selectBtn = this.folderBrowser.modal.querySelector('[data-folder-select]');
|
|
69
|
+
closeBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
70
|
+
cancelBtn?.addEventListener('click', () => this.closeFolderBrowser());
|
|
71
|
+
selectBtn?.addEventListener('click', () => this.confirmFolderSelection());
|
|
72
|
+
this.folderBrowser.modal.addEventListener('click', (e) => {
|
|
73
|
+
if (e.target === this.folderBrowser.modal) this.closeFolderBrowser();
|
|
74
|
+
});
|
|
75
|
+
this.folderBrowser.homePathReady = this.fetchHomePath();
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
async fetchHomePath() {
|
|
79
|
+
try {
|
|
80
|
+
const res = await fetch(`${window.__BASE_URL || '/gm'}/api/home`);
|
|
81
|
+
const data = await res.json();
|
|
82
|
+
this.folderBrowser.homePath = data.home || '~';
|
|
83
|
+
this.folderBrowser.cwdPath = data.cwd || null;
|
|
84
|
+
} catch (e) { console.error('Failed to fetch home path:', e); }
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async openFolderBrowser() {
|
|
88
|
+
window.dispatchEvent(new CustomEvent('preparing-new-conversation'));
|
|
89
|
+
if (!this.folderBrowser.modal) { this.createNew(); return; }
|
|
90
|
+
if (this.folderBrowser.homePathReady) await this.folderBrowser.homePathReady;
|
|
91
|
+
const startPath = this.folderBrowser.cwdPath || '~';
|
|
92
|
+
this.folderBrowser.currentPath = startPath;
|
|
93
|
+
this.folderBrowser.modal.classList.add('visible');
|
|
94
|
+
this.loadFolders(startPath);
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
closeFolderBrowser() { this.folderBrowser.modal?.classList.remove('visible'); },
|
|
98
|
+
|
|
99
|
+
async loadFolders(dirPath) {
|
|
100
|
+
this.folderBrowser.currentPath = dirPath;
|
|
101
|
+
this.renderBreadcrumb(dirPath);
|
|
102
|
+
if (!this.folderBrowser.listEl) return;
|
|
103
|
+
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-loading">Loading...</li>';
|
|
104
|
+
try {
|
|
105
|
+
const data = await window.wsClient.rpc('folders', { path: dirPath });
|
|
106
|
+
const folders = data.folders || [];
|
|
107
|
+
this.folderBrowser.listEl.innerHTML = '';
|
|
108
|
+
const isAtRoot = dirPath === '~' || dirPath === '/' || dirPath === this.folderBrowser.homePath || /^[A-Za-z]:[\/\\]?$/.test(dirPath);
|
|
109
|
+
if (!isAtRoot) {
|
|
110
|
+
const parentPath = this.getParentPath(dirPath);
|
|
111
|
+
const upItem = document.createElement('li');
|
|
112
|
+
upItem.className = 'folder-list-item';
|
|
113
|
+
upItem.innerHTML = '<span class="folder-list-item-icon">..</span><span class="folder-list-item-name">Parent Directory</span>';
|
|
114
|
+
upItem.addEventListener('click', () => this.loadFolders(parentPath));
|
|
115
|
+
this.folderBrowser.listEl.appendChild(upItem);
|
|
116
|
+
}
|
|
117
|
+
if (folders.length === 0 && this.folderBrowser.listEl.children.length === 0) {
|
|
118
|
+
this.folderBrowser.listEl.innerHTML = '<li class="folder-list-empty">No subdirectories</li>';
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
for (const folder of folders) {
|
|
122
|
+
const li = document.createElement('li');
|
|
123
|
+
li.className = 'folder-list-item';
|
|
124
|
+
li.innerHTML = `<span class="folder-list-item-icon">📁</span><span class="folder-list-item-name">${this.escapeHtml(folder.name)}</span>`;
|
|
125
|
+
li.addEventListener('click', () => {
|
|
126
|
+
const expandedBase = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
127
|
+
const separator = expandedBase.includes('\\') ? '\\' : '/';
|
|
128
|
+
const base = expandedBase.replace(/[\/\\]+$/, '');
|
|
129
|
+
this.loadFolders(base + separator + folder.name);
|
|
130
|
+
});
|
|
131
|
+
this.folderBrowser.listEl.appendChild(li);
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
this.folderBrowser.listEl.innerHTML = `<li class="folder-list-error">Error: ${this.escapeHtml(err.message)}</li>`;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
getParentPath(dirPath) {
|
|
139
|
+
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
140
|
+
const parts = pathSplit(expanded);
|
|
141
|
+
const isWindows = expanded.includes('\\') || /^[A-Za-z]:/.test(expanded);
|
|
142
|
+
const separator = isWindows ? '\\' : '/';
|
|
143
|
+
if (parts.length <= 1) return isWindows && parts[0] && parts[0].endsWith(':') ? parts[0] + separator : separator;
|
|
144
|
+
parts.pop();
|
|
145
|
+
if (isWindows) { const joined = parts.join(separator); return parts.length === 1 && parts[0].endsWith(':') ? joined + separator : joined; }
|
|
146
|
+
return separator + parts.join(separator);
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
renderBreadcrumb(dirPath) {
|
|
150
|
+
if (!this.folderBrowser.breadcrumbEl) return;
|
|
151
|
+
const expanded = dirPath === '~' ? this.folderBrowser.homePath : dirPath;
|
|
152
|
+
const parts = pathSplit(expanded);
|
|
153
|
+
const isWin = expanded.includes('\\') || /^[A-Za-z]:/.test(expanded);
|
|
154
|
+
const separator = isWin ? '\\' : '/';
|
|
155
|
+
const rootPath = isWin && parts[0] && /^[A-Za-z]:$/.test(parts[0]) ? parts[0] + separator : separator;
|
|
156
|
+
let html = `<span class="folder-breadcrumb-segment" data-path="${this.escapeHtml(rootPath)}">${this.escapeHtml(rootPath)} </span>`;
|
|
157
|
+
let accumulated = '';
|
|
158
|
+
const isDriveLetter = isWin && parts[0] && /^[A-Za-z]:$/.test(parts[0]);
|
|
159
|
+
for (let i = 0; i < parts.length; i++) {
|
|
160
|
+
if (i === 0 && isDriveLetter) accumulated = parts[0];
|
|
161
|
+
else accumulated += separator + parts[i];
|
|
162
|
+
const segPath = (i === 0 && isDriveLetter) ? rootPath : accumulated;
|
|
163
|
+
html += `<span class="folder-breadcrumb-separator">${separator}</span>`;
|
|
164
|
+
html += `<span class="folder-breadcrumb-segment" data-path="${this.escapeHtml(segPath)}">${this.escapeHtml(parts[i])}</span>`;
|
|
165
|
+
}
|
|
166
|
+
this.folderBrowser.breadcrumbEl.innerHTML = html;
|
|
167
|
+
this.folderBrowser.breadcrumbEl.querySelectorAll('.folder-breadcrumb-segment').forEach(seg => {
|
|
168
|
+
seg.addEventListener('click', () => { const p = seg.dataset.path; if (p) this.loadFolders(p); });
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
confirmFolderSelection() {
|
|
173
|
+
const currentPath = this.folderBrowser.currentPath;
|
|
174
|
+
const expanded = currentPath === '~' ? this.folderBrowser.homePath : currentPath;
|
|
175
|
+
this.closeFolderBrowser();
|
|
176
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation', { detail: { workingDirectory: expanded, title: pathBasename(expanded) || 'root' } }));
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
showLoading() {
|
|
180
|
+
if (!this.listEl) return;
|
|
181
|
+
this.listEl.innerHTML = '';
|
|
182
|
+
if (this.emptyEl) { this.emptyEl.textContent = 'Loading...'; this.emptyEl.style.display = 'block'; }
|
|
183
|
+
}
|
|
184
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Object.assign(ConversationManager.prototype, {
|
|
2
|
+
setupDeleteAllButton() {
|
|
3
|
+
this.deleteAllBtn = document.getElementById('deleteAllConversationsBtn');
|
|
4
|
+
if (!this.deleteAllBtn) return;
|
|
5
|
+
this.deleteAllBtn.addEventListener('click', () => this.confirmDeleteAll());
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
async confirmDeleteAll() {
|
|
9
|
+
if (this.conversations.length === 0) { window.UIDialog.alert('No conversations to delete', 'Information'); return; }
|
|
10
|
+
const confirmed = await window.UIDialog.confirm(`Delete all ${this.conversations.length} conversation(s) and associated Claude Code artifacts?\n\nThis action cannot be undone.`, 'Delete All Conversations');
|
|
11
|
+
if (!confirmed) return;
|
|
12
|
+
try {
|
|
13
|
+
this.deleteAllBtn.disabled = true;
|
|
14
|
+
await window.wsClient.rpc('conv.del.all', {});
|
|
15
|
+
if (window.convListMachineAPI) window.convListMachineAPI.send({ type: 'CLEAR_ALL' });
|
|
16
|
+
window.ConversationState?.clear('delete_all');
|
|
17
|
+
window.dispatchEvent(new CustomEvent('conversation-deselected'));
|
|
18
|
+
this.render();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
console.error('[ConversationManager] Delete all error:', err);
|
|
21
|
+
window.UIDialog.alert('Failed to delete all conversations: ' + (err.message || 'Unknown error'), 'Error');
|
|
22
|
+
} finally { this.deleteAllBtn.disabled = false; }
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
setupCloneUI() {
|
|
26
|
+
this.cloneBtn = document.getElementById('cloneRepoBtn');
|
|
27
|
+
this.cloneBar = document.getElementById('cloneInputBar');
|
|
28
|
+
this.cloneInput = document.getElementById('cloneRepoInput');
|
|
29
|
+
this.cloneGoBtn = document.getElementById('cloneGoBtn');
|
|
30
|
+
this.cloneCancelBtn = document.getElementById('cloneCancelBtn');
|
|
31
|
+
if (!this.cloneBtn || !this.cloneBar) return;
|
|
32
|
+
this.cloneBtn.addEventListener('click', () => this.toggleCloneBar());
|
|
33
|
+
this.cloneCancelBtn?.addEventListener('click', () => this.hideCloneBar());
|
|
34
|
+
this.cloneGoBtn?.addEventListener('click', () => this.performClone());
|
|
35
|
+
this.cloneInput?.addEventListener('keydown', (e) => { if (e.key === 'Enter') this.performClone(); if (e.key === 'Escape') this.hideCloneBar(); });
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
toggleCloneBar() {
|
|
39
|
+
if (!this.cloneBar) return;
|
|
40
|
+
if (this.cloneBar.style.display !== 'none') { this.hideCloneBar(); return; }
|
|
41
|
+
this.cloneBar.style.display = 'flex';
|
|
42
|
+
this.cloneInput.value = '';
|
|
43
|
+
this.cloneInput.focus();
|
|
44
|
+
this.removeCloneStatus();
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
hideCloneBar() {
|
|
48
|
+
if (this.cloneBar) this.cloneBar.style.display = 'none';
|
|
49
|
+
this.removeCloneStatus();
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
removeCloneStatus() {
|
|
53
|
+
const existing = this.sidebarEl?.querySelector('.clone-status');
|
|
54
|
+
if (existing) existing.remove();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
showCloneStatus(message, type) {
|
|
58
|
+
this.removeCloneStatus();
|
|
59
|
+
const statusEl = document.createElement('div');
|
|
60
|
+
statusEl.className = `clone-status ${type}`;
|
|
61
|
+
statusEl.textContent = message;
|
|
62
|
+
if (this.cloneBar && this.cloneBar.parentNode) this.cloneBar.parentNode.insertBefore(statusEl, this.cloneBar.nextSibling);
|
|
63
|
+
if (type === 'clone-success' || type === 'clone-error') setTimeout(() => statusEl.remove(), 5000);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
async performClone() {
|
|
67
|
+
const repo = (this.cloneInput?.value || '').trim();
|
|
68
|
+
if (!repo) return;
|
|
69
|
+
if (!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(repo)) { this.showCloneStatus('Invalid format. Use org/repo', 'clone-error'); return; }
|
|
70
|
+
this.cloneGoBtn.disabled = true;
|
|
71
|
+
this.cloneInput.disabled = true;
|
|
72
|
+
this.showCloneStatus(`Cloning ${repo}...`, 'cloning');
|
|
73
|
+
try {
|
|
74
|
+
const data = await window.wsClient.rpc('clone', { repo });
|
|
75
|
+
this.showCloneStatus(`Cloned ${data.name}`, 'clone-success');
|
|
76
|
+
this.hideCloneBar();
|
|
77
|
+
window.dispatchEvent(new CustomEvent('create-new-conversation', { detail: { workingDirectory: data.path, title: data.name } }));
|
|
78
|
+
} catch (err) {
|
|
79
|
+
this.showCloneStatus(err.message || 'Clone failed', 'clone-error');
|
|
80
|
+
} finally {
|
|
81
|
+
if (this.cloneGoBtn) this.cloneGoBtn.disabled = false;
|
|
82
|
+
if (this.cloneInput) this.cloneInput.disabled = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (document.readyState === 'loading') {
|
|
88
|
+
document.addEventListener('DOMContentLoaded', () => { window.conversationManager = new ConversationManager(); });
|
|
89
|
+
} else {
|
|
90
|
+
window.conversationManager = new ConversationManager();
|
|
91
|
+
}
|