claude-code-session-manager 0.75.3 → 0.77.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 (164) hide show
  1. package/dist/assets/{AgentLibrary-CzQqcObq.js → AgentLibrary-B2ie8bbw.js} +2 -2
  2. package/dist/assets/{DataModel-Bj_WlLz8.js → DataModel-BIJPYw32.js} +1 -1
  3. package/dist/assets/{History-DnSi_OHm.js → History-CeY6dk9S.js} +2 -2
  4. package/dist/assets/{Hooks-0BB0dp3S.js → Hooks-BFH2ocKg.js} +2 -2
  5. package/dist/assets/{HostBilko-DHpwwsLQ.js → HostBilko-36gj9wLz.js} +1 -1
  6. package/dist/assets/{Library-CaJVqVvi.js → Library-C-hBct39.js} +1 -1
  7. package/dist/assets/{ListDetail-C1W2HmC2.js → ListDetail-CNq64VWV.js} +1 -1
  8. package/dist/assets/{MarkdownEditor-5Ob9FW3z.js → MarkdownEditor-Bh3qt5-1.js} +1 -1
  9. package/dist/assets/{McpServers-JxCSfm1S.js → McpServers-DpGN0oyz.js} +1 -1
  10. package/dist/assets/{Memory-BDeqlqwH.js → Memory-D59hUjC4.js} +6 -6
  11. package/dist/assets/{Panel-Dh9ZHuEj.js → Panel-DCgbaoci.js} +1 -1
  12. package/dist/assets/{Permissions-DXy-CbEY.js → Permissions-DAmQ0DYV.js} +2 -2
  13. package/dist/assets/{Plugins-_n1Iuc8T.js → Plugins-Dyfgn6Is.js} +2 -2
  14. package/dist/assets/{ProvenanceBadge-BP_evfxE.js → ProvenanceBadge-BiYhPO1U.js} +1 -1
  15. package/dist/assets/SaveBar-RV7B6sOh.js +1 -0
  16. package/dist/assets/Scheduler-BPaNqx1b.js +14 -0
  17. package/dist/assets/{ScopeSwitcher-CAWzM6RI.js → ScopeSwitcher-P4mdLGNU.js} +1 -1
  18. package/dist/assets/{Settings-DRRozLyT.js → Settings-BL4vf5aX.js} +1 -1
  19. package/dist/assets/{SkillReferenceGraph-DGHDWlz4.js → SkillReferenceGraph-BRBDyi1_.js} +1 -1
  20. package/dist/assets/{Skills-D8L66eiX.js → Skills-BV08gDUH.js} +2 -2
  21. package/dist/assets/{SystemPrompt-CYtUsonD.js → SystemPrompt-CLftSsDw.js} +1 -1
  22. package/dist/assets/TagLibrary-Bp8jGsd5.js +1 -0
  23. package/dist/assets/{TiptapBody-B2hRgbPE.js → TiptapBody-jCpuB6E5.js} +1 -1
  24. package/dist/assets/{Toggle-BTwsbxam.js → Toggle-D2paA1xf.js} +1 -1
  25. package/dist/assets/{index-DijufvkJ.js → index-BDRSqBl3.js} +704 -704
  26. package/dist/assets/{index-CMLnzdZC.css → index-CYhdtisq.css} +1 -1
  27. package/dist/assets/{settingsSchema-D6wzxAi6.js → settingsSchema-6IOLjZZN.js} +1 -1
  28. package/dist/index.html +2 -2
  29. package/package.json +8 -2
  30. package/plugins/session-manager-dev/skills/develop/standards.md +1 -1
  31. package/scripts/lib/activeSessions.cjs +116 -6
  32. package/scripts/project-pages-logic/dist/logic.cjs +4709 -0
  33. package/scripts/render-project-pages/dist/renderer.cjs +18900 -0
  34. package/scripts/render-project-pages.cjs +70 -0
  35. package/scripts/scheduler-mcp-server.cjs +269 -96
  36. package/scripts/validate-project-pages-summary.cjs +62 -0
  37. package/src/main/__tests__/agentModelResolve.test.cjs +66 -0
  38. package/src/main/__tests__/epicStatusMirror.test.cjs +110 -0
  39. package/src/main/__tests__/health-delegation-chain.test.cjs +106 -0
  40. package/src/main/__tests__/prdAdminRoutes.test.cjs +295 -0
  41. package/src/main/__tests__/prdAgentType.test.cjs +103 -0
  42. package/src/main/__tests__/prdCreate.test.cjs +247 -0
  43. package/src/main/__tests__/prdFrontmatterAgentType.test.cjs +117 -0
  44. package/src/main/__tests__/prdFrontmatterQuietMachine.test.cjs +108 -0
  45. package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +485 -0
  46. package/src/main/__tests__/projectPages.test.cjs +73 -1
  47. package/src/main/__tests__/rcaReport.test.cjs +54 -0
  48. package/src/main/__tests__/runVerify.test.cjs +94 -0
  49. package/src/main/__tests__/scheduler-autofix-select.test.cjs +58 -3
  50. package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +103 -0
  51. package/src/main/__tests__/scheduler-commit-guard-noop.test.cjs +41 -0
  52. package/src/main/__tests__/scheduler-effective-concurrency.test.cjs +10 -0
  53. package/src/main/__tests__/scheduler-foreign-wip-manifest.test.cjs +78 -0
  54. package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +242 -0
  55. package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +31 -0
  56. package/src/main/__tests__/scheduler-launch-failure.test.cjs +201 -0
  57. package/src/main/__tests__/scheduler-leftover-fields.test.cjs +52 -0
  58. package/src/main/__tests__/scheduler-looks-done.test.cjs +241 -0
  59. package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +135 -0
  60. package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +222 -0
  61. package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +207 -1
  62. package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +212 -0
  63. package/src/main/__tests__/scheduler-stranded-investigation.test.cjs +185 -0
  64. package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +194 -0
  65. package/src/main/__tests__/seedAgentPersonas.test.cjs +75 -14
  66. package/src/main/__tests__/seedSchedulerMcp.test.cjs +66 -0
  67. package/src/main/__tests__/uniquePrdNumbers.test.cjs +14 -5
  68. package/src/main/bilkoHost.cjs +4 -3
  69. package/src/main/chatRunner.cjs +6 -1
  70. package/src/main/config.cjs +25 -33
  71. package/src/main/health.cjs +153 -2
  72. package/src/main/index.cjs +64 -5
  73. package/src/main/ipcSchemas.cjs +69 -1
  74. package/src/main/lib/__tests__/activeIndexRebuild.test.cjs +179 -0
  75. package/src/main/lib/__tests__/childWithLog.test.cjs +141 -0
  76. package/src/main/lib/__tests__/delegationReadiness.test.cjs +391 -42
  77. package/src/main/lib/__tests__/ephemeralCwd.test.cjs +91 -0
  78. package/src/main/lib/__tests__/epicWorktreeMint.test.cjs +5 -3
  79. package/src/main/lib/__tests__/fixChainDepth.test.cjs +40 -0
  80. package/src/main/lib/__tests__/gitWorktree.test.cjs +290 -5
  81. package/src/main/lib/__tests__/gitWorktreeSalvage.test.cjs +107 -0
  82. package/src/main/lib/__tests__/gitWorktreeSalvageDelta.test.cjs +153 -0
  83. package/src/main/lib/__tests__/jobWorktree.test.cjs +6 -4
  84. package/src/main/lib/__tests__/landedSinceRun.test.cjs +73 -0
  85. package/src/main/lib/__tests__/launchFailure.test.cjs +220 -0
  86. package/src/main/lib/__tests__/loadGate.test.cjs +159 -0
  87. package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +102 -0
  88. package/src/main/lib/__tests__/opsOwnership.test.cjs +7 -0
  89. package/src/main/lib/__tests__/opsRootAbsoluteCwd.test.cjs +151 -0
  90. package/src/main/lib/__tests__/opsRootResolve.test.cjs +149 -0
  91. package/src/main/lib/__tests__/prdDeclaredPaths.test.cjs +82 -0
  92. package/src/main/lib/__tests__/projectRootResolve.test.cjs +148 -0
  93. package/src/main/lib/__tests__/queueHealth.test.cjs +58 -0
  94. package/src/main/lib/__tests__/quietMachineLease.test.cjs +39 -0
  95. package/src/main/lib/__tests__/reaperHelpers.test.cjs +133 -0
  96. package/src/main/lib/__tests__/schedulerBatchDepends.test.cjs +19 -9
  97. package/src/main/lib/__tests__/schedulerBatchFairness.test.cjs +213 -0
  98. package/src/main/lib/__tests__/schedulerBatchLaunchHold.test.cjs +125 -0
  99. package/src/main/lib/__tests__/schedulerBatchProjectCap.test.cjs +127 -0
  100. package/src/main/lib/__tests__/schedulerBatchQuietMachine.test.cjs +109 -0
  101. package/src/main/lib/__tests__/schedulerMcpServerHeadlessRefusal.test.cjs +71 -0
  102. package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +217 -0
  103. package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +350 -0
  104. package/src/main/lib/activeIndexMerge.cjs +15 -0
  105. package/src/main/lib/activeIndexRebuild.cjs +133 -0
  106. package/src/main/lib/agentModelResolve.cjs +58 -0
  107. package/src/main/lib/buildTarget.cjs +3 -2
  108. package/src/main/lib/childWithLog.cjs +69 -2
  109. package/src/main/lib/claudeBin.cjs +54 -1
  110. package/src/main/lib/crossProjectFeedback.cjs +8 -1
  111. package/src/main/lib/definitionOfDone.cjs +3 -2
  112. package/src/main/lib/delegationReadiness.cjs +514 -26
  113. package/src/main/lib/ephemeralCwd.cjs +78 -0
  114. package/src/main/lib/epicDelegationStats.cjs +2 -1
  115. package/src/main/lib/epicMint.cjs +17 -1
  116. package/src/main/lib/epicStatusMirror.cjs +95 -0
  117. package/src/main/lib/epicValidationHook.cjs +2 -1
  118. package/src/main/lib/epicWorktreeMint.cjs +5 -2
  119. package/src/main/lib/fixChainDepth.cjs +45 -0
  120. package/src/main/lib/gitWorktree.cjs +520 -21
  121. package/src/main/lib/jobWorktree.cjs +2 -0
  122. package/src/main/lib/landedSinceRun.cjs +55 -0
  123. package/src/main/lib/launchFailure.cjs +357 -0
  124. package/src/main/lib/loadGate.cjs +134 -0
  125. package/src/main/lib/mcpToolCatalog.cjs +370 -0
  126. package/src/main/lib/opsErrorLog.cjs +12 -1
  127. package/src/main/lib/opsOwnership.cjs +106 -0
  128. package/src/main/lib/prdAdminRoutes.cjs +43 -3
  129. package/src/main/lib/prdAgentType.cjs +84 -0
  130. package/src/main/lib/prdCreate.cjs +103 -15
  131. package/src/main/lib/prdDeclaredPaths.cjs +70 -0
  132. package/src/main/lib/prdFrontmatter.cjs +17 -3
  133. package/src/main/lib/prdLocations.cjs +13 -6
  134. package/src/main/lib/projectHomeAdminRoutes.cjs +402 -0
  135. package/src/main/lib/projectPageSummarySchema.cjs +181 -0
  136. package/src/main/lib/projectRootResolve.cjs +134 -0
  137. package/src/main/lib/promptSessionSchema.cjs +7 -0
  138. package/src/main/lib/queueHealth.cjs +38 -0
  139. package/src/main/lib/queueStore.cjs +40 -7
  140. package/src/main/lib/quietMachineLease.cjs +48 -0
  141. package/src/main/lib/rcaReport.cjs +54 -4
  142. package/src/main/lib/reaperHelpers.cjs +64 -1
  143. package/src/main/lib/scheduleJobSchema.cjs +31 -0
  144. package/src/main/lib/scheduleJobTransitions.cjs +6 -2
  145. package/src/main/lib/schedulerBatch.cjs +301 -55
  146. package/src/main/lib/schedulerConfig.cjs +99 -0
  147. package/src/main/projectBrief.cjs +3 -2
  148. package/src/main/projectPages.cjs +162 -3
  149. package/src/main/promptSessionTranscript.cjs +0 -0
  150. package/src/main/pty.cjs +5 -0
  151. package/src/main/queueOps.cjs +15 -8
  152. package/src/main/runVerify.cjs +50 -9
  153. package/src/main/scheduler/prdParser.cjs +18 -1
  154. package/src/main/scheduler.cjs +1701 -130
  155. package/src/main/seedAgentPersonas.cjs +62 -21
  156. package/src/main/seedSchedulerMcp.cjs +58 -4
  157. package/src/main/templates/project-pages-catalog.json +741 -0
  158. package/src/main/templates/project-pages-pipeline.md +417 -0
  159. package/src/preload/api.d.ts +187 -3
  160. package/src/preload/index.cjs +9 -0
  161. package/src/seed/agents/project-home-builder.md +59 -0
  162. package/dist/assets/SaveBar-D-gCUx4n.js +0 -1
  163. package/dist/assets/Scheduler-Bpd4OGju.js +0 -14
  164. package/dist/assets/TagLibrary-E5CLeuVk.js +0 -1
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+
3
+ // Run: timeout 120 npx vitest run src/main/lib/__tests__/schedulerBatchQuietMachine.test.cjs
4
+ //
5
+ // Pure-logic coverage for the `quietMachine: true` exclusive lease (PRD
6
+ // 1107): dispatched only when zero other jobs are running machine-wide,
7
+ // blocks every other dispatch while its lease is held, degrades (dispatches
8
+ // anyway) once it has waited past the configurable interval, and never
9
+ // touches the ordinary dispatch path for a PRD that doesn't opt in.
10
+
11
+ const assert = require('node:assert/strict');
12
+ const { pickNextBatch } = require('../schedulerBatch.cjs');
13
+
14
+ const CWD_A = '/home/user/Projects/project-a';
15
+ const CWD_B = '/home/user/Projects/project-b';
16
+
17
+ function job(slug, status, cwd, extra = {}) {
18
+ return {
19
+ slug,
20
+ status,
21
+ cwd,
22
+ parallelGroup: Number(String(slug).match(/^(\d+)-/)?.[1] ?? 99),
23
+ dependsOn: [],
24
+ ...extra,
25
+ };
26
+ }
27
+
28
+ const ORIGINAL_WAIT_ENV = process.env.SM_QUIET_MACHINE_WAIT_MINUTES;
29
+ afterEach(() => {
30
+ if (ORIGINAL_WAIT_ENV === undefined) delete process.env.SM_QUIET_MACHINE_WAIT_MINUTES;
31
+ else process.env.SM_QUIET_MACHINE_WAIT_MINUTES = ORIGINAL_WAIT_ENV;
32
+ });
33
+
34
+ test('a quietMachine job dispatches alone when the machine is idle, even with ordinary work also pending', () => {
35
+ const jobs = [
36
+ job('101-quiet', 'pending', CWD_A, { quietMachine: true, createdAt: new Date().toISOString() }),
37
+ job('102-ordinary', 'pending', CWD_A, { createdAt: new Date().toISOString() }),
38
+ job('201-other', 'pending', CWD_B, { createdAt: new Date().toISOString() }),
39
+ ];
40
+ const { batch } = pickNextBatch(jobs, new Set(), 5, { leaseHeld: false, machineInUse: 0, now: Date.now() });
41
+ assert.deepEqual(batch.map((j) => j.slug), ['101-quiet']);
42
+ assert.equal(batch[0].quietLeaseDegraded, false);
43
+ });
44
+
45
+ test('a quietMachine job does NOT dispatch while another job is running machine-wide, and ordinary jobs dispatch unaffected', () => {
46
+ const jobs = [
47
+ job('101-quiet', 'pending', CWD_A, { quietMachine: true, createdAt: new Date().toISOString() }),
48
+ job('201-other', 'pending', CWD_B, { createdAt: new Date().toISOString() }),
49
+ ];
50
+ const { batch } = pickNextBatch(jobs, new Set(), 5, { leaseHeld: false, machineInUse: 1, now: Date.now() });
51
+ assert.deepEqual(batch.map((j) => j.slug), ['201-other']);
52
+ });
53
+
54
+ test('leaseHeld blocks EVERY project from dispatching, not just the quiet job\'s own project', () => {
55
+ const jobs = [
56
+ job('101-quiet', 'running', CWD_A, { quietMachine: true }),
57
+ job('201-other', 'pending', CWD_B, { createdAt: new Date().toISOString() }),
58
+ ];
59
+ const { batch, reason } = pickNextBatch(jobs, new Set(['101-quiet']), 5, { leaseHeld: true, machineInUse: 1, now: Date.now() });
60
+ assert.deepEqual(batch, []);
61
+ assert.match(reason, /quiet-machine/);
62
+ });
63
+
64
+ test('a quietMachine job blocked by dependsOn is skipped even when the machine is idle', () => {
65
+ const jobs = [
66
+ job('100-dep', 'pending', CWD_A, { createdAt: new Date().toISOString() }),
67
+ job('101-quiet', 'pending', CWD_A, { quietMachine: true, dependsOn: ['100-dep'], createdAt: new Date().toISOString() }),
68
+ ];
69
+ const { batch } = pickNextBatch(jobs, new Set(), 5, { leaseHeld: false, machineInUse: 0, now: Date.now() });
70
+ // The quiet job is blocked by its dep; the dep itself is an ordinary job
71
+ // and dispatches normally.
72
+ assert.deepEqual(batch.map((j) => j.slug), ['100-dep']);
73
+ });
74
+
75
+ test('a quietMachine job waiting under the configured interval stays held while the machine is busy', () => {
76
+ process.env.SM_QUIET_MACHINE_WAIT_MINUTES = '30';
77
+ const now = Date.now();
78
+ const queuedAt = new Date(now - 10 * 60_000).toISOString(); // waited 10m
79
+ const jobs = [
80
+ job('101-quiet', 'pending', CWD_A, { quietMachine: true, createdAt: queuedAt }),
81
+ ];
82
+ const { batch } = pickNextBatch(jobs, new Set(), 5, { leaseHeld: false, machineInUse: 1, now });
83
+ assert.deepEqual(batch, []);
84
+ });
85
+
86
+ test('a quietMachine job past the configured wait interval dispatches anyway, marked degraded', () => {
87
+ process.env.SM_QUIET_MACHINE_WAIT_MINUTES = '30';
88
+ const now = Date.now();
89
+ const queuedAt = new Date(now - 31 * 60_000).toISOString(); // waited 31m
90
+ const jobs = [
91
+ job('101-quiet', 'pending', CWD_A, { quietMachine: true, createdAt: queuedAt }),
92
+ ];
93
+ const { batch } = pickNextBatch(jobs, new Set(), 5, { leaseHeld: false, machineInUse: 1, now });
94
+ assert.deepEqual(batch.map((j) => j.slug), ['101-quiet']);
95
+ assert.equal(batch[0].quietLeaseDegraded, true);
96
+ });
97
+
98
+ test('ordinary dispatch path is unchanged when no quietMachine job is present (no quietOpts passed at all)', () => {
99
+ const jobs = [
100
+ job('101-a', 'pending', CWD_A),
101
+ job('102-b', 'pending', CWD_A),
102
+ job('201-a', 'pending', CWD_B),
103
+ ];
104
+ const { batch } = pickNextBatch(jobs, new Set(), 5);
105
+ assert.deepEqual(
106
+ batch.map((j) => j.slug).sort(),
107
+ ['101-a', '102-b', '201-a'],
108
+ );
109
+ });
@@ -0,0 +1,71 @@
1
+ /**
2
+ * schedulerMcpServerHeadlessRefusal.test.cjs — scheduler_create_prd is
3
+ * refused at the authoring boundary when called from inside a headless
4
+ * scheduled job (issue #11 list C1: PRD 460 called /develop from inside its
5
+ * own run, spawned a duplicate PRD, and exited 0 having done nothing).
6
+ * scheduler.cjs stamps SM_SCHEDULER_JOB_SLUG on every job spawn and
7
+ * SM_SCHEDULER_JOB_MAY_QUEUE=1 only for decomposition personas.
8
+ *
9
+ * Run: timeout 120 npx vitest run src/main/lib/__tests__/schedulerMcpServerHeadlessRefusal.test.cjs
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import { test, expect, afterEach } from 'vitest';
15
+ const fsp = require('node:fs/promises');
16
+ const os = require('node:os');
17
+ const path = require('node:path');
18
+
19
+ const SERVER_PATH = path.join(__dirname, '../../../../scripts/scheduler-mcp-server.cjs');
20
+
21
+ const tmpDirs = [];
22
+ const savedEnv = {};
23
+ for (const k of ['SM_SCHEDULER_JOB_SLUG', 'SM_SCHEDULER_JOB_MAY_QUEUE', 'HOME']) savedEnv[k] = process.env[k];
24
+
25
+ afterEach(async () => {
26
+ for (const [k, v] of Object.entries(savedEnv)) {
27
+ if (v === undefined) delete process.env[k]; else process.env[k] = v;
28
+ }
29
+ delete require.cache[require.resolve(SERVER_PATH)];
30
+ while (tmpDirs.length) await fsp.rm(tmpDirs.pop(), { recursive: true, force: true });
31
+ });
32
+
33
+ async function freshServer() {
34
+ const homeDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-mcp-headless-'));
35
+ tmpDirs.push(homeDir);
36
+ process.env.HOME = homeDir;
37
+ delete require.cache[require.resolve(SERVER_PATH)];
38
+ return require(SERVER_PATH);
39
+ }
40
+
41
+ const PRD_ARGS = { title: 'x', goal: 'y', acceptanceCriteria: ['z'] };
42
+
43
+ test('scheduler_create_prd inside a headless job is refused before any admin request', async () => {
44
+ process.env.SM_SCHEDULER_JOB_SLUG = '460-some-prd';
45
+ delete process.env.SM_SCHEDULER_JOB_MAY_QUEUE;
46
+ const { handleCallTool } = await freshServer();
47
+ const result = await handleCallTool({ params: { name: 'scheduler_create_prd', arguments: PRD_ARGS } });
48
+ expect(result.isError).toBe(true);
49
+ const text = result.content[0].text;
50
+ expect(text).toMatch(/refused/);
51
+ expect(text).toMatch(/460-some-prd/);
52
+ expect(text).toMatch(/never queues follow-on work/);
53
+ });
54
+
55
+ test('scheduler_create_prd inside a headless job with SM_SCHEDULER_JOB_MAY_QUEUE=1 is not refused by the gate', async () => {
56
+ process.env.SM_SCHEDULER_JOB_SLUG = '461-architect-plan';
57
+ process.env.SM_SCHEDULER_JOB_MAY_QUEUE = '1';
58
+ const { handleCallTool } = await freshServer();
59
+ const result = await handleCallTool({ params: { name: 'scheduler_create_prd', arguments: PRD_ARGS } });
60
+ // No admin API is configured in this tmp HOME, so the call fails LATER at
61
+ // the admin request — the point is that it was not the headless refusal.
62
+ const text = result.content[0].text;
63
+ expect(text).not.toMatch(/never queues follow-on work/);
64
+ });
65
+
66
+ test('scheduler_create_prd outside a headless job is not refused by the gate', async () => {
67
+ delete process.env.SM_SCHEDULER_JOB_SLUG;
68
+ const { handleCallTool } = await freshServer();
69
+ const result = await handleCallTool({ params: { name: 'scheduler_create_prd', arguments: PRD_ARGS } });
70
+ expect(result.content[0].text).not.toMatch(/never queues follow-on work/);
71
+ });
@@ -0,0 +1,217 @@
1
+ /**
2
+ * schedulerMcpServerHelp.test.cjs — session_manager_help argument handling
3
+ * (none/tool/topic/unknown/both) and the pointer-suffix contract every
4
+ * isError return in scheduler-mcp-server.cjs now carries. Also covers the
5
+ * "app not running" degradation: the static catalog must still answer even
6
+ * when the admin API is unreachable — only the readiness section may report
7
+ * unavailable.
8
+ *
9
+ * TOKEN_PATH (scripts/scheduler-mcp-server.cjs) is computed once, at
10
+ * require-time, from os.homedir(). Since os.homedir() reads process.env.HOME
11
+ * on POSIX, each test temporarily repoints HOME at a fresh tmp dir, clears
12
+ * the require cache, and re-requires the module so TOKEN_PATH resolves under
13
+ * that tmp dir — never touching the real ~/.claude/session-manager/admin-api.json.
14
+ *
15
+ * Run: timeout 120 npx vitest run src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs
16
+ */
17
+ 'use strict';
18
+
19
+ import { test, expect, afterEach } from 'vitest';
20
+ const fsp = require('node:fs/promises');
21
+ const http = require('node:http');
22
+ const os = require('node:os');
23
+ const path = require('node:path');
24
+
25
+ const SERVER_PATH = path.join(__dirname, '../../../../scripts/scheduler-mcp-server.cjs');
26
+
27
+ const tmpDirs = [];
28
+ const servers = [];
29
+ let originalHome;
30
+
31
+ afterEach(async () => {
32
+ if (originalHome !== undefined) {
33
+ process.env.HOME = originalHome;
34
+ originalHome = undefined;
35
+ }
36
+ delete require.cache[require.resolve(SERVER_PATH)];
37
+ while (servers.length) {
38
+ const s = servers.pop();
39
+ await new Promise((resolve) => s.close(resolve));
40
+ }
41
+ while (tmpDirs.length) {
42
+ const d = tmpDirs.pop();
43
+ await fsp.rm(d, { recursive: true, force: true });
44
+ }
45
+ });
46
+
47
+ async function mkTmp() {
48
+ const d = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-mcp-help-'));
49
+ tmpDirs.push(d);
50
+ return d;
51
+ }
52
+
53
+ /** Starts a fake admin HTTP server answering GET /admin/mcp/readiness. */
54
+ function startFakeAdminServer(token, readinessBody) {
55
+ return new Promise((resolve) => {
56
+ const server = http.createServer((req, res) => {
57
+ if (req.headers.authorization !== `Bearer ${token}`) {
58
+ res.writeHead(401, { 'Content-Type': 'application/json' });
59
+ res.end(JSON.stringify({ ok: false, error: 'bad token' }));
60
+ return;
61
+ }
62
+ res.writeHead(200, { 'Content-Type': 'application/json' });
63
+ res.end(JSON.stringify(readinessBody));
64
+ });
65
+ server.listen(0, '127.0.0.1', () => resolve(server));
66
+ });
67
+ }
68
+
69
+ /** Requires a fresh scheduler-mcp-server.cjs with TOKEN_PATH under `homeDir`. */
70
+ function requireServerWithHome(homeDir) {
71
+ originalHome = process.env.HOME;
72
+ process.env.HOME = homeDir;
73
+ delete require.cache[require.resolve(SERVER_PATH)];
74
+ const mod = require(SERVER_PATH);
75
+ process.env.HOME = originalHome;
76
+ originalHome = undefined;
77
+ return mod;
78
+ }
79
+
80
+ async function writeAdminConfig(homeDir, { port, token }) {
81
+ const tokenPath = path.join(homeDir, '.claude', 'session-manager', 'admin-api.json');
82
+ await fsp.mkdir(path.dirname(tokenPath), { recursive: true });
83
+ await fsp.writeFile(tokenPath, JSON.stringify({ port, token }), 'utf8');
84
+ }
85
+
86
+ function callTool(handleCallTool, name, args) {
87
+ return handleCallTool({ params: { name, arguments: args } });
88
+ }
89
+
90
+ test('session_manager_help with no arguments returns grouped tool list + recipe titles + readiness', async () => {
91
+ const homeDir = await mkTmp();
92
+ const token = 'test-token';
93
+ const server = await startFakeAdminServer(token, { ok: true, ready: true, checks: [{ id: 'scheduler-mcp', ok: true }] });
94
+ servers.push(server);
95
+ await writeAdminConfig(homeDir, { port: server.address().port, token });
96
+
97
+ const { handleCallTool } = requireServerWithHome(homeDir);
98
+ const result = await callTool(handleCallTool, 'session_manager_help', {});
99
+ expect(result.isError).toBeFalsy();
100
+ const body = JSON.parse(result.content[0].text);
101
+ expect(Array.isArray(body.tools)).toBe(true);
102
+ expect(body.tools.some((t) => t.name === 'session_manager_help')).toBe(true);
103
+ expect(Array.isArray(body.recipes)).toBe(true);
104
+ expect(body.recipes.some((r) => r.id === 'queue-work-via-develop')).toBe(true);
105
+ expect(body.tool).toBeUndefined();
106
+ expect(body.recipe).toBeUndefined();
107
+ expect(body.readiness.available).toBe(true);
108
+ expect(body.readiness.ok).toBe(true);
109
+ });
110
+
111
+ test('session_manager_help with a valid tool returns that entry including exampleArgs', async () => {
112
+ const homeDir = await mkTmp();
113
+ const token = 'test-token';
114
+ const server = await startFakeAdminServer(token, { ok: true, ready: true, checks: [] });
115
+ servers.push(server);
116
+ await writeAdminConfig(homeDir, { port: server.address().port, token });
117
+
118
+ const { handleCallTool } = requireServerWithHome(homeDir);
119
+ const result = await callTool(handleCallTool, 'session_manager_help', { tool: 'scheduler_create_prd' });
120
+ expect(result.isError).toBeFalsy();
121
+ const body = JSON.parse(result.content[0].text);
122
+ expect(body.tool.name).toBe('scheduler_create_prd');
123
+ expect(body.tool.exampleArgs).toBeTruthy();
124
+ expect(body.tools).toBeUndefined();
125
+ });
126
+
127
+ test('session_manager_help with a valid topic returns that recipe\'s steps', async () => {
128
+ const homeDir = await mkTmp();
129
+ const token = 'test-token';
130
+ const server = await startFakeAdminServer(token, { ok: true, ready: true, checks: [] });
131
+ servers.push(server);
132
+ await writeAdminConfig(homeDir, { port: server.address().port, token });
133
+
134
+ const { handleCallTool } = requireServerWithHome(homeDir);
135
+ const result = await callTool(handleCallTool, 'session_manager_help', { topic: 'unstick-needs-review-job' });
136
+ expect(result.isError).toBeFalsy();
137
+ const body = JSON.parse(result.content[0].text);
138
+ expect(body.recipe.id).toBe('unstick-needs-review-job');
139
+ expect(Array.isArray(body.recipe.steps)).toBe(true);
140
+ expect(body.recipe.steps.length).toBeGreaterThan(0);
141
+ });
142
+
143
+ test('session_manager_help accepts both tool and topic together, returning both sections', async () => {
144
+ const homeDir = await mkTmp();
145
+ const token = 'test-token';
146
+ const server = await startFakeAdminServer(token, { ok: true, ready: true, checks: [] });
147
+ servers.push(server);
148
+ await writeAdminConfig(homeDir, { port: server.address().port, token });
149
+
150
+ const { handleCallTool } = requireServerWithHome(homeDir);
151
+ const result = await callTool(handleCallTool, 'session_manager_help', {
152
+ tool: 'scheduler_list_jobs',
153
+ topic: 'queue-work-via-develop',
154
+ });
155
+ expect(result.isError).toBeFalsy();
156
+ const body = JSON.parse(result.content[0].text);
157
+ expect(body.tool.name).toBe('scheduler_list_jobs');
158
+ expect(body.recipe.id).toBe('queue-work-via-develop');
159
+ });
160
+
161
+ test('session_manager_help with an unknown tool returns a helpful error listing valid names', async () => {
162
+ const homeDir = await mkTmp();
163
+ const { handleCallTool } = requireServerWithHome(homeDir);
164
+ const result = await callTool(handleCallTool, 'session_manager_help', { tool: 'not_a_real_tool' });
165
+ expect(result.isError).toBe(true);
166
+ expect(result.content[0].text).toContain('not_a_real_tool');
167
+ expect(result.content[0].text).toContain('scheduler_create_prd');
168
+ expect(result.content[0].text).toContain('call session_manager_help for the correct usage');
169
+ });
170
+
171
+ test('session_manager_help with an unknown topic returns a helpful error listing valid ids', async () => {
172
+ const homeDir = await mkTmp();
173
+ const { handleCallTool } = requireServerWithHome(homeDir);
174
+ const result = await callTool(handleCallTool, 'session_manager_help', { topic: 'not-a-real-recipe' });
175
+ expect(result.isError).toBe(true);
176
+ expect(result.content[0].text).toContain('not-a-real-recipe');
177
+ expect(result.content[0].text).toContain('queue-work-via-develop');
178
+ });
179
+
180
+ test('session_manager_help still returns the static catalog when the app is not running, with readiness unavailable', async () => {
181
+ // No admin-api.json written under this tmp HOME at all — simulates the app
182
+ // being down. The catalog is bundled in-process, so this must NOT fail
183
+ // wholesale; only the readiness half degrades.
184
+ const homeDir = await mkTmp();
185
+ const { handleCallTool } = requireServerWithHome(homeDir);
186
+ const result = await callTool(handleCallTool, 'session_manager_help', {});
187
+ expect(result.isError).toBeFalsy();
188
+ const body = JSON.parse(result.content[0].text);
189
+ expect(Array.isArray(body.tools)).toBe(true);
190
+ expect(body.tools.length).toBeGreaterThan(0);
191
+ expect(body.readiness.available).toBe(false);
192
+ expect(typeof body.readiness.reason).toBe('string');
193
+ expect(body.readiness.reason.length).toBeGreaterThan(0);
194
+ });
195
+
196
+ test('every isError return from the tool handler carries the session_manager_help pointer', async () => {
197
+ const homeDir = await mkTmp();
198
+ const { handleCallTool } = requireServerWithHome(homeDir);
199
+
200
+ const missingSlug = await callTool(handleCallTool, 'scheduler_reset_job', {});
201
+ expect(missingSlug.isError).toBe(true);
202
+ expect(missingSlug.content[0].text).toContain('call session_manager_help for the correct usage');
203
+
204
+ const unknownTool = await callTool(handleCallTool, 'not_a_tool_at_all', {});
205
+ expect(unknownTool.isError).toBe(true);
206
+ expect(unknownTool.content[0].text).toContain('call session_manager_help for the correct usage');
207
+ });
208
+
209
+ test('NOT_RUNNING_ERROR (app not running) carries the pointer and is surfaced via isError', async () => {
210
+ const homeDir = await mkTmp();
211
+ const { handleCallTool, NOT_RUNNING_ERROR } = requireServerWithHome(homeDir);
212
+ expect(NOT_RUNNING_ERROR).toContain('call session_manager_help for the correct usage');
213
+
214
+ const result = await callTool(handleCallTool, 'scheduler_list_jobs', {});
215
+ expect(result.isError).toBe(true);
216
+ expect(result.content[0].text).toBe(NOT_RUNNING_ERROR);
217
+ });