claude-code-session-manager 0.87.0 → 0.88.1

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 (291) hide show
  1. package/README.md +26 -53
  2. package/dist/assets/{AgentLibrary-DyLWzZDf.js → AgentLibrary-kQF8_wAw.js} +1 -1
  3. package/dist/assets/{DataModel--mISIJ6h.js → DataModel-CY_mMnsr.js} +1 -1
  4. package/dist/assets/{History-C2ahUXTg.js → History-Sji2brb0.js} +1 -1
  5. package/dist/assets/{Hooks-BiC6oyR2.js → Hooks-CtqpO-p5.js} +1 -1
  6. package/dist/assets/{HostBilko-BPleEOld.js → HostBilko-DN0ydOCr.js} +1 -1
  7. package/dist/assets/{Library-Dc8Qst1R.js → Library-CoiLZTKh.js} +1 -1
  8. package/dist/assets/{ListDetail-DIXh-OLX.js → ListDetail-CmqiQ_io.js} +1 -1
  9. package/dist/assets/{MarkdownEditor-C90bkLXK.js → MarkdownEditor-HPoNeKhT.js} +1 -1
  10. package/dist/assets/{McpServers-DqcbLOLZ.js → McpServers-Bj1X3_NT.js} +1 -1
  11. package/dist/assets/{Memory-CW62MXlh.js → Memory-1PKjsM3b.js} +1 -1
  12. package/dist/assets/{Panel-Bw1FhRuF.js → Panel-I1s6ghPo.js} +1 -1
  13. package/dist/assets/{Permissions-BcUC-5y8.js → Permissions-BhiiZjHQ.js} +1 -1
  14. package/dist/assets/{Plugins-BnKx9flD.js → Plugins-gv3_fkPX.js} +2 -2
  15. package/dist/assets/{ProvenanceBadge-Bw5vNVPT.js → ProvenanceBadge-BGcgBd8V.js} +1 -1
  16. package/dist/assets/{SaveBar-CWr0O_w-.js → SaveBar-BGr9eZ4g.js} +1 -1
  17. package/dist/assets/{Scheduler-DYdLuUqq.js → Scheduler-Bdo_awPq.js} +7 -7
  18. package/dist/assets/{ScopeSwitcher-CrBLbg8s.js → ScopeSwitcher-ukl0qWaA.js} +1 -1
  19. package/dist/assets/{Settings-DluB-vN1.js → Settings-DJkFj22G.js} +1 -1
  20. package/dist/assets/{SkillReferenceGraph-CHLSseay.js → SkillReferenceGraph-0t1Qblp6.js} +1 -1
  21. package/dist/assets/{Skills-gNdo_HNK.js → Skills-CeVdBGE-.js} +1 -1
  22. package/dist/assets/{SystemPrompt-Cru05-Ia.js → SystemPrompt-CfKvNHi3.js} +1 -1
  23. package/dist/assets/{TagLibrary-DNHY0xou.js → TagLibrary-DAzNaUPd.js} +1 -1
  24. package/dist/assets/{TiptapBody-I4lmbCgP.js → TiptapBody--S_rGXoA.js} +1 -1
  25. package/dist/assets/{Toggle-bWMHjmRh.js → Toggle-Dszm0xnp.js} +1 -1
  26. package/dist/assets/{index-DV3PorRY.css → index-BHTX4OTc.css} +1 -1
  27. package/dist/assets/{index-fc_JjdxL.js → index-Dp4Rc--q.js} +356 -356
  28. package/dist/assets/{settingsSchema-BfhtZnGD.js → settingsSchema-BLbssMYo.js} +1 -1
  29. package/dist/assets/{whisperWorker-Dbia1OpC.js → whisperWorker-C7ZGQwKg.js} +7 -7
  30. package/dist/index.html +2 -2
  31. package/dist/vad/ort-wasm-simd-threaded.asyncify.mjs +106 -110
  32. package/dist/vad/ort-wasm-simd-threaded.asyncify.wasm +0 -0
  33. package/dist/vad/ort-wasm-simd-threaded.jsep.mjs +98 -98
  34. package/dist/vad/ort-wasm-simd-threaded.jsep.wasm +0 -0
  35. package/dist/vad/ort-wasm-simd-threaded.jspi.mjs +99 -102
  36. package/dist/vad/ort-wasm-simd-threaded.jspi.wasm +0 -0
  37. package/dist/vad/ort-wasm-simd-threaded.mjs +46 -46
  38. package/dist/vad/ort-wasm-simd-threaded.wasm +0 -0
  39. package/package.json +10 -13
  40. package/scripts/README.md +59 -0
  41. package/scripts/audit-ops-hygiene.cjs +350 -0
  42. package/scripts/hooks/guard-destructive-git.cjs +10 -34
  43. package/scripts/hooks/guard-inline-implementation.cjs +14 -8
  44. package/scripts/hooks/guard-prd-writes.cjs +7 -36
  45. package/scripts/hooks/guard-self-schedule.cjs +175 -0
  46. package/scripts/ops-sweep.cjs +355 -0
  47. package/scripts/scheduler-mcp-server.cjs +28 -71
  48. package/src/main/__tests__/bilkoHost-integration.test.cjs +3 -3
  49. package/src/main/__tests__/chat-cancel-terminal.test.cjs +6 -9
  50. package/src/main/__tests__/chat-exit-close-race.test.cjs +3 -3
  51. package/src/main/__tests__/chat-mcp-consent-notice.test.cjs +4 -5
  52. package/src/main/__tests__/chat-queue.test.cjs +2 -2
  53. package/src/main/__tests__/chat-stop-signal.test.cjs +2 -2
  54. package/src/main/__tests__/dep-orphan-archive-health.test.cjs +77 -0
  55. package/src/main/__tests__/dod-batchkey.test.cjs +2 -2
  56. package/src/main/__tests__/dod-drain-hook.test.cjs +2 -2
  57. package/src/main/__tests__/dod-report.test.cjs +2 -2
  58. package/src/main/__tests__/dod-reverify.test.cjs +2 -2
  59. package/src/main/__tests__/epicMint.test.cjs +2 -2
  60. package/src/main/__tests__/exchanges.test.cjs +2 -2
  61. package/src/main/__tests__/extractJson.test.cjs +2 -2
  62. package/src/main/__tests__/files-reject-credentials.test.cjs +1 -1
  63. package/src/main/__tests__/fixtures/1218-fo-01-move-scripts-lib-into-src-main-lib.log +556 -0
  64. package/src/main/__tests__/health-build-freshness.test.cjs +39 -0
  65. package/src/main/__tests__/health-delegation-chain.test.cjs +15 -1
  66. package/src/main/__tests__/health-queue-dispatch.test.cjs +58 -7
  67. package/src/main/__tests__/health-tick-liveness.test.cjs +27 -3
  68. package/src/main/__tests__/health-usage-poller.test.cjs +70 -23
  69. package/src/main/__tests__/historyRollup.test.cjs +2 -2
  70. package/src/main/__tests__/kg-augment.test.cjs +2 -2
  71. package/src/main/__tests__/mcpStatus.test.cjs +2 -2
  72. package/src/main/__tests__/memoryAggregate.test.cjs +1 -1
  73. package/src/main/__tests__/memoryStale.test.cjs +1 -1
  74. package/src/main/__tests__/opsErrorLogTelemetryTap.test.cjs +25 -1
  75. package/src/main/__tests__/pollLoop-dispatch-on-failure.test.cjs +33 -3
  76. package/src/main/__tests__/prd-group-allocator.test.cjs +2 -2
  77. package/src/main/__tests__/prdAdminRouteParity.test.cjs +2 -0
  78. package/src/main/__tests__/prdAdminRoutes.test.cjs +14 -2
  79. package/src/main/__tests__/prdAuthoringSeed.test.cjs +39 -0
  80. package/src/main/__tests__/prdLocationsArchived.test.cjs +20 -13
  81. package/src/main/__tests__/proc-role-env.test.cjs +125 -0
  82. package/src/main/__tests__/procname-claude-spawn-sites.test.cjs +304 -0
  83. package/src/main/__tests__/procname-sm-processes.test.cjs +127 -0
  84. package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +81 -401
  85. package/src/main/__tests__/projectPages.test.cjs +63 -149
  86. package/src/main/__tests__/queue-health-verdict.test.cjs +9 -9
  87. package/src/main/__tests__/queue-starvation-dispatch-driver.test.cjs +117 -20
  88. package/src/main/__tests__/queueHistory.test.cjs +2 -2
  89. package/src/main/__tests__/rateLimitPollerStreak.test.cjs +38 -3
  90. package/src/main/__tests__/runVerify-landed-commit-outranks.test.cjs +181 -0
  91. package/src/main/__tests__/runVerify.test.cjs +5 -5
  92. package/src/main/__tests__/scheduleJobStatusDrift.test.cjs +3 -3
  93. package/src/main/__tests__/scheduleJobTransitions.test.cjs +2 -2
  94. package/src/main/__tests__/scheduler-adopted-run-supervision.test.cjs +143 -0
  95. package/src/main/__tests__/scheduler-autofix-select.test.cjs +2 -2
  96. package/src/main/__tests__/scheduler-autopromote.test.cjs +2 -2
  97. package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +3 -5
  98. package/src/main/__tests__/scheduler-boot-orphans.test.cjs +78 -97
  99. package/src/main/__tests__/scheduler-default-eligible-heal.test.cjs +161 -0
  100. package/src/main/__tests__/scheduler-dispatch-loop.test.cjs +58 -0
  101. package/src/main/__tests__/scheduler-epic-digest.test.cjs +3 -5
  102. package/src/main/__tests__/scheduler-force-tick-outcome.test.cjs +2 -2
  103. package/src/main/__tests__/scheduler-gate-shadow.test.cjs +119 -0
  104. package/src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs +46 -0
  105. package/src/main/__tests__/scheduler-heartbeat-payload.test.cjs +80 -0
  106. package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +25 -18
  107. package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +4 -4
  108. package/src/main/__tests__/scheduler-launch-failure.test.cjs +3 -5
  109. package/src/main/__tests__/scheduler-looks-done.test.cjs +26 -7
  110. package/src/main/__tests__/scheduler-manual-pause.test.cjs +118 -0
  111. package/src/main/__tests__/scheduler-meta-code-sha.test.cjs +26 -3
  112. package/src/main/__tests__/scheduler-prd-missing-skip.test.cjs +17 -2
  113. package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +3 -5
  114. package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +41 -6
  115. package/src/main/__tests__/scheduler-rate-limit-pause.test.cjs +62 -6
  116. package/src/main/__tests__/scheduler-rate-limit-spin-guard.test.cjs +3 -5
  117. package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +23 -4
  118. package/src/main/__tests__/scheduler-reconcile-cwd-preserve.test.cjs +100 -0
  119. package/src/main/__tests__/scheduler-reconcile-invalid-repair.test.cjs +3 -3
  120. package/src/main/__tests__/scheduler-reconcile-quarantine.test.cjs +4 -4
  121. package/src/main/__tests__/scheduler-shard-quarantine.test.cjs +110 -0
  122. package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +81 -1
  123. package/src/main/__tests__/scheduler-stall-per-project.test.cjs +14 -0
  124. package/src/main/__tests__/scheduler-starve-escalation.test.cjs +4 -4
  125. package/src/main/__tests__/scheduler-stranded-autofix-park.test.cjs +245 -0
  126. package/src/main/__tests__/scheduler-supervisor-record.test.cjs +81 -0
  127. package/src/main/__tests__/scheduler-tick-cancel-token.test.cjs +2 -2
  128. package/src/main/__tests__/scheduler-tick-wedge.test.cjs +172 -0
  129. package/src/main/__tests__/scheduler-transient-failure.test.cjs +2 -2
  130. package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +37 -11
  131. package/src/main/__tests__/scheduler-worktree-exec-cwd.test.cjs +3 -5
  132. package/src/main/__tests__/usageSingleFlight.test.cjs +157 -0
  133. package/src/main/__tests__/workTypeLibrary.test.cjs +1 -1
  134. package/src/main/bilkoHost.cjs +16 -7
  135. package/src/main/build-info.json +8 -0
  136. package/src/main/chatRunner.cjs +4 -2
  137. package/src/main/config.cjs +2 -3
  138. package/src/main/docEdit.cjs +4 -2
  139. package/src/main/health.cjs +276 -52
  140. package/src/main/heapSnapshot.cjs +2 -2
  141. package/src/main/historyAggregator.cjs +1 -1
  142. package/src/main/index.cjs +61 -10
  143. package/src/main/ipcSchemas.cjs +6 -17
  144. package/src/main/lib/__tests__/auditLog.test.cjs +38 -0
  145. package/src/main/lib/__tests__/buildIdentity.test.cjs +121 -0
  146. package/src/main/lib/__tests__/cwdClassify.test.cjs +111 -0
  147. package/src/main/lib/__tests__/definitionOfDoneSequence.test.cjs +95 -0
  148. package/src/main/lib/__tests__/delegationReadiness.test.cjs +1 -1
  149. package/src/main/lib/__tests__/dispatchLoop.test.cjs +63 -0
  150. package/src/main/lib/__tests__/gateFixtures.json +20 -0
  151. package/src/main/lib/__tests__/gitWorktree.test.cjs +8 -1
  152. package/src/main/lib/__tests__/instanceLock.test.cjs +93 -7
  153. package/src/main/lib/__tests__/jobSupervisorRecord.test.cjs +78 -0
  154. package/src/main/lib/__tests__/jobWorktreeBootLive.test.cjs +11 -0
  155. package/src/main/lib/__tests__/localAdminHttp.test.cjs +1 -1
  156. package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +6 -1
  157. package/src/main/lib/__tests__/procIdentity.test.cjs +119 -0
  158. package/src/main/lib/__tests__/procName.test.cjs +92 -0
  159. package/src/main/lib/__tests__/queueStoreMachineStateRecovery.test.cjs +67 -0
  160. package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +6 -7
  161. package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +37 -204
  162. package/src/main/lib/__tests__/schedulerPaths.test.cjs +226 -0
  163. package/src/main/lib/__tests__/schedulerPathsWorktree.test.cjs +94 -0
  164. package/src/main/lib/__tests__/schedulerRuntimeState.test.cjs +56 -0
  165. package/src/main/lib/__tests__/sessionSlots.test.cjs +45 -0
  166. package/src/main/lib/__tests__/telemetryBacklog.test.cjs +1 -1
  167. package/src/main/lib/__tests__/upgradeDrain.test.cjs +130 -0
  168. package/src/main/lib/__tests__/usageCircuit.test.cjs +61 -0
  169. package/src/main/lib/__tests__/watchdog-helpers.test.cjs +63 -0
  170. package/src/main/lib/__tests__/watchdog-relaunch.test.cjs +73 -0
  171. package/src/main/lib/activeIndexRebuild.cjs +1 -3
  172. package/src/main/lib/activeSessions.cjs +20 -88
  173. package/src/main/lib/adoptedRunSupervisor.cjs +136 -0
  174. package/src/main/lib/agentModelResolve.cjs +33 -1
  175. package/src/main/lib/agentPersonaSchema.cjs +2 -2
  176. package/src/main/lib/auditLog.cjs +30 -5
  177. package/src/main/lib/buildIdentity.cjs +113 -0
  178. package/src/main/lib/classifyPromptTicket.cjs +3 -2
  179. package/src/main/lib/claudeBin.cjs +37 -2
  180. package/src/main/lib/cleanEnv.cjs +27 -1
  181. package/src/main/lib/credentials.cjs +4 -2
  182. package/src/main/lib/cwdClassify.cjs +185 -0
  183. package/src/main/lib/definitionOfDone.cjs +296 -52
  184. package/src/main/lib/dispatchLoop.cjs +40 -0
  185. package/src/main/lib/effectiveModelInfo.cjs +9 -10
  186. package/src/main/lib/ephemeralCwd.cjs +7 -28
  187. package/src/main/lib/gitWorktree.cjs +95 -8
  188. package/src/main/lib/guardShims.cjs +3 -3
  189. package/src/main/lib/historyRollup.cjs +6 -7
  190. package/src/main/lib/instanceLock.cjs +32 -5
  191. package/src/main/lib/jobSupervisorRecord.cjs +147 -0
  192. package/src/main/lib/jobWorktreeBootLive.cjs +9 -5
  193. package/src/main/lib/localAdminHttp.cjs +9 -27
  194. package/src/main/lib/mcpToolCatalog.cjs +29 -77
  195. package/src/main/lib/opsOwnership.cjs +27 -19
  196. package/src/main/lib/prdAuthoringSeed.cjs +36 -0
  197. package/src/main/lib/prdLocations.cjs +48 -1
  198. package/src/main/lib/procIdentity.cjs +126 -0
  199. package/src/main/lib/procName.cjs +98 -0
  200. package/src/main/lib/projectHomeAdminRoutes.cjs +56 -327
  201. package/src/main/lib/queueHistory.cjs +8 -7
  202. package/src/main/lib/queueStore.cjs +57 -37
  203. package/src/main/lib/quietMachineLease.cjs +19 -2
  204. package/src/main/lib/reservationExpiry.cjs +30 -0
  205. package/src/main/lib/runClaudeP.cjs +4 -2
  206. package/src/main/lib/runLogRetention.cjs +3 -2
  207. package/src/main/lib/scheduleJobSchema.cjs +2 -2
  208. package/src/main/lib/scheduleJobTransitions.cjs +29 -2
  209. package/src/main/lib/schedulerBatch.cjs +27 -2
  210. package/src/main/lib/schedulerPaths.cjs +175 -0
  211. package/src/main/lib/schedulerRuntimeState.cjs +59 -0
  212. package/src/main/lib/sessionSlots.cjs +47 -9
  213. package/src/main/lib/smProcNames.cjs +51 -0
  214. package/src/main/lib/upgradeDrain.cjs +188 -0
  215. package/src/main/lib/usageCircuit.cjs +53 -6
  216. package/src/main/lib/watchdogHelpers.cjs +70 -37
  217. package/src/main/lib/withTimeout.cjs +33 -0
  218. package/src/main/mcpStatus.cjs +4 -2
  219. package/src/main/pluginInstall.cjs +6 -2
  220. package/src/main/projectPages.cjs +41 -145
  221. package/src/main/pty.cjs +8 -1
  222. package/src/main/queueOps.cjs +10 -10
  223. package/src/main/runVerify.cjs +69 -3
  224. package/src/main/scheduler.cjs +1607 -383
  225. package/src/main/seedAgentPersonas.cjs +1 -1
  226. package/src/main/seedDevPlugin.cjs +1 -1
  227. package/src/main/seedSchedulerMcp.cjs +7 -6
  228. package/src/main/seedStatus.cjs +1 -1
  229. package/src/main/supervisor.cjs +5 -3
  230. package/src/main/usage.cjs +126 -62
  231. package/src/preload/api.d.ts +18 -64
  232. package/src/preload/index.cjs +2 -4
  233. package/src/seed/agents/project-home-builder.md +31 -48
  234. package/screenshots/.gitkeep +0 -0
  235. package/screenshots/README-screenshots.md +0 -13
  236. package/src/main/lib/projectPageSummarySchema.cjs +0 -181
  237. package/src/main/teams.cjs +0 -95
  238. package/src/main/templates/project-pages-catalog.json +0 -741
  239. package/src/main/templates/project-pages-default-home.html +0 -123
  240. package/src/main/templates/project-pages-pipeline.md +0 -417
  241. package/src/seed/prompts/code-review/ac-coverage-check.md +0 -8
  242. package/src/seed/prompts/code-review/correctness-only.md +0 -8
  243. package/src/seed/prompts/code-review/full-spectrum-high.md +0 -8
  244. package/src/seed/prompts/code-review/hallucination-check.md +0 -8
  245. package/src/seed/prompts/code-review/public-api-compat.md +0 -8
  246. package/src/seed/prompts/code-review/readability-naming.md +0 -8
  247. package/src/seed/prompts/debugging/bug-as-failing-test.md +0 -8
  248. package/src/seed/prompts/debugging/git-bisect-regression.md +0 -8
  249. package/src/seed/prompts/debugging/instrument-intermittent-bug.md +0 -8
  250. package/src/seed/prompts/debugging/localize-pipeline-failure.md +0 -8
  251. package/src/seed/prompts/debugging/reproduce-then-diagnose.md +0 -8
  252. package/src/seed/prompts/documentation/adr-from-change.md +0 -8
  253. package/src/seed/prompts/documentation/module-readme.md +0 -8
  254. package/src/seed/prompts/documentation/onboarding-plan.md +0 -8
  255. package/src/seed/prompts/documentation/refresh-claude-md.md +0 -8
  256. package/src/seed/prompts/documentation/tsdoc-public-exports.md +0 -8
  257. package/src/seed/prompts/git-pr/conventional-commit.md +0 -8
  258. package/src/seed/prompts/git-pr/draft-pr-title-body.md +0 -8
  259. package/src/seed/prompts/git-pr/pre-commit-safety-sweep.md +0 -8
  260. package/src/seed/prompts/git-pr/release-notes-block.md +0 -8
  261. package/src/seed/prompts/git-pr/split-large-pr.md +0 -8
  262. package/src/seed/prompts/performance/bundle-startup-audit.md +0 -8
  263. package/src/seed/prompts/performance/complexity-audit.md +0 -8
  264. package/src/seed/prompts/performance/cpu-profile-hot-path.md +0 -8
  265. package/src/seed/prompts/performance/db-query-plan-review.md +0 -8
  266. package/src/seed/prompts/performance/memory-leak-hunt.md +0 -8
  267. package/src/seed/prompts/qa/api-contract-tests.md +0 -8
  268. package/src/seed/prompts/qa/e2e-critical-path.md +0 -8
  269. package/src/seed/prompts/qa/failing-test-for-bug.md +0 -8
  270. package/src/seed/prompts/qa/find-missing-test-coverage.md +0 -8
  271. package/src/seed/prompts/qa/stabilize-flaky-test.md +0 -8
  272. package/src/seed/prompts/qa/tdd-red-first.md +0 -8
  273. package/src/seed/prompts/qa/visual-regression-review.md +0 -8
  274. package/src/seed/prompts/qa/wcag-axe-scan.md +0 -8
  275. package/src/seed/prompts/refactoring/dead-code-sweep.md +0 -8
  276. package/src/seed/prompts/refactoring/extract-duplicated-pattern.md +0 -8
  277. package/src/seed/prompts/refactoring/modernize-legacy-file.md +0 -8
  278. package/src/seed/prompts/refactoring/reduce-cyclomatic-complexity.md +0 -8
  279. package/src/seed/prompts/refactoring/tighten-module-boundaries.md +0 -8
  280. package/src/seed/prompts/security/authz-audit.md +0 -8
  281. package/src/seed/prompts/security/crypto-correctness.md +0 -8
  282. package/src/seed/prompts/security/cwe-top-25-hunt.md +0 -8
  283. package/src/seed/prompts/security/dependency-audit.md +0 -8
  284. package/src/seed/prompts/security/ipc-boundary-hardening.md +0 -8
  285. package/src/seed/prompts/security/owasp-top-10-staged-diff.md +0 -8
  286. package/src/seed/prompts/security/secret-credential-scan.md +0 -8
  287. package/web/README.md +0 -41
  288. package/web/project-pages/logic/dist/logic.cjs +0 -4709
  289. package/web/project-pages/render.cjs +0 -70
  290. package/web/project-pages/renderer/dist/renderer.cjs +0 -18900
  291. package/web/project-pages/validate-summary.cjs +0 -62
package/README.md CHANGED
@@ -8,49 +8,21 @@ You already use the `claude` CLI. This wraps it in a cockpit so you can run mult
8
8
 
9
9
  New tabs open as a lightweight **chat box** and stay dormant — no PTY, no `claude` process — until you actually send a message, so a window full of tabs costs almost nothing. Prefer a single bare terminal? Launch with `--simple`.
10
10
 
11
- Single-author hobby project. Linux and macOS only. Free, MIT, zero telemetry.
12
-
13
- ## Screenshots
14
-
15
- | | |
16
- |---|---|
17
- | ![Overview cockpit](screenshots/overview-cockpit.png) | ![Agent view](screenshots/agent-view.png) |
18
- | Overview tab — AppStatusBar + cockpit strip + instrument grid | Agent-View — animated workshop with subagents and todo board |
19
- | ![Command palette](screenshots/command-palette.png) | ![Scheduler](screenshots/scheduler.png) |
20
- | Cmd-K command palette (41+ commands) | Scheduler panel with PRD queue + health linter |
21
- | ![Voice](screenshots/voice.png) | ![Hooks events](screenshots/hooks-events.png) |
22
- | Voice subsystem — local Whisper + Silero VAD | Hooks tab — 29 documented events with inline docs |
23
-
24
- Screenshots are placeholders right now; see `screenshots/README-screenshots.md` if you want to help capture them.
11
+ Single-author hobby project. Linux and macOS only. Free, MIT, anonymous opt-out telemetry (see [Privacy](#privacy)).
25
12
 
26
13
  ## Features tour
27
14
 
28
15
  - **Dormant tabs + chat box** — every new tab opens as a chat box and stays dormant (no PTY, no `claude` process) until you send the first message. The headless chat-run engine drives it through `claude -p` with `stream-json`, session resume, and a stop signal, so a tab is a real conversation without holding a live terminal open. Hydrate into a full terminal whenever you need one.
29
16
  - **Simple mode** — `npx claude-code-session-manager@latest --simple` boots a chrome-free, single-terminal cockpit: no nav, no tabs, no config surface, just one `claude` session in the launch directory.
30
- - **AppStatusBar** — five always-visible pills at the very top of the window: active model, thinking effort, team, voice state, and the current 5-hour usage percentage. Each pill is a shortcut into the relevant settings panel.
31
- - **Overview cockpit** — the home tab is a real instrument cluster:
32
- - CockpitStrip at the top with critical session info.
33
- - Two-by-five instrument grid (one tile per live signal).
34
- - Teams card when `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` is on.
35
- - System row with cwd, model, branch, and git status.
36
- - Quick-actions footer for the things you do every day.
37
- - **Cmd-K command palette** — 41+ commands organised into bands (session, voice, scheduler, config, nav). Fuzzy filter, emit-only dispatch so commands stay decoupled from views.
38
- - **17 tabs** — every Claude Code surface, broken into three groups:
39
- - Workspace: Overview · Terminal · System Prompt · Agent-View · Memory.
40
- - Config: Settings · Permissions · Skills · Plugins · MCP Servers · Hooks · Subagents.
41
- - Activity: Plans · Tasks · Projects · History · Usage.
42
- - Footer dock: Scheduler panel and microphone status, both pinned above the active tab.
43
- - **Scheduler / PRD queue** — drop a markdown file into `~/.claude/session-manager/scheduled-plans/prds/` and the scheduler will pick it up as a headless `claude -p` job. Multi-select bulk archive and reset. Queue-health linter catches unbounded poll loops and post-AC overrun patterns before they burn tokens. Structured frontmatter editor with a raw-yaml escape hatch for power users.
44
- - **Agent-View** — animated workshop scene rendered as a friendly cartoon: subagent dock, plan whiteboard, todo board, and a SchedulerDock with mini-bots that mirror each running scheduler job. Watching a job is more legible than tailing its log.
45
- - **Memory tab** — new this cycle. Workspace-scoped memory entries that the `memory_20250818` tool can read and write, surfaced as a real UI rather than a JSON blob.
17
+ - **Cmd-K command palette** — commands organised into bands (session, voice, scheduler, config, nav). Fuzzy filter, emit-only dispatch so commands stay decoupled from views.
18
+ - **Sidebar groups** — the left nav is organised into three groups: Workspace (where you do the work), Configure (how Claude behaves), and Tools (one-off utilities).
19
+ - **Scheduler / PRD queue** — PRDs live under `<cwd>/session-manager-operations/scheduler/epics/<epic-id>/prds/` and the scheduler picks them up as headless `claude -p` jobs. Author them through the `scheduler_create_prd` MCP tool. Multi-select bulk archive and reset. Queue-health linter catches unbounded poll loops and post-AC overrun patterns before they burn tokens.
20
+ - **Memory tab** — workspace-scoped memory entries that the `memory_20250818` tool can read and write, surfaced as a real UI rather than a JSON blob.
46
21
  - **Hooks** — all 29 documented events with inline tooltips explaining what each event fires on. Definitions editor plus a test-fire runner so you can verify a hook without rebuilding state.
47
- - **Subagents** — full frontmatter editor with tool and skill pickers. Live invocation status while you watch agents spawn off the active session.
48
- - **Plugins** — manifest inspector for installed plugins plus a Discover panel that lists the 23 first-party plugins with one-click install (pty-wrapped `claude plugin install`).
22
+ - **Plugins** — manifest inspector for installed plugins plus a Discover panel that lists first-party plugins with one-click install (pty-wrapped `claude plugin install`).
49
23
  - **MCP servers** — five transports (stdio, http, streamable-http, ws, sse) with a reserved-name linter so you don't waste a launch on a server Claude refuses to load.
50
24
  - **Voice** — local Whisper ASR plus Silero VAD running in a Web Worker. Push-to-talk hotkey, continuous listening, auto-submit, and barge-in that ducks TTS playback. Nothing leaves the machine.
51
25
  - **Toast notifications + 4-scope drift surfacing** — non-fatal errors land in a corner toast instead of being swallowed. Settings show drift across the default / user / project / local scopes so you always know which value actually wins.
52
- - **npm update checker** — new this cycle. Quietly polls `registry.npmjs.org` and surfaces a toast when a newer version is published. Update on your schedule, not theirs.
53
-
54
26
  ## Install
55
27
 
56
28
  ```bash
@@ -65,31 +37,29 @@ Linux needs `build-essential` and `python3` for the rebuild.
65
37
  ## Quick start
66
38
 
67
39
  1. Run the install command above.
68
- 2. The app opens on the Overview tab — you should see your AppStatusBar pills populate and a fresh Terminal tab ready to go.
40
+ 2. The app opens on the Overview tab — you should see a fresh session ready to go.
69
41
  3. Hit Cmd-K (Ctrl-K on Linux) and try `terminal new`, `voice start`, or `scheduler open`.
70
- 4. Drop a markdown file into `~/.claude/session-manager/scheduled-plans/prds/01-my-first-prd.md` and watch the Scheduler dock pick it up.
71
- 5. Press F7 to open the microphone setup wizard, then F1 to start dictating.
42
+ 4. Create a PRD with the `scheduler_create_prd` MCP tool and watch the Scheduler pick it up.
43
+ 5. On first run the microphone setup wizard opens automatically; then use the push-to-talk hotkey (see Voice setup) to dictate.
72
44
 
73
45
  ## Privacy
74
46
 
75
- **Zero telemetry by default.**
47
+ **Anonymous product telemetry is on by default.** It posts event, log, error, and crash records to bilko.run. Opt out with `SM_TELEMETRY=0` or Settings → Telemetry. Details: [telemetry.md](session-manager-operations/architecture/telemetry.md).
76
48
 
77
- - No analytics, no error reporting, no crash uploads.
78
- - The Content-Security-Policy restricts `connect-src` to two hosts: `api.anthropic.com` (so the in-app `/usage` panel can read the billing endpoint) and `registry.npmjs.org` (for the version-check toast).
49
+ - The Content-Security-Policy restricts `connect-src` to four hosts: `api.anthropic.com` (so the in-app `/usage` panel can read the billing endpoint), `registry.npmjs.org`, `json.schemastore.org`, and `www.schemastore.org`.
79
50
  - All settings, skills, hooks, scheduler PRDs, transcripts, and voice configuration stay on disk under `~/.claude/`. The `claude` CLI itself is the only network egress for AI work — the cockpit never proxies your prompts.
80
- - An opt-in OpenTelemetry exporter lives under Settings → Telemetry. It is off until you turn it on.
81
51
  - The recording-status pill is always mounted at the top of the window whenever the microphone is hot, above every other UI layer. There is no way to record without seeing the indicator.
82
52
 
83
53
  ## Voice setup
84
54
 
85
- - Press F7 to open the first-run wizard. It enumerates your input devices, lets you pick one, records a sample utterance, and persists the choice in `voice.json`.
86
- - Press F1 for push-to-talk. Hold or toggle, configurable in the Voice tab.
55
+ - The mic setup wizard auto-opens on first run. It enumerates your input devices, lets you pick one, records a sample utterance, and persists the choice in `voice.json`.
56
+ - Push-to-talk defaults to Cmd+Option+V on macOS and Ctrl+Shift+Space elsewhere. Hold or toggle, configurable in the Voice tab.
87
57
  - Models download once on first use, then run entirely locally via onnxruntime-web.
88
58
  - Auto-submit fires Enter at a configurable countdown (default 6 s); the mic stays open across turns until silence (default 30 s) or an explicit stop.
89
59
 
90
60
  ## Scheduler / PRD workflow
91
61
 
92
- A PRD is a self-contained markdown file with frontmatter (`title`, absolute `cwd`, `estimateMinutes`) and a body that `claude -p` runs without conversation context. They live in `~/.claude/session-manager/scheduled-plans/prds/<NN>-<kebab-slug>.md` where the `NN` prefix groups parallel work.
62
+ A PRD is a self-contained markdown file with frontmatter (`title`, absolute `cwd`, `estimateMinutes`) and a body that `claude -p` runs without conversation context. They live under `<cwd>/session-manager-operations/scheduler/epics/<epic-id>/prds/` and are authored through the `scheduler_create_prd` MCP tool.
93
63
 
94
64
  Three run modes:
95
65
 
@@ -97,23 +67,24 @@ Three run modes:
97
67
  - `on-reset` — fires at the next 5-hour usage reset.
98
68
  - `when-available` — the default. Polls the billing usage endpoint every ten minutes and fires when tokens fall below the configured threshold. Auto-pauses if a job hits a rate limit, auto-resumes at the next reset.
99
69
 
100
- The queue-health linter scans every queued PRD for two patterns that have caused real stuck jobs in this project: unbounded poll loops with unsatisfiable conditions, and post-AC fixture generators that overrun the acceptance criteria. Both incidents are documented in `PRD_AUTHORING.md`.
70
+ The queue-health linter scans every queued PRD for two patterns that have caused real stuck jobs in this project: unbounded poll loops with unsatisfiable conditions, and post-AC fixture generators that overrun the acceptance criteria. Both incidents are documented in [`src/main/templates/PRD_AUTHORING.md`](src/main/templates/PRD_AUTHORING.md).
101
71
 
102
72
  ## Keyboard cheatsheet
103
73
 
104
74
  | Key | Action |
105
75
  |---|---|
106
76
  | Cmd-K / Ctrl-K | Open command palette |
107
- | F1 | Push-to-talk |
108
- | F7 | Microphone setup wizard |
109
- | Ctrl-N | New terminal tab |
110
- | Ctrl-W | Close tab |
111
- | Ctrl-Shift-R | Reboot active session (preset-aware) |
112
- | Ctrl-Shift-B | Toggle build mode for active tab |
77
+ | Alt-1 … Alt-5 | Activate tab 1–5 |
78
+ | Cmd/Ctrl-N | Open / Start Project |
79
+ | Cmd/Ctrl-Shift-R | Restart the app |
80
+ | Cmd/Ctrl-Shift-S | Restart terminal in active tab |
81
+ | Cmd/Ctrl-R | Reload app window |
82
+ | F12 | Toggle developer tools |
83
+ | Cmd/Ctrl-Q | Quit |
113
84
 
114
85
  ## Architecture
115
86
 
116
- Electron 33 with a CommonJS main process and a Vite-built React 18 renderer. xterm and node-pty drive the terminals. zustand owns renderer state. Whisper via `@huggingface/transformers` plus Silero VAD via `@ricky0123/vad-web` runs voice on-device through onnxruntime-web. Tailwind for styling. Single-author project, no backwards-compat shims — when something needs renaming, it gets renamed.
87
+ Electron 42 with a CommonJS main process and a Vite-built React 18 renderer. xterm and node-pty drive the terminals. zustand owns renderer state. Whisper via `@huggingface/transformers` plus Silero VAD via `@ricky0123/vad-web` runs voice on-device through onnxruntime-web. Tailwind for styling. Single-author project, no backwards-compat shims — when something needs renaming, it gets renamed.
117
88
 
118
89
  ## Contributing / development
119
90
 
@@ -123,10 +94,12 @@ cd claude-code-session-manager
123
94
  npm install
124
95
  npm run dev # Vite + Electron with HMR (SM_DEV=1)
125
96
  npm run typecheck # tsc --noEmit, must pass before commits
97
+ npm run lint # unstable selectors, conditional hooks, unregistered tests
98
+ npm run test:unit # vitest run
126
99
  npm run test:e2e # Playwright Electron under xvfb-run (Linux)
127
100
  ```
128
101
 
129
- PRs welcome. Before authoring a scheduler PRD, read `PRD_AUTHORING.md` — the two stuck-job postmortems in there will save you tokens.
102
+ PRs welcome. Before authoring a scheduler PRD, read [`src/main/templates/PRD_AUTHORING.md`](src/main/templates/PRD_AUTHORING.md) — the two stuck-job postmortems in there will save you tokens.
130
103
 
131
104
  ## License
132
105
 
@@ -1,3 +1,3 @@
1
- import{aa as e,z as V,al as h,j as B,b as O,aw as w,at as X,T as z,av as Z,aD as ee,A as T}from"./index-fc_JjdxL.js";import{P as te}from"./Panel-Bw1FhRuF.js";import{L as ne}from"./ListDetail-DIXh-OLX.js";import"./monaco-editor-BW5C4Iv1.js";function y({children:t,onClick:r,disabled:g,variant:f="default",tooltip:l,type:m="button",className:c}){const u=`px-2 py-0.5 text-xs rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${f==="primary"?"text-accent border-accent/50 hover:bg-bg-hi":f==="danger"?"text-red-400 hover:text-red-300 border-line hover:border-red-400/50":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"} ${c??""}`,a=e.jsx("button",{type:m,title:l,onClick:r,disabled:g,className:u,children:t});return l?e.jsx(V,{content:l,align:"bottom-center",children:a}):a}const ae=["inherit","haiku","sonnet","opus","fable"],I=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],se=["","red","orange","yellow","green","cyan","blue","purple","pink"],G={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"};function R(t){return{name:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",color:t.color??"",tags:t.tags,projects:t.projects??[],action:t.action??"",actionLabel:t.actionLabel??"",body:t.body}}const _={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",color:"",tags:[],projects:[],action:"",actionLabel:"",body:""},re=new Set(z.map(t=>t.tag));function oe(t){return t.filter(r=>re.has(r))}function ie(){const[t,r]=h.useState(null),[g,f]=h.useState(null),[l,m]=h.useState(""),[c,i]=h.useState(null),[u,a]=h.useState(!1),[v,N]=h.useState(!1),[P,C]=h.useState(null),[k,s]=h.useState(!1),j=h.useRef(!0);h.useEffect(()=>()=>{j.current=!1},[]);const p=async n=>{try{const x=await window.api.agents.listPersonas();if(!j.current)return;r(x),f(L=>{var D;return n??L??((D=x[0])==null?void 0:D.name)??null})}catch(x){if(!j.current)return;r([]),w.error(x.message||"failed to load agent personas")}};if(h.useEffect(()=>{p()},[]),h.useEffect(()=>window.api.agents.onChanged(()=>p()),[]),h.useEffect(()=>{const n=X();n&&f(n);const x=L=>f(L.detail);return window.addEventListener("sm:select-persona",x),()=>window.removeEventListener("sm:select-persona",x)},[]),t===null)return e.jsx(B,{title:"loading…"});const $=l.toLowerCase(),E=t.filter(n=>!$||n.name.toLowerCase().includes($)||(n.description??"").toLowerCase().includes($)),d=t.find(n=>n.name===g)??t[0]??null,o=c??(d?R(d):null),F=!!c&&!!d&&JSON.stringify(c)!==JSON.stringify(R(d)),S=u,K=n=>{i(null),a(!1),N(!1),C(null),f(n)},W=n=>i(x=>({...x??(d?R(d):_),...n})),M=()=>{i({..._}),a(!0),N(!1)},J=()=>{o&&(i({...o,name:o.name+"-copy"}),a(!0))},H=()=>{i(null),a(!1)},Y=async()=>{if(o){if(!/^[a-z][a-z0-9-]*$/.test(o.name)){w.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}s(!0);try{const n={name:o.name,originalName:S||d==null?void 0:d.name,description:o.description,tools:o.tools,model:o.model,color:o.color,tags:oe(o.tags),projects:o.projects,action:o.action,actionLabel:o.actionLabel,body:o.body};await window.api.agents.savePersona(n),w.info(S?`created ${o.name}`:`saved ${o.name}`),i(null),a(!1),await p(o.name)}catch(n){w.error(n.message||"failed to save agent persona")}finally{s(!1)}}},q=async()=>{if(d){s(!0);try{await window.api.agents.deletePersona({name:d.name}),w.info(`deleted ${d.name}`),N(!1),i(null),a(!1),await p()}catch(n){w.error(n.message||"failed to delete agent persona")}finally{s(!1)}}},Q=async n=>{s(!0);try{await window.api.agents.deletePersona({name:n}),w.info(`deleted ${n}`),C(null),g===n&&(i(null),a(!1)),await p()}catch(x){w.error(x.message||"failed to delete agent persona")}finally{s(!1)}},U=async n=>{if(d)try{await window.api.agents.removeOverride({name:d.name,projectName:n}),w.info(`removed ${n}'s override of ${d.name}`),await p(d.name)}catch(x){w.error(x.message||"failed to remove override")}};return e.jsx(te,{toolbar:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-fg-faint",children:[t.length," persona",t.length===1?"":"s"]}),e.jsx("input",{value:l,onChange:n=>m(n.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(y,{variant:"primary",onClick:M,children:"+ New agent"})]}),children:e.jsx(ne,{sidebar:e.jsxs("div",{className:"py-1",children:[S&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:o==null?void 0:o.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),E.length===0&&!S?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):E.map(n=>{const x=!S&&n.name===g,L=x&&F,D=P===n.name;return e.jsxs("div",{"data-agent-row":n.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${x?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>K(n.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:n.color?G[n.color]??n.color:"var(--fg-faint, #999)",opacity:n.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:n.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[L&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!L&&n.overridingProjects.length>0&&e.jsxs(O,{tone:"dim",children:[n.overridingProjects.length," override",n.overridingProjects.length>1?"s":""]}),D?e.jsxs("span",{className:"flex items-center gap-1",onClick:A=>A.stopPropagation(),children:[e.jsx("button",{onClick:()=>Q(n.name),disabled:k,title:`Delete ${n.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>C(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:A=>{A.stopPropagation(),C(n.name)},title:`Delete ${n.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),n.description&&e.jsx("span",{className:"truncate text-fg-faint",children:n.description})]},n.name)})]}),detail:o?e.jsx(le,{obj:o,set:W,saved:d,dirty:F,isNew:S,busy:k,confirmDelete:v,setConfirmDelete:N,onDuplicate:J,onRevert:H,onSave:Y,onDelete:q,onDropOverride:U}):e.jsx(B,{title:"select an agent"})})})}const he=h.memo(ie);function le({obj:t,set:r,saved:g,dirty:f,isNew:l,busy:m,confirmDelete:c,setConfirmDelete:i,onDuplicate:u,onRevert:a,onSave:v,onDelete:N,onDropOverride:P}){const C=`~/.claude/agents/${t.name}.md`,k=f||l;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:t.name}),l?e.jsx(O,{tone:"accent",children:"unsaved draft"}):f?e.jsx(O,{tone:"warn",children:"edited"}):e.jsx(O,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:C})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(b,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:t.name,onChange:s=>r({name:s.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(b,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:t.description,onChange:s=>r({description:s.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(b,{label:"default model",hint:"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:e.jsx(de,{options:ae,value:t.model,onChange:s=>r({model:s}),mono:!0})}),e.jsx(b,{label:"tools",hint:`${t.tools.length} of ${I.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:I.map(s=>{const j=t.tools.includes(s);return e.jsx("button",{onClick:()=>r({tools:j?t.tools.filter(p=>p!==s):[...t.tools,s]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${j?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:s},s)})})}),e.jsx(b,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:se.map(s=>e.jsx("button",{title:s||"none",onClick:()=>r({color:s}),className:"w-5 h-5 rounded",style:{background:s?G[s]:"transparent",border:t.color===s?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},s||"none"))})}),e.jsx(b,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on that tag's own page. The first one (in Tag Library order) is the MISSION an Action button's session opens with.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map(s=>{const j=t.tags.includes(s.tag),p=Z(s.tag);return e.jsxs("button",{onClick:()=>r({tags:j?t.tags.filter($=>$!==s.tag):[...t.tags,s.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${j?`${p.bg} ${p.text} ${p.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",s.tag]},s.tag)})})}),e.jsx(ce,{obj:t,set:r}),e.jsx(b,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:t.body,onChange:s=>r({body:s.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(b,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:g&&g.overridingProjects.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.overridingProjects.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[s,e.jsx("button",{onClick:()=>P(s),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},s))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:l?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:t.name})," and its file?"]}),e.jsx(y,{variant:"danger",onClick:N,disabled:m,children:"Delete"}),e.jsx(y,{onClick:()=>i(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{onClick:u,disabled:m,children:"Duplicate"}),!l&&e.jsx(y,{variant:"danger",onClick:()=>i(!0),disabled:m,children:"Delete"}),e.jsx("div",{className:"flex-1"}),k&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(y,{onClick:a,disabled:!k||m,children:"Revert"}),e.jsx(y,{variant:"primary",onClick:v,disabled:!k||m,children:m?"Saving…":l?"Create":"Save"})]})})]})}function ce({obj:t,set:r}){const{projects:g}=ee(),f=g.map(a=>({cwd:a.cwd,name:a.name})),l=new Set(f.map(a=>a.cwd)),m=t.projects.filter(a=>a!==T&&!l.has(a)),c=t.projects.includes(T),i=a=>r({projects:t.projects.includes(a)?t.projects.filter(v=>v!==a):[...t.projects,a]}),u=t.projects.length>0;return e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"action — appears in",hint:"Projects whose Sessions toolbar gets a one-click button for this agent. Pressing it starts a normal session: this persona is the ACTOR, its first tag is the MISSION, and the action text below is the opening goal. Leave empty for an agent that is only picked by hand in the New Session card.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{onClick:()=>i(T),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${c?"bg-accent/15 text-accent border-accent/40 font-semibold":"bg-bg-hi text-fg-faint border-line"}`,children:"every project"}),f.map(a=>{const v=t.projects.includes(a.cwd);return e.jsx("button",{title:a.cwd,onClick:()=>i(a.cwd),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${v?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"} ${c&&!v?"opacity-40":""}`,children:a.name},a.cwd)}),m.map(a=>e.jsxs("button",{title:`${a} — not a known project on this machine`,onClick:()=>i(a),className:"px-2 py-0.5 rounded-full text-[11px] font-mono border bg-bg-hi text-fg-faint border-dashed border-line",children:[a," ×"]},a))]})}),u&&e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"action — button label",hint:"Caption on the Sessions toolbar button. Defaults to the agent name.",children:e.jsx("input",{value:t.actionLabel,onChange:a=>r({actionLabel:a.target.value}),placeholder:t.name,className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(b,{label:"action — opening instruction",hint:"Sent as the session's first message, under the AIM framing. Falls back to this persona's description when empty; with neither, no button is shown.",children:e.jsx("textarea",{rows:3,value:t.action,onChange:a=>r({action:a.target.value}),placeholder:t.description||`e.g. /builder
1
+ import{aa as e,z as V,al as h,j as B,b as O,aw as w,at as X,T as z,av as Z,aD as ee,A as T}from"./index-Dp4Rc--q.js";import{P as te}from"./Panel-I1s6ghPo.js";import{L as ne}from"./ListDetail-CmqiQ_io.js";import"./monaco-editor-BW5C4Iv1.js";function y({children:t,onClick:r,disabled:g,variant:f="default",tooltip:l,type:m="button",className:c}){const u=`px-2 py-0.5 text-xs rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${f==="primary"?"text-accent border-accent/50 hover:bg-bg-hi":f==="danger"?"text-red-400 hover:text-red-300 border-line hover:border-red-400/50":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"} ${c??""}`,a=e.jsx("button",{type:m,title:l,onClick:r,disabled:g,className:u,children:t});return l?e.jsx(V,{content:l,align:"bottom-center",children:a}):a}const ae=["inherit","haiku","sonnet","opus","fable"],I=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],se=["","red","orange","yellow","green","cyan","blue","purple","pink"],G={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"};function R(t){return{name:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",color:t.color??"",tags:t.tags,projects:t.projects??[],action:t.action??"",actionLabel:t.actionLabel??"",body:t.body}}const _={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",color:"",tags:[],projects:[],action:"",actionLabel:"",body:""},re=new Set(z.map(t=>t.tag));function oe(t){return t.filter(r=>re.has(r))}function ie(){const[t,r]=h.useState(null),[g,f]=h.useState(null),[l,m]=h.useState(""),[c,i]=h.useState(null),[u,a]=h.useState(!1),[v,N]=h.useState(!1),[P,C]=h.useState(null),[k,s]=h.useState(!1),j=h.useRef(!0);h.useEffect(()=>()=>{j.current=!1},[]);const p=async n=>{try{const x=await window.api.agents.listPersonas();if(!j.current)return;r(x),f(L=>{var D;return n??L??((D=x[0])==null?void 0:D.name)??null})}catch(x){if(!j.current)return;r([]),w.error(x.message||"failed to load agent personas")}};if(h.useEffect(()=>{p()},[]),h.useEffect(()=>window.api.agents.onChanged(()=>p()),[]),h.useEffect(()=>{const n=X();n&&f(n);const x=L=>f(L.detail);return window.addEventListener("sm:select-persona",x),()=>window.removeEventListener("sm:select-persona",x)},[]),t===null)return e.jsx(B,{title:"loading…"});const $=l.toLowerCase(),E=t.filter(n=>!$||n.name.toLowerCase().includes($)||(n.description??"").toLowerCase().includes($)),d=t.find(n=>n.name===g)??t[0]??null,o=c??(d?R(d):null),F=!!c&&!!d&&JSON.stringify(c)!==JSON.stringify(R(d)),S=u,K=n=>{i(null),a(!1),N(!1),C(null),f(n)},W=n=>i(x=>({...x??(d?R(d):_),...n})),M=()=>{i({..._}),a(!0),N(!1)},J=()=>{o&&(i({...o,name:o.name+"-copy"}),a(!0))},H=()=>{i(null),a(!1)},Y=async()=>{if(o){if(!/^[a-z][a-z0-9-]*$/.test(o.name)){w.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}s(!0);try{const n={name:o.name,originalName:S||d==null?void 0:d.name,description:o.description,tools:o.tools,model:o.model,color:o.color,tags:oe(o.tags),projects:o.projects,action:o.action,actionLabel:o.actionLabel,body:o.body};await window.api.agents.savePersona(n),w.info(S?`created ${o.name}`:`saved ${o.name}`),i(null),a(!1),await p(o.name)}catch(n){w.error(n.message||"failed to save agent persona")}finally{s(!1)}}},q=async()=>{if(d){s(!0);try{await window.api.agents.deletePersona({name:d.name}),w.info(`deleted ${d.name}`),N(!1),i(null),a(!1),await p()}catch(n){w.error(n.message||"failed to delete agent persona")}finally{s(!1)}}},Q=async n=>{s(!0);try{await window.api.agents.deletePersona({name:n}),w.info(`deleted ${n}`),C(null),g===n&&(i(null),a(!1)),await p()}catch(x){w.error(x.message||"failed to delete agent persona")}finally{s(!1)}},U=async n=>{if(d)try{await window.api.agents.removeOverride({name:d.name,projectName:n}),w.info(`removed ${n}'s override of ${d.name}`),await p(d.name)}catch(x){w.error(x.message||"failed to remove override")}};return e.jsx(te,{toolbar:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-fg-faint",children:[t.length," persona",t.length===1?"":"s"]}),e.jsx("input",{value:l,onChange:n=>m(n.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(y,{variant:"primary",onClick:M,children:"+ New agent"})]}),children:e.jsx(ne,{sidebar:e.jsxs("div",{className:"py-1",children:[S&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:o==null?void 0:o.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),E.length===0&&!S?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):E.map(n=>{const x=!S&&n.name===g,L=x&&F,D=P===n.name;return e.jsxs("div",{"data-agent-row":n.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${x?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>K(n.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:n.color?G[n.color]??n.color:"var(--fg-faint, #999)",opacity:n.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:n.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[L&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!L&&n.overridingProjects.length>0&&e.jsxs(O,{tone:"dim",children:[n.overridingProjects.length," override",n.overridingProjects.length>1?"s":""]}),D?e.jsxs("span",{className:"flex items-center gap-1",onClick:A=>A.stopPropagation(),children:[e.jsx("button",{onClick:()=>Q(n.name),disabled:k,title:`Delete ${n.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>C(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:A=>{A.stopPropagation(),C(n.name)},title:`Delete ${n.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),n.description&&e.jsx("span",{className:"truncate text-fg-faint",children:n.description})]},n.name)})]}),detail:o?e.jsx(le,{obj:o,set:W,saved:d,dirty:F,isNew:S,busy:k,confirmDelete:v,setConfirmDelete:N,onDuplicate:J,onRevert:H,onSave:Y,onDelete:q,onDropOverride:U}):e.jsx(B,{title:"select an agent"})})})}const he=h.memo(ie);function le({obj:t,set:r,saved:g,dirty:f,isNew:l,busy:m,confirmDelete:c,setConfirmDelete:i,onDuplicate:u,onRevert:a,onSave:v,onDelete:N,onDropOverride:P}){const C=`~/.claude/agents/${t.name}.md`,k=f||l;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:t.name}),l?e.jsx(O,{tone:"accent",children:"unsaved draft"}):f?e.jsx(O,{tone:"warn",children:"edited"}):e.jsx(O,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:C})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(b,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:t.name,onChange:s=>r({name:s.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(b,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:t.description,onChange:s=>r({description:s.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(b,{label:"default model",hint:"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:e.jsx(de,{options:ae,value:t.model,onChange:s=>r({model:s}),mono:!0})}),e.jsx(b,{label:"tools",hint:`${t.tools.length} of ${I.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:I.map(s=>{const j=t.tools.includes(s);return e.jsx("button",{onClick:()=>r({tools:j?t.tools.filter(p=>p!==s):[...t.tools,s]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${j?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:s},s)})})}),e.jsx(b,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:se.map(s=>e.jsx("button",{title:s||"none",onClick:()=>r({color:s}),className:"w-5 h-5 rounded",style:{background:s?G[s]:"transparent",border:t.color===s?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},s||"none"))})}),e.jsx(b,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on that tag's own page. The first one (in Tag Library order) is the MISSION an Action button's session opens with.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map(s=>{const j=t.tags.includes(s.tag),p=Z(s.tag);return e.jsxs("button",{onClick:()=>r({tags:j?t.tags.filter($=>$!==s.tag):[...t.tags,s.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${j?`${p.bg} ${p.text} ${p.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",s.tag]},s.tag)})})}),e.jsx(ce,{obj:t,set:r}),e.jsx(b,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:t.body,onChange:s=>r({body:s.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(b,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:g&&g.overridingProjects.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.overridingProjects.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[s,e.jsx("button",{onClick:()=>P(s),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},s))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:l?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:t.name})," and its file?"]}),e.jsx(y,{variant:"danger",onClick:N,disabled:m,children:"Delete"}),e.jsx(y,{onClick:()=>i(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{onClick:u,disabled:m,children:"Duplicate"}),!l&&e.jsx(y,{variant:"danger",onClick:()=>i(!0),disabled:m,children:"Delete"}),e.jsx("div",{className:"flex-1"}),k&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(y,{onClick:a,disabled:!k||m,children:"Revert"}),e.jsx(y,{variant:"primary",onClick:v,disabled:!k||m,children:m?"Saving…":l?"Create":"Save"})]})})]})}function ce({obj:t,set:r}){const{projects:g}=ee(),f=g.map(a=>({cwd:a.cwd,name:a.name})),l=new Set(f.map(a=>a.cwd)),m=t.projects.filter(a=>a!==T&&!l.has(a)),c=t.projects.includes(T),i=a=>r({projects:t.projects.includes(a)?t.projects.filter(v=>v!==a):[...t.projects,a]}),u=t.projects.length>0;return e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"action — appears in",hint:"Projects whose Sessions toolbar gets a one-click button for this agent. Pressing it starts a normal session: this persona is the ACTOR, its first tag is the MISSION, and the action text below is the opening goal. Leave empty for an agent that is only picked by hand in the New Session card.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{onClick:()=>i(T),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${c?"bg-accent/15 text-accent border-accent/40 font-semibold":"bg-bg-hi text-fg-faint border-line"}`,children:"every project"}),f.map(a=>{const v=t.projects.includes(a.cwd);return e.jsx("button",{title:a.cwd,onClick:()=>i(a.cwd),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${v?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"} ${c&&!v?"opacity-40":""}`,children:a.name},a.cwd)}),m.map(a=>e.jsxs("button",{title:`${a} — not a known project on this machine`,onClick:()=>i(a),className:"px-2 py-0.5 rounded-full text-[11px] font-mono border bg-bg-hi text-fg-faint border-dashed border-line",children:[a," ×"]},a))]})}),u&&e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"action — button label",hint:"Caption on the Sessions toolbar button. Defaults to the agent name.",children:e.jsx("input",{value:t.actionLabel,onChange:a=>r({actionLabel:a.target.value}),placeholder:t.name,className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(b,{label:"action — opening instruction",hint:"Sent as the session's first message, under the AIM framing. Falls back to this persona's description when empty; with neither, no button is shown.",children:e.jsx("textarea",{rows:3,value:t.action,onChange:a=>r({action:a.target.value}),placeholder:t.description||`e.g. /builder
2
2
 
3
3
  Check git vs the published package and publish anything new.`,className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})})]})]})}function b({label:t,hint:r,children:g}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:t}),g,r&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:r})]})}function de({options:t,value:r,onChange:g,mono:f}){const l=r&&!t.includes(r),m=l?[...t,r]:t;return e.jsx("div",{className:"flex flex-wrap gap-1",children:m.map(c=>{const i=c===r,u=l&&c===r;return e.jsxs("button",{onClick:()=>g(c),title:u?`${c} — current on-disk value, not in the standard list`:void 0,className:`px-2.5 py-1 rounded text-xs border ${f?"font-mono":""} ${i?"bg-accent/15 text-accent border-accent/40 font-semibold":"bg-bg-hi text-fg-dim border-line"} ${u?"border-dashed":""}`,children:[c,u?" (current)":""]},c)})})}export{he as AgentLibrary};
@@ -1 +1 @@
1
- import{al as d,f as j,ab as $,U as g,aa as e,j as N,V as E,ad as S,W as b,an as T,b as p,I as D,g as v,E as R}from"./index-fc_JjdxL.js";import{P as V}from"./Panel-Bw1FhRuF.js";import"./monaco-editor-BW5C4Iv1.js";const C=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function G(){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(V,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(E,{options:C,active:s,onChange:t}),e.jsx(M,{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(O,{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(P,{})})}const L=d.memo(G);function M({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 O({layout:s,selectedId:t,onSelect:a}){const i=d.useMemo(()=>t?new Set(S(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,R),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:D(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 P(){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{L as DataModel};
1
+ import{al as d,f as j,ab as $,U as g,aa as e,j as N,V as E,ad as S,W as b,an as T,b as p,I as D,g as v,E as R}from"./index-Dp4Rc--q.js";import{P as V}from"./Panel-I1s6ghPo.js";import"./monaco-editor-BW5C4Iv1.js";const C=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function G(){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(V,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(E,{options:C,active:s,onChange:t}),e.jsx(M,{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(O,{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(P,{})})}const L=d.memo(G);function M({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 O({layout:s,selectedId:t,onSelect:a}){const i=d.useMemo(()=>t?new Set(S(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,R),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:D(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 P(){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{L as DataModel};
@@ -1,2 +1,2 @@
1
- import{ai as ue,aa as e,al as f,aj as F,ak as I,aE as Be,aK as ge,ae as _e,aw as Oe,aD as He,j as Ie}from"./index-fc_JjdxL.js";import{P as Le}from"./Panel-Bw1FhRuF.js";import"./monaco-editor-BW5C4Iv1.js";function ce(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function ke(t,s){t.promptCount+=s.promptCount,t.inputTokens+=s.inputTokens,t.outputTokens+=s.outputTokens,t.cacheReadTokens+=s.cacheReadTokens,t.cacheCreationTokens+=s.cacheCreationTokens,t.toolCallCount+=s.toolCallCount,t.sessionCount+=s.sessionCount,t.errorCount+=s.errorCount,t.activeMinutes+=s.activeMinutes,t.estimatedCostUsd+=s.estimatedCostUsd}function Ke(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function We(t,s){const n=s===null,c=[],o=ce(),r={};let a=0;for(const i of t.days){const d=ce();let u=!1;for(const[l,p]of Object.entries(i.byProject))if(!(!n&&!s.has(l))){ke(d,p),ke(o,p),Ke(p)&&(u=!0);for(const[x,j]of Object.entries(p.byModel)){const T=r[x]??(r[x]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});T.inputTokens+=j.inputTokens,T.outputTokens+=j.outputTokens,T.cacheReadTokens+=j.cacheReadTokens,T.cacheCreationTokens+=j.cacheCreationTokens,T.costUsd+=j.costUsd,j.estimated&&(T.estimated=!0)}}u&&(a+=1),c.push({date:i.date,totals:d})}return{days:c,totals:o,prevTotals:n?t.prevTotals:ce(),prevAvailable:n,byModelTotals:r,activeDays:a}}function we(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,c=n>0?"up":n<0?"down":"flat";return{pct:n,direction:c}}function Ge(t,s,n){return s<=0?0:t/s*n}const Me={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function R(t,s){const n=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens;switch(s){case"in":return n;case"out":return t.outputTokens;case"total":return n+t.outputTokens;case"prompts":return t.promptCount;case"sessions":return t.sessionCount;case"time":return t.activeMinutes;case"spend":return t.estimatedCostUsd}}function Ye(t,s){const n=R(t.totals,s),c=t.prevAvailable?we(n,R(t.prevTotals,s)):null,o=t.days.map(r=>R(r.totals,s));return{value:n,delta:c,series:o}}function be(t,s){const n=new Map,c=Math.ceil(t.length/2);t.forEach((a,i)=>{for(const[d,u]of Object.entries(a.byProject)){let l=n.get(d);l||(l={totals:{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0},toolBreakdown:{},firstHalf:0,secondHalf:0},n.set(d,l)),l.totals.promptCount+=u.promptCount,l.totals.inputTokens+=u.inputTokens,l.totals.outputTokens+=u.outputTokens,l.totals.cacheReadTokens+=u.cacheReadTokens,l.totals.cacheCreationTokens+=u.cacheCreationTokens,l.totals.toolCallCount+=u.toolCallCount,l.totals.sessionCount+=u.sessionCount,l.totals.errorCount+=u.errorCount,l.totals.activeMinutes+=u.activeMinutes,l.totals.estimatedCostUsd+=u.estimatedCostUsd;for(const[x,j]of Object.entries(u.toolBreakdown))l.toolBreakdown[x]=(l.toolBreakdown[x]??0)+j;const p=R(u,s);i<c?l.firstHalf+=p:l.secondHalf+=p}});const o=Array.from(n.entries()).map(([a,i])=>{let d="",u=-1;for(const[l,p]of Object.entries(i.toolBreakdown))p>u&&(u=p,d=l);return{projectDir:a,value:R(i.totals,s),sharePct:0,trend:we(i.secondHalf,i.firstHalf),sessions:i.totals.sessionCount,topTool:d}}),r=o.reduce((a,i)=>a+i.value,0);for(const a of o)a.sharePct=r>0?a.value/r*100:0;return o.sort((a,i)=>i.value-a.value)}const ze=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function Ve(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function ve(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function Xe(t){const s=t.map(n=>{const c=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,r=o>0?n.cacheReadTokens/o*100:0,a=Object.entries(n.byModel).filter(([,l])=>ve(l)>0);let i="",d=-1;for(const[l,p]of a){const x=ve(p);x>d&&(d=x,i=l)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(c),r.toFixed(1),String(a.length),i?ue(i):""].map(Ve).join(",")});return[ze.join(","),...s].join(`
1
+ import{ai as ue,aa as e,al as f,aj as F,ak as I,aE as Be,aK as ge,ae as _e,aw as Oe,aD as He,j as Ie}from"./index-Dp4Rc--q.js";import{P as Le}from"./Panel-I1s6ghPo.js";import"./monaco-editor-BW5C4Iv1.js";function ce(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function ke(t,s){t.promptCount+=s.promptCount,t.inputTokens+=s.inputTokens,t.outputTokens+=s.outputTokens,t.cacheReadTokens+=s.cacheReadTokens,t.cacheCreationTokens+=s.cacheCreationTokens,t.toolCallCount+=s.toolCallCount,t.sessionCount+=s.sessionCount,t.errorCount+=s.errorCount,t.activeMinutes+=s.activeMinutes,t.estimatedCostUsd+=s.estimatedCostUsd}function Ke(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function We(t,s){const n=s===null,c=[],o=ce(),r={};let a=0;for(const i of t.days){const d=ce();let u=!1;for(const[l,p]of Object.entries(i.byProject))if(!(!n&&!s.has(l))){ke(d,p),ke(o,p),Ke(p)&&(u=!0);for(const[x,j]of Object.entries(p.byModel)){const T=r[x]??(r[x]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});T.inputTokens+=j.inputTokens,T.outputTokens+=j.outputTokens,T.cacheReadTokens+=j.cacheReadTokens,T.cacheCreationTokens+=j.cacheCreationTokens,T.costUsd+=j.costUsd,j.estimated&&(T.estimated=!0)}}u&&(a+=1),c.push({date:i.date,totals:d})}return{days:c,totals:o,prevTotals:n?t.prevTotals:ce(),prevAvailable:n,byModelTotals:r,activeDays:a}}function we(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,c=n>0?"up":n<0?"down":"flat";return{pct:n,direction:c}}function Ge(t,s,n){return s<=0?0:t/s*n}const Me={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function R(t,s){const n=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens;switch(s){case"in":return n;case"out":return t.outputTokens;case"total":return n+t.outputTokens;case"prompts":return t.promptCount;case"sessions":return t.sessionCount;case"time":return t.activeMinutes;case"spend":return t.estimatedCostUsd}}function Ye(t,s){const n=R(t.totals,s),c=t.prevAvailable?we(n,R(t.prevTotals,s)):null,o=t.days.map(r=>R(r.totals,s));return{value:n,delta:c,series:o}}function be(t,s){const n=new Map,c=Math.ceil(t.length/2);t.forEach((a,i)=>{for(const[d,u]of Object.entries(a.byProject)){let l=n.get(d);l||(l={totals:{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0},toolBreakdown:{},firstHalf:0,secondHalf:0},n.set(d,l)),l.totals.promptCount+=u.promptCount,l.totals.inputTokens+=u.inputTokens,l.totals.outputTokens+=u.outputTokens,l.totals.cacheReadTokens+=u.cacheReadTokens,l.totals.cacheCreationTokens+=u.cacheCreationTokens,l.totals.toolCallCount+=u.toolCallCount,l.totals.sessionCount+=u.sessionCount,l.totals.errorCount+=u.errorCount,l.totals.activeMinutes+=u.activeMinutes,l.totals.estimatedCostUsd+=u.estimatedCostUsd;for(const[x,j]of Object.entries(u.toolBreakdown))l.toolBreakdown[x]=(l.toolBreakdown[x]??0)+j;const p=R(u,s);i<c?l.firstHalf+=p:l.secondHalf+=p}});const o=Array.from(n.entries()).map(([a,i])=>{let d="",u=-1;for(const[l,p]of Object.entries(i.toolBreakdown))p>u&&(u=p,d=l);return{projectDir:a,value:R(i.totals,s),sharePct:0,trend:we(i.secondHalf,i.firstHalf),sessions:i.totals.sessionCount,topTool:d}}),r=o.reduce((a,i)=>a+i.value,0);for(const a of o)a.sharePct=r>0?a.value/r*100:0;return o.sort((a,i)=>i.value-a.value)}const ze=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function Ve(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function ve(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function Xe(t){const s=t.map(n=>{const c=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,r=o>0?n.cacheReadTokens/o*100:0,a=Object.entries(n.byModel).filter(([,l])=>ve(l)>0);let i="",d=-1;for(const[l,p]of a){const x=ve(p);x>d&&(d=x,i=l)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(c),r.toFixed(1),String(a.length),i?ue(i):""].map(Ve).join(",")});return[ze.join(","),...s].join(`
2
2
  `)}const Ze={folderCount:0,sessionCount:0,promptCount:0,estimatedCostUsd:0,totalTokens:0};function qe(t,s){t.promptCount+=s.promptCount,t.inputTokens+=s.inputTokens,t.outputTokens+=s.outputTokens,t.cacheReadTokens+=s.cacheReadTokens,t.cacheCreationTokens+=s.cacheCreationTokens,t.toolCallCount+=s.toolCallCount,t.sessionCount+=s.sessionCount,t.errorCount+=s.errorCount,t.activeMinutes+=s.activeMinutes,t.estimatedCostUsd+=s.estimatedCostUsd;for(const[n,c]of Object.entries(s.toolBreakdown??{}))t.toolBreakdown[n]=(t.toolBreakdown[n]??0)+c;for(const[n,c]of Object.entries(s.byModel??{})){const o=t.byModel[n]??(t.byModel[n]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});o.inputTokens+=c.inputTokens,o.outputTokens+=c.outputTokens,o.cacheReadTokens+=c.cacheReadTokens,o.cacheCreationTokens+=c.cacheCreationTokens,o.costUsd+=c.costUsd,c.estimated&&(o.estimated=!0)}}function Je(t,s){const n={};for(const[c,o]of Object.entries(t.byModel??{}))n[c]={...o};return{...t,projectDir:s,toolBreakdown:{...t.toolBreakdown??{}},byModel:n}}function Qe(t,s){const n={...Ze},c=new Set,o=t.map(r=>{const a={};for(const[i,d]of Object.entries(r.byProject)){const u=s[i];if(!u){c.add(i),n.sessionCount+=d.sessionCount,n.promptCount+=d.promptCount,n.estimatedCostUsd+=d.estimatedCostUsd,n.totalTokens+=d.inputTokens+d.outputTokens;continue}const l=a[u];l?qe(l,d):a[u]=Je(d,u)}return{...r,byProject:a}});return n.folderCount=c.size,{days:o,excluded:n}}function et(t){return t.folderCount>0}function tt(t){const s=[`${t.folderCount} transcript folder${t.folderCount===1?"":"s"} with no resolvable working directory`];return t.sessionCount&&s.push(`${t.sessionCount.toLocaleString()} sessions`),t.promptCount&&s.push(`${t.promptCount.toLocaleString()} prompts`),t.estimatedCostUsd>=.005&&s.push(`$${t.estimatedCostUsd.toFixed(2)}`),`Excluded: ${s.join(" · ")}`}const st=["in","out","total","prompts","sessions","time","spend"],nt=[{value:30,label:"30d"},{value:60,label:"60d"},{value:90,label:"90d"},{value:0,label:"All time"}];function Te({value:t,options:s,onChange:n}){return e.jsx("div",{className:"flex gap-0.5 p-0.5 rounded bg-bg-elev shadow-[inset_0_0_0_1px_rgba(0,0,0,0.06)] text-[11px]",children:s.map(c=>e.jsx("button",{onClick:()=>n(c.value),className:`px-2 py-1 rounded whitespace-nowrap font-mono ${t===c.value?"bg-bg-hi text-fg shadow-sm":"text-fg-faint hover:text-fg"}`,children:c.label},String(c.value)))})}function ot({measure:t,onMeasure:s,range:n,onRange:c,projectsShown:o,projectsTotal:r,fromDate:a,toDate:i,onRefresh:d,onExport:u,exportDisabled:l}){return e.jsxs("div",{className:"sticky top-0 z-10 border-b border-line px-4 py-2.5 flex flex-wrap items-center gap-3 backdrop-blur-sm",style:{backgroundColor:"rgba(246,239,225,0.93)"},children:[e.jsx(Te,{value:t,options:st.map(p=>({value:p,label:Me[p]})),onChange:s}),e.jsx(Te,{value:n,options:nt,onChange:c}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[o," / ",r," projects"]}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[a," → ",i]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:d,className:"px-2 py-1 text-[11px] border border-line rounded hover:text-fg hover:bg-bg-hi text-fg-faint",title:"Re-fetch the rollup (no scan)",children:"↻ Refresh"}),e.jsx("button",{onClick:u,disabled:l,className:"px-2 py-1 text-[11px] border border-line rounded hover:text-fg hover:bg-bg-hi text-fg-faint disabled:opacity-40 disabled:pointer-events-none",children:"Export CSV"})]})}function U(t){const s=Number.isFinite(t)?t:0,n=Math.abs(s)<1?4:2;return`$${s.toFixed(n)}`}function L(t){const s=Number.isFinite(t)?t:0,n=Math.abs(s);return n>=1e9?`${(s/1e9).toFixed(1)}B`:n>=1e6?`${(s/1e6).toFixed(1)}M`:n>=1e3?`${(s/1e3).toFixed(1)}K`:`${Math.round(s)}`}function K(t){const s=Number.isFinite(t)?t:0;return Math.round(s).toLocaleString("en-US")}function Se(t){const s=Math.max(0,Math.round(Number.isFinite(t)?t:0));if(s<60)return`${s}m`;const n=Math.floor(s/60),c=s%60;return c===0?`${n}h`:`${n}h ${c}m`}function $e(t){return Number.isFinite(t)?t>0&&t<1?"<1%":`${t.toFixed(1)}%`:"0.0%"}const S="rounded-card bg-bg-hi border border-line",at="#ded2bd",ct="#6f7d52";function D({kicker:t,title:s,right:n}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wider text-accent font-mono",children:t}),e.jsx("h2",{className:"font-serif text-[25px] leading-tight tracking-tight text-fg",children:s})]}),n]})}function ee(t,s){switch(t){case"spend":return U(s);case"in":case"out":case"total":return L(s);case"time":return Se(s);default:return K(s)}}function rt({measure:t,headline:s,activeDays:n,projectsTouched:c,totalSessions:o}){const r=n>0?s.value/n:0,a=o>0?s.value/o:0,{delta:i}=s,d=i&&(t==="spend"?i.direction==="down":i.direction==="up"),u=i&&i.direction!=="flat"&&(t==="spend"?i.direction==="up":i.direction==="down"),l=d?"text-delta-good":u?"text-delta-bad":"text-fg-faint";return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"01 · overview",title:Me[t]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[52px] leading-none font-mono tracking-tight text-fg",children:ee(t,s.value)}),i?e.jsxs("div",{className:`text-xs font-mono mt-2 ${l}`,children:[i.direction==="up"?"▲":i.direction==="down"?"▼":"·"," ",$e(Math.abs(i.pct??0))," vs prior period"]}):e.jsx("div",{className:"text-xs text-fg-faint mt-2",children:"no prior window to compare"})]}),e.jsx("div",{className:"flex-1 min-w-0 self-stretch",children:e.jsx(it,{series:s.series})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3 mt-4 pt-3 border-t border-line",children:[e.jsx(Q,{label:"per active day",value:ee(t,r)}),e.jsx(Q,{label:"per session",value:ee(t,a)}),e.jsx(Q,{label:"active days",value:K(n)}),e.jsx(Q,{label:"projects touched",value:K(c)})]})]})}function Q({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider",children:t}),e.jsx("div",{className:"text-[17px] font-mono tracking-tight text-fg-dim",children:s})]})}function it({series:t}){if(t.length<2)return null;const c=Math.max(...t,0),o=Math.min(...t,0),r=c-o||1,a=160/(t.length-1),i=t.map((u,l)=>`${l*a},${48-(u-o)/r*48}`).join(" "),d=`0,48 ${i} 160,48`;return e.jsxs("svg",{viewBox:"0 0 160 48",preserveAspectRatio:"none",className:"w-full h-full min-h-[48px]",children:[e.jsx("polygon",{points:d,fill:"#b85c34",opacity:.15}),e.jsx("polyline",{points:i,fill:"none",stroke:"#b85c34",strokeWidth:1.5,vectorEffect:"non-scaling-stroke"})]})}const Ce="sm.history.budgetCapUsd",ye=50;function lt({days:t}){const[s,n]=f.useState(()=>{try{const i=localStorage.getItem(Ce),d=i===null?NaN:Number(i);return Number.isFinite(d)&&d>0?d:ye}catch{return ye}});f.useEffect(()=>{try{localStorage.setItem(Ce,String(s))}catch{}},[s]);const{mtdSpend:c,projectedSpend:o}=f.useMemo(()=>{const i=new Date,d=i.toLocaleDateString("en-CA").slice(0,7),u=new Date(i.getFullYear(),i.getMonth()+1,0).getDate(),l=i.getDate();let p=0;for(const x of t)if(x.date.startsWith(d))for(const j of Object.values(x.byProject))p+=j.estimatedCostUsd;return{mtdSpend:p,projectedSpend:Ge(p,l,u)}},[t]),r=o>s,a=s>0?Math.min(100,c/s*100):0;return e.jsxs("div",{className:`${S} p-3`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-[10.5px] uppercase tracking-wider text-fg-faint font-mono",children:"Monthly budget"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-faint",children:["cap",e.jsx("span",{children:"$"}),e.jsx("input",{type:"number",min:1,step:1,value:s,onChange:i=>{const d=Number(i.target.value);Number.isFinite(d)&&d>0&&n(d)},className:"w-16 bg-bg border border-line rounded px-1.5 py-0.5 text-xs text-fg font-mono"})]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs font-mono mb-1.5",children:[e.jsxs("span",{className:"text-fg",children:[U(c)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:r?"text-delta-bad":"text-fg-dim",children:[U(o)," ",e.jsx("span",{className:"text-fg-faint",children:"projected"})]})]}),e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:`h-full ${r?"bg-delta-bad":"bg-sage"}`,style:{width:`${Math.max(a,a>0?2:0)}%`}})}),e.jsx("div",{className:`text-[10px] mt-1 font-mono ${r?"text-delta-bad":"text-fg-faint"}`,children:r?`projected to exceed $${s.toFixed(0)} cap`:`${a.toFixed(0)}% of $${s.toFixed(0)} cap`})]})}function dt({chips:t,keep:s,onToggle:n,onIsolate:c,onShowAll:o}){const r=s===null;return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsxs("button",{onClick:o,className:`px-2 py-1 rounded text-[11px] font-mono border ${r?"bg-accent text-white border-accent":"border-line text-fg-faint hover:text-fg hover:bg-bg-hi"}`,children:["show all (",t.length,")"]}),t.map(a=>{const i=r||s.has(a.projectDir);return e.jsxs("button",{onClick:d=>d.shiftKey?c(a.projectDir):n(a.projectDir),title:a.projectDir,className:`inline-flex items-center gap-1.5 px-2 py-1 rounded text-[11px] font-mono border ${i?"border-line text-fg-dim bg-bg-hi":"border-line text-fg-faint opacity-40 hover:opacity-70"}`,children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:F(a.projectDir)}}),I(a.projectDir)??a.projectDir]},a.projectDir)})]})}function ut(t,s){const n=new Map;for(const o of t)for(const[r,a]of Object.entries(o.values))n.set(r,(n.get(r)??0)+a);const c=Array.from(n.entries()).sort((o,r)=>r[1]-o[1]).map(([o])=>o);return t.map(o=>{const r=c.reduce((d,u)=>d+(o.values[u]??0),0);let a=0;const i=c.map(d=>{const u=o.values[d]??0;if(r<=0)return{projectDir:d,value:u,y0:0,y1:0};const l=s==="share"?u/r:u,p=a,x=a+l;return a=x,{projectDir:d,value:u,y0:p,y1:x}});return{date:o.date,bands:i,total:r}})}const re=720,ie=220,le=44,pt=20;function xt(t,s){return t==="spend"?U(s):L(s)}function ht({days:t,measure:s,selected:n,onSelect:c}){const[o,r]=f.useState("absolute"),a=f.useMemo(()=>ut(t,o),[t,o]),i=f.useMemo(()=>{if(o==="share")return 1;let m=0;for(const b of a)m=Math.max(m,b.total);return m||1},[a,o]),d=re-le,u=ie-pt,l=a.length>1?d/(a.length-1):d,p=m=>le+m*l,x=m=>u-m/i*u,j=Math.max(1,Math.ceil(a.length/8)),T=4,g=Array.from({length:T+1},(m,b)=>i/T*b);return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"02 · over time",title:"Trend by project",right:e.jsx("div",{className:"flex border border-line rounded overflow-hidden text-[10px] font-mono",children:["absolute","share"].map(m=>e.jsx("button",{onClick:()=>r(m),className:`px-2 py-0.5 ${o===m?"bg-accent text-white":"text-fg-faint hover:text-fg"}`,children:m},m))})}),e.jsxs("svg",{width:"100%",viewBox:`0 0 ${re} ${ie}`,className:"overflow-visible",children:[g.map((m,b)=>e.jsxs("g",{children:[e.jsx("line",{x1:le,x2:re,y1:x(m),y2:x(m),stroke:"currentColor",className:"text-line",strokeWidth:1}),e.jsx("text",{x:0,y:x(m)+3,fontSize:9,className:"fill-fg-faint",children:o==="share"?`${Math.round(m*100)}%`:xt(s,m)})]},b)),a.map((m,b)=>{if(b===0)return null;const W=a[b-1];return m.bands.map((y,se)=>{const G=W.bands[se],Y=n!==null&&n!==y.projectDir,z=Y?at:F(y.projectDir),V=[`${p(b-1)},${x(G.y0)}`,`${p(b)},${x(y.y0)}`,`${p(b)},${x(y.y1)}`,`${p(b-1)},${x(G.y1)}`].join(" ");return e.jsx("polygon",{points:V,fill:z,opacity:Y?.6:.75,className:"cursor-pointer",onClick:()=>c(n===y.projectDir?null:y.projectDir),children:e.jsx("title",{children:I(y.projectDir)??y.projectDir})},`${y.projectDir}-${b}`)})}),a.map((m,b)=>b%j!==0&&b!==a.length-1?null:e.jsx("text",{x:p(b),y:ie-4,fontSize:9,textAnchor:"middle",className:"fill-fg-faint",children:m.date.slice(5)},m.date))]})]})}function ft({rows:t,measure:s,selected:n,onSelect:c}){return t.length?e.jsxs("div",{className:`${S} overflow-hidden`,children:[e.jsx("div",{className:"p-4 pb-0",children:e.jsx(D,{kicker:"03 · by project",title:"Ranking"})}),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-bg-elev",children:e.jsx("tr",{children:["project","share","value","share %","trend","sessions","top tool"].map(o=>e.jsx("th",{className:"text-left px-3 py-2 text-fg-faint uppercase tracking-wider whitespace-nowrap",children:o},o))})}),e.jsx("tbody",{children:t.map(o=>{const r=F(o.projectDir),a=n===o.projectDir;return e.jsxs("tr",{onClick:()=>c(o.projectDir),className:`border-t border-line hover:bg-bg-elev cursor-pointer ${a?"bg-bg-elev":""}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono text-fg-dim",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:r}}),I(o.projectDir)??o.projectDir]})}),e.jsx("td",{className:"px-3 py-2 w-32",children:e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full",style:{width:`${Math.max(o.sharePct,o.sharePct>0?2:0)}%`,backgroundColor:r}})})}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:ee(s,o.value)}),e.jsxs("td",{className:"px-3 py-2 text-fg-faint font-mono",children:[o.sharePct.toFixed(1),"%"]}),e.jsx("td",{className:"px-3 py-2 font-mono",children:o.trend.pct===null?e.jsx("span",{className:"text-fg-faint",children:"—"}):e.jsxs("span",{className:o.trend.direction==="up"?"text-delta-good":o.trend.direction==="down"?"text-delta-bad":"text-fg-faint",children:[o.trend.direction==="up"?"▲":o.trend.direction==="down"?"▼":"·"," ",$e(Math.abs(o.trend.pct))]})}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:K(o.sessions)}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:o.topTool||"—"})]},o.projectDir)})})]})]}):e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"03 · by project",title:"Ranking"}),e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"})]})}function mt({projectDir:t,totals:s,byModel:n,toolBreakdown:c,onClear:o}){var l;const r=R(s,"in"),a=R(s,"out"),i=Object.entries(n).sort((p,x)=>x[1].costUsd-p[1].costUsd),d=Object.entries(c).sort((p,x)=>x[1]-p[1]),u=((l=d[0])==null?void 0:l[1])??0;return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"04 · drill in",title:I(t)??t,right:e.jsx("button",{onClick:o,className:"text-[11px] text-fg-faint hover:text-fg font-mono",children:"clear ✕"})}),e.jsx("div",{className:"flex items-center gap-1.5 -mt-2 mb-3",children:e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:F(t)}})}),e.jsxs("div",{className:"grid grid-cols-6 gap-3 mb-4",children:[e.jsx(H,{label:"prompts",value:K(s.promptCount)}),e.jsx(H,{label:"sessions",value:K(s.sessionCount)}),e.jsx(H,{label:"in tokens",value:L(r)}),e.jsx(H,{label:"out tokens",value:L(a)}),e.jsx(H,{label:"spend",value:U(s.estimatedCostUsd)}),e.jsx(H,{label:"time",value:Se(s.activeMinutes)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider mb-1.5",children:"model mix"}),i.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data"}):e.jsx("div",{className:"space-y-1",children:i.map(([p,x])=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-fg-dim",children:[e.jsx("span",{children:ue(p)}),e.jsx("span",{className:"text-fg-faint",children:U(x.costUsd)})]},p))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider mb-1.5",children:"tool mix"}),d.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no tool data"}):e.jsx("div",{className:"space-y-1",children:d.slice(0,6).map(([p,x])=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-fg-dim font-mono",children:p}),e.jsx("div",{className:"flex-1 h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full bg-hive-teal",style:{width:`${u>0?x/u*100:0}%`}})}),e.jsx("span",{className:"text-fg-faint font-mono w-8 text-right",children:x})]},p))})]})]})]})}function H({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider",children:t}),e.jsx("div",{className:"text-[17px] font-mono tracking-tight text-fg",children:s})]})}function jt({byModelTotals:t}){const s=Object.entries(t).sort((c,o)=>o[1].costUsd-c[1].costUsd),n=s.reduce((c,[,o])=>c+o.costUsd,0);return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Model mix",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:[U(n)," total"]})}),s.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data in range"}):e.jsx("div",{className:"space-y-2",children:s.map(([c,o])=>{const r=n>0?o.costUsd/n*100:0,a=F(c);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-mono text-fg-dim truncate",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{backgroundColor:a}}),ue(c),o.estimated&&e.jsx("span",{className:"text-fg-faint",children:"(est.)"})]}),e.jsxs("span",{className:"text-fg-faint whitespace-nowrap ml-2",children:[U(o.costUsd)," · ",r.toFixed(0),"%"]})]}),e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full",style:{width:`${Math.max(r,r>0?2:0)}%`,backgroundColor:a}})})]},c)})})]})}function gt({rows:t}){const s=t.slice(0,3),n=s.reduce((r,a)=>r+a.sharePct,0),c=t.slice(3),o=c.reduce((r,a)=>r+a.sharePct,0);return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Concentration",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["top 3 = ",n.toFixed(0),"%"]})}),t.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex h-3 rounded overflow-hidden mb-2",children:t.map(r=>e.jsx("div",{style:{width:`${Math.max(r.sharePct,.5)}%`,backgroundColor:F(r.projectDir)},title:`${I(r.projectDir)??r.projectDir} · ${r.sharePct.toFixed(1)}%`},r.projectDir))}),e.jsx("div",{className:"space-y-1 mb-2",children:s.map(r=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-fg-dim truncate",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:F(r.projectDir)}}),I(r.projectDir)??r.projectDir]}),e.jsxs("span",{className:"text-fg-faint",children:[r.sharePct.toFixed(1),"%"]})]},r.projectDir))}),c.length>0&&e.jsxs("p",{className:"text-[10px] text-fg-faint",children:[c.length," more project",c.length===1?"":"s"," account for ",o.toFixed(1),"% (long tail)."]})]})]})}const te=30,de=9,P=(te+de)*2;function kt({totals:t}){const s=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,n=s>0?t.cacheReadTokens/s*100:0,c=2*Math.PI*te,o=P/2;return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Cache"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative shrink-0",style:{width:P,height:P},children:[e.jsxs("svg",{width:P,height:P,viewBox:`0 0 ${P} ${P}`,className:"-rotate-90",children:[e.jsx("circle",{cx:o,cy:o,r:te,fill:"none",stroke:"currentColor",className:"text-bg-hi",strokeWidth:de}),e.jsx("circle",{cx:o,cy:o,r:te,fill:"none",stroke:ct,strokeWidth:de,strokeDasharray:c,strokeDashoffset:c*(1-n/100),strokeLinecap:"round"})]}),e.jsxs("div",{className:"absolute inset-0 flex items-center justify-center text-[13px] font-mono text-fg",children:[n.toFixed(0),"%"]})]}),e.jsxs("div",{className:"text-[11px] space-y-1 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-fg-faint",children:"reused (cache read)"}),e.jsx("span",{className:"text-fg-dim",children:L(t.cacheReadTokens)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-fg-faint",children:"written to cache"}),e.jsx("span",{className:"text-fg-dim",children:L(t.cacheCreationTokens)})]})]})]})]})}const bt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function vt({days:t,measure:s}){const{buckets:n,weekendShare:c,peakIdx:o}=f.useMemo(()=>{const a=new Array(7).fill(0);for(const l of t){const[p,x,j]=l.date.split("-").map(Number),T=new Date(p,x-1,j).getDay();a[T]+=R(l.totals,s)}const i=a.reduce((l,p)=>l+p,0),d=a[0]+a[6];let u=0;for(let l=1;l<7;l++)a[l]>a[u]&&(u=l);return{buckets:a,weekendShare:i>0?d/i*100:0,peakIdx:u}},[t,s]),r=Math.max(...n,1);return e.jsxs("div",{className:`${S} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Rhythm",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["weekend ",c.toFixed(0),"%"]})}),e.jsx("div",{className:"flex items-end gap-2 h-24",children:n.map((a,i)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end gap-1 h-full",children:[e.jsx("div",{className:`w-full rounded-t ${i===o?"bg-accent":"bg-rhythm"}`,style:{height:`${r>0?a/r*100:0}%`,minHeight:a>0?2:0}}),e.jsx("span",{className:"text-[9px] text-fg-faint font-mono",children:bt[i]})]},i))})]})}const Re="sm.history.analytics.measure",De="sm.history.analytics.range",Tt=["in","out","total","prompts","sessions","time","spend"],Ct=[30,60,90,0],yt=[];function Nt(){try{const t=localStorage.getItem(Re);if(t&&Tt.includes(t))return t}catch{}return"spend"}function wt(){try{const t=Number(localStorage.getItem(De));if(Ct.includes(t))return t}catch{}return 30}function Mt(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function St(){var xe;const[t,s]=f.useState(Nt),[n,c]=f.useState(wt),o=Be(h=>h.navFace),r=ge(h=>h.tabs),a=ge(h=>h.activeTabId),i=((xe=r.find(h=>h.id===a))==null?void 0:xe.cwd)??null,d=f.useRef(o),u=i?_e(i):null,[l,p]=f.useState(null),x=f.useMemo(()=>o==="project"&&u?new Set([u]):l,[o,u,l]),[j,T]=f.useState(null),[g,m]=f.useState(null),[b,W]=f.useState(!0),[y,se]=f.useState(0);f.useEffect(()=>{try{localStorage.setItem(Re,t)}catch{}},[t]),f.useEffect(()=>{try{localStorage.setItem(De,String(n))}catch{}},[n]),f.useEffect(()=>{let h=!1;return W(!0),window.api.history.dashboard({rangeDays:n}).then(v=>{h||(m(v),W(!1))}).catch(v=>{h||(W(!1),Oe.error(`History analytics failed to load: ${String(v)}`))}),()=>{h=!0}},[n,y]);const G=f.useRef(!1);f.useEffect(()=>{if(!G.current){G.current=!0;return}p(null),T(null)},[n]),f.useEffect(()=>{d.current!==o&&(d.current=o,o==="home"&&p(null))},[o]);const{projects:Y,resolving:z}=He(),V=f.useMemo(()=>{const h={};for(const v of Y)for(const C of v.encodedIds)h[C]=v.cwd;return h},[Y]),A=f.useMemo(()=>g&&!z?Qe(g.days,V):null,[g,V,z]),N=(A==null?void 0:A.days)??(g==null?void 0:g.days)??yt,ne=(A==null?void 0:A.excluded)??null,$=f.useMemo(()=>g?We({days:N,totals:g.totals,prevTotals:g.prevTotals},x):null,[g,N,x]),B=f.useMemo(()=>x===null?N:N.map(h=>({date:h.date,byProject:Object.fromEntries(Object.entries(h.byProject).filter(([v])=>x.has(v)))})),[N,x]),X=f.useMemo(()=>be(N,t),[N,t]),oe=f.useMemo(()=>be(B,t),[B,t]),Ee=f.useMemo(()=>B.map(h=>({date:h.date,values:Object.fromEntries(Object.entries(h.byProject).map(([v,C])=>[v,R(C,t)]))})),[B,t]),pe=f.useMemo(()=>$?Ye($,t):null,[$,t]),Z=f.useMemo(()=>{if(!g||!j)return null;const h=Mt(),v={},C={};for(const _ of N){const k=_.byProject[j];if(k){h.promptCount+=k.promptCount,h.inputTokens+=k.inputTokens,h.outputTokens+=k.outputTokens,h.cacheReadTokens+=k.cacheReadTokens,h.cacheCreationTokens+=k.cacheCreationTokens,h.toolCallCount+=k.toolCallCount,h.sessionCount+=k.sessionCount,h.errorCount+=k.errorCount,h.activeMinutes+=k.activeMinutes,h.estimatedCostUsd+=k.estimatedCostUsd;for(const[w,M]of Object.entries(k.byModel)){const E=v[w]??(v[w]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});E.inputTokens+=M.inputTokens,E.outputTokens+=M.outputTokens,E.cacheReadTokens+=M.cacheReadTokens,E.cacheCreationTokens+=M.cacheCreationTokens,E.costUsd+=M.costUsd}for(const[w,M]of Object.entries(k.toolBreakdown))C[w]=(C[w]??0)+M}}return{totals:h,byModel:v,toolBreakdown:C}},[g,N,j]);f.useEffect(()=>{j&&x!==null&&!x.has(j)&&T(null)},[j,x]);function Ue(h){p(v=>{const C=new Set(X.map(w=>w.projectDir)),_=v??new Set(C),k=new Set(_);return k.has(h)?k.delete(h):k.add(h),k.size>=C.size?null:k})}function Pe(h){p(new Set([h]))}function Fe(){p(null)}function Ae(){if(!g)return;const h=B.map(w=>{let M=0,E=0,he=0,fe=0,me=0;const ae={};for(const O of Object.values(w.byProject)){M+=O.estimatedCostUsd,E+=O.inputTokens,he+=O.outputTokens,fe+=O.cacheCreationTokens,me+=O.cacheReadTokens;for(const[je,q]of Object.entries(O.byModel)){const J=ae[je]??(ae[je]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});J.inputTokens+=q.inputTokens,J.outputTokens+=q.outputTokens,J.cacheReadTokens+=q.cacheReadTokens,J.cacheCreationTokens+=q.cacheCreationTokens}}return{date:w.date,costUsd:M,inputTokens:E,outputTokens:he,cacheCreationTokens:fe,cacheReadTokens:me,byModel:ae}}),v=Xe(h),C=new Blob([v],{type:"text/csv"}),_=URL.createObjectURL(C),k=document.createElement("a");k.href=_,k.download=`usage-history-${g.from}-${g.to}.csv`,k.click(),URL.revokeObjectURL(_)}return b&&!g?e.jsx(Ne,{}):g&&g.days.length===0?e.jsx(Ie,{title:"no sessions in range",hint:"Widen the range or check back after your next session."}):!g||!$||!pe?e.jsx(Ne,{}):e.jsxs("div",{"data-testid":"history-dashboard",className:"flex flex-col h-full",children:[e.jsxs("h1",{className:"font-serif text-[42px] leading-tight tracking-tight text-fg px-4 pt-4",children:["Where your ",e.jsx("em",{className:"italic text-accent",children:"Claude time"})," goes"]}),e.jsx(ot,{measure:t,onMeasure:s,range:n,onRange:c,projectsShown:x===null?X.length:x.size,projectsTotal:X.length,fromDate:g.from,toDate:g.to,onRefresh:()=>se(h=>h+1),onExport:Ae,exportDisabled:B.length===0}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-4 space-y-4",children:[e.jsx(rt,{measure:t,headline:pe,activeDays:$.activeDays,projectsTouched:oe.length,totalSessions:$.totals.sessionCount}),e.jsx(lt,{days:N}),ne&&et(ne)&&e.jsx("div",{"data-testid":"history-excluded-note",className:"rounded-[10px] border border-line bg-bg-hi px-3 py-2 text-[11.5px] font-mono text-fg-faint",title:"A project is a working directory. ~/.claude/projects holds one folder per path the CLI was ever launched from — throwaway /tmp dirs and test fixtures included — and a folder whose cwd can't be recovered from its transcripts is not a project. Their totals are stated here rather than silently folded into the charts.",children:tt(ne)}),o==="home"&&e.jsx(dt,{chips:X.map(h=>({projectDir:h.projectDir,value:h.value})),keep:x,onToggle:Ue,onIsolate:Pe,onShowAll:Fe}),e.jsx(ht,{days:Ee,measure:t,selected:j,onSelect:T}),e.jsx(ft,{rows:oe,measure:t,selected:j,onSelect:T}),j&&Z&&e.jsx(mt,{projectDir:j,totals:Z.totals,byModel:Z.byModel,toolBreakdown:Z.toolBreakdown,onClear:()=>T(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(jt,{byModelTotals:$.byModelTotals}),e.jsx(gt,{rows:oe}),e.jsx(kt,{totals:$.totals}),e.jsx(vt,{days:$.days,measure:t})]})]})]})}function Ne(){return e.jsxs("div",{className:"p-4 space-y-4 animate-pulse",children:[e.jsx("div",{className:"h-24 bg-bg-elev rounded"}),e.jsx("div",{className:"h-16 bg-bg-elev rounded"}),e.jsx("div",{className:"h-8 bg-bg-elev rounded"}),e.jsx("div",{className:"h-56 bg-bg-elev rounded"}),e.jsx("div",{className:"h-40 bg-bg-elev rounded"})]})}function $t(){return e.jsx(Le,{children:e.jsx(St,{})})}const Ut=f.memo($t);export{Ut as History};
@@ -1,3 +1,3 @@
1
- import{al as d,aC as X,ax as Z,aE as ee,az as F,ac as te,af as se,a6 as ae,aa as e,j as E,z as oe,w as ne,V as re,aq as ie,p as le}from"./index-fc_JjdxL.js";import{P as R}from"./Panel-Bw1FhRuF.js";import{L as ce}from"./ListDetail-DIXh-OLX.js";import{S as de}from"./SaveBar-CWr0O_w-.js";import{S as q}from"./ScopeSwitcher-CrBLbg8s.js";import{P as me}from"./ProvenanceBadge-Bw5vNVPT.js";import{u as pe,E as ue,s as he}from"./settingsSchema-BfhtZnGD.js";import{H as xe}from"./Library-Dc8Qst1R.js";import"./monaco-editor-BW5C4Iv1.js";const fe={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},I=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],ge=new Set(I),be=["command","http","prompt","agent","mcp_tool"],ye={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}};function ve(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const n=JSON.parse(t);return{full:n,hooks:n.hooks??{},err:null}}catch(n){return{full:{},hooks:{},err:n.message}}}function je(t,n){return JSON.stringify({...t,hooks:n},null,2)+`
1
+ import{al as d,aC as X,ax as Z,aE as ee,az as F,ac as te,af as se,a6 as ae,aa as e,j as E,z as oe,w as ne,V as re,aq as ie,p as le}from"./index-Dp4Rc--q.js";import{P as R}from"./Panel-I1s6ghPo.js";import{L as ce}from"./ListDetail-CmqiQ_io.js";import{S as de}from"./SaveBar-BGr9eZ4g.js";import{S as q}from"./ScopeSwitcher-ukl0qWaA.js";import{P as me}from"./ProvenanceBadge-BGcgBd8V.js";import{u as pe,E as ue,s as he}from"./settingsSchema-BLbssMYo.js";import{H as xe}from"./Library-CoiLZTKh.js";import"./monaco-editor-BW5C4Iv1.js";const fe={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},I=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],ge=new Set(I),be=["command","http","prompt","agent","mcp_tool"],ye={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}};function ve(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const n=JSON.parse(t);return{full:n,hooks:n.hooks??{},err:null}}catch(n){return{full:{},hooks:{},err:n.message}}}function je(t,n){return JSON.stringify({...t,hooks:n},null,2)+`
2
2
  `}function we(t,n){return(t[n]??[]).reduce((o,l)=>{var c;return o+(((c=l.hooks)==null?void 0:c.length)??0)},0)}function ke(){const t=X(),n=Z(),o=(n==null?void 0:n.cwd)??null,l=ee(a=>a.navFace),c=d.useRef(!1),f=d.useRef(l),[m,x]=d.useState(()=>l==="project"&&o?"project":"user"),[r,u]=d.useState("PreToolUse"),[s,S]=d.useState("effective");d.useEffect(()=>{if(f.current!==l){if(f.current=l,c.current){c.current=!1;return}x(l==="project"&&o?"project":"user")}},[l,o]),d.useEffect(()=>{l==="project"&&s==="library"&&S("effective")},[l,s]);const g=a=>{c.current=!0,x(a)},j=pe(ne,t,o),p=j[m]??null,w=F(a=>a.files),O=F(a=>a.setDraft),D=F(a=>a.saveJson),J=F(a=>a.revert),[W,N]=d.useState(null),[C,U]=d.useState(null),T=e.jsx(re,{options:[{key:"effective",label:"Effective"},{key:"events",label:"Events"},...l==="home"?[{key:"library",label:"Library"}]:[]],active:s,onChange:S}),M=d.useMemo(()=>{const a=te(se(w,j));return ae(a,["hooks"])??{kind:"object",children:{}}},[w,j]),$=(a,h)=>{var L;const i=j[m];if(!i)return;N(null);const k=((L=w[i])==null?void 0:L.draftRaw)??"";let v={};if(k.trim())try{v=JSON.parse(k)}catch{v={}}const Y=ie(v.hooks??{},a,h),Q={...v,hooks:Y};O(i,JSON.stringify(Q,null,2)+`
3
3
  `)};if(!t)return e.jsx(E,{title:"loading…"});if(s==="library")return e.jsx(R,{toolbar:T,children:e.jsx(xe,{})});if(m!=="user"&&!o)return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[T,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(q,{scopes:["user","project","local"],active:m,onChange:g})]}),children:e.jsx(E,{title:"no active project"})});if(!p)return e.jsx(E,{title:"loading…"});const b=w[p],{full:K,hooks:y,err:H}=b?ve(b.draftRaw):{full:{},hooks:{},err:null},A=Object.keys(y).filter(a=>!ge.has(a)),B=A.reduce((a,h)=>a+(y[h]??[]).reduce((i,k)=>{var v;return i+(((v=k.hooks)==null?void 0:v.length)??0)},0),0),P=a=>{N(null),O(p,je(K,a))},_=y[r]??[],V=()=>{P({...y,[r]:[..._,{matcher:"",hooks:[{type:"command",command:""}]}]})},G=(a,h)=>{const i=_.slice();i[a]=h,P({...y,[r]:i})},z=a=>{P({...y,[r]:_.filter((h,i)=>i!==a)})};return e.jsxs(R,{toolbar:e.jsxs(e.Fragment,{children:[T,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(q,{scopes:["user","project","local"],active:m,onChange:g}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:s==="effective"?`overrides → ${p}`:p}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),footer:b?e.jsx(de,{dirty:b.dirty,busy:b.busy,parseError:W||H||b.parseError,lastSavedAt:b.lastSavedAt,onSave:async()=>{N(null);const a=await D(p);a.ok||N(a.error??"save failed")},onRevert:()=>{N(null),J(p)}}):null,children:[s==="effective"?e.jsx(ue,{node:M,targetScope:m,onOverride:$,schema:he().rootedAt(["hooks"]),rootLabel:"hooks"}):e.jsxs("div",{className:"flex flex-col h-full",children:[B>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",B," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:A.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(ce,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:I.map(a=>{const h=we(y,a),i=fe[a],k=i?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:i.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",i.payload]}),i.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",i.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(oe,{content:k,align:"bottom-center",children:e.jsxs("button",{onClick:()=>u(a),title:i==null?void 0:i.when,className:`w-full text-left px-3 py-1 text-xs ${r===a?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:a}),h>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:h})]}),i?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:i.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},a)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:r}),e.jsx("button",{onClick:V,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+ add group"})]}),_.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):_.map((a,h)=>e.jsx(Ne,{group:a,jsonInvalid:!!H,onChange:i=>G(h,i),onRemove:()=>z(h),onTestFire:i=>U({event:r,matcher:a.matcher??"",command:i.command??""})},h))]})})]}),C?e.jsx(Fe,{event:C.event,matcher:C.matcher,command:C.command,onClose:()=>U(null)}):null]})}const Le=d.memo(ke);function Ne({group:t,jsonInvalid:n,onChange:o,onRemove:l,onTestFire:c}){const f=()=>o({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),m=(r,u)=>{const s=t.hooks.slice();s[r]=u,o({...t,hooks:s})},x=r=>o({...t,hooks:t.hooks.filter((u,s)=>s!==r)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx("input",{value:t.matcher??"",onChange:r=>o({...t,matcher:r.target.value}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:l,className:"text-fg-faint hover:text-red-400 text-xs",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((r,u)=>e.jsx(_e,{rule:r,jsonInvalid:n,onChange:s=>m(u,s),onRemove:()=>x(u),onTestFire:()=>c(r)},u)),e.jsx("button",{onClick:f,className:"text-xs text-fg-faint hover:text-fg",children:"+ add hook"})]})}function _e({rule:t,jsonInvalid:n,onChange:o,onRemove:l,onTestFire:c}){const f=s=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[s],m=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",x=t[m]??"",r=(t.args??[]).join(" "),u={type:"hook",name:x||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,onChange:s=>o({type:s.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:be.map(s=>e.jsx("option",{value:s,children:s},s))}),e.jsx(me,{interactive:!1,input:u}),e.jsx("input",{value:x,onChange:s=>o({...t,[m]:s.target.value}),placeholder:f(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${n?"border-red-500/70":x.trim()?"border-line":"border-yellow-600/50"}`}),n?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx("input",{value:t.timeout??"",onChange:s=>o({...t,timeout:s.target.value?Number(s.target.value):void 0}),placeholder:"timeout ms",className:"w-20 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),t.type==="command"?e.jsx("button",{onClick:c,disabled:n||!x.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:l,className:"text-fg-faint hover:text-red-400 text-xs",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx("input",{value:r,onChange:s=>o({...t,args:s.target.value.trim()?s.target.value.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx("input",{value:t.terminalSequence??"",onChange:s=>o({...t,terminalSequence:s.target.value||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function Se(t){return JSON.stringify(ye[t]??{},null,2)}function Ce(t,n){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const o=n&&typeof n=="object"&&"tool_name"in n?String(n.tool_name??""):null;if(o==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(o),target:o}}catch{return{matched:t===o,target:o,note:"matcher not valid regex; fell back to exact match"}}}function Fe({event:t,matcher:n,command:o,onClose:l}){const[c,f]=d.useState(()=>Se(t)),[m,x]=d.useState(!1),[r,u]=d.useState(null),[s,S]=d.useState(null);let g=null;try{JSON.parse(c)}catch(p){g=p.message}const j=async()=>{x(!0),u(null);let p=null;try{p=JSON.parse(c)}catch{}S(Ce(n,p));try{const w=await window.api.app.testFireHook({command:o,payload:c,timeoutMs:5e3});u(w)}finally{x(!1)}};return e.jsx(le,{open:!0,onClose:l,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:o})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:n||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),g?e.jsxs("span",{className:"text-red-400",children:["× ",g]}):null]}),e.jsx("textarea",{value:c,onChange:p=>f(p.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${g?"border-red-500/70":"border-line"}`})]}),s?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:s.matched?"text-green-400":"text-red-400",children:s.matched?"✓ match":"✗ no match"}),s.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',s.target,'"']}):null,s.note?e.jsx("div",{className:"text-fg-faint",children:s.note}):null]})]}):null,r?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",r.exitCode," · ",r.durationMs,"ms"]}),r.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stdout})]}):null,r.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:j,disabled:m||!!g||!o.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:m?"running…":"run"})]})]})})}export{Le as Hooks};
@@ -1 +1 @@
1
- import{al as r,ax as V,aG as P,aw as m,K as Y,ay as Q,aa as t,j as I,ar as W}from"./index-fc_JjdxL.js";import"./monaco-editor-BW5C4Iv1.js";function X(i){return i.hasMarketingPage?i.packagePrivate&&!i.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 $(i){return ee[i]}function D(i){const n=i.find(l=>l.subpath==="");return Z.map(l=>{const p=i.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(i){return i.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(i,n){for(const l of Object.values(i))if(l.cwd===n&&l.tag===j&&l.status==="active")return l;return null}function _(i){W(i),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function oe(){const i=V(),n=(i==null?void 0:i.cwd)??null,l=P(e=>e.sessions),p=P(e=>e.createPromptSession),h=P(e=>e.approveProposed),[o,C]=r.useState(null),[R,v]=r.useState(!1),[b,k]=r.useState(""),[E,H]=r.useState(!1),[B,M]=r.useState(!1),[u,A]=r.useState(null),[N,L]=r.useState(""),[f,T]=r.useState(""),[w,G]=r.useState("feature");r.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=r.useCallback(()=>{n&&(v(!1),window.api.bilkoHost.get(n).then(e=>{C(e),k(a=>{var s;return a||((s=e.bundleManifest)==null?void 0:s.slug)||e.defaultSlug}),v(!0)}).catch(e=>{v(!0),m.error(`Could not load bilko-host status: ${e instanceof Error?e.message:String(e)}`)}))},[n]);r.useEffect(()=>{C(null),k(""),H(!1),c()},[c]);const x=n?ae(l,n):null,O=r.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]),z=r.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(""),T(""),c()}).catch(s=>m.error(`Could not add document: ${s instanceof Error?s.message:String(s)}`))},[n,N,f,w,c]),F=r.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]),K=r.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]),U=r.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]),q=r.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}=Y({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"),Q.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(I,{title:"Open a project to host it on Bilko.run"});if(!R||!o)return null;const y=X(o);if(y.kind==="no-marketing-page")return t.jsx(I,{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,J=(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:J}),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=>k(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:O,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:()=>{q().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:K,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:()=>F(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:()=>U(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=>T(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=>G(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:z,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=r.memo(oe);export{le as HostBilko};
1
+ import{al as r,ax as V,aG as P,aw as m,K as Y,ay as Q,aa as t,j as I,ar as W}from"./index-Dp4Rc--q.js";import"./monaco-editor-BW5C4Iv1.js";function X(i){return i.hasMarketingPage?i.packagePrivate&&!i.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 $(i){return ee[i]}function D(i){const n=i.find(l=>l.subpath==="");return Z.map(l=>{const p=i.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(i){return i.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(i,n){for(const l of Object.values(i))if(l.cwd===n&&l.tag===j&&l.status==="active")return l;return null}function _(i){W(i),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function oe(){const i=V(),n=(i==null?void 0:i.cwd)??null,l=P(e=>e.sessions),p=P(e=>e.createPromptSession),h=P(e=>e.approveProposed),[o,C]=r.useState(null),[R,v]=r.useState(!1),[b,k]=r.useState(""),[E,H]=r.useState(!1),[B,M]=r.useState(!1),[u,A]=r.useState(null),[N,L]=r.useState(""),[f,T]=r.useState(""),[w,G]=r.useState("feature");r.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=r.useCallback(()=>{n&&(v(!1),window.api.bilkoHost.get(n).then(e=>{C(e),k(a=>{var s;return a||((s=e.bundleManifest)==null?void 0:s.slug)||e.defaultSlug}),v(!0)}).catch(e=>{v(!0),m.error(`Could not load bilko-host status: ${e instanceof Error?e.message:String(e)}`)}))},[n]);r.useEffect(()=>{C(null),k(""),H(!1),c()},[c]);const x=n?ae(l,n):null,O=r.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]),z=r.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(""),T(""),c()}).catch(s=>m.error(`Could not add document: ${s instanceof Error?s.message:String(s)}`))},[n,N,f,w,c]),F=r.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]),K=r.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]),U=r.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]),q=r.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}=Y({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"),Q.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(I,{title:"Open a project to host it on Bilko.run"});if(!R||!o)return null;const y=X(o);if(y.kind==="no-marketing-page")return t.jsx(I,{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,J=(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:J}),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=>k(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:O,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:()=>{q().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:K,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:()=>F(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:()=>U(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=>T(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=>G(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:z,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=r.memo(oe);export{le as HostBilko};