claude-code-session-manager 0.98.0 → 0.101.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 (441) hide show
  1. package/README.md +3 -3
  2. package/bin/cli.cjs +16 -4
  3. package/bin/node-floor.cjs +41 -0
  4. package/dist/assets/DataModel-CXaH2GED.js +1 -0
  5. package/dist/assets/{History-Bfdoywlh.js → History-Cerii-HA.js} +2 -2
  6. package/dist/assets/{Hooks-CKDJjTJV.js → Hooks-aXMb5LDy.js} +3 -3
  7. package/dist/assets/{Library-7akfgy67.js → Library-WrJFKEOJ.js} +1 -1
  8. package/dist/assets/{MarkdownEditor-DDesiqet.js → MarkdownEditor-D1BMCXS7.js} +1 -1
  9. package/dist/assets/{McpServers-D4lZtXof.js → McpServers-Cf0davLd.js} +2 -2
  10. package/dist/assets/{Memory-CeI8G1w5.js → Memory-Dn6NHWPe.js} +6 -6
  11. package/dist/assets/Permissions-CTVuFPjg.js +3 -0
  12. package/dist/assets/{Plugins-P4eCXy_S.js → Plugins-C2TyF8Mn.js} +2 -2
  13. package/dist/assets/ProvenanceBadge-F_jwHSwE.js +1 -0
  14. package/dist/assets/{SaveBar-l9jnEMES.js → SaveBar-DA1KVJST.js} +1 -1
  15. package/dist/assets/Scheduler-Bm6Q_hlu.js +16 -0
  16. package/dist/assets/{ScopeSwitcher-CjJi8ST5.js → ScopeSwitcher-BygZlJca.js} +1 -1
  17. package/dist/assets/Settings-BYCiv5KV.js +3 -0
  18. package/dist/assets/{SkillReferenceGraph-CjbO01Sg.js → SkillReferenceGraph-CcLnl9np.js} +1 -1
  19. package/dist/assets/{Skills-BxZ9_fCR.js → Skills-ChffsdTD.js} +2 -2
  20. package/dist/assets/{SystemPrompt-D8vfFb8b.js → SystemPrompt-dNkfHE_M.js} +1 -1
  21. package/dist/assets/{TagLibrary-2vzUo7YL.js → TagLibrary-jVlEuB0m.js} +1 -1
  22. package/dist/assets/{TiptapBody-B8ZfbK90.js → TiptapBody-6_cdwcP0.js} +1 -1
  23. package/dist/assets/{Toggle-BbW4nGGf.js → Toggle-CVXqGpAP.js} +1 -1
  24. package/dist/assets/ViewTabs-DO1YVbpc.js +1 -0
  25. package/dist/assets/{index-CKH5Uxik.css → index-D89EUizB.css} +1 -1
  26. package/dist/assets/{index-Cd98Q1lD.js → index-DbCQPWWY.js} +747 -752
  27. package/dist/assets/{settingsSchema-IhUfucCF.js → settingsSchema-Wrvn-Yz1.js} +1 -1
  28. package/dist/index.html +2 -2
  29. package/package.json +25 -29
  30. package/plugins/CLAUDE.md +6 -6
  31. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +21 -19
  32. package/plugins/session-manager-dev/skills/builder/SKILL.md +3 -3
  33. package/plugins/session-manager-dev/skills/develop/SKILL.md +254 -510
  34. package/plugins/session-manager-dev/skills/develop/standards.md +17 -22
  35. package/scripts/README.md +3 -11
  36. package/scripts/audit-ops-hygiene.cjs +3 -3
  37. package/scripts/hooks/lib/guard-prd-writes-policy.cjs +1 -1
  38. package/scripts/hooks/lib/guard-self-schedule-policy.cjs +1 -1
  39. package/scripts/mint-epic.cjs +2 -3
  40. package/scripts/scheduler-mcp-server.cjs +64 -7
  41. package/src/main/agentLibrary.cjs +22 -2
  42. package/src/main/build-info.json +4 -4
  43. package/src/main/chatRunner.cjs +4 -3
  44. package/src/main/config.cjs +41 -38
  45. package/src/main/docEdit.cjs +4 -1
  46. package/src/main/files.cjs +2 -5
  47. package/src/main/health.cjs +1 -1
  48. package/src/main/index.cjs +40 -11
  49. package/src/main/ipcSchemas.cjs +35 -34
  50. package/src/main/lib/agentPersonaSchema.cjs +13 -2
  51. package/src/main/lib/atomicFs.cjs +116 -0
  52. package/src/main/lib/branchSweep.cjs +13 -12
  53. package/src/main/lib/buildTarget.cjs +3 -3
  54. package/src/main/lib/builtinMacros.cjs +39 -0
  55. package/src/main/lib/claudeCliCaps.cjs +129 -0
  56. package/src/main/lib/credentials.cjs +2 -4
  57. package/src/main/lib/crossProjectFeedback.cjs +3 -3
  58. package/src/main/lib/cwdClassify.cjs +15 -3
  59. package/src/main/lib/definitionOfDone.cjs +207 -125
  60. package/src/main/lib/dodDrainHook.cjs +11 -5
  61. package/src/main/lib/epicMint.cjs +2 -4
  62. package/src/main/lib/epicStatusMirror.cjs +8 -10
  63. package/src/main/lib/epicWorktreeProjectConfig.cjs +2 -4
  64. package/src/main/lib/gateAuthority.cjs +96 -0
  65. package/src/main/lib/gitExec.cjs +69 -0
  66. package/src/main/lib/gitWorktree.cjs +656 -92
  67. package/src/main/lib/instanceLock.cjs +5 -8
  68. package/src/main/lib/launchFailure.cjs +2 -3
  69. package/src/main/lib/macroLibrary.cjs +480 -0
  70. package/src/main/lib/mcpToolCatalog.cjs +49 -17
  71. package/src/main/lib/needsReviewLedger.cjs +1 -1
  72. package/src/main/lib/opsErrorLog.cjs +11 -1
  73. package/src/main/lib/opsOwnership.cjs +5 -9
  74. package/src/main/lib/pidAlive.cjs +32 -0
  75. package/src/main/lib/prdCreate.cjs +121 -12
  76. package/src/main/lib/prdDisposition.cjs +2 -2
  77. package/src/main/lib/prdGateFiles.cjs +284 -0
  78. package/src/main/lib/prdLocations.cjs +61 -0
  79. package/src/main/lib/prdMigration.cjs +2 -3
  80. package/src/main/lib/prdSizing.cjs +2 -1
  81. package/src/main/lib/projectHomeAdminRoutes.cjs +136 -21
  82. package/src/main/lib/promptSessionSchema.cjs +10 -2
  83. package/src/main/lib/rcaReport.cjs +4 -6
  84. package/src/main/lib/reaperHelpers.cjs +8 -1
  85. package/src/main/lib/reservationExpiry.cjs +6 -1
  86. package/src/main/lib/reviewNotice.cjs +263 -0
  87. package/src/main/lib/runClaudeP.cjs +4 -1
  88. package/src/main/lib/schedulerPaths.cjs +22 -2
  89. package/src/main/lib/sessionSlots.cjs +2 -4
  90. package/src/main/lib/shippedPersonaSeeds.cjs +226 -0
  91. package/src/main/lib/smfileHeaders.cjs +66 -0
  92. package/src/main/lib/timeoutShim.cjs +123 -0
  93. package/src/main/lib/timeoutShimScript.cjs +275 -0
  94. package/src/main/lib/upgradeDrain.cjs +4 -10
  95. package/src/main/lib/watchdogHelpers.cjs +12 -25
  96. package/src/main/lib/workTypeLibrary.cjs +7 -1
  97. package/src/main/projectPages.cjs +43 -13
  98. package/src/main/promptSessionEvents.cjs +37 -13
  99. package/src/main/scheduler.cjs +910 -198
  100. package/src/main/seedAgentPersonas.cjs +279 -24
  101. package/src/main/supervisor.cjs +4 -1
  102. package/src/main/templates/PRD_AUTHORING.md +126 -406
  103. package/src/preload/__tests__/preload-surface.test.cjs +68 -0
  104. package/src/preload/api.d.ts +53 -94
  105. package/src/preload/index.cjs +14 -9
  106. package/src/seed/agents/architect.md +2 -0
  107. package/src/seed/agents/demo-video-builder.md +84 -0
  108. package/src/seed/agents/dev-lead.md +18 -18
  109. package/src/seed/agents/project-home-builder.md +66 -35
  110. package/src/seed/agents/validator.md +10 -4
  111. package/dist/assets/DataModel-DCEgMTjH.js +0 -1
  112. package/dist/assets/HostBilko-CDVHE0hT.js +0 -1
  113. package/dist/assets/Permissions-BGleLja4.js +0 -3
  114. package/dist/assets/ProvenanceBadge-BFczzI1B.js +0 -1
  115. package/dist/assets/Scheduler-C_phpeUS.js +0 -16
  116. package/dist/assets/Settings-BIwZ3FGQ.js +0 -3
  117. package/src/main/__tests__/activeIndexMerge.test.cjs +0 -235
  118. package/src/main/__tests__/agentEffortResolve.test.cjs +0 -117
  119. package/src/main/__tests__/agentLibrary.test.cjs +0 -276
  120. package/src/main/__tests__/agentModelResolve.test.cjs +0 -311
  121. package/src/main/__tests__/agentOverlayWrite.test.cjs +0 -95
  122. package/src/main/__tests__/bilkoHost-deriveSlug.test.cjs +0 -26
  123. package/src/main/__tests__/bilkoHost-integration.test.cjs +0 -118
  124. package/src/main/__tests__/bilkoHostCore.test.cjs +0 -72
  125. package/src/main/__tests__/broadcastCoalescer.test.cjs +0 -122
  126. package/src/main/__tests__/chat-cancel-terminal.test.cjs +0 -120
  127. package/src/main/__tests__/chat-dead-channels.test.cjs +0 -63
  128. package/src/main/__tests__/chat-exit-close-race.test.cjs +0 -146
  129. package/src/main/__tests__/chat-mcp-consent-notice.test.cjs +0 -139
  130. package/src/main/__tests__/chat-preamble-anchors.test.cjs +0 -100
  131. package/src/main/__tests__/chat-queue.test.cjs +0 -97
  132. package/src/main/__tests__/chat-stop-signal.test.cjs +0 -89
  133. package/src/main/__tests__/chatRunner-epic-worktree-execcwd.test.cjs +0 -125
  134. package/src/main/__tests__/chatRunner-session-flag-retry.test.cjs +0 -252
  135. package/src/main/__tests__/classifyPromptTicket.test.cjs +0 -101
  136. package/src/main/__tests__/classifyTranscriptLine.test.cjs +0 -201
  137. package/src/main/__tests__/computeDepHistorySatisfaction.test.cjs +0 -66
  138. package/src/main/__tests__/config-readText-bounded.test.cjs +0 -84
  139. package/src/main/__tests__/configWriteBoundaryOwners.test.cjs +0 -59
  140. package/src/main/__tests__/crossProjectFeedback.test.cjs +0 -334
  141. package/src/main/__tests__/crossProjectFeedbackRoutes.test.cjs +0 -161
  142. package/src/main/__tests__/dep-orphan-archive-health.test.cjs +0 -77
  143. package/src/main/__tests__/develop-skill-failure-modes.test.cjs +0 -70
  144. package/src/main/__tests__/docEdit.test.cjs +0 -244
  145. package/src/main/__tests__/dod-batchkey.test.cjs +0 -183
  146. package/src/main/__tests__/dod-drain-hook.test.cjs +0 -302
  147. package/src/main/__tests__/dod-report.test.cjs +0 -304
  148. package/src/main/__tests__/dod-reverify.test.cjs +0 -285
  149. package/src/main/__tests__/epicContextDigest.test.cjs +0 -174
  150. package/src/main/__tests__/epicMint.test.cjs +0 -332
  151. package/src/main/__tests__/epicMintTelemetryTap.test.cjs +0 -64
  152. package/src/main/__tests__/epicStatusMirror.test.cjs +0 -110
  153. package/src/main/__tests__/epicValidationHook.test.cjs +0 -291
  154. package/src/main/__tests__/exchanges.test.cjs +0 -122
  155. package/src/main/__tests__/exchangesPromptId.test.cjs +0 -61
  156. package/src/main/__tests__/extractJson.test.cjs +0 -51
  157. package/src/main/__tests__/files-reject-credentials.test.cjs +0 -40
  158. package/src/main/__tests__/fixtures/1218-fo-01-move-scripts-lib-into-src-main-lib.log +0 -556
  159. package/src/main/__tests__/flatPrdTickSweep.test.cjs +0 -110
  160. package/src/main/__tests__/health-build-freshness.test.cjs +0 -39
  161. package/src/main/__tests__/health-claude-md-budget.test.cjs +0 -57
  162. package/src/main/__tests__/health-credentials.test.cjs +0 -81
  163. package/src/main/__tests__/health-delegation-chain.test.cjs +0 -124
  164. package/src/main/__tests__/health-per-project-stall.test.cjs +0 -84
  165. package/src/main/__tests__/health-prd-migration.test.cjs +0 -37
  166. package/src/main/__tests__/health-queue-dispatch.test.cjs +0 -135
  167. package/src/main/__tests__/health-starve-escalation.test.cjs +0 -94
  168. package/src/main/__tests__/health-tick-liveness.test.cjs +0 -179
  169. package/src/main/__tests__/health-usage-poller.test.cjs +0 -144
  170. package/src/main/__tests__/health-worktree-cap-blocked.test.cjs +0 -65
  171. package/src/main/__tests__/heapSnapshot.test.cjs +0 -121
  172. package/src/main/__tests__/historyAggregatorIntraday.test.cjs +0 -313
  173. package/src/main/__tests__/historyDashboard.test.cjs +0 -163
  174. package/src/main/__tests__/historyRollup.test.cjs +0 -333
  175. package/src/main/__tests__/intradayRefresh.test.cjs +0 -39
  176. package/src/main/__tests__/ipcSchemas-dependsOn.test.cjs +0 -39
  177. package/src/main/__tests__/kg-augment.test.cjs +0 -195
  178. package/src/main/__tests__/loadGateDetailTick.test.cjs +0 -31
  179. package/src/main/__tests__/machineProfile.test.cjs +0 -152
  180. package/src/main/__tests__/mcpStatus.test.cjs +0 -61
  181. package/src/main/__tests__/memoryAggregate.test.cjs +0 -109
  182. package/src/main/__tests__/memoryStale.test.cjs +0 -88
  183. package/src/main/__tests__/needsReviewLedger.test.cjs +0 -162
  184. package/src/main/__tests__/openExternalApp-spawn-error.test.cjs +0 -25
  185. package/src/main/__tests__/opsErrorLog.test.cjs +0 -109
  186. package/src/main/__tests__/opsErrorLogTelemetryTap.test.cjs +0 -173
  187. package/src/main/__tests__/personaMerge.test.cjs +0 -169
  188. package/src/main/__tests__/planValidator.test.cjs +0 -125
  189. package/src/main/__tests__/pollLoop-dispatch-on-failure.test.cjs +0 -176
  190. package/src/main/__tests__/prd-group-allocator.test.cjs +0 -119
  191. package/src/main/__tests__/prdAdminRouteParity.test.cjs +0 -70
  192. package/src/main/__tests__/prdAdminRoutes.test.cjs +0 -718
  193. package/src/main/__tests__/prdAgentType.test.cjs +0 -103
  194. package/src/main/__tests__/prdAuthoringSeed.test.cjs +0 -39
  195. package/src/main/__tests__/prdCreate.test.cjs +0 -979
  196. package/src/main/__tests__/prdCreateAdoption.test.cjs +0 -205
  197. package/src/main/__tests__/prdCreateDisposition.test.cjs +0 -201
  198. package/src/main/__tests__/prdCreatePlanId.test.cjs +0 -132
  199. package/src/main/__tests__/prdFrontmatterAgentType.test.cjs +0 -117
  200. package/src/main/__tests__/prdFrontmatterDependsOn.test.cjs +0 -136
  201. package/src/main/__tests__/prdFrontmatterDisposition.test.cjs +0 -125
  202. package/src/main/__tests__/prdFrontmatterQuietMachine.test.cjs +0 -108
  203. package/src/main/__tests__/prdLocations.test.cjs +0 -195
  204. package/src/main/__tests__/prdLocationsArchived.test.cjs +0 -201
  205. package/src/main/__tests__/prdMigration.test.cjs +0 -349
  206. package/src/main/__tests__/prdMigrationLegacyAdopt.test.cjs +0 -91
  207. package/src/main/__tests__/prdParserHighWater.test.cjs +0 -74
  208. package/src/main/__tests__/prdParserSourcePromptId.test.cjs +0 -65
  209. package/src/main/__tests__/prdSetDisposition.test.cjs +0 -222
  210. package/src/main/__tests__/prdSizing.test.cjs +0 -106
  211. package/src/main/__tests__/prdSourcePromptIdBackfill.test.cjs +0 -118
  212. package/src/main/__tests__/prdUpdateDependsOn.test.cjs +0 -160
  213. package/src/main/__tests__/proc-role-env.test.cjs +0 -125
  214. package/src/main/__tests__/procname-claude-spawn-sites.test.cjs +0 -304
  215. package/src/main/__tests__/procname-sm-processes.test.cjs +0 -127
  216. package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +0 -177
  217. package/src/main/__tests__/projectPages.test.cjs +0 -137
  218. package/src/main/__tests__/promptSessionEvents.test.cjs +0 -234
  219. package/src/main/__tests__/promptSessionSchema.test.cjs +0 -101
  220. package/src/main/__tests__/promptSessionTranscript.test.cjs +0 -0
  221. package/src/main/__tests__/promptSessionsCreateEpicHandler.test.cjs +0 -159
  222. package/src/main/__tests__/pty-epic-worktree-spawn-cwd.test.cjs +0 -282
  223. package/src/main/__tests__/pty-session-open-telemetry.test.cjs +0 -96
  224. package/src/main/__tests__/pty-write-result.test.cjs +0 -46
  225. package/src/main/__tests__/queue-health-verdict.test.cjs +0 -170
  226. package/src/main/__tests__/queue-starvation-dispatch-driver.test.cjs +0 -286
  227. package/src/main/__tests__/queue-starvation-per-project.test.cjs +0 -147
  228. package/src/main/__tests__/queueHistory.test.cjs +0 -355
  229. package/src/main/__tests__/queueOps-interactive-ac-lint.test.cjs +0 -65
  230. package/src/main/__tests__/queueOpsArchiveDestination.test.cjs +0 -65
  231. package/src/main/__tests__/queueOpsAutoArchive.test.cjs +0 -211
  232. package/src/main/__tests__/rateLimitPollerStreak.test.cjs +0 -128
  233. package/src/main/__tests__/rcaReport.test.cjs +0 -266
  234. package/src/main/__tests__/reconcileFlatPrdSweep.test.cjs +0 -119
  235. package/src/main/__tests__/reconcileTiming.test.cjs +0 -135
  236. package/src/main/__tests__/runLogRetention.test.cjs +0 -489
  237. package/src/main/__tests__/runVerify-atomic-verdicts.test.cjs +0 -26
  238. package/src/main/__tests__/runVerify-blocked-by-foreign-wip.test.cjs +0 -58
  239. package/src/main/__tests__/runVerify-landed-commit-outranks.test.cjs +0 -191
  240. package/src/main/__tests__/runVerify-policy-denial.test.cjs +0 -89
  241. package/src/main/__tests__/runVerify-transcript-commit-evidence.test.cjs +0 -225
  242. package/src/main/__tests__/runVerify.test.cjs +0 -1784
  243. package/src/main/__tests__/scheduleJobSchema.test.cjs +0 -127
  244. package/src/main/__tests__/scheduleJobStatusDrift.test.cjs +0 -65
  245. package/src/main/__tests__/scheduleJobTransitions.test.cjs +0 -277
  246. package/src/main/__tests__/scheduleJobTransitionsGrep.test.cjs +0 -59
  247. package/src/main/__tests__/scheduleJobTransitionsTelemetryTap.test.cjs +0 -72
  248. package/src/main/__tests__/scheduler-admin-routes.test.cjs +0 -199
  249. package/src/main/__tests__/scheduler-adopted-run-supervision.test.cjs +0 -143
  250. package/src/main/__tests__/scheduler-already-satisfied-on-main.test.cjs +0 -105
  251. package/src/main/__tests__/scheduler-archive-completed-prd.test.cjs +0 -102
  252. package/src/main/__tests__/scheduler-archived-twin-guard.test.cjs +0 -155
  253. package/src/main/__tests__/scheduler-autofix-outcome.test.cjs +0 -188
  254. package/src/main/__tests__/scheduler-autofix-select.test.cjs +0 -439
  255. package/src/main/__tests__/scheduler-autopromote.test.cjs +0 -51
  256. package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +0 -101
  257. package/src/main/__tests__/scheduler-blocked-by-foreign-wip.test.cjs +0 -107
  258. package/src/main/__tests__/scheduler-boot-orphans.test.cjs +0 -153
  259. package/src/main/__tests__/scheduler-broadcast-reconcile.test.cjs +0 -121
  260. package/src/main/__tests__/scheduler-clear-queue-history.test.cjs +0 -134
  261. package/src/main/__tests__/scheduler-commit-guard-noop.test.cjs +0 -244
  262. package/src/main/__tests__/scheduler-committed-in-window.test.cjs +0 -182
  263. package/src/main/__tests__/scheduler-cross-project-batch.test.cjs +0 -43
  264. package/src/main/__tests__/scheduler-default-eligible-heal.test.cjs +0 -168
  265. package/src/main/__tests__/scheduler-dispatch-loop.test.cjs +0 -58
  266. package/src/main/__tests__/scheduler-effective-concurrency.test.cjs +0 -81
  267. package/src/main/__tests__/scheduler-epic-digest.test.cjs +0 -227
  268. package/src/main/__tests__/scheduler-failed-autoreset.test.cjs +0 -121
  269. package/src/main/__tests__/scheduler-finalize-dispatch-guards.test.cjs +0 -229
  270. package/src/main/__tests__/scheduler-find-prd-dir.test.cjs +0 -75
  271. package/src/main/__tests__/scheduler-fix-plan-path.test.cjs +0 -119
  272. package/src/main/__tests__/scheduler-force-tick-outcome.test.cjs +0 -46
  273. package/src/main/__tests__/scheduler-foreign-wip-manifest.test.cjs +0 -78
  274. package/src/main/__tests__/scheduler-gate-shadow.test.cjs +0 -119
  275. package/src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs +0 -390
  276. package/src/main/__tests__/scheduler-heal-refusal.test.cjs +0 -61
  277. package/src/main/__tests__/scheduler-heartbeat-payload.test.cjs +0 -80
  278. package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +0 -323
  279. package/src/main/__tests__/scheduler-integration-failure-stamp.test.cjs +0 -41
  280. package/src/main/__tests__/scheduler-investigation-clean-skip.test.cjs +0 -63
  281. package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +0 -123
  282. package/src/main/__tests__/scheduler-job-budget.test.cjs +0 -172
  283. package/src/main/__tests__/scheduler-job-overrun.test.cjs +0 -175
  284. package/src/main/__tests__/scheduler-launch-failure.test.cjs +0 -199
  285. package/src/main/__tests__/scheduler-leftover-fields.test.cjs +0 -52
  286. package/src/main/__tests__/scheduler-leftover-quarantine.test.cjs +0 -199
  287. package/src/main/__tests__/scheduler-looks-done.test.cjs +0 -537
  288. package/src/main/__tests__/scheduler-manual-pause.test.cjs +0 -118
  289. package/src/main/__tests__/scheduler-mechanical-recovery.test.cjs +0 -245
  290. package/src/main/__tests__/scheduler-meta-code-sha.test.cjs +0 -46
  291. package/src/main/__tests__/scheduler-mutate-reentrancy.test.cjs +0 -117
  292. package/src/main/__tests__/scheduler-needs-review-autoresolve.test.cjs +0 -197
  293. package/src/main/__tests__/scheduler-never-stop.test.cjs +0 -157
  294. package/src/main/__tests__/scheduler-no-dead-end-status.test.cjs +0 -152
  295. package/src/main/__tests__/scheduler-no-orphan-run-dir.test.cjs +0 -81
  296. package/src/main/__tests__/scheduler-notify-originating-tab-transcript.test.cjs +0 -87
  297. package/src/main/__tests__/scheduler-notify-originating-tab.test.cjs +0 -343
  298. package/src/main/__tests__/scheduler-periodic-reverify-guard.test.cjs +0 -217
  299. package/src/main/__tests__/scheduler-porcelain-rename.test.cjs +0 -164
  300. package/src/main/__tests__/scheduler-prd-missing-skip.test.cjs +0 -161
  301. package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +0 -178
  302. package/src/main/__tests__/scheduler-quarantine-autoresolve.test.cjs +0 -165
  303. package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +0 -257
  304. package/src/main/__tests__/scheduler-rate-limit-cooldown-freshness.test.cjs +0 -123
  305. package/src/main/__tests__/scheduler-rate-limit-pause.test.cjs +0 -152
  306. package/src/main/__tests__/scheduler-rate-limit-spin-guard.test.cjs +0 -156
  307. package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +0 -754
  308. package/src/main/__tests__/scheduler-reaper-helpers-basics.test.cjs +0 -87
  309. package/src/main/__tests__/scheduler-reconcile-cwd-preserve.test.cjs +0 -100
  310. package/src/main/__tests__/scheduler-reconcile-history-backfill.test.cjs +0 -105
  311. package/src/main/__tests__/scheduler-reconcile-invalid-repair.test.cjs +0 -203
  312. package/src/main/__tests__/scheduler-reconcile-quarantine.test.cjs +0 -247
  313. package/src/main/__tests__/scheduler-reset-job-fields-guard.test.cjs +0 -77
  314. package/src/main/__tests__/scheduler-resume-recovery.test.cjs +0 -254
  315. package/src/main/__tests__/scheduler-shard-quarantine.test.cjs +0 -115
  316. package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +0 -380
  317. package/src/main/__tests__/scheduler-sigterm-commit.test.cjs +0 -43
  318. package/src/main/__tests__/scheduler-stall-per-project.test.cjs +0 -126
  319. package/src/main/__tests__/scheduler-starve-escalation.test.cjs +0 -154
  320. package/src/main/__tests__/scheduler-stranded-autofix-park.test.cjs +0 -252
  321. package/src/main/__tests__/scheduler-stranded-investigation.test.cjs +0 -185
  322. package/src/main/__tests__/scheduler-stuck-failed-escalation.test.cjs +0 -136
  323. package/src/main/__tests__/scheduler-supervisor-record.test.cjs +0 -81
  324. package/src/main/__tests__/scheduler-tick-cancel-token.test.cjs +0 -54
  325. package/src/main/__tests__/scheduler-tick-wedge.test.cjs +0 -172
  326. package/src/main/__tests__/scheduler-transient-failure.test.cjs +0 -141
  327. package/src/main/__tests__/scheduler-unreadable-queue-guard.test.cjs +0 -62
  328. package/src/main/__tests__/scheduler-utilization-hold.test.cjs +0 -89
  329. package/src/main/__tests__/scheduler-verify-prd-path.test.cjs +0 -109
  330. package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +0 -234
  331. package/src/main/__tests__/scheduler-worktree-exec-cwd.test.cjs +0 -120
  332. package/src/main/__tests__/scheduler-writeprd-epic-rollback.test.cjs +0 -105
  333. package/src/main/__tests__/schedulerBatchRootBlocker.test.cjs +0 -117
  334. package/src/main/__tests__/schedulerStateSidecarRestore.test.cjs +0 -110
  335. package/src/main/__tests__/seedAgentPersonas.test.cjs +0 -184
  336. package/src/main/__tests__/seedSchedulerMcp.test.cjs +0 -211
  337. package/src/main/__tests__/seedStatus.test.cjs +0 -100
  338. package/src/main/__tests__/seedValidatorPersona.test.cjs +0 -116
  339. package/src/main/__tests__/stop-signal-anchor.test.cjs +0 -75
  340. package/src/main/__tests__/telemetryClient.test.cjs +0 -1055
  341. package/src/main/__tests__/telemetryContract.test.cjs +0 -930
  342. package/src/main/__tests__/telemetrySettings.test.cjs +0 -210
  343. package/src/main/__tests__/transcripts-batch-flush.test.cjs +0 -249
  344. package/src/main/__tests__/transcripts-doFlush-array.test.cjs +0 -124
  345. package/src/main/__tests__/transcripts-paged-reads.test.cjs +0 -241
  346. package/src/main/__tests__/transcripts-worktree-epic-path.test.cjs +0 -154
  347. package/src/main/__tests__/transcriptsUsageFor.test.cjs +0 -206
  348. package/src/main/__tests__/uniquePrdNumbers.test.cjs +0 -153
  349. package/src/main/__tests__/usageSingleFlight.test.cjs +0 -169
  350. package/src/main/__tests__/validationSentinels.test.cjs +0 -84
  351. package/src/main/__tests__/workTypeLibrary.test.cjs +0 -89
  352. package/src/main/bilkoHost.cjs +0 -314
  353. package/src/main/bilkoHostCore.cjs +0 -89
  354. package/src/main/lib/__tests__/active-sessions.test.cjs +0 -251
  355. package/src/main/lib/__tests__/activeIndexRebuild.test.cjs +0 -179
  356. package/src/main/lib/__tests__/agentPersonaSchema.test.cjs +0 -67
  357. package/src/main/lib/__tests__/auditLog.test.cjs +0 -38
  358. package/src/main/lib/__tests__/bootSelfHeal.test.cjs +0 -107
  359. package/src/main/lib/__tests__/branchSweep.test.cjs +0 -164
  360. package/src/main/lib/__tests__/buildIdentity.test.cjs +0 -121
  361. package/src/main/lib/__tests__/buildTarget.test.cjs +0 -52
  362. package/src/main/lib/__tests__/childWithLog.test.cjs +0 -321
  363. package/src/main/lib/__tests__/coldBootPromptSessionsWrite.test.cjs +0 -87
  364. package/src/main/lib/__tests__/crashTelemetry.test.cjs +0 -103
  365. package/src/main/lib/__tests__/credentials-futile-refresh.test.cjs +0 -115
  366. package/src/main/lib/__tests__/cwdClassify.test.cjs +0 -111
  367. package/src/main/lib/__tests__/definitionOfDoneSequence.test.cjs +0 -95
  368. package/src/main/lib/__tests__/delegationReadiness.test.cjs +0 -1175
  369. package/src/main/lib/__tests__/dispatchLoop.test.cjs +0 -63
  370. package/src/main/lib/__tests__/effectiveModelInfo.test.cjs +0 -244
  371. package/src/main/lib/__tests__/ephemeralCwd.test.cjs +0 -91
  372. package/src/main/lib/__tests__/epicDelegationStats.test.cjs +0 -137
  373. package/src/main/lib/__tests__/epicSpawnCwd.test.cjs +0 -283
  374. package/src/main/lib/__tests__/epicSpawnPlan.test.cjs +0 -196
  375. package/src/main/lib/__tests__/epicTranscriptPath.test.cjs +0 -163
  376. package/src/main/lib/__tests__/epicWorktreeBoot.test.cjs +0 -136
  377. package/src/main/lib/__tests__/epicWorktreeMerge.test.cjs +0 -130
  378. package/src/main/lib/__tests__/epicWorktreeMint.test.cjs +0 -117
  379. package/src/main/lib/__tests__/epicWorktreeProjectConfig.test.cjs +0 -137
  380. package/src/main/lib/__tests__/fixChainDepth.test.cjs +0 -40
  381. package/src/main/lib/__tests__/fixtures/204-mercury-steam-horse.log.txt +0 -13
  382. package/src/main/lib/__tests__/fixtures/scheduler-machine.json.corrupt-1789147548 +0 -34
  383. package/src/main/lib/__tests__/gateFixtures.json +0 -20
  384. package/src/main/lib/__tests__/gitCacheBound.test.cjs +0 -69
  385. package/src/main/lib/__tests__/gitWorktree.test.cjs +0 -1478
  386. package/src/main/lib/__tests__/gitWorktreeSalvage.test.cjs +0 -107
  387. package/src/main/lib/__tests__/gitWorktreeSalvageDelta.test.cjs +0 -153
  388. package/src/main/lib/__tests__/guardShims.test.cjs +0 -158
  389. package/src/main/lib/__tests__/importReferences.spec.cjs +0 -56
  390. package/src/main/lib/__tests__/instanceLock.test.cjs +0 -173
  391. package/src/main/lib/__tests__/jobSupervisorRecord.test.cjs +0 -78
  392. package/src/main/lib/__tests__/jobWorktree.test.cjs +0 -199
  393. package/src/main/lib/__tests__/jobWorktreeBootLive.test.cjs +0 -82
  394. package/src/main/lib/__tests__/landedSinceRun.test.cjs +0 -133
  395. package/src/main/lib/__tests__/launchFailure.test.cjs +0 -220
  396. package/src/main/lib/__tests__/loadGate.test.cjs +0 -303
  397. package/src/main/lib/__tests__/localAdminHttp.test.cjs +0 -214
  398. package/src/main/lib/__tests__/loopDelay.test.cjs +0 -68
  399. package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +0 -107
  400. package/src/main/lib/__tests__/modelCatalog.test.cjs +0 -202
  401. package/src/main/lib/__tests__/opsOwnership.test.cjs +0 -113
  402. package/src/main/lib/__tests__/opsRootAbsoluteCwd.test.cjs +0 -328
  403. package/src/main/lib/__tests__/opsRootNestedWrite.test.cjs +0 -51
  404. package/src/main/lib/__tests__/opsRootResolve.test.cjs +0 -149
  405. package/src/main/lib/__tests__/prdDeclaredPaths.test.cjs +0 -82
  406. package/src/main/lib/__tests__/prdDisposition.test.cjs +0 -224
  407. package/src/main/lib/__tests__/procIdentity.test.cjs +0 -119
  408. package/src/main/lib/__tests__/procName.test.cjs +0 -92
  409. package/src/main/lib/__tests__/projectBriefCore.test.cjs +0 -216
  410. package/src/main/lib/__tests__/projectRootResolve.test.cjs +0 -148
  411. package/src/main/lib/__tests__/queueHealth.test.cjs +0 -58
  412. package/src/main/lib/__tests__/queueStoreAtomicWrite.test.cjs +0 -88
  413. package/src/main/lib/__tests__/queueStoreMachineStateRecovery.test.cjs +0 -190
  414. package/src/main/lib/__tests__/quietMachineLease.test.cjs +0 -39
  415. package/src/main/lib/__tests__/rateLimitWindow.test.cjs +0 -88
  416. package/src/main/lib/__tests__/reaperHelpers.test.cjs +0 -577
  417. package/src/main/lib/__tests__/schedulerBatchDepends.test.cjs +0 -312
  418. package/src/main/lib/__tests__/schedulerBatchFairness.test.cjs +0 -213
  419. package/src/main/lib/__tests__/schedulerBatchLaunchHold.test.cjs +0 -125
  420. package/src/main/lib/__tests__/schedulerBatchProjectCap.test.cjs +0 -127
  421. package/src/main/lib/__tests__/schedulerBatchQuietMachine.test.cjs +0 -109
  422. package/src/main/lib/__tests__/schedulerMcpServerHeadlessRefusal.test.cjs +0 -71
  423. package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +0 -216
  424. package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +0 -183
  425. package/src/main/lib/__tests__/schedulerPaths.test.cjs +0 -226
  426. package/src/main/lib/__tests__/schedulerPathsWorktree.test.cjs +0 -133
  427. package/src/main/lib/__tests__/schedulerRuntimeState.test.cjs +0 -56
  428. package/src/main/lib/__tests__/sessionSlots.test.cjs +0 -144
  429. package/src/main/lib/__tests__/telemetryBacklog.test.cjs +0 -626
  430. package/src/main/lib/__tests__/telemetryBoot.test.cjs +0 -134
  431. package/src/main/lib/__tests__/telemetryConsent.test.cjs +0 -136
  432. package/src/main/lib/__tests__/telemetryCounters.test.cjs +0 -57
  433. package/src/main/lib/__tests__/telemetryCountersMetadataColumn.test.cjs +0 -98
  434. package/src/main/lib/__tests__/terminalRunOutcome.test.cjs +0 -200
  435. package/src/main/lib/__tests__/toolUseClassify.test.cjs +0 -53
  436. package/src/main/lib/__tests__/updateCheck.test.cjs +0 -63
  437. package/src/main/lib/__tests__/upgradeDrain.test.cjs +0 -130
  438. package/src/main/lib/__tests__/usageCircuit.test.cjs +0 -354
  439. package/src/main/lib/__tests__/watchdog-helpers.test.cjs +0 -441
  440. package/src/main/lib/__tests__/watchdog-relaunch.test.cjs +0 -266
  441. package/src/main/lib/kgExchangePairing.cjs +0 -75
@@ -1,9 +1,10 @@
1
1
  ---
2
2
  name: validator
3
- description: Validates a finished PLAN (the PRDs that share one planId) once, after its last PRD lands — re-runs each PRD's gate, checks every acceptance criterion against the real tree, reviews the plan's combined diff, and reports one VERIFIED/REFUTED verdict per PRD via sentinel lines. Runs headless as a scheduled PRD (agentType: validator); never edits product code and never queues work.
3
+ description: Validates a finished PLAN (the PRDs its validate PRD lists) once, after its last PRD lands — re-runs each PRD's gate, checks every acceptance criterion against the real tree, reviews the plan's combined diff, and reports one VERIFIED/REFUTED verdict per PRD via sentinel lines. Runs headless as a scheduled PRD (agentType: validator); never edits product code and never queues work.
4
4
  tools: Read, Grep, Glob, Bash
5
5
  model: sonnet
6
6
  title: Engineering — Plan Validator
7
+ seedVersion: 2
7
8
  ---
8
9
 
9
10
  You are validator. You judge whether a plan's PRDs actually landed what they promised. You do not fix anything, you do not re-implement, you do not queue PRDs — your output is evidence and verdicts, read by the architect who owns the plan.
@@ -14,9 +15,14 @@ Your PRD's `# Acceptance criteria` lists the plan's PRD slugs and where each PRD
14
15
 
15
16
  ## Procedure (in this order)
16
17
 
17
- 1. For each PRD slug, find its landed commit(s): `git log --oneline --since=<plan start> --grep=<slug>`, then the paths its AC names. No commit and no diff on an implementation PRD → REFUTED ("nothing landed").
18
- 2. For each AC line, produce ONE line of evidence: the `file:line` you read, or the captured output of the command it names. Re-run each PRD's gate command exactly as written (foreground, `timeout`-wrapped).
19
- 3. Review the plan's combined diff once: `git diff <base>..HEAD --stat`, then the diff. Run `/code-review` and `/security-review` on it if available in this environment — synchronously, never as a background agent; otherwise self-review for correctness, unsafe input handling, secrets, path traversal, and duplication of an existing helper.
18
+ 1. Read the `Base: <sha>` line in your PRD's implementation notes. For each PRD slug, list its
19
+ commits: `git log --oneline <base>..HEAD -- <each path in that PRD's # Files section>`. Why:
20
+ commit messages do not carry the slug. No `Base:` line → use
21
+ `git log --oneline -30 -- <paths>` and say in the record that the base was unknown. No commit
22
+ and no diff on an implementation PRD → REFUTED ("nothing landed").
23
+ 2. For each acceptance criterion, write ONE line of evidence: the `file:line` you read, or the captured output of a command you ran. Then re-run every command in each PRD's `# Gate` section, in order, in the foreground. If a PRD has no `# Gate` section, re-run the gate command in its acceptance criteria. If the gate is `none`, the per-criterion evidence is the whole check.
24
+ 3. Review the plan's combined diff once: `git diff <base>..HEAD --stat` (<base> is the SHA from
25
+ step 1), then the diff. Run `/code-review` and `/security-review` on it if available in this environment — synchronously, never as a background agent; otherwise self-review for correctness, unsafe input handling, secrets, path traversal, and duplication of an existing helper.
20
26
  4. Write the review record to the path your PRD names (Markdown: one section per PRD with verdict + evidence, then a Findings section ranked Critical / Important / Minor with `file:line`), `git add` that ONE file, commit it.
21
27
  5. Finish with the sentinel block — one line per PRD, then the scheduler's own verdict line:
22
28
  VALIDATION: <slug> VERIFIED
@@ -1 +0,0 @@
1
- import{az as d,i as j,al as $,a4 as g,ak as e,v as E,m as N,X as S,an as D,a5 as b,aD as T,a as p,$ as R,j as v,E as C}from"./index-Cd98Q1lD.js";import"./monaco-editor-BW5C4Iv1.js";const G=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function M(){const[s,t]=d.useState("diagram"),[a,i]=d.useState(null),[l,n]=d.useState(()=>new Set),c=d.useMemo(()=>j.filter(r=>!l.has(r.group)),[l]),m=d.useMemo(()=>$(c),[c]),o=r=>{n(x=>{const h=new Set(x);return h.has(r)?h.delete(r):h.add(r),h}),i(null)},u=a?g(a):null,y=r=>c.some(x=>x.id===r);return e.jsx(E,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(S,{options:G,active:s,onChange:t}),e.jsx(O,{hiddenGroups:l,onToggle:o}),e.jsxs("span",{className:"ml-auto text-fg-faint",children:[j.length," entities"]})]}),children:s==="diagram"?e.jsxs("div",{className:"h-full flex",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-auto",children:e.jsx(V,{layout:m,selectedId:a,onSelect:r=>i(x=>x===r?null:r)})}),e.jsx("div",{className:"w-96 shrink-0 border-l border-line overflow-y-auto",children:u?e.jsx(F,{entity:u,onSelectRelated:r=>y(r)?i(r):void 0}):e.jsx(N,{title:"select an entity",hint:"click a box in the diagram to see its storage, fields, and relations"})})]}):e.jsx(B,{})})}const X=d.memo(M);function O({hiddenGroups:s,onToggle:t}){return e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:v.map(a=>{const i=s.has(a.id);return e.jsxs("button",{onClick:()=>t(a.id),title:`${a.blurb} (${a.realm})`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded border text-[10.5px] ${i?"border-line text-fg-faint opacity-50":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a.tone.dot}`}),a.label,e.jsx("span",{className:"text-fg-faint",children:a.realm})]},a.id)})})}function V({layout:s,selectedId:t,onSelect:a}){const i=d.useMemo(()=>t?new Set(D(t)):null,[t]),l=n=>!!t&&(n.relation.from===t||n.relation.to===t);return s.boxes.length===0?e.jsx(N,{title:"no entities in view",hint:"toggle a group in the legend to show its entities"}):e.jsxs("div",{className:"relative p-4",style:{width:s.width+32,height:s.height+32},children:[e.jsxs("svg",{width:s.width,height:s.height,className:"absolute left-4 top-4 overflow-visible",children:[s.edges.map(n=>{const c=l(n);return e.jsx("path",{"data-testid":`erd-edge-${n.relation.from}-${n.relation.to}`,d:n.d,fill:"none",className:c?"stroke-accent":"stroke-line",strokeWidth:c?2:1,opacity:t&&!c?.25:1},`${n.relation.from}-${n.relation.to}-${n.relation.label}`)}),s.edges.map(n=>l(n)?e.jsx("text",{x:n.mx,y:n.my,textAnchor:"middle",className:"fill-fg-dim text-[10px]",children:n.relation.label},`label-${n.relation.from}-${n.relation.to}-${n.relation.label}`):null)]}),s.boxes.map(n=>e.jsx(_,{box:n,selected:n.id===t,dimmed:!!t&&n.id!==t&&!(i!=null&&i.has(n.id)),onClick:()=>a(n.id)},n.id))]})}function _({box:s,selected:t,dimmed:a,onClick:i}){const l=g(s.id),n=b(s.group),c=l.fields.slice(0,C),m=l.fields.length-c.length;return e.jsxs("button",{type:"button","data-testid":`erd-box-${s.id}`,onClick:i,className:`absolute text-left rounded border overflow-hidden bg-bg-hi ${t?"border-accent ring-1 ring-accent":"border-line"} ${a?"opacity-30":""}`,style:{left:s.x,top:s.y,width:s.w,height:s.h},children:[e.jsxs("div",{className:"px-2 py-1 border-b border-line flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${n.tone.dot}`}),e.jsx("span",{className:"text-[11px] font-semibold text-fg truncate",children:l.name})]}),l.aka&&e.jsx("div",{className:"px-2 pt-0.5 text-[9.5px] text-fg-faint truncate",children:l.aka}),e.jsxs("div",{className:"px-2 py-0.5",children:[c.map(o=>e.jsxs("div",{className:"text-[9.5px] font-mono text-fg-dim truncate flex items-center gap-1",children:[o.key&&e.jsx("span",{className:"text-fg-faint",children:o.key}),e.jsx("span",{className:"truncate",children:o.name})]},o.name)),m>0&&e.jsxs("div",{className:"text-[9.5px] text-fg-faint italic",children:["+",m," more"]})]})]})}function w({fields:s}){return e.jsxs("table",{className:"w-full text-[11px] font-mono",children:[e.jsx("thead",{className:"text-fg-faint uppercase tracking-wide text-[9.5px]",children:e.jsxs("tr",{className:"border-b border-line",children:[e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"name"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"type"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"key"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"note"})]})}),e.jsx("tbody",{children:s.map(t=>e.jsxs("tr",{className:"border-b border-line/50",children:[e.jsxs("td",{className:"px-2 py-1 text-fg",children:[t.name,t.optional&&e.jsx("span",{className:"text-fg-faint",children:"?"})]}),e.jsx("td",{className:"px-2 py-1 text-fg-dim",children:t.type}),e.jsx("td",{className:"px-2 py-1",children:t.key&&e.jsxs(p,{tone:t.key==="pk"?"accent":"dim",children:[t.key,t.ref?` → ${t.ref}`:""]})}),e.jsx("td",{className:"px-2 py-1 text-fg-faint",children:t.note})]},t.name))})]})}function k({entity:s}){return e.jsxs("div",{className:"space-y-1 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"path"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:s.store.path})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"format"}),e.jsx("span",{className:"font-mono text-fg-dim",children:s.store.format})]}),s.store.writer&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"writer"}),e.jsxs(p,{tone:"accent",children:["single-writer: ",s.store.writer]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"definedIn"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:s.store.definedIn})]})]})}function F({entity:s,onSelectRelated:t}){const a=b(s.group),i=T(s.id);return e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${a.tone.dot}`}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:s.name})]}),s.aka&&e.jsx("div",{className:"text-[10.5px] text-fg-faint",children:s.aka}),e.jsx(p,{tone:"dim",className:"mt-1",children:a.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:s.summary}),e.jsxs("div",{children:[e.jsx(f,{children:"storage"}),e.jsx(k,{entity:s})]}),e.jsxs("div",{children:[e.jsx(f,{children:"fields"}),e.jsx(w,{fields:s.fields})]}),s.notes&&s.notes.length>0&&e.jsxs("div",{children:[e.jsx(f,{children:"notes"}),e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:s.notes.map(l=>e.jsx("li",{children:l},l))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"relations"}),i.length===0?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"no relations"}):e.jsx("ul",{className:"space-y-1",children:i.map(l=>{const n=l.from===s.id?l.to:l.from,c=g(n);return e.jsxs("li",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"font-mono text-fg-faint w-10 shrink-0",children:R(l.cardinality)}),e.jsx("span",{className:"text-fg-dim",children:l.label}),l.via&&e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:["via ",l.via]}),e.jsx("button",{type:"button",onClick:()=>t(n),className:"ml-auto text-accent hover:underline font-mono",children:c.name})]},`${l.from}-${l.to}-${l.label}`)})})]})]})}function f({children:s}){return e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1 font-mono",children:s})}function B(){return e.jsx("div",{className:"p-4 space-y-6",children:v.map(s=>{const t=j.filter(a=>a.group===s.id);return t.length===0?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.tone.dot}`}),e.jsx("span",{className:"text-xs font-semibold text-fg",children:s.label}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:s.realm})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-3",children:t.map(a=>e.jsxs("div",{className:"border border-line rounded bg-bg-hi p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:a.name}),a.aka&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:a.aka})]}),e.jsx(p,{tone:"dim",className:"mt-1",children:s.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:a.summary}),e.jsx(k,{entity:a}),e.jsx(w,{fields:a.fields}),a.notes&&a.notes.length>0&&e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:a.notes.map(i=>e.jsx("li",{children:i},i))})]},a.id))})]},s.id)})})}export{X as DataModel};
@@ -1 +0,0 @@
1
- import{az as i,aO as Q,b0 as P,aN as m,a0 as V,aQ as Y,ak as t,m as T,aI as W}from"./index-Cd98Q1lD.js";import"./monaco-editor-BW5C4Iv1.js";function X(r){return r.hasMarketingPage?r.packagePrivate&&!r.packageHomepage?{kind:"private-needs-confirm"}:{kind:"ready"}:{kind:"no-marketing-page"}}const Z=["home","marketing","feature","architecture"],ee={home:"Home page",marketing:"Marketing page",feature:"Feature page",architecture:"Architecture page"};function $(r){return ee[r]}function D(r){const n=r.find(l=>l.subpath==="");return Z.map(l=>{const p=r.find(h=>h.source.kind==="project-page-lens"&&h.source.lens===l);return p?{lens:l,status:p.subpath===""?"root":"hosted",subpath:p.subpath,documentId:p.id}:!n&&l==="marketing"?{lens:l,status:"root",subpath:"",documentId:null}:{lens:l,status:"available",subpath:l,documentId:null}})}function te(r){return r.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)||"project"}const j="bilko-host-publisher",se="bilko-host-publisher",ne=[{value:"home",label:"Home lens"},{value:"marketing",label:"Marketing lens"},{value:"feature",label:"Feature lens"},{value:"architecture",label:"Architecture lens"}];function ae(r,n){for(const l of Object.values(r))if(l.cwd===n&&l.tag===j&&l.status==="active")return l;return null}function _(r){W(r),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function oe(){const r=Q(),n=(r==null?void 0:r.cwd)??null,l=P(e=>e.sessions),p=P(e=>e.createPromptSession),h=P(e=>e.approveProposed),[o,C]=i.useState(null),[O,k]=i.useState(!1),[b,v]=i.useState(""),[E,H]=i.useState(!1),[B,M]=i.useState(!1),[u,A]=i.useState(null),[N,L]=i.useState(""),[f,I]=i.useState(""),[w,R]=i.useState("feature");i.useEffect(()=>{let e=!1;return window.api.agents.listPersonas().then(a=>{if(e)return;const s=a.find(g=>g.name===se);A(s?{name:s.name,description:s.description}:null)}).catch(()=>{e||A(null)}),()=>{e=!0}},[]);const c=i.useCallback(()=>{n&&(k(!1),window.api.bilkoHost.get(n).then(e=>{C(e),v(a=>{var s;return a||((s=e.bundleManifest)==null?void 0:s.slug)||e.defaultSlug}),k(!0)}).catch(e=>{k(!0),m.error(`Could not load bilko-host status: ${e instanceof Error?e.message:String(e)}`)}))},[n]);i.useEffect(()=>{C(null),v(""),H(!1),c()},[c]);const x=n?ae(l,n):null,z=i.useCallback(()=>{!n||!b||(M(!0),window.api.bilkoHost.prepareBundle(n,b).then(()=>c()).catch(e=>m.error(`Could not prepare bundle: ${e instanceof Error?e.message:String(e)}`)).finally(()=>M(!1)))},[n,b,c]),F=i.useCallback(()=>{if(!n)return;const e=te(N).replace(/^-+|-+$/g,"");if(!e||!f.trim()){m.error("A sub-path and a title are required.");return}const a={kind:"project-page-lens",lens:w};window.api.bilkoHost.addDocument(n,e,f.trim(),a).then(()=>{L(""),I(""),c()}).catch(s=>m.error(`Could not add document: ${s instanceof Error?s.message:String(s)}`))},[n,N,f,w,c]),G=i.useCallback((e,a)=>{n&&window.api.bilkoHost.addDocument(n,a,$(e),{kind:"project-page-lens",lens:e}).then(()=>c()).catch(s=>m.error(`Could not add ${e} page: ${s instanceof Error?s.message:String(s)}`))},[n,c]),U=i.useCallback(async()=>{if(!n||!o)return;const e=D(o.documents).filter(a=>a.status==="available");for(const a of e)try{await window.api.bilkoHost.addDocument(n,a.subpath,$(a.lens),{kind:"project-page-lens",lens:a.lens})}catch(s){m.error(`Could not add ${a.lens} page: ${s instanceof Error?s.message:String(s)}`)}c()},[n,o,c]),q=i.useCallback(e=>{n&&window.api.bilkoHost.removeDocument(n,e).then(()=>c()).catch(a=>m.error(`Could not remove document: ${a instanceof Error?a.message:String(a)}`))},[n,c]),J=i.useCallback(async()=>{if(!n||!b)return;if(x){_(x.id);return}const e=`Publish this project to bilko.run as a static-path listing, slug "${b}". Bundle is at session-manager-operations/bilko-host/dist/ (prepare it first via Prepare Bundle if it's missing or stale) — it may contain multiple documents (a root page plus sub-paths); publish the whole dist/ tree as one static-path app.`,{goalText:a,openingPrompt:s}=V({title:"",goal:e,tag:j,agentName:u==null?void 0:u.name,agentDescription:(u==null?void 0:u.description)??void 0}),g=u?await p(n,a,j,"HostBilko",u.name):await p(n,a,j,"HostBilko");h(g.id,"HostBilko"),Y.getState().send({tabId:g.id,sessionId:g.claudeSessionId,cwd:n,prompt:s}),_(g.id)},[n,b,x,p,h,u]);if(!n)return t.jsx(T,{title:"Open a project to host it on Bilko.run"});if(!O||!o)return null;const y=X(o);if(y.kind==="no-marketing-page")return t.jsx(T,{title:"No Marketing page yet",hint:"Generate this project's Project Pages from Project Home first — the root document publishes the Marketing lens."});const d=o.publishState,K=(d==null?void 0:d.status)??(o.bundleManifest?"bundle-ready":"not-published"),S=y.kind==="ready"||E;return t.jsxs("div",{className:"max-w-2xl space-y-4",children:[t.jsxs("div",{className:"rounded-card border border-line bg-bg-hi p-5 space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{children:[t.jsx("div",{className:"font-serif text-lg text-fg",children:o.projectName}),t.jsxs("div",{className:"text-xs text-fg-faint mt-0.5",children:["Status: ",t.jsx("span",{className:"font-mono",children:K}),o.bundleStale&&o.bundleManifest&&t.jsx("span",{className:"ml-2 text-accent",children:"bundle out of date — Prepare Bundle again"})]})]}),(d==null?void 0:d.status)==="published"&&d.url&&t.jsx("a",{href:d.url,target:"_blank",rel:"noreferrer",className:"text-xs text-accent hover:underline",children:d.url})]}),y.kind==="private-needs-confirm"&&!E&&t.jsxs("div",{className:"rounded-md border border-line bg-bg p-3 text-xs text-fg-dim",children:["This project's package.json is marked private with no public homepage. Confirm you want to publish it to bilko.run anyway.",t.jsx("button",{type:"button",onClick:()=>H(!0),className:"mt-2 block rounded-md bg-accent px-3 py-1.5 text-xs font-semibold text-bg-hi hover:bg-accent-dark",children:"Yes, this can be public"})]}),S&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"block text-xs text-fg-faint",children:["Slug (bilko.run/projects/<slug>/)",t.jsx("input",{value:b,onChange:e=>v(e.target.value.toLowerCase()),className:"mt-1 block w-full rounded-md border border-line bg-bg px-2.5 py-1.5 text-sm font-mono text-fg"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:z,disabled:B,className:"rounded-md border border-line bg-bg px-3.5 py-1.5 text-xs font-semibold text-fg hover:bg-bg-hi disabled:opacity-50",children:B?"Preparing…":"Prepare Bundle"}),t.jsx("button",{type:"button",onClick:()=>{J().catch(e=>{m.error(e instanceof Error?e.message:String(e))})},disabled:!o.bundleManifest,title:o.bundleManifest?void 0:"Prepare a bundle first",className:"rounded-md bg-accent px-3.5 py-1.5 text-xs font-semibold text-bg-hi hover:bg-accent-dark disabled:opacity-50",children:x?"View publish in progress":"Publish"})]}),o.bundleManifest&&t.jsxs("div",{className:"text-[11px] text-fg-faint font-mono",children:["bundle: ",(o.bundleManifest.bundle.sizeBytesGz/1024).toFixed(1)," KB gz ·"," ",o.bundleManifest.bundle.fileCount," document",o.bundleManifest.bundle.fileCount===1?"":"s"," · built"," ",new Date(o.bundleManifest.builtAt).toLocaleString()," · ",o.bundleManifest.gitSha]}),(d==null?void 0:d.status)==="publish-failed"&&d.lastError&&t.jsxs("div",{className:"text-xs text-accent",children:["Last publish failed: ",d.lastError]})]})]}),S&&(()=>{const e=D(o.documents),a=e.filter(s=>s.status==="available").length;return t.jsxs("div",{className:"rounded-card border border-line bg-bg-hi p-5 space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("div",{className:"font-serif text-base text-fg",children:"Project Pages"}),a>1&&t.jsxs("button",{type:"button",onClick:U,className:"text-xs text-accent hover:underline",children:["Host all ",a," remaining"]})]}),t.jsxs("p",{className:"text-xs text-fg-faint",children:["This project generates 4 pages (Home / Marketing / Feature / Architecture). Marketing is the project's root (bilko.run/projects/",b||"<slug>","/); host any of the others as their own sub-page if you want them public too."]}),t.jsx("ul",{className:"space-y-1.5",children:e.map(s=>t.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md border border-line bg-bg px-3 py-2 text-xs",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-fg capitalize",children:s.lens}),t.jsx("div",{className:"text-fg-faint font-mono truncate",children:s.status==="root"?"(project root)":`/${s.subpath}/`})]}),s.status==="available"?t.jsxs("button",{type:"button",onClick:()=>G(s.lens,s.subpath),className:"shrink-0 rounded-md border border-line px-2 py-1 text-fg hover:bg-bg-hi",children:["+ Host as /",s.subpath,"/"]}):t.jsx("span",{className:"shrink-0 text-fg-faint",children:s.status==="root"?"root":"hosted"})]},s.lens))})]})})(),S&&t.jsxs("div",{className:"rounded-card border border-line bg-bg-hi p-5 space-y-3",children:[t.jsx("div",{className:"font-serif text-base text-fg",children:"Hosted documents"}),t.jsx("p",{className:"text-xs text-fg-faint",children:"One project, one Bilko listing — add as many explanatory pages as you want under it, each at its own sub-path. Removing one here takes it down on the next Publish."}),t.jsx("ul",{className:"space-y-1.5",children:o.documents.map(e=>t.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md border border-line bg-bg px-3 py-2 text-xs",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-fg truncate",children:e.title}),t.jsxs("div",{className:"text-fg-faint font-mono truncate",children:[e.subpath===""?"(root)":`/${e.subpath}/`," · ",e.url]})]}),e.subpath!==""&&t.jsx("button",{type:"button",onClick:()=>q(e.id),title:"Remove — takes effect on the next Publish",className:"shrink-0 rounded-md border border-line px-2 py-1 text-fg-faint hover:text-accent hover:border-accent/40",children:"Remove"})]},e.id))}),t.jsxs("div",{className:"rounded-md border border-line bg-bg p-3 space-y-2",children:[t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-fg-faint",children:"Add a document"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx("input",{value:N,onChange:e=>L(e.target.value),placeholder:"sub-path, e.g. special-doc/01",className:"rounded-md border border-line bg-bg-hi px-2.5 py-1.5 text-xs font-mono text-fg"}),t.jsx("input",{value:f,onChange:e=>I(e.target.value),placeholder:"Title",className:"rounded-md border border-line bg-bg-hi px-2.5 py-1.5 text-xs text-fg"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("select",{value:w,onChange:e=>R(e.target.value),className:"rounded-md border border-line bg-bg-hi px-2.5 py-1.5 text-xs text-fg",children:ne.map(e=>t.jsx("option",{value:e.value,children:e.label},e.value))}),t.jsx("button",{type:"button",onClick:F,className:"rounded-md border border-line bg-bg-hi px-3.5 py-1.5 text-xs font-semibold text-fg hover:bg-bg",children:"Add document"})]})]})]})]})}const le=i.memo(oe);export{le as HostBilko};
@@ -1,3 +0,0 @@
1
- import{az as d,aX as V,aO as X,aZ as q,aR as N,am as G,aq as H,ag as W,ak as e,m as w,v as D,P as A,X as Z,aG as Q}from"./index-Cd98Q1lD.js";import{S as U}from"./ScopeSwitcher-CjJi8ST5.js";import{S as Y}from"./SaveBar-l9jnEMES.js";import{P as ee}from"./Library-7akfgy67.js";import{u as te,E as se,s as re}from"./settingsSchema-IhUfucCF.js";import"./monaco-editor-BW5C4Iv1.js";const ne=["allow","deny","ask"];function ae(r){if(r.trim()==="")return{perms:{},full:{},err:null};try{const n=JSON.parse(r);return{perms:n.permissions??{},full:n,err:null}}catch(n){return{perms:{},full:{},err:n.message}}}function oe(r,n){const a={...r,permissions:n};return JSON.stringify(a,null,2)+`
2
- `}function ie(){const r=V(),n=X(),a=(n==null?void 0:n.cwd)??null,s=q(t=>t.navFace),i=d.useRef(!1),u=d.useRef(s),[p,c]=d.useState(()=>s==="project"&&a?"project":"user"),[m,P]=d.useState("effective");d.useEffect(()=>{if(u.current!==s){if(u.current=s,i.current){i.current=!1;return}c(s==="project"&&a?"project":"user")}},[s,a]),d.useEffect(()=>{s==="project"&&m==="presets"&&P("effective")},[s,m]);const O=t=>{i.current=!0,c(t)},b=te(A,r,a),f=b[p]??null,j=N(t=>t.files),k=N(t=>t.setDraft),J=N(t=>t.saveJson),I=N(t=>t.revert),[M,y]=d.useState(null),E=e.jsx(Z,{options:[{key:"effective",label:"Effective"},{key:"rules",label:"Rules"},...s==="home"?[{key:"presets",label:"Presets"}]:[]],active:m,onChange:P}),$=d.useMemo(()=>{const t=G(H(j,b));return W(t,["permissions"])??{kind:"object",children:{}}},[j,b]),F=(t,l)=>{var C;const o=b[p];if(!o)return;y(null);const h=((C=j[o])==null?void 0:C.draftRaw)??"";let v={};if(h.trim())try{v=JSON.parse(h)}catch{v={}}const B=Q(v.permissions??{},t,l),K={...v,permissions:B};k(o,JSON.stringify(K,null,2)+`
3
- `)};if(!r)return e.jsx(w,{title:"loading…"});if(m==="presets")return e.jsx(D,{toolbar:E,children:e.jsx(ee,{})});const R=t=>t!=="user"&&!a,g=f?j[f]:null,{perms:x,full:L,err:T}=g?ae(g.draftRaw):{perms:{},full:{},err:null},S=t=>{f&&(y(null),k(f,oe(L,t)))},_=(t,l)=>{const o=l.trim();if(!o)return;const h=x[t]??[];h.includes(o)||S({...x,[t]:[...h,o]})},z=(t,l)=>{const o=x[t]??[];S({...x,[t]:o.filter((h,v)=>v!==l)})};return e.jsx(D,{toolbar:e.jsxs(e.Fragment,{children:[E,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(U,{scopes:A.scopes,active:p,onChange:O,annotate:t=>{if(R(t))return{exists:!1};const l=b[t];if(!l)return null;const o=j[l];return{exists:(o==null?void 0:o.exists)??!1,dirty:(o==null?void 0:o.dirty)??!1}}}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:f??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),footer:f&&g?e.jsx(Y,{dirty:g.dirty,busy:g.busy,parseError:M||T||g.parseError,lastSavedAt:g.lastSavedAt,onSave:async()=>{y(null);const t=await J(f);t.ok||y(t.error??"save failed")},onRevert:()=>{y(null),I(f)}}):null,children:R(p)?e.jsx(w,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):m==="effective"?e.jsx(se,{node:$,targetScope:p,onOverride:F,schema:re().rootedAt(["permissions"]),rootLabel:"permissions"}):f&&g?e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[e.jsx(le,{value:x.defaultMode??"default",onChange:t=>S({...x,defaultMode:t})}),ne.map(t=>e.jsx(ce,{list:t,rules:x[t]??[],onAdd:l=>_(t,l),onRemove:l=>z(t,l)},t)),e.jsx(de,{dirs:x.additionalDirectories??[],onChange:t=>S({...x,additionalDirectories:t})})]}):e.jsx(w,{title:"resolving…"})})}const he=d.memo(ie);function le({value:r,onChange:n}){const a=["default","acceptEdits","plan","bypassPermissions"];return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:a.map(s=>e.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 text-xs transition-colors ${r===s?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:s},s))})]})}function ce({list:r,rules:n,onAdd:a,onRemove:s}){const[i,u]=d.useState(""),p=r==="allow"?"text-green-400":r==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${p}`,children:r}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:i,onChange:c=>u(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(a(i),u(""))},placeholder:r==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{a(i),u("")},disabled:!i.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),n.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:n.map((c,m)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:c}),e.jsx("button",{onClick:()=>s(m),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${m}-${c}`))})]})}function de({dirs:r,onChange:n}){const[a,s]=d.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:a,onChange:i=>s(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a.trim()&&(n([...r,a.trim()]),s(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:r.map((i,u)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:i}),e.jsx("button",{onClick:()=>n(r.filter((p,c)=>c!==u)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${u}-${i}`))})]})}export{he as Permissions};
@@ -1 +0,0 @@
1
- import{a1 as P,aX as G,az as x,ak as i,Z as R,B as T,a as _}from"./index-Cd98Q1lD.js";import{a as E,C as B,c as L,d as S,b as I}from"./Library-7akfgy67.js";const O=e=>`${e}/.claude/session-manager/provenance.json`;function D(e){if(!e||typeof e!="object")return{};const t={};for(const[n,o]of Object.entries(e))(o==="anthropic"||o==="community"||o==="local")&&(t[n]=o);return t}const K=P((e,t)=>({overrides:{},loaded:!1,loading:!1,home:null,load:async n=>{const o=t();if(!(o.home===n&&(o.loaded||o.loading))){e({home:n,loading:!0});try{const r=await window.api.config.readJson(O(n)),d=r.exists?D(r.data):{};e(h=>({overrides:{...d,...h.overrides},loaded:!0,loading:!1}))}catch{e({loaded:!0,loading:!1})}}},setOverride:async(n,o)=>{const r={...t().overrides};o===null?delete r[n]:r[n]=o,e({overrides:r});const d=t().home;if(d)try{await window.api.config.writeJson(O(d),r)}catch{}}})),a=e=>(e??"").toLowerCase().trim(),j=new Set,$=new Set;for(const e of I){const t=e.official?j:$;t.add(a(e.id)),t.add(a(e.name))}const H=new Set(S.filter(e=>e.official).flatMap(e=>[a(e.id),a(e.name)])),z=new Set(S.filter(e=>!e.official).flatMap(e=>[a(e.id),a(e.name)])),J=new Set(L.filter(e=>e.official).flatMap(e=>[a(e.id),a(e.name)])),U=new Set(L.filter(e=>!e.official).flatMap(e=>[a(e.id),a(e.name)])),V=new Set(B.flatMap(e=>[a(e.id),a(e.name)])),X=new Set(E.flatMap(e=>[a(e.id),a(e.name)])),Z=new Set(E.map(e=>e.command.trim())),q=new Set(["security-review","pr-comments","release-notes","add-dir","code-review","simplify"]),F=/(@anthropic-ai\/|anthropic\.com|github\.com\/anthropics)/i,Q=/(^|\s)(npx|uvx|pipx|bunx|mcp-remote|deno\s+run|docker\s+run)(\s|$)/i;function W(e){return[e.command,...e.args??[],e.url,e.repository,e.homepage].filter(Boolean).join(" ").toLowerCase()}const l=e=>({provenance:"anthropic",reason:e}),y=e=>({provenance:"community",reason:e});function Y(e,t,n){switch(e){case"mcp":return j.has(t)?l("official MCP server (catalog)"):$.has(t)?y("third-party server (catalog)"):null;case"skill":case"command":return H.has(t)?l("official Anthropic skill (catalog)"):z.has(t)?y("third-party skill (catalog)"):null;case"plugin":return J.has(t)?l("official Anthropic plugin (catalog)"):U.has(t)?y("third-party plugin (catalog)"):null;case"subagent":return V.has(t)?l("bundled Anthropic subagent (catalog)"):null;case"hook":return X.has(t)||n&&Z.has(n.trim())?l("bundled hook (catalog)"):null}}function ee(e,t){return e.repository?"has a source repository":e.homepage?"has a homepage":e.url?"remote endpoint":Q.test(t)?"installed from a package registry":null}function te(e){const t=a(e.name),n=W(e),o=Y(e.type,t,e.command);if(o)return o;if((e.type==="command"||e.type==="skill")&&q.has(t))return l("built-in Claude Code command");if(F.test(n))return l("Anthropic package or repo");const r=ee(e,n);return r?y(r):{provenance:"local",reason:"no external source — assumed self-created"}}function ne(e,t,n){return`${e}:${t??"-"}:${n}`}const c={anthropic:"Anthropic",community:"Community",local:"Local"},N={anthropic:"accent",community:"warn",local:"dim"},oe=["anthropic","community","local"];function se({input:e,scope:t,interactive:n=!0,className:o=""}){const r=G(),{overrides:d,load:h,setOverride:k}=K(),[v,m]=x.useState(!1),w=x.useRef(null);x.useEffect(()=>{r&&h(r)},[r,h]),x.useEffect(()=>{if(!v)return;const s=C=>{w.current&&!w.current.contains(C.target)&&m(!1)},g=C=>{C.key==="Escape"&&m(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",g)}},[v]);const b=ne(e.type,t??null,e.name),f=te(e),p=d[b],u=p??f.provenance,M=p?`Origin manually set to ${c[u]} — auto-detected ${c[f.provenance]} (${f.reason})`:`Auto-detected ${c[u]}: ${f.reason}`,A=i.jsxs(_,{tone:N[u],title:M,className:`${n?"cursor-pointer hover:brightness-125":""} ${o}`,children:[c[u],p&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-current opacity-70","aria-hidden":!0})]});return n?i.jsxs("span",{ref:w,className:"relative inline-flex",children:[i.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),m(g=>!g)},className:"inline-flex","aria-label":`Origin: ${c[u]}. Click to change.`,children:A}),v&&i.jsxs("span",{className:`absolute ${R.dialog} top-full right-0 mt-1 min-w-[7.5rem] rounded-md border border-line bg-bg-elev shadow-lg py-1 text-left`,onClick:s=>s.stopPropagation(),children:[i.jsx("span",{className:"block px-2 pb-1 text-[10px] uppercase tracking-wide text-fg-faint",children:"Mark origin as"}),oe.map(s=>i.jsxs("button",{type:"button",onClick:()=>{k(b,s),m(!1)},className:`flex w-full items-center gap-2 px-2 py-1 text-[12px] hover:bg-bg-hi/60 ${u===s?"text-fg":"text-fg-dim"}`,children:[i.jsx("span",{className:`w-2 h-2 rounded-full border ${T[N[s]]}`,"aria-hidden":!0}),c[s],p===s&&i.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:"set"})]},s)),i.jsx("div",{className:"my-1 border-t border-line"}),i.jsxs("button",{type:"button",onClick:()=>{k(b,null),m(!1)},disabled:!p,className:"flex w-full items-center gap-2 px-2 py-1 text-[12px] text-fg-dim hover:bg-bg-hi/60 disabled:opacity-40 disabled:hover:bg-transparent",title:`Revert to auto-detection (${c[f.provenance]})`,children:["Auto-detect",i.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:c[f.provenance]})]})]})]}):A}export{se as P};
@@ -1,16 +0,0 @@
1
- import{aF as Ce,ar as re,aJ as fs,af as Se,a9 as ie,ad as ee,aN as H,b2 as Oe,b0 as ue,az as f,b9 as hs,a7 as xe,b8 as xs,ak as t,b as Ge,I as ge,L as ft,p as gs,K as he,t as ms,Q as bs,e as ws,U as vs,a$ as Ye,aU as js,a3 as ht,ap as Mt,b7 as $e,G as Le,av as Te,A as Xe,aI as Ze,aa as xt,N as Rt,w as It,o as Et,q as ys,n as et,y as tt,O as Ns,D as ae,g as B,ab as Tt,b3 as ks,ay as Ss,aB as _t,bb as Ot,V as $s,as as gt,aV as mt,m as Ne,x as bt,l as Cs,aL as Ps,W as Ds,u as Lt,aX as As,aR as je,H as Ms,C as Rs,b4 as Is,aA as Es,T as Ts,ba as _s,b5 as wt,aH as Os}from"./index-Cd98Q1lD.js";import{l as Ls}from"./listSkills-QORduPIk.js";import{T as Fs}from"./Toggle-BbW4nGGf.js";import"./monaco-editor-BW5C4Iv1.js";function qs(e){const s=new Map(e.map(r=>[r.slug,r])),n=new Map,a=new Set,u=[];function o(r){n.set(r,1),u.push(r);const i=s.get(r);for(const d of(i==null?void 0:i.dependsOn)??[]){if(!s.has(d))continue;const l=n.get(d);if(l===1){const c=u.indexOf(d);for(let p=c;p<u.length;p++)a.add(u[p])}else l===void 0&&o(d)}u.pop(),n.set(r,2)}for(const r of e)n.has(r.slug)||o(r.slug);return a}function Bs(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Hs(e,s,n){const a=new Set(e.map(l=>l.slug)),u=new Set;for(const l of e)for(const c of l.dependsOn??[])a.has(c)&&u.add(c);const o=new Map,r=[];for(const l of e){const c=n.has(l.slug)?void 0:(l.dependsOn??[]).find(p=>a.has(p)&&!n.has(p));c?(o.has(c)||o.set(c,[]),o.get(c).push(l)):r.push(l)}const i=(l,c)=>l.slug.localeCompare(c.slug);r.sort(i);for(const l of o.values())l.sort(i);function d(l,c,p){const h=Bs(l,s),w=n.has(l.slug);p.add(l.slug);const x=w?[]:(o.get(l.slug)??[]).filter(m=>!p.has(m.slug)).map(m=>d(m,c+1,p));return p.delete(l.slug),{row:l,depth:c,children:x,blockers:h,blocked:h.some(m=>!m.missing&&m.status!=="completed"),hasNeedsReviewBlocker:h.some(m=>m.needsReview),hasMissingDep:h.some(m=>m.missing),cycle:w,parallelEligible:(l.dependsOn??[]).length===0&&!u.has(l.slug)}}return r.map(l=>d(l,0,new Set))}function Ft(e,s,n){const a=new Map((n??e).map(l=>[l.slug,l])),u=qs(e),o=[],r=new Map,i=new Map;for(const l of e){const c=Ce(l,s),p=c.epicId??"__none__";r.has(p)||(o.push(p),r.set(p,[]),i.set(p,{epicId:c.epicId,label:c.known&&c.label?c.label:c.epicId?`Epic ${c.epicId.slice(0,12)}…`:"No Epic",known:c.known})),r.get(p).push(l)}const d=o.map(l=>{const c=i.get(l),p=r.get(l),h=Hs(p,a,u),w={};for(const x of p){const m=x.status??"unknown";w[m]=(w[m]??0)+1}return{epicId:c.epicId,label:c.label,known:c.known,nodes:h,counts:w,total:p.length}});return d.sort((l,c)=>l.epicId===null?1:c.epicId===null?-1:l.known!==c.known?l.known?-1:1:l.label.localeCompare(c.label)),d}function Fe(e){const s=[],n=a=>{s.push(a);for(const u of a.children)n(u)};for(const a of e)n(a);return s}const Gs=15e4,ze=e=>e==="completed"||e==="skipped",ke=e=>e==="running"||e==="investigating",qt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Us=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Bt(e){const s=Math.max(0,Math.floor(e/1e3)),n=Math.floor(s/3600),a=Math.floor(s%3600/60),u=s%60;return n>0?`${n}h${String(a).padStart(2,"0")}m`:a>0?`${a}m${String(u).padStart(2,"0")}s`:`${u}s`}function Ht(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function Gt(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Bt(s)}function Vs(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const u=Date.parse(a.finishedAt)-Date.parse(a.startedAt);u>0&&(s+=u,n++)}return n===0?Gs:s/n}function _e(e){const s=re(e);return s===null?1/0:Number(s)}function vt(e,s){const n=_e(e.slug)-_e(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Ws(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Qs(e){return e.some(n=>ke(n.status))?"active":e.every(n=>ze(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function zs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function Js(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function Ks(e,s){const n=new Map(e.map(o=>[o.row.slug,o.row.slug])),a=o=>{for(;n.get(o)!==o;)n.set(o,n.get(n.get(o))),o=n.get(o);return o};for(const o of e)for(const r of o.row.dependsOn??[])s.has(r)&&n.set(a(o.row.slug),a(r));const u=new Map;for(const o of e){const r=a(o.row.slug),i=u.get(r);i?i.push(o):u.set(r,[o])}return[...u.values()]}function Ys(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const u=n.get(a.row.planId);u?u.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return Ks(e,s)}function st(e,s){if(e.length===0)return[];const n=s.now??Date.now(),a=s.avgDurationMs??Vs(e),u=Math.max(1,s.concurrency??1),o=new Map(e.map(c=>[c.slug,c])),r=c=>c.status==="pending"&&(c.dependsOn??[]).every(p=>o.get(p)===void 0||o.get(p).status==="completed"),i=new Map;e.filter(r).sort(vt).forEach((c,p)=>i.set(c.slug,p));const d=Ft(e,s.sessions,e),l=[];for(const c of d){const p=Fe(c.nodes),h=new Set(p.map(m=>m.row.slug)),w=new Map(p.map(m=>[m.row.slug,m])),x=[];for(const m of Ys(p,h)){const j=new Set(m.map($=>$.row.slug)),_=new Map,N=new Set,I=$=>{const S=w.get($);return(S.row.dependsOn??[]).filter(q=>j.has(q)&&!(S.cycle&&w.get(q).cycle))},g=$=>{const S=_.get($);if(S!==void 0)return S;if(N.has($))return 0;N.add($);let q=0;for(const L of I($))q=Math.max(q,g(L));return N.delete($),_.set($,q+1),q+1};for(const $ of m)g($.row.slug);const A=m.map($=>{const S=$.row,q=(S.dependsOn??[]).filter(L=>h.has(L));return{slug:S.slug,title:S.title,status:S.status,stage:_.get(S.slug),prdNumber:re(S.slug),rowKind:"dep",rowTrailing:"",cycle:$.cycle,estimateMinutes:S.estimateMinutes??null,deps:q,crossEpicDeps:(S.dependsOn??[]).filter(L=>!h.has(L)),blockers:$.blockers,job:S}});A.sort(vt);const k=A.reduce(($,S)=>Math.max($,S.stage),0),P=new Map;for(const $ of A){const S=$.job,q=w.get($.slug),L=S.status;let D;if(ze(L)){const E=S.startedAt&&S.finishedAt?Date.parse(S.finishedAt)-Date.parse(S.startedAt):NaN;D={kind:"done",trailing:E>0?Bt(E):"",held:!1,blocked:!1}}else if(ke(L)){const E=S.startedAt?Math.max(0,n-Date.parse(S.startedAt)):null;D={kind:"running",trailing:E===null?"":Gt(S,E),held:!1,blocked:!1}}else if(L==="failed")D={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(L==="needs_review")D={kind:"review",trailing:"review",held:!1,blocked:!1};else if(L==="quarantined")D={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const E=q.blockers.filter(T=>!T.missing&&T.status!=="completed");if(E.length>0){const T=E.some(Y=>Us(Y.status)),V=E[0].slug;D={kind:"dep",trailing:`←${re(V)??V}`,held:!T,blocked:T}}else if(S.heldReason)D={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const T=Ws(S),V=i.get(S.slug)??0;D=T>0?{kind:"retry",trailing:`${T} ${T===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ht(V*a/u),held:!1,blocked:!1}}}P.set($.slug,D)}const G=[];for(let $=1;$<=k;$++){const S=A.filter(b=>b.stage===$),q=S.find(b=>{const y=P.get(b.slug).kind;return b.status==="pending"&&(y==="eta"||y==="retry")});if(q){const b=P.get(q.slug);b.kind="next",b.trailing="next"}let L=0,D=0,E=0,T=0,V=0,Y=0;for(const b of S){const y=P.get(b.slug);b.rowKind=y.kind,b.rowTrailing=y.trailing,ze(b.status)?L++:ke(b.status)?D++:b.status==="pending"?(V++,y.held&&E++,y.blocked&&T++):qt(b.status)&&Y++}const J=L===S.length?"done":D>0?"running":T+Y>0?"blocked":E>0?"held":"pending",ne={n:$,rows:S,doneCount:L,runningCount:D,heldCount:E,blockedCount:T};G.push({...ne,state:J,summary:zs(J,ne,V,Y)})}let z=0;for(const $ of A){const S=$.estimateMinutes?$.estimateMinutes*6e4:a;if($.status==="pending")z+=S;else if(ke($.status)){const q=$.job.startedAt?Math.max(0,n-Date.parse($.job.startedAt)):0;z+=Math.max(0,S-q)}}const Q=A.reduce(($,S)=>Math.min($,_e(S.slug)),1/0),Z=A.reduce(($,S)=>Math.max($,_e(S.slug)),-1/0);x.push({epicId:c.epicId,waveIndex:0,index:0,label:c.known?fs(c.label).title:c.label,status:Qs(A),prdCount:A.length,stageCount:k,doneCount:G.reduce(($,S)=>$+S.doneCount,0),runningCount:G.reduce(($,S)=>$+S.runningCount,0),heldCount:G.reduce(($,S)=>$+S.heldCount,0),blockedCount:G.reduce(($,S)=>$+S.blockedCount,0),etaMs:z/u,stages:G,_firstNum:Q,_lastNum:Z,_firstSlug:A[0].slug})}x.sort(Js),x.forEach((m,j)=>{m.waveIndex=j+1,x.length>1&&(m.label=`${m.label} · plan ${j+1}/${x.length}`),l.push(m)})}return l.sort((c,p)=>{if(c._lastNum!==p._lastNum)return c._lastNum>p._lastNum?-1:1;const h=(c.epicId??"").localeCompare(p.epicId??"");return h!==0?h:c.waveIndex-p.waveIndex}),l.map(({_firstNum:c,_lastNum:p,_firstSlug:h,...w},x)=>({...w,index:x+1}))}function Xs(e,s=Date.now()){const n=new Map(e.map(h=>[h.slug,h])),a=new Date(s).toDateString();let u=0,o=0,r=0,i=0,d=0,l=0,c=0;for(const h of e)h.status==="pending"?(o++,(h.dependsOn??[]).every(x=>n.get(x)===void 0||n.get(x).status==="completed")&&u++):ke(h.status)?c++:h.status==="failed"?r++:h.status==="needs_review"?i++:h.status==="quarantined"?d++:h.status==="completed"&&h.finishedAt&&new Date(Date.parse(h.finishedAt)).toDateString()===a&&l++;let p=null;if(r+i+d>0){for(const h of st(e,{sessions:{},now:s}))for(const w of h.stages)if(w.rows.some(x=>qt(x.status))){(p===null||w.n<p)&&(p=w.n);break}}return{readyNow:u,totalQueued:o,heldByDeps:o-u,needsYou:r+i+d,needsYouStage:p,failedCount:r,needsReviewCount:i,doneToday:l,inFlight:c}}function Zs(e){const s=new Map;for(const d of e.stages)for(const l of d.rows)s.set(l.slug,l);const n=d=>{var l;return((l=s.get(d))==null?void 0:l.cycle)===!0},a=new Map,u=new Set,o=(d,l)=>d.chain.length!==l.chain.length?d.chain.length>l.chain.length:d.est!==l.est?d.est>l.est:d.chain.join("\0")<l.chain.join("\0"),r=d=>{const l=a.get(d);if(l)return l;const c=s.get(d),p=c.estimateMinutes??0;if(u.has(d))return{chain:[d],est:p};u.add(d);let h=null;for(const x of c.deps){if(!s.has(x)||c.cycle&&n(x))continue;const m=r(x);(!h||o(m,h))&&(h=m)}u.delete(d);const w=h?{chain:[...h.chain,d],est:h.est+p}:{chain:[d],est:p};return a.set(d,w),w};let i=null;for(const d of s.keys()){const l=r(d);(!i||o(l,i))&&(i=l)}return i?i.chain:[]}const en=300*6e4,tn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function sn(e){return tn[e]??e.replace(/_/g," ")}function Ut({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:u,jobs:o,paused:r,nextReset:i,utilization:d,utilizationWindow:l,effectiveConcurrency:c}=e;let p=0,h=0;for(const N of o)N.status==="pending"?p++:N.status==="completed"&&h++;const w=a.length,x=p+w,m=(c==null?void 0:c.cap)??5;if(w>0){const N=a.reduce((P,G)=>(P.startedAt??"")<(G.startedAt??"")?P:G),I=N.startedAt?s-Date.parse(N.startedAt):0,g=h+w,A=h+x,k=w>1?` · ${w}/${m} parallel`:"";return{kind:"running",line1:`Running ${g}/${A}${k} · ${Se(I)}`,line2:w===1?N.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(r){const N=r.resumeAt?Date.parse(r.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[r.reason]??`Paused — ${r.reason}`,line2:r.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":N!==null&&N>0?`auto-resume ${ie(Date.parse(r.resumeAt))} (in ${ee(N)})`:r.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:r.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(x===0)return{kind:"idle",line1:"No work queued",line2:null};const j=u.firePolicy??"when-available";if(j==="manual")return{kind:"manual",line1:`Manual · ${p} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};if(j==="on-reset"){if(!i)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const N=Date.parse(i)+u.offsetMinutes*6e4,I=N-s;return{kind:"on-reset",line1:`On-reset · ${p} pending`,line2:I>0?`fires ${ie(N)} (in ${ee(I)})`:"firing now…"}}const _=u.utilizationThreshold??90;if(d==null)return{kind:"auto-soon",line1:`Auto · ${p} pending`,line2:"checking token availability…"};if(d>=_){const N=i?Date.parse(i)-s:null,I=l?sn(l):null,g=N===null||Number.isNaN(N)||N>en,A=N&&N>0?`resets ${ie(Date.parse(i))} (in ${ee(N)})`:null;let k;return g?k=`${I??"binding"} window — long hold${A?`, ${A}`:", reset time unknown"}`:k=A?`${I?`${I} window `:""}next ${A}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${d.toFixed(0)}% ≥ ${_}%)`,line2:k}}return{kind:"auto-soon",line1:`Auto · ${p} pending · util ${d.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const nn=15e3,an=new Set(["failed","needs_review","quarantined"]);function jt(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>an.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function rn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${ee(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?ee(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function ln(e){const[s,n]=f.useState(null),a=Ye(),u=js(),o=a&&u;return f.useEffect(()=>{if(!o)return;let r=!0,i=!1,d=!1;const l=()=>{i||(i=!0,window.api.schedule.queueHealth(e).then(p=>{i=!1,d=!1,r&&n(p)},p=>{i=!1,!d&&(d=!0,H.error(`Queue health refresh failed: ${p instanceof Error?p.message:String(p)}`))}))};l();const c=setInterval(l,nn);return()=>{r=!1,clearInterval(c)}},[e,o]),s}const on={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function dn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}function cn(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e)}const Ue="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function un(e,s,n){if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const a=new Date(s).getTime()-n;return a>0?`Paused for rate limit — resumes in ${ee(a)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function pn({now:e}){const s=Oe(c=>c.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),u=Object.entries(s.launchMitigations??{}),o=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",r="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",i="bg-red-950/10 border-red-700/30 text-red-800",d="bg-amber-400/10 border-amber-600/30 text-amber-700",l="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${r} ${o?i:d}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:un(n.reason,n.resumeAt,e)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:l,children:"Resume"})]}),a.map(([c,p])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${r} ${i}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:c})," jobs are failing before any work starts",p.httpStatus?` (HTTP ${p.httpStatus}, ${p.kind})`:` (${p.kind})`,p.exhausted?" — held until the Claude CLI version changes or you press Retry now.":p.until?` — next automatic probe ${new Date(p.until).getTime()>e?`in ${ee(new Date(p.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:p.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:p.message,children:[p.attempts," failed probe",p.attempts===1?"":"s",p.claudeVersion?` · CLI ${p.claudeVersion}`:"",p.lastSlug?` · last: ${p.lastSlug}`:""," · ",p.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:l,children:"Retry now"})]},`launch-block-${c}`)),u.map(([c,p])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${r} ${d}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:c})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(p.env).map(([h,w])=>`${h}=${w}`).join(" ")}),")",p.claudeVersion?` since CLI ${p.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:p.hint})]})},`launch-mitigation-${c}`))]})}function fn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:u,planMode:o,onPlanMode:r,planToolsRef:i}){const d=Oe(C=>C.snapshot),l=ue(C=>C.sessions),c=ln(e),[p,h]=f.useState(()=>Date.now()),[w,x]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>h(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return hs(Promise.resolve().then(()=>window.api.history.dashboard({rangeDays:30})),5e3,"history.dashboard").then(O=>{if(!C)return;const F=O.totals,K=F.inputTokens+F.outputTokens+F.cacheReadTokens+F.cacheCreationTokens;x(`$${F.estimatedCostUsd.toFixed(2)} · ${cn(K)} tok`)}).catch(()=>{}),()=>{C=!1}},[]);const m=f.useMemo(()=>((d==null?void 0:d.jobs)??[]).filter(C=>!e||C.cwd===e),[d,e]),j=f.useMemo(()=>Xs(m,p),[m,p]),_=f.useMemo(()=>{const C=st(m,{sessions:l,now:p}),O=F=>C.filter(K=>K.status===F).length;return{active:O("active"),queued:O("queued"),draft:O("draft")}},[m,l,p]),N=f.useMemo(()=>{const C=new Date(p).toDateString(),O=[];for(const F of m)if(F.status==="completed"&&F.startedAt&&F.finishedAt&&new Date(Date.parse(F.finishedAt)).toDateString()===C){const K=Date.parse(F.finishedAt)-Date.parse(F.startedAt);K>0&&O.push(K)}return O.length?Math.round(O.reduce((F,K)=>F+K,0)/O.length/6e4):null},[m,p]);if(!d)return null;const I=c&&!c.unknown?c.verdict??null:null,g=c&&!c.unknown?c.slots??null:null,A=d.paused,k=dn((I==null?void 0:I.kind)??null,!!A,j.inFlight),P=on[k],G=m.filter(C=>C.status==="pending").length,z=m.filter(C=>C.status==="running").length,Q=Ut({snap:{...d,jobs:m},now:p,avgDurationMs:0,runningJobs:m.filter(C=>C.status==="running")}),Z=c!=null&&c.unknown?`Queue health: unknown — ${c.reason??"state unavailable"}`:I?rn(I,(c==null?void 0:c.oldestRunningAgeMs)??null):"queue health loading…",$=xe(d.lastRunAt?Date.parse(d.lastRunAt):null,p),S=c!=null&&c.lastDispatchAttemptAt?xe(Date.parse(c.lastDispatchAttemptAt),p):"never",q=[Z,Q.line1,I?`dispatchable ${I.dispatchable} · needs_review ${I.needsReviewCount}`:null,(c==null?void 0:c.oldestRunningAgeMs)!=null?`oldest running ${ee(c.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${$} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${S} (advances on every driver evaluation)`].filter(Boolean).join(`
2
- `),L=d.utilization,D=d.pollHealth,E=D!=null&&!D.lastPollOk,T=xs(d.utilizationWindow),V=d.nextReset?Date.parse(d.nextReset):null,Y=V?V>p?ee(V-p):"soon":"—",J=d.effectiveConcurrency,ne=(J==null?void 0:J.cap)??5,b=(J==null?void 0:J.source)==="env",y=d.config.firePolicy??"when-available",R=G===0&&z===0;return t.jsxs("div",{"data-testid":"scheduler-top-bands",className:"shrink-0 px-[18px]",children:[t.jsxs(Ge,{height:40,testId:"queue-health-header",className:"gap-3",children:[t.jsx("h1",{className:"m-0 font-serif text-[21px] font-semibold leading-none tracking-tight text-fg",children:"Scheduler"}),t.jsx("span",{className:"w-px h-[20px] bg-rule-structural","aria-hidden":"true"}),t.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[12.5px] font-medium ${P.text}`,"data-testid":"scheduler-state-word","data-state":k,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${P.dot}`,"aria-hidden":"true"}),k]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[j.inFlight," in flight · ",j.heldByDeps," held · last batch ",$]}),t.jsxs(ge,{title:q,testId:"scheduler-verdict-info",popoverTestId:"scheduler-info-popover",children:[t.jsx("pre",{className:"m-0 mb-2 whitespace-pre-wrap font-mono text-[11.5px] text-fg-dim",children:q}),ft.scheduler&&t.jsx(gs,{content:ft.scheduler})]}),t.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>window.api.schedule.rescan().then(H.fromOutcome).catch(()=>H.error("Failed to rescan")),title:"Re-scan the prds/ folder. Use when you've added or edited PRDs on disk and want the queue to reflect them immediately.",className:Ue,children:"Refresh"}),A?t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately",className:Ue,children:"Resume"}):t.jsx("button",{type:"button",onClick:()=>window.api.schedule.pause(),title:"Stop NEW dispatch. Running jobs are not killed.",className:Ue,children:"Pause"}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),disabled:R,title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress.",className:"px-3 py-1.5 rounded bg-accent text-white text-[12.5px] font-semibold whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed hover:opacity-90",children:"Fire next batch"})]})]}),t.jsx(pn,{now:p}),t.jsxs(Ge,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(he,{testId:"kpi-window",label:T?`${T} used`:"Window used",info:E?`Billing poll failing — this reading may be outdated (last good reading ${xe(D.lastPollAt,p)}). Machine-wide ${T??"binding"} window.`:`Share of the machine-wide ${T??"binding"} billing window consumed — the window closest to its limit.`,value:L==null?"—":`${Math.round(L)}%`,sub:`resets in ${Y}`,third:t.jsx(ms,{pct:L??0,tone:E?"bg-amber-500":"bg-accent"})}),t.jsx(he,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(g==null?void 0:g.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:g?`${g.inUse}/${g.total}`:"—",sub:"in use",third:g?t.jsx(bs,{filled:g.inUse,total:g.total}):null}),t.jsx(he,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:j.readyNow,sub:`of ${j.totalQueued} queued`,third:`${j.heldByDeps} held by deps`}),j.needsYou>0?t.jsx(he,{testId:"kpi-needs-you",label:"Needs you",value:t.jsx("button",{type:"button","data-testid":"kpi-needs-you-jump",onClick:jt,className:"font-semibold text-accent hover:underline",title:"Scroll to the first failed / needs-review / quarantined row",children:j.needsYou}),sub:t.jsx("button",{type:"button",onClick:jt,className:"hover:underline",children:j.needsYouStage!=null?`blocking stage ${j.needsYouStage}`:"need attention"}),third:[j.failedCount>0&&`${j.failedCount} failed`,j.needsReviewCount>0&&`${j.needsReviewCount} needs review`,j.needsYou-j.failedCount-j.needsReviewCount>0&&`${j.needsYou-j.failedCount-j.needsReviewCount} quarantined`].filter(Boolean).join(" · ")}):t.jsx(he,{testId:"kpi-needs-you",label:"Needs you",value:t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[15px]",children:[t.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-sage","aria-hidden":"true"}),"all clear"]}),third:"0 failed · 0 needs review"}),t.jsx(he,{testId:"kpi-done",label:"Done today",value:j.doneToday,sub:N!=null?`avg ${N}m`:"avg —",third:t.jsx("span",{"data-testid":"kpi-done-spend",children:w})}),t.jsx(he,{testId:"kpi-concurrency",label:"Concurrency",info:"Start-jobs policy, concurrency cap and utilization threshold",infoTestId:"kpi-concurrency-info",infoAlignRight:!0,infoContent:t.jsxs("label",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-fg",children:"Start jobs"}),t.jsxs("select",{"data-testid":"kpi-fire-policy",value:y,onChange:C=>window.api.schedule.setConfig({firePolicy:C.target.value}),className:"border border-line bg-bg-hi rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"when-available: poll usage and fire when tokens are below threshold. on-reset: fire after each 5h reset. manual: only on Run now.","aria-label":"Start jobs policy",children:[t.jsx("option",{value:"when-available",children:"when available"}),t.jsx("option",{value:"on-reset",children:"only on reset"}),t.jsx("option",{value:"manual",children:"manually"})]})]}),value:t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(vs,{value:ne,min:0,max:10,disabled:b,onChange:C=>{window.api.schedule.setSessionSlots(Math.max(0,Math.min(10,C)))},title:b?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),b&&t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-amber-600 bg-amber-400/10 border border-amber-400/30 rounded px-1 py-0",title:"Pinned by SM_SESSION_SLOTS — unset the env var to edit",children:"env"})]}),sub:"at once",third:y==="when-available"?t.jsxs("span",{children:["pause above"," ",t.jsx(ws,{value:d.config.utilizationThreshold??90,min:0,max:100,testId:"kpi-threshold",title:"Fire only when 5h utilization is below this percent — click to edit",onCommit:C=>window.api.schedule.setConfig({utilizationThreshold:C})})]}):null})]}),t.jsxs(Ge,{height:30,testId:"scheduler-plans-toolbar",className:"gap-3",children:[t.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:"Plans"}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-plans-meta",children:[_.active," active · ",_.queued," queued · ",_.draft," draft · ",m.length," PRDs"]}),t.jsxs("span",{className:"ml-auto flex items-center gap-3",children:[t.jsx("span",{ref:i,className:"contents","data-testid":"scheduler-plan-tools"}),t.jsx("input",{type:"text",value:a,onChange:C=>u(C.target.value),placeholder:"filter PRDs…","aria-label":"Filter PRDs by title, slug, or project","data-testid":"scheduler-filter-input",className:"w-[180px] bg-bg-hi border border-line rounded px-2 py-0.5 text-[12px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint"}),t.jsx("span",{className:"inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Plan view mode",children:[["graph","Graph"],["list","List"],["critical","Critical path"]].map(([C,O])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${C}`,"aria-pressed":o===C&&s==="queue",onClick:()=>{r(C),n("queue")},className:`px-2 py-0.5 text-[12px] ${o===C&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:O},C))}),t.jsx("span",{className:"w-px h-[16px] bg-rule-structural","aria-hidden":"true"}),[["prds","PRDs","Authored PRD source files on disk — edit, lint, archive, or queue them."],["history","History","The last 50 completed and failed jobs."],["machine","Machine","Machine-wide config that applies to every project — not this project’s live queue."]].map(([C,O,F])=>t.jsx("button",{type:"button",onClick:()=>n(C),"aria-pressed":s===C,title:F,className:`text-[12.5px] ${s===C?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:O},C))]})]})]})}function Vt({options:e,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return t.jsx("div",{className:"flex gap-1.5 flex-wrap",children:e.map(u=>{const o=u.value===s;return t.jsxs("button",{type:"button",onClick:()=>n(u.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${o?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[u.label,u.count!==void 0&&t.jsxs("span",{children:[" ",u.count]})]},u.value)})})}function Wt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function hn(e){return Fe([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Qt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:hn(s)}))}function xn(e){const s=new Map;for(const n of e){const a=Qt(n);n.nodes.forEach((u,o)=>{const r=a.filter((i,d)=>d!==o);for(const i of Fe([u]))s.set(i.row.slug,r)})}return s}function zt({job:e,headChoices:s}){const[n,a]=f.useState(!1),u=f.useCallback((o,r)=>{a(!0),window.api.schedule.setPrdDisposition({slug:e.slug,cwd:e.cwd??void 0,disposition:o,dependsOn:r}).then(H.fromOutcome).catch(()=>H.error("Failed to change disposition")).finally(()=>a(!1))},[e.slug,e.cwd]);return e.disposition!=="append"&&s.length===0?null:t.jsxs("select",{"data-testid":"job-row-disposition-control",disabled:n,value:"",onChange:o=>{const r=o.target.value;if(r==="__new-head__")u("new-head");else if(r){const i=s.find(d=>d.rootSlug===r);i&&u("append",i.terminals)}},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border border-line/60 rounded px-1.5 py-0.5 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",title:"Change this wave's relationship to the rest of the Epic's plan",children:[t.jsx("option",{value:"",disabled:!0,children:"change disposition…"}),e.disposition==="append"&&t.jsx("option",{value:"__new-head__",children:"promote to new head"}),s.map(o=>t.jsxs("option",{value:o.rootSlug,children:["attach behind: ",Wt(o.label,40)]},o.rootSlug))]})}function gn(e,s,n=null){if(s.length===0||e.length===0)return e;const a=new Set,u=new Set;for(const r of e){a.add(r.slug);for(const i of ht(r))u.add(i)}const o=[];for(const r of s)r.archived!==!0||a.has(r.slug)||n&&r.cwd!==n||ht(r).some(i=>u.has(i))&&(a.add(r.slug),o.push({slug:r.slug,title:r.title,cwd:r.cwd,parallelGroup:r.parallelGroup,estimateMinutes:r.estimateMinutes,bodyPreview:"",status:r.archivedStatus??"completed",runId:null,startedAt:null,finishedAt:null,exitCode:null,error:null,dependsOn:r.dependsOn??void 0,sourcePromptId:r.sourcePromptId??null,epicId:r.epicId??null,synthetic:!0}));return o.length===0?e:[...e,...o]}const mn=[],bn=new Set(["failed","needs_review","quarantined"]);function wn(e){switch(e.status){case"completed":case"skipped":return"bg-sage";case"running":case"investigating":return"bg-accent";case"failed":return"bg-accent";case"needs_review":return"bg-butter";case"quarantined":return"bg-butter/60";default:return e.rowKind==="eta"||e.rowKind==="next"||e.rowKind==="retry"?"border border-fg-faint bg-transparent":"bg-fg-faint/40"}}function vn(e){switch(e.status){case"running":case"investigating":return"bg-butter/10";case"failed":return"bg-accent/10";case"needs_review":return"bg-butter/25";default:return""}}function jn(e){switch(e.rowKind){case"running":case"dep":case"failed":return"text-accent";case"review":return"text-butter font-semibold";default:return"text-fg-faint"}}function yn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:u=mn}){const[o,r]=f.useState(!1),i=e.job,d=s!==null&&e.rowKind==="running"?Gt(i,s):e.rowTrailing,l=e.status==="completed"||e.status==="skipped",c=e.rowKind==="dep"&&e.blockers.some(h=>!h.missing&&h.status!==null&&bn.has(h.status)),p=l||c;return t.jsxs("div",{role:"listitem","data-testid":"prd-row","data-slug":e.slug,className:"border-t border-rule-inner first:border-t-0",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":i.status,"data-job-index":n,onClick:()=>r(h=>!h),onFocus:()=>a(n),"aria-expanded":o,"aria-label":`${e.prdNumber?`PRD ${e.prdNumber}, `:""}${i.title}, ${i.status}${d?`, ${d}`:""}`,title:i.title,className:`w-full h-[31px] py-1 px-2 text-left flex items-center gap-1.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${vn(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${wn(e)}`}),t.jsx("span",{className:"shrink-0 font-mono text-[10.5px] text-fg-faint w-[30px]",children:e.prdNumber?`#${e.prdNumber}`:""}),t.jsx("span",{className:`flex-1 min-w-0 truncate text-[12.5px] leading-tight ${p?"text-fg-faint":"text-fg font-medium"}`,children:i.title}),t.jsx("span",{"data-testid":"prd-row-trailing",className:`shrink-0 font-mono text-[10.5px] ${jn(e)}`,children:d})]}),o&&t.jsx(Nn,{row:e,elapsedMs:s,headChoices:u})]})}const Jt=f.memo(yn);function Nn({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[u,o]=f.useState(!1),r=ue(w=>w.sessions),i=f.useMemo(()=>Ce(a,r),[a,r]),d=i.known&&i.epicId?r[i.epicId]:null,l=f.useCallback(w=>Mt(w),[]),c="font-mono text-[11.5px] text-fg-dim leading-snug break-words",p="text-[12px] font-semibold bg-transparent border-0 cursor-pointer p-0",h=a.error?a.error.split(`
3
- `)[0]:null;return t.jsxs("div",{"data-testid":"prd-row-detail",className:"px-3 py-2 bg-bg-elev/50 border-t border-rule-inner flex flex-col gap-1",children:[t.jsxs("div",{className:c,children:[a.status.replace(/_/g," "),a.exitCode!==null&&` · exit ${a.exitCode}`,a.verifierVerdict&&` · ${$e(a.verifierVerdict)}`,a.startedAt&&` · started ${ie(Date.parse(a.startedAt))}`,a.finishedAt&&` · finished ${ie(Date.parse(a.finishedAt))}`,s===null&&e.rowTrailing&&e.rowKind==="done"?` · took ${e.rowTrailing}`:""]}),e.cycle&&t.jsxs("div",{className:`${c} text-accent`,"data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",e.blockers.map(w=>w.slug).join(" ↔ ")||"self-referencing"]}),!e.cycle&&e.blockers.length>0&&t.jsxs("div",{className:c,"data-testid":"job-row-blockers",children:["depends on ",e.blockers.map(w=>`${w.slug} (${w.missing?"missing":(w.status??"unknown").replace(/_/g," ")})`).join(", ")]}),a.status==="pending"&&a.heldReason&&t.jsxs("div",{className:`${c} text-amber-400/90`,"data-testid":"job-row-held-reason",children:["held · ",a.heldReason]}),h&&t.jsx("div",{className:`${c} text-accent/80`,children:h}),!a.synthetic&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:[d&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:d.goalText,onClick:()=>l(d.id),className:`${p} text-accent hover:text-accent/80`,children:"view epic →"}),a.runId&&t.jsx("button",{type:"button",onClick:()=>o(!0),className:`${p} text-fg-dim hover:text-fg`,children:"view log →"}),a.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(a.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:`${p} text-accent hover:text-accent/80`,children:"adopt PRD →"}),a.status!=="pending"&&a.status!=="running"&&a.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(a.slug),className:`${p} text-fg-dim hover:text-fg`,children:"reset to pending →"}),a.disposition&&(a.status==="pending"||a.status==="quarantined")&&t.jsx(zt,{job:a,headChoices:n})]}),u&&a.runId&&t.jsx(Le,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>o(!1)})]})}const ce=190,kn=7,Sn=5,$n=[],Kt=e=>e==="completed"||e==="skipped",Yt=e=>e==="running"||e==="investigating",Xt=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Me(e){return Yt(e.status)?0:Xt(e.status)?1:Kt(e.status)?3:2}const Cn={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},Pn={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function Dn(e,s){return e.every(n=>Kt(n.status))?`+${e.length} done`:e.every(n=>n.rowKind==="dep"&&n.blockers.some(a=>!a.missing&&a.status!==null&&Xt(a.status)))?`+${e.length} blocked`:`+${e.length} in stage ${s}`}function An({stage:e,epicId:s,now:n,hidden:a,indexBySlug:u,headChoicesBySlug:o,onRowFocused:r}){const[i,d]=f.useState(!1),l=f.useMemo(()=>e.rows.filter(g=>!(a.has(g.slug)&&(g.status==="completed"||g.status==="failed"))).map((g,A)=>({r:g,i:A})).sort((g,A)=>Me(g.r)-Me(A.r)||g.i-A.i).map(g=>g.r),[e.rows,a]),c=f.useMemo(()=>l.filter(g=>Me(g)<=1).length,[l]),p=Math.max(e.state==="done"?Sn:kn,c),h=i?l:l.slice(0,p),w=i?[]:l.slice(p),x=l.find(g=>g.status==="failed"),m=l.find(g=>g.status==="needs_review"),j=c>0&&(x!==void 0||m!==void 0),_=h.reduce((g,A,k)=>Me(A)<=1?k:g,-1),N=g=>t.jsx(Jt,{row:g,elapsedMs:Yt(g.status)&&g.job.startedAt?n-Date.parse(g.job.startedAt):null,listIndex:u.get(g.slug)??0,onFocused:r,headChoices:o.get(g.slug)??$n},g.slug),I="flex-1 min-w-0 truncate h-[24px] text-[11.5px] font-medium text-fg-dim hover:text-fg border border-rule-structural rounded-sm bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"stage-column","data-stage":e.n,style:{width:ce},className:"shrink-0 border-l border-rule-structural first:border-l-0 flex flex-col self-stretch",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center gap-1.5 px-2 border-b border-rule-inner","data-testid":"stage-header",children:[t.jsx("span",{"aria-hidden":"true",className:`w-[7px] h-[7px] rounded-full shrink-0 ${Pn[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${Cn[e.state]}`,children:["Stage ",e.n]}),e.state==="blocked"&&t.jsx(ge,{title:"Rows in this stage are failed / need review / are quarantined, or wait on one that is."}),t.jsx("span",{"data-testid":"stage-summary",className:"ml-auto font-mono text-[10.5px] text-fg-dim truncate",children:e.summary})]}),t.jsx("div",{role:"presentation",children:h.map((g,A)=>t.jsxs("div",{children:[N(g),j&&A===_&&t.jsxs("div",{"data-testid":"stage-attention-actions",className:"flex gap-1.5 px-2 py-1.5 border-t border-rule-inner",children:[x&&t.jsxs("button",{type:"button","data-testid":"stage-retry",title:`Reset ${x.slug} to pending`,onClick:()=>{window.api.schedule.resetJob(x.slug).then(k=>{k.ok||H.error(k.error??`Failed to reset ${x.slug}`)}).catch(()=>H.error(`Failed to reset ${x.slug}`))},className:I,children:["Retry ",x.prdNumber?`#${x.prdNumber}`:x.slug]}),m&&t.jsxs("button",{type:"button","data-testid":"stage-review",disabled:!s,title:s?"Open the authoring Epic — a needs_review PRD is a question routed back to it":"No authoring Epic recorded for this plan",onClick:()=>{s&&Mt(s)},className:I,children:["Review ",m.prdNumber?`#${m.prdNumber}`:m.slug]})]})]},g.slug))}),(w.length>0||i&&l.length>p)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":i,onClick:()=>d(g=>!g),className:"mt-auto h-[26px] border-t border-rule-inner font-mono text-[11px] text-fg-faint hover:text-fg-dim bg-transparent cursor-pointer",children:i?"show less ▴":`${Dn(w,e.n)} ▾`})]})}const be=6,Ve=4,Ee=4,yt=12,Nt=5,Zt=2,kt=4,Mn={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function Rn(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function In(e){const s=[],n=[],a=[];let u=Nt;for(const o of e){const r=Math.max(1,Math.ceil(o.rows.length/Ee));n.push(u),a.push(r*be),o.rows.forEach((i,d)=>{s.push({x:u+Math.floor(d/Ee)*be,y:Zt+d%Ee*be,tone:Rn(i.status),title:`${i.prdNumber?`#${i.prdNumber}`:i.slug} ${i.title} — ${i.status}`})}),u+=r*be+yt}return{dots:s,stageX:n,stageW:a,width:Math.max(0,u-yt)+Nt}}function we(e,s){return e.findIndex(n=>n.rows.some(a=>s(a.status)))}const Je=e=>e==="running"||e==="investigating",Ke=e=>e==="failed"||e==="needs_review"||e==="quarantined";function En({stages:e,first:s,perView:n,onSeek:a}){const u=f.useMemo(()=>In(e),[e]),o=f.useMemo(()=>we(e,Je)>=0,[e]),r=f.useMemo(()=>we(e,Ke)>=0,[e]),i=f.useRef(!1),d=e.length,l=Math.min(d-1,s+n-1),c=u.stageX[Math.min(s,d-1)]??0,p=(u.stageX[l]??0)+(u.stageW[l]??0),h=x=>{const m=x.currentTarget.getBoundingClientRect(),j=x.clientX-m.left;let _=0;for(let N=0;N<d;N++)u.stageX[N]<=j&&(_=N);a(Math.max(0,Math.min(d-1,_-Math.floor(n/2))))},w="px-2 h-[20px] text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"plan-minimap",className:"h-[28px] flex items-center gap-3 px-3 border-t border-rule-inner",children:[t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Whole graph",t.jsx(ge,{title:"Every PRD in this plan as one dot, grouped by stage. The rust box is the range of stages shown below — drag it to scroll."})]}),t.jsxs("div",{"data-testid":"plan-minimap-dots",role:"presentation",className:"relative shrink min-w-0 overflow-hidden cursor-ew-resize touch-none",style:{width:u.width,height:Ee*be-(be-Ve)+2*Zt},onPointerDown:x=>{var m,j;i.current=!0,(j=(m=x.currentTarget).setPointerCapture)==null||j.call(m,x.pointerId),h(x)},onPointerMove:x=>{i.current&&h(x)},onPointerUp:()=>{i.current=!1},onPointerCancel:()=>{i.current=!1},children:[u.dots.map((x,m)=>t.jsx("span",{title:x.title,"data-tone":x.tone,className:`absolute rounded-[1px] ${Mn[x.tone]}`,style:{left:x.x,top:x.y,width:Ve,height:Ve}},m)),t.jsx("span",{"data-testid":"plan-minimap-brush","aria-hidden":"true",className:"absolute top-0 bottom-0 border border-accent bg-accent/10 rounded-[2px] pointer-events-none",style:{left:c-kt,width:p-c+2*kt}})]}),t.jsxs("span",{className:"ml-auto shrink-0 font-mono text-[11.5px] text-fg-faint","data-testid":"plan-minimap-range",children:["stages ",Math.min(s+1,d),"–",l+1," of ",d]}),t.jsxs("span",{className:"shrink-0 inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Jump the stage window",children:[t.jsx("button",{type:"button","data-testid":"minimap-running",disabled:!o,title:o?"Scroll to the lowest stage with a running PRD":"No stage has a running PRD",onClick:()=>a(we(e,Je)),className:`${w} text-fg-dim hover:text-fg`,children:"Running"}),t.jsx("button",{type:"button","data-testid":"minimap-blockers",disabled:!r,title:r?"Scroll to the lowest stage with a failed / needs-review / quarantined PRD":"No stage has a failed, needs-review or quarantined PRD",onClick:()=>a(we(e,Ke)),className:`${w} text-fg-dim hover:text-fg border-l border-line`,children:"Blockers"})]})]})}const Tn=148;function _n({stages:e,onSeek:s}){if(e.length===0)return null;const n=e[0].n,a=e[e.length-1].n;return t.jsxs("div",{"data-testid":"further-stages",style:{width:Tn},className:"shrink-0 border-l border-rule-structural flex flex-col",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center px-2 border-b border-rule-inner text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Stage ",n,"–",a]}),t.jsxs("div",{className:"h-[22px] shrink-0 flex items-center gap-1 px-2 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Further stages",t.jsx(ge,{title:"Stages beyond the visible window. Click one to scroll the stage columns to it."})]}),e.map(u=>{const o=u.rows.length===0?0:u.doneCount/u.rows.length*100;return t.jsxs("button",{type:"button","data-testid":"further-stage-row","data-stage":u.n,title:`${u.summary} — scroll to stage ${u.n}`,onClick:()=>s(u.n-1),className:"h-[26px] px-2 flex items-center gap-2 border-t border-rule-inner bg-transparent hover:bg-bg-hi cursor-pointer text-left",children:[t.jsxs("span",{className:"font-mono text-[10.5px] text-fg-dim w-[50px] whitespace-nowrap shrink-0",children:["stage ",u.n]}),t.jsx("span",{role:"progressbar","aria-valuenow":u.doneCount,"aria-valuemin":0,"aria-valuemax":u.rows.length,className:"flex-1 h-[4px] rounded-sm bg-rule-inner overflow-hidden",children:t.jsx("span",{className:"block h-full bg-sage",style:{width:`${o}%`}})})]},u.n)})]})}const On=[],Ln=e=>e==="running"||e==="investigating";function Fn(e){const s=Zs(e),n=new Map,a=new Map;for(const i of e.stages){a.set(i.n,i.rows.length);for(const d of i.rows)n.set(d.slug,d)}const u=new Map;let o=0;const r=[];for(const i of s){const d=n.get(i);o+=d.estimateMinutes??0,u.set(d.stage,(u.get(d.stage)??0)+1),r.push({row:d,totalMinutes:o,othersInStage:0})}for(const i of r)i.othersInStage=(a.get(i.row.stage)??0)-(u.get(i.row.stage)??0);return r}function qn({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:u}){const o=f.useMemo(()=>Fn(e),[e]);return t.jsx("div",{"data-testid":"critical-path",className:"border-t border-rule-structural max-w-[640px]",children:o.map(({row:r,totalMinutes:i,othersInStage:d})=>t.jsxs("div",{"data-testid":"critical-entry","data-slug":r.slug,children:[t.jsxs("div",{className:"flex items-start",children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(Jt,{row:r,elapsedMs:Ln(r.status)&&r.job.startedAt?s-Date.parse(r.job.startedAt):null,listIndex:n.get(r.slug)??0,onFocused:u,headChoices:a.get(r.slug)??On})}),t.jsxs("span",{"data-testid":"critical-est",className:"shrink-0 h-[31px] px-3 flex items-center gap-2 font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:[t.jsx("span",{title:"estimateMinutes",children:r.estimateMinutes?`${r.estimateMinutes}m`:"—"}),t.jsxs("span",{className:"text-fg-dim",title:"Running total along the chain",children:["Σ ",i,"m"]})]})]}),d>0&&t.jsxs("div",{"data-testid":"critical-others",className:"h-[22px] px-3 flex items-center font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:["stage ",r.stage," · +",d," not on the critical path"]})]},r.slug))})}const St=1,$t=1350,Bn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},Hn={active:{label:"ACTIVE",cls:"bg-accent text-white border border-accent"},queued:{label:"QUEUED",cls:"text-fg-dim border border-fg-faint"},done:{label:"DONE",cls:"text-sage-dark border border-sage"},draft:{label:"DRAFT",cls:"text-fg-faint border border-dashed border-fg-faint"}},Gn=e=>String(e).padStart(2,"0");function Un({plan:e}){const s=Math.max(1,e.prdCount),n=e.doneCount/s*100,a=e.runningCount/s*100;return t.jsxs("span",{"data-testid":"plan-progress",role:"progressbar","aria-valuenow":e.doneCount,"aria-valuemin":0,"aria-valuemax":e.prdCount,className:"flex w-[160px] h-[5px] rounded-sm overflow-hidden bg-rule-inner shrink-0",children:[t.jsx("span",{className:"h-full bg-sage",style:{width:`${n}%`}}),t.jsx("span",{className:"h-full bg-accent",style:{width:`${a}%`}})]})}function Vn({plan:e,mode:s="graph",now:n,hidden:a,indexBySlug:u,headChoicesBySlug:o,onRowFocused:r,onOpenPrds:i}){var q,L;const[d,l]=f.useState(e.status==="active"||e.status==="queued"),[c,p]=f.useState(!1),h=f.useRef(null),[w,x]=f.useState(0),[m,j]=f.useState($t),_=f.useMemo(()=>{const D=we(e.stages,Je);return D>=0?D:Math.max(0,we(e.stages,Ke))},[e.stages]);f.useLayoutEffect(()=>{if(!d)return;const D=h.current,E=(D==null?void 0:D.clientWidth)||$t,T=Math.max(0,Math.min(_,e.stageCount-Math.max(1,Math.ceil(E/ce))));D!=null&&D.clientWidth&&j(D.clientWidth),D&&(D.scrollLeft=T*ce),x(T)},[d]);const N=f.useMemo(()=>{let D=null;for(const E of e.stages)for(const T of E.rows){if(!T.job.runId)continue;const V=T.job.finishedAt?Date.parse(T.job.finishedAt):0;(!D||V>D.at)&&(D={runId:T.job.runId,slug:T.slug,title:T.title,at:V})}return D},[e.stages]),I=Te((L=(q=e.stages[0])==null?void 0:q.rows[0])==null?void 0:L.job.cwd)??"—",g=Hn[e.status],A=Math.max(1,Math.ceil(m/ce)),k=Math.max(0,Math.min(w-St,e.stageCount)),P=Math.min(e.stageCount,w+A+St),G=D=>{const E=Math.max(0,Math.min(e.stageCount-1,D));h.current&&(h.current.scrollLeft=E*ce),x(E)},z=Math.min(e.stageCount,w+A),Q=D=>{const E=D.currentTarget,T=Math.floor(E.scrollLeft/ce);T!==w&&x(T),E.clientWidth&&E.clientWidth!==m&&j(E.clientWidth)},Z="h-[24px] px-3 text-[12px] font-medium text-fg border border-rule-structural rounded-sm bg-transparent hover:bg-bg-hi cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed shrink-0",$=(()=>{switch(e.status){case"active":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Pauses the WHOLE scheduler (machine-wide) — there is no per-plan pause.",onClick:()=>{window.api.schedule.pause().catch(()=>H.error("Failed to pause the scheduler"))},className:Z,children:"Pause plan"});case"queued":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Fires the next scheduler batch machine-wide (force tick) — it does not target this plan.",onClick:()=>{window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire the next batch"))},className:Z,children:"Run now"});case"done":return t.jsx("button",{type:"button","data-testid":"plan-action",disabled:!N,title:N?`Open the run log of ${N.slug}, the plan's last run`:"No run log recorded for this plan",onClick:()=>p(!0),className:Z,children:"View run"});case"draft":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Open the PRDs sub-view on this plan's first PRD (the PRDs view has no per-Epic filter).",onClick:()=>{var D,E;return i==null?void 0:i(((E=(D=e.stages[0])==null?void 0:D.rows[0])==null?void 0:E.slug)??null)},className:Z,children:"Schedule…"})}})(),S=e.etaMs>0?` · ${Ht(e.etaMs)} left`:"";return t.jsxs("section",{"data-testid":"plan-band","data-epic-id":e.epicId??"","data-plan-status":e.status,className:`border-l-[3px] ${Bn[e.status]} border-b border-rule-structural`,children:[t.jsxs("div",{className:"h-[32px] flex items-center gap-2.5 px-3","data-testid":"plan-header",children:[t.jsx("button",{type:"button","aria-expanded":d,"aria-label":d?"Collapse plan":"Expand plan","data-testid":"plan-toggle",onClick:()=>l(D=>!D),className:"shrink-0 w-[14px] text-[11px] text-fg-faint hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:d?"▾":"▸"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint shrink-0",children:Gn(e.index)}),t.jsx("span",{className:"font-serif text-[15px] font-bold text-fg truncate shrink-0 max-w-[320px]",title:e.label,"data-testid":"plan-label",children:e.label}),t.jsx("span",{"data-testid":"plan-chip",className:`shrink-0 rounded-sm px-1.5 py-[1px] text-[10px] font-bold tracking-wide ${g.cls}`,children:g.label}),t.jsx("span",{"aria-hidden":"true",className:"shrink-0 w-px h-[16px] bg-rule-structural"}),t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-faint truncate min-w-0","data-testid":"plan-meta",children:[I," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.stageCount," stage",e.stageCount===1?"":"s"]}),t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-dim shrink-0","data-testid":"plan-step-count",children:[e.prdCount," step",e.prdCount===1?"":"s"," · ",e.doneCount," done"]}),t.jsx(ge,{title:`${e.doneCount} done · ${e.runningCount} running · ${e.heldCount} held · ${e.blockedCount} blocked`}),t.jsxs("span",{className:"ml-auto font-mono text-[11.5px] text-fg-dim shrink-0","data-testid":"plan-progress-label",children:[e.doneCount,"/",e.prdCount,S]}),t.jsx(Un,{plan:e}),$]}),d&&s==="critical"&&t.jsx(qn,{plan:e,now:n,indexBySlug:u,headChoicesBySlug:o,onRowFocused:r}),d&&s!=="critical"&&e.status==="active"&&t.jsx(En,{stages:e.stages,first:w,perView:A,onSeek:G}),d&&s!=="critical"&&t.jsxs("div",{className:"flex border-t border-rule-structural",children:[t.jsxs("div",{ref:h,"data-testid":"plan-stages",onScroll:Q,className:"flex flex-1 min-w-0 overflow-x-auto",children:[k>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:k*ce}}),e.stages.slice(k,P).map(D=>t.jsx(An,{stage:D,epicId:e.epicId,now:n,hidden:a,indexBySlug:u,headChoicesBySlug:o,onRowFocused:r},D.n)),P<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-P)*ce}})]}),t.jsx(_n,{stages:e.stages.slice(z),onSeek:G})]}),c&&N&&t.jsx(Le,{runId:N.runId,slug:N.slug,title:N.title||N.slug,onClose:()=>p(!1)})]})}function Wn({page:e,pageSize:s,totalItems:n,onPageChange:a}){if(n<=s)return null;const u=Math.max(1,Math.ceil(n/s)),o=(e-1)*s+1,r=Math.min(e*s,n);return t.jsxs("div",{"data-testid":"plan-pager",className:"flex items-center justify-center gap-3 px-[18px] py-3 font-mono text-[12px] text-fg-faint",children:[t.jsx("button",{type:"button","data-testid":"plan-pager-prev",onClick:()=>a(e-1),disabled:e<=1,className:"px-2 py-1 rounded border border-line bg-bg-hi text-fg-dim hover:text-fg disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:"Prev"}),t.jsxs("span",{"data-testid":"plan-pager-range",children:[o,"–",r," of ",n]}),t.jsx("button",{type:"button","data-testid":"plan-pager-next",onClick:()=>a(e+1),disabled:e>=u,className:"px-2 py-1 rounded border border-line bg-bg-hi text-fg-dim hover:text-fg disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:"Next"})]})}function Qn({section:e,children:s}){const[n,a]=f.useState(!0),u=Object.entries(e.counts).map(([o,r])=>`${r} ${o.replace(/_/g," ")}`).join(" · ");return t.jsxs("div",{className:"border-t border-line","data-testid":"backlog-epic-section","data-epic-id":e.epicId??"",children:[t.jsxs("button",{type:"button",onClick:()=>a(o=>!o),className:"w-full flex items-center gap-2.5 px-[18px] py-2.5 bg-bg-elev/60 hover:bg-bg-elev text-left","aria-expanded":n,title:e.label,children:[t.jsx("span",{className:`text-fg-faint inline-flex shrink-0 transition-transform duration-150 ${n?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(Xe,{name:"chevron",size:12})}),t.jsx("span",{className:"font-serif text-[14.5px] font-semibold text-fg truncate","data-testid":"backlog-epic-label",children:e.label}),t.jsxs("span",{className:"font-mono text-[11px] text-fg-faint shrink-0",children:[e.total," PRD",e.total===1?"":"s"]}),t.jsx("span",{className:"font-mono text-[11px] text-fg-faint truncate",children:u})]}),n&&s]})}const zn=[],Jn=[],Kn={depth:0,blockers:zn,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function Yn(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function Xn(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function Zn({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:u,onFocused:o,hold:r,backlog:i=Kn,headChoices:d=Jn}){const[l,c]=f.useState(!1),[p,h]=f.useState(!1),w=ue(P=>P.sessions),x=f.useMemo(()=>Ce(e,w),[e,w]),m=x.known&&x.epicId?w[x.epicId]:null,j=f.useCallback(P=>{Ze(P),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),_=e.status==="running",N=e.status==="failed";let I=null;_&&n!==null?I=`${xt(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?I=`took ${Se(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(I=s);const g=e.error??null,A=N&&g?g.split(`
4
- `)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,k=_&&n!==null?Math.min(.99,n/a):0;return t.jsxs("div",{role:"listitem",className:"border-t border-line",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":e.status,"data-job-index":u,"data-depth":i.depth,onClick:()=>c(P=>!P),onFocus:()=>o(u),style:i.depth>0?{paddingLeft:18+i.depth*20}:void 0,className:`w-full text-left grid grid-cols-[116px_1fr_auto_auto] items-center gap-4 px-[18px] py-3.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${l?"bg-bg-elev/40":""}`,"aria-expanded":l,"aria-label":`${re(e.slug)?`PRD ${re(e.slug)}, `:""}${e.title}, ${e.status}${I?`, ${I}`:""}`,title:e.title,children:[t.jsx(Rt,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug",children:[re(e.slug)&&t.jsx(It,{n:re(e.slug)}),e.title,t.jsx(Et,{leaked:e.leakedDescendants}),t.jsx(ys,{count:e.leftoverCount,truncated:e.leftoverPathsTruncated,salvagePatch:e.salvagePatch}),i.parallelEligible&&t.jsx("span",{"data-testid":"job-row-parallel-eligible",title:"No dependsOn, and nothing in this Epic depends on it — can run any time a slot is free",className:"text-[10px] font-semibold uppercase tracking-wide text-sage/90 bg-sage/10 border border-sage/30 rounded px-1.5 py-0.5",children:"parallel"})]}),i.cycle&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-accent font-mono","data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",i.blockers.map(P=>P.slug).join(" ↔ ")||"self-referencing"]}),!i.cycle&&i.blockers.length>0&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 font-mono","data-testid":"job-row-blockers",children:[t.jsx("span",{className:i.blocked||i.hasMissingDep?"text-amber-400/90":"text-fg-faint",children:i.blocked||i.hasMissingDep?"blocked by ":"depends on "}),i.blockers.map((P,G)=>t.jsxs("span",{className:Xn(P),children:[G>0&&", ",Yn(P)]},P.slug))]}),A&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${N?"text-accent/80":"text-fg-faint"}`,children:A}),r&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-hold",children:r.dep?t.jsxs(t.Fragment,{children:["held · waiting on ",r.dep," (",r.depStatus,")"]}):t.jsxs(t.Fragment,{children:["held · ",r.reason??"launch blocked"]})}),!r&&e.status==="pending"&&e.heldReason&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-held-reason",children:["held · ",e.heldReason]}),t.jsx(et,{epicId:x.epicId,label:x.label?Wt(x.label):null,onOpen:j,testId:"job-row-prompt-session-chip",className:"mt-0.5"})]}),t.jsx(tt,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint shrink-0",children:[t.jsx(Ns,{status:e.status,overrun:e.overrun}),I,t.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${l?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(Xe,{name:"chevron",size:14})})]})]}),_&&!l&&t.jsx("div",{className:"h-1 bg-line mx-[18px] mb-3 rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-accent transition-all duration-1000",style:{width:`${Math.max(4,k*100)}%`}})}),l&&t.jsxs("div",{className:"px-[18px] py-5 grid grid-cols-[repeat(auto-fit,minmax(160px,1fr))] gap-5 bg-bg-elev/50 border-t border-line",children:[t.jsxs(ae,{label:"Status",children:[t.jsx(B,{k:"result",v:e.exitCode!==null?`exit ${e.exitCode}`:"—"}),t.jsx(B,{k:"state",v:e.status.replace(/_/g," ")}),e.verifierVerdict&&t.jsx(B,{k:"verdict",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:Tt(e.leakedDescendants),wrap:!0}),e.leftoverCount!=null&&e.leftoverCount>0&&t.jsx(B,{k:"uncommitted",v:`${e.leftoverCount} file${e.leftoverCount===1?"":"s"}${e.leftoverPathsTruncated?"+":""}: ${(e.leftoverPaths??[]).join(", ")}${e.salvagePatch?` — salvaged to ${e.salvagePatch}`:""}`,wrap:!0}),g&&t.jsx(B,{k:"error",v:g.split(`
5
- `)[0],wrap:!0})]}),e.statusHistory&&e.statusHistory.length>0&&t.jsx(ae,{label:"History",children:t.jsx("div",{className:"grid gap-1",children:e.statusHistory.map((P,G)=>t.jsxs("div",{className:"font-mono text-xs leading-relaxed",children:[t.jsxs("div",{className:"text-fg",children:[P.from??"(new)"," → ",P.to,t.jsxs("span",{className:"text-fg-faint",children:[" · ",ie(Date.parse(P.at))]})]}),P.reason&&t.jsx("div",{className:"text-fg-faint break-words",children:P.reason})]},G))})}),t.jsxs(ae,{label:"Timing",children:[t.jsx(B,{k:"started",v:e.startedAt?ie(Date.parse(e.startedAt)):"—"}),t.jsx(B,{k:"finished",v:e.finishedAt?ie(Date.parse(e.finishedAt)):"—"}),t.jsx(B,{k:"duration",v:e.startedAt&&e.finishedAt?Se(Date.parse(e.finishedAt)-Date.parse(e.startedAt)):_&&n!==null?xt(n):"—"})]}),t.jsxs(ae,{label:"Location",children:[t.jsx(B,{k:"group",v:`${e.parallelGroup} · ${e.slug}`}),t.jsx(B,{k:"cwd",v:e.cwd??"—",wrap:!0}),t.jsx(B,{k:"session",v:x.label??x.epicId??"—",wrap:!0}),t.jsx(B,{k:"session id",v:x.epicId??"—",wrap:!0}),t.jsx(B,{k:"prompt id",v:e.sourcePromptId??"—",wrap:!0}),t.jsx(B,{k:"source tab",v:e.sourceTabId??"—",wrap:!0})]}),t.jsx(ae,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-1.5 items-start",children:[m&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:m.goalText,onClick:()=>j(m.id),className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"view epic →"}),e.runId&&t.jsx("button",{type:"button",onClick:()=>h(!0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"view log →"}),e.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(e.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"adopt PRD →"}),e.status!=="pending"&&e.status!=="running"&&e.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(e.slug),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"reset to pending →"}),e.disposition&&(e.status==="pending"||e.status==="quarantined")&&t.jsx(zt,{job:e,headChoices:d})]})})]}),p&&e.runId&&t.jsx(Le,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>h(!1)})]})}const ea=f.memo(Zn);function ta({supervisorConfig:e,onSetConfig:s,onBack:n}){const[a,u]=f.useState([]),[o,r]=f.useState(()=>Date.now()),i=Ye();f.useEffect(()=>{if(!i)return;window.api.supervisor.getLog().then(u).catch(()=>{}),r(Date.now());const l=setInterval(()=>r(Date.now()),5e3);return()=>clearInterval(l)},[i]);const d={enabled:(e==null?void 0:e.enabled)??!0,intervalMinutes:(e==null?void 0:e.intervalMinutes)??15,maxConcurrentProbes:(e==null?void 0:e.maxConcurrentProbes)??2,probeStaleThresholdMinutes:(e==null?void 0:e.probeStaleThresholdMinutes)??10};return t.jsxs("div",{className:"bg-bg-elev/60",children:[t.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 border-b border-line",children:[t.jsx("button",{type:"button",onClick:n,className:"text-[10px] text-fg-faint hover:text-fg-dim",title:"Back to queue",children:"← queue"}),t.jsx("span",{className:"text-[11px] font-medium text-fg-dim",children:"Supervisor"}),t.jsx("button",{type:"button",onClick:()=>window.api.supervisor.getLog().then(u).catch(()=>{}),className:"ml-auto text-[10px] text-fg-faint hover:text-fg-dim underline",title:"Refresh log",children:"refresh"})]}),t.jsxs("div",{className:"px-3 py-2 space-y-1.5 border-b border-line",children:[t.jsx("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider",children:"Config"}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap text-[10px] text-fg-faint",children:[t.jsxs("label",{className:"flex items-center gap-1",children:[t.jsx("input",{type:"checkbox",checked:d.enabled,onChange:l=>s({enabled:l.target.checked}),className:"cursor-pointer"}),t.jsx("span",{children:"enabled"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"How often to check for wedged jobs (minutes)",children:[t.jsx("span",{children:"interval"}),t.jsx("input",{type:"number",min:5,max:60,value:d.intervalMinutes,onChange:l=>s({intervalMinutes:Number(l.target.value)}),className:"w-10 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Max concurrent Opus probes per tick",children:[t.jsx("span",{children:"probes"}),t.jsx("input",{type:"number",min:1,max:5,value:d.maxConcurrentProbes,onChange:l=>s({maxConcurrentProbes:Number(l.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Probe a job only if no JSONL event in this many minutes",children:[t.jsx("span",{children:"stale"}),t.jsx("input",{type:"number",min:5,max:30,value:d.probeStaleThresholdMinutes,onChange:l=>s({probeStaleThresholdMinutes:Number(l.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]})]})]}),t.jsxs("div",{className:"px-3 py-2",children:[t.jsxs("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider mb-1",children:["Recent probes (last ",a.length,")"]}),a.length===0?t.jsx("div",{className:"text-[10px] text-fg-faint italic",children:"No probes yet."}):t.jsx("div",{className:"space-y-0.5 max-h-64 overflow-y-auto",children:a.map((l,c)=>t.jsx(sa,{entry:l,now:o},`${l.ts}-${c}`))})]})]})}function sa({entry:e,now:s}){const n=e.action!=="none",a=ee(s-e.ts);return t.jsxs("div",{className:`text-[10px] px-1.5 py-1 rounded font-mono ${n?"bg-red-500/10 border border-red-500/20":"bg-bg/40"}`,title:e.reason,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("span",{className:"text-fg-faint shrink-0",children:[a," ago"]}),t.jsx("span",{className:`shrink-0 px-1 rounded ${e.verdict==="stuck"?"text-red-400 bg-red-500/10":"text-green-500/70"}`,children:e.verdict}),t.jsx("span",{className:"truncate text-fg-dim",children:e.jobSlug}),n&&t.jsxs("span",{className:"shrink-0 text-red-400",children:[e.action,e.targetPid?` pid=${e.targetPid}`:""]}),e.costUsd!==null&&t.jsxs("span",{className:"shrink-0 text-fg-faint",children:["$",e.costUsd.toFixed(3)]})]}),t.jsx("div",{className:"text-fg-faint truncate mt-0.5",children:e.reason})]})}const na=[{title:"Start a session",body:"In Sessions, pick an Agent and a Mission, describe the outcome you want, then Approve & start. Its thread writes the PRD files into that session's own folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the session produced. Queue one, or the whole session, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],aa=[{term:"Session",def:"One goal, one Claude session, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the session."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and session chats."}];function ra({navigate:e}){return t.jsx("div",{className:"overflow-y-auto h-full",children:t.jsx("div",{className:"px-9 py-6 max-w-[900px] mx-auto",children:t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl px-9 py-8",children:[t.jsx("h2",{className:"m-0 font-serif text-[25px] font-semibold text-fg",children:"Nothing to run yet — the scheduler needs a session."}),t.jsx("p",{className:"mt-2 mb-6 text-[14.5px] text-fg-dim leading-relaxed max-w-[580px]",children:"You don't write PRDs here. A session breaks its goal into numbered PRD files, and this page runs them in order. Two steps, once."}),t.jsx("div",{className:"grid grid-cols-3 gap-3.5",children:na.map((s,n)=>{const a=n===0;return t.jsxs("div",{className:`bg-bg border rounded-xl px-4 py-4 flex flex-col gap-2 ${a?"border-accent shadow-[0_0_0_3px_rgba(184,92,52,.09)]":"border-line"}`,children:[t.jsx("span",{className:`w-6 h-6 rounded-full grid place-items-center font-mono text-[12px] font-semibold ${a?"bg-accent text-white":"bg-bg-elev text-fg-dim"}`,children:n+1}),t.jsx("h3",{className:"m-0 text-[15px] font-semibold text-fg",children:s.title}),t.jsx("p",{className:"m-0 text-[13.5px] text-fg-dim leading-relaxed",children:s.body}),a&&t.jsx("button",{type:"button",onClick:()=>e==null?void 0:e("terminal"),className:"self-start bg-accent text-white rounded-lg px-3.5 py-1.5 text-[13px] font-semibold mt-1",children:"Go to Sessions →"})]},s.title)})}),t.jsx("dl",{className:"flex mt-[22px] pt-4 border-t border-line gap-5 flex-wrap",children:aa.map(({term:s,def:n})=>t.jsxs("div",{className:"flex-1 min-w-[150px]",children:[t.jsx("dt",{className:"text-[13.5px] font-semibold text-fg mb-0.5",children:s}),t.jsx("dd",{className:"m-0 text-[12.5px] text-fg-faint leading-relaxed",children:n})]},s))})]})})})}const ia=5e3;let Re=null,ye=null;async function Ct(e){const s=Date.now();return!(e!=null&&e.fresh)&&Re&&s-Re.at<ia?Re.result:ye||(ye=(async()=>{try{const n=await window.api.schedule.lintQueue();return Re={result:n,at:Date.now()},n}finally{ye=null}})(),ye)}function la({health:e,jobCount:s,lastRunAt:n,nextReset:a,now:u,onOpenSupervisor:o}){const[r,i]=f.useState(!1),[d,l]=f.useState(null),[c,p]=f.useState(!1),h=`${s}:${n??""}`;f.useEffect(()=>{let k=!0;return p(!0),Ct().then(P=>{k&&l(P)}).catch(()=>{}).finally(()=>{k&&p(!1)}),()=>{k=!1}},[h]);let w=0,x=0;const m=d?d.reports.filter(k=>k.findings.length>0):[];for(const k of m)for(const P of k.findings)P.severity==="error"?w++:x++;const j=w===0&&x===0,_=d?`graph lint ${w} error${w===1?"":"s"}, ${x} warn${x===1?"":"s"}`:`graph lint ${c?"scanning…":"idle"}`,N=(e==null?void 0:e.consecutiveFailures)??0,g=[e?`${N} poll failure${N===1?"":"s"} in current streak`:null,_].filter(Boolean).join(" · "),A="text-accent hover:underline bg-transparent border-0 p-0 cursor-pointer text-[12px]";return t.jsxs("div",{"data-testid":"scheduler-footer",className:"border-t border-rule-structural",children:[t.jsxs("div",{className:"h-[28px] flex items-center gap-2 px-[18px] font-mono text-[11.5px] text-fg-faint",children:[t.jsx("span",{"data-testid":"footer-summary",className:"truncate",children:g}),t.jsx("button",{type:"button","data-testid":"footer-info","aria-expanded":r,onClick:()=>i(k=>!k),className:"bg-transparent border-0 p-0 cursor-pointer",children:t.jsx(ge,{title:"Scheduler poll health and queue-lint findings — click for the full detail"})}),t.jsxs("span",{className:"ml-auto flex items-center gap-3 shrink-0",children:[t.jsxs("span",{"data-testid":"footer-timing",children:[a?t.jsxs("span",{title:`next 5h reset: ${a}`,children:["reset ",ee(Date.parse(a)-u)]}):null,a&&n?" · ":null,n?t.jsxs("span",{title:n,children:["last run ",ee(u-Date.parse(n))," ago"]}):null]}),t.jsx("button",{type:"button","data-testid":"footer-supervisor",onClick:o,title:"Open supervisor log and settings",className:A,children:"supervisor"}),t.jsx("button",{type:"button","data-testid":"footer-folder",onClick:()=>window.api.schedule.openFolder(),className:A,children:"folder"})]})]}),r&&t.jsxs("div",{"data-testid":"footer-detail",className:"px-[18px] pb-2 space-y-2 font-mono text-[12px] text-fg-dim border-t border-rule-inner pt-2",children:[e&&t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{children:["booted: ",xe(e.bootedAt,u)]}),t.jsxs("div",{children:["last poll: ",xe(e.lastPollAt,u)," · ",e.lastPollOk?"ok":"failed"]}),e.backoffNextAt!==null&&e.backoffNextAt>u&&t.jsxs("div",{children:["retry in: ",ee(e.backoffNextAt-u)]}),e.nextResetCached&&t.jsxs("div",{children:["cached reset: ",ie(Date.parse(e.nextResetCached))]}),e.runningJobs.length>0&&t.jsxs("div",{children:["running: ",e.runningJobs.map(k=>`${k.slug}(pid ${k.pid})`).join(", ")]})]}),d&&t.jsxs("div",{className:"space-y-1",children:[j?t.jsxs("div",{className:"text-sage",children:["✓ no issues in ",d.reports.length," PRD",d.reports.length!==1?"s":""]}):m.map(k=>t.jsxs("div",{children:[t.jsx("div",{className:"text-fg-dim truncate",title:k.slug,children:k.slug}),k.findings.map((P,G)=>t.jsxs("div",{className:`pl-3 truncate ${P.severity==="error"?"text-accent/80":"text-butter/90"}`,title:P.snippet,children:[P.severity==="error"?"✗":"⚠"," L",P.line,": ",P.snippet]},`${k.slug}-${G}`))]},k.slug)),t.jsx("button",{type:"button","data-testid":"footer-rerun-lint",onClick:()=>{p(!0),Ct({fresh:!0}).then(l).catch(()=>{}).finally(()=>p(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:c?"…":"rerun lint"})]})]})]})}const oa=5,da=1440*60*1e3,Ie=10,ca=["all","running","investigating","pending","completed","skipped","needs_review","failed","quarantined"];async function ua(e){if(!e)return{text:"",status:"all"};const s=await _t(e);return{text:"",status:ca.includes(s.queueFilterStatus)?s.queueFilterStatus:"all"}}function pa(e,s){return e?Ot(e,{queueFilterStatus:s.status}):Promise.resolve()}function Pt(e,s){if(s.status==="all"&&!s.text)return e;const n=s.text.toLowerCase();return e.filter(a=>{if(s.status!=="all"&&a.status!==s.status)return!1;if(!n)return!0;const u=Te(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||u.toLowerCase().includes(n)})}async function fa(e){if(!e)return new Set;const s=await _t(e);return Array.isArray(s.hiddenCompletedSlugs)?new Set(s.hiddenCompletedSlugs.filter(n=>typeof n=="string")):new Set}function ha(e,s){return e?Ot(e,{hiddenCompletedSlugs:[...s]}):Promise.resolve()}function xa({scopeCwd:e=null,navigate:s,filterText:n,planMode:a="graph",onOpenPrds:u,planToolsEl:o=null}){var pt;const r=Oe(v=>v.snapshot),i=f.useMemo(()=>!r||!e?r:{...r,jobs:r.jobs.filter(v=>v.cwd===e)},[r,e]),[d,l]=f.useState(null),[c,p]=f.useState(()=>Date.now()),[h,w]=f.useState(new Set),[x,m]=f.useState(!1),[j,_]=f.useState({text:"",status:"all"}),N=f.useMemo(()=>n===void 0?j:{...j,text:n},[j,n]),[I,g]=f.useState(!1),[A,k]=f.useState("queue"),P=f.useRef(null),[G,z]=f.useState(0),[Q,Z]=f.useState(""),$=Ye(),S=f.useRef(!1),q=f.useRef(!1),L=f.useRef(h);L.current=h;const D=f.useRef(j);D.current=j,f.useEffect(()=>{let v=!1;return S.current=!1,q.current=!1,fa(e).then(M=>{!v&&!S.current&&w(M)}),ua(e).then(M=>{!v&&!q.current&&_(M)}),()=>{v=!0}},[e]),f.useEffect(()=>(window.api.schedule.health().then(l).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(l).catch(()=>{})})),[]),f.useEffect(()=>{if(!$)return;p(Date.now());const v=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(v)},[$]);const E=f.useMemo(()=>{if(!i)return 15e4;const v=[];for(const M of i.jobs)if(M.status==="completed"&&M.startedAt&&M.finishedAt){const U=Date.parse(M.finishedAt)-Date.parse(M.startedAt);U>0&&v.push(U)}return v.length===0?15e4:v.reduce((M,U)=>M+U,0)/v.length},[i]),T=f.useRef(new Map);f.useEffect(()=>{if(!i)return;const v=[];for(const M of i.jobs){const U=T.current.get(M.slug);U&&U!==M.status&&v.push(`${M.title}: ${U} → ${M.status}`),T.current.set(M.slug,M.status)}v.length>0&&Z(v.join("; "))},[i]);const V=f.useMemo(()=>{var M;const v=new Map;for(const U of((M=i==null?void 0:i.lastTick)==null?void 0:M.holds)??[])v.set(U.slug,U);return v},[i==null?void 0:i.lastTick]),Y=ue(v=>v.sessions),J=f.useMemo(()=>i?Ft(i.jobs,Y,r==null?void 0:r.jobs):[],[i,Y,r]),ne=ks(),b=f.useMemo(()=>i?Pt(gn(i.jobs,ne,e),N):[],[i,ne,e,N]),y=(pt=i==null?void 0:i.effectiveConcurrency)==null?void 0:pt.cap,R=f.useMemo(()=>a==="list"?[]:st(b,{sessions:Y,avgDurationMs:E,concurrency:y}),[a,b,Y,E,y]),[C,O]=f.useState(1),F=R.map(v=>`${v.epicId??""}#${v.waveIndex}`).join(",");f.useEffect(()=>{O(1)},[e,N.status,N.text,F]);const K=Math.max(1,Math.ceil(R.length/Ie)),Pe=Math.min(C,K),ts=f.useMemo(()=>R.slice((Pe-1)*Ie,Pe*Ie),[R,Pe]),ss=f.useMemo(()=>{const v=new Map;let M=0;for(const U of R)for(const W of U.stages)for(const se of W.rows)v.set(se.slug,M++);return v},[R]),ns=f.useMemo(()=>xn(J),[J]),as=h,nt=f.useCallback(v=>{var me;const M=(me=P.current)==null?void 0:me.querySelectorAll("[data-job-row]");if(!M||M.length===0)return;const U=Array.from(M),W=U.findIndex(te=>te.dataset.jobIndex===String(G)),se=te=>{const pe=U[te];if(!pe)return;const fe=Number(pe.dataset.jobIndex);z(fe),pe.focus()};v.key==="ArrowDown"?(v.preventDefault(),se(W===-1?0:Math.min(W+1,U.length-1))):v.key==="ArrowUp"&&(v.preventDefault(),se(W===-1?U.length-1:Math.max(W-1,0)))},[G]),at=f.useCallback(v=>{z(v)},[]),rt=f.useCallback(v=>{const M=D.current;q.current=!0,D.current=v,_(v),pa(e,v).catch(()=>{D.current===v&&(D.current=M,_(M),H.error("Couldn't save queue filter — reverted."))})},[e]),it=f.useCallback(v=>{const M=L.current;S.current=!0,L.current=v,w(v),ha(e,v).catch(()=>{L.current===v&&(L.current=M,w(M),H.error("Couldn't save hidden completed jobs — reverted."))})},[e]);if(!i)return null;if(A==="supervisor")return t.jsx(ta,{supervisorConfig:i.config.supervisor,onSetConfig:v=>window.api.schedule.setConfig({supervisor:v}),onBack:()=>k("queue")});const{jobs:X,paused:lt,lastRunAt:rs,nextReset:is,effectiveConcurrency:qe}=i;if(X.length===0)return t.jsx(ra,{navigate:s});const le={pending:0,running:0,investigating:0,completed:0,needs_review:0,failed:0};for(const v of X)v.status in le&&le[v.status]++;const Be=X.filter(v=>v.status==="running"),ls=Ut({snap:i,now:c,avgDurationMs:E,runningJobs:Be}),ve=Pt(X,N),os=ga(ve),{inline:De,collapsedCount:He}=ma(ve,h,c,x),ds=ba(De,X,os,E,ls.kind,c),ot=()=>{const v=new Set(h);for(const M of X)(M.status==="completed"||M.status==="failed")&&v.add(M.slug);it(v)},dt=async()=>{const v=X.filter(W=>W.status!=="running").length;if(v===0)return;const M=`Archive ${v} non-running PRD${v===1?"":"s"} and remove from the queue?
6
-
7
- Files are moved to prds-archived/<timestamp>/ and can be restored from disk. Running jobs are kept.`;if(!window.confirm(M))return;const U=await window.api.schedule.clearQueue();U.ok||H.error(`Clear queue failed: ${U.error??"unknown error"}`)},ct=()=>{it(new Set),m(!1)},ut=a==="list"?De.some(v=>v.status==="completed"):X.some(v=>(v.status==="completed"||v.status==="skipped")&&!h.has(v.slug)),cs=X.filter(v=>(v.status==="completed"||v.status==="failed")&&h.has(v.slug)).length,oe=a==="list",Ae=oe?"":"px-[18px] py-2";return t.jsxs("div",{className:"overflow-y-auto h-full",children:[t.jsx("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Q}),t.jsxs("div",{className:oe?"px-9 py-6 max-w-[1100px] mx-auto space-y-4":"",children:[d&&d.consecutiveFailures>5&&d.lastFailureKind==="meter_rate_limited"&&!lt&&!I&&t.jsx("div",{className:Ae,children:t.jsxs("div",{className:oe?"flex items-center gap-3 px-4 py-3 bg-amber-400/15 border border-amber-400/30 rounded-xl":"flex items-center gap-3 -mx-[18px] px-[18px] py-1 bg-amber-400/15 border-y border-amber-400/30",children:[t.jsx("span",{"aria-hidden":"true",children:"⚠"}),t.jsxs("span",{className:"text-[13.5px] text-amber-400/90",children:[t.jsx("strong",{className:"font-semibold",children:"Usage meter unavailable"})," — last good reading"," ",xe(d.lastPollAt,c),". Firing on a conservative estimate until it recovers."]}),t.jsx("button",{type:"button",onClick:()=>g(!0),className:"ml-auto text-[12px] text-amber-400/70 hover:text-amber-400 shrink-0",title:"Dismiss this banner. The scheduler continues firing normally.",children:"Dismiss"})]})}),oe&&Be.length>0&&(()=>{const v=(qe==null?void 0:qe.cap)??5,M=X.filter(U=>U.status==="pending").length;return t.jsxs("div",{className:`flex items-center gap-2 text-[12px] font-mono ${Ae}`,children:[t.jsxs("span",{className:"px-2 py-0.5 rounded bg-amber-400/20 text-amber-400 shrink-0",children:[Be.length,"/",v," running"]}),M>0&&t.jsxs("span",{className:"text-fg-faint",children:["+",M," ready in this group"]})]})})(),oe&&X.length>0&&t.jsx("div",{className:Ae,children:t.jsx(va,{showText:n===void 0,filter:N,onChange:rt})}),!oe&&t.jsxs("div",{"data-testid":"plan-graph",children:[o&&Ss.createPortal(t.jsx(wa,{jobCount:ve.length,counts:le,filter:N,onFilter:rt,hiddenInGraph:cs,onUnhideAll:ct,hasInlineCompleted:ut,onClearCompleted:ot,onClearQueue:dt,clearQueueDisabled:X.every(v=>v.status==="running")}),o),R.length===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:P,role:"list","aria-label":"Job queue",onKeyDown:nt,children:ts.map(v=>t.jsx(Vn,{plan:v,mode:a,now:c,hidden:as,indexBySlug:ss,headChoicesBySlug:ns,onRowFocused:at,onOpenPrds:u},`${v.epicId??"__none__"}#${v.waveIndex}`))}),t.jsx(Wn,{page:Pe,pageSize:Ie,totalItems:R.length,onPageChange:O})]}),oe&&t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-[18px] py-3 bg-bg-elev",children:[t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[ve.length," job",ve.length!==1?"s":""]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint",children:[le.pending,"p · ",le.running,"r · ",le.completed,"d",le.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",le.failed,"f"]})]}),ut&&t.jsx("button",{type:"button",onClick:ot,className:"text-[12.5px] text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer font-medium",title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:dt,disabled:X.every(v=>v.status==="running"),className:"text-[12px] text-accent border border-accent/40 hover:bg-accent/10 rounded-md px-2.5 py-1 cursor-pointer font-medium disabled:opacity-40 disabled:cursor-not-allowed",title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})]}),De.length===0&&He===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:P,role:"list","aria-label":"Job queue",onKeyDown:nt,children:(()=>{const v=new Set(De.map(W=>W.slug));let M=0;return J.map(W=>{const se=Qt(W),me=W.nodes.map(te=>{const pe=Fe([te]).filter(fe=>v.has(fe.row.slug)).map(fe=>({node:fe,listIndex:M++}));return{headRootSlug:te.row.slug,rows:pe}}).filter(te=>te.rows.length>0);return{section:W,heads:me,headChoices:se}}).filter(W=>W.heads.length>0).map(({section:W,heads:se,headChoices:me})=>t.jsx(Qn,{section:W,children:se.map(({headRootSlug:te,rows:pe},fe)=>t.jsxs("div",{"data-testid":"backlog-head-group",children:[se.length>1&&t.jsxs("div",{className:"px-[18px] pt-2.5 pb-1 text-[11px] font-mono uppercase tracking-wide text-fg-faint bg-bg-elev/30 border-t border-line/60","data-testid":"backlog-head-label",children:["Plan ",fe+1," of ",se.length]}),pe.map(({node:de,listIndex:us})=>t.jsx(ea,{job:de.row,backlog:de,eta:ds.get(de.row.slug)??null,elapsedMs:de.row.status==="running"&&de.row.startedAt?c-Date.parse(de.row.startedAt):null,avgDurationMs:E,listIndex:us,hold:V.get(de.row.slug),onFocused:at,headChoices:me.filter(ps=>ps.rootSlug!==te)},de.row.slug))]},te))},W.epicId??"__none__"))})()}),He>0&&t.jsxs("button",{type:"button",onClick:()=>m(v=>!v),className:"w-full text-left text-[12px] text-fg-faint hover:text-fg-dim px-[18px] py-3 border-t border-line",title:x?"Re-collapse old/cleared completed":"Show all completed (incl. cleared and >24h)",children:[x?"▾":"▸"," ",He," more completed",t.jsx("span",{className:"ml-1.5 font-mono text-[11.5px] text-fg-faint",children:"· fresh & capped at 5 shown inline"}),h.size>0&&t.jsx("span",{className:"ml-2 underline",onClick:v=>{v.stopPropagation(),ct()},children:"un-hide"})]})]}),oe&&!lt&&t.jsx("div",{className:Ae,children:t.jsxs("div",{className:"flex gap-2.5 bg-sage/10 border border-sage/30 rounded-xl px-3.5 py-2.5 text-[13.5px] text-fg-dim leading-relaxed",children:[t.jsx("span",{"aria-hidden":"true",children:"✓"}),t.jsxs("span",{children:[t.jsx("strong",{className:"font-semibold text-fg",children:"Nothing needed from you."})," ","Close the app if you like — jobs keep running, and History shows how each one ended."]})]})})]}),t.jsx(la,{health:d,jobCount:X.length,lastRunAt:rs,nextReset:is,now:c,onOpenSupervisor:()=>k("supervisor")})]})}function ga(e){const s=new Map(e.map(o=>[o.slug,o])),n=o=>(o.dependsOn??[]).filter(r=>{var i;return((i=s.get(r))==null?void 0:i.status)!=="completed"}).length,a=e.filter(o=>o.status==="running"||o.status==="pending").sort((o,r)=>n(o)-n(r)||o.slug.localeCompare(r.slug)),u=new Map;return a.forEach((o,r)=>u.set(o.slug,r)),u}function ma(e,s,n,a){if(a)return{inline:e,collapsedCount:0};const u=e.filter(l=>l.status==="completed").sort((l,c)=>{const p=l.finishedAt?Date.parse(l.finishedAt):0;return(c.finishedAt?Date.parse(c.finishedAt):0)-p}),o=new Set;let r=0;for(const l of u){if(r>=oa)break;s.has(l.slug)||l.finishedAt&&n-Date.parse(l.finishedAt)>da||(o.add(l.slug),r++)}const i=[];let d=0;for(const l of e){if(l.status==="failed"&&s.has(l.slug)){d++;continue}if(l.status!=="completed"){i.push(l);continue}o.has(l.slug)?i.push(l):d++}return{inline:i,collapsedCount:d}}function ba(e,s,n,a,u,o){const r=new Map;if(u==="paused"||u==="manual"||u==="auto-throttled"){for(const l of e)r.set(l.slug,null);return r}const i=s.find(l=>l.status==="running"&&l.startedAt),d=i!=null&&i.startedAt?o-Date.parse(i.startedAt):0;for(const l of e){if(l.status!=="pending"){r.set(l.slug,null);continue}const c=n.get(l.slug)??0;let p=c*a;c>0&&(p-=Math.min(a,d)),r.set(l.slug,p<=5e3?"~now":`~${Se(p)}`)}return r}const es=[{label:"All",value:"all"},{label:"Running",value:"running"},{label:"Investigating",value:"investigating"},{label:"Pending",value:"pending"},{label:"Completed",value:"completed"},{label:"Skipped",value:"skipped"},{label:"Needs review",value:"needs_review"},{label:"Failed",value:"failed"},{label:"Quarantined",value:"quarantined"}];function wa({jobCount:e,counts:s,filter:n,onFilter:a,hiddenInGraph:u,onUnhideAll:o,hasInlineCompleted:r,onClearCompleted:i,onClearQueue:d,clearQueueDisabled:l}){const c="block w-full text-left px-2 py-1 text-[12px] hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed bg-transparent border-0 cursor-pointer";return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-faint whitespace-nowrap","data-testid":"plan-tools-counts",children:[e," job",e!==1?"s":""," · ",s.pending,"p · ",s.running,"r · ",s.completed,"d",s.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",s.failed,"f"]})]}),u>0&&t.jsxs("button",{type:"button",onClick:o,className:"text-[12px] text-fg-faint hover:text-fg-dim underline bg-transparent border-0 cursor-pointer whitespace-nowrap",title:"Show the completed/failed jobs hidden by Clear completed",children:[u," hidden · un-hide"]}),t.jsx("select",{"data-testid":"scheduler-status-filter","aria-label":"Filter by status",value:n.status,onChange:p=>a({...n,status:p.target.value}),className:"bg-bg-hi border border-line rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"Filter the plan graph by job status",children:es.map(p=>t.jsx("option",{value:p.value,children:p.value==="all"?"all statuses":p.label.toLowerCase()},p.value))}),t.jsx(ge,{title:"Queue actions",testId:"plan-tools-menu",popoverTestId:"plan-tools-menu-popover",alignRight:!0,glyph:"⋯",widthCls:"w-52",children:t.jsxs("div",{className:"-mx-3 -my-2",children:[r&&t.jsx("button",{type:"button",onClick:i,className:`${c} text-fg-dim`,title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:d,disabled:l,className:`${c} text-accent`,title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})})]})}function va({filter:e,onChange:s,showText:n}){const a=es;return t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n&&t.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-[320px]",children:[t.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-faint inline-flex","aria-hidden":"true",children:t.jsx(Xe,{name:"search",size:15})}),t.jsx("input",{type:"text",value:e.text,onChange:u=>s({...e,text:u.target.value}),placeholder:"filter jobs…",className:"w-full bg-bg-hi border border-line rounded-xl py-2 pl-9 pr-3 text-[13.5px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint","aria-label":"Filter jobs by title, slug, or project"})]}),t.jsx(Vt,{options:a,value:e.status,onChange:u=>s({...e,status:u})})]})}new Set($s.map(e=>e.tag).filter(e=>e!=="discussion"));const ja=["title","cwd","estimateMinutes","parallelGroup","sourcePromptId","sourceTabId","tag","agentType","dependsOn","disposition","planId"];function ya(e,s){return!Array.isArray(e)||!Array.isArray(s)?!1:e.length===s.length&&e.every((n,a)=>n===s[a])}function Na(e){if(e==null)return"";if(typeof e=="boolean"||typeof e=="number")return String(e);const s=String(e);return s===""||/^(true|false|null|~)$/.test(s)||/^-?\d+(\.\d+)?$/.test(s)||/^\s|\s$/.test(s)||s.startsWith("'")||s.startsWith('"')||s.includes(`
8
- `)?s.includes("'")?`"${s.replace(/"/g,'\\"')}"`:`'${s}'`:s}function ka(e,s){var u;const n=[];for(const o of ja){const r=e[o];if(r==null||r===""||Array.isArray(r)&&r.length===0)continue;const i=(u=e._raw)==null?void 0:u[o];if(i&&(Array.isArray(r)?ya(i.parsed,r):i.parsed===r)){n.push(i.line);continue}if(typeof r=="number"){n.push(`${o}: ${r}`);continue}if(Array.isArray(r)){n.push(`${o}: [${r.join(", ")}]`);continue}n.push(`${o}: ${Na(r)}`)}if(e.extras)for(const o of Object.keys(e.extras)){const r=e.extras[o];!r||!r.lines.length||n.push(r.lines.join(`
9
- `))}return`---
10
- ${n.join(`
11
- `)}
12
- ---
13
- ${s}`}function We(e){return e.filter(s=>!s.archived)}function Sa(e){Ze(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Qe({label:e,tip:s,onClick:n,disabled:a,primary:u}){return t.jsx(Ds,{content:s,align:"bottom-center",children:t.jsx("button",{title:s,onClick:n,disabled:a,className:`px-2 py-0.5 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${u?"text-accent border-accent/50 hover:bg-bg-hi":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:e})})}function $a({scopeCwd:e=null}){const[s,n]=f.useState([]),[a,u]=f.useState(null),[o,r]=f.useState(null),[i,d]=f.useState(null),[l,c]=f.useState(!1),[p,h]=f.useState(!0),[w,x]=f.useState(new Set),[m,j]=f.useState(!1),[_,N]=f.useState(!1),[I,g]=f.useState(!1),[A,k]=f.useState(null);f.useEffect(()=>{let b=!0;return window.api.schedule.listPrds().then(y=>{b&&(n(We(y)),h(!1))}).catch(y=>{b&&(h(!1),H.error(`Scheduler: failed to load PRD list — ${y instanceof Error?y.message:"unknown error"}`))}),()=>{b=!1}},[]);const P=Oe(b=>b.snapshot),G=ue(b=>b.sessions);f.useEffect(()=>{P&&u(P)},[P]);const z=f.useMemo(()=>[...s].filter(b=>!e||b.cwd===e).sort((b,y)=>y.mtimeMs-b.mtimeMs||b.slug.localeCompare(y.slug)),[s,e]);f.useEffect(()=>{const b=Ps();b&&r(b);const y=R=>r(R.detail);return window.addEventListener("sm:select-prd",y),()=>window.removeEventListener("sm:select-prd",y)},[]);const Q=f.useMemo(()=>(a==null?void 0:a.jobs.find(b=>b.slug===o))??null,[a,o]),Z=gt(Q);function $(b){var R;const y=(R=s.find(C=>C.slug===b))==null?void 0:R.cwd;return y?`${y}/session-manager-operations/scheduler/prds/${b}.md`:null}f.useEffect(()=>{if(!o)return;const b=$(o);b&&mt.getState().openFile(b)},[o,s]);function S(b){r(b),d(null),c(!1)}function q(){r(null)}async function L(){if(!o)return;if(!(Q!=null&&Q.runId)){d("no log available (job has not run yet)"),c(y=>!y);return}const b=await window.api.schedule.readLog(Q.runId,o);d(b.ok?b.text??"":`error: ${b.error}`),c(y=>!y)}if(p)return t.jsx(Ne,{title:"loading PRDs…"});const D=b=>{x(y=>{const R=new Set(y);return R.has(b)?R.delete(b):R.add(b),R})};!(z.length>0&&z.every(b=>w.has(b.slug)))&&z.some(b=>w.has(b.slug));const T=()=>x(new Set);async function V(){try{const b=await window.api.schedule.listPrds();n(We(b))}catch{}}async function Y(){const b=`new-prd-${Date.now()}`,y=ka({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
14
-
15
- Describe the task here.
16
- `);try{const R=await window.api.schedule.writePrd(b,y);if(!R.ok){H.error(`Failed to create PRD: ${R.error}`);return}const C=await window.api.schedule.listPrds();n(We(C)),S(b)}catch(R){H.error(`Failed to create PRD: ${R instanceof Error?R.message:String(R)}`)}}async function J(){var b;g(!0),k(null);try{const y=[...w],R=await window.api.schedule.archivePrds(y);if(!R.ok)k(R.error??"archive failed");else{const C=((b=R.results)==null?void 0:b.filter(O=>!O.ok))??[];C.length>0&&H.warn(`Archive: ${C.length} of ${R.results.length} PRD${C.length===1?"":"s"} failed to move`),T(),j(!1),await V()}}catch(y){k(y instanceof Error?y.message:String(y))}finally{g(!1)}}async function ne(b,y){g(!0),k(null);try{const R=[];for(const O of w){const F={slug:O};b!==null&&(F.parallelGroup=b),y!==null&&(F.estimateMinutes=y),R.push(F)}const C=await window.api.schedule.retagPrds(R);if(!C.ok)k(C.error??"retag failed");else{T(),N(!1),await V();for(const O of C.results)if(O.newSlug&&O.newSlug!==O.slug){const F=$(O.slug),K=$(O.newSlug);F&&K&&mt.getState().renameOpenFile(F,K)}o&&C.results.some(O=>O.slug===o&&O.newSlug&&O.newSlug!==O.slug)&&r(null)}}catch(R){k(R instanceof Error?R.message:String(R))}finally{g(!1)}}return t.jsxs(t.Fragment,{children:[o?t.jsxs("div",{className:"h-full flex flex-col min-h-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line flex-wrap shrink-0",children:[t.jsx("button",{type:"button",onClick:q,className:"text-[11px] text-fg-faint hover:text-fg",children:"← PRDs"}),t.jsx("span",{className:"font-mono text-xs text-fg-dim truncate",children:o}),t.jsx(bt,{status:Z}),t.jsx("div",{className:"flex-1"}),t.jsx(Qe,{label:"Reset",tip:"Reset failed job to pending",onClick:()=>{window.api.schedule.resetJob(o)},disabled:Z!=="failed"}),t.jsx(Qe,{label:"Run now",tip:"Run all pending jobs immediately",onClick:()=>{window.api.schedule.runNow()}}),t.jsx(Qe,{label:l?"Hide log":"Last run log",tip:"Toggle most recent run log",onClick:L})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(Cs,{})}),l&&i!==null&&t.jsxs("div",{className:"border-t border-line max-h-64 overflow-auto bg-bg-elev",children:[t.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 border-b border-line sticky top-0 bg-bg-elev",children:[t.jsxs("span",{className:"text-[10px] text-fg-faint font-mono",children:["run log",Q!=null&&Q.runId?` — ${Q.runId}`:""]}),t.jsx("button",{onClick:()=>c(!1),className:"ml-auto text-[10px] text-fg-faint hover:text-fg",children:"close"})]}),t.jsx("pre",{className:"p-3 text-[11px] font-mono text-fg-dim whitespace-pre-wrap",children:i})]})]}):t.jsxs("div",{className:"px-6 py-5 overflow-auto",children:[t.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4",children:[t.jsxs("p",{className:"text-[14px] text-fg-dim leading-relaxed max-w-[560px]",children:["PRDs are the source the scheduler runs from. Each one becomes a"," ",t.jsx("code",{className:"font-mono text-[13px]",children:"claude -p"})," job when you queue it. This is where you write and edit the source — to watch a run in progress, use the Queue tab."]}),t.jsx("button",{type:"button",onClick:Y,className:"shrink-0 bg-accent text-white rounded-lg px-4 py-[9px] text-[13.5px] font-semibold leading-none",children:"+ New PRD"})]}),w.size>0&&t.jsxs("div",{className:"mb-4 px-4 py-2 bg-bg border border-line rounded-lg flex items-center gap-2",children:[t.jsxs("span",{className:"text-xs text-fg-dim",children:[w.size," selected"]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{type:"button",onClick:()=>j(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Archive…"}),t.jsx("button",{type:"button",onClick:()=>N(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Retag…"}),t.jsx("button",{type:"button",onClick:T,className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Clear"})]}),z.length===0?t.jsx(Ne,{title:"no PRDs found"}):t.jsx("div",{className:"grid gap-3",children:z.map(b=>{const y=a==null?void 0:a.jobs.find(K=>K.slug===b.slug),R=gt(y),C=Ce({epicId:b.epicId??(y==null?void 0:y.epicId)??null,sourcePromptId:b.sourcePromptId??(y==null?void 0:y.sourcePromptId)??null,sourceTabId:(y==null?void 0:y.sourceTabId)??null},G),O=(y==null?void 0:y.status)==="running",F=(y==null?void 0:y.status)==="needs_review";return t.jsxs("div",{className:"flex items-stretch bg-bg-elev border border-line rounded-2xl overflow-hidden",children:[t.jsx("label",{className:"flex items-center px-3 cursor-pointer hover:bg-bg-hi",children:t.jsx("input",{type:"checkbox",checked:w.has(b.slug),onChange:()=>D(b.slug),className:"accent-accent w-3.5 h-3.5"})}),t.jsxs("div",{className:"flex-1 min-w-0 py-4 pr-2",children:[t.jsxs("div",{className:"flex items-center gap-2.5 mb-[5px] flex-wrap",children:[re(b.slug)&&t.jsx(It,{n:re(b.slug)}),t.jsx("button",{type:"button",onClick:()=>S(b.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:b.title||b.slug}),t.jsx(bt,{status:R}),(y==null?void 0:y.status)&&t.jsx("span",{className:"sr-only",children:y.status})]}),t.jsxs("div",{className:"flex items-center gap-4 font-mono text-xs text-fg-faint flex-wrap",children:[t.jsx(tt,{cwd:b.cwd}),t.jsx(et,{epicId:C.epicId,label:C.label,onOpen:Sa}),b.estimateMinutes!=null&&t.jsxs("span",{children:[b.estimateMinutes,"m"]}),t.jsxs("span",{className:"opacity-60",title:"parallelGroup — a unique-per-PRD display hint, never an ordering barrier. dependsOn is the real ordering primitive.",children:["g",b.parallelGroup]}),b.dependsOn&&b.dependsOn.length>0&&t.jsxs("span",{title:`depends on: ${b.dependsOn.join(", ")}`,children:["⛓ ",b.dependsOn.length," dep",b.dependsOn.length===1?"":"s"]}),t.jsxs("span",{children:["edited ",xe(b.mtimeMs,Date.now())]})]}),t.jsx("button",{type:"button",onClick:()=>S(b.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:b.slug}),F&&t.jsxs("div",{className:"mt-3 space-y-2",children:[(y==null?void 0:y.verifierVerdict)&&t.jsxs("div",{className:"text-xs text-fg-faint",children:["verdict: ",t.jsx("span",{className:"font-mono",children:$e(y.verifierVerdict)})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(b.slug),className:"text-xs px-2.5 py-1 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Re-fire"})]})]}),t.jsx("div",{className:"flex flex-col gap-2 items-stretch px-[18px] py-4",children:t.jsx("button",{type:"button",onClick:()=>window.api.schedule.runNow(),disabled:O,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:O?"Running…":"Queue job"})})]},b.slug)})})]}),t.jsx(Ca,{open:m,count:w.size,busy:I,onClose:()=>j(!1),onConfirm:J}),t.jsx(Pa,{open:_,count:w.size,busy:I,onClose:()=>N(!1),onConfirm:ne})]})}function Ca({open:e,count:s,busy:n,onClose:a,onConfirm:u}){return t.jsxs(Lt,{open:e,onClose:a,title:"Archive PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Move ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s"," to"," ",t.jsx("span",{className:"font-mono",children:"prds-archived/<timestamp>/"}),"?"]}),t.jsx("p",{className:"text-[10px] text-fg-faint mt-2",children:"Files are renamed, never deleted. Restore manually from disk if needed."}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:u,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function Pa({open:e,count:s,busy:n,onClose:a,onConfirm:u}){const[o,r]=f.useState(""),[i,d]=f.useState(""),[l,c]=f.useState(null);f.useEffect(()=>{e&&(r(""),d(""),c(null))},[e]);function p(){c(null);let h=null,w=null;if(o.trim()){const x=Number(o);if(!Number.isInteger(x)||x<0||x>999){c("parallelGroup must be 0–999");return}h=x}if(i.trim()){const x=Number(i);if(!Number.isInteger(x)||x<=0){c("estimateMinutes must be a positive integer");return}w=x}if(h===null&&w===null){c("set at least one field");return}u(h,w)}return t.jsxs(Lt,{open:e,onClose:a,title:"Retag PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Update ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s",". Leave a field blank to keep its current value."]}),t.jsxs("p",{className:"text-[10px] text-fg-faint mt-2",children:["Changing parallelGroup on an ",t.jsx("span",{className:"font-mono",children:"NN-kebab"})," slug renames the file. Every change is logged to ",t.jsx("span",{className:"font-mono",children:"retag-log.jsonl"})," so it's reversible."]}),t.jsxs("div",{className:"mt-3 space-y-2",children:[t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"parallelGroup:"}),t.jsx("input",{type:"number",min:0,max:999,value:o,onChange:h=>r(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]}),t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"estimateMinutes:"}),t.jsx("input",{type:"number",min:1,value:i,onChange:h=>d(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]})]}),l&&t.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:l}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:p,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Retagging…":`Retag ${s}`})]})]})}function Da(e){Ze(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Dt(e){return e?e.slice(0,10):""}const Aa=[{value:"all",label:"All"},{value:"completed",label:"Completed"},{value:"skipped",label:"Skipped"},{value:"failed",label:"Failed"}];function Ma({scopeCwd:e=null}){const[s,n]=f.useState(null),[a,u]=f.useState(!0),[o,r]=f.useState(""),[i,d]=f.useState(""),[l,c]=f.useState(""),[p,h]=f.useState("all");f.useEffect(()=>{u(!0),window.api.schedule.getHistory().then(j=>n(j)).catch(j=>n({ok:!1,jobs:[],error:j instanceof Error?j.message:String(j)})).finally(()=>u(!1))},[]);const w=f.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const j=new Set;for(const _ of s.jobs){const N=Te(_.cwd);N&&j.add(N)}return[...j].sort()},[s]),x=f.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(j=>!(e&&j.cwd!==e||p!=="all"&&j.status!==p||o&&Te(j.cwd)!==o||i&&Dt(j.finishedAt)<i||l&&Dt(j.finishedAt)>l)):[],[s,p,o,i,l,e]);if(a)return t.jsx(Ne,{title:"Loading history…"});if(!(s!=null&&s.ok)||s.error)return t.jsxs("div",{className:"p-4 text-xs text-red-300",children:["Failed to load history: ",(s==null?void 0:s.error)??"unknown error"]});if(s.jobs.length===0)return t.jsx(Ne,{title:"No history yet",hint:"Completed and failed jobs appear here."});const m=p!=="all"||!!o||!!i||!!l;return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-line flex-wrap",children:[t.jsx(Vt,{options:Aa,value:p,onChange:h,pillPadding:"px-3 py-1"}),t.jsx("span",{className:"w-px h-4 bg-line mx-1","aria-hidden":"true"}),w.length>0&&t.jsxs("select",{value:o,onChange:j=>r(j.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-[12.5px] text-fg-dim max-w-[12rem] font-medium",children:[t.jsx("option",{value:"",children:"All projects"}),w.map(j=>t.jsx("option",{value:j,children:j},j))]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"from"}),t.jsx("input",{type:"date",value:i,onChange:j=>d(j.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"to"}),t.jsx("input",{type:"date",value:l,onChange:j=>c(j.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("span",{className:"text-[12px] text-fg-faint ml-auto font-mono",children:[x.length," / ",s.jobs.length]}),m&&t.jsx("button",{type:"button",onClick:()=>{h("all"),r(""),d(""),c("")},className:"text-[12px] text-fg-faint hover:text-fg-dim underline",children:"clear"})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:x.length===0?t.jsx(Ne,{title:"No matches",hint:"Try adjusting the filters."}):t.jsxs("div",{className:"mx-4 my-3 bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsx("div",{className:"flex items-center px-[18px] py-3 bg-bg-elev",children:t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[x.length," job",x.length!==1?"s":""]})}),x.map(j=>t.jsx(Ra,{job:j},`${j.slug}-${j.finishedAt??""}`))]})})]})}function Ra({job:e}){const[s,n]=f.useState(!1),[a,u]=f.useState(!1),o=ue(h=>h.sessions),r=f.useMemo(()=>Ce(e,o),[e,o]),i=e.startedAt&&e.finishedAt?Date.parse(e.finishedAt)-Date.parse(e.startedAt):null,d=e.startedAt?new Date(e.startedAt).toLocaleString():"—",l=e.finishedAt?new Date(e.finishedAt).toLocaleString():"—",c=i!==null?Se(i):"—",p=e.exitCode!==null?String(e.exitCode):"—";return t.jsxs("div",{className:"border-t border-line/60",children:[t.jsxs("button",{type:"button",className:`w-full text-left grid items-center gap-4 px-[18px] py-3.5 cursor-pointer transition-colors hover:bg-bg-elev ${s?"bg-bg-elev":"bg-transparent"}`,style:{gridTemplateColumns:"116px 1fr auto auto"},onClick:()=>n(h=>!h),"aria-expanded":s,children:[t.jsx(Rt,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug text-pretty",children:[e.title,t.jsx(Et,{leaked:e.leakedDescendants})]}),e.error&&!s&&(e.status==="failed"||e.status==="needs_review")&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-accent/80 truncate",children:e.error}),r.epicId&&t.jsx("span",{className:"flex mt-0.5",children:t.jsx(et,{epicId:r.epicId,label:r.label,onOpen:Da})})]}),t.jsx(tt,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint whitespace-nowrap",children:[c,t.jsx("span",{className:"inline-flex transition-transform duration-150",style:{transform:s?"rotate(90deg)":"none"},"aria-hidden":"true",children:"›"})]})]}),s&&t.jsxs("div",{className:"grid gap-5 px-[18px] pt-1 pb-5 bg-bg-elev",style:{gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))"},children:[t.jsxs(ae,{label:"Status",children:[t.jsx(B,{k:"result",v:p}),t.jsx(B,{k:"state",v:e.status.replace("_"," ")}),e.verifierVerdict&&t.jsx(B,{k:"verifier",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:Tt(e.leakedDescendants),wrap:!0})]}),t.jsxs(ae,{label:"Timing",children:[t.jsx(B,{k:"started",v:d}),t.jsx(B,{k:"finished",v:l}),t.jsx(B,{k:"duration",v:c})]}),t.jsxs(ae,{label:"Location",children:[t.jsx(B,{k:"group",v:e.parallelGroup!=null?String(e.parallelGroup):"—"}),t.jsx(B,{k:"slug",v:e.slug}),t.jsx(B,{k:"epic",v:r.label??r.epicId??"—",wrap:!0}),e.cwd&&t.jsx(B,{k:"cwd",v:e.cwd,wrap:!0})]}),t.jsx(ae,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[e.runId&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),u(!0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"view log →"}),e.status!=="pending"&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),window.api.schedule.resetJob(e.slug)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"reset to pending →"}),e.error&&t.jsx("p",{className:"text-[12px] text-accent/90 mt-1 break-words whitespace-pre-wrap max-w-sm m-0",children:e.error})]})})]}),a&&e.runId&&t.jsx(Le,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>u(!1)})]})}function Ia(e){return e?Object.values(e).reduce((s,n)=>s+(n??[]).reduce((a,u)=>{var o;return a+(((o=u.hooks)==null?void 0:o.length)??0)},0),0):0}function Ea(e){var s,n,a;return e?(((s=e.allow)==null?void 0:s.length)??0)+(((n=e.deny)==null?void 0:n.length)??0)+(((a=e.ask)==null?void 0:a.length)??0):0}function Ta({navigate:e}){const s=As(),n=je(g=>g.files),a=je(g=>g.loadJson),u=je(g=>g.loadText),o=je(g=>g.watchFile),r=je(g=>g.unwatchFile),i=s?Ms.resolve("user",s,null):null,d=s?Rs.resolve("user",s,null):null,l=s?`${s}/.claude.json`:null;f.useEffect(()=>{const g=[i,l].filter(Boolean);g.forEach(k=>{n[k]||a(k),o(k)});const A=[d].filter(Boolean);return A.forEach(k=>{n[k]||u(k),o(k)}),()=>{[...g,...A].forEach(k=>r(k))}},[i,d,l]);const[c,p]=f.useState(null);f.useEffect(()=>{if(!s)return;let g=!1;return(async()=>{const A=await Ls(`${s}/.claude/skills`);g||p(A.length)})(),()=>{g=!0}},[s]);const h=i?n[i]:null,w=l?n[l]:null,x=d?n[d]:null,m=f.useMemo(()=>{if(!(h!=null&&h.exists)||h.parseError)return null;const g=h.diskData;return g===null||typeof g!="object"||Array.isArray(g)?{}:g},[h]),j=f.useMemo(()=>{if(!(w!=null&&w.exists)||w.parseError)return null;const g=w.diskData;return g===null||typeof g!="object"||Array.isArray(g)?{}:g},[w]),_=h?h.parseError?"invalid JSON":null:"loading…",N=w?w.parseError?"invalid JSON":null:"loading…",I=[{key:"settings",title:"Settings",summary:_??(m?`${Object.keys(m).length} top-level key${Object.keys(m).length===1?"":"s"} configured`:"not configured")},{key:"permissions",title:"Permissions",summary:_??(m?`${Ea(m.permissions)} rule(s) configured`:"not configured")},{key:"hooks",title:"Hooks",summary:_??(m?`${Ia(m.hooks)} hook(s) configured`:"not configured")},{key:"mcp",title:"MCP Servers",summary:N??(j?`${Object.keys(j.mcpServers??{}).length} MCP server(s)`:"not configured")},{key:"system-prompt",title:"System Prompt",summary:x!=null&&x.exists&&x.diskRaw.trim().length>0?`configured (${x.diskRaw.length.toLocaleString()} chars)`:"not set"},{key:"skills",title:"Skills",summary:c===null?"loading…":`${c} skill(s) installed`}];return t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Global Controls"}),t.jsx("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:"Machine-wide (user-scope) config state for the tabs that default to global here on Home. Read-only summary — open a card to edit."}),t.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:I.map(g=>t.jsxs("button",{type:"button",onClick:()=>e==null?void 0:e(g.key),className:"text-left border border-line rounded-lg bg-bg px-3 py-2.5 hover:border-accent transition-colors",children:[t.jsx("div",{className:"text-[13px] font-medium text-fg",children:g.title}),t.jsx("div",{className:"mt-0.5 text-[12px] text-fg-dim",children:g.summary})]},g.key))})]})}function _a({navigate:e}){const s=Is(),[n,a]=f.useState(!1),[u,o]=f.useState(!1),[r,i]=f.useState(null);f.useEffect(()=>{let l=!0;return Es().then(c=>{l&&a(c.openToHomeOnLaunch===!0)}),()=>{l=!1}},[]),f.useEffect(()=>{var c,p;let l=!0;return(p=(c=window.api.schedule).worktreeBase)==null||p.call(c).then(h=>{l&&i(h)}).catch(()=>{}),()=>{l=!1}},[]);const d=async l=>{a(l),o(!0);try{await _s({openToHomeOnLaunch:l})}catch{a(!l),H.error('Failed to save "Open to Home on launch" — try again.')}finally{o(!1)}};return t.jsxs("div",{className:"max-w-[760px] space-y-6",children:[t.jsx(Ta,{navigate:e}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Session pool"}),t.jsxs("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:["One machine-wide pool of concurrent Claude sessions. Scheduler jobs and Epic chat runs each request a slot before launching; work waits when the pool is full. Adjustable from 0 (pauses new launches) to 10 on the Home tab, default 5 — or pin it with"," ",t.jsx("code",{className:"font-mono text-[12px]",children:"SM_SESSION_SLOTS"})," (clamped 0–10)."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ts,{total:(s==null?void 0:s.total)??5,inUse:(s==null?void 0:s.inUse)??0,size:"md"}),t.jsx("span",{className:"ml-2 font-mono text-[12.5px] text-fg-faint",children:s?`${s.inUse} / ${s.total} in use`:"loading…"})]}),s&&s.holders.length>0&&t.jsx("ul",{className:"mt-2 mb-0 pl-0 list-none space-y-0.5",children:s.holders.map((l,c)=>t.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[l.owner," ",t.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(l.at).toLocaleTimeString()]})]},c))})]}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Behavior"}),t.jsx("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:"Cross-project app behavior, independent of any single project's config."}),t.jsx(Fs,{checked:n,onChange:d,disabled:u,label:"Open to Home on launch"})]}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"On disk"}),t.jsxs("p",{className:"mt-0 mb-2 text-[13px] text-fg-dim leading-relaxed",children:["Global runtime state is deliberately small — everything project-scoped lives inside that project's ",t.jsx("code",{className:"font-mono text-[12px]",children:"session-manager-operations/"})," folder."]}),t.jsxs("ul",{className:"m-0 pl-0 list-none space-y-1 font-mono text-[12px] text-fg-dim",children:[t.jsxs("li",{children:["~/.claude/session-manager/scheduler-machine.json ",t.jsx("span",{className:"text-fg-faint",children:"— policy + pause state"})]}),t.jsxs("li",{"data-testid":"worktree-base-path",children:[r??"…","/session-manager-epic-worktrees/ ",t.jsx("span",{className:"text-fg-faint",children:"— Epic git worktrees (SM_WORKTREE_ROOT overrides)"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/state/ ",t.jsx("span",{className:"text-fg-faint",children:"— per-project queue + history"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/epics/<epic>/prds/ ",t.jsx("span",{className:"text-fg-faint",children:"— PRD sources, per session"})]})]})]})]})}const At="sm.schedulerTab.subView";function Oa({navigate:e}={}){var x;const[s,n]=f.useState("graph"),[a,u]=f.useState(""),[o,r]=f.useState(null),[i,d]=f.useState(()=>{const m=localStorage.getItem(At);return m==="prds"||m==="history"||m==="machine"?m:"queue"}),l=wt(m=>m.tabs),c=wt(m=>m.activeTabId),p=((x=l.find(m=>m.id===c))==null?void 0:x.cwd)??null,h=p;f.useEffect(()=>{p&&(ue.getState().hydrate(p),ue.getState().hydrateArchived(p))},[p]);const w=f.useCallback(m=>{m&&Os(m),d("prds")},[]);return f.useEffect(()=>{localStorage.setItem(At,i)},[i]),t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsx(fn,{scopeCwd:h,subView:i,onSubView:d,filterText:a,onFilterText:u,planMode:s,onPlanMode:n,planToolsRef:r}),t.jsxs("div",{className:"flex-1 min-h-0",children:[i==="queue"&&t.jsx(xa,{scopeCwd:h,navigate:e,filterText:a,planMode:s,onOpenPrds:w,planToolsEl:o}),i==="prds"&&t.jsx($a,{scopeCwd:h}),i==="history"&&t.jsx(Ma,{scopeCwd:h}),i==="machine"&&t.jsx("div",{className:"h-full overflow-y-auto px-9 py-6",children:t.jsx(_a,{navigate:e})})]})]})}const Ha=f.memo(Oa);export{Ha as Scheduler};