claude-code-session-manager 0.141.0 → 0.143.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 (223) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +76 -153
  3. package/bin/cli.cjs +11 -0
  4. package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
  5. package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
  6. package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
  7. package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
  8. package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
  9. package/dist/assets/Scheduler-CNLjn90m.js +16 -0
  10. package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
  11. package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
  12. package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
  13. package/dist/assets/Toggle-CYajnSdx.js +1 -0
  14. package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
  15. package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
  16. package/dist/assets/index-CdTppjKR.js +3133 -0
  17. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  18. package/dist/index.html +2 -2
  19. package/dist-web/app.css +1 -1
  20. package/dist-web/app.js +496 -484
  21. package/package.json +6 -4
  22. package/plugins/AGENTS.md +4 -3
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  25. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  26. package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
  27. package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
  28. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  29. package/scripts/README.md +2 -0
  30. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  31. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  32. package/scripts/scheduler-mcp-server.cjs +1032 -112
  33. package/src/main/adminRouteRegistry.cjs +69 -0
  34. package/src/main/agentLibrary.cjs +72 -4
  35. package/src/main/agentsIpc.cjs +3 -2
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/chatRunner.cjs +336 -23
  38. package/src/main/config.cjs +35 -1
  39. package/src/main/docEdit.cjs +4 -2
  40. package/src/main/health.cjs +129 -2
  41. package/src/main/index.cjs +110 -52
  42. package/src/main/ipcSchemas.cjs +172 -8
  43. package/src/main/lib/AGENTS.md +1 -1
  44. package/src/main/lib/chatBootRecovery.cjs +2 -0
  45. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  46. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  47. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  48. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  49. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  50. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  51. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  52. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  53. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  54. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  55. package/src/main/lib/demo-video-kit/cast.md +52 -0
  56. package/src/main/lib/demo-video-kit/character.cjs +778 -30
  57. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  58. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  59. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  60. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  61. package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
  62. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  63. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  64. package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
  65. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  66. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  67. package/src/main/lib/demo-video-kit/sound.cjs +166 -9
  68. package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
  69. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  70. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  71. package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
  72. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  73. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  74. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  75. package/src/main/lib/epic/artifactRetention.cjs +356 -0
  76. package/src/main/lib/epic/artifactStore.cjs +435 -0
  77. package/src/main/lib/epic/delegationReadiness.cjs +83 -2
  78. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  79. package/src/main/lib/epic/epicEventLog.cjs +258 -0
  80. package/src/main/lib/epic/epicMint.cjs +43 -1
  81. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  82. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  83. package/src/main/lib/epic/epicPurge.cjs +347 -0
  84. package/src/main/lib/epic/epicReopen.cjs +5 -2
  85. package/src/main/lib/epic/epicSettle.cjs +4 -13
  86. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  87. package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
  88. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  89. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  90. package/src/main/lib/epic/epicValidationHook.cjs +94 -4
  91. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  92. package/src/main/lib/externalContract.cjs +48 -4
  93. package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
  94. package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
  95. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  96. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  97. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  98. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  99. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  100. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  101. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  102. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  103. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  104. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  105. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  106. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
  107. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  108. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  109. package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
  110. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
  111. package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
  112. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  113. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  114. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  115. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  116. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  117. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  118. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  119. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  120. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  121. package/src/main/lib/git/gitWorktree.cjs +8 -0
  122. package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
  123. package/src/main/lib/git/worktreeDeps.cjs +182 -4
  124. package/src/main/lib/mcpToolCatalog.cjs +399 -29
  125. package/src/main/lib/opsOwnership.cjs +141 -28
  126. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  127. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  128. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  129. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  130. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  131. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  132. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  133. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
  134. package/src/main/lib/phaseProjection.cjs +103 -0
  135. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  136. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  137. package/src/main/lib/prd/prdCreate.cjs +387 -228
  138. package/src/main/lib/prd/prdCriteria.cjs +228 -0
  139. package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
  140. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  141. package/src/main/lib/prd/prdSizing.cjs +3 -1
  142. package/src/main/lib/process/cleanEnv.cjs +52 -1
  143. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  144. package/src/main/lib/process/memoryScope.cjs +31 -3
  145. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  146. package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
  147. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  148. package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
  149. package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
  150. package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
  151. package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
  152. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  153. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  154. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  155. package/src/main/lib/promptSessionSchema.cjs +6 -0
  156. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  157. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  158. package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
  159. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  160. package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
  161. package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
  162. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  163. package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
  164. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
  165. package/src/main/lib/scheduler/queueStore.cjs +16 -0
  166. package/src/main/lib/scheduler/rcaReport.cjs +79 -15
  167. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  168. package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
  169. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  170. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  171. package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
  172. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  173. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  174. package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
  175. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  176. package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
  177. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
  178. package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
  179. package/src/main/lib/tasks/mitigationReview.cjs +314 -0
  180. package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
  181. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  182. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  183. package/src/main/lib/tasks/taskRun.cjs +186 -17
  184. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  185. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  186. package/src/main/lib/telemetry/auditEvents.cjs +204 -6
  187. package/src/main/lib/telemetry/auditLog.cjs +6 -2
  188. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  189. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  190. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  191. package/src/main/lib/toolUseClassify.cjs +181 -0
  192. package/src/main/lib/util/atomicFs.cjs +2 -2
  193. package/src/main/lib/util/smfileRange.cjs +77 -0
  194. package/src/main/projectPages.cjs +3 -1
  195. package/src/main/promptSessionEvents.cjs +21 -1
  196. package/src/main/pty.cjs +77 -0
  197. package/src/main/queueOps.cjs +33 -14
  198. package/src/main/runVerify.cjs +74 -9
  199. package/src/main/scheduler/AGENTS.md +1 -0
  200. package/src/main/scheduler/budget.cjs +6 -5
  201. package/src/main/scheduler/prdParser.cjs +46 -13
  202. package/src/main/scheduler/reviewLadder.cjs +9 -25
  203. package/src/main/scheduler/utilizationHold.cjs +191 -0
  204. package/src/main/scheduler.cjs +1932 -213
  205. package/src/main/templates/PRD_AUTHORING.md +11 -3
  206. package/src/main/webRemote.cjs +463 -6
  207. package/src/preload/api.d.ts +576 -39
  208. package/src/preload/apiSurface.json +223 -7
  209. package/src/preload/index.cjs +48 -1
  210. package/src/seed/agents/architect.md +6 -1
  211. package/src/seed/agents/blender-artist.md +2 -1
  212. package/src/seed/agents/competitive-analyst.md +3 -1
  213. package/src/seed/agents/competitive-researcher.md +2 -1
  214. package/src/seed/agents/demo-video-builder.md +98 -87
  215. package/src/seed/agents/dev-lead.md +3 -3
  216. package/src/seed/agents/project-home-builder.md +9 -31
  217. package/src/seed/agents/validator.md +23 -23
  218. package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
  219. package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
  220. package/dist/assets/Scheduler-cyr61UAC.js +0 -16
  221. package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
  222. package/dist/assets/index-B2TQz3nd.js +0 -3121
  223. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -0,0 +1,284 @@
1
+ /**
2
+ * serviceMcpTools.cjs — the MCP tools a paired service (servicePairings.cjs)
3
+ * may call over the Web Remote relay: one entry per SERVICE_TOOL_NAMES name,
4
+ * each { name, description, inputSchema, toRequest(args) } where toRequest
5
+ * maps the call onto the loopback admin route it mirrors:
6
+ *
7
+ * feedback_list_projects() -> GET /admin/feedback/targets
8
+ * feedback_open_session({ ... }) -> POST /admin/feedback/open-session
9
+ * macro_list({ cwd? }) -> GET /admin/macros?cwd=
10
+ * macro_run({ cwd, id, inputs?, effort?, externalRef? }) -> POST /admin/macros/run
11
+ * epic_get({ cwd, id | externalRef, receipt? }) -> GET /admin/epic?cwd=&id=|externalRef=&receipt=1
12
+ * events_read({ after?, kinds?, limit? }) -> GET /admin/events?after=&kinds=&limit=
13
+ *
14
+ * The four tools the stdio server (scripts/scheduler-mcp-server.cjs) also
15
+ * serves share their inputSchema OBJECTS with it — that server imports them
16
+ * from here, so a service and a local agent see the same names and schemas.
17
+ * Their descriptions come from mcpToolCatalog.cjs via composeDescription.
18
+ *
19
+ * macro_run and events_read are SERVICE-ONLY in v1: they are not catalog
20
+ * entries (the external-contract fingerprint stays put) and the stdio server
21
+ * never registers them — a local agent keeps no Epic-starting tool
22
+ * (SINGLE-CREATOR law). No inputSchema uses a top-level oneOf/anyOf (the
23
+ * Claude API refuses those); "exactly one of" rules stay in the handler/route.
24
+ *
25
+ * toRequest only shapes a request; it does not validate (the admin route does).
26
+ * Plain CJS, no Electron dependency — scripts may require it; it requires no
27
+ * script.
28
+ */
29
+ 'use strict';
30
+
31
+ const { MCP_TOOL_CATALOG, composeDescription } = require('../mcpToolCatalog.cjs');
32
+ const { SERVICE_TOOL_NAMES } = require('./servicePairings.cjs');
33
+
34
+ const FEEDBACK_LIST_PROJECTS_INPUT_SCHEMA = { type: 'object', properties: {} };
35
+
36
+ const FEEDBACK_OPEN_SESSION_INPUT_SCHEMA = {
37
+ type: 'object',
38
+ properties: {
39
+ toCwd: {
40
+ type: 'string',
41
+ description: 'Absolute cwd of the RECEIVING project. Must already be a Session Manager project — use feedback_list_projects if unsure.',
42
+ },
43
+ fromCwd: {
44
+ type: 'string',
45
+ description: 'Absolute cwd of YOUR project (the sender). Must differ from toCwd.',
46
+ },
47
+ title: { type: 'string', description: 'One line naming the finding — becomes the receiving queue row' },
48
+ motivation: {
49
+ type: 'string',
50
+ description: 'WHY this is needed, in the originating human\'s terms (max 2000 chars). Lead with this — the approving human reads it first. When a request is split into a series, summarise the overall plan here.',
51
+ },
52
+ plan: {
53
+ type: 'array', items: { type: 'string' },
54
+ description: "Ordered proposed steps (max 20). REQUIRED when tag is 'feature'.",
55
+ },
56
+ acceptanceCriteria: {
57
+ type: 'array', items: { type: 'string' },
58
+ description: 'How the receiving human will know this is done (1-20 items).',
59
+ },
60
+ outOfScope: {
61
+ type: 'array', items: { type: 'string' },
62
+ description: 'Optional: what this proposal deliberately does not cover (max 20).',
63
+ },
64
+ series: {
65
+ type: 'object',
66
+ description: 'Optional: set on EVERY proposal when one request is split into several. Share the same key/title/total across them; index is this proposal\'s position.',
67
+ properties: {
68
+ key: { type: 'string', description: 'Shared kebab-case series id (max 60 chars)' },
69
+ title: { type: 'string', description: 'Shared series title (max 120 chars)' },
70
+ index: { type: 'integer', description: 'This proposal\'s 1-based position in the series' },
71
+ total: { type: 'integer', description: 'Number of proposals in the series (2-50)' },
72
+ },
73
+ required: ['key', 'title', 'index', 'total'],
74
+ },
75
+ body: {
76
+ type: 'string',
77
+ description: 'Supporting detail: evidence, symptom, where observed, references. Self-contained — the reader cannot see your project — but no longer the whole report; motivation/plan/acceptanceCriteria carry the proposal.',
78
+ },
79
+ tag: {
80
+ type: 'string',
81
+ enum: ['bug', 'feature', 'discussion'],
82
+ description: "Mission tag for the receiving session. Defaults to 'discussion' — the tag that keeps /develop available but never assumed, correct for a finding the receiving project has not yet agreed with.",
83
+ },
84
+ fromEpicId: {
85
+ type: 'string',
86
+ description: 'Optional: your own Epic/session id, so a receipt is chained onto your session and the receiving human can see which session is asking. Auto-filled from this process when omitted.',
87
+ },
88
+ agentType: { type: 'string', description: "Optional persona for the receiving session. Defaults to 'architect'." },
89
+ referencePaths: {
90
+ type: 'array', items: { type: 'string' },
91
+ description: 'Optional absolute paths worth reading, appended as Reference lines',
92
+ },
93
+ autoStart: {
94
+ type: 'boolean',
95
+ description: 'Set true ONLY when the human in THIS conversation explicitly asked for this work in the other project. Requires humanRequestQuote. Never set it for work you decided on your own initiative. An unverified request silently falls back to a plain PROPOSED session.',
96
+ },
97
+ humanRequestQuote: {
98
+ type: 'string',
99
+ description: "Required with autoStart. Copy VERBATIM from the human's own message in this conversation; the quoted words themselves must name the target project. Do not paraphrase or write it yourself.",
100
+ },
101
+ externalRef: {
102
+ type: 'string',
103
+ description: 'Optional: your own id for this handoff, 1 to 200 characters of letters, digits or . _ : / @ - (trimmed). It is stored on the new session and returned. Repeating a call with the same toCwd, fromCwd and externalRef opens nothing new and returns the session that already exists (status "existing", existing: true); the same externalRef already used by a different sender is refused with 409.',
104
+ },
105
+ replyMode: {
106
+ type: 'string',
107
+ enum: ['prompt', 'event'],
108
+ description: "Optional: how a reply comes back — 'prompt' (default) wakes your chat session, 'event' records it as data in the audit log for a caller with no chat.",
109
+ },
110
+ },
111
+ required: ['toCwd', 'fromCwd', 'title', 'motivation', 'acceptanceCriteria', 'body'],
112
+ };
113
+
114
+ const MACRO_LIST_INPUT_SCHEMA = {
115
+ type: 'object',
116
+ properties: {
117
+ cwd: { type: 'string', description: "Optional: absolute path to the target project. Defaults to the calling session's own project root (SM_PROJECT_ROOT or process.cwd()) when omitted." },
118
+ },
119
+ };
120
+
121
+ const EPIC_GET_INPUT_SCHEMA = {
122
+ type: 'object',
123
+ properties: {
124
+ cwd: { type: 'string', description: 'Absolute path of the project the Epic belongs to' },
125
+ id: { type: 'string', description: 'The Epic id. Give exactly one of id / externalRef.' },
126
+ externalRef: { type: 'string', description: 'The external reference the Epic was opened with. Give exactly one of id / externalRef.' },
127
+ receipt: { type: 'boolean', description: 'Optional: when true, the answer also carries epic.receipt, what the Epic cost in jobs and chat.' },
128
+ },
129
+ required: ['cwd'],
130
+ };
131
+
132
+ const MACRO_RUN_INPUT_SCHEMA = {
133
+ type: 'object',
134
+ properties: {
135
+ cwd: { type: 'string', description: 'Absolute path of the project the macro belongs to.' },
136
+ id: { type: 'string', description: "The macro id (from macro_list). Only a macro a human ticked 'Can be started by a script' on can be run." },
137
+ inputs: {
138
+ type: 'object',
139
+ additionalProperties: { type: 'string' },
140
+ description: "Optional: values for the macro's {{inputs}}, overlaid on its saved defaults.",
141
+ },
142
+ effort: { type: 'string', description: 'Optional: reasoning effort for the started session (one of the PRD effort levels).' },
143
+ externalRef: {
144
+ type: 'string',
145
+ description: 'Optional: your own id for this run (e.g. a date). The macro starts at most once per ref; a repeat answers with the Epic that already exists.',
146
+ },
147
+ },
148
+ required: ['cwd', 'id'],
149
+ };
150
+
151
+ const EVENTS_READ_KINDS = Object.freeze(['epic_state_changed', 'epic_cross_project_reply']);
152
+
153
+ const EVENTS_READ_INPUT_SCHEMA = {
154
+ type: 'object',
155
+ properties: {
156
+ after: {
157
+ type: 'string',
158
+ description: "Optional: the `next` cursor from your previous call, or 'start' to read from the first kept row. Omit to get no events and a `next` meaning 'from now'.",
159
+ },
160
+ kinds: {
161
+ type: 'array',
162
+ items: { type: 'string', enum: [...EVENTS_READ_KINDS] },
163
+ description: 'Optional: event kinds to return. Defaults to epic_state_changed.',
164
+ },
165
+ limit: { type: 'integer', minimum: 1, maximum: 500, description: 'Optional: page size, 1-500 (default 100).' },
166
+ },
167
+ };
168
+
169
+ const CATALOG_BY_NAME = new Map(MCP_TOOL_CATALOG.map((entry) => [entry.name, entry]));
170
+
171
+ function catalogDescription(name) {
172
+ const entry = CATALOG_BY_NAME.get(name);
173
+ if (!entry) throw new Error(`mcpToolCatalog.cjs has no entry for tool "${name}"`);
174
+ return composeDescription(entry);
175
+ }
176
+
177
+ function isNonEmptyString(v) {
178
+ return typeof v === 'string' && v !== '';
179
+ }
180
+
181
+ const SERVICE_TOOLS = Object.freeze([
182
+ {
183
+ name: 'feedback_list_projects',
184
+ description: catalogDescription('feedback_list_projects'),
185
+ inputSchema: FEEDBACK_LIST_PROJECTS_INPUT_SCHEMA,
186
+ toRequest: () => ({ method: 'GET', path: '/admin/feedback/targets' }),
187
+ },
188
+ {
189
+ name: 'feedback_open_session',
190
+ description: catalogDescription('feedback_open_session'),
191
+ inputSchema: FEEDBACK_OPEN_SESSION_INPUT_SCHEMA,
192
+ // Same body the stdio handler sends minus its env-derived identity: a
193
+ // caller-supplied originClaudeSessionId / originProjectRoot is dropped,
194
+ // since only a local process's own env may vouch for a session.
195
+ toRequest: (args) => {
196
+ const body = { ...(args ?? {}) };
197
+ delete body.originClaudeSessionId;
198
+ delete body.originProjectRoot;
199
+ return { method: 'POST', path: '/admin/feedback/open-session', body };
200
+ },
201
+ },
202
+ {
203
+ name: 'macro_list',
204
+ description: catalogDescription('macro_list'),
205
+ inputSchema: MACRO_LIST_INPUT_SCHEMA,
206
+ toRequest: (args) => {
207
+ const query = {};
208
+ if (isNonEmptyString(args?.cwd)) query.cwd = args.cwd;
209
+ return { method: 'GET', path: '/admin/macros', query };
210
+ },
211
+ },
212
+ {
213
+ name: 'macro_run',
214
+ description: 'Start one of a project\'s saved macros (hot keys) as a new Session, the way a human press would. '
215
+ + "Only a macro a human ticked 'Can be started by a script' on can be run; while that macro's Epic is still running "
216
+ + 'it answers with that Epic (alreadyRunning: true) instead of starting a second one. Pass externalRef to start it at '
217
+ + 'most once per ref. Answer: { ok, epicId, alreadyRunning, externalRef? }; follow it with epic_get / events_read.',
218
+ inputSchema: MACRO_RUN_INPUT_SCHEMA,
219
+ toRequest: (args) => {
220
+ const body = { cwd: args?.cwd, id: args?.id };
221
+ if (args?.inputs !== undefined) body.inputs = args.inputs;
222
+ if (args?.effort !== undefined) body.effort = args.effort;
223
+ if (args?.externalRef !== undefined) body.externalRef = args.externalRef;
224
+ return { method: 'POST', path: '/admin/macros/run', body };
225
+ },
226
+ },
227
+ {
228
+ name: 'epic_get',
229
+ description: catalogDescription('epic_get'),
230
+ inputSchema: EPIC_GET_INPUT_SCHEMA,
231
+ // Mirrors the stdio handler: cwd, then id (preferred) or externalRef,
232
+ // then receipt=1. The "exactly one of" refusal stays with the caller/route.
233
+ toRequest: (args) => {
234
+ const query = {};
235
+ if (args?.cwd) query.cwd = args.cwd;
236
+ if (isNonEmptyString(args?.id)) query.id = args.id;
237
+ else if (isNonEmptyString(args?.externalRef)) query.externalRef = args.externalRef;
238
+ if (args?.receipt === true) query.receipt = '1';
239
+ return { method: 'GET', path: '/admin/epic', query };
240
+ },
241
+ },
242
+ {
243
+ name: 'events_read',
244
+ description: 'Read Epic state changes and cross-project replies after a saved cursor, oldest first. '
245
+ + 'Answer: { ok, events, next, more, gap } — save `next` and send it as `after` next time; call again at once while '
246
+ + '`more` is true; on `gap: true` re-read the Epics you follow with epic_get. kinds: epic_state_changed (default), '
247
+ + 'epic_cross_project_reply.',
248
+ inputSchema: EVENTS_READ_INPUT_SCHEMA,
249
+ toRequest: (args) => {
250
+ const query = {};
251
+ if (isNonEmptyString(args?.after)) query.after = args.after;
252
+ if (Array.isArray(args?.kinds) && args.kinds.length > 0) {
253
+ const bad = args.kinds.filter((k) => !EVENTS_READ_KINDS.includes(k));
254
+ if (bad.length > 0) throw new Error(`events_read: kinds not allowed for a service: ${bad.join(', ')}`);
255
+ query.kinds = args.kinds.join(',');
256
+ }
257
+ if (args?.limit !== undefined) query.limit = String(args.limit);
258
+ return { method: 'GET', path: '/admin/events', query };
259
+ },
260
+ },
261
+ ].map((tool) => Object.freeze(tool)));
262
+
263
+ // Fail at require time if the tool list and the pairing grant list drift.
264
+ {
265
+ const names = SERVICE_TOOLS.map((t) => t.name);
266
+ if (names.length !== SERVICE_TOOL_NAMES.length || SERVICE_TOOL_NAMES.some((n) => !names.includes(n))) {
267
+ throw new Error(`serviceMcpTools: SERVICE_TOOLS (${names.join(', ')}) != SERVICE_TOOL_NAMES (${SERVICE_TOOL_NAMES.join(', ')})`);
268
+ }
269
+ }
270
+
271
+ /** Names served only to a paired service, never by the local stdio server. */
272
+ const SERVICE_ONLY_TOOL_NAMES = Object.freeze(['macro_run', 'events_read']);
273
+
274
+ module.exports = {
275
+ SERVICE_TOOLS,
276
+ SERVICE_ONLY_TOOL_NAMES,
277
+ EVENTS_READ_KINDS,
278
+ FEEDBACK_LIST_PROJECTS_INPUT_SCHEMA,
279
+ FEEDBACK_OPEN_SESSION_INPUT_SCHEMA,
280
+ MACRO_LIST_INPUT_SCHEMA,
281
+ EPIC_GET_INPUT_SCHEMA,
282
+ MACRO_RUN_INPUT_SCHEMA,
283
+ EVENTS_READ_INPUT_SCHEMA,
284
+ };
@@ -0,0 +1,313 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * servicePairings.cjs — store of services paired over the Web Remote relay
5
+ * (first one: Kiln). Pure Node — no Electron — importable in unit tests.
6
+ *
7
+ * File (default ~/.claude/session-manager/remote-services.json, mode 0600):
8
+ * { version: 1, pending: [...], services: [...] }
9
+ *
10
+ * - pending: { pairingId, name, homeCwd, scope, createdAt, expiresAt } — a
11
+ * pairing the owner started; lives 10 minutes (the relay code itself lasts 5).
12
+ * - services: { serviceId, name, homeCwd, scope, pubKey, relayClientId,
13
+ * pairedAt, lastSeenAt, opened: [{ cwd, epicId, externalRef?, at }] } — a
14
+ * confirmed service with its pinned P-256 public key and the ledger of Epics
15
+ * it opened (newest 1000), each keyed by project + id: an Epic id matches
16
+ * only in the project the service opened it in.
17
+ *
18
+ * State is read once from disk (missing/corrupt = empty) and kept in memory;
19
+ * every mutation is written atomically, serialized through one queue. Reads
20
+ * are synchronous over the in-memory copy. Later PRDs use findByPubKey to
21
+ * authenticate a service, `scope` to gate its tools, and hasOpened to limit
22
+ * its reads to its own Epics.
23
+ */
24
+
25
+ const crypto = require('node:crypto');
26
+ const path = require('node:path');
27
+ const { writeTextAtomic, readJsonOrSync } = require('../util/atomicFs.cjs');
28
+
29
+ const STORE_VERSION = 1;
30
+ const PENDING_TTL_MS = 10 * 60 * 1000;
31
+ const MAX_OPENED = 1000;
32
+ const MAX_NAME_LEN = 64;
33
+ const MAX_PUBKEY_LEN = 1024;
34
+ const MAX_EPIC_ID_LEN = 128;
35
+ const MAX_EXTERNAL_REF_LEN = 200;
36
+ const SERVICE_TOOL_NAMES = Object.freeze([
37
+ 'feedback_list_projects',
38
+ 'feedback_open_session',
39
+ 'macro_list',
40
+ 'macro_run',
41
+ 'epic_get',
42
+ 'events_read',
43
+ ]);
44
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
45
+
46
+ function defaultFilePath() {
47
+ const { claudeHome } = require('../scheduler/schedulerPaths.cjs');
48
+ return path.join(claudeHome(), 'session-manager', 'remote-services.json');
49
+ }
50
+
51
+ function validateName(name) {
52
+ if (typeof name !== 'string' || name.trim().length === 0 || name.length > MAX_NAME_LEN || /[\r\n]/.test(name)) {
53
+ throw new Error(`name must be a one-line string of 1 to ${MAX_NAME_LEN} chars`);
54
+ }
55
+ return name;
56
+ }
57
+
58
+ function validateHomeCwd(homeCwd) {
59
+ if (typeof homeCwd !== 'string' || homeCwd.length === 0 || !path.isAbsolute(homeCwd) || homeCwd.includes('\0')) {
60
+ throw new Error('homeCwd must be an absolute path');
61
+ }
62
+ return homeCwd;
63
+ }
64
+
65
+ function validateScope(scope) {
66
+ if (!Array.isArray(scope) || scope.length === 0) throw new Error('scope must be a non-empty list of tool names');
67
+ for (const t of scope) {
68
+ if (typeof t !== 'string' || !SERVICE_TOOL_NAMES.includes(t)) {
69
+ throw new Error(`scope names an unknown tool: ${String(t)}`);
70
+ }
71
+ }
72
+ return [...new Set(scope)];
73
+ }
74
+
75
+ function validateRelayClientId(v) {
76
+ if (v === null || v === undefined) return null;
77
+ if (typeof v !== 'string' || !UUID_RE.test(v)) throw new Error('relayClientId must be a UUID or null');
78
+ return v.toLowerCase();
79
+ }
80
+
81
+ function validatePubKey(pubKey) {
82
+ if (typeof pubKey !== 'string' || pubKey.length === 0 || pubKey.length > MAX_PUBKEY_LEN) {
83
+ throw new Error('pubKey must be a non-empty string');
84
+ }
85
+ return pubKey;
86
+ }
87
+
88
+ function validateEpicId(epicId) {
89
+ if (typeof epicId !== 'string' || epicId.length === 0 || epicId.length > MAX_EPIC_ID_LEN) {
90
+ throw new Error('epicId must be a non-empty string');
91
+ }
92
+ return epicId;
93
+ }
94
+
95
+ function validateLedgerCwd(cwd) {
96
+ if (typeof cwd !== 'string' || cwd.length === 0 || !path.isAbsolute(cwd) || cwd.includes('\0')) {
97
+ throw new Error('cwd must be an absolute path');
98
+ }
99
+ return path.resolve(cwd);
100
+ }
101
+
102
+ function validateExternalRef(externalRef) {
103
+ if (externalRef === undefined || externalRef === null || externalRef === '') return null;
104
+ if (typeof externalRef !== 'string' || externalRef.length > MAX_EXTERNAL_REF_LEN) {
105
+ throw new Error('externalRef must be a string');
106
+ }
107
+ return externalRef;
108
+ }
109
+
110
+ function publicService(s) {
111
+ return {
112
+ serviceId: s.serviceId,
113
+ name: s.name,
114
+ homeCwd: s.homeCwd,
115
+ scope: [...s.scope],
116
+ pubKey: s.pubKey,
117
+ relayClientId: s.relayClientId,
118
+ pairedAt: s.pairedAt,
119
+ lastSeenAt: s.lastSeenAt,
120
+ };
121
+ }
122
+
123
+ function publicPending(p) {
124
+ return { pairingId: p.pairingId, name: p.name, homeCwd: p.homeCwd, scope: [...p.scope], createdAt: p.createdAt, expiresAt: p.expiresAt };
125
+ }
126
+
127
+ function normalizeLoaded(raw) {
128
+ const empty = { version: STORE_VERSION, pending: [], services: [] };
129
+ if (!raw || typeof raw !== 'object') return empty;
130
+ const pending = Array.isArray(raw.pending) ? raw.pending.filter((p) => p && typeof p.pairingId === 'string') : [];
131
+ const services = Array.isArray(raw.services)
132
+ ? raw.services
133
+ .filter((s) => s && typeof s.serviceId === 'string' && typeof s.pubKey === 'string')
134
+ .map((s) => ({ ...s, scope: Array.isArray(s.scope) ? s.scope : [], opened: Array.isArray(s.opened) ? s.opened : [] }))
135
+ : [];
136
+ return { version: STORE_VERSION, pending, services };
137
+ }
138
+
139
+ /**
140
+ * @param {{ filePath?: string, now?: () => number }} [opts]
141
+ */
142
+ function createServicePairings({ filePath, now } = {}) {
143
+ const file = filePath || defaultFilePath();
144
+ const clock = typeof now === 'function' ? now : () => Date.now();
145
+ /** @type {{ version: number, pending: any[], services: any[] } | null} */
146
+ let state = null;
147
+ let queue = Promise.resolve();
148
+
149
+ function load() {
150
+ if (!state) state = normalizeLoaded(readJsonOrSync(file, null));
151
+ return state;
152
+ }
153
+
154
+ function prunePending(s) {
155
+ const t = clock();
156
+ s.pending = s.pending.filter((p) => typeof p.expiresAt === 'number' && p.expiresAt > t);
157
+ }
158
+
159
+ /** Run a mutation then persist; serialized so writes never interleave. */
160
+ function mutate(fn) {
161
+ const run = queue.then(async () => {
162
+ const s = load();
163
+ const result = fn(s);
164
+ await writeTextAtomic(file, `${JSON.stringify(s, null, 2)}\n`, { mode: 0o600 });
165
+ return result;
166
+ });
167
+ queue = run.catch(() => {});
168
+ return run;
169
+ }
170
+
171
+ function findService(serviceId) {
172
+ return load().services.find((x) => x.serviceId === serviceId) || null;
173
+ }
174
+
175
+ return {
176
+ createPending({ name, homeCwd, scope } = /** @type {any} */ ({})) {
177
+ let entry;
178
+ try {
179
+ const t = clock();
180
+ entry = {
181
+ pairingId: crypto.randomUUID(),
182
+ name: validateName(name),
183
+ homeCwd: validateHomeCwd(homeCwd),
184
+ scope: validateScope(scope),
185
+ createdAt: t,
186
+ expiresAt: t + PENDING_TTL_MS,
187
+ };
188
+ } catch (e) {
189
+ return Promise.reject(e);
190
+ }
191
+ return mutate((s) => {
192
+ prunePending(s);
193
+ s.pending.push(entry);
194
+ return { pairingId: entry.pairingId, expiresAt: entry.expiresAt };
195
+ });
196
+ },
197
+
198
+ listPending() {
199
+ const t = clock();
200
+ return load().pending.filter((p) => p.expiresAt > t).map(publicPending);
201
+ },
202
+
203
+ confirmPending(pairingId, pubKey, { relayClientId = null } = {}) {
204
+ let key;
205
+ let relayId;
206
+ try {
207
+ key = validatePubKey(pubKey);
208
+ relayId = validateRelayClientId(relayClientId);
209
+ } catch (e) {
210
+ return Promise.reject(e);
211
+ }
212
+ return mutate((s) => {
213
+ const t = clock();
214
+ const idx = s.pending.findIndex((p) => p.pairingId === pairingId);
215
+ if (idx === -1) throw new Error('no pending pairing with that id');
216
+ const p = s.pending[idx];
217
+ if (!(p.expiresAt > t)) {
218
+ s.pending.splice(idx, 1);
219
+ throw new Error('pending pairing has expired');
220
+ }
221
+ if (s.services.some((x) => x.pubKey === key)) throw new Error('that public key is already paired');
222
+ s.pending.splice(idx, 1);
223
+ prunePending(s);
224
+ const svc = {
225
+ serviceId: crypto.randomUUID(),
226
+ name: p.name,
227
+ homeCwd: p.homeCwd,
228
+ scope: [...p.scope],
229
+ pubKey: key,
230
+ relayClientId: relayId,
231
+ pairedAt: t,
232
+ lastSeenAt: t,
233
+ opened: [],
234
+ };
235
+ s.services.push(svc);
236
+ return publicService(svc);
237
+ });
238
+ },
239
+
240
+ /** Drop a pending pairing so it can no longer be confirmed or listed. Resolves true if it existed. */
241
+ cancelPending(pairingId) {
242
+ if (typeof pairingId !== 'string' || pairingId.length === 0) return Promise.resolve(false);
243
+ return mutate((s) => {
244
+ const before = s.pending.length;
245
+ s.pending = s.pending.filter((p) => p.pairingId !== pairingId);
246
+ const removed = s.pending.length !== before;
247
+ prunePending(s);
248
+ return removed;
249
+ });
250
+ },
251
+
252
+ findByPubKey(pubKey) {
253
+ if (typeof pubKey !== 'string' || pubKey.length === 0) return null;
254
+ const s = load().services.find((x) => x.pubKey === pubKey);
255
+ return s ? publicService(s) : null;
256
+ },
257
+
258
+ list() {
259
+ return load().services.map(publicService);
260
+ },
261
+
262
+ revoke(serviceId) {
263
+ return mutate((s) => {
264
+ const before = s.services.length;
265
+ s.services = s.services.filter((x) => x.serviceId !== serviceId);
266
+ return s.services.length !== before;
267
+ });
268
+ },
269
+
270
+ recordOpened(serviceId, entry) {
271
+ let cwd, id, externalRef;
272
+ try {
273
+ if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) throw new Error('entry must be { cwd, epicId, externalRef? }');
274
+ cwd = validateLedgerCwd(entry.cwd);
275
+ id = validateEpicId(entry.epicId);
276
+ externalRef = validateExternalRef(entry.externalRef);
277
+ } catch (e) { return Promise.reject(e); }
278
+ return mutate((s) => {
279
+ const svc = s.services.find((x) => x.serviceId === serviceId);
280
+ if (!svc) throw new Error('no paired service with that id');
281
+ svc.opened = svc.opened.filter((o) => o && !(o.epicId === id && o.cwd === cwd));
282
+ const rec = { cwd, epicId: id, at: clock() };
283
+ if (externalRef !== null) rec.externalRef = externalRef;
284
+ svc.opened.push(rec);
285
+ if (svc.opened.length > MAX_OPENED) svc.opened = svc.opened.slice(-MAX_OPENED);
286
+ return true;
287
+ });
288
+ },
289
+
290
+ hasOpened(serviceId, cwd, epicId) {
291
+ if (typeof cwd !== 'string' || !path.isAbsolute(cwd) || typeof epicId !== 'string' || epicId === '') return false;
292
+ const want = path.resolve(cwd);
293
+ const svc = findService(serviceId);
294
+ return !!svc && svc.opened.some((o) => o && o.epicId === epicId && o.cwd === want);
295
+ },
296
+
297
+ touchLastSeen(serviceId) {
298
+ return mutate((s) => {
299
+ const svc = s.services.find((x) => x.serviceId === serviceId);
300
+ if (!svc) return false;
301
+ svc.lastSeenAt = clock();
302
+ return true;
303
+ });
304
+ },
305
+ };
306
+ }
307
+
308
+ module.exports = {
309
+ createServicePairings,
310
+ SERVICE_TOOL_NAMES,
311
+ PENDING_TTL_MS,
312
+ MAX_OPENED,
313
+ };