@opengsd/gsd-pi 1.3.0-dev.65546769 → 1.3.0-dev.72e3af2a
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/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +11 -2
- package/dist/resources/extensions/google-cli/stream-adapter.js +82 -15
- package/dist/resources/extensions/gsd/artifact-verification.js +427 -0
- package/dist/resources/extensions/gsd/auto/orchestrator.js +12 -3
- package/dist/resources/extensions/gsd/auto/session.js +3 -0
- package/dist/resources/extensions/gsd/auto-artifact-paths.js +28 -1
- package/dist/resources/extensions/gsd/auto-dispatch.js +20 -19
- package/dist/resources/extensions/gsd/auto-prompts.js +26 -11
- package/dist/resources/extensions/gsd/auto-recovery.js +6 -507
- package/dist/resources/extensions/gsd/auto-runtime-state.js +4 -5
- package/dist/resources/extensions/gsd/auto-timeout-recovery.js +3 -3
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +103 -13
- package/dist/resources/extensions/gsd/bootstrap/core-session-tools.js +38 -0
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +6 -1
- package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +2 -0
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +10 -19
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +46 -19
- package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +68 -10
- package/dist/resources/extensions/gsd/bootstrap/write-gate.js +1 -1
- package/dist/resources/extensions/gsd/commands-context.js +19 -1
- package/dist/resources/extensions/gsd/commands-prefs-wizard.js +16 -10
- package/dist/resources/extensions/gsd/commands-worktree.js +12 -10
- package/dist/resources/extensions/gsd/dashboard-overlay.js +32 -3
- package/dist/resources/extensions/gsd/db/queries.js +60 -0
- package/dist/resources/extensions/gsd/db-workspace.js +55 -3
- package/dist/resources/extensions/gsd/doctor-providers.js +92 -8
- package/dist/resources/extensions/gsd/exec-sandbox.js +45 -9
- package/dist/resources/extensions/gsd/forensics.js +2 -32
- package/dist/resources/extensions/gsd/git-service.js +4 -4
- package/dist/resources/extensions/gsd/guided-flow-queue.js +66 -5
- package/dist/resources/extensions/gsd/health-widget.js +55 -29
- package/dist/resources/extensions/gsd/layout-policy.js +3 -1
- package/dist/resources/extensions/gsd/markdown-renderer.js +8 -9
- package/dist/resources/extensions/gsd/memory-consolidation-scanner.js +44 -21
- package/dist/resources/extensions/gsd/migration-auto-check.js +22 -0
- package/dist/resources/extensions/gsd/milestone-ids.js +32 -2
- package/dist/resources/extensions/gsd/milestone-implementation-evidence.js +26 -20
- package/dist/resources/extensions/gsd/prompts/code-review.md +6 -4
- package/dist/resources/extensions/gsd/quick.js +45 -2
- package/dist/resources/extensions/gsd/session-forensics.js +11 -1
- package/dist/resources/extensions/gsd/skills/gsd-headless/references/commands.md +1 -1
- package/dist/resources/extensions/gsd/state/derive/cache.js +28 -0
- package/dist/resources/extensions/gsd/state/derive/db-open.js +39 -0
- package/dist/resources/extensions/gsd/state/derive/from-db.js +452 -0
- package/dist/resources/extensions/gsd/state/derive/index.js +75 -0
- package/dist/resources/extensions/gsd/state/derive/interrupted-work.js +21 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-render.js +45 -2
- package/dist/resources/extensions/gsd/state-reconciliation/index.js +48 -23
- package/dist/resources/extensions/gsd/state-reconciliation/registry.js +32 -28
- package/dist/resources/extensions/gsd/state.js +12 -611
- package/dist/resources/extensions/gsd/tools/complete-slice.js +2 -2
- package/dist/resources/extensions/gsd/tools/complete-task.js +43 -14
- package/dist/resources/extensions/gsd/tools/exec-tool.js +7 -2
- package/dist/resources/extensions/gsd/unit-context-composer.js +23 -7
- package/dist/resources/extensions/gsd/unit-registry.js +32 -4
- package/dist/resources/extensions/gsd/unmerged-milestone-guard.js +33 -3
- package/dist/resources/extensions/gsd/validation-block-guard.js +9 -4
- package/dist/resources/extensions/gsd/workflow-projections.js +19 -14
- package/dist/resources/extensions/gsd/workspace-git-preflight.js +30 -1
- package/dist/resources/extensions/gsd/worktree-manager.js +44 -2
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
- package/dist/web/standalone/.next/build-manifest.json +3 -3
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/react-loadable-manifest.json +9 -9
- package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +2 -2
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/.next/static/chunks/{2659.b7b129ee6a769448.js → 2659.58e950899a9bb82f.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/2772.a7c1fcc69a4685ef.js +1 -0
- package/dist/web/standalone/.next/static/chunks/{3616.3c60753b8ffcbd2e.js → 3616.61a2af74bb8833c8.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/{4283.8e446784528ed9dc.js → 4283.d0d9e0a955e441cb.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/{5826.a46ecdd1cfe8dabc.js → 5826.5421d66c72b9f34e.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/{8785.481aa5869991b760.js → 8785.e29b3134cab1d153.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/8937.640dc9c2aaa1dfad.js +10 -0
- package/dist/web/standalone/.next/static/chunks/app/{page-6644fc6ee8ca1247.js → page-72a856634ad14c10.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/webpack-9c401904f87ded16.js +1 -0
- package/dist/web/standalone/node_modules/node-pty/build/Makefile +1 -1
- package/package.json +1 -1
- package/packages/cloud-mcp-gateway/package.json +2 -2
- package/packages/contracts/dist/workflow.d.ts +1 -0
- package/packages/contracts/dist/workflow.d.ts.map +1 -1
- package/packages/contracts/dist/workflow.js +2 -0
- package/packages/contracts/dist/workflow.js.map +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/daemon/package.json +4 -4
- package/packages/gsd-agent-core/dist/agent-session.d.ts +1 -0
- package/packages/gsd-agent-core/dist/agent-session.d.ts.map +1 -1
- package/packages/gsd-agent-core/dist/agent-session.js +3 -0
- package/packages/gsd-agent-core/dist/agent-session.js.map +1 -1
- package/packages/gsd-agent-core/dist/extension-ui-snapshot.d.ts +41 -0
- package/packages/gsd-agent-core/dist/extension-ui-snapshot.d.ts.map +1 -0
- package/packages/gsd-agent-core/dist/extension-ui-snapshot.js +62 -0
- package/packages/gsd-agent-core/dist/extension-ui-snapshot.js.map +1 -0
- package/packages/gsd-agent-core/dist/index.d.ts +2 -0
- package/packages/gsd-agent-core/dist/index.d.ts.map +1 -1
- package/packages/gsd-agent-core/dist/index.js +2 -0
- package/packages/gsd-agent-core/dist/index.js.map +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-events.js +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-events.js.map +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-host.d.ts +1 -0
- package/packages/gsd-agent-core/dist/session/agent-session-host.d.ts.map +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-host.js.map +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-prompt.d.ts +5 -0
- package/packages/gsd-agent-core/dist/session/agent-session-prompt.d.ts.map +1 -1
- package/packages/gsd-agent-core/dist/session/agent-session-prompt.js +60 -3
- package/packages/gsd-agent-core/dist/session/agent-session-prompt.js.map +1 -1
- package/packages/gsd-agent-core/dist/transcript-store.d.ts +58 -0
- package/packages/gsd-agent-core/dist/transcript-store.d.ts.map +1 -0
- package/packages/gsd-agent-core/dist/transcript-store.js +132 -0
- package/packages/gsd-agent-core/dist/transcript-store.js.map +1 -0
- package/packages/gsd-agent-core/package.json +5 -5
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +2 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +25 -11
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.d.ts +4 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.js +7 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +3 -24
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +26 -829
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.d.ts +58 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.js +312 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.d.ts +31 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.js +130 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.d.ts +15 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.js +258 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.d.ts +13 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.js +118 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts +9 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.d.ts +54 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.js +20 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +4 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +9 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.d.ts +56 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.js +44 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.d.ts +5 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.d.ts.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.js +77 -0
- package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.js.map +1 -0
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +18 -0
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/packages/gsd-agent-modes/package.json +7 -7
- package/packages/mcp-server/README.md +1 -1
- package/packages/mcp-server/dist/server.d.ts +1 -1
- package/packages/mcp-server/dist/server.d.ts.map +1 -1
- package/packages/mcp-server/dist/server.js +3 -3
- package/packages/mcp-server/dist/server.js.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.d.ts +13 -1
- package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.js +34 -20
- package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
- package/packages/mcp-server/package.json +4 -4
- package/packages/native/package.json +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-coding-agent/README.md +3 -2
- package/packages/pi-coding-agent/dist/core/session-manager-context.d.ts +9 -0
- package/packages/pi-coding-agent/dist/core/session-manager-context.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-context.js +94 -0
- package/packages/pi-coding-agent/dist/core/session-manager-context.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-list.d.ts +8 -0
- package/packages/pi-coding-agent/dist/core/session-manager-list.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-list.js +244 -0
- package/packages/pi-coding-agent/dist/core/session-manager-list.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-migration.d.ts +12 -0
- package/packages/pi-coding-agent/dist/core/session-manager-migration.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-migration.js +84 -0
- package/packages/pi-coding-agent/dist/core/session-manager-migration.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-types.d.ts +135 -0
- package/packages/pi-coding-agent/dist/core/session-manager-types.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager-types.js +2 -0
- package/packages/pi-coding-agent/dist/core/session-manager-types.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts +6 -154
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/session-manager.js +22 -459
- package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme-schema.d.ts +75 -75
- package/packages/pi-coding-agent/dist/theme/theme-schema.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme-schema.js +1 -1
- package/packages/pi-coding-agent/dist/theme/theme-schema.js.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/theme/theme.js +11 -7
- package/packages/pi-coding-agent/dist/theme/theme.js.map +1 -1
- package/packages/pi-coding-agent/package.json +7 -7
- package/packages/pi-tui/package.json +2 -2
- package/packages/rpc-client/package.json +2 -2
- package/pkg/dist/theme/theme-schema.d.ts +75 -75
- package/pkg/dist/theme/theme-schema.d.ts.map +1 -1
- package/pkg/dist/theme/theme-schema.js +1 -1
- package/pkg/dist/theme/theme-schema.js.map +1 -1
- package/pkg/dist/theme/theme.d.ts.map +1 -1
- package/pkg/dist/theme/theme.js +11 -7
- package/pkg/dist/theme/theme.js.map +1 -1
- package/pkg/package.json +1 -1
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +20 -2
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +80 -0
- package/src/resources/extensions/google-cli/stream-adapter.ts +106 -19
- package/src/resources/extensions/gsd/artifact-verification.ts +464 -0
- package/src/resources/extensions/gsd/auto/orchestrator.ts +25 -11
- package/src/resources/extensions/gsd/auto/session.ts +5 -0
- package/src/resources/extensions/gsd/auto-artifact-paths.ts +47 -1
- package/src/resources/extensions/gsd/auto-dispatch.ts +21 -23
- package/src/resources/extensions/gsd/auto-prompts.ts +38 -12
- package/src/resources/extensions/gsd/auto-recovery.ts +10 -508
- package/src/resources/extensions/gsd/auto-runtime-state.ts +4 -5
- package/src/resources/extensions/gsd/auto-timeout-recovery.ts +3 -2
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +125 -12
- package/src/resources/extensions/gsd/bootstrap/core-session-tools.ts +43 -0
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +6 -1
- package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +2 -0
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +11 -19
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +52 -18
- package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +74 -10
- package/src/resources/extensions/gsd/bootstrap/write-gate.ts +1 -1
- package/src/resources/extensions/gsd/commands-context.ts +18 -1
- package/src/resources/extensions/gsd/commands-prefs-wizard.ts +14 -9
- package/src/resources/extensions/gsd/commands-worktree.ts +12 -10
- package/src/resources/extensions/gsd/dashboard-overlay.ts +32 -3
- package/src/resources/extensions/gsd/db/queries.ts +79 -0
- package/src/resources/extensions/gsd/db-workspace.ts +61 -3
- package/src/resources/extensions/gsd/doctor-providers.ts +103 -9
- package/src/resources/extensions/gsd/exec-sandbox.ts +49 -9
- package/src/resources/extensions/gsd/forensics.ts +2 -33
- package/src/resources/extensions/gsd/git-service.ts +5 -5
- package/src/resources/extensions/gsd/guided-flow-queue.ts +89 -4
- package/src/resources/extensions/gsd/health-widget.ts +69 -32
- package/src/resources/extensions/gsd/layout-policy.ts +2 -1
- package/src/resources/extensions/gsd/markdown-renderer.ts +8 -11
- package/src/resources/extensions/gsd/memory-consolidation-scanner.ts +51 -19
- package/src/resources/extensions/gsd/migration-auto-check.ts +23 -0
- package/src/resources/extensions/gsd/milestone-ids.ts +31 -2
- package/src/resources/extensions/gsd/milestone-implementation-evidence.ts +35 -21
- package/src/resources/extensions/gsd/prompts/code-review.md +6 -4
- package/src/resources/extensions/gsd/quick.ts +43 -2
- package/src/resources/extensions/gsd/session-forensics.ts +11 -1
- package/src/resources/extensions/gsd/skills/gsd-headless/references/commands.md +1 -1
- package/src/resources/extensions/gsd/state/derive/cache.ts +46 -0
- package/src/resources/extensions/gsd/state/derive/db-open.ts +45 -0
- package/src/resources/extensions/gsd/state/derive/from-db.ts +561 -0
- package/src/resources/extensions/gsd/state/derive/index.ts +104 -0
- package/src/resources/extensions/gsd/state/derive/interrupted-work.ts +31 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/stale-render.ts +81 -7
- package/src/resources/extensions/gsd/state-reconciliation/index.ts +50 -24
- package/src/resources/extensions/gsd/state-reconciliation/registry.ts +43 -28
- package/src/resources/extensions/gsd/state.ts +32 -732
- package/src/resources/extensions/gsd/tests/auto-artifact-paths.test.ts +98 -1
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +111 -1
- package/src/resources/extensions/gsd/tests/commands-context.test.ts +26 -0
- package/src/resources/extensions/gsd/tests/commands-gsd-core.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/commands-worktree-clean.test.ts +80 -0
- package/src/resources/extensions/gsd/tests/complete-slice.test.ts +11 -0
- package/src/resources/extensions/gsd/tests/complete-task-rollback-evidence.test.ts +48 -8
- package/src/resources/extensions/gsd/tests/complete-task.test.ts +75 -0
- package/src/resources/extensions/gsd/tests/dashboard-overlay.test.ts +55 -2
- package/src/resources/extensions/gsd/tests/dispatch-rule-coverage.test.ts +26 -1
- package/src/resources/extensions/gsd/tests/doctor-forensics-db-open-regression.test.ts +70 -2
- package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +107 -0
- package/src/resources/extensions/gsd/tests/exec-graceful-kill.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/exec-tool.test.ts +45 -1
- package/src/resources/extensions/gsd/tests/forensics-error-filter.test.ts +88 -0
- package/src/resources/extensions/gsd/tests/guided-discuss-milestone-prompt-rendering.test.ts +42 -0
- package/src/resources/extensions/gsd/tests/health-widget.test.ts +268 -3
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +119 -1
- package/src/resources/extensions/gsd/tests/integration/queue-active-milestone-context-budget.test.ts +93 -0
- package/src/resources/extensions/gsd/tests/integration/quick-branch-lifecycle.test.ts +56 -9
- package/src/resources/extensions/gsd/tests/knowledge-cold-start.test.ts +14 -0
- package/src/resources/extensions/gsd/tests/memory-consolidation-scanner.test.ts +78 -0
- package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +70 -0
- package/src/resources/extensions/gsd/tests/orchestrator-logs.test.ts +43 -1
- package/src/resources/extensions/gsd/tests/parallel-research-dispatch.test.ts +26 -0
- package/src/resources/extensions/gsd/tests/parsers-legacy-importers.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/pipeline-variant-dispatch.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +54 -1
- package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +50 -14
- package/src/resources/extensions/gsd/tests/provider-errors.test.ts +195 -1
- package/src/resources/extensions/gsd/tests/read-uat-gate-verdict.test.ts +185 -0
- package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +87 -0
- package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +7 -0
- package/src/resources/extensions/gsd/tests/stalled-tool-recovery.test.ts +56 -0
- package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +191 -0
- package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +151 -0
- package/src/resources/extensions/gsd/tests/tool-param-optionality.test.ts +26 -0
- package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +193 -14
- package/src/resources/extensions/gsd/tests/unmerged-milestone-guard.test.ts +25 -0
- package/src/resources/extensions/gsd/tests/validation-block-guard.test.ts +79 -0
- package/src/resources/extensions/gsd/tests/verify-artifact-tightened.test.ts +66 -0
- package/src/resources/extensions/gsd/tests/workspace-git-preflight.test.ts +151 -2
- package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +39 -0
- package/src/resources/extensions/gsd/tools/complete-slice.ts +2 -2
- package/src/resources/extensions/gsd/tools/complete-task.ts +53 -15
- package/src/resources/extensions/gsd/tools/exec-tool.ts +7 -3
- package/src/resources/extensions/gsd/unit-context-composer.ts +33 -7
- package/src/resources/extensions/gsd/unit-registry.ts +32 -4
- package/src/resources/extensions/gsd/unmerged-milestone-guard.ts +41 -5
- package/src/resources/extensions/gsd/validation-block-guard.ts +13 -7
- package/src/resources/extensions/gsd/workflow-projections.ts +20 -14
- package/src/resources/extensions/gsd/workspace-git-preflight.ts +31 -0
- package/src/resources/extensions/gsd/worktree-manager.ts +41 -1
- package/dist/web/standalone/.next/static/chunks/2772.bfa657f49f955239.js +0 -1
- package/dist/web/standalone/.next/static/chunks/796.e0bdc932325d7e03.js +0 -10
- package/dist/web/standalone/.next/static/chunks/webpack-f46ea08200a0227e.js +0 -1
- /package/dist/web/standalone/.next/static/{BTKtGFF1Y-hvVJEGhBRo9 → O7xDYXO0r4zFhIzY1hrWV}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{BTKtGFF1Y-hvVJEGhBRo9 → O7xDYXO0r4zFhIzY1hrWV}/_ssgManifest.js +0 -0
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[796],{10313:(e,t,s)=>{s.d(t,{WT:()=>n,fl:()=>i,k8:()=>a});var r=s(61415);function a(e){window.dispatchEvent(new CustomEvent("gsd:navigate-view",{detail:{view:e}}))}function n({dispatch:e}){e().catch(e=>{console.error("[workflow-action] dispatch failed:",e)}),a("vibe-coder"===(0,r.B3)()?"chat":"power")}function i({commandInFlight:e,terminalLines:t}){if(!e)return null;for(let e=t.length-1;e>=0;e-=1){let s=t[e];if("input"!==s.type)continue;let r=s.content.trim();if(r)return r}return"prompt"===e?"Sending command":`/${e}`}},14156:(e,t,s)=>{s.d(t,{x:()=>C});var r=s(18870),a=s(45110),n=s(20559),i=s(66828),o=s(18366),l=s(92525),d=s(96526),c=s(52160),u=s(46518),m=s(18833),h=s(69745);let x=/Git Ship Done v\d+\.\d+\.\d+/i;function p(e,t){if(0===t)return 0;let s=0;for(let r=0;r<e.length;r+=1)if("\n"===e[r]&&(s+=1)===t)return r+1;return null}function g(e){return!e||0===e.trim().length}function f(e){return!!e&&/[█╔╗╚╝║═]/.test(e)}var b=s(40525),v=s(83890),j=s(81462);function y(e,t){if(!e||!t)return null;let s=e.getBoundingClientRect();return s.width<180||s.height<120||t.cols<20||t.rows<8?null:{cols:t.cols,rows:t.rows}}async function w(e,t,s,r){if("u">typeof document&&"fonts"in document)try{await Promise.race([document.fonts.ready,new Promise(e=>setTimeout(e,1e3))])}catch{}for(let a=0;a<12;a++){if(r()||(await new Promise(e=>{requestAnimationFrame(()=>e())}),r()))return null;try{s?.fit()}catch{}let a=y(e,t);if(a)return a;await new Promise(e=>setTimeout(e,50))}return y(e,t)}function N({sessionId:e,visible:t,command:n,commandArgs:o,isDark:l,fontSize:d,hideInitialGsdHeader:c=!1,projectCwd:u,onConnectionChange:h}){let y=(0,a.useRef)(null),S=(0,a.useRef)(null),k=(0,a.useRef)(null),C=(0,a.useRef)(null),A=(0,a.useRef)([]),R=(0,a.useRef)(!1),T=(0,a.useRef)(null),E=(0,a.useRef)(h),P=(0,a.useRef)(!c),_=(0,a.useRef)(""),I=(o??[]).join("\0"),[F,$]=(0,a.useState)(!1),L=(0,a.useCallback)((t,s)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{(0,v.tm)((0,b.$)("/api/terminal/resize",u),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,cols:t,rows:s})})},100)},[u,e]),D=(0,a.useCallback)(async()=>{if(!R.current){for(R.current=!0;A.current.length>0;){let t=A.current.shift();try{let s=await (0,v.tm)((0,b.$)("/api/terminal/input",u),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,data:t})});if(!s.ok){s.status>=500&&A.current.unshift(t),E.current(!1),S.current?.writeln(`\r
|
|
2
|
-
Input failed (${s.status}). Reconnect the terminal and retry.`);break}}catch{A.current.unshift(t),E.current(!1);break}}R.current=!1}},[u,e]),M=(0,a.useCallback)(e=>{A.current.push(e),D()},[D]);(0,a.useEffect)(()=>{E.current=h},[h]),(0,a.useEffect)(()=>{P.current=!c,_.current=""},[c,e]),(0,a.useEffect)(()=>{S.current&&(S.current.options.theme=(0,j.E)(l))},[l]),(0,a.useEffect)(()=>{if(S.current){S.current.options.fontSize=d??13;try{k.current?.fit(),S.current&&L(S.current.cols,S.current.rows)}catch{}}},[d,L]),(0,a.useEffect)(()=>{if(t&&k.current&&S.current){let e=setTimeout(()=>{try{k.current?.fit(),S.current&&L(S.current.cols,S.current.rows)}catch{}},50);return()=>clearTimeout(e)}},[t,L]),(0,a.useEffect)(()=>{if(!y.current)return;let t=!1,r=null,a=null,i=null;return(async()=>{let[{Terminal:m},{FitAddon:h}]=await Promise.all([s.e(7110).then(s.bind(s,30493)),s.e(5027).then(s.bind(s,5027))]);if(t||(r=new m((0,j.d)(l,d)),a=new h,r.loadAddon(a),r.open(y.current),S.current=r,k.current=a,await w(y.current,r,a,()=>t),t))return;r.onData(e=>M(e)),r.onBinary(e=>M(e));let N=(0,b.Y)("/api/terminal/stream",window.location.origin,u);for(let t of(N.searchParams.set("id",e),n&&N.searchParams.set("command",n),o??[]))N.searchParams.append("arg",t);let A=new EventSource((0,v.QT)(N.toString()));C.current=A,A.onmessage=e=>{try{let s=JSON.parse(e.data);if("connected"===s.type)E.current(!0),w(y.current,r,a,()=>t).then(e=>{e&&L(e.cols,e.rows)});else if("output"===s.type&&s.data){let e=s.data;if(c&&!P.current){_.current+=e;let t=function(e){let{plainText:t,rawOffsetsByPlainIndex:s}=function(e){let t="",s=[0];for(let r=0;r<e.length;){let a=e[r];if("\x1b"===a){let t=e[r+1];if("["===t){for(r+=2;r<e.length&&!/[A-~]/.test(e[r]);)r+=1;r<e.length&&(r+=1);continue}if("]"===t){for(r+=2;r<e.length;){if("\x07"===e[r]){r+=1;break}if("\x1b"===e[r]&&"\\"===e[r+1]){r+=2;break}r+=1}continue}if("P"===t||"^"===t||"_"===t||"X"===t){for(r+=2;r<e.length;){if("\x1b"===e[r]&&"\\"===e[r+1]){r+=2;break}r+=1}continue}r+=t?2:1;continue}if("\r"===a){r+=1;continue}r+=1,s[(t+=a).length]=r}return{plainText:t,rawOffsetsByPlainIndex:s}}(e);if(!t)return{status:"needs-more",text:""};let r=t.split("\n"),a=r.find(e=>!g(e));if(a&&!f(a))return{status:"passthrough",text:e};let n=r.findIndex(e=>x.test(e));if(-1===n)return r.length>=16||t.length>=4096?{status:"passthrough",text:e}:{status:"needs-more",text:""};if(n<6)return{status:"passthrough",text:e};let i=r.slice(n-6,n);if(6!==i.length||!i.every(f))return{status:"passthrough",text:e};let o=p(t,n+1);if(null===o)return{status:"needs-more",text:""};let l=o,d=n+1;for(;g(r[d]);){let e=p(t,d+1);if(null===e)break;l=e,d+=1}let c=s[l]??e.length;return{status:"matched",text:e.slice(c)}}(_.current);if("needs-more"===t.status)return;P.current=!0,_.current="",e=t.text}e&&(r?.write(e),$(!0))}}catch{}},A.onerror=()=>E.current(!1),(i=new ResizeObserver(()=>{if(!t)try{a?.fit(),r&&L(r.cols,r.rows)}catch{}})).observe(y.current)})(),()=>{t=!0,T.current&&clearTimeout(T.current),C.current?.close(),C.current=null,i?.disconnect(),r?.dispose(),S.current=null,k.current=null}},[e,n,o,I,d,c,l,u,M,L]);let q=(0,a.useRef)(null),B=(0,a.useCallback)(()=>{S.current?.focus()},[]);return(0,a.useEffect)(()=>{let e=q.current;if(!e)return;let t=e=>{"Enter"!==e.key||!e.shiftKey||e.ctrlKey||e.altKey||e.metaKey||(e.preventDefault(),e.stopPropagation(),M("\n"))};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[M]),(0,a.useEffect)(()=>{if(t){let e=setTimeout(()=>S.current?.focus(),80);return()=>clearTimeout(e)}},[t]),(0,r.jsxs)("div",{ref:q,className:(0,m.cn)("relative h-full w-full bg-terminal",!t&&"hidden"),onClick:B,children:[!F&&(0,r.jsxs)("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-terminal",children:[(0,r.jsx)(i.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:n?"Starting GSD…":"Connecting…"})]}),(0,r.jsx)("div",{ref:y,className:"h-full w-full",style:{padding:"8px 4px 4px 8px"}})]})}s(76490);let S=new Set(["image/jpeg","image/png","image/gif","image/webp"]);async function k(e,t,s){let r,a=(0,h.Wl)(e);if(!a.valid)return void console.warn("[terminal-upload] validation failed:",a.error);let n=new FormData;n.append("file",e);try{let e=await (0,v.tm)((0,b.$)("/api/terminal/upload",s),{method:"POST",body:n}),t=await e.json();if(!e.ok||!t.path)return void console.error("[terminal-upload] upload failed:",t.error??`HTTP ${e.status}`);r=t.path}catch(e){console.error("[terminal-upload] upload request failed:",e);return}try{let e=await (0,v.tm)((0,b.$)("/api/terminal/input",s),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,data:`@${r} `})});if(!e.ok){let t=await e.json().catch(()=>({}));console.error("[terminal-upload] inject failed:",t.error??`HTTP ${e.status}`)}}catch(e){console.error("[terminal-upload] inject request failed:",e)}}function C({className:e,command:t,commandArgs:s,sessionPrefix:i,hideSidebar:h=!1,fontSize:x,hideInitialGsdHeader:p=!1,projectCwd:g}){let f,{resolvedTheme:j}=(0,n.D)(),y="light"!==j,w=(f=i??(t?"gsd-default":"default"),g?`${f}:${g}`:f),A=function(e){if(!e?.trim())return"zsh";let t=e.trim().split(/\s+/)[0]||e,s=t.replace(/\\/g,"/").split("/");return s[s.length-1]||t}(t),[R,T]=(0,a.useState)([{id:w,label:A,connected:!1}]),[E,P]=(0,a.useState)(w),[_,I]=(0,a.useState)(!1),[F,$]=(0,a.useState)(null),L=(0,a.useRef)(null),D=(0,a.useRef)(w);(0,a.useEffect)(()=>{D.current!==w&&(D.current=w,T([{id:w,label:A,connected:!1}]),P(w),$(null))},[w,A]),(0,a.useEffect)(()=>{let e=L.current;if(!e)return;let t=0,s=e=>{e.preventDefault(),e.stopPropagation(),1===(t+=1)&&I(!0)},r=e=>{e.preventDefault(),e.stopPropagation()},a=e=>{e.preventDefault(),e.stopPropagation(),(t-=1)<=0&&(t=0,I(!1))},n=e=>{if(e.preventDefault(),e.stopPropagation(),t=0,I(!1),!E)return;let s=Array.from(e.dataTransfer?.files??[]).find(e=>S.has(e.type));s&&k(s,E,g)};return e.addEventListener("dragenter",s,!0),e.addEventListener("dragover",r,!0),e.addEventListener("dragleave",a,!0),e.addEventListener("drop",n,!0),()=>{e.removeEventListener("dragenter",s,!0),e.removeEventListener("dragover",r,!0),e.removeEventListener("dragleave",a,!0),e.removeEventListener("drop",n,!0)}},[E,g]),(0,a.useEffect)(()=>{let e=L.current;if(!e)return;let t=e=>{if(!e.clipboardData)return;let t=Array.from(e.clipboardData.files).find(e=>S.has(e.type));t&&(e.preventDefault(),e.stopPropagation(),E&&k(t,E,g))};return e.addEventListener("paste",t,!0),()=>e.removeEventListener("paste",t,!0)},[E,g]);let M=(0,a.useCallback)(async()=>{try{let e=await (0,v.tm)((0,b.$)("/api/terminal/sessions",g),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{command:t}:{})});if(!e.ok)return void $(`Could not create terminal (${e.status}).`);let s=await e.json();if("string"!=typeof s.id||0===s.id.length)return void $("Could not create terminal: invalid server response.");let r={id:s.id,label:A,connected:!1};$(null),T(e=>[...e,r]),P(s.id)}catch(e){$(`Could not create terminal: ${e instanceof Error?e.message:String(e)}`)}},[t,A,g]),q=(0,a.useCallback)(e=>{if(R.length<=1)return;let t=(0,b.Y)("/api/terminal/sessions",window.location.origin,g);t.searchParams.set("id",e),(0,v.tm)(t.toString(),{method:"DELETE"});let s=R.filter(t=>t.id!==e);T(s),E===e&&P(s[s.length-1]?.id??w)},[R,E,w,g]),B=(0,a.useCallback)((e,t)=>{T(s=>s.map(s=>s.id===e?{...s,connected:t}:s))},[]);return(0,r.jsxs)("div",{className:(0,m.cn)("flex bg-terminal",e),children:[(0,r.jsxs)("div",{ref:L,className:"relative flex-1 min-w-0",children:[R.map(e=>(0,r.jsx)(N,{sessionId:e.id,visible:e.id===E,command:t,commandArgs:e.id===w?s:void 0,isDark:y,fontSize:x,hideInitialGsdHeader:p,projectCwd:g,onConnectionChange:t=>B(e.id,t)},e.id)),_&&(0,r.jsxs)("div",{className:"absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 bg-background backdrop-blur-sm border-2 border-dashed border-primary rounded-md pointer-events-none",children:[(0,r.jsx)(o.A,{className:"h-8 w-8 text-primary"}),(0,r.jsx)("span",{className:"text-sm font-medium text-primary",children:"Drop image here"})]}),F&&(0,r.jsxs)("div",{className:"absolute left-2 right-2 top-2 z-30 flex items-center gap-2 rounded border border-destructive/40 bg-background px-2 py-1 text-xs text-destructive shadow-sm",children:[(0,r.jsx)(l.A,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"min-w-0 truncate",children:F})]})]}),!h&&(0,r.jsxs)("div",{className:"flex w-[34px] flex-shrink-0 flex-col border-l border-border/50 bg-terminal",children:[(0,r.jsx)("button",{onClick:M,className:"flex h-[30px] w-full items-center justify-center text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",title:"New terminal",children:(0,r.jsx)(d.A,{className:"h-3 w-3"})}),(0,r.jsx)("div",{className:"h-px bg-border/50"}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto",children:R.map((e,t)=>(0,r.jsxs)("button",{onClick:()=>P(e.id),className:(0,m.cn)("group relative flex h-[30px] w-full items-center justify-center transition-colors",e.id===E?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"),title:`${e.label} ${t+1}`,children:[e.id===E&&(0,r.jsx)("div",{className:"absolute left-0 top-1.5 bottom-1.5 w-[2px] rounded-full bg-muted-foreground"}),(0,r.jsxs)("div",{className:"relative flex items-center",children:[(0,r.jsx)(c.A,{className:"h-3 w-3"}),(0,r.jsx)("span",{className:(0,m.cn)("absolute -bottom-0.5 -right-0.5 h-1.5 w-1.5 rounded-full border border-terminal",e.connected?"bg-success":"bg-muted-foreground/40")})]}),R.length>1&&(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),q(e.id)},className:"absolute -right-0.5 -top-0.5 z-10 hidden h-3.5 w-3.5 items-center justify-center rounded-full bg-accent text-muted-foreground hover:bg-destructive/20 hover:text-destructive group-hover:flex",title:"Kill terminal",children:(0,r.jsx)(u.A,{className:"h-2 w-2"})})]},e.id))})]})]})}},18833:(e,t,s)=>{s.d(t,{cn:()=>n});var r=s(88912),a=s(29048);function n(...e){return(0,a.QP)((0,r.$)(e))}},25847:(e,t,s)=>{s.d(t,{d:()=>i});var r=s(45110);let a="gsd-editor-font-size",n="editor-font-size-changed";function i(){let[e,t]=(0,r.useState)(()=>{try{let e=localStorage.getItem(a);if(e){let t=Number(e);if(Number.isFinite(t)&&t>=8&&t<=24)return t}}catch{}return 14}),s=(0,r.useCallback)(e=>{let s=Math.max(8,Math.min(24,Math.round(e)));t(s);try{localStorage.setItem(a,String(s))}catch{}window.dispatchEvent(new CustomEvent(n,{detail:s}))},[]);return(0,r.useEffect)(()=>{let e=e=>{if(e.key!==a)return;let s=Number(e.newValue);Number.isFinite(s)&&s>=8&&s<=24&&t(s)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]),(0,r.useEffect)(()=>{let e=e=>{let s=e.detail;Number.isFinite(s)&&s>=8&&s<=24&&t(s)};return window.addEventListener(n,e),()=>window.removeEventListener(n,e)},[]),[e,s]}},37144:(e,t,s)=>{s.d(t,{Q8:()=>A,Qx:()=>R,Yc:()=>P,c0:()=>T,iE:()=>f,ll:()=>r,nU:()=>E,yC:()=>_});let r=["off","minimal","low","medium","high","xhigh"];function a(){return{phase:"idle",data:null,error:null,lastLoadedAt:null}}function n(){return{forensics:a(),doctor:{phase:"idle",data:null,error:null,lastLoadedAt:null,fixPending:!1,lastFixResult:null,lastFixError:null},skillHealth:a()}}function i(){return{knowledge:a(),captures:a(),resolveRequest:{pending:!1,lastError:null,lastResult:null}}}function o(){return{history:a(),inspect:a(),hooks:a(),exportData:a(),undo:a(),cleanup:a(),steer:a()}}let l=new Set(["settings","login","logout"]),d={set_steering_mode:"steeringMode",set_follow_up_mode:"followUpMode",set_auto_compaction:"autoCompaction",set_auto_retry:"autoRetry",abort_retry:"abortRetry"};function c(e={}){return{scope:null,projectCwd:null,projectSessionsDir:null,activeSessionPath:null,query:"",sortMode:"threaded",nameFilter:"all",totalSessions:0,returnedSessions:0,sessions:[],loaded:!1,error:null,...e}}function u(){return{pending:!1,sessionPath:null,result:null,error:null}}function m(){return{pending:!1,result:null,error:null}}function h(){return{steeringMode:m(),followUpMode:m(),autoCompaction:m(),autoRetry:m(),abortRetry:m()}}function x(){return{pending:!1,loaded:!1,result:null,error:null}}function p(){return{phase:"idle",pending:!1,loaded:!1,stale:!1,diagnostics:null,error:null,lastLoadedAt:null,lastInvalidatedAt:null,lastFailureAt:null}}function g(e){return r.includes(e??"")}function f(){return{open:!1,activeSurface:null,source:null,section:null,args:"",pendingAction:null,selectedTarget:null,lastError:null,lastResult:null,availableModels:[],forkMessages:[],sessionStats:null,lastCompaction:null,gitSummary:x(),recovery:p(),diagnostics:n(),knowledgeCaptures:i(),settingsData:a(),remainingCommands:o(),sessionBrowser:c(),resumeRequest:u(),renameRequest:u(),settingsRequests:h()}}function b(e){switch(e.surface){case"model":return"model";case"thinking":return"thinking";case"settings":return e.onboardingLocked?"auth":"general";case"git":return"git";case"login":case"logout":return"auth";case"resume":return"resume";case"name":return"name";case"fork":return"fork";case"session":case"export":return"session";case"compact":return"compact";case"gsd-visualize":return"gsd-visualize";case"gsd-forensics":return"gsd-forensics";case"gsd-doctor":return"gsd-doctor";case"gsd-skill-health":return"gsd-skill-health";case"gsd-knowledge":return"gsd-knowledge";case"gsd-capture":return"gsd-capture";case"gsd-triage":return"gsd-triage";case"gsd-quick":return"gsd-quick";case"gsd-history":return"gsd-history";case"gsd-undo":return"gsd-undo";case"gsd-inspect":return"gsd-inspect";case"gsd-prefs":return"gsd-prefs";case"gsd-config":return"gsd-config";case"gsd-hooks":return"gsd-hooks";case"gsd-mode":return"gsd-mode";case"gsd-steer":return"gsd-steer";case"gsd-report":return"gsd-report";case"gsd-export":return"gsd-export";case"gsd-cleanup":return"gsd-cleanup";case"gsd-queue":return"gsd-queue";default:return null}}function v(e){return{kind:"settings",section:e}}function j(e){let t=e.args?.trim()||void 0;return{kind:"model",provider:e.currentModel?.provider,modelId:e.currentModel?.modelId,query:t}}function y(e){let t=e.args?.trim().toLowerCase()||"";return{kind:"thinking",level:g(t)?t:g(e.currentThinkingLevel)?e.currentThinkingLevel:"off"}}function w(e){return{kind:"auth",providerId:(e.args?.trim()||void 0)??e.preferredProviderId??void 0,intent:"login"===e.surface?"login":"logout"===e.surface?"logout":"manage"}}function N(e){return{kind:"resume",sessionPath:function(e,t){if(!e?.length)return;let s=t?.trim().toLowerCase();if(!s)return e.find(e=>!e.isActive)?.path??e[0]?.path;let r=e.find(e=>[e.id,e.name,e.path].filter(Boolean).map(e=>e.toLowerCase()).includes(s));return r?r.path:e.find(e=>[e.id,e.name,e.path].filter(Boolean).map(e=>e.toLowerCase()).some(e=>e.includes(s)))?.path}(e.resumableSessions,e.args)}}function S(e){return{kind:"fork",entryId:e.args?.trim()||void 0}}function k(e){return{kind:"session",outputPath:e.args?.trim()||void 0}}function C(e){return{kind:"compact",customInstructions:e.args?.trim()??""}}function A(e,t){let s,r=b(t);return{...e,open:!0,activeSurface:t.surface,source:t.source,section:r,args:t.args?.trim()??"",pendingAction:null,selectedTarget:function(e){if(void 0!==e.selectedTarget)return e.selectedTarget;let t=b(e);if(!t)return null;if("settings"===e.surface)return v(t);if("model"===e.surface)return j(e);if("thinking"===e.surface)return y(e);if(l.has(e.surface))return w(e);if("resume"===e.surface)return N(e);if("name"===e.surface){let t;return t=e.args?.trim(),{kind:"name",sessionPath:e.currentSessionPath??void 0,name:void 0!==t&&t.length>0?t:e.currentSessionName?.trim()??""}}if("fork"===e.surface)return S(e);if("session"===e.surface||"export"===e.surface)return k(e);if("compact"===e.surface)return C(e);if(e.surface?.startsWith("gsd-")){let t=e.surface.slice(4);return{kind:"gsd",surface:e.surface,subcommand:t,args:e.args??""}}return v(t)}(t),lastError:null,lastResult:null,sessionStats:null,forkMessages:[],lastCompaction:null,gitSummary:x(),recovery:p(),diagnostics:n(),knowledgeCaptures:i(),settingsData:a(),remainingCommands:o(),sessionBrowser:(s="resume"===t.surface?t.args?.trim()??"":"",c({activeSessionPath:t.currentSessionPath??null,projectCwd:t.projectCwd??null,projectSessionsDir:t.projectSessionsDir??null,query:s,sortMode:s?"relevance":"threaded"})),resumeRequest:u(),renameRequest:u(),settingsRequests:h()}}function R(e){return{...e,open:!1,pendingAction:null}}function T(e,t,s={}){let r={surface:e.activeSurface??"settings",source:e.source??"surface",args:e.args,...s},a=e.selectedTarget?.kind==="resume"||e.selectedTarget?.kind==="name"?e.selectedTarget.sessionPath:void 0,n=e.selectedTarget?.kind==="name"?e.selectedTarget.name:void 0,i=e.selectedTarget;return"model"===t?i=j(r):"thinking"===t?i=y(r):"general"===t||"session-behavior"===t||"queue"===t||"compaction"===t||"retry"===t||"recovery"===t||"git"===t||"admin"===t?i=v(t):"auth"===t?i=w({...r,surface:"logout"===e.activeSurface?"logout":"login"===e.activeSurface?"login":"settings"}):"resume"===t?i={kind:"resume",sessionPath:a??N(r).sessionPath}:"name"===t?i={kind:"name",sessionPath:a??r.currentSessionPath??void 0,name:n??r.currentSessionName?.trim()??""}:"fork"===t?i=S(r):"session"===t?i=k(r):"compact"===t&&(i=C(r)),{...e,section:t,selectedTarget:i}}function E(e,t){let s="settings"===t.kind?t.section:"model"===t.kind?"model":"thinking"===t.kind?"thinking":"auth"===t.kind?"auth":"resume"===t.kind?"resume":"name"===t.kind?"name":"fork"===t.kind?"fork":"session"===t.kind?"session":"compact";return{...e,section:s,selectedTarget:t,lastError:null,lastResult:null}}function P(e,t,s=e.selectedTarget){let r="switch_session"===t?{pending:!0,sessionPath:s?.kind==="resume"?s.sessionPath??null:null,result:null,error:null}:e.resumeRequest,a="rename_session"===t?{pending:!0,sessionPath:s?.kind==="name"?s.sessionPath??null:null,result:null,error:null}:e.renameRequest,n=d[t],i=n?{...e.settingsRequests,[n]:{pending:!0,result:null,error:null}}:e.settingsRequests;return{...e,pendingAction:t,selectedTarget:s,lastError:null,lastResult:null,gitSummary:"load_git_summary"===t?{...e.gitSummary,pending:!0,error:null}:e.gitSummary,recovery:"load_recovery_diagnostics"===t?{...e.recovery,pending:!0,error:null,phase:e.recovery.loaded?e.recovery.phase:"loading"}:e.recovery,sessionBrowser:"load_session_browser"===t?{...e.sessionBrowser,error:null}:e.sessionBrowser,resumeRequest:r,renameRequest:a,settingsRequests:i}}function _(e,t){let s=void 0===t.selectedTarget?e.selectedTarget:t.selectedTarget,r=(s?.kind==="resume"?s.sessionPath:void 0)??e.resumeRequest.sessionPath,a=(s?.kind==="name"?s.sessionPath:void 0)??e.renameRequest.sessionPath,n=d[t.action],i=n?{...e.settingsRequests,[n]:{pending:!1,result:t.success?t.message:null,error:t.success?null:t.message}}:e.settingsRequests;return{...e,pendingAction:null,selectedTarget:s,availableModels:t.availableModels??e.availableModels,forkMessages:t.forkMessages??e.forkMessages,sessionStats:void 0===t.sessionStats?e.sessionStats:t.sessionStats,lastCompaction:void 0===t.lastCompaction?e.lastCompaction:t.lastCompaction,gitSummary:void 0===t.gitSummary?e.gitSummary:{...t.gitSummary,pending:!1,loaded:t.gitSummary.loaded||t.success},recovery:t.recovery??e.recovery,sessionBrowser:t.sessionBrowser??e.sessionBrowser,resumeRequest:"switch_session"===t.action?{pending:!1,sessionPath:r??null,result:t.success?t.message:null,error:t.success?null:t.message}:e.resumeRequest,renameRequest:"rename_session"===t.action?{pending:!1,sessionPath:a??null,result:t.success?t.message:null,error:t.success?null:t.message}:e.renameRequest,settingsRequests:i,lastError:t.success?null:t.message,lastResult:t.success?t.message:null}}},40525:(e,t,s)=>{function r(e,t){if(!t)return e;let s=new URL(e,"http://localhost");return s.searchParams.set("project",t),s.pathname+s.search}function a(e,t,s){return new URL(r(e,s),t)}s.d(t,{$:()=>r,Y:()=>a})},43106:(e,t,s)=>{s.d(t,{p:()=>n});var r=s(18870);s(45110);var a=s(18833);function n({className:e,type:t,...s}){return(0,r.jsx)("input",{type:t,"data-slot":"input",className:(0,a.cn)("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",e),...s})}},46054:(e,t,s)=>{function r(e,t){if(e.status)switch(e.status){case"complete":return"done";case"active":return"in-progress";case"pending":return"pending";case"parked":return"parked"}return e.slices.length>0&&e.slices.every(e=>e.done)?"done":t.milestoneId===e.id||e.slices.some(e=>e.done)?"in-progress":"pending"}function a(e,t,s){return t.done?"done":s.milestoneId===e&&s.sliceId===t.id?"in-progress":"pending"}function n(e,t,s,r){return s.done?"done":r.milestoneId===e&&r.sliceId===t&&r.taskId===s.id?"in-progress":"pending"}s.d(t,{Jq:()=>r,g$:()=>n,z3:()=>a})},59727:(e,t,s)=>{s.d(t,{L:()=>r});function r(e){let t,{phase:s,autoActive:r,autoPaused:a,onboardingLocked:n,commandInFlight:i,bootStatus:o,hasMilestones:l,stepMode:d=!1,projectDetectionKind:c}=e;if(c&&"active-gsd"!==c&&"empty-gsd"!==c)return{primary:null,secondaries:[],disabled:!0,disabledReason:"Project setup pending",isNewMilestone:!1};let u=!1;null!==i?(u=!0,t="Command in progress"):"ready"!==o?(u=!0,t="Workspace not ready"):n&&(u=!0,t="Setup required");let m=null,h=[],x=!1;return r&&!a?m={label:"Stop Auto",command:"/gsd stop",variant:"destructive"}:d&&l&&"complete"!==s&&"blocked"!==s?m={label:"Next Step",command:"/gsd next",variant:"default"}:a?m={label:"Resume Auto",command:"/gsd auto",variant:"default"}:("complete"===s?(m={label:"New Milestone",command:"/gsd",variant:"default"},x=!0):"planning"===s?m={label:"Plan",command:"/gsd",variant:"default"}:"executing"===s||"summarizing"===s?m={label:"Start Auto",command:"/gsd auto",variant:"default"}:"pre-planning"!==s||l?"blocked"===s?(m={label:"Blocked",command:"/gsd",variant:"default"},u=!0,t="Project is blocked — check blockers"):m="paused"===s?{label:"Resume",command:"/gsd auto",variant:"default"}:"validating-milestone"===s?{label:"Validate",command:"/gsd",variant:"default"}:"completing-milestone"===s?{label:"Complete Milestone",command:"/gsd",variant:"default"}:"needs-discussion"===s?{label:"Discuss",command:"/gsd",variant:"default"}:"replanning-slice"===s?{label:"Replan",command:"/gsd",variant:"default"}:{label:"Continue",command:"/gsd",variant:"default"}:m={label:"Initialize Project",command:"/gsd",variant:"default"},"/gsd next"===m.command||x||h.push({label:"Step",command:"/gsd next"})),{primary:m,secondaries:h,disabled:u,disabledReason:t,isNewMilestone:x}}},61415:(e,t,s)=>{s.d(t,{B3:()=>c,s1:()=>u});var r=s(45110);let a="gsd-user-mode",n="expert",i=new Set;function o(e){return i.add(e),()=>{i.delete(e)}}function l(){let e=localStorage.getItem(a);return"expert"===e||"vibe-coder"===e?e:n}function d(){return n}function c(){return l()}function u(){return[(0,r.useSyncExternalStore)(o,l,d),(0,r.useCallback)(e=>{localStorage.setItem(a,e),i.forEach(e=>e())},[])]}},69745:(e,t,s)=>{s.d(t,{Aw:()=>l,Wl:()=>n,wN:()=>a,zF:()=>o});let r=new Set(["image/jpeg","image/png","image/gif","image/webp"]),a=5;function n(e){if(!r.has(e.type)){let t=`Unsupported image type: ${e.type||"unknown"}. Accepted: JPEG, PNG, GIF, WebP.`;return console.warn("[image-utils] validation failed:",t),{valid:!1,error:t}}if(e.size>0x1400000){let t=(e.size/1048576).toFixed(1),s=`Image too large (${t} MB). Maximum: 20 MB.`;return console.warn("[image-utils] validation failed:",s),{valid:!1,error:s}}return{valid:!0}}async function i(e,t){var s,r;let a=.75*e.length;if(("image/gif"===t||"image/webp"===t)&&a<=4718592)return{data:e,mimeType:t};let n=await (s=e,r=t,new Promise((e,t)=>{let a=new Image;a.onload=()=>e(a),a.onerror=()=>t(Error("Failed to decode image")),a.src=`data:${r};base64,${s}`})),i=n.width>2e3||n.height>2e3;if(!i&&!(a>4718592))return{data:e,mimeType:t};let o="image/gif"===t||"image/webp"===t?"image/jpeg":t,l=n.width,d=n.height;if(i){let e=Math.min(2e3/n.width,2e3/n.height);l=Math.round(n.width*e),d=Math.round(n.height*e)}let c=document.createElement("canvas");c.width=l,c.height=d;let u=c.getContext("2d");if(!u)throw Error("Canvas 2D context not available");u.drawImage(n,0,0,l,d);let m=c.toDataURL(o,"image/jpeg"===o?.85:void 0).split(",")[1],h=.75*m.length;if(h>4718592)throw Error(`Image still exceeds 4.5 MB after resize (${(h/1048576).toFixed(1)} MB). Try a smaller image.`);return{data:m,mimeType:o}}async function o(e){let t=n(e);if(!t.valid)throw Error(t.error);return i(await new Promise((t,s)=>{let r=new FileReader;r.onload=()=>{let e=new Uint8Array(r.result),s="";for(let t=0;t<e.length;t++)s+=String.fromCharCode(e[t]);t(btoa(s))},r.onerror=()=>s(Error("Failed to read image file")),r.readAsArrayBuffer(e)}),e.type)}function l(){return`img-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}},72202:(e,t,s)=>{s.d(t,{A:()=>i});var r=s(45110);let a="gsd-terminal-font-size",n="terminal-font-size-changed";function i(){let[e,t]=(0,r.useState)(()=>{try{let e=localStorage.getItem(a);if(e){let t=Number(e);if(Number.isFinite(t)&&t>=8&&t<=24)return t}}catch{}return 13}),s=(0,r.useCallback)(e=>{let s=Math.max(8,Math.min(24,Math.round(e)));t(s);try{localStorage.setItem(a,String(s))}catch{}window.dispatchEvent(new CustomEvent(n,{detail:s}))},[]);return(0,r.useEffect)(()=>{let e=e=>{if(e.key!==a)return;let s=Number(e.newValue);Number.isFinite(s)&&s>=8&&s<=24&&t(s)};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]),(0,r.useEffect)(()=>{let e=e=>{let s=e.detail;Number.isFinite(s)&&s>=8&&s<=24&&t(s)};return window.addEventListener(n,e),()=>window.removeEventListener(n,e)},[]),[e,s]}},78300:(e,t,s)=>{function r(e){let t=Number(e)||0;return t<.01?`$${t.toFixed(4)}`:t<1?`$${t.toFixed(3)}`:`$${t.toFixed(2)}`}function a(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}K`:`${(e/1e6).toFixed(2)}M`}function n(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let s=Math.floor(t/60),r=t%60;if(s<60)return r>0?`${s}m ${r}s`:`${s}m`;let a=Math.floor(s/60),n=s%60;return n>0?`${a}h ${n}m`:`${a}h`}function i(e){let t={pending:0,triaged:0,resolved:0};for(let s of e.entries)t[s.status]+=1;return t}s.d(t,{BD:()=>r,a3:()=>n,ap:()=>a,vX:()=>i})},81462:(e,t,s)=>{s.d(t,{E:()=>o,d:()=>l});let r={background:"#18181e",foreground:"#e4e4e7",cursor:"#e4e4e7",cursorAccent:"#18181e",selectionBackground:"#2a2f3f",selectionForeground:"#e4e4e7",black:"#1e1e24",red:"#cc6666",green:"#b5bd68",yellow:"#e6b800",blue:"#5f87ff",magenta:"#9575cd",cyan:"#00d7ff",white:"#e4e4e7",brightBlack:"#666666",brightRed:"#e07b7b",brightGreen:"#c3cf79",brightYellow:"#f0c95a",brightBlue:"#81a2ff",brightMagenta:"#b294bb",brightCyan:"#53e5ff",brightWhite:"#fafafa"},a={background:"#05070f",foreground:"#e6edf3",cursor:"#e6edf3",cursorAccent:"#05070f",selectionBackground:"#1b2440",selectionForeground:"#e6edf3",black:"#111827",red:"#ff6b8a",green:"#34d399",yellow:"#ffd166",blue:"#4f8cff",magenta:"#d266ff",cyan:"#22d3ee",white:"#e6edf3",brightBlack:"#64748b",brightRed:"#ff8fab",brightGreen:"#4ade80",brightYellow:"#ffe08a",brightBlue:"#82b1ff",brightMagenta:"#e29bff",brightCyan:"#67e8f9",brightWhite:"#ffffff"},n={background:"#f5f5f5",foreground:"#18181b",cursor:"#18181b",cursorAccent:"#f5f5f5",selectionBackground:"#d4d4d8",selectionForeground:"#18181b",black:"#18181b",red:"#b91c1c",green:"#166534",yellow:"#854d0e",blue:"#1d4ed8",magenta:"#7e22ce",cyan:"#0f766e",white:"#52525b",brightBlack:"#71717a",brightRed:"#dc2626",brightGreen:"#15803d",brightYellow:"#713f12",brightBlue:"#2563eb",brightMagenta:"#9333ea",brightCyan:"#0f766e",brightWhite:"#27272a"},i={background:"#f8fafc",foreground:"#0f172a",cursor:"#0f172a",cursorAccent:"#f8fafc",selectionBackground:"#cbd5e1",selectionForeground:"#0f172a",black:"#0f172a",red:"#be123c",green:"#166534",yellow:"#92400e",blue:"#1d4ed8",magenta:"#7e22ce",cyan:"#0f766e",white:"#334155",brightBlack:"#475569",brightRed:"#e11d48",brightGreen:"#15803d",brightYellow:"#854d0e",brightBlue:"#2563eb",brightMagenta:"#9333ea",brightCyan:"#0e7490",brightWhite:"#1e293b"};function o(e,t="classic"){return"vivid"===t?e?a:i:e?r:n}function l(e,t,s="classic"){return{cursorBlink:!0,cursorStyle:"bar",fontSize:t??13,fontFamily:"'SF Mono', 'Cascadia Code', 'Fira Code', Menlo, Monaco, 'Courier New', monospace",lineHeight:1.35,letterSpacing:0,theme:o(e,s),allowProposedApi:!0,scrollback:1e4,convertEol:!1}}},83890:(e,t,s)=>{s.d(t,{QT:()=>o,c4:()=>n,tm:()=>i});let r="gsd-auth-token",a=null;function n(){if(null!==a)return a;let e=window.location.hash;if(e){let t=e.match(/token=([a-fA-F0-9]+)/);if(t){a=t[1];try{localStorage.setItem(r,a)}catch{}return window.history.replaceState(null,"",window.location.pathname+window.location.search),a}}try{let e=localStorage.getItem(r);if(e)return a=e}catch{}return null}async function i(e,t){let s=n(),r=new Headers(t?.headers);return s&&!r.has("Authorization")&&r.set("Authorization",`Bearer ${s}`),fetch(e,{...t,headers:r})}function o(e){let t=n();if(!t)return e;let s=e.includes("?")?"&":"?";return`${e}${s}_token=${t}`}window.addEventListener("storage",e=>{e.key===r&&e.newValue&&(a=e.newValue)})},90796:(e,t,s)=>{s.r(t),s.d(t,{GSDAppShell:()=>aj});var r=s(18870),a=s(89581),n=s(23711),i=s(45110),o=s(46518),l=s(65797),d=s(66840),c=s(85429),u=s(20607),m=s(53348),h=s(32457),x=s(62970),p=s(48632),g=s(87339),f=s(48768),b=s(23189),v=s(58718),j=s(90034),y=s(8992),w=s(57818),N=s(8959),S=s(15007),k=s(25490),C=s(55285),A=s(61999),R=s(20437),T=s(87942),E=s(72852),P=s(78070),_=s(76756),I=s(51738),F=s(66828),$=s(24028),L=s(68154),D=s(35540),M=s(18833);function q({...e}){return(0,r.jsx)(D.bL,{"data-slot":"dialog",...e})}function B({...e}){return(0,r.jsx)(D.ZL,{"data-slot":"dialog-portal",...e})}function O({className:e,...t}){return(0,r.jsx)(D.hJ,{"data-slot":"dialog-overlay",className:(0,M.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t})}function U({className:e,children:t,showCloseButton:s=!0,...a}){return(0,r.jsxs)(B,{"data-slot":"dialog-portal",children:[(0,r.jsx)(O,{}),(0,r.jsxs)(D.UC,{"data-slot":"dialog-content",className:(0,M.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",e),...a,children:[t,s&&(0,r.jsxs)(D.bm,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[(0,r.jsx)(o.A,{}),(0,r.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})}function z({className:e,...t}){return(0,r.jsx)("div",{"data-slot":"dialog-header",className:(0,M.cn)("flex flex-col gap-2 text-center sm:text-left",e),...t})}function G({className:e,...t}){return(0,r.jsx)("div",{"data-slot":"dialog-footer",className:(0,M.cn)("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...t})}function W({className:e,...t}){return(0,r.jsx)(D.hE,{"data-slot":"dialog-title",className:(0,M.cn)("text-lg leading-none font-semibold",e),...t})}function K({className:e,...t}){return(0,r.jsx)(D.VY,{"data-slot":"dialog-description",className:(0,M.cn)("text-muted-foreground text-sm",e),...t})}var V=s(31841),H=s(95426);let Y=(0,H.F)("relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium outline-none transition-[color,background-color,border-color,box-shadow,transform] duration-150 ease-out disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5 before:absolute before:left-1/2 before:top-1/2 before:h-10 before:w-full before:min-w-10 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8 before:absolute before:left-1/2 before:top-1/2 before:size-10 before:-translate-x-1/2 before:-translate-y-1/2 before:content-['']","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function J({className:e,variant:t,size:s,asChild:a=!1,static:n=!1,...i}){let o=a?V.DX:"button";return(0,r.jsx)(o,{"data-slot":"button",className:(0,M.cn)(Y({variant:t,size:s}),!n&&"active:scale-[0.96]",e),...i})}var Q=s(20559),Z=s(93058),X=s(46054),ee=s(59727),et=s(10313);class es{getActiveStore(){return this.activeProjectCwd?this.stores.get(this.activeProjectCwd)??null:null}getActiveProjectCwd(){return this.activeProjectCwd}switchProject(e){if(this.activeProjectCwd&&this.activeProjectCwd!==e){let e=this.stores.get(this.activeProjectCwd);e&&e.disconnectSSE()}let t=this.stores.get(e);return t?t.reconnectSSE():(t=new Z.Hu(e),this.stores.set(e,t),t.start()),this.activeProjectCwd=e,this.notify(),t}disposeAll(){for(let e of this.stores.values())e.dispose();this.stores.clear(),this.activeProjectCwd=null,this.notify()}closeProject(e){let t=this.stores.get(e);if(t){if(t.dispose(),this.stores.delete(e),this.activeProjectCwd===e){let e=Array.from(this.stores.keys());if(e.length>0){let t=this.stores.get(e[0]);this.activeProjectCwd=e[0],t.reconnectSSE()}else this.activeProjectCwd=null}this.notify()}}getProjectCount(){return this.stores.size}getActiveProjectPaths(){return Array.from(this.stores.keys())}notify(){for(let e of this.listeners)e()}constructor(){this.stores=new Map,this.activeProjectCwd=null,this.listeners=new Set,this.subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e)),this.getSnapshot=()=>this.activeProjectCwd}}let er=(0,i.createContext)(null);function ea({children:e}){let[t]=(0,i.useState)(()=>new es);return(0,i.useEffect)(()=>()=>t.disposeAll(),[t]),(0,r.jsx)(er.Provider,{value:t,children:e})}function en(){let e=(0,i.useContext)(er);if(!e)throw Error("useProjectStoreManager must be used within ProjectStoreManagerProvider");return e}function ei({className:e,...t}){return(0,r.jsx)("div",{"data-slot":"skeleton",className:(0,M.cn)("bg-accent animate-pulse rounded-md",e),...t})}var eo=s(83890);let el=({status:e})=>"done"===e?(0,r.jsx)(u.A,{className:"h-4 w-4 shrink-0 text-success"}):"in-progress"===e?(0,r.jsx)(m.A,{className:"h-4 w-4 shrink-0 text-warning"}):"parked"===e?(0,r.jsx)(h.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):(0,r.jsx)(x.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"});function ed({activeView:e,onViewChange:t,isConnecting:s=!1}){let{openCommandSurface:a}=(0,Z._l)(),n=en(),o=(0,i.useSyncExternalStore)(n.subscribe,n.getSnapshot,n.getSnapshot),[l,u]=(0,i.useState)(!1),{theme:m,setTheme:h}=(0,Q.D)(),x="light"===m?p.A:"dark"===m?g.A:f.A,T="light"===m?"Light":"dark"===m?"Dark":"System",E=[{id:"dashboard",label:"Dashboard",icon:b.A},{id:"power",label:"Power Mode",icon:v.A},{id:"chat",label:"Chat",icon:j.A},{id:"roadmap",label:"Roadmap",icon:y.A},{id:"files",label:"Files",icon:w.A},{id:"activity",label:"Activity",icon:N.A},{id:"visualize",label:"Visualize",icon:S.A}];return(0,r.jsxs)("div",{className:"flex w-12 flex-col items-center gap-1 border-r border-border bg-sidebar py-3",children:[E.map(a=>(0,r.jsx)("button",{onClick:()=>t(a.id),disabled:s,className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md transition-colors",s?"cursor-not-allowed text-muted-foreground/50":e===a.id?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),title:s?"Connecting…":a.label,children:(0,r.jsx)(a.icon,{className:"h-5 w-5"})},a.id)),(0,r.jsxs)("div",{className:"mt-auto flex flex-col gap-1",children:[(0,r.jsx)("button",{onClick:()=>window.dispatchEvent(new CustomEvent("gsd:open-projects")),disabled:s,className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md transition-colors",s?"cursor-not-allowed text-muted-foreground/50":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),title:s?"Connecting…":"Projects",children:(0,r.jsx)(k.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md text-muted-foreground transition-colors",s?"cursor-not-allowed opacity-30":"hover:bg-accent/50 hover:text-foreground"),title:"Git",disabled:s,onClick:()=>!s&&a("git",{source:"sidebar"}),"data-testid":"sidebar-git-button",children:(0,r.jsx)(C.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md text-muted-foreground transition-colors",s?"cursor-not-allowed opacity-30":"hover:bg-accent/50 hover:text-foreground"),title:"Settings",disabled:s,onClick:()=>!s&&a("settings",{source:"sidebar"}),"data-testid":"sidebar-settings-button",children:(0,r.jsx)(A.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md text-muted-foreground transition-colors",s?"cursor-not-allowed opacity-30":"hover:bg-accent/50 hover:text-foreground"),title:`Theme: ${T}`,disabled:s,onClick:()=>!s&&void("system"===m?h("light"):"light"===m?h("dark"):h("system")),"data-testid":"sidebar-theme-toggle",children:(0,r.jsx)("span",{className:"relative flex h-5 w-5 items-center justify-center",children:(0,r.jsx)(d.N,{mode:"wait",initial:!1,children:(0,r.jsx)(c.P.span,{className:"absolute inset-0 flex items-center justify-center",initial:{opacity:0,scale:.25,filter:"blur(4px)"},animate:{opacity:1,scale:1,filter:"blur(0px)"},exit:{opacity:0,scale:.25,filter:"blur(4px)"},transition:{type:"spring",duration:.3,bounce:0},children:(0,r.jsx)(x,{className:"h-5 w-5"})},T)})})}),(0,r.jsx)("button",{className:(0,M.cn)("flex h-10 w-10 items-center justify-center rounded-md text-muted-foreground transition-colors",s?"cursor-not-allowed opacity-30":"hover:bg-destructive/15 hover:text-destructive"),title:"Exit",disabled:s,onClick:()=>!s&&u(!0),"data-testid":"sidebar-signoff-button",children:(0,r.jsx)(R.A,{className:"h-5 w-5"})}),(0,r.jsx)(ec,{open:l,onOpenChange:u,projectCount:n.getProjectCount(),activeProjectCwd:o,onCloseProject:e=>{n.closeProject(e),t("dashboard"),u(!1)},onStopServer:async()=>{await (0,eo.tm)("/api/shutdown",{method:"POST"}).catch(()=>{}),setTimeout(()=>{try{window.close()}catch{}setTimeout(()=>{window.location.href="about:blank"},300)},400)}})]})]})}function ec({open:e,onOpenChange:t,projectCount:s,activeProjectCwd:a,onCloseProject:n,onStopServer:i}){let o=s>1,l=a?a.split("/").pop()??a:null;return o?(0,r.jsx)(q,{open:e,onOpenChange:t,children:(0,r.jsxs)(U,{className:"sm:max-w-md",children:[(0,r.jsxs)(z,{children:[(0,r.jsx)(W,{children:"Close project or stop server?"}),(0,r.jsxs)(K,{children:["You have ",s," projects open. You can close just the current project or stop the entire server."]})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 py-2",children:[a&&(0,r.jsxs)(J,{variant:"outline",className:"h-auto justify-start gap-3 px-4 py-3 text-left",onClick:()=>n(a),children:[(0,r.jsx)(k.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsxs)("div",{className:"text-sm font-medium",children:["Close ",l]}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:"Disconnect this project and switch to another"})]})]}),(0,r.jsxs)(J,{variant:"outline",className:"h-auto justify-start gap-3 px-4 py-3 text-left border-destructive/30 hover:bg-destructive/10 hover:text-destructive",onClick:i,children:[(0,r.jsx)(R.A,{className:"h-4 w-4 shrink-0"}),(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-medium",children:"Stop server"}),(0,r.jsxs)("div",{className:"text-xs text-muted-foreground",children:["Shut down all ",s," projects and close the tab"]})]})]})]}),(0,r.jsx)(G,{children:(0,r.jsx)(J,{variant:"ghost",onClick:()=>t(!1),children:"Cancel"})})]})}):(0,r.jsx)(q,{open:e,onOpenChange:t,children:(0,r.jsxs)(U,{className:"sm:max-w-md",children:[(0,r.jsxs)(z,{children:[(0,r.jsx)(W,{children:"Stop the GSD web server?"}),(0,r.jsxs)(K,{children:["This will shut down the server process and close this tab. Run"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"gsd --web"})," again to restart."]})]}),(0,r.jsxs)(G,{children:[(0,r.jsx)(J,{variant:"ghost",onClick:()=>t(!1),children:"Cancel"}),(0,r.jsx)(J,{variant:"destructive",onClick:i,children:"Stop server"})]})]})})}function eu({isConnecting:e=!1,width:t,onCollapse:s}){let a,n=(0,Z.gF)(),{openCommandSurface:o,setCommandSurfaceSection:l,sendCommand:d}=(0,Z._l)(),[c,u]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),g=(0,Z.Gr)(n),f=(0,i.useMemo)(()=>g?.milestones??[],[g?.milestones]),b=g?.active,v=(0,Z.CL)(n),j=n.live.recoverySummary,y=g?.validationIssues.length??0,w=(0,Z.U4)(g),N=n.boot?.project.cwd??null,S=n.boot?.bridge??null,k=(0,ee.L)({phase:g?.active.phase??"pre-planning",autoActive:v?.active??!1,autoPaused:v?.paused??!1,onboardingLocked:n.boot?.onboarding.locked??!1,commandInFlight:n.commandInFlight,bootStatus:n.bootStatus,hasMilestones:f.length>0,stepMode:v?.stepMode??!1,projectDetectionKind:n.boot?.projectDetection?.kind??null}),C=e=>{(0,et.WT)({dispatch:()=>d((0,Z.Sf)(e,S))})},A=b?.milestoneId&&!c.includes(b.milestoneId)?[...c,b.milestoneId]:c,R=b?.milestoneId&&b.sliceId?(a=`${b.milestoneId}-${b.sliceId}`,x.includes(a)?x:[...x,a]):x,L=new Map(f.map(e=>[e.id,(0,X.Jq)(e,b??{})]));return(0,r.jsxs)("div",{className:"flex flex-col bg-sidebar",style:{width:t??256,flexShrink:0},children:[e&&(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto px-1.5 py-1",children:[(0,r.jsx)("div",{className:"px-2 py-1.5",children:(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Milestones"})}),(0,r.jsx)("div",{className:"space-y-0.5 px-1",children:[1,2].map(e=>(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[(0,r.jsx)(ei,{className:"h-4 w-4 shrink-0 rounded"}),(0,r.jsx)(ei,{className:"h-4 w-4 shrink-0 rounded-full"}),(0,r.jsx)(ei,{className:(0,M.cn)("h-4",1===e?"w-40":"w-32")})]}),1===e&&(0,r.jsx)("div",{className:"ml-4 space-y-0.5",children:[1,2,3].map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5",children:[(0,r.jsx)(ei,{className:"h-4 w-4 shrink-0 rounded"}),(0,r.jsx)(ei,{className:"h-4 w-4 shrink-0 rounded-full"}),(0,r.jsx)(ei,{className:(0,M.cn)("h-3.5",1===e?"w-32":2===e?"w-28":"w-24")})]},e))})]},e))})]}),!e&&(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto px-1.5 py-1",children:[(0,r.jsxs)("div",{className:"flex items-start justify-between px-2 py-1.5",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Milestones"}),(0,r.jsx)("div",{className:"mt-1 text-xs text-foreground","data-testid":"sidebar-current-scope",children:w})]}),s&&(0,r.jsx)("button",{onClick:s,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:"Collapse sidebar",children:(0,r.jsx)(T.A,{className:"h-3.5 w-3.5"})})]}),"error"===n.bootStatus&&0===f.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-destructive",children:"Workspace boot failed before the explorer could load."}),"ready"===n.bootStatus&&0===f.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No milestones found for this project."}),f.map(e=>{let t=A.includes(e.id),s=b?.milestoneId===e.id,a=L.get(e.id)??"pending";return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>{var t;return t=e.id,void u(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},className:(0,M.cn)("flex w-full items-center gap-1.5 px-2 py-1.5 text-sm transition-colors hover:bg-accent/50",s&&"bg-accent/30"),children:[t?(0,r.jsx)(E.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):(0,r.jsx)(P.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,r.jsx)(el,{status:a}),(0,r.jsxs)("span",{className:(0,M.cn)("truncate",("pending"===a||"parked"===a)&&"text-muted-foreground"),children:[e.id,": ",e.title]})]}),t&&(0,r.jsx)("div",{className:"ml-4",children:e.slices.map(t=>{let s=`${e.id}-${t.id}`,a=R.includes(s),n=(0,X.z3)(e.id,t,b??{}),i=b?.milestoneId===e.id&&b.sliceId===t.id;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>{p(e=>e.includes(s)?e.filter(e=>e!==s):[...e,s])},className:(0,M.cn)("flex w-full items-center gap-1.5 px-2 py-1.5 text-sm transition-colors hover:bg-accent/50",i&&"bg-accent/20"),children:[a?(0,r.jsx)(E.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):(0,r.jsx)(P.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,r.jsx)(el,{status:n}),(0,r.jsxs)("span",{className:(0,M.cn)("truncate text-[13px]","pending"===n&&"text-muted-foreground"),children:[t.id,": ",t.title]})]}),a&&(0,r.jsxs)("div",{className:"ml-5",children:[t.branch&&(0,r.jsx)("div",{className:"px-2 py-0.5 text-[10px] uppercase tracking-wider text-muted-foreground",children:t.branch}),t.tasks.map(a=>{let n=(0,X.g$)(e.id,t.id,a,b??{}),o=!!(a.planPath||a.summaryPath);return(0,r.jsxs)("button",{type:"button",onClick:()=>(e=>{if(!e||!N)return;let t=`${N}/.gsd/`;if(!e.startsWith(t))return;let s=e.slice(t.length);window.dispatchEvent(new CustomEvent("gsd:open-file",{detail:{root:"gsd",path:s}}))})(a.summaryPath??a.planPath),disabled:!o,className:(0,M.cn)("flex w-full items-center gap-1.5 px-2 py-1 text-xs transition-colors",o?"cursor-pointer hover:bg-accent/50":"cursor-default opacity-70",b?.taskId===a.id&&i&&"bg-accent/10"),children:[(0,r.jsx)(_.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,r.jsx)(el,{status:n}),(0,r.jsxs)("span",{className:(0,M.cn)("truncate text-left","pending"===n&&"text-muted-foreground"),children:[a.id,": ",a.title]})]},`${s}-${a.id}`)})]})]},s)})})]},e.id)})]}),!e&&(0,r.jsx)("div",{className:"border-t border-border px-3 py-2.5",children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border bg-background px-3 py-2 text-xs",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsxs)("div",{className:"font-medium text-foreground","data-testid":"sidebar-validation-count",children:[y," validation issue",1===y?"":"s"]}),(0,r.jsx)("div",{className:"truncate text-muted-foreground",children:j.label})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>{o("settings",{source:"sidebar"}),l("recovery")},className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-border bg-card px-2.5 text-[11px] font-medium text-foreground transition-colors hover:bg-accent","data-testid":"sidebar-recovery-summary-entrypoint",children:[(0,r.jsx)(I.A,{className:"h-3.5 w-3.5"}),"Recovery"]})]})}),!e&&k.primary&&(0,r.jsx)("div",{className:"border-t border-border px-3 py-2.5",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("button",{onClick:()=>{k.primary&&C(k.primary.command)},disabled:k.disabled,className:(0,M.cn)("inline-flex h-9 flex-1 items-center justify-center gap-2 rounded-md px-3 text-sm font-medium transition-colors","destructive"===k.primary.variant?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90",k.disabled&&"cursor-not-allowed opacity-50"),title:k.disabledReason,children:[n.commandInFlight?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):k.isNewMilestone?(0,r.jsx)($.A,{className:"h-3.5 w-3.5"}):(0,r.jsx)(m.A,{className:"h-3.5 w-3.5"}),k.primary.label]}),k.secondaries.map(e=>(0,r.jsx)("button",{onClick:()=>C(e.command),disabled:k.disabled,className:(0,M.cn)("inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-background transition-colors hover:bg-accent",k.disabled&&"cursor-not-allowed opacity-50"),title:e.label,children:(0,r.jsx)(h.A,{className:"h-3.5 w-3.5"})},e.command))]})})]})}function em({onExpand:e}){let t=(0,Z.gF)(),{sendCommand:s}=(0,Z._l)(),a=(0,Z.Gr)(t),n=a?.milestones??[],i=(0,Z.CL)(t),o=t.boot?.bridge??null,l=(0,ee.L)({phase:a?.active.phase??"pre-planning",autoActive:i?.active??!1,autoPaused:i?.paused??!1,onboardingLocked:t.boot?.onboarding.locked??!1,commandInFlight:t.commandInFlight,bootStatus:t.bootStatus,hasMilestones:n.length>0,stepMode:i?.stepMode??!1,projectDetectionKind:t.boot?.projectDetection?.kind??null});return(0,r.jsxs)("div",{className:"flex h-full w-10 flex-col items-center border-l border-border bg-sidebar py-3",children:[(0,r.jsx)("button",{onClick:e,className:"flex h-8 w-8 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:"Expand milestone sidebar",children:(0,r.jsx)(L.A,{className:"h-4 w-4"})}),l.primary&&(0,r.jsx)("div",{className:"mt-auto pb-0.5",children:(0,r.jsx)("button",{onClick:()=>{if(l.primary){var e;e=l.primary.command,(0,et.WT)({dispatch:()=>s((0,Z.Sf)(e,o))})}},disabled:l.disabled,className:(0,M.cn)("flex h-8 w-8 items-center justify-center rounded-md transition-colors","destructive"===l.primary.variant?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90",l.disabled&&"cursor-not-allowed opacity-50"),title:l.disabledReason??l.primary.label,children:t.commandInFlight?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):l.isNewMilestone?(0,r.jsx)($.A,{className:"h-4 w-4"}):(0,r.jsx)(m.A,{className:"h-4 w-4"})})})]})}function eh({activeView:e,onViewChange:t,isConnecting:s=!1,mobile:a=!1}){return a?(0,r.jsx)(ex,{activeView:e,onViewChange:t,isConnecting:s}):(0,r.jsx)("div",{className:"flex h-full",children:(0,r.jsx)(ed,{activeView:e,onViewChange:t,isConnecting:s})})}function ex({activeView:e,onViewChange:t,isConnecting:s=!1}){let{openCommandSurface:a}=(0,Z._l)(),{theme:n,setTheme:i}=(0,Q.D)(),o="light"===n?p.A:"dark"===n?g.A:f.A,l=[{id:"dashboard",label:"Dashboard",icon:b.A},{id:"power",label:"Power Mode",icon:v.A},{id:"chat",label:"Chat",icon:j.A},{id:"roadmap",label:"Roadmap",icon:y.A},{id:"files",label:"Files",icon:w.A},{id:"activity",label:"Activity",icon:N.A},{id:"visualize",label:"Visualize",icon:S.A}];return(0,r.jsxs)("div",{className:"flex h-full flex-col bg-sidebar pt-14","data-testid":"mobile-nav-panel",children:[(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:l.map(a=>(0,r.jsxs)("button",{onClick:()=>t(a.id),disabled:s,className:(0,M.cn)("flex w-full items-center gap-3 rounded-md px-3 py-3 text-sm font-medium transition-colors min-h-[44px]",s?"cursor-not-allowed text-muted-foreground/50":e===a.id?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:[(0,r.jsx)(a.icon,{className:"h-5 w-5 shrink-0"}),a.label]},a.id))}),(0,r.jsxs)("div",{className:"border-t border-border px-2 py-2 space-y-1",children:[(0,r.jsxs)("button",{onClick:()=>window.dispatchEvent(new CustomEvent("gsd:open-projects")),disabled:s,className:"flex w-full items-center gap-3 rounded-md px-3 py-3 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors min-h-[44px]",children:[(0,r.jsx)(k.A,{className:"h-5 w-5 shrink-0"}),"Projects"]}),(0,r.jsxs)("button",{onClick:()=>!s&&a("git",{source:"sidebar"}),disabled:s,className:"flex w-full items-center gap-3 rounded-md px-3 py-3 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors min-h-[44px]",children:[(0,r.jsx)(C.A,{className:"h-5 w-5 shrink-0"}),"Git"]}),(0,r.jsxs)("button",{onClick:()=>!s&&a("settings",{source:"sidebar"}),disabled:s,className:"flex w-full items-center gap-3 rounded-md px-3 py-3 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors min-h-[44px]",children:[(0,r.jsx)(A.A,{className:"h-5 w-5 shrink-0"}),"Settings"]}),(0,r.jsxs)("button",{onClick:()=>!s&&void("system"===n?i("light"):"light"===n?i("dark"):i("system")),disabled:s,className:"flex w-full items-center gap-3 rounded-md px-3 py-3 text-sm text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors min-h-[44px]",children:[(0,r.jsx)(o,{className:"h-5 w-5 shrink-0"}),"Theme: ","light"===n?"Light":"dark"===n?"Dark":"System"]})]})]})}var ep=s(14156),eg=s(24896),ef=s(6742),eb=s(3733),ev=s(36542);function ej(){return(0,r.jsxs)("div",{className:"rounded-md border border-border bg-card",children:[(0,r.jsx)("div",{className:"border-b border-border px-4 py-3",children:(0,r.jsx)("h2",{className:"text-sm font-semibold",children:"Current Slice"})}),(0,r.jsx)("div",{className:"space-y-3 p-4",children:[1,2,3].map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)(ei,{className:"h-4 w-4 shrink-0 rounded-full"}),(0,r.jsx)(ei,{className:(0,M.cn)("h-4",1===e?"w-48":2===e?"w-40":"w-36")})]},e))})]})}function ey(){return(0,r.jsxs)("div",{className:"rounded-md border border-border bg-card",children:[(0,r.jsx)("div",{className:"border-b border-border px-4 py-3",children:(0,r.jsx)("h2",{className:"text-sm font-semibold",children:"Recent Activity"})}),(0,r.jsx)("div",{className:"divide-y divide-border",children:[1,2,3,4].map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[(0,r.jsx)(ei,{className:"h-3 w-16 shrink-0"}),(0,r.jsx)(ei,{className:"h-1.5 w-1.5 shrink-0 rounded-full"}),(0,r.jsx)(ei,{className:(0,M.cn)("h-4 flex-1",e%3==0?"max-w-xs":e%3==1?"max-w-sm":"max-w-md")})]},e))})]})}function ew(e){switch(e){case"complete":case"completed":return{label:"Complete",tone:"success"};case"executing":return{label:"Executing",tone:"active"};case"in-progress":return{label:"In Progress",tone:"active"};case"planning":return{label:"Planning",tone:"info"};case"pre-planning":return{label:"Pre-planning",tone:"muted"};case"researching":return{label:"Researching",tone:"info"};case"refining":return{label:"Refining",tone:"info"};case"summarizing":return{label:"Summarizing",tone:"info"};case"verifying":return{label:"Verifying",tone:"info"};case"blocked":return{label:"Blocked",tone:"warning"};case"paused":return{label:"Paused",tone:"warning"};case"needs-discussion":return{label:"Discussion",tone:"warning"};case"validating-milestone":return{label:"Validating",tone:"info"};case"replanning-slice":return{label:"Replanning",tone:"info"};case"escalating-task":return{label:"Escalating",tone:"warning"};case"completing-milestone":return{label:"Completing",tone:"info"};case"evaluating-gates":return{label:"Evaluating Gates",tone:"info"};default:return{label:e,tone:"muted"}}}let eN={success:"bg-success/15 text-success",active:"bg-primary/15 text-primary",warning:"bg-warning/15 text-warning",info:"bg-info/15 text-info",muted:"bg-muted text-muted-foreground"},eS={success:"bg-success",active:"bg-primary",warning:"bg-warning",info:"bg-info",muted:"bg-muted-foreground/50"};function ek(e){return e.replace(/([MST])0*(\d+)/g,"$1$2")}function eC(e){let t=e.match(/^(.+?)\s*—\s*(.+)$/);return t?{scopeId:ek(t[1].trim()),phase:t[2].trim()}:{scopeId:ek(e.trim()),phase:null}}function eA({label:e,size:t="md",className:s}){let{scopeId:a,phase:n}=eC(e);if("Project scope pending"===a)return(0,r.jsx)("span",{className:(0,M.cn)("text-muted-foreground",eR(t),s),children:"Scope pending…"});let i=n?ew(n):null;return(0,r.jsxs)("span",{className:(0,M.cn)("inline-flex items-center gap-2",s),children:[(0,r.jsx)("span",{className:(0,M.cn)("font-semibold tracking-tight tabular-nums","sm"===t?"text-sm":"text-lg"),children:a}),i&&(0,r.jsx)("span",{className:(0,M.cn)("inline-flex shrink-0 items-center rounded-full px-2 font-medium leading-snug",eN[i.tone],eR(t),"sm"===t?"py-px":"py-0.5"),children:i.label})]})}function eR(e){return"sm"===e?"text-[10px]":"text-[11px]"}function eT({label:e,className:t}){let{scopeId:s,phase:a}=eC(e);if("Project scope pending"===s)return(0,r.jsx)("span",{className:(0,M.cn)("text-muted-foreground",t),children:"Scope pending…"});let n=a?ew(a):null,i=n?eS[n.tone]:"bg-muted-foreground/50";return(0,r.jsxs)("span",{className:(0,M.cn)("inline-flex items-center gap-1.5",t),children:[(0,r.jsx)("span",{className:(0,M.cn)("h-1.5 w-1.5 shrink-0 rounded-full",i)}),(0,r.jsx)("span",{className:"tabular-nums",children:s}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-border",children:"\xb7"}),(0,r.jsx)("span",{children:n.label})]})]})}var eE=s(3445),eP=s(78564),e_=s(12601),eI=s(56478),eF=s(69558),e$=s(67504);function eL({icon:e,label:t}){return(0,r.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-card px-2.5 py-1 text-xs text-muted-foreground",children:[e,t]})}function eD({signals:e}){let t=[];return(e.hasGitRepo&&t.push({icon:(0,r.jsx)(C.A,{className:"h-3 w-3"}),label:"Git repository"}),e.hasPackageJson&&t.push({icon:(0,r.jsx)(eI.A,{className:"h-3 w-3"}),label:"Node.js project"}),e.fileCount>0&&t.push({icon:(0,r.jsx)(eF.A,{className:"h-3 w-3"}),label:`${e.fileCount} file${1===e.fileCount?"":"s"}`}),0===t.length)?null:(0,r.jsx)("div",{className:"flex flex-wrap gap-2",children:t.map(e=>(0,r.jsx)(eL,{icon:e.icon,label:e.label},e.label))})}function eM({detection:e,onCommand:t,onSwitchView:s,disabled:a=!1}){let n=function(e){switch(e.kind){case"brownfield":return{icon:(0,r.jsx)(eE.A,{className:"h-8 w-8 text-foreground",strokeWidth:1.5}),headline:"Existing project detected",body:"GSD will map your codebase and ask a few questions about what you want to build. From there it generates structured milestones and deliverable slices.",primaryLabel:"Map & Initialize",primaryCommand:"/gsd",secondary:{label:"Browse files first",action:"files-view"}};case"v1-legacy":return{icon:(0,r.jsx)(eP.A,{className:"h-8 w-8 text-foreground",strokeWidth:1.5}),headline:"GSD v1 project found",body:"This project has a .planning/ folder from an earlier GSD version. Migration converts your existing planning data into the new .gsd/ format.",detail:"Your original files will be preserved — migration creates the new structure alongside them.",primaryLabel:"Migrate to v2",primaryCommand:"/gsd migrate",secondary:{label:"Start fresh instead",action:"command",command:"/gsd"}};case"blank":return{icon:(0,r.jsx)(e_.A,{className:"h-8 w-8 text-foreground",strokeWidth:1.5}),headline:"Start a new project",body:"This folder is empty. GSD will ask what you want to build, then generate a structured plan — milestones broken into deliverable slices with risk-ordered execution.",primaryLabel:"Start Project Setup",primaryCommand:"/gsd"};default:return{icon:(0,r.jsx)(w.A,{className:"h-8 w-8 text-foreground",strokeWidth:1.5}),headline:"Set up your project",body:"Run the GSD wizard to get started.",primaryLabel:"Get Started",primaryCommand:"/gsd"}}}(e),i="brownfield"===e.kind||"v1-legacy"===e.kind;return(0,r.jsx)("div",{className:"flex h-full items-center justify-center p-8",children:(0,r.jsxs)("div",{className:"w-full max-w-lg",children:[(0,r.jsx)("div",{className:"mb-6 flex h-16 w-16 items-center justify-center rounded-xl border border-border bg-card",children:n.icon}),(0,r.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-balance text-foreground",children:n.headline}),(0,r.jsx)("p",{className:"mt-3 text-sm leading-relaxed text-pretty text-muted-foreground",children:n.body}),n.detail&&(0,r.jsx)("p",{className:"mt-2 text-xs leading-relaxed text-pretty text-muted-foreground",children:n.detail}),i&&(0,r.jsx)("div",{className:"mt-5",children:(0,r.jsx)(eD,{signals:e.signals})}),(0,r.jsxs)("div",{className:"mt-8 flex items-center gap-3",children:[(0,r.jsxs)("button",{onClick:()=>t(n.primaryCommand),disabled:a,className:(0,M.cn)("inline-flex items-center gap-2 rounded-md bg-foreground px-5 py-2.5 text-sm font-medium text-background transition-colors hover:bg-foreground/90",a&&"cursor-not-allowed opacity-50"),children:[n.primaryLabel,(0,r.jsx)(e$.A,{className:"h-3.5 w-3.5"})]}),n.secondary&&(0,r.jsx)("button",{onClick:()=>{"files-view"===n.secondary.action?s("files"):n.secondary.command&&t(n.secondary.command)},disabled:a,className:(0,M.cn)("inline-flex items-center gap-1.5 rounded-md border border-border bg-background px-4 py-2.5 text-sm font-medium text-foreground transition-colors hover:bg-accent",a&&"cursor-not-allowed opacity-50"),children:n.secondary.label})]}),"blank"===e.kind&&(0,r.jsxs)("div",{className:"mt-8 rounded-lg border border-border/50 bg-card/50 p-4",children:[(0,r.jsx)("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"What happens next"}),(0,r.jsx)("ul",{className:"mt-2.5 space-y-2",children:["A few questions about what you're building","Codebase analysis and context gathering","Structured milestone and slice generation"].map((e,t)=>(0,r.jsxs)("li",{className:"flex items-start gap-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border border-border text-[10px] font-medium text-muted-foreground",children:t+1}),e]},t))})]}),"brownfield"===e.kind&&(0,r.jsxs)("div",{className:"mt-8 rounded-lg border border-border/50 bg-card/50 p-4",children:[(0,r.jsx)("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"What happens next"}),(0,r.jsx)("ul",{className:"mt-2.5 space-y-2",children:["GSD scans your codebase and asks about your goals","You discuss scope, constraints, and priorities","A milestone with risk-ordered slices is generated"].map((e,t)=>(0,r.jsxs)("li",{className:"flex items-start gap-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border border-border text-[10px] font-medium text-muted-foreground",children:t+1}),e]},t))})]})]})})}function eq({label:e,value:t,subtext:s,icon:a}){return(0,r.jsx)("div",{className:"rounded-md border border-border bg-card p-4",children:(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:e}),null===t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ei,{className:"mt-2 h-7 w-20"}),(0,r.jsx)(ei,{className:"mt-1.5 h-3 w-16"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"mt-1 truncate text-2xl font-semibold tracking-tight tabular-nums",children:t}),s&&(0,r.jsx)("p",{className:"mt-0.5 truncate text-xs text-muted-foreground tabular-nums",children:s})]})]}),(0,r.jsx)("div",{className:"shrink-0 rounded-md bg-accent p-2 text-muted-foreground",children:a})]})})}function eB({onSwitchView:e,onExpandTerminal:t}={}){var s;let a,n,o=(0,Z.gF)(),{sendCommand:l}=(0,Z._l)(),d=o.boot,c=(0,Z.Gr)(o),p=(0,Z.CL)(o),g=d?.bridge??null,f=o.live.freshness,b=d?.project.cwd,[v,j]=(0,i.useState)(null),y=(0,i.useCallback)(async()=>{try{let e=await (0,eo.tm)((0,Z.fL)("/api/visualizer",b));if(!e.ok)return;let t=await e.json();t.totals&&j(t.totals)}catch{}},[b]);(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{y()},0),t=window.setInterval(()=>{y()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[y]);let w=v?.duration??p?.elapsed??0,S=v?.cost??p?.totalCost??0,k=v?.tokens.total??p?.totalTokens??0,A=(0,Z.Ct)(c),R=A?.tasks.filter(e=>e.done).length??0,T=A?.tasks.length??0,E=T>0?Math.round(R/T*100):0,P=(0,Z.U4)(c),_=(0,Z.E3)(c),I=p?.active??!1,F=p?.currentUnit?.id??P,$=f.auto.stale?"stale":f.auto.status;(0,ee.L)({phase:c?.active.phase??"pre-planning",autoActive:p?.active??!1,autoPaused:p?.paused??!1,onboardingLocked:d?.onboarding.locked??!1,commandInFlight:o.commandInFlight,bootStatus:o.bootStatus,hasMilestones:(c?.milestones.length??0)>0,stepMode:p?.stepMode??!1,projectDetectionKind:d?.projectDetection?.kind??null});let L=(o.terminalLines??[]).slice(-6),D="idle"===o.bootStatus||"loading"===o.bootStatus,q=(s=Z._y,a=p?.rtkSavings??null,{enabled:p?.rtkEnabled===!0,label:"RTK Saved",value:D?null:s(a?.savedTokens??0),subtext:D?null:a&&a.commands>0?`${Math.round(a.savingsPct)}% saved • ${a.commands} cmd${1===a.commands?"":"s"}`:"Waiting for shell usage"}),B=d?.projectDetection;return!D&&B&&"active-gsd"!==B.kind&&"empty-gsd"!==B.kind?(0,r.jsx)("div",{className:"flex h-full flex-col overflow-hidden",children:(0,r.jsx)(eM,{detection:B,onCommand:e=>{(0,et.WT)({dispatch:()=>l((0,Z.Sf)(e,g))})},onSwitchView:t=>e?.(t),disabled:!!o.commandInFlight||d?.onboarding.locked})}):(0,r.jsxs)("div",{className:"flex h-full flex-col overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-3 py-2 md:px-6 md:py-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,r.jsx)("h1",{className:"text-base md:text-lg font-semibold shrink-0",children:"Dashboard"}),!D&&P&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"hidden sm:inline text-lg font-thin text-muted-foreground select-none",children:"/"}),(0,r.jsx)("span",{className:"hidden sm:inline",children:(0,r.jsx)(eA,{label:P,size:"sm"})})]}),D&&(0,r.jsx)(ei,{className:"h-4 w-40"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 md:gap-3","data-testid":"dashboard-action-bar",children:[D?(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(ei,{className:"h-8 w-40 rounded-md"})}):null,!D&&(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border bg-card px-3 py-1.5 text-sm",children:[(0,r.jsx)("span",{className:(0,M.cn)("h-2 w-2 rounded-full",I?"animate-pulse bg-success":"bg-muted-foreground/50")}),(0,r.jsx)("span",{className:"font-medium",children:I?"Auto Mode Active":"Auto Mode Inactive"})]}),!D&&_&&(0,r.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,r.jsx)(C.A,{className:"h-4 w-4"}),(0,r.jsx)("span",{className:"font-mono tabular-nums",children:_})]})]})]}),(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 md:p-6",children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 md:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-5",children:[(0,r.jsx)("div",{className:"rounded-md border border-border bg-card p-4","data-testid":"dashboard-current-unit",children:(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("p",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Current Unit"}),D?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ei,{className:"mt-2 h-7 w-20"}),(0,r.jsx)(ei,{className:"mt-1.5 h-3 w-16"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)(eA,{label:F})}),(0,r.jsxs)("p",{className:"mt-1.5 text-xs text-muted-foreground","data-testid":"dashboard-current-unit-freshness",children:["Auto freshness: ",$]})]})]}),(0,r.jsx)("div",{className:"shrink-0 rounded-md bg-accent p-2 text-muted-foreground",children:(0,r.jsx)(N.A,{className:"h-5 w-5"})})]})}),(0,r.jsx)(eq,{label:"Elapsed Time",value:D?null:(0,Z.a3)(w),icon:(0,r.jsx)(eg.A,{className:"h-5 w-5"})}),(0,r.jsx)(eq,{label:"Total Cost",value:D?null:(0,Z.BD)(S),icon:(0,r.jsx)(ef.A,{className:"h-5 w-5"})}),(0,r.jsx)(eq,{label:"Tokens Used",value:D?null:(0,Z._y)(k),icon:(0,r.jsx)(eb.A,{className:"h-5 w-5"})}),q.enabled&&(0,r.jsx)(eq,{label:q.label,value:q.value,subtext:q.subtext,icon:(0,r.jsx)(ev.A,{className:"h-5 w-5"})})]}),(0,r.jsx)("div",{className:"mt-6",children:D?(0,r.jsx)(ej,{}):(0,r.jsxs)("div",{className:"flex flex-col rounded-md border border-border bg-card",children:[(0,r.jsxs)("div",{className:"border-b border-border px-4 py-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("h2",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Current Slice"}),A?(0,r.jsxs)("p",{className:"mt-0.5 truncate text-sm font-medium text-foreground",children:[A.id," — ",A.title]}):(0,r.jsx)("p",{className:"mt-0.5 text-sm text-muted-foreground",children:"No active slice"})]}),A&&T>0&&(0,r.jsxs)("div",{className:"shrink-0 text-right",children:[(0,r.jsx)("span",{className:"text-2xl font-bold tabular-nums leading-none",children:E}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"%"})]})]}),A&&T>0&&(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("div",{className:"h-1 w-full overflow-hidden rounded-full bg-accent",children:(0,r.jsx)("div",{className:"h-full rounded-full transition-[width,background-color] duration-500",style:{width:`${E}%`,backgroundColor:(n=Math.max(0,Math.min(100,E)),`oklch(0.65 0.16 ${(25+n/100*120).toFixed(1)})`)}})}),(0,r.jsxs)("p",{className:"mt-1.5 text-xs text-muted-foreground tabular-nums",children:[R," of ",T," tasks complete"]})]})]}),(0,r.jsx)("div",{className:"flex-1 p-3",children:A&&A.tasks.length>0?(0,r.jsx)("div",{className:"space-y-0.5",children:A.tasks.map(e=>{let t=(0,X.g$)(c.active.milestoneId,A.id,e,c.active);return(0,r.jsxs)("div",{className:(0,M.cn)("flex items-center gap-2.5 rounded px-2 py-1.5 transition-colors","in-progress"===t&&"bg-accent"),children:[function(e){switch(e){case"done":return(0,r.jsx)(u.A,{className:"h-4 w-4 text-muted-foreground"});case"in-progress":return(0,r.jsx)(m.A,{className:"h-4 w-4 text-foreground"});case"pending":return(0,r.jsx)(x.A,{className:"h-4 w-4 text-muted-foreground"});case"parked":return(0,r.jsx)(h.A,{className:"h-4 w-4 text-muted-foreground"})}}(t),(0,r.jsxs)("span",{className:(0,M.cn)("min-w-0 flex-1 truncate text-xs","done"===t&&"text-muted-foreground line-through decoration-muted-foreground/40","pending"===t&&"text-muted-foreground","in-progress"===t&&"font-medium text-foreground"),children:[(0,r.jsx)("span",{className:"font-mono text-muted-foreground",children:e.id}),(0,r.jsx)("span",{className:"mx-1.5 text-border",children:"\xb7"}),e.title]}),"in-progress"===t&&(0,r.jsx)("span",{className:"shrink-0 rounded-sm bg-foreground/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"active"})]},e.id)})}):(0,r.jsx)("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No active slice or no tasks defined yet."})})]})}),D?(0,r.jsx)("div",{className:"mt-6",children:(0,r.jsx)(ey,{})}):(0,r.jsxs)("div",{className:"mt-6 rounded-md border border-border bg-card",children:[(0,r.jsx)("div",{className:"border-b border-border px-4 py-3",children:(0,r.jsx)("h2",{className:"text-sm font-semibold",children:"Recent Activity"})}),L.length>0?(0,r.jsx)("div",{className:"divide-y divide-border",children:L.map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[(0,r.jsx)("span",{className:"w-16 flex-shrink-0 font-mono text-xs tabular-nums text-muted-foreground",children:e.timestamp}),(0,r.jsx)("span",{className:(0,M.cn)("h-1.5 w-1.5 flex-shrink-0 rounded-full",function(e){switch(e){case"success":return"bg-success";case"error":return"bg-destructive";default:return"bg-foreground/50"}}(e.type))}),(0,r.jsx)("span",{className:"truncate text-sm",children:e.content})]},e.id))}):(0,r.jsx)("div",{className:"px-4 py-4 text-sm text-muted-foreground",children:"No activity yet."})]})]})]})}var eO=s(53199),eU=s(2652),ez=s(92893),eG=s(2354),eW=s(78300);function eK(){let e=(0,Z.gF)(),t=(0,Z.tM)(e),s=(0,Z.Gr)(e),a=(0,Z.CL)(e),n=(0,Z.E3)(s)??"project scope",o=(0,Z.iT)(e.boot?.bridge),l=a?.currentUnit?.id??(0,Z.U4)(s),d=(0,Z.QC)(e),c=e.titleOverride?.trim()||null,u=e.statusTexts,m=e.live.recoverySummary,h=(0,Z.Gr)(e)?.validationIssues.length??0,x=Object.entries(u),p=x.length>0?x[x.length-1][1]:null,g="idle"===e.bootStatus||"loading"===e.bootStatus,f=e.boot?.project.cwd,[b,v]=(0,i.useState)(null),j=(0,i.useCallback)(async()=>{try{let e=await (0,eo.tm)((0,Z.fL)("/api/visualizer",f));if(!e.ok)return;let t=await e.json();t.totals&&v(t.totals)}catch{}},[f]);return(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{j()},0),t=window.setInterval(()=>{j()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[j]),(0,r.jsxs)("div",{className:"flex h-7 items-center justify-between border-t border-border bg-card px-2 md:px-3 text-[10px] md:text-xs",children:[(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2 md:gap-4",children:[(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${function(e){switch(e){case"success":return"text-success";case"warning":return"text-warning";case"danger":return"text-destructive";default:return"text-muted-foreground"}}(t.tone)}`,children:[(0,r.jsx)(eO.A,{className:"h-3 w-3"}),(0,r.jsx)("span",{children:t.label})]}),(0,r.jsxs)("div",{className:"hidden sm:flex items-center gap-1.5 text-muted-foreground",children:[(0,r.jsx)(C.A,{className:"h-3 w-3"}),g?(0,r.jsx)(ei,{className:"h-3 w-20"}):(0,r.jsx)("span",{className:"font-mono tabular-nums",children:n})]}),(0,r.jsxs)("div",{className:"hidden lg:flex items-center gap-1.5 text-muted-foreground",children:[(0,r.jsx)(eU.A,{className:"h-3 w-3"}),g?(0,r.jsx)(ei,{className:"h-3 w-24"}):(0,r.jsx)("span",{className:"font-mono",children:o})]}),!g&&(0,r.jsxs)("div",{className:"hidden max-w-xs items-center gap-1.5 truncate text-muted-foreground xl:flex","data-testid":"status-bar-retry-compaction",children:[(0,r.jsx)(I.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsx)("span",{className:"truncate",children:m.retryInProgress?`Retry ${Math.max(1,m.retryAttempt)}`:m.isCompacting?"Compacting":m.freshness})]}),!g&&(0,r.jsxs)("div",{className:(0,M.cn)("hidden items-center gap-1.5 xl:flex",h>0?"text-warning":"text-muted-foreground"),"data-testid":"status-bar-validation-count",children:[(0,r.jsx)(ez.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsxs)("span",{children:[h," issue",1===h?"":"s"]})]}),!g&&d&&(0,r.jsxs)("div",{className:"hidden max-w-sm items-center gap-1.5 truncate text-destructive lg:flex","data-testid":"status-bar-error",children:[(0,r.jsx)(ez.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsx)("span",{className:"truncate",children:d})]}),!g&&c&&(0,r.jsxs)("div",{className:"hidden max-w-xs items-center gap-1.5 truncate text-foreground/80 xl:flex","data-testid":"status-bar-title-override",children:[(0,r.jsx)(eG.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsx)("span",{className:"truncate",title:c,children:c})]}),!g&&p&&!d&&(0,r.jsxs)("div",{className:"hidden max-w-xs items-center gap-1.5 truncate text-muted-foreground lg:flex","data-testid":"status-bar-extension-status",children:[(0,r.jsx)(eG.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsx)("span",{className:"truncate",children:p})]})]}),(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2 md:gap-4",children:[(0,r.jsxs)("div",{className:"hidden sm:flex items-center gap-1.5 text-muted-foreground",children:[(0,r.jsx)(eg.A,{className:"h-3 w-3"}),g?(0,r.jsx)(ei,{className:"h-3 w-8"}):(0,r.jsx)("span",{className:"tabular-nums",children:(0,eW.a3)(b?.duration??a?.elapsed??0)})]}),(0,r.jsxs)("div",{className:"hidden sm:flex items-center gap-1.5 text-muted-foreground",children:[(0,r.jsx)(eb.A,{className:"h-3 w-3"}),g?(0,r.jsx)(ei,{className:"h-3 w-6"}):(0,r.jsx)("span",{className:"tabular-nums",children:(0,eW.ap)(b?.tokens.total??a?.totalTokens??0)})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[(0,r.jsx)(ef.A,{className:"h-3 w-3"}),g?(0,r.jsx)(ei,{className:"h-3 w-10"}):(0,r.jsx)("span",{className:"tabular-nums",children:(0,eW.BD)(b?.cost??a?.totalCost??0)})]}),(0,r.jsx)("span",{className:"hidden sm:inline max-w-[20rem] truncate text-muted-foreground","data-testid":"status-bar-unit",children:g?(0,r.jsx)(ei,{className:"inline-block h-3 w-28 align-middle"}):(0,r.jsx)(eT,{label:l})})]})]})}var eV=s(87895),eH=s(18239),eY=s(53195),eJ=s(12406),eQ=s(81848),eZ=s(67238),eX=s(75596);function e0({className:e,...t}){return(0,r.jsx)(eX.bL,{"data-slot":"checkbox",className:(0,M.cn)("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:(0,r.jsx)(eX.C1,{"data-slot":"checkbox-indicator",className:"flex items-center justify-center text-current transition-none",children:(0,r.jsx)(eZ.A,{className:"size-3.5"})})})}var e1=s(43106);function e5({...e}){return(0,r.jsx)(D.bL,{"data-slot":"sheet",...e})}function e2({...e}){return(0,r.jsx)(D.ZL,{"data-slot":"sheet-portal",...e})}function e3({className:e,...t}){return(0,r.jsx)(D.hJ,{"data-slot":"sheet-overlay",className:(0,M.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t})}function e4({className:e,children:t,side:s="right",...a}){return(0,r.jsxs)(e2,{children:[(0,r.jsx)(e3,{}),(0,r.jsx)(D.UC,{"data-slot":"sheet-content",className:(0,M.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500","right"===s&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm","left"===s&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm","top"===s&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b","bottom"===s&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",e),...a,children:t})]})}function e8({className:e,...t}){return(0,r.jsx)("div",{"data-slot":"sheet-header",className:(0,M.cn)("flex flex-col gap-1.5 p-4",e),...t})}function e6({className:e,...t}){return(0,r.jsx)("div",{"data-slot":"sheet-footer",className:(0,M.cn)("mt-auto flex flex-col gap-2 p-4",e),...t})}function e7({className:e,...t}){return(0,r.jsx)(D.hE,{"data-slot":"sheet-title",className:(0,M.cn)("text-foreground font-semibold",e),...t})}function e9({className:e,...t}){return(0,r.jsx)(D.VY,{"data-slot":"sheet-description",className:(0,M.cn)("text-muted-foreground text-sm",e),...t})}function te({className:e,...t}){return(0,r.jsx)("textarea",{"data-slot":"textarea",className:(0,M.cn)("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),...t})}var tt=s(94002);function ts(e){switch(e){case"select":return"Selection";case"confirm":return"Confirmation";case"input":return"Input";case"editor":return"Editor"}return e}function tr({request:e,onSubmit:t,disabled:s}){let a=!!e.allowMultiple,[n,o]=(0,i.useState)(()=>(0,tt.cv)(0,e.options.length)),[l,d]=(0,i.useState)(()=>new Set),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{a||requestAnimationFrame(()=>c.current?.focus())},[a]);let u=()=>{if(a)t({value:Array.from(l)});else{let s=e.options[n];s&&t({value:s})}},m=(0,i.useCallback)(r=>{let a=e.options[r];a&&!s&&(o(r),t({value:a}))},[s,t,e.options]),h=(0,i.useCallback)(t=>{if(s)return;let r=(0,tt.cZ)(t.key,n,e.options.length);if("none"!==r.type){if(t.preventDefault(),t.stopPropagation(),"select"===r.type)return void o(r.index);m(r.index)}},[s,e.options.length,n,m]),x=a?l.size>0:n>=0;return a?(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("div",{className:"space-y-2",children:e.options.map((e,t)=>(0,r.jsxs)("label",{className:"flex cursor-pointer items-center gap-3 rounded-lg border border-border bg-background px-3 py-2.5 transition-colors hover:bg-accent/40",children:[(0,r.jsx)(e0,{checked:l.has(e),onCheckedChange:t=>{let s=new Set(l);t?s.add(e):s.delete(e),d(s)},disabled:s}),(0,r.jsx)("span",{className:"text-sm",children:e})]},`${e}-${t}`))}),(0,r.jsxs)(J,{onClick:u,disabled:s||!x,className:"w-full",children:[(0,r.jsx)(eQ.A,{className:"h-4 w-4"}),"Submit selection (",l.size,")"]})]}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("div",{ref:c,role:"listbox",tabIndex:0,"aria-activedescendant":n>=0?`focused-select-option-${n}`:void 0,onKeyDown:h,className:"space-y-2 rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-ring",children:e.options.map((e,t)=>{let a=t===n;return(0,r.jsxs)("button",{id:`focused-select-option-${t}`,type:"button",role:"option","aria-selected":a,onClick:()=>m(t),disabled:s,className:(0,M.cn)("flex w-full cursor-pointer items-center gap-3 rounded-lg border bg-background px-3 py-2.5 text-left text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",a?"border-primary/40 bg-primary/10 text-primary":"border-border hover:bg-accent/40",s&&"cursor-not-allowed opacity-60"),children:[(0,r.jsx)("span",{className:"w-4 shrink-0 text-center font-mono text-[11px] text-muted-foreground",children:t+1}),(0,r.jsx)("span",{className:"min-w-0 flex-1",children:e}),a&&(0,r.jsx)(eZ.A,{className:"h-4 w-4 shrink-0"})]},`${e}-${t}`)})}),(0,r.jsxs)(J,{onClick:u,disabled:s||!x,className:"w-full",children:[(0,r.jsx)(eQ.A,{className:"h-4 w-4"}),"Submit"]})]})}function ta({request:e,onSubmit:t,onCancel:s,disabled:a}){return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("div",{className:"rounded-lg border border-border bg-background px-4 py-3 text-sm leading-relaxed",children:e.message}),(0,r.jsxs)("div",{className:"flex gap-3",children:[(0,r.jsx)(J,{onClick:()=>t({value:!0}),disabled:a,className:"flex-1",children:"Confirm"}),(0,r.jsx)(J,{onClick:s,disabled:a,variant:"outline",className:"flex-1",children:"Cancel"})]})]})}function tn({request:e,onSubmit:t,disabled:s}){let[a,n]=(0,i.useState)("");return(0,r.jsxs)("form",{className:"space-y-4",onSubmit:e=>{e.preventDefault(),a.trim()&&t({value:a})},children:[(0,r.jsx)(e1.p,{value:a,onChange:e=>n(e.target.value),placeholder:e.placeholder||"Enter a value",disabled:s,autoFocus:!0}),(0,r.jsxs)(J,{type:"submit",disabled:s||!a.trim(),className:"w-full",children:[(0,r.jsx)(eQ.A,{className:"h-4 w-4"}),"Submit"]})]})}function ti({request:e,onSubmit:t,disabled:s}){let[a,n]=(0,i.useState)(e.prefill||"");return(0,r.jsxs)("form",{className:"space-y-4",onSubmit:e=>{e.preventDefault(),t({value:a})},children:[(0,r.jsx)(te,{value:a,onChange:e=>n(e.target.value),disabled:s,className:"min-h-[200px] font-mono text-sm",autoFocus:!0}),(0,r.jsxs)(J,{type:"submit",disabled:s,className:"w-full",children:[(0,r.jsx)(eQ.A,{className:"h-4 w-4"}),"Submit"]})]})}function to({request:e,onSubmit:t,onCancel:s,disabled:a}){switch(e.method){case"select":return(0,r.jsx)(tr,{request:e,onSubmit:t,disabled:a});case"confirm":return(0,r.jsx)(ta,{request:e,onSubmit:t,onCancel:s,disabled:a});case"input":return(0,r.jsx)(tn,{request:e,onSubmit:t,disabled:a});case"editor":return(0,r.jsx)(ti,{request:e,onSubmit:t,disabled:a})}}function tl(){let e=(0,Z.gF)(),{respondToUiRequest:t,dismissUiRequest:s}=(0,Z._l)(),a=e.pendingUiRequests,n=a.length>0,i=a[0]??null,o="extension_ui_response"===e.commandInFlight,l=()=>{i&&s(i.id)};return(0,r.jsx)(e5,{open:n,onOpenChange:e=>{e||o||!i||l()},children:(0,r.jsx)(e4,{side:"right",className:"flex flex-col sm:max-w-md","data-testid":"focused-panel",children:i&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(e8,{children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[function(e){switch(e){case"select":return(0,r.jsx)(eV.A,{className:"h-4 w-4"});case"confirm":return(0,r.jsx)(eH.A,{className:"h-4 w-4"});case"input":return(0,r.jsx)(eY.A,{className:"h-4 w-4"});case"editor":return(0,r.jsx)(eJ.A,{className:"h-4 w-4"})}}(i.method),(0,r.jsx)(e7,{children:i.title||ts(i.method)})]}),(0,r.jsx)(e9,{children:(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsxs)("span",{children:[ts(i.method)," requested by the agent"]}),a.length>1&&(0,r.jsxs)("span",{className:(0,M.cn)("inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-foreground px-1.5 text-[11px] font-semibold text-background"),"data-testid":"focused-panel-queue-badge",children:["+",a.length-1]})]})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-2",children:(0,r.jsx)(to,{request:i,onSubmit:e=>{i&&t(i.id,e)},onCancel:l,disabled:o},i.id)}),(0,r.jsx)(e6,{children:(0,r.jsx)(J,{variant:"ghost",size:"sm",onClick:l,disabled:o,className:"text-muted-foreground",children:"Dismiss"})})]})})})}let td="1"===s(42130).env.NEXT_PUBLIC_GSD_DEV,tc=[{key:"forceOnboarding",label:"Onboarding wizard",description:"Force the onboarding gate to render even when credentials are valid",shortcutLabel:"Ctrl+Shift+1"}],tu={forceOnboarding:!1},tm=(0,i.createContext)(null);function th({children:e}){let[t,s]=(0,i.useState)(!1),[a,n]=(0,i.useState)(tu),[o,l]=(0,i.useState)(td);(0,i.useEffect)(()=>{(0,eo.tm)("/api/dev-mode",{cache:"no-store"}).then(e=>e.json()).then(e=>{e.isDevMode&&l(!0)}).catch(()=>{})},[]);let d=(0,i.useCallback)(e=>{n(t=>({...t,[e]:!t[e]}))},[]),c=(0,i.useCallback)(e=>t&&a[e],[t,a]);(0,i.useEffect)(()=>{if(o)return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);function e(e){t&&e.ctrlKey&&e.shiftKey&&"1"===e.key&&(e.preventDefault(),n(e=>({...e,forceOnboarding:!e.forceOnboarding})))}},[t,o]);let u=(0,i.useMemo)(()=>o?{isDevMode:o,enabled:t,setEnabled:s,overrides:a,toggle:d,isActive:c}:{isDevMode:!1,enabled:!1,setEnabled:()=>{},overrides:tu,toggle:()=>{},isActive:()=>!1},[o,t,s,a,d,c]);return(0,r.jsx)(tm.Provider,{value:u,children:e})}function tx(){let e=(0,i.useContext)(tm);if(!e)throw Error("useDevOverrides must be used within <DevOverridesProvider>");return e}var tp=s(61415);function tg({onNext:e}){return(0,r.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{type:"spring",duration:.6,bounce:0},className:"relative",children:[(0,r.jsx)("div",{className:"absolute inset-0 rounded-2xl bg-foreground/5 blur-2xl"}),(0,r.jsxs)("div",{className:"relative mb-4 flex h-18 items-center justify-center",children:[(0,r.jsx)(a.default,{src:"/logo-white.svg",alt:"GSD-Pi Web",height:70,width:200,className:"hidden dark:block"}),(0,r.jsx)(a.default,{src:"/logo-black.svg",alt:"GSD-Pi Web",height:70,width:200,className:"dark:hidden"})]})]}),(0,r.jsx)(c.P.p,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.16,duration:.4},className:"max-w-sm text-[15px] leading-relaxed text-muted-foreground",children:"Let's get your workspace ready. This takes about a minute."}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.24,duration:.4},className:"mt-10 flex items-center gap-3 text-xs text-muted-foreground",children:["Mode","Provider","Auth","Workspace"].map((e,t)=>(0,r.jsxs)("span",{className:"flex items-center gap-3",children:[t>0&&(0,r.jsx)("span",{className:"h-px w-5 bg-border"}),(0,r.jsx)("span",{className:"font-medium",children:e})]},e))}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.35,duration:.4},className:"mt-10",children:(0,r.jsxs)(J,{size:"lg",className:"group gap-2.5 px-8 text-[15px] transition-transform active:scale-[0.96]",onClick:e,"data-testid":"onboarding-start",children:["Get started",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})})]})}var tf=s(14987),tb=s(67552);let tv=[{id:"expert",label:"Expert",icon:tf.A,tagline:"Full control",description:"Dashboard metrics, dual-pane power mode, and direct /gsd command access. Built for people who want visibility into every milestone and task."},{id:"vibe-coder",label:"Vibe Coder",icon:tb.A,tagline:"Just chat",description:"Conversational interface with the AI agent. Describe what you want and let GSD handle the structure. Same engine, friendlier surface."}];function tj({selected:e,onSelect:t,onNext:s,onBack:a}){return(0,r.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,r.jsx)(c.P.h2,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",style:{textWrap:"balance"},children:"How do you want to work?"}),(0,r.jsx)(c.P.p,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.06,duration:.4},className:"mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground",children:"You can switch anytime from settings."}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.12,duration:.45},className:"mt-8 grid w-full max-w-lg gap-3 sm:grid-cols-2",children:tv.map(s=>{let a=e===s.id,n=s.icon;return(0,r.jsxs)("button",{type:"button",onClick:()=>t(s.id),className:(0,M.cn)("group relative flex flex-col rounded-xl border px-5 py-5 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",a?"border-foreground/30 bg-foreground/[0.06] shadow-[0_0_0_1px_rgba(255,255,255,0.06)]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50"),"data-testid":`onboarding-mode-${s.id}`,children:[(0,r.jsx)("div",{className:"absolute right-3.5 top-3.5",children:(0,r.jsx)("div",{className:(0,M.cn)("flex h-5 w-5 items-center justify-center rounded-full border-[1.5px] transition-[background-color,border-color] duration-200",a?"border-foreground bg-foreground":"border-foreground/20"),children:a&&(0,r.jsx)(c.P.svg,{initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},transition:{type:"spring",duration:.3,bounce:0},viewBox:"0 0 12 12",className:"h-2.5 w-2.5 text-background",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"2.5 6 5 8.5 9.5 3.5"})})})}),(0,r.jsx)("div",{className:(0,M.cn)("mb-4 flex h-10 w-10 items-center justify-center rounded-lg transition-colors duration-200",a?"bg-foreground/10":"bg-foreground/[0.04]"),children:(0,r.jsx)(n,{className:(0,M.cn)("h-5 w-5 transition-colors duration-200",a?"text-foreground":"text-muted-foreground"),strokeWidth:1.5})}),(0,r.jsxs)("div",{className:"pr-7",children:[(0,r.jsx)("span",{className:"text-[15px] font-semibold text-foreground",children:s.label}),(0,r.jsx)("span",{className:(0,M.cn)("ml-2 text-xs font-medium transition-colors duration-200","text-muted-foreground"),children:s.tagline})]}),(0,r.jsx)("p",{className:"mt-2 text-[13px] leading-relaxed text-muted-foreground",children:s.description})]},s.id)})}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.2,duration:.3},className:"mt-8 flex w-full max-w-lg items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:a,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)(J,{onClick:s,disabled:!e,className:"group gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-mode-continue",children:["Continue",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})]})}var ty=s(78986);let tw=(0,H.F)("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function tN({className:e,variant:t,asChild:s=!1,...a}){let n=s?V.DX:"span";return(0,r.jsx)(n,{"data-slot":"badge",className:(0,M.cn)(tw({variant:t}),e),...a})}var tS=s(97019);function tk({providers:e,selectedId:t,onSelect:s,onNext:a,onBack:n}){let o=(0,i.useMemo)(()=>{let t,s,r,a;return t=e.filter(e=>e.configured),s=e.filter(e=>!e.configured&&e.recommended),r=e.filter(e=>!e.configured&&!e.recommended),a=[],t.length>0&&a.push({label:"Configured",items:t}),s.length>0&&a.push({label:"Recommended",items:s}),r.length>0&&a.push({label:"Other Providers",items:r}),a},[e]),l=e.some(e=>e.configured);return(0,r.jsxs)("div",{className:"flex flex-col items-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:"text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Choose a provider"}),(0,r.jsx)("p",{className:"mt-2 text-sm leading-relaxed text-muted-foreground",children:"Click a provider to configure it. Set up as many as you want, then continue."})]}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.08,duration:.45},className:"mt-8 w-full space-y-5",children:o.map(e=>(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mb-2 px-0.5 text-[11px] font-medium uppercase tracking-widest text-muted-foreground",children:e.label}),(0,r.jsx)("div",{className:"grid gap-2 sm:grid-cols-2",children:e.items.map(e=>{let a,n=e.id===t;return(0,r.jsxs)("button",{type:"button",onClick:()=>s(e.id),className:(0,M.cn)("group relative rounded-xl border px-4 py-3.5 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",n?"border-foreground/30 bg-foreground/[0.06]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50"),"data-testid":`onboarding-provider-${e.id}`,children:[(0,r.jsx)("div",{className:"absolute right-3 top-3",children:(0,r.jsx)("div",{className:(0,M.cn)("flex h-5 w-5 items-center justify-center rounded-full border-[1.5px] transition-[background-color,border-color] duration-200",n?"border-foreground bg-foreground":"border-foreground/15"),children:n&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background",strokeWidth:3})})}),(0,r.jsxs)("div",{className:"pr-8",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground",children:e.label}),e.recommended&&(0,r.jsx)(tN,{variant:"outline",className:"border-foreground/10 bg-foreground/[0.03] text-[9px] text-muted-foreground",children:"Recommended"})]}),(0,r.jsx)("div",{className:"mt-1 flex items-center gap-1.5 text-xs text-muted-foreground",children:e.configured?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ty.A,{className:"h-3 w-3 text-success/80"}),(0,r.jsx)("span",{children:function(e){switch(e){case"auth_file":return"Saved auth";case"environment":return"Environment variable";case"runtime":return"Runtime";case"external_cli":return"CLI";default:return"Not configured"}}(e.configuredVia)})]}):(0,r.jsx)("span",{className:"text-muted-foreground",children:"Not configured"})})]}),(0,r.jsx)("div",{className:"mt-2.5 flex flex-wrap gap-1",children:(a=[],e.supports.apiKey&&a.push("API key"),e.supports.oauth&&a.push(e.supports.oauthAvailable?"Browser sign-in":"OAuth unavailable"),e.supports.externalCli&&a.push("CLI auth"),a).map(e=>(0,r.jsxs)(tS.m_,{children:[(0,r.jsx)(tS.k$,{asChild:!0,children:(0,r.jsx)(tN,{variant:"outline",className:"border-border/50 text-[10px] text-muted-foreground",children:e})}),(0,r.jsx)(tS.ZI,{side:"bottom",children:"API key"===e?"Enter an API key to authenticate":"Browser sign-in"===e?"Authenticate through your browser":"CLI auth"===e?"Authenticated via local CLI — no API key needed":"This auth method is not available"})]},e))})]},e.id)})})]},e.label))}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.15,duration:.3},className:"mt-8 flex w-full items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:n,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)(J,{onClick:a,disabled:!l,className:"group gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-provider-continue",children:["Continue",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})]})}var tC=s(6172),tA=s(52472),tR=s(79464),tT=s(60510),tE=s(86848),tP=s(16579),t_=s(8291),tI=s(69444);function tF({className:e,value:t,...s}){return(0,r.jsx)(tI.bL,{"data-slot":"progress",className:(0,M.cn)("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",e),...s,children:(0,r.jsx)(tI.C1,{"data-slot":"progress-indicator",className:"bg-primary h-full w-full flex-1 transition-transform",style:{transform:`translateX(-${100-(t||0)}%)`}})})}function t$({provider:e,activeFlow:t,lastValidation:s,requestState:a,requestProviderId:n,onSaveApiKey:o,onStartFlow:l,onSubmitFlowInput:m,onCancelFlow:h,onBack:x,onNext:p,bridgeRefreshPhase:g,bridgeRefreshError:f}){let[b,v]=(0,i.useState)(""),[j,y]=(0,i.useState)(""),[w,N]=(0,i.useState)(!1),S="idle"!==a,k=n===e.id&&S,C=e.supports.externalCli,A=s?.status==="succeeded"&&s.providerId===e.id,R=C&&e.configured||A&&("succeeded"===g||"idle"===g),T=s?.status==="failed"&&s.providerId===e.id,E=T?function(e){if(!e)return{title:"Validation failed",detail:null};let t=e.match(/^\d{3}\s+[^:]+:\s*(.+)$/s),s=t?.[1]??e;try{let e=JSON.parse(s);if("object"==typeof e&&null!==e){let t=e.error_details?.message??e.error?.message??e.message??e.error??null;if("string"==typeof t&&t.length>0){if(/subscription.*(ended|expired|cancelled)/i.test(t))return{title:"Subscription expired",detail:t.replace(/\.$/,"")+". Check your plan status with this provider."};if(/rate.limit/i.test(t))return{title:"Rate limited",detail:"Too many requests. Wait a moment and try again."};if(/invalid.*key|invalid.*token|incorrect.*key/i.test(t))return{title:"Invalid credentials",detail:"The API key was rejected. Double-check and try again."};if(/quota|billing|payment/i.test(t))return{title:"Billing issue",detail:t};return{title:"Provider error",detail:t}}}}catch{}return/^401\b/i.test(e)?{title:"Unauthorized",detail:"The credentials were rejected. Double-check your API key."}:/^403\b/i.test(e)?{title:"Access denied",detail:"Your account doesn't have access. Check your subscription or permissions."}:/^429\b/i.test(e)?{title:"Rate limited",detail:"Too many requests. Wait a moment and try again."}:/^5\d{2}\b/i.test(e)?{title:"Server error",detail:"The provider returned an error. Try again in a minute."}:{title:"Validation failed",detail:e.length>200?e.slice(0,200)+"…":e}}(s.message):null;e.supports.apiKey||e.supports.oauth;let P=e.supports.oauth&&e.supports.oauthAvailable,_=e.supports.apiKey,I=t&&t.providerId===e.id&&!R,$=I&&"failed"===t.status,L=I&&("running"===t.status||"awaiting_browser_auth"===t.status),D=I&&"awaiting_input"===t.status,M=I?function(e){for(let t of[e.prompt?.message,e.auth?.instructions].filter(Boolean)){let e=t?.match(/(?:code|Code)[:\s]+([A-Z0-9]{4}[-–][A-Z0-9]{4})/i);if(e)return e[1]}return null}(t):null;return(0,i.useEffect)(()=>{if(s?.status!=="succeeded")return;let e=window.setTimeout(()=>v(""),0);return()=>window.clearTimeout(e)},[s?.checkedAt,s?.status]),(0,i.useEffect)(()=>{let e=window.setTimeout(()=>y(""),0);return()=>window.clearTimeout(e)},[t?.flowId]),(0,i.useEffect)(()=>{if(!w)return;let e=window.setTimeout(()=>N(!1),2e3);return()=>window.clearTimeout(e)},[w]),(0,r.jsxs)("div",{className:"flex flex-col items-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:"text-center",children:[(0,r.jsxs)("h2",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:["Connect ",e.label]}),(0,r.jsx)("p",{className:"mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground",children:R?"Authenticated and ready to go.":C?"Authentication is handled by the Claude CLI. Make sure it is installed and signed in.":_&&P?"Paste an API key or sign in through your browser.":_?"Paste your API key to authenticate.":"Sign in through your browser to authenticate."})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.08,duration:.45},className:"mt-8 w-full max-w-md space-y-4",children:[(0,r.jsx)(d.N,{children:R&&(0,r.jsxs)(c.P.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{type:"spring",duration:.4,bounce:0},className:"flex flex-col items-center gap-3 rounded-xl border border-success/15 bg-success/[0.04] px-6 py-6 text-center",children:[(0,r.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-success/15",children:(0,r.jsx)(ty.A,{className:"h-5 w-5 text-success"})}),(0,r.jsxs)("div",{className:"text-sm font-medium text-foreground",children:[e.label," authenticated"]})]})}),T&&E&&(0,r.jsxs)("div",{className:"flex items-start gap-3 rounded-xl border border-destructive/20 bg-destructive/[0.06] px-4 py-3 text-sm",children:[(0,r.jsx)(tC.A,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"font-medium text-destructive",children:E.title}),E.detail&&(0,r.jsx)("div",{className:"mt-0.5 text-muted-foreground",children:E.detail})]})]}),"pending"===g&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3 rounded-xl border border-foreground/10 bg-foreground/[0.03] px-4 py-3 text-sm text-foreground/80",children:[(0,r.jsx)(F.A,{className:"h-4 w-4 shrink-0 animate-spin"}),"Connecting to provider…"]}),(0,r.jsx)(tF,{value:66,className:"h-1"})]}),"failed"===g&&f&&(0,r.jsxs)("div",{className:"flex items-start gap-3 rounded-xl border border-destructive/20 bg-destructive/[0.06] px-4 py-3 text-sm",children:[(0,r.jsx)(tC.A,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"font-medium text-destructive",children:"Connection failed"}),(0,r.jsx)("div",{className:"mt-0.5 text-muted-foreground",children:f})]})]}),_&&!R&&(0,r.jsxs)("div",{className:"space-y-3 rounded-xl border border-border/50 bg-card/50 p-4",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"API key"}),(0,r.jsxs)("form",{className:"space-y-3",onSubmit:async t=>{if(t.preventDefault(),!b.trim())return;let s=await o(e.id,b);s&&!s.locked&&("succeeded"===s.bridgeAuthRefresh.phase||"idle"===s.bridgeAuthRefresh.phase)&&p()},children:[(0,r.jsx)(e1.p,{"data-testid":"onboarding-api-key-input",type:"password",autoComplete:"off",value:b,onChange:e=>v(e.target.value),placeholder:`Paste your ${e.label} API key`,disabled:S,className:"font-mono text-sm"}),(0,r.jsx)("div",{className:"flex items-center gap-2",children:(0,r.jsxs)(J,{type:"submit",disabled:!b.trim()||S,className:"gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-save-api-key",children:[k&&"saving_api_key"===a?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(tA.A,{className:"h-4 w-4"}),"Validate & save"]})})]})]}),P&&!R&&(0,r.jsxs)("div",{className:"space-y-3",children:[_&&(0,r.jsxs)("div",{className:"flex items-center gap-3 py-1",children:[(0,r.jsx)("div",{className:"h-px flex-1 bg-border/50"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"or"}),(0,r.jsx)("div",{className:"h-px flex-1 bg-border/50"})]}),!I&&(0,r.jsx)("div",{className:"rounded-xl border border-border/50 bg-card/50 p-4",children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Browser sign-in"}),(0,r.jsxs)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Opens a new tab to authenticate with ",e.label]})]}),(0,r.jsxs)(J,{variant:"outline",disabled:S,onClick:()=>l(e.id),className:"shrink-0 gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-start-provider-flow",children:[k&&"starting_provider_flow"===a?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(tR.A,{className:"h-4 w-4"}),"Sign in"]})]})}),I&&(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.3},className:"rounded-xl border border-border/50 bg-card/50 p-4 space-y-4","data-testid":"onboarding-active-flow",children:[M&&(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 py-2",children:[(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:"Enter this code on the sign-in page"}),(0,r.jsxs)("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(M).then(()=>N(!0)).catch(()=>{})},className:"group flex items-center gap-3 rounded-lg border border-border bg-background/50 px-5 py-3 transition-[border-color,transform] hover:border-foreground/20 active:scale-[0.96]",children:[(0,r.jsx)("span",{className:"font-mono text-2xl font-bold tracking-[0.15em] text-foreground",children:M}),(0,r.jsx)("span",{className:"text-muted-foreground transition-colors group-hover:text-muted-foreground",children:w?(0,r.jsx)(u.A,{className:"h-4 w-4 text-success"}):(0,r.jsx)(tT.A,{className:"h-4 w-4"})})]}),(0,r.jsx)("div",{className:"text-[11px] text-muted-foreground",children:w?"Copied!":"Click to copy"})]}),!M&&t.auth?.instructions&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:t.auth.instructions}),t.auth?.url&&(0,r.jsx)(J,{asChild:!0,className:"w-full gap-2 transition-transform active:scale-[0.96]",children:(0,r.jsxs)("a",{href:t.auth.url,target:"_blank",rel:"noreferrer",children:[(0,r.jsx)(tE.A,{className:"h-4 w-4"}),"Open sign-in page"]})}),(0,r.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[L&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}),(0,r.jsx)("span",{children:"Waiting for authentication…"})]}),$&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(tP.A,{className:"h-3 w-3 text-destructive"}),(0,r.jsx)("span",{className:"text-destructive",children:"Sign-in failed or timed out"})]}),D&&!M&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}),(0,r.jsx)("span",{children:"Waiting for input…"})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[$&&(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>l(e.id),disabled:S,className:"h-7 gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)(t_.A,{className:"h-3 w-3"}),"Retry"]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>h(t.flowId),disabled:S,className:"h-7 text-xs text-muted-foreground",children:"Cancel"})]})]}),t.prompt&&!M&&(0,r.jsxs)("form",{className:"space-y-2 border-t border-border/50 pt-3",onSubmit:e=>{e.preventDefault(),(t.prompt?.allowEmpty||j.trim())&&m(t.flowId,j)},children:[(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:t.prompt.message}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e1.p,{"data-testid":"onboarding-flow-input",value:j,onChange:e=>y(e.target.value),placeholder:t.prompt.placeholder||"Enter value",disabled:S,className:"text-sm"}),(0,r.jsx)(J,{type:"submit",disabled:S||!t.prompt.allowEmpty&&!j.trim(),className:"shrink-0 transition-transform active:scale-[0.96]",children:"submitting_provider_flow_input"===a?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):"Submit"})]})]}),t.progress.length>0&&(0,r.jsx)("div",{className:"space-y-1 border-t border-border/50 pt-3",children:t.progress.map((e,s)=>(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:e},`${t.flowId}-${s}`))})]})]}),e.supports.oauth&&!e.supports.oauthAvailable&&!_&&(0,r.jsx)("div",{className:"rounded-xl border border-border/50 bg-card/50 px-4 py-3.5 text-sm text-muted-foreground",children:"Browser sign-in is not available in this runtime. Go back and choose a provider with API-key support."})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.15,duration:.3},className:"mt-8 flex w-full max-w-md items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:x,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)(J,{onClick:p,disabled:!R,className:"group gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-auth-continue",children:["Configure another provider",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})]})}var tL=s(7747),tD=s(85221),tM=s(99237);function tq({className:e,children:t,viewportRef:s,...a}){return(0,r.jsxs)(tM.bL,{"data-slot":"scroll-area",className:(0,M.cn)("relative",e),...a,children:[(0,r.jsx)(tM.LM,{ref:s,"data-slot":"scroll-area-viewport",className:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:t}),(0,r.jsx)(tB,{}),(0,r.jsx)(tM.OK,{})]})}function tB({className:e,orientation:t="vertical",...s}){return(0,r.jsx)(tM.VM,{"data-slot":"scroll-area-scrollbar",orientation:t,className:(0,M.cn)("flex touch-none p-px transition-colors select-none","vertical"===t&&"h-full w-2.5 border-l border-l-transparent","horizontal"===t&&"h-2.5 flex-col border-t border-t-transparent",e),...s,children:(0,r.jsx)(tM.lr,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}let tO=["~/Projects","~/Developer","~/Code","~/dev"];function tU({onSelect:e,onCancel:t}){let[s,a]=(0,i.useState)(""),[n,o]=(0,i.useState)(null),[l,d]=(0,i.useState)([]),[c,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),x=(0,i.useCallback)(async e=>{u(!0),h(null);try{let t=e?`?path=${encodeURIComponent(e)}`:"",s=await (0,eo.tm)(`/api/browse-directories${t}`);if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error??`${s.status}`)}let r=await s.json();a(r.current),o(r.parent),d(r.entries)}catch(e){h(e instanceof Error?e.message:"Failed to browse")}finally{u(!1)}},[]);return(0,i.useEffect)(()=>{x()},[x]),(0,r.jsxs)("div",{className:"rounded-xl border border-border/50 bg-card/50 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-border/50 px-4 py-2.5",children:[(0,r.jsx)("p",{className:"min-w-0 truncate font-mono text-xs text-muted-foreground",title:s,children:s}),(0,r.jsx)(J,{type:"button",size:"sm",onClick:()=>e(s),className:"shrink-0 h-7 gap-1.5 text-xs transition-transform active:scale-[0.96]",children:"Select this folder"})]}),(0,r.jsx)(tq,{className:"h-[240px]",children:(0,r.jsxs)("div",{className:"px-1.5 py-1",children:[c&&(0,r.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin text-muted-foreground"})}),m&&(0,r.jsx)("div",{className:"px-3 py-4 text-center text-xs text-destructive",children:m}),!c&&!m&&(0,r.jsxs)(r.Fragment,{children:[n&&(0,r.jsxs)("button",{type:"button",onClick:()=>void x(n),className:"flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50",children:[(0,r.jsx)(tL.A,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:".."})]}),l.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>void x(e.path),className:"group flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50",children:[(0,r.jsx)(w.A,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-foreground",children:e.name}),(0,r.jsx)(P.A,{className:"h-3 w-3 shrink-0 text-muted-foreground/50 opacity-0 transition-opacity group-hover:opacity-100"})]},e.path)),0===l.length&&!n&&(0,r.jsx)("div",{className:"px-3 py-8 text-center text-xs text-muted-foreground",children:"No subdirectories"})]})]})}),(0,r.jsx)("div",{className:"border-t border-border/50 px-4 py-2",children:(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:t,className:"h-7 text-xs text-muted-foreground",children:"Cancel"})})]})}function tz({onNext:e,onBack:t}){let[s,a]=(0,i.useState)(""),[n,o]=(0,i.useState)(!1),[l,u]=(0,i.useState)(null),[m,x]=(0,i.useState)(!1),p=(0,i.useCallback)(e=>{a(e),u(null)},[]),g=(0,i.useCallback)(async()=>{let t=s.trim();if(!t)return void u("Enter a path or skip this step");o(!0),u(null);try{let s=await (0,eo.tm)("/api/preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:t})});if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error??`Request failed (${s.status})`)}e()}catch(e){u(e instanceof Error?e.message:"Failed to save preference")}finally{o(!1)}},[s,e]);return(0,r.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,r.jsx)(c.P.div,{initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},transition:{type:"spring",duration:.5,bounce:0},className:"mb-8",children:(0,r.jsx)("div",{className:"flex h-14 w-14 items-center justify-center rounded-xl border border-border/50 bg-card/50",children:(0,r.jsx)(tD.A,{className:"h-7 w-7 text-foreground/80",strokeWidth:1.5})})}),(0,r.jsx)(c.P.h2,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.06,duration:.4},className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Dev root"}),(0,r.jsx)(c.P.p,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.12,duration:.4},className:"mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground",children:"The folder that contains your projects. GSD discovers and manages workspaces inside it."}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.18,duration:.45},className:"mt-8 w-full max-w-md space-y-4",children:(0,r.jsx)(d.N,{mode:"wait",children:m?(0,r.jsx)(c.P.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},transition:{duration:.2},children:(0,r.jsx)(tU,{onSelect:e=>{a(e),x(!1),u(null)},onCancel:()=>x(!1)})},"browser"):(0,r.jsxs)(c.P.div,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e1.p,{value:s,onChange:e=>{a(e.target.value),l&&u(null)},placeholder:"/Users/you/Projects",className:(0,M.cn)("h-11 flex-1 font-mono text-sm",l&&"border-destructive/50 focus-visible:ring-destructive/30"),"data-testid":"onboarding-devroot-input",autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&s.trim()&&g()}}),(0,r.jsxs)(J,{type:"button",variant:"outline",onClick:()=>x(!0),className:"h-11 gap-2 shrink-0 transition-transform active:scale-[0.96]",children:[(0,r.jsx)(eE.A,{className:"h-4 w-4"}),"Browse"]})]}),l&&(0,r.jsx)("p",{className:"text-sm text-destructive",role:"alert",children:l}),(0,r.jsx)("div",{className:"flex flex-wrap items-center justify-center gap-2",children:tO.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>p(e),className:(0,M.cn)("rounded-full border px-3 py-1 font-mono text-xs transition-[background-color,border-color,color,transform] duration-150","active:scale-[0.96]",s===e?"border-foreground/25 bg-foreground/10 text-foreground":"border-border/50 text-muted-foreground hover:border-foreground/15 hover:text-foreground"),children:e},e))})]},"input")})}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.25,duration:.3},className:"mt-8 flex w-full max-w-md items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:t,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)(J,{variant:"ghost",onClick:e,className:"gap-1.5 text-muted-foreground transition-transform active:scale-[0.96]","data-testid":"onboarding-devroot-skip",children:["Skip",(0,r.jsx)(h.A,{className:"h-3.5 w-3.5"})]}),(0,r.jsx)(J,{onClick:()=>void g(),className:"group gap-2 transition-transform active:scale-[0.96]",disabled:n||m,"data-testid":"onboarding-devroot-continue",children:n?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}),"Saving…"]}):(0,r.jsxs)(r.Fragment,{children:["Continue",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})})]})]})]})}var tG=s(45760);function tW({sections:e,onBack:t,onNext:s}){let a=e.filter(e=>"remote_questions"!==e.id),n=a.filter(e=>e.configured).length;return(0,r.jsxs)("div",{className:"flex flex-col items-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:"text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Integrations"}),(0,r.jsx)("p",{className:"mt-2 text-sm leading-relaxed text-muted-foreground",children:"Optional tools. Nothing here blocks the workspace — configure later from settings."})]}),n>0&&(0,r.jsx)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.08,duration:.3},className:"mt-4",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"font-medium text-success",children:n})," of ",a.length," configured"]})}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.1,duration:.45},className:"mt-8 w-full space-y-2",children:a.map(e=>(0,r.jsxs)("div",{className:(0,M.cn)("flex items-start gap-3.5 rounded-xl border px-4 py-3.5 transition-colors",e.configured?"border-success/15 bg-success/[0.03]":"border-border/50 bg-card/50"),"data-testid":`onboarding-optional-${e.id}`,children:[(0,r.jsx)("div",{className:(0,M.cn)("mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full",e.configured?"bg-success/15 text-success":"bg-foreground/[0.05] text-muted-foreground"),children:e.configured?(0,r.jsx)(eZ.A,{className:"h-3 w-3",strokeWidth:3}):(0,r.jsx)(tG.A,{className:"h-3 w-3"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.label}),(0,r.jsxs)(tS.m_,{children:[(0,r.jsx)(tS.k$,{asChild:!0,children:(0,r.jsx)(tN,{variant:"outline",className:(0,M.cn)("text-[10px]",e.configured?"border-success/15 text-success/70":"border-border/50 text-muted-foreground"),children:e.configured?"Ready":"Skipped"})}),(0,r.jsx)(tS.ZI,{children:e.configured?"This integration is configured and active":"You can set this up later from workspace settings"})]})]}),e.configuredItems.length>0&&(0,r.jsx)("div",{className:"mt-1.5 flex flex-wrap gap-1",children:e.configuredItems.map(e=>(0,r.jsx)(tN,{variant:"outline",className:"border-border/50 text-[10px] text-muted-foreground",children:e},e))}),0===e.configuredItems.length&&(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"Not configured — add later from settings."})]})]},e.id))}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.18,duration:.3},className:"mt-8 flex w-full items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:t,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)(J,{onClick:s,className:"group gap-2 transition-transform active:scale-[0.96]","data-testid":"onboarding-optional-continue",children:["Continue",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})]})}var tK=s(2959),tV=s(64791);let tH=[{value:"slack",label:"Slack",description:"Get notified in a Slack channel"},{value:"discord",label:"Discord",description:"Get notified in a Discord channel"},{value:"telegram",label:"Telegram",description:"Get notified via Telegram bot"}],tY={slack:"Channel ID (e.g. C01ABCD2EFG)",discord:"Channel ID (17–20 digit number)",telegram:"Chat ID (numeric, may start with -)"},tJ={slack:/^[A-Z0-9]{9,12}$/,discord:/^\d{17,20}$/,telegram:/^-?\d{5,20}$/},tQ={slack:"SLACK_BOT_TOKEN",discord:"DISCORD_BOT_TOKEN",telegram:"TELEGRAM_BOT_TOKEN"};function tZ({onBack:e,onNext:t}){let[s,a]=(0,i.useState)(null),[n,o]=(0,i.useState)(""),[l,d]=(0,i.useState)(!1),[m,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,b]=(0,i.useState)(!1),[v,j]=(0,i.useState)(!0),[y,w]=(0,i.useState)(""),[N,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[A,R]=(0,i.useState)(!1),[T,E]=(0,i.useState)(null);(0,i.useEffect)(()=>{(0,eo.tm)("/api/remote-questions",{cache:"no-store"}).then(e=>e.json()).then(e=>{e.tokenSet&&R(!0),"configured"===e.status&&e.config&&(b(!0),a(e.config.channel),o(e.config.channelId),g(!0))}).catch(()=>{}).finally(()=>j(!1))},[]);let P=null!==s&&n.trim().length>0&&tJ[s].test(n.trim()),_=(0,i.useCallback)(async()=>{if(s&&P){d(!0),x(null);try{let e=await (0,eo.tm)("/api/remote-questions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:s,channelId:n.trim(),timeoutMinutes:5,pollIntervalSeconds:5})}),t=await e.json();if(!e.ok)return void x(t.error??`Save failed (${e.status})`);g(!0),b(!0)}catch(e){x(e instanceof Error?e.message:"Failed to save")}finally{d(!1)}}},[s,n,P]),I=(0,i.useCallback)(async()=>{if(s&&y.trim()){C(!0),x(null),E(null);try{let e=await (0,eo.tm)("/api/remote-questions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:s,token:y.trim()})}),t=await e.json();if(!e.ok)return void x(t.error??`Token save failed (${e.status})`);E(`Token saved (${t.masked})`),R(!0),w(""),S(!1)}catch(e){x(e instanceof Error?e.message:"Failed to save token")}finally{C(!1)}}},[s,y]);return(0,r.jsxs)("div",{className:"flex flex-col items-center",children:[(0,r.jsx)(c.P.div,{initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},transition:{type:"spring",duration:.5,bounce:0},className:"mb-8",children:(0,r.jsx)("div",{className:"flex h-14 w-14 items-center justify-center rounded-xl border border-border/50 bg-card/50",children:(0,r.jsx)(eH.A,{className:"h-7 w-7 text-foreground/80",strokeWidth:1.5})})}),(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.06,duration:.4},className:"text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Remote notifications"}),(0,r.jsx)("p",{className:"mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground",children:"Get notified when GSD needs your input. Connect a chat channel and the agent pings you instead of waiting silently."})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.12,duration:.45},className:"mt-8 w-full max-w-md space-y-5",children:[p&&(0,r.jsxs)("div",{className:"flex items-center gap-3 rounded-xl border border-success/15 bg-success/[0.04] px-4 py-3 text-sm",children:[(0,r.jsx)(u.A,{className:"h-4 w-4 shrink-0 text-success"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:f&&!l?`Connected to ${s??"channel"}`:"Configuration saved"})]}),!v&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Channel"}),(0,r.jsx)("div",{className:"grid grid-cols-3 gap-2",children:tH.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>{a(e.value),x(null),p&&!f&&g(!1)},disabled:l,className:(0,M.cn)("rounded-xl border px-3 py-3 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",s===e.value?"border-foreground/30 bg-foreground/[0.06]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50"),children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.label}),(0,r.jsx)("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:e.description})]},e.value))})]}),s&&!v&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Channel ID"}),(0,r.jsx)(e1.p,{value:n,onChange:e=>{o(e.target.value),m&&x(null)},placeholder:tY[s],disabled:l,className:"font-mono text-sm",onKeyDown:e=>{"Enter"===e.key&&P&&_()}}),n.trim().length>0&&!tJ[s].test(n.trim())&&(0,r.jsxs)("p",{className:"text-xs text-destructive/70",children:["Doesn't match the expected format for ",s]})]}),s&&!v&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"text-xs font-medium text-muted-foreground",children:["Bot token",A&&(0,r.jsx)("span",{className:"ml-2 text-success",children:"✓ configured"})]}),T&&(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded-xl border border-success/15 bg-success/[0.04] px-3 py-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 shrink-0 text-success"}),T]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)(e1.p,{type:N?"text":"password",value:y,onChange:e=>w(e.target.value),placeholder:`Paste your ${tQ[s]}`,disabled:k,className:"pr-9 font-mono text-sm",onKeyDown:e=>{"Enter"===e.key&&y.trim()&&I()}}),(0,r.jsx)("button",{type:"button",onClick:()=>S(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-muted-foreground transition-colors",children:N?(0,r.jsx)(tK.A,{className:"h-3.5 w-3.5"}):(0,r.jsx)(tV.A,{className:"h-3.5 w-3.5"})})]}),(0,r.jsxs)(J,{type:"button",variant:"outline",onClick:()=>void I(),disabled:!y.trim()||k,className:"gap-1.5 transition-transform active:scale-[0.96]",children:[k?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(tA.A,{className:"h-3.5 w-3.5"}),"Save"]})]})]}),m&&(0,r.jsx)("div",{className:"rounded-xl border border-destructive/20 bg-destructive/[0.06] px-4 py-3 text-sm text-destructive",children:m}),s&&n.trim().length>0&&!p&&(0,r.jsxs)(J,{onClick:()=>void _(),disabled:!P||l,className:"gap-2 transition-transform active:scale-[0.96]",children:[l?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(u.A,{className:"h-4 w-4"}),"Save & connect"]}),v&&(0,r.jsxs)("div",{className:"flex items-center gap-2 py-4 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Checking existing configuration…"]})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.2,duration:.3},className:"mt-8 flex w-full max-w-md items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:e,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[!p&&(0,r.jsxs)(J,{variant:"ghost",onClick:t,className:"gap-1.5 text-muted-foreground transition-transform active:scale-[0.96]",children:["Skip",(0,r.jsx)(h.A,{className:"h-3.5 w-3.5"})]}),(0,r.jsxs)(J,{onClick:t,className:"group gap-2 transition-transform active:scale-[0.96]",children:["Continue",(0,r.jsx)(e$.A,{className:"h-4 w-4 transition-transform group-hover:translate-x-0.5"})]})]})]})]})}function tX({providerLabel:e,onFinish:t}){return(0,r.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,scale:.7},animate:{opacity:1,scale:1},transition:{type:"spring",duration:.6,bounce:.15},className:"relative mb-8",children:[(0,r.jsx)("div",{className:"absolute inset-0 rounded-full bg-success/10 blur-2xl"}),(0,r.jsx)("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-2xl border border-success/20 bg-success/10",children:(0,r.jsx)(u.A,{className:"h-8 w-8 text-success",strokeWidth:1.5})})]}),(0,r.jsx)(c.P.h2,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.1,duration:.4},className:"text-3xl font-bold tracking-tight text-foreground sm:text-4xl",children:"You're all set"}),(0,r.jsxs)(c.P.p,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.18,duration:.4},className:"mt-3 max-w-sm text-[15px] leading-relaxed text-muted-foreground",children:[(0,r.jsx)("span",{className:"font-medium text-foreground",children:e})," is validated. The workspace is live."]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{delay:.26,duration:.4},className:"mt-8 flex items-center gap-4 rounded-xl border border-border/50 bg-card/50 px-5 py-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(a.default,{src:"/logo-icon-white.svg",alt:"",width:14,height:14,className:"hidden opacity-40 dark:block"}),(0,r.jsx)(a.default,{src:"/logo-icon-black.svg",alt:"",width:14,height:14,className:"opacity-40 dark:hidden"}),(0,r.jsx)("span",{children:"Shell unlocked"})]}),(0,r.jsx)("div",{className:"h-3 w-px bg-border"}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-success"}),(0,r.jsx)("span",{children:e})]})]}),(0,r.jsx)(c.P.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.35,duration:.4},className:"mt-8",children:(0,r.jsxs)(J,{size:"lg",className:"group gap-2.5 px-8 text-[15px] transition-transform active:scale-[0.96]",onClick:t,"data-testid":"onboarding-finish",children:["Launch workspace",(0,r.jsx)(eb.A,{className:"h-4 w-4 transition-transform group-hover:scale-110"})]})})]})}var t0=s(86788),t1=s(96526);let t5={"active-gsd":{label:"Active",color:"text-success",icon:t0.A},"empty-gsd":{label:"Initialized",color:"text-info",icon:eE.A},brownfield:{label:"Existing",color:"text-warning",icon:C.A},"v1-legacy":{label:"Legacy",color:"text-warning",icon:C.A},blank:{label:"New",color:"text-muted-foreground",icon:e_.A}};function t2({onFinish:e,onBack:t,onBeforeSwitch:s}){let a=en(),[n,o]=(0,i.useState)(null),[l,d]=(0,i.useState)([]),[u,m]=(0,i.useState)(!0),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),[f,b]=(0,i.useState)(""),[v,j]=(0,i.useState)(!1),[y,w]=(0,i.useState)(null),N=(0,i.useRef)(null),[S,k]=(0,i.useState)(null),C=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=!1;return async function(){m(!0),x(null);try{let t=await (0,eo.tm)("/api/preferences");if(!t.ok)throw Error("Failed to load preferences");let s=await t.json();if(!s.devRoot){o(null),d([]),m(!1);return}o(s.devRoot);let r=await (0,eo.tm)(`/api/projects?root=${encodeURIComponent(s.devRoot)}&detail=true`);if(!r.ok)throw Error("Failed to discover projects");let a=await r.json();e||d(a)}catch(t){e||x(t instanceof Error?t.message:"Unknown error")}finally{e||m(!1)}}(),()=>{e=!0}},[]),(0,i.useEffect)(()=>()=>{C.current&&clearInterval(C.current)},[]),(0,i.useEffect)(()=>{if(p){let e=setTimeout(()=>N.current?.focus(),50);return()=>clearTimeout(e)}},[p]);let A=l.map(e=>e.name),R=/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(f),T=A.includes(f),E=f.length>0&&R&&!T&&!v,P=(0,i.useCallback)(t=>{s?.(),k(t.path);let r=a.switchProject(t.path);C.current&&clearInterval(C.current);let n=Date.now();C.current=setInterval(()=>{let s=r.getSnapshot(),a=Date.now()-n;("ready"===s.bootStatus||"error"===s.bootStatus||a>3e4)&&(C.current&&clearInterval(C.current),C.current=null,k(null),e(t.path))},150)},[a,e,s]),_=(0,i.useCallback)(async()=>{if(E&&n){j(!0),w(null);try{let e=await (0,eo.tm)("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:n,name:f})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Failed (${e.status})`)}let t=await e.json();d(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),b(""),g(!1),P(t)}catch(e){w(e instanceof Error?e.message:"Failed to create project"),j(!1)}}},[E,n,f,P]),I=!u&&!n,$=[...l].sort((e,t)=>{let s={"active-gsd":0,"empty-gsd":1,brownfield:2,"v1-legacy":3,blank:4},r=s[e.kind]??5,a=s[t.kind]??5;return r!==a?r-a:e.name.localeCompare(t.name)});return(0,r.jsxs)("div",{className:"flex flex-col items-center",children:[(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:"text-center",children:[(0,r.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-foreground sm:text-3xl",children:"Open a project"}),(0,r.jsx)("p",{className:"mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground",children:I?"Set a dev root first to discover your projects.":"Pick a project to start working in, or create a new one."})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{delay:.08,duration:.45},className:"mt-8 w-full max-w-lg space-y-2",children:[u&&(0,r.jsxs)("div",{className:"flex items-center justify-center gap-2 py-10 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}),"Discovering projects…"]}),h&&(0,r.jsx)("div",{className:"rounded-xl border border-destructive/20 bg-destructive/[0.06] px-4 py-3 text-sm text-destructive",children:h}),I&&(0,r.jsx)("div",{className:"rounded-xl border border-border/50 bg-card/50 px-4 py-6 text-center text-sm text-muted-foreground",children:"No dev root configured. Go back and set one, or finish setup to configure later."}),!u&&$.length>0&&(0,r.jsx)("div",{className:"space-y-2",children:$.map(e=>{var t;let s,a=S===e.path,n=t5[e.kind],i=n.icon,o=(t=e.signals,s=[],t.isMonorepo&&s.push("Monorepo"),t.hasGitRepo&&s.push("Git"),t.hasPackageJson&&s.push("Node.js"),t.hasCargo&&s.push("Rust"),t.hasGoMod&&s.push("Go"),t.hasPyproject&&s.push("Python"),s),l=e.progress?function(e){if(0===e.milestonesTotal)return null;let t=[];return e.activeMilestone&&t.push(e.activeMilestone),e.activeSlice&&t.push(e.activeSlice),e.phase&&t.push(e.phase),t.join(" \xb7 ")||null}(e.progress):null,d=e.progress?`${e.progress.milestonesCompleted}/${e.progress.milestonesTotal}`:null;return(0,r.jsxs)("button",{type:"button",onClick:()=>P(e),disabled:!!S,className:(0,M.cn)("group flex w-full items-start gap-3.5 rounded-xl border px-4 py-3.5 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",a?"border-foreground/30 bg-foreground/[0.06]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50",S&&!a&&"opacity-40 pointer-events-none"),children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-9 w-9 shrink-0 items-center justify-center rounded-lg mt-0.5","active-gsd"===e.kind?"bg-success/10":"bg-foreground/[0.04]"),children:a?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}):(0,r.jsx)(i,{className:(0,M.cn)("h-4 w-4",n.color)})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground truncate",children:e.name}),(0,r.jsx)("span",{className:(0,M.cn)("text-[10px] font-medium shrink-0",n.color),children:n.label})]}),o.length>0&&(0,r.jsx)("div",{className:"mt-1 flex items-center gap-1.5",children:o.map(e=>(0,r.jsx)("span",{className:"rounded bg-foreground/[0.04] px-1.5 py-0.5 text-[10px] text-muted-foreground",children:e},e))}),l&&(0,r.jsx)("div",{className:"mt-1.5 text-[11px] text-muted-foreground",children:l}),e.progress&&e.progress.milestonesTotal>0&&(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,r.jsx)("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-foreground/[0.06]",children:(0,r.jsx)("div",{className:"h-full rounded-full bg-success/60 transition-[width]",style:{width:`${Math.round(e.progress.milestonesCompleted/e.progress.milestonesTotal*100)}%`}})}),(0,r.jsx)("span",{className:"text-[10px] tabular-nums text-muted-foreground",children:d})]})]}),(0,r.jsx)(e$.A,{className:"mt-1 h-4 w-4 shrink-0 text-muted-foreground/50 transition-[color,transform] group-hover:text-muted-foreground group-hover:translate-x-0.5"})]},e.path)})}),!u&&n&&0===l.length&&!h&&(0,r.jsxs)("div",{className:"rounded-xl border border-border/50 bg-card/50 px-4 py-6 text-center text-sm text-muted-foreground",children:["No projects found in ",n]}),!u&&n&&(0,r.jsx)(r.Fragment,{children:p?(0,r.jsxs)(c.P.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},transition:{duration:.2},className:"rounded-xl border border-border/50 bg-card/50 p-4 space-y-3",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"New project"}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault(),_()},className:"space-y-2",children:[(0,r.jsx)(e1.p,{ref:N,value:f,onChange:e=>{b(e.target.value),w(null)},placeholder:"my-project",autoComplete:"off",className:"text-sm",disabled:v}),f&&!R&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:"Letters, numbers, hyphens, underscores, dots. Must start with a letter or number."}),T&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:"A project with this name already exists"}),y&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:y}),f&&R&&!T&&(0,r.jsxs)("p",{className:"font-mono text-xs text-muted-foreground",children:[n,"/",f]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,r.jsxs)(J,{type:"submit",size:"sm",disabled:!E,className:"gap-1.5 transition-transform active:scale-[0.96]",children:[v?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(t1.A,{className:"h-3.5 w-3.5"}),"Create & open"]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>{g(!1),b(""),w(null)},disabled:v,className:"text-muted-foreground",children:"Cancel"})]})]})]}):(0,r.jsxs)("button",{type:"button",onClick:()=>g(!0),disabled:!!S,className:(0,M.cn)("flex w-full items-center gap-3.5 rounded-xl border border-dashed px-4 py-3.5 text-left transition-[background-color,border-color,color,transform] duration-200","border-border/50 text-muted-foreground hover:border-foreground/15 hover:text-foreground","active:scale-[0.96]",S&&"opacity-40 pointer-events-none"),children:[(0,r.jsx)("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-foreground/[0.04]",children:(0,r.jsx)(t1.A,{className:"h-4 w-4"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Create new project"}),(0,r.jsx)("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Initialize a new directory with Git"})]})]})})]}),(0,r.jsxs)(c.P.div,{initial:{opacity:0},animate:{opacity:1},transition:{delay:.15,duration:.3},className:"mt-8 flex w-full max-w-lg items-center justify-between",children:[(0,r.jsx)(J,{variant:"ghost",onClick:t,className:"text-muted-foreground transition-transform active:scale-[0.96]",children:"Back"}),(0,r.jsxs)(J,{onClick:()=>{s?.(),e("")},className:"group gap-2 transition-transform active:scale-[0.96]",children:["Finish setup",(0,r.jsx)(eb.A,{className:"h-4 w-4 transition-transform group-hover:scale-110"})]})]})]})}let t3=[{id:"welcome",label:"Welcome"},{id:"mode",label:"Mode"},{id:"provider",label:"Provider"},{id:"authenticate",label:"Auth"},{id:"devRoot",label:"Root"},{id:"optional",label:"Extras"},{id:"remote",label:"Remote"},{id:"ready",label:"Ready"},{id:"project",label:"Project"}],t4=t3.length,t8=[],t6={enter:e=>({x:e>0?50:-50,opacity:0}),center:{x:0,opacity:1},exit:e=>({x:e<0?50:-50,opacity:0})};function t7({current:e,total:t}){return(0,r.jsx)("div",{className:"flex items-center gap-1",children:Array.from({length:t},(t,s)=>(0,r.jsx)("div",{className:(0,M.cn)("rounded-full transition-[width,background-color] duration-300",s===e?"h-1.5 w-5 bg-foreground":s<e?"h-1.5 w-1.5 bg-foreground/40":"h-1.5 w-1.5 bg-foreground/10")},s))})}function t9(){let e=(0,Z.gF)(),{refreshOnboarding:t,saveApiKey:s,startProviderFlow:n,submitProviderFlowInput:o,cancelProviderFlow:l,refreshBoot:u}=(0,Z._l)(),m=tx(),h=e.boot?.onboarding,x=m.isActive("forceOnboarding"),p="idle"!==e.onboardingRequestState,[g,f]=(0,i.useState)(0),[b,v]=(0,i.useState)(0),[j,y]=(0,i.useState)(null),[w,N]=(0,i.useState)(!1),[S,k]=(0,tp.s1)(),[C,A]=(0,i.useState)(S),R=h?.required.providers??t8,T=(0,i.useMemo)(()=>{if(h?.activeFlow?.providerId)return h.activeFlow.providerId;if(j&&R.some(e=>e.id===j))return j;let e=R.find(e=>!e.configured&&e.recommended);if(e)return e.id;let t=R.find(e=>!e.configured);return t?t.id:R[0]?.id??null},[h?.activeFlow?.providerId,R,j]),E=w&&!h?.locked&&!p,[P,_]=(0,i.useState)(!1),I=(0,i.useCallback)(e=>{3===e&&h?.locked?_(!0):3!==e||h?.locked||_(!1),v(e>g?1:-1),f(e)},[g,h?.locked]);(0,i.useEffect)(()=>{if(!h||3!==g||!P)return;let e=!h.locked,t="succeeded"===h.bridgeAuthRefresh.phase||"idle"===h.bridgeAuthRefresh.phase;if(!e||!t)return;let s=window.setTimeout(()=>I(4),0);return()=>window.clearTimeout(s)},[h,I,g,P]);let F=(0,i.useMemo)(()=>R.find(e=>e.id===T)??null,[T,R]);if(!h)return null;let $=!h.locked||h.lastValidation?.status==="succeeded"&&("succeeded"===h.bridgeAuthRefresh.phase||"idle"===h.bridgeAuthRefresh.phase);if(!x&&($||E))return null;let L=t3[g]?.label??"";return(0,r.jsxs)("div",{className:"pointer-events-auto absolute inset-0 z-30 flex flex-col bg-background","data-testid":"onboarding-gate",children:[(0,r.jsxs)("header",{className:"relative z-10 flex h-12 shrink-0 items-center justify-between px-5 md:px-8",children:[(0,r.jsxs)("div",{className:"flex w-24 items-center gap-2",children:[(0,r.jsx)(a.default,{src:"/logo-white.svg",alt:"GSD-Pi Web",width:57,height:16,className:"hidden h-4 w-auto dark:block"}),(0,r.jsx)(a.default,{src:"/logo-black.svg",alt:"GSD-Pi Web",width:57,height:16,className:"h-4 w-auto dark:hidden"})]}),(0,r.jsx)("div",{className:"absolute inset-x-0 flex justify-center pointer-events-none",children:(0,r.jsx)("div",{className:"pointer-events-auto",children:(0,r.jsx)(t7,{current:g,total:t4})})}),(0,r.jsx)("div",{className:"flex w-24 justify-end",children:(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:L})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,r.jsx)("div",{className:"mx-auto flex min-h-full w-full max-w-2xl flex-col justify-center px-5 py-10 md:px-8 md:py-16",children:(0,r.jsx)(d.N,{mode:"wait",custom:b,children:(0,r.jsxs)(c.P.div,{custom:b,variants:t6,initial:"enter",animate:"center",exit:"exit",transition:{type:"spring",stiffness:400,damping:35,opacity:{duration:.15}},children:[0===g&&(0,r.jsx)(tg,{onNext:()=>I(1)}),1===g&&(0,r.jsx)(tj,{selected:C,onSelect:e=>{A(e),k(e)},onNext:()=>I(2),onBack:()=>I(0)}),2===g&&(0,r.jsx)(tk,{providers:h.required.providers,selectedId:T,onSelect:e=>{y(e),I(3)},onNext:()=>I(4),onBack:()=>I(1)}),3===g&&F&&(0,r.jsx)(t$,{provider:F,activeFlow:h.activeFlow,lastValidation:h.lastValidation,requestState:e.onboardingRequestState,requestProviderId:e.onboardingRequestProviderId,onSaveApiKey:async(e,t)=>{let r=await s(e,t);return r&&!r.locked&&("succeeded"===r.bridgeAuthRefresh.phase||"idle"===r.bridgeAuthRefresh.phase)&&(N(!0),u()),r},onStartFlow:e=>void n(e),onSubmitFlowInput:(e,t)=>void o(e,t),onCancelFlow:e=>void l(e),onBack:()=>I(2),onNext:()=>I(2),bridgeRefreshPhase:h.bridgeAuthRefresh.phase,bridgeRefreshError:h.bridgeAuthRefresh.error}),4===g&&(0,r.jsx)(tz,{onBack:()=>I(2),onNext:()=>I(5)}),5===g&&(0,r.jsx)(tW,{sections:h.optional.sections,onBack:()=>I(4),onNext:()=>I(6)}),6===g&&(0,r.jsx)(tZ,{onBack:()=>I(5),onNext:()=>I(7)}),7===g&&(0,r.jsx)(tX,{providerLabel:h.lastValidation?.providerId?h.required.providers.find(e=>e.id===h.lastValidation?.providerId)?.label??"Provider":"Provider",onFinish:()=>I(8)}),8===g&&(0,r.jsx)(t2,{onBack:()=>I(7),onBeforeSwitch:()=>{m.isActive("forceOnboarding")&&m.toggle("forceOnboarding"),N(!0)},onFinish:()=>{(0,et.k8)("dashboard"),u()}})]},g)})})})]})}var se=s(12875),st=s(85794),ss=s(18834),sr=s(37464),sa=s(57714),sn=s(52160),si=s(29492),so=s(41881),sl=s(50417),sd=s(13586),sc=s(91262),su=s(95904),sm=s(82773),sh=s(15392);function sx({className:e,...t}){return(0,r.jsx)(sh.bL,{"data-slot":"switch",className:(0,M.cn)("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-[background-color,border-color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:(0,r.jsx)(sh.zi,{"data-slot":"switch-thumb",className:"bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"})})}var sp=s(37144),sg=s(86419);function sf({severity:e,className:t}){let s=(0,M.cn)("h-3.5 w-3.5 shrink-0",t);switch(e){case"error":case"critical":return(0,r.jsx)(tP.A,{className:(0,M.cn)(s,"text-destructive")});case"warning":return(0,r.jsx)(ez.A,{className:(0,M.cn)(s,"text-warning")});default:return(0,r.jsx)(eG.A,{className:(0,M.cn)(s,"text-info")})}}function sb(e){return"error"===e||"critical"===e?"destructive":"warning"===e?"secondary":"outline"}function sv({title:e,subtitle:t,status:s,onRefresh:a,refreshing:n}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 pb-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:e}),s,t&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:t})]}),(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:a,disabled:n,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",n&&"animate-spin")}),"Refresh"]})]})}function sj({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive",children:e})}function sy({label:e}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),e]})}function sw({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-4 py-5 text-center text-xs text-muted-foreground",children:e})}function sN({label:e,value:t,variant:s}){return(0,r.jsxs)("div",{className:(0,M.cn)("flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs","error"===s&&"border-destructive/20 bg-destructive/5 text-destructive","warning"===s&&"border-warning/20 bg-warning/5 text-warning","info"===s&&"border-info/20 bg-info/5 text-info",(!s||"default"===s)&&"border-border/50 bg-card/50 text-foreground/80"),children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:e}),(0,r.jsx)("span",{className:"font-medium tabular-nums",children:t})]})}function sS({anomaly:e}){return(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(sf,{severity:e.severity}),(0,r.jsx)(tN,{variant:sb(e.severity),className:"text-[10px] px-1.5 py-0",children:e.severity}),(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:e.type}),e.unitId&&(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground font-mono truncate",children:[e.unitType,"/",e.unitId]})]}),(0,r.jsx)("p",{className:"text-xs text-foreground",children:e.summary}),e.details&&e.details!==e.summary&&(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:e.details})]})}function sk(){let e=(0,Z.gF)(),{loadForensicsDiagnostics:t}=(0,Z._l)(),s=e.commandSurface.diagnostics.forensics,a=s.data,n="loading"===s.phase;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"diagnostics-forensics",children:[(0,r.jsx)(sv,{title:"Forensic Analysis",subtitle:a?new Date(a.timestamp).toLocaleString():null,status:a?(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-1.5 w-1.5 rounded-full",a.anomalies.length>0?"bg-warning":"bg-success")}):null,onRefresh:()=>void t(),refreshing:n}),s.error&&(0,r.jsx)(sj,{message:s.error}),n&&!a&&(0,r.jsx)(sy,{label:"Running forensic analysis…"}),a&&(0,r.jsxs)(r.Fragment,{children:[a.metrics&&(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(sN,{label:"Units",value:a.metrics.totalUnits}),(0,r.jsx)(sN,{label:"Cost",value:(0,Z.BD)(a.metrics.totalCost)}),(0,r.jsx)(sN,{label:"Duration",value:`${Math.round(a.metrics.totalDuration/1e3)}s`}),(0,r.jsx)(sN,{label:"Traces",value:a.unitTraceCount})]}),a.crashLock?(0,r.jsxs)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(tC.A,{className:"h-3.5 w-3.5 text-destructive"}),(0,r.jsx)("span",{className:"text-xs font-medium text-destructive",children:"Crash Lock Active"})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-0.5 text-[11px]",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"PID"}),(0,r.jsx)("span",{className:"font-mono text-foreground/80",children:a.crashLock.pid}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"Started"}),(0,r.jsx)("span",{className:"text-foreground/80",children:new Date(a.crashLock.startedAt).toLocaleString()}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"Unit"}),(0,r.jsxs)("span",{className:"font-mono text-foreground/80",children:[a.crashLock.unitType,"/",a.crashLock.unitId]})]})]}):(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-border/50 bg-card/50 px-3 py-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 text-success"}),"No crash lock"]}),a.anomalies.length>0?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Anomalies (",a.anomalies.length,")"]}),a.anomalies.map((e,t)=>(0,r.jsx)(sS,{anomaly:e},t))]}):(0,r.jsx)(sw,{message:"No anomalies detected"}),a.recentUnits.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Recent Units (",a.recentUnits.length,")"]}),(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"ID"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Model"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Duration"})]})}),(0,r.jsx)("tbody",{children:a.recentUnits.map((e,t)=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.type}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 truncate max-w-[120px]",children:e.id}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:e.model}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.cost)}),(0,r.jsxs)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:[Math.round(e.duration/1e3),"s"]})]},t))})]})})]})]})]})}function sC({issue:e}){return(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)(sf,{severity:e.severity}),(0,r.jsx)(tN,{variant:sb(e.severity),className:"text-[10px] px-1.5 py-0",children:e.severity}),(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:e.code.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase())}),e.scope&&(0,r.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono",children:e.scope}),e.fixable&&(0,r.jsxs)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-success/30 text-success",children:[(0,r.jsx)(sg.A,{className:"h-2.5 w-2.5 mr-0.5"}),"fixable"]})]}),(0,r.jsx)("p",{className:"text-xs text-foreground",children:e.message}),e.file&&(0,r.jsx)("p",{className:"text-[10px] font-mono text-muted-foreground truncate",children:e.file})]})}function sA(){let e=(0,Z.gF)(),{loadDoctorDiagnostics:t,applyDoctorFixes:s}=(0,Z._l)(),a=e.commandSurface.diagnostics.doctor,n=a.data,i="loading"===a.phase,o=n?.summary.fixable??0;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"diagnostics-doctor",children:[(0,r.jsx)(sv,{title:"Doctor Health Check",status:n?(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-1.5 w-1.5 rounded-full",n.ok?"bg-success":"bg-destructive")}):null,onRefresh:()=>void t(),refreshing:i}),a.error&&(0,r.jsx)(sj,{message:a.error}),i&&!n&&(0,r.jsx)(sy,{label:"Running health check…"}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(sN,{label:"Total",value:n.summary.total}),n.summary.errors>0&&(0,r.jsx)(sN,{label:"Errors",value:n.summary.errors,variant:"error"}),n.summary.warnings>0&&(0,r.jsx)(sN,{label:"Warnings",value:n.summary.warnings,variant:"warning"}),n.summary.infos>0&&(0,r.jsx)(sN,{label:"Info",value:n.summary.infos,variant:"info"}),o>0&&(0,r.jsx)(sN,{label:"Fixable",value:o,variant:"info"})]}),o>0&&(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)(J,{type:"button",variant:"default",size:"sm",onClick:()=>void s(),disabled:a.fixPending,className:"h-7 gap-1.5 text-xs","data-testid":"doctor-apply-fixes",children:[a.fixPending?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(sg.A,{className:"h-3 w-3"}),"Apply Fixes (",o,")"]}),a.lastFixError&&(0,r.jsx)("span",{className:"text-[11px] text-destructive",children:a.lastFixError})]}),a.lastFixResult&&a.lastFixResult.fixesApplied.length>0&&(0,r.jsxs)("div",{className:"rounded-lg border border-success/20 bg-success/5 px-3 py-2.5 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 text-success"}),(0,r.jsx)("span",{className:"text-xs font-medium text-success",children:"Fixes Applied"})]}),(0,r.jsx)("ul",{className:"space-y-0.5 pl-5",children:a.lastFixResult.fixesApplied.map((e,t)=>(0,r.jsx)("li",{className:"text-[11px] text-foreground/80 list-disc",children:e},t))})]}),n.issues.length>0?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Issues (",n.issues.length,")"]}),n.issues.map((e,t)=>(0,r.jsx)(sC,{issue:e},t))]}):(0,r.jsx)(sw,{message:"No issues found — workspace is healthy"})]})]})}function sR({suggestion:e}){return(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)(sf,{severity:e.severity}),(0,r.jsx)(tN,{variant:sb(e.severity),className:"text-[10px] px-1.5 py-0",children:e.severity}),(0,r.jsx)("span",{className:"text-[11px] font-medium text-foreground/80",children:e.skillName}),(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:e.trigger.replace(/_/g," ")})]}),(0,r.jsx)("p",{className:"text-xs text-foreground",children:e.message})]})}function sT(){let e=(0,Z.gF)(),{loadSkillHealthDiagnostics:t}=(0,Z._l)(),s=e.commandSurface.diagnostics.skillHealth,a=s.data,n="loading"===s.phase;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"diagnostics-skill-health",children:[(0,r.jsx)(sv,{title:"Skill Health",subtitle:a?new Date(a.generatedAt).toLocaleString():null,status:a?(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-1.5 w-1.5 rounded-full",a.decliningSkills.length>0?"bg-warning":"bg-success")}):null,onRefresh:()=>void t(),refreshing:n}),s.error&&(0,r.jsx)(sj,{message:s.error}),n&&!a&&(0,r.jsx)(sy,{label:"Analyzing skill health…"}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(sN,{label:"Skills",value:a.skills.length}),a.staleSkills.length>0&&(0,r.jsx)(sN,{label:"Stale",value:a.staleSkills.length,variant:"warning"}),a.decliningSkills.length>0&&(0,r.jsx)(sN,{label:"Declining",value:a.decliningSkills.length,variant:"error"}),(0,r.jsx)(sN,{label:"Total units",value:a.totalUnitsWithSkills})]}),a.skills.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Skills (",a.skills.length,")"]}),(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Skill"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Uses"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Success"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Tokens"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-center font-medium text-muted-foreground",children:"Trend"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Stale"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"})]})}),(0,r.jsx)("tbody",{children:a.skills.map(e=>{var t,s;return(0,r.jsxs)("tr",{className:(0,M.cn)("border-b border-border/50 last:border-0",e.flagged&&"bg-destructive/3"),children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[e.name,e.flagged&&(0,r.jsx)(ez.A,{className:"h-3 w-3 text-warning shrink-0"})]})}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:e.totalUses}),(0,r.jsxs)("td",{className:(0,M.cn)("px-2.5 py-1.5 text-right tabular-nums",e.successRate>=.9?"text-success":e.successRate>=.7?"text-warning":"text-destructive"),children:[(100*e.successRate).toFixed(0),"%"]}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:Math.round(e.avgTokens)}),(0,r.jsx)("td",{className:(0,M.cn)("px-2.5 py-1.5 text-center","rising"===(t=e.tokenTrend)?"text-warning":"declining"===t?"text-destructive":"text-muted-foreground"),children:"rising"===(s=e.tokenTrend)?"↑":"declining"===s?"↓":"→"}),(0,r.jsx)("td",{className:(0,M.cn)("px-2.5 py-1.5 text-right tabular-nums",e.staleDays>30?"text-warning":"text-foreground/80"),children:e.staleDays>0?`${e.staleDays}d`:"—"}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.avgCost)})]},e.name)})})]})})]}),a.staleSkills.length>0&&(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-xs font-medium text-muted-foreground",children:"Stale Skills"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:a.staleSkills.map(e=>(0,r.jsx)(tN,{variant:"secondary",className:"text-[10px] font-mono",children:e},e))})]}),a.decliningSkills.length>0&&(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-xs font-medium text-muted-foreground",children:"Declining Skills"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:a.decliningSkills.map(e=>(0,r.jsx)(tN,{variant:"destructive",className:"text-[10px] font-mono",children:e},e))})]}),a.suggestions.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Suggestions (",a.suggestions.length,")"]}),a.suggestions.map((e,t)=>(0,r.jsx)(sR,{suggestion:e},t))]}),0===a.skills.length&&0===a.suggestions.length&&(0,r.jsx)(sw,{message:"No skill usage data available"})]})]})}var sE=s(3150),sP=s(86002),s_=s(63089),sI=s(84971),sF=s(53709),s$=s(79384),sL=s(44302),sD=s(68206);function sM({title:e,subtitle:t,status:s,onRefresh:a,refreshing:n}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 pb-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:e}),s,t&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:t})]}),(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:a,disabled:n,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",n&&"animate-spin")}),"Refresh"]})]})}function sq({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive",children:e})}function sB({label:e}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),e]})}function sO({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-4 py-5 text-center text-xs text-muted-foreground",children:e})}function sU({label:e,value:t,variant:s}){return(0,r.jsxs)("div",{className:(0,M.cn)("flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs","error"===s&&"border-destructive/20 bg-destructive/5 text-destructive","warning"===s&&"border-warning/20 bg-warning/5 text-warning","info"===s&&"border-info/20 bg-info/5 text-info",(!s||"default"===s)&&"border-border/50 bg-card/50 text-foreground/80"),children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:e}),(0,r.jsx)("span",{className:"font-medium tabular-nums",children:t})]})}function sz({type:e,className:t}){let s=(0,M.cn)("h-3.5 w-3.5 shrink-0",t);switch(e){case"rule":return(0,r.jsx)(sE.A,{className:(0,M.cn)(s,"text-violet-400")});case"pattern":return(0,r.jsx)(sP.A,{className:(0,M.cn)(s,"text-info")});case"lesson":return(0,r.jsx)(s_.A,{className:(0,M.cn)(s,"text-warning")});case"freeform":return(0,r.jsx)(_.A,{className:(0,M.cn)(s,"text-success")})}}function sG(e){switch(e){case"quick-task":return"Quick Task";case"inject":return"Inject";case"defer":return"Defer";case"replan":return"Replan";case"note":return"Note"}}function sW({classification:e,className:t}){let s=(0,M.cn)("h-3 w-3 shrink-0",t);switch(e){case"quick-task":return(0,r.jsx)(eb.A,{className:s});case"inject":return(0,r.jsx)(ss.A,{className:s});case"defer":return(0,r.jsx)(sI.A,{className:s});case"replan":return(0,r.jsx)(sF.A,{className:s});case"note":return(0,r.jsx)(s$.A,{className:s})}}let sK=["quick-task","inject","defer","replan","note"];function sV({entry:e}){let t=function(e){switch(e){case"rule":return{label:"Rule",className:"border-violet-500/30 bg-violet-500/10 text-violet-400"};case"pattern":return{label:"Pattern",className:"border-info/30 bg-info/10 text-info"};case"lesson":return{label:"Lesson",className:"border-warning/30 bg-warning/10 text-warning"};case"freeform":return{label:"Freeform",className:"border-success/30 bg-success/10 text-success"}}}(e.type);return(0,r.jsx)("div",{className:"group rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 transition-colors hover:bg-card/50",children:(0,r.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,r.jsx)(sz,{type:e.type,className:"mt-0.5"}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground truncate",children:e.title}),(0,r.jsx)(tN,{variant:"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0 h-4 shrink-0",t.className),children:t.label})]}),e.content&&(0,r.jsx)("p",{className:"mt-1 text-[11px] text-muted-foreground line-clamp-2 leading-relaxed",children:e.content})]})]})})}function sH({data:e,phase:t,error:s,onRefresh:a}){return"loading"===t?(0,r.jsx)(sB,{label:"Loading knowledge base…"}):"error"===t&&s?(0,r.jsx)(sq,{message:s}):e&&0!==e.entries.length?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(sM,{title:"Knowledge Base",subtitle:`${e.entries.length} entries`,onRefresh:a,refreshing:"loading"===t}),(0,r.jsx)("div",{className:"space-y-1.5",children:e.entries.map(e=>(0,r.jsx)(sV,{entry:e},e.id))}),e.lastModified&&(0,r.jsxs)("p",{className:"pt-2 text-[10px] text-muted-foreground",children:["Last modified: ",new Date(e.lastModified).toLocaleString()]})]}):(0,r.jsx)(sO,{message:"No knowledge entries found"})}function sY({entry:e,onResolve:t,resolvePending:s}){let a=function(e){switch(e){case"pending":return{label:"Pending",className:"border-warning/30 bg-warning/10 text-warning"};case"triaged":return{label:"Triaged",className:"border-info/30 bg-info/10 text-info"};case"resolved":return{label:"Resolved",className:"border-success/30 bg-success/10 text-success"}}}(e.status);return(0,r.jsx)("div",{className:"group rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 transition-colors hover:bg-card/50",children:(0,r.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,r.jsx)("div",{className:(0,M.cn)("mt-1 h-2 w-2 shrink-0 rounded-full","pending"===e.status&&"bg-warning","triaged"===e.status&&"bg-info","resolved"===e.status&&"bg-success")}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsx)("span",{className:"text-xs text-foreground",children:e.text}),(0,r.jsx)(tN,{variant:"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0 h-4 shrink-0",a.className),children:a.label}),e.classification&&(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 shrink-0 border-border/50 text-muted-foreground",children:sG(e.classification)})]}),e.timestamp&&(0,r.jsxs)("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-muted-foreground",children:[(0,r.jsx)(eg.A,{className:"h-2.5 w-2.5"}),e.timestamp]}),e.resolution&&(0,r.jsx)("p",{className:"mt-1 text-[10px] text-muted-foreground italic",children:e.resolution}),"pending"===e.status&&(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:sK.map(a=>(0,r.jsxs)(J,{type:"button",variant:"outline",size:"sm",disabled:s,onClick:()=>t(e.id,a),className:"h-6 gap-1 px-2 text-[10px] font-normal border-border/50 hover:bg-foreground/5",children:[(0,r.jsx)(sW,{classification:a}),sG(a)]},a))})]})]})})}function sJ({data:e,phase:t,error:s,resolvePending:a,resolveError:n,onRefresh:i,onResolve:o}){return"loading"===t?(0,r.jsx)(sB,{label:"Loading captures…"}):"error"===t&&s?(0,r.jsx)(sq,{message:s}):e&&0!==e.entries.length?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(sM,{title:"Captures",subtitle:`${e.entries.length} total`,status:(0,r.jsxs)("div",{className:"flex gap-1.5",children:[(0,r.jsx)(sU,{label:"Pending",value:e.pendingCount,variant:e.pendingCount>0?"warning":"default"}),(0,r.jsx)(sU,{label:"Actionable",value:e.actionableCount,variant:e.actionableCount>0?"info":"default"})]}),onRefresh:i,refreshing:"loading"===t}),n&&(0,r.jsxs)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2 text-[11px] text-destructive",children:["Resolve error: ",n]}),(0,r.jsx)("div",{className:"space-y-1.5",children:e.entries.map(e=>(0,r.jsx)(sY,{entry:e,onResolve:o,resolvePending:a},e.id))})]}):(0,r.jsx)(sO,{message:"No captures found"})}function sQ({initialTab:e}){let[t,s]=(0,i.useState)(e),a=(0,Z.gF)(),{loadKnowledgeData:n,loadCapturesData:o,resolveCaptureAction:l}=(0,Z._l)(),d=a.commandSurface.knowledgeCaptures,c=d.knowledge,u=d.captures,m=d.resolveRequest,h=u.data,x=h?.pendingCount??0;return(0,r.jsxs)("div",{className:"space-y-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-0.5 border-b border-border/50 px-1",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>s("knowledge"),className:(0,M.cn)("flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-[color,border-color,background-color] border-b-2 -mb-px","knowledge"===t?"border-foreground/60 text-foreground":"border-transparent text-muted-foreground hover:text-muted-foreground"),children:[(0,r.jsx)(sL.A,{className:"h-3.5 w-3.5"}),"Knowledge"]}),(0,r.jsxs)("button",{type:"button",onClick:()=>s("captures"),className:(0,M.cn)("flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-[color,border-color,background-color] border-b-2 -mb-px","captures"===t?"border-foreground/60 text-foreground":"border-transparent text-muted-foreground hover:text-muted-foreground"),children:[(0,r.jsx)(sD.A,{className:"h-3.5 w-3.5"}),"Captures",x>0&&(0,r.jsxs)(tN,{variant:"outline",className:"ml-1 h-4 px-1.5 py-0 text-[10px] border-warning/30 bg-warning/10 text-warning",children:[x," pending"]})]})]}),(0,r.jsx)("div",{className:"p-4",children:"knowledge"===t?(0,r.jsx)(sH,{data:c.data,phase:c.phase,error:c.error,onRefresh:()=>void n()}):(0,r.jsx)(sJ,{data:h,phase:u.phase,error:u.error,resolvePending:m.pending,resolveError:m.lastError,onRefresh:()=>void o(),onResolve:(e,t)=>{l({captureId:e,classification:t,resolution:"Manual browser triage",rationale:"Triaged via web UI"})}})})]})}var sZ=s(77059),sX=s(35361),s0=s(41363),s1=s(8891),s5=s(41655),s2=s(65496),s3=s(72202),s4=s(25847);function s8({title:e,icon:t,subtitle:s,onRefresh:a,refreshing:n}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 pb-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:t}),(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:e}),s&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:s})]}),(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:a,disabled:n,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",n&&"animate-spin")}),"Refresh"]})]})}function s6({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive",children:e})}function s7({label:e}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),e]})}function s9({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-4 py-5 text-center text-xs text-muted-foreground",children:e})}function re({label:e,value:t,variant:s}){return(0,r.jsxs)("div",{className:(0,M.cn)("flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs","info"===s&&"border-info/20 bg-info/5 text-info","warning"===s&&"border-warning/20 bg-warning/5 text-warning","success"===s&&"border-success/20 bg-success/5 text-success",(!s||"default"===s)&&"border-border/50 bg-card/50 text-foreground/80"),children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:e}),(0,r.jsx)("span",{className:"font-medium tabular-nums",children:t})]})}function rt({label:e,enabled:t}){return(0,r.jsxs)(tN,{variant:t?"secondary":"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0 font-mono",t?"border-success/30 text-success":"text-muted-foreground"),children:[e,": ",t?"on":"off"]})}function rs({label:e,skills:t}){return t?.length?(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:e}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:t.map(e=>(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:e},e))})]}):null}function rr({models:e}){return e&&0!==Object.keys(e).length?(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:"Phase Models"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,r.jsxs)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:[e,": ",t]},e))})]}):null}function ra({label:e,children:t}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-4 text-xs",children:[(0,r.jsx)("span",{className:"text-muted-foreground shrink-0",children:e}),(0,r.jsx)("span",{className:"text-foreground/80 text-right truncate",children:t})]})}function rn(){let e=(0,Z.gF)(),{loadSettingsData:t}=(0,Z._l)(),s=e.commandSurface.settingsData;return{state:s,data:s.data,busy:"loading"===s.phase,refresh:()=>void t()}}function ri(e){return"budget"===e||"burn-max"===e?"warning":"quality"===e?"success":"info"}function ro(){let{state:e,data:t,busy:s,refresh:a}=rn(),n=t?.preferences??null;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"settings-prefs",children:[(0,r.jsx)(s8,{title:"Effective Preferences",icon:(0,r.jsx)(A.A,{className:"h-3.5 w-3.5"}),subtitle:n?`${n.scope} scope`:null,onRefresh:a,refreshing:s}),e.error&&(0,r.jsx)(s6,{message:e.error}),s&&!t&&(0,r.jsx)(s7,{label:"Loading preferences…"}),t&&!n&&(0,r.jsx)(s9,{message:"No preferences file found"}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Mode",value:n.mode??"solo",variant:"info"}),(0,r.jsx)(re,{label:"Token Profile",value:n.tokenProfile??"balanced",variant:ri(n.tokenProfile)}),n.customInstructions?.length?(0,r.jsx)(re,{label:"Custom Instructions",value:n.customInstructions.length}):null]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(rr,{models:n.models}),(0,r.jsx)(rs,{label:"Always use",skills:n.alwaysUseSkills}),(0,r.jsx)(rs,{label:"Prefer",skills:n.preferSkills}),(0,r.jsx)(rs,{label:"Avoid",skills:n.avoidSkills}),n.models&&0!==Object.keys(n.models).length?!n.alwaysUseSkills?.length&&!n.preferSkills?.length&&!n.avoidSkills?.length&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:"No skill preferences configured"}):!n.alwaysUseSkills?.length&&!n.preferSkills?.length&&!n.avoidSkills?.length&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:"No model or skill preferences configured"})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1.5 rounded-lg border border-border/50 bg-card/50 px-3 py-2.5",children:[(0,r.jsx)(ra,{label:"Auto-Supervisor",children:n.autoSupervisor?.enabled?(0,r.jsxs)("span",{className:"text-success",children:["on",null!=n.autoSupervisor.softTimeoutMinutes&&` (${n.autoSupervisor.softTimeoutMinutes}m)`]}):(0,r.jsx)("span",{className:"text-muted-foreground",children:"off"})}),(0,r.jsx)(ra,{label:"UAT Dispatch",children:(0,r.jsx)("span",{className:n.uatDispatch?"text-success":"text-muted-foreground",children:n.uatDispatch?"on":"off"})}),(0,r.jsx)(ra,{label:"Auto-Visualize",children:(0,r.jsx)("span",{className:n.autoVisualize?"text-success":"text-muted-foreground",children:n.autoVisualize?"on":"off"})}),(0,r.jsx)(ra,{label:"Service Tier",children:(0,r.jsx)("span",{className:"font-mono text-[10px]",children:n.serviceTier??"default"})}),(0,r.jsx)(ra,{label:"Show Token Cost",children:(0,r.jsx)("span",{className:n.showTokenCost?"text-success":"text-muted-foreground",children:n.showTokenCost?"on":"off"})}),(0,r.jsx)(ra,{label:"Context Selection",children:(0,r.jsx)("span",{className:"font-mono text-[10px]",children:n.contextSelection??"full"})}),(0,r.jsx)(ra,{label:"Context Window",children:(0,r.jsx)("span",{className:"font-mono text-[10px]",children:"number"==typeof n.contextWindowOverride?n.contextWindowOverride:"auto"})}),(0,r.jsx)(ra,{label:"Language",children:(0,r.jsx)("span",{className:"font-mono text-[10px]",children:n.language??"default"})}),(0,r.jsx)(ra,{label:"Reactive Exec",children:(0,r.jsx)("span",{className:n.reactiveExecution?.enabled?"text-success":"text-muted-foreground",children:n.reactiveExecution?.enabled?"on":"off"})}),(0,r.jsx)(ra,{label:"Gate Eval",children:(0,r.jsx)("span",{className:n.gateEvaluation?.enabled?"text-success":"text-muted-foreground",children:n.gateEvaluation?.enabled?"on":"off"})}),(0,r.jsx)(ra,{label:"Slice Parallel",children:(0,r.jsx)("span",{className:n.sliceParallel?.enabled?"text-success":"text-muted-foreground",children:n.sliceParallel?.enabled?"on":"off"})}),(0,r.jsx)(ra,{label:"Phase Controls",children:(0,r.jsxs)("span",{className:"font-mono text-[10px]",children:[n.phases?Object.values(n.phases).filter(e=>!0===e).length:0," enabled"]})}),(0,r.jsx)(ra,{label:"Preference Scope",children:(0,r.jsx)("span",{className:"font-mono text-[10px]",children:n.scope})})]}),(0,r.jsxs)("div",{className:"text-[11px] text-muted-foreground truncate font-mono",children:["Source: ",n.path]}),n.warnings&&n.warnings.length>0&&(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-warning",children:[(0,r.jsx)(ez.A,{className:"h-3 w-3"}),(0,r.jsxs)("span",{className:"font-medium",children:["Warnings (",n.warnings.length,")"]})]}),n.warnings.map((e,t)=>(0,r.jsx)("div",{className:"rounded border border-warning/20 bg-warning/5 px-2.5 py-1.5 text-[11px] text-warning",children:e},t))]})]})]})}function rl({tier:e,modelId:t}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-4 text-xs",children:[(0,r.jsx)("span",{className:"text-muted-foreground capitalize",children:e}),(0,r.jsx)("span",{className:"font-mono text-[11px] text-foreground/80 truncate max-w-[200px]",children:t??(0,r.jsx)("span",{className:"text-muted-foreground italic",children:"default"})})]})}function rd({tier:e,success:t,fail:s}){return 0===t+s?null:(0,r.jsxs)(tN,{variant:"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0 font-mono",s>0?"border-destructive/20 text-destructive":"text-muted-foreground"),children:[e,": ",t,"✓",s>0&&(0,r.jsxs)("span",{children:[" ",s,"✗"]})]})}function rc(){let{state:e,data:t,busy:s,refresh:a}=rn(),n=t?.routingConfig??null,i=t?.routingHistory??null;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"settings-model-routing",children:[(0,r.jsx)(s8,{title:"Model Routing",icon:(0,r.jsx)(eU.A,{className:"h-3.5 w-3.5"}),onRefresh:a,refreshing:s}),e.error&&(0,r.jsx)(s6,{message:e.error}),s&&!t&&(0,r.jsx)(s7,{label:"Loading routing config…"}),t&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex items-center gap-2",children:(0,r.jsxs)(tN,{variant:n?.enabled?"secondary":"outline",className:(0,M.cn)("text-[10px] px-2 py-0.5",n?.enabled?"border-success/30 text-success":"text-muted-foreground"),children:["Dynamic Routing: ",n?.enabled?"enabled":"disabled"]})}),n?.tier_models&&(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Tier Assignments"}),(0,r.jsx)(rl,{tier:"light",modelId:n.tier_models.light}),(0,r.jsx)(rl,{tier:"standard",modelId:n.tier_models.standard}),(0,r.jsx)(rl,{tier:"heavy",modelId:n.tier_models.heavy})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[(0,r.jsx)(rt,{label:"escalate_on_failure",enabled:n?.escalate_on_failure}),(0,r.jsx)(rt,{label:"budget_pressure",enabled:n?.budget_pressure}),(0,r.jsx)(rt,{label:"cross_provider",enabled:n?.cross_provider}),(0,r.jsx)(rt,{label:"hooks",enabled:n?.hooks})]}),i?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Patterns",value:Object.keys(i.patterns).length}),(0,r.jsx)(re,{label:"Feedback",value:i.feedback.length})]}),Object.keys(i.patterns).length>0&&(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground",children:"Top Patterns"}),(0,r.jsx)("div",{className:"space-y-2",children:(function(e,t=5){return Object.entries(e.patterns).map(([e,t])=>({name:e,total:t.light.success+t.light.fail+t.standard.success+t.standard.fail+t.heavy.success+t.heavy.fail,pattern:t})).sort((e,t)=>t.total-e.total).slice(0,t)})(i).map(({name:e,total:t,pattern:s})=>(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-mono text-foreground/80 truncate",children:e}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground tabular-nums shrink-0",children:[t," attempts"]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-1",children:[(0,r.jsx)(rd,{tier:"L",success:s.light.success,fail:s.light.fail}),(0,r.jsx)(rd,{tier:"S",success:s.standard.success,fail:s.standard.fail}),(0,r.jsx)(rd,{tier:"H",success:s.heavy.success,fail:s.heavy.fail})]})]},e))})]})]}):(0,r.jsx)(s9,{message:"No routing history yet"})]})]})}function ru(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}K`:String(e)}function rm(){var e;let{state:t,data:s,busy:a,refresh:n}=rn(),i=s?.preferences??null,o=s?.budgetAllocation??null,l=s?.projectTotals??null;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"settings-budget",children:[(0,r.jsx)(s8,{title:"Budget & Costs",icon:(0,r.jsx)(ef.A,{className:"h-3.5 w-3.5"}),onRefresh:n,refreshing:a}),t.error&&(0,r.jsx)(s6,{message:t.error}),a&&!s&&(0,r.jsx)(s7,{label:"Loading budget data…"}),s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Ceiling",value:i?.budgetCeiling!=null?(0,Z.BD)(i.budgetCeiling):"Not set",variant:i?.budgetCeiling!=null?"warning":"default"}),(0,r.jsx)(re,{label:"Enforcement",value:i?.budgetEnforcement??"Not set",variant:i?.budgetEnforcement?"halt"===(e=i.budgetEnforcement)?"warning":"pause"===e?"info":"success":"default"}),(0,r.jsx)(re,{label:"Token Profile",value:i?.tokenProfile??"balanced",variant:ri(i?.tokenProfile)}),(0,r.jsx)(re,{label:"Service Tier",value:i?.serviceTier??"default"}),(0,r.jsx)(re,{label:"Token Cost",value:i?.showTokenCost?"shown":"hidden"})]}),o&&(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Context Budget Allocations"}),(0,r.jsxs)(ra,{label:"Summary Budget",children:[ru(o.summaryBudgetChars)," chars"]}),(0,r.jsxs)(ra,{label:"Inline Context",children:[ru(o.inlineContextBudgetChars)," chars"]}),(0,r.jsxs)(ra,{label:"Verification",children:[ru(o.verificationBudgetChars)," chars"]}),(0,r.jsxs)(ra,{label:"Task Count Range",children:[o.taskCountRange.min,"–",o.taskCountRange.max]}),(0,r.jsxs)(ra,{label:"Continue Threshold",children:[o.continueThresholdPercent,"%"]})]}),l?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Project Cost Totals"}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Units",value:l.units}),(0,r.jsx)(re,{label:"Total Cost",value:(0,Z.BD)(l.cost),variant:"warning"}),(0,r.jsx)(re,{label:"Duration",value:`${Math.round(l.duration/1e3)}s`})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Token Breakdown"}),(0,r.jsx)(ra,{label:"Input",children:(0,Z._y)(l.tokens.input)}),(0,r.jsx)(ra,{label:"Output",children:(0,Z._y)(l.tokens.output)}),(0,r.jsx)(ra,{label:"Cache Read",children:(0,Z._y)(l.tokens.cacheRead)}),(0,r.jsx)(ra,{label:"Cache Write",children:(0,Z._y)(l.tokens.cacheWrite)}),(0,r.jsx)(ra,{label:"Total",children:(0,Z._y)(l.tokens.total)})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Tool Calls",value:l.toolCalls}),(0,r.jsx)(re,{label:"Assistant Msgs",value:l.assistantMessages}),(0,r.jsx)(re,{label:"User Msgs",value:l.userMessages})]})]}):(0,r.jsx)(s9,{message:"No execution metrics yet"})]})]})}let rh=[{value:"slack",label:"Slack",description:"Get pinged in a Slack channel",idPlaceholder:"Channel ID (e.g. C01ABCD2EFG)"},{value:"discord",label:"Discord",description:"Get pinged in a Discord channel",idPlaceholder:"Channel ID (17–20 digit number)"},{value:"telegram",label:"Telegram",description:"Get pinged via Telegram bot",idPlaceholder:"Chat ID (numeric, may start with -)"}],rx={slack:/^[A-Z0-9]{9,12}$/,discord:/^\d{17,20}$/,telegram:/^-?\d{5,20}$/};function rp(){let{data:e,busy:t,refresh:s}=rn(),a=e?.preferences?.remoteQuestions??null,[n,o]=(0,i.useState)(null),[l,d]=(0,i.useState)(!0),[c,m]=(0,i.useState)(!1),[h,x]=(0,i.useState)("slack"),[p,g]=(0,i.useState)(""),[f,b]=(0,i.useState)(5),[v,j]=(0,i.useState)(5),[y,w]=(0,i.useState)(""),[N,S]=(0,i.useState)(!1),[k,C]=(0,i.useState)(!1),[A,R]=(0,i.useState)(null),[T,E]=(0,i.useState)(!1),[P,_]=(0,i.useState)(!1),[I,$]=(0,i.useState)(null),[L,D]=(0,i.useState)(null),[q,B]=(0,i.useState)(!1),[O,U]=(0,i.useState)(!1),z=(0,i.useCallback)(async()=>{try{d(!0);let e=await (0,eo.tm)("/api/remote-questions",{cache:"no-store"});if(!e.ok){let t=await e.json().catch(()=>({error:"Unknown error"}));$(t.error??`API error ${e.status}`);return}let t=await e.json();o(t.envVarName),m(t.tokenSet),B("configured"===t.status&&null!==t.config),t.config&&(x(t.config.channel),g(t.config.channelId),b(t.config.timeoutMinutes),j(t.config.pollIntervalSeconds))}catch(e){$(e instanceof Error?e.message:"Failed to fetch remote questions status")}finally{d(!1)}},[]);(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{z()},0);return()=>window.clearTimeout(e)},[z]),(0,i.useEffect)(()=>{if(!a?.channel)return;let e=a.channel,t=window.setTimeout(()=>{x(e),g(a.channelId??""),b(a.timeoutMinutes??5),j(a.pollIntervalSeconds??5)},0);return()=>window.clearTimeout(t)},[a]);let G=p.trim().length>0&&rx[h].test(p.trim())&&!T&&!P;(0,i.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>D(null),3e3);return()=>clearTimeout(e)},[L]);let W=async()=>{E(!0),$(null),D(null);try{let e=await (0,eo.tm)("/api/remote-questions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:h,channelId:p.trim(),timeoutMinutes:f,pollIntervalSeconds:v})}),t=await e.json();if(!e.ok)return void $(t.error??`Save failed (${e.status})`);D("Configuration saved"),B(!0),s(),z()}catch(e){$(e instanceof Error?e.message:"Failed to save configuration")}finally{E(!1)}},K=async()=>{_(!0),$(null),D(null);try{let e=await (0,eo.tm)("/api/remote-questions",{method:"DELETE"}),t=await e.json();if(!e.ok)return void $(t.error??`Disconnect failed (${e.status})`);D("Channel disconnected"),B(!1),g(""),b(5),j(5),x("slack"),m(!1),s(),z()}catch(e){$(e instanceof Error?e.message:"Failed to disconnect channel")}finally{_(!1)}},V=async()=>{if(y.trim()){C(!0),$(null),R(null);try{let e=await (0,eo.tm)("/api/remote-questions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:h,token:y.trim()})}),t=await e.json();if(!e.ok)return void $(t.error??`Token save failed (${e.status})`);R(`Token saved (${t.masked})`),m(!0),w(""),S(!1),z()}catch(e){$(e instanceof Error?e.message:"Failed to save token")}finally{C(!1)}}};(0,i.useEffect)(()=>{if(!A)return;let e=setTimeout(()=>R(null),3e3);return()=>clearTimeout(e)},[A]);let H=n??`${h.toUpperCase()}_BOT_TOKEN`,Y=rh.find(e=>e.value===h);return(t||l)&&!e&&!q?(0,r.jsxs)("div",{className:"space-y-5","data-testid":"settings-remote-questions",children:[(0,r.jsx)(s8,{title:"Integrations",icon:(0,r.jsx)(so.A,{className:"h-3.5 w-3.5"}),subtitle:"Remote notifications",onRefresh:()=>{s(),z()},refreshing:!0}),(0,r.jsx)(s7,{label:"Loading integration status…"})]}):(0,r.jsxs)("div",{className:"space-y-5","data-testid":"settings-remote-questions",children:[(0,r.jsx)(s8,{title:"Integrations",icon:(0,r.jsx)(so.A,{className:"h-3.5 w-3.5"}),subtitle:"Remote notifications",onRefresh:()=>{s(),z()},refreshing:t||l}),(0,r.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Connect a chat channel so the agent pings you when it needs input instead of waiting silently."}),I&&(0,r.jsx)(s6,{message:I}),L&&(0,r.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl border border-success/15 bg-success/[0.04] px-4 py-3 text-sm text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-4 w-4 shrink-0 text-success"}),L]}),q&&(0,r.jsxs)("div",{className:"rounded-xl border border-success/15 bg-success/[0.04] px-4 py-4",children:[(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg border border-success/20 bg-success/10",children:(0,r.jsx)(u.A,{className:"h-4.5 w-4.5 text-success"})}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"text-sm font-medium text-foreground",children:["Connected to ",Y.label]}),(0,r.jsx)("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:p})]})]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void K(),disabled:P,className:"h-7 text-xs text-destructive/70 hover:text-destructive",children:P?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):"Disconnect"})]}),(0,r.jsxs)("div",{className:"mt-3 flex gap-4 border-t border-success/10 pt-3 text-[11px] text-muted-foreground",children:[(0,r.jsxs)("span",{children:["Timeout: ",f,"m"]}),(0,r.jsxs)("span",{children:["Poll: ",v,"s"]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:q?"Switch channel":"Choose a channel"}),(0,r.jsx)("div",{className:"grid grid-cols-3 gap-2",children:rh.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>{x(e.value),$(null)},disabled:T,className:(0,M.cn)("rounded-xl border px-3 py-3 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",h===e.value?"border-foreground/30 bg-foreground/[0.06]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50"),children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.label}),(0,r.jsx)("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:e.description})]},e.value))})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Channel ID"}),(0,r.jsx)("input",{type:"text",value:p,onChange:e=>{g(e.target.value),I&&$(null)},placeholder:Y.idPlaceholder,disabled:T,className:(0,M.cn)("w-full rounded-xl border bg-card/50 px-4 py-2.5 font-mono text-sm text-foreground","placeholder:text-muted-foreground","focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent","transition-colors",p.trim().length>0&&!rx[h].test(p.trim())?"border-destructive/40":"border-border/50"),onKeyDown:e=>{"Enter"===e.key&&G&&W()}}),p.trim().length>0&&!rx[h].test(p.trim())&&(0,r.jsxs)("p",{className:"text-[11px] text-destructive/70",children:["Does not match the expected format for ",Y.label]})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>U(e=>!e),className:"flex items-center gap-1.5 text-[11px] text-muted-foreground hover:text-muted-foreground transition-colors",children:[(0,r.jsx)("svg",{className:(0,M.cn)("h-3 w-3 transition-transform",O&&"rotate-90"),viewBox:"0 0 16 16",fill:"currentColor",children:(0,r.jsx)("path",{d:"M6 4l4 4-4 4"})}),"Advanced settings"]}),O&&(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3 pl-4",children:[(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-[11px] text-muted-foreground",htmlFor:"rq-timeout",children:"Timeout (min)"}),(0,r.jsx)("input",{id:"rq-timeout",type:"number",min:1,max:30,value:f,onChange:e=>b(Math.max(1,Math.min(30,Number(e.target.value)||1))),className:"w-full rounded-lg border border-border/50 bg-card/50 px-3 py-2 text-xs text-foreground tabular-nums focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("label",{className:"text-[11px] text-muted-foreground",htmlFor:"rq-poll",children:"Poll interval (sec)"}),(0,r.jsx)("input",{id:"rq-poll",type:"number",min:2,max:30,value:v,onChange:e=>j(Math.max(2,Math.min(30,Number(e.target.value)||2))),className:"w-full rounded-lg border border-border/50 bg-card/50 px-3 py-2 text-xs text-foreground tabular-nums focus:outline-none focus:ring-2 focus:ring-ring"})]})]}),p.trim().length>0&&(0,r.jsxs)(J,{type:"button",onClick:()=>void W(),disabled:!G,className:"gap-2 transition-transform active:scale-[0.96]",children:[T?(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(u.A,{className:"h-4 w-4"}),q?"Update connection":"Save & connect"]}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Bot token"}),A&&(0,r.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl border border-success/15 bg-success/[0.04] px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 shrink-0 text-success"}),A]}),c&&!A&&(0,r.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl border border-success/15 bg-success/[0.04] px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 shrink-0 text-success"}),(0,r.jsx)("span",{className:"font-mono text-[11px]",children:H})," is configured"]}),!c&&(0,r.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl border border-warning/15 bg-warning/[0.04] px-4 py-2.5 text-xs text-muted-foreground",children:[(0,r.jsx)(ez.A,{className:"h-3.5 w-3.5 shrink-0 text-warning"}),(0,r.jsxs)("span",{children:[(0,r.jsx)("span",{className:"font-mono text-[11px]",children:H})," not configured"]})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)("input",{type:N?"text":"password",value:y,onChange:e=>w(e.target.value),placeholder:`Paste your ${Y.label} bot token`,disabled:k,className:(0,M.cn)("w-full rounded-xl border border-border/50 bg-card/50 pl-4 pr-10 py-2.5 font-mono text-sm text-foreground","placeholder:text-muted-foreground","focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent","transition-colors"),onKeyDown:e=>{"Enter"===e.key&&y.trim()&&V()}}),(0,r.jsx)("button",{type:"button",onClick:()=>S(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-muted-foreground transition-colors",children:N?(0,r.jsx)(tK.A,{className:"h-3.5 w-3.5"}):(0,r.jsx)(tV.A,{className:"h-3.5 w-3.5"})})]}),(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>void V(),disabled:!y.trim()||k,className:"h-[42px] gap-1.5 px-4",children:[k?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(tA.A,{className:"h-3.5 w-3.5"}),"Save"]})]})]})]})}function rg(e){return e?Object.entries(e).map(([e,t])=>`${e}=${t}`).join("\n"):""}function rf(e){let t=e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf("=");if(t<=0)throw Error(`Invalid key=value line: ${e}`);return[e.slice(0,t).trim(),e.slice(t+1)]});return t.length>0?Object.fromEntries(t):void 0}function rb(){let[e,t]=(0,i.useState)(null),[s,a]=(0,i.useState)(!0),[n,o]=(0,i.useState)(!1),[l,d]=(0,i.useState)(null),[c,m]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[f,b]=(0,i.useState)(null),[v,j]=(0,i.useState)(""),[y,w]=(0,i.useState)("stdio"),[N,S]=(0,i.useState)(""),[k,C]=(0,i.useState)(""),[A,R]=(0,i.useState)(""),[T,E]=(0,i.useState)(""),[P,_]=(0,i.useState)(""),[I,$]=(0,i.useState)(""),L=(0,i.useCallback)(async()=>{a(!0),m(null);try{let e=await (0,eo.tm)("/api/mcp-connections",{cache:"no-store"}),s=await e.json();if(!e.ok)throw Error(s.error??`MCP request failed (${e.status})`);t(s)}catch(e){m(e instanceof Error?e.message:String(e))}finally{a(!1)}},[]);function D(){b(null),j(""),w("stdio"),S(""),C(""),R(""),E(""),_(""),$("")}async function q(e){let s=await (0,eo.tm)("/api/mcp-connections",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await s.json();if("error"===r.status)throw Error(r.error);if(!s.ok)throw Error(`MCP request failed (${s.status})`);return t(r.data),r}async function B(){o(!0),m(null),x(null);try{let e,t="stdio"===y?{name:v.trim(),transport:y,command:N.trim(),args:(e=k.split(/\r?\n/).map(e=>e.trim()).filter(Boolean)).length>0?e:void 0,env:rf(P),cwd:A.trim()||void 0}:{name:v.trim(),transport:y,url:T.trim(),headers:rf(I)};await q({action:"save",previousName:f??void 0,server:t}),x(f?"MCP server updated":"MCP server saved"),D()}catch(e){m(e instanceof Error?e.message:String(e))}finally{o(!1)}}async function O(e){m(null);try{await q({action:e.disabled?"enable":"disable",name:e.name}),x(e.disabled?"MCP server enabled":"MCP server disabled")}catch(e){m(e instanceof Error?e.message:String(e))}}async function U(e){if(window.confirm(`Delete local MCP server "${e.name}"?`)){m(null);try{await q({action:"delete",name:e.name}),x("MCP server deleted"),f===e.name&&D()}catch(e){m(e instanceof Error?e.message:String(e))}}}async function z(e){d(e.name),m(null),g(null);try{let t=await q({action:"test",name:e.name});g(t.result??null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{d(null)}}async function G(e){let t=e.conflicts?window.prompt(`Rename imported MCP server "${e.name}"`,`${e.name}-local`):e.name;if(t){m(null);try{await q({action:"import",server:e,name:t}),x("MCP server imported")}catch(e){m(e instanceof Error?e.message:String(e))}}}(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{L()},0);return()=>window.clearTimeout(e)},[L]),(0,i.useEffect)(()=>{if(!h)return;let e=setTimeout(()=>x(null),3e3);return()=>clearTimeout(e)},[h]);let W=v.trim().length>0&&("stdio"===y?N.trim().length>0:T.trim().length>0);return(0,r.jsxs)("div",{className:"space-y-5","data-testid":"settings-mcp-connections",children:[(0,r.jsx)(s8,{title:"MCP Connections",icon:(0,r.jsx)(sZ.A,{className:"h-3.5 w-3.5"}),subtitle:e?`${e.servers.length} configured`:null,onRefresh:()=>void L(),refreshing:s}),c&&(0,r.jsx)(s6,{message:c}),h&&(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded-lg border border-success/15 bg-success/[0.04] px-3 py-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 text-success"}),h]}),s&&!e&&(0,r.jsx)(s7,{label:"Loading MCP connections…"}),e&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(re,{label:"Local config",value:e.localConfigPath}),(0,r.jsx)(re,{label:"Importable",value:e.importableServers.length,variant:"info"}),e.duplicates.length>0&&(0,r.jsx)(re,{label:"Duplicates",value:e.duplicates.length,variant:"warning"})]}),e.warnings.length>0&&(0,r.jsx)("div",{className:"space-y-1 rounded-lg border border-warning/20 bg-warning/5 px-3 py-2 text-[11px] text-warning",children:e.warnings.map(e=>(0,r.jsx)("div",{children:e},e))}),(0,r.jsxs)("div",{className:"grid gap-2",children:[0===e.servers.length&&(0,r.jsx)(s9,{message:"No MCP servers configured"}),e.servers.map(e=>(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-3",children:(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(sX.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"font-mono text-xs text-foreground",children:e.name}),(0,r.jsx)(re,{label:e.transport,value:e.disabled?"disabled":"enabled",variant:e.disabled||"unsupported"===e.transport?"warning":e.connected||e.toolCount>0?"success":"info"})]}),(0,r.jsx)("div",{className:"truncate font-mono text-[10px] text-muted-foreground",children:e.sourcePath}),e.envWarnings.length>0&&(0,r.jsx)("div",{className:"text-[11px] text-warning",children:e.envWarnings[0]})]}),(0,r.jsxs)("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[(0,r.jsxs)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:()=>void z(e),disabled:l===e.name||e.disabled||"unsupported"===e.transport,children:[l===e.name?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(sl.A,{className:"h-3.5 w-3.5"}),"Test"]}),(0,r.jsxs)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:()=>void O(e),children:[e.disabled?(0,r.jsx)(s0.A,{className:"h-3.5 w-3.5"}):(0,r.jsx)(s1.A,{className:"h-3.5 w-3.5"}),e.disabled?"Enable":"Disable"]}),(0,r.jsx)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:()=>(function(e){if("unsupported"!==e.transport){var t;b(e.name),j(e.name),w(e.transport),S(e.command??""),C((t=e.args,t?.join("\n")??"")),R(e.cwd??""),E(e.url??""),_(rg(e.env)),$(rg(e.headers))}})(e),disabled:"unsupported"===e.transport,children:"Edit"}),(0,r.jsx)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-destructive/80",onClick:()=>void U(e),disabled:"project-local"!==e.sourceKind,children:(0,r.jsx)(s5.A,{className:"h-3.5 w-3.5"})})]})]})},`${e.sourcePath}:${e.name}`))]}),p&&(0,r.jsx)("div",{className:(0,M.cn)("rounded-lg border px-3 py-2 text-xs",p.ok?"border-success/20 bg-success/5 text-success":"border-warning/20 bg-warning/5 text-warning"),children:p.ok?`${p.server} responded with ${p.toolCount} tools`:`${p.server} failed: ${p.error??"unknown error"}`}),(0,r.jsxs)("div",{className:"space-y-3 rounded-lg border border-border/50 bg-card/50 px-3 py-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:f?"Edit local server":"Add local server"}),f&&(0,r.jsx)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:D,children:"Cancel"})]}),(0,r.jsxs)("div",{className:"grid gap-2 md:grid-cols-2",children:[(0,r.jsx)("input",{value:v,onChange:e=>j(e.target.value),placeholder:"server-name",className:"rounded-lg border border-border/50 bg-background px-3 py-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"rounded-lg border border-border/50 bg-background px-3 py-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("option",{value:"stdio",children:"stdio"}),(0,r.jsx)("option",{value:"http",children:"http"})]}),"stdio"===y?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:N,onChange:e=>S(e.target.value),placeholder:"/absolute/path/to/server",className:"rounded-lg border border-border/50 bg-background px-3 py-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("input",{value:A,onChange:e=>R(e.target.value),placeholder:"cwd (optional)",className:"rounded-lg border border-border/50 bg-background px-3 py-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("textarea",{value:k,onChange:e=>C(e.target.value),placeholder:"args, one per line",rows:3,className:"rounded-lg border border-border/50 bg-background px-3 py-2 font-mono text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("textarea",{value:P,onChange:e=>_(e.target.value),placeholder:"ENV_KEY=value",rows:3,className:"rounded-lg border border-border/50 bg-background px-3 py-2 font-mono text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("input",{value:T,onChange:e=>E(e.target.value),placeholder:"https://server.example/mcp",className:"md:col-span-2 rounded-lg border border-border/50 bg-background px-3 py-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("textarea",{value:I,onChange:e=>$(e.target.value),placeholder:"Authorization=Bearer ${TOKEN}",rows:3,className:"md:col-span-2 rounded-lg border border-border/50 bg-background px-3 py-2 font-mono text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]})]}),(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>void B(),disabled:!W||n,className:"gap-1.5",children:[n?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(t1.A,{className:"h-3.5 w-3.5"}),f?"Update server":"Save server"]})]}),e.importableServers.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Discovered imports"}),(0,r.jsx)("div",{className:"grid gap-2",children:e.importableServers.slice(0,6).map(e=>(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-border/50 bg-card/50 px-3 py-2",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsx)("div",{className:"font-mono text-xs text-foreground",children:e.name}),(0,r.jsxs)("div",{className:"truncate text-[10px] text-muted-foreground",children:[e.sourceTool," \xb7 ",e.sourcePath]})]}),(0,r.jsx)(J,{type:"button",size:"sm",variant:"ghost",className:"h-7 text-xs",disabled:"unsupported"===e.transport,onClick:()=>void G(e),children:"Import"})]},`${e.sourcePath}:${e.name}`))})]})]})]})}let rv=[11,12,13,14,15,16],rj=[11,12,13,14,15,16];function ry({label:e,description:t,presets:s,defaultSize:a,currentSize:n,onChange:i,previewFont:o}){return(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-3 space-y-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-medium text-foreground",children:e}),(0,r.jsx)("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:t})]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:s.map(e=>(0,r.jsxs)("button",{type:"button",onClick:()=>i(e),className:(0,M.cn)("rounded-md border px-3 py-1.5 text-xs font-medium tabular-nums transition-colors",n===e?"border-foreground/30 bg-foreground/10 text-foreground shadow-sm":"border-border/50 bg-card/50 text-muted-foreground hover:border-foreground/20 hover:text-foreground"),children:[e,"px",e===a&&(0,r.jsx)("span",{className:"ml-1 text-[10px] text-muted-foreground",children:"(default)"})]},e))}),(0,r.jsx)("div",{className:(0,M.cn)("mt-2 rounded-md border border-border/50 bg-terminal px-3 py-2 text-foreground/80","mono"===o?"font-mono":"font-sans"),style:{fontSize:`${n}px`,lineHeight:1.35},children:"The quick brown fox jumps over the lazy dog"})]})}let rw={llm:"LLM provider & auth",model:"Default model",search:"Web search provider",remote:"Remote questions","tool-keys":"Tool API keys",prefs:"Global preferences",skills:"Skills install",doctor:"Validate setup",project:"Project init"},rN=["llm","model","search","remote","tool-keys","prefs","skills","doctor","project"];function rS(){let e=(0,Z.gF)(),t=tx(),s=e.boot?.onboarding,a=s?.completionRecord??null;if(void 0===a)return null;let n=new Set(a?.completedSteps??[]),i=new Set(a?.skippedSteps??[]),o=a?.completedAt??null,l=a?.lastResumePoint??null,d=t.isDevMode;return(0,r.jsxs)("div",{className:"space-y-3 rounded-md border border-border/50 bg-muted/20 p-4","data-testid":"settings-onboarding-status",children:[(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[(0,r.jsx)(s2.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("span",{children:"Onboarding setup"}),o?(0,r.jsx)(tN,{variant:"outline",className:"h-5 border-success/40 bg-success/10 text-[10px] text-success",children:"Complete"}):(0,r.jsx)(tN,{variant:"outline",className:"h-5 border-warning/40 bg-warning/10 text-[10px] text-warning",children:"Incomplete"})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:o?`Last completed ${function(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return e}}(o)}.`:l?`Paused at "${rw[l]??l}". Re-run /gsd onboarding --resume to continue.`:"You haven't completed the onboarding wizard yet."})]}),(0,r.jsxs)("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[(0,r.jsxs)(J,{size:"sm",variant:"outline",onClick:()=>{d&&t.toggle("forceOnboarding")},disabled:!d,"data-testid":"settings-onboarding-rerun",children:[(0,r.jsx)(t_.A,{className:"mr-1.5 h-3 w-3"}),"Re-run setup"]}),!d&&(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["Run ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 font-mono",children:"/gsd onboarding"})," in your terminal"]})]})]}),(0,r.jsx)("ul",{className:"grid grid-cols-1 gap-1 sm:grid-cols-2",children:rN.map(e=>{let t=n.has(e),s=i.has(e),a=t?u.A:s?h.A:tG.A;return(0,r.jsxs)("li",{className:"flex items-center gap-2 text-[11px]","data-testid":`settings-onboarding-step-${e}`,children:[(0,r.jsx)(a,{className:(0,M.cn)("h-3 w-3 shrink-0",t?"text-success":s?"text-muted-foreground/70":"text-muted-foreground/50")}),(0,r.jsx)("span",{className:(0,M.cn)("truncate",t?"text-foreground":"text-muted-foreground"),children:rw[e]??e})]},e)})})]})}function rk(){let[e,t]=(0,s3.A)(),[s,a]=(0,s4.d)();return(0,r.jsxs)("div",{className:"space-y-5","data-testid":"settings-general",children:[(0,r.jsx)(s8,{title:"General",icon:(0,r.jsx)(se.A,{className:"h-3.5 w-3.5"}),subtitle:"Appearance & behavior",onRefresh:()=>{},refreshing:!1}),(0,r.jsx)(rS,{}),(0,r.jsx)(ry,{label:"Terminal font size",description:"Applies to all terminals and the chat mode interface",presets:rv,defaultSize:13,currentSize:e,onChange:t,previewFont:"mono"}),(0,r.jsx)(ry,{label:"Code font size",description:"Applies to the file viewer and code editor",presets:rj,defaultSize:14,currentSize:s,onChange:a,previewFont:"mono"})]})}let rC=[{key:"rtk",label:"RTK Shell Compression",description:"Wraps shell commands through the RTK binary to reduce token usage during command execution. RTK is downloaded automatically on first use.",warning:"Experimental — may change or be removed without notice."}];function rA(){let{state:e,data:t,busy:s,refresh:a}=rn(),n=t?.preferences??null,[o,l]=(0,i.useState)({}),[d,c]=(0,i.useState)({}),[u,m]=(0,i.useState)(null);async function h(e,t){c(t=>({...t,[e]:!0})),m(null);try{let s=await (0,eo.tm)("/api/experimental",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({flag:e,enabled:t})});if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error??`HTTP ${s.status}`)}l(s=>({...s,[e]:t})),a()}catch(e){m(e instanceof Error?e.message:String(e))}finally{c(t=>({...t,[e]:!1}))}}return(0,i.useEffect)(()=>{t||s||"idle"!==e.phase||a()},[]),(0,i.useEffect)(()=>{if(!n)return;let e=window.setTimeout(()=>{l({rtk:n.experimental?.rtk===!0})},0);return()=>window.clearTimeout(e)},[n]),(0,r.jsxs)("div",{className:"space-y-4","data-testid":"settings-experimental",children:[(0,r.jsx)(s8,{title:"Experimental",icon:(0,r.jsx)(sl.A,{className:"h-3.5 w-3.5"}),subtitle:"Opt-in features — may change without notice",onRefresh:a,refreshing:s}),e.error&&(0,r.jsx)(s6,{message:e.error}),u&&(0,r.jsx)(s6,{message:u}),s&&!t&&(0,r.jsx)(s7,{label:"Loading preferences…"}),(0,r.jsx)("div",{className:"space-y-3",children:rC.map(e=>{let a=o[e.key]??!1,n=d[e.key]??!1;return(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-3 space-y-2",children:(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:e.label}),(0,r.jsx)("span",{className:(0,M.cn)("rounded-full px-1.5 py-0.5 text-[10px] font-medium",a?"bg-success/10 text-success":"bg-muted text-muted-foreground"),children:a?"on":"off"})]}),(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:e.description}),e.warning&&(0,r.jsxs)("div",{className:"flex items-center gap-1 text-[10px] text-warning",children:[(0,r.jsx)(ez.A,{className:"h-3 w-3 shrink-0"}),(0,r.jsx)("span",{children:e.warning})]})]}),(0,r.jsxs)("button",{onClick:()=>h(e.key,!a),disabled:n||s||!t,className:(0,M.cn)("shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",a?"bg-success":"bg-muted-foreground/30"),role:"switch","aria-checked":a,"aria-label":`Toggle ${e.label}`,children:[(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-3.5 w-3.5 rounded-full bg-white shadow-sm transition-transform",a?"translate-x-4":"translate-x-0.5")}),n&&(0,r.jsx)("span",{className:"absolute inset-0 flex items-center justify-center",children:(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin text-white"})})]})]})},e.key)})}),t&&(0,r.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:["Changes are written to"," ",(0,r.jsx)("span",{className:"font-mono",children:n?.path??"~/.gsd/PREFERENCES.md"})," ","and take effect on the next session."]})]})}var rR=s(92525),rT=s(16521);function rE({className:e,...t}){return(0,r.jsx)(rT.b,{"data-slot":"label",className:(0,M.cn)("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",e),...t})}let rP={"active-gsd":{label:"Active",color:"text-success",bgClass:"bg-success/10",icon:t0.A},"empty-gsd":{label:"Initialized",color:"text-info",bgClass:"bg-info/10",icon:eE.A},brownfield:{label:"Existing",color:"text-warning",bgClass:"bg-warning/10",icon:C.A},"v1-legacy":{label:"Legacy",color:"text-warning",bgClass:"bg-warning/10",icon:eP.A},blank:{label:"New",color:"text-muted-foreground",bgClass:"bg-foreground/[0.04]",icon:e_.A}};function r_(e){let t=[];return e.isMonorepo&&t.push("Monorepo"),e.hasGitRepo&&t.push("Git"),e.hasPackageJson&&t.push("Node.js"),e.hasCargo&&t.push("Rust"),e.hasGoMod&&t.push("Go"),e.hasPyproject&&t.push("Python"),t}function rI(e){if(0===e.milestonesTotal)return null;let t=[];return e.activeMilestone&&t.push(e.activeMilestone),e.activeSlice&&t.push(e.activeSlice),e.phase&&t.push(e.phase),t.join(" \xb7 ")||null}function rF({project:e,isActive:t=!1,onClick:s,disabled:a=!1}){let n=rP[e.kind],i=n.icon,o=r_(e.signals),l=e.progress?rI(e.progress):null,d=e.progress?`${e.progress.milestonesCompleted}/${e.progress.milestonesTotal}`:null;return(0,r.jsxs)("button",{type:"button",onClick:s,disabled:a,className:(0,M.cn)("group flex w-full items-start gap-3.5 rounded-xl border px-4 py-3.5 text-left transition-[background-color,border-color,box-shadow,transform] duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","active:scale-[0.96]",t?"border-primary/30 bg-primary/[0.08]":"border-border/50 bg-card/50 hover:border-foreground/15 hover:bg-card/50",a&&"opacity-40 pointer-events-none"),children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-9 w-9 shrink-0 items-center justify-center rounded-lg mt-0.5",t?"bg-primary/15":n.bgClass),children:t?(0,r.jsx)(u.A,{className:"h-4 w-4 text-primary"}):(0,r.jsx)(i,{className:(0,M.cn)("h-4 w-4",n.color)})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground truncate",children:e.name}),(0,r.jsx)("span",{className:(0,M.cn)("text-[10px] font-medium shrink-0",t?"text-primary":n.color),children:t?"Current":n.label})]}),o.length>0&&(0,r.jsx)("div",{className:"mt-1 flex items-center gap-1.5",children:o.map(e=>(0,r.jsx)("span",{className:"rounded bg-foreground/[0.06] px-1.5 py-0.5 text-[10px] text-muted-foreground",children:e},e))}),l&&(0,r.jsx)("div",{className:"mt-1.5 text-[11px] text-muted-foreground",children:l}),e.progress&&e.progress.milestonesTotal>0&&(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,r.jsx)("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-foreground/[0.08]",children:(0,r.jsx)("div",{className:"h-full rounded-full bg-success/70 transition-[width]",style:{width:`${Math.round(e.progress.milestonesCompleted/e.progress.milestonesTotal*100)}%`}})}),(0,r.jsx)("span",{className:"text-[10px] tabular-nums text-muted-foreground",children:d})]})]}),(0,r.jsx)(e$.A,{className:"mt-1 h-4 w-4 shrink-0 text-muted-foreground/50 transition-[color,transform] group-hover:text-muted-foreground group-hover:translate-x-0.5"})]})}function r$({open:e,onOpenChange:t}){let s,a=en(),n=(0,i.useSyncExternalStore)(a.subscribe,a.getSnapshot,a.getSnapshot),[l,d]=(0,i.useState)([]),[c,u]=(0,i.useState)(null),[m,h]=(0,i.useState)(!0),[x,p]=(0,i.useState)(null),g=(0,i.useCallback)(async e=>{let t=await (0,eo.tm)(`/api/projects?root=${encodeURIComponent(e)}&detail=true`);if(!t.ok)throw Error(`Failed to discover projects: ${t.status}`);return await t.json()},[]);(0,i.useEffect)(()=>{if(!e)return;let t=!1;return async function(){h(!0),p(null);try{let e=await (0,eo.tm)("/api/preferences");if(!e.ok)throw Error(`Failed to load preferences: ${e.status}`);let s=await e.json();if(!s.devRoot){u(null),d([]),h(!1);return}u(s.devRoot);let r=await g(s.devRoot);t||d(r)}catch(e){t||p(e instanceof Error?e.message:"Unknown error")}finally{t||h(!1)}}(),()=>{t=!0}},[e,g]);let f=(0,i.useCallback)(async e=>{h(!0),p(null);try{let t=await (0,eo.tm)("/api/switch-root",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Request failed (${t.status})`)}let s=await t.json();u(s.devRoot),d(s.projects)}catch(e){p(e instanceof Error?e.message:"Failed to switch project root")}finally{h(!1)}},[]),[b,v]=(0,i.useState)(!1),[j,y]=(0,i.useState)(!1);(0,Z.gF)();let w=(0,i.useCallback)(e=>{d(t=>[...t,e].sort((e,t)=>e.name.localeCompare(t.name))),v(!1),N(e)},[]);function N(e){n===e.path?t(!1):(t(!1),a.switchProject(e.path))}let S=[...l].sort((e,t)=>{let s={"active-gsd":0,"empty-gsd":1,brownfield:2,"v1-legacy":3,blank:4},r=s[e.kind]??5,a=s[t.kind]??5;return r!==a?r-a:e.name.localeCompare(t.name)});return s=m?(0,r.jsxs)("div",{className:"flex items-center justify-center gap-2 py-16 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}),"Discovering projects…"]}):x?(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 px-5 py-16 text-center",children:[(0,r.jsx)(rR.A,{className:"h-8 w-8 text-destructive"}),(0,r.jsx)("p",{className:"text-sm text-destructive",children:x})]}):c?0===S.length?(0,r.jsxs)("div",{className:"flex flex-col items-center gap-4 px-5 py-16 text-center",children:[(0,r.jsx)("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl bg-muted",children:(0,r.jsx)(eE.A,{className:"h-7 w-7 text-muted-foreground"})}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h3",{className:"text-base font-semibold text-foreground",children:"No projects found"}),(0,r.jsxs)("p",{className:"text-sm text-muted-foreground leading-relaxed",children:["No project directories discovered in"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs font-mono text-foreground",children:c})]})]})]}):(0,r.jsxs)("div",{className:"space-y-2",children:[S.map(e=>(0,r.jsx)(rF,{project:e,isActive:n===e.path,onClick:()=>N(e)},e.path)),(0,r.jsxs)("button",{type:"button",onClick:()=>v(!0),className:(0,M.cn)("flex w-full items-center gap-3.5 rounded-xl border border-dashed px-4 py-3.5 text-left transition-[background-color,border-color,color,transform] duration-200","border-border/50 text-muted-foreground hover:border-foreground/15 hover:text-foreground","active:scale-[0.96]"),children:[(0,r.jsx)("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-foreground/[0.04]",children:(0,r.jsx)(t1.A,{className:"h-4 w-4"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Create new project"}),(0,r.jsx)("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Initialize a new directory with Git"})]})]}),(0,r.jsx)(rL,{open:b,onOpenChange:v,devRoot:c,existingNames:l.map(e=>e.name),onCreated:w})]}):(0,r.jsx)(rM,{onSaved:f}),(0,r.jsx)(e5,{open:e,onOpenChange:t,children:(0,r.jsxs)(e4,{side:"left",className:"flex h-full w-full flex-col p-0 sm:max-w-[420px]","data-testid":"projects-panel",children:[(0,r.jsxs)(e8,{className:"sr-only",children:[(0,r.jsx)(e7,{children:"Projects"}),(0,r.jsx)(e9,{children:"Switch between projects or create a new one"})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between border-b border-border/50 px-5 py-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-base font-semibold text-foreground",children:"Projects"}),c&&!m&&(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-[10px] truncate max-w-[200px]",children:c}),(0,r.jsx)("button",{type:"button",onClick:()=>y(!0),className:"shrink-0 text-[10px] text-primary hover:text-primary/80 transition-colors font-medium","data-testid":"projects-panel-change-root",children:"Change"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"\xb7"}),(0,r.jsxs)("span",{children:[l.length," project",1!==l.length?"s":""]})]})]}),(0,r.jsx)(J,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>t(!1),children:(0,r.jsx)(o.A,{className:"h-4 w-4"})})]}),(0,r.jsx)(tq,{className:"min-h-0 flex-1",children:(0,r.jsx)("div",{className:"px-5 py-4",children:s})}),(0,r.jsx)(rD,{open:j,onOpenChange:y,onSelect:e=>void f(e),initialPath:c})]})})}function rL({open:e,onOpenChange:t,devRoot:s,existingNames:a,onCreated:n}){let[o,l]=(0,i.useState)(""),[d,c]=(0,i.useState)(!1),[u,m]=(0,i.useState)(null),h=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(e){l(""),m(null),c(!1);let e=setTimeout(()=>h.current?.focus(),100);return()=>clearTimeout(e)}},[e]);let x=/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(o),p=a.includes(o),g=o.length>0&&x&&!p&&!d,f=o?p?"A project with this name already exists":x?null:"Use letters, numbers, hyphens, underscores, dots. Must start with a letter or number.":null;async function b(){if(g){c(!0),m(null);try{let e=await (0,eo.tm)("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:s,name:o})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Failed (${e.status})`)}let t=await e.json();n(t)}catch(e){m(e instanceof Error?e.message:"Failed to create project"),c(!1)}}}return(0,r.jsx)(q,{open:e,onOpenChange:t,children:(0,r.jsxs)(U,{className:"sm:max-w-md",children:[(0,r.jsxs)(z,{children:[(0,r.jsx)(W,{children:"New Project"}),(0,r.jsxs)(K,{children:["Create a new project directory in"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 text-xs font-mono",children:s})]})]}),(0,r.jsx)("form",{onSubmit:e=>{e.preventDefault(),b()},className:"space-y-4 py-2",children:(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(rE,{htmlFor:"project-name",children:"Project name"}),(0,r.jsx)(e1.p,{ref:h,id:"project-name",placeholder:"my-project",value:o,onChange:e=>{l(e.target.value),m(null)},autoComplete:"off","aria-invalid":!!f}),f&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:f}),u&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:u}),o&&x&&!p&&(0,r.jsxs)("p",{className:"text-xs text-muted-foreground font-mono",children:[s,"/",o]})]})}),(0,r.jsxs)(G,{children:[(0,r.jsx)(J,{variant:"ghost",size:"sm",onClick:()=>t(!1),disabled:d,children:"Cancel"}),(0,r.jsxs)(J,{size:"sm",onClick:()=>void b(),disabled:!g,className:"gap-1.5",children:[d?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(t1.A,{className:"h-3.5 w-3.5"}),"Create"]})]})]})})}function rD({open:e,onOpenChange:t,onSelect:s,initialPath:a}){let[n,o]=(0,i.useState)(""),[l,d]=(0,i.useState)(null),[c,u]=(0,i.useState)([]),[m,h]=(0,i.useState)(!1),[x,p]=(0,i.useState)(null),[g,f]=(0,i.useState)(""),b=(0,i.useCallback)(async e=>{h(!0),p(null);try{let t=e?`?path=${encodeURIComponent(e)}`:"",s=await (0,eo.tm)(`/api/browse-directories${t}`);if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error??`${s.status}`)}let r=await s.json();o(r.current),f(r.current),d(r.parent),u(r.entries)}catch(e){p(e instanceof Error?e.message:"Failed to browse")}finally{h(!1)}},[]);return(0,i.useEffect)(()=>{e?b(a??void 0):(o(""),d(null),u([]),p(null),f(""))},[e,a,b]),(0,r.jsx)(q,{open:e,onOpenChange:t,children:(0,r.jsxs)(U,{className:"sm:max-w-lg gap-0 p-0 overflow-hidden",children:[(0,r.jsxs)(z,{className:"px-5 pt-5 pb-3",children:[(0,r.jsx)(W,{className:"text-base",children:"Choose Folder"}),(0,r.jsx)(K,{className:"text-xs",children:"Navigate to the folder that contains your project directories."})]}),(0,r.jsx)("div",{className:"border-y border-border/50 bg-muted/50 px-5 py-2",children:(0,r.jsx)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&b(t)},children:(0,r.jsx)("input",{type:"text",value:g,onChange:e=>f(e.target.value),spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",placeholder:"/absolute/path/to/folder","aria-label":"Folder path","data-testid":"folder-picker-path-input",className:"w-full bg-transparent font-mono text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})})}),(0,r.jsx)(tq,{className:"h-[320px]",children:(0,r.jsxs)("div",{className:"px-2 py-1",children:[m&&(0,r.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,r.jsx)(F.A,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),x&&(0,r.jsx)("div",{className:"px-3 py-4 text-center text-xs text-destructive",children:x}),!m&&!x&&(0,r.jsxs)(r.Fragment,{children:[l&&(0,r.jsxs)("button",{onClick:()=>void b(l),className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50",children:[(0,r.jsx)(tL.A,{className:"h-4 w-4 text-muted-foreground shrink-0"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:".."})]}),c.map(e=>(0,r.jsxs)("button",{onClick:()=>void b(e.path),className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-accent/50 group",children:[(0,r.jsx)(w.A,{className:"h-4 w-4 text-muted-foreground shrink-0"}),(0,r.jsx)("span",{className:"text-foreground truncate flex-1",children:e.name}),(0,r.jsx)(P.A,{className:"h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity shrink-0"})]},e.path)),!l&&0===c.length&&(0,r.jsx)("div",{className:"px-3 py-8 text-center text-xs text-muted-foreground",children:"No subdirectories"})]})]})}),(0,r.jsxs)(G,{className:"border-t border-border/50 px-5 py-3",children:[(0,r.jsx)(J,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),(0,r.jsxs)(J,{size:"sm",onClick:()=>{s(n),t(!1)},disabled:!n,className:"gap-1.5",children:[(0,r.jsx)(eE.A,{className:"h-3.5 w-3.5"}),"Select This Folder"]})]})]})})}function rM({onSaved:e,currentRoot:t}){let[s,a]=(0,i.useState)(!1),[n,o]=(0,i.useState)(null),[l,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)(!1),h=(0,i.useCallback)(async t=>{a(!0),o(null),d(!1);try{let s=await (0,eo.tm)("/api/preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:t})});if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error??`Request failed (${s.status})`)}d(!0),e(t)}catch(e){o(e instanceof Error?e.message:"Failed to save preference")}finally{a(!1)}},[e]);return t?(0,r.jsxs)("div",{className:"space-y-3","data-testid":"devroot-settings",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("code",{className:"flex-1 truncate rounded border border-border/50 bg-muted/50 px-3 py-2 font-mono text-xs text-foreground",children:t}),(0,r.jsx)(J,{size:"sm",variant:"outline",onClick:()=>m(!0),disabled:s,className:"h-9 gap-1.5 shrink-0",children:s?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):l?(0,r.jsx)(u.A,{className:"h-3.5 w-3.5 text-success"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eE.A,{className:"h-3.5 w-3.5"}),"Change"]})})]}),n&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:n}),l&&(0,r.jsx)("p",{className:"text-xs text-success",children:"Dev root updated"}),(0,r.jsx)(rD,{open:c,onOpenChange:m,onSelect:e=>void h(e),initialPath:t})]}):(0,r.jsxs)("div",{className:"rounded-md border border-border bg-card p-6",children:[(0,r.jsxs)("div",{className:"flex items-start gap-4",children:[(0,r.jsx)("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-md border border-border bg-accent",children:(0,r.jsx)(tD.A,{className:"h-5 w-5 text-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:"Set your development root"}),(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground leading-relaxed",children:"Point GSD at the folder that contains your project directories. It scans one level deep."}),(0,r.jsx)(J,{onClick:()=>m(!0),disabled:s,size:"sm",className:"mt-3 gap-2","data-testid":"projects-devroot-browse",children:s?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eE.A,{className:"h-3.5 w-3.5"}),"Browse"]})}),n&&(0,r.jsx)("p",{className:"mt-2 text-xs text-destructive",children:n})]})]}),(0,r.jsx)(rD,{open:c,onOpenChange:m,onSelect:e=>void h(e)})]})}function rq(){let[e,t]=(0,i.useState)(null),[s,a]=(0,i.useState)(!0);return((0,i.useEffect)(()=>{(0,eo.tm)("/api/preferences").then(e=>e.json()).then(e=>t(e.devRoot??null)).catch(()=>t(null)).finally(()=>a(!1))},[]),s)?(0,r.jsxs)("div",{className:"flex items-center gap-2 py-4 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading preferences…"]}):(0,r.jsxs)("div",{className:"space-y-3","data-testid":"settings-devroot",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)(tD.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:"Development Root"})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"The parent folder containing your project directories. GSD scans one level deep for projects."}),(0,r.jsx)(rM,{currentRoot:e??"",onSaved:e=>t(e)})]})}function rB(){let e=en(),[t,s]=(0,i.useState)([]),[n,o]=(0,i.useState)(null),[l,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[x,p]=(0,i.useState)(!1),[g,f]=(0,i.useState)(""),b=(0,i.useCallback)(async e=>{let t=await (0,eo.tm)(`/api/projects?root=${encodeURIComponent(e)}&detail=true`);if(!t.ok)throw Error(`Failed to discover projects: ${t.status}`);return await t.json()},[]);(0,i.useEffect)(()=>{let e=!1;return async function(){d(!0),u(null);try{let t=await (0,eo.tm)("/api/preferences");if(!t.ok)throw Error(`Failed to load preferences: ${t.status}`);let r=await t.json();if(!r.devRoot){o(null),s([]),d(!1);return}o(r.devRoot);let a=await b(r.devRoot);e||s(a)}catch(t){e||u(t instanceof Error?t.message:"Unknown error")}finally{e||d(!1)}}(),()=>{e=!0}},[b]);let v=(0,i.useCallback)(async e=>{d(!0),u(null);try{let t=await (0,eo.tm)("/api/switch-root",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({devRoot:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Request failed (${t.status})`)}let r=await t.json();o(r.devRoot),s(r.projects)}catch(e){u(e instanceof Error?e.message:"Failed to switch project root")}finally{d(!1)}},[]),j=(0,i.useCallback)(t=>{s(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),h(!1),e.switchProject(t.path)},[e]),y=[...t].sort((e,t)=>{let s={"active-gsd":0,"empty-gsd":1,brownfield:2,"v1-legacy":3,blank:4},r=s[e.kind]??5,a=s[t.kind]??5;return r!==a?r-a:e.name.localeCompare(t.name)}),w=g.trim()?y.filter(e=>e.name.toLowerCase().includes(g.toLowerCase())):y,N=!l&&y.length>0,S=y.length>5;return(0,r.jsxs)("div",{className:"flex h-screen flex-col bg-background text-foreground","data-testid":"project-selection-gate",children:[(0,r.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,r.jsxs)("div",{className:"mx-auto max-w-2xl px-6 pt-16 pb-10 md:px-10 lg:pt-24",children:[(0,r.jsxs)("div",{className:"flex flex-col items-center text-center mb-10",children:[(0,r.jsx)(a.default,{src:"/logo-black.svg",alt:"GSD-Pi Web",width:100,height:28,className:"h-7 w-auto dark:hidden"}),(0,r.jsx)(a.default,{src:"/logo-white.svg",alt:"GSD-Pi Web",width:100,height:28,className:"h-7 w-auto hidden dark:block"}),(0,r.jsx)("p",{className:"mt-3 text-sm text-muted-foreground",children:"Select a project to get started"})]}),l&&(0,r.jsxs)("div",{className:"flex items-center gap-3 py-20 justify-center text-sm text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-4 w-4 animate-spin"}),"Scanning for projects…"]}),c&&!l&&(0,r.jsx)("div",{className:"rounded-md border border-destructive/20 bg-destructive/[0.06] px-4 py-3 text-sm text-destructive",children:c}),!n&&!l&&!c&&(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-lg font-semibold tracking-tight text-foreground",children:"Welcome to GSD"}),(0,r.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"Set a development root to get started. GSD will discover projects inside it."})]}),(0,r.jsx)(rM,{onSaved:v})]}),n&&!l&&0===y.length&&!c&&(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-lg font-semibold tracking-tight text-foreground",children:"No projects found"}),(0,r.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:"No project directories were discovered. Create one to get started."})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-3 rounded-md border border-dashed border-border px-4 py-3 text-sm text-muted-foreground transition-colors hover:border-foreground/20 hover:text-foreground",children:[(0,r.jsx)(t1.A,{className:"h-4 w-4"}),"Create a new project"]})]}),N&&(0,r.jsxs)("div",{className:"space-y-5",children:[n&&(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(tD.A,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,r.jsx)("code",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground truncate",children:n}),(0,r.jsx)("button",{type:"button",onClick:()=>p(!0),className:"shrink-0 text-[11px] text-primary hover:text-primary/80 transition-colors font-medium","data-testid":"gate-change-root",children:"Change"})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,r.jsxs)("p",{className:"text-xs text-muted-foreground tabular-nums",children:[y.length," project",1!==y.length?"s":""]}),S&&(0,r.jsxs)("div",{className:"relative w-48",children:[(0,r.jsx)(sd.A,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("input",{type:"text",placeholder:"Filter…",value:g,onChange:e=>f(e.target.value),className:"h-8 w-full rounded-md border border-border bg-background pl-8 pr-3 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,r.jsxs)("div",{className:"rounded-md border border-border bg-card overflow-hidden divide-y divide-border",children:[w.map(t=>{let s=rP[t.kind],a=s.icon,n=r_(t.signals),i=t.progress?rI(t.progress):null,o=t.progress&&t.progress.milestonesTotal>0,l=o?Math.round(t.progress.milestonesCompleted/t.progress.milestonesTotal*100):0;return(0,r.jsxs)("button",{type:"button",onClick:()=>{e.switchProject(t.path)},className:"group flex w-full items-center gap-4 px-4 py-3 text-left transition-colors hover:bg-accent/50 focus-visible:outline-none focus-visible:bg-accent/50",children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-md",s.bgClass),children:(0,r.jsx)(a,{className:(0,M.cn)("h-3.5 w-3.5",s.color)})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:t.name}),(0,r.jsx)("span",{className:(0,M.cn)("text-[10px] font-medium shrink-0",s.color),children:s.label})]}),(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[n.length>0&&(0,r.jsx)("span",{children:n.join(" \xb7 ")}),n.length>0&&i&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"—"}),i&&(0,r.jsx)("span",{className:"truncate",children:i})]})]}),o&&(0,r.jsxs)("div",{className:"hidden sm:flex items-center gap-2 shrink-0 w-24",children:[(0,r.jsx)("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-foreground/[0.08]",children:(0,r.jsx)("div",{className:"h-full rounded-full bg-success/70 transition-[width]",style:{width:`${l}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] tabular-nums text-muted-foreground w-6 text-right",children:[t.progress.milestonesCompleted,"/",t.progress.milestonesTotal]})]}),t.lastModified>0&&(0,r.jsx)("span",{className:"hidden lg:inline text-[10px] text-muted-foreground shrink-0 w-16 text-right tabular-nums",children:function(e){let t=Date.now()-e;if(t<6e4)return"just now";let s=Math.floor(t/6e4);if(s<60)return`${s}m ago`;let r=Math.floor(s/60);if(r<24)return`${r}h ago`;let a=Math.floor(r/24);return a<30?`${a}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}(t.lastModified)}),(0,r.jsx)(P.A,{className:"h-4 w-4 shrink-0 text-muted-foreground/50 transition-colors group-hover:text-muted-foreground"})]},t.path)}),0===w.length&&g.trim()&&(0,r.jsxs)("div",{className:"px-4 py-8 text-center text-xs text-muted-foreground",children:['No projects matching "',g,'"']})]}),(0,r.jsxs)("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-3 rounded-md border border-dashed border-border px-4 py-2.5 text-sm text-muted-foreground transition-colors hover:border-foreground/20 hover:text-foreground w-full",children:[(0,r.jsx)(t1.A,{className:"h-3.5 w-3.5"}),"New project"]}),n&&(0,r.jsx)(rL,{open:m,onOpenChange:h,devRoot:n,existingNames:t.map(e=>e.name),onCreated:j})]}),n&&!l&&0===y.length&&!c&&(0,r.jsx)("div",{className:"mt-4",children:(0,r.jsxs)("button",{type:"button",onClick:()=>p(!0),className:"flex items-center gap-2 text-xs text-primary hover:text-primary/80 transition-colors font-medium","data-testid":"gate-change-root-empty",children:[(0,r.jsx)(eE.A,{className:"h-3.5 w-3.5"}),"Change project root"]})})]})}),(0,r.jsx)(rD,{open:x,onOpenChange:p,onSelect:e=>void v(e),initialPath:n})]})}var rO=s(36843),rU=s(72612),rz=s(94991),rG=s(28649),rW=s(43056);function rK({title:e,icon:t,subtitle:s,status:a,onRefresh:n,refreshing:i}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 pb-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:t}),(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:e}),a,s&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:s})]}),n&&(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:n,disabled:i,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",i&&"animate-spin")}),"Refresh"]})]})}function rV({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive",children:e})}function rH({label:e}){return(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),e]})}function rY({message:e}){return(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-4 py-5 text-center text-xs text-muted-foreground",children:e})}function rJ({label:e,value:t,variant:s}){return(0,r.jsxs)("div",{className:(0,M.cn)("flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs","info"===s&&"border-info/20 bg-info/5 text-info","warning"===s&&"border-warning/20 bg-warning/5 text-warning","success"===s&&"border-success/20 bg-success/5 text-success","error"===s&&"border-destructive/20 bg-destructive/5 text-destructive",(!s||"default"===s)&&"border-border/50 bg-card/50 text-foreground/80"),children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:e}),(0,r.jsx)("span",{className:"font-medium tabular-nums",children:t})]})}function rQ(e){if(e<1e3)return`${e}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let s=Math.floor(t/60),r=t%60;if(s<60)return r>0?`${s}m ${r}s`:`${s}m`;let a=Math.floor(s/60),n=s%60;return n>0?`${a}h ${n}m`:`${a}h`}function rZ(){return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-quick",children:[(0,r.jsx)(rK,{title:"Quick Task",icon:(0,r.jsx)(eb.A,{className:"h-3.5 w-3.5"})}),(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-4 py-4 space-y-3",children:[(0,r.jsx)("p",{className:"text-xs text-foreground",children:"Create a quick one-off task outside the current plan. Useful for small fixes, experiments, or ad-hoc work that doesn't fit into the milestone structure."}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Usage"}),(0,r.jsx)("div",{className:"rounded-md border border-border/50 bg-background/50 px-3 py-2 font-mono text-[11px] text-foreground/80",children:"/gsd quick <description>"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Examples"}),(0,r.jsx)("div",{className:"space-y-1.5",children:["Fix the typo in README.md header","Add .env.example with required keys","Update the LICENSE year to 2026","Run prettier on the whole project"].map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[11px]",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"$"}),(0,r.jsxs)("code",{className:"font-mono text-muted-foreground",children:["/gsd quick ",e]})]},e))})]}),(0,r.jsx)("div",{className:"rounded-md border border-info/15 bg-info/5 px-3 py-2 text-[11px] text-info/90",children:"Quick tasks run as standalone units — they don't affect milestone progress, slices, or the plan. Use them for work that should happen now without ceremony."})]})]})}function rX(){let e=(0,Z.gF)(),{loadHistoryData:t}=(0,Z._l)(),s=e.commandSurface.remainingCommands.history,a=s.data,n="loading"===s.phase,[o,l]=(0,i.useState)("phase");return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-history",children:[(0,r.jsx)(rK,{title:"History & Metrics",icon:(0,r.jsx)(eg.A,{className:"h-3.5 w-3.5"}),onRefresh:()=>void t(),refreshing:n}),s.error&&(0,r.jsx)(rV,{message:s.error}),n&&!a&&(0,r.jsx)(rH,{label:"Loading history data…"}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(rJ,{label:"Units",value:a.totals.units}),(0,r.jsx)(rJ,{label:"Cost",value:(0,Z.BD)(a.totals.cost),variant:"warning"}),(0,r.jsx)(rJ,{label:"Duration",value:rQ(a.totals.duration)}),(0,r.jsx)(rJ,{label:"Tool Calls",value:a.totals.toolCalls})]}),(0,r.jsx)("div",{className:"flex gap-1 rounded-lg border border-border/50 bg-card/50 p-0.5",children:["phase","slice","model","units"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>l(e),className:(0,M.cn)("flex-1 rounded-md px-2.5 py-1 text-[11px] font-medium capitalize transition-colors",o===e?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-muted-foreground"),children:"units"===e?"Recent":`By ${e}`},e))}),"phase"===o&&a.byPhase.length>0&&(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Phase"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Units"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Duration"})]})}),(0,r.jsx)("tbody",{children:a.byPhase.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 capitalize",children:e.phase}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:e.units}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.cost)}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:rQ(e.duration)})]},e.phase))})]})}),"slice"===o&&a.bySlice.length>0&&(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Slice"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Units"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Duration"})]})}),(0,r.jsx)("tbody",{children:a.bySlice.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.sliceId}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:e.units}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.cost)}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:rQ(e.duration)})]},e.sliceId))})]})}),"model"===o&&a.byModel.length>0&&(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Model"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Units"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"})]})}),(0,r.jsx)("tbody",{children:a.byModel.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 truncate max-w-[180px]",children:e.model}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:e.units}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.cost)})]},e.model))})]})}),"units"===o&&(0,r.jsx)(r.Fragment,{children:a.units.length>0?(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"ID"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Model"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cost"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Duration"})]})}),(0,r.jsx)("tbody",{children:a.units.slice(0,20).map((e,t)=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.type}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 truncate max-w-[120px]",children:e.id}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-muted-foreground truncate max-w-[120px]",children:e.model}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:(0,Z.BD)(e.cost)}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:rQ(e.finishedAt-e.startedAt)})]},t))})]})}):(0,r.jsx)(rY,{message:"No unit history recorded yet"})}),"phase"===o&&0===a.byPhase.length&&(0,r.jsx)(rY,{message:"No phase breakdown available"}),"slice"===o&&0===a.bySlice.length&&(0,r.jsx)(rY,{message:"No slice breakdown available"}),"model"===o&&0===a.byModel.length&&(0,r.jsx)(rY,{message:"No model breakdown available"})]})]})}function r0(){let e=(0,Z.gF)(),{loadUndoInfo:t,executeUndoAction:s}=(0,Z._l)(),a=e.commandSurface.remainingCommands.undo,n=a.data,o="loading"===a.phase,[l,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),p=async()=>{m(!0),x(null);try{let e=await s();x(e),d(!1)}finally{m(!1)}};return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-undo",children:[(0,r.jsx)(rK,{title:"Undo Last Unit",icon:(0,r.jsx)(rO.A,{className:"h-3.5 w-3.5"}),onRefresh:()=>{x(null),d(!1),t()},refreshing:o}),a.error&&(0,r.jsx)(rV,{message:a.error}),o&&!n&&(0,r.jsx)(rH,{label:"Loading undo info…"}),h&&(0,r.jsxs)("div",{className:(0,M.cn)("rounded-lg border px-3 py-2.5 text-xs",h.success?"border-success/20 bg-success/5 text-success":"border-destructive/20 bg-destructive/5 text-destructive"),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[h.success?(0,r.jsx)(u.A,{className:"h-3.5 w-3.5"}):(0,r.jsx)(tP.A,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"font-medium",children:h.success?"Undo Successful":"Undo Failed"})]}),(0,r.jsx)("p",{className:"mt-1 text-[11px] text-muted-foreground",children:h.message})]}),n&&(0,r.jsx)(r.Fragment,{children:n.lastUnitType?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Last Completed Unit"}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-0.5 text-[11px]",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"Type"}),(0,r.jsx)("span",{className:"font-mono text-foreground/80",children:n.lastUnitType}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"ID"}),(0,r.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:n.lastUnitId??"—"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"Key"}),(0,r.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:n.lastUnitKey??"—"})]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(rJ,{label:"Completed Units",value:n.completedCount}),n.commits.length>0&&(0,r.jsx)(rJ,{label:"Commits",value:n.commits.length,variant:"info"})]}),n.commits.length>0&&(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground",children:"Associated Commits"}),(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:n.commits.map(e=>(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-mono",children:e.slice(0,8)},e))})]}),l?(0,r.jsxs)("div",{className:"rounded-lg border border-warning/20 bg-warning/5 px-3 py-2.5 space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-warning",children:[(0,r.jsx)(ez.A,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"font-medium",children:"This will revert the last unit and its git commits."})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)(J,{type:"button",variant:"destructive",size:"sm",onClick:()=>void p(),disabled:c,className:"h-7 gap-1.5 text-xs",children:[c?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(t_.A,{className:"h-3 w-3"}),"Confirm Undo"]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(!1),disabled:c,className:"h-7 text-xs",children:"Cancel"})]})]}):(0,r.jsxs)(J,{type:"button",variant:"destructive",size:"sm",onClick:()=>d(!0),disabled:c||!!h?.success,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(t_.A,{className:"h-3 w-3"}),"Undo Last Unit"]})]}):(0,r.jsx)(rY,{message:"No completed units to undo"})})]})}function r1(){let e=(0,Z.gF)(),{loadSteerData:t,sendSteer:s}=(0,Z._l)(),a=e.commandSurface.remainingCommands.steer,n=a.data,o="loading"===a.phase,[l,d]=(0,i.useState)(""),[c,m]=(0,i.useState)(!1),[h,x]=(0,i.useState)(!1),p=async()=>{if(l.trim()){m(!0),x(!1);try{await s(l.trim()),x(!0),d(""),t()}finally{m(!1)}}};return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-steer",children:[(0,r.jsx)(rK,{title:"Steer",icon:(0,r.jsx)(rU.A,{className:"h-3.5 w-3.5"}),onRefresh:()=>{x(!1),t()},refreshing:o}),a.error&&(0,r.jsx)(rV,{message:a.error}),o&&!n&&(0,r.jsx)(rH,{label:"Loading steer data…"}),h&&(0,r.jsxs)("div",{className:"rounded-lg border border-success/20 bg-success/5 px-3 py-2.5 text-xs text-success flex items-center gap-2",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5"}),"Steering message sent successfully."]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Current Overrides"}),n?.overridesContent?(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-background/50 px-3 py-2.5 text-[11px] font-mono text-foreground/80 whitespace-pre-wrap max-h-[200px] overflow-y-auto leading-relaxed",children:n.overridesContent}):(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 text-[11px] text-muted-foreground italic",children:"No active overrides"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Send Steering Message"}),(0,r.jsx)(te,{value:l,onChange:e=>d(e.target.value),placeholder:"Enter steering instructions for the agent…",className:"min-h-[80px] text-xs resize-none"}),(0,r.jsxs)(J,{type:"button",variant:"default",size:"sm",onClick:()=>void p(),disabled:c||!l.trim(),className:"h-7 gap-1.5 text-xs",children:[c?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(rU.A,{className:"h-3 w-3"}),"Send"]})]})]})}function r5(){let e=(0,Z.gF)(),{loadHooksData:t}=(0,Z._l)(),s=e.commandSurface.remainingCommands.hooks,a=s.data,n="loading"===s.phase;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-hooks",children:[(0,r.jsx)(rK,{title:"Hooks",icon:(0,r.jsx)(t0.A,{className:"h-3.5 w-3.5"}),status:a?(0,r.jsxs)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:[a.entries.length," ",1===a.entries.length?"hook":"hooks"]}):null,onRefresh:()=>void t(),refreshing:n}),s.error&&(0,r.jsx)(rV,{message:s.error}),n&&!a&&(0,r.jsx)(rH,{label:"Loading hooks…"}),a&&(0,r.jsxs)(r.Fragment,{children:[a.entries.length>0?(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Name"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-center font-medium text-muted-foreground",children:"Status"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Targets"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Cycles"})]})}),(0,r.jsx)("tbody",{children:a.entries.map(e=>{let t=Object.values(e.activeCycles).reduce((e,t)=>e+t,0);return(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.name}),(0,r.jsx)("td",{className:"px-2.5 py-1.5",children:(0,r.jsx)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:e.type})}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-center",children:(0,r.jsx)(tN,{variant:e.enabled?"secondary":"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0",e.enabled?"border-success/30 text-success":"text-muted-foreground"),children:e.enabled?"enabled":"disabled"})}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:e.targets.length>0?e.targets.join(", "):"all"}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right tabular-nums text-foreground/80",children:t})]},e.name)})})]})}):(0,r.jsx)(rY,{message:"No hooks configured"}),a.formattedStatus&&(0,r.jsx)("div",{className:"rounded-lg border border-border/50 bg-background/50 px-3 py-2.5 text-[11px] font-mono text-muted-foreground whitespace-pre-wrap leading-relaxed",children:a.formattedStatus})]})]})}function r2(){let e=(0,Z.gF)(),{loadInspectData:t}=(0,Z._l)(),s=e.commandSurface.remainingCommands.inspect,a=s.data,n="loading"===s.phase;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-inspect",children:[(0,r.jsx)(rK,{title:"Inspect Database",icon:(0,r.jsx)(rz.A,{className:"h-3.5 w-3.5"}),subtitle:a?.schemaVersion!=null?`v${a.schemaVersion}`:null,onRefresh:()=>void t(),refreshing:n}),s.error&&(0,r.jsx)(rV,{message:s.error}),n&&!a&&(0,r.jsx)(rH,{label:"Loading database…"}),a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(rJ,{label:"Decisions",value:a.counts.decisions,variant:"info"}),(0,r.jsx)(rJ,{label:"Requirements",value:a.counts.requirements,variant:"info"}),(0,r.jsx)(rJ,{label:"Artifacts",value:a.counts.artifacts})]}),a.recentDecisions.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Recent Decisions (",a.recentDecisions.length,")"]}),(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"ID"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Decision"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Choice"})]})}),(0,r.jsx)("tbody",{children:a.recentDecisions.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.id}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-foreground/80 max-w-[200px] truncate",children:e.decision}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-muted-foreground max-w-[150px] truncate",children:e.choice})]},e.id))})]})})]}),a.recentRequirements.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Recent Requirements (",a.recentRequirements.length,")"]}),(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"ID"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Status"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Description"})]})}),(0,r.jsx)("tbody",{children:a.recentRequirements.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80",children:e.id}),(0,r.jsx)("td",{className:"px-2.5 py-1.5",children:(0,r.jsx)(tN,{variant:"active"===e.status?"secondary":"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0","active"===e.status&&"border-success/30 text-success","validated"===e.status&&"border-info/30 text-info","deferred"===e.status&&"text-muted-foreground"),children:e.status})}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-foreground/80 max-w-[220px] truncate",children:e.description})]},e.id))})]})})]}),0===a.recentDecisions.length&&0===a.recentRequirements.length&&(0,r.jsx)(rY,{message:"Database is empty — no decisions or requirements recorded"})]})]})}function r3(){let e=(0,Z.gF)(),{loadExportData:t}=(0,Z._l)(),s=e.commandSurface.remainingCommands.exportData,a=s.data,n="loading"===s.phase,[o,l]=(0,i.useState)("markdown"),d=e=>{let t="json"===e.format?"application/json":"text/markdown",s=new Blob([e.content],{type:t}),r=URL.createObjectURL(s),a=document.createElement("a");a.href=r,a.download=e.filename,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r)},c=async()=>{let e=await t(o);e&&d(e)};return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-export",children:[(0,r.jsx)(rK,{title:"Export",icon:(0,r.jsx)(sc.A,{className:"h-3.5 w-3.5"})}),s.error&&(0,r.jsx)(rV,{message:s.error}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:"Format"}),(0,r.jsx)("div",{className:"flex gap-1 rounded-lg border border-border/50 bg-card/50 p-0.5",children:["markdown","json"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>l(e),className:(0,M.cn)("flex-1 rounded-md px-3 py-1.5 text-[11px] font-medium capitalize transition-colors",o===e?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-muted-foreground"),children:"markdown"===e?"Markdown":"JSON"},e))})]}),(0,r.jsxs)(J,{type:"button",variant:"default",size:"sm",onClick:()=>void c(),disabled:n,className:"h-7 gap-1.5 text-xs",children:[n?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(sc.A,{className:"h-3 w-3"}),"Generate Export"]}),a&&(0,r.jsxs)("div",{className:"rounded-lg border border-success/20 bg-success/5 px-3 py-2.5 space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-success",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"font-medium",children:"Export Ready"})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-[11px] font-mono text-muted-foreground",children:a.filename}),(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>d(a),className:"h-6 gap-1 text-[10px]",children:[(0,r.jsx)(sc.A,{className:"h-2.5 w-2.5"}),"Download Again"]})]})]})]})}function r4(){let e=(0,Z.gF)(),{loadCleanupData:t,executeCleanupAction:s}=(0,Z._l)(),a=e.commandSurface.remainingCommands.cleanup,n=a.data,o="loading"===a.phase,[l,d]=(0,i.useState)(!1),[c,m]=(0,i.useState)(null),h=n?.branches.filter(e=>e.merged)??[],x=n?.snapshots??[],p=async e=>{d(!0),m(null);try{let r="branches"===e?h.map(e=>e.name):[],a="snapshots"===e?x.map(e=>e.ref):[],n=await s(r,a);m(n),t()}finally{d(!1)}};return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-cleanup",children:[(0,r.jsx)(rK,{title:"Cleanup",icon:(0,r.jsx)(s5.A,{className:"h-3.5 w-3.5"}),onRefresh:()=>{m(null),t()},refreshing:o}),a.error&&(0,r.jsx)(rV,{message:a.error}),o&&!n&&(0,r.jsx)(rH,{label:"Scanning for cleanup targets…"}),c&&(0,r.jsxs)("div",{className:"rounded-lg border border-success/20 bg-success/5 px-3 py-2.5 text-xs text-success",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(u.A,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"font-medium",children:"Cleanup Complete"})]}),(0,r.jsx)("p",{className:"mt-1 text-[11px] text-muted-foreground",children:c.message})]}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Branches (",n.branches.length,")"]}),h.length>0&&(0,r.jsxs)(J,{type:"button",variant:"destructive",size:"sm",onClick:()=>void p("branches"),disabled:l,className:"h-6 gap-1 text-[10px]",children:[l?(0,r.jsx)(F.A,{className:"h-2.5 w-2.5 animate-spin"}):(0,r.jsx)(rG.A,{className:"h-2.5 w-2.5"}),"Delete Merged (",h.length,")"]})]}),n.branches.length>0?(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Branch"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-center font-medium text-muted-foreground",children:"Status"})]})}),(0,r.jsx)("tbody",{children:n.branches.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 truncate max-w-[250px]",children:(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(C.A,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.name]})}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-center",children:(0,r.jsx)(tN,{variant:e.merged?"secondary":"outline",className:(0,M.cn)("text-[10px] px-1.5 py-0",e.merged?"border-success/30 text-success":"text-muted-foreground"),children:e.merged?"merged":"active"})})]},e.name))})]})}):(0,r.jsx)(rY,{message:"No branches to clean up"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("h4",{className:"text-xs font-medium text-muted-foreground",children:["Snapshots (",n.snapshots.length,")"]}),x.length>0&&(0,r.jsxs)(J,{type:"button",variant:"destructive",size:"sm",onClick:()=>void p("snapshots"),disabled:l,className:"h-6 gap-1 text-[10px]",children:[l?(0,r.jsx)(F.A,{className:"h-2.5 w-2.5 animate-spin"}):(0,r.jsx)(sr.A,{className:"h-2.5 w-2.5"}),"Prune Snapshots (",x.length,")"]})]}),n.snapshots.length>0?(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg border border-border/50",children:(0,r.jsxs)("table",{className:"w-full text-[11px]",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border/50 bg-card/50",children:[(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Ref"}),(0,r.jsx)("th",{className:"px-2.5 py-1.5 text-right font-medium text-muted-foreground",children:"Date"})]})}),(0,r.jsx)("tbody",{children:n.snapshots.map(e=>(0,r.jsxs)("tr",{className:"border-b border-border/50 last:border-0",children:[(0,r.jsx)("td",{className:"px-2.5 py-1.5 font-mono text-foreground/80 truncate max-w-[200px]",children:e.ref}),(0,r.jsx)("td",{className:"px-2.5 py-1.5 text-right text-muted-foreground",children:e.date})]},e.ref))})]})}):(0,r.jsx)(rY,{message:"No snapshots to prune"})]})]})]})}function r8(){let e=(0,Z.gF)(),t=(0,Z.Gr)(e),s=t?.milestones??[],a=t?.active;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"gsd-surface-gsd-queue",children:[(0,r.jsx)(rK,{title:"Queue",icon:(0,r.jsx)(rW.A,{className:"h-3.5 w-3.5"}),status:(0,r.jsxs)(tN,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:[s.length," ",1===s.length?"milestone":"milestones"]})}),s.length>0?(0,r.jsx)("div",{className:"space-y-2",children:s.map(e=>{var t;let s=a?.milestoneId===e.id,n={done:(t=e.slices).filter(e=>e.done).length,total:t.length};return(0,r.jsxs)("div",{className:(0,M.cn)("rounded-lg border px-3 py-2.5 space-y-1.5",s?"border-info/25 bg-info/5":"border-border/50 bg-card/50"),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-mono font-medium text-foreground/80",children:e.id}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate",children:e.title}),s&&(0,r.jsx)(tN,{variant:"secondary",className:"text-[10px] px-1.5 py-0 border-info/30 text-info",children:"active"})]}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground tabular-nums shrink-0",children:[n.done,"/",n.total," slices"]})]}),n.total>0&&(0,r.jsx)("div",{className:"h-1 rounded-full bg-border/50 overflow-hidden",children:(0,r.jsx)("div",{className:(0,M.cn)("h-full rounded-full transition-[width]",n.done===n.total?"bg-success":"bg-info"),style:{width:`${n.done/n.total*100}%`}})}),s&&e.slices.length>0&&(0,r.jsx)("div",{className:"space-y-0.5 pt-1",children:e.slices.map(e=>(0,r.jsxs)("div",{className:"flex items-center gap-2 text-[11px]",children:[e.done?(0,r.jsx)(u.A,{className:"h-3 w-3 text-success shrink-0"}):(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-1.5 w-1.5 rounded-full shrink-0",a?.sliceId===e.id?"bg-info":"bg-border/50")}),(0,r.jsx)("span",{className:"font-mono text-muted-foreground",children:e.id}),(0,r.jsx)("span",{className:(0,M.cn)("truncate",e.done?"text-muted-foreground line-through":"text-foreground/80"),children:e.title}),a?.sliceId===e.id&&!e.done&&(0,r.jsx)(tN,{variant:"outline",className:"text-[9px] px-1 py-0 text-info",children:"current"})]},e.id))})]},e.id)})}):(0,r.jsx)(rY,{message:"No milestones in the plan"})]})}let r6=["general","model","session-behavior","recovery","auth","integrations","workspace","experimental"],r7=["git"],r9=["resume","name","fork","session","compact"];function ae(e){return({model:"Model",thinking:"Thinking",git:"Git",login:"Login",logout:"Logout",settings:"Settings",resume:"Resume",name:"Name",fork:"Fork",session:"Session",export:"Export",compact:"Compact"})[e??""]??"Settings"}function at(e){let t=Date.now()-new Date(e).getTime();if(t<6e4)return"just now";let s=Math.floor(t/6e4);if(s<60)return`${s}m ago`;let r=Math.floor(s/60);if(r<24)return`${r}h ago`;let a=Math.floor(r/24);return`${a}d ago`}function as({status:e}){return(0,r.jsx)("span",{className:(0,M.cn)("inline-block h-1.5 w-1.5 rounded-full","ok"===e&&"bg-success","warning"===e&&"bg-warning","error"===e&&"bg-destructive","idle"===e&&"bg-foreground/20")})}function ar({title:e,action:t,status:s}){return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 pb-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,r.jsx)("h3",{className:"text-[13px] font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:e}),s]}),t]})}function aa({label:e,children:t,mono:s}){return(0,r.jsxs)("div",{className:"flex items-baseline justify-between gap-4 py-1.5 text-sm",children:[(0,r.jsx)("span",{className:"shrink-0 text-muted-foreground",children:e}),(0,r.jsx)("span",{className:(0,M.cn)("text-right text-foreground",s&&"font-mono text-xs"),children:t})]})}function an({label:e,description:t,checked:s,onCheckedChange:a,disabled:n,busy:i,testId:o}){return(0,r.jsxs)("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-border/50 bg-card/50 px-4 py-3",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e,i&&(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin text-muted-foreground"})]}),t&&(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t})]}),(0,r.jsx)(sx,{checked:s,onCheckedChange:a,disabled:n||i,"data-testid":o})]})}function ai({options:e,value:t,onChange:s,disabled:a}){return(0,r.jsx)("div",{className:"inline-flex rounded-lg border border-border bg-card/50 p-0.5",children:e.map(e=>(0,r.jsx)("button",{type:"button",className:(0,M.cn)("rounded-md px-3 py-1.5 text-xs font-medium transition-[color,background-color,box-shadow] duration-150 ease-out",t===e.value?"bg-foreground/10 text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>s(e.value),disabled:a||t===e.value,children:e.label},e.value))})}function ao(){var e,t;let s,a,n,l,d=(0,Z.gF)(),{closeCommandSurface:c,openCommandSurface:u,refreshBoot:m,setCommandSurfaceSection:h,selectCommandSurfaceTarget:x,loadGitSummary:p,loadRecoveryDiagnostics:g,loadForensicsDiagnostics:f,loadDoctorDiagnostics:b,loadSkillHealthDiagnostics:v,loadKnowledgeData:j,loadCapturesData:y,loadSettingsData:w,updateSessionBrowserState:N,loadSessionBrowser:S,renameSessionFromSurface:k,loadAvailableModels:A,applyModelSelection:T,applyThinkingLevel:E,setSteeringModeFromSurface:$,setFollowUpModeFromSurface:L,setAutoCompactionFromSurface:D,setAutoRetryFromSurface:q,abortRetryFromSurface:B,switchSessionFromSurface:O,loadSessionStats:U,exportSessionFromSurface:z,loadForkMessages:G,forkSessionFromSurface:W,compactSessionFromSurface:K,saveApiKeyFromSurface:V,startProviderFlowFromSurface:H,submitProviderFlowInputFromSurface:Y,cancelProviderFlowFromSurface:Q,logoutProviderFromSurface:X,loadHistoryData:ee,loadInspectData:et,loadHooksData:es,loadUndoInfo:er,loadCleanupData:ea,loadSteerData:en}=(0,Z._l)(),{commandSurface:ei}=d,eo=d.boot?.onboarding??null,el=eo?.activeFlow??null,ed=ei.gitSummary,ec=ei.recovery,eu=ei.sessionBrowser,em=d.boot?.bridge.sessionState??null,eh=ei.settingsRequests,ex=(0,Z.iT)(d.boot?.bridge),ep=(0,Z._0)(d.boot?.bridge),[eg,ef]=(0,i.useState)({}),[eb,ev]=(0,i.useState)(""),ej=(0,i.useRef)(null);(0,i.useEffect)(()=>{!ei.open||"model"!==ei.section||ei.availableModels.length>0||"loading_models"!==ei.pendingAction&&A()},[ei.open,ei.section,ei.availableModels.length,ei.pendingAction,A]),(0,i.useEffect)(()=>{!ei.open||"git"!==ei.section||"load_git_summary"===ei.pendingAction||ei.gitSummary.loaded||ei.gitSummary.error||p()},[ei.open,ei.section,ei.pendingAction,ei.gitSummary.loaded,ei.gitSummary.error,p]),(0,i.useEffect)(()=>{!ei.open||"recovery"!==ei.section||"load_recovery_diagnostics"===ei.pendingAction||ei.recovery.pending||(!ei.recovery.loaded||ei.recovery.stale||ei.recovery.error)&&g()},[ei.open,ei.section,ei.pendingAction,ei.recovery.pending,ei.recovery.loaded,ei.recovery.stale,ei.recovery.error,g]);let ey=ei.diagnostics,ew=ei.knowledgeCaptures,eN=ei.settingsData,eS=ei.remainingCommands;(0,i.useEffect)(()=>{ei.open&&("gsd-forensics"===ei.section&&"idle"===ey.forensics.phase?f():"gsd-doctor"===ei.section&&"idle"===ey.doctor.phase?b():"gsd-skill-health"===ei.section&&"idle"===ey.skillHealth.phase?v():"gsd-knowledge"===ei.section&&"idle"===ew.knowledge.phase?(j(),y()):("gsd-capture"===ei.section||"gsd-triage"===ei.section)&&"idle"===ew.captures.phase?(y(),j()):("gsd-prefs"===ei.section||"gsd-mode"===ei.section||"gsd-config"===ei.section||"experimental"===ei.section)&&"idle"===eN.phase?w():"gsd-history"===ei.section&&"idle"===eS.history.phase?ee():"gsd-inspect"===ei.section&&"idle"===eS.inspect.phase?et():"gsd-hooks"===ei.section&&"idle"===eS.hooks.phase?es():"gsd-undo"===ei.section&&"idle"===eS.undo.phase?er():"gsd-cleanup"===ei.section&&"idle"===eS.cleanup.phase?ea():"gsd-steer"===ei.section&&"idle"===eS.steer.phase&&en())},[ei.open,ei.section,ey.forensics.phase,ey.doctor.phase,ey.skillHealth.phase,ew.knowledge.phase,ew.captures.phase,eN.phase,eS.history.phase,eS.inspect.phase,eS.hooks.phase,eS.undo.phase,eS.cleanup.phase,eS.steer.phase,f,b,v,j,y,w,ee,et,es,er,ea,en]),(0,i.useEffect)(()=>{!ei.open||"resume"!==ei.section&&"name"!==ei.section||"load_session_browser"===ei.pendingAction||ei.sessionBrowser.loaded||S()},[ei.open,ei.section,ei.pendingAction,ei.sessionBrowser.loaded,S]),(0,i.useEffect)(()=>{if(!ei.open)return;let e=ej.current;e&&(e.scrollTop=0)},[ei.open,ei.activeSurface,ei.section]),(0,i.useEffect)(()=>{!ei.open||"session"!==ei.section||ei.sessionStats||"load_session_stats"!==ei.pendingAction&&U()},[ei.open,ei.section,ei.sessionStats,ei.pendingAction,U]),(0,i.useEffect)(()=>{!ei.open||"fork"!==ei.section||ei.forkMessages.length>0||"load_fork_messages"!==ei.pendingAction&&G()},[ei.open,ei.section,ei.forkMessages.length,ei.pendingAction,G]),(0,i.useEffect)(()=>{if(!ei.open||"resume"!==ei.section)return;let e=ei.selectedTarget?.kind==="resume"?ei.selectedTarget:null;if(e?.sessionPath)return;let t=eu.sessions.find(e=>!e.isActive)??eu.sessions[0];t&&x({kind:"resume",sessionPath:t.path})},[ei.open,ei.section,ei.selectedTarget,eu.sessions,x]),(0,i.useEffect)(()=>{if(!ei.open||"name"!==ei.section)return;let e=ei.selectedTarget?.kind==="name"?ei.selectedTarget:null;if(e?.sessionPath)return;let t=eu.sessions.find(e=>e.isActive)??eu.sessions[0];t&&x({kind:"name",sessionPath:t.path,name:t.name??""})},[ei.open,ei.section,ei.selectedTarget,eu.sessions,x]),(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{ev("")},0);return()=>window.clearTimeout(e)},[el?.flowId]),(0,i.useEffect)(()=>{ei.lastError&&sm.oR.error(ei.lastError)},[ei.lastError]),(0,i.useEffect)(()=>{ei.lastResult&&sm.oR.success(ei.lastResult)},[ei.lastResult]);let ek=ei.selectedTarget?.kind==="model"?ei.selectedTarget:null,eC=ei.selectedTarget?.kind==="thinking"?ei.selectedTarget:null,eA=ei.selectedTarget?.kind==="auth"?ei.selectedTarget:null,eR=ei.selectedTarget?.kind==="resume"?ei.selectedTarget:null,eT=ei.selectedTarget?.kind==="name"?ei.selectedTarget:null,eE=ei.selectedTarget?.kind==="fork"?ei.selectedTarget:null,eP=ei.selectedTarget?.kind==="session"?ei.selectedTarget:null,e_=ei.selectedTarget?.kind==="compact"?ei.selectedTarget:null,eI=(e=ei.activeSurface,t=ei.selectedTarget,t?.kind==="auth"?t.intent:"login"===e?"login":"logout"===e?"logout":"manage"),eF=eo?.required.providers.find(e=>e.id===eA?.providerId)??null,e$=(ek?.query??ei.args).trim().toLowerCase(),eL=(0,i.useMemo)(()=>e$?ei.availableModels.filter(e=>`${e.provider} ${e.modelId} ${e.name??""}`.toLowerCase().includes(e$)):ei.availableModels,[ei.availableModels,e$]),eD=(0,i.useMemo)(()=>{let e=new Map;for(let t of eL){let s=t.provider,r=e.get(s);r?r.push(t):e.set(s,[t])}return e},[eL]),eM="idle"!==d.onboardingRequestState,eq="loading_models"===ei.pendingAction||"get_available_models"===d.commandInFlight,eB="load_git_summary"===ei.pendingAction,eO="load_recovery_diagnostics"===ei.pendingAction||ec.pending,ez=ec.diagnostics,eG="load_session_browser"===ei.pendingAction,eW="load_fork_messages"===ei.pendingAction||"fork_session"===ei.pendingAction,eK="load_session_stats"===ei.pendingAction||"export_html"===ei.pendingAction,eV="switch_session"===ei.pendingAction,eH="rename_session"===ei.pendingAction,eY="compact_session"===ei.pendingAction||em?.isCompacting===!0,eJ=eh.steeringMode.pending||eh.followUpMode.pending,eQ=eh.autoCompaction.pending,eX=eh.autoRetry.pending,e0=eh.abortRetry.pending,e2=eF?eg[eF.id]??"":"",e3=tx(),e6=function(e,t=!1){switch(e){case"git":return[...r7];case"resume":case"name":case"fork":case"session":case"export":case"compact":return[...r9];default:return t?[...r6,"admin"]:[...r6]}}(ei.activeSurface,e3.isDevMode),tt=`/${ei.activeSurface??"settings"}`,ts=e=>{let t="name"===e,s=t?eT?.sessionPath:eR?.sessionPath;return(0,r.jsxs)("div",{className:"space-y-4","data-testid":t?"command-surface-name":"command-surface-resume",children:[(0,r.jsx)(ar,{title:t?"Rename":"Resume",status:t?null:(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:ep??"pending"})}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)(sd.A,{className:"absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),(0,r.jsx)(e1.p,{value:eu.query,onChange:e=>N({query:e.target.value}),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),S())},placeholder:"Search sessions…",className:"h-8 pl-9 text-xs",disabled:eG,"data-testid":"command-surface-session-browser-query"})]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void S(),disabled:eG,className:"h-8 w-8 p-0",children:(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3.5 w-3.5",eG&&"animate-spin")})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(ai,{options:[{value:"threaded",label:"Threaded"},{value:"recent",label:"Recent"},{value:"relevance",label:"Relevance"}],value:eu.sortMode,onChange:e=>{N({sortMode:e}),S({sortMode:e})},disabled:eG}),(0,r.jsx)("button",{type:"button",className:(0,M.cn)("rounded-md border border-border px-2.5 py-1.5 text-[11px] font-medium transition-colors","named"===eu.nameFilter?"bg-foreground/10 text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{let e="named"===eu.nameFilter?"all":"named";N({nameFilter:e}),S({nameFilter:e})},disabled:eG,children:"Named"})]}),eu.error&&(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive",children:eu.error}),eG&&0===eu.sessions.length?(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading sessions…"]}):eu.sessions.length>0?(0,r.jsx)("div",{className:"space-y-1","data-testid":"command-surface-session-browser-results",children:eu.sessions.map(e=>{let a=e.path===s;return(0,r.jsxs)("button",{type:"button",className:(0,M.cn)("flex w-full items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors",a?"bg-foreground/[0.07]":"hover:bg-foreground/[0.03]"),style:{paddingLeft:`${.75+.6*e.depth}rem`},onClick:()=>t?x({kind:"name",sessionPath:e.path,name:eT?.sessionPath===e.path?eT?.name??e.name??"":e.name??""}):x({kind:"resume",sessionPath:e.path}),"data-testid":`command-surface-session-browser-item-${e.id}`,children:[(0,r.jsx)("div",{className:(0,M.cn)("mt-1 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",a?"border-foreground bg-foreground":"border-foreground/25"),children:a&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"truncate text-sm font-medium text-foreground",children:e.name||e.firstMessage||e.id}),e.isActive&&(0,r.jsx)(as,{status:"ok"})]}),e.name&&e.firstMessage&&(0,r.jsx)("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:e.firstMessage}),(0,r.jsxs)("div",{className:"mt-0.5 flex gap-3 text-[11px] text-muted-foreground",children:[(0,r.jsxs)("span",{children:[e.messageCount," msgs"]}),(0,r.jsx)("span",{children:at(e.modifiedAt)})]})]})]},e.path)})}):(0,r.jsx)("p",{className:"py-4 text-center text-xs text-muted-foreground",children:"No sessions matched."}),eu.loaded&&(0,r.jsxs)("p",{className:"text-[11px] text-muted-foreground","data-testid":"command-surface-session-browser-meta",children:["Current-project sessions \xb7 ",eu.returnedSessions," of ",eu.totalSessions," \xb7 ",eu.sortMode," \xb7 ",eu.nameFilter]}),t&&(0,r.jsxs)("div",{className:"space-y-3 border-t border-border/50 pt-3",children:[(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e1.p,{value:eT?.name??"",onChange:e=>x({kind:"name",sessionPath:eT?.sessionPath,name:e.target.value}),placeholder:"Session name",className:"h-8 flex-1 text-xs",disabled:!eT?.sessionPath||eH,"data-testid":"command-surface-rename-input"}),(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>eT?.sessionPath&&void k(eT.sessionPath,eT.name),disabled:!eT?.sessionPath||!eT.name.trim()||eH,"data-testid":"command-surface-apply-rename",className:"h-8 gap-1.5",children:[eH?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(si.A,{className:"h-3.5 w-3.5"}),"Rename"]})]}),ei.renameRequest.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:ei.renameRequest.error}),ei.renameRequest.result&&(0,r.jsx)("p",{className:"text-xs text-success",children:ei.renameRequest.result})]}),!t&&(0,r.jsxs)("div",{className:"flex items-center justify-between border-t border-border/50 pt-3",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"command-surface-resume-state",children:eV?"Switching…":ei.resumeRequest.error??ei.resumeRequest.result??"Select a session"}),(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>eR?.sessionPath&&void O(eR.sessionPath),disabled:!eR?.sessionPath||eV,"data-testid":"command-surface-apply-resume",className:"h-8 gap-1.5",children:[eV?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(ss.A,{className:"h-3.5 w-3.5"}),"Switch"]})]})]})},tr=e6.length<=1,ta="git"===ei.activeSurface,tn=ed.result;return(0,r.jsx)(e5,{open:ei.open,onOpenChange:e=>!e&&c(),children:(0,r.jsxs)(e4,{side:"right",className:"flex h-full w-full flex-col p-0 sm:max-w-[540px]","data-testid":"command-surface",children:[(0,r.jsxs)(e8,{className:"sr-only",children:[(0,r.jsx)(e7,{children:ae(ei.activeSurface)}),(0,r.jsx)(e9,{children:"Settings and controls"})]}),(0,r.jsxs)("div",{className:"flex h-full min-h-0",children:[!tr&&(0,r.jsx)("nav",{className:"flex w-12 shrink-0 flex-col items-center gap-0.5 border-r border-border/50 bg-card/50 py-3","data-testid":"command-surface-sections",children:e6.map(e=>{let t=ei.section===e;return(0,r.jsxs)(tS.m_,{children:[(0,r.jsx)(tS.k$,{asChild:!0,children:(0,r.jsx)("button",{type:"button",className:(0,M.cn)("flex h-9 w-9 items-center justify-center rounded-lg transition-colors",t?"bg-foreground/10 text-foreground":"text-muted-foreground hover:bg-foreground/[0.04] hover:text-foreground"),onClick:()=>h(e),"data-testid":`command-surface-section-${e}`,children:{general:(0,r.jsx)(se.A,{className:"h-4 w-4"}),model:(0,r.jsx)(eU.A,{className:"h-4 w-4"}),thinking:(0,r.jsx)(st.A,{className:"h-4 w-4"}),queue:(0,r.jsx)(ss.A,{className:"h-4 w-4"}),compaction:(0,r.jsx)(sr.A,{className:"h-4 w-4"}),retry:(0,r.jsx)(sa.A,{className:"h-4 w-4"}),"session-behavior":(0,r.jsx)(ss.A,{className:"h-4 w-4"}),recovery:(0,r.jsx)(I.A,{className:"h-4 w-4"}),auth:(0,r.jsx)(ty.A,{className:"h-4 w-4"}),admin:(0,r.jsx)(sn.A,{className:"h-4 w-4"}),git:(0,r.jsx)(C.A,{className:"h-4 w-4"}),resume:(0,r.jsx)(ss.A,{className:"h-4 w-4"}),name:(0,r.jsx)(si.A,{className:"h-4 w-4"}),fork:(0,r.jsx)(C.A,{className:"h-4 w-4"}),session:(0,r.jsx)(_.A,{className:"h-4 w-4"}),compact:(0,r.jsx)(sr.A,{className:"h-4 w-4"}),workspace:(0,r.jsx)(tD.A,{className:"h-4 w-4"}),integrations:(0,r.jsx)(so.A,{className:"h-4 w-4"}),experimental:(0,r.jsx)(sl.A,{className:"h-4 w-4"})}[e]??null})}),(0,r.jsx)(tS.ZI,{side:"right",sideOffset:6,children:{general:"General",model:"Model",thinking:"Thinking",queue:"Queue",compaction:"Compaction",retry:"Retry","session-behavior":"Session",recovery:"Recovery",auth:"Auth",admin:"Admin",git:"Git",resume:"Resume",name:"Name",fork:"Fork",session:"Session",compact:"Compact",workspace:"Workspace",integrations:"Integrations",experimental:"Experimental"}[e]??e})]},e)})}),(0,r.jsxs)("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[ta?(s=tn?.kind==="repo"?tn.branch??"detached":null,a=tn?.kind==="repo"?tn.mainBranch:null,n=tn?.kind==="repo"&&tn.hasChanges,l=tn?.kind==="repo"&&!n,(0,r.jsx)("div",{className:"border-b border-border/50 px-5 py-4",children:(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-8 w-8 items-center justify-center rounded-lg",l?"bg-success/10":n?"bg-warning/10":"bg-card/50"),children:(0,r.jsx)(C.A,{className:(0,M.cn)("h-4 w-4",l?"text-success":n?"text-warning":"text-muted-foreground")})}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h2",{className:"text-sm font-semibold text-foreground","data-testid":"command-surface-title",children:s??"Git"}),s&&a&&s!==a&&(0,r.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:["from ",a]})]}),tn?.kind==="repo"&&(0,r.jsxs)("div",{className:"mt-0.5 flex items-center gap-1.5",children:[(0,r.jsx)(as,{status:l?"ok":n?"warning":"idle"}),(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground",children:l?"Clean":n?"Changes detected":"Loading…"})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>void p(),disabled:eB,"aria-label":"Refresh",className:"h-7 w-7",children:(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3.5 w-3.5",eB&&"animate-spin")})}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"icon",onClick:c,"aria-label":"Close",className:"h-7 w-7",children:(0,r.jsx)(o.A,{className:"h-3.5 w-3.5"})})]})]})})):(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 border-b border-border/50 px-5 py-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Command surface"}),(0,r.jsx)("div",{className:"text-lg font-semibold text-foreground","data-testid":"command-surface-title",children:ae(ei.activeSurface)})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"rounded-full border border-border bg-card px-2.5 py-1 text-xs font-medium text-muted-foreground","data-testid":"command-surface-kind",children:tt}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"icon",onClick:c,"aria-label":"Close",className:"h-8 w-8",children:(0,r.jsx)(o.A,{className:"h-4 w-4"})})]})]}),(ei.lastResult||ei.lastError)&&(0,r.jsx)("div",{className:(0,M.cn)("border-b border-border/50 px-5 py-3 text-xs",ei.lastError?"bg-destructive/5 text-destructive":"bg-success/5 text-success"),"data-testid":"command-surface-result",children:ei.lastError??ei.lastResult}),(0,r.jsx)(tq,{className:"min-h-0 flex-1",viewportRef:ej,children:(0,r.jsx)("div",{className:"px-5 py-5",children:(()=>{switch(ei.section){case"general":return(0,r.jsx)(rk,{});case"experimental":return(0,r.jsx)(rA,{});case"model":case"thinking":return(0,r.jsxs)("div",{className:"space-y-8",children:[(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-models",children:[(0,r.jsx)(ar,{title:"Model",status:(0,r.jsx)("span",{className:"font-mono text-xs text-muted-foreground",children:ex}),action:(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void A(),disabled:eq,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",eq&&"animate-spin")}),"Refresh"]})}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(sd.A,{className:"absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),(0,r.jsx)(e1.p,{value:ek?.query??ei.args,onChange:e=>x({kind:"model",provider:ek?.provider,modelId:ek?.modelId,query:e.target.value}),placeholder:"Filter models…",className:"h-8 pl-9 text-xs"})]}),eq&&0===ei.availableModels.length?(0,r.jsxs)("div",{className:"flex items-center gap-2 py-8 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading models…"]}):eL.length>0?(0,r.jsx)("div",{className:"space-y-4",children:Array.from(eD.entries()).map(([e,t])=>(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mb-1.5 px-1 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground",children:e}),(0,r.jsx)("div",{className:"space-y-0.5",children:t.map(e=>{let t=ek?.provider===e.provider&&ek?.modelId===e.modelId;return(0,r.jsxs)("button",{type:"button",className:(0,M.cn)("group flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left transition-colors",t?"bg-foreground/[0.07]":"hover:bg-foreground/[0.03]"),onClick:()=>x({kind:"model",provider:e.provider,modelId:e.modelId,query:ek?.query}),children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",t?"border-foreground bg-foreground":"border-foreground/25"),children:t&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.name||e.modelId}),e.isCurrent&&(0,r.jsx)(as,{status:"ok"})]}),(0,r.jsx)("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.modelId})]}),(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.isCurrent&&(0,r.jsx)("span",{className:"rounded bg-foreground/10 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:"Active"}),e.reasoning&&(0,r.jsx)("span",{className:"rounded bg-foreground/10 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:"Thinking"})]})]},`${e.provider}/${e.modelId}`)})})]},e))}):(0,r.jsx)("p",{className:"py-6 text-center text-xs text-muted-foreground",children:"No models matched."}),(0,r.jsx)("div",{className:"flex justify-end border-t border-border/50 pt-3",children:(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>ek?.provider&&ek?.modelId&&void T(ek.provider,ek.modelId),disabled:!ek?.provider||!ek.modelId||"set_model"===ei.pendingAction,"data-testid":"command-surface-apply-model",className:"h-8 gap-1.5",children:["set_model"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(eZ.A,{className:"h-3.5 w-3.5"}),"Apply model"]})})]}),(0,r.jsx)("div",{className:"border-t border-border/50 pt-6",children:(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-thinking",children:[(0,r.jsx)(ar,{title:"Thinking level",status:(0,r.jsx)("span",{className:"font-mono text-xs text-muted-foreground",children:d.boot?.bridge.sessionState?.thinkingLevel??"off"})}),(0,r.jsx)("div",{className:"space-y-1",children:sp.ll.map(e=>{let t=eC?.level===e,s=d.boot?.bridge.sessionState?.thinkingLevel===e,a="off"===e?"No reasoning overhead":"minimal"===e?"Light reasoning":"low"===e?"Basic analysis":"medium"===e?"Balanced reasoning":"high"===e?"Deep analysis":"Maximum deliberation";return(0,r.jsxs)("button",{type:"button",className:(0,M.cn)("flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left transition-colors",t?"bg-foreground/[0.07]":"hover:bg-foreground/[0.03]"),onClick:()=>x({kind:"thinking",level:e}),children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",t?"border-foreground bg-foreground":"border-foreground/25"),children:t&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium capitalize text-foreground",children:e}),s&&(0,r.jsx)(as,{status:"ok"})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:a})]})]},e)})}),(0,r.jsx)("div",{className:"flex justify-end border-t border-border/50 pt-3",children:(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>eC&&void E(eC.level),disabled:!eC||"set_thinking_level"===ei.pendingAction,"data-testid":"command-surface-apply-thinking",className:"h-8 gap-1.5",children:["set_thinking_level"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(eZ.A,{className:"h-3.5 w-3.5"}),"Apply"]})})]})})]});case"session-behavior":case"queue":case"compaction":case"retry":return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"space-y-5","data-testid":"command-surface-queue-settings",children:[(0,r.jsx)(ar,{title:"Queue modes"}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Steering mode"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"How steering messages queue during streaming"})]}),eh.steeringMode.pending&&(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),(0,r.jsx)(ai,{options:[{value:"all",label:"Queue all"},{value:"one-at-a-time",label:"One at a time"}],value:em?.steeringMode??null,onChange:e=>void $(e),disabled:!em||eJ}),eh.steeringMode.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:eh.steeringMode.error})]}),(0,r.jsx)("div",{className:"border-t border-border/50"}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Follow-up mode"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"How follow-up prompts sequence during a live turn"})]}),eh.followUpMode.pending&&(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),(0,r.jsx)(ai,{options:[{value:"all",label:"Queue all"},{value:"one-at-a-time",label:"One at a time"}],value:em?.followUpMode??null,onChange:e=>void L(e),disabled:!em||eJ}),eh.followUpMode.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:eh.followUpMode.error})]})]}),(0,r.jsx)("div",{className:"border-t border-border/50 pt-4",children:(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-auto-compaction-settings",children:[(0,r.jsx)(ar,{title:"Auto-compaction",status:em?.isCompacting?(0,r.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-warning",children:[(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"})," Compacting"]}):null}),(0,r.jsx)(an,{label:"Auto-compact",description:"Automatically compact when context thresholds are crossed",checked:em?.autoCompactionEnabled??!1,onCheckedChange:e=>void D(e),disabled:!em||eQ,busy:eQ,testId:"command-surface-toggle-auto-compaction"}),eh.autoCompaction.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:eh.autoCompaction.error}),eh.autoCompaction.result&&(0,r.jsx)("p",{className:"text-xs text-success",children:eh.autoCompaction.result})]})}),(0,r.jsx)("div",{className:"border-t border-border/50 pt-4",children:(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-retry-settings",children:[(0,r.jsx)(ar,{title:"Retry",status:em?.retryInProgress?(0,r.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-warning",children:[(0,r.jsx)(so.A,{className:"h-3 w-3"})," Attempt ",Math.max(1,em.retryAttempt)]}):null}),(0,r.jsx)(an,{label:"Auto-retry",description:"Automatically retry on transient failures",checked:em?.autoRetryEnabled??!1,onCheckedChange:e=>void q(e),disabled:!em||eX,busy:eX,testId:"command-surface-toggle-auto-retry"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"command-surface-auto-retry-state",children:eX?"Updating auto-retry…":eh.autoRetry.error?eh.autoRetry.error:eh.autoRetry.result?eh.autoRetry.result:em?.autoRetryEnabled?"Auto-retry enabled":"Auto-retry disabled"}),em?.retryInProgress&&(0,r.jsxs)("div",{className:"flex items-center justify-between rounded-lg border border-warning/20 bg-warning/5 px-4 py-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Retry in progress"}),(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Attempt ",Math.max(1,em.retryAttempt)," is active"]})]}),(0,r.jsxs)(J,{type:"button",variant:"destructive",size:"sm",onClick:()=>void B(),disabled:e0,"data-testid":"command-surface-abort-retry",className:"h-7 gap-1.5 text-xs",children:[e0?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(o.A,{className:"h-3 w-3"}),"Abort"]})]}),eh.autoRetry.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:eh.autoRetry.error}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"command-surface-abort-retry-state",children:e0?"Aborting retry…":eh.abortRetry.error?eh.abortRetry.error:eh.abortRetry.result?eh.abortRetry.result:em?.retryInProgress?"Retry can be aborted":"No retry in progress"}),eh.abortRetry.error&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:eh.abortRetry.error})]})})]});case"recovery":return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-recovery",children:[(0,r.jsx)("div",{className:"text-xs text-muted-foreground","data-testid":"command-surface-recovery-state",children:eO?"Loading recovery diagnostics…":ec.error?"Recovery diagnostics failed":ec.stale?"Recovery diagnostics stale":ec.loaded?"Recovery diagnostics loaded":"Recovery diagnostics idle"}),(0,r.jsx)(ar,{title:"Recovery",status:ez?(0,r.jsx)(as,{status:"healthy"===ez.summary.tone?"ok":"warning"===ez.summary.tone?"warning":"error"}):null,action:(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void g(),disabled:eO,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3",eO&&"animate-spin")}),"Refresh"]})}),ec.error&&(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive","data-testid":"command-surface-recovery-error",children:ec.error}),eO&&!ez&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading diagnostics…"]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 border-t border-border/50 pt-3","data-testid":"command-surface-recovery-actions",children:(0,r.jsx)(J,{type:"button",variant:"default",size:"sm",onClick:()=>void g(),"data-testid":"command-surface-recovery-action-refresh_diagnostics",className:"h-7 text-xs",children:"Refresh diagnostics"})})]}),ez?.status==="unavailable"&&!ec.error&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"space-y-1 rounded-lg border border-border/50 bg-card/50 px-4 py-3","data-testid":"command-surface-recovery-summary",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:ez.summary.label}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:ez.summary.detail})]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 border-t border-border/50 pt-3","data-testid":"command-surface-recovery-actions",children:(0,r.jsx)(J,{type:"button",variant:"default",size:"sm",onClick:()=>void g(),"data-testid":"command-surface-recovery-action-refresh_diagnostics",className:"h-7 text-xs",children:"Refresh diagnostics"})})]}),ez&&"unavailable"!==ez.status&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"space-y-1","data-testid":"command-surface-recovery-summary",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:ez.summary.label}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:ez.summary.detail})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Validation"}),(0,r.jsx)("div",{className:"mt-1 text-lg font-semibold tabular-nums text-foreground",children:ez.summary.validationCount})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Doctor"}),(0,r.jsx)("div",{className:"mt-1 text-lg font-semibold tabular-nums text-foreground",children:ez.summary.doctorIssueCount})]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[ez.summary.retryInProgress&&(0,r.jsxs)(tN,{variant:"default",className:"text-[10px]",children:["Retry ",Math.max(1,ez.summary.retryAttempt)]}),ez.summary.compactionActive&&(0,r.jsx)(tN,{variant:"default",className:"text-[10px]",children:"Compacting"}),ez.summary.lastFailurePhase&&(0,r.jsxs)(tN,{variant:"destructive",className:"text-[10px]",children:["Phase ",ez.summary.lastFailurePhase]}),ec.stale&&(0,r.jsx)(tN,{variant:"outline",className:"text-[10px]",children:"Stale"})]}),ez.bridge.lastFailure&&(0,r.jsxs)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5","data-testid":"command-surface-recovery-last-failure",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-destructive",children:"Last failure"}),(0,r.jsx)("p",{className:"mt-1 text-xs text-destructive/80",children:ez.bridge.lastFailure.message}),(0,r.jsxs)("div",{className:"mt-1.5 flex gap-3 text-[10px] text-destructive/60",children:[(0,r.jsxs)("span",{children:["Phase: ",ez.bridge.lastFailure.phase]}),(0,r.jsx)("span",{children:at(ez.bridge.lastFailure.at)})]})]}),ez.validation.topIssues.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Validation issues"}),ez.validation.topIssues.map(e=>(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2",children:[(0,r.jsx)("div",{className:"flex items-center gap-2",children:(0,r.jsx)(tN,{variant:"error"===e.severity?"destructive":"outline",className:"text-[10px]",children:e.code})}),(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:e.message}),e.suggestion&&(0,r.jsxs)("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["→ ",e.suggestion]})]},`${e.code}:${e.file??e.message}`))]}),ez.doctor.topIssues.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Doctor issues"}),ez.doctor.topIssues.map(e=>(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2",children:[(0,r.jsx)(tN,{variant:"outline",className:"text-[10px]",children:e.code}),(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:e.message})]},`${e.code}:${e.unitId??e.message}`))]}),ez.interruptedRun.detected&&(0,r.jsxs)("div",{className:"rounded-lg border border-warning/20 bg-warning/5 px-3 py-2.5","data-testid":"command-surface-recovery-interrupted-run",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-warning",children:"Interrupted run detected"}),(0,r.jsxs)("div",{className:"mt-1 space-y-1 text-xs text-warning/80",children:[(0,r.jsx)("p",{children:"Available: yes"}),(0,r.jsx)("p",{children:"Detected: yes"}),(0,r.jsx)("p",{children:ez.interruptedRun.detail})]}),(0,r.jsxs)("div",{className:"mt-1.5 grid gap-1 text-[10px] text-warning/60",children:[(0,r.jsxs)("span",{children:["Tool calls: ",ez.interruptedRun.counts.toolCalls]}),(0,r.jsxs)("span",{children:["Files written: ",ez.interruptedRun.counts.filesWritten]}),(0,r.jsxs)("span",{children:["Commands: ",ez.interruptedRun.counts.commandsRun]}),(0,r.jsxs)("span",{children:["Errors: ",ez.interruptedRun.counts.errors]}),(0,r.jsxs)("span",{children:["Last forensic error: ",ez.interruptedRun.lastError??"[redacted]"]})]})]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 border-t border-border/50 pt-3","data-testid":"command-surface-recovery-actions",children:ez.actions.browser.length>0?ez.actions.browser.map(e=>(0,r.jsx)(J,{type:"button",variant:"danger"===e.emphasis?"destructive":"primary"===e.emphasis?"default":"outline",size:"sm",onClick:()=>(e=>{switch(e){case"refresh_diagnostics":g();return;case"refresh_workspace":m({soft:!0});return;case"open_retry_controls":h("retry");return;case"open_resume_controls":u("resume",{source:"surface"});return;case"open_auth_controls":h("auth");return;default:return}})(e.id),"data-testid":`command-surface-recovery-action-${e.id}`,className:"h-7 text-xs",children:e.label},e.id)):(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:eO?"Loading recovery actions…":"No browser recovery actions available."})}),ez.actions.commands.length>0&&(0,r.jsxs)("div",{className:"space-y-2 border-t border-border/50 pt-3","data-testid":"command-surface-recovery-commands",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Suggested commands"}),ez.actions.commands.map(e=>(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2 text-xs",children:[(0,r.jsx)("div",{className:"font-mono text-foreground",children:e.command}),(0,r.jsx)("p",{className:"mt-1 text-muted-foreground",children:e.label})]},e.command))]})]})]});case"auth":return eo?(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-auth",children:[(0,r.jsx)(ar,{title:"Auth",status:(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"login"===eI?"Login":"logout"===eI?"Logout":"Manage"})}),(0,r.jsx)("div",{className:"space-y-1",children:eo.required.providers.map(e=>{let t=e.id===eF?.id;return(0,r.jsxs)("button",{type:"button",className:(0,M.cn)("flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left transition-colors",t?"bg-foreground/[0.07]":"hover:bg-foreground/[0.03]"),onClick:()=>x({kind:"auth",providerId:e.id,intent:eI}),children:[(0,r.jsx)("div",{className:(0,M.cn)("flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",t?"border-foreground bg-foreground":"border-foreground/25"),children:t&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.label}),e.configured&&(0,r.jsx)(as,{status:"ok"})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:e.configured?`via ${e.configuredVia}`:"Not configured"})]}),e.recommended&&(0,r.jsx)("span",{className:"rounded bg-foreground/10 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:"Recommended"})]},e.id)})}),eF&&(0,r.jsxs)("div",{className:"space-y-4 border-t border-border/50 pt-3",children:[(0,r.jsx)("div",{className:"flex items-center justify-between",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:eF.label}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:eF.configuredVia??"Not configured"})]})}),eF.supports.apiKey&&(0,r.jsx)("form",{className:"space-y-3",onSubmit:e=>{e.preventDefault(),e2.trim()&&V(eF.id,e2)},children:(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e1.p,{type:"password",autoComplete:"off",value:e2,onChange:e=>ef(t=>({...t,[eF.id]:e.target.value})),placeholder:"Paste API key",className:"h-8 flex-1 text-xs",disabled:eM,"data-testid":"command-surface-api-key-input"}),(0,r.jsxs)(J,{type:"submit",size:"sm",disabled:!e2.trim()||eM,"data-testid":"command-surface-save-api-key",className:"h-8 gap-1.5",children:["save_api_key"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(tA.A,{className:"h-3.5 w-3.5"}),"Save"]})]})}),(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[eF.supports.oauth&&eF.supports.oauthAvailable&&(0,r.jsxs)(J,{type:"button",variant:"outline",size:"sm",disabled:eM,onClick:()=>void H(eF.id),"data-testid":"command-surface-start-provider-flow",className:"h-8 gap-1.5 text-xs",children:["start_provider_flow"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(su.A,{className:"h-3.5 w-3.5"}),"Browser sign-in"]}),(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",disabled:eM,onClick:()=>void X(eF.id),"data-testid":"command-surface-logout-provider",className:"h-8 gap-1.5 text-xs text-destructive hover:text-destructive",children:["logout_provider"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(R.A,{className:"h-3.5 w-3.5"}),"Logout"]})]}),el&&el.providerId===eF.id&&(0,r.jsxs)("div",{className:"space-y-3 rounded-lg border border-foreground/10 bg-foreground/[0.03] px-4 py-3","data-testid":"command-surface-active-flow",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,r.jsx)(tN,{variant:"outline",className:"text-[10px]",children:el.status.replaceAll("_"," ")}),(0,r.jsx)("span",{className:"text-muted-foreground",children:new Date(el.updatedAt).toLocaleTimeString()})]}),el.auth?.instructions&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:el.auth.instructions}),el.auth?.url&&(0,r.jsx)(J,{asChild:!0,variant:"outline",size:"sm",className:"h-7 gap-1.5 text-xs","data-testid":"command-surface-open-auth-url",children:(0,r.jsxs)("a",{href:el.auth.url,target:"_blank",rel:"noreferrer",children:[(0,r.jsx)(tE.A,{className:"h-3 w-3"}),"Open sign-in page"]})}),el.progress.length>0&&(0,r.jsx)("div",{className:"space-y-1",children:el.progress.map((e,t)=>(0,r.jsx)("div",{className:"rounded-md border border-border/50 bg-card/50 px-2.5 py-1.5 text-xs text-muted-foreground",children:e},`${el.flowId}-${t}`))}),el.prompt&&(0,r.jsxs)("form",{className:"space-y-2",onSubmit:e=>{e.preventDefault(),(el.prompt?.allowEmpty||eb.trim())&&Y(el.flowId,eb)},children:[(0,r.jsx)(e1.p,{value:eb,onChange:e=>ev(e.target.value),placeholder:el.prompt.placeholder||"Enter value",className:"h-8 text-xs",disabled:eM,"data-testid":"command-surface-flow-input"}),(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground",children:el.prompt.message}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)(J,{type:"submit",size:"sm",disabled:eM||!el.prompt.allowEmpty&&!eb.trim(),className:"h-7 gap-1.5 text-xs",children:["submit_provider_flow_input"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"}):(0,r.jsx)(ty.A,{className:"h-3 w-3"}),"Continue"]}),(0,r.jsx)(J,{type:"button",variant:"ghost",size:"sm",disabled:eM,onClick:()=>void Q(el.flowId),className:"h-7 text-xs",children:"Cancel"})]})]})]}),"idle"!==eo.bridgeAuthRefresh.phase&&(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 text-xs",children:[(0,r.jsx)("span",{className:"font-medium text-foreground",children:"Auth refresh"}),(0,r.jsx)("span",{className:"ml-2 text-muted-foreground",children:"pending"===eo.bridgeAuthRefresh.phase?"Refreshing…":"failed"===eo.bridgeAuthRefresh.phase?eo.bridgeAuthRefresh.error||"Failed.":"Complete."})]})]})]}):null;case"admin":return(0,r.jsxs)("div",{className:"space-y-5","data-testid":"command-surface-admin",children:[(0,r.jsx)(ar,{title:"Admin",status:(0,r.jsx)(tN,{variant:"outline",className:"border-warning/20 bg-warning/[0.06] text-[10px] text-warning",children:"Dev only"})}),(0,r.jsx)(an,{label:"UI overrides",description:"Enable keyboard shortcuts and forced UI states for development",checked:e3.enabled,onCheckedChange:e3.setEnabled,testId:"admin-ui-overrides-master"}),e3.enabled&&(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border border-border/50 bg-card/50 p-3",children:[(0,r.jsx)("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Override shortcuts"}),tc.map(e=>(0,r.jsxs)("div",{className:"flex items-start justify-between gap-3 rounded-md px-3 py-2.5 transition-colors hover:bg-foreground/[0.03]",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:e.label}),(0,r.jsx)(tN,{variant:"outline",className:"border-border font-mono text-[10px] text-muted-foreground",children:e.shortcutLabel})]}),(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:e.description})]}),(0,r.jsx)(sx,{checked:e3.overrides[e.key],onCheckedChange:()=>e3.toggle(e.key),"data-testid":`admin-override-${e.key}`})]},e.key))]}),(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 p-3 space-y-3",children:[(0,r.jsx)("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Onboarding"}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 px-3 py-2.5",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Run setup wizard"}),(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"Opens the full onboarding flow as a new user would see it."})]}),(0,r.jsx)(J,{type:"button",size:"sm",className:"h-8 shrink-0 gap-1.5 text-xs",onClick:()=>{c(),window.setTimeout(()=>{e3.enabled||e3.setEnabled(!0),e3.overrides.forceOnboarding||e3.toggle("forceOnboarding")},150)},"data-testid":"admin-trigger-onboarding",children:"Launch"})]})]}),(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 text-xs text-muted-foreground",children:["This tab is only visible when running via"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-[11px]",children:"npm run gsd:web"}),". Overrides reset on page refresh."]})]});case"git":let e;return e=ed.result,(0,r.jsxs)("div",{className:"space-y-5","data-testid":"command-surface-git-summary",children:[(0,r.jsx)("div",{className:"text-xs text-muted-foreground","data-testid":"command-surface-git-state",children:eB?"Loading git summary…":ed.error?"Git summary failed":e?.kind==="not_repo"?"No git repository":e?.kind==="repo"?`Repo ready${e.hasChanges?" — changes detected":" — clean"}`:"Git summary idle"}),eB&&!e&&(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center gap-3 py-16",children:[(0,r.jsx)(F.A,{className:"h-5 w-5 animate-spin text-muted-foreground"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"Loading repo state…"})]}),ed.error&&(0,r.jsx)("div",{className:"rounded-lg border border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive","data-testid":"command-surface-git-error",children:ed.error}),!ed.error&&e?.kind==="not_repo"&&(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 py-16 text-center","data-testid":"command-surface-git-not-repo",children:[(0,r.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-full border border-border/50 bg-card/50",children:(0,r.jsx)(C.A,{className:"h-4.5 w-4.5 text-muted-foreground"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:"No Git repository"}),(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:e.message})]})]}),!ed.error&&e?.kind==="repo"&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"font-mono",children:(0,Z.nf)(e.project.repoRoot,3)}),e.project.repoRelativePath&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(P.A,{className:"h-3 w-3 text-muted-foreground"}),(0,r.jsx)("span",{className:"font-mono",children:e.project.repoRelativePath})]})]}),(0,r.jsx)("div",{className:"grid grid-cols-4 gap-1.5","data-testid":"command-surface-git-counts",children:[{label:"Staged",count:e.counts.staged,active:e.counts.staged>0,color:"text-success"},{label:"Modified",count:e.counts.dirty,active:e.counts.dirty>0,color:"text-warning"},{label:"Untracked",count:e.counts.untracked,active:e.counts.untracked>0,color:"text-muted-foreground"},{label:"Conflicts",count:e.counts.conflicts,active:e.counts.conflicts>0,color:"text-destructive"}].map(({label:e,count:t,active:s,color:a})=>(0,r.jsxs)("div",{className:(0,M.cn)("rounded-md border px-2 py-2 text-center transition-colors",s?"border-border bg-card":"border-border/50 bg-card/50"),children:[(0,r.jsx)("div",{className:(0,M.cn)("text-base font-semibold tabular-nums leading-none",s?a:"text-muted-foreground"),children:t}),(0,r.jsx)("div",{className:(0,M.cn)("mt-1.5 text-[10px] leading-none","text-muted-foreground"),children:e})]},e))}),e.changedFiles.length>0&&(0,r.jsxs)("div",{"data-testid":"command-surface-git-files",children:[(0,r.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-[11px] font-medium uppercase tracking-[0.06em] text-muted-foreground",children:"Changes"}),(0,r.jsxs)("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[e.changedFiles.length,e.truncatedFileCount>0?`+${e.truncatedFileCount}`:""," files"]})]}),(0,r.jsx)("div",{className:"space-y-px rounded-lg border border-border/50 bg-card/50 overflow-hidden",children:e.changedFiles.map(e=>(0,r.jsxs)("div",{className:"group flex items-center gap-2.5 px-3 py-2 transition-colors hover:bg-foreground/[0.03]",children:[(0,r.jsx)("span",{className:(0,M.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded text-[10px] font-semibold",(e=>{switch(e){case"M":return"text-warning bg-warning/10";case"A":return"text-success bg-success/10";case"D":case"U":return"text-destructive bg-destructive/10";case"R":case"C":return"text-info bg-info/10";default:return"text-muted-foreground bg-foreground/5"}})(e.status)),children:e.status}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-foreground/80",children:e.path}),e.conflict&&(0,r.jsx)("span",{className:"shrink-0 rounded bg-destructive/15 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-destructive",children:"conflict"})]},`${e.status}:${e.repoPath}`))}),e.truncatedFileCount>0&&(0,r.jsxs)("p",{className:"mt-1.5 text-center text-[11px] text-muted-foreground",children:["+",e.truncatedFileCount," more files not shown"]})]}),0===e.changedFiles.length&&(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2 py-8 text-center",children:[(0,r.jsx)(eZ.A,{className:"h-4 w-4 text-success/60"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"Working tree clean"})]})]})]});case"resume":return ts("resume");case"name":return ts("name");case"fork":return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-fork",children:[(0,r.jsx)(ar,{title:"Fork",action:(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void G(),disabled:eW,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3","load_fork_messages"===ei.pendingAction&&"animate-spin")}),"Refresh"]})}),eW&&0===ei.forkMessages.length?(0,r.jsxs)("div",{className:"flex items-center gap-2 py-6 text-xs text-muted-foreground",children:[(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading fork points…"]}):ei.forkMessages.length>0?(0,r.jsx)("div",{className:"space-y-1",children:ei.forkMessages.map(e=>{let t=eE?.entryId===e.entryId;return(0,r.jsxs)("button",{type:"button",className:(0,M.cn)("flex w-full items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors",t?"bg-foreground/[0.07]":"hover:bg-foreground/[0.03]"),onClick:()=>x({kind:"fork",entryId:e.entryId}),children:[(0,r.jsx)("div",{className:(0,M.cn)("mt-1 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",t?"border-foreground bg-foreground":"border-foreground/25"),children:t&&(0,r.jsx)(eZ.A,{className:"h-2.5 w-2.5 text-background"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:"font-mono text-[10px] text-muted-foreground",children:e.entryId}),(0,r.jsx)("p",{className:"mt-0.5 text-sm text-foreground",children:e.text})]})]},e.entryId)})}):(0,r.jsx)("p",{className:"py-4 text-center text-xs text-muted-foreground",children:"No fork points available yet."}),(0,r.jsx)("div",{className:"flex justify-end border-t border-border/50 pt-3",children:(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>eE?.entryId&&void W(eE.entryId),disabled:!eE?.entryId||"fork_session"===ei.pendingAction,"data-testid":"command-surface-apply-fork",className:"h-8 gap-1.5",children:["fork_session"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(C.A,{className:"h-3.5 w-3.5"}),"Create fork"]})})]});case"session":return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-session",children:[(0,r.jsx)(ar,{title:"Session",status:(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:ep??"pending"}),action:(0,r.jsxs)(J,{type:"button",variant:"ghost",size:"sm",onClick:()=>void U(),disabled:eK,className:"h-7 gap-1.5 text-xs",children:[(0,r.jsx)(sa.A,{className:(0,M.cn)("h-3 w-3","load_session_stats"===ei.pendingAction&&"animate-spin")}),"Refresh"]})}),ei.sessionStats?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{label:"Input",value:(0,Z._y)(ei.sessionStats.tokens.input)},{label:"Output",value:(0,Z._y)(ei.sessionStats.tokens.output)},{label:"Total",value:(0,Z._y)(ei.sessionStats.tokens.total)}].map(({label:e,value:t})=>(0,r.jsxs)("div",{className:"rounded-lg border border-border/50 bg-card/50 px-3 py-2.5 text-center",children:[(0,r.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:e}),(0,r.jsx)("div",{className:"mt-1 text-sm font-semibold tabular-nums text-foreground",children:t})]},e))}),(0,r.jsxs)("div",{className:"divide-y divide-border/30 rounded-lg border border-border/50 bg-card/50",children:[(0,r.jsxs)("div",{className:"px-4 py-2",children:[(0,r.jsx)(aa,{label:"User messages",children:ei.sessionStats.userMessages}),(0,r.jsx)(aa,{label:"Assistant messages",children:ei.sessionStats.assistantMessages}),(0,r.jsx)(aa,{label:"Tool calls",children:ei.sessionStats.toolCalls}),(0,r.jsx)(aa,{label:"Tool results",children:ei.sessionStats.toolResults})]}),(0,r.jsxs)("div",{className:"px-4 py-2",children:[(0,r.jsx)(aa,{label:"Total messages",children:ei.sessionStats.totalMessages}),(0,r.jsx)(aa,{label:"Cost",children:(0,Z.BD)(ei.sessionStats.cost)}),ei.sessionStats.tokens.cacheRead>0&&(0,r.jsx)(aa,{label:"Cache read",children:(0,Z._y)(ei.sessionStats.tokens.cacheRead)})]})]})]}):(0,r.jsx)("p",{className:"py-4 text-center text-xs text-muted-foreground",children:"Refresh to load session stats."}),(0,r.jsxs)("div",{className:"space-y-3 border-t border-border/50 pt-3",children:[(0,r.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:"Export"}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(e1.p,{value:eP?.outputPath??"",onChange:e=>x({kind:"session",outputPath:e.target.value}),placeholder:"Output path (optional)",className:"h-8 flex-1 text-xs",disabled:"export_html"===ei.pendingAction,"data-testid":"command-surface-export-path"}),(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>void z(eP?.outputPath),disabled:"export_html"===ei.pendingAction,"data-testid":"command-surface-export-session",className:"h-8 gap-1.5",children:["export_html"===ei.pendingAction?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(sc.A,{className:"h-3.5 w-3.5"}),"Export HTML"]})]})]})]});case"compact":return(0,r.jsxs)("div",{className:"space-y-4","data-testid":"command-surface-compact",children:[(0,r.jsx)(ar,{title:"Manual compact",status:eY?(0,r.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-warning",children:[(0,r.jsx)(F.A,{className:"h-3 w-3 animate-spin"})," Working"]}):null}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-muted-foreground",htmlFor:"command-surface-compact-instructions",children:"Custom instructions"}),(0,r.jsx)(te,{id:"command-surface-compact-instructions","data-testid":"command-surface-compact-instructions",value:e_?.customInstructions??"",onChange:e=>x({kind:"compact",customInstructions:e.target.value}),placeholder:"Tell compaction what to preserve or emphasize…",rows:4,disabled:eY,className:"text-xs"})]}),(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsxs)(J,{type:"button",size:"sm",onClick:()=>void K(e_?.customInstructions),disabled:eY,"data-testid":"command-surface-apply-compact",className:"h-8 gap-1.5",children:[eY?(0,r.jsx)(F.A,{className:"h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(sr.A,{className:"h-3.5 w-3.5"}),"Compact now"]})}),ei.lastCompaction&&(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border border-border/50 bg-card/50 px-4 py-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Last compaction"}),(0,r.jsxs)("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[(0,Z._y)(ei.lastCompaction.tokensBefore)," before"]})]}),(0,r.jsx)("p",{className:"whitespace-pre-wrap text-xs text-foreground",children:ei.lastCompaction.summary}),(0,r.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:["First kept: ",ei.lastCompaction.firstKeptEntryId]})]})]});case"workspace":return(0,r.jsx)(rq,{});case"integrations":return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(rp,{}),(0,r.jsx)(rb,{})]});case"gsd-forensics":return(0,r.jsx)(sk,{});case"gsd-doctor":return(0,r.jsx)(sA,{});case"gsd-skill-health":return(0,r.jsx)(sT,{});case"gsd-knowledge":return(0,r.jsx)(sQ,{initialTab:"knowledge"});case"gsd-capture":case"gsd-triage":return(0,r.jsx)(sQ,{initialTab:"captures"});case"gsd-prefs":return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(rq,{}),(0,r.jsx)(ro,{}),(0,r.jsx)(rc,{}),(0,r.jsx)(rm,{}),(0,r.jsx)(rp,{}),(0,r.jsx)(rb,{}),(0,r.jsx)(rk,{}),(0,r.jsx)(rA,{})]});case"gsd-mode":return(0,r.jsx)(rc,{});case"gsd-config":return(0,r.jsx)(rm,{});case"gsd-quick":return(0,r.jsx)(rZ,{});case"gsd-history":return(0,r.jsx)(rX,{});case"gsd-undo":return(0,r.jsx)(r0,{});case"gsd-steer":return(0,r.jsx)(r1,{});case"gsd-hooks":return(0,r.jsx)(r5,{});case"gsd-inspect":return(0,r.jsx)(r2,{});case"gsd-report":case"gsd-export":return(0,r.jsx)(r3,{});case"gsd-cleanup":return(0,r.jsx)(r4,{});case"gsd-queue":return(0,r.jsx)(r8,{});default:if(ei.section?.startsWith("gsd-"))return(0,r.jsxs)("div",{className:"p-4 text-sm text-muted-foreground","data-testid":`gsd-surface-${ei.section}`,children:[(0,r.jsxs)("p",{className:"font-medium text-foreground",children:["/gsd ",ei.section.slice(4)]}),(0,r.jsx)("p",{className:"mt-1",children:"Unknown GSD surface."})]});return null}})()})})]})]})]})})}function al(){let[e,t]=(0,i.useState)(null),[s,a]=(0,i.useState)(!1),[n,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),d=(0,i.useCallback)(async()=>{try{let e=await (0,eo.tm)("/api/update");if(!e.ok)return;let s=await e.json();t(s)}catch{}},[]);(0,i.useEffect)(()=>{d()},[d]),(0,i.useEffect)(()=>(e?.updateStatus==="running"&&(l.current=setInterval(()=>void d(),3e3)),()=>{l.current&&(clearInterval(l.current),l.current=null)}),[e?.updateStatus,d]);let c=async()=>{a(!0);try{let e=await (0,eo.tm)("/api/update",{method:"POST"});e.ok||202===e.status?await d():409===e.status&&await d()}catch{}finally{a(!1)}};if(!e||!e.updateAvailable&&"idle"===e.updateStatus||n)return null;let u="running"===e.updateStatus,m="success"===e.updateStatus,h="error"===e.updateStatus,x=e.targetVersion??e.latestVersion;return(0,r.jsxs)("div",{"data-testid":"update-banner",className:(0,M.cn)("flex items-center gap-3 border-b px-4 py-2 text-xs",m&&"border-success/20 bg-success/10 text-success",h&&"border-destructive/20 bg-destructive/10 text-destructive",!m&&!h&&"border-warning/20 bg-warning/10 text-warning"),children:[m?(0,r.jsxs)("span",{className:"flex-1","data-testid":"update-banner-message",children:["Update complete — restart GSD to use v",x]}):h?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{className:"flex-1","data-testid":"update-banner-message",children:["Update failed",e.error?`: ${e.error}`:""]}),(0,r.jsx)("button",{onClick:()=>void c(),disabled:s,className:(0,M.cn)("flex-shrink-0 rounded border border-destructive/30 bg-background px-2 py-0.5 text-xs font-medium text-destructive transition-colors hover:bg-destructive/10",s&&"cursor-not-allowed opacity-50"),"data-testid":"update-banner-retry",children:"Retry"})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"flex-1","data-testid":"update-banner-message",children:u?(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)(ad,{}),"Updating to v",x,"…"]}):(0,r.jsxs)(r.Fragment,{children:["Update available: v",e.currentVersion," → v",e.latestVersion]})}),!u&&(0,r.jsx)("button",{onClick:()=>void c(),disabled:s,className:(0,M.cn)("flex-shrink-0 rounded border border-warning/30 bg-background px-2 py-0.5 text-xs font-medium text-warning transition-colors hover:bg-warning/10",s&&"cursor-not-allowed opacity-50"),"data-testid":"update-banner-action",children:"Update"})]}),(0,r.jsx)("button",{onClick:()=>o(!0),"aria-label":"Dismiss update banner",className:"flex-shrink-0 rounded p-0.5 opacity-50 transition-opacity hover:opacity-100","data-testid":"update-banner-dismiss",children:(0,r.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}function ad(){return(0,r.jsxs)("svg",{className:"h-3 w-3 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,r.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,r.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}let ac=new Set(["dashboard","power","chat","roadmap","files","activity","visualize"]),au=()=>(0,r.jsx)("div",{className:"h-full w-full p-4",children:(0,r.jsx)(ei,{className:"h-full w-full"})}),am=(0,n.default)(()=>s.e(2772).then(s.bind(s,72772)).then(e=>e.Roadmap),{loadableGenerated:{webpack:()=>[72772]},loading:au,ssr:!1}),ah=(0,n.default)(()=>Promise.all([s.e(5745),s.e(4872),s.e(3211),s.e(3050),s.e(8785),s.e(5826)]).then(s.bind(s,5826)).then(e=>e.FilesView),{loadableGenerated:{webpack:()=>[5826]},loading:au,ssr:!1}),ax=(0,n.default)(()=>s.e(2659).then(s.bind(s,82659)).then(e=>e.ActivityView),{loadableGenerated:{webpack:()=>[82659]},loading:au,ssr:!1}),ap=(0,n.default)(()=>Promise.all([s.e(4872),s.e(4283)]).then(s.bind(s,54283)).then(e=>e.VisualizerView),{loadableGenerated:{webpack:()=>[54283]},loading:au,ssr:!1}),ag=(0,n.default)(()=>s.e(3616).then(s.bind(s,3616)).then(e=>e.DualTerminal),{loadableGenerated:{webpack:()=>[3616]},loading:au,ssr:!1}),af=(0,n.default)(()=>Promise.all([s.e(3211),s.e(8785)]).then(s.bind(s,18785)).then(e=>e.ChatMode),{loadableGenerated:{webpack:()=>[18785]},loading:au,ssr:!1});function ab(e){return`gsd-active-view:${e}`}function av(){let[e,t]=(0,i.useState)("dashboard"),[s,n]=(0,i.useState)(!1),[u,m]=(0,i.useState)(300),[h,x]=(0,i.useState)(!1),p=(0,i.useRef)(!1),g=(0,i.useRef)(!1),f=(0,i.useRef)(0),b=(0,i.useRef)(0),[v,j]=(0,i.useState)(256),y=(0,i.useRef)(!1),w=(0,i.useRef)(0),N=(0,i.useRef)(0),[S,k]=(0,i.useState)(!1),[C,A]=(0,i.useState)(!1),[R,T]=(0,i.useState)(!1),[E,P]=(0,i.useState)(!1),[_,I]=(0,i.useState)(!1),F=(0,Z.gF)(),{refreshBoot:$}=(0,Z._l)(),L=(0,Z.tM)(F),D=F.boot?.project.cwd,q=(0,Z.$9)(D),B=F.titleOverride?.trim()||null,O=(0,Z.U4)(F.boot?.workspace),U=(0,Z.QC)(F);(0,i.useEffect)(()=>{if(C||!D)return;let e=window.setTimeout(()=>{try{let e=sessionStorage.getItem(ab(D));e&&ac.has(e)&&t(e)}catch{}A(!0)},0);return()=>window.clearTimeout(e)},[D,C]);let z=(0,i.useRef)(D);(0,i.useEffect)(()=>{z.current!==D&&(z.current=D,A(!1))},[D]),(0,i.useEffect)(()=>{if(D)try{sessionStorage.setItem(ab(D),e)}catch{}},[e,D]),(0,i.useEffect)(()=>{let e=window.setTimeout(()=>{try{let e=localStorage.getItem("gsd-sidebar-collapsed");"true"===e&&k(!0)}catch{}},0);return()=>window.clearTimeout(e)},[]),(0,i.useEffect)(()=>{try{localStorage.setItem("gsd-sidebar-collapsed",String(S))}catch{}},[S]),(0,i.useEffect)(()=>{if("u"<typeof document)return;let e=q?`GSD - ${q}`:"GSD";document.title=B?`${B} \xb7 ${e}`:e},[B,q]);let G=(0,i.useCallback)(e=>{t(e),P(!1)},[]);(0,i.useEffect)(()=>{let e=()=>{t("files")};return window.addEventListener("gsd:open-file",e),()=>window.removeEventListener("gsd:open-file",e)},[]),(0,i.useEffect)(()=>{let e=e=>{ac.has(e.detail.view)&&G(e.detail.view)};return window.addEventListener("gsd:navigate-view",e),()=>window.removeEventListener("gsd:navigate-view",e)},[G]),(0,i.useEffect)(()=>{let e=()=>T(!0);return window.addEventListener("gsd:open-projects",e),()=>window.removeEventListener("gsd:open-projects",e)},[]),(0,i.useEffect)(()=>{let e=e=>{if(p.current){g.current=!0;let t=f.current-e.clientY;m(Math.max(150,Math.min(600,b.current+t)))}if(y.current){let t=w.current-e.clientX;j(Math.max(180,Math.min(480,N.current+t)))}},t=()=>{p.current=!1,y.current=!1,x(!1),document.body.style.cursor="",document.body.style.userSelect=""};return document.addEventListener("mousemove",e),document.addEventListener("mouseup",t),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",t)}},[]);let W=(0,i.useCallback)(e=>{p.current=!0,x(!0),f.current=e.clientY,b.current=u,document.body.style.cursor="row-resize",document.body.style.userSelect="none"},[u]),K=(0,i.useCallback)(e=>{y.current=!0,w.current=e.clientX,N.current=v,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[v]),V=!!F.commandInFlight||"idle"!==F.onboardingRequestState,H="idle"===F.bootStatus||"loading"===F.bootStatus;(0,i.useEffect)(()=>{if(!H)return;let e=sm.oR.loading("Connecting to workspace…",{description:"Establishing the live bridge session",duration:1/0});return()=>{sm.oR.dismiss(e)}},[H]);let Y=F.boot?.projectDetection,J=!H&&"dashboard"===e&&null!=Y&&"active-gsd"!==Y.kind&&"empty-gsd"!==Y.kind;return"unauthenticated"===F.bootStatus?(0,r.jsxs)("div",{className:"flex h-dvh flex-col items-center justify-center gap-6 bg-background p-8 text-center",children:[(0,r.jsx)(a.default,{src:"/logo-black.svg",alt:"GSD-Pi Web",width:57,height:16,className:"shrink-0 h-4 w-auto dark:hidden"}),(0,r.jsx)(a.default,{src:"/logo-white.svg",alt:"GSD-Pi Web",width:57,height:16,className:"shrink-0 h-4 w-auto hidden dark:block"}),(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,r.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Authentication Required"}),(0,r.jsxs)("p",{className:"max-w-sm text-sm text-muted-foreground",children:["This workspace requires an auth token. Copy the full URL from your terminal (including the"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"#token=…"})," ","part) or restart with"," ",(0,r.jsx)("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"gsd --web"}),"."]})]})]}):(0,r.jsxs)("div",{className:"relative flex h-screen flex-col overflow-hidden bg-background text-foreground",children:[(0,r.jsxs)("header",{className:"flex h-12 flex-shrink-0 items-center justify-between border-b border-border bg-card px-2 md:px-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 md:gap-3 min-w-0",children:[(0,r.jsx)("button",{className:"flex md:hidden h-10 w-10 items-center justify-center rounded-md text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors",onClick:()=>P(!E),"aria-label":E?"Close navigation":"Open navigation","data-testid":"mobile-nav-toggle",children:(0,r.jsx)("span",{className:"relative flex h-5 w-5 items-center justify-center",children:(0,r.jsx)(d.N,{mode:"wait",initial:!1,children:(0,r.jsx)(c.P.span,{className:"absolute inset-0 flex items-center justify-center",initial:{opacity:0,scale:.25,filter:"blur(4px)"},animate:{opacity:1,scale:1,filter:"blur(0px)"},exit:{opacity:0,scale:.25,filter:"blur(4px)"},transition:{type:"spring",duration:.3,bounce:0},children:E?(0,r.jsx)(o.A,{className:"h-5 w-5"}):(0,r.jsx)(l.A,{className:"h-5 w-5"})},E?"close":"open")})})}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(a.default,{src:"/logo-black.svg",alt:"GSD-Pi Web",width:57,height:16,className:"shrink-0 h-4 w-auto dark:hidden"}),(0,r.jsx)(a.default,{src:"/logo-white.svg",alt:"GSD-Pi Web",width:57,height:16,className:"shrink-0 h-4 w-auto hidden dark:block"}),(0,r.jsx)(tN,{variant:"outline",className:"hidden sm:inline-flex text-[10px] rounded-full border-foreground/15 bg-accent/40 text-muted-foreground font-normal",children:"beta"})]}),(0,r.jsx)("span",{className:"hidden sm:inline text-2xl font-thin text-muted-foreground leading-none select-none",children:"/"}),(0,r.jsx)("span",{className:"hidden sm:inline text-sm text-muted-foreground truncate","data-testid":"workspace-project-cwd",title:D??void 0,children:H?(0,r.jsx)(ei,{className:"inline-block h-4 w-28 align-middle"}):(0,r.jsxs)(r.Fragment,{children:[q,B&&(0,r.jsx)("span",{className:"ml-2 inline-flex items-center rounded-full border border-foreground/15 bg-accent/60 px-2 py-0.5 text-[10px] font-medium text-foreground","data-testid":"workspace-title-override",title:B,children:B})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 md:gap-3",children:[(0,r.jsx)("span",{className:"sr-only","data-testid":"workspace-connection-status",children:L.label}),(0,r.jsx)("span",{className:"hidden sm:inline text-xs text-muted-foreground","data-testid":"workspace-scope-label",children:H?(0,r.jsx)(ei,{className:"inline-block h-3.5 w-40 align-middle"}):(0,r.jsx)(eA,{label:O,size:"sm"})})]})]}),(0,r.jsx)(al,{}),!H&&U&&(0,r.jsxs)("div",{className:"flex items-center gap-3 border-b border-destructive/20 bg-destructive/10 px-4 py-2 text-xs text-destructive","data-testid":"workspace-error-banner",children:[(0,r.jsx)("span",{className:"flex-1",children:U}),(0,r.jsx)("button",{onClick:()=>void $(),disabled:V,className:(0,M.cn)("flex-shrink-0 rounded border border-destructive/30 bg-background px-2 py-0.5 text-xs font-medium text-destructive transition-colors hover:bg-destructive/10",V&&"cursor-not-allowed opacity-50"),children:"Retry"})]}),E&&(0,r.jsx)("div",{className:"fixed inset-0 z-40 bg-black/50 md:hidden",onClick:()=>P(!1),"data-testid":"mobile-nav-overlay"}),(0,r.jsx)("div",{className:(0,M.cn)("fixed inset-y-0 left-0 z-50 w-64 transform bg-sidebar border-r border-border transition-transform duration-200 ease-out md:hidden",E?"translate-x-0":"-translate-x-full"),"data-testid":"mobile-nav-drawer",children:(0,r.jsx)(eh,{activeView:e,onViewChange:H?()=>{}:G,isConnecting:H,mobile:!0})}),_&&(0,r.jsx)("div",{className:"fixed inset-0 z-40 bg-black/50 md:hidden",onClick:()=>I(!1),"data-testid":"mobile-milestone-overlay"}),!J&&(0,r.jsx)("div",{className:(0,M.cn)("fixed inset-y-0 right-0 z-50 w-72 transform bg-sidebar border-l border-border transition-transform duration-200 ease-out md:hidden",_?"translate-x-0":"translate-x-full"),"data-testid":"mobile-milestone-drawer",children:(0,r.jsx)(eu,{isConnecting:H,width:288,onCollapse:()=>I(!1)})}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,r.jsx)("div",{className:"hidden md:flex",children:(0,r.jsx)(eh,{activeView:e,onViewChange:H?()=>{}:G,isConnecting:H})}),(0,r.jsxs)("div",{className:"flex flex-1 flex-col overflow-hidden",children:[(0,r.jsx)("div",{className:(0,M.cn)("flex-1 overflow-hidden transition-[height] duration-200 ease-out",s&&"h-1/3"),children:H?(0,r.jsx)(eB,{}):(0,r.jsxs)(r.Fragment,{children:["dashboard"===e&&(0,r.jsx)(eB,{onSwitchView:G,onExpandTerminal:()=>n(!0)}),"power"===e&&(0,r.jsx)(ag,{}),"roadmap"===e&&(0,r.jsx)(am,{}),"files"===e&&(0,r.jsx)(ah,{}),"activity"===e&&(0,r.jsx)(ax,{}),"visualize"===e&&(0,r.jsx)(ap,{}),"chat"===e&&(0,r.jsx)(af,{})]})}),"power"!==e&&"chat"!==e&&(0,r.jsxs)("div",{className:"border-t border-border flex flex-col",style:{flexShrink:0},children:[(0,r.jsx)("div",{role:"button",tabIndex:0,onClick:()=>{if(g.current){g.current=!1;return}H||n(!s)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),H||n(!s))},className:(0,M.cn)("flex h-8 w-full items-center justify-between bg-card px-3 text-xs select-none transition-colors",s&&"cursor-row-resize",!s&&!H&&"cursor-pointer hover:bg-muted/50",H&&"cursor-default"),onMouseDown:e=>{s&&W(e)},children:(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"font-medium text-foreground",children:"Terminal"}),(0,r.jsx)("span",{className:"text-[10px] text-muted-foreground",children:s?"▼":"▲"})]})}),(0,r.jsx)("div",{className:"overflow-hidden",style:{height:s?u:0,transition:h?"none":"height 200ms"},children:s&&(0,r.jsx)(ep.x,{className:"h-full",projectCwd:F.boot?.project.cwd})})]})]}),!J&&!S&&(0,r.jsxs)("div",{className:"relative hidden md:flex h-full items-stretch",style:{flexShrink:0},children:[(0,r.jsx)("div",{className:"w-px bg-border"}),(0,r.jsx)("div",{className:"absolute left-[-3px] top-0 bottom-0 w-[7px] cursor-col-resize z-10 hover:bg-muted-foreground/20 transition-colors",onMouseDown:K})]}),(0,r.jsx)("div",{className:"hidden md:flex",children:!J&&(S?(0,r.jsx)(em,{onExpand:()=>k(!1)}):(0,r.jsx)(eu,{isConnecting:H,width:v,onCollapse:()=>k(!0)}))})]}),(0,r.jsx)("div",{className:"hidden md:block",children:(0,r.jsx)(eK,{})}),!J&&(0,r.jsxs)("div",{className:"flex md:hidden h-12 items-center justify-between border-t border-border bg-card px-3","data-testid":"mobile-bottom-bar",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground truncate",children:[(0,r.jsx)("span",{className:"sr-only","data-testid":"workspace-connection-status-mobile",children:L.label}),(0,r.jsx)("span",{className:(0,M.cn)("h-2 w-2 rounded-full shrink-0","success"===L.tone?"bg-success":"warning"===L.tone?"bg-warning":"danger"===L.tone?"bg-destructive":"bg-muted-foreground")}),(0,r.jsx)("span",{className:"truncate",children:O})]}),(0,r.jsx)("button",{onClick:()=>I(!_),className:"flex h-10 items-center gap-2 rounded-md px-3 text-xs font-medium text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors","data-testid":"mobile-milestone-toggle",children:"Milestones"})]}),(0,r.jsx)(r$,{open:R,onOpenChange:T}),(0,r.jsx)(ao,{}),(0,r.jsx)(tl,{}),(0,r.jsx)(t9,{})]})}function aj(){return(0,eo.c4)(),(0,r.jsx)(ea,{children:(0,r.jsx)(ay,{})})}function ay(){let e=en(),t=(0,i.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot),s=t?e.getActiveStore():null,a=(0,i.useRef)(!1);return((0,i.useEffect)(()=>{if(a.current||e.getActiveProjectCwd())return;let t=new AbortController;return(async()=>{try{let s=await (0,eo.tm)("/api/preferences",{signal:t.signal});if(!s.ok)return;let r=await s.json();a.current=!0,r.launchCwd&&!e.getActiveProjectCwd()&&e.switchProject(r.launchCwd)}catch(e){if("AbortError"===e.name)return}})(),()=>t.abort()},[e]),(0,i.useEffect)(()=>{let e=e=>{if(e.persisted)return;let t=(0,eo.c4)(),s=t?`/api/shutdown?_token=${t}`:"/api/shutdown";navigator.sendBeacon(s,"")};return window.addEventListener("pagehide",e),()=>{window.removeEventListener("pagehide",e)}},[]),t&&s)?(0,r.jsx)(Z.jg,{store:s,children:(0,r.jsx)(th,{children:(0,r.jsx)(av,{})})}):(0,r.jsx)(rB,{})}},93058:(e,t,s)=>{s.d(t,{jg:()=>ex,Hu:()=>em,fL:()=>eu,Sf:()=>eb,BD:()=>Y,a3:()=>V,_y:()=>H,E3:()=>Q,U4:()=>J,Ct:()=>Z,CL:()=>E,Gr:()=>T,iT:()=>ee,$9:()=>K,_0:()=>X,tM:()=>ec,QC:()=>ed,nf:()=>W,_l:()=>ef,gF:()=>eg});var r=s(18870),a=s(45110);let n=new Map([{name:"settings",description:"Open settings menu"},{name:"model",description:"Select model (opens selector UI)"},{name:"scoped-models",description:"Enable/disable models for Ctrl+P cycling"},{name:"export",description:"Export session (HTML default, or specify path: .html/.jsonl)"},{name:"import",description:"Import and resume a session from a JSONL file"},{name:"share",description:"Share session as a secret GitHub gist"},{name:"copy",description:"Copy last agent message to clipboard"},{name:"name",description:"Set session display name"},{name:"session",description:"Show session info and stats"},{name:"changelog",description:"Show changelog entries"},{name:"hotkeys",description:"Show all keyboard shortcuts"},{name:"fork",description:"Create a new fork from a previous user message"},{name:"clone",description:"Duplicate the current session at the current position"},{name:"tree",description:"Navigate session tree (switch branches)"},{name:"login",description:"Configure provider authentication"},{name:"logout",description:"Remove provider authentication"},{name:"new",description:"Start a new session"},{name:"compact",description:"Manually compact the session context"},{name:"resume",description:"Resume a different session"},{name:"reload",description:"Reload keybindings, extensions, skills, prompts, and themes"},{name:"quit",description:"Quit pi"}].map(e=>[e.name,e.description])),i=new Set(n.keys()),o=new Map([["settings","settings"],["model","model"],["thinking","thinking"],["git","git"],["resume","resume"],["name","name"],["fork","fork"],["compact","compact"],["login","login"],["logout","logout"],["session","session"],["export","export"]]),l=new Map([["visualize","gsd-visualize"],["forensics","gsd-forensics"],["doctor","gsd-doctor"],["skill-health","gsd-skill-health"],["knowledge","gsd-knowledge"],["capture","gsd-capture"],["triage","gsd-triage"],["quick","gsd-quick"],["history","gsd-history"],["undo","gsd-undo"],["inspect","gsd-inspect"],["model","model"],["prefs","gsd-prefs"],["config","gsd-config"],["hooks","gsd-hooks"],["mode","gsd-mode"],["steer","gsd-steer"],["report","gsd-report"],["export","gsd-export"],["cleanup","gsd-cleanup"],["queue","gsd-queue"]]),d=new Set(["auto","next","stop","pause","skip","discuss","run-hook","migrate","remote"]),c=`Available /gsd subcommands:
|
|
3
|
-
|
|
4
|
-
Workflow: next \xb7 auto \xb7 stop \xb7 pause \xb7 skip \xb7 queue \xb7 quick \xb7 capture \xb7 triage
|
|
5
|
-
Diagnostics: status \xb7 visualize \xb7 forensics \xb7 doctor \xb7 skill-health \xb7 inspect
|
|
6
|
-
Context: knowledge \xb7 history \xb7 undo \xb7 discuss
|
|
7
|
-
Settings: model \xb7 prefs \xb7 config \xb7 hooks \xb7 mode \xb7 steer
|
|
8
|
-
Advanced: report \xb7 export \xb7 cleanup \xb7 run-hook \xb7 migrate \xb7 remote
|
|
9
|
-
|
|
10
|
-
Type /gsd <subcommand> to run. Use /gsd help for this message.`;function u(e){return e.isStreaming?"follow_up":"prompt"}function m(e,t={}){let s=e.trim(),r=function(e){let t=e.trim();if(!t.startsWith("!"))return null;let s=t.startsWith("!!"),r=s?t.slice(2).trim():t.slice(1).trim();return r?{command:r,excludeFromContext:s}:null}(s);if(r)return{kind:"bash",input:s,command:{type:"bash",command:r.command,...r.excludeFromContext?{excludeFromContext:!0}:{}}};let a=function(e){if(!e.startsWith("/"))return null;let t=e.slice(1).trim();if(!t)return null;let s=t.search(/\s/);return -1===s?{name:t,args:""}:{name:t.slice(0,s),args:t.slice(s+1).trim()}}(s);if("/clear"===s)return{kind:"local",input:s,commandName:"clear",action:"clear_terminal"};if("/refresh"===s)return{kind:"local",input:s,commandName:"refresh",action:"refresh_workspace"};if("/state"===s)return{kind:"rpc",input:s,commandName:"state",command:{type:"get_state"}};if("/new-session"===s)return{kind:"rpc",input:s,commandName:"new",command:{type:"new_session"}};if(!a)return{kind:"prompt",input:s,slashCommandName:null,command:{type:u(t),message:s}};if("new"===a.name)return{kind:"rpc",input:s,commandName:"new",command:{type:"new_session"}};if("gsd"===a.name)return function(e,t,s){let r=t.trim(),a=r.search(/\s/),n=-1===a?r:r.slice(0,a),i=-1===a?"":r.slice(a+1).trim();if(!n)return{kind:"prompt",input:e,slashCommandName:"gsd",command:{type:u(s),message:e}};if("help"===n)return{kind:"local",input:e,commandName:"gsd",action:"gsd_help"};if("status"===n||"visualize"===n)return{kind:"view-navigate",input:e,commandName:"gsd",view:"visualize"};let o=l.get(n);return o?{kind:"surface",input:e,commandName:"gsd",surface:o,args:i}:(d.has(n),{kind:"prompt",input:e,slashCommandName:"gsd",command:{type:u(s),message:e}})}(s,a.args,t);let c=o.get(a.name);if(c)return{kind:"surface",input:s,commandName:a.name,surface:c,args:a.args};if(i.has(a.name)){var h,x;let e;return x=h=a.name,e=n.get(x)??"Browser handling is reserved for this built-in command.",{kind:"reject",input:s,commandName:h,reason:`/${h} is a built-in pi command (${e}) that is not available in the browser yet.`,guidance:"It was blocked instead of falling through to the model."}}return{kind:"prompt",input:s,slashCommandName:a.name,command:{type:u(t),message:s}}}function h(e){switch(e.kind){case"surface":return{type:"system",message:`/${e.commandName} is reserved for browser-native handling and was not sent to the model.`};case"reject":return{type:"error",message:`${e.reason} ${e.guidance}`.trim()};default:return null}}var x=s(37144);class p{constructor(e,t=e=>new EventSource(e)){this.eventSource=null,this.lastConnectionState="idle",this.handlers=e,this.createEventSource=t}isOpen(){return null!==this.eventSource}ensure(){if(this.eventSource||!this.handlers.canConnect())return;let e=this.createEventSource(this.handlers.streamUrl());this.eventSource=e,e.onopen=()=>{let e=this.lastConnectionState;this.lastConnectionState="connected",this.handlers.onOpen({previousState:e,wasDisconnected:"reconnecting"===e||"disconnected"===e||"error"===e})},e.onmessage=e=>{this.handlers.onMessage(e.data)},e.onerror=()=>{let e="connected"===this.lastConnectionState?"reconnecting":"error",t=e!==this.lastConnectionState;this.lastConnectionState=e,this.handlers.onError({nextConnectionState:e,changed:t})}}close(){this.eventSource?.close(),this.eventSource=null}}function g(e,t){return{id:`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,type:e,content:t,timestamp:function(e=new Date){return e.toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}()}}function f(e,t){return[...e,t].slice(-250)}var b=s(83890);let v=new Set(["ls","ll","la","pwd","cd","dir","cat","head","tail","wc","file","which","whoami","echo","date","tree","find","grep","rg","clear","env","df","du","uname","hostname","mkdir","rm","cp","mv","touch","chmod","less","more","sort","uniq","sed","awk","curl","wget","tar","zip","unzip","git","docker","npm","npx","yarn","pnpm","node","python","python3","pip","pip3","make","cargo","go","ruby","brew"]);function j(e){let t=e.trimStart(),s=t.search(/\s/);return(-1===s?t:t.slice(0,s)).toLowerCase()}let y=[{id:"shell-command-prefix",maxShows:2,evaluate(e){let t;if(!(!((t=e.input.trimStart()).startsWith("!")||t.startsWith("/")||t.includes("\n")||t.length>120)&&v.has(j(t))))return null;let s=j(e.input);return`Tip: "${s}" looks like a shell command. Prefix with ! to run locally, or !! to run without using tokens.`}},{id:"large-paste",maxShows:2,evaluate:e=>e.input.length<2e3||e.input.trimStart().startsWith("/")||e.input.trimStart().startsWith("!")?null:"Tip: Large inputs consume many tokens. Consider saving to a file and asking the agent to read it."},{id:"thinking-level-high",maxShows:1,evaluate(e){let t=e.thinkingLevel?.toLowerCase();if("high"!==t&&"xhigh"!==t)return null;let s=e.input.trim();return s.length>80||s.includes("\n")||s.startsWith("/")||s.startsWith("!")?null:`Tip: Thinking is set to ${t}. Use Ctrl+T to lower it for simple questions — saves tokens.`}},{id:"double-bang-reminder",maxShows:2,evaluate(e){if(e.bashIncludedCount<3)return null;let t=e.input.trimStart();return!t.startsWith("!")||t.startsWith("!!")?null:"Tip: Use !! instead of ! to keep command output out of agent context and save tokens."}},{id:"compaction-nudge",maxShows:1,evaluate(e){if(void 0===e.contextPercent||e.contextPercent<70)return null;let t=e.input.trimStart();return t.startsWith("/")||t.startsWith("!")?null:"Tip: Context is getting full. Use /compact to summarize the conversation and free up space."}}];class w{recordBashIncluded(){this._bashIncludedCount++}get bashIncludedCount(){return this._bashIncludedCount}evaluate(e){let t={...e,bashIncludedCount:this._bashIncludedCount};for(let e of y){let s=this.showCounts.get(e.id)??0;if(s>=e.maxShows)continue;let r=e.evaluate(t);if(r)return this.showCounts.set(e.id,s+1),r}return null}reset(){this.showCounts.clear(),this._bashIncludedCount=0}constructor(){this.showCounts=new Map,this._bashIncludedCount=0}}function N(){return{status:"idle",stale:!1,reloadCount:0,lastRequestedAt:null,lastSuccessAt:null,lastFailureAt:null,lastFailure:null,invalidatedAt:null,invalidationReason:null,invalidationSource:null}}function S(){return{visible:!1,tone:"healthy",label:"Recovery summary pending",detail:"Waiting for the first live workspace snapshot.",validationCount:0,retryInProgress:!1,retryAttempt:0,autoRetryEnabled:!1,isCompacting:!1,currentUnitId:null,freshness:"idle",entrypointLabel:"Inspect recovery",lastError:null}}function k(e){return{...e,status:"refreshing",lastRequestedAt:new Date().toISOString(),lastFailure:null}}function C(e,t,s){return{...e,status:e.lastSuccessAt?"stale":e.status,stale:!0,invalidatedAt:new Date().toISOString(),invalidationReason:t,invalidationSource:s}}function A(e){return{...e,status:"fresh",stale:!1,reloadCount:e.reloadCount+1,lastSuccessAt:new Date().toISOString(),lastFailureAt:null,lastFailure:null}}function R(e,t){return{...e,status:"error",stale:!0,lastFailureAt:new Date().toISOString(),lastFailure:t}}function T(e){return e.live.workspace??e.boot?.workspace??null}function E(e){return e.live.auto??e.boot?.auto??null}function P(e){return e.live.resumableSessions.length>0?e.live.resumableSessions:e.boot?.resumableSessions??[]}function _(e){let t=e.boot?.bridge??null,s=T(e),r=E(e),a=s?.validationIssues.length??0,n=!!t?.sessionState?.retryInProgress,i=t?.sessionState?.retryAttempt??0,o=!!t?.sessionState?.autoRetryEnabled,l=!!t?.sessionState?.isCompacting,d=e.live.freshness.recovery,c="error"===d.status?"error":d.stale?"stale":d.lastSuccessAt?"fresh":"idle",u=t?.lastError?{message:t.lastError.message,phase:t.lastError.phase,at:t.lastError.at}:null,m="healthy",h="Recovery summary healthy",x="No retry, compaction, bridge, or validation recovery signals are active.";return s||r||t?(u||"error"===c?(m="danger",h="Recovery attention required",x=u?.message??d.lastFailure??"A targeted live refresh failed."):a>0?(m="warning",h=`Recovery summary: ${a} validation issue${1===a?"":"s"}`,x="Workspace validation surfaced issues that may need doctor or audit follow-up."):n?(m="warning",h=`Recovery retry active (attempt ${Math.max(1,i)})`,x="The live bridge is retrying the current unit after a transient failure."):l?(m="warning",h="Recovery compaction active",x="The live session is compacting context before continuing."):"stale"===c&&(m="warning",h="Recovery summary stale",x=d.invalidationReason?`Waiting for a targeted refresh after ${d.invalidationReason.replaceAll("_"," ")}.`:"Waiting for the next targeted refresh."),{visible:!0,tone:m,label:h,detail:x,validationCount:a,retryInProgress:n,retryAttempt:i,autoRetryEnabled:o,isCompacting:l,currentUnitId:r?.currentUnit?.id??null,freshness:c,entrypointLabel:"danger"===m||"warning"===m?"Inspect recovery":"Review recovery",lastError:u}):S()}let I=new Set(["settings","model","thinking","git","resume","name","fork","compact","login","logout","session","export","gsd-visualize","gsd-forensics","gsd-doctor","gsd-skill-health","gsd-knowledge","gsd-capture","gsd-triage","gsd-quick","gsd-history","gsd-undo","gsd-inspect","gsd-prefs","gsd-config","gsd-hooks","gsd-mode","gsd-steer","gsd-report","gsd-export","gsd-cleanup","gsd-queue"]);function F(e){return!!(e?.activeSessionId||e?.sessionState?.sessionId)}function $(e){return e instanceof Error?e.message:String(e)}function L(e){if("failed"===e.phase)return{type:"error",message:`Bridge failed${e.lastError?.message?` — ${e.lastError.message}`:""}`};if("starting"===e.phase)return{type:"system",message:"Bridge starting for the current project…"};if("ready"===e.phase){let t=X(e);return{type:"success",message:t?`Live bridge ready — attached to ${t}`:"Live bridge ready — session attachment pending"}}return{type:"system",message:"Bridge idle"}}let D=new Set(["running","awaiting_browser_auth","awaiting_input"]),M=new Set(["succeeded","failed","cancelled"]);function q(e,t){return e.required.providers.find(e=>e.id===t)?.label??t}function B(e,t){if(!e)return null;let s={...e,bridge:t};return{...s,resumableSessions:ei(s.resumableSessions,s)}}function O(e,t){return e?.bridge.sessionState?B(e,{...e.bridge,sessionState:{...e.bridge.sessionState,...t}}):e}function U(e,t){return e?{...e,onboarding:t,onboardingNeeded:t.locked}:null}function z(e){return"failed"===e.bridgeAuthRefresh.phase?{type:"error",message:e.bridgeAuthRefresh.error?`Bridge auth refresh failed — ${e.bridgeAuthRefresh.error}`:"Bridge auth refresh failed after setup"}:"pending"===e.bridgeAuthRefresh.phase?{type:"system",message:"Credentials saved — refreshing bridge auth before the workspace unlocks…"}:e.lastValidation?.status==="failed"?{type:"error",message:`Credential validation failed — ${e.lastValidation.message}`}:e.locked||e.lastValidation?.status!=="succeeded"?e.activeFlow?.status==="awaiting_browser_auth"?{type:"system",message:`${e.activeFlow.providerLabel} sign-in is waiting for browser confirmation`}:e.activeFlow?.status==="awaiting_input"?{type:"system",message:`${e.activeFlow.providerLabel} sign-in needs one more input step`}:e.activeFlow?.status==="cancelled"?{type:"system",message:`${e.activeFlow.providerLabel} sign-in was cancelled`}:e.activeFlow?.status==="failed"?{type:"error",message:e.activeFlow.error?`${e.activeFlow.providerLabel} sign-in failed — ${e.activeFlow.error}`:`${e.activeFlow.providerLabel} sign-in failed`}:"required_setup"===e.lockReason?{type:"system",message:"Onboarding is still required before model-backed prompts will run"}:null:{type:"success",message:`${q(e,e.lastValidation.providerId)} is ready — workspace unlocked`}}function G(e){let t=[g("system",`GSD web workspace attached to ${e.project.cwd}`),g("system",`Workspace scope: ${J(e.workspace)}`)],s=L(e.bridge);t.push(g(s.type,s.message)),e.bridge.lastError&&t.push(g("error",`Bridge error: ${e.bridge.lastError.message}`));let r=z(e.onboarding);return r&&t.push(g(r.type,r.message)),t}function W(e,t=3){if(!e)return"—";let s=e.split(/[\\/]/).filter(Boolean);if(s.length<=t)return e.startsWith("/")?`/${s.join("/")}`:s.join("/");let r=s.slice(-t).join("/");return`…/${r}`}function K(e){return e?e.split(/[\\/]/).filter(Boolean).at(-1)||e:"Current project"}function V(e){if(!e||e<1e3)return"0m";let t=Math.floor(e/6e4),s=Math.floor(t/60),r=t%60;return s>0?`${s}h ${r}m`:`${r}m`}function H(e){return!Number.isFinite(e)||e<=0?"0":e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}K`:String(Math.round(e))}function Y(e){return!Number.isFinite(e)||e<=0?"$0.00":`$${e.toFixed(2)}`}function J(e){if(!e)return"Project scope pending";let t=[e.active.milestoneId,e.active.sliceId,e.active.taskId].filter(Boolean).join("/");return t?`${t} — ${e.active.phase}`:`project — ${e.active.phase}`}function Q(e){if(!e?.active.milestoneId||!e.active.sliceId)return null;let t=e.milestones.find(t=>t.id===e.active.milestoneId),s=t?.slices.find(t=>t.id===e.active.sliceId);return s?.branch??null}function Z(e){if(!e?.active.milestoneId||!e.active.sliceId)return null;let t=e.milestones.find(t=>t.id===e.active.milestoneId);return t?.slices.find(t=>t.id===e.active.sliceId)??null}function X(e){if(!e?.sessionState&&!e?.activeSessionId)return null;let t=e.sessionState?.sessionName?.trim();return t||(e.activeSessionId?`session ${e.activeSessionId}`:e.sessionState?.sessionId??null)}function ee(e){let t=e?.sessionState?.model;return t&&(t.id||t.providerId||t.provider)||"model pending"}function et(e){let t=e?.sessionState?.model;return t?{provider:t.provider??t.providerId,modelId:t.id}:null}function es(e){if(!e)return null;if(e.required.satisfiedBy?.providerId)return e.required.satisfiedBy.providerId;let t=e.required.providers.find(e=>!e.configured&&e.recommended);if(t)return t.id;let s=e.required.providers.find(e=>!e.configured);return s?s.id:e.required.providers[0]?.id??null}function er(e,t){return{...e,pending:!1,loaded:!1,error:t}}function ea(e,t){return{...e,phase:"error",pending:!1,stale:!0,error:t,lastFailureAt:new Date().toISOString()}}function en(e){return e?.bridge.activeSessionFile??e?.bridge.sessionState?.sessionFile??null}function ei(e,t){let s=en(t),r=t?.bridge.sessionState?.sessionName?.trim()||void 0;return e.map(e=>{let t=s?e.path===s:e.isActive;return{...e,isActive:t,...t&&r?{name:r}:{}}})}function eo(e,t){return{...e,activeSessionPath:en(t),sessions:ei(e.sessions,t)}}function el(e,t,s){return{...e,activeSessionPath:s.isActive?t:e.activeSessionPath,sessions:e.sessions.map(e=>e.path===t?{...e,...s}:s.isActive?{...e,isActive:!1}:e)}}function ed(e){let t=e.boot?.onboarding;return t?.bridgeAuthRefresh.phase==="failed"&&t.bridgeAuthRefresh.error?t.bridgeAuthRefresh.error:t?.lastValidation?.status==="failed"?t.lastValidation.message:e.lastBridgeError?.message??e.lastClientError}function ec(e){if("loading"===e.bootStatus)return{label:"Loading workspace",tone:"info"};if("error"===e.bootStatus)return{label:"Boot failed",tone:"danger"};let t=function(e){if("loading"===e.bootStatus||!e.boot)return{phase:"loading",label:"Loading setup state",detail:"Resolving the current project, bridge, and onboarding contract…",tone:"info"};let t=e.boot.onboarding;return t.activeFlow?.status==="awaiting_browser_auth"?{phase:"awaiting_browser_auth",label:"Continue sign-in in your browser",detail:`${t.activeFlow.providerLabel} is waiting for browser confirmation before the workspace can unlock.`,tone:"info"}:t.activeFlow?.status==="awaiting_input"?{phase:"awaiting_input",label:"One more sign-in step is required",detail:t.activeFlow.prompt?.message??`${t.activeFlow.providerLabel} needs one more input step.`,tone:"info"}:"bridge_refresh_pending"===t.lockReason?{phase:"refreshing",label:"Refreshing bridge auth",detail:"Credentials validated. The live bridge is restarting onto the new auth view before the shell unlocks.",tone:"info"}:"bridge_refresh_failed"===t.lockReason?{phase:"failure",label:"Setup completed, but the shell is still locked",detail:t.bridgeAuthRefresh.error??"The bridge could not reload auth after setup.",tone:"danger"}:t.lastValidation?.status==="failed"?{phase:"failure",label:"Credential validation failed",detail:t.lastValidation.message,tone:"danger"}:"saving_api_key"===e.onboardingRequestState?{phase:"validating",label:"Validating credentials",detail:"Checking the provider key and saving it only if validation succeeds.",tone:"info"}:"starting_provider_flow"===e.onboardingRequestState||"submitting_provider_flow_input"===e.onboardingRequestState?{phase:"running_flow",label:"Advancing provider sign-in",detail:"The onboarding flow is running and will update here as soon as the next step is ready.",tone:"info"}:t.locked?{phase:"locked",label:"Required setup needed",detail:"Choose a required provider, validate it here, and the workspace will unlock without restarting the host.",tone:"warning"}:{phase:"ready",label:"Workspace unlocked",detail:t.lastValidation?.status==="succeeded"?`${q(t,t.lastValidation.providerId)} is ready and the workspace is live.`:"Required setup is satisfied and the shell is ready for live commands.",tone:"success"}}(e);if("ready"!==t.phase)return{label:t.label,tone:t.tone};if(e.boot?.bridge.phase==="failed")return{label:"Bridge failed",tone:"danger"};switch(e.connectionState){case"connected":return{label:"Bridge connected",tone:"success"};case"connecting":return{label:"Connecting stream",tone:"info"};case"reconnecting":return{label:"Reconnecting stream",tone:"warning"};case"disconnected":return{label:"Stream disconnected",tone:"warning"};case"error":return{label:"Stream error",tone:"danger"};default:return{label:"Workspace idle",tone:"muted"}}}function eu(e,t){if(!t)return e;let s=new URL(e,"http://localhost");return s.searchParams.set("project",t),s.pathname+s.search}class em{constructor(e){this.projectCwd=e,this.state={bootStatus:"idle",connectionState:"idle",boot:null,live:{auto:null,workspace:null,resumableSessions:[],recoverySummary:S(),freshness:{auto:N(),workspace:N(),recovery:N(),resumableSessions:N(),gitSummary:N(),sessionBrowser:N(),sessionStats:N()},softBootRefreshCount:0,targetedRefreshCount:0},terminalLines:[g("system","Preparing the live GSD workspace…")],lastClientError:null,lastBridgeError:null,sessionAttached:!1,lastEventType:null,commandInFlight:null,lastSlashCommandOutcome:null,commandSurface:(0,x.iE)(),onboardingRequestState:"idle",onboardingRequestProviderId:null,pendingUiRequests:[],streamingAssistantText:"",streamingThinkingText:"",liveTranscript:[],liveThinkingTranscript:[],completedToolExecutions:[],activeToolExecution:null,currentTurnSegments:[],completedTurnSegments:[],chatUserMessages:[],statusTexts:{},widgetContents:{},titleOverride:null,editorTextBuffer:null},this.listeners=new Set,this.contextualTips=new w,this.eventStream=new p({canConnect:()=>!this.disposed&&!this.state.boot?.onboarding.locked,streamUrl:()=>(0,b.QT)(this.buildUrl("/api/session/events")),onOpen:({wasDisconnected:e})=>this.handleEventStreamOpen(e),onMessage:e=>this.handleEventStreamMessage(e),onError:({nextConnectionState:e,changed:t})=>this.handleEventStreamError(e,t)}),this.bootPromise=null,this.onboardingPollTimer=null,this.started=!1,this.disposed=!1,this.lastBridgeDigest=null,this.commandTimeoutTimer=null,this.lastBootRefreshAt=0,this.visibilityHandler=null,this.subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}),this.getSnapshot=()=>this.state,this.start=()=>{this.started||this.disposed||(this.started=!0,"u">typeof document&&(this.visibilityHandler=()=>{"visible"===document.visibilityState&&Date.now()-this.lastBootRefreshAt>=3e4&&this.refreshBoot({soft:!0})},document.addEventListener("visibilitychange",this.visibilityHandler)),this.refreshBoot())},this.dispose=()=>{this.disposed=!0,this.started=!1,this.stopOnboardingPoller(),this.closeEventStream(),this.clearCommandTimeout(),this.visibilityHandler&&"u">typeof document&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)},this.disconnectSSE=()=>{this.closeEventStream()},this.reconnectSSE=()=>{this.disposed||(this.ensureEventStream(),this.refreshBoot({soft:!0}))},this.clearTerminalLines=()=>{let e=this.state.boot?G(this.state.boot):[g("system","Terminal cleared")];this.patchState({terminalLines:e})},this.consumeEditorTextBuffer=()=>{let e=this.state.editorTextBuffer;return null!==e&&this.patchState({editorTextBuffer:null}),e},this.openCommandSurface=(e,t={})=>{let s=P(this.state);this.patchState({commandSurface:(0,x.Q8)(this.state.commandSurface,{surface:e,source:t.source??"surface",args:t.args??"",selectedTarget:t.selectedTarget,onboardingLocked:this.state.boot?.onboarding.locked,currentModel:et(this.state.boot?.bridge),currentThinkingLevel:this.state.boot?.bridge.sessionState?.thinkingLevel??null,preferredProviderId:es(this.state.boot?.onboarding),resumableSessions:s.map(e=>({id:e.id,path:e.path,name:e.name,isActive:e.isActive})),currentSessionPath:this.state.boot?.bridge.activeSessionFile??this.state.boot?.bridge.sessionState?.sessionFile??null,currentSessionName:this.state.boot?.bridge.sessionState?.sessionName??null,projectCwd:this.state.boot?.project.cwd??null,projectSessionsDir:this.state.boot?.project.sessionsDir??null})})},this.closeCommandSurface=()=>{this.patchState({commandSurface:(0,x.Qx)(this.state.commandSurface)})},this.setCommandSurfaceSection=e=>{let t=P(this.state);this.patchState({commandSurface:(0,x.c0)(this.state.commandSurface,e,{onboardingLocked:this.state.boot?.onboarding.locked,currentModel:et(this.state.boot?.bridge),currentThinkingLevel:this.state.boot?.bridge.sessionState?.thinkingLevel??null,preferredProviderId:es(this.state.boot?.onboarding),resumableSessions:t.map(e=>({id:e.id,path:e.path,name:e.name,isActive:e.isActive})),currentSessionPath:this.state.boot?.bridge.activeSessionFile??this.state.boot?.bridge.sessionState?.sessionFile??null,currentSessionName:this.state.boot?.bridge.sessionState?.sessionName??null,projectCwd:this.state.boot?.project.cwd??null,projectSessionsDir:this.state.boot?.project.sessionsDir??null})})},this.selectCommandSurfaceTarget=e=>{this.patchState({commandSurface:(0,x.nU)(this.state.commandSurface,e)})},this.loadGitSummary=async()=>{let e={...this.state.commandSurface.gitSummary,pending:!0,error:null},t={...this.state.live,freshness:{...this.state.live.freshness,gitSummary:k(this.state.live.freshness.gitSummary)}};this.patchState({live:{...t,recoverySummary:_({boot:this.state.boot,live:t})},commandSurface:(0,x.Yc)({...this.state.commandSurface,gitSummary:e},"load_git_summary")});try{let t=await (0,b.tm)(this.buildUrl("/api/git"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),s=await t.json().catch(()=>null),r=s&&"object"==typeof s&&("repo"===s.kind||"not_repo"===s.kind)&&s.project&&"object"==typeof s.project&&"current_project"===s.project.scope&&"string"==typeof s.project.cwd&&("not_repo"===s.kind?"string"==typeof s.message:"string"==typeof s.project?.repoRoot&&"boolean"==typeof s.hasChanges&&"boolean"==typeof s.hasConflicts&&!!s.counts&&"object"==typeof s.counts&&!!Array.isArray(s.changedFiles)&&"number"==typeof s.truncatedFileCount&&"number"==typeof s.counts.changed&&"number"==typeof s.counts.staged&&"number"==typeof s.counts.dirty&&"number"==typeof s.counts.untracked&&"number"==typeof s.counts.conflicts)?s:null;if(!t.ok||!r){let r=s&&"object"==typeof s&&"error"in s&&"string"==typeof s.error?s.error:`Current-project git summary failed with ${t.status}`,a=er(e,r),n={...this.state.live,freshness:{...this.state.live.freshness,gitSummary:R(this.state.live.freshness.gitSummary,r)}};return this.patchState({live:{...n,recoverySummary:_({boot:this.state.boot,live:n})},commandSurface:(0,x.yC)({...this.state.commandSurface,gitSummary:a},{action:"load_git_summary",success:!1,message:r,gitSummary:a})}),null}let a={...this.state.live,freshness:{...this.state.live.freshness,gitSummary:A(this.state.live.freshness.gitSummary)}};return this.patchState({live:{...a,recoverySummary:_({boot:this.state.boot,live:a})},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_git_summary",success:!0,message:"",gitSummary:{pending:!1,loaded:!0,result:r,error:null}})}),r}catch(a){let t=$(a),s=er(e,t),r={...this.state.live,freshness:{...this.state.live.freshness,gitSummary:R(this.state.live.freshness.gitSummary,t)}};return this.patchState({live:{...r,recoverySummary:_({boot:this.state.boot,live:r})},commandSurface:(0,x.yC)({...this.state.commandSurface,gitSummary:s},{action:"load_git_summary",success:!1,message:t,gitSummary:s})}),null}},this.loadRecoveryDiagnostics=async()=>{var e;let t={...e=this.state.commandSurface.recovery,pending:!0,error:null,phase:e.loaded?e.phase:"loading"},s={...this.state.live,freshness:{...this.state.live.freshness,recovery:k(this.state.live.freshness.recovery)}};this.patchState({live:{...s,recoverySummary:_({boot:this.state.boot,live:s})},commandSurface:(0,x.Yc)({...this.state.commandSurface,recovery:t},"load_recovery_diagnostics")});try{let e=await (0,b.tm)(this.buildUrl("/api/recovery"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),s=await e.json().catch(()=>null),r=s&&"object"==typeof s&&("ready"===s.status||"unavailable"===s.status)&&"string"==typeof s.loadedAt&&s.project&&"string"==typeof s.project.cwd&&s.summary&&"string"==typeof s.summary.label&&"string"==typeof s.summary.detail&&s.bridge&&"string"==typeof s.bridge.phase&&s.validation&&"number"==typeof s.validation.total&&s.doctor&&"number"==typeof s.doctor.total&&s.interruptedRun&&"boolean"==typeof s.interruptedRun.available&&s.actions&&Array.isArray(s.actions.browser)&&Array.isArray(s.actions.commands)?s:null;if(!e.ok||!r){let r=s&&"object"==typeof s&&"error"in s&&"string"==typeof s.error?s.error:`Recovery diagnostics failed with ${e.status}`,a=ea(t,r),n={...this.state.live,freshness:{...this.state.live.freshness,recovery:R(this.state.live.freshness.recovery,r)}};return this.patchState({lastClientError:r,live:{...n,recoverySummary:_({boot:this.state.boot,live:n})},commandSurface:(0,x.yC)({...this.state.commandSurface,recovery:a},{action:"load_recovery_diagnostics",success:!1,message:r,recovery:a})}),null}let a={...{phase:"ready"===r.status?"ready":"unavailable",pending:!1,loaded:!0,stale:!1,diagnostics:r,error:null,lastLoadedAt:r.loadedAt,lastInvalidatedAt:null,lastFailureAt:null},lastInvalidatedAt:this.state.commandSurface.recovery.lastInvalidatedAt},n={...this.state.live,freshness:{...this.state.live.freshness,recovery:A(this.state.live.freshness.recovery)}};return this.patchState({lastClientError:null,live:{...n,recoverySummary:_({boot:this.state.boot,live:n})},commandSurface:(0,x.yC)({...this.state.commandSurface,recovery:a},{action:"load_recovery_diagnostics",success:!0,message:"ready"===r.status?"Recovery diagnostics refreshed":"Recovery diagnostics are currently unavailable",recovery:a})}),r}catch(a){let e=$(a),s=ea(t,e),r={...this.state.live,freshness:{...this.state.live.freshness,recovery:R(this.state.live.freshness.recovery,e)}};return this.patchState({lastClientError:e,live:{...r,recoverySummary:_({boot:this.state.boot,live:r})},commandSurface:(0,x.yC)({...this.state.commandSurface,recovery:s},{action:"load_recovery_diagnostics",success:!1,message:e,recovery:s})}),null}},this.loadForensicsDiagnostics=async()=>{this.patchDiagnosticsPhaseState("forensics",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/forensics"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Forensics request failed with ${e.status}`;return this.patchDiagnosticsPhaseState("forensics",{phase:"error",error:s}),null}return this.patchDiagnosticsPhaseState("forensics",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchDiagnosticsPhaseState("forensics",{phase:"error",error:e}),null}},this.loadDoctorDiagnostics=async e=>{this.patchDoctorState({phase:"loading",error:null});try{let t=e?`/api/doctor?scope=${encodeURIComponent(e)}`:"/api/doctor",s=await (0,b.tm)(t,{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),r=await s.json().catch(()=>null);if(!s.ok||!r){let e=r?.error??`Doctor request failed with ${s.status}`;return this.patchDoctorState({phase:"error",error:e}),null}return this.patchDoctorState({phase:"loaded",data:r,lastLoadedAt:new Date().toISOString()}),r}catch(t){let e=$(t);return this.patchDoctorState({phase:"error",error:e}),null}},this.applyDoctorFixes=async e=>{this.patchDoctorState({fixPending:!0,lastFixError:null,lastFixResult:null});try{let t=await (0,b.tm)(this.buildUrl("/api/doctor"),{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e?{scope:e}:{})}),s=await t.json().catch(()=>null);if(!t.ok||!s){let e=s?.error??`Doctor fix request failed with ${t.status}`;return this.patchDoctorState({fixPending:!1,lastFixError:e}),null}return this.patchDoctorState({fixPending:!1,lastFixResult:s}),this.loadDoctorDiagnostics(e),s}catch(t){let e=$(t);return this.patchDoctorState({fixPending:!1,lastFixError:e}),null}},this.loadSkillHealthDiagnostics=async()=>{this.patchDiagnosticsPhaseState("skillHealth",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/skill-health"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Skill health request failed with ${e.status}`;return this.patchDiagnosticsPhaseState("skillHealth",{phase:"error",error:s}),null}return this.patchDiagnosticsPhaseState("skillHealth",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchDiagnosticsPhaseState("skillHealth",{phase:"error",error:e}),null}},this.loadKnowledgeData=async()=>{this.patchKnowledgeCapturesPhaseState("knowledge",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/knowledge"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Knowledge request failed with ${e.status}`;return this.patchKnowledgeCapturesPhaseState("knowledge",{phase:"error",error:s}),null}return this.patchKnowledgeCapturesPhaseState("knowledge",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchKnowledgeCapturesPhaseState("knowledge",{phase:"error",error:e}),null}},this.loadCapturesData=async()=>{this.patchKnowledgeCapturesPhaseState("captures",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/captures"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Captures request failed with ${e.status}`;return this.patchKnowledgeCapturesPhaseState("captures",{phase:"error",error:s}),null}return this.patchKnowledgeCapturesPhaseState("captures",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchKnowledgeCapturesPhaseState("captures",{phase:"error",error:e}),null}},this.loadSettingsData=async()=>{this.patchSettingsPhaseState({phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/settings-data"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Settings request failed with ${e.status}`;return this.patchSettingsPhaseState({phase:"error",error:s}),null}return this.patchSettingsPhaseState({phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchSettingsPhaseState({phase:"error",error:e}),null}},this.loadHistoryData=async()=>{this.patchRemainingCommandsPhaseState("history",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/history"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`History request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("history",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("history",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("history",{phase:"error",error:e}),null}},this.loadInspectData=async()=>{this.patchRemainingCommandsPhaseState("inspect",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/inspect"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Inspect request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("inspect",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("inspect",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("inspect",{phase:"error",error:e}),null}},this.loadHooksData=async()=>{this.patchRemainingCommandsPhaseState("hooks",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/hooks"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Hooks request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("hooks",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("hooks",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("hooks",{phase:"error",error:e}),null}},this.loadExportData=async e=>{this.patchRemainingCommandsPhaseState("exportData",{phase:"loading",error:null});try{let t=e?`/api/export-data?format=${encodeURIComponent(e)}`:"/api/export-data",s=await (0,b.tm)(t,{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),r=await s.json().catch(()=>null);if(!s.ok||!r){let e=r?.error??`Export request failed with ${s.status}`;return this.patchRemainingCommandsPhaseState("exportData",{phase:"error",error:e}),null}return this.patchRemainingCommandsPhaseState("exportData",{phase:"loaded",data:r,lastLoadedAt:new Date().toISOString()}),r}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("exportData",{phase:"error",error:e}),null}},this.loadUndoInfo=async()=>{this.patchRemainingCommandsPhaseState("undo",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/undo"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Undo info request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("undo",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("undo",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("undo",{phase:"error",error:e}),null}},this.loadCleanupData=async()=>{this.patchRemainingCommandsPhaseState("cleanup",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/cleanup"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Cleanup data request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("cleanup",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("cleanup",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("cleanup",{phase:"error",error:e}),null}},this.loadSteerData=async()=>{this.patchRemainingCommandsPhaseState("steer",{phase:"loading",error:null});try{let e=await (0,b.tm)(this.buildUrl("/api/steer"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Steer data request failed with ${e.status}`;return this.patchRemainingCommandsPhaseState("steer",{phase:"error",error:s}),null}return this.patchRemainingCommandsPhaseState("steer",{phase:"loaded",data:t,lastLoadedAt:new Date().toISOString()}),t}catch(t){let e=$(t);return this.patchRemainingCommandsPhaseState("steer",{phase:"error",error:e}),null}},this.executeUndoAction=async()=>{try{let e=await (0,b.tm)(this.buildUrl("/api/undo"),{method:"POST",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t){let s=t?.error??`Undo action failed with ${e.status}`;return{success:!1,message:s}}return this.loadUndoInfo(),t}catch(e){return{success:!1,message:$(e)}}},this.executeCleanupAction=async(e,t)=>{try{let s=await (0,b.tm)(this.buildUrl("/api/cleanup"),{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({branches:e,snapshots:t})}),r=await s.json().catch(()=>null);if(!s.ok||!r){let e=r?.error??`Cleanup action failed with ${s.status}`;return{deletedBranches:0,prunedSnapshots:0,message:e}}return this.loadCleanupData(),r}catch(e){return{deletedBranches:0,prunedSnapshots:0,message:$(e)}}},this.resolveCaptureAction=async e=>{this.patchKnowledgeCapturesState({resolveRequest:{pending:!0,lastError:null,lastResult:null}});try{let t=await (0,b.tm)(this.buildUrl("/api/captures"),{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),s=await t.json().catch(()=>null);if(!t.ok||!s){let e=s?.error??`Capture resolve failed with ${t.status}`;return this.patchKnowledgeCapturesState({resolveRequest:{pending:!1,lastError:e,lastResult:null}}),null}return this.patchKnowledgeCapturesState({resolveRequest:{pending:!1,lastError:null,lastResult:s}}),this.loadCapturesData(),s}catch(t){let e=$(t);return this.patchKnowledgeCapturesState({resolveRequest:{pending:!1,lastError:e,lastResult:null}}),null}},this.updateSessionBrowserState=e=>{this.patchState({commandSurface:{...this.state.commandSurface,sessionBrowser:{...this.state.commandSurface.sessionBrowser,...e,error:null},lastError:null,lastResult:null}})},this.loadSessionBrowser=async(e={})=>{let t={...this.state.commandSurface.sessionBrowser,...e,error:null},s={...this.state.live,freshness:{...this.state.live.freshness,sessionBrowser:k(this.state.live.freshness.sessionBrowser)}};this.patchState({live:{...s,recoverySummary:_({boot:this.state.boot,live:s})},commandSurface:(0,x.Yc)({...this.state.commandSurface,sessionBrowser:t},"load_session_browser")});let r=new URLSearchParams;t.query.trim()&&r.set("query",t.query.trim()),r.set("sortMode",t.sortMode),r.set("nameFilter",t.nameFilter);try{let e=await (0,b.tm)(this.buildUrl(`/api/session/browser?${r.toString()}`),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),s=await e.json().catch(()=>null),a=function(e){if(!e||"object"!=typeof e)return null;let t=e.project,s=e.query;if(!t||!s||!Array.isArray(e.sessions)||"current_project"!==t.scope||"string"!=typeof t.cwd||"string"!=typeof t.sessionsDir||"string"!=typeof s.query||"string"!=typeof s.sortMode||"string"!=typeof s.nameFilter)return null;let r=e.sessions.filter(e=>"string"==typeof e?.id&&"string"==typeof e?.path&&"string"==typeof e?.cwd&&"string"==typeof e?.createdAt&&"string"==typeof e?.modifiedAt&&"number"==typeof e?.messageCount&&"string"==typeof e?.firstMessage&&"boolean"==typeof e?.isActive&&"number"==typeof e?.depth&&"boolean"==typeof e?.isLastInThread&&Array.isArray(e?.ancestorHasNextSibling));return{scope:t.scope,projectCwd:t.cwd,projectSessionsDir:t.sessionsDir,activeSessionPath:"string"==typeof t.activeSessionPath?t.activeSessionPath:null,query:s.query,sortMode:s.sortMode,nameFilter:s.nameFilter,totalSessions:Number(e.totalSessions??r.length),returnedSessions:Number(e.returnedSessions??r.length),sessions:r,loaded:!0,error:null}}(s);if(!e.ok||!a){let r=s&&"object"==typeof s&&"error"in s&&"string"==typeof s.error?s.error:`Current-project session browser failed with ${e.status}`,a={...t,error:r},n={...this.state.live,freshness:{...this.state.live.freshness,sessionBrowser:R(this.state.live.freshness.sessionBrowser,r)}};return this.patchState({live:{...n,recoverySummary:_({boot:this.state.boot,live:n})},commandSurface:(0,x.yC)({...this.state.commandSurface,sessionBrowser:a},{action:"load_session_browser",success:!1,message:r,sessionBrowser:a})}),null}let n=eo(a,this.state.boot),i=this.state.commandSurface.selectedTarget,o=n.sessions.find(e=>!e.isActive)?.path??n.sessions[0]?.path,l=n.sessions.find(e=>e.path===n.activeSessionPath)??n.sessions[0],d=i;if(i?.kind==="resume"||"resume"===this.state.commandSurface.section){let e=i?.kind==="resume"&&i.sessionPath&&n.sessions.some(e=>e.path===i.sessionPath)?i.sessionPath:o;d={kind:"resume",sessionPath:e}}else if(i?.kind==="name"||"name"===this.state.commandSurface.section){let e=i?.kind==="name"&&i.sessionPath?n.sessions.find(e=>e.path===i.sessionPath)??l:l;d={kind:"name",sessionPath:e?.path,name:i?.kind==="name"&&i.sessionPath===e?.path?i.name:e?.name??""}}let c={...this.state.live,freshness:{...this.state.live.freshness,sessionBrowser:A(this.state.live.freshness.sessionBrowser)}};return this.patchState({live:{...c,recoverySummary:_({boot:this.state.boot,live:c})},commandSurface:(0,x.yC)({...this.state.commandSurface,sessionBrowser:n},{action:"load_session_browser",success:!0,message:"",selectedTarget:d,sessionBrowser:n})}),n}catch(a){let e=$(a),s={...t,error:e},r={...this.state.live,freshness:{...this.state.live.freshness,sessionBrowser:R(this.state.live.freshness.sessionBrowser,e)}};return this.patchState({live:{...r,recoverySummary:_({boot:this.state.boot,live:r})},commandSurface:(0,x.yC)({...this.state.commandSurface,sessionBrowser:s},{action:"load_session_browser",success:!1,message:e,sessionBrowser:s})}),null}},this.renameSessionFromSurface=async(e,t)=>{let s=this.state.commandSurface.selectedTarget,r=t??(s?.kind==="name"?s.name:""),a=r.trim(),n={kind:"name",sessionPath:e,name:r};if(!a)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"rename_session",success:!1,message:"Session name cannot be empty",selectedTarget:n})}),null;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"rename_session",n)});try{let t=await (0,b.tm)(this.buildUrl("/api/session/manage"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({action:"rename",sessionPath:e,name:a})}),s=await t.json().catch(()=>null);if(!t.ok||!s||"object"!=typeof s||!0!==s.success){let e=s&&"object"==typeof s&&"error"in s&&"string"==typeof s.error?s.error:`Session rename failed with ${t.status}`;return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"rename_session",success:!1,message:e,selectedTarget:n})}),null}let r=function(e,t,s){if(!e)return null;let r=en(e)===t&&e.bridge.sessionState?{...e.bridge,sessionState:{...e.bridge.sessionState,sessionName:s}}:e.bridge,a={...e,bridge:r};return{...a,resumableSessions:ei(a.resumableSessions.map(e=>e.path===t?{...e,name:s}:e),a)}}(this.state.boot,s.sessionPath,s.name),i=eo(el(this.state.commandSurface.sessionBrowser,s.sessionPath,{name:s.name,...s.isActiveSession?{isActive:!0}:{}}),r),o={kind:"name",sessionPath:s.sessionPath,name:s.name},l={...this.state.live,resumableSessions:ei(P(this.state).map(e=>e.path===s.sessionPath?{...e,name:s.name}:e),r)};return this.patchState({...r?{boot:r}:{},live:{...l,recoverySummary:_({boot:r,live:l})},commandSurface:(0,x.yC)({...this.state.commandSurface,sessionBrowser:i},{action:"rename_session",success:!0,message:`Session name set: ${s.name}`,selectedTarget:o,sessionBrowser:i})}),s}catch(t){let e=$(t);return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"rename_session",success:!1,message:e,selectedTarget:n})}),null}},this.loadAvailableModels=async()=>{this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"loading_models")});let e=await this.sendCommand({type:"get_available_models"},{appendInputLine:!1,appendResponseLine:!1});if(!e||!1===e.success){let t=e?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"loading_models",success:!1,message:`Couldn't load models — ${t}`})}),[]}let t=function(e,t){let s=e&&"object"==typeof e&&"models"in e&&Array.isArray(e.models)?e.models:[],r=[];for(let e of s){let s="string"==typeof e.provider?e.provider:"string"==typeof e.providerId?e.providerId:void 0,a="string"==typeof e.id?e.id:void 0;s&&a&&r.push({provider:s,modelId:a,name:"string"==typeof e.name?e.name:void 0,reasoning:!!e.reasoning,isCurrent:s===t?.provider&&a===t?.modelId})}return r.sort((e,t)=>Number(t.isCurrent)-Number(e.isCurrent)||e.provider.localeCompare(t.provider)||e.modelId.localeCompare(t.modelId))}(e.data,et(this.state.boot?.bridge)),s=this.state.commandSurface.selectedTarget,r=s?.kind==="model"?s:t[0]?{kind:"model",provider:t[0].provider,modelId:t[0].modelId}:s;return this.patchState({commandSurface:{...this.state.commandSurface,pendingAction:null,lastError:null,availableModels:t,selectedTarget:r??null}}),t},this.applyModelSelection=async(e,t)=>{let s={kind:"model",provider:e,modelId:t};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_model",s)});let r=await this.sendCommand({type:"set_model",provider:e,modelId:t},{appendInputLine:!1,appendResponseLine:!1});if(!r||!1===r.success){let e=r?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_model",success:!1,message:e,selectedTarget:s})}),r}let a=this.state.boot?.bridge.sessionState?{...this.state.boot.bridge,sessionState:{...this.state.boot.bridge.sessionState,model:r.data}}:null,n=this.state.commandSurface.availableModels.map(s=>({...s,isCurrent:s.provider===e&&s.modelId===t}));return this.patchState({...a&&this.state.boot?{boot:B(this.state.boot,a)}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_model",success:!0,message:`Model set to ${e}/${t}`,selectedTarget:s,availableModels:n})}),r},this.applyThinkingLevel=async e=>{let t={kind:"thinking",level:e};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_thinking_level",t)});let s=await this.sendCommand({type:"set_thinking_level",level:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_thinking_level",success:!1,message:e,selectedTarget:t})}),s}let r=this.state.boot?.bridge.sessionState?{...this.state.boot.bridge,sessionState:{...this.state.boot.bridge.sessionState,thinkingLevel:e}}:null;return this.patchState({...r&&this.state.boot?{boot:B(this.state.boot,r)}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_thinking_level",success:!0,message:`Thinking level set to ${e}`,selectedTarget:t})}),s},this.setSteeringModeFromSurface=async e=>{let t=this.state.commandSurface.selectedTarget;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_steering_mode",t)});let s=await this.sendCommand({type:"set_steering_mode",mode:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_steering_mode",success:!1,message:e,selectedTarget:t})}),s}let r=O(this.state.boot,{steeringMode:e});return this.patchState({...r?{boot:r}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_steering_mode",success:!0,message:`Steering mode set to ${e}`,selectedTarget:t})}),s},this.setFollowUpModeFromSurface=async e=>{let t=this.state.commandSurface.selectedTarget;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_follow_up_mode",t)});let s=await this.sendCommand({type:"set_follow_up_mode",mode:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_follow_up_mode",success:!1,message:e,selectedTarget:t})}),s}let r=O(this.state.boot,{followUpMode:e});return this.patchState({...r?{boot:r}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_follow_up_mode",success:!0,message:`Follow-up mode set to ${e}`,selectedTarget:t})}),s},this.setAutoCompactionFromSurface=async e=>{let t=this.state.commandSurface.selectedTarget;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_auto_compaction",t)});let s=await this.sendCommand({type:"set_auto_compaction",enabled:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_auto_compaction",success:!1,message:e,selectedTarget:t})}),s}let r=O(this.state.boot,{autoCompactionEnabled:e});return this.patchState({...r?{boot:r}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_auto_compaction",success:!0,message:`Auto-compaction ${e?"enabled":"disabled"}`,selectedTarget:t})}),s},this.setAutoRetryFromSurface=async e=>{let t=this.state.commandSurface.selectedTarget;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"set_auto_retry",t)});let s=await this.sendCommand({type:"set_auto_retry",enabled:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_auto_retry",success:!1,message:e,selectedTarget:t})}),s}let r=O(this.state.boot,{autoRetryEnabled:e});return this.patchState({...r?{boot:r}:{},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"set_auto_retry",success:!0,message:`Auto-retry ${e?"enabled":"disabled"}`,selectedTarget:t})}),s},this.abortRetryFromSurface=async()=>{let e=this.state.commandSurface.selectedTarget;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"abort_retry",e)});let t=await this.sendCommand({type:"abort_retry"},{appendInputLine:!1,appendResponseLine:!1});if(!t||!1===t.success){let s=t?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"abort_retry",success:!1,message:s,selectedTarget:e})}),t}return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"abort_retry",success:!0,message:"Retry cancellation requested. Live retry state will update when the bridge confirms the abort.",selectedTarget:e})}),t},this.switchSessionFromSurface=async e=>{var t;let s,r={kind:"resume",sessionPath:e};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"switch_session",r)});let a=await this.sendCommand({type:"switch_session",sessionPath:e},{appendInputLine:!1,appendResponseLine:!1});if(!a||!1===a.success){let e=a?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"switch_session",success:!1,message:e,selectedTarget:r})}),a}if(a.data&&"object"==typeof a.data&&"cancelled"in a.data&&a.data.cancelled)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"switch_session",success:!1,message:"Session switch was cancelled before the browser changed sessions.",selectedTarget:r})}),a;let n=this.state.commandSurface.sessionBrowser.sessions.find(t=>t.path===e)?.name??this.state.boot?.resumableSessions.find(t=>t.path===e)?.name,i=function(e,t,s){if(!e)return null;let r=e.resumableSessions.find(e=>e.path===t),a={...e.bridge,activeSessionFile:t,activeSessionId:r?.id??e.bridge.activeSessionId,sessionState:e.bridge.sessionState?{...e.bridge.sessionState,sessionFile:t,sessionId:r?.id??e.bridge.sessionState.sessionId,sessionName:s??r?.name??e.bridge.sessionState.sessionName}:e.bridge.sessionState},n={...e,bridge:a};return{...n,resumableSessions:ei(n.resumableSessions.map(e=>({...e,isActive:e.path===t})),n)}}(this.state.boot,e,n),o=eo(el(this.state.commandSurface.sessionBrowser,e,{isActive:!0,...n?{name:n}:{}}),i),l={...this.state.live,resumableSessions:ei(P(this.state).map(t=>({...t,isActive:t.path===e,...t.path===e&&n?{name:n}:{}})),i)};return this.patchState({...i?{boot:i}:{},live:{...l,recoverySummary:_({boot:i,live:l})},commandSurface:(0,x.yC)({...this.state.commandSurface,sessionBrowser:o},{action:"switch_session",success:!0,message:`Switched to ${(t=i??this.state.boot,s=t?.resumableSessions.find(t=>t.path===e),s?.name?.trim()?s.name.trim():s?.id?s.id:W(e))}`,selectedTarget:r,sessionBrowser:o})}),a},this.loadSessionStats=async()=>{var e;let t={...this.state.live,freshness:{...this.state.live.freshness,sessionStats:k(this.state.live.freshness.sessionStats)}};this.patchState({live:{...t,recoverySummary:_({boot:this.state.boot,live:t})},commandSurface:(0,x.Yc)(this.state.commandSurface,"load_session_stats")});let s=await this.sendCommand({type:"get_session_stats"},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error",t={...this.state.live,freshness:{...this.state.live.freshness,sessionStats:R(this.state.live.freshness.sessionStats,e)}};return this.patchState({live:{...t,recoverySummary:_({boot:this.state.boot,live:t})},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_session_stats",success:!1,message:`Couldn't load session details — ${e}`,sessionStats:null})}),null}let r=(e=s.data)&&"object"==typeof e?"string"!=typeof e.sessionId?null:{sessionFile:"string"==typeof e.sessionFile?e.sessionFile:void 0,sessionId:e.sessionId,userMessages:Number(e.userMessages??0),assistantMessages:Number(e.assistantMessages??0),toolCalls:Number(e.toolCalls??0),toolResults:Number(e.toolResults??0),totalMessages:Number(e.totalMessages??0),tokens:{input:Number(e.tokens?.input??0),output:Number(e.tokens?.output??0),cacheRead:Number(e.tokens?.cacheRead??0),cacheWrite:Number(e.tokens?.cacheWrite??0),total:Number(e.tokens?.total??0)},cost:Number(e.cost??0)}:null;if(!r){let e="Session details response was missing the expected fields.",t={...this.state.live,freshness:{...this.state.live.freshness,sessionStats:R(this.state.live.freshness.sessionStats,e)}};return this.patchState({live:{...t,recoverySummary:_({boot:this.state.boot,live:t})},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_session_stats",success:!1,message:e,sessionStats:null})}),null}let a={...this.state.live,freshness:{...this.state.live.freshness,sessionStats:A(this.state.live.freshness.sessionStats)}};return this.patchState({live:{...a,recoverySummary:_({boot:this.state.boot,live:a})},commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_session_stats",success:!0,message:`Loaded session details for ${r.sessionId}`,sessionStats:r})}),r},this.exportSessionFromSurface=async e=>{let t=e?.trim()||void 0,s={kind:"session",outputPath:t};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"export_html",s)});let r=await this.sendCommand(t?{type:"export_html",outputPath:t}:{type:"export_html"},{appendInputLine:!1,appendResponseLine:!1});if(!r||!1===r.success){let e=r?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"export_html",success:!1,message:`Couldn't export this session — ${e}`,selectedTarget:s})}),r}let a=r.data&&"object"==typeof r.data&&"path"in r.data&&"string"==typeof r.data.path?r.data.path:"the generated file";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"export_html",success:!0,message:`Session exported to ${a}`,selectedTarget:s})}),r},this.loadForkMessages=async()=>{var e;this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"load_fork_messages")});let t=await this.sendCommand({type:"get_fork_messages"},{appendInputLine:!1,appendResponseLine:!1});if(!t||!1===t.success){let e=t?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_fork_messages",success:!1,message:`Couldn't load fork points — ${e}`,forkMessages:[]})}),[]}let s=((e=t.data)&&"object"==typeof e&&"messages"in e&&Array.isArray(e.messages)?e.messages:[]).map(e=>{let t="string"==typeof e.entryId?e.entryId:void 0,s="string"==typeof e.text?e.text:void 0;return t&&s?{entryId:t,text:s}:null}).filter(e=>null!==e),r=this.state.commandSurface.selectedTarget,a=r?.kind==="fork"&&r.entryId?r:s[0]?{kind:"fork",entryId:s[0].entryId}:r;return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"load_fork_messages",success:!0,message:s.length>0?`Loaded ${s.length} fork points.`:"No fork points are available yet.",selectedTarget:a??null,forkMessages:s})}),s},this.forkSessionFromSurface=async e=>{let t={kind:"fork",entryId:e};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"fork_session",t)});let s=await this.sendCommand({type:"fork",entryId:e},{appendInputLine:!1,appendResponseLine:!1});if(!s||!1===s.success){let e=s?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"fork_session",success:!1,message:`Couldn't create a fork — ${e}`,selectedTarget:t})}),s}if(s.data&&"object"==typeof s.data&&"cancelled"in s.data&&s.data.cancelled)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"fork_session",success:!1,message:"Fork creation was cancelled before a new session was created.",selectedTarget:t})}),s;let r=s.data&&"object"==typeof s.data&&"text"in s.data&&"string"==typeof s.data.text?s.data.text.trim():"";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"fork_session",success:!0,message:r?`Forked from “${r.slice(0,120)}${r.length>120?"…":""}”`:"Created a forked session.",selectedTarget:t})}),s},this.compactSessionFromSurface=async e=>{var t;let s=e?.trim()??"",r={kind:"compact",customInstructions:s};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"compact_session",r)});let a=await this.sendCommand(s?{type:"compact",customInstructions:s}:{type:"compact"},{appendInputLine:!1,appendResponseLine:!1});if(!a||!1===a.success){let e=a?.error??this.state.lastClientError??"Unknown error";return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"compact_session",success:!1,message:`Couldn't compact the session — ${e}`,selectedTarget:r,lastCompaction:null})}),a}let n=(t=a.data)&&"object"==typeof t?"string"!=typeof t.summary||"string"!=typeof t.firstKeptEntryId?null:{summary:t.summary,firstKeptEntryId:t.firstKeptEntryId,tokensBefore:Number(t.tokensBefore??0),details:t.details}:null;return n?this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"compact_session",success:!0,message:`Compacted ${n.tokensBefore.toLocaleString()} tokens into a fresh summary${s?" with custom instructions":""}.`,selectedTarget:r,lastCompaction:n})}):this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"compact_session",success:!1,message:"Compaction finished but the browser could not read the compaction result.",selectedTarget:r,lastCompaction:null})}),a},this.saveApiKeyFromSurface=async(e,t)=>{let s={kind:"auth",providerId:e,intent:"manage"};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"save_api_key",s)});let r=await this.saveApiKey(e,t),a=r?q(r,e):e;return r?(r.lastValidation?.status==="failed"?this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"save_api_key",success:!1,message:r.lastValidation.message,selectedTarget:s})}):"failed"===r.bridgeAuthRefresh.phase?this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"save_api_key",success:!1,message:r.bridgeAuthRefresh.error??`${a} credentials validated but bridge auth refresh failed`,selectedTarget:s})}):this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"save_api_key",success:!0,message:`${a} credentials validated and saved.`,selectedTarget:s})}),r):(this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"save_api_key",success:!1,message:this.state.lastClientError??`${a} setup failed`,selectedTarget:s})}),null)},this.startProviderFlowFromSurface=async e=>{let t={kind:"auth",providerId:e,intent:"login"};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"start_provider_flow",t)});let s=await this.startProviderFlow(e),r=s?q(s,e):e;return s?(this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"start_provider_flow",success:!0,message:`${r} sign-in started. Continue in the auth section.`,selectedTarget:t})}),s):(this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"start_provider_flow",success:!1,message:this.state.lastClientError??`${r} sign-in failed to start`,selectedTarget:t})}),null)},this.submitProviderFlowInputFromSurface=async(e,t)=>{let s=this.state.boot?.onboarding.activeFlow?.providerId??void 0,r={kind:"auth",providerId:s,intent:"login"};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"submit_provider_flow_input",r)});let a=await this.submitProviderFlowInput(e,t),n=a?.activeFlow?.providerLabel??(s&&a?q(a,s):s)??"Provider";if(!a)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"submit_provider_flow_input",success:!1,message:this.state.lastClientError??`${n} sign-in failed`,selectedTarget:r})}),null;if(a.activeFlow?.status==="failed")return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"submit_provider_flow_input",success:!1,message:a.activeFlow.error??`${n} sign-in failed`,selectedTarget:r})}),a;if("failed"===a.bridgeAuthRefresh.phase)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"submit_provider_flow_input",success:!1,message:a.bridgeAuthRefresh.error??`${n} sign-in completed but bridge auth refresh failed`,selectedTarget:r})}),a;let i=a.activeFlow&&["running","awaiting_browser_auth","awaiting_input"].includes(a.activeFlow.status)?`${n} sign-in advanced. Complete the remaining step in this panel.`:`${n} sign-in complete.`;return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"submit_provider_flow_input",success:!0,message:i,selectedTarget:r})}),a},this.cancelProviderFlowFromSurface=async e=>{let t=this.state.boot?.onboarding.activeFlow?.providerId??void 0,s={kind:"auth",providerId:t,intent:"login"};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"cancel_provider_flow",s)});let r=await this.cancelProviderFlow(e),a=r?.activeFlow?.providerLabel??(t&&r?q(r,t):t)??"Provider";return r?(this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"cancel_provider_flow",success:!0,message:`${a} sign-in cancelled.`,selectedTarget:s})}),r):(this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"cancel_provider_flow",success:!1,message:this.state.lastClientError??`${a} sign-in cancellation failed`,selectedTarget:s})}),null)},this.logoutProviderFromSurface=async e=>{let t={kind:"auth",providerId:e,intent:"logout"};this.patchState({commandSurface:(0,x.Yc)(this.state.commandSurface,"logout_provider",t)});let s=await this.logoutProvider(e),r=s?q(s,e):e;if(!s)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"logout_provider",success:!1,message:this.state.lastClientError??`${r} logout failed`,selectedTarget:t})}),null;if("failed"===s.bridgeAuthRefresh.phase)return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"logout_provider",success:!1,message:s.bridgeAuthRefresh.error??`${r} logout completed but bridge auth refresh failed`,selectedTarget:t})}),s;let a=s.required.providers.find(t=>t.id===e),n=a?.configured?`${r} saved credentials were removed, but ${a.configuredVia} auth still keeps the provider available.`:s.locked?`${r} logged out — required setup is needed again.`:`${r} logged out.`;return this.patchState({commandSurface:(0,x.yC)(this.state.commandSurface,{action:"logout_provider",success:!0,message:n,selectedTarget:t})}),s},this.respondToUiRequest=async(e,t)=>{this.patchState({commandInFlight:"extension_ui_response"});try{let s=await (0,b.tm)(this.buildUrl("/api/session/command"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:"extension_ui_response",id:e,...t})});if(!s.ok){let e=await s.json().catch(()=>({error:`HTTP ${s.status}`}));throw Error(e.error??`extension_ui_response failed with ${s.status}`)}this.patchState({pendingUiRequests:this.state.pendingUiRequests.filter(t=>t.id!==e)})}catch(t){let e=$(t);this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`UI response failed — ${e}`))})}finally{this.patchState({commandInFlight:null})}},this.dismissUiRequest=async e=>{this.patchState({commandInFlight:"extension_ui_response"});try{let t=await (0,b.tm)(this.buildUrl("/api/session/command"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({type:"extension_ui_response",id:e,cancelled:!0})});if(!t.ok){let e=await t.json().catch(()=>({error:`HTTP ${t.status}`}));throw Error(e.error??`extension_ui_response cancel failed with ${t.status}`)}this.patchState({pendingUiRequests:this.state.pendingUiRequests.filter(t=>t.id!==e)})}catch(t){let e=$(t);this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`UI dismiss failed — ${e}`))})}finally{this.patchState({commandInFlight:null})}},this.sendSteer=async e=>{await this.sendCommand({type:"steer",message:e})},this.sendAbort=async()=>{await this.sendCommand({type:"abort"})},this.pushChatUserMessage=e=>{this.patchState({chatUserMessages:[...this.state.chatUserMessages,e]})},this.submitInput=async(e,t)=>{let s=e.trim();if(!s)return null;let r=m(s,{isStreaming:this.state.boot?.bridge.sessionState?.isStreaming});if(this.patchState({lastSlashCommandOutcome:s.startsWith("/")?r:null}),"prompt"===r.kind){let e=this.state.boot?.bridge.sessionState,t=this.contextualTips.evaluate({input:s,isStreaming:!!e?.isStreaming,thinkingLevel:e?.thinkingLevel,contextPercent:void 0});t&&this.patchState({terminalLines:f(this.state.terminalLines,g("system",`💡 ${t}`))})}switch(r.kind){case"bash":return await this.sendCommand(r.command,{displayInput:s}),r;case"prompt":case"rpc":{let e=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),a=e&&e.length>0?{...r.command,images:e}:r.command;return await this.sendCommand(a,{displayInput:s}),r}case"local":if("clear_terminal"===r.action)return this.clearTerminalLines(),r;if("refresh_workspace"===r.action)return await this.refreshBoot(),r;return"gsd_help"===r.action&&this.patchState({terminalLines:f(f(this.state.terminalLines,g("input",s)),g("system",c))}),r;case"surface":{if(I.has(r.surface))return this.patchState({terminalLines:f(this.state.terminalLines,g("input",s))}),this.openCommandSurface(r.surface,{source:"slash",args:r.args}),r;let e=h(r),t=f(this.state.terminalLines,g("input",s));return e&&(t=f(t,g(e.type,e.message))),this.patchState({terminalLines:t}),r}case"reject":{let e=h(r),t=f(this.state.terminalLines,g("input",s));return e&&(t=f(t,g(e.type,e.message))),this.patchState({terminalLines:t}),r}case"view-navigate":return this.patchState({terminalLines:f(this.state.terminalLines,g("system",`Navigating to ${r.view} view`))}),window.dispatchEvent(new CustomEvent("gsd:navigate-view",{detail:{view:r.view}})),r}},this.refreshBoot=async(e={})=>{if(this.bootPromise)return await this.bootPromise;this.lastBootRefreshAt=Date.now();let t=!!(e.soft&&this.state.boot);this.bootPromise=(async()=>{t?this.patchState({lastClientError:null}):this.patchState({bootStatus:"loading",connectionState:"connected"===this.state.connectionState?"connected":"connecting",lastClientError:null});try{let e=await (0,b.tm)(this.buildUrl("/api/boot"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}});if(!e.ok){if(401===e.status)return void this.patchState({bootStatus:"unauthenticated",connectionState:"error"});throw Error(`Boot request failed with ${e.status}`)}let s=await e.json(),r=B(s,s.bridge)??s,a=function(e,t,s={}){let r={...e,auto:t.auto,workspace:t.workspace,resumableSessions:t.resumableSessions,freshness:{...e.freshness,auto:A(e.freshness.auto),workspace:A(e.freshness.workspace),recovery:A(e.freshness.recovery),resumableSessions:A(e.freshness.resumableSessions)},softBootRefreshCount:e.softBootRefreshCount+ +!!s.soft};return r.recoverySummary=_({boot:t,live:r}),r}(this.state.live,r,{soft:t});this.lastBridgeDigest=null,this.lastBridgeDigest=[r.bridge.phase,r.bridge.activeSessionId,r.bridge.lastError?.at,r.bridge.lastError?.message].join("::"),this.patchState({bootStatus:"ready",boot:r,live:a,connectionState:r.onboarding.locked?"idle":this.eventStream.isOpen()?this.state.connectionState:"connecting",lastBridgeError:r.bridge.lastError,sessionAttached:F(r.bridge),lastClientError:null,...t?{}:{terminalLines:G(r)}}),r.onboarding.locked?this.closeEventStream():this.ensureEventStream()}catch(s){let e=$(s);if(t)return void this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Workspace refresh failed — ${e}`))});this.patchState({bootStatus:"error",connectionState:"error",lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Boot failed — ${e}`))})}})().finally(()=>{this.bootPromise=null}),await this.bootPromise},this.refreshOnboarding=async()=>{this.patchState({onboardingRequestState:"refreshing",onboardingRequestProviderId:null,lastClientError:null});try{return await this.fetchOnboardingState()}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Onboarding refresh failed — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.saveApiKey=async(e,t)=>{this.patchState({onboardingRequestState:"saving_api_key",onboardingRequestProviderId:e,lastClientError:null});try{let s=await this.postOnboardingAction({action:"save_api_key",providerId:e,apiKey:t});return await this.syncAfterOnboardingMutation(s),s}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Credential setup failed — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.startProviderFlow=async e=>{this.patchState({onboardingRequestState:"starting_provider_flow",onboardingRequestProviderId:e,lastClientError:null});try{let t=await this.postOnboardingAction({action:"start_provider_flow",providerId:e});return await this.syncAfterOnboardingMutation(t),t}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Provider sign-in failed to start — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.submitProviderFlowInput=async(e,t)=>{this.patchState({onboardingRequestState:"submitting_provider_flow_input",onboardingRequestProviderId:this.state.boot?.onboarding.activeFlow?.providerId??null,lastClientError:null});try{let s=await this.postOnboardingAction({action:"continue_provider_flow",flowId:e,input:t});return await this.syncAfterOnboardingMutation(s),s}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Provider sign-in input failed — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.cancelProviderFlow=async e=>{this.patchState({onboardingRequestState:"cancelling_provider_flow",onboardingRequestProviderId:this.state.boot?.onboarding.activeFlow?.providerId??null,lastClientError:null});try{let t=await this.postOnboardingAction({action:"cancel_provider_flow",flowId:e});return await this.syncAfterOnboardingMutation(t),t}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Provider sign-in cancellation failed — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.logoutProvider=async e=>{this.patchState({onboardingRequestState:"logging_out_provider",onboardingRequestProviderId:e,lastClientError:null});try{let t=await this.postOnboardingAction({action:"logout_provider",providerId:e});return await this.syncAfterOnboardingMutation(t),t}catch(t){let e=$(t);return this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Provider logout failed — ${e}`))}),null}finally{this.patchState({onboardingRequestState:"idle",onboardingRequestProviderId:null})}},this.sendCommand=async(e,t={})=>{this.clearCommandTimeout();let s={commandInFlight:e.type};!1!==t.appendInputLine&&(s.terminalLines=f(this.state.terminalLines,g("input",t.displayInput??("string"==typeof e.message?e.message:`/${e.type}`)))),this.patchState(s),this.commandTimeoutTimer=setTimeout(()=>{this.state.commandInFlight&&this.patchState({commandInFlight:null,lastClientError:"Command timed out — controls re-enabled",terminalLines:f(this.state.terminalLines,g("error","Command timed out — controls re-enabled"))})},9e4);try{let s=await (0,b.tm)(this.buildUrl("/api/session/command"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await s.json();if("ok"in r)return null;if("get_state"===r.command&&r.success&&this.state.boot){let e={...this.state.boot.bridge,sessionState:r.data,activeSessionId:r.data.sessionId,activeSessionFile:r.data.sessionFile??this.state.boot.bridge.activeSessionFile,lastCommandType:"get_state",updatedAt:new Date().toISOString()};this.patchState({boot:B(this.state.boot,e),lastBridgeError:e.lastError,sessionAttached:F(e)})}return"new_session"===r.command&&r.success&&this.contextualTips.reset(),"onboarding_locked"===r.code&&r.details?.onboarding&&this.state.boot&&this.patchState({boot:function(e,t){var s;return e?U(e,(s=e.onboarding,{...s,...t,required:{...s.required,...t.required??{},providers:t.required?.providers??s.required.providers},optional:{...s.optional,...t.optional??{},sections:t.optional?.sections??s.optional.sections},bridgeAuthRefresh:{...s.bridgeAuthRefresh,...t.bridgeAuthRefresh??{}}})):null}(this.state.boot,r.details.onboarding)}),this.patchState({...!1===t.appendResponseLine?{}:{terminalLines:f(this.state.terminalLines,function(e){if(!e.success)return g("error",`Command failed (${e.command}) — ${e.error??"unknown error"}`);switch(e.command){case"get_state":return g("success","Session state refreshed");case"new_session":return g("success","Started a new session");case"prompt":return g("success","Prompt accepted by the live bridge");case"follow_up":return g("success","Follow-up queued on the live bridge");case"bash":{let t=e.data;if(t?.output?.trim())return g("output",t.output.trimEnd());if(t?.cancelled)return g("system","Bash command cancelled");let s=t?.exitCode??0;return g(0===s?"success":"error",0===s?"Bash command completed":`Bash command exited with code ${s}`)}default:return g("success",`Command accepted (${e.command})`)}}(r))},lastBridgeError:r.success?this.state.lastBridgeError:this.state.boot?.bridge.lastError??this.state.lastBridgeError}),r}catch(s){let t=$(s);return this.patchState({lastClientError:t,terminalLines:f(this.state.terminalLines,g("error",`Command failed (${e.type}) — ${t}`))}),{type:"response",command:e.type,success:!1,error:t}}finally{this.clearCommandTimeout(),this.patchState({commandInFlight:null})}}}buildUrl(e){return eu(e,this.projectCwd)}patchDiagnosticsPhaseState(e,t){this.patchState({commandSurface:{...this.state.commandSurface,diagnostics:{...this.state.commandSurface.diagnostics,[e]:{...this.state.commandSurface.diagnostics[e],...t}}}})}patchDoctorState(e){this.patchState({commandSurface:{...this.state.commandSurface,diagnostics:{...this.state.commandSurface.diagnostics,doctor:{...this.state.commandSurface.diagnostics.doctor,...e}}}})}patchKnowledgeCapturesState(e){this.patchState({commandSurface:{...this.state.commandSurface,knowledgeCaptures:{...this.state.commandSurface.knowledgeCaptures,...e}}})}patchKnowledgeCapturesPhaseState(e,t){this.patchState({commandSurface:{...this.state.commandSurface,knowledgeCaptures:{...this.state.commandSurface.knowledgeCaptures,[e]:{...this.state.commandSurface.knowledgeCaptures[e],...t}}}})}patchSettingsPhaseState(e){this.patchState({commandSurface:{...this.state.commandSurface,settingsData:{...this.state.commandSurface.settingsData,...e}}})}patchRemainingCommandsPhaseState(e,t){this.patchState({commandSurface:{...this.state.commandSurface,remainingCommands:{...this.state.commandSurface.remainingCommands,[e]:{...this.state.commandSurface.remainingCommands[e],...t}}}})}async refreshBootAfterCurrentSettles(e={}){if(this.bootPromise)try{await this.bootPromise}catch{}await this.refreshBoot(e)}invalidateLiveFreshness(e,t,s){let r={...this.state.live.freshness};e.includes("auto")&&(r.auto=C(r.auto,t,s)),e.includes("workspace")&&(r.workspace=C(r.workspace,t,s),r.gitSummary=C(r.gitSummary,t,s)),e.includes("recovery")&&(r.recovery=C(r.recovery,t,s),r.sessionStats=C(r.sessionStats,t,s)),e.includes("resumable_sessions")&&(r.resumableSessions=C(r.resumableSessions,t,s),r.sessionBrowser=C(r.sessionBrowser,t,s),r.sessionStats=C(r.sessionStats,t,s));let a={...this.state.live,freshness:r};return{...a,recoverySummary:_({boot:this.state.boot,live:a})}}refreshOpenCommandSurfacesForInvalidation(e){if(e.domains.includes("workspace")&&this.state.commandSurface.open&&"git"===this.state.commandSurface.section&&"load_git_summary"!==this.state.commandSurface.pendingAction&&this.loadGitSummary(),e.domains.includes("recovery")&&this.state.commandSurface.open&&"recovery"===this.state.commandSurface.section&&"load_recovery_diagnostics"!==this.state.commandSurface.pendingAction&&this.loadRecoveryDiagnostics(),e.domains.includes("resumable_sessions")&&(this.state.commandSurface.open&&("resume"===this.state.commandSurface.section||"name"===this.state.commandSurface.section)&&"load_session_browser"!==this.state.commandSurface.pendingAction&&this.loadSessionBrowser(),this.state.commandSurface.open&&"session"===this.state.commandSurface.section)){let e=this.state.boot?.bridge.activeSessionFile??this.state.boot?.bridge.sessionState?.sessionFile??null;this.patchState({commandSurface:{...this.state.commandSurface,sessionStats:this.state.commandSurface.sessionStats&&this.state.commandSurface.sessionStats.sessionFile===e?this.state.commandSurface.sessionStats:null}}),"load_session_stats"!==this.state.commandSurface.pendingAction&&this.loadSessionStats()}}async reloadLiveState(e,t){let s=e.filter(e=>"auto"===e||"workspace"===e||"resumable_sessions"===e);if(0===s.length){let e={...this.state.live,freshness:{...this.state.live.freshness,recovery:A(this.state.live.freshness.recovery)}};this.patchState({live:{...e,recoverySummary:_({boot:this.state.boot,live:e})}});return}let r={...this.state.live.freshness};s.includes("auto")&&(r.auto=k(r.auto)),s.includes("workspace")&&(r.workspace=k(r.workspace)),s.includes("resumable_sessions")&&(r.resumableSessions=k(r.resumableSessions)),r.recovery=k(r.recovery);let a={...this.state.live,freshness:r,targetedRefreshCount:this.state.live.targetedRefreshCount+1};this.patchState({live:{...a,recoverySummary:_({boot:this.state.boot,live:a})}});let n=new URLSearchParams;for(let e of s)n.append("domain",e);try{let e=await (0,b.tm)(this.buildUrl(`/api/live-state?${n.toString()}`),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),t=await e.json().catch(()=>null);if(!e.ok||!t)throw Error(t?.error??`Live state request failed with ${e.status}`);let r=this.state.boot,a={...this.state.live,freshness:{...this.state.live.freshness}};if(s.includes("auto")&&t.auto&&(a.auto=t.auto,a.freshness.auto=A(a.freshness.auto),r=r?{...r,auto:t.auto}:r),s.includes("workspace")&&t.workspace&&(a.workspace=t.workspace,a.freshness.workspace=A(a.freshness.workspace),r=r?{...r,workspace:t.workspace}:r),s.includes("resumable_sessions")&&t.resumableSessions){let e=ei(t.resumableSessions,r);a.resumableSessions=e,a.freshness.resumableSessions=A(a.freshness.resumableSessions),r=r?{...r,resumableSessions:e}:r}a.freshness.recovery=A(a.freshness.recovery),a.recoverySummary=_({boot:r,live:a}),this.patchState({...r?{boot:r}:{},live:a})}catch(a){let e=$(a),r={...this.state.live,freshness:{...this.state.live.freshness,auto:s.includes("auto")?R(this.state.live.freshness.auto,e):this.state.live.freshness.auto,workspace:s.includes("workspace")?R(this.state.live.freshness.workspace,e):this.state.live.freshness.workspace,resumableSessions:s.includes("resumable_sessions")?R(this.state.live.freshness.resumableSessions,e):this.state.live.freshness.resumableSessions,recovery:R(this.state.live.freshness.recovery,e)}};this.patchState({lastClientError:e,live:{...r,recoverySummary:_({boot:this.state.boot,live:r})},terminalLines:f(this.state.terminalLines,g("error",`Live refresh failed (${t}) — ${e}`))})}}handleLiveStateInvalidation(e){var t;this.patchState({live:this.invalidateLiveFreshness(e.domains,e.reason,e.source),commandSurface:e.domains.includes("recovery")?{...this.state.commandSurface,recovery:(t=this.state.commandSurface.recovery).loaded||t.error?{...t,stale:!0,lastInvalidatedAt:new Date().toISOString()}:t}:this.state.commandSurface}),this.refreshOpenCommandSurfacesForInvalidation(e),this.reloadLiveState(e.domains,e.reason)}clearCommandTimeout(){this.commandTimeoutTimer&&(clearTimeout(this.commandTimeoutTimer),this.commandTimeoutTimer=null)}async fetchOnboardingState(e=!1){let t=this.state.boot?.onboarding.activeFlow?.status??null,s=await (0,b.tm)(this.buildUrl("/api/onboarding"),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}}),r=await s.json();if(!s.ok||!r.onboarding)throw Error(r.error??`Onboarding request failed with ${s.status}`);return this.applyOnboardingState(r.onboarding),t&&D.has(t)&&r.onboarding.activeFlow&&M.has(r.onboarding.activeFlow.status)?await this.syncAfterOnboardingMutation(r.onboarding):e||this.appendOnboardingSummaryLine(r.onboarding),r.onboarding}async postOnboardingAction(e){let t=await (0,b.tm)(this.buildUrl("/api/onboarding"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),s=await t.json();if(!t.ok)throw s.onboarding&&this.applyOnboardingState(s.onboarding),Error(s.error??`Onboarding action failed with ${t.status}`);if(!s.onboarding)throw Error(`Onboarding action returned no state (${t.status})`);return this.applyOnboardingState(s.onboarding),s.onboarding}applyOnboardingState(e){this.state.boot&&this.patchState({boot:U(this.state.boot,e)})}async syncAfterOnboardingMutation(e){this.applyOnboardingState(e),this.appendOnboardingSummaryLine(e),(e.lastValidation?.status==="succeeded"||"idle"!==e.bridgeAuthRefresh.phase)&&this.refreshBootAfterCurrentSettles({soft:!0})}appendOnboardingSummaryLine(e){let t=z(e);if(!t)return;let s=this.state.terminalLines.at(-1);(s?.type!==t.type||s.content!==t.message)&&this.patchState({terminalLines:f(this.state.terminalLines,g(t.type,t.message))})}emit(){for(let e of this.listeners)e()}patchState(e){this.state={...this.state,...e},this.syncOnboardingPoller(),this.emit()}syncOnboardingPoller(){if(this.disposed)return void this.stopOnboardingPoller();let e=this.state.boot?.onboarding.activeFlow?.status,t=!!(e&&D.has(e));if(t&&!this.onboardingPollTimer){this.onboardingPollTimer=setInterval(()=>{"idle"===this.state.onboardingRequestState&&this.fetchOnboardingState(!0).catch(e=>{let t=$(e);this.patchState({lastClientError:t})})},1500);return}t||this.stopOnboardingPoller()}stopOnboardingPoller(){this.onboardingPollTimer&&(clearInterval(this.onboardingPollTimer),this.onboardingPollTimer=null)}ensureEventStream(){this.eventStream.ensure()}closeEventStream(){this.eventStream.close()}handleEventStreamOpen(e){e&&this.patchState({terminalLines:f(this.state.terminalLines,g("success","Live event stream reconnected"))}),this.patchState({connectionState:"connected",lastClientError:null}),e&&this.refreshBoot({soft:!0})}handleEventStreamMessage(e){try{let t=JSON.parse(e);if(null===t||"object"!=typeof t||"string"!=typeof t.type)return void this.patchState({lastClientError:"Malformed event received from stream",terminalLines:f(this.state.terminalLines,g("error","Malformed event received from stream"))});this.handleEvent(t)}catch(t){let e=$(t);this.patchState({lastClientError:e,terminalLines:f(this.state.terminalLines,g("error",`Failed to parse stream event — ${e}`))})}}handleEventStreamError(e,t){t?this.patchState({connectionState:e,terminalLines:f(this.state.terminalLines,g("reconnecting"===e?"system":"error","reconnecting"===e?"Live event stream disconnected — retrying…":"Live event stream failed before connection was established"))}):this.patchState({connectionState:e})}handleEvent(e){if(this.patchState({lastEventType:e.type}),"bridge_status"===e.type)return void this.recordBridgeStatus(e.bridge);"live_state_invalidation"===e.type&&this.handleLiveStateInvalidation(e),this.routeLiveInteractionEvent(e);let t=function(e){switch(e.type){case"bridge_status":return L(e.bridge);case"live_state_invalidation":return{type:"system",message:`[Live] Refreshing ${Array.isArray(e.domains)?e.domains.join(", "):"state"} after ${String(e.reason).replaceAll("_"," ")}`};case"agent_start":return{type:"system",message:"[Agent] Run started"};case"agent_end":return{type:"success",message:"[Agent] Run finished"};case"turn_start":return{type:"system",message:"[Agent] Turn started"};case"turn_end":return{type:"success",message:"[Agent] Turn complete"};case"tool_execution_start":return{type:"output",message:`[Tool] ${"string"==typeof e.toolName?e.toolName:"tool"} started`};case"tool_execution_update":default:return null;case"tool_execution_end":return{type:e.isError?"error":"success",message:`[Tool] ${"string"==typeof e.toolName?e.toolName:"tool"} ${e.isError?"failed":"completed"}`};case"auto_compaction_start":return{type:"system",message:"[Auto] Compaction started"};case"auto_compaction_end":return{type:e.aborted?"error":"success",message:e.aborted?"[Auto] Compaction aborted":"[Auto] Compaction finished"};case"auto_retry_start":return{type:"system",message:`[Auto] Retry ${String(e.attempt)}/${String(e.maxAttempts)} scheduled`};case"auto_retry_end":return{type:e.success?"success":"error",message:e.success?"[Auto] Retry recovered the run":"[Auto] Retry exhausted"};case"extension_ui_request":{let t="title"in e&&"string"==typeof e.title&&e.title.trim().length>0?e.title:"message"in e&&"string"==typeof e.message&&e.message.trim().length>0?e.message:e.method;return{type:"notifyType"in e&&"error"===e.notifyType?"error":"system",message:`[UI] ${t}`}}case"extension_error":return{type:"error",message:`[Extension] ${e.error}`}}}(e);t&&this.patchState({terminalLines:f(this.state.terminalLines,g(t.type,t.message))})}routeLiveInteractionEvent(e){switch(e.type){case"extension_ui_request":this.handleExtensionUiRequest(e);break;case"message_update":this.handleMessageUpdate(e);break;case"agent_end":case"turn_end":this.handleTurnBoundary();break;case"tool_execution_start":this.handleToolExecutionStart(e);break;case"tool_execution_update":this.handleToolExecutionUpdate(e);break;case"tool_execution_end":this.handleToolExecutionEnd(e)}}handleExtensionUiRequest(e){switch(e.method){case"select":case"confirm":case"input":case"editor":this.patchState({pendingUiRequests:[...this.state.pendingUiRequests,e]});break;case"notify":break;case"setStatus":if("setStatus"===e.method){let t={...this.state.statusTexts};void 0===e.statusText?delete t[e.statusKey]:t[e.statusKey]=e.statusText,this.patchState({statusTexts:t})}break;case"setWidget":if("setWidget"===e.method){let t={...this.state.widgetContents};void 0===e.widgetLines?delete t[e.widgetKey]:t[e.widgetKey]={lines:e.widgetLines,placement:e.widgetPlacement},this.patchState({widgetContents:t})}break;case"setTitle":if("setTitle"===e.method){let t=e.title.trim();this.patchState({titleOverride:t||null})}break;case"set_editor_text":"set_editor_text"===e.method&&this.patchState({editorTextBuffer:e.text})}}handleMessageUpdate(e){let t=e.assistantMessageEvent;t&&("text_delta"===t.type&&"string"==typeof t.delta?(this.state.streamingThinkingText.length>0&&this.patchState({currentTurnSegments:[...this.state.currentTurnSegments,{kind:"thinking",content:this.state.streamingThinkingText}],streamingThinkingText:""}),this.patchState({streamingAssistantText:this.state.streamingAssistantText+t.delta})):"thinking_delta"===t.type&&"string"==typeof t.delta?(this.state.streamingAssistantText.length>0&&this.patchState({currentTurnSegments:[...this.state.currentTurnSegments,{kind:"text",content:this.state.streamingAssistantText}],streamingAssistantText:""}),this.patchState({streamingThinkingText:this.state.streamingThinkingText+t.delta})):"thinking_end"===t.type&&this.state.streamingThinkingText.length>0&&this.patchState({currentTurnSegments:[...this.state.currentTurnSegments,{kind:"thinking",content:this.state.streamingThinkingText}],streamingThinkingText:""}))}handleTurnBoundary(){let e=[];this.state.streamingThinkingText.length>0&&e.push({kind:"thinking",content:this.state.streamingThinkingText}),this.state.streamingAssistantText.length>0&&e.push({kind:"text",content:this.state.streamingAssistantText});let t=e.length>0?[...this.state.currentTurnSegments,...e]:this.state.currentTurnSegments,s=t.filter(e=>"text"===e.kind).map(e=>e.content).join("");if(s.length>0||t.length>0){let e=[...this.state.liveTranscript,s],r=[...this.state.liveThinkingTranscript,""],a=[...this.state.completedTurnSegments,t],n=e.length>100?e.length-100:0,i=n>0?this.state.chatUserMessages.slice(n):void 0;this.patchState({liveTranscript:n>0?e.slice(n):e,liveThinkingTranscript:n>0?r.slice(n):r,completedTurnSegments:n>0?a.slice(n):a,...void 0!==i?{chatUserMessages:i}:{},streamingAssistantText:"",streamingThinkingText:"",currentTurnSegments:[],completedToolExecutions:[]})}else this.state.streamingThinkingText.length>0?this.patchState({streamingThinkingText:"",currentTurnSegments:[],completedToolExecutions:[]}):this.patchState({currentTurnSegments:[],completedToolExecutions:[]})}handleToolExecutionStart(e){this.patchState({activeToolExecution:{id:e.toolCallId,name:e.toolName,args:e.args},streamingAssistantText:"",streamingThinkingText:""})}handleToolExecutionUpdate(e){let t=this.state.activeToolExecution;t&&t.id===e.toolCallId&&this.patchState({activeToolExecution:{...t,result:e.partialResult?{content:e.partialResult.content,details:e.partialResult.details,isError:!!e.partialResult.isError}:t.result}})}handleToolExecutionEnd(e){let t=this.state.activeToolExecution;if(t){let s={id:t.id,name:t.name,args:t.args??{},result:{content:e.result?.content,details:e.result?.details,isError:e.isError}},r=[...this.state.completedToolExecutions,s];this.patchState({activeToolExecution:null,completedToolExecutions:r.length>50?r.slice(r.length-50):r,currentTurnSegments:[...this.state.currentTurnSegments,{kind:"tool",tool:s}]})}else this.patchState({activeToolExecution:null})}recordBridgeStatus(e){let t=[e.phase,e.activeSessionId,e.lastError?.at,e.lastError?.message].join("::"),s=t!==this.lastBridgeDigest;this.lastBridgeDigest=t;let r=B(this.state.boot,e),a={...this.state.live,resumableSessions:ei(this.state.live.resumableSessions,r)},n={...a,recoverySummary:_({boot:r,live:a})},i={boot:r,live:n,lastBridgeError:e.lastError,sessionAttached:F(e),commandSurface:{...this.state.commandSurface,sessionBrowser:eo(this.state.commandSurface.sessionBrowser,r)}};if(s){let t=L(e);i.terminalLines=f(this.state.terminalLines,g(t.type,t.message))}this.patchState(i)}}let eh=(0,a.createContext)(null);function ex({children:e,store:t}){let[s]=(0,a.useState)(()=>new em),n=t??s;return(0,a.useEffect)(()=>{if(!t)return n.start(),()=>n.dispose()},[n,t]),(0,r.jsx)(eh.Provider,{value:n,children:e})}function ep(){let e=(0,a.useContext)(eh);if(!e)throw Error("useWorkspaceStore must be used within GSDWorkspaceProvider");return e}function eg(){let e=ep();return(0,a.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot)}function ef(){let e=ep();return{sendCommand:e.sendCommand,submitInput:e.submitInput,clearTerminalLines:e.clearTerminalLines,consumeEditorTextBuffer:e.consumeEditorTextBuffer,refreshBoot:e.refreshBoot,refreshOnboarding:e.refreshOnboarding,openCommandSurface:e.openCommandSurface,closeCommandSurface:e.closeCommandSurface,setCommandSurfaceSection:e.setCommandSurfaceSection,selectCommandSurfaceTarget:e.selectCommandSurfaceTarget,loadGitSummary:e.loadGitSummary,loadRecoveryDiagnostics:e.loadRecoveryDiagnostics,loadForensicsDiagnostics:e.loadForensicsDiagnostics,loadDoctorDiagnostics:e.loadDoctorDiagnostics,applyDoctorFixes:e.applyDoctorFixes,loadSkillHealthDiagnostics:e.loadSkillHealthDiagnostics,loadKnowledgeData:e.loadKnowledgeData,loadCapturesData:e.loadCapturesData,loadSettingsData:e.loadSettingsData,loadHistoryData:e.loadHistoryData,loadInspectData:e.loadInspectData,loadHooksData:e.loadHooksData,loadExportData:e.loadExportData,loadUndoInfo:e.loadUndoInfo,loadCleanupData:e.loadCleanupData,loadSteerData:e.loadSteerData,executeUndoAction:e.executeUndoAction,executeCleanupAction:e.executeCleanupAction,resolveCaptureAction:e.resolveCaptureAction,updateSessionBrowserState:e.updateSessionBrowserState,loadSessionBrowser:e.loadSessionBrowser,renameSessionFromSurface:e.renameSessionFromSurface,loadAvailableModels:e.loadAvailableModels,applyModelSelection:e.applyModelSelection,applyThinkingLevel:e.applyThinkingLevel,setSteeringModeFromSurface:e.setSteeringModeFromSurface,setFollowUpModeFromSurface:e.setFollowUpModeFromSurface,setAutoCompactionFromSurface:e.setAutoCompactionFromSurface,setAutoRetryFromSurface:e.setAutoRetryFromSurface,abortRetryFromSurface:e.abortRetryFromSurface,switchSessionFromSurface:e.switchSessionFromSurface,loadSessionStats:e.loadSessionStats,exportSessionFromSurface:e.exportSessionFromSurface,loadForkMessages:e.loadForkMessages,forkSessionFromSurface:e.forkSessionFromSurface,compactSessionFromSurface:e.compactSessionFromSurface,saveApiKey:e.saveApiKey,saveApiKeyFromSurface:e.saveApiKeyFromSurface,startProviderFlow:e.startProviderFlow,startProviderFlowFromSurface:e.startProviderFlowFromSurface,submitProviderFlowInput:e.submitProviderFlowInput,submitProviderFlowInputFromSurface:e.submitProviderFlowInputFromSurface,cancelProviderFlow:e.cancelProviderFlow,cancelProviderFlowFromSurface:e.cancelProviderFlowFromSurface,logoutProvider:e.logoutProvider,logoutProviderFromSurface:e.logoutProviderFromSurface,respondToUiRequest:e.respondToUiRequest,dismissUiRequest:e.dismissUiRequest,sendSteer:e.sendSteer,sendAbort:e.sendAbort,pushChatUserMessage:e.pushChatUserMessage}}function eb(e,t){let s=m(e,{isStreaming:t?.sessionState?.isStreaming});if("prompt"===s.kind||"rpc"===s.kind)return s.command;throw Error(`buildPromptCommand cannot serialize ${s.input||e} because browser dispatch resolved it to ${s.kind}; use submitInput() instead.`)}},94002:(e,t,s)=>{function r(e,t){return t<=0?-1:Math.max(0,Math.min(t-1,e))}function a(e,t,s){if(s<=0)return{type:"none"};let a=function(e,t){if(!/^[1-9]$/.test(e))return null;let s=Number(e)-1;return s<t?s:null}(e,s);return null!==a?{type:"select",index:a}:"ArrowUp"===e?{type:"select",index:r(t-1,s)}:"ArrowDown"===e?{type:"select",index:r(t+1,s)}:"Home"===e?{type:"select",index:0}:"End"===e?{type:"select",index:s-1}:"Enter"===e||" "===e?{type:"submit",index:r(t,s)}:{type:"none"}}s.d(t,{cZ:()=>a,cv:()=>r})},97019:(e,t,s)=>{s.d(t,{Bc:()=>i,ZI:()=>d,k$:()=>l,m_:()=>o});var r=s(18870);s(45110);var a=s(37250),n=s(18833);function i({delayDuration:e=0,...t}){return(0,r.jsx)(a.Kq,{"data-slot":"tooltip-provider",delayDuration:e,...t})}function o({...e}){return(0,r.jsx)(i,{children:(0,r.jsx)(a.bL,{"data-slot":"tooltip",...e})})}function l({...e}){return(0,r.jsx)(a.l9,{"data-slot":"tooltip-trigger",...e})}function d({className:e,sideOffset:t=0,children:s,...i}){return(0,r.jsx)(a.ZL,{children:(0,r.jsxs)(a.UC,{"data-slot":"tooltip-content",sideOffset:t,className:(0,n.cn)("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",e),...i,children:[s,(0,r.jsx)(a.i3,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}}}]);
|