claude-code-session-manager 0.138.0 → 0.140.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 (194) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +352 -79
  3. package/dist/assets/AppSettings-CMFEM68R.js +2 -0
  4. package/dist/assets/History--JwsFnbn.js +2 -0
  5. package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
  6. package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
  7. package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
  8. package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
  9. package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
  10. package/dist/assets/Skills-DtRzghn5.js +67 -0
  11. package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
  12. package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
  13. package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
  14. package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
  15. package/dist/assets/index-CtxruO1L.js +3121 -0
  16. package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +467 -451
  20. package/package.json +17 -6
  21. package/plugins/AGENTS.md +60 -0
  22. package/plugins/CLAUDE.md +1 -60
  23. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  24. package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
  25. package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
  26. package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
  27. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
  28. package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
  29. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
  30. package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
  31. package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
  32. package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
  33. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
  34. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
  35. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
  36. package/scripts/README.md +2 -0
  37. package/scripts/hooks/guard-tool-risk.cjs +91 -0
  38. package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
  39. package/scripts/ops-sweep.cjs +53 -23
  40. package/scripts/scheduler-mcp-server.cjs +360 -35
  41. package/src/main/build-info.json +4 -4
  42. package/src/main/chatRunner.cjs +2 -2
  43. package/src/main/config.cjs +112 -8
  44. package/src/main/docEdit.cjs +6 -1
  45. package/src/main/exchanges.cjs +70 -5
  46. package/src/main/files.cjs +7 -27
  47. package/src/main/health.cjs +48 -15
  48. package/src/main/historyAggregator.cjs +172 -63
  49. package/src/main/historyDashboard.cjs +87 -17
  50. package/src/main/index.cjs +78 -4
  51. package/src/main/ipcSchemas.cjs +233 -20
  52. package/src/main/lib/AGENTS.md +54 -0
  53. package/src/main/lib/CLAUDE.md +1 -54
  54. package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
  55. package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
  56. package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
  57. package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
  58. package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
  59. package/src/main/lib/claude/effectiveModelInfo.cjs +92 -22
  60. package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
  61. package/src/main/lib/claude/modelPricing.cjs +148 -0
  62. package/src/main/lib/claude/personaToolScope.cjs +12 -6
  63. package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
  64. package/src/main/lib/claude/runClaudeP.cjs +6 -1
  65. package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
  66. package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
  67. package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
  68. package/src/main/lib/ephemeralCwd.cjs +37 -2
  69. package/src/main/lib/epic/delegationReadiness.cjs +42 -9
  70. package/src/main/lib/epic/epicAdminRoutes.cjs +121 -0
  71. package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
  72. package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
  73. package/src/main/lib/epic/epicOutsideState.cjs +233 -0
  74. package/src/main/lib/epic/epicSettle.cjs +1 -1
  75. package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
  76. package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
  77. package/src/main/lib/epic/epicValidationHook.cjs +24 -4
  78. package/src/main/lib/epic/externalRef.cjs +37 -0
  79. package/src/main/lib/epic/externalRefIndex.cjs +136 -0
  80. package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
  81. package/src/main/lib/epic/restorableSessions.cjs +151 -17
  82. package/src/main/lib/epic/transcriptUsage.cjs +197 -0
  83. package/src/main/lib/externalContract.cjs +137 -0
  84. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
  85. package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
  86. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
  87. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
  88. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
  89. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
  90. package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
  91. package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
  92. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
  93. package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
  94. package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
  95. package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
  96. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
  97. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
  98. package/src/main/lib/git/branchSweep.cjs +209 -4
  99. package/src/main/lib/git/gitWorktree.cjs +41 -5
  100. package/src/main/lib/guardShims.cjs +1 -1
  101. package/src/main/lib/historyRollup.cjs +58 -5
  102. package/src/main/lib/insideHome.cjs +27 -1
  103. package/src/main/lib/mcpToolCatalog.cjs +232 -25
  104. package/src/main/lib/mdDocCensus.cjs +59 -78
  105. package/src/main/lib/mdDocRefs.cjs +71 -93
  106. package/src/main/lib/mdNetworkScan.cjs +245 -250
  107. package/src/main/lib/mdReviewRecord.cjs +22 -9
  108. package/src/main/lib/memoryMdNetwork.cjs +5 -12
  109. package/src/main/lib/opsOwnership.cjs +18 -2
  110. package/src/main/lib/opsRetentionSettings.cjs +28 -4
  111. package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
  112. package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
  113. package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
  114. package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
  115. package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
  116. package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
  117. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
  118. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  119. package/src/main/lib/prd/depSlugResolve.cjs +104 -4
  120. package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
  121. package/src/main/lib/prd/prdCreate.cjs +351 -23
  122. package/src/main/lib/prd/prdDisposition.cjs +11 -2
  123. package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
  124. package/src/main/lib/process/loginItem.cjs +171 -0
  125. package/src/main/lib/process/loginItemPlan.cjs +193 -0
  126. package/src/main/lib/project-pages/playerBridge.cjs +4 -0
  127. package/src/main/lib/project-pages/videoReview.cjs +268 -0
  128. package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
  129. package/src/main/lib/promptSessionSchema.cjs +4 -0
  130. package/src/main/lib/remoteTranscriptTail.cjs +32 -1
  131. package/src/main/lib/scheduler/cpuSample.cjs +131 -4
  132. package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
  133. package/src/main/lib/scheduler/loadGate.cjs +24 -6
  134. package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
  135. package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
  136. package/src/main/lib/scheduler/queueStore.cjs +7 -0
  137. package/src/main/lib/scheduler/rcaReport.cjs +21 -1
  138. package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
  139. package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
  140. package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
  141. package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
  142. package/src/main/lib/scheduler/schedulerPaths.cjs +12 -0
  143. package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
  144. package/src/main/lib/scheduler/validationQuality.cjs +282 -0
  145. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
  146. package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
  147. package/src/main/lib/tasks/taskIpc.cjs +80 -0
  148. package/src/main/lib/tasks/taskLedger.cjs +502 -0
  149. package/src/main/lib/tasks/taskRun.cjs +313 -0
  150. package/src/main/lib/tasks/taskSwitch.cjs +120 -0
  151. package/src/main/lib/telemetry/auditEvents.cjs +176 -0
  152. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
  153. package/src/main/loginItemIpc.cjs +35 -0
  154. package/src/main/loopEfficiencyHandlers.cjs +11 -2
  155. package/src/main/projectPages.cjs +6 -15
  156. package/src/main/promptSessionEvents.cjs +9 -1
  157. package/src/main/queueOps.cjs +260 -3
  158. package/src/main/runVerify.cjs +53 -25
  159. package/src/main/scheduler/AGENTS.md +26 -0
  160. package/src/main/scheduler/CLAUDE.md +1 -26
  161. package/src/main/scheduler/budget.cjs +239 -9
  162. package/src/main/scheduler/cancelDependents.cjs +154 -0
  163. package/src/main/scheduler/prdParser.cjs +4 -1
  164. package/src/main/scheduler/starvation.cjs +20 -18
  165. package/src/main/scheduler.cjs +774 -64
  166. package/src/main/supervisor.cjs +5 -1
  167. package/src/main/templates/PRD_AUTHORING.md +7 -1
  168. package/src/main/transcripts.cjs +62 -7
  169. package/src/main/validationQualityHandlers.cjs +199 -0
  170. package/src/main/webRemote.cjs +132 -20
  171. package/src/preload/api.d.ts +434 -28
  172. package/src/preload/apiSurface.cjs +7 -0
  173. package/src/preload/apiSurface.json +485 -81
  174. package/src/preload/index.cjs +38 -5
  175. package/src/seed/agents/validator.md +19 -8
  176. package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
  177. package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
  178. package/dist/assets/Button-Bk23rEnZ.js +0 -1
  179. package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
  180. package/dist/assets/Extensions-CXem-uwI.js +0 -2
  181. package/dist/assets/History-BwO3coo4.js +0 -2
  182. package/dist/assets/Library-BDV69fSe.js +0 -32
  183. package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
  184. package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
  185. package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
  186. package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
  187. package/dist/assets/Settings-COT34hBF.js +0 -2
  188. package/dist/assets/Skills-BgexoUkQ.js +0 -29
  189. package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
  190. package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
  191. package/dist/assets/Toggle-CENi19iK.js +0 -1
  192. package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
  193. package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
  194. package/dist/assets/index-CgCxpunJ.js +0 -3116
@@ -7,7 +7,18 @@
7
7
  *
8
8
  * deps: { schemas, validatePath, readActiveIndex, createPrd, loadJobs,
9
9
  * archivePrd, appendResponseEventWithReason?, dispatchMacroJob?,
10
- * macroJobStatuses?, readHistoryTail?, builtins? }
10
+ * macroJobStatuses?, readHistoryTail?, builtins?, listMacros?
11
+ * (default macroLibrary.listMacros), videoReview? (default
12
+ * project-pages/videoReview.cjs), listReviews?,
13
+ * checkProjectVideoToolRunnable? (default projectVideoToolCheck.cjs) }
14
+ *
15
+ * runToolJob is the one dispatch path: macros:dispatch-job calls it without a
16
+ * review decision; the review-decision IPC calls it with one. After an ok
17
+ * dispatch of a project Video tool it records the entry's review dispatch
18
+ * (dispatch.json), so every tool entry links to its tool, run and inputs.
19
+ * Before dispatching a library 'project-video' tool with a job it runs
20
+ * checkProjectVideoToolRunnable; a refusal returns { ok: false, error } with
21
+ * no PRD written and the job-not-queued notice. Built-ins are never checked.
11
22
  *
12
23
  * When a dispatch returns ok:false for an Epic that exists in the cwd's
13
24
  * active-index.json (and no build is already running for it — `activeSlug`),
@@ -22,6 +33,7 @@
22
33
  const { dispatchMacroJob: realDispatch } = require('./macroJobDispatch.cjs');
23
34
  const { macroJobStatuses: realStatuses } = require('./macroJobStatus.cjs');
24
35
  const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
36
+ const macroLibrary = require('./macroLibrary.cjs');
25
37
 
26
38
  const JOB_NOT_QUEUED_NOTICE = 'job-not-queued';
27
39
 
@@ -29,68 +41,154 @@ function noticeText(label, error) {
29
41
  return `${label} background build was not queued: ${error} — press it again in Project Home ▸ Tools to retry.`;
30
42
  }
31
43
 
32
- function registerMacroJobIpc(ipcMain, deps = {}) {
44
+ function defaultCheckRunnable() {
45
+ return require('./projectVideoToolCheck.cjs').checkProjectVideoToolRunnable;
46
+ }
47
+
48
+ function defaultVideoReview() {
49
+ return require('../project-pages/videoReview.cjs');
50
+ }
51
+
52
+ const findById = (list, id) => (Array.isArray(list) ? list : []).find((m) => m && m.id === id);
53
+
54
+ /** Built-in label first, then the library tool's label, then the id itself. */
55
+ async function appendNotice(deps, macros, cwd, macroId, epicId, error) {
56
+ if (typeof deps.appendResponseEventWithReason !== 'function') return;
57
+ try {
58
+ const macro = findById(deps.builtins || BUILTIN_MACROS, macroId) || findById(macros, macroId);
59
+ const label = (macro && macro.label) || macroId;
60
+ const res = await deps.appendResponseEventWithReason(
61
+ cwd, epicId, noticeText(label, error),
62
+ { notice: JOB_NOT_QUEUED_NOTICE, allowInactive: true },
63
+ );
64
+ if (res && res.ok === false) console.warn('[macroJobIpc] job-not-queued notice not appended', epicId, res.reason);
65
+ } catch (e) {
66
+ console.warn('[macroJobIpc] job-not-queued notice append failed', epicId, e?.message ?? e);
67
+ }
68
+ }
69
+
70
+ async function listLibraryMacros(deps) {
71
+ const list = typeof deps.listMacros === 'function' ? deps.listMacros : macroLibrary.listMacros;
72
+ const macros = await list();
73
+ return Array.isArray(macros) ? macros : [];
74
+ }
75
+
76
+ /**
77
+ * runToolJob(deps, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review })
78
+ * `cwd` must already be validated. Returns dispatchMacroJob's result.
79
+ */
80
+ async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review } = {}) {
33
81
  const dispatch = deps.dispatchMacroJob || realDispatch;
34
- const statuses = deps.macroJobStatuses || realStatuses;
35
- const builtins = deps.builtins || BUILTIN_MACROS;
82
+ const index = deps.readActiveIndex(cwd);
83
+ const sessions = index && index.sessions ? index.sessions : {};
84
+ const entry = Object.prototype.hasOwnProperty.call(sessions, epicId) ? sessions[epicId] : null;
85
+ const notActive = `epic ${epicId} is not an active session in this project`;
86
+ if (!entry) return { ok: false, error: notActive };
36
87
 
37
- async function appendNotice(cwd, macroId, epicId, error) {
38
- if (typeof deps.appendResponseEventWithReason !== 'function') return;
39
- try {
40
- const macro = (builtins || []).find((m) => m && m.id === macroId);
41
- const label = (macro && macro.label) || macroId;
42
- const res = await deps.appendResponseEventWithReason(
43
- cwd, epicId, noticeText(label, error),
44
- { notice: JOB_NOT_QUEUED_NOTICE, allowInactive: true },
45
- );
46
- if (res && res.ok === false) console.warn('[macroJobIpc] job-not-queued notice not appended', epicId, res.reason);
47
- } catch (e) {
48
- console.warn('[macroJobIpc] job-not-queued notice append failed', epicId, e?.message ?? e);
88
+ let macros = [];
89
+ let result;
90
+ try {
91
+ macros = await listLibraryMacros(deps);
92
+ if (entry.status !== 'active') {
93
+ await appendNotice(deps, macros, cwd, macroId, epicId, notActive);
94
+ return { ok: false, error: notActive };
49
95
  }
96
+ const refusal = await projectVideoRefusal(deps, macros, cwd, macroId);
97
+ if (refusal) {
98
+ await appendNotice(deps, macros, cwd, macroId, epicId, refusal);
99
+ return { ok: false, error: refusal };
100
+ }
101
+ const args = { cwd, macroId, epicId, extraInstructions, effort };
102
+ if (inputValues !== undefined) args.inputValues = inputValues;
103
+ if (review !== undefined) args.review = review;
104
+ const dispatchDeps = {
105
+ createPrd: deps.createPrd,
106
+ listRows: async () => deps.loadJobs(),
107
+ archivePrd: (slug, rowCwd) => deps.archivePrd(slug, rowCwd),
108
+ macros,
109
+ };
110
+ if (deps.builtins) dispatchDeps.builtins = deps.builtins;
111
+ result = await dispatch(args, dispatchDeps);
112
+ } catch (e) {
113
+ await appendNotice(deps, macros, cwd, macroId, epicId, e?.message ?? String(e));
114
+ throw e;
115
+ }
116
+ if (result && result.ok === false && !result.activeSlug) {
117
+ await appendNotice(deps, macros, cwd, macroId, epicId, result.error || 'unknown error');
50
118
  }
119
+ if (result && result.ok === true && result.entryId) {
120
+ const isBuiltin = !!findById(deps.builtins || BUILTIN_MACROS, macroId);
121
+ const tool = isBuiltin ? null : findById(macros, macroId);
122
+ if (tool && !tool.builtin && macroLibrary.isProjectVideoTool(tool, cwd)) {
123
+ await recordToolDispatch(deps, cwd, result, { macroId, epicId, inputValues, extraInstructions });
124
+ }
125
+ }
126
+ return result;
127
+ }
128
+
129
+ /**
130
+ * The runnable-check error for a library 'project-video' tool with a job, or
131
+ * null (built-ins, other macros and runnable tools).
132
+ */
133
+ async function projectVideoRefusal(deps, macros, cwd, macroId) {
134
+ if (findById(deps.builtins || BUILTIN_MACROS, macroId)) return null;
135
+ const tool = findById(macros, macroId);
136
+ if (!tool || tool.builtin || tool.surface !== 'project-video' || !tool.job || typeof tool.job !== 'object') return null;
137
+ const check = deps.checkProjectVideoToolRunnable || defaultCheckRunnable();
138
+ const verdict = await check({ cwd, agentName: tool.agentName, job: tool.job });
139
+ return verdict && verdict.ok === false ? verdict.error : null;
140
+ }
141
+
142
+ /** Best effort: a failed record is logged and never changes the dispatch result. */
143
+ async function recordToolDispatch(deps, cwd, result, { macroId, epicId, inputValues, extraInstructions }) {
144
+ try {
145
+ const videoReview = deps.videoReview || defaultVideoReview();
146
+ const rec = await videoReview.recordDispatch(cwd, result.entryId, {
147
+ macroId,
148
+ epicId,
149
+ slug: result.slug,
150
+ stage: result.stage || 'final',
151
+ inputValues: inputValues && typeof inputValues === 'object' ? inputValues : {},
152
+ extraInstructions: typeof extraInstructions === 'string' ? extraInstructions : '',
153
+ });
154
+ if (rec && rec.ok === false) console.warn('[macroJobIpc] review dispatch not recorded', result.entryId, rec.error);
155
+ } catch (e) {
156
+ console.warn('[macroJobIpc] review dispatch record failed', result.entryId, e?.message ?? e);
157
+ }
158
+ }
159
+
160
+ function registerMacroJobIpc(ipcMain, deps = {}) {
161
+ const statuses = deps.macroJobStatuses || realStatuses;
51
162
 
52
163
  ipcMain.handle('macros:dispatch-job', async (_event, rawPayload) => {
53
164
  const payload = deps.schemas.macrosDispatchJob.parse(rawPayload);
54
165
  const cwd = deps.validatePath(payload.cwd);
55
- const index = deps.readActiveIndex(cwd);
56
- const sessions = index && index.sessions ? index.sessions : {};
57
- const entry = Object.prototype.hasOwnProperty.call(sessions, payload.epicId) ? sessions[payload.epicId] : null;
58
- if (!entry) {
59
- return { ok: false, error: `epic ${payload.epicId} is not an active session in this project` };
60
- }
61
- if (entry.status !== 'active') {
62
- const refused = { ok: false, error: `epic ${payload.epicId} is not an active session in this project` };
63
- await appendNotice(cwd, payload.macroId, payload.epicId, refused.error);
64
- return refused;
65
- }
66
- let result;
67
- try {
68
- result = await dispatch(
69
- { cwd, macroId: payload.macroId, epicId: payload.epicId, extraInstructions: payload.extraInstructions, effort: payload.effort },
70
- {
71
- createPrd: deps.createPrd,
72
- listRows: async () => deps.loadJobs(),
73
- archivePrd: (slug, rowCwd) => deps.archivePrd(slug, rowCwd),
74
- },
75
- );
76
- } catch (e) {
77
- await appendNotice(cwd, payload.macroId, payload.epicId, e?.message ?? String(e));
78
- throw e;
79
- }
80
- if (result && result.ok === false && !result.activeSlug) {
81
- await appendNotice(cwd, payload.macroId, payload.epicId, result.error || 'unknown error');
82
- }
83
- return result;
166
+ return runToolJob(deps, {
167
+ cwd,
168
+ macroId: payload.macroId,
169
+ epicId: payload.epicId,
170
+ extraInstructions: payload.extraInstructions,
171
+ inputValues: payload.inputValues,
172
+ effort: payload.effort,
173
+ });
84
174
  });
85
175
 
86
176
  ipcMain.handle('macros:job-status', async (_event, rawPayload) => {
87
177
  const payload = deps.schemas.macrosJobStatus.parse(rawPayload);
88
178
  const cwd = deps.validatePath(payload.cwd);
179
+ let macros = [];
180
+ try {
181
+ macros = await listLibraryMacros(deps);
182
+ } catch (e) {
183
+ console.warn('[macroJobIpc] macro library unreadable for job-status', e?.message ?? e);
184
+ }
89
185
  return statuses({ cwd }, {
90
186
  loadJobs: deps.loadJobs,
187
+ macros,
91
188
  ...(deps.readHistoryTail ? { readHistoryTail: deps.readHistoryTail } : {}),
189
+ ...(deps.listReviews ? { listReviews: deps.listReviews } : {}),
92
190
  });
93
191
  });
94
192
  }
95
193
 
96
- module.exports = { registerMacroJobIpc, JOB_NOT_QUEUED_NOTICE };
194
+ module.exports = { registerMacroJobIpc, runToolJob, JOB_NOT_QUEUED_NOTICE };
@@ -1,19 +1,32 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * macroJobStatus.cjs — per built-in macro with a `job` declaration, the state of
5
- * its newest background job for one project: newest live queue row, else newest
4
+ * macroJobStatus.cjs — per built-in macro with a `job` declaration, and per
5
+ * project Video tool (isProjectVideoTool) of this project, the state of its
6
+ * newest background job for one project: newest live queue row, else newest
6
7
  * entry in a bounded tail of the project's scheduler history. Read-only.
8
+ * A tool's status also carries entryId (from the video entry's review
9
+ * dispatch.json, matched by slug); a completed review-stage run whose entry is
10
+ * waiting on the human reports status 'awaiting_review'.
7
11
  *
8
12
  * Plain Node, no Electron imports; all I/O is injected.
9
13
  */
10
14
 
11
15
  const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
12
16
  const { readTail } = require('../util/fileTail.cjs');
17
+ const { isProjectVideoTool } = require('./macroLibrary.cjs');
13
18
 
14
19
  const HISTORY_TAIL_BYTES = 524288;
15
20
  const RUNNING = new Set(['running', 'investigating']);
16
21
  const FAILED = new Set(['failed', 'needs_review', 'skipped', 'cancelled']);
22
+ const REASON_MAX = 200;
23
+ const AWAITING_REVIEW = 'awaiting_review';
24
+
25
+ /** First non-empty line, at most REASON_MAX chars. */
26
+ function oneLineReason(v) {
27
+ const line = String(v).split(/\r?\n/).map((l) => l.trim()).find(Boolean) || '';
28
+ return line.length > REASON_MAX ? line.slice(0, REASON_MAX) : line;
29
+ }
17
30
 
18
31
  function stateOf(status) {
19
32
  if (RUNNING.has(status)) return 'running';
@@ -28,7 +41,7 @@ function reasonOf(row, status) {
28
41
  return Number.isFinite(n) && n > 0 ? `Timed out at the ${n}-minute job budget` : 'Timed out at the job budget';
29
42
  }
30
43
  for (const v of [row.error, row.finalizeReason, row.terminalReason]) {
31
- if (typeof v === 'string' && v.trim()) return v;
44
+ if (typeof v === 'string' && v.trim()) return oneLineReason(v);
32
45
  }
33
46
  return `Ended as ${status}`;
34
47
  }
@@ -77,14 +90,25 @@ function parseHistory(text) {
77
90
  return out;
78
91
  }
79
92
 
93
+ function defaultListReviews(cwd) {
94
+ return require('../project-pages/videoReview.cjs').listReviews(cwd);
95
+ }
96
+
80
97
  function defaultReadHistoryTail(cwd) {
81
98
  const { projectHistoryPath } = require('../scheduler/queueStore.cjs');
82
99
  return readTail(projectHistoryPath(cwd), HISTORY_TAIL_BYTES);
83
100
  }
84
101
 
85
- async function macroJobStatuses({ cwd } = {}, { loadJobs, readHistoryTail = defaultReadHistoryTail, builtins = BUILTIN_MACROS } = {}) {
86
- const macros = (builtins || []).filter((m) => m && m.job && m.id);
87
- if (!macros.length) return [];
102
+ async function macroJobStatuses(
103
+ { cwd } = {},
104
+ { loadJobs, readHistoryTail = defaultReadHistoryTail, builtins = BUILTIN_MACROS, macros = [], listReviews = defaultListReviews } = {},
105
+ ) {
106
+ const jobBuiltins = (builtins || []).filter((m) => m && m.job && m.id);
107
+ const builtinIds = new Set(jobBuiltins.map((m) => m.id));
108
+ const tools = (Array.isArray(macros) ? macros : [])
109
+ .filter((m) => m && m.id && !m.builtin && !builtinIds.has(m.id) && isProjectVideoTool(m, cwd));
110
+ const all = [...jobBuiltins.map((m) => ({ m, tool: false })), ...tools.map((m) => ({ m, tool: true }))];
111
+ if (!all.length) return [];
88
112
  let live = [];
89
113
  try {
90
114
  const rows = typeof loadJobs === 'function' ? await loadJobs() : [];
@@ -100,13 +124,67 @@ async function macroJobStatuses({ cwd } = {}, { loadJobs, readHistoryTail = defa
100
124
  return history;
101
125
  };
102
126
 
127
+ let reviews = null; // lazily read once, only if some tool has a row
128
+ const loadReviews = async () => {
129
+ if (reviews) return reviews;
130
+ try {
131
+ const list = typeof listReviews === 'function' ? await listReviews(cwd) : [];
132
+ reviews = Array.isArray(list) ? list.filter((r) => r && r.dispatch && typeof r.dispatch.slug === 'string' && r.dispatch.slug) : [];
133
+ } catch { reviews = []; }
134
+ return reviews;
135
+ };
136
+
103
137
  const out = [];
104
- for (const m of macros) {
138
+ for (const { m, tool } of all) {
105
139
  let row = newest(live.filter((r) => r.macroId === m.id));
106
140
  if (!row) row = newest((await loadHistory()).filter((r) => r.macroId === m.id));
107
- if (row) out.push(toStatus(m.id, row));
141
+ if (!row) continue;
142
+ const st = toStatus(m.id, row);
143
+ if (tool) {
144
+ const review = row.slug ? (await loadReviews()).find((r) => r.dispatch.slug === row.slug) : null;
145
+ st.entryId = review ? review.entryId : null;
146
+ if (review && row.status === 'completed' && review.dispatch.stage === 'review' && review.status === 'waiting') {
147
+ st.status = AWAITING_REVIEW;
148
+ }
149
+ }
150
+ out.push(st);
151
+ }
152
+ return out;
153
+ }
154
+
155
+ /**
156
+ * Per run slug, the job state of that run: the newest live queue row for cwd,
157
+ * else the newest row in the project's history tail (read at most once).
158
+ * Value is null when no row with that slug exists for cwd. Never throws.
159
+ */
160
+ async function jobStatusesBySlug({ cwd, slugs } = {}, { loadJobs, readHistoryTail = defaultReadHistoryTail } = {}) {
161
+ const wanted = [...new Set((Array.isArray(slugs) ? slugs : []).filter((s) => typeof s === 'string' && s))];
162
+ if (!wanted.length) return {};
163
+ const set = new Set(wanted);
164
+ let live = [];
165
+ try {
166
+ const rows = typeof loadJobs === 'function' ? await loadJobs() : [];
167
+ live = Array.isArray(rows) ? rows.filter((r) => r && r.cwd === cwd && set.has(r.slug)) : [];
168
+ } catch { live = []; }
169
+
170
+ let history = null; // lazily read once, only if some slug has no live row
171
+ const loadHistory = async () => {
172
+ if (history) return history;
173
+ try {
174
+ history = parseHistory(await readHistoryTail(cwd)).filter((r) => set.has(r.slug) && (!r.cwd || r.cwd === cwd));
175
+ } catch { history = []; }
176
+ return history;
177
+ };
178
+
179
+ const out = {};
180
+ for (const slug of wanted) {
181
+ let row = newest(live.filter((r) => r.slug === slug));
182
+ if (!row) row = newest((await loadHistory()).filter((r) => r.slug === slug));
183
+ if (!row) { out[slug] = null; continue; }
184
+ const { state, status, reason, startedAt, finishedAt } = toStatus(row.macroId ?? null, row);
185
+ out[slug] = { slug, state, status, reason, startedAt, finishedAt };
108
186
  }
109
187
  return out;
110
188
  }
111
189
 
112
- module.exports = { macroJobStatuses, HISTORY_TAIL_BYTES };
190
+ module.exports = { macroJobStatuses, jobStatusesBySlug, HISTORY_TAIL_BYTES, REASON_MAX, AWAITING_REVIEW };
@@ -35,6 +35,13 @@
35
35
  * artifacts are per project); this module enforces that on load (a narrowed
36
36
  * stored entry is widened to ['*']) and on save (projects forced to ['*']).
37
37
  *
38
+ * A surface 'project-video' macro is one project's own Video tool (Project
39
+ * Home ▸ Video): its `projects` is exactly one absolute cwd — never '*', never
40
+ * widened, never given a second project — and it may carry a `job`
41
+ * declaration `{ estimateMinutes, repoPaths?, review? }` stored as is. saveMacro
42
+ * refuses `job` on every other surface and on built-ins; a read drops such a
43
+ * stale key (a built-in's job is read live from BUILTIN_MACROS by withBuiltinJobs).
44
+ *
38
45
  * Plain Node, no Electron imports.
39
46
  */
40
47
 
@@ -62,7 +69,32 @@ const AbsolutePathSchema = z.string().max(1024).refine(
62
69
  );
63
70
  const MacroProjectEntrySchema = z.union([z.literal(ALL_PROJECTS), AbsolutePathSchema]);
64
71
  const MacroProjectsSchema = z.array(MacroProjectEntrySchema).max(200);
65
- const MacroSurfaceSchema = z.enum(['sessions', 'project-home']);
72
+ const MacroSurfaceSchema = z.enum(['sessions', 'project-home', 'project-video']);
73
+
74
+ const PROJECT_VIDEO_ONE_PROJECT = 'a Project Video tool belongs to exactly one project';
75
+ const JOB_SURFACE_ONLY = 'job is allowed only on a Project Video tool';
76
+ const JOB_NOT_ON_BUILTIN = 'a built-in macro job cannot be set';
77
+
78
+ /** Repo-relative path a Project Video job may write: '/'-separated, inside the repo, outside ops/git state. */
79
+ const JobRepoPathSchema = z.string().min(1).max(200).superRefine((v, ctx) => {
80
+ const bad = (message) => ctx.addIssue({ code: 'custom', message });
81
+ if (v.includes('\\')) bad('repoPath must use "/", not a backslash');
82
+ if (v.includes('\0')) bad('repoPath must not contain a NUL byte');
83
+ if (v.startsWith('/')) bad('repoPath must be relative (no leading "/")');
84
+ if (v.split('/').some((seg) => seg === '..' || seg === '.')) bad('repoPath must not contain a "." or ".." segment');
85
+ if (v.startsWith('session-manager-operations/')) bad('repoPath must not be under session-manager-operations/');
86
+ if (v.startsWith('.git')) bad('repoPath must not start with .git');
87
+ });
88
+ const MacroJobSchema = z.object({
89
+ estimateMinutes: z.number().int().min(5).max(60),
90
+ repoPaths: z.array(JobRepoPathSchema).min(1).max(20).optional(),
91
+ review: z.boolean().optional(),
92
+ }).strict();
93
+
94
+ /** True iff `projects` is exactly one absolute cwd (not '*'). */
95
+ function isSingleProject(projects) {
96
+ return Array.isArray(projects) && projects.length === 1 && projects[0] !== ALL_PROJECTS;
97
+ }
66
98
 
67
99
  const MACRO_INPUT_MAX_LEN = 500;
68
100
  const MACRO_PLACEHOLDER_RE = /\{\{\s*([a-z][a-z0-9_]{0,31})\s*\}\}/g;
@@ -152,7 +184,19 @@ function renderMacroPrompt(prompt, inputs, values) {
152
184
  return { ok: true, prompt: rendered };
153
185
  }
154
186
 
155
- const MacroSchema = z.object({
187
+ /**
188
+ * A job outside a custom Project Video tool is stale (e.g. a stored or live
189
+ * built-in job of a different shape): drop the key, keep the macro. saveMacro
190
+ * refuses such a job outright; reads stay tolerant.
191
+ */
192
+ function stripForeignJob(entry) {
193
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry) || !('job' in entry)) return entry;
194
+ if (entry.surface === 'project-video' && !entry.builtin) return entry;
195
+ const { job: _stale, ...rest } = entry;
196
+ return rest;
197
+ }
198
+
199
+ const MacroObjectSchema = z.object({
156
200
  id: MacroIdSchema,
157
201
  label: MacroLabelSchema,
158
202
  agentName: MacroAgentNameSchema,
@@ -169,7 +213,15 @@ const MacroSchema = z.object({
169
213
  autoStartTargets: MacroProjectsSchema.optional(),
170
214
  // Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
171
215
  scriptStart: z.boolean().optional(),
172
- }).superRefine(refineInputs);
216
+ // Background job declaration; only on a non-built-in 'project-video' macro.
217
+ job: MacroJobSchema.optional(),
218
+ }).superRefine((value, ctx) => {
219
+ refineInputs(value, ctx);
220
+ if (value.surface === 'project-video' && !isSingleProject(value.projects)) {
221
+ ctx.addIssue({ code: 'custom', path: ['projects'], message: PROJECT_VIDEO_ONE_PROJECT });
222
+ }
223
+ });
224
+ const MacroSchema = z.preprocess(stripForeignJob, MacroObjectSchema);
173
225
 
174
226
  const MacroSaveSchema = z.object({
175
227
  id: MacroIdSchema.optional(),
@@ -188,6 +240,8 @@ const MacroSaveSchema = z.object({
188
240
  autoStartTargets: MacroProjectsSchema.optional(),
189
241
  // Human consent that a local script may start this macro (POST /admin/macros/run). Set only by the app's IPC save.
190
242
  scriptStart: z.boolean().optional(),
243
+ // Omitted keeps the stored job on update; `null` removes it. Only on a 'project-video' macro.
244
+ job: MacroJobSchema.nullable().optional(),
191
245
  }).superRefine(refineInputs);
192
246
 
193
247
  const MacroDeleteSchema = z.object({ id: MacroIdSchema });
@@ -536,15 +590,43 @@ async function loadStore(filePath, opts) {
536
590
  /**
537
591
  * Decorate built-in entries with their live `job` declaration from BUILTIN_MACROS.
538
592
  * Never persisted: `job` is read at list time so a stored copy cannot freeze it.
593
+ * A non-built-in macro's stored job (a Project Video tool's) is returned unchanged.
539
594
  */
540
595
  function withBuiltinJobs(macros) {
541
596
  return macros.map((m) => {
542
- const { job: _stale, ...rest } = m;
543
597
  const b = BUILTIN_MACROS.find((x) => x.id === m.id);
544
- return b && b.job ? { ...rest, job: b.job } : rest;
598
+ if (!b) return m;
599
+ const { job: _stale, ...rest } = m;
600
+ return b.job ? { ...rest, job: b.job } : rest;
545
601
  });
546
602
  }
547
603
 
604
+ /** Pure. True only for a 'project-video' macro whose projects is exactly [cwd] and that declares a job. */
605
+ function isProjectVideoTool(macro, cwd) {
606
+ if (!macro || macro.surface !== 'project-video') return false;
607
+ if (!macro.job || typeof macro.job !== 'object') return false;
608
+ const projects = macro.projects;
609
+ return isSingleProject(projects) && typeof cwd === 'string' && projects[0] === normalizeCwd(cwd);
610
+ }
611
+
612
+ /** Throws unless the merged save's surface/projects/job combination is allowed. */
613
+ function assertSurfaceRules(saved, parsedJob) {
614
+ if (saved.surface === 'project-video' && !isSingleProject(saved.projects)) {
615
+ throw new Error(PROJECT_VIDEO_ONE_PROJECT);
616
+ }
617
+ if (parsedJob !== undefined && parsedJob !== null) {
618
+ if (saved.builtin) throw new Error(JOB_NOT_ON_BUILTIN);
619
+ if (saved.surface !== 'project-video') throw new Error(JOB_SURFACE_ONLY);
620
+ }
621
+ }
622
+
623
+ /** Apply the save's `job` (omitted = keep, null = remove) and drop any job the surface cannot carry. */
624
+ function applyJob(saved, parsedJob) {
625
+ if (parsedJob === null) delete saved.job;
626
+ else if (parsedJob !== undefined) saved.job = parsedJob;
627
+ if (saved.surface !== 'project-video' || saved.builtin) delete saved.job;
628
+ }
629
+
548
630
  /** @returns {Promise<Macro[]>} */
549
631
  async function listMacros(opts = {}) {
550
632
  return withBuiltinJobs(await listMacrosRaw(opts));
@@ -623,6 +705,8 @@ async function saveMacro(input, opts = {}) {
623
705
  }
624
706
  if (parsed.scriptStart === true) saved.scriptStart = true;
625
707
  else if (parsed.scriptStart === false) delete saved.scriptStart;
708
+ assertSurfaceRules(saved, parsed.job);
709
+ applyJob(saved, parsed.job);
626
710
  assertPlaceholdersDeclared(saved);
627
711
  macros[idx] = saved;
628
712
  } else {
@@ -646,6 +730,8 @@ async function saveMacro(input, opts = {}) {
646
730
  saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
647
731
  }
648
732
  if (parsed.scriptStart === true) saved.scriptStart = true;
733
+ assertSurfaceRules(saved, parsed.job);
734
+ applyJob(saved, parsed.job);
649
735
  assertPlaceholdersDeclared(saved);
650
736
  macros.push(saved);
651
737
  }
@@ -690,6 +776,8 @@ async function setMacroProject(input, opts = {}) {
690
776
  if (macro.builtin && !enabled) return { ok: false, error: 'built-in macro visibility cannot be narrowed' };
691
777
  const has = macro.projects.includes(target);
692
778
  if (enabled === has) return { ok: true, macro };
779
+ // A Project Video tool never gains a second project nor loses its only one.
780
+ if (macro.surface === 'project-video') return { ok: false, error: PROJECT_VIDEO_ONE_PROJECT };
693
781
  const projects = enabled ? [...macro.projects, target] : macro.projects.filter((p) => p !== target);
694
782
  if (projects.length > 200) return { ok: false, error: 'too many projects' };
695
783
  const updated = { ...macro, projects, updatedAt: new Date().toISOString() };
@@ -747,6 +835,8 @@ module.exports = {
747
835
  renderMacroPrompt,
748
836
  macroVisibleIn,
749
837
  macroAllowsAutoStart,
838
+ isProjectVideoTool,
839
+ MacroJobSchema,
750
840
  listMacros,
751
841
  saveMacro,
752
842
  deleteMacro,