claude-code-session-manager 0.141.0 → 0.142.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 (200) hide show
  1. package/README.md +80 -70
  2. package/bin/cli.cjs +11 -0
  3. package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
  4. package/dist/assets/{History-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
  5. package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
  6. package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
  7. package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
  8. package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
  10. package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
  11. package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
  12. package/dist/assets/Toggle-CiYCWLjh.js +1 -0
  13. package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
  14. package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-DDunb8Ch.js} +1 -1
  15. package/dist/assets/index-Cn5E9958.js +3133 -0
  16. package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +496 -484
  20. package/package.json +4 -2
  21. package/plugins/AGENTS.md +4 -3
  22. package/plugins/session-manager-dev/hooks/hooks.json +15 -0
  23. package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
  24. package/plugins/session-manager-dev/skills/develop/SKILL.md +52 -18
  25. package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
  26. package/scripts/README.md +1 -0
  27. package/scripts/hooks/guard-tool-risk.cjs +5 -1
  28. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
  29. package/scripts/scheduler-mcp-server.cjs +732 -110
  30. package/src/main/adminRouteRegistry.cjs +59 -0
  31. package/src/main/agentLibrary.cjs +72 -4
  32. package/src/main/agentsIpc.cjs +3 -2
  33. package/src/main/build-info.json +4 -4
  34. package/src/main/chatRunner.cjs +231 -16
  35. package/src/main/config.cjs +30 -0
  36. package/src/main/docEdit.cjs +4 -2
  37. package/src/main/health.cjs +91 -0
  38. package/src/main/index.cjs +98 -48
  39. package/src/main/ipcSchemas.cjs +161 -8
  40. package/src/main/lib/AGENTS.md +1 -1
  41. package/src/main/lib/chatBootRecovery.cjs +2 -0
  42. package/src/main/lib/claude/agentModelResolve.cjs +51 -25
  43. package/src/main/lib/claude/agentSnapshot.cjs +186 -0
  44. package/src/main/lib/claude/environmentProfiles.cjs +242 -0
  45. package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
  46. package/src/main/lib/claude/personaToolScope.cjs +82 -31
  47. package/src/main/lib/claude/runClaudeP.cjs +4 -2
  48. package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
  49. package/src/main/lib/claude/usageCircuit.cjs +49 -21
  50. package/src/main/lib/claude/vaultRefs.cjs +277 -0
  51. package/src/main/lib/demo-video-kit/capture.cjs +282 -12
  52. package/src/main/lib/demo-video-kit/cast.md +43 -0
  53. package/src/main/lib/demo-video-kit/character.cjs +722 -30
  54. package/src/main/lib/demo-video-kit/checks.cjs +120 -1
  55. package/src/main/lib/demo-video-kit/export.cjs +218 -0
  56. package/src/main/lib/demo-video-kit/frames.cjs +104 -9
  57. package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
  58. package/src/main/lib/demo-video-kit/kind-tiktok.md +99 -0
  59. package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
  60. package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
  61. package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
  62. package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
  63. package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
  64. package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
  65. package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
  66. package/src/main/lib/epic/artifactIpc.cjs +153 -0
  67. package/src/main/lib/epic/artifactNotice.cjs +72 -0
  68. package/src/main/lib/epic/artifactRetention.cjs +310 -0
  69. package/src/main/lib/epic/artifactStore.cjs +392 -0
  70. package/src/main/lib/epic/delegationReadiness.cjs +76 -2
  71. package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
  72. package/src/main/lib/epic/epicEventLog.cjs +214 -0
  73. package/src/main/lib/epic/epicMint.cjs +43 -1
  74. package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
  75. package/src/main/lib/epic/epicOutsideState.cjs +18 -4
  76. package/src/main/lib/epic/epicPurge.cjs +347 -0
  77. package/src/main/lib/epic/epicReopen.cjs +5 -2
  78. package/src/main/lib/epic/epicSettle.cjs +4 -13
  79. package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
  80. package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
  81. package/src/main/lib/epic/epicTransitions.cjs +139 -0
  82. package/src/main/lib/epic/epicValidationHook.cjs +81 -2
  83. package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
  84. package/src/main/lib/externalContract.cjs +37 -4
  85. package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
  86. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
  87. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
  88. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
  89. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
  90. package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
  91. package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
  92. package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
  93. package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
  94. package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
  95. package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
  96. package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
  97. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
  98. package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
  99. package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
  100. package/src/main/lib/feedback-remote/pendingReplies.cjs +189 -0
  101. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
  102. package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
  103. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
  104. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
  105. package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
  106. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
  107. package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
  108. package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
  109. package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
  110. package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
  111. package/src/main/lib/git/worktreeDeps.cjs +77 -2
  112. package/src/main/lib/mcpToolCatalog.cjs +304 -28
  113. package/src/main/lib/opsOwnership.cjs +29 -1
  114. package/src/main/lib/opsRetentionSettings.cjs +27 -5
  115. package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
  116. package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
  117. package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
  118. package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
  119. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
  120. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
  121. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +263 -0
  122. package/src/main/lib/phaseProjection.cjs +103 -0
  123. package/src/main/lib/prd/depSlugResolve.cjs +4 -13
  124. package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
  125. package/src/main/lib/prd/prdCreate.cjs +41 -5
  126. package/src/main/lib/prd/prdCriteria.cjs +225 -0
  127. package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
  128. package/src/main/lib/prd/prdGateFiles.cjs +125 -49
  129. package/src/main/lib/prd/prdSizing.cjs +3 -1
  130. package/src/main/lib/process/cleanEnv.cjs +52 -1
  131. package/src/main/lib/process/leftoverRenice.cjs +178 -0
  132. package/src/main/lib/process/memoryScope.cjs +31 -3
  133. package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
  134. package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
  135. package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
  136. package/src/main/lib/project-pages/voicePreview.cjs +196 -0
  137. package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
  138. package/src/main/lib/promptSessionSchema.cjs +6 -0
  139. package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
  140. package/src/main/lib/scheduler/cpuSample.cjs +133 -42
  141. package/src/main/lib/scheduler/criteriaChecks.cjs +169 -0
  142. package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
  143. package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
  144. package/src/main/lib/scheduler/loadGate.cjs +82 -4
  145. package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
  146. package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
  147. package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
  148. package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -0
  149. package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
  150. package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
  151. package/src/main/lib/scheduler/schedulerPaths.cjs +0 -3
  152. package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
  153. package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
  154. package/src/main/lib/scheduler/slotsRoute.cjs +237 -0
  155. package/src/main/lib/scheduler/toolClearance.cjs +258 -0
  156. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
  157. package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
  158. package/src/main/lib/tasks/mitigationReview.cjs +294 -0
  159. package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
  160. package/src/main/lib/tasks/taskIpc.cjs +22 -18
  161. package/src/main/lib/tasks/taskLedger.cjs +147 -25
  162. package/src/main/lib/tasks/taskRun.cjs +186 -17
  163. package/src/main/lib/tasks/taskSwitch.cjs +85 -12
  164. package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
  165. package/src/main/lib/telemetry/auditEvents.cjs +207 -6
  166. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
  167. package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
  168. package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
  169. package/src/main/lib/toolUseClassify.cjs +181 -0
  170. package/src/main/lib/util/smfileRange.cjs +77 -0
  171. package/src/main/projectPages.cjs +3 -1
  172. package/src/main/promptSessionEvents.cjs +5 -0
  173. package/src/main/pty.cjs +68 -0
  174. package/src/main/queueOps.cjs +32 -13
  175. package/src/main/runVerify.cjs +74 -9
  176. package/src/main/scheduler/AGENTS.md +1 -0
  177. package/src/main/scheduler/budget.cjs +6 -5
  178. package/src/main/scheduler/prdParser.cjs +46 -13
  179. package/src/main/scheduler/reviewLadder.cjs +9 -25
  180. package/src/main/scheduler/utilizationHold.cjs +101 -0
  181. package/src/main/scheduler.cjs +1414 -189
  182. package/src/main/templates/PRD_AUTHORING.md +5 -2
  183. package/src/main/webRemote.cjs +463 -6
  184. package/src/preload/api.d.ts +529 -38
  185. package/src/preload/apiSurface.json +209 -7
  186. package/src/preload/index.cjs +46 -1
  187. package/src/seed/agents/architect.md +6 -1
  188. package/src/seed/agents/blender-artist.md +2 -1
  189. package/src/seed/agents/competitive-analyst.md +3 -1
  190. package/src/seed/agents/competitive-researcher.md +2 -1
  191. package/src/seed/agents/demo-video-builder.md +87 -83
  192. package/src/seed/agents/dev-lead.md +3 -3
  193. package/src/seed/agents/project-home-builder.md +9 -31
  194. package/src/seed/agents/validator.md +9 -10
  195. package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
  196. package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
  197. package/dist/assets/Scheduler-cyr61UAC.js +0 -16
  198. package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
  199. package/dist/assets/index-B2TQz3nd.js +0 -3121
  200. package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
@@ -42,6 +42,9 @@ const { readBody, sendJson } = require('./localAdminHttp.cjs');
42
42
  const { readActiveIndex } = require('../epic/epicMint.cjs');
43
43
  const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
44
44
  const { resolveProjectContext } = require('../projectRootResolve.cjs');
45
+ const pendingReplies = require('./pendingReplies.cjs');
46
+
47
+ const { addPendingReply, countPendingForThread } = pendingReplies;
45
48
 
46
49
  /** crossProjectFeedback.cjs is required lazily: its fallback path may require
47
50
  * this module, and a top-level require both ways would hand one side a
@@ -60,6 +63,10 @@ const FALLBACK_NOTICE = 'cross-project-reply-fallback';
60
63
  const EVENT_MODE_REASON = 'asker-requested-event';
61
64
  const AUDIT_MESSAGE_CHARS = 2000;
62
65
  const AUDIT_MAX_REFERENCES = 10;
66
+ const SCHEDULED_AUDIT = 'cross-project-reply-scheduled';
67
+ const DELIVERED_SCHEDULED_AUDIT = 'cross-project-reply-delivered-scheduled';
68
+ const GAVE_UP_SCHEDULED_AUDIT = 'cross-project-reply-scheduled-gave-up';
69
+ const SEMVER_RE = /^\d+\.\d+\.\d+$/;
63
70
 
64
71
  /** Per-Y promise chain: cap check → deliver → receipt run one at a time. */
65
72
  const threadLocks = new Map();
@@ -130,7 +137,20 @@ function validateReplyInput(input) {
130
137
  }
131
138
  referencePaths = input.referencePaths.slice();
132
139
  }
133
- return { ok: true, value: { message, outcome: input.outcome, referencePaths } };
140
+ let deliverWhen = null;
141
+ if (input.deliverWhen !== undefined && input.deliverWhen !== null) {
142
+ const dw = input.deliverWhen;
143
+ const keys = dw && typeof dw === 'object' && !Array.isArray(dw) ? Object.keys(dw) : null;
144
+ if (!keys || keys.length !== 1 || keys[0] !== 'appVersionAbove'
145
+ || typeof dw.appVersionAbove !== 'string' || !SEMVER_RE.test(dw.appVersionAbove)) {
146
+ return bad(400, 'deliverWhen must be { appVersionAbove: "x.y.z" } — the Session Manager version running now');
147
+ }
148
+ deliverWhen = { appVersionAbove: dw.appVersionAbove };
149
+ }
150
+ return {
151
+ ok: true,
152
+ value: { message, outcome: input.outcome, referencePaths, ...(deliverWhen ? { deliverWhen } : {}) },
153
+ };
134
154
  }
135
155
 
136
156
  function defaultSendPrompt(tabId, prompt, extra) {
@@ -213,22 +233,23 @@ function earlierDelivery(receipt, { targetCwd, rt, threadField, sent }) {
213
233
  /**
214
234
  * sendFeedbackReply(input, deps) → Promise<result>
215
235
  *
216
- * input: { message, outcome, referencePaths?, toEpicId?, fromCwd,
236
+ * input: { message, outcome, referencePaths?, toEpicId?, deliverWhen?, fromCwd,
217
237
  * originProjectRoot?, originClaudeSessionId }
238
+ * deliverWhen { appVersionAbove: 'x.y.z' } holds the reply in the
239
+ * pending-reply ledger (pendingReplies.cjs) instead of sending it; its
240
+ * ledger entry holds a slot under MAX_REPLIES_PER_THREAD like a receipt.
218
241
  * deps: { sendPrompt, appendEvent, resolveEpicId, appendAudit, openFallback }
219
242
  * openFallback defaults to crossProjectFeedback.openReplyFallbackSession;
220
243
  * pass null to get a 409 fallbackNeeded instead.
221
244
  */
222
245
  async function sendFeedbackReply(input, deps = {}) {
223
- const sendPrompt = deps.sendPrompt || defaultSendPrompt;
224
- const appendEvent = deps.appendEvent || defaultAppendEvent;
225
246
  const resolveEpicId = deps.resolveEpicId || defaultResolveEpicId;
226
247
  const audit = deps.appendAudit || appendAuditEvent;
227
248
 
228
249
  // 1. Validation.
229
250
  const valid = validateReplyInput(input);
230
251
  if (!valid.ok) return valid;
231
- const { message, outcome, referencePaths } = valid.value;
252
+ const { message, outcome, referencePaths, deliverWhen } = valid.value;
232
253
 
233
254
  // 2. Identity — Y comes ONLY from the caller's chat session id.
234
255
  const originClaudeSessionId = typeof input.originClaudeSessionId === 'string' ? input.originClaudeSessionId : '';
@@ -272,169 +293,249 @@ async function sendFeedbackReply(input, deps = {}) {
272
293
  }
273
294
 
274
295
  return withThreadLock(`${realOr(replierCwd)}\u0000${yId}`, async () => {
275
- // 4. Identical retry, then cap.
296
+ // 4. Identical retry, then cap (receipts + replies still held in the ledger).
276
297
  const receipts = readReceipts(replierCwd, yId);
277
298
  const sent = receipts.length;
299
+ const pending = countPendingForThread(replierCwd, yId);
278
300
  const hash = replyHash(outcome, message);
279
301
  const latest = receipts[sent - 1];
280
- if (latest && latest.reply && latest.reply.hash === hash) {
302
+ if (!deliverWhen && latest && latest.reply && latest.reply.hash === hash) {
281
303
  return earlierDelivery(latest, { targetCwd, rt, threadField, sent });
282
304
  }
283
- if (sent >= MAX_REPLIES_PER_THREAD) {
305
+ const used = sent + pending;
306
+ if (deliverWhen) {
307
+ // Identical scheduled retry: the reply this thread already holds, not a new one.
308
+ const held = pendingReplies.listPendingForThread(replierCwd, yId).find((e) => e.outcome === outcome
309
+ && (e.hash || replyHash(e.outcome, e.message)) === hash);
310
+ if (held) {
311
+ return {
312
+ ok: true,
313
+ delivery: 'scheduled',
314
+ alreadyScheduled: true,
315
+ id: held.id,
316
+ deliverWhen: { appVersionAbove: held.appVersionAbove },
317
+ repliesUsed: used,
318
+ repliesLeft: Math.max(0, MAX_REPLIES_PER_THREAD - used),
319
+ };
320
+ }
321
+ }
322
+ if (used >= MAX_REPLIES_PER_THREAD) {
284
323
  return bad(429, `reply limit of ${MAX_REPLIES_PER_THREAD} reached for this thread`);
285
324
  }
286
325
 
287
- if (eventMode) {
288
- return replyAsEvent({
289
- appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y,
290
- message, outcome, referencePaths, hash,
326
+ if (deliverWhen) {
327
+ addPendingReply({
328
+ replierCwd,
329
+ yId,
330
+ goalText: y.goalText,
331
+ thread: {
332
+ cwd: rt.cwd, epicId: rt.epicId, claudeSessionId: rt.claudeSessionId,
333
+ legacy, mode: resolved.mode || null,
334
+ },
335
+ targetCwd,
336
+ outcome,
337
+ message,
338
+ referencePaths,
339
+ appVersionAbove: deliverWhen.appVersionAbove,
340
+ hash,
341
+ ySource: y.source || {},
342
+ sentAtScheduling: used + 1,
291
343
  });
292
- }
293
-
294
- // The fallback (default: crossProjectFeedback.openReplyFallbackSession,
295
- // the only cross-project mint authority) opens a NEW proposed Epic in the
296
- // asking project. `openFallback: null` disables it (409 fallbackNeeded).
297
- const openFallback = Object.prototype.hasOwnProperty.call(deps, 'openFallback')
298
- ? deps.openFallback
299
- : (args) => feedbackConduit().openReplyFallbackSession(args);
300
- const fallback = async (reason) => {
301
- if (typeof openFallback !== 'function') {
302
- return bad(409, `the asking Epic cannot take a reply: ${reason}`, { fallbackNeeded: true, reason });
303
- }
304
- const opened = await openFallback({
305
- reason,
306
- toCwd: targetCwd,
307
- toEpicId: rt.epicId,
344
+ audit(SCHEDULED_AUDIT, {
345
+ cwd: targetCwd,
346
+ epicId: rt.epicId || null,
308
347
  fromCwd: replierCwd,
309
348
  fromEpicId: yId,
310
- message,
311
349
  outcome,
312
- referencePaths,
313
- originClaudeSessionId,
314
- original: originalRequest(y),
350
+ appVersionAbove: deliverWhen.appVersionAbove,
351
+ ...threadField,
315
352
  });
316
- if (!opened || !opened.ok || typeof opened.epicId !== 'string') return opened;
317
- const project = path.basename(targetCwd);
318
- const reused = opened.reused === true;
319
- // A reused fallback Epic already carries the first reply in its opening
320
- // prompt; this one must land in it too, or its text is lost.
321
- let landedInFallback = null;
322
- if (reused) {
323
- landedInFallback = await deliverIntoReusedFallback({
324
- sendPrompt, appendEvent, targetCwd, epicId: opened.epicId,
325
- replierCwd, yId, y, outcome, message, referencePaths,
326
- });
327
- }
328
- // Receipt on Y — counts toward the per-thread cap like a delivered reply.
329
- const receipt = await appendEvent(replierCwd, yId,
330
- reused
331
- ? `Reply to ${rt.epicId} in ${project} fell back into the open session ${opened.epicId} in ${project} (${reason}).`
332
- : `Reply to ${rt.epicId} in ${project} fell back to a new proposed session ${opened.epicId} in ${project} (${reason}).`,
333
- {
334
- notice: RECEIPT_NOTICE,
335
- allowInactive: true,
336
- reply: {
337
- fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
338
- delivery: 'fallback', toEpicId: rt.epicId, fallbackEpicId: opened.epicId, reason,
339
- ...(reused ? { reused: true } : {}),
340
- },
341
- });
342
- // Best-effort receipt on X, only while X is still in A's active index.
343
- let receiptOnAskingEpic = false;
344
- try {
345
- if (readActiveIndex(targetCwd).sessions[rt.epicId]) {
346
- const r = await appendEvent(targetCwd, rt.epicId,
347
- `A reply from ${path.basename(replierCwd)} (${outcome}) could not be delivered here (${reason}); `
348
- + (reused ? `it was added to the open session ${opened.epicId}.` : `it opened as a new proposed session ${opened.epicId}.`),
349
- { notice: FALLBACK_NOTICE, allowInactive: true, reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, fallbackEpicId: opened.epicId } });
350
- receiptOnAskingEpic = !!(r && r.ok);
351
- }
352
- } catch { receiptOnAskingEpic = false; }
353
353
  return {
354
354
  ok: true,
355
- delivery: 'fallback',
356
- reason,
357
- toCwd: targetCwd,
358
- toEpicId: rt.epicId,
359
- fallbackEpicId: opened.epicId,
360
- ...(reused ? { reused: true, landedInFallback } : {}),
361
- receiptOnAskingEpic,
362
- ...threadField,
363
- ...receiptFields(receipt),
364
- repliesUsed: sent + 1,
365
- repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
355
+ delivery: 'scheduled',
356
+ deliverWhen,
357
+ repliesUsed: used + 1,
358
+ repliesLeft: MAX_REPLIES_PER_THREAD - used - 1,
366
359
  };
367
- };
368
-
369
- // 5. Deliver.
370
- const x = readActiveIndex(targetCwd).sessions[rt.epicId];
371
- if (!x) return fallback('missing');
372
- if (x.status !== 'active') return fallback('not-active');
373
- // Legacy threads carry no session pin; X's own (1:1, life-long) session is the one that asked.
374
- if (legacy ? !(typeof x.claudeSessionId === 'string' && x.claudeSessionId) : x.claudeSessionId !== rt.claudeSessionId) {
375
- return fallback('session-mismatch');
376
360
  }
377
361
 
378
- const prompt = composeReplyPrompt({
362
+ return deliverAuthorizedReply({
363
+ replierCwd, yId, y, rt, legacy, eventMode, threadField, targetCwd,
364
+ message, outcome, referencePaths, hash, sent: used, originClaudeSessionId,
365
+ }, deps);
366
+ });
367
+ }
368
+
369
+ /**
370
+ * deliverAuthorizedReply(ctx, deps) → Promise<result>. The send-and-fallback
371
+ * half of a reply whose identity, thread and cap checks already passed — run
372
+ * inside the per-Y thread lock. sendFeedbackReply calls it for a live reply;
373
+ * the pending-reply deliverer reuses it for a held one. ctx.sent = replies
374
+ * already counted against the cap (this one excluded).
375
+ *
376
+ * ctx: { replierCwd, yId, y, rt, legacy, eventMode, threadField, targetCwd,
377
+ * message, outcome, referencePaths, hash, sent, originClaudeSessionId? }
378
+ * deps: { sendPrompt, appendEvent, appendAudit, openFallback } (see sendFeedbackReply)
379
+ */
380
+ async function deliverAuthorizedReply(ctx, deps = {}) {
381
+ const {
382
+ replierCwd, yId, y, rt, legacy, eventMode, threadField = {}, targetCwd,
383
+ message, outcome, referencePaths = [], hash, sent, originClaudeSessionId,
384
+ } = ctx;
385
+ const sendPrompt = deps.sendPrompt || defaultSendPrompt;
386
+ const appendEvent = deps.appendEvent || defaultAppendEvent;
387
+ const audit = deps.appendAudit || appendAuditEvent;
388
+
389
+ if (eventMode) {
390
+ return replyAsEvent({
391
+ appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y,
392
+ message, outcome, referencePaths, hash,
393
+ });
394
+ }
395
+
396
+ // The fallback (default: crossProjectFeedback.openReplyFallbackSession,
397
+ // the only cross-project mint authority) opens a NEW proposed Epic in the
398
+ // asking project. `openFallback: null` disables it (409 fallbackNeeded).
399
+ const openFallback = Object.prototype.hasOwnProperty.call(deps, 'openFallback')
400
+ ? deps.openFallback
401
+ : (args) => feedbackConduit().openReplyFallbackSession(args);
402
+ const fallback = async (reason) => {
403
+ if (typeof openFallback !== 'function') {
404
+ return bad(409, `the asking Epic cannot take a reply: ${reason}`, { fallbackNeeded: true, reason });
405
+ }
406
+ const opened = await openFallback({
407
+ reason,
408
+ toCwd: targetCwd,
409
+ toEpicId: rt.epicId,
379
410
  fromCwd: replierCwd,
380
411
  fromEpicId: yId,
381
- fromGoalText: y.goalText,
382
- outcome,
383
412
  message,
413
+ outcome,
384
414
  referencePaths,
415
+ originClaudeSessionId,
416
+ original: originalRequest(y),
385
417
  });
386
- const appended = await appendEvent(targetCwd, x.id, prompt, {
387
- notice: REPLY_NOTICE,
388
- reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
389
- });
390
- if (!appended || !appended.ok) return fallback((appended && appended.reason) || 'append-failed');
391
-
392
- let sendResult;
393
- try {
394
- sendResult = await sendPrompt(x.id, prompt, { sessionId: x.claudeSessionId, cwd: x.cwd || targetCwd });
395
- } catch (e) {
396
- sendResult = { disposition: 'unconfirmed', reason: e && e.message ? e.message : 'send-error' };
418
+ if (!opened || !opened.ok || typeof opened.epicId !== 'string') return opened;
419
+ const project = path.basename(targetCwd);
420
+ const reused = opened.reused === true;
421
+ // A reused fallback Epic already carries the first reply in its opening
422
+ // prompt; this one must land in it too, or its text is lost.
423
+ let landedInFallback = null;
424
+ if (reused) {
425
+ landedInFallback = await deliverIntoReusedFallback({
426
+ sendPrompt, appendEvent, targetCwd, epicId: opened.epicId,
427
+ replierCwd, yId, y, outcome, message, referencePaths,
428
+ });
397
429
  }
398
- const disposition = sendResult && sendResult.disposition;
399
- if (disposition === 'refused') return fallback(`send-refused:${sendResult.reason || 'unknown'}`);
400
- const delivery = disposition === 'sent' || disposition === 'queued' ? 'delivered' : 'event-only';
401
-
402
- // 6. Receipt on Y (counts toward the cap).
430
+ // Receipt on Y — counts toward the per-thread cap like a delivered reply.
403
431
  const receipt = await appendEvent(replierCwd, yId,
404
- `Reply sent to ${x.id} in ${path.basename(targetCwd)} (${outcome}, ${delivery}).`,
432
+ reused
433
+ ? `Reply to ${rt.epicId} in ${project} fell back into the open session ${opened.epicId} in ${project} (${reason}).`
434
+ : `Reply to ${rt.epicId} in ${project} fell back to a new proposed session ${opened.epicId} in ${project} (${reason}).`,
405
435
  {
406
436
  notice: RECEIPT_NOTICE,
407
437
  allowInactive: true,
408
438
  reply: {
409
439
  fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
410
- delivery, toEpicId: x.id,
411
- ...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
440
+ delivery: 'fallback', toEpicId: rt.epicId, fallbackEpicId: opened.epicId, reason,
441
+ ...(reused ? { reused: true } : {}),
412
442
  },
413
443
  });
414
-
415
- // 7. Audit.
416
- audit('epic_cross_project_reply', {
417
- cwd: targetCwd,
418
- epicId: x.id,
419
- fromCwd: replierCwd,
420
- fromEpicId: yId,
421
- outcome,
422
- delivery,
423
- ...threadField,
424
- });
425
-
444
+ // Best-effort receipt on X, only while X is still in A's active index.
445
+ let receiptOnAskingEpic = false;
446
+ try {
447
+ if (readActiveIndex(targetCwd).sessions[rt.epicId]) {
448
+ const r = await appendEvent(targetCwd, rt.epicId,
449
+ `A reply from ${path.basename(replierCwd)} (${outcome}) could not be delivered here (${reason}); `
450
+ + (reused ? `it was added to the open session ${opened.epicId}.` : `it opened as a new proposed session ${opened.epicId}.`),
451
+ { notice: FALLBACK_NOTICE, allowInactive: true, reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, fallbackEpicId: opened.epicId } });
452
+ receiptOnAskingEpic = !!(r && r.ok);
453
+ }
454
+ } catch { receiptOnAskingEpic = false; }
426
455
  return {
427
456
  ok: true,
428
- delivery,
457
+ delivery: 'fallback',
458
+ reason,
429
459
  toCwd: targetCwd,
430
- toEpicId: x.id,
460
+ toEpicId: rt.epicId,
461
+ fallbackEpicId: opened.epicId,
462
+ ...(reused ? { reused: true, landedInFallback } : {}),
463
+ receiptOnAskingEpic,
431
464
  ...threadField,
432
465
  ...receiptFields(receipt),
433
466
  repliesUsed: sent + 1,
434
467
  repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
435
- ...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
436
468
  };
469
+ };
470
+
471
+ // 5. Deliver.
472
+ const x = readActiveIndex(targetCwd).sessions[rt.epicId];
473
+ if (!x) return fallback('missing');
474
+ if (x.status !== 'active') return fallback('not-active');
475
+ // Legacy threads carry no session pin; X's own (1:1, life-long) session is the one that asked.
476
+ if (legacy ? !(typeof x.claudeSessionId === 'string' && x.claudeSessionId) : x.claudeSessionId !== rt.claudeSessionId) {
477
+ return fallback('session-mismatch');
478
+ }
479
+
480
+ const prompt = composeReplyPrompt({
481
+ fromCwd: replierCwd,
482
+ fromEpicId: yId,
483
+ fromGoalText: y.goalText,
484
+ outcome,
485
+ message,
486
+ referencePaths,
487
+ });
488
+ const appended = await appendEvent(targetCwd, x.id, prompt, {
489
+ notice: REPLY_NOTICE,
490
+ reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
437
491
  });
492
+ if (!appended || !appended.ok) return fallback((appended && appended.reason) || 'append-failed');
493
+
494
+ let sendResult;
495
+ try {
496
+ sendResult = await sendPrompt(x.id, prompt, { sessionId: x.claudeSessionId, cwd: x.cwd || targetCwd });
497
+ } catch (e) {
498
+ sendResult = { disposition: 'unconfirmed', reason: e && e.message ? e.message : 'send-error' };
499
+ }
500
+ const disposition = sendResult && sendResult.disposition;
501
+ if (disposition === 'refused') return fallback(`send-refused:${sendResult.reason || 'unknown'}`);
502
+ const delivery = disposition === 'sent' || disposition === 'queued' ? 'delivered' : 'event-only';
503
+
504
+ // 6. Receipt on Y (counts toward the cap).
505
+ const receipt = await appendEvent(replierCwd, yId,
506
+ `Reply sent to ${x.id} in ${path.basename(targetCwd)} (${outcome}, ${delivery}).`,
507
+ {
508
+ notice: RECEIPT_NOTICE,
509
+ allowInactive: true,
510
+ reply: {
511
+ fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
512
+ delivery, toEpicId: x.id,
513
+ ...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
514
+ },
515
+ });
516
+
517
+ // 7. Audit.
518
+ audit('epic_cross_project_reply', {
519
+ cwd: targetCwd,
520
+ epicId: x.id,
521
+ fromCwd: replierCwd,
522
+ fromEpicId: yId,
523
+ outcome,
524
+ delivery,
525
+ ...threadField,
526
+ });
527
+
528
+ return {
529
+ ok: true,
530
+ delivery,
531
+ toCwd: targetCwd,
532
+ toEpicId: x.id,
533
+ ...threadField,
534
+ ...receiptFields(receipt),
535
+ repliesUsed: sent + 1,
536
+ repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
537
+ ...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
538
+ };
438
539
  }
439
540
 
440
541
  /**
@@ -587,6 +688,165 @@ function resolveThread(src) {
587
688
  };
588
689
  }
589
690
 
691
+ /**
692
+ * deliverDueReplies({ appVersion }, deps) → Promise<{ due, delivered, failed, results }>.
693
+ * Sends every pending-reply ledger entry whose appVersionAbove is now below
694
+ * appVersion: `{version}` in its message becomes appVersion, then it goes
695
+ * through deliverAuthorizedReply (same path + fallback as a live reply) under
696
+ * the same per-Y thread lock. The thread rule was checked when the reply was
697
+ * scheduled; the stored thread is the only target. The scheduling Epic Y may
698
+ * have closed since — the reply still goes, and the receipt on Y is written
699
+ * only while Y is still in its project's active index. A delivery that throws
700
+ * or returns not-ok stays pending with lastError (attempts + 1); the 24th
701
+ * failure gives up (gaveUpAt) and is audited GAVE_UP_SCHEDULED_AUDIT. A pass
702
+ * started while another is still running in this process returns
703
+ * { skipped: true } and sends nothing. The pass never throws.
704
+ *
705
+ * deps: deliverAuthorizedReply's deps plus { listDueReplies, markReplyDelivered }
706
+ * (default: pendingReplies.cjs).
707
+ */
708
+ let dueRepliesPassRunning = false;
709
+
710
+ async function deliverDueReplies(opts = {}, deps = {}) {
711
+ if (dueRepliesPassRunning) return { due: 0, delivered: 0, failed: 0, results: [], skipped: true };
712
+ dueRepliesPassRunning = true;
713
+ try {
714
+ return await runDueRepliesPass(opts, deps);
715
+ } finally {
716
+ dueRepliesPassRunning = false;
717
+ }
718
+ }
719
+
720
+ /**
721
+ * Log meta for one 'scheduled replies pass' line. `skipped` tells a pass that
722
+ * deliverDueReplies skipped (a previous pass still running) apart from a pass
723
+ * that ran and found nothing due — both report due 0.
724
+ */
725
+ function replyPassLogMeta(r, appVersion) {
726
+ return {
727
+ appVersion,
728
+ due: r.due,
729
+ delivered: r.delivered,
730
+ failed: r.failed,
731
+ skipped: r.skipped === true,
732
+ ...(r.error ? { error: r.error } : {}),
733
+ };
734
+ }
735
+
736
+ async function runDueRepliesPass({ appVersion } = {}, deps = {}) {
737
+ const summary = { due: 0, delivered: 0, failed: 0, results: [] };
738
+ const listDue = deps.listDueReplies || pendingReplies.listDueReplies;
739
+ const markDelivered = deps.markReplyDelivered || pendingReplies.markReplyDelivered;
740
+ const audit = deps.appendAudit || appendAuditEvent;
741
+ let due;
742
+ try {
743
+ due = listDue(appVersion);
744
+ } catch (e) {
745
+ summary.error = e && e.message ? e.message : String(e);
746
+ return summary;
747
+ }
748
+ if (!Array.isArray(due)) return summary;
749
+ summary.due = due.length;
750
+ const version = String(appVersion);
751
+
752
+ for (const entry of due) {
753
+ let result;
754
+ try {
755
+ result = await deliverOneDueReply(entry, version, deps);
756
+ } catch (e) {
757
+ result = { ok: false, error: e && e.message ? e.message : String(e) };
758
+ }
759
+ const ok = !!(result && result.ok);
760
+ if (ok) {
761
+ summary.delivered += 1;
762
+ try {
763
+ audit(DELIVERED_SCHEDULED_AUDIT, {
764
+ cwd: entry.targetCwd || null,
765
+ epicId: (entry.thread && entry.thread.epicId) || null,
766
+ fromCwd: entry.replierCwd || null,
767
+ fromEpicId: entry.yId || null,
768
+ outcome: entry.outcome || null,
769
+ appVersionAbove: entry.appVersionAbove || null,
770
+ appVersion: version,
771
+ delivery: result.delivery || null,
772
+ ...(entry.thread && entry.thread.legacy ? { thread: 'legacy' } : {}),
773
+ });
774
+ } catch { /* audit is best-effort */ }
775
+ } else {
776
+ summary.failed += 1;
777
+ }
778
+ try {
779
+ const marked = markDelivered(entry.id, {
780
+ version,
781
+ result: ok ? result : { ...(result || {}), ok: false, error: (result && (result.error || result.reason)) || 'delivery failed' },
782
+ });
783
+ if (!ok && marked && marked.gaveUpAt && !entry.gaveUpAt) {
784
+ try {
785
+ audit(GAVE_UP_SCHEDULED_AUDIT, {
786
+ cwd: entry.targetCwd || null,
787
+ epicId: (entry.thread && entry.thread.epicId) || null,
788
+ fromCwd: entry.replierCwd || null,
789
+ fromEpicId: entry.yId || null,
790
+ outcome: entry.outcome || null,
791
+ appVersionAbove: entry.appVersionAbove || null,
792
+ appVersion: version,
793
+ attempts: marked.attempts,
794
+ lastError: marked.lastError || null,
795
+ ...(entry.thread && entry.thread.legacy ? { thread: 'legacy' } : {}),
796
+ });
797
+ } catch { /* audit is best-effort */ }
798
+ }
799
+ } catch (e) {
800
+ // A failed ledger write leaves the entry due; a delivered one may resend next pass.
801
+ summary.markError = e && e.message ? e.message : String(e);
802
+ }
803
+ summary.results.push({ id: entry.id, ok, ...(result && result.delivery ? { delivery: result.delivery } : {}), ...(ok ? {} : { error: (result && (result.error || result.reason)) || 'delivery failed' }) });
804
+ }
805
+ return summary;
806
+ }
807
+
808
+ async function deliverOneDueReply(entry, version, deps) {
809
+ if (!entry || typeof entry !== 'object') return { ok: false, error: 'ill-shaped ledger entry' };
810
+ const { replierCwd, yId, targetCwd } = entry;
811
+ const thread = entry.thread && typeof entry.thread === 'object' ? entry.thread : {};
812
+ if (!nonEmpty(replierCwd) || !nonEmpty(yId) || !nonEmpty(targetCwd) || !nonEmpty(thread.cwd)) {
813
+ return { ok: false, error: 'ledger entry is missing its thread context' };
814
+ }
815
+ const eventMode = thread.mode === 'event';
816
+ if (!eventMode && !nonEmpty(thread.epicId)) return { ok: false, error: 'ledger entry has no asking Epic' };
817
+ const message = String(entry.message ?? '').split('{version}').join(version);
818
+ const outcome = entry.outcome;
819
+ const referencePaths = Array.isArray(entry.referencePaths) ? entry.referencePaths : [];
820
+ const legacy = thread.legacy === true;
821
+ const rt = { cwd: thread.cwd, epicId: thread.epicId || null, claudeSessionId: thread.claudeSessionId || null };
822
+
823
+ return withThreadLock(`${realOr(replierCwd)}\u0000${yId}`, async () => {
824
+ let yLive = null;
825
+ try { yLive = readActiveIndex(replierCwd).sessions[yId] || null; } catch { yLive = null; }
826
+ // A closed Y is rebuilt from what the ledger stored at scheduling time:
827
+ // its source (externalRef, proposal, replyTo) and the count this reply took.
828
+ const ySource = entry.ySource && typeof entry.ySource === 'object' && !Array.isArray(entry.ySource) ? entry.ySource : {};
829
+ const y = yLive || { id: yId, goalText: entry.goalText || '', source: ySource };
830
+ const atScheduling = Number.isInteger(entry.sentAtScheduling) && entry.sentAtScheduling > 0
831
+ ? entry.sentAtScheduling - 1 : 0;
832
+ const sent = yLive ? readReceipts(replierCwd, yId).length : atScheduling;
833
+ const baseAppend = deps.appendEvent || defaultAppendEvent;
834
+ // Receipt on Y only while Y is still in its project's active index.
835
+ const appendEvent = (cwd, epicId, text, meta) => {
836
+ if (!yLive && epicId === yId && cwd === replierCwd) {
837
+ return Promise.resolve({ ok: false, reason: 'replier-closed' });
838
+ }
839
+ return baseAppend(cwd, epicId, text, meta);
840
+ };
841
+ return deliverAuthorizedReply({
842
+ replierCwd, yId, y, rt, legacy, eventMode,
843
+ threadField: legacy ? { thread: 'legacy' } : {},
844
+ targetCwd, message, outcome, referencePaths,
845
+ hash: replyHash(outcome, message), sent,
846
+ }, { ...deps, appendEvent });
847
+ });
848
+ }
849
+
590
850
  /** Registers POST /admin/feedback/reply on the loopback admin transport —
591
851
  * mirrors crossProjectFeedback.registerAdminRoute; auth is the transport's. */
592
852
  function registerAdminRoute(adminHttp, deps) {
@@ -615,5 +875,8 @@ module.exports = {
615
875
  composeReplyPrompt,
616
876
  validateReplyInput,
617
877
  sendFeedbackReply,
878
+ deliverAuthorizedReply,
879
+ deliverDueReplies,
880
+ replyPassLogMeta,
618
881
  registerAdminRoute,
619
882
  };
@@ -5,7 +5,7 @@
5
5
  * through customerFeedbackInbox.cjs:
6
6
  * GET /admin/customer-feedback/inbox?pull=1&includeHidden=1 -> { ok, items, pulled? }
7
7
  * POST /admin/customer-feedback/status {id, status, note?} -> { ok, item }
8
- * POST /admin/customer-feedback/submit {title, body, tag, imagePaths?} -> { ok, item, warning? } | { ok:false, error }
8
+ * POST /admin/customer-feedback/submit {title, body, tag, imagePaths?, context?} -> { ok, item, warning? } | { ok:false, error }
9
9
  *
10
10
  * submit is the customer path (no owner token needed): it runs the exact
11
11
  * submit the Feedback panel's customerFeedback:submit IPC uses
@@ -13,7 +13,8 @@
13
13
  * item + receipt land in the same local mirror. os.homedir() is replaced with
14
14
  * `~` in title and body first; the body text is never echoed or logged.
15
15
  * imagePaths (absolute only) are prepared by submitFeedback; image bytes are
16
- * never logged or echoed.
16
+ * never logged or echoed. context (the widget's page/marks/console/network) is validated by
17
+ * feedbackReport.parseContext (Report v1 rules, <= 262144 bytes) and forwarded unchanged.
17
18
  *
18
19
  * Deliberately NO route that mints an Epic (SINGLE-CREATOR LAW, epicMint.cjs).
19
20
  * Responses never carry the owner token — the inbox lib redacts it from errors.
@@ -22,6 +23,7 @@
22
23
 
23
24
  const path = require('path');
24
25
  const { readBody, sendJson } = require('./localAdminHttp.cjs');
26
+ const feedbackReport = require('./feedbackReport.cjs');
25
27
 
26
28
  /** @param {any} dep */
27
29
  function getInbox(dep) {
@@ -131,9 +133,20 @@ function submitHandler(submitDep) {
131
133
  sendJson(res, 400, { ok: false, error: 'imagePaths must be absolute paths' });
132
134
  return;
133
135
  }
136
+ /** @type {import('./feedbackReport.cjs').FeedbackContext | undefined} */
137
+ let context;
138
+ if (body.context !== undefined && body.context !== null) {
139
+ const c = feedbackReport.parseContext(body.context);
140
+ if (!c.ok) {
141
+ sendJson(res, 400, { ok: false, error: `invalid submission: ${c.error}` });
142
+ return;
143
+ }
144
+ context = c.context;
145
+ }
134
146
  const result = await submit({
135
147
  title: redactHome(title), body: redactHome(text), tag,
136
148
  ...(imagePaths && imagePaths.length ? { imagePaths } : {}),
149
+ ...(context ? { context } : {}),
137
150
  });
138
151
  if (!result || !result.ok) {
139
152
  sendJson(res, 502, { ok: false, error: result && typeof result.error === 'string' ? result.error : 'submit failed' });
@@ -148,7 +161,7 @@ function submitHandler(submitDep) {
148
161
 
149
162
  /**
150
163
  * @param {any} adminHttp
151
- * @param {{ inbox?: any, submit?: (p: { title: string, body: string, tag: string, imagePaths?: string[] }) => Promise<any> }} [opts] test seams
164
+ * @param {{ inbox?: any, submit?: (p: { title: string, body: string, tag: string, imagePaths?: string[], context?: import('./feedbackReport.cjs').FeedbackContext }) => Promise<any> }} [opts] test seams
152
165
  */
153
166
  function registerAdminRoute(adminHttp, opts = {}) {
154
167
  adminHttp.registerRoute('GET', '/admin/customer-feedback/inbox', inboxHandler(opts.inbox));