@bakapiano/ccsm 0.14.0 → 0.15.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/CLAUDE.md +474 -475
- package/README.md +189 -190
- package/bin/ccsm.js +194 -194
- package/lib/cliActivity.js +118 -0
- package/lib/codexSeed.js +147 -0
- package/lib/config.js +211 -188
- package/lib/folders.js +105 -105
- package/lib/localCliSessions.js +489 -489
- package/lib/persistedSessions.js +144 -142
- package/lib/webTerminal.js +224 -224
- package/lib/workspace.js +230 -230
- package/package.json +57 -57
- package/public/css/base.css +99 -99
- package/public/css/cards.css +183 -183
- package/public/css/feedback.css +303 -303
- package/public/css/forms.css +405 -405
- package/public/css/layout.css +160 -160
- package/public/css/modal.css +190 -190
- package/public/css/responsive.css +10 -10
- package/public/css/sidebar.css +613 -608
- package/public/css/terminals.css +294 -294
- package/public/css/tokens.css +81 -81
- package/public/css/wco.css +98 -98
- package/public/css/widgets.css +1628 -1628
- package/public/index.html +111 -105
- package/public/js/api.js +296 -280
- package/public/js/components/AdoptModal.js +343 -343
- package/public/js/components/App.js +35 -35
- package/public/js/components/DirectoryPicker.js +203 -203
- package/public/js/components/EntityFormModal.js +141 -141
- package/public/js/components/Modal.js +51 -51
- package/public/js/components/OfflineBanner.js +93 -93
- package/public/js/components/PageTitleBar.js +13 -13
- package/public/js/components/Picker.js +179 -179
- package/public/js/components/Popover.js +55 -55
- package/public/js/components/Sidebar.js +299 -299
- package/public/js/components/TerminalView.js +314 -314
- package/public/js/components/useDragSort.js +67 -67
- package/public/js/dialog.js +67 -67
- package/public/js/icons.js +177 -177
- package/public/js/main.js +132 -132
- package/public/js/pages/AboutPage.js +165 -165
- package/public/js/pages/ConfigurePage.js +505 -475
- package/public/js/pages/LaunchPage.js +369 -369
- package/public/js/pages/SessionsPage.js +101 -97
- package/public/js/state.js +231 -231
- package/scripts/dev.js +44 -11
- package/scripts/install.js +158 -158
- package/scripts/restart-helper.js +91 -0
- package/server.js +1278 -1254
- package/lib/cliSessionWatcher.js +0 -275
- package/public/manifest.webmanifest +0 -15
package/lib/cliSessionWatcher.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Captures the upstream CLI's session id (claude / codex / copilot) so
|
|
4
|
-
// ccsm can later spawn `<cli> --resume <uuid>` and reattach to the same
|
|
5
|
-
// conversation precisely.
|
|
6
|
-
//
|
|
7
|
-
// Approach (poll-based, deliberately):
|
|
8
|
-
// - fs.watch is unreliable on Windows for in-place content writes.
|
|
9
|
-
// - CLIs reuse existing transcripts in the same cwd when they can —
|
|
10
|
-
// there's no "new file appears" signal to wait on.
|
|
11
|
-
// - Instead we poll the per-CLI transcript dir every POLL_MS, find
|
|
12
|
-
// candidates whose mtime > spawnAt, read each one's cwd field, and
|
|
13
|
-
// if exactly one matches our spawn cwd that's the session id.
|
|
14
|
-
// - Window expires after WINDOW_MS — CLIs only persist after the first
|
|
15
|
-
// user message, so this needs to be generous.
|
|
16
|
-
//
|
|
17
|
-
// Per-CLI profile shape:
|
|
18
|
-
// dirFor(cwd) → directory to poll
|
|
19
|
-
// entryType → 'file' (claude/codex) or 'dir' (copilot —
|
|
20
|
-
// each child dir = one session)
|
|
21
|
-
// recursive → for 'file' mode only; walk subdirs too
|
|
22
|
-
// filePattern → regex an entry's basename must match
|
|
23
|
-
// parseId(basename) → extract the upstream session id from name
|
|
24
|
-
// (returns null to skip)
|
|
25
|
-
// readCwd(entryPath) → async; returns the cwd recorded inside the
|
|
26
|
-
// session, or null if not yet readable.
|
|
27
|
-
|
|
28
|
-
const fs = require('node:fs');
|
|
29
|
-
const fsp = require('node:fs/promises');
|
|
30
|
-
const path = require('node:path');
|
|
31
|
-
const os = require('node:os');
|
|
32
|
-
const readline = require('node:readline');
|
|
33
|
-
|
|
34
|
-
const POLL_MS = 1_500;
|
|
35
|
-
const WINDOW_MS = 5 * 60_000;
|
|
36
|
-
|
|
37
|
-
// Module-level set of upstream session UUIDs known to belong to some
|
|
38
|
-
// ccsm session — either persisted on disk (seeded at watcher start via
|
|
39
|
-
// the excludeIds arg), or captured by another in-flight watcher in
|
|
40
|
-
// THIS server's lifetime. Grows monotonically; we never unclaim because
|
|
41
|
-
// the file-level cliSessionId is sticky too.
|
|
42
|
-
//
|
|
43
|
-
// Why module-level rather than per-watcher: when two ccsm sessions
|
|
44
|
-
// spawn back-to-back in the same cwd, the FIRST watcher might capture
|
|
45
|
-
// its UUID AFTER the second watcher started. The second watcher needs
|
|
46
|
-
// to see "this UUID just got claimed" without us threading a notify
|
|
47
|
-
// callback. Sharing the set in module scope is the simplest fix.
|
|
48
|
-
const claimedIds = new Set();
|
|
49
|
-
|
|
50
|
-
const profiles = {
|
|
51
|
-
claude: {
|
|
52
|
-
dirFor: (cwd) => path.join(os.homedir(), '.claude', 'projects', claudeSlug(cwd)),
|
|
53
|
-
entryType: 'file',
|
|
54
|
-
filePattern: /\.jsonl$/i,
|
|
55
|
-
parseId: (filename) => filename.replace(/\.jsonl$/i, ''),
|
|
56
|
-
readCwd: (filepath) => firstJsonField(filepath, 'cwd', 12),
|
|
57
|
-
},
|
|
58
|
-
codex: {
|
|
59
|
-
dirFor: () => path.join(os.homedir(), '.codex', 'sessions'),
|
|
60
|
-
entryType: 'file',
|
|
61
|
-
recursive: true,
|
|
62
|
-
filePattern: /\.jsonl$/i,
|
|
63
|
-
parseId: (filename) => {
|
|
64
|
-
const m = filename.match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i);
|
|
65
|
-
return m ? m[1] : null;
|
|
66
|
-
},
|
|
67
|
-
readCwd: (filepath) => firstJsonField(filepath, 'cwd', 12),
|
|
68
|
-
},
|
|
69
|
-
copilot: {
|
|
70
|
-
// ~/.copilot/session-state/<uuid>/ with workspace.yaml + events.jsonl
|
|
71
|
-
// Each session is a directory, not a single file.
|
|
72
|
-
dirFor: () => path.join(os.homedir(), '.copilot', 'session-state'),
|
|
73
|
-
entryType: 'dir',
|
|
74
|
-
// Subdir name is the uuid; tolerate any non-empty name (copilot uses
|
|
75
|
-
// standard uuid4 but we'd rather not be strict).
|
|
76
|
-
parseId: (dirname) => /^[0-9a-f-]+$/i.test(dirname) ? dirname : null,
|
|
77
|
-
readCwd: async (dirpath) => {
|
|
78
|
-
// workspace.yaml has plain `cwd: <path>` on its own line — quick
|
|
79
|
-
// regex parse, no YAML dep.
|
|
80
|
-
const yaml = path.join(dirpath, 'workspace.yaml');
|
|
81
|
-
try {
|
|
82
|
-
const txt = await fsp.readFile(yaml, 'utf8');
|
|
83
|
-
const m = txt.match(/^\s*cwd\s*:\s*(.+?)\s*$/m);
|
|
84
|
-
return m ? m[1].trim() : null;
|
|
85
|
-
} catch {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
function captureSessionId({ cliType, cwd, onCapture, onTimeout, windowMs = WINDOW_MS, excludeIds = [] }) {
|
|
93
|
-
const profile = profiles[cliType];
|
|
94
|
-
if (!profile) return () => {};
|
|
95
|
-
const dir = profile.dirFor(cwd);
|
|
96
|
-
const spawnAt = Date.now();
|
|
97
|
-
// Seed module-level claimedIds with the caller's view of "already
|
|
98
|
-
// assigned" UUIDs (typically persistedSessions cliSessionIds). The
|
|
99
|
-
// poll loop reads claimedIds fresh every tick so concurrent watchers
|
|
100
|
-
// see each other's captures.
|
|
101
|
-
for (const id of (excludeIds || [])) if (id) claimedIds.add(id);
|
|
102
|
-
console.log(`[cliSessionWatcher] start ${cliType} dir=${dir} cwd=${cwd}${claimedIds.size ? ` claimed=${claimedIds.size}` : ''}`);
|
|
103
|
-
|
|
104
|
-
let stopped = false;
|
|
105
|
-
let captured = false;
|
|
106
|
-
let pollTimer = null;
|
|
107
|
-
let expireTimer = null;
|
|
108
|
-
// Track entries we've already proven aren't ours so we don't re-read them.
|
|
109
|
-
// Only used for "wrong cwd recorded inside the file" — that's stable.
|
|
110
|
-
// We do NOT cache mtime-based rejections: a stale file can be re-touched
|
|
111
|
-
// by the CLI later (claude appends to existing transcripts) and we want
|
|
112
|
-
// to re-evaluate it then.
|
|
113
|
-
const rejected = new Set();
|
|
114
|
-
|
|
115
|
-
const cleanup = () => {
|
|
116
|
-
if (stopped) return;
|
|
117
|
-
stopped = true;
|
|
118
|
-
if (pollTimer) clearTimeout(pollTimer);
|
|
119
|
-
if (expireTimer) clearTimeout(expireTimer);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const finish = (sessionId) => {
|
|
123
|
-
if (stopped) return;
|
|
124
|
-
captured = true;
|
|
125
|
-
// Add to module-level claimedIds BEFORE firing onCapture so any
|
|
126
|
-
// concurrent watcher polling at the same instant won't also grab
|
|
127
|
-
// this UUID. Sticky for the lifetime of the server.
|
|
128
|
-
claimedIds.add(sessionId);
|
|
129
|
-
cleanup();
|
|
130
|
-
console.log(`[cliSessionWatcher] captured ${cliType} ${sessionId}`);
|
|
131
|
-
try { onCapture?.(sessionId); } catch (e) { console.error('[cliSessionWatcher] onCapture:', e); }
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const onExpire = () => {
|
|
135
|
-
if (stopped || captured) return;
|
|
136
|
-
cleanup();
|
|
137
|
-
console.warn(`[cliSessionWatcher] timeout ${cliType} (no transcript in ${Math.round(windowMs / 1000)}s) cwd=${cwd}`);
|
|
138
|
-
try { onTimeout?.(); } catch (e) { console.error('[cliSessionWatcher] onTimeout:', e); }
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const poll = async () => {
|
|
142
|
-
if (stopped) return;
|
|
143
|
-
try {
|
|
144
|
-
const entries = await listEntries(dir, profile);
|
|
145
|
-
console.log(`[cliSessionWatcher] poll: ${entries.length} entries, rejected=${rejected.size}`);
|
|
146
|
-
const candidates = [];
|
|
147
|
-
for (const entryPath of entries) {
|
|
148
|
-
const base = path.basename(entryPath);
|
|
149
|
-
if (rejected.has(entryPath)) continue;
|
|
150
|
-
if (profile.filePattern && !profile.filePattern.test(base)) continue;
|
|
151
|
-
const id = profile.parseId(base);
|
|
152
|
-
if (!id) continue;
|
|
153
|
-
// Already-claimed-by-another-ccsm-session UUIDs are never ours.
|
|
154
|
-
// claimedIds is module-level so concurrent watchers see each
|
|
155
|
-
// other's captures (not just the snapshot at our spawn time).
|
|
156
|
-
if (claimedIds.has(id)) { rejected.add(entryPath); continue; }
|
|
157
|
-
let st;
|
|
158
|
-
try { st = await fsp.stat(entryPath); } catch { continue; }
|
|
159
|
-
// Mtime gate is re-evaluated every poll: don't memoise it. If the
|
|
160
|
-
// CLI later re-touches an old transcript (claude appends to the
|
|
161
|
-
// existing one for the cwd), this poll will pick it up.
|
|
162
|
-
if (st.mtimeMs < spawnAt - 2000) continue;
|
|
163
|
-
candidates.push({ entryPath, id, mtime: st.mtimeMs });
|
|
164
|
-
}
|
|
165
|
-
const matched = [];
|
|
166
|
-
for (const c of candidates) {
|
|
167
|
-
const cwdFromEntry = await profile.readCwd(c.entryPath);
|
|
168
|
-
if (cwdFromEntry == null) continue; // not enough data yet
|
|
169
|
-
if (!samePath(cwdFromEntry, cwd)) { rejected.add(c.entryPath); continue; }
|
|
170
|
-
matched.push(c);
|
|
171
|
-
}
|
|
172
|
-
if (matched.length === 1) {
|
|
173
|
-
finish(matched[0].id);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (matched.length > 1) {
|
|
177
|
-
console.warn(`[cliSessionWatcher] ambiguous: ${matched.length} candidates for ${cwd} — skipping capture`);
|
|
178
|
-
cleanup();
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
} catch (e) {
|
|
182
|
-
console.error('[cliSessionWatcher] poll:', e.message);
|
|
183
|
-
}
|
|
184
|
-
if (!stopped) pollTimer = setTimeout(poll, POLL_MS);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
(async () => {
|
|
188
|
-
try { await fsp.mkdir(dir, { recursive: true }); } catch {}
|
|
189
|
-
if (stopped) return;
|
|
190
|
-
expireTimer = setTimeout(onExpire, windowMs);
|
|
191
|
-
poll();
|
|
192
|
-
})();
|
|
193
|
-
|
|
194
|
-
return cleanup;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
module.exports = { captureSessionId };
|
|
198
|
-
|
|
199
|
-
// ── helpers ─────────────────────────────────────────────────────────
|
|
200
|
-
|
|
201
|
-
async function listEntries(root, profile) {
|
|
202
|
-
if (profile.entryType === 'dir') {
|
|
203
|
-
let names;
|
|
204
|
-
try { names = await fsp.readdir(root, { withFileTypes: true }); }
|
|
205
|
-
catch { return []; }
|
|
206
|
-
return names.filter((e) => e.isDirectory()).map((e) => path.join(root, e.name));
|
|
207
|
-
}
|
|
208
|
-
// file mode
|
|
209
|
-
if (profile.recursive) return listAllFiles(root);
|
|
210
|
-
try {
|
|
211
|
-
const names = await fsp.readdir(root);
|
|
212
|
-
return names.map((n) => path.join(root, n));
|
|
213
|
-
} catch {
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function claudeSlug(cwd) {
|
|
219
|
-
return cwd.replace(/[:\\\/]/g, '-');
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function samePath(a, b) {
|
|
223
|
-
if (!a || !b) return false;
|
|
224
|
-
const norm = (p) => path.resolve(p).replace(/[\\\/]+$/, '').toLowerCase();
|
|
225
|
-
return norm(a) === norm(b);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async function firstJsonField(filepath, field, maxLines) {
|
|
229
|
-
return new Promise((resolve) => {
|
|
230
|
-
let stream;
|
|
231
|
-
try { stream = fs.createReadStream(filepath, { encoding: 'utf8' }); }
|
|
232
|
-
catch { resolve(null); return; }
|
|
233
|
-
const rl = readline.createInterface({ input: stream });
|
|
234
|
-
let count = 0;
|
|
235
|
-
// rl.close() synchronously emits 'close' on some platforms, which would
|
|
236
|
-
// re-enter done(null) and clobber the value resolve. Guard against that.
|
|
237
|
-
let settled = false;
|
|
238
|
-
const done = (v) => {
|
|
239
|
-
if (settled) return;
|
|
240
|
-
settled = true;
|
|
241
|
-
try { rl.close(); } catch {}
|
|
242
|
-
try { stream.destroy(); } catch {}
|
|
243
|
-
resolve(v);
|
|
244
|
-
};
|
|
245
|
-
rl.on('line', (line) => {
|
|
246
|
-
count++;
|
|
247
|
-
try {
|
|
248
|
-
const obj = JSON.parse(line);
|
|
249
|
-
if (obj && Object.prototype.hasOwnProperty.call(obj, field)) {
|
|
250
|
-
done(obj[field]);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
} catch {}
|
|
254
|
-
if (count >= maxLines) done(null);
|
|
255
|
-
});
|
|
256
|
-
rl.on('close', () => done(null));
|
|
257
|
-
rl.on('error', () => done(null));
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async function listAllFiles(root) {
|
|
262
|
-
const out = [];
|
|
263
|
-
const walk = async (dir) => {
|
|
264
|
-
let entries;
|
|
265
|
-
try { entries = await fsp.readdir(dir, { withFileTypes: true }); }
|
|
266
|
-
catch { return; }
|
|
267
|
-
for (const e of entries) {
|
|
268
|
-
const p = path.join(dir, e.name);
|
|
269
|
-
if (e.isDirectory()) await walk(p);
|
|
270
|
-
else out.push(p);
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
await walk(root);
|
|
274
|
-
return out;
|
|
275
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "CCSM",
|
|
3
|
-
"short_name": "CCSM",
|
|
4
|
-
"version": "0.0.0-dev",
|
|
5
|
-
"description": "Single pane over every live claude session on this machine.",
|
|
6
|
-
"start_url": "./",
|
|
7
|
-
"scope": "./",
|
|
8
|
-
"display": "standalone",
|
|
9
|
-
"display_override": ["window-controls-overlay", "standalone"],
|
|
10
|
-
"background_color": "#f6f8fa",
|
|
11
|
-
"theme_color": "#f6f8fa",
|
|
12
|
-
"icons": [
|
|
13
|
-
{ "src": "favicon.svg", "type": "image/svg+xml", "sizes": "any", "purpose": "any" }
|
|
14
|
-
]
|
|
15
|
-
}
|