@bakapiano/ccsm 0.9.0 → 0.10.1
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 +222 -195
- package/README.md +77 -79
- package/lib/cliSessionWatcher.js +249 -0
- package/lib/config.js +101 -24
- package/lib/folders.js +96 -0
- package/lib/localCliSessions.js +177 -0
- package/lib/persistedSessions.js +134 -0
- package/lib/webTerminal.js +31 -18
- package/lib/workspace.js +26 -4
- package/package.json +1 -1
- package/public/assets/claude-color.svg +1 -0
- package/public/assets/codex-color.svg +1 -0
- package/public/assets/copilot-color.svg +1 -0
- package/public/css/base.css +22 -5
- package/public/css/cards.css +37 -3
- package/public/css/feedback.css +127 -43
- package/public/css/forms.css +97 -25
- package/public/css/layout.css +74 -26
- package/public/css/modal.css +40 -26
- package/public/css/responsive.css +2 -2
- package/public/css/sidebar.css +424 -25
- package/public/css/terminals.css +138 -0
- package/public/css/tokens.css +28 -12
- package/public/css/wco.css +38 -39
- package/public/css/widgets.css +1177 -6
- package/public/index.html +35 -2
- package/public/js/api.js +194 -37
- package/public/js/components/AdoptModal.js +171 -0
- package/public/js/components/App.js +1 -11
- package/public/js/components/DirectoryPicker.js +203 -0
- package/public/js/components/EntityFormModal.js +105 -0
- package/public/js/components/Modal.js +51 -0
- package/public/js/components/OfflineBanner.js +29 -23
- package/public/js/components/PageTitleBar.js +13 -0
- package/public/js/components/Picker.js +179 -0
- package/public/js/components/Popover.js +55 -0
- package/public/js/components/Sidebar.js +219 -32
- package/public/js/components/TerminalView.js +27 -3
- package/public/js/components/useDragSort.js +67 -0
- package/public/js/dialog.js +10 -2
- package/public/js/icons.js +66 -3
- package/public/js/main.js +54 -3
- package/public/js/pages/AboutPage.js +80 -0
- package/public/js/pages/ConfigurePage.js +429 -207
- package/public/js/pages/LaunchPage.js +326 -86
- package/public/js/pages/SessionsPage.js +91 -41
- package/public/js/state.js +102 -73
- package/public/manifest.webmanifest +2 -2
- package/scripts/install.js +7 -2
- package/server.js +755 -441
- package/lib/favorites.js +0 -51
- package/lib/focus.js +0 -369
- package/lib/labels.js +0 -29
- package/lib/launcher.js +0 -219
- package/lib/sessions.js +0 -272
- package/lib/snapshot.js +0 -141
- package/public/js/actions.js +0 -107
- package/public/js/components/Fab.js +0 -11
- package/public/js/components/FavoritesTable.js +0 -81
- package/public/js/components/Footer.js +0 -12
- package/public/js/components/NewSessionModal.js +0 -153
- package/public/js/components/PageHead.js +0 -33
- package/public/js/components/Pagination.js +0 -27
- package/public/js/components/RecentTable.js +0 -68
- package/public/js/components/SessionsTable.js +0 -71
- package/public/js/components/SnapshotPanel.js +0 -77
- package/public/js/components/TitleCell.js +0 -40
- package/public/js/components/WorkspacesGrid.js +0 -41
- package/public/js/pages/TerminalsPage.js +0 -74
package/public/index.html
CHANGED
|
@@ -8,17 +8,49 @@
|
|
|
8
8
|
honor this in standalone app windows. -->
|
|
9
9
|
<meta name="theme-color" content="#faf9f5" />
|
|
10
10
|
<meta name="color-scheme" content="light" />
|
|
11
|
-
<title>CCSM
|
|
11
|
+
<title>CCSM</title>
|
|
12
12
|
<!-- All asset paths are RELATIVE so the same index.html works when
|
|
13
13
|
served from localhost:7777/ (backend bundle) AND from
|
|
14
14
|
https://bakapiano.github.io/ccsm/v1/ (GH Pages hosted). -->
|
|
15
15
|
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
|
|
16
16
|
<link rel="manifest" href="./manifest.webmanifest" />
|
|
17
|
+
<!-- Apply saved accent color BEFORE stylesheets/paint to avoid a
|
|
18
|
+
flash of the default theme. Mirrors applyAccentCssVars() in
|
|
19
|
+
state.js (only the bg-tinted vars that affect first paint). -->
|
|
20
|
+
<script>
|
|
21
|
+
(function () {
|
|
22
|
+
try {
|
|
23
|
+
var hex = localStorage.getItem('ccsm.accent');
|
|
24
|
+
if (!/^#[0-9a-fA-F]{6}$/.test(hex || '')) return;
|
|
25
|
+
var n = parseInt(hex.slice(1), 16);
|
|
26
|
+
var r = (n >> 16) & 255, g = (n >> 8) & 255, b = n & 255;
|
|
27
|
+
var toHex = function (v) { v = Math.max(0, Math.min(255, Math.round(v))); var s = v.toString(16); return s.length < 2 ? '0' + s : s; };
|
|
28
|
+
var mix = function (t) { return '#' + toHex(r * t + 255 * (1 - t)) + toHex(g * t + 255 * (1 - t)) + toHex(b * t + 255 * (1 - t)); };
|
|
29
|
+
var darken = function (a) { return '#' + toHex(r * (1 - a)) + toHex(g * (1 - a)) + toHex(b * (1 - a)); };
|
|
30
|
+
var bg = mix(0.04);
|
|
31
|
+
var root = document.documentElement.style;
|
|
32
|
+
root.setProperty('--accent', hex);
|
|
33
|
+
root.setProperty('--accent-deep', darken(0.2));
|
|
34
|
+
root.setProperty('--accent-soft', 'rgba(' + r + ',' + g + ',' + b + ',0.10)');
|
|
35
|
+
root.setProperty('--accent-softer', 'rgba(' + r + ',' + g + ',' + b + ',0.04)');
|
|
36
|
+
root.setProperty('--bg', bg);
|
|
37
|
+
root.setProperty('--sidebar-bg', bg);
|
|
38
|
+
root.setProperty('--sidebar-hover', mix(0.10));
|
|
39
|
+
root.setProperty('--sidebar-active', mix(0.15));
|
|
40
|
+
root.setProperty('--border', mix(0.15));
|
|
41
|
+
root.setProperty('--border-soft', mix(0.12));
|
|
42
|
+
root.setProperty('--border-strong', mix(0.25));
|
|
43
|
+
root.setProperty('--ui-bg', mix(0.10));
|
|
44
|
+
var meta = document.querySelector('meta[name="theme-color"]');
|
|
45
|
+
if (meta) meta.setAttribute('content', bg);
|
|
46
|
+
} catch (_) {}
|
|
47
|
+
})();
|
|
48
|
+
</script>
|
|
17
49
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
18
50
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
19
51
|
<link
|
|
20
52
|
rel="stylesheet"
|
|
21
|
-
href="https://fonts.googleapis.com/css2?family=Geist:wght@300..700&family=JetBrains+Mono:wght@400..600&display=swap"
|
|
53
|
+
href="https://fonts.googleapis.com/css2?family=Geist:wght@300..700&family=Geist+Mono:wght@400..600&family=JetBrains+Mono:wght@400..600&display=swap"
|
|
22
54
|
/>
|
|
23
55
|
<link rel="stylesheet" href="./css/tokens.css" />
|
|
24
56
|
<link rel="stylesheet" href="./css/base.css" />
|
|
@@ -39,6 +71,7 @@
|
|
|
39
71
|
"imports": {
|
|
40
72
|
"preact": "https://esm.sh/preact@10.27.0",
|
|
41
73
|
"preact/hooks": "https://esm.sh/preact@10.27.0/hooks",
|
|
74
|
+
"preact/compat": "https://esm.sh/preact@10.27.0/compat",
|
|
42
75
|
"@preact/signals": "https://esm.sh/@preact/signals@1.3.2?deps=preact@10.27.0",
|
|
43
76
|
"htm": "https://esm.sh/htm@3.1.1",
|
|
44
77
|
"@xterm/xterm": "https://esm.sh/@xterm/xterm@5.5.0",
|
package/public/js/api.js
CHANGED
|
@@ -16,62 +16,200 @@ export async function api(method, url, body) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export async function loadConfig() {
|
|
19
|
-
const [cfg,
|
|
19
|
+
const [cfg, caps] = await Promise.all([
|
|
20
20
|
api('GET', '/api/config'),
|
|
21
|
-
api('GET', '/api/terminals'),
|
|
22
21
|
api('GET', '/api/capabilities').catch(() => ({ webTerminal: false })),
|
|
23
22
|
]);
|
|
24
23
|
S.config.value = cfg;
|
|
25
|
-
S.terminals.value = terms.terminals;
|
|
26
24
|
S.capabilities.value = caps;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// Update an existing CLI by id. patch is shallow-merged into the record.
|
|
28
|
+
export async function updateCli(id, patch) {
|
|
29
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
30
|
+
const target = (cfg.clis || []).find((c) => c.id === id);
|
|
31
|
+
// Built-in CLIs lock down identity-defining fields. UI already greys these
|
|
32
|
+
// out; we belt-and-braces here so a tampered request from elsewhere
|
|
33
|
+
// can't change them either.
|
|
34
|
+
if (target?.builtin) {
|
|
35
|
+
delete patch.command;
|
|
36
|
+
delete patch.id;
|
|
37
|
+
delete patch.builtin;
|
|
38
|
+
}
|
|
39
|
+
const toArr = (v, fallback) => Array.isArray(v) ? v :
|
|
40
|
+
typeof v === 'string' ? v.split(/\s+/).filter(Boolean) : fallback;
|
|
41
|
+
const next = {
|
|
42
|
+
...cfg,
|
|
43
|
+
clis: (cfg.clis || []).map((c) => c.id === id ? {
|
|
44
|
+
...c, ...patch,
|
|
45
|
+
args: toArr(patch.args, c.args),
|
|
46
|
+
resumeArgs: toArr(patch.resumeArgs, c.resumeArgs || []),
|
|
47
|
+
shell: ['direct', 'pwsh', 'cmd'].includes(patch.shell ?? c.shell) ? (patch.shell ?? c.shell) : 'direct',
|
|
48
|
+
} : c),
|
|
49
|
+
};
|
|
50
|
+
const saved = await api('PUT', '/api/config', next);
|
|
51
|
+
S.config.value = saved;
|
|
52
|
+
return id;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function deleteCli(id) {
|
|
56
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
57
|
+
const target = (cfg.clis || []).find((c) => c.id === id);
|
|
58
|
+
if (target?.builtin) throw new Error(`"${target.name}" is built-in and can't be deleted`);
|
|
59
|
+
const clis = (cfg.clis || []).filter((c) => c.id !== id);
|
|
60
|
+
if (clis.length === 0) throw new Error('cannot delete the last CLI');
|
|
61
|
+
const next = { ...cfg, clis };
|
|
62
|
+
if (next.defaultCliId === id) next.defaultCliId = clis[0].id;
|
|
63
|
+
const saved = await api('PUT', '/api/config', next);
|
|
64
|
+
S.config.value = saved;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function updateRepo(name, patch) {
|
|
68
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
69
|
+
const next = {
|
|
70
|
+
...cfg,
|
|
71
|
+
repos: (cfg.repos || []).map((r) => r.name === name ? {
|
|
72
|
+
...r,
|
|
73
|
+
name: (patch.name ?? r.name).trim(),
|
|
74
|
+
url: (patch.url ?? r.url).trim(),
|
|
75
|
+
defaultSelected: patch.defaultSelected ?? r.defaultSelected,
|
|
76
|
+
} : r),
|
|
77
|
+
};
|
|
78
|
+
const saved = await api('PUT', '/api/config', next);
|
|
79
|
+
S.config.value = saved;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function deleteRepo(name) {
|
|
83
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
84
|
+
const next = { ...cfg, repos: (cfg.repos || []).filter((r) => r.name !== name) };
|
|
85
|
+
const saved = await api('PUT', '/api/config', next);
|
|
86
|
+
S.config.value = saved;
|
|
34
87
|
}
|
|
35
88
|
|
|
36
|
-
export async function
|
|
37
|
-
await api('
|
|
38
|
-
await
|
|
89
|
+
export async function setDefaultCli(id) {
|
|
90
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
91
|
+
const saved = await api('PUT', '/api/config', { ...cfg, defaultCliId: id });
|
|
92
|
+
S.config.value = saved;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Add a new CLI to config.clis and return its id. Generates a fresh id
|
|
96
|
+
// from the command name + an integer suffix when collisions exist.
|
|
97
|
+
export async function createCli({ name, command, args, resumeArgs, shell, type }) {
|
|
98
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
99
|
+
const base = (name || command || 'cli').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'cli';
|
|
100
|
+
let id = base, n = 1;
|
|
101
|
+
while ((cfg.clis || []).some((c) => c.id === id)) { id = `${base}-${++n}`; }
|
|
102
|
+
const toArr = (v) => Array.isArray(v) ? v : (typeof v === 'string' ? v.split(/\s+/).filter(Boolean) : []);
|
|
103
|
+
const next = {
|
|
104
|
+
...cfg,
|
|
105
|
+
clis: [...(cfg.clis || []), {
|
|
106
|
+
id,
|
|
107
|
+
name: (name || command || id).trim(),
|
|
108
|
+
command: (command || '').trim(),
|
|
109
|
+
args: toArr(args),
|
|
110
|
+
resumeArgs: toArr(resumeArgs),
|
|
111
|
+
shell: ['direct', 'pwsh', 'cmd'].includes(shell) ? shell : 'direct',
|
|
112
|
+
type: ['claude', 'codex', 'other'].includes(type) ? type : 'other',
|
|
113
|
+
}],
|
|
114
|
+
};
|
|
115
|
+
const saved = await api('PUT', '/api/config', next);
|
|
116
|
+
S.config.value = saved;
|
|
117
|
+
return id;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Add a new repo to config.repos. Repos are addressed by name (which must
|
|
121
|
+
// be unique). Returns the name on success, throws on duplicate.
|
|
122
|
+
export async function createRepo({ name, url, defaultSelected }) {
|
|
123
|
+
const cfg = S.config.value || (await api('GET', '/api/config'));
|
|
124
|
+
const cleanName = (name || '').trim();
|
|
125
|
+
const cleanUrl = (url || '').trim();
|
|
126
|
+
if (!cleanName) throw new Error('repo name required');
|
|
127
|
+
if (!cleanUrl) throw new Error('repo url required');
|
|
128
|
+
if ((cfg.repos || []).some((r) => r.name === cleanName)) {
|
|
129
|
+
throw new Error(`repo "${cleanName}" already exists`);
|
|
130
|
+
}
|
|
131
|
+
const next = {
|
|
132
|
+
...cfg,
|
|
133
|
+
repos: [...(cfg.repos || []), {
|
|
134
|
+
name: cleanName,
|
|
135
|
+
url: cleanUrl,
|
|
136
|
+
defaultSelected: !!defaultSelected,
|
|
137
|
+
}],
|
|
138
|
+
};
|
|
139
|
+
const saved = await api('PUT', '/api/config', next);
|
|
140
|
+
S.config.value = saved;
|
|
141
|
+
return cleanName;
|
|
39
142
|
}
|
|
40
143
|
|
|
41
144
|
export async function loadSessions() {
|
|
42
145
|
const r = await api('GET', '/api/sessions');
|
|
43
|
-
S.sessions.value = r.sessions;
|
|
146
|
+
S.sessions.value = r.sessions || [];
|
|
147
|
+
try { localStorage.setItem('ccsm.sessions-cache', JSON.stringify(S.sessions.value)); } catch {}
|
|
44
148
|
}
|
|
45
149
|
|
|
46
|
-
export async function
|
|
47
|
-
const r = await api('GET',
|
|
48
|
-
S.
|
|
49
|
-
S.
|
|
50
|
-
S.recentLimit.value = r.limit || S.recentLimit.value;
|
|
51
|
-
S.recentOffset.value = r.offset || 0;
|
|
150
|
+
export async function loadFolders() {
|
|
151
|
+
const r = await api('GET', '/api/folders');
|
|
152
|
+
S.folders.value = (r.folders || []).sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
153
|
+
try { localStorage.setItem('ccsm.folders-cache', JSON.stringify(S.folders.value)); } catch {}
|
|
52
154
|
}
|
|
53
155
|
|
|
54
|
-
export async function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (const f of r.favorites || []) map[f.sessionId] = f;
|
|
59
|
-
S.favorites.value = map;
|
|
60
|
-
} catch (e) { /* ignore — endpoint may not exist on older servers */ }
|
|
156
|
+
export async function createFolder(name) {
|
|
157
|
+
const r = await api('POST', '/api/folders', { name });
|
|
158
|
+
await loadFolders();
|
|
159
|
+
return r.folder;
|
|
61
160
|
}
|
|
62
161
|
|
|
63
|
-
export async function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
162
|
+
export async function renameFolder(id, name) {
|
|
163
|
+
const r = await api('PUT', `/api/folders/${id}`, { name });
|
|
164
|
+
await loadFolders();
|
|
165
|
+
return r.folder;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function deleteFolder(id) {
|
|
169
|
+
await api('DELETE', `/api/folders/${id}`);
|
|
170
|
+
await Promise.all([loadFolders(), loadSessions()]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function reorderFolders(ids) {
|
|
174
|
+
const r = await api('POST', '/api/folders/reorder', { ids });
|
|
175
|
+
await loadFolders();
|
|
176
|
+
return r.folders;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function setSessionFolder(sessionId, folderId) {
|
|
180
|
+
await api('PUT', `/api/sessions/${sessionId}`, { folderId: folderId || null });
|
|
181
|
+
await loadSessions();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function setSessionTitle(sessionId, title) {
|
|
185
|
+
await api('PUT', `/api/sessions/${sessionId}`, { title });
|
|
186
|
+
await loadSessions();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export async function deleteSession(sessionId) {
|
|
190
|
+
await api('DELETE', `/api/sessions/${sessionId}`);
|
|
191
|
+
await loadSessions();
|
|
68
192
|
}
|
|
69
193
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
194
|
+
// Per-session in-flight resume promise. Sidebar.onClick and the
|
|
195
|
+
// SessionsPage auto-resume effect can both fire for the same exited
|
|
196
|
+
// session in the same tick (clicking an exited row mounts SessionsPage
|
|
197
|
+
// which runs its effect AND awaits Sidebar's own POST). Without this
|
|
198
|
+
// dedup the backend gets two concurrent /resume requests and may spawn
|
|
199
|
+
// two PTYs against the same record. Cleared on resolve/reject.
|
|
200
|
+
const resumeInFlight = new Map(); // sessionId → Promise
|
|
201
|
+
|
|
202
|
+
export function resumeSession(sessionId) {
|
|
203
|
+
const cached = resumeInFlight.get(sessionId);
|
|
204
|
+
if (cached) return cached;
|
|
205
|
+
const p = (async () => {
|
|
206
|
+
const r = await api('POST', `/api/sessions/${sessionId}/resume`);
|
|
207
|
+
await loadSessions();
|
|
208
|
+
return r.launched;
|
|
209
|
+
})();
|
|
210
|
+
resumeInFlight.set(sessionId, p);
|
|
211
|
+
p.finally(() => { resumeInFlight.delete(sessionId); });
|
|
212
|
+
return p;
|
|
75
213
|
}
|
|
76
214
|
|
|
77
215
|
export async function loadWorkspaces() {
|
|
@@ -79,14 +217,33 @@ export async function loadWorkspaces() {
|
|
|
79
217
|
S.workspaces.value = r.workspaces;
|
|
80
218
|
}
|
|
81
219
|
|
|
220
|
+
export async function deleteWorkspace(name) {
|
|
221
|
+
await api('DELETE', `/api/workspaces/${encodeURIComponent(name)}`);
|
|
222
|
+
}
|
|
223
|
+
|
|
82
224
|
export async function refreshAll() {
|
|
83
225
|
await Promise.all([
|
|
84
|
-
loadSessions(),
|
|
85
|
-
|
|
226
|
+
loadSessions(),
|
|
227
|
+
loadFolders(),
|
|
228
|
+
loadWorkspaces(),
|
|
86
229
|
]);
|
|
87
230
|
S.lastRefreshAt.value = Date.now();
|
|
88
231
|
}
|
|
89
232
|
|
|
233
|
+
// List existing CLI sessions discovered on disk for a given cli type.
|
|
234
|
+
// Returns array of { cliType, cliSessionId, cwd, mtime, summary, adopted }.
|
|
235
|
+
export async function listLocalCliSessions(cliType) {
|
|
236
|
+
const r = await api('GET', `/api/cli-sessions/${cliType}`);
|
|
237
|
+
return r.sessions || [];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Adopt an existing upstream CLI session into ccsm. Returns the created
|
|
241
|
+
// (or existing) persistedSessions record.
|
|
242
|
+
export async function adoptSession({ cliId, cliSessionId, cwd, title, folderId }) {
|
|
243
|
+
const r = await api('POST', '/api/sessions/adopt', { cliId, cliSessionId, cwd, title, folderId });
|
|
244
|
+
return r;
|
|
245
|
+
}
|
|
246
|
+
|
|
90
247
|
export async function pollHealth() {
|
|
91
248
|
const ctrl = new AbortController();
|
|
92
249
|
const t = setTimeout(() => ctrl.abort(), 3000);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// "Import existing session" modal. Browses sessions discovered on disk
|
|
2
|
+
// for claude / codex / copilot, lets the user pick one, choose which
|
|
3
|
+
// configured CLI it should be tied to, and adopts it — a ccsm
|
|
4
|
+
// persistedSessions record is created with the upstream session id
|
|
5
|
+
// pre-filled so clicking it later runs `<cli> --resume <id>` (via
|
|
6
|
+
// cli.resumeIdArgs).
|
|
7
|
+
//
|
|
8
|
+
// Props:
|
|
9
|
+
// onClose() — close request
|
|
10
|
+
// onAdopted(sessionId) — fires after a successful adopt with
|
|
11
|
+
// the new (or pre-existing) record id
|
|
12
|
+
//
|
|
13
|
+
// Shows a row of cli-type tabs at the top. Each tab loads on first
|
|
14
|
+
// click. Adopted rows are greyed out and labelled.
|
|
15
|
+
|
|
16
|
+
import { html } from '../html.js';
|
|
17
|
+
import { useState, useEffect } from 'preact/hooks';
|
|
18
|
+
import { Modal } from './Modal.js';
|
|
19
|
+
import { config } from '../state.js';
|
|
20
|
+
import { listLocalCliSessions, adoptSession } from '../api.js';
|
|
21
|
+
import { setToast } from '../toast.js';
|
|
22
|
+
import { IconForCliType, IconClaudeColor, IconCodexColor, IconCopilotColor } from '../icons.js';
|
|
23
|
+
|
|
24
|
+
const TABS = [
|
|
25
|
+
{ type: 'claude', label: 'Claude', Icon: IconClaudeColor },
|
|
26
|
+
{ type: 'codex', label: 'Codex', Icon: IconCodexColor },
|
|
27
|
+
{ type: 'copilot', label: 'Copilot', Icon: IconCopilotColor },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export function AdoptModal({ onClose, onAdopted }) {
|
|
31
|
+
const [tab, setTab] = useState('claude');
|
|
32
|
+
// cache per tab so flipping back is instant
|
|
33
|
+
const [cache, setCache] = useState({}); // { claude: {loading, error, items} }
|
|
34
|
+
const [adopting, setAdopting] = useState(null); // cliSessionId being adopted
|
|
35
|
+
|
|
36
|
+
const load = async (type, { force = false } = {}) => {
|
|
37
|
+
if (!force && cache[type] && !cache[type].error) return;
|
|
38
|
+
setCache((c) => ({ ...c, [type]: { loading: true, items: [], error: null } }));
|
|
39
|
+
try {
|
|
40
|
+
const items = await listLocalCliSessions(type);
|
|
41
|
+
setCache((c) => ({ ...c, [type]: { loading: false, items, error: null } }));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
setCache((c) => ({ ...c, [type]: { loading: false, items: [], error: e.message } }));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useEffect(() => { load(tab); /* eslint-disable-next-line */ }, [tab]);
|
|
48
|
+
|
|
49
|
+
const cfg = config.value || {};
|
|
50
|
+
const clis = cfg.clis || [];
|
|
51
|
+
// Pick first matching configured CLI for the current upstream type; fall
|
|
52
|
+
// back to the configured default. Users can change per-row via the select.
|
|
53
|
+
const defaultCliFor = (type) => {
|
|
54
|
+
const match = clis.find((c) => c.type === type);
|
|
55
|
+
if (match) return match.id;
|
|
56
|
+
return cfg.defaultCliId || clis[0]?.id || '';
|
|
57
|
+
};
|
|
58
|
+
const [chosenCli, setChosenCli] = useState({}); // cliSessionId → cli id override
|
|
59
|
+
|
|
60
|
+
const adopt = async (item) => {
|
|
61
|
+
const cliId = chosenCli[item.cliSessionId] || defaultCliFor(item.cliType);
|
|
62
|
+
if (!cliId) { setToast('configure a CLI first', 'error'); return; }
|
|
63
|
+
setAdopting(item.cliSessionId);
|
|
64
|
+
try {
|
|
65
|
+
const r = await adoptSession({
|
|
66
|
+
cliId,
|
|
67
|
+
cliSessionId: item.cliSessionId,
|
|
68
|
+
cwd: item.cwd,
|
|
69
|
+
title: item.summary || '',
|
|
70
|
+
});
|
|
71
|
+
if (r.alreadyAdopted) {
|
|
72
|
+
setToast('already in ccsm — opened existing record');
|
|
73
|
+
} else {
|
|
74
|
+
setToast(`imported · ${item.cliSessionId.slice(0, 8)}…`);
|
|
75
|
+
}
|
|
76
|
+
// Mark adopted in the cache so the UI updates instantly.
|
|
77
|
+
setCache((c) => ({
|
|
78
|
+
...c,
|
|
79
|
+
[tab]: c[tab] ? {
|
|
80
|
+
...c[tab],
|
|
81
|
+
items: c[tab].items.map((x) => x.cliSessionId === item.cliSessionId
|
|
82
|
+
? { ...x, adopted: true } : x),
|
|
83
|
+
} : c[tab],
|
|
84
|
+
}));
|
|
85
|
+
onAdopted?.(r.session?.id);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
setToast(e.message, 'error');
|
|
88
|
+
} finally {
|
|
89
|
+
setAdopting(null);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const state = cache[tab] || { loading: true, items: [], error: null };
|
|
94
|
+
|
|
95
|
+
return html`
|
|
96
|
+
<${Modal} title="Import existing session" onClose=${onClose} width=${640}>
|
|
97
|
+
<div class="adopt-tabs">
|
|
98
|
+
${TABS.map((t) => html`
|
|
99
|
+
<button type="button"
|
|
100
|
+
class=${`adopt-tab${tab === t.type ? ' is-active' : ''}`}
|
|
101
|
+
onClick=${() => setTab(t.type)}>
|
|
102
|
+
<span class="adopt-tab-icon"><${t.Icon} /></span>
|
|
103
|
+
<span>${t.label}</span>
|
|
104
|
+
</button>`)}
|
|
105
|
+
<button type="button" class="action subtle adopt-refresh"
|
|
106
|
+
title="Rescan"
|
|
107
|
+
onClick=${() => load(tab, { force: true })}>Refresh</button>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<div class="adopt-body">
|
|
111
|
+
${state.loading ? html`
|
|
112
|
+
<div class="adopt-empty">Scanning…</div>
|
|
113
|
+
` : state.error ? html`
|
|
114
|
+
<div class="adopt-empty adopt-error">${state.error}</div>
|
|
115
|
+
` : state.items.length === 0 ? html`
|
|
116
|
+
<div class="adopt-empty">No ${tab} sessions found on this machine.</div>
|
|
117
|
+
` : html`
|
|
118
|
+
<ul class="adopt-list">
|
|
119
|
+
${state.items.map((it) => html`
|
|
120
|
+
<li class=${`adopt-item${it.adopted ? ' is-adopted' : ''}`}
|
|
121
|
+
key=${it.cliSessionId}>
|
|
122
|
+
<div class="adopt-main">
|
|
123
|
+
<div class="adopt-title">
|
|
124
|
+
${it.summary || html`<span class="ink-faint">(no preview)</span>`}
|
|
125
|
+
</div>
|
|
126
|
+
<div class="adopt-meta mono">
|
|
127
|
+
${it.cwd}
|
|
128
|
+
<span class="adopt-sep">·</span>
|
|
129
|
+
${relTime(it.mtime)}
|
|
130
|
+
<span class="adopt-sep">·</span>
|
|
131
|
+
${it.cliSessionId.slice(0, 8)}…
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
<div class="adopt-actions">
|
|
135
|
+
${clis.length > 1 ? html`
|
|
136
|
+
<select class="adopt-cli-select"
|
|
137
|
+
value=${chosenCli[it.cliSessionId] || defaultCliFor(it.cliType)}
|
|
138
|
+
onChange=${(e) => setChosenCli((m) => ({ ...m, [it.cliSessionId]: e.target.value }))}
|
|
139
|
+
disabled=${it.adopted}>
|
|
140
|
+
${clis.map((c) => html`<option value=${c.id}>${c.name}</option>`)}
|
|
141
|
+
</select>
|
|
142
|
+
` : null}
|
|
143
|
+
${it.adopted ? html`
|
|
144
|
+
<span class="adopt-badge">Imported</span>
|
|
145
|
+
` : html`
|
|
146
|
+
<button type="button" class="action primary adopt-btn"
|
|
147
|
+
disabled=${adopting === it.cliSessionId}
|
|
148
|
+
onClick=${() => adopt(it)}>
|
|
149
|
+
${adopting === it.cliSessionId ? 'Importing…' : 'Import'}
|
|
150
|
+
</button>
|
|
151
|
+
`}
|
|
152
|
+
</div>
|
|
153
|
+
</li>`)}
|
|
154
|
+
</ul>
|
|
155
|
+
`}
|
|
156
|
+
</div>
|
|
157
|
+
</${Modal}>`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function relTime(ms) {
|
|
161
|
+
if (!ms) return '';
|
|
162
|
+
const d = Date.now() - ms;
|
|
163
|
+
const s = Math.round(d / 1000);
|
|
164
|
+
if (s < 60) return `${s}s ago`;
|
|
165
|
+
const m = Math.round(s / 60);
|
|
166
|
+
if (m < 60) return `${m}m ago`;
|
|
167
|
+
const h = Math.round(m / 60);
|
|
168
|
+
if (h < 48) return `${h}h ago`;
|
|
169
|
+
const days = Math.round(h / 24);
|
|
170
|
+
return `${days}d ago`;
|
|
171
|
+
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { html } from '../html.js';
|
|
2
2
|
import { activeTab } from '../state.js';
|
|
3
3
|
import { Sidebar } from './Sidebar.js';
|
|
4
|
-
import { PageHead } from './PageHead.js';
|
|
5
|
-
import { Footer } from './Footer.js';
|
|
6
4
|
import { Toast } from './Toast.js';
|
|
7
|
-
import { Fab } from './Fab.js';
|
|
8
|
-
import { NewSessionModal } from './NewSessionModal.js';
|
|
9
5
|
import { DialogHost } from './DialogHost.js';
|
|
10
6
|
import { OfflineBanner } from './OfflineBanner.js';
|
|
11
7
|
import { SessionsPage } from '../pages/SessionsPage.js';
|
|
12
8
|
import { LaunchPage } from '../pages/LaunchPage.js';
|
|
13
|
-
import { TerminalsPage } from '../pages/TerminalsPage.js';
|
|
14
9
|
import { ConfigurePage } from '../pages/ConfigurePage.js';
|
|
15
10
|
import { AboutPage } from '../pages/AboutPage.js';
|
|
16
11
|
|
|
@@ -26,19 +21,14 @@ export function App() {
|
|
|
26
21
|
<div class="app">
|
|
27
22
|
<${Sidebar} />
|
|
28
23
|
<main class="main">
|
|
29
|
-
<${PageHead} />
|
|
30
|
-
<${OfflineBanner} />
|
|
31
24
|
<div class="content">
|
|
32
25
|
${tab === 'sessions' ? html`<${Panel} name="sessions"><${SessionsPage} /></${Panel}>` : null}
|
|
33
26
|
${tab === 'launch' ? html`<${Panel} name="launch"><${LaunchPage} /></${Panel}>` : null}
|
|
34
|
-
${tab === 'terminals' ? html`<${Panel} name="terminals"><${TerminalsPage} /></${Panel}>` : null}
|
|
35
27
|
${tab === 'configure' ? html`<${Panel} name="configure"><${ConfigurePage} /></${Panel}>` : null}
|
|
36
28
|
${tab === 'about' ? html`<${Panel} name="about"><${AboutPage} /></${Panel}>` : null}
|
|
37
29
|
</div>
|
|
38
|
-
<${Footer} />
|
|
39
30
|
</main>
|
|
40
|
-
<${
|
|
41
|
-
<${NewSessionModal} />
|
|
31
|
+
<${OfflineBanner} />
|
|
42
32
|
<${Toast} />
|
|
43
33
|
<${DialogHost} />
|
|
44
34
|
</div>`;
|