claude-code-session-manager 0.25.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
9
  <link href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&family=Geist:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
10
- <script type="module" crossorigin src="./assets/index-H0IXEKiC.js"></script>
10
+ <script type="module" crossorigin src="./assets/index-CK5Ob11w.js"></script>
11
11
  <link rel="modulepreload" crossorigin href="./assets/monaco-editor-BW5C4Iv1.js">
12
12
  <link rel="stylesheet" crossorigin href="./assets/monaco-editor-BTnBOi8r.css">
13
13
  <link rel="stylesheet" crossorigin href="./assets/index-Cu9X6oyA.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-session-manager",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "Local cockpit for the Claude Code CLI — multi-tab terminal, full config surface, scheduler, voice dictation, and live observability.",
5
5
  "type": "module",
6
6
  "main": "src/main/index.cjs",
@@ -0,0 +1,183 @@
1
+ /**
2
+ * dod-batchkey.test.cjs — unit tests for definitionOfDone.cjs helpers.
3
+ *
4
+ * Run: timeout 120 node --test src/main/__tests__/dod-batchkey.test.cjs
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ const { test } = require('node:test');
10
+ const assert = require('node:assert/strict');
11
+ const os = require('node:os');
12
+ const fs = require('node:fs');
13
+ const path = require('node:path');
14
+ const { batchKey, reportPathFor, reportExists } = require('../lib/definitionOfDone.cjs');
15
+
16
+ // ─── helpers ──────────────────────────────────────────────────────────────────
17
+
18
+ function makeTmpDir() {
19
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'dod-batchkey-test-'));
20
+ }
21
+
22
+ function rmdir(dir) {
23
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* */ }
24
+ }
25
+
26
+ function makeJob(slug, runId) {
27
+ return { slug, runId };
28
+ }
29
+
30
+ // ─── batchKey: order-independence ─────────────────────────────────────────────
31
+
32
+ test('batchKey is order-independent', () => {
33
+ const jobsA = [
34
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
35
+ makeJob('102-bar', '2026-06-01T11-00-00-000Z'),
36
+ ];
37
+ const jobsB = [
38
+ makeJob('102-bar', '2026-06-01T11-00-00-000Z'),
39
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
40
+ ];
41
+ assert.strictEqual(batchKey(jobsA), batchKey(jobsB));
42
+ });
43
+
44
+ // ─── batchKey: adding a real job changes the key ─────────────────────────────
45
+
46
+ test('adding a real job changes the batchKey', () => {
47
+ const base = [
48
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
49
+ ];
50
+ const extended = [
51
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
52
+ makeJob('102-bar', '2026-06-01T11-00-00-000Z'),
53
+ ];
54
+ assert.notStrictEqual(batchKey(base), batchKey(extended));
55
+ });
56
+
57
+ // ─── batchKey: adding a meta/dod job does NOT change the key ─────────────────
58
+
59
+ test('adding a dod-prefixed slug does not change batchKey', () => {
60
+ const base = [makeJob('101-foo', '2026-06-01T10-00-00-000Z')];
61
+ const withDod = [
62
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
63
+ makeJob('dod-gate', '2026-06-01T12-00-00-000Z'),
64
+ ];
65
+ assert.strictEqual(batchKey(base), batchKey(withDod));
66
+ });
67
+
68
+ test('adding a dod-suffixed slug does not change batchKey', () => {
69
+ const base = [makeJob('101-foo', '2026-06-01T10-00-00-000Z')];
70
+ const withDod = [
71
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
72
+ makeJob('gate-dod', '2026-06-01T12-00-00-000Z'),
73
+ ];
74
+ assert.strictEqual(batchKey(base), batchKey(withDod));
75
+ });
76
+
77
+ test('adding a definition-of-done slug does not change batchKey', () => {
78
+ const base = [makeJob('101-foo', '2026-06-01T10-00-00-000Z')];
79
+ const withDod = [
80
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
81
+ makeJob('definition-of-done-pass', '2026-06-01T12-00-00-000Z'),
82
+ ];
83
+ assert.strictEqual(batchKey(base), batchKey(withDod));
84
+ });
85
+
86
+ test('adding an inline dod slug (dod between dashes) does not change batchKey', () => {
87
+ const base = [makeJob('101-foo', '2026-06-01T10-00-00-000Z')];
88
+ const withDod = [
89
+ makeJob('101-foo', '2026-06-01T10-00-00-000Z'),
90
+ makeJob('batch-dod-check', '2026-06-01T12-00-00-000Z'),
91
+ ];
92
+ assert.strictEqual(batchKey(base), batchKey(withDod));
93
+ });
94
+
95
+ // ─── batchKey: empty set ──────────────────────────────────────────────────────
96
+
97
+ test('empty job list produces a stable key', () => {
98
+ assert.strictEqual(typeof batchKey([]), 'string');
99
+ assert.strictEqual(batchKey([]), batchKey([]));
100
+ });
101
+
102
+ // ─── batchKey: same slug different runId produces different keys ──────────────
103
+
104
+ test('same slug but different runId produces different keys', () => {
105
+ const a = [makeJob('101-foo', '2026-06-01T10-00-00-000Z')];
106
+ const b = [makeJob('101-foo', '2026-06-01T11-00-00-000Z')];
107
+ assert.notStrictEqual(batchKey(a), batchKey(b));
108
+ });
109
+
110
+ // ─── reportPathFor ────────────────────────────────────────────────────────────
111
+
112
+ test('reportPathFor returns a path ending with definition-of-done-<key>.md', () => {
113
+ const key = batchKey([makeJob('101-foo', '2026-06-01T10-00-00-000Z')]);
114
+ const p = reportPathFor(key);
115
+ assert.ok(p.endsWith(`definition-of-done-${key}.md`), `path: ${p}`);
116
+ assert.ok(p.includes('scheduled-plans/runs/'), `path: ${p}`);
117
+ });
118
+
119
+ // ─── reportExists ─────────────────────────────────────────────────────────────
120
+
121
+ test('reportExists returns false when runs/ dir does not exist', () => {
122
+ const key = batchKey([makeJob('101-foo', '2026-06-01T10-00-00-000Z')]);
123
+ const tmpDir = makeTmpDir();
124
+ try {
125
+ const runsDir = path.join(tmpDir, 'runs');
126
+ // runsDir intentionally not created
127
+ assert.strictEqual(reportExists(key, runsDir), false);
128
+ } finally {
129
+ rmdir(tmpDir);
130
+ }
131
+ });
132
+
133
+ test('reportExists returns false when no matching file exists', () => {
134
+ const key = batchKey([makeJob('101-foo', '2026-06-01T10-00-00-000Z')]);
135
+ const tmpDir = makeTmpDir();
136
+ try {
137
+ const runsDir = path.join(tmpDir, 'runs');
138
+ const runDir = path.join(runsDir, '2026-06-01T10-00-00-000Z');
139
+ fs.mkdirSync(runDir, { recursive: true });
140
+ fs.writeFileSync(path.join(runDir, 'some-other-file.md'), '# other');
141
+ assert.strictEqual(reportExists(key, runsDir), false);
142
+ } finally {
143
+ rmdir(tmpDir);
144
+ }
145
+ });
146
+
147
+ test('reportExists returns true when matching file exists in any run subdir', () => {
148
+ const key = batchKey([makeJob('101-foo', '2026-06-01T10-00-00-000Z')]);
149
+ const tmpDir = makeTmpDir();
150
+ try {
151
+ const runsDir = path.join(tmpDir, 'runs');
152
+ const runDir = path.join(runsDir, '2026-06-01T10-00-00-000Z');
153
+ fs.mkdirSync(runDir, { recursive: true });
154
+ fs.writeFileSync(
155
+ path.join(runDir, `definition-of-done-${key}.md`),
156
+ '# DoD report'
157
+ );
158
+ assert.strictEqual(reportExists(key, runsDir), true);
159
+ } finally {
160
+ rmdir(tmpDir);
161
+ }
162
+ });
163
+
164
+ test('reportExists finds match in a nested run directory (not first subdir)', () => {
165
+ const key = batchKey([makeJob('101-foo', '2026-06-01T10-00-00-000Z')]);
166
+ const tmpDir = makeTmpDir();
167
+ try {
168
+ const runsDir = path.join(tmpDir, 'runs');
169
+ // Two subdirs; match is in the second
170
+ const runDir1 = path.join(runsDir, '2026-06-01T09-00-00-000Z');
171
+ const runDir2 = path.join(runsDir, '2026-06-01T10-00-00-000Z');
172
+ fs.mkdirSync(runDir1, { recursive: true });
173
+ fs.mkdirSync(runDir2, { recursive: true });
174
+ fs.writeFileSync(path.join(runDir1, 'other.md'), '# other');
175
+ fs.writeFileSync(
176
+ path.join(runDir2, `definition-of-done-${key}.md`),
177
+ '# DoD report'
178
+ );
179
+ assert.strictEqual(reportExists(key, runsDir), true);
180
+ } finally {
181
+ rmdir(tmpDir);
182
+ }
183
+ });
@@ -0,0 +1,285 @@
1
+ /**
2
+ * dod-reverify.test.cjs — unit tests for extractAcCommand / reverifyAc / reverifyBatch.
3
+ *
4
+ * Run: timeout 180 node --test src/main/__tests__/dod-reverify.test.cjs
5
+ *
6
+ * Fixtures: os.tmpdir() only — never touches the real prds dir or scheduler queue.
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ const { test } = require('node:test');
12
+ const assert = require('node:assert/strict');
13
+ const os = require('node:os');
14
+ const fs = require('node:fs');
15
+ const path = require('node:path');
16
+ const { extractAcCommand, reverifyAc, reverifyBatch } = require('../lib/definitionOfDone.cjs');
17
+
18
+ // ─── helpers ──────────────────────────────────────────────────────────────────
19
+
20
+ function makeTmpDir() {
21
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'dod-reverify-test-'));
22
+ }
23
+
24
+ function rmdir(dir) {
25
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* */ }
26
+ }
27
+
28
+ /** Write a minimal PRD file and return the job object. */
29
+ function writePrd(prdsDir, slug, acLine, cwd) {
30
+ const body = [
31
+ '---',
32
+ `title: ${slug}`,
33
+ `cwd: ${cwd}`,
34
+ 'estimateMinutes: 5',
35
+ '---',
36
+ '',
37
+ '# Goal',
38
+ '',
39
+ 'Test fixture.',
40
+ '',
41
+ '# Acceptance criteria',
42
+ '',
43
+ acLine,
44
+ '',
45
+ '# Out of scope',
46
+ '',
47
+ '- N/A',
48
+ ].join('\n');
49
+ fs.writeFileSync(path.join(prdsDir, `${slug}.md`), body);
50
+ return { slug, cwd };
51
+ }
52
+
53
+ // ─── extractAcCommand: backtick-quoted timeout ─────────────────────────────
54
+
55
+ test('extractAcCommand: extracts timeout from backtick-quoted inline code', () => {
56
+ const body = [
57
+ '# Acceptance criteria',
58
+ '',
59
+ '- [ ] Test `timeout 120 node --test src/main/__tests__/foo.test.cjs` passes.',
60
+ ].join('\n');
61
+ assert.strictEqual(extractAcCommand(body), 'timeout 120 node --test src/main/__tests__/foo.test.cjs');
62
+ });
63
+
64
+ test('extractAcCommand: extracts timeout from raw (non-backtick) AC line', () => {
65
+ const body = [
66
+ '# Acceptance criteria',
67
+ '',
68
+ '- [ ] timeout 60 node -c src/main/lib/definitionOfDone.cjs',
69
+ ].join('\n');
70
+ assert.strictEqual(extractAcCommand(body), 'timeout 60 node -c src/main/lib/definitionOfDone.cjs');
71
+ });
72
+
73
+ test('extractAcCommand: returns first timeout command when multiple AC lines match', () => {
74
+ const body = [
75
+ '# Acceptance criteria',
76
+ '',
77
+ '- [ ] `timeout 60 node -c foo.cjs` parses clean.',
78
+ '- [ ] `timeout 120 node --test bar.test.cjs` passes.',
79
+ ].join('\n');
80
+ assert.strictEqual(extractAcCommand(body), 'timeout 60 node -c foo.cjs');
81
+ });
82
+
83
+ test('extractAcCommand: returns null when no timeout command in AC section', () => {
84
+ const body = [
85
+ '# Acceptance criteria',
86
+ '',
87
+ '- [ ] The widget renders without errors.',
88
+ '- [ ] The config file is valid JSON.',
89
+ ].join('\n');
90
+ assert.strictEqual(extractAcCommand(body), null);
91
+ });
92
+
93
+ test('extractAcCommand: returns null for null/empty body', () => {
94
+ assert.strictEqual(extractAcCommand(null), null);
95
+ assert.strictEqual(extractAcCommand(''), null);
96
+ assert.strictEqual(extractAcCommand(undefined), null);
97
+ });
98
+
99
+ test('extractAcCommand: skips commands with shell pipes (needs shell:true)', () => {
100
+ const body = [
101
+ '# Acceptance criteria',
102
+ '',
103
+ '- [ ] `timeout 150 python -m pytest 2>&1 | tail -15` passes.',
104
+ '- [ ] `timeout 60 node -c src/lib/foo.cjs` parses clean.',
105
+ ].join('\n');
106
+ // Pipe command is rejected; falls back to the second clean command.
107
+ assert.strictEqual(extractAcCommand(body), 'timeout 60 node -c src/lib/foo.cjs');
108
+ });
109
+
110
+ test('extractAcCommand: works when body contains frontmatter strip artifact', () => {
111
+ const body = [
112
+ '# Goal',
113
+ '',
114
+ 'Do something.',
115
+ '',
116
+ '# Acceptance criteria',
117
+ '',
118
+ '- [ ] `timeout 30 node --test tests/foo.test.cjs` passes.',
119
+ ].join('\n');
120
+ assert.strictEqual(extractAcCommand(body), 'timeout 30 node --test tests/foo.test.cjs');
121
+ });
122
+
123
+ // ─── reverifyAc: pass ─────────────────────────────────────────────────────────
124
+
125
+ test('reverifyAc: returns pass when AC command exits 0', async () => {
126
+ const tmpDir = makeTmpDir();
127
+ const prdsDir = path.join(tmpDir, 'prds');
128
+ const cwd = path.join(tmpDir, 'project');
129
+ fs.mkdirSync(prdsDir);
130
+ fs.mkdirSync(cwd);
131
+ // Write a tiny node script that exits 0
132
+ fs.writeFileSync(path.join(cwd, 'ok.cjs'), 'process.exit(0);');
133
+
134
+ const job = writePrd(prdsDir, '101-pass', '- [ ] `timeout 10 node ok.cjs` succeeds.', cwd);
135
+ try {
136
+ const result = await reverifyAc(job, { timeoutMs: 15_000, prdsDir });
137
+ assert.strictEqual(result.slug, '101-pass');
138
+ assert.strictEqual(result.status, 'pass');
139
+ assert.strictEqual(result.code, 0);
140
+ assert.ok(typeof result.ms === 'number' && result.ms >= 0, `ms should be >= 0, got ${result.ms}`);
141
+ } finally {
142
+ rmdir(tmpDir);
143
+ }
144
+ });
145
+
146
+ // ─── reverifyAc: fail ─────────────────────────────────────────────────────────
147
+
148
+ test('reverifyAc: returns fail when AC command exits non-zero', async () => {
149
+ const tmpDir = makeTmpDir();
150
+ const prdsDir = path.join(tmpDir, 'prds');
151
+ const cwd = path.join(tmpDir, 'project');
152
+ fs.mkdirSync(prdsDir);
153
+ fs.mkdirSync(cwd);
154
+ fs.writeFileSync(path.join(cwd, 'fail.cjs'), 'process.exit(1);');
155
+
156
+ const job = writePrd(prdsDir, '102-fail', '- [ ] `timeout 10 node fail.cjs` succeeds.', cwd);
157
+ try {
158
+ const result = await reverifyAc(job, { timeoutMs: 15_000, prdsDir });
159
+ assert.strictEqual(result.slug, '102-fail');
160
+ assert.strictEqual(result.status, 'fail');
161
+ assert.strictEqual(result.code, 1);
162
+ assert.ok(typeof result.ms === 'number' && result.ms >= 0);
163
+ } finally {
164
+ rmdir(tmpDir);
165
+ }
166
+ });
167
+
168
+ // ─── reverifyAc: unverifiable ─────────────────────────────────────────────────
169
+
170
+ test('reverifyAc: returns unverifiable when PRD has no parseable AC command', async () => {
171
+ const tmpDir = makeTmpDir();
172
+ const prdsDir = path.join(tmpDir, 'prds');
173
+ const cwd = path.join(tmpDir, 'project');
174
+ fs.mkdirSync(prdsDir);
175
+ fs.mkdirSync(cwd);
176
+
177
+ const job = writePrd(prdsDir, '103-nocmd', '- [ ] The widget renders correctly.', cwd);
178
+ try {
179
+ const result = await reverifyAc(job, { timeoutMs: 15_000, prdsDir });
180
+ assert.strictEqual(result.slug, '103-nocmd');
181
+ assert.strictEqual(result.status, 'unverifiable');
182
+ assert.strictEqual(result.code, null);
183
+ } finally {
184
+ rmdir(tmpDir);
185
+ }
186
+ });
187
+
188
+ test('reverifyAc: returns unverifiable when cwd does not exist', async () => {
189
+ const tmpDir = makeTmpDir();
190
+ const prdsDir = path.join(tmpDir, 'prds');
191
+ fs.mkdirSync(prdsDir);
192
+ const missingCwd = path.join(tmpDir, 'nonexistent-project');
193
+
194
+ const job = writePrd(prdsDir, '104-nocwd', '- [ ] `timeout 5 node -e "process.exit(0)"` passes.', missingCwd);
195
+ try {
196
+ const result = await reverifyAc(job, { timeoutMs: 15_000, prdsDir });
197
+ assert.strictEqual(result.status, 'unverifiable');
198
+ } finally {
199
+ rmdir(tmpDir);
200
+ }
201
+ });
202
+
203
+ test('reverifyAc: returns unverifiable when PRD file does not exist', async () => {
204
+ const tmpDir = makeTmpDir();
205
+ const prdsDir = path.join(tmpDir, 'prds');
206
+ const cwd = path.join(tmpDir, 'project');
207
+ fs.mkdirSync(prdsDir);
208
+ fs.mkdirSync(cwd);
209
+
210
+ // job.slug points to a missing .md file
211
+ const job = { slug: '105-missing-prd', cwd };
212
+ try {
213
+ const result = await reverifyAc(job, { timeoutMs: 15_000, prdsDir });
214
+ assert.strictEqual(result.status, 'unverifiable');
215
+ } finally {
216
+ rmdir(tmpDir);
217
+ }
218
+ });
219
+
220
+ // ─── reverifyBatch: all three statuses ────────────────────────────────────────
221
+
222
+ test('reverifyBatch: returns pass/fail/unverifiable for a mixed batch', async () => {
223
+ const tmpDir = makeTmpDir();
224
+ const prdsDir = path.join(tmpDir, 'prds');
225
+ const cwd = path.join(tmpDir, 'project');
226
+ fs.mkdirSync(prdsDir);
227
+ fs.mkdirSync(cwd);
228
+
229
+ fs.writeFileSync(path.join(cwd, 'ok.cjs'), 'process.exit(0);');
230
+ fs.writeFileSync(path.join(cwd, 'fail.cjs'), 'process.exit(1);');
231
+
232
+ const jobPass = writePrd(prdsDir, '201-pass', '- [ ] `timeout 10 node ok.cjs` passes.', cwd);
233
+ const jobFail = writePrd(prdsDir, '202-fail', '- [ ] `timeout 10 node fail.cjs` passes.', cwd);
234
+ const jobNone = writePrd(prdsDir, '203-noop', '- [ ] The result is correct.', cwd);
235
+
236
+ try {
237
+ const results = await reverifyBatch([jobPass, jobFail, jobNone], {
238
+ timeoutMs: 15_000,
239
+ batchTimeoutMs: 120_000,
240
+ prdsDir,
241
+ });
242
+ assert.strictEqual(results.length, 3);
243
+
244
+ const bySlug = Object.fromEntries(results.map((r) => [r.slug, r]));
245
+ assert.strictEqual(bySlug['201-pass'].status, 'pass');
246
+ assert.strictEqual(bySlug['202-fail'].status, 'fail');
247
+ assert.strictEqual(bySlug['203-noop'].status, 'unverifiable');
248
+ } finally {
249
+ rmdir(tmpDir);
250
+ }
251
+ });
252
+
253
+ // ─── reverifyBatch: batch wall-time cap ───────────────────────────────────────
254
+
255
+ test('reverifyBatch: marks remaining jobs unverifiable when batch cap is hit', async () => {
256
+ const tmpDir = makeTmpDir();
257
+ const prdsDir = path.join(tmpDir, 'prds');
258
+ const cwd = path.join(tmpDir, 'project');
259
+ fs.mkdirSync(prdsDir);
260
+ fs.mkdirSync(cwd);
261
+
262
+ // Slow job — sleeps longer than batchTimeoutMs
263
+ fs.writeFileSync(path.join(cwd, 'slow.cjs'), 'setTimeout(() => process.exit(0), 30_000);');
264
+ const jobSlow = writePrd(prdsDir, '301-slow', '- [ ] `timeout 60 node slow.cjs` passes.', cwd);
265
+ fs.writeFileSync(path.join(cwd, 'ok.cjs'), 'process.exit(0);');
266
+ const jobAfter = writePrd(prdsDir, '302-after', '- [ ] `timeout 10 node ok.cjs` passes.', cwd);
267
+
268
+ try {
269
+ // Kill the slow job after 500ms; the batch cap (200ms) ensures jobAfter
270
+ // is never started. Total test wall-time ≈ 500ms.
271
+ const results = await reverifyBatch([jobSlow, jobAfter], {
272
+ timeoutMs: 500,
273
+ batchTimeoutMs: 200,
274
+ prdsDir,
275
+ });
276
+ assert.strictEqual(results.length, 2);
277
+ // The slow job ran but the batch cap check fires before jobAfter starts.
278
+ // (The slow job itself may finish or not within the timeoutMs; we only care
279
+ // that jobAfter is unverifiable due to the batch cap.)
280
+ const after = results.find((r) => r.slug === '302-after');
281
+ assert.strictEqual(after.status, 'unverifiable');
282
+ } finally {
283
+ rmdir(tmpDir);
284
+ }
285
+ });
@@ -57,6 +57,9 @@ let powerBlockerId = -1;
57
57
  // `systemd-inhibit` child, which talks straight to logind and is
58
58
  // desktop-agnostic. Handle to the child so we can release it on quit.
59
59
  let systemdInhibitChild = null;
60
+ // Belt-and-suspenders: re-assert the inhibitor on a slow cadence so it can never
61
+ // stay dead (idempotent — startSystemdInhibit no-ops if a live holder exists).
62
+ let inhibitReassertTimer = null;
60
63
 
61
64
  function startSystemdInhibit() {
62
65
  if (process.platform !== 'linux') return;
@@ -70,7 +73,11 @@ function startSystemdInhibit() {
70
73
  // this the child reparents to init on a hard kill and the inhibitor leaks
71
74
  // forever (one stranded lock per crash). 5s tick = worst-case 5s of stale
72
75
  // lock after death, which errs toward "stay awake" — the safe direction.
73
- const child = spawn('systemd-inhibit', [
76
+ // Absolute path — a GUI/desktop-launched Electron can boot with a minimal
77
+ // PATH that lacks /usr/bin, so a bare `systemd-inhibit` would ENOENT.
78
+ const inhibitBin = require('node:fs').existsSync('/usr/bin/systemd-inhibit')
79
+ ? '/usr/bin/systemd-inhibit' : 'systemd-inhibit';
80
+ const child = spawn(inhibitBin, [
74
81
  '--what=sleep:idle',
75
82
  '--who=Claude Session Manager',
76
83
  '--why=Scheduler polling and claude -p jobs must survive idle',
@@ -80,6 +87,17 @@ function startSystemdInhibit() {
80
87
  child.on('error', (e) => {
81
88
  logs.writeLine({ scope: 'main', level: 'warn', message: 'systemd-inhibit spawn failed', meta: { error: e?.message } });
82
89
  });
90
+ // Self-heal: if the holder ever dies while the app is alive (a missed
91
+ // suspend, an external kill, a transient spawn that didn't hold), revive it.
92
+ // Without this the lock is held exactly once at boot and never recovers —
93
+ // the machine then idle-suspends with the app open (the reported bug).
94
+ child.on('exit', (code, signal) => {
95
+ logs.writeLine({ scope: 'main', level: 'warn', message: 'systemd-inhibit holder exited', meta: { code, signal } });
96
+ if (!teardownDone && systemdInhibitChild === child) {
97
+ systemdInhibitChild = null;
98
+ setTimeout(() => { if (!teardownDone) startSystemdInhibit(); }, 2000);
99
+ }
100
+ });
83
101
  if (child.pid) {
84
102
  systemdInhibitChild = child;
85
103
  logs.writeLine({ scope: 'main', level: 'info', message: 'systemd-inhibit block lock held', meta: { pid: child.pid } });
@@ -952,6 +970,12 @@ app.whenReady().then(async () => {
952
970
  }
953
971
  // Linux backstop — Electron's blocker no-ops under COSMIC (see above).
954
972
  startSystemdInhibit();
973
+ // Re-assert every 60s so a dead holder self-revives even if its exit handler
974
+ // was missed. Idempotent; unref'd so it never holds the loop open at quit.
975
+ if (process.platform === 'linux' && !inhibitReassertTimer) {
976
+ inhibitReassertTimer = setInterval(() => { if (!teardownDone) startSystemdInhibit(); }, 60_000);
977
+ if (inhibitReassertTimer.unref) inhibitReassertTimer.unref();
978
+ }
955
979
 
956
980
  // OTEL: load persisted config and start the exporter only if `enabled`.
957
981
  // Failures are non-fatal — the app must keep working without telemetry.
@@ -987,6 +1011,7 @@ function runShutdownCleanup() {
987
1011
  try { powerSaveBlocker.stop(powerBlockerId); } catch { /* */ }
988
1012
  powerBlockerId = -1;
989
1013
  }
1014
+ if (inhibitReassertTimer) { clearInterval(inhibitReassertTimer); inhibitReassertTimer = null; }
990
1015
  stopSystemdInhibit();
991
1016
  }
992
1017