@openrig/cli 0.7.14 → 0.7.15

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 (334) hide show
  1. package/README.md +5 -5
  2. package/daemon/assets/plugins/openrig/.claude-plugin/plugin.json +1 -1
  3. package/daemon/assets/plugins/openrig/.codex-plugin/plugin.json +1 -1
  4. package/daemon/assets/plugins/openrig/.cursor-plugin/plugin.json +1 -1
  5. package/daemon/assets/plugins/openrig/README.md +2 -0
  6. package/daemon/assets/plugins/openrig/plugin.json +1 -1
  7. package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
  8. package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
  9. package/daemon/assets/plugins/openrig-core/skills/claude-compaction-restore/SKILL.md +4 -4
  10. package/daemon/assets/plugins/openrig-core/skills/messaging-the-human/SKILL.md +13 -4
  11. package/daemon/assets/plugins/openrig-core/skills/orienting-to-an-inherited-seat/CHANGELOG.md +10 -0
  12. package/daemon/assets/plugins/openrig-core/skills/orienting-to-an-inherited-seat/SKILL.md +12 -13
  13. package/daemon/context-packs/help/manifest.yaml +1 -1
  14. package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
  15. package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +41 -5
  16. package/daemon/context-packs/reference/getting-started.md +12 -11
  17. package/daemon/context-packs/reference/manifest.yaml +1 -1
  18. package/daemon/context-packs/reference/whats-new.md +150 -5
  19. package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
  20. package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
  21. package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
  22. package/daemon/context-packs/skills/claude-compaction-restore/SKILL.md +4 -4
  23. package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
  24. package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
  25. package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
  26. package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
  27. package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
  28. package/daemon/context-packs/skills/core/messaging-the-human/SKILL.md +13 -4
  29. package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
  30. package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
  31. package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
  32. package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
  33. package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
  34. package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
  35. package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
  36. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
  37. package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
  38. package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
  39. package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
  40. package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
  41. package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
  42. package/daemon/context-packs/skills/core/working-with-an-openrig-team/manifest.yaml +1 -1
  43. package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
  44. package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
  45. package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
  46. package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
  47. package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
  48. package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
  49. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/CHANGELOG.md +10 -0
  50. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/SKILL.md +12 -13
  51. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +3 -3
  52. package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
  53. package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
  54. package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
  55. package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
  56. package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
  57. package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
  58. package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
  59. package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
  60. package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
  61. package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
  62. package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
  63. package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
  64. package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
  65. package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
  66. package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
  67. package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
  68. package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
  69. package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
  70. package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
  71. package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
  72. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
  73. package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
  74. package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
  75. package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
  76. package/daemon/context-packs/world-example/manifest.yaml +1 -1
  77. package/daemon/context-packs/world-public/manifest.yaml +1 -1
  78. package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
  79. package/daemon/dist/adapters/codex-runtime-adapter.js +13 -3
  80. package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
  81. package/daemon/dist/adapters/community-harness-runtime-adapter.d.ts +2 -0
  82. package/daemon/dist/adapters/community-harness-runtime-adapter.d.ts.map +1 -1
  83. package/daemon/dist/adapters/community-harness-runtime-adapter.js +93 -36
  84. package/daemon/dist/adapters/community-harness-runtime-adapter.js.map +1 -1
  85. package/daemon/dist/adapters/pi-resume.d.ts +3 -0
  86. package/daemon/dist/adapters/pi-resume.d.ts.map +1 -1
  87. package/daemon/dist/adapters/pi-resume.js +99 -51
  88. package/daemon/dist/adapters/pi-resume.js.map +1 -1
  89. package/daemon/dist/adapters/pi-runner.d.ts +2 -1
  90. package/daemon/dist/adapters/pi-runner.d.ts.map +1 -1
  91. package/daemon/dist/adapters/pi-runner.js +15 -9
  92. package/daemon/dist/adapters/pi-runner.js.map +1 -1
  93. package/daemon/dist/adapters/pi-runtime-adapter.d.ts +4 -0
  94. package/daemon/dist/adapters/pi-runtime-adapter.d.ts.map +1 -1
  95. package/daemon/dist/adapters/pi-runtime-adapter.js +133 -75
  96. package/daemon/dist/adapters/pi-runtime-adapter.js.map +1 -1
  97. package/daemon/dist/adapters/tmux.d.ts +7 -0
  98. package/daemon/dist/adapters/tmux.d.ts.map +1 -1
  99. package/daemon/dist/adapters/tmux.js +26 -5
  100. package/daemon/dist/adapters/tmux.js.map +1 -1
  101. package/daemon/dist/build-info.js +3 -3
  102. package/daemon/dist/daemon-shutdown.d.ts +3 -0
  103. package/daemon/dist/daemon-shutdown.d.ts.map +1 -1
  104. package/daemon/dist/daemon-shutdown.js +6 -0
  105. package/daemon/dist/daemon-shutdown.js.map +1 -1
  106. package/daemon/dist/db/all-migrations.d.ts.map +1 -1
  107. package/daemon/dist/db/all-migrations.js +2 -0
  108. package/daemon/dist/db/all-migrations.js.map +1 -1
  109. package/daemon/dist/db/migrations/165_run_bound_activity_grants.d.ts +4 -0
  110. package/daemon/dist/db/migrations/165_run_bound_activity_grants.d.ts.map +1 -0
  111. package/daemon/dist/db/migrations/165_run_bound_activity_grants.js +14 -0
  112. package/daemon/dist/db/migrations/165_run_bound_activity_grants.js.map +1 -0
  113. package/daemon/dist/domain/activity-grants.d.ts +36 -3
  114. package/daemon/dist/domain/activity-grants.d.ts.map +1 -1
  115. package/daemon/dist/domain/activity-grants.js +188 -7
  116. package/daemon/dist/domain/activity-grants.js.map +1 -1
  117. package/daemon/dist/domain/applied-launch-observation-store.d.ts +2 -0
  118. package/daemon/dist/domain/applied-launch-observation-store.d.ts.map +1 -1
  119. package/daemon/dist/domain/applied-launch-observation-store.js +27 -16
  120. package/daemon/dist/domain/applied-launch-observation-store.js.map +1 -1
  121. package/daemon/dist/domain/claude-compaction-enforcer.js +2 -2
  122. package/daemon/dist/domain/claude-compaction-enforcer.js.map +1 -1
  123. package/daemon/dist/domain/codex-member-permissions.d.ts +2 -0
  124. package/daemon/dist/domain/codex-member-permissions.d.ts.map +1 -1
  125. package/daemon/dist/domain/codex-member-permissions.js +17 -9
  126. package/daemon/dist/domain/codex-member-permissions.js.map +1 -1
  127. package/daemon/dist/domain/codex-owned-plugin-trust.d.ts +6 -1
  128. package/daemon/dist/domain/codex-owned-plugin-trust.d.ts.map +1 -1
  129. package/daemon/dist/domain/codex-owned-plugin-trust.js +30 -9
  130. package/daemon/dist/domain/codex-owned-plugin-trust.js.map +1 -1
  131. package/daemon/dist/domain/execution-candidate-reader.d.ts +15 -5
  132. package/daemon/dist/domain/execution-candidate-reader.d.ts.map +1 -1
  133. package/daemon/dist/domain/execution-candidate-reader.js +36 -25
  134. package/daemon/dist/domain/execution-candidate-reader.js.map +1 -1
  135. package/daemon/dist/domain/execution-view.d.ts.map +1 -1
  136. package/daemon/dist/domain/execution-view.js +34 -11
  137. package/daemon/dist/domain/execution-view.js.map +1 -1
  138. package/daemon/dist/domain/gateway/destination-resolver.js +3 -3
  139. package/daemon/dist/domain/gateway/destination-resolver.js.map +1 -1
  140. package/daemon/dist/domain/gateway/slack/config.d.ts +2 -0
  141. package/daemon/dist/domain/gateway/slack/config.d.ts.map +1 -1
  142. package/daemon/dist/domain/gateway/slack/config.js +4 -0
  143. package/daemon/dist/domain/gateway/slack/config.js.map +1 -1
  144. package/daemon/dist/domain/gateway/slack/inbound.d.ts +11 -0
  145. package/daemon/dist/domain/gateway/slack/inbound.d.ts.map +1 -1
  146. package/daemon/dist/domain/gateway/slack/inbound.js +3 -0
  147. package/daemon/dist/domain/gateway/slack/inbound.js.map +1 -1
  148. package/daemon/dist/domain/gateway/slack/slack-api.d.ts +2 -0
  149. package/daemon/dist/domain/gateway/slack/slack-api.d.ts.map +1 -1
  150. package/daemon/dist/domain/gateway/slack/slack-api.js +4 -0
  151. package/daemon/dist/domain/gateway/slack/slack-api.js.map +1 -1
  152. package/daemon/dist/domain/gateway/slack/slack-delivery.d.ts +2 -0
  153. package/daemon/dist/domain/gateway/slack/slack-delivery.d.ts.map +1 -1
  154. package/daemon/dist/domain/gateway/slack/slack-delivery.js +2 -1
  155. package/daemon/dist/domain/gateway/slack/slack-delivery.js.map +1 -1
  156. package/daemon/dist/domain/gateway/slack/slack-subsystem.d.ts.map +1 -1
  157. package/daemon/dist/domain/gateway/slack/slack-subsystem.js +36 -2
  158. package/daemon/dist/domain/gateway/slack/slack-subsystem.js.map +1 -1
  159. package/daemon/dist/domain/gateway/slack/thread-routing.d.ts +5 -0
  160. package/daemon/dist/domain/gateway/slack/thread-routing.d.ts.map +1 -1
  161. package/daemon/dist/domain/gateway/slack/thread-routing.js +1 -1
  162. package/daemon/dist/domain/gateway/slack/thread-routing.js.map +1 -1
  163. package/daemon/dist/domain/health-passive-ceremony.d.ts.map +1 -1
  164. package/daemon/dist/domain/health-passive-ceremony.js +13 -7
  165. package/daemon/dist/domain/health-passive-ceremony.js.map +1 -1
  166. package/daemon/dist/domain/native-permission-store.d.ts +40 -0
  167. package/daemon/dist/domain/native-permission-store.d.ts.map +1 -1
  168. package/daemon/dist/domain/native-permission-store.js +108 -29
  169. package/daemon/dist/domain/native-permission-store.js.map +1 -1
  170. package/daemon/dist/domain/native-resume-probe.d.ts +33 -1
  171. package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
  172. package/daemon/dist/domain/native-resume-probe.js +127 -4
  173. package/daemon/dist/domain/native-resume-probe.js.map +1 -1
  174. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  175. package/daemon/dist/domain/node-inventory.js +214 -30
  176. package/daemon/dist/domain/node-inventory.js.map +1 -1
  177. package/daemon/dist/domain/permission-drift.d.ts +2 -1
  178. package/daemon/dist/domain/permission-drift.d.ts.map +1 -1
  179. package/daemon/dist/domain/permission-drift.js.map +1 -1
  180. package/daemon/dist/domain/permission-policy/persisted-restore-posture.d.ts +62 -0
  181. package/daemon/dist/domain/permission-policy/persisted-restore-posture.d.ts.map +1 -0
  182. package/daemon/dist/domain/permission-policy/persisted-restore-posture.js +117 -0
  183. package/daemon/dist/domain/permission-policy/persisted-restore-posture.js.map +1 -0
  184. package/daemon/dist/domain/policies/context-usage-threshold.d.ts.map +1 -1
  185. package/daemon/dist/domain/policies/context-usage-threshold.js +5 -1
  186. package/daemon/dist/domain/policies/context-usage-threshold.js.map +1 -1
  187. package/daemon/dist/domain/policies/types.d.ts +2 -0
  188. package/daemon/dist/domain/policies/types.d.ts.map +1 -1
  189. package/daemon/dist/domain/queue-repository.d.ts +9 -1
  190. package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
  191. package/daemon/dist/domain/queue-repository.js +24 -6
  192. package/daemon/dist/domain/queue-repository.js.map +1 -1
  193. package/daemon/dist/domain/queue-wake-ladder.d.ts +12 -0
  194. package/daemon/dist/domain/queue-wake-ladder.d.ts.map +1 -1
  195. package/daemon/dist/domain/queue-wake-ladder.js +27 -7
  196. package/daemon/dist/domain/queue-wake-ladder.js.map +1 -1
  197. package/daemon/dist/domain/rehydrate-eligibility.d.ts.map +1 -1
  198. package/daemon/dist/domain/rehydrate-eligibility.js +3 -2
  199. package/daemon/dist/domain/rehydrate-eligibility.js.map +1 -1
  200. package/daemon/dist/domain/reply-to-choice.d.ts +10 -0
  201. package/daemon/dist/domain/reply-to-choice.d.ts.map +1 -1
  202. package/daemon/dist/domain/reply-to-choice.js +23 -0
  203. package/daemon/dist/domain/reply-to-choice.js.map +1 -1
  204. package/daemon/dist/domain/restore-check-service.d.ts +5 -0
  205. package/daemon/dist/domain/restore-check-service.d.ts.map +1 -1
  206. package/daemon/dist/domain/restore-check-service.js +31 -6
  207. package/daemon/dist/domain/restore-check-service.js.map +1 -1
  208. package/daemon/dist/domain/restore-orchestrator.d.ts +1 -1
  209. package/daemon/dist/domain/restore-orchestrator.d.ts.map +1 -1
  210. package/daemon/dist/domain/restore-orchestrator.js +48 -80
  211. package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
  212. package/daemon/dist/domain/restore-preconditions.d.ts +2 -0
  213. package/daemon/dist/domain/restore-preconditions.d.ts.map +1 -1
  214. package/daemon/dist/domain/restore-preconditions.js +6 -0
  215. package/daemon/dist/domain/restore-preconditions.js.map +1 -1
  216. package/daemon/dist/domain/resume-metadata-refresher.d.ts +4 -0
  217. package/daemon/dist/domain/resume-metadata-refresher.d.ts.map +1 -1
  218. package/daemon/dist/domain/resume-metadata-refresher.js +7 -2
  219. package/daemon/dist/domain/resume-metadata-refresher.js.map +1 -1
  220. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  221. package/daemon/dist/domain/rigspec-instantiator.js +2 -1
  222. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  223. package/daemon/dist/domain/runner-grant-launch.d.ts +16 -0
  224. package/daemon/dist/domain/runner-grant-launch.d.ts.map +1 -0
  225. package/daemon/dist/domain/runner-grant-launch.js +86 -0
  226. package/daemon/dist/domain/runner-grant-launch.js.map +1 -0
  227. package/daemon/dist/domain/runtime-adapter.d.ts +2 -0
  228. package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
  229. package/daemon/dist/domain/runtime-adapter.js.map +1 -1
  230. package/daemon/dist/domain/seat-delivery-guard.d.ts +13 -1
  231. package/daemon/dist/domain/seat-delivery-guard.d.ts.map +1 -1
  232. package/daemon/dist/domain/seat-delivery-guard.js +53 -1
  233. package/daemon/dist/domain/seat-delivery-guard.js.map +1 -1
  234. package/daemon/dist/domain/seat-handover-service.d.ts.map +1 -1
  235. package/daemon/dist/domain/seat-handover-service.js +13 -7
  236. package/daemon/dist/domain/seat-handover-service.js.map +1 -1
  237. package/daemon/dist/domain/seat-identity-reconciler.d.ts +3 -0
  238. package/daemon/dist/domain/seat-identity-reconciler.d.ts.map +1 -1
  239. package/daemon/dist/domain/seat-identity-reconciler.js +34 -2
  240. package/daemon/dist/domain/seat-identity-reconciler.js.map +1 -1
  241. package/daemon/dist/domain/seat-lifecycle-service.d.ts.map +1 -1
  242. package/daemon/dist/domain/seat-lifecycle-service.js +5 -1
  243. package/daemon/dist/domain/seat-lifecycle-service.js.map +1 -1
  244. package/daemon/dist/domain/seat-runtime-switch-service.d.ts.map +1 -1
  245. package/daemon/dist/domain/seat-runtime-switch-service.js +15 -0
  246. package/daemon/dist/domain/seat-runtime-switch-service.js.map +1 -1
  247. package/daemon/dist/domain/session-registry.d.ts +2 -0
  248. package/daemon/dist/domain/session-registry.d.ts.map +1 -1
  249. package/daemon/dist/domain/session-registry.js +16 -0
  250. package/daemon/dist/domain/session-registry.js.map +1 -1
  251. package/daemon/dist/domain/session-transport.js +1 -1
  252. package/daemon/dist/domain/session-transport.js.map +1 -1
  253. package/daemon/dist/domain/skill-discovery.d.ts.map +1 -1
  254. package/daemon/dist/domain/skill-discovery.js +2 -1
  255. package/daemon/dist/domain/skill-discovery.js.map +1 -1
  256. package/daemon/dist/domain/slow-op-recorder.d.ts +3 -0
  257. package/daemon/dist/domain/slow-op-recorder.d.ts.map +1 -1
  258. package/daemon/dist/domain/slow-op-recorder.js +5 -0
  259. package/daemon/dist/domain/slow-op-recorder.js.map +1 -1
  260. package/daemon/dist/domain/startup-orchestrator.d.ts.map +1 -1
  261. package/daemon/dist/domain/startup-orchestrator.js +9 -0
  262. package/daemon/dist/domain/startup-orchestrator.js.map +1 -1
  263. package/daemon/dist/domain/successor-session-launcher.d.ts +3 -1
  264. package/daemon/dist/domain/successor-session-launcher.d.ts.map +1 -1
  265. package/daemon/dist/domain/successor-session-launcher.js +12 -2
  266. package/daemon/dist/domain/successor-session-launcher.js.map +1 -1
  267. package/daemon/dist/domain/sync-site-wrap.d.ts +13 -1
  268. package/daemon/dist/domain/sync-site-wrap.d.ts.map +1 -1
  269. package/daemon/dist/domain/sync-site-wrap.js +38 -0
  270. package/daemon/dist/domain/sync-site-wrap.js.map +1 -1
  271. package/daemon/dist/domain/terminal/terminal-service.d.ts +3 -1
  272. package/daemon/dist/domain/terminal/terminal-service.d.ts.map +1 -1
  273. package/daemon/dist/domain/terminal/terminal-service.js +17 -12
  274. package/daemon/dist/domain/terminal/terminal-service.js.map +1 -1
  275. package/daemon/dist/domain/types.d.ts +3 -0
  276. package/daemon/dist/domain/types.d.ts.map +1 -1
  277. package/daemon/dist/domain/types.js.map +1 -1
  278. package/daemon/dist/domain/watchdog-policy-engine.d.ts +5 -0
  279. package/daemon/dist/domain/watchdog-policy-engine.d.ts.map +1 -1
  280. package/daemon/dist/domain/watchdog-policy-engine.js +4 -0
  281. package/daemon/dist/domain/watchdog-policy-engine.js.map +1 -1
  282. package/daemon/dist/domain/workflow-runtime.d.ts +1 -1
  283. package/daemon/dist/routes/activity.d.ts.map +1 -1
  284. package/daemon/dist/routes/activity.js +34 -2
  285. package/daemon/dist/routes/activity.js.map +1 -1
  286. package/daemon/dist/routes/sessions.d.ts.map +1 -1
  287. package/daemon/dist/routes/sessions.js +9 -6
  288. package/daemon/dist/routes/sessions.js.map +1 -1
  289. package/daemon/dist/startup.d.ts.map +1 -1
  290. package/daemon/dist/startup.js +27 -9
  291. package/daemon/dist/startup.js.map +1 -1
  292. package/daemon/docs/reference/agent-startup-guide.md +1 -1
  293. package/daemon/docs/reference/bundle-formats.md +6 -4
  294. package/daemon/docs/reference/daemon-http-clients.md +2 -1
  295. package/daemon/docs/reference/getting-started.md +12 -11
  296. package/daemon/docs/reference/harness-runner-contract.md +27 -1
  297. package/daemon/docs/reference/health-diagnosis.md +5 -3
  298. package/daemon/docs/reference/keeping-a-watch.md +14 -9
  299. package/daemon/docs/reference/quickstart.md +2 -2
  300. package/daemon/docs/reference/slack-app-setup.md +4 -0
  301. package/daemon/docs/reference/whats-new.md +150 -5
  302. package/daemon/specs/agents/shared/skills/core/messaging-the-human/SKILL.md +13 -4
  303. package/dist/build-info.js +3 -3
  304. package/dist/commands/down.d.ts.map +1 -1
  305. package/dist/commands/down.js +2 -1
  306. package/dist/commands/down.js.map +1 -1
  307. package/dist/commands/ps.d.ts +1 -0
  308. package/dist/commands/ps.d.ts.map +1 -1
  309. package/dist/commands/ps.js +2 -1
  310. package/dist/commands/ps.js.map +1 -1
  311. package/dist/commands/slack.d.ts.map +1 -1
  312. package/dist/commands/slack.js +2 -0
  313. package/dist/commands/slack.js.map +1 -1
  314. package/dist/daemon-lifecycle.d.ts.map +1 -1
  315. package/dist/daemon-lifecycle.js +10 -5
  316. package/dist/daemon-lifecycle.js.map +1 -1
  317. package/dist/lib/work-install.d.ts.map +1 -1
  318. package/dist/lib/work-install.js +7 -3
  319. package/dist/lib/work-install.js.map +1 -1
  320. package/dist/mcp-server.d.ts.map +1 -1
  321. package/dist/mcp-server.js +27 -13
  322. package/dist/mcp-server.js.map +1 -1
  323. package/package.json +1 -1
  324. package/tui/dist/connected-assistants.js +1 -1
  325. package/tui/dist/connected-assistants.js.map +1 -1
  326. package/tui/dist/main.js +4 -3
  327. package/tui/dist/main.js.map +1 -1
  328. package/tui/dist/render.d.ts.map +1 -1
  329. package/tui/dist/render.js +4 -1
  330. package/tui/dist/render.js.map +1 -1
  331. package/ui/dist/assets/index-BX8TUZ0E.css +32 -0
  332. package/ui/dist/assets/{index-BOYrLyfQ.js → index-BvUEh33d.js} +1 -1
  333. package/ui/dist/index.html +2 -2
  334. package/ui/dist/assets/index-DqSRu4OY.css +0 -32
@@ -584,7 +584,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
584
584
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
585
585
 
586
586
  For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return E.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},dwe="DialogDescriptionWarning",hwe=({contentRef:e,descriptionId:t})=>{const s=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${HV(dwe).contentName}}.`;return E.useEffect(()=>{var a;const r=(a=e.current)==null?void 0:a.getAttribute("aria-describedby");t&&r&&(document.getElementById(t)||console.warn(s))},[s,e,t]),null},fwe=RV,pwe=TV,mwe=MV,UV=LV,VV=OV,WV=DV,GV=BV,gwe=FV;const Gy=fwe,xwe=pwe,vwe=mwe,KV=E.forwardRef(({className:e,...t},n)=>i.jsx(UV,{ref:n,className:le("fixed inset-0 z-50 bg-black/20 backdrop-blur-[8px]",e),...t}));KV.displayName=UV.displayName;const Bp=E.forwardRef(({className:e,children:t,hideCloseButton:n,...s},r)=>i.jsxs(vwe,{children:[i.jsx(KV,{}),i.jsxs(VV,{ref:r,className:le("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 vellum-heavy p-6 shadow-[0_20px_40px_rgba(46,52,46,0.06)] border border-outline-variant",e),...s,children:[t,!n&&i.jsxs(gwe,{className:"absolute right-4 top-4 opacity-70 transition-opacity duration-150 hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 focus:ring-offset-background disabled:pointer-events-none",children:[i.jsx(OE,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bp.displayName=VV.displayName;const Ky=({className:e,...t})=>i.jsx("div",{className:le("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ky.displayName="DialogHeader";const Yy=({className:e,...t})=>i.jsx("div",{className:le("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});Yy.displayName="DialogFooter";const qp=E.forwardRef(({className:e,...t},n)=>i.jsx(WV,{ref:n,className:le("text-lg font-semibold leading-none tracking-tight",e),...t}));qp.displayName=WV.displayName;const Fp=E.forwardRef(({className:e,...t},n)=>i.jsx(GV,{ref:n,className:le("text-sm text-foreground-muted",e),...t}));Fp.displayName=GV.displayName;function ywe(e){return Re({queryKey:["packages",e],queryFn:async()=>{const t=await fetch(`/api/packages/${e}`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function bwe(e){return Re({queryKey:["packages",e,"installs"],queryFn:async()=>{const t=await fetch(`/api/packages/${e}/installs`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function _we(e){return Re({queryKey:["installs",e,"journal"],queryFn:async()=>{const t=await fetch(`/api/packages/installs/${e}/journal`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function wwe(e){const t=bt();return Xt({mutationFn:async n=>{const s=await fetch(`/api/packages/${n}/rollback`,{method:"POST"});if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()},onSuccess:()=>{t.invalidateQueries({queryKey:["packages",e,"installs"]}),t.invalidateQueries({queryKey:["installs"]})}})}function Swe(e){switch(e){case"applied":return"bg-success";case"rolled_back":return"bg-warning";case"failed":return"bg-destructive";default:return"bg-foreground-muted"}}function jwe(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return e.toUpperCase()}}function Nwe({installId:e}){const{data:t,isPending:n,isError:s}=_we(e);return n?i.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"Loading journal..."}):s?i.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-destructive","data-testid":"journal-error",children:"Failed to load journal entries"}):!t||t.length===0?i.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"No journal entries"}):i.jsx("div",{className:"pl-spacing-6 py-spacing-2 space-y-spacing-1","data-testid":"journal-entries",children:t.map(r=>i.jsxs("div",{"data-testid":"journal-entry",className:"flex items-center gap-spacing-3 text-label-sm font-mono py-spacing-1 border-b border-foreground/6 last:border-0",children:[i.jsx("span",{className:"text-foreground-muted w-6 text-right",children:r.seq}),i.jsx("span",{className:"uppercase",children:r.action}),i.jsx("span",{className:"text-foreground-muted",children:r.exportType}),i.jsx("span",{className:"text-foreground-muted truncate max-w-[200px]",children:r.targetPath}),i.jsx("span",{className:"text-foreground-muted ml-auto",children:r.status})]},r.id))})}function kwe({install:e,onRollback:t}){const[n,s]=E.useState(!1);return i.jsxs("div",{"data-testid":"install-row",className:"card-dark p-spacing-4 mb-spacing-2",children:[i.jsxs("div",{className:"flex items-center gap-spacing-4",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-spacing-3 mb-spacing-1",children:[i.jsx("span",{className:"font-mono text-label-sm text-foreground-muted",children:e.createdAt}),i.jsx("span",{"data-testid":"install-status-badge",className:le("inline-block px-spacing-2 py-px text-label-sm uppercase",Swe(e.status)),children:jwe(e.status)})]}),i.jsx("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:e.targetRoot}),i.jsxs("div",{className:"flex items-center gap-spacing-3 mt-spacing-1 text-label-sm",children:[i.jsxs("span",{"data-testid":"applied-count",children:[i.jsx("span",{className:"font-mono",children:e.appliedCount})," applied"]}),i.jsx("span",{"data-testid":"deferred-placeholder",className:"text-foreground-muted",children:"— deferred"})]})]}),i.jsxs("div",{className:"flex items-center gap-spacing-2 shrink-0",children:[i.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"expand-btn",onClick:()=>s(!n),children:n?"COLLAPSE":"EXPAND"}),e.status==="applied"&&i.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"rollback-btn",onClick:()=>t(e.id),children:"ROLLBACK"})]})]}),n&&i.jsx(Nwe,{installId:e.id})]})}function Cwe(){var b;const{packageId:e}=Bn({strict:!1}),{data:t,isPending:n,error:s}=ywe(e),{data:r,isPending:a,error:o}=bwe(e),c=wwe(e),[d,h]=E.useState(null),[p,f]=E.useState(!1),g=_=>{h(_),f(!0)},x=()=>{d&&c.mutate(d,{onSuccess:()=>{f(!1),h(null)}})};if(n||a)return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"detail-loading",children:[i.jsx("div",{className:"h-8 w-48 shimmer mb-spacing-4"}),i.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-4",children:[i.jsx("div",{className:"h-6 w-64 shimmer-dark mb-spacing-3"}),i.jsx("div",{className:"h-4 w-full shimmer-dark"})]})]})});if(s)return i.jsx(ht,{children:i.jsx("div",{"data-testid":"detail-error",children:i.jsx("p",{className:"text-destructive",children:s.message})})});if(o)return i.jsx(ht,{children:i.jsx("div",{"data-testid":"installs-error",children:i.jsx("p",{className:"text-destructive",children:"Failed to load install history"})})});const y=r??[];return i.jsx(ht,{children:i.jsxs("div",{children:[t&&i.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-6","data-testid":"package-header",children:[i.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[i.jsxs("h2",{className:"text-headline-lg uppercase",children:[t.name," (Legacy)"]}),i.jsxs("span",{className:"text-label-md font-mono text-foreground-muted-on-dark",children:["v",t.version]})]}),i.jsxs("div",{className:"text-label-sm text-foreground-muted-on-dark mb-spacing-2",children:["SOURCE"," ",i.jsx("span",{className:"font-mono text-foreground-on-dark","data-testid":"package-source",children:t.sourceRef})]}),t.summary&&i.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark",children:t.summary})]}),i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-4",children:"INSTALL HISTORY"}),y.length===0?i.jsx("div",{"data-testid":"empty-installs",className:"text-body-md text-foreground-muted",children:"No installs yet"}):i.jsx("div",{"data-testid":"install-list",children:y.map(_=>i.jsx(kwe,{install:_,onRollback:g},_.id))}),i.jsx(Gy,{open:p,onOpenChange:_=>{c.isPending||(f(_),_||c.reset())},children:i.jsxs(Bp,{"data-testid":"rollback-dialog",onPointerDownOutside:_=>{c.isPending&&_.preventDefault()},onEscapeKeyDown:_=>{c.isPending&&_.preventDefault()},hideCloseButton:c.isPending,children:[i.jsxs(Ky,{children:[i.jsx(qp,{className:"text-headline-md uppercase",children:"CONFIRM ROLLBACK"}),i.jsx(Fp,{children:"This will roll back the install and restore previous file states. This action cannot be undone."})]}),c.isError&&i.jsxs("p",{className:"text-destructive text-label-sm","data-testid":"rollback-error",children:["Rollback failed: ",((b=c.error)==null?void 0:b.message)??"Unknown error"]}),i.jsxs(Yy,{children:[i.jsx(Ne,{variant:"ghost",onClick:()=>{c.reset(),f(!1)},"data-testid":"rollback-cancel",disabled:c.isPending,children:"CANCEL"}),i.jsx(Ne,{variant:"destructive",onClick:x,"data-testid":"rollback-confirm",disabled:c.isPending,children:c.isPending?"ROLLING BACK...":"ROLLBACK"})]})]})})]})})}function Ewe(e){switch(e){case"installed":return"bg-success";case"missing":return"bg-destructive";case"unsupported":return"bg-warning";case"unknown":return"bg-warning";default:return"bg-foreground-muted"}}function Rwe(e){switch(e){case"installed":return"OK";case"missing":return"MISSING";case"unsupported":return"MANUAL";case"unknown":return"UNKNOWN";default:return e.toUpperCase()}}function Awe({results:e}){return e.length===0?i.jsx("div",{className:"text-body-sm text-foreground-muted","data-testid":"no-requirements",children:"No requirements declared."}):i.jsx("div",{className:"space-y-spacing-1","data-testid":"requirements-panel",children:e.map(t=>i.jsxs("div",{"data-testid":"requirement-row",className:"flex items-center gap-spacing-3 py-spacing-1 text-label-sm font-mono",children:[i.jsx("span",{"data-testid":"requirement-dot",className:le("w-2 h-2 shrink-0",Ewe(t.status))}),i.jsx("span",{"data-testid":"requirement-status",className:"w-16 uppercase",children:Rwe(t.status)}),i.jsx("span",{className:"text-foreground-muted w-24",children:t.kind}),i.jsx("span",{children:t.name}),t.detectedPath&&i.jsx("span",{className:"text-foreground-muted ml-auto truncate max-w-[200px]",children:t.detectedPath})]},`${t.kind}:${t.name}`))})}function YV(e,t){var s,r;const n=((s=e.stages)==null?void 0:s.flatMap(a=>{const o=a.detail;if(!o)return[];const c=[];return Array.isArray(o.errors)&&c.push(...o.errors.filter(d=>typeof d=="string")),typeof o.error=="string"&&c.push(o.error),c}))??[];return((r=e.errors)==null?void 0:r.find(a=>typeof a=="string"))??n[0]??e.error??`HTTP ${t}`}function Twe(){return Xt({mutationFn:async({sourceRef:e})=>{const t=await fetch("/api/bootstrap/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:e})});if(!t.ok){const n=await t.json().catch(()=>({})),s=new Error(YV(n,t.status));throw s.data=n,s}return t.json()}})}function Iwe(){const e=bt();return Xt({mutationFn:async({sourceRef:t,autoApprove:n,approvedActionKeys:s})=>{const r=await fetch("/api/bootstrap/apply",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,autoApprove:n,approvedActionKeys:s})}),a=await r.json();if(!r.ok){const o=new Error(YV(a,r.status));throw o.data=a,o}return a},onSuccess:()=>{e.invalidateQueries({queryKey:["rigs","summary"]})}})}const Mwe=["ENTER","PLAN","REVIEW","APPLY"],Lwe=Mwe.map((e,t)=>({num:t+1,label:e}));function Owe(e){switch(e){case"enter":return 1;case"planning":return 2;case"planned":return 3;case"applying":return 4;case"done":case"error":return 4;default:return 1}}function Pwe(){const e=Ut(),{bootstrapSourceRef:t,setBootstrapSourceRef:n}=vp(),[s,r]=E.useState("enter"),[a,o]=E.useState(()=>t),[c,d]=E.useState(null),[h,p]=E.useState(new Set),[f,g]=E.useState(!1),[x,y]=E.useState(null),b=Twe(),_=Iwe();E.useEffect(()=>{n(a)},[n,a]);const w=async()=>{if(a.trim()){r("planning");try{const q=await b.mutateAsync({sourceRef:a.trim()});d(q),p(new Set(q.actionKeys??[])),r("planned")}catch(q){y(q.message),r("error")}}},k=async()=>{r("applying");try{const q=await _.mutateAsync({sourceRef:a.trim(),autoApprove:f,approvedActionKeys:f?void 0:[...h]});d(q),r("done")}catch(q){y(q.message),r("error")}},N=()=>{r("enter"),o(""),d(null),p(new Set),g(!1),y(null),b.reset(),_.reset()},C=c==null?void 0:c.stages.find(q=>q.stage==="probe_requirements"),R=C==null?void 0:C.detail,T=(R==null?void 0:R.results)??[],A=c==null?void 0:c.stages.find(q=>q.stage==="build_install_plan"),I=A==null?void 0:A.detail,M=(I==null?void 0:I.actions)??[],B=(A==null?void 0:A.status)==="blocked",P=M.some(q=>q.classification!=="manual_only"&&q.commandPreview)&&h.size===0&&!f;return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"bootstrap-wizard",className:"space-y-8",children:[i.jsx(Tn,{eyebrow:"Bootstrap",title:"Bootstrap",description:"Plan environment requirements, approve install actions, then import the rig into a running topology."}),i.jsx(hV,{"data-testid":"step-indicator",steps:Lwe,currentStep:Owe(s)}),s==="enter"&&i.jsx(gr,{title:"Source",description:"Provide a rig spec or bundle path. Bootstrap will inspect requirements before it imports anything.",children:i.jsxs("div",{"data-testid":"step-enter",children:[i.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"SPEC OR BUNDLE PATH"}),i.jsx(TA,{"data-testid":"spec-input",type:"text",value:a,onChange:q=>o(q.target.value),placeholder:"/path/to/rig.yaml or /path/to/bundle.rigbundle",className:"font-mono text-body-md"}),i.jsxs("p",{className:"text-label-sm text-foreground-muted mt-spacing-1",children:["Accepts .yaml rig specs or .rigbundle archives."," ",i.jsx("span",{role:"link",tabIndex:0,className:"text-primary cursor-pointer","data-testid":"inspect-link",onClick:()=>e({to:"/bundles/inspect"}),onKeyDown:q=>{q.key==="Enter"&&e({to:"/bundles/inspect"})},children:"Inspect a bundle first →"})]}),i.jsx("div",{className:"mt-spacing-4",children:i.jsx(Ne,{variant:"tactical",onClick:w,disabled:!a.trim(),"data-testid":"plan-btn",children:"PLAN"})})]})}),s==="planning"&&i.jsx("div",{"data-testid":"step-planning",className:"text-body-md text-foreground-muted",children:"Planning..."}),s==="planned"&&c&&i.jsx(gr,{title:"Plan Review",description:"Review requirement probe results and approve the install actions that bootstrap should execute.",children:i.jsxs("div",{"data-testid":"step-planned",children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"STAGES"}),i.jsx("div",{className:"space-y-spacing-1 mb-spacing-6","data-testid":"stage-list",children:c.stages.map(q=>i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"stage-row",children:[i.jsx("span",{className:q.status==="ok"?"text-success":q.status==="blocked"?"text-warning":"text-foreground-muted",children:q.status.toUpperCase()}),i.jsx("span",{children:q.stage})]},q.stage))}),T.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"REQUIREMENTS"}),i.jsx("div",{className:"mb-spacing-6",children:i.jsx(Awe,{results:T})})]}),M.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"ACTIONS"}),i.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:M.map(q=>i.jsxs("label",{className:"flex items-center gap-spacing-3 text-label-sm font-mono cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:f||h.has(q.key),disabled:f||q.classification==="manual_only",onChange:$=>{const F=new Set(h);$.target.checked?F.add(q.key):F.delete(q.key),p(F)}}),i.jsx("span",{className:q.classification==="manual_only"?"text-warning":"",children:q.requirementName}),q.commandPreview&&i.jsx("span",{className:"text-foreground-muted",children:q.commandPreview})]},q.key))}),i.jsxs("label",{className:"flex items-center gap-spacing-2 text-label-sm mb-spacing-4",children:[i.jsx("input",{type:"checkbox",checked:f,onChange:q=>g(q.target.checked)}),"Auto-approve all trusted actions"]})]}),B&&i.jsx("div",{className:"text-warning text-label-sm mb-spacing-4","data-testid":"blocked-warning",children:"Manual requirements must be resolved before bootstrap can proceed."}),c.warnings.length>0&&i.jsx("div",{className:"mb-spacing-4",children:c.warnings.map((q,$)=>i.jsx("div",{className:"text-warning text-label-sm",children:q},$))}),i.jsx(Ne,{variant:"tactical",onClick:k,disabled:B||P,title:B?"Manual requirements must be resolved":P?"Select actions to approve":void 0,"data-testid":"apply-btn",children:"APPLY"})]})}),s==="applying"&&c&&i.jsx(gr,{title:"Applying",description:"Bootstrap is executing the approved actions and importing the rig.",children:i.jsxs("div",{"data-testid":"step-applying",children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"APPLYING"}),i.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"applying-checklist",children:[c.stages.map(q=>i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[i.jsx("span",{className:"text-foreground-muted",children:"○"}),i.jsx("span",{children:q.stage})]},q.stage)),i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[i.jsx("span",{className:"text-foreground-muted",children:"○"}),i.jsx("span",{children:"execute_external_installs"})]}),i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[i.jsx("span",{className:"text-foreground-muted",children:"○"}),i.jsx("span",{children:"install_packages"})]}),i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[i.jsx("span",{className:"text-foreground-muted",children:"○"}),i.jsx("span",{children:"import_rig"})]})]}),i.jsx("p",{className:"text-body-sm text-foreground-muted",children:"Bootstrapping..."})]})}),s==="done"&&c&&i.jsx(gr,{title:"Result",description:"Bootstrap finished and returned the managed rig identity.",children:i.jsxs("div",{"data-testid":"step-done",children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:c.status==="completed"?"BOOTSTRAP COMPLETE":"BOOTSTRAP PARTIAL"}),i.jsxs("div",{className:"text-label-sm font-mono space-y-spacing-1 mb-spacing-4",children:[i.jsxs("div",{children:["Status: ",i.jsx("span",{className:c.status==="completed"?"text-success":"text-warning",children:c.status.toUpperCase()})]}),c.rigId&&i.jsxs("div",{"data-testid":"result-rig-id",children:["Rig: ",c.rigId]})]}),c.rigId&&i.jsx(Ne,{variant:"tactical","data-testid":"view-rig-btn",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:c.rigId}}),children:"VIEW RIG"})]})}),s==="error"&&i.jsx(gr,{title:"Bootstrap Error",description:"Bootstrap could not complete. Fix the issue and retry the plan.",children:i.jsxs("div",{"data-testid":"step-error",children:[i.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:x}),i.jsx(Ne,{variant:"tactical",onClick:N,"data-testid":"try-again-btn",children:"TRY AGAIN"})]})})]})})}function Dwe(){const{currentAgentDraft:e,selectedAgentDraft:t,saveAgentDraft:n,rememberAgentDraft:s,clearSelectedAgentDraft:r}=vp(),[a,o]=E.useState(()=>(t==null?void 0:t.yaml)??(e==null?void 0:e.yaml)??""),[c,d]=E.useState("idle"),[h,p]=E.useState([]);E.useEffect(()=>{n(a)},[n,a]),E.useEffect(()=>{t&&(o(t.yaml),r())},[r,t]);const f=async()=>{s(a),d("pending"),p([]);try{const g=await fetch("/api/agents/validate",{method:"POST",headers:{"Content-Type":"text/yaml"},body:a}),x=await g.json().catch(()=>({}));if(g.ok&&x.valid){d("valid");return}p(x.errors??["Validation failed"]),d("invalid")}catch{p(["Validation request failed"]),d("error")}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"agent-spec-validate-flow",className:"space-y-8",children:[i.jsx(Tn,{eyebrow:"Agent Spec Validation",title:"VALIDATE AGENT",description:"Check an AgentSpec before you use it in a rig."}),i.jsxs(gr,{title:"Agent YAML",description:"Paste or refine an AgentSpec draft, then validate it against the daemon contract.",children:[i.jsx(IA,{"data-testid":"agent-spec-yaml-input",value:a,onChange:g=>o(g.target.value),placeholder:"Paste agent.yaml here...",rows:16,className:"bg-background font-mono text-body-sm"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:i.jsx(Ne,{variant:"tactical","data-testid":"agent-spec-validate-btn",onClick:f,disabled:!a.trim()||c==="pending",children:c==="pending"?"VALIDATING...":"VALIDATE AGENTSPEC"})}),c==="valid"&&i.jsx(os,{className:"mt-spacing-1","data-testid":"agent-spec-valid",children:i.jsx(Yn,{className:"text-primary",children:"AgentSpec valid."})}),(c==="invalid"||c==="error")&&i.jsx(os,{className:"mt-spacing-1","data-testid":"agent-spec-invalid",children:i.jsx(Yn,{children:i.jsx("ul",{className:"list-disc pl-5",children:h.map(g=>i.jsx("li",{children:g},g))})})})]})]})})}async function $we(e,t="draft"){var s;const n=await fetch("/api/specs/review/rig",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(((s=r.errors)==null?void 0:s.join("; "))??`HTTP ${n.status}`)}return n.json()}async function Bwe(e,t="draft"){var s;const n=await fetch("/api/specs/review/agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(((s=r.errors)==null?void 0:s.join("; "))??`HTTP ${n.status}`)}return n.json()}function QV(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t}function XV(e,t="draft"){return Re({queryKey:["spec-review","rig",e?QV(e):null,t],queryFn:()=>$we(e,t),enabled:!!e})}function qwe(e,t="draft"){return Re({queryKey:["spec-review","agent",e?QV(e):null,t],queryFn:()=>Bwe(e,t),enabled:!!e})}const Fwe=160,zwe=48,d8=200,Hwe=100;function Uwe(e){switch(e){case"claude-code":return"#d4c4a8";case"codex":return"#b8c9d4";case"terminal":return"#c4c4c4";default:return"#e0ddd4"}}function Vwe(e){const t=new Map,n=[];for(const a of e)a.pod?(t.has(a.pod)||t.set(a.pod,[]),t.get(a.pod).push(a)):n.push(a);const s=[];let r=0;for(const[,a]of t)a.forEach((o,c)=>{s.push({id:o.id,x:c*d8,y:r})}),r+=Hwe;return n.forEach((a,o)=>{s.push({id:a.id,x:o*d8,y:r})}),s}function Wwe({graph:e,testId:t}){const n=e??{nodes:[],edges:[]},{nodes:s,edges:r}=E.useMemo(()=>{const a=Vwe(n.nodes),o=new Map(a.map(h=>[h.id,h])),c=n.nodes.map(h=>{const p=o.get(h.id)??{x:0,y:0};return{id:h.id,type:"default",position:{x:p.x,y:p.y},data:{label:i.jsxs("div",{className:"flex h-full min-w-0 flex-col justify-center gap-1 font-mono leading-tight",children:[i.jsxs("div",{className:"truncate text-[10px] font-bold text-on-surface",children:[h.pod?`${h.pod} / `:"",h.label]}),i.jsx(Ps,{runtime:h.runtime,size:"xs",compact:!0,variant:"inline"})]})},style:{backgroundColor:Uwe(h.runtime),border:"1px solid #8a8577",fontSize:11,fontFamily:"monospace",width:Fwe,height:zwe}}}),d=n.edges.map((h,p)=>({id:`e-${p}`,source:h.source,target:h.target,label:h.kind,labelStyle:{fontSize:9,fontFamily:"monospace"},style:{strokeDasharray:"4 4",stroke:"#8a8577"}}));return{nodes:c,edges:d}},[n]);return i.jsx("div",{"data-testid":t??"spec-topology-preview",className:"w-full h-[400px] bg-background border border-outline-variant",children:i.jsxs(Cp,{nodes:s,edges:r,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(zR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(Ep,{showInteractive:!1})]})})}function Gwe({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=ry();return i.jsx("button",{type:"button","data-testid":r??"sub-spec-trigger",onClick:()=>a({type:"sub-spec",data:e}),className:n??"text-left",style:s,children:t})}function Kwe(e){const n=(e.startsWith("local:")?e.slice(6):e).replace(/^(builtin|user|fork):/,""),s=n.startsWith("agents/")?n.slice(7):n,r=s.split("@")[0]??s,a=e.startsWith("fork:")?"fork":e.startsWith("builtin:")?"builtin":"user_file";return{specName:r,source:a}}function DA({review:e,yaml:t,testIdPrefix:n="",yamlTestId:s,showEnvironmentTab:r,onMemberClick:a}){var y,b,_;const o=r&&!!(e!=null&&e.services),c=o?["topology","configuration","environment","yaml"]:["topology","configuration","yaml"],[d,h]=E.useState("topology"),p=(e==null?void 0:e.pods)??[],f=(e==null?void 0:e.nodes)??[],g=(e==null?void 0:e.edges)??[],x=n?`${n}-`:"";return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"flex gap-1 border-b border-outline-variant",children:c.map(w=>i.jsx("button",{"data-testid":`${x}tab-${w}`,onClick:()=>h(w),className:`px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider transition-colors ${d===w?"border-b-2 border-on-surface text-on-surface font-bold":"text-on-surface-variant hover:text-on-surface"}`,children:w},w))}),d==="topology"&&e&&i.jsx(Wwe,{graph:e.graph,testId:`${x}topology-preview`}),d==="configuration"&&e&&i.jsxs("div",{"data-testid":`${x}config-tables`,className:"space-y-4",children:[e.format==="pod_aware"&&p.map(w=>i.jsxs("div",{className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:w.label??w.id}),i.jsxs("table",{className:"w-full font-mono text-[10px]",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-outline-variant text-on-surface-variant",children:[i.jsx("th",{className:"text-left py-1",children:"Member"}),i.jsx("th",{className:"text-left py-1",children:"Agent Ref"}),i.jsx("th",{className:"text-left py-1",children:"Runtime"}),i.jsx("th",{className:"text-left py-1",children:"Profile"})]})}),i.jsx("tbody",{children:w.members.map(k=>i.jsxs("tr",{className:"border-b border-outline-variant",children:[i.jsx("td",{className:"py-1",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{children:k.id}),a&&i.jsx(Ne,{variant:"outline",size:"sm","data-testid":`${x}member-open-agent-${w.id}-${k.id}`,className:"h-6 px-2 font-mono text-[9px] uppercase tracking-[0.12em]",onClick:()=>a(w.id,k),children:"Agent Spec"})]})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:(()=>{const N=Kwe(k.agentRef);return i.jsx(Gwe,{data:{specKind:"agent",specName:N.specName,source:N.source},testId:`${x}member-sub-spec-${w.id}-${k.id}`,className:"text-on-surface-variant underline decoration-dotted decoration-outline hover:text-on-surface hover:decoration-on-surface",children:k.agentRef})})()}),i.jsx("td",{className:"py-1",children:i.jsx(Ps,{runtime:k.runtime,size:"xs",compact:!0,variant:"inline"})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:k.profile??"—"})]},k.id))})]})]},w.id)),e.format==="legacy"&&f.length>0&&i.jsxs("div",{className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Nodes"}),i.jsxs("table",{className:"w-full font-mono text-[10px]",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-outline-variant text-on-surface-variant",children:[i.jsx("th",{className:"text-left py-1",children:"ID"}),i.jsx("th",{className:"text-left py-1",children:"Runtime"}),i.jsx("th",{className:"text-left py-1",children:"Role"})]})}),i.jsx("tbody",{children:f.map(w=>i.jsxs("tr",{className:"border-b border-outline-variant",children:[i.jsx("td",{className:"py-1",children:w.id}),i.jsx("td",{className:"py-1",children:i.jsx(Ps,{runtime:w.runtime,size:"xs",compact:!0,variant:"inline"})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:w.role??"—"})]},w.id))})]})]}),g.length>0&&i.jsxs("div",{className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:e.format==="pod_aware"?"Cross-Pod Edges":"Edges"}),i.jsxs("table",{className:"w-full font-mono text-[10px]",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-outline-variant text-on-surface-variant",children:[i.jsx("th",{className:"text-left py-1",children:"From"}),i.jsx("th",{className:"text-left py-1",children:"To"}),i.jsx("th",{className:"text-left py-1",children:"Kind"})]})}),i.jsx("tbody",{children:g.map((w,k)=>i.jsxs("tr",{className:"border-b border-outline-variant",children:[i.jsx("td",{className:"py-1",children:w.from}),i.jsx("td",{className:"py-1",children:w.to}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:w.kind})]},k))})]})]})]}),d==="environment"&&o&&(e==null?void 0:e.services)&&i.jsxs("div",{className:"space-y-4","data-testid":`${x}env-details`,children:[i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:"Services"}),(y=e.services.composePreview)==null?void 0:y.services.map(w=>i.jsxs("div",{className:"flex items-center justify-between border border-outline-variant px-3 py-2",children:[i.jsx("span",{className:"font-mono text-[11px] text-on-surface",children:w.name}),w.image&&i.jsx("span",{className:"font-mono text-[9px] text-on-surface-variant",children:w.image})]},w.name))]}),e.services.waitFor.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:"Health Gates"}),e.services.waitFor.map((w,k)=>i.jsxs("div",{className:"font-mono text-[10px] text-on-surface-variant border border-outline-variant px-3 py-2",children:[w.url&&i.jsx("span",{children:w.url}),w.tcp&&i.jsxs("span",{children:["tcp: ",w.tcp]}),w.service&&i.jsxs("span",{children:["service: ",w.service,w.condition?` (${w.condition})`:""]})]},k))]}),e.services.surfaces&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:"Surfaces"}),(b=e.services.surfaces.urls)==null?void 0:b.map(w=>i.jsxs("div",{className:"flex items-center justify-between border border-outline-variant px-3 py-2",children:[i.jsx("span",{className:"text-[11px] text-on-surface",children:w.name}),i.jsx("span",{className:"font-mono text-[9px] text-on-surface-variant",children:w.url})]},w.name)),(_=e.services.surfaces.commands)==null?void 0:_.map(w=>i.jsxs("div",{className:"flex items-center justify-between border border-outline-variant px-3 py-2",children:[i.jsx("span",{className:"text-[11px] text-on-surface",children:w.name}),i.jsx("span",{className:"font-mono text-[9px] text-on-surface-variant",children:w.command})]},w.name))]})]}),d==="yaml"&&i.jsx(MA,{title:"YAML Preview",testId:s??`${x}spec-yaml`,children:t})]})}function Ywe(){const e=Ut(),{selectedRigDraft:t,currentRigDraft:n}=vp(),s=t??n,{data:r,isLoading:a,error:o}=XV((s==null?void 0:s.yaml)??null),c=(r==null?void 0:r.pods)??[],d=(r==null?void 0:r.nodes)??[],h=(r==null?void 0:r.edges)??[];return s?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"rig-spec-review",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:"Rig Spec Review",title:(r==null?void 0:r.name)??s.label,description:(r==null?void 0:r.summary)??"Review the spec structure before import or bootstrap.",actions:i.jsxs(i.Fragment,{children:[i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open In Import"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/bootstrap"}),children:"Bootstrap"})]})}),r&&i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:r.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"rig-spec-summary-format"}),i.jsx(ct,{label:r.format==="pod_aware"?"Pods":"Nodes",value:r.format==="pod_aware"?c.length:d.length,testId:"rig-spec-summary-pods"}),i.jsx(ct,{label:"Members",value:r.format==="pod_aware"?c.reduce((p,f)=>p+f.members.length,0):d.length,testId:"rig-spec-summary-members"}),i.jsx(ct,{label:"Edges",value:h.length+(r.format==="pod_aware"?c.reduce((p,f)=>{var g;return p+(((g=f.edges)==null?void 0:g.length)??0)},0):0),testId:"rig-spec-summary-edges"})]}),a&&i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading review..."}),o&&i.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:o.message}),i.jsx(DA,{review:r,yaml:s.yaml,yamlTestId:"rig-spec-yaml"})]})}):i.jsx(ht,{children:i.jsxs("div",{"data-testid":"rig-spec-review-empty",className:"space-y-5",children:[i.jsx(Tn,{eyebrow:"Rig Spec Review",title:"No RigSpec Selected",description:"Choose a current or recent rig draft from the Library drawer to review it here before you import or bootstrap it."}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open Import"})]})})}function mc({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=ry();return i.jsx("button",{type:"button","data-testid":r??"file-reference-trigger",onClick:()=>a({type:"file",data:e}),className:n??"text-left",style:s,children:t})}function Qwe(e,t){if(!e||!t)return null;if(t.startsWith("/"))return t;const s=`${e.replace(/\/[^/]*$/,"")}/${t}`.split("/"),r=[];for(const a of s)if(!(!a||a===".")){if(a===".."){r.pop();continue}r.push(a)}return`/${r.join("/")}`}function h8({label:e,sourcePath:t,testId:n,children:s}){const r=Qwe(t,e);return r?i.jsx(mc,{data:{path:e,absolutePath:r},testId:n,className:"inline-block text-left",children:s}):i.jsx(i.Fragment,{children:s})}function $A({review:e,yaml:t,testIdPrefix:n="agent",sourcePath:s}){const r=(e==null?void 0:e.profiles)??[],a=(e==null?void 0:e.resources)??{skills:[],guidance:[],plugins:[]},o=(e==null?void 0:e.startup)??{files:[],actions:[]};return i.jsxs(i.Fragment,{children:[r.length>0&&i.jsxs("div",{"data-testid":`${n}-profiles-section`,className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Profiles"}),i.jsx("div",{className:"space-y-1",children:r.map(c=>i.jsxs("div",{className:"font-mono text-[10px] flex justify-between",children:[i.jsx("span",{className:"font-bold",children:c.name}),c.description&&i.jsx("span",{className:"text-on-surface-variant",children:c.description})]},c.name))})]}),i.jsxs("div",{"data-testid":`${n}-resources-section`,className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Resources"}),i.jsxs("div",{className:"space-y-2 font-mono text-[10px]",children:[a.skills.length>0&&i.jsxs("div",{children:[i.jsx("span",{className:"text-on-surface-variant",children:"Skills:"})," ",a.skills.map((c,d)=>i.jsxs("span",{className:"mr-1 mb-0.5 inline-flex items-center gap-1 bg-surface-low px-1.5 py-0.5",children:[i.jsx(vt,{tool:"file",size:"xs",decorative:!0}),c]},d))]}),a.guidance.length>0&&i.jsxs("div",{children:[i.jsx("span",{className:"text-on-surface-variant",children:"Guidance:"})," ",a.guidance.map((c,d)=>i.jsx(h8,{label:c,sourcePath:s,testId:`${n}-guidance-file-trigger-${c}`,children:i.jsxs("span",{className:"mr-1 mb-0.5 inline-flex items-center gap-1 bg-surface-low px-1.5 py-0.5 underline decoration-dotted decoration-outline",children:[i.jsx(vt,{tool:c,size:"xs",decorative:!0}),c]})},`${c}-${d}`))]}),a.plugins.length>0&&i.jsxs("div",{children:[i.jsx("span",{className:"text-on-surface-variant",children:"Plugins:"})," ",a.plugins.map((c,d)=>i.jsxs("span",{className:"mr-1 mb-0.5 inline-flex items-center gap-1 bg-surface-low px-1.5 py-0.5",children:[i.jsx(vt,{tool:"file",size:"xs",decorative:!0}),c]},`${c}-${d}`))]})]})]}),(o.files.length>0||o.actions.length>0)&&i.jsxs("div",{"data-testid":`${n}-startup-section`,className:"border border-outline-variant p-3",children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Startup"}),o.files.length>0&&i.jsxs("div",{className:"mb-2",children:[i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant uppercase mb-1",children:"Files"}),o.files.map((c,d)=>i.jsxs("div",{className:"font-mono text-[10px]",children:[i.jsx(h8,{label:c.path,sourcePath:s,testId:`${n}-startup-file-trigger-${c.path}`,children:i.jsxs("span",{className:"inline-flex items-center gap-1 underline decoration-dotted decoration-outline",children:[i.jsx(vt,{tool:c.path,size:"xs",decorative:!0}),c.path]})})," ",c.required&&i.jsx("span",{className:"text-red-500 text-[8px]",children:"REQUIRED"})]},d))]}),o.actions.length>0&&i.jsxs("div",{children:[i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant uppercase mb-1",children:"Actions"}),o.actions.map((c,d)=>i.jsxs("div",{className:"font-mono text-[10px]",children:[i.jsxs("span",{className:"inline-flex items-center gap-1 text-on-surface-variant",children:[i.jsx(vt,{tool:c.type.includes("command")?"terminal":c.type,size:"xs",decorative:!0}),c.type,":"]})," ",c.value]},d))]})]}),i.jsx(MA,{title:"YAML Preview",testId:`${n}-spec-yaml`,children:t})]})}function Xwe(){const e=Ut(),{selectedAgentDraft:t,currentAgentDraft:n}=vp(),s=t??n,{data:r,isLoading:a,error:o}=qwe((s==null?void 0:s.yaml)??null);return s?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"agent-spec-review",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:"Agent Spec Review",title:(r==null?void 0:r.name)??s.label,description:(r==null?void 0:r.description)??"Review the agent spec structure before validation.",actions:i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open In Validate"})}),r&&i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:"AgentSpec",testId:"agent-spec-summary-format"}),i.jsx(ct,{label:"Version",value:r.version,testId:"agent-spec-summary-version"}),i.jsx(ct,{label:"Profiles",value:(r.profiles??[]).length,testId:"agent-spec-summary-profiles"}),i.jsx(ct,{label:"Skills",value:(r.resources??{skills:[]}).skills.length,testId:"agent-spec-summary-skills"})]}),a&&i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading review..."}),o&&i.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:o.message}),i.jsx($A,{review:r,yaml:s.yaml,testIdPrefix:"agent"})]})}):i.jsx(ht,{children:i.jsxs("div",{"data-testid":"agent-spec-review-empty",className:"space-y-5",children:[i.jsx(Tn,{eyebrow:"Agent Spec Review",title:"No AgentSpec Selected",description:"Choose a current or recent agent draft from the Library drawer to review it here before you validate it."}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open Validate"})]})})}function Zwe(){return Xt({mutationFn:async({bundlePath:e})=>{const t=await fetch("/api/bundles/inspect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e})}),n=await t.json();if(n.error)throw new Error(n.error);if(!t.ok)throw new Error(`HTTP ${t.status}`);return n}})}function Jwe(){return Xt({mutationFn:async({bundlePath:e,plan:t,autoApprove:n,targetRoot:s})=>{const r=await fetch("/api/bundles/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e,plan:t,autoApprove:n,targetRoot:s})}),a=await r.json();if(!r.ok)throw new Error(a.error??`HTTP ${r.status}`);return a}})}function e1e(){var a,o;const[e,t]=E.useState(""),n=Zwe(),s=()=>{e.trim()&&n.mutate({bundlePath:e.trim()})},r=n.data;return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"bundle-inspector",children:[i.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSPECT BUNDLE"}),i.jsxs("div",{className:"mb-spacing-4",children:[i.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),i.jsx("input",{"data-testid":"bundle-path-input",type:"text",value:e,onChange:c=>t(c.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary"}),i.jsx(Ne,{variant:"tactical",onClick:s,disabled:!e.trim()||n.isPending,className:"mt-spacing-3","data-testid":"inspect-btn",children:n.isPending?"INSPECTING...":"INSPECT"})]}),n.isError&&i.jsx("div",{className:"text-destructive text-body-md mb-spacing-4","data-testid":"inspect-error",children:n.error.message}),r&&i.jsxs("div",{"data-testid":"inspect-result",children:[i.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4","data-testid":"manifest-summary",children:[i.jsxs("div",{className:"flex items-center gap-spacing-2 mb-spacing-2",children:[i.jsx("h3",{className:"text-headline-md uppercase",children:r.manifest.name}),i.jsxs("span",{className:"text-label-sm font-mono px-spacing-2 py-px bg-foreground/10","data-testid":"schema-badge",children:["v",r.manifest.schemaVersion??1]})]}),i.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["v",r.manifest.version]}),i.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["Spec: ",r.manifest.rigSpec]}),i.jsxs("div",{className:"mt-spacing-2 flex gap-spacing-3",children:[i.jsxs("span",{className:le("text-label-sm",r.digestValid?"text-success":"text-destructive"),children:["DIGEST: ",r.digestValid?"VALID":"INVALID"]}),i.jsxs("span",{className:le("text-label-sm",r.integrityResult.passed?"text-success":"text-destructive"),"data-testid":"integrity-status",children:["INTEGRITY: ",r.integrityResult.passed?"PASS":"FAIL"]})]})]}),r.manifest.schemaVersion===2&&r.manifest.agents?i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"AGENTS"}),i.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"agent-list",children:r.manifest.agents.map(c=>i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"agent-entry",children:[c.name," v",c.version," — ",c.path]},c.name))})]}):i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PACKAGES"}),i.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"package-list",children:(r.manifest.packages??[]).map(c=>i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"package-entry",children:[c.name," v",c.version," — ",c.path]},c.name))})]}),r.manifest.provenance&&i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PROVENANCE"}),i.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4 space-y-spacing-1","data-testid":"provenance-block",children:[r.manifest.provenance.createdAt&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"provenance-createdAt",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Created: "}),r.manifest.provenance.createdAt]}),r.manifest.provenance.sourceHost&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"provenance-sourceHost",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Host: "}),r.manifest.provenance.sourceHost]}),r.manifest.provenance.authorSession&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"provenance-authorSession",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Author: "}),r.manifest.provenance.authorSession]}),r.manifest.provenance.sourceRigName&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"provenance-sourceRigName",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Rig: "}),r.manifest.provenance.sourceRigName,r.manifest.provenance.sourceRigId&&i.jsxs("span",{className:"text-foreground-muted-on-dark",children:[" (",r.manifest.provenance.sourceRigId,")"]})]}),(r.manifest.provenance.daemonVersion||r.manifest.provenance.cliVersion)&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"provenance-versions",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Built with: "}),r.manifest.provenance.daemonVersion&&i.jsxs(i.Fragment,{children:["daemon ",r.manifest.provenance.daemonVersion]}),r.manifest.provenance.daemonVersion&&r.manifest.provenance.cliVersion&&" / ",r.manifest.provenance.cliVersion&&i.jsxs(i.Fragment,{children:["cli ",r.manifest.provenance.cliVersion]})]}),r.manifest.provenance.notes&&i.jsxs("div",{className:"text-label-sm font-mono whitespace-pre-wrap mt-spacing-2","data-testid":"provenance-notes",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Notes: "}),r.manifest.provenance.notes]})]})]}),r.manifest.compatibility&&i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"COMPATIBILITY"}),i.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4 space-y-spacing-1","data-testid":"compatibility-block",children:[r.manifest.compatibility.minDaemonVersion&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"compatibility-minDaemonVersion",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Min daemon: "}),r.manifest.compatibility.minDaemonVersion]}),r.manifest.compatibility.minCliVersion&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"compatibility-minCliVersion",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Min CLI: "}),r.manifest.compatibility.minCliVersion]}),r.manifest.compatibility.schemaVersion!==void 0&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"compatibility-schemaVersion",children:[i.jsx("span",{className:"text-foreground-muted-on-dark",children:"Schema: "}),"v",r.manifest.compatibility.schemaVersion]})]})]}),r.integrityResult.errors.map(c=>i.jsx("p",{className:"text-destructive text-body-md mb-spacing-2",children:c},c)),(r.integrityResult.warnings??[]).map(c=>i.jsx("p",{className:"text-warning text-body-md mb-spacing-2",children:c},c)),r.integrityResult&&i.jsxs(i.Fragment,{children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"FILE INTEGRITY"}),i.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"file-integrity",children:[Object.keys((r.manifest.packages??r.manifest.agents??[]).length>0?((o=(a=r.manifest)==null?void 0:a.integrity)==null?void 0:o.files)??{}:{}).map(c=>{const d=r.integrityResult.mismatches.includes(c),h=r.integrityResult.missing.includes(c),p=d?"MISMATCH":h?"MISSING":"OK";return i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[i.jsx("span",{className:le("w-2 h-2",p==="OK"?"bg-success":"bg-destructive"),"data-testid":"file-dot"}),i.jsx("span",{children:c}),i.jsx("span",{className:"text-foreground-muted ml-auto",children:p})]},c)}),r.integrityResult.extra.map(c=>i.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[i.jsx("span",{className:"w-2 h-2 bg-warning","data-testid":"file-dot"}),i.jsx("span",{children:c}),i.jsx("span",{className:"text-foreground-muted ml-auto",children:"EXTRA"})]},c))]})]}),i.jsx(Ne,{variant:"tactical","data-testid":"install-btn",onClick:()=>window.location.href=`/bundles/install?bundlePath=${encodeURIComponent(e)}`,children:"INSTALL THIS BUNDLE"})]})]})})}function t1e(){const e=Ut(),[t,n]=E.useState("enter"),s=typeof window<"u"?new URLSearchParams(window.location.search):null,[r,a]=E.useState((s==null?void 0:s.get("bundlePath"))??""),[o,c]=E.useState(""),[d,h]=E.useState(null),[p,f]=E.useState(null),g=Jwe(),x=async()=>{if(r.trim()){n("planning");try{const b=await g.mutateAsync({bundlePath:r.trim(),plan:!0});h(b),n("planned")}catch(b){f(b.message),n("error")}}},y=async()=>{if(o.trim()){n("applying");try{const b=await g.mutateAsync({bundlePath:r.trim(),autoApprove:!0,targetRoot:o.trim()});h(b),n("done")}catch(b){f(b.message),n("error")}}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"bundle-install-flow",children:[i.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSTALL BUNDLE"}),t==="enter"&&i.jsxs("div",{"data-testid":"step-enter",children:[i.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),i.jsx("input",{"data-testid":"bundle-input",type:"text",value:r,onChange:b=>a(b.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),i.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"TARGET ROOT"}),i.jsx("input",{"data-testid":"target-input",type:"text",value:o,onChange:b=>c(b.target.value),placeholder:"/path/to/target/project",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),i.jsx(Ne,{variant:"tactical",onClick:x,disabled:!r.trim(),"data-testid":"plan-btn",children:"PLAN"})]}),t==="planning"&&i.jsx("div",{"data-testid":"step-planning",className:"text-foreground-muted",children:"Planning..."}),t==="planned"&&d&&i.jsxs("div",{"data-testid":"step-planned",children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PLAN"}),i.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:d.stages.map(b=>i.jsxs("div",{className:"text-label-sm font-mono",children:[i.jsx("span",{className:b.status==="ok"?"text-success":"text-foreground-muted",children:b.status.toUpperCase()})," ",b.stage]},b.stage))}),i.jsx(Ne,{variant:"tactical",onClick:y,disabled:!o.trim(),"data-testid":"apply-btn",children:"APPLY"})]}),t==="applying"&&i.jsx("div",{"data-testid":"step-applying",className:"text-foreground-muted",children:"Installing..."}),t==="done"&&d&&i.jsxs("div",{"data-testid":"step-done",children:[i.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"COMPLETE"}),i.jsxs("div",{className:"text-label-sm font-mono",children:["Status: ",i.jsx("span",{className:"text-success",children:d.status.toUpperCase()}),d.stages.some(b=>{var _;return((_=b.detail)==null?void 0:_.source)==="pod_bundle"})?i.jsx("span",{className:"ml-spacing-2 text-primary","data-testid":"bundle-type-label",children:"Pod-aware bundle"}):i.jsx("span",{className:"ml-spacing-2 text-foreground-muted","data-testid":"bundle-type-label",children:"Legacy bundle"})]}),d.rigId&&i.jsxs("div",{className:"text-label-sm font-mono","data-testid":"result-rig-id",children:["Rig: ",d.rigId]}),d.rigId&&i.jsx(Ne,{variant:"tactical",className:"mt-spacing-3",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:d.rigId}}),children:"VIEW RIG"})]}),t==="error"&&i.jsxs("div",{"data-testid":"step-error",children:[i.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:p}),i.jsx(Ne,{variant:"tactical",onClick:()=>{n("enter"),f(null),g.reset()},"data-testid":"try-again-btn",children:"TRY AGAIN"})]})]})})}const n1e=180,f8=56,s1e=220,r1e=110,ZV="in-top",JV="out-bottom",eW="in-side",tW="out-side";function i1e(e){const t=new Map;for(const a of e.edges)t.has(a.fromStepId)||t.set(a.fromStepId,[]),t.get(a.fromStepId).push(a.toStepId);const n=new Map,s=[];for(const a of e.nodes)a.isEntry&&(n.set(a.stepId,0),s.push({id:a.stepId,d:0}));for(;s.length>0;){const{id:a,d:o}=s.shift();for(const c of t.get(a)??[])n.has(c)||(n.set(c,o+1),s.push({id:c,d:o+1}))}let r=0;for(const a of e.nodes)n.has(a.stepId)||n.set(a.stepId,r++);return n}function a1e(e,t,n){const s=n.get(e)??0;return(n.get(t)??0)>s?{sourceHandle:JV,targetHandle:ZV}:{sourceHandle:tW,targetHandle:eW}}function o1e({data:e}){const t=e.isEntry?"#a8c8d4":e.isTerminal?"#d4b8a8":"#d4c4a8",n=!!(e.harness||e.host||e.gate);return i.jsxs("div",{style:{backgroundColor:e.isCurrent?"#e8dcb8":e.wasVisited?"#cfc3a4":t,border:e.isCurrent?"3px solid #7a5c10":"1px solid #8a8577",boxShadow:e.isCurrent?"0 0 0 3px rgba(122, 92, 16, 0.25)":void 0,borderRadius:0,width:n1e,height:n?f8+12:f8,padding:6,fontFamily:"monospace",fontSize:11},children:[i.jsx(wn,{type:"target",position:we.Top,id:ZV,className:"opacity-0"}),i.jsx(wn,{type:"source",position:we.Bottom,id:JV,className:"opacity-0"}),i.jsx(wn,{type:"target",position:we.Right,id:eW,className:"opacity-0"}),i.jsx(wn,{type:"source",position:we.Right,id:tW,className:"opacity-0"}),i.jsxs("div",{className:"font-mono text-[10px] leading-tight",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2 font-bold",children:[i.jsxs("span",{children:[e.isCurrent?i.jsx("span",{"aria-hidden":!0,children:"● "}):null,e.stepId]}),e.isTerminal?i.jsx(vt,{tool:"terminal",size:"xs",title:"Terminal step",decorative:!0}):null]}),i.jsx("div",{className:"text-on-surface-variant",children:e.role}),e.preferredTarget&&i.jsxs("div",{className:"text-[8px] text-on-surface-variant",children:["→ ",e.preferredTarget]}),n&&i.jsxs("div",{className:"text-[8px] text-on-surface-variant",children:[e.harness?i.jsxs("span",{"data-testid":`wf-node-harness-${e.stepId}`,children:["⌁ ",e.harness]}):null,e.host?i.jsxs("span",{"data-testid":`wf-node-host-${e.stepId}`,children:[e.harness?" · ":"","host: ",e.host]}):null,e.gate?i.jsxs("span",{"data-testid":`wf-node-gate-${e.stepId}`,children:[e.harness||e.host?" · ":"","⛨ gate: ",e.gate.target]}):null]})]})]})}const l1e={workflowStep:o1e};function nW({topology:e,testId:t,currentStepId:n,visitedStepIds:s,takenEdgeKeys:r,heightClass:a}){const{nodes:o,edges:c}=E.useMemo(()=>{const d=i1e(e),h=new Map;for(const b of e.nodes){const _=d.get(b.stepId)??0;h.has(_)||h.set(_,[]),h.get(_).push(b.stepId)}const p=new Map;for(const[b,_]of h)_.forEach((w,k)=>p.set(w,{x:k*s1e,y:b*r1e}));const f=new Set(s??[]),g=new Set(r??[]),x=e.nodes.map(b=>({id:b.stepId,type:"workflowStep",position:p.get(b.stepId)??{x:0,y:0},data:{stepId:b.stepId,role:b.role,preferredTarget:b.preferredTarget,isEntry:b.isEntry,isTerminal:b.isTerminal,harness:b.harness,host:b.host,gate:b.gate,isCurrent:n!=null&&b.stepId===n,wasVisited:f.has(b.stepId)}})),y=e.edges.map((b,_)=>{const w=b.routingType==="branch",k=g.has(`${b.fromStepId}→${b.toStepId}`),{sourceHandle:N,targetHandle:C}=a1e(b.fromStepId,b.toStepId,d);return{id:`e-${_}`,source:b.fromStepId,target:b.toStepId,sourceHandle:N,targetHandle:C,label:w&&b.branchOn?`on ${b.branchOn}`:void 0,labelStyle:{fontFamily:"monospace",fontSize:9,fill:"#7a5c10"},labelBgStyle:{fill:"#f2ead6"},animated:k&&n!=null,style:{stroke:k?"#5c4a10":w?"#a8842c":"#8a8577",strokeWidth:k?2.5:1,strokeDasharray:w?"6 4":void 0}}});return{nodes:x,edges:y}},[e,n,s,r]);return i.jsx("div",{"data-testid":t??"workflow-topology-graph",className:`w-full ${a??"h-[400px]"} bg-background border border-outline-variant`,children:i.jsxs(Cp,{nodes:o,edges:c,nodeTypes:l1e,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(zR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(Ep,{showInteractive:!1})]})})}async function BA(e){const t=await fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.json()}function sW(e){return Re({queryKey:["workflow","instances","all"],queryFn:()=>BA("/api/workflow/list"),staleTime:15e3})}function c1e(){return Re({queryKey:["workflow","specs"],queryFn:()=>BA("/api/workflow/specs"),staleTime:15e3})}function u1e(e){return Re({queryKey:["workflow","trace",e],queryFn:()=>BA(`/api/workflow/${encodeURIComponent(e)}/trace`),enabled:!!e,staleTime:15e3})}function oa(e){return e.status==="failed"?0:e.deadline.state!=="healthy"?1:e.status==="waiting"?2:e.status==="active"?3:4}function d1e(e){return e.status==="failed"?{glyph:"▲",label:"FAILED",cls:"text-red-700"}:e.deadline.state!=="healthy"?{glyph:"▲",label:e.deadline.state.toUpperCase(),cls:"text-amber-700"}:e.status==="waiting"?{glyph:"◐",label:"WAITING",cls:"text-on-surface-variant"}:e.status==="active"?{glyph:"●",label:"ACTIVE",cls:"text-emerald-800"}:e.status==="aborted"?{glyph:"⊘",label:"ABORTED",cls:"text-on-surface-variant"}:{glyph:"○",label:"COMPLETED",cls:"text-on-surface-variant"}}function h1e(e){return`…${e.slice(-6)}`}function f1e(e){const t=Math.max(0,Math.floor((Date.now()-Date.parse(e))/6e4));return t<60?`${t}m`:t<1440?`${Math.floor(t/60)}h`:`${Math.floor(t/1440)}d`}function p1e(e){return e.currentStepId?`at ${e.currentStepId}`:e.status==="completed"?"closed":e.status==="failed"?"felled":"—"}function rW({instance:e}){const t=d1e(e);return i.jsx("li",{children:i.jsxs(Ke,{to:"/workflow/instance/$instanceId",params:{instanceId:e.instanceId},"data-testid":`workflow-instance-row-${e.instanceId}`,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left hover:bg-surface-variant/50",children:[i.jsx("span",{className:le("font-mono text-[11px]",t.cls),"aria-hidden":!0,children:t.glyph}),i.jsx("span",{className:le("font-mono text-[9px] uppercase w-32 shrink-0",t.cls),children:t.label}),i.jsx("span",{className:"font-mono text-[11px] text-on-surface",title:e.instanceId,children:h1e(e.instanceId)}),i.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-on-surface",children:[p1e(e),i.jsxs("span",{className:"text-on-surface-variant",children:[" · hop ",e.hopCount]}),e.resumeCount>0?i.jsxs("span",{className:"text-on-surface-variant",children:[" · resumed ",e.resumeCount,"×"]}):null]}),e.deadline.state!=="healthy"&&e.deadline.evidence?i.jsxs("span",{className:"hidden font-mono text-[10px] text-amber-800 md:inline truncate max-w-64",children:[e.deadline.evidence.ownerSession," · ",Math.floor(e.deadline.evidence.overdueBySeconds/60),"m over"]}):null,i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant",children:f1e(e.createdAt)}),i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant","aria-hidden":!0,children:"→"})]})})}function m1e(e,t,n){return e.filter(s=>t?s.workflowName===t:!0).filter(s=>n?s.workflowVersion===n:!0).slice().sort((s,r)=>oa(s)-oa(r))}function g1e({workflowName:e,workflowVersion:t,testId:n,quietWhenEmpty:s=!0}){const{data:r,isLoading:a}=sW(),o=m1e(r??[],e,t);if(a||o.length===0)return s?null:i.jsx("p",{"data-testid":n?`${n}-empty`:void 0,className:"font-mono text-[11px] text-on-surface-variant",children:a?"Loading instances…":"0 instances — computed from /api/workflow/list"});const c=o.filter(h=>h.status==="active"||h.status==="waiting").length,d=o.filter(h=>oa(h)<=1).length;return i.jsxs("div",{"data-testid":n??"workflow-instances-band",className:"space-y-2",children:[i.jsxs("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:["Instances",i.jsxs("span",{className:"ml-2 normal-case tracking-normal",children:[o.length," total · ",c," live",d>0?` · ${d} need attention`:""]})]}),i.jsx("ul",{className:"divide-y divide-outline-variant/50 border border-outline-variant",children:o.map(h=>i.jsx(rW,{instance:h},h.instanceId))})]})}function x1e({entry:e}){const[t,n]=E.useState(!1),[s,r]=E.useState(null),[a,o]=E.useState(null),[c,d]=E.useState(null),[h,p]=E.useState(""),[f,g]=E.useState(null),x=bt(),y=lp(),b=pd(s),_=!e.sourceCwd,w=y.data??[],k=b.data??[],N=[...new Set(k.filter(A=>A.podId).map(A=>A.podNamespace??A.podId))],C=a?k.filter(A=>(A.podNamespace??A.podId)===a&&A.runtime===e.runtime&&!!A.agentRef&&!!A.profile):[],R=C.find(A=>A.logicalId===c),T=Xt({mutationFn:async()=>{var L,P,q,$,F,D,z,U,K;if(!s||!a||!R||!h.trim())throw new Error("Missing required fields");const A={id:h.trim(),runtime:e.runtime,agent_ref:R.agentRef,profile:R.profile,cwd:e.sourceCwd,session_source:{mode:"agent_image",ref:{kind:"image_name",value:e.name}}};e.runtime==="codex"&&R.codexConfigProfile&&(A.codex_config_profile=R.codexConfigProfile);const I=await fetch(`/api/rigs/${encodeURIComponent(s)}/pods/${encodeURIComponent(a)}/members`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({member:A})}),M=await I.json();if(!I.ok||!M.ok)throw new Error(M.message??((L=M.errors)==null?void 0:L.join("; "))??M.code??`HTTP ${I.status}`);const B=(q=(P=M.result)==null?void 0:P.node)==null?void 0:q.status;return B==="failed"||B==="attention_required"?{ok:!1,status:B,error:((F=($=M.result)==null?void 0:$.node)==null?void 0:F.error)??`Launch ${B}`,logicalId:(z=(D=M.result)==null?void 0:D.node)==null?void 0:z.logicalId}:{ok:!0,status:B??"launched",logicalId:((K=(U=M.result)==null?void 0:U.node)==null?void 0:K.logicalId)??h.trim()}},onSuccess:A=>{g(A),x.invalidateQueries({queryKey:["ps"]})},onError:A=>{g({ok:!1,error:A.message})}});return _?i.jsx("div",{"data-testid":"fork-now-disabled-no-cwd",className:"font-mono text-[9px] text-on-surface-variant",children:"Fork now unavailable: image lacks source cwd (pre-Finding-2 manifest)"}):i.jsxs(i.Fragment,{children:[i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"fork-now-button",onClick:()=>{n(!0),g(null)},children:"Fork now"}),t&&i.jsxs("div",{"data-testid":"fork-now-modal",className:"border border-outline bg-surface-lowest px-3 py-3 space-y-3 mt-2",children:[i.jsxs("div",{className:"font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface",children:['Fork "',e.name,'" into a running rig']}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"block font-mono text-[9px] text-on-surface-variant",children:["Target rig",i.jsxs("select",{"data-testid":"fork-now-rig-select",className:"block w-full mt-0.5 border border-outline-variant bg-surface-lowest px-1 py-0.5 font-mono text-[10px]",value:s??"",onChange:A=>{r(A.target.value||null),o(null),d(null)},children:[i.jsx("option",{value:"",children:"Select rig…"}),w.map(A=>i.jsx("option",{value:A.rigId,children:A.name},A.rigId))]})]}),s&&i.jsxs("label",{className:"block font-mono text-[9px] text-on-surface-variant",children:["Target pod",i.jsxs("select",{"data-testid":"fork-now-pod-select",className:"block w-full mt-0.5 border border-outline-variant bg-surface-lowest px-1 py-0.5 font-mono text-[10px]",value:a??"",onChange:A=>{o(A.target.value||null),d(null)},children:[i.jsx("option",{value:"",children:"Select pod…"}),N.map(A=>i.jsx("option",{value:A,children:A},A))]})]}),a&&C.length===0&&i.jsxs("div",{"data-testid":"fork-now-no-sibling",className:"font-mono text-[9px] text-amber-600",children:["No ",e.runtime," member in this pod to clone identity from. Choose a different pod."]}),a&&C.length>0&&i.jsxs("label",{className:"block font-mono text-[9px] text-on-surface-variant",children:["Clone identity from (",e.runtime," member)",i.jsxs("select",{"data-testid":"fork-now-sibling-select",className:"block w-full mt-0.5 border border-outline-variant bg-surface-lowest px-1 py-0.5 font-mono text-[10px]",value:c??"",onChange:A=>d(A.target.value||null),children:[i.jsx("option",{value:"",children:"Select member…"}),C.map(A=>i.jsx("option",{value:A.logicalId,children:A.logicalId},A.logicalId))]})]}),c&&i.jsxs("label",{className:"block font-mono text-[9px] text-on-surface-variant",children:["New member ID (no dots)",i.jsx("input",{"data-testid":"fork-now-member-id",type:"text",className:"block w-full mt-0.5 border border-outline-variant bg-surface-lowest px-1 py-0.5 font-mono text-[10px]",value:h,onChange:A=>p(A.target.value.replace(/\./g,"")),placeholder:"e.g. forked-worker"})]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"fork-now-confirm",disabled:!c||!h.trim()||T.isPending,onClick:()=>T.mutate(),children:T.isPending?"Forking…":"Confirm fork"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>n(!1),children:"Cancel"})]}),f&&i.jsx("div",{"data-testid":"fork-now-result",className:`font-mono text-[9px] ${f.ok?"text-green-700":"text-red-600"}`,children:f.ok?`Forked: ${f.logicalId??h} launched from image "${e.name}" (${f.status})`:`Fork failed: ${f.status?`[${f.status}] `:""}${f.error}`})]})]})}function v1e(e){const t=[`Install and launch the "${e.name}" managed app using OpenRig.`,""];return e.summary&&t.push(`About: ${e.summary}`,""),t.push(`Source: ${e.sourcePath}`,"","Steps:",`1. Run: rig up ${e.name}`,`2. Monitor: rig ps --nodes --rig ${e.name}`,"3. Check env: rig env status <rig-name>"),t.join(`
587
- `)}function qA({sourcePath:e,sourceState:t}){return i.jsxs("div",{className:"font-mono text-[9px] text-on-surface-variant","data-testid":"library-provenance",children:["Source: ",e," · ",t]})}function y1e({review:e}){const t=Ut(),n=e.profiles??[],s=e.resources??{skills:[]};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-agent",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:"Library — Agent Spec",title:e.name,description:e.description??"Agent spec from library.",actions:i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/agents/validate"}),children:"Validate"})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:"AgentSpec",testId:"lib-agent-format"}),i.jsx(ct,{label:"Version",value:e.version,testId:"lib-agent-version"}),i.jsx(ct,{label:"Profiles",value:n.length,testId:"lib-agent-profiles"}),i.jsx(ct,{label:"Skills",value:s.skills.length,testId:"lib-agent-skills"})]}),i.jsx($A,{review:e,yaml:e.raw,testIdPrefix:"lib-agent",sourcePath:e.sourcePath})]})})}function b1e({review:e}){const t=Ut(),[n,s]=E.useState(!1),{data:r=[]}=Bv("agent");new Map(r.map(h=>[h.name,h]));const a=e.pods??[],o=e.nodes??[],c=e.edges??[],d=h=>{if(!h.startsWith("local:"))return null;const p=h.slice(6),g=`${e.sourcePath.replace(/\/[^/]+$/,"")}/${p}`.split("/"),x=[];for(const b of g)b===".."?x.pop():b!=="."&&b!==""&&x.push(b);const y="/"+x.join("/");return r.find(b=>b.sourcePath.startsWith(y+"/"))??null};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-rig",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:e.services?"Library — Managed App":"Library — Rig Spec",title:e.name,description:e.summary??"Rig spec from library.",actions:i.jsxs("div",{className:"flex gap-2",children:[e.services&&i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"copy-setup-prompt",onClick:()=>void(async()=>{await pa(v1e({name:e.name,summary:e.summary,sourcePath:e.sourcePath}))&&(s(!0),window.setTimeout(()=>s(!1),2e3))})(),children:n?"Copied":"Copy Setup Prompt"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/import"}),children:"Import"})]})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:e.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"lib-rig-format"}),e.services&&i.jsx(ct,{label:"Type",value:"Agent-Managed App",testId:"lib-rig-type"}),e.services&&a.length>0&&(()=>{const h=a.find(p=>p.members.some(f=>f.id==="specialist"));return h?i.jsx(ct,{label:"Specialist Agent",value:`${h.id}.specialist`,testId:"lib-rig-specialist"}):null})(),i.jsx(ct,{label:e.format==="pod_aware"?"Pods":"Nodes",value:e.format==="pod_aware"?a.length:o.length,testId:"lib-rig-pods"}),i.jsx(ct,{label:"Members",value:e.format==="pod_aware"?a.reduce((h,p)=>h+p.members.length,0):o.length,testId:"lib-rig-members"}),i.jsx(ct,{label:"Edges",value:c.length+(e.format==="pod_aware"?a.reduce((h,p)=>{var f;return h+(((f=p.edges)==null?void 0:f.length)??0)},0):0),testId:"lib-rig-edges"})]}),i.jsx(DA,{review:e,yaml:e.raw,testIdPrefix:"lib",yamlTestId:"lib-rig-yaml",showEnvironmentTab:!!e.services,onMemberClick:(h,p)=>{const f=d(p.agentRef);f&&t({to:"/specs/library/$entryId",params:{entryId:f.id}})}})]})})}function _1e({entryId:e}){return e.startsWith("context-pack:")?i.jsx(j1e,{entryId:e}):e.startsWith("agent-image:")?i.jsx(k1e,{entryId:e}):i.jsx(w1e,{entryId:e})}function w1e({entryId:e}){const t=Ut(),{data:n,isLoading:s,error:r}=JE(e);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading spec review..."})}):r||!n?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Spec Not Found",description:(r==null?void 0:r.message)??"Could not load spec."}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):n.kind==="agent"?i.jsx(y1e,{review:n}):n.kind==="workflow"?i.jsx(S1e,{review:n}):i.jsx(b1e,{review:n})}function S1e({review:e}){const t=Ut(),n=bt(),{data:s}=mne(),[r,a]=E.useState(null),[o,c]=E.useState(!1),d=(s==null?void 0:s.specName)===e.name&&(s==null?void 0:s.specVersion)===e.version,h=async()=>{c(!0),a(null);try{await gne(e.name,e.version),await n.invalidateQueries({queryKey:["spec-library","active-lens"]}),await n.invalidateQueries({queryKey:["slices"]})}catch(f){a(f.message)}finally{c(!1)}},p=async()=>{c(!0),a(null);try{await xne(),await n.invalidateQueries({queryKey:["spec-library","active-lens"]}),await n.invalidateQueries({queryKey:["slices"]})}catch(f){a(f.message)}finally{c(!1)}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-workflow",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:e.isBuiltIn?"Library — Workflow (Built-in)":"Library — Workflow",title:`${e.name} v${e.version}`,description:e.purpose??"Workflow spec from library.",actions:i.jsxs("div",{className:"flex gap-2 items-center",children:[d?i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"workflow-deactivate-lens",onClick:()=>void p(),disabled:o,children:o?"...":"Deactivate Lens"}):i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"workflow-activate-lens",onClick:()=>void h(),disabled:o,children:o?"...":"Activate as Lens"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back"})]})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:"library_item"}),r&&i.jsx("div",{"data-testid":"workflow-lens-error",className:"font-mono text-[10px] text-red-600",children:r}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:"WorkflowSpec",testId:"lib-wf-format"}),i.jsx(ct,{label:"Version",value:e.version,testId:"lib-wf-version"}),i.jsx(ct,{label:"Roles",value:e.rolesCount,testId:"lib-wf-roles"}),i.jsx(ct,{label:"Steps",value:e.stepsCount,testId:"lib-wf-steps"}),i.jsx(ct,{label:"Target Rig",value:e.targetRig??"(any)",testId:"lib-wf-target-rig"}),i.jsx(ct,{label:"Source",value:e.isBuiltIn?"built-in":"user file",testId:"lib-wf-source"})]}),i.jsxs("div",{"data-testid":"workflow-terminal-rule",className:"flex items-center gap-2 border border-outline-variant/40 bg-surface-lowest/10 px-3 py-2 font-mono text-[10px] text-on-surface",children:[i.jsx(vt,{tool:"terminal",size:"xs",decorative:!0}),i.jsx("span",{className:"text-on-surface-variant uppercase tracking-[0.16em] text-[8px]",children:"Coordination Terminal Turn:"}),e.terminalTurnRule]}),i.jsx(nW,{topology:e.topology}),i.jsx(g1e,{workflowName:e.name,workflowVersion:e.version,testId:"library-instances-band"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:"Steps"}),i.jsx("div",{className:"space-y-1",children:e.steps.map(f=>i.jsxs("div",{"data-testid":`workflow-step-${f.stepId}`,className:"border border-outline-variant/40 bg-surface-lowest/5 px-3 py-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"font-mono text-[11px] font-bold text-on-surface",children:f.stepId}),i.jsx("span",{className:"font-mono text-[9px] text-on-surface-variant",children:f.role})]}),f.objective&&i.jsx("div",{className:"mt-1 text-[10px] text-on-surface-variant leading-tight",children:f.objective}),f.allowedNextSteps.length>0&&i.jsxs("div",{className:"mt-1 font-mono text-[9px] text-on-surface-variant",children:["next: ",f.allowedNextSteps.map(g=>`${g.stepId} (${g.role})`).join(", ")]}),f.allowedExits.length>0&&i.jsxs("div",{className:"font-mono text-[9px] text-on-surface-variant",children:["exits: ",f.allowedExits.join(", ")]})]},f.stepId))})]})]})})}function j1e({entryId:e}){const t=Ut(),{data:n=[],isLoading:s,error:r}=eR(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=bne(a?a.relativePath:null);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading context pack…"})}):r||!a?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Context Pack Not Found",description:(r==null?void 0:r.message)??`No context pack with id ${e}.`}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(N1e,{entry:a,preview:o,previewLoading:c})}function N1e({entry:e,preview:t,previewLoading:n}){const s=Ut();return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-context-pack",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:`Library — Context Pack${e.sourceType==="builtin"?" (built-in)":""}`,title:e.name,description:e.purpose??"Operator-authored composable context bundle.",actions:i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Version",value:e.version,testId:"lib-pack-version"}),i.jsx(ct,{label:"Files",value:e.files.length,testId:"lib-pack-files"}),i.jsx(ct,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-pack-tokens"}),i.jsx(ct,{label:"Source",value:e.sourceType,testId:"lib-pack-source"})]}),i.jsxs("div",{"data-testid":"lib-pack-source-path",className:"font-mono text-[9px] text-on-surface-variant",children:["path: ",e.sourcePath]}),i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Files"}),i.jsx("ul",{"data-testid":"lib-pack-file-list",className:"divide-y divide-outline-variant",children:e.files.map(r=>{const a=r.bytes===null;return i.jsx("li",{"data-testid":`lib-pack-file-${r.path}`,"data-missing":a?"true":"false",className:`font-mono text-[10px] ${a?"text-red-700":"text-on-surface"}`,children:i.jsxs(mc,{data:{path:r.path,absolutePath:r.absolutePath},testId:`lib-pack-file-trigger-${r.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors",children:[i.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[i.jsx("span",{className:"font-bold truncate underline decoration-dotted decoration-outline",children:r.path}),i.jsxs("span",{className:"font-mono text-[8px] text-on-surface-variant shrink-0",children:["role: ",r.role,a?" · MISSING":` · ${r.bytes}B · ~${r.estimatedTokens} tokens`]})]}),r.summary&&i.jsx("div",{className:"mt-0.5 text-on-surface-variant text-[9px]",children:r.summary})]})},r.path)})})]}),i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Bundle preview"}),n&&i.jsx("div",{className:"px-3 py-2 font-mono text-[9px] text-on-surface-variant",children:"Loading bundle…"}),t&&i.jsxs(i.Fragment,{children:[t.missingFiles.length>0&&i.jsxs("div",{"data-testid":"lib-pack-missing-warning",className:"px-3 py-2 font-mono text-[9px] text-red-700 border-b border-outline-variant",children:["Warning: ",t.missingFiles.length," file",t.missingFiles.length===1?"":"s"," referenced by manifest but missing on disk."]}),i.jsx("pre",{"data-testid":"lib-pack-bundle-text",className:"font-mono text-[9px] text-on-surface bg-background px-3 py-2 max-h-96 overflow-y-auto whitespace-pre-wrap",children:t.bundleText})]})]})]})})}function k1e({entryId:e}){const t=Ut(),{data:n=[],isLoading:s,error:r}=tR(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=Sne(a?e:null);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading agent image…"})}):r||!a?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Agent Image Not Found",description:(r==null?void 0:r.message)??`No agent image with id ${e}.`}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(C1e,{entry:a,preview:o,previewLoading:c})}function C1e({entry:e,preview:t,previewLoading:n}){const s=Ut(),r=jne(),[a,o]=E.useState(!1),[c,d]=E.useState(null),h=async()=>{if(!(t!=null&&t.starterSnippet))return;await pa(t.starterSnippet)&&(o(!0),window.setTimeout(()=>o(!1),2e3))},p=async()=>{d(null);try{await r.mutateAsync({id:e.id,pin:!e.pinned})}catch(f){d(f.message)}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-agent-image",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:`Library — Agent Image${e.sourceType==="builtin"?" (built-in)":""}`,title:`${e.name} v${e.version}`,description:e.notes??`Snapshot of ${e.sourceSeat}.`,actions:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"agent-image-pin-toggle",onClick:()=>void p(),disabled:r.isPending,children:e.pinned?"Unpin":"Pin"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})]})}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Runtime",value:i.jsx(Ps,{runtime:e.runtime,size:"sm",compact:!0,variant:"inline"}),testId:"lib-image-runtime"}),i.jsx(ct,{label:"Forks",value:String(e.stats.forkCount),testId:"lib-image-forks"}),i.jsx(ct,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-image-tokens"}),i.jsx(ct,{label:"Size",value:`${e.stats.estimatedSizeBytes}B`,testId:"lib-image-size"})]}),i.jsxs("div",{"data-testid":"lib-image-source",className:"font-mono text-[9px] text-on-surface-variant space-y-0.5",children:[i.jsxs("div",{children:["source seat: ",e.sourceSeat]}),i.jsxs("div",{"data-testid":"lib-image-source-cwd",children:["source cwd: ",e.sourceCwd??"(unknown — pre-Finding-2 manifest)"]}),i.jsxs("div",{children:["created: ",e.createdAt]}),i.jsxs("div",{children:["last used: ",e.stats.lastUsedAt??"never"]}),i.jsxs("div",{children:["path: ",e.sourcePath]}),i.jsxs("div",{"data-testid":"lib-image-pinned",className:e.pinned?"text-amber-700 font-bold":"",children:["pinned: ",String(e.pinned)]})]}),e.lineage.length>0&&i.jsxs("section",{"data-testid":"lib-image-lineage",className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Lineage"}),i.jsxs("div",{className:"px-3 py-2 font-mono text-[10px] text-on-surface",children:[e.lineage.join(" → ")," → ",i.jsx("span",{className:"font-bold",children:e.name})]})]}),i.jsx(x1e,{entry:e}),i.jsxs("section",{"data-testid":"lib-image-starter-snippet",className:"border border-outline bg-surface-lowest px-3 py-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface",children:"Use as starter"}),i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"agent-image-copy-snippet",onClick:()=>void h(),disabled:!(t!=null&&t.starterSnippet),children:a?"Copied":"Copy snippet"})]}),i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant",children:"Paste into your agent.yaml's session_source. The instantiator resolves the image via the daemon AgentImageLibraryService at startup time."}),n&&i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant",children:"Loading snippet…"}),(t==null?void 0:t.starterSnippet)&&i.jsx("pre",{"data-testid":"lib-image-snippet-text",className:"font-mono text-[10px] bg-background border border-outline-variant px-2 py-1 whitespace-pre-wrap",children:t.starterSnippet})]}),c&&i.jsx("div",{"data-testid":"lib-image-pin-error",className:"font-mono text-[9px] text-red-600",children:c}),e.files.length>0&&i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Supplementary files"}),i.jsx("ul",{className:"divide-y divide-outline-variant",children:e.files.map(f=>i.jsx("li",{className:"font-mono text-[10px] text-on-surface","data-testid":`lib-image-file-${f.path}`,children:i.jsxs(mc,{data:{path:f.path,absolutePath:f.absolutePath},testId:`lib-image-file-trigger-${f.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors",children:[i.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[i.jsx("span",{className:"font-bold truncate underline decoration-dotted decoration-outline",children:f.path}),i.jsxs("span",{className:"font-mono text-[8px] text-on-surface-variant shrink-0",children:["role: ",f.role,f.bytes===null?" · MISSING":` · ${f.bytes}B`]})]}),f.summary&&i.jsx("div",{className:"mt-0.5 text-on-surface-variant text-[9px]",children:f.summary})]})},f.path))})]})]})})}async function E1e(e,t,n){const s=await fetch(ls(`/api/rigs/${encodeURIComponent(e)}/nodes/${encodeURIComponent(t)}`,n));if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}function R1e(e,t){const n=Vt();return Re({queryKey:["rig",e,"nodes",t,n],queryFn:()=>E1e(e,t,n),enabled:!!e&&!!t,refetchInterval:3e4,placeholderData:wi})}function A1e({pluginIds:e}){const{data:t=[]}=Fv();if(e.length===0)return i.jsx("div",{className:"px-3 py-4",children:i.jsx(Le,{label:"NO PLUGINS",description:"This agent's profile does not declare any plugins.",variant:"card",testId:"agent-plugins-empty"})});const n=new Map;for(const s of t)n.set(s.id,s);return i.jsx("ul",{"data-testid":"agent-plugins-list",className:"flex flex-col gap-2",children:e.map(s=>{const r=n.get(s);return i.jsx("li",{children:r?i.jsx(T1e,{entry:r}):i.jsx(I1e,{pluginId:s})},s)})})}function T1e({entry:e}){return i.jsxs(Ke,{to:"/plugins/$pluginId",params:{pluginId:e.id},"data-testid":`agent-plugin-chip-${e.id}`,className:"flex items-center justify-between gap-3 border border-outline-variant bg-surface-lowest/30 px-3 py-2 font-mono text-[11px] hover:bg-surface-low/50",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(vt,{tool:"skill",title:`${e.name} plugin`,size:"xs",decorative:!0}),i.jsx("span",{className:"truncate text-xs font-bold text-on-surface",children:e.name}),i.jsx("span",{className:"shrink-0 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:`v${e.version}`})]}),i.jsxs("span",{className:"flex shrink-0 items-center gap-2 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:[e.runtimes.map(t=>i.jsx("span",{className:"inline-block border border-outline-variant px-1.5 py-0.5 font-mono",children:t},t)),i.jsx("span",{title:e.path,children:e.sourceLabel})]})]})}function I1e({pluginId:e}){return i.jsxs(Ke,{to:"/plugins/$pluginId",params:{pluginId:e},"data-testid":`agent-plugin-chip-${e}`,className:"flex items-center justify-between gap-3 border border-dashed border-outline-variant bg-surface-lowest/20 px-3 py-2 font-mono text-[11px] hover:bg-surface-low/50",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(vt,{tool:"skill",title:`${e} plugin (unresolved)`,size:"xs",decorative:!0}),i.jsx("span",{className:"truncate text-xs font-bold text-on-surface",children:e})]}),i.jsx("span",{"data-testid":`agent-plugin-unresolved-${e}`,className:"shrink-0 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:"not discovered"})]})}function M1e(e){return e==null?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):typeof e=="string"&&e.trim()===""?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):e}function L1e(e,t){return e==="running"?"active":qE(e,t)}function O1e(e){return e==="active"?"active":e==="needs_input"?"needs input":e}function P1e({data:e,activityVisual:t}){var k,N,C;const n=BE(e.agentActivity)&&(t==null?void 0:t.state)!=="needs_input"&&(t==null?void 0:t.state)!=="blocked"?null:t,{state:s,source:r}=cp(e.agentActivity,e.terminalActive),a=(n==null?void 0:n.state)??s,o=n?O1e(n.state):L1e(s,e.agentActivity),c=n?n.state==="active":s==="running",d=!!(n!=null&&n.recent),h=d?null:FE(e.agentActivity),p=!d&&r!=="hook"&&r!=="none"?" (activity-grade)":"",f=((k=e.contextUsage)==null?void 0:k.availability)==="known"&&typeof e.contextUsage.usedPercentage=="number"?`${e.contextUsage.usedPercentage}%`:null,g=Do((N=e.contextUsage)==null?void 0:N.totalInputTokens,(C=e.contextUsage)==null?void 0:C.totalOutputTokens),x=Mp(g),y=e.resolvedSpecName&&e.resolvedSpecVersion?`${e.resolvedSpecName}@${e.resolvedSpecVersion}`:e.resolvedSpecName??null,b=i.jsxs("span",{"data-testid":"seat-overview-activity-state","data-activity-state":a,"data-activity-source":d?"ring":r,className:c?"topology-table-active-shimmer text-emerald-600":"text-on-surface",children:[o,h?` ${h.label}`:"",p]}),_=[{key:"runtime",label:"runtime",value:e.runtime?i.jsx(Ps,{runtime:e.runtime,model:e.model,size:"xs",compact:!0,variant:"inline",className:"max-w-full"}):null},{key:"model",label:"model",value:e.model,mono:!0},{key:"profile",label:"profile",value:e.profile,mono:!0},{key:"spec",label:"spec",value:y,mono:!0},{key:"activity",label:"activity",value:b},{key:"context-percent",label:"context %",value:f,mono:!0},{key:"total-tokens",label:"tokens",value:x,mono:!0}],w=_.length-1;return i.jsx("section",{"data-testid":"seat-overview-table",className:"border border-outline-variant bg-surface-lowest/30",children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-left",children:[i.jsx("thead",{children:i.jsx("tr",{"data-testid":"seat-overview-header-row",className:"border-b border-outline-variant/55 bg-background/30",children:_.map((R,T)=>i.jsx("th",{scope:"col","data-testid":`seat-overview-header-${R.key}`,className:`px-3 py-1.5 text-left font-mono text-[10px] font-normal lowercase tracking-[0.04em] text-on-surface-variant ${T<w?"border-r border-outline-variant/55":""}`,children:R.label},R.key))})}),i.jsx("tbody",{children:i.jsx("tr",{"data-testid":"seat-overview-data-row","data-row-shape":"data",children:_.map((R,T)=>i.jsx("td",{"data-testid":`seat-overview-cell-${R.key}`,className:`min-w-0 px-3 py-1.5 align-middle ${R.mono?"font-mono text-[11px]":"text-[11px]"} text-on-surface ${T<w?"border-r border-outline-variant/55":""}`,children:i.jsx("div",{className:"truncate",children:M1e(R.value)})},R.key))})})]})})})}function D1e(e){return e==null?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):typeof e=="string"&&e.trim()===""?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):e}function $1e({data:e}){var s;const t=((s=e.currentQitems)==null?void 0:s[0])??null,n=t?i.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[i.jsx("span",{className:"shrink-0 font-mono text-[10px] text-on-surface-variant",children:t.qitemId}),i.jsx("span",{className:"min-w-0 truncate text-[11px] text-on-surface",children:t.bodyExcerpt})]}):null;return i.jsx("section",{"data-testid":"seat-overview-secondary",className:"border border-outline-variant bg-surface-lowest/30",children:i.jsxs("dl",{className:"divide-y divide-outline-variant/55",children:[i.jsx(p8,{fieldKey:"cwd",label:"cwd",value:e.cwd,mono:!0,titleAttr:e.cwd??void 0}),i.jsx(p8,{fieldKey:"current-work",label:"current work",value:n})]})})}function p8({fieldKey:e,label:t,value:n,mono:s,titleAttr:r}){return i.jsxs("div",{"data-testid":`seat-overview-secondary-row-${e}`,className:"flex min-w-0 items-baseline gap-3 px-3 py-1.5",title:r,children:[i.jsx("dt",{className:"shrink-0 font-mono text-[10px] lowercase tracking-[0.04em] text-on-surface-variant",children:t}),i.jsx("dd",{"data-testid":`seat-overview-secondary-cell-${e}`,className:`min-w-0 flex-1 truncate ${s?"font-mono text-[11px]":"text-[11px]"} text-on-surface`,children:D1e(n)})]})}function B1e(e){return e.startupStatus==="failed"?"Startup failed":e.startupStatus==="attention_required"?"Attention required":e.latestError?"Error":null}function q1e(e){return e.startupStatus==="failed"||e.latestError&&e.startupStatus!=="attention_required"?"destructive":"default"}function F1e({data:e}){const t=B1e(e);if(!t)return null;const n=!!e.latestError,s=!!e.recoveryGuidance;return i.jsxs(os,{"data-testid":"seat-notification-banner","data-startup-status":e.startupStatus??"unknown",variant:q1e(e),children:[i.jsx(lU,{"data-testid":"seat-notification-headline",className:"font-mono text-[11px] uppercase tracking-[0.08em]",children:t}),n?i.jsx(Yn,{"data-testid":"seat-notification-error",className:"font-mono text-[10px]",children:e.latestError}):null,s&&e.recoveryGuidance?i.jsx(Yn,{"data-testid":"seat-notification-guidance",className:"mt-1 font-mono text-[10px] text-on-surface",children:e.recoveryGuidance.summary}):null]})}function z1e(e){switch(e){case"resumed":return"text-success";case"rebuilt":return"text-success";case"fresh":return"text-foreground-muted";case"failed":return"text-destructive";case"checkpoint_written":return"text-success";case"fresh_no_checkpoint":return"text-foreground-muted";default:return"text-foreground-muted"}}const $o="border border-outline-variant bg-surface-lowest/30 p-3";function H1e(e){switch(e){case"ready":return"text-green-600";case"pending":return"text-amber-600";case"attention_required":return"text-orange-600";case"failed":return"text-red-600";default:return"text-on-surface-variant"}}function U1e(e){switch(e){case"attention_required":return"attention required";default:return e??"stopped"}}function V1e(e){if(!e)return null;const t=e.match(/^local:agents\/([^/]+)$/);return(t==null?void 0:t[1])??null}function $r({label:e,value:t}){return t==null||t===""?null:i.jsxs("div",{className:"flex justify-between gap-3 font-mono text-[10px]",children:[i.jsx("span",{className:"text-on-surface-variant",children:e}),i.jsx("span",{className:"truncate text-right text-on-surface",children:t})]})}function W1e({data:e}){const t=V1e(e.agentRef),{data:n=[],isLoading:s}=Bv("agent"),r=t?n.filter(d=>d.name===t):[],a=r.length===1?r[0].id:null,{data:o,isLoading:c}=JE(a);return i.jsxs("div",{"data-testid":"live-agent-spec-section",className:"space-y-4",children:[e.compactSpec.name&&i.jsxs("section",{"data-testid":"detail-compact-spec",className:$o,children:[i.jsx("div",{className:"mb-2 font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Resolved Agent Spec"}),i.jsxs("div",{className:"space-y-0.5",children:[i.jsx($r,{label:"Spec",value:e.compactSpec.name}),i.jsx($r,{label:"Version",value:e.compactSpec.version}),i.jsx($r,{label:"Profile",value:e.compactSpec.profile}),i.jsx($r,{label:"Skills",value:e.compactSpec.skillCount}),i.jsx($r,{label:"Guidance",value:e.compactSpec.guidanceCount})]})]}),t?s||c?i.jsx("div",{className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"Loading agent spec..."}):r.length===0?i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"}):r.length>1?i.jsxs("div",{"data-testid":"agent-spec-ambiguous",className:"p-4 font-mono text-[10px] text-amber-600",children:["Agent spec ambiguous (",r.length,' matches for "',t,'")']}):!o||o.kind!=="agent"?i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"}):i.jsxs(i.Fragment,{children:[i.jsx($A,{review:o,yaml:o.raw,testIdPrefix:"live-agent",sourcePath:o.sourcePath}),i.jsxs("section",{"data-testid":"live-agent-plugins-section",className:"border border-outline-variant bg-surface-lowest/30 p-3",children:[i.jsx("div",{className:"mb-2 font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Plugins"}),i.jsx(A1e,{pluginIds:G1e(o)})]})]}):i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"})]})}function G1e(e){if(!e||typeof e!="object")return[];const t=e.resources;if(!t||typeof t!="object")return[];const n=t.plugins;if(!Array.isArray(n))return[];const s=[];for(const r of n)r&&typeof r=="object"&&typeof r.id=="string"?s.push(r.id):typeof r=="string"&&s.push(r);return s}function K1e({rigId:e,logicalId:t,data:n}){const s=Vt()!==at,r=async()=>{n.tmuxAttachCommand&&await pa(n.tmuxAttachCommand)},a=async()=>{try{await iA({rigId:e,logicalId:t})}catch{}},o=async()=>{n.resumeCommand&&await pa(n.resumeCommand)};return s?i.jsx("div",{"data-testid":"live-node-actions-remote-readonly","data-remote-readonly":"true",className:"font-mono text-[9px] uppercase tracking-wide text-on-surface-variant",children:"read-only — remote host"}):i.jsxs("div",{"data-testid":"live-node-actions",className:"flex flex-wrap gap-2",children:[i.jsxs("button",{onClick:a,"data-testid":"detail-cmux-open",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(vt,{tool:"cmux",size:"sm"}),"Open CMUX"]}),n.tmuxAttachCommand&&i.jsxs("button",{onClick:r,"data-testid":"detail-copy-attach",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(vt,{tool:"tmux",size:"sm"}),"Copy tmux attach"]}),n.resumeCommand&&i.jsxs("button",{onClick:o,"data-testid":"detail-copy-resume",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(tJ,{"aria-hidden":"true",className:"h-4 w-4 shrink-0",strokeWidth:1.5}),"Copy resume command"]})]})}function Y1e({data:e}){const t=e.startupStatus==="failed"||e.startupStatus==="attention_required"||!!e.latestError;return i.jsxs("section",{"data-testid":"live-node-status",className:"grid gap-2 border border-outline-variant bg-surface-lowest/30 p-3 sm:grid-cols-2",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Startup"}),i.jsx("span",{className:H1e(e.startupStatus),"data-testid":"detail-startup-status",children:U1e(e.startupStatus)})]}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Restore"}),i.jsx("span",{className:`font-mono text-xs font-bold ${z1e(e.restoreOutcome)}`,"data-testid":"detail-restore-outcome",children:e.restoreOutcome})]}),t&&i.jsxs("div",{className:`sm:col-span-2 mt-1 p-2 border ${e.startupStatus==="attention_required"?"bg-orange-50 border-orange-200":"bg-red-50 border-red-200"}`,"data-testid":"detail-failure-banner",children:[i.jsx("div",{className:`font-mono text-[9px] font-bold mb-1 ${e.startupStatus==="attention_required"?"text-orange-700":"text-red-700"}`,children:e.startupStatus==="attention_required"?"Attention Required":e.startupStatus==="failed"?"Startup Failed":"Error"}),e.latestError&&i.jsx("div",{className:`font-mono text-[9px] mb-1 ${e.startupStatus==="attention_required"?"text-orange-700":"text-red-600"}`,children:e.latestError}),i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant",children:e.startupStatus==="attention_required"?`Use rig capture ${e.canonicalSessionName??"<session>"} to inspect the prompt, then rig send ${e.canonicalSessionName??"<session>"} to clear it.`:e.startupStatus==="failed"?"Check logs with: rig ps --nodes --rig <name>, or restart with: rig up":"Try: rig restore <snapshotId>"}),e.recoveryGuidance&&i.jsxs("div",{className:"mt-2 border-t border-outline-variant pt-2","data-testid":"detail-recovery-guidance",children:[i.jsx("div",{className:"font-mono text-[8px] font-bold text-on-surface mb-1",children:"Recovery"}),i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant mb-1",children:e.recoveryGuidance.summary}),i.jsx("div",{className:"space-y-0.5 mb-1",children:e.recoveryGuidance.commands.map((n,s)=>i.jsx("code",{className:"font-mono text-[8px] text-on-surface bg-surface-low px-1 py-0.5 block",children:n},`${n}-${s}`))}),i.jsx("div",{className:"space-y-0.5",children:e.recoveryGuidance.notes.map((n,s)=>i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant",children:n},`${n}-${s}`))})]})]})]})}function Q1e({data:e}){return!e.recentEvents||e.recentEvents.length===0?null:i.jsxs("section",{"data-testid":"live-node-recent-events",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Recent Events"}),i.jsx("div",{className:"space-y-0.5",children:e.recentEvents.slice(0,10).map((t,n)=>i.jsxs("div",{className:"font-mono text-[9px] flex justify-between gap-3",children:[i.jsx("span",{className:"text-on-surface truncate",children:t.type}),i.jsx("span",{className:"text-on-surface-variant ml-2 shrink-0",children:t.createdAt})]},`${t.type}-${n}`))})]})}function X1e({data:e}){const{outgoing:t,incoming:n}=e.edges;return t.length===0&&n.length===0?null:i.jsxs("section",{"data-testid":"detail-edges",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Edges"}),i.jsxs("div",{className:"space-y-0.5 font-mono text-[10px]",children:[t.map((s,r)=>{var a;return i.jsxs("div",{className:"flex gap-1",children:[i.jsx("span",{className:"text-on-surface-variant",children:"->"}),i.jsx("span",{className:"text-on-surface-variant",children:s.kind}),i.jsx("span",{className:"text-on-surface",children:((a=s.to)==null?void 0:a.logicalId)??"?"})]},`out-${r}`)}),n.map((s,r)=>{var a;return i.jsxs("div",{className:"flex gap-1",children:[i.jsx("span",{className:"text-on-surface-variant",children:"<-"}),i.jsx("span",{className:"text-on-surface-variant",children:s.kind}),i.jsx("span",{className:"text-on-surface",children:((a=s.from)==null?void 0:a.logicalId)??"?"})]},`in-${r}`)})]})]})}function Z1e({data:e}){return e.peers.length===0?null:i.jsxs("section",{"data-testid":"detail-peers",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Peers"}),i.jsx("div",{className:"space-y-1 font-mono text-[10px]",children:e.peers.map(t=>i.jsxs("div",{className:"space-y-0",children:[i.jsxs("div",{className:"flex justify-between gap-3",children:[i.jsx("span",{className:"text-on-surface",children:t.logicalId}),i.jsx("span",{className:"text-on-surface-variant",children:t.runtime??"-"})]}),t.canonicalSessionName&&i.jsx("div",{className:"text-[9px] text-on-surface-variant truncate",children:t.canonicalSessionName})]},t.logicalId))})]})}function J1e({data:e}){var n,s,r;const t=e.contextUsage;return i.jsxs("section",{"data-testid":"detail-context-usage",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Context"}),(t==null?void 0:t.availability)==="known"?i.jsxs("div",{className:"space-y-0.5 font-mono text-[10px]",children:[i.jsx($r,{label:"Used",value:t.usedPercentage!=null?`${t.usedPercentage}%`:null}),i.jsx($r,{label:"Remaining",value:t.remainingPercentage!=null?`${t.remainingPercentage}%`:null}),i.jsx($r,{label:"Window",value:(n=t.contextWindowSize)==null?void 0:n.toLocaleString()}),i.jsx($r,{label:"Input tokens",value:(s=t.totalInputTokens)==null?void 0:s.toLocaleString()}),i.jsx($r,{label:"Output tokens",value:(r=t.totalOutputTokens)==null?void 0:r.toLocaleString()}),i.jsx($r,{label:"Sampled",value:t.sampledAt}),t.fresh===!1&&i.jsx("div",{className:"font-mono text-[9px] text-amber-600 mt-1",children:"Stale sample"})]}):i.jsxs("div",{className:"font-mono text-[10px] text-on-surface-variant",children:["unknown",t!=null&&t.reason?` (${t.reason})`:""]})]})}function eSe({data:e,activityVisual:t}){return i.jsxs("div",{"data-testid":"live-overview-section",className:"space-y-4",children:[i.jsx(F1e,{data:e}),i.jsx(P1e,{data:e,activityVisual:t}),i.jsx($1e,{data:e}),i.jsx(nSe,{data:e}),i.jsx(Q1e,{data:e})]})}function tSe({rigId:e,logicalId:t,data:n,isAgent:s}){return i.jsxs("div",{"data-testid":"live-details-section",className:"space-y-4",children:[i.jsx(sSe,{rigId:e,logicalId:t,data:n}),s?i.jsx(W1e,{data:n}):null,i.jsx(X1e,{data:n}),i.jsx(Z1e,{data:n}),i.jsx(J1e,{data:n}),i.jsx(rSe,{data:n})]})}function nSe({data:e}){return Vt()!==at?i.jsx("div",{"data-testid":"node-detail-terminal-remote-gated",className:"font-mono text-[10px] text-on-surface-variant p-4",children:"Terminal not available for remote hosts — terminal streams are this host's local sessions. Viewing a remote host is read-only."}):e.canonicalSessionName?i.jsx("div",{"data-testid":"live-terminal-shell",className:"bg-stone-950/65 text-stone-50 backdrop-blur-sm h-[500px]",children:i.jsx(Uo,{sessionName:e.canonicalSessionName,terminalKey:`node-detail:${e.canonicalSessionName}`,testIdPrefix:"node-detail-terminal",fit:"contain"})}):i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant p-4",children:"No canonical session name; terminal preview unavailable."})}function sSe({rigId:e,logicalId:t,data:n}){return i.jsxs("div",{"data-testid":"live-startup-section",className:"space-y-4",children:[i.jsx(Y1e,{data:n}),n.infrastructureStartupCommand&&i.jsxs("section",{"data-testid":"live-node-infra-startup",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Startup Command"}),i.jsx("code",{className:"font-mono text-[9px] text-on-surface bg-surface-low px-2 py-1 block",children:n.infrastructureStartupCommand})]}),n.startupActions.length>0&&i.jsxs("section",{"data-testid":"live-startup-actions",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Startup Actions"}),i.jsx("div",{className:"space-y-1",children:n.startupActions.map((s,r)=>i.jsxs("div",{className:"font-mono text-[10px] text-on-surface",children:[i.jsxs("span",{className:"text-on-surface-variant",children:[s.type,":"]})," ",s.value]},`${s.type}-${s.value}-${r}`))})]}),n.startupFiles.length>0?i.jsxs("section",{className:"border border-outline-variant bg-surface-lowest/30",children:[i.jsx("div",{className:"px-3 py-2 border-b border-outline-variant font-mono text-xs font-bold",children:"Startup Files"}),i.jsx("ul",{className:"divide-y divide-outline-variant",children:n.startupFiles.map((s,r)=>i.jsx("li",{"data-testid":`live-startup-file-${s.path}`,children:i.jsxs(mc,{data:{path:s.path,absolutePath:s.absolutePath},testId:`live-startup-file-trigger-${s.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors font-mono text-[10px]",children:[i.jsx("span",{className:"font-bold underline decoration-dotted decoration-outline",children:s.path}),i.jsxs("span",{className:"text-on-surface-variant ml-2",children:["(",s.deliveryHint,")"]}),s.required&&i.jsx("span",{className:"text-red-500 text-[8px] ml-1",children:"REQUIRED"})]})},`${s.path}-${r}`))})]}):i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant p-4",children:"No startup files declared"})]})}function rSe({data:e}){return e.transcript.enabled?i.jsx("div",{"data-testid":"live-transcript-section",className:"space-y-4",children:i.jsxs("section",{"data-testid":"detail-transcript",className:$o,children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Transcript"}),i.jsx("div",{className:"font-mono text-[10px] text-on-surface",children:e.transcript.path??"enabled"}),e.transcript.tailCommand&&i.jsx("button",{type:"button",onClick:()=>pa(e.transcript.tailCommand),className:"mt-2 w-full border border-outline-variant bg-surface-lowest/40 px-2 py-1 text-left font-mono text-[8px] uppercase text-on-surface hover:bg-surface-low",children:"Copy tail command"})]})}):i.jsx("div",{"data-testid":"live-transcript-section",className:"font-mono text-[10px] text-on-surface-variant p-4",children:"Transcript capture not enabled"})}function iSe({tabs:e,activeTab:t,onSelect:n}){return i.jsx("div",{className:"flex gap-1 border-b border-outline-variant",role:"tablist","data-testid":"live-node-tabs",children:e.map(s=>i.jsx("button",{role:"tab","aria-selected":t===s,"data-testid":`live-tab-${s}`,onClick:()=>n(s),className:`min-h-11 px-3 py-2 font-mono text-[10px] uppercase tracking-wider transition-colors ${t===s?"border-b-2 border-on-surface text-on-surface font-bold -mb-px":"text-on-surface-variant hover:text-on-surface"}`,children:s.replace("-"," ")},s))})}function iW({rigId:e,logicalId:t}){const{data:n,isLoading:s,error:r}=R1e(e,t),a=E.useMemo(()=>By(n?[{nodeId:`${n.rigId}::${n.logicalId}`,rigId:n.rigId,rigName:n.rigName,logicalId:n.logicalId,canonicalSessionName:n.canonicalSessionName,agentActivity:n.agentActivity??null,currentQitems:n.currentQitems??null,startupStatus:n.startupStatus,terminalActive:n.terminalActive,hasAssignedWork:n.hasAssignedWork??!1,pendingWorkCount:n.pendingWorkCount??0}]:[]),[n]),o=qy(a),c=n?o.getNodeActivity(`${n.rigId}::${n.logicalId}`,{agentActivity:n.agentActivity??null,currentQitems:n.currentQitems??null,startupStatus:n.startupStatus,terminalActive:n.terminalActive,hasAssignedWork:n.hasAssignedWork??!1,pendingWorkCount:n.pendingWorkCount??0}):null,[d,h]=E.useState("overview"),p=n?n.nodeKind!=="infrastructure":!0,f=["overview","details"];return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"live-node-details",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Live Node Details",title:(n==null?void 0:n.canonicalSessionName)??t,description:`${(n==null?void 0:n.rigName)??e} / ${(n==null?void 0:n.podNamespace)??pi(t)??Eu((n==null?void 0:n.podId)??null)} / ${t}`,actions:n?i.jsx(Ps,{runtime:n.runtime,model:n.model,size:"sm",compact:!0,className:"bg-surface-lowest/40 backdrop-blur-sm"}):null}),s&&i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading..."}),r&&i.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:r.message}),n&&i.jsxs(i.Fragment,{children:[i.jsx(K1e,{rigId:e,logicalId:t,data:n}),i.jsx(iSe,{tabs:f,activeTab:d,onSelect:h}),i.jsxs("div",{"data-testid":"live-node-tab-body",className:"space-y-4",children:[d==="overview"&&i.jsx(eSe,{data:n,activityVisual:c}),d==="details"&&i.jsx(tSe,{rigId:e,logicalId:t,data:n,isAgent:p})]})]})]})})}function aSe(e){return`'${e.replace(/'/g,"'\\''")}'`}function oSe(e){const t=e.tmuxWindow?`${e.tmuxSession}:${e.tmuxWindow}`:e.tmuxSession;return`tmux attach -t ${aSe(t)}`}function m8({label:e,activeLabel:t,onClick:n,testId:s,tool:r}){const[a,o]=E.useState(!1),c=E.useRef(null);E.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=async()=>{await n()&&(o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{o(!1),c.current=null},900))};return i.jsxs("button",{type:"button","data-testid":s,"aria-label":e,onClick:()=>{d()},className:le("inline-flex items-center gap-1.5 px-spacing-2 py-1 border font-mono text-[10px] uppercase transition-colors duration-150 ease-tactical",a?"bg-inverse-surface text-background border-on-surface":"bg-surface-lowest text-on-surface border-outline-variant hover:bg-surface-low"),children:[r?i.jsx(vt,{tool:r,size:"sm"}):null,i.jsx("span",{children:a?t:e})]})}function lSe({session:e,onAdopt:t}){return i.jsx("div",{"data-testid":"discovered-node",className:le("border-dashed border border-foreground/20 bg-[hsl(var(--surface-container-lowest)/0.72)] px-spacing-4 py-spacing-3 mb-spacing-2 shadow-[0_10px_28px_rgba(20,20,20,0.04)] backdrop-blur-sm"),children:i.jsxs("div",{className:"flex flex-col gap-spacing-3 lg:flex-row lg:items-center lg:justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-spacing-3 gap-y-spacing-1",children:[i.jsx("span",{"data-testid":"runtime-badge",children:i.jsx(Ps,{runtime:e.runtimeHint,size:"sm",compact:!0})}),i.jsx("div",{"data-testid":"session-name",className:"font-mono text-[13px] leading-5 text-foreground",title:e.tmuxSession,children:e.tmuxSession}),e.confidence==="medium"?i.jsx("div",{"data-testid":"runtime-inferred-note",className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"runtime inferred"}):null]}),e.cwd?i.jsxs("div",{className:"mt-spacing-2 min-w-0",children:[i.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"cwd"}),i.jsx("div",{className:"font-mono text-[12px] leading-5 text-foreground-muted truncate",title:e.cwd,children:e.cwd})]}):null]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-spacing-2 lg:justify-end",children:[i.jsx(m8,{label:"copy tmux",activeLabel:"copied",testId:"copy-tmux-btn",tool:"tmux",onClick:async()=>await pa(oSe(e))}),e.cwd?i.jsx(m8,{label:"copy cwd",activeLabel:"copied",testId:"copy-cwd-btn",onClick:async()=>await pa(e.cwd??"")}):null,i.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"adopt-btn",onClick:()=>t(e.id),children:"ADOPT"})]})]})})}function cSe(){const[e,t]=E.useState(null),[n,s]=E.useState(!1),r=E.useCallback(async()=>{s(!0);try{const a=await fetch("/api/discovery/draft-rig",{method:"POST"});if(!a.ok){t(`# Error: draft generation failed (HTTP ${a.status})`);return}const o=await a.text();t(o)}catch{t("# Error: failed to reach daemon")}finally{s(!1)}},[]);return i.jsxs("div",{className:"mt-spacing-4 border-t border-foreground/10 pt-spacing-4","data-testid":"generate-draft-section",children:[i.jsx(Ne,{variant:"tactical",onClick:r,disabled:n,"data-testid":"generate-draft-btn",className:"mb-spacing-3",children:n?"GENERATING...":"GENERATE RIG SPEC"}),e&&(()=>{const a=e.split(`
587
+ `)}function qA({sourcePath:e,sourceState:t}){return i.jsxs("div",{className:"font-mono text-[9px] text-on-surface-variant","data-testid":"library-provenance",children:["Source: ",e," · ",t]})}function y1e({review:e}){const t=Ut(),n=e.profiles??[],s=e.resources??{skills:[]};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-agent",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:"Library — Agent Spec",title:e.name,description:e.description??"Agent spec from library.",actions:i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/agents/validate"}),children:"Validate"})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:"AgentSpec",testId:"lib-agent-format"}),i.jsx(ct,{label:"Version",value:e.version,testId:"lib-agent-version"}),i.jsx(ct,{label:"Profiles",value:n.length,testId:"lib-agent-profiles"}),i.jsx(ct,{label:"Skills",value:s.skills.length,testId:"lib-agent-skills"})]}),i.jsx($A,{review:e,yaml:e.raw,testIdPrefix:"lib-agent",sourcePath:e.sourcePath})]})})}function b1e({review:e}){const t=Ut(),[n,s]=E.useState(!1),{data:r=[]}=Bv("agent");new Map(r.map(h=>[h.name,h]));const a=e.pods??[],o=e.nodes??[],c=e.edges??[],d=h=>{if(!h.startsWith("local:"))return null;const p=h.slice(6),g=`${e.sourcePath.replace(/\/[^/]+$/,"")}/${p}`.split("/"),x=[];for(const b of g)b===".."?x.pop():b!=="."&&b!==""&&x.push(b);const y="/"+x.join("/");return r.find(b=>b.sourcePath.startsWith(y+"/"))??null};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-rig",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:e.services?"Library — Managed App":"Library — Rig Spec",title:e.name,description:e.summary??"Rig spec from library.",actions:i.jsxs("div",{className:"flex gap-2",children:[e.services&&i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"copy-setup-prompt",onClick:()=>void(async()=>{await pa(v1e({name:e.name,summary:e.summary,sourcePath:e.sourcePath}))&&(s(!0),window.setTimeout(()=>s(!1),2e3))})(),children:n?"Copied":"Copy Setup Prompt"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/import"}),children:"Import"})]})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:e.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"lib-rig-format"}),e.services&&i.jsx(ct,{label:"Type",value:"Agent-Managed App",testId:"lib-rig-type"}),e.services&&a.length>0&&(()=>{const h=a.find(p=>p.members.some(f=>f.id==="specialist"));return h?i.jsx(ct,{label:"Specialist Agent",value:`${h.id}.specialist`,testId:"lib-rig-specialist"}):null})(),i.jsx(ct,{label:e.format==="pod_aware"?"Pods":"Nodes",value:e.format==="pod_aware"?a.length:o.length,testId:"lib-rig-pods"}),i.jsx(ct,{label:"Members",value:e.format==="pod_aware"?a.reduce((h,p)=>h+p.members.length,0):o.length,testId:"lib-rig-members"}),i.jsx(ct,{label:"Edges",value:c.length+(e.format==="pod_aware"?a.reduce((h,p)=>{var f;return h+(((f=p.edges)==null?void 0:f.length)??0)},0):0),testId:"lib-rig-edges"})]}),i.jsx(DA,{review:e,yaml:e.raw,testIdPrefix:"lib",yamlTestId:"lib-rig-yaml",showEnvironmentTab:!!e.services,onMemberClick:(h,p)=>{const f=d(p.agentRef);f&&t({to:"/specs/library/$entryId",params:{entryId:f.id}})}})]})})}function _1e({entryId:e}){return e.startsWith("context-pack:")?i.jsx(j1e,{entryId:e}):e.startsWith("agent-image:")?i.jsx(k1e,{entryId:e}):i.jsx(w1e,{entryId:e})}function w1e({entryId:e}){const t=Ut(),{data:n,isLoading:s,error:r}=JE(e);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading spec review..."})}):r||!n?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Spec Not Found",description:(r==null?void 0:r.message)??"Could not load spec."}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):n.kind==="agent"?i.jsx(y1e,{review:n}):n.kind==="workflow"?i.jsx(S1e,{review:n}):i.jsx(b1e,{review:n})}function S1e({review:e}){const t=Ut(),n=bt(),{data:s}=mne(),[r,a]=E.useState(null),[o,c]=E.useState(!1),d=(s==null?void 0:s.specName)===e.name&&(s==null?void 0:s.specVersion)===e.version,h=async()=>{c(!0),a(null);try{await gne(e.name,e.version),await n.invalidateQueries({queryKey:["spec-library","active-lens"]}),await n.invalidateQueries({queryKey:["slices"]})}catch(f){a(f.message)}finally{c(!1)}},p=async()=>{c(!0),a(null);try{await xne(),await n.invalidateQueries({queryKey:["spec-library","active-lens"]}),await n.invalidateQueries({queryKey:["slices"]})}catch(f){a(f.message)}finally{c(!1)}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-workflow",className:"space-y-6",children:[i.jsx(Tn,{eyebrow:e.isBuiltIn?"Library — Workflow (Built-in)":"Library — Workflow",title:`${e.name} v${e.version}`,description:e.purpose??"Workflow spec from library.",actions:i.jsxs("div",{className:"flex gap-2 items-center",children:[d?i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"workflow-deactivate-lens",onClick:()=>void p(),disabled:o,children:o?"...":"Deactivate Lens"}):i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"workflow-activate-lens",onClick:()=>void h(),disabled:o,children:o?"...":"Activate as Lens"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back"})]})}),i.jsx(qA,{sourcePath:e.sourcePath,sourceState:"library_item"}),r&&i.jsx("div",{"data-testid":"workflow-lens-error",className:"font-mono text-[10px] text-red-600",children:r}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Format",value:"WorkflowSpec",testId:"lib-wf-format"}),i.jsx(ct,{label:"Version",value:e.version,testId:"lib-wf-version"}),i.jsx(ct,{label:"Roles",value:e.rolesCount,testId:"lib-wf-roles"}),i.jsx(ct,{label:"Steps",value:e.stepsCount,testId:"lib-wf-steps"}),i.jsx(ct,{label:"Target Rig",value:e.targetRig??"(any)",testId:"lib-wf-target-rig"}),i.jsx(ct,{label:"Source",value:e.isBuiltIn?"built-in":"user file",testId:"lib-wf-source"})]}),i.jsxs("div",{"data-testid":"workflow-terminal-rule",className:"flex items-center gap-2 border border-outline-variant/40 bg-surface-lowest/10 px-3 py-2 font-mono text-[10px] text-on-surface",children:[i.jsx(vt,{tool:"terminal",size:"xs",decorative:!0}),i.jsx("span",{className:"text-on-surface-variant uppercase tracking-[0.16em] text-[8px]",children:"Coordination Terminal Turn:"}),e.terminalTurnRule]}),i.jsx(nW,{topology:e.topology}),i.jsx(g1e,{workflowName:e.name,workflowVersion:e.version,testId:"library-instances-band"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-on-surface-variant",children:"Steps"}),i.jsx("div",{className:"space-y-1",children:e.steps.map(f=>i.jsxs("div",{"data-testid":`workflow-step-${f.stepId}`,className:"border border-outline-variant/40 bg-surface-lowest/5 px-3 py-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"font-mono text-[11px] font-bold text-on-surface",children:f.stepId}),i.jsx("span",{className:"font-mono text-[9px] text-on-surface-variant",children:f.role})]}),f.objective&&i.jsx("div",{className:"mt-1 text-[10px] text-on-surface-variant leading-tight",children:f.objective}),f.allowedNextSteps.length>0&&i.jsxs("div",{className:"mt-1 font-mono text-[9px] text-on-surface-variant",children:["next: ",f.allowedNextSteps.map(g=>`${g.stepId} (${g.role})`).join(", ")]}),f.allowedExits.length>0&&i.jsxs("div",{className:"font-mono text-[9px] text-on-surface-variant",children:["exits: ",f.allowedExits.join(", ")]})]},f.stepId))})]})]})})}function j1e({entryId:e}){const t=Ut(),{data:n=[],isLoading:s,error:r}=eR(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=bne(a?a.relativePath:null);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading context pack…"})}):r||!a?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Context Pack Not Found",description:(r==null?void 0:r.message)??`No context pack with id ${e}.`}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(N1e,{entry:a,preview:o,previewLoading:c})}function N1e({entry:e,preview:t,previewLoading:n}){const s=Ut();return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-context-pack",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:`Library — Context Pack${e.sourceType==="builtin"?" (built-in)":""}`,title:e.name,description:e.purpose??"Operator-authored composable context bundle.",actions:i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Version",value:e.version,testId:"lib-pack-version"}),i.jsx(ct,{label:"Files",value:e.files.length,testId:"lib-pack-files"}),i.jsx(ct,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-pack-tokens"}),i.jsx(ct,{label:"Source",value:e.sourceType,testId:"lib-pack-source"})]}),i.jsxs("div",{"data-testid":"lib-pack-source-path",className:"font-mono text-[9px] text-on-surface-variant",children:["path: ",e.sourcePath]}),i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Files"}),i.jsx("ul",{"data-testid":"lib-pack-file-list",className:"divide-y divide-outline-variant",children:e.files.map(r=>{const a=r.bytes===null;return i.jsx("li",{"data-testid":`lib-pack-file-${r.path}`,"data-missing":a?"true":"false",className:`font-mono text-[10px] ${a?"text-red-700":"text-on-surface"}`,children:i.jsxs(mc,{data:{path:r.path,absolutePath:r.absolutePath},testId:`lib-pack-file-trigger-${r.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors",children:[i.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[i.jsx("span",{className:"font-bold truncate underline decoration-dotted decoration-outline",children:r.path}),i.jsxs("span",{className:"font-mono text-[8px] text-on-surface-variant shrink-0",children:["role: ",r.role,a?" · MISSING":` · ${r.bytes}B · ~${r.estimatedTokens} tokens`]})]}),r.summary&&i.jsx("div",{className:"mt-0.5 text-on-surface-variant text-[9px]",children:r.summary})]})},r.path)})})]}),i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Bundle preview"}),n&&i.jsx("div",{className:"px-3 py-2 font-mono text-[9px] text-on-surface-variant",children:"Loading bundle…"}),t&&i.jsxs(i.Fragment,{children:[t.missingFiles.length>0&&i.jsxs("div",{"data-testid":"lib-pack-missing-warning",className:"px-3 py-2 font-mono text-[9px] text-red-700 border-b border-outline-variant",children:["Warning: ",t.missingFiles.length," file",t.missingFiles.length===1?"":"s"," referenced by manifest but missing on disk."]}),i.jsx("pre",{"data-testid":"lib-pack-bundle-text",className:"font-mono text-[9px] text-on-surface bg-background px-3 py-2 max-h-96 overflow-y-auto whitespace-pre-wrap",children:t.bundleText})]})]})]})})}function k1e({entryId:e}){const t=Ut(),{data:n=[],isLoading:s,error:r}=tR(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=Sne(a?e:null);return s?i.jsx(ht,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading agent image…"})}):r||!a?i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Library",title:"Agent Image Not Found",description:(r==null?void 0:r.message)??`No agent image with id ${e}.`}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(C1e,{entry:a,preview:o,previewLoading:c})}function C1e({entry:e,preview:t,previewLoading:n}){const s=Ut(),r=jne(),[a,o]=E.useState(!1),[c,d]=E.useState(null),h=async()=>{if(!(t!=null&&t.starterSnippet))return;await pa(t.starterSnippet)&&(o(!0),window.setTimeout(()=>o(!1),2e3))},p=async()=>{d(null);try{await r.mutateAsync({id:e.id,pin:!e.pinned})}catch(f){d(f.message)}};return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"library-review-agent-image",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:`Library — Agent Image${e.sourceType==="builtin"?" (built-in)":""}`,title:`${e.name} v${e.version}`,description:e.notes??`Snapshot of ${e.sourceSeat}.`,actions:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"agent-image-pin-toggle",onClick:()=>void p(),disabled:r.isPending,children:e.pinned?"Unpin":"Pin"}),i.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})]})}),i.jsxs(Wo,{children:[i.jsx(ct,{label:"Runtime",value:i.jsx(Ps,{runtime:e.runtime,size:"sm",compact:!0,variant:"inline"}),testId:"lib-image-runtime"}),i.jsx(ct,{label:"Forks",value:String(e.stats.forkCount),testId:"lib-image-forks"}),i.jsx(ct,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-image-tokens"}),i.jsx(ct,{label:"Size",value:`${e.stats.estimatedSizeBytes}B`,testId:"lib-image-size"})]}),i.jsxs("div",{"data-testid":"lib-image-source",className:"font-mono text-[9px] text-on-surface-variant space-y-0.5",children:[i.jsxs("div",{children:["source seat: ",e.sourceSeat]}),i.jsxs("div",{"data-testid":"lib-image-source-cwd",children:["source cwd: ",e.sourceCwd??"(unknown — pre-Finding-2 manifest)"]}),i.jsxs("div",{children:["created: ",e.createdAt]}),i.jsxs("div",{children:["last used: ",e.stats.lastUsedAt??"never"]}),i.jsxs("div",{children:["path: ",e.sourcePath]}),i.jsxs("div",{"data-testid":"lib-image-pinned",className:e.pinned?"text-amber-700 font-bold":"",children:["pinned: ",String(e.pinned)]})]}),e.lineage.length>0&&i.jsxs("section",{"data-testid":"lib-image-lineage",className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Lineage"}),i.jsxs("div",{className:"px-3 py-2 font-mono text-[10px] text-on-surface",children:[e.lineage.join(" → ")," → ",i.jsx("span",{className:"font-bold",children:e.name})]})]}),i.jsx(x1e,{entry:e}),i.jsxs("section",{"data-testid":"lib-image-starter-snippet",className:"border border-outline bg-surface-lowest px-3 py-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface",children:"Use as starter"}),i.jsx(Ne,{variant:"outline",size:"sm","data-testid":"agent-image-copy-snippet",onClick:()=>void h(),disabled:!(t!=null&&t.starterSnippet),children:a?"Copied":"Copy snippet"})]}),i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant",children:"Paste into your agent.yaml's session_source. The instantiator resolves the image via the daemon AgentImageLibraryService at startup time."}),n&&i.jsx("div",{className:"font-mono text-[9px] text-on-surface-variant",children:"Loading snippet…"}),(t==null?void 0:t.starterSnippet)&&i.jsx("pre",{"data-testid":"lib-image-snippet-text",className:"font-mono text-[10px] bg-background border border-outline-variant px-2 py-1 whitespace-pre-wrap",children:t.starterSnippet})]}),c&&i.jsx("div",{"data-testid":"lib-image-pin-error",className:"font-mono text-[9px] text-red-600",children:c}),e.files.length>0&&i.jsxs("section",{className:"border border-outline-variant/40 bg-surface-lowest/[0.08]",children:[i.jsx("header",{className:"border-b border-outline-variant bg-background px-3 py-2 font-mono text-[10px] uppercase tracking-[0.10em] text-on-surface-variant",children:"Supplementary files"}),i.jsx("ul",{className:"divide-y divide-outline-variant",children:e.files.map(f=>i.jsx("li",{className:"font-mono text-[10px] text-on-surface","data-testid":`lib-image-file-${f.path}`,children:i.jsxs(mc,{data:{path:f.path,absolutePath:f.absolutePath},testId:`lib-image-file-trigger-${f.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors",children:[i.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[i.jsx("span",{className:"font-bold truncate underline decoration-dotted decoration-outline",children:f.path}),i.jsxs("span",{className:"font-mono text-[8px] text-on-surface-variant shrink-0",children:["role: ",f.role,f.bytes===null?" · MISSING":` · ${f.bytes}B`]})]}),f.summary&&i.jsx("div",{className:"mt-0.5 text-on-surface-variant text-[9px]",children:f.summary})]})},f.path))})]})]})})}async function E1e(e,t,n){const s=await fetch(ls(`/api/rigs/${encodeURIComponent(e)}/nodes/${encodeURIComponent(t)}`,n));if(!s.ok)throw new Error(`HTTP ${s.status}`);return s.json()}function R1e(e,t){const n=Vt();return Re({queryKey:["rig",e,"nodes",t,n],queryFn:()=>E1e(e,t,n),enabled:!!e&&!!t,refetchInterval:3e4,placeholderData:wi})}function A1e({pluginIds:e}){const{data:t=[]}=Fv();if(e.length===0)return i.jsx("div",{className:"px-3 py-4",children:i.jsx(Le,{label:"NO PLUGINS",description:"This agent's profile does not declare any plugins.",variant:"card",testId:"agent-plugins-empty"})});const n=new Map;for(const s of t)n.set(s.id,s);return i.jsx("ul",{"data-testid":"agent-plugins-list",className:"flex flex-col gap-2",children:e.map(s=>{const r=n.get(s);return i.jsx("li",{children:r?i.jsx(T1e,{entry:r}):i.jsx(I1e,{pluginId:s})},s)})})}function T1e({entry:e}){return i.jsxs(Ke,{to:"/plugins/$pluginId",params:{pluginId:e.id},"data-testid":`agent-plugin-chip-${e.id}`,className:"flex items-center justify-between gap-3 border border-outline-variant bg-surface-lowest/30 px-3 py-2 font-mono text-[11px] hover:bg-surface-low/50",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(vt,{tool:"skill",title:`${e.name} plugin`,size:"xs",decorative:!0}),i.jsx("span",{className:"truncate text-xs font-bold text-on-surface",children:e.name}),i.jsx("span",{className:"shrink-0 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:`v${e.version}`})]}),i.jsxs("span",{className:"flex shrink-0 items-center gap-2 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:[e.runtimes.map(t=>i.jsx("span",{className:"inline-block border border-outline-variant px-1.5 py-0.5 font-mono",children:t},t)),i.jsx("span",{title:e.path,children:e.sourceLabel})]})]})}function I1e({pluginId:e}){return i.jsxs(Ke,{to:"/plugins/$pluginId",params:{pluginId:e},"data-testid":`agent-plugin-chip-${e}`,className:"flex items-center justify-between gap-3 border border-dashed border-outline-variant bg-surface-lowest/20 px-3 py-2 font-mono text-[11px] hover:bg-surface-low/50",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(vt,{tool:"skill",title:`${e} plugin (unresolved)`,size:"xs",decorative:!0}),i.jsx("span",{className:"truncate text-xs font-bold text-on-surface",children:e})]}),i.jsx("span",{"data-testid":`agent-plugin-unresolved-${e}`,className:"shrink-0 text-[9px] uppercase tracking-[0.08em] text-on-surface-variant",children:"not discovered"})]})}function M1e(e){return e==null?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):typeof e=="string"&&e.trim()===""?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):e}function L1e(e,t){return e==="running"?"active":qE(e,t)}function O1e(e){return e==="active"?"active":e==="needs_input"?"needs input":e}function P1e({data:e,activityVisual:t}){var k,N,C;const n=BE(e.agentActivity)&&(t==null?void 0:t.state)!=="needs_input"&&(t==null?void 0:t.state)!=="blocked"?null:t,{state:s,source:r}=cp(e.agentActivity,e.terminalActive),a=(n==null?void 0:n.state)??s,o=n?O1e(n.state):L1e(s,e.agentActivity),c=n?n.state==="active":s==="running",d=!!(n!=null&&n.recent),h=d?null:FE(e.agentActivity),p=!d&&r!=="hook"&&r!=="none"?" (activity-grade)":"",f=((k=e.contextUsage)==null?void 0:k.availability)==="known"&&typeof e.contextUsage.usedPercentage=="number"?`${e.contextUsage.usedPercentage}%`:null,g=Do((N=e.contextUsage)==null?void 0:N.totalInputTokens,(C=e.contextUsage)==null?void 0:C.totalOutputTokens),x=Mp(g),y=e.resolvedSpecName&&e.resolvedSpecVersion?`${e.resolvedSpecName}@${e.resolvedSpecVersion}`:e.resolvedSpecName??null,b=i.jsxs("span",{"data-testid":"seat-overview-activity-state","data-activity-state":a,"data-activity-source":d?"ring":r,className:c?"topology-table-active-shimmer text-emerald-600":"text-on-surface",children:[o,h?` ${h.label}`:"",p]}),_=[{key:"runtime",label:"runtime",value:e.runtime?i.jsx(Ps,{runtime:e.runtime,model:e.model,size:"xs",compact:!0,variant:"inline",className:"max-w-full"}):null},{key:"model",label:"model",value:e.model,mono:!0},{key:"profile",label:"profile",value:e.profile,mono:!0},{key:"spec",label:"spec",value:y,mono:!0},{key:"activity",label:"activity",value:b},{key:"context-percent",label:"context %",value:f,mono:!0},{key:"total-tokens",label:"tokens",value:x,mono:!0}],w=_.length-1;return i.jsx("section",{"data-testid":"seat-overview-table",className:"border border-outline-variant bg-surface-lowest/30",children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-left",children:[i.jsx("thead",{children:i.jsx("tr",{"data-testid":"seat-overview-header-row",className:"border-b border-outline-variant/55 bg-background/30",children:_.map((R,T)=>i.jsx("th",{scope:"col","data-testid":`seat-overview-header-${R.key}`,className:`px-3 py-1.5 text-left font-mono text-[10px] font-normal lowercase tracking-[0.04em] text-on-surface-variant ${T<w?"border-r border-outline-variant/55":""}`,children:R.label},R.key))})}),i.jsx("tbody",{children:i.jsx("tr",{"data-testid":"seat-overview-data-row","data-row-shape":"data",children:_.map((R,T)=>i.jsx("td",{"data-testid":`seat-overview-cell-${R.key}`,className:`min-w-0 px-3 py-1.5 align-middle ${R.mono?"font-mono text-[11px]":"text-[11px]"} text-on-surface ${T<w?"border-r border-outline-variant/55":""}`,children:i.jsx("div",{className:"truncate",children:M1e(R.value)})},R.key))})})]})})})}function D1e(e){return e==null?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):typeof e=="string"&&e.trim()===""?i.jsx("span",{className:"text-on-surface-variant",children:"—"}):e}function $1e({data:e}){var s;const t=((s=e.currentQitems)==null?void 0:s[0])??null,n=t?i.jsxs("span",{className:"flex min-w-0 items-baseline gap-2",children:[i.jsx("span",{className:"shrink-0 font-mono text-[10px] text-on-surface-variant",children:t.qitemId}),i.jsx("span",{className:"min-w-0 truncate text-[11px] text-on-surface",children:t.bodyExcerpt})]}):null;return i.jsx("section",{"data-testid":"seat-overview-secondary",className:"border border-outline-variant bg-surface-lowest/30",children:i.jsxs("dl",{className:"divide-y divide-outline-variant/55",children:[i.jsx(p8,{fieldKey:"cwd",label:"cwd",value:e.cwd,mono:!0,titleAttr:e.cwd??void 0}),i.jsx(p8,{fieldKey:"current-work",label:"current work",value:n})]})})}function p8({fieldKey:e,label:t,value:n,mono:s,titleAttr:r}){return i.jsxs("div",{"data-testid":`seat-overview-secondary-row-${e}`,className:"flex min-w-0 items-baseline gap-3 px-3 py-1.5",title:r,children:[i.jsx("dt",{className:"shrink-0 font-mono text-[10px] lowercase tracking-[0.04em] text-on-surface-variant",children:t}),i.jsx("dd",{"data-testid":`seat-overview-secondary-cell-${e}`,className:`min-w-0 flex-1 truncate ${s?"font-mono text-[11px]":"text-[11px]"} text-on-surface`,children:D1e(n)})]})}function B1e(e){return e.startupStatus==="failed"?"Startup failed":e.startupStatus==="attention_required"?"Attention required":e.latestError?"Error":null}function q1e(e){return e.startupStatus==="failed"||e.latestError&&e.startupStatus!=="attention_required"?"destructive":"default"}function F1e({data:e}){const t=B1e(e);if(!t)return null;const n=!!e.latestError,s=!!e.recoveryGuidance;return i.jsxs(os,{"data-testid":"seat-notification-banner","data-startup-status":e.startupStatus??"unknown",variant:q1e(e),children:[i.jsx(lU,{"data-testid":"seat-notification-headline",className:"font-mono text-[11px] uppercase tracking-[0.08em]",children:t}),n?i.jsx(Yn,{"data-testid":"seat-notification-error",className:"font-mono text-[10px]",children:e.latestError}):null,s&&e.recoveryGuidance?i.jsx(Yn,{"data-testid":"seat-notification-guidance",className:"mt-1 font-mono text-[10px] text-on-surface",children:e.recoveryGuidance.summary}):null]})}function z1e(e){switch(e){case"resumed":return"text-success";case"rebuilt":return"text-success";case"fresh":return"text-foreground-muted";case"failed":return"text-destructive";case"checkpoint_written":return"text-success";case"fresh_no_checkpoint":return"text-foreground-muted";default:return"text-foreground-muted"}}const $o="border border-outline-variant bg-surface-lowest/30 p-3";function H1e(e){switch(e){case"ready":return"text-green-600";case"pending":return"text-amber-600";case"attention_required":return"text-orange-600";case"failed":return"text-red-600";default:return"text-on-surface-variant"}}function U1e(e){switch(e){case"attention_required":return"attention required";default:return e??"stopped"}}function V1e(e){if(!e)return null;const t=e.match(/^local:agents\/([^/]+)$/);return(t==null?void 0:t[1])??null}function $r({label:e,value:t}){return t==null||t===""?null:i.jsxs("div",{className:"flex justify-between gap-3 font-mono text-[10px]",children:[i.jsx("span",{className:"text-on-surface-variant",children:e}),i.jsx("span",{className:"truncate text-right text-on-surface",children:t})]})}function W1e({data:e}){const t=V1e(e.agentRef),{data:n=[],isLoading:s}=Bv("agent"),r=t?n.filter(d=>d.name===t):[],a=r.length===1?r[0].id:null,{data:o,isLoading:c}=JE(a);return i.jsxs("div",{"data-testid":"live-agent-spec-section",className:"space-y-4",children:[e.compactSpec.name&&i.jsxs("section",{"data-testid":"detail-compact-spec",className:$o,children:[i.jsx("div",{className:"mb-2 font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Resolved Agent Spec"}),i.jsxs("div",{className:"space-y-0.5",children:[i.jsx($r,{label:"Spec",value:e.compactSpec.name}),i.jsx($r,{label:"Version",value:e.compactSpec.version}),i.jsx($r,{label:"Profile",value:e.compactSpec.profile}),i.jsx($r,{label:"Skills",value:e.compactSpec.skillCount}),i.jsx($r,{label:"Guidance",value:e.compactSpec.guidanceCount})]})]}),t?s||c?i.jsx("div",{className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"Loading agent spec..."}):r.length===0?i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"}):r.length>1?i.jsxs("div",{"data-testid":"agent-spec-ambiguous",className:"p-4 font-mono text-[10px] text-amber-600",children:["Agent spec ambiguous (",r.length,' matches for "',t,'")']}):!o||o.kind!=="agent"?i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"}):i.jsxs(i.Fragment,{children:[i.jsx($A,{review:o,yaml:o.raw,testIdPrefix:"live-agent",sourcePath:o.sourcePath}),i.jsxs("section",{"data-testid":"live-agent-plugins-section",className:"border border-outline-variant bg-surface-lowest/30 p-3",children:[i.jsx("div",{className:"mb-2 font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Plugins"}),i.jsx(A1e,{pluginIds:G1e(o)})]})]}):i.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-on-surface-variant",children:"No agent spec available"})]})}function G1e(e){if(!e||typeof e!="object")return[];const t=e.resources;if(!t||typeof t!="object")return[];const n=t.plugins;if(!Array.isArray(n))return[];const s=[];for(const r of n)r&&typeof r=="object"&&typeof r.id=="string"?s.push(r.id):typeof r=="string"&&s.push(r);return s}function K1e({rigId:e,logicalId:t,data:n}){const s=Vt()!==at,r=async()=>{n.tmuxAttachCommand&&await pa(n.tmuxAttachCommand)},a=async()=>{try{await iA({rigId:e,logicalId:t})}catch{}},o=async()=>{n.resumeCommand&&await pa(n.resumeCommand)};return s?i.jsx("div",{"data-testid":"live-node-actions-remote-readonly","data-remote-readonly":"true",className:"font-mono text-[9px] uppercase tracking-wide text-on-surface-variant",children:"read-only — remote host"}):i.jsxs("div",{"data-testid":"live-node-actions",className:"flex flex-wrap gap-2",children:[i.jsxs("button",{onClick:a,"data-testid":"detail-cmux-open",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(vt,{tool:"cmux",size:"sm"}),"Open CMUX"]}),n.tmuxAttachCommand&&i.jsxs("button",{onClick:r,"data-testid":"detail-copy-attach",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(vt,{tool:"tmux",size:"sm"}),"Copy tmux attach"]}),n.resumeCommand&&i.jsxs("button",{onClick:o,"data-testid":"detail-copy-resume",className:"inline-flex min-h-11 items-center gap-1.5 px-3 py-2 border border-outline-variant bg-surface-lowest/30 font-mono text-[10px] uppercase tracking-wide text-on-surface hover:bg-surface-low/60",children:[i.jsx(tJ,{"aria-hidden":"true",className:"h-4 w-4 shrink-0",strokeWidth:1.5}),"Copy resume command"]}),n.resumeCommandLabel&&i.jsx("span",{"data-testid":"detail-resume-command-label",className:"self-center font-mono text-[9px] text-on-surface-variant",children:n.resumeCommandLabel})]})}function Y1e({data:e}){const t=e.startupStatus==="failed"||e.startupStatus==="attention_required"||!!e.latestError;return i.jsxs("section",{"data-testid":"live-node-status",className:"grid gap-2 border border-outline-variant bg-surface-lowest/30 p-3 sm:grid-cols-2",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Startup"}),i.jsx("span",{className:H1e(e.startupStatus),"data-testid":"detail-startup-status",children:U1e(e.startupStatus)})]}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant",children:"Restore"}),i.jsx("span",{className:`font-mono text-xs font-bold ${z1e(e.restoreOutcome)}`,"data-testid":"detail-restore-outcome",children:e.restoreOutcome})]}),t&&i.jsxs("div",{className:`sm:col-span-2 mt-1 p-2 border ${e.startupStatus==="attention_required"?"bg-orange-50 border-orange-200":"bg-red-50 border-red-200"}`,"data-testid":"detail-failure-banner",children:[i.jsx("div",{className:`font-mono text-[9px] font-bold mb-1 ${e.startupStatus==="attention_required"?"text-orange-700":"text-red-700"}`,children:e.startupStatus==="attention_required"?"Attention Required":e.startupStatus==="failed"?"Startup Failed":"Error"}),e.latestError&&i.jsx("div",{className:`font-mono text-[9px] mb-1 ${e.startupStatus==="attention_required"?"text-orange-700":"text-red-600"}`,children:e.latestError}),i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant",children:e.startupStatus==="attention_required"?`Use rig capture ${e.canonicalSessionName??"<session>"} to inspect the prompt, then rig send ${e.canonicalSessionName??"<session>"} to clear it.`:e.startupStatus==="failed"?"Check logs with: rig ps --nodes --rig <name>, or restart with: rig up":"Try: rig restore <snapshotId>"}),e.recoveryGuidance&&i.jsxs("div",{className:"mt-2 border-t border-outline-variant pt-2","data-testid":"detail-recovery-guidance",children:[i.jsx("div",{className:"font-mono text-[8px] font-bold text-on-surface mb-1",children:"Recovery"}),i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant mb-1",children:e.recoveryGuidance.summary}),i.jsx("div",{className:"space-y-0.5 mb-1",children:e.recoveryGuidance.commands.map((n,s)=>i.jsx("code",{className:"font-mono text-[8px] text-on-surface bg-surface-low px-1 py-0.5 block",children:n},`${n}-${s}`))}),i.jsx("div",{className:"space-y-0.5",children:e.recoveryGuidance.notes.map((n,s)=>i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant",children:n},`${n}-${s}`))})]})]})]})}function Q1e({data:e}){return!e.recentEvents||e.recentEvents.length===0?null:i.jsxs("section",{"data-testid":"live-node-recent-events",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Recent Events"}),i.jsx("div",{className:"space-y-0.5",children:e.recentEvents.slice(0,10).map((t,n)=>i.jsxs("div",{className:"font-mono text-[9px] flex justify-between gap-3",children:[i.jsx("span",{className:"text-on-surface truncate",children:t.type}),i.jsx("span",{className:"text-on-surface-variant ml-2 shrink-0",children:t.createdAt})]},`${t.type}-${n}`))})]})}function X1e({data:e}){const{outgoing:t,incoming:n}=e.edges;return t.length===0&&n.length===0?null:i.jsxs("section",{"data-testid":"detail-edges",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Edges"}),i.jsxs("div",{className:"space-y-0.5 font-mono text-[10px]",children:[t.map((s,r)=>{var a;return i.jsxs("div",{className:"flex gap-1",children:[i.jsx("span",{className:"text-on-surface-variant",children:"->"}),i.jsx("span",{className:"text-on-surface-variant",children:s.kind}),i.jsx("span",{className:"text-on-surface",children:((a=s.to)==null?void 0:a.logicalId)??"?"})]},`out-${r}`)}),n.map((s,r)=>{var a;return i.jsxs("div",{className:"flex gap-1",children:[i.jsx("span",{className:"text-on-surface-variant",children:"<-"}),i.jsx("span",{className:"text-on-surface-variant",children:s.kind}),i.jsx("span",{className:"text-on-surface",children:((a=s.from)==null?void 0:a.logicalId)??"?"})]},`in-${r}`)})]})]})}function Z1e({data:e}){return e.peers.length===0?null:i.jsxs("section",{"data-testid":"detail-peers",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Peers"}),i.jsx("div",{className:"space-y-1 font-mono text-[10px]",children:e.peers.map(t=>i.jsxs("div",{className:"space-y-0",children:[i.jsxs("div",{className:"flex justify-between gap-3",children:[i.jsx("span",{className:"text-on-surface",children:t.logicalId}),i.jsx("span",{className:"text-on-surface-variant",children:t.runtime??"-"})]}),t.canonicalSessionName&&i.jsx("div",{className:"text-[9px] text-on-surface-variant truncate",children:t.canonicalSessionName})]},t.logicalId))})]})}function J1e({data:e}){var n,s,r;const t=e.contextUsage;return i.jsxs("section",{"data-testid":"detail-context-usage",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] text-on-surface-variant uppercase tracking-wider mb-2",children:"Context"}),(t==null?void 0:t.availability)==="known"?i.jsxs("div",{className:"space-y-0.5 font-mono text-[10px]",children:[i.jsx($r,{label:"Used",value:t.usedPercentage!=null?`${t.usedPercentage}%`:null}),i.jsx($r,{label:"Remaining",value:t.remainingPercentage!=null?`${t.remainingPercentage}%`:null}),i.jsx($r,{label:"Window",value:(n=t.contextWindowSize)==null?void 0:n.toLocaleString()}),i.jsx($r,{label:"Input tokens",value:(s=t.totalInputTokens)==null?void 0:s.toLocaleString()}),i.jsx($r,{label:"Output tokens",value:(r=t.totalOutputTokens)==null?void 0:r.toLocaleString()}),i.jsx($r,{label:"Sampled",value:t.sampledAt}),t.fresh===!1&&i.jsx("div",{className:"font-mono text-[9px] text-amber-600 mt-1",children:"Stale sample"})]}):i.jsxs("div",{className:"font-mono text-[10px] text-on-surface-variant",children:["unknown",t!=null&&t.reason?` (${t.reason})`:""]})]})}function eSe({data:e,activityVisual:t}){return i.jsxs("div",{"data-testid":"live-overview-section",className:"space-y-4",children:[i.jsx(F1e,{data:e}),i.jsx(P1e,{data:e,activityVisual:t}),i.jsx($1e,{data:e}),i.jsx(nSe,{data:e}),i.jsx(Q1e,{data:e})]})}function tSe({rigId:e,logicalId:t,data:n,isAgent:s}){return i.jsxs("div",{"data-testid":"live-details-section",className:"space-y-4",children:[i.jsx(sSe,{rigId:e,logicalId:t,data:n}),s?i.jsx(W1e,{data:n}):null,i.jsx(X1e,{data:n}),i.jsx(Z1e,{data:n}),i.jsx(J1e,{data:n}),i.jsx(rSe,{data:n})]})}function nSe({data:e}){return Vt()!==at?i.jsx("div",{"data-testid":"node-detail-terminal-remote-gated",className:"font-mono text-[10px] text-on-surface-variant p-4",children:"Terminal not available for remote hosts — terminal streams are this host's local sessions. Viewing a remote host is read-only."}):e.canonicalSessionName?i.jsx("div",{"data-testid":"live-terminal-shell",className:"bg-stone-950/65 text-stone-50 backdrop-blur-sm h-[500px]",children:i.jsx(Uo,{sessionName:e.canonicalSessionName,terminalKey:`node-detail:${e.canonicalSessionName}`,testIdPrefix:"node-detail-terminal",fit:"contain"})}):i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant p-4",children:"No canonical session name; terminal preview unavailable."})}function sSe({rigId:e,logicalId:t,data:n}){return i.jsxs("div",{"data-testid":"live-startup-section",className:"space-y-4",children:[i.jsx(Y1e,{data:n}),n.infrastructureStartupCommand&&i.jsxs("section",{"data-testid":"live-node-infra-startup",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Startup Command"}),i.jsx("code",{className:"font-mono text-[9px] text-on-surface bg-surface-low px-2 py-1 block",children:n.infrastructureStartupCommand})]}),n.startupActions.length>0&&i.jsxs("section",{"data-testid":"live-startup-actions",className:$o,children:[i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wider text-on-surface-variant mb-2",children:"Startup Actions"}),i.jsx("div",{className:"space-y-1",children:n.startupActions.map((s,r)=>i.jsxs("div",{className:"font-mono text-[10px] text-on-surface",children:[i.jsxs("span",{className:"text-on-surface-variant",children:[s.type,":"]})," ",s.value]},`${s.type}-${s.value}-${r}`))})]}),n.startupFiles.length>0?i.jsxs("section",{className:"border border-outline-variant bg-surface-lowest/30",children:[i.jsx("div",{className:"px-3 py-2 border-b border-outline-variant font-mono text-xs font-bold",children:"Startup Files"}),i.jsx("ul",{className:"divide-y divide-outline-variant",children:n.startupFiles.map((s,r)=>i.jsx("li",{"data-testid":`live-startup-file-${s.path}`,children:i.jsxs(mc,{data:{path:s.path,absolutePath:s.absolutePath},testId:`live-startup-file-trigger-${s.path}`,className:"block w-full px-3 py-2 text-left hover:bg-surface-low/60 transition-colors font-mono text-[10px]",children:[i.jsx("span",{className:"font-bold underline decoration-dotted decoration-outline",children:s.path}),i.jsxs("span",{className:"text-on-surface-variant ml-2",children:["(",s.deliveryHint,")"]}),s.required&&i.jsx("span",{className:"text-red-500 text-[8px] ml-1",children:"REQUIRED"})]})},`${s.path}-${r}`))})]}):i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant p-4",children:"No startup files declared"})]})}function rSe({data:e}){return e.transcript.enabled?i.jsx("div",{"data-testid":"live-transcript-section",className:"space-y-4",children:i.jsxs("section",{"data-testid":"detail-transcript",className:$o,children:[i.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Transcript"}),i.jsx("div",{className:"font-mono text-[10px] text-on-surface",children:e.transcript.path??"enabled"}),e.transcript.tailCommand&&i.jsx("button",{type:"button",onClick:()=>pa(e.transcript.tailCommand),className:"mt-2 w-full border border-outline-variant bg-surface-lowest/40 px-2 py-1 text-left font-mono text-[8px] uppercase text-on-surface hover:bg-surface-low",children:"Copy tail command"})]})}):i.jsx("div",{"data-testid":"live-transcript-section",className:"font-mono text-[10px] text-on-surface-variant p-4",children:"Transcript capture not enabled"})}function iSe({tabs:e,activeTab:t,onSelect:n}){return i.jsx("div",{className:"flex gap-1 border-b border-outline-variant",role:"tablist","data-testid":"live-node-tabs",children:e.map(s=>i.jsx("button",{role:"tab","aria-selected":t===s,"data-testid":`live-tab-${s}`,onClick:()=>n(s),className:`min-h-11 px-3 py-2 font-mono text-[10px] uppercase tracking-wider transition-colors ${t===s?"border-b-2 border-on-surface text-on-surface font-bold -mb-px":"text-on-surface-variant hover:text-on-surface"}`,children:s.replace("-"," ")},s))})}function iW({rigId:e,logicalId:t}){const{data:n,isLoading:s,error:r}=R1e(e,t),a=E.useMemo(()=>By(n?[{nodeId:`${n.rigId}::${n.logicalId}`,rigId:n.rigId,rigName:n.rigName,logicalId:n.logicalId,canonicalSessionName:n.canonicalSessionName,agentActivity:n.agentActivity??null,currentQitems:n.currentQitems??null,startupStatus:n.startupStatus,terminalActive:n.terminalActive,hasAssignedWork:n.hasAssignedWork??!1,pendingWorkCount:n.pendingWorkCount??0}]:[]),[n]),o=qy(a),c=n?o.getNodeActivity(`${n.rigId}::${n.logicalId}`,{agentActivity:n.agentActivity??null,currentQitems:n.currentQitems??null,startupStatus:n.startupStatus,terminalActive:n.terminalActive,hasAssignedWork:n.hasAssignedWork??!1,pendingWorkCount:n.pendingWorkCount??0}):null,[d,h]=E.useState("overview"),p=n?n.nodeKind!=="infrastructure":!0,f=["overview","details"];return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"live-node-details",className:"space-y-4",children:[i.jsx(Tn,{eyebrow:"Live Node Details",title:(n==null?void 0:n.canonicalSessionName)??t,description:`${(n==null?void 0:n.rigName)??e} / ${(n==null?void 0:n.podNamespace)??pi(t)??Eu((n==null?void 0:n.podId)??null)} / ${t}`,actions:n?i.jsx(Ps,{runtime:n.runtime,model:n.model,size:"sm",compact:!0,className:"bg-surface-lowest/40 backdrop-blur-sm"}):null}),s&&i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading..."}),r&&i.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:r.message}),n&&i.jsxs(i.Fragment,{children:[i.jsx(K1e,{rigId:e,logicalId:t,data:n}),i.jsx(iSe,{tabs:f,activeTab:d,onSelect:h}),i.jsxs("div",{"data-testid":"live-node-tab-body",className:"space-y-4",children:[d==="overview"&&i.jsx(eSe,{data:n,activityVisual:c}),d==="details"&&i.jsx(tSe,{rigId:e,logicalId:t,data:n,isAgent:p})]})]})]})})}function aSe(e){return`'${e.replace(/'/g,"'\\''")}'`}function oSe(e){const t=e.tmuxWindow?`${e.tmuxSession}:${e.tmuxWindow}`:e.tmuxSession;return`tmux attach -t ${aSe(t)}`}function m8({label:e,activeLabel:t,onClick:n,testId:s,tool:r}){const[a,o]=E.useState(!1),c=E.useRef(null);E.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=async()=>{await n()&&(o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{o(!1),c.current=null},900))};return i.jsxs("button",{type:"button","data-testid":s,"aria-label":e,onClick:()=>{d()},className:le("inline-flex items-center gap-1.5 px-spacing-2 py-1 border font-mono text-[10px] uppercase transition-colors duration-150 ease-tactical",a?"bg-inverse-surface text-background border-on-surface":"bg-surface-lowest text-on-surface border-outline-variant hover:bg-surface-low"),children:[r?i.jsx(vt,{tool:r,size:"sm"}):null,i.jsx("span",{children:a?t:e})]})}function lSe({session:e,onAdopt:t}){return i.jsx("div",{"data-testid":"discovered-node",className:le("border-dashed border border-foreground/20 bg-[hsl(var(--surface-container-lowest)/0.72)] px-spacing-4 py-spacing-3 mb-spacing-2 shadow-[0_10px_28px_rgba(20,20,20,0.04)] backdrop-blur-sm"),children:i.jsxs("div",{className:"flex flex-col gap-spacing-3 lg:flex-row lg:items-center lg:justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-x-spacing-3 gap-y-spacing-1",children:[i.jsx("span",{"data-testid":"runtime-badge",children:i.jsx(Ps,{runtime:e.runtimeHint,size:"sm",compact:!0})}),i.jsx("div",{"data-testid":"session-name",className:"font-mono text-[13px] leading-5 text-foreground",title:e.tmuxSession,children:e.tmuxSession}),e.confidence==="medium"?i.jsx("div",{"data-testid":"runtime-inferred-note",className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"runtime inferred"}):null]}),e.cwd?i.jsxs("div",{className:"mt-spacing-2 min-w-0",children:[i.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"cwd"}),i.jsx("div",{className:"font-mono text-[12px] leading-5 text-foreground-muted truncate",title:e.cwd,children:e.cwd})]}):null]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-spacing-2 lg:justify-end",children:[i.jsx(m8,{label:"copy tmux",activeLabel:"copied",testId:"copy-tmux-btn",tool:"tmux",onClick:async()=>await pa(oSe(e))}),e.cwd?i.jsx(m8,{label:"copy cwd",activeLabel:"copied",testId:"copy-cwd-btn",onClick:async()=>await pa(e.cwd??"")}):null,i.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"adopt-btn",onClick:()=>t(e.id),children:"ADOPT"})]})]})})}function cSe(){const[e,t]=E.useState(null),[n,s]=E.useState(!1),r=E.useCallback(async()=>{s(!0);try{const a=await fetch("/api/discovery/draft-rig",{method:"POST"});if(!a.ok){t(`# Error: draft generation failed (HTTP ${a.status})`);return}const o=await a.text();t(o)}catch{t("# Error: failed to reach daemon")}finally{s(!1)}},[]);return i.jsxs("div",{className:"mt-spacing-4 border-t border-foreground/10 pt-spacing-4","data-testid":"generate-draft-section",children:[i.jsx(Ne,{variant:"tactical",onClick:r,disabled:n,"data-testid":"generate-draft-btn",className:"mb-spacing-3",children:n?"GENERATING...":"GENERATE RIG SPEC"}),e&&(()=>{const a=e.split(`
588
588
  `),o=a.filter(d=>d.startsWith("# WARNING:")).map(d=>d.replace(/^# WARNING:\s*/,"")),c=a.filter(d=>!d.startsWith("# WARNING:")).join(`
589
589
  `).trim();return i.jsxs("div",{className:"relative",children:[o.length>0&&i.jsx("div",{className:"mb-spacing-2 p-spacing-2 bg-warning/10 border border-warning/30 text-label-sm","data-testid":"draft-warnings",children:o.map((d,h)=>i.jsx("div",{className:"text-warning font-mono",children:d},h))}),i.jsx("pre",{className:"bg-surface-low p-spacing-3 text-label-sm font-mono overflow-x-auto max-h-64 border border-foreground/10","data-testid":"draft-yaml",children:c}),i.jsx("button",{onClick:()=>{var d;return(d=navigator.clipboard)==null?void 0:d.writeText(e)},className:"absolute top-2 right-2 text-label-sm text-foreground-muted hover:text-foreground","data-testid":"copy-draft-btn",children:"COPY"})]})})()]})}function uSe(){var k,N;const{data:e=[]}=iR({status:"active",runtimeHint:["claude-code","codex"],minConfidence:"medium"}),t=bz(),{data:n=[]}=Wr(),s=Ese(),r=e,[a,o]=E.useState(null),[c,d]=E.useState(!1),[h,p]=E.useState(""),[f,g]=E.useState(""),x=C=>{o(C),d(!0),p(""),g(""),s.reset()},y=()=>{d(!1),o(null)},b=()=>{!a||!h||!f.trim()||s.mutate({discoveredId:a,rigId:h,logicalId:f.trim()},{onSuccess:y})},_=((k=s.error)==null?void 0:k.message)??null,w=s.isPending;return i.jsx(ht,{children:i.jsxs("div",{"data-testid":"discovery-overlay",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-col gap-spacing-4 border-b border-foreground/10 pb-spacing-5 sm:flex-row sm:items-end sm:justify-between",children:[i.jsxs("div",{className:"max-w-[620px]",children:[i.jsx("h2",{className:"text-headline-lg uppercase",children:"DISCOVERY"}),i.jsx("p",{className:"mt-spacing-1 text-body-md text-foreground-muted",children:"Running agent sessions currently visible on this machine. Copy a tmux attach command, review the working directory, or adopt the session into a rig."})]}),i.jsx(Ne,{variant:"ghost",size:"sm","data-testid":"scan-now-btn",disabled:t.isPending,onClick:()=>t.mutate(),children:t.isPending?"SCANNING...":"SCAN NOW"})]}),t.isError?i.jsxs("div",{className:"mt-spacing-4 text-label-sm text-destructive","data-testid":"scan-error",children:["Discovery scan failed: ",(N=t.error)==null?void 0:N.message]}):null,r.length===0?i.jsx("div",{className:"py-spacing-8","data-testid":"discovery-empty",children:i.jsx("p",{className:"text-body-md text-foreground-muted",children:"No running Claude or Codex sessions are currently visible."})}):i.jsxs("div",{className:"mt-spacing-6 space-y-spacing-3","data-testid":"discovery-active-section",children:[i.jsxs("div",{className:"mb-spacing-2",children:[i.jsx("h3",{className:"text-headline-sm uppercase",children:"Running agents"}),i.jsxs("p",{className:"text-label-md text-foreground-muted",children:[r.length," session",r.length!==1?"s":""," available to inspect or adopt"]})]}),r.map(C=>i.jsx(lSe,{session:C,onAdopt:x},C.id))]}),i.jsx(cSe,{})]}),i.jsx(Gy,{open:c,onOpenChange:d,children:i.jsxs(Bp,{"data-testid":"adopt-dialog",children:[i.jsxs(Ky,{children:[i.jsx(qp,{className:"text-headline-md uppercase",children:"ADOPT SESSION"}),i.jsx(Fp,{children:"Bind this session to an existing logical node in the rig."})]}),i.jsxs("div",{className:"space-y-spacing-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-label-sm uppercase block mb-spacing-1",children:"RIG"}),i.jsxs("select",{"data-testid":"adopt-rig-input",value:h,onChange:C=>p(C.target.value),className:"w-full bg-surface-lowest border-b border-outline py-spacing-1 text-body-md font-mono focus:outline-none focus:border-on-surface appearance-none cursor-pointer",children:[i.jsx("option",{value:"",children:"Select a rig..."}),n.map(C=>i.jsxs("option",{value:C.id,children:[C.name," (",C.nodeCount," nodes)"]},C.id))]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-label-sm uppercase block mb-spacing-1",children:"LOGICAL ID (required)"}),i.jsx("input",{"data-testid":"adopt-logical-input",type:"text",value:f,onChange:C=>g(C.target.value),className:"w-full bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono focus:outline-none focus:border-primary"}),i.jsx("p",{className:"mt-spacing-1 text-label-sm text-foreground-muted",children:"Enter the logical ID of an existing node in the target rig. For pod placement, use the Discovery drawer instead."})]})]}),_&&i.jsx("p",{className:"text-destructive text-label-sm","data-testid":"adopt-error",children:_}),i.jsxs(Yy,{children:[i.jsx(Ne,{variant:"ghost",onClick:()=>d(!1),children:"CANCEL"}),i.jsx(Ne,{variant:"tactical",onClick:b,disabled:!h||!f.trim()||w,"data-testid":"adopt-confirm",children:w?"ADOPTING...":"ADOPT"})]})]})})]})})}async function dSe(e){const t=new URLSearchParams;e.qitemId&&t.set("qitem_id",e.qitemId),e.actionVerb&&t.set("action_verb",e.actionVerb),e.actorSession&&t.set("actor_session",e.actorSession),e.since&&t.set("since",e.since),e.until&&t.set("until",e.until),e.limit!==void 0&&t.set("limit",String(e.limit)),e.beforeId&&t.set("before_id",e.beforeId);const n=t.toString(),s=`/api/mission-control/audit${n?`?${n}`:""}`,r=await fetch(s);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}function aW(e){return Re({queryKey:["mission-control","audit",e],queryFn:()=>dSe(e)})}const oW=["approve","deny","route","annotate","hold","drop","handoff"],hSe=new Set(["done","closed","completed","canceled","cancelled","denied","expired","handed-off","handed_off","routed"]);function fSe(e){if(e.answer)return e.answer.outcome==="recorded";if(e.reconciled&&typeof e.closedQitem=="object"&&e.closedQitem){const t=e.closedQitem.state;return typeof t=="string"&&!hSe.has(t.toLowerCase())}return!1}async function pSe(e){const t=await fetch("/api/mission-control/action",{method:"POST",headers:{"Content-Type":"application/json",...PE()},body:JSON.stringify(e)}),n=await t.text();let s;if(n)try{s=JSON.parse(n)}catch{s=void 0}if(!t.ok){const r=n.trim();let a=r?`HTTP ${t.status}: ${r}`:`HTTP ${t.status}`,o;if(typeof s=="object"&&s){a=`HTTP ${t.status}`;const d=s;if(d.error==="remote_action_failed"){const h=["remote_action_failed"];typeof d.detail=="string"&&d.detail.length>0&&h.push(d.detail),typeof d.remoteStatus=="number"&&h.push(`remote status ${d.remoteStatus}`),a=h.join(" · ")}else typeof d.message=="string"&&d.message.length>0&&(a=d.message);typeof d.error=="string"&&d.error.length>0&&(o=d.error)}const c=new Error(a);throw o&&(c.code=o),c.status=t.status,c.details=s,c}if(!s||typeof s!="object")throw new Error("Invalid JSON response from action endpoint");return s}function lW(){const e=bt();return Xt({mutationFn:pSe,onSuccess:(t,n)=>{e.invalidateQueries({queryKey:["mission-control","view"]}),e.invalidateQueries({queryKey:["mission-control","audit"]});const s=fSe(t);(n.verb!=="answer"||s)&&e.invalidateQueries({queryKey:["queue","item",n.qitemId]}),t.createdQitemId&&e.invalidateQueries({queryKey:["queue","item",t.createdQitemId]}),s&&e.invalidateQueries({queryKey:["attention-items"]}),e.invalidateQueries({queryKey:["slices"]})}})}function ao(e){return typeof window>"u"?"":new URL(window.location.href).searchParams.get(e)??""}function mSe(){var k,N,C,R;const[e,t]=E.useState(()=>ao("qitem_id")||ao("qitem")),[n,s]=E.useState(()=>ao("action_verb")||ao("verb")),[r,a]=E.useState(()=>ao("actor_session")||ao("actor")),[o,c]=E.useState(()=>ao("since")),[d,h]=E.useState(()=>ao("until")),[p]=E.useState(50),[f,g]=E.useState([]),x={qitemId:e||void 0,actionVerb:n||void 0,actorSession:r||void 0,since:o||void 0,until:d||void 0,limit:p,beforeId:f[f.length-1]},y=aW(x);function b(){g([])}function _(){var T;(T=y.data)!=null&&T.nextBeforeId&&g([...f,y.data.nextBeforeId])}function w(){g(f.slice(0,-1))}return i.jsxs("div",{"data-testid":"mc-view-audit-history",className:"space-y-3 p-3",children:[i.jsxs("header",{className:"space-y-0.5",children:[i.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.16em] text-on-surface-variant",children:"audit-history"}),i.jsx("h2",{className:"font-headline text-lg text-on-surface",children:"Audit history"}),i.jsxs("p",{className:"text-xs text-on-surface-variant",children:["Browse ",i.jsx("code",{children:"mission_control_actions"})," by qitem, verb, actor, and time range. Read-only."]})]}),i.jsxs("div",{"data-testid":"mc-audit-filters",className:"grid grid-cols-1 gap-2 border border-outline-variant bg-background p-2 sm:grid-cols-2",children:[i.jsx("input",{type:"text","data-testid":"mc-audit-filter-qitem-id",placeholder:"qitem_id (exact)",value:e,onChange:T=>t(T.target.value),className:"border border-outline-variant px-2 py-1 font-mono text-xs"}),i.jsxs("select",{"data-testid":"mc-audit-filter-action-verb",value:n,onChange:T=>s(T.target.value),className:"border border-outline-variant px-2 py-1 font-mono text-xs",children:[i.jsx("option",{value:"",children:"all verbs"}),oW.map(T=>i.jsx("option",{value:T,children:T},T))]}),i.jsx("input",{type:"text","data-testid":"mc-audit-filter-actor-session",placeholder:"actor_session (e.g., operator-alex@kernel)",value:r,onChange:T=>a(T.target.value),className:"border border-outline-variant px-2 py-1 font-mono text-xs"}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"datetime-local","data-testid":"mc-audit-filter-since",value:o,onChange:T=>c(T.target.value),className:"flex-1 border border-outline-variant px-2 py-1 font-mono text-[11px]",title:"since"}),i.jsx("input",{type:"datetime-local","data-testid":"mc-audit-filter-until",value:d,onChange:T=>h(T.target.value),className:"flex-1 border border-outline-variant px-2 py-1 font-mono text-[11px]",title:"until"})]}),i.jsx("button",{type:"button","data-testid":"mc-audit-filter-apply",onClick:b,className:"border border-on-surface bg-inverse-surface px-2 py-1 font-mono text-[10px] uppercase tracking-[0.12em] text-background",children:"Apply filters"})]}),y.isLoading?i.jsx("div",{"data-testid":"mc-audit-loading",className:"font-mono text-[10px] text-on-surface-variant",children:"loading..."}):y.isError?i.jsxs("div",{"data-testid":"mc-audit-error",className:"font-mono text-[11px] text-red-700",children:["error: ",y.error.message]}):((k=y.data)==null?void 0:k.rows.length)===0?i.jsx("div",{"data-testid":"mc-audit-empty",className:"font-mono text-[11px] text-on-surface-variant",children:"No audit entries match these filters."}):i.jsx("ul",{"data-testid":"mc-audit-rows",className:"space-y-1",children:(N=y.data)==null?void 0:N.rows.map(T=>i.jsxs("li",{"data-testid":"mc-audit-row","data-action-id":T.actionId,className:"border border-outline-variant bg-surface-lowest p-2 text-[11px]",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("span",{className:"font-mono uppercase tracking-[0.1em] text-on-surface",children:T.actionVerb}),i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant",children:T.actedAt})]}),i.jsxs("div",{className:"mt-1 text-on-surface",children:["qitem: ",i.jsx("span",{className:"font-mono",children:T.qitemId??"—"})]}),i.jsxs("div",{className:"text-on-surface",children:["actor: ",i.jsx("span",{className:"font-mono",children:T.actorSession})]}),T.reason?i.jsxs("div",{className:"text-on-surface",children:["reason: ",i.jsx("span",{className:"italic",children:T.reason})]}):null,T.annotation?i.jsxs("div",{className:"text-on-surface",children:["annotation: ",i.jsx("span",{className:"italic",children:T.annotation})]}):null]},T.actionId))}),i.jsxs("footer",{"data-testid":"mc-audit-pagination",className:"flex items-center justify-between font-mono text-[10px] uppercase tracking-[0.12em] text-on-surface-variant",children:[i.jsx("button",{type:"button","data-testid":"mc-audit-prev-page",onClick:w,disabled:f.length===0,className:"border border-outline-variant px-2 py-0.5 disabled:opacity-50",children:"← prev"}),i.jsxs("span",{children:["rows: ",((C=y.data)==null?void 0:C.rows.length)??0]}),i.jsx("button",{type:"button","data-testid":"mc-audit-next-page",onClick:_,disabled:!((R=y.data)!=null&&R.hasMore),className:"border border-outline-variant px-2 py-0.5 disabled:opacity-50",children:"next →"})]})]})}async function gSe(){const e=await fetch("/api/health-summary/version");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}function xSe(){return Re({queryKey:["health-summary","version"],queryFn:gSe,staleTime:1/0})}const g8={active:"bg-success",running:"bg-success",stopped:"bg-outline-variant",warning:"bg-warning",error:"bg-tertiary",info:"bg-secondary"},vSe={active:"border-success text-success",running:"border-success text-success",stopped:"border-outline text-on-surface-variant",warning:"border-warning text-warning",error:"border-tertiary text-tertiary",info:"border-secondary text-secondary"};function Bo({status:e,label:t,variant:n="dot",className:s,labelClassName:r,testId:a}){const o=t??e;return n==="pill"?i.jsxs("span",{"data-testid":a,className:le("inline-flex items-center gap-1 px-1.5 py-0.5 border font-mono text-[9px] uppercase tracking-wide",vSe[e],s),role:"status","aria-label":o,children:[i.jsx("span",{className:le("w-1.5 h-1.5 rounded-full",g8[e]),"aria-hidden":"true"}),i.jsx("span",{className:r,children:o})]}):i.jsxs("span",{"data-testid":a,className:le("inline-flex items-center gap-1.5",s),role:"status","aria-label":o,children:[i.jsx("span",{className:le("w-2 h-2 rounded-full",g8[e]),"aria-hidden":"true"}),t?i.jsx("span",{className:le("font-mono text-[9px] uppercase tracking-wide text-on-surface-variant",r),children:t}):null]})}const cW={up:"running",partial:"warning",down:"stopped",blocked:"error",unknown:"info",untracked:"info"},uW={up:"border-success text-success",partial:"border-warning text-warning",down:"border-stone-400 text-stone-500",blocked:"border-tertiary text-tertiary",unknown:"border-stone-300 text-stone-400",untracked:"border-stone-300 text-stone-500"},dW={up:"All managed seats are running.",partial:"Some seats running, some stopped / detached / attention-required.",down:"No seats running — recoverable from snapshot.",blocked:"Restore cannot proceed without operator action (missing token / auth / spec).",unknown:"Daemon/API cannot confidently compute the state.",untracked:"Kernel boot was skipped; readiness is not tracked."};function Yk({rigId:e,rigName:t,isKernel:n=!1,status:s,seatsRunning:r,seatsTotal:a,recoverable:o,src:c,primaryLabel:d,onPrimary:h,primaryDisabled:p,testId:f}){const g=cW[s],x=p??s==="up";return i.jsxs("div",{"data-testid":f??`rig-status-card-${e}`,"data-status":s,className:"bg-surface-lowest border border-stone-900 dark:border-outline hard-shadow relative",children:[i.jsxs("div",{className:"bg-stone-900 text-white px-4 py-1.5 font-mono text-[10px] flex justify-between items-center",children:[i.jsx("span",{children:n?"KERNEL RIG":`RIG: ${t.toUpperCase()}`}),n?i.jsx(xJ,{className:"h-3 w-3"}):i.jsx(yF,{className:"h-3 w-3"})]}),i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsxs("div",{className:"flex justify-between items-end border-b border-stone-100 dark:border-outline-variant pb-2",children:[i.jsx("span",{className:"font-headline font-bold text-lg tracking-tight uppercase",children:t}),i.jsxs("span",{"data-testid":`rig-status-badge-${e}`,className:le("px-2 py-0.5 border font-mono text-[9px] uppercase tracking-wide inline-flex items-center gap-1.5",uW[s]),children:[i.jsx(Bo,{status:g}),s==="untracked"?"boot not tracked":s]})]}),i.jsx("p",{className:"font-mono text-[9px] leading-relaxed text-secondary",children:dW[s]}),i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex justify-between font-mono text-[9px] text-secondary",children:[i.jsx("span",{children:"SEATS RUNNING"}),i.jsxs("span",{"data-testid":`seats-${e}`,children:[r,"/",a]})]}),i.jsxs("div",{className:"flex justify-between font-mono text-[9px] text-secondary",children:[i.jsx("span",{children:"RECOVERABLE"}),i.jsx("span",{children:o?"yes":"no — needs operator"})]})]}),i.jsx("div",{className:"pt-1",children:i.jsx(Ne,{variant:s==="blocked"?"destructive":"default",size:"sm",disabled:x,onClick:h,"data-testid":`rig-primary-action-${e}`,className:"w-full font-mono text-[10px] tracking-widest",children:s==="up"?"RUNNING":d})}),i.jsxs("p",{"data-testid":`rig-status-src-${e}`,className:"font-mono text-[8px] leading-snug text-stone-400 border-t border-stone-100 dark:border-outline-variant pt-2",children:["src: ",c.join(" · ")]})]})]})}async function ySe(e,t){const n=await fetch(`/api/rigs/${encodeURIComponent(e)}/launch-plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{freshLogicalIds:t}:{})});if(!n.ok){const s=await n.json().catch(()=>({}));throw new Error(s.error??`Launch plan failed (HTTP ${n.status})`)}return n.json()}function bSe(e){return Xt({mutationFn:t=>ySe(e,t)})}const _Se={"resume-original":"running","fresh-primed":"info","awaiting-decision":"warning","leave-attached":"info"},wSe={present:"text-success",missing:"text-tertiary font-bold",stale:"text-warning font-bold",unverified:"text-warning"};function x8({policy:e,label:t,selected:n,warn:s,sub:r,onSelect:a}){return i.jsxs("button",{type:"button","data-testid":`launch-policy-${e}`,"aria-pressed":n,onClick:a,className:le("flex-1 border px-3 py-2 text-left",n?"border-stone-900 bg-stone-900 text-white":"border-outline bg-white text-stone-700",s&&!n&&"border-tertiary/50"),children:[i.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-wide",children:[n?i.jsx(GZ,{className:"h-3 w-3"}):null,t,e==="restore-original"?i.jsx("span",{className:le("ml-auto text-[8px]",n?"text-white/70":"text-secondary"),children:"default"}):null]}),i.jsx("div",{className:le("mt-1 font-mono text-[8px] leading-snug",n?"text-white/75":s?"text-tertiary":"text-secondary"),children:r})]})}function hW({rigId:e,rigName:t,open:n,onOpenChange:s}){var b;const r=bSe(e),a=c0e(e),[o,c]=E.useState("restore-original"),d=((b=r.data)==null?void 0:b.nodes)??[],h=d.map(_=>_.logicalId);E.useEffect(()=>{n&&(c("restore-original"),a.reset(),r.mutate(void 0))},[n,e]);function p(_){_!==o&&(c(_),r.mutate(_==="fresh"?d.map(w=>w.logicalId):void 0))}const f=d.filter(_=>_.intendedAction==="awaiting-decision"),g=o==="restore-original"&&f.length>0,x=!g&&d.length>0&&!r.isPending&&!a.isPending;function y(){a.mutate(o==="fresh"?h:void 0,{onSuccess:()=>s(!1)})}return i.jsx(Gy,{open:n,onOpenChange:s,children:i.jsxs(Bp,{hideCloseButton:!0,className:"max-w-3xl border-stone-900","data-testid":"launch-recovery-modal",children:[i.jsxs(Ky,{children:[i.jsxs(qp,{className:"font-headline uppercase tracking-tight flex items-center gap-2",children:[i.jsx(xF,{className:"h-4 w-4"}),"Restore ",t]}),i.jsx(Fp,{className:"font-mono text-[10px] text-secondary",children:"Plan before action — this is a READ-ONLY preview. No changes made yet."})]}),i.jsxs("div",{className:"flex gap-2","data-testid":"launch-policy-picker",children:[i.jsx(x8,{policy:"restore-original",label:"Restore original",selected:o==="restore-original",sub:"Resume original sessions only. If a seat can't resume, fail loudly — never fresh-prime silently.",onSelect:()=>p("restore-original")}),i.jsx(x8,{policy:"fresh",label:"Fresh",selected:o==="fresh",warn:!0,sub:"⚠ Identity/context-changing — creates NEW sessions for ALL seats. Previous conversation context is NOT restored.",onSelect:()=>p("fresh")})]}),g?i.jsxs("div",{"data-testid":"launch-blocked-banner",className:"border border-tertiary bg-tertiary/10 px-3 py-2 flex items-start gap-2",children:[i.jsx(EE,{className:"h-3.5 w-3.5 text-tertiary shrink-0"}),i.jsxs("div",{className:"font-mono text-[9px] leading-relaxed text-tertiary",children:[i.jsx("span",{className:"font-bold uppercase",children:"restore-original blocked"})," — ",f.length," seat(s) need a decision. restore-original will NOT silently fresh-prime. Resolve each seat below, or switch to"," ",i.jsx("span",{className:"underline",children:"fresh"})," (identity-changing) for the whole rig."]})]}):null,r.isPending?i.jsx("p",{"data-testid":"launch-plan-loading",className:"font-mono text-[10px] text-secondary py-4",children:"Fetching read-only plan…"}):r.isError?i.jsxs("p",{"data-testid":"launch-plan-error",className:"font-mono text-[10px] text-tertiary py-4",children:["Could not fetch plan: ",r.error.message]}):i.jsxs(i.Fragment,{children:[i.jsxs(Fy,{"data-testid":"launch-plan-table",children:[i.jsx(zy,{children:i.jsxs(nc,{children:[i.jsx(zr,{className:"font-mono text-[9px]",children:"Seat"}),i.jsx(zr,{className:"font-mono text-[9px]",children:"Token"}),i.jsx(zr,{className:"font-mono text-[9px]",children:"Plan"}),i.jsx(zr,{className:"font-mono text-[9px]",children:"Prompt / note"})]})}),i.jsx(Hy,{children:d.map(_=>i.jsxs(nc,{"data-testid":`plan-row-${_.logicalId}`,children:[i.jsx(Hr,{className:"py-2 font-mono text-[10px] font-medium",children:_.logicalId}),i.jsx(Hr,{className:"py-2 font-mono text-[9px]","data-testid":`plan-token-${_.logicalId}`,children:i.jsx("span",{className:le(wSe[_.tokenState]),children:_.tokenState})}),i.jsx(Hr,{className:"py-2","data-testid":`plan-verdict-${_.logicalId}`,children:i.jsx(Bo,{status:_Se[_.intendedAction],variant:"pill",label:_.intendedAction})}),i.jsx(Hr,{className:"py-2 font-mono text-[9px] text-secondary",children:_.runtimePrompt??_.reason??"—"})]},_.logicalId))})]}),a.isError?i.jsx("p",{"data-testid":"launch-execute-error",className:"font-mono text-[9px] text-tertiary",children:a.error.message}):null]}),i.jsxs(Yy,{className:"items-center gap-2",children:[i.jsx("p",{className:"mr-auto font-mono text-[8px] text-stone-400 leading-snug",children:"src: composed from /api/rigs/:id/launch-plan (read-only forecast · mutated:false)"}),i.jsx(Ne,{variant:"secondary",size:"sm",className:"font-mono text-[10px]",onClick:()=>s(!1),"data-testid":"launch-cancel",children:"Cancel"}),i.jsx(Ne,{variant:o==="fresh"?"destructive":"default",size:"sm",disabled:!x,onClick:y,"data-testid":"launch-execute",className:"font-mono text-[10px] tracking-widest",children:g?"Resolve blockers to restore":o==="fresh"?"Fresh-prime all seats ▸":"Restore original ▸"})]})]})})}function SSe(e){return!!e&&"error"in e}async function jSe(){const e=await fetch("/api/kernel/status");if(e.status===503)return e.json();if(!e.ok)throw new Error(`HTTP ${e.status}`);return e.json()}function NSe(){return Re({queryKey:["kernel","status"],queryFn:jSe,refetchInterval:1e4})}function kSe(e){switch(e){case"skipped":return"untracked";case"ready":return"up";case"booting":case"partial_ready":case"degraded":return"partial";case"auth_blocked":case"spec_missing":case"bootstrap_failed":return"blocked";default:return"unknown"}}function CSe(){const{data:e,isLoading:t}=NSe(),{data:n}=Wr(),[s,r]=E.useState(!1),a=n==null?void 0:n.find(f=>f.name==="kernel");if(t||!e)return i.jsx(Yk,{rigId:"kernel",rigName:"kernel",isKernel:!0,status:"unknown",seatsRunning:0,seatsTotal:0,recoverable:!1,src:["kernel-status: loading…"],primaryLabel:"Restore kernel ▸",primaryDisabled:!0,testId:"kernel-status-card"});if(SSe(e))return i.jsx(Yk,{rigId:(a==null?void 0:a.id)??"kernel",rigName:"kernel",isKernel:!0,status:"unknown",seatsRunning:0,seatsTotal:0,recoverable:!1,src:[`kernel-status: unavailable (${e.error})`],primaryLabel:"Restore kernel ▸",primaryDisabled:!0,testId:"kernel-status-card"});const o=Array.isArray(e.agents)?kSe(e.kernel_state):"unknown",c=Array.isArray(e.agents)?e.agents:[],d=c.filter(f=>f.startup_status==="ready").length,h=[`kernel-status.kernel_state=${e.kernel_state??"unknown"}`,...e.variant?[`variant=${e.variant}`]:[],`agents ${d}/${c.length} ready`,...e.detail?[e.detail]:[]],p=!a||o==="up";return i.jsxs(i.Fragment,{children:[i.jsx(Yk,{rigId:(a==null?void 0:a.id)??"kernel",rigName:"kernel",isKernel:!0,status:o,seatsRunning:d,seatsTotal:c.length,recoverable:o==="down"||o==="partial",src:h,primaryLabel:"Restore kernel ▸",primaryDisabled:p,onPrimary:()=>r(!0),testId:"kernel-status-card"}),a?i.jsx(hW,{rigId:a.id,rigName:"kernel",open:s,onOpenChange:r}):null]})}function v8(e,t){var s;const n=(s=e==null?void 0:e.settings)==null?void 0:s[t];return typeof(n==null?void 0:n.value)=="string"?n.value:""}function ESe(e){return e.transport==="ssh"?e.target??"—":e.url??"—"}function RSe(){var R,T,A;const{data:e}=Nr(),{data:t,error:n}=jr(),s=Ov(),r=oee(),[a,o]=E.useState(!1),[c,d]=E.useState(""),[h,p]=E.useState(""),[f,g]=E.useState(null),x=lee(f),y=v8(e,"host.name")||(t==null?void 0:t.ownName)||"localhost",b=v8(e,"host.selected")||(t==null?void 0:t.selected)||"local",_=(t==null?void 0:t.hosts)??[],w=(R=x.data)==null?void 0:R.status,k=((T=x.data)==null?void 0:T.code)??((A=r.data)==null?void 0:A.code);async function N(){const I=h.trim();if(I)try{const M=await r.mutateAsync({url:I});g(M.pairId)}catch{}}function C(){g(null),p(""),r.reset()}return i.jsxs("section",{"data-testid":"dashboard-host-config",className:"df-hosts",children:[i.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-secondary mb-2",children:"Hosts"}),i.jsx("div",{className:"df-hosts-own","data-testid":"host-config-own",children:a?i.jsxs("form",{className:"df-hosts-rename",onSubmit:I=>{I.preventDefault();const M=c.trim();M&&s.mutateAsync({key:"host.name",value:M}),o(!1)},children:[i.jsx("input",{"data-testid":"host-rename-input",className:"df-hosts-input",value:c,onChange:I=>d(I.target.value),autoFocus:!0}),i.jsx("button",{type:"submit",className:"df-hosts-btn",children:"Save"}),i.jsx("button",{type:"button",className:"df-hosts-btn",onClick:()=>o(!1),children:"Cancel"})]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{"data-testid":"host-own-name",className:"df-hosts-name",children:y}),i.jsx("span",{className:"df-hosts-tag",children:"this host"}),b==="local"?i.jsx("span",{"data-testid":"host-selected-marker-local",className:"df-hosts-selected",children:"selected"}):i.jsx("button",{type:"button",className:"df-hosts-btn","data-testid":"host-select-local",onClick:()=>void s.mutateAsync({key:"host.selected",value:"local"}),children:"Select"}),i.jsx("button",{type:"button",className:"df-hosts-btn","data-testid":"host-rename-button",onClick:()=>{d(y),o(!0)},children:"Rename"})]})}),n?i.jsxs("div",{className:"df-hosts-empty",children:["host registry unreadable: ",String(n.message)]}):_.length===0?i.jsx("div",{"data-testid":"host-config-empty",className:"df-hosts-empty",children:"No remote hosts yet. Paste an address below and pair — one approval on the target, done."}):i.jsx("ul",{className:"df-hosts-list","data-testid":"host-config-rows",children:_.map(I=>i.jsxs("li",{className:"df-hosts-row",children:[i.jsx("span",{className:"df-hosts-marker",children:I.selected?"*":""}),i.jsx("span",{className:"df-hosts-id",children:I.id}),i.jsx("span",{className:"df-hosts-addr",children:ESe(I)}),i.jsx("span",{className:"df-hosts-transport",children:I.transport}),i.jsx("span",{className:`df-hosts-status df-hosts-status-${I.status}`,children:I.status}),I.selected?i.jsx("span",{className:"df-hosts-selected","data-testid":`host-selected-marker-${I.id}`,children:"selected"}):i.jsx("button",{type:"button",className:"df-hosts-btn","data-testid":`host-select-${I.id}`,onClick:()=>void s.mutateAsync({key:"host.selected",value:I.id}),children:"Select"})]},I.id))}),b!=="local"?i.jsxs("div",{className:"df-hosts-banner","data-testid":"host-selection-banner",children:["Selected host: ",b," — flagless CLI commands run against it (rig host select local returns)."]}):null,f===null?i.jsxs("form",{className:"df-hosts-add",onSubmit:I=>{I.preventDefault(),N()},children:[i.jsx("input",{"data-testid":"host-pair-input",className:"df-hosts-input",placeholder:"http://host:7433 — pair a new host",value:h,onChange:I=>p(I.target.value)}),i.jsx("button",{type:"submit",className:"df-hosts-btn","data-testid":"host-pair-button",disabled:r.isPending,children:"Pair"}),r.error?i.jsx("span",{className:"df-hosts-error","data-testid":"host-pair-error",children:r.error.message}):null]}):i.jsx("div",{className:"df-hosts-pairing","data-testid":"host-pairing",children:w==="approved"?i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"Paired."}),i.jsx("button",{type:"button",className:"df-hosts-btn",onClick:C,children:"Done"})]}):w==="denied"||w==="expired"?i.jsxs(i.Fragment,{children:[i.jsxs("span",{"data-testid":"host-pair-outcome",children:["Pairing ",w," — nothing was persisted."]}),i.jsx("button",{type:"button",className:"df-hosts-btn",onClick:C,children:"Dismiss"})]}):i.jsxs(i.Fragment,{children:[i.jsxs("span",{"data-testid":"host-pair-code",children:["Code ",k??"…"," — waiting for approval on the target."]}),i.jsx("button",{type:"button",className:"df-hosts-btn",onClick:C,children:"Cancel"})]})})]})}class ud extends E.Component{constructor(){super(...arguments);yn(this,"state",{error:null})}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,s){var r,a;console.error(`[ErrorBoundary${this.props.label?`: ${this.props.label}`:""}]`,n,s.componentStack),(a=(r=this.props).onError)==null||a.call(r,n,s)}render(){return this.state.error?this.props.fallback!==void 0?this.props.fallback:i.jsxs("div",{"data-testid":"error-boundary-fallback",role:"alert",className:"border border-outline-variant bg-surface-low px-3 py-6 text-center font-mono text-xs text-on-surface-variant",children:[this.props.label?`${this.props.label} failed to render.`:"This view failed to render."," ","The rest of the page is still usable."]}):this.props.children}}function ASe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("rect",{x:"22",y:"6",width:"16",height:"8"}),i.jsx("rect",{x:"6",y:"28",width:"14",height:"8"}),i.jsx("rect",{x:"40",y:"28",width:"14",height:"8"}),i.jsx("rect",{x:"6",y:"48",width:"14",height:"6"}),i.jsx("rect",{x:"22",y:"48",width:"14",height:"6"}),i.jsx("rect",{x:"40",y:"48",width:"14",height:"6"}),i.jsx("line",{x1:"30",y1:"14",x2:"13",y2:"28"}),i.jsx("line",{x1:"30",y1:"14",x2:"47",y2:"28"}),i.jsx("line",{x1:"13",y1:"36",x2:"13",y2:"48"}),i.jsx("line",{x1:"47",y1:"36",x2:"47",y2:"48"}),i.jsx("line",{x1:"13",y1:"44",x2:"29",y2:"48"}),i.jsx("line",{x1:"47",y1:"44",x2:"29",y2:"48"})]})}function TSe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("path",{d:"M2 26 Q 18 18 30 22 T 58 18"}),i.jsx("path",{d:"M2 36 Q 18 28 30 32 T 58 28",strokeDasharray:"2 2"}),i.jsx("path",{d:"M2 46 Q 18 40 30 42 T 58 38",strokeDasharray:"2 2"}),i.jsx("circle",{cx:"30",cy:"22",r:"2",fill:"currentColor"}),i.jsx("line",{x1:"30",y1:"22",x2:"30",y2:"10"})]})}function ISe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("circle",{cx:"30",cy:"30",r:"12"}),i.jsx("circle",{cx:"30",cy:"30",r:"20",strokeDasharray:"2 3"}),i.jsx("circle",{cx:"30",cy:"30",r:"27",strokeDasharray:"2 4"}),i.jsx("line",{x1:"30",y1:"0",x2:"30",y2:"60",strokeDasharray:"2 3"}),i.jsx("line",{x1:"0",y1:"30",x2:"60",y2:"30",strokeDasharray:"2 3"}),i.jsx("circle",{className:"df-amf",cx:"30",cy:"30",r:"4"})]})}function MSe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("circle",{cx:"30",cy:"30",r:"26"}),i.jsx("ellipse",{cx:"30",cy:"30",rx:"26",ry:"9"}),i.jsx("ellipse",{cx:"30",cy:"30",rx:"9",ry:"26"}),i.jsx("line",{x1:"0",y1:"30",x2:"60",y2:"30",strokeDasharray:"2 3"}),i.jsx("line",{x1:"30",y1:"0",x2:"30",y2:"60",strokeDasharray:"2 3"}),i.jsx("circle",{cx:"30",cy:"30",r:"3",fill:"currentColor"})]})}function LSe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("path",{d:"M10 18 V10 H18"}),i.jsx("path",{d:"M42 10 H50 V18"}),i.jsx("path",{d:"M10 42 V50 H18"}),i.jsx("path",{d:"M42 50 H50 V42"}),i.jsx("circle",{cx:"27",cy:"27",r:"11"}),i.jsx("line",{x1:"22",y1:"27",x2:"32",y2:"27"}),i.jsx("line",{x1:"27",y1:"22",x2:"27",y2:"32"}),i.jsx("line",{x1:"35",y1:"35",x2:"44",y2:"44"})]})}function OSe(){return i.jsxs("svg",{viewBox:"0 0 60 60",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("circle",{cx:"30",cy:"30",r:"18"}),i.jsx("circle",{cx:"30",cy:"30",r:"6"}),i.jsx("circle",{cx:"30",cy:"30",r:"2",fill:"currentColor"}),i.jsx("line",{x1:"36",y1:"30",x2:"53",y2:"30"}),i.jsx("line",{x1:"24",y1:"30",x2:"7",y2:"30"}),i.jsx("line",{x1:"30",y1:"36",x2:"30",y2:"53"}),i.jsx("line",{x1:"30",y1:"24",x2:"30",y2:"7"}),i.jsx("line",{x1:"34.2",y1:"34.2",x2:"46.3",y2:"46.3"}),i.jsx("line",{x1:"25.8",y1:"25.8",x2:"13.7",y2:"13.7"}),i.jsx("line",{x1:"34.2",y1:"25.8",x2:"46.3",y2:"13.7"}),i.jsx("line",{x1:"25.8",y1:"34.2",x2:"13.7",y2:"46.3"})]})}function PSe(){return i.jsxs("svg",{viewBox:"0 0 72 72",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[i.jsx("circle",{cx:"36",cy:"36",r:"26"}),i.jsx("ellipse",{cx:"36",cy:"36",rx:"9",ry:"26"}),i.jsx("ellipse",{cx:"36",cy:"36",rx:"19",ry:"26"}),i.jsx("line",{x1:"10",y1:"36",x2:"62",y2:"36"}),i.jsx("line",{x1:"14",y1:"22",x2:"58",y2:"22"}),i.jsx("line",{x1:"14",y1:"50",x2:"58",y2:"50"}),i.jsx("line",{x1:"36",y1:"2",x2:"36",y2:"70",strokeDasharray:"2 3"}),i.jsx("line",{x1:"2",y1:"36",x2:"70",y2:"36",strokeDasharray:"2 3"})]})}function DSe({kind:e}){return e==="cross"?i.jsx("svg",{viewBox:"0 0 12 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:i.jsx("path",{d:"M2 2l8 8M10 2l-8 8"})}):e==="square"?i.jsx("svg",{viewBox:"0 0 12 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:i.jsx("rect",{className:"df-cap-fill",x:"3",y:"3",width:"6",height:"6"})}):i.jsx("svg",{viewBox:"0 0 12 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:i.jsx("circle",{cx:"6",cy:"6",r:"3"})})}const $Se=[{num:"01",to:"/topology",label:"TOPOLOGY",caption:"VIEW RIG GRAPH",glyph:i.jsx(ASe,{}),captionGlyph:"cross"},{num:"02",to:"/project",label:"PROJECT",caption:"BROWSE PROJECTS",glyph:i.jsx(TSe,{}),captionGlyph:"square"},{num:"03",to:"/for-you",label:"FOR YOU",caption:"PRIORITIZED FOR YOU",glyph:i.jsx(ISe,{}),captionGlyph:"square",amber:!0},{num:"04",to:"/specs",label:"LIBRARY",caption:"SPECS & ARTIFACTS",glyph:i.jsx(MSe,{}),captionGlyph:"cross"},{num:"05",to:"/search",label:"SEARCH & AUDIT",caption:"FIND & VERIFY",glyph:i.jsx(LSe,{}),captionGlyph:"circle"},{num:"06",to:"/settings",label:"SETTINGS",caption:"CONFIGURE · STATUS",glyph:i.jsx(OSe,{}),captionGlyph:"circle"}];function y8(e){return String(Math.max(0,e)).padStart(2,"0")}function BSe(e,t){var s,r;const n=(r=(s=e==null?void 0:e.settings)==null?void 0:s[t])==null?void 0:r.value;return typeof n=="string"?n:""}function qSe(){const{data:e}=Wr(),{data:t,isError:n}=lp(),{data:s}=Nr(),{data:r}=xSe(),a=(e==null?void 0:e.length)??0,o=(t==null?void 0:t.reduce((y,b)=>y+b.nodeCount,0))??0,d=(typeof window>"u"?"localhost":window.location.hostname||"localhost").toUpperCase(),h=!n&&t!==void 0,p=BSe(s,"agents.operator_session"),f=fp(p),g=f.kind==="canonical"?f.member.toUpperCase():"OPERATOR",x=((r==null?void 0:r.version)??"").toUpperCase()||"—";return i.jsxs("div",{"data-testid":"dashboard-surface",className:"df-root",children:[i.jsxs("div",{className:"df-main",children:[i.jsxs("div",{className:"df-head",children:[i.jsxs("div",{className:"df-eyebrow",children:[i.jsxs("span",{className:"df-eyebrow-l",children:[i.jsx("span",{className:"df-gd","aria-hidden":"true"}),"OPERATOR"]}),i.jsx("span",{className:"df-eyebrow-r",children:"DASHBOARD · LAUNCHER · CONFIGSTORE-BACKED"})]}),i.jsx("h1",{"data-testid":"dashboard-greeting",className:"df-h1",children:"Welcome back, operator."}),i.jsxs("div",{className:"df-sub",children:["STATION ",d," IS ",i.jsxs("b",{children:["[ ",h?"ONLINE":"CONNECTING"," ]"]})]}),i.jsx(FSe,{station:d,operatorId:g,rigs:a,agents:o,version:x}),i.jsx("div",{className:"df-reg","aria-hidden":"true"})]}),i.jsxs("section",{"data-testid":"dashboard-kernel-section",className:"mb-6 max-w-md",children:[i.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-secondary mb-2",children:"Host / kernel"}),i.jsx(ud,{label:"Kernel status",children:i.jsx(CSe,{})})]}),i.jsx(ud,{label:"Hosts",children:i.jsx(RSe,{})}),i.jsx("div",{className:"df-grid","data-testid":"dashboard-launcher-grid",children:$Se.map(y=>i.jsx(zSe,{dest:y},y.num))})]}),i.jsx(HSe,{})]})}function FSe({station:e,operatorId:t,rigs:n,agents:s,version:r}){const a=[{k:"STATION ID",v:e},{k:"OPERATOR ID",v:t},{k:"RIGS",v:y8(n)},{k:"AGENTS",v:y8(s)},{k:"VERSION",v:r}];return i.jsxs("section",{"data-testid":"dashboard-field-environment",className:"df-fieldenv","aria-label":"Field environment",children:[i.jsxs("div",{className:"df-feh",children:[i.jsx("span",{children:"FIELD ENVIRONMENT"}),i.jsx("span",{className:"df-feh-mark","aria-hidden":"true"})]}),i.jsxs("div",{className:"df-fe-body",children:[i.jsx("div",{className:"df-fe-list",children:a.map(o=>i.jsxs("div",{className:"df-fe-row",children:[i.jsx("span",{className:"df-k",children:o.k}),i.jsx("span",{className:"df-dots","aria-hidden":"true"}),i.jsx("span",{className:"df-v",children:o.v})]},o.k))}),i.jsx("div",{className:"df-fe-globe","aria-hidden":"true",children:i.jsx(PSe,{})})]})]})}function zSe({dest:e}){return i.jsxs("div",{className:"df-cell",children:[i.jsxs(Ke,{to:e.to,"data-testid":`dashboard-card-${e.num}`,"aria-label":e.label,className:"df-card",children:[i.jsx("span",{className:"df-plus","aria-hidden":"true"}),i.jsxs("span",{className:"df-idx",children:[e.num," ",i.jsx("i",{className:"df-idx-sq","aria-hidden":"true"})]}),i.jsx("span",{className:"df-glyph","aria-hidden":"true",children:e.glyph}),i.jsx("span",{className:"df-clabel",children:e.label}),i.jsx("span",{className:"df-half","aria-hidden":"true"}),i.jsxs("span",{className:"df-crop","aria-hidden":"true",children:[i.jsx("i",{className:"df-crop-tl"}),i.jsx("i",{className:"df-crop-br"})]})]}),i.jsxs("div",{className:`df-cap${e.amber?" df-cap--amber":""}`,children:[i.jsx("span",{className:"df-cap-glyph","aria-hidden":"true",children:i.jsx(DSe,{kind:e.captionGlyph})}),i.jsx("span",{className:"df-lead","aria-hidden":"true"}),e.caption]})]})}function HSe(){const e=[{left:6,top:14,w:4,h:1},{left:16,top:9,w:1,h:1},{left:24,top:16,w:3,h:1},{left:34,top:6,w:1,h:1},{left:30,top:13,w:1,h:1},{left:46,top:11,w:5,h:1},{left:58,top:7,w:1,h:1},{left:66,top:15,w:2,h:1},{left:78,top:10,w:1,h:1},{left:90,top:13,w:4,h:1}];return i.jsxs("div",{className:"df-foot","data-testid":"dashboard-footer",children:[i.jsxs("div",{className:"df-foot-fl",children:[i.jsx("span",{className:"df-foot-sq","aria-hidden":"true"}),"[ LOG ] .0001 · A SOLO BUILD, DELIBERATE, YEAR OVER YEAR"]}),i.jsx("span",{className:"df-plus2","aria-hidden":"true"}),i.jsx("span",{className:"df-foot-dots","aria-hidden":"true"}),i.jsx("div",{className:"df-dissolve","aria-hidden":"true",children:i.jsx("span",{className:"df-dissolve-blk"})}),i.jsx("div",{className:"df-arts","aria-hidden":"true",children:e.map((t,n)=>i.jsx("i",{style:{left:`${t.left}px`,top:`${t.top}px`,width:`${t.w}px`,height:`${t.h}px`}},n))}),i.jsxs("div",{className:"df-sqs","aria-hidden":"true",children:[i.jsx("span",{className:"df-sq-o"}),i.jsx("span",{className:"df-sq-b"})]}),i.jsx("span",{className:"df-plus2","aria-hidden":"true"})]})}async function USe(e){const t=new URLSearchParams({attention:"1"});e!==void 0&&t.set("limit",String(e));const n=await fetch(`/api/queue/list?${t.toString()}`);if(!n.ok)throw new Error(`HTTP ${n.status}`);return await n.json()}async function VSe(e){const t=await fetch("/api/queue/attention-aggregate");if(!t.ok)throw new Error(`HTTP ${t.status}`);const n=await t.json(),s=Array.isArray(n.items)?n.items:[];return{items:e!==void 0?s.slice(0,e):s,hosts:Array.isArray(n.hosts)?n.hosts:[]}}const fW=50,di=new Map,pW=new Set;function WSe(e){pW.add(e)}function mW(e){for(const t of pW)t(e)}function GSe(e,t){const n=t??di.get(e);if(n){if(di.delete(e),di.size>=fW){const s=di.keys().next().value;s!==void 0&&(di.delete(s),mW(s))}di.set(e,n)}}function b8(e,t,n){const s=new Set;for(const d of e)(!d.hostId||d.hostId==="local")&&(s.add(d.qitemId),di.has(d.qitemId)&&di.set(d.qitemId,d));const r=[...di.values()].filter(d=>!s.has(d.qitemId)&&(n||!d.hostId||d.hostId==="local"));if(!r.length)return t!==void 0?e.slice(0,t):e;if(t===void 0)return[...e,...r];const a=e.slice(0,Math.max(0,t)),o=Math.max(0,t-a.length),c=Math.max(0,r.length-o);for(let d=0;d<c;d++){const h=r[d].qitemId;di.delete(h),mW(h)}return o>0?[...a,...r.slice(c)]:a}function KSe(e=50,t=!1){return Re({queryKey:["attention-items",e,t],queryFn:t?async()=>{const n=await VSe(e);return{items:b8(n.items,e,!0),hosts:n.hosts}}:async()=>({items:b8(await USe(e),e,!1),hosts:[]}),staleTime:15e3,refetchOnWindowFocus:"always"})}function J2(e){return typeof e=="string"&&e.length>0?e:void 0}function On(e,...t){for(const n of t){const s=J2(e[n]);if(s)return s}}function YSe(e){if(e)return e.length<=28?e:`${e.slice(0,18)}...${e.slice(-6)}`}function QSe(e){switch(e){case"queue.created":case"queue.item.created":return"Queue item created";case"queue.updated":case"queue.item.updated":return"Queue item updated";case"queue.handed_off":return"Queue item handed off";case"queue.claimed":return"Queue item claimed";case"queue.unclaimed":return"Queue item unclaimed";case"qitem.fallback_routed":return"Queue item fallback routed";case"qitem.closure_overdue":return"Queue item closure overdue";case"inbox.absorbed":return"Inbox item absorbed";case"inbox.denied":return"Inbox item denied";default:return e}}function XSe(e){return e==="queue.created"||e==="queue.updated"||e==="queue.claimed"||e==="queue.unclaimed"||e==="queue.handed_off"||e==="queue.item.created"||e==="queue.item.updated"||e==="qitem.fallback_routed"||e==="qitem.closure_overdue"||e==="inbox.absorbed"||e==="inbox.denied"}function ZSe(e,t,n){return e.startsWith("queue.")&&e.endsWith(".closed")?"shipped":e==="qitem.closure_overdue"||e==="inbox.denied"?"action-required":n==="human-gate"?"approval":t==="pending-approval"?"action-required":t==="closeout-pending-ratify"?"approval":t==="done"||t==="closed"||t==="completed"||t==="shipped"?"shipped":"progress"}function JSe(e){const t=On(e,"sourceSession","source_session","fromSession"),n=On(e,"destinationSession","destination_session","toSession","destination"),s=t&&n?`${t} -> ${n}`:t?`Source: ${t}`:n?`Destination: ${n}`:void 0,r=[On(e,"priority")?`priority=${On(e,"priority")}`:void 0,On(e,"tier")?`tier=${On(e,"tier")}`:void 0,On(e,"state","toState")?`state=${On(e,"state","toState")}`:void 0,On(e,"closureReason")?`closure=${On(e,"closureReason")}`:void 0].filter(a=>!!a);return[s,r.length>0?r.join(" / "):void 0].filter(a=>!!a).join(`
590
590
  `)||void 0}function gW(e){return VE(e??"")}function eje(e){const t=e.payload??{},n=On(t,"actor_session","actorSession","source_session","sourceSession","fromSession","sender"),s=On(t,"rig_id","rigId"),r=On(t,"summary","body","title"),a={id:`${e.type}-${e.seq}`,title:r??e.type,body:J2(t.body),authorSession:n,rigId:s,receivedAt:e.receivedAt,createdAt:e.createdAt,source:e};if(e.type.startsWith("queue.")&&e.type.endsWith(".closed"))return{...a,kind:"shipped"};if(XSe(e.type)){const o=On(t,"qitemId","qitem_id"),c=On(t,"destinationSession","destination_session","toSession","destination"),d=On(t,"state","toState"),h=On(t,"tier"),p=ZSe(e.type,d,h),f=p==="approval"?"approval":gW(c)?"action-required":p,g=On(t,"summary","title"),x=f==="shipped"&&e.type==="queue.updated"?"Queue item shipped":QSe(e.type),y=g??[x,YSe(o)].filter(b=>!!b).join(": ");return{...a,title:y,body:J2(t.body)??JSe(t),kind:f}}return e.type.startsWith("workflow.")?{...a,kind:"progress"}:e.type.startsWith("stream.")||e.type.startsWith("watchdog.")?{...a,kind:"observation"}:e.type.startsWith("lifecycle.")||e.type.startsWith("git.")?{...a,kind:"shipped"}:{...a,kind:"observation"}}function tje(e){return e.map(eje).filter(n=>n!==null).sort((n,s)=>s.receivedAt-n.receivedAt)}const _8=new Set(["action-required","approval"]);function nje(e){const t=(r,a)=>a.receivedAt-r.receivedAt,n=e.filter(r=>_8.has(r.kind)).sort(t),s=e.filter(r=>!_8.has(r.kind)).sort(t);return[...n,...s]}function sje(e){return e.tier==="human-gate"?"approval":(VE(e.destinationSession??""),"action-required")}function rje(e){const t=sje(e),n=`queue-attention-${e.qitemId}`,s=Date.parse(e.tsUpdated)||Date.now(),r=e.tsUpdated||e.tsCreated||new Date().toISOString(),a={seq:-1,type:"queue.attention.synthetic",payload:{qitemId:e.qitemId,destinationSession:e.destinationSession,sourceSession:e.sourceSession,tier:e.tier,state:e.state,body:e.body,humanQuestions:e.humanQuestions??null,humanAnswers:e.humanAnswers??null,tags:e.tags},createdAt:r,receivedAt:s},o=e.summary??(t==="approval"?`Approval needed: ${e.qitemId.slice(0,24)}`:`Action required: ${e.qitemId.slice(0,24)}`),c=(e.tags??[]).find(d=>d.startsWith("slice:"));return{id:n,kind:t,title:o,body:e.body,authorSession:e.sourceSession,receivedAt:s,createdAt:r,source:a,evidenceRef:e.evidenceRef??null,reviewSlice:c?c.slice(6):null,reviewAnchor:c?e.qitemId:null,...e.hostId!==void 0?{hostId:e.hostId}:{}}}function ije(e,t){const n=new Set;for(const r of t){const a=w8(r);a&&n.add(a)}const s=e.filter(r=>{if(r.kind!=="action-required"&&r.kind!=="approval")return!0;const a=w8(r);return a?!n.has(a):!0});return[...t,...s]}const xW="queue-attention-",aje="activity-needs-input-";function jv(e){return e.id.startsWith(xW)||e.id.startsWith(aje)}function oje(e){return e.id.startsWith(xW)}function lje(e){return e.filter(t=>!jv(t)).map(t=>t.source.seq)}function w8(e){const t=e.source.payload??{};return typeof t.qitemId=="string"&&t.qitemId.length>0?t.qitemId:typeof t.qitem_id=="string"&&t.qitem_id.length>0?t.qitem_id:null}function cje(e){const t=`activity-needs-input-${e.rigId??"unknown"}-${e.logicalId}`,n=e.eventAt??e.sampledAt??new Date().toISOString(),s=Date.parse(n)||Date.now(),r={seq:-1,type:"activity.needs_input.synthetic",payload:{logicalId:e.logicalId,sessionName:e.sessionName,source:e.source,rigId:e.rigId},createdAt:n,receivedAt:s};return{id:t,kind:"action-required",title:`${e.logicalId} needs input${e.source!=="hook"?" (activity-grade)":""}`,body:e.sessionName??void 0,rigId:e.rigId,source:r,receivedAt:s,createdAt:n}}function uje(){return Re({queryKey:["needs-input-seats"],queryFn:async()=>{var s,r;const e=await fetch("/api/ps");if(!e.ok)return[];const t=await e.json(),n=[];for(const a of t){let o;try{const c=await fetch(`/api/rigs/${encodeURIComponent(a.rigId)}/nodes?full=true`);if(!c.ok)continue;o=await c.json()}catch{continue}for(const c of o){const{state:d,source:h}=cp(c.agentActivity,c.terminalActive);d==="needs_input"&&n.push({logicalId:c.logicalId,sessionName:c.canonicalSessionName,source:h,eventAt:(s=c.agentActivity)==null?void 0:s.eventAt,sampledAt:(r=c.agentActivity)==null?void 0:r.sampledAt,rigId:a.rigId})}}return n},staleTime:5e3,refetchInterval:1e4})}const dje=["all-activity","highlights","needs-you"],hje={"all-activity":"level-control-option-all-activity",highlights:"level-control-option-highlights","needs-you":"level-control-option-needs-you"};function fje({level:e}){return e==="needs-you"?i.jsxs(i.Fragment,{children:[i.jsx("b",{className:"text-on-surface",children:"Just what needs you"})," · ",i.jsx("span",{className:"text-amber-700",children:"action items"})," only"]}):e==="all-activity"?i.jsxs(i.Fragment,{children:[i.jsx("b",{className:"text-on-surface",children:"All activity"})," · ",i.jsx("span",{className:"text-amber-700",children:"what needs you"})," + everything, incl. audit log"]}):e==="highlights"?i.jsxs(i.Fragment,{children:[i.jsx("b",{className:"text-on-surface",children:"Highlights"})," · ",i.jsx("span",{className:"text-amber-700",children:"what needs you"})," + approvals + ships + progress · ",i.jsx("span",{className:"text-on-surface-variant",children:"audit hidden"})]}):i.jsxs(i.Fragment,{children:[i.jsx("b",{className:"text-on-surface",children:"Custom"})," · set via the individual toggles below"]})}function pje(){const{state:e,setLevel:t,isMutating:n,unavailable:s}=nR(),r=Xne(e),a=!s&&!n;return i.jsxs("div",{"data-testid":"level-control",className:"border border-outline-variant bg-background",children:[i.jsxs("div",{className:"flex items-center justify-between bg-inverse-surface text-background font-mono text-[8px] tracking-[0.16em] uppercase px-2.5 py-1.5",children:[i.jsx("span",{children:"Show me"}),i.jsx("span",{className:"text-on-surface-variant",children:"action items always on"})]}),i.jsx("div",{className:"flex px-2.5 pt-2.5 pb-1",children:dje.map(o=>{const c=r===o;return i.jsx("button",{type:"button",role:"radio","aria-checked":c,disabled:!a,"data-testid":hje[o],"data-active":c?"true":"false",onClick:()=>t(o),className:"flex-1 -ml-px first:ml-0 border px-1 py-2 font-mono text-[9px] uppercase tracking-[0.06em] whitespace-nowrap "+(c?"bg-inverse-surface text-background border-on-surface relative z-10":"bg-transparent text-on-surface-variant border-outline-variant")+(a&&!c?" hover:bg-surface-low":"")+(a?"":" opacity-60 cursor-not-allowed"),children:Zne[o]},o)})}),i.jsx("div",{"data-testid":"level-control-readout",className:"font-mono text-[8px] tracking-[0.04em] text-on-surface-variant leading-relaxed px-2.5 pb-2.5 pt-1.5",children:i.jsx(fje,{level:r})}),s?i.jsx("p",{"data-testid":"level-control-unavailable",className:"font-mono text-[8px] text-on-surface-variant italic px-2.5 pb-2.5",children:"Settings endpoint unreachable (legacy daemon). Showing canonical defaults."}):null]})}const vW="forYou.dismissedSeqs";function mje(){try{const e=localStorage.getItem(vW);if(!e)return new Set;const t=JSON.parse(e);if(!Array.isArray(t))return new Set;const n=t.filter(s=>typeof s=="number"&&Number.isFinite(s));return new Set(n)}catch{return new Set}}function Qk(e){try{localStorage.setItem(vW,JSON.stringify(Array.from(e)))}catch{}}function gje(e){const[t,n]=E.useState(()=>mje()),s=E.useMemo(()=>{if(e.length===0)return null;let o=e[0];for(const c of e)c<o&&(o=c);return o},[e]);E.useEffect(()=>{if(s===null)return;let o=!1;const c=new Set;for(const d of t)d>=s?c.add(d):o=!0;o&&(n(c),Qk(c))},[s,t]);const r=E.useCallback(o=>{n(c=>{if(c.has(o))return c;const d=new Set(c);return d.add(o),Qk(d),d})},[]),a=E.useCallback(o=>{n(c=>{if(!c.has(o))return c;const d=new Set(c);return d.delete(o),Qk(d),d})},[]);return{dismissedSeqs:t,dismiss:r,undismiss:a}}const yW="forYou.dismissedCardIds";function xje(){try{const e=localStorage.getItem(yW);if(!e)return new Set;const t=JSON.parse(e);if(!Array.isArray(t))return new Set;const n=t.filter(s=>typeof s=="string"&&s.length>0);return new Set(n)}catch{return new Set}}function Xk(e){try{localStorage.setItem(yW,JSON.stringify(Array.from(e)))}catch{}}function vje(e){const[t,n]=E.useState(()=>xje()),s=E.useMemo(()=>new Set(e),[e]);E.useEffect(()=>{if(s.size===0)return;let o=!1;const c=new Set;for(const d of t)s.has(d)?c.add(d):o=!0;o&&(n(c),Xk(c))},[s,t]);const r=E.useCallback(o=>{n(c=>{if(c.has(o))return c;const d=new Set(c);return d.add(o),Xk(d),d})},[]),a=E.useCallback(o=>{n(c=>{if(!c.has(o))return c;const d=new Set(c);return d.delete(o),Xk(d),d})},[]);return{dismissedIds:t,dismiss:r,undismiss:a}}function yje(){const e=[{pos:"top-[18%] left-[36%]",text:"▪ 03°",size:"text-[10px]"},{pos:"top-[24%] right-[34%]",text:"**",size:"text-base"},{pos:"top-[44%] left-[44%]",text:"+",size:"text-sm"},{pos:"top-[52%] right-[36%]",text:"(A)",size:"text-[10px]"},{pos:"bottom-[34%] left-[20%]",text:"[?]",size:"text-sm"},{pos:"bottom-[42%] right-[24%]",text:"▪ 06°",size:"text-[10px]"},{pos:"bottom-[18%] left-[58%]",text:"+",size:"text-sm"}];return i.jsx(i.Fragment,{children:e.map((t,n)=>i.jsx("span",{className:`absolute ${t.pos} ${t.size??"text-xs"} font-mono text-on-surface leading-none`,children:t.text},n))})}function bje({tier:e="mid"}){const t=e==="mid"?"text-base":"text-2xl",n=[{pos:"top-[22%] left-[58%]",text:"■ 03°"},{pos:"top-[60%] left-[18%]",text:"+"},{pos:"bottom-[26%] right-[40%]",text:"■ 06°"},{pos:"top-[68%] right-[22%]",text:"▣"},{pos:"top-[72%] left-[8%]",text:"**"},{pos:"top-[86%] right-[5%]",text:"(A)"}];return i.jsx(i.Fragment,{children:n.map((s,r)=>i.jsx("span",{className:`absolute ${s.pos} ${t} font-mono text-on-surface leading-none`,children:s.text},r))})}function _je({hostname:e="127.0.0.1"}={}){return i.jsxs("div",{"data-testid":"mid-layer","aria-hidden":"true",className:"absolute inset-0 z-[10] overflow-hidden pointer-events-none select-none",children:[i.jsxs("div",{className:"absolute top-[64%] left-[3%] font-mono text-[11px] text-on-surface leading-tight max-w-[180px]",children:[i.jsx("div",{className:"font-bold uppercase",children:"▪ 06° Field Report"}),i.jsxs("div",{className:"text-on-surface mt-1",children:["Operator session captured at field station ",e," — release 0.3.1; daemon trace nominal."]})]}),i.jsxs("div",{className:"absolute bottom-[8%] left-[6%] font-mono text-[11px] text-on-surface leading-tight max-w-[180px]",children:[i.jsx("div",{className:"font-bold uppercase",children:"Data Streams ⚠⚠"}),i.jsxs("div",{className:"text-on-surface mt-1 text-[10px]",children:["x-axis(1) y-axis(2) z-axis(3) — synchronized at ",e]})]}),i.jsx(bje,{tier:"mid"})]})}function wje({hostname:e="127.0.0.1",totalRigs:t=1,totalAgents:n=4,activeAgents:s=4}={}){return i.jsxs("div",{"data-testid":"top-layer",className:"absolute inset-0 z-20 pointer-events-none select-none",children:[i.jsx("div",{"data-testid":"dashboard-classification",className:"absolute top-0 inset-x-0 border-b border-on-surface/40 bg-background/40 backdrop-blur-[6px]",children:i.jsxs("div",{className:"mx-auto max-w-[1180px] px-6 py-2 flex items-center justify-between gap-4 font-mono text-[10px] uppercase tracking-[0.32em] text-on-surface",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"inline-block w-1.5 h-1.5 bg-success rounded-none"}),"Operator"]}),i.jsx("span",{className:"hidden sm:inline",children:"▪ OpenRig · 0.3.1"}),i.jsxs("span",{className:"hidden md:inline",children:["▪ Field Station ",e]}),i.jsx("span",{className:"hidden md:inline",children:"▪ Session 04°"}),i.jsx("span",{className:"text-on-surface-variant",children:"04°"})]})}),i.jsxs("div",{className:"absolute top-[44px] left-[5%] right-[5%] z-20 pointer-events-none",children:[i.jsxs("h1",{"data-testid":"dashboard-greeting",className:"font-headline text-[44px] font-black tracking-tight uppercase text-on-surface leading-[0.95] inky-display",children:["Welcome back",i.jsx("sup",{className:"text-[22px] tracking-tight align-super",children:"(s*)"})]}),i.jsxs("div",{"data-testid":"dashboard-stats",className:"font-mono text-xs text-on-surface mt-2 flex flex-wrap items-baseline gap-x-4 gap-y-1",children:[i.jsxs("span",{"data-testid":"stat-rigs",className:"inline-flex items-baseline gap-1.5",children:[i.jsx("span",{className:"text-on-surface font-bold tabular-nums text-sm",children:String(t).padStart(2,"0")}),i.jsx("span",{className:"uppercase tracking-[0.12em] text-[10px]",children:"rigs"})]}),i.jsx("span",{"aria-hidden":"true",className:"text-on-surface-variant",children:"·"}),i.jsxs("span",{"data-testid":"stat-agents",className:"inline-flex items-baseline gap-1.5",children:[i.jsx("span",{className:"text-on-surface font-bold tabular-nums text-sm",children:String(n).padStart(2,"0")}),i.jsx("span",{className:"uppercase tracking-[0.12em] text-[10px]",children:"agents"}),i.jsx("span",{className:"ml-1 text-on-surface-variant",children:"("}),i.jsx("span",{className:"text-success font-bold tabular-nums",children:String(s).padStart(2,"0")}),i.jsx("span",{className:"uppercase tracking-[0.12em] text-[10px] text-success",children:"active"}),i.jsx("span",{className:"text-on-surface-variant",children:")"})]})]})]}),i.jsx("div",{className:"absolute bottom-8 right-10 rotate-[-4deg] origin-bottom-right",children:i.jsx("span",{className:"font-headline font-black text-[13px] tracking-[0.02em] text-on-surface uppercase inky-text",children:"Eyes Everywhere"})}),i.jsx(yje,{}),i.jsx("div",{className:"absolute left-2 top-[42%] font-mono text-[9px] uppercase tracking-[0.2em] text-on-surface-variant rotate-[-90deg] origin-top-left whitespace-nowrap",children:"▪ Author redacted · entry 04°"}),i.jsx("div",{"data-testid":"dashboard-footer-marginalia",className:"absolute bottom-0 inset-x-0 border-t border-on-surface/40 bg-background/40 backdrop-blur-[6px]",children:i.jsxs("div",{className:"mx-auto max-w-[1180px] px-6 py-2 flex items-center justify-between gap-4 font-mono text-[10px] uppercase tracking-[0.24em] text-on-surface",children:[i.jsx("span",{children:"▪▪▪ End Surface · Dashboard · 01°"}),i.jsx("span",{className:"hidden sm:inline",children:"Operator-Grade · ConfigStore-Backed"}),i.jsx("span",{children:"OpenRig · 0.3.1"})]})})]})}function xr({position:e}){const t={tl:"top-1.5 left-1.5",tr:"top-1.5 right-1.5",bl:"bottom-1.5 left-1.5",br:"bottom-1.5 right-1.5"}[e],n={tl:"M 10 0 L 0 0 L 0 10",tr:"M 0 0 L 10 0 L 10 10",bl:"M 0 0 L 0 10 L 10 10",br:"M 10 0 L 10 10 L 0 10"}[e];return i.jsx("svg",{className:`absolute ${t} w-2.5 h-2.5 text-on-surface pointer-events-none select-none`,viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:i.jsx("path",{d:n})})}function du(e){const{to:t,num:n,big:s,label:r,icon:a,body:o,graphic:c,positionClass:d,accent:h,washed:p,layout:f="numeral",callouts:g,tint:x="white",shadow:y="none"}=e,b=p?"inky-display":"",_=p?"inky-text":"",w={white:"bg-surface-lowest/30",cream:"bg-amber-50/45",stone:"bg-surface-low/45",rose:"bg-rose-50/45",slate:"bg-slate-50/50",sepia:"bg-yellow-50/45",mint:"bg-emerald-50/40"},k={none:{},soft:{boxShadow:"0 4px 12px rgba(0, 0, 0, 0.08)"},hard:{boxShadow:"3px 3px 0px #2e342e"},paper:{boxShadow:"0 2px 6px rgba(0,0,0,0.05), 0 8px 24px rgba(0,0,0,0.07)"},long:{boxShadow:"6px 6px 18px rgba(0, 0, 0, 0.1)"},inset:{boxShadow:"inset 0 1px 2px rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.04)"},halo:{boxShadow:"0 0 24px rgba(0, 0, 0, 0.12)"},ambient:{boxShadow:["0 2px 4px rgba(0, 0, 0, 0.14)","0 8px 20px rgba(0, 0, 0, 0.16)","0 0 40px rgba(0, 0, 0, 0.12)"].join(", ")}},N=s??n;return i.jsx(Ke,{to:t,"data-testid":`dashboard-card-${n}`,className:`absolute ${d} w-[28%] h-[220px] pointer-events-auto group block`,children:i.jsxs("article",{"data-testid":`destination-${n}`,style:k[y],className:`relative h-full ${w[x]} backdrop-blur-[10px] overflow-hidden transition-transform duration-300 ease-tactical group-hover:-translate-y-0.5 motion-reduce:transition-none motion-reduce:group-hover:translate-y-0`,children:[i.jsx(xr,{position:"tl"}),i.jsx(xr,{position:"tr"}),i.jsx(xr,{position:"bl"}),i.jsx(xr,{position:"br"}),i.jsxs("span",{className:"absolute top-2 right-6 font-mono text-[9px] uppercase tracking-[0.18em] text-on-surface select-none",children:["■ ",n,"°"]}),f==="headline"&&i.jsx(jje,{label:r,icon:a,body:o,graphic:c,to:t,accent:h,textClass:_}),f==="stat"&&i.jsx(Nje,{label:r,num:n,icon:a,body:o,graphic:c,to:t,accent:h,textClass:_}),f==="coordinate"&&i.jsx(kje,{label:r,num:n,icon:a,body:o,graphic:c,to:t,accent:h,textClass:_}),f==="schematic"&&i.jsx(Cje,{label:r,num:n,icon:a,body:o,graphic:c,to:t,accent:h,textClass:_,callouts:g,washed:p}),(f==="numeral"||!f)&&i.jsx(Sje,{big:N,numClass:b,graphic:c,body:o,label:r,icon:a,to:t,accent:h,textClass:_}),h&&i.jsxs("div",{className:"absolute bottom-[88px] right-[-14px] w-[156px] border border-tertiary text-tertiary font-mono text-[7.5px] uppercase tracking-[0.18em] px-1.5 py-[2px] flex items-center gap-1 bg-background/30",children:[i.jsx("span",{className:"inline-block w-[3px] h-[3px] bg-tertiary rounded-full"}),"Warning · Operator Live"]})]})})}function Sje({big:e,numClass:t,graphic:n,body:s,label:r,icon:a,to:o,accent:c,textClass:d}){return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`absolute top-7 left-3 font-headline font-black text-[110px] leading-[0.82] tracking-[-0.06em] text-on-surface select-none ${t}`,children:[e[0],i.jsx("sup",{className:"text-[55px] tracking-tight align-super",children:e[1]})]}),i.jsx("div",{className:"absolute top-7 right-7 w-[58px] h-[58px]",children:n}),i.jsx("p",{className:`absolute bottom-12 right-1 w-[140px] font-mono text-[8.5px] leading-[1.35] uppercase text-on-surface ${d}`,children:s}),i.jsxs("div",{className:"absolute bottom-3 left-3 right-3 flex items-baseline gap-2",children:[i.jsx("span",{className:c?"text-tertiary":"text-on-surface",children:a}),i.jsx("h2",{className:`font-headline font-black text-[17px] leading-none uppercase tracking-tight ${d} ${c?"text-tertiary":"text-on-surface"}`,children:r}),i.jsxs("span",{className:`ml-auto font-mono text-[9px] tracking-tight text-on-surface-variant ${d}`,children:["[",o,"] →"]})]})]})}function jje({label:e,icon:t,body:n,graphic:s,to:r,accent:a,textClass:o}){return i.jsxs(i.Fragment,{children:[i.jsx("h2",{className:`absolute top-6 left-3 right-3 font-headline font-black text-[40px] leading-[0.95] uppercase tracking-tight text-on-surface ${o} ${a?"text-tertiary":""}`,children:e}),i.jsx("div",{className:"absolute top-[88px] left-3 right-3 h-px bg-inverse-surface/30"}),i.jsx("div",{className:"absolute top-[100px] left-3 w-[60px] h-[60px]",children:s}),i.jsx("p",{className:`absolute top-[100px] left-[80px] right-1 font-mono text-[8.5px] leading-[1.35] uppercase text-on-surface ${o}`,children:n}),i.jsxs("div",{className:"absolute bottom-3 left-3 right-3 flex items-baseline gap-2",children:[i.jsx("span",{className:a?"text-tertiary":"text-on-surface",children:t}),i.jsx("span",{className:`font-mono text-[9px] uppercase tracking-[0.16em] text-on-surface ${o}`,children:"Destination · 01°"}),i.jsxs("span",{className:`ml-auto font-mono text-[9px] tracking-tight text-on-surface-variant ${o}`,children:["[",r,"] →"]})]})]})}function Nje({label:e,num:t,icon:n,body:s,graphic:r,to:a,accent:o,textClass:c}){return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"absolute top-3 left-3 font-mono text-[9px] uppercase tracking-[0.16em] text-on-surface select-none",children:["▪ ",e," · ",t,"°"]}),i.jsx("div",{className:"absolute top-9 right-9 w-[36px] h-[36px]",children:r}),i.jsxs("div",{className:"absolute top-[44px] left-3 flex items-baseline gap-3",children:[i.jsx("span",{className:`font-headline font-black text-[64px] leading-[0.82] tracking-[-0.04em] text-on-surface tabular-nums ${c}`,children:"38"}),i.jsxs("div",{className:"flex flex-col leading-tight",children:[i.jsx("span",{className:"font-mono text-[10px] uppercase tracking-wide text-on-surface",children:"Active"}),i.jsx("span",{className:"font-mono text-[10px] uppercase tracking-wide text-on-surface",children:"Artifacts"})]})]}),i.jsxs("div",{className:"absolute top-[120px] left-3 right-3 grid grid-cols-3 gap-0",children:[i.jsx(Zk,{big:"12",small:"Specs"}),i.jsx(Zk,{big:"08",small:"Plugins"}),i.jsx(Zk,{big:"18",small:"Skills"})]}),i.jsx("p",{className:`absolute bottom-12 left-3 right-1 font-mono text-[8px] leading-[1.3] uppercase text-on-surface ${c}`,children:s}),i.jsxs("div",{className:"absolute bottom-3 left-3 right-3 flex items-baseline gap-2",children:[i.jsx("span",{className:o?"text-tertiary":"text-on-surface",children:n}),i.jsx("h2",{className:`font-headline font-black text-[15px] leading-none uppercase tracking-tight ${o?"text-tertiary":"text-on-surface"}`,children:e}),i.jsxs("span",{className:"ml-auto font-mono text-[9px] tracking-tight text-on-surface-variant",children:["[",a,"] →"]})]})]})}function Zk({big:e,small:t}){return i.jsxs("div",{className:"border-l border-on-surface/30 first:border-l-0 pl-2",children:[i.jsx("div",{className:"font-mono text-[14px] font-bold tabular-nums text-on-surface leading-none",children:e}),i.jsx("div",{className:"font-mono text-[8px] uppercase tracking-wide text-on-surface-variant mt-0.5",children:t})]})}function kje({label:e,num:t,icon:n,body:s,graphic:r,to:a,accent:o,textClass:c}){const d=Array.from({length:12});return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"absolute top-3 left-3 font-mono text-[9px] uppercase tracking-[0.16em] text-on-surface select-none",children:["▪ ",e," · ",t,"°"]}),i.jsx("div",{className:"absolute top-7 left-6 right-6 flex justify-between",children:d.map((h,p)=>i.jsx("span",{className:`w-px h-[6px] ${p%3===0?"bg-inverse-surface":"bg-inverse-surface/40"}`},p))}),i.jsx("div",{className:"absolute bottom-12 left-6 right-6 flex justify-between",children:d.map((h,p)=>i.jsx("span",{className:`w-px h-[6px] ${p%3===0?"bg-inverse-surface":"bg-inverse-surface/40"}`},p))}),i.jsx("div",{className:"absolute top-12 bottom-16 left-3 flex flex-col justify-between",children:Array.from({length:8}).map((h,p)=>i.jsx("span",{className:`h-px w-[6px] ${p%2===0?"bg-inverse-surface":"bg-inverse-surface/40"}`},p))}),i.jsx("div",{className:"absolute top-12 bottom-16 right-3 flex flex-col justify-between",children:Array.from({length:8}).map((h,p)=>i.jsx("span",{className:`h-px w-[6px] ${p%2===0?"bg-inverse-surface":"bg-inverse-surface/40"}`},p))}),i.jsx("div",{className:"absolute top-[40px] left-1/2 -translate-x-1/2 w-[72px] h-[72px]",children:r}),i.jsx("div",{className:"absolute top-[76px] left-6 right-6 h-px bg-inverse-surface/30"}),i.jsx("div",{className:"absolute top-[40px] bottom-[80px] left-1/2 w-px bg-inverse-surface/30"}),i.jsx("span",{className:"absolute top-[120px] left-1/2 ml-1 font-mono text-[8px] text-on-surface",children:"⟨x: 24, y: 18⟩"}),i.jsx("p",{className:`absolute bottom-[60px] left-6 right-6 font-mono text-[8px] leading-[1.3] uppercase text-on-surface text-center ${c}`,children:s}),i.jsxs("div",{className:"absolute bottom-3 left-3 right-3 flex items-baseline gap-2",children:[i.jsx("span",{className:o?"text-tertiary":"text-on-surface",children:n}),i.jsx("h2",{className:"font-headline font-black text-[15px] leading-none uppercase tracking-tight text-on-surface",children:e}),i.jsxs("span",{className:"ml-auto font-mono text-[9px] tracking-tight text-on-surface-variant",children:["[",a,"] →"]})]})]})}function Cje({label:e,num:t,icon:n,body:s,graphic:r,to:a,accent:o,textClass:c,callouts:d,washed:h}){const p=d??["A","B","C","D"];return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"absolute top-3 left-3 font-mono text-[9px] uppercase tracking-[0.16em] text-on-surface select-none",children:["▪ ",e," · ",t,"°"]}),i.jsx("div",{className:"absolute top-7 left-1/2 -translate-x-1/2 w-[110px] h-[110px]",children:r}),i.jsx(ix,{num:".01",label:p[0],positionClass:"top-[42px] left-3",align:"left"}),i.jsx(ix,{num:".02",label:p[1],positionClass:"top-[42px] right-3",align:"right"}),i.jsx(ix,{num:".03",label:p[2],positionClass:"top-[98px] left-3",align:"left"}),i.jsx(ix,{num:".04",label:p[3],positionClass:"top-[98px] right-3",align:"right"}),i.jsx("p",{className:`absolute bottom-12 left-3 right-3 font-mono text-[8px] leading-[1.3] uppercase text-on-surface text-center ${c}`,children:s}),i.jsxs("div",{className:"absolute bottom-3 left-3 right-3 flex items-baseline gap-2",children:[i.jsx("span",{className:o?"text-tertiary":"text-on-surface",children:n}),i.jsx("h2",{className:`font-headline font-black text-[15px] leading-none uppercase tracking-tight ${h?"inky-text":""} ${o?"text-tertiary":"text-on-surface"}`,children:e}),i.jsxs("span",{className:"ml-auto font-mono text-[9px] tracking-tight text-on-surface-variant",children:["[",a,"] →"]})]})]})}function ix({num:e,label:t,positionClass:n,align:s}){return i.jsxs("div",{className:`absolute ${n} font-mono text-[8px] text-on-surface ${s==="right"?"text-right":"text-left"}`,children:[i.jsx("span",{className:"block",children:e}),i.jsx("span",{className:"block tabular-nums text-on-surface",children:t})]})}function Eje(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[i.jsx("path",{d:"M2 26 Q 18 18 30 22 T 58 18"}),i.jsx("path",{d:"M2 36 Q 18 28 30 32 T 58 28",strokeDasharray:"2 2"}),i.jsx("path",{d:"M2 46 Q 18 40 30 42 T 58 38",strokeDasharray:"2 2"}),i.jsx("circle",{cx:"30",cy:"22",r:"2",fill:"currentColor"}),i.jsx("line",{x1:"30",y1:"22",x2:"30",y2:"10"}),i.jsx("text",{x:"34",y:"12",fontSize:"6",fontFamily:"monospace",fill:"currentColor",fontWeight:"bold",children:"[01]"})]})}function Rje(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[i.jsx("rect",{x:"22",y:"6",width:"16",height:"8"}),i.jsx("rect",{x:"6",y:"28",width:"14",height:"8"}),i.jsx("rect",{x:"40",y:"28",width:"14",height:"8"}),i.jsx("rect",{x:"6",y:"48",width:"14",height:"6"}),i.jsx("rect",{x:"22",y:"48",width:"14",height:"6"}),i.jsx("rect",{x:"40",y:"48",width:"14",height:"6"}),i.jsx("line",{x1:"30",y1:"14",x2:"13",y2:"28"}),i.jsx("line",{x1:"30",y1:"14",x2:"47",y2:"28"}),i.jsx("line",{x1:"13",y1:"36",x2:"13",y2:"48"}),i.jsx("line",{x1:"47",y1:"36",x2:"47",y2:"48"}),i.jsx("line",{x1:"13",y1:"44",x2:"29",y2:"48"}),i.jsx("line",{x1:"47",y1:"44",x2:"29",y2:"48"})]})}function Aje(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[i.jsx("circle",{cx:"30",cy:"30",r:"4",fill:"currentColor"}),i.jsx("circle",{cx:"30",cy:"30",r:"12"}),i.jsx("circle",{cx:"30",cy:"30",r:"20",strokeDasharray:"2 3"}),i.jsx("circle",{cx:"30",cy:"30",r:"27",strokeDasharray:"2 4"}),i.jsx("line",{x1:"30",y1:"0",x2:"30",y2:"60",strokeDasharray:"2 3"}),i.jsx("line",{x1:"0",y1:"30",x2:"60",y2:"30",strokeDasharray:"2 3"})]})}function Tje(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[i.jsx("circle",{cx:"30",cy:"30",r:"26"}),i.jsx("ellipse",{cx:"30",cy:"30",rx:"26",ry:"9"}),i.jsx("ellipse",{cx:"30",cy:"30",rx:"9",ry:"26"}),i.jsx("line",{x1:"0",y1:"30",x2:"60",y2:"30",strokeDasharray:"2 3"}),i.jsx("line",{x1:"30",y1:"0",x2:"30",y2:"60",strokeDasharray:"2 3"}),i.jsx("circle",{cx:"30",cy:"30",r:"3",fill:"currentColor"})]})}function Ije(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[i.jsx("circle",{cx:"24",cy:"24",r:"14"}),i.jsx("line",{x1:"20",y1:"24",x2:"28",y2:"24"}),i.jsx("line",{x1:"24",y1:"20",x2:"24",y2:"28"}),i.jsx("line",{x1:"34",y1:"34",x2:"52",y2:"52",strokeWidth:"1.6"}),i.jsx("line",{x1:"48",y1:"48",x2:"55",y2:"48"}),i.jsx("line",{x1:"48",y1:"48",x2:"48",y2:"55"})]})}function Mje(){return i.jsxs("svg",{className:"w-full h-full text-on-surface",viewBox:"0 0 60 60",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[i.jsx("circle",{cx:"30",cy:"30",r:"20"}),i.jsx("circle",{cx:"30",cy:"30",r:"12"}),i.jsx("circle",{cx:"30",cy:"30",r:"3",fill:"currentColor"}),i.jsx("line",{x1:"30",y1:"6",x2:"30",y2:"11",strokeWidth:"1.5"}),i.jsx("line",{x1:"30",y1:"49",x2:"30",y2:"54",strokeWidth:"1.5"}),i.jsx("line",{x1:"6",y1:"30",x2:"11",y2:"30",strokeWidth:"1.5"}),i.jsx("line",{x1:"49",y1:"30",x2:"54",y2:"30",strokeWidth:"1.5"}),i.jsx("line",{x1:"13",y1:"13",x2:"17",y2:"17",strokeWidth:"1.5"}),i.jsx("line",{x1:"43",y1:"13",x2:"47",y2:"17",strokeWidth:"1.5"}),i.jsx("line",{x1:"13",y1:"47",x2:"17",y2:"43",strokeWidth:"1.5"}),i.jsx("line",{x1:"43",y1:"47",x2:"47",y2:"43",strokeWidth:"1.5"})]})}function Lje({librarySize:e}={}){const t=e&&e>0?`Specs · Plugins · Skills · Context packs. Field catalog 0.3.1 — ${e} active artifacts.`:"Specs · Plugins · Skills · Context packs. Field catalog 0.3.1 — 38 active artifacts.";return i.jsxs("div",{"data-testid":"destinations-layer",className:"absolute inset-0 z-[18] pointer-events-none",children:[i.jsx(du,{to:"/topology",num:"01",big:"01",label:"Topology",icon:i.jsx(IE,{className:"h-4 w-4"}),body:"Host · Rig · Pod · Seat tree — live edges + runtimes; drill into any rig's pod graph.",positionClass:"top-[22%] left-[5%]",graphic:i.jsx(Rje,{}),layout:"numeral",callouts:["HOST","RIG","POD","SEAT"],tint:"stone",shadow:"ambient"}),i.jsx(du,{to:"/project",num:"02",big:"02",label:"Project",icon:i.jsx(AE,{className:"h-4 w-4"}),body:"Workspace · Mission · Slice. Browse all in-flight work by what agents are doing, not by repo.",positionClass:"top-[22%] left-[36%]",graphic:i.jsx(Eje,{}),layout:"numeral",callouts:["WORKSPACE","MISSION","SLICE","TASK"],washed:!0,tint:"stone",shadow:"ambient"}),i.jsx(du,{to:"/for-you",num:"03",big:"03",label:"For You",icon:i.jsx(LE,{className:"h-4 w-4"}),body:"Action feed → what needs you · what shipped · what's in flight. Prioritized for the operator.",positionClass:"top-[22%] left-[67%]",graphic:i.jsx(Aje,{}),layout:"numeral",callouts:["NEEDS YOU","SHIPPED","IN-FLIGHT","BLOCKED"],accent:!0,tint:"stone",shadow:"ambient"}),i.jsx(du,{to:"/specs",num:"04",big:"04",label:"Library",icon:i.jsx(mF,{className:"h-4 w-4"}),body:t,positionClass:"top-[55%] left-[5%]",graphic:i.jsx(Tje,{}),layout:"numeral",callouts:["SPECS","PLUGINS","SKILLS","PACKS"],tint:"stone",shadow:"ambient"}),i.jsx(du,{to:"/search",num:"05",big:"05",label:"Search & Audit",icon:i.jsx(qJ,{className:"h-4 w-4"}),body:"Audit history · full artifact explorer. V1 placeholder; the full surface ships in V2.",positionClass:"top-[55%] left-[36%]",graphic:i.jsx(Ije,{}),layout:"numeral",callouts:["AUDIT","HISTORY","QUERY","FILTER"],tint:"stone",shadow:"ambient"}),i.jsx(du,{to:"/settings",num:"06",big:"06",label:"Settings",icon:i.jsx(pF,{className:"h-4 w-4"}),body:"Config · Policy · Log · Status. Operator-grade controls; ConfigStore-backed; reversible.",positionClass:"top-[55%] left-[67%]",graphic:i.jsx(Mje,{}),layout:"numeral",callouts:["CONFIG","POLICY","LOG","STATUS"],tint:"stone",shadow:"ambient"})]})}function Oje(e){const t=fp(e);return t.kind!=="canonical"?{logicalId:e,rigId:null}:{logicalId:t.member,rigId:t.rig}}function Pje({authorSession:e,rigId:t,className:n,testId:s}){const r=Oje(e),a=t??r.rigId,o=aA(),c=ZF(e);return a?i.jsxs(Ke,{to:"/topology/seat/$rigId/$logicalId",params:{rigId:a,logicalId:encodeURIComponent(r.logicalId)},"data-testid":s??"author-agent-tag",onClick:d=>{d.metaKey||d.ctrlKey||d.shiftKey||d.button!==0||o.mutate({rigId:a,logicalId:r.logicalId})},className:n??"inline-flex items-center gap-1 font-mono text-[10px] text-on-surface-variant hover:text-on-surface hover:underline",children:[c?i.jsx(Xx,{actor:e,size:"xs"}):null,i.jsx("span",{children:e})]}):i.jsxs("span",{"data-testid":s??"author-agent-tag",className:n??"inline-flex items-center gap-1 font-mono text-[10px] text-on-surface-variant",children:[c?i.jsx(Xx,{actor:e,size:"xs"}):null,i.jsx("span",{children:e})]})}const Dje="openrig:topology-terminal-preview";function $je({cardId:e,sessionName:t}){if(!t)return i.jsx("button",{type:"button",disabled:!0,"data-testid":`feed-card-drill-${e}`,title:"No session resolved for this card — live terminal unavailable",className:"inline-flex items-center gap-1 font-mono text-[10px] uppercase tracking-wide text-on-surface-variant cursor-not-allowed",children:"live terminal"});const n=`${e}:${t}`,s=r=>{r.stopPropagation(),window.dispatchEvent(new CustomEvent(Dje,{detail:{key:n}}))};return i.jsxs("span",{className:"inline-flex items-center",children:[i.jsx("button",{type:"button","data-testid":`feed-card-drill-${e}`,onClick:s,title:`Open live terminal for ${t}`,className:"font-mono text-[10px] uppercase tracking-wide text-on-surface hover:text-on-surface underline",children:"live terminal"}),i.jsx(by,{rigId:e,logicalId:t,sessionName:t,renderTrigger:!1,testIdPrefix:`feed-card-drill-${e}`})]})}const dd=e=>!!e&&typeof e=="object"&&!Array.isArray(e),cf=(e,t)=>e&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;function Bje(){const e=globalThis.crypto;if(typeof e.randomUUID=="function")return e.randomUUID();const t=new Uint8Array(16);e.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;const n=Array.from(t,s=>s.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function qje(e){if(!Array.isArray(e)||e.length===0)return[];const t=[];for(const n of e){if(!dd(n)||typeof n.id!="string"||typeof n.question!="string"||!Array.isArray(n.options)||n.options.length===0)return[];const s=[];for(const r of n.options){if(!dd(r)||typeof r.id!="string"||typeof r.label!="string")return[];s.push({id:r.id,label:r.label,...r.recommended===!0?{recommended:!0}:{}})}t.push({id:n.id,question:n.question,options:s})}return t}function vf(e){if(!dd(e))return{};const t={};for(const[n,s]of Object.entries(e))typeof s=="string"?t[n]=s:dd(s)&&s.kind==="typed-reply"&&typeof s.text=="string"&&(t[n]={kind:"typed-reply",text:s.text});return t}function bW(e,t){return e.flatMap(n=>{var a;const s=cf(t,n.id);if(s===void 0)return[];const r=typeof s=="string"?((a=n.options.find(o=>o.id===s))==null?void 0:a.label)??s:s.text;return[{questionId:n.id,question:n.question,answerText:r}]})}const ju=e=>(e??"").toLowerCase().replace("cancelled","canceled").replace("handed_off","handed-off"),zh=new Set(["done","closed","completed","canceled","denied","expired","handed-off","routed"]),S8={denied:"denied",canceled:"dropped","handed-off-to":"handed off","handed-off":"handed off",routed:"routed",expired:"expired"},ax="min-h-[44px] px-3 py-2 border font-mono text-[10px] uppercase tracking-wider break-words whitespace-normal disabled:opacity-50",j8="w-full min-[360px]:w-auto min-h-[44px] px-3 py-1 font-mono text-[10px] uppercase disabled:opacity-50",ur=new Map;WSe(e=>{e===void 0?ur.clear():ur.delete(e)});function Fje(e,t,n){var x,y,b,_,w,k;const s=bW(t,vf(e==null?void 0:e.humanAnswers)),r=ju((e==null?void 0:e.state)??((x=e==null?void 0:e.closingTransition)==null?void 0:x.state)??((y=e==null?void 0:e.closingTransition)==null?void 0:y.toState)??n??"closed"),a=(e==null?void 0:e.closureReason)??((b=e==null?void 0:e.closingTransition)==null?void 0:b.closureReason)??((_=e==null?void 0:e.closingTransition)==null?void 0:_.reason)??null,o=a?ju(a).replace("_","-"):null,c=(o&&S8[o])??S8[r]??r,d=(w=e==null?void 0:e.closingTransition)==null?void 0:w.actorSession,h=(e==null?void 0:e.handedOffTo)??(e==null?void 0:e.closureTarget)??((k=e==null?void 0:e.closingTransition)==null?void 0:k.closureTarget),p=[d?`by ${d}`:null,h&&h!=="no-follow-on"?c==="handed off"||c==="routed"?`to ${h}`:`(${h})`:null].filter(Boolean),f=s.map(N=>`${N.question}: ${N.answerText}`).join("; "),g=s.length>0?` Recorded: ${f}${/[.!?]$/.test(f)?"":"."}`:"";return`This request is ${c} now${p.length?` ${p.join(" ")}`:""}.${g}`}function zje({cardId:e,qitemId:t,actorSession:n,recipientSession:s,askerSession:r,questions:a,initialAnswers:o,queueItem:c}){var fn,rn,Et;const d=bt(),h=lW(),p=(c==null?void 0:c.decisionRevision)??void 0,f=ju(c==null?void 0:c.state),g=!!(f&&zh.has(f)),x=ur.get(t),y=!!((rn=(fn=x==null?void 0:x.settled)==null?void 0:fn.refreshedItem)!=null&&rn.state&&zh.has(ju(x.settled.refreshedItem.state))),b=!!(x&&(p&&p!==x.revision&&p!==x.queueItemRevisionAtSave||x.settled&&f&&!g&&(y||!p||p!==x.revision&&p!==x.queueItemRevisionAtSave)));b&&ur.delete(t);const _=b?void 0:x,[w,k]=E.useState(()=>(_==null?void 0:_.answers)??{}),[N,C]=E.useState(()=>_!=null&&_.revision?p&&p!==_.queueItemRevisionAtSave?p:_.revision:p),[R,T]=E.useState(!1),[A,I]=E.useState(""),[M,B]=E.useState(()=>(_==null?void 0:_.lastOutcome)??null),[L,P]=E.useState(()=>{var de;return((de=_==null?void 0:_.settled)==null?void 0:de.error)??null}),[q,$]=E.useState(!1),[F,D]=E.useState(()=>_!=null&&_.settled?{refreshing:!1,refreshedItem:_.settled.refreshedItem,fallbackState:_.settled.fallbackState}:null),z=E.useRef(p),U=E.useRef(f);E.useEffect(()=>{if(p===z.current&&f===U.current)return;const de=!!(U.current&&zh.has(U.current));z.current=p,U.current=f;const Oe=ur.get(t),Ve=!!(Oe&&p&&(p===Oe.revision||p===Oe.queueItemRevisionAtSave));!!((F||Oe!=null&&Oe.settled)&&f&&!g&&(de||!Ve))||p&&!Ve&&p!==N?(ur.delete(t),C(p),k({}),B(null),D(null),P(null)):p&&!N&&C(p)},[p,f,g,t,N,F]);const K=de=>{const Oe=ur.get(t)??{answers:w,revision:N};if(ur.delete(t),ur.size>=fW){const Ve=ur.keys().next().value;Ve!==void 0&&ur.delete(Ve)}ur.set(t,{...Oe,queueItemRevisionAtSave:(c==null?void 0:c.decisionRevision)??null,...de})},Q=()=>{var de;for(const[,Oe]of d.getQueriesData({queryKey:["attention-items"]})){const Ve=(de=Oe==null?void 0:Oe.items)==null?void 0:de.find(We=>We.qitemId===t&&(!We.hostId||We.hostId==="local"));if(Ve)return Ve}return c?{...c,blockedOn:c.blockedOn??null,handedOffTo:c.handedOffTo??null,handedOffFrom:c.handedOffFrom??null}:null},H=E.useRef(new Map),W=de=>{const Oe=H.current.get(de);if(Oe)return Oe;const Ve=Bje();return H.current.set(de,Ve),Ve},ee={...o,...vf(c==null?void 0:c.humanAnswers),...w},G=N??p,Y=typeof G=="string"&&G.length>0,X=a.length,te=a.filter(de=>cf(ee,de.id)!==void 0).length,se=X>0&&te===X,ie=r??"the asker",xe=s&&VE(s)?s:n,ye=`Answering as human@host (unattributed)${s&&s!=="human@host"?` on ${s}'s ask`:""}`;async function _e(de){var Qe,wt,Je;const Oe=typeof((Qe=de==null?void 0:de.details)==null?void 0:Qe.state)=="string"?de.details.state:null,Ve=(de==null?void 0:de.code)==="qitem_already_terminal"||(de==null?void 0:de.code)==="decision_revision_changed";(Ve||de!=null&&de.fromUnknown||de!=null&&de.fromLoadRetry)&&D(St=>({refreshing:!0,refreshedItem:(St==null?void 0:St.refreshedItem)??c??null,fallbackState:Oe})),d.invalidateQueries({queryKey:["attention-items"]}),d.invalidateQueries({queryKey:["mission-control","audit"]});let We=null;try{We=await d.fetchQuery({queryKey:["queue","item",t],queryFn:async()=>{const St=await fetch(`/api/queue/${encodeURIComponent(t)}`);if(!St.ok)throw new Error(`HTTP ${St.status}`);return await St.json()},staleTime:0})}catch{We=null}if(de!=null&&de.fromLoadRetry&&$(!(We!=null&&We.decisionRevision)),de!=null&&de.fromUnknown){if(!We){D(null),P(St=>St&&{...St,message:"Could not refresh request state. Check connection and try again."});return}P(null)}const mt=(We==null?void 0:We.decisionRevision)??(typeof((wt=de==null?void 0:de.details)==null?void 0:wt.currentRevision)=="string"?de.details.currentRevision:void 0);mt&&($(!1),C(mt),K({revision:mt}));const ys=(We==null?void 0:We.humanAnswers)??((Je=de==null?void 0:de.details)==null?void 0:Je.humanAnswers);if(ys){const St=vf(ys);k(St),K({answers:St})}if(!Ve&&!(de!=null&&de.fromUnknown)&&!(de!=null&&de.fromLoadRetry))return;const Zn=We??c??null,Bt=ju((We==null?void 0:We.state)??Oe??(c==null?void 0:c.state)??"pending");if((de==null?void 0:de.code)!=="qitem_already_terminal"&&!zh.has(Bt)){D(null),K({revision:mt??N,settled:null});return}D({refreshing:!1,refreshedItem:Zn,fallbackState:Oe}),K({revision:mt??N,settled:{refreshedItem:Zn,fallbackState:Oe,error:(de==null?void 0:de.errSummary)??null}})}function ge(de,Oe,Ve,We,mt){if(h.isPending||F||!Y)return;let ys;try{GSe(t,Q()),ys=W(Oe)}catch(Bt){P({message:Bt instanceof Error?Bt.message:String(Bt),source:de,unknown:!1});return}P(null);const Zn=()=>{if(!We)return ee;const Bt=We(w);return k(Bt),Bt};h.mutate({verb:"answer",qitemId:t,actorSession:xe,...Ve,expectedRevision:G,authority:"primary-user",auditNotes:{operationId:ys}},{onSuccess:Bt=>{var Ni;H.current.delete(Oe),P(null);const Qe=dd(Bt.closedQitem)?Bt.closedQitem:null,wt=typeof(Qe==null?void 0:Qe.state)=="string"?Qe.state:void 0,Je=wt?ju(wt):void 0,St=typeof(Qe==null?void 0:Qe.closureReason)=="string"?Qe.closureReason:null,an=typeof(Qe==null?void 0:Qe.closureTarget)=="string"?Qe.closureTarget:void 0,bs=Bt.decisionRevision??(typeof(Qe==null?void 0:Qe.decisionRevision)=="string"?Qe.decisionRevision:void 0)??N;bs&&C(bs),(c||d.getQueryData(["queue","item",t]))&&d.setQueryData(["queue","item",t],zn=>zn&&{...zn,...bs?{decisionRevision:bs}:{},...wt?{state:wt}:{},...St!==null?{closureReason:St}:{},...an!==void 0?{closureTarget:an}:{},...Qe!=null&&Qe.humanAnswers?{humanAnswers:Qe.humanAnswers}:{}});let Jn=ee;if(Qe!=null&&Qe.humanAnswers?(Jn=vf(Qe.humanAnswers),k(Jn)):Jn=Zn(),((Ni=Bt.answer)==null?void 0:Ni.outcome)!=="answered"&&Je&&zh.has(Je)){const zn=Qe;B(null),D({refreshing:!1,refreshedItem:zn,fallbackState:Je}),K({answers:Jn,revision:bs,lastOutcome:null,settled:{refreshedItem:zn,fallbackState:Je,error:null}});return}const gc=Bt.answer??{outcome:"recorded",unanswered:a.filter(zn=>cf({...ee,...Jn},zn.id)===void 0).map(zn=>zn.question)};B(gc),K({answers:Jn,revision:bs,lastOutcome:gc}),mt==null||mt()},onError:Bt=>{const Qe=Bt instanceof Error?Bt:new Error(String(Bt)),wt=dd(Qe.details)?Qe.details:void 0,Je=Qe.code;if(Je==="answer_not_closed"){if(typeof(wt==null?void 0:wt.replyQitemId)=="string"){const bs=Zn(),Jn={outcome:"answered",unanswered:[],message:Qe.message,notClosed:!0,code:Je};P(null),B(Jn),K({answers:bs,revision:N,lastOutcome:Jn}),mt==null||mt(),_e({code:Je,details:wt});return}if(de!=="words"){const bs=Zn(),Jn={outcome:"recorded",unanswered:[]};B(Jn),K({answers:bs,lastOutcome:Jn})}}const St=!Je||typeof Qe.status=="number"&&Qe.status>=500,an={code:Je,message:Qe.message,source:de,unknown:St};P(an),(Je==="qitem_already_terminal"||Je==="decision_revision_changed"||Je==="answer_not_closed"&&de!=="words")&&_e({code:Je,details:wt,errSummary:an})}})}const Se=i.jsx("div",{"data-testid":`feed-card-answer-identity-${e}`,className:"font-mono text-[10px] text-on-surface-variant break-words",children:ye}),ke=de=>L?i.jsxs("div",{"data-testid":`feed-card-answer-error-${e}`,role:"alert",className:"space-y-1 border border-error bg-error-container px-2.5 py-2 text-on-error-container",children:[de?i.jsx("p",{className:"font-mono text-[10px] uppercase tracking-wider text-on-error-container",children:de}):null,i.jsx("p",{"data-testid":`feed-card-answer-error-message-${e}`,className:"font-body text-[11px] leading-relaxed break-words whitespace-pre-wrap",children:L.message}),L.code?i.jsx("div",{"data-testid":`feed-card-answer-error-code-${e}`,className:"font-mono text-[10px] text-on-error-container/80 break-words",children:L.code}):null,L.unknown?i.jsx("button",{type:"button","data-testid":`feed-card-answer-refresh-${e}`,onClick:()=>void _e({fromUnknown:!0}),className:"mt-1 min-h-[36px] border border-on-error-container px-2.5 py-1 font-mono text-[10px] uppercase tracking-wider text-on-error-container hover:opacity-80",children:"Refresh request state"}):null]}):null;if((M==null?void 0:M.outcome)==="answered"){const de=bW(a,ee);return i.jsxs("div",{"data-testid":`feed-card-answer-receipt-${e}`,className:"w-full space-y-2 border border-outline-variant bg-surface-lowest/55 p-3",children:[Se,i.jsxs("div",{className:"flex items-center gap-2 font-mono text-[10px] uppercase tracking-[0.14em] text-on-surface",children:[i.jsx(Xu,{className:"h-3.5 w-3.5 shrink-0 text-success",strokeWidth:1.8}),i.jsx("span",{children:M.notClosed?`Answered and returned to ${ie}; this ask didn't close.`:`Answered and sent to ${ie}.`})]}),M.message?i.jsx("p",{"data-testid":`feed-card-answer-receipt-message-${e}`,className:"font-body text-[12px] leading-relaxed text-on-surface break-words",children:M.message}):null,M.code?i.jsx("div",{"data-testid":`feed-card-answer-error-code-${e}`,className:"font-mono text-[10px] text-on-surface-variant break-words",children:M.code}):null,de.length>0?i.jsx("dl",{className:"space-y-1 pt-1 font-body text-[12px] text-on-surface",children:de.map(Oe=>i.jsxs("div",{className:"break-words",children:[i.jsxs("dt",{className:"inline font-semibold",children:[Oe.question,": "]}),i.jsx("dd",{className:"inline",children:Oe.answerText})]},Oe.questionId))}):null]})}if(F&&!F.refreshing||g)return i.jsxs("div",{"data-testid":`feed-card-answer-settled-${e}`,className:"w-full space-y-2 border border-outline-variant bg-surface-lowest/55 p-3",children:[Se,i.jsx("p",{"data-testid":`feed-card-answer-settled-headline-${e}`,className:"font-body text-[12px] font-medium leading-relaxed text-on-surface break-words",children:Fje((F==null?void 0:F.refreshedItem)??c,a,F==null?void 0:F.fallbackState)}),ke()]});const Pe=d.getQueryState(["queue","item",t]),Ie=!Y&&!(F!=null&&F.refreshing)&&(q||c!==void 0&&!c.decisionRevision||(Pe==null?void 0:Pe.status)==="error"||(Pe==null?void 0:Pe.status)==="success"&&!((Et=Pe.data)!=null&&Et.decisionRevision)),Nt=h.isPending||!!(F!=null&&F.refreshing)||!Y,_t=F!=null&&F.refreshing?"Refreshing request state...":h.isPending?"Sending...":se?"All answered and recorded. Not sent yet.":(M==null?void 0:M.outcome)==="recorded"?`Recorded. ${te} of ${X} answered. Not sent yet.`:te>0?`${te} of ${X} answered. Not sent yet.`:Ie?"Could not load request state. Answer in the TUI (rig tui) or retry.":Y?X===1?`Your answer goes to ${ie} when answered.`:`Your answers go to ${ie} when all ${X} are answered.`:"Loading request state...",Fn=L!=null&&L.unknown?"Outcome unknown — couldn't confirm whether your answer went through.":(L==null?void 0:L.code)==="answer_not_closed"&&(L==null?void 0:L.source)!=="words"?"Your choices are recorded.":(L==null?void 0:L.source)==="words"?"Not recorded or sent. Your text is still here.":"Answer not recorded.";return i.jsxs("div",{"data-testid":`feed-card-questions-${e}`,className:"w-full space-y-3",children:[Se,i.jsx("div",{className:"space-y-3",children:a.map((de,Oe)=>{const Ve=cf(ee,de.id);return i.jsxs("div",{"data-testid":`feed-card-question-${de.id}`,className:"space-y-1.5",children:[i.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[i.jsxs("p",{id:`feed-card-question-label-${e}-${de.id}`,className:"font-body text-[12px] font-medium leading-relaxed text-on-surface break-words min-w-0",children:[Oe+1,". ",de.question]}),Ve!==void 0?i.jsx("span",{"data-testid":`feed-card-question-answered-${de.id}`,className:"font-mono text-[10px] uppercase tracking-wider text-on-surface-variant shrink-0",children:"answered"}):null]}),i.jsx("div",{role:"group","aria-labelledby":`feed-card-question-label-${e}-${de.id}`,className:"grid grid-cols-1 sm:flex sm:flex-wrap gap-1.5",children:de.options.map(We=>{const mt=Ve===We.id;return i.jsxs("button",{type:"button","data-testid":`feed-card-option-${de.id}-${We.id}`,"data-selected":mt,"aria-pressed":mt,disabled:Nt,onClick:()=>ge("option",`opt:${de.id}:${We.id}:${G??"none"}`,{questionId:de.id,optionId:We.id},ys=>({...ys,[de.id]:We.id})),className:le(ax,"w-full sm:w-auto text-left sm:text-center transition-colors",mt?"bg-primary text-on-primary border-primary":"bg-surface-lowest border-outline hover:bg-surface-high text-on-surface"),children:[mt?"■ ":"",We.label,We.recommended?" · RECOMMENDED":""]},We.id)})}),typeof Ve=="object"&&Ve.kind==="typed-reply"?i.jsxs("p",{className:"font-mono text-[10px] text-on-surface-variant break-words",children:["Answered in your own words: ",Ve.text]}):null]},de.id)})}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{role:"status","aria-live":"polite","data-testid":`feed-card-answer-status-${e}`,className:"font-mono text-[10px] text-on-surface-variant break-words",children:_t}),Ie?i.jsx("button",{type:"button","data-testid":`feed-card-ask-retry-load-${e}`,onClick:()=>void _e({fromLoadRetry:!0}),className:le(ax,"w-full sm:w-auto border-outline bg-surface-lowest text-on-surface hover:bg-surface-high"),children:"Retry loading request state"}):null,M!=null&&M.message?i.jsx("p",{"data-testid":`feed-card-answer-outcome-message-${e}`,className:"font-body text-[11px] leading-relaxed text-on-surface break-words",children:M.message}):null,se?i.jsxs("button",{type:"button","data-testid":`feed-card-send-answers-${e}`,disabled:Nt,onClick:()=>ge("resend",`resend:${G??"none"}`,{}),className:le(ax,"w-full sm:w-auto border-primary bg-primary text-on-primary hover:opacity-90"),children:["Send answers to ",ie]}):null]}),ke(Fn),se?null:R?i.jsxs("div",{"data-testid":`feed-card-own-words-box-${e}`,className:"space-y-2 border border-outline-variant bg-surface-lowest p-2.5",children:[i.jsx("textarea",{"data-testid":`feed-card-own-words-input-${e}`,"aria-label":"Answer in your own words",rows:3,value:A,disabled:Nt,onChange:de=>I(de.target.value),placeholder:"Answer in your own words...",className:"w-full px-2 py-1.5 bg-surface-container-lowest border border-outline font-body text-[12px] text-on-surface focus:outline-none focus:border-primary disabled:opacity-50"}),i.jsx("p",{className:"font-mono text-[10px] text-on-surface-variant break-words",children:"Sends now and closes this request. Questions you haven't answered stay unanswered."}),i.jsxs("div",{className:"flex flex-col min-[360px]:flex-row min-[360px]:justify-end gap-1.5",children:[i.jsx("button",{type:"button","data-testid":`feed-card-own-words-cancel-${e}`,disabled:Nt,onClick:()=>T(!1),className:le(j8,"border border-outline text-on-surface-variant hover:text-on-surface"),children:"Cancel"}),i.jsx("button",{type:"button","data-testid":`feed-card-own-words-send-${e}`,disabled:Nt||A.trim().length===0,onClick:()=>{const de=A.trim();if(!de)return;const Oe=a.find(Ve=>cf(ee,Ve.id)===void 0);ge("words",`words:${de}:${G??"none"}`,{decision:de},Ve=>Oe?{...Ve,[Oe.id]:{kind:"typed-reply",text:de}}:Ve,()=>{T(!1),I("")})},className:le(j8,"bg-primary text-on-primary hover:opacity-90"),children:h.isPending?"Sending...":"Send"})]})]}):i.jsx("div",{children:i.jsx("button",{type:"button","data-testid":`feed-card-own-words-toggle-${e}`,disabled:Nt,onClick:()=>T(!0),className:le(ax,"w-full sm:w-auto py-1.5 border-outline text-on-surface hover:bg-surface-variant"),children:"✎ Answer in your own words"})})]})}function zp({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=ry();return i.jsx("button",{type:"button","data-testid":r??"queue-item-trigger",onClick:()=>a({type:"qitem",data:e}),className:n??"text-left",style:s,children:t})}async function Hje(){const e=await fetch("/api/mission-control/destinations");if(!e.ok)throw new Error(`HTTP ${e.status}`);return e.json()}function Uje(e){return Re({queryKey:["mission-control","destinations"],queryFn:Hje,enabled:e,staleTime:3e4})}const Nu={approve:{label:"Approve",outcomeLabel:"Approved",description:"Accept the work and let it close or continue.",tone:"success",icon:Xu},deny:{label:"Deny",outcomeLabel:"Denied",description:"Reject this request and leave a reason if needed.",tone:"danger",icon:WJ},route:{label:"Route",outcomeLabel:"Routed",description:"Send this to another session for follow-up.",tone:"info",icon:vF},annotate:{label:"Annotate",outcomeLabel:"Annotated",description:"Add context without changing ownership.",tone:"neutral",icon:dJ},hold:{label:"Hold",outcomeLabel:"Held",description:"Pause this item until more context is available.",tone:"warning",icon:IJ},drop:{label:"Drop",outcomeLabel:"Dropped",description:"Remove this item from the active path.",tone:"neutral",icon:QJ},handoff:{label:"Handoff",outcomeLabel:"Handed off",description:"Transfer active ownership to another session.",tone:"info",icon:Mv}};function Vje(e,t="action"){const n=Nu[e];return{label:t==="outcome"?n.outcomeLabel:n.label,tone:n.tone,icon:n.icon}}const Wje=new Set(["approve"]);function Gje(e){return e instanceof Error?e.message:typeof e=="string"?e:"Action failed."}const N8={approve:{idle:"border-success text-success hover:bg-success hover:text-white",active:"border-success bg-success text-white"},deny:{idle:"border-tertiary text-tertiary hover:bg-tertiary hover:text-white",active:"border-tertiary bg-tertiary text-white"},route:{idle:"border-on-surface text-on-surface hover:bg-inverse-surface hover:text-background",active:"border-on-surface bg-inverse-surface text-background"},annotate:{idle:"border-on-surface text-on-surface hover:bg-inverse-surface hover:text-background",active:"border-on-surface bg-inverse-surface text-background"},hold:{idle:"border-warning text-warning hover:bg-warning hover:text-white",active:"border-warning bg-warning text-white"},drop:{idle:"border-on-surface text-on-surface hover:bg-inverse-surface hover:text-background",active:"border-on-surface bg-inverse-surface text-background"},handoff:{idle:"border-on-surface text-on-surface hover:bg-inverse-surface hover:text-background",active:"border-on-surface bg-inverse-surface text-background"}};function Kje({qitemId:e,actorSession:t,bare:n=!1,hostId:s,enabledVerbs:r=[...oW],oneClickVerbs:a,onSettled:o,onOptimisticOutcome:c}){var U;const d=lW(),[h,p]=E.useState(null),[f,g]=E.useState(""),[x,y]=E.useState(!1),[b,_]=E.useState(""),[w,k]=E.useState(""),[N,C]=E.useState(null),R=h==="route"||h==="handoff",T=h==="annotate",A=h==="hold"||h==="drop";function I(){p(null),g(""),y(!1),_(""),k(""),C(null)}function M(K){p(K),g(""),y(!1),_(""),k(""),C(null)}function B(K,Q){const{dest:H,annotationText:W,reasonText:ee}=Q;d.mutate({verb:K,qitemId:e,actorSession:t,destinationSession:H,annotation:W,reason:ee,...s&&s!=="local"?{hostId:s}:{}},{onSuccess:()=>{c==null||c({verb:K,actorSession:t,actedAt:new Date().toISOString(),destinationSession:H??null,reason:ee??null}),I(),o==null||o()},onError:G=>{C(Gje(G))}})}function L(){h&&B(h,{dest:R?f:void 0,annotationText:T?b:void 0,reasonText:A?w:void 0})}function P(K){return!!(a!=null&&a.includes(K))&&Wje.has(K)}const q=Uje(R),$=((U=q.data)==null?void 0:U.destinations)??[],F=R&&q.isLoading,D=R&&($.length>0||F),z=R&&(x||q.isError||q.isFetched&&$.length===0);return i.jsxs("div",{"data-testid":"mc-verb-actions",className:"space-y-2",children:[n?null:i.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2 border border-outline-variant bg-surface-lowest/40 px-2 py-1.5 backdrop-blur-sm",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-mono text-[9px] uppercase tracking-[0.12em] text-on-surface",children:"Choose response"}),i.jsx("div",{className:"mt-0.5 font-mono text-[10px] leading-relaxed text-on-surface-variant",children:"Pick the next move for this queue item."})]}),h?i.jsxs("div",{className:"font-mono text-[9px] uppercase tracking-[0.12em] text-on-surface-variant",children:["Selected: ",i.jsx("span",{className:"text-on-surface",children:Nu[h].label})]}):null]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:r.map(K=>{const Q=Nu[K],H=Q.icon,W=P(K);return i.jsxs("button",{type:"button","data-testid":`mc-verb-${K}`,"data-one-click":W?"true":void 0,onClick:()=>{if(W){C(null),B(K,{});return}M(K)},disabled:d.isPending,title:W?`${Q.description} (records immediately)`:Q.description,className:le("inline-flex min-h-[44px] items-center gap-1 border px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.12em] transition-colors disabled:opacity-50",h===K?N8[K].active:N8[K].idle),children:[i.jsx(H,{className:"h-3 w-3",strokeWidth:1.7}),Q.label]},K)})}),h&&i.jsxs("div",{className:"space-y-1 border border-outline-variant bg-background p-2",children:[i.jsx("div",{"data-testid":"mc-verb-guidance",className:"font-mono text-[10px] leading-relaxed text-on-surface-variant",children:Nu[h].description}),R&&i.jsxs("div",{className:"space-y-1",children:[D?i.jsxs("select",{"data-testid":"mc-verb-destination-select","aria-label":"Destination session",value:x?"__manual__":f,disabled:F,onChange:K=>{if(K.target.value==="__manual__"){y(!0),g("");return}y(!1),g(K.target.value)},className:"w-full border border-outline-variant bg-surface-lowest px-2 py-1 font-mono text-xs",children:[i.jsx("option",{value:"",children:F?"loading destinations...":"choose destination"}),$.map(K=>i.jsx("option",{value:K.sessionName,children:K.label},K.sessionName)),i.jsx("option",{value:"__manual__",children:"manual entry"})]}):null,z?i.jsx("input",{type:"text","data-testid":"mc-verb-destination-input",value:f,onChange:K=>g(K.target.value),placeholder:"destination session (member@rig)",className:"w-full border border-outline-variant px-2 py-1 font-mono text-xs"}):null,q.isError?i.jsx("div",{className:"font-mono text-[10px] text-amber-700",children:"destination list unavailable"}):null]}),T&&i.jsx("textarea",{"data-testid":"mc-verb-annotation-input",value:b,onChange:K=>_(K.target.value),placeholder:"annotation",rows:2,className:"w-full border border-outline-variant px-2 py-1 font-mono text-xs"}),A&&i.jsx("input",{type:"text","data-testid":"mc-verb-reason-input",value:w,onChange:K=>k(K.target.value),placeholder:`${h} reason`,className:"w-full border border-outline-variant px-2 py-1 font-mono text-xs"}),i.jsxs("div",{className:"flex items-center justify-end gap-1",children:[i.jsx("button",{type:"button",onClick:I,"data-testid":"mc-verb-cancel",className:"border border-outline-variant px-2 py-0.5 font-mono text-[9px] uppercase tracking-[0.12em] text-on-surface-variant",children:"Cancel"}),i.jsx("button",{type:"button",onClick:L,"data-testid":"mc-verb-submit",disabled:d.isPending||R&&!f||T&&!b||A&&!w,className:"border border-on-surface bg-inverse-surface px-2 py-0.5 font-mono text-[9px] uppercase tracking-[0.12em] text-background disabled:opacity-50",children:d.isPending?"...":`Confirm ${Nu[h].label}`})]})]}),N?i.jsx("div",{"data-testid":"mc-verb-error",role:"alert",className:"truncate border border-tertiary bg-background/40 px-3 py-2 font-mono text-[10px] uppercase tracking-[0.12em] text-tertiary",title:N,children:N}):null]})}const Yje="user message begins here: ";function Qy(e){return`[review ${e.itemRef}] Standing contract: when this conversation reaches an outcome, record it durably against the referenced item (resolve with the decision text, an adjudication proof-drop, or a routed qitem back to delivery) — a conversation is not a resolution. `+Yje}function Qje({sliceName:e,relPath:t,onClose:n,testId:s="proof-image-viewer",imageTestId:r="proof-image-viewer-image",closeTestId:a="proof-image-viewer-close"}){return t?op.createPortal(i.jsx("div",{role:"dialog","aria-label":"Screenshot preview","data-testid":s,className:"absolute bottom-0 right-0 top-0 z-[1000] flex items-center justify-center bg-stone-950/20 p-6 backdrop-blur-[2px] lg:left-[21rem]",onClick:n,children:i.jsxs("div",{className:"flex max-h-full max-w-[92vw] flex-col border border-white/20 bg-stone-950/70 p-2 backdrop-blur-sm",onClick:o=>o.stopPropagation(),children:[i.jsx("img",{src:UF(e,t),alt:t,"data-testid":r,className:"min-h-0 max-h-[78vh] max-w-full object-contain"}),i.jsxs("div",{className:"mt-2 flex shrink-0 items-center justify-between gap-3 font-mono text-[10px] text-stone-50",children:[i.jsx("span",{className:"truncate",children:t}),i.jsx("button",{type:"button","data-testid":a,onClick:n,className:"inline-flex h-7 w-7 items-center justify-center border border-white/30 text-stone-50 hover:bg-white/10","aria-label":"Close screenshot preview",children:i.jsx(OE,{className:"h-3.5 w-3.5",strokeWidth:1.5})})]})]})}),document.getElementById("shell-content")??document.body):null}const Xje={"action-required":"bg-tertiary",approval:"bg-warning",shipped:"bg-success",progress:"bg-secondary",observation:"bg-outline"},FA={neutral:"bg-outline",info:"bg-secondary",success:"bg-success",warning:"bg-warning",danger:"bg-tertiary"},Zje={"action-required":"feed-card-action",approval:"feed-card-approval",shipped:"feed-card-shipped",progress:"feed-card-progress",observation:"feed-card-observation"},Jje={"action-required":{label:"Action required",tone:"danger",icon:Po},approval:{label:"Needs approval",tone:"warning",icon:Po},shipped:{label:"Shipped",tone:"success",icon:ME},progress:{label:"Progress",tone:"info",icon:Cu},observation:{label:"Observation",tone:"neutral",icon:Rf}},eNe={neutral:"text-on-surface-variant",info:"text-secondary",success:"text-success",warning:"text-warning",danger:"text-tertiary"};function tNe(e,t,n){return e==="action-required"||e==="approval"?t:n??t}const nNe="relative bg-surface-low/45 backdrop-blur-[10px] overflow-hidden group",sNe={boxShadow:["0 2px 4px rgba(0, 0, 0, 0.14)","0 8px 20px rgba(0, 0, 0, 0.16)","0 0 40px rgba(0, 0, 0, 0.12)"].join(", ")};function Mr(e){return typeof e=="string"&&e.length>0?e:void 0}function rNe(e){const t=e.source.payload??{},n=Mr(t.qitem_id)??Mr(t.qitemId);if(!n)return null;const s=t.tags,r=Array.isArray(s)?s.filter(a=>typeof a=="string"):void 0;return{qitemId:n,source:Mr(t.source_session)??Mr(t.sourceSession)??Mr(t.fromSession),destination:Mr(t.destination)??Mr(t.destination_session)??Mr(t.destinationSession)??Mr(t.toSession),state:Mr(t.state),tags:r,createdAt:e.createdAt,body:Mr(t.body)??e.body}}function iNe(e,t){const n=rNe(e);return t?{qitemId:t.qitemId,source:t.sourceSession,destination:t.destinationSession,state:t.state,tags:t.tags??void 0,createdAt:t.tsCreated,body:t.body||(n==null?void 0:n.body)||e.body}:n}function aNe(e){if(!e)return;const t=e.trim();return t.length<=520?t:`${t.slice(0,520).trimEnd()}