@bakapiano/ccsm 0.22.5 → 0.22.7

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.
Files changed (59) hide show
  1. package/CLAUDE.md +538 -538
  2. package/README.md +189 -189
  3. package/bin/ccsm.js +235 -235
  4. package/lib/cliActivity.js +139 -139
  5. package/lib/codexSeed.js +183 -183
  6. package/lib/config.js +279 -274
  7. package/lib/devices.js +229 -229
  8. package/lib/folders.js +124 -124
  9. package/lib/localCliSessions.js +519 -519
  10. package/lib/persistedSessions.js +129 -129
  11. package/lib/tunnel.js +621 -621
  12. package/lib/webTerminal.js +225 -225
  13. package/lib/workspace.js +233 -233
  14. package/package.json +57 -57
  15. package/public/css/base.css +99 -99
  16. package/public/css/cards.css +183 -183
  17. package/public/css/feedback.css +504 -504
  18. package/public/css/forms.css +453 -453
  19. package/public/css/layout.css +177 -176
  20. package/public/css/modal.css +190 -190
  21. package/public/css/responsive.css +176 -176
  22. package/public/css/sidebar.css +707 -707
  23. package/public/css/terminals.css +547 -553
  24. package/public/css/tokens.css +81 -81
  25. package/public/css/wco.css +196 -196
  26. package/public/css/widgets.css +2725 -2725
  27. package/public/index.html +152 -152
  28. package/public/js/api.js +371 -371
  29. package/public/js/backend.js +149 -149
  30. package/public/js/components/App.js +73 -73
  31. package/public/js/components/DirectoryPicker.js +203 -203
  32. package/public/js/components/EntityFormModal.js +153 -153
  33. package/public/js/components/Modal.js +57 -57
  34. package/public/js/components/OfflineBanner.js +67 -67
  35. package/public/js/components/PageTitleBar.js +13 -13
  36. package/public/js/components/PendingApprovalOverlay.js +128 -128
  37. package/public/js/components/Picker.js +179 -179
  38. package/public/js/components/Popover.js +55 -55
  39. package/public/js/components/RestartOverlay.js +36 -36
  40. package/public/js/components/Sidebar.js +380 -380
  41. package/public/js/components/TerminalInstance.js +28 -9
  42. package/public/js/components/XtermTerminal.js +62 -2
  43. package/public/js/components/useDragSort.js +67 -67
  44. package/public/js/dialog.js +67 -67
  45. package/public/js/icons.js +212 -212
  46. package/public/js/main.js +296 -296
  47. package/public/js/pages/AboutPage.js +90 -90
  48. package/public/js/pages/ConfigurePage.js +728 -713
  49. package/public/js/pages/LaunchPage.js +421 -421
  50. package/public/js/pages/RemotePage.js +743 -743
  51. package/public/js/pages/SessionsPage.js +73 -80
  52. package/public/js/state.js +335 -335
  53. package/scripts/dev.js +149 -149
  54. package/scripts/install.js +153 -153
  55. package/scripts/restart-helper.js +96 -96
  56. package/scripts/upgrade-helper.js +687 -687
  57. package/server.js +1820 -1807
  58. package/public/manifest.webmanifest +0 -25
  59. package/public/setup/index.html +0 -567
@@ -1,421 +1,421 @@
1
- // Launch page. ChatGPT-style centered composer with custom popover
2
- // pickers for CLI / Folder / Repos. Each picker shares the unified
3
- // PickerPanel component and can inline-create new entries.
4
-
5
- import { html } from '../html.js';
6
- import { useState, useEffect } from 'preact/hooks';
7
- import { signal } from '@preact/signals';
8
- import { config, folders, selectSession, selectTab } from '../state.js';
9
- import { createCli, createFolder, createRepo, refreshAll } from '../api.js';
10
- import { setToast } from '../toast.js';
11
- import { streamNewSession, resetProgress } from '../streaming.js';
12
- import { PageTitleBar } from '../components/PageTitleBar.js';
13
- import { ProgressList } from '../components/ProgressList.js';
14
- import { Modal } from '../components/Modal.js';
15
- import { PickerPanel } from '../components/Picker.js';
16
- import { DirectoryPicker } from '../components/DirectoryPicker.js';
17
- import { AdoptModal } from '../components/AdoptModal.js';
18
- import { BrandMark, IconTerminal, IconFolder, IconFolderOpen, IconBranch, IconChevronDown, IconForCliType, IconClaudeColor, IconCodexColor, IconCopilotColor, IconSparkle, IconWorkspace, IconArrowRight } from '../icons.js';
19
-
20
- const ROOT_ID = 'newSessionProgress';
21
- const selectedRepos = signal(new Set());
22
-
23
- // Persist the user's last Launch picks (CLI / folder / mode / cwd /
24
- // selected repos) so the form stays as they left it across reloads
25
- // and tab switches. localStorage is best-effort — any access failure
26
- // falls back silently.
27
- const LS_KEY = 'ccsm.launch-state';
28
- function loadLaunchState() {
29
- try {
30
- const raw = localStorage.getItem(LS_KEY);
31
- if (!raw) return null;
32
- const j = JSON.parse(raw);
33
- if (j && typeof j === 'object') return j;
34
- } catch {}
35
- return null;
36
- }
37
- function saveLaunchState(s) {
38
- try { localStorage.setItem(LS_KEY, JSON.stringify(s)); } catch {}
39
- }
40
-
41
- function initRepoSelection(repos, saved) {
42
- const valid = new Set(repos.map((r) => r.name));
43
- const sel = new Set();
44
- // Start from the persisted selection (last-used picks), keeping only
45
- // repos that still exist.
46
- if (saved && Array.isArray(saved.repos)) {
47
- for (const n of saved.repos) if (valid.has(n)) sel.add(n);
48
- }
49
- // Auto-check any repo whose "pre-select on launch" default is newly
50
- // active — i.e. it wasn't a default the last time we saved. This
51
- // covers both a brand-new default repo and an existing repo the user
52
- // just flipped to default in Configure. A default the user previously
53
- // unchecked stays unchecked (it's an old default, already in
54
- // knownDefaults). With no saved knownDefaults (fresh user / old
55
- // state), every default applies.
56
- const knownDefaults = saved && Array.isArray(saved.knownDefaults)
57
- ? new Set(saved.knownDefaults) : null;
58
- for (const r of repos) {
59
- if (r.defaultSelected && (knownDefaults === null || !knownDefaults.has(r.name))) {
60
- sel.add(r.name);
61
- }
62
- }
63
- selectedRepos.value = sel;
64
- }
65
-
66
- function LaunchHero() {
67
- const cfg = config.value || {};
68
- const clis = cfg.clis || [];
69
- const repos = cfg.repos || [];
70
- const defaultCli = cfg.defaultCliId || clis[0]?.id || '';
71
- const saved = loadLaunchState();
72
-
73
- // Initial values pull from localStorage first (last-used picks),
74
- // then fall back to config defaults. cliId is validated below in
75
- // the useEffect once `clis` arrives.
76
- const [cliId, setCliId] = useState(saved?.cliId || defaultCli);
77
- const [folderId, setFolderId] = useState(saved?.folderId || '');
78
- const [mode, setMode] = useState(saved?.mode === 'cwd' ? 'cwd' : 'auto');
79
- const [cwd, setCwd] = useState(saved?.cwd || ''); // only used when mode === 'cwd'
80
- const [busy, setBusy] = useState(false);
81
- const [result, setResult] = useState('');
82
- const [openPicker, setOpenPicker] = useState(null); // 'cli' | 'folder' | 'workdir' | null
83
- const [adoptOpen, setAdoptOpen] = useState(false);
84
-
85
- // If config arrives after first render (cliId === '') OR the saved
86
- // cli was removed, snap to the current default.
87
- useEffect(() => {
88
- if (!clis.length) return;
89
- if (!cliId || !clis.find((c) => c.id === cliId)) {
90
- setCliId(defaultCli);
91
- }
92
- }, [defaultCli, clis.length]);
93
-
94
- // Validate the persisted folder id against the live folders list
95
- // — folders deleted between sessions snap back to "no folder".
96
- useEffect(() => {
97
- if (!folderId) return;
98
- if (!folders.value.find((f) => f.id === folderId)) setFolderId('');
99
- }, [folderId, folders.value.length]);
100
-
101
- // Persist every change. JSON-stringifying a Set isn't useful, so
102
- // we materialize selectedRepos to an array here. knownDefaults records
103
- // which repos were marked "pre-select" at save time so
104
- // initRepoSelection can tell a newly-flipped default apart from one the
105
- // user deliberately unchecked.
106
- useEffect(() => {
107
- saveLaunchState({
108
- cliId, folderId, mode, cwd,
109
- repos: [...selectedRepos.value],
110
- knownDefaults: repos.filter((r) => r.defaultSelected).map((r) => r.name),
111
- });
112
- }, [cliId, folderId, mode, cwd, selectedRepos.value]);
113
-
114
-
115
- const sig = repos.map((r) => r.name + ':' + r.defaultSelected).join('|');
116
- useStateOnce(sig, () => initRepoSelection(repos, saved));
117
-
118
- const cli = clis.find((c) => c.id === cliId) || clis[0];
119
- const folder = folders.value.find((f) => f.id === folderId);
120
-
121
- const toggleRepo = (name, on) => {
122
- const next = new Set(selectedRepos.value);
123
- if (on) next.add(name); else next.delete(name);
124
- selectedRepos.value = next;
125
- };
126
-
127
- const onLaunch = async () => {
128
- const useCwd = mode === 'cwd' && cwd;
129
- const chosen = useCwd ? [] : [...selectedRepos.value];
130
- setBusy(true);
131
- setResult('');
132
- resetProgress(chosen, ROOT_ID);
133
- try {
134
- const final = await streamNewSession(
135
- {
136
- repos: chosen,
137
- cwd: useCwd ? cwd : undefined,
138
- cliId: cliId || undefined,
139
- folderId: folderId || undefined,
140
- },
141
- {
142
- progressRootId: ROOT_ID,
143
- onMeta: (ev) => {
144
- if (ev.type === 'workspace') {
145
- setResult(`workspace · ${ev.workspace.path}${ev.created ? ' · newly created' : ''}`);
146
- } else if (ev.type === 'launched') {
147
- setResult(`launched · session ${ev.launched.id}`);
148
- }
149
- },
150
- },
151
- );
152
- if (final.success && final.launched) {
153
- setToast(`launched · ${final.workspace.name}`);
154
- await refreshAll();
155
- selectSession(final.launched.id);
156
- selectTab('sessions');
157
- } else if (!final.success) {
158
- setResult(`error · ${final.error}`);
159
- setToast(final.error || 'launch failed', 'error');
160
- }
161
- } catch (e) {
162
- setResult(`error · ${e.message}`);
163
- setToast(e.message, 'error');
164
- } finally {
165
- setBusy(false);
166
- }
167
- };
168
-
169
- const close = () => setOpenPicker(null);
170
-
171
- // --- CLI picker config -----------------------------------------------
172
- const cliItems = clis.map((c) => {
173
- const Icon = IconForCliType(c.type);
174
- return {
175
- id: c.id,
176
- icon: html`<${Icon} />`,
177
- label: c.name,
178
- meta: `${c.command}${c.shell && c.shell !== 'direct' ? ' · ' + c.shell : ''}`,
179
- };
180
- });
181
- const cliCreateFields = [
182
- { key: 'type', label: 'Type', type: 'iconRadio', default: 'other', options: [
183
- { value: 'claude', label: 'Claude CLI', icon: html`<${IconClaudeColor} />` },
184
- { value: 'codex', label: 'Codex CLI', icon: html`<${IconCodexColor} />` },
185
- { value: 'copilot', label: 'GitHub Copilot', icon: html`<${IconCopilotColor} />` },
186
- { value: 'other', label: 'Other', icon: html`<${IconTerminal} />` },
187
- ],
188
- onChange: (v, next) => {
189
- const presets = { claude: { command: 'claude', resumeArgs: '--continue', resumeIdArgs: '--resume <id>', name: 'Claude Code' },
190
- codex: { command: 'codex', resumeArgs: 'resume --last', resumeIdArgs: 'resume <id>', name: 'OpenAI Codex' },
191
- copilot: { command: 'copilot', resumeArgs: '--continue', resumeIdArgs: '--session-id <id>', name: 'GitHub Copilot' },
192
- other: {} }[v] || {};
193
- const patch = {};
194
- if (presets.resumeArgs != null) patch.resumeArgs = presets.resumeArgs;
195
- if (presets.resumeIdArgs != null) patch.resumeIdArgs = presets.resumeIdArgs;
196
- if (!next.command || !next.command.trim()) patch.command = presets.command || '';
197
- if (!next.name || !next.name.trim()) patch.name = presets.name || '';
198
- return patch;
199
- },
200
- },
201
- { key: 'name', label: 'Name', placeholder: 'My CLI', required: true },
202
- { key: 'command', label: 'Command', mono: true, placeholder: 'claude / codex / ...', required: true },
203
- { key: 'args', label: 'Args (space-separated)', mono: true, placeholder: '' },
204
- { key: 'resumeArgs', label: 'Resume args (fallback)', mono: true, placeholder: '--continue',
205
- hint: 'Used when ccsm has no captured upstream session id.' },
206
- { key: 'resumeIdArgs', label: 'Resume by id args', mono: true, placeholder: '--resume <id>',
207
- hint: 'Use <id> as the placeholder for the captured upstream session UUID.' },
208
- { key: 'shell', label: 'Shell', type: 'select', default: 'direct', options: [
209
- { value: 'direct', label: 'direct (real .exe / .cmd)' },
210
- { value: 'pwsh', label: 'pwsh (PowerShell aliases & functions)' },
211
- { value: 'cmd', label: 'cmd (doskey)' },
212
- ] },
213
- ];
214
-
215
- // --- Folder picker config --------------------------------------------
216
- const folderItems = [
217
- { id: '', label: 'Unsorted', meta: 'no folder', undraggable: true, icon: html`<${IconFolderOpen} />` },
218
- ...folders.value.map((f) => ({ id: f.id, label: f.name, icon: html`<${IconFolder} />` })),
219
- ];
220
- const folderCreateFields = [
221
- { key: 'name', label: 'Folder name', placeholder: 'Work / Personal / ...', autoFocus: true, required: true },
222
- ];
223
-
224
- // --- Repo picker config ----------------------------------------------
225
- const repoItems = repos.map((r) => ({
226
- id: r.name,
227
- label: r.name,
228
- meta: r.url,
229
- }));
230
- const repoCreateFields = [
231
- { key: 'name', label: 'Name', placeholder: 'my-repo', autoFocus: true, required: true },
232
- { key: 'url', label: 'URL', mono: true, placeholder: 'https://github.com/me/foo.git', required: true },
233
- ];
234
-
235
- const selectedRepoCount = selectedRepos.value.size;
236
-
237
- // Label + title for the unified workdir/repos pill.
238
- const workdirLabel = (() => {
239
- if (mode === 'cwd') return cwd ? shortenPath(cwd) : 'Pick folder…';
240
- if (selectedRepoCount === 0) return 'Auto workspace';
241
- if (selectedRepoCount === 1) return [...selectedRepos.value][0];
242
- return `Auto · ${selectedRepoCount} repos`;
243
- })();
244
- const workdirTitle = mode === 'cwd'
245
- ? (cwd ? `Working dir · ${cwd}` : 'Pick an existing folder')
246
- : (selectedRepoCount === 0
247
- ? 'Auto: a fresh workspace under workDir (no repos)'
248
- : `Auto workspace · clone ${selectedRepoCount} repo(s)`);
249
-
250
- return html`
251
- <div class="launch-hero">
252
- <div class="launch-brand">
253
- <span class="launch-brand-mark"><${BrandMark} /></span>
254
- </div>
255
- <h1 class="launch-tagline">
256
- One shell. <em>Every CLI.</em>
257
- </h1>
258
-
259
- <div class="launch-toolbar">
260
- <button type="button"
261
- class=${`pill${openPicker === 'cli' ? ' is-open' : ''}`}
262
- title="Choose CLI"
263
- onClick=${() => setOpenPicker(openPicker === 'cli' ? null : 'cli')}>
264
- <span class="pill-icon">${(() => { const I = IconForCliType(cli?.type); return html`<${I} />`; })()}</span>
265
- <span class="pill-label">${cli ? cli.name : 'Choose CLI'}</span>
266
- <span class="pill-chev"><${IconChevronDown} /></span>
267
- </button>
268
- ${openPicker === 'cli' ? html`
269
- <${Modal} title="Choose CLI" onClose=${close} width=${440}>
270
- <${PickerPanel} items=${cliItems} selectedId=${cliId}
271
- showSearch=${false}
272
- onSelect=${(id) => setCliId(id)}
273
- onCreate=${async (v) => {
274
- try {
275
- const id = await createCli(v);
276
- setToast(`created CLI · ${v.name}`);
277
- return id;
278
- } catch (e) { setToast(e.message, 'error'); throw e; }
279
- }}
280
- createLabel="New CLI" createFields=${cliCreateFields}
281
- onClose=${close} />
282
- </${Modal}>` : null}
283
-
284
- <button type="button"
285
- class=${`pill${openPicker === 'workdir' ? ' is-open' : ''}${(mode === 'cwd' && cwd) ? ' is-set' : ''}`}
286
- title=${workdirTitle}
287
- onClick=${() => setOpenPicker(openPicker === 'workdir' ? null : 'workdir')}>
288
- <span class="pill-icon"><${IconWorkspace} /></span>
289
- <span class="pill-label">${workdirLabel}</span>
290
- <span class="pill-chev"><${IconChevronDown} /></span>
291
- </button>
292
- ${openPicker === 'workdir' ? html`
293
- <${Modal} title="Working directory" onClose=${close} width=${640}
294
- footer=${html`
295
- <button type="button" class="action subtle" onClick=${close}>Cancel</button>
296
- <button type="button" class="action primary"
297
- disabled=${mode === 'cwd' && !cwd}
298
- onClick=${close}>
299
- ${mode === 'cwd' ? 'Use folder' : 'Done'}
300
- </button>`}>
301
- <div class="workdir-modal">
302
- <div class="workdir-mode-grid">
303
- <button type="button"
304
- class=${`workdir-mode-opt${mode === 'auto' ? ' is-active' : ''}`}
305
- onClick=${() => setMode('auto')}>
306
- <span class="workdir-mode-icon"><${IconSparkle} /></span>
307
- <span class="workdir-mode-name">Auto workspace</span>
308
- <span class="workdir-mode-sub">Fresh <span class="mono">ws-N</span> + clone repos</span>
309
- </button>
310
- <button type="button"
311
- class=${`workdir-mode-opt${mode === 'cwd' ? ' is-active' : ''}`}
312
- onClick=${() => setMode('cwd')}>
313
- <span class="workdir-mode-icon"><${IconFolderOpen} /></span>
314
- <span class="workdir-mode-name">Existing folder</span>
315
- <span class="workdir-mode-sub">Launch directly · no clone</span>
316
- </button>
317
- </div>
318
- <div class="workdir-detail">
319
- ${mode === 'auto' ? html`
320
- <${PickerPanel} items=${repoItems} multi
321
- showSearch=${false}
322
- selectedIds=${selectedRepos.value}
323
- onToggle=${toggleRepo}
324
- title="Repos to clone"
325
- emptyHint="No repos configured. Add one below to clone it into the workspace."
326
- onCreate=${async (v) => {
327
- try {
328
- const name = await createRepo(v);
329
- setToast(`added repo · ${name}`);
330
- return name;
331
- } catch (e) { setToast(e.message, 'error'); throw e; }
332
- }}
333
- createLabel="New repo" createFields=${repoCreateFields}
334
- onClose=${close} />
335
- ` : html`
336
- <${DirectoryPicker} initialPath=${cwd || ''}
337
- onPick=${(p) => { setCwd(p); }} />
338
- `}
339
- </div>
340
- </div>
341
- </${Modal}>` : null}
342
-
343
- <button type="button"
344
- class=${`pill${openPicker === 'folder' ? ' is-open' : ''}`}
345
- title="Choose folder"
346
- onClick=${() => setOpenPicker(openPicker === 'folder' ? null : 'folder')}>
347
- <span class="pill-icon"><${IconFolder} /></span>
348
- <span class="pill-label">${folder ? folder.name : 'Unsorted'}</span>
349
- <span class="pill-chev"><${IconChevronDown} /></span>
350
- </button>
351
- ${openPicker === 'folder' ? html`
352
- <${Modal} title="Choose folder" onClose=${close} width=${400}>
353
- <${PickerPanel} items=${folderItems} selectedId=${folderId}
354
- showSearch=${false}
355
- onSelect=${(id) => setFolderId(id)}
356
- onCreate=${async (v) => {
357
- try {
358
- const f = await createFolder(v.name);
359
- setToast(`created folder · ${v.name}`);
360
- return f?.id;
361
- } catch (e) { setToast(e.message, 'error'); throw e; }
362
- }}
363
- createLabel="New folder" createFields=${folderCreateFields}
364
- onClose=${close} />
365
- </${Modal}>` : null}
366
- </div>
367
-
368
- <button class="action primary launch-cta"
369
- disabled=${busy || !cliId || (mode === 'cwd' && !cwd)}
370
- onClick=${onLaunch}>
371
- ${busy ? 'Launching…' : html`Launch <span class="launch-cta-plane" aria-hidden="true">
372
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
373
- <path d="M22 2 11 13"/>
374
- <path d="M22 2 15 22l-4-9-9-4Z"/>
375
- </svg>
376
- </span>`}
377
- </button>
378
-
379
- <button type="button" class="launch-import-link"
380
- onClick=${() => setAdoptOpen(true)}>
381
- or import existing<span class="launch-import-arrow" aria-hidden="true"><${IconArrowRight} /></span>
382
- </button>
383
-
384
- ${adoptOpen ? html`
385
- <${AdoptModal} onClose=${() => setAdoptOpen(false)}
386
- onAdopted=${async (id) => {
387
- setAdoptOpen(false);
388
- await refreshAll();
389
- if (id) selectSession(id);
390
- selectTab('sessions');
391
- }} />` : null}
392
-
393
- <${ProgressList} rootId=${ROOT_ID} />
394
- ${result ? html`<div class="launch-status mono">${result}</div>` : null}
395
- </div>`;
396
- }
397
-
398
- let lastKey = null;
399
- function useStateOnce(key, init) {
400
- if (key !== lastKey) {
401
- lastKey = key;
402
- init();
403
- }
404
- }
405
-
406
- // Truncate a long path so it fits the pill nicely.
407
- // C:\Users\admin\proj\foo\bar → …\foo\bar
408
- function shortenPath(p) {
409
- if (!p) return '';
410
- if (p.length <= 28) return p;
411
- const sep = p.includes('\\') ? '\\' : '/';
412
- const parts = p.split(sep).filter(Boolean);
413
- if (parts.length <= 2) return p;
414
- return '…' + sep + parts.slice(-2).join(sep);
415
- }
416
-
417
- export function LaunchPage() {
418
- return html`
419
- <${PageTitleBar} title="New session" />
420
- <${LaunchHero} />`;
421
- }
1
+ // Launch page. ChatGPT-style centered composer with custom popover
2
+ // pickers for CLI / Folder / Repos. Each picker shares the unified
3
+ // PickerPanel component and can inline-create new entries.
4
+
5
+ import { html } from '../html.js';
6
+ import { useState, useEffect } from 'preact/hooks';
7
+ import { signal } from '@preact/signals';
8
+ import { config, folders, selectSession, selectTab } from '../state.js';
9
+ import { createCli, createFolder, createRepo, refreshAll } from '../api.js';
10
+ import { setToast } from '../toast.js';
11
+ import { streamNewSession, resetProgress } from '../streaming.js';
12
+ import { PageTitleBar } from '../components/PageTitleBar.js';
13
+ import { ProgressList } from '../components/ProgressList.js';
14
+ import { Modal } from '../components/Modal.js';
15
+ import { PickerPanel } from '../components/Picker.js';
16
+ import { DirectoryPicker } from '../components/DirectoryPicker.js';
17
+ import { AdoptModal } from '../components/AdoptModal.js';
18
+ import { BrandMark, IconTerminal, IconFolder, IconFolderOpen, IconBranch, IconChevronDown, IconForCliType, IconClaudeColor, IconCodexColor, IconCopilotColor, IconSparkle, IconWorkspace, IconArrowRight } from '../icons.js';
19
+
20
+ const ROOT_ID = 'newSessionProgress';
21
+ const selectedRepos = signal(new Set());
22
+
23
+ // Persist the user's last Launch picks (CLI / folder / mode / cwd /
24
+ // selected repos) so the form stays as they left it across reloads
25
+ // and tab switches. localStorage is best-effort — any access failure
26
+ // falls back silently.
27
+ const LS_KEY = 'ccsm.launch-state';
28
+ function loadLaunchState() {
29
+ try {
30
+ const raw = localStorage.getItem(LS_KEY);
31
+ if (!raw) return null;
32
+ const j = JSON.parse(raw);
33
+ if (j && typeof j === 'object') return j;
34
+ } catch {}
35
+ return null;
36
+ }
37
+ function saveLaunchState(s) {
38
+ try { localStorage.setItem(LS_KEY, JSON.stringify(s)); } catch {}
39
+ }
40
+
41
+ function initRepoSelection(repos, saved) {
42
+ const valid = new Set(repos.map((r) => r.name));
43
+ const sel = new Set();
44
+ // Start from the persisted selection (last-used picks), keeping only
45
+ // repos that still exist.
46
+ if (saved && Array.isArray(saved.repos)) {
47
+ for (const n of saved.repos) if (valid.has(n)) sel.add(n);
48
+ }
49
+ // Auto-check any repo whose "pre-select on launch" default is newly
50
+ // active — i.e. it wasn't a default the last time we saved. This
51
+ // covers both a brand-new default repo and an existing repo the user
52
+ // just flipped to default in Configure. A default the user previously
53
+ // unchecked stays unchecked (it's an old default, already in
54
+ // knownDefaults). With no saved knownDefaults (fresh user / old
55
+ // state), every default applies.
56
+ const knownDefaults = saved && Array.isArray(saved.knownDefaults)
57
+ ? new Set(saved.knownDefaults) : null;
58
+ for (const r of repos) {
59
+ if (r.defaultSelected && (knownDefaults === null || !knownDefaults.has(r.name))) {
60
+ sel.add(r.name);
61
+ }
62
+ }
63
+ selectedRepos.value = sel;
64
+ }
65
+
66
+ function LaunchHero() {
67
+ const cfg = config.value || {};
68
+ const clis = cfg.clis || [];
69
+ const repos = cfg.repos || [];
70
+ const defaultCli = cfg.defaultCliId || clis[0]?.id || '';
71
+ const saved = loadLaunchState();
72
+
73
+ // Initial values pull from localStorage first (last-used picks),
74
+ // then fall back to config defaults. cliId is validated below in
75
+ // the useEffect once `clis` arrives.
76
+ const [cliId, setCliId] = useState(saved?.cliId || defaultCli);
77
+ const [folderId, setFolderId] = useState(saved?.folderId || '');
78
+ const [mode, setMode] = useState(saved?.mode === 'cwd' ? 'cwd' : 'auto');
79
+ const [cwd, setCwd] = useState(saved?.cwd || ''); // only used when mode === 'cwd'
80
+ const [busy, setBusy] = useState(false);
81
+ const [result, setResult] = useState('');
82
+ const [openPicker, setOpenPicker] = useState(null); // 'cli' | 'folder' | 'workdir' | null
83
+ const [adoptOpen, setAdoptOpen] = useState(false);
84
+
85
+ // If config arrives after first render (cliId === '') OR the saved
86
+ // cli was removed, snap to the current default.
87
+ useEffect(() => {
88
+ if (!clis.length) return;
89
+ if (!cliId || !clis.find((c) => c.id === cliId)) {
90
+ setCliId(defaultCli);
91
+ }
92
+ }, [defaultCli, clis.length]);
93
+
94
+ // Validate the persisted folder id against the live folders list
95
+ // — folders deleted between sessions snap back to "no folder".
96
+ useEffect(() => {
97
+ if (!folderId) return;
98
+ if (!folders.value.find((f) => f.id === folderId)) setFolderId('');
99
+ }, [folderId, folders.value.length]);
100
+
101
+ // Persist every change. JSON-stringifying a Set isn't useful, so
102
+ // we materialize selectedRepos to an array here. knownDefaults records
103
+ // which repos were marked "pre-select" at save time so
104
+ // initRepoSelection can tell a newly-flipped default apart from one the
105
+ // user deliberately unchecked.
106
+ useEffect(() => {
107
+ saveLaunchState({
108
+ cliId, folderId, mode, cwd,
109
+ repos: [...selectedRepos.value],
110
+ knownDefaults: repos.filter((r) => r.defaultSelected).map((r) => r.name),
111
+ });
112
+ }, [cliId, folderId, mode, cwd, selectedRepos.value]);
113
+
114
+
115
+ const sig = repos.map((r) => r.name + ':' + r.defaultSelected).join('|');
116
+ useStateOnce(sig, () => initRepoSelection(repos, saved));
117
+
118
+ const cli = clis.find((c) => c.id === cliId) || clis[0];
119
+ const folder = folders.value.find((f) => f.id === folderId);
120
+
121
+ const toggleRepo = (name, on) => {
122
+ const next = new Set(selectedRepos.value);
123
+ if (on) next.add(name); else next.delete(name);
124
+ selectedRepos.value = next;
125
+ };
126
+
127
+ const onLaunch = async () => {
128
+ const useCwd = mode === 'cwd' && cwd;
129
+ const chosen = useCwd ? [] : [...selectedRepos.value];
130
+ setBusy(true);
131
+ setResult('');
132
+ resetProgress(chosen, ROOT_ID);
133
+ try {
134
+ const final = await streamNewSession(
135
+ {
136
+ repos: chosen,
137
+ cwd: useCwd ? cwd : undefined,
138
+ cliId: cliId || undefined,
139
+ folderId: folderId || undefined,
140
+ },
141
+ {
142
+ progressRootId: ROOT_ID,
143
+ onMeta: (ev) => {
144
+ if (ev.type === 'workspace') {
145
+ setResult(`workspace · ${ev.workspace.path}${ev.created ? ' · newly created' : ''}`);
146
+ } else if (ev.type === 'launched') {
147
+ setResult(`launched · session ${ev.launched.id}`);
148
+ }
149
+ },
150
+ },
151
+ );
152
+ if (final.success && final.launched) {
153
+ setToast(`launched · ${final.workspace.name}`);
154
+ await refreshAll();
155
+ selectSession(final.launched.id);
156
+ selectTab('sessions');
157
+ } else if (!final.success) {
158
+ setResult(`error · ${final.error}`);
159
+ setToast(final.error || 'launch failed', 'error');
160
+ }
161
+ } catch (e) {
162
+ setResult(`error · ${e.message}`);
163
+ setToast(e.message, 'error');
164
+ } finally {
165
+ setBusy(false);
166
+ }
167
+ };
168
+
169
+ const close = () => setOpenPicker(null);
170
+
171
+ // --- CLI picker config -----------------------------------------------
172
+ const cliItems = clis.map((c) => {
173
+ const Icon = IconForCliType(c.type);
174
+ return {
175
+ id: c.id,
176
+ icon: html`<${Icon} />`,
177
+ label: c.name,
178
+ meta: `${c.command}${c.shell && c.shell !== 'direct' ? ' · ' + c.shell : ''}`,
179
+ };
180
+ });
181
+ const cliCreateFields = [
182
+ { key: 'type', label: 'Type', type: 'iconRadio', default: 'other', options: [
183
+ { value: 'claude', label: 'Claude CLI', icon: html`<${IconClaudeColor} />` },
184
+ { value: 'codex', label: 'Codex CLI', icon: html`<${IconCodexColor} />` },
185
+ { value: 'copilot', label: 'GitHub Copilot', icon: html`<${IconCopilotColor} />` },
186
+ { value: 'other', label: 'Other', icon: html`<${IconTerminal} />` },
187
+ ],
188
+ onChange: (v, next) => {
189
+ const presets = { claude: { command: 'claude', resumeArgs: '--continue', resumeIdArgs: '--resume <id>', name: 'Claude Code' },
190
+ codex: { command: 'codex', resumeArgs: 'resume --last', resumeIdArgs: 'resume <id>', name: 'OpenAI Codex' },
191
+ copilot: { command: 'copilot', resumeArgs: '--continue', resumeIdArgs: '--session-id <id>', name: 'GitHub Copilot' },
192
+ other: {} }[v] || {};
193
+ const patch = {};
194
+ if (presets.resumeArgs != null) patch.resumeArgs = presets.resumeArgs;
195
+ if (presets.resumeIdArgs != null) patch.resumeIdArgs = presets.resumeIdArgs;
196
+ if (!next.command || !next.command.trim()) patch.command = presets.command || '';
197
+ if (!next.name || !next.name.trim()) patch.name = presets.name || '';
198
+ return patch;
199
+ },
200
+ },
201
+ { key: 'name', label: 'Name', placeholder: 'My CLI', required: true },
202
+ { key: 'command', label: 'Command', mono: true, placeholder: 'claude / codex / ...', required: true },
203
+ { key: 'args', label: 'Args (space-separated)', mono: true, placeholder: '' },
204
+ { key: 'resumeArgs', label: 'Resume args (fallback)', mono: true, placeholder: '--continue',
205
+ hint: 'Used when ccsm has no captured upstream session id.' },
206
+ { key: 'resumeIdArgs', label: 'Resume by id args', mono: true, placeholder: '--resume <id>',
207
+ hint: 'Use <id> as the placeholder for the captured upstream session UUID.' },
208
+ { key: 'shell', label: 'Shell', type: 'select', default: 'direct', options: [
209
+ { value: 'direct', label: 'direct (real .exe / .cmd)' },
210
+ { value: 'pwsh', label: 'pwsh (PowerShell aliases & functions)' },
211
+ { value: 'cmd', label: 'cmd (doskey)' },
212
+ ] },
213
+ ];
214
+
215
+ // --- Folder picker config --------------------------------------------
216
+ const folderItems = [
217
+ { id: '', label: 'Unsorted', meta: 'no folder', undraggable: true, icon: html`<${IconFolderOpen} />` },
218
+ ...folders.value.map((f) => ({ id: f.id, label: f.name, icon: html`<${IconFolder} />` })),
219
+ ];
220
+ const folderCreateFields = [
221
+ { key: 'name', label: 'Folder name', placeholder: 'Work / Personal / ...', autoFocus: true, required: true },
222
+ ];
223
+
224
+ // --- Repo picker config ----------------------------------------------
225
+ const repoItems = repos.map((r) => ({
226
+ id: r.name,
227
+ label: r.name,
228
+ meta: r.url,
229
+ }));
230
+ const repoCreateFields = [
231
+ { key: 'name', label: 'Name', placeholder: 'my-repo', autoFocus: true, required: true },
232
+ { key: 'url', label: 'URL', mono: true, placeholder: 'https://github.com/me/foo.git', required: true },
233
+ ];
234
+
235
+ const selectedRepoCount = selectedRepos.value.size;
236
+
237
+ // Label + title for the unified workdir/repos pill.
238
+ const workdirLabel = (() => {
239
+ if (mode === 'cwd') return cwd ? shortenPath(cwd) : 'Pick folder…';
240
+ if (selectedRepoCount === 0) return 'Auto workspace';
241
+ if (selectedRepoCount === 1) return [...selectedRepos.value][0];
242
+ return `Auto · ${selectedRepoCount} repos`;
243
+ })();
244
+ const workdirTitle = mode === 'cwd'
245
+ ? (cwd ? `Working dir · ${cwd}` : 'Pick an existing folder')
246
+ : (selectedRepoCount === 0
247
+ ? 'Auto: a fresh workspace under workDir (no repos)'
248
+ : `Auto workspace · clone ${selectedRepoCount} repo(s)`);
249
+
250
+ return html`
251
+ <div class="launch-hero">
252
+ <div class="launch-brand">
253
+ <span class="launch-brand-mark"><${BrandMark} /></span>
254
+ </div>
255
+ <h1 class="launch-tagline">
256
+ One shell. <em>Every CLI.</em>
257
+ </h1>
258
+
259
+ <div class="launch-toolbar">
260
+ <button type="button"
261
+ class=${`pill${openPicker === 'cli' ? ' is-open' : ''}`}
262
+ title="Choose CLI"
263
+ onClick=${() => setOpenPicker(openPicker === 'cli' ? null : 'cli')}>
264
+ <span class="pill-icon">${(() => { const I = IconForCliType(cli?.type); return html`<${I} />`; })()}</span>
265
+ <span class="pill-label">${cli ? cli.name : 'Choose CLI'}</span>
266
+ <span class="pill-chev"><${IconChevronDown} /></span>
267
+ </button>
268
+ ${openPicker === 'cli' ? html`
269
+ <${Modal} title="Choose CLI" onClose=${close} width=${440}>
270
+ <${PickerPanel} items=${cliItems} selectedId=${cliId}
271
+ showSearch=${false}
272
+ onSelect=${(id) => setCliId(id)}
273
+ onCreate=${async (v) => {
274
+ try {
275
+ const id = await createCli(v);
276
+ setToast(`created CLI · ${v.name}`);
277
+ return id;
278
+ } catch (e) { setToast(e.message, 'error'); throw e; }
279
+ }}
280
+ createLabel="New CLI" createFields=${cliCreateFields}
281
+ onClose=${close} />
282
+ </${Modal}>` : null}
283
+
284
+ <button type="button"
285
+ class=${`pill${openPicker === 'workdir' ? ' is-open' : ''}${(mode === 'cwd' && cwd) ? ' is-set' : ''}`}
286
+ title=${workdirTitle}
287
+ onClick=${() => setOpenPicker(openPicker === 'workdir' ? null : 'workdir')}>
288
+ <span class="pill-icon"><${IconWorkspace} /></span>
289
+ <span class="pill-label">${workdirLabel}</span>
290
+ <span class="pill-chev"><${IconChevronDown} /></span>
291
+ </button>
292
+ ${openPicker === 'workdir' ? html`
293
+ <${Modal} title="Working directory" onClose=${close} width=${640}
294
+ footer=${html`
295
+ <button type="button" class="action subtle" onClick=${close}>Cancel</button>
296
+ <button type="button" class="action primary"
297
+ disabled=${mode === 'cwd' && !cwd}
298
+ onClick=${close}>
299
+ ${mode === 'cwd' ? 'Use folder' : 'Done'}
300
+ </button>`}>
301
+ <div class="workdir-modal">
302
+ <div class="workdir-mode-grid">
303
+ <button type="button"
304
+ class=${`workdir-mode-opt${mode === 'auto' ? ' is-active' : ''}`}
305
+ onClick=${() => setMode('auto')}>
306
+ <span class="workdir-mode-icon"><${IconSparkle} /></span>
307
+ <span class="workdir-mode-name">Auto workspace</span>
308
+ <span class="workdir-mode-sub">Fresh <span class="mono">ws-N</span> + clone repos</span>
309
+ </button>
310
+ <button type="button"
311
+ class=${`workdir-mode-opt${mode === 'cwd' ? ' is-active' : ''}`}
312
+ onClick=${() => setMode('cwd')}>
313
+ <span class="workdir-mode-icon"><${IconFolderOpen} /></span>
314
+ <span class="workdir-mode-name">Existing folder</span>
315
+ <span class="workdir-mode-sub">Launch directly · no clone</span>
316
+ </button>
317
+ </div>
318
+ <div class="workdir-detail">
319
+ ${mode === 'auto' ? html`
320
+ <${PickerPanel} items=${repoItems} multi
321
+ showSearch=${false}
322
+ selectedIds=${selectedRepos.value}
323
+ onToggle=${toggleRepo}
324
+ title="Repos to clone"
325
+ emptyHint="No repos configured. Add one below to clone it into the workspace."
326
+ onCreate=${async (v) => {
327
+ try {
328
+ const name = await createRepo(v);
329
+ setToast(`added repo · ${name}`);
330
+ return name;
331
+ } catch (e) { setToast(e.message, 'error'); throw e; }
332
+ }}
333
+ createLabel="New repo" createFields=${repoCreateFields}
334
+ onClose=${close} />
335
+ ` : html`
336
+ <${DirectoryPicker} initialPath=${cwd || ''}
337
+ onPick=${(p) => { setCwd(p); }} />
338
+ `}
339
+ </div>
340
+ </div>
341
+ </${Modal}>` : null}
342
+
343
+ <button type="button"
344
+ class=${`pill${openPicker === 'folder' ? ' is-open' : ''}`}
345
+ title="Choose folder"
346
+ onClick=${() => setOpenPicker(openPicker === 'folder' ? null : 'folder')}>
347
+ <span class="pill-icon"><${IconFolder} /></span>
348
+ <span class="pill-label">${folder ? folder.name : 'Unsorted'}</span>
349
+ <span class="pill-chev"><${IconChevronDown} /></span>
350
+ </button>
351
+ ${openPicker === 'folder' ? html`
352
+ <${Modal} title="Choose folder" onClose=${close} width=${400}>
353
+ <${PickerPanel} items=${folderItems} selectedId=${folderId}
354
+ showSearch=${false}
355
+ onSelect=${(id) => setFolderId(id)}
356
+ onCreate=${async (v) => {
357
+ try {
358
+ const f = await createFolder(v.name);
359
+ setToast(`created folder · ${v.name}`);
360
+ return f?.id;
361
+ } catch (e) { setToast(e.message, 'error'); throw e; }
362
+ }}
363
+ createLabel="New folder" createFields=${folderCreateFields}
364
+ onClose=${close} />
365
+ </${Modal}>` : null}
366
+ </div>
367
+
368
+ <button class="action primary launch-cta"
369
+ disabled=${busy || !cliId || (mode === 'cwd' && !cwd)}
370
+ onClick=${onLaunch}>
371
+ ${busy ? 'Launching…' : html`Launch <span class="launch-cta-plane" aria-hidden="true">
372
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
373
+ <path d="M22 2 11 13"/>
374
+ <path d="M22 2 15 22l-4-9-9-4Z"/>
375
+ </svg>
376
+ </span>`}
377
+ </button>
378
+
379
+ <button type="button" class="launch-import-link"
380
+ onClick=${() => setAdoptOpen(true)}>
381
+ or import existing<span class="launch-import-arrow" aria-hidden="true"><${IconArrowRight} /></span>
382
+ </button>
383
+
384
+ ${adoptOpen ? html`
385
+ <${AdoptModal} onClose=${() => setAdoptOpen(false)}
386
+ onAdopted=${async (id) => {
387
+ setAdoptOpen(false);
388
+ await refreshAll();
389
+ if (id) selectSession(id);
390
+ selectTab('sessions');
391
+ }} />` : null}
392
+
393
+ <${ProgressList} rootId=${ROOT_ID} />
394
+ ${result ? html`<div class="launch-status mono">${result}</div>` : null}
395
+ </div>`;
396
+ }
397
+
398
+ let lastKey = null;
399
+ function useStateOnce(key, init) {
400
+ if (key !== lastKey) {
401
+ lastKey = key;
402
+ init();
403
+ }
404
+ }
405
+
406
+ // Truncate a long path so it fits the pill nicely.
407
+ // C:\Users\admin\proj\foo\bar → …\foo\bar
408
+ function shortenPath(p) {
409
+ if (!p) return '';
410
+ if (p.length <= 28) return p;
411
+ const sep = p.includes('\\') ? '\\' : '/';
412
+ const parts = p.split(sep).filter(Boolean);
413
+ if (parts.length <= 2) return p;
414
+ return '…' + sep + parts.slice(-2).join(sep);
415
+ }
416
+
417
+ export function LaunchPage() {
418
+ return html`
419
+ <${PageTitleBar} title="New session" />
420
+ <${LaunchHero} />`;
421
+ }