claude-instance-manager 0.0.0-stage → 1.0.0

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/index.html ADDED
@@ -0,0 +1,512 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Claude Instance Manager</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: light;
10
+ font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
11
+ color: #242824;
12
+ background: #f7f5f0;
13
+ }
14
+ * { box-sizing: border-box; }
15
+ body { margin: 0; min-width: 0; }
16
+ button, input { font: inherit; }
17
+ button { cursor: pointer; }
18
+ .app { max-width: 1050px; margin: auto; padding: 32px 38px 48px; }
19
+ .topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
20
+ .brand { display: flex; align-items: center; gap: 11px; font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
21
+ .brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 12px; background: #cf795f; color: white; font-size: 23px; }
22
+ .header-actions { display: flex; align-items: center; gap: 20px; }
23
+ .privacy { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: #68756c; text-transform: uppercase; }
24
+ .privacy::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #78a187; }
25
+ .add-button { padding: 11px 16px; border: 0; border-radius: 9px; background: #cc765b; color: white; font-size: 12px; font-weight: 700; }
26
+ .add-button:hover { background: #b9654b; }
27
+ .shortcut-hint { margin-left: 8px; padding: 3px 5px; border-radius: 4px; background: rgba(255, 255, 255, .18); font: inherit; font-size: 10px; }
28
+ .hero { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 42px 0 24px; }
29
+ .eyebrow { margin: 0 0 10px; color: #b66a52; font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
30
+ h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(32px, 5vw, 40px); font-weight: 400; letter-spacing: -.045em; line-height: 1.1; }
31
+ .subtitle { margin: 10px 0 0; color: #777b74; font-size: 14px; line-height: 1.6; }
32
+ .install-state { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid #e6e5df; border-radius: 99px; background: #fff; color: #68736b; font-size: 12px; font-weight: 600; }
33
+ .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #b9bcb7; }
34
+ .dot.online { background: #70a887; box-shadow: 0 0 0 3px #e6f2e9; }
35
+ .dot.error { background: #cf795f; }
36
+ .dot.loading { width: 10px; height: 10px; border: 2px solid #e6d3ca; border-top-color: #b66a52; background: transparent; animation: spin .8s linear infinite; }
37
+ @keyframes spin { to { transform: rotate(360deg); } }
38
+ @media (prefers-reduced-motion: reduce) { .dot.loading { animation: none; } }
39
+ h2 { margin: 0; font-size: 18px; letter-spacing: -.03em; }
40
+ .workspace { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 380px; overflow: hidden; border: 1px solid #e9e7e0; border-radius: 16px; background: #fff; box-shadow: 0 4px 18px rgba(48, 46, 39, .025); }
41
+ .sidebar { display: flex; flex-direction: column; min-width: 0; padding: 22px 14px; border-right: 1px solid #e9e7e0; background: #f0eee8; }
42
+ .sidebar-heading { padding: 0 8px; }
43
+ .sidebar-heading h2 { font-size: 13px; }
44
+ .sidebar-summary { margin: 6px 0 16px; color: #898d85; font-size: 11px; }
45
+ .sidebar-summary strong { font-weight: 600; }
46
+ .refresh-note { margin: auto 8px 0; padding-top: 18px; color: #9a9d96; font-size: 11px; }
47
+ .list { display: flex; flex-direction: column; gap: 4px; }
48
+ .instance-row { display: flex; align-items: center; gap: 10px; min-width: 0; width: 100%; padding: 9px; border: 0; border-radius: 10px; background: transparent; color: #575d56; text-align: left; }
49
+ .instance-row:hover { background: #eae8e1; }
50
+ .instance-row.is-selected { background: #fff; color: #242824; box-shadow: 0 2px 8px rgba(48, 46, 39, .04); }
51
+ .avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 10px; background: #f6e8df; color: #b65f43; font-size: 14px; font-weight: 700; }
52
+ .instance-row:nth-child(3n+2) .avatar { color: #698575; background: #e7f0e9; }
53
+ .instance-row:nth-child(3n) .avatar { color: #7d719b; background: #eeeaf5; }
54
+ .instance-name { overflow: hidden; min-width: 0; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
55
+ .instance-detail { min-width: 0; padding: 36px 40px; }
56
+ .detail-header { display: flex; align-items: center; gap: 17px; min-width: 0; }
57
+ .detail-header .avatar { width: 58px; height: 58px; border-radius: 17px; font-size: 23px; }
58
+ .detail-name { min-width: 0; }
59
+ .detail-name h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; font-size: 32px; font-weight: 400; }
60
+ .detail-body { margin-top: 32px; border-top: 1px solid #efede8; }
61
+ .detail-body h3 { margin: 22px 0 10px; font-size: 12px; }
62
+ .detail-row { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid #efede8; color: #898d85; font-size: 12px; }
63
+ .detail-row strong { color: #575d56; text-align: right; font-weight: 600; }
64
+ .usage-metric { padding: 10px 0; }
65
+ .usage-metric-header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 8px; color: #898d85; font-size: 12px; }
66
+ .usage-metric-header strong { color: #575d56; font-weight: 600; }
67
+ .usage-bar { display: block; width: 100%; height: 8px; border: 0; border-radius: 99px; appearance: none; }
68
+ .usage-bar::-webkit-progress-bar { border-radius: 99px; background: #f0eee8; }
69
+ .usage-bar::-webkit-progress-value { border-radius: 99px; background: #cc765b; }
70
+ .usage-reset { margin: 7px 0 0; color: #898d85; font-size: 11px; line-height: 1.5; }
71
+ .usage-note { color: #898d85; font-size: 11px; line-height: 1.5; }
72
+ .status { display: flex; align-items: center; gap: 7px; margin-top: 20px; color: #8a8e87; font-size: 12px; }
73
+ .status.is-running { color: #5c8a6c; }
74
+ .instance-row .status { margin: 0 0 0 auto; font-size: 0; }
75
+ .detail-header .status { margin-top: 8px; }
76
+ .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 24px; }
77
+ .open { padding: 8px 13px; border: 0; border-radius: 8px; background: #282d29; color: white; font-size: 12px; font-weight: 700; }
78
+ .open:hover { background: #414b43; }
79
+ .hide { padding: 8px; border: 0; background: transparent; color: #9a9c96; font-size: 12px; }
80
+ .hide:hover { color: #a75947; }
81
+ .delete { padding: 8px; border: 0; background: transparent; color: #b86956; font-size: 12px; }
82
+ .delete:hover { color: #8d392c; }
83
+ button:disabled { cursor: wait; opacity: .5; }
84
+ .new-dialog { width: min(440px, calc(100% - 40px)); padding: 28px; border: 1px solid #e9e7e0; border-radius: 18px; background: #fff; color: #242824; box-shadow: 0 20px 70px rgba(37, 39, 34, .18); }
85
+ .new-dialog::backdrop { background: rgba(36, 40, 36, .44); }
86
+ .new-dialog h2 { font-family: Georgia, serif; font-size: 26px; font-weight: 400; }
87
+ .dialog-description { margin: 10px 0 22px; color: #777b74; font-size: 13px; line-height: 1.5; }
88
+ .add-form label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 700; }
89
+ input { width: 100%; min-width: 0; padding: 11px 13px; border: 1px solid #e4e3dc; border-radius: 9px; outline: none; background: #fff; color: #242824; font-size: 13px; }
90
+ input:focus { border-color: #cf795f; box-shadow: 0 0 0 3px #f7e9e2; }
91
+ .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
92
+ .cancel-button { padding: 11px 16px; border: 1px solid #e4e3dc; border-radius: 9px; background: #fff; color: #68736b; font-size: 12px; font-weight: 700; }
93
+ .cancel-button:hover { background: #f7f5f0; }
94
+ .message { margin: 12px 0 0; color: #a85441; font-size: 12px; line-height: 1.5; }
95
+ .footer { margin: 24px 0 0; color: #a1a39d; font-size: 11px; line-height: 1.6; }
96
+ button:focus-visible { outline: 3px solid #dfaa97; outline-offset: 3px; }
97
+ @media (max-width: 700px) {
98
+ .app { padding: 24px 22px 40px; }
99
+ .hero { margin-top: 32px; }
100
+ .workspace { grid-template-columns: 190px minmax(0, 1fr); }
101
+ .instance-detail { padding: 28px 24px; }
102
+ .privacy { display: none; }
103
+ }
104
+ </style>
105
+ </head>
106
+ <body>
107
+ <main class="app">
108
+ <header class="topbar">
109
+ <div class="brand"><span class="brand-mark" aria-hidden="true">✳</span> Claude Instance Manager</div>
110
+ <div class="header-actions">
111
+ <div class="privacy">Stored locally</div>
112
+ <button class="add-button" id="newInstanceButton" type="button" aria-keyshortcuts="Control+N">+ New Instance <kbd class="shortcut-hint" aria-hidden="true">Ctrl N</kbd></button>
113
+ </div>
114
+ </header>
115
+
116
+ <section class="hero">
117
+ <div>
118
+ <p class="eyebrow">Your workspace</p>
119
+ <h1>Your instances.</h1>
120
+ <p class="subtitle">Choose an instance to open and manage.</p>
121
+ </div>
122
+ <div class="install-state"><span class="dot" id="installDot"></span><span id="installState">Checking Claude…</span></div>
123
+ </section>
124
+
125
+ <section class="workspace" aria-label="Instances">
126
+ <aside class="sidebar" aria-labelledby="instancesTitle">
127
+ <div class="sidebar-heading">
128
+ <h2 id="instancesTitle">Your instances</h2>
129
+ <p class="sidebar-summary"><strong id="instanceCount">—</strong> instances · <strong id="runningCount">—</strong> running</p>
130
+ </div>
131
+ <div class="list" id="list"></div>
132
+ <span class="refresh-note" id="refreshNote">Status refreshes automatically</span>
133
+ </aside>
134
+ <section class="instance-detail" id="instanceDetail" aria-label="Selected instance"></section>
135
+ </section>
136
+
137
+ <dialog class="new-dialog" id="newInstanceDialog" aria-labelledby="newInstanceTitle" aria-describedby="newInstanceDescription">
138
+ <h2 id="newInstanceTitle">New instance</h2>
139
+ <p class="dialog-description" id="newInstanceDescription">Give this instance a name. You'll sign in when you open it.</p>
140
+ <form class="add-form" id="addForm">
141
+ <label for="accInput">Instance name</label>
142
+ <input id="accInput" aria-describedby="formMessage" placeholder="e.g. Work, Personal, Creative" autocomplete="off" autofocus>
143
+ <p class="message" id="formMessage" role="status" hidden></p>
144
+ <div class="dialog-actions">
145
+ <button class="cancel-button" id="cancelInstanceButton" type="button">Cancel</button>
146
+ <button class="add-button" type="submit">Create instance</button>
147
+ </div>
148
+ </form>
149
+ </dialog>
150
+
151
+ <p class="message" id="stateMessage" role="status" hidden></p>
152
+ <p class="footer">The default instance uses your existing Claude Desktop data. Hiding an instance only removes it from this list; it does not delete its data or stop Claude.</p>
153
+ </main>
154
+ <script>
155
+ const list = document.getElementById('list');
156
+ const detail = document.getElementById('instanceDetail');
157
+ const input = document.getElementById('accInput');
158
+ const newInstanceDialog = document.getElementById('newInstanceDialog');
159
+ const newInstanceButton = document.getElementById('newInstanceButton');
160
+ const formMessage = document.getElementById('formMessage');
161
+ const stateMessage = document.getElementById('stateMessage');
162
+ const instanceId = name => name.trim().replace(/\s+/g, '_');
163
+ const key = id => id.toLowerCase();
164
+ let savedInstances = [];
165
+ let hiddenInstances = [];
166
+ let state = null;
167
+ let refreshing = false;
168
+ let initialLoading = true;
169
+ let storageWarning = '';
170
+ let operationWarning = '';
171
+ let instanceRevision = 0;
172
+ let selectedInstance = null;
173
+ const deletingInstances = new Set();
174
+
175
+ function showMessage(element, message) {
176
+ element.textContent = message;
177
+ element.hidden = !message;
178
+ }
179
+
180
+ try {
181
+ savedInstances = JSON.parse(localStorage.getItem('claude_profiles') || '["Personal", "Work"]');
182
+ hiddenInstances = JSON.parse(localStorage.getItem('claude_hidden_profiles') || '[]');
183
+ if (!Array.isArray(savedInstances) || !savedInstances.every(name => typeof name === 'string') ||
184
+ !Array.isArray(hiddenInstances) || !hiddenInstances.every(name => typeof name === 'string')) {
185
+ throw new Error('Invalid saved instance list.');
186
+ }
187
+ } catch (error) {
188
+ console.error('Could not read saved instances:', error);
189
+ savedInstances = [];
190
+ hiddenInstances = [];
191
+ storageWarning = 'Could not read saved instance names. Existing instance folders will still be shown.';
192
+ showMessage(stateMessage, storageWarning);
193
+ }
194
+
195
+ function visibleInstances() {
196
+ const instances = new Map();
197
+ for (const name of savedInstances) {
198
+ const id = instanceId(name);
199
+ if (!hiddenInstances.includes(key(id))) instances.set(key(id), { name, id, exists: false });
200
+ }
201
+ for (const instance of state ? state.instances : []) {
202
+ if (!hiddenInstances.includes(key(instance.id))) instances.set(key(instance.id), { ...instance, exists: true });
203
+ }
204
+ return [...instances.values()];
205
+ }
206
+
207
+ function save() {
208
+ try {
209
+ localStorage.setItem('claude_profiles', JSON.stringify(savedInstances));
210
+ localStorage.setItem('claude_hidden_profiles', JSON.stringify(hiddenInstances));
211
+ } catch (error) {
212
+ console.error('Could not save instances:', error);
213
+ storageWarning = 'Could not save instance names. Changes may not persist.';
214
+ showMessage(stateMessage, storageWarning);
215
+ }
216
+ }
217
+
218
+ function updateStatus(status, running) {
219
+ status.className = `status${!initialLoading && running ? ' is-running' : ''}`;
220
+ const dot = document.createElement('span');
221
+ dot.className = `dot${initialLoading ? ' loading' : running ? ' online' : ''}`;
222
+ const label = initialLoading ? 'Checking status…' : !state || !state.running ? 'Status unavailable' : running ? 'Running' : 'Not running';
223
+ status.replaceChildren(dot, document.createTextNode(label));
224
+ }
225
+
226
+ async function deleteInstance(entry) {
227
+ const id = key(entry.id);
228
+ if (deletingInstances.has(id)) return;
229
+ deletingInstances.add(id);
230
+ operationWarning = '';
231
+ render();
232
+ let result;
233
+ try {
234
+ result = await window.claudeManager.deleteInstance(entry.id);
235
+ if (result === 'deleted') {
236
+ savedInstances = savedInstances.filter(instance => key(instanceId(instance)) !== id);
237
+ hiddenInstances = hiddenInstances.filter(instance => instance !== id);
238
+ if (state) state.instances = state.instances.filter(instance => key(instance.id) !== id);
239
+ save();
240
+ }
241
+ if (result !== 'cancelled') instanceRevision++;
242
+ } catch (error) {
243
+ console.error('Could not delete instance:', error);
244
+ operationWarning = 'Could not delete the instance. Check the launcher logs for details.';
245
+ showMessage(stateMessage, operationWarning);
246
+ instanceRevision++;
247
+ } finally {
248
+ deletingInstances.delete(id);
249
+ render();
250
+ if (result !== 'cancelled') refresh();
251
+ }
252
+ }
253
+
254
+ function render() {
255
+ const instances = visibleInstances();
256
+ const focusedKey = document.activeElement && document.activeElement.dataset && document.activeElement.dataset.instanceKey;
257
+ const focusedAction = document.activeElement && document.activeElement.dataset && document.activeElement.dataset.detailAction;
258
+ const focusedDetailKey = document.activeElement && document.activeElement.dataset && document.activeElement.dataset.detailInstanceKey;
259
+ list.replaceChildren();
260
+ detail.replaceChildren();
261
+ const knownStatus = !initialLoading && state && state.running;
262
+ const entries = [{ name: 'Default', isDefault: true }, ...instances.map(instance => ({ ...instance, isDefault: false }))];
263
+ const selected = entries.find(entry => entry.isDefault ? selectedInstance === null : key(entry.id) === selectedInstance) || entries[0];
264
+ if (selected.isDefault) selectedInstance = null;
265
+ let runningCount = 0;
266
+ let focusedRow;
267
+
268
+ for (const entry of entries) {
269
+ const running = knownStatus && (entry.isDefault ? state.running.defaultRunning : state.running.instances.includes(key(entry.id)));
270
+ if (running) runningCount++;
271
+ const row = document.createElement('button');
272
+ row.className = `instance-row${entry === selected ? ' is-selected' : ''}`;
273
+ row.dataset.instanceKey = entry.isDefault ? '' : key(entry.id);
274
+ row.setAttribute('aria-pressed', String(entry === selected));
275
+ row.addEventListener('click', () => {
276
+ selectedInstance = entry.isDefault ? null : key(entry.id);
277
+ render();
278
+ });
279
+ if (focusedKey !== undefined && focusedKey === row.dataset.instanceKey) focusedRow = row;
280
+ const avatar = document.createElement('div');
281
+ avatar.className = 'avatar';
282
+ avatar.textContent = entry.isDefault ? '✳' : entry.name.charAt(0).toUpperCase();
283
+ avatar.setAttribute('aria-hidden', 'true');
284
+ const name = document.createElement('span');
285
+ name.className = 'instance-name';
286
+ name.textContent = entry.name;
287
+ const status = document.createElement('span');
288
+ updateStatus(status, running);
289
+ row.append(avatar, name, status);
290
+ list.append(row);
291
+ }
292
+
293
+ const running = knownStatus && (selected.isDefault ? state.running.defaultRunning : state.running.instances.includes(key(selected.id)));
294
+ const header = document.createElement('div');
295
+ header.className = 'detail-header';
296
+ const avatar = document.createElement('div');
297
+ avatar.className = 'avatar';
298
+ avatar.textContent = selected.isDefault ? '✳' : selected.name.charAt(0).toUpperCase();
299
+ avatar.setAttribute('aria-hidden', 'true');
300
+ const nameBlock = document.createElement('div');
301
+ nameBlock.className = 'detail-name';
302
+ const name = document.createElement('h2');
303
+ name.textContent = selected.name;
304
+ const status = document.createElement('div');
305
+ updateStatus(status, running);
306
+ nameBlock.append(name, status);
307
+ header.append(avatar, nameBlock);
308
+
309
+ const body = document.createElement('div');
310
+ body.className = 'detail-body';
311
+ const heading = document.createElement('h3');
312
+ heading.textContent = 'Instance details';
313
+ const typeRow = document.createElement('div');
314
+ typeRow.className = 'detail-row';
315
+ const typeLabel = document.createElement('span');
316
+ typeLabel.textContent = 'Type';
317
+ const typeValue = document.createElement('strong');
318
+ typeValue.textContent = selected.isDefault ? 'Existing Claude Desktop instance' : 'Separate instance';
319
+ typeRow.append(typeLabel, typeValue);
320
+ const dataRow = document.createElement('div');
321
+ dataRow.className = 'detail-row';
322
+ const dataLabel = document.createElement('span');
323
+ dataLabel.textContent = 'Data';
324
+ const dataValue = document.createElement('strong');
325
+ dataValue.textContent = selected.isDefault ? 'Existing Claude Desktop data' : selected.exists ? 'Separate data directory' : 'Created when opened';
326
+ dataRow.append(dataLabel, dataValue);
327
+ body.append(heading, typeRow, dataRow);
328
+
329
+ const usageHeading = document.createElement('h3');
330
+ usageHeading.textContent = 'Last recorded usage';
331
+ body.append(usageHeading);
332
+ const usage = state && state.usage && (selected.isDefault
333
+ ? state.usage.default
334
+ : state.usage.managed.find(entry => entry.id === key(selected.id)));
335
+ const usageNote = document.createElement('p');
336
+ usageNote.className = 'usage-note';
337
+ if (usage && usage.error) {
338
+ usageNote.textContent = 'Could not read local usage history. Check the launcher logs.';
339
+ } else if (!usage || !usage.history) {
340
+ usageNote.textContent = 'No local usage history found for this instance.';
341
+ } else {
342
+ for (const [label, value] of Object.entries(usage.history.metrics)) {
343
+ const row = document.createElement('div');
344
+ row.className = 'usage-metric';
345
+ const rowHeader = document.createElement('div');
346
+ rowHeader.className = 'usage-metric-header';
347
+ const metric = document.createElement('span');
348
+ metric.textContent = label;
349
+ const percent = document.createElement('strong');
350
+ percent.textContent = `${value}%`;
351
+ rowHeader.append(metric, percent);
352
+ const bar = document.createElement('progress');
353
+ bar.className = 'usage-bar';
354
+ bar.max = 100;
355
+ bar.value = Math.min(value, 100);
356
+ bar.setAttribute('aria-label', `${label} usage`);
357
+ bar.setAttribute('aria-valuetext', `${value}% used`);
358
+ row.append(rowHeader, bar);
359
+ const reset = usage.history.resets && usage.history.resets[label];
360
+ const resetNote = document.createElement('p');
361
+ resetNote.className = 'usage-reset';
362
+ resetNote.textContent = reset
363
+ ? `Cached reset: ${new Date(reset.resetAt).toLocaleString()} · cached ${new Date(reset.cachedAt).toLocaleString()}`
364
+ : usage.history.resetError ? 'Could not read cached reset time.' : 'Reset time unavailable in local cache.';
365
+ row.append(resetNote);
366
+ body.append(row);
367
+ }
368
+ usageNote.textContent = `Recorded ${new Date(usage.history.recordedAt).toLocaleString()}. This may reflect a previously signed-in account. Cached reset times may be stale.`;
369
+ }
370
+ body.append(usageNote);
371
+
372
+ const actions = document.createElement('div');
373
+ actions.className = 'actions';
374
+ const deleting = !selected.isDefault && deletingInstances.has(key(selected.id));
375
+ const selectedKey = selected.isDefault ? '' : key(selected.id);
376
+ const open = document.createElement('button');
377
+ open.className = 'open';
378
+ open.dataset.detailAction = 'open';
379
+ open.dataset.detailInstanceKey = selectedKey;
380
+ open.textContent = 'Open Claude ↗';
381
+ open.disabled = deleting;
382
+ open.addEventListener('click', () => {
383
+ window.claudeManager.launch(selected.isDefault ? null : selected.id);
384
+ setTimeout(refresh, 1500);
385
+ });
386
+ actions.append(open);
387
+ if (!selected.isDefault) {
388
+ const hide = document.createElement('button');
389
+ hide.className = 'hide';
390
+ hide.dataset.detailAction = 'hide';
391
+ hide.dataset.detailInstanceKey = selectedKey;
392
+ hide.textContent = 'Hide';
393
+ hide.disabled = deleting;
394
+ hide.setAttribute('aria-label', `Hide ${selected.name}`);
395
+ hide.title = 'Hide from this list without deleting data or stopping Claude';
396
+ hide.addEventListener('click', () => {
397
+ savedInstances = savedInstances.filter(instance => key(instanceId(instance)) !== key(selected.id));
398
+ hiddenInstances.push(key(selected.id));
399
+ save();
400
+ render();
401
+ });
402
+ actions.append(hide);
403
+ if (selected.exists) {
404
+ const remove = document.createElement('button');
405
+ remove.className = 'delete';
406
+ remove.dataset.detailAction = 'delete';
407
+ remove.dataset.detailInstanceKey = selectedKey;
408
+ remove.textContent = deleting ? 'Deleting…' : 'Delete';
409
+ remove.disabled = deleting;
410
+ remove.setAttribute('aria-label', `Delete ${selected.name}`);
411
+ remove.title = 'Permanently delete this instance and its data';
412
+ remove.addEventListener('click', () => deleteInstance(selected));
413
+ actions.append(remove);
414
+ }
415
+ }
416
+ detail.append(header, body, actions);
417
+ document.getElementById('instanceCount').textContent = entries.length;
418
+ document.getElementById('runningCount').textContent = knownStatus ? runningCount : '—';
419
+ document.getElementById('installState').textContent = !state ? initialLoading ? 'Checking Claude…' : 'Claude status unavailable' : state.installed ? 'Claude installed' : 'Claude not found';
420
+ document.getElementById('installDot').className = `dot${!state ? '' : state.installed ? ' online' : ' error'}`;
421
+ list.setAttribute('aria-busy', String(initialLoading));
422
+ detail.setAttribute('aria-busy', String(initialLoading));
423
+ document.getElementById('refreshNote').textContent = initialLoading ? 'Checking statuses…' : 'Status refreshes automatically';
424
+ if (focusedRow) focusedRow.focus({ preventScroll: true });
425
+ if (focusedAction && focusedDetailKey === selectedKey) {
426
+ const button = [...actions.querySelectorAll('button')].find(item => item.dataset.detailAction === focusedAction);
427
+ if (button && !button.disabled) button.focus({ preventScroll: true });
428
+ }
429
+ }
430
+
431
+ async function refresh() {
432
+ if (refreshing) return;
433
+ refreshing = true;
434
+ const revision = instanceRevision;
435
+ let stale = false;
436
+ let needsRender = initialLoading;
437
+ try {
438
+ const nextState = await window.claudeManager.getInstanceState();
439
+ if (revision !== instanceRevision) {
440
+ stale = true;
441
+ } else {
442
+ if (JSON.stringify(state) !== JSON.stringify(nextState)) needsRender = true;
443
+ state = nextState;
444
+ const statusWarning = state.installed && !state.running ? 'Running status is unavailable. Check Windows permissions and PowerShell.' : '';
445
+ showMessage(stateMessage, [storageWarning, operationWarning, statusWarning].filter(Boolean).join(' '));
446
+ }
447
+ } catch (error) {
448
+ if (revision !== instanceRevision) {
449
+ stale = true;
450
+ } else {
451
+ console.error('Could not load instances:', error);
452
+ if (state && state.running) {
453
+ state = { ...state, running: null };
454
+ needsRender = true;
455
+ }
456
+ showMessage(stateMessage, 'Could not load local instances. Check the launcher logs for details.');
457
+ }
458
+ } finally {
459
+ refreshing = false;
460
+ initialLoading = false;
461
+ if (needsRender) render();
462
+ if (stale) refresh();
463
+ }
464
+ }
465
+
466
+ newInstanceButton.addEventListener('click', () => newInstanceDialog.showModal());
467
+ document.addEventListener('keydown', event => {
468
+ if (event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && !event.isComposing && event.key.toLowerCase() === 'n') {
469
+ event.preventDefault();
470
+ if (!event.repeat && !newInstanceDialog.open) newInstanceDialog.showModal();
471
+ }
472
+ });
473
+ document.getElementById('cancelInstanceButton').addEventListener('click', () => newInstanceDialog.close());
474
+ newInstanceDialog.addEventListener('close', () => {
475
+ if (newInstanceDialog.open) return;
476
+ input.value = '';
477
+ showMessage(formMessage, '');
478
+ newInstanceButton.focus();
479
+ });
480
+
481
+ document.getElementById('addForm').addEventListener('submit', event => {
482
+ event.preventDefault();
483
+ const name = input.value.trim();
484
+ if (!name || /[<>:"/\\|?*\x00-\x1f]/.test(name) || name.endsWith('.')) {
485
+ showMessage(formMessage, 'Enter an instance name without Windows-invalid characters.');
486
+ return;
487
+ }
488
+ const hidden = (state ? state.instances : []).find(instance =>
489
+ hiddenInstances.includes(key(instance.id)) &&
490
+ (key(instance.id) === key(instanceId(name)) || instance.name.toLowerCase() === name.toLowerCase())
491
+ );
492
+ const id = hidden ? hidden.id : instanceId(name);
493
+ if (visibleInstances().some(instance => key(instance.id) === key(id))) {
494
+ showMessage(formMessage, 'An instance with this name already exists.');
495
+ return;
496
+ }
497
+ hiddenInstances = hiddenInstances.filter(instance => instance !== key(id));
498
+ if (!hidden) savedInstances.push(name);
499
+ selectedInstance = key(id);
500
+ save();
501
+ input.value = '';
502
+ showMessage(formMessage, '');
503
+ newInstanceDialog.close();
504
+ render();
505
+ });
506
+
507
+ render();
508
+ refresh();
509
+ setInterval(refresh, 10000);
510
+ </script>
511
+ </body>
512
+ </html>
package/instances.js ADDED
@@ -0,0 +1,69 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execFile } = require('child_process');
4
+ const { promisify } = require('util');
5
+
6
+ const execFileAsync = promisify(execFile);
7
+ const instancePrefix = 'Claude-Profile-';
8
+
9
+ function listInstances(appData) {
10
+ return fs.readdirSync(appData, { withFileTypes: true })
11
+ .filter(entry => entry.isDirectory() && entry.name.startsWith(instancePrefix))
12
+ .map(entry => {
13
+ const id = entry.name.slice(instancePrefix.length);
14
+ return { id, name: id.replace(/_/g, ' ') };
15
+ });
16
+ }
17
+
18
+ function runningInstances(processes, claudePath, appData) {
19
+ const normalize = value => path.win32.normalize(value).toLowerCase();
20
+ const running = new Set();
21
+ let defaultRunning = false;
22
+
23
+ for (const process of processes) {
24
+ if (!process.ExecutablePath || !process.CommandLine) {
25
+ throw new Error('Some Claude process details are unavailable.');
26
+ }
27
+ if (normalize(process.ExecutablePath) !== normalize(claudePath)) continue;
28
+ if (/(?:^|\s)"?--type(?:=|\s)/i.test(process.CommandLine)) continue;
29
+
30
+ const match = process.CommandLine.match(/(?:^|\s)(?:"--user-data-dir=([^"]+)"|--user-data-dir(?:=|\s+)(?:"([^"]+)"|(\S+)))/i);
31
+ if (!match) {
32
+ if (/--user-data-dir/i.test(process.CommandLine)) {
33
+ throw new Error('A Claude instance path could not be determined.');
34
+ }
35
+ defaultRunning = true;
36
+ continue;
37
+ }
38
+
39
+ const instancePath = match[1] || match[2] || match[3];
40
+ const directory = path.win32.dirname(instancePath);
41
+ const name = path.win32.basename(instancePath);
42
+ if (normalize(directory) === normalize(appData) && name.toLowerCase().startsWith(instancePrefix.toLowerCase())) {
43
+ running.add(name.slice(instancePrefix.length).toLowerCase());
44
+ }
45
+ }
46
+ return { defaultRunning, instances: [...running] };
47
+ }
48
+
49
+ async function getRunningInstances(claudePath, appData) {
50
+ const command = `
51
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
52
+ $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
53
+ $items = @(foreach ($process in @(Get-CimInstance Win32_Process -Filter "Name = 'claude.exe'" -ErrorAction Stop)) {
54
+ if ($process.CommandLine -match '(?:^|\\s)"?--type(?:=|\\s)') { continue }
55
+ $owner = Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid -ErrorAction Stop
56
+ if ($owner.ReturnValue -ne 0) { throw 'Could not determine Claude process owner.' }
57
+ if ($owner.Sid -eq $sid) { $process | Select-Object ExecutablePath, CommandLine }
58
+ })
59
+ ConvertTo-Json -InputObject $items -Compress
60
+ `;
61
+ const { stdout } = await execFileAsync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], {
62
+ encoding: 'utf8',
63
+ timeout: 10000,
64
+ windowsHide: true
65
+ });
66
+ return runningInstances(JSON.parse(stdout), claudePath, appData);
67
+ }
68
+
69
+ module.exports = { listInstances, runningInstances, getRunningInstances };