commandmate 0.33.1 → 0.33.2
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/.next/BUILD_ID +1 -1
- package/.next/app-build-manifest.json +290 -290
- package/.next/app-path-routes-manifest.json +29 -29
- package/.next/build-manifest.json +5 -5
- package/.next/diagnostics/framework.json +1 -1
- package/.next/next-server.js.nft.json +1 -1
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.json +1 -2
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/api/agents/update/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/agents/versions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/app/update/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/app/update-check/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/conversation/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/conversation/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/current-output/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/current-output/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/messages/route.js +1 -1
- package/.next/server/app/api/assistant/messages/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/messages/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/session/route.js +1 -1
- package/.next/server/app/api/assistant/session/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/session/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/start/route.js +32 -1
- package/.next/server/app/api/assistant/start/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/start/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/terminal/route.js +33 -2
- package/.next/server/app/api/assistant/terminal/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/terminal/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/tools/route.js.nft.json +1 -1
- package/.next/server/app/api/assistant/tools/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/capabilities/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/daily-summary/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/daily-summary/status/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/external-apps/[id]/health/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/external-apps/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/external-apps/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/fs/browse/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/fs/recent-paths/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/hooks/agent-event/route.js +1 -1
- package/.next/server/app/api/hooks/agent-event/route.js.nft.json +1 -1
- package/.next/server/app/api/hooks/agent-event/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/hooks/claude-done/route.js +2 -2
- package/.next/server/app/api/hooks/claude-done/route.js.nft.json +1 -1
- package/.next/server/app/api/hooks/claude-done/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/hooks/permission-request/route.js +1 -1
- package/.next/server/app/api/hooks/permission-request/route.js.nft.json +1 -1
- package/.next/server/app/api/hooks/permission-request/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/metrics/vibe/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/ollama/models/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/push/escalation/route.js +1 -1
- package/.next/server/app/api/push/escalation/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/push/subscriptions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/push/vapid/route.js +1 -1
- package/.next/server/app/api/push/vapid/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/relays/[relayId]/cancel/route.js +1 -1
- package/.next/server/app/api/relays/[relayId]/cancel/route.js.nft.json +1 -1
- package/.next/server/app/api/relays/[relayId]/cancel/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/relays/route.js +1 -1
- package/.next/server/app/api/relays/route.js.nft.json +1 -1
- package/.next/server/app/api/relays/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/remote/pair/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/[id]/todos/[todoId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/[id]/todos/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/clone/[jobId]/route.js +1 -1
- package/.next/server/app/api/repositories/clone/[jobId]/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/clone/[jobId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/clone/route.js +1 -1
- package/.next/server/app/api/repositories/clone/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/clone/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/excluded/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/restore/route.js +1 -1
- package/.next/server/app/api/repositories/restore/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/restore/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/route.js +1 -1
- package/.next/server/app/api/repositories/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/scan/route.js +1 -1
- package/.next/server/app/api/repositories/scan/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/scan/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/sync/route.js +1 -1
- package/.next/server/app/api/repositories/sync/route.js.nft.json +1 -1
- package/.next/server/app/api/repositories/sync/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/validate-path/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/settings/default-agents/route.js.nft.json +1 -1
- package/.next/server/app/api/settings/default-agents/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/settings/default-surface-mode/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/sidebar/group-order/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/skills/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/skills/installations/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/skills/operations/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/skills/reindex/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/slash-commands/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/tasks/[taskId]/cancel/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/tasks/[taskId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/templates/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/templates/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/todos/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/verification/runs/[runId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/verification/runs/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/auto-yes/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/auto-yes/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/auto-yes/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/capture/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/capture/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/clear-composer/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/clear-composer/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/clear-composer/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/cli-reference/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/cli-tool/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/cmate/schedules/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/current-output/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/current-output/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/current-output/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/env/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/execution-logs/[logId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/execution-logs/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/files/[...path]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/branch/create/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/branch/delete/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/branches/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/checkout/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/commit/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/diff/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/fetch/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/log/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/pull/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/push/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/reset/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/revert/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/show/[commitHash]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stage/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/staged/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stash/[index]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stash/apply/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stash/pop/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stash/push/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/stash/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/status/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/unstage/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/git/working-diff/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/instances/notes/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/instances/opencode/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/instances/opencode/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/interrupt/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/interrupt/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/kill-session/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/kill-session/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/kill-session/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/logs/[filename]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/logs/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/marp-render/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/memos/[memoId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/memos/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/messages/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/opencode/diff/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/opencode/session/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/opencode/share/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/prompt-response/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/prompt-response/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/prompt-response/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/resolve-target/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/respond/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/respond/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/respond/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/schedules/[scheduleId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/schedules/active/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/schedules/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/search/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/send/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/send/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/send/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/git-workflow/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/git-workflow/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/install/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/plan/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/uninstall/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/uninstall-plan/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/update/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/[skillId]/update-plan/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/skills/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/slash-commands/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/special-keys/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/special-keys/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/special-keys/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/tasks/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/terminal/route.js +103 -1
- package/.next/server/app/api/worktrees/[id]/terminal/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/terminal/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/timers/history/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/timers/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/timers/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/[id]/timers/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/todos/[todoId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/todos/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/tree/[...path]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/tree/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/upload/[...path]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/config/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/runs/[runId]/cancel/route.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/runs/[runId]/cancel/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/runs/[runId]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/verify/runs/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/viewed/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/apply-default-agents/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/route.js +1 -1
- package/.next/server/app/api/worktrees/route.js.nft.json +1 -1
- package/.next/server/app/api/worktrees/route_client-reference-manifest.js +1 -1
- package/.next/server/app/chat/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -1
- package/.next/server/app/more/page_client-reference-manifest.js +1 -1
- package/.next/server/app/offline/page_client-reference-manifest.js +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/proxy/[...path]/route_client-reference-manifest.js +1 -1
- package/.next/server/app/repositories/page_client-reference-manifest.js +1 -1
- package/.next/server/app/review/page_client-reference-manifest.js +1 -1
- package/.next/server/app/sessions/page_client-reference-manifest.js +1 -1
- package/.next/server/app/skills/[skillId]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/skills/installed/page_client-reference-manifest.js +1 -1
- package/.next/server/app/skills/page_client-reference-manifest.js +1 -1
- package/.next/server/app/worktrees/[id]/files/[...path]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/worktrees/[id]/page.js +8 -8
- package/.next/server/app/worktrees/[id]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/worktrees/[id]/terminal/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +29 -29
- package/.next/server/chunks/1068.js +1 -0
- package/.next/server/chunks/1210.js +1 -1
- package/.next/server/chunks/1331.js +2 -2
- package/.next/server/chunks/1366.js +5 -3
- package/.next/server/chunks/1886.js +2 -2
- package/.next/server/chunks/2839.js +1 -0
- package/.next/server/chunks/3241.js +1 -1
- package/.next/server/chunks/3323.js +1 -0
- package/.next/server/chunks/3707.js +1 -1
- package/.next/server/chunks/3708.js +1 -1
- package/.next/server/chunks/4443.js +1 -1
- package/.next/server/chunks/5220.js +1 -1
- package/.next/server/chunks/595.js +2 -2
- package/.next/server/chunks/650.js +1 -0
- package/.next/server/chunks/6781.js +1 -0
- package/.next/server/chunks/6808.js +1 -0
- package/.next/server/chunks/6838.js +1 -1
- package/.next/server/chunks/7875.js +3 -3
- package/.next/server/chunks/8918.js +107 -5
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-manifest.json +5 -5
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/server/src/middleware.js.map +1 -1
- package/.next/static/chunks/1255-7e5873f06b25e129.js +1 -0
- package/.next/static/chunks/{4718-2bc5cdf06573bf54.js → 4718-441a2af91f0374e9.js} +1 -1
- package/.next/static/chunks/app/worktrees/[id]/page-38edcd53e51f53b0.js +1 -0
- package/.next/static/chunks/{main-6092074a0dc78280.js → main-ac91ed6e71380841.js} +1 -1
- package/.next/trace +13 -14
- package/dist/server/src/lib/assistant-response-saver.js +168 -12
- package/dist/server/src/lib/hooks/sources/antigravity/history.js +204 -9
- package/dist/server/src/lib/hooks/sources/claude/history.js +29 -3
- package/dist/server/src/lib/hooks/sources/codex/history.js +29 -3
- package/dist/server/src/lib/hooks/sources/command-code/history.js +29 -3
- package/dist/server/src/lib/hooks/stop-history-capture.js +30 -4
- package/dist/server/src/lib/polling/response-checker.js +258 -9
- package/dist/server/src/lib/polling/response-poller-core.js +20 -0
- package/dist/server/src/lib/polling/structured-history-gate.js +26 -6
- package/dist/server/src/lib/response-cleaner.js +84 -0
- package/package.json +2 -2
- package/.next/server/chunks/21.js +0 -1
- package/.next/server/chunks/3086.js +0 -1
- package/.next/server/chunks/3270.js +0 -1
- package/.next/server/chunks/3925.js +0 -1
- package/.next/server/chunks/5043.js +0 -1
- package/.next/server/chunks/6306.js +0 -1
- package/.next/server/chunks/6363.js +0 -1
- package/.next/server/chunks/6491.js +0 -103
- package/.next/server/chunks/7890.js +0 -1
- package/.next/server/chunks/8063.js +0 -32
- package/.next/server/chunks/8687.js +0 -1
- package/.next/static/chunks/1255-8cb587d9170b45ed.js +0 -1
- package/.next/static/chunks/app/worktrees/[id]/page-13ca0ba551fe5cfb.js +0 -1
- /package/.next/static/{9lgw9hA727UMyFhXryGWG → 0a4qrU8WdUwQrlO4mfLMu}/_buildManifest.js +0 -0
- /package/.next/static/{9lgw9hA727UMyFhXryGWG → 0a4qrU8WdUwQrlO4mfLMu}/_ssgManifest.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1479],{8269:(e,t,n)=>{"use strict";n.d(t,{hU:()=>r});var a=n(12115);function r(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onSwipeLeft:t,onSwipeRight:n,onSwipeUp:r,onSwipeDown:s,threshold:l=50,enabled:i=!0,axis:o="both",directionLock:c,directionLockThreshold:d=12,suppressWhenScrollable:u=!0,edgeStartZone:m=0,onSwipeMove:h,onSwipeEnd:f}=e,x=null!=c?c:"both"!==o,p="horizontal"===o?"horizontal":"vertical",g="both"===o||"horizontal"===o,b="both"===o||"vertical"===o,v=(0,a.useRef)(null),[y,j]=(0,a.useState)(!1),[w,k]=(0,a.useState)(null),N=(0,a.useRef)(null),C=(0,a.useRef)(null),S=(0,a.useCallback)(()=>{k(null)},[]),T=(0,a.useCallback)(e=>{if(!i)return;if(u&&e.target instanceof HTMLElement&&function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"vertical",n=e;for(;n;){let e=getComputedStyle(n);if("horizontal"===t){let{overflowX:t}=e;if(("auto"===t||"scroll"===t)&&n.scrollWidth>n.clientWidth)return!0}else{let{overflowY:t}=e;if(("auto"===t||"scroll"===t)&&n.scrollHeight>n.clientHeight)return!0}n=n.parentElement}return!1}(e.target,p)){N.current=null;return}let t=e.touches[0];if(m>0&&v.current){let e=v.current.getBoundingClientRect(),n=t.clientX-e.left,a=e.right-t.clientX;if(n>m&&a>m){N.current=null;return}}N.current={x:t.clientX,y:t.clientY},C.current={committed:null,cancelled:!1},j(!0)},[i,u,p,m]),I=(0,a.useCallback)(e=>{if(!i||!N.current)return;let t=e.touches[0],n=t.clientX-N.current.x,a=t.clientY-N.current.y,r=Math.abs(n),s=Math.abs(a);if(x){let e=C.current;if(e){if(e.cancelled)return;if(null===e.committed&&Math.max(r,s)>=d){let t=r>s?"horizontal":"vertical";if(e.committed=t,t!==o){e.cancelled=!0;return}}if(null!==e.committed&&e.committed!==o)return}}g&&r>s&&r>=l?k(n<0?"left":"right"):b&&s>=l&&k(a<0?"up":"down"),null==h||h({deltaX:n,deltaY:a})},[i,l,o,x,d,g,b,h]),E=(0,a.useCallback)(e=>{var a;if(!i||!N.current)return void j(!1);let o=x&&(null==(a=C.current)?void 0:a.cancelled)===!0,c=e.changedTouches[0];if(!o&&c){let e=c.clientX-N.current.x,a=c.clientY-N.current.y,i=Math.abs(e),o=Math.abs(a);i>o?g&&i>=l&&(e<0?(k("left"),null==t||t()):(k("right"),null==n||n())):b&&o>=l&&(a<0?(k("up"),null==r||r()):(k("down"),null==s||s()))}N.current=null,C.current=null,j(!1),null==f||f()},[i,l,x,g,b,t,n,r,s,f]),A=(0,a.useCallback)(()=>{N.current&&(N.current=null,C.current=null,j(!1),null==f||f())},[f]);return(0,a.useEffect)(()=>{let e=v.current;if(e)return e.addEventListener("touchstart",T),e.addEventListener("touchmove",I),e.addEventListener("touchend",E),e.addEventListener("touchcancel",A),()=>{e.removeEventListener("touchstart",T),e.removeEventListener("touchmove",I),e.removeEventListener("touchend",E),e.removeEventListener("touchcancel",A)}},[T,I,E,A]),{ref:v,isSwiping:y,swipeDirection:w,resetSwipeDirection:S}}},11063:(e,t,n)=>{"use strict";n.d(t,{Ko:()=>r,j6:()=>a}),n(19985);let a=5242880,r={safe:"",interactive:"allow-scripts"}},17846:(e,t,n)=>{"use strict";n.d(t,{a:()=>l});var a=n(95155),r=n(12115),s=n(18955);function l(e){let{src:t,alt:n,onError:l}=e,i=(0,s.c)("worktree"),[o,c]=(0,r.useState)(!1);return o?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,a.jsx)("svg",{className:"w-16 h-16 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),(0,a.jsx)("p",{className:"text-sm",children:i("imageViewer.loadError")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:n})]}):(0,a.jsx)("div",{className:"flex items-center justify-center p-4",children:(0,a.jsx)("img",{src:t,alt:n,onError:()=>{c(!0),null==l||l()},style:{maxWidth:"100%",maxHeight:"500px",objectFit:"contain"},className:"rounded-lg shadow-sm"})})}},19985:(e,t,n)=>{"use strict";n.d(t,{F5:()=>i,Fg:()=>a,HB:()=>s,Hv:()=>l});let a=0x1400000,r=[{extension:".png",mimeType:"image/png",magicBytes:[137,80,78,71]},{extension:".jpg",mimeType:"image/jpeg",magicBytes:[255,216,255]},{extension:".jpeg",mimeType:"image/jpeg",magicBytes:[255,216,255]},{extension:".gif",mimeType:"image/gif",magicBytes:[71,73,70,56]},{extension:".webp",mimeType:"image/webp",magicBytes:[82,73,70,70]},{extension:".svg",mimeType:"image/svg+xml"}];function s(e){return e?e.startsWith(".")?e.toLowerCase():"."+e.toLowerCase():""}let l=[".png",".jpg",".jpeg",".gif",".webp",".svg"].filter(e=>".svg"!==e),i=l.map(e=>(function(e){let t=s(e),n=r.find(e=>e.extension===t);return(null==n?void 0:n.mimeType)||"application/octet-stream"})(e)).filter(e=>"application/octet-stream"!==e).join(",")},20252:(e,t,n)=>{Promise.resolve().then(n.bind(n,86537))},27307:(e,t,n)=>{"use strict";n.r(t),n.d(t,{PdfPreview:()=>o,default:()=>c});var a=n(95155),r=n(12115),s=n(18955);n(19985);let l=void 0;var i=n(3005);function o(e){let{dataUri:t,filePath:n,variant:o="iframe"}=e,[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(!1),h=(0,s.c)("worktree");if((0,r.useEffect)(()=>{let e=!1,n=null;return d(null),m(!1),(async()=>{try{let a=await fetch(t);if(!a.ok)throw Error("fetch failed: ".concat(a.status));let r=await a.blob();if(e)return;n=URL.createObjectURL(r),d(n)}catch(t){if(e)return;m(!0)}})(),()=>{e=!0,n&&URL.revokeObjectURL(n)}},[t,n]),u)return(0,a.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 p-6 text-center","data-testid":"pdf-preview-error",children:[(0,a.jsx)("p",{className:"text-sm text-danger-foreground",children:h("pdfPreview.loadError")}),(0,a.jsx)("a",{href:t,download:n.split("/").pop()||"document.pdf",className:"inline-flex items-center gap-2 px-4 py-2 rounded-md border border-input text-sm text-foreground hover:bg-muted",rel:"noopener",children:h("pdfPreview.downloadPdf")})]});if(!c)return(0,a.jsx)("div",{className:"h-full flex items-center justify-center","data-testid":"pdf-preview-loading",children:(0,a.jsx)(i.y,{size:"xl",variant:"accent"})});if("download"===o){let e=n.split("/").pop()||"document.pdf";return(0,a.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-4 p-6 text-center","data-testid":"pdf-preview-download",children:[(0,a.jsx)("svg",{className:"w-16 h-16 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,a.jsx)("p",{className:"text-sm text-foreground break-all",children:e}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 w-full max-w-xs",children:[(0,a.jsx)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center gap-2 px-6 py-3 rounded-lg bg-accent-600 hover:bg-accent-700 active:bg-accent-800 text-white text-sm font-medium transition-colors",children:h("pdfPreview.openInNewTab")}),(0,a.jsx)("a",{href:c,download:e,className:"inline-flex items-center justify-center gap-2 px-6 py-2 rounded-lg border border-input text-sm text-foreground hover:bg-muted transition-colors",children:h("pdfPreview.download")})]})]})}return(0,a.jsx)("iframe",{src:c,sandbox:l,title:h("pdfPreview.title",{path:n}),className:"w-full h-full border-0 bg-white","data-testid":"pdf-preview-iframe"})}let c=o},50857:(e,t,n)=>{"use strict";function a(e){return"running"===e||"generating"===e||"waiting"===e}function r(e){return e.isActive||a(e.status)}function s(e,t){let n=e.map((e,t)=>({it:e,index:t})).filter(e=>{let{it:t}=e;return r(t)}),a=new Set;return t>0&&n.length>0&&[...n].sort((e,t)=>Number(t.it.isActive)-Number(e.it.isActive)||e.index-t.index).slice(0,t).forEach(e=>{let{index:t}=e;return a.add(t)}),e.map((e,t)=>r(e)?{...e,slot:a.has(t)?"pill":"overflow"}:{...e,slot:"dot"})}n.d(t,{Qo:()=>a,Uw:()=>s})},51434:(e,t,n)=>{"use strict";n.d(t,{C:()=>r});var a=n(12115);function r(){let[e,t]=(0,a.useState)(!1),[n,r]=(0,a.useState)(0),[s,l]=(0,a.useState)(null),i=(0,a.useCallback)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport,n=window.innerHeight,a=e.height,s=n-a,i=s>100;t(i),r(i?s:0),l(a)},[]);return(0,a.useEffect)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport;return i(),e.addEventListener("resize",i),()=>{e.removeEventListener("resize",i)}},[i]),{isKeyboardVisible:e,keyboardHeight:n,viewportHeight:s}}},53292:(e,t,n)=>{"use strict";n.d(t,{Ll:()=>a,bu:()=>r});let a=2e3,r=4e3},60850:(e,t,n)=>{"use strict";n.d(t,{U:()=>r});var a=n(12115);function r(e){let{value:t,saveFn:n,debounceMs:r=300,disabled:s=!1,maxRetries:l=3,onSaveComplete:i}=e,[o,c]=(0,a.useState)(!1),[d,u]=(0,a.useState)(null),m=(0,a.useRef)(t),h=(0,a.useRef)(n),f=(0,a.useRef)(i),x=(0,a.useRef)(null),p=(0,a.useRef)(!0),g=(0,a.useRef)(t);(0,a.useEffect)(()=>{m.current=t},[t]),(0,a.useEffect)(()=>{h.current=n},[n]),(0,a.useEffect)(()=>{f.current=i},[i]),(0,a.useEffect)(()=>(p.current=!0,()=>{p.current=!1,x.current&&clearTimeout(x.current)}),[]);let b=(0,a.useCallback)(async e=>{if(!p.current)return;c(!0),u(null);let t=null,n=0;for(;n<=l;)try{if(await h.current(e),p.current){var a;c(!1),u(null),null==(a=f.current)||a.call(f)}return}catch(e){if(t=e instanceof Error?e:Error(String(e)),++n<=l){let e=1e3*Math.pow(2,n-1);await new Promise(t=>setTimeout(t,e))}}p.current&&(c(!1),u(t))},[l]),v=(0,a.useCallback)(()=>{x.current&&(clearTimeout(x.current),x.current=null)},[]),y=(0,a.useCallback)(async()=>{s||(v(),await b(m.current))},[s,v,b]);return(0,a.useEffect)(()=>{if(t!==g.current&&!s)return v(),x.current=setTimeout(()=>{b(m.current)},r),()=>{v()}},[t,s,r,v,b]),{isSaving:o,error:d,saveNow:y}}},64269:(e,t,n)=>{"use strict";function a(e,t){let n=null;return function(){for(var a=arguments.length,r=Array(a),s=0;s<a;s++)r[s]=arguments[s];n&&clearTimeout(n),n=setTimeout(()=>{e(...r),n=null},t)}}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e){let t=new Set;for(let n of e){t.add(n);let e=n.split("/"),a="";for(let n=0;n<e.length-1;n++)a=a?"".concat(a,"/").concat(e[n]):e[n],t.add(a)}return t}function l(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:30;return e.length<=t?e:"".concat(e.substring(0,t-3),"...")}function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}n.d(t,{Nt:()=>r,W5:()=>l,ZD:()=>i,q3:()=>s,sg:()=>a})},69264:(e,t,n)=>{"use strict";n.d(t,{u:()=>i});var a=n(95155),r=n(12115),s=n(18955),l=n(3005);function i(e){let{src:t,onError:n}=e,i=(0,s.c)("worktree"),[o,c]=(0,r.useState)(!0),[d,u]=(0,r.useState)(!1);return d?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,a.jsx)("svg",{className:"w-16 h-16 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"})}),(0,a.jsx)("p",{className:"text-sm",children:i("videoViewer.loadError")})]}):(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center p-4",children:[o&&(0,a.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,a.jsx)(l.y,{size:"xl",variant:"accent"}),(0,a.jsx)("p",{className:"ml-3 text-muted-foreground",children:i("videoViewer.loading")})]}),(0,a.jsx)("video",{controls:!0,src:t,onLoadedData:()=>{c(!1)},onError:()=>{c(!1),u(!0),null==n||n()},style:{maxWidth:"100%",maxHeight:"500px",display:o?"none":"block"},className:"rounded-lg shadow-sm",children:i("videoViewer.unsupported")})]})}},72115:(e,t,n)=>{"use strict";n.d(t,{f:()=>d});var a=n(95155),r=n(12115),s=n(18955);let l=["relative","flex-shrink-0","bg-border","transition-colors","duration-150","hover:bg-accent-500","dark:hover:bg-accent-500","focus:outline-none","focus:ring-2","focus:ring-ring","focus:ring-offset-2","focus:ring-offset-background"],i=["w-1","h-full","cursor-col-resize","before:content-['']","before:absolute","before:inset-y-0","before:-inset-x-1"],o=["h-1","w-full","cursor-row-resize","before:content-['']","before:absolute","before:inset-x-0","before:-inset-y-1"];function c(e,t){return"touches"in e&&e.touches.length>0?t?e.touches[0].clientX:e.touches[0].clientY:"clientX"in e?t?e.clientX:e.clientY:0}let d=(0,r.memo)(function(e){let{onResize:t,orientation:n="horizontal",ariaValueNow:d=50,onDoubleClick:u,minRatio:m=.1}=e,h=(0,s.c)("worktree"),[f,x]=(0,r.useState)(!1),p=(0,r.useRef)(0),g=(0,r.useRef)(null),b="horizontal"===n,v=(0,r.useCallback)(e=>{e.preventDefault(),x(!0),p.current=c(e,b)},[b]),y=(0,r.useCallback)(e=>{1===e.touches.length&&(x(!0),p.current=c(e,b))},[b]),j=(0,r.useCallback)(e=>{if(!f)return;let n=c(e,b);t(n-p.current),p.current=n},[f,b,t]),w=(0,r.useCallback)(e=>{if(!f||1!==e.touches.length)return;let n=c(e,b);t(n-p.current),p.current=n},[f,b,t]),k=(0,r.useCallback)(()=>{x(!1)},[]),N=(0,r.useCallback)(()=>{u&&u()},[u]),C=(0,r.useCallback)(e=>{let n=0;b?"ArrowRight"===e.key?n=10:"ArrowLeft"===e.key&&(n=-10):"ArrowDown"===e.key?n=10:"ArrowUp"===e.key&&(n=-10),0!==n&&(e.preventDefault(),t(n))},[b,t]);(0,r.useEffect)(()=>(f&&(document.addEventListener("mousemove",j),document.addEventListener("mouseup",k),document.addEventListener("touchmove",w),document.addEventListener("touchend",k),document.body.style.userSelect="none",document.body.style.cursor=b?"col-resize":"row-resize"),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",k),document.removeEventListener("touchmove",w),document.removeEventListener("touchend",k),document.body.style.userSelect="",document.body.style.cursor=""}),[f,j,k,w,b]);let S=(0,r.useMemo)(()=>[...l,...b?i:o,...f?["bg-accent-500","dark:bg-accent-500","dragging",b?"w-2":"h-2"]:[]].join(" "),[b,f]);return(0,a.jsx)("div",{ref:g,role:"separator","aria-orientation":n,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100,"aria-label":h("paneResizer.label",{arrows:h(b?"paneResizer.arrowsHorizontal":"paneResizer.arrowsVertical")}),tabIndex:0,className:S,onMouseDown:v,onTouchStart:y,onKeyDown:C,onDoubleClick:N})})},83012:(e,t,n)=>{"use strict";n.d(t,{Fx:()=>l,Uq:()=>o,bg:()=>i,fw:()=>s});var a=n(53298),r=n(73683);function s(e,t){let n=new Date(e);return isNaN(n.getTime())?"":(0,a.m)(n,{addSuffix:!0,...t?{locale:t}:{}})}function l(e){let t=new Date(e);if(isNaN(t.getTime()))return"";let n=Math.round((Date.now()-t.getTime())/1e3);if(n<45)return"now";let a=Math.round(n/60);if(a<60)return"".concat(a,"m ago");let r=Math.round(a/60);if(r<24)return"".concat(r,"h ago");let s=Math.round(r/24);return s<7?"".concat(s,"d ago"):s<30?"".concat(Math.round(s/7),"w ago"):s<365?"".concat(Math.round(s/30),"mo ago"):"".concat(Math.round(s/365),"y ago")}function i(e,t){return!(e instanceof Date)||isNaN(e.getTime())?"":(0,r.GP)(e,"PPp",t?{locale:t}:void 0)}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date;if(!(e instanceof Date)||isNaN(e.getTime()))return"";let n=t instanceof Date&&!isNaN(t.getTime())?t:new Date,a=e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate();return(0,r.GP)(e,a?"HH:mm":"M/d HH:mm")}},85872:(e,t,n)=>{"use strict";async function a(e,t){throw Error((await e.json().catch(()=>({}))).error||"".concat(t," (").concat(e.status,")"))}n.d(t,{$C:()=>r,Ar:()=>l,KG:()=>s});let r={async list(e){var t;let n=await fetch("/api/repositories/".concat(encodeURIComponent(e),"/todos"));return n.ok?null!=(t=(await n.json()).todos)?t:[]:a(n,"Failed to load todos")},async listAll(){var e;let t=await fetch("/api/todos");return t.ok?null!=(e=(await t.json()).todos)?e:[]:a(t,"Failed to load todos")},async create(e,t){let n=await fetch("/api/repositories/".concat(encodeURIComponent(e),"/todos"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});return n.ok?(await n.json()).todo:a(n,"Failed to create todo")},async update(e,t,n){let r=await fetch("/api/repositories/".concat(encodeURIComponent(e),"/todos/").concat(encodeURIComponent(t)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return r.ok?(await r.json()).todo:a(r,"Failed to update todo")},async remove(e,t){let n=await fetch("/api/repositories/".concat(encodeURIComponent(e),"/todos/").concat(encodeURIComponent(t)),{method:"DELETE"});n.ok||await a(n,"Failed to delete todo")}},s=["todo","doing","done"],l={async list(e){var t;let n=await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/todos"));return n.ok?null!=(t=(await n.json()).todos)?t:[]:a(n,"Failed to load todos")},async create(e,t,n){let r=await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/todos"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(void 0!==n?{content:t,detail:n}:{content:t})});return r.ok?(await r.json()).todo:a(r,"Failed to create todo")},async update(e,t,n){let r=await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/todos/").concat(encodeURIComponent(t)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return r.ok?(await r.json()).todo:a(r,"Failed to update todo")},async remove(e,t){let n=await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/todos/").concat(encodeURIComponent(t)),{method:"DELETE"});n.ok||await a(n,"Failed to delete todo")},async reorder(e,t){let n=await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/todos"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({todoIds:t})});n.ok||await a(n,"Failed to reorder todos")}}},86537:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>ud});var a,r=n(95155),s=n(20063),l=n(68361),i=n(12115),o=n(67909),c=n(18955),d=n(37772),u=n(3005),m=n(28019),h=n(48481),f=n(92614),x=n(64269);let p=(0,i.memo)(function(e){let{path:t,className:n="w-6 h-6"}=e;return(0,r.jsx)("svg",{className:n,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:t})})}),g={back:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-4 0a1 1 0 01-1-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 01-1 1h-2z",menu:"M4 6h16M4 12h16M4 18h16",search:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"};function b(e){let{worktreeName:t,repositoryName:n,status:a,gitStatus:s,onBackClick:l,onMenuClick:i}=e,o=(0,c.c)("common"),d=(0,c.c)("worktree"),u=(0,c.c)("commandPalette"),{setOpen:b}=(0,f.C)();return(0,r.jsx)("header",{"data-testid":"mobile-header",role:"banner",className:"sticky top-0 inset-x-0 bg-surface border-b border-border shadow-sm pt-safe z-40",children:(0,r.jsxs)("div",{className:"flex items-center justify-between h-14 px-4",children:[(0,r.jsx)("div",{className:"w-10 flex-shrink-0",children:l&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:l,"aria-label":o("back"),className:"p-2 -ml-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(p,{path:g.back})})}),(0,r.jsxs)("div",{className:"flex-1 flex items-center justify-center min-w-0 px-2",children:[(0,r.jsx)(h.m,{"data-testid":"status-indicator",status:a,size:"sm",className:"mr-2"}),(0,r.jsxs)("div",{className:"flex flex-col items-center min-w-0",children:[(0,r.jsx)("h1",{role:"heading","data-testid":"worktree-name",title:t,className:"text-sm font-medium text-foreground truncate text-center leading-tight",children:t}),(0,r.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[n&&(0,r.jsx)("span",{className:"truncate max-w-[100px] text-center",children:n}),s&&"(unknown)"!==s.currentBranch&&(0,r.jsxs)(r.Fragment,{children:[n&&(0,r.jsx)("span",{className:"text-muted-foreground/50",children:"/"}),(0,r.jsx)("span",{className:"truncate max-w-[80px] font-mono",title:s.currentBranch,"data-testid":"mobile-branch-name",children:(0,x.W5)(s.currentBranch,20)}),s.isDirty&&(0,r.jsx)("span",{className:"text-warning",title:d("git.uncommittedChanges"),children:"*"})]})]})]})]}),(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-end",children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button","data-testid":"mobile-header-command-palette-trigger",onClick:()=>b(!0),"aria-label":u("mobileTrigger"),title:u("mobileTrigger"),className:"p-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(p,{path:g.search})}),i&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:i,"aria-label":o("menu"),className:"p-2 -mr-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(p,{path:g.menu})})]})]})})}var v=n(22479),y=n(26983),j=n(59847),w=n(53842),k=n(23327);function N(e){let{"data-testid":t,"aria-label":n,className:a=""}=e;return(0,r.jsx)("span",{"data-testid":t,className:"w-2 h-2 rounded-full bg-accent-500 ".concat(a).trim(),"aria-label":n})}let C=[{id:"terminal",labelKey:"tabs.terminal",icon:(0,r.jsx)(v.A,{size:20,"aria-hidden":"true"})},{id:"history",labelKey:"tabs.history",icon:(0,r.jsx)(y.A,{size:20,"aria-hidden":"true"})},{id:"files",labelKey:"tabs.files",icon:(0,r.jsx)(j.A,{size:20,"aria-hidden":"true"})},{id:"memo",labelKey:"tabs.memo",icon:(0,r.jsx)(w.A,{size:20,"aria-hidden":"true"})},{id:"info",labelKey:"tabs.info",icon:(0,r.jsx)(k.A,{size:20,"aria-hidden":"true"})}];function S(e){let{activeTab:t,onTabChange:n,hasNewOutput:a=!1,hasPrompt:s=!1,hasUpdate:l=!1,onSearchParamsChange:o,inFlow:d=!1}=e,u=(0,c.c)("worktree"),m=(0,i.useRef)([]),h=(0,i.useCallback)(e=>{let n=e===t;return"".concat("flex flex-col items-center justify-center flex-1 min-h-[44px] py-2 px-1 transition-colors relative touch-manipulation"," ").concat(n?"text-accent-600 dark:text-accent-400":"text-muted-foreground hover:text-foreground")},[t]),f=(0,i.useCallback)(e=>{n(e),null==o||o("memo"===e?"notes":e)},[n,o]),x=(0,i.useCallback)((e,t)=>{var n;let a=null;switch(e.key){case"ArrowRight":case"ArrowDown":a=(t+1)%C.length;break;case"ArrowLeft":case"ArrowUp":a=(t-1+C.length)%C.length;break;case"Home":a=0;break;case"End":a=C.length-1;break;default:return}e.preventDefault(),null==(n=m.current[a])||n.focus(),f(C[a].id)},[f]),p=(0,i.useMemo)(()=>(0,r.jsxs)(r.Fragment,{children:[a&&(0,r.jsx)("span",{"data-testid":"new-output-badge",className:"absolute top-1 right-1 w-2 h-2 bg-success rounded-full","aria-label":u("tabs.newOutput")}),s&&(0,r.jsx)("span",{"data-testid":"prompt-badge",className:"absolute top-1 right-3 w-2 h-2 bg-warning rounded-full","aria-label":u("tabs.promptWaiting")})]}),[a,s,u]);return(0,r.jsx)("nav",{"data-testid":"mobile-tab-bar",role:"tablist","aria-label":u("tabs.ariaLabel"),className:"".concat(d?"flex-shrink-0":"fixed bottom-0"," inset-x-0 border-t border-border bg-background supports-[backdrop-filter]:bg-background/80 backdrop-blur-md flex pb-safe z-40"),children:C.map((e,n)=>(0,r.jsxs)("button",{ref:e=>{m.current[n]=e},type:"button","data-testid":"mobile-tab-".concat(e.id),role:"tab","aria-selected":t===e.id,"aria-label":u(e.labelKey),tabIndex:t===e.id?0:-1,onClick:()=>f(e.id),onKeyDown:e=>x(e,n),className:h(e.id),children:[t===e.id&&(0,r.jsx)("span",{"aria-hidden":"true",className:"absolute top-0 inset-x-2 h-0.5 rounded-full bg-accent-500"}),e.icon,(0,r.jsx)("span",{className:"text-xs mt-1 whitespace-nowrap",children:u(e.labelKey)}),"terminal"===e.id&&p,"info"===e.id&&l&&(0,r.jsx)(N,{"data-testid":"info-update-badge",className:"absolute top-1 right-1","aria-label":u("tabs.updateAvailable")})]},e.id))})}let T="unclassified";function I(e){return null!=e&&e.type!==T}class E extends i.Component{static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){var n,a;console.error("[ErrorBoundary:".concat(this.props.componentName||"unknown","]"),e,t),null==(n=(a=this.props).onError)||n.call(a,e,t)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,r.jsx)(A,{componentName:this.props.componentName,error:this.state.error,onRetry:this.handleRetry}):this.props.children}constructor(e){super(e),this.handleRetry=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}}function A(e){let{componentName:t,error:n,onRetry:a}=e,s=(0,c.c)("error"),l=(0,c.c)("common");return(0,r.jsxs)("div",{className:"p-4 bg-danger-subtle border border-danger-border rounded-lg",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-danger-foreground mb-2",children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),(0,r.jsx)("span",{className:"font-medium",children:t?s("boundary.errorOccurredIn",{componentName:t}):s("boundary.errorOccurred")})]}),n&&(0,r.jsx)("p",{className:"text-sm text-danger-foreground/80 mb-3",children:n.message}),a&&(0,r.jsx)("button",{onClick:a,className:"px-4 py-2 bg-danger-foreground text-danger-subtle rounded hover:opacity-90 transition-opacity text-sm",children:l("retry")})]})}let M={fadeIn:"animate-fade-in",fadeOut:"animate-fade-out",none:""};function L(e){let{visible:t,duration:n=200}=e,[a,r]=(0,i.useState)(t?"visible":"hidden"),s=(0,i.useRef)(null),l=(0,i.useRef)(t);(0,i.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),(0,i.useEffect)(()=>{let e=l.current;l.current=t,s.current&&(clearTimeout(s.current),s.current=null);let a=e=>{s.current=setTimeout(()=>{r(e),s.current=null},n)};t&&!e?(r("fade-in"),a("visible")):!t&&e?(r("fade-out"),a("hidden")):t?r(e=>"fade-out"===e?(a("visible"),"fade-in"):e):r(e=>"fade-in"===e?(a("hidden"),"fade-out"):e)},[t,n]);let o="hidden"!==a,c="fade-in"===a||"fade-out"===a;return{shouldRender:o,animationClass:(0,i.useMemo)(()=>{switch(a){case"fade-in":return M.fadeIn;case"fade-out":return M.fadeOut;default:return M.none}},[a]),isAnimating:c}}var R=n(92539),P=n(8269);let D={base:"px-6 py-3 rounded-lg font-medium transition-all touch-manipulation disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus:ring-2 focus:ring-offset-2",primary:"bg-accent-600 text-white hover:bg-accent-700 focus:ring-ring",secondary:"bg-muted border-2 border-input hover:bg-muted/80 text-foreground focus:ring-ring",defaultSelected:"bg-muted-foreground text-background hover:bg-muted-foreground/90"},F=(0,i.memo)(function(e){let{promptData:t,visible:n,answering:a,onRespond:s,onDismiss:l,cliToolName:o}=e,{shouldRender:c,animationClass:d}=L({visible:n&&null!==t,duration:300}),u=(0,i.useId)(),m=n&&null!==t,h=(0,R.r)({active:m}),[f,x]=(0,i.useState)(0);(0,i.useEffect)(()=>{n||x(0)},[n]);let p=(0,i.useCallback)(e=>{let{deltaY:t}=e;x(t>0?t:0)},[]),g=(0,i.useCallback)(()=>{null==l||l()},[l]),b=(0,i.useCallback)(()=>{x(0)},[]),{ref:v}=(0,P.hU)({axis:"vertical",threshold:100,enabled:m,onSwipeMove:p,onSwipeDown:g,onSwipeEnd:b}),y=(0,i.useCallback)(e=>{h.current=e,v.current=e},[h,v]),j=(0,i.useCallback)(()=>{l&&l()},[l]),w=(0,i.useCallback)(e=>{e.stopPropagation()},[]);if(!c||!t)return null;let k="animate-fade-out"===d;return(0,r.jsxs)(E,{componentName:"MobilePromptSheet",children:[(0,r.jsx)("div",{"data-testid":"prompt-overlay",onClick:j,className:"fixed inset-0 bg-black/50 z-50 transition-opacity duration-300 ".concat(k?"opacity-0":"opacity-100"," ").concat(k?"pointer-events-none":""),"aria-hidden":"true"}),(0,r.jsxs)("div",{ref:y,"data-testid":"mobile-prompt-sheet",role:"dialog","aria-modal":"true","aria-labelledby":u,onClick:w,style:{transform:f>0?"translateY(".concat(f,"px)"):void 0},className:"fixed bottom-0 inset-x-0 bg-surface rounded-t-2xl z-50 pb-safe transform transition-transform duration-300 ".concat(k?"translate-y-full":"translate-y-0"),children:[(0,r.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,r.jsx)("div",{"data-testid":"drag-handle",className:"w-10 h-1 bg-input rounded-full","aria-hidden":"true"})}),(0,r.jsx)("div",{className:"px-4 pb-6",children:(0,r.jsx)(O,{promptData:t,answering:a,onRespond:s,labelId:u,cliToolName:o})})]})]})});function O(e){let{promptData:t,answering:n,onRespond:a,labelId:s,cliToolName:l}=e,o=(0,c.c)("prompt"),[d,u]=(0,i.useState)(()=>{if("multiple_choice"===t.type){var e;let n=t.options.find(e=>e.isDefault);return null!=(e=null==n?void 0:n.number)?e:null}return null}),[h,f]=(0,i.useState)(""),[x,p]=(0,i.useState)(!1),g=(0,i.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===d))?e:null},[t,d]),b=(null==g?void 0:g.requiresTextInput)===!0,v=n||x,y=(0,i.useCallback)(async e=>{if(!v){p(!0);try{await a(e)}catch(e){}finally{p(!1)}}},[v,a]),j=(0,i.useCallback)(async()=>{if(!v&&null!==d){p(!0);try{let e=b&&h.trim()?h.trim():d.toString();await a(e)}catch(e){}finally{p(!1)}}},[v,a,d,b,h]);return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("h3",{id:s,className:"text-lg font-semibold text-foreground",children:l?o("confirmationFrom",{toolName:l}):o("confirmationFromClaude")}),I(t)&&t.instructionText&&(0,r.jsx)("div",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap text-sm text-muted-foreground bg-muted rounded p-2 border border-border",children:t.instructionText}),(0,r.jsx)("p",{className:"text-foreground leading-relaxed",children:t.question}),v&&(0,r.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-muted-foreground",role:"status","aria-live":"polite",children:[(0,r.jsx)(m.y$,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{children:o("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(z,{promptData:t,disabled:v,onYes:()=>y("yes"),onNo:()=>y("no")}),"multiple_choice"===t.type&&(0,r.jsx)(_,{promptData:t,disabled:v,selectedOption:d,onSelectOption:u,textInputValue:h,onTextInputChange:f,showTextInput:b,onSubmit:j})]})}let z=(0,i.memo)(function(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),i="yes"===t.defaultOption,o="no"===t.defaultOption;return(0,r.jsxs)("div",{className:"flex gap-3",role:"group","aria-label":l("yesNoGroupLabel"),children:[(0,r.jsx)("button",{type:"button",onClick:a,disabled:n,className:"flex-1 ".concat(D.base," ").concat(D.primary," ").concat(i?"ring-2 ring-accent-300":""),children:l("yes")}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:n,className:"flex-1 ".concat(D.base," ").concat(o?D.defaultSelected:D.secondary),children:l("no")})]})}),_=(0,i.memo)(function(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:o,showTextInput:d,onSubmit:u}=e,h=(0,i.useId)(),f=(0,c.c)("prompt");return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("fieldset",{children:[(0,r.jsx)("legend",{className:"sr-only",children:f("selectAnOption")}),(0,r.jsx)(m.z6,{name:h,value:null!=a?String(a):"",onValueChange:e=>s(Number(e)),disabled:n,className:"flex flex-col gap-2",children:t.options.map(e=>{let t=a===e.number;return(0,r.jsxs)("label",{className:"flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all ".concat(t?"bg-accent-50 dark:bg-accent-900/30 border-2 border-accent-500":"bg-surface border-2 border-border hover:border-input"," ").concat(n?"opacity-50 cursor-not-allowed":""),children:[(0,r.jsx)(m.CU,{value:String(e.number),className:"mt-1"}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("span",{className:"font-medium text-foreground",children:[e.number,". ",e.label]}),e.isDefault&&(0,r.jsx)("span",{className:"ml-2 text-xs text-accent-600 bg-accent-100 px-2 py-0.5 rounded",children:f("default")})]})]},e.number)})})]}),d&&(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("label",{htmlFor:"text-input-".concat(h),className:"sr-only",children:f("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>o(e.target.value),disabled:n,placeholder:f("enterValuePlaceholder"),inputMode:"text",enterKeyHint:"done",className:"w-full px-4 py-3 border-2 border-input rounded-lg bg-surface text-foreground focus:outline-none focus:border-ring disabled:opacity-50"})]}),(0,r.jsx)("button",{type:"button",onClick:u,disabled:n||null===a,className:"w-full ".concat(D.base," ").concat(D.primary),children:f("submit")})]})});var B=n(86651),H=n(11047),V=n(84926),U=n(37586),K=n(24033),W=n(97624),$=n(37354),q=n(54014),G=n(75676),J=n(26232),Y=n(41898),Q=n(66966),X=n(83012);let Z="application/x-commandmate-agent-instance",ee=[{mode:"terminal",labelKey:"surfaceMode.showTerminal",icon:v.A},{mode:"chat",labelKey:"surfaceMode.showChat",icon:U.A}],et="session-note-open";function en(e,t){let n=(0,Q.rC)(),a=null==n?void 0:n.worktrees,r=null==n?void 0:n.refresh,s=(0,i.useMemo)(()=>(function(e,t,n){var a;let r=null==e?void 0:e.find(e=>e.id===t),s=null==r||null==(a=r.sessionNotes)?void 0:a[n];return s&&"string"==typeof s.text&&0!==s.text.length?{text:s.text,updatedAt:"number"==typeof s.updatedAt?s.updatedAt:0}:null})(a,e,t),[a,e,t]),[l,o]=(0,i.useState)(null);(0,i.useEffect)(()=>{o(null)},[e,t]),(0,i.useEffect)(()=>{var e,t;if(null===l)return;let n=null===l.value?null===s:null!==s&&s.text===l.value.text,a=(null==s?void 0:s.text)!==(null==(e=l.base)?void 0:e.text)||(null==s?void 0:s.updatedAt)!==(null==(t=l.base)?void 0:t.updatedAt);(n||a)&&o(null)},[l,s]);let c=(0,i.useCallback)(n=>{let a=n.replace(/\s+/g," ").trim();Array.from(a).length>100||(o({value:a.length>0?{text:a,updatedAt:Date.now()}:null,base:s}),(async()=>{try{if(!(await fetch("/api/worktrees/".concat(encodeURIComponent(e),"/instances/notes"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({instanceId:t,text:a})})).ok)return void o(null);await (null==r?void 0:r())}catch(e){o(null)}})())},[t,r,s,e]);return{note:l?l.value:s,save:c}}function ea(e){let{initialText:t,onCommit:n,onCancel:a,ariaLabel:s,placeholder:l,testId:o}=e,[c,d]=(0,i.useState)(t),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e,t;null==(e=u.current)||e.focus(),null==(t=u.current)||t.select()},[]);let m=(0,i.useCallback)(e=>{if("Enter"===e.key){if(e.nativeEvent.isComposing)return;e.preventDefault(),n(c);return}"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a())},[a,n,c]);return(0,r.jsx)("input",{ref:u,type:"text",value:c,maxLength:100,placeholder:l,"aria-label":s,"data-testid":o,onChange:e=>d(e.target.value),onKeyDown:m,className:"w-full rounded border border-border bg-surface px-2 py-1 text-xs text-surface-foreground placeholder:text-muted-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"})}let er=(0,i.memo)(function(e){var t;let{worktreeId:n,splitIndex:a,cliToolId:s,instanceId:l,instance:o,availableInstances:d,onInstanceChange:u,status:m="idle",agentModel:f,agentUsage:x,agentUsageDetail:p,onFocus:g,attaching:b=!1,headerExtras:v,surfaceMode:y=G.wf,onSurfaceModeChange:j,isMaximized:w=!1,onToggleMaximize:k,terminal:N,footer:C,style:S,onDropInstance:T,draggedInstanceId:I}=e,E=(0,c.c)("worktree"),[A,M]=(0,i.useState)(null),{note:L,save:R}=en(n,l),[P,D]=(0,i.useState)(!1);(0,i.useEffect)(()=>{D(!1)},[n,l]);let F=(0,i.useCallback)(()=>D(!0),[]),O=(0,i.useCallback)(()=>D(!1),[]),z=(0,i.useCallback)(e=>{R(e),D(!1)},[R]),_=(0,i.useCallback)(()=>{setTimeout(()=>D(!0),0)},[]),B=null!=T,V=(0,i.useCallback)(()=>null==I||d.some(e=>e.id===I)?"allowed":"forbidden",[I,d]),U=(0,i.useCallback)(e=>{if(!B)return;e.preventDefault();let t=V();e.dataTransfer.dropEffect="forbidden"===t?"none":"move",M(e=>e===t?e:t)},[B,V]),Q=(0,i.useCallback)(e=>{if(!B)return;e.preventDefault();let t=V();M(e=>e===t?e:t)},[B,V]),et=(0,i.useCallback)(()=>{B&&M(null)},[B]),er=(0,i.useCallback)(e=>{if(!B)return;e.preventDefault(),M(null);let t=e.dataTransfer.getData(Z);t&&(null==T||T(t))},[B,T]),es=(0,i.useCallback)(()=>{window.dispatchEvent(new CustomEvent("terminal-search-open"))},[]),el=(0,i.useCallback)(()=>{g()},[g]),ei="Terminal split ".concat(a+1),eo=(0,q.sw)(null!=o?o:{cliTool:s}),ec=E("terminal.selectInstance",{split:ei}),ed=E("terminal.searchOutput",{split:ei}),eu=E("sessionNote.editLabel",{split:ei}),em=L?(0,X.Uq)(new Date(L.updatedAt)):"",eh=L?E("sessionNote.label",{note:L.text,time:em}):"";return(0,r.jsxs)("div",{role:"region","aria-label":ei,"data-testid":"terminal-split-pane-".concat(a),"data-split-index":a,style:S,className:"flex flex-col min-w-0 h-full rounded-lg overflow-hidden border border-border bg-surface".concat(null===A?" focus-within:ring-1 focus-within:ring-accent-500/30":"").concat("allowed"===A?" ring-2 ring-accent-400":"forbidden"===A?" ring-2 ring-red-300 cursor-not-allowed":""),onFocusCapture:el,onMouseDown:g,onDragOver:U,onDragEnter:Q,onDragLeave:et,onDrop:er,children:[(0,r.jsxs)("div",{className:"relative px-2 py-1 flex items-center gap-2 bg-surface-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)(J.rI,{children:[(0,r.jsxs)(J.ty,{"data-testid":"cli-selector-".concat(a),"aria-label":ec,className:"flex items-center gap-1.5 min-w-0 max-w-[12rem] rounded px-1.5 py-0.5 text-xs border border-border bg-surface text-surface-foreground hover:bg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:ring-2 data-[state=open]:ring-ring transition-colors",children:[(0,r.jsx)(h.m,{status:m,size:"sm","aria-hidden":!0,"data-testid":"split-status-indicator-".concat(a)}),(0,r.jsx)("span",{className:"truncate",children:eo}),(0,r.jsx)(K.A,{size:14,"aria-hidden":"true",className:"flex-shrink-0 opacity-70"})]}),(0,r.jsxs)(J.SQ,{align:"start",className:"min-w-[10rem]",children:[(0,r.jsx)(J.Hr,{value:l,onValueChange:u,children:d.map(e=>(0,r.jsx)(J.Ht,{value:e.id,children:(0,q.sw)(e)},e.id))}),(0,r.jsx)(J.mB,{}),(0,r.jsxs)(J._2,{"data-testid":"split-session-note-menu-item-".concat(a),onSelect:_,children:[(0,r.jsx)(H.A,{size:14,"aria-hidden":"true",className:"opacity-70"}),E("sessionNote.menuItem")]})]})]}),j?(0,r.jsx)("div",{role:"group","aria-label":E("surfaceMode.groupLabel",{split:ei}),"data-testid":"surface-mode-toggle-".concat(a),className:"flex flex-shrink-0 items-center gap-0.5 rounded border border-border bg-surface p-0.5",children:ee.map(e=>{let{mode:t,labelKey:n,icon:s}=e,l=y===t,i=E(n);return(0,r.jsx)(Y.m_,{content:i,placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:()=>j(t),"aria-pressed":l,"aria-label":i,"data-testid":"surface-mode-".concat(t,"-").concat(a),className:"flex items-center justify-center rounded px-1.5 py-0.5 touch-manipulation transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ".concat(l?"bg-accent-500/15 text-accent-600 dark:text-accent-400":"text-muted-foreground hover:bg-muted hover:text-surface-foreground"),children:(0,r.jsx)(s,{size:14,"aria-hidden":"true"})})},t)})}):null,f&&(0,r.jsx)("span",{"data-testid":"split-agent-model-".concat(a),title:E("agentModel.modelLabel",{model:f}),className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground ".concat(L?"max-w-[5rem] shrink-[4]":"max-w-[10rem]"),children:f}),x&&(0,r.jsx)("span",{"data-testid":"split-agent-usage-".concat(a),title:null!=p?p:E("agentSession.chipLabel",{usage:x}),className:"min-w-0 max-w-[10rem] truncate text-[11px] leading-none tabular-nums text-muted-foreground",children:x}),L&&(0,r.jsxs)("button",{type:"button",onClick:F,"aria-label":eu,title:eh,"data-testid":"split-session-note-".concat(a),className:"flex min-w-0 max-w-[16rem] shrink items-center gap-1 rounded px-1 py-0.5 text-[11px] leading-none text-muted-foreground hover:bg-muted-foreground/10 hover:text-surface-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,r.jsx)(H.A,{size:11,"aria-hidden":"true",className:"shrink-0 opacity-70"}),(0,r.jsx)("span",{className:"min-w-0 truncate",children:L.text}),(0,r.jsx)("span",{"data-testid":"split-session-note-time-".concat(a),className:"shrink-0 tabular-nums opacity-70",children:em})]}),v,(0,r.jsx)(Y.m_,{content:ed,placement:"bottom",className:"ml-auto",children:(0,r.jsx)("button",{type:"button",onClick:es,"aria-label":ed,"data-testid":"terminal-search-button-".concat(a),className:"flex items-center gap-1 px-1.5 py-0.5 text-xs text-muted-foreground hover:text-surface-foreground hover:bg-muted-foreground/10 rounded transition-colors",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})})}),k?(0,r.jsx)(Y.m_,{content:"".concat(w?E("terminal.restoreSplits"):E("terminal.maximizeSplit",{split:ei})," — ").concat(E("terminal.maximizeShortcutHint")),placement:"bottom",className:"flex-shrink-0",children:(0,r.jsx)("button",{type:"button",onClick:k,"aria-pressed":w,"aria-label":w?E("terminal.restoreSplits"):E("terminal.maximizeSplit",{split:ei}),"data-testid":"toggle-maximize-".concat(a),className:"flex flex-shrink-0 items-center justify-center px-1.5 py-0.5 text-muted-foreground hover:text-surface-foreground hover:bg-muted-foreground/10 rounded transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:w?(0,r.jsx)(W.A,{size:14,"aria-hidden":"true"}):(0,r.jsx)($.A,{size:14,"aria-hidden":"true"})})}):null,P?(0,r.jsxs)("div",{"data-testid":"split-session-note-editor-".concat(a),className:"absolute inset-x-2 top-full z-30 mt-1 rounded-md border border-border bg-surface p-2 shadow-lg",children:[(0,r.jsx)(ea,{initialText:null!=(t=null==L?void 0:L.text)?t:"",onCommit:z,onCancel:O,ariaLabel:eu,placeholder:E("sessionNote.placeholder"),testId:"split-session-note-input-".concat(a)}),(0,r.jsx)("p",{className:"mt-1 text-[10px] leading-tight text-muted-foreground",children:E("sessionNote.hint")})]}):null]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[b?(0,r.jsxs)("div",{"data-testid":"terminal-attach-skeleton-".concat(a),className:"absolute inset-0 flex items-center justify-center text-xs text-muted-foreground bg-surface-2/80",role:"status","aria-live":"polite",children:["Attaching ",eo," session..."]}):null,N]}),(0,r.jsx)("div",{className:"flex-shrink-0 border-t border-border p-2 bg-surface-2",children:C})]})});function es(e){let{open:t,onClose:n,onSearch:a,onEnd:s,endDisabled:l=!1}=e,o=(0,c.c)("worktree"),d=(0,i.useId)(),u=(0,R.r)({active:t}),m=(0,i.useCallback)(()=>{a(),n()},[a,n]),h=(0,i.useCallback)(()=>{s(),n()},[s,n]),f=(0,i.useCallback)(()=>{window.dispatchEvent(new CustomEvent(et)),n()},[n]);return((0,i.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&n()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,n]),t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{"data-testid":"terminal-actions-overlay",onClick:n,className:"fixed inset-0 bg-black/50 z-50","aria-hidden":"true"}),(0,r.jsxs)("div",{ref:u,"data-testid":"mobile-terminal-actions-sheet",role:"dialog","aria-modal":"true","aria-labelledby":d,tabIndex:-1,className:"fixed bottom-0 inset-x-0 z-50 rounded-t-2xl border-t border-border bg-surface pb-safe",children:[(0,r.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,r.jsx)("div",{className:"w-10 h-1 rounded-full bg-muted-foreground/30","aria-hidden":"true"})}),(0,r.jsx)("h2",{id:d,className:"px-4 pb-2 text-sm font-medium text-muted-foreground",children:o("terminal.moreActions")}),(0,r.jsxs)("div",{className:"px-2 pb-4",children:[(0,r.jsxs)("button",{type:"button","data-testid":"actions-sheet-search",onClick:m,className:"flex w-full items-center gap-3 rounded-lg px-3 py-3 text-sm text-foreground hover:bg-muted transition-colors touch-manipulation",children:[(0,r.jsx)(B.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),o("terminal.searchTerminal")]}),(0,r.jsxs)("button",{type:"button","data-testid":"actions-sheet-session-note",onClick:f,className:"flex w-full items-center gap-3 rounded-lg px-3 py-3 text-sm text-foreground hover:bg-muted transition-colors touch-manipulation",children:[(0,r.jsx)(H.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),o("sessionNote.menuItem")]}),(0,r.jsxs)("button",{type:"button","data-testid":"actions-sheet-end",onClick:h,disabled:l,className:"flex w-full items-center gap-3 rounded-lg px-3 py-3 text-sm text-danger hover:bg-danger/10 transition-colors touch-manipulation disabled:opacity-40 disabled:hover:bg-transparent",children:[(0,r.jsx)(V.A,{size:18,"aria-hidden":"true"}),o("terminal.endSession")]})]})]})]}):null}var el=n(80344),ei=n(79651);function eo(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e=>{var t;return null!=(t=e.description)?t:""};if(!t.trim())return e;let a=t.toLowerCase();return e.map(e=>({...e,commands:e.commands.filter(e=>{let t=e.name.toLowerCase().includes(a),r=n(e).toLowerCase().includes(a);return t||r})})).filter(e=>e.commands.length>0)}function ec(e,t){return"codex-skill"===e.source?"antigravity"===t?"/".concat(e.name):"$".concat(e.name):"/".concat(e.name)}function ed(e,t){var n;return e.descriptionKey?t(e.descriptionKey):null!=(n=e.description)?n:""}function eu(e){let{groups:t,onSelect:n,highlightedIndex:a=-1,className:s="",cliToolId:l}=e,i=(0,c.c)("worktree"),o=0;return 0===t.length?(0,r.jsx)("div",{className:"text-sm text-muted-foreground p-4 text-center ".concat(s),children:i("slashCommands.empty")}):(0,r.jsx)("div",{className:"overflow-y-auto ".concat(s),children:t.map(e=>(0,r.jsxs)("div",{className:"mb-2",children:[(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider bg-muted",children:e.label}),(0,r.jsx)("div",{children:e.commands.map(e=>{var t;let s=o;o++;let c=s===a;return(0,r.jsxs)("button",{type:"button","data-command-item":!0,"data-highlighted":c,onClick:()=>n(e),className:"w-full px-3 py-2 text-left flex items-start gap-2 hover:bg-accent-50 dark:hover:bg-accent-900/30 transition-colors ".concat(c?"bg-accent-100 dark:bg-accent-900/40":""),children:[(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 font-mono text-sm flex-shrink-0",children:ec(e,l)}),(null==(t=e.cliTools)?void 0:t.length)===1&&"codex"===e.cliTools[0]&&(0,r.jsx)("span",{className:"mt-0.5 rounded border border-accent-200 bg-accent-50 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-accent-700 dark:border-accent-800 dark:bg-accent-950/40 dark:text-accent-300",children:"Codex"}),"user-catalog"===e.source&&(0,r.jsx)("span",{"data-testid":"user-catalog-badge",className:"mt-0.5 rounded border border-border bg-muted px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:i("slashCommands.sourceBadge.userCatalog")}),(0,r.jsx)("span",{className:"text-muted-foreground text-sm truncate",children:ed(e,i)})]},e.name)})})]},e.category))})}function em(e,t,n){if(t<=0||n<=0)return 0;let a=e+t+8-n;return a>0?-Math.min(a,Math.max(0,e-8)):e<8?8-e:0}let eh=(0,i.memo)(function(e){let{isOpen:t,groups:n,onSelect:a,onClose:s,isMobile:l=!1,position:o,onFreeInput:d,isCatalogStale:u=!1,cliToolId:m}=e,[h,f]=(0,i.useState)(""),[x,p]=(0,i.useState)(0),g=(0,i.useRef)(null),b=(0,i.useRef)(null),v=(0,i.useRef)({x:0,y:0}),[y,j]=(0,i.useState)({x:0,y:0}),w=(0,c.c)("worktree"),k=(0,c.c)("common"),N=(0,i.useMemo)(()=>eo(n,h,e=>ed(e,w)),[n,h,w]),C=(0,i.useMemo)(()=>N.flatMap(e=>e.commands),[N]);(0,i.useEffect)(()=>{t&&(f(""),p(0),setTimeout(()=>{var e;null==(e=g.current)||e.focus()},50))},[t]);let S=(0,i.useCallback)(e=>{a(e),s()},[a,s]),T=(0,i.useCallback)(e=>{if(t)switch(e.key){case"Escape":e.preventDefault(),s();break;case"ArrowDown":e.preventDefault(),p(e=>Math.min(e+1,C.length-1));break;case"ArrowUp":e.preventDefault(),p(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),C[x]&&S(C[x])}},[t,C,x,s,S]);if((0,i.useEffect)(()=>{if(t)return document.addEventListener("keydown",T),()=>{document.removeEventListener("keydown",T)}},[t,T]),(0,i.useLayoutEffect)(()=>{let e=e=>{v.current=e,j(t=>t.x===e.x&&t.y===e.y?t:e)};if(!t||l)return void e({x:0,y:0});let n=b.current;if(!n)return;let a=n.getBoundingClientRect();e({x:em(a.left-v.current.x,a.width,window.innerWidth),y:em(a.top-v.current.y,a.height,window.innerHeight)})},[t,l,N,null==o?void 0:o.top,null==o?void 0:o.left]),!t)return null;let I=u?(0,r.jsx)("div",{"data-testid":"slash-command-stale-note",className:"px-3 py-2 border-t border-border text-xs text-muted-foreground",children:w("slashCommands.catalogStale.hint")}):null;if(l)return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40",onClick:s,"aria-hidden":"true"}),(0,r.jsxs)("div",{"data-testid":"slash-command-bottom-sheet",className:"fixed bottom-0 left-0 right-0 bg-surface rounded-t-xl z-50 max-h-[70vh] flex flex-col shadow-xl",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:w("slashCommands.title")}),(0,r.jsx)("button",{type:"button",onClick:s,"aria-label":k("close"),className:"p-2 rounded-full hover:bg-muted",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{className:"px-4 py-2 border-b border-border",children:(0,r.jsx)("input",{ref:g,type:"text",value:h,onChange:e=>f(e.target.value),placeholder:w("slashCommands.searchPlaceholder"),className:"w-full px-3 py-2 border border-input bg-surface dark:bg-surface-2 text-foreground rounded-lg focus:outline-none focus:ring-2 focus:ring-ring"})}),d&&(0,r.jsxs)("button",{type:"button","data-testid":"free-input-button",onClick:()=>d(h),className:"w-full px-4 py-3 text-left border-b border-border flex items-center gap-2 hover:bg-accent-50 dark:hover:bg-accent-900/30 transition-colors",children:[(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,r.jsx)("span",{className:"text-muted-foreground",children:w("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(eu,{groups:N,onSelect:S,highlightedIndex:x,className:"flex-1 overflow-y-auto pb-20",cliToolId:m}),I]})]});let E=o?{top:o.top,left:o.left}:{bottom:"100%",left:0,marginBottom:"4px"};return(0,r.jsxs)("div",{ref:b,role:"listbox","data-testid":"slash-command-dropdown",className:"absolute bg-surface border border-border rounded-lg shadow-lg z-50 w-80 max-h-96 flex flex-col",style:0!==y.x||0!==y.y?{...E,transform:"translate(".concat(y.x,"px, ").concat(y.y,"px)")}:E,children:[(0,r.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,r.jsx)("input",{ref:g,type:"text",value:h,onChange:e=>f(e.target.value),placeholder:w("slashCommands.searchPlaceholder"),className:"w-full px-3 py-1.5 text-sm border border-input bg-surface dark:bg-surface-2 text-foreground rounded focus:outline-none focus:ring-1 focus:ring-ring"})}),d&&(0,r.jsxs)("button",{type:"button","data-testid":"free-input-button",onClick:()=>d(h),className:"w-full px-3 py-2 text-left border-b border-border flex items-center gap-2 hover:bg-accent-50 dark:hover:bg-accent-900/30 transition-colors text-sm",children:[(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400",children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,r.jsx)("span",{className:"text-muted-foreground",children:w("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(eu,{groups:N,onSelect:S,highlightedIndex:x,className:"flex-1 overflow-y-auto",cliToolId:m}),I,(0,r.jsxs)("div",{className:"px-3 py-1.5 border-t border-border text-xs text-muted-foreground flex gap-3",children:[(0,r.jsxs)("span",{children:[(0,r.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded",children:"Enter"})," ",w("slashCommands.selectHint")]}),(0,r.jsxs)("span",{children:[(0,r.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded",children:"Esc"})," ",w("slashCommands.closeHint")]})]})]})}),ef=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disabled:s=!1,onInterrupt:l}=e,o=(0,c.c)("worktree"),[d,m]=(0,i.useState)(!1),h=(0,i.useRef)(0),f=(0,i.useCallback)(async()=>{let e=Date.now();if(!(e-h.current<1e3)){h.current=e,m(!0);try{let e=a&&a!==n?{cliToolId:n,instanceId:a}:{cliToolId:n},r=await fetch("/api/worktrees/".concat(t,"/interrupt"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(r.ok)null==l||l();else{let e=await r.json().catch(()=>({}));console.error("[InterruptButton] Failed to send interrupt:",e.error||r.statusText)}}catch(e){console.error("[InterruptButton] Error sending interrupt:",e)}finally{m(!1)}}},[t,n,a,l]);return(0,r.jsx)("button",{type:"button",onClick:f,disabled:s||d,className:"flex-shrink-0 p-2 text-danger hover:bg-danger/10 rounded-full transition-colors disabled:text-muted-foreground/40 disabled:hover:bg-transparent","aria-label":o("interrupt.stopProcessing"),"data-testid":"interrupt-button",children:d?(0,r.jsx)(u.y,{size:"md"}):(0,r.jsx)(ex,{})})});function ex(){return(0,r.jsx)("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}var ep=n(44309),eg=n(50386),eb=n(62512),ev=n(4788),ey=n(5917),ej=n(75426),ew=n(77588);let ek=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disabled:s=!1,onActionComplete:l,showToast:o}=e,d=(0,c.c)("worktree.opencodeSession"),u=(0,m.SC)(),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),[j,w]=(0,i.useState)(null),k="opencode"===n,N=null!=a?a:n,C=(0,i.useCallback)(e=>{if(o){w(null),o(e,"error");return}w(e)},[o]),S=(0,i.useCallback)((e,t,n)=>"NO_OPENCODE_PORT"===e.code?d("errorNoPort"):"NO_OPENCODE_SESSION"===e.code?d(n):e.error||t||d("errorUnknown"),[d]),T=(0,i.useCallback)(async()=>{if(k)try{let e=await fetch("/api/worktrees/".concat(t,"/opencode/share?instance=").concat(encodeURIComponent(N)));if(!e.ok)return void p(null);p(await e.json())}catch(e){p(null)}},[k,t,N]);(0,i.useEffect)(()=>{T()},[T]);let I=(0,i.useCallback)(async e=>{f(e),w(null);try{let n=await fetch("/api/worktrees/".concat(t,"/opencode/session"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,instanceId:N})});if(!n.ok){let t=await n.json().catch(()=>({}));console.error("[OpencodeSessionControls] action failed:",e,t.error||n.statusText),C(S(t,n.statusText,"errorNoSessionFork"));return}null==l||l(e),"list"!==e&&(b(null),T())}catch(e){console.error("[OpencodeSessionControls] request error:",e),C(d("errorRequestFailed"))}finally{f(null)}},[t,N,l,T,C,S,d]),E=(0,i.useCallback)(async()=>{if(await u({title:d("shareConfirmTitle"),description:d("shareConfirmBody"),confirmLabel:d("shareConfirmLabel"),variant:"danger"})){f("share"),w(null);try{let e=await fetch("/api/worktrees/".concat(t,"/opencode/share"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({instanceId:N})}),n=await e.json().catch(()=>({}));if(!e.ok||"string"!=typeof n.url){console.error("[OpencodeSessionControls] share failed:",n.error||e.statusText),C(S(n,e.statusText,"errorNoSessionShare")),T();return}b(n.url),y(!1),T()}catch(e){console.error("[OpencodeSessionControls] share request error:",e),C(d("errorRequestFailed"))}finally{f(null)}}},[u,d,t,N,T,C,S]),A=(0,i.useCallback)(async()=>{f("unshare"),w(null);try{let e=await fetch("/api/worktrees/".concat(t,"/opencode/share?instance=").concat(encodeURIComponent(N)),{method:"DELETE"});if(!e.ok){let t=await e.json().catch(()=>({}));console.error("[OpencodeSessionControls] unshare failed:",t.error||e.statusText),C(S(t,e.statusText,"errorNoSessionShare"));return}b(null),y(!1),T()}catch(e){console.error("[OpencodeSessionControls] unshare request error:",e),C(d("errorRequestFailed"))}finally{f(null)}},[t,N,T,C,S,d]),M=(0,i.useCallback)(async()=>{if(null!==g)try{await navigator.clipboard.writeText(g),y(!0),w(null)}catch(e){console.error("[OpencodeSessionControls] clipboard write failed:",e),C(d("errorCopyFailed"))}},[g,C,d]);if(!k)return null;let L=[{action:"new",icon:(0,r.jsx)(ep.A,{className:"h-5 w-5","aria-hidden":"true"})},{action:"list",icon:(0,r.jsx)(eg.A,{className:"h-5 w-5","aria-hidden":"true"})},{action:"fork",icon:(0,r.jsx)(eb.A,{className:"h-5 w-5","aria-hidden":"true"})}],R="flex-shrink-0 p-2 text-muted-foreground hover:text-accent-600 hover:bg-accent-50 dark:hover:text-accent-400 dark:hover:bg-accent-900/30 rounded-full transition-colors disabled:text-muted-foreground/50 disabled:hover:bg-transparent";return(0,r.jsxs)("div",{className:"flex items-center gap-1","data-testid":"opencode-session-controls",children:[L.map(e=>{let{action:t,icon:n}=e;return(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>void I(t),disabled:s||null!==h,className:R,"aria-label":d(t),title:d(t),"data-testid":"opencode-session-".concat(t),children:h===t?(0,r.jsx)(m.y$,{size:"md"}):n},t)}),(null==x?void 0:x.canShare)?(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>void E(),disabled:s||null!==h,className:R,"aria-label":d("share"),title:d("share"),"data-testid":"opencode-session-share",children:"share"===h?(0,r.jsx)(m.y$,{size:"md"}):(0,r.jsx)(ev.A,{className:"h-5 w-5","aria-hidden":"true"})}):null,null!==g?(0,r.jsxs)("span",{className:"flex min-w-0 items-center gap-1 rounded-full border border-warning-border bg-warning-subtle px-2 py-0.5 text-xs text-warning-foreground","data-testid":"opencode-share-result",children:[(0,r.jsx)("span",{className:"sr-only",children:d("sharePublicNotice")}),(0,r.jsx)("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"truncate text-accent-600 underline dark:text-accent-400",title:g,"data-testid":"opencode-share-url",children:g}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>void M(),className:"flex-shrink-0 rounded-full p-1 text-muted-foreground hover:text-accent-600","aria-label":d("shareCopy"),title:d("shareCopy"),"data-testid":"opencode-share-copy",children:v?(0,r.jsx)(ey.A,{className:"h-3.5 w-3.5","aria-hidden":"true"}):(0,r.jsx)(ej.A,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>void A(),disabled:null!==h,className:"flex-shrink-0 rounded-full p-1 text-muted-foreground hover:text-danger-foreground","aria-label":d("unshare"),title:d("unshare"),"data-testid":"opencode-session-unshare",children:"unshare"===h?(0,r.jsx)(m.y$,{size:"sm"}):(0,r.jsx)(ew.A,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]}):null,null!==j?(0,r.jsx)("span",{role:"alert",className:"flex min-w-0 items-center rounded-full border border-danger-border bg-danger-subtle px-2 py-0.5 text-xs text-danger-foreground",title:j,"data-testid":"opencode-session-error",children:(0,r.jsx)("span",{className:"truncate",children:j})}):null]})});var eN=n(74385),eC=n(38218),eS=n(19985);let eT="commandmate:draft-message:",eI="Queued (session busy) — your message will run after the current task finishes.";function eE(e,t){return"".concat(eT).concat(e,":").concat(t)}let eA=(0,i.memo)(function(e){let{worktreeId:t,onMessageSent:n,cliToolId:a,instanceId:s,isSessionRunning:l=!1,pendingInsertText:o,onInsertConsumed:d,splitIndex:u=0,onFocus:h,isProcessing:f=!1,showToast:x,autoYesSlot:p,onOptimisticSend:g}=e,b=(0,c.c)("worktree"),[v,y]=(0,i.useState)(""),[j,w]=(0,i.useState)(!1),[k,N]=(0,i.useState)(null),[C,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(!1),[E,A]=(0,i.useState)(!1),M=(0,i.useRef)(null),L=(0,i.useRef)(null),R=(0,i.useRef)(!1),P=(0,i.useRef)(null),D=(0,i.useRef)(null),F=(0,eC.a)(),{groups:O,isCatalogStale:z}=function(e,t){let[n,a]=(0,i.useState)([]),[r,s]=(0,i.useState)(!0),[l,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(""),[u,m]=(0,i.useState)(t||"claude"),[h,f]=(0,i.useState)({}),x=(0,i.useCallback)(async()=>{try{var n;s(!0),o(null);let r=e?"/api/worktrees/".concat(e,"/slash-commands"):"/api/slash-commands";t&&(r+="?cliTool=".concat(t));let l=await fetch(r,{cache:"no-store"});if(!l.ok)throw Error("HTTP error ".concat(l.status));let i=await l.json();a(i.groups),m(i.cliTool||t||"claude"),f(null!=(n=i.catalogStaleness)?n:{})}catch(e){o((0,el.hS)(e)),a([]),f({})}finally{s(!1)}},[e,t]);(0,i.useEffect)(()=>{x()},[x]),(0,i.useEffect)(()=>{if(!e)return;let t=t=>{let n=t.detail;(null==n?void 0:n.worktreeId)===e&&x()};return window.addEventListener(eN.I,t),()=>window.removeEventListener(eN.I,t)},[e,x]);let p=(0,i.useMemo)(()=>n.flatMap(e=>e.commands),[n]),g=(0,i.useMemo)(()=>eo(n,c),[n,c]),b=(0,i.useMemo)(()=>Object.values(h).some(e=>e.stale),[h]);return{groups:n,filteredGroups:g,allCommands:p,loading:r,error:l,filter:c,setFilter:d,refresh:(0,i.useCallback)(()=>{x()},[x]),cliTool:u,isCatalogStale:b}}(t,a),{attachedImage:_,fileInputRef:B,isUploading:H,error:V,acceptAttribute:U,openFileDialog:K,handleFileSelect:W,removeAttachment:$,resetAfterSend:q}=function(e,t){let[n,a]=(0,i.useState)(null),[r,s]=(0,i.useState)(!1),[l,o]=(0,i.useState)(null),c=(0,i.useRef)(null),d=(0,i.useCallback)(()=>{var e;null==(e=c.current)||e.click()},[]),u=(0,i.useCallback)(async n=>{var r;let l=null==(r=n.target.files)?void 0:r[0];if(!l)return;o(null);let i=function(e){let t=e.name.lastIndexOf(".");if(-1===t)return"Unsupported file format";let n=(0,eS.HB)(e.name.substring(t));if(!eS.Hv.includes(n))return"Unsupported file format: ".concat(n);if(e.size>eS.Fg){let e=eS.Fg/1024/1024;return"File size exceeds ".concat(e,"MB limit")}return null}(l);if(i){o(i),c.current&&(c.current.value="");return}s(!0);try{let n=await t(e,l);a({file:l,path:n.path})}catch(e){o(e instanceof Error?e.message:"Upload failed")}finally{s(!1),c.current&&(c.current.value="")}},[e,t]),m=(0,i.useCallback)(()=>{a(null),o(null)},[]),h=(0,i.useCallback)(()=>{a(null)},[]);return{attachedImage:n,fileInputRef:c,isUploading:r,error:l,acceptAttribute:eS.F5,openFileDialog:d,handleFileSelect:u,removeAttachment:m,resetAfterSend:h}}(t,(0,i.useCallback)((e,t)=>el.y.uploadImageFile(e,t),[]));(0,i.useEffect)(()=>{try{0===u&&function(e){try{let t="".concat(eT).concat(e),n=window.localStorage.getItem(t);if(null===n)return;let a=eE(e,0);null===window.localStorage.getItem(a)&&window.localStorage.setItem(a,n),window.localStorage.removeItem(t)}catch(e){}}(t);let e=window.localStorage.getItem(eE(t,u));e?y(e):y("")}catch(e){}return()=>{D.current&&clearTimeout(D.current)}},[t,u]),(0,i.useEffect)(()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{try{let e=eE(t,u);v?window.localStorage.setItem(e,v):window.localStorage.removeItem(e)}catch(e){}},500)},[v,t,u]),(0,i.useEffect)(()=>{let e=M.current;e&&(v?(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px")):e.style.height="24px")},[v]),(0,i.useEffect)(()=>{o&&(y(e=>""===e.trim()?o:e+"\n\n"+o),null==d||d())},[o,d]);let G=(0,i.useCallback)(async()=>{if(C||!v.trim()&&!_||j)return;let e=v.trim(),r=a||"claude",l={cliToolId:r};if(s&&s!==r&&(l.instanceId=s),_&&(l.imagePath=_.path),g){N(null),g(e,l),y(""),A(!1),q();try{window.localStorage.removeItem(eE(t,u))}catch(e){}f&&(null==x||x(eI,"warning")),null==n||n(r);return}try{w(!0),N(null);let a=await el.y.sendMessage(t,e,l);y(""),A(!1),q();try{window.localStorage.removeItem(eE(t,u))}catch(e){}f&&(null==x||x(eI,"warning")),null==n||n(r,a)}catch(e){N((0,el.hS)(e))}finally{w(!1)}},[C,v,_,j,t,a,s,n,q,u,f,x,g]),J=(0,i.useCallback)(async e=>{e.preventDefault(),await G()},[G]),Y=(0,i.useCallback)(()=>{S(!0),R.current=!1,L.current&&clearTimeout(L.current)},[]),Q=(0,i.useCallback)(()=>{S(!1),R.current=!0,L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{R.current=!1},300)},[]),X=(0,i.useCallback)(e=>{var t;y("".concat(ec(e,a)," ")),I(!1),null==(t=M.current)||t.focus()},[a]),Z=(0,i.useCallback)(()=>{var e;I(!1),A(!1),null==(e=M.current)||e.focus()},[]),ee=(0,i.useCallback)(e=>{I(!1),A(!0),y(e?"/".concat(e):"/"),setTimeout(()=>{var e;null==(e=M.current)||e.focus()},50)},[]),et=(0,i.useCallback)(e=>{let t=e.target.value;if(y(t),""===t){A(!1),I(!1);return}if(E)return;let n="/"===t||t.startsWith("/")&&!t.includes(" "),r="codex"===a&&("$"===t||t.startsWith("$")&&!t.includes(" "));n||r?I(!0):I(!1)},[E,a]),en=(0,i.useCallback)(e=>{let{keyCode:t}=e.nativeEvent;if(229!==t){if("Escape"===e.key&&T){e.preventDefault(),Z();return}if(R.current&&"Enter"===e.key){R.current=!1;return}if("Enter"===e.key&&!C&&(!T||E)){if(F)return;e.shiftKey||(e.preventDefault(),G())}}},[T,E,C,F,G,Z]);return(0,r.jsxs)("div",{ref:P,className:"space-y-2 relative","data-testid":"message-input-container",children:[(k||V)&&(0,r.jsx)("div",{className:"p-2 bg-danger-subtle border border-danger-border rounded text-sm text-danger-foreground",children:k||V}),_&&(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-1.5 bg-accent-50 dark:bg-accent-900/20 border border-accent-200 dark:border-accent-800 rounded-lg text-sm","data-testid":"image-attachment-preview",children:[(0,r.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-accent-600 dark:text-accent-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),(0,r.jsx)("span",{className:"truncate text-accent-800 dark:text-accent-300",children:_.file.name}),(0,r.jsx)("button",{type:"button",onClick:$,className:"flex-shrink-0 p-0.5 text-accent-600 hover:text-danger-foreground dark:text-accent-400 rounded transition-colors","aria-label":b("composer.removeAttachment"),"data-testid":"remove-attachment-button",children:(0,r.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("input",{ref:B,type:"file",accept:U,onChange:W,className:"hidden","data-testid":"image-file-input"}),(0,r.jsxs)("form",{onSubmit:J,className:"rounded-xl bg-surface border border-border shadow-sm px-3 py-2 focus-within:ring-2 focus-within:ring-accent-500/40 transition-shadow flex flex-col gap-1.5",children:[(0,r.jsxs)("div",{className:F?"flex flex-col gap-1":"flex items-center gap-2",children:[F&&(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>{E&&A(!1),I(!0)},className:"flex-shrink-0 p-2 text-muted-foreground hover:text-accent-600 hover:bg-accent-50 dark:hover:text-accent-400 dark:hover:bg-accent-900/30 rounded-full transition-colors","aria-label":b("composer.showSlashCommands"),"data-testid":"mobile-command-button",children:(0,r.jsx)("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 20l4-16m2 16l4-16M6 9h14M4 15h14"})})}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:K,disabled:H||j,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-accent-600 hover:bg-accent-50 dark:hover:text-accent-400 dark:hover:bg-accent-900/30 rounded-full transition-colors disabled:text-muted-foreground/50 disabled:hover:bg-transparent","aria-label":b("composer.attachImage"),"data-testid":"attach-image-button",children:H?(0,r.jsx)(m.y$,{size:"md"}):(0,r.jsx)("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}),(0,r.jsx)(ek,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l,showToast:x}),(0,r.jsx)(ef,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l})]}),!F&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:K,disabled:H||j,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-accent-600 hover:bg-accent-50 dark:hover:text-accent-400 dark:hover:bg-accent-900/30 rounded-full transition-colors disabled:text-muted-foreground/50 disabled:hover:bg-transparent","aria-label":b("composer.attachImage"),"data-testid":"attach-image-button",children:H?(0,r.jsx)(m.y$,{size:"md"}):(0,r.jsx)("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(0,r.jsx)("textarea",{ref:M,"data-testid":"message-input-textarea",value:v,onChange:et,onKeyDown:en,onCompositionStart:Y,onCompositionEnd:Q,onFocus:h,placeholder:b("composer.placeholder"),disabled:j,rows:1,inputMode:"text",enterKeyHint:"send",className:"flex-1 outline-none bg-transparent resize-none overflow-y-auto scrollbar-thin",style:{minHeight:"36px",maxHeight:"160px",paddingTop:"8px",paddingBottom:"8px",lineHeight:"20px"}}),!F&&(0,r.jsx)(ek,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l,showToast:x}),!F&&(0,r.jsx)(ef,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l}),(0,r.jsx)(m.$n,{variant:"ghost",type:"submit","data-testid":"send-message-button","data-can-send":String((!!v.trim()||!!_)&&!j),disabled:!v.trim()&&!_||j,className:"flex-shrink-0 p-2 rounded-full transition-colors disabled:hover:bg-transparent ".concat((v.trim()||_)&&!j?"bg-accent-600 text-white hover:bg-accent-700 shadow-sm":"text-muted-foreground/50"),"aria-label":b("composer.sendMessage"),children:j?(0,r.jsx)(m.y$,{size:"md"}):(0,r.jsx)("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]})]}),(p||!F)&&(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 min-w-0","data-testid":"composer-meta-row",children:[(0,r.jsx)("div",{className:"flex items-center gap-2 min-w-0 overflow-x-auto scrollbar-hide",children:p}),!F&&(0,r.jsxs)("div",{className:"flex flex-shrink-0 items-center gap-1.5 text-[11px] text-muted-foreground select-none",children:[(0,r.jsx)(ei.u,{children:"/"}),(0,r.jsx)("span",{children:b("composer.commandsHint")}),(0,r.jsx)("span",{"aria-hidden":"true",className:"opacity-50",children:"\xb7"}),(0,r.jsx)(ei.u,{children:"⇧"}),(0,r.jsx)(ei.u,{children:"↵"}),(0,r.jsx)("span",{children:b("composer.newlineHint")})]})]})]}),(0,r.jsx)(eh,{isOpen:T,groups:O,onSelect:X,onClose:Z,isMobile:F,onFreeInput:ee,isCatalogStale:z,cliToolId:a})]})});var eM=n(9900);function eL(e,t,n,a){return(0,i.useCallback)(r=>{let s=n&&n!==t?{cliToolId:t,keys:r,instanceId:n}:{cliToolId:t,keys:r};fetch("/api/worktrees/".concat(encodeURIComponent(e),"/special-keys"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).then(()=>{a&&setTimeout(a,eM.LK)}).catch(e=>{console.error("Failed to send special keys:",e)})},[e,t,n,a])}function eR(){let[e,t]=(0,i.useState)(null),n=(0,i.useRef)(null);return(0,i.useEffect)(()=>()=>{null!==n.current&&(clearTimeout(n.current),n.current=null)},[]),{activeKey:e,markPressed:(0,i.useCallback)(e=>{t(e),null!==n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=null,t(null)},eM.tX)},[])}}let eP=[{key:"Left",label:"◀",ariaLabel:"Left"},{key:"Up",label:"▲",ariaLabel:"Up"},{key:"Down",label:"▼",ariaLabel:"Down"},{key:"Right",label:"▶",ariaLabel:"Right"},{key:"Enter",label:"↵",ariaLabel:"Enter"},{key:"Escape",label:"Esc",ariaLabel:"Escape"}],eD=[{key:"PageUp",label:"PgUp",ariaLabel:"Page Up"},{key:"PageDown",label:"PgDn",ariaLabel:"Page Down"},{key:"Home",label:"Home",ariaLabel:"Home"},{key:"End",label:"End",ariaLabel:"End"},{key:"q",label:"q",ariaLabelKey:"navigation.quitPager"}];function eF(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s,showPagerKeys:l=!1}=e,o=(0,c.c)("worktree"),{activeKey:d,markPressed:u}=eR(),m=eL(t,n,a,s),h=(0,i.useCallback)(e=>{u(e[0]),m(e)},[u,m]),f=(0,i.useMemo)(()=>l?[...eP,...eD]:eP,[l]),x=(0,i.useCallback)(e=>{let t={ArrowLeft:"Left",ArrowUp:"Up",ArrowDown:"Down",ArrowRight:"Right",Enter:"Enter",Escape:"Escape"}[e.key];t&&(e.preventDefault(),h([t]))},[h]);return(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 py-1.5 bg-muted rounded-lg",onKeyDown:x,role:"toolbar","aria-label":o("navigation.toolbarLabel"),children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground mx-2",children:o("navigation.caption")}),f.map(e=>{let{key:t,label:n,ariaLabel:a,ariaLabelKey:s}=e;return(0,r.jsx)("button",{type:"button",className:"min-w-[44px] min-h-[44px] px-3 py-2 text-sm font-medium rounded-md\n border border-border\n focus:outline-none focus:ring-2 focus:ring-ring\n transition-colors duration-75\n ".concat(d===t?"bg-accent-500 text-white border-accent-500 scale-95":"bg-surface dark:bg-surface-2 hover:bg-muted active:bg-muted"),"aria-label":s?o(s):a,onClick:()=>h([t]),children:n},t)})]})}var eO=n(36402),ez=n(17846),e_=n(69264),eB=n(27307),eH=n(24027),eV=n(51963),eU=n(39867);let eK="flex w-full items-center gap-3 rounded-lg px-3 min-h-[44px] py-3 text-sm text-foreground hover:bg-muted transition-colors touch-manipulation";function eW(e){let{open:t,onClose:n,onSearch:a,onCopyContent:s,onCopyPath:l,downloadUrl:o,downloadName:d,contentCopied:u,pathCopied:m}=e,h=(0,c.c)("worktree"),f=(0,i.useId)(),x=(0,R.r)({active:t}),p=(0,i.useCallback)(()=>{a(),n()},[a,n]),g=(0,i.useCallback)(()=>{s(),n()},[s,n]),b=(0,i.useCallback)(()=>{l(),n()},[l,n]);return((0,i.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&(e.stopPropagation(),n())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,n]),t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{"data-testid":"file-actions-overlay",onClick:n,className:"fixed inset-0 bg-black/50 z-50","aria-hidden":"true"}),(0,r.jsxs)("div",{ref:x,"data-testid":"mobile-file-actions-sheet",role:"dialog","aria-modal":"true","aria-labelledby":f,tabIndex:-1,className:"fixed bottom-0 inset-x-0 z-50 rounded-t-2xl border-t border-border bg-surface pb-safe",children:[(0,r.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,r.jsx)("div",{className:"w-10 h-1 rounded-full bg-muted-foreground/30","aria-hidden":"true"})}),(0,r.jsx)("h2",{id:f,className:"px-4 pb-2 text-sm font-medium text-muted-foreground",children:h("fileViewer.moreActions")}),(0,r.jsxs)("div",{className:"px-2 pb-4",children:[(0,r.jsxs)("button",{type:"button","data-testid":"file-actions-sheet-search",onClick:p,className:eK,children:[(0,r.jsx)(B.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),h("actions.searchInFile")]}),(0,r.jsxs)("button",{type:"button","data-testid":"file-actions-sheet-copy-content",onClick:g,className:eK,children:[u?(0,r.jsx)(ey.A,{size:18,"aria-hidden":"true",className:"text-success"}):(0,r.jsx)(ej.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),h("actions.copyFileContent")]}),(0,r.jsxs)("button",{type:"button","data-testid":"file-actions-sheet-copy-path",onClick:b,className:eK,children:[m?(0,r.jsx)(ey.A,{size:18,"aria-hidden":"true",className:"text-success"}):(0,r.jsx)(eV.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),h("actions.copyFilePath")]}),(0,r.jsxs)("a",{"data-testid":"download-file-button",href:o,download:d,onClick:n,className:eK,"aria-label":h("actions.downloadFile"),children:[(0,r.jsx)(eU.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),h("actions.downloadFile")]})]})]})]}):null}var e$=n(11063),eq=n(60322),eG=n(65229),eJ=n(57828),eY=n(18514),eQ=n(59854),eX=n(76246);let eZ={highlightName:"terminal-search",currentHighlightName:"terminal-search-current",fallbackOverlayId:"terminal-search-fallback-overlay",fallbackOverlayBgColor:"rgba(255, 165, 0, 0.6)"},e0={highlightName:"history-search",currentHighlightName:"history-search-current",fallbackOverlayId:"history-search-fallback-overlay",fallbackOverlayBgColor:"rgba(59, 130, 246, 0.6)"};function e1(){return"undefined"!=typeof CSS&&null!==CSS&&"highlights"in CSS}function e2(e,t,n){let a=document.createRange(),r=!1;for(let{node:s,start:l,end:i}of e)if(!r&&t<i&&t>=l&&(a.setStart(s,t-l),r=!0),r&&n<=i)return a.setEnd(s,n-l),a;return r?a:null}function e5(e){var t;e1()&&(CSS.highlights.delete(e.highlightName),CSS.highlights.delete(e.currentHighlightName)),null==(t=document.getElementById(e.fallbackOverlayId))||t.remove()}function e4(e,t,n,a){if(0===t.length)return void e5(a);let r=function(e){let t,n=[],a=0,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(;t=r.nextNode();){var s,l;let e=null!=(l=null==(s=t.nodeValue)?void 0:s.length)?l:0;n.push({node:t,start:a,end:a+e}),a+=e}return n}(e),s=t[n],l=s?e2(r,s.start,s.end):null;if(e1()){let e=[];t.forEach((t,a)=>{if(a===n)return;let s=e2(r,t.start,t.end);s&&e.push(s)}),CSS.highlights.set(a.highlightName,new Highlight(...e)),CSS.highlights.delete(a.currentHighlightName)}if(function(e,t,n){let a=document.getElementById(n.fallbackOverlayId);if(!t||"function"!=typeof t.getBoundingClientRect){null==a||a.remove();return}let r=t.getBoundingClientRect(),s=e.getBoundingClientRect();a?a.style.backgroundColor=n.fallbackOverlayBgColor:((a=document.createElement("div")).id=n.fallbackOverlayId,a.style.position="absolute",a.style.backgroundColor=n.fallbackOverlayBgColor,a.style.borderRadius="2px",a.style.pointerEvents="none",a.style.zIndex="5",e instanceof HTMLElement&&(e.style.position="relative"),e.appendChild(a)),a.style.top="".concat(r.top-s.top+e.scrollTop,"px"),a.style.left="".concat(r.left-s.left+e.scrollLeft,"px"),a.style.width="".concat(r.width,"px"),a.style.height="".concat(r.height,"px")}(e,l,a),l){let e=l.startContainer,t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"})}}function e3(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e0;e5(e)}function e6(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e0;e4(e,t,n,a)}function e8(e){let[t,n]=(0,i.useState)(!1),[a,r]=(0,i.useState)(""),[s,l]=(0,i.useState)(""),[o,c]=(0,i.useState)([]),[d,u]=(0,i.useState)(0),m=(0,i.useRef)(null),h=(0,i.useRef)(null),f=(0,i.useCallback)(()=>{n(!0),setTimeout(()=>{var e;return null==(e=m.current)?void 0:e.focus()},50)},[]),x=(0,i.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),p=(0,i.useCallback)(()=>{n(!1),r(""),l(""),c([]),u(0),x()},[x]);(0,i.useEffect)(()=>{if(!a||a.length<2){l(""),x();return}return x(),h.current=setTimeout(()=>{l(a)},300),x},[a,x]),(0,i.useEffect)(()=>{if(!s||s.length<2||!e){c([]),u(0);return}let t=e.split("\n"),n=s.toLowerCase(),a=[];t.forEach((e,t)=>{e.toLowerCase().includes(n)&&a.push(t+1)}),c(a),u(0)},[s,e]);let g=(0,i.useCallback)(()=>{0!==o.length&&u(e=>(e+1)%o.length)},[o.length]),b=(0,i.useCallback)(()=>{0!==o.length&&u(e=>(e-1+o.length)%o.length)},[o.length]);return{searchOpen:t,searchQuery:a,searchMatches:o,searchCurrentIdx:d,searchInputRef:m,openSearch:f,closeSearch:p,nextMatch:g,prevMatch:b,setSearchQuery:r}}var e9=n(4138),e7=n(90487);function te(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex h-full items-center justify-center bg-surface text-muted-foreground",children:[(0,r.jsx)(m.y$,{size:"lg",className:"mr-2"}),(0,r.jsx)("span",{children:e("detail.loadingEditor")})]})}n(1226);let tt=(0,o.default)(()=>n.e(3922).then(n.bind(n,33922)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[33922]},ssr:!1,loading:()=>(0,r.jsx)(te,{})}),tn="flex min-h-[44px] min-w-[44px] flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface hover:text-foreground transition-colors touch-manipulation",ta=/^---\s*\nmarp:\s*true/;function tr(e){let{searchInputRef:t,searchQuery:n,searchMatches:a,searchCurrentIdx:s,onQueryChange:l,onPrev:i,onNext:o,onClose:d}=e,u=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted border-b border-border",children:[(0,r.jsx)("input",{ref:t,type:"text",value:n,onChange:e=>l(e.target.value),onKeyDown:e=>{"Escape"===e.key&&d(),"Enter"!==e.key||e.nativeEvent.isComposing||(e.shiftKey?i():o())},placeholder:u("fileSearch.placeholder"),className:"flex-1 min-w-0 px-2 py-0.5 text-sm bg-surface dark:bg-surface-2 text-foreground border border-input rounded outline-none focus:ring-1 focus:ring-ring",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground min-w-[3rem] text-right",children:a.length>0?"".concat(s+1,"/").concat(a.length):"0/0"}),(0,r.jsx)("button",{onClick:i,disabled:0===a.length,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground disabled:text-muted-foreground","aria-label":u("fileSearch.prevMatch"),children:"▲"}),(0,r.jsx)("button",{onClick:o,disabled:0===a.length,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground disabled:text-muted-foreground","aria-label":u("fileSearch.nextMatch"),children:"▼"}),(0,r.jsx)("button",{onClick:d,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground","aria-label":u("fileSearch.close"),children:(0,r.jsx)(eG.A,{className:"w-4 h-4"})})]})}let ts="\n<script>\ndocument.addEventListener('click', function(e) {\n var target = e.target;\n while (target && target.tagName !== 'A') {\n target = target.parentElement;\n }\n if (target && target.href) {\n e.preventDefault();\n parent.postMessage({\n type: 'commandmate:link-click',\n href: target.getAttribute('href')\n }, '*');\n }\n});\n<\/script>";function tl(e){let{htmlContent:t,filePath:n}=e,[a,s]=(0,i.useState)("preview"),[l,o]=(0,i.useState)("safe"),d=(0,i.useRef)(new Set),u=(0,c.c)("worktree"),m=(0,eO.SC)(),h=(0,i.useCallback)(async e=>{if("interactive"===e&&!d.current.has(n)){if(!await m({description:u("htmlPreview.interactiveModeConfirm")}))return;d.current.add(n)}o(e)},[n,m,u]),f=(0,i.useMemo)(()=>"interactive"!==l?t:t.includes("</body>")?t.replace("</body>","".concat(ts,"</body>")):t+ts,[t,l]);(0,i.useEffect)(()=>{if("interactive"!==l)return;let e=e=>{if("null"!==e.origin)return;let t=e.data;if(!t||"object"!=typeof t||"commandmate:link-click"!==t.type||"string"!=typeof t.href)return;let n=t.href;(n.startsWith("http://")||n.startsWith("https://"))&&window.open(n,"_blank","noopener,noreferrer")};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[l]);let x=(0,i.useMemo)(()=>{try{return e7.A.highlight(t,{language:"html",ignoreIllegals:!0}).value}catch(e){return e7.A.highlightAuto(t).value}},[t]),p=(0,i.useMemo)(()=>Array.from({length:t.split("\n").length},(e,t)=>t+1),[t]),g=(0,i.useMemo)(()=>x.split("\n"),[x]);return(0,r.jsxs)("div",{className:"flex flex-col h-full","data-testid":"html-preview-mobile",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between p-1 border-b border-border bg-muted",children:[(0,r.jsx)("div",{className:"flex gap-1",children:["source","preview"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>s(e),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat(a===e?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:"source"===e?u("fileViewer.tabSource"):u("fileViewer.tabPreview")},e))}),(0,r.jsx)("div",{className:"flex gap-1",children:["safe","interactive"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>h(e),className:"px-2 py-1 text-xs font-medium rounded-md transition-colors ".concat(l===e?"safe"===e?"bg-success-subtle text-success-foreground":"bg-warning-subtle text-warning-foreground":"text-muted-foreground hover:bg-muted"),children:"safe"===e?u("fileViewer.sandboxSafe"):u("fileViewer.sandboxInteractive")},e))})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto min-h-0",children:"source"===a?(0,r.jsx)("table",{className:"text-sm w-full border-collapse",children:(0,r.jsx)("tbody",{children:p.map(e=>{var t;let n=e-1;return(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{className:"pl-3 pr-2 text-right select-none font-mono border-r border-border bg-muted dark:bg-muted/50 sticky left-0 align-top whitespace-nowrap text-muted-foreground",children:e}),(0,r.jsx)("td",{className:"px-4 text-foreground align-top",children:(0,r.jsx)("pre",{className:"m-0 whitespace-pre-wrap break-words font-mono",children:(0,r.jsx)("code",{className:"hljs",dangerouslySetInnerHTML:{__html:null!=(t=g[n])?t:""}})})})]},e)})})}):(0,r.jsx)("iframe",{srcDoc:f,sandbox:e$.Ko[l],title:u("htmlPreview.title",{path:n}),className:"w-full h-full border-0 bg-white"},"".concat(n,"-").concat(l))})]})}let ti=(0,i.memo)(function(e){let{isOpen:t,onClose:n,worktreeId:a,filePath:s,onFileSaved:l,onOpenFile:o}=e,[u,h]=(0,i.useState)(null),[f,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null),{copied:b,markCopied:v,reset:y}=(0,e9.q)(),{copied:j,markCopied:w}=(0,e9.q)(),[k,N]=(0,i.useState)(null),[C,S]=(0,i.useState)(0),[T,I]=(0,i.useState)(!1),[E,A]=(0,i.useState)("viewer"),[M,L]=(0,i.useState)(!1),[R,P]=(0,i.useState)(null),[D,F]=(0,i.useState)(!1),O=(0,i.useRef)(null),z=(0,c.c)("worktree"),_=(0,eO.SC)(),H=u?null!=R?R:u.content:void 0,{searchOpen:V,searchQuery:U,searchMatches:K,searchCurrentIdx:q,searchInputRef:G,openSearch:J,closeSearch:Y,nextMatch:Q,prevMatch:X,setSearchQuery:Z}=e8(H),ee=(0,i.useMemo)(()=>!!((null==u?void 0:u.content)&&!u.isImage&&!u.isVideo&&!u.isPdf),[u]),et=(null==u?void 0:u.extension)==="md",en=(0,i.useCallback)(async()=>{if(ee&&H)try{await (0,eq.l)(H),v()}catch(e){}},[ee,H,v]),ea=(0,i.useCallback)(async()=>{try{await (0,eq.l)(s),w()}catch(e){}},[s,w]),er=(0,i.useCallback)(()=>{I(e=>!e)},[]);(0,i.useEffect)(()=>{if(0===K.length||!O.current)return;let e=K[q],t=O.current.querySelector('[data-line="'.concat(e,'"]'));t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"})},[q,K]),(0,i.useEffect)(()=>{if(!T||et)return;let e=e=>{"Escape"===e.key&&I(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[T,et]),(0,i.useEffect)(()=>{if(!t||!s){h(null),g(null),y(),A("viewer"),L(!1),P(null),F(!1),Y();return}A("viewer"),L(!1),P(null),F(!1),(async()=>{x(!0),g(null);try{let t=await fetch("/api/worktrees/".concat(a,"/files/").concat((0,eX.o)(s)));if(!t.ok){var e;let n=await t.json(),a="string"==typeof n.error?n.error:(null==(e=n.error)?void 0:e.message)||z("fileViewer.loadError");throw Error(a)}let n=await t.json();h(n)}catch(e){g(e instanceof Error?e.message:z("fileViewer.loadError"))}finally{x(!1)}})()},[t,a,s]),(0,i.useEffect)(()=>{N(null),S(0),u&&"md"===u.extension&&ta.test(u.content)&&!(u.content.length>1e6)&&(async()=>{try{let e=await fetch("/api/worktrees/".concat(a,"/marp-render"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdownContent:u.content})});if(e.ok){let t=await e.json();N(t.slides)}}catch(e){}})()},[u,a]);let es=!!(k&&k.length>0),el=(0,i.useCallback)(e=>{P(e)},[]),ei=(0,i.useCallback)((e,t)=>{h(e=>e?{...e,content:t}:e),P(t),null==l||l(e)},[l]),eo=(0,i.useCallback)(async()=>{(!D||await _({description:z("editor.unsavedCloseConfirm"),variant:"danger"}))&&n()},[D,_,z,n]);(0,i.useEffect)(()=>{if(!et||M)return;let e=e=>{"Escape"===e.key&&(V?Y():T?I(!1):eo())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[et,M,V,T,eo]);let[ec,ed]=(0,i.useState)("");(0,i.useEffect)(()=>{"viewer"===E&&void 0!==H&&ed(H)},[E,H]),(0,i.useEffect)(()=>{if(!et||!t)return;let e=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=e}},[et,t]);let eu=(0,i.useMemo)(()=>{if(!u||void 0===H||u.isImage||u.isVideo||u.isHtml||u.isPdf)return null;let e=Array.from({length:H.split("\n").length},(e,t)=>t+1);try{return{lineNumbers:e,highlightedHtml:e7.A.highlight(H,{language:u.extension,ignoreIllegals:!0}).value}}catch(t){return{lineNumbers:e,highlightedHtml:e7.A.highlightAuto(H).value}}},[u,H]),em=()=>u?u.isImage?(0,r.jsx)(ez.a,{src:u.content,alt:u.path,mimeType:u.mimeType}):u.isVideo?(0,r.jsx)(e_.u,{src:u.content,mimeType:u.mimeType}):u.isPdf?(0,r.jsx)("div",{className:"h-full min-h-[40vh]",children:(0,r.jsx)(eB.PdfPreview,{dataUri:u.content,filePath:s,variant:"download"})}):u.isHtml?(0,r.jsx)(tl,{htmlContent:u.content,filePath:s}):eh():null,eh=()=>{if(!eu)return null;let e=new Set(K),t=K.length>0?K[q]:-1,n=eu.highlightedHtml.split("\n");return(0,r.jsx)("div",{ref:O,children:(0,r.jsx)("table",{className:"text-sm w-full border-collapse",children:(0,r.jsx)("tbody",{children:eu.lineNumbers.map(a=>{var s;let l=a-1,i=a===t,o=e.has(a);return(0,r.jsxs)("tr",{"data-line":a,className:i?"bg-warning/30":o?"bg-warning/15":"",children:[(0,r.jsx)("td",{className:"pl-3 pr-2 text-right select-none font-mono border-r border-border bg-muted dark:bg-muted/50 sticky left-0 align-top whitespace-nowrap ".concat(i||o?"text-warning-foreground":"text-muted-foreground"),children:a}),(0,r.jsx)("td",{className:"px-4 text-foreground align-top",children:(0,r.jsx)("pre",{className:"m-0 whitespace-pre-wrap break-words font-mono",children:(0,r.jsx)("code",{className:"hljs",dangerouslySetInnerHTML:{__html:null!=(s=n[l])?s:""}})})})]},a)})})})})},ef="/api/worktrees/".concat(a,"/files/").concat((0,eX.o)(s),"?download=1"),ex=s?s.split("/").pop()||s:"",ep=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return(0,r.jsxs)("a",{"data-testid":"download-file-button",href:ef,download:ex,className:e,"aria-label":z("actions.downloadFile"),title:z("actions.download"),children:[(0,r.jsx)(eU.A,{className:"w-3.5 h-3.5"}),t&&(0,r.jsx)("span",{children:z("actions.download")})]})},eg=()=>(0,r.jsxs)("div",{className:"bg-muted px-3 py-1.5 border-b border-border flex items-center justify-between gap-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,r.jsx)("button",{onClick:ea,className:"flex-shrink-0 p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":z("actions.copyFilePath"),title:z("actions.copyPath"),children:j?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(eV.A,{className:"w-3.5 h-3.5"})}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground font-mono truncate",children:s})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[ee&&(0,r.jsx)("button",{onClick:J,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":z("actions.searchInFile"),title:z("actions.search"),children:(0,r.jsx)(B.A,{className:"w-3.5 h-3.5"})}),ee&&(0,r.jsx)("button",{"data-testid":"copy-content-button",onClick:en,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":z("actions.copyFileContent"),title:z("actions.copyContent"),children:b?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ej.A,{className:"w-3.5 h-3.5"})}),ep("p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground"),(0,r.jsx)("button",{onClick:er,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T?z("actions.exitFullscreen"):z("actions.fullscreen"),title:T?z("actions.exitFullscreen"):z("actions.fullscreen"),children:T?(0,r.jsx)(W.A,{className:"w-3.5 h-3.5"}):(0,r.jsx)($.A,{className:"w-3.5 h-3.5"})})]})]}),eb=()=>(0,r.jsx)(tr,{searchInputRef:G,searchQuery:U,searchMatches:K,searchCurrentIdx:q,onQueryChange:Z,onPrev:X,onNext:Q,onClose:Y});if(et&&u&&!f&&!p){let e=e=>"flex min-h-[44px] items-center justify-center gap-1 rounded-md px-2 text-xs font-medium touch-manipulation transition-colors ".concat(e?"bg-surface shadow-sm text-accent-600 dark:text-accent-400":"text-muted-foreground hover:text-foreground");return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{"data-testid":"markdown-file-screen",role:"dialog","aria-modal":"true","aria-label":s,className:"fixed inset-0 flex h-[100dvh] flex-col bg-surface",style:{zIndex:eQ.M.MAXIMIZED_EDITOR},children:[T?(0,r.jsxs)("div",{"data-testid":"markdown-file-immersive-controls",className:"absolute right-2 top-2 z-10 flex items-center gap-1 rounded-lg border border-border bg-surface/90 shadow-sm",children:[(0,r.jsx)("button",{type:"button","data-testid":"markdown-file-maximize",onClick:er,"aria-pressed":!0,"aria-label":z("actions.exitFullscreen"),className:tn,children:(0,r.jsx)(W.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{type:"button","data-testid":"markdown-file-close",onClick:()=>void eo(),"aria-label":z("actions.close"),className:tn,children:(0,r.jsx)(eG.A,{className:"h-5 w-5"})})]}):(0,r.jsxs)("div",{className:"flex flex-shrink-0 items-center gap-1 border-b border-border bg-muted px-2",children:[(0,r.jsx)("p",{className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground",children:s}),(0,r.jsxs)("div",{"data-testid":"markdown-file-mode-switch",role:"group","aria-label":z("fileViewer.modeSwitch"),className:"flex flex-shrink-0 items-center gap-0.5 rounded-lg bg-muted p-0.5",children:[(0,r.jsxs)("button",{type:"button","data-testid":"markdown-file-mode-viewer","aria-pressed":"viewer"===E,onClick:()=>A("viewer"),className:e("viewer"===E),children:[(0,r.jsx)(eJ.A,{className:"h-4 w-4"}),z("fileViewer.modeViewer")]}),(0,r.jsxs)("button",{type:"button","data-testid":"markdown-file-mode-editor","aria-pressed":"editor"===E,onClick:()=>A("editor"),className:e("editor"===E),children:[(0,r.jsx)(eY.A,{className:"h-4 w-4"}),z("fileViewer.modeEditor")]})]}),(0,r.jsx)("button",{type:"button","data-testid":"markdown-file-actions-trigger",onClick:()=>L(!0),"aria-label":z("fileViewer.moreActions"),className:tn,children:(0,r.jsx)(d.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{type:"button","data-testid":"markdown-file-maximize",onClick:er,"aria-pressed":!1,"aria-label":z("actions.fullscreen"),className:tn,children:(0,r.jsx)($.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{type:"button","data-testid":"markdown-file-close",onClick:()=>void eo(),"aria-label":z("actions.close"),className:tn,children:(0,r.jsx)(eG.A,{className:"h-5 w-5"})})]}),V&&(0,r.jsx)("div",{className:"flex-shrink-0",children:eb()}),(0,r.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col",children:[(0,r.jsx)("div",{className:"viewer"===E?"flex min-h-0 flex-1 flex-col":"hidden",children:V?(0,r.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:eh()}):es?k?(0,r.jsxs)("div",{className:"flex h-full flex-col",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between p-2 bg-muted border-b border-border",children:[(0,r.jsx)("button",{type:"button",onClick:()=>S(e=>Math.max(0,e-1)),disabled:0===C,className:"min-h-[44px] px-3 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors touch-manipulation",children:z("actions.prev")}),(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[C+1," / ",k.length]}),(0,r.jsx)("button",{type:"button",onClick:()=>S(e=>Math.min(k.length-1,e+1)),disabled:C===k.length-1,className:"min-h-[44px] px-3 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors touch-manipulation",children:z("actions.next")})]}),(0,r.jsx)("iframe",{srcDoc:k[C],sandbox:"",title:z("fileViewer.slideTitle",{name:s,number:C+1}),className:"w-full flex-1 border-0"})]}):null:(0,r.jsx)("div",{"data-testid":"markdown-file-preview",className:"prose prose-sm dark:prose-invert min-h-0 max-w-none flex-1 overflow-y-auto p-4",children:(0,r.jsx)(eH.G8,{content:ec,currentFilePath:s,worktreeId:a,onOpenFile:o})})}),(0,r.jsx)("div",{"data-testid":"markdown-file-editor",className:"editor"===E?"flex min-h-0 flex-1 flex-col":"hidden",children:(0,r.jsx)(tt,{worktreeId:a,filePath:s,initialContent:u.content,embedded:!0,onSave:ei,onDirtyChange:F,onContentChange:el,onOpenFile:o},s)})]}),(0,r.jsx)(eW,{open:M,onClose:()=>L(!1),onSearch:()=>{A("viewer"),J()},onCopyContent:en,onCopyPath:ea,downloadUrl:ef,downloadName:ex,contentCopied:b,pathCopied:j})]})})}return T&&u&&!f&&!p?(0,r.jsxs)("div",{className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:eQ.M.MAXIMIZED_EDITOR},children:[eg(),V&&eb(),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:em()})]}):(0,r.jsx)(m.Jh,{isOpen:t,onClose:n,title:s,size:"xl",children:(0,r.jsxs)("div",{className:"max-h-[60vh] sm:max-h-[70vh] flex flex-col",children:[f&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,r.jsx)(m.y$,{size:"xl",variant:"accent"}),(0,r.jsx)("p",{className:"ml-3 text-muted-foreground",children:z("fileViewer.loading")})]}),p&&(0,r.jsxs)("div",{className:"bg-danger-subtle border border-danger-border rounded-lg p-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-5 h-5 text-danger-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("p",{className:"text-sm text-danger-foreground",children:p})]}),(0,r.jsx)("div",{className:"mt-3",children:ep("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm font-medium bg-surface border border-border text-foreground hover:bg-muted transition-colors",!0)})]}),u&&!f&&!p&&(0,r.jsxs)("div",{className:"bg-muted rounded-lg overflow-hidden flex flex-col min-h-0 flex-1",children:[(0,r.jsxs)("div",{className:"flex-shrink-0",children:[eg(),V&&eb()]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:em()})]})]})})});var to=n(36809),tc=n(46892),td=n(50857),tu=n(94442);function tm(e){let{worktreeId:t}=e,[n,a]=(0,i.useState)([]),[s,l]=(0,i.useState)(null),[o,d]=(0,i.useState)(null),[u,h]=(0,i.useState)(!0),[f,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(""),[v,y]=(0,i.useState)(0),[j,w]=(0,i.useState)("all"),[k,N]=(0,i.useState)(!1),{showToast:C}=(0,tu.dj)(),S=(0,c.c)("worktree");(0,i.useEffect)(()=>{(async()=>{try{h(!0),p(null);let e=await el.y.getLogs(t);a(e)}catch(e){p((0,el.hS)(e))}finally{h(!1)}})()},[t]);let T=(0,i.useMemo)(()=>"all"===j?n:n.filter(e=>e.toLowerCase().includes(j)),[n,j]),I=async e=>{try{h(!0),p(null);let n=await el.y.getLogFile(t,e);d(n.content),l(e),b(""),y(0)}catch(e){p((0,el.hS)(e))}finally{h(!1)}},E=(0,i.useCallback)(async()=>{if(s)try{N(!0);let e=await el.y.getLogFile(t,s,{sanitize:!0});await (0,eq.l)(e.content),C(S("logViewer.copied"),"success")}catch(e){C(S("logViewer.exportError",{error:(0,el.hS)(e)}),"error")}finally{N(!1)}},[t,s,C,S]),A=(0,i.useMemo)(()=>{let e;if(!g||!o)return[];let t=RegExp((0,x.Nt)(g),"gi"),n=[];for(;null!==(e=t.exec(o));)n.push({index:e.index,length:e[0].length});return n},[g,o]);(0,i.useEffect)(()=>{y(0)},[g]);let M=()=>{A.length>0&&y(e=>(e+1)%A.length)},L=()=>{A.length>0&&y(e=>(e-1+A.length)%A.length)},R=(0,i.useMemo)(()=>{if(!o||!g||0===A.length)return o;let e="",t=0;return A.forEach((n,a)=>{e+=(0,x.ZD)(o.substring(t,n.index));let r=o.substring(n.index,n.index+n.length),s=a===v;e+='<mark class="'.concat(s?"bg-warning text-black":"bg-warning-border text-black",'" data-match-index="').concat(a,'">').concat((0,x.ZD)(r),"</mark>"),t=n.index+n.length}),e+=(0,x.ZD)(o.substring(t))},[o,g,A,v]);return(0,i.useEffect)(()=>{A.length>0&&v>=0&&setTimeout(()=>{let e=document.querySelector('mark[data-match-index="'.concat(v,'"]'));e&&e.scrollIntoView({behavior:"smooth",block:"center"})},100)},[v,A.length]),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)(m.Zp,{padding:"md",children:[(0,r.jsx)(m.aR,{children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(m.ZB,{children:S("logViewer.title")}),(0,r.jsx)(m.Ex,{variant:"gray",children:T.length})]}),(0,r.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,r.jsx)(m.$n,{variant:"all"===j?"primary":"ghost",size:"sm",onClick:()=>w("all"),children:S("logViewer.all",{count:n.length})}),(0,r.jsx)(m.$n,{variant:"claude"===j?"primary":"ghost",size:"sm",onClick:()=>w("claude"),children:S("logViewer.toolCount",{tool:"Claude",count:n.filter(e=>e.toLowerCase().includes("claude")).length})}),(0,r.jsx)(m.$n,{variant:"codex"===j?"primary":"ghost",size:"sm",onClick:()=>w("codex"),children:S("logViewer.toolCount",{tool:"Codex",count:n.filter(e=>e.toLowerCase().includes("codex")).length})}),(0,r.jsx)(m.$n,{variant:"gemini"===j?"primary":"ghost",size:"sm",onClick:()=>w("gemini"),children:S("logViewer.toolCount",{tool:"Gemini",count:n.filter(e=>e.toLowerCase().includes("gemini")).length})}),(0,r.jsx)(m.$n,{variant:"antigravity"===j?"primary":"ghost",size:"sm",onClick:()=>w("antigravity"),children:S("logViewer.toolCount",{tool:"Antigravity",count:n.filter(e=>e.toLowerCase().includes("antigravity")).length})})]})]})}),(0,r.jsxs)(m.Wu,{children:[u&&0===n.length&&(0,r.jsx)("div",{className:"text-center py-4",children:(0,r.jsx)(m.y$,{size:"lg",variant:"accent",className:"inline-block"})}),f&&(0,r.jsx)("div",{className:"p-3 bg-danger-subtle border border-danger-border rounded text-sm text-danger-foreground",children:f}),!u&&0===T.length&&!f&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground text-center py-4",children:"all"===j?S("logViewer.empty"):S("logViewer.emptyFiltered",{tool:j})}),T.length>0&&(0,r.jsx)("div",{className:"space-y-2",children:T.map(e=>(0,r.jsx)("button",{onClick:()=>I(e),className:"w-full text-left px-3 py-2 rounded text-sm font-mono transition-colors ".concat(s===e?"bg-accent-50 text-accent-700 border border-accent-200":"hover:bg-muted border border-transparent"),children:e},e))})]})]}),s&&(0,r.jsxs)(m.Zp,{padding:"md",children:[(0,r.jsx)(m.aR,{children:(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(m.ZB,{className:"font-mono text-base",children:s}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:E,disabled:!s||k,title:S("logViewer.copyTitle"),children:k?S("logViewer.exporting"):S("logViewer.export")}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:()=>{l(null),d(null),b(""),y(0)},children:S("actions.close")})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)(m.pd,{type:"text",value:g,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),e.shiftKey?L():M())},placeholder:S("logViewer.searchPlaceholder"),className:"w-full pr-20"}),A.length>0&&(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground",children:[v+1," / ",A.length]})]}),A.length>0&&(0,r.jsxs)("div",{className:"flex gap-1",children:[(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:L,disabled:0===A.length,title:S("logViewer.prevMatch"),children:"↑"}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:M,disabled:0===A.length,title:S("logViewer.nextMatch"),children:"↓"})]})]})]})}),(0,r.jsxs)(m.Wu,{children:[u&&(0,r.jsx)("div",{className:"text-center py-8",children:(0,r.jsx)(m.y$,{size:"xl",variant:"accent",className:"inline-block"})}),!u&&o&&(0,r.jsx)("div",{className:"bg-[#111827] text-[#f3f4f6] rounded p-4 overflow-x-auto max-h-[500px] scrollbar-thin",children:g&&A.length>0?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:R||""}}):(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",children:o})}),!u&&g&&0===A.length&&o&&(0,r.jsx)("div",{className:"text-center py-4 text-sm text-muted-foreground",children:S("logViewer.noMatches",{query:g})})]})]})]})}function th(){let[e,t]=(0,i.useState)(null),[n,a]=(0,i.useState)(!0),[r,s]=(0,i.useState)(null);return(0,i.useEffect)(()=>{let e=!1;return async function(){try{a(!0),s(null);let n=await el.GQ.checkForUpdate();e||t(n)}catch(t){e||s(t instanceof Error?t.message:"Failed to check for updates")}finally{e||a(!1)}}(),()=>{e=!0}},[]),{data:e,loading:n,error:r}}var tf=n(31166);function tx(e){let{hasUpdate:t,latestVersion:n,releaseUrl:a,updateCommand:s,installType:l}=e,o=(0,c.c)("worktree"),[d,m]=(0,i.useState)("idle"),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),g=(0,i.useRef)(!1),b="global"===l,v="npx"===l,y=b||v,j=v?"npx commandmate@latest":"commandmate update",w=(0,i.useCallback)(async()=>{m("starting");try{let e=await el.GQ.startUpdate();f(e.logPath),m(e.willRestart?"updating":"no-restart")}catch(e){e instanceof el.hD&&400===e.status?p(o("update.errorNotGlobal")):e instanceof el.hD&&409===e.status?p(o("update.errorInProgress")):p(o("update.errorGeneric")),m("error")}},[o]);return((0,i.useEffect)(()=>{if("updating"!==d)return;let e=!1,t=Date.now();g.current=!1;let n=setInterval(async()=>{if(e)return;if(Date.now()-t>3e5)return void m("timeout");let n=await el.GQ.ping();if(!e){if(!n){g.current=!0;return}g.current&&window.location.reload()}},2e3);return()=>{e=!0,clearInterval(n)}},[d]),t)?(0,r.jsxs)("div",{className:"bg-accent-50 border border-accent-200 rounded-lg p-3 mt-2",role:"status","aria-label":o("update.available"),"data-testid":"update-notification-banner",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800 mb-1",children:o("update.available")}),n&&(0,r.jsx)("p",{className:"text-sm text-accent-700 mb-2",children:o("update.latestVersion",{version:n})}),y&&"idle"===d&&(0,r.jsx)(tf.$,{variant:"primary",size:"sm",className:"mb-2",onClick:()=>m("confirming"),"data-testid":"update-now-button",children:o("update.updateNow")}),v&&"idle"===d&&(0,r.jsx)("p",{className:"text-xs text-accent-600 mb-2","data-testid":"update-npx-notice",children:o("update.npxRestartNotice")}),("starting"===d||"updating"===d)&&(0,r.jsxs)("div",{className:"mb-2","data-testid":"update-progress",children:[(0,r.jsxs)("p",{className:"flex items-center text-sm text-accent-800",children:[(0,r.jsx)(u.y,{size:"sm",className:"mr-2"}),"starting"===d?o("update.starting"):o("update.updating")]}),"updating"===d&&(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:o("update.updatingHint")})]}),"no-restart"===d&&(0,r.jsxs)("div",{className:"mb-2","data-testid":"update-no-restart",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800",children:o("update.noRestartTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:o("update.noRestartDescription")})]}),"timeout"===d&&(0,r.jsxs)("div",{className:"mb-2","data-testid":"update-timeout",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800",children:o("update.timeoutTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:o("update.timeoutDescription")}),(0,r.jsx)("code",{className:"block bg-accent-100 rounded px-2 py-1 mt-1 text-xs text-accent-900 font-mono",children:j})]}),"error"===d&&(0,r.jsxs)("div",{className:"mb-2","data-testid":"update-error",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800",children:o("update.errorTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:x}),(0,r.jsx)("code",{className:"block bg-accent-100 rounded px-2 py-1 mt-1 text-xs text-accent-900 font-mono",children:j})]}),h&&("no-restart"===d||"timeout"===d)&&(0,r.jsx)("p",{className:"text-xs text-accent-500 mb-2","data-testid":"update-log-hint",children:o("update.logHint",{path:h})}),s&&b&&"idle"===d&&(0,r.jsxs)("div",{className:"mb-2",children:[(0,r.jsx)("p",{className:"text-xs text-accent-600 mb-1",children:o("update.updateCommand")}),(0,r.jsx)("code",{className:"block bg-accent-100 rounded px-2 py-1 text-xs text-accent-900 font-mono",children:s})]}),a&&(0,r.jsxs)("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-sm text-accent-600 hover:text-accent-800 underline",children:[o("update.viewRelease"),(0,r.jsx)("span",{className:"ml-1","aria-hidden":"true",children:"→"})]}),(0,r.jsx)("p",{className:"text-xs text-accent-500 mt-2",children:o("update.dataPreserved")}),(0,r.jsx)(eO.TM,{isOpen:"confirming"===d,title:o("update.confirmTitle"),description:o("update.confirmDescription",{version:null!=n?n:""}),confirmLabel:o("update.confirmButton"),onConfirm:w,onCancel:()=>m("idle")})]}):null}function tp(e){let{version:t,className:n}=e,a=(0,c.c)("worktree"),{data:s,loading:l}=th(),o=(0,i.useMemo)(()=>s&&s.hasUpdate?{hasUpdate:s.hasUpdate,latestVersion:s.latestVersion,releaseUrl:s.releaseUrl,updateCommand:s.updateCommand,installType:s.installType}:null,[s]);return(0,r.jsxs)("div",{className:n,"data-testid":"version-section",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-1",children:a("update.version")}),(0,r.jsx)("p",{className:"text-sm text-foreground",children:t}),l&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground mt-1","data-testid":"version-loading",children:"..."}),o&&(0,r.jsx)(tx,{...o})]})}let tg="https://github.com/Kewton/CommandMate",tb="".concat(tg,"/issues"),tv="".concat(tg,"/issues/new"),ty="".concat(tv,"?template=bug_report.md"),tj="".concat(tv,"?template=feature_request.md"),tw="".concat(tv,"?template=question.md");function tk(e){let{className:t}=e,n=(0,c.c)("worktree"),a=[{href:ty,label:n("feedback.bugReport")},{href:tj,label:n("feedback.featureRequest")},{href:tw,label:n("feedback.question")},{href:tb,label:n("feedback.viewIssues")}];return(0,r.jsxs)("div",{className:t,"data-testid":"feedback-section",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-2",children:n("feedback.title")}),(0,r.jsx)("div",{className:"flex flex-col gap-1",children:a.map(e=>{let{href:t,label:n}=e;return(0,r.jsxs)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-sm text-accent-600 hover:text-accent-800 underline",children:[n,(0,r.jsx)("span",{className:"ml-1","aria-hidden":"true",children:"→"})]},t)})})]})}var tN=n(94465),tC=n(38606),tS=n(34681),tT=n(95707),tI=n(20562),tE=n(8803),tA=n(46980),tM=n.n(tA),tL=n(62459),tR=n.n(tL);let tP="[... 古い出力を省略しました / older output truncated ...]",tD="\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)",tF=RegExp(tD,"g"),tO=RegExp("\\x1b\\[[0-9;]*[a-zA-Z]|".concat(tD,"|\\[[0-9;]*m"),"g");function tz(e){return e.replace(tO,"")}function t_(e){let t=e.match(tO);return t?t.join(""):""}let tB=new(tR())({fg:"#d1d5db",bg:"#1f2937",newline:!0,escapeXML:!0}),tH=/[\x40-\x7e]/;function tV(e){let t=(function(e){if(e.length<=1048576)return e;let t=tP+"\n",n=1048576-t.length;if(n<=0)return tP.slice(0,1048576);let a=e.length-n,r=e.indexOf("\n",a);if(-1!==r&&r-a<=65536)return t+e.slice(r+1);let s=function(e,t){let n=e.lastIndexOf("\x1b",t-1);if(-1===n)return t;let a=e.slice(n+1,t);if(tH.test(a.slice(1)))return t;for(let n=t;n<e.length;n++)if(tH.test(e[n]))return n+1;return e.length}(e,a),l=e.charCodeAt(s);return l>=56320&&l<=57343&&(s+=1),t+e.slice(s)})(e.replace(/\0/g,"")).replace(tF,""),n=tB.toHtml(t);return tM().sanitize(n,{ALLOWED_TAGS:["span","br"],ALLOWED_ATTR:["style"],ALLOW_DATA_ATTR:!1})}let tU=/\x1b(?:\[[0-9;?]*)?$/;function tK(e){return""===tz(e).trim()}let tW=/\x1b\[([0-9;]*)m/g;function t$(e){return""===tz(e).trim()}function tq(e){return t$(e)&&""!==tz(e)&&function(e){let t;for(tW.lastIndex=0;null!==(t=tW.exec(e));)if(function(e){let t=0;for(;t<e.length;){let n=e[t];if(38===n||48===n||58===n){if(48===n)return!0;let a=e[t+1];t+=5===a?3:2===a?5:2;continue}if(n>=40&&n<=47||n>=100&&n<=107)return!0;t+=1}return!1}(t[1].split(";").filter(e=>""!==e).map(e=>Number(e)).filter(e=>Number.isInteger(e))))return!0;return!1}(e)}function tG(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(""===e)return"";let{isStructuralRow:n}=t,a=e.split("\n"),r=[],s=!1,l=0,i=e=>{var t;return t$(e)&&!(null!=(t=null==n?void 0:n(e))&&t)};for(;l<a.length;){if(!i(a[l])){r.push(a[l]),s=!0,l++;continue}let e=l;for(;e<a.length&&i(a[e]);)e++;let t=e-l,n=!s,o=e>=a.length;if(!n&&!o)if(t<=2)for(let t=l;t<e;t++)r.push(a[t]);else r.push(t_(a.slice(l,e).join("")));l=e}return r.join("\n")}function tJ(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:o,onClose:c,isAtMaxMatches:d=!1}=e,u=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null==(e=u.current)||e.focus()},[]);let m=(0,i.useCallback)(e=>{"Escape"===e.key&&c()},[c]),h=(0,i.useCallback)(e=>{n(e.target.value)},[n]),f=0===a?"0/0":d?"".concat(s+1,"/").concat(500,"以上"):"".concat(s+1,"/").concat(a);return(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-gray-800 border border-gray-600 rounded shadow-lg",role:"search","aria-label":"ターミナル内テキスト検索",children:[(0,r.jsx)("input",{ref:u,type:"text",value:t,onChange:h,onKeyDown:m,placeholder:"検索...",className:"bg-transparent text-gray-200 text-sm outline-none w-32 sm:w-40 placeholder-gray-500","aria-label":"検索キーワード",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1}),(0,r.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"text-gray-400 text-xs min-w-[3rem] text-right",children:f}),(0,r.jsx)("button",{onClick:o,disabled:0===a,"aria-label":"前の結果",className:"text-gray-300 hover:text-white disabled:text-gray-600 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▲"}),(0,r.jsx)("button",{onClick:l,disabled:0===a,"aria-label":"次の結果",className:"text-gray-300 hover:text-white disabled:text-gray-600 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▼"}),(0,r.jsx)("button",{onClick:c,"aria-label":"検索を閉じる",className:"text-gray-400 hover:text-white min-w-[36px] min-h-[36px] flex items-center justify-center text-base ml-1",children:"✕"})]})}let tY=new Set(["claude","codex","opencode"]),tQ=new Set(["opencode"]),tX=new Set(["opencode"]),tZ=/\x1b\[[0-9;]*m/g;function t0(e){return{compactTuiLayoutPadding:tY.has(e),preservePaintedPanelRows:tQ.has(e),mobileWrapMode:tX.has(e)?"frame":"viewport"}}function t1(){return(0,r.jsxs)("div",{"data-testid":"thinking-indicator",className:"flex items-center gap-2 py-2 px-1 text-gray-400",children:[(0,r.jsxs)("span",{className:"flex gap-1",children:[(0,r.jsx)("span",{className:"animate-pulse delay-0",children:"."}),(0,r.jsx)("span",{className:"animate-pulse delay-150",children:"."}),(0,r.jsx)("span",{className:"animate-pulse delay-300",children:"."})]}),(0,r.jsx)("span",{className:"text-sm",children:"Thinking"})]})}let t2=(0,i.memo)(function(e){let{output:t,isActive:n,attaching:a=!1,isThinking:s=!1,autoScroll:l=!0,onScrollChange:o,disableAutoFollow:c=!1,compactTuiLayoutPadding:d=!1,preservePaintedPanelRows:u=!1,wrapMode:m="viewport",className:h=""}=e,{scrollRef:f,autoScroll:x,handleScroll:p,scrollToBottom:g,scrollToTop:b}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{initialAutoScroll:t=!0,onAutoScrollChange:n}=e,a=(0,i.useRef)(null),[r,s]=(0,i.useState)(t),l=(0,i.useRef)(!1),o=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{o.current&&clearTimeout(o.current)},[]);let c=(0,i.useCallback)(e=>{s(e),null==n||n(e)},[n]),d=(0,i.useCallback)(()=>{let e=a.current;if(!e)return!0;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;return n-r-t<=50},[]),u=(0,i.useCallback)(()=>{if(l.current)return;let e=d();e&&!r?c(!0):!e&&r&&c(!1)},[r,d,c]),m=(0,i.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),r||c(!0),o.current=setTimeout(()=>{l.current=!1,o.current=null},500))},[r,c]),h=(0,i.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:0,behavior:"smooth"}),r&&c(!1),o.current=setTimeout(()=>{l.current=!1,o.current=null},500))},[r,c]);return{scrollRef:a,autoScroll:r,setAutoScroll:c,scrollToBottom:m,scrollToTop:h,handleScroll:u}}({initialAutoScroll:l,onAutoScrollChange:o}),v=null!=t?t:"",y=(0,i.useMemo)(()=>d?u?tG(v,{isStructuralRow:tq}):function(e){if(""===e)return"";let t=e.split("\n"),n=[],a=!1,r=0;for(;r<t.length;){if(!tK(t[r])){n.push(t[r]),a=!0,r++;continue}let e=r;for(;e<t.length&&tK(t[e]);)e++;let s=e-r,l=!a,i=e>=t.length;if(!l&&!i)if(s<=2)for(let a=r;a<e;a++)n.push(t[a]);else n.push(t_(t.slice(r,e).join("")));r=e}return n.join("\n")}(v):v,[d,u,v]),j=(0,i.useMemo)(()=>{if("frame"===m)return{minWidth:"".concat(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:400,n=1;for(let a of e.split("\n")){let e=a.replace(tZ,"").trimEnd().length;if(e>n&&(n=e),n>=t)return t}return n}(y),"ch")}},[m,y]),{isOpen:w,query:k,matchCount:N,currentIndex:C,isAtMaxMatches:S,openSearch:T,closeSearch:I,setQuery:E,nextMatch:A,prevMatch:M}=function(e){let{output:t,containerRef:n}=e,[a,r]=(0,i.useState)(!1),[s,l]=(0,i.useState)(""),[o,c]=(0,i.useState)([]),[d,u]=(0,i.useState)(0),[m,h]=(0,i.useState)(!1),f=(0,i.useRef)(null),x=(0,i.useRef)(""),p=o.length,g=(0,i.useCallback)(e=>{var t;if(e.length<2||!n.current)return{positions:[],capped:!1};let a=(null!=(t=n.current.textContent)?t:"").toLowerCase(),r=e.toLowerCase(),s=[],l=0;for(;s.length<500;){let t=a.indexOf(r,l);if(-1===t)break;s.push({start:t,end:t+e.length}),l=t+1}let i=s.length>=500&&-1!==a.indexOf(r,l);return{positions:s,capped:i}},[n]),b=(0,i.useCallback)(e=>{let{positions:t,capped:a}=g(e);if(c(t),u(0),h(a),n.current)if(t.length>0){var r;r=n.current,e4(r,t,0,eZ)}else e5(eZ)},[g,n]),v=(0,i.useCallback)(e=>{l(e),f.current&&clearTimeout(f.current),x.current=e,f.current=setTimeout(()=>{b(e)},300)},[b]),y=(0,i.useCallback)(()=>{r(!0)},[]),j=(0,i.useCallback)(()=>{r(!1),l(""),x.current="",c([]),u(0),h(!1),f.current&&clearTimeout(f.current),e5(eZ)},[]),w=(0,i.useCallback)(()=>{0!==p&&u(e=>{let t=(e+1)%p;return n.current&&o.length>0&&e4(n.current,o,t,eZ),t})},[p,o,n]),k=(0,i.useCallback)(()=>{0!==p&&u(e=>{let t=(e-1+p)%p;return n.current&&o.length>0&&e4(n.current,o,t,eZ),t})},[p,o,n]);return(0,i.useEffect)(()=>{x.current.length<2||b(x.current)},[t,b]),(0,i.useEffect)(()=>()=>{f.current&&clearTimeout(f.current),e5(eZ)},[]),{isOpen:a,query:s,matchCount:p,currentIndex:d,isAtMaxMatches:m,openSearch:y,closeSearch:j,setQuery:v,nextMatch:w,prevMatch:k}}({output:y,containerRef:f}),L=(0,i.useCallback)(e=>{(e.ctrlKey||e.metaKey)&&"f"===e.key&&(e.preventDefault(),T())},[T]);(0,i.useEffect)(()=>{let e=()=>T();return window.addEventListener("terminal-search-open",e),()=>window.removeEventListener("terminal-search-open",e)},[T]);let[R,P]=(0,i.useState)(()=>y?[{key:0,html:tV(y)}]:[]),D=(0,i.useRef)(y),F=(0,i.useRef)(0);(0,i.useEffect)(()=>{let e=function(e,t){if(e===t)return{mode:"noop",text:t,appended:"",retainedLength:e.length};if(0===e.length||t.length<=e.length||!t.startsWith(e))return{mode:"replace",text:t,appended:"",retainedLength:0};let n=e.match(tU),a=n?e.length-n[0].length:e.length;return{mode:"append",text:t,appended:t.slice(a),retainedLength:a}}(D.current,y);if(D.current=y,"noop"===e.mode)return;let t="append"===e.mode&&e.appended.length>1048576;if("append"===e.mode&&!t)return void P(t=>(F.current+=1,t.length>=400)?[{key:F.current,html:tV(y)}]:[...t,{key:F.current,html:tV(e.appended)}]);F.current+=1,P(y?[{key:F.current,html:tV(y)}]:[])},[y]);let[O,z]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a?z(!1):n&&z(!0)},[a,n]);let _=!t,B=_&&a,H=_&&!a&&!n&&O,V=(0,i.useRef)(!1);(0,i.useEffect)(()=>{c&&(V.current=!0)},[c]),(0,i.useEffect)(()=>{if(f.current){if(V.current&&c&&y){f.current.scrollTo({top:0,behavior:"instant"}),V.current=!1;return}!c&&x&&f.current.scrollTo({top:f.current.scrollHeight,behavior:"instant"})}},[R,y,x,c,f]);let U=(0,i.useMemo)(()=>["terminal","font-mono","text-sm","p-4","rounded-lg","overflow-y-auto","frame"===m?"overflow-x-auto":"overflow-x-hidden","bg-gray-900","text-gray-300","border","border-gray-700","h-full",n?"active":"",h].filter(Boolean).join(" "),[n,h,m]),[K,W]=(0,i.useState)(!1),$=(0,i.useRef)(null),q=(0,i.useCallback)(()=>{W(!0),$.current&&clearTimeout($.current),$.current=setTimeout(()=>W(!1),1500)},[]);(0,i.useEffect)(()=>()=>{$.current&&clearTimeout($.current)},[]);let G=(0,i.useCallback)(()=>{p(),q()},[p,q]),J=["absolute bottom-4 right-4 flex items-center justify-center h-9 w-9 rounded-full bg-surface/80 backdrop-blur border border-border text-muted-foreground shadow-lg transition-opacity hover:text-surface-foreground hover:opacity-100 focus-visible:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",K?"opacity-100":"opacity-60"].join(" ");return(0,r.jsxs)("div",{className:"relative h-full flex flex-col",children:[w&&(0,r.jsx)("div",{className:"absolute top-2 right-2 z-10",children:(0,r.jsx)(tJ,{query:k,onQueryChange:E,matchCount:N,currentIndex:C,onNext:A,onPrev:M,onClose:I,isAtMaxMatches:S})}),(0,r.jsxs)("div",{ref:f,role:"log","aria-live":"polite","aria-label":"Terminal output",className:U,onScroll:G,onKeyDown:L,tabIndex:0,children:[(0,r.jsx)("div",{className:"frame"===m?"whitespace-pre w-max":"whitespace-pre-wrap break-words",style:j,children:R.map(e=>(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:e.html}},e.key))}),B&&(0,r.jsx)("div",{"data-testid":"terminal-loading-placeholder",className:"flex h-full items-center justify-center px-4 text-center text-sm text-gray-500 select-none",children:"読込中..."}),H&&(0,r.jsx)("div",{"data-testid":"terminal-ended-placeholder",className:"flex h-full items-center justify-center px-4 text-center text-sm text-gray-500 select-none",children:"セッションは終了しました(メッセージ送信で再開できます)"}),n&&s&&(0,r.jsx)(t1,{})]}),x?(0,r.jsx)("button",{type:"button",onClick:b,className:J,"aria-label":"Scroll to top",children:(0,r.jsx)(tI.A,{size:16,"aria-hidden":"true"})}):(0,r.jsx)("button",{type:"button",onClick:g,className:J,"aria-label":"Scroll to bottom",children:(0,r.jsx)(tE.A,{size:16,"aria-hidden":"true"})})]})}),t5=[{key:"Left",label:"◀",ariaLabel:"Send Left"},{key:"Up",label:"▲",ariaLabel:"Send Up"},{key:"Down",label:"▼",ariaLabel:"Send Down"},{key:"Right",label:"▶",ariaLabel:"Send Right"},{key:"Enter",label:"↵",ariaLabel:"Send Enter"}],t4={key:"Escape",label:"Esc",ariaLabel:"Send Escape"},t3={key:"q",label:"q",ariaLabel:"Send q (quit)"};function t6(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,{activeKey:l,markPressed:o}=eR(),c=eL(t,n,a,s),d="codex"===n?[...t5,t4,t3]:[...t5,t4],u=(0,i.useCallback)(e=>{o(e),c([e])},[o,c]);return(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 py-1.5 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800/50 rounded-lg",role:"toolbar","aria-label":"Terminal navigation keys",children:[(0,r.jsx)("span",{className:"text-xs text-amber-700 dark:text-amber-400 mx-2",title:"Send navigation / escape keys when the terminal is stuck in a TUI overlay",children:"Navigate"}),d.map(e=>{let{key:t,label:n,ariaLabel:a}=e;return(0,r.jsx)("button",{type:"button",className:"min-w-[44px] min-h-[44px] px-3 py-2 text-sm font-medium rounded-md\n border border-amber-300 dark:border-amber-700\n focus:outline-none focus:ring-2 focus:ring-amber-500\n transition-colors duration-75\n ".concat(l===t?"bg-amber-500 text-white border-amber-500 scale-95":"bg-white dark:bg-gray-700 hover:bg-amber-50 dark:hover:bg-gray-600 active:bg-amber-100 dark:active:bg-gray-500"),"aria-label":a,onClick:()=>u(t),children:n},t)})]})}function t8(e){return""!==(null!=e?e:"").trim()}function t9(e){let{worktreeId:t,cliToolId:n,instanceId:a,composerText:s,onActionSent:l}=e,o=(0,c.c)("worktree"),[d,u]=(0,i.useState)(!1),m=eL(t,n,a,l),h=(0,i.useCallback)(()=>{m(["Enter"])},[m]),f=(0,i.useCallback)(()=>{u(!0);let e=a&&a!==n?{cliToolId:n,instanceId:a}:{cliToolId:n};fetch("/api/worktrees/".concat(encodeURIComponent(t),"/clear-composer"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(()=>{l&&setTimeout(l,eM.LK)}).catch(e=>{console.error("Failed to clear composer:",e)}).finally(()=>{u(!1)})},[t,n,a,l]);if(!t8(s))return null;let x=s.length>300?"".concat(s.slice(0,300),"…"):s;return(0,r.jsxs)("div",{"data-testid":"unsent-composer-bar",role:"region","aria-label":o("unsentComposer.regionLabel"),className:"flex flex-wrap items-center gap-2 px-2 py-1.5 bg-info-subtle border border-info-border rounded-lg",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-info-foreground shrink-0",children:o("unsentComposer.label")}),(0,r.jsx)("code",{"data-testid":"unsent-composer-text",className:"flex-1 min-w-0 font-mono text-xs text-foreground break-all line-clamp-3 whitespace-pre-wrap",children:x}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,r.jsx)("button",{type:"button",onClick:h,"aria-label":o("unsentComposer.run"),className:"min-h-[32px] px-3 rounded-md text-xs font-medium bg-info-foreground text-info-subtle hover:opacity-90 transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background",children:o("unsentComposer.run")}),(0,r.jsx)("button",{type:"button",onClick:f,disabled:d,"aria-label":o("unsentComposer.clear"),className:"min-h-[32px] px-3 rounded-md text-xs font-medium bg-surface border border-info-border text-info-foreground hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background",children:o("unsentComposer.clear")})]})]})}function t7(e,t,n){let a=new TextEncoder;if(a.encode(e).length<=t)return e;let r=t-a.encode(n).length,s=0,l="";for(let t of e){let e=a.encode(t).length;if(s+e>r)break;s+=e,l+=t}return"".concat(l).concat(n)}let ne=RegExp("^\\p{M}$","u");function nt(e,t){if(e.length<=t)return e.length;let n=0,a=0;for(let r of e){let e=+!ne.test(r);if(1===e&&n>=t)break;n+=e,a+=r.length}return a}function nn(e,t,n){return e.slice(nt(e,t),nt(e,n))}function na(e){let t=0;for(let n of e)ne.test(n)||(t+=1);return t}let nr=/^([^\S\n]*)╹(▀{4,})/,ns=/^([^\S\n]*)[│┃]/;function nl(e,t){return"opencode"===e&&null!==function(e){let t=tz(e).split("\n"),n=-1,a=-1,r=-1;for(let e=0;e<t.length;e++){let s=nr.exec(t[e]);s&&(n=e,r=(a=s[1].length)+1+s[2].length)}if(-1===n)return null;let s=0,l="";for(let e=0;e<t.length;e++){let i=t[e];if(e!==n){let e=ns.exec(i);if(!e||e[1].length!==a)continue}let o=i.slice(nt(i,r)).trim();""!==o&&(s+=1,""===l&&(l=t7(o,200,"…[truncated]")))}return s<2?null:{id:"opencode_sidebar",matchedText:l,boxRight:r,rows:s}}(null!=t?t:"")}function ni(e){let{cliToolId:t,frame:n}=e,a=(0,c.c)("worktree");return(0,i.useMemo)(()=>nl(t,n),[t,n])?(0,r.jsxs)("div",{"data-testid":"opencode-sidebar-notice",role:"status","aria-label":a("opencodeSidebar.regionLabel"),className:"flex flex-wrap items-center gap-2 px-2 py-1.5 bg-warning-subtle border border-warning-border rounded-lg",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-warning-foreground shrink-0",children:a("opencodeSidebar.label")}),(0,r.jsx)("span",{className:"flex-1 min-w-0 text-xs text-foreground",children:a("opencodeSidebar.body")}),(0,r.jsx)("code",{"data-testid":"opencode-sidebar-notice-chord",className:"shrink-0 font-mono text-xs px-1.5 py-0.5 rounded bg-surface border border-warning-border text-warning-foreground",children:"ctrl+x b"})]}):null}let no=["Up","Down","Left","Right","Enter","Escape","Tab","BTab","PageUp","PageDown","Home","End","q","1","2","3","4","5","6","7","8","9","y","n"];[...no];let nc=["claude","command-code"],nd=["C-p","C-t"],nu=["a","l","t","m","g","u","r","c"];[...no,...nd,...nu],[...no,...nd,...nu];var nm=n(2317);let nh={mobile:{storageKey:"commandmate:mobile:opencodeQuickKeysOpen",defaultOpen:!1},desktop:{storageKey:"commandmate:desktop:opencodeQuickKeysOpen",defaultOpen:!0}},nf=e=>"boolean"==typeof e;function nx(e){return["C-x",e]}let np=[{id:"agentNext",keys:["Tab"],notation:"tab"},{id:"agentPrev",keys:["BTab"],notation:"shift+tab"},{id:"commands",keys:["C-p"],notation:"ctrl+p"},{id:"variant",keys:["C-t"],notation:"ctrl+t"}],ng=[{id:"agents",keys:nx("a"),notation:"ctrl+x a"},{id:"sessions",keys:nx("l"),notation:"ctrl+x l"},{id:"newSession",keys:nx("n"),notation:"ctrl+x n"},{id:"models",keys:nx("m"),notation:"ctrl+x m"},{id:"themes",keys:nx("t"),notation:"ctrl+x t"}],nb=[np,ng,[{id:"timeline",keys:nx("g"),notation:"ctrl+x g",sessionScoped:!0},{id:"undo",keys:nx("u"),notation:"ctrl+x u",sessionScoped:!0},{id:"redo",keys:nx("r"),notation:"ctrl+x r",sessionScoped:!0},{id:"compact",keys:nx("c"),notation:"ctrl+x c",sessionScoped:!0}],[{id:"pageUp",keys:["PageUp"],notation:"pgup"},{id:"pageDown",keys:["PageDown"],notation:"pgdn"},{id:"first",keys:["Home"],notation:"home"},{id:"last",keys:["End"],notation:"end"}]],nv=nb.reduce((e,t)=>e+t.length,0),ny=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,hasAgentSession:s,onKeysSent:l,compact:o=!1,collapsible:d=!1,layout:u="mobile"}=e,m=(0,c.c)("worktree"),{activeKey:h,markPressed:f}=eR(),x=eL(t,n,a,l),{open:p,toggle:g}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"mobile",{storageKey:t,defaultOpen:n}=nh[e],{value:a,setValue:r,isAvailable:s}=(0,nm.V)({key:t,defaultValue:n,validate:nf});return{open:a,toggle:(0,i.useCallback)(()=>r(e=>!e),[r]),isPersistent:s}}(u),b=(0,i.useId)(),v=(0,i.useCallback)(e=>{f(e.id),x([...e.keys])},[f,x]);if("opencode"!==n)return null;let y=(0,r.jsxs)("div",{className:"@container flex flex-wrap items-center gap-1.5 ".concat(d?"px-1.5 pb-1.5":"py-1.5 bg-muted rounded-lg"),id:d?b:void 0,role:"toolbar","aria-label":m("opencodeQuickKeys.toolbarLabel"),"data-testid":"opencode-quick-keys",children:[d?null:(0,r.jsx)("span",{className:"text-xs text-muted-foreground mx-2",children:m("opencodeQuickKeys.caption")}),nb.map((e,t)=>(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[t>0?(0,r.jsx)("span",{className:"w-px h-6 bg-border mx-0.5","aria-hidden":"true"}):null,e.map(e=>{let t=m("opencodeQuickKeys.keys.".concat(e.id)),n=!0===e.sessionScoped&&!s;return(0,r.jsxs)("button",{type:"button",disabled:n,className:"min-h-[44px] px-3 py-2 text-sm font-medium rounded-md\n border border-border\n focus:outline-none focus:ring-2 focus:ring-ring\n transition-colors duration-75\n disabled:opacity-50 disabled:cursor-not-allowed\n ".concat(h===e.id?"bg-accent-500 text-white border-accent-500 scale-95":"bg-surface dark:bg-surface-2 hover:bg-muted active:bg-muted disabled:hover:bg-surface"),"aria-label":"".concat(t," (").concat(e.notation,")"),title:n?m("opencodeQuickKeys.needsSession",{notation:e.notation}):"".concat(t," — ").concat(e.notation),"data-testid":"opencode-quick-key-".concat(e.id),onClick:()=>v(e),children:[t,o?null:(0,r.jsx)("span",{className:"ml-1.5 text-xs text-muted-foreground hidden @min-[640px]:inline",children:e.notation})]},e.id)})]},e[0].id))]});return d?(0,r.jsxs)("div",{className:"bg-muted rounded-lg","data-testid":"opencode-quick-keys-disclosure",children:[(0,r.jsxs)("button",{type:"button",className:"w-full min-h-[44px] flex items-center gap-2 px-3 py-2 text-sm font-medium rounded-lg touch-manipulation transition-colors hover:bg-surface-2 active:bg-surface-2 focus:outline-none focus:ring-2 focus:ring-ring","aria-expanded":p,"aria-controls":b,"aria-label":p?m("opencodeQuickKeys.hideKeys"):m("opencodeQuickKeys.showKeys"),"data-testid":"opencode-quick-keys-toggle",onClick:g,children:[(0,r.jsx)(K.A,{className:"w-4 h-4 shrink-0 transition-transform duration-150 ".concat(p?"":"-rotate-90"),"aria-hidden":"true"}),(0,r.jsx)("span",{children:m("opencodeQuickKeys.toolbarLabel")}),(0,r.jsx)("span",{className:"ml-auto text-xs text-muted-foreground",children:nv})]}),p?y:null]}):y}),nj=["variant","models","commands"].map(e=>{let t=[...np,...ng].find(t=>t.id===e);if(!t)throw Error("OpencodeQuickKeys: unknown model key id ".concat(e));return t}),nw=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,l=(0,c.c)("worktree"),{activeKey:o,markPressed:d}=eR(),u=eL(t,n,a,s),m=(0,i.useCallback)(e=>{d(e.id),u([...e.keys])},[d,u]);return"opencode"!==n?null:(0,r.jsxs)("div",{"data-testid":"opencode-model-keys",role:"toolbar","aria-label":l("selectionKeys.opencodeToolbarLabel"),className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-muted px-2 py-1.5",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:l("selectionKeys.opencodeCaption")}),nj.map(e=>{let t=l("opencodeQuickKeys.keys.".concat(e.id));return(0,r.jsxs)("button",{type:"button","data-testid":"opencode-model-key-".concat(e.id),"aria-label":"".concat(t," (").concat(e.notation,")"),title:"".concat(t," — ").concat(e.notation),onClick:()=>m(e),className:"min-h-[44px] rounded-md border border-border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat(o===e.id?"border-accent-500 bg-accent-500 text-white scale-95":"bg-surface hover:bg-muted active:bg-muted dark:bg-surface-2"),children:[t,(0,r.jsx)("span",{className:"ml-1.5 text-xs text-muted-foreground",children:e.notation})]},e.id)})]})});var nk=n(7620),nN=n(35299);function nC(){return{pending:0,delivered:0,prompt:0,expired:0,cancelled:0}}let nS=[],nT=new Map;function nI(){return{open:nS,counts:nC()}}async function nE(e,t){try{var n;let a=await fetch("/api/relays?worktree=".concat(encodeURIComponent(e)));if(!a.ok)return;let r=await a.json();if(nT.get(e)!==t)return;for(let e of(t.snapshot={open:Array.isArray(r.open)?r.open:nS,counts:null!=(n=r.counts)?n:nC()},t.listeners))e()}catch(e){}}function nA(e){let[t]=(0,i.useState)(nI),n=(0,i.useCallback)(t=>{let n;if(!e)return()=>{};let a=((n=nT.get(e))||(n={snapshot:nI(),listeners:new Set,timer:null,refs:0},nT.set(e,n)),n.refs+=1,null===n.timer&&(nE(e,n),n.timer=setInterval(()=>void nE(e,n),2e4)),n);return a.listeners.add(t),()=>{a.listeners.delete(t),function(e){let t=nT.get(e);t&&(t.refs-=1,t.refs>0||(t.timer&&clearInterval(t.timer),nT.delete(e)))}(e)}},[e]),a=(0,i.useCallback)(()=>{var n,a;return e&&null!=(a=null==(n=nT.get(e))?void 0:n.snapshot)?a:t},[e,t]),{open:r,counts:s}=(0,i.useSyncExternalStore)(n,a,a),l=(0,i.useCallback)(()=>{let t=e?nT.get(e):void 0;e&&t&&nE(e,t)},[e]);return(0,i.useMemo)(()=>({open:r,counts:s,owedBy:t=>r.filter(n=>n.to.worktreeId===e&&n.to.instanceId===t),awaitedBy:t=>r.filter(n=>n.from.worktreeId===e&&n.from.instanceId===t),refresh:l}),[r,s,e,l])}function nM(e){let t=[],n=e.awaiting.filter(e=>"prompt"===e.state);n.length>0&&t.push({tone:"prompt",key:"badgePrompt",params:{count:n.length,alias:e.aliasOf(n[0].to)},titleKey:"promptTitle",count:n.length});let a=e.awaiting.filter(e=>"prompt"!==e.state);return 1===a.length?t.push({tone:"awaiting",key:"badgeAwaiting",params:{alias:e.aliasOf(a[0].to)},titleKey:"awaitingTitle",count:1}):a.length>1&&t.push({tone:"awaiting",key:"badgeAwaitingMany",params:{count:a.length},titleKey:"awaitingTitle",count:a.length}),1===e.owed.length?t.push({tone:"owed",key:"badgeOwed",params:{alias:e.aliasOf(e.owed[0].from)},titleKey:"owedTitle",count:1}):e.owed.length>1&&t.push({tone:"owed",key:"badgeOwedMany",params:{count:e.owed.length},titleKey:"owedTitle",count:e.owed.length}),t}var nL=n(96195);function nR(e){if(0===e.length)return"0";let t=e[e.length-1],n=t.timestamp instanceof Date?t.timestamp.getTime():String(t.timestamp);return"".concat(e.length,"|").concat(t.id,"|").concat(n)}function nP(e){let{messages:t}=e,[n,a]=(0,i.useState)(!1),[r,s]=(0,i.useState)(""),[l,o]=(0,i.useState)([]),[c,d]=(0,i.useState)(0),[u,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f=(0,i.useRef)(""),x=(0,i.useRef)(!1),p=(0,i.useRef)(nR(t)),g=(0,i.useRef)(t);g.current=t;let b=l.reduce((e,t)=>e+t.ranges.length,0),v=(0,i.useMemo)(()=>(function(e,t){if(0===e.length||t<0)return null;let n=0;for(let a of e){if(t<n+a.ranges.length)return{messageId:a.messageId,localIndex:t-n};n+=a.ranges.length}return null})(l,c),[l,c]),y=(0,i.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),j=(0,i.useCallback)(e=>{let{positions:t,capped:n}=function(e,t){if(t.length<2||0===e.length)return{positions:[],capped:!1};let n=t.toLowerCase(),a=t.length,r=[],s=0,l=!1;for(let t of e){if(l)break;let i=t.content;if(!i)continue;let o=i.toLowerCase(),c=[],d=0;for(;;){let r=o.indexOf(n,d);if(-1===r)break;if(c.push({start:r,end:r+a}),d=r+1,(s+=1)>=500){if(-1!==o.indexOf(n,d))l=!0;else{let a=e.indexOf(t)+1;for(let t=a;t<e.length;t++){let a=e[t].content;if(a&&-1!==a.toLowerCase().indexOf(n)){l=!0;break}}}break}}c.length>0&&r.push({messageId:t.id,ranges:c})}return{positions:r,capped:l}}(g.current,e);o(t),d(0),m(n)},[]),w=(0,i.useCallback)(e=>{y(),f.current=e,x.current||(h.current=setTimeout(()=>{j(e)},300))},[y,j]),k=(0,i.useCallback)(e=>{s(e),w(e)},[w]),N=(0,i.useCallback)(()=>{a(!0)},[]),C=(0,i.useCallback)(()=>{a(!1),s(""),f.current="",o([]),d(0),m(!1),y()},[y]),S=(0,i.useCallback)(()=>{d(e=>0===b?0:(e+1)%b)},[b]),T=(0,i.useCallback)(()=>{d(e=>0===b?0:(e-1+b)%b)},[b]),I=(0,i.useCallback)(()=>{x.current=!0,y()},[y]),E=(0,i.useCallback)(()=>{x.current=!1;let e=f.current;e.length>=2&&(y(),h.current=setTimeout(()=>{j(e)},300))},[y,j]);return(0,i.useEffect)(()=>{let e=nR(t);if(e===p.current)return;p.current=e;let n=f.current;n.length>=2&&j(n)},[t,j]),(0,i.useEffect)(()=>()=>{y(),f.current=""},[y]),{isOpen:n,query:r,matchCount:b,currentIndex:c,isAtMaxMatches:u,matchPositions:l,currentMatch:v,openSearch:N,closeSearch:C,setQuery:k,onCompositionStart:I,onCompositionEnd:E,nextMatch:S,prevMatch:T}}var nD=n(69352);let nF=/^(https?|mailto|tel|file):/i,nO=/^[a-zA-Z][a-zA-Z0-9+.-]*:/,nz=/^file:\/\/(localhost)?/i,n_=/:\d+(?::\d+)?$/;function nB(e){let t=(0,nD.d3)(e.trim());return t?t.startsWith("#")?"anchor":nz.test(t)?"file":nO.test(t)&&!nF.test(t)?null:"external"===(0,nD.dj)(t)?"external":"file":null}function nH(e){let t=[];for(let n of e.split("/"))if(""!==n&&"."!==n){if(".."===n){t.pop();continue}t.push(n)}return t.join("/")}function nV(e,t){var n;if("file"!==nB(e))return null;let a=(function(e){try{return decodeURIComponent(e)}catch(t){return e}})((function(e){let t=e.indexOf("#");return -1===t?e:e.slice(0,t)})(e.trim().replace(nz,"")).replace(n_,"")).trim();if(!a)return null;if(!a.startsWith("/"))return nH(a)||null;let r=t?(n=t.trim()).length>1&&n.endsWith("/")?n.replace(/\/+$/,""):n:"";return r&&r.startsWith("/")?a===r?null:a.startsWith("".concat(r,"/"))?nH(a.slice(r.length+1))||null:a:a}let nU={method:"HEAD",cache:"no-store"},nK=(e,t)=>fetch(e,t);async function nW(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:nK;try{var a;return(a=await n("/api/worktrees/".concat(encodeURIComponent(e),"/files/").concat((0,eX.o)(t)),nU)).ok?"present":404===a.status||400===a.status||403===a.status?"missing":"unknown"}catch(e){return"unknown"}}let n$=Object.freeze({}),nq=(0,i.createContext)(n$),nG=nq.Provider;function nJ(){return(0,i.useContext)(nq)}function nY(e){let{scrollTop:t,scrollHeight:n,clientHeight:a}=e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:80,s=n-t-a;return!!Number.isFinite(s)&&s<=r}let nQ={human:5,auto:4,terminal:3,pending:2,unclassified:1,unknown:0};function nX(e,t){let n=null==e?void 0:e[t];return"string"==typeof n?n:""}function nZ(e){return(null==e?void 0:e.messageType)==="prompt"}function n0(e){var t;let n,a="object"==typeof(t=e.promptData)&&null!==t?t:null,r=function(e){let t=null==e?void 0:e.summary;return"string"==typeof t&&t.startsWith("PermissionRequest allow")}(e),s=nX(a,"question"),l=nX(a,"approvalTarget"),i=nX(a,"answeredBy"),o=nX(a,"status"),c=nX(a,"type"),d="string"==typeof e.summary?e.summary:"";return n=r?"auto":"auto"===i||"human"===i||"terminal"===i?i:c===T||"unclassified"===o?"unclassified":"pending"===o?"pending":"unknown",{id:e.id,messageIds:[e.id],label:function(e){let t=e.replace(/\s+/g," ").trim();return t.length<=160?t:"".concat(t.slice(0,159).trimEnd(),"…")}(s||d),outcome:n,isPermissionAudit:r,timestampMs:function(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:0}if("string"==typeof e||"number"==typeof e){let t=new Date(e).getTime();return Number.isFinite(t)?t:0}return 0}(e.timestamp),mergeKey:s?JSON.stringify([s,l]):""}}let n1=/(^|[\s`"'(\[<(「『【])(\/[^\s\n<>"']+\.[a-zA-Z0-9]+)/g;function n2(e){if("string"!=typeof e||0===e.length)return[{type:"text",content:""}];let t=[],n=0;for(let s of e.matchAll(n1)){var a,r;let l=null!=(a=s[1])?a:"",i=s[2];if(!i)continue;let o=(null!=(r=s.index)?r:0)+l.length;o>n&&t.push({type:"text",content:e.slice(n,o)}),t.push({type:"path",content:i}),n=o+i.length}return 0===t.length?[{type:"text",content:e}]:(n<e.length&&t.push({type:"text",content:e.slice(n)}),t)}function n5(e){return!e||"assistant"!==e.role}let n4={highlightName:"chat-search",currentHighlightName:"chat-search-current",fallbackOverlayId:"chat-search-fallback-overlay",fallbackOverlayBgColor:"rgba(59, 130, 246, 0.6)"},n3="commandmate:chatShowToolActivity";function n6(){try{return"true"===window.localStorage.getItem(n3)}catch(e){return!1}}var n8=n(27937),n9=n(1473),n7=n(76907),ae=n(6132),at=n(48314),an=n(54916),aa=n(51238),ar=n(22133),as=n(10934),al=n(5225);let ai=["oc-turn:","claude-turn:","codex-turn:","antigravity-turn:","command-code-turn:"];function ao(e){return"string"==typeof e&&ai.some(t=>e.startsWith(t))}var ac=n(55041),ad=n(8574);let au={en:ad.c,ja:ac.ja};function am(e){var t;return null!=(t=au[e])?t:ad.c}let ah="Tool calls",af=new RegExp("^>[ \\t]*\\*\\*".concat(ah,"(?:[ \\t]*\\((\\d+)\\))?\\*\\*[ \\t]*$")),ax=/^- `[^`\n]+`(?: — .*)?$/;function ap(e){return{prose:e,toolLog:"",toolCalls:0}}let ag="mr-auto w-full max-w-full px-1 text-sm text-foreground",ab="chat-bubble",av="flex w-full flex-col gap-1 pb-3",ay="max-w-full overflow-x-hidden break-words [word-break:break-word]",aj="".concat(ay," chat-md"),aw=i.createContext({showAll:!1}),ak=aw.Provider,aN={showAll:!0},aC="mr-auto flex w-fit max-w-full items-center gap-1.5 rounded-full border border-border bg-surface-2 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring";function aS(){let{showAll:e}=i.useContext(aw),[t,n]=(0,i.useState)(null),a=null!==t&&t.against===e?t.isOpen:e,r=(0,i.useCallback)(()=>n({against:e,isOpen:!a}),[e,a]);return{isOpen:a,toggle:r}}let aT=/^>[ \t]*\*\*Thinking(?:[ \t]*\((\d+)\))?\*\*[ \t]*$/,aI=(0,i.memo)(function(e){let{blocks:t,children:n}=e,a=(0,c.c)("worktree"),{isOpen:s,toggle:l}=aS(),i=s?K.A:n8.A;return(0,r.jsxs)("div",{"data-testid":"chat-thinking-group","data-thinking-blocks":t,className:"mt-2 flex w-full flex-col gap-1",children:[(0,r.jsxs)("button",{type:"button","data-testid":"chat-thinking-toggle",onClick:l,"aria-expanded":s,"aria-label":a(s?"chatTranscript.thinking.collapse":"chatTranscript.thinking.expand"),className:aC,children:[(0,r.jsx)(n9.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:a("chatTranscript.thinking.summary",{count:t})}),(0,r.jsx)(i,{size:12,"aria-hidden":"true"})]}),s&&(0,r.jsx)("div",{"data-testid":"chat-thinking-body",className:"max-w-full border-l-2 border-border pl-2 text-muted-foreground",children:n})]})}),aE=(0,i.memo)(function(e){let{toolCalls:t,children:n}=e,a=(0,c.c)("worktree"),{isOpen:s,toggle:l}=aS(),i=s?K.A:n8.A;return(0,r.jsxs)("div",{"data-testid":"chat-tool-log-group","data-tool-calls":t,className:"mt-2 flex w-full flex-col gap-1",children:[(0,r.jsxs)("button",{type:"button","data-testid":"chat-tool-log-toggle",onClick:l,"aria-expanded":s,"aria-label":a(s?"chatTranscript.toolLog.collapse":"chatTranscript.toolLog.expand"),className:aC,children:[(0,r.jsx)(w.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:a("chatTranscript.toolLog.summary",{count:t})}),(0,r.jsx)(i,{size:12,"aria-hidden":"true"})]}),s&&(0,r.jsx)("div",{"data-testid":"chat-tool-log-body",className:"max-w-full border-l-2 border-border pl-2 text-muted-foreground",children:n})]})}),aA={claude:!0,codex:!0,antigravity:!0,"command-code":!0,opencode:!0,copilot:!1,gemini:!1,"vibe-local":!1},aM=(0,i.memo)(function(e){let{children:t}=e,n=(0,c.c)("worktree"),{isOpen:a,toggle:s}=aS(),l=a?K.A:n8.A;return(0,r.jsxs)("div",{"data-testid":"chat-pane-scrape-group",className:"flex w-full flex-col gap-1",children:[(0,r.jsxs)("button",{type:"button","data-testid":"chat-pane-scrape-toggle",onClick:s,"aria-expanded":a,className:aC,children:[(0,r.jsx)(v.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:n("agentSource.kindScraper")}),(0,r.jsx)(l,{size:12,"aria-hidden":"true"})]}),a&&(0,r.jsx)("div",{"data-testid":"chat-pane-scrape-body",className:"max-w-full border-l-2 border-border pl-2 text-muted-foreground",children:t})]})}),aL=(0,i.memo)(function(e){var t;let{href:n,children:a,onFilePathClick:s,...l}=e,o=(0,c.c)("worktree"),d=n?nB(n):null,u=(0,i.useCallback)(e=>{n&&(e.preventDefault(),s(n))},[n,s]);return n&&null!==d&&"anchor"!==d?"external"===d?(0,r.jsx)("a",{...l,href:n,target:"_blank",rel:"noopener noreferrer",children:a}):(0,r.jsx)("a",{...l,href:n,"data-testid":"chat-file-link",onClick:u,className:"cursor-pointer font-mono text-sm text-accent-700 underline-offset-2 hover:underline dark:text-accent-400","aria-label":o("conversation.openFile",{path:null!=(t=nV(n))?t:n}),children:a}):(0,r.jsx)("a",{...l,href:n,children:a})}),aR=(0,i.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,c.c)("worktree"),s=(0,i.useMemo)(()=>n2(t),[t]),l=(0,i.useCallback)(e=>()=>n(e),[n]);return(0,r.jsx)("span",{children:s.map((e,t)=>"path"===e.type?(0,r.jsx)("button",{type:"button",onClick:l(e.content),className:"cursor-pointer font-mono text-sm text-accent-700 underline-offset-2 hover:underline dark:text-accent-400","aria-label":a("conversation.openFile",{path:e.content}),children:e.content},t):(0,r.jsx)("span",{children:e.content},t))})}),aP=(0,i.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,i.useMemo)(()=>{let e=e=>i.Children.map(e,e=>"string"==typeof e?(0,r.jsx)(aR,{content:e,onFilePathClick:n}):e);return{p:t=>{let{children:n}=t;return(0,r.jsx)("p",{children:e(n)})},li:t=>{let{children:n}=t;return(0,r.jsx)("li",{children:e(n)})},td:t=>{let{children:n}=t;return(0,r.jsx)("td",{children:e(n)})},th:t=>{let{children:n}=t;return(0,r.jsx)("th",{children:e(n)})},strong:t=>{let{children:n}=t;return(0,r.jsx)("strong",{children:e(n)})},em:t=>{let{children:n}=t;return(0,r.jsx)("em",{children:e(n)})},a:e=>{let{href:t,children:a,node:s,...l}=e;return(0,r.jsx)(aL,{...l,href:t,onFilePathClick:n,children:a})}}},[n]),s=(0,i.useMemo)(()=>[ar.A],[]),l=(0,i.useMemo)(()=>[as.A,al.A],[]),o=(0,i.useMemo)(()=>(function(e){if("string"!=typeof e||0===e.length)return ap(null!=e?e:"");if(!e.includes(ah)&&!e.startsWith("- `"))return ap(e);let t=e.split("\n"),n=t.length;for(;n>0&&0===t[n-1].trim().length;)n-=1;for(let e=n-1;e>=0;e-=1){let a=af.exec(t[e]);if(!a){if(!t[e].startsWith(">"))break;continue}if(e>0&&t[e-1].startsWith(">"))break;let r=t.slice(e+1,n).map(e=>e.replace(/^>[ \t]?/,"")).join("\n").replace(/^\n+/,"").replace(/\n+$/,""),s=a[1]?Number.parseInt(a[1],10):0;return{prose:t.slice(0,e).join("\n").replace(/\n+$/,""),toolLog:r,toolCalls:Number.isFinite(s)&&s>0?s:r.split("\n").filter(e=>e.trim().length>0).length}}let a=0;for(;a<t.length&&ax.test(t[a]);)a+=1;return 0===a?ap(e):{prose:t.slice(a).join("\n").replace(/^\n+/,""),toolLog:t.slice(0,a).join("\n"),toolCalls:a}})(t),[t]),c=(0,i.useMemo)(()=>(function(e){if(!e.includes("Thinking"))return{body:e,reasoning:null,blocks:0};let t=e.split("\n"),n=[],a=[],r=0,s=0;for(;s<t.length;){let e=aT.exec(t[s]),l=0===s||!t[s-1].startsWith(">");if(!e||!l){n.push(t[s]),s+=1;continue}let i=s+1;for(;i<t.length&&t[i].startsWith(">");)i+=1;let o=e[1]?Number.parseInt(e[1],10):1;r+=Number.isFinite(o)&&o>0?o:1,a.push(t.slice(s+1,i).map(e=>e.replace(/^>[ \t]?/,"")).join("\n").replace(/^\n+/,"").replace(/\n+$/,"")),s=i}return 0===r?{body:e,reasoning:null,blocks:0}:{body:n.join("\n").replace(/\n{3,}/g,"\n\n").trim(),reasoning:a.join("\n\n").replace(/^\n+/,"").replace(/\n+$/,""),blocks:r}})(o.prose),[o.prose]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(aa.oz,{remarkPlugins:s,rehypePlugins:l,components:a,children:c.body}),null!==c.reasoning&&(0,r.jsx)(aI,{blocks:c.blocks,children:(0,r.jsx)(aa.oz,{remarkPlugins:s,rehypePlugins:l,components:a,children:c.reasoning})}),o.toolCalls>0&&(0,r.jsx)(aE,{toolCalls:o.toolCalls,children:(0,r.jsx)(aa.oz,{remarkPlugins:s,rehypePlugins:l,components:a,children:o.toolLog})})]})}),aD={human:"chatTranscript.toolApproval.answeredByHuman",auto:"chatTranscript.toolApproval.autoApproved",terminal:"chatTranscript.toolApproval.answeredInTerminal",pending:"chatTranscript.toolApproval.awaitingAnswer",unclassified:"chatTranscript.toolApproval.unclassified",unknown:"chatTranscript.toolApproval.resolved"},aF=(0,i.memo)(function(e){let{entries:t}=e,n=(0,c.c)("worktree"),{isOpen:a,toggle:s}=aS();if(0===t.length)return null;let l=a?K.A:n8.A;return(0,r.jsxs)("div",{"data-testid":"chat-tool-approval-group","data-approval-count":t.length,className:"".concat(av," items-start"),children:[(0,r.jsxs)("button",{type:"button","data-testid":"chat-tool-approval-toggle",onClick:s,"aria-expanded":a,"aria-label":a?n("chatTranscript.toolApproval.collapse"):n("chatTranscript.toolApproval.expand"),className:aC,children:[(0,r.jsx)(n7.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:n("chatTranscript.toolApproval.summary",{count:t.length})}),(0,r.jsx)(l,{size:12,"aria-hidden":"true"})]}),a&&(0,r.jsx)("ul",{"data-testid":"chat-tool-approval-list",className:"mr-auto flex w-full max-w-full flex-col gap-1 pl-1",children:t.map(e=>(0,r.jsxs)("li",{"data-testid":"chat-tool-approval-entry","data-approval-outcome":e.outcome,"data-approval-audit":e.isPermissionAudit?"true":void 0,"data-approval-merged":e.messageIds.length,className:"flex max-w-full flex-wrap items-baseline gap-x-2 gap-y-0.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"min-w-0 break-words [word-break:break-word] font-mono text-foreground",children:e.label||n("chatTranscript.toolApproval.unlabeled")}),(0,r.jsx)("span",{"data-testid":"chat-tool-approval-outcome",children:n(aD[e.outcome])})]},e.id))})]})}),aO=(0,i.memo)(function(e){var t;let{message:n,showHeader:a,onFilePathClick:s,onCopy:l,onInsertToMessage:o,onRetryPending:d,onDiscardPending:u}=e,m=(0,to.Ym)(),h=(0,c.c)("worktree"),f=(0,c.c)("common"),x="user"===n.role,p=n.optimisticState,g=ao(n.requestId),b="assistant"===n.role&&"normal"===n.messageType&&("string"!=typeof n.requestId||!(n.requestId.length>0))&&!0===aA[null!=(t=n.cliToolId)?t:"claude"],v=(0,X.bg)(n.timestamp,am(m)),y=(0,i.useMemo)(()=>{var e;return"string"==typeof(e=n.content)?tz(e):""},[n.content]),j=g?n.content:y,w=[x?"".concat("w-fit rounded-2xl border px-3 py-2 text-sm text-foreground"," ").concat("ml-auto"," ").concat("max-w-[85%] sm:max-w-[75%]"," rounded-br-md"):ag,x&&"error"===p?"border-danger-border bg-danger-subtle":"",x&&"error"!==p?"border-accent-500/30 bg-accent-500/10":"","sending"===p?"opacity-70":""].filter(Boolean).join(" "),k=g?aj:"".concat(ay," whitespace-pre-wrap");return(0,r.jsxs)("div",{"data-testid":"chat-message-row","data-role":n.role,"data-row-message-id":n.id,className:[av,n.archived?"opacity-60":""].filter(Boolean).join(" "),children:[a&&(0,r.jsxs)("div",{className:["flex items-center gap-2 px-1 text-xs text-muted-foreground",x?"justify-end":""].filter(Boolean).join(" "),children:[(0,r.jsx)("span",{className:x?"font-medium text-accent-700 dark:text-accent-400":"font-medium",children:h(x?"conversation.you":"conversation.assistant")}),v&&(0,r.jsx)("span",{children:v})]}),(0,r.jsx)("div",{"data-testid":ab,className:w,children:b?(0,r.jsx)(aM,{children:(0,r.jsx)("div",{"data-message-id":n.id,className:k,children:(0,r.jsx)(aR,{content:y,onFilePathClick:s})})}):(0,r.jsx)("div",{"data-message-id":n.id,"data-markdown":g?"true":void 0,className:k,children:g?(0,r.jsx)(aP,{content:n.content,onFilePathClick:s}):(0,r.jsx)(aR,{content:y,onFilePathClick:s})})}),(0,r.jsxs)("div",{"data-testid":"chat-message-actions",className:["flex items-center gap-1 px-1",x?"justify-end":""].filter(Boolean).join(" "),children:["sending"===p&&(0,r.jsxs)("span",{"data-testid":"chat-optimistic-sending",className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(nN.A,{size:12,className:"animate-spin","aria-hidden":"true"}),(0,r.jsx)("span",{children:h("conversation.sending")})]}),"error"===p&&(0,r.jsxs)("span",{"data-testid":"chat-optimistic-error",className:"flex items-center gap-1 text-xs text-danger-foreground",children:[(0,r.jsx)(ae.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:h("conversation.failedToSend")})]}),"error"===p?(0,r.jsxs)(r.Fragment,{children:[d&&(0,r.jsxs)("button",{type:"button","data-testid":"chat-pending-retry",onClick:()=>d(n.id),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-accent-700 transition-colors hover:bg-muted dark:text-accent-400","aria-label":h("conversation.retrySending"),title:f("retry"),children:[(0,r.jsx)(at.A,{size:12,"aria-hidden":"true"}),f("retry")]}),u&&(0,r.jsxs)("button",{type:"button","data-testid":"chat-pending-discard",onClick:()=>u(n.id),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-danger-foreground","aria-label":h("conversation.discardMessage"),title:h("conversation.discard"),children:[(0,r.jsx)(eG.A,{size:12,"aria-hidden":"true"}),h("conversation.discard")]})]}):(0,r.jsxs)(r.Fragment,{children:[l&&(0,r.jsx)("button",{type:"button","data-testid":"chat-copy-message",onClick:()=>l(j),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground","aria-label":h("conversation.copyMessage"),title:h("conversation.copy"),children:(0,r.jsx)(ej.A,{size:14,"aria-hidden":"true"})}),x&&o&&(0,r.jsx)("button",{type:"button","data-testid":"chat-insert-user-message",onClick:()=>o(j),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-accent-600 dark:hover:text-accent-400","aria-label":h("conversation.insertToMessage"),title:h("conversation.insertToMessage"),children:(0,r.jsx)(an.A,{size:14,"aria-hidden":"true"})})]})]})]})}),az="chat-live-turn",a_=(0,i.memo)(function(e){let{turnKey:t,version:n,body:a,partial:s=!1,isThinking:l=!1,showHeader:i=!1,onFilePathClick:o}=e,d=(0,c.c)("worktree"),u="string"==typeof a&&a.length>0;return(0,r.jsxs)("div",{"data-testid":az,"data-role":"assistant","data-turn-key":t,"data-version":void 0===n?void 0:String(n),"data-has-body":u?"true":"false",role:"group","aria-label":d("chatSurface.progressLabel"),className:av,children:[i&&(0,r.jsx)("div",{className:"flex items-center gap-2 px-1 text-xs text-muted-foreground",children:(0,r.jsx)("span",{className:"font-medium",children:d("conversation.assistant")})}),(0,r.jsxs)("div",{"data-testid":ab,className:ag,children:[u&&(0,r.jsx)("div",{"data-testid":"chat-live-turn-body","data-markdown":"true",className:aj,children:(0,r.jsx)(aP,{content:a,onFilePathClick:o})}),(0,r.jsxs)("div",{"data-testid":"chat-live-turn-indicator",role:"status","aria-live":"polite",className:["flex flex-wrap items-center gap-2 text-xs text-muted-foreground",u?"mt-1.5":""].filter(Boolean).join(" "),children:[(0,r.jsx)(nN.A,{size:14,className:"animate-spin","aria-hidden":"true"}),(0,r.jsx)("span",{children:d(l?"chatSurface.thinking":"chatSurface.generating")}),s&&(0,r.jsx)("span",{"data-testid":"chat-live-turn-partial",className:"rounded border border-warning-border bg-warning-subtle px-1 py-0.5 text-warning-foreground",children:d("chatSurface.progressPartial")})]})]})]})});function aB(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:o,onClose:d,isAtMaxMatches:u,onCompositionStart:m,onCompositionEnd:h}=e,f=(0,i.useRef)(null),x=(0,c.c)("worktree");(0,i.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let p=(0,i.useCallback)(e=>{"Escape"===e.key&&d()},[d]),g=(0,i.useCallback)(e=>{n(e.target.value)},[n]),b=0===a?"0/0":u?x("history.search.countAtMax",{current:s+1,max:500}):"".concat(s+1,"/").concat(a);return(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-surface border border-border rounded shadow-lg",role:"search","aria-label":x("history.search.regionLabel"),children:[(0,r.jsx)("input",{ref:f,type:"text",value:t,onChange:g,onKeyDown:p,onCompositionStart:m,onCompositionEnd:h,placeholder:x("history.search.placeholder"),className:"bg-transparent text-foreground text-sm outline-none w-32 sm:w-40 placeholder-muted-foreground","aria-label":x("history.search.keywordLabel"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1}),(0,r.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"text-muted-foreground text-xs min-w-[3rem] text-right",children:b}),(0,r.jsx)("button",{type:"button",onClick:o,disabled:0===a,"aria-label":x("history.search.prev"),className:"text-muted-foreground hover:text-foreground disabled:opacity-40 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▲"}),(0,r.jsx)("button",{type:"button",onClick:l,disabled:0===a,"aria-label":x("history.search.next"),className:"text-muted-foreground hover:text-foreground disabled:opacity-40 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▼"}),(0,r.jsx)("button",{type:"button",onClick:d,"aria-label":x("history.search.close"),className:"text-muted-foreground hover:text-foreground min-w-[36px] min-h-[36px] flex items-center justify-center text-base ml-1",children:"✕"})]})}let aH="chat-transcript-scroll-container",aV="chat-transcript-jump-fab",aU="absolute bottom-3 right-3 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-border bg-surface-2/80 text-muted-foreground shadow-lg backdrop-blur transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation";function aK(){let e=(0,c.c)("worktree");return(0,r.jsx)("div",{"data-testid":"chat-transcript-loading",role:"status","aria-label":e("chatTranscript.loading"),children:[0,1,2].map(e=>(0,r.jsxs)("div",{className:"mb-4 flex flex-col gap-1 ".concat(e%2==0?"items-end":"items-start"),children:[(0,r.jsx)(m.EA,{className:"h-3 w-24"}),(0,r.jsx)(m.EA,{className:"h-14 rounded-2xl ".concat(e%2==0?"w-2/3":"w-11/12")})]},e))})}function aW(e){let{turnKey:t,version:n,body:a,partial:s=!1,showHeader:l=!1,onFilePathClick:i}=e,o=(0,c.c)("worktree"),d="string"==typeof a&&a.length>0;return(0,r.jsxs)("div",{"data-testid":az,"data-role":"assistant","data-settling":"true","data-turn-key":t,"data-version":void 0===n?void 0:String(n),"data-has-body":d?"true":"false",role:"group","aria-label":o("chatSurface.settlingLabel"),className:av,children:[l&&(0,r.jsx)("div",{className:"flex items-center gap-2 px-1 text-xs text-muted-foreground",children:(0,r.jsx)("span",{className:"font-medium",children:o("conversation.assistant")})}),(0,r.jsxs)("div",{"data-testid":ab,className:ag,children:[d&&(0,r.jsx)("div",{"data-testid":"chat-live-turn-body","data-markdown":"true",className:aj,children:(0,r.jsx)(aP,{content:a,onFilePathClick:i})}),(0,r.jsxs)("div",{"data-testid":"chat-settling-turn-note",className:["flex flex-wrap items-center gap-2 text-xs text-muted-foreground",d?"mt-1.5":""].filter(Boolean).join(" "),children:[(0,r.jsx)("span",{children:o("chatSurface.settling")}),s&&(0,r.jsx)("span",{"data-testid":"chat-live-turn-partial",className:"rounded border border-warning-border bg-warning-subtle px-1 py-0.5 text-warning-foreground",children:o("chatSurface.progressPartial")})]})]})]})}function a$(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{"data-testid":"chat-transcript-empty",className:"flex flex-col items-center justify-center gap-1 py-10 text-center text-muted-foreground",children:[(0,r.jsx)(U.A,{className:"mb-1 h-10 w-10 opacity-50","aria-hidden":"true"}),(0,r.jsx)("p",{className:"text-sm",children:e("chatTranscript.empty")}),(0,r.jsx)("p",{className:"text-xs",children:e("chatTranscript.emptyHint")})]})}let aq=(0,i.memo)(function(e){let{messages:t,worktreeId:n,worktreePath:a,cliToolId:s,isLoading:l=!1,className:o="",onFilePathClick:d,showToast:u,onInsertToMessage:m,onRetryPending:h,onDiscardPending:f,splitIndex:x,liveTurn:p=null,onScrollControlsChange:g}=e,b=(0,c.c)("worktree"),v=(0,i.useRef)(null),y=(0,i.useMemo)(()=>void 0===x?n4:{highlightName:"chat-search-".concat(x),currentHighlightName:"chat-search-current-".concat(x),fallbackOverlayId:"chat-search-fallback-overlay-".concat(x),fallbackOverlayBgColor:n4.fallbackOverlayBgColor},[x]),j=(0,i.useRef)(!0),k=(0,i.useRef)(-1),N=(0,i.useRef)(l),C=(0,i.useRef)(0),[S,T]=(0,i.useState)(!0),{isOpen:I,query:E,matchCount:A,currentIndex:M,isAtMaxMatches:L,matchPositions:R,currentMatch:P,openSearch:D,closeSearch:F,setQuery:O,onCompositionStart:z,onCompositionEnd:_,nextMatch:H,prevMatch:V}=nP({messages:(0,i.useMemo)(()=>t.filter(e=>!e.archived&&!nZ(e)&&"string"==typeof e.content&&e.content.length>0),[t])}),U=I&&R.length>0,[K,W]=(0,i.useState)(n6),$=(0,i.useCallback)(()=>{let e=!K;W(e);try{window.localStorage.setItem(n3,String(e))}catch(e){}},[K]),q=(0,i.useMemo)(()=>({showAll:K}),[K]),G=(0,i.useMemo)(()=>I&&0!==R.length?new Set(R.map(e=>e.messageId)):null,[I,R]);(0,i.useEffect)(()=>{F()},[n]);let J=(0,i.useMemo)(()=>(function(e){let t,n=[],a=[],r=()=>{0!==a.length&&(n.push({kind:"approvals",key:"approvals:".concat(a[0].id),entries:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3;return function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,n=[];for(let a of e){let e=a.mergeKey?n.find(e=>e.mergeKey===a.mergeKey&&Math.abs(a.timestampMs-e.timestampMs)<=t):void 0;if(!e){n.push({...a,messageIds:[...a.messageIds]});continue}e.messageIds.push(...a.messageIds),e.isPermissionAudit=e.isPermissionAudit||a.isPermissionAudit,e.label||(e.label=a.label),nQ[a.outcome]>nQ[e.outcome]&&(e.outcome=a.outcome)}return n}(e.map(n0),t)}(a)}),a=[])};for(let l of function(e){let t=[],n=[],a=[],r=!1,s=()=>{t.push(...n,...a),n=[],a=[]};for(let l of e){if("user"===l.role&&!nZ(l)){s(),t.push(l);continue}if(!nZ(l)){a.push(l);continue}a.length>0&&(r=!0),n.push(l)}return s(),r?t:e}(e)){var s;if(nZ(l)){a.push(l);continue}r(),n.push({kind:"message",key:l.id,message:l,showHeader:!(s=t)||s.role!==l.role}),t=l}return r(),n})(t),[t]);C.current=J.length;let Y=(0,nL.Te)({count:J.length,getScrollElement:()=>v.current,estimateSize:()=>120,overscan:8,getItemKey:e=>{var t,n;return null!=(n=null==(t=J[e])?void 0:t.key)?n:e}}),Q=Y.getVirtualItems(),X=Q.length>0?"".concat(Q[0].index,"-").concat(Q[Q.length-1].index):"",Z=(0,i.useMemo)(()=>{let e=new Map;return J.forEach((t,n)=>{if("message"===t.kind)e.set(t.message.id,n);else for(let a of t.entries)for(let t of a.messageIds)e.set(t,n)}),e},[J]),ee=(0,i.useRef)(null),et=(0,i.useCallback)(()=>{let e=ee.current;ee.current=null,e&&null!==e.frame&&cancelAnimationFrame(e.frame)},[]),en=(0,i.useCallback)(()=>{et();let e=C.current-1;if(e<0||(Y.scrollToIndex(e,{align:"end"}),"function"!=typeof requestAnimationFrame))return;let t={frame:null,frames:0,stableFrames:0,totalSize:Y.getTotalSize(),deadline:Date.now()+600},n=()=>{if(t.frame=null,ee.current!==t)return;t.frames+=1;let e=C.current-1;if(e<0||!j.current||t.frames>12||Date.now()>t.deadline){ee.current=null;return}let a=Y.getTotalSize();if(a===t.totalSize){if(t.stableFrames+=1,t.stableFrames>=3){ee.current=null;return}}else t.stableFrames=0,t.totalSize=a,Y.scrollToIndex(e,{align:"end"});t.frame=requestAnimationFrame(n)};ee.current=t,t.frame=requestAnimationFrame(n)},[Y,et]);(0,i.useEffect)(()=>et,[et]);let ea=(0,i.useCallback)(()=>{j.current=!0,T(!0),en()},[en]),er=(0,i.useCallback)(()=>{et(),j.current=!1,T(!1),C.current>0&&Y.scrollToIndex(0,{align:"start"})},[Y,et]),es=(0,i.useCallback)(()=>{let e=v.current;if(!e)return;let t=nY({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight});(t||null===ee.current)&&(j.current=t,T(t))},[]);(0,i.useLayoutEffect)(()=>{let e=k.current,n=N.current,a=t.length;k.current=a,N.current=l,l||U||0===J.length||!j.current||(-1===e||n||!(a<=e))&&en()},[t.length,J.length,l,U,en]),(0,i.useEffect)(()=>{if(g)return g({scrollToLatest:ea,scrollToTop:er}),()=>g(null)},[g,ea,er]);let el=(0,i.useCallback)(e=>{if("Home"!==e.key&&"End"!==e.key)return;let t=e.target;t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||t.isContentEditable)||0!==C.current&&(e.preventDefault(),"End"===e.key?ea():er())},[ea,er]);(0,i.useEffect)(()=>{if(!I||!P)return;let e=Z.get(P.messageId);void 0!==e&&Y.scrollToIndex(e,{align:"center"})},[I,P,Z,Y]),(0,i.useLayoutEffect)(()=>{let e=v.current;if(!e)return;if(!I||0===R.length)return void e3(y);let t=null;for(let n of R){let a=e.querySelector('[data-message-id="'.concat(CSS.escape(n.messageId),'"]'));if(!a)continue;let r=(null==P?void 0:P.messageId)===n.messageId;e6(a,n.ranges,r?P.localIndex:-1,y),r&&a instanceof HTMLElement&&(t=a)}return t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"}),()=>{e3(y)}},[I,R,P,y,X]);let ei=(0,i.useRef)(b);ei.current=b;let eo=nJ(),ec=null!=a?a:eo.worktreePath,ed=(0,i.useCallback)(e=>{if(!d)return;let t=nV(e,ec);null!==t&&(async()=>{if("missing"===await nW(n,t)){null==u||u(ei.current("conversation.filePathMissing"),"error");return}d(t)})()},[d,n,ec,u]),eu=(0,i.useCallback)(async e=>{try{await (0,eq.l)(e),null==u||u(ei.current("history.copied"),"success")}catch(e){null==u||u(ei.current("history.copyFailed"),"error")}},[u]),em=(0,i.useCallback)(e=>{let t=J[e];if(!t)return null;if("approvals"===t.kind)return(0,r.jsx)(aF,{entries:t.entries});let n=(0,r.jsx)(aO,{message:t.message,showHeader:t.showHeader,onFilePathClick:ed,onCopy:eu,onInsertToMessage:m,onRetryPending:h,onDiscardPending:f});return(null==G?void 0:G.has(t.message.id))?(0,r.jsx)(ak,{value:aN,children:n}):n},[J,ed,eu,m,h,f,G]),eh=null!==p&&!0!==p.settling;return(0,r.jsxs)("div",{"data-testid":"chat-transcript","data-tool-activity":K?"shown":"folded",role:"log","aria-label":b("chatTranscript.regionLabel"),className:["relative flex h-full min-h-0 w-full flex-col overflow-hidden bg-surface",o].filter(Boolean).join(" "),children:[(0,r.jsx)("div",{ref:v,"data-testid":aH,onScroll:es,onKeyDown:el,tabIndex:0,className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-3 py-3",children:(0,r.jsxs)(ak,{value:q,children:[l?(0,r.jsx)(aK,{}):0===J.length?p?null:(0,r.jsx)(a$,{}):0===Q.length?(0,r.jsx)("div",{"data-testid":"chat-transcript-fallback-list",children:J.slice(0,40).map((e,t)=>(0,r.jsx)("div",{children:em(t)},e.key))}):(0,r.jsx)("div",{style:{height:Y.getTotalSize(),width:"100%",position:"relative"},children:Q.map(e=>(0,r.jsx)("div",{"data-index":e.index,ref:Y.measureElement,className:"absolute left-0 top-0 w-full",style:{transform:"translateY(".concat(e.start,"px)")},children:em(e.index)},e.key))}),p&&(p.settling?(0,r.jsx)(aW,{turnKey:p.turnKey,version:p.version,body:p.body,partial:p.partial,showHeader:n5(t[t.length-1]),onFilePathClick:ed}):(0,r.jsx)(a_,{turnKey:p.turnKey,version:p.version,body:p.body,partial:p.partial,isThinking:p.isThinking,showHeader:n5(t[t.length-1]),onFilePathClick:ed}))]})}),J.length>0&&(S?(0,r.jsx)("button",{type:"button","data-testid":aV,"data-direction":"top",onClick:er,"aria-label":b("chatTranscript.jumpToTop"),title:b("chatTranscript.jumpToTop"),className:aU,children:(0,r.jsx)(tI.A,{size:16,"aria-hidden":"true"})}):(0,r.jsx)("button",{type:"button","data-testid":aV,"data-direction":"latest","data-generating":eh?"true":void 0,onClick:ea,"aria-label":b(eh?"chatSurface.jumpToLatestGenerating":"chatSurface.jumpToLatest"),title:b(eh?"chatSurface.jumpToLatestGenerating":"chatSurface.jumpToLatest"),className:aU,children:eh?(0,r.jsx)(nN.A,{size:16,className:"animate-spin","aria-hidden":"true"}):(0,r.jsx)(tE.A,{size:16,"aria-hidden":"true"})})),(0,r.jsxs)("div",{className:"pointer-events-none absolute right-2 top-2 z-10 flex items-start justify-end gap-1",children:[!I&&(0,r.jsx)("div",{className:"pointer-events-auto",children:(0,r.jsx)("button",{type:"button","data-testid":"chat-transcript-tool-activity-toggle",onClick:$,"aria-pressed":K,"aria-label":b(K?"chatTranscript.toolActivity.hide":"chatTranscript.toolActivity.show"),title:b(K?"chatTranscript.toolActivity.hide":"chatTranscript.toolActivity.show"),className:["rounded-full border border-border p-1.5 shadow-sm backdrop-blur transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",K?"bg-accent-500/15 text-accent-700 hover:bg-accent-500/25 dark:text-accent-400":"bg-surface-2/80 text-muted-foreground hover:bg-muted hover:text-foreground"].join(" "),children:(0,r.jsx)(w.A,{size:14,"aria-hidden":"true"})})}),(0,r.jsx)("div",{className:"pointer-events-auto",children:I?(0,r.jsx)(aB,{query:E,onQueryChange:O,matchCount:A,currentIndex:M,onNext:H,onPrev:V,onClose:F,isAtMaxMatches:L,onCompositionStart:z,onCompositionEnd:_}):(0,r.jsx)("button",{type:"button","data-testid":"chat-transcript-search-toggle",onClick:D,"aria-label":b("chatTranscript.openSearch"),title:b("chatTranscript.openSearch"),className:"rounded-full border border-border bg-surface-2/80 p-1.5 text-muted-foreground shadow-sm backdrop-blur transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:(0,r.jsx)(B.A,{size:14,"aria-hidden":"true"})})})]})]})}),aG=/\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\[[0-9;]*m/g,aJ=/^(?:\x1b\[|\[)([0-9;]*)m$/,aY=new Set([38,48,58]);function aQ(e){let t;aG.lastIndex=0;let n=[],a="",r=null,s=0,l=0,i=0;for(;null!==(t=aG.exec(e));){let o=e.slice(i,t.index);a+=o,s+=na(o),i=t.index+t[0].length;let c=aJ.exec(t[0]);if(null===c)continue;let d=function(e,t){let n=(""===t?"0":t).split(";"),a=e;for(let e=0;e<n.length;e++){let t=Number(""===n[e]?"0":n[e]);if(Number.isFinite(t)){if(aY.has(t)){let r="2"===n[e+1]?4:2*("5"===n[e+1]);r>0&&48===t&&(a=n.slice(e,e+1+r).join(";")),e+=r;continue}0===t||49===t?a=null:(t>=40&&t<=47||t>=100&&t<=107)&&(a=n[e])}}return a}(r,c[1]);d!==r&&(s>l&&n.push({bg:r,start:l,end:s}),r=d,l=s)}let o=e.slice(i);a+=o,(s+=na(o))>l&&n.push({bg:r,start:l,end:s});let c=new Set(n.map(e=>e.start));return n.length>0&&c.add(n[n.length-1].end),{text:a,segments:n,edges:c,width:s}}function aX(e,t){for(let n of e.segments)if(n.start<=t&&t<n.end)return n.bg;return null}function aZ(e){let t=new Set;for(let n of e.segments)null!==n.bg&&t.add(n.bg);return t}function a0(e){let t=new Map;for(let a of e.segments){var n;null!==a.bg&&t.set(a.bg,(null!=(n=t.get(a.bg))?n:0)+(a.end-a.start))}let a=null,r=0;for(let[e,n]of t)n>r&&(a=e,r=n);return{bg:a,columns:r}}let a1=/\S[^\S\n]{2,}esc[^\S\n]*$/,a2=/^[│┃╹]/;function a5(e,t,n){if(!e.edges.has(t)||!e.edges.has(n))return!1;for(let a of e.segments)if(!(a.end<=t)&&!(a.start>=n)&&null===a.bg)return!1;return!(aX(e,t-1)===aX(e,t)||n<e.width&&aX(e,n)===aX(e,n-1)||a2.test(nn(e.text,t-1,t)))&&!a2.test(nn(e.text,t,n))}let a4=/^[^0-9A-Za-z]*([1-9])[.)]\s+\S/,a3=/\bs\s+to\s+use\s+this\s+session\s+only\b/i,a6=/\bEnter\s+to\s+set\s+as\s+default\b/i,a8=/\btype\s+to\s+search\b|\bsearch\s+\w+\s*(?:…|\.\.\.)|(?:^|·)\s*\/\s+search\b/im,a9=/\benter\s+to\s+select\b\s*[·•]\s*esc\s+to\s+cancel\b/i,a7=/^\s*(?:press|hit|type)?\s*(?:<)?esc(?:ape)?(?:>)?\s+to\s+(?:close|dismiss|exit)\b[\s.·•]*$/im,re=/^\u2500+$/,rt={optionCount:0,offersSessionScope:!1,commitsDefaultOnEnter:!1,hasFilterInput:!1},rn=[function(e){let t=function(e){let t=e.split("\n").map(aQ),n=new Set,a=null;for(let e of t){if(!e.text.includes("esc"))continue;let r=[...e.edges].sort((e,t)=>e-t);for(let s of r)if(!(s<1))for(let l of r){if(l-s<16)continue;let r="".concat(s,":").concat(l);if(n.has(r)||!a5(e,s,l))continue;let i=nn(e.text,s,l);if(!a1.test(i))continue;n.add(r);let o=t.filter(e=>a5(e,s,l));if(o.length<3)continue;let c=o.indexOf(e);c<0||c>=3||(null===a||o.length>a.rows)&&(a={id:"opencode_modal_overlay",headerText:t7(i.trim(),200,"…[truncated]"),left:s,right:l,rows:o.length,headerRow:c,frameRowStart:t.indexOf(o[0]),frameRowEnd:t.indexOf(o[o.length-1])})}}return a}(e);return null===t?null:e.split("\n").slice(t.frameRowStart,t.frameRowEnd+1).join("\n")},function(e){let t=e.replace(/\r\n/g,"\n").split("\n"),n=-1;for(let e=t.length-1;e>=0;e-=1)if(a9.test(tz(t[e]))){n=e;break}if(n<0)return null;for(let e=n-1;e>=0;e-=1){let a=tz(t[e]).trim();if(!(a.length<40)&&re.test(a))return t.slice(e+1,n+1).join("\n")}return null}];function ra(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return"";let n=e.replace(/\r\n/g,"\n");if(t.selectionList)for(let e of rn){let t=e(n);if(null===t)continue;let a=tG(t,{isStructuralRow:tq});if(""!==a)return a}let a=tG(n,{isStructuralRow:tq});if(""===a)return"";if(t.selectionList)return a;let r=a.split("\n"),s=function(e){if(void 0===e||!Number.isFinite(e))return 16;let t=Math.trunc(e);return t<12?12:t>20?20:t}(t.maxLines);return r.slice(-s).join("\n")}let rr=/^[^\S\n]*[❯›●][^\S\n]/;function rs(e){let{frame:t,maxLines:n=16,maxHeightClassName:a="max-h-64",actions:s,reason:l,className:o=""}=e,d=(0,c.c)("worktree"),u="selectionList"===l,m=(0,i.useMemo)(()=>ra(t,{maxLines:n,selectionList:u}),[t,n,u]),h=(0,i.useMemo)(()=>m?tV(m):"",[m]),f=(0,i.useRef)(null),x=(0,i.useMemo)(()=>u&&m?function(e){let t=e.split("\n"),n=-1;for(let e=t.length-1;e>=0;e-=1)if(rr.test(tz(t[e]))){n=e;break}return Math.max(n,function(e){let t=e.map(aQ),n=t.map(a0),a=t.map(aZ);for(let e=t.length-1;e>=0;e-=1){let{bg:r,columns:s}=n[e];if(!(null===r||s<8||e>0&&a[e-1].has(r))&&!(e+1<t.length&&a[e+1].has(r)))return e}return -1}(t))}(m):-1,[u,m]);return((0,i.useLayoutEffect)(()=>{if(x<0)return;let e=f.current;if(!e)return;let t=tz(m).split("\n").length;if(t<=1)return;let n=e.scrollHeight-e.clientHeight;if(n<=0)return;let a=window.getComputedStyle(e),r=Number.parseFloat(a.paddingTop)||0,s=Number.parseFloat(a.paddingBottom)||0,l=Math.max(0,e.scrollHeight-r-s)/t,i=r+x*l-(e.clientHeight-l)/2;e.scrollTop=Math.min(n,Math.max(0,i))},[x,m]),m)?(0,r.jsxs)("div",{"data-testid":"chat-dialog-card","data-reason":l,role:"group","aria-label":d("chatSurface.dialogCardLabel"),className:["flex min-w-0 flex-col gap-2",o].filter(Boolean).join(" "),children:[(0,r.jsx)("div",{ref:f,"data-testid":"chat-dialog-card-frame",className:"overflow-auto rounded-lg border border-border bg-terminal-surface p-2 font-mono text-[11px] leading-snug text-terminal-foreground ".concat(a),children:(0,r.jsx)("div",{className:"whitespace-pre w-max",dangerouslySetInnerHTML:{__html:h}})}),s?(0,r.jsx)("div",{"data-testid":"chat-dialog-card-actions",className:"min-w-0",children:s}):null]}):null}let rl=[{key:"1",label:"1",ariaLabel:"Send 1"},{key:"2",label:"2",ariaLabel:"Send 2"},{key:"3",label:"3",ariaLabel:"Send 3"},{key:"4",label:"4",ariaLabel:"Send 4"},{key:"5",label:"5",ariaLabel:"Send 5"},{key:"6",label:"6",ariaLabel:"Send 6"},{key:"7",label:"7",ariaLabel:"Send 7"},{key:"8",label:"8",ariaLabel:"Send 8"},{key:"9",label:"9",ariaLabel:"Send 9"}],ri=[{key:"y",label:"y",ariaLabel:"Send y"},{key:"n",label:"n",ariaLabel:"Send n"},{key:"Enter",label:"↵",ariaLabel:"Send Enter"}],ro="Escape";function rc(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,l=(0,c.c)("worktree"),{activeKey:o,markPressed:d}=eR(),u=eL(t,n,a,s),m=(0,i.useCallback)(e=>{d(e),u([e])},[d,u]);return(0,r.jsxs)("div",{"data-testid":"prompt-answer-keys",role:"toolbar","aria-label":l("promptAnswerKeys.toolbarLabel"),className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-muted px-2 py-1.5",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:l("promptAnswerKeys.caption")}),[...rl,...ri].map(e=>{let{key:t,label:n,ariaLabel:a}=e;return(0,r.jsx)("button",{type:"button","data-testid":"prompt-answer-key-".concat(t),"aria-label":a,onClick:()=>m(t),className:"min-h-[44px] min-w-[44px] rounded-md border border-border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat(o===t?"border-accent-500 bg-accent-500 text-white scale-95":"bg-surface hover:bg-muted active:bg-muted dark:bg-surface-2"),children:n},t)})]})}function rd(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s,optionCount:l}=e,o=(0,c.c)("worktree"),{activeKey:d,markPressed:u}=eR(),m=eL(t,n,a,s),h=(0,i.useMemo)(()=>{let e=Math.min(Math.trunc(l),9);return!Number.isFinite(e)||e<1?[]:rl.slice(0,e)},[l]),f=(0,i.useCallback)(e=>{u(e),m([e])},[u,m]);return 0===h.length?null:(0,r.jsxs)("div",{"data-testid":"selection-number-keys","data-option-count":String(h.length),role:"toolbar","aria-label":o("selectionKeys.numbersToolbarLabel"),className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-muted px-2 py-1.5",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:o("selectionKeys.numbersCaption")}),h.map(e=>{let{key:t,label:n,ariaLabel:a}=e;return(0,r.jsx)("button",{type:"button","data-testid":"selection-number-key-".concat(t),"aria-label":a,onClick:()=>f(t),className:"min-h-[44px] min-w-[44px] rounded-md border border-border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat(d===t?"border-accent-500 bg-accent-500 text-white scale-95":"bg-surface hover:bg-muted active:bg-muted dark:bg-surface-2"),children:n},t)})]})}function ru(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s,commitsDefaultOnEnter:l}=e,o=(0,c.c)("worktree"),{activeKey:d,markPressed:u}=eR(),m=eL(t,n,a,s),h=(0,i.useCallback)(e=>{u(e),m([e])},[u,m]);return(0,r.jsxs)("div",{"data-testid":"selection-commit-keys",role:"toolbar","aria-label":o("selectionKeys.commitToolbarLabel"),className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-muted px-2 py-1.5",children:[(0,r.jsx)("button",{type:"button","data-testid":"selection-commit-session","aria-label":o("selectionKeys.sessionOnlyAria"),title:o("selectionKeys.sessionOnlyAria"),onClick:()=>h("s"),className:"min-h-[44px] rounded-md border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat("s"===d?"border-accent-500 bg-accent-500 text-white scale-95":"border-accent-500 bg-surface text-accent-600 hover:bg-muted active:bg-muted dark:bg-surface-2 dark:text-accent-400"),children:o("selectionKeys.sessionOnly")}),(0,r.jsx)("button",{type:"button","data-testid":"selection-commit-default","aria-label":o("selectionKeys.setDefaultAria"),title:o("selectionKeys.setDefaultAria"),onClick:()=>h("Enter"),className:"min-h-[44px] rounded-md border border-border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat("Enter"===d?"border-accent-500 bg-accent-500 text-white scale-95":"bg-surface hover:bg-muted active:bg-muted dark:bg-surface-2"),children:o("selectionKeys.setDefault")}),l?(0,r.jsx)("p",{"data-testid":"selection-commit-warning",className:"w-full text-xs text-muted-foreground",children:o("selectionKeys.defaultWarning")}):null]})}function rm(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,l=(0,c.c)("worktree"),{activeKey:o,markPressed:d}=eR(),u=eL(t,n,a,s),m=(0,i.useCallback)(()=>{d(ro),u([ro])},[d,u]);return(0,r.jsx)("div",{"data-testid":"dismiss-panel-keys",role:"toolbar","aria-label":l("dismissPanelKeys.toolbarLabel"),className:"flex flex-wrap items-center gap-1.5 rounded-lg bg-muted px-2 py-1.5",children:(0,r.jsx)("button",{type:"button","data-testid":"dismiss-panel-key-Escape","aria-label":l("dismissPanelKeys.closeAria"),title:l("dismissPanelKeys.closeAria"),onClick:m,className:"min-h-[44px] rounded-md border px-3 py-2 text-sm font-medium transition-colors duration-75 touch-manipulation focus:outline-none focus:ring-2 focus:ring-ring ".concat(o===ro?"border-accent-500 bg-accent-500 text-white scale-95":"border-accent-500 bg-surface text-accent-600 hover:bg-muted active:bg-muted dark:bg-surface-2 dark:text-accent-400"),children:l("dismissPanelKeys.close")})})}[...rl.map(e=>e.key),...ri.map(e=>e.key)];var rh=n(63365),rf=n(52703);let rx='[data-testid="'.concat(aH,'"]'),rp={pager:"chatSurface.reasonPager",selectionList:"chatSurface.reasonSelectionList",dismissablePanel:"chatSurface.reasonDismissablePanel",unclassified:"chatSurface.reasonUnclassified",promptUnreadable:"chatSurface.reasonPromptUnreadable"},rg=(0,i.memo)(function(e){var t,n;let{messages:a,worktreeId:s,worktreePath:l,cliToolId:o,instanceId:d,live:u,onSurfaceModeChange:m,frame:h,onKeysSent:f,compact:x=!1,history:p,className:g=""}=e,b=(0,c.c)("worktree"),y=(0,i.useRef)(null),j=(0,i.useMemo)(()=>(function(e){let t=new Map;for(let n of e)t.set(n.id,n);return t.size===e.length?e:Array.from(t.values())})(a),[a]),w=(0,i.useRef)(!0),k=(0,i.useRef)(-1),[N,C]=(0,i.useState)(!1),[S,T]=(0,i.useState)(!0),E=(0,i.useCallback)(()=>{var e,t;return null!=(t=null==(e=y.current)?void 0:e.querySelector(rx))?t:null},[]),[A,M]=(0,i.useState)(!1),L=(0,i.useCallback)(e=>{M(null!==e)},[]),R=(0,i.useCallback)(()=>{let e=E();e&&(e.scrollTop=e.scrollHeight),w.current=!0,T(!0),C(!1)},[E]);(0,i.useEffect)(()=>{let e=E();if(!e)return;let t=()=>{let t=nY({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight});w.current=t,T(t),t&&C(!1)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[E,null==p?void 0:p.isLoading]),(0,i.useLayoutEffect)(()=>{let e=k.current,t=j.length;if(k.current=t,-1!==e&&!(t<=e)){if(w.current){let e=E();e&&(e.scrollTop=e.scrollHeight);return}C(!0)}},[j.length,E]);let P="running"===u.sessionStatus,D=function(e){let{worktreeId:t,cliToolId:n,instanceId:a,enabled:r=!0}=e,{addListener:s,connected:l}=(0,rh.xM)(),[o,c]=(0,i.useState)(null),d=(0,i.useRef)(0),u=null!=a?a:n;(0,i.useEffect)(()=>{d.current=0,c(null)},[t,n,u]),(0,i.useEffect)(()=>{r&&(d.current=0,c(null))},[r]),(0,i.useEffect)(()=>{!l&&r&&(d.current=0,c(null))},[l,r]),(0,i.useEffect)(()=>{if(r||null===o)return;let e=setTimeout(()=>c(null),6e5);return()=>clearTimeout(e)},[r,o]),(0,i.useEffect)(()=>{if(r&&void 0!==n)return s(e=>{e.type===rf.rz&&void 0!==n&&void 0!==u&&e.worktreeId===t&&e.cliToolId===n&&e.instanceId===u&&"string"==typeof e.turnKey&&0!==e.turnKey.length&&"string"==typeof e.body&&"number"==typeof e.version&&Number.isFinite(e.version)&&(e.version<=d.current||(d.current=e.version,c({turnKey:e.turnKey,body:e.body,partial:!0===e.partial,version:e.version,settling:!1})))})},[s,r,t,n,u]);let m=(0,i.useMemo)(()=>null===o?null:{...o,settling:!0},[o]);return r?l?o:null:m}({worktreeId:s,cliToolId:o,instanceId:d,enabled:P}),F=j.length?j[j.length-1].id:null,O=(null==D?void 0:D.settling)===!0,z=(0,i.useRef)(null),[_,B]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!O){z.current=null,B(!1);return}if(null===z.current){z.current={id:F};return}z.current.id!==F&&B(!0)},[O,F]);let H=null===D||function(e,t){for(let n=e.length-1;n>=0;n-=1)if(e[n].requestId===t)return!0;return!1}(j,D.turnKey)||D.settling&&_?null:D,V=(0,i.useMemo)(()=>null!==H?{turnKey:H.turnKey,version:H.version,body:H.body,partial:H.partial,isThinking:!H.settling&&!0===u.isThinking,settling:H.settling}:P?{isThinking:!0===u.isThinking}:null,[H,P,u.isThinking]),U=null!==V,K=U&&!0!==V.settling,W=(0,i.useRef)(!1);(0,i.useLayoutEffect)(()=>{if(!W.current){W.current=!0;return}if(!w.current)return;let e=E();e&&(e.scrollTop=e.scrollHeight)},[null==H?void 0:H.body,U,E]);let $=u.isPagerActive?"pager":u.isSelectionListActive?"selectionList":(null!=(n=u.isDismissablePanelActive)?n:function(e){if(!e)return!1;let t=tz(e.replace(/\r\n/g,"\n")).split("\n"),n=t.length-1;for(;n>=0&&""===t[n].trim();)n-=1;return!(n<0)&&t.slice(Math.max(0,n+1-15),n+1).some(e=>a7.test(e))}(h))?"dismissablePanel":u.isUnclassifiedActive?"unclassified":u.isPromptWaiting&&!I(u.promptData)?"promptUnreadable":null,q=(0,i.useCallback)(()=>{m("terminal")},[m]),G=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{null!==G.current&&clearTimeout(G.current)},[]);let J=(0,i.useCallback)(()=>{null==f||f(),null!==G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{G.current=null,null==f||f()},400)},[f]),Y=(0,i.useMemo)(()=>"selectionList"===$?function(e){if(!e)return rt;let t=function(e){let t=tz(e.replace(/\r\n/g,"\n")).split("\n"),n=t.length-1;for(;n>=0&&""===t[n].trim();)n-=1;return n<0?[]:t.slice(Math.max(0,n+1-40),n+1)}(e);if(0===t.length)return rt;let n=t.join("\n");return{optionCount:function(e){let t=0,n=0;for(let a of e){let e=a4.exec(a);if(null===e)continue;let r=Number(e[1]);r===n+1?(n=r,t=r):1===r?(n=1,t=1):n=0}return Math.min(t,9)}(t),offersSessionScope:a3.test(n),commitsDefaultOnEnter:a6.test(n),hasFilterInput:a8.test(n)}}(h):null,[$,h]),Q=(0,i.useMemo)(()=>"selectionList"===$&&h?ra(h,{selectionList:!0}).split("\n").length:0,[$,h]),X=(0,i.useMemo)(()=>{if(null===$||!o)return null;let e={worktreeId:s,cliToolId:o,instanceId:d,onKeysSent:J};switch($){case"pager":return(0,r.jsx)(eF,{...e,showPagerKeys:!0});case"selectionList":{var t;let n=(null==Y?void 0:Y.offersSessionScope)===!0&&nc.includes(o);return(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(eF,{...e}),Y&&(t=Y).optionCount>0&&!t.offersSessionScope&&!t.hasFilterInput?(0,r.jsx)(rd,{...e,optionCount:Y.optionCount}):null,n&&Y?(0,r.jsx)(ru,{...e,commitsDefaultOnEnter:Y.commitsDefaultOnEnter}):null,(0,r.jsx)(nw,{worktreeId:s,cliToolId:o,instanceId:d,onKeysSent:J})]})}case"dismissablePanel":return(0,r.jsx)(rm,{...e});case"unclassified":return(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(t6,{...e}),(0,r.jsx)(rc,{...e})]});case"promptUnreadable":return(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("p",{"data-testid":"chat-surface-unreadable-hint",className:"text-xs text-muted-foreground",children:b("chatSurface.unreadableHint")}),(0,r.jsx)(rc,{...e})]})}},[$,o,s,d,J,Y,b]),Z=null!=p?p:{},ee=nA(s),et=null!=(t=null!=d?d:o)?t:null,en=(0,i.useMemo)(()=>{if(!et)return null;var e=nM({owed:ee.owedBy(et),awaiting:ee.awaitedBy(et),aliasOf:e=>e.worktreeId===s?e.instanceId:"".concat(e.instanceId," @ ").concat(e.worktreeId)});if(0===e.length)return null;let[t]=e,n="prompt"===t.tone?"stripPrompt":"owed"===t.tone?"stripOwed":t.count>1?"stripAwaitingMany":"stripAwaiting";return{...t,key:n}},[ee,et,s]);return(0,r.jsxs)("div",{ref:y,"data-testid":"chat-surface","data-instance-id":null!=d?d:o,className:["flex h-full min-h-0 w-full flex-col overflow-hidden bg-surface text-surface-foreground",g].filter(Boolean).join(" "),children:[en&&(0,r.jsxs)("div",{"data-testid":"chat-surface-relay","data-relay-tone":en.tone,role:"status",className:"flex shrink-0 items-center gap-1.5 border-b border-border px-3 py-1 text-xs ".concat("prompt"===en.tone?"bg-warning-subtle text-warning-foreground":"bg-surface-2 text-muted-foreground"),children:[(0,r.jsx)(nk.A,{size:12,className:"shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate",children:b("relay.".concat(en.key),en.params)})]}),(0,r.jsxs)("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:[(0,r.jsx)(aq,{...Z,messages:j,worktreeId:s,worktreePath:l,cliToolId:o,liveTurn:V,onScrollControlsChange:L,className:"h-full"}),!A&&(N||U&&!S)&&(0,r.jsxs)("button",{type:"button","data-testid":"chat-surface-new-messages","data-generating":K?"true":void 0,onClick:R,"aria-label":K?b("chatSurface.jumpToLatestGenerating"):void 0,className:"absolute bottom-3 left-1/2 z-10 flex min-h-[36px] -translate-x-1/2 items-center gap-1.5 rounded-full border border-border bg-surface-2 px-3 py-1.5 text-xs font-medium text-foreground shadow-lg transition-colors hover:bg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:[K?(0,r.jsx)(nN.A,{size:14,className:"animate-spin","aria-hidden":"true"}):(0,r.jsx)(tE.A,{size:14,"aria-hidden":"true"}),b("chatSurface.jumpToLatest")]})]}),null!==$&&(0,r.jsxs)("div",{"data-testid":"chat-surface-live",role:"group","aria-label":b("chatSurface.liveRegionLabel"),className:"flex shrink-0 flex-col gap-2 border-t border-border bg-surface px-3 py-2",children:[(0,r.jsxs)("div",{"data-testid":"chat-surface-terminal-banner","data-reason":$,role:"status","aria-label":b("chatSurface.bannerLabel"),className:"flex flex-wrap items-center gap-2 rounded-lg border border-warning-border bg-warning-subtle px-2 py-1.5",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 text-xs text-foreground",children:b(rp[$])}),(0,r.jsxs)("button",{type:"button","data-testid":"chat-surface-open-terminal",onClick:q,className:"flex min-h-[32px] shrink-0 items-center gap-1 rounded-md border border-warning-border bg-surface px-2 py-1 text-xs font-medium text-warning-foreground transition-colors hover:bg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:[(0,r.jsx)(v.A,{size:14,"aria-hidden":"true"}),b("chatSurface.openTerminal")]})]}),h?(0,r.jsx)(rs,{frame:h,reason:$,maxLines:x?12:void 0,maxHeightClassName:Q>24?"max-h-[35vh]":x?"max-h-32":"max-h-64",actions:X}):null]})]})}),rb=/^[>❯]/,rv=/^\u203A/;function ry(e){return void 0===e||""===tz(e).trim()}function rj(e){let t=[],n={dim:!1,bold:!1},a=0;for(;a<e.length;){let r=e[a];if("\x1b"!==r){t.push({ch:r,dim:n.dim,bold:n.bold}),a++;continue}let s=e[a+1];if("["===s){let t=a+2;for(;t<e.length&&!/[A-Za-z]/.test(e[t]);)t++;if(t>=e.length)break;"m"===e[t]&&(n=function(e,t){let n=""===e?["0"]:e.split(";"),{dim:a,bold:r}=t;for(let e=0;e<n.length;e++){let t=""===n[e]?0:Number(n[e]);if(!Number.isNaN(t)){if(38===t||48===t||58===t){let t=""===n[e+1]||void 0===n[e+1]?-1:Number(n[e+1]);5===t?e+=2:2===t?e+=4:e+=1;continue}0===t||22===t?(a=!1,r=!1):1===t?r=!0:2===t&&(a=!0)}}return{dim:a,bold:r}}(e.slice(a+2,t),n)),a=t+1;continue}if("]"===s){let t=a+2;for(;t<e.length;){if("\x07"===e[t]){t++;break}if("\x1b"===e[t]&&"\\"===e[t+1]){t+=2;break}t++}a=t;continue}a+=2}return t}let rw=new Set(["claude","codex"]);function rk(e){let t=e.length;for(;t>0&&""===e[t-1].trim();)t--;return e.slice(0,t)}let rN={session:null,context:null,diff:null};function rC(e){var t,n,a,r,s,l,i,o,c,d,u,m;let h=e.session,f=e.context,x=e.diff;return JSON.stringify([null!=(t=null==h?void 0:h.title)?t:null,null!=(n=null==h?void 0:h.agent)?n:null,null!=(a=null==h?void 0:h.model)?a:null,null!=(r=null==h?void 0:h.cost)?r:null,null!=(s=null==h?void 0:h.tokens)?s:null,null!=(l=null==f?void 0:f.tokens)?l:null,null!=(i=null==f?void 0:f.limit)?i:null,null!=(o=null==f?void 0:f.percent)?o:null,null!=(c=null==x?void 0:x.turnMessageId)?c:null,null!=(d=null==x?void 0:x.revertedMessageId)?d:null,null!=(u=null==x?void 0:x.files.map(rS))?u:null,null!=(m=null==x?void 0:x.revertedFiles.map(rS))?m:null])}function rS(e){var t,n;return"".concat(null!=(t=e.file)?t:"",":").concat(null!=(n=e.status)?n:"",":").concat(e.additions,":").concat(e.deletions)}function rT(e){let{worktreeId:t,cliToolId:n,instanceId:a,enabled:r=!0}=e,s=null!=a?a:n,[l,o]=(0,i.useState)(()=>({output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,sessionStatus:"",isSelectionListActive:!1,isPagerActive:!1,isDismissablePanelActive:!1,isUnclassifiedActive:!1,composerText:"",attaching:!0,autoScroll:!0})),[c,d]=(0,i.useState)(()=>({visible:!1,data:null,messageId:null,answering:!1})),[u,m]=(0,i.useState)(rN),h=(0,i.useRef)(0),f=(0,i.useRef)(n);f.current=n;let x=(0,i.useRef)(s);x.current=s;let p=(0,i.useRef)(c.visible);p.current=c.visible;let{connected:g,subscribe:b,unsubscribe:v,addListener:y}=(0,rh.xM)(),j=(0,i.useRef)(0),w=(0,i.useRef)(0),k=(0,i.useRef)(null),N=(0,i.useRef)(null),[C,S]=(0,i.useState)(!1),T=(0,i.useCallback)(()=>{S(!0),null!==N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,S(!1)},5e3)},[]),I=(0,i.useCallback)(e=>{var t,n;let a=null!=(n=null!=(t=e.fullOutput)?t:e.realtimeSnippet)?n:"";!0===e.isUnclassifiedActive&&!0!==e.isPromptWaiting&&!0!==e.isSelectionListActive&&!0!==e.isPagerActive&&!0!==e.isDismissablePanelActive?(w.current+=1,null!=k.current||(k.current=Date.now())):(w.current=0,k.current=null);let r=w.current>=2&&null!==k.current&&Date.now()-k.current>=500,s=e.isRunning?function(e,t){if(!rw.has(t))return{text:"",state:"unsupported_tool"};let n=e.split("\n"),a=function(e,t){if("claude"===t){let t=function(e){var t;let n=e=>/^─{10,}$/.test(tz(e).trimEnd()),a=e.length-1;for(;a>=0&&""===e[a].trim();)a--;if(a<0)return null;let r=-1;for(let t=a;t>=Math.max(0,a-4);t--)if(n(e[t])){r=t;break}if(r<0)return null;let s=-1;for(let t=r-1;t>=Math.max(0,r-40);t--)if(n(e[t])){s=t;break}return s<0||!rb.test(tz(null!=(t=e[s+1])?t:""))?null:{openingSeparator:s,closingSeparator:r}}(e);return null===t?null:{firstRow:t.openingSeparator+1,lastRow:t.closingSeparator-1,glyph:rb}}let n=function(e){let t=e.length-1;for(;t>=0&&ry(e[t]);)t--;if(t<0)return null;for(let n=0;n<4&&t>=0;n++){let n=t,a=t;for(;a>0&&!ry(e[a-1]);)a--;if(function(e){if(void 0===e)return!1;let t=rj(e);if(0===t.length||"›"!==t[0].ch||t[0].dim||t.length>1&&" "!==t[1].ch)return!1;let n=t.slice(2).find(e=>" "!==e.ch);return void 0===n||!n.bold}(e[a]))return{firstRow:a,lastRow:Math.min(n,a+40-1)};for(t=a-1;t>=0&&ry(e[t]);)t--}return null}(e);return null===n?null:{firstRow:n.firstRow,lastRow:n.lastRow,glyph:rv}}(n,t);if(null===a)return{text:"",state:"no_composer"};let r=[],s=[];for(let e=a.firstRow;e<=a.lastRow;e++){var l;let t=function(e,t,n){if(t){let t=e.findIndex(e=>n.test(e.ch));if(t<0)return e;let a=t+1;return a<e.length&&/\s/.test(e[a].ch)&&a++,e.slice(a)}let a=0;for(;a<2&&a<e.length&&" "===e[a].ch;)a++;return e.slice(a)}(rj(null!=(l=n[e])?l:""),e===a.firstRow,a.glyph);r.push(t.filter(e=>!e.dim).map(e=>e.ch).join("").trimEnd()),s.push(t.map(e=>e.ch).join("").trimEnd())}let i=rk(r).join("\n");return""!==i.trim()?{text:i.slice(0,2e3),state:"content"}:{text:"",state:""===rk(s).join("\n").trim()?"empty":"ghost"}}(a,f.current).text:"";o(t=>{var n,l,i,o,c,d,u;let m=!1===e.isRunning,h=!!a||!!e.isRunning||m;return{...t,output:h?a:t.output,realtimeSnippet:null!=(n=e.realtimeSnippet)?n:"",isRunning:null!=(l=e.isRunning)&&l,isThinking:null!=(i=e.thinking)&&i,sessionStatus:null!=(o=e.sessionStatus)?o:t.sessionStatus,isSelectionListActive:null!=(c=e.isSelectionListActive)&&c,isPagerActive:null!=(d=e.isPagerActive)&&d,isDismissablePanelActive:null!=(u=e.isDismissablePanelActive)&&u,isUnclassifiedActive:r,composerText:s,attaching:!1}}),e.isPromptWaiting&&e.promptData?d(t=>{var n,a;return{...t,visible:!0,data:null!=(n=e.promptData)?n:t.data,messageId:null!=(a=t.messageId)?a:"prompt-".concat(Date.now())}}):!e.isPromptWaiting&&p.current&&d({visible:!1,data:null,messageId:null,answering:!1})},[]),E=(0,i.useCallback)(async()=>{let e=++h.current;try{var a,r,l,i,o,c;let d=await fetch("/api/worktrees/".concat(t,"/current-output?cliTool=").concat(n,"&instance=").concat(encodeURIComponent(s)));if(!d.ok)return;let u=await d.json();if(h.current!==e||f.current!==n||x.current!==s||u.cliToolId&&u.cliToolId!==n)return;I(u);let p={session:null!=(i=null==(a=u.structuredEvents)?void 0:a.session)?i:null,context:null!=(o=null==(r=u.structuredEvents)?void 0:r.sessionContext)?o:null,diff:null!=(c=null==(l=u.structuredEvents)?void 0:l.sessionDiff)?c:null};m(e=>rC(e)===rC(p)?e:p)}catch(t){if(h.current!==e||f.current!==n||x.current!==s)return;console.error("[useTerminalPanePolling] fetch error:",t)}},[t,n,s,I]),A="".concat(t,"::").concat(n,"::").concat(s),M=(0,i.useRef)(A);(0,i.useEffect)(()=>{M.current!==A&&(M.current=A,h.current+=1,j.current=0,w.current=0,k.current=null,S(!1),null!==N.current&&(clearTimeout(N.current),N.current=null),o(e=>({...e,output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,sessionStatus:"",isSelectionListActive:!1,isPagerActive:!1,isDismissablePanelActive:!1,isUnclassifiedActive:!1,composerText:"",attaching:!0})),d({visible:!1,data:null,messageId:null,answering:!1}),m(rN))},[A]),(0,i.useEffect)(()=>{if(r)return b(t),()=>v(t)},[r,t,b,v]),(0,i.useEffect)(()=>{j.current=0,S(!1),null!==N.current&&(clearTimeout(N.current),N.current=null)},[g]),(0,i.useEffect)(()=>()=>{null!==N.current&&clearTimeout(N.current)},[]),(0,i.useEffect)(()=>{if(r)return y(e=>{var n;if("terminal_snapshot"!==e.type||e.worktreeId!==t||e.cliToolId!==f.current||e.instanceId!==x.current||e.version<=j.current)return;j.current=e.version,T();let a=e.output.split("\n").slice(-100).join("\n");I({fullOutput:e.output,realtimeSnippet:a,isRunning:e.isRunning,sessionStatus:e.sessionStatus,thinking:e.thinking,isSelectionListActive:e.isSelectionListActive,isPagerActive:e.isPagerActive,isDismissablePanelActive:e.isDismissablePanelActive,isUnclassifiedActive:e.isUnclassifiedActive,isPromptWaiting:e.isPromptWaiting,promptData:null!=(n=e.promptData)?n:null})})},[r,t,y,I,T]),(0,i.useEffect)(()=>{if(r)return y(e=>{if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===x.current)&&(null==e.cliTool||e.cliTool===f.current)&&(j.current=0,I({fullOutput:"",realtimeSnippet:"",isRunning:!1,sessionStatus:"idle",thinking:!1,isSelectionListActive:!1,isPagerActive:!1,isDismissablePanelActive:!1,isUnclassifiedActive:!1,isPromptWaiting:!1,promptData:null}))})},[r,t,y,I]),(0,i.useEffect)(()=>{if(!r)return;let e=!1,t=c.visible||l.isSelectionListActive||l.isPagerActive||l.isDismissablePanelActive||l.isUnclassifiedActive,n=setInterval(()=>{"hidden"!==document.visibilityState&&E()},g&&C&&!t?15e3:l.isRunning||t?2e3:5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&E();let a=()=>{"visible"!==document.visibilityState||e||E()};return document.addEventListener("visibilitychange",a),()=>{e=!0,null!==n&&(clearInterval(n),n=null),document.removeEventListener("visibilitychange",a)}},[r,g,C,l.isRunning,l.isSelectionListActive,l.isPagerActive,l.isDismissablePanelActive,l.isUnclassifiedActive,c.visible,E]);let L=(0,i.useCallback)(e=>{o(t=>t.autoScroll===e?t:{...t,autoScroll:e})},[]),R=(0,i.useCallback)(e=>{d(t=>({...t,answering:e}))},[]);return{terminal:l,prompt:c,agentSession:u,setAutoScroll:L,setPromptAnswering:R,clearPrompt:(0,i.useCallback)(()=>{d({visible:!1,data:null,messageId:null,answering:!1})},[]),refresh:(0,i.useCallback)(()=>E(),[E])}}let rI="claude";function rE(e,t,n){let a=e.findIndex(e=>e.id===t.id),r=[...e];a>=0?r[a]=t:r.push(t);var s=[...r].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());if(void 0===n||n<1)return s;let l=s.filter(e=>"user"===e.role).map(e=>e.timestamp.getTime()).sort((e,t)=>t-e);if(l.length<=n)return s;let i=l[n-1];return s.filter(e=>e.timestamp.getTime()>=i)}function rA(e){let{worktreeId:t,cliToolId:n,instanceId:a,limit:r,includeArchived:s=!1,enabled:l=!0}=e,[o,c]=(0,i.useState)([]),[d,u]=(0,i.useState)(!0),{connected:m,subscribe:h,unsubscribe:f,addListener:x}=(0,rh.xM)(),p=null!=a?a:n,g=(0,i.useRef)(0),b=(0,i.useRef)(n);b.current=n;let v=(0,i.useRef)(p);v.current=p;let y=(0,i.useRef)(r);y.current=r;let j=(0,i.useRef)(s);j.current=s;let w=(0,i.useRef)(new Map),k=(0,i.useCallback)(async()=>{let e=++g.current,a=new Map;w.current=a;try{let l=new URLSearchParams({cliTool:n,instance:p,unit:"pairs"});void 0!==r&&l.set("limit",String(r)),s&&l.set("includeArchived","true");let i=await fetch("/api/worktrees/".concat(t,"/messages?").concat(l.toString()));if(!i.ok)return;let o=await i.json();if(g.current!==e||b.current!==n||v.current!==p)return;let d=o.map(e=>({...e,timestamp:new Date(e.timestamp)}));for(let e of a.values())d=rE(d,e,r);w.current===a&&(w.current=new Map),c(d),u(!1)}catch(t){if(g.current!==e||b.current!==n||v.current!==p)return;console.error("[useSplitMessages] fetch error:",t),u(!1)}},[t,n,p,r,s]),N="".concat(t,"::").concat(n,"::").concat(p),C=(0,i.useRef)(N);return(0,i.useEffect)(()=>{C.current!==N&&(C.current=N,g.current+=1,w.current=new Map,c([]),u(!0))},[N]),(0,i.useEffect)(()=>{if(!l)return;let e=!1,t=setInterval(()=>{"hidden"!==document.visibilityState&&k()},m?15e3:5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&k();let n=()=>{"visible"!==document.visibilityState||e||k()};return document.addEventListener("visibilitychange",n),()=>{e=!0,clearInterval(t),document.removeEventListener("visibilitychange",n)}},[l,m,k]),(0,i.useEffect)(()=>{if(l)return h(t),()=>f(t)},[l,t,h,f]),(0,i.useEffect)(()=>{if(l)return x(e=>{var n,a,r,s;if("message"===e.type||"message_updated"===e.type){if(e.worktreeId!==t)return;let r=e.message;if(!r||"string"!=typeof r.id)return;let s=null!=(n=r.cliToolId)?n:rI,l=null!=(a=r.instanceId)?a:s;if(s!==b.current||l!==v.current||!r.content||""===r.content.trim()||r.archived&&!j.current)return;let i={...r,timestamp:new Date(r.timestamp),cliToolId:s,instanceId:l};w.current.set(i.id,i),c(e=>rE(e,i,y.current));return}if(e.type===rf.dz){if(e.worktreeId!==t)return;let n=null!=(r=e.cliToolId)?r:rI,a=null!=(s=e.instanceId)?s:n;if(n!==b.current||a!==v.current)return;k();return}if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===v.current)&&(null==e.cliTool||e.cliTool===b.current)&&k()})},[l,t,x,k]),{messages:o,isLoading:d,refresh:(0,i.useCallback)(()=>k(),[k])}}function rM(e){let t=new Set;for(let n of e)"user"===n.role&&t.add(n.id);return t}function rL(e,t,n){let a=new Set,r=new Set,s=e.filter(e=>"sending"===e.status);if(0===s.length)return{reconciledTempIds:a,consumedServerIds:r};let l=t.filter(e=>"user"===e.role&&!n.has(e.id)).sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),i=new Set;for(let e of[...s].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())){let t=l.find(t=>!i.has(t.id)&&!e.baselineUserIds.has(t.id)&&t.content===e.content);t&&(i.add(t.id),a.add(e.tempId),r.add(t.id))}return{reconciledTempIds:a,consumedServerIds:r}}function rR(e){let{worktreeId:t,serverMessages:n,sendFn:a,onSent:r,timeoutMs:s=3e4}=e,[l,o]=(0,i.useState)([]),c=(0,i.useRef)(n);c.current=n;let d=(0,i.useRef)(l);d.current=l;let u=(0,i.useRef)(r);u.current=r;let m=(0,i.useRef)(a);m.current=a;let h=(0,i.useRef)(0),f=(0,i.useRef)(new Map),x=(0,i.useRef)(new Set),p=(0,i.useCallback)(e=>{let t=f.current.get(e);void 0!==t&&(clearTimeout(t),f.current.delete(e))},[]),g=(0,i.useCallback)(e=>{p(e);let t=setTimeout(()=>{f.current.delete(e),o(t=>t.map(t=>t.tempId===e&&"sending"===t.status?{...t,status:"error"}:t))},s);f.current.set(e,t)},[p,s]),b=(0,i.useCallback)(async e=>{g(e.tempId);try{var t;await m.current(e.content,e.options),null==(t=u.current)||t.call(u)}catch(t){p(e.tempId),o(t=>t.map(t=>t.tempId===e.tempId?{...t,status:"error"}:t))}},[g,p]),v=(0,i.useCallback)((e,t)=>{let n={tempId:"pending-".concat(h.current++),content:e,options:t,timestamp:new Date,status:"sending",baselineUserIds:rM(c.current)};o(e=>[...e,n]),b(n)},[b]),y=(0,i.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);if(!t)return;let n={...t,status:"sending",timestamp:new Date,baselineUserIds:rM(c.current)};o(t=>t.map(t=>t.tempId===e?n:t)),b(n)},[b]),j=(0,i.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);return p(e),o(t=>t.filter(t=>t.tempId!==e)),null==t?void 0:t.content},[p]);return(0,i.useEffect)(()=>{let{reconciledTempIds:e,consumedServerIds:t}=rL(d.current,n,x.current),a=new Set(n.map(e=>e.id)),r=new Set;x.current.forEach(e=>{a.has(e)&&r.add(e)}),t.forEach(e=>r.add(e)),x.current=r,0!==e.size&&(e.forEach(p),o(t=>t.filter(t=>!e.has(t.tempId))))},[n,p]),(0,i.useEffect)(()=>{let e=f.current;return()=>{e.forEach(e=>clearTimeout(e)),e.clear()}},[]),{messages:(0,i.useMemo)(()=>{if(0===l.length)return n;let{reconciledTempIds:e}=rL(l,n,x.current),a=l.filter(t=>!e.has(t.tempId)).map(e=>({id:e.tempId,worktreeId:t,role:"user",content:e.content,timestamp:e.timestamp,messageType:"normal",archived:!1,cliToolId:e.options.cliToolId,instanceId:e.options.instanceId,optimisticState:e.status}));return 0===a.length?n:[...n,...a]},[n,l,t]),pending:l,sendOptimistic:v,retry:y,discard:j}}let rP=(0,i.createContext)({register:()=>{},insertToComposer:()=>{}}),rD=(0,i.createContext)(null);function rF(e){var t;return null!=(t=e.instanceId)?t:e.cliToolId}function rO(e){let{onInsertToComposer:t,children:n}=e,[a,s]=(0,i.useState)(null),l=(0,i.useRef)(t);l.current=t;let o=(0,i.useCallback)(e=>{var t;null==(t=l.current)||t.call(l,e)},[]),c=(0,i.useMemo)(()=>({register:s,insertToComposer:o}),[o]);return(0,r.jsx)(rP.Provider,{value:c,children:(0,r.jsx)(rD.Provider,{value:a,children:n})})}function rz(e){let t=(0,i.useContext)(rD);if(null!==t&&t.target.cliToolId===e.cliToolId&&rF(t.target)===rF(e))return t.send}var r_=n(17683);let rB=[{mode:"terminal",labelKey:"surfaceMode.terminal",icon:v.A},{mode:"chat",labelKey:"surfaceMode.chat",icon:U.A}],rH=["C-x","m"],rV="/model",rU=(0,i.memo)(function(e){let{modelLabel:t,usage:n,usageDetail:a,recentChange:s,note:l,onEditNote:i,onOpenPicker:o,onDismissChange:d}=e,u=(0,c.c)("worktree"),m=null!==s,h=u("agentModel.sessionRow",{model:null!=t?t:""}),f=l?(0,X.Uq)(new Date(l.updatedAt)):"",x=l?u("sessionNote.label",{note:l.text,time:f}):u("sessionNote.menuItem");return(0,r.jsxs)("div",{"data-testid":"mobile-session-row","data-model-changed":m?"true":"false",className:"relative z-20 flex h-7 shrink-0 items-center gap-2 border-b px-3 text-[11px] leading-none ".concat(m?"border-warning-border bg-warning-subtle text-warning-foreground":"border-border bg-surface-2 text-muted-foreground"),children:[t?(0,r.jsxs)("button",{type:"button",onClick:o,"aria-label":h,title:h,"data-testid":"mobile-session-model",className:"relative flex min-w-0 basis-0 grow items-center gap-1.5 truncate text-left touch-manipulation before:absolute before:inset-x-0 before:-inset-y-2 before:content-[''] ".concat(l?"shrink-[4]":"shrink"),children:[(0,r.jsx)(tT.A,{size:12,"aria-hidden":"true",className:"shrink-0"}),(0,r.jsx)("span",{className:"min-w-0 truncate",children:t})]}):null,l?(0,r.jsxs)("button",{type:"button",onClick:i,"aria-label":x,title:x,"data-testid":"mobile-session-note",className:"relative flex min-w-0 shrink basis-0 grow items-center gap-1 text-left touch-manipulation before:absolute before:inset-x-0 before:-inset-y-2 before:content-['']",children:[(0,r.jsx)(H.A,{size:12,"aria-hidden":"true",className:"shrink-0 opacity-70"}),(0,r.jsx)("span",{className:"min-w-0 truncate",children:l.text}),(0,r.jsx)("span",{"data-testid":"mobile-session-note-time",className:"shrink-0 tabular-nums opacity-70",children:f})]}):null,n?(0,r.jsx)("span",{"data-testid":"mobile-session-usage",title:null!=a?a:u("agentSession.chipLabel",{usage:n}),className:"min-w-0 max-w-[10rem] shrink-0 truncate tabular-nums",children:n}):null,s?(0,r.jsx)("button",{type:"button",onClick:d,"aria-label":u("agentModel.changedRecentlyDetail",{from:s.from,to:s.to}),title:u("agentModel.changedRecentlyDetail",{from:s.from,to:s.to}),"data-testid":"mobile-session-model-changed",className:"relative shrink-0 rounded-full border border-warning-border bg-warning/20 px-1.5 py-0.5 font-medium touch-manipulation before:absolute before:inset-x-0 before:-inset-y-2 before:content-['']",children:u("agentModel.changedRecently")}):null]})}),rK=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,live:s,frame:l,onKeysSent:o,onSurfaceModeChange:c}=e,{messages:d,isLoading:u,refresh:m}=rA({worktreeId:t,cliToolId:n,instanceId:a}),h=(0,i.useCallback)((e,n)=>el.y.sendMessage(t,e,n),[t]),{messages:f,sendOptimistic:x,retry:p,discard:g}=rR({worktreeId:t,serverMessages:d,sendFn:h,onSent:m});!function(e){let{cliToolId:t,instanceId:n,send:a}=e,{register:r}=(0,i.useContext)(rP);(0,i.useEffect)(()=>(r({target:{cliToolId:t,instanceId:n},send:a}),()=>r(null)),[r,t,n,a])}({cliToolId:n,instanceId:a,send:x});let{worktreePath:b,openFile:v}=nJ(),y=(0,i.useContext)(rP).insertToComposer,j=(0,i.useCallback)(e=>{let t=g(e);t&&y(t)},[g,y]);return(0,r.jsx)(rg,{messages:f,worktreeId:t,worktreePath:b,cliToolId:n,instanceId:a,live:s,onSurfaceModeChange:c,frame:l,onKeysSent:o,compact:!0,history:{onFilePathClick:v,isLoading:u,onRetryPending:p,onDiscardPending:j,onInsertToMessage:y}})}),rW=(0,i.memo)(function(e){var t,n;let{worktreeId:a,cliToolId:s,instanceId:l,disableAutoFollow:o,onSurfaceModeChange:d}=e,{terminal:u,prompt:m,agentSession:h,setAutoScroll:f,refresh:x}=rT({worktreeId:a,cliToolId:s,instanceId:l}),{compactTuiLayoutPadding:p,preservePaintedPanelRows:g,mobileWrapMode:b}=t0(s),v=(0,c.c)("worktree"),y=(0,to.Ym)(),j=null!=l?l:s,w=function(e,t){let n=(0,Q.rC)(),a=null==n?void 0:n.worktrees;return(0,i.useMemo)(()=>{var n;let r=null==a?void 0:a.find(t=>t.id===e);return null!=(n=cd(null==r?void 0:r.sessionStatusByInstance)[t])?n:null},[a,e,t])}(a,j),k=(0,Q.rC)(),N=cs(w,null,null==(t=h.session)?void 0:t.agent),C=co(h.session,h.context,v,y),S=cc(h.session,h.context,v,y),{note:T,save:I}=en(a,j),[E,A]=(0,i.useState)(!1);(0,i.useEffect)(()=>{let e=()=>A(!0);return window.addEventListener(et,e),()=>window.removeEventListener(et,e)},[]),(0,i.useEffect)(()=>{A(!1)},[a,j]);let M=(0,i.useCallback)(()=>A(!0),[]),L=(0,i.useCallback)(()=>A(!1),[]),R=(0,i.useCallback)(e=>{I(e),A(!1)},[I]),P=null!==N||null!==T,[D,F]=(0,i.useState)(null);(0,rh.T3)(e=>{e.type===rf.T4&&e.worktreeId===a&&e.instance===j&&(F({from:e.from,to:e.to,at:e.at}),null==k||k.refresh())}),(0,i.useEffect)(()=>{if(null===D)return;let e=D.at+3e5-Date.now();if(e<=0)return void F(null);let t=setTimeout(()=>F(null),e);return()=>clearTimeout(t)},[D]);let O=(0,i.useCallback)(()=>F(null),[]);(0,i.useEffect)(()=>{F(null)},[a,j]);let z=eL(a,s,l,x),_=rz({cliToolId:s,instanceId:l}),B=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{null!==B.current&&clearTimeout(B.current)},[]);let H=(0,i.useCallback)(()=>{if("opencode"===s)return void z([...rH]);let e={cliToolId:s,instanceId:l};_?_(rV,e):el.y.sendMessage(a,rV,e).catch(()=>{}),null!==B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{B.current=null,x()},eM.LK)},[s,l,_,x,z,a]),V=(0,r_.NP)(a),[U,K]=(0,i.useState)(G.wf);(0,i.useEffect)(()=>{K((0,r_.TR)(V))},[V]);let W=(0,i.useCallback)(e=>{K(e),(0,r_.If)(V,e)},[V]);(0,i.useEffect)(()=>{null==d||d(U)},[d,U]);let $=u.isUnclassifiedActive&&!m.visible&&"chat"!==U,q=t8(u.composerText),J=nl(s,u.realtimeSnippet||u.output),Y=(0,i.useMemo)(()=>({isRunning:u.isRunning,sessionStatus:u.sessionStatus,isThinking:u.isThinking,isPromptWaiting:m.visible,promptData:m.data,isSelectionListActive:u.isSelectionListActive,isPagerActive:u.isPagerActive,isDismissablePanelActive:u.isDismissablePanelActive,isUnclassifiedActive:u.isUnclassifiedActive}),[u.isRunning,u.sessionStatus,u.isThinking,u.isSelectionListActive,u.isPagerActive,u.isDismissablePanelActive,u.isUnclassifiedActive,m.visible,m.data]);return(0,r.jsxs)("div",{className:"relative flex flex-col h-full min-h-0",children:[(0,r.jsx)("div",{role:"group","aria-label":v("surfaceMode.groupLabelMobile"),"data-testid":"mobile-surface-mode-toggle",className:"pointer-events-none absolute right-2 z-30 flex items-center gap-0.5 rounded-full border border-border bg-surface-2/95 p-0.5 shadow-lg backdrop-blur ".concat(P?"top-9":"top-2"),children:rB.map(e=>{let{mode:t,labelKey:n,icon:a}=e,s=U===t,l=v(n);return(0,r.jsx)("button",{type:"button",onClick:()=>W(t),"aria-pressed":s,"aria-label":l,title:l,"data-testid":"mobile-surface-mode-".concat(t),className:"pointer-events-auto flex min-h-[44px] min-w-[44px] items-center justify-center rounded-full transition-colors touch-manipulation ".concat(s?"bg-accent-500/20 text-accent-600 dark:text-accent-400":"text-muted-foreground"),children:(0,r.jsx)(a,{size:18,"aria-hidden":"true"})},t)})}),P?(0,r.jsx)(rU,{modelLabel:N,usage:C,usageDetail:S,recentChange:D,note:T,onEditNote:M,onOpenPicker:H,onDismissChange:O}):null,E?(0,r.jsxs)("div",{"data-testid":"mobile-session-note-editor",className:"absolute inset-x-2 z-40 rounded-md border border-border bg-surface p-2 shadow-lg ".concat(P?"top-9":"top-2"),children:[(0,r.jsx)(ea,{initialText:null!=(n=null==T?void 0:T.text)?n:"",onCommit:R,onCancel:L,ariaLabel:v("sessionNote.menuItem"),placeholder:v("sessionNote.placeholder"),testId:"mobile-session-note-input"}),(0,r.jsx)("p",{className:"mt-1 text-[10px] leading-tight text-muted-foreground",children:v("sessionNote.hint")})]}):null,(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden","data-testid":"mobile-terminal-region",children:"chat"===U?(0,r.jsx)("div",{className:"h-full min-h-0","data-testid":"mobile-chat-surface",children:(0,r.jsx)(rK,{worktreeId:a,cliToolId:s,instanceId:l,live:Y,frame:u.output,onKeysSent:x,onSurfaceModeChange:W})}):(0,r.jsx)(t2,{output:u.output,isActive:u.isRunning,isThinking:u.isThinking,autoScroll:u.autoScroll,onScrollChange:f,disableAutoFollow:o,compactTuiLayoutPadding:p,preservePaintedPanelRows:g,wrapMode:b})}),q?(0,r.jsx)("div",{className:"shrink-0 px-2 pt-1",children:(0,r.jsx)(t9,{worktreeId:a,cliToolId:s,instanceId:l,composerText:u.composerText,onActionSent:x})}):null,J?(0,r.jsx)("div",{className:"shrink-0 px-2 pt-1",children:(0,r.jsx)(ni,{cliToolId:s,frame:u.realtimeSnippet||u.output})}):null,u.isRunning?(0,r.jsx)("div",{className:"shrink-0 px-2 pt-1","data-testid":"mobile-quick-keys-slot",children:(0,r.jsx)(ny,{worktreeId:a,cliToolId:s,instanceId:l,hasAgentSession:null!==h.session,onKeysSent:x,compact:!0,collapsible:!0,layout:"mobile"})}):null,$?(0,r.jsx)("div",{className:"shrink-0 px-2 pt-1 pb-2",children:(0,r.jsx)(t6,{worktreeId:a,cliToolId:s,instanceId:l,onKeysSent:x})}):null]})});var r$=n(12181),rq=n(20508),rG=n(90368);let rJ="commandmate.worktree.historyVisible",rY="commandmate.worktree.historyWidth";function rQ(e){return Number.isFinite(e)?Math.min(60,Math.max(10,e)):40}let rX="commandmate:historyPaneStateChange";function rZ(e){try{window.dispatchEvent(new CustomEvent(rX,{detail:e}))}catch(e){}}function r0(){let[e,t]=(0,i.useState)(!0),[n,a]=(0,i.useState)(40),r=(0,i.useRef)(e);r.current=e;let s=(0,i.useRef)(n);return s.current=n,(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(rJ);if("true"===e)return!0;if("false"===e)return!1}catch(e){}return!0}(),n=function(){try{let e=window.localStorage.getItem(rY);if(null===e)return 40;let t=Number(e);if(Number.isFinite(t))return rQ(t)}catch(e){}return 40}();t(e),a(n)},[]),(0,i.useEffect)(()=>{let e=e=>{e.detail&&(e.detail.visible!==r.current&&t(e.detail.visible),e.detail.width!==s.current&&a(e.detail.width))};return window.addEventListener(rX,e),()=>window.removeEventListener(rX,e)},[]),{visible:e,width:n,toggle:(0,i.useCallback)(()=>{let e=!r.current;t(e);try{window.localStorage.setItem(rJ,String(e))}catch(e){}rZ({visible:e,width:s.current})},[]),setWidth:(0,i.useCallback)(e=>{let t=rQ(e);a(t);try{window.localStorage.setItem(rY,String(t))}catch(e){}rZ({visible:r.current,width:t})},[])}}function r1(e){return"split-history-slot-".concat(e)}function r2(e){let t=e.split("\n");if(t.length<=2&&e.length<=100)return{text:e,isTruncated:!1};let n=t.slice(0,2).join("\n");return n.length>100&&(n=n.slice(0,100)),{text:n,isTruncated:!0}}let r5=(0,i.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,c.c)("worktree"),s=(0,i.useMemo)(()=>n2(t),[t]),l=(0,i.useCallback)(e=>()=>n(e),[n]);return(0,r.jsx)("span",{children:s.map((e,t)=>"path"===e.type?(0,r.jsx)("button",{type:"button",onClick:l(e.content),className:"text-accent-700 dark:text-accent-400 hover:text-accent-600 dark:hover:text-accent-300 hover:underline cursor-pointer font-mono text-sm","aria-label":a("conversation.openFile",{path:e.content}),children:e.content},t):(0,r.jsx)("span",{children:e.content},t))})}),r4=(0,i.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,i.useMemo)(()=>{let e=e=>i.Children.map(e,e=>"string"==typeof e?(0,r.jsx)(r5,{content:e,onFilePathClick:n}):e);return{p:t=>{let{children:n}=t;return(0,r.jsx)("p",{children:e(n)})},li:t=>{let{children:n}=t;return(0,r.jsx)("li",{children:e(n)})},td:t=>{let{children:n}=t;return(0,r.jsx)("td",{children:e(n)})},th:t=>{let{children:n}=t;return(0,r.jsx)("th",{children:e(n)})},strong:t=>{let{children:n}=t;return(0,r.jsx)("strong",{children:e(n)})},em:t=>{let{children:n}=t;return(0,r.jsx)("em",{children:e(n)})},a:e=>{let{href:t,children:a,node:s,...l}=e;return(0,r.jsx)(aL,{...l,href:t,onFilePathClick:n,children:a})}}},[n]),s=(0,i.useMemo)(()=>[ar.A],[]),l=(0,i.useMemo)(()=>[as.A,al.A],[]);return(0,r.jsx)(aa.oz,{remarkPlugins:s,rehypePlugins:l,components:a,children:t})});function r3(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{"data-testid":"pending-indicator",className:"flex items-center gap-2 text-muted-foreground py-2",children:[(0,r.jsxs)("div",{className:"flex gap-1","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"w-2 h-2 bg-muted-foreground rounded-full animate-pulse"}),(0,r.jsx)("span",{className:"w-2 h-2 bg-muted-foreground rounded-full animate-pulse",style:{animationDelay:"150ms"}}),(0,r.jsx)("span",{className:"w-2 h-2 bg-muted-foreground rounded-full animate-pulse",style:{animationDelay:"300ms"}})]}),(0,r.jsx)("span",{className:"text-sm",children:e("conversation.waitingForResponse")})]})}let r6=(0,i.memo)(function(e){let{message:t,onFilePathClick:n,onCopy:a,onInsertToMessage:s,onRetryPending:l,onDiscardPending:i}=e,o=(0,to.Ym)(),d=(0,c.c)("worktree"),u=(0,c.c)("common"),m=am(o),h=(0,X.bg)(t.timestamp,m),f=t.optimisticState,x=["group relative border-l-2 p-3 transition-opacity","error"===f?"border-danger-border bg-danger-subtle":"border-accent-500 bg-accent-500/10","sending"===f?"opacity-70":""].filter(Boolean).join(" ");return(0,r.jsxs)("div",{className:x,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-accent-700 dark:text-accent-400",children:d("conversation.you")}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:h}),"sending"===f&&(0,r.jsxs)("span",{"data-testid":"optimistic-sending",className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(nN.A,{size:12,className:"animate-spin","aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.sending")})]}),"error"===f&&(0,r.jsxs)("span",{"data-testid":"optimistic-error",className:"flex items-center gap-1 text-xs text-danger-foreground",children:[(0,r.jsx)(ae.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.failedToSend")})]}),"error"===f?(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[l&&(0,r.jsxs)("button",{type:"button","data-testid":"pending-retry",onClick:()=>l(t.id),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-accent-700 dark:text-accent-400 hover:bg-muted transition-colors","aria-label":d("conversation.retrySending"),title:u("retry"),children:[(0,r.jsx)(at.A,{size:12,"aria-hidden":"true"}),u("retry")]}),i&&(0,r.jsxs)("button",{type:"button","data-testid":"pending-discard",onClick:()=>i(t.id),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-muted-foreground hover:text-danger-foreground hover:bg-muted transition-colors","aria-label":d("conversation.discardMessage"),title:d("conversation.discard"),children:[(0,r.jsx)(eG.A,{size:12,"aria-hidden":"true"}),d("conversation.discard")]})]}):(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100 [@media(hover:none)]:opacity-100",children:[s&&(0,r.jsx)("button",{type:"button","data-testid":"insert-user-message",onClick:()=>s(t.content),className:"p-1 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 hover:bg-muted rounded transition-colors","aria-label":d("conversation.insertToMessage"),title:d("conversation.insertToMessage"),children:(0,r.jsx)(an.A,{size:14,"aria-hidden":"true"})}),a&&(0,r.jsx)("button",{type:"button","data-testid":"copy-user-message",onClick:()=>a(t.content),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors","aria-label":d("conversation.copyMessage"),title:d("conversation.copy"),children:(0,r.jsx)(ej.A,{size:14,"aria-hidden":"true"})})]})]}),(0,r.jsx)("div",{"data-message-id":t.id,className:"text-sm text-foreground whitespace-pre-wrap break-words [word-break:break-word] max-w-full overflow-x-hidden",children:(0,r.jsx)(r5,{content:t.content,onFilePathClick:n})})]})}),r8=(0,i.memo)(function(e){let{message:t,index:n,total:a,isExpanded:s,onFilePathClick:l,onCopy:o,hasLongContent:d=!1,onToggleExpand:u}=e,m=(0,to.Ym)(),h=(0,c.c)("worktree"),f=am(m),x=(0,X.bg)(t.timestamp,f),{text:p,isTruncated:g}=(0,i.useMemo)(()=>r2(t.content),[t.content]),b=s||!g?t.content:p,v=ao(t.requestId),y=v&&g&&!s;return(0,r.jsxs)("div",{className:"assistant-message-item group relative",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:h("conversation.assistant")}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:x}),a>1&&(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",n+1,"/",a,")"]}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100 [@media(hover:none)]:opacity-100",children:[0===n&&d&&!!u&&(0,r.jsxs)("button",{type:"button",onClick:u,className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-accent-700 dark:text-accent-400 hover:text-accent-600 dark:hover:text-accent-300 hover:bg-muted transition-colors","aria-expanded":s,"aria-label":h(s?"conversation.collapseMessage":"conversation.expandMessage"),children:[(0,r.jsx)(K.A,{size:12,className:"transition-transform ".concat(s?"rotate-180":""),"aria-hidden":"true"}),h(s?"conversation.collapse":"conversation.expand")]}),o&&(0,r.jsx)("button",{type:"button","data-testid":"copy-assistant-message",onClick:()=>o(t.content),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors","aria-label":h("conversation.copyMessage"),title:h("conversation.copy"),children:(0,r.jsx)(ej.A,{size:14,"aria-hidden":"true"})})]})]}),v?(0,r.jsx)("div",{"data-message-id":t.id,"data-markdown":"true",className:["assistant-md text-xs text-foreground break-words [word-break:break-word] max-w-full overflow-x-hidden",y?"".concat("max-h-[3.25rem]"," overflow-y-hidden"):""].filter(Boolean).join(" "),children:(0,r.jsx)(r4,{content:t.content,onFilePathClick:l})}):(0,r.jsxs)("div",{"data-message-id":t.id,className:"text-xs text-foreground whitespace-pre-wrap break-words [word-break:break-word] max-w-full overflow-x-hidden",children:[(0,r.jsx)(r5,{content:b,onFilePathClick:l}),!s&&g&&(0,r.jsx)("span",{className:"text-muted-foreground",children:"..."})]})]})}),r9=(0,i.memo)(function(e){let{messages:t,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l=!1,onToggleExpand:o}=e;return(0,r.jsx)("div",{className:"bg-surface-2/50 border-l-2 border-border p-2 border-t border-border space-y-2",children:t.map((e,c)=>(0,r.jsxs)(i.Fragment,{children:[c>0&&(0,r.jsx)("div",{"data-testid":"assistant-message-divider",className:"border-t border-dashed border-border"}),(0,r.jsx)(r8,{message:e,index:c,total:t.length,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l,onToggleExpand:o})]},e.id))})});function r7(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{"data-testid":"orphan-indicator",className:"bg-warning/10 text-warning-foreground text-xs px-3 py-1 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("span",{children:e("conversation.systemMessage")})]})}let se=(0,i.memo)(function(e){var t;let{pair:n,onFilePathClick:a,isExpanded:s=!1,onToggleExpand:l,onCopy:o,onInsertToMessage:d,showAssistant:u=!0,onRetryPending:m,onDiscardPending:h}=e,f=(0,c.c)("worktree"),x=(null==(t=n.userMessage)?void 0:t.optimisticState)!==void 0,p=(0,i.useMemo)(()=>n.assistantMessages.some(e=>{let{isTruncated:t}=r2(e.content);return t}),[n.assistantMessages]),g=(0,i.useCallback)(()=>{l&&l()},[l]),b=(0,i.useMemo)(()=>{let e="pending"===n.status?"pending":"orphan"===n.status?"orphan border-l-4 border-warning":"";return"".concat("border border-border rounded-lg overflow-hidden mb-4 transition-colors"," ").concat(e).trim()},[n.status]),v=n.userMessage?f("conversation.conversationLabel",{preview:"".concat(n.userMessage.content.substring(0,50)).concat(n.userMessage.content.length>50?"...":"")}):f("conversation.systemMessageLabel");return(0,r.jsxs)("div",{"data-testid":"conversation-pair-card",role:"article","aria-label":v,className:b,children:["orphan"===n.status&&(0,r.jsx)(r7,{}),n.userMessage&&(0,r.jsx)(r6,{message:n.userMessage,onFilePathClick:a,onCopy:o,onInsertToMessage:d,onRetryPending:m,onDiscardPending:h}),"pending"!==n.status||x?u&&n.assistantMessages.length>0?(0,r.jsx)(r9,{messages:n.assistantMessages,isExpanded:s,onFilePathClick:a,onCopy:o,hasLongContent:p,onToggleExpand:g}):null:(0,r.jsx)("div",{className:"bg-muted/40 border-l-2 border-border p-3 border-t border-border",children:(0,r.jsx)(r3,{})})]})});var st=n(72115);let sn="worktree-history-pane",sa=(0,i.memo)(function(e){let{history:t,terminal:n}=e,{visible:a,width:s,setWidth:l}=r0(),o=(0,i.useRef)(null),c=(0,i.useCallback)(e=>{let t=o.current;if(!t)return;let n=t.offsetWidth;0!==n&&l(s+e/n*100)},[s,l]);return(0,r.jsxs)("div",{ref:o,className:"flex h-full min-h-0 w-full",children:[null!=t&&(a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:sn,"data-testid":"terminal-container-history-slot","aria-label":"History pane",style:{width:"".concat(s,"%")},className:"flex-shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",children:(0,r.jsx)(E,{componentName:"HistoryPane",children:t})}),(0,r.jsx)(st.f,{onResize:c,orientation:"horizontal",ariaValueNow:s})]}):null),(0,r.jsx)("div",{"data-testid":"terminal-container-terminal-slot","aria-label":"Terminal pane",className:"flex-grow overflow-hidden min-w-0",children:(0,r.jsx)(E,{componentName:"TerminalAndFilePanel",children:n})})]})}),sr=[50,100,150,200,250,500,1e3],ss="commandmate:historyDisplayLimit";function sl(e){return sr.includes(e)}let si="commandmate:historyUserOnly";function so(){let e=(0,c.c)("worktree");return(0,r.jsx)("div",{"data-testid":"loading-indicator",role:"status","aria-label":e("history.loading"),children:[0,1,2].map(e=>(0,r.jsxs)("div",{className:"mb-4 overflow-hidden rounded-lg border border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 p-3",children:[(0,r.jsx)(m.EA,{className:"h-4 w-4 rounded-full"}),(0,r.jsx)(m.EA,{className:"h-4 w-1/3"})]}),(0,r.jsxs)("div",{className:"space-y-2 px-3 pb-3",children:[(0,r.jsx)(m.EA,{className:"h-3 w-full"}),(0,r.jsx)(m.EA,{className:"h-3 w-5/6"}),(0,r.jsx)(m.EA,{className:"h-3 w-2/3"})]})]},e))})}function sc(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[(0,r.jsx)("svg",{className:"w-12 h-12 mb-2 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,r.jsx)("p",{className:"text-sm",children:e("history.empty")})]})}let sd=["h-full","flex","flex-col","overflow-hidden","bg-surface-2","rounded-lg","border","border-border"],su=(0,i.memo)(function(e){let{messages:t,worktreeId:n,worktreePath:a,onFilePathClick:s,isLoading:l=!1,className:o="",showToast:d,onInsertToMessage:u,onRetryPending:h,onDiscardPending:f,showArchived:x=!1,onShowArchivedChange:p,historyDisplayLimit:g,onHistoryDisplayLimitChange:b,historyUserOnly:v=!1,onHistoryUserOnlyChange:y,onCollapse:j,splitIndex:w,cliToolId:k}=e,N=(0,c.c)("worktree"),C=(0,i.useRef)(null),S=nJ(),T=null!=a?a:S.worktreePath,I=(0,i.useMemo)(()=>void 0===w?e0:{highlightName:"history-search-".concat(w),currentHighlightName:"history-search-current-".concat(w),fallbackOverlayId:"history-search-fallback-overlay-".concat(w),fallbackOverlayBgColor:e0.fallbackOverlayBgColor},[w]),E=void 0===w?"history-pane-collapse-button":"history-pane-collapse-button-".concat(w),A=void 0===w?sn:r1(w),M=(0,i.useRef)(!0),L=(0,i.useRef)(-1),R=(0,i.useRef)(null),{pairs:P,isExpanded:D,toggleExpand:F}=function(e){let t=(0,i.useMemo)(()=>(function(e){if(0===e.length)return[];let t=[...e].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),n=[],a=null;for(let e of t)if("user"===e.role)a={id:e.id,userMessage:e,assistantMessages:[],status:"pending"},n.push(a);else if("assistant"===e.role)if(a&&null!==a.userMessage)a.assistantMessages.push(e),a.status="completed";else if(a&&null===a.userMessage)a.assistantMessages.push(e);else{let t={id:"orphan-".concat(e.id),userMessage:null,assistantMessages:[e],status:"orphan"};n.push(t),a=t}return n})(e),[e]),[n,a]=(0,i.useState)(new Set),r=(0,i.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,i.useCallback)(e=>n.has(e),[n]),l=(0,i.useCallback)(()=>{a(new Set(t.map(e=>e.id)))},[t]);return{pairs:t,expandedPairs:n,toggleExpand:r,isExpanded:s,expandAll:l,collapseAll:(0,i.useCallback)(()=>{a(new Set)},[])}}(t),{isOpen:O,query:z,matchCount:_,currentIndex:H,isAtMaxMatches:V,matchPositions:U,currentMatch:K,openSearch:W,closeSearch:$,setQuery:q,onCompositionStart:G,onCompositionEnd:J,nextMatch:Y,prevMatch:Q}=nP({messages:(0,i.useMemo)(()=>t.filter(e=>!e.archived&&"string"==typeof e.content&&e.content.length>0&&(!v||"user"===e.role)),[t,v])}),X=O&&U.length>0,Z=(0,i.useMemo)(()=>t.filter(e=>"relay"===e.messageType).length,[t]),[ee,et]=(0,i.useState)(new Set);(0,i.useEffect)(()=>{$()},[n]);let en=(0,i.useMemo)(()=>v?P.filter(e=>e.userMessage):P,[P,v]),ea=(0,i.useMemo)(()=>{let e=new Map;for(let t of en)for(let n of(t.userMessage&&e.set(t.userMessage.id,t.id),t.assistantMessages))e.set(n.id,t.id);return e},[en]),er=(0,i.useMemo)(()=>{let e=new Map;return en.forEach((t,n)=>e.set(t.id,n)),e},[en]),es=(0,nL.Te)({count:en.length,getScrollElement:()=>C.current,estimateSize:()=>160,overscan:6,getItemKey:e=>{var t,n;return null!=(n=null==(t=en[e])?void 0:t.id)?n:e}}),el=es.getVirtualItems(),ei=el.length>0?"".concat(el[0].index,"-").concat(el[el.length-1].index):"",eo=(0,i.useCallback)(()=>{let e=C.current;e&&(M.current=nY({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))},[]);(0,i.useLayoutEffect)(()=>{let e=L.current,t=en.length;L.current=t,-1!==e&&t>e&&t>0&&M.current&&!X&&es.scrollToIndex(t-1,{align:"end"})},[en.length,X,es]),(0,i.useLayoutEffect)(()=>{if(!O||0===U.length)return void et(e=>0===e.size?e:new Set);et(function(e,t){let n=new Map;for(let e of t)for(let t of(e.userMessage&&n.set(e.userMessage.id,e.id),e.assistantMessages))n.set(t.id,e.id);let a=new Set;for(let t of e){let e=n.get(t.messageId);e&&a.add(e)}return a}(U,P))},[O,U,P]),(0,i.useEffect)(()=>{if(!O||!K)return;let e=ea.get(K.messageId);if(void 0===e)return;let t=er.get(e);void 0!==t&&es.scrollToIndex(t,{align:"center"})},[O,K,ea,er,es]),(0,i.useLayoutEffect)(()=>{let e=C.current;if(!e)return;if(!O||0===U.length)return void e3(I);let t=null;for(let a of U){var n;let r=(n=a.messageId,e.querySelector('[data-message-id="'.concat(CSS.escape(n),'"]')));if(!r)continue;let s=(null==K?void 0:K.messageId)===a.messageId,l=s?K.localIndex:-1;e6(r,a.ranges,l,I),s&&r instanceof HTMLElement&&(t=r)}return t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"}),()=>{e3(I)}},[O,U,K,ee,I,ei]),(0,i.useEffect)(()=>{let e=C.current;if(O)null===R.current&&e&&(R.current=e.scrollTop);else{if(null!==R.current&&e){let t=R.current;requestAnimationFrame(()=>{e.scrollTop=t})}R.current=null}},[O]);let ec=(0,i.useMemo)(()=>[...sd,o].filter(Boolean).join(" "),[o]),ed=(0,i.useRef)(N);ed.current=N;let eu=(0,i.useCallback)(e=>{let t=nV(e,T);null!==t&&(async()=>{if("missing"===await nW(n,t)){null==d||d(ed.current("conversation.filePathMissing"),"error");return}s(t)})()},[s,n,T,d]),em=(0,i.useCallback)(e=>()=>F(e),[F]),eh=(0,i.useCallback)(async e=>{try{await (0,eq.l)(e),null==d||d(ed.current("history.copied"),"success")}catch(e){console.error("[HistoryPane] Failed to copy to clipboard"),null==d||d(ed.current("history.copyFailed"),"error")}},[d]),ef=e=>{var t,n;let a=(null==(t=e.userMessage)?void 0:t.archived)===!0||(null==(n=e.assistantMessages)?void 0:n.some(e=>!0===e.archived)),s=D(e.id)||ee.has(e.id);return(0,r.jsx)("div",{className:a?"opacity-60":"",children:(0,r.jsx)(se,{pair:e,onFilePathClick:eu,isExpanded:s,onToggleExpand:em(e.id),onCopy:eh,onInsertToMessage:u,onRetryPending:h,onDiscardPending:f,showAssistant:!v})})},ex=(0,i.useCallback)(e=>{let t=parseInt(e.target.value,10);sl(t)&&(null==b||b(t))},[b]),ep=(0,i.useCallback)(()=>{O?$():W()},[O,W,$]);return(0,r.jsxs)("div",{role:"region","aria-label":N("history.regionLabel"),className:ec,children:[(0,r.jsxs)("div",{className:"flex-shrink-0 bg-surface-2 border-b border-border px-4 py-2 flex items-center justify-between flex-wrap gap-1",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:N("history.title")}),Z>0&&(0,r.jsxs)("span",{"data-testid":"history-relay-count",title:N("relay.historyBadgeTitle"),className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(nk.A,{size:12,className:"shrink-0","aria-hidden":"true"}),N("relay.historyCount",{count:Z})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[b&&void 0!==g&&(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer",children:[(0,r.jsx)("span",{children:N("history.show")}),(0,r.jsx)("select",{value:g,onChange:ex,"aria-label":N("history.displayLimit"),className:"rounded border border-input bg-surface text-foreground text-xs px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring",children:sr.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),p&&(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer",children:[(0,r.jsx)(m.Sc,{checked:x,onCheckedChange:e=>p(!0===e),className:"h-3.5 w-3.5"}),N("history.showArchived")]}),y&&(0,r.jsx)("button",{type:"button",onClick:()=>y(!v),"aria-label":N("history.showUserOnly"),"aria-pressed":v,className:"p-1 rounded transition-colors ".concat(v?"bg-accent-500/15 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:text-foreground"),title:N(v?"history.showAllMessages":"history.showUserOnly"),children:v?(0,r.jsx)(r$.A,{size:14,"aria-hidden":"true"}):(0,r.jsx)(rq.A,{size:14,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:ep,"aria-label":N(O?"history.closeSearch":"history.openSearch"),"aria-pressed":O,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:N(O?"history.closeSearch":"history.openSearch"),children:(0,r.jsx)(B.A,{size:14,"aria-hidden":"true"})}),j&&(0,r.jsx)("button",{type:"button",onClick:j,"aria-label":N("terminal.hideHistory"),"aria-expanded":"true","aria-controls":A,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:N("terminal.hideHistory"),"data-testid":E,children:(0,r.jsx)(rG.A,{size:14,"aria-hidden":"true"})})]})]}),O&&(0,r.jsx)("div",{className:"flex-shrink-0 px-3 py-2 bg-surface-2 border-b border-border",children:(0,r.jsx)(aB,{query:z,onQueryChange:q,matchCount:_,currentIndex:H,onNext:Y,onPrev:Q,onClose:$,isAtMaxMatches:V,onCompositionStart:G,onCompositionEnd:J})}),(0,r.jsx)("div",{ref:C,"data-testid":"history-scroll-container",onScroll:eo,className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden p-4",children:l?(0,r.jsx)(so,{}):0===en.length?(0,r.jsx)(sc,{}):0===el.length?(0,r.jsx)("div",{"data-testid":"history-fallback-list",children:en.slice(0,30).map(e=>(0,r.jsx)("div",{children:ef(e)},e.id))}):(0,r.jsx)("div",{style:{height:es.getTotalSize(),width:"100%",position:"relative"},children:el.map(e=>{let t=en[e.index];return t?(0,r.jsx)("div",{"data-index":e.index,ref:es.measureElement,className:"absolute left-0 top-0 w-full",style:{transform:"translateY(".concat(e.start,"px)")},children:ef(t)},e.key):null})})})]})}),sm={isOpen:!1,position:{x:0,y:0},targetPath:null,targetType:null};function sh(){let[e,t]=(0,i.useState)(sm),n=(0,i.useCallback)((e,n,a)=>{t({isOpen:!0,position:e,targetPath:n,targetType:a})},[]),a=(0,i.useCallback)((e,t,a)=>{let r,s;if(e.preventDefault(),"touches"in e&&e.touches.length>0)r=e.touches[0].clientX,s=e.touches[0].clientY;else{if(!("clientX"in e))return;r=e.clientX,s=e.clientY}n({x:r,y:s},t,a)},[n]),r=(0,i.useCallback)(()=>{t(e=>({...e,isOpen:!1}))},[]),s=(0,i.useCallback)(()=>{t(sm)},[]);return(0,i.useEffect)(()=>{if(!e.isOpen)return;let t=()=>{r()},n=setTimeout(()=>{document.addEventListener("click",t)},0);return()=>{clearTimeout(n),document.removeEventListener("click",t)}},[e.isOpen,r]),(0,i.useEffect)(()=>{if(!e.isOpen)return;let t=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[e.isOpen,r]),{menuState:e,openMenu:a,openMenuAt:n,closeMenu:r,resetMenu:s}}var sf=n(47650),sx=n(7504),sp=n(22198),sg=n(21786),sb=n(26754),sv=n(71360),sy=n(9286);function sj(e,t,n){let a=n-t-8;return a<8?8:Math.min(Math.max(e,8),a)}let sw=(0,i.memo)(function(e){let{isOpen:t,position:n,targetPath:a,targetType:s,onClose:l,onNewFile:o,onNewDirectory:d,onRename:u,onDelete:m,onUpload:h,onMove:f,items:x,ariaLabel:p}=e,g=(0,c.c)("worktree"),b=(0,i.useRef)(null),{shouldRender:v,isExiting:y}=(0,sy.O)(t,eM.$B),j=x?x.map(e=>e.id).join(","):"builtin",w="".concat(n.x,":").concat(n.y,":").concat(s,":").concat(j),[k,N]=(0,i.useState)(null),C=(null==k?void 0:k.key)===w?k:null;(0,i.useLayoutEffect)(()=>{if(!t)return;let e=b.current;if(!e)return;let a=e.getBoundingClientRect();N({key:w,left:sj(n.x,a.width,window.innerWidth),top:sj(n.y,a.height,window.innerHeight)})},[t,w,n.x,n.y]);let S=(0,i.useCallback)(e=>{e&&a&&e(a),l()},[a,l]),T=[{id:"new-file",label:g("fileTree.newFile"),icon:(0,r.jsx)(sx.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>S(o),showFor:["directory"]},{id:"new-directory",label:g("fileTree.newDirectory"),icon:(0,r.jsx)(sp.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>S(d),showFor:["directory"]},{id:"upload",label:g("contextMenu.uploadFile"),icon:(0,r.jsx)(sg.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>S(h),showFor:["directory"],showDividerAfter:!0},{id:"rename",label:g("contextMenu.rename"),icon:(0,r.jsx)(eY.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>S(u)},{id:"move",label:g("contextMenu.move"),icon:(0,r.jsx)(sb.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>{f&&a&&s&&f(a,s),l()},showDividerAfter:!0},{id:"delete",label:g("contextMenu.delete"),icon:(0,r.jsx)(sv.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>S(m),variant:"danger"}],I=x?x.map(e=>{var t,n;return{id:e.id,label:e.label,icon:null!=(t=e.icon)?t:null,onClick:()=>{e.onSelect(),l()},variant:e.variant,showDividerAfter:e.showDividerAfter,disabled:null!=(n=e.disabled)&&n}}):T.filter(e=>!e.showFor||s&&e.showFor.includes(s));if((0,i.useEffect)(()=>{if(!t)return;let e=e=>{if("Escape"===e.key)return void l();if("ArrowDown"===e.key||"ArrowUp"===e.key){var t;let n;e.preventDefault();let a=null==(t=b.current)?void 0:t.querySelectorAll('[role="menuitem"]');if(!(null==a?void 0:a.length))return;let r=Array.from(a).findIndex(e=>e===document.activeElement);n="ArrowDown"===e.key?r<a.length-1?r+1:0:r>0?r-1:a.length-1,a[n].focus()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,l]),(0,i.useEffect)(()=>{if(t&&b.current){let e=b.current.querySelector('[role="menuitem"]');e&&e.focus()}},[t]),!v)return null;let E=(0,r.jsx)("div",{ref:b,"data-testid":"context-menu",role:"menu","aria-label":null!=p?p:g("contextMenu.label"),className:"fixed min-w-[160px] py-1 bg-surface rounded-lg shadow-lg border border-border ".concat(y?"animate-out fade-out-0 zoom-out-95 duration-100 fill-mode-forwards pointer-events-none":"animate-in fade-in-0 zoom-in-95 duration-100"),style:{zIndex:eQ.M.CONTEXT_MENU,left:"".concat(C?C.left:0,"px"),top:"".concat(C?C.top:0,"px")},children:I.map((e,t)=>{var n;let s=null!=(n=e.disabled)?n:!a;return(0,r.jsxs)(i.Fragment,{children:[(0,r.jsxs)("button",{role:"menuitem","data-testid":"context-menu-".concat(e.id),onClick:e.onClick,disabled:s,className:"w-full flex items-center gap-3 px-3 py-2 text-sm transition-colors focus:outline-none focus:bg-muted ".concat("danger"===e.variant?"text-danger hover:bg-danger-subtle focus:bg-danger-subtle":"text-foreground hover:bg-muted"," ").concat(s?"opacity-50 cursor-not-allowed":""),children:[e.icon,(0,r.jsx)("span",{children:e.label})]}),e.showDividerAfter&&t<I.length-1&&(0,r.jsx)("div",{"data-testid":"context-menu-divider",className:"my-1 border-t border-border"})]},e.id)})});return"undefined"==typeof document?E:(0,sf.createPortal)(E,document.body)});var sk=n(30061);let sN="commandmate.worktree.fileMetadataDisplay",sC={showSize:!0,showCreated:!1,showModified:!1},sS="commandmate:fileMetadataDisplayChange";function sT(e){return void 0===e?"":e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}let sI=(0,i.memo)(function(e){let{expanded:t}=e;return(0,r.jsx)("svg",{"data-testid":"chevron-icon",className:"w-4 h-4 text-muted-foreground transition-transform ".concat(t?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}),sE=(0,i.memo)(function(e){let{open:t}=e;return(0,r.jsx)("svg",{"data-testid":"folder-icon",className:"w-5 h-5 text-warning",fill:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:t?(0,r.jsx)("path",{d:"M19 20H5c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2h6l2 2h6c1.1 0 2 .9 2 2v10c0 1.1-.9 2-2 2zM5 6v12h14V8h-7l-2-2H5z"}):(0,r.jsx)("path",{d:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"})})}),sA=(0,i.memo)(function(e){let{text:t,query:n}=e;if(!n||!n.trim())return(0,r.jsx)(r.Fragment,{children:t});let a=(0,x.Nt)(n),s=t.split(RegExp("(".concat(a,")"),"gi"));return(0,r.jsx)(r.Fragment,{children:s.map((e,t)=>e.toLowerCase()===n.toLowerCase()?(0,r.jsx)("mark",{className:"bg-warning-border text-foreground px-0.5 rounded",children:e},t):(0,r.jsx)("span",{children:e},t))})}),sM=(0,i.memo)(function(e){let{extension:t}=e,n=(0,i.useMemo)(()=>t&&({ts:"text-info",tsx:"text-info",js:"text-warning",jsx:"text-warning",json:"text-warning",md:"text-muted-foreground",css:"text-accent-500",scss:"text-accent-500",html:"text-warning",py:"text-success"})[t]||"text-muted-foreground",[t]);return(0,r.jsx)("svg",{"data-testid":"file-icon",className:"w-5 h-5 ".concat(n),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),sL=(0,i.memo)(function e(t){let{item:n,path:a,depth:s,worktreeId:l,expanded:o,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:f,onContextMenu:x,searchQuery:p,searchMode:g,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y=sC}=t,j=(0,c.c)("worktree"),[w,k]=(0,i.useState)(!1),N=a?"".concat(a,"/").concat(n.name):n.name,C=o.has(N),S="directory"===n.type,T=d.get(N),I=(0,i.useMemo)(()=>v?am(v):void 0,[v]),E=(0,i.useMemo)(()=>{if(S)return;let e=[];if(void 0!==n.size&&e.push("".concat(j("fileTree.metadata.size"),": ").concat(sT(n.size))),n.birthtime){let t=(0,X.bg)(new Date(n.birthtime),I);t&&e.push("".concat(j("fileTree.metadata.created"),": ").concat(t))}if(n.mtime){let t=(0,X.bg)(new Date(n.mtime),I);t&&e.push("".concat(j("fileTree.metadata.modified"),": ").concat(t))}return e.length>0?e.join("\n"):void 0},[S,n.size,n.birthtime,n.mtime,I,j]),A=(0,i.useCallback)(async()=>{S?(C||T||(k(!0),await f(N),k(!1)),m(N)):null==h||h(N)},[S,C,T,N,f,m,h]),M=(0,i.useCallback)(e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),A())},[A]),L=(0,i.useCallback)(e=>{e.preventDefault(),null==x||x(e,N,S?"directory":"file")},[N,S,x]),R=function(e){let{delay:t=500,moveThreshold:n=10,onLongPress:a}=e,r=(0,i.useRef)(null),s=(0,i.useRef)(null),l=(0,i.useRef)(null),o=(0,i.useCallback)(()=>{r.current&&(clearTimeout(r.current),r.current=null),s.current=null,l.current=null},[]);(0,i.useEffect)(()=>()=>o(),[o]);let c=(0,i.useCallback)(e=>{if(1!==e.touches.length)return;let n=e.touches[0];s.current={x:n.clientX,y:n.clientY},l.current=e,r.current=setTimeout(()=>{l.current&&a(l.current),o()},t)},[t,a,o]),d=(0,i.useCallback)(e=>{if(!s.current||1!==e.touches.length)return;let t=e.touches[0],a=t.clientX-s.current.x,r=t.clientY-s.current.y;Math.sqrt(a*a+r*r)>n&&o()},[n,o]);return{onTouchStart:c,onTouchMove:d,onTouchEnd:(0,i.useCallback)(()=>{o()},[o]),onTouchCancel:(0,i.useCallback)(()=>{o()},[o])}}({onLongPress:(0,i.useCallback)(e=>{null==x||x(e,N,S?"directory":"file")},[N,S,x])}),P={...function(e){let t=Math.min(e,20);return{paddingLeft:"".concat(.5+ +t,"rem")}}(s),touchAction:"manipulation",WebkitTouchCallout:"none"};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{"data-testid":"tree-item-".concat(n.name),role:"treeitem","aria-selected":!1,"aria-expanded":S?C:void 0,tabIndex:0,className:"flex items-center gap-2 py-1.5 pr-2 cursor-pointer hover:bg-muted rounded transition-colors",style:P,onClick:A,onKeyDown:M,onContextMenu:L,onTouchStart:R.onTouchStart,onTouchMove:R.onTouchMove,onTouchEnd:R.onTouchEnd,onTouchCancel:R.onTouchCancel,children:[S?(0,r.jsx)("span",{className:"w-4 h-4 flex items-center justify-center",children:w?(0,r.jsx)(u.y,{size:"xs",variant:"accent"}):(0,r.jsx)(sI,{expanded:C})}):(0,r.jsx)("span",{className:"w-4 h-4"}),S?(0,r.jsx)(sE,{open:C}):(0,r.jsx)(sM,{extension:n.extension}),(0,r.jsx)(sk.nR,{content:n.name,metadata:E,className:"flex-1 truncate text-sm text-foreground",children:"name"===g&&p?(0,r.jsx)(sA,{text:n.name,query:p}):n.name}),y.showSize&&(0,r.jsx)("span",{"data-testid":"tree-item-size",className:"text-xs text-muted-foreground flex-shrink-0",children:S?void 0!==n.itemCount&&j("fileTree.itemCount",{count:n.itemCount}):sT(n.size)}),!S&&y.showCreated&&n.birthtime&&(0,r.jsx)("span",{"data-testid":"tree-item-created",className:"text-xs text-muted-foreground flex-shrink-0",children:(0,X.fw)(n.birthtime,I)}),!S&&y.showModified&&n.mtime&&(0,r.jsx)("span",{"data-testid":"tree-item-modified",className:"text-xs text-muted-foreground flex-shrink-0",children:(0,X.fw)(n.mtime,I)})]}),S&&C&&T&&(0,r.jsx)("div",{role:"group",children:T.filter(e=>{let t=N?"".concat(N,"/").concat(e.name):e.name;if(!(null==p?void 0:p.trim()))return!0;if("name"===g){let t=p.toLowerCase();return!!e.name.toLowerCase().includes(t)||"directory"===e.type}if("content"===g&&b&&b.size>0){if(b.has(t))return!0;if("directory"===e.type){for(let e of b)if(e.startsWith(t+"/"))return!0}return!1}return!0}).map(t=>(0,r.jsx)(e,{item:t,path:N,depth:s+1,worktreeId:l,expanded:o,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:f,onContextMenu:x,searchQuery:p,searchMode:g,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y},t.name))})]})});var sR=n(26989);let sP=[{key:"showSize",labelKey:"fileTree.metadata.showSize"},{key:"showCreated",labelKey:"fileTree.metadata.showCreated"},{key:"showModified",labelKey:"fileTree.metadata.showModified"}];function sD(e,t,n){if(t<=0||n<=0)return 0;let a=e+t+8-n;return a>0?-Math.min(a,Math.max(0,e-8)):e<8?8-e:0}let sF=(0,i.memo)(function(e){let{settings:t,onToggle:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,i.useState)(!1),o=(0,i.useRef)(null),d=(0,i.useRef)(null),u=(0,i.useRef)({x:0,y:0}),[h,f]=(0,i.useState)({x:0,y:0});(0,i.useEffect)(()=>{if(!s)return;let e=e=>{o.current&&!o.current.contains(e.target)&&l(!1)},t=e=>{"Escape"===e.key&&l(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[s]),(0,i.useLayoutEffect)(()=>{let e=e=>{u.current=e,f(t=>t.x===e.x&&t.y===e.y?t:e)};if(!s)return void e({x:0,y:0});let t=d.current;if(!t)return;let n=t.getBoundingClientRect();e({x:sD(n.left-u.current.x,n.width,window.innerWidth),y:sD(n.top-u.current.y,n.height,window.innerHeight)})},[s]);let x=(0,i.useCallback)(e=>{n(e)},[n]);return(0,r.jsxs)("div",{className:"relative",ref:o,"data-testid":"file-metadata-toggle",children:[(0,r.jsx)("button",{type:"button","data-testid":"file-metadata-toggle-button",onClick:()=>l(e=>!e),"aria-haspopup":"menu","aria-expanded":s,"aria-label":a("fileTree.metadata.settingsLabel"),title:a("fileTree.metadata.settingsLabel"),className:"flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:bg-muted rounded transition-colors",children:(0,r.jsx)(sR.A,{className:"w-4 h-4","aria-hidden":"true"})}),s&&(0,r.jsxs)("div",{ref:d,role:"menu","data-testid":"file-metadata-toggle-menu",className:"absolute right-0 top-full z-20 mt-1 min-w-[12rem] rounded border border-border bg-surface shadow-lg p-1",style:0!==h.x||0!==h.y?{transform:"translate(".concat(h.x,"px, ").concat(h.y,"px)")}:void 0,children:[(0,r.jsx)("div",{className:"px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wide",children:a("fileTree.metadata.settingsTitle")}),sP.map(e=>(0,r.jsxs)("label",{className:"flex items-center gap-2 px-2 py-1.5 text-xs text-foreground hover:bg-muted rounded cursor-pointer",children:[(0,r.jsx)(m.Sc,{"data-testid":"file-metadata-toggle-".concat(e.key),checked:t[e.key],onCheckedChange:()=>x(e.key),className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{children:a(e.labelKey)})]},e.key))]})]})});function sO(e){let{intervalMs:t,enabled:n,onPoll:a}=e,r=(0,i.useRef)(a);r.current=a;let s=(0,i.useRef)(n);s.current=n;let l=(0,i.useRef)(null);(0,i.useEffect)(()=>{function e(){null!==l.current&&(clearInterval(l.current),l.current=null)}function a(){e(),l.current=setInterval(()=>{r.current()},t)}function i(){"hidden"===document.visibilityState?e():"visible"===document.visibilityState&&s.current&&(r.current(),a())}return n?a():e(),document.addEventListener("visibilitychange",i),()=>{e(),document.removeEventListener("visibilitychange",i)}},[t,n])}function sz(e){return"commandmate:file-tree-expanded:"+e}function s_(e){try{let t=window.localStorage.getItem(sz(e));if(!t)return new Set;let n=JSON.parse(t);if(Array.isArray(n)&&n.every(e=>"string"==typeof e))return new Set(n)}catch(e){}return new Set}var sB=n(89559);let sH=(0,i.memo)(function(e){let{worktreeId:t,onFileSelect:n,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:o,onUpload:d,onMove:u,className:h="",refreshTrigger:f=0,pollingEnabled:p=!1,searchQuery:g,searchMode:b,searchResults:v,onSearchResultSelect:y,onResetView:j}=e,w=(0,to.Ym)(),k=(0,c.c)("worktree"),{settings:N,toggle:C}=function(){let[e,t]=(0,i.useState)(sC),n=(0,i.useRef)(e);n.current=e,(0,i.useEffect)(()=>{t(function(){try{var e;let t=window.localStorage.getItem(sN);if(!t)return{...sC};return e=JSON.parse(t),"object"!=typeof e||null===e?{...sC}:{showSize:"boolean"==typeof e.showSize?e.showSize:sC.showSize,showCreated:"boolean"==typeof e.showCreated?e.showCreated:sC.showCreated,showModified:"boolean"==typeof e.showModified?e.showModified:sC.showModified}}catch(e){return{...sC}}}())},[]),(0,i.useEffect)(()=>{let e=e=>{if(e.detail){var a,r;a=e.detail.settings,r=n.current,(a.showSize!==r.showSize||a.showCreated!==r.showCreated||a.showModified!==r.showModified)&&t(e.detail.settings)}};return window.addEventListener(sS,e),()=>window.removeEventListener(sS,e)},[]);let a=(0,i.useCallback)(e=>{n.current=e,t(e);try{window.localStorage.setItem(sN,JSON.stringify(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(sS,{detail:{settings:e}}))}catch(e){}},[]);return{settings:e,toggle:(0,i.useCallback)(e=>{a({...n.current,[e]:!n.current[e]})},[a]),setSettings:a}}(),[S,T]=(0,i.useState)(!0),[I,E]=(0,i.useState)(null),[A,M]=(0,i.useState)([]),{expanded:L,setExpanded:R,resetExpanded:P}=function(e){let[t,n]=(0,i.useState)(()=>s_(e)),a=(0,i.useRef)(e);(0,i.useEffect)(()=>{a.current!==e&&(a.current=e,n(s_(e)))},[e]),(0,i.useEffect)(()=>{!function(e,t){try{let n=sz(e);if(0===t.size)return void window.localStorage.removeItem(n);window.localStorage.setItem(n,JSON.stringify(Array.from(t)))}catch(e){}}(a.current,t)},[t]);let r=(0,i.useCallback)(()=>{n(new Set)},[]);return{expanded:t,setExpanded:n,resetExpanded:r}}(t),[D,F]=(0,i.useState)(()=>new Map),O=(0,i.useRef)(null),z=(0,i.useRef)(L);z.current=L;let _=(0,i.useRef)(k);_.current=k;let B=(0,i.useRef)(new Set),{menuState:H,openMenu:V,closeMenu:U}=sh(),K=(0,i.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{let n=e?"/api/worktrees/".concat(t,"/tree/").concat(e):"/api/worktrees/".concat(t,"/tree"),a=await fetch(n);if(!a.ok)throw Error(_.current("fileTree.loadDirectoryError",{status:a.status}));return await a.json()}catch(e){throw console.error("[FileTreeView] Error fetching directory:",e),e}},[t]),W=(0,i.useRef)(!0);(0,i.useEffect)(()=>(W.current=!0,()=>{W.current=!1}),[]);let $=(0,i.useCallback)(async()=>{if(W.current){T(!0),E(null);try{let e=await K();if(!W.current||!e)return;let t=Array.from(z.current),n=new Map,a=[];for(let e=0;e<t.length;e+=5){if(!W.current)return;let r=t.slice(e,e+5);for(let[e,t]of(await Promise.allSettled(r.map(async e=>{let t=await K(e);return{dirPath:e,data:t}}))).entries())"fulfilled"===t.status&&t.value.data?n.set(t.value.dirPath,t.value.data.items):a.push(r[e])}if(!W.current)return;M(e.items),F(n),a.length>0&&R(e=>{let t=new Set(e);for(let e of a)e&&t.delete(e);return t})}catch(e){W.current&&E(e instanceof Error?e.message:_.current("fileTree.loadError"))}finally{W.current&&T(!1)}}},[K,R]);(0,i.useEffect)(()=>{$()},[$,f]);let q=(0,i.useRef)(null),G=(0,i.useRef)(!1);(0,i.useEffect)(()=>{q.current=null},[t]),sO({intervalMs:5e3,enabled:p,onPoll:(0,i.useCallback)(async()=>{if(W.current&&!G.current){G.current=!0;try{let e=["",...Array.from(z.current)],t=new Map;for(let n=0;n<e.length;n+=5){if(!W.current)return;let a=e.slice(n,n+5);for(let{dirPath:e,hash:n}of(await Promise.all(a.map(async e=>{try{var t;let n=await K(e);return{dirPath:e,hash:JSON.stringify(null!=(t=null==n?void 0:n.items)?t:null)}}catch(t){return{dirPath:e,hash:"unavailable"}}}))))t.set(e,n)}if(!W.current)return;let n=q.current;if(q.current=t,null===n)return;let a=!1;for(let[e,r]of t){let t=n.get(e);if(void 0!==t&&t!==r){a=!0;break}}a&&$()}finally{G.current=!1}}},[K,$])});let J=(0,i.useCallback)(async e=>{if(!(D.has(e)||B.current.has(e))){B.current.add(e);try{let t=await K(e);t&&F(n=>{let a=new Map(n);return a.set(e,t.items),a})}catch(e){console.error("[FileTreeView] Error loading children:",e)}finally{B.current.delete(e)}}},[D,K]),Y=(0,i.useCallback)(e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[R]),Q=(0,i.useCallback)(()=>{var e;P(),F(new Map),null==(e=O.current)||e.scrollTo({top:0}),null==j||j()},[P,j]),X=(0,i.useMemo)(()=>"content"===b&&v&&0!==v.length?(0,x.q3)(v.map(e=>e.filePath)):new Set,[b,v]);(0,i.useEffect)(()=>{X.size>0&&R(e=>{let t=new Set(e);for(let e of X)(D.has(e)||(null==v?void 0:v.some(t=>t.filePath.startsWith(e+"/"))))&&t.add(e);return t})},[X,D,v,R]);let Z=(0,i.useMemo)(()=>{if(!(null==g?void 0:g.trim()))return A;if("name"===b){let e=g.toLowerCase(),t=(n,a)=>n.filter(n=>{let r=a?"".concat(a,"/").concat(n.name):n.name,s=n.name.toLowerCase().includes(e);if("directory"===n.type){let e=D.get(r);if(e&&t(e,r).length>0)return!0}return s});return t(A,"")}return"content"===b&&X.size>0?A.filter(e=>{if(X.has(e.name))return!0;if("directory"===e.type){for(let t of X)if(t.startsWith(e.name+"/")||t===e.name)return!0}return!1}):A},[A,g,b,X,D]);if(S&&0===A.length)return(0,r.jsx)("div",{"data-testid":"file-tree-loading",className:"p-2 ".concat(h),role:"status","aria-label":k("fileTree.loading"),children:[0,8,16,8,0,8].map((e,t)=>(0,r.jsxs)("div",{className:"flex items-center gap-2 py-1.5 pr-2",style:{paddingLeft:"".concat(8+e,"px")},children:[(0,r.jsx)(m.EA,{className:"h-4 w-4 shrink-0 rounded"}),(0,r.jsx)(m.EA,{className:"h-4 ".concat(t%3==0?"w-32":t%3==1?"w-24":"w-40"," max-w-full")})]},t))});if(I&&0===A.length)return(0,r.jsx)("div",{"data-testid":"file-tree-error",className:"p-4 bg-danger-subtle border border-danger-border rounded-lg ".concat(h),children:(0,r.jsx)("p",{className:"text-sm text-danger",children:I})});let ee=S&&A.length>0,et=!!I&&A.length>0;return 0===A.length?(0,r.jsxs)("div",{"data-testid":"file-tree-empty",className:"p-4 text-center text-muted-foreground ".concat(h),children:[(0,r.jsx)("p",{className:"text-sm",children:k("fileTree.empty")}),(a||s)&&(0,r.jsxs)("div",{className:"flex flex-col gap-2 mt-4",children:[a&&(0,r.jsxs)(m.$n,{variant:"ghost","data-testid":"empty-new-file-button",onClick:()=>a(""),className:"flex items-center justify-center gap-2 px-3 py-2 text-sm text-foreground bg-surface border border-input rounded-md hover:bg-muted transition-colors",children:[(0,r.jsx)(sx.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newFile")})]}),s&&(0,r.jsxs)(m.$n,{variant:"ghost","data-testid":"empty-new-directory-button",onClick:()=>s(""),className:"flex items-center justify-center gap-2 px-3 py-2 text-sm text-foreground bg-surface border border-input rounded-md hover:bg-muted transition-colors",children:[(0,r.jsx)(sp.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newDirectory")})]})]})]}):(null==g?void 0:g.trim())&&0===Z.length?(0,r.jsx)("div",{"data-testid":"file-tree-no-results",className:"p-4 text-center text-muted-foreground ".concat(h),children:(0,r.jsx)("p",{className:"text-sm",children:k("content"===b?"fileTree.noResultsContaining":"fileTree.noResultsMatching",{query:g})})}):(0,r.jsxs)("div",{ref:O,"data-testid":"file-tree-view",role:"tree","aria-label":k("fileTree.label"),className:"overflow-auto bg-surface ".concat(h),children:[(0,r.jsxs)("div",{"data-testid":"file-tree-toolbar",className:"flex items-center gap-1 p-1 border-b border-border",children:[a&&(0,r.jsxs)("button",{"data-testid":"toolbar-new-file-button",onClick:()=>a(""),className:"flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:bg-muted rounded transition-colors",children:[(0,r.jsx)(sx.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newFile")})]}),s&&(0,r.jsxs)("button",{"data-testid":"toolbar-new-directory-button",onClick:()=>s(""),className:"flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:bg-muted rounded transition-colors",children:[(0,r.jsx)(sp.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newDirectory")})]}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[(0,r.jsx)(sF,{settings:N,onToggle:C}),ee&&(0,r.jsxs)("div",{"data-testid":"file-tree-refetch-indicator",role:"status","aria-live":"polite",className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:"w-3 h-3 border-2 border-input border-t-accent-500 rounded-full animate-spin"}),(0,r.jsx)("span",{className:"sr-only",children:k("fileTree.refreshing")})]}),(0,r.jsx)("button",{"data-testid":"file-tree-refresh-button",type:"button",onClick:()=>{$()},disabled:ee,"aria-label":k("fileTree.refreshLabel"),title:k("actions.refresh"),className:"flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:bg-muted rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,r.jsx)(sB.A,{className:"w-4 h-4 ".concat(ee?"animate-spin":""),"aria-hidden":"true"})}),(0,r.jsx)("button",{"data-testid":"file-tree-reset-button",type:"button",onClick:Q,"aria-label":k("fileTree.resetViewLabel"),title:k("actions.resetView"),className:"flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:bg-muted rounded transition-colors",children:(0,r.jsx)(at.A,{className:"w-4 h-4","aria-hidden":"true"})})]})]}),et&&(0,r.jsxs)("div",{"data-testid":"file-tree-refetch-error",role:"alert",className:"flex items-center gap-2 px-2 py-1 text-xs bg-danger-subtle border-b border-danger-border text-danger-foreground",children:[(0,r.jsx)(ae.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"flex-1 truncate",children:I}),(0,r.jsx)(m.$n,{variant:"ghost","data-testid":"file-tree-refetch-retry-button",onClick:()=>{$()},className:"px-2 py-0.5 text-xs rounded border border-danger-border hover:bg-danger-subtle transition-colors",children:k("actions.retry")})]}),Z.map(e=>(0,r.jsx)(sL,{item:e,path:"",depth:0,worktreeId:t,expanded:L,cache:D,onToggle:Y,onFileSelect:y||n,onLoadChildren:J,onContextMenu:V,searchQuery:g,searchMode:b,matchedPaths:X,dateFnsLocaleStr:w,metadataDisplay:N},e.name)),(0,r.jsx)(sw,{isOpen:H.isOpen,position:H.position,targetPath:H.targetPath,targetType:H.targetType,onClose:U,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:o,onUpload:d,onMove:u})]})}),sV=(0,i.memo)(function(){return(0,r.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),sU=(0,i.memo)(function(){return(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),sK=(0,i.memo)(function(){let e=(0,c.c)("worktree");return(0,r.jsx)(u.y,{size:"sm",variant:"accent","data-testid":"search-loading",role:"status","aria-hidden":!1,"aria-label":e("search.searching")})}),sW=(0,i.memo)(function(e){let{query:t,mode:n,isSearching:a,error:s,onQueryChange:l,onModeChange:o,onClear:d,placeholder:u,className:m=""}=e,h=(0,i.useRef)(null),f=(0,c.c)("worktree"),x=(0,i.useCallback)(e=>{l(e.target.value)},[l]),p=(0,i.useCallback)(()=>{var e;d(),null==(e=h.current)||e.focus()},[d]),g=(0,i.useCallback)(e=>{if("Escape"===e.key)if(t)p();else{var n;null==(n=h.current)||n.blur()}},[t,p]);return(0,i.useEffect)(()=>{if(!(window.innerWidth<eC.D)){let e=setTimeout(()=>{var e;null==(e=h.current)||e.focus()},100);return()=>clearTimeout(e)}},[]),(0,r.jsxs)("div",{"data-testid":"search-bar",className:"flex flex-col gap-2 p-2 bg-surface dark:bg-surface-2 border-b border-border ".concat(m),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(sV,{})}),(0,r.jsx)("input",{ref:h,type:"text","data-testid":"search-input",value:t,onChange:x,onKeyDown:g,placeholder:null!=u?u:f("search.placeholder"),className:"flex-1 min-w-0 px-2 py-1 text-sm bg-muted text-foreground border border-input rounded focus:outline-none focus:ring-1 focus:ring-ring focus:border-accent-500","aria-label":f("search.label"),"aria-busy":a}),(0,r.jsx)("div",{className:"flex-shrink-0 w-6 h-6 flex items-center justify-center",children:a?(0,r.jsx)(sK,{}):t?(0,r.jsx)("button",{type:"button","data-testid":"search-clear",onClick:p,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors","aria-label":f("search.clear"),children:(0,r.jsx)(sU,{})}):null})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground mr-1",children:f("search.mode")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-name",onClick:()=>o("name"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("name"===n?"bg-accent-100 dark:bg-accent-900 text-accent-700 dark:text-accent-300 font-medium":"bg-muted text-muted-foreground hover:bg-muted/80"),"aria-pressed":"name"===n,children:f("search.modeName")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-content",onClick:()=>o("content"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("content"===n?"bg-accent-100 dark:bg-accent-900 text-accent-700 dark:text-accent-300 font-medium":"bg-muted text-muted-foreground hover:bg-muted/80"),"aria-pressed":"content"===n,children:f("search.modeContent")})]}),s&&(0,r.jsx)("div",{"data-testid":"search-error",className:"text-xs text-danger bg-danger-subtle px-2 py-1 rounded",role:"alert",children:s})]})});function s$(e){return 0===e.length?"0":e.map(e=>"".concat(e.id,":").concat(e.title.length,":").concat(e.content.length)).join("|")}var sq=n(12108),sG=n(60850);let sJ=(0,i.memo)(function(e){var t,n;let{memo:a,onUpdate:s,onDelete:l,isSaving:o,error:d,className:u="",onInsertToMessage:m,onMoveUp:h,onMoveDown:f,canMoveUp:x=!0,canMoveDown:p=!0}=e,g=(0,c.c)("schedule"),b=(0,c.c)("worktree"),v=!!(h||f),[y,j]=(0,i.useState)(a.title),[w,k]=(0,i.useState)(a.content),[N,C]=(0,i.useState)(!1),S=(0,i.useRef)(void 0);(0,i.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let{isSaving:T,error:I,saveNow:E}=(0,sG.U)({value:y,saveFn:async e=>{await s(a.id,{title:e})}}),{isSaving:A,error:M,saveNow:L}=(0,sG.U)({value:w,saveFn:async e=>{await s(a.id,{content:e})}}),R=null!=(n=null!=(t=null!=d?d:null==I?void 0:I.message)?t:null==M?void 0:M.message)?n:null,P=(0,i.useCallback)(e=>{j(e.target.value)},[]),D=(0,i.useCallback)(e=>{k(e.target.value)},[]),F=(0,i.useCallback)(()=>{E()},[E]),O=(0,i.useCallback)(()=>{L()},[L]),z=(0,i.useCallback)(()=>{l(a.id)},[a.id,l]),_=(0,i.useCallback)(()=>{w.trim()&&(null==m||m(w))},[w,m]),B=(0,i.useCallback)(async()=>{if(w.trim())try{await (0,eq.l)(w),C(!0),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>C(!1),2e3)}catch(e){}},[w]);return(0,r.jsxs)("div",{"data-testid":"memo-card","data-memo-id":a.id,tabIndex:-1,className:"bg-surface dark:bg-surface-2 border border-border rounded-lg p-4 space-y-3 focus:outline-none ".concat(u),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"text",value:y,onChange:P,onBlur:F,placeholder:g("memoTitlePlaceholder"),className:"flex-1 min-w-0 text-sm font-medium text-foreground bg-transparent border-none focus:outline-none focus:ring-0 p-0"}),(null!=o?o:T||A)&&(0,r.jsx)("span",{"data-testid":"saving-indicator",className:"text-xs text-muted-foreground",children:b("actions.saving")}),v&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{type:"button","data-testid":"memo-move-up-".concat(a.id),onClick:h,disabled:!x,"aria-label":g("memoMoveUp"),title:g("memoMoveUp"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-foreground transition-colors rounded disabled:opacity-30 disabled:cursor-not-allowed",children:(0,r.jsx)(sq.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button","data-testid":"memo-move-down-".concat(a.id),onClick:f,disabled:!p,"aria-label":g("memoMoveDown"),title:g("memoMoveDown"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-foreground transition-colors rounded disabled:opacity-30 disabled:cursor-not-allowed",children:(0,r.jsx)(K.A,{className:"w-4 h-4","aria-hidden":"true"})})]}),m&&(0,r.jsx)("button",{type:"button","data-testid":"insert-memo-content",onClick:_,"aria-label":g("memoInsertToMessage"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 transition-colors rounded",title:g("memoInsertToMessage"),children:(0,r.jsx)(an.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:B,"aria-label":g("memoCopyContent"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-foreground transition-colors rounded",children:N?(0,r.jsx)(ey.A,{className:"w-4 h-4 text-success"}):(0,r.jsx)(ej.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{type:"button",onClick:z,"aria-label":g("memoDelete"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-danger transition-colors rounded",children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}),(0,r.jsx)("textarea",{value:w,onChange:D,onBlur:O,placeholder:g("memoContentPlaceholder"),rows:4,className:"w-full text-sm text-foreground bg-muted border border-border rounded-md p-2 resize-y focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),R&&(0,r.jsx)("div",{className:"text-xs text-danger",children:R})]})}),sY=(0,i.memo)(function(e){let{currentCount:t,maxCount:n,onAdd:a,isLoading:s=!1,className:l=""}=e,i=(0,c.c)("schedule"),o=Math.max(0,n-t),d=t>=n||s;return(0,r.jsxs)("div",{"data-testid":"memo-add-button",className:"flex flex-col items-center gap-2 ".concat(l),children:[(0,r.jsxs)("button",{type:"button",onClick:()=>{d||a()},disabled:d,"aria-label":i("memoAdd"),"aria-disabled":d,className:"\n flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-dashed\n transition-colors focus:outline-none focus:ring-2 focus:ring-ring\n ".concat(d?"border-border text-muted-foreground cursor-not-allowed opacity-50":"border-border text-muted-foreground hover:border-accent-400 dark:hover:border-accent-500 hover:text-accent-600 dark:hover:text-accent-400 hover:bg-accent-50 dark:hover:bg-accent-900/30","\n "),children:[s?(0,r.jsx)(u.y,{"data-testid":"loading-indicator",size:"md",variant:"accent"}):(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),(0,r.jsx)("span",{className:"text-sm font-medium",children:i("memoAdd")})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:i("memoRemaining",{count:o})})]})});function sQ(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:o,onClose:d,onCompositionStart:u,onCompositionEnd:h}=e,f=(0,c.c)("schedule"),x=(0,i.useRef)(null);(0,i.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]);let p=(0,i.useCallback)(e=>{if("Escape"===e.key)return void d();"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),l())},[d,l]),g=(0,i.useCallback)(e=>{n(e.target.value)},[n]),b=0===a?"0/0":"".concat(s+1,"/").concat(a);return(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted border border-input rounded",role:"search","aria-label":f("memoSearchLabel"),children:[(0,r.jsx)("input",{ref:x,type:"text",value:t,onChange:g,onKeyDown:p,onCompositionStart:u,onCompositionEnd:h,placeholder:f("memoSearchPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-foreground text-sm outline-none placeholder-muted-foreground","aria-label":f("memoSearchInputLabel"),autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1}),(0,r.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"text-muted-foreground text-xs min-w-[3rem] text-right",children:b}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:o,disabled:0===a,"aria-label":f("memoSearchPrev"),className:"text-muted-foreground hover:text-foreground dark:hover:text-white disabled:text-muted-foreground/50 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▲"}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:l,disabled:0===a,"aria-label":f("memoSearchNext"),className:"text-muted-foreground hover:text-foreground dark:hover:text-white disabled:text-muted-foreground/50 min-w-[36px] min-h-[36px] flex items-center justify-center text-base",children:"▼"}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:d,"aria-label":f("memoSearchClose"),className:"text-muted-foreground hover:text-foreground dark:hover:text-white min-w-[36px] min-h-[36px] flex items-center justify-center text-base ml-1",children:"✕"})]})}let sX=(0,i.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a}=e,s=(0,c.c)("schedule"),l=(0,c.c)("common"),o=(0,eO.SC)(),[d,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(!0),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(!1),k=(0,i.useRef)(null),{query:N,matches:C,currentMatch:S,totalCount:T,setQuery:I,reset:E,navigateNext:A,navigatePrev:M,onCompositionStart:L,onCompositionEnd:R}=function(e){let{memos:t}=e,[n,a]=(0,i.useState)(""),[r,s]=(0,i.useState)([]),[l,o]=(0,i.useState)(-1),c=(0,i.useRef)(null),d=(0,i.useRef)(""),u=(0,i.useRef)(!1),m=(0,i.useRef)(s$(t)),h=(0,i.useRef)(t);h.current=t;let f=r.length,x=(0,i.useCallback)(()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),p=(0,i.useCallback)(e=>{let t=function(e,t){if(t.length<2||0===e.length)return[];let n=t.toLowerCase();return e.filter(e=>-1!==e.title.toLowerCase().indexOf(n)||-1!==e.content.toLowerCase().indexOf(n))}(h.current,e);s(t),o(t.length>0?0:-1)},[]),g=(0,i.useCallback)(e=>{x(),d.current=e,u.current||(c.current=setTimeout(()=>{p(e)},300))},[x,p]),b=(0,i.useCallback)(e=>{a(e),g(e)},[g]),v=(0,i.useCallback)(()=>{a(""),d.current="",s([]),o(-1),x()},[x]),y=(0,i.useCallback)(()=>{o(e=>0===f?-1:(e+1)%f)},[f]),j=(0,i.useCallback)(()=>{o(e=>0===f?-1:(e-1+f)%f)},[f]),w=(0,i.useCallback)(()=>{u.current=!0,x()},[x]),k=(0,i.useCallback)(()=>{u.current=!1;let e=d.current;e.length>=2&&(x(),c.current=setTimeout(()=>{p(e)},300))},[x,p]);return(0,i.useEffect)(()=>{let e=s$(t);if(e===m.current)return;m.current=e;let n=d.current;n.length>=2&&p(n)},[t,p]),(0,i.useEffect)(()=>()=>{x(),d.current=""},[x]),{query:n,matches:r,currentMatch:l,totalCount:f,setQuery:b,reset:v,navigateNext:y,navigatePrev:j,onCompositionStart:w,onCompositionEnd:k}}({memos:d}),P=j&&N.length>0,D=P?C:d,F=(0,i.useCallback)(async()=>{f(!0),b(null);try{let e=await el.$T.getAll(t);m(e.sort((e,t)=>e.position-t.position))}catch(e){b((0,el.hS)(e))}finally{f(!1)}},[t]);(0,i.useEffect)(()=>{F()},[F]);let O=(0,i.useCallback)(async()=>{p(!0),y(null);try{let e=await el.$T.create(t,{title:s("memoDefaultTitle"),content:""});m(t=>[...t,e])}catch(e){y((0,el.hS)(e))}finally{p(!1)}},[t,s]),z=(0,i.useCallback)(async(e,n)=>{await el.$T.update(t,e,n),m(t=>t.map(t=>t.id===e?{...t,...n}:t))},[t]),_=(0,i.useCallback)(async e=>{var n;let a=d.find(t=>t.id===e);if(await o({description:l("confirmDelete",{name:null!=(n=null==a?void 0:a.title)?n:""}),variant:"danger"}))try{await el.$T.delete(t,e),m(t=>t.filter(t=>t.id!==e))}catch(e){console.error("Failed to delete memo:",e)}},[t,d,o,l]),H=(0,i.useCallback)(async(e,n)=>{let a=e+n;if(a<0||a>=d.length)return;let r=[...d];[r[e],r[a]]=[r[a],r[e]],m(r);try{await el.$T.reorder(t,r.map(e=>e.id))}catch(e){b((0,el.hS)(e)),await F()}},[d,t,F]),V=(0,i.useCallback)(()=>{F()},[F]),U=(0,i.useCallback)(()=>{w(e=>(e&&E(),!e))},[E]),K=(0,i.useCallback)(()=>{w(!1),E()},[E]);return((0,i.useEffect)(()=>{var e;if(!P||S<0)return;let t=C[S];if(!t)return;let n=null==(e=k.current)?void 0:e.querySelector('[data-memo-id="'.concat(t.id,'"]'));n&&(n.scrollIntoView({block:"nearest"}),n.focus({preventScroll:!0}))},[P,S,C]),h)?(0,r.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(n),children:(0,r.jsxs)("div",{"data-testid":"memo-loading",className:"flex flex-col items-center gap-3",children:[(0,r.jsx)(u.y,{size:"xl",variant:"accent"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:s("memoLoading")})]})}):g?(0,r.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(n),children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 text-center",children:[(0,r.jsx)("svg",{className:"w-12 h-12 text-danger",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("span",{className:"text-sm text-danger-foreground",children:g}),(0,r.jsx)("button",{type:"button",onClick:V,"aria-label":l("retry"),className:"px-4 py-2 text-sm font-medium text-white bg-accent-500 rounded-lg hover:bg-accent-600 transition-colors",children:l("retry")})]})}):(0,r.jsxs)("div",{ref:k,"data-testid":"memo-pane",className:"flex flex-col gap-4 p-4 overflow-y-auto ".concat(n),children:[(0,r.jsx)("div",{"data-testid":"memo-pane-header",className:"flex items-center gap-2",children:j?(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsx)(sQ,{query:N,onQueryChange:I,matchCount:T,currentIndex:S,onNext:A,onPrev:M,onClose:K,onCompositionStart:L,onCompositionEnd:R})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsx)("button",{type:"button","data-testid":"memo-search-toggle",onClick:U,"aria-label":s("memoSearchToggle"),className:"p-1.5 text-muted-foreground hover:text-foreground transition-colors rounded",children:(0,r.jsx)(B.A,{className:"w-4 h-4","aria-hidden":"true"})})]})}),0===d.length&&!P&&!v&&(0,r.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,r.jsx)("p",{children:s("memoEmpty")}),(0,r.jsx)("p",{className:"text-sm",children:s("memoEmptyHint")})]}),P&&0===D.length&&(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:(0,r.jsx)("p",{children:s("memoNoMatch")})}),D.map((e,t)=>(0,r.jsx)(sJ,{memo:e,onUpdate:z,onDelete:_,onInsertToMessage:a,onMoveUp:P?void 0:()=>H(t,-1),onMoveDown:P?void 0:()=>H(t,1),canMoveUp:!P&&t>0,canMoveDown:!P&&t<d.length-1},e.id)),v&&(0,r.jsx)("div",{className:"text-center py-2 text-sm text-danger",children:v}),!P&&(0,r.jsx)(sY,{currentCount:d.length,maxCount:20,onAdd:O,isLoading:x,className:"mt-2"})]})});var sZ=n(85872),s0=n(53292),s1=n(53482);let s2={todo:"border-input text-muted-foreground",doing:"border-warning-border bg-warning-subtle text-warning-foreground",done:"border-success-border bg-success-subtle text-success-foreground"},s5=i.memo(function(e){let{worktreeId:t,className:n=""}=e,a=(0,c.c)("worktree"),s=(0,c.c)("common"),l=(0,eO.SC)(),[o,d]=(0,i.useState)([]),[u,m]=(0,i.useState)(""),[h,f]=(0,i.useState)(!0),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(""),[k,N]=(0,i.useState)(""),[C,S]=(0,i.useState)(!1),T=(0,i.useCallback)(e=>{switch(e){case"doing":return a("todo.statusDoing");case"done":return a("todo.statusDone");default:return a("todo.statusTodo")}},[a]),I=(0,i.useCallback)(async()=>{f(!0),b(null);try{let e=await sZ.Ar.list(t);d(e)}catch(e){b(e instanceof Error?e.message:a("todo.loadError")),d([])}finally{f(!1)}},[t,a]);(0,i.useEffect)(()=>{I()},[t]);let E=(0,i.useCallback)(async()=>{let e=u.trim();if(e&&!x){p(!0),b(null);try{let n=await sZ.Ar.create(t,e);d(e=>[...e,n]),m("")}catch(e){b(e instanceof Error?e.message:a("todo.addError"))}finally{p(!1)}}},[u,x,t,a]),A=(0,i.useCallback)(async e=>{let n=function(e){let t=sZ.KG.indexOf(e);return sZ.KG[(t+1)%sZ.KG.length]}(e.status);d(t=>t.map(t=>t.id===e.id?{...t,status:n,done:"done"===n}:t)),b(null);try{await sZ.Ar.update(t,e.id,{status:n})}catch(e){b(e instanceof Error?e.message:a("todo.updateError")),I()}},[t,I,a]),M=(0,i.useCallback)(async e=>{if(await l({description:s("confirmDelete",{name:e.content}),variant:"danger"})){b(null);try{await sZ.Ar.remove(t,e.id),d(t=>t.filter(t=>t.id!==e.id))}catch(e){b(e instanceof Error?e.message:a("todo.deleteError"))}}},[t,a,l,s]),L=(0,i.useCallback)(e=>{y(e),w(e.content),N(e.detail),b(null)},[]),R=(0,i.useCallback)(()=>{y(null),S(!1)},[]),P=(0,i.useCallback)(async()=>{if(!v)return;let e=j.trim();if(e&&!C){S(!0),b(null);try{let n=await sZ.Ar.update(t,v.id,{content:e,detail:k});d(e=>e.map(e=>e.id===v.id?n:e)),R()}catch(e){b(e instanceof Error?e.message:a("todo.updateError")),S(!1)}}},[v,j,k,C,t,R,a]),D=(0,i.useCallback)(async(e,n)=>{let r=e+n;if(r<0||r>=o.length)return;let s=[...o];[s[e],s[r]]=[s[r],s[e]],d(s),b(null);try{await sZ.Ar.reorder(t,s.map(e=>e.id))}catch(e){b(e instanceof Error?e.message:a("todo.reorderError")),I()}},[o,t,I,a]),F=(0,i.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),E())},[E]),O=(0,i.useMemo)(()=>({todo:o.filter(e=>"todo"===e.status).length,doing:o.filter(e=>"doing"===e.status).length,done:o.filter(e=>"done"===e.status).length}),[o]);return(0,r.jsxs)("div",{"data-testid":"todo-pane",className:"flex flex-col h-full overflow-y-auto p-4 ".concat(n).trim(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,r.jsx)("input",{type:"text",value:u,onChange:e=>m(e.target.value),onKeyDown:F,maxLength:s0.Ll,placeholder:a("todo.addPlaceholder"),"data-testid":"todo-input",className:"flex-1 min-w-0 rounded-md border border-input bg-surface dark:bg-surface-2 px-3 py-1.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("button",{type:"button",onClick:E,disabled:x||0===u.trim().length,"data-testid":"todo-add-button",className:"shrink-0 rounded-md bg-accent-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-accent-700 disabled:opacity-50",children:a("todo.add")})]}),(0,r.jsxs)("div",{className:"mb-2 flex justify-end gap-2 text-xs text-muted-foreground",children:[(0,r.jsxs)("span",{"data-testid":"todo-count-todo",children:[T("todo")," ",O.todo]}),(0,r.jsxs)("span",{"data-testid":"todo-count-doing",children:[T("doing")," ",O.doing]}),(0,r.jsxs)("span",{"data-testid":"todo-count-done",children:[T("done")," ",O.done]})]}),g&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"todo-error",children:g}),h?(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"todo-loading",children:a("todo.loading")}):0===o.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"todo-empty",children:a("todo.empty")}):(0,r.jsx)("ul",{className:"space-y-1","data-testid":"todo-list",children:o.map((e,t)=>(0,r.jsxs)("li",{className:"flex items-center gap-2 rounded-md px-1 py-1 hover:bg-muted group","data-testid":"todo-item",children:[(0,r.jsx)("button",{type:"button",onClick:()=>A(e),"data-testid":"todo-status","data-status":e.status,"aria-label":a("todo.cycleStatus",{status:T(e.status)}),title:a("todo.cycleStatus",{status:T(e.status)}),className:"shrink-0 inline-flex min-h-[44px] items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium sm:min-h-0 ".concat(s2[e.status]),children:T(e.status)}),(0,r.jsxs)("button",{type:"button",onClick:()=>L(e),"data-testid":"todo-content","aria-label":a("todo.edit"),title:a("todo.edit"),className:"group/content flex min-h-[44px] min-w-0 flex-1 items-center gap-1.5 text-left sm:min-h-0",children:[(0,r.jsx)("span",{className:"min-w-0 break-words text-sm ".concat("done"===e.status?"line-through text-muted-foreground":"text-foreground group-hover/content:text-accent-700 dark:group-hover/content:text-accent-300"),children:e.content}),""!==e.detail.trim()&&(0,r.jsxs)("svg",{"data-testid":"todo-detail-indicator","aria-label":a("todo.hasDetail"),className:"h-3.5 w-3.5 shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,r.jsx)("title",{children:a("todo.hasDetail")}),(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h10"})]})]}),(0,r.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[(0,r.jsx)("button",{type:"button",onClick:()=>D(t,-1),disabled:0===t,"aria-label":a("todo.moveUp"),"data-testid":"todo-move-up",className:"p-1 text-muted-foreground hover:text-foreground disabled:opacity-30",children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{type:"button",onClick:()=>D(t,1),disabled:t===o.length-1,"aria-label":a("todo.moveDown"),"data-testid":"todo-move-down",className:"p-1 text-muted-foreground hover:text-foreground disabled:opacity-30",children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{type:"button",onClick:()=>M(e),"aria-label":a("todo.delete"),"data-testid":"todo-delete",className:"inline-flex min-h-[44px] min-w-[44px] shrink-0 items-center justify-center text-muted-foreground opacity-100 transition-opacity hover:text-danger-foreground sm:min-h-0 sm:min-w-0 sm:opacity-0 sm:group-hover:opacity-100",children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.id))}),(0,r.jsx)(tN.a,{isOpen:null!==v,onClose:R,title:a("todo.editTitle"),size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:a("todo.contentLabel")}),(0,r.jsx)("input",{type:"text",value:j,onChange:e=>w(e.target.value),maxLength:s0.Ll,placeholder:a("todo.contentPlaceholder"),"data-testid":"todo-edit-content",className:"w-full rounded-md border border-input bg-surface dark:bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,r.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,r.jsxs)("span",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:a("todo.detailLabel")}),""!==k.trim()&&(0,r.jsx)(s1.i,{text:k,label:a("todo.copyDetail"),className:"!border-input !bg-surface dark:!bg-surface-2 !text-muted-foreground hover:!bg-muted"})]}),(0,r.jsx)("textarea",{value:k,onChange:e=>N(e.target.value),maxLength:s0.bu,rows:6,placeholder:a("todo.detailPlaceholder"),"data-testid":"todo-edit-detail",className:"w-full resize-y rounded-md border border-input bg-surface dark:bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:R,"data-testid":"todo-edit-cancel",className:"rounded-md border border-input px-3 py-1.5 text-sm font-medium text-foreground hover:bg-muted",children:a("todo.cancel")}),(0,r.jsx)("button",{type:"button",onClick:P,disabled:C||0===j.trim().length,"data-testid":"todo-edit-save",className:"rounded-md bg-accent-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-accent-700 disabled:opacity-50",children:a("todo.save")})]})]})})]})});var s4=n(95740),s3=n(66630);function s6(e){let{isOpen:t,onClose:n,title:a,children:s,footer:l,showCloseButton:o=!0}=e,d=(0,c.c)("common"),[u,m]=(0,i.useState)(null);return((0,i.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,n]),(0,i.useEffect)(()=>(t?document.body.style.overflow="hidden":document.body.style.overflow="unset",()=>{document.body.style.overflow="unset"}),[t]),(0,i.useEffect)(()=>{if(!t)return;let e=window.visualViewport;if(!e)return;let n=()=>m(e.height);return n(),e.addEventListener("resize",n),()=>e.removeEventListener("resize",n)},[t]),t)?(0,sf.createPortal)((0,r.jsxs)("div",{"data-testid":"full-screen-modal",role:"dialog","aria-modal":"true",className:"fixed inset-0 flex flex-col bg-surface animate-slide-up",style:{zIndex:eQ.M.MODAL,height:u?"".concat(u,"px"):"100dvh"},children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("h3",{className:"text-base font-semibold text-foreground truncate pr-2",children:a}),o&&(0,r.jsx)("button",{type:"button",onClick:n,"aria-label":d("close"),"data-testid":"full-screen-modal-close",className:"flex-shrink-0 -mr-1 p-1 text-muted-foreground hover:text-foreground transition-colors",children:(0,r.jsx)(eG.A,{className:"w-6 h-6"})})]}),(0,r.jsx)("div",{"data-testid":"full-screen-modal-body",className:"flex-1 min-h-0 overflow-y-auto overscroll-contain px-4 py-4",onFocusCapture:e=>{let t=e.target;t&&"function"==typeof t.scrollIntoView&&window.requestAnimationFrame(()=>{t.scrollIntoView({block:"center",behavior:"smooth"})})},children:s}),l&&(0,r.jsx)("div",{"data-testid":"full-screen-modal-footer",className:"flex-shrink-0 border-t border-border bg-surface px-4 py-3",style:{paddingBottom:"max(0.75rem, env(safe-area-inset-bottom))"},children:l})]}),document.body):null}let s8=["default","acceptEdits","plan","dontAsk","bypassPermissions"],s9=["read-only","workspace-write","danger-full-access"],s7=["allow-all-tools","yolo"],le=["--dangerously-skip-permissions"],lt=["default","standard","plan","auto-accept","dont-ask"],ln=[],la=[],lr=[],ls=[],ll={claude:"acceptEdits",codex:"workspace-write",gemini:"","vibe-local":"",opencode:"",copilot:"allow-all-tools",antigravity:"--dangerously-skip-permissions","command-code":"default"};function li(e){switch(e){case"claude":return s8;case"codex":return s9;case"copilot":return s7;case"antigravity":return le;case"command-code":return lt;case"gemini":return ln;case"vibe-local":return la;case"opencode":return lr;default:return ls}}let lo=/^[\w\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uF900-\uFAFF\s-]{1,100}$/;var lc=n(3199);let ld=[{value:"0 */1 * * *",labelKey:"cronPresetHourly"},{value:"0 9 * * *",labelKey:"cronPresetDaily9"},{value:"0 9 * * 1",labelKey:"cronPresetWeeklyMon9"}],lu={name:"",cronExpression:"0 9 * * *",message:"",cliToolId:"claude",enabled:!0,permission:null!=(a=ll.claude)?a:"",model:"",agent:"",variant:"",continueSession:!1,title:""},lm="w-full px-3 py-2 text-sm border border-input rounded-md bg-surface dark:bg-surface-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring",lh="block text-xs font-semibold text-foreground mb-1",lf="mt-1 text-xs text-danger-foreground";function lx(e){let{onClick:t,label:n,title:a,testId:s}=e;return(0,r.jsxs)("button",{type:"button","data-testid":s,onClick:t,title:a,className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-info-border text-info-foreground hover:bg-info-subtle transition-colors",children:[(0,r.jsx)(s4.A,{size:14,"aria-hidden":"true"}),n]})}function lp(e){let{id:t,title:n,summary:a,icon:s,isOpen:l,onToggle:i,children:o}=e,c="schedule-section-".concat(t,"-content");return(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,r.jsxs)("button",{type:"button","data-testid":"schedule-section-".concat(t),"aria-expanded":l,"aria-controls":c,onClick:()=>i(t),className:"w-full flex items-center gap-3 px-3 py-2.5 text-left bg-surface-2 hover:bg-muted transition-colors",children:[(0,r.jsx)("span",{className:"flex-shrink-0 text-accent-600 dark:text-accent-400",children:s}),(0,r.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"block text-sm font-semibold text-foreground",children:n}),a&&(0,r.jsx)("span",{"data-testid":"schedule-section-".concat(t,"-summary"),className:"block truncate text-xs text-muted-foreground",children:a})]}),(0,r.jsx)(K.A,{className:"flex-shrink-0 w-4 h-4 text-muted-foreground transition-transform ".concat(l?"rotate-180":"")})]}),l&&(0,r.jsx)("div",{id:c,className:"px-3 py-3 flex flex-col gap-4",children:o})]})}function lg(e){var t,n;let{isOpen:a,worktreeId:s,initialValues:l,originalName:o,onInsertToMessage:d,instances:u,onClose:h,onSaved:f}=e,x=(0,c.c)("schedule"),p=(0,eC.a)(),g=(0,i.useMemo)(()=>u&&u.length>0?u:(0,q.lu)([...q.XH]),[u]),[b,v]=(0,i.useState)(lu),[y,j]=(0,i.useState)(""),[w,N]=(0,i.useState)(!1),[C,S]=(0,i.useState)(null),[T,I]=(0,i.useState)(()=>new Set(["basic","advanced","message"]));(0,i.useEffect)(()=>{var e,t,n,r,s,i,o,c,d,u,m,h,f,x;if(!a)return;S(null),N(!1);let p=null!=(t=null==l?void 0:l.cliToolId)?t:lu.cliToolId;v({name:null!=(n=null==l?void 0:l.name)?n:lu.name,cronExpression:null!=(r=null==l?void 0:l.cronExpression)?r:lu.cronExpression,message:null!=(s=null==l?void 0:l.message)?s:lu.message,cliToolId:p,enabled:null!=(i=null==l?void 0:l.enabled)?i:lu.enabled,permission:null!=(o=null==l?void 0:l.permission)?o:lu.permission,model:null!=(c=null==l?void 0:l.model)?c:lu.model,agent:null!=(d=null==l?void 0:l.agent)?d:lu.agent,variant:null!=(u=null==l?void 0:l.variant)?u:lu.variant,continueSession:null!=(m=null==l?void 0:l.continueSession)?m:lu.continueSession,title:null!=(h=null==l?void 0:l.title)?h:lu.title});let b=g.find(e=>e.cliTool===p);j(null!=(x=null!=(f=null==b?void 0:b.id)?f:null==(e=g[0])?void 0:e.id)?x:p)},[a,l,g]),(0,i.useEffect)(()=>{a&&I(new Set(p?["basic"]:["basic","advanced","message"]))},[a,p]);let E=(0,i.useCallback)(e=>{I(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),A=li(b.cliToolId),M=A.length>0,L=lc.Vt.has(b.cliToolId),R=lc.aN.has(b.cliToolId),P=!!o,D=(0,i.useMemo)(()=>{let e=b.name.trim();return e?e.length>100?x("edit.errorNameTooLong",{max:100}):lo.test(e)?null:x("edit.errorNameInvalid"):x("edit.errorNameRequired")},[b.name,x]),F=(0,i.useMemo)(()=>!function(e){if(e.length>100)return!1;let t=e.trim().split(/\s+/);return t.length>=5&&t.length<=6}(b.cronExpression.trim())?x("edit.errorCronInvalid"):null,[b.cronExpression,x]),O=(0,i.useMemo)(()=>b.message.trim()?b.message.length>1e4?x("edit.errorMessageTooLong",{max:1e4}):null:x("edit.errorMessageRequired"),[b.message,x]),z=(0,i.useMemo)(()=>L&&b.model.trim()?(0,lc.JY)(b.model.trim()).valid?null:x("edit.errorModelInvalid"):null,[L,b.model,x]),_=(0,i.useMemo)(()=>R&&b.agent.trim()?(0,lc.sd)(b.agent.trim(),"agent").valid?null:x("edit.errorAgentInvalid"):null,[R,b.agent,x]),B=(0,i.useMemo)(()=>R&&b.variant.trim()?(0,lc.sd)(b.variant.trim(),"variant").valid?null:x("edit.errorVariantInvalid"):null,[R,b.variant,x]),H=(0,i.useMemo)(()=>R&&b.title.trim()?(0,lc.kj)(b.title.trim()).valid?null:x("edit.errorTitleInvalid"):null,[R,b.title,x]),V=!D&&!F&&!O&&!z&&!_&&!B&&!H,K=(0,i.useCallback)(e=>{v(t=>({...t,cliToolId:e,permission:function(e){let t=ll[e];if(void 0!==t)return t;let n=li(e);return n.length>0?n[0]:""}(e),model:lc.Vt.has(e)?t.model:"",agent:lc.aN.has(e)?t.agent:"",variant:lc.aN.has(e)?t.variant:"",continueSession:!!lc.aN.has(e)&&t.continueSession,title:lc.aN.has(e)?t.title:""}))},[]),W=(0,i.useCallback)(e=>{let t=g.find(t=>t.id===e);t&&(j(e),K(t.cliTool))},[g,K]),$=ld.some(e=>e.value===b.cronExpression)?b.cronExpression:"custom",G=(0,i.useCallback)(e=>{"custom"!==e&&v(t=>({...t,cronExpression:e}))},[]),J=(0,i.useCallback)(e=>{null==d||d(e),h()},[d,h]),Y=(0,i.useCallback)(async()=>{if(V&&!w){N(!0),S(null);try{let e=await fetch("/api/worktrees/".concat(s,"/cmate/schedules"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b.name.trim(),cronExpression:b.cronExpression.trim(),message:b.message.trim(),cliToolId:b.cliToolId,enabled:b.enabled,permission:M?b.permission:"",model:L&&b.model.trim()?b.model.trim():void 0,agent:R&&b.agent.trim()?b.agent.trim():void 0,variant:R&&b.variant.trim()?b.variant.trim():void 0,continueSession:!!R&&!!b.continueSession||void 0,title:R&&b.title.trim()?b.title.trim():void 0,originalName:null!=o?o:void 0})});if(!e.ok){let t=await e.json().catch(()=>({}));S(t.error||x("edit.saveError"));return}f(),h()}catch(e){S(x("edit.saveError"))}finally{N(!1)}}},[V,w,s,b,M,L,R,o,f,h,x]),Q=null!=(n=null==(t=g.find(e=>e.id===y))?void 0:t.alias)?n:(0,q.f_)(b.cliToolId),X=b.name.trim()?"".concat(b.name.trim()," \xb7 ").concat(b.cronExpression):b.cronExpression,Z=[Q,M?b.permission:null,L&&b.model.trim()?b.model.trim():null,R&&b.agent.trim()?"--agent ".concat(b.agent.trim()):null,R&&b.variant.trim()?"--variant ".concat(b.variant.trim()):null,R&&b.continueSession?"--continue":null].filter(Boolean).join(" \xb7 "),ee=b.message.trim(),et=ee.length>32?"".concat(ee.slice(0,32),"…"):ee,en=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-name-input",children:x("edit.name")}),(0,r.jsx)("input",{id:"schedule-name-input","data-testid":"schedule-name-input",type:"text",value:b.name,maxLength:100,placeholder:x("edit.namePlaceholder"),onChange:e=>v(t=>({...t,name:e.target.value})),className:lm}),D&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-name-error",children:D})]}),(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"mb-1 flex items-center justify-between gap-2",children:[(0,r.jsx)("label",{className:"block text-xs font-semibold text-foreground",htmlFor:"schedule-cron-input",children:x("edit.cron")}),d&&(0,r.jsx)(lx,{testId:"schedule-cron-ask-ai",label:x("edit.askAiCron"),title:x("edit.askAiHint"),onClick:()=>J(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.cron"):e("edit.aiPrompts.cronRefine",{current:"`"+n+"`"})}(x,b.cronExpression))})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row",children:[(0,r.jsx)("input",{id:"schedule-cron-input","data-testid":"schedule-cron-input",type:"text",value:b.cronExpression,placeholder:x("edit.cronPlaceholder"),onChange:e=>v(t=>({...t,cronExpression:e.target.value})),className:"".concat(lm," font-mono sm:flex-1")}),(0,r.jsxs)("select",{"data-testid":"schedule-cron-preset","aria-label":x("edit.cronPreset"),value:$,onChange:e=>G(e.target.value),className:"".concat(lm," sm:w-48"),children:[ld.map(e=>(0,r.jsx)("option",{value:e.value,children:x("edit.".concat(e.labelKey))},e.value)),(0,r.jsx)("option",{value:"custom",children:x("edit.cronPresetCustom")})]})]}),F&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-cron-error",children:F})]}),(0,r.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,r.jsx)(m.Sc,{"data-testid":"schedule-enabled-toggle",checked:b.enabled,onCheckedChange:e=>v(t=>({...t,enabled:!0===e}))}),(0,r.jsx)("span",{className:"text-sm text-foreground",children:x("edit.enabledLabel")})]})]}),ea=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-cli-tool-select",children:x("edit.cliTool")}),(0,r.jsx)("select",{id:"schedule-cli-tool-select","data-testid":"schedule-cli-tool-select",value:y,onChange:e=>W(e.target.value),className:lm,children:g.map(e=>(0,r.jsx)("option",{value:e.id,children:e.alias},e.id))})]}),L&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-model-input",children:x("edit.model")}),(0,r.jsx)("input",{id:"schedule-model-input","data-testid":"schedule-model-input",type:"text",value:b.model,placeholder:x("edit.modelPlaceholder"),onChange:e=>v(t=>({...t,model:e.target.value})),className:lm}),z&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-model-error",children:z})]}),R&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-agent-input",children:x("edit.opencodeAgent")}),(0,r.jsx)("input",{id:"schedule-agent-input","data-testid":"schedule-agent-input",type:"text",value:b.agent,placeholder:x("edit.opencodeAgentPlaceholder"),onChange:e=>v(t=>({...t,agent:e.target.value})),className:lm}),_&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-agent-error",children:_})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-variant-input",children:x("edit.opencodeVariant")}),(0,r.jsx)("input",{id:"schedule-variant-input","data-testid":"schedule-variant-input",type:"text",value:b.variant,placeholder:x("edit.opencodeVariantPlaceholder"),onChange:e=>v(t=>({...t,variant:e.target.value})),className:lm}),B&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-variant-error",children:B})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-title-input",children:x("edit.opencodeTitle")}),(0,r.jsx)("input",{id:"schedule-title-input","data-testid":"schedule-title-input",type:"text",value:b.title,placeholder:x("edit.opencodeTitlePlaceholder"),onChange:e=>v(t=>({...t,title:e.target.value})),className:lm}),H&&(0,r.jsx)("p",{className:lf,"data-testid":"schedule-title-error",children:H})]}),(0,r.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,r.jsx)(m.Sc,{"data-testid":"schedule-continue-toggle",checked:b.continueSession,onCheckedChange:e=>v(t=>({...t,continueSession:!0===e}))}),(0,r.jsx)("span",{className:"text-sm text-foreground",children:x("edit.opencodeContinue")})]})]}),M&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:lh,htmlFor:"schedule-permission-select",children:x("edit.permission")}),(0,r.jsx)("select",{id:"schedule-permission-select","data-testid":"schedule-permission-select",value:b.permission,onChange:e=>v(t=>({...t,permission:e.target.value})),className:lm,children:A.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),er=(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"mb-1 flex items-center justify-between gap-2",children:[(0,r.jsx)("label",{className:"block text-xs font-semibold text-foreground",htmlFor:"schedule-message-input",children:x("edit.message")}),d&&(0,r.jsx)(lx,{testId:"schedule-message-ask-ai",label:x("edit.askAiMessage"),title:x("edit.askAiHint"),onClick:()=>J(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.messageDraft"):e("edit.aiPrompts.messageDraftNamed",{name:"`"+n+"`"})}(x,b.name))})]}),(0,r.jsx)("textarea",{id:"schedule-message-input","data-testid":"schedule-message-input",value:b.message,rows:4,maxLength:1e4,placeholder:x("edit.messagePlaceholder"),onChange:e=>v(t=>({...t,message:e.target.value})),className:"".concat(lm," resize-none")}),(0,r.jsxs)("div",{className:"mt-1 flex items-center justify-between",children:[O?(0,r.jsx)("p",{className:lf,"data-testid":"schedule-message-error",children:O}):(0,r.jsx)("span",{}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"schedule-message-count",children:x("edit.charCount",{count:b.message.length,max:1e4})})]})]}),es=(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsx)(lp,{id:"basic",title:x("edit.sectionBasic"),summary:X,icon:(0,r.jsx)(k.A,{className:"w-4 h-4"}),isOpen:T.has("basic"),onToggle:E,children:en}),(0,r.jsx)(lp,{id:"advanced",title:x("edit.sectionAdvanced"),summary:Z,icon:(0,r.jsx)(s3.A,{className:"w-4 h-4"}),isOpen:T.has("advanced"),onToggle:E,children:ea}),(0,r.jsx)(lp,{id:"message",title:x("edit.sectionMessage"),summary:et,icon:(0,r.jsx)(U.A,{className:"w-4 h-4"}),isOpen:T.has("message"),onToggle:E,children:er}),C&&(0,r.jsx)("div",{className:"text-xs p-2 rounded bg-danger-subtle text-danger-foreground","data-testid":"schedule-submit-error",children:C})]}),el=(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:h,className:"px-4 py-2 text-sm font-medium text-foreground hover:bg-muted rounded-md transition-colors",children:x("edit.cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"schedule-save-button",onClick:()=>void Y(),disabled:!V||w,className:"px-4 py-2 text-sm font-medium text-white bg-accent-600 hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed rounded-md transition-colors",children:x("edit.save")})]}),ei=P?x("edit.titleEdit"):x("edit.titleCreate");return p?(0,r.jsx)(s6,{isOpen:a,onClose:h,title:ei,footer:el,children:es}):(0,r.jsx)(tN.a,{isOpen:a,onClose:h,title:ei,size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[es,(0,r.jsx)("div",{className:"pt-2 border-t border-border",children:el})]})})}function lb(e){return new Date(e).toLocaleString()}function lv(e,t){if(null===t)return null;let n=t-e;if(n<0)return null;let a=Math.floor(n/1e3),r=Math.floor(a/60),s=a%60;return r>0?"".concat(r,"m ").concat(s,"s"):"".concat(s,"s")}let ly=(0,i.memo)(function(e){let{worktreeId:t,logs:n}=e,a=(0,c.c)("schedule"),[s,l]=(0,i.useState)(null),[o,d]=(0,i.useState)(null),u=(0,i.useCallback)(async e=>{if(s===e){l(null),d(null);return}try{let n=await fetch("/api/worktrees/".concat(t,"/execution-logs/").concat(e));if(n.ok){let t=await n.json();d(t.log),l(e)}}catch(e){console.error("Failed to fetch log detail:",e)}},[t,s]);return 0===n.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:a("noLogs")}):(0,r.jsx)("div",{className:"space-y-2","data-testid":"execution-logs-view",children:n.map(e=>(0,r.jsxs)("div",{className:"border border-border rounded bg-surface",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>void u(e.id),className:"w-full text-left p-3 hover:bg-muted transition-colors",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-sm truncate max-w-[60%]",children:e.schedule_name||a("unknownSchedule")}),(0,r.jsx)("span",{className:"text-xs px-2 py-0.5 rounded ".concat(function(e){switch(e){case"completed":return"text-success-foreground bg-success-subtle";case"failed":return"text-danger-foreground bg-danger-subtle";case"timeout":return"text-warning-foreground bg-warning-subtle";case"running":return"text-accent-600 dark:text-accent-400 bg-accent-50 dark:bg-accent-900/30";case"cancelled":return"text-muted-foreground bg-muted"}}(e.status)),children:a("status.".concat(e.status))})]}),(0,r.jsxs)("div",{className:"text-xs text-muted-foreground mt-1",children:[lb(e.started_at),lv(e.started_at,e.completed_at)&&(0,r.jsxs)("span",{className:"ml-2",children:["(",lv(e.started_at,e.completed_at),")"]}),null!==e.exit_code&&(0,r.jsxs)("span",{className:"ml-2",children:[a("exitCode"),": ",e.exit_code]})]})]}),s===e.id&&o&&(0,r.jsxs)("div",{className:"border-t border-border p-3 bg-muted space-y-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-muted-foreground mb-1",children:a("message")}),(0,r.jsx)("pre",{className:"text-xs whitespace-pre-wrap font-mono text-foreground",children:o.message})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-muted-foreground mb-1",children:a("response")}),(0,r.jsx)("pre",{className:"text-xs whitespace-pre-wrap font-mono text-foreground max-h-60 overflow-y-auto",children:o.result||a("noOutput")})]})]})]},e.id))})});function lj(){return(0,r.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 20 20",fill:"currentColor",className:"w-4 h-4",children:(0,r.jsx)("path",{d:"M13.586 3.586a2 2 0 112.828 2.828l-8.5 8.5a1 1 0 01-.43.26l-3 .857a.5.5 0 01-.617-.618l.857-3a1 1 0 01.26-.43l8.5-8.5z"})})}function lw(){return(0,r.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 20 20",fill:"currentColor",className:"w-4 h-4",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M8 2a1 1 0 00-.894.553L6.382 4H3a1 1 0 000 2h.293l.668 9.357A2 2 0 005.956 17h8.088a2 2 0 001.995-1.643L16.707 6H17a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0012 2H8zm1 5a1 1 0 012 0v6a1 1 0 11-2 0V7zm-3 0a1 1 0 011 1v5a1 1 0 11-2 0V8a1 1 0 011-1z",clipRule:"evenodd"})})}let lk=(0,i.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a,instances:s}=e,l=(0,c.c)("schedule"),o=(0,eO.SC)(),[d,u]=(0,i.useState)([]),[h,f]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[g,b]=(0,i.useState)(!0),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)("schedules"),[k,N]=(0,i.useState)(!1),[C,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(void 0),[E,A]=(0,i.useState)(void 0),M=(0,i.useCallback)(async()=>{b(!0),y(null);try{let[e,n,a]=await Promise.all([fetch("/api/worktrees/".concat(t,"/execution-logs")),fetch("/api/worktrees/".concat(t,"/schedules")),fetch("/api/worktrees/".concat(t,"/schedules/active"))]);if(e.ok){let t=await e.json();u(t.logs||[])}if(n.ok){let e=await n.json();f(e.schedules||[])}if(a.ok){let e=await a.json();p(e.schedules||[])}else p([])}catch(e){y(e instanceof Error?e.message:"Failed to fetch data")}finally{b(!1)}},[t]);(0,i.useEffect)(()=>{M()},[M]);let L=(0,i.useCallback)(async e=>{try{var n,a,r,s,l,i,o;let c=await fetch("/api/worktrees/".concat(t,"/files/CMATE.md"));if(!c.ok)return null;let d=await c.json(),u="string"==typeof d.content?d.content:"",m=(null!=(n=(function(e){let t=new Map,n=e.split("\n"),a=null,r=!1,s=!1;for(let e of n){let n=e.trim(),l=n.match(/^##\s+(.+)$/);if(l){a=l[1].trim(),r=!1,s=!1,t.has(a)||t.set(a,[]);continue}if(!n||!n.startsWith("|")||!a)continue;if(!r){r=!0;continue}if(!s){if(n.match(/^\|[\s-:|]+\|$/)){s=!0;continue}s=!0}let i=n.split("|").slice(1,-1).map(e=>e.trim());i.length>0&&t.get(a).push(i)}return t})(u).get("Schedules"))?n:[]).find(t=>{var n;return(null!=(n=t[0])?n:"").trim()===e});if(!m)return null;let h=(0,lc.I_)(null!=(a=m[3])?a:"claude"),f=(null!=(r=m[4])?r:"true").trim().toLowerCase();return{name:e,cronExpression:(null!=(s=m[1])?s:"").trim(),message:(null!=(l=m[2])?l:"").trim(),cliToolId:h.cliToolId||"claude",enabled:""===f||"true"===f,permission:(null!=(i=m[5])?i:"").trim(),model:null!=(o=h.model)?o:""}}catch(e){return null}},[t]),R=(0,i.useCallback)(()=>{A(void 0),I(void 0),S(!0)},[]),P=(0,i.useCallback)(async e=>{let t=await L(e.name);A(e.name),I(null!=t?t:{name:e.name,cronExpression:e.cron_expression,message:e.message,cliToolId:e.cli_tool_id,enabled:1===e.enabled,permission:"",model:""}),S(!0)},[L]),D=(0,i.useCallback)(async e=>{if(await o({description:l("edit.confirmDelete",{name:e}),variant:"danger"}))try{(await fetch("/api/worktrees/".concat(t,"/cmate/schedules"),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})})).ok&&await M()}catch(e){console.error("Failed to delete schedule:",e)}},[t,l,M,o]),F=(0,i.useCallback)(async e=>{try{(await fetch("/api/worktrees/".concat(t,"/cmate/schedules"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.name,enabled:1!==e.enabled})})).ok&&await M()}catch(e){console.error("Failed to toggle schedule:",e)}},[t,M]);return g?(0,r.jsx)("div",{className:"flex items-center justify-center h-full p-4 ".concat(n),children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,r.jsx)(m.y$,{size:"xl",variant:"accent"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:l("loading")})]})}):v?(0,r.jsx)("div",{className:"flex items-center justify-center h-full p-4 ".concat(n),children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("span",{className:"text-sm text-danger-foreground",children:v}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>void M(),className:"ml-2 px-3 py-1 text-sm text-white bg-accent-500 rounded hover:bg-accent-600",children:l("retry")})]})}):(0,r.jsxs)("div",{className:"flex flex-col h-full ".concat(n),children:[(0,r.jsxs)("div",{className:"flex shrink-0 border-b border-border px-4 pt-3",children:[(0,r.jsxs)("button",{type:"button","data-testid":"schedule-tab-schedules",role:"tab","aria-selected":"schedules"===j,onClick:()=>w("schedules"),className:"-mb-px px-3 py-2 text-sm font-medium border-b-2 transition-colors ".concat("schedules"===j?"border-accent-500 text-accent-700 dark:text-accent-300":"border-transparent text-muted-foreground hover:text-foreground"),children:[l("tabs.schedules")," (",h.length,")"]}),(0,r.jsxs)("button",{type:"button","data-testid":"schedule-tab-logs",role:"tab","aria-selected":"logs"===j,onClick:()=>w("logs"),className:"-mb-px px-3 py-2 text-sm font-medium border-b-2 transition-colors ".concat("logs"===j?"border-accent-500 text-accent-700 dark:text-accent-300":"border-transparent text-muted-foreground hover:text-foreground"),children:[l("tabs.logs")," (",d.length,")"]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:"schedules"===j?(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"rounded border border-accent-100 bg-accent-50/60 p-3 dark:border-accent-900/40 dark:bg-accent-950/20",children:[(0,r.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,r.jsxs)("span",{className:"text-sm font-semibold text-accent-900 dark:text-accent-200",children:[l("activeSchedulesTitle")," (",x.length,")"]}),(0,r.jsx)("span",{className:"text-xs text-accent-700 dark:text-accent-300",children:l("activeSchedulesDescription")})]}),0===x.length?(0,r.jsx)("p",{className:"text-xs text-accent-800 dark:text-accent-300",children:l("noActiveSchedules")}):(0,r.jsx)("div",{className:"space-y-2",children:x.map(e=>(0,r.jsxs)("div",{className:"rounded border border-accent-200/80 bg-white/80 p-3 dark:border-accent-900/40 dark:bg-surface/60",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"font-medium text-sm text-foreground",children:e.name}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs px-2 py-0.5 rounded ".concat(e.isCronActive?"bg-success-subtle text-success-foreground":"bg-danger-subtle text-danger-foreground"),children:e.isCronActive?l("activeState.active"):l("activeState.inactive")}),e.isExecuting&&(0,r.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-accent-100 text-accent-700 dark:bg-accent-900/30 dark:text-accent-300",children:l("activeState.executing")})]})]}),(0,r.jsxs)("div",{className:"mt-1 text-xs text-muted-foreground",children:[(0,r.jsxs)("span",{children:[l("cron"),": ",e.cronExpression||"N/A"]}),(0,r.jsxs)("span",{className:"ml-3",children:[l("agentLabel"),": ",e.cliToolId]}),e.model&&(0,r.jsxs)("span",{className:"ml-3",children:["model: ",e.model]}),e.nextRunAt&&(0,r.jsxs)("span",{className:"ml-3",children:[l("nextRun"),": ",lb(e.nextRunAt)]})]})]},e.scheduleId))})]}),0===h.length?(0,r.jsxs)("div",{className:"flex flex-col items-center text-center py-8 px-4",children:[(0,r.jsx)("div",{className:"mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-accent-50 text-accent-600 dark:bg-accent-900/30 dark:text-accent-300",children:(0,r.jsxs)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",className:"w-7 h-7",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 7.5V12l3 2"})]})}),(0,r.jsx)("p",{className:"font-semibold text-foreground mb-1",children:l("emptyState.title")}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground mb-5 max-w-xs",children:l("emptyState.description")}),(0,r.jsxs)(m.$n,{variant:"ghost",type:"button","data-testid":"schedule-empty-cta",onClick:R,className:"inline-flex items-center gap-1.5 px-5 py-2.5 text-sm font-semibold text-white bg-accent-600 hover:bg-accent-700 rounded-lg shadow-sm transition-colors",children:[(0,r.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 20 20",fill:"currentColor",className:"w-4 h-4",children:(0,r.jsx)("path",{d:"M10 4a1 1 0 011 1v4h4a1 1 0 110 2h-4v4a1 1 0 11-2 0v-4H5a1 1 0 110-2h4V5a1 1 0 011-1z"})}),l("emptyState.createButton")]}),(0,r.jsx)("button",{type:"button","data-testid":"schedule-manual-toggle","aria-expanded":k,onClick:()=>N(e=>!e),className:"mt-5 text-xs text-accent-700 dark:text-accent-300 hover:underline",children:l("emptyState.manualToggle")}),k&&(0,r.jsxs)("ol",{"data-testid":"schedule-manual-steps",className:"mt-3 text-xs text-left inline-block space-y-1.5 list-decimal list-inside text-muted-foreground",children:[(0,r.jsx)("li",{children:l("noSchedulesStep1")}),(0,r.jsx)("li",{children:l("noSchedulesStep2")}),(0,r.jsx)("li",{children:l("noSchedulesStep3")}),(0,r.jsx)("li",{children:l("noSchedulesStep4")})]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"mb-2 flex items-center justify-end",children:(0,r.jsxs)(m.$n,{variant:"ghost",type:"button","data-testid":"schedule-new-button",onClick:R,className:"inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-white bg-accent-600 hover:bg-accent-700 rounded transition-colors whitespace-nowrap",children:[(0,r.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 20 20",fill:"currentColor",className:"w-3.5 h-3.5",children:(0,r.jsx)("path",{d:"M10 4a1 1 0 011 1v4h4a1 1 0 110 2h-4v4a1 1 0 11-2 0v-4H5a1 1 0 110-2h4V5a1 1 0 011-1z"})}),l("edit.newSchedule")]})}),(0,r.jsx)("div",{className:"space-y-2",children:h.map(e=>{let t=1===e.enabled;return(0,r.jsxs)("div",{className:"border border-border rounded p-3 bg-white dark:bg-surface",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"font-medium text-sm truncate",children:e.name}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":t,"aria-label":t?l("edit.disable"):l("edit.enable"),title:t?l("edit.disable"):l("edit.enable"),"data-testid":"schedule-toggle-".concat(e.name),onClick:()=>void F(e),className:"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors ".concat(t?"bg-success":"bg-input"),children:(0,r.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ".concat(t?"translate-x-4":"translate-x-0.5")})}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button","data-testid":"schedule-edit-".concat(e.name),"aria-label":l("edit.edit"),title:l("edit.edit"),onClick:()=>void P(e),className:"p-1.5 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 hover:bg-accent-50 dark:hover:bg-accent-900/20 rounded transition-colors",children:(0,r.jsx)(lj,{})}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button","data-testid":"schedule-delete-".concat(e.name),"aria-label":l("edit.delete"),title:l("edit.delete"),onClick:()=>void D(e.name),className:"p-1.5 text-muted-foreground hover:text-danger-foreground hover:bg-danger-subtle rounded transition-colors",children:(0,r.jsx)(lw,{})})]})]}),(0,r.jsxs)("div",{className:"text-xs text-muted-foreground mt-1",children:[(0,r.jsxs)("span",{children:[l("cron"),": ",e.cron_expression||"N/A"]}),e.last_executed_at&&(0,r.jsxs)("span",{className:"ml-3",children:[l("lastRun"),": ",lb(e.last_executed_at)]})]})]},e.id)})})]})]}):(0,r.jsx)(ly,{worktreeId:t,logs:d})}),(0,r.jsx)(lg,{isOpen:C,worktreeId:t,initialValues:T,originalName:E,onInsertToMessage:a,instances:s,onClose:()=>S(!1),onSaved:()=>{M()}})]})}),lN=(0,i.memo)(function(e){let{worktreeId:t,vibeLocalModel:n,onVibeLocalModelChange:a,vibeLocalContextWindow:s,onVibeLocalContextWindowChange:l}=e,o=(0,c.c)("schedule"),[d,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)(!1),[v,y]=(0,i.useState)(null!=s?String(s):""),[j,w]=(0,i.useState)(!1);(0,i.useEffect)(()=>{y(null!=s?String(s):"")},[s]),(0,i.useEffect)(()=>{let e=!1;return p(!0),fetch("/api/ollama/models").then(e=>e.json()).then(t=>{e||(m(t.models),f(0===t.models.length&&t.error?t.error:null))}).catch(()=>{e||(m([]),f("Failed to fetch models"))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let k=(0,i.useCallback)(async e=>{let n=e.target.value,r=""===n?null:n;b(!0);try{(await fetch("/api/worktrees/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({vibeLocalModel:r})})).ok&&a(r)}catch(e){}finally{b(!1)}},[t,a]),N=(0,i.useCallback)(e=>{y(e.target.value)},[]),C=(0,i.useCallback)(async()=>{let e=v.trim(),n=parseInt(e,10),a=""===e||Number.isNaN(n)?null:n,r=null!=s?s:null;if(a!==r){w(!0);try{(await fetch("/api/worktrees/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({vibeLocalContextWindow:a})})).ok?null==l||l(a):y(null!=r?String(r):"")}catch(e){y(null!=r?String(r):"")}finally{w(!1)}}},[v,s,t,l]);return(0,r.jsxs)("div",{className:"mt-4 pt-4 border-t border-border",children:[(0,r.jsx)("h4",{className:"text-sm font-semibold text-foreground mb-2",children:o("vibeLocalModel")}),x?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.y,{size:"xs",variant:"muted"}),o("loading")]}):h&&0===d.length?(0,r.jsx)("p",{className:"text-xs text-warning-foreground",children:o("ollamaNotAvailable")}):(0,r.jsxs)("select",{"data-testid":"vibe-local-model-select",value:null!=n?n:"",onChange:k,disabled:g,className:"w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50",children:[(0,r.jsx)("option",{value:"",children:o("vibeLocalModelDefault")}),d.map(e=>(0,r.jsxs)("option",{value:e.name,children:[e.name,e.parameterSize?" (".concat(e.parameterSize,")"):""]},e.name))]}),(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("h4",{className:"text-sm font-semibold text-foreground mb-2",children:o("vibeLocalContextWindow")}),(0,r.jsx)("input",{type:"number","data-testid":"vibe-local-context-window-input",step:"1",min:q.vz,max:q.NL,value:v,onChange:N,onBlur:C,placeholder:o("vibeLocalContextWindowDefault"),disabled:j,className:"w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50"})]})]})}),lC=Object.freeze({agent:null,providerId:null,modelId:null,variant:null}),lS=[{id:"opencode",label:(0,q.oo)("opencode")}];function lT(e){let t=e.indexOf("/");return t<=0||t===e.length-1?null:{providerId:e.slice(0,t),modelId:e.slice(t+1)}}let lI=(0,i.memo)(function(e){let{worktreeId:t,instances:n}=e,a=(0,c.c)("schedule"),[s,l]=(0,i.useState)({}),[o,d]=(0,i.useState)({connected:!1,providers:[],agents:[]}),[u,h]=(0,i.useState)(!0),[f,x]=(0,i.useState)(!1),[p,g]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=!1;return h(!0),fetch("/api/worktrees/".concat(t,"/instances/opencode")).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{var n,a;e||(l(null!=(n=t.settings)?n:{}),d(null!=(a=t.catalog)?a:{connected:!1,providers:[],agents:[]}),g(null))}).catch(()=>{e||g(a("opencodeSettingsLoadError"))}).finally(()=>{e||h(!1)}),()=>{e=!0}},[t,a]);let b=(0,i.useCallback)(async(e,n)=>{l(t=>({...t,[e]:n})),x(!0),g(null);try{let r=await fetch("/api/worktrees/".concat(t,"/instances/opencode"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({instanceId:e,...n})});if(!r.ok)return void g(a("opencodeSettingsSaveError"));let s=await r.json();s.settings&&l(t=>({...t,[e]:s.settings}))}catch(e){g(a("opencodeSettingsSaveError"))}finally{x(!1)}},[t,a]);return(0,r.jsxs)("div",{className:"mt-4 pt-4 border-t border-border","data-testid":"opencode-instance-settings",children:[(0,r.jsx)("h4",{className:"text-sm font-semibold text-foreground mb-1",children:a("opencodeSettings")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-3",children:a("opencodeSettingsDescription")}),u?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(m.y$,{size:"xs",variant:"muted"}),a("loading")]}):(0,r.jsxs)("div",{className:"space-y-4",children:[!o.connected&&(0,r.jsx)("p",{"data-testid":"opencode-settings-offline",className:"text-xs text-muted-foreground",children:a("opencodeSettingsOffline")}),n.map(e=>{var t,l,i,c,d,u;let m=null!=(t=s[e.id])?t:{...lC},h=m.providerId&&m.modelId?"".concat(m.providerId,"/").concat(m.modelId):"",x=function(e,t){var n;if(!t.providerId||!t.modelId)return null;let a=e.providers.find(e=>e.id===t.providerId);return null!=(n=null==a?void 0:a.models.find(e=>e.id===t.modelId))?n:null}(o,m),p=null!=(l=null==x?void 0:x.variants)?l:[],g=o.agents.filter(e=>"primary"===e.mode);return(0,r.jsxs)("div",{className:"space-y-2",children:[n.length>1&&(0,r.jsx)("p",{className:"text-xs font-medium text-foreground",children:e.label}),(0,r.jsxs)("label",{className:"block text-xs text-muted-foreground",children:[a("opencodeAgent"),g.length>0?(0,r.jsxs)("select",{"data-testid":"opencode-agent-select-".concat(e.id),value:null!=(i=m.agent)?i:"",disabled:f,onChange:t=>void b(e.id,{...m,agent:""===t.target.value?null:t.target.value}),className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50",children:[(0,r.jsx)("option",{value:"",children:a("opencodeDefault")}),g.map(e=>(0,r.jsx)("option",{value:e.name,children:e.name},e.name))]}):(0,r.jsx)("input",{type:"text","data-testid":"opencode-agent-input-".concat(e.id),defaultValue:null!=(c=m.agent)?c:"",disabled:f,placeholder:a("opencodeAgentPlaceholder"),onBlur:t=>void b(e.id,{...m,agent:""===t.target.value.trim()?null:t.target.value.trim()}),className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50"})]}),(0,r.jsxs)("label",{className:"block text-xs text-muted-foreground",children:[a("opencodeModel"),o.providers.length>0?(0,r.jsxs)("select",{"data-testid":"opencode-model-select-".concat(e.id),value:h,disabled:f,onChange:t=>{var n,a;let r=lT(t.target.value);b(e.id,{...m,providerId:null!=(n=null==r?void 0:r.providerId)?n:null,modelId:null!=(a=null==r?void 0:r.modelId)?a:null,variant:null})},className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50",children:[(0,r.jsx)("option",{value:"",children:a("opencodeDefault")}),o.providers.map(e=>(0,r.jsx)("optgroup",{label:e.name,children:e.models.map(t=>(0,r.jsx)("option",{value:"".concat(e.id,"/").concat(t.id),children:t.name},t.id))},e.id))]}):(0,r.jsx)("input",{type:"text","data-testid":"opencode-model-input-".concat(e.id),defaultValue:h,disabled:f,placeholder:a("opencodeModelPlaceholder"),onBlur:t=>{var n,a;let r=lT(t.target.value.trim());b(e.id,{...m,providerId:null!=(n=null==r?void 0:r.providerId)?n:null,modelId:null!=(a=null==r?void 0:r.modelId)?a:null})},className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50"})]}),(0,r.jsxs)("label",{className:"block text-xs text-muted-foreground",children:[a("opencodeVariant"),p.length>0?(0,r.jsxs)("select",{"data-testid":"opencode-variant-select-".concat(e.id),value:null!=(d=m.variant)?d:"",disabled:f,onChange:t=>void b(e.id,{...m,variant:""===t.target.value?null:t.target.value}),className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50",children:[(0,r.jsx)("option",{value:"",children:a("opencodeDefault")}),p.map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}):(0,r.jsx)("input",{type:"text","data-testid":"opencode-variant-input-".concat(e.id),defaultValue:null!=(u=m.variant)?u:"",disabled:f,placeholder:a("opencodeVariantPlaceholder"),onBlur:t=>void b(e.id,{...m,variant:""===t.target.value.trim()?null:t.target.value.trim()}),className:"mt-1 w-full text-sm border border-input rounded-md px-3 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50"})]}),x&&0===p.length&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:a("opencodeNoVariants")})]},e.id)}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:a("opencodeVariantLaunchNote")}),f&&(0,r.jsxs)("div",{"data-testid":"opencode-settings-loading",className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(m.y$,{size:"xs",variant:"muted"}),a("loading")]}),p&&(0,r.jsx)("p",{"data-testid":"opencode-settings-error",className:"text-xs text-danger-foreground",children:p})]})]})}),lE=(0,i.memo)(function(e){let{worktreeId:t,selectedAgents:n,onSelectedAgentsChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:d,maxAgents:u=2,availableAgents:h=q.XH,persistToServer:f=!0}=e,x=(0,c.c)("schedule"),p=n.length>u?n.slice(0,u):n,[g,b]=(0,i.useState)(()=>new Set(p)),[v,y]=(0,i.useState)(!1),[j,w]=(0,i.useState)(!1),k=(0,i.useRef)(g);k.current=g,(0,i.useEffect)(()=>{j||b(new Set(p))},[n,j,u]);let N=g.has("vibe-local"),C=g.has("opencode"),S=(0,i.useCallback)(async(e,n)=>{let r=new Set(k.current);if(n?r.add(e):(r.delete(e),w(!0)),b(r),r.size>=2){let e=Array.from(r);if(!f){b(new Set(e)),a(e),w(!1);return}y(!0);try{(await fetch("/api/worktrees/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({selectedAgents:e})})).ok?(b(new Set(e)),a(e)):b(new Set(p))}catch(e){b(new Set(p))}finally{y(!1),w(!1)}}},[t,p,a,f]),T=g.size>=u;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground mb-1",children:x("agentSettings")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:x("selectAgents")}),(0,r.jsx)("div",{className:"space-y-3",children:h.map(e=>{let t=g.has(e),n=!t&&T;return(0,r.jsxs)("label",{className:"flex items-center gap-3 p-2 rounded-lg border transition-colors ".concat(t?"border-accent-200 dark:border-accent-700 bg-accent-50 dark:bg-accent-900/30":n?"border-border bg-muted opacity-50":"border-border hover:border-input hover:bg-muted"),children:[(0,r.jsx)(m.Sc,{"data-testid":"agent-checkbox-".concat(e),"aria-label":(0,q.oo)(e),checked:t,disabled:n||v,onCheckedChange:t=>S(e,!0===t)}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:(0,q.oo)(e)})]},e)})}),v&&(0,r.jsxs)("div",{"data-testid":"agent-settings-loading",className:"mt-3 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(m.y$,{size:"xs",variant:"muted"}),x("loading")]}),C&&(0,r.jsx)(lI,{worktreeId:t,instances:lS}),N&&(0,r.jsx)(lN,{worktreeId:t,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:d})]})});function lA(e){return"".concat("commandmate:worktree:mobileInstances:").concat(e)}function lM(e,t){if(0===t.length)return[];if(null!==e){let n=new Set(e),a=t.filter(e=>n.has(e.id));if(a.length>0)return a}return[...t]}var lL=n(49476),lR=n(52056),lP=n(65506),lD=n(50803),lF=n(20017),lO=n(18085),lz=n(6191),l_=n(63001),lB=n(55449);let lH="/api/worktrees/apply-default-agents";var lV=n(18848);let lU=["noteInstanceFlag","noteWaitOnPrompt","noteRespondNumber"];function lK(e){let{worktreeId:t,instance:n,isOpen:a,onClose:s}=e,l=(0,c.c)("worktree"),[o,d]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[f,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),[b,v]=(0,i.useState)(null),[y,j]=(0,i.useState)(!1),[w,k]=(0,i.useState)(0);(0,i.useEffect)(()=>{if(!a)return;let e=!1;return d(!0),h(!1),v(null),j(!1),(async()=>{try{let[a,r]=await Promise.all([fetch("/api/worktrees/".concat(t,"/cli-reference")),fetch("/api/worktrees/".concat(t,"/resolve-target?instance=").concat(encodeURIComponent(n.id)))]);if(e)return;if(!a.ok||!r.ok)return void h(!0);let[s,l]=await Promise.all([a.json(),r.json()]);if(e)return;x(s),g(l)}catch(t){e||h(!0)}finally{e||d(!1)}})(),()=>{e=!0}},[a,t,n.id,w]);let N=f&&p?(0,lV.kj)({binary:f.binary,worktreeId:f.worktreeId,instanceId:p.instanceId,portPrefix:f.portPrefix,messagePlaceholder:l("cliCommands.messagePlaceholder")}):null,C=(0,i.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(t),v(e),j(!1)}catch(e){console.error("[InstanceCliCommandsModal] clipboard write failed:",e),v(null),j(!0)}},[]);return(0,r.jsx)(tN.a,{isOpen:a,onClose:s,size:"md",title:l("cliCommands.title",{alias:n.alias}),children:(0,r.jsxs)("div",{className:"space-y-4","data-testid":"cli-commands-panel-".concat(n.id),children:[o&&(0,r.jsxs)("div",{"data-testid":"cli-commands-loading",className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.y,{size:"xs",variant:"muted"}),l("cliCommands.loading")]}),m&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("p",{"data-testid":"cli-commands-error",className:"text-xs text-danger-foreground",children:l("cliCommands.loadError")}),(0,r.jsx)("button",{type:"button","data-testid":"cli-commands-retry",onClick:()=>k(e=>e+1),className:"text-xs font-medium px-2 py-1 rounded-md border border-input text-foreground hover:bg-muted",children:l("cliCommands.retry")})]}),N&&p&&f&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{"data-testid":"cli-commands-target",className:"text-xs text-muted-foreground break-words",children:l("cliCommands.target",{instance:p.instanceId,tool:(0,q.oo)(p.cliToolId),stage:l("cliCommands.resolvedBy.".concat(p.resolvedBy))})}),p.conflict&&(0,r.jsxs)("p",{"data-testid":"cli-commands-conflict",className:"flex items-start gap-1 text-xs text-warning",children:[(0,r.jsx)(lR.A,{className:"w-3 h-3 mt-0.5 shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:l("cliCommands.conflict",{instance:p.conflict.instanceId,roster:(0,q.oo)(p.conflict.rosterCliTool),requested:(0,q.oo)(p.conflict.requestedCliTool)})})]}),(0,r.jsx)("ul",{className:"space-y-3",children:lV.wx.map(e=>(0,r.jsxs)("li",{className:"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-semibold text-foreground",children:l("cliCommands.commandLabel.".concat(e))}),(0,r.jsxs)("button",{type:"button","data-testid":"cli-commands-copy-".concat(e),"aria-label":l("cliCommands.copy"),title:l("cliCommands.copy"),onClick:()=>void C(e,N[e]),className:"flex items-center gap-1 shrink-0 text-xs px-2 py-1 rounded-md border border-input text-muted-foreground hover:text-foreground hover:bg-muted",children:[b===e?(0,r.jsx)(ey.A,{className:"w-3 h-3","aria-hidden":"true"}):(0,r.jsx)(ej.A,{className:"w-3 h-3","aria-hidden":"true"}),b===e?l("cliCommands.copied"):l("cliCommands.copy")]})]}),(0,r.jsx)("code",{"data-testid":"cli-commands-command-".concat(e),className:"block whitespace-pre-wrap break-all rounded-md bg-terminal-surface px-2 py-1.5 font-mono text-xs text-terminal-foreground",children:N[e]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:l("cliCommands.commandDescription.".concat(e))})]},e))}),y&&(0,r.jsx)("p",{"data-testid":"cli-commands-copy-error",className:"text-xs text-danger-foreground",children:l("cliCommands.copyFailed")}),null!==f.portPrefix&&(0,r.jsx)("p",{"data-testid":"cli-commands-port-hint",className:"text-xs text-muted-foreground",children:l("cliCommands.portHint",{port:f.portPrefix})}),(0,r.jsxs)("div",{className:"rounded-md border border-border bg-surface-2 p-3",children:[(0,r.jsx)("p",{className:"text-xs font-semibold text-foreground",children:l("cliCommands.notesTitle")}),(0,r.jsx)("ul",{className:"mt-1 space-y-1",children:lU.map(e=>(0,r.jsx)("li",{"data-testid":"cli-commands-".concat(e),className:"text-xs text-muted-foreground",children:l("cliCommands.".concat(e))},e))})]})]})]})})}var lW=n(46022),l$=n(45573);function lq(e){return"prompt"===e.tone?"text-warning":"text-muted-foreground"}let lG=(0,i.memo)(function(e){var t;let{worktreeId:n,instances:a,onInstancesChange:s,vibeLocalModel:l,onVibeLocalModelChange:o,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:m,modelByInstance:h,sourceByInstance:f,composerTargetInstanceId:x,className:p=""}=e,g=(0,c.c)("schedule"),b=(0,to.Ym)(),{showToast:v}=(0,tu.dj)(),y=(0,c.c)("common"),j=(0,c.c)("worktree"),w=(0,eO.SC)(),[k,N]=(0,i.useState)(!1),[C,S]=(0,i.useState)(null),[T,I]=(0,i.useState)({}),[E,A]=(0,i.useState)(q.XH[0]),[M,L]=(0,i.useState)(null),[R,P]=(0,i.useState)(!1),[D,F]=(0,i.useState)(!1),[O,z]=(0,i.useState)(null),_=(0,i.useCallback)(async e=>{let t=l$.yW["ja"===b?"ja":"en"];if((null!=x?x:(0,l$.xk)())===e.id)return void v(t.self,"info");let a=await (0,l$.P0)(n,e,b);if(null===a)return void v(t.failed,"error");let r=(0,l$.oQ)(a);v(r?t.inserted:t.noComposer,r?"success":"error")},[x,b,v,n]),B=function(e,t,n){let[a,r]=(0,i.useState)({}),s=t.some(e=>"opencode"===e.cliTool);return(0,i.useEffect)(()=>{if(n)return;if(!s)return void r({});let t=!1,a=async()=>{try{var n;let a=await fetch("/api/worktrees/".concat(e));if(!a.ok)return;let s=await a.json();if(t)return;let l={};for(let[e,t]of Object.entries(null!=(n=s.sessionStatusByInstance)?n:{}))(null==t?void 0:t.eventSource)&&(l[e]=t.eventSource);r(l)}catch(e){}};a();let l=setInterval(()=>void a(),1e4);return()=>{t=!0,clearInterval(l)}},[e,s,n]),null!=n?n:a}(n,a,f),H=nA(n),V=(0,i.useCallback)(e=>{var t,r;return e.worktreeId!==n?"".concat(e.instanceId," @ ").concat(e.worktreeId):null!=(r=null==(t=a.find(t=>t.id===e.instanceId))?void 0:t.alias)?r:e.instanceId},[a,n]),U=a.length>=q.Ab,W=a.length<=1,$=a.some(e=>"vibe-local"===e.cliTool),G=(0,i.useMemo)(()=>{let e=new Set,t=[];for(let n of a)e.has(n.cliTool)||(e.add(n.cliTool),t.push(n.cliTool));return t},[a]),Y=function(e,t){let[n,a]=(0,i.useState)(null),[r,s]=(0,i.useState)(null),[l,o]=(0,i.useState)(!1),[c,d]=(0,i.useState)(!1),[u,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),g=(0,i.useCallback)(e=>{s("string"==typeof(null==e?void 0:e.repositoryName)?e.repositoryName:null),o((null==e?void 0:e.repoDeclaresAgents)===!0)},[]),b=(0,i.useCallback)(async()=>{d(!0);try{let t=await fetch("".concat(lH,"?worktreeId=").concat(encodeURIComponent(e)));if(!t.ok)throw Error(String(t.status));let n=await t.json(),r=null==n?void 0:n.eligible;if("number"!=typeof r||!Number.isFinite(r))throw Error("unexpected body");return a(r),g(n),p(null),r}catch(e){return a(null),p("count"),null}finally{d(!1)}},[e,g]),v=(0,i.useCallback)(async()=>{d(!0),p(null),m(!1),f(null);try{let e=await fetch(lB.zk,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({agents:t})}),n=await e.json().catch(()=>null),a=null==n?void 0:n.defaultSelectedAgents;if(!e.ok||!Array.isArray(a))return p("save"),!1;return(0,lB.IK)(a),m(!0),!0}catch(e){return p("save"),!1}finally{d(!1)}},[t]),y=(0,i.useCallback)(async()=>{d(!0),p(null),m(!1);try{let n=await fetch(lH,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({worktreeId:e,agents:t})}),r=await n.json().catch(()=>null),s=null==r?void 0:r.updated;if(!n.ok||"number"!=typeof s||!Number.isFinite(s))return p("apply"),null;f(s),g(r);let l=r.eligible;return"number"==typeof l&&Number.isFinite(l)&&a(l),s}catch(e){return p("apply"),null}finally{d(!1)}},[e,t,g]);return{eligible:n,repositoryName:r,repoDeclaresAgents:l,busy:c,savedDefault:u,appliedCount:h,error:x,refreshEligible:b,saveAsDefault:v,applyToUnchanged:y}}(n,G),Q=G.length>=l_.eu&&G.length<=l_.Wj,X=k||Y.busy,Z=Q&&!Y.repoDeclaresAgents&&null!==Y.eligible&&Y.eligible>0,ee="count"===Y.error?g("agentDefaultsCountError"):"save"===Y.error?g("agentDefaultsSaveError"):"apply"===Y.error?g("agentDefaultsApplyError"):null,et=(0,i.useCallback)(()=>{let e=!D;F(e),e&&Y.refreshEligible()},[D,Y]),en=(0,i.useCallback)(async()=>{if(!Z)return;let e=await Y.refreshEligible();null!==e&&0!==e&&await w({description:g("agentDefaultsApplyConfirm",{count:e,agents:G.map(e=>(0,q.oo)(e)).join(", ")})})&&await Y.applyToUnchanged()},[Z,Y,w,g,G]),ea=(0,i.useCallback)(async e=>{let t=e.map((e,t)=>({...e,order:t}));N(!0),S(null);try{(await fetch("/api/worktrees/".concat(n),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentInstances:t})})).ok?s(t):S(g("agentInstanceSaveError"))}catch(e){S(g("agentInstanceSaveError"))}finally{N(!1)}},[n,s,g]),er=(0,i.useCallback)(()=>{if(a.length>=q.Ab)return;let e=function(e,t){let n=new Set(t.map(e=>e.id));if(!n.has(e))return e;let a=2;for(;n.has("".concat(e,"-").concat(a));)a++;return"".concat(e,"-").concat(a)}(E,a);ea([...a,{id:e,cliTool:E,alias:function(e,t){let n=(0,q.oo)(e);if(t===e)return n;let a=t.slice(e.length+1);return a?"".concat(n," ").concat(a):n}(E,e),order:a.length}])},[E,a,ea]),es=(0,i.useCallback)(async e=>{var t;if(a.length<=1)return;let n=a.find(t=>t.id===e);await w({description:y("confirmDelete",{name:null!=(t=null==n?void 0:n.alias)?t:""}),variant:"danger"})&&ea(a.filter(t=>t.id!==e))},[a,ea,w,y]),el=(0,i.useCallback)((e,t)=>{let n=e+t;if(n<0||n>=a.length)return;let r=[...a];[r[e],r[n]]=[r[n],r[e]],ea(r)},[a,ea]),ei=(0,i.useCallback)((e,t)=>{I(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n});let n=a.find(t=>t.id===e);n&&t!==n.alias&&ea(a.map(n=>n.id===e?{...n,alias:t}:n))},[a,ea]),eo=(0,i.useCallback)((e,t)=>{if(e===t||e<0||t<0||e>=a.length||t>=a.length)return;let n=[...a],[r]=n.splice(e,1);n.splice(t,0,r),ea(n)},[a,ea]),ec=["flex flex-col p-4",p?"overflow-y-auto":"",p].filter(Boolean).join(" ");return(0,r.jsxs)("div",{className:ec,"data-testid":"agent-instances-pane",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground mb-1",children:g("agentInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:g("agentInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-2",children:a.map((e,t)=>{var s,l;let i=e.id in T?T[e.id]:e.alias,o=M===t,c=null!=(s=null==h?void 0:h[e.id])?s:null,d=null==B?void 0:B[e.id],u=cl(d,j),m=!!(l=d)&&("sse"!==l.kind||"live"!==l.liveness),f=nM({owed:H.owedBy(e.id),awaiting:H.awaitedBy(e.id),aliasOf:V}),p=x===e.id;return(0,r.jsxs)("div",{"data-testid":"agent-instance-row-".concat(e.id),draggable:!0,onDragStart:()=>L(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{null!==M&&eo(M,t),L(null)},onDragEnd:()=>L(null),className:"flex items-center gap-2 p-2 rounded-lg border border-border bg-surface transition-colors hover:border-accent-300 dark:hover:border-accent-700 focus-within:border-accent-500 ".concat(o?"opacity-50":""),children:[(0,r.jsx)("span",{className:"cursor-grab text-muted-foreground shrink-0","aria-hidden":"true",children:(0,r.jsx)(lL.A,{className:"w-4 h-4"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("input",{type:"text","data-testid":"agent-instance-alias-".concat(e.id),"aria-label":g("agentInstanceAliasLabel"),value:i,maxLength:q.pQ,disabled:k,placeholder:g("agentInstanceAliasPlaceholder"),onChange:t=>I(n=>({...n,[e.id]:t.target.value})),onBlur:t=>ei(e.id,t.target.value),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||e.currentTarget.blur()},className:"w-full text-sm font-medium border border-input rounded-md px-2 py-1 bg-surface dark:bg-surface-2 text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50"}),(0,r.jsx)(sk.nR,{content:(0,q.oo)(e.cliTool),className:"mt-0.5 block truncate text-xs text-muted-foreground"}),c&&(0,r.jsx)("span",{"data-testid":"agent-instance-model-".concat(e.id),title:j("agentModel.modelLabel",{model:c}),className:"mt-0.5 block truncate text-xs text-muted-foreground",children:c}),u&&(0,r.jsxs)("span",{"data-testid":"agent-instance-source-".concat(e.id),title:j(m?"agentSource.degradedTitle":"agentSource.healthyTitle"),className:"mt-0.5 flex items-center gap-1 truncate text-xs ".concat(m?"text-warning":"text-muted-foreground"),children:[m?(0,r.jsx)(lR.A,{className:"w-3 h-3 shrink-0","aria-hidden":"true"}):(0,r.jsx)(lP.A,{className:"w-3 h-3 shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"truncate",children:u})]}),f.map(t=>(0,r.jsxs)("span",{"data-testid":"agent-instance-relay-".concat(t.tone,"-").concat(e.id),title:j("relay.".concat(t.titleKey)),className:"mt-0.5 flex items-center gap-1 truncate text-xs ".concat(lq(t)),children:[(0,r.jsx)(nk.A,{className:"w-3 h-3 shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"truncate",children:j("relay.".concat(t.key),t.params)})]},t.key))]}),(0,r.jsx)("button",{type:"button","data-testid":"agent-instance-cli-".concat(e.id),"aria-label":j("cliCommands.open"),title:j("cliCommands.open"),onClick:()=>z(e.id),className:"shrink-0 p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted",children:(0,r.jsx)(lD.A,{className:"w-4 h-4"})}),O===e.id&&(0,r.jsx)(lK,{worktreeId:n,instance:e,isOpen:!0,onClose:()=>z(null)}),(0,r.jsxs)(J.rI,{children:[(0,r.jsx)(J.ty,{asChild:!0,children:(0,r.jsx)("button",{type:"button","data-testid":"agent-instance-menu-".concat(e.id),"aria-label":g("agentInstanceActions"),title:g("agentInstanceActions"),disabled:k,className:"shrink-0 p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed",children:(0,r.jsx)(lF.A,{className:"w-4 h-4"})})}),(0,r.jsxs)(J.SQ,{align:"end",children:[!p&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(J._2,{"data-testid":"agent-instance-delegate-".concat(e.id),onSelect:()=>{_(e)},children:[(0,r.jsx)(lO.A,{className:"w-4 h-4"}),l$.yW["ja"===b?"ja":"en"].menuItem]}),(0,r.jsx)(J.mB,{})]}),(0,r.jsxs)(J._2,{"data-testid":"agent-instance-move-up-".concat(e.id),disabled:0===t,onSelect:()=>el(t,-1),children:[(0,r.jsx)(sq.A,{className:"w-4 h-4"}),g("agentInstanceMoveUp")]}),(0,r.jsxs)(J._2,{"data-testid":"agent-instance-move-down-".concat(e.id),disabled:t===a.length-1,onSelect:()=>el(t,1),children:[(0,r.jsx)(K.A,{className:"w-4 h-4"}),g("agentInstanceMoveDown")]}),(0,r.jsx)(J.mB,{}),(0,r.jsxs)(J._2,{"data-testid":"agent-instance-delete-".concat(e.id),disabled:W,onSelect:()=>{es(e.id)},className:"text-danger-foreground focus:text-danger-foreground",children:[(0,r.jsx)(sv.A,{className:"w-4 h-4"}),g("agentInstanceDelete")]})]})]})]},e.id)})}),(0,r.jsxs)("div",{className:"mt-4 flex items-center gap-2",children:[(0,r.jsx)("select",{"data-testid":"agent-instance-add-tool","aria-label":g("agentInstanceBaseTool"),value:E,disabled:k||U,onChange:e=>A(e.target.value),className:"flex-1 min-w-0 text-sm border border-input rounded-md px-2 py-2 bg-surface text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-accent-500 disabled:opacity-50",children:q.XH.map(e=>(0,r.jsx)("option",{value:e,children:(0,q.oo)(e)},e))}),(0,r.jsxs)("button",{type:"button","data-testid":"agent-instance-add",disabled:k||U,onClick:er,className:"flex items-center gap-1 text-sm font-medium px-3 py-2 rounded-md border border-accent-200 dark:border-accent-700 bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300 hover:bg-accent-100 dark:hover:bg-accent-900/50 disabled:opacity-40 disabled:cursor-not-allowed shrink-0",children:[(0,r.jsx)(lz.A,{className:"w-4 h-4"}),g("agentInstanceAdd")]})]}),U&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:g("agentInstanceMax",{max:q.Ab})}),W&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:g("agentInstanceMin",{min:1})}),k&&(0,r.jsxs)("div",{"data-testid":"agent-instances-loading",className:"mt-3 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)(u.y,{size:"xs",variant:"muted"}),g("loading")]}),C&&(0,r.jsx)("p",{"data-testid":"agent-instances-error",className:"mt-3 text-xs text-danger-foreground",children:C}),$&&(0,r.jsx)(lN,{worktreeId:n,vibeLocalModel:l,onVibeLocalModelChange:o,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:m}),(0,r.jsxs)("div",{className:"mt-6 border-t border-border pt-4",children:[(0,r.jsxs)("button",{type:"button","data-testid":"agent-defaults-toggle","aria-expanded":D,onClick:et,className:"flex w-full items-center gap-1 text-left text-sm font-semibold text-foreground hover:text-accent-600 dark:hover:text-accent-400",children:[D?(0,r.jsx)(K.A,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}):(0,r.jsx)(n8.A,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),g("agentDefaults")]}),D&&(0,r.jsxs)("div",{className:"mt-2 space-y-3","data-testid":"agent-defaults-section",children:[(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:g("agentDefaultsDescription")}),(0,r.jsx)("p",{"data-testid":"agent-defaults-roster",className:"text-xs font-medium text-foreground break-words",children:G.map(e=>(0,q.oo)(e)).join(" → ")}),!Q&&(0,r.jsx)("p",{"data-testid":"agent-defaults-invalid",className:"text-xs text-warning-foreground",children:g("agentDefaultsInvalidRoster",{min:l_.eu,max:l_.Wj})}),(0,r.jsx)("button",{type:"button","data-testid":"agent-defaults-set-default",disabled:X||!Q,onClick:()=>{Y.saveAsDefault()},className:"w-full text-sm font-medium px-3 py-2 rounded-md border border-accent-200 dark:border-accent-700 bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300 hover:bg-accent-100 dark:hover:bg-accent-900/50 disabled:opacity-40 disabled:cursor-not-allowed",children:g("agentDefaultsSetDefault")}),(0,r.jsxs)("div",{className:"space-y-1",children:[Y.repositoryName&&(0,r.jsx)("p",{"data-testid":"agent-defaults-repository","data-repository":Y.repositoryName,className:"text-xs text-muted-foreground",children:g("agentDefaultsRepositoryLabel",{repository:Y.repositoryName})}),Y.repoDeclaresAgents&&(0,r.jsx)("p",{"data-testid":"agent-defaults-repo-declared",className:"text-xs text-warning-foreground",children:g("agentDefaultsRepoDeclared")}),!Y.repoDeclaresAgents&&(0,r.jsx)("span",{"data-testid":"agent-defaults-eligible","data-count":null!=(t=Y.eligible)?t:void 0,className:"block text-xs text-muted-foreground",children:null===Y.eligible?g("agentDefaultsEligibleUnknown"):g("agentDefaultsEligible",{count:Y.eligible})}),(0,r.jsx)("button",{type:"button","data-testid":"agent-defaults-apply",disabled:X||!Z,onClick:()=>{en()},className:"w-full text-sm font-medium px-3 py-2 rounded-md border border-border bg-surface text-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed",children:g("agentDefaultsApply")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:g("agentDefaultsApplyScope")})]}),Y.savedDefault&&(0,r.jsxs)("p",{"data-testid":"agent-defaults-saved",className:"flex items-center gap-1 text-xs text-success-foreground",children:[(0,r.jsx)(ey.A,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),g("agentDefaultsSaved")]}),null!==Y.appliedCount&&(0,r.jsxs)("p",{"data-testid":"agent-defaults-applied","data-count":Y.appliedCount,className:"flex items-center gap-1 text-xs text-success-foreground",children:[(0,r.jsx)(ey.A,{className:"h-3 w-3 shrink-0","aria-hidden":"true"}),g("agentDefaultsApplied",{count:Y.appliedCount})]}),ee&&(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{"data-testid":"agent-defaults-error",className:"text-xs text-danger-foreground",children:ee}),"count"===Y.error&&(0,r.jsx)("button",{type:"button","data-testid":"agent-defaults-retry",disabled:X,onClick:()=>{Y.refreshEligible()},className:"text-xs font-medium underline text-accent-700 dark:text-accent-300 disabled:opacity-40 disabled:cursor-not-allowed",children:g("agentDefaultsRetry")})]})]})]}),(0,r.jsxs)("div",{className:"mt-6 border-t border-border pt-4",children:[(0,r.jsxs)("button",{type:"button","data-testid":"agent-updates-toggle","aria-expanded":R,onClick:()=>P(e=>!e),className:"flex w-full items-center gap-1 text-left text-sm font-semibold text-foreground hover:text-accent-600 dark:hover:text-accent-400",children:[R?(0,r.jsx)(K.A,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}):(0,r.jsx)(n8.A,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),y("agentUpdates.title")]}),R&&(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)(lW.uN,{worktreeId:n,instances:a.map(e=>({id:e.id,cliTool:e.cliTool,alias:e.alias})),variant:"plain"})})]})]})}),lJ=(0,i.memo)(function(e){let{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:d,visibleInstanceIds:u,onToggleInstanceVisible:h,modelByInstance:f,sourceByInstance:x,composerTargetInstanceId:p}=e,g=(0,c.c)("schedule"),b=(0,c.c)("worktree"),v=new Set(u),y=u.length<=1,j=nA(t),w=(0,i.useCallback)(e=>{var a,r;return e.worktreeId!==t?"".concat(e.instanceId," @ ").concat(e.worktreeId):null!=(r=null==(a=n.find(t=>t.id===e.instanceId))?void 0:a.alias)?r:e.instanceId},[n,t]);return(0,r.jsxs)("div",{"data-testid":"mobile-agent-instances-pane",children:[(0,r.jsx)(lG,{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:d,modelByInstance:f,sourceByInstance:x,composerTargetInstanceId:p}),(0,r.jsxs)("div",{"data-testid":"mobile-visible-instances",className:"px-4 pb-4 border-t border-border mt-2 pt-4",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground mb-1",children:g("mobileVisibleInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-3",children:g("mobileVisibleInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-1",children:n.map(e=>{var t;let n=v.has(e.id),a=n&&y,s=null!=(t=null==f?void 0:f[e.id])?t:null,l=nM({owed:j.owedBy(e.id),awaiting:j.awaitedBy(e.id),aliasOf:w});return(0,r.jsxs)("label",{className:"flex items-center gap-2 p-2 rounded-lg cursor-pointer ".concat(a?"opacity-60 cursor-not-allowed":"hover:bg-muted"),children:[(0,r.jsx)(m.Sc,{"data-testid":"mobile-visible-instance-toggle-".concat(e.id),checked:n,disabled:a,onCheckedChange:()=>h(e.id)}),(0,r.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,r.jsx)("span",{className:"block text-sm font-medium text-foreground truncate",children:(0,q.sw)(e)}),(0,r.jsx)("span",{className:"block text-xs text-muted-foreground truncate",children:(0,q.oo)(e.cliTool)}),s&&(0,r.jsx)("span",{"data-testid":"mobile-visible-instance-model-".concat(e.id),title:b("agentModel.modelLabel",{model:s}),className:"block text-xs text-muted-foreground truncate",children:s}),l.map(t=>(0,r.jsx)("span",{"data-testid":"mobile-visible-instance-relay-".concat(t.tone,"-").concat(e.id),title:b("relay.".concat(t.titleKey)),className:"block text-xs truncate ".concat(lq(t)),children:b("relay.".concat(t.key),t.params)},t.key))]})]},e.id)})}),y&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:g("mobileVisibleInstanceMin")})]})]})}),lY=Array.from({length:Math.floor(104)+1},(e,t)=>3e5+3e5*t);var lQ=n(82912),lX=n.n(lQ);n(95704);let lZ=[36e5,108e5,288e5],l0={36e5:"autoYes.durations.1h",108e5:"autoYes.durations.3h",288e5:"autoYes.durations.8h"};function l1(e){if(e.length>500)return{valid:!1,error:"Pattern must be ".concat(500," characters or less")};if(!lX()(e))return{valid:!1,error:"Pattern may cause performance issues (catastrophic backtracking detected)"};try{return new RegExp(e),{valid:!0}}catch(e){return{valid:!1,error:"Invalid regular expression syntax"}}}function l2(e){let t=Math.max(0,e-Date.now()),n=Math.floor(t/36e5),a=Math.floor(t%36e5/6e4),r=Math.floor(t%6e4/1e3);return n>0?"".concat(n,":").concat(a.toString().padStart(2,"0"),":").concat(r.toString().padStart(2,"0")):"".concat(a.toString().padStart(2,"0"),":").concat(r.toString().padStart(2,"0"))}function l5(e){let t=Math.floor(e/6e4),n=Math.floor(t/60),a=t%60;return n>0&&a>0?"".concat(n,"h ").concat(a,"m"):n>0?"".concat(n,"h"):"".concat(a,"m")}let l4="w-full px-3 py-2 text-sm border border-input rounded-md bg-surface dark:bg-surface-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring";function l3(e){let{isOpen:t,worktreeId:n,instances:a,onClose:s,onSaved:l}=e,o=(0,c.c)("schedule"),d=(0,eC.a)(),u=(0,i.useMemo)(()=>a&&a.length>0?a:(0,q.lu)([...q.XH]),[a]),[m,h]=(0,i.useState)(""),[f,x]=(0,i.useState)(()=>{var e,t;return null!=(t=null==(e=u[0])?void 0:e.id)?t:q.XH[0]}),[p,g]=(0,i.useState)(lY[0]),[b,v]=(0,i.useState)(!1),[y,j]=(0,i.useState)(null);(0,i.useEffect)(()=>{var e,n;t&&(h(""),g(lY[0]),j(null),v(!1),x(null!=(n=null==(e=u[0])?void 0:e.id)?n:q.XH[0]))},[t,u]),(0,i.useEffect)(()=>{if(!u.some(e=>e.id===f)){var e,t;x(null!=(t=null==(e=u[0])?void 0:e.id)?t:q.XH[0])}},[u,f]);let w=m.trim().length>0&&!b,k=(0,i.useCallback)(async()=>{if(!m.trim()||b)return;let e=u.find(e=>e.id===f);if(e){j(null),v(!0);try{let t=await fetch("/api/worktrees/".concat(n,"/timers"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cliToolId:e.cliTool,instanceId:e.id,message:m.trim(),delayMs:p})});if(t.ok){let e=await t.json();l(),"session_not_running"===e.warning?(j("session_not_running"),h("")):s()}}catch(e){}finally{v(!1)}}},[n,u,f,m,p,b,l,s]),N=(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-xs font-semibold text-foreground mb-1",htmlFor:"timer-instance-select",children:o("timer.agent")}),(0,r.jsx)("select",{id:"timer-instance-select","data-testid":"timer-instance-select",value:f,onChange:e=>x(e.target.value),className:l4,children:u.map(e=>(0,r.jsx)("option",{value:e.id,children:e.alias},e.id))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-xs font-semibold text-foreground mb-1",htmlFor:"timer-message-input",children:o("timer.message")}),(0,r.jsx)("textarea",{id:"timer-message-input","data-testid":"timer-message-input",value:m,onChange:e=>h(e.target.value),placeholder:o("timer.message"),maxLength:1e4,rows:3,className:"".concat(l4," resize-none")})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-xs font-semibold text-foreground mb-1",htmlFor:"timer-delay-select",children:o("timer.delay")}),(0,r.jsx)("select",{id:"timer-delay-select","data-testid":"timer-delay-select",value:p,onChange:e=>g(Number(e.target.value)),className:l4,children:lY.map(e=>(0,r.jsx)("option",{value:e,children:l5(e)},e))})]}),"session_not_running"===y&&(0,r.jsx)("div",{"data-testid":"timer-session-warning",className:"text-xs p-2 rounded bg-warning-subtle text-warning-foreground",children:o("timer.sessionWarning")})]}),C=(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm font-medium text-foreground hover:bg-muted rounded-md transition-colors",children:o("timer.close")}),(0,r.jsx)("button",{type:"button","data-testid":"timer-register-button",onClick:()=>void k(),disabled:!w,className:"px-4 py-2 text-sm font-medium text-white bg-accent-600 hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed rounded-md transition-colors",children:o("timer.register")})]}),S=o("timer.titleCreate");return d?(0,r.jsx)(s6,{isOpen:t,onClose:s,title:S,footer:C,children:N}):(0,r.jsx)(tN.a,{isOpen:t,onClose:s,title:S,size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[N,(0,r.jsx)("div",{className:"pt-2 border-t border-border",children:C})]})})}function l6(e){return new Date(e).toLocaleString()}function l8(e){var t,n;let{timer:a,instances:s,onClose:l}=e,i=(0,c.c)("schedule"),o=(0,eC.a)();if(!a)return null;let d=null!=(n=null==(t=s.find(e=>e.id===a.instanceId))?void 0:t.alias)?n:a.cliToolId,u=e=>{let{label:t,children:n}=e;return(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-muted-foreground mb-0.5",children:t}),(0,r.jsx)("div",{className:"text-sm text-foreground break-words",children:n})]})},m=(0,r.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"timer-detail-body",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-muted-foreground mb-1",children:i("timer.message")}),(0,r.jsx)("pre",{"data-testid":"timer-detail-message",className:"text-sm whitespace-pre-wrap break-words font-mono text-foreground bg-muted rounded p-2 max-h-60 overflow-y-auto",children:a.message})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,r.jsx)(u,{label:i("timer.agent"),children:(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 font-medium",children:d})}),(0,r.jsx)(u,{label:i("timer.statusLabel"),children:(0,r.jsx)("span",{className:function(e){switch(e){case"pending":return"text-info";case"sending":case"no_session":return"text-warning-foreground";case"sent":return"text-success-foreground";case"failed":return"text-danger-foreground";default:return"text-muted-foreground"}}(a.status),children:i("timer.status.".concat(a.status))})}),(0,r.jsx)(u,{label:i("timer.delay"),children:l5(a.delayMs)}),(0,r.jsx)(u,{label:i("timer.scheduledTime"),children:l6(a.scheduledSendTime)}),(0,r.jsx)(u,{label:i("timer.createdTime"),children:l6(a.createdAt)}),null!==a.sentAt&&(0,r.jsx)(u,{label:i("timer.sentTime"),children:l6(a.sentAt)})]}),"failed"===a.status&&a.error&&(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-danger-foreground mb-1",children:i("timer.failureReason")}),(0,r.jsx)("pre",{"data-testid":"timer-detail-error",className:"text-xs whitespace-pre-wrap break-words font-mono text-danger-foreground bg-danger-subtle rounded p-2 max-h-40 overflow-y-auto",children:a.error})]})]}),h=(0,r.jsx)("div",{className:"flex items-center justify-end",children:(0,r.jsx)("button",{type:"button","data-testid":"timer-detail-close",onClick:l,className:"px-4 py-2 text-sm font-medium text-foreground hover:bg-muted rounded-md transition-colors",children:i("timer.close")})}),f=i("timer.detailTitle");return o?(0,r.jsx)(s6,{isOpen:!0,title:f,onClose:l,footer:h,children:m}):(0,r.jsx)(tN.a,{isOpen:!0,title:f,onClose:l,size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[m,(0,r.jsx)("div",{className:"pt-2 border-t border-border",children:h})]})})}let l9=(0,i.memo)(function(e){let{worktreeId:t,instances:n}=e,a=(0,c.c)("schedule"),s=(0,eO.SC)(),l=(0,i.useMemo)(()=>n&&n.length>0?n:(0,q.lu)([...q.XH]),[n]),[o,d]=(0,i.useState)([]),[u,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(!1),[x,p]=(0,i.useState)(null),[,g]=(0,i.useState)(0),b=(0,i.useRef)(null),v=(0,i.useRef)(null),j=(0,i.useRef)(null),w=(0,i.useCallback)(async()=>{try{let n=await fetch("/api/worktrees/".concat(t,"/timers"));if(n.ok){var e;let t=await n.json();d(t.timers),m(null!=(e=t.hasMore)&&e),t.timers.length>0?j.current=t.timers[t.timers.length-1].createdAt:j.current=null}}catch(e){}},[t]),k=(0,i.useCallback)(async()=>{if(null!=j.current)try{let n=new URLSearchParams;n.set("before",String(j.current)),n.set("limit",String(50));let a=await fetch("/api/worktrees/".concat(t,"/timers?").concat(n));if(a.ok){var e;let t=await a.json();d(e=>[...e,...t.timers]),m(null!=(e=t.hasMore)&&e),t.timers.length>0&&(j.current=t.timers[t.timers.length-1].createdAt)}}catch(e){}},[t]);(0,i.useEffect)(()=>{function e(){return w(),b.current=setInterval(()=>{w()},1e4),v.current=setInterval(()=>{g(e=>e+1)},1e3),t}function t(){b.current&&clearInterval(b.current),v.current&&clearInterval(v.current),b.current=null,v.current=null}e();let n=()=>{"hidden"===document.visibilityState?t():e()};return document.addEventListener("visibilitychange",n),()=>{t(),document.removeEventListener("visibilitychange",n)}},[w]);let N=(0,i.useCallback)(async e=>{try{(await fetch("/api/worktrees/".concat(t,"/timers?timerId=").concat(e),{method:"DELETE"})).ok&&w()}catch(e){}},[t,w]),C=(0,i.useCallback)(async()=>{if(await s({description:a("timer.clearConfirm"),variant:"danger"}))try{(await fetch("/api/worktrees/".concat(t,"/timers/history"),{method:"DELETE"})).ok&&w()}catch(e){}},[t,w,a,s]),S=o.filter(e=>"pending"===e.status).length>=5;return(0,r.jsxs)("div",{className:"flex flex-col h-full p-3 gap-3 overflow-auto",children:[0===o.length?(0,r.jsxs)("div",{className:"flex flex-col items-center text-center py-8 px-4",children:[(0,r.jsx)("div",{className:"mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-accent-50 text-accent-600 dark:bg-accent-900/30 dark:text-accent-300",children:(0,r.jsx)(y.A,{className:"w-7 h-7"})}),(0,r.jsx)("p",{className:"font-semibold text-foreground mb-1",children:a("timer.title")}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground mb-5 max-w-xs",children:a("timer.noTimers")}),(0,r.jsxs)("button",{type:"button","data-testid":"timer-empty-cta",onClick:()=>f(!0),className:"inline-flex items-center gap-1.5 px-5 py-2.5 text-sm font-semibold text-white bg-accent-600 hover:bg-accent-700 rounded-lg shadow-sm transition-colors",children:[(0,r.jsx)(lz.A,{className:"w-4 h-4"}),a("timer.createButton")]})]}):(0,r.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[S&&(0,r.jsx)("span",{className:"text-xs text-warning-foreground",children:a("timer.maxReached",{max:5})}),(0,r.jsxs)("button",{type:"button","data-testid":"timer-new-button",onClick:()=>f(!0),disabled:S,className:"inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-white bg-accent-600 hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed rounded transition-colors whitespace-nowrap",children:[(0,r.jsx)(lz.A,{className:"w-3.5 h-3.5"}),a("timer.newTimer")]})]}),o.map(e=>{var t,n;return(0,r.jsxs)("div",{role:"button",tabIndex:0,"data-testid":"timer-row",onClick:()=>p(e),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),p(e))},className:"flex items-center gap-2 p-2 rounded-lg border border-border bg-surface text-left cursor-pointer hover:bg-muted transition-colors",children:[(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message.length>60?e.message.slice(0,60)+"...":e.message}),(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs",children:[(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 font-medium",children:null!=(n=null==(t=l.find(t=>t.id===e.instanceId))?void 0:t.alias)?n:e.cliToolId}),(0,r.jsx)("span",{className:function(e){switch(e){case"pending":return"text-info";case"sending":case"no_session":return"text-warning-foreground";case"sent":return"text-success-foreground";case"failed":return"text-danger-foreground";default:return"text-muted-foreground"}}(e.status),children:a("timer.status.".concat(e.status))}),"pending"===e.status&&(0,r.jsx)("span",{className:"text-muted-foreground",children:l2(e.scheduledSendTime)}),(0,r.jsx)("span",{className:"text-muted-foreground",children:l5(e.delayMs)})]})]}),"pending"===e.status&&(0,r.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),N(e.id)},className:"px-2 py-1 text-xs text-danger-foreground hover:bg-danger-subtle rounded transition-colors",children:a("timer.cancel")})]},e.id)}),u&&(0,r.jsx)("button",{type:"button",onClick:k,className:"px-3 py-2 text-sm text-accent-600 dark:text-accent-400 hover:bg-accent-50 dark:hover:bg-accent-900/20 rounded-md transition-colors text-center",children:a("timer.loadMore")}),o.some(e=>"pending"!==e.status)&&(0,r.jsx)("button",{type:"button",onClick:C,className:"px-3 py-2 text-sm text-muted-foreground hover:bg-muted rounded-md transition-colors text-center",children:a("timer.clearHistory")})]}),(0,r.jsx)(l3,{isOpen:h,worktreeId:t,instances:n,onClose:()=>f(!1),onSaved:()=>{w()}}),(0,r.jsx)(l8,{timer:x,instances:l,onClose:()=>p(null)})]})});var l7=n(35626),ie=n(99648);let it={verified:"skills.compatibility.axisOutcome.verified",unsupported:"skills.compatibility.axisOutcome.unsupported",unknown:"skills.compatibility.axisOutcome.unknown"},ia={mechanical:"skills.compatibility.evidenceKind.mechanical",self_report:"skills.compatibility.evidenceKind.selfReport",not_measured:"skills.compatibility.evidenceKind.notMeasured"},ir={outcome:"unknown",evidenceKind:"not_measured",labelKey:it.unknown,evidenceKindKey:ia.not_measured,limitationKey:null},is={SESSION_RESTART:"skills.compatibility.reload.sessionRestart",SESSION_RESTART_NO_SLASH:"skills.compatibility.reload.sessionRestartNoSlash",UNKNOWN:"skills.compatibility.reload.unknown"},il={NO_SLASH_COMMAND:"skills.compatibility.limitation.noSlashCommand"};function ii(e){return{agent:e,discoveryRoots:[],discovery:ir,invocation:ir,testedVersion:null,testedDate:null,evidenceSource:null,reloadKey:is.UNKNOWN,skipReasonKey:"skills.compatibility.skipReason.notMeasured"}}ie.td,it.verified,ia.mechanical,it.verified,ia.mechanical,is.SESSION_RESTART,ie.Co,it.verified,ia.self_report,it.unsupported,ia.mechanical,il.NO_SLASH_COMMAND,is.SESSION_RESTART_NO_SLASH,ii("gemini"),ii("vibe-local"),ie.Co,ie.td,it.verified,ia.mechanical,it.verified,ia.mechanical,il.NO_SLASH_COMMAND,is.SESSION_RESTART,ie.Co,ie.td,it.verified,ia.mechanical,it.verified,ia.mechanical,is.UNKNOWN,ii("antigravity"),ie.Co,it.verified,ia.mechanical,it.verified,ia.mechanical,is.SESSION_RESTART;let io={SATISFIED:"SKILL_COMPAT_SATISFIED",HOST_VERSION_OUT_OF_RANGE:"SKILL_COMPAT_HOST_VERSION_OUT_OF_RANGE",HOST_VERSION_UNKNOWN:"SKILL_COMPAT_HOST_VERSION_UNKNOWN",RANGE_UNSUPPORTED:"SKILL_COMPAT_RANGE_UNSUPPORTED"};io.SATISFIED,io.HOST_VERSION_OUT_OF_RANGE,io.HOST_VERSION_UNKNOWN,io.RANGE_UNSUPPORTED;let ic={CONFIRMED:"SKILL_AGENT_EVIDENCE_CONFIRMED",RESTRICTED:"SKILL_AGENT_EVIDENCE_RESTRICTED",STALE_DECLARATION:"SKILL_AGENT_EVIDENCE_STALE_DECLARATION",UNVERIFIED:"SKILL_AGENT_EVIDENCE_UNVERIFIED"};ic.CONFIRMED,ic.RESTRICTED,ic.STALE_DECLARATION,ic.UNVERIFIED;let id=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function iu(e){if("string"!=typeof e||e.length>64)return null;let t=id.exec(e);return t?{major:Number(t[1]),minor:Number(t[2]),patch:Number(t[3]),prerelease:t[4]?t[4].split("."):[],build:t[5]?t[5].split("."):[]}:null}let im={UP_TO_DATE:"SKILL_UPDATE_UP_TO_DATE",HIGHEST_COMPATIBLE:"SKILL_UPDATE_RECOMMEND_HIGHEST_COMPATIBLE",LATEST_UNVERIFIED:"SKILL_UPDATE_RECOMMEND_LATEST_UNVERIFIED",NONE_COMPATIBLE:"SKILL_UPDATE_RECOMMEND_NONE_COMPATIBLE",INSTALLED_VERSION_INVALID:"SKILL_UPDATE_INSTALLED_VERSION_INVALID",RANGE_UNSUPPORTED:"SKILL_UPDATE_RANGE_UNSUPPORTED"};function ih(e,t){let n=function(e,t){let n=iu(e),a=iu(t);return n&&a?n.major!==a.major?n.major<a.major?-1:1:n.minor!==a.minor?n.minor<a.minor?-1:1:n.patch!==a.patch?n.patch<a.patch?-1:1:function(e,t){if(0===e.length&&0===t.length)return 0;if(0===e.length)return 1;if(0===t.length)return -1;let n=Math.min(e.length,t.length);for(let a=0;a<n;a++){let n=e[a],r=t[a];if(n===r)continue;let s=/^\d+$/.test(n),l=/^\d+$/.test(r);if(s&&l)return Number(n)<Number(r)?-1:1;if(s)return -1;if(l)return 1;return n<r?-1:1}return e.length===t.length?0:e.length<t.length?-1:1}(n.prerelease,a.prerelease):null}(e,t);return null!==n&&n>0}im.UP_TO_DATE,im.HIGHEST_COMPATIBLE,im.LATEST_UNVERIFIED,im.NONE_COMPATIBLE,im.INSTALLED_VERSION_INVALID,im.RANGE_UNSUPPORTED;var ix=n(75333),ip=n(34380),ig=n(37381),ib=n(95584),iv=n(80130);let iy={open:!1,selectedVersion:null,busy:!1,plan:null,failure:null,riskAcknowledged:!1,riskIncreaseAcknowledged:!1,applying:!1,applyResult:null,applyFailure:null};function ij(e){let{heading:t,paths:n,testid:a}=e;return 0===n.length?null:(0,r.jsxs)("div",{"data-testid":a,children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t}),(0,r.jsx)("ul",{className:"mt-1 space-y-0.5",children:n.map(e=>(0,r.jsx)("li",{className:"break-all font-mono text-xs text-foreground",children:e},e))})]})}function iw(e){var t;let{skillId:n,skillName:a,worktreeId:s,installedVersion:l,versions:o}=e,d=(0,c.c)("skills"),u=(0,i.useMemo)(()=>o.filter(e=>ih(e.version,l)),[o,l]),h=(0,i.useMemo)(()=>{var e,t,n;return null!=(n=null==(e=null!=(t=u.find(e=>"compatible"===e.compatibility.commandmate.status))?t:u[0])?void 0:e.version)?n:null},[u]),[f,x]=(0,i.useState)(iy),p=(0,i.useCallback)(()=>{x({...iy,open:!0,selectedVersion:h})},[h]),g=(0,i.useCallback)(()=>{x(iy)},[]),b=(0,i.useCallback)(async()=>{let e=f.selectedVersion;if(!e)return;x(e=>({...e,busy:!0,plan:null,failure:null,riskAcknowledged:!1,riskIncreaseAcknowledged:!1,applyResult:null,applyFailure:null}));let t=await (0,iv.Sw)(s,n,{version:e});x(e=>({...e,busy:!1,plan:t.ok?t.data.plan:null,failure:t.ok?null:t.failure}))},[n,f.selectedVersion,s]),v=(0,i.useCallback)(async()=>{var e;let t=f.plan;if(!t||!t.updatable)return;x(e=>({...e,applying:!0,applyFailure:null}));let a=await (0,iv.h2)(s,n,{planToken:t.token,version:t.update.toVersion,acknowledgeRisk:f.riskAcknowledged,acknowledgeRiskIncrease:f.riskIncreaseAcknowledged,idempotencyKey:(e=t.token,"skill-update-".concat(e))});x(e=>({...e,applying:!1,applyResult:a.ok?a.data:null,applyFailure:a.ok?null:a.failure}))},[n,f.plan,f.riskAcknowledged,f.riskIncreaseAcknowledged,s]);if(0===u.length)return(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"skill-update-uptodate",children:d("update.upToDate",{version:l})});let y=f.plan,j=f.applyResult;return(0,r.jsxs)("div",{"data-testid":"skill-update-dialog-host",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(m.Ex,{variant:"info","data-testid":"skill-update-badge",children:d("update.badge")}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("update.fromTo",{from:l,to:u[0].version})}),(0,r.jsx)(m.$n,{variant:"secondary",size:"sm",onClick:p,"data-testid":"skill-update-trigger",children:d("update.open")})]}),(0,r.jsx)(m.Jh,{isOpen:f.open,onClose:g,title:d("update.heading"),size:"lg",children:(0,r.jsxs)("div",{className:"space-y-3 p-4","data-testid":"skill-update-dialog",children:[(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:d("update.intro",{skill:a,version:l})}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:d("update.ready")}),(0,r.jsxs)("label",{className:"block text-xs font-medium text-muted-foreground",children:[d("update.versionPicker"),(0,r.jsx)("select",{className:"".concat("w-full rounded-md border border-input bg-surface px-3 py-2 text-sm text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"," mt-1"),value:null!=(t=f.selectedVersion)?t:"",onChange:e=>x(t=>({...t,selectedVersion:e.target.value,plan:null,failure:null})),disabled:f.busy,"data-testid":"skill-update-version-select",children:u.map(e=>(0,r.jsxs)("option",{value:e.version,children:[e.version,e.prerelease?" (".concat(d("detail.prerelease"),")"):"","compatible"!==e.compatibility.commandmate.status?" — ".concat(d(ib.OV[e.compatibility.commandmate.status])):""]},e.version))})]}),(0,r.jsx)(m.$n,{variant:"primary",disabled:f.busy||!f.selectedVersion,onClick:b,"data-testid":"skill-update-build",children:f.busy?d("update.building"):d("update.build")}),f.failure&&(0,r.jsxs)(ig.u,{tone:"danger","data-testid":"skill-update-error",children:[(0,r.jsx)("p",{children:d((0,ib.FW)(f.failure.code))}),(0,r.jsx)("p",{className:"mt-1 break-words",children:d("state.errorCode",{code:f.failure.code})})]}),y&&(0,r.jsxs)("div",{className:"space-y-3","data-testid":"skill-update-plan",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground",children:d("update.fromTo",{from:y.update.fromVersion,to:y.update.toVersion})}),null!==y.update.latestVersion&&y.update.latestVersion!==y.update.toVersion&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("update.latestAvailable",{version:y.update.latestVersion})})]}),(0,r.jsx)(ig.u,{tone:y.updatable?"info":"warning","data-testid":"skill-update-next-action",children:d((0,ib.e5)(y.nextActionKey))}),y.blockers.length>0&&(0,r.jsx)("ul",{className:"space-y-1","data-testid":"skill-update-blockers",children:y.blockers.map(e=>{var t;return(0,r.jsxs)("li",{className:"text-xs text-danger-foreground",children:[e.path&&(0,r.jsx)("span",{className:"mr-1 break-all font-mono",children:e.path}),d((0,ib.e5)(e.messageKey))]},"".concat(e.code,":").concat(null!=(t=e.path)?t:""))})}),(0,r.jsxs)("div",{className:"space-y-2","data-testid":"skill-update-risk",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("plan.riskHeading")}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-foreground",children:[(0,r.jsx)(ix.qW,{risk:y.securityDiff.risk.from.effective}),(0,r.jsx)("span",{"aria-hidden":"true",children:"→"}),(0,r.jsx)(ix.qW,{risk:y.securityDiff.risk.to.effective})]}),y.riskIncreased&&y.riskIncreaseMessageKey&&(0,r.jsx)(ig.u,{tone:"danger","data-testid":"skill-update-risk-increase",children:d((0,ib.e5)(y.riskIncreaseMessageKey))}),y.requiresRiskAcknowledgement&&y.riskAcknowledgementMessageKey&&(0,r.jsx)(ig.u,{tone:"warning","data-testid":"skill-update-high-risk",children:d((0,ib.e5)(y.riskAcknowledgementMessageKey))}),y.updatable&&!f.applyResult&&y.requiresRiskAcknowledgement&&(0,r.jsxs)("label",{className:"flex items-start gap-2 text-xs text-foreground",children:[(0,r.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:f.riskAcknowledged,onChange:e=>x(t=>({...t,riskAcknowledged:e.target.checked})),"data-testid":"skill-update-ack-risk"}),d("update.ackRisk")]}),y.updatable&&!f.applyResult&&y.riskIncreased&&(0,r.jsxs)("label",{className:"flex items-start gap-2 text-xs text-foreground",children:[(0,r.jsx)("input",{type:"checkbox",className:"mt-0.5",checked:f.riskIncreaseAcknowledged,onChange:e=>x(t=>({...t,riskIncreaseAcknowledged:e.target.checked})),"data-testid":"skill-update-ack-risk-increase"}),d("update.ackRiskIncrease")]})]}),(0,r.jsxs)("div",{className:"space-y-2","data-testid":"skill-update-security-diff",children:[y.securityDiff.permissions.added.length>0&&(0,r.jsxs)("div",{"data-testid":"skill-update-permissions-added",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("update.permissionsAdded")}),(0,r.jsx)("ul",{className:"mt-1 space-y-0.5",children:y.securityDiff.permissions.added.map(e=>{var t;return(0,r.jsx)("li",{className:"text-xs text-foreground",children:d(null!=(t=ib.z2[e])?t:"plan.permissionsNone")},e)})})]}),y.securityDiff.permissions.removed.length>0&&(0,r.jsxs)("div",{"data-testid":"skill-update-permissions-removed",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("update.permissionsRemoved")}),(0,r.jsx)("ul",{className:"mt-1 space-y-0.5",children:y.securityDiff.permissions.removed.map(e=>{var t;return(0,r.jsx)("li",{className:"text-xs text-foreground",children:d(null!=(t=ib.z2[e])?t:"plan.permissionsNone")},e)})})]}),(0,r.jsx)(ij,{heading:d("update.scriptsAdded"),paths:y.securityDiff.scripts.added,testid:"skill-update-scripts-added"}),(0,r.jsx)(ij,{heading:d("update.scriptsRemoved"),paths:y.securityDiff.scripts.removed,testid:"skill-update-scripts-removed"}),(0,r.jsx)(ij,{heading:d("update.executablesAdded"),paths:y.securityDiff.executables.added,testid:"skill-update-executables-added"}),(0,r.jsx)(ij,{heading:d("update.executablesRemoved"),paths:y.securityDiff.executables.removed,testid:"skill-update-executables-removed"})]}),y.securityDiff.changelogs.length>0&&(0,r.jsxs)("div",{className:"space-y-1","data-testid":"skill-update-changelogs",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("detail.changelogHeading")}),y.securityDiff.changelogs.map(e=>(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-xs font-semibold text-foreground",children:e.version}),(0,r.jsx)("p",{className:"whitespace-pre-wrap text-xs text-muted-foreground",children:e.changelog})]},e.version))]}),(0,r.jsxs)("div",{className:"space-y-1","data-testid":"skill-update-files",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("update.filesHeading")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"skill-update-stats",children:d("update.stats",{added:y.stats.added,updated:y.stats.updated,removed:y.stats.removed,unchanged:y.stats.unchanged})}),(0,r.jsx)("ul",{className:"space-y-1",children:y.files.filter(e=>"unchanged"!==e.change).map(e=>{var t,n;return(0,r.jsxs)("li",{"data-testid":"skill-update-file",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(m.Ex,{variant:null!=(t=ib.JD[e.change])?t:"gray",children:d(null!=(n=ib.KS[e.change])?n:"update.change.update")}),(0,r.jsx)("span",{className:"break-all font-mono text-xs text-foreground",children:e.path})]}),e.diff&&(0,r.jsxs)("details",{className:"mt-1",children:[(0,r.jsx)("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:d("update.showDiff")}),(0,r.jsx)("pre",{className:"mt-1 overflow-x-auto rounded-md bg-muted p-2 text-xs text-foreground",children:e.diff})]})]},e.path)})})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"skill-update-expiry",children:d("plan.expiresAt",{timestamp:y.expiresAt})}),y.updatable&&!f.applyResult&&(0,r.jsx)(m.$n,{variant:"primary",disabled:f.applying||y.requiresRiskAcknowledgement&&!f.riskAcknowledged||y.riskIncreased&&!f.riskIncreaseAcknowledged,onClick:v,"data-testid":"skill-update-apply",children:f.applying?d("update.applying"):d("update.apply")}),f.applyFailure&&(0,r.jsxs)("div",{className:"space-y-2","data-testid":"skill-update-apply-error",children:[(0,r.jsxs)(ig.u,{tone:"danger",children:[(0,r.jsx)("p",{children:d((0,ib.FW)(f.applyFailure.code))}),(0,r.jsx)("p",{className:"mt-1 break-words",children:d("state.errorCode",{code:f.applyFailure.code})})]}),f.applyFailure.nextActionKey&&(0,r.jsx)(ig.u,{tone:"warning",children:d((0,ib.e5)(f.applyFailure.nextActionKey))}),f.applyFailure.blockers&&f.applyFailure.blockers.length>0&&(0,r.jsx)("ul",{className:"space-y-1","data-testid":"skill-update-apply-error-blockers",children:f.applyFailure.blockers.map(e=>{var t;return(0,r.jsxs)("li",{className:"text-xs text-danger-foreground",children:[e.path&&(0,r.jsx)("span",{className:"mr-1 break-all font-mono",children:e.path}),d((0,ib.e5)(e.messageKey))]},"".concat(e.code,":").concat(null!=(t=e.path)?t:""))})})]})]}),j&&(0,r.jsxs)("div",{className:"space-y-3","data-testid":"skill-update-result",children:[(0,r.jsx)(ig.u,{tone:"succeeded"===j.operation.result?"info":"warning","data-testid":"skill-update-result-next-action",children:d((0,ib.e5)(j.operation.nextActionKey))}),"reload"in j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-sm font-semibold text-foreground",children:d("update.fromTo",{from:j.update.fromVersion,to:j.update.toVersion})}),(0,r.jsxs)("div",{className:"space-y-1","data-testid":"skill-update-result-reload",children:[(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d("operation.reloadHeading")}),(0,r.jsx)("ul",{className:"space-y-1",children:j.reload.agents.map(e=>(0,r.jsx)("li",{className:"text-xs text-muted-foreground",children:d((0,ib.e5)(e.messageKey),{agent:(0,q.f_)(e.agent),skillId:j.reload.skillId,version:j.reload.version})},e.agent))})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"skill-update-result-rollback",children:d((0,ib.e5)(j.rollback.messageKey),{version:j.rollback.backup.fromVersion})})]})]})]})})]})}let ik={status:"loading",skills:[],failure:null},iN={status:"loading",skills:[],failure:null};function iC(e){var t,n,a,s,l,o,d,u;let{worktreeId:h,className:f=""}=e,x=(0,c.c)("skills"),[p,g]=(0,i.useState)(ik),[b,v]=(0,i.useState)(iN),[y,j]=(0,i.useState)(null),[w,k]=(0,i.useState)(0),[N,C]=(0,i.useState)(0);(0,i.useEffect)(()=>{let e=new AbortController;return g(ik),(0,iv.s5)(e.signal).then(t=>{e.signal.aborted||g(t.ok?{status:"loaded",skills:t.data.skills,failure:null}:{status:"error",skills:[],failure:t.failure})}).catch(()=>{}),()=>e.abort()},[w]),(0,i.useEffect)(()=>{let e=new AbortController;return v(iN),(0,iv.Gj)(h,e.signal).then(t=>{e.signal.aborted||v(t.ok?{status:"loaded",skills:t.data.skills,failure:null}:{status:"error",skills:[],failure:t.failure})}).catch(()=>{}),()=>e.abort()},[h,N]);let S=(0,i.useMemo)(()=>new Map(b.skills.map(e=>[e.skillId,e.version])),[b.skills]),T=(0,i.useMemo)(()=>new Map(p.skills.map(e=>[e.id,{name:e.name,summary:e.summary,latest:e.latest}])),[p.skills]),I=(0,i.useMemo)(()=>{let e=new Map;for(let[r,s]of S){var t,n,a;e.set(r,(a=null!=(n=null==(t=T.get(r))?void 0:t.latest)?n:null,null!==s&&null!==a&&ih(a,s)))}return e},[S,T]),E=(0,i.useMemo)(()=>{var e;return null!=(e=p.skills.find(e=>e.id===y))?e:null},[p.skills,y]),A=(0,i.useMemo)(()=>{var e;return null!=(e=b.skills.find(e=>e.skillId===y))?e:null},[b.skills,y]);if(y){let e=null!=(a=null==E?void 0:E.compatibility)?a:null,t=E?E.recommendedVersion:null!=(s=null==A?void 0:A.version)?s:null,n=E?E.recommendedVersion?e&&"compatible"!==e.status?x("detail.install.blockedIncompatible",{reason:x((0,ib.e5)(e.messageKey),{range:e.requiredRange,currentVersion:null!=(l=e.currentVersion)?l:""})}):null:x("detail.install.blockedNoVersion"):null;return(0,r.jsxs)("div",{className:"flex flex-col min-h-0 ".concat(f).trim(),"data-testid":"worktree-skills-pane",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 border-b border-border p-3",children:[(0,r.jsxs)(m.$n,{variant:"ghost",size:"sm",onClick:()=>{j(null),C(e=>e+1)},"data-testid":"worktree-skills-back",children:[(0,r.jsx)(l7.A,{size:14,"aria-hidden":"true",className:"mr-1"}),x("worktreePane.back")]}),(0,r.jsx)("h2",{className:"min-w-0 truncate text-sm font-semibold text-foreground",children:null!=(o=null==E?void 0:E.name)?o:y})]}),(0,r.jsxs)("div",{className:"min-h-0 flex-1 space-y-3 overflow-auto p-3",children:[A&&E&&(0,r.jsx)(iw,{skillId:y,skillName:E.name,worktreeId:h,installedVersion:A.version,versions:E.versions}),(0,r.jsx)(ip.B,{skillId:y,version:t,blockedReason:n,worktreeId:h})]})]})}return(0,r.jsx)("div",{className:"flex flex-col min-h-0 ".concat(f).trim(),"data-testid":"worktree-skills-pane",children:(0,r.jsxs)("div",{className:"min-h-0 flex-1 space-y-4 overflow-auto p-3",children:[(0,r.jsxs)("section",{className:"space-y-2","data-testid":"worktree-skills-installed",children:[(0,r.jsx)("h2",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:x("worktreePane.installedHeading")}),"loading"===b.status?(0,r.jsx)(m.EA,{className:"h-16 w-full rounded-lg","data-testid":"worktree-skills-installed-loading"}):"error"===b.status?(0,r.jsxs)(m.Zp,{className:"space-y-2","data-testid":"worktree-skills-installed-error",children:[(0,r.jsxs)(ig.u,{tone:"danger",children:[(0,r.jsx)("p",{children:x("worktreePane.installedError")}),(0,r.jsx)("p",{className:"mt-1 break-words",children:x("state.errorCode",{code:null!=(d=null==(t=b.failure)?void 0:t.code)?d:""})})]}),(0,r.jsx)(m.$n,{variant:"secondary",size:"sm",onClick:()=>C(e=>e+1),"data-testid":"worktree-skills-installed-retry",children:x("state.retry")})]}):0===b.skills.length?(0,r.jsx)(m.Zp,{"data-testid":"worktree-skills-installed-empty",children:(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:x("worktreePane.installedEmpty")})}):(0,r.jsx)("ul",{className:"space-y-2",children:b.skills.map(e=>{var t;let n=T.get(e.skillId);return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",onClick:()=>j(e.skillId),"data-testid":"worktree-skills-installed-".concat(e.skillId),className:"w-full rounded-lg border border-border bg-card px-3 py-2.5 text-left transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"break-all text-sm font-semibold text-foreground",children:null!=(t=null==n?void 0:n.name)?t:e.skillId}),(0,r.jsx)(ix.qW,{risk:e.effectiveRisk}),I.get(e.skillId)&&(0,r.jsx)(m.Ex,{variant:"info","data-testid":"worktree-skills-update-badge-".concat(e.skillId),children:x("worktreePane.updateBadge")})]}),(null==n?void 0:n.summary)&&(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground line-clamp-2","data-testid":"worktree-skills-installed-summary-".concat(e.skillId),children:n.summary}),(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:x("worktreePane.version",{version:e.version})})]})},e.skillId)})})]}),(0,r.jsxs)("section",{className:"space-y-2","data-testid":"worktree-skills-catalog",children:[(0,r.jsx)("h2",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:x("worktreePane.catalogHeading")}),"loading"===p.status?(0,r.jsx)(m.EA,{className:"h-24 w-full rounded-lg","data-testid":"worktree-skills-catalog-loading"}):"error"===p.status?(0,r.jsxs)(m.Zp,{className:"space-y-2","data-testid":"worktree-skills-catalog-error",children:[(0,r.jsxs)(ig.u,{tone:"danger",children:[(0,r.jsx)("p",{children:x("state.errorNotice")}),(0,r.jsx)("p",{className:"mt-1 break-words",children:x("state.errorCode",{code:null!=(u=null==(n=p.failure)?void 0:n.code)?u:""})})]}),(0,r.jsx)(m.$n,{variant:"secondary",size:"sm",onClick:()=>k(e=>e+1),"data-testid":"worktree-skills-catalog-retry",children:x("state.retry")})]}):0===p.skills.length?(0,r.jsx)(m.Zp,{"data-testid":"worktree-skills-catalog-empty",children:(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:x("state.empty")})}):(0,r.jsx)("ul",{className:"space-y-2",children:p.skills.map(e=>{let t=(0,ib.gh)(e),n=S.has(e.id),a=!0===I.get(e.id);return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",onClick:()=>j(e.id),"data-testid":"worktree-skills-catalog-".concat(e.id),className:"w-full rounded-lg border border-border bg-card px-3 py-2.5 text-left transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"min-w-0 break-all text-sm font-semibold text-foreground",children:e.name}),n&&(a?(0,r.jsx)(m.Ex,{variant:"info","data-testid":"worktree-skills-catalog-update-badge-".concat(e.id),children:x("worktreePane.updateBadge")}):(0,r.jsx)(m.Ex,{variant:"info","data-testid":"worktree-skills-installed-badge-".concat(e.id),children:x("worktreePane.installedBadge")}))]}),(0,r.jsx)("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:x("card.provider",{provider:e.provider.name})}),(0,r.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground","data-testid":"worktree-skills-catalog-version-".concat(e.id),children:x("worktreePane.version",{version:e.latest})}),e.summary&&(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground line-clamp-2","data-testid":"worktree-skills-catalog-summary-".concat(e.id),children:e.summary}),(0,r.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[e.compatibility&&(0,r.jsx)(ix.Xz,{status:e.compatibility.status}),t&&(0,r.jsx)(ix.qW,{risk:t})]})]})},e.id)})})]})]})})}var iS=n(93499),iT=n(52799),iI=n(32209);let iE={pending:"gray",running:"info",waiting_input:"warning",verifying:"info",succeeded:"success",failed:"error",not_started:"warning",cancelled:"gray"},iA={running:"info",passed:"success",failed:"error",not_started:"warning",error:"error",cancelled:"gray"},iM={running:"info",passed:"success",failed:"error",timeout:"error",skipped:"gray",error:"error"},iL=["failed","timeout","error"],iR="".concat(tg,"/blob/main/docs/design/verification-config.md"),iP=".commandmate/verify.yaml";class iD extends Error{constructor(e,t,n=null){super(e),this.name="VerificationApiError",this.status=t,this.runningRunId=n}}async function iF(e,t){let n=await e.json().catch(()=>({})),a="string"==typeof n.error?n.error:"".concat(t," (").concat(e.status,")"),r="number"==typeof n.runningRunId?n.runningRunId:null;throw new iD(a,e.status,r)}function iO(e){return"/api/worktrees/".concat(encodeURIComponent(e))}async function iz(e,t){var n,a;let r=await fetch("".concat(iO(e),"/tasks?limit=1"),{signal:t});return r.ok?null!=(a=null==(n=(await r.json()).tasks)?void 0:n[0])?a:null:iF(r,"Failed to load tasks")}async function i_(e){var t;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,a=arguments.length>2?arguments[2]:void 0,r=await fetch("".concat(iO(e),"/verify/runs?limit=").concat(n),{signal:a});return r.ok?null!=(t=(await r.json()).runs)?t:[]:iF(r,"Failed to load verification runs")}async function iB(e,t,n){let a=await fetch("".concat(iO(e),"/verify/runs/").concat(t),{signal:n});return 404===a.status?null:a.ok?(await a.json()).run:iF(a,"Failed to load the verification run")}async function iH(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=await fetch("".concat(iO(e),"/verify"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)return iF(n,"Failed to start verification");let a=await n.json();if("number"!=typeof a.runId)throw new iD("Verification response carried no run id",n.status);return a.runId}async function iV(e,t){var n,a,r;let s=await fetch("".concat(iO(e),"/verify/config"),{signal:t});if(!s.ok)return iF(s,"Failed to load the verification config");let l=await s.json();return{exists:!0===l.exists,path:"string"==typeof l.path?l.path:iP,gates:null!=(n=l.gates)?n:[],options:null!=(a=l.options)?a:null,plannedGateIds:null!=(r=l.plannedGateIds)?r:[],error:"string"==typeof l.error?l.error:null}}async function iU(e){var t,n,a;let r=await fetch("".concat(iO(e),"/verify/config"),{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"});if(!r.ok)return iF(r,"Failed to draft the verification config");let s=await r.json();return{created:!0===s.created,path:"string"==typeof s.path?s.path:iP,gates:null!=(t=s.gates)?t:[],excluded:null!=(n=s.excluded)?n:[],scanned:null!=(a=s.scanned)?a:[]}}async function iK(e,t){var n;let a=await fetch("".concat(iO(e),"/verify/runs/").concat(t,"/cancel"),{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"});if(!a.ok)return iF(a,"Failed to cancel the verification run");let r=await a.json();return{runId:"number"==typeof r.runId?r.runId:t,status:null!=(n=r.status)?n:"cancelled"}}async function iW(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0,a=new URLSearchParams;void 0!==t.worktreeId&&a.set("worktreeId",t.worktreeId),void 0!==t.days&&a.set("days",String(t.days)),void 0!==t.limit&&a.set("limit",String(t.limit));let r=a.toString(),s=await fetch("/api/verification/runs".concat(r?"?".concat(r):""),{signal:n});return s.ok?null!=(e=(await s.json()).runs)?e:[]:iF(s,"Failed to load the verification history")}let i$={running:null,passed:0,failed:20,not_started:21,error:99,cancelled:99},iq=["passed","failed","not_started","error","cancelled"],iG={"work-evidence":"workEvidence",scope:"scope","env-clean":"envClean",config:"config"},iJ={mutex:"reason=mutex-wait",detachedContract:"was NOT judged",noContract:"no contract is attached to this run",notRequired:"success.requireScopeClean: false"};function iY(e){if(!e)return"—";let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function iQ(e){let{heading:t,action:n,children:a,testId:s}=e;return(0,r.jsxs)("section",{className:"border-b border-border px-3 py-3 last:border-b-0","data-testid":s,children:[(0,r.jsxs)("div",{className:"mb-2 flex items-center justify-between gap-2",children:[(0,r.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t}),n]}),a]})}function iX(e){let{label:t,children:n}=e;return(0,r.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,r.jsx)("span",{className:"font-mono text-xs text-muted-foreground",children:t}),(0,r.jsx)("span",{className:"min-w-0 break-words text-xs text-foreground",children:n})]})}function iZ(e){var t,n;let{task:a}=e,s=(0,c.c)("worktree"),l=a.contract,i=null!=(t=l.goal)?t:"",o=i.length>240?"".concat(i.slice(0,240),"…"):i;return(0,r.jsxs)("div",{className:"space-y-2","data-testid":"verification-contract",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"min-w-0 break-words text-sm font-medium text-foreground",children:l.title||a.title}),(0,r.jsx)(iT.E,{variant:iE[a.status],"data-testid":"verification-task-status",children:s("task.status.".concat(a.status))})]}),(0,r.jsx)("p",{className:"whitespace-pre-wrap break-words text-xs text-muted-foreground",children:o}),(0,r.jsxs)("div",{className:"space-y-1 pt-1",children:[(0,r.jsx)(iX,{label:s("verification.contract.scopeAllow"),children:(0,r.jsx)("span",{className:"font-mono",children:l.scope.allow.join(", ")||"—"})}),l.scope.deny.length>0&&(0,r.jsx)(iX,{label:s("verification.contract.scopeDeny"),children:(0,r.jsx)("span",{className:"font-mono",children:l.scope.deny.join(", ")})}),(0,r.jsx)(iX,{label:s("verification.contract.gates"),children:(0,r.jsx)("span",{className:"font-mono",children:null===l.verify.gates?s("verification.contract.gatesAll"):l.verify.gates.join(", ")||s("verification.contract.gatesAll")})}),(0,r.jsx)(iX,{label:s("verification.contract.autoYes"),children:(0,r.jsx)("span",{className:"font-mono",children:null!=(n=l.autoYes.mode)?n:s("verification.contract.autoYesUnset")})}),a.contractPath&&(0,r.jsx)(iX,{label:s("verification.contract.file"),children:(0,r.jsx)("span",{className:"font-mono",children:a.contractPath})}),(0,r.jsx)(iX,{label:s("verification.contract.updated"),children:iY(a.updatedAt)})]})]})}function i0(e){let{gate:t}=e;return(0,r.jsxs)("li",{className:"flex flex-col gap-0.5 rounded-md border border-border bg-surface px-2 py-1.5","data-testid":"verification-declared-gate-".concat(t.id),children:[(0,r.jsx)("span",{className:"break-all font-mono text-xs font-medium text-foreground",children:t.id}),(0,r.jsx)("span",{className:"break-all font-mono text-[11px] text-muted-foreground",children:t.command})]})}function i1(e){let{children:t,testId:n,tone:a="muted"}=e;return(0,r.jsx)("p",{className:"whitespace-pre-line break-words ".concat("warning"===a?"rounded border border-warning-border bg-warning-subtle px-2 py-1 text-xs text-warning-foreground":"text-xs text-muted-foreground"),"data-testid":n,role:"warning"===a?"alert":void 0,children:t})}function i2(e){var t,n,a,s,l,o;let{state:d}=e,u=(0,c.c)("worktree"),{config:m,configError:h,phase:f,runs:x,selectedRun:p,latestRun:g}=d,b=null!=(n=null==m?void 0:m.path)?n:iP,v=(0,i.useCallback)(()=>{d.draftConfig()},[d]),y=(0,i.useCallback)(()=>{d.rerun()},[d]),j=(0,i.useCallback)(()=>{g&&d.selectRun(g.id)},[g,d]),w=(0,i.useCallback)(()=>{d.cancelRun()},[d]),k=null!=(a=x.find(e=>"running"===e.status))?a:null,N=p&&k&&p.id===k.id?p.gates:[],C=N.filter(e=>"running"!==e.status).length,S=Math.max(null!=(s=null==m?void 0:m.plannedGateIds.length)?s:0,N.length),T=k?Date.now()-new Date(k.startedAt).getTime():0;return(0,r.jsxs)("section",{className:"space-y-2 border-b border-border px-3 py-3","data-testid":"verification-onboarding","data-phase":f,children:[(0,r.jsx)(i1,{testId:"verification-onboarding-what",children:u("verification.onboarding.what",{path:b})}),(0,r.jsx)(i1,{testId:"verification-onboarding-how",children:u("verification.onboarding.how")}),null!==h&&(0,r.jsx)(i1,{tone:"warning",testId:"verification-config-error",children:u("verification.onboarding.configError",{message:h})}),(null==m?void 0:m.error)!=null&&(0,r.jsx)(i1,{tone:"warning",testId:"verification-config-invalid",children:u("verification.onboarding.invalid",{path:b,message:m.error})}),"unknown"===f&&(0,r.jsx)(i1,{testId:"verification-onboarding-unknown",children:u("verification.onboarding.loading")}),"no-config"===f&&(0,r.jsxs)("div",{className:"space-y-2","data-testid":"verification-onboarding-no-config",children:[(0,r.jsx)(i1,{children:u("verification.onboarding.noConfig.body",{path:b})}),(0,r.jsx)(i1,{children:u("verification.onboarding.noConfig.hint")}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"primary",onClick:v,disabled:d.draftPending,"data-testid":"verification-draft-button",children:u(d.draftPending?"verification.onboarding.noConfig.pending":"verification.onboarding.noConfig.action")}),(0,r.jsxs)("a",{href:iR,target:"_blank",rel:"noreferrer noopener","data-testid":"verification-docs-link",className:"inline-flex items-center gap-1 rounded text-xs font-medium text-accent-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:text-accent-400 touch-manipulation",children:[u("verification.onboarding.noConfig.docs"),(0,r.jsx)(iS.A,{size:12,"aria-hidden":"true"})]})]}),d.draftFailure&&(0,r.jsx)(i1,{tone:"warning",testId:"verification-draft-failure",children:"conflict"===d.draftFailure.kind?u("verification.onboarding.noConfig.conflict",{path:b}):"empty"===d.draftFailure.kind?u("verification.onboarding.noConfig.empty",{path:b}):u("verification.onboarding.noConfig.error",{message:d.draftFailure.message})})]}),"configured"===f&&(0,r.jsxs)("div",{className:"space-y-2","data-testid":"verification-onboarding-configured",children:[(0,r.jsx)(i1,{children:u("verification.onboarding.configured.body",{path:b,count:null!=(l=null==m?void 0:m.gates.length)?l:0})}),(null==(t=d.draftResult)?void 0:t.created)&&(0,r.jsx)(i1,{testId:"verification-draft-created",children:u("verification.onboarding.noConfig.created",{path:d.draftResult.path,count:d.draftResult.gates.length})}),(0,r.jsx)("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:u("verification.onboarding.configured.gatesHeading")}),(0,r.jsx)("ul",{className:"space-y-1","data-testid":"verification-declared-gates",children:(null!=(o=null==m?void 0:m.gates)?o:[]).map(e=>(0,r.jsx)(i0,{gate:e},e.id))}),(0,r.jsx)(i1,{testId:"verification-builtin-gates",children:u("verification.onboarding.configured.builtin",{gates:(function(e){if(null===e)return[];let t=new Set(e.gates.map(e=>e.id));return e.plannedGateIds.filter(e=>!t.has(e))})(m).join(", ")})}),(0,r.jsx)(i1,{testId:"verification-builtin-gates-hint",children:u("verification.onboarding.configured.builtinHint")}),(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"primary",onClick:y,disabled:d.rerunPending,"data-testid":"verification-run-button",children:u(d.rerunPending?"verification.runs.rerunPending":"verification.onboarding.configured.action")})]}),"running"===f&&null!==k&&(0,r.jsxs)("div",{className:"space-y-1","data-testid":"verification-onboarding-running",children:[(0,r.jsx)(i1,{testId:"verification-running-progress",children:u("verification.onboarding.running.progress",{done:C,total:S})}),(0,r.jsx)(i1,{testId:"verification-running-elapsed",children:u("verification.onboarding.running.elapsed",{elapsed:function(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return"".concat(t,"s");let n=Math.floor(t/60);return"".concat(n,"m ").concat(String(t%60).padStart(2,"0"),"s")}(T)})}),(0,r.jsx)(i1,{children:u("verification.onboarding.running.hint")}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"secondary",onClick:d.refresh,"data-testid":"verification-running-refresh-button",children:u("verification.onboarding.running.action")}),(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"danger",onClick:w,disabled:d.cancelPending,"data-testid":"verification-cancel-button",children:u(d.cancelPending?"verification.runs.cancelPending":"verification.runs.cancel")})]}),(0,r.jsx)(i1,{testId:"verification-cancel-hint",children:u("verification.runs.cancelHint")}),d.cancelSettling&&(0,r.jsx)(i1,{testId:"verification-cancel-settling",children:u("verification.runs.cancelSettling")}),d.cancelFailure&&(0,r.jsx)(i1,{tone:"warning",testId:"verification-cancel-failure",children:"gone"===d.cancelFailure.kind?u("verification.runs.cancelGone"):u("verification.runs.cancelError",{message:d.cancelFailure.message})})]}),"result"===f&&null!==g&&(0,r.jsxs)("div",{className:"space-y-2","data-testid":"verification-onboarding-result",children:[(0,r.jsx)(i1,{testId:"verification-result-body",children:u("verification.onboarding.result.body",{runId:g.id,verdict:u("verification.runStatus.".concat(g.status))})}),(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"secondary",onClick:j,"data-testid":"verification-show-latest-button",children:u("verification.onboarding.result.action")})]})]})}function i5(e){let{state:t}=e,n=(0,c.c)("worktree"),[a,s]=(0,i.useState)(!1),{availableGateIds:l,selectedGateIds:o,failedGateIds:d,rerunPending:u}=t,m=(0,i.useCallback)(()=>s(e=>!e),[]),h=(0,i.useCallback)(()=>t.setGateSelection(null),[t]),f=(0,i.useCallback)(()=>{t.selectFailedGates(),s(!0)},[t]),x=(0,i.useCallback)(()=>{t.rerun()},[t]);if(0===l.length)return null;let p=null!=o?o:l,g=null===o,b=l.filter(e=>d.includes(e));return(0,r.jsxs)("div",{className:"mb-2 rounded-md border border-border bg-surface-2 px-2 py-2","data-testid":"verification-gate-selector","data-selection":g?"all":p.join(","),children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-semibold text-foreground",children:n("verification.selection.heading")}),(0,r.jsx)("button",{type:"button",onClick:m,"aria-expanded":a,"data-testid":"verification-gate-selector-toggle",className:"rounded text-[11px] font-medium text-accent-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:text-accent-400 touch-manipulation",children:a?n("verification.selection.close"):n("verification.selection.open")})]}),(0,r.jsx)("p",{className:"mt-0.5 break-words text-[11px] text-muted-foreground","data-testid":"verification-gate-selector-summary",children:g?n("verification.selection.all",{count:l.length}):n("verification.selection.partial",{selected:p.length,total:l.length,gates:p.join(", ")})}),a&&(0,r.jsxs)("div",{className:"mt-2 space-y-2","data-testid":"verification-gate-selector-body",children:[(0,r.jsx)("ul",{className:"space-y-1","data-testid":"verification-gate-checkboxes",children:l.map(e=>{let a="verification-gate-select-".concat(e),s=d.includes(e);return(0,r.jsxs)("li",{className:"flex items-center gap-2",children:[(0,r.jsx)(iI.S,{id:a,checked:p.includes(e),onCheckedChange:()=>t.toggleGate(e),"data-testid":a,"aria-label":n("verification.selection.gateLabel",{gateId:e})}),(0,r.jsx)("label",{htmlFor:a,className:"min-w-0 flex-1 cursor-pointer break-all font-mono text-[11px] text-foreground touch-manipulation",children:e}),s&&(0,r.jsx)(iT.E,{variant:"error",className:"flex-shrink-0",children:n("verification.gateStatus.failed")})]},e)})}),(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"primary",onClick:x,disabled:u,"data-testid":"verification-run-selected-button",children:u?n("verification.runs.rerunPending"):g?n("verification.selection.runAll"):n("verification.selection.runSelected",{count:p.length})}),(0,r.jsx)("p",{className:"break-words text-[11px] text-muted-foreground",children:n("verification.selection.hint")})]}),(0,r.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"secondary",onClick:f,disabled:0===b.length,"data-testid":"verification-failed-only-button",children:n("verification.selection.failedOnly",{count:b.length})}),!g&&(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"ghost",onClick:h,"data-testid":"verification-select-all-button",children:n("verification.selection.selectAll")})]}),0===b.length&&(0,r.jsx)("p",{className:"mt-1 break-words text-[11px] text-muted-foreground","data-testid":"verification-failed-only-empty",children:n("verification.selection.failedOnlyEmpty")})]})}function i4(e){let{state:t}=e,n=(0,c.c)("worktree"),{repositoryHistoryOpen:a,repositoryHistory:s,repositoryHistoryLoading:l,repositoryHistoryError:o}=t,d=(0,i.useCallback)(()=>{t.toggleRepositoryHistory()},[t]);return(0,r.jsxs)("div",{className:"mt-2","data-testid":"verification-repository-history",children:[(0,r.jsx)("button",{type:"button",onClick:d,"aria-expanded":a,"data-testid":"verification-repository-history-toggle",className:"rounded text-[11px] font-medium text-accent-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:text-accent-400 touch-manipulation",children:n(a?"verification.runs.history.close":"verification.runs.history.open")}),a&&(0,r.jsxs)("div",{className:"mt-1 space-y-1","data-testid":"verification-repository-history-body",children:[(0,r.jsx)("p",{className:"break-words text-[11px] text-muted-foreground",children:n("verification.runs.history.hint")}),null!==o?(0,r.jsx)("p",{className:"rounded border border-warning-border bg-warning-subtle px-2 py-1 text-[11px] text-warning-foreground","data-testid":"verification-repository-history-error",role:"alert",children:n("verification.runs.history.error",{message:o})}):l&&0===s.length?(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground",children:n("verification.runs.history.loading")}):0===s.length?(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"verification-repository-history-empty",children:n("verification.runs.history.empty")}):(0,r.jsx)("ul",{className:"space-y-1","data-testid":"verification-repository-history-runs",children:s.map(e=>(0,r.jsx)(i3,{run:e},e.id))})]})]})}function i3(e){let{run:t}=e,n=(0,c.c)("worktree"),a=t.status,s=t.gates.filter(e=>iL.includes(e.status)).map(e=>e.gateId);return(0,r.jsxs)("li",{className:"flex flex-col gap-0.5 rounded-md border border-border bg-surface px-2 py-1.5","data-testid":"verification-history-run-".concat(t.id),children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)(iT.E,{variant:iA[a],className:"flex-shrink-0",children:n("verification.runStatus.".concat(a))}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-foreground",children:t.worktreeId})]}),(0,r.jsxs)("span",{className:"flex flex-wrap gap-x-2 font-mono text-[11px] text-muted-foreground",children:[(0,r.jsx)("span",{children:n("verification.runs.runLabel",{runId:t.id})}),(0,r.jsx)("span",{children:iY(t.startedAt)})]}),s.length>0&&(0,r.jsx)("span",{className:"break-words text-[11px] text-muted-foreground",children:n("verification.runs.history.failingGates",{gates:s.join(", ")})})]})}function i6(e){let{gate:t,log:n,onClose:a}=e,s=(0,c.c)("worktree"),[l,o]=(0,i.useState)("idle"),d=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{null!==d.current&&clearTimeout(d.current)},[]);let u=""===n?0:n.replace(/\n+$/,"").split("\n").length,m=""!==n.trim(),h=(0,i.useCallback)(()=>{(async()=>{try{await (0,eq.l)(n),o("done")}catch(e){o("failed")}null!==d.current&&clearTimeout(d.current),d.current=setTimeout(()=>o("idle"),2e3)})()},[n]);return(0,r.jsx)(tN.a,{isOpen:!0,onClose:a,size:"xl",title:s("verification.gates.fullLogTitle",{gateId:t.gateId,runId:t.runId}),children:(0,r.jsxs)("div",{className:"space-y-2","data-testid":"verification-gate-full-log-".concat(t.gateId),children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxs)(tf.$,{type:"button",size:"sm",variant:"secondary",onClick:h,disabled:!m,"data-testid":"verification-gate-log-copy-button",children:[(0,r.jsx)(ej.A,{size:12,"aria-hidden":"true",className:"mr-1"}),s("done"===l?"verification.gates.copied":"failed"===l?"verification.gates.copyFailed":"verification.gates.copyLog")]}),(0,r.jsx)("span",{className:"font-mono text-[11px] text-muted-foreground","data-testid":"verification-gate-log-size",children:s("verification.gates.fullLogSize",{lines:u})})]}),(0,r.jsx)("p",{className:"break-words text-[11px] text-muted-foreground",children:s("verification.gates.fullLogStored")}),""===n?(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:s("verification.gates.noLog")}):(0,r.jsx)("pre",{className:"max-h-[60vh] overflow-auto rounded bg-terminal-surface p-2 font-mono text-[11px] leading-relaxed text-terminal-foreground",children:n})]})})}function i8(e){let{run:t,selected:n,onSelect:a}=e,s=(0,c.c)("worktree"),l=s("verification.runStatus.".concat(t.status)),i=s("verification.runStatusGloss.".concat(t.status)),o=i$[t.status];return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",onClick:()=>a(t.id),"aria-current":n?"true":void 0,"aria-label":s("verification.runs.select",{runId:t.id,verdict:l,gloss:i}),title:i,"data-testid":"verification-run-".concat(t.id),className:"flex w-full flex-col gap-0.5 rounded-md border px-2 py-2 text-left text-xs transition-colors touch-manipulation focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ".concat(n?"border-accent-500 bg-accent-50 dark:bg-accent-900/30":"border-border bg-surface hover:bg-muted"),children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)(iT.E,{variant:iA[t.status],className:"flex-shrink-0",children:l}),(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate text-foreground",children:iY(t.startedAt)})]}),(0,r.jsxs)("span",{className:"flex flex-wrap gap-x-2 font-mono text-[11px] text-muted-foreground",children:[(0,r.jsx)("span",{children:s("verification.runs.runLabel",{runId:t.id})}),(0,r.jsx)("span",{children:s("verification.runs.trigger",{trigger:t.trigger})}),null!==o&&(0,r.jsx)("span",{children:s("verification.runs.exitCode",{code:o})})]})]})})}function i9(){let e=(0,c.c)("worktree"),t=iq.map(t=>{var n;return e("verification.runs.cliLegendItem",{label:e("verification.runStatus.".concat(t)),code:null!=(n=i$[t])?n:0})}).join(" / ");return(0,r.jsx)("p",{className:"mb-2 break-words text-[11px] text-muted-foreground","data-testid":"verification-cli-exit-legend",children:e("verification.runs.cliLegend",{items:t})})}function i7(e){let{run:t,plannedGateIds:n}=e,a=(0,c.c)("worktree"),s=i$[t.status],l=t.gates.filter(e=>"skipped"===e.status),i=new Set(t.gates.map(e=>e.gateId)),o=n.filter(e=>!i.has(e));return(0,r.jsxs)("div",{className:"mb-2 space-y-1 rounded-md border border-border bg-surface-2 px-2 py-2","data-testid":"verification-run-verdict",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-semibold text-foreground",children:a("verification.gates.verdictHeading")}),(0,r.jsx)(iT.E,{variant:iA[t.status],className:"flex-shrink-0",children:a("verification.runStatus.".concat(t.status))}),null!==s&&(0,r.jsx)("span",{className:"font-mono text-[11px] text-muted-foreground",children:a("verification.runs.exitCode",{code:s})})]}),(0,r.jsx)("p",{className:"break-words text-xs text-muted-foreground","data-testid":"verification-run-verdict-gloss",children:a("verification.runStatusGloss.".concat(t.status))}),o.length>0&&(0,r.jsx)("p",{className:"rounded border border-warning-border bg-warning-subtle px-2 py-1 text-xs text-warning-foreground","data-testid":"verification-run-partial",children:a("verification.runs.partial",{ran:i.size,total:n.length,gates:o.join(", ")})}),l.length>0&&(0,r.jsxs)("div",{className:"space-y-0.5 pt-1","data-testid":"verification-run-skip-reasons",children:[(0,r.jsx)("p",{className:"text-xs font-semibold text-foreground",children:a("verification.gates.skipHeading")}),(0,r.jsx)("ul",{className:"space-y-0.5",children:l.map(e=>(0,r.jsx)("li",{className:"break-words text-xs text-muted-foreground",children:a("verification.gates.skipReasonFor",{gateId:e.gateId,reason:a("verification.gates.skipReason.".concat(function(e){let t=null!=e?e:"";return t.includes("skipped: worktreePath is the server process working directory and options.skipInPrimaryCheckout is true.")?"primaryCheckout":t.includes("skipped: the work-evidence gate did not pass.")?"workEvidence":t.includes("skipped: the verification run was cancelled.")?"cancelled":t.includes(iJ.mutex)?"mutex":t.includes(iJ.detachedContract)?"detachedContract":t.includes(iJ.noContract)?"noContract":t.includes(iJ.notRequired)?"notRequired":"unknown"}(e.logTail)))})},e.id))})]})]})}function oe(e){var t,n;let{gate:a}=e,s=(0,c.c)("worktree"),l=iL.includes(a.status),[o,d]=(0,i.useState)(null),[u,m]=(0,i.useState)(!1),h=(0,i.useCallback)(()=>m(!1),[]),f=null!=o?o:l,x=tz(null!=(t=a.logTail)?t:""),p=function(e,t){let n=(null!=e?e:"").replace(/\n+$/,"");if(""===n)return{lines:[],omitted:0};let a=n.split("\n");return a.length<=40?{lines:a,omitted:0}:{lines:a.slice(-40),omitted:a.length-t}}(x,40),g=function(e){if(null==e||!Number.isFinite(e))return null;if(e<1e3)return"".concat(Math.max(0,Math.round(e)),"ms");let t=e/1e3;return t<10?"".concat(t.toFixed(1),"s"):"".concat(Math.round(t),"s")}(a.durationMs),b=null!=(n=iG[a.gateId])?n:null;return(0,r.jsxs)("li",{className:"rounded-md border border-border bg-surface p-2","data-testid":"verification-gate-".concat(a.gateId),children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)(iT.E,{variant:iM[a.status],className:"flex-shrink-0",children:s("verification.gateStatus.".concat(a.status))}),(0,r.jsx)("span",{className:"min-w-0 break-all font-mono text-xs font-medium text-foreground",children:a.gateId}),"contract"===a.source&&(0,r.jsx)("span",{className:"font-mono text-[10px] text-muted-foreground",title:s("verification.gates.contractSourceHint"),children:s("verification.gates.contractSource")}),null!==b&&(0,r.jsx)("span",{className:"text-[10px] text-muted-foreground",children:s("verification.gates.builtinBadge")})]}),null!==b&&(0,r.jsx)("p",{className:"mt-1 break-words text-[11px] text-muted-foreground","data-testid":"verification-gate-about-".concat(a.gateId),children:s("verification.gates.builtin.".concat(b))}),"skipped"===a.status&&(0,r.jsxs)("p",{className:"mt-1 break-words text-[11px] text-muted-foreground","data-testid":"verification-gate-skipped-".concat(a.gateId),children:[s("verification.gateStatus.skipped")," — ",s("verification.gateStatusGloss.skipped")]}),(0,r.jsxs)("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-0.5 font-mono text-[11px] text-muted-foreground",children:[null!==a.exitCode&&void 0!==a.exitCode&&(0,r.jsx)("span",{children:s("verification.gates.exitCode",{code:a.exitCode})}),g&&(0,r.jsx)("span",{children:s("verification.gates.duration",{duration:g})}),a.command&&(0,r.jsx)("span",{className:"break-all",children:a.command})]}),(0,r.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,r.jsx)("button",{type:"button",onClick:()=>d(!f),"aria-expanded":f,"data-testid":"verification-gate-log-toggle-".concat(a.gateId),className:"rounded text-[11px] font-medium text-accent-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:text-accent-400 touch-manipulation",children:s(f?"verification.gates.hideLog":"verification.gates.showLog")}),""!==x&&(0,r.jsx)("button",{type:"button",onClick:()=>m(!0),"data-testid":"verification-gate-full-log-button-".concat(a.gateId),className:"rounded text-[11px] font-medium text-accent-600 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:text-accent-400 touch-manipulation",children:s("verification.gates.showFullLog")})]}),u&&(0,r.jsx)(i6,{gate:a,log:x,onClose:h}),f&&(0,r.jsx)("div",{className:"mt-1","data-testid":"verification-gate-log-".concat(a.gateId),children:0===p.lines.length?(0,r.jsx)("p",{className:"text-[11px] text-muted-foreground",children:s("verification.gates.noLog")}):(0,r.jsxs)(r.Fragment,{children:[p.omitted>0&&(0,r.jsx)("p",{className:"mb-1 text-[11px] text-muted-foreground",children:s("verification.gates.logOmitted",{count:p.omitted,runId:a.runId})}),(0,r.jsx)("pre",{className:"max-h-64 overflow-auto rounded bg-terminal-surface p-2 font-mono text-[11px] leading-relaxed text-terminal-foreground",children:p.lines.join("\n")})]})})]})}let ot=(0,i.memo)(function(e){var t,n;let{state:a,className:s=""}=e,l=(0,c.c)("worktree"),{worktreeId:o,task:d,runs:u,selectedRunId:m,selectedRun:h,loading:f,error:x,detailError:p,detailLoading:g,rerunPending:b,rerunFailure:v,cancelFailure:y,canLoadMore:j,selectRun:w,refresh:k,rerun:N,loadMore:C}=a,S=(0,i.useCallback)(()=>{N()},[N]);return(0,r.jsxs)("div",{className:"flex h-full flex-col overflow-y-auto bg-surface ".concat(s).trim(),"data-testid":"verification-pane",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-2",children:[(0,r.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,r.jsx)(n7.A,{size:16,"aria-hidden":"true",className:"flex-shrink-0 text-muted-foreground"}),(0,r.jsx)("h2",{className:"truncate text-sm font-semibold text-foreground",children:l("verification.title")})]}),(0,r.jsx)("button",{type:"button",onClick:k,"aria-label":l("verification.refresh"),title:l("verification.refresh"),"data-testid":"verification-refresh-button",className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:(0,r.jsx)(sB.A,{size:14,"aria-hidden":"true"})})]}),x&&(0,r.jsx)("p",{className:"border-b border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-foreground","data-testid":"verification-error",role:"alert",children:l("verification.loadError",{message:x})}),f?(0,r.jsx)("p",{className:"px-3 py-4 text-xs text-muted-foreground","data-testid":"verification-loading",children:l("verification.loading")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i2,{state:a}),(0,r.jsx)(iQ,{heading:l("verification.contract.heading"),testId:"verification-contract-section",children:d?(0,r.jsx)(iZ,{task:d}):(0,r.jsx)("p",{className:"whitespace-pre-line text-xs text-muted-foreground","data-testid":"verification-contract-empty",children:l("verification.contract.empty")})}),(0,r.jsxs)(iQ,{heading:l("verification.runs.heading"),testId:"verification-runs-section",action:(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"secondary",onClick:S,disabled:b,"data-testid":"verification-rerun-button",children:l(b?"verification.runs.rerunPending":"verification.runs.rerun")}),children:[v&&(0,r.jsx)("p",{className:"mb-2 rounded border border-warning-border bg-warning-subtle px-2 py-1 text-xs text-warning-foreground","data-testid":"verification-rerun-failure",role:"alert",children:"conflict"===v.kind?null!==v.runningRunId?l("verification.runs.rerunConflict",{runId:v.runningRunId}):l("verification.runs.rerunConflictUnknown"):l("verification.runs.rerunError",{message:v.message})}),y&&(0,r.jsx)("p",{className:"mb-2 rounded border border-warning-border bg-warning-subtle px-2 py-1 text-xs text-warning-foreground","data-testid":"verification-runs-cancel-failure",role:"alert",children:"gone"===y.kind?l("verification.runs.cancelGone"):l("verification.runs.cancelError",{message:y.message})}),(0,r.jsx)(i5,{state:a}),(0,r.jsx)(i9,{}),0===u.length?(0,r.jsx)("p",{className:"whitespace-pre-line text-xs text-muted-foreground","data-testid":"verification-runs-empty",children:l("verification.runs.empty",{worktreeId:o})}):(0,r.jsx)("ul",{className:"space-y-1","data-testid":"verification-runs",children:u.map(e=>(0,r.jsx)(i8,{run:e,selected:e.id===m,onSelect:w},e.id))}),j&&(0,r.jsx)(tf.$,{type:"button",size:"sm",variant:"ghost",onClick:C,className:"mt-1","data-testid":"verification-load-more-button",children:l("verification.runs.loadMore",{count:10})}),(0,r.jsx)(i4,{state:a})]}),null!==m&&(0,r.jsx)(iQ,{heading:l("verification.gates.heading",{runId:m}),testId:"verification-gates-section",children:null!==p?(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"verification-gates-error",role:"alert",children:"not-found"===p?l("verification.gates.notFound"):l("verification.gates.loadError",{message:p})}):null===h?(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"verification-gates-loading",children:l(g?"verification.gates.loading":"verification.gates.empty")}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i7,{run:h,plannedGateIds:null!=(n=null==(t=a.config)?void 0:t.plannedGateIds)?n:[]}),0===h.gates.length?(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"verification-gates-empty",children:l("verification.gates.empty")}):(0,r.jsx)("ul",{className:"space-y-1.5","data-testid":"verification-gates",children:h.gates.map(e=>(0,r.jsx)(oe,{gate:e},e.id))}),h.gates.some(e=>"contract"===e.source)&&(0,r.jsx)("p",{className:"mt-2 break-words text-[11px] text-muted-foreground","data-testid":"verification-contract-source-hint",children:l("verification.gates.contractSourceHint")})]})})]})]})});var on=n(70532),oa=n(46046),or=n(47972),os=n(5590),ol=n(25840);class oi extends Error{constructor(e,t,n=[]){super(t),this.name="EnvApiError",this.code=e,this.issues=n}}async function oo(e,t){var n,a,r,s,l,i;let o=await e.json().catch(()=>null);return new oi(null!=(s=null==o||null==(n=o.error)?void 0:n.code)?s:"HTTP_".concat(e.status),null!=(l=null==o||null==(a=o.error)?void 0:a.message)?l:t,null!=(i=null==o||null==(r=o.error)?void 0:r.issues)?i:[])}function oc(e,t){let n="/api/worktrees/".concat(encodeURIComponent(e),"/env");return void 0===t?n:"".concat(n,"?file=").concat(encodeURIComponent(t))}async function od(e,t){var n,a;let r=await fetch(oc(e,t),{cache:"no-store"});if(!r.ok)throw await oo(r,"Failed to load env files");let s=await r.json();return{files:null!=(n=s.files)?n:[],selected:null!=(a=s.selected)?a:null}}async function ou(e,t,n){var a;let r=await fetch(oc(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:t,content:n})});if(!r.ok)throw await oo(r,"Failed to save env file");let s=await r.json();return{file:s.file,issues:null!=(a=s.issues)?a:[]}}let om=/^[A-Za-z_][A-Za-z0-9_]*$/;function oh(e){return e.split(/\r\n|\n|\r/)}function of(e,t,n){for(let a=n;a<e.length;a+=1){if('"'===t&&"\\"===e[a]){a+=1;continue}if(e[a]===t)return a}return -1}function ox(e){let t=oh(e),n=[],a=[],r=new Map;for(let e=0;e<t.length;e+=1){let s,l=e+1,i=t[e].trim();if(""===i||i.startsWith("#"))continue;let o=/^export\s+/.test(i),c=o?i.replace(/^export\s+/,""):i,d=c.indexOf("=");if(-1===d){a.push({line:l,code:"invalid-syntax",severity:"error"});continue}let u=c.slice(0,d).trim();if(!om.test(u)){a.push({line:l,code:"invalid-key",severity:"error",...u.length>0&&u.length<=64?{key:u}:{}});continue}let m=c.slice(d+1).replace(/^[ \t]+/,""),h=null,f=l;if(m.startsWith('"')||m.startsWith("'")){h=m[0];let n=m.slice(1),r=of(n,h,0);for(;-1===r&&e+1<t.length;)e+=1,f=e+1,n+="\n".concat(t[e]),r=of(n,h,0);if(-1===r){a.push({line:l,code:"unterminated-quote",severity:"error",key:u});continue}let i=n.slice(0,r);s='"'===h?function(e){let t="";for(let n=0;n<e.length;n+=1){let a=e[n];if("\\"!==a||n===e.length-1){t+=a;continue}let r=e[n+1];switch(n+=1,r){case"n":t+="\n";break;case"r":t+="\r";break;case"t":t+=" ";break;case"\\":t+="\\";break;case'"':t+='"';break;default:t+="\\".concat(r)}}return t}(i):i}else s=(function(e){let t=/\s#/.exec(e);return t?e.slice(0,t.index):e})(m).replace(/[ \t]+$/,"");void 0!==r.get(u)&&a.push({line:l,code:"duplicate-key",severity:"warning",key:u}),r.set(u,l),n.push({key:u,value:s,line:l,endLine:f,exported:o,quote:h})}return{entries:n,issues:a}}let op=/[\s#'"$`\\]/;function og(e){if(!op.test(e))return e;let t=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t");return'"'.concat(t,'"')}function ob(e,t,n){let a=oh(e),r=new Map(t.map(e=>[e.line,e])),s=new Map,l=[];for(let e of n)null!==e.sourceLine&&r.has(e.sourceLine)?s.set(e.sourceLine,e):l.push(e);let i=[],o=0;for(let e=0;e<a.length;e+=1){let t=e+1;if(t<=o)continue;let n=r.get(t);if(!n){i.push(a[e]);continue}o=n.endLine;let l=s.get(t);l&&i.push("".concat(n.exported?"export ":"").concat(l.key,"=").concat(og(l.value)))}for(let e of(i.length>0&&""===i[i.length-1]&&i.pop(),l))i.push("".concat(e.key,"=").concat(og(e.value)));return 0===i.length?"":"".concat(i.join("\n"),"\n")}let ov=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/,oy=0;function oj(){return oy+=1,"env-row-".concat(oy)}function ow(e){return e.map(e=>({id:oj(),key:e.key,value:e.value,sourceLine:e.line}))}let ok="••••••••";function oN(e){return 0===e.length?"":ok}let oC="flex-shrink-0 px-2 opacity-80 transition-opacity hover:opacity-100 [@media(hover:none)]:opacity-100",oS={"invalid-syntax":"envManager.issues.invalidSyntax","invalid-key":"envManager.issues.invalidKey","unterminated-quote":"envManager.issues.unterminatedQuote","duplicate-key":"envManager.issues.duplicateKey","control-character":"envManager.issues.controlCharacter","too-large":"envManager.issues.tooLarge","too-many-entries":"envManager.issues.tooManyEntries"},oT=(0,i.memo)(function(e){let{worktreeId:t,className:n=""}=e,a=(0,c.c)("worktree"),s=function(e){var t;let[n,a]=(0,i.useState)([]),[r,s]=(0,i.useState)(".env"),[l,o]=(0,i.useState)(null),[c,d]=(0,i.useState)(!0),[u,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)("kv"),[v,y]=(0,i.useState)([]),[j,w]=(0,i.useState)(""),[k,N]=(0,i.useState)(""),[C,S]=(0,i.useState)([]),[T,I]=(0,i.useState)(""),[E,A]=(0,i.useState)(new Set),[M,L]=(0,i.useState)(!1),[R,P]=(0,i.useState)(0),D=(0,i.useRef)(0);(0,i.useEffect)(()=>{let t=!1,n=D.current+1;return D.current=n,d(!0),f(null),p(!1),od(e,r).then(e=>{var r,s;if(t||D.current!==n)return;a(e.files);let l=e.selected;o(l);let i=null!=(r=null==l?void 0:l.content)?r:"",c=null!=(s=null==l?void 0:l.entries)?s:[];I(i),N(i),S(c),y(ow(c)),w(i),A(new Set),L(!1)}).catch(e=>{var a,r;if(t||D.current!==n)return;let s=e instanceof oi?e:null;f({code:null!=(a=null==s?void 0:s.code)?a:"UNKNOWN",message:null!=(r=null==s?void 0:s.message)?r:e instanceof Error?e.message:"Failed to load"}),o(null)}).finally(()=>{t||D.current!==n||d(!1)}),()=>{t=!0}},[e,r,R]);let F=(0,i.useMemo)(()=>"raw"===g?j:ob(k,C,v),[g,j,k,C,v]),O=(0,i.useMemo)(()=>(function(e){let t=[];if("string"!=typeof e)return{valid:!1,issues:[{line:null,code:"invalid-syntax",severity:"error"}],entries:[]};if(new TextEncoder().encode(e).length>262144)return{valid:!1,issues:[{line:null,code:"too-large",severity:"error"}],entries:[]};let n=e.split(/\r\n|\n|\r/);for(let e=0;e<n.length;e+=1)ov.test(n[e])&&t.push({line:e+1,code:"control-character",severity:"error"});let a=ox(e);return t.push(...a.issues),a.entries.length>1e3&&t.push({line:null,code:"too-many-entries",severity:"error"}),t.sort((e,t)=>{var n,a;return(null!=(n=e.line)?n:0)-(null!=(a=t.line)?a:0)}),{valid:!t.some(e=>"error"===e.severity),issues:t,entries:a.entries}})(F),[F]),z=(0,i.useMemo)(()=>"raw"===g?j!==T:k!==T||v.length!==C.length||v.some((e,t)=>{var n,a;return e.key!==(null==(n=C[t])?void 0:n.key)||e.value!==(null==(a=C[t])?void 0:a.value)}),[g,j,T,k,v,C]),_=(0,i.useCallback)(e=>{if(e!==g){if("raw"===e)w(ob(k,C,v));else{let e=ox(j);N(j),S(e.entries),y(ow(e.entries))}b(e)}},[g,k,C,v,j]),B=(0,i.useCallback)(e=>{s(e),b("kv")},[]),H=(0,i.useCallback)(e=>{w(e),p(!1)},[]),V=(0,i.useCallback)((e,t)=>{y(n=>n.map(n=>n.id===e?{...n,...t}:n)),p(!1)},[]),U=(0,i.useCallback)(e=>{var t,n;let a={id:oj(),key:null!=(t=null==e?void 0:e.key)?t:"",value:null!=(n=null==e?void 0:e.value)?n:"",sourceLine:null};y(e=>[...e,a]),p(!1),(null==e?void 0:e.key)&&A(t=>new Set([...t,e.key]))},[]),K=(0,i.useCallback)(e=>{y(t=>t.filter(t=>t.id!==e)),p(!1)},[]),W=(0,i.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),$=(0,i.useCallback)(()=>L(e=>!e),[]),q=(0,i.useCallback)(()=>{A(new Set(v.map(e=>e.key)))},[v]),G=(0,i.useCallback)(()=>A(new Set),[]),J=(0,i.useCallback)(()=>P(e=>e+1),[]),Y=(0,i.useCallback)(()=>{O.valid&&!u&&(m(!0),f(null),ou(e,r,F).then(()=>{p(!0),P(e=>e+1)}).catch(e=>{var t,n;let a=e instanceof oi?e:null;f({code:null!=(t=null==a?void 0:a.code)?t:"UNKNOWN",message:null!=(n=null==a?void 0:a.message)?n:e instanceof Error?e.message:"Failed to save"})}).finally(()=>m(!1)))},[O.valid,u,e,r,F]);return{files:n,selectedFile:r,detail:l,loading:c,saving:u,error:h,saved:x,mode:g,rows:v,rawDraft:j,revealedKeys:E,rawRevealed:M,suggestions:null!=(t=null==l?void 0:l.suggestions)?t:[],issues:O.issues,canSave:O.valid,dirty:z,selectFile:B,setMode:_,setRawDraft:H,updateRow:V,addRow:U,removeRow:K,toggleReveal:W,toggleRawReveal:$,revealAll:q,hideAll:G,reload:J,save:Y}}(t),{mode:l,rows:o,revealedKeys:d,rawRevealed:m}=s,h=(0,i.useMemo)(()=>s.issues.filter(e=>"error"===e.severity),[s.issues]),f=(0,i.useMemo)(()=>s.issues.filter(e=>"warning"===e.severity),[s.issues]),x="raw"===l?m:o.length>0&&o.every(e=>d.has(e.key)),p=(0,i.useCallback)(()=>{if("raw"===l)return void s.toggleRawReveal();x?s.hideAll():s.revealAll()},[l,x,s]),g=(0,i.useMemo)(()=>"raw"!==l||m?"":function(e,t){let n=e.split(/\r\n|\n|\r/),a=new Map,r=new Set;for(let e of t){a.set(e.line,e);for(let t=e.line+1;t<=e.endLine;t+=1)r.add(t)}let s=[];for(let e=0;e<n.length;e+=1){let t=e+1;if(r.has(t))continue;let l=a.get(t);if(!l){s.push(n[e]);continue}s.push("".concat(l.exported?"export ":"").concat(l.key,"=").concat(oN(l.value)))}return s.join("\n")}(s.rawDraft,ox(s.rawDraft).entries),[l,m,s.rawDraft]),b=(0,i.useCallback)((e,t)=>{var n,s,l;return(0,r.jsx)("li",{children:a(oS[e.code],{line:null!=(n=e.line)?n:0,key:null!=(s=e.key)?s:""})},"".concat(e.code,"-").concat(null!=(l=e.line)?l:"file","-").concat(t))},[a]);return(0,r.jsxs)("div",{"data-testid":"env-manager-pane",role:"region","aria-label":a("envManager.title"),className:"flex flex-col h-full min-h-0 bg-background ".concat(n).trim(),children:[(0,r.jsxs)("div",{className:"flex-shrink-0 border-b border-border bg-surface dark:bg-surface-2 p-2 space-y-2",children:[(0,r.jsx)("div",{role:"group","aria-label":a("envManager.filePickerLabel"),className:"flex gap-1 overflow-x-auto scrollbar-hide",children:s.files.map(e=>(0,r.jsxs)(tf.$,{size:"sm",variant:e.name===s.selectedFile?"primary":"ghost",onClick:()=>s.selectFile(e.name),"aria-pressed":e.name===s.selectedFile,"data-testid":"env-file-".concat(e.name),className:"flex-shrink-0 whitespace-nowrap min-h-[44px] gap-1.5 font-mono text-xs",children:[e.name,!e.exists&&(0,r.jsx)(iT.E,{variant:"gray",children:a("envManager.notCreated")}),e.isExample&&(0,r.jsx)(iT.E,{variant:"info",children:a("envManager.templateBadge")})]},e.name))}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxs)("div",{role:"group","aria-label":a("envManager.viewModeLabel"),className:"flex gap-1",children:[(0,r.jsx)(tf.$,{size:"sm",variant:"kv"===l?"primary":"ghost",onClick:()=>s.setMode("kv"),"aria-pressed":"kv"===l,"data-testid":"env-mode-kv",className:"min-h-[44px]",children:a("envManager.viewKeyValue")}),(0,r.jsx)(tf.$,{size:"sm",variant:"raw"===l?"primary":"ghost",onClick:()=>s.setMode("raw"),"aria-pressed":"raw"===l,"data-testid":"env-mode-raw",className:"min-h-[44px]",children:a("envManager.viewRaw")})]}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[(0,r.jsxs)(tf.$,{size:"sm",variant:"ghost",onClick:p,"data-testid":"env-toggle-all","aria-pressed":x,className:"min-h-[44px] gap-1.5",children:[x?(0,r.jsx)(on.A,{size:16,"aria-hidden":"true"}):(0,r.jsx)(eJ.A,{size:16,"aria-hidden":"true"}),(0,r.jsx)("span",{className:"hidden sm:inline",children:x?a("envManager.hideAll"):a("envManager.revealAll")})]}),(0,r.jsx)(tf.$,{size:"sm",variant:"ghost",onClick:s.reload,"data-testid":"env-reload","aria-label":a("envManager.reload"),className:"min-h-[44px]",children:(0,r.jsx)(sB.A,{size:16,"aria-hidden":"true"})}),(0,r.jsxs)(tf.$,{size:"sm",variant:"primary",onClick:s.save,loading:s.saving,disabled:!s.canSave||!s.dirty,"data-testid":"env-save",className:"min-h-[44px] gap-1.5",children:[(0,r.jsx)(oa.A,{size:16,"aria-hidden":"true"}),a("envManager.save")]})]})]})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-3",children:[(0,r.jsx)("p",{"data-testid":"env-description",className:"text-xs text-muted-foreground",children:a("envManager.description")}),s.loading&&(0,r.jsxs)("div",{className:"flex items-center gap-2 p-4 text-sm text-muted-foreground",children:[(0,r.jsx)(u.y,{size:"sm"}),a("envManager.loading")]}),s.error&&(0,r.jsx)("div",{role:"alert","data-testid":"env-error",className:"rounded-md border border-danger-border bg-danger-subtle p-2 text-sm text-danger-foreground",children:a("envManager.loadError")}),!s.loading&&s.detail&&!s.detail.exists&&(0,r.jsx)("p",{"data-testid":"env-not-created",className:"rounded-md border border-border bg-muted p-2 text-xs text-muted-foreground",children:a("envManager.notCreatedHint",{file:s.selectedFile})}),s.saved&&!s.dirty&&(0,r.jsx)("p",{"data-testid":"env-saved",className:"text-xs text-success-foreground",children:a("envManager.saved")}),h.length>0&&(0,r.jsxs)("div",{role:"alert","data-testid":"env-errors",className:"rounded-md border border-danger-border bg-danger-subtle p-2 text-xs text-danger-foreground",children:[(0,r.jsxs)("p",{className:"flex items-center gap-1.5 font-medium",children:[(0,r.jsx)(lR.A,{size:14,"aria-hidden":"true"}),a("envManager.validationFailed")]}),(0,r.jsx)("ul",{className:"mt-1 list-disc pl-5 space-y-0.5",children:h.map(b)})]}),f.length>0&&(0,r.jsx)("div",{"data-testid":"env-warnings",className:"rounded-md border border-warning-border bg-warning-subtle p-2 text-xs text-warning-foreground",children:(0,r.jsx)("ul",{className:"list-disc pl-5 space-y-0.5",children:f.map(b)})}),!s.loading&&"kv"===l&&(0,r.jsxs)("div",{"data-testid":"env-kv-view",className:"space-y-2",children:[0===o.length&&(0,r.jsx)("p",{"data-testid":"env-empty",className:"px-1 py-4 text-center text-sm text-muted-foreground",children:a("envManager.empty")}),o.map(e=>{let t=d.has(e.key);return(0,r.jsxs)("div",{"data-testid":"env-row","data-env-key":e.key,className:"flex flex-col gap-1 rounded-md border border-border bg-surface dark:bg-surface-2 p-2 sm:flex-row sm:items-center sm:gap-2",children:[(0,r.jsx)(os.p,{inputSize:"sm",value:e.key,onChange:t=>s.updateRow(e.id,{key:t.target.value}),"aria-label":a("envManager.keyLabel"),spellCheck:!1,autoComplete:"off","data-testid":"env-row-key",className:"font-mono text-xs sm:w-2/5"}),(0,r.jsxs)("div",{className:"flex flex-1 items-center gap-1",children:[(0,r.jsx)(os.p,{inputSize:"sm",readOnly:!t,value:t?e.value:oN(e.value),onChange:t=>s.updateRow(e.id,{value:t.target.value}),"aria-label":a("envManager.valueLabel",{key:e.key}),spellCheck:!1,autoComplete:"off","data-testid":"env-row-value","data-masked":t?"false":"true",className:"flex-1 font-mono text-xs"}),(0,r.jsx)(tf.$,{size:"sm",variant:"ghost",onClick:()=>s.toggleReveal(e.key),"aria-label":t?a("envManager.hideValue",{key:e.key}):a("envManager.showValue",{key:e.key}),"aria-pressed":t,"data-testid":"env-row-reveal",className:"".concat(oC," min-h-[44px]"),children:t?(0,r.jsx)(on.A,{size:16,"aria-hidden":"true"}):(0,r.jsx)(eJ.A,{size:16,"aria-hidden":"true"})}),(0,r.jsx)(tf.$,{size:"sm",variant:"ghost",onClick:()=>s.removeRow(e.id),"aria-label":a("envManager.removeRow",{key:e.key}),"data-testid":"env-row-remove",className:"".concat(oC," min-h-[44px] text-danger"),children:(0,r.jsx)(sv.A,{size:16,"aria-hidden":"true"})})]})]},e.id)}),(0,r.jsxs)(tf.$,{size:"sm",variant:"secondary",onClick:()=>s.addRow(),"data-testid":"env-add-row",className:"min-h-[44px] gap-1.5",children:[(0,r.jsx)(lz.A,{size:16,"aria-hidden":"true"}),a("envManager.addRow")]}),s.suggestions.length>0&&(0,r.jsxs)(or.Zp,{"data-testid":"env-suggestions",className:"mt-3",children:[(0,r.jsxs)(or.aR,{children:[(0,r.jsx)(or.ZB,{className:"text-sm",children:a("envManager.suggestionsTitle")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:a("envManager.suggestionsHint")})]}),(0,r.jsx)(or.Wu,{className:"flex flex-wrap gap-2",children:s.suggestions.map(e=>(0,r.jsxs)(tf.$,{size:"sm",variant:"secondary",onClick:()=>s.addRow({key:e.key,value:e.value}),"data-testid":"env-suggestion-".concat(e.key),className:"min-h-[44px] gap-1.5 font-mono text-xs",children:[(0,r.jsx)(lz.A,{size:14,"aria-hidden":"true"}),e.key,(0,r.jsx)("span",{className:"font-sans text-muted-foreground",children:e.source})]},"".concat(e.source,":").concat(e.key)))})]})]}),!s.loading&&"raw"===l&&(0,r.jsx)("div",{"data-testid":"env-raw-view",className:"space-y-2",children:m?(0,r.jsx)(ol.T,{value:s.rawDraft,onChange:e=>s.setRawDraft(e.target.value),"aria-label":a("envManager.rawLabel"),spellCheck:!1,"data-testid":"env-raw-editor",className:"min-h-[240px] font-mono text-xs"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ol.T,{readOnly:!0,value:g,"aria-label":a("envManager.rawMaskedLabel"),spellCheck:!1,"data-testid":"env-raw-masked",className:"min-h-[240px] font-mono text-xs"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:a("envManager.rawMaskedHint",{mask:ok})})]})})]})]})}),oI=[{id:"notes",labelKey:"notes"},{id:"logs",labelKey:"logs"},{id:"agent",labelKey:"agentTab"},{id:"timer",labelKey:"timerTab"},{id:"todo",labelKey:"todoTab"},{id:"skills",labelKey:"skillsTab"},{id:"verification",labelKey:"verificationTab"},{id:"env",labelKey:"envTab"}],oE=(0,i.memo)(function(e){var t,n;let{worktreeId:a,className:s="",selectedAgents:l,onSelectedAgentsChange:o,vibeLocalModel:d,onVibeLocalModelChange:u,vibeLocalContextWindow:m,onVibeLocalContextWindowChange:h,maxAgents:f,availableAgents:x,persistToServer:p,onInsertToMessage:g,useInstanceManagement:b=!1,instances:v,onInstancesChange:y,visibleInstanceIds:j,onToggleInstanceVisible:w,modelByInstance:k,composerTargetInstanceId:N,verification:C,requestedSubTab:S}=e,T=(0,c.c)("schedule"),[I,E]=(0,i.useState)(null!=(t=null==S?void 0:S.tab)?t:"notes"),A=(0,i.useRef)(null!=(n=null==S?void 0:S.token)?n:null);(0,i.useEffect)(()=>{S&&S.token!==A.current&&(A.current=S.token,E(S.tab))},[S]);let M=(0,i.useCallback)(e=>{E(e)},[]),L=(0,i.useRef)({});return(0,i.useEffect)(()=>{var e,t;null==(t=L.current[I])||null==(e=t.scrollIntoView)||e.call(t,{block:"nearest",inline:"nearest"})},[I]),(0,r.jsxs)("div",{className:"flex flex-col h-full ".concat(s),children:[(0,r.jsx)("div",{className:"flex overflow-x-auto scrollbar-hide border-b border-border bg-surface dark:bg-surface-2 flex-shrink-0",children:oI.map(e=>(0,r.jsx)("button",{type:"button",ref:t=>{L.current[e.id]=t},onClick:()=>M(e.id),className:"flex-shrink-0 whitespace-nowrap px-3 py-2 text-sm font-medium transition-colors ".concat(I===e.id?"text-accent-600 dark:text-accent-400 border-b-2 border-accent-600 dark:border-accent-400 bg-accent-50 dark:bg-accent-900/30":"text-muted-foreground hover:text-foreground hover:bg-muted"),children:T(e.labelKey)},e.id))}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["notes"===I&&(0,r.jsx)(sX,{worktreeId:a,className:"h-full",onInsertToMessage:g}),"logs"===I&&(0,r.jsx)(lk,{worktreeId:a,className:"h-full",onInsertToMessage:g,instances:v}),"agent"===I&&(b&&v&&y&&j&&w?(0,r.jsx)("div",{className:"h-full overflow-y-auto",children:(0,r.jsx)(lJ,{worktreeId:a,instances:v,onInstancesChange:y,vibeLocalModel:d,onVibeLocalModelChange:u,vibeLocalContextWindow:m,onVibeLocalContextWindowChange:h,visibleInstanceIds:j,onToggleInstanceVisible:w,modelByInstance:k,composerTargetInstanceId:N})}):(0,r.jsx)(lE,{worktreeId:a,selectedAgents:l,onSelectedAgentsChange:o,vibeLocalModel:d,onVibeLocalModelChange:u,vibeLocalContextWindow:m,onVibeLocalContextWindowChange:h,maxAgents:f,availableAgents:x,persistToServer:p})),"timer"===I&&(0,r.jsx)(l9,{worktreeId:a,instances:v,selectedAgents:l}),"todo"===I&&(0,r.jsx)(s5,{worktreeId:a,className:"h-full"}),"skills"===I&&(0,r.jsx)(iC,{worktreeId:a,className:"h-full"}),"verification"===I&&(0,r.jsx)(ot,{state:C,className:"h-full"}),"env"===I&&(0,r.jsx)(oT,{worktreeId:a,className:"h-full"})]})]})}),oA=["status","changes","history","advanced"],oM="commandmate:gitPane:",oL={activeTab:"".concat(oM,"activeTab"),historyOpen:"".concat(oM,"historyOpen"),advancedOpen:"".concat(oM,"advancedOpen")};function oR(e){return"string"==typeof e&&oA.includes(e)}let oP=e=>"boolean"==typeof e,oD=i.useLayoutEffect;function oF(e,t,n){return Math.max(8,Math.min(e,n-t-8))}let oO=(0,i.memo)(function(e){var t,n;let{branches:a,busy:s,actionError:l,hasRunningSession:o,isMobile:d,onCheckout:u}=e,h=(0,c.c)("worktree"),f=(0,c.c)("common"),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),j=(0,i.useRef)(null),w=(0,i.useRef)(null),[k,N]=(0,i.useState)(null),C=a.filter(e=>!e.isCurrent),S=(0,i.useCallback)(()=>{let e=j.current,t=w.current;if(!e||!t)return;let n=e.getBoundingClientRect(),a=t.getBoundingClientRect(),r=window.innerHeight-n.bottom,s=n.top;N({top:oF(r<a.height+4+8&&s>r?n.top-a.height-4:n.bottom+4,a.height,window.innerHeight),left:oF(n.left,a.width,window.innerWidth)})},[]);oD(()=>x?(S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}):void N(null),[x,C.length,S]);let T=(0,i.useCallback)(e=>{y(!1),b({...e}),p(!1)},[]),I=(0,i.useCallback)(()=>{g&&(u(g,v),b(null))},[g,v,u]);return(0,r.jsxs)("div",{className:"relative",ref:j,"data-testid":"branch-checkout-dropdown",children:[(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:()=>p(e=>!e),disabled:s||0===C.length,className:"flex items-center gap-1 px-2 py-1 text-xs rounded border border-input text-accent-700 dark:text-accent-300 hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"branch-checkout-dropdown-toggle","aria-haspopup":"menu","aria-expanded":x,"aria-label":h("git.checkout.ariaLabel"),children:[h("git.checkout.action"),(0,r.jsx)("span",{"aria-hidden":"true",className:"text-[10px]",children:"▾"})]}),x&&"undefined"!=typeof document&&(0,sf.createPortal)((0,r.jsx)("div",{ref:w,className:"fixed z-50 min-w-[12rem] max-w-[calc(100vw-1rem)] max-h-64 overflow-y-auto rounded border border-border bg-surface shadow-lg",style:{top:null!=(t=null==k?void 0:k.top)?t:-9999,left:null!=(n=null==k?void 0:k.left)?n:-9999},role:"menu","data-testid":"branch-checkout-menu",children:0===C.length?(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:h("git.checkout.noBranches")}):(0,r.jsx)("ul",{className:"divide-y divide-border",children:C.map(e=>{var t;let n=null!==e.checkedOutWorktreePath;return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>T(e),disabled:s||n,className:"w-full text-left px-3 py-1.5 font-mono text-xs text-foreground hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed","aria-label":h("git.checkout.checkoutBranch",{name:e.name}),title:n?h("git.checkout.checkedOutElsewhere",{path:null!=(t=e.checkedOutWorktreePath)?t:""}):void 0,children:[e.name,e.isDefault&&(0,r.jsx)("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:h("git.checkout.defaultBadge")})]})},"".concat(e.isRemote?"r":"l",":").concat(e.name))})})}),document.body),l&&(0,r.jsx)("div",{className:"mt-1 text-xs text-danger-foreground",role:"alert","data-testid":"branch-checkout-error",children:l}),g&&(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",role:"dialog","aria-modal":"true","data-testid":"branch-checkout-confirm",children:(0,r.jsxs)("div",{className:"w-full max-w-md rounded-lg bg-surface p-4 shadow-xl flex flex-col gap-3",children:[(0,r.jsxs)("h3",{className:"text-sm font-medium text-foreground",children:[h("git.checkout.confirmTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:g.name}),h("git.checkout.confirmTitleSuffix")]}),(0,r.jsx)("div",{className:"rounded border border-warning-border bg-warning-subtle px-3 py-2 text-xs text-warning-foreground",role:"alert","data-testid":"branch-history-loss-warning",children:h("git.checkout.historyLossWarning")}),o&&(0,r.jsx)("div",{className:"rounded border border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-foreground",role:"alert","data-testid":"branch-session-warning",children:h("git.checkout.runningSessionWarning")}),(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)(m.Sc,{checked:v,onCheckedChange:e=>y(!0===e),"data-testid":"branch-checkout-force"}),h("git.checkout.forceLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 ".concat(d?"flex-wrap":""),children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>b(null),className:"px-3 py-1 text-xs rounded border border-input text-foreground hover:bg-muted",children:f("cancel")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:I,disabled:s,className:"px-3 py-1 text-xs font-medium rounded bg-accent-600 text-white hover:bg-accent-700 disabled:opacity-50","data-testid":"branch-checkout-confirm-button",children:h("git.checkout.action")})]})]})})]})}),oz=(0,i.memo)(function(e){let{open:t,onToggle:n,children:a}=e,s=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex flex-col border-t border-border","data-testid":"git-advanced-section",children:[(0,r.jsxs)("button",{type:"button",onClick:n,className:"w-full flex items-center gap-1 px-3 py-2 text-sm font-medium text-muted-foreground cursor-pointer hover:text-foreground","data-testid":"git-advanced-toggle","aria-expanded":t,children:[(0,r.jsx)("span",{className:"text-xs w-4 text-center",children:t?"▼":"▶"}),s("git.advancedOperations")]}),t&&(0,r.jsx)("div",{className:"flex flex-col","data-testid":"git-advanced-content",children:a})]})}),o_=(0,i.createContext)(null);function oB(e){let{value:t,children:n}=e;return(0,r.jsx)(o_.Provider,{value:t,children:n})}function oH(){let e=(0,i.useContext)(o_);if(null===e)throw Error("useGitPaneContext must be used within a GitPaneProvider");return e}let oV=(0,i.memo)(function(e){let{path:t}=e;return(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:t})})}),oU={status:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",changes:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z",history:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z",advanced:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"},oK={status:"git.tabs.status",changes:"git.tabs.changes",history:"git.tabs.history",advanced:"git.tabs.advanced"},oW=(0,i.memo)(function(e){let{activeTab:t,onTabChange:n}=e,a=(0,c.c)("worktree");return(0,r.jsx)("div",{role:"tablist","aria-label":a("git.paneSections"),"data-testid":"git-pane-mobile-tabs",className:"flex shrink-0 border-b border-border bg-surface sticky top-0 z-30",children:oA.map(e=>{let s=e===t,l=a(oK[e]);return(0,r.jsxs)("button",{type:"button",role:"tab","aria-selected":s,"aria-label":l,"data-testid":"git-tab-".concat(e),onClick:()=>n(e),className:"flex flex-1 flex-col items-center justify-center gap-1 py-2 px-1 text-xs transition-colors border-b-2 ".concat(s?"text-accent-600 dark:text-accent-400 border-accent-500 bg-accent-50 dark:bg-accent-900/30":"text-muted-foreground border-transparent hover:text-foreground hover:bg-muted"),children:[(0,r.jsx)(oV,{path:oU[e]}),(0,r.jsx)("span",{children:l})]},e)})})});function o$(e){let{activeTab:t,onTabChange:n,className:a="",statusSection:s,quickActionsSection:l,changesSection:i,historySection:o,advancedSection:c}=e,{isMobile:d}=oH();return d?(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden ".concat(a),"data-testid":"git-pane-mobile",children:[(0,r.jsx)(oW,{activeTab:t,onTabChange:n}),(0,r.jsxs)("div",{className:"flex-1 flex flex-col min-h-0","data-testid":"git-pane-mobile-panel","data-active-tab":t,children:["status"===t&&(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto min-h-0",children:[s,l]}),"changes"===t&&(0,r.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:i}),"history"===t&&o,"advanced"===t&&(0,r.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:c})]})]}):(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden ".concat(a),"data-testid":"git-pane-desktop",children:[(0,r.jsx)("div",{"data-testid":"git-group-read","data-git-group":"read",className:"border-l-2 border-info-border bg-info-subtle",children:s}),(0,r.jsxs)("div",{"data-testid":"git-group-write","data-git-group":"write",className:"border-l-2 border-input bg-muted/70 dark:bg-muted/30",children:[l,i]}),(0,r.jsx)("div",{"data-testid":"git-group-history","data-git-group":"read",className:"flex-1 flex flex-col min-h-0 border-l-2 border-info-border bg-info-subtle",children:o}),(0,r.jsx)("div",{"data-testid":"git-group-advanced","data-git-group":"advanced",className:"border-l-2 border-t-2 border-input bg-muted/50 dark:bg-muted/40",children:c})]})}let oq={added:"text-success-foreground",modified:"text-warning-foreground",deleted:"text-danger-foreground",renamed:"text-info",untracked:"text-accent-600 dark:text-accent-400",unmerged:"text-warning-foreground"},oG=(0,i.memo)(function(){return(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),oJ=(0,i.memo)(function(e){let{onClick:t,disabled:n=!1,testId:a,className:s=""}=e,l=(0,c.c)("worktree");return(0,r.jsxs)("button",{type:"button",disabled:n,onClick:t,className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-info-border text-info-foreground hover:bg-info-subtle disabled:opacity-50 disabled:cursor-not-allowed ".concat(s),"data-testid":a,title:l("git.askAiTooltip"),children:[(0,r.jsx)(s4.A,{size:14,"aria-hidden":"true"}),l("git.askAi")]})}),oY=(0,i.memo)(function(e){let{line:t}=e,n="whitespace-pre font-mono text-xs";return t.startsWith("+")&&!t.startsWith("+++")?n+=" text-success-foreground bg-success-subtle":t.startsWith("-")&&!t.startsWith("---")?n+=" text-danger-foreground bg-danger-subtle":t.startsWith("@@")?n+=" text-info":n+=" text-foreground",(0,r.jsx)("div",{className:n,children:t})}),oQ=(0,i.memo)(function(e){let{message:t}=e;return(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-danger-foreground",role:"alert",children:t})}),oX={no_upstream:{badgeKey:"git.currentStatus.noUpstreamBadge",tooltipKey:"git.currentStatus.noUpstreamTooltip"},upstream_gone:{badgeKey:"git.currentStatus.upstreamGoneBadge",tooltipKey:"git.currentStatus.upstreamGoneTooltip"},detached:{badgeKey:"git.currentStatus.detachedBadge",tooltipKey:"git.currentStatus.detachedTooltip"},error:{badgeKey:"git.currentStatus.aheadBehindErrorBadge",tooltipKey:"git.currentStatus.aheadBehindErrorTooltip"}},oZ=(0,i.memo)(function(e){var t;let{gitStatus:n,statusLoading:a,statusError:s,onRefresh:l,refreshing:o=!1}=e,{isMobile:d}=oH(),m=(0,c.c)("worktree"),h=(0,to.Ym)(),f=(0,i.useMemo)(()=>{let e=null==n?void 0:n.lastFetchAt;if(null==e)return m("git.currentStatus.lastFetchNever");let t=(0,X.fw)(new Date(e).toISOString(),am(h));return t?m("git.currentStatus.lastFetch",{relative:t}):m("git.currentStatus.lastFetchNever")},[null==n?void 0:n.lastFetchAt,h,m]),x=n&&!n.aheadBehind&&null!=(t=n.aheadBehindReason)?t:null;return(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 px-3 py-2 border-b border-border","data-testid":"git-status-section",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:m("git.currentStatus.title")}),(0,r.jsx)("button",{type:"button",onClick:l,disabled:o,className:"p-1 text-muted-foreground hover:text-foreground rounded disabled:opacity-50","aria-label":o?m("git.currentStatus.refreshing"):m("git.currentStatus.refresh"),"aria-busy":o,"data-testid":"git-status-refresh-button",children:o?(0,r.jsx)(u.y,{size:"sm",variant:"accent"}):(0,r.jsx)(oG,{})})]}),a&&!n&&(0,r.jsxs)("div",{className:"flex items-center gap-2 py-1",role:"status",children:[(0,r.jsx)(u.y,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:m("git.currentStatus.loading")})]}),s&&!n&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-status-error",children:s}),n&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center flex-wrap ".concat(d?"gap-1.5":"gap-2"),children:[(0,r.jsx)("span",{className:"inline-flex items-center max-w-full truncate rounded px-2 py-0.5 text-xs font-mono bg-accent-50 text-accent-700 dark:bg-accent-900/30 dark:text-accent-300","data-testid":"git-status-branch-chip",title:n.currentBranch,children:n.currentBranch}),n.isDirty&&(0,r.jsx)("span",{className:"inline-flex items-center rounded px-2 py-0.5 text-xs font-medium bg-warning-subtle text-warning-foreground","data-testid":"git-status-dirty-badge",children:m("git.currentStatus.uncommitted")}),n.aheadBehind&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs font-mono bg-muted text-foreground","data-testid":"git-status-ahead-behind",children:[(0,r.jsxs)("span",{title:m("git.currentStatus.aheadTooltip"),children:["↑",n.aheadBehind.ahead]}),(0,r.jsxs)("span",{title:m("git.currentStatus.behindTooltip"),children:["↓",n.aheadBehind.behind]})]}),x&&(0,r.jsx)("span",{className:"inline-flex items-center rounded px-2 py-0.5 text-xs font-medium bg-muted text-muted-foreground border border-border","data-testid":"git-status-ahead-behind-reason","data-reason":x,title:m(oX[x].tooltipKey),children:m(oX[x].badgeKey)})]}),(0,r.jsx)("div",{className:"text-[11px] text-muted-foreground","data-testid":"git-status-last-fetch",title:m("git.currentStatus.lastFetchTooltip"),children:f}),n.isBranchMismatch&&(0,r.jsxs)("div",{className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs bg-warning-subtle text-warning-foreground border border-warning-border",role:"alert","data-testid":"git-status-mismatch-warning",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"⚠"}),(0,r.jsxs)("span",{children:[m("branchMismatch.changedFrom")," ",(0,r.jsx)("span",{className:"font-medium",children:n.initialBranch})," ",m("branchMismatch.to")," ",(0,r.jsx)("span",{className:"font-medium",children:n.currentBranch})]})]})]})]})}),o0=(0,i.memo)(function(e){let{progressState:t,operation:n,error:a,conflict:s,conflictFiles:l,hasUpstream:o,onFetch:d,onPull:m,onPush:h,onAbort:f,extraActions:x}=e,{isMobile:p}=oH(),g=(0,c.c)("worktree"),b="running"===t,v=null!=a?a:g("git.network.failed"),[y,j]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!b)return void j(0);let e=setInterval(()=>j(e=>e+1),1e3);return()=>clearInterval(e)},[b]),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 px-3 py-2 border-b border-border","data-testid":"git-network-section",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:g("git.network.quickActions")}),(0,r.jsxs)("div",{className:"flex items-center ".concat(p?"flex-wrap gap-1.5":"gap-2"),children:[d&&(0,r.jsx)("button",{type:"button",onClick:d,disabled:b,className:"px-2 py-1 text-xs rounded border border-border text-foreground hover:bg-muted disabled:opacity-50","data-testid":"git-fetch-button",children:g("git.network.fetch")}),(0,r.jsx)("button",{type:"button",onClick:m,disabled:b,className:"px-2 py-1 text-xs rounded border border-accent-300 dark:border-accent-700 text-accent-700 dark:text-accent-300 hover:bg-accent-50 dark:hover:bg-accent-900/30 disabled:opacity-50","data-testid":"git-pull-button",children:g("git.network.pull")}),(0,r.jsx)("button",{type:"button",onClick:h,disabled:b,className:"px-2 py-1 text-xs rounded border border-success-border text-success-foreground hover:bg-success-subtle disabled:opacity-50","data-testid":"git-push-button",title:o?void 0:g("git.network.noUpstreamTooltip"),children:g("git.network.push")}),x]}),b&&(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1 text-xs bg-accent-50 text-accent-800 dark:bg-accent-900/20 dark:text-accent-300 ".concat(p?"sticky top-0 z-40":""),"data-testid":"git-network-progress-bar",children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",role:"status","data-testid":"git-network-operation-spinner",children:[(0,r.jsx)(u.y,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{children:g("git.network.progress",{operation:g("push"===n?"git.network.pushing":"pull"===n?"git.network.pulling":"git.network.fetching"),elapsed:y})})]}),(0,r.jsx)("button",{type:"button",onClick:f,className:"ml-auto px-1.5 py-0.5 rounded border border-accent-400 dark:border-accent-600 hover:bg-accent-100 dark:hover:bg-accent-900/40","data-testid":"git-network-abort-button",children:g("git.network.abort")})]}),"error"===t&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-network-operation-error",children:v}),s&&(0,r.jsx)("div",{className:"text-xs text-warning-foreground",role:"status","data-testid":"git-network-conflict",children:g("git.network.conflicts",{files:l.join(", ")})})]})}),o1=(0,i.memo)(function(e){let{title:t,testId:n,files:a,actionLabel:s,mode:l,defaultOpen:o,busy:d,onDiff:u,onToggleStage:h,onPreview:f}=e,x=(0,c.c)("worktree"),[p,g]=(0,i.useState)(o),[b,v]=(0,i.useState)(null),[y,j]=(0,i.useState)(null),[w,k]=(0,i.useState)(!1),[N,C]=(0,i.useState)(null),S=(0,i.useCallback)(async e=>{if(b===e){v(null),j(null),C(null);return}v(e),j(null),C(null),k(!0);try{let t=await f(e,l);j(null!=t?t:"")}catch(e){C(x("git.changes.previewFailed"))}finally{k(!1)}},[b,f,l,x]);return(0,r.jsxs)("div",{className:"border-t border-border","data-testid":n,children:[(0,r.jsxs)("button",{type:"button",onClick:()=>g(e=>!e),className:"w-full flex items-center gap-1 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground",children:[(0,r.jsx)("span",{className:"w-4 text-center",children:p?"▼":"▶"}),x("git.changes.listHeader",{title:t,count:a.length})]}),p&&0===a.length&&(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:x("git.changes.empty")}),p&&a.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:a.map(e=>{let t=b===e.path;return(0,r.jsxs)("li",{className:"flex flex-col",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5",children:[(0,r.jsx)("span",{className:"inline-block w-16 shrink-0 text-xs font-medium ".concat(oq[e.status]),children:e.status}),(0,r.jsx)("span",{className:"flex-1 truncate font-mono text-xs text-foreground",title:e.path,children:e.path}),(0,r.jsx)("button",{type:"button",onClick:()=>S(e.path),className:"shrink-0 w-5 text-center text-xs text-muted-foreground hover:text-foreground","aria-label":x("git.changes.togglePreview",{path:e.path}),"aria-expanded":t,"data-testid":"git-changes-preview-toggle",children:t?"▼":"▶"}),(0,r.jsx)("button",{type:"button",onClick:()=>u(e.path,l),className:"shrink-0 px-1.5 py-0.5 text-xs text-accent-600 dark:text-accent-400 hover:underline","aria-label":x("git.changes.showDiff",{path:e.path}),"data-testid":"git-changes-diff-button",children:x("git.changes.diff")}),(0,r.jsx)("button",{type:"button",onClick:()=>h(e.path),disabled:d,className:"shrink-0 px-1.5 py-0.5 text-xs rounded border border-input text-foreground hover:bg-muted disabled:opacity-50","aria-label":x("git.changes.fileAction",{action:s,path:e.path}),"data-testid":"git-changes-toggle-button",children:s})]}),t&&(0,r.jsxs)("div",{className:"px-3 pb-2 bg-muted/40","data-testid":"git-changes-inline-preview",children:[w&&(0,r.jsxs)("div",{className:"flex items-center gap-2 py-2",role:"status",children:[(0,r.jsx)(m.y$,{size:"xs",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:x("git.changes.loadingPreview")})]}),N&&(0,r.jsx)("div",{className:"py-2 text-xs text-danger-foreground",role:"alert",children:N}),!w&&!N&&null!==y&&(""===y.trim()?(0,r.jsx)("div",{className:"py-2 text-xs text-muted-foreground",children:x("git.changes.noDiff")}):(0,r.jsxs)("div",{className:"overflow-x-auto",children:[(0,r.jsx)("pre",{className:"text-xs",children:(0,r.jsx)("code",{children:y.split("\n").slice(0,20).map((e,t)=>(0,r.jsx)(oY,{line:e},t))})}),y.split("\n").length>20&&(0,r.jsx)("button",{type:"button",onClick:()=>u(e.path,l),className:"mt-1 text-xs text-accent-600 dark:text-accent-400 hover:underline","data-testid":"git-changes-preview-more",children:x("git.changes.truncated")})]}))]})]},"".concat(e.status,":").concat(e.path))})})]})}),o2=(0,i.memo)(function(e){var t,n,a;let{staged:s,loading:l,error:i,busy:o,commitMessage:d,amend:u,committing:h,commitError:f,onRefresh:x,onDiff:p,onPreview:g,onStage:b,onUnstage:v,onCommitMessageChange:y,onAmendChange:j,onCommit:w,onCommitAndPush:k}=e,{isMobile:N}=oH(),C=(0,c.c)("worktree"),S=null!=(t=null==s?void 0:s.staged)?t:[],T=null!=(n=null==s?void 0:s.unstaged)?n:[],I=null!=(a=null==s?void 0:s.untracked)?a:[],E=!h&&d.trim().length>0&&(S.length>0||u),A=!N;return(0,r.jsxs)("div",{className:"flex flex-col border-b border-border","data-testid":"git-changes-section",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:C("git.changes.title")}),(0,r.jsx)("button",{type:"button",onClick:x,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":C("git.changes.refresh"),children:(0,r.jsx)(oG,{})})]}),l&&!s&&(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 pb-2",role:"status",children:[(0,r.jsx)(m.y$,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:C("git.changes.loading")})]}),i&&!s&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-changes-error",children:i}),s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(o1,{title:C("git.changes.staged"),testId:"git-staged-list",files:S,actionLabel:C("git.changes.unstage"),mode:"staged",defaultOpen:A,busy:o,onDiff:p,onPreview:g,onToggleStage:v}),(0,r.jsx)(o1,{title:C("git.changes.unstaged"),testId:"git-unstaged-list",files:T,actionLabel:C("git.changes.stage"),mode:"unstaged",defaultOpen:A,busy:o,onDiff:p,onPreview:g,onToggleStage:b}),(0,r.jsx)(o1,{title:C("git.changes.untracked"),testId:"git-untracked-list",files:I,actionLabel:C("git.changes.stage"),mode:"untracked",defaultOpen:A,busy:o,onDiff:p,onPreview:g,onToggleStage:b}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 px-3 py-2 border-t border-border",children:[(0,r.jsx)("textarea",{value:d,onChange:e=>y(e.target.value),placeholder:C("git.changes.commitMessage"),rows:N?2:3,className:"w-full resize-y rounded border border-input bg-surface dark:bg-surface-2 px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring","data-testid":"git-commit-message","aria-label":C("git.changes.commitMessage")}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)(m.Sc,{checked:u,onCheckedChange:e=>j(!0===e),"data-testid":"git-amend-checkbox"}),C("git.changes.amend")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:w,disabled:!E,className:"px-3 py-1 text-xs font-medium rounded bg-accent-600 text-white hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"git-commit-button",children:C(h?"git.changes.committing":"git.changes.commit")}),(0,r.jsx)("button",{type:"button",onClick:k,disabled:!E||o,title:C("git.changes.commitAndPushTooltip"),className:"px-3 py-1 text-xs font-medium rounded border border-accent-600 text-accent-700 dark:text-accent-300 hover:bg-accent-50 dark:hover:bg-accent-900/30 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"git-commit-push-button",children:C("git.changes.commitAndPush")})]})]}),f&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-commit-error",children:f})]})]})]})}),o5=(0,i.memo)(function(e){let{commits:t,isLoading:n,commitError:a,commitListOpen:s,onToggleCommitList:l,onRefresh:o,selectedCommit:d,onCommitSelect:m,inlineDiffCommit:h,inlineFiles:f,inlineFilesLoading:x,inlineFilesError:p,onToggleInlineDiff:g,onInlineDiffFile:b,changedFiles:v,isLoadingFiles:y,detailError:j,selectedFile:w,onFileSelect:k,diffContent:N,isLoadingDiff:C}=e,{isMobile:S}=oH(),T=(0,c.c)("worktree"),[I,E]=(0,i.useState)(!0),[A,M]=(0,i.useState)(!0);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[(0,r.jsxs)("button",{type:"button",onClick:l,className:"flex items-center gap-1 text-sm font-medium text-muted-foreground cursor-pointer hover:text-foreground",children:[(0,r.jsx)("span",{className:"text-xs w-4 text-center",children:s?"▼":"▶"}),T("git.history.title")]}),(0,r.jsx)("button",{type:"button",onClick:o,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":T("git.history.refresh"),children:(0,r.jsx)(oG,{})})]}),s&&n&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-8",role:"status",children:[(0,r.jsx)(u.y,{size:"lg",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:T("git.history.loading")})]}),s&&a&&!n&&(0,r.jsx)("div",{className:"px-3 py-4 text-sm text-danger-foreground",role:"alert",children:a}),s&&!n&&!a&&0===t.length&&(0,r.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:T("git.history.empty")}),!n&&!a&&t.length>0&&(0,r.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[s&&(0,r.jsx)("div",{className:"overflow-y-auto ".concat(d?"max-h-[40%] shrink-0":"flex-1"),children:(0,r.jsx)("ul",{className:"divide-y divide-border",children:t.map(e=>{let t=h===e.hash;return(0,r.jsxs)("li",{children:[(0,r.jsxs)("div",{className:"flex items-stretch",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>m(e.hash),className:"flex-1 min-w-0 text-left px-3 py-2 text-sm hover:bg-muted transition-colors ".concat(d===e.hash?"bg-accent-50 dark:bg-accent-900/30":""),children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsx)("span",{className:"font-mono text-xs text-accent-600 dark:text-accent-400 shrink-0",children:e.shortHash}),(0,r.jsx)("span",{className:"truncate text-foreground",children:e.message})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{children:e.author}),(0,r.jsx)("span",{children:new Date(e.date).toLocaleDateString()})]})]}),(0,r.jsx)("button",{type:"button",onClick:()=>g(e.hash),className:"shrink-0 px-2 text-xs text-accent-600 dark:text-accent-400 hover:bg-muted hover:underline","aria-label":T("git.history.viewDiffFor",{hash:e.shortHash}),"aria-expanded":t,"data-testid":"git-commit-view-diff-button",children:t?T("git.history.hideDiff"):T("git.history.viewDiff")})]}),t&&(0,r.jsxs)("div",{className:"border-t border-border bg-muted/40","data-testid":"git-commit-inline-files",children:[x&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-3",role:"status",children:[(0,r.jsx)(u.y,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:T("git.history.loadingChangedFiles")})]}),p&&(0,r.jsx)(oQ,{message:p}),!x&&!p&&0===f.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:T("git.history.noChangedFiles")}),!x&&f.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:f.map(t=>(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",onClick:()=>b(e.hash,t.path),className:"w-full text-left px-3 py-1.5 text-xs hover:bg-muted transition-colors ".concat(w===t.path&&d===e.hash?"bg-accent-50 dark:bg-accent-900/30":""),"aria-label":T("git.history.showCommitDiff",{path:t.path}),"data-testid":"git-commit-inline-file",children:[(0,r.jsx)("span",{className:"inline-block w-14 font-medium ".concat(oq[t.status]),children:t.status}),(0,r.jsx)("span",{className:"font-mono text-foreground",children:t.path})]})},t.path))})]})]},e.hash)})})}),d&&(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto min-h-0 border-t border-border",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>E(e=>!e),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground bg-surface-2 sticky top-0 z-10 cursor-pointer hover:text-foreground",children:[(0,r.jsx)("span",{className:"w-4 text-center",children:I?"▼":"▶"}),T("git.history.changedFiles")]}),I&&(0,r.jsxs)(r.Fragment,{children:[j&&(0,r.jsx)(oQ,{message:j}),y&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-4",role:"status",children:[(0,r.jsx)(u.y,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:T("git.history.loadingChangedFiles")})]}),!y&&!j&&0===v.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:T("git.history.noChangedFiles")}),!y&&v.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:v.map(e=>(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",onClick:()=>k(e.path),className:"w-full text-left px-3 py-1.5 text-xs hover:bg-muted transition-colors ".concat(w===e.path?"bg-accent-50 dark:bg-accent-900/30":""),children:[(0,r.jsx)("span",{className:"inline-block w-14 font-medium ".concat(oq[e.status]),children:e.status}),(0,r.jsx)("span",{className:"font-mono text-foreground",children:e.path})]})},e.path))})]}),S&&w&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>M(e=>!e),className:"w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground bg-surface-2 sticky top-0 z-10 cursor-pointer hover:text-foreground",children:[(0,r.jsx)("span",{className:"w-4 text-center",children:A?"▼":"▶"}),T("git.history.diffLabel",{file:w})]}),A&&(0,r.jsxs)(r.Fragment,{children:[C&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-4",role:"status",children:[(0,r.jsx)(u.y,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:T("git.history.loadingDiff")})]}),!C&&N&&(0,r.jsx)("div",{className:"overflow-x-auto p-2",children:(0,r.jsx)("pre",{className:"text-xs",children:(0,r.jsx)("code",{children:N.split("\n").map((e,t)=>(0,r.jsx)(oY,{line:e},t))})})}),!C&&!N&&!j&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:T("git.history.noDiff")})]})]}),!S&&w&&!j&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground border-t border-border",children:C?T("git.history.loadingDiff"):T("git.history.diffInFilePanel",{file:w})})]})]})]})});function o4(e){return"`"+e+"`"}let o3={local:"git.branches.filterLocal",remote:"git.branches.filterRemote",all:"git.branches.filterAll"},o6=(0,i.memo)(function(e){let{branches:t,include:n,loading:a,error:s,busy:l,actionError:o,onIncludeChange:d,onRefresh:u,onCreate:h,onDelete:f}=e,{isMobile:x,onInsertToMessage:p}=oH(),g=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,i.useState)(!x),[j,w]=(0,i.useState)(!1),[k,N]=(0,i.useState)(""),[C,S]=(0,i.useState)(""),[T,I]=(0,i.useState)(null),[E,A]=(0,i.useState)(!1),M=(0,i.useCallback)(()=>{0!==k.trim().length&&(h(k.trim(),C.trim()||void 0),w(!1),N(""),S(""))},[k,C,h]),L=(0,i.useCallback)(()=>{T&&(f(T.name,E),I(null),A(!1))},[T,E,f]);return(0,r.jsxs)("div",{className:"flex flex-col border-b border-border","data-testid":"git-branches-section",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>y(e=>!e),className:"flex items-center gap-1 text-sm font-medium text-muted-foreground hover:text-foreground",children:[(0,r.jsx)("span",{className:"text-xs w-4 text-center",children:v?"▼":"▶"}),g("git.branches.title")]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("button",{type:"button",onClick:()=>w(!0),className:"px-2 py-0.5 text-xs rounded border border-input text-foreground hover:bg-muted","data-testid":"git-branch-create-open",children:g("git.branches.newButton")}),(0,r.jsx)("button",{type:"button",onClick:u,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":g("git.branches.refresh"),children:(0,r.jsx)(oG,{})})]})]}),v&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex items-center gap-1 px-3 pb-2",children:["local","remote","all"].map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>d(e),className:"px-2 py-0.5 text-xs rounded ".concat(n===e?"bg-accent-100 text-accent-800 dark:bg-accent-900/40 dark:text-accent-200":"text-muted-foreground hover:bg-muted"),"data-testid":"git-branches-tab-".concat(e),children:g(o3[e])},e))}),a&&0===t.length&&(0,r.jsxs)("div",{className:"flex items-center gap-2 px-3 pb-2",role:"status",children:[(0,r.jsx)(m.y$,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{className:"sr-only",children:g("git.branches.loading")})]}),s&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-branches-error",children:s}),o&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-branches-action-error",children:o}),!a&&!s&&0===t.length&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-muted-foreground",children:g("git.branches.empty")}),t.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border max-h-64 overflow-y-auto",children:t.map(e=>{let t=l||e.isCurrent||e.isDefault;return(0,r.jsxs)("li",{className:"flex items-center gap-2 px-3 py-1.5","data-testid":"git-branch-row",children:[(0,r.jsxs)("span",{className:"flex-1 truncate font-mono text-xs text-foreground",title:e.name,children:[e.isCurrent&&(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 mr-1",children:"●"}),e.name,e.isDefault&&(0,r.jsx)("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:g("git.branches.defaultBadge")})]}),(0,r.jsx)("button",{type:"button",onClick:()=>{A(!1),I(e)},disabled:t,className:"shrink-0 px-1.5 py-0.5 text-xs rounded border border-input text-danger-foreground hover:bg-muted disabled:opacity-50 disabled:cursor-not-allowed","aria-label":g("git.branches.deleteBranch",{name:e.name}),children:g("git.branches.delete")})]},"".concat(e.isRemote?"r":"l",":").concat(e.name))})})]}),j&&(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",role:"dialog","aria-modal":"true","data-testid":"branch-create-modal",children:(0,r.jsxs)("div",{className:"w-full max-w-md rounded-lg bg-surface p-4 shadow-xl flex flex-col gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:g("git.branches.createTitle")}),(0,r.jsx)("input",{type:"text",value:k,onChange:e=>N(e.target.value),placeholder:g("git.branches.namePlaceholder"),className:"w-full rounded border border-input bg-surface dark:bg-surface-2 px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring","data-testid":"branch-create-name-input","aria-label":g("git.branches.nameLabel")}),(0,r.jsxs)("select",{value:C,onChange:e=>S(e.target.value),className:"w-full rounded border border-input bg-surface dark:bg-surface-2 px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring","data-testid":"branch-create-from-select","aria-label":g("git.branches.baseLabel"),children:[(0,r.jsx)("option",{value:"",children:g("git.branches.currentHead")}),t.map(e=>(0,r.jsx)("option",{value:e.name,children:e.name},"from:".concat(e.isRemote?"r":"l",":").concat(e.name)))]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[p&&(0,r.jsx)(oJ,{className:"mr-auto",testId:"branch-create-ask-ai",disabled:0===k.trim().length,onClick:()=>{p(function(e,t,n){let a=n&&n.trim().length>0?o4(n.trim()):e("git.aiPrompts.branchCreateBaseHead");return e("git.aiPrompts.branchCreate",{base:a,name:o4(t.trim())})}(g,k,C)),w(!1)}}),(0,r.jsx)("button",{type:"button",onClick:()=>w(!1),className:"px-3 py-1 text-xs rounded border border-input text-foreground hover:bg-muted",children:b("cancel")}),(0,r.jsx)("button",{type:"button",onClick:M,disabled:l||0===k.trim().length,className:"px-3 py-1 text-xs font-medium rounded bg-accent-600 text-white hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"branch-create-submit",children:g("git.branches.create")})]})]})}),T&&(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",role:"dialog","aria-modal":"true","data-testid":"branch-delete-confirm",children:(0,r.jsxs)("div",{className:"w-full max-w-md rounded-lg bg-surface p-4 shadow-xl flex flex-col gap-3",children:[(0,r.jsxs)("h3",{className:"text-sm font-medium text-foreground",children:[g("git.branches.deleteTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:T.name}),g("git.branches.deleteTitleSuffix")]}),(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)(m.Sc,{checked:E,onCheckedChange:e=>A(!0===e),"data-testid":"branch-delete-force"}),g("git.branches.forceDeleteLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[p&&T&&(0,r.jsx)(oJ,{className:"mr-auto",testId:"branch-delete-ask-ai",onClick:()=>{p(g(E?"git.aiPrompts.branchDeleteForce":"git.aiPrompts.branchDelete",{name:o4(T.name)})),I(null),A(!1)}}),(0,r.jsx)("button",{type:"button",onClick:()=>I(null),className:"px-3 py-1 text-xs rounded border border-input text-foreground hover:bg-muted",children:b("cancel")}),(0,r.jsx)("button",{type:"button",onClick:L,disabled:l,className:"px-3 py-1 text-xs font-medium rounded bg-danger text-white hover:bg-danger/90 disabled:opacity-50","data-testid":"branch-delete-confirm-button",children:g("git.branches.delete")})]})]})})]})}),o8=(0,i.memo)(function(e){let{stashes:t,loading:n,error:a,busy:s,actionError:l,conflictNotice:o,hasRunningSession:d,onRefresh:u,onPush:h,onPop:f,onApply:x,onDrop:p}=e,{isMobile:g,onInsertToMessage:b}=oH(),v=(0,c.c)("worktree"),y=(0,c.c)("common"),[j,w]=(0,i.useState)(!g),[k,N]=(0,i.useState)(""),[C,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(null);return(0,r.jsxs)("div",{className:"border-b border-border","data-testid":"git-stash-section",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>w(e=>!e),className:"flex items-center gap-1 text-sm font-medium text-muted-foreground cursor-pointer hover:text-foreground",children:[(0,r.jsx)("span",{className:"text-xs w-4 text-center",children:j?"▼":"▶"}),v("git.stash.titlePrefix"),t.length>0&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:v("git.stash.count",{count:t.length})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[j&&b&&t.length>0&&(0,r.jsx)(oJ,{testId:"stash-cleanup-ask-ai",onClick:()=>b(function(e,t){let n=e("git.aiPrompts.stashCleanup");if(0===t.length)return n;let a=t.map(e=>"- stash@{".concat(e.index,"}: ").concat(e.message)).join("\n");return"".concat(n,"\n\n").concat(e("git.aiPrompts.stashCleanupCurrent"),"\n").concat(a)}(v,t))}),(0,r.jsx)("button",{type:"button",onClick:u,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":v("git.stash.refresh"),children:(0,r.jsx)(oG,{})})]})]}),j&&(0,r.jsxs)("div",{className:"px-3 pb-3 space-y-2",children:[a&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-stash-error",children:a}),l&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-stash-action-error",children:l}),o&&(0,r.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,r.jsx)("div",{className:"text-xs text-warning-foreground",role:"status","data-testid":"git-stash-conflict",children:o}),b&&(0,r.jsx)(oJ,{className:"shrink-0",testId:"stash-conflict-ask-ai",onClick:()=>b(function(e,t){let n=e("git.aiPrompts.stashConflict");return t&&t.trim().length>0?"".concat(n,"\n\n").concat(t.trim()):n}(v,o))})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)("input",{type:"text",value:k,onChange:e=>N(e.target.value),placeholder:v("git.stash.messagePlaceholder"),className:"w-full px-2 py-1 text-xs border border-input rounded bg-surface dark:bg-surface-2 text-foreground","data-testid":"git-stash-push-message"}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(m.Sc,{checked:C,onCheckedChange:e=>S(!0===e),"data-testid":"git-stash-include-untracked"}),v("git.stash.includeUntracked")]}),(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>{h(k,C),N(""),S(!1)},className:"px-2 py-1 text-xs rounded bg-accent-600 hover:bg-accent-700 text-white disabled:opacity-50","data-testid":"stash-push-button",children:v("git.stash.push")})]})]}),n?(0,r.jsx)("div",{className:"py-3 text-center text-xs text-muted-foreground",role:"status",children:v("git.stash.loading")}):0===t.length?(0,r.jsx)("div",{className:"py-3 text-center text-xs text-muted-foreground",children:v("git.stash.empty")}):(0,r.jsx)("ul",{className:"divide-y divide-border",children:t.map(e=>(0,r.jsx)("li",{className:"py-1.5","data-testid":"git-stash-row",children:(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsxs)("div",{className:"min-w-0",children:[(0,r.jsxs)("span",{className:"font-mono text-xs text-accent-600 dark:text-accent-400",children:["stash@","{",e.index,"}"]}),(0,r.jsx)("span",{className:"ml-2 text-xs text-foreground truncate",children:e.message})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>x(e.index),className:"px-1.5 py-0.5 text-xs rounded border border-input hover:bg-muted disabled:opacity-50","data-testid":"stash-apply-button",children:v("git.stash.apply")}),(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>f(e.index),className:"px-1.5 py-0.5 text-xs rounded border border-input hover:bg-muted disabled:opacity-50","data-testid":"stash-pop-button",children:v("git.stash.pop")}),(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>I(e.index),className:"px-1.5 py-0.5 text-xs rounded border border-danger-border text-danger-foreground hover:bg-danger-subtle disabled:opacity-50","data-testid":"stash-drop-button",children:v("git.stash.drop")})]})]})},e.index))})]}),null!==T&&(0,r.jsxs)("div",{className:"px-3 py-3 border-t border-danger-border bg-danger-subtle","data-testid":"git-stash-drop-confirm",role:"dialog",children:[(0,r.jsxs)("p",{className:"text-xs text-danger-foreground",children:["stash@","{",T,"}",v("git.stash.dropConfirmSuffix")]}),d&&(0,r.jsx)("p",{className:"mt-1 text-xs text-danger-foreground","data-testid":"git-stash-drop-session-warning",children:v("git.danger.runningSessionWarning")}),(0,r.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>{p(T),I(null)},className:"px-2 py-1 text-xs rounded bg-danger hover:bg-danger/90 text-white disabled:opacity-50","data-testid":"git-stash-drop-confirm-button",children:v("git.stash.drop")}),(0,r.jsx)("button",{type:"button",onClick:()=>I(null),className:"px-2 py-1 text-xs rounded border border-input hover:bg-muted",children:y("cancel")})]})]})]})}),o9={soft:"git.danger.modeSoft",mixed:"git.danger.modeMixed",hard:"git.danger.modeHard"},o7=(0,i.memo)(function(e){let{selectedCommit:t,busy:n,actionError:a,conflictNotice:s,currentBranch:l,aheadCount:o,hasRunningSession:d,onReset:u,onRevert:h,onForcePush:f}=e,{isMobile:x,onInsertToMessage:p}=oH(),g=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,i.useState)(!1),[j,w]=(0,i.useState)("mixed"),[k,N]=(0,i.useState)(!0),[C,S]=(0,i.useState)(""),[T,I]=(0,i.useState)(!1),[E,A]=(0,i.useState)(!1),[M,L]=(0,i.useState)(!1),[R,P]=(0,i.useState)(!1),[D,F]=(0,i.useState)(!0),O=k?"HEAD":t,z=!k&&!t;return(0,r.jsxs)("div",{className:"border-t-2 border-danger-border","data-testid":"git-danger-zone-section",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>y(e=>!e),className:"w-full flex items-center gap-1 px-3 py-2 text-sm font-medium text-danger-foreground bg-danger-subtle cursor-pointer hover:bg-danger-subtle","data-testid":"git-danger-zone-toggle",children:[(0,r.jsx)("span",{className:"text-xs w-4 text-center",children:v?"▼":"▶"}),g("git.danger.title")]}),v&&(0,r.jsxs)("div",{className:"px-3 py-3 space-y-2 bg-danger-subtle",children:[a&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-danger-zone-error",children:a}),s&&(0,r.jsx)("div",{className:"text-xs text-warning-foreground",role:"status","data-testid":"git-danger-zone-conflict",children:s}),(0,r.jsxs)("div",{className:"flex ".concat(x?"flex-col":"flex-row"," gap-2"),children:[(0,r.jsx)("button",{type:"button",onClick:()=>I(!0),className:"px-2 py-1 text-xs rounded border border-danger-border text-danger-foreground hover:bg-danger-subtle","data-testid":"git-danger-zone-reset-open",children:g("git.danger.resetOpen")}),(0,r.jsx)("button",{type:"button",disabled:!t,onClick:()=>A(!0),className:"px-2 py-1 text-xs rounded border border-danger-border text-danger-foreground hover:bg-danger-subtle disabled:opacity-50","data-testid":"git-danger-zone-revert-open",children:g("git.danger.revertOpen")}),f&&(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>P(!0),className:"px-2 py-1 text-xs rounded border border-danger-border text-danger-foreground hover:bg-danger-subtle disabled:opacity-50","data-testid":"git-force-push-open",children:g("git.danger.forcePushOpen")})]}),!t&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:g("git.danger.selectCommitHint")})]}),T&&(0,r.jsxs)("div",{className:"px-3 py-3 border-t border-danger-border bg-danger-subtle","data-testid":"reset-confirm",role:"dialog",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-danger-foreground mb-2",children:g("git.danger.resetTitle")}),(0,r.jsxs)(m.z6,{value:k?"head":"commit",onValueChange:e=>N("head"===e),name:"reset-target",className:"flex flex-col gap-1 mb-2",children:[(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-foreground",children:[(0,r.jsx)(m.CU,{value:"head","data-testid":"reset-target-head"}),g("git.danger.resetTargetHead")]}),(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-foreground",children:[(0,r.jsx)(m.CU,{value:"commit",disabled:!t,"data-testid":"reset-target-commit"}),g("git.danger.resetTargetSelectedPrefix"),t?g("git.danger.resetTargetSelectedHash",{hash:t.slice(0,7)}):g("git.danger.resetTargetNoneSelected")]})]}),(0,r.jsx)(m.z6,{value:j,onValueChange:e=>w(e),name:"reset-mode",className:"flex flex-col gap-1 mb-2",children:["soft","mixed","hard"].map(e=>(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-foreground",children:[(0,r.jsx)(m.CU,{value:e,"data-testid":"reset-mode-".concat(e)}),g(o9[e])]},e))}),"hard"===j&&(0,r.jsxs)("div",{className:"mb-2 space-y-1",children:[(0,r.jsx)("p",{className:"text-xs text-danger-foreground","data-testid":"reset-hard-history-loss-warning",children:g("git.danger.resetHardWarning")}),d&&(0,r.jsx)("p",{className:"text-xs text-danger-foreground","data-testid":"reset-hard-session-warning",children:g("git.danger.runningSessionWarning")}),(0,r.jsx)("input",{type:"text",value:C,onChange:e=>S(e.target.value),placeholder:g("git.danger.confirmPlaceholder",{branch:null!=l?l:""}),className:"w-full px-2 py-1 text-xs border border-danger-border rounded bg-surface dark:bg-surface-2 text-foreground","data-testid":"reset-hard-branch-input"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[p&&(0,r.jsx)(oJ,{className:"mr-auto",testId:"reset-ask-ai",disabled:z,onClick:()=>{O&&(p("hard"===j?g("git.aiPrompts.resetHard",{target:o4(O)}):g("git.aiPrompts.reset",{target:o4(O),mode:j})),I(!1),S(""))}}),(0,r.jsx)("button",{type:"button",disabled:n||z||"hard"===j&&C!==(null!=l?l:""),onClick:()=>{O&&(u(O,j,"hard"===j?C:void 0),I(!1),S(""))},className:"px-2 py-1 text-xs rounded bg-danger hover:bg-danger/90 text-white disabled:opacity-50","data-testid":"reset-confirm-button",children:g("git.danger.reset")}),(0,r.jsx)("button",{type:"button",onClick:()=>{I(!1),S("")},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),E&&t&&(0,r.jsxs)("div",{className:"px-3 py-3 border-t border-danger-border bg-danger-subtle","data-testid":"revert-confirm",role:"dialog",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-danger-foreground mb-2",children:g("git.danger.revertTitle")}),(0,r.jsxs)("p",{className:"text-xs text-foreground mb-2",children:[g("git.danger.revertBodyPrefix"),(0,r.jsx)("span",{className:"font-mono",children:t.slice(0,7)})]}),d&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"revert-session-warning",children:g("git.danger.runningSessionWarning")}),(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-foreground mb-2",children:[(0,r.jsx)(m.Sc,{checked:M,onCheckedChange:e=>L(!0===e),"data-testid":"revert-no-commit"}),g("git.danger.revertNoCommit")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[p&&(0,r.jsx)(oJ,{className:"mr-auto",testId:"revert-ask-ai",onClick:()=>{p(g("git.aiPrompts.revert",{commit:o4(t.slice(0,7))})),A(!1),L(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{h(t,M),A(!1),L(!1)},className:"px-2 py-1 text-xs rounded bg-danger hover:bg-danger/90 text-white disabled:opacity-50","data-testid":"revert-confirm-button",children:g("git.danger.revert")}),(0,r.jsx)("button",{type:"button",onClick:()=>{A(!1),L(!1)},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),R&&f&&(0,r.jsxs)("div",{className:"px-3 py-3 border-t border-danger-border bg-danger-subtle","data-testid":"force-push-confirm",role:"dialog",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-danger-foreground mb-2",children:g("git.danger.forcePushTitle")}),(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-protected-branch-warning",children:g("git.danger.protectedBranchWarning")}),d&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-session-warning",children:g("git.danger.runningSessionWarning")}),(0,r.jsxs)("label",{className:"flex items-center gap-1 text-xs text-foreground mb-2",children:[(0,r.jsx)(m.Sc,{checked:D,onCheckedChange:e=>F(!0===e),"data-testid":"force-push-with-lease"}),g("git.danger.forceWithLease")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[p&&(0,r.jsx)(oJ,{className:"mr-auto",testId:"force-push-ask-ai",onClick:()=>{p(function(e,t){let{branch:n,ahead:a}=t,r=n?o4(n):e("git.aiPrompts.forcePushCurrentBranch");return e("number"==typeof a&&a>0?"git.aiPrompts.forcePushAhead":"git.aiPrompts.forcePush",{branchRef:r,upstream:o4("origin/".concat(null!=n?n:"<branch>")),ahead:null!=a?a:0})}(g,{branch:l,ahead:null!=o?o:null})),P(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{f(D),P(!1)},className:"px-2 py-1 text-xs rounded bg-danger hover:bg-danger/90 text-white disabled:opacity-50","data-testid":"force-push-confirm-button",children:g("git.danger.forcePush")}),(0,r.jsx)("button",{type:"button",onClick:()=>P(!1),className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]})]})}),ce=(0,i.memo)(function(e){var t,n,a,s;let{worktreeId:l,onDiffSelect:o,isMobile:d=!1,worktree:u,onInsertToMessage:h,className:f=""}=e,x=(0,c.c)("worktree"),{activeTab:p,setActiveTab:g,historyOpen:b,toggleHistory:v,advancedOpen:y,toggleAdvanced:j}=function(){let{value:e,setValue:t,isAvailable:n}=(0,nm.V)({key:oL.activeTab,defaultValue:"status",validate:oR}),{value:a,setValue:r}=(0,nm.V)({key:oL.historyOpen,defaultValue:!0,validate:oP}),{value:s,setValue:l}=(0,nm.V)({key:oL.advancedOpen,defaultValue:!1,validate:oP}),o=(0,i.useCallback)(e=>t(e),[t]);return{activeTab:e,setActiveTab:o,historyOpen:a,toggleHistory:(0,i.useCallback)(()=>r(e=>!e),[r]),advancedOpen:s,toggleAdvanced:(0,i.useCallback)(()=>l(e=>!e),[l]),isPersistent:n}}(),w=Object.values(null!=(n=null==u?void 0:u.sessionStatusByCli)?n:{}).some(e=>(null==e?void 0:e.isRunning)===!0),{gitStatus:k,statusLoading:N,statusError:C,fetchStatus:S}=function(e){let[t,n]=(0,i.useState)(null),[a,r]=(0,i.useState)(!0),[s,l]=(0,i.useState)(null),o=(0,i.useCallback)(async()=>{l(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/status"));if(!t.ok){let e=await t.json().catch(()=>({}));l(e.error||"Failed to fetch git status");return}let a=await t.json();n(a)}catch(e){l("Failed to fetch git status")}finally{r(!1)}},[e]);return(0,i.useEffect)(()=>{o()},[o]),{gitStatus:t,statusLoading:a,statusError:s,fetchStatus:o}}(l),{commits:T,selectedCommit:I,changedFiles:E,inlineDiffCommit:A,inlineFiles:M,inlineFilesLoading:L,inlineFilesError:R,selectedFile:P,diffContent:D,isLoading:F,isLoadingFiles:O,isLoadingDiff:z,commitError:_,detailError:B,setDiffContent:H,fetchCommits:V,handleCommitSelect:U,handleFileSelect:K,handleToggleInlineDiff:W,handleInlineDiffFile:$,handleRefresh:q}=function(e,t){let[n,a]=(0,i.useState)([]),[r,s]=(0,i.useState)(null),[l,o]=(0,i.useState)([]),[c,d]=(0,i.useState)(null),[u,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(!1),[x,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(!0),[k,N]=(0,i.useState)(!1),[C,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(null),[E,A]=(0,i.useState)(null),M=(0,i.useCallback)(async()=>{w(!0),I(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/log"));if(!t.ok){let e=await t.json();I(e.error||"Failed to fetch commit history");return}let n=await t.json();a(n.commits)}catch(e){I("Failed to fetch commit history")}finally{w(!1)}},[e]),L=(0,i.useCallback)(async t=>{N(!0),o([]),b(null),y(null),A(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json();A(e.error||"Failed to fetch commit details");return}let a=await n.json();o(a.files)}catch(e){A("Failed to fetch commit details")}finally{N(!1)}},[e]),R=(0,i.useCallback)(async(n,a)=>{S(!0),y(null),A(null);try{let r=await fetch("/api/worktrees/".concat(e,"/git/diff?commit=").concat(n,"&file=").concat(encodeURIComponent(a)));if(!r.ok){let e=await r.json();A(e.error||"Failed to fetch diff");return}let s=await r.json();y(s.diff),t(s.diff,a)}catch(e){A("Failed to fetch diff")}finally{S(!1)}},[e,t]);(0,i.useEffect)(()=>{M()},[M]);let P=(0,i.useCallback)(e=>{s(e),L(e)},[L]),D=(0,i.useCallback)(e=>{r&&(b(e),R(r,e))},[r,R]),F=(0,i.useCallback)(async t=>{if(c===t){d(null),m([]),p(null);return}d(t),m([]),p(null),f(!0);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json().catch(()=>({}));p(e.error||"Failed to fetch commit details");return}let a=await n.json();m(Array.isArray(a.files)?a.files:[])}catch(e){p("Failed to fetch commit details")}finally{f(!1)}},[e,c]),O=(0,i.useCallback)((e,t)=>{s(e),b(t),o(u),R(e,t)},[u,R]),z=(0,i.useCallback)(()=>{s(null),o([]),b(null),y(null),A(null),M()},[M]);return{commits:n,selectedCommit:r,changedFiles:l,inlineDiffCommit:c,inlineFiles:u,inlineFilesLoading:h,inlineFilesError:x,selectedFile:g,diffContent:v,isLoading:j,isLoadingFiles:k,isLoadingDiff:C,commitError:T,detailError:E,setDiffContent:y,fetchCommits:M,handleCommitSelect:P,handleFileSelect:D,handleToggleInlineDiff:F,handleInlineDiffFile:O,handleRefresh:z}}(l,o),G=(0,i.useCallback)(async()=>{await V(),await S()},[V,S]),{staged:J,stagedLoading:Y,stagedError:Q,opBusy:X,commitMessage:Z,setCommitMessage:ee,amend:et,setAmend:en,committing:ea,changesCommitError:er,fetchStaged:es,handleStage:el,handleUnstage:ei,handleChangesDiff:eo,fetchWorkingDiffText:ec,commit:ed,commitAndPush:eu}=function(e,t){let{onWorkingDiff:n,onCommitted:a}=t,[r,s]=(0,i.useState)(null),[l,o]=(0,i.useState)(!0),[c,d]=(0,i.useState)(null),[u,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(""),[x,p]=(0,i.useState)(!1),[g,b]=(0,i.useState)(!1),[v,y]=(0,i.useState)(null),j=(0,i.useCallback)(async()=>{d(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/staged"));if(!t.ok){let e=await t.json().catch(()=>({}));d(e.error||"Failed to fetch changes");return}let n=await t.json();s(n)}catch(e){d("Failed to fetch changes")}finally{o(!1)}},[e]);(0,i.useEffect)(()=>{j()},[j]);let w=(0,i.useCallback)(async t=>{m(!0),d(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/stage"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[t]})});if(!n.ok){let e=await n.json().catch(()=>({}));d(e.error||"Failed to stage file");return}await j()}catch(e){d("Failed to stage file")}finally{m(!1)}},[e,j]),k=(0,i.useCallback)(async t=>{m(!0),d(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/unstage"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[t]})});if(!n.ok){let e=await n.json().catch(()=>({}));d(e.error||"Failed to unstage file");return}await j()}catch(e){d("Failed to unstage file")}finally{m(!1)}},[e,j]),N=(0,i.useCallback)(async()=>{y(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:h,amend:x})});if(!t.ok){let e=await t.json().catch(()=>({}));return y(e.error||"Failed to commit"),!1}return f(""),p(!1),await j(),await a(),!0}catch(e){return y("Failed to commit"),!1}},[e,h,x,j,a]),C=(0,i.useCallback)(async()=>{b(!0);try{await N()}finally{b(!1)}},[N]),S=(0,i.useCallback)(async e=>{b(!0);try{await N()&&await e()}finally{b(!1)}},[N]);return{staged:r,stagedLoading:l,stagedError:c,opBusy:u,commitMessage:h,setCommitMessage:f,amend:x,setAmend:p,committing:g,changesCommitError:v,fetchStaged:j,handleStage:w,handleUnstage:k,handleChangesDiff:(0,i.useCallback)(async(t,a)=>{try{let r=await fetch("/api/worktrees/".concat(e,"/git/working-diff?file=").concat(encodeURIComponent(t),"&mode=").concat(a));if(!r.ok)return;let s=await r.json();"string"==typeof s.diff&&n(s.diff,t)}catch(e){}},[e,n]),fetchWorkingDiffText:(0,i.useCallback)(async(t,n)=>{try{let a=await fetch("/api/worktrees/".concat(e,"/git/working-diff?file=").concat(encodeURIComponent(t),"&mode=").concat(n));if(!a.ok)return null;let r=await a.json();return"string"==typeof r.diff?r.diff:null}catch(e){return null}},[e]),commit:C,commitAndPush:S}}(l,{onWorkingDiff:(0,i.useCallback)((e,t)=>{H(e),o(e,t)},[H,o]),onCommitted:G}),{branches:em,branchInclude:eh,branchesLoading:ef,branchesError:ex,branchBusy:ep,branchActionError:eg,fetchBranches:eb,handleBranchIncludeChange:ev,handleBranchesRefresh:ey,handleCheckout:ej,handleBranchCreate:ew,handleBranchDelete:ek}=function(e,t){let{onCheckoutCascade:n}=t,[a,r]=(0,i.useState)([]),[s,l]=(0,i.useState)("local"),[o,c]=(0,i.useState)(!0),[d,u]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[f,x]=(0,i.useState)(null),p=(0,i.useCallback)(async t=>{u(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/branches?include=").concat(t));if(!n.ok){let e=await n.json().catch(()=>({}));u(e.error||"Failed to fetch branches");return}let a=await n.json();r(Array.isArray(a.branches)?a.branches:[])}catch(e){u("Failed to fetch branches")}finally{c(!1)}},[e]);(0,i.useEffect)(()=>{p(s)},[p,s]);let g=(0,i.useCallback)(e=>{l(e)},[]),b=(0,i.useCallback)(()=>{p(s)},[p,s]),v=(0,i.useCallback)(async(t,a)=>{h(!0),x(null);try{let r=await fetch("/api/worktrees/".concat(e,"/git/checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t.name,force:a})});if(!r.ok){let e=await r.json().catch(()=>({}));x(e.error||"Failed to checkout branch");return}await Promise.all([n(),p(s)])}catch(e){x("Failed to checkout branch")}finally{h(!1)}},[e,s,n,p]),y=(0,i.useCallback)(async(t,n)=>{h(!0),x(null);try{let a=await fetch("/api/worktrees/".concat(e,"/git/branch/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,from:n})});if(!a.ok){let e=await a.json().catch(()=>({}));x(e.error||"Failed to create branch");return}await p(s)}catch(e){x("Failed to create branch")}finally{h(!1)}},[e,s,p]),j=(0,i.useCallback)(async(t,n)=>{h(!0),x(null);try{let a=await fetch("/api/worktrees/".concat(e,"/git/branch/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,force:n})});if(!a.ok){let e=await a.json().catch(()=>({}));x(e.error||"Failed to delete branch");return}await p(s)}catch(e){x("Failed to delete branch")}finally{h(!1)}},[e,s,p]);return{branches:a,branchInclude:s,branchesLoading:o,branchesError:d,branchBusy:m,branchActionError:f,fetchBranches:p,handleBranchIncludeChange:g,handleBranchesRefresh:b,handleCheckout:v,handleBranchCreate:y,handleBranchDelete:j}}(l,{onCheckoutCascade:(0,i.useCallback)(async()=>{await Promise.all([S(),es(),V()])},[S,es,V])}),{stashes:eN,stashLoading:eC,stashError:eS,stashBusy:eT,stashActionError:eI,stashConflictNotice:eE,fetchStash:eA,handleStashPush:eM,handleStashPop:eL,handleStashApply:eR,handleStashDrop:eP}=function(e,t){let{onStashMutated:n}=t,[a,r]=(0,i.useState)([]),[s,l]=(0,i.useState)(!0),[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[f,x]=(0,i.useState)(null),p=(0,i.useCallback)(async()=>{c(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/stash"));if(!t.ok){let e=await t.json().catch(()=>({}));c(e.error||"Failed to fetch stashes");return}let n=await t.json();r(Array.isArray(n.stashes)?n.stashes:[])}catch(e){c("Failed to fetch stashes")}finally{l(!1)}},[e]);(0,i.useEffect)(()=>{p()},[p]);let g=(0,i.useCallback)(async()=>{await Promise.all([p(),n()])},[p,n]),b=(0,i.useCallback)(async(e,t,n)=>{u(!0),h(null),x(null);try{let a=await fetch(e,t),r=await a.json().catch(()=>({}));if(!a.ok)return void h(r.error||n);if(r.conflict){let e=Array.isArray(r.conflictFiles)?r.conflictFiles.join(", "):"",t=r.stashRetained?" (stash retained)":"";x("Stash operation produced conflicts: ".concat(e).concat(t))}await g()}catch(e){h(n)}finally{u(!1)}},[g]),v=(0,i.useCallback)((t,n)=>{b("/api/worktrees/".concat(e,"/git/stash/push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t||void 0,includeUntracked:n})},"Failed to stash changes")},[e,b]),y=(0,i.useCallback)(t=>{b("/api/worktrees/".concat(e,"/git/stash/pop"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({index:t})},"Failed to pop stash")},[e,b]);return{stashes:a,stashLoading:s,stashError:o,stashBusy:d,stashActionError:m,stashConflictNotice:f,fetchStash:p,handleStashPush:v,handleStashPop:y,handleStashApply:(0,i.useCallback)(t=>{b("/api/worktrees/".concat(e,"/git/stash/apply"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({index:t})},"Failed to apply stash")},[e,b]),handleStashDrop:(0,i.useCallback)(t=>{b("/api/worktrees/".concat(e,"/git/stash/").concat(t),{method:"DELETE"},"Failed to drop stash")},[e,b])}}(l,{onStashMutated:(0,i.useCallback)(async()=>{await Promise.all([S(),es()])},[S,es])}),{dangerBusy:eD,dangerActionError:eF,dangerConflictNotice:eO,handleReset:ez,handleRevert:e_}=function(e,t){let{onHeadMoved:n}=t,[a,r]=(0,i.useState)(!1),[s,l]=(0,i.useState)(null),[o,c]=(0,i.useState)(null);return{dangerBusy:a,dangerActionError:s,dangerConflictNotice:o,handleReset:(0,i.useCallback)(async(t,a,s)=>{r(!0),l(null),c(null);try{let r=await fetch("/api/worktrees/".concat(e,"/git/reset"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:t,mode:a,confirmBranch:s})});if(!r.ok){let e=await r.json().catch(()=>({}));l(e.error||"Failed to reset");return}await n()}catch(e){l("Failed to reset")}finally{r(!1)}},[e,n]),handleRevert:(0,i.useCallback)(async(t,a)=>{r(!0),l(null),c(null);try{let r=await fetch("/api/worktrees/".concat(e,"/git/revert"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commitHash:t,noCommit:a})});if(!r.ok){let e=await r.json().catch(()=>({}));l(e.error||"Failed to revert");return}let s=await r.json().catch(()=>({}));if(s.conflict){let e=Array.isArray(s.conflictFiles)?s.conflictFiles.join(", "):"";c("Revert produced conflicts: ".concat(e))}await n()}catch(e){l("Failed to revert")}finally{r(!1)}},[e,n])}}(l,{onHeadMoved:(0,i.useCallback)(async()=>{await Promise.all([S(),es(),eb(eh),V()])},[S,es,eb,eh,V])}),{operation:eB,progressState:eH,error:eV,errorReason:eU,conflict:eK,conflictFiles:eW,runFetch:e$,runPull:eq,runPush:eG,abort:eJ}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{onCascade:n}=t,[a,r]=(0,i.useState)(null),[s,l]=(0,i.useState)("idle"),[o,c]=(0,i.useState)(null),[d,u]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[f,x]=(0,i.useState)([]),p=(0,i.useRef)(null),g=(0,i.useRef)(n);(0,i.useEffect)(()=>{g.current=n},[n]),(0,i.useEffect)(()=>()=>{var e;null==(e=p.current)||e.abort()},[]);let b=(0,i.useCallback)(async(t,n,a)=>{var s,i,o;c(null),u(null),h(!1),x([]),r(t),l("running");let d=new AbortController;p.current=d;try{let r=await fetch("/api/worktrees/".concat(e,"/git/").concat(n),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:d.signal});if(!r.ok){let e=await r.json().catch(()=>({}));u((s=null==e?void 0:e.reason,"auth_failed"===s?"auth_failed":"protected_branch"===s?"protected_branch":null)),c((i=null==e?void 0:e.error,"string"==typeof i&&i.length>0?i:null)),l("error");return}let o=await r.json().catch(()=>({success:!0}));"pull"===t&&(null==o?void 0:o.conflict)&&(h(!0),x(Array.isArray(o.conflictFiles)?o.conflictFiles:[])),l("idle")}catch(e){e instanceof Error&&"AbortError"===e.name?l("idle"):(c(null),u(null),l("error"))}finally{r(null),p.current=null,null==(o=g.current)||o.call(g,t)}},[e]),v=(0,i.useCallback)(e=>{let t={prune:!0===e.prune};return void 0!==e.remote&&(t.remote=e.remote),b("fetch","fetch",t)},[b]),y=(0,i.useCallback)(e=>{let t={rebase:!0===e.rebase,ffOnly:!0===e.ffOnly};return void 0!==e.remote&&(t.remote=e.remote),void 0!==e.branch&&(t.branch=e.branch),b("pull","pull",t)},[b]);return{operation:a,progressState:s,error:o,errorReason:d,conflict:m,conflictFiles:f,runFetch:v,runPull:y,runPush:(0,i.useCallback)(e=>{let t={force:!0===e.force,forceWithLease:!0===e.forceWithLease,setUpstream:!0===e.setUpstream};return void 0!==e.remote&&(t.remote=e.remote),void 0!==e.branch&&(t.branch=e.branch),b("push","push",t)},[b]),abort:(0,i.useCallback)(()=>{var e;null==(e=p.current)||e.abort()},[])}}(l,{onCascade:(0,i.useCallback)(e=>{S(),eb(eh),"pull"===e&&(es(),V())},[S,eb,eh,es,V])}),eY="auth_failed"===eU?x("git.network.authFailedGuidance"):"protected_branch"===eU?x("git.danger.protectedBranchWarning"):eV,eQ="running"===eH&&("push"===eB||"pull"===eB),eX=(null==k?void 0:k.aheadBehind)!=null,eZ=(0,i.useCallback)(()=>{e$({})},[e$]),e0=(0,i.useCallback)(()=>eu(()=>eG({setUpstream:!eX})),[eu,eG,eX]);sO({intervalMs:5e3,enabled:"running"!==eH,onPoll:S});let e1=(0,i.useMemo)(()=>({isMobile:d,onDiffSelect:o,onInsertToMessage:h}),[d,o,h]),e2=(0,r.jsx)(oZ,{gitStatus:k,statusLoading:N,statusError:C,onRefresh:eZ,refreshing:"running"===eH}),e5=(0,r.jsx)(o0,{progressState:eH,operation:eB,error:eY,conflict:eK,conflictFiles:eW,hasUpstream:eX,onPull:()=>eq({}),onPush:()=>eG({setUpstream:!eX}),onAbort:eJ,extraActions:(0,r.jsx)(oO,{branches:em,busy:ep||eQ,actionError:eg,hasRunningSession:w,isMobile:d,onCheckout:ej})}),e4=(0,r.jsx)(o2,{staged:J,loading:Y,error:Q,busy:X||eQ,commitMessage:Z,amend:et,committing:ea,commitError:er,onRefresh:es,onDiff:eo,onPreview:ec,onStage:el,onUnstage:ei,onCommitMessageChange:ee,onAmendChange:en,onCommit:ed,onCommitAndPush:e0}),e3=(0,r.jsx)(o5,{commits:T,isLoading:F,commitError:_,commitListOpen:b,onToggleCommitList:v,onRefresh:q,selectedCommit:I,onCommitSelect:U,inlineDiffCommit:A,inlineFiles:M,inlineFilesLoading:L,inlineFilesError:R,onToggleInlineDiff:W,onInlineDiffFile:$,changedFiles:E,isLoadingFiles:O,detailError:B,selectedFile:P,onFileSelect:K,diffContent:D,isLoadingDiff:z}),e6=(0,r.jsxs)(oz,{open:y,onToggle:j,children:[(0,r.jsxs)("div",{className:"flex flex-col gap-1.5 px-3 py-2 border-b border-border","data-testid":"git-advanced-fetch",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:x("git.remote")}),(0,r.jsx)("div",{children:(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>e$({}),disabled:"running"===eH,className:"px-2 py-1 text-xs rounded border border-input text-foreground hover:bg-muted disabled:opacity-50","data-testid":"git-fetch-button",children:x("git.network.fetch")})})]}),(0,r.jsx)(o6,{branches:em,include:eh,loading:ef,error:ex,busy:ep||eQ,actionError:eg,onIncludeChange:ev,onRefresh:ey,onCreate:ew,onDelete:ek}),(0,r.jsx)(o8,{stashes:eN,loading:eC,error:eS,busy:eT||eQ,actionError:eI,conflictNotice:eE,hasRunningSession:w,onRefresh:eA,onPush:eM,onPop:eL,onApply:eR,onDrop:eP}),(0,r.jsx)(o7,{selectedCommit:I,busy:eD||eQ,actionError:eF,conflictNotice:eO,currentBranch:null!=(a=null==k?void 0:k.currentBranch)?a:null,aheadCount:null!=(s=null==k||null==(t=k.aheadBehind)?void 0:t.ahead)?s:null,hasRunningSession:w,onReset:ez,onRevert:e_,onForcePush:e=>eG(e?{forceWithLease:!0}:{force:!0})})]});return(0,r.jsx)(oB,{value:e1,children:(0,r.jsx)(o$,{activeTab:p,onTabChange:g,className:f,statusSection:e2,quickActionsSection:e5,changesSection:e4,historySection:e3,advancedSection:e6})})}),ct=(0,i.memo)(function(e){let{worktreeId:t,worktree:n,onWorktreeUpdate:a}=e,[s,l]=(0,i.useState)(!1),o=(0,c.c)("worktree"),d=(0,i.useRef)(null==n?void 0:n.id),u=(0,i.useRef)(!1),m=cu(n,a,null==n?void 0:n.id,()=>{let e=(null==n?void 0:n.id)!==d.current;return d.current=null==n?void 0:n.id,e&&!u.current});return(u.current=m.isEditing,n)?(0,r.jsx)("div",{className:"p-4 space-y-4 overflow-y-auto h-full",children:(0,r.jsx)(cm,{worktreeId:t,worktree:n,cardClassName:"bg-surface rounded-lg border border-border p-4",descriptionEditor:m,showLogs:s,onToggleLogs:()=>l(!s),onWorktreeUpdate:a})}):(0,r.jsx)("div",{className:"text-muted-foreground text-center py-8",children:o("detail.loadingInfo")})}),cn=(0,i.memo)(function(e){let{activeTab:t,worktreeId:n,worktree:a,messages:s,cliToolId:l,instanceId:i,onFilePathClick:o,onFileSelect:d,onWorktreeUpdate:u,onNewFile:m,onNewDirectory:h,onRename:f,onDelete:x,onUpload:p,onMove:g,onFileTreeReset:b,refreshTrigger:v,fileSearch:y,showToast:j,selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:S,vibeLocalModel:T,onVibeLocalModelChange:I,vibeLocalContextWindow:A,onVibeLocalContextWindowChange:M,disableAutoFollow:L,historySubTab:R,onHistorySubTabChange:P,onDiffSelect:D,onInsertToMessage:F,showArchived:O,onShowArchivedChange:z,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:H,onHistoryUserOnlyChange:V,useInstanceManagement:U,instances:K,onInstancesChange:W,visibleInstanceIds:$,onToggleInstanceVisible:q,verification:G,toolsSubTabRequest:J,onSurfaceModeChange:Y}=e,Q=(0,c.c)("worktree");switch(t){case"terminal":return(0,r.jsx)(E,{componentName:"TerminalDisplay",children:(0,r.jsx)(rW,{worktreeId:n,cliToolId:l,instanceId:i,disableAutoFollow:L,onSurfaceModeChange:Y})});case"history":return(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsxs)("div",{className:"flex border-b border-border shrink-0",children:[(0,r.jsx)("button",{type:"button",onClick:()=>P("message"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("message"===R?"text-accent-600 dark:text-accent-400 border-b-2 border-accent-600 dark:border-accent-400 bg-accent-50 dark:bg-accent-900/30":"text-muted-foreground hover:text-foreground"),children:Q("detail.subTabMessage")}),(0,r.jsx)("button",{type:"button",onClick:()=>P("git"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("git"===R?"text-accent-600 dark:text-accent-400 border-b-2 border-accent-600 dark:border-accent-400 bg-accent-50 dark:bg-accent-900/30":"text-muted-foreground hover:text-foreground"),children:Q("detail.subTabGit")})]}),"message"===R?(0,r.jsx)(E,{componentName:"HistoryPane",children:(0,r.jsx)(su,{messages:s,worktreeId:n,onFilePathClick:o,className:"flex-1 min-h-0",showToast:j,onInsertToMessage:F,showArchived:O,onShowArchivedChange:z,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:H,onHistoryUserOnlyChange:V})}):(0,r.jsx)(E,{componentName:"GitPane",children:(0,r.jsx)(ce,{worktreeId:n,onDiffSelect:D,isMobile:!0,worktree:null!=a?a:void 0,onInsertToMessage:F,className:"flex-1 min-h-0"})})]});case"files":var X;return(0,r.jsx)(E,{componentName:"FileTreeView",children:(0,r.jsxs)("div",{className:"h-full flex flex-col overflow-hidden",children:[(0,r.jsx)(sW,{query:y.query,mode:y.mode,isSearching:y.isSearching,error:y.error,onQueryChange:y.setQuery,onModeChange:y.setMode,onClear:y.clearSearch}),(0,r.jsx)(sH,{worktreeId:n,onFileSelect:d,onNewFile:m,onNewDirectory:h,onRename:f,onDelete:x,onUpload:p,onMove:g,onResetView:b,refreshTrigger:v,pollingEnabled:"files"===t,searchQuery:y.query,searchMode:y.mode,searchResults:null==(X=y.results)?void 0:X.results,className:"flex-1 min-h-0"})]})});case"memo":return(0,r.jsx)(E,{componentName:"NotesAndLogsPane",children:(0,r.jsx)(oE,{worktreeId:n,className:"h-full",selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:S,vibeLocalModel:T,onVibeLocalModelChange:I,vibeLocalContextWindow:A,onVibeLocalContextWindowChange:M,onInsertToMessage:F,useInstanceManagement:U,instances:K,onInstancesChange:W,visibleInstanceIds:$,onToggleInstanceVisible:q,modelByInstance:cd(null==a?void 0:a.sessionStatusByInstance),composerTargetInstanceId:i,verification:G,requestedSubTab:J})});case"info":return(0,r.jsx)(ct,{worktreeId:n,worktree:a,onWorktreeUpdate:u});default:return null}}),ca="v".concat("0.33.2"),cr=[{value:null,labelKey:"worktreeStatus.notSet"},{value:"ready",labelKey:"worktreeStatus.ready"},{value:"in_progress",labelKey:"worktreeStatus.inProgress"},{value:"in_review",labelKey:"worktreeStatus.inReview"},{value:"done",labelKey:"worktreeStatus.done"}];function cs(e,t,n){if(!e)return null;let a=t?"".concat(e," \xb7 ").concat(t):e;return n?"".concat(n," \xb7 ").concat(a):a}function cl(e,t){if(!e||!e.liveness&&!e.degradedReason)return null;let n=t("sse"===e.kind?"agentSource.kindSse":"scraper"===e.kind?"agentSource.kindScraper":"agentSource.kindHooks"),a=void 0===e.degradedReason?null:"port_identity_changed"===e.degradedReason?t("agentSource.reasonPortIdentityChanged"):"heartbeat_stale"===e.degradedReason?t("agentSource.reasonHeartbeatStale"):"not_subscribed"===e.degradedReason?t("agentSource.reasonNotSubscribed"):t("agentSource.reasonOther",{reason:e.degradedReason}),r=["stale"===e.liveness?t("agentSource.livenessStale"):"live"===e.liveness?t("agentSource.livenessLive"):null,a].filter(e=>null!==e).join(" \xb7 ");return r?t("agentSource.line",{kind:n,state:r}):t("agentSource.lineBare",{kind:n})}function ci(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2;return"number"==typeof e&&Number.isFinite(e)?new Intl.NumberFormat(t,{style:"currency",currency:"USD",minimumFractionDigits:n,maximumFractionDigits:n}).format(e):null}function co(e,t,n,a){var r;let s=ci(null==e?void 0:e.cost,a),l=(r=null==t?void 0:t.tokens,"number"==typeof r&&Number.isFinite(r)?new Intl.NumberFormat(a,{notation:"compact",maximumFractionDigits:1}).format(r):null),i=[];return s&&i.push(s),l&&i.push("number"==typeof(null==t?void 0:t.percent)?n("agentSession.context",{tokens:l,percent:t.percent}):l),i.length>0?i.join(" \xb7 "):null}function cc(e,t,n,a){let r=[];(null==e?void 0:e.title)&&r.push(n("agentSession.titleLabel",{title:e.title})),(null==e?void 0:e.agent)&&r.push(n("agentSession.agentLabel",{agent:e.agent}));let s=ci(null==e?void 0:e.cost,a,4);s&&r.push(n("agentSession.costLabel",{cost:s}));let l=function(e){if(!e)return null;if(null!==e.total)return e.total;let t=[e.input,e.output,e.reasoning,e.cacheRead,e.cacheWrite].filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===t.length?null:t.reduce((e,t)=>e+t,0)}(null==e?void 0:e.tokens);if(null!==l&&r.push(n("agentSession.spentLabel",{tokens:new Intl.NumberFormat(a).format(l)})),"number"==typeof(null==t?void 0:t.tokens)){let e=new Intl.NumberFormat(a).format(t.tokens);r.push("number"==typeof t.limit&&"number"==typeof t.percent?n("agentSession.contextLabel",{tokens:e,limit:new Intl.NumberFormat(a).format(t.limit),percent:t.percent}):n("agentSession.contextUnknownLabel",{tokens:e}))}return r.length>0?r.join("\n"):null}function cd(e){if(!e)return{};let t={};for(let[n,a]of Object.entries(e)){let e=cs(null==a?void 0:a.model,null==a?void 0:a.reasoningEffort);e&&(t[n]=e)}return t}function cu(e,t,n,a){let[r,s]=(0,i.useState)(!1),[l,o]=(0,i.useState)(""),[c,d]=(0,i.useState)(!1);(0,i.useEffect)(()=>{a()&&e&&(o(e.description||""),s(!1))},[n,e]);let u=(0,i.useCallback)(async()=>{if(e){d(!0);try{let n=await el.y.updateDescription(e.id,l);t(n),s(!1)}catch(e){console.error("Failed to save description:",e)}finally{d(!1)}}},[e,l,t]),m=(0,i.useCallback)(()=>{o((null==e?void 0:e.description)||""),s(!1)},[e]);return{isEditing:r,text:l,setText:o,isSaving:c,handleSave:u,handleCancel:m,startEditing:(0,i.useCallback)(()=>{s(!0)},[])}}let cm=(0,i.memo)(function(e){var t,n;let{worktreeId:a,worktree:s,cardClassName:l,descriptionEditor:o,showLogs:d,onToggleLogs:u,onWorktreeUpdate:h}=e,{isEditing:f,text:x,setText:p,isSaving:g,handleSave:b,handleCancel:v,startEditing:y}=o,j=(0,c.c)("worktree"),w=(0,c.c)("common"),{copied:k,markCopied:N}=(0,e9.q)(),{copied:C,markCopied:S}=(0,e9.q)(),T=(0,i.useCallback)(async()=>{try{await (0,eq.l)(s.path),N()}catch(e){}},[s.path,N]),I=(0,i.useCallback)(async()=>{try{await (0,eq.l)(s.repositoryPath),S()}catch(e){}},[s.repositoryPath,S]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:l,children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-1",children:j("detail.worktree")}),(0,r.jsx)("p",{className:"text-lg font-semibold text-foreground",children:s.name})]}),(0,r.jsxs)("div",{className:l,children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground",children:j("detail.repository")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:I,className:"flex-shrink-0 p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":j("detail.copyRepositoryPath"),title:C?j("detail.copied"):j("detail.copyRepositoryPath"),children:C?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(eV.A,{className:"w-3.5 h-3.5"})})]}),(0,r.jsx)("p",{className:"text-base text-foreground",children:null!=(t=s.repositoryDisplayName)?t:s.repositoryName}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mt-1 break-all",children:s.repositoryPath})]}),(0,r.jsxs)("div",{className:l,children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground",children:j("detail.path")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:T,className:"flex-shrink-0 p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":j("detail.copyWorktreePath"),title:k?j("detail.copied"):j("detail.copyPath"),children:k?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(eV.A,{className:"w-3.5 h-3.5"})})]}),(0,r.jsx)("p",{className:"text-sm text-foreground break-all font-mono",children:s.path})]}),(0,r.jsxs)("div",{className:l,children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-1",children:j("detail.status")}),(0,r.jsx)("select",{value:null!=(n=s.status)?n:"",onChange:async e=>{let t=e.target.value;try{let e=await fetch("/api/worktrees/".concat(s.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:""===t?null:t})});if(e.ok&&h){let t=await e.json();h(t)}}catch(e){}},className:"text-sm px-3 py-1.5 rounded-lg border border-input bg-surface text-foreground focus:ring-2 focus:ring-ring focus:border-transparent w-full","data-testid":"mobile-status-dropdown","aria-label":j("detail.worktreeStatusLabel"),children:cr.map(e=>{var t;return(0,r.jsx)("option",{value:null!=(t=e.value)?t:"",children:j(e.labelKey)},e.labelKey)})})]}),(0,r.jsxs)("div",{className:l,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground",children:j("detail.description")}),!f&&(0,r.jsx)("button",{type:"button",onClick:y,className:"text-sm text-accent-600 hover:text-accent-800 dark:text-accent-400 dark:hover:text-accent-300",children:j("actions.edit")})]}),f?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("textarea",{value:x,onChange:e=>p(e.target.value),placeholder:j("detail.addNotesPlaceholder"),className:"w-full min-h-[150px] p-3 border border-input dark:bg-surface dark:text-foreground rounded-lg resize-y focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent",autoFocus:!0}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:b,disabled:g,className:"px-4 py-2 bg-accent-600 text-white rounded-lg hover:bg-accent-700 disabled:opacity-50 text-sm font-medium",children:g?j("actions.saving"):j("actions.save")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:v,disabled:g,className:"px-4 py-2 bg-muted text-foreground rounded-lg hover:bg-border disabled:opacity-50 text-sm font-medium",children:w("cancel")})]})]}):(0,r.jsx)("div",{className:"min-h-[50px]",children:s.description?(0,r.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:s.description}):(0,r.jsx)("p",{className:"text-sm text-muted-foreground italic",children:j("detail.noDescription")})})]}),s.link&&(0,r.jsxs)("div",{className:l,children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-1",children:j("detail.link")}),(0,r.jsx)("a",{href:s.link,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-600 hover:underline break-all",children:s.link})]}),s.updatedAt&&(0,r.jsxs)("div",{className:l,children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground mb-1",children:j("detail.lastUpdated")}),(0,r.jsx)("p",{className:"text-sm text-foreground",children:new Date(s.updatedAt).toLocaleString()})]}),(0,r.jsx)(tp,{version:ca,className:l}),(0,r.jsx)(tk,{className:l}),(0,r.jsxs)("div",{className:l,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-muted-foreground",children:j("detail.logs")}),(0,r.jsx)("button",{type:"button",onClick:u,className:"text-sm text-accent-600 hover:text-accent-800",children:d?j("detail.hide"):j("detail.show")})]}),d&&(0,r.jsx)(tm,{worktreeId:a})]})]})}),ch=(0,i.memo)(function(e){var t,n,a,s;let{worktreeName:l,repositoryName:o,description:d,status:u,gitStatus:f,onBackClick:p,onInfoClick:g,hasUpdate:b,worktreeStatus:v,onWorktreeStatusChange:y,sessionStatusByCli:j,sessionStatusByInstance:w,instances:k,activeInstanceId:C,onActiveInstanceChange:S,onAgentDragStart:T,onAgentDragEnd:I,onKillSession:E,verificationChip:A,agentSessionByInstance:M}=e,L=(0,c.c)("worktree"),R=(0,to.Ym)(),P=(0,c.c)("common"),D=tc.sb[u],F=D?L(D):void 0,[O,z]=(0,i.useState)(null),_=null==k?void 0:k.find(e=>e.id===C),B=!!C&&null!=(s=null!=(a=null==w||null==(t=w[C])?void 0:t.isRunning)?a:_?null==j||null==(n=j[_.cliTool])?void 0:n.isRunning:void 0)&&s,H=(0,i.useCallback)((e,t)=>{e.dataTransfer.setData(Z,t),e.dataTransfer.effectAllowed="move",z(t),null==T||T(t)},[T]),V=(0,i.useCallback)(()=>{z(null),null==I||I()},[I]),U=d?(0,x.W5)(d,50):null;return(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 bg-surface border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)("button",{type:"button",onClick:p,className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors","aria-label":L("detail.goBack"),"data-testid":"worktree-back-button",children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-4 0a1 1 0 01-1-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 01-1 1h-2z"})}),(0,r.jsx)("span",{className:"text-sm font-medium",children:L("detail.home")})]}),(0,r.jsx)("div",{className:"w-px h-6 bg-border","aria-hidden":"true"}),(0,r.jsx)(h.m,{"data-testid":"desktop-status-indicator",status:u,size:"lg",label:F}),(0,r.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,r.jsx)("h1",{className:"text-lg font-semibold text-foreground truncate max-w-[200px] leading-tight",children:l}),(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,r.jsx)("span",{className:"truncate max-w-[200px]",children:o}),f&&"(unknown)"!==f.currentBranch&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"/"}),(0,r.jsx)("span",{className:"truncate max-w-[150px] font-mono",title:f.currentBranch,"data-testid":"desktop-branch-name",children:(0,x.W5)(f.currentBranch,30)}),f.isDirty&&(0,r.jsx)("span",{className:"text-warning",title:L("git.uncommittedChanges"),children:"*"})]}),U&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"—"}),(0,r.jsx)("span",{className:"truncate max-w-[300px] text-muted-foreground",title:d,children:U})]})]})]}),A&&(0,r.jsx)("div",{className:"min-w-0 max-w-[360px]",children:A})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[k&&k.length>0&&(()=>{var e,t,n,a;let s=(0,td.Uw)(k.map(e=>{var t;return{item:e,status:(0,tC.kA)(null!=(t=null==w?void 0:w[e.id])?t:null==j?void 0:j[e.cliTool]),isActive:e.id===C}}),4),l=s.filter(e=>"overflow"===e.slot),i=null!=(a=null!=(n=null==(e=l.find(e=>"running"===e.status||"generating"===e.status))?void 0:e.status)?n:null==(t=l.find(e=>"waiting"===e.status))?void 0:t.status)?a:null,o=k.some(e=>{var t,n;return(null==(t=null!=(n=null==w?void 0:w[e.id])?n:null==j?void 0:j[e.cliTool])?void 0:t.awaitingInstruction)===!0});return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0","data-testid":"desktop-agent-status-row",children:[s.map(e=>{var t;if("overflow"===e.slot)return null;let n=e.item,a=(0,q.sw)(n),s=L("detail.statusPill",{label:a,status:P("status.".concat(e.status))}),l=null==w?void 0:w[n.id],i=null==M?void 0:M[n.id],o=cs(null==l?void 0:l.model,null==l?void 0:l.reasoningEffort,null==i||null==(t=i.session)?void 0:t.agent),c=o?L("detail.statusPillWithModel",{label:a,status:P("status.".concat(e.status)),model:o}):s,d=co(null==i?void 0:i.session,null==i?void 0:i.context,L,R),u=d?L("detail.statusPillWithUsage",{base:c,usage:d}):c,m=cl(null==l?void 0:l.eventSource,L),f=m?L("detail.statusPillWithSource",{base:u,source:m}):u,x=e.isActive,p={draggable:!0,onDragStart:e=>H(e,n.id),onDragEnd:V},g=O===n.id?" opacity-50 cursor-grabbing":"";return"pill"===e.slot?(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-".concat(n.id),onClick:()=>null==S?void 0:S(n.id),...p,"aria-label":f,title:f,"aria-pressed":x,className:"flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ".concat(x?"bg-accent-100 dark:bg-accent-900/30 text-accent-900 dark:text-accent-100":"hover:bg-muted text-foreground").concat(g),children:[(0,r.jsx)(h.m,{status:e.status,size:"sm","aria-hidden":!0,title:void 0}),(0,r.jsx)("span",{className:"whitespace-nowrap",children:s})]},n.id):(0,r.jsx)(Y.m_,{content:f,placement:"bottom",children:(0,r.jsx)("button",{type:"button","data-testid":"desktop-agent-status-".concat(n.id),onClick:()=>null==S?void 0:S(n.id),...p,"aria-label":f,"aria-pressed":x,className:"flex items-center justify-center w-6 h-6 rounded-full transition-colors ".concat(x?"bg-accent-100 dark:bg-accent-900/30":"hover:bg-muted").concat(g),children:(0,r.jsx)(h.m,{status:e.status,size:"sm","aria-hidden":!0,title:void 0})})},n.id)}),l.length>0&&(0,r.jsxs)(J.rI,{children:[(0,r.jsx)(J.ty,{asChild:!0,children:(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-overflow","aria-label":L("agentStatus.moreAgents",{count:l.length}),className:"flex items-center gap-1 px-2 py-1 rounded text-xs tabular-nums text-muted-foreground hover:bg-muted transition-colors",children:[i&&(0,r.jsx)(h.m,{status:i,size:"sm","aria-hidden":!0,title:void 0}),"+",l.length]})}),(0,r.jsx)(J.SQ,{align:"end",children:l.map(e=>{let t=e.item,n=L("detail.statusPill",{label:(0,q.sw)(t),status:P("status.".concat(e.status))});return(0,r.jsxs)(J._2,{"data-testid":"desktop-agent-overflow-".concat(t.id),onSelect:()=>null==S?void 0:S(t.id),children:[(0,r.jsx)(h.m,{status:e.status,size:"sm","aria-hidden":!0,title:void 0}),(0,r.jsx)("span",{className:"whitespace-nowrap",children:n})]},t.id)})})]}),o&&(0,r.jsx)("span",{"data-testid":"desktop-awaiting-instruction-badge",className:"flex-shrink-0 rounded-full bg-success-subtle px-1.5 py-0.5 text-[10px] font-medium leading-4 text-success-foreground",title:L("awaitingInstruction.label"),children:L("awaitingInstruction.badge")})]})})(),E&&B&&(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:E,className:"flex items-center gap-1 px-2 py-1.5 text-xs font-medium rounded-lg text-danger-foreground hover:bg-danger-subtle transition-colors flex-shrink-0","aria-label":L("terminal.endSession"),"data-testid":"desktop-kill-session",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"✕"}),P("end")]}),y&&(0,r.jsx)("select",{value:null!=v?v:"",onChange:e=>{let t=e.target.value;y(""===t?null:t)},onClick:e=>e.stopPropagation(),className:"text-xs px-2 py-1.5 rounded-lg border border-input bg-surface text-foreground focus:ring-2 focus:ring-ring focus:border-transparent cursor-pointer","data-testid":"desktop-status-dropdown","aria-label":L("detail.worktreeStatusLabel"),children:cr.map(e=>{var t;return(0,r.jsx)("option",{value:null!=(t=e.value)?t:"",children:L(e.labelKey)},e.labelKey)})}),(0,r.jsx)(tS.g,{}),(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:g,className:"relative flex items-center gap-1.5 px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors","aria-label":L("detail.viewInfo"),children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("span",{className:"text-sm font-medium",children:L("detail.info")}),b&&(0,r.jsx)(N,{"data-testid":"info-update-indicator",className:"absolute top-0 right-0","aria-label":L("tabs.updateAvailable")})]})]})]})}),cf=(0,i.memo)(function(e){let{worktreeId:t,worktree:n,isOpen:a,onClose:s,onWorktreeUpdate:l}=e,[o,d]=(0,i.useState)(!1),u=(0,c.c)("worktree"),m=(0,i.useRef)(a),h=cu(n,l,a,()=>{let e=a&&!m.current;return m.current=a,e});return n?(0,r.jsx)(tN.a,{isOpen:a,onClose:s,title:u("detail.infoModalTitle"),size:"md",children:(0,r.jsx)("div",{className:"space-y-4 max-h-[70vh] overflow-y-auto","data-testid":"worktree-info-modal",children:(0,r.jsx)(cm,{worktreeId:t,worktree:n,cardClassName:"bg-muted rounded-lg p-4",descriptionEditor:h,showLogs:o,onToggleLogs:()=>d(!o),onWorktreeUpdate:l})})}):null}),cx=(0,i.memo)(function(){let e=(0,c.c)("worktree");return(0,r.jsx)("div",{className:"flex items-center justify-center h-full min-h-[200px]",role:"status","aria-live":"polite",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,r.jsx)(m.y$,{size:"xl",variant:"accent"}),(0,r.jsx)("p",{className:"text-muted-foreground",children:e("detail.loading")})]})})}),cp=(0,i.memo)(function(e){let{message:t,onRetry:n}=e,a=(0,c.c)("worktree"),s=(0,c.c)("common");return(0,r.jsx)("div",{className:"flex items-center justify-center h-full min-h-[200px]",role:"alert","aria-live":"assertive",children:(0,r.jsxs)("div",{className:"text-center p-6 bg-danger-subtle rounded-lg border border-danger-border max-w-md",children:[(0,r.jsx)("svg",{className:"mx-auto h-12 w-12 text-danger-foreground/70 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("p",{className:"text-danger-foreground font-medium",children:a("detail.errorLoading")}),(0,r.jsx)("p",{className:"text-danger-foreground/80 text-sm mt-2",children:t}),n&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:n,className:"mt-4 px-4 py-2 bg-danger-foreground text-danger-subtle rounded-lg hover:opacity-90 transition-opacity focus:outline-none focus:ring-2 focus:ring-danger focus:ring-offset-2 ring-offset-background",children:s("retry")})]})})}),cg=(0,i.memo)(function(e){let{activityPane:t,rightPane:n,activityPaneWidth:a=18,minPaneWidth:s=10,maxPaneWidth:l=60,onActivityPaneResize:o,className:d=""}=e,u=(0,i.useRef)(null),m=(0,c.c)("worktree"),[h,f]=(0,i.useState)(a),x=o?a:h,p=(0,i.useCallback)(e=>{let t=u.current;if(!t)return;let n=t.offsetWidth;if(0===n)return;let r=Math.min(l,Math.max(s,(o?a:h)+e/n*100));o?o(r):f(r)},[a,h,s,l,o]),g=(0,i.useMemo)(()=>"flex h-full min-h-0 ".concat(d).trim(),[d]);return(0,r.jsx)("div",{ref:u,className:"h-full",children:(0,r.jsxs)("div",{"data-testid":"desktop-layout",role:"main",className:g,children:[null!==t&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:"worktree-activity-pane","data-testid":"activity-pane-slot","aria-label":m("desktopLayout.activityPane"),style:{width:"".concat(x,"%")},className:"flex-shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",children:(0,r.jsx)(E,{componentName:"ActivityPane",children:t})}),(0,r.jsx)(st.f,{onResize:p,orientation:"horizontal",ariaValueNow:x})]}),(0,r.jsx)("div",{id:"worktree-right-pane","data-testid":"right-pane-slot","aria-label":m("desktopLayout.terminalPane"),className:"flex-grow overflow-hidden min-w-0",children:(0,r.jsx)(E,{componentName:"TerminalPane",children:n})})]})})});var cb=n(9540),cv=n(92001),cy=n(39332),cj=n(16485),cw=n(78192),ck=n(39324),cN=n(80298),cC=n(55867);let cS=[{id:"files",labelKey:"activityBar.files",icon:cv.A},{id:"git",labelKey:"activityBar.git",icon:cy.A},{id:"notes",labelKey:"activityBar.notes",icon:H.A},{id:"schedules",labelKey:"activityBar.schedules",icon:cj.A},{id:"agent",labelKey:"activityBar.agent",icon:cw.A},{id:"timer",labelKey:"activityBar.timer",icon:ck.A},{id:"todo",labelKey:"activityBar.todo",icon:cN.A},{id:"skills",labelKey:"activityBar.skills",icon:s4.A},{id:"verification",labelKey:"activityBar.verification",icon:n7.A},{id:"env",labelKey:"activityBar.env",icon:cC.A}],cT=new Set(cS.map(e=>e.id)),cI="files",cE="__closed__";function cA(e){return"".concat("commandmate.worktree.activeActivity-").concat(e)}var cM=n(32916);let cL=(0,i.memo)(function(e){let{active:t,onToggle:n,className:a=""}=e,s=(0,c.c)("worktree"),l=(0,i.useRef)([]),{isOpen:o,toggle:d}=(0,cM.VF)(),u=(0,i.useCallback)((e,t,a)=>{var r,s,i,o;if("Enter"===e.key||" "===e.key){e.preventDefault(),n(a);return}if("ArrowDown"===e.key){e.preventDefault();let n=(t+1)%cS.length;null==(r=l.current[n])||r.focus();return}if("ArrowUp"===e.key){e.preventDefault();let n=(t-1+cS.length)%cS.length;null==(s=l.current[n])||s.focus();return}if("Home"===e.key){e.preventDefault(),null==(i=l.current[0])||i.focus();return}if("End"===e.key){e.preventDefault(),null==(o=l.current[cS.length-1])||o.focus();return}},[n]);return(0,r.jsxs)("div",{"data-testid":"activity-bar",className:"flex flex-col items-stretch w-12 flex-shrink-0 bg-muted border-r border-border ".concat(a).trim(),children:[(0,r.jsx)(Y.m_,{content:s("activityBar.toggleSidebar"),placement:"right",children:(0,r.jsx)("button",{type:"button","data-testid":"activity-bar-toggle-sidebar",onClick:d,"aria-label":s("activityBar.toggleSidebar"),"aria-expanded":o,className:"flex items-center justify-center h-12 w-12 text-muted-foreground transition-colors hover:text-surface-foreground hover:bg-muted-foreground/10 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-inset",children:(0,r.jsx)(cb.A,{size:20,"aria-hidden":"true"})})}),(0,r.jsx)("div",{className:"mx-2 my-1 border-b border-border","aria-hidden":"true"}),(0,r.jsx)("div",{id:"worktree-activity-bar",role:"tablist","aria-orientation":"vertical","aria-label":s("activityBar.label"),className:"flex flex-col items-stretch",children:cS.map((e,a)=>{let i=e.icon,o=t===e.id,c=s(e.labelKey);return(0,r.jsx)(Y.m_,{content:c,placement:"right",children:(0,r.jsx)("button",{ref:e=>{l.current[a]=e},type:"button",role:"tab","aria-selected":o,"aria-label":c,"aria-controls":"worktree-activity-pane",tabIndex:o||null===t&&0===a?0:-1,onClick:()=>n(e.id),onKeyDown:t=>u(t,a,e.id),"data-testid":"activity-bar-button-".concat(e.id),className:"group flex items-center justify-center h-12 w-12 transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-inset",children:(0,r.jsx)("span",{"aria-hidden":"true",className:"flex items-center justify-center h-9 w-9 rounded-md transition-colors ".concat(o?"bg-accent-500/10 text-accent-600 dark:text-accent-400":"text-muted-foreground group-hover:text-surface-foreground group-hover:bg-muted-foreground/10"),children:(0,r.jsx)(i,{size:20,"aria-hidden":"true"})})})},e.id)})})]})}),cR="worktree-activity-pane",cP={files:"FileTreeView",git:"GitPane",notes:"MemoPane",schedules:"ExecutionLogPane",agent:"AgentInstancesPane",timer:"TimerPane",todo:"TodoPane",skills:"WorktreeSkillsPane",verification:"VerificationPane",env:"EnvManagerPane"},cD=(0,i.memo)(function(e){let{active:t,activities:n,className:a=""}=e;if(null===t)return(0,r.jsx)("div",{id:cR,"data-testid":"activity-pane","data-active":"none",className:"h-full flex flex-col ".concat(a).trim()});let s=n[t],l=cP[t];return(0,r.jsx)("div",{id:cR,"data-testid":"activity-pane","data-active":t,role:"tabpanel","aria-labelledby":"activity-bar-button-".concat(t),className:"h-full flex flex-col min-h-0 ".concat(a).trim(),children:(0,r.jsx)(E,{componentName:l,children:null!=s?s:null})})});var cF=n(13577),cO=n(72338),cz=n(90088);let c_=(0,i.memo)(function(e){let{inputRef:t,searchQuery:n,onQueryChange:a,matchCount:s,currentIdx:l,onNextMatch:i,onPrevMatch:o,onClose:d}=e,u=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted border-b border-input flex-shrink-0",children:[(0,r.jsx)("input",{ref:t,type:"text",value:n,onChange:e=>a(e.target.value),onKeyDown:e=>{"Escape"===e.key&&d(),"Enter"!==e.key||e.nativeEvent.isComposing||(e.shiftKey?o():i())},placeholder:u("fileSearch.placeholder"),className:"flex-1 min-w-0 px-2 py-0.5 text-sm bg-surface dark:text-foreground border border-input rounded outline-none focus:ring-1 focus:ring-ring",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground min-w-[3rem] text-right",children:s>0?"".concat(l+1,"/").concat(s):"0/0"}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:o,disabled:0===s,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground dark:hover:text-white disabled:text-muted-foreground/50","aria-label":u("fileSearch.prevMatch"),children:"▲"}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:i,disabled:0===s,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground dark:hover:text-white disabled:text-muted-foreground/50","aria-label":u("fileSearch.nextMatch"),children:"▼"}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:d,className:"min-w-[32px] min-h-[32px] flex items-center justify-center text-muted-foreground hover:text-foreground dark:hover:text-white","aria-label":u("fileSearch.close"),children:(0,r.jsx)(eG.A,{className:"w-4 h-4"})})]})}),cB=[{extension:".png",maxFileSize:0x1400000,allowedMimeTypes:["image/png"],magicBytes:[{bytes:[137,80,78,71,13,10,26,10]}]},{extension:".jpg",maxFileSize:0x1400000,allowedMimeTypes:["image/jpeg"],magicBytes:[{bytes:[255,216,255]}]},{extension:".jpeg",maxFileSize:0x1400000,allowedMimeTypes:["image/jpeg"],magicBytes:[{bytes:[255,216,255]}]},{extension:".gif",maxFileSize:0x1400000,allowedMimeTypes:["image/gif"],magicBytes:[{bytes:[71,73,70,56,55,97]},{bytes:[71,73,70,56,57,97]}]},{extension:".webp",maxFileSize:0x1400000,allowedMimeTypes:["image/webp"],magicBytes:[{bytes:[82,73,70,70],offset:0}]},{extension:".mp4",maxFileSize:0x6400000,allowedMimeTypes:["video/mp4"],magicBytes:[{bytes:[102,116,121,112],offset:4}]},{extension:".txt",maxFileSize:0x1400000,allowedMimeTypes:["text/plain"]},{extension:".log",maxFileSize:0x1400000,allowedMimeTypes:["text/plain"]},{extension:".md",maxFileSize:0x1400000,allowedMimeTypes:["text/markdown","text/plain"]},{extension:".csv",maxFileSize:0x1400000,allowedMimeTypes:["text/csv"]},{extension:".json",maxFileSize:0x1400000,allowedMimeTypes:["application/json"]},{extension:".yaml",maxFileSize:0x1400000,allowedMimeTypes:["text/yaml","application/x-yaml"]},{extension:".yml",maxFileSize:0x1400000,allowedMimeTypes:["text/yaml","application/x-yaml"]}],cH=cB.map(e=>e.extension),cV=[".md",".html",".htm",".yaml",".yml"];e$.j6,e$.j6;var cU=n(40051);function cK(){return(0,r.jsx)("div",{className:"flex items-center justify-center py-12 bg-surface",children:(0,r.jsx)(u.y,{size:"xl",variant:"accent"})})}let cW=(0,o.default)(()=>n.e(530).then(n.bind(n,530)).then(e=>({default:e.HtmlPreview})),{loadableGenerated:{webpack:()=>[530]},ssr:!1,loading:()=>(0,r.jsx)(cK,{})}),c$=(0,o.default)(()=>Promise.resolve().then(n.bind(n,27307)).then(e=>({default:e.PdfPreview})),{loadableGenerated:{webpack:()=>[27307]},ssr:!1,loading:()=>(0,r.jsx)(cK,{})}),cq=(0,o.default)(()=>n.e(3922).then(n.bind(n,33922)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[33922]},ssr:!1,loading:()=>(0,r.jsx)(cK,{})}),cG=/^---\s*\nmarp:\s*true/;function cJ(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,r.jsx)(u.y,{size:"xl",variant:"accent"}),(0,r.jsx)("p",{className:"ml-3 text-muted-foreground",children:e("fileViewer.loading")})]})}function cY(e){let{error:t}=e;return(0,r.jsx)("div",{className:"bg-danger-subtle border border-danger-border rounded-lg p-4 m-4",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-5 h-5 text-danger-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,r.jsx)("p",{className:"text-sm text-danger-foreground",children:t})]})})}function cQ(e){let{filePath:t,isMaximized:n,onToggleMaximize:a,copyableContent:s,onSearch:l}=e,i=(0,c.c)("worktree"),{copied:o,markCopied:d}=(0,e9.q)(),{copied:u,markCopied:m}=(0,e9.q)(),h=async()=>{try{await (0,eq.l)(t),d()}catch(e){}},f=async()=>{if(s)try{await (0,eq.l)(s),m()}catch(e){}};return(0,r.jsxs)("div",{className:"flex items-center justify-between p-1 border-b border-border gap-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,r.jsx)("button",{type:"button",onClick:h,className:"flex-shrink-0 p-1 rounded-md hover:bg-muted text-muted-foreground transition-colors","aria-label":i("actions.copyFilePath"),title:i("actions.copyPath"),children:o?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(eV.A,{className:"w-3.5 h-3.5"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground font-mono truncate",title:t,children:t})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[l&&(0,r.jsx)("button",{type:"button",onClick:l,className:"flex-shrink-0 p-1 rounded-md hover:bg-muted text-muted-foreground transition-colors","aria-label":i("actions.searchInFile"),title:i("actions.search"),children:(0,r.jsx)(B.A,{className:"w-3.5 h-3.5"})}),s&&(0,r.jsx)("button",{type:"button",onClick:f,className:"flex-shrink-0 p-1 rounded-md hover:bg-muted text-muted-foreground transition-colors","aria-label":i("actions.copyFileContent"),title:i("actions.copyContent"),children:u?(0,r.jsx)(ey.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ej.A,{className:"w-3.5 h-3.5"})}),(0,r.jsx)("button",{type:"button",onClick:a,className:"flex-shrink-0 p-1.5 rounded-md hover:bg-muted text-muted-foreground transition-colors","aria-label":i(n?"actions.minimize":"actions.maximize"),title:i(n?"actions.minimize":"actions.maximize"),children:n?(0,r.jsx)(W.A,{className:"w-4 h-4"}):(0,r.jsx)($.A,{className:"w-4 h-4"})})]})]})}function cX(e){var t;let{content:n,extension:a,searchMatches:s,searchCurrentIdx:l,totalLines:o,rangeStart:c,worktreeId:d,filePath:u,onLineRangeFetched:m}=e,h=(0,i.useRef)(null),f=(0,i.useMemo)(()=>n.split("\n"),[n]),x=Math.max(1,null!=c?c:1),p=f.length,g=Math.max(null!=o?o:p,p),b=(0,i.useRef)(new Map);(0,i.useEffect)(()=>{b.current.clear()},[n,a]);let v=(0,i.useCallback)(e=>{var t;let n=Math.floor(e/500),r=b.current,s=r.get(n);if(!s){let e=500*n,t=Math.min(e+500,f.length),l=f.slice(e,t).join("\n"),i="";try{i=e7.A.highlight(l,{language:a,ignoreIllegals:!0}).value}catch(e){i=e7.A.highlightAuto(l).value}s=i.split("\n"),r.set(n,s)}return null!=(t=s[e-500*n])?t:""},[f,a]),y=(0,i.useMemo)(()=>new Set(null!=s?s:[]),[s]),j=(null!=(t=null==s?void 0:s.length)?t:0)>0?s[null!=l?l:0]:-1,w=(0,nL.Te)({count:g,getScrollElement:()=>h.current,estimateSize:()=>24,overscan:100});(0,i.useEffect)(()=>{if(!s||0===s.length)return;let e=s[null!=l?l:0];if(!Number.isFinite(e))return;let t=Math.max(0,Math.min(g-1,e-1));w.scrollToIndex(t,{align:"center"})},[l,s,w,g]);let k=w.getVirtualItems();return!function(e){let{virtualItems:t,worktreeId:n,filePath:a,onLineRangeFetched:r,loadedStart:s,loadedLineCount:l}=e,o=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{if(!n||!a||!r||0===t.length)return;let e=t[0].index+1,i=t[t.length-1].index+1,c=s+l-1;if(e>=s&&i<=c)return;let d=Math.max(1,500*Math.floor((e-1)/500)+1),u=d+500-1;o.current.has(d)||(o.current.add(d),fetch("/api/worktrees/".concat(n,"/files/").concat((0,eX.o)(a),"?startLine=").concat(d,"&endLine=").concat(u)).then(async e=>e.ok?e.json():null).then(e=>{o.current.delete(d),e&&!0===e.success&&r({content:e.content,range:e.range,totalLines:e.totalLines,totalBytes:e.totalBytes})}).catch(()=>{o.current.delete(d)}))},[t,n,a,r,s,l])}({virtualItems:k,worktreeId:d,filePath:u,onLineRangeFetched:m,loadedStart:x,loadedLineCount:p}),(0,r.jsx)("div",{className:"overflow-auto h-full",ref:h,"data-testid":"file-content-code",children:(0,r.jsx)("div",{style:{height:w.getTotalSize(),width:"100%",position:"relative"},children:k.map(e=>{let t=e.index+1,n=t-x,a=n>=0&&n<p,s=t===j,l=y.has(t),i=a?v(n):"";return(0,r.jsxs)("div",{"data-line":t,"data-index":e.index,ref:w.measureElement,className:"absolute left-0 right-0 flex font-mono text-sm ".concat(s?"bg-warning/30":l?"bg-warning/15":""),style:{top:0,transform:"translateY(".concat(e.start,"px)"),height:"".concat(24,"px"),lineHeight:"".concat(24,"px")},children:[(0,r.jsx)("div",{className:"px-3 text-right select-none border-r border-border bg-muted dark:bg-muted/50 whitespace-nowrap ".concat(s||l?"text-warning-foreground":"text-muted-foreground"),style:{minWidth:"4rem"},children:t}),(0,r.jsx)("div",{className:"px-4 text-foreground flex-1 min-w-0 overflow-hidden",children:a?(0,r.jsx)("code",{className:"hljs",style:{padding:0,background:"transparent",whiteSpace:"pre"},dangerouslySetInnerHTML:{__html:i}}):(0,r.jsx)(cU.E,{className:"h-4 w-3/4"})})]},e.key)})})})}function cZ(e){let{slides:t,fileName:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,i.useState)(0);return 0===t.length?(0,r.jsx)("div",{className:"p-4 text-muted-foreground",children:a("fileViewer.noSlides",{fileName:n})}):(0,r.jsxs)("div",{className:"h-full flex flex-col","data-testid":"marp-preview",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between p-2 border-b border-border bg-muted",children:[(0,r.jsx)("button",{type:"button",onClick:()=>{l(e=>Math.max(0,e-1))},disabled:0===s,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:a("actions.prev")}),(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[s+1," / ",t.length]}),(0,r.jsx)("button",{type:"button",onClick:()=>{l(e=>Math.min(t.length-1,e+1))},disabled:s===t.length-1,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:a("actions.next")})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,r.jsx)("iframe",{srcDoc:t[s],sandbox:"",title:a("fileViewer.slideTitle",{name:n,number:s+1}),className:"w-full h-full border-0"})})]})}function c0(e){let{marpSlides:t,fileName:n,worktreeId:a,filePath:s,contentText:l,onFileSaved:o,isMaximized:d,onToggleMaximize:u,onDirtyChange:m,onOpenFile:h}=e,f=(0,c.c)("worktree"),[x,p]=(0,i.useState)("slides");return(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between p-1 border-b border-border bg-muted",children:[(0,r.jsxs)("div",{className:"flex gap-1",children:[(0,r.jsx)("button",{type:"button",onClick:()=>p("slides"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("slides"===x?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:f("fileViewer.slides")}),(0,r.jsx)("button",{type:"button",onClick:()=>p("editor"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("editor"===x?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:f("fileViewer.editor")})]}),(0,r.jsx)(cQ,{filePath:s,isMaximized:d,onToggleMaximize:u,copyableContent:l})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:"slides"===x?(0,r.jsx)(cZ,{slides:t,fileName:n}):(0,r.jsx)(cq,{worktreeId:a,filePath:s,onSave:o,initialViewMode:"split",onDirtyChange:m,onOpenFile:h})})]})}function c1(e){let{children:t,isMaximized:n,onToggle:a,filePath:s}=e;if(!n)return(0,r.jsx)(r.Fragment,{children:t});let l=(0,r.jsxs)("div",{"data-testid":"maximized-file-overlay",className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:eQ.M.MAXIMIZED_EDITOR},children:[(0,r.jsx)(cQ,{filePath:s,isMaximized:n,onToggleMaximize:a}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:t})]});return"undefined"==typeof document?l:(0,sf.createPortal)(l,document.body)}function c2(e){let{tab:t,content:n,worktreeId:a,isMaximized:s,onToggleMaximize:l,onFileSaved:i,onDirtyChange:o,onOpenFile:c}=e,d=e8(n.content);return(0,r.jsxs)(r.Fragment,{children:[!s&&(0,r.jsx)(cQ,{filePath:t.path,isMaximized:s,onToggleMaximize:l,copyableContent:n.content,onSearch:d.openSearch}),d.searchOpen&&(0,r.jsx)(c_,{inputRef:d.searchInputRef,searchQuery:d.searchQuery,onQueryChange:d.setSearchQuery,matchCount:d.searchMatches.length,currentIdx:d.searchCurrentIdx,onNextMatch:d.nextMatch,onPrevMatch:d.prevMatch,onClose:d.closeSearch}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:d.searchOpen&&d.searchQuery.length>=2?(0,r.jsx)(cX,{content:n.content,extension:"md",searchMatches:d.searchMatches,searchCurrentIdx:d.searchCurrentIdx}):(0,r.jsx)(cq,{worktreeId:a,filePath:t.path,onSave:i,initialViewMode:"preview",onDirtyChange:o,onOpenFile:c})})]})}function c5(e){var t,n;let{tab:a,content:s,worktreeId:l,isMaximized:o,onToggleMaximize:c,onLoadContent:d}=e,u=e8(s.content),m=(0,i.useCallback)(e=>{var t;d&&d(a.path,{...s,content:e.content,totalLines:e.totalLines,totalBytes:null!=(t=e.totalBytes)?t:s.totalBytes,range:e.range})},[d,a.path,s]),h=void 0!==s.range&&(null!=(n=s.totalLines)?n:0)>s.range.end-s.range.start+1;return(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(cQ,{filePath:a.path,isMaximized:o,onToggleMaximize:c,copyableContent:s.content,onSearch:u.openSearch}),u.searchOpen&&(0,r.jsx)(c_,{inputRef:u.searchInputRef,searchQuery:u.searchQuery,onQueryChange:u.setSearchQuery,matchCount:u.searchMatches.length,currentIdx:u.searchCurrentIdx,onNextMatch:u.nextMatch,onPrevMatch:u.prevMatch,onClose:u.closeSearch}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(cX,{content:s.content,extension:s.extension,searchMatches:u.searchOpen?u.searchMatches:void 0,searchCurrentIdx:u.searchOpen?u.searchCurrentIdx:void 0,totalLines:s.totalLines,rangeStart:null==(t=s.range)?void 0:t.start,worktreeId:h?l:void 0,filePath:h?a.path:void 0,onLineRangeFetched:h?m:void 0})})]})}let c4=(0,i.memo)(function(e){var t,n,a,s;let{tab:l,worktreeId:o,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,onDirtyChange:f,onOpenFile:x}=e,p=(0,c.c)("worktree"),g=(0,i.useRef)(p);g.current=p;let b=(0,i.useRef)(!1),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(!1);!function(e){let{tab:t,worktreeId:n,onLoadContent:a}=e,r=(0,i.useRef)(null),s=(0,i.useRef)(a);s.current=a;let l=(0,i.useRef)(t.path);l.current=t.path,sO({intervalMs:5e3,enabled:function(e){if(null===e.content||e.loading||e.isDirty||e.content.isPdf)return!1;let{totalBytes:t}=e.content;return void 0===t||!(t>=1048576)}(t),onPoll:async()=>{let e="/api/worktrees/".concat(n,"/files/").concat((0,eX.o)(l.current)),t={};r.current&&(t["If-Modified-Since"]=r.current);try{let n=await fetch(e,{headers:t});if(304===n.status||!n.ok)return;r.current=n.headers.get("Last-Modified");let a=await n.json();s.current(l.current,a)}catch(e){}}})}({tab:l,worktreeId:o,onLoadContent:d});let k=(0,i.useMemo)(()=>f?e=>f(l.path,e):void 0,[f,l.path]),N=(0,i.useCallback)(()=>{w(e=>!e)},[]);(0,i.useEffect)(()=>{if(!j)return;let e=e=>{"Escape"===e.key&&w(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j]),(0,i.useEffect)(()=>{null!==l.content||l.loading||null!==l.error||b.current||(b.current=!0,m(l.path,!0),(async()=>{try{let t=await fetch("/api/worktrees/".concat(o,"/files/").concat((0,eX.o)(l.path)));if(304===t.status)return;if(!t.ok){var e;let n=await t.json(),a="string"==typeof n.error?n.error:(null==(e=n.error)?void 0:e.message)||g.current("fileViewer.loadError");u(l.path,a);return}let n=await t.json();d(l.path,n)}catch(e){u(l.path,e instanceof Error?e.message:g.current("fileViewer.loadError"))}finally{b.current=!1}})())},[l.content,l.loading,l.error,l.path,o,d,u,m]);let C=null!=(a=null==(t=l.content)?void 0:t.content)?a:null,S=null!=(s=null==(n=l.content)?void 0:n.extension)?s:null;if((0,i.useEffect)(()=>{if(!C||"md"!==S||!cG.test(C)||C.length>1e6)return void y(null);let e=!1;return(async()=>{try{let t=await fetch("/api/worktrees/".concat(o,"/marp-render"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({markdownContent:C})});if(t.ok){let n=await t.json();e||y(Array.isArray(n.slides)?n.slides:null)}}catch(e){}})(),()=>{e=!0}},[C,S,o]),l.loading)return(0,r.jsx)(cJ,{});if(l.error)return(0,r.jsx)(cY,{error:l.error});if(!l.content)return null;let{content:T}=l;return T.isImage?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(cQ,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(ez.a,{src:T.content,alt:T.path,mimeType:T.mimeType})})]})}):T.isVideo?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(cQ,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(e_.u,{src:T.content,mimeType:T.mimeType})})]})}):T.isPdf?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(cQ,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(c$,{dataUri:T.content,filePath:l.path})})]})}):T.isHtml?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(cQ,{filePath:l.path,isMaximized:j,onToggleMaximize:N,copyableContent:T.content}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(cW,{worktreeId:o,filePath:l.path,htmlContent:T.content,onFileSaved:h,onOpenFile:x})})]})}):"md"===T.extension?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:v?(0,r.jsx)(c0,{marpSlides:v,fileName:l.name,worktreeId:o,filePath:l.path,contentText:T.content,onFileSaved:h,isMaximized:j,onToggleMaximize:N,onDirtyChange:k,onOpenFile:x}):(0,r.jsx)(c2,{tab:l,content:T,worktreeId:o,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:x})})}):!function(e){if(!e)return!1;let t=e.toLowerCase();return cV.includes(t)}("."+T.extension)?(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)(c5,{tab:l,content:T,worktreeId:o,isMaximized:j,onToggleMaximize:N,onLoadContent:d})}):(0,r.jsx)(c1,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:(0,r.jsx)(c2,{tab:l,content:T,worktreeId:o,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:x})})})}),c3="commandmate:file-tabs:";function c6(e){let t=e.split("/");return t[t.length-1]||e}function c8(e,t,n){let a=e.findIndex(e=>e.path===t);if(-1===a)return null;let r=[...e];return r[a]=n(r[a]),r}function c9(e,t,n){if("all"===n)return e.map(e=>e.path);let a=e.findIndex(e=>e.path===t);return -1===a?[]:"others"===n?e.filter((e,t)=>t!==a).map(e=>e.path):e.slice(a+1).map(e=>e.path)}let c7={tabs:[],activeIndex:null};function de(e,t,n){if(t<=0||n<=0)return 0;let a=e+t+8-n;return a>0?-Math.min(a,Math.max(0,e-8)):e<8?8-e:0}let dt=(0,i.memo)(function(e){let{tab:t,isActive:n,onActivate:a,onClose:s,onOpenMenu:l}=e,o=(0,c.c)("worktree"),d=(0,i.useCallback)(()=>{n||a(t.path)},[n,a,t.path]),u=(0,i.useCallback)(e=>{e.stopPropagation(),s(t.path)},[s,t.path]),m=(0,i.useCallback)(e=>{l(e,t.path)},[l,t.path]),h=(0,i.useCallback)(e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),s(t.path))},[s,t.path]),f=n?"border-accent-500 text-accent-600 dark:text-accent-400 bg-surface":"border-transparent text-muted-foreground hover:text-foreground";return(0,r.jsxs)("div",{"data-testid":"file-tab-".concat(t.path),"data-active":n,onClick:d,onAuxClick:h,onContextMenu:m,className:"flex items-center gap-1 px-3 py-2 text-sm font-medium border-b-2 cursor-pointer flex-shrink-0 ".concat(f),children:[(0,r.jsx)("span",{className:"truncate max-w-[120px]",title:t.path,children:t.name}),t.isDirty&&(0,r.jsx)("span",{"data-testid":"file-tab-dirty-".concat(t.path),className:"w-2 h-2 rounded-full bg-warning flex-shrink-0",title:o("fileTabs.unsavedChanges")}),(0,r.jsx)("button",{type:"button",onClick:u,className:"ml-1 p-0.5 rounded-sm hover:bg-muted transition-colors","aria-label":o("fileTabs.closeTab",{name:t.name}),children:(0,r.jsx)(eG.A,{className:"w-3 h-3"})})]})}),dn=(0,i.memo)(function(e){var t,n,a;let{tabs:s,activeIndex:l,worktreeId:o,onClose:u,onActivate:m,onLoadContent:h,onLoadError:f,onSetLoading:x,onFileSaved:p,onDirtyChange:g,onMoveToFront:b,onOpenFile:v}=e,y=(0,c.c)("worktree"),[j,w]=(0,i.useState)(!1),k=(0,i.useRef)(null),N=(0,i.useRef)(null),C=(0,i.useRef)({x:0,y:0}),[S,T]=(0,i.useState)({x:0,y:0}),{menuState:I,openMenu:E,openMenuAt:A,closeMenu:M}=sh(),[L,R]=(0,i.useState)(null),P=null!==l&&l>=0&&l<s.length?s[l]:null,D=s.length>5?s.slice(0,5):s,F=s.length>5?s.slice(5):[];(0,i.useEffect)(()=>{if(!j)return;let e=e=>{k.current&&!k.current.contains(e.target)&&w(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[j]),(0,i.useLayoutEffect)(()=>{let e=e=>{C.current=e,T(t=>t.x===e.x&&t.y===e.y?t:e)};if(!j)return void e({x:0,y:0});let t=N.current;if(!t)return;let n=t.getBoundingClientRect();e({x:de(n.left-C.current.x,n.width,window.innerWidth),y:de(n.top-C.current.y,n.height,window.innerHeight)})},[j]);let O=(0,i.useCallback)(e=>{w(!1),null==b||b(e)},[b]),z=(0,i.useCallback)(()=>{w(e=>!e)},[]),_=(0,i.useCallback)(e=>{for(let t=e.length-1;t>=0;t--)u(e[t])},[u]),B=(0,i.useCallback)((e,t)=>{let n=c9(s,t,e);if(0===n.length)return;let a=new Set(n);if(s.some(e=>e.isDirty&&a.has(e.path)))return void R({mode:e,anchorPath:t});_(n)},[s,_]),H=I.targetPath,V=(0,i.useMemo)(()=>H?[{id:"close-all-tabs",label:y("fileTabs.closeAll"),icon:(0,r.jsx)(cF.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onSelect:()=>B("all",H),disabled:0===s.length},{id:"close-other-tabs",label:y("fileTabs.closeOthers"),icon:(0,r.jsx)(cO.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onSelect:()=>B("others",H),disabled:0===c9(s,H,"others").length},{id:"close-tabs-to-right",label:y("fileTabs.closeToRight"),icon:(0,r.jsx)(cz.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onSelect:()=>B("right",H),disabled:0===c9(s,H,"right").length}]:[],[H,s,B,y]),U=(0,i.useCallback)((e,t)=>{E(e,t,"file")},[E]),W=null!=(a=null!=(n=null==P?void 0:P.path)?n:null==(t=s[0])?void 0:t.path)?a:null,$=(0,i.useCallback)(e=>{if(!W)return;let t=e.currentTarget.getBoundingClientRect();A({x:t.left,y:t.bottom},W,"file")},[W,A]),q=L?c9(s,L.anchorPath,L.mode):[],G=q.filter(e=>{var t;return null==(t=s.find(t=>t.path===e))?void 0:t.isDirty}),J=(0,i.useCallback)(()=>R(null),[]);return(0,r.jsxs)("div",{className:"flex flex-col h-full",children:[(0,r.jsxs)("div",{className:"flex border-b border-border bg-surface dark:bg-surface-2 min-w-0",children:[(0,r.jsx)("div",{className:"flex min-w-0 overflow-hidden flex-1",children:D.map((e,t)=>(0,r.jsx)(dt,{tab:e,isActive:t===l,onActivate:m,onClose:u,onOpenMenu:U},e.path))}),F.length>0&&(0,r.jsxs)("div",{className:"relative flex-shrink-0",ref:k,children:[(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-button",onClick:z,className:"flex items-center gap-0.5 px-2 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-muted border-b-2 border-transparent transition-colors",children:[(0,r.jsx)(K.A,{className:"w-3 h-3 transition-transform ".concat(j?"rotate-180":"")}),(0,r.jsxs)("span",{children:["+",F.length]})]}),j&&(0,r.jsx)("div",{ref:N,"data-testid":"tab-dropdown-menu",className:"absolute right-0 top-full mt-1 bg-surface border border-border rounded-md shadow-lg z-50 min-w-[200px] max-h-[300px] overflow-y-auto",style:0!==S.x||0!==S.y?{transform:"translate(".concat(S.x,"px, ").concat(S.y,"px)")}:void 0,children:F.map(e=>(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-item-".concat(e.path),onClick:()=>O(e.path),className:"w-full text-left px-3 py-2 text-sm text-foreground hover:bg-muted truncate",title:e.path,children:[e.name,e.isDirty&&(0,r.jsx)("span",{className:"ml-1 w-2 h-2 inline-block rounded-full bg-warning"})]},e.path))})]}),s.length>0&&(0,r.jsx)("button",{type:"button","data-testid":"tab-actions-button",onClick:$,"aria-haspopup":"menu","aria-expanded":I.isOpen,"aria-label":y("fileTabs.tabActions"),title:y("fileTabs.tabActions"),className:"flex-shrink-0 flex items-center px-2 py-2 text-muted-foreground hover:text-foreground hover:bg-muted border-b-2 border-transparent transition-colors",children:(0,r.jsx)(d.A,{className:"w-4 h-4"})})]}),(0,r.jsx)(sw,{isOpen:I.isOpen,position:I.position,targetPath:I.targetPath,targetType:I.targetType,onClose:M,items:V,ariaLabel:y("fileTabs.tabActions")}),(0,r.jsxs)(tN.a,{isOpen:null!==L,onClose:J,title:y("fileTabs.confirmCloseTitle"),size:"sm",children:[(0,r.jsx)("p",{"data-testid":"file-tabs-close-confirm-body",className:"text-sm text-foreground",children:y("fileTabs.confirmCloseBody",{count:G.length})}),(0,r.jsx)("ul",{className:"mt-2 max-h-32 overflow-y-auto text-sm text-muted-foreground",children:G.map(e=>(0,r.jsx)("li",{className:"truncate",title:e,children:e},e))}),(0,r.jsxs)("div",{className:"mt-4 flex flex-wrap justify-end gap-2",children:[(0,r.jsx)(tf.$,{variant:"ghost",size:"sm","data-testid":"file-tabs-close-cancel",onClick:J,children:y("fileTabs.confirmCancel")}),(0,r.jsx)(tf.$,{variant:"secondary",size:"sm","data-testid":"file-tabs-close-keep-unsaved",onClick:()=>{let e=new Set(G);_(q.filter(t=>!e.has(t))),R(null)},children:y("fileTabs.confirmKeepUnsaved")}),(0,r.jsx)(tf.$,{variant:"danger",size:"sm","data-testid":"file-tabs-close-discard",onClick:()=>{_(q),R(null)},children:y("fileTabs.confirmDiscard")})]})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:P&&(0,r.jsx)(c4,{tab:P,worktreeId:o,onLoadContent:h,onLoadError:f,onSetLoading:x,onFileSaved:p,onDirtyChange:g,onOpenFile:v},P.path)})]})}),da=(0,i.memo)(function(e){let{line:t}=e,n="whitespace-pre font-mono text-xs leading-5";return t.startsWith("+")&&!t.startsWith("+++")?n+=" text-success-foreground bg-success-subtle":t.startsWith("-")&&!t.startsWith("---")?n+=" text-danger-foreground bg-danger-subtle":t.startsWith("@@")?n+=" text-info bg-info/10":t.startsWith("diff --git")||t.startsWith("index ")||t.startsWith("---")||t.startsWith("+++")?n+=" text-muted-foreground":n+=" text-foreground",(0,r.jsx)("div",{className:n,children:t})}),dr=(0,i.memo)(function(e){let{diff:t,filePath:n,onClose:a}=e,s=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"h-full flex flex-col bg-surface",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border bg-muted shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-accent-600 dark:text-accent-400 shrink-0",children:s("diffViewer.badge")}),(0,r.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:n})]}),(0,r.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground rounded shrink-0","aria-label":s("diffViewer.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-2",children:(0,r.jsx)("pre",{className:"text-xs",children:(0,r.jsx)("code",{children:t.split("\n").map((e,t)=>(0,r.jsx)(da,{line:e},t))})})})]})}),ds="commandmate.worktree.filePanelCollapsed",dl="worktree-file-panel",di=(0,i.createContext)({tabCount:0,hasDiff:!1}),dc="commandmate:filePanelStateChange";function dd(){let[e,t]=(0,i.useState)(!1),n=(0,i.useRef)(e);n.current=e,(0,i.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(ds);if("true"===e)return!0}catch(e){}return!1}())},[]),(0,i.useEffect)(()=>{let e=e=>{e.detail&&e.detail.collapsed!==n.current&&t(e.detail.collapsed)};return window.addEventListener(dc,e),()=>window.removeEventListener(dc,e)},[]);let a=(0,i.useCallback)(e=>{t(e);try{window.localStorage.setItem(ds,String(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(dc,{detail:{collapsed:e}}))}catch(e){}},[]);return{collapsed:e,toggle:(0,i.useCallback)(()=>{a(!n.current)},[a]),setCollapsed:a}}let du=(0,i.memo)(function(e){let{terminal:t,terminalHeader:n,fileTabs:a,worktreeId:s,onCloseTab:l,onActivateTab:o,onLoadContent:c,onLoadError:d,onSetLoading:u,onFileSaved:m,diffContent:h,diffFilePath:f,onCloseDiff:x,onDirtyChange:p,onMoveToFront:g,onOpenFile:b}=e,v=(0,i.useRef)(null),[y,j]=(0,i.useState)(50),{collapsed:w}=dd(),k=(0,i.useCallback)(e=>{let t=v.current;if(!t)return;let n=t.offsetWidth;if(0===n)return;let a=e/n*100;j(e=>Math.min(80,Math.max(20,e+a)))},[]),N=(0,i.useMemo)(()=>({width:"".concat(y,"%")}),[y]),C=(0,i.useMemo)(()=>({width:"".concat(100-y,"%")}),[y]),S=(0,i.useMemo)(()=>({tabCount:a.tabs.length,hasDiff:!!(h&&f)}),[a.tabs.length,h,f]),T=(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[n,(0,r.jsx)("div",{className:"flex-1 min-h-0",children:t})]});return a.tabs.length>0||h&&f?w?(0,r.jsx)(di.Provider,{value:S,children:(0,r.jsx)("div",{ref:v,className:"flex h-full min-h-0",children:(0,r.jsx)("div",{"data-testid":"terminal-pane",style:{width:"100%"},className:"flex-shrink-0 overflow-hidden",children:T})})}):(0,r.jsx)(di.Provider,{value:S,children:(0,r.jsxs)("div",{ref:v,className:"flex h-full min-h-0",children:[(0,r.jsx)("div",{"data-testid":"terminal-pane",style:N,className:"flex-shrink-0 overflow-hidden",children:T}),(0,r.jsx)(st.f,{onResize:k,orientation:"horizontal",ariaValueNow:y}),(0,r.jsx)("div",{id:dl,"data-testid":"file-panel-pane",style:C,className:"flex-grow overflow-hidden flex",children:(0,r.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:h&&f&&x?(0,r.jsx)(dr,{diff:h,filePath:f,onClose:x}):(0,r.jsx)(dn,{tabs:a.tabs,activeIndex:a.activeIndex,worktreeId:s,onClose:l,onActivate:o,onLoadContent:c,onLoadError:d,onSetLoading:u,onFileSaved:m,onDirtyChange:p,onMoveToFront:g,onOpenFile:b})})})]})}):(0,r.jsx)(di.Provider,{value:S,children:(0,r.jsx)("div",{className:"h-full",children:T})})});var dm=n(7125),dh=n(22509),df=n(54485),dx=n(70198);let dp=[.5,.5],dg={splits:[{cliToolId:"claude",instanceId:"claude"}],widths:[1]},db=new Set(q.XH);function dv(e){return"".concat("commandmate:terminalSplits:").concat(e)}function dy(e){return"object"==typeof e&&null!==e}function dj(e){return"number"==typeof e&&Number.isFinite(e)&&e>0}function dw(e){return void 0===e||!!Array.isArray(e)&&2===e.length&&e.every(dj)}function dk(e,t){let n=e+t;if(!Number.isFinite(n)||n<=0)return[1,1];let a=Math.min(e,t);return!Number.isFinite(a)||a<=0?[1,1]:[e/a,t/a]}function dN(e){let t=e[0];return t?{splits:[{cliToolId:t.cliTool,instanceId:t.id}],widths:[1]}:{splits:dg.splits.map(e=>({...e})),widths:[...dg.widths]}}function dC(e){let t=e.reduce((e,t)=>e+t,0);return t>0?e.map(e=>e/t):e.map(()=>1/e.length)}function dS(e){if(4===e.splits.length)return dw(e.rowHeights)&&void 0!==e.rowHeights?e:{...e,rowHeights:[...dp]};if(void 0===e.rowHeights)return e;let{rowHeights:t,...n}=e;return n}function dT(e,t){let n;if(0===t.length)return e;let a=new Map(t.map(e=>[e.id,e.cliTool])),r=new Set,s=Math.min(Math.max(e.splits.length,1),t.length,4),l=[];for(let t of e.splits){if(l.length>=s)break;let e=a.get(t.instanceId);e&&!r.has(t.instanceId)&&(r.add(t.instanceId),l.push({cliToolId:e,instanceId:t.instanceId}))}for(let e of t){if(l.length>=s)break;r.has(e.id)||(r.add(e.id),l.push({cliToolId:e.cliTool,instanceId:e.id}))}return(0===l.length&&l.push({cliToolId:t[0].cliTool,instanceId:t[0].id}),l.length===e.splits.length&&l.every((t,n)=>t.instanceId===e.splits[n].instanceId&&t.cliToolId===e.splits[n].cliToolId))?e:(n=l.length===e.widths.length?dC(e.widths):l.length<e.widths.length?dC(e.widths.slice(0,l.length)):Array.from({length:l.length},()=>1/l.length),dS({...e,splits:l,widths:n}))}function dI(e,t,n){let a=function(e,t){try{let n=window.localStorage.getItem(dv(e));if(!n)return dN(t);let a=JSON.parse(n),r=function(e){if(!dy(e))return null;let{splits:t,widths:n,rowHeights:a}=e;if(!Array.isArray(t)||!Array.isArray(n)||t.length<1||t.length>4||n.length!==t.length)return null;let r=[];for(let e of t){if(!dy(e))return null;let t=e.cliToolId;if("string"!=typeof t||!db.has(t))return null;let n=e.instanceId,a="string"==typeof n&&(0,q.n6)(n)?n:t;r.push({cliToolId:t,instanceId:a})}for(let e of n)if(!dj(e))return null;let s={splits:r,widths:n};return 4===r.length&&void 0!==a&&dw(a)&&(s.rowHeights=[...a]),s}(a);if(r)return dS({...r,widths:dC(r.widths)});return console.warn("[useTerminalSplits] stale state for ".concat(e,"; falling back to default")),dN(t)}catch(n){return console.warn("[useTerminalSplits] failed to parse stored state for ".concat(e,"; using default"),n),dN(t)}}(e,t);return n?dT(a,t):a}let dE="commandmate:surfaceModeChange",dA=(0,i.memo)(function(e){var t,n,a,s;let{worktreeId:l,instances:o,rosterReady:d=!0,renderPane:u,onFocusedSplitChange:m,showToast:h,onActiveInstanceChange:f,headerInstanceSelection:x}=e,{splits:p,widths:g,rowHeights:b,setRowHeights:v,addSplit:y,removeSplit:j,setSplitInstance:w,setSplitWidth:k,resetWidths:N,availableInstanceIds:C,focusedSplitIndex:S,setFocusedSplitIndex:T,maximizedIndex:I,toggleMaximize:E}=function(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2],[a,r]=(0,i.useState)(()=>dI(e,t,n)),[s,l]=(0,i.useState)(0),[o,c]=(0,i.useState)(null),d=(0,i.useRef)(a);d.current=a;let u=(0,i.useRef)(t);u.current=t;let m=(0,i.useRef)(n);m.current=n;let h=(0,i.useRef)(e);(0,i.useEffect)(()=>{h.current!==e&&(h.current=e,r(dI(e,u.current,m.current)),l(0),c(null))},[e]);let f=(0,i.useMemo)(()=>t.map(e=>"".concat(e.id,":").concat(e.cliTool)).join("|"),[t]);(0,i.useEffect)(()=>{n&&r(e=>dT(e,u.current))},[f,n]);let x=(0,i.useRef)(e);(0,i.useEffect)(()=>{if(x.current!==e){x.current=e;return}try{window.localStorage.setItem(dv(e),JSON.stringify(a))}catch(e){}},[a,e]);let p=(0,i.useCallback)(()=>{c(null),r(e=>{if(e.splits.length>=4)return e;let t=new Set(e.splits.map(e=>e.instanceId)),n=function(e,t){for(let n of e)if(!t.has(n.id))return n;return null}(u.current,t);if(!n)return e;let a=[...e.splits,{cliToolId:n.cliTool,instanceId:n.id}];if(4===a.length)return dS({...e,splits:a,widths:Array.from({length:4},()=>.25)});let r=e.widths.length-1,s=e.widths[r]/2,l=[...e.widths];return l[r]=s,l.push(s),dS({...e,splits:a,widths:l})})},[]),g=(0,i.useCallback)(()=>{c(null),r(e=>{if(e.splits.length<=1)return e;let t=e.splits.slice(0,-1),n=dC(e.widths.slice(0,-1));return dS({...e,splits:t,widths:n})})},[]);(0,i.useEffect)(()=>{l(e=>{let t=a.splits.length-1;return e>t?t:e<0?0:e}),c(e=>null!==e&&e>a.splits.length-1?null:e)},[a.splits.length]);let b=(0,i.useCallback)((e,t)=>{let n=d.current,a=u.current;if(e<0||e>=n.splits.length)return!1;let s=a.find(e=>e.id===t);if(!s||n.splits[e].instanceId===t)return!1;for(let a=0;a<n.splits.length;a++)if(a!==e&&n.splits[a].instanceId===t)return!1;return r(n=>{if(e<0||e>=n.splits.length||n.splits[e].instanceId===t)return n;for(let a=0;a<n.splits.length;a++)if(a!==e&&n.splits[a].instanceId===t)return n;let a=n.splits.map((n,a)=>a===e?{cliToolId:s.cliTool,instanceId:t}:n);return{...n,splits:a}}),!0},[]),v=(0,i.useCallback)(e=>{r(t=>e.length!==t.widths.length||!function(e){if(!Array.isArray(e))return!1;for(let t of e)if("number"!=typeof t||!Number.isFinite(t)||t<=0)return!1;return!0}(e)?t:{...t,widths:[...e]})},[]),y=(0,i.useCallback)(()=>{c(null),r(e=>{let t=e.splits.length;if(0===t)return e;let n=Array.from({length:t},()=>1/t);return 4===t?{...e,widths:n,rowHeights:[...dp]}:dS({...e,widths:n})})},[]),j=(0,i.useCallback)(e=>{r(t=>4!==t.splits.length?t:Array.isArray(e)&&2===e.length&&dw(e)?{...t,rowHeights:[...e]}:t)},[]),w=(0,i.useCallback)(e=>{let n=new Set;for(let t=0;t<a.splits.length;t++)t!==e&&n.add(a.splits[t].instanceId);return t.filter(e=>!n.has(e.id)).map(e=>e.id)},[a.splits,t]),k=(0,i.useCallback)(e=>{l(e)},[]),N=(0,i.useMemo)(()=>{var e;return(e=a.rowHeights)&&dw(e)?[...e]:[...dp]},[a.rowHeights]),C=(0,i.useCallback)(e=>{e<0||e>=d.current.splits.length||c(t=>t===e?null:e)},[]);return{splits:a.splits,widths:a.widths,rowHeights:N,setRowHeights:j,addSplit:p,removeSplit:g,setSplitInstance:b,setSplitWidth:v,resetWidths:y,availableInstanceIds:w,focusedSplitIndex:s,setFocusedSplitIndex:k,maximizedIndex:o,toggleMaximize:C}}(l,o,d),A=(0,i.useMemo)(()=>{let e=new Map;for(let t of o)e.set(t.id,t);return e},[o]),M=(0,c.c)("worktree"),{visible:L,toggle:R,setWidth:P}=r0(),{collapsed:D,toggle:F}=dd(),O=!D,z=(0,i.useRef)(null),[_,B]=(0,i.useState)(!1),H=(0,i.useRef)(p.length),[V,U]=(0,i.useState)(null);(0,i.useEffect)(()=>{p.length>H.current&&U(p.length-1),H.current=p.length},[p.length]),(0,i.useEffect)(()=>{null==m||m(S)},[S,m]);let K=(0,i.useRef)(0),J=(0,i.useRef)(p);J.current=p,(0,i.useEffect)(()=>{if(!x||x.token===K.current)return;K.current=x.token;let{instanceId:e}=x,t=J.current.findIndex(t=>t.instanceId===e);if(0!==t){if(t>0)return void T(t);w(0,e)&&T(0)}},[x,w,T]),(0,i.useEffect)(()=>{if(null===V)return;let e=z.current;if(!e)return;let t=e.querySelector('[data-split-index="'.concat(V,'"]'));if(!t)return;let n=t.querySelector("textarea");null==n||n.focus(),T(V),U(null)},[V,T]);let Q=(0,i.useCallback)((e,t)=>{let n=z.current;if(!n)return;let a=n.offsetWidth;if(0===a)return;let r=g.reduce((e,t)=>e+t,0),s=t/a*r,l=[...g],i=l[e]+s,o=l[e+1]-s,c=.05*r;i<c||o<c||(l[e]=i,l[e+1]=o,k(l))},[g,k]),X=dk(null!=(t=g[0])?t:1,null!=(n=g[1])?n:1),Z=dk(null!=(a=b[0])?a:1,null!=(s=b[1])?s:1),ee=(0,i.useCallback)((e,t)=>{let n=z.current;if(!n)return;let a=n.offsetWidth;if(0===a)return;let r=g[0]+g[1];if(!(r>0))return;let s=t/a*r,l=g[0]+s,i=g[1]-s,o=.05*r;l<o||i<o||k([l,i,l,i])},[g,k]),et=(0,i.useCallback)((e,t)=>{let n=z.current;if(!n)return;let a=n.offsetHeight;if(0===a)return;let r=b[0]+b[1];if(!(r>0))return;let s=t/a*r,l=b[0]+s,i=b[1]-s,o=.05*r;l<o||i<o||v([l,i])},[b,v]),en=(0,i.useCallback)(()=>B(!0),[]),ea=(0,i.useCallback)(()=>B(!1),[]),er=(0,i.useCallback)(()=>{N(),P(40)},[N,P]),es=p.length<4&&!_,el=p.length>1&&!_,ei=p.length>1||L,eo=null!==I,ec=p.length>1,ed=4===p.length,eu=(0,i.useCallback)(()=>{E(null!=I?I:S)},[E,I,S]),em=M(eo?"terminal.restoreSplits":"terminal.maximizeFocusedSplit"),eh="".concat(em," — ").concat(M("terminal.maximizeShortcutHint")),ef=function(e,t){let[n,a]=(0,i.useState)(()=>Array.from({length:t},()=>G.wf));return(0,i.useEffect)(()=>{a(Array.from({length:t},(t,n)=>(0,r_.Dq)((0,r_.$2)(e,n))))},[e,t]),(0,i.useEffect)(()=>{let t=t=>{let n=t.detail;if(!n||n.worktreeId!==e)return;let{splitIndex:r,mode:s}=n;a(e=>{if(r<0||r>=e.length||e[r]===s)return e;let t=[...e];return t[r]=s,t})};return window.addEventListener(dE,t),()=>window.removeEventListener(dE,t)},[e]),n}(l,p.length),ex=ef.length>0&&ef.every(e=>"chat"===e),{tabCount:ep,hasDiff:eg}=(0,i.useContext)(di),eb=0===ep&&!eg,ev=ex?M("terminal.historyChatOnlyHint"):"".concat(M(L?"terminal.hideHistory":"terminal.showHistory")," — ").concat(M("terminal.historyAllSplitsHint")),ey=M(eb?"terminal.filesEmptyHint":O?"terminal.hideFiles":"terminal.showFiles"),ej=(0,i.useMemo)(()=>p.map((e,t)=>r1(t)).join(" "),[p]),ew=(0,i.useMemo)(()=>p.map((e,t)=>()=>T(t)),[p,T]),ek=(0,i.useMemo)(()=>p.map((e,t)=>e=>w(t,e)),[p,w]),eN=(0,i.useMemo)(()=>p.map((e,t)=>()=>E(t)),[p,E]),eC=(0,i.useMemo)(()=>p.map((e,t)=>e=>{var n,a;let r=(0,q.sw)(null!=(a=A.get(e))?a:{cliTool:"claude",alias:e});if((null==(n=p[t])?void 0:n.instanceId)===e)return;let s=p.findIndex((n,a)=>a!==t&&n.instanceId===e);if(-1!==s){null==h||h("".concat(r," is already in use by split ").concat(s+1),"warning");return}w(t,e)&&(null==f||f(e),null==h||h("Moved ".concat(r," to Split ").concat(t+1),"success"))}),[p,w,h,f,A]);return(0,r.jsxs)("div",{role:"group","aria-label":"Terminal splits","data-testid":"terminal-split-container",className:"flex flex-col h-full min-h-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-surface border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{"data-testid":"split-count-label",className:"text-xs text-muted-foreground tabular-nums mr-1 truncate",children:eo?M("terminal.maximizedStatus",{split:(null!=I?I:0)+1}):"".concat(p.length," / ").concat(4," splits")}),(0,r.jsx)(Y.m_,{content:M("terminal.addSplit"),placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:y,disabled:!es,"aria-disabled":!es,"aria-label":M("terminal.addSplit"),"data-testid":"add-terminal-split",className:"flex items-center justify-center h-7 w-7 rounded text-muted-foreground hover:text-surface-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors",children:(0,r.jsx)(lz.A,{className:"w-4 h-4","aria-hidden":"true"})})}),(0,r.jsx)(Y.m_,{content:M("terminal.removeSplit"),placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:j,disabled:!el,"aria-disabled":!el,"aria-label":M("terminal.removeSplit"),"data-testid":"remove-terminal-split",className:"flex items-center justify-center h-7 w-7 rounded text-muted-foreground hover:text-surface-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors",children:(0,r.jsx)(dm.A,{className:"w-4 h-4","aria-hidden":"true"})})}),(0,r.jsx)(Y.m_,{content:M("terminal.equalizeWidthsHint"),placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:er,disabled:!ei,"aria-disabled":!ei,"aria-label":M("terminal.equalizeWidthsHint"),"data-testid":"equalize-split-widths",className:"flex items-center justify-center h-7 w-7 rounded text-muted-foreground hover:text-surface-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors",children:(0,r.jsx)(dh.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"})})}),(0,r.jsx)(Y.m_,{content:eh,placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:eu,disabled:!ec,"aria-disabled":!ec,"aria-pressed":eo,"aria-label":em,"data-testid":"toggle-maximize-split",className:"flex items-center justify-center h-7 w-7 rounded text-muted-foreground hover:text-surface-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-ring transition-colors",children:eo?(0,r.jsx)(W.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}):(0,r.jsx)($.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"})})}),(0,r.jsx)("div",{className:"ml-auto h-4 w-px bg-border","aria-hidden":"true"}),(0,r.jsx)(Y.m_,{content:ev,placement:"bottom",className:"flex-shrink-0",children:(0,r.jsxs)("button",{type:"button",onClick:R,disabled:ex,"aria-disabled":ex,"aria-pressed":L,"aria-expanded":L,"aria-controls":ej,"aria-label":M(L?"terminal.hideHistory":"terminal.showHistory"),"data-testid":"toggle-history-pane",className:"flex flex-shrink-0 items-center gap-1 whitespace-nowrap text-xs px-2 py-0.5 rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ".concat(L?"border-accent-300 dark:border-accent-700 bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300":"border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"),children:[(0,r.jsx)(df.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:M("terminal.historyLabel")})]})}),(0,r.jsx)(Y.m_,{content:ey,placement:"bottom",className:"flex-shrink-0",children:(0,r.jsxs)("button",{type:"button",onClick:F,disabled:eb,"aria-disabled":eb,"aria-pressed":O,"aria-expanded":O,"aria-controls":dl,"aria-label":M(O?"terminal.hideFiles":"terminal.showFiles"),"data-testid":"toggle-file-panel",className:"flex flex-shrink-0 items-center gap-1 whitespace-nowrap text-xs px-2 py-0.5 rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ".concat(O?"border-accent-300 dark:border-accent-700 bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300":"border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"),children:[(0,r.jsx)(dx.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:M("terminal.filesLabel")}),ep>0&&(0,r.jsx)("span",{"data-testid":"open-files-count",className:"ml-0.5 min-w-[1.25rem] px-1 rounded-full bg-muted text-[10px] leading-4 text-muted-foreground tabular-nums text-center",children:ep})]})})]}),(0,r.jsxs)("div",{ref:z,"data-testid":"terminal-split-layout","data-layout":ed?"grid":"row",className:ed?"grid flex-1 min-h-0 w-full overflow-y-auto":"flex flex-1 min-h-0 w-full",style:ed?{gridTemplateColumns:eo?"1fr":"".concat(X[0],"fr ").concat(4,"px ").concat(X[1],"fr"),gridTemplateRows:eo?"1fr":"minmax(".concat(280,"px, ").concat(Z[0],"fr) ").concat(4,"px minmax(").concat(280,"px, ").concat(Z[1],"fr)")}:void 0,children:[p.map((e,t)=>{var n;let a=t===p.length-1,s=null!==I&&I!==t,l=I===t;return(0,r.jsxs)(i.Fragment,{children:[(0,r.jsx)("div",{"data-testid":"split-wrapper-".concat(t),"data-hidden":s?"true":void 0,style:ed?{gridColumn:l||t%2==0?1:3,gridRow:l||t<2?1:3,minWidth:0,minHeight:0,...s?{display:"none"}:null}:{flexGrow:l?1:null!=(n=g[t])?n:1,flexShrink:1,flexBasis:0,minWidth:0,...s?{display:"none"}:null},className:"h-full",children:u({splitIndex:t,cliToolId:e.cliToolId,instanceId:e.instanceId,instance:A.get(e.instanceId),availableInstances:C(t).map(e=>A.get(e)).filter(e=>void 0!==e),onInstanceChange:ek[t],onFocus:ew[t],isFocused:S===t,onDropInstance:eC[t],isMaximized:l,onToggleMaximize:eN[t]})}),ed||a?null:(0,r.jsx)(dM,{resizerIdx:t,hidden:null!==I,ariaValueNow:g.length?g[t]/g.reduce((e,t)=>e+t,0)*100:50,onResize:Q,onStart:en,onEnd:ea,onDoubleClick:N})]},"split-".concat(t))}),ed?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(dM,{resizerIdx:0,testId:"split-grid-column-resizer",gridArea:{gridColumn:2,gridRow:"1 / span 3"},hidden:eo,ariaValueNow:g[0]/(g[0]+g[1])*100,onResize:ee,onStart:en,onEnd:ea,onDoubleClick:N}),(0,r.jsx)(dM,{resizerIdx:0,testId:"split-grid-row-resizer",orientation:"vertical",gridArea:{gridColumn:"1 / span 3",gridRow:2},hidden:eo,ariaValueNow:b[0]/(b[0]+b[1])*100,onResize:et,onStart:en,onEnd:ea,onDoubleClick:N})]}):null]})]})});function dM(e){let{resizerIdx:t,ariaValueNow:n,onResize:a,onStart:s,onEnd:l,onDoubleClick:o,hidden:c=!1,orientation:d="horizontal",testId:u,gridArea:m}=e,h=(0,i.useCallback)(e=>a(t,e),[t,a]);return(0,r.jsx)("div",{"data-testid":null!=u?u:"split-resizer-".concat(t),style:{...m,...c?{display:"none"}:null},onMouseDownCapture:s,onTouchStartCapture:s,onMouseUpCapture:l,onTouchEndCapture:l,children:(0,r.jsx)(st.f,{onResize:h,orientation:d,ariaValueNow:n,onDoubleClick:o})})}function dL(e){if(!e)return null;let t=e.decisionId;return"string"==typeof t&&""!==t?t:null}let dR="\n px-6 py-2 rounded-lg font-medium transition-all\n disabled:opacity-50 disabled:cursor-not-allowed\n focus:outline-none focus:ring-2 focus:ring-offset-2\n".trim(),dP="bg-accent-600 text-white hover:bg-accent-700 focus:ring-ring",dD="bg-surface border-2 border-input hover:bg-muted text-foreground focus:ring-ring";function dF(e){let{promptData:t,answering:n,onRespond:a,decisionId:s,onDismiss:l,labelId:o,cliToolName:d}=e,u=(0,c.c)("prompt"),[h,f]=(0,i.useState)(()=>{if("multiple_choice"===t.type){var e;let n=t.options.find(e=>e.isDefault);return null!=(e=null==n?void 0:n.number)?e:null}return null}),[x,p]=(0,i.useState)(""),[g,b]=(0,i.useState)(!1),v=(0,i.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===h))?e:null},[t,h]),y=(null==v?void 0:v.requiresTextInput)===!0,j=n||g,w=(0,i.useCallback)(async e=>{if(!j){b(!0);try{await a(e,s)}catch(e){}finally{b(!1)}}},[j,a,s]),k=(0,i.useCallback)(async()=>{if(!j&&null!==h){b(!0);try{let e=y&&x.trim()?x.trim():h.toString();await a(e,s)}catch(e){}finally{b(!1)}}},[j,a,s,h,y,x]),N=(0,i.useCallback)(async e=>{if(!j&&s){b(!0);try{await a(e,s)}catch(e){}finally{b(!1)}}},[j,a,s]);return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("h3",{id:o,className:"text-lg font-semibold text-warning-foreground flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xl","aria-hidden":"true",children:"?"}),d?u("confirmationFrom",{toolName:d}):u("confirmationFromClaude")]}),l&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:l,"aria-label":"close",className:"p-1 rounded hover:bg-warning-border/50 transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5 text-warning-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),I(t)&&t.instructionText&&(0,r.jsx)("div",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap text-sm text-muted-foreground bg-muted rounded p-2 border border-border",children:t.instructionText}),"multiple_choice"===t.type&&t.askUserQuestion&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ask-user-question-progress",children:t.askUserQuestion.questionCount>1?u("askUserQuestionProgress",{index:t.askUserQuestion.questionIndex+1,total:t.askUserQuestion.questionCount}):u("askUserQuestionSource")}),(0,r.jsx)("p",{className:"text-foreground leading-relaxed",children:I(t)?t.question:u("unclassifiedTitle")}),j&&(0,r.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-muted-foreground",role:"status","aria-live":"polite",children:[(0,r.jsx)(m.y$,{size:"sm",variant:"accent"}),(0,r.jsx)("span",{children:u("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(dH,{promptData:t,disabled:j,onYes:()=>w("yes"),onNo:()=>w("no")}),"multiple_choice"===t.type&&(0,r.jsx)(dV,{promptData:t,disabled:j,selectedOption:h,onSelectOption:f,textInputValue:x,onTextInputChange:p,showTextInput:y,onSubmit:k}),!I(t)&&(0,r.jsx)(dO,{promptData:t,decisionId:s,disabled:j,onRespond:N})]})}function dO(e){var t,n,a,s,l;let{promptData:i,decisionId:o,disabled:d,onRespond:u}=e,m=(0,c.c)("prompt"),h=o&&null!=(n=i.decisionOptions)?n:null,f=function(e){if(null===dL(e)||Array.isArray(e.decisionOptions)&&e.decisionOptions.length>0)return null;let t=e.askUserQuestion;if(!t||"string"!=typeof t.question||""===t.question||!Array.isArray(t.labels)||0===t.labels.length)return null;let n=t.labels.filter(e=>"string"==typeof e&&""!==e);if(n.length!==t.labels.length)return null;let a="number"==typeof t.questionCount?t.questionCount:1;return 1!==a?null:{question:t.question,labels:n,questionCount:a}}(i);return(0,r.jsxs)("div",{className:"space-y-2","data-testid":"unclassified-prompt-notice",children:[i.message&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:i.message}),i.askUserQuestion&&(0,r.jsxs)("div",{className:"space-y-1","data-testid":"unclassified-ask-user-question",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:i.askUserQuestion.question}),f?(0,r.jsx)(dB,{choices:f,disabled:d,onRespond:u}):(0,r.jsx)("ul",{className:"list-disc list-inside text-sm text-muted-foreground",children:i.askUserQuestion.labels.map(e=>(0,r.jsx)("li",{children:e},e))})]}),f?null:h&&h.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(dz,{toolName:null!=(a=i.toolName)?a:null,patterns:null!=(s=i.patterns)?s:null,allowAlwaysLabel:null!=(l=null==(t=h.find(e=>"always"===e.reply))?void 0:t.label)?l:null}),(0,r.jsx)(d_,{options:h,disabled:d,onRespond:u})]}):(0,r.jsx)("p",{className:"text-sm text-foreground",children:m("unclassifiedInstruction",{command:m("unclassifiedRespondCommand")})})]})}function dz(e){let{toolName:t,patterns:n,allowAlwaysLabel:a}=e,s=null!==n&&n.length>0;return t||s?(0,r.jsxs)("div",{className:"space-y-1","data-testid":"structured-decision-subject",children:[t&&(0,r.jsx)("p",{className:"text-sm font-medium text-foreground font-mono break-all","data-testid":"structured-decision-tool",children:t}),s&&(0,r.jsxs)("div",{className:"text-xs text-muted-foreground",children:[a&&(0,r.jsx)("span",{"data-testid":"structured-decision-patterns-label",children:a}),(0,r.jsx)("ul",{className:"mt-0.5 flex flex-wrap gap-1","data-testid":"structured-decision-patterns",children:n.map(e=>(0,r.jsx)("li",{className:"font-mono break-all bg-muted border border-border rounded px-1.5 py-0.5",children:e},e))})]})]}):null}function d_(e){let{options:t,disabled:n,onRespond:a}=e,s=(0,c.c)("prompt");return(0,r.jsx)("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":s("selectAnOption"),"data-testid":"structured-decision-actions",children:t.map(e=>(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",disabled:n,onClick:()=>a(String(e.number)),"data-testid":"structured-decision-option-".concat(e.number),className:"".concat(dR," ").concat(3===e.number?dD:dP),children:[e.number,". ",e.label]},e.number))})}function dB(e){let{choices:t,disabled:n,onRespond:a}=e,s=(0,c.c)("prompt"),l=(0,i.useId)(),[o,d]=(0,i.useState)(null),u=(0,i.useCallback)(e=>{let t=o===e,a=n?"opacity-50 cursor-not-allowed":"";return"".concat("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all"," ").concat(t?"bg-accent-50 dark:bg-accent-900/30 border-2 border-accent-500":"bg-surface border-2 border-border hover:border-input"," ").concat(a)},[o,n]);return(0,r.jsxs)("div",{className:"space-y-3","data-testid":"structured-question-actions",children:[(0,r.jsxs)("fieldset",{children:[(0,r.jsx)("legend",{className:"sr-only",children:s("selectAnOption")}),(0,r.jsx)(m.z6,{name:l,value:null!=o?String(o):"",onValueChange:e=>d(Number(e)),disabled:n,className:"flex flex-col gap-2",children:t.labels.map((e,t)=>(0,r.jsxs)("label",{className:u(t+1),children:[(0,r.jsx)(m.CU,{value:String(t+1),className:"mt-1"}),(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsxs)("span",{className:"font-medium",children:[t+1,". ",e]})})]},"".concat(t+1,"-").concat(e)))})]}),(0,r.jsx)("button",{type:"button","data-testid":"structured-question-submit",onClick:()=>{null!==o&&a(String(o))},disabled:n||null===o,className:"w-full ".concat(dR," ").concat(dP),children:s("submit")})]})}function dH(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),i="yes"===t.defaultOption,o="no"===t.defaultOption,d="".concat(dR," ").concat(dP," ").concat(i?"primary default highlighted":""),u="".concat(dR," ").concat(o?"bg-foreground text-background hover:bg-foreground/90 primary default highlighted":dD);return(0,r.jsxs)("div",{className:"flex items-center gap-3",role:"group","aria-label":l("yesNoGroupLabel"),children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:a,disabled:n,className:d,children:l("yes")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:s,disabled:n,className:u,children:l("no")})]})}function dV(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:o,showTextInput:d,onSubmit:u}=e,h=(0,i.useId)(),f=(0,c.c)("prompt"),x=(0,i.useCallback)(e=>{let t=a===e,r=n?"opacity-50 cursor-not-allowed":"";return"".concat("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all"," ").concat(t?"bg-accent-50 dark:bg-accent-900/30 border-2 border-accent-500":"bg-surface border-2 border-border hover:border-input"," ").concat(r)},[a,n]);return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("fieldset",{children:[(0,r.jsx)("legend",{className:"sr-only",children:f("selectAnOption")}),(0,r.jsx)(m.z6,{name:h,value:null!=a?String(a):"",onValueChange:e=>s(Number(e)),disabled:n,className:"flex flex-col gap-2",children:t.options.map(e=>(0,r.jsxs)("label",{className:x(e.number),children:[(0,r.jsx)(m.CU,{value:String(e.number),className:"mt-1","aria-describedby":e.isDefault?"default-".concat(e.number):void 0}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("span",{className:"font-medium",children:[e.number,". ",e.label]}),e.isDefault&&(0,r.jsx)("span",{id:"default-".concat(e.number),className:"ml-2 text-xs text-accent-600 dark:text-accent-400 bg-accent-100 dark:bg-accent-900/30 px-2 py-0.5 rounded",children:f("default")}),e.description&&(0,r.jsx)("p",{className:"mt-0.5 text-sm text-muted-foreground",children:e.description})]})]},e.number))})]}),d&&(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("label",{htmlFor:"text-input-".concat(h),className:"sr-only",children:f("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>o(e.target.value),disabled:n,placeholder:f("enterValuePlaceholder"),className:"w-full px-4 py-2 border-2 border-input dark:bg-muted dark:text-foreground rounded-lg focus:outline-none focus:border-accent-500 disabled:opacity-50"})]}),(0,r.jsx)("button",{type:"button",onClick:u,disabled:n||null===a,className:"w-full ".concat(dR," ").concat(dP),children:f("submit")})]})}let dU=(0,i.memo)(function(e){let t,{promptData:n,messageId:a,decisionId:s,visible:l,answering:o,onRespond:c,onDismiss:d,cliToolName:u}=e,{shouldRender:m,animationClass:h}=L({visible:l&&null!==n,duration:200}),f=(0,i.useId)();if(!m||!n)return null;let x=(t="opacity-100","animate-fade-in"===h?t="opacity-100 transform translate-y-0":"animate-fade-out"===h&&(t="opacity-0 transform translate-y-2"),"".concat("bg-warning-subtle border-2 border-warning-border rounded-lg p-4 shadow-lg transition-all duration-200 ease-in-out"," ").concat(h," ").concat(t));return(0,r.jsx)(E,{componentName:"PromptPanel",children:(0,r.jsx)("div",{"data-testid":"prompt-panel",role:"dialog","aria-labelledby":f,"aria-modal":"true",className:x,children:(0,r.jsx)(dF,{promptData:n,answering:o,onRespond:c,decisionId:s,onDismiss:d,labelId:f,cliToolName:u})})})});var dK=n(35619),dW=n(93141);let d$=(0,i.memo)(function(e){var t,n,a;let{worktreeId:s,cliToolId:l,instanceId:o,diff:d,disabled:u=!1}=e,h=(0,c.c)("worktree"),f=(0,m.SC)(),[x,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(null),[v,y]=(0,i.useState)(null),j=(null==d?void 0:d.revertedMessageId)!=null,w=(0,i.useMemo)(()=>{var e,t;return j?null!=(e=null==d?void 0:d.revertedFiles)?e:[]:null!=(t=null==d?void 0:d.files)?t:[]},[j,d]),k=(0,i.useCallback)(async e=>{b(null),p(e);try{let t=await fetch("/api/worktrees/".concat(s,"/opencode/diff"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,instanceId:null!=o?o:l})}),n=await t.json().catch(()=>({}));if(409===t.status&&"SESSION_BUSY"===n.code)return void b("busy");if(!t.ok)return void b("failed");!1===n.applied&&b("noop")}catch(e){b("failed")}finally{p(null)}},[s,l,o]),N=(0,i.useCallback)(async()=>{await f({title:h("opencodeDiff.revertConfirmTitle"),description:h("opencodeDiff.revertConfirmBody",{count:w.length}),confirmLabel:h("opencodeDiff.revertConfirmLabel"),variant:"danger"})&&await k("revert")},[f,h,w.length,k]),C=(0,i.useCallback)(async()=>{await f({title:h("opencodeDiff.unrevertConfirmTitle"),description:h("opencodeDiff.unrevertConfirmBody",{count:w.length}),confirmLabel:h("opencodeDiff.unrevertConfirmLabel")})&&await k("unrevert")},[f,h,w.length,k]);return"opencode"!==l?null:d&&(d.files.length>0||d.revertedFiles.length>0)?(0,r.jsxs)("div",{className:"border-t border-border bg-muted/30 px-3 py-2 text-xs","data-testid":"opencode-turn-diff-panel",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(dK.A,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:j?h("opencodeDiff.revertedTitle"):h("opencodeDiff.title")}),(0,r.jsx)("span",{className:"text-muted-foreground",children:j?h("opencodeDiff.revertedSubtitle",{count:w.length}):h("opencodeDiff.subtitle",{count:w.length})}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-1",children:[null!==x?(0,r.jsx)(m.y$,{size:"sm"}):null,j?(0,r.jsxs)(m.$n,{variant:"ghost",size:"sm",onClick:C,disabled:u||null!==x,children:[(0,r.jsx)(dW.A,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),h("opencodeDiff.unrevert")]}):(0,r.jsxs)(m.$n,{variant:"ghost",size:"sm",onClick:N,disabled:u||null!==x,children:[(0,r.jsx)(at.A,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),h("opencodeDiff.revert")]})]})]}),null!==g?(0,r.jsx)("p",{className:"mt-1 text-danger-foreground",role:"status",children:h("opencodeDiff.".concat(g))}):null,(0,r.jsx)("ul",{className:"mt-1 space-y-0.5",children:w.map((e,t)=>{var n,a;let s=null!=(n=e.file)?n:h("opencodeDiff.unnamedFile"),l=function(e){let t=[];return e.additions>0&&t.push("+".concat(e.additions)),e.deletions>0&&t.push("−".concat(e.deletions)),t.join(" ")}(e);return(0,r.jsxs)("li",{className:"flex items-center gap-2",children:[null!==e.patch&&null!==e.file?(0,r.jsx)("button",{type:"button",className:"truncate text-info underline-offset-2 hover:underline",onClick:()=>y(e),title:h("opencodeDiff.openDiff",{file:s}),children:s}):(0,r.jsx)("span",{className:"truncate text-muted-foreground",children:s}),null!==e.status?(0,r.jsx)("span",{className:"shrink-0 text-muted-foreground",children:h("opencodeDiff.status.".concat(e.status))}):null,""!==l?(0,r.jsx)("span",{className:"shrink-0 font-mono text-muted-foreground",children:l}):null]},"".concat(null!=(a=e.file)?a:"unnamed","-").concat(t))})}),(0,r.jsx)(m.Jh,{isOpen:null!==v,onClose:()=>y(null),title:null!=(t=null==v?void 0:v.file)?t:void 0,size:"xl",children:null!==v?(0,r.jsx)(dr,{diff:null!=(n=v.patch)?n:"",filePath:null!=(a=v.file)?a:"",onClose:()=>y(null)}):null})]}):null});var dq=n(91758);function dG(e){let{isOpen:t,onConfirm:n,onCancel:a,cliToolName:s}=e,l=(0,c.c)("autoYes"),o=(0,c.c)("common"),[d,u]=(0,i.useState)(36e5),[m,h]=(0,i.useState)(""),[f,x]=(0,i.useState)(null),[p,g]=(0,i.useState)(!1),b=(0,i.useRef)(null),v=e=>l(l0[e].replace("autoYes.",""));return(0,i.useEffect)(()=>{t&&(h(""),x(null),g(!1))},[t]),(0,i.useEffect)(()=>{if(!p)return;let e=e=>{b.current&&!b.current.contains(e.target)&&g(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[p]),(0,i.useEffect)(()=>{if(!m.trim())return void x(null);let e=l1(m.trim());if(e.valid)x(null);else{var t;x(null!=(t=e.error)?t:l("invalidRegexPattern"))}},[m,l]),(0,r.jsx)(tN.a,{isOpen:t,onClose:a,title:s?l("enableTitleWithTool",{toolName:s}):l("enableTitle"),size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"text-sm text-foreground",children:[(0,r.jsx)("p",{className:"font-medium mb-2",children:l("featureDescription")}),(0,r.jsxs)("ul",{className:"list-disc list-inside space-y-1",children:[(0,r.jsx)("li",{children:l("yesNoAutoResponse")}),(0,r.jsx)("li",{children:l("multipleChoiceAutoSelect")})]}),(0,r.jsx)("p",{className:"mt-1",children:l("autoDisableAfter",{duration:v(d)})}),s&&(0,r.jsx)("p",{className:"mt-2 text-muted-foreground",children:l("appliesOnlyToCurrent",{toolName:s})})]}),(0,r.jsxs)("div",{className:"text-sm text-foreground",children:[(0,r.jsx)("p",{className:"font-medium mb-2",children:l("duration")}),(0,r.jsx)("div",{className:"flex gap-2",children:lZ.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>u(e),className:"flex-1 py-2 px-3 text-sm font-medium rounded-md border-2 transition-colors ".concat(d===e?"border-accent-600 bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-400":"border-border bg-surface dark:bg-surface-2 text-foreground hover:border-muted-foreground"),style:{minHeight:"44px"},children:v(e)},e))})]}),(0,r.jsxs)("div",{className:"text-sm text-foreground",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,r.jsx)("label",{htmlFor:"stop-pattern-input",className:"font-medium",children:l("stopPatternLabel")}),(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsx)("button",{type:"button",onClick:()=>g(!p),className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-muted text-muted-foreground text-[10px] font-bold hover:bg-muted/80 focus:outline-none","aria-label":l("regexTipsLabel"),"data-testid":"regex-tips-button",children:"?"}),p&&(0,r.jsxs)("div",{className:"absolute left-0 top-6 z-50 w-72 rounded-md border border-border bg-surface p-3 shadow-lg text-xs text-foreground","data-testid":"regex-tips-tooltip",children:[(0,r.jsx)("p",{className:"font-medium mb-1.5",children:l("regexTipsTitle")}),(0,r.jsxs)("ul",{className:"space-y-1",children:[(0,r.jsxs)("li",{children:[(0,r.jsx)("code",{className:"bg-muted px-1 rounded",children:"\\bcat\\b"})," ",l("regexTipWordBoundary")]}),(0,r.jsxs)("li",{children:[(0,r.jsx)("code",{className:"bg-muted px-1 rounded",children:"error|fatal"})," ",l("regexTipOr")]}),(0,r.jsxs)("li",{children:[(0,r.jsx)("code",{className:"bg-muted px-1 rounded",children:"(?i)error"})," ",l("regexTipCaseNote")]})]})]})]})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-2",children:l("stopPatternDescription")}),(0,r.jsx)("input",{id:"stop-pattern-input",type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("stopPatternPlaceholder"),className:"w-full px-3 py-2 border rounded-md text-sm font-mono bg-surface dark:bg-surface-2 text-foreground ".concat(f?"border-danger focus:ring-danger focus:border-danger":"border-input focus:ring-ring focus:border-accent-500"," focus:outline-none focus:ring-1"),"data-testid":"stop-pattern-input"}),f&&(0,r.jsx)("p",{className:"mt-1 text-xs text-danger","data-testid":"stop-pattern-error",children:f})]}),(0,r.jsxs)("div",{className:"text-sm text-foreground",children:[(0,r.jsx)("p",{className:"font-medium mb-2",children:l("aboutRisks")}),(0,r.jsx)("p",{children:l("riskWarning")})]}),(0,r.jsx)("div",{className:"bg-warning-subtle border-l-4 border-warning p-3",children:(0,r.jsxs)("p",{className:"text-sm text-warning-foreground",children:[(0,r.jsx)("span",{className:"font-medium",children:l("disclaimer")}),l("disclaimerText")]})}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:o("cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>{n(d,m.trim()||void 0)},disabled:!!f,className:"px-4 py-2 text-sm font-medium rounded-md text-white ".concat(f?"bg-muted-foreground cursor-not-allowed":"bg-warning hover:bg-warning/90"),"data-testid":"confirm-button",children:l("agreeAndEnable")})]})]})})}let dJ=(0,i.memo)(function(e){let{enabled:t,expiresAt:n,onToggle:a,lastAutoResponse:s,cliToolName:l,inline:o=!1,showToolName:d=!0,onExpire:u}=e,m=(0,c.c)("autoYes"),[h,f]=(0,i.useState)(""),[x,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(!1),[v,y]=(0,i.useState)(!1),[j,w]=(0,i.useState)(!1);(0,i.useEffect)(()=>{if(!t||!n){f(""),w(!1);return}w(!1);let e=!1,a=()=>(f(l2(n)),n-Date.now()<=0&&!e&&(e=!0,w(!0),null==u||u(),!0));if(a())return;let r=setInterval(()=>{a()&&clearInterval(r)},1e3);return()=>clearInterval(r)},[t,n,u]),(0,i.useEffect)(()=>{if(!s)return;p('Auto responded: "'.concat(s,'"'));let e=setTimeout(()=>p(null),eM.I2);return()=>clearTimeout(e)},[s]);let k=t&&!j,N=(0,i.useCallback)(()=>{k?(b(!0),a({enabled:!1}).finally(()=>b(!1))):y(!0)},[k,a]),C=(0,i.useCallback)((e,t)=>{y(!1),b(!0),a({enabled:!0,duration:e,stopPattern:t}).finally(()=>b(!1))},[a]),S=(0,i.useCallback)(()=>{y(!1)},[]);return(0,r.jsxs)("div",{className:o?"flex items-center gap-2":"flex items-center gap-3 px-4 py-2 bg-surface-2 border-b border-border",children:[(0,r.jsx)(dq.d,{checked:k,onCheckedChange:N,disabled:g,"aria-label":m("toggleLabel")}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:m("label")}),d&&l&&(0,r.jsxs)("span",{className:"text-xs text-accent-600 dark:text-accent-400 font-medium","aria-label":m("targetLabel"),children:["(",(0,q.f_)(l,""),")"]}),k&&h&&(0,r.jsx)("span",{className:"text-sm text-muted-foreground","aria-label":m("timeRemaining"),children:h}),x&&(0,r.jsx)("span",{className:"text-sm text-success animate-pulse",children:x}),(0,r.jsx)(dG,{isOpen:v,onConfirm:C,onCancel:S,cliToolName:(0,q.f_)(l,"")})]})});function dY(e,t,n,a){let r={answer:e,cliTool:t};if(a&&a!==t&&(r.instanceId=a),n&&(r.promptType=n.type,"multiple_choice"===n.type)){let e=n.options.find(e=>e.isDefault);e&&(r.defaultOptionNumber=e.number),n.submitMode&&(r.submitMode=n.submitMode)}return r}let dQ=(0,i.memo)(function(e){var t,n,a,s,l,o;let{worktreeId:d,splitIndex:u,cliToolId:m,instanceId:h,instance:f,availableInstances:x,onInstanceChange:p,onFocus:g,disabled:b=!1,pendingInsertText:v,onInsertConsumed:y,onMessageSent:j,cliStatus:w="idle",autoYes:k,history:N,onDropInstance:C,draggedInstanceId:S,onRequestSessionEnd:T,agentModel:E,onAgentSessionChange:A,isMaximized:M=!1,onToggleMaximize:L}=e,R=null!=h?h:m,P=null!=(n=k.enabled)&&n,D=null!=(a=k.expiresAt)?a:null,F=null!=(s=k.lastAutoResponse)?s:null,O=k.onToggle,z=null!=(l=null==N?void 0:N.showArchived)&&l,_=null==N?void 0:N.onShowArchivedChange,B=null==N?void 0:N.historyDisplayLimit,H=null==N?void 0:N.onHistoryDisplayLimitChange,V=null!=(o=null==N?void 0:N.historyUserOnly)&&o,U=null==N?void 0:N.onHistoryUserOnlyChange,K=null==N?void 0:N.onInsertToMessage,W=null==N?void 0:N.onFilePathClick,$=null==N?void 0:N.showToast,J=(0,c.c)("worktree"),Q=(0,to.Ym)(),X=(0,i.useMemo)(()=>(0,r_.$2)(d,u),[d,u]),[Z,ee]=(0,i.useState)(G.wf);(0,i.useEffect)(()=>{ee((0,r_.TR)(X))},[X]);let et=(0,i.useCallback)(e=>{ee(e),(0,r_.If)(X,e);try{window.dispatchEvent(new CustomEvent(dE,{detail:{worktreeId:d,splitIndex:u,mode:e}}))}catch(e){}},[X,d,u]),en=(0,i.useRef)(Z);en.current=Z,(0,i.useEffect)(()=>{function e(e){if(!e.shiftKey||e.altKey||!e.metaKey&&!e.ctrlKey||"m"!==e.key.toLowerCase())return;let t=e.target instanceof Element?e.target:null,n=null==t?void 0:t.closest("[data-split-index]");if(n){if(Number(n.getAttribute("data-split-index"))!==u)return}else if(0!==u||(null==t?void 0:t.closest('input, textarea, select, [contenteditable="true"]')))return;e.preventDefault(),et("chat"===en.current?"terminal":"chat")}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u,et]);let ea=(0,i.useRef)(L);ea.current=L,(0,i.useEffect)(()=>{function e(e){if(!e.shiftKey||e.altKey||!e.metaKey&&!e.ctrlKey||"Enter"!==e.key)return;let t=e.target instanceof Element?e.target:null,n=null==t?void 0:t.closest("[data-split-index]");if(n){if(Number(n.getAttribute("data-split-index"))!==u)return}else if(0!==u||(null==t?void 0:t.closest('input, textarea, select, [contenteditable="true"]')))return;let a=ea.current;a&&(e.preventDefault(),a())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u]);let{terminal:es,prompt:ei,agentSession:eo,setAutoScroll:ec,setPromptAnswering:ed,clearPrompt:eu,refresh:em}=rT({worktreeId:d,cliToolId:m,instanceId:R,enabled:!b}),{messages:eh,isLoading:ef,refresh:ex}=rA({worktreeId:d,cliToolId:m,instanceId:R,limit:B,includeArchived:z,enabled:!b}),ep=(0,i.useCallback)((e,t)=>el.y.sendMessage(d,e,t),[d]),{messages:eg,sendOptimistic:eb,retry:ev,discard:ey}=rR({worktreeId:d,serverMessages:eh,sendFn:ep,onSent:ex}),{visible:ej,width:ew,toggle:ek,setWidth:eN}=r0(),eC=i.useRef(null),eS=(0,i.useCallback)(e=>{let t=eC.current;if(!t)return;let n=t.offsetWidth;0!==n&&eN(ew+e/n*100)},[ew,eN]),eT="opencode"===m||"copilot"===m,{compactTuiLayoutPadding:eI,preservePaintedPanelRows:eE}=(0,i.useMemo)(()=>t0(m),[m]),eM=(0,i.useCallback)(e=>ec(e),[ec]),eL=(0,i.useCallback)(e=>{em(),ex(),null==j||j(e)},[em,ex,j]),eR=(0,i.useCallback)(e=>{let t=ey(e);t&&(null==K||K(t))},[ey,K]),eP=(0,i.useCallback)(async(e,t)=>{ed(!0);try{let n=t?{decisionId:t,answer:e,cliTool:m,...R&&R!==m?{instanceId:R}:{}}:dY(e,m,I(ei.data)?ei.data:null,R),a=await fetch(t?"/api/worktrees/".concat(d,"/respond"):"/api/worktrees/".concat(d,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw Error("Failed to send prompt response: ".concat(a.status));eu(),await em()}catch(e){console.error("[TerminalSplitPaneContent] prompt response error:",e)}finally{ed(!1)}},[d,m,R,ei.data,ed,eu,em]),eD=(0,i.useCallback)(()=>{eu()},[eu]),eO="chat"===Z,ez=es.isSelectionListActive,e_=ez&&!eO,eB="running"===es.sessionStatus,eH=ei.visible&&!P,eV=dL(ei.data),eU=es.isUnclassifiedActive&&!ez&&!ei.visible&&!eO,eK=t8(es.composerText),eW=nl(m,es.realtimeSnippet||es.output),e$=(0,i.useMemo)(()=>({messages:eg,worktreeId:d,onFilePathClick:null!=W?W:()=>{},isLoading:ef,className:"h-full",showToast:$,onInsertToMessage:K,onRetryPending:ev,onDiscardPending:eR,showArchived:z,onShowArchivedChange:_,historyDisplayLimit:B,onHistoryDisplayLimitChange:H,historyUserOnly:V,onHistoryUserOnlyChange:U,splitIndex:u,cliToolId:m}),[eg,ev,eR,d,W,ef,$,K,z,_,B,H,V,U,u,m]),eq=(0,i.useMemo)(()=>(0,r.jsx)(su,{...e$,onCollapse:ek}),[e$,ek]),eJ=(0,i.useMemo)(()=>(0,r.jsx)(t2,{output:es.output,isActive:es.isRunning,attaching:es.attaching,isThinking:es.isThinking,autoScroll:es.autoScroll,onScrollChange:eM,disableAutoFollow:eT,compactTuiLayoutPadding:eI,preservePaintedPanelRows:eE}),[es.output,es.isRunning,es.attaching,es.isThinking,es.autoScroll,eM,eT,eI,eE]),eY=(0,i.useMemo)(()=>(0,r.jsx)("div",{"data-testid":"split-chat-slot-".concat(u),"aria-label":J("surfaceMode.chatSurfaceLabel"),className:"flex h-full min-h-0 w-full overflow-hidden bg-surface text-surface-foreground",children:(0,r.jsx)("div",{className:"min-w-0 min-h-0 flex-1 overflow-hidden",children:(0,r.jsx)(rg,{messages:e$.messages,worktreeId:d,cliToolId:m,instanceId:R,history:e$,live:{isRunning:es.isRunning,sessionStatus:es.sessionStatus,isThinking:es.isThinking,isPromptWaiting:ei.visible,promptData:ei.data,isSelectionListActive:es.isSelectionListActive,isPagerActive:es.isPagerActive,isDismissablePanelActive:es.isDismissablePanelActive,isUnclassifiedActive:es.isUnclassifiedActive},onSurfaceModeChange:et,frame:es.output,onKeysSent:em})})}),[e$,u,J,d,m,R,es.isRunning,es.sessionStatus,es.isThinking,es.isSelectionListActive,es.isPagerActive,es.isDismissablePanelActive,es.isUnclassifiedActive,es.output,em,ei.visible,ei.data,et]),eQ=(0,i.useMemo)(()=>(0,r.jsxs)("div",{ref:eC,"data-testid":"split-terminal-row-".concat(u),className:"flex h-full min-h-0 w-full",children:[ej?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:r1(u),"data-testid":"split-history-slot-".concat(u),"aria-label":"History pane",style:{width:"".concat(ew,"%")},className:"flex-shrink-0 overflow-hidden min-h-0",children:eq}),(0,r.jsx)(st.f,{onResize:eS,orientation:"horizontal",ariaValueNow:ew})]}):null,(0,r.jsx)("div",{"data-testid":"split-terminal-slot-".concat(u),style:ej?void 0:{width:"100%"},className:"flex-grow overflow-hidden min-w-0 min-h-0 relative",children:eJ})]}),[ej,ew,eq,eS,eJ,u]),eX=(0,i.useMemo)(()=>(0,r.jsxs)("div",{className:"space-y-2","data-testid":"split-footer-".concat(u),children:[e_?(0,r.jsx)(eF,{worktreeId:d,cliToolId:m,instanceId:R,onKeysSent:em,showPagerKeys:es.isPagerActive}):null,eU?(0,r.jsx)(t6,{worktreeId:d,cliToolId:m,instanceId:R,onKeysSent:em}):null,eK?(0,r.jsx)(t9,{worktreeId:d,cliToolId:m,instanceId:R,composerText:es.composerText,onActionSent:em}):null,eW?(0,r.jsx)(ni,{cliToolId:m,frame:es.realtimeSnippet||es.output}):null,eH?(0,r.jsx)(dU,{promptData:ei.data,messageId:ei.messageId,decisionId:eV,visible:ei.visible,answering:ei.answering,onRespond:eP,onDismiss:eD,cliToolName:(0,q.oo)(m)}):null,es.isRunning?(0,r.jsx)(ny,{worktreeId:d,cliToolId:m,instanceId:R,hasAgentSession:null!==eo.session,onKeysSent:em,collapsible:!0,layout:"desktop"}):null,(0,r.jsx)(d$,{worktreeId:d,cliToolId:m,instanceId:R,diff:eo.diff,disabled:!es.isRunning}),(0,r.jsx)(eA,{worktreeId:d,onMessageSent:eL,onOptimisticSend:eb,cliToolId:m,instanceId:R,isSessionRunning:es.isRunning,pendingInsertText:null!=v?v:null,onInsertConsumed:y,splitIndex:u,onFocus:g,isProcessing:eB,showToast:$,autoYesSlot:(0,r.jsx)(dJ,{enabled:P,expiresAt:null!=D?D:null,onToggle:O,lastAutoResponse:null!=F?F:null,cliToolName:m,inline:!0})})]}),[e_,eH,eU,eK,eW,es.realtimeSnippet,es.output,eo.session,es.composerText,es.isPagerActive,d,m,R,em,ei.data,ei.messageId,eV,ei.visible,ei.answering,eP,eD,eL,eb,es.isRunning,eB,v,y,u,g,P,D,F,O,$,eo.diff]),eZ=(0,q.sw)(null!=f?f:{cliTool:m}),e0=(0,i.useCallback)(()=>{null==T||T({cliToolId:m,instanceId:R,label:eZ})},[T,m,R,eZ]),e1=(0,i.useMemo)(()=>{if(!T||!es.isRunning)return null;let e=J("terminal.endSessionFor",{name:eZ});return(0,r.jsx)(Y.m_,{content:e,placement:"bottom",children:(0,r.jsx)("button",{type:"button",onClick:e0,"aria-label":e,"data-testid":"terminal-end-session-button-".concat(u),className:"flex items-center justify-center p-0.5 rounded text-muted-foreground hover:text-danger focus:text-danger hover:bg-danger/10 focus:outline-none focus-visible:ring-2 focus-visible:ring-danger/50 transition-colors",children:(0,r.jsx)(eG.A,{size:14,"aria-hidden":"true"})})})},[T,es.isRunning,J,eZ,e0,u]);(0,i.useEffect)(()=>{null==A||A(R,eo)},[A,R,eo]);let e2=cs(E,null,null==(t=eo.session)?void 0:t.agent),e5=co(eo.session,eo.context,J,Q),e4=cc(eo.session,eo.context,J,Q);return(0,r.jsx)(er,{worktreeId:d,splitIndex:u,cliToolId:m,instanceId:R,instance:f,availableInstances:x,onInstanceChange:p,headerExtras:e1,status:w,agentModel:e2,agentUsage:e5,agentUsageDetail:e4,onFocus:g,attaching:es.attaching,surfaceMode:Z,onSurfaceModeChange:et,isMaximized:M,onToggleMaximize:L,terminal:"chat"===Z?eY:eQ,footer:eX,onDropInstance:C,draggedInstanceId:S})}),dX=(0,i.memo)(function(e){var t;let{task:n,latestRun:a,latestRunGates:s,onOpen:l,className:o=""}=e,d=(0,c.c)("worktree"),[u,m]=(0,i.useState)(!1),h=(0,i.useRef)(null),f=(0,i.useId)(),x=function(e,t){var n;let a=(0,i.useRef)(null);return(null!==e&&t&&t.length>0&&(a.current={runId:e.id,gates:t}),t&&t.length>0)?t:null!==e&&(null==(n=a.current)?void 0:n.runId)===e.id?a.current.gates:null}(a,s),p=(0,i.useMemo)(()=>{let e=[n?d("verification.chip.taskReason",{title:n.title,status:d("task.status.".concat(n.status))}):d("verification.chip.noTask")];if(a){if(e.push(d("verification.chip.runReason",{verdict:d("verification.runStatus.".concat(a.status)),runId:a.id})),e.push(d("verification.runStatusGloss.".concat(a.status))),x&&x.length>0){let t=x.filter(e=>iL.includes(e.status));e.push(t.length>0?d("verification.chip.failingGates",{gates:t.map(e=>e.gateId).join(", ")}):d("verification.chip.gatesPassed",{count:x.length}))}}else e.push(d("verification.chip.noRun"));return e.push(d("verification.chip.openHint")),e},[n,a,x,d]),g=p.join(" \xb7 "),b=(0,i.useCallback)(()=>{m(!1),l()},[l]),v=(0,i.useCallback)(()=>{m(e=>!e)},[]);return(0,i.useEffect)(()=>{if(!u)return;let e=e=>{var t;null!=(t=h.current)&&t.contains(e.target)||m(!1)},t=e=>{"Escape"===e.key&&m(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[u]),(0,r.jsxs)("div",{ref:h,className:"relative inline-flex max-w-full ".concat(o).trim(),children:[(0,r.jsxs)("div",{className:"inline-flex min-w-0 max-w-full grow items-center gap-1 rounded-full border border-border bg-surface-2 pr-1 text-xs text-foreground",children:[(0,r.jsxs)("button",{type:"button",onClick:b,"data-testid":"verification-status-chip","aria-label":g,title:g,className:"inline-flex min-w-0 flex-1 items-center gap-1.5 rounded-full px-2 py-1 transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:[(0,r.jsx)(n7.A,{size:14,"aria-hidden":"true",className:"flex-shrink-0 text-muted-foreground"}),(0,r.jsx)("span",{className:"truncate font-medium","data-testid":"verification-chip-title",children:n?(t=n.title,t.length<=36?t:"".concat(t.slice(0,35),"…")):d("verification.title")}),n&&(0,r.jsx)(iT.E,{variant:iE[n.status],className:"flex-shrink-0 px-1.5 py-0","data-testid":"verification-chip-task-status",children:d("task.status.".concat(n.status))}),(0,r.jsx)(iT.E,{variant:a?iA[a.status]:"gray",className:"flex-shrink-0 px-1.5 py-0 font-mono","data-testid":"verification-chip-run-status",children:a?d("verification.chip.resultBadge",{verdict:d("verification.runStatus.".concat(a.status))}):d("verification.chip.unverified")})]}),(0,r.jsx)("button",{type:"button",onClick:v,"data-testid":"verification-chip-reason-toggle","aria-expanded":u,"aria-controls":f,"aria-label":d(u?"verification.chip.hideReason":"verification.chip.showReason"),className:"inline-flex min-h-[32px] min-w-[32px] flex-shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring touch-manipulation",children:(0,r.jsx)(k.A,{size:14,"aria-hidden":"true"})})]}),u&&(0,r.jsxs)("div",{id:f,role:"tooltip","data-testid":"verification-chip-reason-popover",className:"absolute left-0 top-full z-50 mt-1 w-72 max-w-[80vw] rounded-lg border border-border bg-surface p-3 text-xs leading-relaxed text-foreground shadow-lg",children:[(0,r.jsx)("p",{className:"mb-1 font-semibold",children:d("verification.chip.reasonHeading")}),(0,r.jsx)("ul",{className:"space-y-1",children:p.map(e=>(0,r.jsx)("li",{className:"break-words",children:e},e))})]})]})}),dZ=(0,i.memo)(function(e){let{isBranchMismatch:t,currentBranch:n,initialBranch:a}=e,s=(0,c.c)("worktree"),[l,o]=(0,i.useState)(!1);return((0,i.useEffect)(()=>{o(!1)},[n]),!t||l||null===a)?null:(0,r.jsxs)("div",{"data-testid":"branch-mismatch-alert",role:"alert",className:"flex items-center gap-3 px-4 py-2 bg-warning-subtle border border-warning-border text-warning-foreground rounded-lg",children:[(0,r.jsx)(lR.A,{className:"w-5 h-5 text-warning flex-shrink-0"}),(0,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsxs)("span",{className:"text-sm",children:[s("branchMismatch.changedFrom")," ",(0,r.jsx)("span",{className:"font-medium",children:a})," ",s("branchMismatch.to")," ",(0,r.jsx)("span",{className:"font-medium",children:n})]})}),(0,r.jsx)("button",{type:"button",onClick:()=>o(!0),className:"p-1 rounded hover:bg-warning-subtle transition-colors","aria-label":s("branchMismatch.dismiss"),children:(0,r.jsx)(eG.A,{className:"w-4 h-4"})})]})});var d0=n(58734);let d1=(0,i.memo)(function(e){let{isOpen:t,onClose:n,onConfirm:a,worktreeId:s,sourcePath:l,sourceType:o}=e,d=(0,c.c)("worktree"),u=(0,c.c)("common"),[h,f]=(0,i.useState)(""),[x,p]=(0,i.useState)(new Set([""])),[g,b]=(0,i.useState)([]),[v,y]=(0,i.useState)(!1),[w,k]=(0,i.useState)(new Set),N=l.includes("/")?l.substring(0,l.lastIndexOf("/")):"";(0,i.useEffect)(()=>{t&&(f(N),p(new Set([""])),b([]),C())},[t,s]);let C=(0,i.useCallback)(async()=>{y(!0);try{let e=await fetch("/api/worktrees/".concat(s,"/tree"));if(!e.ok)return;let t=(await e.json()).items.filter(e=>"directory"===e.type).map(e=>({name:e.name,path:e.name,loaded:!1}));b(t)}catch(e){}finally{y(!1)}},[s]),S=(0,i.useCallback)(async e=>{k(t=>new Set(t).add(e));try{let t=await fetch("/api/worktrees/".concat(s,"/tree/").concat(e));if(!t.ok)return;let n=(await t.json()).items.filter(e=>"directory"===e.type).map(t=>({name:t.name,path:"".concat(e,"/").concat(t.name),loaded:!1}));b(t=>(function e(t,n,a){return t.map(t=>t.path===n?{...t,children:a,loaded:!0}:t.children?{...t,children:e(t.children,n,a)}:t)})(t,e,n))}catch(e){}finally{k(t=>{let n=new Set(t);return n.delete(e),n})}},[s]),T=(0,i.useCallback)(async e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});let t=function e(t,n){for(let a of t){if(a.path===n)return a;if(a.children){let t=e(a.children,n);if(t)return t}}return null}(g,e);t&&!t.loaded&&await S(e)},[g,S]),I=(0,i.useCallback)(e=>!(e===N||"directory"===o&&(e===l||e.startsWith(l+"/")))&&!0,[N,l,o]),E=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=x.has(e.path),a=h===e.path,s=w.has(e.path),l=I(e.path);return(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 py-1.5 px-2 cursor-pointer rounded text-sm transition-colors ".concat(a?"bg-accent-100 text-accent-800":"hover:bg-muted text-foreground"," ").concat(l?"":"opacity-40 cursor-not-allowed"),style:{paddingLeft:"".concat(.5+1.25*t,"rem")},onClick:()=>{l&&f(e.path)},children:[(0,r.jsx)("button",{className:"w-4 h-4 flex items-center justify-center flex-shrink-0",onClick:t=>{t.stopPropagation(),T(e.path)},children:s?(0,r.jsx)(m.y$,{size:"xs",variant:"muted"}):(0,r.jsx)(n8.A,{className:"w-3 h-3 text-muted-foreground transition-transform ".concat(n?"rotate-90":"")})}),n?(0,r.jsx)(d0.A,{className:"w-4 h-4 text-warning flex-shrink-0"}):(0,r.jsx)(j.A,{className:"w-4 h-4 text-warning flex-shrink-0"}),(0,r.jsx)("span",{className:"truncate",children:e.name})]}),n&&e.children&&(0,r.jsx)("div",{children:e.children.map(e=>E(e,t+1))})]},e.path)},A=I(h);return(0,r.jsx)(tN.a,{isOpen:t,onClose:n,title:d("fileTree.moveDialogTitle"),size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:[d("fileTree.moveTo"),": ",(0,r.jsx)("span",{className:"font-mono text-foreground",children:l})]}),(0,r.jsxs)("div",{className:"border border-border rounded-lg max-h-64 overflow-y-auto p-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 py-1.5 px-2 cursor-pointer rounded text-sm transition-colors ".concat(""===h?"bg-accent-100 text-accent-800":"hover:bg-muted text-foreground"," ").concat(I("")?"":"opacity-40 cursor-not-allowed"),onClick:()=>{I("")&&f("")},children:[(0,r.jsx)("span",{className:"w-4 h-4"}),(0,r.jsx)(j.A,{className:"w-4 h-4 text-warning flex-shrink-0"}),(0,r.jsx)("span",{children:d("fileTree.rootDirectory")})]}),v?(0,r.jsx)("div",{className:"flex items-center justify-center py-4",children:(0,r.jsx)(m.y$,{size:"md",variant:"muted"})}):g.map(e=>E(e,1))]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)(m.$n,{variant:"ghost",onClick:n,className:"px-4 py-2 text-sm text-foreground bg-white border border-border rounded-md hover:bg-muted transition-colors",children:u("cancel")}),(0,r.jsx)(m.$n,{variant:"ghost",onClick:()=>a(h),disabled:!A,className:"px-4 py-2 text-sm text-white bg-accent-600 rounded-md hover:bg-accent-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:d("fileTree.moveConfirm")})]})]})})});function d2(e,t){let n=e.trim();return n?0>=n.lastIndexOf(".")?n+t:n:""}let d5=(0,i.memo)(function(e){let{isOpen:t,parentPath:n,onConfirm:a,onCancel:s}=e,l=(0,c.c)("worktree"),o=(0,c.c)("common"),[d,u]=(0,i.useState)(""),[m,h]=(0,i.useState)(".md"),f=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(t){u(""),h(".md");let e=setTimeout(()=>{var e;null==(e=f.current)||e.focus()},100);return()=>clearTimeout(e)}},[t]);let x=(0,i.useCallback)(()=>{let e=d2(d,m);e&&a(e)},[d,m,a]),p=(0,i.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),x())},[x]),g=d2(d,m),b=n?"".concat(n,"/").concat(g):g;return(0,r.jsx)(tN.a,{isOpen:t,onClose:s,title:l("newFileDialog.title"),size:"sm",children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"new-file-name",className:"block text-sm font-medium text-foreground mb-1",children:l("newFileDialog.fileNameLabel")}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)("input",{ref:f,id:"new-file-name","data-testid":"new-file-name-input",type:"text",value:d,onChange:e=>u(e.target.value),onKeyDown:p,placeholder:l("newFileDialog.placeholder"),className:"flex-1 px-3 py-2 border border-input rounded-lg bg-surface text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,r.jsx)("select",{"data-testid":"new-file-ext-select",value:m,onChange:e=>h(e.target.value),className:"px-3 py-2 border border-input rounded-lg bg-surface text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent",children:cV.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),g&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground font-mono bg-muted rounded px-2 py-1",children:b}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm font-medium text-foreground bg-muted hover:bg-muted/80 rounded-lg transition-colors",children:o("cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"new-file-confirm-button",onClick:x,disabled:!g,className:"px-4 py-2 text-sm font-medium text-white bg-accent-600 hover:bg-accent-700 disabled:opacity-50 disabled:cursor-not-allowed rounded-lg transition-colors",children:l("newFileDialog.create")})]})]})})}),d4=(0,i.memo)(function(e){var t,n,a,s,l;let{worktreeId:o,worktree:d,worktreeName:u,worktreeStatus:m,instances:h,rosterReady:f,activeInstanceId:x,setActiveInstanceId:p,hasUpdate:g,lastAutoResponse:b,activeActivity:v,onActivityToggle:y,onActivityOpen:j,verification:w,onBackClick:k,onInfoClick:N,onWorktreeStatusChange:C,pendingInsertTextMap:S,setFocusedSplitIndex:T,handleInsertToSplit:I,handleInsertConsumed:A,handleInsertToMessage:M,autoYesStateMap:L,makeAutoYesToggleHandler:R,showArchived:P,onShowArchivedChange:D,historyDisplayLimit:F,onHistoryDisplayLimitChange:O,historyUserOnly:z,onHistoryUserOnlyChange:_,onMessageSent:B,onFilePathClick:H,showToast:V,tabsState:U,tabsActions:K,onLoadContent:W,onLoadError:$,onSetLoading:q,onFilePanelSave:G,onDirtyChange:J,onOpenFile:Y,diffContent:Q,diffFilePath:X,onCloseDiff:Z,fileSearch:ee,fileTreeRefresh:et,onFileSelect:en,onNewFile:ea,onNewDirectory:er,onRename:es,onDelete:el,onUpload:ei,onMove:eo,onFileTreeReset:ec,onDiffSelect:ed,onAgentInstancesChange:eu,vibeLocalModel:em,onVibeLocalModelChange:eh,vibeLocalContextWindow:ef,onVibeLocalContextWindowChange:ex,isInfoModalOpen:ep,onInfoModalClose:eg,onWorktreeUpdate:eb,fileInputRef:ev,onFileInputChange:ey,onKillSession:ej,onRequestSessionEnd:ew,killTarget:ek,isKillPending:eN,onKillCancel:eC,onKillConfirm:eS,moveTarget:eT,isMoveDialogOpen:eI,onMoveCancel:eE,onMoveConfirm:eA,showNewFileDialog:eM,newFileParentPath:eL,onNewFileConfirm:eR,onNewFileCancel:eP,killDialogTitle:eD,killDialogWarning:eF,cancelLabel:eO,endLabel:ez}=e,e_=(0,c.c)("worktree"),[eB,eH]=i.useState(null),eV=(0,i.useCallback)(e=>eH(e),[]),eU=(0,i.useCallback)(()=>eH(null),[]),eK=(0,i.useMemo)(()=>cd(null==d?void 0:d.sessionStatusByInstance),[null==d?void 0:d.sessionStatusByInstance]),[eW,e$]=(0,i.useState)({}),eq=(0,i.useCallback)((e,t)=>{e$(n=>n[e]===t?n:{...n,[e]:t})},[]),[eG,eJ]=i.useState(null),eY=i.useRef(0),eQ=(0,i.useCallback)(e=>{p(e),eY.current+=1,eJ({instanceId:e,token:eY.current})},[p]),eX=(0,i.useCallback)(()=>{j("verification")},[j]),eZ=(0,i.useCallback)(e=>{var t,n,a,s,l,i,c,u,m,h;let{splitIndex:f,cliToolId:x,instanceId:g,instance:v,availableInstances:y,onInstanceChange:j,onFocus:w,onDropInstance:k,isMaximized:N,onToggleMaximize:C}=e,T=null!=(c=S.get(f))?c:null,E=L.get(g),M=null!=(u=null==E?void 0:E.enabled)&&u,U=null!=(m=null==E?void 0:E.expiresAt)?m:null,K=(0,tC.kA)(null!=(h=null==d||null==(t=d.sessionStatusByInstance)?void 0:t[g])?h:null==d||null==(n=d.sessionStatusByCli)?void 0:n[x]);return(0,r.jsx)(dQ,{worktreeId:o,splitIndex:f,cliToolId:x,instanceId:g,instance:v,availableInstances:y,onInstanceChange:e=>{j(e),0===f&&p(e)},onFocus:w,pendingInsertText:T,onInsertConsumed:()=>A(f),onMessageSent:B,cliStatus:K,onAgentSessionChange:eq,agentModel:cs(null==d||null==(s=d.sessionStatusByInstance)||null==(a=s[g])?void 0:a.model,null==d||null==(i=d.sessionStatusByInstance)||null==(l=i[g])?void 0:l.reasoningEffort),autoYes:{enabled:M,expiresAt:U,lastAutoResponse:b,onToggle:R(x,g)},history:{showArchived:P,onShowArchivedChange:D,historyDisplayLimit:F,onHistoryDisplayLimitChange:O,historyUserOnly:z,onHistoryUserOnlyChange:_,onInsertToMessage:e=>I(f,e),onFilePathClick:H,showToast:V},onDropInstance:k,draggedInstanceId:eB,isMaximized:N,onToggleMaximize:C,onRequestSessionEnd:ew})},[o,S,L,A,B,p,b,R,null==d?void 0:d.sessionStatusByCli,null==d?void 0:d.sessionStatusByInstance,H,V,I,P,D,F,O,z,_,eB,ew,eq]),e0=(0,i.useMemo)(()=>(0,r.jsx)(dA,{worktreeId:o,instances:h,rosterReady:f,renderPane:eZ,onFocusedSplitChange:T,showToast:V,onActiveInstanceChange:p,headerInstanceSelection:eG}),[o,h,f,eZ,T,V,p,eG]),e1=(0,i.useMemo)(()=>(0,r.jsx)(du,{terminal:e0,terminalHeader:null,fileTabs:U,worktreeId:o,onCloseTab:K.closeTab,onActivateTab:K.activateTab,onLoadContent:W,onLoadError:$,onSetLoading:q,onFileSaved:G,diffContent:Q,diffFilePath:X,onCloseDiff:Z,onDirtyChange:J,onMoveToFront:K.moveToFront,onOpenFile:Y}),[e0,U,o,K.closeTab,K.activateTab,W,$,q,G,Q,X,Z,J,K.moveToFront,Y]),e2=(0,i.useMemo)(()=>(0,r.jsx)(cL,{active:v,onToggle:y}),[v,y]),e5=(0,i.useMemo)(()=>{var e;return{files:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(sW,{query:ee.query,mode:ee.mode,isSearching:ee.isSearching,error:ee.error,onQueryChange:ee.setQuery,onModeChange:ee.setMode,onClear:ee.clearSearch}),(0,r.jsx)(sH,{worktreeId:o,onFileSelect:en,onNewFile:ea,onNewDirectory:er,onRename:es,onDelete:el,onUpload:ei,onMove:eo,onResetView:ec,refreshTrigger:et,pollingEnabled:"files"===v,searchQuery:ee.query,searchMode:ee.mode,searchResults:null==(e=ee.results)?void 0:e.results,className:"flex-1 min-h-0"})]}),git:(0,r.jsx)(ce,{worktreeId:o,onDiffSelect:ed,isMobile:!1,worktree:null!=d?d:void 0,onInsertToMessage:M,className:"h-full"}),notes:(0,r.jsx)(sX,{worktreeId:o,className:"h-full",onInsertToMessage:M}),schedules:(0,r.jsx)(lk,{worktreeId:o,className:"h-full",onInsertToMessage:M,instances:h}),agent:(0,r.jsx)(lG,{worktreeId:o,instances:h,onInstancesChange:eu,vibeLocalModel:em,onVibeLocalModelChange:eh,vibeLocalContextWindow:ef,onVibeLocalContextWindowChange:ex,modelByInstance:eK,className:"h-full"}),timer:(0,r.jsx)(l9,{worktreeId:o,instances:h}),todo:(0,r.jsx)(s5,{worktreeId:o,className:"h-full"}),skills:(0,r.jsx)(iC,{worktreeId:o,className:"h-full"}),verification:(0,r.jsx)(ot,{state:w,className:"h-full"}),env:(0,r.jsx)(oT,{worktreeId:o,className:"h-full"})}},[o,d,v,ee.query,ee.mode,ee.isSearching,ee.error,ee.setQuery,ee.setMode,ee.clearSearch,null==(t=ee.results)?void 0:t.results,en,ea,er,es,el,ei,eo,ec,et,ed,M,h,eu,em,eh,ef,ex,eK,w]),e4=(0,i.useMemo)(()=>null===v?null:(0,r.jsx)(cD,{active:v,activities:e5}),[v,e5]);return(0,r.jsx)(E,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"flex h-full overflow-hidden relative",children:[e2,(0,r.jsxs)("div",{className:"flex flex-col flex-1 min-h-0 min-w-0",children:[(0,r.jsx)(ch,{worktreeName:u,repositoryName:null!=(s=null!=(a=null==d?void 0:d.repositoryDisplayName)?a:null==d?void 0:d.repositoryName)?s:e_("detail.unknownRepository"),description:null==d?void 0:d.description,status:m,gitStatus:null==d?void 0:d.gitStatus,onBackClick:k,onInfoClick:N,hasUpdate:g,worktreeStatus:null!=(l=null==d?void 0:d.status)?l:null,onWorktreeStatusChange:C,sessionStatusByCli:null==d?void 0:d.sessionStatusByCli,sessionStatusByInstance:null==d?void 0:d.sessionStatusByInstance,instances:h,activeInstanceId:x,onActiveInstanceChange:eQ,onAgentDragStart:eV,onAgentDragEnd:eU,onKillSession:ej,agentSessionByInstance:eW,verificationChip:(0,r.jsx)(dX,{task:w.task,latestRun:w.latestRun,latestRunGates:null!==w.selectedRun&&w.selectedRun.id===(null==(n=w.latestRun)?void 0:n.id)?w.selectedRun.gates:null,onOpen:eX})}),(null==d?void 0:d.gitStatus)&&(0,r.jsx)(dZ,{isBranchMismatch:d.gitStatus.isBranchMismatch,currentBranch:d.gitStatus.currentBranch,initialBranch:d.gitStatus.initialBranch}),(0,r.jsx)("div",{className:"flex-1 min-h-0 min-w-0",children:(0,r.jsx)(cg,{activityPane:e4,rightPane:(0,r.jsx)(sa,{terminal:e1})})})]}),(0,r.jsx)(cf,{worktreeId:o,worktree:d,isOpen:ep,onClose:eg,onWorktreeUpdate:eb}),(0,r.jsx)("input",{ref:ev,type:"file",accept:cH.join(","),onChange:ey,className:"hidden","aria-label":e_("detail.uploadFile")}),(0,r.jsx)(tN.a,{isOpen:null!==ek,onClose:eC,title:eD,size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:eF}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:eC,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:eO}),(0,r.jsx)("button",{type:"button",onClick:eS,disabled:eN,"data-testid":"kill-session-confirm-button",className:"px-4 py-2 text-sm font-medium rounded-md bg-danger hover:bg-danger/90 text-white disabled:opacity-60 disabled:cursor-not-allowed",children:ez})]})]})}),eT&&(0,r.jsx)(d1,{isOpen:eI,onClose:eE,onConfirm:eA,worktreeId:o,sourcePath:eT.path,sourceType:eT.type}),(0,r.jsx)(d5,{isOpen:eM,parentPath:eL,onConfirm:eR,onCancel:eP})]})})});q.oo;var d3=n(51434);function d6(e,t){switch(t.type){case"SET_PHASE":return{...e,phase:t.phase};case"SHOW_PROMPT":return{...e,phase:"prompt",prompt:{data:t.data,messageId:t.messageId,visible:!0,answering:!1}};case"CLEAR_PROMPT":return{...e,prompt:{...G.kQ}};case"SET_PROMPT_ANSWERING":return{...e,prompt:{...e.prompt,answering:t.answering}};case"SET_LAYOUT_MODE":return{...e,layout:{...e.layout,mode:t.mode}};case"SET_MOBILE_ACTIVE_PANE":return{...e,layout:{...e.layout,mobileActivePane:t.pane}};case"SET_SPLIT_RATIO":return{...e,layout:{...e.layout,splitRatio:t.ratio}};case"SET_LEFT_PANE_TAB":return{...e,layout:{...e.layout,leftPaneTab:t.tab}};case"TOGGLE_LEFT_PANE":return{...e,layout:{...e.layout,leftPaneCollapsed:!e.layout.leftPaneCollapsed}};case"SET_LEFT_PANE_COLLAPSED":return{...e,layout:{...e.layout,leftPaneCollapsed:t.collapsed}};case"SET_ACTIVE_ACTIVITY":return{...e,layout:{...e.layout,activityBar:{...e.layout.activityBar,active:t.activity}}};case"TOGGLE_ACTIVITY":{let n=e.layout.activityBar.active===t.activity?null:t.activity;return{...e,layout:{...e.layout,activityBar:{...e.layout.activityBar,active:n}}}}case"TOGGLE_HISTORY_PANE":{let t=!e.layout.historyPane.visible;return{...e,layout:{...e.layout,historyPane:{...e.layout.historyPane,visible:t,collapsed:!t}}}}case"SET_HISTORY_PANE_VISIBLE":return{...e,layout:{...e.layout,historyPane:{...e.layout.historyPane,visible:t.visible,collapsed:!t.visible}}};case"SET_HISTORY_WIDTH":return{...e,layout:{...e.layout,historyPane:{...e.layout.historyPane,width:t.width}}};case"SET_ERROR":return{...e,error:t.error};case"CLEAR_ERROR":return{...e,error:{...G.mS}};case"INCREMENT_RETRY_COUNT":return{...e,error:{...e.error,retryCount:e.error.retryCount+1}};case"SET_MESSAGES":return{...e,messages:t.messages};case"ADD_MESSAGE":return{...e,messages:[...e.messages,t.message]};case"UPDATE_MESSAGE":return{...e,messages:e.messages.map(e=>e.id===t.id?{...e,...t.updates}:e)};case"CLEAR_MESSAGES":return{...e,messages:[]};case"SET_WS_CONNECTED":return{...e,wsConnected:t.connected};default:return e}}function d8(e,t){try{window.localStorage.setItem(cA(e),null!=t?t:cE)}catch(e){}}function d9(e,t){if(e.length!==t.length)return!1;let n=new Set(e);return t.every(e=>n.has(e))}function d7(e,t){return e instanceof Error&&e.message?e.message:t}function ue(e){return e instanceof DOMException&&"AbortError"===e.name}let ut="commandmate:showArchived",un="activeCliTab-",ua="activeInstanceId-";function ur(){let e=(0,c.c)("worktree");return(0,r.jsxs)("div",{className:"flex items-center justify-center h-full bg-surface text-muted-foreground",children:[(0,r.jsx)(u.y,{size:"lg",className:"mr-2"}),(0,r.jsx)("span",{children:e("detail.loadingEditor")})]})}let us=(0,o.default)(()=>n.e(3922).then(n.bind(n,33922)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[33922]},ssr:!1,loading:()=>(0,r.jsx)(ur,{})}),ul=()=>{},ui=["terminal","history","files","memo","info"],uo=(0,i.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,onMessageSent:s,isSessionRunning:l,isProcessing:i,showToast:o,pendingInsertText:c,onInsertConsumed:d,autoYesSlot:u}=e,m=rz({cliToolId:n,instanceId:a});return(0,r.jsx)(eA,{worktreeId:t,onMessageSent:s,cliToolId:n,instanceId:a,isSessionRunning:l,isProcessing:i,showToast:o,pendingInsertText:c,onInsertConsumed:d,onOptimisticSend:m,autoYesSlot:u})}),uc=(0,i.memo)(function(e){var t,n,a,l,o,u,m,f,p,g,v,y;let{worktreeId:j}=e,{activeActivity:w,activeCliTab:k,activeInstanceId:N,activeTab:C,agentInstances:T,autoYesEnabled:A,autoYesExpiresAt:M,autoYesStateMap:L,diffContent:R,diffFilePath:D,disableAutoFollow:O,displayedInstances:z,editorFilePath:_,error:B,fetchCurrentOutput:H,fileInputRef:V,fileSearch:U,fileTreeRefresh:K,handleActivityOpen:W,handleActivityToggle:$,handleAgentInstancesChange:J,handleAutoYesToggle:Y,handleBackClick:X,handleCloseDiff:Z,handleDelete:ee,handleDiffSelect:et,handleDirtyChange:en,handleEditorClose:ea,handleEditorSave:er,handleFileInputChange:ei,handleFilePanelSave:eo,handleFilePathClick:ec,handleFileSelect:ed,handleHistoryDisplayLimitChange:eu,handleHistoryUserOnlyChange:em,handleInfoClick:eh,handleInfoModalClose:ef,handleInsertConsumed:ex,handleInsertConsumedSingle:ep,handleInsertToMessage:eg,handleInsertToSplit:eb,handleKillCancel:ev,handleKillConfirm:ey,openKillConfirm:ej,openActiveKillConfirm:ew,killTarget:ek,isKillPending:eN,handleLoadContent:eS,handleLoadError:eT,handleMessageSent:eI,handleMobileFileViewerClose:eE,handleMobileTabChange:eA,handleMove:eM,handleMoveCancel:eL,handleMoveConfirm:eR,handleNewDirectory:eP,handleNewFile:eD,handleNewFileCancel:ez,handleNewFileConfirm:e_,handleOpenFile:eB,handlePromptDismiss:eH,handlePromptRespond:eV,handleRename:eU,handleRetry:eK,handleSetLoading:eW,handleShowArchivedChange:e$,handleUpload:eq,handleVibeLocalContextWindowChange:eG,handleVibeLocalModelChange:eJ,handleWorktreeStatusChange:eY,hasUpdate:eQ,historyDisplayLimit:eZ,historySubTab:e0,historyUserOnly:e1,isEditorMaximized:e2,isInfoModalOpen:e5,isMobile:e4,isMoveDialogOpen:e3,isSelectionListActive:e6,isPagerActive:e8,lastAutoResponse:e9,loading:e7,makeAutoYesToggleHandler:te,mobileFileViewerPath:tt,mobileSelectedAgents:tn,moveTarget:ta,newFileParentPath:tr,openMobileDrawer:ts,pendingInsertText:tl,pendingInsertTextMap:to,rosterReady:tc,setActiveInstanceId:td,setFocusedSplitIndex:tm,setHistorySubTab:tf,setIsEditorMaximized:tx,setWorktree:tp,showArchived:tg,showNewFileDialog:tb,showToast:tv,state:ty,tCommon:tj,tWorktree:tw,tabsActions:tk,tabsState:tS,resetFileTreeView:tT,toggleInstanceVisible:tI,verification:tE,vibeLocalContextWindow:tA,vibeLocalModel:tM,visibleInstanceIds:tL,worktree:tR,worktreeName:tP,worktreeStatus:tD}=function(e){var t,n,a,r,l,o,d,u,m,h;let{worktreeId:f}=e,p=(0,s.useRouter)(),g=(0,eC.a)(),b=(0,i.useRef)(g);b.current=g;let{openMobileDrawer:v}=(0,cM.VF)(),{state:y,actions:j}=function(){let[e,t]=(0,i.useReducer)(d6,void 0,G.mR),{value:n,setValue:a}=(0,nm.V)({key:"commandmate.worktree.leftPaneCollapsed",defaultValue:!1,validate:e=>"boolean"==typeof e}),r=(0,i.useRef)(e.layout.leftPaneCollapsed);r.current=e.layout.leftPaneCollapsed;let s=(0,i.useRef)(!1);(0,i.useEffect)(()=>{s.current||(s.current=!0,n!==r.current&&t({type:"SET_LEFT_PANE_COLLAPSED",collapsed:n}))},[n]);let l=(0,i.useMemo)(()=>({setPhase:e=>t({type:"SET_PHASE",phase:e}),showPrompt:(e,n)=>t({type:"SHOW_PROMPT",data:e,messageId:n}),clearPrompt:()=>t({type:"CLEAR_PROMPT"}),setPromptAnswering:e=>t({type:"SET_PROMPT_ANSWERING",answering:e}),setError:e=>t({type:"SET_ERROR",error:e}),clearError:()=>t({type:"CLEAR_ERROR"}),setMessages:e=>t({type:"SET_MESSAGES",messages:e}),addMessage:e=>t({type:"ADD_MESSAGE",message:e}),updateMessage:(e,n)=>t({type:"UPDATE_MESSAGE",id:e,updates:n}),clearMessages:()=>t({type:"CLEAR_MESSAGES"}),setMobileActivePane:e=>t({type:"SET_MOBILE_ACTIVE_PANE",pane:e}),setLeftPaneTab:e=>t({type:"SET_LEFT_PANE_TAB",tab:e}),setLayoutMode:e=>t({type:"SET_LAYOUT_MODE",mode:e}),setSplitRatio:e=>t({type:"SET_SPLIT_RATIO",ratio:e}),setWsConnected:e=>t({type:"SET_WS_CONNECTED",connected:e}),toggleLeftPane:()=>{let e=!r.current;t({type:"SET_LEFT_PANE_COLLAPSED",collapsed:e}),a(e)},setActiveActivity:e=>t({type:"SET_ACTIVE_ACTIVITY",activity:e}),toggleActivity:e=>t({type:"TOGGLE_ACTIVITY",activity:e}),toggleHistoryPane:()=>t({type:"TOGGLE_HISTORY_PANE"}),setHistoryPaneVisible:e=>t({type:"SET_HISTORY_PANE_VISIBLE",visible:e}),setHistoryWidth:e=>t({type:"SET_HISTORY_WIDTH",width:e})}),[a]);return{state:e,dispatch:t,actions:l}}(),w=(0,c.c)("worktree"),k=(0,c.c)("error"),N=(0,c.c)("common"),C=(0,c.c)("autoYes"),S=(0,eO.SC)(),T=(0,Q.rC)(),E=null!=(l=null==T?void 0:T.worktrees.find(e=>e.id===f))?l:null,[A,M]=(0,i.useState)(E),[L,R]=(0,i.useState)(null===E),[P,D]=(0,i.useState)(null),[F,O]=(0,i.useState)(0),z=(0,i.useRef)(null!==E),[_,B]=(0,i.useState)(!1),[H,V]=function(e){let[t,n]=(0,i.useReducer)(function e(t,n){switch(n.type){case"OPEN_FILE":{let e=t.tabs.findIndex(e=>e.path===n.path);if(-1!==e){if(t.activeIndex===e)return t;return{...t,activeIndex:e}}if(t.tabs.length>=30)return t;let a={path:n.path,name:c6(n.path),content:null,loading:!1,error:null,isDirty:!1},r=[...t.tabs,a];return{tabs:r,activeIndex:r.length-1}}case"CLOSE_TAB":{var a,r;let e=t.tabs.findIndex(e=>e.path===n.path);if(-1===e)return t;let s=t.tabs.filter((t,n)=>n!==e),l=(a=t.activeIndex,0===(r=s.length)||null===a?null:e<a?a-1:e===a?Math.min(e,r-1):a);return{tabs:s,activeIndex:l}}case"ACTIVATE_TAB":{let e=t.tabs.findIndex(e=>e.path===n.path);if(-1===e||t.activeIndex===e)return t;return{...t,activeIndex:e}}case"SET_CONTENT":{let e=c8(t.tabs,n.path,e=>({...e,content:n.content,loading:!1,error:null,isDirty:!1}));if(!e)return t;return{...t,tabs:e}}case"SET_LOADING":{let e=c8(t.tabs,n.path,e=>({...e,loading:n.loading}));if(!e)return t;return{...t,tabs:e}}case"SET_ERROR":{let e=c8(t.tabs,n.path,e=>({...e,error:n.error,loading:!1}));if(!e)return t;return{...t,tabs:e}}case"RENAME_FILE":{let e=t.tabs.findIndex(e=>e.path===n.oldPath);if(-1===e)return t;let a=[...t.tabs];return a[e]={...a[e],path:n.newPath,name:c6(n.newPath)},{...t,tabs:a}}case"DELETE_FILE":return e(t,{type:"CLOSE_TAB",path:n.path});case"RESTORE":{let e=n.paths.slice(0,30).map(e=>({path:e,name:c6(e),content:null,loading:!1,error:null,isDirty:!1}));if(0===e.length)return c7;let t=n.activePath?Math.max(0,e.findIndex(e=>e.path===n.activePath)):0;return{tabs:e,activeIndex:t}}case"SET_DIRTY":{let e=t.tabs.find(e=>e.path===n.path);if(e&&e.isDirty===n.isDirty)return t;let a=c8(t.tabs,n.path,e=>({...e,isDirty:n.isDirty}));if(!a)return t;return{...t,tabs:a}}case"MOVE_TO_FRONT":{let e=t.tabs.findIndex(e=>e.path===n.path);if(-1===e||0===e)return t;return{tabs:[t.tabs[e],...t.tabs.filter((t,n)=>n!==e)],activeIndex:0}}case"CLOSE_ALL":if(0===t.tabs.length)return t;return c7;case"CLOSE_OTHERS":case"CLOSE_TO_RIGHT":{let e="CLOSE_OTHERS"===n.type?"others":"right",a=new Set(c9(t.tabs,n.path,e));if(0===a.size)return t;let r=t.tabs.filter(e=>!a.has(e.path));return{tabs:r,activeIndex:function(e,t,n){var a;if(0===t.length)return null;let r=null!==e.activeIndex?null==(a=e.tabs[e.activeIndex])?void 0:a.path:void 0;if(void 0!==r){let e=t.findIndex(e=>e.path===r);if(-1!==e)return e}let s=t.findIndex(e=>e.path===n);return -1!==s?s:0}(t,r,n.path)}}default:return t}},c7),a=(0,i.useRef)(!1),r=(0,i.useRef)(e);(0,i.useEffect)(()=>{if(r.current!==e&&(r.current=e,a.current=!1),a.current)return;a.current=!0;let t=function(e){try{let t=window.localStorage.getItem(c3+e);if(!t)return null;let n=JSON.parse(t);if("object"==typeof n&&null!==n&&Array.isArray(n.paths)&&n.paths.every(e=>"string"==typeof e)&&(null===n.activePath||"string"==typeof n.activePath))return n}catch(e){}return null}(e);t&&t.paths.length>0&&n({type:"RESTORE",paths:t.paths,activePath:t.activePath})},[e]),(0,i.useEffect)(()=>{if(a.current){var n,r;try{let a={paths:t.tabs.map(e=>e.path),activePath:null!==t.activeIndex&&null!=(r=null==(n=t.tabs[t.activeIndex])?void 0:n.path)?r:null};window.localStorage.setItem(c3+e,JSON.stringify(a))}catch(e){}}},[e,t]);let s=(0,i.useRef)(t);s.current=t;let l=(0,i.useCallback)(e=>{let t=s.current.tabs;return -1!==t.findIndex(t=>t.path===e)?(n({type:"OPEN_FILE",path:e}),"activated"):t.length>=30?"limit_reached":(n({type:"OPEN_FILE",path:e}),"opened")},[]),o=(0,i.useCallback)(e=>{n({type:"CLOSE_TAB",path:e})},[]),c=(0,i.useCallback)(e=>{n({type:"ACTIVATE_TAB",path:e})},[]),d=(0,i.useCallback)((e,t)=>{n({type:"RENAME_FILE",oldPath:e,newPath:t})},[]),u=(0,i.useCallback)(e=>{n({type:"DELETE_FILE",path:e})},[]),m=(0,i.useCallback)(e=>{n({type:"MOVE_TO_FRONT",path:e})},[]),h=(0,i.useCallback)(()=>{n({type:"CLOSE_ALL"})},[]),f=(0,i.useCallback)(e=>{n({type:"CLOSE_OTHERS",path:e})},[]),x=(0,i.useCallback)(e=>{n({type:"CLOSE_TO_RIGHT",path:e})},[]),p=(0,i.useMemo)(()=>({dispatch:n,openFile:l,closeTab:o,activateTab:c,onFileRenamed:d,onFileDeleted:u,moveToFront:m,closeAllTabs:h,closeOtherTabs:f,closeTabsToRight:x}),[n,l,o,c,d,u,m,h,f,x]);return[t,p]}(f),[U,K]=(0,i.useState)(null),[W,$]=(0,i.useState)(null),[J,Y]=(0,i.useState)(!1),[X,Z]=(0,i.useState)(new Map),[ee,et]=(0,i.useState)(null),[en,ea]=(0,i.useState)(!1),[er,es]=(0,i.useState)(!1),[ei,eo]=(0,i.useState)(!1),ec=(0,i.useRef)(!1),[ed,eu]=(0,i.useState)(null),[em,eh]=(0,i.useState)(lB.sA),ef=(0,i.useRef)(em);ef.current=em;let[ex,ep]=(0,i.useState)(()=>(0,q.lu)((0,lB.sA)())),eg=(0,i.useRef)(ex);eg.current=ex;let[eb,ev]=(0,i.useState)(null),ey=eb===f,[ej,ew]=(0,i.useState)(null),[ek,eN]=(0,i.useState)(null),[eS,eT]=(0,i.useState)(()=>{try{let e=window.localStorage.getItem(un+f);if(e&&(0,q.hR)(e))return e}catch(e){}return(0,lB.sA)()[0]}),eI=(0,i.useCallback)(e=>{eT(e);try{window.localStorage.setItem(un+f,e)}catch(e){}},[f]),eE=(0,i.useRef)(eS);eE.current=eS;let[eA,eM]=(0,i.useState)(()=>{try{let e=window.localStorage.getItem(ua+f);if(e&&(0,q.n6)(e))return e;let t=window.localStorage.getItem(un+f);if(t&&(0,q.hR)(t))return t}catch(e){}return(0,lB.sA)()[0]}),eL=(0,i.useCallback)(e=>{eM(e);try{window.localStorage.setItem(ua+f,e)}catch(e){}let t=eg.current.find(t=>t.id===e);t&&eI(t.cliTool)},[f,eI]),eR=(0,i.useRef)(eA);eR.current=eA;let eP=(0,i.useRef)(0),eD=(0,i.useRef)(0),eF=(0,i.useRef)(0),ez=null!=(o=null==(t=X.get(eA))?void 0:t.enabled)&&o,e_=null!=(d=null==(n=X.get(eA))?void 0:n.expiresAt)?d:null,[eB,eH]=(0,i.useState)(0),[eV,eU]=(0,i.useState)(!1),[eK,eW]=(0,i.useState)(""),{active:e$,setActive:eq,toggle:eG}=function(e){let[t,n]=(0,i.useState)(cI),a=(0,i.useRef)(t);a.current=t;let r=(0,i.useRef)(e);return r.current=e,(0,i.useEffect)(()=>{let t=function(e){try{let t=window.localStorage.getItem(cA(e));if(t===cE)return null;if(t&&"string"==typeof t&&cT.has(t))return t}catch(e){}return cI}(e);t!==a.current&&n(t)},[e]),{active:t,setActive:(0,i.useCallback)(e=>{n(e),d8(r.current,e)},[]),toggle:(0,i.useCallback)(e=>{if(a.current===e){n(null),d8(r.current,null);return}n(e),d8(r.current,e)},[])}}(f),{historySubTab:eJ,setHistorySubTab:eY,showArchived:eQ,handleShowArchivedChange:eZ,historyUserOnly:e0,handleHistoryUserOnlyChange:e1,historyDisplayLimit:e2,handleHistoryDisplayLimitChange:e5}=function(){let[e,t]=(0,i.useState)("message"),[n,a]=(0,i.useState)(()=>"true"===localStorage.getItem(ut)),r=(0,i.useCallback)(e=>{a(e),localStorage.setItem(ut,String(e))},[]),[s,l]=(0,i.useState)(()=>{try{return"true"===localStorage.getItem(si)}catch(e){return!1}}),o=(0,i.useCallback)(e=>{l(e);try{localStorage.setItem(si,String(e))}catch(e){}},[]),[c,d]=(0,i.useState)(()=>{try{let e=localStorage.getItem(ss);if(null===e)return 50;let t=parseInt(e,10);return sl(t)?t:50}catch(e){return 50}});return{historySubTab:e,setHistorySubTab:t,showArchived:n,handleShowArchivedChange:r,historyUserOnly:s,handleHistoryUserOnlyChange:o,historyDisplayLimit:c,handleHistoryDisplayLimitChange:(0,i.useCallback)(e=>{d(e);try{localStorage.setItem(ss,String(e))}catch(e){}},[])}}(),e4=(0,i.useRef)(eQ);(0,i.useEffect)(()=>{e4.current=eQ},[eQ]);let e3=(0,i.useRef)(e2);(0,i.useEffect)(()=>{e3.current=e2},[e2]),(0,i.useEffect)(()=>{(0,lB.qD)()},[]);let{pendingInsertTextMap:e6,pendingInsertText:e8,setFocusedSplitIndex:e9,handleInsertToMessage:e7,handleInsertToSplit:te,handleInsertConsumed:tt,handleInsertConsumedSingle:tn}=function(){var e;let[t,n]=(0,i.useState)(()=>new Map),[a,r]=(0,i.useState)(0),s=(0,i.useCallback)(e=>{n(t=>{let n=new Map(t);return n.set(a,e),n})},[a]),l=(0,i.useCallback)((e,t)=>{n(n=>{let a=new Map(n);return a.set(e,t),a})},[]),o=(0,i.useCallback)(e=>{n(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),c=null!=(e=t.get(0))?e:null,d=(0,i.useCallback)(()=>o(0),[o]);return{pendingInsertTextMap:t,pendingInsertText:c,focusedSplitIndex:a,setFocusedSplitIndex:r,handleInsertToMessage:s,handleInsertToSplit:l,handleInsertConsumed:o,handleInsertConsumedSingle:d}}(),{diffContent:ta,diffFilePath:tr,handleDiffSelect:ts,handleCloseDiff:tl}=function(e){let[t,n]=(0,i.useState)(null),[a,r]=(0,i.useState)(null);return{diffContent:t,diffFilePath:a,handleDiffSelect:(0,i.useCallback)((t,a)=>{e||(n(t),r(a))},[e]),handleCloseDiff:(0,i.useCallback)(()=>{n(null),r(null)},[])}}(g),ti=function(e){let{worktreeId:t,initialMode:n="name",debounceMs:a=300}=e,[r,s]=(0,i.useState)(""),[l,o]=(0,i.useState)(""),[c,d]=(0,i.useState)(n),[u,m]=(0,i.useState)(!1),[h,f]=(0,i.useState)(null),[p,g]=(0,i.useState)(null),b=(0,i.useRef)(null),v=(0,i.useMemo)(()=>(0,x.sg)(e=>{o(e)},a),[a]),y=(0,i.useCallback)(e=>{s(e),v(e),g(null)},[v]),j=(0,i.useCallback)(()=>{s(""),o(""),f(null),g(null),m(!1),b.current&&(b.current.abort(),b.current=null)},[]),w=(0,i.useCallback)(e=>{if(!l.trim())return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t))},[l]),k=(0,i.useCallback)(()=>h&&0!==h.results.length?(0,x.q3)(h.results.map(e=>e.filePath)):new Set,[h]);return(0,i.useEffect)(()=>{if("content"!==c||!l.trim())return void f(null);b.current&&b.current.abort();let e=new AbortController;return b.current=e,(async()=>{m(!0),g(null);try{var n,a;let r=await fetch("/api/worktrees/".concat(encodeURIComponent(t),"/search?q=").concat(encodeURIComponent(l),"&mode=content"),{signal:e.signal});if(!r.ok){let e=await r.json();throw Error((null==(n=e.error)?void 0:n.message)||"Search failed: ".concat(r.status))}let s=await r.json();if(s.success)f({mode:"content",query:l,results:s.results,totalMatches:s.totalMatches,truncated:s.truncated,executionTimeMs:s.executionTimeMs});else throw Error((null==(a=s.error)?void 0:a.message)||"Search failed")}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g(e instanceof Error?e.message:"An error occurred while searching"),f(null)}finally{m(!1)}})(),()=>{e.abort()}},[c,l,t]),(0,i.useEffect)(()=>{"name"===c&&(f(null),m(!1),g(null))},[c]),{query:r,mode:c,isSearching:u,results:h,error:p,setQuery:y,setMode:d,clearSearch:j,filterByName:w,getMatchedPaths:k}}({worktreeId:f}),to=(0,i.useRef)(!1),tc=(0,i.useRef)(f);(0,i.useEffect)(()=>{tc.current!==f&&(j.clearMessages(),to.current=!1,Z(new Map),tc.current=f)},[f,j]);let td=(0,i.useCallback)(async()=>{try{var e,t;let n=await fetch("/api/worktrees/".concat(f));if(!n.ok)throw Error("Failed to fetch worktree: ".concat(n.status));let a=await n.json();if(M(a),a.selectedAgents){let e=ef.current;a.selectedAgents.length===e.length&&a.selectedAgents.every((t,n)=>t===e[n])||eh(a.selectedAgents)}if(a.agentInstances){let e=eg.current,t=a.agentInstances;t.length===e.length&&t.every((t,n)=>t.id===e[n].id&&t.cliTool===e[n].cliTool&&t.alias===e[n].alias)||ep(t),ev(f)}return"vibeLocalModel"in a&&ew(null!=(e=a.vibeLocalModel)?e:null),"vibeLocalContextWindow"in a&&eN(null!=(t=a.vibeLocalContextWindow)?t:null),a}catch(e){return D(e instanceof Error?e.message:"Unknown error"),null}},[f]),tm=(0,i.useCallback)(async()=>{let e=eE.current,t=b.current,n=eR.current,a=++eP.current;try{let r=new URLSearchParams({cliTool:e,unit:"pairs"});t&&r.set("instance",n),e4.current&&r.set("includeArchived","true"),r.set("limit",String(e3.current));let s=await fetch("/api/worktrees/".concat(f,"/messages?").concat(r.toString()));if(!s.ok)throw Error("Failed to fetch messages: ".concat(s.status));let l=await s.json();if(eP.current!==a||eE.current!==e||t&&eR.current!==n)return;j.setMessages(l.map(e=>({...e,timestamp:new Date(e.timestamp)})))}catch(r){if(eP.current!==a||eE.current!==e||t&&eR.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching messages:",r)}},[f,j]),tf=(0,i.useCallback)(async()=>{let e=eE.current,t=b.current,n=eR.current,a=++eD.current;try{var r,s,l,i;let o=t?"/api/worktrees/".concat(f,"/current-output?cliTool=").concat(e,"&instance=").concat(encodeURIComponent(n)):"/api/worktrees/".concat(f,"/current-output?cliTool=").concat(e),c=await fetch(o);if(!c.ok)return;let d=await c.json();if(eD.current!==a||eE.current!==e||t&&eR.current!==n||d.cliToolId&&d.cliToolId!==e)return;if(d.isPromptWaiting&&d.promptData?j.showPrompt(d.promptData,"prompt-".concat(Date.now())):!d.isPromptWaiting&&y.prompt.visible&&j.clearPrompt(),es(null!=(r=d.isSelectionListActive)&&r),eo(null!=(s=d.isPagerActive)&&s),et(null!=(l=d.lastServerResponseTimestamp)?l:null),ea(null!=(i=d.serverPollerActive)&&i),d.autoYes){let a=ec.current,r=d.autoYes,s=t?n:e;Z(e=>{let t=new Map(e);return t.set(s,{enabled:r.enabled,expiresAt:r.expiresAt}),t}),ec.current=r.enabled,a&&!d.autoYes.enabled&&("stop_pattern_matched"===d.autoYes.stopReason||"consecutive_errors"===d.autoYes.stopReason)&&eu(d.autoYes.stopReason)}}catch(r){if(eD.current!==a||eE.current!==e||t&&eR.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching current output:",r)}},[f,j,y.prompt.visible]),tx=(0,i.useCallback)(async()=>{let e=++eF.current;try{let a=await fetch("/api/worktrees/".concat(f,"/auto-yes"));if(!a.ok)return;let r=await a.json();if(eF.current!==e)return;let s=null==r?void 0:r.instances;if(!s||"object"!=typeof s)return;let l=new Map;for(let[e,a]of Object.entries(s))if(a&&"object"==typeof a){var t,n;l.set(e,{enabled:null!=(t=a.enabled)&&t,expiresAt:null!=(n=a.expiresAt)?n:null})}Z(l)}catch(t){if(eF.current!==e)return;console.error("[WorktreeDetailRefactored] Error fetching auto-yes states:",t)}},[f]),{visibleInstances:tp,visibleInstanceIds:tg,toggleInstanceVisible:tb}=function(e){let{worktreeId:t,roster:n}=e,[a,r]=(0,i.useState)(null);(0,i.useEffect)(()=>{r(function(e){try{let t=window.localStorage.getItem(lA(e));if(null===t)return null;let n=JSON.parse(t);if(!Array.isArray(n))return null;let a=n.filter(e=>"string"==typeof e);return a.length>0?a:null}catch(e){return null}}(t))},[t]);let s=(0,i.useMemo)(()=>lM(a,n),[a,n]),l=(0,i.useMemo)(()=>s.map(e=>e.id),[s]),o=(0,i.useMemo)(()=>null!==a&&n.some(e=>a.includes(e.id)),[a,n]),c=(0,i.useCallback)(e=>{let a=new Set(e),s=n.filter(e=>a.has(e.id)).map(e=>e.id);if(!(s.length<1)){r(s);try{window.localStorage.setItem(lA(t),JSON.stringify(s))}catch(e){}}},[n,t]),d=(0,i.useCallback)(e=>c(e),[c]);return{visibleInstances:s,visibleInstanceIds:l,hasStoredPreference:o,toggleInstanceVisible:(0,i.useCallback)(e=>{let t=lM(a,n).map(e=>e.id);if(t.includes(e)){if(t.length<=1)return;c(t.filter(t=>t!==e))}else c([...t,e])},[a,n,c]),setVisibleInstanceIds:d,showInstances:(0,i.useCallback)(e=>{null!==a&&c([...lM(a,n).map(e=>e.id),...e])},[a,n,c])}}({worktreeId:f,roster:ex}),tv=g?tp:ex,ty=(0,i.useMemo)(()=>Array.from(new Set(tp.map(e=>e.cliTool))),[tp]),tj=g?ty:em;(0,i.useEffect)(()=>{0!==tv.length&&(tv.some(e=>e.id===eA)||eL(tv[0].id))},[tv,eA,eL]),(0,i.useEffect)(()=>{let e=tv.find(e=>e.id===eA);e&&e.cliTool!==eS&&eI(e.cliTool)},[tv,eA,eS,eI]);let tw="opencode"===eS||"copilot"===eS,tk=(0,i.useCallback)(e=>{eh(e)},[]),tN=(0,i.useCallback)(e=>{ep(e),ev(f)},[f]),tC=(0,i.useCallback)(e=>{ew(e)},[]),tS=(0,i.useCallback)(e=>{eN(e)},[]),tT=(0,i.useRef)(eS);(0,i.useEffect)(()=>{tT.current!==eS&&(tT.current=eS,j.clearMessages(),j.clearPrompt(),es(!1),tm(),tf())},[eS,j,tm,tf]),(0,i.useEffect)(()=>{tm()},[eQ,tm]),(0,i.useEffect)(()=>{tm()},[e2,tm]);let{showToast:tI}=(0,tu.dj)(),tE=(0,i.useCallback)(()=>{tI("Maximum ".concat(30," file tabs. Close a tab first."),"info")},[tI]),tA=(0,i.useCallback)(e=>{g?K(e):"limit_reached"===V.openFile(e)&&tE()},[g,V,tE]),tM=(0,i.useCallback)(e=>{g?K(e):"limit_reached"===V.openFile(e)&&tE()},[g,V,tE]),tL=(0,i.useCallback)(e=>{"limit_reached"===V.openFile(e)&&tE()},[V,tE]),tR=(0,i.useCallback)(()=>{K(null)},[]),tP=(0,i.useCallback)(e=>{eH(e=>e+1)},[]),tD=(0,i.useCallback)(()=>{$(null)},[]),tF=(0,i.useCallback)(()=>{ti.clearSearch(),V.closeAllTabs(),K(null),$(null)},[ti,V]),tO=(0,i.useCallback)(e=>{eH(e=>e+1)},[]),tz=(0,i.useCallback)(e=>{eG(e)},[eG]),t_=(0,i.useCallback)(e=>{eq(e)},[eq]),tB=(0,i.useCallback)(()=>{p.push("/")},[p]),tH=(0,i.useCallback)(async e=>{try{let t=await fetch("/api/worktrees/".concat(f),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:e})});if(t.ok){let e=await t.json();M(e)}}catch(e){}},[f]),tV=(0,i.useCallback)(()=>{B(!0)},[]),tU=(0,i.useCallback)(()=>{B(!1)},[]),tK=(0,i.useCallback)(async e=>{j.setPromptAnswering(!0);try{let t=dY(e,eS,I(y.prompt.data)?y.prompt.data:null,b.current?eR.current:void 0),n=await fetch("/api/worktrees/".concat(f,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error("Failed to send prompt response: ".concat(n.status));j.clearPrompt(),await tf()}catch(e){console.error("[WorktreeDetailRefactored] Error sending prompt response:",e)}finally{j.setPromptAnswering(!1)}},[f,j,tf,eS,y.prompt.data]),tW=(0,i.useCallback)(()=>{j.clearPrompt()},[j]),t$=(0,i.useCallback)(e=>{j.setMobileActivePane(e)},[j]),tq=(0,i.useCallback)(()=>{tm(),tf()},[tm,tf]),tG=(0,i.useCallback)((e,t)=>async n=>{let a=null!=t?t:e;try{let t=await fetch("/api/worktrees/".concat(f,"/auto-yes"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:n.enabled,cliToolId:e,instanceId:a,duration:n.duration,stopPattern:n.stopPattern})});if(t.ok){let e=await t.json();Z(t=>{let n=new Map(t);return n.set(a,{enabled:e.enabled,expiresAt:e.expiresAt}),n}),a===eR.current&&(ec.current=e.enabled)}}catch(e){console.error("[WorktreeDetailRefactored] Error toggling auto-yes:",e)}},[f]),tJ=(0,i.useCallback)(e=>tG(eS,eA)(e),[tG,eS,eA]),[tY,tQ]=(0,i.useState)(null),[tX,tZ]=(0,i.useState)(!1),t0=(0,i.useRef)(!1),t1=(0,i.useCallback)(e=>{tQ(e)},[]),t2=(0,i.useCallback)(()=>{let e=eR.current,t=eE.current,n=(0,q.O6)(eg.current,e,t);tQ({cliToolId:t,instanceId:e,label:n})},[]),t5=(0,i.useCallback)(async()=>{if(!tY||t0.current)return;t0.current=!0,tZ(!0);let e=()=>{tY.instanceId===eR.current&&(j.clearMessages(),j.clearPrompt())};try{await el.y.killSession(f,tY.cliToolId,tY.instanceId),e(),await td(),tQ(null)}catch(t){t instanceof el.hD&&404===t.status?(e(),await td(),tQ(null)):tI(w("session.failedToKill"),"error")}finally{t0.current=!1,tZ(!1)}},[tY,f,j,td,tI,w]),t4=(0,i.useCallback)(()=>{t0.current||tQ(null)},[]),t3=(0,i.useCallback)(e=>{eW(e),eU(!0)},[]),t6=(0,i.useCallback)(async e=>{eU(!1);let t=eK?"".concat(eK,"/").concat(e):e;try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,eX.o)(t)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"file",content:""})})).ok)throw Error("Failed to create file");eH(e=>e+1)}catch(e){window.alert(k("fileOps.failedToCreateFile"))}},[f,eK,k]),t8=(0,i.useCallback)(()=>{eU(!1)},[]),t9=(0,i.useCallback)(async e=>{let t=window.prompt("Enter directory name:");if(!t)return;let n=e?"".concat(e,"/").concat(t):t;try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,eX.o)(n)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"directory"})})).ok)throw Error("Failed to create directory");eH(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to create directory:",e),window.alert(k("fileOps.failedToCreateDirectory"))}},[f,k]),t7=(0,i.useCallback)(async e=>{let t=e.split("/").pop()||"",n=window.prompt("Enter new name:",t);if(n&&n!==t)try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,eX.o)(e)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"rename",newName:n})})).ok)throw Error("Failed to rename");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")+1):"";V.onFileRenamed(e,"".concat(t).concat(n)),eH(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to rename:",e),window.alert(k("fileOps.failedToRename"))}},[f,V,k]),ne=(0,i.useCallback)(async e=>{let t=e.split("/").pop()||e;if(await S({description:N("confirmDelete",{name:t}),variant:"danger"}))try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,eX.o)(e),"?recursive=true"),{method:"DELETE"})).ok)throw Error("Failed to delete");(W===e||(null==W?void 0:W.startsWith("".concat(e,"/"))))&&$(null),V.onFileDeleted(e),eH(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to delete:",e),window.alert(k("fileOps.failedToDelete"))}},[f,W,V,N,k,S]);(0,i.useEffect)(()=>{"stop_pattern_matched"===ed?(tI(C("stopPatternMatched"),"info"),eu(null)):"consecutive_errors"===ed&&(tI(C("consecutiveErrorsStopped"),"warning"),eu(null))},[ed,tI,C]);let{moveTarget:nt,isMoveDialogOpen:nn,handleMove:na,handleMoveConfirm:nr,handleMoveCancel:ns}=function(e,t,n,a){let[r,s]=(0,i.useState)(null),[l,o]=(0,i.useState)(!1),c=(0,i.useCallback)((e,t)=>{s({path:e,type:t}),o(!0)},[]),d=(0,i.useCallback)(async l=>{if(r)try{let s=await fetch("/api/worktrees/".concat(e,"/files/").concat(r.path),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"move",destination:l})}),o=await s.json();if(!s.ok||!o.success){var i;let e=(null==(i=o.error)?void 0:i.message)||"Failed to move";null==a||a(e);return}null==n||n("Moved successfully"),t()}catch(e){null==a||a("Failed to move")}finally{s(null),o(!1)}},[r,e,t,n,a]);return{moveTarget:r,isMoveDialogOpen:l,handleMove:c,handleMoveConfirm:d,handleMoveCancel:(0,i.useCallback)(()=>{s(null),o(!1)},[])}}(f,()=>eH(e=>e+1),e=>tI(e,"success"),e=>tI(e,"error")),nl=(0,i.useRef)(null),ni=(0,i.useRef)(""),no=(0,i.useCallback)(e=>{var t;ni.current=e,null==(t=nl.current)||t.click()},[]),nc=(0,i.useCallback)(async e=>{var t,n,a;let r=null==(t=e.target.files)?void 0:t[0];if(!r)return;e.target.value="";let s=ni.current,l=".".concat(null==(n=r.name.split(".").pop())?void 0:n.toLowerCase());if(!function(e){if(!e)return!1;let t=e.toLowerCase();return cH.includes(t)}(l))return void tI("Unsupported file type: ".concat(l,". Allowed: ").concat(cH.join(", ")),"error");let i=function(e){var t;let n=function(e){let t=e.toLowerCase();return cB.find(e=>e.extension===t)}(e);return null!=(t=null==n?void 0:n.maxFileSize)?t:0x1400000}(l);if(r.size>i)return void tI("File too large. Maximum size: ".concat((i/1024/1024).toFixed(1),"MB"),"error");let o=new FormData;o.append("file",r);try{let e=await fetch("/api/worktrees/".concat(f,"/upload/").concat((0,eX.o)(s||".")),{method:"POST",body:o});if(!e.ok){let t=await e.json().catch(()=>({})),n=(null==t||null==(a=t.error)?void 0:a.message)||"Failed to upload file";tI(n,"error");return}let t=await e.json();tI("Uploaded: ".concat(t.filename),"success"),eH(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to upload:",e),tI("Upload failed. Please try again.","error")}},[f,tI]),{data:nd}=th(),nu=null!=(u=null==nd?void 0:nd.hasUpdate)&&u,{lastAutoResponse:nh}=function(e){let{worktreeId:t,cliTool:n,isPromptWaiting:a,promptData:r,autoYesEnabled:s,lastServerResponseTimestamp:l,serverPollerActive:o}=e,c=(0,i.useRef)(null),[d,u]=(0,i.useState)(null);return(0,i.useEffect)(()=>{var e;if(!a){c.current=null;return}if(!r||!s||!I(r)||o||l&&Date.now()-l<3e3)return;let i=(e={type:r.type,question:r.question},"".concat(e.type,":").concat(e.question));if(c.current===i)return;let d=function(e,t){let n=function(e){if("yes_no"===e.type)return"y";if("multiple_choice"===e.type){let t=e.options.find(e=>e.isDefault),n=null!=t?t:e.options[0];return!n||n.requiresTextInput?null:n.number.toString()}return null}(e);if(null===n)return{answer:null,suppressedBy:null};let a=function(e,t,n){if(!n)return null;if("off"===n.mode)return{reason:"mode-off"};let a=function(e,t){if(0===t.length)return{outcome:"no-match"};let n=e.map(e=>e.length>2e4?e.slice(0,2e4):e);for(let e of t){if(e.length>200||!l1(e).valid)return{outcome:"unusable",pattern:e};let t=new RegExp(e);for(let a of n){let n=function(e,t){arguments.length>2&&void 0!==arguments[2]&&arguments[2];try{return e.test(t)}catch(e){return null}}(t,a);if(null===n)return{outcome:"unusable",pattern:e};if(n)return{outcome:"match",pattern:e}}}return{outcome:"no-match"}}(t,n.denyPatterns);return"match"===a.outcome?{reason:"deny-pattern",pattern:a.pattern}:"unusable"===a.outcome?{reason:"deny-pattern-unusable",pattern:a.pattern}:"safe"===n.mode?"yes_no"===e?null:{reason:"type-not-allowed"}:"allow-listed"===n.mode?n.allowPromptTypes.includes(e)?null:{reason:"type-not-allowed"}:null}(e.type,function(e){let t=[e.question];if(e.approvalTarget&&t.push(e.approvalTarget),"multiple_choice"===e.type)for(let n of e.options)t.push(n.label);else t.push(...e.options);return t}(e),t);return a?{answer:null,suppressedBy:a.reason,pattern:a.pattern}:{answer:n,suppressedBy:null}}(r,void 0).answer;if(null===d)return;c.current=i,u(d);let m=dY(d,n,r);fetch("/api/worktrees/".concat(t,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}).catch(e=>{console.error("[useAutoYes] Failed to send auto-response:",e)})},[a,r,s,t,n,l,o]),{lastAutoResponse:d}}({worktreeId:f,cliTool:eS,isPromptWaiting:y.prompt.visible,promptData:y.prompt.data,autoYesEnabled:ez,lastServerResponseTimestamp:ee,serverPollerActive:en}),nf=(0,i.useCallback)(async()=>{D(null),R(!0),await td()&&await Promise.all([tm(),tf()]),R(!1)},[td,tm,tf]);!function(e){let{error:t,handleRetry:n,fetchWorktree:a,fetchMessages:r,fetchCurrentOutput:s,setError:l}=e,o=(0,i.useRef)(0),c=(0,i.useCallback)(async()=>{if("visible"!==document.visibilityState)return;let e=Date.now();if(!(e-o.current<5e3)){if(o.current=e,t)return void n();try{await Promise.all([a(),r(),s()])}finally{l(null)}}},[t,n,a,r,s,l]);(0,i.useEffect)(()=>(document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c)}),[c])}({error:P,handleRetry:nf,fetchWorktree:td,fetchMessages:tm,fetchCurrentOutput:tf,setError:D}),(0,i.useEffect)(()=>{if(to.current)return;let e=!0;return(async()=>{z.current||R(!0),await Promise.all([td(),tm(),tf()]),e&&(R(!1),to.current=!0)})(),()=>{e=!1}},[td,tm,tf]);let nx=null!=(m=null==A||null==(r=A.sessionStatusByCli)||null==(a=r[eS])?void 0:a.isRunning)&&m;(0,i.useEffect)(()=>{if(L||P)return;let e=setInterval(async()=>{let e=[tf(),td()];g&&e.push(tm()),await Promise.all(e),O(e=>e+1)},nx?2e3:5e3);return()=>clearInterval(e)},[L,P,tf,td,tm,nx,g]),(0,i.useEffect)(()=>{tx()},[f,ey,tx]),(0,i.useEffect)(()=>{j.setLayoutMode(g?"tabs":"split")},[g,j]);let np=(0,i.useMemo)(()=>(function(e,t){var n;let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"claude";if(t)return"error";if(!e)return"idle";let r=null==(n=e.sessionStatusByCli)?void 0:n[a];if(r){if(r.isWaitingForResponse)return"waiting";if(r.isProcessing)return"running";if(r.isRunning)return"ready"}if("claude"===a){if(e.isWaitingForResponse)return"waiting";if(e.isProcessing)return"running";if(e.isSessionRunning)return"ready"}return"idle"})(A,null!==y.error.type,eS),[A,y.error.type,eS]),ng=(0,i.useMemo)(()=>y.layout.mobileActivePane,[y.layout.mobileActivePane]),nb=null!=(h=null==A?void 0:A.name)?h:"Unknown",nv=(0,i.useCallback)((e,t)=>{V.dispatch({type:"SET_CONTENT",path:e,content:t})},[V]),ny=(0,i.useCallback)((e,t)=>{V.dispatch({type:"SET_ERROR",path:e,error:t})},[V]),nj=(0,i.useCallback)((e,t)=>{V.dispatch({type:"SET_LOADING",path:e,loading:t})},[V]),nw=(0,i.useCallback)((e,t)=>{V.dispatch({type:"SET_DIRTY",path:e,isDirty:t})},[V]),nk=function(e){var t,n,a;let{worktreeId:r,refreshToken:s=0,enabled:l=!0,limit:o=10}=e,[c,d]=(0,i.useState)(null),[u,m]=(0,i.useState)([]),[h,f]=(0,i.useState)(null),[x,p]=(0,i.useState)(null),[g,b]=(0,i.useState)(!0),[v,y]=(0,i.useState)(null),[j,w]=(0,i.useState)(null),[k,N]=(0,i.useState)(!1),[C,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(null),[E,A]=(0,i.useState)(null),[M,L]=(0,i.useState)(null),[R,P]=(0,i.useState)(!1),[D,F]=(0,i.useState)(null),[O,z]=(0,i.useState)(null),[_,B]=(0,i.useState)(!1),[H,V]=(0,i.useState)(null),[U,K]=(0,i.useState)(null),[W,$]=(0,i.useState)(null),[q,G]=(0,i.useState)(o),[J,Y]=(0,i.useState)(o),[Q,X]=(0,i.useState)(!1),[Z,ee]=(0,i.useState)([]),[et,en]=(0,i.useState)(!1),[ea,er]=(0,i.useState)(null),[es,el]=(0,i.useState)(0),ei=(0,i.useRef)(0),eo=(0,i.useRef)(0),ec=(0,i.useRef)(!1),ed=(0,i.useRef)(!1),eu=(0,i.useRef)(!1),em=(0,i.useRef)(!1),eh=(0,i.useRef)(!1),ef=(0,i.useRef)(!1),ex=(0,i.useRef)(null);ex.current=W;let ep=(0,i.useRef)(o);ep.current=q,ed.current=(null==c?void 0:c.status)==="verifying"||u.some(e=>"running"===e.status),(0,i.useEffect)(()=>{if(ei.current+=1,eo.current=0,ec.current=!1,!ef.current){ef.current=!0;return}d(null),m([]),f(null),p(null),b(!0),y(null),w(null),I(null),A(null),L(null),F(null),z(null),V(null),$(null),G(o),Y(o),K(null)},[r]),(0,i.useEffect)(()=>{if(!l)return;let e=new AbortController,t=!1;return(async()=>{try{let n=await iV(r,e.signal);if(t)return;A(n),L(null)}catch(e){if(t||ue(e))return;A(null),L(d7(e,"Failed to load the verification config"))}})(),()=>{t=!0,e.abort()}},[r,l,es]),(0,i.useEffect)(()=>{if(!l)return;let e=0===eo.current,t=15e3*!ed.current;if(!e&&Date.now()-eo.current<t||ec.current)return;let n=ei.current;ec.current=!0,eo.current=Date.now(),(async()=>{try{let[e,t]=await Promise.all([iz(r),i_(r,q)]);if(n!==ei.current)return;d(e),m(t),Y(q),y(null)}catch(e){if(n!==ei.current||ue(e))return;y(d7(e,"Failed to load verification data"))}finally{ec.current=!1,n===ei.current&&(b(!1),ep.current!==q&&(eo.current=0,el(e=>e+1)))}})()},[r,s,es,l,q]);let eg=null!=(n=null!=h?h:null==(t=u[0])?void 0:t.id)?n:null,eb=(0,i.useMemo)(()=>{var e,t;if(null===eg)return null;let n=u.find(e=>e.id===eg);return(null==n?void 0:n.status)==="running"?"".concat(eg,":running:").concat(s,":").concat(es):"".concat(eg,":").concat(null!=(e=null==n?void 0:n.status)?e:"unlisted",":").concat(null!=(t=null==n?void 0:n.finishedAt)?t:"")},[eg,u,s,es]);(0,i.useEffect)(()=>{if(!l||null===eg){p(null),w(null),N(!1);return}let e=new AbortController,t=!1;return N(!0),(async()=>{try{let n=await iB(r,eg,e.signal);if(t)return;p(n),w(null===n?"not-found":null)}catch(e){if(t||ue(e))return;p(null),w(d7(e,"Failed to load the verification run"))}finally{t||N(!1)}})(),()=>{t=!0,e.abort()}},[r,l,eb]),(0,i.useEffect)(()=>{if(!l||!Q)return;let e=new AbortController,t=!1;return en(!0),(async()=>{try{let n=await iW({days:7,limit:20},e.signal);if(t)return;ee(n),er(null)}catch(e){if(t||ue(e))return;er(d7(e,"Failed to load the verification history"))}finally{t||en(!1)}})(),()=>{t=!0,e.abort()}},[l,Q,es]);let ev=(0,i.useMemo)(()=>{var e;return null!=(e=null==E?void 0:E.plannedGateIds)?e:[]},[E]),ey=(0,i.useMemo)(()=>{var e;return(null!=(e=null==x?void 0:x.gates)?e:[]).filter(e=>iL.includes(e.status)).map(e=>e.gateId)},[x]),ej=(0,i.useMemo)(()=>{var e;return null!=(e=u.find(e=>"running"===e.status))?e:null},[u]),ew=(0,i.useCallback)(e=>{$(null===e||d9(e,ev)?null:e)},[ev]),ek=(0,i.useCallback)(e=>{$(t=>{let n=new Set(null!=t?t:ev);n.has(e)?n.delete(e):n.add(e);let a=ev.filter(e=>n.has(e));return d9(a,ev)?null:a})},[ev]),eN=(0,i.useCallback)(()=>{let e=ev.filter(e=>ey.includes(e));$(0===e.length||d9(e,ev)?null:e)},[ev,ey]),eC=(0,i.useCallback)(()=>{eo.current=0,G(e=>Math.min(e+10,100))},[]),eS=(0,i.useCallback)(()=>{X(e=>!e)},[]),eT=(0,i.useCallback)(()=>{eo.current=0,el(e=>e+1)},[]),eI=(0,i.useCallback)(e=>{f(e)},[]),eE=(0,i.useCallback)(async e=>{if(!eu.current){eu.current=!0,S(!0),I(null),V(null);try{let t=void 0===e?ex.current:e,n=await iH(r,null!==t&&t.length>0?{gateIds:t}:{});f(n),eo.current=0,el(e=>e+1)}catch(t){let e=t instanceof iD&&409===t.status;I({kind:e?"conflict":"error",message:d7(t,"Failed to start verification"),runningRunId:t instanceof iD?t.runningRunId:null}),e&&(eo.current=0,el(e=>e+1))}finally{eu.current=!1,S(!1)}}},[r]),eA=(0,i.useCallback)(async()=>{if(!eh.current&&null!==ej){eh.current=!0,B(!0),V(null);try{let e=await iK(r,ej.id);K("running"===e.status?ej.id:null)}catch(e){V({kind:409===(e instanceof iD?e.status:0)?"gone":"error",message:d7(e,"Failed to cancel the verification run")})}finally{eh.current=!1,B(!1),eo.current=0,el(e=>e+1)}}},[r,ej]),eM=(0,i.useCallback)(async()=>{if(!em.current){em.current=!0,P(!0),F(null);try{let e=await iU(r);z(e),eo.current=0,el(e=>e+1)}catch(t){let e=t instanceof iD?t.status:0;F({kind:409===e?"conflict":422===e?"empty":"error",message:d7(t,"Failed to draft the verification config")}),409===e&&(eo.current=0,el(e=>e+1))}finally{em.current=!1,P(!1)}}},[r]);return{worktreeId:r,task:c,runs:u,latestRun:null!=(a=u[0])?a:null,selectedRunId:eg,selectedRun:x,loading:g,error:v,detailError:j,detailLoading:k,rerunPending:C,rerunFailure:T,config:E,configError:M,phase:u.some(e=>"running"===e.status)?"running":null===E?"unknown":E.exists?0===u.length?"configured":"result":"no-config",draftPending:R,draftFailure:D,draftResult:O,availableGateIds:ev,selectedGateIds:W,failedGateIds:ey,toggleGate:ek,setGateSelection:ew,selectFailedGates:eN,runningRun:ej,cancelPending:_,cancelSettling:null!==U&&(null==ej?void 0:ej.id)===U,cancelFailure:H,historyLimit:q,canLoadMore:u.length>=J&&J<100,repositoryHistoryOpen:Q,repositoryHistory:Z,repositoryHistoryLoading:et,repositoryHistoryError:ea,selectRun:eI,refresh:eT,rerun:eE,cancelRun:eA,loadMore:eC,toggleRepositoryHistory:eS,draftConfig:eM}}({worktreeId:f,refreshToken:F,enabled:!L&&!P});return{activeActivity:e$,activeCliTab:eS,activeInstanceId:eA,activeTab:ng,agentInstances:ex,autoYesEnabled:ez,autoYesExpiresAt:e_,autoYesStateMap:X,diffContent:ta,diffFilePath:tr,disableAutoFollow:tw,displayedAgents:tj,displayedInstances:tv,editorFilePath:W,error:P,fetchCurrentOutput:tf,fileInputRef:nl,fileSearch:ti,fileTreeRefresh:eB,handleActivityOpen:t_,handleActivityToggle:tz,handleAgentInstancesChange:tN,handleAutoYesToggle:tJ,handleBackClick:tB,handleCloseDiff:tl,handleDelete:ne,handleDiffSelect:ts,handleDirtyChange:nw,handleEditorClose:tD,handleEditorSave:tO,handleFileInputChange:nc,handleFilePanelSave:tP,handleFilePathClick:tA,handleFileSelect:tM,handleHistoryDisplayLimitChange:e5,handleHistoryUserOnlyChange:e1,handleInfoClick:tV,handleInfoModalClose:tU,handleInsertConsumed:tt,handleInsertConsumedSingle:tn,handleInsertToMessage:e7,handleInsertToSplit:te,handleKillCancel:t4,handleKillConfirm:t5,openKillConfirm:t1,openActiveKillConfirm:t2,killTarget:tY,isKillPending:tX,handleLoadContent:nv,handleLoadError:ny,handleMessageSent:tq,handleMobileFileViewerClose:tR,handleMobileTabChange:t$,handleMove:na,resetFileTreeView:tF,handleMoveCancel:ns,handleMoveConfirm:nr,handleNewDirectory:t9,handleNewFile:t3,handleNewFileCancel:t8,handleNewFileConfirm:t6,handleOpenFile:tL,handlePromptDismiss:tW,handlePromptRespond:tK,handleRename:t7,handleRetry:nf,handleSelectedAgentsChange:tk,handleSetLoading:nj,handleShowArchivedChange:eZ,handleUpload:no,handleVibeLocalContextWindowChange:tS,rosterReady:ey,handleVibeLocalModelChange:tC,handleWorktreeStatusChange:tH,hasUpdate:nu,historyDisplayLimit:e2,historySubTab:eJ,historyUserOnly:e0,isEditorMaximized:J,isInfoModalOpen:_,isMobile:g,isMoveDialogOpen:nn,isSelectionListActive:er,isPagerActive:ei,lastAutoResponse:nh,loading:L,makeAutoYesToggleHandler:tG,mobileFileViewerPath:U,mobileSelectedAgents:ty,moveTarget:nt,newFileParentPath:eK,openMobileDrawer:v,pendingInsertText:e8,pendingInsertTextMap:e6,selectedAgents:em,setActiveCliTab:eI,setActiveInstanceId:eL,setEditorFilePath:$,setFocusedSplitIndex:e9,setHistorySubTab:eY,setIsEditorMaximized:Y,setWorktree:M,showArchived:eQ,showNewFileDialog:eV,showToast:tI,state:y,tCommon:N,tWorktree:w,tabsActions:V,tabsState:H,toggleInstanceVisible:tb,vibeLocalContextWindow:ek,verification:nk,vibeLocalModel:ej,visibleInstanceIds:tg,worktree:A,worktreeName:nb,worktreeStatus:np}}({worktreeId:j}),[tF,tO]=(0,i.useState)(!1),[tz,t_]=(0,i.useState)(null),[tB,tH]=(0,i.useState)(G.wf),tV="terminal"===C&&"chat"===tB,tU=(0,i.useCallback)(e=>{"memo"!==e&&t_(null),eA(e)},[eA]),tK=(0,i.useCallback)(()=>{t_(e=>{var t;return{tab:"verification",token:(null!=(t=null==e?void 0:e.token)?t:0)+1}}),eA("memo")},[eA]),tW=function(e){let{worktreeId:t,active:n}=e,{addListener:a}=(0,rh.xM)(),[r,s]=(0,i.useState)(!1),l=(0,i.useRef)(n);return l.current=n,(0,i.useEffect)(()=>{n&&s(!1)},[n]),(0,i.useEffect)(()=>a(e=>{e.worktreeId===t&&("terminal_snapshot"===e.type||"message"===e.type)&&(l.current||s(!0))}),[a,t]),!n&&r}({worktreeId:j,active:"terminal"===C}),{viewportHeight:t$}=(0,d3.C)(),tq=(0,i.useCallback)(e=>{let t=ui.indexOf(C);if(-1===t)return;let n=t+e;n<0||n>=ui.length||tU(ui[n])},[C,tU]),{ref:tG}=(0,P.hU)({axis:"horizontal",threshold:60,edgeStartZone:32*("terminal"===C),onSwipeLeft:()=>tq(1),onSwipeRight:()=>tq(-1)}),tJ=(0,i.useMemo)(()=>({worktreePath:null==tR?void 0:tR.path,openFile:ec}),[null==tR?void 0:tR.path,ec]);if(e7)return(0,r.jsx)(cx,{});if(B)return(0,r.jsx)(cp,{message:B,onRetry:eK});let tY=(0,q.O6)(T,N,k),tQ=null!=(f=null==ek?void 0:ek.label)?f:tY,tX=null!=(g=null==(t=null!=(p=null==tR||null==(n=tR.sessionStatusByInstance)?void 0:n[N])?p:null==tR||null==(a=tR.sessionStatusByCli)?void 0:a[k])?void 0:t.isRunning)&&g,tZ=null!=(y=null==(l=null!=(v=null==tR||null==(o=tR.sessionStatusByInstance)?void 0:o[N])?v:null==tR||null==(u=tR.sessionStatusByCli)?void 0:u[k])?void 0:l.isProcessing)&&y;return e4?(0,r.jsx)(E,{componentName:"WorktreeDetailRefactored",children:(0,r.jsx)(rO,{onInsertToComposer:eg,children:(0,r.jsx)(nG,{value:tJ,children:(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden",style:{height:null!=t$?"".concat(t$,"px"):"100%"},"data-testid":"mobile-worktree-shell",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(b,{worktreeName:tP,repositoryName:null==tR?void 0:tR.repositoryName,status:tD,gitStatus:null==tR?void 0:tR.gitStatus,onBackClick:X,onMenuClick:ts})}),tE.task&&(0,r.jsx)("div",{className:"flex-shrink-0 border-b border-border bg-surface px-3 py-1.5",children:(0,r.jsx)(dX,{task:tE.task,latestRun:tE.latestRun,latestRunGates:null!==tE.selectedRun&&tE.selectedRun.id===(null==(m=tE.latestRun)?void 0:m.id)?tE.selectedRun.gates:null,onOpen:tK,className:"w-full justify-start"})}),(null==tR?void 0:tR.gitStatus)&&tR.gitStatus.isBranchMismatch&&(0,r.jsx)("div",{className:"z-35 flex-shrink-0",children:(0,r.jsx)(dZ,{isBranchMismatch:tR.gitStatus.isBranchMismatch,currentBranch:tR.gitStatus.currentBranch,initialBranch:tR.gitStatus.initialBranch})}),(0,r.jsxs)("div",{className:"flex-shrink-0 z-30 flex items-center gap-2 px-3 py-1.5 bg-surface-2 border-b border-border",children:[(0,r.jsx)("nav",{className:"flex gap-1 flex-1 min-w-0 overflow-x-auto scrollbar-hide","aria-label":tw("detail.agentInstanceSelection"),children:z.map(e=>{var t,n,a;let s=(0,tC.kA)(null!=(a=null==tR||null==(t=tR.sessionStatusByInstance)?void 0:t[e.id])?a:null==tR||null==(n=tR.sessionStatusByCli)?void 0:n[e.cliTool]),l=tj("status.".concat(s)),i=N===e.id;return(0,r.jsxs)("button",{onClick:()=>td(e.id),className:"flex-shrink-0 whitespace-nowrap min-h-[44px] px-1.5 py-1 font-medium text-xs transition-colors flex items-center gap-1 border-b-2 touch-manipulation ".concat(i?"text-accent-600 dark:text-accent-400 border-accent-500":"text-muted-foreground hover:text-foreground border-transparent"),"aria-current":i?"page":void 0,children:[(0,r.jsx)(h.m,{status:s,size:"sm",label:tw("detail.statusPill",{label:(0,q.sw)(e),status:l})}),(0,q.sw)(e)]},e.id)})}),(0,r.jsx)("button",{type:"button",onClick:()=>tO(!0),className:"flex-shrink-0 flex items-center justify-center min-h-[44px] min-w-[44px] rounded text-muted-foreground hover:text-foreground hover:bg-muted transition-colors touch-manipulation","aria-label":tw("terminal.moreActions"),"data-testid":"mobile-more-actions-button",children:(0,r.jsx)(d.A,{size:18,"aria-hidden":"true"})})]}),(0,r.jsx)("main",{className:"flex-1 min-h-0 overflow-y-auto",ref:tG,children:(0,r.jsx)(cn,{activeTab:C,worktreeId:j,worktree:tR,messages:ty.messages,cliToolId:k,instanceId:N,onFilePathClick:ec,onFileSelect:ed,onWorktreeUpdate:tp,onNewFile:eD,onNewDirectory:eP,onRename:eU,onDelete:ee,onUpload:eq,onMove:eM,onFileTreeReset:tT,refreshTrigger:K,fileSearch:U,showToast:tv,selectedAgents:tn,onSelectedAgentsChange:ul,useInstanceManagement:!0,instances:T,onInstancesChange:J,visibleInstanceIds:tL,onToggleInstanceVisible:tI,vibeLocalModel:tM,onVibeLocalModelChange:eJ,vibeLocalContextWindow:tA,onVibeLocalContextWindowChange:eG,disableAutoFollow:O,historySubTab:e0,onHistorySubTabChange:tf,onDiffSelect:et,onInsertToMessage:eg,showArchived:tg,onShowArchivedChange:e$,historyDisplayLimit:eZ,onHistoryDisplayLimitChange:eu,historyUserOnly:e1,onHistoryUserOnlyChange:em,verification:tE,toolsSubTabRequest:tz,onSurfaceModeChange:tH})}),(0,r.jsxs)("div",{className:"flex-shrink-0 border-t border-border bg-surface z-30",children:[e6&&!tV&&(0,r.jsx)("div",{className:"px-2 pt-1 border-b border-border",children:(0,r.jsx)(eF,{worktreeId:j,cliToolId:k,instanceId:N,onKeysSent:H,showPagerKeys:e8})}),(0,r.jsx)("div",{className:"p-2",children:(0,r.jsx)(uo,{worktreeId:j,onMessageSent:eI,cliToolId:k,instanceId:N,isSessionRunning:tX,isProcessing:tZ,showToast:tv,pendingInsertText:tl,onInsertConsumed:ep,autoYesSlot:(0,r.jsx)(dJ,{enabled:A,expiresAt:M,onToggle:Y,lastAutoResponse:e9,cliToolName:k,inline:!0,showToolName:!1})})})]}),(0,r.jsx)(S,{activeTab:C,onTabChange:tU,hasNewOutput:tW,hasPrompt:ty.prompt.visible,hasUpdate:eQ,inFlow:!0}),!A&&(0,r.jsx)(F,{promptData:ty.prompt.data,visible:ty.prompt.visible,answering:ty.prompt.answering,onRespond:eV,onDismiss:eH,cliToolName:(0,q.oo)(k)}),(0,r.jsx)(es,{open:tF,onClose:()=>tO(!1),onSearch:()=>window.dispatchEvent(new CustomEvent("terminal-search-open")),onEnd:ew,endDisabled:!tX}),(0,r.jsx)(ti,{isOpen:null!==tt,onClose:eE,worktreeId:j,filePath:null!=tt?tt:"",onFileSaved:er,onOpenFile:ec}),(0,r.jsx)("input",{ref:V,type:"file",accept:cH.join(","),onChange:ei,className:"hidden","aria-label":tw("detail.uploadFile")}),(0,r.jsx)(tN.a,{isOpen:null!==ek,onClose:ev,title:tw("session.confirmEnd",{tool:tQ}),size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:tw("session.endWarning")}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:ev,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:tj("cancel")}),(0,r.jsx)("button",{type:"button",onClick:ey,disabled:eN,className:"px-4 py-2 text-sm font-medium rounded-md bg-danger hover:bg-danger/90 text-white disabled:opacity-60 disabled:cursor-not-allowed",children:tj("end")})]})]})}),ta&&(0,r.jsx)(d1,{isOpen:e3,onClose:eL,onConfirm:eR,worktreeId:j,sourcePath:ta.path,sourceType:ta.type}),(0,r.jsx)(d5,{isOpen:tb,parentPath:tr,onConfirm:e_,onCancel:ez})]})})})}):(0,r.jsxs)(nG,{value:tJ,children:[(0,r.jsx)(d4,{worktreeId:j,worktree:tR,worktreeName:tP,worktreeStatus:tD,instances:T,rosterReady:tc,activeInstanceId:N,setActiveInstanceId:td,hasUpdate:eQ,lastAutoResponse:e9,activeActivity:w,onActivityToggle:$,onActivityOpen:W,verification:tE,onBackClick:X,onInfoClick:eh,onWorktreeStatusChange:eY,pendingInsertTextMap:to,setFocusedSplitIndex:tm,handleInsertToSplit:eb,handleInsertConsumed:ex,handleInsertToMessage:eg,autoYesStateMap:L,makeAutoYesToggleHandler:te,showArchived:tg,onShowArchivedChange:e$,historyDisplayLimit:eZ,onHistoryDisplayLimitChange:eu,historyUserOnly:e1,onHistoryUserOnlyChange:em,onMessageSent:eI,onFilePathClick:ec,showToast:tv,tabsState:tS,tabsActions:tk,onLoadContent:eS,onLoadError:eT,onSetLoading:eW,onFilePanelSave:eo,onDirtyChange:en,onOpenFile:eB,diffContent:R,diffFilePath:D,onCloseDiff:Z,fileSearch:U,fileTreeRefresh:K,onFileSelect:ed,onNewFile:eD,onNewDirectory:eP,onRename:eU,onDelete:ee,onUpload:eq,onMove:eM,onFileTreeReset:tT,onDiffSelect:et,onAgentInstancesChange:J,vibeLocalModel:tM,onVibeLocalModelChange:eJ,vibeLocalContextWindow:tA,onVibeLocalContextWindowChange:eG,isInfoModalOpen:e5,onInfoModalClose:ef,onWorktreeUpdate:tp,fileInputRef:V,onFileInputChange:ei,onKillSession:ew,onRequestSessionEnd:ej,killTarget:ek,isKillPending:eN,onKillCancel:ev,onKillConfirm:ey,moveTarget:ta,isMoveDialogOpen:e3,onMoveCancel:eL,onMoveConfirm:eR,showNewFileDialog:tb,newFileParentPath:tr,onNewFileConfirm:e_,onNewFileCancel:ez,killDialogTitle:tw("session.confirmEnd",{tool:tQ}),killDialogWarning:tw("session.endWarning"),cancelLabel:tj("cancel"),endLabel:tj("end")}),_&&(0,r.jsx)(tN.a,{isOpen:!0,onClose:ea,title:_.split("/").pop()||tw("fileViewer.editor"),size:"full",disableClose:e2,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(us,{worktreeId:j,filePath:_,onClose:ea,onSave:er,onMaximizedChange:tx})})})]})});function ud(){let e=(0,s.useParams)().id;return(0,r.jsx)(l.GV,{children:(0,r.jsx)(uc,{worktreeId:e})})}}},e=>{e.O(0,[6481,6809,4909,2770,790,5694,8566,9948,1191,5542,8772,6402,8019,4718,8361,2751,2053,6022,998,8441,1255,7358],()=>e(e.s=20252)),_N_E=e.O()}]);
|