@bakapiano/ccsm 0.22.6 → 0.22.8
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 +521 -540
- package/README.md +186 -189
- package/bin/ccsm.js +235 -235
- package/lib/cliActivity.js +36 -139
- package/lib/codexSeed.js +126 -183
- package/lib/config.js +277 -274
- package/lib/devices.js +229 -229
- package/lib/folders.js +124 -124
- package/lib/persistedSessions.js +179 -139
- package/lib/tunnel.js +621 -621
- package/lib/webTerminal.js +225 -225
- package/lib/winPath.js +1 -1
- package/lib/workspace.js +233 -233
- package/package.json +57 -57
- package/public/css/base.css +99 -99
- package/public/css/cards.css +183 -183
- package/public/css/feedback.css +504 -504
- package/public/css/forms.css +453 -453
- package/public/css/layout.css +154 -154
- package/public/css/modal.css +190 -190
- package/public/css/responsive.css +176 -176
- package/public/css/sidebar.css +707 -707
- package/public/css/terminals.css +546 -546
- package/public/css/tokens.css +81 -81
- package/public/css/wco.css +196 -196
- package/public/css/widgets.css +2347 -2725
- package/public/index.html +152 -152
- package/public/js/api.js +349 -371
- package/public/js/backend.js +149 -149
- package/public/js/components/App.js +73 -73
- package/public/js/components/DirectoryPicker.js +203 -203
- package/public/js/components/EntityFormModal.js +153 -153
- package/public/js/components/Modal.js +57 -57
- package/public/js/components/OfflineBanner.js +67 -67
- package/public/js/components/PageTitleBar.js +13 -13
- package/public/js/components/PendingApprovalOverlay.js +128 -128
- package/public/js/components/Picker.js +179 -179
- package/public/js/components/Popover.js +55 -55
- package/public/js/components/RestartOverlay.js +36 -36
- package/public/js/components/Sidebar.js +380 -380
- package/public/js/components/TerminalInstance.js +28 -0
- package/public/js/components/useDragSort.js +67 -67
- package/public/js/dialog.js +67 -67
- package/public/js/icons.js +212 -212
- package/public/js/main.js +296 -296
- package/public/js/pages/AboutPage.js +90 -90
- package/public/js/pages/ConfigurePage.js +730 -713
- package/public/js/pages/LaunchPage.js +403 -421
- package/public/js/pages/RemotePage.js +743 -743
- package/public/js/pages/SessionsPage.js +54 -54
- package/public/js/state.js +335 -335
- package/public/js/util.js +1 -1
- package/scripts/dev.js +149 -149
- package/scripts/install.js +153 -153
- package/scripts/restart-helper.js +96 -96
- package/scripts/upgrade-helper.js +687 -687
- package/server.js +1748 -1817
- package/lib/localCliSessions.js +0 -519
- package/public/js/components/AdoptModal.js +0 -261
- package/public/manifest.webmanifest +0 -25
- package/public/setup/index.html +0 -567
package/lib/folders.js
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// User-curated folders. Sessions reference these by id. Order is
|
|
4
|
-
// user-controlled (drag-reorder in sidebar). The store is a flat list
|
|
5
|
-
// in $DATA_DIR/folders.json:
|
|
6
|
-
// [{ id, name, order, createdAt }]
|
|
7
|
-
//
|
|
8
|
-
// Top-level "Unsorted" is implicit — sessions with folderId === null
|
|
9
|
-
// render under it. The user can't delete or rename it; we just synthesise
|
|
10
|
-
// the bucket in the frontend.
|
|
11
|
-
|
|
12
|
-
const path = require('node:path');
|
|
13
|
-
const fs = require('node:fs/promises');
|
|
14
|
-
const { DATA_DIR } = require('./config');
|
|
15
|
-
const { atomicWriteJson, withFileLock } = require('./atomicJson');
|
|
16
|
-
|
|
17
|
-
const FILE = path.join(DATA_DIR, 'folders.json');
|
|
18
|
-
|
|
19
|
-
// Sentinel for the synthetic "Unsorted" folder. Sessions with
|
|
20
|
-
// folderId === null render under it. We always materialize it in the
|
|
21
|
-
// returned list so the sidebar can drag-reorder it like a real folder,
|
|
22
|
-
// but create/update/delete refuse to touch it.
|
|
23
|
-
const UNSORTED_ID = 'unsorted';
|
|
24
|
-
function unsortedDefault(order) {
|
|
25
|
-
return { id: UNSORTED_ID, name: 'Unsorted', order, builtin: true };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function loadAll() {
|
|
29
|
-
let list = [];
|
|
30
|
-
try {
|
|
31
|
-
const raw = await fs.readFile(FILE, 'utf8');
|
|
32
|
-
const j = JSON.parse(raw);
|
|
33
|
-
if (Array.isArray(j)) list = j;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e.code !== 'ENOENT') throw e;
|
|
36
|
-
}
|
|
37
|
-
// Ensure the synthetic Unsorted entry is present. New install: append
|
|
38
|
-
// at the end. Existing install pre-Unsorted-draggable: same.
|
|
39
|
-
if (!list.find((f) => f.id === UNSORTED_ID)) {
|
|
40
|
-
list = list.concat(unsortedDefault(list.length));
|
|
41
|
-
}
|
|
42
|
-
return list;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function saveAll(list) {
|
|
46
|
-
await atomicWriteJson(FILE, list);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function genId() {
|
|
50
|
-
return 'folder-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function create({ name }) {
|
|
54
|
-
if (!name || typeof name !== 'string') throw new Error('name required');
|
|
55
|
-
return withFileLock(FILE, async () => {
|
|
56
|
-
const list = await loadAll();
|
|
57
|
-
const entry = {
|
|
58
|
-
id: genId(),
|
|
59
|
-
name: name.trim(),
|
|
60
|
-
order: list.length,
|
|
61
|
-
createdAt: Date.now(),
|
|
62
|
-
};
|
|
63
|
-
list.push(entry);
|
|
64
|
-
await saveAll(list);
|
|
65
|
-
return entry;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function update(id, patch) {
|
|
70
|
-
if (id === UNSORTED_ID && typeof patch.name === 'string') {
|
|
71
|
-
throw new Error('cannot rename the Unsorted bucket');
|
|
72
|
-
}
|
|
73
|
-
return withFileLock(FILE, async () => {
|
|
74
|
-
const list = await loadAll();
|
|
75
|
-
const idx = list.findIndex((f) => f.id === id);
|
|
76
|
-
if (idx < 0) return null;
|
|
77
|
-
// Allow rename + reorder, ignore other keys.
|
|
78
|
-
const allowed = {};
|
|
79
|
-
if (id !== UNSORTED_ID && typeof patch.name === 'string') allowed.name = patch.name.trim();
|
|
80
|
-
if (typeof patch.order === 'number') allowed.order = patch.order;
|
|
81
|
-
list[idx] = { ...list[idx], ...allowed };
|
|
82
|
-
await saveAll(list);
|
|
83
|
-
return list[idx];
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function remove(id) {
|
|
88
|
-
if (id === UNSORTED_ID) throw new Error('cannot delete the Unsorted bucket');
|
|
89
|
-
return withFileLock(FILE, async () => {
|
|
90
|
-
const list = await loadAll();
|
|
91
|
-
const idx = list.findIndex((f) => f.id === id);
|
|
92
|
-
if (idx < 0) return false;
|
|
93
|
-
list.splice(idx, 1);
|
|
94
|
-
await saveAll(list);
|
|
95
|
-
return true;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function reorder(idsInOrder) {
|
|
100
|
-
if (!Array.isArray(idsInOrder)) throw new Error('idsInOrder must be array');
|
|
101
|
-
return withFileLock(FILE, async () => {
|
|
102
|
-
const list = await loadAll();
|
|
103
|
-
const byId = new Map(list.map((f) => [f.id, f]));
|
|
104
|
-
const next = [];
|
|
105
|
-
idsInOrder.forEach((id, i) => {
|
|
106
|
-
const f = byId.get(id);
|
|
107
|
-
if (f) {
|
|
108
|
-
f.order = i;
|
|
109
|
-
next.push(f);
|
|
110
|
-
byId.delete(id);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
// Append any folders not mentioned in the new order, preserving original
|
|
114
|
-
// relative order. Prevents accidentally dropping folders.
|
|
115
|
-
for (const f of byId.values()) {
|
|
116
|
-
f.order = next.length;
|
|
117
|
-
next.push(f);
|
|
118
|
-
}
|
|
119
|
-
await saveAll(next);
|
|
120
|
-
return next;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
module.exports = { loadAll, create, update, remove, reorder, FILE };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// User-curated folders. Sessions reference these by id. Order is
|
|
4
|
+
// user-controlled (drag-reorder in sidebar). The store is a flat list
|
|
5
|
+
// in $DATA_DIR/folders.json:
|
|
6
|
+
// [{ id, name, order, createdAt }]
|
|
7
|
+
//
|
|
8
|
+
// Top-level "Unsorted" is implicit — sessions with folderId === null
|
|
9
|
+
// render under it. The user can't delete or rename it; we just synthesise
|
|
10
|
+
// the bucket in the frontend.
|
|
11
|
+
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const fs = require('node:fs/promises');
|
|
14
|
+
const { DATA_DIR } = require('./config');
|
|
15
|
+
const { atomicWriteJson, withFileLock } = require('./atomicJson');
|
|
16
|
+
|
|
17
|
+
const FILE = path.join(DATA_DIR, 'folders.json');
|
|
18
|
+
|
|
19
|
+
// Sentinel for the synthetic "Unsorted" folder. Sessions with
|
|
20
|
+
// folderId === null render under it. We always materialize it in the
|
|
21
|
+
// returned list so the sidebar can drag-reorder it like a real folder,
|
|
22
|
+
// but create/update/delete refuse to touch it.
|
|
23
|
+
const UNSORTED_ID = 'unsorted';
|
|
24
|
+
function unsortedDefault(order) {
|
|
25
|
+
return { id: UNSORTED_ID, name: 'Unsorted', order, builtin: true };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function loadAll() {
|
|
29
|
+
let list = [];
|
|
30
|
+
try {
|
|
31
|
+
const raw = await fs.readFile(FILE, 'utf8');
|
|
32
|
+
const j = JSON.parse(raw);
|
|
33
|
+
if (Array.isArray(j)) list = j;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e.code !== 'ENOENT') throw e;
|
|
36
|
+
}
|
|
37
|
+
// Ensure the synthetic Unsorted entry is present. New install: append
|
|
38
|
+
// at the end. Existing install pre-Unsorted-draggable: same.
|
|
39
|
+
if (!list.find((f) => f.id === UNSORTED_ID)) {
|
|
40
|
+
list = list.concat(unsortedDefault(list.length));
|
|
41
|
+
}
|
|
42
|
+
return list;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function saveAll(list) {
|
|
46
|
+
await atomicWriteJson(FILE, list);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function genId() {
|
|
50
|
+
return 'folder-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function create({ name }) {
|
|
54
|
+
if (!name || typeof name !== 'string') throw new Error('name required');
|
|
55
|
+
return withFileLock(FILE, async () => {
|
|
56
|
+
const list = await loadAll();
|
|
57
|
+
const entry = {
|
|
58
|
+
id: genId(),
|
|
59
|
+
name: name.trim(),
|
|
60
|
+
order: list.length,
|
|
61
|
+
createdAt: Date.now(),
|
|
62
|
+
};
|
|
63
|
+
list.push(entry);
|
|
64
|
+
await saveAll(list);
|
|
65
|
+
return entry;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function update(id, patch) {
|
|
70
|
+
if (id === UNSORTED_ID && typeof patch.name === 'string') {
|
|
71
|
+
throw new Error('cannot rename the Unsorted bucket');
|
|
72
|
+
}
|
|
73
|
+
return withFileLock(FILE, async () => {
|
|
74
|
+
const list = await loadAll();
|
|
75
|
+
const idx = list.findIndex((f) => f.id === id);
|
|
76
|
+
if (idx < 0) return null;
|
|
77
|
+
// Allow rename + reorder, ignore other keys.
|
|
78
|
+
const allowed = {};
|
|
79
|
+
if (id !== UNSORTED_ID && typeof patch.name === 'string') allowed.name = patch.name.trim();
|
|
80
|
+
if (typeof patch.order === 'number') allowed.order = patch.order;
|
|
81
|
+
list[idx] = { ...list[idx], ...allowed };
|
|
82
|
+
await saveAll(list);
|
|
83
|
+
return list[idx];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function remove(id) {
|
|
88
|
+
if (id === UNSORTED_ID) throw new Error('cannot delete the Unsorted bucket');
|
|
89
|
+
return withFileLock(FILE, async () => {
|
|
90
|
+
const list = await loadAll();
|
|
91
|
+
const idx = list.findIndex((f) => f.id === id);
|
|
92
|
+
if (idx < 0) return false;
|
|
93
|
+
list.splice(idx, 1);
|
|
94
|
+
await saveAll(list);
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function reorder(idsInOrder) {
|
|
100
|
+
if (!Array.isArray(idsInOrder)) throw new Error('idsInOrder must be array');
|
|
101
|
+
return withFileLock(FILE, async () => {
|
|
102
|
+
const list = await loadAll();
|
|
103
|
+
const byId = new Map(list.map((f) => [f.id, f]));
|
|
104
|
+
const next = [];
|
|
105
|
+
idsInOrder.forEach((id, i) => {
|
|
106
|
+
const f = byId.get(id);
|
|
107
|
+
if (f) {
|
|
108
|
+
f.order = i;
|
|
109
|
+
next.push(f);
|
|
110
|
+
byId.delete(id);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// Append any folders not mentioned in the new order, preserving original
|
|
114
|
+
// relative order. Prevents accidentally dropping folders.
|
|
115
|
+
for (const f of byId.values()) {
|
|
116
|
+
f.order = next.length;
|
|
117
|
+
next.push(f);
|
|
118
|
+
}
|
|
119
|
+
await saveAll(next);
|
|
120
|
+
return next;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { loadAll, create, update, remove, reorder, FILE };
|
package/lib/persistedSessions.js
CHANGED
|
@@ -1,148 +1,188 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// ccsm-owned session records. Replaces the old "scan ~/.claude/sessions/
|
|
4
|
-
// + tasklist" path entirely: we no longer try to enumerate every claude
|
|
5
|
-
// process on the machine. Instead, every session ccsm starts (via the
|
|
6
|
-
// web terminal) gets recorded here, and the user organises them in
|
|
7
|
-
// folders.
|
|
8
|
-
//
|
|
9
|
-
// Each entry:
|
|
10
|
-
// {
|
|
11
|
-
// id: 'sess-...', // ccsm's session id (matches webTerminal id)
|
|
12
|
-
// cliId: 'claude', // which CLI from config.clis
|
|
13
|
-
// cwd: '...', // absolute workspace
|
|
14
|
-
// workspace: 'ws-3', //
|
|
15
|
-
// title: '', // user-edited label (Configure / sidebar tree)
|
|
16
|
-
// folderId: null, // nullable; null = "Unsorted" top-level
|
|
17
|
-
// repos: ['foo','bar'], //
|
|
18
|
-
// createdAt: 1234,
|
|
19
|
-
// lastActiveAt: 1234, // updated on attach/input; drives sort
|
|
20
|
-
// status: 'running'|'exited',
|
|
21
|
-
// exitedAt: null,
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ccsm-owned session records. Replaces the old "scan ~/.claude/sessions/
|
|
4
|
+
// + tasklist" path entirely: we no longer try to enumerate every claude
|
|
5
|
+
// process on the machine. Instead, every session ccsm starts (via the
|
|
6
|
+
// web terminal) gets recorded here, and the user organises them in
|
|
7
|
+
// folders.
|
|
8
|
+
//
|
|
9
|
+
// Each entry:
|
|
10
|
+
// {
|
|
11
|
+
// id: 'sess-...', // ccsm's session id (matches webTerminal id)
|
|
12
|
+
// cliId: 'claude', // which CLI from config.clis
|
|
13
|
+
// cwd: '...', // absolute launch path (workspace or repo)
|
|
14
|
+
// workspace: 'ws-3', // workspace display name
|
|
15
|
+
// title: '', // user-edited label (Configure / sidebar tree)
|
|
16
|
+
// folderId: null, // nullable; null = "Unsorted" top-level
|
|
17
|
+
// repos: ['foo','bar'], // selected repo names cloned at launch
|
|
18
|
+
// createdAt: 1234,
|
|
19
|
+
// lastActiveAt: 1234, // updated on attach/input; drives sort
|
|
20
|
+
// status: 'running'|'exited',
|
|
21
|
+
// exitedAt: null,
|
|
22
22
|
// exitCode: null,
|
|
23
23
|
// pid: null, // current pid if running
|
|
24
|
-
// cliSessionId: null, // upstream CLI's session UUID. Pre-assigned
|
|
25
|
-
// // at spawn time for CLIs with
|
|
26
|
-
// // newSessionIdArgs (claude, copilot); set
|
|
27
|
-
// // from disk for adopted sessions. Used
|
|
28
|
-
// // for precise --resume <id>.
|
|
29
24
|
// manualStopped: false, // true only when the user explicitly stopped
|
|
30
25
|
// // it from ccsm; prevents auto-resume until
|
|
31
26
|
// // they press Resume.
|
|
32
27
|
// }
|
|
33
|
-
|
|
34
|
-
const path = require('node:path');
|
|
35
|
-
const fs = require('node:fs/promises');
|
|
36
|
-
const { DATA_DIR } = require('./config');
|
|
37
|
-
const { atomicWriteJson, withFileLock } = require('./atomicJson');
|
|
38
|
-
|
|
39
|
-
const FILE = path.join(DATA_DIR, 'sessions.json');
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
28
|
+
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
const fs = require('node:fs/promises');
|
|
31
|
+
const { DATA_DIR } = require('./config');
|
|
32
|
+
const { atomicWriteJson, withFileLock } = require('./atomicJson');
|
|
33
|
+
|
|
34
|
+
const FILE = path.join(DATA_DIR, 'sessions.json');
|
|
35
|
+
|
|
36
|
+
function normalizeEntry(entry) {
|
|
37
|
+
if (!entry || typeof entry !== 'object') return entry;
|
|
38
|
+
const { cliSessionId, ...rest } = entry;
|
|
39
|
+
return rest;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function loadAll() {
|
|
43
|
+
try {
|
|
44
|
+
const raw = await fs.readFile(FILE, 'utf8');
|
|
45
|
+
const j = JSON.parse(raw);
|
|
46
|
+
return Array.isArray(j) ? j.map(normalizeEntry) : [];
|
|
47
|
+
} catch (e) {
|
|
48
|
+
if (e.code === 'ENOENT') return [];
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function saveAll(list) {
|
|
54
|
+
await atomicWriteJson(FILE, (list || []).map(normalizeEntry));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function genId() {
|
|
58
|
+
return 'sess-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function cwdKey(cwd) {
|
|
62
|
+
return path.resolve(String(cwd || '')).toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function sameCliAndCwd(entry, cliId, cwd) {
|
|
66
|
+
return entry && entry.cliId === cliId && entry.cwd && cwdKey(entry.cwd) === cwdKey(cwd);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildEntry(opts) {
|
|
70
|
+
const { cliId, cwd, workspace, repos = [], folderId = null, title = '', status = 'running' } = opts;
|
|
71
|
+
return {
|
|
72
|
+
id: genId(),
|
|
73
|
+
cliId,
|
|
74
|
+
cwd,
|
|
75
|
+
workspace,
|
|
76
|
+
title,
|
|
77
|
+
folderId,
|
|
78
|
+
repos,
|
|
79
|
+
createdAt: Date.now(),
|
|
80
|
+
lastActiveAt: Date.now(),
|
|
81
|
+
status,
|
|
82
|
+
exitedAt: status === 'exited' ? Date.now() : null,
|
|
83
|
+
exitCode: null,
|
|
84
|
+
pid: null,
|
|
85
|
+
manualStopped: false,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function create(opts) {
|
|
90
|
+
return withFileLock(FILE, async () => {
|
|
91
|
+
const list = await loadAll();
|
|
92
|
+
const entry = buildEntry(opts);
|
|
93
|
+
list.push(entry);
|
|
94
|
+
await saveAll(list);
|
|
95
|
+
return entry;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function findByCliAndCwd(cliId, cwd) {
|
|
100
|
+
const list = await loadAll();
|
|
101
|
+
return list.find((s) => sameCliAndCwd(s, cliId, cwd)) || null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function createOrGetByCliAndCwd(opts) {
|
|
105
|
+
return withFileLock(FILE, async () => {
|
|
106
|
+
const list = await loadAll();
|
|
107
|
+
const existing = list.find((s) => sameCliAndCwd(s, opts.cliId, opts.cwd));
|
|
108
|
+
if (existing) return { entry: existing, created: false };
|
|
109
|
+
const entry = buildEntry(opts);
|
|
110
|
+
list.push(entry);
|
|
111
|
+
await saveAll(list);
|
|
112
|
+
return { entry, created: true };
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function get(id) {
|
|
117
|
+
const list = await loadAll();
|
|
118
|
+
return list.find((s) => s.id === id) || null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function update(id, patch) {
|
|
122
|
+
return withFileLock(FILE, async () => {
|
|
123
|
+
const list = await loadAll();
|
|
124
|
+
const idx = list.findIndex((s) => s.id === id);
|
|
125
|
+
if (idx < 0) return null;
|
|
126
|
+
list[idx] = { ...list[idx], ...patch };
|
|
127
|
+
await saveAll(list);
|
|
128
|
+
return list[idx];
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function remove(id) {
|
|
133
|
+
return withFileLock(FILE, async () => {
|
|
134
|
+
const list = await loadAll();
|
|
135
|
+
const idx = list.findIndex((s) => s.id === id);
|
|
136
|
+
if (idx < 0) return false;
|
|
137
|
+
list.splice(idx, 1);
|
|
138
|
+
await saveAll(list);
|
|
139
|
+
return true;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Convenience helpers used at runtime so callers don't have to do
|
|
144
|
+
// load/find/update/save themselves.
|
|
116
145
|
async function markRunning(id, pid) {
|
|
117
146
|
return update(id, { status: 'running', pid, exitedAt: null, exitCode: null, manualStopped: false, lastActiveAt: Date.now() });
|
|
118
147
|
}
|
|
119
|
-
|
|
120
|
-
async function
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function
|
|
129
|
-
return update(id, {
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function
|
|
133
|
-
return update(id, {
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
|
|
149
|
+
async function normalizeStore() {
|
|
150
|
+
return withFileLock(FILE, async () => {
|
|
151
|
+
const list = await loadAll();
|
|
152
|
+
await saveAll(list);
|
|
153
|
+
return list;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function markExited(id, exitCode) {
|
|
158
|
+
return update(id, { status: 'exited', exitCode: exitCode ?? null, exitedAt: Date.now(), pid: null });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function touch(id) {
|
|
162
|
+
return update(id, { lastActiveAt: Date.now() });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function setFolder(id, folderId) {
|
|
166
|
+
return update(id, { folderId: folderId || null });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function setTitle(id, title) {
|
|
170
|
+
return update(id, { title: title || '' });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
module.exports = {
|
|
174
|
+
loadAll,
|
|
175
|
+
create,
|
|
176
|
+
findByCliAndCwd,
|
|
177
|
+
createOrGetByCliAndCwd,
|
|
178
|
+
get,
|
|
179
|
+
update,
|
|
180
|
+
remove,
|
|
181
|
+
markRunning,
|
|
182
|
+
markExited,
|
|
183
|
+
touch,
|
|
184
|
+
setFolder,
|
|
185
|
+
setTitle,
|
|
186
|
+
normalizeStore,
|
|
187
|
+
FILE,
|
|
188
|
+
};
|