claude-code-session-manager 0.67.0 → 0.69.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.
Files changed (42) hide show
  1. package/dist/assets/{AgentLibrary-CiqimwWl.js → AgentLibrary-DngWZmn2.js} +1 -1
  2. package/dist/assets/{History-DbzjII2Z.js → History-CiqbZNCW.js} +1 -1
  3. package/dist/assets/{Hooks-C0PTplI_.js → Hooks-1LHEEKhK.js} +1 -1
  4. package/dist/assets/{HostBilko-vGc1FYLD.js → HostBilko-DruBVVx_.js} +1 -1
  5. package/dist/assets/{Library-4tU4rg2h.js → Library-BXt58QDN.js} +1 -1
  6. package/dist/assets/{ListDetail-BGIvkCwZ.js → ListDetail-V5JV-SVN.js} +1 -1
  7. package/dist/assets/{MarkdownEditor-ChFdpCam.js → MarkdownEditor-BYUdiq8p.js} +1 -1
  8. package/dist/assets/{McpServers-DsRWWpU3.js → McpServers-C3b18FY5.js} +1 -1
  9. package/dist/assets/{Memory-DmxoxxxY.js → Memory-MyToD3ri.js} +1 -1
  10. package/dist/assets/{Panel-KC-rv3jS.js → Panel-D1z0ZvX_.js} +1 -1
  11. package/dist/assets/{Permissions-DrDjCRFl.js → Permissions-BDRMk8Uu.js} +1 -1
  12. package/dist/assets/{Plugins-KexSQwk0.js → Plugins-Bd1wIgVW.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-Rg-jL94y.js → ProvenanceBadge-BIX0JW7m.js} +1 -1
  14. package/dist/assets/{SaveBar-BbEo8U2e.js → SaveBar-DOJnzj3n.js} +1 -1
  15. package/dist/assets/{Scheduler-C4Ti9TCc.js → Scheduler-LdawPR1e.js} +1 -1
  16. package/dist/assets/{ScopeSwitcher-Di9BmYze.js → ScopeSwitcher-Cl3g7YOM.js} +1 -1
  17. package/dist/assets/{Settings-CxyhPuYQ.js → Settings-7jHzkgfK.js} +1 -1
  18. package/dist/assets/{SkillReferenceGraph-0q26RHrn.js → SkillReferenceGraph-B_KqYC6R.js} +1 -1
  19. package/dist/assets/{Skills-BXkVyCo5.js → Skills-H8pCR_6D.js} +1 -1
  20. package/dist/assets/{SystemPrompt-Bwe3NTbi.js → SystemPrompt-fCD2rD2R.js} +1 -1
  21. package/dist/assets/{TagLibrary-CnwEf6EI.js → TagLibrary-erEiP4bj.js} +1 -1
  22. package/dist/assets/{TiptapBody-faCtLj9L.js → TiptapBody-A93HQtTH.js} +1 -1
  23. package/dist/assets/{Toggle-Bw7G_-RR.js → Toggle-CoFtvmoX.js} +1 -1
  24. package/dist/assets/{index-CEnMgeQU.css → index-B77KHr7n.css} +1 -1
  25. package/dist/assets/{index-B6dJ2CsU.js → index-C-iwyX_s.js} +356 -355
  26. package/dist/assets/{settingsSchema-B5C9hZoS.js → settingsSchema-DHDH8NJR.js} +1 -1
  27. package/dist/index.html +2 -2
  28. package/package.json +1 -1
  29. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  30. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +149 -0
  31. package/src/main/__tests__/crossProjectFeedback.test.cjs +327 -0
  32. package/src/main/__tests__/crossProjectFeedbackRoutes.test.cjs +154 -0
  33. package/src/main/__tests__/health-per-project-stall.test.cjs +4 -2
  34. package/src/main/__tests__/scheduler-job-overrun.test.cjs +117 -0
  35. package/src/main/__tests__/scheduler-stall-per-project.test.cjs +6 -2
  36. package/src/main/index.cjs +5 -0
  37. package/src/main/lib/buildTarget.cjs +15 -0
  38. package/src/main/lib/crossProjectFeedback.cjs +545 -0
  39. package/src/main/lib/epicMint.cjs +38 -7
  40. package/src/main/lib/promptSessionSchema.cjs +7 -1
  41. package/src/main/lib/schedulerConfig.cjs +15 -0
  42. package/src/main/scheduler.cjs +73 -1
@@ -0,0 +1,327 @@
1
+ /**
2
+ * crossProjectFeedback.test.cjs — the project-to-project conduit
3
+ * (lib/crossProjectFeedback.cjs).
4
+ *
5
+ * The point of these tests is the SAFETY ENVELOPE, not the happy path: this
6
+ * module is the second (and only other) holder of an ensureEpic mint
7
+ * authority, so what matters is that every way of misusing it is refused, and
8
+ * that the one thing it CAN do lands as an unstarted 'proposed' Epic in
9
+ * somebody else's project.
10
+ *
11
+ * Run: timeout 300 npx vitest run src/main/__tests__/crossProjectFeedback.test.cjs
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ import { test, expect, afterEach } from 'vitest';
17
+ const fs = require('node:fs');
18
+ const fsp = require('node:fs/promises');
19
+ const os = require('node:os');
20
+ const path = require('node:path');
21
+ const config = require('../config.cjs');
22
+ const {
23
+ composeFeedbackIntake,
24
+ validateFeedbackInput,
25
+ openFeedbackSession,
26
+ listFeedbackTargets,
27
+ isSessionManagerProject,
28
+ MAX_BODY_CHARS,
29
+ } = require('../lib/crossProjectFeedback.cjs');
30
+ const { readActiveIndex, MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK, MINT_AUTHORITIES } = require('../lib/epicMint.cjs');
31
+ const { assertValidPromptSession } = require('../lib/promptSessionSchema.cjs');
32
+
33
+ const tmpDirs = [];
34
+ afterEach(async () => {
35
+ while (tmpDirs.length) {
36
+ const d = tmpDirs.pop();
37
+ await fsp.rm(d, { recursive: true, force: true });
38
+ }
39
+ });
40
+
41
+ /** A project dir. `managed: false` produces a directory that exists but has
42
+ * never been opened in Session Manager (no operations root). */
43
+ async function mkProject({ managed = true } = {}) {
44
+ const cwd = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-xproj-'));
45
+ config.addAllowedRoot(cwd);
46
+ tmpDirs.push(cwd);
47
+ if (managed) fs.mkdirSync(path.join(cwd, 'session-manager-operations'), { recursive: true });
48
+ return fs.realpathSync(cwd);
49
+ }
50
+
51
+ function payload(toCwd, fromCwd, overrides = {}) {
52
+ return {
53
+ toCwd,
54
+ fromCwd,
55
+ title: 'Relay drops the session-state frame on reconnect',
56
+ body: 'Symptom: after a relay reconnect the first session-state frame is silently discarded.',
57
+ ...overrides,
58
+ };
59
+ }
60
+
61
+ // ---------------------------------------------------------------------------
62
+ // Refusals — the envelope
63
+ // ---------------------------------------------------------------------------
64
+
65
+ test('refuses same-project feedback and names /develop instead', async () => {
66
+ const p = await mkProject();
67
+ const r = await openFeedbackSession(payload(p, p));
68
+ expect(r.ok).toBe(false);
69
+ expect(r.status).toBe(400);
70
+ expect(r.error).toMatch(/same project/i);
71
+ expect(r.error).toMatch(/\/develop/);
72
+ });
73
+
74
+ test('refuses a target that is not a Session Manager project, and does not create the ops root', async () => {
75
+ const to = await mkProject({ managed: false });
76
+ const from = await mkProject();
77
+ const r = await openFeedbackSession(payload(to, from));
78
+ expect(r.ok).toBe(false);
79
+ expect(r.error).toMatch(/not a Session Manager project/);
80
+ // The refusal must not have half-created what it was checking for.
81
+ expect(fs.existsSync(path.join(to, 'session-manager-operations'))).toBe(false);
82
+ });
83
+
84
+ test('refuses a target directory that does not exist', async () => {
85
+ const from = await mkProject();
86
+ const r = await openFeedbackSession(payload(path.join(os.tmpdir(), 'sm-xproj-does-not-exist'), from));
87
+ expect(r.ok).toBe(false);
88
+ expect(r.error).toMatch(/not an existing directory|rejected/);
89
+ });
90
+
91
+ test('refuses a cwd outside the allowed boundary rather than writing there', async () => {
92
+ const from = await mkProject();
93
+ const r = await openFeedbackSession(payload('/etc', from));
94
+ expect(r.ok).toBe(false);
95
+ expect(r.error).toMatch(/toCwd rejected/);
96
+ });
97
+
98
+ test('refuses missing title/body and an unknown tag', async () => {
99
+ const to = await mkProject();
100
+ const from = await mkProject();
101
+ expect(validateFeedbackInput(payload(to, from, { title: ' ' })).error).toMatch(/title is required/);
102
+ expect(validateFeedbackInput(payload(to, from, { body: '' })).error).toMatch(/body is required/);
103
+ expect(validateFeedbackInput(payload(to, from, { tag: 'build' })).error).toMatch(/tag must be one of/);
104
+ });
105
+
106
+ test('caps the body so one call cannot write an unbounded blob into another project', async () => {
107
+ const to = await mkProject();
108
+ const from = await mkProject();
109
+ const r = validateFeedbackInput(payload(to, from, { body: 'x'.repeat(MAX_BODY_CHARS + 1) }));
110
+ expect(r.ok).toBe(false);
111
+ expect(r.error).toMatch(/cap is/);
112
+ });
113
+
114
+ // ---------------------------------------------------------------------------
115
+ // Delivery
116
+ // ---------------------------------------------------------------------------
117
+
118
+ test('delivers a PROPOSED Epic into the receiving project, never an active one', async () => {
119
+ const to = await mkProject();
120
+ const from = await mkProject();
121
+
122
+ const r = await openFeedbackSession(payload(to, from));
123
+ expect(r.ok).toBe(true);
124
+ expect(r.status).toBe('proposed');
125
+
126
+ // It landed in the RECEIVING project's index, not the sender's.
127
+ const received = readActiveIndex(to);
128
+ const epic = received.sessions[r.epicId];
129
+ expect(epic).toBeTruthy();
130
+ expect(epic.status).toBe('proposed');
131
+ expect(epic.cwd).toBe(to);
132
+ expect(readActiveIndex(from).sessions[r.epicId]).toBeUndefined();
133
+
134
+ // And it is a valid PromptSession — the same schema a hand-created Epic
135
+ // must satisfy, including the extended EpicSource producer.
136
+ expect(() => assertValidPromptSession(epic)).not.toThrow();
137
+ expect(epic.source).toEqual({ producer: 'cross-project-feedback', fromCwd: from });
138
+ expect(epic.tag).toBe('discussion');
139
+ expect(epic.agentType).toBe('architect');
140
+ });
141
+
142
+ test("the queue row is the title; the report travels in the opening prompt", async () => {
143
+ const to = await mkProject();
144
+ const from = await mkProject();
145
+ const r = await openFeedbackSession(payload(to, from, { title: 'Short row', body: 'The long report body.' }));
146
+ const epic = readActiveIndex(to).sessions[r.epicId];
147
+ expect(epic.goalText).toBe('Short row');
148
+ expect(epic.openingPrompt).toContain('The long report body.');
149
+ });
150
+
151
+ test('the opening prompt names the sending project and warns the receiver to verify first', async () => {
152
+ const to = await mkProject();
153
+ const from = await mkProject();
154
+ const r = await openFeedbackSession(payload(to, from));
155
+ const epic = readActiveIndex(to).sessions[r.epicId];
156
+ expect(epic.openingPrompt).toContain('INBOUND FEEDBACK');
157
+ expect(epic.openingPrompt).toContain(from);
158
+ expect(epic.openingPrompt).toMatch(/verify/i);
159
+ });
160
+
161
+ test('the response says plainly that nothing has started', async () => {
162
+ const to = await mkProject();
163
+ const from = await mkProject();
164
+ const r = await openFeedbackSession(payload(to, from));
165
+ expect(r.note).toMatch(/Approve & start/);
166
+ expect(r.note).toMatch(/no tokens are spent|Nothing runs/i);
167
+ });
168
+
169
+ test('an unresolvable sending Epic still delivers, just without a receipt', async () => {
170
+ const to = await mkProject();
171
+ const from = await mkProject();
172
+ const r = await openFeedbackSession(payload(to, from, { fromEpicId: 'no-such-epic' }));
173
+ expect(r.ok).toBe(true);
174
+ expect(r.receiptOnOriginEpic).toBe(false);
175
+ });
176
+
177
+ test('chains a receipt onto the sending Epic when it is known and active', async () => {
178
+ const to = await mkProject();
179
+ const from = await mkProject();
180
+ const calls = [];
181
+ const r = await openFeedbackSession(
182
+ payload(to, from, { fromEpicId: 'sender-epic' }),
183
+ { appendResponseEventIfKnown: async (...args) => { calls.push(args); return true; } },
184
+ );
185
+ expect(r.receiptOnOriginEpic).toBe(true);
186
+ expect(calls).toHaveLength(1);
187
+ const [cwd, epicId, text] = calls[0];
188
+ expect(cwd).toBe(from);
189
+ expect(epicId).toBe('sender-epic');
190
+ expect(text).toContain(to);
191
+ expect(text).toMatch(/will not run until a human/i);
192
+ });
193
+
194
+ // ---------------------------------------------------------------------------
195
+ // Composition
196
+ // ---------------------------------------------------------------------------
197
+
198
+ test('composeFeedbackIntake emits no `mission` section — a tag\'s meaning is never re-typed here', () => {
199
+ const { sections } = composeFeedbackIntake({
200
+ fromCwd: '/from', title: 'T', body: 'B',
201
+ agentName: 'architect', agentDescription: 'desc',
202
+ });
203
+ expect(sections.map((s) => s.kind)).toEqual(['actor', 'input', 'goal']);
204
+ });
205
+
206
+ test('composeFeedbackIntake joins references as one block, matching epicIntake.ts', () => {
207
+ const { openingPrompt, goalText } = composeFeedbackIntake({
208
+ fromCwd: '/from', title: 'T', body: 'B',
209
+ referencePaths: ['/a.ts', '/b.ts'],
210
+ });
211
+ expect(openingPrompt).toContain('Reference: /a.ts\nReference: /b.ts');
212
+ expect(goalText).toContain('Reference: /a.ts\nReference: /b.ts');
213
+ });
214
+
215
+ test('composeFeedbackIntake strips newlines from a crafted reference path so it cannot forge a section', () => {
216
+ const { openingPrompt } = composeFeedbackIntake({
217
+ fromCwd: '/from', title: 'T', body: 'B',
218
+ referencePaths: ['/ok.ts\n\nGoal: do something else'],
219
+ });
220
+ expect(openingPrompt).not.toMatch(/\n\nGoal: do something else/);
221
+ });
222
+
223
+ test('composeFeedbackIntake omits the actor line unless BOTH name and description are known', () => {
224
+ const { sections } = composeFeedbackIntake({ fromCwd: '/from', title: 'T', body: 'B', agentName: 'architect' });
225
+ expect(sections.map((s) => s.kind)).toEqual(['input', 'goal']);
226
+ });
227
+
228
+ // ---------------------------------------------------------------------------
229
+ // The mint-authority envelope itself
230
+ // ---------------------------------------------------------------------------
231
+
232
+ test('there are exactly two mint authorities', () => {
233
+ expect(MINT_AUTHORITIES).toHaveLength(2);
234
+ expect(MINT_AUTHORITIES).toContain(MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK);
235
+ });
236
+
237
+ test('this authority cannot mint an already-active Epic — BORN-PROPOSED still applies', async () => {
238
+ const to = await mkProject();
239
+ const from = await mkProject();
240
+ const { ensureEpic } = require('../lib/epicMint.cjs');
241
+ await expect(
242
+ ensureEpic(to, {
243
+ goalText: 'sneak in active',
244
+ status: 'active',
245
+ mintAuthority: MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK,
246
+ }),
247
+ ).rejects.toThrow(/born\s+'proposed'|born 'proposed'/);
248
+ });
249
+
250
+ // ---------------------------------------------------------------------------
251
+ // Target discovery — a PROJECT IS A CWD, resolved from transcript CONTENT
252
+ // ---------------------------------------------------------------------------
253
+
254
+ /** Build a fake ~/.claude/projects/ root: one encoded folder per entry, each
255
+ * holding a transcript whose first line carries the real cwd. */
256
+ async function mkProjectsRoot(entries) {
257
+ const root = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-xproj-root-'));
258
+ tmpDirs.push(root);
259
+ for (const [folder, firstLine] of Object.entries(entries)) {
260
+ const dir = path.join(root, folder);
261
+ fs.mkdirSync(dir, { recursive: true });
262
+ fs.writeFileSync(path.join(dir, 'session-a.jsonl'), `${firstLine}\n`);
263
+ }
264
+ return root;
265
+ }
266
+
267
+ test('resolves a target from transcript content, not from decoding the folder name', async () => {
268
+ const real = await mkProject();
269
+ // The folder name is deliberately NOT a decodable version of `real` — if
270
+ // the scan ever regressed to the naive '-' -> '/' decode, this would miss.
271
+ const root = await mkProjectsRoot({ 'l2mclS-SrR7IF-garbage': JSON.stringify({ cwd: real, type: 'user' }) });
272
+ const { projects } = await listFeedbackTargets({ projectsDir: root });
273
+ expect(projects.map((p) => p.cwd)).toEqual([real]);
274
+ });
275
+
276
+ test('drops a folder whose cwd never resolved rather than guessing a path', async () => {
277
+ const root = await mkProjectsRoot({
278
+ 'no-cwd-field': JSON.stringify({ type: 'user', message: 'hi' }),
279
+ 'not-even-json': 'this is not json at all',
280
+ });
281
+ const { projects } = await listFeedbackTargets({ projectsDir: root });
282
+ expect(projects).toEqual([]);
283
+ });
284
+
285
+ test('drops a resolved cwd that is not a Session Manager project', async () => {
286
+ const bare = await mkProject({ managed: false });
287
+ const root = await mkProjectsRoot({ enc: JSON.stringify({ cwd: bare }) });
288
+ const { projects } = await listFeedbackTargets({ projectsDir: root });
289
+ expect(projects).toEqual([]);
290
+ });
291
+
292
+ test('folds several transcript folders that resolve to ONE cwd into a single entry', async () => {
293
+ const real = await mkProject();
294
+ const root = await mkProjectsRoot({
295
+ 'enc-one': JSON.stringify({ cwd: real }),
296
+ 'enc-two': JSON.stringify({ cwd: real }),
297
+ 'enc-three': JSON.stringify({ cwd: real }),
298
+ });
299
+ const { projects } = await listFeedbackTargets({ projectsDir: root });
300
+ expect(projects).toHaveLength(1);
301
+ expect(projects[0].cwd).toBe(real);
302
+ });
303
+
304
+ test('a missing projects root yields an empty list, never a throw', async () => {
305
+ await expect(
306
+ listFeedbackTargets({ projectsDir: path.join(os.tmpdir(), 'sm-xproj-nonexistent-root') }),
307
+ ).resolves.toEqual({ projects: [], scanned: 0, truncated: 0 });
308
+ });
309
+
310
+ test('reports truncation instead of silently covering a subset', async () => {
311
+ const real = await mkProject();
312
+ const root = await mkProjectsRoot({
313
+ a: JSON.stringify({ cwd: real }),
314
+ b: JSON.stringify({ cwd: real }),
315
+ c: JSON.stringify({ cwd: real }),
316
+ });
317
+ const res = await listFeedbackTargets({ projectsDir: root, limit: 2 });
318
+ expect(res.scanned).toBe(2);
319
+ expect(res.truncated).toBe(1);
320
+ });
321
+
322
+ test('isSessionManagerProject is the only definition of a valid target', async () => {
323
+ const managed = await mkProject();
324
+ const bare = await mkProject({ managed: false });
325
+ expect(isSessionManagerProject(managed)).toBe(true);
326
+ expect(isSessionManagerProject(bare)).toBe(false);
327
+ });
@@ -0,0 +1,154 @@
1
+ /**
2
+ * crossProjectFeedbackRoutes.test.cjs — the HTTP hop for the project-to-project
3
+ * conduit (lib/crossProjectFeedback.cjs's registerAdminRoute).
4
+ *
5
+ * Why this is its own file. crossProjectFeedback.test.cjs drives
6
+ * openFeedbackSession() directly, and the MCP tool definitions live in
7
+ * scripts/scheduler-mcp-server.cjs — so the ROUTE REGISTRATION between them was
8
+ * the one layer nothing exercised. That layer has a real, silent failure mode:
9
+ * a route registered under a path the MCP client doesn't call (or not
10
+ * registered at all) surfaces only as `{"ok":false,"error":"not found"}` from a
11
+ * tool that otherwise looks perfectly wired. Confirmed live 2026-08-08 against
12
+ * a running app whose process predated the route being added.
13
+ *
14
+ * These tests boot the real transport (localAdminHttp.cjs) on a throwaway port
15
+ * and speak real HTTP to it, so the method+path pair is asserted end to end
16
+ * rather than assumed.
17
+ *
18
+ * Run: timeout 300 npx vitest run src/main/__tests__/crossProjectFeedbackRoutes.test.cjs
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ import { test, expect, beforeAll, afterAll, afterEach } from 'vitest';
24
+ const http = require('node:http');
25
+ const fs = require('node:fs');
26
+ const fsp = require('node:fs/promises');
27
+ const os = require('node:os');
28
+ const path = require('node:path');
29
+ const config = require('../config.cjs');
30
+ const { createAdminHttp, TOKEN_PATH } = require('../lib/localAdminHttp.cjs');
31
+ const crossProjectFeedback = require('../lib/crossProjectFeedback.cjs');
32
+ const { readActiveIndex } = require('../lib/epicMint.cjs');
33
+
34
+ // Never let start() overwrite the RUNNING app's admin-api.json — that orphans
35
+ // scheduler-mcp-server.cjs until an app restart (the incident documented in
36
+ // localAdminHttp.cjs's resolveTokenPath).
37
+ const TEST_TOKEN_PATH = path.join(path.dirname(TOKEN_PATH), `admin-api.xproj-test-${process.pid}.json`);
38
+ process.env.SM_ADMIN_TOKEN_PATH = TEST_TOKEN_PATH;
39
+
40
+ let adminHttp;
41
+ let port;
42
+ let token;
43
+
44
+ beforeAll(async () => {
45
+ adminHttp = createAdminHttp();
46
+ crossProjectFeedback.registerAdminRoute(adminHttp);
47
+ ({ port, token } = await adminHttp.start());
48
+ });
49
+
50
+ afterAll(async () => {
51
+ if (adminHttp) await adminHttp.stop();
52
+ fs.rmSync(TEST_TOKEN_PATH, { force: true });
53
+ });
54
+
55
+ const tmpDirs = [];
56
+ afterEach(async () => {
57
+ while (tmpDirs.length) await fsp.rm(tmpDirs.pop(), { recursive: true, force: true });
58
+ });
59
+
60
+ async function mkProject({ managed = true } = {}) {
61
+ const cwd = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-xproj-route-'));
62
+ config.addAllowedRoot(cwd);
63
+ tmpDirs.push(cwd);
64
+ if (managed) fs.mkdirSync(path.join(cwd, 'session-manager-operations'), { recursive: true });
65
+ return fs.realpathSync(cwd);
66
+ }
67
+
68
+ function request({ method = 'GET', path: reqPath, body, auth = true }) {
69
+ return new Promise((resolve, reject) => {
70
+ const headers = {};
71
+ if (auth) headers.Authorization = `Bearer ${token}`;
72
+ let payload;
73
+ if (body !== undefined) {
74
+ payload = typeof body === 'string' ? body : JSON.stringify(body);
75
+ headers['Content-Type'] = 'application/json';
76
+ headers['Content-Length'] = Buffer.byteLength(payload);
77
+ }
78
+ const req = http.request({ hostname: '127.0.0.1', port, method, path: reqPath, headers }, (res) => {
79
+ let data = '';
80
+ res.on('data', (c) => { data += c; });
81
+ res.on('end', () => {
82
+ let json = null;
83
+ try { json = JSON.parse(data); } catch { /* non-JSON body */ }
84
+ resolve({ status: res.statusCode, json, raw: data });
85
+ });
86
+ });
87
+ req.on('error', reject);
88
+ if (payload !== undefined) req.write(payload);
89
+ req.end();
90
+ });
91
+ }
92
+
93
+ // ---------------------------------------------------------------------------
94
+ // The exact method+path pairs scripts/scheduler-mcp-server.cjs calls.
95
+ // If either of these two tests fails, the MCP tool is dead in the water and
96
+ // reports only "not found".
97
+ // ---------------------------------------------------------------------------
98
+
99
+ test('GET /admin/feedback/targets is registered and answers', async () => {
100
+ // Scanned against an EMPTY throwaway root, never the developer's real
101
+ // ~/.claude/projects/ — the transcripts tests create and delete folders
102
+ // there in their own afterEach, and scanning it made this test race their
103
+ // teardown (green alone, intermittently red under the full suite).
104
+ const emptyRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-xproj-scan-'));
105
+ tmpDirs.push(emptyRoot);
106
+ const res = await request({
107
+ method: 'GET',
108
+ path: `/admin/feedback/targets?projectsDir=${encodeURIComponent(emptyRoot)}`,
109
+ });
110
+ expect(res.status).toBe(200);
111
+ expect(res.json.ok).toBe(true);
112
+ expect(res.json.projects).toEqual([]);
113
+ });
114
+
115
+ test('POST /admin/feedback/open-session is registered and delivers', async () => {
116
+ const to = await mkProject();
117
+ const from = await mkProject();
118
+ const res = await request({
119
+ method: 'POST',
120
+ path: '/admin/feedback/open-session',
121
+ body: { toCwd: to, fromCwd: from, title: 'Route smoke', body: 'Delivered over real HTTP.' },
122
+ });
123
+ expect(res.status).toBe(200);
124
+ expect(res.json.ok).toBe(true);
125
+ expect(res.json.status).toBe('proposed');
126
+
127
+ // The write really landed in the receiving project, not just in the response.
128
+ const epic = readActiveIndex(to).sessions[res.json.epicId];
129
+ expect(epic.status).toBe('proposed');
130
+ expect(epic.source.producer).toBe('cross-project-feedback');
131
+ });
132
+
133
+ test('a refusal comes back as a 400 with the reason, not a 500 or a silent 200', async () => {
134
+ const p = await mkProject();
135
+ const res = await request({
136
+ method: 'POST',
137
+ path: '/admin/feedback/open-session',
138
+ body: { toCwd: p, fromCwd: p, title: 'Same project', body: 'Should be refused.' },
139
+ });
140
+ expect(res.status).toBe(400);
141
+ expect(res.json.ok).toBe(false);
142
+ expect(res.json.error).toMatch(/\/develop/);
143
+ });
144
+
145
+ test('a malformed JSON body is a 400, never an unhandled throw', async () => {
146
+ const res = await request({ method: 'POST', path: '/admin/feedback/open-session', body: '{not json' });
147
+ expect(res.status).toBe(400);
148
+ expect(res.json.error).toMatch(/invalid JSON body/);
149
+ });
150
+
151
+ test('both routes are behind the transport\'s bearer auth', async () => {
152
+ expect((await request({ method: 'GET', path: '/admin/feedback/targets', auth: false })).status).toBe(401);
153
+ expect((await request({ method: 'POST', path: '/admin/feedback/open-session', body: {}, auth: false })).status).toBe(401);
154
+ });
@@ -6,12 +6,14 @@
6
6
  * (which requires actual pending work) — the exact way the burrow project's
7
7
  * four quarantined PRDs went dark.
8
8
  *
9
- * Run: timeout 120 node --test src/main/__tests__/health-per-project-stall.test.cjs
9
+ * Run: timeout 120 npx vitest run src/main/__tests__/health-per-project-stall.test.cjs
10
10
  */
11
11
 
12
12
  'use strict';
13
13
 
14
- const { test } = require('node:test');
14
+ // vitest, NOT node:test — see the sibling note in
15
+ // scheduler-stall-per-project.test.cjs. node:assert works inside vitest.
16
+ import { test } from 'vitest';
15
17
  const assert = require('node:assert/strict');
16
18
  const {
17
19
  computeProjectProblemCounts,
@@ -0,0 +1,117 @@
1
+ /**
2
+ * scheduler-job-overrun.test.cjs — findOverrunningJobs: escalate a RUNNING
3
+ * job that has blown past its own PRD's `estimateMinutes`.
4
+ *
5
+ * Covers the blind spot between the two existing kill paths, which is how a
6
+ * PRD ran 3h+ on 2026-08-08 with nothing noticing:
7
+ * - MAX_JOB_DURATION_MS (4h) deadman — 3h is still an hour short of it
8
+ * - IDLE_OUTPUT_KILL_MS (20m) — only fires on a STALLED log; a job looping
9
+ * while still writing output never trips it
10
+ * `estimateMinutes` was stored and displayed but never compared to runtime.
11
+ *
12
+ * Run: timeout 120 npx vitest run src/main/__tests__/scheduler-job-overrun.test.cjs
13
+ */
14
+
15
+ 'use strict';
16
+
17
+ // vitest, NOT node:test — this repo's suite is vitest-only (CLAUDE.md). A
18
+ // node:test file loads here as "No test suite found" and contributes zero
19
+ // tests, so the guard silently wouldn't exist.
20
+ import { test } from 'vitest';
21
+ const assert = require('node:assert/strict');
22
+ const {
23
+ findOverrunningJobs,
24
+ JOB_OVERRUN_FACTOR,
25
+ JOB_OVERRUN_FLOOR_MS,
26
+ } = require('../scheduler.cjs');
27
+
28
+ const NOW = Date.parse('2026-08-08T12:00:00.000Z');
29
+ const agoMin = (m) => new Date(NOW - m * 60_000).toISOString();
30
+
31
+ test('the real incident: a 20-minute PRD still running at 3h escalates', () => {
32
+ const jobs = [
33
+ { slug: '1029-long', cwd: '/p1', status: 'running', estimateMinutes: 20, startedAt: agoMin(180) },
34
+ ];
35
+ const over = findOverrunningJobs(jobs, NOW);
36
+ assert.strictEqual(over.length, 1);
37
+ assert.strictEqual(over[0].slug, '1029-long');
38
+ assert.strictEqual(over[0].estimateMinutes, 20);
39
+ assert.ok(over[0].ratio >= 8.9 && over[0].ratio <= 9.1, `expected ~9x, got ${over[0].ratio}`);
40
+ });
41
+
42
+ test('a job comfortably inside its estimate does not escalate', () => {
43
+ const jobs = [
44
+ { slug: 'ok', cwd: '/p1', status: 'running', estimateMinutes: 60, startedAt: agoMin(30) },
45
+ ];
46
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
47
+ });
48
+
49
+ test('the floor stops a tiny estimate escalating on noise', () => {
50
+ // 5m estimate x3 = 15m, but the floor is 45m — at 20m elapsed this is
51
+ // over the factor yet under the floor, so it must stay silent.
52
+ const jobs = [
53
+ { slug: 'tiny', cwd: '/p1', status: 'running', estimateMinutes: 5, startedAt: agoMin(20) },
54
+ ];
55
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
56
+ // Past the floor it does escalate.
57
+ const past = findOverrunningJobs(
58
+ [{ slug: 'tiny', cwd: '/p1', status: 'running', estimateMinutes: 5, startedAt: agoMin(50) }],
59
+ NOW,
60
+ );
61
+ assert.strictEqual(past.length, 1);
62
+ });
63
+
64
+ test('only RUNNING jobs are considered — pending/completed/quarantined are not', () => {
65
+ const base = { cwd: '/p1', estimateMinutes: 10, startedAt: agoMin(300) };
66
+ const jobs = [
67
+ { ...base, slug: 'a', status: 'pending' },
68
+ { ...base, slug: 'b', status: 'completed' },
69
+ { ...base, slug: 'c', status: 'failed' },
70
+ { ...base, slug: 'd', status: 'quarantined' },
71
+ { ...base, slug: 'e', status: 'needs_review' },
72
+ ];
73
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
74
+ });
75
+
76
+ test('a job with no usable estimate or start time is skipped, never guessed at', () => {
77
+ const jobs = [
78
+ { slug: 'no-est', cwd: '/p1', status: 'running', startedAt: agoMin(300) },
79
+ { slug: 'zero-est', cwd: '/p1', status: 'running', estimateMinutes: 0, startedAt: agoMin(300) },
80
+ { slug: 'nan-est', cwd: '/p1', status: 'running', estimateMinutes: 'soon', startedAt: agoMin(300) },
81
+ { slug: 'no-start', cwd: '/p1', status: 'running', estimateMinutes: 10 },
82
+ { slug: 'bad-start', cwd: '/p1', status: 'running', estimateMinutes: 10, startedAt: 'not-a-date' },
83
+ ];
84
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
85
+ });
86
+
87
+ test('a clock skew making elapsed negative does not escalate', () => {
88
+ const jobs = [
89
+ { slug: 'future', cwd: '/p1', status: 'running', estimateMinutes: 10, startedAt: agoMin(-60) },
90
+ ];
91
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
92
+ });
93
+
94
+ test('escalation is per-project and reports every overrunning job', () => {
95
+ const jobs = [
96
+ { slug: 'p1-a', cwd: '/p1', status: 'running', estimateMinutes: 20, startedAt: agoMin(180) },
97
+ { slug: 'p2-a', cwd: '/p2', status: 'running', estimateMinutes: 30, startedAt: agoMin(200) },
98
+ { slug: 'p2-b', cwd: '/p2', status: 'running', estimateMinutes: 60, startedAt: agoMin(30) },
99
+ ];
100
+ const slugs = findOverrunningJobs(jobs, NOW).map((o) => o.slug).sort();
101
+ assert.deepStrictEqual(slugs, ['p1-a', 'p2-a']);
102
+ });
103
+
104
+ test('factor and floor are overridable per call', () => {
105
+ const jobs = [
106
+ { slug: 'x', cwd: '/p1', status: 'running', estimateMinutes: 60, startedAt: agoMin(90) },
107
+ ];
108
+ // Default: 60m x3 = 180m threshold, 90m elapsed → silent.
109
+ assert.deepStrictEqual(findOverrunningJobs(jobs, NOW), []);
110
+ // Tighter factor → escalates.
111
+ assert.strictEqual(findOverrunningJobs(jobs, NOW, { factor: 1.5, floorMs: 0 }).length, 1);
112
+ });
113
+
114
+ test('the shipped defaults are the documented ones', () => {
115
+ assert.strictEqual(JOB_OVERRUN_FACTOR, 3);
116
+ assert.strictEqual(JOB_OVERRUN_FLOOR_MS, 45 * 60_000);
117
+ });
@@ -8,12 +8,16 @@
8
8
  * has running + pending work — the machine-wide `stalled` boolean reads
9
9
  * false (masking burrow), but burrow's own byProject entry must read true.
10
10
  *
11
- * Run: timeout 120 node --test src/main/__tests__/scheduler-stall-per-project.test.cjs
11
+ * Run: timeout 120 npx vitest run src/main/__tests__/scheduler-stall-per-project.test.cjs
12
12
  */
13
13
 
14
14
  'use strict';
15
15
 
16
- const { test } = require('node:test');
16
+ // vitest, NOT node:test — this repo's suite is vitest-only (see CLAUDE.md:
17
+ // "This repo does not use `node --test`"). A node:test file loads under
18
+ // vitest as "No test suite found" and contributes zero tests, so the guard
19
+ // silently doesn't exist. node:assert works fine inside a vitest run.
20
+ import { test } from 'vitest';
17
21
  const assert = require('node:assert/strict');
18
22
  const { computeStallSummary, findStaleQuarantinedJobs, QUARANTINE_ESCALATE_MS } = require('../scheduler.cjs');
19
23
 
@@ -35,11 +35,16 @@ const promptSessionsCreateEpic = require('./lib/promptSessionsCreateEpic.cjs');
35
35
  const agentLibrary = require('./agentLibrary.cjs');
36
36
  const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
37
37
  const { resolveBuildTarget } = require('./lib/buildTarget.cjs');
38
+ const crossProjectFeedback = require('./lib/crossProjectFeedback.cjs');
38
39
  const adminHttp = createAdminHttp();
39
40
  scheduler.registerAdminRoutes(adminHttp);
40
41
  prdCreate.registerAdminRoute(adminHttp, scheduler.remote);
41
42
  prdAdminRoutes.registerAdminRoute(adminHttp, scheduler.remote);
42
43
  chatRunner.registerAdminRoute(adminHttp);
44
+ // Project-to-project feedback conduit — the app is the only process holding
45
+ // several projects' operations roots open, so it performs the cross-folder
46
+ // write (lib/crossProjectFeedback.cjs).
47
+ crossProjectFeedback.registerAdminRoute(adminHttp);
43
48
  const supervisor = require('./supervisor.cjs');
44
49
  const watchers = require('./watchers.cjs');
45
50
  const teams = require('./teams.cjs');