@openrig/cli 0.6.12 → 0.6.14
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.
- package/README.md +69 -14
- package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
- package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
- package/daemon/assets/plugins/openrig-core/README.md +9 -2
- package/daemon/assets/plugins/openrig-core/hooks/scripts/activity-relay.cjs +25 -9
- package/daemon/assets/plugins/openrig-core/hooks/scripts/refocus.cjs +7 -4
- package/daemon/assets/plugins/openrig-core/skills/mission-slice-sop/SKILL.md +5 -0
- package/daemon/assets/plugins/openrig-core/skills/openrig-user/SKILL.md +11 -3
- package/daemon/assets/plugins/openrig-core/skills/refocusing/scripts/trace-to-root.py +73 -48
- package/daemon/assets/skills/rigs/SKILL.md +8 -4
- package/daemon/context-packs/help/manifest.yaml +1 -1
- package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
- package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +76 -16
- package/daemon/context-packs/reference/getting-started.md +135 -28
- package/daemon/context-packs/reference/manifest.yaml +1 -1
- package/daemon/context-packs/reference/rig-spec.md +5 -5
- package/daemon/context-packs/reference/whats-new.md +65 -167
- package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
- package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
- package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
- package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
- package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
- package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
- package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
- package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
- package/daemon/context-packs/skills/mission-slice-sop/SKILL.md +5 -0
- package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
- package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
- package/daemon/context-packs/skills/openrig-user/SKILL.md +11 -3
- package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
- package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
- package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
- package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
- package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
- package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
- package/daemon/context-packs/skills/refocusing/scripts/trace-to-root.py +73 -48
- package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
- package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
- package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
- package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
- package/daemon/context-packs/world-example/manifest.yaml +1 -1
- package/daemon/context-packs/world-public/manifest.yaml +1 -1
- package/daemon/dist/adapters/claude-code-adapter.d.ts +9 -1
- package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
- package/daemon/dist/adapters/claude-code-adapter.js +110 -52
- package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
- package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
- package/daemon/dist/adapters/codex-runtime-adapter.js +47 -6
- package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
- package/daemon/dist/adapters/pi-resume.d.ts +1 -1
- package/daemon/dist/adapters/pi-resume.d.ts.map +1 -1
- package/daemon/dist/adapters/pi-resume.js +4 -1
- package/daemon/dist/adapters/pi-resume.js.map +1 -1
- package/daemon/dist/adapters/pi-runner-protocol.d.ts +9 -0
- package/daemon/dist/adapters/pi-runner-protocol.d.ts.map +1 -1
- package/daemon/dist/adapters/pi-runner-protocol.js +16 -0
- package/daemon/dist/adapters/pi-runner-protocol.js.map +1 -1
- package/daemon/dist/adapters/pi-runner.d.ts +5 -2
- package/daemon/dist/adapters/pi-runner.d.ts.map +1 -1
- package/daemon/dist/adapters/pi-runner.js +72 -15
- package/daemon/dist/adapters/pi-runner.js.map +1 -1
- package/daemon/dist/adapters/pi-runtime-adapter.d.ts.map +1 -1
- package/daemon/dist/adapters/pi-runtime-adapter.js +2 -0
- package/daemon/dist/adapters/pi-runtime-adapter.js.map +1 -1
- package/daemon/dist/adapters/stub-compaction.d.ts +1 -0
- package/daemon/dist/adapters/stub-compaction.d.ts.map +1 -1
- package/daemon/dist/adapters/stub-compaction.js +2 -0
- package/daemon/dist/adapters/stub-compaction.js.map +1 -1
- package/daemon/dist/adapters/stub-refocus.d.ts +6 -0
- package/daemon/dist/adapters/stub-refocus.d.ts.map +1 -0
- package/daemon/dist/adapters/stub-refocus.js +22 -0
- package/daemon/dist/adapters/stub-refocus.js.map +1 -0
- package/daemon/dist/adapters/stub-runner.d.ts +6 -0
- package/daemon/dist/adapters/stub-runner.d.ts.map +1 -1
- package/daemon/dist/adapters/stub-runner.js +18 -1
- package/daemon/dist/adapters/stub-runner.js.map +1 -1
- package/daemon/dist/adapters/stub-script.d.ts +2 -2
- package/daemon/dist/adapters/stub-script.d.ts.map +1 -1
- package/daemon/dist/adapters/stub-script.js +2 -2
- package/daemon/dist/adapters/stub-script.js.map +1 -1
- package/daemon/dist/adapters/tmux.js +1 -1
- package/daemon/dist/adapters/tmux.js.map +1 -1
- package/daemon/dist/build-info.js +3 -3
- package/daemon/dist/db/all-migrations.d.ts.map +1 -1
- package/daemon/dist/db/all-migrations.js +2 -0
- package/daemon/dist/db/all-migrations.js.map +1 -1
- package/daemon/dist/db/migrations/117_provider_account_readings.d.ts +3 -0
- package/daemon/dist/db/migrations/117_provider_account_readings.d.ts.map +1 -0
- package/daemon/dist/db/migrations/117_provider_account_readings.js +32 -0
- package/daemon/dist/db/migrations/117_provider_account_readings.js.map +1 -0
- package/daemon/dist/domain/claim-service.d.ts +9 -18
- package/daemon/dist/domain/claim-service.d.ts.map +1 -1
- package/daemon/dist/domain/claim-service.js +83 -0
- package/daemon/dist/domain/claim-service.js.map +1 -1
- package/daemon/dist/domain/claude-activity-hooks.d.ts +6 -0
- package/daemon/dist/domain/claude-activity-hooks.d.ts.map +1 -1
- package/daemon/dist/domain/claude-activity-hooks.js +19 -1
- package/daemon/dist/domain/claude-activity-hooks.js.map +1 -1
- package/daemon/dist/domain/claude-compaction-enforcer.d.ts +2 -2
- package/daemon/dist/domain/claude-compaction-enforcer.d.ts.map +1 -1
- package/daemon/dist/domain/claude-compaction-enforcer.js +20 -14
- package/daemon/dist/domain/claude-compaction-enforcer.js.map +1 -1
- package/daemon/dist/domain/claude-core-plugin-env.d.ts +2 -0
- package/daemon/dist/domain/claude-core-plugin-env.d.ts.map +1 -1
- package/daemon/dist/domain/claude-core-plugin-env.js +6 -2
- package/daemon/dist/domain/claude-core-plugin-env.js.map +1 -1
- package/daemon/dist/domain/claude-managed-launch.d.ts +5 -0
- package/daemon/dist/domain/claude-managed-launch.d.ts.map +1 -1
- package/daemon/dist/domain/claude-managed-launch.js +48 -7
- package/daemon/dist/domain/claude-managed-launch.js.map +1 -1
- package/daemon/dist/domain/claude-mcp-menu.d.ts +5 -0
- package/daemon/dist/domain/claude-mcp-menu.d.ts.map +1 -0
- package/daemon/dist/domain/claude-mcp-menu.js +25 -0
- package/daemon/dist/domain/claude-mcp-menu.js.map +1 -0
- package/daemon/dist/domain/fresh-occupant-relation.d.ts +7 -0
- package/daemon/dist/domain/fresh-occupant-relation.d.ts.map +1 -1
- package/daemon/dist/domain/fresh-occupant-relation.js +45 -0
- package/daemon/dist/domain/fresh-occupant-relation.js.map +1 -1
- package/daemon/dist/domain/gateway/slack/channel-recovery.d.ts +14 -2
- package/daemon/dist/domain/gateway/slack/channel-recovery.d.ts.map +1 -1
- package/daemon/dist/domain/gateway/slack/channel-recovery.js +128 -89
- package/daemon/dist/domain/gateway/slack/channel-recovery.js.map +1 -1
- package/daemon/dist/domain/gateway/slack/inbound.d.ts +4 -0
- package/daemon/dist/domain/gateway/slack/inbound.d.ts.map +1 -1
- package/daemon/dist/domain/gateway/slack/inbound.js +5 -3
- package/daemon/dist/domain/gateway/slack/inbound.js.map +1 -1
- package/daemon/dist/domain/gateway/slack/recovery-budget.d.ts +24 -0
- package/daemon/dist/domain/gateway/slack/recovery-budget.d.ts.map +1 -0
- package/daemon/dist/domain/gateway/slack/recovery-budget.js +18 -0
- package/daemon/dist/domain/gateway/slack/recovery-budget.js.map +1 -0
- package/daemon/dist/domain/gateway/slack/slack-recovery.d.ts +104 -0
- package/daemon/dist/domain/gateway/slack/slack-recovery.d.ts.map +1 -0
- package/daemon/dist/domain/gateway/slack/slack-recovery.js +236 -0
- package/daemon/dist/domain/gateway/slack/slack-recovery.js.map +1 -0
- package/daemon/dist/domain/gateway/slack/slack-subsystem.d.ts.map +1 -1
- package/daemon/dist/domain/gateway/slack/slack-subsystem.js +29 -6
- package/daemon/dist/domain/gateway/slack/slack-subsystem.js.map +1 -1
- package/daemon/dist/domain/gateway/slack/state-store.d.ts +34 -0
- package/daemon/dist/domain/gateway/slack/state-store.d.ts.map +1 -1
- package/daemon/dist/domain/gateway/slack/state-store.js +67 -0
- package/daemon/dist/domain/gateway/slack/state-store.js.map +1 -1
- package/daemon/dist/domain/gateway/slack/thread-recovery.d.ts +37 -0
- package/daemon/dist/domain/gateway/slack/thread-recovery.d.ts.map +1 -0
- package/daemon/dist/domain/gateway/slack/thread-recovery.js +173 -0
- package/daemon/dist/domain/gateway/slack/thread-recovery.js.map +1 -0
- package/daemon/dist/domain/gateway/slack/thread-seat-map.d.ts +8 -0
- package/daemon/dist/domain/gateway/slack/thread-seat-map.d.ts.map +1 -1
- package/daemon/dist/domain/gateway/slack/thread-seat-map.js +11 -0
- package/daemon/dist/domain/gateway/slack/thread-seat-map.js.map +1 -1
- package/daemon/dist/domain/model-divergence/current-generation-record.d.ts +6 -1
- package/daemon/dist/domain/model-divergence/current-generation-record.d.ts.map +1 -1
- package/daemon/dist/domain/model-divergence/current-generation-record.js +4 -1
- package/daemon/dist/domain/model-divergence/current-generation-record.js.map +1 -1
- package/daemon/dist/domain/model-divergence/current-model-reader.d.ts +74 -0
- package/daemon/dist/domain/model-divergence/current-model-reader.d.ts.map +1 -0
- package/daemon/dist/domain/model-divergence/current-model-reader.js +246 -0
- package/daemon/dist/domain/model-divergence/current-model-reader.js.map +1 -0
- package/daemon/dist/domain/model-divergence/effective-model-readers.d.ts +18 -0
- package/daemon/dist/domain/model-divergence/effective-model-readers.d.ts.map +1 -1
- package/daemon/dist/domain/model-divergence/effective-model-readers.js +24 -8
- package/daemon/dist/domain/model-divergence/effective-model-readers.js.map +1 -1
- package/daemon/dist/domain/native-process-lineage.d.ts +8 -1
- package/daemon/dist/domain/native-process-lineage.d.ts.map +1 -1
- package/daemon/dist/domain/native-process-lineage.js +40 -26
- package/daemon/dist/domain/native-process-lineage.js.map +1 -1
- package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
- package/daemon/dist/domain/native-resume-probe.js +34 -8
- package/daemon/dist/domain/native-resume-probe.js.map +1 -1
- package/daemon/dist/domain/node-inventory.d.ts +1 -1
- package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
- package/daemon/dist/domain/node-inventory.js +84 -18
- package/daemon/dist/domain/node-inventory.js.map +1 -1
- package/daemon/dist/domain/process-census.d.ts +1 -1
- package/daemon/dist/domain/process-census.d.ts.map +1 -1
- package/daemon/dist/domain/process-table.d.ts +26 -0
- package/daemon/dist/domain/process-table.d.ts.map +1 -0
- package/daemon/dist/domain/process-table.js +185 -0
- package/daemon/dist/domain/process-table.js.map +1 -0
- package/daemon/dist/domain/profile-resolver.d.ts +8 -0
- package/daemon/dist/domain/profile-resolver.d.ts.map +1 -1
- package/daemon/dist/domain/profile-resolver.js +11 -0
- package/daemon/dist/domain/profile-resolver.js.map +1 -1
- package/daemon/dist/domain/projection-planner.js +1 -1
- package/daemon/dist/domain/projection-planner.js.map +1 -1
- package/daemon/dist/domain/provider/claude-usage-windows.d.ts +3 -1
- package/daemon/dist/domain/provider/claude-usage-windows.d.ts.map +1 -1
- package/daemon/dist/domain/provider/claude-usage-windows.js +48 -3
- package/daemon/dist/domain/provider/claude-usage-windows.js.map +1 -1
- package/daemon/dist/domain/provider/codex-usage-reader.d.ts +4 -1
- package/daemon/dist/domain/provider/codex-usage-reader.d.ts.map +1 -1
- package/daemon/dist/domain/provider/codex-usage-reader.js +3 -0
- package/daemon/dist/domain/provider/codex-usage-reader.js.map +1 -1
- package/daemon/dist/domain/provider/codex-usage-windows.d.ts +3 -1
- package/daemon/dist/domain/provider/codex-usage-windows.d.ts.map +1 -1
- package/daemon/dist/domain/provider/codex-usage-windows.js +1 -0
- package/daemon/dist/domain/provider/codex-usage-windows.js.map +1 -1
- package/daemon/dist/domain/provider/provider-account-readings.d.ts +42 -0
- package/daemon/dist/domain/provider/provider-account-readings.d.ts.map +1 -0
- package/daemon/dist/domain/provider/provider-account-readings.js +132 -0
- package/daemon/dist/domain/provider/provider-account-readings.js.map +1 -0
- package/daemon/dist/domain/provider/provider-types.d.ts +29 -0
- package/daemon/dist/domain/provider/provider-types.d.ts.map +1 -1
- package/daemon/dist/domain/provider/usage-across-hosts.d.ts.map +1 -1
- package/daemon/dist/domain/provider/usage-across-hosts.js +6 -0
- package/daemon/dist/domain/provider/usage-across-hosts.js.map +1 -1
- package/daemon/dist/domain/provider/usage-windows.d.ts +25 -0
- package/daemon/dist/domain/provider/usage-windows.d.ts.map +1 -1
- package/daemon/dist/domain/provider/usage-windows.js +100 -4
- package/daemon/dist/domain/provider/usage-windows.js.map +1 -1
- package/daemon/dist/domain/queue-repository.d.ts +23 -0
- package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
- package/daemon/dist/domain/queue-repository.js +59 -1
- package/daemon/dist/domain/queue-repository.js.map +1 -1
- package/daemon/dist/domain/queue-stuck-sweep.d.ts.map +1 -1
- package/daemon/dist/domain/queue-stuck-sweep.js +47 -4
- package/daemon/dist/domain/queue-stuck-sweep.js.map +1 -1
- package/daemon/dist/domain/restore-check-service.d.ts +10 -0
- package/daemon/dist/domain/restore-check-service.d.ts.map +1 -1
- package/daemon/dist/domain/restore-check-service.js +73 -10
- package/daemon/dist/domain/restore-check-service.js.map +1 -1
- package/daemon/dist/domain/restore-guidance.d.ts +6 -0
- package/daemon/dist/domain/restore-guidance.d.ts.map +1 -1
- package/daemon/dist/domain/restore-guidance.js +21 -5
- package/daemon/dist/domain/restore-guidance.js.map +1 -1
- package/daemon/dist/domain/restore-orchestrator.js +1 -1
- package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
- package/daemon/dist/domain/resume-metadata-refresher.d.ts.map +1 -1
- package/daemon/dist/domain/resume-metadata-refresher.js +6 -29
- package/daemon/dist/domain/resume-metadata-refresher.js.map +1 -1
- package/daemon/dist/domain/rig-repository.d.ts +3 -0
- package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
- package/daemon/dist/domain/rig-repository.js +6 -0
- package/daemon/dist/domain/rig-repository.js.map +1 -1
- package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
- package/daemon/dist/domain/rigspec-instantiator.js +4 -2
- package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
- package/daemon/dist/domain/rigspec-preflight.d.ts +4 -0
- package/daemon/dist/domain/rigspec-preflight.d.ts.map +1 -1
- package/daemon/dist/domain/rigspec-preflight.js +12 -2
- package/daemon/dist/domain/rigspec-preflight.js.map +1 -1
- package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
- package/daemon/dist/domain/rigspec-schema.js +11 -0
- package/daemon/dist/domain/rigspec-schema.js.map +1 -1
- package/daemon/dist/domain/runtime-adapter.d.ts +13 -0
- package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
- package/daemon/dist/domain/runtime-adapter.js.map +1 -1
- package/daemon/dist/domain/seat-attention-reconciler.d.ts.map +1 -1
- package/daemon/dist/domain/seat-attention-reconciler.js +15 -1
- package/daemon/dist/domain/seat-attention-reconciler.js.map +1 -1
- package/daemon/dist/domain/seat-cwd-preparation.d.ts +22 -0
- package/daemon/dist/domain/seat-cwd-preparation.d.ts.map +1 -0
- package/daemon/dist/domain/seat-cwd-preparation.js +107 -0
- package/daemon/dist/domain/seat-cwd-preparation.js.map +1 -0
- package/daemon/dist/domain/seat-effort.d.ts +4 -3
- package/daemon/dist/domain/seat-effort.d.ts.map +1 -1
- package/daemon/dist/domain/seat-effort.js +21 -3
- package/daemon/dist/domain/seat-effort.js.map +1 -1
- package/daemon/dist/domain/seat-lifecycle-service.d.ts +36 -2
- package/daemon/dist/domain/seat-lifecycle-service.d.ts.map +1 -1
- package/daemon/dist/domain/seat-lifecycle-service.js +206 -15
- package/daemon/dist/domain/seat-lifecycle-service.js.map +1 -1
- package/daemon/dist/domain/seat-restart-in-place.d.ts +14 -0
- package/daemon/dist/domain/seat-restart-in-place.d.ts.map +1 -1
- package/daemon/dist/domain/seat-restart-in-place.js +59 -3
- package/daemon/dist/domain/seat-restart-in-place.js.map +1 -1
- package/daemon/dist/domain/seat-status-service.d.ts +2 -0
- package/daemon/dist/domain/seat-status-service.d.ts.map +1 -1
- package/daemon/dist/domain/seat-status-service.js +1 -0
- package/daemon/dist/domain/seat-status-service.js.map +1 -1
- package/daemon/dist/domain/seat-structural-activity-service.d.ts +7 -1
- package/daemon/dist/domain/seat-structural-activity-service.d.ts.map +1 -1
- package/daemon/dist/domain/seat-structural-activity-service.js +9 -3
- package/daemon/dist/domain/seat-structural-activity-service.js.map +1 -1
- package/daemon/dist/domain/session-name.d.ts +8 -0
- package/daemon/dist/domain/session-name.d.ts.map +1 -1
- package/daemon/dist/domain/session-name.js +12 -0
- package/daemon/dist/domain/session-name.js.map +1 -1
- package/daemon/dist/domain/session-transport.d.ts +78 -3
- package/daemon/dist/domain/session-transport.d.ts.map +1 -1
- package/daemon/dist/domain/session-transport.js +306 -15
- package/daemon/dist/domain/session-transport.js.map +1 -1
- package/daemon/dist/domain/successor-session-launcher.js +1 -1
- package/daemon/dist/domain/successor-session-launcher.js.map +1 -1
- package/daemon/dist/domain/topology-converge.d.ts +1 -0
- package/daemon/dist/domain/topology-converge.d.ts.map +1 -1
- package/daemon/dist/domain/topology-converge.js +1 -0
- package/daemon/dist/domain/topology-converge.js.map +1 -1
- package/daemon/dist/domain/types.d.ts +14 -0
- package/daemon/dist/domain/types.d.ts.map +1 -1
- package/daemon/dist/domain/types.js.map +1 -1
- package/daemon/dist/domain/user-settings/settings-store.d.ts +1 -1
- package/daemon/dist/domain/user-settings/settings-store.d.ts.map +1 -1
- package/daemon/dist/domain/user-settings/settings-store.js +4 -0
- package/daemon/dist/domain/user-settings/settings-store.js.map +1 -1
- package/daemon/dist/domain/wake-resolve-service.d.ts +1 -0
- package/daemon/dist/domain/wake-resolve-service.d.ts.map +1 -1
- package/daemon/dist/domain/wake-resolve-service.js +10 -0
- package/daemon/dist/domain/wake-resolve-service.js.map +1 -1
- package/daemon/dist/domain/wake-resolver.d.ts.map +1 -1
- package/daemon/dist/domain/wake-resolver.js +7 -0
- package/daemon/dist/domain/wake-resolver.js.map +1 -1
- package/daemon/dist/domain/watchdog-delivery.d.ts +29 -0
- package/daemon/dist/domain/watchdog-delivery.d.ts.map +1 -0
- package/daemon/dist/domain/watchdog-delivery.js +113 -0
- package/daemon/dist/domain/watchdog-delivery.js.map +1 -0
- package/daemon/dist/domain/watchdog-policy-engine.d.ts +60 -1
- package/daemon/dist/domain/watchdog-policy-engine.d.ts.map +1 -1
- package/daemon/dist/domain/watchdog-policy-engine.js +154 -28
- package/daemon/dist/domain/watchdog-policy-engine.js.map +1 -1
- package/daemon/dist/domain/watchdog-scheduler.d.ts.map +1 -1
- package/daemon/dist/domain/watchdog-scheduler.js +6 -1
- package/daemon/dist/domain/watchdog-scheduler.js.map +1 -1
- package/daemon/dist/domain/workflow-instance-store.d.ts.map +1 -1
- package/daemon/dist/domain/workflow-instance-store.js +6 -2
- package/daemon/dist/domain/workflow-instance-store.js.map +1 -1
- package/daemon/dist/routes/attention.d.ts.map +1 -1
- package/daemon/dist/routes/attention.js +41 -1
- package/daemon/dist/routes/attention.js.map +1 -1
- package/daemon/dist/routes/compaction.js +1 -1
- package/daemon/dist/routes/compaction.js.map +1 -1
- package/daemon/dist/routes/queue.d.ts.map +1 -1
- package/daemon/dist/routes/queue.js +3 -1
- package/daemon/dist/routes/queue.js.map +1 -1
- package/daemon/dist/routes/restore-check.d.ts.map +1 -1
- package/daemon/dist/routes/restore-check.js +19 -1
- package/daemon/dist/routes/restore-check.js.map +1 -1
- package/daemon/dist/routes/seat.d.ts.map +1 -1
- package/daemon/dist/routes/seat.js +15 -2
- package/daemon/dist/routes/seat.js.map +1 -1
- package/daemon/dist/routes/sessions.d.ts.map +1 -1
- package/daemon/dist/routes/sessions.js +42 -1
- package/daemon/dist/routes/sessions.js.map +1 -1
- package/daemon/dist/routes/transport.d.ts.map +1 -1
- package/daemon/dist/routes/transport.js +13 -2
- package/daemon/dist/routes/transport.js.map +1 -1
- package/daemon/dist/server.d.ts +1 -0
- package/daemon/dist/server.d.ts.map +1 -1
- package/daemon/dist/server.js +7 -4
- package/daemon/dist/server.js.map +1 -1
- package/daemon/dist/startup.d.ts.map +1 -1
- package/daemon/dist/startup.js +41 -118
- package/daemon/dist/startup.js.map +1 -1
- package/daemon/docs/reference/agent-spec.md +1 -1
- package/daemon/docs/reference/agent-startup-guide.md +84 -0
- package/daemon/docs/reference/getting-started.md +135 -28
- package/daemon/docs/reference/publishing-a-rig-bundle.md +5 -2
- package/daemon/docs/reference/quickstart.md +187 -0
- package/daemon/docs/reference/refocus-channel.md +11 -1
- package/daemon/docs/reference/rig-spec.md +5 -5
- package/daemon/docs/reference/rosters.md +29 -2
- package/daemon/docs/reference/slack-app-setup.md +47 -17
- package/daemon/docs/reference/whats-new.md +65 -167
- package/daemon/specs/agents/apps/vault-specialist/agent.yaml +1 -0
- package/daemon/specs/agents/conveyor/builder/agent.yaml +1 -0
- package/daemon/specs/agents/conveyor/lead/agent.yaml +1 -0
- package/daemon/specs/agents/conveyor/planner/agent.yaml +1 -0
- package/daemon/specs/agents/conveyor/reviewer/agent.yaml +1 -0
- package/daemon/specs/agents/design/product-designer/agent.yaml +1 -0
- package/daemon/specs/agents/development/implementer/agent.yaml +1 -0
- package/daemon/specs/agents/development/qa/agent.yaml +1 -0
- package/daemon/specs/agents/factory-rsi/dogfood/agent.yaml +1 -0
- package/daemon/specs/agents/factory-rsi/release-manager/agent.yaml +1 -0
- package/daemon/specs/agents/orchestration/orchestrator/agent.yaml +1 -0
- package/daemon/specs/agents/product-management/pm/agent.yaml +1 -0
- package/daemon/specs/agents/research/analyst/agent.yaml +1 -0
- package/daemon/specs/agents/research/synthesizer/agent.yaml +1 -0
- package/daemon/specs/agents/review/independent-reviewer/agent.yaml +1 -0
- package/dist/build-info.js +3 -3
- package/dist/client.d.ts +7 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +28 -0
- package/dist/client.js.map +1 -1
- package/dist/commands/ask.d.ts.map +1 -1
- package/dist/commands/ask.js +13 -3
- package/dist/commands/ask.js.map +1 -1
- package/dist/commands/capture.d.ts.map +1 -1
- package/dist/commands/capture.js +14 -0
- package/dist/commands/capture.js.map +1 -1
- package/dist/commands/chatroom.d.ts.map +1 -1
- package/dist/commands/chatroom.js +1 -0
- package/dist/commands/chatroom.js.map +1 -1
- package/dist/commands/compact.d.ts.map +1 -1
- package/dist/commands/compact.js +5 -4
- package/dist/commands/compact.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +4 -2
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +47 -23
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/grow.d.ts.map +1 -1
- package/dist/commands/grow.js +24 -7
- package/dist/commands/grow.js.map +1 -1
- package/dist/commands/provider.d.ts.map +1 -1
- package/dist/commands/provider.js +43 -7
- package/dist/commands/provider.js.map +1 -1
- package/dist/commands/ps.d.ts +2 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +12 -1
- package/dist/commands/ps.js.map +1 -1
- package/dist/commands/reconcile-session.d.ts.map +1 -1
- package/dist/commands/reconcile-session.js +25 -4
- package/dist/commands/reconcile-session.js.map +1 -1
- package/dist/commands/remove.d.ts.map +1 -1
- package/dist/commands/remove.js +20 -1
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/roster.d.ts +2 -1
- package/dist/commands/roster.d.ts.map +1 -1
- package/dist/commands/roster.js +10 -5
- package/dist/commands/roster.js.map +1 -1
- package/dist/commands/scope.js +1 -1
- package/dist/commands/scope.js.map +1 -1
- package/dist/commands/seat.d.ts.map +1 -1
- package/dist/commands/seat.js +75 -8
- package/dist/commands/seat.js.map +1 -1
- package/dist/commands/slack.d.ts.map +1 -1
- package/dist/commands/slack.js +14 -1
- package/dist/commands/slack.js.map +1 -1
- package/dist/commands/ui.d.ts.map +1 -1
- package/dist/commands/ui.js +8 -1
- package/dist/commands/ui.js.map +1 -1
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +4 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/config-store.d.ts +2 -1
- package/dist/config-store.d.ts.map +1 -1
- package/dist/config-store.js +5 -0
- package/dist/config-store.js.map +1 -1
- package/dist/daemon-lifecycle.d.ts.map +1 -1
- package/dist/daemon-lifecycle.js +11 -3
- package/dist/daemon-lifecycle.js.map +1 -1
- package/dist/front-door.d.ts.map +1 -1
- package/dist/front-door.js +3 -1
- package/dist/front-door.js.map +1 -1
- package/dist/lib/model-observation.d.ts +13 -0
- package/dist/lib/model-observation.d.ts.map +1 -0
- package/dist/lib/model-observation.js +25 -0
- package/dist/lib/model-observation.js.map +1 -0
- package/dist/local-daemon-owner.d.ts +28 -0
- package/dist/local-daemon-owner.d.ts.map +1 -0
- package/dist/local-daemon-owner.js +98 -0
- package/dist/local-daemon-owner.js.map +1 -0
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +1 -0
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/tui/dist/attention/attention-model.js +6 -5
- package/tui/dist/attention/attention-model.js.map +1 -1
- package/tui/dist/attention/source-continuity.d.ts.map +1 -1
- package/tui/dist/attention/source-continuity.js +2 -0
- package/tui/dist/attention/source-continuity.js.map +1 -1
- package/tui/dist/terminals/open-window.d.ts +11 -1
- package/tui/dist/terminals/open-window.d.ts.map +1 -1
- package/tui/dist/terminals/open-window.js +47 -2
- package/tui/dist/terminals/open-window.js.map +1 -1
- package/tui/dist/usage/usage-model.d.ts +2 -0
- package/tui/dist/usage/usage-model.d.ts.map +1 -1
- package/tui/dist/usage/usage-model.js +38 -3
- package/tui/dist/usage/usage-model.js.map +1 -1
- package/ui/dist/assets/{index-Cfbtfd9G.js → index-CVgod3Pm.js} +1 -1
- package/ui/dist/index.html +1 -1
|
@@ -583,7 +583,7 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
|
|
|
583
583
|
|
|
584
584
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
585
585
|
|
|
586
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return C.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},H_e="DialogDescriptionWarning",U_e=({contentRef:e,descriptionId:t})=>{const s=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${TV(H_e).contentName}}.`;return C.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},V_e=gV,W_e=vV,G_e=bV,AV=_V,IV=wV,MV=jV,LV=kV,K_e=EV;const Dy=V_e,Y_e=W_e,Q_e=G_e,OV=C.forwardRef(({className:e,...t},n)=>i.jsx(AV,{ref:n,className:ce("fixed inset-0 z-50 bg-black/20 backdrop-blur-[8px]",e),...t}));OV.displayName=AV.displayName;const Ep=C.forwardRef(({className:e,children:t,hideCloseButton:n,...s},r)=>i.jsxs(Q_e,{children:[i.jsx(OV,{}),i.jsxs(IV,{ref:r,className:ce("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(K_e,{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(CE,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ep.displayName=IV.displayName;const $y=({className:e,...t})=>i.jsx("div",{className:ce("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});$y.displayName="DialogHeader";const By=({className:e,...t})=>i.jsx("div",{className:ce("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});By.displayName="DialogFooter";const Rp=C.forwardRef(({className:e,...t},n)=>i.jsx(MV,{ref:n,className:ce("text-lg font-semibold leading-none tracking-tight",e),...t}));Rp.displayName=MV.displayName;const Tp=C.forwardRef(({className:e,...t},n)=>i.jsx(LV,{ref:n,className:ce("text-sm text-foreground-muted",e),...t}));Tp.displayName=LV.displayName;function X_e(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 Z_e(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 J_e(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 ewe(e){const t=mt();return Ht({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 twe(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 nwe(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return e.toUpperCase()}}function swe({installId:e}){const{data:t,isPending:n,isError:s}=J_e(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 rwe({install:e,onRollback:t}){const[n,s]=C.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:ce("inline-block px-spacing-2 py-px text-label-sm uppercase",twe(e.status)),children:nwe(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(Se,{variant:"tactical",size:"sm","data-testid":"expand-btn",onClick:()=>s(!n),children:n?"COLLAPSE":"EXPAND"}),e.status==="applied"&&i.jsx(Se,{variant:"tactical",size:"sm","data-testid":"rollback-btn",onClick:()=>t(e.id),children:"ROLLBACK"})]})]}),n&&i.jsx(swe,{installId:e.id})]})}function iwe(){var b;const{packageId:e}=An({strict:!1}),{data:t,isPending:n,error:s}=X_e(e),{data:r,isPending:a,error:o}=Z_e(e),c=ewe(e),[d,h]=C.useState(null),[m,f]=C.useState(!1),g=_=>{h(_),f(!0)},x=()=>{d&&c.mutate(d,{onSuccess:()=>{f(!1),h(null)}})};if(n||a)return i.jsx(ot,{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(ot,{children:i.jsx("div",{"data-testid":"detail-error",children:i.jsx("p",{className:"text-destructive",children:s.message})})});if(o)return i.jsx(ot,{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(ot,{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(rwe,{install:_,onRollback:g},_.id))}),i.jsx(Dy,{open:m,onOpenChange:_=>{c.isPending||(f(_),_||c.reset())},children:i.jsxs(Ep,{"data-testid":"rollback-dialog",onPointerDownOutside:_=>{c.isPending&&_.preventDefault()},onEscapeKeyDown:_=>{c.isPending&&_.preventDefault()},hideCloseButton:c.isPending,children:[i.jsxs($y,{children:[i.jsx(Rp,{className:"text-headline-md uppercase",children:"CONFIRM ROLLBACK"}),i.jsx(Tp,{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(By,{children:[i.jsx(Se,{variant:"ghost",onClick:()=>{c.reset(),f(!1)},"data-testid":"rollback-cancel",disabled:c.isPending,children:"CANCEL"}),i.jsx(Se,{variant:"destructive",onClick:x,"data-testid":"rollback-confirm",disabled:c.isPending,children:c.isPending?"ROLLING BACK...":"ROLLBACK"})]})]})})]})})}function awe(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 owe(e){switch(e){case"installed":return"OK";case"missing":return"MISSING";case"unsupported":return"MANUAL";case"unknown":return"UNKNOWN";default:return e.toUpperCase()}}function lwe({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:ce("w-2 h-2 shrink-0",awe(t.status))}),i.jsx("span",{"data-testid":"requirement-status",className:"w-16 uppercase",children:owe(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 PV(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 cwe(){return Ht({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(PV(n,t.status));throw s.data=n,s}return t.json()}})}function uwe(){const e=mt();return Ht({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(PV(a,r.status));throw o.data=a,o}return a},onSuccess:()=>{e.invalidateQueries({queryKey:["rigs","summary"]})}})}const dwe=["ENTER","PLAN","REVIEW","APPLY"],hwe=dwe.map((e,t)=>({num:t+1,label:e}));function fwe(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=Pt(),{bootstrapSourceRef:t,setBootstrapSourceRef:n}=op(),[s,r]=C.useState("enter"),[a,o]=C.useState(()=>t),[c,d]=C.useState(null),[h,m]=C.useState(new Set),[f,g]=C.useState(!1),[x,y]=C.useState(null),b=cwe(),_=uwe();C.useEffect(()=>{n(a)},[n,a]);const w=async()=>{if(a.trim()){r("planning");try{const q=await b.mutateAsync({sourceRef:a.trim()});d(q),m(new Set(q.actionKeys??[])),r("planned")}catch(q){y(q.message),r("error")}}},E=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),m(new Set),g(!1),y(null),b.reset(),_.reset()},k=c==null?void 0:c.stages.find(q=>q.stage==="probe_requirements"),R=k==null?void 0:k.detail,A=(R==null?void 0:R.results)??[],T=c==null?void 0:c.stages.find(q=>q.stage==="build_install_plan"),I=T==null?void 0:T.detail,M=(I==null?void 0:I.actions)??[],P=(T==null?void 0:T.status)==="blocked",D=M.some(q=>q.classification!=="manual_only"&&q.commandPreview)&&h.size===0&&!f;return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"bootstrap-wizard",className:"space-y-8",children:[i.jsx(wn,{eyebrow:"Bootstrap",title:"Bootstrap",description:"Plan environment requirements, approve install actions, then import the rig into a running topology."}),i.jsx(ZU,{"data-testid":"step-indicator",steps:hwe,currentStep:fwe(s)}),s==="enter"&&i.jsx(or,{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(_T,{"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(Se,{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(or,{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))}),A.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(lwe,{results:A})})]}),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:B=>{const F=new Set(h);B.target.checked?F.add(q.key):F.delete(q.key),m(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"]})]}),P&&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,B)=>i.jsx("div",{className:"text-warning text-label-sm",children:q},B))}),i.jsx(Se,{variant:"tactical",onClick:E,disabled:P||D,title:P?"Manual requirements must be resolved":D?"Select actions to approve":void 0,"data-testid":"apply-btn",children:"APPLY"})]})}),s==="applying"&&c&&i.jsx(or,{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(or,{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(Se,{variant:"tactical","data-testid":"view-rig-btn",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:c.rigId}}),children:"VIEW RIG"})]})}),s==="error"&&i.jsx(or,{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(Se,{variant:"tactical",onClick:N,"data-testid":"try-again-btn",children:"TRY AGAIN"})]})})]})})}function mwe(){const{currentAgentDraft:e,selectedAgentDraft:t,saveAgentDraft:n,rememberAgentDraft:s,clearSelectedAgentDraft:r}=op(),[a,o]=C.useState(()=>(t==null?void 0:t.yaml)??(e==null?void 0:e.yaml)??""),[c,d]=C.useState("idle"),[h,m]=C.useState([]);C.useEffect(()=>{n(a)},[n,a]),C.useEffect(()=>{t&&(o(t.yaml),r())},[r,t]);const f=async()=>{s(a),d("pending"),m([]);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}m(x.errors??["Validation failed"]),d("invalid")}catch{m(["Validation request failed"]),d("error")}};return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-validate-flow",className:"space-y-8",children:[i.jsx(wn,{eyebrow:"Agent Spec Validation",title:"VALIDATE AGENT",description:"Check an AgentSpec before you use it in a rig."}),i.jsxs(or,{title:"Agent YAML",description:"Paste or refine an AgentSpec draft, then validate it against the daemon contract.",children:[i.jsx(wT,{"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(Se,{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(Xn,{className:"mt-spacing-1","data-testid":"agent-spec-valid",children:i.jsx(qn,{className:"text-primary",children:"AgentSpec valid."})}),(c==="invalid"||c==="error")&&i.jsx(Xn,{className:"mt-spacing-1","data-testid":"agent-spec-invalid",children:i.jsx(qn,{children:i.jsx("ul",{className:"list-disc pl-5",children:h.map(g=>i.jsx("li",{children:g},g))})})})]})]})})}async function gwe(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 xwe(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 DV(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t}function vwe(e,t="draft"){return Re({queryKey:["spec-review","rig",e?DV(e):null,t],queryFn:()=>gwe(e,t),enabled:!!e})}function ywe(e,t="draft"){return Re({queryKey:["spec-review","agent",e?DV(e):null,t],queryFn:()=>xwe(e,t),enabled:!!e})}const bwe=160,_we=48,t8=200,wwe=100;function Swe(e){switch(e){case"claude-code":return"#d4c4a8";case"codex":return"#b8c9d4";case"terminal":return"#c4c4c4";default:return"#e0ddd4"}}function jwe(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*t8,y:r})}),r+=wwe;return n.forEach((a,o)=>{s.push({id:a.id,x:o*t8,y:r})}),s}function Nwe({graph:e,testId:t}){const n=e??{nodes:[],edges:[]},{nodes:s,edges:r}=C.useMemo(()=>{const a=jwe(n.nodes),o=new Map(a.map(h=>[h.id,h])),c=n.nodes.map(h=>{const m=o.get(h.id)??{x:0,y:0};return{id:h.id,type:"default",position:{x:m.x,y:m.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(Cs,{runtime:h.runtime,size:"xs",compact:!0,variant:"inline"})]})},style:{backgroundColor:Swe(h.runtime),border:"1px solid #8a8577",fontSize:11,fontFamily:"monospace",width:bwe,height:_we}}}),d=n.edges.map((h,m)=>({id:`e-${m}`,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(gp,{nodes:s,edges:r,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(IR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(xp,{showInteractive:!1})]})})}function kwe({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=Kv();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 Cwe(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 kT({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]=C.useState("topology"),m=(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(Nwe,{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"&&m.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(E=>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:E.id}),a&&i.jsx(Se,{variant:"outline",size:"sm","data-testid":`${x}member-open-agent-${w.id}-${E.id}`,className:"h-6 px-2 font-mono text-[9px] uppercase tracking-[0.12em]",onClick:()=>a(w.id,E),children:"Agent Spec"})]})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:(()=>{const N=Cwe(E.agentRef);return i.jsx(kwe,{data:{specKind:"agent",specName:N.specName,source:N.source},testId:`${x}member-sub-spec-${w.id}-${E.id}`,className:"text-on-surface-variant underline decoration-dotted decoration-outline hover:text-on-surface hover:decoration-on-surface",children:E.agentRef})})()}),i.jsx("td",{className:"py-1",children:i.jsx(Cs,{runtime:E.runtime,size:"xs",compact:!0,variant:"inline"})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:E.profile??"—"})]},E.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(Cs,{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,E)=>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})]},E))})]})]})]}),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,E)=>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})`:""]})]},E))]}),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(JU,{title:"YAML Preview",testId:s??`${x}spec-yaml`,children:t})]})}function Ewe(){const e=Pt(),{selectedRigDraft:t,currentRigDraft:n}=op(),s=t??n,{data:r,isLoading:a,error:o}=vwe((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(ot,{children:i.jsxs("div",{"data-testid":"rig-spec-review",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open In Import"}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/bootstrap"}),children:"Bootstrap"})]})}),r&&i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:r.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"rig-spec-summary-format"}),i.jsx(st,{label:r.format==="pod_aware"?"Pods":"Nodes",value:r.format==="pod_aware"?c.length:d.length,testId:"rig-spec-summary-pods"}),i.jsx(st,{label:"Members",value:r.format==="pod_aware"?c.reduce((m,f)=>m+f.members.length,0):d.length,testId:"rig-spec-summary-members"}),i.jsx(st,{label:"Edges",value:h.length+(r.format==="pod_aware"?c.reduce((m,f)=>{var g;return m+(((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(kT,{review:r,yaml:s.yaml,yamlTestId:"rig-spec-yaml"})]})}):i.jsx(ot,{children:i.jsxs("div",{"data-testid":"rig-spec-review-empty",className:"space-y-5",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open Import"})]})})}function ac({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=Kv();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 Rwe(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 n8({label:e,sourcePath:t,testId:n,children:s}){const r=Rwe(t,e);return r?i.jsx(ac,{data:{path:e,absolutePath:r},testId:n,className:"inline-block text-left",children:s}):i.jsx(i.Fragment,{children:s})}function CT({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(ht,{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(n8,{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(ht,{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(ht,{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(n8,{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(ht,{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(ht,{tool:c.type.includes("command")?"terminal":c.type,size:"xs",decorative:!0}),c.type,":"]})," ",c.value]},d))]})]}),i.jsx(JU,{title:"YAML Preview",testId:`${n}-spec-yaml`,children:t})]})}function Twe(){const e=Pt(),{selectedAgentDraft:t,currentAgentDraft:n}=op(),s=t??n,{data:r,isLoading:a,error:o}=ywe((s==null?void 0:s.yaml)??null);return s?i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-review",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open In Validate"})}),r&&i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:"AgentSpec",testId:"agent-spec-summary-format"}),i.jsx(st,{label:"Version",value:r.version,testId:"agent-spec-summary-version"}),i.jsx(st,{label:"Profiles",value:(r.profiles??[]).length,testId:"agent-spec-summary-profiles"}),i.jsx(st,{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(CT,{review:r,yaml:s.yaml,testIdPrefix:"agent"})]})}):i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-review-empty",className:"space-y-5",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open Validate"})]})})}function Awe(){return Ht({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 Iwe(){return Ht({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 Mwe(){var a,o;const[e,t]=C.useState(""),n=Awe(),s=()=>{e.trim()&&n.mutate({bundlePath:e.trim()})},r=n.data;return i.jsx(ot,{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(Se,{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:ce("text-label-sm",r.digestValid?"text-success":"text-destructive"),children:["DIGEST: ",r.digestValid?"VALID":"INVALID"]}),i.jsxs("span",{className:ce("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),m=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:ce("w-2 h-2",m==="OK"?"bg-success":"bg-destructive"),"data-testid":"file-dot"}),i.jsx("span",{children:c}),i.jsx("span",{className:"text-foreground-muted ml-auto",children:m})]},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(Se,{variant:"tactical","data-testid":"install-btn",onClick:()=>window.location.href=`/bundles/install?bundlePath=${encodeURIComponent(e)}`,children:"INSTALL THIS BUNDLE"})]})]})})}function Lwe(){const e=Pt(),[t,n]=C.useState("enter"),s=typeof window<"u"?new URLSearchParams(window.location.search):null,[r,a]=C.useState((s==null?void 0:s.get("bundlePath"))??""),[o,c]=C.useState(""),[d,h]=C.useState(null),[m,f]=C.useState(null),g=Iwe(),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(ot,{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(Se,{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(Se,{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(Se,{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:m}),i.jsx(Se,{variant:"tactical",onClick:()=>{n("enter"),f(null),g.reset()},"data-testid":"try-again-btn",children:"TRY AGAIN"})]})]})})}const Owe=180,s8=56,Pwe=220,Dwe=110,$V="in-top",BV="out-bottom",qV="in-side",FV="out-side";function $we(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 Bwe(e,t,n){const s=n.get(e)??0;return(n.get(t)??0)>s?{sourceHandle:BV,targetHandle:$V}:{sourceHandle:FV,targetHandle:qV}}function qwe({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:Owe,height:n?s8+12:s8,padding:6,fontFamily:"monospace",fontSize:11},children:[i.jsx(hn,{type:"target",position:_e.Top,id:$V,className:"opacity-0"}),i.jsx(hn,{type:"source",position:_e.Bottom,id:BV,className:"opacity-0"}),i.jsx(hn,{type:"target",position:_e.Right,id:qV,className:"opacity-0"}),i.jsx(hn,{type:"source",position:_e.Right,id:FV,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(ht,{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 Fwe={workflowStep:qwe};function zV({topology:e,testId:t,currentStepId:n,visitedStepIds:s,takenEdgeKeys:r,heightClass:a}){const{nodes:o,edges:c}=C.useMemo(()=>{const d=$we(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 m=new Map;for(const[b,_]of h)_.forEach((w,E)=>m.set(w,{x:E*Pwe,y:b*Dwe}));const f=new Set(s??[]),g=new Set(r??[]),x=e.nodes.map(b=>({id:b.stepId,type:"workflowStep",position:m.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",E=g.has(`${b.fromStepId}→${b.toStepId}`),{sourceHandle:N,targetHandle:k}=Bwe(b.fromStepId,b.toStepId,d);return{id:`e-${_}`,source:b.fromStepId,target:b.toStepId,sourceHandle:N,targetHandle:k,label:w&&b.branchOn?`on ${b.branchOn}`:void 0,labelStyle:{fontFamily:"monospace",fontSize:9,fill:"#7a5c10"},labelBgStyle:{fill:"#f2ead6"},animated:E&&n!=null,style:{stroke:E?"#5c4a10":w?"#a8842c":"#8a8577",strokeWidth:E?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(gp,{nodes:o,edges:c,nodeTypes:Fwe,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(IR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(xp,{showInteractive:!1})]})})}async function ET(e){const t=await fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.json()}function HV(e){return Re({queryKey:["workflow","instances","all"],queryFn:()=>ET("/api/workflow/list"),staleTime:15e3})}function zwe(){return Re({queryKey:["workflow","specs"],queryFn:()=>ET("/api/workflow/specs"),staleTime:15e3})}function Hwe(e){return Re({queryKey:["workflow","trace",e],queryFn:()=>ET(`/api/workflow/${encodeURIComponent(e)}/trace`),enabled:!!e,staleTime:15e3})}function Zi(e){return e.status==="failed"?0:e.deadline.state!=="healthy"?1:e.status==="waiting"?2:e.status==="active"?3:4}function Uwe(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"}:{glyph:"○",label:"COMPLETED",cls:"text-on-surface-variant"}}function Vwe(e){return`…${e.slice(-6)}`}function Wwe(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 Gwe(e){return e.currentStepId?`at ${e.currentStepId}`:e.status==="completed"?"closed":e.status==="failed"?"felled":"—"}function UV({instance:e}){const t=Uwe(e);return i.jsx("li",{children:i.jsxs(Ve,{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:ce("font-mono text-[11px]",t.cls),"aria-hidden":!0,children:t.glyph}),i.jsx("span",{className:ce("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:Vwe(e.instanceId)}),i.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-on-surface",children:[Gwe(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:Wwe(e.createdAt)}),i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant","aria-hidden":!0,children:"→"})]})})}function Kwe(e,t,n){return e.filter(s=>t?s.workflowName===t:!0).filter(s=>n?s.workflowVersion===n:!0).slice().sort((s,r)=>Zi(s)-Zi(r))}function Ywe({workflowName:e,workflowVersion:t,testId:n,quietWhenEmpty:s=!0}){const{data:r,isLoading:a}=HV(),o=Kwe(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=>Zi(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(UV,{instance:h},h.instanceId))})]})}function Qwe({entry:e}){const[t,n]=C.useState(!1),[s,r]=C.useState(null),[a,o]=C.useState(null),[c,d]=C.useState(null),[h,m]=C.useState(""),[f,g]=C.useState(null),x=mt(),y=Qf(),b=id(s),_=!e.sourceCwd,w=y.data??[],E=b.data??[],N=[...new Set(E.filter(T=>T.podId).map(T=>T.podNamespace??T.podId))],k=a?E.filter(T=>(T.podNamespace??T.podId)===a&&T.runtime===e.runtime&&!!T.agentRef&&!!T.profile):[],R=k.find(T=>T.logicalId===c),A=Ht({mutationFn:async()=>{var L,D,q,B,F,$,U,V,Y;if(!s||!a||!R||!h.trim())throw new Error("Missing required fields");const T={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&&(T.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:T})}),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 P=(q=(D=M.result)==null?void 0:D.node)==null?void 0:q.status;return P==="failed"||P==="attention_required"?{ok:!1,status:P,error:((F=(B=M.result)==null?void 0:B.node)==null?void 0:F.error)??`Launch ${P}`,logicalId:(U=($=M.result)==null?void 0:$.node)==null?void 0:U.logicalId}:{ok:!0,status:P??"launched",logicalId:((Y=(V=M.result)==null?void 0:V.node)==null?void 0:Y.logicalId)??h.trim()}},onSuccess:T=>{g(T),x.invalidateQueries({queryKey:["ps"]})},onError:T=>{g({ok:!1,error:T.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(Se,{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:T=>{r(T.target.value||null),o(null),d(null)},children:[i.jsx("option",{value:"",children:"Select rig…"}),w.map(T=>i.jsx("option",{value:T.rigId,children:T.name},T.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:T=>{o(T.target.value||null),d(null)},children:[i.jsx("option",{value:"",children:"Select pod…"}),N.map(T=>i.jsx("option",{value:T,children:T},T))]})]}),a&&k.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&&k.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:T=>d(T.target.value||null),children:[i.jsx("option",{value:"",children:"Select member…"}),k.map(T=>i.jsx("option",{value:T.logicalId,children:T.logicalId},T.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:T=>m(T.target.value.replace(/\./g,"")),placeholder:"e.g. forked-worker"})]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Se,{variant:"outline",size:"sm","data-testid":"fork-now-confirm",disabled:!c||!h.trim()||A.isPending,onClick:()=>A.mutate(),children:A.isPending?"Forking…":"Confirm fork"}),i.jsx(Se,{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 Xwe(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(`
|
|
586
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return C.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},H_e="DialogDescriptionWarning",U_e=({contentRef:e,descriptionId:t})=>{const s=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${TV(H_e).contentName}}.`;return C.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},V_e=gV,W_e=vV,G_e=bV,AV=_V,IV=wV,MV=jV,LV=kV,K_e=EV;const Dy=V_e,Y_e=W_e,Q_e=G_e,OV=C.forwardRef(({className:e,...t},n)=>i.jsx(AV,{ref:n,className:ce("fixed inset-0 z-50 bg-black/20 backdrop-blur-[8px]",e),...t}));OV.displayName=AV.displayName;const Ep=C.forwardRef(({className:e,children:t,hideCloseButton:n,...s},r)=>i.jsxs(Q_e,{children:[i.jsx(OV,{}),i.jsxs(IV,{ref:r,className:ce("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(K_e,{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(CE,{className:"h-4 w-4"}),i.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Ep.displayName=IV.displayName;const $y=({className:e,...t})=>i.jsx("div",{className:ce("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});$y.displayName="DialogHeader";const By=({className:e,...t})=>i.jsx("div",{className:ce("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});By.displayName="DialogFooter";const Rp=C.forwardRef(({className:e,...t},n)=>i.jsx(MV,{ref:n,className:ce("text-lg font-semibold leading-none tracking-tight",e),...t}));Rp.displayName=MV.displayName;const Tp=C.forwardRef(({className:e,...t},n)=>i.jsx(LV,{ref:n,className:ce("text-sm text-foreground-muted",e),...t}));Tp.displayName=LV.displayName;function X_e(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 Z_e(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 J_e(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 ewe(e){const t=mt();return Ht({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 twe(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 nwe(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return e.toUpperCase()}}function swe({installId:e}){const{data:t,isPending:n,isError:s}=J_e(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 rwe({install:e,onRollback:t}){const[n,s]=C.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:ce("inline-block px-spacing-2 py-px text-label-sm uppercase",twe(e.status)),children:nwe(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(Se,{variant:"tactical",size:"sm","data-testid":"expand-btn",onClick:()=>s(!n),children:n?"COLLAPSE":"EXPAND"}),e.status==="applied"&&i.jsx(Se,{variant:"tactical",size:"sm","data-testid":"rollback-btn",onClick:()=>t(e.id),children:"ROLLBACK"})]})]}),n&&i.jsx(swe,{installId:e.id})]})}function iwe(){var b;const{packageId:e}=An({strict:!1}),{data:t,isPending:n,error:s}=X_e(e),{data:r,isPending:a,error:o}=Z_e(e),c=ewe(e),[d,h]=C.useState(null),[m,f]=C.useState(!1),g=_=>{h(_),f(!0)},x=()=>{d&&c.mutate(d,{onSuccess:()=>{f(!1),h(null)}})};if(n||a)return i.jsx(ot,{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(ot,{children:i.jsx("div",{"data-testid":"detail-error",children:i.jsx("p",{className:"text-destructive",children:s.message})})});if(o)return i.jsx(ot,{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(ot,{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(rwe,{install:_,onRollback:g},_.id))}),i.jsx(Dy,{open:m,onOpenChange:_=>{c.isPending||(f(_),_||c.reset())},children:i.jsxs(Ep,{"data-testid":"rollback-dialog",onPointerDownOutside:_=>{c.isPending&&_.preventDefault()},onEscapeKeyDown:_=>{c.isPending&&_.preventDefault()},hideCloseButton:c.isPending,children:[i.jsxs($y,{children:[i.jsx(Rp,{className:"text-headline-md uppercase",children:"CONFIRM ROLLBACK"}),i.jsx(Tp,{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(By,{children:[i.jsx(Se,{variant:"ghost",onClick:()=>{c.reset(),f(!1)},"data-testid":"rollback-cancel",disabled:c.isPending,children:"CANCEL"}),i.jsx(Se,{variant:"destructive",onClick:x,"data-testid":"rollback-confirm",disabled:c.isPending,children:c.isPending?"ROLLING BACK...":"ROLLBACK"})]})]})})]})})}function awe(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 owe(e){switch(e){case"installed":return"OK";case"missing":return"MISSING";case"unsupported":return"MANUAL";case"unknown":return"UNKNOWN";default:return e.toUpperCase()}}function lwe({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:ce("w-2 h-2 shrink-0",awe(t.status))}),i.jsx("span",{"data-testid":"requirement-status",className:"w-16 uppercase",children:owe(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 PV(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 cwe(){return Ht({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(PV(n,t.status));throw s.data=n,s}return t.json()}})}function uwe(){const e=mt();return Ht({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(PV(a,r.status));throw o.data=a,o}return a},onSuccess:()=>{e.invalidateQueries({queryKey:["rigs","summary"]})}})}const dwe=["ENTER","PLAN","REVIEW","APPLY"],hwe=dwe.map((e,t)=>({num:t+1,label:e}));function fwe(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=Pt(),{bootstrapSourceRef:t,setBootstrapSourceRef:n}=op(),[s,r]=C.useState("enter"),[a,o]=C.useState(()=>t),[c,d]=C.useState(null),[h,m]=C.useState(new Set),[f,g]=C.useState(!1),[x,y]=C.useState(null),b=cwe(),_=uwe();C.useEffect(()=>{n(a)},[n,a]);const w=async()=>{if(a.trim()){r("planning");try{const q=await b.mutateAsync({sourceRef:a.trim()});d(q),m(new Set(q.actionKeys??[])),r("planned")}catch(q){y(q.message),r("error")}}},E=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),m(new Set),g(!1),y(null),b.reset(),_.reset()},k=c==null?void 0:c.stages.find(q=>q.stage==="probe_requirements"),R=k==null?void 0:k.detail,A=(R==null?void 0:R.results)??[],T=c==null?void 0:c.stages.find(q=>q.stage==="build_install_plan"),I=T==null?void 0:T.detail,M=(I==null?void 0:I.actions)??[],P=(T==null?void 0:T.status)==="blocked",D=M.some(q=>q.classification!=="manual_only"&&q.commandPreview)&&h.size===0&&!f;return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"bootstrap-wizard",className:"space-y-8",children:[i.jsx(wn,{eyebrow:"Bootstrap",title:"Bootstrap",description:"Plan environment requirements, approve install actions, then import the rig into a running topology."}),i.jsx(ZU,{"data-testid":"step-indicator",steps:hwe,currentStep:fwe(s)}),s==="enter"&&i.jsx(or,{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(_T,{"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(Se,{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(or,{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))}),A.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(lwe,{results:A})})]}),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:B=>{const F=new Set(h);B.target.checked?F.add(q.key):F.delete(q.key),m(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"]})]}),P&&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,B)=>i.jsx("div",{className:"text-warning text-label-sm",children:q},B))}),i.jsx(Se,{variant:"tactical",onClick:E,disabled:P||D,title:P?"Manual requirements must be resolved":D?"Select actions to approve":void 0,"data-testid":"apply-btn",children:"APPLY"})]})}),s==="applying"&&c&&i.jsx(or,{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(or,{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(Se,{variant:"tactical","data-testid":"view-rig-btn",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:c.rigId}}),children:"VIEW RIG"})]})}),s==="error"&&i.jsx(or,{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(Se,{variant:"tactical",onClick:N,"data-testid":"try-again-btn",children:"TRY AGAIN"})]})})]})})}function mwe(){const{currentAgentDraft:e,selectedAgentDraft:t,saveAgentDraft:n,rememberAgentDraft:s,clearSelectedAgentDraft:r}=op(),[a,o]=C.useState(()=>(t==null?void 0:t.yaml)??(e==null?void 0:e.yaml)??""),[c,d]=C.useState("idle"),[h,m]=C.useState([]);C.useEffect(()=>{n(a)},[n,a]),C.useEffect(()=>{t&&(o(t.yaml),r())},[r,t]);const f=async()=>{s(a),d("pending"),m([]);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}m(x.errors??["Validation failed"]),d("invalid")}catch{m(["Validation request failed"]),d("error")}};return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-validate-flow",className:"space-y-8",children:[i.jsx(wn,{eyebrow:"Agent Spec Validation",title:"VALIDATE AGENT",description:"Check an AgentSpec before you use it in a rig."}),i.jsxs(or,{title:"Agent YAML",description:"Paste or refine an AgentSpec draft, then validate it against the daemon contract.",children:[i.jsx(wT,{"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(Se,{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(Xn,{className:"mt-spacing-1","data-testid":"agent-spec-valid",children:i.jsx(qn,{className:"text-primary",children:"AgentSpec valid."})}),(c==="invalid"||c==="error")&&i.jsx(Xn,{className:"mt-spacing-1","data-testid":"agent-spec-invalid",children:i.jsx(qn,{children:i.jsx("ul",{className:"list-disc pl-5",children:h.map(g=>i.jsx("li",{children:g},g))})})})]})]})})}async function gwe(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 xwe(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 DV(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t}function vwe(e,t="draft"){return Re({queryKey:["spec-review","rig",e?DV(e):null,t],queryFn:()=>gwe(e,t),enabled:!!e})}function ywe(e,t="draft"){return Re({queryKey:["spec-review","agent",e?DV(e):null,t],queryFn:()=>xwe(e,t),enabled:!!e})}const bwe=160,_we=48,t8=200,wwe=100;function Swe(e){switch(e){case"claude-code":return"#d4c4a8";case"codex":return"#b8c9d4";case"terminal":return"#c4c4c4";default:return"#e0ddd4"}}function jwe(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*t8,y:r})}),r+=wwe;return n.forEach((a,o)=>{s.push({id:a.id,x:o*t8,y:r})}),s}function Nwe({graph:e,testId:t}){const n=e??{nodes:[],edges:[]},{nodes:s,edges:r}=C.useMemo(()=>{const a=jwe(n.nodes),o=new Map(a.map(h=>[h.id,h])),c=n.nodes.map(h=>{const m=o.get(h.id)??{x:0,y:0};return{id:h.id,type:"default",position:{x:m.x,y:m.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(Cs,{runtime:h.runtime,size:"xs",compact:!0,variant:"inline"})]})},style:{backgroundColor:Swe(h.runtime),border:"1px solid #8a8577",fontSize:11,fontFamily:"monospace",width:bwe,height:_we}}}),d=n.edges.map((h,m)=>({id:`e-${m}`,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(gp,{nodes:s,edges:r,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(IR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(xp,{showInteractive:!1})]})})}function kwe({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=Kv();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 Cwe(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 kT({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]=C.useState("topology"),m=(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(Nwe,{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"&&m.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(E=>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:E.id}),a&&i.jsx(Se,{variant:"outline",size:"sm","data-testid":`${x}member-open-agent-${w.id}-${E.id}`,className:"h-6 px-2 font-mono text-[9px] uppercase tracking-[0.12em]",onClick:()=>a(w.id,E),children:"Agent Spec"})]})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:(()=>{const N=Cwe(E.agentRef);return i.jsx(kwe,{data:{specKind:"agent",specName:N.specName,source:N.source},testId:`${x}member-sub-spec-${w.id}-${E.id}`,className:"text-on-surface-variant underline decoration-dotted decoration-outline hover:text-on-surface hover:decoration-on-surface",children:E.agentRef})})()}),i.jsx("td",{className:"py-1",children:i.jsx(Cs,{runtime:E.runtime,size:"xs",compact:!0,variant:"inline"})}),i.jsx("td",{className:"py-1 text-on-surface-variant",children:E.profile??"—"})]},E.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(Cs,{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,E)=>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})]},E))})]})]})]}),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,E)=>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})`:""]})]},E))]}),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(JU,{title:"YAML Preview",testId:s??`${x}spec-yaml`,children:t})]})}function Ewe(){const e=Pt(),{selectedRigDraft:t,currentRigDraft:n}=op(),s=t??n,{data:r,isLoading:a,error:o}=vwe((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(ot,{children:i.jsxs("div",{"data-testid":"rig-spec-review",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open In Import"}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/bootstrap"}),children:"Bootstrap"})]})}),r&&i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:r.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"rig-spec-summary-format"}),i.jsx(st,{label:r.format==="pod_aware"?"Pods":"Nodes",value:r.format==="pod_aware"?c.length:d.length,testId:"rig-spec-summary-pods"}),i.jsx(st,{label:"Members",value:r.format==="pod_aware"?c.reduce((m,f)=>m+f.members.length,0):d.length,testId:"rig-spec-summary-members"}),i.jsx(st,{label:"Edges",value:h.length+(r.format==="pod_aware"?c.reduce((m,f)=>{var g;return m+(((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(kT,{review:r,yaml:s.yaml,yamlTestId:"rig-spec-yaml"})]})}):i.jsx(ot,{children:i.jsxs("div",{"data-testid":"rig-spec-review-empty",className:"space-y-5",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open Import"})]})})}function ac({data:e,children:t,className:n,style:s,testId:r}){const{setSelection:a}=Kv();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 Rwe(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 n8({label:e,sourcePath:t,testId:n,children:s}){const r=Rwe(t,e);return r?i.jsx(ac,{data:{path:e,absolutePath:r},testId:n,className:"inline-block text-left",children:s}):i.jsx(i.Fragment,{children:s})}function CT({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(ht,{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(n8,{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(ht,{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(ht,{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(n8,{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(ht,{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(ht,{tool:c.type.includes("command")?"terminal":c.type,size:"xs",decorative:!0}),c.type,":"]})," ",c.value]},d))]})]}),i.jsx(JU,{title:"YAML Preview",testId:`${n}-spec-yaml`,children:t})]})}function Twe(){const e=Pt(),{selectedAgentDraft:t,currentAgentDraft:n}=op(),s=t??n,{data:r,isLoading:a,error:o}=ywe((s==null?void 0:s.yaml)??null);return s?i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-review",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open In Validate"})}),r&&i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:"AgentSpec",testId:"agent-spec-summary-format"}),i.jsx(st,{label:"Version",value:r.version,testId:"agent-spec-summary-version"}),i.jsx(st,{label:"Profiles",value:(r.profiles??[]).length,testId:"agent-spec-summary-profiles"}),i.jsx(st,{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(CT,{review:r,yaml:s.yaml,testIdPrefix:"agent"})]})}):i.jsx(ot,{children:i.jsxs("div",{"data-testid":"agent-spec-review-empty",className:"space-y-5",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open Validate"})]})})}function Awe(){return Ht({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 Iwe(){return Ht({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 Mwe(){var a,o;const[e,t]=C.useState(""),n=Awe(),s=()=>{e.trim()&&n.mutate({bundlePath:e.trim()})},r=n.data;return i.jsx(ot,{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(Se,{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:ce("text-label-sm",r.digestValid?"text-success":"text-destructive"),children:["DIGEST: ",r.digestValid?"VALID":"INVALID"]}),i.jsxs("span",{className:ce("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),m=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:ce("w-2 h-2",m==="OK"?"bg-success":"bg-destructive"),"data-testid":"file-dot"}),i.jsx("span",{children:c}),i.jsx("span",{className:"text-foreground-muted ml-auto",children:m})]},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(Se,{variant:"tactical","data-testid":"install-btn",onClick:()=>window.location.href=`/bundles/install?bundlePath=${encodeURIComponent(e)}`,children:"INSTALL THIS BUNDLE"})]})]})})}function Lwe(){const e=Pt(),[t,n]=C.useState("enter"),s=typeof window<"u"?new URLSearchParams(window.location.search):null,[r,a]=C.useState((s==null?void 0:s.get("bundlePath"))??""),[o,c]=C.useState(""),[d,h]=C.useState(null),[m,f]=C.useState(null),g=Iwe(),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(ot,{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(Se,{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(Se,{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(Se,{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:m}),i.jsx(Se,{variant:"tactical",onClick:()=>{n("enter"),f(null),g.reset()},"data-testid":"try-again-btn",children:"TRY AGAIN"})]})]})})}const Owe=180,s8=56,Pwe=220,Dwe=110,$V="in-top",BV="out-bottom",qV="in-side",FV="out-side";function $we(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 Bwe(e,t,n){const s=n.get(e)??0;return(n.get(t)??0)>s?{sourceHandle:BV,targetHandle:$V}:{sourceHandle:FV,targetHandle:qV}}function qwe({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:Owe,height:n?s8+12:s8,padding:6,fontFamily:"monospace",fontSize:11},children:[i.jsx(hn,{type:"target",position:_e.Top,id:$V,className:"opacity-0"}),i.jsx(hn,{type:"source",position:_e.Bottom,id:BV,className:"opacity-0"}),i.jsx(hn,{type:"target",position:_e.Right,id:qV,className:"opacity-0"}),i.jsx(hn,{type:"source",position:_e.Right,id:FV,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(ht,{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 Fwe={workflowStep:qwe};function zV({topology:e,testId:t,currentStepId:n,visitedStepIds:s,takenEdgeKeys:r,heightClass:a}){const{nodes:o,edges:c}=C.useMemo(()=>{const d=$we(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 m=new Map;for(const[b,_]of h)_.forEach((w,E)=>m.set(w,{x:E*Pwe,y:b*Dwe}));const f=new Set(s??[]),g=new Set(r??[]),x=e.nodes.map(b=>({id:b.stepId,type:"workflowStep",position:m.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",E=g.has(`${b.fromStepId}→${b.toStepId}`),{sourceHandle:N,targetHandle:k}=Bwe(b.fromStepId,b.toStepId,d);return{id:`e-${_}`,source:b.fromStepId,target:b.toStepId,sourceHandle:N,targetHandle:k,label:w&&b.branchOn?`on ${b.branchOn}`:void 0,labelStyle:{fontFamily:"monospace",fontSize:9,fill:"#7a5c10"},labelBgStyle:{fill:"#f2ead6"},animated:E&&n!=null,style:{stroke:E?"#5c4a10":w?"#a8842c":"#8a8577",strokeWidth:E?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(gp,{nodes:o,edges:c,nodeTypes:Fwe,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[i.jsx(IR,{gap:20,size:.5,color:"#d4d0c8"}),i.jsx(xp,{showInteractive:!1})]})})}async function ET(e){const t=await fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.json()}function HV(e){return Re({queryKey:["workflow","instances","all"],queryFn:()=>ET("/api/workflow/list"),staleTime:15e3})}function zwe(){return Re({queryKey:["workflow","specs"],queryFn:()=>ET("/api/workflow/specs"),staleTime:15e3})}function Hwe(e){return Re({queryKey:["workflow","trace",e],queryFn:()=>ET(`/api/workflow/${encodeURIComponent(e)}/trace`),enabled:!!e,staleTime:15e3})}function Zi(e){return e.status==="failed"?0:e.deadline.state!=="healthy"?1:e.status==="waiting"?2:e.status==="active"?3:4}function Uwe(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 Vwe(e){return`…${e.slice(-6)}`}function Wwe(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 Gwe(e){return e.currentStepId?`at ${e.currentStepId}`:e.status==="completed"?"closed":e.status==="failed"?"felled":"—"}function UV({instance:e}){const t=Uwe(e);return i.jsx("li",{children:i.jsxs(Ve,{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:ce("font-mono text-[11px]",t.cls),"aria-hidden":!0,children:t.glyph}),i.jsx("span",{className:ce("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:Vwe(e.instanceId)}),i.jsxs("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-on-surface",children:[Gwe(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:Wwe(e.createdAt)}),i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant","aria-hidden":!0,children:"→"})]})})}function Kwe(e,t,n){return e.filter(s=>t?s.workflowName===t:!0).filter(s=>n?s.workflowVersion===n:!0).slice().sort((s,r)=>Zi(s)-Zi(r))}function Ywe({workflowName:e,workflowVersion:t,testId:n,quietWhenEmpty:s=!0}){const{data:r,isLoading:a}=HV(),o=Kwe(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=>Zi(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(UV,{instance:h},h.instanceId))})]})}function Qwe({entry:e}){const[t,n]=C.useState(!1),[s,r]=C.useState(null),[a,o]=C.useState(null),[c,d]=C.useState(null),[h,m]=C.useState(""),[f,g]=C.useState(null),x=mt(),y=Qf(),b=id(s),_=!e.sourceCwd,w=y.data??[],E=b.data??[],N=[...new Set(E.filter(T=>T.podId).map(T=>T.podNamespace??T.podId))],k=a?E.filter(T=>(T.podNamespace??T.podId)===a&&T.runtime===e.runtime&&!!T.agentRef&&!!T.profile):[],R=k.find(T=>T.logicalId===c),A=Ht({mutationFn:async()=>{var L,D,q,B,F,$,U,V,Y;if(!s||!a||!R||!h.trim())throw new Error("Missing required fields");const T={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&&(T.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:T})}),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 P=(q=(D=M.result)==null?void 0:D.node)==null?void 0:q.status;return P==="failed"||P==="attention_required"?{ok:!1,status:P,error:((F=(B=M.result)==null?void 0:B.node)==null?void 0:F.error)??`Launch ${P}`,logicalId:(U=($=M.result)==null?void 0:$.node)==null?void 0:U.logicalId}:{ok:!0,status:P??"launched",logicalId:((Y=(V=M.result)==null?void 0:V.node)==null?void 0:Y.logicalId)??h.trim()}},onSuccess:T=>{g(T),x.invalidateQueries({queryKey:["ps"]})},onError:T=>{g({ok:!1,error:T.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(Se,{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:T=>{r(T.target.value||null),o(null),d(null)},children:[i.jsx("option",{value:"",children:"Select rig…"}),w.map(T=>i.jsx("option",{value:T.rigId,children:T.name},T.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:T=>{o(T.target.value||null),d(null)},children:[i.jsx("option",{value:"",children:"Select pod…"}),N.map(T=>i.jsx("option",{value:T,children:T},T))]})]}),a&&k.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&&k.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:T=>d(T.target.value||null),children:[i.jsx("option",{value:"",children:"Select member…"}),k.map(T=>i.jsx("option",{value:T.logicalId,children:T.logicalId},T.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:T=>m(T.target.value.replace(/\./g,"")),placeholder:"e.g. forked-worker"})]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Se,{variant:"outline",size:"sm","data-testid":"fork-now-confirm",disabled:!c||!h.trim()||A.isPending,onClick:()=>A.mutate(),children:A.isPending?"Forking…":"Confirm fork"}),i.jsx(Se,{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 Xwe(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
587
|
`)}function RT({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 Zwe({review:e}){const t=Pt(),n=e.profiles??[],s=e.resources??{skills:[]};return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-agent",className:"space-y-6",children:[i.jsx(wn,{eyebrow:"Library — Agent Spec",title:e.name,description:e.description??"Agent spec from library.",actions:i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/agents/validate"}),children:"Validate"})}),i.jsx(RT,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:"AgentSpec",testId:"lib-agent-format"}),i.jsx(st,{label:"Version",value:e.version,testId:"lib-agent-version"}),i.jsx(st,{label:"Profiles",value:n.length,testId:"lib-agent-profiles"}),i.jsx(st,{label:"Skills",value:s.skills.length,testId:"lib-agent-skills"})]}),i.jsx(CT,{review:e,yaml:e.raw,testIdPrefix:"lib-agent",sourcePath:e.sourcePath})]})})}function Jwe({review:e}){const t=Pt(),[n,s]=C.useState(!1),{data:r=[]}=np("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 m=h.slice(6),g=`${e.sourcePath.replace(/\/[^/]+$/,"")}/${m}`.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(ot,{children:i.jsxs("div",{"data-testid":"library-review-rig",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm","data-testid":"copy-setup-prompt",onClick:()=>void(async()=>{await ia(Xwe({name:e.name,summary:e.summary,sourcePath:e.sourcePath}))&&(s(!0),window.setTimeout(()=>s(!1),2e3))})(),children:n?"Copied":"Copy Setup Prompt"}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/import"}),children:"Import"})]})}),i.jsx(RT,{sourcePath:e.sourcePath,sourceState:e.sourceState}),i.jsxs(Do,{children:[i.jsx(st,{label:"Format",value:e.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"lib-rig-format"}),e.services&&i.jsx(st,{label:"Type",value:"Agent-Managed App",testId:"lib-rig-type"}),e.services&&a.length>0&&(()=>{const h=a.find(m=>m.members.some(f=>f.id==="specialist"));return h?i.jsx(st,{label:"Specialist Agent",value:`${h.id}.specialist`,testId:"lib-rig-specialist"}):null})(),i.jsx(st,{label:e.format==="pod_aware"?"Pods":"Nodes",value:e.format==="pod_aware"?a.length:o.length,testId:"lib-rig-pods"}),i.jsx(st,{label:"Members",value:e.format==="pod_aware"?a.reduce((h,m)=>h+m.members.length,0):o.length,testId:"lib-rig-members"}),i.jsx(st,{label:"Edges",value:c.length+(e.format==="pod_aware"?a.reduce((h,m)=>{var f;return h+(((f=m.edges)==null?void 0:f.length)??0)},0):0),testId:"lib-rig-edges"})]}),i.jsx(kT,{review:e,yaml:e.raw,testIdPrefix:"lib",yamlTestId:"lib-rig-yaml",showEnvironmentTab:!!e.services,onMemberClick:(h,m)=>{const f=d(m.agentRef);f&&t({to:"/specs/library/$entryId",params:{entryId:f.id}})}})]})})}function e1e({entryId:e}){return e.startsWith("context-pack:")?i.jsx(s1e,{entryId:e}):e.startsWith("agent-image:")?i.jsx(i1e,{entryId:e}):i.jsx(t1e,{entryId:e})}function t1e({entryId:e}){const t=Pt(),{data:n,isLoading:s,error:r}=Rv(e);return s?i.jsx(ot,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading spec review..."})}):r||!n?i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(wn,{eyebrow:"Library",title:"Spec Not Found",description:(r==null?void 0:r.message)??"Could not load spec."}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):n.kind==="agent"?i.jsx(Zwe,{review:n}):n.kind==="workflow"?i.jsx(n1e,{review:n}):i.jsx(Jwe,{review:n})}function n1e({review:e}){const t=Pt(),n=mt(),{data:s}=Qte(),[r,a]=C.useState(null),[o,c]=C.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 Xte(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)}},m=async()=>{c(!0),a(null);try{await Zte(),await n.invalidateQueries({queryKey:["spec-library","active-lens"]}),await n.invalidateQueries({queryKey:["slices"]})}catch(f){a(f.message)}finally{c(!1)}};return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-workflow",className:"space-y-6",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm","data-testid":"workflow-deactivate-lens",onClick:()=>void m(),disabled:o,children:o?"...":"Deactivate Lens"}):i.jsx(Se,{variant:"outline",size:"sm","data-testid":"workflow-activate-lens",onClick:()=>void h(),disabled:o,children:o?"...":"Activate as Lens"}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back"})]})}),i.jsx(RT,{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(Do,{children:[i.jsx(st,{label:"Format",value:"WorkflowSpec",testId:"lib-wf-format"}),i.jsx(st,{label:"Version",value:e.version,testId:"lib-wf-version"}),i.jsx(st,{label:"Roles",value:e.rolesCount,testId:"lib-wf-roles"}),i.jsx(st,{label:"Steps",value:e.stepsCount,testId:"lib-wf-steps"}),i.jsx(st,{label:"Target Rig",value:e.targetRig??"(any)",testId:"lib-wf-target-rig"}),i.jsx(st,{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(ht,{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(zV,{topology:e.topology}),i.jsx(Ywe,{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 s1e({entryId:e}){const t=Pt(),{data:n=[],isLoading:s,error:r}=UE(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=tne(a?a.relativePath:null);return s?i.jsx(ot,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading context pack…"})}):r||!a?i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(wn,{eyebrow:"Library",title:"Context Pack Not Found",description:(r==null?void 0:r.message)??`No context pack with id ${e}.`}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(r1e,{entry:a,preview:o,previewLoading:c})}function r1e({entry:e,preview:t,previewLoading:n}){const s=Pt();return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-context-pack",className:"space-y-4",children:[i.jsx(wn,{eyebrow:`Library — Context Pack${e.sourceType==="builtin"?" (built-in)":""}`,title:e.name,description:e.purpose??"Operator-authored composable context bundle.",actions:i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})}),i.jsxs(Do,{children:[i.jsx(st,{label:"Version",value:e.version,testId:"lib-pack-version"}),i.jsx(st,{label:"Files",value:e.files.length,testId:"lib-pack-files"}),i.jsx(st,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-pack-tokens"}),i.jsx(st,{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(ac,{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 i1e({entryId:e}){const t=Pt(),{data:n=[],isLoading:s,error:r}=VE(),a=n.find(d=>d.id===e)??null,{data:o,isLoading:c}=rne(a?e:null);return s?i.jsx(ot,{children:i.jsx("div",{className:"font-mono text-[10px] text-on-surface-variant",children:"Loading agent image…"})}):r||!a?i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[i.jsx(wn,{eyebrow:"Library",title:"Agent Image Not Found",description:(r==null?void 0:r.message)??`No agent image with id ${e}.`}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Library"})]})}):i.jsx(a1e,{entry:a,preview:o,previewLoading:c})}function a1e({entry:e,preview:t,previewLoading:n}){const s=Pt(),r=ine(),[a,o]=C.useState(!1),[c,d]=C.useState(null),h=async()=>{if(!(t!=null&&t.starterSnippet))return;await ia(t.starterSnippet)&&(o(!0),window.setTimeout(()=>o(!1),2e3))},m=async()=>{d(null);try{await r.mutateAsync({id:e.id,pin:!e.pinned})}catch(f){d(f.message)}};return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"library-review-agent-image",className:"space-y-4",children:[i.jsx(wn,{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(Se,{variant:"outline",size:"sm","data-testid":"agent-image-pin-toggle",onClick:()=>void m(),disabled:r.isPending,children:e.pinned?"Unpin":"Pin"}),i.jsx(Se,{variant:"outline",size:"sm",onClick:()=>s({to:"/specs"}),children:"Back to Library"})]})}),i.jsxs(Do,{children:[i.jsx(st,{label:"Runtime",value:i.jsx(Cs,{runtime:e.runtime,size:"sm",compact:!0,variant:"inline"}),testId:"lib-image-runtime"}),i.jsx(st,{label:"Forks",value:String(e.stats.forkCount),testId:"lib-image-forks"}),i.jsx(st,{label:"Tokens (~)",value:String(e.derivedEstimatedTokens),testId:"lib-image-tokens"}),i.jsx(st,{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(Qwe,{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(Se,{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(ac,{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 o1e(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 l1e(e,t){const n=At();return Re({queryKey:["rig",e,"nodes",t,n],queryFn:()=>o1e(e,t,n),enabled:!!e&&!!t,refetchInterval:3e4,placeholderData:fi})}function c1e({pluginIds:e}){const{data:t=[]}=Av();if(e.length===0)return i.jsx("div",{className:"px-3 py-4",children:i.jsx(Ae,{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(u1e,{entry:r}):i.jsx(d1e,{pluginId:s})},s)})})}function u1e({entry:e}){return i.jsxs(Ve,{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(ht,{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 d1e({pluginId:e}){return i.jsxs(Ve,{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(ht,{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 h1e(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 f1e(e,t){return e==="running"?"active":IE(e,t)}function p1e(e){return e==="active"?"active":e==="needs_input"?"needs input":e}function m1e({data:e,activityVisual:t}){var E,N,k;const n=AE(e.agentActivity)&&(t==null?void 0:t.state)!=="needs_input"&&(t==null?void 0:t.state)!=="blocked"?null:t,{state:s,source:r}=Xf(e.agentActivity,e.terminalActive),a=(n==null?void 0:n.state)??s,o=n?p1e(n.state):f1e(s,e.agentActivity),c=n?n.state==="active":s==="running",d=!!(n!=null&&n.recent),h=d?null:ME(e.agentActivity),m=!d&&r!=="hook"&&r!=="none"?" (activity-grade)":"",f=((E=e.contextUsage)==null?void 0:E.availability)==="known"&&typeof e.contextUsage.usedPercentage=="number"?`${e.contextUsage.usedPercentage}%`:null,g=Eo((N=e.contextUsage)==null?void 0:N.totalInputTokens,(k=e.contextUsage)==null?void 0:k.totalOutputTokens),x=wp(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}`:"",m]}),_=[{key:"runtime",label:"runtime",value:e.runtime?i.jsx(Cs,{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,A)=>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 ${A<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,A)=>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 ${A<w?"border-r border-outline-variant/55":""}`,children:i.jsx("div",{className:"truncate",children:h1e(R.value)})},R.key))})})]})})})}function g1e(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 x1e({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(r8,{fieldKey:"cwd",label:"cwd",value:e.cwd,mono:!0,titleAttr:e.cwd??void 0}),i.jsx(r8,{fieldKey:"current-work",label:"current work",value:n})]})})}function r8({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:g1e(n)})]})}function v1e(e){return e.startupStatus==="failed"?"Startup failed":e.startupStatus==="attention_required"?"Attention required":e.latestError?"Error":null}function y1e(e){return e.startupStatus==="failed"||e.latestError&&e.startupStatus!=="attention_required"?"destructive":"default"}function b1e({data:e}){const t=v1e(e);if(!t)return null;const n=!!e.latestError,s=!!e.recoveryGuidance;return i.jsxs(Xn,{"data-testid":"seat-notification-banner","data-startup-status":e.startupStatus??"unknown",variant:y1e(e),children:[i.jsx(K7,{"data-testid":"seat-notification-headline",className:"font-mono text-[11px] uppercase tracking-[0.08em]",children:t}),n?i.jsx(qn,{"data-testid":"seat-notification-error",className:"font-mono text-[10px]",children:e.latestError}):null,s&&e.recoveryGuidance?i.jsx(qn,{"data-testid":"seat-notification-guidance",className:"mt-1 font-mono text-[10px] text-on-surface",children:e.recoveryGuidance.summary}):null]})}function _1e(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 Ro="border border-outline-variant bg-surface-lowest/30 p-3";function w1e(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 S1e(e){switch(e){case"attention_required":return"attention required";default:return e??"stopped"}}function j1e(e){if(!e)return null;const t=e.match(/^local:agents\/([^/]+)$/);return(t==null?void 0:t[1])??null}function Er({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 N1e({data:e}){const t=j1e(e.agentRef),{data:n=[],isLoading:s}=np("agent"),r=t?n.filter(d=>d.name===t):[],a=r.length===1?r[0].id:null,{data:o,isLoading:c}=Rv(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:Ro,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(Er,{label:"Spec",value:e.compactSpec.name}),i.jsx(Er,{label:"Version",value:e.compactSpec.version}),i.jsx(Er,{label:"Profile",value:e.compactSpec.profile}),i.jsx(Er,{label:"Skills",value:e.compactSpec.skillCount}),i.jsx(Er,{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(CT,{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(c1e,{pluginIds:k1e(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 k1e(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 C1e({rigId:e,logicalId:t,data:n}){const s=At()!==at,r=async()=>{n.tmuxAttachCommand&&await ia(n.tmuxAttachCommand)},a=async()=>{try{await YR({rigId:e,logicalId:t})}catch{}},o=async()=>{n.resumeCommand&&await ia(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(ht,{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(ht,{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(PZ,{"aria-hidden":"true",className:"h-4 w-4 shrink-0",strokeWidth:1.5}),"Copy resume command"]})]})}function E1e({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:w1e(e.startupStatus),"data-testid":"detail-startup-status",children:S1e(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 ${_1e(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 R1e({data:e}){return!e.recentEvents||e.recentEvents.length===0?null:i.jsxs("section",{"data-testid":"live-node-recent-events",className:Ro,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 T1e({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:Ro,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 A1e({data:e}){return e.peers.length===0?null:i.jsxs("section",{"data-testid":"detail-peers",className:Ro,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 I1e({data:e}){var n,s,r;const t=e.contextUsage;return i.jsxs("section",{"data-testid":"detail-context-usage",className:Ro,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(Er,{label:"Used",value:t.usedPercentage!=null?`${t.usedPercentage}%`:null}),i.jsx(Er,{label:"Remaining",value:t.remainingPercentage!=null?`${t.remainingPercentage}%`:null}),i.jsx(Er,{label:"Window",value:(n=t.contextWindowSize)==null?void 0:n.toLocaleString()}),i.jsx(Er,{label:"Input tokens",value:(s=t.totalInputTokens)==null?void 0:s.toLocaleString()}),i.jsx(Er,{label:"Output tokens",value:(r=t.totalOutputTokens)==null?void 0:r.toLocaleString()}),i.jsx(Er,{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 M1e({data:e,activityVisual:t}){return i.jsxs("div",{"data-testid":"live-overview-section",className:"space-y-4",children:[i.jsx(b1e,{data:e}),i.jsx(m1e,{data:e,activityVisual:t}),i.jsx(x1e,{data:e}),i.jsx(O1e,{data:e}),i.jsx(R1e,{data:e})]})}function L1e({rigId:e,logicalId:t,data:n,isAgent:s}){return i.jsxs("div",{"data-testid":"live-details-section",className:"space-y-4",children:[i.jsx(P1e,{rigId:e,logicalId:t,data:n}),s?i.jsx(N1e,{data:n}):null,i.jsx(T1e,{data:n}),i.jsx(A1e,{data:n}),i.jsx(I1e,{data:n}),i.jsx(D1e,{data:n})]})}function O1e({data:e}){return At()!==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(Oo,{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 P1e({rigId:e,logicalId:t,data:n}){return i.jsxs("div",{"data-testid":"live-startup-section",className:"space-y-4",children:[i.jsx(E1e,{data:n}),n.infrastructureStartupCommand&&i.jsxs("section",{"data-testid":"live-node-infra-startup",className:Ro,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:Ro,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(ac,{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 D1e({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:Ro,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:()=>ia(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 $1e({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 VV({rigId:e,logicalId:t}){const{data:n,isLoading:s,error:r}=l1e(e,t),a=C.useMemo(()=>Ry(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=Ty(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]=C.useState("overview"),m=n?n.nodeKind!=="infrastructure":!0,f=["overview","details"];return i.jsx(ot,{children:i.jsxs("div",{"data-testid":"live-node-details",className:"space-y-4",children:[i.jsx(wn,{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)??ii(t)??_u((n==null?void 0:n.podId)??null)} / ${t}`,actions:n?i.jsx(Cs,{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(C1e,{rigId:e,logicalId:t,data:n}),i.jsx($1e,{tabs:f,activeTab:d,onSelect:h}),i.jsxs("div",{"data-testid":"live-node-tab-body",className:"space-y-4",children:[d==="overview"&&i.jsx(M1e,{data:n,activityVisual:c}),d==="details"&&i.jsx(L1e,{rigId:e,logicalId:t,data:n,isAgent:m})]})]})]})})}function B1e(e){return`'${e.replace(/'/g,"'\\''")}'`}function q1e(e){const t=e.tmuxWindow?`${e.tmuxSession}:${e.tmuxWindow}`:e.tmuxSession;return`tmux attach -t ${B1e(t)}`}function i8({label:e,activeLabel:t,onClick:n,testId:s,tool:r}){const[a,o]=C.useState(!1),c=C.useRef(null);C.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:ce("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(ht,{tool:r,size:"sm"}):null,i.jsx("span",{children:a?t:e})]})}function F1e({session:e,onAdopt:t}){return i.jsx("div",{"data-testid":"discovered-node",className:ce("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(Cs,{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(i8,{label:"copy tmux",activeLabel:"copied",testId:"copy-tmux-btn",tool:"tmux",onClick:async()=>await ia(q1e(e))}),e.cwd?i.jsx(i8,{label:"copy cwd",activeLabel:"copied",testId:"copy-cwd-btn",onClick:async()=>await ia(e.cwd??"")}):null,i.jsx(Se,{variant:"tactical",size:"sm","data-testid":"adopt-btn",onClick:()=>t(e.id),children:"ADOPT"})]})]})})}function z1e(){const[e,t]=C.useState(null),[n,s]=C.useState(!1),r=C.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(Se,{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 H1e(){var E,N;const{data:e=[]}=YE({status:"active",runtimeHint:["claude-code","codex"],minConfidence:"medium"}),t=oz(),{data:n=[]}=Dr(),s=cse(),r=e,[a,o]=C.useState(null),[c,d]=C.useState(!1),[h,m]=C.useState(""),[f,g]=C.useState(""),x=k=>{o(k),d(!0),m(""),g(""),s.reset()},y=()=>{d(!1),o(null)},b=()=>{!a||!h||!f.trim()||s.mutate({discoveredId:a,rigId:h,logicalId:f.trim()},{onSuccess:y})},_=((E=s.error)==null?void 0:E.message)??null,w=s.isPending;return i.jsx(ot,{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(Se,{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(k=>i.jsx(F1e,{session:k,onAdopt:x},k.id))]}),i.jsx(z1e,{})]}),i.jsx(Dy,{open:c,onOpenChange:d,children:i.jsxs(Ep,{"data-testid":"adopt-dialog",children:[i.jsxs($y,{children:[i.jsx(Rp,{className:"text-headline-md uppercase",children:"ADOPT SESSION"}),i.jsx(Tp,{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:k=>m(k.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(k=>i.jsxs("option",{value:k.id,children:[k.name," (",k.nodeCount," nodes)"]},k.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:k=>g(k.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(By,{children:[i.jsx(Se,{variant:"ghost",onClick:()=>d(!1),children:"CANCEL"}),i.jsx(Se,{variant:"tactical",onClick:b,disabled:!h||!f.trim()||w,"data-testid":"adopt-confirm",children:w?"ADOPTING...":"ADOPT"})]})]})})]})})}async function U1e(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 WV(e){return Re({queryKey:["mission-control","audit",e],queryFn:()=>U1e(e)})}const GV=["approve","deny","route","annotate","hold","drop","handoff"];async function V1e(e){const t=await fetch("/api/mission-control/action",{method:"POST",headers:{"Content-Type":"application/json",...EE()},body:JSON.stringify(e)}),n=await t.json();if(!t.ok){const s=new Error(typeof n=="object"&&n&&"message"in n?String(n.message):`HTTP ${t.status}`);throw typeof n=="object"&&n&&"error"in n&&(s.code=String(n.error)),s.details=n,s}return n}function W1e(){const e=mt();return Ht({mutationFn:V1e,onSuccess:(t,n)=>{e.invalidateQueries({queryKey:["mission-control","view"]}),e.invalidateQueries({queryKey:["mission-control","audit"]}),e.invalidateQueries({queryKey:["queue","item",n.qitemId]}),t.createdQitemId&&e.invalidateQueries({queryKey:["queue","item",t.createdQitemId]}),e.invalidateQueries({queryKey:["slices"]})}})}function Xa(e){return typeof window>"u"?"":new URL(window.location.href).searchParams.get(e)??""}function G1e(){var E,N,k,R;const[e,t]=C.useState(()=>Xa("qitem_id")||Xa("qitem")),[n,s]=C.useState(()=>Xa("action_verb")||Xa("verb")),[r,a]=C.useState(()=>Xa("actor_session")||Xa("actor")),[o,c]=C.useState(()=>Xa("since")),[d,h]=C.useState(()=>Xa("until")),[m]=C.useState(50),[f,g]=C.useState([]),x={qitemId:e||void 0,actionVerb:n||void 0,actorSession:r||void 0,since:o||void 0,until:d||void 0,limit:m,beforeId:f[f.length-1]},y=WV(x);function b(){g([])}function _(){var A;(A=y.data)!=null&&A.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:A=>t(A.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:A=>s(A.target.value),className:"border border-outline-variant px-2 py-1 font-mono text-xs",children:[i.jsx("option",{value:"",children:"all verbs"}),GV.map(A=>i.jsx("option",{value:A,children:A},A))]}),i.jsx("input",{type:"text","data-testid":"mc-audit-filter-actor-session",placeholder:"actor_session (e.g., operator-alex@kernel)",value:r,onChange:A=>a(A.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:A=>c(A.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:A=>h(A.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]}):((E=y.data)==null?void 0:E.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(A=>i.jsxs("li",{"data-testid":"mc-audit-row","data-action-id":A.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:A.actionVerb}),i.jsx("span",{className:"font-mono text-[10px] text-on-surface-variant",children:A.actedAt})]}),i.jsxs("div",{className:"mt-1 text-on-surface",children:["qitem: ",i.jsx("span",{className:"font-mono",children:A.qitemId??"—"})]}),i.jsxs("div",{className:"text-on-surface",children:["actor: ",i.jsx("span",{className:"font-mono",children:A.actorSession})]}),A.reason?i.jsxs("div",{className:"text-on-surface",children:["reason: ",i.jsx("span",{className:"italic",children:A.reason})]}):null,A.annotation?i.jsxs("div",{className:"text-on-surface",children:["annotation: ",i.jsx("span",{className:"italic",children:A.annotation})]}):null]},A.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: ",((k=y.data)==null?void 0:k.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 K1e(){const e=await fetch("/api/health-summary/version");if(!e.ok)throw new Error(`HTTP ${e.status}`);return await e.json()}function Y1e(){return Re({queryKey:["health-summary","version"],queryFn:K1e,staleTime:1/0})}const a8={active:"bg-success",running:"bg-success",stopped:"bg-outline-variant",warning:"bg-warning",error:"bg-tertiary",info:"bg-secondary"},Q1e={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 To({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:ce("inline-flex items-center gap-1 px-1.5 py-0.5 border font-mono text-[9px] uppercase tracking-wide",Q1e[e],s),role:"status","aria-label":o,children:[i.jsx("span",{className:ce("w-1.5 h-1.5 rounded-full",a8[e]),"aria-hidden":"true"}),i.jsx("span",{className:r,children:o})]}):i.jsxs("span",{"data-testid":a,className:ce("inline-flex items-center gap-1.5",s),role:"status","aria-label":o,children:[i.jsx("span",{className:ce("w-2 h-2 rounded-full",a8[e]),"aria-hidden":"true"}),t?i.jsx("span",{className:ce("font-mono text-[9px] uppercase tracking-wide text-on-surface-variant",r),children:t}):null]})}const KV={up:"running",partial:"warning",down:"stopped",blocked:"error",unknown:"info"},YV={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"},QV={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."};function Fk({rigId:e,rigName:t,isKernel:n=!1,status:s,seatsRunning:r,seatsTotal:a,recoverable:o,src:c,primaryLabel:d,onPrimary:h,primaryDisabled:m,testId:f}){const g=KV[s],x=m??s==="up";return i.jsxs("div",{"data-testid":f??`rig-status-card-${e}`,"data-status":s,className:"bg-white border border-stone-900 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(ZZ,{className:"h-3 w-3"}):i.jsx(aF,{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 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:ce("px-2 py-0.5 border font-mono text-[9px] uppercase tracking-wide inline-flex items-center gap-1.5",YV[s]),children:[i.jsx(To,{status:g}),s]})]}),i.jsx("p",{className:"font-mono text-[9px] leading-relaxed text-secondary",children:QV[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(Se,{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 pt-2",children:["src: ",c.join(" · ")]})]})]})}async function X1e(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 Z1e(e){return Ht({mutationFn:t=>X1e(e,t)})}const J1e={"resume-original":"running","fresh-primed":"info","awaiting-decision":"warning"},eSe={present:"text-success",missing:"text-tertiary font-bold",stale:"text-warning font-bold",unverified:"text-warning"};function o8({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:ce("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(EZ,{className:"h-3 w-3"}):null,t,e==="restore-original"?i.jsx("span",{className:ce("ml-auto text-[8px]",n?"text-white/70":"text-secondary"),children:"default"}):null]}),i.jsx("div",{className:ce("mt-1 font-mono text-[8px] leading-snug",n?"text-white/75":s?"text-tertiary":"text-secondary"),children:r})]})}function XV({rigId:e,rigName:t,open:n,onOpenChange:s}){var b;const r=Z1e(e),a=Fbe(e),[o,c]=C.useState("restore-original"),d=((b=r.data)==null?void 0:b.nodes)??[],h=d.map(_=>_.logicalId);C.useEffect(()=>{n&&(c("restore-original"),a.reset(),r.mutate(void 0))},[n,e]);function m(_){_!==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(Dy,{open:n,onOpenChange:s,children:i.jsxs(Ep,{hideCloseButton:!0,className:"max-w-3xl border-stone-900","data-testid":"launch-recovery-modal",children:[i.jsxs($y,{children:[i.jsxs(Rp,{className:"font-headline uppercase tracking-tight flex items-center gap-2",children:[i.jsx(rF,{className:"h-4 w-4"}),"Restore ",t]}),i.jsx(Tp,{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(o8,{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:()=>m("restore-original")}),i.jsx(o8,{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:()=>m("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(bE,{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(Ay,{"data-testid":"launch-plan-table",children:[i.jsx(Iy,{children:i.jsxs(Gl,{children:[i.jsx(Ir,{className:"font-mono text-[9px]",children:"Seat"}),i.jsx(Ir,{className:"font-mono text-[9px]",children:"Token"}),i.jsx(Ir,{className:"font-mono text-[9px]",children:"Plan"}),i.jsx(Ir,{className:"font-mono text-[9px]",children:"Prompt / note"})]})}),i.jsx(My,{children:d.map(_=>i.jsxs(Gl,{"data-testid":`plan-row-${_.logicalId}`,children:[i.jsx(Mr,{className:"py-2 font-mono text-[10px] font-medium",children:_.logicalId}),i.jsx(Mr,{className:"py-2 font-mono text-[9px]","data-testid":`plan-token-${_.logicalId}`,children:i.jsx("span",{className:ce(eSe[_.tokenState]),children:_.tokenState})}),i.jsx(Mr,{className:"py-2","data-testid":`plan-verdict-${_.logicalId}`,children:i.jsx(To,{status:J1e[_.intendedAction],variant:"pill",label:_.intendedAction})}),i.jsx(Mr,{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(By,{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(Se,{variant:"secondary",size:"sm",className:"font-mono text-[10px]",onClick:()=>s(!1),"data-testid":"launch-cancel",children:"Cancel"}),i.jsx(Se,{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 tSe(e){return!!e&&"error"in e}async function nSe(){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 sSe(){return Re({queryKey:["kernel","status"],queryFn:nSe,refetchInterval:1e4})}function rSe(e){switch(e){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 iSe(){const{data:e,isLoading:t}=sSe(),{data:n}=Dr(),[s,r]=C.useState(!1),a=n==null?void 0:n.find(f=>f.name==="kernel");if(t||!e)return i.jsx(Fk,{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(tSe(e))return i.jsx(Fk,{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=rSe(e.kernel_state),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]:[]],m=!a||o==="up";return i.jsxs(i.Fragment,{children:[i.jsx(Fk,{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:m,onPrimary:()=>r(!0),testId:"kernel-status-card"}),a?i.jsx(XV,{rigId:a.id,rigName:"kernel",open:s,onOpenChange:r}):null]})}function l8(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 aSe(e){return e.transport==="ssh"?e.target??"—":e.url??"—"}function oSe(){var R,A,T;const{data:e}=mr(),{data:t,error:n}=Pr(),s=Nv(),r=zJ(),[a,o]=C.useState(!1),[c,d]=C.useState(""),[h,m]=C.useState(""),[f,g]=C.useState(null),x=HJ(f),y=l8(e,"host.name")||(t==null?void 0:t.ownName)||"localhost",b=l8(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,E=((A=x.data)==null?void 0:A.code)??((T=r.data)==null?void 0:T.code);async function N(){const I=h.trim();if(I)try{const M=await r.mutateAsync({url:I});g(M.pairId)}catch{}}function k(){g(null),m(""),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:aSe(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=>m(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:k,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:k,children:"Dismiss"})]}):i.jsxs(i.Fragment,{children:[i.jsxs("span",{"data-testid":"host-pair-code",children:["Code ",E??"…"," — waiting for approval on the target."]}),i.jsx("button",{type:"button",className:"df-hosts-btn",onClick:k,children:"Cancel"})]})})]})}class nd extends C.Component{constructor(){super(...arguments);cn(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 lSe(){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 cSe(){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 uSe(){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 dSe(){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 hSe(){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 fSe(){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 mSe({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 gSe=[{num:"01",to:"/topology",label:"TOPOLOGY",caption:"VIEW RIG GRAPH",glyph:i.jsx(lSe,{}),captionGlyph:"cross"},{num:"02",to:"/project",label:"PROJECT",caption:"BROWSE PROJECTS",glyph:i.jsx(cSe,{}),captionGlyph:"square"},{num:"03",to:"/for-you",label:"FOR YOU",caption:"PRIORITIZED FOR YOU",glyph:i.jsx(uSe,{}),captionGlyph:"square",amber:!0},{num:"04",to:"/specs",label:"LIBRARY",caption:"SPECS & ARTIFACTS",glyph:i.jsx(dSe,{}),captionGlyph:"cross"},{num:"05",to:"/search",label:"SEARCH & AUDIT",caption:"FIND & VERIFY",glyph:i.jsx(hSe,{}),captionGlyph:"circle"},{num:"06",to:"/settings",label:"SETTINGS",caption:"CONFIGURE · STATUS",glyph:i.jsx(fSe,{}),captionGlyph:"circle"}];function c8(e){return String(Math.max(0,e)).padStart(2,"0")}function xSe(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 vSe(){const{data:e}=Dr(),{data:t,isError:n}=Qf(),{data:s}=mr(),{data:r}=Y1e(),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,m=xSe(s,"agents.operator_session"),f=tp(m),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(ySe,{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(nd,{label:"Kernel status",children:i.jsx(iSe,{})})]}),i.jsx(nd,{label:"Hosts",children:i.jsx(oSe,{})}),i.jsx("div",{className:"df-grid","data-testid":"dashboard-launcher-grid",children:gSe.map(y=>i.jsx(bSe,{dest:y},y.num))})]}),i.jsx(_Se,{})]})}function ySe({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:c8(n)},{k:"AGENTS",v:c8(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 bSe({dest:e}){return i.jsxs("div",{className:"df-cell",children:[i.jsxs(Ve,{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(mSe,{kind:e.captionGlyph})}),i.jsx("span",{className:"df-lead","aria-hidden":"true"}),e.caption]})]})}function _Se(){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 wSe(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 SSe(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:[]}}function jSe(e=50,t=!1){return Re({queryKey:["attention-items",e,t],queryFn:t?()=>SSe(e):async()=>({items:await wSe(e),hosts:[]}),staleTime:15e3,refetchOnWindowFocus:"always"})}function V2(e){return typeof e=="string"&&e.length>0?e:void 0}function Cn(e,...t){for(const n of t){const s=V2(e[n]);if(s)return s}}function NSe(e){if(e)return e.length<=28?e:`${e.slice(0,18)}...${e.slice(-6)}`}function kSe(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 CSe(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 ESe(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 RSe(e){const t=Cn(e,"sourceSession","source_session","fromSession"),n=Cn(e,"destinationSession","destination_session","toSession","destination"),s=t&&n?`${t} -> ${n}`:t?`Source: ${t}`:n?`Destination: ${n}`:void 0,r=[Cn(e,"priority")?`priority=${Cn(e,"priority")}`:void 0,Cn(e,"tier")?`tier=${Cn(e,"tier")}`:void 0,Cn(e,"state","toState")?`state=${Cn(e,"state","toState")}`:void 0,Cn(e,"closureReason")?`closure=${Cn(e,"closureReason")}`:void 0].filter(a=>!!a);return[s,r.length>0?r.join(" / "):void 0].filter(a=>!!a).join(`
|