commandmate 0.10.1 → 0.10.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/.env.example +13 -4
- package/.next/BUILD_ID +1 -1
- package/.next/app-build-manifest.json +114 -114
- package/.next/app-path-routes-manifest.json +25 -25
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +9 -9
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_not-found/page_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.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_client-reference-manifest.js +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_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/session/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/start/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/assistant/terminal/route_client-reference-manifest.js +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/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/hooks/claude-done/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/subscriptions/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/push/vapid/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_client-reference-manifest.js +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_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/scan/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/repositories/sync/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/slash-commands/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/worktrees/[id]/auto-yes/route_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/capture/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_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]/interrupt/route_client-reference-manifest.js +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]/prompt-response/route_client-reference-manifest.js +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_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_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_client-reference-manifest.js +1 -1
- package/.next/server/app/api/worktrees/[id]/start-polling/route_client-reference-manifest.js +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_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]/viewed/route_client-reference-manifest.js +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/worktrees/[id]/files/[...path]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/worktrees/[id]/page.js +1 -1
- 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 +25 -25
- package/.next/server/chunks/1068.js +1 -1
- package/.next/server/middleware-manifest.json +5 -5
- package/.next/server/pages/500.html +1 -1
- package/.next/server/pages-manifest.json +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/worktrees/[id]/{page-fe5271b9b3183269.js → page-562c763045f66200.js} +1 -1
- package/.next/trace +10 -10
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +11 -4
- package/dist/cli/utils/env-setup.d.ts +6 -1
- package/dist/cli/utils/env-setup.d.ts.map +1 -1
- package/dist/cli/utils/env-setup.js +6 -1
- package/dist/server/src/lib/git/worktrees.js +14 -12
- package/package.json +1 -1
- /package/.next/static/{dDVU1B2x3rosk-lJ9KDFn → SZPCFMNuIVbWNY8xv93Lf}/_buildManifest.js +0 -0
- /package/.next/static/{dDVU1B2x3rosk-lJ9KDFn → SZPCFMNuIVbWNY8xv93Lf}/_ssgManifest.js +0 -0
package/.next/static/chunks/app/worktrees/[id]/{page-fe5271b9b3183269.js → page-562c763045f66200.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1479],{5235:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>sV});var a,r=n(95155),s=n(20063),l=n(78954),o=n(12115),i=n(67909),c=n(18955),d=n(37772),u=n(3005),m=n(744),h=n(48481),x=n(64269);let f=(0,o.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"};function p(e){let{worktreeName:t,repositoryName:n,status:a,gitStatus:s,onBackClick:l,onMenuClick:o}=e,i=(0,c.c)("common"),d=(0,c.c)("worktree");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":i("back"),className:"p-2 -ml-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(f,{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.jsx)("div",{className:"w-10 flex-shrink-0 flex justify-end",children:o&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:o,"aria-label":i("menu"),className:"p-2 -mr-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(f,{path:g.menu})})})]})})}var b=n(22479),v=n(26983),y=n(59847),j=n(53842),w=n(23327);function k(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 N=[{id:"terminal",labelKey:"tabs.terminal",icon:(0,r.jsx)(b.A,{size:20,"aria-hidden":"true"})},{id:"history",labelKey:"tabs.history",icon:(0,r.jsx)(v.A,{size:20,"aria-hidden":"true"})},{id:"files",labelKey:"tabs.files",icon:(0,r.jsx)(y.A,{size:20,"aria-hidden":"true"})},{id:"memo",labelKey:"tabs.memo",icon:(0,r.jsx)(j.A,{size:20,"aria-hidden":"true"})},{id:"info",labelKey:"tabs.info",icon:(0,r.jsx)(w.A,{size:20,"aria-hidden":"true"})}];function C(e){let{activeTab:t,onTabChange:n,hasNewOutput:a=!1,hasPrompt:s=!1,hasUpdate:l=!1,onSearchParamsChange:i,inFlow:d=!1}=e,u=(0,c.c)("worktree"),m=(0,o.useRef)([]),h=(0,o.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]),x=(0,o.useCallback)(e=>{n(e),null==i||i("memo"===e?"notes":e)},[n,i]),f=(0,o.useCallback)((e,t)=>{var n;let a=null;switch(e.key){case"ArrowRight":case"ArrowDown":a=(t+1)%N.length;break;case"ArrowLeft":case"ArrowUp":a=(t-1+N.length)%N.length;break;case"Home":a=0;break;case"End":a=N.length-1;break;default:return}e.preventDefault(),null==(n=m.current[a])||n.focus(),x(N[a].id)},[x]),g=(0,o.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:N.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:()=>x(e.id),onKeyDown:e=>f(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&&g,"info"===e.id&&l&&(0,r.jsx)(k,{"data-testid":"info-update-badge",className:"absolute top-1 right-1","aria-label":u("tabs.updateAvailable")})]},e.id))})}class S extends o.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)(T,{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 T(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 E={fadeIn:"animate-fade-in",fadeOut:"animate-fade-out",none:""};function I(e){let{visible:t,duration:n=200}=e,[a,r]=(0,o.useState)(t?"visible":"hidden"),s=(0,o.useRef)(null),l=(0,o.useRef)(t);(0,o.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),(0,o.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 i="hidden"!==a,c="fade-in"===a||"fade-out"===a;return{shouldRender:i,animationClass:(0,o.useMemo)(()=>{switch(a){case"fade-in":return E.fadeIn;case"fade-out":return E.fadeOut;default:return E.none}},[a]),isAnimating:c}}var M=n(92539),L=n(8269);let A={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"},P=(0,o.memo)(function(e){let{promptData:t,visible:n,answering:a,onRespond:s,onDismiss:l,cliToolName:i}=e,{shouldRender:c,animationClass:d}=I({visible:n&&null!==t,duration:300}),u=(0,o.useId)(),m=n&&null!==t,h=(0,M.r)({active:m}),[x,f]=(0,o.useState)(0);(0,o.useEffect)(()=>{n||f(0)},[n]);let g=(0,o.useCallback)(e=>{let{deltaY:t}=e;f(t>0?t:0)},[]),p=(0,o.useCallback)(()=>{null==l||l()},[l]),b=(0,o.useCallback)(()=>{f(0)},[]),{ref:v}=(0,L.hU)({axis:"vertical",threshold:100,enabled:m,onSwipeMove:g,onSwipeDown:p,onSwipeEnd:b}),y=(0,o.useCallback)(e=>{h.current=e,v.current=e},[h,v]),j=(0,o.useCallback)(()=>{l&&l()},[l]),w=(0,o.useCallback)(e=>{e.stopPropagation()},[]);if(!c||!t)return null;let k="animate-fade-out"===d;return(0,r.jsxs)(S,{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:x>0?"translateY(".concat(x,"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)(R,{promptData:t,answering:a,onRespond:s,labelId:u,cliToolName:i})})]})]})});function R(e){let{promptData:t,answering:n,onRespond:a,labelId:s,cliToolName:l}=e,i=(0,c.c)("prompt"),[d,u]=(0,o.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,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(!1),p=(0,o.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===d))?e:null},[t,d]),b=(null==p?void 0:p.requiresTextInput)===!0,v=n||f,y=(0,o.useCallback)(async e=>{if(!v){g(!0);try{await a(e)}catch(e){}finally{g(!1)}}},[v,a]),j=(0,o.useCallback)(async()=>{if(!v&&null!==d){g(!0);try{let e=b&&h.trim()?h.trim():d.toString();await a(e)}catch(e){}finally{g(!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?i("confirmationFrom",{toolName:l}):i("confirmationFromClaude")}),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:i("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(D,{promptData:t,disabled:v,onYes:()=>y("yes"),onNo:()=>y("no")}),"multiple_choice"===t.type&&(0,r.jsx)(F,{promptData:t,disabled:v,selectedOption:d,onSelectOption:u,textInputValue:h,onTextInputChange:x,showTextInput:b,onSubmit:j})]})}let D=(0,o.memo)(function(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),o="yes"===t.defaultOption,i="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(A.base," ").concat(A.primary," ").concat(o?"ring-2 ring-accent-300":""),children:l("yes")}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:n,className:"flex-1 ".concat(A.base," ").concat(i?A.defaultSelected:A.secondary),children:l("no")})]})}),F=(0,o.memo)(function(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:i,showTextInput:d,onSubmit:u}=e,h=(0,o.useId)(),x=(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:x("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:x("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:x("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>i(e.target.value),disabled:n,placeholder:x("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(A.base," ").concat(A.primary),children:x("submit")})]})});var z=n(86651),O=n(84926);function _(e){let{open:t,onClose:n,onSearch:a,onEnd:s,endDisabled:l=!1}=e,i=(0,c.c)("worktree"),d=(0,o.useId)(),u=(0,M.r)({active:t}),m=(0,o.useCallback)(()=>{a(),n()},[a,n]),h=(0,o.useCallback)(()=>{s(),n()},[s,n]);return((0,o.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:i("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)(z.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),i("terminal.searchTerminal")]}),(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)(O.A,{size:18,"aria-hidden":"true"}),i("terminal.endSession")]})]})]})]}):null}var B=n(80344),W=n(79651);function H(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 V(e){return"codex-skill"===e.source?"$".concat(e.name):"/".concat(e.name)}function U(e,t){var n;return e.descriptionKey?t(e.descriptionKey):null!=(n=e.description)?n:""}function K(e){let{groups:t,onSelect:n,highlightedIndex:a=-1,className:s=""}=e,l=(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:l("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 i=s===a;return(0,r.jsxs)("button",{type:"button","data-command-item":!0,"data-highlighted":i,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(i?"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:V(e)}),(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"}),(0,r.jsx)("span",{className:"text-muted-foreground text-sm truncate",children:U(e,l)})]},e.name)})})]},e.category))})}let $=(0,o.memo)(function(e){let{isOpen:t,groups:n,onSelect:a,onClose:s,isMobile:l=!1,position:i,onFreeInput:d}=e,[u,m]=(0,o.useState)(""),[h,x]=(0,o.useState)(0),f=(0,o.useRef)(null),g=(0,c.c)("worktree"),p=(0,c.c)("common"),b=(0,o.useMemo)(()=>H(n,u,e=>U(e,g)),[n,u,g]),v=(0,o.useMemo)(()=>b.flatMap(e=>e.commands),[b]);(0,o.useEffect)(()=>{t&&(m(""),x(0),setTimeout(()=>{var e;null==(e=f.current)||e.focus()},50))},[t]);let y=(0,o.useCallback)(e=>{a(e),s()},[a,s]),j=(0,o.useCallback)(e=>{if(t)switch(e.key){case"Escape":e.preventDefault(),s();break;case"ArrowDown":e.preventDefault(),x(e=>Math.min(e+1,v.length-1));break;case"ArrowUp":e.preventDefault(),x(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),v[h]&&y(v[h])}},[t,v,h,s,y]);return((0,o.useEffect)(()=>{if(t)return document.addEventListener("keydown",j),()=>{document.removeEventListener("keydown",j)}},[t,j]),t)?l?(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:g("slashCommands.title")}),(0,r.jsx)("button",{type:"button",onClick:s,"aria-label":p("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:f,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:g("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(u),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:g("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(K,{groups:b,onSelect:y,highlightedIndex:h,className:"flex-1 overflow-y-auto pb-20"})]})]}):(0,r.jsxs)("div",{role:"listbox",className:"absolute bg-surface border border-border rounded-lg shadow-lg z-50 w-80 max-h-96 flex flex-col",style:i?{top:i.top,left:i.left}:{bottom:"100%",left:0,marginBottom:"4px"},children:[(0,r.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,r.jsx)("input",{ref:f,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:g("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(u),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:g("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(K,{groups:b,onSelect:y,highlightedIndex:h,className:"flex-1 overflow-y-auto"}),(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"})," ",g("slashCommands.selectHint")]}),(0,r.jsxs)("span",{children:[(0,r.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded",children:"Esc"})," ",g("slashCommands.closeHint")]})]})]}):null}),q=(0,o.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disabled:s=!1,onInterrupt:l}=e,i=(0,c.c)("worktree"),[d,m]=(0,o.useState)(!1),h=(0,o.useRef)(0),x=(0,o.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:x,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":i("interrupt.stopProcessing"),"data-testid":"interrupt-button",children:d?(0,r.jsx)(u.y,{size:"md"}):(0,r.jsx)(J,{})})});function J(){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 Y=n(38218),G=n(19985);let X="commandmate:draft-message:",Q="Queued (session busy) — your message will run after the current task finishes.";function Z(e,t){return"".concat(X).concat(e,":").concat(t)}let ee=(0,o.memo)(function(e){let{worktreeId:t,onMessageSent:n,cliToolId:a,instanceId:s,isSessionRunning:l=!1,pendingInsertText:i,onInsertConsumed:d,splitIndex:u=0,onFocus:h,isProcessing:x=!1,showToast:f,autoYesSlot:g,onOptimisticSend:p}=e,b=(0,c.c)("worktree"),[v,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(!1),[k,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(!1),[I,M]=(0,o.useState)(!1),L=(0,o.useRef)(null),A=(0,o.useRef)(null),P=(0,o.useRef)(!1),R=(0,o.useRef)(null),D=(0,o.useRef)(null),F=(0,Y.a)(),{groups:z}=function(e,t){let[n,a]=(0,o.useState)([]),[r,s]=(0,o.useState)(!0),[l,i]=(0,o.useState)(null),[c,d]=(0,o.useState)(""),[u,m]=(0,o.useState)(t||"claude"),h=(0,o.useCallback)(async()=>{try{s(!0),i(null);let n=e?"/api/worktrees/".concat(e,"/slash-commands"):"/api/slash-commands";t&&(n+="?cliTool=".concat(t));let r=await fetch(n);if(!r.ok)throw Error("HTTP error ".concat(r.status));let l=await r.json();a(l.groups),m(l.cliTool||t||"claude")}catch(e){i((0,B.hS)(e)),a([])}finally{s(!1)}},[e,t]);(0,o.useEffect)(()=>{h()},[h]);let x=(0,o.useMemo)(()=>n.flatMap(e=>e.commands),[n]),f=(0,o.useMemo)(()=>H(n,c),[n,c]);return{groups:n,filteredGroups:f,allCommands:x,loading:r,error:l,filter:c,setFilter:d,refresh:(0,o.useCallback)(()=>{h()},[h]),cliTool:u}}(t,a),{attachedImage:O,fileInputRef:_,isUploading:U,error:K,acceptAttribute:J,openFileDialog:ee,handleFileSelect:et,removeAttachment:en,resetAfterSend:ea}=function(e,t){let[n,a]=(0,o.useState)(null),[r,s]=(0,o.useState)(!1),[l,i]=(0,o.useState)(null),c=(0,o.useRef)(null),d=(0,o.useCallback)(()=>{var e;null==(e=c.current)||e.click()},[]),u=(0,o.useCallback)(async n=>{var r;let l=null==(r=n.target.files)?void 0:r[0];if(!l)return;i(null);let o=function(e){let t=e.name.lastIndexOf(".");if(-1===t)return"Unsupported file format";let n=(0,G.HB)(e.name.substring(t));if(!G.Hv.includes(n))return"Unsupported file format: ".concat(n);if(e.size>G.Fg){let e=G.Fg/1024/1024;return"File size exceeds ".concat(e,"MB limit")}return null}(l);if(o){i(o),c.current&&(c.current.value="");return}s(!0);try{let n=await t(e,l);a({file:l,path:n.path})}catch(e){i(e instanceof Error?e.message:"Upload failed")}finally{s(!1),c.current&&(c.current.value="")}},[e,t]),m=(0,o.useCallback)(()=>{a(null),i(null)},[]),h=(0,o.useCallback)(()=>{a(null)},[]);return{attachedImage:n,fileInputRef:c,isUploading:r,error:l,acceptAttribute:G.F5,openFileDialog:d,handleFileSelect:u,removeAttachment:m,resetAfterSend:h}}(t,(0,o.useCallback)((e,t)=>B.y.uploadImageFile(e,t),[]));(0,o.useEffect)(()=>{try{0===u&&function(e){try{let t="".concat(X).concat(e),n=window.localStorage.getItem(t);if(null===n)return;let a=Z(e,0);null===window.localStorage.getItem(a)&&window.localStorage.setItem(a,n),window.localStorage.removeItem(t)}catch(e){}}(t);let e=window.localStorage.getItem(Z(t,u));e?y(e):y("")}catch(e){}return()=>{D.current&&clearTimeout(D.current)}},[t,u]),(0,o.useEffect)(()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{try{let e=Z(t,u);v?window.localStorage.setItem(e,v):window.localStorage.removeItem(e)}catch(e){}},500)},[v,t,u]),(0,o.useEffect)(()=>{let e=L.current;e&&(v?(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px")):e.style.height="24px")},[v]),(0,o.useEffect)(()=>{i&&(y(e=>""===e.trim()?i:e+"\n\n"+i),null==d||d())},[i,d]);let er=(0,o.useCallback)(async()=>{if(C||!v.trim()&&!O||j)return;let e=v.trim(),r=a||"claude",l={cliToolId:r};if(s&&s!==r&&(l.instanceId=s),O&&(l.imagePath=O.path),p){N(null),p(e,l),y(""),M(!1),ea();try{window.localStorage.removeItem(Z(t,u))}catch(e){}x&&(null==f||f(Q,"warning")),null==n||n(r);return}try{w(!0),N(null),await B.y.sendMessage(t,e,l),y(""),M(!1),ea();try{window.localStorage.removeItem(Z(t,u))}catch(e){}x&&(null==f||f(Q,"warning")),null==n||n(r)}catch(e){N((0,B.hS)(e))}finally{w(!1)}},[C,v,O,j,t,a,s,n,ea,u,x,f,p]),es=(0,o.useCallback)(async e=>{e.preventDefault(),await er()},[er]),el=(0,o.useCallback)(()=>{S(!0),P.current=!1,A.current&&clearTimeout(A.current)},[]),eo=(0,o.useCallback)(()=>{S(!1),P.current=!0,A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{P.current=!1},300)},[]),ei=(0,o.useCallback)(e=>{var t;y("".concat(V(e)," ")),E(!1),null==(t=L.current)||t.focus()},[]),ec=(0,o.useCallback)(()=>{var e;E(!1),M(!1),null==(e=L.current)||e.focus()},[]),ed=(0,o.useCallback)(e=>{E(!1),M(!0),y(e?"/".concat(e):"/"),setTimeout(()=>{var e;null==(e=L.current)||e.focus()},50)},[]),eu=(0,o.useCallback)(e=>{let t=e.target.value;if(y(t),""===t){M(!1),E(!1);return}if(I)return;let n="/"===t||t.startsWith("/")&&!t.includes(" "),r="codex"===a&&("$"===t||t.startsWith("$")&&!t.includes(" "));n||r?E(!0):E(!1)},[I,a]),em=(0,o.useCallback)(e=>{let{keyCode:t}=e.nativeEvent;if(229!==t){if("Escape"===e.key&&T){e.preventDefault(),ec();return}if(P.current&&"Enter"===e.key){P.current=!1;return}if("Enter"===e.key&&!C&&(!T||I)){if(F)return;e.shiftKey||(e.preventDefault(),er())}}},[T,I,C,F,er,ec]);return(0,r.jsxs)("div",{ref:R,className:"space-y-2 relative","data-testid":"message-input-container",children:[(k||K)&&(0,r.jsx)("div",{className:"p-2 bg-danger-subtle border border-danger-border rounded text-sm text-danger-foreground",children:k||K}),O&&(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:O.file.name}),(0,r.jsx)("button",{type:"button",onClick:en,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:_,type:"file",accept:J,onChange:et,className:"hidden","data-testid":"image-file-input"}),(0,r.jsxs)("form",{onSubmit:es,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:()=>{I&&M(!1),E(!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:ee,disabled:U||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:U?(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)(q,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l})]}),!F&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:ee,disabled:U||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:U?(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:L,"data-testid":"message-input-textarea",value:v,onChange:eu,onKeyDown:em,onCompositionStart:el,onCompositionEnd:eo,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)(q,{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()||!!O)&&!j),disabled:!v.trim()&&!O||j,className:"flex-shrink-0 p-2 rounded-full transition-colors disabled:hover:bg-transparent ".concat((v.trim()||O)&&!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"})})})]})]}),(g||!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:g}),!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)(W.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)(W.u,{children:"⇧"}),(0,r.jsx)(W.u,{children:"↵"}),(0,r.jsx)("span",{children:b("composer.newlineHint")})]})]})]}),(0,r.jsx)($,{isOpen:T,groups:z,onSelect:ei,onClose:ec,isMobile:F,onFreeInput:ed})]})});var et=n(9900);function en(e,t,n,a){return(0,o.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,et.LK)}).catch(e=>{console.error("Failed to send special keys:",e)})},[e,t,n,a])}let ea=[{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"}],er=[{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 es(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s,showPagerKeys:l=!1}=e,i=(0,c.c)("worktree"),[d,u]=(0,o.useState)(null),m=en(t,n,a,s),h=(0,o.useCallback)(e=>{u(e[0]),setTimeout(()=>u(null),et.tX),m(e)},[m]),x=(0,o.useMemo)(()=>l?[...ea,...er]:ea,[l]),f=(0,o.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:f,role:"toolbar","aria-label":i("navigation.toolbarLabel"),children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground mx-2",children:i("navigation.caption")}),x.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?i(s):a,onClick:()=>h([t]),children:n},t)})]})}var el=n(36402),eo=n(17846),ei=n(69264),ec=n(27307),ed=n(11063),eu=n(60322),em=n(65229),eh=n(39867),ex=n(5917),ef=n(51963),eg=n(18514),ep=n(75426),eb=n(97624),ev=n(37354),ey=n(59854),ej=n(76246);let ew={highlightName:"terminal-search",currentHighlightName:"terminal-search-current",fallbackOverlayId:"terminal-search-fallback-overlay",fallbackOverlayBgColor:"rgba(255, 165, 0, 0.6)"},ek={highlightName:"history-search",currentHighlightName:"history-search-current",fallbackOverlayId:"history-search-fallback-overlay",fallbackOverlayBgColor:"rgba(59, 130, 246, 0.6)"};function eN(){return"undefined"!=typeof CSS&&null!==CSS&&"highlights"in CSS}function eC(e,t,n){let a=document.createRange(),r=!1;for(let{node:s,start:l,end:o}of e)if(!r&&t<o&&t>=l&&(a.setStart(s,t-l),r=!0),r&&n<=o)return a.setEnd(s,n-l),a;return r?a:null}function eS(e){var t;eN()&&(CSS.highlights.delete(e.highlightName),CSS.highlights.delete(e.currentHighlightName)),null==(t=document.getElementById(e.fallbackOverlayId))||t.remove()}function eT(e,t,n,a){if(0===t.length)return void eS(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?eC(r,s.start,s.end):null;if(eN()){let e=[];t.forEach((t,a)=>{if(a===n)return;let s=eC(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 eE(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ek;eS(e)}function eI(e){let[t,n]=(0,o.useState)(!1),[a,r]=(0,o.useState)(""),[s,l]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),m=(0,o.useRef)(null),h=(0,o.useRef)(null),x=(0,o.useCallback)(()=>{n(!0),setTimeout(()=>{var e;return null==(e=m.current)?void 0:e.focus()},50)},[]),f=(0,o.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),g=(0,o.useCallback)(()=>{n(!1),r(""),l(""),c([]),u(0),f()},[f]);(0,o.useEffect)(()=>{if(!a||a.length<2){l(""),f();return}return f(),h.current=setTimeout(()=>{l(a)},300),f},[a,f]),(0,o.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 p=(0,o.useCallback)(()=>{0!==i.length&&u(e=>(e+1)%i.length)},[i.length]),b=(0,o.useCallback)(()=>{0!==i.length&&u(e=>(e-1+i.length)%i.length)},[i.length]);return{searchOpen:t,searchQuery:a,searchMatches:i,searchCurrentIdx:d,searchInputRef:m,openSearch:x,closeSearch:g,nextMatch:p,prevMatch:b,setSearchQuery:r}}var eM=n(90487);n(1226);let eL=/^---\s*\nmarp:\s*true/;function eA(e){let{searchInputRef:t,searchQuery:n,searchMatches:a,searchCurrentIdx:s,onQueryChange:l,onPrev:o,onNext:i,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.shiftKey?o():i())},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: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.prevMatch"),children:"▲"}),(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.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)(em.A,{className:"w-4 h-4"})})]})}let eP="\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 eR(e){let{htmlContent:t,filePath:n}=e,[a,s]=(0,o.useState)("preview"),[l,i]=(0,o.useState)("safe"),d=(0,o.useRef)(new Set),u=(0,c.c)("worktree"),m=(0,el.SC)(),h=(0,o.useCallback)(async e=>{if("interactive"===e&&!d.current.has(n)){if(!await m({description:u("htmlPreview.interactiveModeConfirm")}))return;d.current.add(n)}i(e)},[n,m,u]),x=(0,o.useMemo)(()=>"interactive"!==l?t:t.includes("</body>")?t.replace("</body>","".concat(eP,"</body>")):t+eP,[t,l]);(0,o.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 f=(0,o.useMemo)(()=>{try{return eM.A.highlight(t,{language:"html",ignoreIllegals:!0}).value}catch(e){return eM.A.highlightAuto(t).value}},[t]),g=(0,o.useMemo)(()=>Array.from({length:t.split("\n").length},(e,t)=>t+1),[t]),p=(0,o.useMemo)(()=>f.split("\n"),[f]);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:g.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=p[n])?t:""}})})})]},e)})})}):(0,r.jsx)("iframe",{srcDoc:x,sandbox:ed.Ko[l],title:u("htmlPreview.title",{path:n}),className:"w-full h-full border-0 bg-white"},"".concat(n,"-").concat(l))})]})}let eD=(0,o.memo)(function(e){let{isOpen:t,onClose:n,worktreeId:a,filePath:s,onEditMarkdown:l}=e,[i,d]=(0,o.useState)(null),[u,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),[b,v]=(0,o.useState)(!1),[y,j]=(0,o.useState)(null),[w,k]=(0,o.useState)(0),[N,C]=(0,o.useState)(!1),S=(0,o.useRef)(null),T=(0,c.c)("worktree"),{searchOpen:E,searchQuery:I,searchMatches:M,searchCurrentIdx:L,searchInputRef:A,openSearch:P,closeSearch:R,nextMatch:D,prevMatch:F,setSearchQuery:O}=eI(null==i?void 0:i.content),_=(0,o.useMemo)(()=>!!((null==i?void 0:i.content)&&!i.isImage&&!i.isVideo&&!i.isPdf),[i]),B=(0,o.useCallback)(async()=>{if(_&&(null==i?void 0:i.content))try{await (0,eu.l)(i.content),p(!0),setTimeout(()=>p(!1),et.pX)}catch(e){}},[_,i]),W=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s),v(!0),setTimeout(()=>v(!1),et.pX)}catch(e){}},[s]),H=(0,o.useCallback)(()=>{C(e=>!e)},[]);(0,o.useEffect)(()=>{if(0===M.length||!S.current)return;let e=M[L],t=S.current.querySelector('[data-line="'.concat(e,'"]'));t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"})},[L,M]),(0,o.useEffect)(()=>{if(!N)return;let e=e=>{"Escape"===e.key&&C(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[N]),(0,o.useEffect)(()=>{if(!t||!s){d(null),f(null),p(!1),R();return}(async()=>{h(!0),f(null);try{let t=await fetch("/api/worktrees/".concat(a,"/files/").concat((0,ej.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)||T("fileViewer.loadError");throw Error(a)}let n=await t.json();d(n)}catch(e){f(e instanceof Error?e.message:T("fileViewer.loadError"))}finally{h(!1)}})()},[t,a,s]),(0,o.useEffect)(()=>{j(null),k(0),i&&"md"===i.extension&&eL.test(i.content)&&!(i.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:i.content})});if(e.ok){let t=await e.json();j(t.slides)}}catch(e){}})()},[i,a]);let V=!!(y&&y.length>0),U=(null==i?void 0:i.extension)==="md",K=(0,o.useCallback)(()=>{l&&s&&(n(),l(s))},[l,s,n]),$=(0,o.useMemo)(()=>{if(!i||i.isImage||i.isVideo||i.isHtml||i.isPdf||V&&y)return null;let e=Array.from({length:i.content.split("\n").length},(e,t)=>t+1);try{return{lineNumbers:e,highlightedHtml:eM.A.highlight(i.content,{language:i.extension,ignoreIllegals:!0}).value}}catch(t){return{lineNumbers:e,highlightedHtml:eM.A.highlightAuto(i.content).value}}},[i,V,y]),q=()=>{if(!i)return null;if(i.isImage)return(0,r.jsx)(eo.a,{src:i.content,alt:i.path,mimeType:i.mimeType});if(i.isVideo)return(0,r.jsx)(ei.u,{src:i.content,mimeType:i.mimeType});if(i.isPdf)return(0,r.jsx)("div",{className:"h-full min-h-[40vh]",children:(0,r.jsx)(ec.PdfPreview,{dataUri:i.content,filePath:s,variant:"download"})});if(i.isHtml)return(0,r.jsx)(eR,{htmlContent:i.content,filePath:s});if(V&&y)return(0,r.jsxs)("div",{className:"flex 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:()=>k(e=>Math.max(0,e-1)),disabled:0===w,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:T("actions.prev")}),(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[w+1," / ",y.length]}),(0,r.jsx)("button",{type:"button",onClick:()=>k(e=>Math.min(y.length-1,e+1)),disabled:w===y.length-1,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:T("actions.next")})]}),(0,r.jsx)("iframe",{srcDoc:y[w],sandbox:"",title:T("fileViewer.slideTitle",{name:s,number:w+1}),className:"w-full border-0",style:{height:N?"calc(100vh - 100px)":"50vh"}})]});if(!$)return null;let e=new Set(M),t=M.length>0?M[L]:-1,n=$.highlightedHtml.split("\n");return(0,r.jsx)("div",{ref:S,children:(0,r.jsx)("table",{className:"text-sm w-full border-collapse",children:(0,r.jsx)("tbody",{children:$.lineNumbers.map(a=>{var s;let l=a-1,o=a===t,i=e.has(a);return(0,r.jsxs)("tr",{"data-line":a,className:o?"bg-warning/30":i?"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(o||i?"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)})})})})},J="/api/worktrees/".concat(a,"/files/").concat((0,ej.o)(s),"?download=1"),Y=s?s.split("/").pop()||s:"",G=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return(0,r.jsxs)("a",{"data-testid":"download-file-button",href:J,download:Y,className:e,"aria-label":T("actions.downloadFile"),title:T("actions.download"),children:[(0,r.jsx)(eh.A,{className:"w-3.5 h-3.5"}),t&&(0,r.jsx)("span",{children:T("actions.download")})]})},X=()=>(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:W,className:"flex-shrink-0 p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.copyFilePath"),title:T("actions.copyPath"),children:b?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:[_&&(0,r.jsx)("button",{onClick:P,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.searchInFile"),title:T("actions.search"),children:(0,r.jsx)(z.A,{className:"w-3.5 h-3.5"})}),U&&l&&(0,r.jsx)("button",{onClick:K,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.editFile"),title:T("actions.edit"),children:(0,r.jsx)(eg.A,{className:"w-3.5 h-3.5"})}),_&&(0,r.jsx)("button",{"data-testid":"copy-content-button",onClick:B,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.copyFileContent"),title:T("actions.copyContent"),children:g?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ep.A,{className:"w-3.5 h-3.5"})}),G("p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground"),(0,r.jsx)("button",{onClick:H,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":N?T("actions.exitFullscreen"):T("actions.fullscreen"),title:N?T("actions.exitFullscreen"):T("actions.fullscreen"),children:N?(0,r.jsx)(eb.A,{className:"w-3.5 h-3.5"}):(0,r.jsx)(ev.A,{className:"w-3.5 h-3.5"})})]})]});return N&&i&&!u&&!x?(0,r.jsxs)("div",{className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:ey.M.MAXIMIZED_EDITOR},children:[X(),E&&(0,r.jsx)(eA,{searchInputRef:A,searchQuery:I,searchMatches:M,searchCurrentIdx:L,onQueryChange:O,onPrev:F,onNext:D,onClose:R}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:q()})]}):(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:[u&&(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:T("fileViewer.loading")})]}),x&&(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:x})]}),(0,r.jsx)("div",{className:"mt-3",children:G("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)})]}),i&&!u&&!x&&(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:[X(),E&&(0,r.jsx)(eA,{searchInputRef:A,searchQuery:I,searchMatches:M,searchCurrentIdx:L,onQueryChange:O,onPrev:F,onNext:D,onClose:R})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:q()})]})]})})});var eF=n(46892),ez=n(41898),eO=n(26232),e_=n(50857),eB=n(94442);function eW(e){let{worktreeId:t}=e,[n,a]=(0,o.useState)([]),[s,l]=(0,o.useState)(null),[i,d]=(0,o.useState)(null),[u,h]=(0,o.useState)(!0),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(""),[v,y]=(0,o.useState)(0),[j,w]=(0,o.useState)("all"),[k,N]=(0,o.useState)(!1),{toasts:C,showToast:S,removeToast:T}=(0,eB.dj)(),E=(0,c.c)("worktree");(0,o.useEffect)(()=>{(async()=>{try{h(!0),g(null);let e=await B.y.getLogs(t);a(e)}catch(e){g((0,B.hS)(e))}finally{h(!1)}})()},[t]);let I=(0,o.useMemo)(()=>"all"===j?n:n.filter(e=>e.toLowerCase().includes(j)),[n,j]),M=async e=>{try{h(!0),g(null);let n=await B.y.getLogFile(t,e);d(n.content),l(e),b(""),y(0)}catch(e){g((0,B.hS)(e))}finally{h(!1)}},L=(0,o.useCallback)(async()=>{if(s)try{N(!0);let e=await B.y.getLogFile(t,s,{sanitize:!0});await (0,eu.l)(e.content),S(E("logViewer.copied"),"success")}catch(e){S(E("logViewer.exportError",{error:(0,B.hS)(e)}),"error")}finally{N(!1)}},[t,s,S,E]),A=(0,o.useMemo)(()=>{let e;if(!p||!i)return[];let t=RegExp((0,x.Nt)(p),"gi"),n=[];for(;null!==(e=t.exec(i));)n.push({index:e.index,length:e[0].length});return n},[p,i]);(0,o.useEffect)(()=>{y(0)},[p]);let P=()=>{A.length>0&&y(e=>(e+1)%A.length)},R=()=>{A.length>0&&y(e=>(e-1+A.length)%A.length)},D=(0,o.useMemo)(()=>{if(!i||!p||0===A.length)return i;let e="",t=0;return A.forEach((n,a)=>{e+=(0,x.ZD)(i.substring(t,n.index));let r=i.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)(i.substring(t))},[i,p,A,v]);return(0,o.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:E("logViewer.title")}),(0,r.jsx)(m.Ex,{variant:"gray",children:I.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:E("logViewer.all",{count:n.length})}),(0,r.jsx)(m.$n,{variant:"claude"===j?"primary":"ghost",size:"sm",onClick:()=>w("claude"),children:E("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:E("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:E("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:E("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===I.length&&!f&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground text-center py-4",children:"all"===j?E("logViewer.empty"):E("logViewer.emptyFiltered",{tool:j})}),I.length>0&&(0,r.jsx)("div",{className:"space-y-2",children:I.map(e=>(0,r.jsx)("button",{onClick:()=>M(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:L,disabled:!s||k,title:E("logViewer.copyTitle"),children:k?E("logViewer.exporting"):E("logViewer.export")}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:()=>{l(null),d(null),b(""),y(0)},children:E("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:p,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?R():P())},placeholder:E("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:R,disabled:0===A.length,title:E("logViewer.prevMatch"),children:"↑"}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:P,disabled:0===A.length,title:E("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&&i&&(0,r.jsx)("div",{className:"bg-[#111827] text-[#f3f4f6] rounded p-4 overflow-x-auto max-h-[500px] scrollbar-thin",children:p&&A.length>0?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:D||""}}):(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",children:i})}),!u&&p&&0===A.length&&i&&(0,r.jsx)("div",{className:"text-center py-4 text-sm text-muted-foreground",children:E("logViewer.noMatches",{query:p})})]})]}),(0,r.jsx)(eB.N9,{toasts:C,onClose:T})]})}function eH(){let[e,t]=(0,o.useState)(null),[n,a]=(0,o.useState)(!0),[r,s]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let e=!1;return async function(){try{a(!0),s(null);let n=await B.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 eV=n(31166);let eU="commandmate update";function eK(e){let{hasUpdate:t,latestVersion:n,releaseUrl:a,updateCommand:s,installType:l}=e,i=(0,c.c)("worktree"),[d,m]=(0,o.useState)("idle"),[h,x]=(0,o.useState)(null),[f,g]=(0,o.useState)(null),p=(0,o.useRef)(!1),b="global"===l,v=(0,o.useCallback)(async()=>{m("starting");try{let e=await B.GQ.startUpdate();x(e.logPath),m(e.willRestart?"updating":"no-restart")}catch(e){e instanceof B.hD&&400===e.status?g(i("update.errorNotGlobal")):e instanceof B.hD&&409===e.status?g(i("update.errorInProgress")):g(i("update.errorGeneric")),m("error")}},[i]);return((0,o.useEffect)(()=>{if("updating"!==d)return;let e=!1,t=Date.now();p.current=!1;let n=setInterval(async()=>{if(e)return;if(Date.now()-t>3e5)return void m("timeout");let n=await B.GQ.ping();if(!e){if(!n){p.current=!0;return}p.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":i("update.available"),"data-testid":"update-notification-banner",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800 mb-1",children:i("update.available")}),n&&(0,r.jsx)("p",{className:"text-sm text-accent-700 mb-2",children:i("update.latestVersion",{version:n})}),b&&"idle"===d&&(0,r.jsx)(eV.$,{variant:"primary",size:"sm",className:"mb-2",onClick:()=>m("confirming"),"data-testid":"update-now-button",children:i("update.updateNow")}),("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?i("update.starting"):i("update.updating")]}),"updating"===d&&(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:i("update.noRestartTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:i("update.timeoutTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:eU})]}),"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:i("update.errorTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:f}),(0,r.jsx)("code",{className:"block bg-accent-100 rounded px-2 py-1 mt-1 text-xs text-accent-900 font-mono",children:eU})]}),h&&("no-restart"===d||"timeout"===d)&&(0,r.jsx)("p",{className:"text-xs text-accent-500 mb-2","data-testid":"update-log-hint",children:i("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:i("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:[i("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:i("update.dataPreserved")}),(0,r.jsx)(el.TM,{isOpen:"confirming"===d,title:i("update.confirmTitle"),description:i("update.confirmDescription",{version:null!=n?n:""}),confirmLabel:i("update.confirmButton"),onConfirm:v,onCancel:()=>m("idle")})]}):null}function e$(e){let{version:t,className:n}=e,a=(0,c.c)("worktree"),{data:s,loading:l}=eH(),i=(0,o.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:"..."}),i&&(0,r.jsx)(eK,{...i})]})}let eq="https://github.com/Kewton/CommandMate",eJ="".concat(eq,"/issues"),eY="".concat(eq,"/issues/new"),eG="".concat(eY,"?template=bug_report.md"),eX="".concat(eY,"?template=feature_request.md"),eQ="".concat(eY,"?template=question.md");function eZ(e){let{className:t}=e,n=(0,c.c)("worktree"),a=[{href:eG,label:n("feedback.bugReport")},{href:eX,label:n("feedback.featureRequest")},{href:eQ,label:n("feedback.question")},{href:eJ,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 e0=n(94465),e1=n(55142),e2=n(54014),e4=n(24033);let e5="application/x-commandmate-agent-instance",e3=(0,o.memo)(function(e){let{splitIndex:t,cliToolId:n,instanceId:a,instance:s,availableInstances:l,onInstanceChange:i,status:d="idle",onFocus:u,attaching:m=!1,headerExtras:x,terminal:f,footer:g,style:p,onDropInstance:b,draggedInstanceId:v}=e,y=(0,c.c)("worktree"),[j,w]=(0,o.useState)(null),k=null!=b,N=(0,o.useCallback)(()=>null==v||l.some(e=>e.id===v)?"allowed":"forbidden",[v,l]),C=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault();let t=N();e.dataTransfer.dropEffect="forbidden"===t?"none":"move",w(e=>e===t?e:t)},[k,N]),S=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault();let t=N();w(e=>e===t?e:t)},[k,N]),T=(0,o.useCallback)(()=>{k&&w(null)},[k]),E=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault(),w(null);let t=e.dataTransfer.getData(e5);t&&(null==b||b(t))},[k,b]),I=(0,o.useCallback)(()=>{window.dispatchEvent(new CustomEvent("terminal-search-open"))},[]),M=(0,o.useCallback)(()=>{u()},[u]),L="Terminal split ".concat(t+1),A=(0,e2.sw)(null!=s?s:{cliTool:n}),P=y("terminal.selectInstance",{split:L});return(0,r.jsxs)("div",{role:"region","aria-label":L,"data-testid":"terminal-split-pane-".concat(t),"data-split-index":t,style:p,className:"flex flex-col min-w-0 h-full rounded-lg overflow-hidden border border-border bg-surface".concat(null===j?" focus-within:ring-1 focus-within:ring-accent-500/30":"").concat("allowed"===j?" ring-2 ring-accent-400":"forbidden"===j?" ring-2 ring-red-300 cursor-not-allowed":""),onFocusCapture:M,onMouseDown:u,onDragOver:C,onDragEnter:S,onDragLeave:T,onDrop:E,children:[(0,r.jsxs)("div",{className:"px-2 py-1 flex items-center gap-2 bg-surface-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)(eO.rI,{children:[(0,r.jsxs)(eO.ty,{"data-testid":"cli-selector-".concat(t),"aria-label":P,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:d,size:"sm","aria-hidden":!0,"data-testid":"split-status-indicator-".concat(t)}),(0,r.jsx)("span",{className:"truncate",children:A}),(0,r.jsx)(e4.A,{size:14,"aria-hidden":"true",className:"flex-shrink-0 opacity-70"})]}),(0,r.jsx)(eO.SQ,{align:"start",className:"min-w-[10rem]",children:(0,r.jsx)(eO.Hr,{value:a,onValueChange:i,children:l.map(e=>(0,r.jsx)(eO.Ht,{value:e.id,children:(0,e2.sw)(e)},e.id))})})]}),x,(0,r.jsx)("button",{type:"button",onClick:I,"aria-label":"Search terminal output for ".concat(L),"data-testid":"terminal-search-button-".concat(t),className:"ml-auto 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"})})})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[m?(0,r.jsxs)("div",{"data-testid":"terminal-attach-skeleton-".concat(t),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 ",A," session..."]}):null,f]}),(0,r.jsx)("div",{className:"flex-shrink-0 border-t border-border p-2 bg-surface-2",children:g})]})});var e6=n(34681),e8=n(20562),e9=n(8803),e7=n(46980),te=n.n(e7),tt=n(62459);let tn=new(n.n(tt)())({fg:"#d1d5db",bg:"#1f2937",newline:!0,escapeXML:!0});function ta(e){let t=e.replace(/\0/g,"");t.length>1048576&&(t=t.slice(0,1048576));let n=tn.toHtml(t);return te().sanitize(n,{ALLOWED_TAGS:["span","br"],ALLOWED_ATTR:["style"],ALLOW_DATA_ATTR:!1})}let tr=/\x1b(?:\[[0-9;?]*)?$/,ts=/\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07]*\x07|\[[0-9;]*m/g;function tl(e){return""===e.replace(ts,"").trim()}function to(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:c,isAtMaxMatches:d=!1}=e,u=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=u.current)||e.focus()},[]);let m=(0,o.useCallback)(e=>{"Escape"===e.key&&c()},[c]),h=(0,o.useCallback)(e=>{n(e.target.value)},[n]),x=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:x}),(0,r.jsx)("button",{onClick:i,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:"✕"})]})}function ti(){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 tc=(0,o.memo)(function(e){let{output:t,isActive:n,attaching:a=!1,isThinking:s=!1,autoScroll:l=!0,onScrollChange:i,disableAutoFollow:c=!1,compactTuiLayoutPadding:d=!1,className:u=""}=e,{scrollRef:m,autoScroll:h,handleScroll:x,scrollToBottom:f,scrollToTop:g}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{initialAutoScroll:t=!0,onAutoScrollChange:n}=e,a=(0,o.useRef)(null),[r,s]=(0,o.useState)(t),l=(0,o.useRef)(!1),i=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]);let c=(0,o.useCallback)(e=>{s(e),null==n||n(e)},[n]),d=(0,o.useCallback)(()=>{let e=a.current;if(!e)return!0;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;return n-r-t<=50},[]),u=(0,o.useCallback)(()=>{if(l.current)return;let e=d();e&&!r?c(!0):!e&&r&&c(!1)},[r,d,c]),m=(0,o.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),r||c(!0),i.current=setTimeout(()=>{l.current=!1,i.current=null},500))},[r,c]),h=(0,o.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:0,behavior:"smooth"}),r&&c(!1),i.current=setTimeout(()=>{l.current=!1,i.current=null},500))},[r,c]);return{scrollRef:a,autoScroll:r,setAutoScroll:c,scrollToBottom:m,scrollToTop:h,handleScroll:u}}({initialAutoScroll:l,onAutoScrollChange:i}),p=null!=t?t:"",b=(0,o.useMemo)(()=>d?function(e){if(""===e)return"";let t=e.split("\n"),n=[],a=!1,r=0;for(;r<t.length;){if(!tl(t[r])){n.push(t[r]),a=!0,r++;continue}let e=r;for(;e<t.length&&tl(t[e]);)e++;let s=e-r,l=!a,o=e>=t.length;if(!l&&!o)if(s<=2)for(let a=r;a<e;a++)n.push(t[a]);else n.push(function(e){let t=e.match(ts);return t?t.join(""):""}(t.slice(r,e).join("")));r=e}return n.join("\n")}(p):p,[d,p]),{isOpen:v,query:y,matchCount:j,currentIndex:w,isAtMaxMatches:k,openSearch:N,closeSearch:C,setQuery:S,nextMatch:T,prevMatch:E}=function(e){let{output:t,containerRef:n}=e,[a,r]=(0,o.useState)(!1),[s,l]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),[m,h]=(0,o.useState)(!1),x=(0,o.useRef)(null),f=(0,o.useRef)(""),g=i.length,p=(0,o.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 o=s.length>=500&&-1!==a.indexOf(r,l);return{positions:s,capped:o}},[n]),b=(0,o.useCallback)(e=>{let{positions:t,capped:a}=p(e);if(c(t),u(0),h(a),n.current)if(t.length>0){var r;r=n.current,eT(r,t,0,ew)}else eS(ew)},[p,n]),v=(0,o.useCallback)(e=>{l(e),x.current&&clearTimeout(x.current),f.current=e,x.current=setTimeout(()=>{b(e)},300)},[b]),y=(0,o.useCallback)(()=>{r(!0)},[]),j=(0,o.useCallback)(()=>{r(!1),l(""),f.current="",c([]),u(0),h(!1),x.current&&clearTimeout(x.current),eS(ew)},[]),w=(0,o.useCallback)(()=>{0!==g&&u(e=>{let t=(e+1)%g;return n.current&&i.length>0&&eT(n.current,i,t,ew),t})},[g,i,n]),k=(0,o.useCallback)(()=>{0!==g&&u(e=>{let t=(e-1+g)%g;return n.current&&i.length>0&&eT(n.current,i,t,ew),t})},[g,i,n]);return(0,o.useEffect)(()=>{f.current.length<2||b(f.current)},[t,b]),(0,o.useEffect)(()=>()=>{x.current&&clearTimeout(x.current),eS(ew)},[]),{isOpen:a,query:s,matchCount:g,currentIndex:d,isAtMaxMatches:m,openSearch:y,closeSearch:j,setQuery:v,nextMatch:w,prevMatch:k}}({output:b,containerRef:m}),I=(0,o.useCallback)(e=>{(e.ctrlKey||e.metaKey)&&"f"===e.key&&(e.preventDefault(),N())},[N]);(0,o.useEffect)(()=>{let e=()=>N();return window.addEventListener("terminal-search-open",e),()=>window.removeEventListener("terminal-search-open",e)},[N]);let[M,L]=(0,o.useState)(()=>b?[{key:0,html:ta(b)}]:[]),A=(0,o.useRef)(b),P=(0,o.useRef)(0);(0,o.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(tr),a=n?e.length-n[0].length:e.length;return{mode:"append",text:t,appended:t.slice(a),retainedLength:a}}(A.current,b);if(A.current=b,"noop"!==e.mode){if("append"===e.mode)return void L(t=>(P.current+=1,t.length>=400)?[{key:P.current,html:ta(b)}]:[...t,{key:P.current,html:ta(e.appended)}]);P.current+=1,L(b?[{key:P.current,html:ta(b)}]:[])}},[b]);let[R,D]=(0,o.useState)(!1);(0,o.useEffect)(()=>{a?D(!1):n&&D(!0)},[a,n]);let F=!t,z=F&&a,O=F&&!a&&!n&&R,_=(0,o.useRef)(!1);(0,o.useEffect)(()=>{c&&(_.current=!0)},[c]),(0,o.useEffect)(()=>{if(m.current){if(_.current&&c&&b){m.current.scrollTo({top:0,behavior:"instant"}),_.current=!1;return}!c&&h&&m.current.scrollTo({top:m.current.scrollHeight,behavior:"instant"})}},[M,b,h,c,m]);let B=(0,o.useMemo)(()=>["terminal","font-mono","text-sm","p-4","rounded-lg","overflow-y-auto","overflow-x-hidden","bg-gray-900","text-gray-300","border","border-gray-700","h-full",n?"active":"",u].filter(Boolean).join(" "),[n,u]),[W,H]=(0,o.useState)(!1),V=(0,o.useRef)(null),U=(0,o.useCallback)(()=>{H(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>H(!1),1500)},[]);(0,o.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let K=(0,o.useCallback)(()=>{x(),U()},[x,U]),$=["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",W?"opacity-100":"opacity-60"].join(" ");return(0,r.jsxs)("div",{className:"relative h-full flex flex-col",children:[v&&(0,r.jsx)("div",{className:"absolute top-2 right-2 z-10",children:(0,r.jsx)(to,{query:y,onQueryChange:S,matchCount:j,currentIndex:w,onNext:T,onPrev:E,onClose:C,isAtMaxMatches:k})}),(0,r.jsxs)("div",{ref:m,role:"log","aria-live":"polite","aria-label":"Terminal output",className:B,onScroll:K,onKeyDown:I,tabIndex:0,children:[(0,r.jsx)("div",{className:"whitespace-pre-wrap break-words",children:M.map(e=>(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:e.html}},e.key))}),z&&(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:"読込中..."}),O&&(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)(ti,{})]}),h?(0,r.jsx)("button",{type:"button",onClick:g,className:$,"aria-label":"Scroll to top",children:(0,r.jsx)(e8.A,{size:16,"aria-hidden":"true"})}):(0,r.jsx)("button",{type:"button",onClick:f,className:$,"aria-label":"Scroll to bottom",children:(0,r.jsx)(e9.A,{size:16,"aria-hidden":"true"})})]})});var td=n(9109);function tu(e){let{worktreeId:t,cliToolId:n,instanceId:a,enabled:r=!0}=e,s=null!=a?a:n,[l,i]=(0,o.useState)(()=>({output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,attaching:!0,autoScroll:!0})),[c,d]=(0,o.useState)(()=>({visible:!1,data:null,messageId:null,answering:!1})),u=(0,o.useRef)(0),m=(0,o.useRef)(n);m.current=n;let h=(0,o.useRef)(s);h.current=s;let x=(0,o.useRef)(c.visible);x.current=c.visible;let{connected:f,subscribe:g,unsubscribe:p,addListener:b}=(0,td.xM)(),v=(0,o.useRef)(0),y=(0,o.useRef)(0),j=(0,o.useRef)(null),w=(0,o.useRef)(null),[k,N]=(0,o.useState)(!1),C=(0,o.useCallback)(()=>{N(!0),null!==w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{w.current=null,N(!1)},5e3)},[]),S=(0,o.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?(y.current+=1,null!=j.current||(j.current=Date.now())):(y.current=0,j.current=null);let r=y.current>=2&&null!==j.current&&Date.now()-j.current>=500;i(t=>{var n,s,l,o,i;let c=!1===e.isRunning,d=!!a||!!e.isRunning||c;return{...t,output:d?a:t.output,realtimeSnippet:null!=(n=e.realtimeSnippet)?n:"",isRunning:null!=(s=e.isRunning)&&s,isThinking:null!=(l=e.thinking)&&l,isSelectionListActive:null!=(o=e.isSelectionListActive)&&o,isPagerActive:null!=(i=e.isPagerActive)&&i,isUnclassifiedActive:r,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&&x.current&&d({visible:!1,data:null,messageId:null,answering:!1})},[]),T=(0,o.useCallback)(async()=>{let e=++u.current;try{let a=await fetch("/api/worktrees/".concat(t,"/current-output?cliTool=").concat(n,"&instance=").concat(encodeURIComponent(s)));if(!a.ok)return;let r=await a.json();if(u.current!==e||m.current!==n||h.current!==s||r.cliToolId&&r.cliToolId!==n)return;S(r)}catch(t){if(u.current!==e||m.current!==n||h.current!==s)return;console.error("[useTerminalPanePolling] fetch error:",t)}},[t,n,s,S]),E="".concat(t,"::").concat(n,"::").concat(s),I=(0,o.useRef)(E);(0,o.useEffect)(()=>{I.current!==E&&(I.current=E,u.current+=1,v.current=0,y.current=0,j.current=null,N(!1),null!==w.current&&(clearTimeout(w.current),w.current=null),i(e=>({...e,output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,attaching:!0})),d({visible:!1,data:null,messageId:null,answering:!1}))},[E]),(0,o.useEffect)(()=>{if(r)return g(t),()=>p(t)},[r,t,g,p]),(0,o.useEffect)(()=>{v.current=0,N(!1),null!==w.current&&(clearTimeout(w.current),w.current=null)},[f]),(0,o.useEffect)(()=>()=>{null!==w.current&&clearTimeout(w.current)},[]),(0,o.useEffect)(()=>{if(r)return b(e=>{var n;if("terminal_snapshot"!==e.type||e.worktreeId!==t||e.cliToolId!==m.current||e.instanceId!==h.current||e.version<=v.current)return;v.current=e.version,C();let a=e.output.split("\n").slice(-100).join("\n");S({fullOutput:e.output,realtimeSnippet:a,isRunning:e.isRunning,thinking:e.thinking,isSelectionListActive:e.isSelectionListActive,isPagerActive:e.isPagerActive,isUnclassifiedActive:e.isUnclassifiedActive,isPromptWaiting:e.isPromptWaiting,promptData:null!=(n=e.promptData)?n:null})})},[r,t,b,S,C]),(0,o.useEffect)(()=>{if(r)return b(e=>{if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===h.current)&&(null==e.cliTool||e.cliTool===m.current)&&(v.current=0,S({fullOutput:"",realtimeSnippet:"",isRunning:!1,thinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,isPromptWaiting:!1,promptData:null}))})},[r,t,b,S]),(0,o.useEffect)(()=>{if(!r)return;let e=!1,t=c.visible||l.isSelectionListActive||l.isPagerActive||l.isUnclassifiedActive,n=setInterval(()=>{"hidden"!==document.visibilityState&&T()},f&&k&&!t?15e3:l.isRunning||t?2e3:5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&T();let a=()=>{"visible"!==document.visibilityState||e||T()};return document.addEventListener("visibilitychange",a),()=>{e=!0,null!==n&&(clearInterval(n),n=null),document.removeEventListener("visibilitychange",a)}},[r,f,k,l.isRunning,l.isSelectionListActive,l.isPagerActive,l.isUnclassifiedActive,c.visible,T]);let M=(0,o.useCallback)(e=>{i(t=>t.autoScroll===e?t:{...t,autoScroll:e})},[]),L=(0,o.useCallback)(e=>{d(t=>({...t,answering:e}))},[]);return{terminal:l,prompt:c,setAutoScroll:M,setPromptAnswering:L,clearPrompt:(0,o.useCallback)(()=>{d({visible:!1,data:null,messageId:null,answering:!1})},[]),refresh:(0,o.useCallback)(()=>T(),[T])}}var tm=n(96195),th=n(12181),tx=n(20508),tf=n(27937);function tg(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)}var tp=n(35299),tb=n(6132),tv=n(48314),ty=n(54916),tj=n(36809),tw=n(55041),tk=n(8574);let tN={en:tk.c,ja:tw.ja};function tC(e){var t;return null!=(t=tN[e])?t:tk.c}var tS=n(83012);let tT=/(\/[^\s\n<>"']+\.[a-zA-Z0-9]+)/g;function tE(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 tI=(0,o.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,c.c)("worktree"),s=(0,o.useMemo)(()=>(function(e){let t=e.match(tT);if(!t||0===t.length)return[{type:"text",content:e}];let n=[],a=0;return t.forEach(t=>{let r=e.indexOf(t,a);r>a&&n.push({type:"text",content:e.slice(a,r)}),n.push({type:"path",content:t}),a=r+t.length}),a<e.length&&n.push({type:"text",content:e.slice(a)}),n})(t),[t]),l=(0,o.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))})});function tM(){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 tL=(0,o.memo)(function(e){let{message:t,onFilePathClick:n,onCopy:a,onInsertToMessage:s,onRetryPending:l,onDiscardPending:o}=e,i=(0,tj.Ym)(),d=(0,c.c)("worktree"),u=(0,c.c)("common"),m=tC(i),h=(0,tS.bg)(t.timestamp,m),x=t.optimisticState,f=["group relative border-l-2 p-3 transition-opacity","error"===x?"border-danger-border bg-danger-subtle":"border-accent-500 bg-accent-500/10","sending"===x?"opacity-70":""].filter(Boolean).join(" ");return(0,r.jsxs)("div",{className:f,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"===x&&(0,r.jsxs)("span",{"data-testid":"optimistic-sending",className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(tp.A,{size:12,className:"animate-spin","aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.sending")})]}),"error"===x&&(0,r.jsxs)("span",{"data-testid":"optimistic-error",className:"flex items-center gap-1 text-xs text-danger-foreground",children:[(0,r.jsx)(tb.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.failedToSend")})]}),"error"===x?(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)(tv.A,{size:12,"aria-hidden":"true"}),u("retry")]}),o&&(0,r.jsxs)("button",{type:"button","data-testid":"pending-discard",onClick:()=>o(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)(em.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)(ty.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)(ep.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)(tI,{content:t.content,onFilePathClick:n})})]})}),tA=(0,o.memo)(function(e){let{message:t,index:n,total:a,isExpanded:s,onFilePathClick:l,onCopy:i,hasLongContent:d=!1,onToggleExpand:u}=e,m=(0,tj.Ym)(),h=(0,c.c)("worktree"),x=tC(m),f=(0,tS.bg)(t.timestamp,x),{text:g,isTruncated:p}=(0,o.useMemo)(()=>tE(t.content),[t.content]),b=s||!p?t.content:g;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:f}),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)(e4.A,{size:12,className:"transition-transform ".concat(s?"rotate-180":""),"aria-hidden":"true"}),h(s?"conversation.collapse":"conversation.expand")]}),i&&(0,r.jsx)("button",{type:"button","data-testid":"copy-assistant-message",onClick:()=>i(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)(ep.A,{size:14,"aria-hidden":"true"})})]})]}),(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)(tI,{content:b,onFilePathClick:l}),!s&&p&&(0,r.jsx)("span",{className:"text-muted-foreground",children:"..."})]})]})}),tP=(0,o.memo)(function(e){let{messages:t,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l=!1,onToggleExpand:i}=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)(o.Fragment,{children:[c>0&&(0,r.jsx)("div",{"data-testid":"assistant-message-divider",className:"border-t border-dashed border-border"}),(0,r.jsx)(tA,{message:e,index:c,total:t.length,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l,onToggleExpand:i})]},e.id))})});function tR(){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 tD=(0,o.memo)(function(e){var t;let{pair:n,onFilePathClick:a,isExpanded:s=!1,onToggleExpand:l,onCopy:i,onInsertToMessage:d,showAssistant:u=!0,onRetryPending:m,onDiscardPending:h}=e,x=(0,c.c)("worktree"),f=(null==(t=n.userMessage)?void 0:t.optimisticState)!==void 0,g=(0,o.useMemo)(()=>n.assistantMessages.some(e=>{let{isTruncated:t}=tE(e.content);return t}),[n.assistantMessages]),p=(0,o.useCallback)(()=>{l&&l()},[l]),b=(0,o.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?x("conversation.conversationLabel",{preview:"".concat(n.userMessage.content.substring(0,50)).concat(n.userMessage.content.length>50?"...":"")}):x("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)(tR,{}),n.userMessage&&(0,r.jsx)(tL,{message:n.userMessage,onFilePathClick:a,onCopy:i,onInsertToMessage:d,onRetryPending:m,onDiscardPending:h}),"pending"!==n.status||f?u&&n.assistantMessages.length>0?(0,r.jsx)(tP,{messages:n.assistantMessages,isExpanded:s,onFilePathClick:a,onCopy:i,hasLongContent:g,onToggleExpand:p}):null:(0,r.jsx)("div",{className:"bg-muted/40 border-l-2 border-border p-3 border-t border-border",children:(0,r.jsx)(tM,{})})]})});function tF(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:d,isAtMaxMatches:u,onCompositionStart:m,onCompositionEnd:h}=e,x=(0,o.useRef)(null),f=(0,c.c)("worktree");(0,o.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]);let g=(0,o.useCallback)(e=>{"Escape"===e.key&&d()},[d]),p=(0,o.useCallback)(e=>{n(e.target.value)},[n]),b=0===a?"0/0":u?f("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":f("history.search.regionLabel"),children:[(0,r.jsx)("input",{ref:x,type:"text",value:t,onChange:p,onKeyDown:g,onCompositionStart:m,onCompositionEnd:h,placeholder:f("history.search.placeholder"),className:"bg-transparent text-foreground text-sm outline-none w-32 sm:w-40 placeholder-muted-foreground","aria-label":f("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:i,disabled:0===a,"aria-label":f("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":f("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":f("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 tz="commandmate.worktree.historyVisible",tO="commandmate.worktree.historyWidth";function t_(e){return Number.isFinite(e)?Math.min(60,Math.max(10,e)):40}let tB="commandmate:historyPaneStateChange";function tW(e){try{window.dispatchEvent(new CustomEvent(tB,{detail:e}))}catch(e){}}function tH(){let[e,t]=(0,o.useState)(!0),[n,a]=(0,o.useState)(40),r=(0,o.useRef)(e);r.current=e;let s=(0,o.useRef)(n);return s.current=n,(0,o.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(tz);if("true"===e)return!0;if("false"===e)return!1}catch(e){}return!0}(),n=function(){try{let e=window.localStorage.getItem(tO);if(null===e)return 40;let t=Number(e);if(Number.isFinite(t))return t_(t)}catch(e){}return 40}();t(e),a(n)},[]),(0,o.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(tB,e),()=>window.removeEventListener(tB,e)},[]),{visible:e,width:n,toggle:(0,o.useCallback)(()=>{let e=!r.current;t(e);try{window.localStorage.setItem(tz,String(e))}catch(e){}tW({visible:e,width:s.current})},[]),setWidth:(0,o.useCallback)(e=>{let t=t_(e);a(t);try{window.localStorage.setItem(tO,String(t))}catch(e){}tW({visible:r.current,width:t})},[])}}var tV=n(72115);let tU="worktree-history-pane",tK=(0,o.memo)(function(e){let{onToggle:t}=e,n=(0,c.c)("worktree");return(0,r.jsx)("div",{"data-testid":"terminal-container-expand-bar",style:{width:"".concat(36,"px")},className:"flex-shrink-0 flex items-start justify-center bg-gray-100 dark:bg-gray-800 border-r border-gray-200 dark:border-gray-700",children:(0,r.jsxs)("button",{type:"button","data-testid":"history-pane-expand","aria-label":n("terminal.showHistory"),title:n("terminal.showHistory"),"aria-expanded":"false","aria-controls":tU,onClick:t,className:"flex flex-col items-center gap-2 w-full pt-2 text-gray-500 dark:text-gray-400 hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",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"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:n("terminal.historyLabel")})]})})}),t$=(0,o.memo)(function(e){let{history:t,terminal:n}=e,{visible:a,width:s,toggle:l,setWidth:i}=tH(),c=(0,o.useRef)(null),d=(0,o.useCallback)(e=>{let t=c.current;if(!t)return;let n=t.offsetWidth;0!==n&&i(s+e/n*100)},[s,i]);return(0,r.jsxs)("div",{ref:c,className:"flex h-full min-h-0 w-full",children:[null!=t&&(a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:tU,"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)(S,{componentName:"HistoryPane",children:t})}),(0,r.jsx)(tV.f,{onResize:d,orientation:"horizontal",ariaValueNow:s})]}):(0,r.jsx)(tK,{onToggle:l})),(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)(S,{componentName:"TerminalAndFilePanel",children:n})})]})}),tq=[50,100,150,200,250,500,1e3],tJ="commandmate:historyDisplayLimit";function tY(e){return tq.includes(e)}let tG="commandmate:historyUserOnly";function tX(e){return"split-history-slot-".concat(e)}function tQ(){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 tZ(){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 t0=["h-full","flex","flex-col","overflow-hidden","bg-surface-2","rounded-lg","border","border-border"],t1=(0,o.memo)(function(e){let{messages:t,worktreeId:n,onFilePathClick:a,isLoading:s=!1,className:l="",showToast:i,onInsertToMessage:d,onRetryPending:u,onDiscardPending:h,showArchived:x=!1,onShowArchivedChange:f,historyDisplayLimit:g,onHistoryDisplayLimitChange:p,historyUserOnly:b=!1,onHistoryUserOnlyChange:v,onCollapse:y,splitIndex:j,cliToolId:w}=e,k=(0,c.c)("worktree"),N=(0,o.useRef)(null),C=(0,o.useMemo)(()=>void 0===j?ek:{highlightName:"history-search-".concat(j),currentHighlightName:"history-search-current-".concat(j),fallbackOverlayId:"history-search-fallback-overlay-".concat(j),fallbackOverlayBgColor:ek.fallbackOverlayBgColor},[j]),S=void 0===j?"history-pane-collapse-button":"history-pane-collapse-button-".concat(j),T=void 0===j?tU:tX(j),E=(0,o.useRef)(!0),I=(0,o.useRef)(-1),M=(0,o.useRef)(null),{pairs:L,isExpanded:A,toggleExpand:P}=function(e){let t=(0,o.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,o.useState)(new Set),r=(0,o.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,o.useCallback)(e=>n.has(e),[n]),l=(0,o.useCallback)(()=>{a(new Set(t.map(e=>e.id)))},[t]);return{pairs:t,expandedPairs:n,toggleExpand:r,isExpanded:s,expandAll:l,collapseAll:(0,o.useCallback)(()=>{a(new Set)},[])}}(t),{isOpen:R,query:D,matchCount:F,currentIndex:O,isAtMaxMatches:_,matchPositions:B,currentMatch:W,openSearch:H,closeSearch:V,setQuery:U,onCompositionStart:K,onCompositionEnd:$,nextMatch:q,prevMatch:J}=function(e){let{messages:t}=e,[n,a]=(0,o.useState)(!1),[r,s]=(0,o.useState)(""),[l,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(0),[u,m]=(0,o.useState)(!1),h=(0,o.useRef)(null),x=(0,o.useRef)(""),f=(0,o.useRef)(!1),g=(0,o.useRef)(tg(t)),p=(0,o.useRef)(t);p.current=t;let b=l.reduce((e,t)=>e+t.ranges.length,0),v=(0,o.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,o.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),j=(0,o.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 o=t.content;if(!o)continue;let i=o.toLowerCase(),c=[],d=0;for(;;){let r=i.indexOf(n,d);if(-1===r)break;if(c.push({start:r,end:r+a}),d=r+1,(s+=1)>=500){if(-1!==i.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}}(p.current,e);i(t),d(0),m(n)},[]),w=(0,o.useCallback)(e=>{y(),x.current=e,f.current||(h.current=setTimeout(()=>{j(e)},300))},[y,j]),k=(0,o.useCallback)(e=>{s(e),w(e)},[w]),N=(0,o.useCallback)(()=>{a(!0)},[]),C=(0,o.useCallback)(()=>{a(!1),s(""),x.current="",i([]),d(0),m(!1),y()},[y]),S=(0,o.useCallback)(()=>{d(e=>0===b?0:(e+1)%b)},[b]),T=(0,o.useCallback)(()=>{d(e=>0===b?0:(e-1+b)%b)},[b]),E=(0,o.useCallback)(()=>{f.current=!0,y()},[y]),I=(0,o.useCallback)(()=>{f.current=!1;let e=x.current;e.length>=2&&(y(),h.current=setTimeout(()=>{j(e)},300))},[y,j]);return(0,o.useEffect)(()=>{let e=tg(t);if(e===g.current)return;g.current=e;let n=x.current;n.length>=2&&j(n)},[t,j]),(0,o.useEffect)(()=>()=>{y(),x.current=""},[y]),{isOpen:n,query:r,matchCount:b,currentIndex:c,isAtMaxMatches:u,matchPositions:l,currentMatch:v,openSearch:N,closeSearch:C,setQuery:k,onCompositionStart:E,onCompositionEnd:I,nextMatch:S,prevMatch:T}}({messages:(0,o.useMemo)(()=>t.filter(e=>!e.archived&&"string"==typeof e.content&&e.content.length>0&&(!b||"user"===e.role)),[t,b])}),Y=R&&B.length>0,[G,X]=(0,o.useState)(new Set);(0,o.useEffect)(()=>{V()},[n]);let Q=(0,o.useMemo)(()=>b?L.filter(e=>e.userMessage):L,[L,b]),Z=(0,o.useMemo)(()=>{let e=new Map;for(let t of Q)for(let n of(t.userMessage&&e.set(t.userMessage.id,t.id),t.assistantMessages))e.set(n.id,t.id);return e},[Q]),ee=(0,o.useMemo)(()=>{let e=new Map;return Q.forEach((t,n)=>e.set(t.id,n)),e},[Q]),et=(0,tm.Te)({count:Q.length,getScrollElement:()=>N.current,estimateSize:()=>160,overscan:6,getItemKey:e=>{var t,n;return null!=(n=null==(t=Q[e])?void 0:t.id)?n:e}}),en=et.getVirtualItems(),ea=en.length>0?"".concat(en[0].index,"-").concat(en[en.length-1].index):"",er=(0,o.useCallback)(()=>{let e=N.current;e&&(E.current=function(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}({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))},[]);(0,o.useLayoutEffect)(()=>{let e=I.current,t=Q.length;I.current=t,-1!==e&&t>e&&t>0&&E.current&&!Y&&et.scrollToIndex(t-1,{align:"end"})},[Q.length,Y,et]),(0,o.useLayoutEffect)(()=>{if(!R||0===B.length)return void X(e=>0===e.size?e:new Set);X(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}(B,L))},[R,B,L]),(0,o.useEffect)(()=>{if(!R||!W)return;let e=Z.get(W.messageId);if(void 0===e)return;let t=ee.get(e);void 0!==t&&et.scrollToIndex(t,{align:"center"})},[R,W,Z,ee,et]),(0,o.useLayoutEffect)(()=>{let e=N.current;if(!e)return;if(!R||0===B.length)return void eE(C);let t=null;for(let a of B){var n;let r=(n=a.messageId,e.querySelector('[data-message-id="'.concat(CSS.escape(n),'"]')));if(!r)continue;let s=(null==W?void 0:W.messageId)===a.messageId,l=s?W.localIndex:-1;!function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ek;eT(e,t,n,a)}(r,a.ranges,l,C),s&&r instanceof HTMLElement&&(t=r)}return t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"}),()=>{eE(C)}},[R,B,W,G,C,ea]),(0,o.useEffect)(()=>{let e=N.current;if(R)null===M.current&&e&&(M.current=e.scrollTop);else{if(null!==M.current&&e){let t=M.current;requestAnimationFrame(()=>{e.scrollTop=t})}M.current=null}},[R]);let es=(0,o.useMemo)(()=>[...t0,l].filter(Boolean).join(" "),[l]),el=(0,o.useCallback)(e=>a(e),[a]),eo=(0,o.useCallback)(e=>()=>P(e),[P]),ei=(0,o.useRef)(k);ei.current=k;let ec=(0,o.useCallback)(async e=>{try{await (0,eu.l)(e),null==i||i(ei.current("history.copied"),"success")}catch(e){console.error("[HistoryPane] Failed to copy to clipboard"),null==i||i(ei.current("history.copyFailed"),"error")}},[i]),ed=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=A(e.id)||G.has(e.id);return(0,r.jsx)("div",{className:a?"opacity-60":"",children:(0,r.jsx)(tD,{pair:e,onFilePathClick:el,isExpanded:s,onToggleExpand:eo(e.id),onCopy:ec,onInsertToMessage:d,onRetryPending:u,onDiscardPending:h,showAssistant:!b})})},em=(0,o.useCallback)(e=>{let t=parseInt(e.target.value,10);tY(t)&&(null==p||p(t))},[p]),eh=(0,o.useCallback)(()=>{R?V():H()},[R,H,V]);return(0,r.jsxs)("div",{role:"region","aria-label":k("history.regionLabel"),className:es,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:k("history.title")}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[p&&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:k("history.show")}),(0,r.jsx)("select",{value:g,onChange:em,"aria-label":k("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:tq.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),f&&(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=>f(!0===e),className:"h-3.5 w-3.5"}),k("history.showArchived")]}),v&&(0,r.jsx)("button",{type:"button",onClick:()=>v(!b),"aria-label":k("history.showUserOnly"),"aria-pressed":b,className:"p-1 rounded transition-colors ".concat(b?"bg-accent-500/15 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:text-foreground"),title:k(b?"history.showAllMessages":"history.showUserOnly"),children:b?(0,r.jsx)(th.A,{size:14,"aria-hidden":"true"}):(0,r.jsx)(tx.A,{size:14,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:eh,"aria-label":k(R?"history.closeSearch":"history.openSearch"),"aria-pressed":R,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:k(R?"history.closeSearch":"history.openSearch"),children:(0,r.jsx)(z.A,{size:14,"aria-hidden":"true"})}),y&&(0,r.jsx)("button",{type:"button",onClick:y,"aria-label":k("terminal.hideHistory"),"aria-expanded":"true","aria-controls":T,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:k("terminal.hideHistory"),"data-testid":S,children:(0,r.jsx)(tf.A,{size:14,"aria-hidden":"true"})})]})]}),R&&(0,r.jsx)("div",{className:"flex-shrink-0 px-3 py-2 bg-surface-2 border-b border-border",children:(0,r.jsx)(tF,{query:D,onQueryChange:U,matchCount:F,currentIndex:O,onNext:q,onPrev:J,onClose:V,isAtMaxMatches:_,onCompositionStart:K,onCompositionEnd:$})}),(0,r.jsx)("div",{ref:N,"data-testid":"history-scroll-container",onScroll:er,className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden p-4",children:s?(0,r.jsx)(tQ,{}):0===Q.length?(0,r.jsx)(tZ,{}):0===en.length?(0,r.jsx)("div",{"data-testid":"history-fallback-list",children:Q.slice(0,30).map(e=>(0,r.jsx)("div",{children:ed(e)},e.id))}):(0,r.jsx)("div",{style:{height:et.getTotalSize(),width:"100%",position:"relative"},children:en.map(e=>{let t=Q[e.index];return t?(0,r.jsx)("div",{"data-index":e.index,ref:et.measureElement,className:"absolute left-0 top-0 w-full",style:{transform:"translateY(".concat(e.start,"px)")},children:ed(t)},e.key):null})})})]})}),t2={isOpen:!1,position:{x:0,y:0},targetPath:null,targetType:null};var t4=n(7504),t5=n(22198),t3=n(21786),t6=n(26754),t8=n(71360),t9=n(9286);let t7=(0,o.memo)(function(e){let{isOpen:t,position:n,targetPath:a,targetType:s,onClose:l,onNewFile:i,onNewDirectory:d,onRename:u,onDelete:m,onUpload:h,onMove:x}=e,f=(0,c.c)("worktree"),g=(0,o.useRef)(null),{shouldRender:p,isExiting:b}=(0,t9.O)(t,et.$B),v=(0,o.useCallback)(e=>{e&&a&&e(a),l()},[a,l]),y=[{id:"new-file",label:f("fileTree.newFile"),icon:(0,r.jsx)(t4.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(i),showFor:["directory"]},{id:"new-directory",label:f("fileTree.newDirectory"),icon:(0,r.jsx)(t5.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(d),showFor:["directory"]},{id:"upload",label:f("contextMenu.uploadFile"),icon:(0,r.jsx)(t3.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(h),showFor:["directory"],showDividerAfter:!0},{id:"rename",label:f("contextMenu.rename"),icon:(0,r.jsx)(eg.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(u)},{id:"move",label:f("contextMenu.move"),icon:(0,r.jsx)(t6.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>{x&&a&&s&&x(a,s),l()},showDividerAfter:!0},{id:"delete",label:f("contextMenu.delete"),icon:(0,r.jsx)(t8.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(m),variant:"danger"}].filter(e=>!e.showFor||s&&e.showFor.includes(s));return((0,o.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=g.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,o.useEffect)(()=>{if(t&&g.current){let e=g.current.querySelector('[role="menuitem"]');e&&e.focus()}},[t]),p)?(0,r.jsx)("div",{ref:g,"data-testid":"context-menu",role:"menu","aria-label":f("contextMenu.label"),className:"fixed min-w-[160px] py-1 bg-surface rounded-lg shadow-lg border border-border ".concat(b?"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:ey.M.CONTEXT_MENU,left:"".concat(n.x,"px"),top:"".concat(n.y,"px")},children:y.map((e,t)=>(0,r.jsxs)(o.Fragment,{children:[(0,r.jsxs)("button",{role:"menuitem","data-testid":"context-menu-".concat(e.id),onClick:e.onClick,disabled:!a,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(a?"":"opacity-50 cursor-not-allowed"),children:[e.icon,(0,r.jsx)("span",{children:e.label})]}),e.showDividerAfter&&t<y.length-1&&(0,r.jsx)("div",{"data-testid":"context-menu-divider",className:"my-1 border-t border-border"})]},e.id))}):null});var ne=n(30061);let nt="commandmate.worktree.fileMetadataDisplay",nn={showSize:!0,showCreated:!1,showModified:!1},na="commandmate:fileMetadataDisplayChange";function nr(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 ns=(0,o.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"})})}),nl=(0,o.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"})})}),no=(0,o.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))})}),ni=(0,o.memo)(function(e){let{extension:t}=e,n=(0,o.useMemo)(()=>t&&({ts:"text-info",tsx:"text-info",js:"text-warning",jsx:"text-warning",json:"text-warning",md:"text-muted-foreground",css:"text-pink-500",scss:"text-pink-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"})})}),nc=(0,o.memo)(function e(t){let{item:n,path:a,depth:s,worktreeId:l,expanded:i,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:x,onContextMenu:f,searchQuery:g,searchMode:p,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y=nn}=t,j=(0,c.c)("worktree"),[w,k]=(0,o.useState)(!1),N=a?"".concat(a,"/").concat(n.name):n.name,C=i.has(N),S="directory"===n.type,T=d.get(N),E=(0,o.useMemo)(()=>v?tC(v):void 0,[v]),I=(0,o.useMemo)(()=>{if(S)return;let e=[];if(void 0!==n.size&&e.push("".concat(j("fileTree.metadata.size"),": ").concat(nr(n.size))),n.birthtime){let t=(0,tS.bg)(new Date(n.birthtime),E);t&&e.push("".concat(j("fileTree.metadata.created"),": ").concat(t))}if(n.mtime){let t=(0,tS.bg)(new Date(n.mtime),E);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,E,j]),M=(0,o.useCallback)(async()=>{S?(C||T||(k(!0),await x(N),k(!1)),m(N)):null==h||h(N)},[S,C,T,N,x,m,h]),L=(0,o.useCallback)(e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),M())},[M]),A=(0,o.useCallback)(e=>{e.preventDefault(),null==f||f(e,N,S?"directory":"file")},[N,S,f]),P=function(e){let{delay:t=500,moveThreshold:n=10,onLongPress:a}=e,r=(0,o.useRef)(null),s=(0,o.useRef)(null),l=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{r.current&&(clearTimeout(r.current),r.current=null),s.current=null,l.current=null},[]);(0,o.useEffect)(()=>()=>i(),[i]);let c=(0,o.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),i()},t)},[t,a,i]),d=(0,o.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&&i()},[n,i]);return{onTouchStart:c,onTouchMove:d,onTouchEnd:(0,o.useCallback)(()=>{i()},[i]),onTouchCancel:(0,o.useCallback)(()=>{i()},[i])}}({onLongPress:(0,o.useCallback)(e=>{null==f||f(e,N,S?"directory":"file")},[N,S,f])}),R={...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:R,onClick:M,onKeyDown:L,onContextMenu:A,onTouchStart:P.onTouchStart,onTouchMove:P.onTouchMove,onTouchEnd:P.onTouchEnd,onTouchCancel:P.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)(ns,{expanded:C})}):(0,r.jsx)("span",{className:"w-4 h-4"}),S?(0,r.jsx)(nl,{open:C}):(0,r.jsx)(ni,{extension:n.extension}),(0,r.jsx)(ne.nR,{content:n.name,metadata:I,className:"flex-1 truncate text-sm text-foreground",children:"name"===p&&g?(0,r.jsx)(no,{text:n.name,query:g}):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}):nr(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,tS.fw)(n.birthtime,E)}),!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,tS.fw)(n.mtime,E)})]}),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==g?void 0:g.trim()))return!0;if("name"===p){let t=g.toLowerCase();return!!e.name.toLowerCase().includes(t)||"directory"===e.type}if("content"===p&&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:i,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:x,onContextMenu:f,searchQuery:g,searchMode:p,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y},t.name))})]})});var nd=n(26989);let nu=[{key:"showSize",labelKey:"fileTree.metadata.showSize"},{key:"showCreated",labelKey:"fileTree.metadata.showCreated"},{key:"showModified",labelKey:"fileTree.metadata.showModified"}],nm=(0,o.memo)(function(e){let{settings:t,onToggle:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.useState)(!1),i=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!s)return;let e=e=>{i.current&&!i.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]);let d=(0,o.useCallback)(e=>{n(e)},[n]);return(0,r.jsxs)("div",{className:"relative",ref:i,"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)(nd.A,{className:"w-4 h-4","aria-hidden":"true"})}),s&&(0,r.jsxs)("div",{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",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")}),nu.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:()=>d(e.key),className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{children:a(e.labelKey)})]},e.key))]})]})});function nh(e){let{intervalMs:t,enabled:n,onPoll:a}=e,r=(0,o.useRef)(a);r.current=a;let s=(0,o.useRef)(n);s.current=n;let l=(0,o.useRef)(null);(0,o.useEffect)(()=>{function e(){null!==l.current&&(clearInterval(l.current),l.current=null)}function a(){e(),l.current=setInterval(()=>{r.current()},t)}function o(){"hidden"===document.visibilityState?e():"visible"===document.visibilityState&&s.current&&(r.current(),a())}return n?a():e(),document.addEventListener("visibilitychange",o),()=>{e(),document.removeEventListener("visibilitychange",o)}},[t,n])}function nx(e){return"commandmate:file-tree-expanded:"+e}function nf(e){try{let t=window.localStorage.getItem(nx(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 ng=n(89559);let np=(0,o.memo)(function(e){let{worktreeId:t,onFileSelect:n,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:i,onUpload:d,onMove:u,className:h="",refreshTrigger:f=0,pollingEnabled:g=!1,searchQuery:p,searchMode:b,searchResults:v,onSearchResultSelect:y,onResetView:j}=e,w=(0,tj.Ym)(),k=(0,c.c)("worktree"),{settings:N,toggle:C}=function(){let[e,t]=(0,o.useState)(nn),n=(0,o.useRef)(e);n.current=e,(0,o.useEffect)(()=>{t(function(){try{var e;let t=window.localStorage.getItem(nt);if(!t)return{...nn};return e=JSON.parse(t),"object"!=typeof e||null===e?{...nn}:{showSize:"boolean"==typeof e.showSize?e.showSize:nn.showSize,showCreated:"boolean"==typeof e.showCreated?e.showCreated:nn.showCreated,showModified:"boolean"==typeof e.showModified?e.showModified:nn.showModified}}catch(e){return{...nn}}}())},[]),(0,o.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(na,e),()=>window.removeEventListener(na,e)},[]);let a=(0,o.useCallback)(e=>{n.current=e,t(e);try{window.localStorage.setItem(nt,JSON.stringify(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(na,{detail:{settings:e}}))}catch(e){}},[]);return{settings:e,toggle:(0,o.useCallback)(e=>{a({...n.current,[e]:!n.current[e]})},[a]),setSettings:a}}(),[S,T]=(0,o.useState)(!0),[E,I]=(0,o.useState)(null),[M,L]=(0,o.useState)([]),{expanded:A,setExpanded:P,resetExpanded:R}=function(e){let[t,n]=(0,o.useState)(()=>nf(e)),a=(0,o.useRef)(e);(0,o.useEffect)(()=>{a.current!==e&&(a.current=e,n(nf(e)))},[e]),(0,o.useEffect)(()=>{!function(e,t){try{let n=nx(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,o.useCallback)(()=>{n(new Set)},[]);return{expanded:t,setExpanded:n,resetExpanded:r}}(t),[D,F]=(0,o.useState)(()=>new Map),z=(0,o.useRef)(null),O=(0,o.useRef)(A);O.current=A;let _=(0,o.useRef)(k);_.current=k;let B=(0,o.useRef)(new Set),{menuState:W,openMenu:H,closeMenu:V}=function(){let[e,t]=(0,o.useState)(t2),n=(0,o.useCallback)((e,n,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}t({isOpen:!0,position:{x:r,y:s},targetPath:n,targetType:a})},[]),a=(0,o.useCallback)(()=>{t(e=>({...e,isOpen:!1}))},[]),r=(0,o.useCallback)(()=>{t(t2)},[]);return(0,o.useEffect)(()=>{if(!e.isOpen)return;let t=()=>{a()},n=setTimeout(()=>{document.addEventListener("click",t)},0);return()=>{clearTimeout(n),document.removeEventListener("click",t)}},[e.isOpen,a]),(0,o.useEffect)(()=>{if(!e.isOpen)return;let t=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[e.isOpen,a]),{menuState:e,openMenu:n,closeMenu:a,resetMenu:r}}(),U=(0,o.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]),K=(0,o.useRef)(!0);(0,o.useEffect)(()=>(K.current=!0,()=>{K.current=!1}),[]);let $=(0,o.useCallback)(async()=>{if(K.current){T(!0),I(null);try{let e=await U();if(!K.current||!e)return;let t=Array.from(O.current),n=new Map,a=[];for(let e=0;e<t.length;e+=5){if(!K.current)return;let r=t.slice(e,e+5);for(let[e,t]of(await Promise.allSettled(r.map(async e=>{let t=await U(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(!K.current)return;L(e.items),F(n),a.length>0&&P(e=>{let t=new Set(e);for(let e of a)e&&t.delete(e);return t})}catch(e){K.current&&I(e instanceof Error?e.message:_.current("fileTree.loadError"))}finally{K.current&&T(!1)}}},[U,P]);(0,o.useEffect)(()=>{$()},[$,f]);let q=(0,o.useRef)(null),J=(0,o.useRef)(!1);(0,o.useEffect)(()=>{q.current=null},[t]),nh({intervalMs:5e3,enabled:g,onPoll:(0,o.useCallback)(async()=>{if(K.current&&!J.current){J.current=!0;try{let e=["",...Array.from(O.current)],t=new Map;for(let n=0;n<e.length;n+=5){if(!K.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 U(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(!K.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{J.current=!1}}},[U,$])});let Y=(0,o.useCallback)(async e=>{if(!(D.has(e)||B.current.has(e))){B.current.add(e);try{let t=await U(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,U]),G=(0,o.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[P]),X=(0,o.useCallback)(()=>{var e;R(),F(new Map),null==(e=z.current)||e.scrollTo({top:0}),null==j||j()},[R,j]),Q=(0,o.useMemo)(()=>"content"===b&&v&&0!==v.length?(0,x.q3)(v.map(e=>e.filePath)):new Set,[b,v]);(0,o.useEffect)(()=>{Q.size>0&&P(e=>{let t=new Set(e);for(let e of Q)(D.has(e)||(null==v?void 0:v.some(t=>t.filePath.startsWith(e+"/"))))&&t.add(e);return t})},[Q,D,v,P]);let Z=(0,o.useMemo)(()=>{if(!(null==p?void 0:p.trim()))return M;if("name"===b){let e=p.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(M,"")}return"content"===b&&Q.size>0?M.filter(e=>{if(Q.has(e.name))return!0;if("directory"===e.type){for(let t of Q)if(t.startsWith(e.name+"/")||t===e.name)return!0}return!1}):M},[M,p,b,Q,D]);if(S&&0===M.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(E&&0===M.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:E})});let ee=S&&M.length>0,et=!!E&&M.length>0;return 0===M.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)(t4.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)(t5.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newDirectory")})]})]})]}):(null==p?void 0:p.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:p})})}):(0,r.jsxs)("div",{ref:z,"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)(t4.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)(t5.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)(nm,{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-cyan-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)(ng.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:X,"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)(tv.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)(tb.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"flex-1 truncate",children:E}),(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)(nc,{item:e,path:"",depth:0,worktreeId:t,expanded:A,cache:D,onToggle:G,onFileSelect:y||n,onLoadChildren:Y,onContextMenu:H,searchQuery:p,searchMode:b,matchedPaths:Q,dateFnsLocaleStr:w,metadataDisplay:N},e.name)),(0,r.jsx)(t7,{isOpen:W.isOpen,position:W.position,targetPath:W.targetPath,targetType:W.targetType,onClose:V,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:i,onUpload:d,onMove:u})]})}),nb=(0,o.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"})})}),nv=(0,o.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"})})}),ny=(0,o.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")})}),nj=(0,o.memo)(function(e){let{query:t,mode:n,isSearching:a,error:s,onQueryChange:l,onModeChange:i,onClear:d,placeholder:u,className:m=""}=e,h=(0,o.useRef)(null),x=(0,c.c)("worktree"),f=(0,o.useCallback)(e=>{l(e.target.value)},[l]),g=(0,o.useCallback)(()=>{var e;d(),null==(e=h.current)||e.focus()},[d]),p=(0,o.useCallback)(e=>{if("Escape"===e.key)if(t)g();else{var n;null==(n=h.current)||n.blur()}},[t,g]);return(0,o.useEffect)(()=>{if(!(window.innerWidth<Y.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)(nb,{})}),(0,r.jsx)("input",{ref:h,type:"text","data-testid":"search-input",value:t,onChange:f,onKeyDown:p,placeholder:null!=u?u:x("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":x("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)(ny,{}):t?(0,r.jsx)("button",{type:"button","data-testid":"search-clear",onClick:g,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors","aria-label":x("search.clear"),children:(0,r.jsx)(nv,{})}):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:x("search.mode")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-name",onClick:()=>i("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:x("search.modeName")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-content",onClick:()=>i("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:x("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 nw(e){return 0===e.length?"0":e.map(e=>"".concat(e.id,":").concat(e.title.length,":").concat(e.content.length)).join("|")}var nk=n(12108),nN=n(60850);let nC=(0,o.memo)(function(e){var t,n;let{memo:a,onUpdate:s,onDelete:l,isSaving:i,error:d,className:u="",onInsertToMessage:m,onMoveUp:h,onMoveDown:x,canMoveUp:f=!0,canMoveDown:g=!0}=e,p=(0,c.c)("schedule"),b=(0,c.c)("worktree"),v=!!(h||x),[y,j]=(0,o.useState)(a.title),[w,k]=(0,o.useState)(a.content),[N,C]=(0,o.useState)(!1),S=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let{isSaving:T,error:E,saveNow:I}=(0,nN.U)({value:y,saveFn:async e=>{await s(a.id,{title:e})}}),{isSaving:M,error:L,saveNow:A}=(0,nN.U)({value:w,saveFn:async e=>{await s(a.id,{content:e})}}),P=null!=(n=null!=(t=null!=d?d:null==E?void 0:E.message)?t:null==L?void 0:L.message)?n:null,R=(0,o.useCallback)(e=>{j(e.target.value)},[]),D=(0,o.useCallback)(e=>{k(e.target.value)},[]),F=(0,o.useCallback)(()=>{I()},[I]),z=(0,o.useCallback)(()=>{A()},[A]),O=(0,o.useCallback)(()=>{l(a.id)},[a.id,l]),_=(0,o.useCallback)(()=>{w.trim()&&(null==m||m(w))},[w,m]),B=(0,o.useCallback)(async()=>{if(w.trim())try{await (0,eu.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:R,onBlur:F,placeholder:p("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!=i?i:T||M)&&(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:!f,"aria-label":p("memoMoveUp"),title:p("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)(nk.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button","data-testid":"memo-move-down-".concat(a.id),onClick:x,disabled:!g,"aria-label":p("memoMoveDown"),title:p("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)(e4.A,{className:"w-4 h-4","aria-hidden":"true"})})]}),m&&(0,r.jsx)("button",{type:"button","data-testid":"insert-memo-content",onClick:_,"aria-label":p("memoInsertToMessage"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 transition-colors rounded",title:p("memoInsertToMessage"),children:(0,r.jsx)(ty.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:B,"aria-label":p("memoCopyContent"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-foreground transition-colors rounded",children:N?(0,r.jsx)(ex.A,{className:"w-4 h-4 text-success"}):(0,r.jsx)(ep.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{type:"button",onClick:O,"aria-label":p("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:z,placeholder:p("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"}),P&&(0,r.jsx)("div",{className:"text-xs text-danger",children:P})]})}),nS=(0,o.memo)(function(e){let{currentCount:t,maxCount:n,onAdd:a,isLoading:s=!1,className:l=""}=e,o=(0,c.c)("schedule"),i=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":o("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:o("memoAdd")})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:o("memoRemaining",{count:i})})]})});function nT(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:d,onCompositionStart:u,onCompositionEnd:h}=e,x=(0,c.c)("schedule"),f=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let g=(0,o.useCallback)(e=>{"Escape"===e.key?d():"Enter"===e.key&&(e.preventDefault(),l())},[d,l]),p=(0,o.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":x("memoSearchLabel"),children:[(0,r.jsx)("input",{ref:f,type:"text",value:t,onChange:p,onKeyDown:g,onCompositionStart:u,onCompositionEnd:h,placeholder:x("memoSearchPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-foreground text-sm outline-none placeholder-muted-foreground","aria-label":x("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:i,disabled:0===a,"aria-label":x("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":x("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":x("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 nE=(0,o.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a}=e,s=(0,c.c)("schedule"),l=(0,c.c)("common"),[i,d]=(0,o.useState)([]),[m,h]=(0,o.useState)(!0),[x,f]=(0,o.useState)(!1),[g,p]=(0,o.useState)(null),[b,v]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),w=(0,o.useRef)(null),{query:k,matches:N,currentMatch:C,totalCount:S,setQuery:T,reset:E,navigateNext:I,navigatePrev:M,onCompositionStart:L,onCompositionEnd:A}=function(e){let{memos:t}=e,[n,a]=(0,o.useState)(""),[r,s]=(0,o.useState)([]),[l,i]=(0,o.useState)(-1),c=(0,o.useRef)(null),d=(0,o.useRef)(""),u=(0,o.useRef)(!1),m=(0,o.useRef)(nw(t)),h=(0,o.useRef)(t);h.current=t;let x=r.length,f=(0,o.useCallback)(()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),g=(0,o.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),i(t.length>0?0:-1)},[]),p=(0,o.useCallback)(e=>{f(),d.current=e,u.current||(c.current=setTimeout(()=>{g(e)},300))},[f,g]),b=(0,o.useCallback)(e=>{a(e),p(e)},[p]),v=(0,o.useCallback)(()=>{a(""),d.current="",s([]),i(-1),f()},[f]),y=(0,o.useCallback)(()=>{i(e=>0===x?-1:(e+1)%x)},[x]),j=(0,o.useCallback)(()=>{i(e=>0===x?-1:(e-1+x)%x)},[x]),w=(0,o.useCallback)(()=>{u.current=!0,f()},[f]),k=(0,o.useCallback)(()=>{u.current=!1;let e=d.current;e.length>=2&&(f(),c.current=setTimeout(()=>{g(e)},300))},[f,g]);return(0,o.useEffect)(()=>{let e=nw(t);if(e===m.current)return;m.current=e;let n=d.current;n.length>=2&&g(n)},[t,g]),(0,o.useEffect)(()=>()=>{f(),d.current=""},[f]),{query:n,matches:r,currentMatch:l,totalCount:x,setQuery:b,reset:v,navigateNext:y,navigatePrev:j,onCompositionStart:w,onCompositionEnd:k}}({memos:i}),P=y&&k.length>0,R=P?N:i,D=(0,o.useCallback)(async()=>{h(!0),p(null);try{let e=await B.$T.getAll(t);d(e.sort((e,t)=>e.position-t.position))}catch(e){p((0,B.hS)(e))}finally{h(!1)}},[t]);(0,o.useEffect)(()=>{D()},[D]);let F=(0,o.useCallback)(async()=>{f(!0),v(null);try{let e=await B.$T.create(t,{title:s("memoDefaultTitle"),content:""});d(t=>[...t,e])}catch(e){v((0,B.hS)(e))}finally{f(!1)}},[t,s]),O=(0,o.useCallback)(async(e,n)=>{await B.$T.update(t,e,n),d(t=>t.map(t=>t.id===e?{...t,...n}:t))},[t]),_=(0,o.useCallback)(async e=>{try{await B.$T.delete(t,e),d(t=>t.filter(t=>t.id!==e))}catch(e){console.error("Failed to delete memo:",e)}},[t]),W=(0,o.useCallback)(async(e,n)=>{let a=e+n;if(a<0||a>=i.length)return;let r=[...i];[r[e],r[a]]=[r[a],r[e]],d(r);try{await B.$T.reorder(t,r.map(e=>e.id))}catch(e){p((0,B.hS)(e)),await D()}},[i,t,D]),H=(0,o.useCallback)(()=>{D()},[D]),V=(0,o.useCallback)(()=>{j(e=>(e&&E(),!e))},[E]),U=(0,o.useCallback)(()=>{j(!1),E()},[E]);return((0,o.useEffect)(()=>{var e;if(!P||C<0)return;let t=N[C];if(!t)return;let n=null==(e=w.current)?void 0:e.querySelector('[data-memo-id="'.concat(t.id,'"]'));n&&(n.scrollIntoView({block:"nearest"}),n.focus({preventScroll:!0}))},[P,C,N]),m)?(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:H,"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:w,"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:y?(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsx)(nT,{query:k,onQueryChange:T,matchCount:S,currentIndex:C,onNext:I,onPrev:M,onClose:U,onCompositionStart:L,onCompositionEnd:A})}):(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:V,"aria-label":s("memoSearchToggle"),className:"p-1.5 text-muted-foreground hover:text-foreground transition-colors rounded",children:(0,r.jsx)(z.A,{className:"w-4 h-4","aria-hidden":"true"})})]})}),0===i.length&&!P&&!b&&(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===R.length&&(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:(0,r.jsx)("p",{children:s("memoNoMatch")})}),R.map((e,t)=>(0,r.jsx)(nC,{memo:e,onUpdate:O,onDelete:_,onInsertToMessage:a,onMoveUp:P?void 0:()=>W(t,-1),onMoveDown:P?void 0:()=>W(t,1),canMoveUp:!P&&t>0,canMoveDown:!P&&t<i.length-1},e.id)),b&&(0,r.jsx)("div",{className:"text-center py-2 text-sm text-danger",children:b}),!P&&(0,r.jsx)(nS,{currentCount:i.length,maxCount:20,onAdd:F,isLoading:x,className:"mt-2"})]})});var nI=n(85872),nM=n(53292),nL=n(53482);let nA={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"},nP=o.memo(function(e){let{worktreeId:t,className:n=""}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.useState)([]),[i,d]=(0,o.useState)(""),[u,m]=(0,o.useState)(!0),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(null),[v,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(""),[k,N]=(0,o.useState)(!1),C=(0,o.useCallback)(e=>{switch(e){case"doing":return a("todo.statusDoing");case"done":return a("todo.statusDone");default:return a("todo.statusTodo")}},[a]),S=(0,o.useCallback)(async()=>{m(!0),g(null);try{let e=await nI.Ar.list(t);l(e)}catch(e){g(e instanceof Error?e.message:a("todo.loadError")),l([])}finally{m(!1)}},[t,a]);(0,o.useEffect)(()=>{S()},[t]);let T=(0,o.useCallback)(async()=>{let e=i.trim();if(e&&!h){x(!0),g(null);try{let n=await nI.Ar.create(t,e);l(e=>[...e,n]),d("")}catch(e){g(e instanceof Error?e.message:a("todo.addError"))}finally{x(!1)}}},[i,h,t,a]),E=(0,o.useCallback)(async e=>{let n=function(e){let t=nI.KG.indexOf(e);return nI.KG[(t+1)%nI.KG.length]}(e.status);l(t=>t.map(t=>t.id===e.id?{...t,status:n,done:"done"===n}:t)),g(null);try{await nI.Ar.update(t,e.id,{status:n})}catch(e){g(e instanceof Error?e.message:a("todo.updateError")),S()}},[t,S,a]),I=(0,o.useCallback)(async e=>{g(null);try{await nI.Ar.remove(t,e.id),l(t=>t.filter(t=>t.id!==e.id))}catch(e){g(e instanceof Error?e.message:a("todo.deleteError"))}},[t,a]),M=(0,o.useCallback)(e=>{b(e),y(e.content),w(e.detail),g(null)},[]),L=(0,o.useCallback)(()=>{b(null),N(!1)},[]),A=(0,o.useCallback)(async()=>{if(!p)return;let e=v.trim();if(e&&!k){N(!0),g(null);try{let n=await nI.Ar.update(t,p.id,{content:e,detail:j});l(e=>e.map(e=>e.id===p.id?n:e)),L()}catch(e){g(e instanceof Error?e.message:a("todo.updateError")),N(!1)}}},[p,v,j,k,t,L,a]),P=(0,o.useCallback)(async(e,n)=>{let r=e+n;if(r<0||r>=s.length)return;let o=[...s];[o[e],o[r]]=[o[r],o[e]],l(o),g(null);try{await nI.Ar.reorder(t,o.map(e=>e.id))}catch(e){g(e instanceof Error?e.message:a("todo.reorderError")),S()}},[s,t,S,a]),R=(0,o.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),T())},[T]),D=(0,o.useMemo)(()=>({todo:s.filter(e=>"todo"===e.status).length,doing:s.filter(e=>"doing"===e.status).length,done:s.filter(e=>"done"===e.status).length}),[s]);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:i,onChange:e=>d(e.target.value),onKeyDown:R,maxLength:nM.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:T,disabled:h||0===i.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:[C("todo")," ",D.todo]}),(0,r.jsxs)("span",{"data-testid":"todo-count-doing",children:[C("doing")," ",D.doing]}),(0,r.jsxs)("span",{"data-testid":"todo-count-done",children:[C("done")," ",D.done]})]}),f&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"todo-error",children:f}),u?(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"todo-loading",children:a("todo.loading")}):0===s.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:s.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:()=>E(e),"data-testid":"todo-status","data-status":e.status,"aria-label":a("todo.cycleStatus",{status:C(e.status)}),title:a("todo.cycleStatus",{status:C(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(nA[e.status]),children:C(e.status)}),(0,r.jsxs)("button",{type:"button",onClick:()=>M(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:()=>P(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:()=>P(t,1),disabled:t===s.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:()=>I(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)(e0.a,{isOpen:null!==p,onClose:L,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:v,onChange:e=>y(e.target.value),maxLength:nM.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")}),""!==j.trim()&&(0,r.jsx)(nL.i,{text:j,label:a("todo.copyDetail"),className:"!border-input !bg-surface dark:!bg-surface-2 !text-muted-foreground hover:!bg-muted"})]}),(0,r.jsx)("textarea",{value:j,onChange:e=>w(e.target.value),maxLength:nM.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:L,"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:A,disabled:k||0===v.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 nR=n(95740),nD=n(66630),nF=n(37586),nz=n(47650);function nO(e){let{isOpen:t,onClose:n,title:a,children:s,footer:l,showCloseButton:i=!0}=e,d=(0,c.c)("common"),[u,m]=(0,o.useState)(null);return((0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,n]),(0,o.useEffect)(()=>(t?document.body.style.overflow="hidden":document.body.style.overflow="unset",()=>{document.body.style.overflow="unset"}),[t]),(0,o.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,nz.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:ey.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}),i&&(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)(em.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 n_=["default","acceptEdits","plan","dontAsk","bypassPermissions"],nB=["read-only","workspace-write","danger-full-access"],nW=["allow-all-tools","yolo"],nH=["--dangerously-skip-permissions"],nV=[],nU={claude:"acceptEdits",codex:"workspace-write",gemini:"","vibe-local":"",copilot:"allow-all-tools",antigravity:"--dangerously-skip-permissions"};function nK(e){switch(e){case"codex":return nB;case"copilot":return nW;case"antigravity":return nH;case"claude":return n_;default:return nV}}let n$=/^[\w\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uF900-\uFAFF\s-]{1,100}$/,nq=/^[a-zA-Z0-9][a-zA-Z0-9\-._/:]*$/,nJ=new Set(["copilot"]),nY=[{value:"0 */1 * * *",labelKey:"cronPresetHourly"},{value:"0 9 * * *",labelKey:"cronPresetDaily9"},{value:"0 9 * * 1",labelKey:"cronPresetWeeklyMon9"}],nG={name:"",cronExpression:"0 9 * * *",message:"",cliToolId:"claude",enabled:!0,permission:null!=(a=nU.claude)?a:"",model:""},nX="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",nQ="block text-xs font-semibold text-foreground mb-1",nZ="mt-1 text-xs text-danger-foreground";function n0(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)(nR.A,{size:14,"aria-hidden":"true"}),n]})}function n1(e){let{id:t,title:n,summary:a,icon:s,isOpen:l,onToggle:o,children:i}=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:()=>o(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)(e4.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:i})]})}function n2(e){var t,n;let{isOpen:a,worktreeId:s,initialValues:l,originalName:i,onInsertToMessage:d,instances:u,onClose:h,onSaved:x}=e,f=(0,c.c)("schedule"),g=(0,Y.a)(),p=(0,o.useMemo)(()=>u&&u.length>0?u:(0,e2.lu)([...e2.XH]),[u]),[b,v]=(0,o.useState)(nG),[y,j]=(0,o.useState)(""),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(null),[T,E]=(0,o.useState)(()=>new Set(["basic","advanced","message"]));(0,o.useEffect)(()=>{var e,t,n,r,s,o,i,c,d,u;if(!a)return;S(null),N(!1);let m=null!=(t=null==l?void 0:l.cliToolId)?t:nG.cliToolId;v({name:null!=(n=null==l?void 0:l.name)?n:nG.name,cronExpression:null!=(r=null==l?void 0:l.cronExpression)?r:nG.cronExpression,message:null!=(s=null==l?void 0:l.message)?s:nG.message,cliToolId:m,enabled:null!=(o=null==l?void 0:l.enabled)?o:nG.enabled,permission:null!=(i=null==l?void 0:l.permission)?i:nG.permission,model:null!=(c=null==l?void 0:l.model)?c:nG.model});let h=p.find(e=>e.cliTool===m);j(null!=(u=null!=(d=null==h?void 0:h.id)?d:null==(e=p[0])?void 0:e.id)?u:m)},[a,l,p]),(0,o.useEffect)(()=>{a&&E(new Set(g?["basic"]:["basic","advanced","message"]))},[a,g]);let I=(0,o.useCallback)(e=>{E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),M=nK(b.cliToolId),L=M.length>0,A="copilot"===b.cliToolId,P=!!i,R=(0,o.useMemo)(()=>{let e=b.name.trim();return e?e.length>100?f("edit.errorNameTooLong",{max:100}):n$.test(e)?null:f("edit.errorNameInvalid"):f("edit.errorNameRequired")},[b.name,f]),D=(0,o.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())?f("edit.errorCronInvalid"):null,[b.cronExpression,f]),F=(0,o.useMemo)(()=>b.message.trim()?b.message.length>1e4?f("edit.errorMessageTooLong",{max:1e4}):null:f("edit.errorMessageRequired"),[b.message,f]),z=(0,o.useMemo)(()=>{var e;return A&&b.model.trim()?(e=b.model.trim(),/[\x00-\x1f\x7f]/.test(e)?{valid:!1,reason:"Model name contains control characters"}:""===e.trim()?{valid:!1,reason:"Model name must not be empty"}:!nq.test(e)?{valid:!1,reason:"Model name contains invalid characters"}:e.length>128?{valid:!1,reason:"Model name exceeds ".concat(128," characters")}:{valid:!0}).valid?null:f("edit.errorModelInvalid"):null},[A,b.model,f]),O=!R&&!D&&!F&&!z,_=(0,o.useCallback)(e=>{v(t=>({...t,cliToolId:e,permission:function(e){let t=nU[e];if(void 0!==t)return t;let n=nK(e);return n.length>0?n[0]:""}(e),model:"copilot"===e?t.model:""}))},[]),B=(0,o.useCallback)(e=>{let t=p.find(t=>t.id===e);t&&(j(e),_(t.cliTool))},[p,_]),W=nY.some(e=>e.value===b.cronExpression)?b.cronExpression:"custom",H=(0,o.useCallback)(e=>{"custom"!==e&&v(t=>({...t,cronExpression:e}))},[]),V=(0,o.useCallback)(e=>{null==d||d(e),h()},[d,h]),U=(0,o.useCallback)(async()=>{if(O&&!k){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:L?b.permission:"",model:A&&b.model.trim()?b.model.trim():void 0,originalName:null!=i?i:void 0})});if(!e.ok){let t=await e.json().catch(()=>({}));S(t.error||f("edit.saveError"));return}x(),h()}catch(e){S(f("edit.saveError"))}finally{N(!1)}}},[O,k,s,b,L,A,i,x,h,f]),K=null!=(n=null==(t=p.find(e=>e.id===y))?void 0:t.alias)?n:(0,e2.f_)(b.cliToolId),$=b.name.trim()?"".concat(b.name.trim()," \xb7 ").concat(b.cronExpression):b.cronExpression,q=[K,L?b.permission:null,A&&b.model.trim()?b.model.trim():null].filter(Boolean).join(" \xb7 "),J=b.message.trim(),G=J.length>32?"".concat(J.slice(0,32),"…"):J,X=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-name-input",children:f("edit.name")}),(0,r.jsx)("input",{id:"schedule-name-input","data-testid":"schedule-name-input",type:"text",value:b.name,maxLength:100,placeholder:f("edit.namePlaceholder"),onChange:e=>v(t=>({...t,name:e.target.value})),className:nX}),R&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-name-error",children:R})]}),(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:f("edit.cron")}),d&&(0,r.jsx)(n0,{testId:"schedule-cron-ask-ai",label:f("edit.askAiCron"),title:f("edit.askAiHint"),onClick:()=>V(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.cron"):e("edit.aiPrompts.cronRefine",{current:"`"+n+"`"})}(f,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:f("edit.cronPlaceholder"),onChange:e=>v(t=>({...t,cronExpression:e.target.value})),className:"".concat(nX," font-mono sm:flex-1")}),(0,r.jsxs)("select",{"data-testid":"schedule-cron-preset","aria-label":f("edit.cronPreset"),value:W,onChange:e=>H(e.target.value),className:"".concat(nX," sm:w-48"),children:[nY.map(e=>(0,r.jsx)("option",{value:e.value,children:f("edit.".concat(e.labelKey))},e.value)),(0,r.jsx)("option",{value:"custom",children:f("edit.cronPresetCustom")})]})]}),D&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-cron-error",children:D})]}),(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:f("edit.enabledLabel")})]})]}),Q=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-cli-tool-select",children:f("edit.cliTool")}),(0,r.jsx)("select",{id:"schedule-cli-tool-select","data-testid":"schedule-cli-tool-select",value:y,onChange:e=>B(e.target.value),className:nX,children:p.map(e=>(0,r.jsx)("option",{value:e.id,children:e.alias},e.id))})]}),A&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-model-input",children:f("edit.model")}),(0,r.jsx)("input",{id:"schedule-model-input","data-testid":"schedule-model-input",type:"text",value:b.model,placeholder:f("edit.modelPlaceholder"),onChange:e=>v(t=>({...t,model:e.target.value})),className:nX}),z&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-model-error",children:z})]}),L&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-permission-select",children:f("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:nX,children:M.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),Z=(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:f("edit.message")}),d&&(0,r.jsx)(n0,{testId:"schedule-message-ask-ai",label:f("edit.askAiMessage"),title:f("edit.askAiHint"),onClick:()=>V(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.messageDraft"):e("edit.aiPrompts.messageDraftNamed",{name:"`"+n+"`"})}(f,b.name))})]}),(0,r.jsx)("textarea",{id:"schedule-message-input","data-testid":"schedule-message-input",value:b.message,rows:4,maxLength:1e4,placeholder:f("edit.messagePlaceholder"),onChange:e=>v(t=>({...t,message:e.target.value})),className:"".concat(nX," resize-none")}),(0,r.jsxs)("div",{className:"mt-1 flex items-center justify-between",children:[F?(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-message-error",children:F}):(0,r.jsx)("span",{}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"schedule-message-count",children:f("edit.charCount",{count:b.message.length,max:1e4})})]})]}),ee=(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsx)(n1,{id:"basic",title:f("edit.sectionBasic"),summary:$,icon:(0,r.jsx)(w.A,{className:"w-4 h-4"}),isOpen:T.has("basic"),onToggle:I,children:X}),(0,r.jsx)(n1,{id:"advanced",title:f("edit.sectionAdvanced"),summary:q,icon:(0,r.jsx)(nD.A,{className:"w-4 h-4"}),isOpen:T.has("advanced"),onToggle:I,children:Q}),(0,r.jsx)(n1,{id:"message",title:f("edit.sectionMessage"),summary:G,icon:(0,r.jsx)(nF.A,{className:"w-4 h-4"}),isOpen:T.has("message"),onToggle:I,children:Z}),C&&(0,r.jsx)("div",{className:"text-xs p-2 rounded bg-danger-subtle text-danger-foreground","data-testid":"schedule-submit-error",children:C})]}),et=(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:f("edit.cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"schedule-save-button",onClick:()=>void U(),disabled:!O||k,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:f("edit.save")})]}),en=P?f("edit.titleEdit"):f("edit.titleCreate");return g?(0,r.jsx)(nO,{isOpen:a,onClose:h,title:en,footer:et,children:ee}):(0,r.jsx)(e0.a,{isOpen:a,onClose:h,title:en,size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[ee,(0,r.jsx)("div",{className:"pt-2 border-t border-border",children:et})]})})}function n4(e){return new Date(e).toLocaleString()}function n5(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 n3=(0,o.memo)(function(e){let{worktreeId:t,logs:n}=e,a=(0,c.c)("schedule"),[s,l]=(0,o.useState)(null),[i,d]=(0,o.useState)(null),u=(0,o.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:[n4(e.started_at),n5(e.started_at,e.completed_at)&&(0,r.jsxs)("span",{className:"ml-2",children:["(",n5(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&&i&&(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:i.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:i.result||a("noOutput")})]})]})]},e.id))})});function n6(){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 n8(){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 n9=(0,o.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a,instances:s}=e,l=(0,c.c)("schedule"),i=(0,el.SC)(),[d,u]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[f,g]=(0,o.useState)([]),[p,b]=(0,o.useState)(!0),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)("schedules"),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(void 0),[I,M]=(0,o.useState)(void 0),L=(0,o.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();x(e.schedules||[])}if(a.ok){let e=await a.json();g(e.schedules||[])}else g([])}catch(e){y(e instanceof Error?e.message:"Failed to fetch data")}finally{b(!1)}},[t]);(0,o.useEffect)(()=>{L()},[L]);let A=(0,o.useCallback)(async e=>{try{var n,a,r,s,l,o,i;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 o=n.split("|").slice(1,-1).map(e=>e.trim());o.length>0&&t.get(a).push(o)}return t})(u).get("Schedules"))?n:[]).find(t=>{var n;return(null!=(n=t[0])?n:"").trim()===e});if(!m)return null;let h=function(e){let t=e.trim();if(!t)return{cliToolId:"claude",model:void 0};let n=t.split(/\s+/),a=n[0];return 1===n.length?{cliToolId:a,model:void 0}:nJ.has(a)?3===n.length&&"--model"===n[1]?{cliToolId:a,model:n[2]}:{cliToolId:a,error:"".concat(a," only supports: ").concat(a," --model <modelName>")}:{cliToolId:a,error:'CLI Tool "'.concat(a,'" does not support additional options')}}(null!=(a=m[3])?a:"claude"),x=(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:""===x||"true"===x,permission:(null!=(o=m[5])?o:"").trim(),model:null!=(i=h.model)?i:""}}catch(e){return null}},[t]),P=(0,o.useCallback)(()=>{M(void 0),E(void 0),S(!0)},[]),R=(0,o.useCallback)(async e=>{let t=await A(e.name);M(e.name),E(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)},[A]),D=(0,o.useCallback)(async e=>{if(await i({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 L()}catch(e){console.error("Failed to delete schedule:",e)}},[t,l,L,i]),F=(0,o.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 L()}catch(e){console.error("Failed to toggle schedule:",e)}},[t,L]);return p?(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 L(),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")," (",f.length,")"]}),(0,r.jsx)("span",{className:"text-xs text-accent-700 dark:text-accent-300",children:l("activeSchedulesDescription")})]}),0===f.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:f.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"),": ",n4(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:P,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:P,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 R(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)(n6,{})}),(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)(n8,{})})]})]}),(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"),": ",n4(e.last_executed_at)]})]})]},e.id)})})]})]}):(0,r.jsx)(n3,{worktreeId:t,logs:d})}),(0,r.jsx)(n2,{isOpen:C,worktreeId:t,initialValues:T,originalName:I,onInsertToMessage:a,instances:s,onClose:()=>S(!1),onSaved:()=>{L()}})]})}),n7=(0,o.memo)(function(e){let{worktreeId:t,vibeLocalModel:n,onVibeLocalModelChange:a,vibeLocalContextWindow:s,onVibeLocalContextWindowChange:l}=e,i=(0,c.c)("schedule"),[d,m]=(0,o.useState)([]),[h,x]=(0,o.useState)(null),[f,g]=(0,o.useState)(!1),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null!=s?String(s):""),[j,w]=(0,o.useState)(!1);(0,o.useEffect)(()=>{y(null!=s?String(s):"")},[s]),(0,o.useEffect)(()=>{let e=!1;return g(!0),fetch("/api/ollama/models").then(e=>e.json()).then(t=>{e||(m(t.models),x(0===t.models.length&&t.error?t.error:null))}).catch(()=>{e||(m([]),x("Failed to fetch models"))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[]);let k=(0,o.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,o.useCallback)(e=>{y(e.target.value)},[]),C=(0,o.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:i("vibeLocalModel")}),f?(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"}),i("loading")]}):h&&0===d.length?(0,r.jsx)("p",{className:"text-xs text-warning-foreground",children:i("ollamaNotAvailable")}):(0,r.jsxs)("select",{"data-testid":"vibe-local-model-select",value:null!=n?n:"",onChange:k,disabled:p,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:i("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:i("vibeLocalContextWindow")}),(0,r.jsx)("input",{type:"number","data-testid":"vibe-local-context-window-input",step:"1",min:e2.vz,max:e2.NL,value:v,onChange:N,onBlur:C,placeholder:i("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"})]})]})}),ae=(0,o.memo)(function(e){let{worktreeId:t,selectedAgents:n,onSelectedAgentsChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d,maxAgents:u=2,availableAgents:h=e2.XH,persistToServer:x=!0}=e,f=(0,c.c)("schedule"),g=n.length>u?n.slice(0,u):n,[p,b]=(0,o.useState)(()=>new Set(g)),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)(!1),k=(0,o.useRef)(p);k.current=p,(0,o.useEffect)(()=>{j||b(new Set(g))},[n,j,u]);let N=p.has("vibe-local"),C=(0,o.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(!x){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(g))}catch(e){b(new Set(g))}finally{y(!1),w(!1)}}},[t,g,a,x]),S=p.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:f("agentSettings")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:f("selectAgents")}),(0,r.jsx)("div",{className:"space-y-3",children:h.map(e=>{let t=p.has(e),n=!t&&S;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,e2.oo)(e),checked:t,disabled:n||v,onCheckedChange:t=>C(e,!0===t)}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:(0,e2.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"}),f("loading")]}),N&&(0,r.jsx)(n7,{worktreeId:t,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d})]})});function at(e){return"".concat("commandmate:worktree:mobileInstances:").concat(e)}function an(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 aa=n(49476),ar=n(20017),as=n(6191);let al=(0,o.memo)(function(e){let{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d}=e,m=(0,c.c)("schedule"),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)({}),[v,y]=(0,o.useState)(e2.XH[0]),[j,w]=(0,o.useState)(null),k=n.length>=e2.Ab,N=n.length<=1,C=n.some(e=>"vibe-local"===e.cliTool),S=(0,o.useCallback)(async e=>{let n=e.map((e,t)=>({...e,order:t}));x(!0),g(null);try{(await fetch("/api/worktrees/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentInstances:n})})).ok?a(n):g(m("agentInstanceSaveError"))}catch(e){g(m("agentInstanceSaveError"))}finally{x(!1)}},[t,a,m]),T=(0,o.useCallback)(()=>{if(n.length>=e2.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)}(v,n);S([...n,{id:e,cliTool:v,alias:function(e,t){let n=(0,e2.oo)(e);if(t===e)return n;let a=t.slice(e.length+1);return a?"".concat(n," ").concat(a):n}(v,e),order:n.length}])},[v,n,S]),E=(0,o.useCallback)(e=>{n.length<=1||S(n.filter(t=>t.id!==e))},[n,S]),I=(0,o.useCallback)((e,t)=>{let a=e+t;if(a<0||a>=n.length)return;let r=[...n];[r[e],r[a]]=[r[a],r[e]],S(r)},[n,S]),M=(0,o.useCallback)((e,t)=>{b(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n});let a=n.find(t=>t.id===e);a&&t!==a.alias&&S(n.map(n=>n.id===e?{...n,alias:t}:n))},[n,S]),L=(0,o.useCallback)((e,t)=>{if(e===t||e<0||t<0||e>=n.length||t>=n.length)return;let a=[...n],[r]=a.splice(e,1);a.splice(t,0,r),S(a)},[n,S]);return(0,r.jsxs)("div",{className:"p-4","data-testid":"agent-instances-pane",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground mb-1",children:m("agentInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:m("agentInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-2",children:n.map((e,t)=>{let a=e.id in p?p[e.id]:e.alias,s=j===t;return(0,r.jsxs)("div",{"data-testid":"agent-instance-row-".concat(e.id),draggable:!0,onDragStart:()=>w(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{null!==j&&L(j,t),w(null)},onDragEnd:()=>w(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(s?"opacity-50":""),children:[(0,r.jsx)("span",{className:"cursor-grab text-muted-foreground shrink-0","aria-hidden":"true",children:(0,r.jsx)(aa.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":m("agentInstanceAliasLabel"),value:a,maxLength:e2.pQ,disabled:h,placeholder:m("agentInstanceAliasPlaceholder"),onChange:t=>b(n=>({...n,[e.id]:t.target.value})),onBlur:t=>M(e.id,t.target.value),onKeyDown:e=>{"Enter"===e.key&&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)(ne.nR,{content:(0,e2.oo)(e.cliTool),className:"mt-0.5 block truncate text-xs text-muted-foreground"})]}),(0,r.jsxs)(eO.rI,{children:[(0,r.jsx)(eO.ty,{asChild:!0,children:(0,r.jsx)("button",{type:"button","data-testid":"agent-instance-menu-".concat(e.id),"aria-label":m("agentInstanceActions"),title:m("agentInstanceActions"),disabled:h,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)(ar.A,{className:"w-4 h-4"})})}),(0,r.jsxs)(eO.SQ,{align:"end",children:[(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-move-up-".concat(e.id),disabled:0===t,onSelect:()=>I(t,-1),children:[(0,r.jsx)(nk.A,{className:"w-4 h-4"}),m("agentInstanceMoveUp")]}),(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-move-down-".concat(e.id),disabled:t===n.length-1,onSelect:()=>I(t,1),children:[(0,r.jsx)(e4.A,{className:"w-4 h-4"}),m("agentInstanceMoveDown")]}),(0,r.jsx)(eO.mB,{}),(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-delete-".concat(e.id),disabled:N,onSelect:()=>E(e.id),className:"text-danger-foreground focus:text-danger-foreground",children:[(0,r.jsx)(t8.A,{className:"w-4 h-4"}),m("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":m("agentInstanceBaseTool"),value:v,disabled:h||k,onChange:e=>y(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:e2.XH.map(e=>(0,r.jsx)("option",{value:e,children:(0,e2.oo)(e)},e))}),(0,r.jsxs)("button",{type:"button","data-testid":"agent-instance-add",disabled:h||k,onClick:T,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)(as.A,{className:"w-4 h-4"}),m("agentInstanceAdd")]})]}),k&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:m("agentInstanceMax",{max:e2.Ab})}),N&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:m("agentInstanceMin",{min:1})}),h&&(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"}),m("loading")]}),f&&(0,r.jsx)("p",{"data-testid":"agent-instances-error",className:"mt-3 text-xs text-danger-foreground",children:f}),C&&(0,r.jsx)(n7,{worktreeId:t,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d})]})}),ao=(0,o.memo)(function(e){let{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:i,visibleInstanceIds:d,onToggleInstanceVisible:u}=e,h=(0,c.c)("schedule"),x=new Set(d),f=d.length<=1;return(0,r.jsxs)("div",{"data-testid":"mobile-agent-instances-pane",children:[(0,r.jsx)(al,{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:i}),(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:h("mobileVisibleInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-3",children:h("mobileVisibleInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-1",children:n.map(e=>{let t=x.has(e.id),n=t&&f;return(0,r.jsxs)("label",{className:"flex items-center gap-2 p-2 rounded-lg cursor-pointer ".concat(n?"opacity-60 cursor-not-allowed":"hover:bg-muted"),children:[(0,r.jsx)(m.Sc,{"data-testid":"mobile-visible-instance-toggle-".concat(e.id),checked:t,disabled:n,onCheckedChange:()=>u(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,e2.sw)(e)}),(0,r.jsx)("span",{className:"block text-xs text-muted-foreground truncate",children:(0,e2.oo)(e.cliTool)})]})]},e.id)})}),f&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:h("mobileVisibleInstanceMin")})]})]})}),ai=Array.from({length:Math.floor(104)+1},(e,t)=>3e5+3e5*t);var ac=n(82912),ad=n.n(ac);let au=[36e5,108e5,288e5],am={36e5:"autoYes.durations.1h",108e5:"autoYes.durations.3h",288e5:"autoYes.durations.8h"};function ah(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 ax(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 af="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 ag(e){let{isOpen:t,worktreeId:n,instances:a,onClose:s,onSaved:l}=e,i=(0,c.c)("schedule"),d=(0,Y.a)(),u=(0,o.useMemo)(()=>a&&a.length>0?a:(0,e2.lu)([...e2.XH]),[a]),[m,h]=(0,o.useState)(""),[x,f]=(0,o.useState)(()=>{var e,t;return null!=(t=null==(e=u[0])?void 0:e.id)?t:e2.XH[0]}),[g,p]=(0,o.useState)(ai[0]),[b,v]=(0,o.useState)(!1),[y,j]=(0,o.useState)(null);(0,o.useEffect)(()=>{var e,n;t&&(h(""),p(ai[0]),j(null),v(!1),f(null!=(n=null==(e=u[0])?void 0:e.id)?n:e2.XH[0]))},[t,u]),(0,o.useEffect)(()=>{if(!u.some(e=>e.id===x)){var e,t;f(null!=(t=null==(e=u[0])?void 0:e.id)?t:e2.XH[0])}},[u,x]);let w=m.trim().length>0&&!b,k=(0,o.useCallback)(async()=>{if(!m.trim()||b)return;let e=u.find(e=>e.id===x);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:g})});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,x,m,g,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:i("timer.agent")}),(0,r.jsx)("select",{id:"timer-instance-select","data-testid":"timer-instance-select",value:x,onChange:e=>f(e.target.value),className:af,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:i("timer.message")}),(0,r.jsx)("textarea",{id:"timer-message-input","data-testid":"timer-message-input",value:m,onChange:e=>h(e.target.value),placeholder:i("timer.message"),maxLength:1e4,rows:3,className:"".concat(af," 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:i("timer.delay")}),(0,r.jsx)("select",{id:"timer-delay-select","data-testid":"timer-delay-select",value:g,onChange:e=>p(Number(e.target.value)),className:af,children:ai.map(e=>(0,r.jsx)("option",{value:e,children:ax(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:i("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:i("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:i("timer.register")})]}),S=i("timer.titleCreate");return d?(0,r.jsx)(nO,{isOpen:t,onClose:s,title:S,footer:C,children:N}):(0,r.jsx)(e0.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 ap(e){return new Date(e).toLocaleString()}function ab(e){var t,n;let{timer:a,instances:s,onClose:l}=e,o=(0,c.c)("schedule"),i=(0,Y.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:o("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:o("timer.agent"),children:(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 font-medium",children:d})}),(0,r.jsx)(u,{label:o("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:o("timer.status.".concat(a.status))})}),(0,r.jsx)(u,{label:o("timer.delay"),children:ax(a.delayMs)}),(0,r.jsx)(u,{label:o("timer.scheduledTime"),children:ap(a.scheduledSendTime)}),(0,r.jsx)(u,{label:o("timer.createdTime"),children:ap(a.createdAt)}),null!==a.sentAt&&(0,r.jsx)(u,{label:o("timer.sentTime"),children:ap(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:o("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:o("timer.close")})}),x=o("timer.detailTitle");return i?(0,r.jsx)(nO,{isOpen:!0,title:x,onClose:l,footer:h,children:m}):(0,r.jsx)(e0.a,{isOpen:!0,title:x,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 av=(0,o.memo)(function(e){let{worktreeId:t,instances:n}=e,a=(0,c.c)("schedule"),s=(0,el.SC)(),l=(0,o.useMemo)(()=>n&&n.length>0?n:(0,e2.lu)([...e2.XH]),[n]),[i,d]=(0,o.useState)([]),[u,m]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[,p]=(0,o.useState)(0),b=(0,o.useRef)(null),y=(0,o.useRef)(null),j=(0,o.useRef)(null),w=(0,o.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,o.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,o.useEffect)(()=>{function e(){return w(),b.current=setInterval(()=>{w()},1e4),y.current=setInterval(()=>{p(e=>e+1)},1e3),t}function t(){b.current&&clearInterval(b.current),y.current&&clearInterval(y.current),b.current=null,y.current=null}e();let n=()=>{"hidden"===document.visibilityState?t():e()};return document.addEventListener("visibilitychange",n),()=>{t(),document.removeEventListener("visibilitychange",n)}},[w]);let N=(0,o.useCallback)(async e=>{try{(await fetch("/api/worktrees/".concat(t,"/timers?timerId=").concat(e),{method:"DELETE"})).ok&&w()}catch(e){}},[t,w]),C=(0,o.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=i.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===i.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)(v.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:()=>x(!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)(as.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:()=>x(!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)(as.A,{className:"w-3.5 h-3.5"}),a("timer.newTimer")]})]}),i.map(e=>{var t,n;return(0,r.jsxs)("div",{role:"button",tabIndex:0,"data-testid":"timer-row",onClick:()=>g(e),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),g(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:ah(e.scheduledSendTime)}),(0,r.jsx)("span",{className:"text-muted-foreground",children:ax(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")}),i.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)(ag,{isOpen:h,worktreeId:t,instances:n,onClose:()=>x(!1),onSaved:()=>{w()}}),(0,r.jsx)(ab,{timer:f,instances:l,onClose:()=>g(null)})]})}),ay=[{id:"notes",labelKey:"notes"},{id:"logs",labelKey:"logs"},{id:"agent",labelKey:"agentTab"},{id:"timer",labelKey:"timerTab"},{id:"todo",labelKey:"todoTab"}],aj=(0,o.memo)(function(e){let{worktreeId:t,className:n="",selectedAgents:a,onSelectedAgentsChange:s,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,maxAgents:m,availableAgents:h,persistToServer:x,onInsertToMessage:f,useInstanceManagement:g=!1,instances:p,onInstancesChange:b,visibleInstanceIds:v,onToggleInstanceVisible:y}=e,j=(0,c.c)("schedule"),[w,k]=(0,o.useState)("notes"),N=(0,o.useCallback)(e=>{k(e)},[]);return(0,r.jsxs)("div",{className:"flex flex-col h-full ".concat(n),children:[(0,r.jsx)("div",{className:"flex border-b border-border bg-surface dark:bg-surface-2 flex-shrink-0",children:ay.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>N(e.id),className:"flex-1 px-3 py-2 text-sm font-medium transition-colors ".concat(w===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:j(e.labelKey)},e.id))}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["notes"===w&&(0,r.jsx)(nE,{worktreeId:t,className:"h-full",onInsertToMessage:f}),"logs"===w&&(0,r.jsx)(n9,{worktreeId:t,className:"h-full",onInsertToMessage:f,instances:p}),"agent"===w&&(g&&p&&b&&v&&y?(0,r.jsx)("div",{className:"h-full overflow-y-auto",children:(0,r.jsx)(ao,{worktreeId:t,instances:p,onInstancesChange:b,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,visibleInstanceIds:v,onToggleInstanceVisible:y})}):(0,r.jsx)(ae,{worktreeId:t,selectedAgents:a,onSelectedAgentsChange:s,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,maxAgents:m,availableAgents:h,persistToServer:x})),"timer"===w&&(0,r.jsx)(av,{worktreeId:t,instances:p,selectedAgents:a}),"todo"===w&&(0,r.jsx)(nP,{worktreeId:t,className:"h-full"})]})]})});var aw=n(2317);let ak=["status","changes","history","advanced"],aN="commandmate:gitPane:",aC={activeTab:"".concat(aN,"activeTab"),historyOpen:"".concat(aN,"historyOpen"),advancedOpen:"".concat(aN,"advancedOpen")};function aS(e){return"string"==typeof e&&ak.includes(e)}let aT=e=>"boolean"==typeof e,aE=(0,o.memo)(function(e){let{branches:t,busy:n,actionError:a,hasRunningSession:s,isMobile:l,onCheckout:i}=e,d=(0,c.c)("worktree"),u=(0,c.c)("common"),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(!1),v=t.filter(e=>!e.isCurrent),y=(0,o.useCallback)(e=>{b(!1),g({...e}),x(!1)},[]),j=(0,o.useCallback)(()=>{f&&(i(f,p),g(null))},[f,p,i]);return(0,r.jsxs)("div",{className:"relative","data-testid":"branch-checkout-dropdown",children:[(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:()=>x(e=>!e),disabled:n||0===v.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":h,"aria-label":d("git.checkout.ariaLabel"),children:[d("git.checkout.action"),(0,r.jsx)("span",{"aria-hidden":"true",className:"text-[10px]",children:"▾"})]}),h&&(0,r.jsx)("div",{className:"absolute left-0 top-full z-20 mt-1 min-w-[12rem] max-h-64 overflow-y-auto rounded border border-border bg-surface shadow-lg",role:"menu","data-testid":"branch-checkout-menu",children:0===v.length?(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:d("git.checkout.noBranches")}):(0,r.jsx)("ul",{className:"divide-y divide-border",children:v.map(e=>{var t;let a=null!==e.checkedOutWorktreePath;return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>y(e),disabled:n||a,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":d("git.checkout.checkoutBranch",{name:e.name}),title:a?d("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:d("git.checkout.defaultBadge")})]})},"".concat(e.isRemote?"r":"l",":").concat(e.name))})})}),a&&(0,r.jsx)("div",{className:"mt-1 text-xs text-danger-foreground",role:"alert","data-testid":"branch-checkout-error",children:a}),f&&(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:[d("git.checkout.confirmTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:f.name}),d("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:d("git.checkout.historyLossWarning")}),s&&(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:d("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:p,onCheckedChange:e=>b(!0===e),"data-testid":"branch-checkout-force"}),d("git.checkout.forceLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 ".concat(l?"flex-wrap":""),children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>g(null),className:"px-3 py-1 text-xs rounded border border-input text-foreground hover:bg-muted",children:u("cancel")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:j,disabled:n,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:d("git.checkout.action")})]})]})})]})}),aI=(0,o.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})]})}),aM=(0,o.createContext)(null);function aL(e){let{value:t,children:n}=e;return(0,r.jsx)(aM.Provider,{value:t,children:n})}function aA(){let e=(0,o.useContext)(aM);if(null===e)throw Error("useGitPaneContext must be used within a GitPaneProvider");return e}let aP=(0,o.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})})}),aR={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"},aD={status:"git.tabs.status",changes:"git.tabs.changes",history:"git.tabs.history",advanced:"git.tabs.advanced"},aF=(0,o.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:ak.map(e=>{let s=e===t,l=a(aD[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)(aP,{path:aR[e]}),(0,r.jsx)("span",{children:l})]},e)})})});function az(e){let{activeTab:t,onTabChange:n,className:a="",statusSection:s,quickActionsSection:l,changesSection:o,historySection:i,advancedSection:c}=e,{isMobile:d}=aA();return d?(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden ".concat(a),"data-testid":"git-pane-mobile",children:[(0,r.jsx)(aF,{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:o}),"history"===t&&i,"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,o]}),(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:i}),(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 aO={added:"text-success-foreground",modified:"text-warning-foreground",deleted:"text-danger-foreground",renamed:"text-info",untracked:"text-teal-600 dark:text-teal-400",unmerged:"text-warning-foreground"},a_=(0,o.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"})})}),aB=(0,o.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)(nR.A,{size:14,"aria-hidden":"true"}),l("git.askAi")]})}),aW=(0,o.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})}),aH=(0,o.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})}),aV=(0,o.memo)(function(e){let{gitStatus:t,statusLoading:n,statusError:a,onRefresh:s}=e,{isMobile:l}=aA(),o=(0,c.c)("worktree");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:o("git.currentStatus.title")}),(0,r.jsx)("button",{type:"button",onClick:s,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":o("git.currentStatus.refresh"),children:(0,r.jsx)(a_,{})})]}),n&&!t&&(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:o("git.currentStatus.loading")})]}),a&&!t&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-status-error",children:a}),t&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center flex-wrap ".concat(l?"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:t.currentBranch,children:t.currentBranch}),t.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:o("git.currentStatus.uncommitted")}),t.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:o("git.currentStatus.aheadTooltip"),children:["↑",t.aheadBehind.ahead]}),(0,r.jsxs)("span",{title:o("git.currentStatus.behindTooltip"),children:["↓",t.aheadBehind.behind]})]})]}),t.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:[o("branchMismatch.changedFrom")," ",(0,r.jsx)("span",{className:"font-medium",children:t.initialBranch})," ",o("branchMismatch.to")," ",(0,r.jsx)("span",{className:"font-medium",children:t.currentBranch})]})]})]})]})}),aU=(0,o.memo)(function(e){let{progressState:t,operation:n,error:a,conflict:s,conflictFiles:l,hasUpstream:i,onFetch:d,onPull:m,onPush:h,onAbort:x,extraActions:f}=e,{isMobile:g}=aA(),p=(0,c.c)("worktree"),b="running"===t,v=null!=a?a:p("git.network.failed"),[y,j]=(0,o.useState)(0);return(0,o.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:p("git.network.quickActions")}),(0,r.jsxs)("div",{className:"flex items-center ".concat(g?"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:p("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:p("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:i?void 0:p("git.network.noUpstreamTooltip"),children:p("git.network.push")}),f]}),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(g?"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:p("git.network.progress",{operation:p("push"===n?"git.network.pushing":"pull"===n?"git.network.pulling":"git.network.fetching"),elapsed:y})})]}),(0,r.jsx)("button",{type:"button",onClick:x,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:p("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:p("git.network.conflicts",{files:l.join(", ")})})]})}),aK=(0,o.memo)(function(e){let{title:t,testId:n,files:a,actionLabel:s,mode:l,defaultOpen:i,busy:d,onDiff:u,onToggleStage:h,onPreview:x}=e,f=(0,c.c)("worktree"),[g,p]=(0,o.useState)(i),[b,v]=(0,o.useState)(null),[y,j]=(0,o.useState)(null),[w,k]=(0,o.useState)(!1),[N,C]=(0,o.useState)(null),S=(0,o.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 x(e,l);j(null!=t?t:"")}catch(e){C(f("git.changes.previewFailed"))}finally{k(!1)}},[b,x,l,f]);return(0,r.jsxs)("div",{className:"border-t border-border","data-testid":n,children:[(0,r.jsxs)("button",{type:"button",onClick:()=>p(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:g?"▼":"▶"}),f("git.changes.listHeader",{title:t,count:a.length})]}),g&&0===a.length&&(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:f("git.changes.empty")}),g&&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(aO[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":f("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":f("git.changes.showDiff",{path:e.path}),"data-testid":"git-changes-diff-button",children:f("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":f("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:f("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:f("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)(aW,{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:f("git.changes.truncated")})]}))]})]},"".concat(e.status,":").concat(e.path))})})]})}),a$=(0,o.memo)(function(e){var t,n,a;let{staged:s,loading:l,error:o,busy:i,commitMessage:d,amend:u,committing:h,commitError:x,onRefresh:f,onDiff:g,onPreview:p,onStage:b,onUnstage:v,onCommitMessageChange:y,onAmendChange:j,onCommit:w,onCommitAndPush:k}=e,{isMobile:N}=aA(),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:[],E=null!=(a=null==s?void 0:s.untracked)?a:[],I=!h&&d.trim().length>0&&(S.length>0||u),M=!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:f,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":C("git.changes.refresh"),children:(0,r.jsx)(a_,{})})]}),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")})]}),o&&!s&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-changes-error",children:o}),s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(aK,{title:C("git.changes.staged"),testId:"git-staged-list",files:S,actionLabel:C("git.changes.unstage"),mode:"staged",defaultOpen:M,busy:i,onDiff:g,onPreview:p,onToggleStage:v}),(0,r.jsx)(aK,{title:C("git.changes.unstaged"),testId:"git-unstaged-list",files:T,actionLabel:C("git.changes.stage"),mode:"unstaged",defaultOpen:M,busy:i,onDiff:g,onPreview:p,onToggleStage:b}),(0,r.jsx)(aK,{title:C("git.changes.untracked"),testId:"git-untracked-list",files:E,actionLabel:C("git.changes.stage"),mode:"untracked",defaultOpen:M,busy:i,onDiff:g,onPreview:p,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:!I,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:!I||i,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")})]})]}),x&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-commit-error",children:x})]})]})]})}),aq=(0,o.memo)(function(e){let{commits:t,isLoading:n,commitError:a,commitListOpen:s,onToggleCommitList:l,onRefresh:i,selectedCommit:d,onCommitSelect:m,inlineDiffCommit:h,inlineFiles:x,inlineFilesLoading:f,inlineFilesError:g,onToggleInlineDiff:p,onInlineDiffFile:b,changedFiles:v,isLoadingFiles:y,detailError:j,selectedFile:w,onFileSelect:k,diffContent:N,isLoadingDiff:C}=e,{isMobile:S}=aA(),T=(0,c.c)("worktree"),[E,I]=(0,o.useState)(!0),[M,L]=(0,o.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:i,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":T("git.history.refresh"),children:(0,r.jsx)(a_,{})})]}),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:()=>p(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:[f&&(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")})]}),g&&(0,r.jsx)(aH,{message:g}),!f&&!g&&0===x.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:T("git.history.noChangedFiles")}),!f&&x.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:x.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(aO[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:()=>I(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:E?"▼":"▶"}),T("git.history.changedFiles")]}),E&&(0,r.jsxs)(r.Fragment,{children:[j&&(0,r.jsx)(aH,{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(aO[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:()=>L(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:M?"▼":"▶"}),T("git.history.diffLabel",{file:w})]}),M&&(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)(aW,{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 aJ(e){return"`"+e+"`"}let aY={local:"git.branches.filterLocal",remote:"git.branches.filterRemote",all:"git.branches.filterAll"},aG=(0,o.memo)(function(e){let{branches:t,include:n,loading:a,error:s,busy:l,actionError:i,onIncludeChange:d,onRefresh:u,onCreate:h,onDelete:x}=e,{isMobile:f,onInsertToMessage:g}=aA(),p=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,o.useState)(!f),[j,w]=(0,o.useState)(!1),[k,N]=(0,o.useState)(""),[C,S]=(0,o.useState)(""),[T,E]=(0,o.useState)(null),[I,M]=(0,o.useState)(!1),L=(0,o.useCallback)(()=>{0!==k.trim().length&&(h(k.trim(),C.trim()||void 0),w(!1),N(""),S(""))},[k,C,h]),A=(0,o.useCallback)(()=>{T&&(x(T.name,I),E(null),M(!1))},[T,I,x]);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?"▼":"▶"}),p("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:p("git.branches.newButton")}),(0,r.jsx)("button",{type:"button",onClick:u,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":p("git.branches.refresh"),children:(0,r.jsx)(a_,{})})]})]}),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:p(aY[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:p("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}),i&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-branches-action-error",children:i}),!a&&!s&&0===t.length&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-muted-foreground",children:p("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:p("git.branches.defaultBadge")})]}),(0,r.jsx)("button",{type:"button",onClick:()=>{M(!1),E(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":p("git.branches.deleteBranch",{name:e.name}),children:p("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:p("git.branches.createTitle")}),(0,r.jsx)("input",{type:"text",value:k,onChange:e=>N(e.target.value),placeholder:p("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":p("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":p("git.branches.baseLabel"),children:[(0,r.jsx)("option",{value:"",children:p("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:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"branch-create-ask-ai",disabled:0===k.trim().length,onClick:()=>{g(function(e,t,n){let a=n&&n.trim().length>0?aJ(n.trim()):e("git.aiPrompts.branchCreateBaseHead");return e("git.aiPrompts.branchCreate",{base:a,name:aJ(t.trim())})}(p,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:L,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:p("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:[p("git.branches.deleteTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:T.name}),p("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:I,onCheckedChange:e=>M(!0===e),"data-testid":"branch-delete-force"}),p("git.branches.forceDeleteLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[g&&T&&(0,r.jsx)(aB,{className:"mr-auto",testId:"branch-delete-ask-ai",onClick:()=>{g(p(I?"git.aiPrompts.branchDeleteForce":"git.aiPrompts.branchDelete",{name:aJ(T.name)})),E(null),M(!1)}}),(0,r.jsx)("button",{type:"button",onClick:()=>E(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:A,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:p("git.branches.delete")})]})]})})]})}),aX=(0,o.memo)(function(e){let{stashes:t,loading:n,error:a,busy:s,actionError:l,conflictNotice:i,hasRunningSession:d,onRefresh:u,onPush:h,onPop:x,onApply:f,onDrop:g}=e,{isMobile:p,onInsertToMessage:b}=aA(),v=(0,c.c)("worktree"),y=(0,c.c)("common"),[j,w]=(0,o.useState)(!p),[k,N]=(0,o.useState)(""),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.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)(aB,{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)(a_,{})})]})]}),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}),i&&(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:i}),b&&(0,r.jsx)(aB,{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,i))})]}),(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:()=>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-apply-button",children:v("git.stash.apply")}),(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-pop-button",children:v("git.stash.pop")}),(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>E(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:()=>{g(T),E(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:()=>E(null),className:"px-2 py-1 text-xs rounded border border-input hover:bg-muted",children:y("cancel")})]})]})]})}),aQ={soft:"git.danger.modeSoft",mixed:"git.danger.modeMixed",hard:"git.danger.modeHard"},aZ=(0,o.memo)(function(e){let{selectedCommit:t,busy:n,actionError:a,conflictNotice:s,currentBranch:l,aheadCount:i,hasRunningSession:d,onReset:u,onRevert:h,onForcePush:x}=e,{isMobile:f,onInsertToMessage:g}=aA(),p=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)("mixed"),[k,N]=(0,o.useState)(!0),[C,S]=(0,o.useState)(""),[T,E]=(0,o.useState)(!1),[I,M]=(0,o.useState)(!1),[L,A]=(0,o.useState)(!1),[P,R]=(0,o.useState)(!1),[D,F]=(0,o.useState)(!0),z=k?"HEAD":t,O=!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?"▼":"▶"}),p("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(f?"flex-col":"flex-row"," gap-2"),children:[(0,r.jsx)("button",{type:"button",onClick:()=>E(!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:p("git.danger.resetOpen")}),(0,r.jsx)("button",{type:"button",disabled:!t,onClick:()=>M(!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:p("git.danger.revertOpen")}),x&&(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>R(!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:p("git.danger.forcePushOpen")})]}),!t&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:p("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:p("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"}),p("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"}),p("git.danger.resetTargetSelectedPrefix"),t?p("git.danger.resetTargetSelectedHash",{hash:t.slice(0,7)}):p("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)}),p(aQ[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:p("git.danger.resetHardWarning")}),d&&(0,r.jsx)("p",{className:"text-xs text-danger-foreground","data-testid":"reset-hard-session-warning",children:p("git.danger.runningSessionWarning")}),(0,r.jsx)("input",{type:"text",value:C,onChange:e=>S(e.target.value),placeholder:p("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:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"reset-ask-ai",disabled:O,onClick:()=>{z&&(g("hard"===j?p("git.aiPrompts.resetHard",{target:aJ(z)}):p("git.aiPrompts.reset",{target:aJ(z),mode:j})),E(!1),S(""))}}),(0,r.jsx)("button",{type:"button",disabled:n||O||"hard"===j&&C!==(null!=l?l:""),onClick:()=>{z&&(u(z,j,"hard"===j?C:void 0),E(!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:p("git.danger.reset")}),(0,r.jsx)("button",{type:"button",onClick:()=>{E(!1),S("")},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),I&&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:p("git.danger.revertTitle")}),(0,r.jsxs)("p",{className:"text-xs text-foreground mb-2",children:[p("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:p("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:L,onCheckedChange:e=>A(!0===e),"data-testid":"revert-no-commit"}),p("git.danger.revertNoCommit")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"revert-ask-ai",onClick:()=>{g(p("git.aiPrompts.revert",{commit:aJ(t.slice(0,7))})),M(!1),A(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{h(t,L),M(!1),A(!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:p("git.danger.revert")}),(0,r.jsx)("button",{type:"button",onClick:()=>{M(!1),A(!1)},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),P&&x&&(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:p("git.danger.forcePushTitle")}),(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-protected-branch-warning",children:p("git.danger.protectedBranchWarning")}),d&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-session-warning",children:p("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"}),p("git.danger.forceWithLease")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"force-push-ask-ai",onClick:()=>{g(function(e,t){let{branch:n,ahead:a}=t,r=n?aJ(n):e("git.aiPrompts.forcePushCurrentBranch");return e("number"==typeof a&&a>0?"git.aiPrompts.forcePushAhead":"git.aiPrompts.forcePush",{branchRef:r,upstream:aJ("origin/".concat(null!=n?n:"<branch>")),ahead:null!=a?a:0})}(p,{branch:l,ahead:null!=i?i:null})),R(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{x(D),R(!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:p("git.danger.forcePush")}),(0,r.jsx)("button",{type:"button",onClick:()=>R(!1),className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]})]})}),a0=(0,o.memo)(function(e){var t,n,a,s;let{worktreeId:l,onDiffSelect:i,isMobile:d=!1,worktree:u,onInsertToMessage:h,className:x=""}=e,f=(0,c.c)("worktree"),{activeTab:g,setActiveTab:p,historyOpen:b,toggleHistory:v,advancedOpen:y,toggleAdvanced:j}=function(){let{value:e,setValue:t,isAvailable:n}=(0,aw.V)({key:aC.activeTab,defaultValue:"status",validate:aS}),{value:a,setValue:r}=(0,aw.V)({key:aC.historyOpen,defaultValue:!0,validate:aT}),{value:s,setValue:l}=(0,aw.V)({key:aC.advancedOpen,defaultValue:!1,validate:aT}),i=(0,o.useCallback)(e=>t(e),[t]);return{activeTab:e,setActiveTab:i,historyOpen:a,toggleHistory:(0,o.useCallback)(()=>r(e=>!e),[r]),advancedOpen:s,toggleAdvanced:(0,o.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,o.useState)(null),[a,r]=(0,o.useState)(!0),[s,l]=(0,o.useState)(null),i=(0,o.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,o.useEffect)(()=>{i()},[i]),{gitStatus:t,statusLoading:a,statusError:s,fetchStatus:i}}(l),{commits:T,selectedCommit:E,changedFiles:I,inlineDiffCommit:M,inlineFiles:L,inlineFilesLoading:A,inlineFilesError:P,selectedFile:R,diffContent:D,isLoading:F,isLoadingFiles:z,isLoadingDiff:O,commitError:_,detailError:B,setDiffContent:W,fetchCommits:H,handleCommitSelect:V,handleFileSelect:U,handleToggleInlineDiff:K,handleInlineDiffFile:$,handleRefresh:q}=function(e,t){let[n,a]=(0,o.useState)([]),[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)([]),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)(!0),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(null),[I,M]=(0,o.useState)(null),L=(0,o.useCallback)(async()=>{w(!0),E(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/log"));if(!t.ok){let e=await t.json();E(e.error||"Failed to fetch commit history");return}let n=await t.json();a(n.commits)}catch(e){E("Failed to fetch commit history")}finally{w(!1)}},[e]),A=(0,o.useCallback)(async t=>{N(!0),i([]),b(null),y(null),M(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json();M(e.error||"Failed to fetch commit details");return}let a=await n.json();i(a.files)}catch(e){M("Failed to fetch commit details")}finally{N(!1)}},[e]),P=(0,o.useCallback)(async(n,a)=>{S(!0),y(null),M(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();M(e.error||"Failed to fetch diff");return}let s=await r.json();y(s.diff),t(s.diff,a)}catch(e){M("Failed to fetch diff")}finally{S(!1)}},[e,t]);(0,o.useEffect)(()=>{L()},[L]);let R=(0,o.useCallback)(e=>{s(e),A(e)},[A]),D=(0,o.useCallback)(e=>{r&&(b(e),P(r,e))},[r,P]),F=(0,o.useCallback)(async t=>{if(c===t){d(null),m([]),g(null);return}d(t),m([]),g(null),x(!0);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json().catch(()=>({}));g(e.error||"Failed to fetch commit details");return}let a=await n.json();m(Array.isArray(a.files)?a.files:[])}catch(e){g("Failed to fetch commit details")}finally{x(!1)}},[e,c]),z=(0,o.useCallback)((e,t)=>{s(e),b(t),i(u),P(e,t)},[u,P]),O=(0,o.useCallback)(()=>{s(null),i([]),b(null),y(null),M(null),L()},[L]);return{commits:n,selectedCommit:r,changedFiles:l,inlineDiffCommit:c,inlineFiles:u,inlineFilesLoading:h,inlineFilesError:f,selectedFile:p,diffContent:v,isLoading:j,isLoadingFiles:k,isLoadingDiff:C,commitError:T,detailError:I,setDiffContent:y,fetchCommits:L,handleCommitSelect:R,handleFileSelect:D,handleToggleInlineDiff:F,handleInlineDiffFile:z,handleRefresh:O}}(l,i),J=(0,o.useCallback)(async()=>{await H(),await S()},[H,S]),{staged:Y,stagedLoading:G,stagedError:X,opBusy:Q,commitMessage:Z,setCommitMessage:ee,amend:et,setAmend:en,committing:ea,changesCommitError:er,fetchStaged:es,handleStage:el,handleUnstage:eo,handleChangesDiff:ei,fetchWorkingDiffText:ec,commit:ed,commitAndPush:eu}=function(e,t){let{onWorkingDiff:n,onCommitted:a}=t,[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)(!0),[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)(!1),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(!1),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),j=(0,o.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{i(!1)}},[e]);(0,o.useEffect)(()=>{j()},[j]);let w=(0,o.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,o.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,o.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:f})});if(!t.ok){let e=await t.json().catch(()=>({}));return y(e.error||"Failed to commit"),!1}return x(""),g(!1),await j(),await a(),!0}catch(e){return y("Failed to commit"),!1}},[e,h,f,j,a]),C=(0,o.useCallback)(async()=>{b(!0);try{await N()}finally{b(!1)}},[N]),S=(0,o.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:x,amend:f,setAmend:g,committing:p,changesCommitError:v,fetchStaged:j,handleStage:w,handleUnstage:k,handleChangesDiff:(0,o.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,o.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,o.useCallback)((e,t)=>{W(e),i(e,t)},[W,i]),onCommitted:J}),{branches:em,branchInclude:eh,branchesLoading:ex,branchesError:ef,branchBusy:eg,branchActionError:ep,fetchBranches:eb,handleBranchIncludeChange:ev,handleBranchesRefresh:ey,handleCheckout:ej,handleBranchCreate:ew,handleBranchDelete:ek}=function(e,t){let{onCheckoutCascade:n}=t,[a,r]=(0,o.useState)([]),[s,l]=(0,o.useState)("local"),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(null),[m,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)(null),g=(0,o.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,o.useEffect)(()=>{g(s)},[g,s]);let p=(0,o.useCallback)(e=>{l(e)},[]),b=(0,o.useCallback)(()=>{g(s)},[g,s]),v=(0,o.useCallback)(async(t,a)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to checkout branch");return}await Promise.all([n(),g(s)])}catch(e){f("Failed to checkout branch")}finally{h(!1)}},[e,s,n,g]),y=(0,o.useCallback)(async(t,n)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to create branch");return}await g(s)}catch(e){f("Failed to create branch")}finally{h(!1)}},[e,s,g]),j=(0,o.useCallback)(async(t,n)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to delete branch");return}await g(s)}catch(e){f("Failed to delete branch")}finally{h(!1)}},[e,s,g]);return{branches:a,branchInclude:s,branchesLoading:i,branchesError:d,branchBusy:m,branchActionError:x,fetchBranches:g,handleBranchIncludeChange:p,handleBranchesRefresh:b,handleCheckout:v,handleBranchCreate:y,handleBranchDelete:j}}(l,{onCheckoutCascade:(0,o.useCallback)(async()=>{await Promise.all([S(),es(),H()])},[S,es,H])}),{stashes:eN,stashLoading:eC,stashError:eS,stashBusy:eT,stashActionError:eE,stashConflictNotice:eI,fetchStash:eM,handleStashPush:eL,handleStashPop:eA,handleStashApply:eP,handleStashDrop:eR}=function(e,t){let{onStashMutated:n}=t,[a,r]=(0,o.useState)([]),[s,l]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),[m,h]=(0,o.useState)(null),[x,f]=(0,o.useState)(null),g=(0,o.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,o.useEffect)(()=>{g()},[g]);let p=(0,o.useCallback)(async()=>{await Promise.all([g(),n()])},[g,n]),b=(0,o.useCallback)(async(e,t,n)=>{u(!0),h(null),f(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)":"";f("Stash operation produced conflicts: ".concat(e).concat(t))}await p()}catch(e){h(n)}finally{u(!1)}},[p]),v=(0,o.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,o.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:i,stashBusy:d,stashActionError:m,stashConflictNotice:x,fetchStash:g,handleStashPush:v,handleStashPop:y,handleStashApply:(0,o.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,o.useCallback)(t=>{b("/api/worktrees/".concat(e,"/git/stash/").concat(t),{method:"DELETE"},"Failed to drop stash")},[e,b])}}(l,{onStashMutated:(0,o.useCallback)(async()=>{await Promise.all([S(),es()])},[S,es])}),{dangerBusy:eD,dangerActionError:eF,dangerConflictNotice:ez,handleReset:eO,handleRevert:e_}=function(e,t){let{onHeadMoved:n}=t,[a,r]=(0,o.useState)(!1),[s,l]=(0,o.useState)(null),[i,c]=(0,o.useState)(null);return{dangerBusy:a,dangerActionError:s,dangerConflictNotice:i,handleReset:(0,o.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,o.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,o.useCallback)(async()=>{await Promise.all([S(),es(),eb(eh),H()])},[S,es,eb,eh,H])}),{operation:eB,progressState:eW,error:eH,errorReason:eV,conflict:eU,conflictFiles:eK,runFetch:e$,runPull:eq,runPush:eJ,abort:eY}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{onCascade:n}=t,[a,r]=(0,o.useState)(null),[s,l]=(0,o.useState)("idle"),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(null),[m,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)([]),g=(0,o.useRef)(null),p=(0,o.useRef)(n);(0,o.useEffect)(()=>{p.current=n},[n]),(0,o.useEffect)(()=>()=>{var e;null==(e=g.current)||e.abort()},[]);let b=(0,o.useCallback)(async(t,n,a)=>{var s,o,i;c(null),u(null),h(!1),f([]),r(t),l("running");let d=new AbortController;g.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((o=null==e?void 0:e.error,"string"==typeof o&&o.length>0?o:null)),l("error");return}let i=await r.json().catch(()=>({success:!0}));"pull"===t&&(null==i?void 0:i.conflict)&&(h(!0),f(Array.isArray(i.conflictFiles)?i.conflictFiles:[])),l("idle")}catch(e){e instanceof Error&&"AbortError"===e.name?l("idle"):(c(null),u(null),l("error"))}finally{r(null),g.current=null,null==(i=p.current)||i.call(p,t)}},[e]),v=(0,o.useCallback)(e=>{let t={prune:!0===e.prune};return void 0!==e.remote&&(t.remote=e.remote),b("fetch","fetch",t)},[b]),y=(0,o.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:i,errorReason:d,conflict:m,conflictFiles:x,runFetch:v,runPull:y,runPush:(0,o.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,o.useCallback)(()=>{var e;null==(e=g.current)||e.abort()},[])}}(l,{onCascade:(0,o.useCallback)(e=>{S(),eb(eh),"pull"===e&&(es(),H())},[S,eb,eh,es,H])}),eG="auth_failed"===eV?f("git.network.authFailedGuidance"):"protected_branch"===eV?f("git.danger.protectedBranchWarning"):eH,eX="running"===eW&&("push"===eB||"pull"===eB),eQ=(null==k?void 0:k.aheadBehind)!=null,eZ=(0,o.useCallback)(()=>eu(()=>eJ({setUpstream:!eQ})),[eu,eJ,eQ]);nh({intervalMs:5e3,enabled:"running"!==eW,onPoll:S});let e0=(0,o.useMemo)(()=>({isMobile:d,onDiffSelect:i,onInsertToMessage:h}),[d,i,h]),e1=(0,r.jsx)(aV,{gitStatus:k,statusLoading:N,statusError:C,onRefresh:S}),e2=(0,r.jsx)(aU,{progressState:eW,operation:eB,error:eG,conflict:eU,conflictFiles:eK,hasUpstream:eQ,onPull:()=>eq({}),onPush:()=>eJ({setUpstream:!eQ}),onAbort:eY,extraActions:(0,r.jsx)(aE,{branches:em,busy:eg||eX,actionError:ep,hasRunningSession:w,isMobile:d,onCheckout:ej})}),e4=(0,r.jsx)(a$,{staged:Y,loading:G,error:X,busy:Q||eX,commitMessage:Z,amend:et,committing:ea,commitError:er,onRefresh:es,onDiff:ei,onPreview:ec,onStage:el,onUnstage:eo,onCommitMessageChange:ee,onAmendChange:en,onCommit:ed,onCommitAndPush:eZ}),e5=(0,r.jsx)(aq,{commits:T,isLoading:F,commitError:_,commitListOpen:b,onToggleCommitList:v,onRefresh:q,selectedCommit:E,onCommitSelect:V,inlineDiffCommit:M,inlineFiles:L,inlineFilesLoading:A,inlineFilesError:P,onToggleInlineDiff:K,onInlineDiffFile:$,changedFiles:I,isLoadingFiles:z,detailError:B,selectedFile:R,onFileSelect:U,diffContent:D,isLoadingDiff:O}),e3=(0,r.jsxs)(aI,{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:f("git.remote")}),(0,r.jsx)("div",{children:(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>e$({}),disabled:"running"===eW,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:f("git.network.fetch")})})]}),(0,r.jsx)(aG,{branches:em,include:eh,loading:ex,error:ef,busy:eg||eX,actionError:ep,onIncludeChange:ev,onRefresh:ey,onCreate:ew,onDelete:ek}),(0,r.jsx)(aX,{stashes:eN,loading:eC,error:eS,busy:eT||eX,actionError:eE,conflictNotice:eI,hasRunningSession:w,onRefresh:eM,onPush:eL,onPop:eA,onApply:eP,onDrop:eR}),(0,r.jsx)(aZ,{selectedCommit:E,busy:eD||eX,actionError:eF,conflictNotice:ez,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:eO,onRevert:e_,onForcePush:e=>eJ(e?{forceWithLease:!0}:{force:!0})})]});return(0,r.jsx)(aL,{value:e0,children:(0,r.jsx)(az,{activeTab:g,onTabChange:p,className:x,statusSection:e1,quickActionsSection:e2,changesSection:e4,historySection:e5,advancedSection:e3})})}),a1=(0,o.memo)(function(e){let{worktreeId:t,worktree:n,onWorktreeUpdate:a}=e,[s,l]=(0,o.useState)(!1),i=(0,c.c)("worktree"),d=(0,o.useRef)(null==n?void 0:n.id),u=(0,o.useRef)(!1),m=a6(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)(a8,{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:i("detail.loadingInfo")})}),a2=(0,o.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disableAutoFollow:s}=e,{terminal:l,setAutoScroll:o}=tu({worktreeId:t,cliToolId:n,instanceId:a});return(0,r.jsx)(tc,{output:l.output,isActive:l.isRunning,isThinking:l.isThinking,autoScroll:l.autoScroll,onScrollChange:o,disableAutoFollow:s,compactTuiLayoutPadding:"claude"===n||"codex"===n,className:"h-full"})}),a4=(0,o.memo)(function(e){let{activeTab:t,worktreeId:n,worktree:a,messages:s,cliToolId:l,instanceId:o,onFilePathClick:i,onFileSelect:d,onWorktreeUpdate:u,onNewFile:m,onNewDirectory:h,onRename:x,onDelete:f,onUpload:g,onMove:p,onFileTreeReset:b,refreshTrigger:v,fileSearch:y,showToast:j,selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:T,vibeLocalModel:E,onVibeLocalModelChange:I,vibeLocalContextWindow:M,onVibeLocalContextWindowChange:L,disableAutoFollow:A,historySubTab:P,onHistorySubTabChange:R,onDiffSelect:D,onInsertToMessage:F,showArchived:z,onShowArchivedChange:O,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:W,onHistoryUserOnlyChange:H,useInstanceManagement:V,instances:U,onInstancesChange:K,visibleInstanceIds:$,onToggleInstanceVisible:q}=e,J=(0,c.c)("worktree");switch(t){case"terminal":return(0,r.jsx)(S,{componentName:"TerminalDisplay",children:(0,r.jsx)(a2,{worktreeId:n,cliToolId:l,instanceId:o,disableAutoFollow:A})});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:()=>R("message"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("message"===P?"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:J("detail.subTabMessage")}),(0,r.jsx)("button",{type:"button",onClick:()=>R("git"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("git"===P?"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:J("detail.subTabGit")})]}),"message"===P?(0,r.jsx)(S,{componentName:"HistoryPane",children:(0,r.jsx)(t1,{messages:s,worktreeId:n,onFilePathClick:i,className:"flex-1 min-h-0",showToast:j,onInsertToMessage:F,showArchived:z,onShowArchivedChange:O,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:W,onHistoryUserOnlyChange:H})}):(0,r.jsx)(S,{componentName:"GitPane",children:(0,r.jsx)(a0,{worktreeId:n,onDiffSelect:D,isMobile:!0,worktree:null!=a?a:void 0,onInsertToMessage:F,className:"flex-1 min-h-0"})})]});case"files":var Y;return(0,r.jsx)(S,{componentName:"FileTreeView",children:(0,r.jsxs)("div",{className:"h-full flex flex-col overflow-hidden",children:[(0,r.jsx)(nj,{query:y.query,mode:y.mode,isSearching:y.isSearching,error:y.error,onQueryChange:y.setQuery,onModeChange:y.setMode,onClear:y.clearSearch}),(0,r.jsx)(np,{worktreeId:n,onFileSelect:d,onNewFile:m,onNewDirectory:h,onRename:x,onDelete:f,onUpload:g,onMove:p,onResetView:b,refreshTrigger:v,pollingEnabled:"files"===t,searchQuery:y.query,searchMode:y.mode,searchResults:null==(Y=y.results)?void 0:Y.results,className:"flex-1 min-h-0"})]})});case"memo":return(0,r.jsx)(S,{componentName:"NotesAndLogsPane",children:(0,r.jsx)(aj,{worktreeId:n,className:"h-full",selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:T,vibeLocalModel:E,onVibeLocalModelChange:I,vibeLocalContextWindow:M,onVibeLocalContextWindowChange:L,onInsertToMessage:F,useInstanceManagement:V,instances:U,onInstancesChange:K,visibleInstanceIds:$,onToggleInstanceVisible:q})});case"info":return(0,r.jsx)(a1,{worktreeId:n,worktree:a,onWorktreeUpdate:u});default:return null}}),a5="v".concat("0.10.1"),a3=[{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 a6(e,t,n,a){let[r,s]=(0,o.useState)(!1),[l,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(!1);(0,o.useEffect)(()=>{a()&&e&&(i(e.description||""),s(!1))},[n,e]);let u=(0,o.useCallback)(async()=>{if(e){d(!0);try{let n=await B.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,o.useCallback)(()=>{i((null==e?void 0:e.description)||""),s(!1)},[e]);return{isEditing:r,text:l,setText:i,isSaving:c,handleSave:u,handleCancel:m,startEditing:(0,o.useCallback)(()=>{s(!0)},[])}}let a8=(0,o.memo)(function(e){var t,n;let{worktreeId:a,worktree:s,cardClassName:l,descriptionEditor:i,showLogs:d,onToggleLogs:u,onWorktreeUpdate:h}=e,{isEditing:x,text:f,setText:g,isSaving:p,handleSave:b,handleCancel:v,startEditing:y}=i,j=(0,c.c)("worktree"),w=(0,c.c)("common"),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),T=(0,o.useRef)(void 0),E=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>{T.current&&clearTimeout(T.current),E.current&&clearTimeout(E.current)},[]);let I=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s.path),N(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>N(!1),et.pX)}catch(e){}},[s.path]),M=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s.repositoryPath),S(!0),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>S(!1),et.pX)}catch(e){}},[s.repositoryPath]);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:M,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)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:I,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)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:a3.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")}),!x&&(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")})]}),x?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("textarea",{value:f,onChange:e=>g(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:p,className:"px-4 py-2 bg-accent-600 text-white rounded-lg hover:bg-accent-700 disabled:opacity-50 text-sm font-medium",children:p?j("actions.saving"):j("actions.save")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:v,disabled:p,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)(e$,{version:a5,className:l}),(0,r.jsx)(eZ,{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)(eW,{worktreeId:a})]})]})}),a9=(0,o.memo)(function(e){var t,n,a,s;let{worktreeName:l,repositoryName:i,description:d,status:u,gitStatus:f,onBackClick:g,onInfoClick:p,hasUpdate:b,worktreeStatus:v,onWorktreeStatusChange:y,sessionStatusByCli:j,sessionStatusByInstance:w,instances:N,activeInstanceId:C,onActiveInstanceChange:S,onAgentDragStart:T,onAgentDragEnd:E,onKillSession:I}=e,M=(0,c.c)("worktree"),L=(0,c.c)("common"),A=eF.sb[u],P=A?M(A):void 0,[R,D]=(0,o.useState)(null),F=null==N?void 0:N.find(e=>e.id===C),z=!!C&&null!=(s=null!=(a=null==w||null==(t=w[C])?void 0:t.isRunning)?a:F?null==j||null==(n=j[F.cliTool])?void 0:n.isRunning:void 0)&&s,O=(0,o.useCallback)((e,t)=>{e.dataTransfer.setData(e5,t),e.dataTransfer.effectAllowed="move",D(t),null==T||T(t)},[T]),_=(0,o.useCallback)(()=>{D(null),null==E||E()},[E]),B=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:g,className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors","aria-label":M("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:M("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:P}),(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:i}),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:M("git.uncommittedChanges"),children:"*"})]}),B&&(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:B})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[N&&N.length>0&&(()=>{var e,t,n,a;let s=(0,e_.Uw)(N.map(e=>{var t;return{item:e,status:(0,e1.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),o=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;return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0","data-testid":"desktop-agent-status-row",children:[s.map(e=>{if("overflow"===e.slot)return null;let t=e.item,n=M("detail.statusPill",{label:(0,e2.sw)(t),status:L("status.".concat(e.status))}),a=e.isActive,s={draggable:!0,onDragStart:e=>O(e,t.id),onDragEnd:_},l=R===t.id?" opacity-50 cursor-grabbing":"";return"pill"===e.slot?(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-".concat(t.id),onClick:()=>null==S?void 0:S(t.id),...s,"aria-label":n,"aria-pressed":a,className:"flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ".concat(a?"bg-accent-100 dark:bg-accent-900/30 text-accent-900 dark:text-accent-100":"hover:bg-muted text-foreground").concat(l),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):(0,r.jsx)(ez.m_,{content:n,placement:"bottom",children:(0,r.jsx)("button",{type:"button","data-testid":"desktop-agent-status-".concat(t.id),onClick:()=>null==S?void 0:S(t.id),...s,"aria-label":n,"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 rounded-full transition-colors ".concat(a?"bg-accent-100 dark:bg-accent-900/30":"hover:bg-muted").concat(l),children:(0,r.jsx)(h.m,{status:e.status,size:"sm","aria-hidden":!0,title:void 0})})},t.id)}),l.length>0&&(0,r.jsxs)(eO.rI,{children:[(0,r.jsx)(eO.ty,{asChild:!0,children:(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-overflow","aria-label":M("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:[o&&(0,r.jsx)(h.m,{status:o,size:"sm","aria-hidden":!0,title:void 0}),"+",l.length]})}),(0,r.jsx)(eO.SQ,{align:"end",children:l.map(e=>{let t=e.item,n=M("detail.statusPill",{label:(0,e2.sw)(t),status:L("status.".concat(e.status))});return(0,r.jsxs)(eO._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)})})]})]})})(),I&&z&&(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:I,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":M("terminal.endSession"),"data-testid":"desktop-kill-session",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"✕"}),L("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":M("detail.worktreeStatusLabel"),children:a3.map(e=>{var t;return(0,r.jsx)("option",{value:null!=(t=e.value)?t:"",children:M(e.labelKey)},e.labelKey)})}),(0,r.jsx)(e6.g,{}),(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:p,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":M("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:M("detail.info")}),b&&(0,r.jsx)(k,{"data-testid":"info-update-indicator",className:"absolute top-0 right-0","aria-label":M("tabs.updateAvailable")})]})]})]})}),a7=(0,o.memo)(function(e){let{worktreeId:t,worktree:n,isOpen:a,onClose:s,onWorktreeUpdate:l}=e,[i,d]=(0,o.useState)(!1),u=(0,c.c)("worktree"),m=(0,o.useRef)(a),h=a6(n,l,a,()=>{let e=a&&!m.current;return m.current=a,e});return n?(0,r.jsx)(e0.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)(a8,{worktreeId:t,worktree:n,cardClassName:"bg-muted rounded-lg p-4",descriptionEditor:h,showLogs:i,onToggleLogs:()=>d(!i),onWorktreeUpdate:l})})}):null}),re=(0,o.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")})]})})}),rt=(0,o.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")})]})})}),rn=(0,o.memo)(function(e){let{activityPane:t,rightPane:n,activityPaneWidth:a=18,minPaneWidth:s=10,maxPaneWidth:l=60,onActivityPaneResize:i,className:d=""}=e,u=(0,o.useRef)(null),m=(0,c.c)("worktree"),[h,x]=(0,o.useState)(a),f=i?a:h,g=(0,o.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,(i?a:h)+e/n*100));i?i(r):x(r)},[a,h,s,l,i]),p=(0,o.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:p,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(f,"%")},className:"flex-shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",children:(0,r.jsx)(S,{componentName:"ActivityPane",children:t})}),(0,r.jsx)(tV.f,{onResize:g,orientation:"horizontal",ariaValueNow:f})]}),(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)(S,{componentName:"TerminalPane",children:n})})]})})});var ra=n(9540),rr=n(92001),rs=n(39332),rl=n(11047),ro=n(16485),ri=n(78192),rc=n(39324),rd=n(80298);let ru=[{id:"files",labelKey:"activityBar.files",icon:rr.A},{id:"git",labelKey:"activityBar.git",icon:rs.A},{id:"notes",labelKey:"activityBar.notes",icon:rl.A},{id:"schedules",labelKey:"activityBar.schedules",icon:ro.A},{id:"agent",labelKey:"activityBar.agent",icon:ri.A},{id:"timer",labelKey:"activityBar.timer",icon:rc.A},{id:"todo",labelKey:"activityBar.todo",icon:rd.A}],rm=new Set(ru.map(e=>e.id)),rh="files",rx="__closed__";function rf(e){return"".concat("commandmate.worktree.activeActivity-").concat(e)}var rg=n(32916);let rp=(0,o.memo)(function(e){let{active:t,onToggle:n,className:a=""}=e,s=(0,c.c)("worktree"),l=(0,o.useRef)([]),{isOpen:i,toggle:d}=(0,rg.VF)(),u=(0,o.useCallback)((e,t,a)=>{var r,s,o,i;if("Enter"===e.key||" "===e.key){e.preventDefault(),n(a);return}if("ArrowDown"===e.key){e.preventDefault();let n=(t+1)%ru.length;null==(r=l.current[n])||r.focus();return}if("ArrowUp"===e.key){e.preventDefault();let n=(t-1+ru.length)%ru.length;null==(s=l.current[n])||s.focus();return}if("Home"===e.key){e.preventDefault(),null==(o=l.current[0])||o.focus();return}if("End"===e.key){e.preventDefault(),null==(i=l.current[ru.length-1])||i.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)(ez.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":i,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)(ra.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:ru.map((e,a)=>{let o=e.icon,i=t===e.id,c=s(e.labelKey);return(0,r.jsx)(ez.m_,{content:c,placement:"right",children:(0,r.jsx)("button",{ref:e=>{l.current[a]=e},type:"button",role:"tab","aria-selected":i,"aria-label":c,"aria-controls":"worktree-activity-pane",tabIndex:i||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(i?"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)(o,{size:20,"aria-hidden":"true"})})})},e.id)})})]})}),rb="worktree-activity-pane",rv={files:"FileTreeView",git:"GitPane",notes:"MemoPane",schedules:"ExecutionLogPane",agent:"AgentSettingsPane",timer:"TimerPane",todo:"TodoPane"},ry=(0,o.memo)(function(e){let{active:t,activities:n,className:a=""}=e;if(null===t)return(0,r.jsx)("div",{id:rb,"data-testid":"activity-pane","data-active":"none",className:"h-full flex flex-col ".concat(a).trim()});let s=n[t],l=rv[t];return(0,r.jsx)("div",{id:rb,"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)(S,{componentName:l,children:null!=s?s:null})})}),rj=(0,o.memo)(function(e){let{inputRef:t,searchQuery:n,onQueryChange:a,matchCount:s,currentIdx:l,onNextMatch:o,onPrevMatch:i,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.shiftKey?i():o())},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: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.prevMatch"),children:"▲"}),(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.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)(em.A,{className:"w-4 h-4"})})]})}),rw=[{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"]}],rk=rw.map(e=>e.extension),rN=[".md",".html",".htm",".yaml",".yml"];ed.j6,ed.j6;var rC=n(40051);function rS(){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 rT=(0,i.default)(()=>n.e(530).then(n.bind(n,530)).then(e=>({default:e.HtmlPreview})),{loadableGenerated:{webpack:()=>[530]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rE=(0,i.default)(()=>Promise.resolve().then(n.bind(n,27307)).then(e=>({default:e.PdfPreview})),{loadableGenerated:{webpack:()=>[27307]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rI=(0,i.default)(()=>Promise.all([n.e(8566),n.e(934),n.e(6416),n.e(8676)]).then(n.bind(n,98676)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[98676]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rM=/^---\s*\nmarp:\s*true/;function rL(){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 rA(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 rP(e){let{filePath:t,isMaximized:n,onToggleMaximize:a,copyableContent:s,onSearch:l}=e,i=(0,c.c)("worktree"),[d,u]=(0,o.useState)(!1),[m,h]=(0,o.useState)(!1),x=(0,o.useRef)(null),f=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{x.current&&clearTimeout(x.current),f.current&&clearTimeout(f.current)},[]);let g=async()=>{try{await (0,eu.l)(t),u(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>u(!1),et.pX)}catch(e){}},p=async()=>{if(s)try{await (0,eu.l)(s),h(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>h(!1),et.pX)}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:g,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:d?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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)(z.A,{className:"w-3.5 h-3.5"})}),s&&(0,r.jsx)("button",{type:"button",onClick:p,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:m?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ep.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)(eb.A,{className:"w-4 h-4"}):(0,r.jsx)(ev.A,{className:"w-4 h-4"})})]})]})}function rR(e){var t;let{content:n,extension:a,searchMatches:s,searchCurrentIdx:l,totalLines:i,rangeStart:c,worktreeId:d,filePath:u,onLineRangeFetched:m}=e,h=(0,o.useRef)(null),x=(0,o.useMemo)(()=>n.split("\n"),[n]),f=Math.max(1,null!=c?c:1),g=x.length,p=Math.max(null!=i?i:g,g),b=(0,o.useRef)(new Map);(0,o.useEffect)(()=>{b.current.clear()},[n,a]);let v=(0,o.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,x.length),l=x.slice(e,t).join("\n"),o="";try{o=eM.A.highlight(l,{language:a,ignoreIllegals:!0}).value}catch(e){o=eM.A.highlightAuto(l).value}s=o.split("\n"),r.set(n,s)}return null!=(t=s[e-500*n])?t:""},[x,a]),y=(0,o.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,tm.Te)({count:p,getScrollElement:()=>h.current,estimateSize:()=>24,overscan:100});(0,o.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(p-1,e-1));w.scrollToIndex(t,{align:"center"})},[l,s,w,p]);let k=w.getVirtualItems();return!function(e){let{virtualItems:t,worktreeId:n,filePath:a,onLineRangeFetched:r,loadedStart:s,loadedLineCount:l}=e,i=(0,o.useRef)(new Set);(0,o.useEffect)(()=>{if(!n||!a||!r||0===t.length)return;let e=t[0].index+1,o=t[t.length-1].index+1,c=s+l-1;if(e>=s&&o<=c)return;let d=Math.max(1,500*Math.floor((e-1)/500)+1),u=d+500-1;i.current.has(d)||(i.current.add(d),fetch("/api/worktrees/".concat(n,"/files/").concat((0,ej.o)(a),"?startLine=").concat(d,"&endLine=").concat(u)).then(async e=>e.ok?e.json():null).then(e=>{i.current.delete(d),e&&!0===e.success&&r({content:e.content,range:e.range,totalLines:e.totalLines,totalBytes:e.totalBytes})}).catch(()=>{i.current.delete(d)}))},[t,n,a,r,s,l])}({virtualItems:k,worktreeId:d,filePath:u,onLineRangeFetched:m,loadedStart:f,loadedLineCount:g}),(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-f,a=n>=0&&n<g,s=t===j,l=y.has(t),o=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:o}}):(0,r.jsx)(rC.E,{className:"h-4 w-3/4"})})]},e.key)})})})}function rD(e){let{slides:t,fileName:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.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 rF(e){let{marpSlides:t,fileName:n,worktreeId:a,filePath:s,contentText:l,onFileSaved:i,isMaximized:d,onToggleMaximize:u,onDirtyChange:m,onOpenFile:h}=e,x=(0,c.c)("worktree"),[f,g]=(0,o.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:()=>g("slides"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("slides"===f?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:x("fileViewer.slides")}),(0,r.jsx)("button",{type:"button",onClick:()=>g("editor"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("editor"===f?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:x("fileViewer.editor")})]}),(0,r.jsx)(rP,{filePath:s,isMaximized:d,onToggleMaximize:u,copyableContent:l})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:"slides"===f?(0,r.jsx)(rD,{slides:t,fileName:n}):(0,r.jsx)(rI,{worktreeId:a,filePath:s,onSave:i,initialViewMode:"split",onDirtyChange:m,onOpenFile:h})})]})}function rz(e){let{children:t,isMaximized:n,onToggle:a,filePath:s}=e;return n?(0,r.jsxs)("div",{className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:ey.M.MAXIMIZED_EDITOR},children:[(0,r.jsx)(rP,{filePath:s,isMaximized:n,onToggleMaximize:a}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:t})]}):(0,r.jsx)(r.Fragment,{children:t})}function rO(e){let{tab:t,content:n,worktreeId:a,isMaximized:s,onToggleMaximize:l,onFileSaved:o,onDirtyChange:i,onOpenFile:c}=e,d=eI(n.content);return(0,r.jsxs)(r.Fragment,{children:[!s&&(0,r.jsx)(rP,{filePath:t.path,isMaximized:s,onToggleMaximize:l,copyableContent:n.content,onSearch:d.openSearch}),d.searchOpen&&(0,r.jsx)(rj,{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)(rR,{content:n.content,extension:"md",searchMatches:d.searchMatches,searchCurrentIdx:d.searchCurrentIdx}):(0,r.jsx)(rI,{worktreeId:a,filePath:t.path,onSave:o,initialViewMode:"preview",onDirtyChange:i,onOpenFile:c})})]})}function r_(e){var t,n;let{tab:a,content:s,worktreeId:l,isMaximized:i,onToggleMaximize:c,onLoadContent:d}=e,u=eI(s.content),m=(0,o.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)(rP,{filePath:a.path,isMaximized:i,onToggleMaximize:c,copyableContent:s.content,onSearch:u.openSearch}),u.searchOpen&&(0,r.jsx)(rj,{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)(rR,{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 rB=(0,o.memo)(function(e){var t,n,a,s;let{tab:l,worktreeId:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,onDirtyChange:x,onOpenFile:f}=e,g=(0,c.c)("worktree"),p=(0,o.useRef)(g);p.current=g;let b=(0,o.useRef)(!1),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)(!1);!function(e){let{tab:t,worktreeId:n,onLoadContent:a}=e,r=(0,o.useRef)(null),s=(0,o.useRef)(a);s.current=a;let l=(0,o.useRef)(t.path);l.current=t.path,nh({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,ej.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:i,onLoadContent:d});let k=(0,o.useMemo)(()=>x?e=>x(l.path,e):void 0,[x,l.path]),N=(0,o.useCallback)(()=>{w(e=>!e)},[]);(0,o.useEffect)(()=>{if(!j)return;let e=e=>{"Escape"===e.key&&w(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j]),(0,o.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(i,"/files/").concat((0,ej.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)||p.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:p.current("fileViewer.loadError"))}finally{b.current=!1}})())},[l.content,l.loading,l.error,l.path,i,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,o.useEffect)(()=>{if(!C||"md"!==S||!rM.test(C)||C.length>1e6)return void y(null);let e=!1;return(async()=>{try{let t=await fetch("/api/worktrees/".concat(i,"/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,i]),l.loading)return(0,r.jsx)(rL,{});if(l.error)return(0,r.jsx)(rA,{error:l.error});if(!l.content)return null;let{content:T}=l;return T.isImage?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(eo.a,{src:T.content,alt:T.path,mimeType:T.mimeType})})]})}):T.isVideo?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(ei.u,{src:T.content,mimeType:T.mimeType})})]})}):T.isPdf?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(rE,{dataUri:T.content,filePath:l.path})})]})}):T.isHtml?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N,copyableContent:T.content}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(rT,{worktreeId:i,filePath:l.path,htmlContent:T.content,onFileSaved:h,onOpenFile:f})})]})}):"md"===T.extension?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:v?(0,r.jsx)(rF,{marpSlides:v,fileName:l.name,worktreeId:i,filePath:l.path,contentText:T.content,onFileSaved:h,isMaximized:j,onToggleMaximize:N,onDirtyChange:k,onOpenFile:f}):(0,r.jsx)(rO,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:f})})}):!function(e){if(!e)return!1;let t=e.toLowerCase();return rN.includes(t)}("."+T.extension)?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)(r_,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onLoadContent:d})}):(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:(0,r.jsx)(rO,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:f})})})}),rW=(0,o.memo)(function(e){let{tab:t,isActive:n,onActivate:a,onClose:s}=e,l=(0,c.c)("worktree"),i=(0,o.useCallback)(()=>{n||a(t.path)},[n,a,t.path]),d=(0,o.useCallback)(e=>{e.stopPropagation(),s(t.path)},[s,t.path]),u=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:i,className:"flex items-center gap-1 px-3 py-2 text-sm font-medium border-b-2 cursor-pointer flex-shrink-0 ".concat(u),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:l("fileTabs.unsavedChanges")}),(0,r.jsx)("button",{type:"button",onClick:d,className:"ml-1 p-0.5 rounded-sm hover:bg-muted transition-colors","aria-label":l("fileTabs.closeTab",{name:t.name}),children:(0,r.jsx)(em.A,{className:"w-3 h-3"})})]})}),rH=(0,o.memo)(function(e){let{tabs:t,activeIndex:n,worktreeId:a,onClose:s,onActivate:l,onLoadContent:i,onLoadError:c,onSetLoading:d,onFileSaved:u,onDirtyChange:m,onMoveToFront:h,onOpenFile:x}=e,[f,g]=(0,o.useState)(!1),p=(0,o.useRef)(null),b=null!==n&&n>=0&&n<t.length?t[n]:null,v=t.length>5?t.slice(0,5):t,y=t.length>5?t.slice(5):[];(0,o.useEffect)(()=>{if(!f)return;let e=e=>{p.current&&!p.current.contains(e.target)&&g(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[f]);let j=(0,o.useCallback)(e=>{g(!1),null==h||h(e)},[h]),w=(0,o.useCallback)(()=>{g(e=>!e)},[]);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:v.map((e,t)=>(0,r.jsx)(rW,{tab:e,isActive:t===n,onActivate:l,onClose:s},e.path))}),y.length>0&&(0,r.jsxs)("div",{className:"relative flex-shrink-0",ref:p,children:[(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-button",onClick:w,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)(e4.A,{className:"w-3 h-3 transition-transform ".concat(f?"rotate-180":"")}),(0,r.jsxs)("span",{children:["+",y.length]})]}),f&&(0,r.jsx)("div",{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",children:y.map(e=>(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-item-".concat(e.path),onClick:()=>j(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))})]})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:b&&(0,r.jsx)(rB,{tab:b,worktreeId:a,onLoadContent:i,onLoadError:c,onSetLoading:d,onFileSaved:u,onDirtyChange:m,onOpenFile:x},b.path)})]})}),rV=(0,o.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})}),rU=(0,o.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)(rV,{line:e},t))})})})]})}),rK="commandmate.worktree.filePanelCollapsed",r$="commandmate:filePanelStateChange";function rq(){let[e,t]=(0,o.useState)(!1),n=(0,o.useRef)(e);n.current=e,(0,o.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(rK);if("true"===e)return!0}catch(e){}return!1}())},[]),(0,o.useEffect)(()=>{let e=e=>{e.detail&&e.detail.collapsed!==n.current&&t(e.detail.collapsed)};return window.addEventListener(r$,e),()=>window.removeEventListener(r$,e)},[]);let a=(0,o.useCallback)(e=>{t(e);try{window.localStorage.setItem(rK,String(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(r$,{detail:{collapsed:e}}))}catch(e){}},[]);return{collapsed:e,toggle:(0,o.useCallback)(()=>{a(!n.current)},[a]),setCollapsed:a}}let rJ=(0,o.memo)(function(e){let{terminal:t,terminalHeader:n,fileTabs:a,worktreeId:s,onCloseTab:l,onActivateTab:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,diffContent:x,diffFilePath:f,onCloseDiff:g,onDirtyChange:p,onMoveToFront:b,onOpenFile:v}=e,y=(0,c.c)("worktree"),j=(0,o.useRef)(null),[w,k]=(0,o.useState)(50),{collapsed:N,toggle:C}=rq(),S=(0,o.useCallback)(e=>{let t=j.current;if(!t)return;let n=t.offsetWidth;if(0===n)return;let a=e/n*100;k(e=>Math.min(80,Math.max(20,e+a)))},[]),T=(0,o.useMemo)(()=>({width:"".concat(w,"%")}),[w]),E=(0,o.useMemo)(()=>({width:"".concat(100-w,"%")}),[w]),I=(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||x&&f?N?(0,r.jsxs)("div",{ref:j,className:"flex h-full min-h-0",children:[(0,r.jsx)("div",{"data-testid":"terminal-pane",style:{width:"calc(100% - ".concat(36,"px)")},className:"flex-shrink-0 overflow-hidden",children:I}),(0,r.jsx)("div",{"data-testid":"file-panel-expand-bar",style:{width:"".concat(36,"px")},className:"flex-shrink-0 flex items-start justify-center bg-muted border-l border-border",children:(0,r.jsxs)("button",{type:"button","aria-label":y("terminal.showFiles"),title:y("terminal.showFiles"),onClick:C,className:"flex flex-col items-center gap-2 w-full pt-2 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:y("terminal.filesLabel")})]})})]}):(0,r.jsxs)("div",{ref:j,className:"flex h-full min-h-0",children:[(0,r.jsx)("div",{"data-testid":"terminal-pane",style:T,className:"flex-shrink-0 overflow-hidden",children:I}),(0,r.jsx)(tV.f,{onResize:S,orientation:"horizontal",ariaValueNow:w}),(0,r.jsxs)("div",{"data-testid":"file-panel-pane",style:E,className:"flex-grow overflow-hidden flex",children:[(0,r.jsx)("button",{type:"button","aria-label":y("terminal.hideFiles"),title:y("terminal.hideFiles"),onClick:C,className:"flex-shrink-0 flex items-center justify-center w-5 h-full bg-muted border-r border-border text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",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:"M9 5l7 7-7 7"})})}),(0,r.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:x&&f&&g?(0,r.jsx)(rU,{diff:x,filePath:f,onClose:g}):(0,r.jsx)(rH,{tabs:a.tabs,activeIndex:a.activeIndex,worktreeId:s,onClose:l,onActivate:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,onDirtyChange:p,onMoveToFront:b,onOpenFile:v})})]})]}):(0,r.jsx)("div",{className:"h-full",children:I})});var rY=n(7125),rG=n(22509),rX=n(54485),rQ=n(70198);let rZ={splits:[{cliToolId:"claude",instanceId:"claude"}],widths:[1]},r0=new Set(e2.XH);function r1(e){return"".concat("commandmate:terminalSplits:").concat(e)}function r2(e){return"object"==typeof e&&null!==e}function r4(e){let t=e[0];return t?{splits:[{cliToolId:t.cliTool,instanceId:t.id}],widths:[1]}:{splits:rZ.splits.map(e=>({...e})),widths:[...rZ.widths]}}function r5(e){let t=e.reduce((e,t)=>e+t,0);return t>0?e.map(e=>e/t):e.map(()=>1/e.length)}function r3(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,3),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?r5(e.widths):l.length<e.widths.length?r5(e.widths.slice(0,l.length)):Array.from({length:l.length},()=>1/l.length),{splits:l,widths:n})}function r6(e,t,n){let a=function(e,t){try{let n=window.localStorage.getItem(r1(e));if(!n)return r4(t);let a=JSON.parse(n),r=function(e){if(!r2(e))return null;let{splits:t,widths:n}=e;if(!Array.isArray(t)||!Array.isArray(n)||t.length<1||t.length>3||n.length!==t.length)return null;let a=[];for(let e of t){if(!r2(e))return null;let t=e.cliToolId;if("string"!=typeof t||!r0.has(t))return null;let n=e.instanceId,r="string"==typeof n&&(0,e2.n6)(n)?n:t;a.push({cliToolId:t,instanceId:r})}for(let e of n)if("number"!=typeof e||!Number.isFinite(e)||e<=0)return null;return{splits:a,widths:n}}(a);if(r)return{...r,widths:r5(r.widths)};return console.warn("[useTerminalSplits] stale state for ".concat(e,"; falling back to default")),r4(t)}catch(n){return console.warn("[useTerminalSplits] failed to parse stored state for ".concat(e,"; using default"),n),r4(t)}}(e,t);return n?r3(a,t):a}let r8=(0,o.memo)(function(e){let{worktreeId:t,instances:n,rosterReady:a=!0,renderPane:s,onFocusedSplitChange:l,showToast:i,onActiveInstanceChange:d,headerInstanceSelection:u}=e,{splits:m,widths:h,addSplit:x,removeSplit:f,setSplitInstance:g,setSplitWidth:p,resetWidths:b,availableInstanceIds:v,focusedSplitIndex:y,setFocusedSplitIndex:j}=function(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2],[a,r]=(0,o.useState)(()=>r6(e,t,n)),[s,l]=(0,o.useState)(0),i=(0,o.useRef)(a);i.current=a;let c=(0,o.useRef)(t);c.current=t;let d=(0,o.useRef)(n);d.current=n;let u=(0,o.useRef)(e);(0,o.useEffect)(()=>{u.current!==e&&(u.current=e,r(r6(e,c.current,d.current)),l(0))},[e]);let m=(0,o.useMemo)(()=>t.map(e=>"".concat(e.id,":").concat(e.cliTool)).join("|"),[t]);(0,o.useEffect)(()=>{n&&r(e=>r3(e,c.current))},[m,n]);let h=(0,o.useRef)(e);(0,o.useEffect)(()=>{if(h.current!==e){h.current=e;return}try{window.localStorage.setItem(r1(e),JSON.stringify(a))}catch(e){}},[a,e]);let x=(0,o.useCallback)(()=>{r(e=>{if(e.splits.length>=3)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}(c.current,t);if(!n)return e;let a=e.widths.length-1,r=e.widths[a]/2,s=[...e.widths];return s[a]=r,s.push(r),{splits:[...e.splits,{cliToolId:n.cliTool,instanceId:n.id}],widths:s}})},[]),f=(0,o.useCallback)(()=>{r(e=>e.splits.length<=1?e:{splits:e.splits.slice(0,-1),widths:r5(e.widths.slice(0,-1))})},[]);(0,o.useEffect)(()=>{l(e=>{let t=a.splits.length-1;return e>t?t:e<0?0:e})},[a.splits.length]);let g=(0,o.useCallback)((e,t)=>{let n=i.current,a=c.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},[]),p=(0,o.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]})},[]),b=(0,o.useCallback)(()=>{r(e=>{let t=e.splits.length;return 0===t?e:{...e,widths:Array.from({length:t},()=>1/t)}})},[]),v=(0,o.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]),y=(0,o.useCallback)(e=>{l(e)},[]);return{splits:a.splits,widths:a.widths,addSplit:x,removeSplit:f,setSplitInstance:g,setSplitWidth:p,resetWidths:b,availableInstanceIds:v,focusedSplitIndex:s,setFocusedSplitIndex:y}}(t,n,a),w=(0,o.useMemo)(()=>{let e=new Map;for(let t of n)e.set(t.id,t);return e},[n]),k=(0,c.c)("worktree"),{visible:N,toggle:C,setWidth:S}=tH(),{collapsed:T,toggle:E}=rq(),I=!T,M=(0,o.useRef)(null),[L,A]=(0,o.useState)(!1),P=(0,o.useRef)(m.length),[R,D]=(0,o.useState)(null);(0,o.useEffect)(()=>{m.length>P.current&&D(m.length-1),P.current=m.length},[m.length]),(0,o.useEffect)(()=>{null==l||l(y)},[y,l]);let F=(0,o.useRef)(0),z=(0,o.useRef)(m);z.current=m,(0,o.useEffect)(()=>{if(!u||u.token===F.current)return;F.current=u.token;let{instanceId:e}=u,t=z.current.findIndex(t=>t.instanceId===e);if(0!==t){if(t>0)return void j(t);g(0,e)&&j(0)}},[u,g,j]),(0,o.useEffect)(()=>{if(null===R)return;let e=M.current;if(!e)return;let t=e.querySelector('[data-split-index="'.concat(R,'"]'));if(!t)return;let n=t.querySelector("textarea");null==n||n.focus(),j(R),D(null)},[R,j]);let O=(0,o.useCallback)((e,t)=>{let n=M.current;if(!n)return;let a=n.offsetWidth;if(0===a)return;let r=h.reduce((e,t)=>e+t,0),s=t/a*r,l=[...h],o=l[e]+s,i=l[e+1]-s,c=.05*r;o<c||i<c||(l[e]=o,l[e+1]=i,p(l))},[h,p]),_=(0,o.useCallback)(()=>A(!0),[]),B=(0,o.useCallback)(()=>A(!1),[]),W=(0,o.useCallback)(()=>{b(),S(40)},[b,S]),H=m.length<3&&!L,V=m.length>1&&!L,U=m.length>1||N,K=(0,o.useMemo)(()=>m.map((e,t)=>()=>j(t)),[m,j]),$=(0,o.useMemo)(()=>m.map((e,t)=>e=>g(t,e)),[m,g]),q=(0,o.useMemo)(()=>m.map((e,t)=>e=>{var n,a;let r=(0,e2.sw)(null!=(a=w.get(e))?a:{cliTool:"claude",alias:e});if((null==(n=m[t])?void 0:n.instanceId)===e)return;let s=m.findIndex((n,a)=>a!==t&&n.instanceId===e);if(-1!==s){null==i||i("".concat(r," is already in use by split ").concat(s+1),"warning");return}g(t,e)&&(null==d||d(e),null==i||i("Moved ".concat(r," to Split ").concat(t+1),"success"))}),[m,g,i,d,w]);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.jsxs)("span",{className:"text-xs text-muted-foreground tabular-nums mr-1",children:[m.length," / ",3," splits"]}),(0,r.jsx)("button",{type:"button",onClick:x,disabled:!H,"aria-disabled":!H,"aria-label":k("terminal.addSplit"),title:k("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)(as.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:f,disabled:!V,"aria-disabled":!V,"aria-label":k("terminal.removeSplit"),title:k("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)(rY.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:W,disabled:!U,"aria-disabled":!U,"aria-label":k("terminal.equalizeWidthsHint"),title:k("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)(rG.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.jsxs)("button",{type:"button",onClick:C,"aria-pressed":N,"aria-label":k(N?"terminal.hideHistory":"terminal.showHistory"),title:k(N?"terminal.hideHistory":"terminal.showHistory"),"data-testid":"toggle-history-pane",className:"flex items-center gap-1 text-xs px-2 py-0.5 rounded border transition-colors ".concat(N?"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)(rX.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("terminal.historyLabel")})]}),(0,r.jsxs)("button",{type:"button",onClick:E,"aria-pressed":I,"aria-label":k(I?"terminal.hideFiles":"terminal.showFiles"),title:k(I?"terminal.hideFiles":"terminal.showFiles"),"data-testid":"toggle-file-panel",className:"flex items-center gap-1 text-xs px-2 py-0.5 rounded border transition-colors ".concat(I?"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)(rQ.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("terminal.filesLabel")})]})]}),(0,r.jsx)("div",{ref:M,className:"flex flex-1 min-h-0 w-full",children:m.map((e,t)=>{var n;let a=t===m.length-1;return(0,r.jsxs)(o.Fragment,{children:[(0,r.jsx)("div",{style:{flexGrow:null!=(n=h[t])?n:1,flexShrink:1,flexBasis:0,minWidth:0},className:"h-full",children:s({splitIndex:t,cliToolId:e.cliToolId,instanceId:e.instanceId,instance:w.get(e.instanceId),availableInstances:v(t).map(e=>w.get(e)).filter(e=>void 0!==e),onInstanceChange:$[t],onFocus:K[t],isFocused:y===t,onDropInstance:q[t]})}),a?null:(0,r.jsx)(r9,{resizerIdx:t,ariaValueNow:h.length?h[t]/h.reduce((e,t)=>e+t,0)*100:50,onResize:O,onStart:_,onEnd:B,onDoubleClick:b})]},"split-".concat(t))})})]})});function r9(e){let{resizerIdx:t,ariaValueNow:n,onResize:a,onStart:s,onEnd:l,onDoubleClick:i}=e,c=(0,o.useCallback)(e=>a(t,e),[t,a]);return(0,r.jsx)("div",{"data-testid":"split-resizer-".concat(t),onMouseDownCapture:s,onTouchStartCapture:s,onMouseUpCapture:l,onTouchEndCapture:l,children:(0,r.jsx)(tV.f,{onResize:c,orientation:"horizontal",ariaValueNow:n,onDoubleClick:i})})}let r7={key:"Escape",label:"Esc",ariaLabel:"Send Escape"},se=[r7,{key:"q",label:"q",ariaLabel:"Send q (quit)"}];function st(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,[l,i]=(0,o.useState)(null),c=en(t,n,a,s),d="codex"===n?se:[r7],u=(0,o.useCallback)(e=>{i(e),setTimeout(()=>i(null),et.tX),c([e])},[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 escape keys",children:[(0,r.jsx)("span",{className:"text-xs text-amber-700 dark:text-amber-400 mx-2",title:"Send an escape key when the terminal is stuck in a TUI mode",children:"Escape"}),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)})]})}let sn="\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(),sa="bg-accent-600 text-white hover:bg-accent-700 focus:ring-ring";function sr(e){let{promptData:t,answering:n,onRespond:a,onDismiss:s,labelId:l,cliToolName:i}=e,d=(0,c.c)("prompt"),[u,h]=(0,o.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,f]=(0,o.useState)(""),[g,p]=(0,o.useState)(!1),b=(0,o.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===u))?e:null},[t,u]),v=(null==b?void 0:b.requiresTextInput)===!0,y=n||g,j=(0,o.useCallback)(async e=>{if(!y){p(!0);try{await a(e)}catch(e){}finally{p(!1)}}},[y,a]),w=(0,o.useCallback)(async()=>{if(!y&&null!==u){p(!0);try{let e=v&&x.trim()?x.trim():u.toString();await a(e)}catch(e){}finally{p(!1)}}},[y,a,u,v,x]);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:l,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:"?"}),i?d("confirmationFrom",{toolName:i}):d("confirmationFromClaude")]}),s&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:s,"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"})})})]}),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}),y&&(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:d("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(ss,{promptData:t,disabled:y,onYes:()=>j("yes"),onNo:()=>j("no")}),"multiple_choice"===t.type&&(0,r.jsx)(sl,{promptData:t,disabled:y,selectedOption:u,onSelectOption:h,textInputValue:x,onTextInputChange:f,showTextInput:v,onSubmit:w})]})}function ss(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),o="yes"===t.defaultOption,i="no"===t.defaultOption,d="".concat(sn," ").concat(sa," ").concat(o?"primary default highlighted":""),u="".concat(sn," ").concat(i?"bg-foreground text-background hover:bg-foreground/90 primary default highlighted":"bg-surface border-2 border-input hover:bg-muted text-foreground focus:ring-ring");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 sl(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:i,showTextInput:d,onSubmit:u}=e,h=(0,o.useId)(),x=(0,c.c)("prompt"),f=(0,o.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:x("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:f(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:x("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:x("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>i(e.target.value),disabled:n,placeholder:x("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(sn," ").concat(sa),children:x("submit")})]})}let so=(0,o.memo)(function(e){let t,{promptData:n,messageId:a,visible:s,answering:l,onRespond:i,onDismiss:c,cliToolName:d}=e,{shouldRender:u,animationClass:m}=I({visible:s&&null!==n,duration:200}),h=(0,o.useId)();if(!u||!n)return null;let x=(t="opacity-100","animate-fade-in"===m?t="opacity-100 transform translate-y-0":"animate-fade-out"===m&&(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(m," ").concat(t));return(0,r.jsx)(S,{componentName:"PromptPanel",children:(0,r.jsx)("div",{"data-testid":"prompt-panel",role:"dialog","aria-labelledby":h,"aria-modal":"true",className:x,children:(0,r.jsx)(sr,{promptData:n,answering:l,onRespond:i,onDismiss:c,labelId:h,cliToolName:d})})})});var si=n(91758);function sc(e){let{isOpen:t,onConfirm:n,onCancel:a,cliToolName:s}=e,l=(0,c.c)("autoYes"),i=(0,c.c)("common"),[d,u]=(0,o.useState)(36e5),[m,h]=(0,o.useState)(""),[x,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),b=(0,o.useRef)(null),v=e=>l(am[e].replace("autoYes.",""));return(0,o.useEffect)(()=>{t&&(h(""),f(null),p(!1))},[t]),(0,o.useEffect)(()=>{if(!g)return;let e=e=>{b.current&&!b.current.contains(e.target)&&p(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[g]),(0,o.useEffect)(()=>{if(!m.trim())return void f(null);let e=function(e){if(e.length>500)return{valid:!1,error:"Pattern must be ".concat(500," characters or less")};if(!ad()(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"}}}(m.trim());if(e.valid)f(null);else{var t;f(null!=(t=e.error)?t:l("invalidRegexPattern"))}},[m,l]),(0,r.jsx)(e0.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:au.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:()=>p(!g),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:"?"}),g&&(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(x?"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"}),x&&(0,r.jsx)("p",{className:"mt-1 text-xs text-danger","data-testid":"stop-pattern-error",children:x})]}),(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:i("cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>{n(d,m.trim()||void 0)},disabled:!!x,className:"px-4 py-2 text-sm font-medium rounded-md text-white ".concat(x?"bg-muted-foreground cursor-not-allowed":"bg-warning hover:bg-warning/90"),"data-testid":"confirm-button",children:l("agreeAndEnable")})]})]})})}let sd=(0,o.memo)(function(e){let{enabled:t,expiresAt:n,onToggle:a,lastAutoResponse:s,cliToolName:l,inline:i=!1,showToolName:d=!0,onExpire:u}=e,m=(0,c.c)("autoYes"),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!t||!n){x(""),w(!1);return}w(!1);let e=!1,a=()=>(x(ah(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,o.useEffect)(()=>{if(!s)return;g('Auto responded: "'.concat(s,'"'));let e=setTimeout(()=>g(null),et.I2);return()=>clearTimeout(e)},[s]);let k=t&&!j,N=(0,o.useCallback)(()=>{k?(b(!0),a({enabled:!1}).finally(()=>b(!1))):y(!0)},[k,a]),C=(0,o.useCallback)((e,t)=>{y(!1),b(!0),a({enabled:!0,duration:e,stopPattern:t}).finally(()=>b(!1))},[a]),S=(0,o.useCallback)(()=>{y(!1)},[]);return(0,r.jsxs)("div",{className:i?"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)(si.d,{checked:k,onCheckedChange:N,disabled:p,"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,e2.f_)(l,""),")"]}),k&&h&&(0,r.jsx)("span",{className:"text-sm text-muted-foreground","aria-label":m("timeRemaining"),children:h}),f&&(0,r.jsx)("span",{className:"text-sm text-success animate-pulse",children:f}),(0,r.jsx)(sc,{isOpen:v,onConfirm:C,onCancel:S,cliToolName:(0,e2.f_)(l,"")})]})});function su(e){let t=new Set;for(let n of e)"user"===n.role&&t.add(n.id);return t}function sm(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()),o=new Set;for(let e of[...s].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())){let t=l.find(t=>!o.has(t.id)&&!e.baselineUserIds.has(t.id)&&t.content===e.content);t&&(o.add(t.id),a.add(e.tempId),r.add(t.id))}return{reconciledTempIds:a,consumedServerIds:r}}function sh(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 sx=(0,o.memo)(function(e){var t,n,a,s,l;let{worktreeId:i,splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:f,onFocus:g,disabled:p=!1,pendingInsertText:b,onInsertConsumed:v,onMessageSent:y,cliStatus:j="idle",autoYes:w,history:k,onDropInstance:N,draggedInstanceId:C,onRequestSessionEnd:S}=e,T=null!=m?m:u,E=null!=(t=w.enabled)&&t,I=null!=(n=w.expiresAt)?n:null,M=null!=(a=w.lastAutoResponse)?a:null,L=w.onToggle,A=null!=(s=null==k?void 0:k.showArchived)&&s,P=null==k?void 0:k.onShowArchivedChange,R=null==k?void 0:k.historyDisplayLimit,D=null==k?void 0:k.onHistoryDisplayLimitChange,F=null!=(l=null==k?void 0:k.historyUserOnly)&&l,z=null==k?void 0:k.onHistoryUserOnlyChange,O=null==k?void 0:k.onInsertToMessage,_=null==k?void 0:k.onFilePathClick,W=null==k?void 0:k.showToast,H=(0,c.c)("worktree"),{terminal:V,prompt:U,setAutoScroll:K,setPromptAnswering:$,clearPrompt:q,refresh:J}=tu({worktreeId:i,cliToolId:u,instanceId:T,enabled:!p}),{messages:Y,isLoading:G,refresh:X}=function(e){let{worktreeId:t,cliToolId:n,instanceId:a,limit:r,includeArchived:s=!1,enabled:l=!0}=e,[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(!0),{subscribe:m,unsubscribe:h,addListener:x}=(0,td.xM)(),f=null!=a?a:n,g=(0,o.useRef)(0),p=(0,o.useRef)(n);p.current=n;let b=(0,o.useRef)(f);b.current=f;let v=(0,o.useCallback)(async()=>{let e=++g.current;try{let a=new URLSearchParams({cliTool:n,instance:f});void 0!==r&&a.set("limit",String(r)),s&&a.set("includeArchived","true");let l=await fetch("/api/worktrees/".concat(t,"/messages?").concat(a.toString()));if(!l.ok)return;let o=await l.json();if(g.current!==e||p.current!==n||b.current!==f)return;c(o.map(e=>({...e,timestamp:new Date(e.timestamp)}))),u(!1)}catch(t){if(g.current!==e||p.current!==n||b.current!==f)return;console.error("[useSplitMessages] fetch error:",t),u(!1)}},[t,n,f,r,s]),y="".concat(t,"::").concat(n,"::").concat(f),j=(0,o.useRef)(y);return(0,o.useEffect)(()=>{j.current!==y&&(j.current=y,g.current+=1,c([]),u(!0))},[y]),(0,o.useEffect)(()=>{if(!l)return;let e=!1,t=setInterval(()=>{"hidden"!==document.visibilityState&&v()},5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&v();let n=()=>{"visible"!==document.visibilityState||e||v()};return document.addEventListener("visibilitychange",n),()=>{e=!0,clearInterval(t),document.removeEventListener("visibilitychange",n)}},[l,v]),(0,o.useEffect)(()=>{if(l)return m(t),()=>h(t)},[l,t,m,h]),(0,o.useEffect)(()=>{if(l)return x(e=>{if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===b.current)&&(null==e.cliTool||e.cliTool===p.current)&&v()})},[l,t,x,v]),{messages:i,isLoading:d,refresh:(0,o.useCallback)(()=>v(),[v])}}({worktreeId:i,cliToolId:u,instanceId:T,limit:R,includeArchived:A,enabled:!p}),Q=(0,o.useCallback)((e,t)=>B.y.sendMessage(i,e,t),[i]),{messages:Z,sendOptimistic:et,retry:en,discard:ea}=function(e){let{worktreeId:t,serverMessages:n,sendFn:a,onSent:r,timeoutMs:s=3e4}=e,[l,i]=(0,o.useState)([]),c=(0,o.useRef)(n);c.current=n;let d=(0,o.useRef)(l);d.current=l;let u=(0,o.useRef)(r);u.current=r;let m=(0,o.useRef)(a);m.current=a;let h=(0,o.useRef)(0),x=(0,o.useRef)(new Map),f=(0,o.useRef)(new Set),g=(0,o.useCallback)(e=>{let t=x.current.get(e);void 0!==t&&(clearTimeout(t),x.current.delete(e))},[]),p=(0,o.useCallback)(e=>{g(e);let t=setTimeout(()=>{x.current.delete(e),i(t=>t.map(t=>t.tempId===e&&"sending"===t.status?{...t,status:"error"}:t))},s);x.current.set(e,t)},[g,s]),b=(0,o.useCallback)(async e=>{p(e.tempId);try{var t;await m.current(e.content,e.options),null==(t=u.current)||t.call(u)}catch(t){g(e.tempId),i(t=>t.map(t=>t.tempId===e.tempId?{...t,status:"error"}:t))}},[p,g]),v=(0,o.useCallback)((e,t)=>{let n={tempId:"pending-".concat(h.current++),content:e,options:t,timestamp:new Date,status:"sending",baselineUserIds:su(c.current)};i(e=>[...e,n]),b(n)},[b]),y=(0,o.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);if(!t)return;let n={...t,status:"sending",timestamp:new Date,baselineUserIds:su(c.current)};i(t=>t.map(t=>t.tempId===e?n:t)),b(n)},[b]),j=(0,o.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);return g(e),i(t=>t.filter(t=>t.tempId!==e)),null==t?void 0:t.content},[g]);return(0,o.useEffect)(()=>{let{reconciledTempIds:e,consumedServerIds:t}=sm(d.current,n,f.current),a=new Set(n.map(e=>e.id)),r=new Set;f.current.forEach(e=>{a.has(e)&&r.add(e)}),t.forEach(e=>r.add(e)),f.current=r,0!==e.size&&(e.forEach(g),i(t=>t.filter(t=>!e.has(t.tempId))))},[n,g]),(0,o.useEffect)(()=>{let e=x.current;return()=>{e.forEach(e=>clearTimeout(e)),e.clear()}},[]),{messages:(0,o.useMemo)(()=>{if(0===l.length)return n;let{reconciledTempIds:e}=sm(l,n,f.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}}({worktreeId:i,serverMessages:Y,sendFn:Q,onSent:X}),{visible:er,width:el,toggle:eo,setWidth:ei}=tH(),ec=o.useRef(null),ed=(0,o.useCallback)(e=>{let t=ec.current;if(!t)return;let n=t.offsetWidth;0!==n&&ei(el+e/n*100)},[el,ei]),eu="opencode"===u||"copilot"===u,eh="claude"===u||"codex"===u,ex=(0,o.useCallback)(e=>K(e),[K]),ef=(0,o.useCallback)(e=>{J(),X(),null==y||y(e)},[J,X,y]),eg=(0,o.useCallback)(e=>{let t=ea(e);t&&(null==O||O(t))},[ea,O]),ep=(0,o.useCallback)(async e=>{$(!0);try{let t=sh(e,u,U.data,T),n=await fetch("/api/worktrees/".concat(i,"/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));q(),await J()}catch(e){console.error("[TerminalSplitPaneContent] prompt response error:",e)}finally{$(!1)}},[i,u,T,U.data,$,q,J]),eb=(0,o.useCallback)(()=>{q()},[q]),ev=V.isSelectionListActive,ey=U.visible&&!E,ej=V.isUnclassifiedActive&&!ev&&!U.visible,ew=(0,o.useMemo)(()=>(0,r.jsx)(t1,{messages:Z,worktreeId:i,onFilePathClick:null!=_?_:()=>{},isLoading:G,className:"h-full",showToast:W,onInsertToMessage:O,onRetryPending:en,onDiscardPending:eg,showArchived:A,onShowArchivedChange:P,historyDisplayLimit:R,onHistoryDisplayLimitChange:D,historyUserOnly:F,onHistoryUserOnlyChange:z,onCollapse:eo,splitIndex:d,cliToolId:u}),[Z,en,eg,i,_,G,W,O,A,P,R,D,F,z,eo,d,u]),ek=(0,o.useMemo)(()=>(0,r.jsx)(tc,{output:V.output,isActive:V.isRunning,attaching:V.attaching,isThinking:V.isThinking,autoScroll:V.autoScroll,onScrollChange:ex,disableAutoFollow:eu,compactTuiLayoutPadding:eh}),[V.output,V.isRunning,V.attaching,V.isThinking,V.autoScroll,ex,eu,eh]),eN=(0,o.useMemo)(()=>(0,r.jsxs)("div",{ref:ec,className:"flex h-full min-h-0 w-full",children:[er?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:tX(d),"data-testid":"split-history-slot-".concat(d),"aria-label":"History pane",style:{width:"".concat(el,"%")},className:"flex-shrink-0 overflow-hidden min-h-0",children:ew}),(0,r.jsx)(tV.f,{onResize:ed,orientation:"horizontal",ariaValueNow:el})]}):(0,r.jsx)("div",{"data-testid":"split-history-expand-bar-".concat(d),className:"flex-shrink-0 flex items-start justify-center w-9 bg-gray-50 dark:bg-gray-800 border-r border-gray-200 dark:border-gray-700",children:(0,r.jsxs)("button",{type:"button","data-testid":"split-history-expand-".concat(d),"aria-label":H("terminal.showHistory"),title:H("terminal.showHistory"),"aria-expanded":"false",onClick:eo,className:"flex flex-col items-center gap-2 w-full pt-2 text-gray-500 dark:text-gray-400 hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",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"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:H("terminal.historyLabel")})]})}),(0,r.jsx)("div",{className:"flex-grow overflow-hidden min-w-0 min-h-0 relative",children:ek})]}),[er,el,ew,ed,eo,ek,d,H]),eC=(0,o.useMemo)(()=>(0,r.jsxs)("div",{className:"space-y-2",children:[ev?(0,r.jsx)(es,{worktreeId:i,cliToolId:u,instanceId:T,onKeysSent:J,showPagerKeys:V.isPagerActive}):null,ej?(0,r.jsx)(st,{worktreeId:i,cliToolId:u,instanceId:T,onKeysSent:J}):null,ey?(0,r.jsx)(so,{promptData:U.data,messageId:U.messageId,visible:U.visible,answering:U.answering,onRespond:ep,onDismiss:eb,cliToolName:(0,e2.oo)(u)}):null,(0,r.jsx)(ee,{worktreeId:i,onMessageSent:ef,onOptimisticSend:et,cliToolId:u,instanceId:T,isSessionRunning:V.isRunning,pendingInsertText:null!=b?b:null,onInsertConsumed:v,splitIndex:d,onFocus:g,isProcessing:V.isRunning,showToast:W,autoYesSlot:(0,r.jsx)(sd,{enabled:E,expiresAt:null!=I?I:null,onToggle:L,lastAutoResponse:null!=M?M:null,cliToolName:u,inline:!0})})]}),[ev,ey,ej,V.isPagerActive,i,u,T,J,U.data,U.messageId,U.visible,U.answering,ep,eb,ef,et,V.isRunning,b,v,d,g,E,I,M,L,W]),eS=(0,e2.sw)(null!=h?h:{cliTool:u}),eT=(0,o.useCallback)(()=>{null==S||S({cliToolId:u,instanceId:T,label:eS})},[S,u,T,eS]),eE=(0,o.useMemo)(()=>{if(!S||!V.isRunning)return null;let e=H("terminal.endSessionFor",{name:eS});return(0,r.jsx)("button",{type:"button",onClick:eT,"aria-label":e,title:e,"data-testid":"terminal-end-session-button-".concat(d),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)(em.A,{size:14,"aria-hidden":"true"})})},[S,V.isRunning,H,eS,eT,d]);return(0,r.jsx)(e3,{worktreeId:i,splitIndex:d,cliToolId:u,instanceId:T,instance:h,availableInstances:x,onInstanceChange:f,headerExtras:eE,status:j,onFocus:g,attaching:V.attaching,terminal:eN,footer:eC,onDropInstance:N,draggedInstanceId:C})});var sf=n(52056);let sg=(0,o.memo)(function(e){let{isBranchMismatch:t,currentBranch:n,initialBranch:a}=e,s=(0,c.c)("worktree"),[l,i]=(0,o.useState)(!1);return((0,o.useEffect)(()=>{i(!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)(sf.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:()=>i(!0),className:"p-1 rounded hover:bg-warning-subtle transition-colors","aria-label":s("branchMismatch.dismiss"),children:(0,r.jsx)(em.A,{className:"w-4 h-4"})})]})});var sp=n(58734);let sb=(0,o.memo)(function(e){let{isOpen:t,onClose:n,onConfirm:a,worktreeId:s,sourcePath:l,sourceType:i}=e,d=(0,c.c)("worktree"),u=(0,c.c)("common"),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(new Set([""])),[p,b]=(0,o.useState)([]),[v,j]=(0,o.useState)(!1),[w,k]=(0,o.useState)(new Set),N=l.includes("/")?l.substring(0,l.lastIndexOf("/")):"";(0,o.useEffect)(()=>{t&&(x(N),g(new Set([""])),b([]),C())},[t,s]);let C=(0,o.useCallback)(async()=>{j(!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{j(!1)}},[s]),S=(0,o.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,o.useCallback)(async e=>{g(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}(p,e);t&&!t.loaded&&await S(e)},[p,S]),E=(0,o.useCallback)(e=>!(e===N||"directory"===i&&(e===l||e.startsWith(l+"/")))&&!0,[N,l,i]),I=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=f.has(e.path),a=h===e.path,s=w.has(e.path),l=E(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&&x(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)(tf.A,{className:"w-3 h-3 text-muted-foreground transition-transform ".concat(n?"rotate-90":"")})}),n?(0,r.jsx)(sp.A,{className:"w-4 h-4 text-warning flex-shrink-0"}):(0,r.jsx)(y.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=>I(e,t+1))})]},e.path)},M=E(h);return(0,r.jsx)(e0.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(E("")?"":"opacity-40 cursor-not-allowed"),onClick:()=>{E("")&&x("")},children:[(0,r.jsx)("span",{className:"w-4 h-4"}),(0,r.jsx)(y.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"})}):p.map(e=>I(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:!M,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 sv(e,t){let n=e.trim();return n?0>=n.lastIndexOf(".")?n+t:n:""}let sy=(0,o.memo)(function(e){let{isOpen:t,parentPath:n,onConfirm:a,onCancel:s}=e,l=(0,c.c)("worktree"),i=(0,c.c)("common"),[d,u]=(0,o.useState)(""),[m,h]=(0,o.useState)(".md"),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(t){u(""),h(".md");let e=setTimeout(()=>{var e;null==(e=x.current)||e.focus()},100);return()=>clearTimeout(e)}},[t]);let f=(0,o.useCallback)(()=>{let e=sv(d,m);e&&a(e)},[d,m,a]),g=(0,o.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),f())},[f]),p=sv(d,m),b=n?"".concat(n,"/").concat(p):p;return(0,r.jsx)(e0.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:x,id:"new-file-name","data-testid":"new-file-name-input",type:"text",value:d,onChange:e=>u(e.target.value),onKeyDown:g,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:rN.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),p&&(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:i("cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"new-file-confirm-button",onClick:f,disabled:!p,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")})]})]})})}),sj=(0,o.memo)(function(e){var t,n,a,s;let{worktreeId:l,worktree:i,worktreeName:d,worktreeStatus:u,instances:m,rosterReady:h,activeInstanceId:x,setActiveInstanceId:f,hasUpdate:g,lastAutoResponse:p,activeActivity:b,onActivityToggle:v,onBackClick:y,onInfoClick:j,onWorktreeStatusChange:w,pendingInsertTextMap:k,setFocusedSplitIndex:N,handleInsertToSplit:C,handleInsertConsumed:T,handleInsertToMessage:E,autoYesStateMap:I,makeAutoYesToggleHandler:M,showArchived:L,onShowArchivedChange:A,historyDisplayLimit:P,onHistoryDisplayLimitChange:R,historyUserOnly:D,onHistoryUserOnlyChange:F,onMessageSent:z,onFilePathClick:O,showToast:_,tabsState:B,tabsActions:W,onLoadContent:H,onLoadError:V,onSetLoading:U,onFilePanelSave:K,onDirtyChange:$,onOpenFile:q,diffContent:J,diffFilePath:Y,onCloseDiff:G,fileSearch:X,fileTreeRefresh:Q,onFileSelect:Z,onNewFile:ee,onNewDirectory:et,onRename:en,onDelete:ea,onUpload:er,onMove:es,onFileTreeReset:el,onDiffSelect:eo,onAgentInstancesChange:ei,vibeLocalModel:ec,onVibeLocalModelChange:ed,vibeLocalContextWindow:eu,onVibeLocalContextWindowChange:em,isInfoModalOpen:eh,onInfoModalClose:ex,onWorktreeUpdate:ef,fileInputRef:eg,onFileInputChange:ep,onKillSession:eb,onRequestSessionEnd:ev,killTarget:ey,isKillPending:ej,onKillCancel:ew,onKillConfirm:ek,moveTarget:eN,isMoveDialogOpen:eC,onMoveCancel:eS,onMoveConfirm:eT,showNewFileDialog:eE,newFileParentPath:eI,onNewFileConfirm:eM,onNewFileCancel:eL,toasts:eA,onToastClose:eP,killDialogTitle:eR,killDialogWarning:eD,cancelLabel:eF,endLabel:ez}=e,eO=(0,c.c)("worktree"),[e_,eW]=o.useState(null),eH=(0,o.useCallback)(e=>eW(e),[]),eV=(0,o.useCallback)(()=>eW(null),[]),[eU,eK]=o.useState(null),e$=o.useRef(0),eq=(0,o.useCallback)(e=>{f(e),e$.current+=1,eK({instanceId:e,token:e$.current})},[f]),eJ=(0,o.useCallback)(e=>{var t,n,a,s,o,c;let{splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:g,onFocus:b,onDropInstance:v}=e,y=null!=(a=k.get(d))?a:null,j=I.get(m),w=null!=(s=null==j?void 0:j.enabled)&&s,N=null!=(o=null==j?void 0:j.expiresAt)?o:null,S=(0,e1.kA)(null!=(c=null==i||null==(t=i.sessionStatusByInstance)?void 0:t[m])?c:null==i||null==(n=i.sessionStatusByCli)?void 0:n[u]);return(0,r.jsx)(sx,{worktreeId:l,splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:e=>{g(e),0===d&&f(e)},onFocus:b,pendingInsertText:y,onInsertConsumed:()=>T(d),onMessageSent:z,cliStatus:S,autoYes:{enabled:w,expiresAt:N,lastAutoResponse:p,onToggle:M(u,m)},history:{showArchived:L,onShowArchivedChange:A,historyDisplayLimit:P,onHistoryDisplayLimitChange:R,historyUserOnly:D,onHistoryUserOnlyChange:F,onInsertToMessage:e=>C(d,e),onFilePathClick:O,showToast:_},onDropInstance:v,draggedInstanceId:e_,onRequestSessionEnd:ev})},[l,k,I,T,z,f,p,M,null==i?void 0:i.sessionStatusByCli,null==i?void 0:i.sessionStatusByInstance,O,_,C,L,A,P,R,D,F,e_,ev]),eY=(0,o.useMemo)(()=>(0,r.jsx)(r8,{worktreeId:l,instances:m,rosterReady:h,renderPane:eJ,onFocusedSplitChange:N,showToast:_,onActiveInstanceChange:f,headerInstanceSelection:eU}),[l,m,h,eJ,N,_,f,eU]),eG=(0,o.useMemo)(()=>(0,r.jsx)(rJ,{terminal:eY,terminalHeader:null,fileTabs:B,worktreeId:l,onCloseTab:W.closeTab,onActivateTab:W.activateTab,onLoadContent:H,onLoadError:V,onSetLoading:U,onFileSaved:K,diffContent:J,diffFilePath:Y,onCloseDiff:G,onDirtyChange:$,onMoveToFront:W.moveToFront,onOpenFile:q}),[eY,B,l,W.closeTab,W.activateTab,H,V,U,K,J,Y,G,$,W.moveToFront,q]),eX=(0,o.useMemo)(()=>(0,r.jsx)(rp,{active:b,onToggle:v}),[b,v]),eQ=(0,o.useMemo)(()=>{var e;return{files:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(nj,{query:X.query,mode:X.mode,isSearching:X.isSearching,error:X.error,onQueryChange:X.setQuery,onModeChange:X.setMode,onClear:X.clearSearch}),(0,r.jsx)(np,{worktreeId:l,onFileSelect:Z,onNewFile:ee,onNewDirectory:et,onRename:en,onDelete:ea,onUpload:er,onMove:es,onResetView:el,refreshTrigger:Q,pollingEnabled:"files"===b,searchQuery:X.query,searchMode:X.mode,searchResults:null==(e=X.results)?void 0:e.results,className:"flex-1 min-h-0"})]}),git:(0,r.jsx)(a0,{worktreeId:l,onDiffSelect:eo,isMobile:!1,worktree:null!=i?i:void 0,onInsertToMessage:E,className:"h-full"}),notes:(0,r.jsx)(nE,{worktreeId:l,className:"h-full",onInsertToMessage:E}),schedules:(0,r.jsx)(n9,{worktreeId:l,className:"h-full",onInsertToMessage:E,instances:m}),agent:(0,r.jsx)(al,{worktreeId:l,instances:m,onInstancesChange:ei,vibeLocalModel:ec,onVibeLocalModelChange:ed,vibeLocalContextWindow:eu,onVibeLocalContextWindowChange:em}),timer:(0,r.jsx)(av,{worktreeId:l,instances:m}),todo:(0,r.jsx)(nP,{worktreeId:l,className:"h-full"})}},[l,i,b,X.query,X.mode,X.isSearching,X.error,X.setQuery,X.setMode,X.clearSearch,null==(t=X.results)?void 0:t.results,Z,ee,et,en,ea,er,es,el,Q,eo,E,m,ei,ec,ed,eu,em]),eZ=(0,o.useMemo)(()=>null===b?null:(0,r.jsx)(ry,{active:b,activities:eQ}),[b,eQ]);return(0,r.jsx)(S,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"flex h-full overflow-hidden relative",children:[eX,(0,r.jsxs)("div",{className:"flex flex-col flex-1 min-h-0 min-w-0",children:[(0,r.jsx)(a9,{worktreeName:d,repositoryName:null!=(a=null!=(n=null==i?void 0:i.repositoryDisplayName)?n:null==i?void 0:i.repositoryName)?a:eO("detail.unknownRepository"),description:null==i?void 0:i.description,status:u,gitStatus:null==i?void 0:i.gitStatus,onBackClick:y,onInfoClick:j,hasUpdate:g,worktreeStatus:null!=(s=null==i?void 0:i.status)?s:null,onWorktreeStatusChange:w,sessionStatusByCli:null==i?void 0:i.sessionStatusByCli,sessionStatusByInstance:null==i?void 0:i.sessionStatusByInstance,instances:m,activeInstanceId:x,onActiveInstanceChange:eq,onAgentDragStart:eH,onAgentDragEnd:eV,onKillSession:eb}),(null==i?void 0:i.gitStatus)&&(0,r.jsx)(sg,{isBranchMismatch:i.gitStatus.isBranchMismatch,currentBranch:i.gitStatus.currentBranch,initialBranch:i.gitStatus.initialBranch}),(0,r.jsx)("div",{className:"flex-1 min-h-0 min-w-0",children:(0,r.jsx)(rn,{activityPane:eZ,rightPane:(0,r.jsx)(t$,{terminal:eG})})})]}),(0,r.jsx)(a7,{worktreeId:l,worktree:i,isOpen:eh,onClose:ex,onWorktreeUpdate:ef}),(0,r.jsx)("input",{ref:eg,type:"file",accept:rk.join(","),onChange:ep,className:"hidden","aria-label":eO("detail.uploadFile")}),(0,r.jsx)(e0.a,{isOpen:null!==ey,onClose:ew,title:eR,size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:eD}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:ew,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:eF}),(0,r.jsx)("button",{type:"button",onClick:ek,disabled:ej,"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})]})]})}),eN&&(0,r.jsx)(sb,{isOpen:eC,onClose:eS,onConfirm:eT,worktreeId:l,sourcePath:eN.path,sourceType:eN.type}),(0,r.jsx)(sy,{isOpen:eE,parentPath:eI,onConfirm:eM,onCancel:eL}),(0,r.jsx)(eB.N9,{toasts:eA,onClose:eP})]})})});e2.oo;var sw=n(51434);let sk={data:null,messageId:null,visible:!1,answering:!1},sN={mode:"split",mobileActivePane:"terminal",leftPaneTab:"history",splitRatio:.5,leftPaneCollapsed:!1,activityBar:{active:"files"},historyPane:{visible:!0,width:25,collapsed:!1}},sC={type:null,message:null,retryable:!1,retryCount:0};function sS(){return{phase:"idle",prompt:{...sk},layout:{...sN},error:{...sC},messages:[],wsConnected:!1}}function sT(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:{...sk}};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:{...sC}};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}}var sE=n(66966);function sI(e,t){try{window.localStorage.setItem(rf(e),null!=t?t:rx)}catch(e){}}let sM="commandmate:file-tabs:";function sL(e){let t=e.split("/");return t[t.length-1]||e}function sA(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}let sP={tabs:[],activeIndex:null};var sR=n(63001);let sD="commandmate:showArchived",sF="activeCliTab-",sz="activeInstanceId-";function sO(){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 s_=(0,i.default)(()=>Promise.all([n.e(8566),n.e(934),n.e(6416),n.e(8676)]).then(n.bind(n,98676)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[98676]},ssr:!1,loading:()=>(0,r.jsx)(sO,{})}),sB=()=>{},sW=["terminal","history","files","memo","info"],sH=(0,o.memo)(function(e){var t,n,a,l,i,u;let{worktreeId:m}=e,{activeActivity:f,activeCliTab:g,activeInstanceId:b,activeTab:v,agentInstances:y,autoYesEnabled:j,autoYesExpiresAt:w,autoYesStateMap:k,diffContent:N,diffFilePath:T,disableAutoFollow:E,displayedInstances:I,editorFilePath:M,error:A,fetchCurrentOutput:R,fileInputRef:D,fileSearch:F,fileTreeRefresh:z,handleActivityToggle:O,handleAgentInstancesChange:W,handleAutoYesToggle:H,handleBackClick:V,handleCloseDiff:U,handleDelete:K,handleDiffSelect:$,handleDirtyChange:q,handleEditorClose:J,handleEditorSave:G,handleFileInputChange:X,handleFilePanelSave:Q,handleFilePathClick:Z,handleFileSelect:et,handleHistoryDisplayLimitChange:en,handleHistoryUserOnlyChange:ea,handleInfoClick:er,handleInfoModalClose:eo,handleInsertConsumed:ei,handleInsertConsumedSingle:ec,handleInsertToMessage:ed,handleInsertToSplit:eu,handleKillCancel:em,handleKillConfirm:eh,openKillConfirm:ex,openActiveKillConfirm:ef,killTarget:eg,isKillPending:ep,handleLoadContent:eb,handleLoadError:ev,handleMessageSent:ey,handleMobileFileViewerClose:ew,handleMobileTabChange:ek,handleMove:eN,handleMoveCancel:eC,handleMoveConfirm:eS,handleNewDirectory:eT,handleNewFile:eE,handleNewFileCancel:eI,handleNewFileConfirm:eM,handleOpenFile:eL,handlePromptDismiss:eA,handlePromptRespond:eP,handleRename:eR,handleRetry:eF,handleSetLoading:ez,handleShowArchivedChange:eO,handleUpload:e_,handleVibeLocalContextWindowChange:eW,handleVibeLocalModelChange:eV,handleWorktreeStatusChange:eU,hasUpdate:eK,historyDisplayLimit:e$,historySubTab:eq,historyUserOnly:eJ,isEditorMaximized:eY,isInfoModalOpen:eG,isMobile:eX,isMoveDialogOpen:eQ,isSelectionListActive:eZ,isPagerActive:e4,lastAutoResponse:e5,loading:e3,makeAutoYesToggleHandler:e6,mobileFileViewerPath:e8,mobileSelectedAgents:e9,moveTarget:e7,newFileParentPath:te,openMobileDrawer:tt,pendingInsertText:tn,pendingInsertTextMap:ta,removeToast:tr,rosterReady:ts,setActiveInstanceId:tl,setEditorFilePath:to,setFocusedSplitIndex:ti,setHistorySubTab:tc,setIsEditorMaximized:tu,setWorktree:tm,showArchived:th,showNewFileDialog:tx,showToast:tf,state:tg,tCommon:tp,tWorktree:tb,tabsActions:tv,tabsState:ty,resetFileTreeView:tj,toasts:tw,toggleInstanceVisible:tk,vibeLocalContextWindow:tN,vibeLocalModel:tC,visibleInstanceIds:tS,worktree:tT,worktreeName:tE,worktreeStatus:tI}=function(e){var t,n,a,r,l,i,d,u,m,h;let{worktreeId:f}=e,g=(0,s.useRouter)(),p=(0,Y.a)(),b=(0,o.useRef)(p);b.current=p;let{openMobileDrawer:v}=(0,rg.VF)(),{state:y,actions:j}=function(){let[e,t]=(0,o.useReducer)(sT,void 0,sS),{value:n,setValue:a}=(0,aw.V)({key:"commandmate.worktree.leftPaneCollapsed",defaultValue:!1,validate:e=>"boolean"==typeof e}),r=(0,o.useRef)(e.layout.leftPaneCollapsed);r.current=e.layout.leftPaneCollapsed;let s=(0,o.useRef)(!1);(0,o.useEffect)(()=>{s.current||(s.current=!0,n!==r.current&&t({type:"SET_LEFT_PANE_COLLAPSED",collapsed:n}))},[n]);let l=(0,o.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,el.SC)(),T=(0,sE.rC)(),E=null!=(l=null==T?void 0:T.worktrees.find(e=>e.id===f))?l:null,[I,M]=(0,o.useState)(E),[L,A]=(0,o.useState)(null===E),[P,R]=(0,o.useState)(null),D=(0,o.useRef)(null!==E),[F,z]=(0,o.useState)(!1),[O,_]=function(e){let[t,n]=(0,o.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:sL(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=sA(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=sA(t.tabs,n.path,e=>({...e,loading:n.loading}));if(!e)return t;return{...t,tabs:e}}case"SET_ERROR":{let e=sA(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:sL(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:sL(e),content:null,loading:!1,error:null,isDirty:!1}));if(0===e.length)return sP;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=sA(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 sP;default:return t}},sP),a=(0,o.useRef)(!1),r=(0,o.useRef)(e);(0,o.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(sM+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,o.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(sM+e,JSON.stringify(a))}catch(e){}}},[e,t]);let s=(0,o.useRef)(t);s.current=t;let l=(0,o.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")},[]),i=(0,o.useCallback)(e=>{n({type:"CLOSE_TAB",path:e})},[]),c=(0,o.useCallback)(e=>{n({type:"ACTIVATE_TAB",path:e})},[]),d=(0,o.useCallback)((e,t)=>{n({type:"RENAME_FILE",oldPath:e,newPath:t})},[]),u=(0,o.useCallback)(e=>{n({type:"DELETE_FILE",path:e})},[]),m=(0,o.useCallback)(e=>{n({type:"MOVE_TO_FRONT",path:e})},[]),h=(0,o.useCallback)(()=>{n({type:"CLOSE_ALL"})},[]),x=(0,o.useMemo)(()=>({dispatch:n,openFile:l,closeTab:i,activateTab:c,onFileRenamed:d,onFileDeleted:u,moveToFront:m,closeAllTabs:h}),[n,l,i,c,d,u,m,h]);return[t,x]}(f),[W,H]=(0,o.useState)(null),[V,U]=(0,o.useState)(null),[K,$]=(0,o.useState)(!1),[q,J]=(0,o.useState)(new Map),[G,X]=(0,o.useState)(null),[Q,Z]=(0,o.useState)(!1),[ee,et]=(0,o.useState)(!1),[en,ea]=(0,o.useState)(!1),er=(0,o.useRef)(!1),[es,eo]=(0,o.useState)(null),[ei,ec]=(0,o.useState)(sR.fJ),ed=(0,o.useRef)(ei);ed.current=ei;let[eu,em]=(0,o.useState)(()=>(0,e2.lu)(sR.fJ)),eh=(0,o.useRef)(eu);eh.current=eu;let[ex,ef]=(0,o.useState)(null),eg=ex===f,[ep,eb]=(0,o.useState)(null),[ev,ey]=(0,o.useState)(null),[ew,ek]=(0,o.useState)(()=>{try{let e=window.localStorage.getItem(sF+f);if(e&&(0,e2.hR)(e))return e}catch(e){}return sR.fJ[0]}),eN=(0,o.useCallback)(e=>{ek(e);try{window.localStorage.setItem(sF+f,e)}catch(e){}},[f]),eC=(0,o.useRef)(ew);eC.current=ew;let[eS,eT]=(0,o.useState)(()=>{try{let e=window.localStorage.getItem(sz+f);if(e&&(0,e2.n6)(e))return e;let t=window.localStorage.getItem(sF+f);if(t&&(0,e2.hR)(t))return t}catch(e){}return sR.fJ[0]}),eE=(0,o.useCallback)(e=>{eT(e);try{window.localStorage.setItem(sz+f,e)}catch(e){}let t=eh.current.find(t=>t.id===e);t&&eN(t.cliTool)},[f,eN]),eI=(0,o.useRef)(eS);eI.current=eS;let eM=(0,o.useRef)(0),eL=(0,o.useRef)(0),eA=(0,o.useRef)(0),eP=null!=(i=null==(t=q.get(eS))?void 0:t.enabled)&&i,eR=null!=(d=null==(n=q.get(eS))?void 0:n.expiresAt)?d:null,[eD,eF]=(0,o.useState)(0),[ez,eO]=(0,o.useState)(!1),[e_,eW]=(0,o.useState)(""),{active:eV,toggle:eU}=function(e){let[t,n]=(0,o.useState)(rh),a=(0,o.useRef)(t);a.current=t;let r=(0,o.useRef)(e);return r.current=e,(0,o.useEffect)(()=>{let t=function(e){try{let t=window.localStorage.getItem(rf(e));if(t===rx)return null;if(t&&"string"==typeof t&&rm.has(t))return t}catch(e){}return rh}(e);t!==a.current&&n(t)},[e]),{active:t,setActive:(0,o.useCallback)(e=>{n(e),sI(r.current,e)},[]),toggle:(0,o.useCallback)(e=>{if(a.current===e){n(null),sI(r.current,null);return}n(e),sI(r.current,e)},[])}}(f),{historySubTab:eK,setHistorySubTab:e$,showArchived:eq,handleShowArchivedChange:eJ,historyUserOnly:eY,handleHistoryUserOnlyChange:eG,historyDisplayLimit:eX,handleHistoryDisplayLimitChange:eQ}=function(){let[e,t]=(0,o.useState)("message"),[n,a]=(0,o.useState)(()=>"true"===localStorage.getItem(sD)),r=(0,o.useCallback)(e=>{a(e),localStorage.setItem(sD,String(e))},[]),[s,l]=(0,o.useState)(()=>{try{return"true"===localStorage.getItem(tG)}catch(e){return!1}}),i=(0,o.useCallback)(e=>{l(e);try{localStorage.setItem(tG,String(e))}catch(e){}},[]),[c,d]=(0,o.useState)(()=>{try{let e=localStorage.getItem(tJ);if(null===e)return 50;let t=parseInt(e,10);return tY(t)?t:50}catch(e){return 50}});return{historySubTab:e,setHistorySubTab:t,showArchived:n,handleShowArchivedChange:r,historyUserOnly:s,handleHistoryUserOnlyChange:i,historyDisplayLimit:c,handleHistoryDisplayLimitChange:(0,o.useCallback)(e=>{d(e);try{localStorage.setItem(tJ,String(e))}catch(e){}},[])}}(),eZ=(0,o.useRef)(eq);(0,o.useEffect)(()=>{eZ.current=eq},[eq]);let e0=(0,o.useRef)(eX);(0,o.useEffect)(()=>{e0.current=eX},[eX]);let{pendingInsertTextMap:e1,pendingInsertText:e4,setFocusedSplitIndex:e5,handleInsertToMessage:e3,handleInsertToSplit:e6,handleInsertConsumed:e8,handleInsertConsumedSingle:e9}=function(){var e;let[t,n]=(0,o.useState)(()=>new Map),[a,r]=(0,o.useState)(0),s=(0,o.useCallback)(e=>{n(t=>{let n=new Map(t);return n.set(a,e),n})},[a]),l=(0,o.useCallback)((e,t)=>{n(n=>{let a=new Map(n);return a.set(e,t),a})},[]),i=(0,o.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,o.useCallback)(()=>i(0),[i]);return{pendingInsertTextMap:t,pendingInsertText:c,focusedSplitIndex:a,setFocusedSplitIndex:r,handleInsertToMessage:s,handleInsertToSplit:l,handleInsertConsumed:i,handleInsertConsumedSingle:d}}(),{diffContent:e7,diffFilePath:te,handleDiffSelect:tt,handleCloseDiff:tn}=function(e){let[t,n]=(0,o.useState)(null),[a,r]=(0,o.useState)(null);return{diffContent:t,diffFilePath:a,handleDiffSelect:(0,o.useCallback)((t,a)=>{e||(n(t),r(a))},[e]),handleCloseDiff:(0,o.useCallback)(()=>{n(null),r(null)},[])}}(p),ta=function(e){let{worktreeId:t,initialMode:n="name",debounceMs:a=300}=e,[r,s]=(0,o.useState)(""),[l,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(n),[u,m]=(0,o.useState)(!1),[h,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(null),b=(0,o.useRef)(null),v=(0,o.useMemo)(()=>(0,x.sg)(e=>{i(e)},a),[a]),y=(0,o.useCallback)(e=>{s(e),v(e),p(null)},[v]),j=(0,o.useCallback)(()=>{s(""),i(""),f(null),p(null),m(!1),b.current&&(b.current.abort(),b.current=null)},[]),w=(0,o.useCallback)(e=>{if(!l.trim())return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t))},[l]),k=(0,o.useCallback)(()=>h&&0!==h.results.length?(0,x.q3)(h.results.map(e=>e.filePath)):new Set,[h]);return(0,o.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),p(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;p(e instanceof Error?e.message:"An error occurred while searching"),f(null)}finally{m(!1)}})(),()=>{e.abort()}},[c,l,t]),(0,o.useEffect)(()=>{"name"===c&&(f(null),m(!1),p(null))},[c]),{query:r,mode:c,isSearching:u,results:h,error:g,setQuery:y,setMode:d,clearSearch:j,filterByName:w,getMatchedPaths:k}}({worktreeId:f}),tr=(0,o.useRef)(!1),ts=(0,o.useRef)(f);(0,o.useEffect)(()=>{ts.current!==f&&(j.clearMessages(),tr.current=!1,J(new Map),ts.current=f)},[f,j]);let tl=(0,o.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=ed.current;a.selectedAgents.length===e.length&&a.selectedAgents.every((t,n)=>t===e[n])||ec(a.selectedAgents)}if(a.agentInstances){let e=eh.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)||em(t),ef(f)}return"vibeLocalModel"in a&&eb(null!=(e=a.vibeLocalModel)?e:null),"vibeLocalContextWindow"in a&&ey(null!=(t=a.vibeLocalContextWindow)?t:null),a}catch(e){return R(e instanceof Error?e.message:"Unknown error"),null}},[f]),to=(0,o.useCallback)(async()=>{let e=eC.current,t=b.current,n=eI.current,a=++eM.current;try{let r=new URLSearchParams({cliTool:e});t&&r.set("instance",n),eZ.current&&r.set("includeArchived","true"),r.set("limit",String(e0.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(eM.current!==a||eC.current!==e||t&&eI.current!==n)return;j.setMessages(l.map(e=>({...e,timestamp:new Date(e.timestamp)})))}catch(r){if(eM.current!==a||eC.current!==e||t&&eI.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching messages:",r)}},[f,j]),ti=(0,o.useCallback)(async()=>{let e=eC.current,t=b.current,n=eI.current,a=++eL.current;try{var r,s,l,o;let i=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(i);if(!c.ok)return;let d=await c.json();if(eL.current!==a||eC.current!==e||t&&eI.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(),et(null!=(r=d.isSelectionListActive)&&r),ea(null!=(s=d.isPagerActive)&&s),X(null!=(l=d.lastServerResponseTimestamp)?l:null),Z(null!=(o=d.serverPollerActive)&&o),d.autoYes){let a=er.current,r=d.autoYes,s=t?n:e;J(e=>{let t=new Map(e);return t.set(s,{enabled:r.enabled,expiresAt:r.expiresAt}),t}),er.current=r.enabled,a&&!d.autoYes.enabled&&("stop_pattern_matched"===d.autoYes.stopReason||"consecutive_errors"===d.autoYes.stopReason)&&eo(d.autoYes.stopReason)}}catch(r){if(eL.current!==a||eC.current!==e||t&&eI.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching current output:",r)}},[f,j,y.prompt.visible]),tc=(0,o.useCallback)(async()=>{let e=++eA.current;try{let a=await fetch("/api/worktrees/".concat(f,"/auto-yes"));if(!a.ok)return;let r=await a.json();if(eA.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})}J(l)}catch(t){if(eA.current!==e)return;console.error("[WorktreeDetailRefactored] Error fetching auto-yes states:",t)}},[f]),{visibleInstances:td,visibleInstanceIds:tu,toggleInstanceVisible:tm}=function(e){let{worktreeId:t,roster:n}=e,[a,r]=(0,o.useState)(null);(0,o.useEffect)(()=>{r(function(e){try{let t=window.localStorage.getItem(at(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,o.useMemo)(()=>an(a,n),[a,n]),l=(0,o.useMemo)(()=>s.map(e=>e.id),[s]),i=(0,o.useMemo)(()=>null!==a&&n.some(e=>a.includes(e.id)),[a,n]),c=(0,o.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(at(t),JSON.stringify(s))}catch(e){}}},[n,t]),d=(0,o.useCallback)(e=>c(e),[c]);return{visibleInstances:s,visibleInstanceIds:l,hasStoredPreference:i,toggleInstanceVisible:(0,o.useCallback)(e=>{let t=an(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,o.useCallback)(e=>{null!==a&&c([...an(a,n).map(e=>e.id),...e])},[a,n,c])}}({worktreeId:f,roster:eu}),th=p?td:eu,tx=(0,o.useMemo)(()=>Array.from(new Set(td.map(e=>e.cliTool))),[td]),tf=p?tx:ei;(0,o.useEffect)(()=>{0!==th.length&&(th.some(e=>e.id===eS)||eE(th[0].id))},[th,eS,eE]),(0,o.useEffect)(()=>{let e=th.find(e=>e.id===eS);e&&e.cliTool!==ew&&eN(e.cliTool)},[th,eS,ew,eN]);let tg="opencode"===ew||"copilot"===ew,tp=(0,o.useCallback)(e=>{ec(e)},[]),tb=(0,o.useCallback)(e=>{em(e),ef(f)},[f]),tv=(0,o.useCallback)(e=>{eb(e)},[]),ty=(0,o.useCallback)(e=>{ey(e)},[]),tj=(0,o.useRef)(ew);(0,o.useEffect)(()=>{tj.current!==ew&&(tj.current=ew,j.clearMessages(),j.clearPrompt(),et(!1),to(),ti())},[ew,j,to,ti]),(0,o.useEffect)(()=>{to()},[eq,to]),(0,o.useEffect)(()=>{to()},[eX,to]);let{toasts:tw,showToast:tk,removeToast:tN}=(0,eB.dj)(),tC=(0,o.useCallback)(()=>{tk("Maximum ".concat(30," file tabs. Close a tab first."),"info")},[tk]),tS=(0,o.useCallback)(e=>{p?H(e):"limit_reached"===_.openFile(e)&&tC()},[p,_,tC]),tT=(0,o.useCallback)(e=>{p?H(e):"limit_reached"===_.openFile(e)&&tC()},[p,_,tC]),tE=(0,o.useCallback)(e=>{"limit_reached"===_.openFile(e)&&tC()},[_,tC]),tI=(0,o.useCallback)(()=>{H(null)},[]),tM=(0,o.useCallback)(e=>{eF(e=>e+1)},[]),tL=(0,o.useCallback)(()=>{U(null)},[]),tA=(0,o.useCallback)(()=>{ta.clearSearch(),_.closeAllTabs(),H(null),U(null)},[ta,_]),tP=(0,o.useCallback)(e=>{eF(e=>e+1)},[]),tR=(0,o.useCallback)(e=>{eU(e)},[eU]),tD=(0,o.useCallback)(()=>{g.push("/")},[g]),tF=(0,o.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]),tz=(0,o.useCallback)(()=>{z(!0)},[]),tO=(0,o.useCallback)(()=>{z(!1)},[]),t_=(0,o.useCallback)(async e=>{j.setPromptAnswering(!0);try{let t=sh(e,ew,y.prompt.data,b.current?eI.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 ti()}catch(e){console.error("[WorktreeDetailRefactored] Error sending prompt response:",e)}finally{j.setPromptAnswering(!1)}},[f,j,ti,ew,y.prompt.data]),tB=(0,o.useCallback)(()=>{j.clearPrompt()},[j]),tW=(0,o.useCallback)(e=>{j.setMobileActivePane(e)},[j]),tH=(0,o.useCallback)(()=>{to(),ti()},[to,ti]),tV=(0,o.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();J(t=>{let n=new Map(t);return n.set(a,{enabled:e.enabled,expiresAt:e.expiresAt}),n}),a===eI.current&&(er.current=e.enabled)}}catch(e){console.error("[WorktreeDetailRefactored] Error toggling auto-yes:",e)}},[f]),tU=(0,o.useCallback)(e=>tV(ew,eS)(e),[tV,ew,eS]),[tK,t$]=(0,o.useState)(null),[tq,tX]=(0,o.useState)(!1),tQ=(0,o.useRef)(!1),tZ=(0,o.useCallback)(e=>{t$(e)},[]),t0=(0,o.useCallback)(()=>{let e=eI.current,t=eC.current,n=(0,e2.O6)(eh.current,e,t);t$({cliToolId:t,instanceId:e,label:n})},[]),t1=(0,o.useCallback)(async()=>{if(!tK||tQ.current)return;tQ.current=!0,tX(!0);let e=()=>{tK.instanceId===eI.current&&(j.clearMessages(),j.clearPrompt())};try{await B.y.killSession(f,tK.cliToolId,tK.instanceId),e(),await tl(),t$(null)}catch(t){t instanceof B.hD&&404===t.status?(e(),await tl(),t$(null)):tk(w("session.failedToKill"),"error")}finally{tQ.current=!1,tX(!1)}},[tK,f,j,tl,tk,w]),t2=(0,o.useCallback)(()=>{tQ.current||t$(null)},[]),t4=(0,o.useCallback)(e=>{eW(e),eO(!0)},[]),t5=(0,o.useCallback)(async e=>{eO(!1);let t=e_?"".concat(e_,"/").concat(e):e;try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,ej.o)(t)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"file",content:""})})).ok)throw Error("Failed to create file");eF(e=>e+1)}catch(e){window.alert(k("fileOps.failedToCreateFile"))}},[f,e_,k]),t3=(0,o.useCallback)(()=>{eO(!1)},[]),t6=(0,o.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,ej.o)(n)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"directory"})})).ok)throw Error("Failed to create directory");eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to create directory:",e),window.alert(k("fileOps.failedToCreateDirectory"))}},[f,k]),t8=(0,o.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,ej.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):"";_.onFileRenamed(e,"".concat(t).concat(n)),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to rename:",e),window.alert(k("fileOps.failedToRename"))}},[f,_,k]),t9=(0,o.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,ej.o)(e),"?recursive=true"),{method:"DELETE"})).ok)throw Error("Failed to delete");(V===e||(null==V?void 0:V.startsWith("".concat(e,"/"))))&&U(null),_.onFileDeleted(e),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to delete:",e),window.alert(k("fileOps.failedToDelete"))}},[f,V,_,N,k,S]);(0,o.useEffect)(()=>{"stop_pattern_matched"===es?(tk(C("stopPatternMatched"),"info"),eo(null)):"consecutive_errors"===es&&(tk(C("consecutiveErrorsStopped"),"warning"),eo(null))},[es,tk,C]);let{moveTarget:t7,isMoveDialogOpen:ne,handleMove:nt,handleMoveConfirm:nn,handleMoveCancel:na}=function(e,t,n,a){let[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)(!1),c=(0,o.useCallback)((e,t)=>{s({path:e,type:t}),i(!0)},[]),d=(0,o.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})}),i=await s.json();if(!s.ok||!i.success){var o;let e=(null==(o=i.error)?void 0:o.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),i(!1)}},[r,e,t,n,a]);return{moveTarget:r,isMoveDialogOpen:l,handleMove:c,handleMoveConfirm:d,handleMoveCancel:(0,o.useCallback)(()=>{s(null),i(!1)},[])}}(f,()=>eF(e=>e+1),e=>tk(e,"success"),e=>tk(e,"error")),nr=(0,o.useRef)(null),ns=(0,o.useRef)(""),nl=(0,o.useCallback)(e=>{var t;ns.current=e,null==(t=nr.current)||t.click()},[]),no=(0,o.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=ns.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 rk.includes(t)}(l))return void tk("Unsupported file type: ".concat(l,". Allowed: ").concat(rk.join(", ")),"error");let o=function(e){var t;let n=function(e){let t=e.toLowerCase();return rw.find(e=>e.extension===t)}(e);return null!=(t=null==n?void 0:n.maxFileSize)?t:0x1400000}(l);if(r.size>o)return void tk("File too large. Maximum size: ".concat((o/1024/1024).toFixed(1),"MB"),"error");let i=new FormData;i.append("file",r);try{let e=await fetch("/api/worktrees/".concat(f,"/upload/").concat((0,ej.o)(s||".")),{method:"POST",body:i});if(!e.ok){let t=await e.json().catch(()=>({})),n=(null==t||null==(a=t.error)?void 0:a.message)||"Failed to upload file";tk(n,"error");return}let t=await e.json();tk("Uploaded: ".concat(t.filename),"success"),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to upload:",e),tk("Upload failed. Please try again.","error")}},[f,tk]),{data:ni}=eH(),nc=null!=(u=null==ni?void 0:ni.hasUpdate)&&u,{lastAutoResponse:nd}=function(e){let{worktreeId:t,cliTool:n,isPromptWaiting:a,promptData:r,autoYesEnabled:s,lastServerResponseTimestamp:l,serverPollerActive:i}=e,c=(0,o.useRef)(null),[d,u]=(0,o.useState)(null);return(0,o.useEffect)(()=>{var e;if(!a){c.current=null;return}if(!r||!s||i||l&&Date.now()-l<3e3)return;let o=(e={type:r.type,question:r.question},"".concat(e.type,":").concat(e.question));if(c.current===o)return;let d=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}(r);if(null===d)return;c.current=o,u(d);let m=sh(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,i]),{lastAutoResponse:d}}({worktreeId:f,cliTool:ew,isPromptWaiting:y.prompt.visible,promptData:y.prompt.data,autoYesEnabled:eP,lastServerResponseTimestamp:G,serverPollerActive:Q}),nu=(0,o.useCallback)(async()=>{R(null),A(!0),await tl()&&await Promise.all([to(),ti()]),A(!1)},[tl,to,ti]);!function(e){let{error:t,handleRetry:n,fetchWorktree:a,fetchMessages:r,fetchCurrentOutput:s,setError:l}=e,i=(0,o.useRef)(0),c=(0,o.useCallback)(async()=>{if("visible"!==document.visibilityState)return;let e=Date.now();if(!(e-i.current<5e3)){if(i.current=e,t)return void n();try{await Promise.all([a(),r(),s()])}finally{l(null)}}},[t,n,a,r,s,l]);(0,o.useEffect)(()=>(document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c)}),[c])}({error:P,handleRetry:nu,fetchWorktree:tl,fetchMessages:to,fetchCurrentOutput:ti,setError:R}),(0,o.useEffect)(()=>{if(tr.current)return;let e=!0;return(async()=>{D.current||A(!0),await Promise.all([tl(),to(),ti()]),e&&(A(!1),tr.current=!0)})(),()=>{e=!1}},[tl,to,ti]);let nm=null!=(m=null==I||null==(r=I.sessionStatusByCli)||null==(a=r[ew])?void 0:a.isRunning)&&m;(0,o.useEffect)(()=>{if(L||P)return;let e=setInterval(async()=>{let e=[ti(),tl()];p&&e.push(to()),await Promise.all(e)},nm?2e3:5e3);return()=>clearInterval(e)},[L,P,ti,tl,to,nm,p]),(0,o.useEffect)(()=>{tc()},[f,eg,tc]),(0,o.useEffect)(()=>{j.setLayoutMode(p?"tabs":"split")},[p,j]);let nh=(0,o.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"})(I,null!==y.error.type,ew),[I,y.error.type,ew]),nx=(0,o.useMemo)(()=>y.layout.mobileActivePane,[y.layout.mobileActivePane]),nf=null!=(h=null==I?void 0:I.name)?h:"Unknown",ng=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_CONTENT",path:e,content:t})},[_]),np=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_ERROR",path:e,error:t})},[_]),nb=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_LOADING",path:e,loading:t})},[_]);return{activeActivity:eV,activeCliTab:ew,activeInstanceId:eS,activeTab:nx,agentInstances:eu,autoYesEnabled:eP,autoYesExpiresAt:eR,autoYesStateMap:q,diffContent:e7,diffFilePath:te,disableAutoFollow:tg,displayedAgents:tf,displayedInstances:th,editorFilePath:V,error:P,fetchCurrentOutput:ti,fileInputRef:nr,fileSearch:ta,fileTreeRefresh:eD,handleActivityToggle:tR,handleAgentInstancesChange:tb,handleAutoYesToggle:tU,handleBackClick:tD,handleCloseDiff:tn,handleDelete:t9,handleDiffSelect:tt,handleDirtyChange:(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_DIRTY",path:e,isDirty:t})},[_]),handleEditorClose:tL,handleEditorSave:tP,handleFileInputChange:no,handleFilePanelSave:tM,handleFilePathClick:tS,handleFileSelect:tT,handleHistoryDisplayLimitChange:eQ,handleHistoryUserOnlyChange:eG,handleInfoClick:tz,handleInfoModalClose:tO,handleInsertConsumed:e8,handleInsertConsumedSingle:e9,handleInsertToMessage:e3,handleInsertToSplit:e6,handleKillCancel:t2,handleKillConfirm:t1,openKillConfirm:tZ,openActiveKillConfirm:t0,killTarget:tK,isKillPending:tq,handleLoadContent:ng,handleLoadError:np,handleMessageSent:tH,handleMobileFileViewerClose:tI,handleMobileTabChange:tW,handleMove:nt,resetFileTreeView:tA,handleMoveCancel:na,handleMoveConfirm:nn,handleNewDirectory:t6,handleNewFile:t4,handleNewFileCancel:t3,handleNewFileConfirm:t5,handleOpenFile:tE,handlePromptDismiss:tB,handlePromptRespond:t_,handleRename:t8,handleRetry:nu,handleSelectedAgentsChange:tp,handleSetLoading:nb,handleShowArchivedChange:eJ,handleUpload:nl,handleVibeLocalContextWindowChange:ty,rosterReady:eg,handleVibeLocalModelChange:tv,handleWorktreeStatusChange:tF,hasUpdate:nc,historyDisplayLimit:eX,historySubTab:eK,historyUserOnly:eY,isEditorMaximized:K,isInfoModalOpen:F,isMobile:p,isMoveDialogOpen:ne,isSelectionListActive:ee,isPagerActive:en,lastAutoResponse:nd,loading:L,makeAutoYesToggleHandler:tV,mobileFileViewerPath:W,mobileSelectedAgents:tx,moveTarget:t7,newFileParentPath:e_,openMobileDrawer:v,pendingInsertText:e4,pendingInsertTextMap:e1,removeToast:tN,selectedAgents:ei,setActiveCliTab:eN,setActiveInstanceId:eE,setEditorFilePath:U,setFocusedSplitIndex:e5,setHistorySubTab:e$,setIsEditorMaximized:$,setWorktree:M,showArchived:eq,showNewFileDialog:ez,showToast:tk,state:y,tCommon:N,tWorktree:w,tabsActions:_,tabsState:O,toasts:tw,toggleInstanceVisible:tm,vibeLocalContextWindow:ev,vibeLocalModel:ep,visibleInstanceIds:tu,worktree:I,worktreeName:nf,worktreeStatus:nh}}({worktreeId:m}),[tM,tL]=(0,o.useState)(!1),tA=function(e){let{worktreeId:t,active:n}=e,{addListener:a}=(0,td.xM)(),[r,s]=(0,o.useState)(!1),l=(0,o.useRef)(n);return l.current=n,(0,o.useEffect)(()=>{n&&s(!1)},[n]),(0,o.useEffect)(()=>a(e=>{e.worktreeId===t&&("terminal_snapshot"===e.type||"message"===e.type)&&(l.current||s(!0))}),[a,t]),!n&&r}({worktreeId:m,active:"terminal"===v}),{viewportHeight:tP}=(0,sw.C)(),tR=(0,o.useCallback)(e=>{let t=sW.indexOf(v);if(-1===t)return;let n=t+e;n<0||n>=sW.length||ek(sW[n])},[v,ek]),{ref:tD}=(0,L.hU)({axis:"horizontal",threshold:60,edgeStartZone:32*("terminal"===v),onSwipeLeft:()=>tR(1),onSwipeRight:()=>tR(-1)});if(e3)return(0,r.jsx)(re,{});if(A)return(0,r.jsx)(rt,{message:A,onRetry:eF});let tF=(0,e2.O6)(y,b,g),tz=null!=(l=null==eg?void 0:eg.label)?l:tF,tO=null!=(u=null==(t=null!=(i=null==tT||null==(n=tT.sessionStatusByInstance)?void 0:n[b])?i:null==tT||null==(a=tT.sessionStatusByCli)?void 0:a[g])?void 0:t.isRunning)&&u;return eX?(0,r.jsx)(S,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden",style:{height:null!=tP?"".concat(tP,"px"):"100%"},"data-testid":"mobile-worktree-shell",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(p,{worktreeName:tE,repositoryName:null==tT?void 0:tT.repositoryName,status:tI,gitStatus:null==tT?void 0:tT.gitStatus,onBackClick:V,onMenuClick:tt})}),(null==tT?void 0:tT.gitStatus)&&tT.gitStatus.isBranchMismatch&&(0,r.jsx)("div",{className:"z-35 flex-shrink-0",children:(0,r.jsx)(sg,{isBranchMismatch:tT.gitStatus.isBranchMismatch,currentBranch:tT.gitStatus.currentBranch,initialBranch:tT.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":tb("detail.agentInstanceSelection"),children:I.map(e=>{var t,n,a;let s=(0,e1.kA)(null!=(a=null==tT||null==(t=tT.sessionStatusByInstance)?void 0:t[e.id])?a:null==tT||null==(n=tT.sessionStatusByCli)?void 0:n[e.cliTool]),l=tp("status.".concat(s)),o=b===e.id;return(0,r.jsxs)("button",{onClick:()=>tl(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(o?"text-accent-600 dark:text-accent-400 border-accent-500":"text-muted-foreground hover:text-foreground border-transparent"),"aria-current":o?"page":void 0,children:[(0,r.jsx)(h.m,{status:s,size:"sm",label:tb("detail.statusPill",{label:(0,e2.sw)(e),status:l})}),(0,e2.sw)(e)]},e.id)})}),(0,r.jsx)("button",{type:"button",onClick:()=>tL(!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":tb("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:tD,children:(0,r.jsx)(a4,{activeTab:v,worktreeId:m,worktree:tT,messages:tg.messages,cliToolId:g,instanceId:b,onFilePathClick:Z,onFileSelect:et,onWorktreeUpdate:tm,onNewFile:eE,onNewDirectory:eT,onRename:eR,onDelete:K,onUpload:e_,onMove:eN,onFileTreeReset:tj,refreshTrigger:z,fileSearch:F,showToast:tf,selectedAgents:e9,onSelectedAgentsChange:sB,useInstanceManagement:!0,instances:y,onInstancesChange:W,visibleInstanceIds:tS,onToggleInstanceVisible:tk,vibeLocalModel:tC,onVibeLocalModelChange:eV,vibeLocalContextWindow:tN,onVibeLocalContextWindowChange:eW,disableAutoFollow:E,historySubTab:eq,onHistorySubTabChange:tc,onDiffSelect:$,onInsertToMessage:ed,showArchived:th,onShowArchivedChange:eO,historyDisplayLimit:e$,onHistoryDisplayLimitChange:en,historyUserOnly:eJ,onHistoryUserOnlyChange:ea})}),(0,r.jsxs)("div",{className:"flex-shrink-0 border-t border-border bg-surface z-30",children:[eZ&&(0,r.jsx)("div",{className:"px-2 pt-1 border-b border-border",children:(0,r.jsx)(es,{worktreeId:m,cliToolId:g,instanceId:b,onKeysSent:R,showPagerKeys:e4})}),(0,r.jsx)("div",{className:"p-2",children:(0,r.jsx)(ee,{worktreeId:m,onMessageSent:ey,cliToolId:g,instanceId:b,isSessionRunning:tO,pendingInsertText:tn,onInsertConsumed:ec,autoYesSlot:(0,r.jsx)(sd,{enabled:j,expiresAt:w,onToggle:H,lastAutoResponse:e5,cliToolName:g,inline:!0,showToolName:!1})})})]}),(0,r.jsx)(C,{activeTab:v,onTabChange:ek,hasNewOutput:tA,hasPrompt:tg.prompt.visible,hasUpdate:eK,inFlow:!0}),!j&&(0,r.jsx)(P,{promptData:tg.prompt.data,visible:tg.prompt.visible,answering:tg.prompt.answering,onRespond:eP,onDismiss:eA,cliToolName:(0,e2.oo)(g)}),(0,r.jsx)(_,{open:tM,onClose:()=>tL(!1),onSearch:()=>window.dispatchEvent(new CustomEvent("terminal-search-open")),onEnd:ef,endDisabled:!tO}),(0,r.jsx)(eD,{isOpen:null!==e8,onClose:ew,worktreeId:m,filePath:null!=e8?e8:"",onEditMarkdown:to}),M&&(0,r.jsx)(e0.a,{isOpen:!0,onClose:J,title:M.split("/").pop()||tb("fileViewer.editor"),size:"full",disableClose:eY,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(s_,{worktreeId:m,filePath:M,onClose:J,onSave:G,onMaximizedChange:tu,initialViewMode:"split"})})}),(0,r.jsx)("input",{ref:D,type:"file",accept:rk.join(","),onChange:X,className:"hidden","aria-label":tb("detail.uploadFile")}),(0,r.jsx)(e0.a,{isOpen:null!==eg,onClose:em,title:tb("session.confirmEnd",{tool:tz}),size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:tb("session.endWarning")}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:em,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:tp("cancel")}),(0,r.jsx)("button",{type:"button",onClick:eh,disabled:ep,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:tp("end")})]})]})}),e7&&(0,r.jsx)(sb,{isOpen:eQ,onClose:eC,onConfirm:eS,worktreeId:m,sourcePath:e7.path,sourceType:e7.type}),(0,r.jsx)(sy,{isOpen:tx,parentPath:te,onConfirm:eM,onCancel:eI}),(0,r.jsx)(eB.N9,{toasts:tw,onClose:tr})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(sj,{worktreeId:m,worktree:tT,worktreeName:tE,worktreeStatus:tI,instances:y,rosterReady:ts,activeInstanceId:b,setActiveInstanceId:tl,hasUpdate:eK,lastAutoResponse:e5,activeActivity:f,onActivityToggle:O,onBackClick:V,onInfoClick:er,onWorktreeStatusChange:eU,pendingInsertTextMap:ta,setFocusedSplitIndex:ti,handleInsertToSplit:eu,handleInsertConsumed:ei,handleInsertToMessage:ed,autoYesStateMap:k,makeAutoYesToggleHandler:e6,showArchived:th,onShowArchivedChange:eO,historyDisplayLimit:e$,onHistoryDisplayLimitChange:en,historyUserOnly:eJ,onHistoryUserOnlyChange:ea,onMessageSent:ey,onFilePathClick:Z,showToast:tf,tabsState:ty,tabsActions:tv,onLoadContent:eb,onLoadError:ev,onSetLoading:ez,onFilePanelSave:Q,onDirtyChange:q,onOpenFile:eL,diffContent:N,diffFilePath:T,onCloseDiff:U,fileSearch:F,fileTreeRefresh:z,onFileSelect:et,onNewFile:eE,onNewDirectory:eT,onRename:eR,onDelete:K,onUpload:e_,onMove:eN,onFileTreeReset:tj,onDiffSelect:$,onAgentInstancesChange:W,vibeLocalModel:tC,onVibeLocalModelChange:eV,vibeLocalContextWindow:tN,onVibeLocalContextWindowChange:eW,isInfoModalOpen:eG,onInfoModalClose:eo,onWorktreeUpdate:tm,fileInputRef:D,onFileInputChange:X,onKillSession:ef,onRequestSessionEnd:ex,killTarget:eg,isKillPending:ep,onKillCancel:em,onKillConfirm:eh,moveTarget:e7,isMoveDialogOpen:eQ,onMoveCancel:eC,onMoveConfirm:eS,showNewFileDialog:tx,newFileParentPath:te,onNewFileConfirm:eM,onNewFileCancel:eI,toasts:tw,onToastClose:tr,killDialogTitle:tb("session.confirmEnd",{tool:tz}),killDialogWarning:tb("session.endWarning"),cancelLabel:tp("cancel"),endLabel:tp("end")}),M&&(0,r.jsx)(e0.a,{isOpen:!0,onClose:J,title:M.split("/").pop()||tb("fileViewer.editor"),size:"full",disableClose:eY,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(s_,{worktreeId:m,filePath:M,onClose:J,onSave:G,onMaximizedChange:tu})})})]})});function sV(){let e=(0,s.useParams)().id;return(0,r.jsx)(l.GV,{children:(0,r.jsx)(sH,{worktreeId:e})})}},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:o=!0,axis:i="both",directionLock:c,directionLockThreshold:d=12,suppressWhenScrollable:u=!0,edgeStartZone:m=0,onSwipeMove:h,onSwipeEnd:x}=e,f=null!=c?c:"both"!==i,g="horizontal"===i?"horizontal":"vertical",p="both"===i||"horizontal"===i,b="both"===i||"vertical"===i,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(!o)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,g)){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)},[o,u,g,m]),E=(0,a.useCallback)(e=>{if(!o||!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(f){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!==i){e.cancelled=!0;return}}if(null!==e.committed&&e.committed!==i)return}}p&&r>s&&r>=l?k(n<0?"left":"right"):b&&s>=l&&k(a<0?"up":"down"),null==h||h({deltaX:n,deltaY:a})},[o,l,i,f,d,p,b,h]),I=(0,a.useCallback)(e=>{var a;if(!o||!N.current)return void j(!1);let i=f&&(null==(a=C.current)?void 0:a.cancelled)===!0,c=e.changedTouches[0];if(!i&&c){let e=c.clientX-N.current.x,a=c.clientY-N.current.y,o=Math.abs(e),i=Math.abs(a);o>i?p&&o>=l&&(e<0?(k("left"),null==t||t()):(k("right"),null==n||n())):b&&i>=l&&(a<0?(k("up"),null==r||r()):(k("down"),null==s||s()))}N.current=null,C.current=null,j(!1),null==x||x()},[o,l,f,p,b,t,n,r,s,x]),M=(0,a.useCallback)(()=>{N.current&&(N.current=null,C.current=null,j(!1),null==x||x())},[x]);return(0,a.useEffect)(()=>{let e=v.current;if(e)return e.addEventListener("touchstart",T),e.addEventListener("touchmove",E),e.addEventListener("touchend",I),e.addEventListener("touchcancel",M),()=>{e.removeEventListener("touchstart",T),e.removeEventListener("touchmove",E),e.removeEventListener("touchend",I),e.removeEventListener("touchcancel",M)}},[T,E,I,M]),{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,o=(0,s.c)("worktree"),[i,c]=(0,r.useState)(!1);return i?(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:o("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:()=>o,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),o=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,5235))},27307:(e,t,n)=>{"use strict";n.r(t),n.d(t,{PdfPreview:()=>i,default:()=>c});var a=n(95155),r=n(12115),s=n(18955);n(19985);let l=void 0;var o=n(3005);function i(e){let{dataUri:t,filePath:n,variant:i="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)(o.y,{size:"xl",variant:"accent"})});if("download"===i){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=i},46892:(e,t,n)=>{"use strict";n.d(t,{PL:()=>r,sb:()=>s});let a={idle:"bg-muted-foreground",ready:"bg-success",spinner:"border-info",waiting:"bg-warning"},r={idle:{className:a.idle,labelKey:"status.idle",type:"dot"},ready:{className:a.ready,labelKey:"status.ready",type:"dot"},running:{className:a.spinner,labelKey:"status.running",type:"spinner"},waiting:{className:a.waiting,labelKey:"status.waiting",type:"dot"},generating:{className:a.spinner,labelKey:"status.generating",type:"spinner"}},s={idle:"detailStatus.idle",ready:"detailStatus.ready",running:"detailStatus.running",waiting:"detailStatus.waiting"}},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),o=(0,a.useCallback)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport,n=window.innerHeight,a=e.height,s=n-a,o=s>100;t(o),r(o?s:0),l(a)},[]);return(0,a.useEffect)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport;return o(),e.addEventListener("resize",o),()=>{e.removeEventListener("resize",o)}},[o]),{isKeyboardVisible:e,keyboardHeight:n,viewportHeight:s}}},53292:(e,t,n)=>{"use strict";n.d(t,{Ll:()=>a,bu:()=>r});let a=2e3,r=4e3},53482:(e,t,n)=>{"use strict";n.d(t,{i:()=>c});var a=n(95155),r=n(12115),s=n(60322),l=n(9900);function o(){return(0,a.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function i(){return(0,a.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function c(e){let{text:t,className:n="",label:c="Copy"}=e,[d,u]=(0,r.useState)(!1),m=(0,r.useRef)(null);(0,r.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=(0,r.useCallback)(async()=>{try{await (0,s.l)(t),u(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>u(!1),l.s7)}catch(e){}},[t]);return(0,a.jsxs)("button",{type:"button",onClick:h,className:"inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground transition-colors hover:bg-muted ".concat(n),"aria-label":d?"Copied":c,title:d?"Copied!":c,children:[d?(0,a.jsx)(i,{}):(0,a.jsx)(o,{}),(0,a.jsx)("span",{children:d?"Copied":c})]})}},60322:(e,t,n)=>{"use strict";n.d(t,{l:()=>r});let a=/\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07]*\x07|\[[0-9;]*m/g;async function r(e){var t;if(!e||0===e.trim().length)return;let n=e.replace(a,"");if(null==(t=navigator.clipboard)?void 0:t.writeText)try{await navigator.clipboard.writeText(n);return}catch(e){}let r=document.createElement("textarea");r.value=n,r.style.position="fixed",r.style.left="-9999px",r.style.top="-9999px",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();try{document.execCommand("copy")}finally{document.body.removeChild(r)}}},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:o}=e,[i,c]=(0,a.useState)(!1),[d,u]=(0,a.useState)(null),m=(0,a.useRef)(t),h=(0,a.useRef)(n),x=(0,a.useRef)(o),f=(0,a.useRef)(null),g=(0,a.useRef)(!0),p=(0,a.useRef)(t);(0,a.useEffect)(()=>{m.current=t},[t]),(0,a.useEffect)(()=>{h.current=n},[n]),(0,a.useEffect)(()=>{x.current=o},[o]),(0,a.useEffect)(()=>(g.current=!0,()=>{g.current=!1,f.current&&clearTimeout(f.current)}),[]);let b=(0,a.useCallback)(async e=>{if(!g.current)return;c(!0),u(null);let t=null,n=0;for(;n<=l;)try{if(await h.current(e),g.current){var a;c(!1),u(null),null==(a=x.current)||a.call(x)}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))}}g.current&&(c(!1),u(t))},[l]),v=(0,a.useCallback)(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),y=(0,a.useCallback)(async()=>{s||(v(),await b(m.current))},[s,v,b]);return(0,a.useEffect)(()=>{if(t!==p.current&&!s)return v(),f.current=setTimeout(()=>{b(m.current)},r),()=>{v()}},[t,s,r,v,b]),{isSaving:i,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 o(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}n.d(t,{Nt:()=>r,W5:()=>l,ZD:()=>o,q3:()=>s,sg:()=>a})},69264:(e,t,n)=>{"use strict";n.d(t,{u:()=>o});var a=n(95155),r=n(12115),s=n(18955),l=n(3005);function o(e){let{src:t,onError:n}=e,o=(0,s.c)("worktree"),[i,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:o("videoViewer.loadError")})]}):(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center p-4",children:[i&&(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:o("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:i?"none":"block"},className:"rounded-lg shadow-sm",children:o("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"],o=["w-1","h-full","cursor-col-resize","before:content-['']","before:absolute","before:inset-y-0","before:-inset-x-1"],i=["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"),[x,f]=(0,r.useState)(!1),g=(0,r.useRef)(0),p=(0,r.useRef)(null),b="horizontal"===n,v=(0,r.useCallback)(e=>{e.preventDefault(),f(!0),g.current=c(e,b)},[b]),y=(0,r.useCallback)(e=>{1===e.touches.length&&(f(!0),g.current=c(e,b))},[b]),j=(0,r.useCallback)(e=>{if(!x)return;let n=c(e,b);t(n-g.current),g.current=n},[x,b,t]),w=(0,r.useCallback)(e=>{if(!x||1!==e.touches.length)return;let n=c(e,b);t(n-g.current),g.current=n},[x,b,t]),k=(0,r.useCallback)(()=>{f(!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)(()=>(x&&(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=""}),[x,j,k,w,b]);let S=(0,r.useMemo)(()=>[...l,...b?o:i,...x?["bg-accent-500","dark:bg-accent-500","dragging",b?"w-2":"h-2"]:[]].join(" "),[b,x]);return(0,a.jsx)("div",{ref:p,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})})},76246:(e,t,n)=>{"use strict";function a(e){return e?e.split("/").map(encodeURIComponent).join("/"):""}n.d(t,{o:()=>a})},83012:(e,t,n)=>{"use strict";n.d(t,{Fx:()=>l,bg:()=>o,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 o(e,t){return!(e instanceof Date)||isNaN(e.getTime())?"":(0,r.GP)(e,"PPp",t?{locale:t}:void 0)}},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")}}}},e=>{e.O(0,[6481,6809,4909,2770,3165,4974,9948,2069,8965,6402,744,7347,8954,8441,1255,7358],()=>e(e.s=20252)),_N_E=e.O()}]);
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1479],{5235:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>sV});var a,r=n(95155),s=n(20063),l=n(78954),o=n(12115),i=n(67909),c=n(18955),d=n(37772),u=n(3005),m=n(744),h=n(48481),x=n(64269);let f=(0,o.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"};function p(e){let{worktreeName:t,repositoryName:n,status:a,gitStatus:s,onBackClick:l,onMenuClick:o}=e,i=(0,c.c)("common"),d=(0,c.c)("worktree");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":i("back"),className:"p-2 -ml-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(f,{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.jsx)("div",{className:"w-10 flex-shrink-0 flex justify-end",children:o&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:o,"aria-label":i("menu"),className:"p-2 -mr-2 rounded-full hover:bg-muted transition-colors dark:text-foreground",children:(0,r.jsx)(f,{path:g.menu})})})]})})}var b=n(22479),v=n(26983),y=n(59847),j=n(53842),w=n(23327);function k(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 N=[{id:"terminal",labelKey:"tabs.terminal",icon:(0,r.jsx)(b.A,{size:20,"aria-hidden":"true"})},{id:"history",labelKey:"tabs.history",icon:(0,r.jsx)(v.A,{size:20,"aria-hidden":"true"})},{id:"files",labelKey:"tabs.files",icon:(0,r.jsx)(y.A,{size:20,"aria-hidden":"true"})},{id:"memo",labelKey:"tabs.memo",icon:(0,r.jsx)(j.A,{size:20,"aria-hidden":"true"})},{id:"info",labelKey:"tabs.info",icon:(0,r.jsx)(w.A,{size:20,"aria-hidden":"true"})}];function C(e){let{activeTab:t,onTabChange:n,hasNewOutput:a=!1,hasPrompt:s=!1,hasUpdate:l=!1,onSearchParamsChange:i,inFlow:d=!1}=e,u=(0,c.c)("worktree"),m=(0,o.useRef)([]),h=(0,o.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]),x=(0,o.useCallback)(e=>{n(e),null==i||i("memo"===e?"notes":e)},[n,i]),f=(0,o.useCallback)((e,t)=>{var n;let a=null;switch(e.key){case"ArrowRight":case"ArrowDown":a=(t+1)%N.length;break;case"ArrowLeft":case"ArrowUp":a=(t-1+N.length)%N.length;break;case"Home":a=0;break;case"End":a=N.length-1;break;default:return}e.preventDefault(),null==(n=m.current[a])||n.focus(),x(N[a].id)},[x]),g=(0,o.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:N.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:()=>x(e.id),onKeyDown:e=>f(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&&g,"info"===e.id&&l&&(0,r.jsx)(k,{"data-testid":"info-update-badge",className:"absolute top-1 right-1","aria-label":u("tabs.updateAvailable")})]},e.id))})}class S extends o.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)(T,{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 T(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 E={fadeIn:"animate-fade-in",fadeOut:"animate-fade-out",none:""};function I(e){let{visible:t,duration:n=200}=e,[a,r]=(0,o.useState)(t?"visible":"hidden"),s=(0,o.useRef)(null),l=(0,o.useRef)(t);(0,o.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),(0,o.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 i="hidden"!==a,c="fade-in"===a||"fade-out"===a;return{shouldRender:i,animationClass:(0,o.useMemo)(()=>{switch(a){case"fade-in":return E.fadeIn;case"fade-out":return E.fadeOut;default:return E.none}},[a]),isAnimating:c}}var M=n(92539),L=n(8269);let A={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"},P=(0,o.memo)(function(e){let{promptData:t,visible:n,answering:a,onRespond:s,onDismiss:l,cliToolName:i}=e,{shouldRender:c,animationClass:d}=I({visible:n&&null!==t,duration:300}),u=(0,o.useId)(),m=n&&null!==t,h=(0,M.r)({active:m}),[x,f]=(0,o.useState)(0);(0,o.useEffect)(()=>{n||f(0)},[n]);let g=(0,o.useCallback)(e=>{let{deltaY:t}=e;f(t>0?t:0)},[]),p=(0,o.useCallback)(()=>{null==l||l()},[l]),b=(0,o.useCallback)(()=>{f(0)},[]),{ref:v}=(0,L.hU)({axis:"vertical",threshold:100,enabled:m,onSwipeMove:g,onSwipeDown:p,onSwipeEnd:b}),y=(0,o.useCallback)(e=>{h.current=e,v.current=e},[h,v]),j=(0,o.useCallback)(()=>{l&&l()},[l]),w=(0,o.useCallback)(e=>{e.stopPropagation()},[]);if(!c||!t)return null;let k="animate-fade-out"===d;return(0,r.jsxs)(S,{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:x>0?"translateY(".concat(x,"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)(R,{promptData:t,answering:a,onRespond:s,labelId:u,cliToolName:i})})]})]})});function R(e){let{promptData:t,answering:n,onRespond:a,labelId:s,cliToolName:l}=e,i=(0,c.c)("prompt"),[d,u]=(0,o.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,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(!1),p=(0,o.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===d))?e:null},[t,d]),b=(null==p?void 0:p.requiresTextInput)===!0,v=n||f,y=(0,o.useCallback)(async e=>{if(!v){g(!0);try{await a(e)}catch(e){}finally{g(!1)}}},[v,a]),j=(0,o.useCallback)(async()=>{if(!v&&null!==d){g(!0);try{let e=b&&h.trim()?h.trim():d.toString();await a(e)}catch(e){}finally{g(!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?i("confirmationFrom",{toolName:l}):i("confirmationFromClaude")}),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:i("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(D,{promptData:t,disabled:v,onYes:()=>y("yes"),onNo:()=>y("no")}),"multiple_choice"===t.type&&(0,r.jsx)(F,{promptData:t,disabled:v,selectedOption:d,onSelectOption:u,textInputValue:h,onTextInputChange:x,showTextInput:b,onSubmit:j})]})}let D=(0,o.memo)(function(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),o="yes"===t.defaultOption,i="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(A.base," ").concat(A.primary," ").concat(o?"ring-2 ring-accent-300":""),children:l("yes")}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:n,className:"flex-1 ".concat(A.base," ").concat(i?A.defaultSelected:A.secondary),children:l("no")})]})}),F=(0,o.memo)(function(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:i,showTextInput:d,onSubmit:u}=e,h=(0,o.useId)(),x=(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:x("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:x("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:x("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>i(e.target.value),disabled:n,placeholder:x("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(A.base," ").concat(A.primary),children:x("submit")})]})});var z=n(86651),O=n(84926);function _(e){let{open:t,onClose:n,onSearch:a,onEnd:s,endDisabled:l=!1}=e,i=(0,c.c)("worktree"),d=(0,o.useId)(),u=(0,M.r)({active:t}),m=(0,o.useCallback)(()=>{a(),n()},[a,n]),h=(0,o.useCallback)(()=>{s(),n()},[s,n]);return((0,o.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:i("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)(z.A,{size:18,"aria-hidden":"true",className:"text-muted-foreground"}),i("terminal.searchTerminal")]}),(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)(O.A,{size:18,"aria-hidden":"true"}),i("terminal.endSession")]})]})]})]}):null}var B=n(80344),W=n(79651);function H(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 V(e){return"codex-skill"===e.source?"$".concat(e.name):"/".concat(e.name)}function U(e,t){var n;return e.descriptionKey?t(e.descriptionKey):null!=(n=e.description)?n:""}function K(e){let{groups:t,onSelect:n,highlightedIndex:a=-1,className:s=""}=e,l=(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:l("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 i=s===a;return(0,r.jsxs)("button",{type:"button","data-command-item":!0,"data-highlighted":i,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(i?"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:V(e)}),(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"}),(0,r.jsx)("span",{className:"text-muted-foreground text-sm truncate",children:U(e,l)})]},e.name)})})]},e.category))})}let $=(0,o.memo)(function(e){let{isOpen:t,groups:n,onSelect:a,onClose:s,isMobile:l=!1,position:i,onFreeInput:d}=e,[u,m]=(0,o.useState)(""),[h,x]=(0,o.useState)(0),f=(0,o.useRef)(null),g=(0,c.c)("worktree"),p=(0,c.c)("common"),b=(0,o.useMemo)(()=>H(n,u,e=>U(e,g)),[n,u,g]),v=(0,o.useMemo)(()=>b.flatMap(e=>e.commands),[b]);(0,o.useEffect)(()=>{t&&(m(""),x(0),setTimeout(()=>{var e;null==(e=f.current)||e.focus()},50))},[t]);let y=(0,o.useCallback)(e=>{a(e),s()},[a,s]),j=(0,o.useCallback)(e=>{if(t)switch(e.key){case"Escape":e.preventDefault(),s();break;case"ArrowDown":e.preventDefault(),x(e=>Math.min(e+1,v.length-1));break;case"ArrowUp":e.preventDefault(),x(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),v[h]&&y(v[h])}},[t,v,h,s,y]);return((0,o.useEffect)(()=>{if(t)return document.addEventListener("keydown",j),()=>{document.removeEventListener("keydown",j)}},[t,j]),t)?l?(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:g("slashCommands.title")}),(0,r.jsx)("button",{type:"button",onClick:s,"aria-label":p("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:f,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:g("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(u),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:g("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(K,{groups:b,onSelect:y,highlightedIndex:h,className:"flex-1 overflow-y-auto pb-20"})]})]}):(0,r.jsxs)("div",{role:"listbox",className:"absolute bg-surface border border-border rounded-lg shadow-lg z-50 w-80 max-h-96 flex flex-col",style:i?{top:i.top,left:i.left}:{bottom:"100%",left:0,marginBottom:"4px"},children:[(0,r.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,r.jsx)("input",{ref:f,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:g("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(u),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:g("slashCommands.enterCustomCommand")})]}),(0,r.jsx)(K,{groups:b,onSelect:y,highlightedIndex:h,className:"flex-1 overflow-y-auto"}),(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"})," ",g("slashCommands.selectHint")]}),(0,r.jsxs)("span",{children:[(0,r.jsx)("kbd",{className:"px-1 py-0.5 bg-muted rounded",children:"Esc"})," ",g("slashCommands.closeHint")]})]})]}):null}),q=(0,o.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disabled:s=!1,onInterrupt:l}=e,i=(0,c.c)("worktree"),[d,m]=(0,o.useState)(!1),h=(0,o.useRef)(0),x=(0,o.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:x,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":i("interrupt.stopProcessing"),"data-testid":"interrupt-button",children:d?(0,r.jsx)(u.y,{size:"md"}):(0,r.jsx)(J,{})})});function J(){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 Y=n(38218),G=n(19985);let X="commandmate:draft-message:",Q="Queued (session busy) — your message will run after the current task finishes.";function Z(e,t){return"".concat(X).concat(e,":").concat(t)}let ee=(0,o.memo)(function(e){let{worktreeId:t,onMessageSent:n,cliToolId:a,instanceId:s,isSessionRunning:l=!1,pendingInsertText:i,onInsertConsumed:d,splitIndex:u=0,onFocus:h,isProcessing:x=!1,showToast:f,autoYesSlot:g,onOptimisticSend:p}=e,b=(0,c.c)("worktree"),[v,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(!1),[k,N]=(0,o.useState)(null),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(!1),[I,M]=(0,o.useState)(!1),L=(0,o.useRef)(null),A=(0,o.useRef)(null),P=(0,o.useRef)(!1),R=(0,o.useRef)(null),D=(0,o.useRef)(null),F=(0,Y.a)(),{groups:z}=function(e,t){let[n,a]=(0,o.useState)([]),[r,s]=(0,o.useState)(!0),[l,i]=(0,o.useState)(null),[c,d]=(0,o.useState)(""),[u,m]=(0,o.useState)(t||"claude"),h=(0,o.useCallback)(async()=>{try{s(!0),i(null);let n=e?"/api/worktrees/".concat(e,"/slash-commands"):"/api/slash-commands";t&&(n+="?cliTool=".concat(t));let r=await fetch(n);if(!r.ok)throw Error("HTTP error ".concat(r.status));let l=await r.json();a(l.groups),m(l.cliTool||t||"claude")}catch(e){i((0,B.hS)(e)),a([])}finally{s(!1)}},[e,t]);(0,o.useEffect)(()=>{h()},[h]);let x=(0,o.useMemo)(()=>n.flatMap(e=>e.commands),[n]),f=(0,o.useMemo)(()=>H(n,c),[n,c]);return{groups:n,filteredGroups:f,allCommands:x,loading:r,error:l,filter:c,setFilter:d,refresh:(0,o.useCallback)(()=>{h()},[h]),cliTool:u}}(t,a),{attachedImage:O,fileInputRef:_,isUploading:U,error:K,acceptAttribute:J,openFileDialog:ee,handleFileSelect:et,removeAttachment:en,resetAfterSend:ea}=function(e,t){let[n,a]=(0,o.useState)(null),[r,s]=(0,o.useState)(!1),[l,i]=(0,o.useState)(null),c=(0,o.useRef)(null),d=(0,o.useCallback)(()=>{var e;null==(e=c.current)||e.click()},[]),u=(0,o.useCallback)(async n=>{var r;let l=null==(r=n.target.files)?void 0:r[0];if(!l)return;i(null);let o=function(e){let t=e.name.lastIndexOf(".");if(-1===t)return"Unsupported file format";let n=(0,G.HB)(e.name.substring(t));if(!G.Hv.includes(n))return"Unsupported file format: ".concat(n);if(e.size>G.Fg){let e=G.Fg/1024/1024;return"File size exceeds ".concat(e,"MB limit")}return null}(l);if(o){i(o),c.current&&(c.current.value="");return}s(!0);try{let n=await t(e,l);a({file:l,path:n.path})}catch(e){i(e instanceof Error?e.message:"Upload failed")}finally{s(!1),c.current&&(c.current.value="")}},[e,t]),m=(0,o.useCallback)(()=>{a(null),i(null)},[]),h=(0,o.useCallback)(()=>{a(null)},[]);return{attachedImage:n,fileInputRef:c,isUploading:r,error:l,acceptAttribute:G.F5,openFileDialog:d,handleFileSelect:u,removeAttachment:m,resetAfterSend:h}}(t,(0,o.useCallback)((e,t)=>B.y.uploadImageFile(e,t),[]));(0,o.useEffect)(()=>{try{0===u&&function(e){try{let t="".concat(X).concat(e),n=window.localStorage.getItem(t);if(null===n)return;let a=Z(e,0);null===window.localStorage.getItem(a)&&window.localStorage.setItem(a,n),window.localStorage.removeItem(t)}catch(e){}}(t);let e=window.localStorage.getItem(Z(t,u));e?y(e):y("")}catch(e){}return()=>{D.current&&clearTimeout(D.current)}},[t,u]),(0,o.useEffect)(()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{try{let e=Z(t,u);v?window.localStorage.setItem(e,v):window.localStorage.removeItem(e)}catch(e){}},500)},[v,t,u]),(0,o.useEffect)(()=>{let e=L.current;e&&(v?(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px")):e.style.height="24px")},[v]),(0,o.useEffect)(()=>{i&&(y(e=>""===e.trim()?i:e+"\n\n"+i),null==d||d())},[i,d]);let er=(0,o.useCallback)(async()=>{if(C||!v.trim()&&!O||j)return;let e=v.trim(),r=a||"claude",l={cliToolId:r};if(s&&s!==r&&(l.instanceId=s),O&&(l.imagePath=O.path),p){N(null),p(e,l),y(""),M(!1),ea();try{window.localStorage.removeItem(Z(t,u))}catch(e){}x&&(null==f||f(Q,"warning")),null==n||n(r);return}try{w(!0),N(null),await B.y.sendMessage(t,e,l),y(""),M(!1),ea();try{window.localStorage.removeItem(Z(t,u))}catch(e){}x&&(null==f||f(Q,"warning")),null==n||n(r)}catch(e){N((0,B.hS)(e))}finally{w(!1)}},[C,v,O,j,t,a,s,n,ea,u,x,f,p]),es=(0,o.useCallback)(async e=>{e.preventDefault(),await er()},[er]),el=(0,o.useCallback)(()=>{S(!0),P.current=!1,A.current&&clearTimeout(A.current)},[]),eo=(0,o.useCallback)(()=>{S(!1),P.current=!0,A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{P.current=!1},300)},[]),ei=(0,o.useCallback)(e=>{var t;y("".concat(V(e)," ")),E(!1),null==(t=L.current)||t.focus()},[]),ec=(0,o.useCallback)(()=>{var e;E(!1),M(!1),null==(e=L.current)||e.focus()},[]),ed=(0,o.useCallback)(e=>{E(!1),M(!0),y(e?"/".concat(e):"/"),setTimeout(()=>{var e;null==(e=L.current)||e.focus()},50)},[]),eu=(0,o.useCallback)(e=>{let t=e.target.value;if(y(t),""===t){M(!1),E(!1);return}if(I)return;let n="/"===t||t.startsWith("/")&&!t.includes(" "),r="codex"===a&&("$"===t||t.startsWith("$")&&!t.includes(" "));n||r?E(!0):E(!1)},[I,a]),em=(0,o.useCallback)(e=>{let{keyCode:t}=e.nativeEvent;if(229!==t){if("Escape"===e.key&&T){e.preventDefault(),ec();return}if(P.current&&"Enter"===e.key){P.current=!1;return}if("Enter"===e.key&&!C&&(!T||I)){if(F)return;e.shiftKey||(e.preventDefault(),er())}}},[T,I,C,F,er,ec]);return(0,r.jsxs)("div",{ref:R,className:"space-y-2 relative","data-testid":"message-input-container",children:[(k||K)&&(0,r.jsx)("div",{className:"p-2 bg-danger-subtle border border-danger-border rounded text-sm text-danger-foreground",children:k||K}),O&&(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:O.file.name}),(0,r.jsx)("button",{type:"button",onClick:en,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:_,type:"file",accept:J,onChange:et,className:"hidden","data-testid":"image-file-input"}),(0,r.jsxs)("form",{onSubmit:es,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:()=>{I&&M(!1),E(!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:ee,disabled:U||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:U?(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)(q,{worktreeId:t,cliToolId:a||"claude",instanceId:s,disabled:!l})]}),!F&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:ee,disabled:U||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:U?(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:L,"data-testid":"message-input-textarea",value:v,onChange:eu,onKeyDown:em,onCompositionStart:el,onCompositionEnd:eo,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)(q,{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()||!!O)&&!j),disabled:!v.trim()&&!O||j,className:"flex-shrink-0 p-2 rounded-full transition-colors disabled:hover:bg-transparent ".concat((v.trim()||O)&&!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"})})})]})]}),(g||!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:g}),!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)(W.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)(W.u,{children:"⇧"}),(0,r.jsx)(W.u,{children:"↵"}),(0,r.jsx)("span",{children:b("composer.newlineHint")})]})]})]}),(0,r.jsx)($,{isOpen:T,groups:z,onSelect:ei,onClose:ec,isMobile:F,onFreeInput:ed})]})});var et=n(9900);function en(e,t,n,a){return(0,o.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,et.LK)}).catch(e=>{console.error("Failed to send special keys:",e)})},[e,t,n,a])}let ea=[{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"}],er=[{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 es(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s,showPagerKeys:l=!1}=e,i=(0,c.c)("worktree"),[d,u]=(0,o.useState)(null),m=en(t,n,a,s),h=(0,o.useCallback)(e=>{u(e[0]),setTimeout(()=>u(null),et.tX),m(e)},[m]),x=(0,o.useMemo)(()=>l?[...ea,...er]:ea,[l]),f=(0,o.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:f,role:"toolbar","aria-label":i("navigation.toolbarLabel"),children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground mx-2",children:i("navigation.caption")}),x.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?i(s):a,onClick:()=>h([t]),children:n},t)})]})}var el=n(36402),eo=n(17846),ei=n(69264),ec=n(27307),ed=n(11063),eu=n(60322),em=n(65229),eh=n(39867),ex=n(5917),ef=n(51963),eg=n(18514),ep=n(75426),eb=n(97624),ev=n(37354),ey=n(59854),ej=n(76246);let ew={highlightName:"terminal-search",currentHighlightName:"terminal-search-current",fallbackOverlayId:"terminal-search-fallback-overlay",fallbackOverlayBgColor:"rgba(255, 165, 0, 0.6)"},ek={highlightName:"history-search",currentHighlightName:"history-search-current",fallbackOverlayId:"history-search-fallback-overlay",fallbackOverlayBgColor:"rgba(59, 130, 246, 0.6)"};function eN(){return"undefined"!=typeof CSS&&null!==CSS&&"highlights"in CSS}function eC(e,t,n){let a=document.createRange(),r=!1;for(let{node:s,start:l,end:o}of e)if(!r&&t<o&&t>=l&&(a.setStart(s,t-l),r=!0),r&&n<=o)return a.setEnd(s,n-l),a;return r?a:null}function eS(e){var t;eN()&&(CSS.highlights.delete(e.highlightName),CSS.highlights.delete(e.currentHighlightName)),null==(t=document.getElementById(e.fallbackOverlayId))||t.remove()}function eT(e,t,n,a){if(0===t.length)return void eS(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?eC(r,s.start,s.end):null;if(eN()){let e=[];t.forEach((t,a)=>{if(a===n)return;let s=eC(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 eE(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ek;eS(e)}function eI(e){let[t,n]=(0,o.useState)(!1),[a,r]=(0,o.useState)(""),[s,l]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),m=(0,o.useRef)(null),h=(0,o.useRef)(null),x=(0,o.useCallback)(()=>{n(!0),setTimeout(()=>{var e;return null==(e=m.current)?void 0:e.focus()},50)},[]),f=(0,o.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),g=(0,o.useCallback)(()=>{n(!1),r(""),l(""),c([]),u(0),f()},[f]);(0,o.useEffect)(()=>{if(!a||a.length<2){l(""),f();return}return f(),h.current=setTimeout(()=>{l(a)},300),f},[a,f]),(0,o.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 p=(0,o.useCallback)(()=>{0!==i.length&&u(e=>(e+1)%i.length)},[i.length]),b=(0,o.useCallback)(()=>{0!==i.length&&u(e=>(e-1+i.length)%i.length)},[i.length]);return{searchOpen:t,searchQuery:a,searchMatches:i,searchCurrentIdx:d,searchInputRef:m,openSearch:x,closeSearch:g,nextMatch:p,prevMatch:b,setSearchQuery:r}}var eM=n(90487);n(1226);let eL=/^---\s*\nmarp:\s*true/;function eA(e){let{searchInputRef:t,searchQuery:n,searchMatches:a,searchCurrentIdx:s,onQueryChange:l,onPrev:o,onNext:i,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.shiftKey?o():i())},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: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.prevMatch"),children:"▲"}),(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.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)(em.A,{className:"w-4 h-4"})})]})}let eP="\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 eR(e){let{htmlContent:t,filePath:n}=e,[a,s]=(0,o.useState)("preview"),[l,i]=(0,o.useState)("safe"),d=(0,o.useRef)(new Set),u=(0,c.c)("worktree"),m=(0,el.SC)(),h=(0,o.useCallback)(async e=>{if("interactive"===e&&!d.current.has(n)){if(!await m({description:u("htmlPreview.interactiveModeConfirm")}))return;d.current.add(n)}i(e)},[n,m,u]),x=(0,o.useMemo)(()=>"interactive"!==l?t:t.includes("</body>")?t.replace("</body>","".concat(eP,"</body>")):t+eP,[t,l]);(0,o.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 f=(0,o.useMemo)(()=>{try{return eM.A.highlight(t,{language:"html",ignoreIllegals:!0}).value}catch(e){return eM.A.highlightAuto(t).value}},[t]),g=(0,o.useMemo)(()=>Array.from({length:t.split("\n").length},(e,t)=>t+1),[t]),p=(0,o.useMemo)(()=>f.split("\n"),[f]);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:g.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=p[n])?t:""}})})})]},e)})})}):(0,r.jsx)("iframe",{srcDoc:x,sandbox:ed.Ko[l],title:u("htmlPreview.title",{path:n}),className:"w-full h-full border-0 bg-white"},"".concat(n,"-").concat(l))})]})}let eD=(0,o.memo)(function(e){let{isOpen:t,onClose:n,worktreeId:a,filePath:s,onEditMarkdown:l}=e,[i,d]=(0,o.useState)(null),[u,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),[b,v]=(0,o.useState)(!1),[y,j]=(0,o.useState)(null),[w,k]=(0,o.useState)(0),[N,C]=(0,o.useState)(!1),S=(0,o.useRef)(null),T=(0,c.c)("worktree"),{searchOpen:E,searchQuery:I,searchMatches:M,searchCurrentIdx:L,searchInputRef:A,openSearch:P,closeSearch:R,nextMatch:D,prevMatch:F,setSearchQuery:O}=eI(null==i?void 0:i.content),_=(0,o.useMemo)(()=>!!((null==i?void 0:i.content)&&!i.isImage&&!i.isVideo&&!i.isPdf),[i]),B=(0,o.useCallback)(async()=>{if(_&&(null==i?void 0:i.content))try{await (0,eu.l)(i.content),p(!0),setTimeout(()=>p(!1),et.pX)}catch(e){}},[_,i]),W=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s),v(!0),setTimeout(()=>v(!1),et.pX)}catch(e){}},[s]),H=(0,o.useCallback)(()=>{C(e=>!e)},[]);(0,o.useEffect)(()=>{if(0===M.length||!S.current)return;let e=M[L],t=S.current.querySelector('[data-line="'.concat(e,'"]'));t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"})},[L,M]),(0,o.useEffect)(()=>{if(!N)return;let e=e=>{"Escape"===e.key&&C(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[N]),(0,o.useEffect)(()=>{if(!t||!s){d(null),f(null),p(!1),R();return}(async()=>{h(!0),f(null);try{let t=await fetch("/api/worktrees/".concat(a,"/files/").concat((0,ej.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)||T("fileViewer.loadError");throw Error(a)}let n=await t.json();d(n)}catch(e){f(e instanceof Error?e.message:T("fileViewer.loadError"))}finally{h(!1)}})()},[t,a,s]),(0,o.useEffect)(()=>{j(null),k(0),i&&"md"===i.extension&&eL.test(i.content)&&!(i.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:i.content})});if(e.ok){let t=await e.json();j(t.slides)}}catch(e){}})()},[i,a]);let V=!!(y&&y.length>0),U=(null==i?void 0:i.extension)==="md",K=(0,o.useCallback)(()=>{l&&s&&(n(),l(s))},[l,s,n]),$=(0,o.useMemo)(()=>{if(!i||i.isImage||i.isVideo||i.isHtml||i.isPdf||V&&y)return null;let e=Array.from({length:i.content.split("\n").length},(e,t)=>t+1);try{return{lineNumbers:e,highlightedHtml:eM.A.highlight(i.content,{language:i.extension,ignoreIllegals:!0}).value}}catch(t){return{lineNumbers:e,highlightedHtml:eM.A.highlightAuto(i.content).value}}},[i,V,y]),q=()=>{if(!i)return null;if(i.isImage)return(0,r.jsx)(eo.a,{src:i.content,alt:i.path,mimeType:i.mimeType});if(i.isVideo)return(0,r.jsx)(ei.u,{src:i.content,mimeType:i.mimeType});if(i.isPdf)return(0,r.jsx)("div",{className:"h-full min-h-[40vh]",children:(0,r.jsx)(ec.PdfPreview,{dataUri:i.content,filePath:s,variant:"download"})});if(i.isHtml)return(0,r.jsx)(eR,{htmlContent:i.content,filePath:s});if(V&&y)return(0,r.jsxs)("div",{className:"flex 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:()=>k(e=>Math.max(0,e-1)),disabled:0===w,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:T("actions.prev")}),(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[w+1," / ",y.length]}),(0,r.jsx)("button",{type:"button",onClick:()=>k(e=>Math.min(y.length-1,e+1)),disabled:w===y.length-1,className:"px-3 py-1 text-sm rounded-md bg-muted disabled:opacity-50 hover:bg-muted/80 transition-colors",children:T("actions.next")})]}),(0,r.jsx)("iframe",{srcDoc:y[w],sandbox:"",title:T("fileViewer.slideTitle",{name:s,number:w+1}),className:"w-full border-0",style:{height:N?"calc(100vh - 100px)":"50vh"}})]});if(!$)return null;let e=new Set(M),t=M.length>0?M[L]:-1,n=$.highlightedHtml.split("\n");return(0,r.jsx)("div",{ref:S,children:(0,r.jsx)("table",{className:"text-sm w-full border-collapse",children:(0,r.jsx)("tbody",{children:$.lineNumbers.map(a=>{var s;let l=a-1,o=a===t,i=e.has(a);return(0,r.jsxs)("tr",{"data-line":a,className:o?"bg-warning/30":i?"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(o||i?"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)})})})})},J="/api/worktrees/".concat(a,"/files/").concat((0,ej.o)(s),"?download=1"),Y=s?s.split("/").pop()||s:"",G=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return(0,r.jsxs)("a",{"data-testid":"download-file-button",href:J,download:Y,className:e,"aria-label":T("actions.downloadFile"),title:T("actions.download"),children:[(0,r.jsx)(eh.A,{className:"w-3.5 h-3.5"}),t&&(0,r.jsx)("span",{children:T("actions.download")})]})},X=()=>(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:W,className:"flex-shrink-0 p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.copyFilePath"),title:T("actions.copyPath"),children:b?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:[_&&(0,r.jsx)("button",{onClick:P,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.searchInFile"),title:T("actions.search"),children:(0,r.jsx)(z.A,{className:"w-3.5 h-3.5"})}),U&&l&&(0,r.jsx)("button",{onClick:K,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.editFile"),title:T("actions.edit"),children:(0,r.jsx)(eg.A,{className:"w-3.5 h-3.5"})}),_&&(0,r.jsx)("button",{"data-testid":"copy-content-button",onClick:B,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":T("actions.copyFileContent"),title:T("actions.copyContent"),children:g?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ep.A,{className:"w-3.5 h-3.5"})}),G("p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground"),(0,r.jsx)("button",{onClick:H,className:"p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground","aria-label":N?T("actions.exitFullscreen"):T("actions.fullscreen"),title:N?T("actions.exitFullscreen"):T("actions.fullscreen"),children:N?(0,r.jsx)(eb.A,{className:"w-3.5 h-3.5"}):(0,r.jsx)(ev.A,{className:"w-3.5 h-3.5"})})]})]});return N&&i&&!u&&!x?(0,r.jsxs)("div",{className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:ey.M.MAXIMIZED_EDITOR},children:[X(),E&&(0,r.jsx)(eA,{searchInputRef:A,searchQuery:I,searchMatches:M,searchCurrentIdx:L,onQueryChange:O,onPrev:F,onNext:D,onClose:R}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:q()})]}):(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:[u&&(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:T("fileViewer.loading")})]}),x&&(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:x})]}),(0,r.jsx)("div",{className:"mt-3",children:G("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)})]}),i&&!u&&!x&&(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:[X(),E&&(0,r.jsx)(eA,{searchInputRef:A,searchQuery:I,searchMatches:M,searchCurrentIdx:L,onQueryChange:O,onPrev:F,onNext:D,onClose:R})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0",children:q()})]})]})})});var eF=n(46892),ez=n(41898),eO=n(26232),e_=n(50857),eB=n(94442);function eW(e){let{worktreeId:t}=e,[n,a]=(0,o.useState)([]),[s,l]=(0,o.useState)(null),[i,d]=(0,o.useState)(null),[u,h]=(0,o.useState)(!0),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(""),[v,y]=(0,o.useState)(0),[j,w]=(0,o.useState)("all"),[k,N]=(0,o.useState)(!1),{toasts:C,showToast:S,removeToast:T}=(0,eB.dj)(),E=(0,c.c)("worktree");(0,o.useEffect)(()=>{(async()=>{try{h(!0),g(null);let e=await B.y.getLogs(t);a(e)}catch(e){g((0,B.hS)(e))}finally{h(!1)}})()},[t]);let I=(0,o.useMemo)(()=>"all"===j?n:n.filter(e=>e.toLowerCase().includes(j)),[n,j]),M=async e=>{try{h(!0),g(null);let n=await B.y.getLogFile(t,e);d(n.content),l(e),b(""),y(0)}catch(e){g((0,B.hS)(e))}finally{h(!1)}},L=(0,o.useCallback)(async()=>{if(s)try{N(!0);let e=await B.y.getLogFile(t,s,{sanitize:!0});await (0,eu.l)(e.content),S(E("logViewer.copied"),"success")}catch(e){S(E("logViewer.exportError",{error:(0,B.hS)(e)}),"error")}finally{N(!1)}},[t,s,S,E]),A=(0,o.useMemo)(()=>{let e;if(!p||!i)return[];let t=RegExp((0,x.Nt)(p),"gi"),n=[];for(;null!==(e=t.exec(i));)n.push({index:e.index,length:e[0].length});return n},[p,i]);(0,o.useEffect)(()=>{y(0)},[p]);let P=()=>{A.length>0&&y(e=>(e+1)%A.length)},R=()=>{A.length>0&&y(e=>(e-1+A.length)%A.length)},D=(0,o.useMemo)(()=>{if(!i||!p||0===A.length)return i;let e="",t=0;return A.forEach((n,a)=>{e+=(0,x.ZD)(i.substring(t,n.index));let r=i.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)(i.substring(t))},[i,p,A,v]);return(0,o.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:E("logViewer.title")}),(0,r.jsx)(m.Ex,{variant:"gray",children:I.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:E("logViewer.all",{count:n.length})}),(0,r.jsx)(m.$n,{variant:"claude"===j?"primary":"ghost",size:"sm",onClick:()=>w("claude"),children:E("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:E("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:E("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:E("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===I.length&&!f&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground text-center py-4",children:"all"===j?E("logViewer.empty"):E("logViewer.emptyFiltered",{tool:j})}),I.length>0&&(0,r.jsx)("div",{className:"space-y-2",children:I.map(e=>(0,r.jsx)("button",{onClick:()=>M(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:L,disabled:!s||k,title:E("logViewer.copyTitle"),children:k?E("logViewer.exporting"):E("logViewer.export")}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:()=>{l(null),d(null),b(""),y(0)},children:E("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:p,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?R():P())},placeholder:E("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:R,disabled:0===A.length,title:E("logViewer.prevMatch"),children:"↑"}),(0,r.jsx)(m.$n,{variant:"ghost",size:"sm",onClick:P,disabled:0===A.length,title:E("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&&i&&(0,r.jsx)("div",{className:"bg-[#111827] text-[#f3f4f6] rounded p-4 overflow-x-auto max-h-[500px] scrollbar-thin",children:p&&A.length>0?(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:D||""}}):(0,r.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap",children:i})}),!u&&p&&0===A.length&&i&&(0,r.jsx)("div",{className:"text-center py-4 text-sm text-muted-foreground",children:E("logViewer.noMatches",{query:p})})]})]}),(0,r.jsx)(eB.N9,{toasts:C,onClose:T})]})}function eH(){let[e,t]=(0,o.useState)(null),[n,a]=(0,o.useState)(!0),[r,s]=(0,o.useState)(null);return(0,o.useEffect)(()=>{let e=!1;return async function(){try{a(!0),s(null);let n=await B.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 eV=n(31166);let eU="commandmate update";function eK(e){let{hasUpdate:t,latestVersion:n,releaseUrl:a,updateCommand:s,installType:l}=e,i=(0,c.c)("worktree"),[d,m]=(0,o.useState)("idle"),[h,x]=(0,o.useState)(null),[f,g]=(0,o.useState)(null),p=(0,o.useRef)(!1),b="global"===l,v=(0,o.useCallback)(async()=>{m("starting");try{let e=await B.GQ.startUpdate();x(e.logPath),m(e.willRestart?"updating":"no-restart")}catch(e){e instanceof B.hD&&400===e.status?g(i("update.errorNotGlobal")):e instanceof B.hD&&409===e.status?g(i("update.errorInProgress")):g(i("update.errorGeneric")),m("error")}},[i]);return((0,o.useEffect)(()=>{if("updating"!==d)return;let e=!1,t=Date.now();p.current=!1;let n=setInterval(async()=>{if(e)return;if(Date.now()-t>3e5)return void m("timeout");let n=await B.GQ.ping();if(!e){if(!n){p.current=!0;return}p.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":i("update.available"),"data-testid":"update-notification-banner",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-accent-800 mb-1",children:i("update.available")}),n&&(0,r.jsx)("p",{className:"text-sm text-accent-700 mb-2",children:i("update.latestVersion",{version:n})}),b&&"idle"===d&&(0,r.jsx)(eV.$,{variant:"primary",size:"sm",className:"mb-2",onClick:()=>m("confirming"),"data-testid":"update-now-button",children:i("update.updateNow")}),("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?i("update.starting"):i("update.updating")]}),"updating"===d&&(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:i("update.noRestartTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:i("update.timeoutTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:i("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:eU})]}),"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:i("update.errorTitle")}),(0,r.jsx)("p",{className:"text-xs text-accent-600 mt-1",children:f}),(0,r.jsx)("code",{className:"block bg-accent-100 rounded px-2 py-1 mt-1 text-xs text-accent-900 font-mono",children:eU})]}),h&&("no-restart"===d||"timeout"===d)&&(0,r.jsx)("p",{className:"text-xs text-accent-500 mb-2","data-testid":"update-log-hint",children:i("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:i("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:[i("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:i("update.dataPreserved")}),(0,r.jsx)(el.TM,{isOpen:"confirming"===d,title:i("update.confirmTitle"),description:i("update.confirmDescription",{version:null!=n?n:""}),confirmLabel:i("update.confirmButton"),onConfirm:v,onCancel:()=>m("idle")})]}):null}function e$(e){let{version:t,className:n}=e,a=(0,c.c)("worktree"),{data:s,loading:l}=eH(),i=(0,o.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:"..."}),i&&(0,r.jsx)(eK,{...i})]})}let eq="https://github.com/Kewton/CommandMate",eJ="".concat(eq,"/issues"),eY="".concat(eq,"/issues/new"),eG="".concat(eY,"?template=bug_report.md"),eX="".concat(eY,"?template=feature_request.md"),eQ="".concat(eY,"?template=question.md");function eZ(e){let{className:t}=e,n=(0,c.c)("worktree"),a=[{href:eG,label:n("feedback.bugReport")},{href:eX,label:n("feedback.featureRequest")},{href:eQ,label:n("feedback.question")},{href:eJ,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 e0=n(94465),e1=n(55142),e2=n(54014),e4=n(24033);let e5="application/x-commandmate-agent-instance",e3=(0,o.memo)(function(e){let{splitIndex:t,cliToolId:n,instanceId:a,instance:s,availableInstances:l,onInstanceChange:i,status:d="idle",onFocus:u,attaching:m=!1,headerExtras:x,terminal:f,footer:g,style:p,onDropInstance:b,draggedInstanceId:v}=e,y=(0,c.c)("worktree"),[j,w]=(0,o.useState)(null),k=null!=b,N=(0,o.useCallback)(()=>null==v||l.some(e=>e.id===v)?"allowed":"forbidden",[v,l]),C=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault();let t=N();e.dataTransfer.dropEffect="forbidden"===t?"none":"move",w(e=>e===t?e:t)},[k,N]),S=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault();let t=N();w(e=>e===t?e:t)},[k,N]),T=(0,o.useCallback)(()=>{k&&w(null)},[k]),E=(0,o.useCallback)(e=>{if(!k)return;e.preventDefault(),w(null);let t=e.dataTransfer.getData(e5);t&&(null==b||b(t))},[k,b]),I=(0,o.useCallback)(()=>{window.dispatchEvent(new CustomEvent("terminal-search-open"))},[]),M=(0,o.useCallback)(()=>{u()},[u]),L="Terminal split ".concat(t+1),A=(0,e2.sw)(null!=s?s:{cliTool:n}),P=y("terminal.selectInstance",{split:L});return(0,r.jsxs)("div",{role:"region","aria-label":L,"data-testid":"terminal-split-pane-".concat(t),"data-split-index":t,style:p,className:"flex flex-col min-w-0 h-full rounded-lg overflow-hidden border border-border bg-surface".concat(null===j?" focus-within:ring-1 focus-within:ring-accent-500/30":"").concat("allowed"===j?" ring-2 ring-accent-400":"forbidden"===j?" ring-2 ring-red-300 cursor-not-allowed":""),onFocusCapture:M,onMouseDown:u,onDragOver:C,onDragEnter:S,onDragLeave:T,onDrop:E,children:[(0,r.jsxs)("div",{className:"px-2 py-1 flex items-center gap-2 bg-surface-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)(eO.rI,{children:[(0,r.jsxs)(eO.ty,{"data-testid":"cli-selector-".concat(t),"aria-label":P,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:d,size:"sm","aria-hidden":!0,"data-testid":"split-status-indicator-".concat(t)}),(0,r.jsx)("span",{className:"truncate",children:A}),(0,r.jsx)(e4.A,{size:14,"aria-hidden":"true",className:"flex-shrink-0 opacity-70"})]}),(0,r.jsx)(eO.SQ,{align:"start",className:"min-w-[10rem]",children:(0,r.jsx)(eO.Hr,{value:a,onValueChange:i,children:l.map(e=>(0,r.jsx)(eO.Ht,{value:e.id,children:(0,e2.sw)(e)},e.id))})})]}),x,(0,r.jsx)("button",{type:"button",onClick:I,"aria-label":"Search terminal output for ".concat(L),"data-testid":"terminal-search-button-".concat(t),className:"ml-auto 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"})})})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[m?(0,r.jsxs)("div",{"data-testid":"terminal-attach-skeleton-".concat(t),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 ",A," session..."]}):null,f]}),(0,r.jsx)("div",{className:"flex-shrink-0 border-t border-border p-2 bg-surface-2",children:g})]})});var e6=n(34681),e8=n(20562),e9=n(8803),e7=n(46980),te=n.n(e7),tt=n(62459);let tn=new(n.n(tt)())({fg:"#d1d5db",bg:"#1f2937",newline:!0,escapeXML:!0});function ta(e){let t=e.replace(/\0/g,"");t.length>1048576&&(t=t.slice(0,1048576));let n=tn.toHtml(t);return te().sanitize(n,{ALLOWED_TAGS:["span","br"],ALLOWED_ATTR:["style"],ALLOW_DATA_ATTR:!1})}let tr=/\x1b(?:\[[0-9;?]*)?$/,ts=/\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07]*\x07|\[[0-9;]*m/g;function tl(e){return""===e.replace(ts,"").trim()}function to(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:c,isAtMaxMatches:d=!1}=e,u=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=u.current)||e.focus()},[]);let m=(0,o.useCallback)(e=>{"Escape"===e.key&&c()},[c]),h=(0,o.useCallback)(e=>{n(e.target.value)},[n]),x=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:x}),(0,r.jsx)("button",{onClick:i,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:"✕"})]})}function ti(){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 tc=(0,o.memo)(function(e){let{output:t,isActive:n,attaching:a=!1,isThinking:s=!1,autoScroll:l=!0,onScrollChange:i,disableAutoFollow:c=!1,compactTuiLayoutPadding:d=!1,className:u=""}=e,{scrollRef:m,autoScroll:h,handleScroll:x,scrollToBottom:f,scrollToTop:g}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{initialAutoScroll:t=!0,onAutoScrollChange:n}=e,a=(0,o.useRef)(null),[r,s]=(0,o.useState)(t),l=(0,o.useRef)(!1),i=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]);let c=(0,o.useCallback)(e=>{s(e),null==n||n(e)},[n]),d=(0,o.useCallback)(()=>{let e=a.current;if(!e)return!0;let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;return n-r-t<=50},[]),u=(0,o.useCallback)(()=>{if(l.current)return;let e=d();e&&!r?c(!0):!e&&r&&c(!1)},[r,d,c]),m=(0,o.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),r||c(!0),i.current=setTimeout(()=>{l.current=!1,i.current=null},500))},[r,c]),h=(0,o.useCallback)(()=>{let e=a.current;e&&(l.current=!0,e.scrollTo({top:0,behavior:"smooth"}),r&&c(!1),i.current=setTimeout(()=>{l.current=!1,i.current=null},500))},[r,c]);return{scrollRef:a,autoScroll:r,setAutoScroll:c,scrollToBottom:m,scrollToTop:h,handleScroll:u}}({initialAutoScroll:l,onAutoScrollChange:i}),p=null!=t?t:"",b=(0,o.useMemo)(()=>d?function(e){if(""===e)return"";let t=e.split("\n"),n=[],a=!1,r=0;for(;r<t.length;){if(!tl(t[r])){n.push(t[r]),a=!0,r++;continue}let e=r;for(;e<t.length&&tl(t[e]);)e++;let s=e-r,l=!a,o=e>=t.length;if(!l&&!o)if(s<=2)for(let a=r;a<e;a++)n.push(t[a]);else n.push(function(e){let t=e.match(ts);return t?t.join(""):""}(t.slice(r,e).join("")));r=e}return n.join("\n")}(p):p,[d,p]),{isOpen:v,query:y,matchCount:j,currentIndex:w,isAtMaxMatches:k,openSearch:N,closeSearch:C,setQuery:S,nextMatch:T,prevMatch:E}=function(e){let{output:t,containerRef:n}=e,[a,r]=(0,o.useState)(!1),[s,l]=(0,o.useState)(""),[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(0),[m,h]=(0,o.useState)(!1),x=(0,o.useRef)(null),f=(0,o.useRef)(""),g=i.length,p=(0,o.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 o=s.length>=500&&-1!==a.indexOf(r,l);return{positions:s,capped:o}},[n]),b=(0,o.useCallback)(e=>{let{positions:t,capped:a}=p(e);if(c(t),u(0),h(a),n.current)if(t.length>0){var r;r=n.current,eT(r,t,0,ew)}else eS(ew)},[p,n]),v=(0,o.useCallback)(e=>{l(e),x.current&&clearTimeout(x.current),f.current=e,x.current=setTimeout(()=>{b(e)},300)},[b]),y=(0,o.useCallback)(()=>{r(!0)},[]),j=(0,o.useCallback)(()=>{r(!1),l(""),f.current="",c([]),u(0),h(!1),x.current&&clearTimeout(x.current),eS(ew)},[]),w=(0,o.useCallback)(()=>{0!==g&&u(e=>{let t=(e+1)%g;return n.current&&i.length>0&&eT(n.current,i,t,ew),t})},[g,i,n]),k=(0,o.useCallback)(()=>{0!==g&&u(e=>{let t=(e-1+g)%g;return n.current&&i.length>0&&eT(n.current,i,t,ew),t})},[g,i,n]);return(0,o.useEffect)(()=>{f.current.length<2||b(f.current)},[t,b]),(0,o.useEffect)(()=>()=>{x.current&&clearTimeout(x.current),eS(ew)},[]),{isOpen:a,query:s,matchCount:g,currentIndex:d,isAtMaxMatches:m,openSearch:y,closeSearch:j,setQuery:v,nextMatch:w,prevMatch:k}}({output:b,containerRef:m}),I=(0,o.useCallback)(e=>{(e.ctrlKey||e.metaKey)&&"f"===e.key&&(e.preventDefault(),N())},[N]);(0,o.useEffect)(()=>{let e=()=>N();return window.addEventListener("terminal-search-open",e),()=>window.removeEventListener("terminal-search-open",e)},[N]);let[M,L]=(0,o.useState)(()=>b?[{key:0,html:ta(b)}]:[]),A=(0,o.useRef)(b),P=(0,o.useRef)(0);(0,o.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(tr),a=n?e.length-n[0].length:e.length;return{mode:"append",text:t,appended:t.slice(a),retainedLength:a}}(A.current,b);if(A.current=b,"noop"!==e.mode){if("append"===e.mode)return void L(t=>(P.current+=1,t.length>=400)?[{key:P.current,html:ta(b)}]:[...t,{key:P.current,html:ta(e.appended)}]);P.current+=1,L(b?[{key:P.current,html:ta(b)}]:[])}},[b]);let[R,D]=(0,o.useState)(!1);(0,o.useEffect)(()=>{a?D(!1):n&&D(!0)},[a,n]);let F=!t,z=F&&a,O=F&&!a&&!n&&R,_=(0,o.useRef)(!1);(0,o.useEffect)(()=>{c&&(_.current=!0)},[c]),(0,o.useEffect)(()=>{if(m.current){if(_.current&&c&&b){m.current.scrollTo({top:0,behavior:"instant"}),_.current=!1;return}!c&&h&&m.current.scrollTo({top:m.current.scrollHeight,behavior:"instant"})}},[M,b,h,c,m]);let B=(0,o.useMemo)(()=>["terminal","font-mono","text-sm","p-4","rounded-lg","overflow-y-auto","overflow-x-hidden","bg-gray-900","text-gray-300","border","border-gray-700","h-full",n?"active":"",u].filter(Boolean).join(" "),[n,u]),[W,H]=(0,o.useState)(!1),V=(0,o.useRef)(null),U=(0,o.useCallback)(()=>{H(!0),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>H(!1),1500)},[]);(0,o.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let K=(0,o.useCallback)(()=>{x(),U()},[x,U]),$=["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",W?"opacity-100":"opacity-60"].join(" ");return(0,r.jsxs)("div",{className:"relative h-full flex flex-col",children:[v&&(0,r.jsx)("div",{className:"absolute top-2 right-2 z-10",children:(0,r.jsx)(to,{query:y,onQueryChange:S,matchCount:j,currentIndex:w,onNext:T,onPrev:E,onClose:C,isAtMaxMatches:k})}),(0,r.jsxs)("div",{ref:m,role:"log","aria-live":"polite","aria-label":"Terminal output",className:B,onScroll:K,onKeyDown:I,tabIndex:0,children:[(0,r.jsx)("div",{className:"whitespace-pre-wrap break-words",children:M.map(e=>(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:e.html}},e.key))}),z&&(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:"読込中..."}),O&&(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)(ti,{})]}),h?(0,r.jsx)("button",{type:"button",onClick:g,className:$,"aria-label":"Scroll to top",children:(0,r.jsx)(e8.A,{size:16,"aria-hidden":"true"})}):(0,r.jsx)("button",{type:"button",onClick:f,className:$,"aria-label":"Scroll to bottom",children:(0,r.jsx)(e9.A,{size:16,"aria-hidden":"true"})})]})});var td=n(9109);function tu(e){let{worktreeId:t,cliToolId:n,instanceId:a,enabled:r=!0}=e,s=null!=a?a:n,[l,i]=(0,o.useState)(()=>({output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,attaching:!0,autoScroll:!0})),[c,d]=(0,o.useState)(()=>({visible:!1,data:null,messageId:null,answering:!1})),u=(0,o.useRef)(0),m=(0,o.useRef)(n);m.current=n;let h=(0,o.useRef)(s);h.current=s;let x=(0,o.useRef)(c.visible);x.current=c.visible;let{connected:f,subscribe:g,unsubscribe:p,addListener:b}=(0,td.xM)(),v=(0,o.useRef)(0),y=(0,o.useRef)(0),j=(0,o.useRef)(null),w=(0,o.useRef)(null),[k,N]=(0,o.useState)(!1),C=(0,o.useCallback)(()=>{N(!0),null!==w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{w.current=null,N(!1)},5e3)},[]),S=(0,o.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?(y.current+=1,null!=j.current||(j.current=Date.now())):(y.current=0,j.current=null);let r=y.current>=2&&null!==j.current&&Date.now()-j.current>=500;i(t=>{var n,s,l,o,i;let c=!1===e.isRunning,d=!!a||!!e.isRunning||c;return{...t,output:d?a:t.output,realtimeSnippet:null!=(n=e.realtimeSnippet)?n:"",isRunning:null!=(s=e.isRunning)&&s,isThinking:null!=(l=e.thinking)&&l,isSelectionListActive:null!=(o=e.isSelectionListActive)&&o,isPagerActive:null!=(i=e.isPagerActive)&&i,isUnclassifiedActive:r,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&&x.current&&d({visible:!1,data:null,messageId:null,answering:!1})},[]),T=(0,o.useCallback)(async()=>{let e=++u.current;try{let a=await fetch("/api/worktrees/".concat(t,"/current-output?cliTool=").concat(n,"&instance=").concat(encodeURIComponent(s)));if(!a.ok)return;let r=await a.json();if(u.current!==e||m.current!==n||h.current!==s||r.cliToolId&&r.cliToolId!==n)return;S(r)}catch(t){if(u.current!==e||m.current!==n||h.current!==s)return;console.error("[useTerminalPanePolling] fetch error:",t)}},[t,n,s,S]),E="".concat(t,"::").concat(n,"::").concat(s),I=(0,o.useRef)(E);(0,o.useEffect)(()=>{I.current!==E&&(I.current=E,u.current+=1,v.current=0,y.current=0,j.current=null,N(!1),null!==w.current&&(clearTimeout(w.current),w.current=null),i(e=>({...e,output:"",realtimeSnippet:"",isRunning:!1,isThinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,attaching:!0})),d({visible:!1,data:null,messageId:null,answering:!1}))},[E]),(0,o.useEffect)(()=>{if(r)return g(t),()=>p(t)},[r,t,g,p]),(0,o.useEffect)(()=>{v.current=0,N(!1),null!==w.current&&(clearTimeout(w.current),w.current=null)},[f]),(0,o.useEffect)(()=>()=>{null!==w.current&&clearTimeout(w.current)},[]),(0,o.useEffect)(()=>{if(r)return b(e=>{var n;if("terminal_snapshot"!==e.type||e.worktreeId!==t||e.cliToolId!==m.current||e.instanceId!==h.current||e.version<=v.current)return;v.current=e.version,C();let a=e.output.split("\n").slice(-100).join("\n");S({fullOutput:e.output,realtimeSnippet:a,isRunning:e.isRunning,thinking:e.thinking,isSelectionListActive:e.isSelectionListActive,isPagerActive:e.isPagerActive,isUnclassifiedActive:e.isUnclassifiedActive,isPromptWaiting:e.isPromptWaiting,promptData:null!=(n=e.promptData)?n:null})})},[r,t,b,S,C]),(0,o.useEffect)(()=>{if(r)return b(e=>{if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===h.current)&&(null==e.cliTool||e.cliTool===m.current)&&(v.current=0,S({fullOutput:"",realtimeSnippet:"",isRunning:!1,thinking:!1,isSelectionListActive:!1,isPagerActive:!1,isUnclassifiedActive:!1,isPromptWaiting:!1,promptData:null}))})},[r,t,b,S]),(0,o.useEffect)(()=>{if(!r)return;let e=!1,t=c.visible||l.isSelectionListActive||l.isPagerActive||l.isUnclassifiedActive,n=setInterval(()=>{"hidden"!==document.visibilityState&&T()},f&&k&&!t?15e3:l.isRunning||t?2e3:5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&T();let a=()=>{"visible"!==document.visibilityState||e||T()};return document.addEventListener("visibilitychange",a),()=>{e=!0,null!==n&&(clearInterval(n),n=null),document.removeEventListener("visibilitychange",a)}},[r,f,k,l.isRunning,l.isSelectionListActive,l.isPagerActive,l.isUnclassifiedActive,c.visible,T]);let M=(0,o.useCallback)(e=>{i(t=>t.autoScroll===e?t:{...t,autoScroll:e})},[]),L=(0,o.useCallback)(e=>{d(t=>({...t,answering:e}))},[]);return{terminal:l,prompt:c,setAutoScroll:M,setPromptAnswering:L,clearPrompt:(0,o.useCallback)(()=>{d({visible:!1,data:null,messageId:null,answering:!1})},[]),refresh:(0,o.useCallback)(()=>T(),[T])}}var tm=n(96195),th=n(12181),tx=n(20508),tf=n(27937);function tg(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)}var tp=n(35299),tb=n(6132),tv=n(48314),ty=n(54916),tj=n(36809),tw=n(55041),tk=n(8574);let tN={en:tk.c,ja:tw.ja};function tC(e){var t;return null!=(t=tN[e])?t:tk.c}var tS=n(83012);let tT=/(\/[^\s\n<>"']+\.[a-zA-Z0-9]+)/g;function tE(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 tI=(0,o.memo)(function(e){let{content:t,onFilePathClick:n}=e,a=(0,c.c)("worktree"),s=(0,o.useMemo)(()=>(function(e){let t=e.match(tT);if(!t||0===t.length)return[{type:"text",content:e}];let n=[],a=0;return t.forEach(t=>{let r=e.indexOf(t,a);r>a&&n.push({type:"text",content:e.slice(a,r)}),n.push({type:"path",content:t}),a=r+t.length}),a<e.length&&n.push({type:"text",content:e.slice(a)}),n})(t),[t]),l=(0,o.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))})});function tM(){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 tL=(0,o.memo)(function(e){let{message:t,onFilePathClick:n,onCopy:a,onInsertToMessage:s,onRetryPending:l,onDiscardPending:o}=e,i=(0,tj.Ym)(),d=(0,c.c)("worktree"),u=(0,c.c)("common"),m=tC(i),h=(0,tS.bg)(t.timestamp,m),x=t.optimisticState,f=["group relative border-l-2 p-3 transition-opacity","error"===x?"border-danger-border bg-danger-subtle":"border-accent-500 bg-accent-500/10","sending"===x?"opacity-70":""].filter(Boolean).join(" ");return(0,r.jsxs)("div",{className:f,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"===x&&(0,r.jsxs)("span",{"data-testid":"optimistic-sending",className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,r.jsx)(tp.A,{size:12,className:"animate-spin","aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.sending")})]}),"error"===x&&(0,r.jsxs)("span",{"data-testid":"optimistic-error",className:"flex items-center gap-1 text-xs text-danger-foreground",children:[(0,r.jsx)(tb.A,{size:12,"aria-hidden":"true"}),(0,r.jsx)("span",{children:d("conversation.failedToSend")})]}),"error"===x?(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)(tv.A,{size:12,"aria-hidden":"true"}),u("retry")]}),o&&(0,r.jsxs)("button",{type:"button","data-testid":"pending-discard",onClick:()=>o(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)(em.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)(ty.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)(ep.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)(tI,{content:t.content,onFilePathClick:n})})]})}),tA=(0,o.memo)(function(e){let{message:t,index:n,total:a,isExpanded:s,onFilePathClick:l,onCopy:i,hasLongContent:d=!1,onToggleExpand:u}=e,m=(0,tj.Ym)(),h=(0,c.c)("worktree"),x=tC(m),f=(0,tS.bg)(t.timestamp,x),{text:g,isTruncated:p}=(0,o.useMemo)(()=>tE(t.content),[t.content]),b=s||!p?t.content:g;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:f}),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)(e4.A,{size:12,className:"transition-transform ".concat(s?"rotate-180":""),"aria-hidden":"true"}),h(s?"conversation.collapse":"conversation.expand")]}),i&&(0,r.jsx)("button",{type:"button","data-testid":"copy-assistant-message",onClick:()=>i(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)(ep.A,{size:14,"aria-hidden":"true"})})]})]}),(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)(tI,{content:b,onFilePathClick:l}),!s&&p&&(0,r.jsx)("span",{className:"text-muted-foreground",children:"..."})]})]})}),tP=(0,o.memo)(function(e){let{messages:t,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l=!1,onToggleExpand:i}=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)(o.Fragment,{children:[c>0&&(0,r.jsx)("div",{"data-testid":"assistant-message-divider",className:"border-t border-dashed border-border"}),(0,r.jsx)(tA,{message:e,index:c,total:t.length,isExpanded:n,onFilePathClick:a,onCopy:s,hasLongContent:l,onToggleExpand:i})]},e.id))})});function tR(){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 tD=(0,o.memo)(function(e){var t;let{pair:n,onFilePathClick:a,isExpanded:s=!1,onToggleExpand:l,onCopy:i,onInsertToMessage:d,showAssistant:u=!0,onRetryPending:m,onDiscardPending:h}=e,x=(0,c.c)("worktree"),f=(null==(t=n.userMessage)?void 0:t.optimisticState)!==void 0,g=(0,o.useMemo)(()=>n.assistantMessages.some(e=>{let{isTruncated:t}=tE(e.content);return t}),[n.assistantMessages]),p=(0,o.useCallback)(()=>{l&&l()},[l]),b=(0,o.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?x("conversation.conversationLabel",{preview:"".concat(n.userMessage.content.substring(0,50)).concat(n.userMessage.content.length>50?"...":"")}):x("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)(tR,{}),n.userMessage&&(0,r.jsx)(tL,{message:n.userMessage,onFilePathClick:a,onCopy:i,onInsertToMessage:d,onRetryPending:m,onDiscardPending:h}),"pending"!==n.status||f?u&&n.assistantMessages.length>0?(0,r.jsx)(tP,{messages:n.assistantMessages,isExpanded:s,onFilePathClick:a,onCopy:i,hasLongContent:g,onToggleExpand:p}):null:(0,r.jsx)("div",{className:"bg-muted/40 border-l-2 border-border p-3 border-t border-border",children:(0,r.jsx)(tM,{})})]})});function tF(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:d,isAtMaxMatches:u,onCompositionStart:m,onCompositionEnd:h}=e,x=(0,o.useRef)(null),f=(0,c.c)("worktree");(0,o.useEffect)(()=>{var e;null==(e=x.current)||e.focus()},[]);let g=(0,o.useCallback)(e=>{"Escape"===e.key&&d()},[d]),p=(0,o.useCallback)(e=>{n(e.target.value)},[n]),b=0===a?"0/0":u?f("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":f("history.search.regionLabel"),children:[(0,r.jsx)("input",{ref:x,type:"text",value:t,onChange:p,onKeyDown:g,onCompositionStart:m,onCompositionEnd:h,placeholder:f("history.search.placeholder"),className:"bg-transparent text-foreground text-sm outline-none w-32 sm:w-40 placeholder-muted-foreground","aria-label":f("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:i,disabled:0===a,"aria-label":f("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":f("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":f("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 tz="commandmate.worktree.historyVisible",tO="commandmate.worktree.historyWidth";function t_(e){return Number.isFinite(e)?Math.min(60,Math.max(10,e)):40}let tB="commandmate:historyPaneStateChange";function tW(e){try{window.dispatchEvent(new CustomEvent(tB,{detail:e}))}catch(e){}}function tH(){let[e,t]=(0,o.useState)(!0),[n,a]=(0,o.useState)(40),r=(0,o.useRef)(e);r.current=e;let s=(0,o.useRef)(n);return s.current=n,(0,o.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(tz);if("true"===e)return!0;if("false"===e)return!1}catch(e){}return!0}(),n=function(){try{let e=window.localStorage.getItem(tO);if(null===e)return 40;let t=Number(e);if(Number.isFinite(t))return t_(t)}catch(e){}return 40}();t(e),a(n)},[]),(0,o.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(tB,e),()=>window.removeEventListener(tB,e)},[]),{visible:e,width:n,toggle:(0,o.useCallback)(()=>{let e=!r.current;t(e);try{window.localStorage.setItem(tz,String(e))}catch(e){}tW({visible:e,width:s.current})},[]),setWidth:(0,o.useCallback)(e=>{let t=t_(e);a(t);try{window.localStorage.setItem(tO,String(t))}catch(e){}tW({visible:r.current,width:t})},[])}}var tV=n(72115);let tU="worktree-history-pane",tK=(0,o.memo)(function(e){let{onToggle:t}=e,n=(0,c.c)("worktree");return(0,r.jsx)("div",{"data-testid":"terminal-container-expand-bar",style:{width:"".concat(36,"px")},className:"flex-shrink-0 flex items-start justify-center bg-gray-100 dark:bg-gray-800 border-r border-gray-200 dark:border-gray-700",children:(0,r.jsxs)("button",{type:"button","data-testid":"history-pane-expand","aria-label":n("terminal.showHistory"),title:n("terminal.showHistory"),"aria-expanded":"false","aria-controls":tU,onClick:t,className:"flex flex-col items-center gap-2 w-full pt-2 text-gray-500 dark:text-gray-400 hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",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"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:n("terminal.historyLabel")})]})})}),t$=(0,o.memo)(function(e){let{history:t,terminal:n}=e,{visible:a,width:s,toggle:l,setWidth:i}=tH(),c=(0,o.useRef)(null),d=(0,o.useCallback)(e=>{let t=c.current;if(!t)return;let n=t.offsetWidth;0!==n&&i(s+e/n*100)},[s,i]);return(0,r.jsxs)("div",{ref:c,className:"flex h-full min-h-0 w-full",children:[null!=t&&(a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:tU,"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)(S,{componentName:"HistoryPane",children:t})}),(0,r.jsx)(tV.f,{onResize:d,orientation:"horizontal",ariaValueNow:s})]}):(0,r.jsx)(tK,{onToggle:l})),(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)(S,{componentName:"TerminalAndFilePanel",children:n})})]})}),tq=[50,100,150,200,250,500,1e3],tJ="commandmate:historyDisplayLimit";function tY(e){return tq.includes(e)}let tG="commandmate:historyUserOnly";function tX(e){return"split-history-slot-".concat(e)}function tQ(){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 tZ(){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 t0=["h-full","flex","flex-col","overflow-hidden","bg-surface-2","rounded-lg","border","border-border"],t1=(0,o.memo)(function(e){let{messages:t,worktreeId:n,onFilePathClick:a,isLoading:s=!1,className:l="",showToast:i,onInsertToMessage:d,onRetryPending:u,onDiscardPending:h,showArchived:x=!1,onShowArchivedChange:f,historyDisplayLimit:g,onHistoryDisplayLimitChange:p,historyUserOnly:b=!1,onHistoryUserOnlyChange:v,onCollapse:y,splitIndex:j,cliToolId:w}=e,k=(0,c.c)("worktree"),N=(0,o.useRef)(null),C=(0,o.useMemo)(()=>void 0===j?ek:{highlightName:"history-search-".concat(j),currentHighlightName:"history-search-current-".concat(j),fallbackOverlayId:"history-search-fallback-overlay-".concat(j),fallbackOverlayBgColor:ek.fallbackOverlayBgColor},[j]),S=void 0===j?"history-pane-collapse-button":"history-pane-collapse-button-".concat(j),T=void 0===j?tU:tX(j),E=(0,o.useRef)(!0),I=(0,o.useRef)(-1),M=(0,o.useRef)(null),{pairs:L,isExpanded:A,toggleExpand:P}=function(e){let t=(0,o.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,o.useState)(new Set),r=(0,o.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,o.useCallback)(e=>n.has(e),[n]),l=(0,o.useCallback)(()=>{a(new Set(t.map(e=>e.id)))},[t]);return{pairs:t,expandedPairs:n,toggleExpand:r,isExpanded:s,expandAll:l,collapseAll:(0,o.useCallback)(()=>{a(new Set)},[])}}(t),{isOpen:R,query:D,matchCount:F,currentIndex:O,isAtMaxMatches:_,matchPositions:B,currentMatch:W,openSearch:H,closeSearch:V,setQuery:U,onCompositionStart:K,onCompositionEnd:$,nextMatch:q,prevMatch:J}=function(e){let{messages:t}=e,[n,a]=(0,o.useState)(!1),[r,s]=(0,o.useState)(""),[l,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(0),[u,m]=(0,o.useState)(!1),h=(0,o.useRef)(null),x=(0,o.useRef)(""),f=(0,o.useRef)(!1),g=(0,o.useRef)(tg(t)),p=(0,o.useRef)(t);p.current=t;let b=l.reduce((e,t)=>e+t.ranges.length,0),v=(0,o.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,o.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),j=(0,o.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 o=t.content;if(!o)continue;let i=o.toLowerCase(),c=[],d=0;for(;;){let r=i.indexOf(n,d);if(-1===r)break;if(c.push({start:r,end:r+a}),d=r+1,(s+=1)>=500){if(-1!==i.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}}(p.current,e);i(t),d(0),m(n)},[]),w=(0,o.useCallback)(e=>{y(),x.current=e,f.current||(h.current=setTimeout(()=>{j(e)},300))},[y,j]),k=(0,o.useCallback)(e=>{s(e),w(e)},[w]),N=(0,o.useCallback)(()=>{a(!0)},[]),C=(0,o.useCallback)(()=>{a(!1),s(""),x.current="",i([]),d(0),m(!1),y()},[y]),S=(0,o.useCallback)(()=>{d(e=>0===b?0:(e+1)%b)},[b]),T=(0,o.useCallback)(()=>{d(e=>0===b?0:(e-1+b)%b)},[b]),E=(0,o.useCallback)(()=>{f.current=!0,y()},[y]),I=(0,o.useCallback)(()=>{f.current=!1;let e=x.current;e.length>=2&&(y(),h.current=setTimeout(()=>{j(e)},300))},[y,j]);return(0,o.useEffect)(()=>{let e=tg(t);if(e===g.current)return;g.current=e;let n=x.current;n.length>=2&&j(n)},[t,j]),(0,o.useEffect)(()=>()=>{y(),x.current=""},[y]),{isOpen:n,query:r,matchCount:b,currentIndex:c,isAtMaxMatches:u,matchPositions:l,currentMatch:v,openSearch:N,closeSearch:C,setQuery:k,onCompositionStart:E,onCompositionEnd:I,nextMatch:S,prevMatch:T}}({messages:(0,o.useMemo)(()=>t.filter(e=>!e.archived&&"string"==typeof e.content&&e.content.length>0&&(!b||"user"===e.role)),[t,b])}),Y=R&&B.length>0,[G,X]=(0,o.useState)(new Set);(0,o.useEffect)(()=>{V()},[n]);let Q=(0,o.useMemo)(()=>b?L.filter(e=>e.userMessage):L,[L,b]),Z=(0,o.useMemo)(()=>{let e=new Map;for(let t of Q)for(let n of(t.userMessage&&e.set(t.userMessage.id,t.id),t.assistantMessages))e.set(n.id,t.id);return e},[Q]),ee=(0,o.useMemo)(()=>{let e=new Map;return Q.forEach((t,n)=>e.set(t.id,n)),e},[Q]),et=(0,tm.Te)({count:Q.length,getScrollElement:()=>N.current,estimateSize:()=>160,overscan:6,getItemKey:e=>{var t,n;return null!=(n=null==(t=Q[e])?void 0:t.id)?n:e}}),en=et.getVirtualItems(),ea=en.length>0?"".concat(en[0].index,"-").concat(en[en.length-1].index):"",er=(0,o.useCallback)(()=>{let e=N.current;e&&(E.current=function(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}({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}))},[]);(0,o.useLayoutEffect)(()=>{let e=I.current,t=Q.length;I.current=t,-1!==e&&t>e&&t>0&&E.current&&!Y&&et.scrollToIndex(t-1,{align:"end"})},[Q.length,Y,et]),(0,o.useLayoutEffect)(()=>{if(!R||0===B.length)return void X(e=>0===e.size?e:new Set);X(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}(B,L))},[R,B,L]),(0,o.useEffect)(()=>{if(!R||!W)return;let e=Z.get(W.messageId);if(void 0===e)return;let t=ee.get(e);void 0!==t&&et.scrollToIndex(t,{align:"center"})},[R,W,Z,ee,et]),(0,o.useLayoutEffect)(()=>{let e=N.current;if(!e)return;if(!R||0===B.length)return void eE(C);let t=null;for(let a of B){var n;let r=(n=a.messageId,e.querySelector('[data-message-id="'.concat(CSS.escape(n),'"]')));if(!r)continue;let s=(null==W?void 0:W.messageId)===a.messageId,l=s?W.localIndex:-1;!function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ek;eT(e,t,n,a)}(r,a.ranges,l,C),s&&r instanceof HTMLElement&&(t=r)}return t&&"function"==typeof t.scrollIntoView&&t.scrollIntoView({block:"center",behavior:"smooth"}),()=>{eE(C)}},[R,B,W,G,C,ea]),(0,o.useEffect)(()=>{let e=N.current;if(R)null===M.current&&e&&(M.current=e.scrollTop);else{if(null!==M.current&&e){let t=M.current;requestAnimationFrame(()=>{e.scrollTop=t})}M.current=null}},[R]);let es=(0,o.useMemo)(()=>[...t0,l].filter(Boolean).join(" "),[l]),el=(0,o.useCallback)(e=>a(e),[a]),eo=(0,o.useCallback)(e=>()=>P(e),[P]),ei=(0,o.useRef)(k);ei.current=k;let ec=(0,o.useCallback)(async e=>{try{await (0,eu.l)(e),null==i||i(ei.current("history.copied"),"success")}catch(e){console.error("[HistoryPane] Failed to copy to clipboard"),null==i||i(ei.current("history.copyFailed"),"error")}},[i]),ed=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=A(e.id)||G.has(e.id);return(0,r.jsx)("div",{className:a?"opacity-60":"",children:(0,r.jsx)(tD,{pair:e,onFilePathClick:el,isExpanded:s,onToggleExpand:eo(e.id),onCopy:ec,onInsertToMessage:d,onRetryPending:u,onDiscardPending:h,showAssistant:!b})})},em=(0,o.useCallback)(e=>{let t=parseInt(e.target.value,10);tY(t)&&(null==p||p(t))},[p]),eh=(0,o.useCallback)(()=>{R?V():H()},[R,H,V]);return(0,r.jsxs)("div",{role:"region","aria-label":k("history.regionLabel"),className:es,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:k("history.title")}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[p&&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:k("history.show")}),(0,r.jsx)("select",{value:g,onChange:em,"aria-label":k("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:tq.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]}),f&&(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=>f(!0===e),className:"h-3.5 w-3.5"}),k("history.showArchived")]}),v&&(0,r.jsx)("button",{type:"button",onClick:()=>v(!b),"aria-label":k("history.showUserOnly"),"aria-pressed":b,className:"p-1 rounded transition-colors ".concat(b?"bg-accent-500/15 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:text-foreground"),title:k(b?"history.showAllMessages":"history.showUserOnly"),children:b?(0,r.jsx)(th.A,{size:14,"aria-hidden":"true"}):(0,r.jsx)(tx.A,{size:14,"aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:eh,"aria-label":k(R?"history.closeSearch":"history.openSearch"),"aria-pressed":R,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:k(R?"history.closeSearch":"history.openSearch"),children:(0,r.jsx)(z.A,{size:14,"aria-hidden":"true"})}),y&&(0,r.jsx)("button",{type:"button",onClick:y,"aria-label":k("terminal.hideHistory"),"aria-expanded":"true","aria-controls":T,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors",title:k("terminal.hideHistory"),"data-testid":S,children:(0,r.jsx)(tf.A,{size:14,"aria-hidden":"true"})})]})]}),R&&(0,r.jsx)("div",{className:"flex-shrink-0 px-3 py-2 bg-surface-2 border-b border-border",children:(0,r.jsx)(tF,{query:D,onQueryChange:U,matchCount:F,currentIndex:O,onNext:q,onPrev:J,onClose:V,isAtMaxMatches:_,onCompositionStart:K,onCompositionEnd:$})}),(0,r.jsx)("div",{ref:N,"data-testid":"history-scroll-container",onScroll:er,className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden p-4",children:s?(0,r.jsx)(tQ,{}):0===Q.length?(0,r.jsx)(tZ,{}):0===en.length?(0,r.jsx)("div",{"data-testid":"history-fallback-list",children:Q.slice(0,30).map(e=>(0,r.jsx)("div",{children:ed(e)},e.id))}):(0,r.jsx)("div",{style:{height:et.getTotalSize(),width:"100%",position:"relative"},children:en.map(e=>{let t=Q[e.index];return t?(0,r.jsx)("div",{"data-index":e.index,ref:et.measureElement,className:"absolute left-0 top-0 w-full",style:{transform:"translateY(".concat(e.start,"px)")},children:ed(t)},e.key):null})})})]})}),t2={isOpen:!1,position:{x:0,y:0},targetPath:null,targetType:null};var t4=n(7504),t5=n(22198),t3=n(21786),t6=n(26754),t8=n(71360),t9=n(9286);let t7=(0,o.memo)(function(e){let{isOpen:t,position:n,targetPath:a,targetType:s,onClose:l,onNewFile:i,onNewDirectory:d,onRename:u,onDelete:m,onUpload:h,onMove:x}=e,f=(0,c.c)("worktree"),g=(0,o.useRef)(null),{shouldRender:p,isExiting:b}=(0,t9.O)(t,et.$B),v=(0,o.useCallback)(e=>{e&&a&&e(a),l()},[a,l]),y=[{id:"new-file",label:f("fileTree.newFile"),icon:(0,r.jsx)(t4.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(i),showFor:["directory"]},{id:"new-directory",label:f("fileTree.newDirectory"),icon:(0,r.jsx)(t5.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(d),showFor:["directory"]},{id:"upload",label:f("contextMenu.uploadFile"),icon:(0,r.jsx)(t3.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(h),showFor:["directory"],showDividerAfter:!0},{id:"rename",label:f("contextMenu.rename"),icon:(0,r.jsx)(eg.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(u)},{id:"move",label:f("contextMenu.move"),icon:(0,r.jsx)(t6.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>{x&&a&&s&&x(a,s),l()},showDividerAfter:!0},{id:"delete",label:f("contextMenu.delete"),icon:(0,r.jsx)(t8.A,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>v(m),variant:"danger"}].filter(e=>!e.showFor||s&&e.showFor.includes(s));return((0,o.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=g.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,o.useEffect)(()=>{if(t&&g.current){let e=g.current.querySelector('[role="menuitem"]');e&&e.focus()}},[t]),p)?(0,r.jsx)("div",{ref:g,"data-testid":"context-menu",role:"menu","aria-label":f("contextMenu.label"),className:"fixed min-w-[160px] py-1 bg-surface rounded-lg shadow-lg border border-border ".concat(b?"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:ey.M.CONTEXT_MENU,left:"".concat(n.x,"px"),top:"".concat(n.y,"px")},children:y.map((e,t)=>(0,r.jsxs)(o.Fragment,{children:[(0,r.jsxs)("button",{role:"menuitem","data-testid":"context-menu-".concat(e.id),onClick:e.onClick,disabled:!a,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(a?"":"opacity-50 cursor-not-allowed"),children:[e.icon,(0,r.jsx)("span",{children:e.label})]}),e.showDividerAfter&&t<y.length-1&&(0,r.jsx)("div",{"data-testid":"context-menu-divider",className:"my-1 border-t border-border"})]},e.id))}):null});var ne=n(30061);let nt="commandmate.worktree.fileMetadataDisplay",nn={showSize:!0,showCreated:!1,showModified:!1},na="commandmate:fileMetadataDisplayChange";function nr(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 ns=(0,o.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"})})}),nl=(0,o.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"})})}),no=(0,o.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))})}),ni=(0,o.memo)(function(e){let{extension:t}=e,n=(0,o.useMemo)(()=>t&&({ts:"text-info",tsx:"text-info",js:"text-warning",jsx:"text-warning",json:"text-warning",md:"text-muted-foreground",css:"text-pink-500",scss:"text-pink-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"})})}),nc=(0,o.memo)(function e(t){let{item:n,path:a,depth:s,worktreeId:l,expanded:i,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:x,onContextMenu:f,searchQuery:g,searchMode:p,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y=nn}=t,j=(0,c.c)("worktree"),[w,k]=(0,o.useState)(!1),N=a?"".concat(a,"/").concat(n.name):n.name,C=i.has(N),S="directory"===n.type,T=d.get(N),E=(0,o.useMemo)(()=>v?tC(v):void 0,[v]),I=(0,o.useMemo)(()=>{if(S)return;let e=[];if(void 0!==n.size&&e.push("".concat(j("fileTree.metadata.size"),": ").concat(nr(n.size))),n.birthtime){let t=(0,tS.bg)(new Date(n.birthtime),E);t&&e.push("".concat(j("fileTree.metadata.created"),": ").concat(t))}if(n.mtime){let t=(0,tS.bg)(new Date(n.mtime),E);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,E,j]),M=(0,o.useCallback)(async()=>{S?(C||T||(k(!0),await x(N),k(!1)),m(N)):null==h||h(N)},[S,C,T,N,x,m,h]),L=(0,o.useCallback)(e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),M())},[M]),A=(0,o.useCallback)(e=>{e.preventDefault(),null==f||f(e,N,S?"directory":"file")},[N,S,f]),P=function(e){let{delay:t=500,moveThreshold:n=10,onLongPress:a}=e,r=(0,o.useRef)(null),s=(0,o.useRef)(null),l=(0,o.useRef)(null),i=(0,o.useCallback)(()=>{r.current&&(clearTimeout(r.current),r.current=null),s.current=null,l.current=null},[]);(0,o.useEffect)(()=>()=>i(),[i]);let c=(0,o.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),i()},t)},[t,a,i]),d=(0,o.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&&i()},[n,i]);return{onTouchStart:c,onTouchMove:d,onTouchEnd:(0,o.useCallback)(()=>{i()},[i]),onTouchCancel:(0,o.useCallback)(()=>{i()},[i])}}({onLongPress:(0,o.useCallback)(e=>{null==f||f(e,N,S?"directory":"file")},[N,S,f])}),R={...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:R,onClick:M,onKeyDown:L,onContextMenu:A,onTouchStart:P.onTouchStart,onTouchMove:P.onTouchMove,onTouchEnd:P.onTouchEnd,onTouchCancel:P.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)(ns,{expanded:C})}):(0,r.jsx)("span",{className:"w-4 h-4"}),S?(0,r.jsx)(nl,{open:C}):(0,r.jsx)(ni,{extension:n.extension}),(0,r.jsx)(ne.nR,{content:n.name,metadata:I,className:"flex-1 truncate text-sm text-foreground",children:"name"===p&&g?(0,r.jsx)(no,{text:n.name,query:g}):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}):nr(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,tS.fw)(n.birthtime,E)}),!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,tS.fw)(n.mtime,E)})]}),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==g?void 0:g.trim()))return!0;if("name"===p){let t=g.toLowerCase();return!!e.name.toLowerCase().includes(t)||"directory"===e.type}if("content"===p&&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:i,cache:d,onToggle:m,onFileSelect:h,onLoadChildren:x,onContextMenu:f,searchQuery:g,searchMode:p,matchedPaths:b,dateFnsLocaleStr:v,metadataDisplay:y},t.name))})]})});var nd=n(26989);let nu=[{key:"showSize",labelKey:"fileTree.metadata.showSize"},{key:"showCreated",labelKey:"fileTree.metadata.showCreated"},{key:"showModified",labelKey:"fileTree.metadata.showModified"}],nm=(0,o.memo)(function(e){let{settings:t,onToggle:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.useState)(!1),i=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!s)return;let e=e=>{i.current&&!i.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]);let d=(0,o.useCallback)(e=>{n(e)},[n]);return(0,r.jsxs)("div",{className:"relative",ref:i,"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)(nd.A,{className:"w-4 h-4","aria-hidden":"true"})}),s&&(0,r.jsxs)("div",{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",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")}),nu.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:()=>d(e.key),className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{children:a(e.labelKey)})]},e.key))]})]})});function nh(e){let{intervalMs:t,enabled:n,onPoll:a}=e,r=(0,o.useRef)(a);r.current=a;let s=(0,o.useRef)(n);s.current=n;let l=(0,o.useRef)(null);(0,o.useEffect)(()=>{function e(){null!==l.current&&(clearInterval(l.current),l.current=null)}function a(){e(),l.current=setInterval(()=>{r.current()},t)}function o(){"hidden"===document.visibilityState?e():"visible"===document.visibilityState&&s.current&&(r.current(),a())}return n?a():e(),document.addEventListener("visibilitychange",o),()=>{e(),document.removeEventListener("visibilitychange",o)}},[t,n])}function nx(e){return"commandmate:file-tree-expanded:"+e}function nf(e){try{let t=window.localStorage.getItem(nx(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 ng=n(89559);let np=(0,o.memo)(function(e){let{worktreeId:t,onFileSelect:n,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:i,onUpload:d,onMove:u,className:h="",refreshTrigger:f=0,pollingEnabled:g=!1,searchQuery:p,searchMode:b,searchResults:v,onSearchResultSelect:y,onResetView:j}=e,w=(0,tj.Ym)(),k=(0,c.c)("worktree"),{settings:N,toggle:C}=function(){let[e,t]=(0,o.useState)(nn),n=(0,o.useRef)(e);n.current=e,(0,o.useEffect)(()=>{t(function(){try{var e;let t=window.localStorage.getItem(nt);if(!t)return{...nn};return e=JSON.parse(t),"object"!=typeof e||null===e?{...nn}:{showSize:"boolean"==typeof e.showSize?e.showSize:nn.showSize,showCreated:"boolean"==typeof e.showCreated?e.showCreated:nn.showCreated,showModified:"boolean"==typeof e.showModified?e.showModified:nn.showModified}}catch(e){return{...nn}}}())},[]),(0,o.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(na,e),()=>window.removeEventListener(na,e)},[]);let a=(0,o.useCallback)(e=>{n.current=e,t(e);try{window.localStorage.setItem(nt,JSON.stringify(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(na,{detail:{settings:e}}))}catch(e){}},[]);return{settings:e,toggle:(0,o.useCallback)(e=>{a({...n.current,[e]:!n.current[e]})},[a]),setSettings:a}}(),[S,T]=(0,o.useState)(!0),[E,I]=(0,o.useState)(null),[M,L]=(0,o.useState)([]),{expanded:A,setExpanded:P,resetExpanded:R}=function(e){let[t,n]=(0,o.useState)(()=>nf(e)),a=(0,o.useRef)(e);(0,o.useEffect)(()=>{a.current!==e&&(a.current=e,n(nf(e)))},[e]),(0,o.useEffect)(()=>{!function(e,t){try{let n=nx(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,o.useCallback)(()=>{n(new Set)},[]);return{expanded:t,setExpanded:n,resetExpanded:r}}(t),[D,F]=(0,o.useState)(()=>new Map),z=(0,o.useRef)(null),O=(0,o.useRef)(A);O.current=A;let _=(0,o.useRef)(k);_.current=k;let B=(0,o.useRef)(new Set),{menuState:W,openMenu:H,closeMenu:V}=function(){let[e,t]=(0,o.useState)(t2),n=(0,o.useCallback)((e,n,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}t({isOpen:!0,position:{x:r,y:s},targetPath:n,targetType:a})},[]),a=(0,o.useCallback)(()=>{t(e=>({...e,isOpen:!1}))},[]),r=(0,o.useCallback)(()=>{t(t2)},[]);return(0,o.useEffect)(()=>{if(!e.isOpen)return;let t=()=>{a()},n=setTimeout(()=>{document.addEventListener("click",t)},0);return()=>{clearTimeout(n),document.removeEventListener("click",t)}},[e.isOpen,a]),(0,o.useEffect)(()=>{if(!e.isOpen)return;let t=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[e.isOpen,a]),{menuState:e,openMenu:n,closeMenu:a,resetMenu:r}}(),U=(0,o.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]),K=(0,o.useRef)(!0);(0,o.useEffect)(()=>(K.current=!0,()=>{K.current=!1}),[]);let $=(0,o.useCallback)(async()=>{if(K.current){T(!0),I(null);try{let e=await U();if(!K.current||!e)return;let t=Array.from(O.current),n=new Map,a=[];for(let e=0;e<t.length;e+=5){if(!K.current)return;let r=t.slice(e,e+5);for(let[e,t]of(await Promise.allSettled(r.map(async e=>{let t=await U(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(!K.current)return;L(e.items),F(n),a.length>0&&P(e=>{let t=new Set(e);for(let e of a)e&&t.delete(e);return t})}catch(e){K.current&&I(e instanceof Error?e.message:_.current("fileTree.loadError"))}finally{K.current&&T(!1)}}},[U,P]);(0,o.useEffect)(()=>{$()},[$,f]);let q=(0,o.useRef)(null),J=(0,o.useRef)(!1);(0,o.useEffect)(()=>{q.current=null},[t]),nh({intervalMs:5e3,enabled:g,onPoll:(0,o.useCallback)(async()=>{if(K.current&&!J.current){J.current=!0;try{let e=["",...Array.from(O.current)],t=new Map;for(let n=0;n<e.length;n+=5){if(!K.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 U(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(!K.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{J.current=!1}}},[U,$])});let Y=(0,o.useCallback)(async e=>{if(!(D.has(e)||B.current.has(e))){B.current.add(e);try{let t=await U(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,U]),G=(0,o.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[P]),X=(0,o.useCallback)(()=>{var e;R(),F(new Map),null==(e=z.current)||e.scrollTo({top:0}),null==j||j()},[R,j]),Q=(0,o.useMemo)(()=>"content"===b&&v&&0!==v.length?(0,x.q3)(v.map(e=>e.filePath)):new Set,[b,v]);(0,o.useEffect)(()=>{Q.size>0&&P(e=>{let t=new Set(e);for(let e of Q)(D.has(e)||(null==v?void 0:v.some(t=>t.filePath.startsWith(e+"/"))))&&t.add(e);return t})},[Q,D,v,P]);let Z=(0,o.useMemo)(()=>{if(!(null==p?void 0:p.trim()))return M;if("name"===b){let e=p.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(M,"")}return"content"===b&&Q.size>0?M.filter(e=>{if(Q.has(e.name))return!0;if("directory"===e.type){for(let t of Q)if(t.startsWith(e.name+"/")||t===e.name)return!0}return!1}):M},[M,p,b,Q,D]);if(S&&0===M.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(E&&0===M.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:E})});let ee=S&&M.length>0,et=!!E&&M.length>0;return 0===M.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)(t4.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)(t5.A,{className:"w-4 h-4","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("fileTree.newDirectory")})]})]})]}):(null==p?void 0:p.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:p})})}):(0,r.jsxs)("div",{ref:z,"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)(t4.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)(t5.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)(nm,{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-cyan-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)(ng.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:X,"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)(tv.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)(tb.A,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{className:"flex-1 truncate",children:E}),(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)(nc,{item:e,path:"",depth:0,worktreeId:t,expanded:A,cache:D,onToggle:G,onFileSelect:y||n,onLoadChildren:Y,onContextMenu:H,searchQuery:p,searchMode:b,matchedPaths:Q,dateFnsLocaleStr:w,metadataDisplay:N},e.name)),(0,r.jsx)(t7,{isOpen:W.isOpen,position:W.position,targetPath:W.targetPath,targetType:W.targetType,onClose:V,onNewFile:a,onNewDirectory:s,onRename:l,onDelete:i,onUpload:d,onMove:u})]})}),nb=(0,o.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"})})}),nv=(0,o.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"})})}),ny=(0,o.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")})}),nj=(0,o.memo)(function(e){let{query:t,mode:n,isSearching:a,error:s,onQueryChange:l,onModeChange:i,onClear:d,placeholder:u,className:m=""}=e,h=(0,o.useRef)(null),x=(0,c.c)("worktree"),f=(0,o.useCallback)(e=>{l(e.target.value)},[l]),g=(0,o.useCallback)(()=>{var e;d(),null==(e=h.current)||e.focus()},[d]),p=(0,o.useCallback)(e=>{if("Escape"===e.key)if(t)g();else{var n;null==(n=h.current)||n.blur()}},[t,g]);return(0,o.useEffect)(()=>{if(!(window.innerWidth<Y.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)(nb,{})}),(0,r.jsx)("input",{ref:h,type:"text","data-testid":"search-input",value:t,onChange:f,onKeyDown:p,placeholder:null!=u?u:x("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":x("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)(ny,{}):t?(0,r.jsx)("button",{type:"button","data-testid":"search-clear",onClick:g,className:"p-1 text-muted-foreground hover:text-foreground rounded transition-colors","aria-label":x("search.clear"),children:(0,r.jsx)(nv,{})}):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:x("search.mode")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-name",onClick:()=>i("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:x("search.modeName")}),(0,r.jsx)("button",{type:"button","data-testid":"mode-content",onClick:()=>i("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:x("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 nw(e){return 0===e.length?"0":e.map(e=>"".concat(e.id,":").concat(e.title.length,":").concat(e.content.length)).join("|")}var nk=n(12108),nN=n(60850);let nC=(0,o.memo)(function(e){var t,n;let{memo:a,onUpdate:s,onDelete:l,isSaving:i,error:d,className:u="",onInsertToMessage:m,onMoveUp:h,onMoveDown:x,canMoveUp:f=!0,canMoveDown:g=!0}=e,p=(0,c.c)("schedule"),b=(0,c.c)("worktree"),v=!!(h||x),[y,j]=(0,o.useState)(a.title),[w,k]=(0,o.useState)(a.content),[N,C]=(0,o.useState)(!1),S=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>{S.current&&clearTimeout(S.current)},[]);let{isSaving:T,error:E,saveNow:I}=(0,nN.U)({value:y,saveFn:async e=>{await s(a.id,{title:e})}}),{isSaving:M,error:L,saveNow:A}=(0,nN.U)({value:w,saveFn:async e=>{await s(a.id,{content:e})}}),P=null!=(n=null!=(t=null!=d?d:null==E?void 0:E.message)?t:null==L?void 0:L.message)?n:null,R=(0,o.useCallback)(e=>{j(e.target.value)},[]),D=(0,o.useCallback)(e=>{k(e.target.value)},[]),F=(0,o.useCallback)(()=>{I()},[I]),z=(0,o.useCallback)(()=>{A()},[A]),O=(0,o.useCallback)(()=>{l(a.id)},[a.id,l]),_=(0,o.useCallback)(()=>{w.trim()&&(null==m||m(w))},[w,m]),B=(0,o.useCallback)(async()=>{if(w.trim())try{await (0,eu.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:R,onBlur:F,placeholder:p("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!=i?i:T||M)&&(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:!f,"aria-label":p("memoMoveUp"),title:p("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)(nk.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button","data-testid":"memo-move-down-".concat(a.id),onClick:x,disabled:!g,"aria-label":p("memoMoveDown"),title:p("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)(e4.A,{className:"w-4 h-4","aria-hidden":"true"})})]}),m&&(0,r.jsx)("button",{type:"button","data-testid":"insert-memo-content",onClick:_,"aria-label":p("memoInsertToMessage"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 transition-colors rounded",title:p("memoInsertToMessage"),children:(0,r.jsx)(ty.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:B,"aria-label":p("memoCopyContent"),className:"flex-shrink-0 p-1 text-muted-foreground hover:text-foreground transition-colors rounded",children:N?(0,r.jsx)(ex.A,{className:"w-4 h-4 text-success"}):(0,r.jsx)(ep.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{type:"button",onClick:O,"aria-label":p("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:z,placeholder:p("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"}),P&&(0,r.jsx)("div",{className:"text-xs text-danger",children:P})]})}),nS=(0,o.memo)(function(e){let{currentCount:t,maxCount:n,onAdd:a,isLoading:s=!1,className:l=""}=e,o=(0,c.c)("schedule"),i=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":o("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:o("memoAdd")})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:o("memoRemaining",{count:i})})]})});function nT(e){let{query:t,onQueryChange:n,matchCount:a,currentIndex:s,onNext:l,onPrev:i,onClose:d,onCompositionStart:u,onCompositionEnd:h}=e,x=(0,c.c)("schedule"),f=(0,o.useRef)(null);(0,o.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let g=(0,o.useCallback)(e=>{"Escape"===e.key?d():"Enter"===e.key&&(e.preventDefault(),l())},[d,l]),p=(0,o.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":x("memoSearchLabel"),children:[(0,r.jsx)("input",{ref:f,type:"text",value:t,onChange:p,onKeyDown:g,onCompositionStart:u,onCompositionEnd:h,placeholder:x("memoSearchPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-foreground text-sm outline-none placeholder-muted-foreground","aria-label":x("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:i,disabled:0===a,"aria-label":x("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":x("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":x("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 nE=(0,o.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a}=e,s=(0,c.c)("schedule"),l=(0,c.c)("common"),[i,d]=(0,o.useState)([]),[m,h]=(0,o.useState)(!0),[x,f]=(0,o.useState)(!1),[g,p]=(0,o.useState)(null),[b,v]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),w=(0,o.useRef)(null),{query:k,matches:N,currentMatch:C,totalCount:S,setQuery:T,reset:E,navigateNext:I,navigatePrev:M,onCompositionStart:L,onCompositionEnd:A}=function(e){let{memos:t}=e,[n,a]=(0,o.useState)(""),[r,s]=(0,o.useState)([]),[l,i]=(0,o.useState)(-1),c=(0,o.useRef)(null),d=(0,o.useRef)(""),u=(0,o.useRef)(!1),m=(0,o.useRef)(nw(t)),h=(0,o.useRef)(t);h.current=t;let x=r.length,f=(0,o.useCallback)(()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),g=(0,o.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),i(t.length>0?0:-1)},[]),p=(0,o.useCallback)(e=>{f(),d.current=e,u.current||(c.current=setTimeout(()=>{g(e)},300))},[f,g]),b=(0,o.useCallback)(e=>{a(e),p(e)},[p]),v=(0,o.useCallback)(()=>{a(""),d.current="",s([]),i(-1),f()},[f]),y=(0,o.useCallback)(()=>{i(e=>0===x?-1:(e+1)%x)},[x]),j=(0,o.useCallback)(()=>{i(e=>0===x?-1:(e-1+x)%x)},[x]),w=(0,o.useCallback)(()=>{u.current=!0,f()},[f]),k=(0,o.useCallback)(()=>{u.current=!1;let e=d.current;e.length>=2&&(f(),c.current=setTimeout(()=>{g(e)},300))},[f,g]);return(0,o.useEffect)(()=>{let e=nw(t);if(e===m.current)return;m.current=e;let n=d.current;n.length>=2&&g(n)},[t,g]),(0,o.useEffect)(()=>()=>{f(),d.current=""},[f]),{query:n,matches:r,currentMatch:l,totalCount:x,setQuery:b,reset:v,navigateNext:y,navigatePrev:j,onCompositionStart:w,onCompositionEnd:k}}({memos:i}),P=y&&k.length>0,R=P?N:i,D=(0,o.useCallback)(async()=>{h(!0),p(null);try{let e=await B.$T.getAll(t);d(e.sort((e,t)=>e.position-t.position))}catch(e){p((0,B.hS)(e))}finally{h(!1)}},[t]);(0,o.useEffect)(()=>{D()},[D]);let F=(0,o.useCallback)(async()=>{f(!0),v(null);try{let e=await B.$T.create(t,{title:s("memoDefaultTitle"),content:""});d(t=>[...t,e])}catch(e){v((0,B.hS)(e))}finally{f(!1)}},[t,s]),O=(0,o.useCallback)(async(e,n)=>{await B.$T.update(t,e,n),d(t=>t.map(t=>t.id===e?{...t,...n}:t))},[t]),_=(0,o.useCallback)(async e=>{try{await B.$T.delete(t,e),d(t=>t.filter(t=>t.id!==e))}catch(e){console.error("Failed to delete memo:",e)}},[t]),W=(0,o.useCallback)(async(e,n)=>{let a=e+n;if(a<0||a>=i.length)return;let r=[...i];[r[e],r[a]]=[r[a],r[e]],d(r);try{await B.$T.reorder(t,r.map(e=>e.id))}catch(e){p((0,B.hS)(e)),await D()}},[i,t,D]),H=(0,o.useCallback)(()=>{D()},[D]),V=(0,o.useCallback)(()=>{j(e=>(e&&E(),!e))},[E]),U=(0,o.useCallback)(()=>{j(!1),E()},[E]);return((0,o.useEffect)(()=>{var e;if(!P||C<0)return;let t=N[C];if(!t)return;let n=null==(e=w.current)?void 0:e.querySelector('[data-memo-id="'.concat(t.id,'"]'));n&&(n.scrollIntoView({block:"nearest"}),n.focus({preventScroll:!0}))},[P,C,N]),m)?(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:H,"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:w,"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:y?(0,r.jsx)("div",{className:"flex-1",children:(0,r.jsx)(nT,{query:k,onQueryChange:T,matchCount:S,currentIndex:C,onNext:I,onPrev:M,onClose:U,onCompositionStart:L,onCompositionEnd:A})}):(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:V,"aria-label":s("memoSearchToggle"),className:"p-1.5 text-muted-foreground hover:text-foreground transition-colors rounded",children:(0,r.jsx)(z.A,{className:"w-4 h-4","aria-hidden":"true"})})]})}),0===i.length&&!P&&!b&&(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===R.length&&(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:(0,r.jsx)("p",{children:s("memoNoMatch")})}),R.map((e,t)=>(0,r.jsx)(nC,{memo:e,onUpdate:O,onDelete:_,onInsertToMessage:a,onMoveUp:P?void 0:()=>W(t,-1),onMoveDown:P?void 0:()=>W(t,1),canMoveUp:!P&&t>0,canMoveDown:!P&&t<i.length-1},e.id)),b&&(0,r.jsx)("div",{className:"text-center py-2 text-sm text-danger",children:b}),!P&&(0,r.jsx)(nS,{currentCount:i.length,maxCount:20,onAdd:F,isLoading:x,className:"mt-2"})]})});var nI=n(85872),nM=n(53292),nL=n(53482);let nA={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"},nP=o.memo(function(e){let{worktreeId:t,className:n=""}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.useState)([]),[i,d]=(0,o.useState)(""),[u,m]=(0,o.useState)(!0),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(null),[v,y]=(0,o.useState)(""),[j,w]=(0,o.useState)(""),[k,N]=(0,o.useState)(!1),C=(0,o.useCallback)(e=>{switch(e){case"doing":return a("todo.statusDoing");case"done":return a("todo.statusDone");default:return a("todo.statusTodo")}},[a]),S=(0,o.useCallback)(async()=>{m(!0),g(null);try{let e=await nI.Ar.list(t);l(e)}catch(e){g(e instanceof Error?e.message:a("todo.loadError")),l([])}finally{m(!1)}},[t,a]);(0,o.useEffect)(()=>{S()},[t]);let T=(0,o.useCallback)(async()=>{let e=i.trim();if(e&&!h){x(!0),g(null);try{let n=await nI.Ar.create(t,e);l(e=>[...e,n]),d("")}catch(e){g(e instanceof Error?e.message:a("todo.addError"))}finally{x(!1)}}},[i,h,t,a]),E=(0,o.useCallback)(async e=>{let n=function(e){let t=nI.KG.indexOf(e);return nI.KG[(t+1)%nI.KG.length]}(e.status);l(t=>t.map(t=>t.id===e.id?{...t,status:n,done:"done"===n}:t)),g(null);try{await nI.Ar.update(t,e.id,{status:n})}catch(e){g(e instanceof Error?e.message:a("todo.updateError")),S()}},[t,S,a]),I=(0,o.useCallback)(async e=>{g(null);try{await nI.Ar.remove(t,e.id),l(t=>t.filter(t=>t.id!==e.id))}catch(e){g(e instanceof Error?e.message:a("todo.deleteError"))}},[t,a]),M=(0,o.useCallback)(e=>{b(e),y(e.content),w(e.detail),g(null)},[]),L=(0,o.useCallback)(()=>{b(null),N(!1)},[]),A=(0,o.useCallback)(async()=>{if(!p)return;let e=v.trim();if(e&&!k){N(!0),g(null);try{let n=await nI.Ar.update(t,p.id,{content:e,detail:j});l(e=>e.map(e=>e.id===p.id?n:e)),L()}catch(e){g(e instanceof Error?e.message:a("todo.updateError")),N(!1)}}},[p,v,j,k,t,L,a]),P=(0,o.useCallback)(async(e,n)=>{let r=e+n;if(r<0||r>=s.length)return;let o=[...s];[o[e],o[r]]=[o[r],o[e]],l(o),g(null);try{await nI.Ar.reorder(t,o.map(e=>e.id))}catch(e){g(e instanceof Error?e.message:a("todo.reorderError")),S()}},[s,t,S,a]),R=(0,o.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),T())},[T]),D=(0,o.useMemo)(()=>({todo:s.filter(e=>"todo"===e.status).length,doing:s.filter(e=>"doing"===e.status).length,done:s.filter(e=>"done"===e.status).length}),[s]);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:i,onChange:e=>d(e.target.value),onKeyDown:R,maxLength:nM.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:T,disabled:h||0===i.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:[C("todo")," ",D.todo]}),(0,r.jsxs)("span",{"data-testid":"todo-count-doing",children:[C("doing")," ",D.doing]}),(0,r.jsxs)("span",{"data-testid":"todo-count-done",children:[C("done")," ",D.done]})]}),f&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"todo-error",children:f}),u?(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"todo-loading",children:a("todo.loading")}):0===s.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:s.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:()=>E(e),"data-testid":"todo-status","data-status":e.status,"aria-label":a("todo.cycleStatus",{status:C(e.status)}),title:a("todo.cycleStatus",{status:C(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(nA[e.status]),children:C(e.status)}),(0,r.jsxs)("button",{type:"button",onClick:()=>M(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:()=>P(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:()=>P(t,1),disabled:t===s.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:()=>I(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)(e0.a,{isOpen:null!==p,onClose:L,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:v,onChange:e=>y(e.target.value),maxLength:nM.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")}),""!==j.trim()&&(0,r.jsx)(nL.i,{text:j,label:a("todo.copyDetail"),className:"!border-input !bg-surface dark:!bg-surface-2 !text-muted-foreground hover:!bg-muted"})]}),(0,r.jsx)("textarea",{value:j,onChange:e=>w(e.target.value),maxLength:nM.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:L,"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:A,disabled:k||0===v.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 nR=n(95740),nD=n(66630),nF=n(37586),nz=n(47650);function nO(e){let{isOpen:t,onClose:n,title:a,children:s,footer:l,showCloseButton:i=!0}=e,d=(0,c.c)("common"),[u,m]=(0,o.useState)(null);return((0,o.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,n]),(0,o.useEffect)(()=>(t?document.body.style.overflow="hidden":document.body.style.overflow="unset",()=>{document.body.style.overflow="unset"}),[t]),(0,o.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,nz.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:ey.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}),i&&(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)(em.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 n_=["default","acceptEdits","plan","dontAsk","bypassPermissions"],nB=["read-only","workspace-write","danger-full-access"],nW=["allow-all-tools","yolo"],nH=["--dangerously-skip-permissions"],nV=[],nU={claude:"acceptEdits",codex:"workspace-write",gemini:"","vibe-local":"",copilot:"allow-all-tools",antigravity:"--dangerously-skip-permissions"};function nK(e){switch(e){case"codex":return nB;case"copilot":return nW;case"antigravity":return nH;case"claude":return n_;default:return nV}}let n$=/^[\w\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uF900-\uFAFF\s-]{1,100}$/,nq=/^[a-zA-Z0-9][a-zA-Z0-9\-._/:]*$/,nJ=new Set(["copilot"]),nY=[{value:"0 */1 * * *",labelKey:"cronPresetHourly"},{value:"0 9 * * *",labelKey:"cronPresetDaily9"},{value:"0 9 * * 1",labelKey:"cronPresetWeeklyMon9"}],nG={name:"",cronExpression:"0 9 * * *",message:"",cliToolId:"claude",enabled:!0,permission:null!=(a=nU.claude)?a:"",model:""},nX="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",nQ="block text-xs font-semibold text-foreground mb-1",nZ="mt-1 text-xs text-danger-foreground";function n0(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)(nR.A,{size:14,"aria-hidden":"true"}),n]})}function n1(e){let{id:t,title:n,summary:a,icon:s,isOpen:l,onToggle:o,children:i}=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:()=>o(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)(e4.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:i})]})}function n2(e){var t,n;let{isOpen:a,worktreeId:s,initialValues:l,originalName:i,onInsertToMessage:d,instances:u,onClose:h,onSaved:x}=e,f=(0,c.c)("schedule"),g=(0,Y.a)(),p=(0,o.useMemo)(()=>u&&u.length>0?u:(0,e2.lu)([...e2.XH]),[u]),[b,v]=(0,o.useState)(nG),[y,j]=(0,o.useState)(""),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(null),[T,E]=(0,o.useState)(()=>new Set(["basic","advanced","message"]));(0,o.useEffect)(()=>{var e,t,n,r,s,o,i,c,d,u;if(!a)return;S(null),N(!1);let m=null!=(t=null==l?void 0:l.cliToolId)?t:nG.cliToolId;v({name:null!=(n=null==l?void 0:l.name)?n:nG.name,cronExpression:null!=(r=null==l?void 0:l.cronExpression)?r:nG.cronExpression,message:null!=(s=null==l?void 0:l.message)?s:nG.message,cliToolId:m,enabled:null!=(o=null==l?void 0:l.enabled)?o:nG.enabled,permission:null!=(i=null==l?void 0:l.permission)?i:nG.permission,model:null!=(c=null==l?void 0:l.model)?c:nG.model});let h=p.find(e=>e.cliTool===m);j(null!=(u=null!=(d=null==h?void 0:h.id)?d:null==(e=p[0])?void 0:e.id)?u:m)},[a,l,p]),(0,o.useEffect)(()=>{a&&E(new Set(g?["basic"]:["basic","advanced","message"]))},[a,g]);let I=(0,o.useCallback)(e=>{E(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),M=nK(b.cliToolId),L=M.length>0,A="copilot"===b.cliToolId,P=!!i,R=(0,o.useMemo)(()=>{let e=b.name.trim();return e?e.length>100?f("edit.errorNameTooLong",{max:100}):n$.test(e)?null:f("edit.errorNameInvalid"):f("edit.errorNameRequired")},[b.name,f]),D=(0,o.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())?f("edit.errorCronInvalid"):null,[b.cronExpression,f]),F=(0,o.useMemo)(()=>b.message.trim()?b.message.length>1e4?f("edit.errorMessageTooLong",{max:1e4}):null:f("edit.errorMessageRequired"),[b.message,f]),z=(0,o.useMemo)(()=>{var e;return A&&b.model.trim()?(e=b.model.trim(),/[\x00-\x1f\x7f]/.test(e)?{valid:!1,reason:"Model name contains control characters"}:""===e.trim()?{valid:!1,reason:"Model name must not be empty"}:!nq.test(e)?{valid:!1,reason:"Model name contains invalid characters"}:e.length>128?{valid:!1,reason:"Model name exceeds ".concat(128," characters")}:{valid:!0}).valid?null:f("edit.errorModelInvalid"):null},[A,b.model,f]),O=!R&&!D&&!F&&!z,_=(0,o.useCallback)(e=>{v(t=>({...t,cliToolId:e,permission:function(e){let t=nU[e];if(void 0!==t)return t;let n=nK(e);return n.length>0?n[0]:""}(e),model:"copilot"===e?t.model:""}))},[]),B=(0,o.useCallback)(e=>{let t=p.find(t=>t.id===e);t&&(j(e),_(t.cliTool))},[p,_]),W=nY.some(e=>e.value===b.cronExpression)?b.cronExpression:"custom",H=(0,o.useCallback)(e=>{"custom"!==e&&v(t=>({...t,cronExpression:e}))},[]),V=(0,o.useCallback)(e=>{null==d||d(e),h()},[d,h]),U=(0,o.useCallback)(async()=>{if(O&&!k){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:L?b.permission:"",model:A&&b.model.trim()?b.model.trim():void 0,originalName:null!=i?i:void 0})});if(!e.ok){let t=await e.json().catch(()=>({}));S(t.error||f("edit.saveError"));return}x(),h()}catch(e){S(f("edit.saveError"))}finally{N(!1)}}},[O,k,s,b,L,A,i,x,h,f]),K=null!=(n=null==(t=p.find(e=>e.id===y))?void 0:t.alias)?n:(0,e2.f_)(b.cliToolId),$=b.name.trim()?"".concat(b.name.trim()," \xb7 ").concat(b.cronExpression):b.cronExpression,q=[K,L?b.permission:null,A&&b.model.trim()?b.model.trim():null].filter(Boolean).join(" \xb7 "),J=b.message.trim(),G=J.length>32?"".concat(J.slice(0,32),"…"):J,X=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-name-input",children:f("edit.name")}),(0,r.jsx)("input",{id:"schedule-name-input","data-testid":"schedule-name-input",type:"text",value:b.name,maxLength:100,placeholder:f("edit.namePlaceholder"),onChange:e=>v(t=>({...t,name:e.target.value})),className:nX}),R&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-name-error",children:R})]}),(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:f("edit.cron")}),d&&(0,r.jsx)(n0,{testId:"schedule-cron-ask-ai",label:f("edit.askAiCron"),title:f("edit.askAiHint"),onClick:()=>V(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.cron"):e("edit.aiPrompts.cronRefine",{current:"`"+n+"`"})}(f,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:f("edit.cronPlaceholder"),onChange:e=>v(t=>({...t,cronExpression:e.target.value})),className:"".concat(nX," font-mono sm:flex-1")}),(0,r.jsxs)("select",{"data-testid":"schedule-cron-preset","aria-label":f("edit.cronPreset"),value:W,onChange:e=>H(e.target.value),className:"".concat(nX," sm:w-48"),children:[nY.map(e=>(0,r.jsx)("option",{value:e.value,children:f("edit.".concat(e.labelKey))},e.value)),(0,r.jsx)("option",{value:"custom",children:f("edit.cronPresetCustom")})]})]}),D&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-cron-error",children:D})]}),(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:f("edit.enabledLabel")})]})]}),Q=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-cli-tool-select",children:f("edit.cliTool")}),(0,r.jsx)("select",{id:"schedule-cli-tool-select","data-testid":"schedule-cli-tool-select",value:y,onChange:e=>B(e.target.value),className:nX,children:p.map(e=>(0,r.jsx)("option",{value:e.id,children:e.alias},e.id))})]}),A&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-model-input",children:f("edit.model")}),(0,r.jsx)("input",{id:"schedule-model-input","data-testid":"schedule-model-input",type:"text",value:b.model,placeholder:f("edit.modelPlaceholder"),onChange:e=>v(t=>({...t,model:e.target.value})),className:nX}),z&&(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-model-error",children:z})]}),L&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:nQ,htmlFor:"schedule-permission-select",children:f("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:nX,children:M.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),Z=(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:f("edit.message")}),d&&(0,r.jsx)(n0,{testId:"schedule-message-ask-ai",label:f("edit.askAiMessage"),title:f("edit.askAiHint"),onClick:()=>V(function(e,t){let n=t.trim();return 0===n.length?e("edit.aiPrompts.messageDraft"):e("edit.aiPrompts.messageDraftNamed",{name:"`"+n+"`"})}(f,b.name))})]}),(0,r.jsx)("textarea",{id:"schedule-message-input","data-testid":"schedule-message-input",value:b.message,rows:4,maxLength:1e4,placeholder:f("edit.messagePlaceholder"),onChange:e=>v(t=>({...t,message:e.target.value})),className:"".concat(nX," resize-none")}),(0,r.jsxs)("div",{className:"mt-1 flex items-center justify-between",children:[F?(0,r.jsx)("p",{className:nZ,"data-testid":"schedule-message-error",children:F}):(0,r.jsx)("span",{}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"schedule-message-count",children:f("edit.charCount",{count:b.message.length,max:1e4})})]})]}),ee=(0,r.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,r.jsx)(n1,{id:"basic",title:f("edit.sectionBasic"),summary:$,icon:(0,r.jsx)(w.A,{className:"w-4 h-4"}),isOpen:T.has("basic"),onToggle:I,children:X}),(0,r.jsx)(n1,{id:"advanced",title:f("edit.sectionAdvanced"),summary:q,icon:(0,r.jsx)(nD.A,{className:"w-4 h-4"}),isOpen:T.has("advanced"),onToggle:I,children:Q}),(0,r.jsx)(n1,{id:"message",title:f("edit.sectionMessage"),summary:G,icon:(0,r.jsx)(nF.A,{className:"w-4 h-4"}),isOpen:T.has("message"),onToggle:I,children:Z}),C&&(0,r.jsx)("div",{className:"text-xs p-2 rounded bg-danger-subtle text-danger-foreground","data-testid":"schedule-submit-error",children:C})]}),et=(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:f("edit.cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"schedule-save-button",onClick:()=>void U(),disabled:!O||k,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:f("edit.save")})]}),en=P?f("edit.titleEdit"):f("edit.titleCreate");return g?(0,r.jsx)(nO,{isOpen:a,onClose:h,title:en,footer:et,children:ee}):(0,r.jsx)(e0.a,{isOpen:a,onClose:h,title:en,size:"md",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[ee,(0,r.jsx)("div",{className:"pt-2 border-t border-border",children:et})]})})}function n4(e){return new Date(e).toLocaleString()}function n5(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 n3=(0,o.memo)(function(e){let{worktreeId:t,logs:n}=e,a=(0,c.c)("schedule"),[s,l]=(0,o.useState)(null),[i,d]=(0,o.useState)(null),u=(0,o.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:[n4(e.started_at),n5(e.started_at,e.completed_at)&&(0,r.jsxs)("span",{className:"ml-2",children:["(",n5(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&&i&&(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:i.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:i.result||a("noOutput")})]})]})]},e.id))})});function n6(){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 n8(){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 n9=(0,o.memo)(function(e){let{worktreeId:t,className:n="",onInsertToMessage:a,instances:s}=e,l=(0,c.c)("schedule"),i=(0,el.SC)(),[d,u]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[f,g]=(0,o.useState)([]),[p,b]=(0,o.useState)(!0),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)("schedules"),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(void 0),[I,M]=(0,o.useState)(void 0),L=(0,o.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();x(e.schedules||[])}if(a.ok){let e=await a.json();g(e.schedules||[])}else g([])}catch(e){y(e instanceof Error?e.message:"Failed to fetch data")}finally{b(!1)}},[t]);(0,o.useEffect)(()=>{L()},[L]);let A=(0,o.useCallback)(async e=>{try{var n,a,r,s,l,o,i;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 o=n.split("|").slice(1,-1).map(e=>e.trim());o.length>0&&t.get(a).push(o)}return t})(u).get("Schedules"))?n:[]).find(t=>{var n;return(null!=(n=t[0])?n:"").trim()===e});if(!m)return null;let h=function(e){let t=e.trim();if(!t)return{cliToolId:"claude",model:void 0};let n=t.split(/\s+/),a=n[0];return 1===n.length?{cliToolId:a,model:void 0}:nJ.has(a)?3===n.length&&"--model"===n[1]?{cliToolId:a,model:n[2]}:{cliToolId:a,error:"".concat(a," only supports: ").concat(a," --model <modelName>")}:{cliToolId:a,error:'CLI Tool "'.concat(a,'" does not support additional options')}}(null!=(a=m[3])?a:"claude"),x=(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:""===x||"true"===x,permission:(null!=(o=m[5])?o:"").trim(),model:null!=(i=h.model)?i:""}}catch(e){return null}},[t]),P=(0,o.useCallback)(()=>{M(void 0),E(void 0),S(!0)},[]),R=(0,o.useCallback)(async e=>{let t=await A(e.name);M(e.name),E(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)},[A]),D=(0,o.useCallback)(async e=>{if(await i({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 L()}catch(e){console.error("Failed to delete schedule:",e)}},[t,l,L,i]),F=(0,o.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 L()}catch(e){console.error("Failed to toggle schedule:",e)}},[t,L]);return p?(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 L(),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")," (",f.length,")"]}),(0,r.jsx)("span",{className:"text-xs text-accent-700 dark:text-accent-300",children:l("activeSchedulesDescription")})]}),0===f.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:f.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"),": ",n4(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:P,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:P,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 R(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)(n6,{})}),(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)(n8,{})})]})]}),(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"),": ",n4(e.last_executed_at)]})]})]},e.id)})})]})]}):(0,r.jsx)(n3,{worktreeId:t,logs:d})}),(0,r.jsx)(n2,{isOpen:C,worktreeId:t,initialValues:T,originalName:I,onInsertToMessage:a,instances:s,onClose:()=>S(!1),onSaved:()=>{L()}})]})}),n7=(0,o.memo)(function(e){let{worktreeId:t,vibeLocalModel:n,onVibeLocalModelChange:a,vibeLocalContextWindow:s,onVibeLocalContextWindowChange:l}=e,i=(0,c.c)("schedule"),[d,m]=(0,o.useState)([]),[h,x]=(0,o.useState)(null),[f,g]=(0,o.useState)(!1),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null!=s?String(s):""),[j,w]=(0,o.useState)(!1);(0,o.useEffect)(()=>{y(null!=s?String(s):"")},[s]),(0,o.useEffect)(()=>{let e=!1;return g(!0),fetch("/api/ollama/models").then(e=>e.json()).then(t=>{e||(m(t.models),x(0===t.models.length&&t.error?t.error:null))}).catch(()=>{e||(m([]),x("Failed to fetch models"))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[]);let k=(0,o.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,o.useCallback)(e=>{y(e.target.value)},[]),C=(0,o.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:i("vibeLocalModel")}),f?(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"}),i("loading")]}):h&&0===d.length?(0,r.jsx)("p",{className:"text-xs text-warning-foreground",children:i("ollamaNotAvailable")}):(0,r.jsxs)("select",{"data-testid":"vibe-local-model-select",value:null!=n?n:"",onChange:k,disabled:p,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:i("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:i("vibeLocalContextWindow")}),(0,r.jsx)("input",{type:"number","data-testid":"vibe-local-context-window-input",step:"1",min:e2.vz,max:e2.NL,value:v,onChange:N,onBlur:C,placeholder:i("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"})]})]})}),ae=(0,o.memo)(function(e){let{worktreeId:t,selectedAgents:n,onSelectedAgentsChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d,maxAgents:u=2,availableAgents:h=e2.XH,persistToServer:x=!0}=e,f=(0,c.c)("schedule"),g=n.length>u?n.slice(0,u):n,[p,b]=(0,o.useState)(()=>new Set(g)),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)(!1),k=(0,o.useRef)(p);k.current=p,(0,o.useEffect)(()=>{j||b(new Set(g))},[n,j,u]);let N=p.has("vibe-local"),C=(0,o.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(!x){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(g))}catch(e){b(new Set(g))}finally{y(!1),w(!1)}}},[t,g,a,x]),S=p.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:f("agentSettings")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:f("selectAgents")}),(0,r.jsx)("div",{className:"space-y-3",children:h.map(e=>{let t=p.has(e),n=!t&&S;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,e2.oo)(e),checked:t,disabled:n||v,onCheckedChange:t=>C(e,!0===t)}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:(0,e2.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"}),f("loading")]}),N&&(0,r.jsx)(n7,{worktreeId:t,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d})]})});function at(e){return"".concat("commandmate:worktree:mobileInstances:").concat(e)}function an(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 aa=n(49476),ar=n(20017),as=n(6191);let al=(0,o.memo)(function(e){let{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d}=e,m=(0,c.c)("schedule"),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)({}),[v,y]=(0,o.useState)(e2.XH[0]),[j,w]=(0,o.useState)(null),k=n.length>=e2.Ab,N=n.length<=1,C=n.some(e=>"vibe-local"===e.cliTool),S=(0,o.useCallback)(async e=>{let n=e.map((e,t)=>({...e,order:t}));x(!0),g(null);try{(await fetch("/api/worktrees/".concat(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentInstances:n})})).ok?a(n):g(m("agentInstanceSaveError"))}catch(e){g(m("agentInstanceSaveError"))}finally{x(!1)}},[t,a,m]),T=(0,o.useCallback)(()=>{if(n.length>=e2.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)}(v,n);S([...n,{id:e,cliTool:v,alias:function(e,t){let n=(0,e2.oo)(e);if(t===e)return n;let a=t.slice(e.length+1);return a?"".concat(n," ").concat(a):n}(v,e),order:n.length}])},[v,n,S]),E=(0,o.useCallback)(e=>{n.length<=1||S(n.filter(t=>t.id!==e))},[n,S]),I=(0,o.useCallback)((e,t)=>{let a=e+t;if(a<0||a>=n.length)return;let r=[...n];[r[e],r[a]]=[r[a],r[e]],S(r)},[n,S]),M=(0,o.useCallback)((e,t)=>{b(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n});let a=n.find(t=>t.id===e);a&&t!==a.alias&&S(n.map(n=>n.id===e?{...n,alias:t}:n))},[n,S]),L=(0,o.useCallback)((e,t)=>{if(e===t||e<0||t<0||e>=n.length||t>=n.length)return;let a=[...n],[r]=a.splice(e,1);a.splice(t,0,r),S(a)},[n,S]);return(0,r.jsxs)("div",{className:"p-4","data-testid":"agent-instances-pane",children:[(0,r.jsx)("h3",{className:"text-sm font-semibold text-foreground mb-1",children:m("agentInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:m("agentInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-2",children:n.map((e,t)=>{let a=e.id in p?p[e.id]:e.alias,s=j===t;return(0,r.jsxs)("div",{"data-testid":"agent-instance-row-".concat(e.id),draggable:!0,onDragStart:()=>w(t),onDragOver:e=>e.preventDefault(),onDrop:()=>{null!==j&&L(j,t),w(null)},onDragEnd:()=>w(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(s?"opacity-50":""),children:[(0,r.jsx)("span",{className:"cursor-grab text-muted-foreground shrink-0","aria-hidden":"true",children:(0,r.jsx)(aa.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":m("agentInstanceAliasLabel"),value:a,maxLength:e2.pQ,disabled:h,placeholder:m("agentInstanceAliasPlaceholder"),onChange:t=>b(n=>({...n,[e.id]:t.target.value})),onBlur:t=>M(e.id,t.target.value),onKeyDown:e=>{"Enter"===e.key&&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)(ne.nR,{content:(0,e2.oo)(e.cliTool),className:"mt-0.5 block truncate text-xs text-muted-foreground"})]}),(0,r.jsxs)(eO.rI,{children:[(0,r.jsx)(eO.ty,{asChild:!0,children:(0,r.jsx)("button",{type:"button","data-testid":"agent-instance-menu-".concat(e.id),"aria-label":m("agentInstanceActions"),title:m("agentInstanceActions"),disabled:h,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)(ar.A,{className:"w-4 h-4"})})}),(0,r.jsxs)(eO.SQ,{align:"end",children:[(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-move-up-".concat(e.id),disabled:0===t,onSelect:()=>I(t,-1),children:[(0,r.jsx)(nk.A,{className:"w-4 h-4"}),m("agentInstanceMoveUp")]}),(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-move-down-".concat(e.id),disabled:t===n.length-1,onSelect:()=>I(t,1),children:[(0,r.jsx)(e4.A,{className:"w-4 h-4"}),m("agentInstanceMoveDown")]}),(0,r.jsx)(eO.mB,{}),(0,r.jsxs)(eO._2,{"data-testid":"agent-instance-delete-".concat(e.id),disabled:N,onSelect:()=>E(e.id),className:"text-danger-foreground focus:text-danger-foreground",children:[(0,r.jsx)(t8.A,{className:"w-4 h-4"}),m("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":m("agentInstanceBaseTool"),value:v,disabled:h||k,onChange:e=>y(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:e2.XH.map(e=>(0,r.jsx)("option",{value:e,children:(0,e2.oo)(e)},e))}),(0,r.jsxs)("button",{type:"button","data-testid":"agent-instance-add",disabled:h||k,onClick:T,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)(as.A,{className:"w-4 h-4"}),m("agentInstanceAdd")]})]}),k&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:m("agentInstanceMax",{max:e2.Ab})}),N&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:m("agentInstanceMin",{min:1})}),h&&(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"}),m("loading")]}),f&&(0,r.jsx)("p",{"data-testid":"agent-instances-error",className:"mt-3 text-xs text-danger-foreground",children:f}),C&&(0,r.jsx)(n7,{worktreeId:t,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:i,onVibeLocalContextWindowChange:d})]})}),ao=(0,o.memo)(function(e){let{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:i,visibleInstanceIds:d,onToggleInstanceVisible:u}=e,h=(0,c.c)("schedule"),x=new Set(d),f=d.length<=1;return(0,r.jsxs)("div",{"data-testid":"mobile-agent-instances-pane",children:[(0,r.jsx)(al,{worktreeId:t,instances:n,onInstancesChange:a,vibeLocalModel:s,onVibeLocalModelChange:l,vibeLocalContextWindow:o,onVibeLocalContextWindowChange:i}),(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:h("mobileVisibleInstances")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-3",children:h("mobileVisibleInstancesDescription")}),(0,r.jsx)("div",{className:"space-y-1",children:n.map(e=>{let t=x.has(e.id),n=t&&f;return(0,r.jsxs)("label",{className:"flex items-center gap-2 p-2 rounded-lg cursor-pointer ".concat(n?"opacity-60 cursor-not-allowed":"hover:bg-muted"),children:[(0,r.jsx)(m.Sc,{"data-testid":"mobile-visible-instance-toggle-".concat(e.id),checked:t,disabled:n,onCheckedChange:()=>u(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,e2.sw)(e)}),(0,r.jsx)("span",{className:"block text-xs text-muted-foreground truncate",children:(0,e2.oo)(e.cliTool)})]})]},e.id)})}),f&&(0,r.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:h("mobileVisibleInstanceMin")})]})]})}),ai=Array.from({length:Math.floor(104)+1},(e,t)=>3e5+3e5*t);var ac=n(82912),ad=n.n(ac);let au=[36e5,108e5,288e5],am={36e5:"autoYes.durations.1h",108e5:"autoYes.durations.3h",288e5:"autoYes.durations.8h"};function ah(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 ax(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 af="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 ag(e){let{isOpen:t,worktreeId:n,instances:a,onClose:s,onSaved:l}=e,i=(0,c.c)("schedule"),d=(0,Y.a)(),u=(0,o.useMemo)(()=>a&&a.length>0?a:(0,e2.lu)([...e2.XH]),[a]),[m,h]=(0,o.useState)(""),[x,f]=(0,o.useState)(()=>{var e,t;return null!=(t=null==(e=u[0])?void 0:e.id)?t:e2.XH[0]}),[g,p]=(0,o.useState)(ai[0]),[b,v]=(0,o.useState)(!1),[y,j]=(0,o.useState)(null);(0,o.useEffect)(()=>{var e,n;t&&(h(""),p(ai[0]),j(null),v(!1),f(null!=(n=null==(e=u[0])?void 0:e.id)?n:e2.XH[0]))},[t,u]),(0,o.useEffect)(()=>{if(!u.some(e=>e.id===x)){var e,t;f(null!=(t=null==(e=u[0])?void 0:e.id)?t:e2.XH[0])}},[u,x]);let w=m.trim().length>0&&!b,k=(0,o.useCallback)(async()=>{if(!m.trim()||b)return;let e=u.find(e=>e.id===x);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:g})});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,x,m,g,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:i("timer.agent")}),(0,r.jsx)("select",{id:"timer-instance-select","data-testid":"timer-instance-select",value:x,onChange:e=>f(e.target.value),className:af,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:i("timer.message")}),(0,r.jsx)("textarea",{id:"timer-message-input","data-testid":"timer-message-input",value:m,onChange:e=>h(e.target.value),placeholder:i("timer.message"),maxLength:1e4,rows:3,className:"".concat(af," 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:i("timer.delay")}),(0,r.jsx)("select",{id:"timer-delay-select","data-testid":"timer-delay-select",value:g,onChange:e=>p(Number(e.target.value)),className:af,children:ai.map(e=>(0,r.jsx)("option",{value:e,children:ax(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:i("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:i("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:i("timer.register")})]}),S=i("timer.titleCreate");return d?(0,r.jsx)(nO,{isOpen:t,onClose:s,title:S,footer:C,children:N}):(0,r.jsx)(e0.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 ap(e){return new Date(e).toLocaleString()}function ab(e){var t,n;let{timer:a,instances:s,onClose:l}=e,o=(0,c.c)("schedule"),i=(0,Y.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:o("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:o("timer.agent"),children:(0,r.jsx)("span",{className:"text-accent-600 dark:text-accent-400 font-medium",children:d})}),(0,r.jsx)(u,{label:o("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:o("timer.status.".concat(a.status))})}),(0,r.jsx)(u,{label:o("timer.delay"),children:ax(a.delayMs)}),(0,r.jsx)(u,{label:o("timer.scheduledTime"),children:ap(a.scheduledSendTime)}),(0,r.jsx)(u,{label:o("timer.createdTime"),children:ap(a.createdAt)}),null!==a.sentAt&&(0,r.jsx)(u,{label:o("timer.sentTime"),children:ap(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:o("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:o("timer.close")})}),x=o("timer.detailTitle");return i?(0,r.jsx)(nO,{isOpen:!0,title:x,onClose:l,footer:h,children:m}):(0,r.jsx)(e0.a,{isOpen:!0,title:x,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 av=(0,o.memo)(function(e){let{worktreeId:t,instances:n}=e,a=(0,c.c)("schedule"),s=(0,el.SC)(),l=(0,o.useMemo)(()=>n&&n.length>0?n:(0,e2.lu)([...e2.XH]),[n]),[i,d]=(0,o.useState)([]),[u,m]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[,p]=(0,o.useState)(0),b=(0,o.useRef)(null),y=(0,o.useRef)(null),j=(0,o.useRef)(null),w=(0,o.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,o.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,o.useEffect)(()=>{function e(){return w(),b.current=setInterval(()=>{w()},1e4),y.current=setInterval(()=>{p(e=>e+1)},1e3),t}function t(){b.current&&clearInterval(b.current),y.current&&clearInterval(y.current),b.current=null,y.current=null}e();let n=()=>{"hidden"===document.visibilityState?t():e()};return document.addEventListener("visibilitychange",n),()=>{t(),document.removeEventListener("visibilitychange",n)}},[w]);let N=(0,o.useCallback)(async e=>{try{(await fetch("/api/worktrees/".concat(t,"/timers?timerId=").concat(e),{method:"DELETE"})).ok&&w()}catch(e){}},[t,w]),C=(0,o.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=i.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===i.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)(v.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:()=>x(!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)(as.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:()=>x(!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)(as.A,{className:"w-3.5 h-3.5"}),a("timer.newTimer")]})]}),i.map(e=>{var t,n;return(0,r.jsxs)("div",{role:"button",tabIndex:0,"data-testid":"timer-row",onClick:()=>g(e),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),g(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:ah(e.scheduledSendTime)}),(0,r.jsx)("span",{className:"text-muted-foreground",children:ax(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")}),i.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)(ag,{isOpen:h,worktreeId:t,instances:n,onClose:()=>x(!1),onSaved:()=>{w()}}),(0,r.jsx)(ab,{timer:f,instances:l,onClose:()=>g(null)})]})}),ay=[{id:"notes",labelKey:"notes"},{id:"logs",labelKey:"logs"},{id:"agent",labelKey:"agentTab"},{id:"timer",labelKey:"timerTab"},{id:"todo",labelKey:"todoTab"}],aj=(0,o.memo)(function(e){let{worktreeId:t,className:n="",selectedAgents:a,onSelectedAgentsChange:s,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,maxAgents:m,availableAgents:h,persistToServer:x,onInsertToMessage:f,useInstanceManagement:g=!1,instances:p,onInstancesChange:b,visibleInstanceIds:v,onToggleInstanceVisible:y}=e,j=(0,c.c)("schedule"),[w,k]=(0,o.useState)("notes"),N=(0,o.useCallback)(e=>{k(e)},[]);return(0,r.jsxs)("div",{className:"flex flex-col h-full ".concat(n),children:[(0,r.jsx)("div",{className:"flex border-b border-border bg-surface dark:bg-surface-2 flex-shrink-0",children:ay.map(e=>(0,r.jsx)("button",{type:"button",onClick:()=>N(e.id),className:"flex-1 px-3 py-2 text-sm font-medium transition-colors ".concat(w===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:j(e.labelKey)},e.id))}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["notes"===w&&(0,r.jsx)(nE,{worktreeId:t,className:"h-full",onInsertToMessage:f}),"logs"===w&&(0,r.jsx)(n9,{worktreeId:t,className:"h-full",onInsertToMessage:f,instances:p}),"agent"===w&&(g&&p&&b&&v&&y?(0,r.jsx)("div",{className:"h-full overflow-y-auto",children:(0,r.jsx)(ao,{worktreeId:t,instances:p,onInstancesChange:b,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,visibleInstanceIds:v,onToggleInstanceVisible:y})}):(0,r.jsx)(ae,{worktreeId:t,selectedAgents:a,onSelectedAgentsChange:s,vibeLocalModel:l,onVibeLocalModelChange:i,vibeLocalContextWindow:d,onVibeLocalContextWindowChange:u,maxAgents:m,availableAgents:h,persistToServer:x})),"timer"===w&&(0,r.jsx)(av,{worktreeId:t,instances:p,selectedAgents:a}),"todo"===w&&(0,r.jsx)(nP,{worktreeId:t,className:"h-full"})]})]})});var aw=n(2317);let ak=["status","changes","history","advanced"],aN="commandmate:gitPane:",aC={activeTab:"".concat(aN,"activeTab"),historyOpen:"".concat(aN,"historyOpen"),advancedOpen:"".concat(aN,"advancedOpen")};function aS(e){return"string"==typeof e&&ak.includes(e)}let aT=e=>"boolean"==typeof e,aE=(0,o.memo)(function(e){let{branches:t,busy:n,actionError:a,hasRunningSession:s,isMobile:l,onCheckout:i}=e,d=(0,c.c)("worktree"),u=(0,c.c)("common"),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(!1),v=t.filter(e=>!e.isCurrent),y=(0,o.useCallback)(e=>{b(!1),g({...e}),x(!1)},[]),j=(0,o.useCallback)(()=>{f&&(i(f,p),g(null))},[f,p,i]);return(0,r.jsxs)("div",{className:"relative","data-testid":"branch-checkout-dropdown",children:[(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:()=>x(e=>!e),disabled:n||0===v.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":h,"aria-label":d("git.checkout.ariaLabel"),children:[d("git.checkout.action"),(0,r.jsx)("span",{"aria-hidden":"true",className:"text-[10px]",children:"▾"})]}),h&&(0,r.jsx)("div",{className:"absolute left-0 top-full z-20 mt-1 min-w-[12rem] max-h-64 overflow-y-auto rounded border border-border bg-surface shadow-lg",role:"menu","data-testid":"branch-checkout-menu",children:0===v.length?(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:d("git.checkout.noBranches")}):(0,r.jsx)("ul",{className:"divide-y divide-border",children:v.map(e=>{var t;let a=null!==e.checkedOutWorktreePath;return(0,r.jsx)("li",{children:(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>y(e),disabled:n||a,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":d("git.checkout.checkoutBranch",{name:e.name}),title:a?d("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:d("git.checkout.defaultBadge")})]})},"".concat(e.isRemote?"r":"l",":").concat(e.name))})})}),a&&(0,r.jsx)("div",{className:"mt-1 text-xs text-danger-foreground",role:"alert","data-testid":"branch-checkout-error",children:a}),f&&(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:[d("git.checkout.confirmTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:f.name}),d("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:d("git.checkout.historyLossWarning")}),s&&(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:d("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:p,onCheckedChange:e=>b(!0===e),"data-testid":"branch-checkout-force"}),d("git.checkout.forceLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2 ".concat(l?"flex-wrap":""),children:[(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>g(null),className:"px-3 py-1 text-xs rounded border border-input text-foreground hover:bg-muted",children:u("cancel")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:j,disabled:n,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:d("git.checkout.action")})]})]})})]})}),aI=(0,o.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})]})}),aM=(0,o.createContext)(null);function aL(e){let{value:t,children:n}=e;return(0,r.jsx)(aM.Provider,{value:t,children:n})}function aA(){let e=(0,o.useContext)(aM);if(null===e)throw Error("useGitPaneContext must be used within a GitPaneProvider");return e}let aP=(0,o.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})})}),aR={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"},aD={status:"git.tabs.status",changes:"git.tabs.changes",history:"git.tabs.history",advanced:"git.tabs.advanced"},aF=(0,o.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:ak.map(e=>{let s=e===t,l=a(aD[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)(aP,{path:aR[e]}),(0,r.jsx)("span",{children:l})]},e)})})});function az(e){let{activeTab:t,onTabChange:n,className:a="",statusSection:s,quickActionsSection:l,changesSection:o,historySection:i,advancedSection:c}=e,{isMobile:d}=aA();return d?(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden ".concat(a),"data-testid":"git-pane-mobile",children:[(0,r.jsx)(aF,{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:o}),"history"===t&&i,"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,o]}),(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:i}),(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 aO={added:"text-success-foreground",modified:"text-warning-foreground",deleted:"text-danger-foreground",renamed:"text-info",untracked:"text-teal-600 dark:text-teal-400",unmerged:"text-warning-foreground"},a_=(0,o.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"})})}),aB=(0,o.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)(nR.A,{size:14,"aria-hidden":"true"}),l("git.askAi")]})}),aW=(0,o.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})}),aH=(0,o.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})}),aV=(0,o.memo)(function(e){let{gitStatus:t,statusLoading:n,statusError:a,onRefresh:s}=e,{isMobile:l}=aA(),o=(0,c.c)("worktree");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:o("git.currentStatus.title")}),(0,r.jsx)("button",{type:"button",onClick:s,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":o("git.currentStatus.refresh"),children:(0,r.jsx)(a_,{})})]}),n&&!t&&(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:o("git.currentStatus.loading")})]}),a&&!t&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-status-error",children:a}),t&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center flex-wrap ".concat(l?"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:t.currentBranch,children:t.currentBranch}),t.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:o("git.currentStatus.uncommitted")}),t.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:o("git.currentStatus.aheadTooltip"),children:["↑",t.aheadBehind.ahead]}),(0,r.jsxs)("span",{title:o("git.currentStatus.behindTooltip"),children:["↓",t.aheadBehind.behind]})]})]}),t.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:[o("branchMismatch.changedFrom")," ",(0,r.jsx)("span",{className:"font-medium",children:t.initialBranch})," ",o("branchMismatch.to")," ",(0,r.jsx)("span",{className:"font-medium",children:t.currentBranch})]})]})]})]})}),aU=(0,o.memo)(function(e){let{progressState:t,operation:n,error:a,conflict:s,conflictFiles:l,hasUpstream:i,onFetch:d,onPull:m,onPush:h,onAbort:x,extraActions:f}=e,{isMobile:g}=aA(),p=(0,c.c)("worktree"),b="running"===t,v=null!=a?a:p("git.network.failed"),[y,j]=(0,o.useState)(0);return(0,o.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:p("git.network.quickActions")}),(0,r.jsxs)("div",{className:"flex items-center ".concat(g?"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:p("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:p("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:i?void 0:p("git.network.noUpstreamTooltip"),children:p("git.network.push")}),f]}),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(g?"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:p("git.network.progress",{operation:p("push"===n?"git.network.pushing":"pull"===n?"git.network.pulling":"git.network.fetching"),elapsed:y})})]}),(0,r.jsx)("button",{type:"button",onClick:x,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:p("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:p("git.network.conflicts",{files:l.join(", ")})})]})}),aK=(0,o.memo)(function(e){let{title:t,testId:n,files:a,actionLabel:s,mode:l,defaultOpen:i,busy:d,onDiff:u,onToggleStage:h,onPreview:x}=e,f=(0,c.c)("worktree"),[g,p]=(0,o.useState)(i),[b,v]=(0,o.useState)(null),[y,j]=(0,o.useState)(null),[w,k]=(0,o.useState)(!1),[N,C]=(0,o.useState)(null),S=(0,o.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 x(e,l);j(null!=t?t:"")}catch(e){C(f("git.changes.previewFailed"))}finally{k(!1)}},[b,x,l,f]);return(0,r.jsxs)("div",{className:"border-t border-border","data-testid":n,children:[(0,r.jsxs)("button",{type:"button",onClick:()=>p(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:g?"▼":"▶"}),f("git.changes.listHeader",{title:t,count:a.length})]}),g&&0===a.length&&(0,r.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:f("git.changes.empty")}),g&&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(aO[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":f("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":f("git.changes.showDiff",{path:e.path}),"data-testid":"git-changes-diff-button",children:f("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":f("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:f("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:f("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)(aW,{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:f("git.changes.truncated")})]}))]})]},"".concat(e.status,":").concat(e.path))})})]})}),a$=(0,o.memo)(function(e){var t,n,a;let{staged:s,loading:l,error:o,busy:i,commitMessage:d,amend:u,committing:h,commitError:x,onRefresh:f,onDiff:g,onPreview:p,onStage:b,onUnstage:v,onCommitMessageChange:y,onAmendChange:j,onCommit:w,onCommitAndPush:k}=e,{isMobile:N}=aA(),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:[],E=null!=(a=null==s?void 0:s.untracked)?a:[],I=!h&&d.trim().length>0&&(S.length>0||u),M=!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:f,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":C("git.changes.refresh"),children:(0,r.jsx)(a_,{})})]}),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")})]}),o&&!s&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-changes-error",children:o}),s&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(aK,{title:C("git.changes.staged"),testId:"git-staged-list",files:S,actionLabel:C("git.changes.unstage"),mode:"staged",defaultOpen:M,busy:i,onDiff:g,onPreview:p,onToggleStage:v}),(0,r.jsx)(aK,{title:C("git.changes.unstaged"),testId:"git-unstaged-list",files:T,actionLabel:C("git.changes.stage"),mode:"unstaged",defaultOpen:M,busy:i,onDiff:g,onPreview:p,onToggleStage:b}),(0,r.jsx)(aK,{title:C("git.changes.untracked"),testId:"git-untracked-list",files:E,actionLabel:C("git.changes.stage"),mode:"untracked",defaultOpen:M,busy:i,onDiff:g,onPreview:p,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:!I,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:!I||i,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")})]})]}),x&&(0,r.jsx)("div",{className:"text-xs text-danger-foreground",role:"alert","data-testid":"git-commit-error",children:x})]})]})]})}),aq=(0,o.memo)(function(e){let{commits:t,isLoading:n,commitError:a,commitListOpen:s,onToggleCommitList:l,onRefresh:i,selectedCommit:d,onCommitSelect:m,inlineDiffCommit:h,inlineFiles:x,inlineFilesLoading:f,inlineFilesError:g,onToggleInlineDiff:p,onInlineDiffFile:b,changedFiles:v,isLoadingFiles:y,detailError:j,selectedFile:w,onFileSelect:k,diffContent:N,isLoadingDiff:C}=e,{isMobile:S}=aA(),T=(0,c.c)("worktree"),[E,I]=(0,o.useState)(!0),[M,L]=(0,o.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:i,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":T("git.history.refresh"),children:(0,r.jsx)(a_,{})})]}),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:()=>p(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:[f&&(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")})]}),g&&(0,r.jsx)(aH,{message:g}),!f&&!g&&0===x.length&&(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:T("git.history.noChangedFiles")}),!f&&x.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:x.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(aO[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:()=>I(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:E?"▼":"▶"}),T("git.history.changedFiles")]}),E&&(0,r.jsxs)(r.Fragment,{children:[j&&(0,r.jsx)(aH,{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(aO[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:()=>L(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:M?"▼":"▶"}),T("git.history.diffLabel",{file:w})]}),M&&(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)(aW,{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 aJ(e){return"`"+e+"`"}let aY={local:"git.branches.filterLocal",remote:"git.branches.filterRemote",all:"git.branches.filterAll"},aG=(0,o.memo)(function(e){let{branches:t,include:n,loading:a,error:s,busy:l,actionError:i,onIncludeChange:d,onRefresh:u,onCreate:h,onDelete:x}=e,{isMobile:f,onInsertToMessage:g}=aA(),p=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,o.useState)(!f),[j,w]=(0,o.useState)(!1),[k,N]=(0,o.useState)(""),[C,S]=(0,o.useState)(""),[T,E]=(0,o.useState)(null),[I,M]=(0,o.useState)(!1),L=(0,o.useCallback)(()=>{0!==k.trim().length&&(h(k.trim(),C.trim()||void 0),w(!1),N(""),S(""))},[k,C,h]),A=(0,o.useCallback)(()=>{T&&(x(T.name,I),E(null),M(!1))},[T,I,x]);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?"▼":"▶"}),p("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:p("git.branches.newButton")}),(0,r.jsx)("button",{type:"button",onClick:u,className:"p-1 text-muted-foreground hover:text-foreground rounded","aria-label":p("git.branches.refresh"),children:(0,r.jsx)(a_,{})})]})]}),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:p(aY[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:p("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}),i&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-danger-foreground",role:"alert","data-testid":"git-branches-action-error",children:i}),!a&&!s&&0===t.length&&(0,r.jsx)("div",{className:"px-3 pb-2 text-xs text-muted-foreground",children:p("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:p("git.branches.defaultBadge")})]}),(0,r.jsx)("button",{type:"button",onClick:()=>{M(!1),E(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":p("git.branches.deleteBranch",{name:e.name}),children:p("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:p("git.branches.createTitle")}),(0,r.jsx)("input",{type:"text",value:k,onChange:e=>N(e.target.value),placeholder:p("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":p("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":p("git.branches.baseLabel"),children:[(0,r.jsx)("option",{value:"",children:p("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:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"branch-create-ask-ai",disabled:0===k.trim().length,onClick:()=>{g(function(e,t,n){let a=n&&n.trim().length>0?aJ(n.trim()):e("git.aiPrompts.branchCreateBaseHead");return e("git.aiPrompts.branchCreate",{base:a,name:aJ(t.trim())})}(p,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:L,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:p("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:[p("git.branches.deleteTitlePrefix"),(0,r.jsx)("span",{className:"font-mono",children:T.name}),p("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:I,onCheckedChange:e=>M(!0===e),"data-testid":"branch-delete-force"}),p("git.branches.forceDeleteLabel")]}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[g&&T&&(0,r.jsx)(aB,{className:"mr-auto",testId:"branch-delete-ask-ai",onClick:()=>{g(p(I?"git.aiPrompts.branchDeleteForce":"git.aiPrompts.branchDelete",{name:aJ(T.name)})),E(null),M(!1)}}),(0,r.jsx)("button",{type:"button",onClick:()=>E(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:A,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:p("git.branches.delete")})]})]})})]})}),aX=(0,o.memo)(function(e){let{stashes:t,loading:n,error:a,busy:s,actionError:l,conflictNotice:i,hasRunningSession:d,onRefresh:u,onPush:h,onPop:x,onApply:f,onDrop:g}=e,{isMobile:p,onInsertToMessage:b}=aA(),v=(0,c.c)("worktree"),y=(0,c.c)("common"),[j,w]=(0,o.useState)(!p),[k,N]=(0,o.useState)(""),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.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)(aB,{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)(a_,{})})]})]}),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}),i&&(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:i}),b&&(0,r.jsx)(aB,{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,i))})]}),(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:()=>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-apply-button",children:v("git.stash.apply")}),(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-pop-button",children:v("git.stash.pop")}),(0,r.jsx)("button",{type:"button",disabled:s,onClick:()=>E(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:()=>{g(T),E(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:()=>E(null),className:"px-2 py-1 text-xs rounded border border-input hover:bg-muted",children:y("cancel")})]})]})]})}),aQ={soft:"git.danger.modeSoft",mixed:"git.danger.modeMixed",hard:"git.danger.modeHard"},aZ=(0,o.memo)(function(e){let{selectedCommit:t,busy:n,actionError:a,conflictNotice:s,currentBranch:l,aheadCount:i,hasRunningSession:d,onReset:u,onRevert:h,onForcePush:x}=e,{isMobile:f,onInsertToMessage:g}=aA(),p=(0,c.c)("worktree"),b=(0,c.c)("common"),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)("mixed"),[k,N]=(0,o.useState)(!0),[C,S]=(0,o.useState)(""),[T,E]=(0,o.useState)(!1),[I,M]=(0,o.useState)(!1),[L,A]=(0,o.useState)(!1),[P,R]=(0,o.useState)(!1),[D,F]=(0,o.useState)(!0),z=k?"HEAD":t,O=!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?"▼":"▶"}),p("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(f?"flex-col":"flex-row"," gap-2"),children:[(0,r.jsx)("button",{type:"button",onClick:()=>E(!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:p("git.danger.resetOpen")}),(0,r.jsx)("button",{type:"button",disabled:!t,onClick:()=>M(!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:p("git.danger.revertOpen")}),x&&(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>R(!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:p("git.danger.forcePushOpen")})]}),!t&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:p("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:p("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"}),p("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"}),p("git.danger.resetTargetSelectedPrefix"),t?p("git.danger.resetTargetSelectedHash",{hash:t.slice(0,7)}):p("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)}),p(aQ[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:p("git.danger.resetHardWarning")}),d&&(0,r.jsx)("p",{className:"text-xs text-danger-foreground","data-testid":"reset-hard-session-warning",children:p("git.danger.runningSessionWarning")}),(0,r.jsx)("input",{type:"text",value:C,onChange:e=>S(e.target.value),placeholder:p("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:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"reset-ask-ai",disabled:O,onClick:()=>{z&&(g("hard"===j?p("git.aiPrompts.resetHard",{target:aJ(z)}):p("git.aiPrompts.reset",{target:aJ(z),mode:j})),E(!1),S(""))}}),(0,r.jsx)("button",{type:"button",disabled:n||O||"hard"===j&&C!==(null!=l?l:""),onClick:()=>{z&&(u(z,j,"hard"===j?C:void 0),E(!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:p("git.danger.reset")}),(0,r.jsx)("button",{type:"button",onClick:()=>{E(!1),S("")},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),I&&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:p("git.danger.revertTitle")}),(0,r.jsxs)("p",{className:"text-xs text-foreground mb-2",children:[p("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:p("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:L,onCheckedChange:e=>A(!0===e),"data-testid":"revert-no-commit"}),p("git.danger.revertNoCommit")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"revert-ask-ai",onClick:()=>{g(p("git.aiPrompts.revert",{commit:aJ(t.slice(0,7))})),M(!1),A(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{h(t,L),M(!1),A(!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:p("git.danger.revert")}),(0,r.jsx)("button",{type:"button",onClick:()=>{M(!1),A(!1)},className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]}),P&&x&&(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:p("git.danger.forcePushTitle")}),(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-protected-branch-warning",children:p("git.danger.protectedBranchWarning")}),d&&(0,r.jsx)("p",{className:"mb-2 text-xs text-danger-foreground","data-testid":"force-push-session-warning",children:p("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"}),p("git.danger.forceWithLease")]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[g&&(0,r.jsx)(aB,{className:"mr-auto",testId:"force-push-ask-ai",onClick:()=>{g(function(e,t){let{branch:n,ahead:a}=t,r=n?aJ(n):e("git.aiPrompts.forcePushCurrentBranch");return e("number"==typeof a&&a>0?"git.aiPrompts.forcePushAhead":"git.aiPrompts.forcePush",{branchRef:r,upstream:aJ("origin/".concat(null!=n?n:"<branch>")),ahead:null!=a?a:0})}(p,{branch:l,ahead:null!=i?i:null})),R(!1)}}),(0,r.jsx)("button",{type:"button",disabled:n,onClick:()=>{x(D),R(!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:p("git.danger.forcePush")}),(0,r.jsx)("button",{type:"button",onClick:()=>R(!1),className:"px-2 py-1 text-xs rounded border border-border hover:bg-muted",children:b("cancel")})]})]})]})}),a0=(0,o.memo)(function(e){var t,n,a,s;let{worktreeId:l,onDiffSelect:i,isMobile:d=!1,worktree:u,onInsertToMessage:h,className:x=""}=e,f=(0,c.c)("worktree"),{activeTab:g,setActiveTab:p,historyOpen:b,toggleHistory:v,advancedOpen:y,toggleAdvanced:j}=function(){let{value:e,setValue:t,isAvailable:n}=(0,aw.V)({key:aC.activeTab,defaultValue:"status",validate:aS}),{value:a,setValue:r}=(0,aw.V)({key:aC.historyOpen,defaultValue:!0,validate:aT}),{value:s,setValue:l}=(0,aw.V)({key:aC.advancedOpen,defaultValue:!1,validate:aT}),i=(0,o.useCallback)(e=>t(e),[t]);return{activeTab:e,setActiveTab:i,historyOpen:a,toggleHistory:(0,o.useCallback)(()=>r(e=>!e),[r]),advancedOpen:s,toggleAdvanced:(0,o.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,o.useState)(null),[a,r]=(0,o.useState)(!0),[s,l]=(0,o.useState)(null),i=(0,o.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,o.useEffect)(()=>{i()},[i]),{gitStatus:t,statusLoading:a,statusError:s,fetchStatus:i}}(l),{commits:T,selectedCommit:E,changedFiles:I,inlineDiffCommit:M,inlineFiles:L,inlineFilesLoading:A,inlineFilesError:P,selectedFile:R,diffContent:D,isLoading:F,isLoadingFiles:z,isLoadingDiff:O,commitError:_,detailError:B,setDiffContent:W,fetchCommits:H,handleCommitSelect:V,handleFileSelect:U,handleToggleInlineDiff:K,handleInlineDiffFile:$,handleRefresh:q}=function(e,t){let[n,a]=(0,o.useState)([]),[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)([]),[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)([]),[h,x]=(0,o.useState)(!1),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(null),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)(!0),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),[T,E]=(0,o.useState)(null),[I,M]=(0,o.useState)(null),L=(0,o.useCallback)(async()=>{w(!0),E(null);try{let t=await fetch("/api/worktrees/".concat(e,"/git/log"));if(!t.ok){let e=await t.json();E(e.error||"Failed to fetch commit history");return}let n=await t.json();a(n.commits)}catch(e){E("Failed to fetch commit history")}finally{w(!1)}},[e]),A=(0,o.useCallback)(async t=>{N(!0),i([]),b(null),y(null),M(null);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json();M(e.error||"Failed to fetch commit details");return}let a=await n.json();i(a.files)}catch(e){M("Failed to fetch commit details")}finally{N(!1)}},[e]),P=(0,o.useCallback)(async(n,a)=>{S(!0),y(null),M(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();M(e.error||"Failed to fetch diff");return}let s=await r.json();y(s.diff),t(s.diff,a)}catch(e){M("Failed to fetch diff")}finally{S(!1)}},[e,t]);(0,o.useEffect)(()=>{L()},[L]);let R=(0,o.useCallback)(e=>{s(e),A(e)},[A]),D=(0,o.useCallback)(e=>{r&&(b(e),P(r,e))},[r,P]),F=(0,o.useCallback)(async t=>{if(c===t){d(null),m([]),g(null);return}d(t),m([]),g(null),x(!0);try{let n=await fetch("/api/worktrees/".concat(e,"/git/show/").concat(t));if(!n.ok){let e=await n.json().catch(()=>({}));g(e.error||"Failed to fetch commit details");return}let a=await n.json();m(Array.isArray(a.files)?a.files:[])}catch(e){g("Failed to fetch commit details")}finally{x(!1)}},[e,c]),z=(0,o.useCallback)((e,t)=>{s(e),b(t),i(u),P(e,t)},[u,P]),O=(0,o.useCallback)(()=>{s(null),i([]),b(null),y(null),M(null),L()},[L]);return{commits:n,selectedCommit:r,changedFiles:l,inlineDiffCommit:c,inlineFiles:u,inlineFilesLoading:h,inlineFilesError:f,selectedFile:p,diffContent:v,isLoading:j,isLoadingFiles:k,isLoadingDiff:C,commitError:T,detailError:I,setDiffContent:y,fetchCommits:L,handleCommitSelect:R,handleFileSelect:D,handleToggleInlineDiff:F,handleInlineDiffFile:z,handleRefresh:O}}(l,i),J=(0,o.useCallback)(async()=>{await H(),await S()},[H,S]),{staged:Y,stagedLoading:G,stagedError:X,opBusy:Q,commitMessage:Z,setCommitMessage:ee,amend:et,setAmend:en,committing:ea,changesCommitError:er,fetchStaged:es,handleStage:el,handleUnstage:eo,handleChangesDiff:ei,fetchWorkingDiffText:ec,commit:ed,commitAndPush:eu}=function(e,t){let{onWorkingDiff:n,onCommitted:a}=t,[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)(!0),[c,d]=(0,o.useState)(null),[u,m]=(0,o.useState)(!1),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(!1),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null),j=(0,o.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{i(!1)}},[e]);(0,o.useEffect)(()=>{j()},[j]);let w=(0,o.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,o.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,o.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:f})});if(!t.ok){let e=await t.json().catch(()=>({}));return y(e.error||"Failed to commit"),!1}return x(""),g(!1),await j(),await a(),!0}catch(e){return y("Failed to commit"),!1}},[e,h,f,j,a]),C=(0,o.useCallback)(async()=>{b(!0);try{await N()}finally{b(!1)}},[N]),S=(0,o.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:x,amend:f,setAmend:g,committing:p,changesCommitError:v,fetchStaged:j,handleStage:w,handleUnstage:k,handleChangesDiff:(0,o.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,o.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,o.useCallback)((e,t)=>{W(e),i(e,t)},[W,i]),onCommitted:J}),{branches:em,branchInclude:eh,branchesLoading:ex,branchesError:ef,branchBusy:eg,branchActionError:ep,fetchBranches:eb,handleBranchIncludeChange:ev,handleBranchesRefresh:ey,handleCheckout:ej,handleBranchCreate:ew,handleBranchDelete:ek}=function(e,t){let{onCheckoutCascade:n}=t,[a,r]=(0,o.useState)([]),[s,l]=(0,o.useState)("local"),[i,c]=(0,o.useState)(!0),[d,u]=(0,o.useState)(null),[m,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)(null),g=(0,o.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,o.useEffect)(()=>{g(s)},[g,s]);let p=(0,o.useCallback)(e=>{l(e)},[]),b=(0,o.useCallback)(()=>{g(s)},[g,s]),v=(0,o.useCallback)(async(t,a)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to checkout branch");return}await Promise.all([n(),g(s)])}catch(e){f("Failed to checkout branch")}finally{h(!1)}},[e,s,n,g]),y=(0,o.useCallback)(async(t,n)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to create branch");return}await g(s)}catch(e){f("Failed to create branch")}finally{h(!1)}},[e,s,g]),j=(0,o.useCallback)(async(t,n)=>{h(!0),f(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(()=>({}));f(e.error||"Failed to delete branch");return}await g(s)}catch(e){f("Failed to delete branch")}finally{h(!1)}},[e,s,g]);return{branches:a,branchInclude:s,branchesLoading:i,branchesError:d,branchBusy:m,branchActionError:x,fetchBranches:g,handleBranchIncludeChange:p,handleBranchesRefresh:b,handleCheckout:v,handleBranchCreate:y,handleBranchDelete:j}}(l,{onCheckoutCascade:(0,o.useCallback)(async()=>{await Promise.all([S(),es(),H()])},[S,es,H])}),{stashes:eN,stashLoading:eC,stashError:eS,stashBusy:eT,stashActionError:eE,stashConflictNotice:eI,fetchStash:eM,handleStashPush:eL,handleStashPop:eA,handleStashApply:eP,handleStashDrop:eR}=function(e,t){let{onStashMutated:n}=t,[a,r]=(0,o.useState)([]),[s,l]=(0,o.useState)(!0),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(!1),[m,h]=(0,o.useState)(null),[x,f]=(0,o.useState)(null),g=(0,o.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,o.useEffect)(()=>{g()},[g]);let p=(0,o.useCallback)(async()=>{await Promise.all([g(),n()])},[g,n]),b=(0,o.useCallback)(async(e,t,n)=>{u(!0),h(null),f(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)":"";f("Stash operation produced conflicts: ".concat(e).concat(t))}await p()}catch(e){h(n)}finally{u(!1)}},[p]),v=(0,o.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,o.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:i,stashBusy:d,stashActionError:m,stashConflictNotice:x,fetchStash:g,handleStashPush:v,handleStashPop:y,handleStashApply:(0,o.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,o.useCallback)(t=>{b("/api/worktrees/".concat(e,"/git/stash/").concat(t),{method:"DELETE"},"Failed to drop stash")},[e,b])}}(l,{onStashMutated:(0,o.useCallback)(async()=>{await Promise.all([S(),es()])},[S,es])}),{dangerBusy:eD,dangerActionError:eF,dangerConflictNotice:ez,handleReset:eO,handleRevert:e_}=function(e,t){let{onHeadMoved:n}=t,[a,r]=(0,o.useState)(!1),[s,l]=(0,o.useState)(null),[i,c]=(0,o.useState)(null);return{dangerBusy:a,dangerActionError:s,dangerConflictNotice:i,handleReset:(0,o.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,o.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,o.useCallback)(async()=>{await Promise.all([S(),es(),eb(eh),H()])},[S,es,eb,eh,H])}),{operation:eB,progressState:eW,error:eH,errorReason:eV,conflict:eU,conflictFiles:eK,runFetch:e$,runPull:eq,runPush:eJ,abort:eY}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{onCascade:n}=t,[a,r]=(0,o.useState)(null),[s,l]=(0,o.useState)("idle"),[i,c]=(0,o.useState)(null),[d,u]=(0,o.useState)(null),[m,h]=(0,o.useState)(!1),[x,f]=(0,o.useState)([]),g=(0,o.useRef)(null),p=(0,o.useRef)(n);(0,o.useEffect)(()=>{p.current=n},[n]),(0,o.useEffect)(()=>()=>{var e;null==(e=g.current)||e.abort()},[]);let b=(0,o.useCallback)(async(t,n,a)=>{var s,o,i;c(null),u(null),h(!1),f([]),r(t),l("running");let d=new AbortController;g.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((o=null==e?void 0:e.error,"string"==typeof o&&o.length>0?o:null)),l("error");return}let i=await r.json().catch(()=>({success:!0}));"pull"===t&&(null==i?void 0:i.conflict)&&(h(!0),f(Array.isArray(i.conflictFiles)?i.conflictFiles:[])),l("idle")}catch(e){e instanceof Error&&"AbortError"===e.name?l("idle"):(c(null),u(null),l("error"))}finally{r(null),g.current=null,null==(i=p.current)||i.call(p,t)}},[e]),v=(0,o.useCallback)(e=>{let t={prune:!0===e.prune};return void 0!==e.remote&&(t.remote=e.remote),b("fetch","fetch",t)},[b]),y=(0,o.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:i,errorReason:d,conflict:m,conflictFiles:x,runFetch:v,runPull:y,runPush:(0,o.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,o.useCallback)(()=>{var e;null==(e=g.current)||e.abort()},[])}}(l,{onCascade:(0,o.useCallback)(e=>{S(),eb(eh),"pull"===e&&(es(),H())},[S,eb,eh,es,H])}),eG="auth_failed"===eV?f("git.network.authFailedGuidance"):"protected_branch"===eV?f("git.danger.protectedBranchWarning"):eH,eX="running"===eW&&("push"===eB||"pull"===eB),eQ=(null==k?void 0:k.aheadBehind)!=null,eZ=(0,o.useCallback)(()=>eu(()=>eJ({setUpstream:!eQ})),[eu,eJ,eQ]);nh({intervalMs:5e3,enabled:"running"!==eW,onPoll:S});let e0=(0,o.useMemo)(()=>({isMobile:d,onDiffSelect:i,onInsertToMessage:h}),[d,i,h]),e1=(0,r.jsx)(aV,{gitStatus:k,statusLoading:N,statusError:C,onRefresh:S}),e2=(0,r.jsx)(aU,{progressState:eW,operation:eB,error:eG,conflict:eU,conflictFiles:eK,hasUpstream:eQ,onPull:()=>eq({}),onPush:()=>eJ({setUpstream:!eQ}),onAbort:eY,extraActions:(0,r.jsx)(aE,{branches:em,busy:eg||eX,actionError:ep,hasRunningSession:w,isMobile:d,onCheckout:ej})}),e4=(0,r.jsx)(a$,{staged:Y,loading:G,error:X,busy:Q||eX,commitMessage:Z,amend:et,committing:ea,commitError:er,onRefresh:es,onDiff:ei,onPreview:ec,onStage:el,onUnstage:eo,onCommitMessageChange:ee,onAmendChange:en,onCommit:ed,onCommitAndPush:eZ}),e5=(0,r.jsx)(aq,{commits:T,isLoading:F,commitError:_,commitListOpen:b,onToggleCommitList:v,onRefresh:q,selectedCommit:E,onCommitSelect:V,inlineDiffCommit:M,inlineFiles:L,inlineFilesLoading:A,inlineFilesError:P,onToggleInlineDiff:K,onInlineDiffFile:$,changedFiles:I,isLoadingFiles:z,detailError:B,selectedFile:R,onFileSelect:U,diffContent:D,isLoadingDiff:O}),e3=(0,r.jsxs)(aI,{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:f("git.remote")}),(0,r.jsx)("div",{children:(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:()=>e$({}),disabled:"running"===eW,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:f("git.network.fetch")})})]}),(0,r.jsx)(aG,{branches:em,include:eh,loading:ex,error:ef,busy:eg||eX,actionError:ep,onIncludeChange:ev,onRefresh:ey,onCreate:ew,onDelete:ek}),(0,r.jsx)(aX,{stashes:eN,loading:eC,error:eS,busy:eT||eX,actionError:eE,conflictNotice:eI,hasRunningSession:w,onRefresh:eM,onPush:eL,onPop:eA,onApply:eP,onDrop:eR}),(0,r.jsx)(aZ,{selectedCommit:E,busy:eD||eX,actionError:eF,conflictNotice:ez,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:eO,onRevert:e_,onForcePush:e=>eJ(e?{forceWithLease:!0}:{force:!0})})]});return(0,r.jsx)(aL,{value:e0,children:(0,r.jsx)(az,{activeTab:g,onTabChange:p,className:x,statusSection:e1,quickActionsSection:e2,changesSection:e4,historySection:e5,advancedSection:e3})})}),a1=(0,o.memo)(function(e){let{worktreeId:t,worktree:n,onWorktreeUpdate:a}=e,[s,l]=(0,o.useState)(!1),i=(0,c.c)("worktree"),d=(0,o.useRef)(null==n?void 0:n.id),u=(0,o.useRef)(!1),m=a6(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)(a8,{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:i("detail.loadingInfo")})}),a2=(0,o.memo)(function(e){let{worktreeId:t,cliToolId:n,instanceId:a,disableAutoFollow:s}=e,{terminal:l,setAutoScroll:o}=tu({worktreeId:t,cliToolId:n,instanceId:a});return(0,r.jsx)(tc,{output:l.output,isActive:l.isRunning,isThinking:l.isThinking,autoScroll:l.autoScroll,onScrollChange:o,disableAutoFollow:s,compactTuiLayoutPadding:"claude"===n||"codex"===n,className:"h-full"})}),a4=(0,o.memo)(function(e){let{activeTab:t,worktreeId:n,worktree:a,messages:s,cliToolId:l,instanceId:o,onFilePathClick:i,onFileSelect:d,onWorktreeUpdate:u,onNewFile:m,onNewDirectory:h,onRename:x,onDelete:f,onUpload:g,onMove:p,onFileTreeReset:b,refreshTrigger:v,fileSearch:y,showToast:j,selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:T,vibeLocalModel:E,onVibeLocalModelChange:I,vibeLocalContextWindow:M,onVibeLocalContextWindowChange:L,disableAutoFollow:A,historySubTab:P,onHistorySubTabChange:R,onDiffSelect:D,onInsertToMessage:F,showArchived:z,onShowArchivedChange:O,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:W,onHistoryUserOnlyChange:H,useInstanceManagement:V,instances:U,onInstancesChange:K,visibleInstanceIds:$,onToggleInstanceVisible:q}=e,J=(0,c.c)("worktree");switch(t){case"terminal":return(0,r.jsx)(S,{componentName:"TerminalDisplay",children:(0,r.jsx)(a2,{worktreeId:n,cliToolId:l,instanceId:o,disableAutoFollow:A})});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:()=>R("message"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("message"===P?"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:J("detail.subTabMessage")}),(0,r.jsx)("button",{type:"button",onClick:()=>R("git"),className:"flex-1 min-h-[44px] px-3 py-1.5 text-xs font-medium transition-colors touch-manipulation ".concat("git"===P?"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:J("detail.subTabGit")})]}),"message"===P?(0,r.jsx)(S,{componentName:"HistoryPane",children:(0,r.jsx)(t1,{messages:s,worktreeId:n,onFilePathClick:i,className:"flex-1 min-h-0",showToast:j,onInsertToMessage:F,showArchived:z,onShowArchivedChange:O,historyDisplayLimit:_,onHistoryDisplayLimitChange:B,historyUserOnly:W,onHistoryUserOnlyChange:H})}):(0,r.jsx)(S,{componentName:"GitPane",children:(0,r.jsx)(a0,{worktreeId:n,onDiffSelect:D,isMobile:!0,worktree:null!=a?a:void 0,onInsertToMessage:F,className:"flex-1 min-h-0"})})]});case"files":var Y;return(0,r.jsx)(S,{componentName:"FileTreeView",children:(0,r.jsxs)("div",{className:"h-full flex flex-col overflow-hidden",children:[(0,r.jsx)(nj,{query:y.query,mode:y.mode,isSearching:y.isSearching,error:y.error,onQueryChange:y.setQuery,onModeChange:y.setMode,onClear:y.clearSearch}),(0,r.jsx)(np,{worktreeId:n,onFileSelect:d,onNewFile:m,onNewDirectory:h,onRename:x,onDelete:f,onUpload:g,onMove:p,onResetView:b,refreshTrigger:v,pollingEnabled:"files"===t,searchQuery:y.query,searchMode:y.mode,searchResults:null==(Y=y.results)?void 0:Y.results,className:"flex-1 min-h-0"})]})});case"memo":return(0,r.jsx)(S,{componentName:"NotesAndLogsPane",children:(0,r.jsx)(aj,{worktreeId:n,className:"h-full",selectedAgents:w,onSelectedAgentsChange:k,availableAgents:N,maxAgents:C,persistToServer:T,vibeLocalModel:E,onVibeLocalModelChange:I,vibeLocalContextWindow:M,onVibeLocalContextWindowChange:L,onInsertToMessage:F,useInstanceManagement:V,instances:U,onInstancesChange:K,visibleInstanceIds:$,onToggleInstanceVisible:q})});case"info":return(0,r.jsx)(a1,{worktreeId:n,worktree:a,onWorktreeUpdate:u});default:return null}}),a5="v".concat("0.10.2"),a3=[{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 a6(e,t,n,a){let[r,s]=(0,o.useState)(!1),[l,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(!1);(0,o.useEffect)(()=>{a()&&e&&(i(e.description||""),s(!1))},[n,e]);let u=(0,o.useCallback)(async()=>{if(e){d(!0);try{let n=await B.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,o.useCallback)(()=>{i((null==e?void 0:e.description)||""),s(!1)},[e]);return{isEditing:r,text:l,setText:i,isSaving:c,handleSave:u,handleCancel:m,startEditing:(0,o.useCallback)(()=>{s(!0)},[])}}let a8=(0,o.memo)(function(e){var t,n;let{worktreeId:a,worktree:s,cardClassName:l,descriptionEditor:i,showLogs:d,onToggleLogs:u,onWorktreeUpdate:h}=e,{isEditing:x,text:f,setText:g,isSaving:p,handleSave:b,handleCancel:v,startEditing:y}=i,j=(0,c.c)("worktree"),w=(0,c.c)("common"),[k,N]=(0,o.useState)(!1),[C,S]=(0,o.useState)(!1),T=(0,o.useRef)(void 0),E=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>{T.current&&clearTimeout(T.current),E.current&&clearTimeout(E.current)},[]);let I=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s.path),N(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>N(!1),et.pX)}catch(e){}},[s.path]),M=(0,o.useCallback)(async()=>{try{await (0,eu.l)(s.repositoryPath),S(!0),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>S(!1),et.pX)}catch(e){}},[s.repositoryPath]);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:M,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)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:I,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)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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:a3.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")}),!x&&(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")})]}),x?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("textarea",{value:f,onChange:e=>g(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:p,className:"px-4 py-2 bg-accent-600 text-white rounded-lg hover:bg-accent-700 disabled:opacity-50 text-sm font-medium",children:p?j("actions.saving"):j("actions.save")}),(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:v,disabled:p,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)(e$,{version:a5,className:l}),(0,r.jsx)(eZ,{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)(eW,{worktreeId:a})]})]})}),a9=(0,o.memo)(function(e){var t,n,a,s;let{worktreeName:l,repositoryName:i,description:d,status:u,gitStatus:f,onBackClick:g,onInfoClick:p,hasUpdate:b,worktreeStatus:v,onWorktreeStatusChange:y,sessionStatusByCli:j,sessionStatusByInstance:w,instances:N,activeInstanceId:C,onActiveInstanceChange:S,onAgentDragStart:T,onAgentDragEnd:E,onKillSession:I}=e,M=(0,c.c)("worktree"),L=(0,c.c)("common"),A=eF.sb[u],P=A?M(A):void 0,[R,D]=(0,o.useState)(null),F=null==N?void 0:N.find(e=>e.id===C),z=!!C&&null!=(s=null!=(a=null==w||null==(t=w[C])?void 0:t.isRunning)?a:F?null==j||null==(n=j[F.cliTool])?void 0:n.isRunning:void 0)&&s,O=(0,o.useCallback)((e,t)=>{e.dataTransfer.setData(e5,t),e.dataTransfer.effectAllowed="move",D(t),null==T||T(t)},[T]),_=(0,o.useCallback)(()=>{D(null),null==E||E()},[E]),B=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:g,className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors","aria-label":M("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:M("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:P}),(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:i}),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:M("git.uncommittedChanges"),children:"*"})]}),B&&(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:B})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[N&&N.length>0&&(()=>{var e,t,n,a;let s=(0,e_.Uw)(N.map(e=>{var t;return{item:e,status:(0,e1.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),o=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;return(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0","data-testid":"desktop-agent-status-row",children:[s.map(e=>{if("overflow"===e.slot)return null;let t=e.item,n=M("detail.statusPill",{label:(0,e2.sw)(t),status:L("status.".concat(e.status))}),a=e.isActive,s={draggable:!0,onDragStart:e=>O(e,t.id),onDragEnd:_},l=R===t.id?" opacity-50 cursor-grabbing":"";return"pill"===e.slot?(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-".concat(t.id),onClick:()=>null==S?void 0:S(t.id),...s,"aria-label":n,"aria-pressed":a,className:"flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ".concat(a?"bg-accent-100 dark:bg-accent-900/30 text-accent-900 dark:text-accent-100":"hover:bg-muted text-foreground").concat(l),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):(0,r.jsx)(ez.m_,{content:n,placement:"bottom",children:(0,r.jsx)("button",{type:"button","data-testid":"desktop-agent-status-".concat(t.id),onClick:()=>null==S?void 0:S(t.id),...s,"aria-label":n,"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 rounded-full transition-colors ".concat(a?"bg-accent-100 dark:bg-accent-900/30":"hover:bg-muted").concat(l),children:(0,r.jsx)(h.m,{status:e.status,size:"sm","aria-hidden":!0,title:void 0})})},t.id)}),l.length>0&&(0,r.jsxs)(eO.rI,{children:[(0,r.jsx)(eO.ty,{asChild:!0,children:(0,r.jsxs)("button",{type:"button","data-testid":"desktop-agent-status-overflow","aria-label":M("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:[o&&(0,r.jsx)(h.m,{status:o,size:"sm","aria-hidden":!0,title:void 0}),"+",l.length]})}),(0,r.jsx)(eO.SQ,{align:"end",children:l.map(e=>{let t=e.item,n=M("detail.statusPill",{label:(0,e2.sw)(t),status:L("status.".concat(e.status))});return(0,r.jsxs)(eO._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)})})]})]})})(),I&&z&&(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:I,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":M("terminal.endSession"),"data-testid":"desktop-kill-session",children:[(0,r.jsx)("span",{"aria-hidden":"true",children:"✕"}),L("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":M("detail.worktreeStatusLabel"),children:a3.map(e=>{var t;return(0,r.jsx)("option",{value:null!=(t=e.value)?t:"",children:M(e.labelKey)},e.labelKey)})}),(0,r.jsx)(e6.g,{}),(0,r.jsxs)(m.$n,{variant:"ghost",type:"button",onClick:p,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":M("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:M("detail.info")}),b&&(0,r.jsx)(k,{"data-testid":"info-update-indicator",className:"absolute top-0 right-0","aria-label":M("tabs.updateAvailable")})]})]})]})}),a7=(0,o.memo)(function(e){let{worktreeId:t,worktree:n,isOpen:a,onClose:s,onWorktreeUpdate:l}=e,[i,d]=(0,o.useState)(!1),u=(0,c.c)("worktree"),m=(0,o.useRef)(a),h=a6(n,l,a,()=>{let e=a&&!m.current;return m.current=a,e});return n?(0,r.jsx)(e0.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)(a8,{worktreeId:t,worktree:n,cardClassName:"bg-muted rounded-lg p-4",descriptionEditor:h,showLogs:i,onToggleLogs:()=>d(!i),onWorktreeUpdate:l})})}):null}),re=(0,o.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")})]})})}),rt=(0,o.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")})]})})}),rn=(0,o.memo)(function(e){let{activityPane:t,rightPane:n,activityPaneWidth:a=18,minPaneWidth:s=10,maxPaneWidth:l=60,onActivityPaneResize:i,className:d=""}=e,u=(0,o.useRef)(null),m=(0,c.c)("worktree"),[h,x]=(0,o.useState)(a),f=i?a:h,g=(0,o.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,(i?a:h)+e/n*100));i?i(r):x(r)},[a,h,s,l,i]),p=(0,o.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:p,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(f,"%")},className:"flex-shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",children:(0,r.jsx)(S,{componentName:"ActivityPane",children:t})}),(0,r.jsx)(tV.f,{onResize:g,orientation:"horizontal",ariaValueNow:f})]}),(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)(S,{componentName:"TerminalPane",children:n})})]})})});var ra=n(9540),rr=n(92001),rs=n(39332),rl=n(11047),ro=n(16485),ri=n(78192),rc=n(39324),rd=n(80298);let ru=[{id:"files",labelKey:"activityBar.files",icon:rr.A},{id:"git",labelKey:"activityBar.git",icon:rs.A},{id:"notes",labelKey:"activityBar.notes",icon:rl.A},{id:"schedules",labelKey:"activityBar.schedules",icon:ro.A},{id:"agent",labelKey:"activityBar.agent",icon:ri.A},{id:"timer",labelKey:"activityBar.timer",icon:rc.A},{id:"todo",labelKey:"activityBar.todo",icon:rd.A}],rm=new Set(ru.map(e=>e.id)),rh="files",rx="__closed__";function rf(e){return"".concat("commandmate.worktree.activeActivity-").concat(e)}var rg=n(32916);let rp=(0,o.memo)(function(e){let{active:t,onToggle:n,className:a=""}=e,s=(0,c.c)("worktree"),l=(0,o.useRef)([]),{isOpen:i,toggle:d}=(0,rg.VF)(),u=(0,o.useCallback)((e,t,a)=>{var r,s,o,i;if("Enter"===e.key||" "===e.key){e.preventDefault(),n(a);return}if("ArrowDown"===e.key){e.preventDefault();let n=(t+1)%ru.length;null==(r=l.current[n])||r.focus();return}if("ArrowUp"===e.key){e.preventDefault();let n=(t-1+ru.length)%ru.length;null==(s=l.current[n])||s.focus();return}if("Home"===e.key){e.preventDefault(),null==(o=l.current[0])||o.focus();return}if("End"===e.key){e.preventDefault(),null==(i=l.current[ru.length-1])||i.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)(ez.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":i,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)(ra.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:ru.map((e,a)=>{let o=e.icon,i=t===e.id,c=s(e.labelKey);return(0,r.jsx)(ez.m_,{content:c,placement:"right",children:(0,r.jsx)("button",{ref:e=>{l.current[a]=e},type:"button",role:"tab","aria-selected":i,"aria-label":c,"aria-controls":"worktree-activity-pane",tabIndex:i||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(i?"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)(o,{size:20,"aria-hidden":"true"})})})},e.id)})})]})}),rb="worktree-activity-pane",rv={files:"FileTreeView",git:"GitPane",notes:"MemoPane",schedules:"ExecutionLogPane",agent:"AgentSettingsPane",timer:"TimerPane",todo:"TodoPane"},ry=(0,o.memo)(function(e){let{active:t,activities:n,className:a=""}=e;if(null===t)return(0,r.jsx)("div",{id:rb,"data-testid":"activity-pane","data-active":"none",className:"h-full flex flex-col ".concat(a).trim()});let s=n[t],l=rv[t];return(0,r.jsx)("div",{id:rb,"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)(S,{componentName:l,children:null!=s?s:null})})}),rj=(0,o.memo)(function(e){let{inputRef:t,searchQuery:n,onQueryChange:a,matchCount:s,currentIdx:l,onNextMatch:o,onPrevMatch:i,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.shiftKey?i():o())},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: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.prevMatch"),children:"▲"}),(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.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)(em.A,{className:"w-4 h-4"})})]})}),rw=[{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"]}],rk=rw.map(e=>e.extension),rN=[".md",".html",".htm",".yaml",".yml"];ed.j6,ed.j6;var rC=n(40051);function rS(){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 rT=(0,i.default)(()=>n.e(530).then(n.bind(n,530)).then(e=>({default:e.HtmlPreview})),{loadableGenerated:{webpack:()=>[530]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rE=(0,i.default)(()=>Promise.resolve().then(n.bind(n,27307)).then(e=>({default:e.PdfPreview})),{loadableGenerated:{webpack:()=>[27307]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rI=(0,i.default)(()=>Promise.all([n.e(8566),n.e(934),n.e(6416),n.e(8676)]).then(n.bind(n,98676)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[98676]},ssr:!1,loading:()=>(0,r.jsx)(rS,{})}),rM=/^---\s*\nmarp:\s*true/;function rL(){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 rA(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 rP(e){let{filePath:t,isMaximized:n,onToggleMaximize:a,copyableContent:s,onSearch:l}=e,i=(0,c.c)("worktree"),[d,u]=(0,o.useState)(!1),[m,h]=(0,o.useState)(!1),x=(0,o.useRef)(null),f=(0,o.useRef)(null);(0,o.useEffect)(()=>()=>{x.current&&clearTimeout(x.current),f.current&&clearTimeout(f.current)},[]);let g=async()=>{try{await (0,eu.l)(t),u(!0),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>u(!1),et.pX)}catch(e){}},p=async()=>{if(s)try{await (0,eu.l)(s),h(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>h(!1),et.pX)}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:g,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:d?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ef.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)(z.A,{className:"w-3.5 h-3.5"})}),s&&(0,r.jsx)("button",{type:"button",onClick:p,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:m?(0,r.jsx)(ex.A,{className:"w-3.5 h-3.5 text-success"}):(0,r.jsx)(ep.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)(eb.A,{className:"w-4 h-4"}):(0,r.jsx)(ev.A,{className:"w-4 h-4"})})]})]})}function rR(e){var t;let{content:n,extension:a,searchMatches:s,searchCurrentIdx:l,totalLines:i,rangeStart:c,worktreeId:d,filePath:u,onLineRangeFetched:m}=e,h=(0,o.useRef)(null),x=(0,o.useMemo)(()=>n.split("\n"),[n]),f=Math.max(1,null!=c?c:1),g=x.length,p=Math.max(null!=i?i:g,g),b=(0,o.useRef)(new Map);(0,o.useEffect)(()=>{b.current.clear()},[n,a]);let v=(0,o.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,x.length),l=x.slice(e,t).join("\n"),o="";try{o=eM.A.highlight(l,{language:a,ignoreIllegals:!0}).value}catch(e){o=eM.A.highlightAuto(l).value}s=o.split("\n"),r.set(n,s)}return null!=(t=s[e-500*n])?t:""},[x,a]),y=(0,o.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,tm.Te)({count:p,getScrollElement:()=>h.current,estimateSize:()=>24,overscan:100});(0,o.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(p-1,e-1));w.scrollToIndex(t,{align:"center"})},[l,s,w,p]);let k=w.getVirtualItems();return!function(e){let{virtualItems:t,worktreeId:n,filePath:a,onLineRangeFetched:r,loadedStart:s,loadedLineCount:l}=e,i=(0,o.useRef)(new Set);(0,o.useEffect)(()=>{if(!n||!a||!r||0===t.length)return;let e=t[0].index+1,o=t[t.length-1].index+1,c=s+l-1;if(e>=s&&o<=c)return;let d=Math.max(1,500*Math.floor((e-1)/500)+1),u=d+500-1;i.current.has(d)||(i.current.add(d),fetch("/api/worktrees/".concat(n,"/files/").concat((0,ej.o)(a),"?startLine=").concat(d,"&endLine=").concat(u)).then(async e=>e.ok?e.json():null).then(e=>{i.current.delete(d),e&&!0===e.success&&r({content:e.content,range:e.range,totalLines:e.totalLines,totalBytes:e.totalBytes})}).catch(()=>{i.current.delete(d)}))},[t,n,a,r,s,l])}({virtualItems:k,worktreeId:d,filePath:u,onLineRangeFetched:m,loadedStart:f,loadedLineCount:g}),(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-f,a=n>=0&&n<g,s=t===j,l=y.has(t),o=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:o}}):(0,r.jsx)(rC.E,{className:"h-4 w-3/4"})})]},e.key)})})})}function rD(e){let{slides:t,fileName:n}=e,a=(0,c.c)("worktree"),[s,l]=(0,o.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 rF(e){let{marpSlides:t,fileName:n,worktreeId:a,filePath:s,contentText:l,onFileSaved:i,isMaximized:d,onToggleMaximize:u,onDirtyChange:m,onOpenFile:h}=e,x=(0,c.c)("worktree"),[f,g]=(0,o.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:()=>g("slides"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("slides"===f?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:x("fileViewer.slides")}),(0,r.jsx)("button",{type:"button",onClick:()=>g("editor"),className:"px-3 py-1 text-xs font-medium rounded-md transition-colors ".concat("editor"===f?"bg-accent-100 dark:bg-accent-900/50 text-accent-700 dark:text-accent-300":"text-muted-foreground hover:bg-muted"),children:x("fileViewer.editor")})]}),(0,r.jsx)(rP,{filePath:s,isMaximized:d,onToggleMaximize:u,copyableContent:l})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:"slides"===f?(0,r.jsx)(rD,{slides:t,fileName:n}):(0,r.jsx)(rI,{worktreeId:a,filePath:s,onSave:i,initialViewMode:"split",onDirtyChange:m,onOpenFile:h})})]})}function rz(e){let{children:t,isMaximized:n,onToggle:a,filePath:s}=e;return n?(0,r.jsxs)("div",{className:"fixed inset-0 bg-surface flex flex-col",style:{zIndex:ey.M.MAXIMIZED_EDITOR},children:[(0,r.jsx)(rP,{filePath:s,isMaximized:n,onToggleMaximize:a}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:t})]}):(0,r.jsx)(r.Fragment,{children:t})}function rO(e){let{tab:t,content:n,worktreeId:a,isMaximized:s,onToggleMaximize:l,onFileSaved:o,onDirtyChange:i,onOpenFile:c}=e,d=eI(n.content);return(0,r.jsxs)(r.Fragment,{children:[!s&&(0,r.jsx)(rP,{filePath:t.path,isMaximized:s,onToggleMaximize:l,copyableContent:n.content,onSearch:d.openSearch}),d.searchOpen&&(0,r.jsx)(rj,{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)(rR,{content:n.content,extension:"md",searchMatches:d.searchMatches,searchCurrentIdx:d.searchCurrentIdx}):(0,r.jsx)(rI,{worktreeId:a,filePath:t.path,onSave:o,initialViewMode:"preview",onDirtyChange:i,onOpenFile:c})})]})}function r_(e){var t,n;let{tab:a,content:s,worktreeId:l,isMaximized:i,onToggleMaximize:c,onLoadContent:d}=e,u=eI(s.content),m=(0,o.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)(rP,{filePath:a.path,isMaximized:i,onToggleMaximize:c,copyableContent:s.content,onSearch:u.openSearch}),u.searchOpen&&(0,r.jsx)(rj,{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)(rR,{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 rB=(0,o.memo)(function(e){var t,n,a,s;let{tab:l,worktreeId:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,onDirtyChange:x,onOpenFile:f}=e,g=(0,c.c)("worktree"),p=(0,o.useRef)(g);p.current=g;let b=(0,o.useRef)(!1),[v,y]=(0,o.useState)(null),[j,w]=(0,o.useState)(!1);!function(e){let{tab:t,worktreeId:n,onLoadContent:a}=e,r=(0,o.useRef)(null),s=(0,o.useRef)(a);s.current=a;let l=(0,o.useRef)(t.path);l.current=t.path,nh({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,ej.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:i,onLoadContent:d});let k=(0,o.useMemo)(()=>x?e=>x(l.path,e):void 0,[x,l.path]),N=(0,o.useCallback)(()=>{w(e=>!e)},[]);(0,o.useEffect)(()=>{if(!j)return;let e=e=>{"Escape"===e.key&&w(!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j]),(0,o.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(i,"/files/").concat((0,ej.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)||p.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:p.current("fileViewer.loadError"))}finally{b.current=!1}})())},[l.content,l.loading,l.error,l.path,i,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,o.useEffect)(()=>{if(!C||"md"!==S||!rM.test(C)||C.length>1e6)return void y(null);let e=!1;return(async()=>{try{let t=await fetch("/api/worktrees/".concat(i,"/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,i]),l.loading)return(0,r.jsx)(rL,{});if(l.error)return(0,r.jsx)(rA,{error:l.error});if(!l.content)return null;let{content:T}=l;return T.isImage?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(eo.a,{src:T.content,alt:T.path,mimeType:T.mimeType})})]})}):T.isVideo?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 overflow-auto",children:(0,r.jsx)(ei.u,{src:T.content,mimeType:T.mimeType})})]})}):T.isPdf?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(rE,{dataUri:T.content,filePath:l.path})})]})}):T.isHtml?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(rP,{filePath:l.path,isMaximized:j,onToggleMaximize:N,copyableContent:T.content}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(rT,{worktreeId:i,filePath:l.path,htmlContent:T.content,onFileSaved:h,onOpenFile:f})})]})}):"md"===T.extension?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:v?(0,r.jsx)(rF,{marpSlides:v,fileName:l.name,worktreeId:i,filePath:l.path,contentText:T.content,onFileSaved:h,isMaximized:j,onToggleMaximize:N,onDirtyChange:k,onOpenFile:f}):(0,r.jsx)(rO,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:f})})}):!function(e){if(!e)return!1;let t=e.toLowerCase();return rN.includes(t)}("."+T.extension)?(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)(r_,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onLoadContent:d})}):(0,r.jsx)(rz,{isMaximized:j,onToggle:N,filePath:l.path,children:(0,r.jsx)("div",{className:"h-full flex flex-col",children:(0,r.jsx)(rO,{tab:l,content:T,worktreeId:i,isMaximized:j,onToggleMaximize:N,onFileSaved:h,onDirtyChange:k,onOpenFile:f})})})}),rW=(0,o.memo)(function(e){let{tab:t,isActive:n,onActivate:a,onClose:s}=e,l=(0,c.c)("worktree"),i=(0,o.useCallback)(()=>{n||a(t.path)},[n,a,t.path]),d=(0,o.useCallback)(e=>{e.stopPropagation(),s(t.path)},[s,t.path]),u=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:i,className:"flex items-center gap-1 px-3 py-2 text-sm font-medium border-b-2 cursor-pointer flex-shrink-0 ".concat(u),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:l("fileTabs.unsavedChanges")}),(0,r.jsx)("button",{type:"button",onClick:d,className:"ml-1 p-0.5 rounded-sm hover:bg-muted transition-colors","aria-label":l("fileTabs.closeTab",{name:t.name}),children:(0,r.jsx)(em.A,{className:"w-3 h-3"})})]})}),rH=(0,o.memo)(function(e){let{tabs:t,activeIndex:n,worktreeId:a,onClose:s,onActivate:l,onLoadContent:i,onLoadError:c,onSetLoading:d,onFileSaved:u,onDirtyChange:m,onMoveToFront:h,onOpenFile:x}=e,[f,g]=(0,o.useState)(!1),p=(0,o.useRef)(null),b=null!==n&&n>=0&&n<t.length?t[n]:null,v=t.length>5?t.slice(0,5):t,y=t.length>5?t.slice(5):[];(0,o.useEffect)(()=>{if(!f)return;let e=e=>{p.current&&!p.current.contains(e.target)&&g(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[f]);let j=(0,o.useCallback)(e=>{g(!1),null==h||h(e)},[h]),w=(0,o.useCallback)(()=>{g(e=>!e)},[]);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:v.map((e,t)=>(0,r.jsx)(rW,{tab:e,isActive:t===n,onActivate:l,onClose:s},e.path))}),y.length>0&&(0,r.jsxs)("div",{className:"relative flex-shrink-0",ref:p,children:[(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-button",onClick:w,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)(e4.A,{className:"w-3 h-3 transition-transform ".concat(f?"rotate-180":"")}),(0,r.jsxs)("span",{children:["+",y.length]})]}),f&&(0,r.jsx)("div",{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",children:y.map(e=>(0,r.jsxs)("button",{type:"button","data-testid":"tab-dropdown-item-".concat(e.path),onClick:()=>j(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))})]})]}),(0,r.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:b&&(0,r.jsx)(rB,{tab:b,worktreeId:a,onLoadContent:i,onLoadError:c,onSetLoading:d,onFileSaved:u,onDirtyChange:m,onOpenFile:x},b.path)})]})}),rV=(0,o.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})}),rU=(0,o.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)(rV,{line:e},t))})})})]})}),rK="commandmate.worktree.filePanelCollapsed",r$="commandmate:filePanelStateChange";function rq(){let[e,t]=(0,o.useState)(!1),n=(0,o.useRef)(e);n.current=e,(0,o.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(rK);if("true"===e)return!0}catch(e){}return!1}())},[]),(0,o.useEffect)(()=>{let e=e=>{e.detail&&e.detail.collapsed!==n.current&&t(e.detail.collapsed)};return window.addEventListener(r$,e),()=>window.removeEventListener(r$,e)},[]);let a=(0,o.useCallback)(e=>{t(e);try{window.localStorage.setItem(rK,String(e))}catch(e){}try{window.dispatchEvent(new CustomEvent(r$,{detail:{collapsed:e}}))}catch(e){}},[]);return{collapsed:e,toggle:(0,o.useCallback)(()=>{a(!n.current)},[a]),setCollapsed:a}}let rJ=(0,o.memo)(function(e){let{terminal:t,terminalHeader:n,fileTabs:a,worktreeId:s,onCloseTab:l,onActivateTab:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,diffContent:x,diffFilePath:f,onCloseDiff:g,onDirtyChange:p,onMoveToFront:b,onOpenFile:v}=e,y=(0,c.c)("worktree"),j=(0,o.useRef)(null),[w,k]=(0,o.useState)(50),{collapsed:N,toggle:C}=rq(),S=(0,o.useCallback)(e=>{let t=j.current;if(!t)return;let n=t.offsetWidth;if(0===n)return;let a=e/n*100;k(e=>Math.min(80,Math.max(20,e+a)))},[]),T=(0,o.useMemo)(()=>({width:"".concat(w,"%")}),[w]),E=(0,o.useMemo)(()=>({width:"".concat(100-w,"%")}),[w]),I=(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||x&&f?N?(0,r.jsxs)("div",{ref:j,className:"flex h-full min-h-0",children:[(0,r.jsx)("div",{"data-testid":"terminal-pane",style:{width:"calc(100% - ".concat(36,"px)")},className:"flex-shrink-0 overflow-hidden",children:I}),(0,r.jsx)("div",{"data-testid":"file-panel-expand-bar",style:{width:"".concat(36,"px")},className:"flex-shrink-0 flex items-start justify-center bg-muted border-l border-border",children:(0,r.jsxs)("button",{type:"button","aria-label":y("terminal.showFiles"),title:y("terminal.showFiles"),onClick:C,className:"flex flex-col items-center gap-2 w-full pt-2 text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:y("terminal.filesLabel")})]})})]}):(0,r.jsxs)("div",{ref:j,className:"flex h-full min-h-0",children:[(0,r.jsx)("div",{"data-testid":"terminal-pane",style:T,className:"flex-shrink-0 overflow-hidden",children:I}),(0,r.jsx)(tV.f,{onResize:S,orientation:"horizontal",ariaValueNow:w}),(0,r.jsxs)("div",{"data-testid":"file-panel-pane",style:E,className:"flex-grow overflow-hidden flex",children:[(0,r.jsx)("button",{type:"button","aria-label":y("terminal.hideFiles"),title:y("terminal.hideFiles"),onClick:C,className:"flex-shrink-0 flex items-center justify-center w-5 h-full bg-muted border-r border-border text-muted-foreground hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",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:"M9 5l7 7-7 7"})})}),(0,r.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:x&&f&&g?(0,r.jsx)(rU,{diff:x,filePath:f,onClose:g}):(0,r.jsx)(rH,{tabs:a.tabs,activeIndex:a.activeIndex,worktreeId:s,onClose:l,onActivate:i,onLoadContent:d,onLoadError:u,onSetLoading:m,onFileSaved:h,onDirtyChange:p,onMoveToFront:b,onOpenFile:v})})]})]}):(0,r.jsx)("div",{className:"h-full",children:I})});var rY=n(7125),rG=n(22509),rX=n(54485),rQ=n(70198);let rZ={splits:[{cliToolId:"claude",instanceId:"claude"}],widths:[1]},r0=new Set(e2.XH);function r1(e){return"".concat("commandmate:terminalSplits:").concat(e)}function r2(e){return"object"==typeof e&&null!==e}function r4(e){let t=e[0];return t?{splits:[{cliToolId:t.cliTool,instanceId:t.id}],widths:[1]}:{splits:rZ.splits.map(e=>({...e})),widths:[...rZ.widths]}}function r5(e){let t=e.reduce((e,t)=>e+t,0);return t>0?e.map(e=>e/t):e.map(()=>1/e.length)}function r3(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,3),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?r5(e.widths):l.length<e.widths.length?r5(e.widths.slice(0,l.length)):Array.from({length:l.length},()=>1/l.length),{splits:l,widths:n})}function r6(e,t,n){let a=function(e,t){try{let n=window.localStorage.getItem(r1(e));if(!n)return r4(t);let a=JSON.parse(n),r=function(e){if(!r2(e))return null;let{splits:t,widths:n}=e;if(!Array.isArray(t)||!Array.isArray(n)||t.length<1||t.length>3||n.length!==t.length)return null;let a=[];for(let e of t){if(!r2(e))return null;let t=e.cliToolId;if("string"!=typeof t||!r0.has(t))return null;let n=e.instanceId,r="string"==typeof n&&(0,e2.n6)(n)?n:t;a.push({cliToolId:t,instanceId:r})}for(let e of n)if("number"!=typeof e||!Number.isFinite(e)||e<=0)return null;return{splits:a,widths:n}}(a);if(r)return{...r,widths:r5(r.widths)};return console.warn("[useTerminalSplits] stale state for ".concat(e,"; falling back to default")),r4(t)}catch(n){return console.warn("[useTerminalSplits] failed to parse stored state for ".concat(e,"; using default"),n),r4(t)}}(e,t);return n?r3(a,t):a}let r8=(0,o.memo)(function(e){let{worktreeId:t,instances:n,rosterReady:a=!0,renderPane:s,onFocusedSplitChange:l,showToast:i,onActiveInstanceChange:d,headerInstanceSelection:u}=e,{splits:m,widths:h,addSplit:x,removeSplit:f,setSplitInstance:g,setSplitWidth:p,resetWidths:b,availableInstanceIds:v,focusedSplitIndex:y,setFocusedSplitIndex:j}=function(e,t){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2],[a,r]=(0,o.useState)(()=>r6(e,t,n)),[s,l]=(0,o.useState)(0),i=(0,o.useRef)(a);i.current=a;let c=(0,o.useRef)(t);c.current=t;let d=(0,o.useRef)(n);d.current=n;let u=(0,o.useRef)(e);(0,o.useEffect)(()=>{u.current!==e&&(u.current=e,r(r6(e,c.current,d.current)),l(0))},[e]);let m=(0,o.useMemo)(()=>t.map(e=>"".concat(e.id,":").concat(e.cliTool)).join("|"),[t]);(0,o.useEffect)(()=>{n&&r(e=>r3(e,c.current))},[m,n]);let h=(0,o.useRef)(e);(0,o.useEffect)(()=>{if(h.current!==e){h.current=e;return}try{window.localStorage.setItem(r1(e),JSON.stringify(a))}catch(e){}},[a,e]);let x=(0,o.useCallback)(()=>{r(e=>{if(e.splits.length>=3)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}(c.current,t);if(!n)return e;let a=e.widths.length-1,r=e.widths[a]/2,s=[...e.widths];return s[a]=r,s.push(r),{splits:[...e.splits,{cliToolId:n.cliTool,instanceId:n.id}],widths:s}})},[]),f=(0,o.useCallback)(()=>{r(e=>e.splits.length<=1?e:{splits:e.splits.slice(0,-1),widths:r5(e.widths.slice(0,-1))})},[]);(0,o.useEffect)(()=>{l(e=>{let t=a.splits.length-1;return e>t?t:e<0?0:e})},[a.splits.length]);let g=(0,o.useCallback)((e,t)=>{let n=i.current,a=c.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},[]),p=(0,o.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]})},[]),b=(0,o.useCallback)(()=>{r(e=>{let t=e.splits.length;return 0===t?e:{...e,widths:Array.from({length:t},()=>1/t)}})},[]),v=(0,o.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]),y=(0,o.useCallback)(e=>{l(e)},[]);return{splits:a.splits,widths:a.widths,addSplit:x,removeSplit:f,setSplitInstance:g,setSplitWidth:p,resetWidths:b,availableInstanceIds:v,focusedSplitIndex:s,setFocusedSplitIndex:y}}(t,n,a),w=(0,o.useMemo)(()=>{let e=new Map;for(let t of n)e.set(t.id,t);return e},[n]),k=(0,c.c)("worktree"),{visible:N,toggle:C,setWidth:S}=tH(),{collapsed:T,toggle:E}=rq(),I=!T,M=(0,o.useRef)(null),[L,A]=(0,o.useState)(!1),P=(0,o.useRef)(m.length),[R,D]=(0,o.useState)(null);(0,o.useEffect)(()=>{m.length>P.current&&D(m.length-1),P.current=m.length},[m.length]),(0,o.useEffect)(()=>{null==l||l(y)},[y,l]);let F=(0,o.useRef)(0),z=(0,o.useRef)(m);z.current=m,(0,o.useEffect)(()=>{if(!u||u.token===F.current)return;F.current=u.token;let{instanceId:e}=u,t=z.current.findIndex(t=>t.instanceId===e);if(0!==t){if(t>0)return void j(t);g(0,e)&&j(0)}},[u,g,j]),(0,o.useEffect)(()=>{if(null===R)return;let e=M.current;if(!e)return;let t=e.querySelector('[data-split-index="'.concat(R,'"]'));if(!t)return;let n=t.querySelector("textarea");null==n||n.focus(),j(R),D(null)},[R,j]);let O=(0,o.useCallback)((e,t)=>{let n=M.current;if(!n)return;let a=n.offsetWidth;if(0===a)return;let r=h.reduce((e,t)=>e+t,0),s=t/a*r,l=[...h],o=l[e]+s,i=l[e+1]-s,c=.05*r;o<c||i<c||(l[e]=o,l[e+1]=i,p(l))},[h,p]),_=(0,o.useCallback)(()=>A(!0),[]),B=(0,o.useCallback)(()=>A(!1),[]),W=(0,o.useCallback)(()=>{b(),S(40)},[b,S]),H=m.length<3&&!L,V=m.length>1&&!L,U=m.length>1||N,K=(0,o.useMemo)(()=>m.map((e,t)=>()=>j(t)),[m,j]),$=(0,o.useMemo)(()=>m.map((e,t)=>e=>g(t,e)),[m,g]),q=(0,o.useMemo)(()=>m.map((e,t)=>e=>{var n,a;let r=(0,e2.sw)(null!=(a=w.get(e))?a:{cliTool:"claude",alias:e});if((null==(n=m[t])?void 0:n.instanceId)===e)return;let s=m.findIndex((n,a)=>a!==t&&n.instanceId===e);if(-1!==s){null==i||i("".concat(r," is already in use by split ").concat(s+1),"warning");return}g(t,e)&&(null==d||d(e),null==i||i("Moved ".concat(r," to Split ").concat(t+1),"success"))}),[m,g,i,d,w]);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.jsxs)("span",{className:"text-xs text-muted-foreground tabular-nums mr-1",children:[m.length," / ",3," splits"]}),(0,r.jsx)("button",{type:"button",onClick:x,disabled:!H,"aria-disabled":!H,"aria-label":k("terminal.addSplit"),title:k("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)(as.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:f,disabled:!V,"aria-disabled":!V,"aria-label":k("terminal.removeSplit"),title:k("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)(rY.A,{className:"w-4 h-4","aria-hidden":"true"})}),(0,r.jsx)("button",{type:"button",onClick:W,disabled:!U,"aria-disabled":!U,"aria-label":k("terminal.equalizeWidthsHint"),title:k("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)(rG.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.jsxs)("button",{type:"button",onClick:C,"aria-pressed":N,"aria-label":k(N?"terminal.hideHistory":"terminal.showHistory"),title:k(N?"terminal.hideHistory":"terminal.showHistory"),"data-testid":"toggle-history-pane",className:"flex items-center gap-1 text-xs px-2 py-0.5 rounded border transition-colors ".concat(N?"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)(rX.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("terminal.historyLabel")})]}),(0,r.jsxs)("button",{type:"button",onClick:E,"aria-pressed":I,"aria-label":k(I?"terminal.hideFiles":"terminal.showFiles"),title:k(I?"terminal.hideFiles":"terminal.showFiles"),"data-testid":"toggle-file-panel",className:"flex items-center gap-1 text-xs px-2 py-0.5 rounded border transition-colors ".concat(I?"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)(rQ.A,{className:"w-3.5 h-3.5 flex-shrink-0","aria-hidden":"true"}),(0,r.jsx)("span",{children:k("terminal.filesLabel")})]})]}),(0,r.jsx)("div",{ref:M,className:"flex flex-1 min-h-0 w-full",children:m.map((e,t)=>{var n;let a=t===m.length-1;return(0,r.jsxs)(o.Fragment,{children:[(0,r.jsx)("div",{style:{flexGrow:null!=(n=h[t])?n:1,flexShrink:1,flexBasis:0,minWidth:0},className:"h-full",children:s({splitIndex:t,cliToolId:e.cliToolId,instanceId:e.instanceId,instance:w.get(e.instanceId),availableInstances:v(t).map(e=>w.get(e)).filter(e=>void 0!==e),onInstanceChange:$[t],onFocus:K[t],isFocused:y===t,onDropInstance:q[t]})}),a?null:(0,r.jsx)(r9,{resizerIdx:t,ariaValueNow:h.length?h[t]/h.reduce((e,t)=>e+t,0)*100:50,onResize:O,onStart:_,onEnd:B,onDoubleClick:b})]},"split-".concat(t))})})]})});function r9(e){let{resizerIdx:t,ariaValueNow:n,onResize:a,onStart:s,onEnd:l,onDoubleClick:i}=e,c=(0,o.useCallback)(e=>a(t,e),[t,a]);return(0,r.jsx)("div",{"data-testid":"split-resizer-".concat(t),onMouseDownCapture:s,onTouchStartCapture:s,onMouseUpCapture:l,onTouchEndCapture:l,children:(0,r.jsx)(tV.f,{onResize:c,orientation:"horizontal",ariaValueNow:n,onDoubleClick:i})})}let r7={key:"Escape",label:"Esc",ariaLabel:"Send Escape"},se=[r7,{key:"q",label:"q",ariaLabel:"Send q (quit)"}];function st(e){let{worktreeId:t,cliToolId:n,instanceId:a,onKeysSent:s}=e,[l,i]=(0,o.useState)(null),c=en(t,n,a,s),d="codex"===n?se:[r7],u=(0,o.useCallback)(e=>{i(e),setTimeout(()=>i(null),et.tX),c([e])},[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 escape keys",children:[(0,r.jsx)("span",{className:"text-xs text-amber-700 dark:text-amber-400 mx-2",title:"Send an escape key when the terminal is stuck in a TUI mode",children:"Escape"}),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)})]})}let sn="\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(),sa="bg-accent-600 text-white hover:bg-accent-700 focus:ring-ring";function sr(e){let{promptData:t,answering:n,onRespond:a,onDismiss:s,labelId:l,cliToolName:i}=e,d=(0,c.c)("prompt"),[u,h]=(0,o.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,f]=(0,o.useState)(""),[g,p]=(0,o.useState)(!1),b=(0,o.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!=(e=t.options.find(e=>e.number===u))?e:null},[t,u]),v=(null==b?void 0:b.requiresTextInput)===!0,y=n||g,j=(0,o.useCallback)(async e=>{if(!y){p(!0);try{await a(e)}catch(e){}finally{p(!1)}}},[y,a]),w=(0,o.useCallback)(async()=>{if(!y&&null!==u){p(!0);try{let e=v&&x.trim()?x.trim():u.toString();await a(e)}catch(e){}finally{p(!1)}}},[y,a,u,v,x]);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:l,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:"?"}),i?d("confirmationFrom",{toolName:i}):d("confirmationFromClaude")]}),s&&(0,r.jsx)(m.$n,{variant:"ghost",type:"button",onClick:s,"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"})})})]}),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}),y&&(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:d("sending")})]}),"yes_no"===t.type&&(0,r.jsx)(ss,{promptData:t,disabled:y,onYes:()=>j("yes"),onNo:()=>j("no")}),"multiple_choice"===t.type&&(0,r.jsx)(sl,{promptData:t,disabled:y,selectedOption:u,onSelectOption:h,textInputValue:x,onTextInputChange:f,showTextInput:v,onSubmit:w})]})}function ss(e){let{promptData:t,disabled:n,onYes:a,onNo:s}=e,l=(0,c.c)("prompt"),o="yes"===t.defaultOption,i="no"===t.defaultOption,d="".concat(sn," ").concat(sa," ").concat(o?"primary default highlighted":""),u="".concat(sn," ").concat(i?"bg-foreground text-background hover:bg-foreground/90 primary default highlighted":"bg-surface border-2 border-input hover:bg-muted text-foreground focus:ring-ring");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 sl(e){let{promptData:t,disabled:n,selectedOption:a,onSelectOption:s,textInputValue:l,onTextInputChange:i,showTextInput:d,onSubmit:u}=e,h=(0,o.useId)(),x=(0,c.c)("prompt"),f=(0,o.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:x("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:f(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:x("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:x("customValueInput")}),(0,r.jsx)("input",{id:"text-input-".concat(h),type:"text",value:l,onChange:e=>i(e.target.value),disabled:n,placeholder:x("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(sn," ").concat(sa),children:x("submit")})]})}let so=(0,o.memo)(function(e){let t,{promptData:n,messageId:a,visible:s,answering:l,onRespond:i,onDismiss:c,cliToolName:d}=e,{shouldRender:u,animationClass:m}=I({visible:s&&null!==n,duration:200}),h=(0,o.useId)();if(!u||!n)return null;let x=(t="opacity-100","animate-fade-in"===m?t="opacity-100 transform translate-y-0":"animate-fade-out"===m&&(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(m," ").concat(t));return(0,r.jsx)(S,{componentName:"PromptPanel",children:(0,r.jsx)("div",{"data-testid":"prompt-panel",role:"dialog","aria-labelledby":h,"aria-modal":"true",className:x,children:(0,r.jsx)(sr,{promptData:n,answering:l,onRespond:i,onDismiss:c,labelId:h,cliToolName:d})})})});var si=n(91758);function sc(e){let{isOpen:t,onConfirm:n,onCancel:a,cliToolName:s}=e,l=(0,c.c)("autoYes"),i=(0,c.c)("common"),[d,u]=(0,o.useState)(36e5),[m,h]=(0,o.useState)(""),[x,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),b=(0,o.useRef)(null),v=e=>l(am[e].replace("autoYes.",""));return(0,o.useEffect)(()=>{t&&(h(""),f(null),p(!1))},[t]),(0,o.useEffect)(()=>{if(!g)return;let e=e=>{b.current&&!b.current.contains(e.target)&&p(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[g]),(0,o.useEffect)(()=>{if(!m.trim())return void f(null);let e=function(e){if(e.length>500)return{valid:!1,error:"Pattern must be ".concat(500," characters or less")};if(!ad()(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"}}}(m.trim());if(e.valid)f(null);else{var t;f(null!=(t=e.error)?t:l("invalidRegexPattern"))}},[m,l]),(0,r.jsx)(e0.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:au.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:()=>p(!g),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:"?"}),g&&(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(x?"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"}),x&&(0,r.jsx)("p",{className:"mt-1 text-xs text-danger","data-testid":"stop-pattern-error",children:x})]}),(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:i("cancel")}),(0,r.jsx)("button",{type:"button",onClick:()=>{n(d,m.trim()||void 0)},disabled:!!x,className:"px-4 py-2 text-sm font-medium rounded-md text-white ".concat(x?"bg-muted-foreground cursor-not-allowed":"bg-warning hover:bg-warning/90"),"data-testid":"confirm-button",children:l("agreeAndEnable")})]})]})})}let sd=(0,o.memo)(function(e){let{enabled:t,expiresAt:n,onToggle:a,lastAutoResponse:s,cliToolName:l,inline:i=!1,showToolName:d=!0,onExpire:u}=e,m=(0,c.c)("autoYes"),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(null),[p,b]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),[j,w]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!t||!n){x(""),w(!1);return}w(!1);let e=!1,a=()=>(x(ah(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,o.useEffect)(()=>{if(!s)return;g('Auto responded: "'.concat(s,'"'));let e=setTimeout(()=>g(null),et.I2);return()=>clearTimeout(e)},[s]);let k=t&&!j,N=(0,o.useCallback)(()=>{k?(b(!0),a({enabled:!1}).finally(()=>b(!1))):y(!0)},[k,a]),C=(0,o.useCallback)((e,t)=>{y(!1),b(!0),a({enabled:!0,duration:e,stopPattern:t}).finally(()=>b(!1))},[a]),S=(0,o.useCallback)(()=>{y(!1)},[]);return(0,r.jsxs)("div",{className:i?"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)(si.d,{checked:k,onCheckedChange:N,disabled:p,"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,e2.f_)(l,""),")"]}),k&&h&&(0,r.jsx)("span",{className:"text-sm text-muted-foreground","aria-label":m("timeRemaining"),children:h}),f&&(0,r.jsx)("span",{className:"text-sm text-success animate-pulse",children:f}),(0,r.jsx)(sc,{isOpen:v,onConfirm:C,onCancel:S,cliToolName:(0,e2.f_)(l,"")})]})});function su(e){let t=new Set;for(let n of e)"user"===n.role&&t.add(n.id);return t}function sm(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()),o=new Set;for(let e of[...s].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())){let t=l.find(t=>!o.has(t.id)&&!e.baselineUserIds.has(t.id)&&t.content===e.content);t&&(o.add(t.id),a.add(e.tempId),r.add(t.id))}return{reconciledTempIds:a,consumedServerIds:r}}function sh(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 sx=(0,o.memo)(function(e){var t,n,a,s,l;let{worktreeId:i,splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:f,onFocus:g,disabled:p=!1,pendingInsertText:b,onInsertConsumed:v,onMessageSent:y,cliStatus:j="idle",autoYes:w,history:k,onDropInstance:N,draggedInstanceId:C,onRequestSessionEnd:S}=e,T=null!=m?m:u,E=null!=(t=w.enabled)&&t,I=null!=(n=w.expiresAt)?n:null,M=null!=(a=w.lastAutoResponse)?a:null,L=w.onToggle,A=null!=(s=null==k?void 0:k.showArchived)&&s,P=null==k?void 0:k.onShowArchivedChange,R=null==k?void 0:k.historyDisplayLimit,D=null==k?void 0:k.onHistoryDisplayLimitChange,F=null!=(l=null==k?void 0:k.historyUserOnly)&&l,z=null==k?void 0:k.onHistoryUserOnlyChange,O=null==k?void 0:k.onInsertToMessage,_=null==k?void 0:k.onFilePathClick,W=null==k?void 0:k.showToast,H=(0,c.c)("worktree"),{terminal:V,prompt:U,setAutoScroll:K,setPromptAnswering:$,clearPrompt:q,refresh:J}=tu({worktreeId:i,cliToolId:u,instanceId:T,enabled:!p}),{messages:Y,isLoading:G,refresh:X}=function(e){let{worktreeId:t,cliToolId:n,instanceId:a,limit:r,includeArchived:s=!1,enabled:l=!0}=e,[i,c]=(0,o.useState)([]),[d,u]=(0,o.useState)(!0),{subscribe:m,unsubscribe:h,addListener:x}=(0,td.xM)(),f=null!=a?a:n,g=(0,o.useRef)(0),p=(0,o.useRef)(n);p.current=n;let b=(0,o.useRef)(f);b.current=f;let v=(0,o.useCallback)(async()=>{let e=++g.current;try{let a=new URLSearchParams({cliTool:n,instance:f});void 0!==r&&a.set("limit",String(r)),s&&a.set("includeArchived","true");let l=await fetch("/api/worktrees/".concat(t,"/messages?").concat(a.toString()));if(!l.ok)return;let o=await l.json();if(g.current!==e||p.current!==n||b.current!==f)return;c(o.map(e=>({...e,timestamp:new Date(e.timestamp)}))),u(!1)}catch(t){if(g.current!==e||p.current!==n||b.current!==f)return;console.error("[useSplitMessages] fetch error:",t),u(!1)}},[t,n,f,r,s]),y="".concat(t,"::").concat(n,"::").concat(f),j=(0,o.useRef)(y);return(0,o.useEffect)(()=>{j.current!==y&&(j.current=y,g.current+=1,c([]),u(!0))},[y]),(0,o.useEffect)(()=>{if(!l)return;let e=!1,t=setInterval(()=>{"hidden"!==document.visibilityState&&v()},5e3);"undefined"!=typeof document&&"hidden"!==document.visibilityState&&v();let n=()=>{"visible"!==document.visibilityState||e||v()};return document.addEventListener("visibilitychange",n),()=>{e=!0,clearInterval(t),document.removeEventListener("visibilitychange",n)}},[l,v]),(0,o.useEffect)(()=>{if(l)return m(t),()=>h(t)},[l,t,m,h]),(0,o.useEffect)(()=>{if(l)return x(e=>{if("session_status_changed"===e.type)e.worktreeId===t&&!1===e.isRunning&&(null==e.instance||e.instance===b.current)&&(null==e.cliTool||e.cliTool===p.current)&&v()})},[l,t,x,v]),{messages:i,isLoading:d,refresh:(0,o.useCallback)(()=>v(),[v])}}({worktreeId:i,cliToolId:u,instanceId:T,limit:R,includeArchived:A,enabled:!p}),Q=(0,o.useCallback)((e,t)=>B.y.sendMessage(i,e,t),[i]),{messages:Z,sendOptimistic:et,retry:en,discard:ea}=function(e){let{worktreeId:t,serverMessages:n,sendFn:a,onSent:r,timeoutMs:s=3e4}=e,[l,i]=(0,o.useState)([]),c=(0,o.useRef)(n);c.current=n;let d=(0,o.useRef)(l);d.current=l;let u=(0,o.useRef)(r);u.current=r;let m=(0,o.useRef)(a);m.current=a;let h=(0,o.useRef)(0),x=(0,o.useRef)(new Map),f=(0,o.useRef)(new Set),g=(0,o.useCallback)(e=>{let t=x.current.get(e);void 0!==t&&(clearTimeout(t),x.current.delete(e))},[]),p=(0,o.useCallback)(e=>{g(e);let t=setTimeout(()=>{x.current.delete(e),i(t=>t.map(t=>t.tempId===e&&"sending"===t.status?{...t,status:"error"}:t))},s);x.current.set(e,t)},[g,s]),b=(0,o.useCallback)(async e=>{p(e.tempId);try{var t;await m.current(e.content,e.options),null==(t=u.current)||t.call(u)}catch(t){g(e.tempId),i(t=>t.map(t=>t.tempId===e.tempId?{...t,status:"error"}:t))}},[p,g]),v=(0,o.useCallback)((e,t)=>{let n={tempId:"pending-".concat(h.current++),content:e,options:t,timestamp:new Date,status:"sending",baselineUserIds:su(c.current)};i(e=>[...e,n]),b(n)},[b]),y=(0,o.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);if(!t)return;let n={...t,status:"sending",timestamp:new Date,baselineUserIds:su(c.current)};i(t=>t.map(t=>t.tempId===e?n:t)),b(n)},[b]),j=(0,o.useCallback)(e=>{let t=d.current.find(t=>t.tempId===e);return g(e),i(t=>t.filter(t=>t.tempId!==e)),null==t?void 0:t.content},[g]);return(0,o.useEffect)(()=>{let{reconciledTempIds:e,consumedServerIds:t}=sm(d.current,n,f.current),a=new Set(n.map(e=>e.id)),r=new Set;f.current.forEach(e=>{a.has(e)&&r.add(e)}),t.forEach(e=>r.add(e)),f.current=r,0!==e.size&&(e.forEach(g),i(t=>t.filter(t=>!e.has(t.tempId))))},[n,g]),(0,o.useEffect)(()=>{let e=x.current;return()=>{e.forEach(e=>clearTimeout(e)),e.clear()}},[]),{messages:(0,o.useMemo)(()=>{if(0===l.length)return n;let{reconciledTempIds:e}=sm(l,n,f.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}}({worktreeId:i,serverMessages:Y,sendFn:Q,onSent:X}),{visible:er,width:el,toggle:eo,setWidth:ei}=tH(),ec=o.useRef(null),ed=(0,o.useCallback)(e=>{let t=ec.current;if(!t)return;let n=t.offsetWidth;0!==n&&ei(el+e/n*100)},[el,ei]),eu="opencode"===u||"copilot"===u,eh="claude"===u||"codex"===u,ex=(0,o.useCallback)(e=>K(e),[K]),ef=(0,o.useCallback)(e=>{J(),X(),null==y||y(e)},[J,X,y]),eg=(0,o.useCallback)(e=>{let t=ea(e);t&&(null==O||O(t))},[ea,O]),ep=(0,o.useCallback)(async e=>{$(!0);try{let t=sh(e,u,U.data,T),n=await fetch("/api/worktrees/".concat(i,"/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));q(),await J()}catch(e){console.error("[TerminalSplitPaneContent] prompt response error:",e)}finally{$(!1)}},[i,u,T,U.data,$,q,J]),eb=(0,o.useCallback)(()=>{q()},[q]),ev=V.isSelectionListActive,ey=U.visible&&!E,ej=V.isUnclassifiedActive&&!ev&&!U.visible,ew=(0,o.useMemo)(()=>(0,r.jsx)(t1,{messages:Z,worktreeId:i,onFilePathClick:null!=_?_:()=>{},isLoading:G,className:"h-full",showToast:W,onInsertToMessage:O,onRetryPending:en,onDiscardPending:eg,showArchived:A,onShowArchivedChange:P,historyDisplayLimit:R,onHistoryDisplayLimitChange:D,historyUserOnly:F,onHistoryUserOnlyChange:z,onCollapse:eo,splitIndex:d,cliToolId:u}),[Z,en,eg,i,_,G,W,O,A,P,R,D,F,z,eo,d,u]),ek=(0,o.useMemo)(()=>(0,r.jsx)(tc,{output:V.output,isActive:V.isRunning,attaching:V.attaching,isThinking:V.isThinking,autoScroll:V.autoScroll,onScrollChange:ex,disableAutoFollow:eu,compactTuiLayoutPadding:eh}),[V.output,V.isRunning,V.attaching,V.isThinking,V.autoScroll,ex,eu,eh]),eN=(0,o.useMemo)(()=>(0,r.jsxs)("div",{ref:ec,className:"flex h-full min-h-0 w-full",children:[er?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{id:tX(d),"data-testid":"split-history-slot-".concat(d),"aria-label":"History pane",style:{width:"".concat(el,"%")},className:"flex-shrink-0 overflow-hidden min-h-0",children:ew}),(0,r.jsx)(tV.f,{onResize:ed,orientation:"horizontal",ariaValueNow:el})]}):(0,r.jsx)("div",{"data-testid":"split-history-expand-bar-".concat(d),className:"flex-shrink-0 flex items-start justify-center w-9 bg-gray-50 dark:bg-gray-800 border-r border-gray-200 dark:border-gray-700",children:(0,r.jsxs)("button",{type:"button","data-testid":"split-history-expand-".concat(d),"aria-label":H("terminal.showHistory"),title:H("terminal.showHistory"),"aria-expanded":"false",onClick:eo,className:"flex flex-col items-center gap-2 w-full pt-2 text-gray-500 dark:text-gray-400 hover:text-accent-600 dark:hover:text-accent-400 focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,r.jsx)("svg",{className:"w-4 h-4 flex-shrink-0",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"})}),(0,r.jsx)("span",{className:"text-xs font-medium tracking-wide select-none",style:{writingMode:"vertical-rl"},"aria-hidden":"true",children:H("terminal.historyLabel")})]})}),(0,r.jsx)("div",{className:"flex-grow overflow-hidden min-w-0 min-h-0 relative",children:ek})]}),[er,el,ew,ed,eo,ek,d,H]),eC=(0,o.useMemo)(()=>(0,r.jsxs)("div",{className:"space-y-2",children:[ev?(0,r.jsx)(es,{worktreeId:i,cliToolId:u,instanceId:T,onKeysSent:J,showPagerKeys:V.isPagerActive}):null,ej?(0,r.jsx)(st,{worktreeId:i,cliToolId:u,instanceId:T,onKeysSent:J}):null,ey?(0,r.jsx)(so,{promptData:U.data,messageId:U.messageId,visible:U.visible,answering:U.answering,onRespond:ep,onDismiss:eb,cliToolName:(0,e2.oo)(u)}):null,(0,r.jsx)(ee,{worktreeId:i,onMessageSent:ef,onOptimisticSend:et,cliToolId:u,instanceId:T,isSessionRunning:V.isRunning,pendingInsertText:null!=b?b:null,onInsertConsumed:v,splitIndex:d,onFocus:g,isProcessing:V.isRunning,showToast:W,autoYesSlot:(0,r.jsx)(sd,{enabled:E,expiresAt:null!=I?I:null,onToggle:L,lastAutoResponse:null!=M?M:null,cliToolName:u,inline:!0})})]}),[ev,ey,ej,V.isPagerActive,i,u,T,J,U.data,U.messageId,U.visible,U.answering,ep,eb,ef,et,V.isRunning,b,v,d,g,E,I,M,L,W]),eS=(0,e2.sw)(null!=h?h:{cliTool:u}),eT=(0,o.useCallback)(()=>{null==S||S({cliToolId:u,instanceId:T,label:eS})},[S,u,T,eS]),eE=(0,o.useMemo)(()=>{if(!S||!V.isRunning)return null;let e=H("terminal.endSessionFor",{name:eS});return(0,r.jsx)("button",{type:"button",onClick:eT,"aria-label":e,title:e,"data-testid":"terminal-end-session-button-".concat(d),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)(em.A,{size:14,"aria-hidden":"true"})})},[S,V.isRunning,H,eS,eT,d]);return(0,r.jsx)(e3,{worktreeId:i,splitIndex:d,cliToolId:u,instanceId:T,instance:h,availableInstances:x,onInstanceChange:f,headerExtras:eE,status:j,onFocus:g,attaching:V.attaching,terminal:eN,footer:eC,onDropInstance:N,draggedInstanceId:C})});var sf=n(52056);let sg=(0,o.memo)(function(e){let{isBranchMismatch:t,currentBranch:n,initialBranch:a}=e,s=(0,c.c)("worktree"),[l,i]=(0,o.useState)(!1);return((0,o.useEffect)(()=>{i(!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)(sf.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:()=>i(!0),className:"p-1 rounded hover:bg-warning-subtle transition-colors","aria-label":s("branchMismatch.dismiss"),children:(0,r.jsx)(em.A,{className:"w-4 h-4"})})]})});var sp=n(58734);let sb=(0,o.memo)(function(e){let{isOpen:t,onClose:n,onConfirm:a,worktreeId:s,sourcePath:l,sourceType:i}=e,d=(0,c.c)("worktree"),u=(0,c.c)("common"),[h,x]=(0,o.useState)(""),[f,g]=(0,o.useState)(new Set([""])),[p,b]=(0,o.useState)([]),[v,j]=(0,o.useState)(!1),[w,k]=(0,o.useState)(new Set),N=l.includes("/")?l.substring(0,l.lastIndexOf("/")):"";(0,o.useEffect)(()=>{t&&(x(N),g(new Set([""])),b([]),C())},[t,s]);let C=(0,o.useCallback)(async()=>{j(!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{j(!1)}},[s]),S=(0,o.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,o.useCallback)(async e=>{g(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}(p,e);t&&!t.loaded&&await S(e)},[p,S]),E=(0,o.useCallback)(e=>!(e===N||"directory"===i&&(e===l||e.startsWith(l+"/")))&&!0,[N,l,i]),I=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=f.has(e.path),a=h===e.path,s=w.has(e.path),l=E(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&&x(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)(tf.A,{className:"w-3 h-3 text-muted-foreground transition-transform ".concat(n?"rotate-90":"")})}),n?(0,r.jsx)(sp.A,{className:"w-4 h-4 text-warning flex-shrink-0"}):(0,r.jsx)(y.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=>I(e,t+1))})]},e.path)},M=E(h);return(0,r.jsx)(e0.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(E("")?"":"opacity-40 cursor-not-allowed"),onClick:()=>{E("")&&x("")},children:[(0,r.jsx)("span",{className:"w-4 h-4"}),(0,r.jsx)(y.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"})}):p.map(e=>I(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:!M,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 sv(e,t){let n=e.trim();return n?0>=n.lastIndexOf(".")?n+t:n:""}let sy=(0,o.memo)(function(e){let{isOpen:t,parentPath:n,onConfirm:a,onCancel:s}=e,l=(0,c.c)("worktree"),i=(0,c.c)("common"),[d,u]=(0,o.useState)(""),[m,h]=(0,o.useState)(".md"),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(t){u(""),h(".md");let e=setTimeout(()=>{var e;null==(e=x.current)||e.focus()},100);return()=>clearTimeout(e)}},[t]);let f=(0,o.useCallback)(()=>{let e=sv(d,m);e&&a(e)},[d,m,a]),g=(0,o.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),f())},[f]),p=sv(d,m),b=n?"".concat(n,"/").concat(p):p;return(0,r.jsx)(e0.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:x,id:"new-file-name","data-testid":"new-file-name-input",type:"text",value:d,onChange:e=>u(e.target.value),onKeyDown:g,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:rN.map(e=>(0,r.jsx)("option",{value:e,children:e},e))})]})]}),p&&(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:i("cancel")}),(0,r.jsx)("button",{type:"button","data-testid":"new-file-confirm-button",onClick:f,disabled:!p,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")})]})]})})}),sj=(0,o.memo)(function(e){var t,n,a,s;let{worktreeId:l,worktree:i,worktreeName:d,worktreeStatus:u,instances:m,rosterReady:h,activeInstanceId:x,setActiveInstanceId:f,hasUpdate:g,lastAutoResponse:p,activeActivity:b,onActivityToggle:v,onBackClick:y,onInfoClick:j,onWorktreeStatusChange:w,pendingInsertTextMap:k,setFocusedSplitIndex:N,handleInsertToSplit:C,handleInsertConsumed:T,handleInsertToMessage:E,autoYesStateMap:I,makeAutoYesToggleHandler:M,showArchived:L,onShowArchivedChange:A,historyDisplayLimit:P,onHistoryDisplayLimitChange:R,historyUserOnly:D,onHistoryUserOnlyChange:F,onMessageSent:z,onFilePathClick:O,showToast:_,tabsState:B,tabsActions:W,onLoadContent:H,onLoadError:V,onSetLoading:U,onFilePanelSave:K,onDirtyChange:$,onOpenFile:q,diffContent:J,diffFilePath:Y,onCloseDiff:G,fileSearch:X,fileTreeRefresh:Q,onFileSelect:Z,onNewFile:ee,onNewDirectory:et,onRename:en,onDelete:ea,onUpload:er,onMove:es,onFileTreeReset:el,onDiffSelect:eo,onAgentInstancesChange:ei,vibeLocalModel:ec,onVibeLocalModelChange:ed,vibeLocalContextWindow:eu,onVibeLocalContextWindowChange:em,isInfoModalOpen:eh,onInfoModalClose:ex,onWorktreeUpdate:ef,fileInputRef:eg,onFileInputChange:ep,onKillSession:eb,onRequestSessionEnd:ev,killTarget:ey,isKillPending:ej,onKillCancel:ew,onKillConfirm:ek,moveTarget:eN,isMoveDialogOpen:eC,onMoveCancel:eS,onMoveConfirm:eT,showNewFileDialog:eE,newFileParentPath:eI,onNewFileConfirm:eM,onNewFileCancel:eL,toasts:eA,onToastClose:eP,killDialogTitle:eR,killDialogWarning:eD,cancelLabel:eF,endLabel:ez}=e,eO=(0,c.c)("worktree"),[e_,eW]=o.useState(null),eH=(0,o.useCallback)(e=>eW(e),[]),eV=(0,o.useCallback)(()=>eW(null),[]),[eU,eK]=o.useState(null),e$=o.useRef(0),eq=(0,o.useCallback)(e=>{f(e),e$.current+=1,eK({instanceId:e,token:e$.current})},[f]),eJ=(0,o.useCallback)(e=>{var t,n,a,s,o,c;let{splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:g,onFocus:b,onDropInstance:v}=e,y=null!=(a=k.get(d))?a:null,j=I.get(m),w=null!=(s=null==j?void 0:j.enabled)&&s,N=null!=(o=null==j?void 0:j.expiresAt)?o:null,S=(0,e1.kA)(null!=(c=null==i||null==(t=i.sessionStatusByInstance)?void 0:t[m])?c:null==i||null==(n=i.sessionStatusByCli)?void 0:n[u]);return(0,r.jsx)(sx,{worktreeId:l,splitIndex:d,cliToolId:u,instanceId:m,instance:h,availableInstances:x,onInstanceChange:e=>{g(e),0===d&&f(e)},onFocus:b,pendingInsertText:y,onInsertConsumed:()=>T(d),onMessageSent:z,cliStatus:S,autoYes:{enabled:w,expiresAt:N,lastAutoResponse:p,onToggle:M(u,m)},history:{showArchived:L,onShowArchivedChange:A,historyDisplayLimit:P,onHistoryDisplayLimitChange:R,historyUserOnly:D,onHistoryUserOnlyChange:F,onInsertToMessage:e=>C(d,e),onFilePathClick:O,showToast:_},onDropInstance:v,draggedInstanceId:e_,onRequestSessionEnd:ev})},[l,k,I,T,z,f,p,M,null==i?void 0:i.sessionStatusByCli,null==i?void 0:i.sessionStatusByInstance,O,_,C,L,A,P,R,D,F,e_,ev]),eY=(0,o.useMemo)(()=>(0,r.jsx)(r8,{worktreeId:l,instances:m,rosterReady:h,renderPane:eJ,onFocusedSplitChange:N,showToast:_,onActiveInstanceChange:f,headerInstanceSelection:eU}),[l,m,h,eJ,N,_,f,eU]),eG=(0,o.useMemo)(()=>(0,r.jsx)(rJ,{terminal:eY,terminalHeader:null,fileTabs:B,worktreeId:l,onCloseTab:W.closeTab,onActivateTab:W.activateTab,onLoadContent:H,onLoadError:V,onSetLoading:U,onFileSaved:K,diffContent:J,diffFilePath:Y,onCloseDiff:G,onDirtyChange:$,onMoveToFront:W.moveToFront,onOpenFile:q}),[eY,B,l,W.closeTab,W.activateTab,H,V,U,K,J,Y,G,$,W.moveToFront,q]),eX=(0,o.useMemo)(()=>(0,r.jsx)(rp,{active:b,onToggle:v}),[b,v]),eQ=(0,o.useMemo)(()=>{var e;return{files:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(nj,{query:X.query,mode:X.mode,isSearching:X.isSearching,error:X.error,onQueryChange:X.setQuery,onModeChange:X.setMode,onClear:X.clearSearch}),(0,r.jsx)(np,{worktreeId:l,onFileSelect:Z,onNewFile:ee,onNewDirectory:et,onRename:en,onDelete:ea,onUpload:er,onMove:es,onResetView:el,refreshTrigger:Q,pollingEnabled:"files"===b,searchQuery:X.query,searchMode:X.mode,searchResults:null==(e=X.results)?void 0:e.results,className:"flex-1 min-h-0"})]}),git:(0,r.jsx)(a0,{worktreeId:l,onDiffSelect:eo,isMobile:!1,worktree:null!=i?i:void 0,onInsertToMessage:E,className:"h-full"}),notes:(0,r.jsx)(nE,{worktreeId:l,className:"h-full",onInsertToMessage:E}),schedules:(0,r.jsx)(n9,{worktreeId:l,className:"h-full",onInsertToMessage:E,instances:m}),agent:(0,r.jsx)(al,{worktreeId:l,instances:m,onInstancesChange:ei,vibeLocalModel:ec,onVibeLocalModelChange:ed,vibeLocalContextWindow:eu,onVibeLocalContextWindowChange:em}),timer:(0,r.jsx)(av,{worktreeId:l,instances:m}),todo:(0,r.jsx)(nP,{worktreeId:l,className:"h-full"})}},[l,i,b,X.query,X.mode,X.isSearching,X.error,X.setQuery,X.setMode,X.clearSearch,null==(t=X.results)?void 0:t.results,Z,ee,et,en,ea,er,es,el,Q,eo,E,m,ei,ec,ed,eu,em]),eZ=(0,o.useMemo)(()=>null===b?null:(0,r.jsx)(ry,{active:b,activities:eQ}),[b,eQ]);return(0,r.jsx)(S,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"flex h-full overflow-hidden relative",children:[eX,(0,r.jsxs)("div",{className:"flex flex-col flex-1 min-h-0 min-w-0",children:[(0,r.jsx)(a9,{worktreeName:d,repositoryName:null!=(a=null!=(n=null==i?void 0:i.repositoryDisplayName)?n:null==i?void 0:i.repositoryName)?a:eO("detail.unknownRepository"),description:null==i?void 0:i.description,status:u,gitStatus:null==i?void 0:i.gitStatus,onBackClick:y,onInfoClick:j,hasUpdate:g,worktreeStatus:null!=(s=null==i?void 0:i.status)?s:null,onWorktreeStatusChange:w,sessionStatusByCli:null==i?void 0:i.sessionStatusByCli,sessionStatusByInstance:null==i?void 0:i.sessionStatusByInstance,instances:m,activeInstanceId:x,onActiveInstanceChange:eq,onAgentDragStart:eH,onAgentDragEnd:eV,onKillSession:eb}),(null==i?void 0:i.gitStatus)&&(0,r.jsx)(sg,{isBranchMismatch:i.gitStatus.isBranchMismatch,currentBranch:i.gitStatus.currentBranch,initialBranch:i.gitStatus.initialBranch}),(0,r.jsx)("div",{className:"flex-1 min-h-0 min-w-0",children:(0,r.jsx)(rn,{activityPane:eZ,rightPane:(0,r.jsx)(t$,{terminal:eG})})})]}),(0,r.jsx)(a7,{worktreeId:l,worktree:i,isOpen:eh,onClose:ex,onWorktreeUpdate:ef}),(0,r.jsx)("input",{ref:eg,type:"file",accept:rk.join(","),onChange:ep,className:"hidden","aria-label":eO("detail.uploadFile")}),(0,r.jsx)(e0.a,{isOpen:null!==ey,onClose:ew,title:eR,size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:eD}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:ew,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:eF}),(0,r.jsx)("button",{type:"button",onClick:ek,disabled:ej,"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})]})]})}),eN&&(0,r.jsx)(sb,{isOpen:eC,onClose:eS,onConfirm:eT,worktreeId:l,sourcePath:eN.path,sourceType:eN.type}),(0,r.jsx)(sy,{isOpen:eE,parentPath:eI,onConfirm:eM,onCancel:eL}),(0,r.jsx)(eB.N9,{toasts:eA,onClose:eP})]})})});e2.oo;var sw=n(51434);let sk={data:null,messageId:null,visible:!1,answering:!1},sN={mode:"split",mobileActivePane:"terminal",leftPaneTab:"history",splitRatio:.5,leftPaneCollapsed:!1,activityBar:{active:"files"},historyPane:{visible:!0,width:25,collapsed:!1}},sC={type:null,message:null,retryable:!1,retryCount:0};function sS(){return{phase:"idle",prompt:{...sk},layout:{...sN},error:{...sC},messages:[],wsConnected:!1}}function sT(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:{...sk}};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:{...sC}};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}}var sE=n(66966);function sI(e,t){try{window.localStorage.setItem(rf(e),null!=t?t:rx)}catch(e){}}let sM="commandmate:file-tabs:";function sL(e){let t=e.split("/");return t[t.length-1]||e}function sA(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}let sP={tabs:[],activeIndex:null};var sR=n(63001);let sD="commandmate:showArchived",sF="activeCliTab-",sz="activeInstanceId-";function sO(){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 s_=(0,i.default)(()=>Promise.all([n.e(8566),n.e(934),n.e(6416),n.e(8676)]).then(n.bind(n,98676)).then(e=>({default:e.MarkdownEditor})),{loadableGenerated:{webpack:()=>[98676]},ssr:!1,loading:()=>(0,r.jsx)(sO,{})}),sB=()=>{},sW=["terminal","history","files","memo","info"],sH=(0,o.memo)(function(e){var t,n,a,l,i,u;let{worktreeId:m}=e,{activeActivity:f,activeCliTab:g,activeInstanceId:b,activeTab:v,agentInstances:y,autoYesEnabled:j,autoYesExpiresAt:w,autoYesStateMap:k,diffContent:N,diffFilePath:T,disableAutoFollow:E,displayedInstances:I,editorFilePath:M,error:A,fetchCurrentOutput:R,fileInputRef:D,fileSearch:F,fileTreeRefresh:z,handleActivityToggle:O,handleAgentInstancesChange:W,handleAutoYesToggle:H,handleBackClick:V,handleCloseDiff:U,handleDelete:K,handleDiffSelect:$,handleDirtyChange:q,handleEditorClose:J,handleEditorSave:G,handleFileInputChange:X,handleFilePanelSave:Q,handleFilePathClick:Z,handleFileSelect:et,handleHistoryDisplayLimitChange:en,handleHistoryUserOnlyChange:ea,handleInfoClick:er,handleInfoModalClose:eo,handleInsertConsumed:ei,handleInsertConsumedSingle:ec,handleInsertToMessage:ed,handleInsertToSplit:eu,handleKillCancel:em,handleKillConfirm:eh,openKillConfirm:ex,openActiveKillConfirm:ef,killTarget:eg,isKillPending:ep,handleLoadContent:eb,handleLoadError:ev,handleMessageSent:ey,handleMobileFileViewerClose:ew,handleMobileTabChange:ek,handleMove:eN,handleMoveCancel:eC,handleMoveConfirm:eS,handleNewDirectory:eT,handleNewFile:eE,handleNewFileCancel:eI,handleNewFileConfirm:eM,handleOpenFile:eL,handlePromptDismiss:eA,handlePromptRespond:eP,handleRename:eR,handleRetry:eF,handleSetLoading:ez,handleShowArchivedChange:eO,handleUpload:e_,handleVibeLocalContextWindowChange:eW,handleVibeLocalModelChange:eV,handleWorktreeStatusChange:eU,hasUpdate:eK,historyDisplayLimit:e$,historySubTab:eq,historyUserOnly:eJ,isEditorMaximized:eY,isInfoModalOpen:eG,isMobile:eX,isMoveDialogOpen:eQ,isSelectionListActive:eZ,isPagerActive:e4,lastAutoResponse:e5,loading:e3,makeAutoYesToggleHandler:e6,mobileFileViewerPath:e8,mobileSelectedAgents:e9,moveTarget:e7,newFileParentPath:te,openMobileDrawer:tt,pendingInsertText:tn,pendingInsertTextMap:ta,removeToast:tr,rosterReady:ts,setActiveInstanceId:tl,setEditorFilePath:to,setFocusedSplitIndex:ti,setHistorySubTab:tc,setIsEditorMaximized:tu,setWorktree:tm,showArchived:th,showNewFileDialog:tx,showToast:tf,state:tg,tCommon:tp,tWorktree:tb,tabsActions:tv,tabsState:ty,resetFileTreeView:tj,toasts:tw,toggleInstanceVisible:tk,vibeLocalContextWindow:tN,vibeLocalModel:tC,visibleInstanceIds:tS,worktree:tT,worktreeName:tE,worktreeStatus:tI}=function(e){var t,n,a,r,l,i,d,u,m,h;let{worktreeId:f}=e,g=(0,s.useRouter)(),p=(0,Y.a)(),b=(0,o.useRef)(p);b.current=p;let{openMobileDrawer:v}=(0,rg.VF)(),{state:y,actions:j}=function(){let[e,t]=(0,o.useReducer)(sT,void 0,sS),{value:n,setValue:a}=(0,aw.V)({key:"commandmate.worktree.leftPaneCollapsed",defaultValue:!1,validate:e=>"boolean"==typeof e}),r=(0,o.useRef)(e.layout.leftPaneCollapsed);r.current=e.layout.leftPaneCollapsed;let s=(0,o.useRef)(!1);(0,o.useEffect)(()=>{s.current||(s.current=!0,n!==r.current&&t({type:"SET_LEFT_PANE_COLLAPSED",collapsed:n}))},[n]);let l=(0,o.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,el.SC)(),T=(0,sE.rC)(),E=null!=(l=null==T?void 0:T.worktrees.find(e=>e.id===f))?l:null,[I,M]=(0,o.useState)(E),[L,A]=(0,o.useState)(null===E),[P,R]=(0,o.useState)(null),D=(0,o.useRef)(null!==E),[F,z]=(0,o.useState)(!1),[O,_]=function(e){let[t,n]=(0,o.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:sL(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=sA(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=sA(t.tabs,n.path,e=>({...e,loading:n.loading}));if(!e)return t;return{...t,tabs:e}}case"SET_ERROR":{let e=sA(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:sL(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:sL(e),content:null,loading:!1,error:null,isDirty:!1}));if(0===e.length)return sP;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=sA(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 sP;default:return t}},sP),a=(0,o.useRef)(!1),r=(0,o.useRef)(e);(0,o.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(sM+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,o.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(sM+e,JSON.stringify(a))}catch(e){}}},[e,t]);let s=(0,o.useRef)(t);s.current=t;let l=(0,o.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")},[]),i=(0,o.useCallback)(e=>{n({type:"CLOSE_TAB",path:e})},[]),c=(0,o.useCallback)(e=>{n({type:"ACTIVATE_TAB",path:e})},[]),d=(0,o.useCallback)((e,t)=>{n({type:"RENAME_FILE",oldPath:e,newPath:t})},[]),u=(0,o.useCallback)(e=>{n({type:"DELETE_FILE",path:e})},[]),m=(0,o.useCallback)(e=>{n({type:"MOVE_TO_FRONT",path:e})},[]),h=(0,o.useCallback)(()=>{n({type:"CLOSE_ALL"})},[]),x=(0,o.useMemo)(()=>({dispatch:n,openFile:l,closeTab:i,activateTab:c,onFileRenamed:d,onFileDeleted:u,moveToFront:m,closeAllTabs:h}),[n,l,i,c,d,u,m,h]);return[t,x]}(f),[W,H]=(0,o.useState)(null),[V,U]=(0,o.useState)(null),[K,$]=(0,o.useState)(!1),[q,J]=(0,o.useState)(new Map),[G,X]=(0,o.useState)(null),[Q,Z]=(0,o.useState)(!1),[ee,et]=(0,o.useState)(!1),[en,ea]=(0,o.useState)(!1),er=(0,o.useRef)(!1),[es,eo]=(0,o.useState)(null),[ei,ec]=(0,o.useState)(sR.fJ),ed=(0,o.useRef)(ei);ed.current=ei;let[eu,em]=(0,o.useState)(()=>(0,e2.lu)(sR.fJ)),eh=(0,o.useRef)(eu);eh.current=eu;let[ex,ef]=(0,o.useState)(null),eg=ex===f,[ep,eb]=(0,o.useState)(null),[ev,ey]=(0,o.useState)(null),[ew,ek]=(0,o.useState)(()=>{try{let e=window.localStorage.getItem(sF+f);if(e&&(0,e2.hR)(e))return e}catch(e){}return sR.fJ[0]}),eN=(0,o.useCallback)(e=>{ek(e);try{window.localStorage.setItem(sF+f,e)}catch(e){}},[f]),eC=(0,o.useRef)(ew);eC.current=ew;let[eS,eT]=(0,o.useState)(()=>{try{let e=window.localStorage.getItem(sz+f);if(e&&(0,e2.n6)(e))return e;let t=window.localStorage.getItem(sF+f);if(t&&(0,e2.hR)(t))return t}catch(e){}return sR.fJ[0]}),eE=(0,o.useCallback)(e=>{eT(e);try{window.localStorage.setItem(sz+f,e)}catch(e){}let t=eh.current.find(t=>t.id===e);t&&eN(t.cliTool)},[f,eN]),eI=(0,o.useRef)(eS);eI.current=eS;let eM=(0,o.useRef)(0),eL=(0,o.useRef)(0),eA=(0,o.useRef)(0),eP=null!=(i=null==(t=q.get(eS))?void 0:t.enabled)&&i,eR=null!=(d=null==(n=q.get(eS))?void 0:n.expiresAt)?d:null,[eD,eF]=(0,o.useState)(0),[ez,eO]=(0,o.useState)(!1),[e_,eW]=(0,o.useState)(""),{active:eV,toggle:eU}=function(e){let[t,n]=(0,o.useState)(rh),a=(0,o.useRef)(t);a.current=t;let r=(0,o.useRef)(e);return r.current=e,(0,o.useEffect)(()=>{let t=function(e){try{let t=window.localStorage.getItem(rf(e));if(t===rx)return null;if(t&&"string"==typeof t&&rm.has(t))return t}catch(e){}return rh}(e);t!==a.current&&n(t)},[e]),{active:t,setActive:(0,o.useCallback)(e=>{n(e),sI(r.current,e)},[]),toggle:(0,o.useCallback)(e=>{if(a.current===e){n(null),sI(r.current,null);return}n(e),sI(r.current,e)},[])}}(f),{historySubTab:eK,setHistorySubTab:e$,showArchived:eq,handleShowArchivedChange:eJ,historyUserOnly:eY,handleHistoryUserOnlyChange:eG,historyDisplayLimit:eX,handleHistoryDisplayLimitChange:eQ}=function(){let[e,t]=(0,o.useState)("message"),[n,a]=(0,o.useState)(()=>"true"===localStorage.getItem(sD)),r=(0,o.useCallback)(e=>{a(e),localStorage.setItem(sD,String(e))},[]),[s,l]=(0,o.useState)(()=>{try{return"true"===localStorage.getItem(tG)}catch(e){return!1}}),i=(0,o.useCallback)(e=>{l(e);try{localStorage.setItem(tG,String(e))}catch(e){}},[]),[c,d]=(0,o.useState)(()=>{try{let e=localStorage.getItem(tJ);if(null===e)return 50;let t=parseInt(e,10);return tY(t)?t:50}catch(e){return 50}});return{historySubTab:e,setHistorySubTab:t,showArchived:n,handleShowArchivedChange:r,historyUserOnly:s,handleHistoryUserOnlyChange:i,historyDisplayLimit:c,handleHistoryDisplayLimitChange:(0,o.useCallback)(e=>{d(e);try{localStorage.setItem(tJ,String(e))}catch(e){}},[])}}(),eZ=(0,o.useRef)(eq);(0,o.useEffect)(()=>{eZ.current=eq},[eq]);let e0=(0,o.useRef)(eX);(0,o.useEffect)(()=>{e0.current=eX},[eX]);let{pendingInsertTextMap:e1,pendingInsertText:e4,setFocusedSplitIndex:e5,handleInsertToMessage:e3,handleInsertToSplit:e6,handleInsertConsumed:e8,handleInsertConsumedSingle:e9}=function(){var e;let[t,n]=(0,o.useState)(()=>new Map),[a,r]=(0,o.useState)(0),s=(0,o.useCallback)(e=>{n(t=>{let n=new Map(t);return n.set(a,e),n})},[a]),l=(0,o.useCallback)((e,t)=>{n(n=>{let a=new Map(n);return a.set(e,t),a})},[]),i=(0,o.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,o.useCallback)(()=>i(0),[i]);return{pendingInsertTextMap:t,pendingInsertText:c,focusedSplitIndex:a,setFocusedSplitIndex:r,handleInsertToMessage:s,handleInsertToSplit:l,handleInsertConsumed:i,handleInsertConsumedSingle:d}}(),{diffContent:e7,diffFilePath:te,handleDiffSelect:tt,handleCloseDiff:tn}=function(e){let[t,n]=(0,o.useState)(null),[a,r]=(0,o.useState)(null);return{diffContent:t,diffFilePath:a,handleDiffSelect:(0,o.useCallback)((t,a)=>{e||(n(t),r(a))},[e]),handleCloseDiff:(0,o.useCallback)(()=>{n(null),r(null)},[])}}(p),ta=function(e){let{worktreeId:t,initialMode:n="name",debounceMs:a=300}=e,[r,s]=(0,o.useState)(""),[l,i]=(0,o.useState)(""),[c,d]=(0,o.useState)(n),[u,m]=(0,o.useState)(!1),[h,f]=(0,o.useState)(null),[g,p]=(0,o.useState)(null),b=(0,o.useRef)(null),v=(0,o.useMemo)(()=>(0,x.sg)(e=>{i(e)},a),[a]),y=(0,o.useCallback)(e=>{s(e),v(e),p(null)},[v]),j=(0,o.useCallback)(()=>{s(""),i(""),f(null),p(null),m(!1),b.current&&(b.current.abort(),b.current=null)},[]),w=(0,o.useCallback)(e=>{if(!l.trim())return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t))},[l]),k=(0,o.useCallback)(()=>h&&0!==h.results.length?(0,x.q3)(h.results.map(e=>e.filePath)):new Set,[h]);return(0,o.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),p(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;p(e instanceof Error?e.message:"An error occurred while searching"),f(null)}finally{m(!1)}})(),()=>{e.abort()}},[c,l,t]),(0,o.useEffect)(()=>{"name"===c&&(f(null),m(!1),p(null))},[c]),{query:r,mode:c,isSearching:u,results:h,error:g,setQuery:y,setMode:d,clearSearch:j,filterByName:w,getMatchedPaths:k}}({worktreeId:f}),tr=(0,o.useRef)(!1),ts=(0,o.useRef)(f);(0,o.useEffect)(()=>{ts.current!==f&&(j.clearMessages(),tr.current=!1,J(new Map),ts.current=f)},[f,j]);let tl=(0,o.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=ed.current;a.selectedAgents.length===e.length&&a.selectedAgents.every((t,n)=>t===e[n])||ec(a.selectedAgents)}if(a.agentInstances){let e=eh.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)||em(t),ef(f)}return"vibeLocalModel"in a&&eb(null!=(e=a.vibeLocalModel)?e:null),"vibeLocalContextWindow"in a&&ey(null!=(t=a.vibeLocalContextWindow)?t:null),a}catch(e){return R(e instanceof Error?e.message:"Unknown error"),null}},[f]),to=(0,o.useCallback)(async()=>{let e=eC.current,t=b.current,n=eI.current,a=++eM.current;try{let r=new URLSearchParams({cliTool:e});t&&r.set("instance",n),eZ.current&&r.set("includeArchived","true"),r.set("limit",String(e0.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(eM.current!==a||eC.current!==e||t&&eI.current!==n)return;j.setMessages(l.map(e=>({...e,timestamp:new Date(e.timestamp)})))}catch(r){if(eM.current!==a||eC.current!==e||t&&eI.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching messages:",r)}},[f,j]),ti=(0,o.useCallback)(async()=>{let e=eC.current,t=b.current,n=eI.current,a=++eL.current;try{var r,s,l,o;let i=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(i);if(!c.ok)return;let d=await c.json();if(eL.current!==a||eC.current!==e||t&&eI.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(),et(null!=(r=d.isSelectionListActive)&&r),ea(null!=(s=d.isPagerActive)&&s),X(null!=(l=d.lastServerResponseTimestamp)?l:null),Z(null!=(o=d.serverPollerActive)&&o),d.autoYes){let a=er.current,r=d.autoYes,s=t?n:e;J(e=>{let t=new Map(e);return t.set(s,{enabled:r.enabled,expiresAt:r.expiresAt}),t}),er.current=r.enabled,a&&!d.autoYes.enabled&&("stop_pattern_matched"===d.autoYes.stopReason||"consecutive_errors"===d.autoYes.stopReason)&&eo(d.autoYes.stopReason)}}catch(r){if(eL.current!==a||eC.current!==e||t&&eI.current!==n)return;console.error("[WorktreeDetailRefactored] Error fetching current output:",r)}},[f,j,y.prompt.visible]),tc=(0,o.useCallback)(async()=>{let e=++eA.current;try{let a=await fetch("/api/worktrees/".concat(f,"/auto-yes"));if(!a.ok)return;let r=await a.json();if(eA.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})}J(l)}catch(t){if(eA.current!==e)return;console.error("[WorktreeDetailRefactored] Error fetching auto-yes states:",t)}},[f]),{visibleInstances:td,visibleInstanceIds:tu,toggleInstanceVisible:tm}=function(e){let{worktreeId:t,roster:n}=e,[a,r]=(0,o.useState)(null);(0,o.useEffect)(()=>{r(function(e){try{let t=window.localStorage.getItem(at(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,o.useMemo)(()=>an(a,n),[a,n]),l=(0,o.useMemo)(()=>s.map(e=>e.id),[s]),i=(0,o.useMemo)(()=>null!==a&&n.some(e=>a.includes(e.id)),[a,n]),c=(0,o.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(at(t),JSON.stringify(s))}catch(e){}}},[n,t]),d=(0,o.useCallback)(e=>c(e),[c]);return{visibleInstances:s,visibleInstanceIds:l,hasStoredPreference:i,toggleInstanceVisible:(0,o.useCallback)(e=>{let t=an(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,o.useCallback)(e=>{null!==a&&c([...an(a,n).map(e=>e.id),...e])},[a,n,c])}}({worktreeId:f,roster:eu}),th=p?td:eu,tx=(0,o.useMemo)(()=>Array.from(new Set(td.map(e=>e.cliTool))),[td]),tf=p?tx:ei;(0,o.useEffect)(()=>{0!==th.length&&(th.some(e=>e.id===eS)||eE(th[0].id))},[th,eS,eE]),(0,o.useEffect)(()=>{let e=th.find(e=>e.id===eS);e&&e.cliTool!==ew&&eN(e.cliTool)},[th,eS,ew,eN]);let tg="opencode"===ew||"copilot"===ew,tp=(0,o.useCallback)(e=>{ec(e)},[]),tb=(0,o.useCallback)(e=>{em(e),ef(f)},[f]),tv=(0,o.useCallback)(e=>{eb(e)},[]),ty=(0,o.useCallback)(e=>{ey(e)},[]),tj=(0,o.useRef)(ew);(0,o.useEffect)(()=>{tj.current!==ew&&(tj.current=ew,j.clearMessages(),j.clearPrompt(),et(!1),to(),ti())},[ew,j,to,ti]),(0,o.useEffect)(()=>{to()},[eq,to]),(0,o.useEffect)(()=>{to()},[eX,to]);let{toasts:tw,showToast:tk,removeToast:tN}=(0,eB.dj)(),tC=(0,o.useCallback)(()=>{tk("Maximum ".concat(30," file tabs. Close a tab first."),"info")},[tk]),tS=(0,o.useCallback)(e=>{p?H(e):"limit_reached"===_.openFile(e)&&tC()},[p,_,tC]),tT=(0,o.useCallback)(e=>{p?H(e):"limit_reached"===_.openFile(e)&&tC()},[p,_,tC]),tE=(0,o.useCallback)(e=>{"limit_reached"===_.openFile(e)&&tC()},[_,tC]),tI=(0,o.useCallback)(()=>{H(null)},[]),tM=(0,o.useCallback)(e=>{eF(e=>e+1)},[]),tL=(0,o.useCallback)(()=>{U(null)},[]),tA=(0,o.useCallback)(()=>{ta.clearSearch(),_.closeAllTabs(),H(null),U(null)},[ta,_]),tP=(0,o.useCallback)(e=>{eF(e=>e+1)},[]),tR=(0,o.useCallback)(e=>{eU(e)},[eU]),tD=(0,o.useCallback)(()=>{g.push("/")},[g]),tF=(0,o.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]),tz=(0,o.useCallback)(()=>{z(!0)},[]),tO=(0,o.useCallback)(()=>{z(!1)},[]),t_=(0,o.useCallback)(async e=>{j.setPromptAnswering(!0);try{let t=sh(e,ew,y.prompt.data,b.current?eI.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 ti()}catch(e){console.error("[WorktreeDetailRefactored] Error sending prompt response:",e)}finally{j.setPromptAnswering(!1)}},[f,j,ti,ew,y.prompt.data]),tB=(0,o.useCallback)(()=>{j.clearPrompt()},[j]),tW=(0,o.useCallback)(e=>{j.setMobileActivePane(e)},[j]),tH=(0,o.useCallback)(()=>{to(),ti()},[to,ti]),tV=(0,o.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();J(t=>{let n=new Map(t);return n.set(a,{enabled:e.enabled,expiresAt:e.expiresAt}),n}),a===eI.current&&(er.current=e.enabled)}}catch(e){console.error("[WorktreeDetailRefactored] Error toggling auto-yes:",e)}},[f]),tU=(0,o.useCallback)(e=>tV(ew,eS)(e),[tV,ew,eS]),[tK,t$]=(0,o.useState)(null),[tq,tX]=(0,o.useState)(!1),tQ=(0,o.useRef)(!1),tZ=(0,o.useCallback)(e=>{t$(e)},[]),t0=(0,o.useCallback)(()=>{let e=eI.current,t=eC.current,n=(0,e2.O6)(eh.current,e,t);t$({cliToolId:t,instanceId:e,label:n})},[]),t1=(0,o.useCallback)(async()=>{if(!tK||tQ.current)return;tQ.current=!0,tX(!0);let e=()=>{tK.instanceId===eI.current&&(j.clearMessages(),j.clearPrompt())};try{await B.y.killSession(f,tK.cliToolId,tK.instanceId),e(),await tl(),t$(null)}catch(t){t instanceof B.hD&&404===t.status?(e(),await tl(),t$(null)):tk(w("session.failedToKill"),"error")}finally{tQ.current=!1,tX(!1)}},[tK,f,j,tl,tk,w]),t2=(0,o.useCallback)(()=>{tQ.current||t$(null)},[]),t4=(0,o.useCallback)(e=>{eW(e),eO(!0)},[]),t5=(0,o.useCallback)(async e=>{eO(!1);let t=e_?"".concat(e_,"/").concat(e):e;try{if(!(await fetch("/api/worktrees/".concat(f,"/files/").concat((0,ej.o)(t)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"file",content:""})})).ok)throw Error("Failed to create file");eF(e=>e+1)}catch(e){window.alert(k("fileOps.failedToCreateFile"))}},[f,e_,k]),t3=(0,o.useCallback)(()=>{eO(!1)},[]),t6=(0,o.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,ej.o)(n)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"directory"})})).ok)throw Error("Failed to create directory");eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to create directory:",e),window.alert(k("fileOps.failedToCreateDirectory"))}},[f,k]),t8=(0,o.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,ej.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):"";_.onFileRenamed(e,"".concat(t).concat(n)),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to rename:",e),window.alert(k("fileOps.failedToRename"))}},[f,_,k]),t9=(0,o.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,ej.o)(e),"?recursive=true"),{method:"DELETE"})).ok)throw Error("Failed to delete");(V===e||(null==V?void 0:V.startsWith("".concat(e,"/"))))&&U(null),_.onFileDeleted(e),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to delete:",e),window.alert(k("fileOps.failedToDelete"))}},[f,V,_,N,k,S]);(0,o.useEffect)(()=>{"stop_pattern_matched"===es?(tk(C("stopPatternMatched"),"info"),eo(null)):"consecutive_errors"===es&&(tk(C("consecutiveErrorsStopped"),"warning"),eo(null))},[es,tk,C]);let{moveTarget:t7,isMoveDialogOpen:ne,handleMove:nt,handleMoveConfirm:nn,handleMoveCancel:na}=function(e,t,n,a){let[r,s]=(0,o.useState)(null),[l,i]=(0,o.useState)(!1),c=(0,o.useCallback)((e,t)=>{s({path:e,type:t}),i(!0)},[]),d=(0,o.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})}),i=await s.json();if(!s.ok||!i.success){var o;let e=(null==(o=i.error)?void 0:o.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),i(!1)}},[r,e,t,n,a]);return{moveTarget:r,isMoveDialogOpen:l,handleMove:c,handleMoveConfirm:d,handleMoveCancel:(0,o.useCallback)(()=>{s(null),i(!1)},[])}}(f,()=>eF(e=>e+1),e=>tk(e,"success"),e=>tk(e,"error")),nr=(0,o.useRef)(null),ns=(0,o.useRef)(""),nl=(0,o.useCallback)(e=>{var t;ns.current=e,null==(t=nr.current)||t.click()},[]),no=(0,o.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=ns.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 rk.includes(t)}(l))return void tk("Unsupported file type: ".concat(l,". Allowed: ").concat(rk.join(", ")),"error");let o=function(e){var t;let n=function(e){let t=e.toLowerCase();return rw.find(e=>e.extension===t)}(e);return null!=(t=null==n?void 0:n.maxFileSize)?t:0x1400000}(l);if(r.size>o)return void tk("File too large. Maximum size: ".concat((o/1024/1024).toFixed(1),"MB"),"error");let i=new FormData;i.append("file",r);try{let e=await fetch("/api/worktrees/".concat(f,"/upload/").concat((0,ej.o)(s||".")),{method:"POST",body:i});if(!e.ok){let t=await e.json().catch(()=>({})),n=(null==t||null==(a=t.error)?void 0:a.message)||"Failed to upload file";tk(n,"error");return}let t=await e.json();tk("Uploaded: ".concat(t.filename),"success"),eF(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to upload:",e),tk("Upload failed. Please try again.","error")}},[f,tk]),{data:ni}=eH(),nc=null!=(u=null==ni?void 0:ni.hasUpdate)&&u,{lastAutoResponse:nd}=function(e){let{worktreeId:t,cliTool:n,isPromptWaiting:a,promptData:r,autoYesEnabled:s,lastServerResponseTimestamp:l,serverPollerActive:i}=e,c=(0,o.useRef)(null),[d,u]=(0,o.useState)(null);return(0,o.useEffect)(()=>{var e;if(!a){c.current=null;return}if(!r||!s||i||l&&Date.now()-l<3e3)return;let o=(e={type:r.type,question:r.question},"".concat(e.type,":").concat(e.question));if(c.current===o)return;let d=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}(r);if(null===d)return;c.current=o,u(d);let m=sh(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,i]),{lastAutoResponse:d}}({worktreeId:f,cliTool:ew,isPromptWaiting:y.prompt.visible,promptData:y.prompt.data,autoYesEnabled:eP,lastServerResponseTimestamp:G,serverPollerActive:Q}),nu=(0,o.useCallback)(async()=>{R(null),A(!0),await tl()&&await Promise.all([to(),ti()]),A(!1)},[tl,to,ti]);!function(e){let{error:t,handleRetry:n,fetchWorktree:a,fetchMessages:r,fetchCurrentOutput:s,setError:l}=e,i=(0,o.useRef)(0),c=(0,o.useCallback)(async()=>{if("visible"!==document.visibilityState)return;let e=Date.now();if(!(e-i.current<5e3)){if(i.current=e,t)return void n();try{await Promise.all([a(),r(),s()])}finally{l(null)}}},[t,n,a,r,s,l]);(0,o.useEffect)(()=>(document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c)}),[c])}({error:P,handleRetry:nu,fetchWorktree:tl,fetchMessages:to,fetchCurrentOutput:ti,setError:R}),(0,o.useEffect)(()=>{if(tr.current)return;let e=!0;return(async()=>{D.current||A(!0),await Promise.all([tl(),to(),ti()]),e&&(A(!1),tr.current=!0)})(),()=>{e=!1}},[tl,to,ti]);let nm=null!=(m=null==I||null==(r=I.sessionStatusByCli)||null==(a=r[ew])?void 0:a.isRunning)&&m;(0,o.useEffect)(()=>{if(L||P)return;let e=setInterval(async()=>{let e=[ti(),tl()];p&&e.push(to()),await Promise.all(e)},nm?2e3:5e3);return()=>clearInterval(e)},[L,P,ti,tl,to,nm,p]),(0,o.useEffect)(()=>{tc()},[f,eg,tc]),(0,o.useEffect)(()=>{j.setLayoutMode(p?"tabs":"split")},[p,j]);let nh=(0,o.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"})(I,null!==y.error.type,ew),[I,y.error.type,ew]),nx=(0,o.useMemo)(()=>y.layout.mobileActivePane,[y.layout.mobileActivePane]),nf=null!=(h=null==I?void 0:I.name)?h:"Unknown",ng=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_CONTENT",path:e,content:t})},[_]),np=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_ERROR",path:e,error:t})},[_]),nb=(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_LOADING",path:e,loading:t})},[_]);return{activeActivity:eV,activeCliTab:ew,activeInstanceId:eS,activeTab:nx,agentInstances:eu,autoYesEnabled:eP,autoYesExpiresAt:eR,autoYesStateMap:q,diffContent:e7,diffFilePath:te,disableAutoFollow:tg,displayedAgents:tf,displayedInstances:th,editorFilePath:V,error:P,fetchCurrentOutput:ti,fileInputRef:nr,fileSearch:ta,fileTreeRefresh:eD,handleActivityToggle:tR,handleAgentInstancesChange:tb,handleAutoYesToggle:tU,handleBackClick:tD,handleCloseDiff:tn,handleDelete:t9,handleDiffSelect:tt,handleDirtyChange:(0,o.useCallback)((e,t)=>{_.dispatch({type:"SET_DIRTY",path:e,isDirty:t})},[_]),handleEditorClose:tL,handleEditorSave:tP,handleFileInputChange:no,handleFilePanelSave:tM,handleFilePathClick:tS,handleFileSelect:tT,handleHistoryDisplayLimitChange:eQ,handleHistoryUserOnlyChange:eG,handleInfoClick:tz,handleInfoModalClose:tO,handleInsertConsumed:e8,handleInsertConsumedSingle:e9,handleInsertToMessage:e3,handleInsertToSplit:e6,handleKillCancel:t2,handleKillConfirm:t1,openKillConfirm:tZ,openActiveKillConfirm:t0,killTarget:tK,isKillPending:tq,handleLoadContent:ng,handleLoadError:np,handleMessageSent:tH,handleMobileFileViewerClose:tI,handleMobileTabChange:tW,handleMove:nt,resetFileTreeView:tA,handleMoveCancel:na,handleMoveConfirm:nn,handleNewDirectory:t6,handleNewFile:t4,handleNewFileCancel:t3,handleNewFileConfirm:t5,handleOpenFile:tE,handlePromptDismiss:tB,handlePromptRespond:t_,handleRename:t8,handleRetry:nu,handleSelectedAgentsChange:tp,handleSetLoading:nb,handleShowArchivedChange:eJ,handleUpload:nl,handleVibeLocalContextWindowChange:ty,rosterReady:eg,handleVibeLocalModelChange:tv,handleWorktreeStatusChange:tF,hasUpdate:nc,historyDisplayLimit:eX,historySubTab:eK,historyUserOnly:eY,isEditorMaximized:K,isInfoModalOpen:F,isMobile:p,isMoveDialogOpen:ne,isSelectionListActive:ee,isPagerActive:en,lastAutoResponse:nd,loading:L,makeAutoYesToggleHandler:tV,mobileFileViewerPath:W,mobileSelectedAgents:tx,moveTarget:t7,newFileParentPath:e_,openMobileDrawer:v,pendingInsertText:e4,pendingInsertTextMap:e1,removeToast:tN,selectedAgents:ei,setActiveCliTab:eN,setActiveInstanceId:eE,setEditorFilePath:U,setFocusedSplitIndex:e5,setHistorySubTab:e$,setIsEditorMaximized:$,setWorktree:M,showArchived:eq,showNewFileDialog:ez,showToast:tk,state:y,tCommon:N,tWorktree:w,tabsActions:_,tabsState:O,toasts:tw,toggleInstanceVisible:tm,vibeLocalContextWindow:ev,vibeLocalModel:ep,visibleInstanceIds:tu,worktree:I,worktreeName:nf,worktreeStatus:nh}}({worktreeId:m}),[tM,tL]=(0,o.useState)(!1),tA=function(e){let{worktreeId:t,active:n}=e,{addListener:a}=(0,td.xM)(),[r,s]=(0,o.useState)(!1),l=(0,o.useRef)(n);return l.current=n,(0,o.useEffect)(()=>{n&&s(!1)},[n]),(0,o.useEffect)(()=>a(e=>{e.worktreeId===t&&("terminal_snapshot"===e.type||"message"===e.type)&&(l.current||s(!0))}),[a,t]),!n&&r}({worktreeId:m,active:"terminal"===v}),{viewportHeight:tP}=(0,sw.C)(),tR=(0,o.useCallback)(e=>{let t=sW.indexOf(v);if(-1===t)return;let n=t+e;n<0||n>=sW.length||ek(sW[n])},[v,ek]),{ref:tD}=(0,L.hU)({axis:"horizontal",threshold:60,edgeStartZone:32*("terminal"===v),onSwipeLeft:()=>tR(1),onSwipeRight:()=>tR(-1)});if(e3)return(0,r.jsx)(re,{});if(A)return(0,r.jsx)(rt,{message:A,onRetry:eF});let tF=(0,e2.O6)(y,b,g),tz=null!=(l=null==eg?void 0:eg.label)?l:tF,tO=null!=(u=null==(t=null!=(i=null==tT||null==(n=tT.sessionStatusByInstance)?void 0:n[b])?i:null==tT||null==(a=tT.sessionStatusByCli)?void 0:a[g])?void 0:t.isRunning)&&u;return eX?(0,r.jsx)(S,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"flex flex-col overflow-hidden",style:{height:null!=tP?"".concat(tP,"px"):"100%"},"data-testid":"mobile-worktree-shell",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(p,{worktreeName:tE,repositoryName:null==tT?void 0:tT.repositoryName,status:tI,gitStatus:null==tT?void 0:tT.gitStatus,onBackClick:V,onMenuClick:tt})}),(null==tT?void 0:tT.gitStatus)&&tT.gitStatus.isBranchMismatch&&(0,r.jsx)("div",{className:"z-35 flex-shrink-0",children:(0,r.jsx)(sg,{isBranchMismatch:tT.gitStatus.isBranchMismatch,currentBranch:tT.gitStatus.currentBranch,initialBranch:tT.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":tb("detail.agentInstanceSelection"),children:I.map(e=>{var t,n,a;let s=(0,e1.kA)(null!=(a=null==tT||null==(t=tT.sessionStatusByInstance)?void 0:t[e.id])?a:null==tT||null==(n=tT.sessionStatusByCli)?void 0:n[e.cliTool]),l=tp("status.".concat(s)),o=b===e.id;return(0,r.jsxs)("button",{onClick:()=>tl(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(o?"text-accent-600 dark:text-accent-400 border-accent-500":"text-muted-foreground hover:text-foreground border-transparent"),"aria-current":o?"page":void 0,children:[(0,r.jsx)(h.m,{status:s,size:"sm",label:tb("detail.statusPill",{label:(0,e2.sw)(e),status:l})}),(0,e2.sw)(e)]},e.id)})}),(0,r.jsx)("button",{type:"button",onClick:()=>tL(!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":tb("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:tD,children:(0,r.jsx)(a4,{activeTab:v,worktreeId:m,worktree:tT,messages:tg.messages,cliToolId:g,instanceId:b,onFilePathClick:Z,onFileSelect:et,onWorktreeUpdate:tm,onNewFile:eE,onNewDirectory:eT,onRename:eR,onDelete:K,onUpload:e_,onMove:eN,onFileTreeReset:tj,refreshTrigger:z,fileSearch:F,showToast:tf,selectedAgents:e9,onSelectedAgentsChange:sB,useInstanceManagement:!0,instances:y,onInstancesChange:W,visibleInstanceIds:tS,onToggleInstanceVisible:tk,vibeLocalModel:tC,onVibeLocalModelChange:eV,vibeLocalContextWindow:tN,onVibeLocalContextWindowChange:eW,disableAutoFollow:E,historySubTab:eq,onHistorySubTabChange:tc,onDiffSelect:$,onInsertToMessage:ed,showArchived:th,onShowArchivedChange:eO,historyDisplayLimit:e$,onHistoryDisplayLimitChange:en,historyUserOnly:eJ,onHistoryUserOnlyChange:ea})}),(0,r.jsxs)("div",{className:"flex-shrink-0 border-t border-border bg-surface z-30",children:[eZ&&(0,r.jsx)("div",{className:"px-2 pt-1 border-b border-border",children:(0,r.jsx)(es,{worktreeId:m,cliToolId:g,instanceId:b,onKeysSent:R,showPagerKeys:e4})}),(0,r.jsx)("div",{className:"p-2",children:(0,r.jsx)(ee,{worktreeId:m,onMessageSent:ey,cliToolId:g,instanceId:b,isSessionRunning:tO,pendingInsertText:tn,onInsertConsumed:ec,autoYesSlot:(0,r.jsx)(sd,{enabled:j,expiresAt:w,onToggle:H,lastAutoResponse:e5,cliToolName:g,inline:!0,showToolName:!1})})})]}),(0,r.jsx)(C,{activeTab:v,onTabChange:ek,hasNewOutput:tA,hasPrompt:tg.prompt.visible,hasUpdate:eK,inFlow:!0}),!j&&(0,r.jsx)(P,{promptData:tg.prompt.data,visible:tg.prompt.visible,answering:tg.prompt.answering,onRespond:eP,onDismiss:eA,cliToolName:(0,e2.oo)(g)}),(0,r.jsx)(_,{open:tM,onClose:()=>tL(!1),onSearch:()=>window.dispatchEvent(new CustomEvent("terminal-search-open")),onEnd:ef,endDisabled:!tO}),(0,r.jsx)(eD,{isOpen:null!==e8,onClose:ew,worktreeId:m,filePath:null!=e8?e8:"",onEditMarkdown:to}),M&&(0,r.jsx)(e0.a,{isOpen:!0,onClose:J,title:M.split("/").pop()||tb("fileViewer.editor"),size:"full",disableClose:eY,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(s_,{worktreeId:m,filePath:M,onClose:J,onSave:G,onMaximizedChange:tu,initialViewMode:"split"})})}),(0,r.jsx)("input",{ref:D,type:"file",accept:rk.join(","),onChange:X,className:"hidden","aria-label":tb("detail.uploadFile")}),(0,r.jsx)(e0.a,{isOpen:null!==eg,onClose:em,title:tb("session.confirmEnd",{tool:tz}),size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("p",{className:"text-sm text-foreground",children:tb("session.endWarning")}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:em,className:"px-4 py-2 text-sm font-medium rounded-md bg-muted hover:bg-muted/80 text-foreground",children:tp("cancel")}),(0,r.jsx)("button",{type:"button",onClick:eh,disabled:ep,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:tp("end")})]})]})}),e7&&(0,r.jsx)(sb,{isOpen:eQ,onClose:eC,onConfirm:eS,worktreeId:m,sourcePath:e7.path,sourceType:e7.type}),(0,r.jsx)(sy,{isOpen:tx,parentPath:te,onConfirm:eM,onCancel:eI}),(0,r.jsx)(eB.N9,{toasts:tw,onClose:tr})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(sj,{worktreeId:m,worktree:tT,worktreeName:tE,worktreeStatus:tI,instances:y,rosterReady:ts,activeInstanceId:b,setActiveInstanceId:tl,hasUpdate:eK,lastAutoResponse:e5,activeActivity:f,onActivityToggle:O,onBackClick:V,onInfoClick:er,onWorktreeStatusChange:eU,pendingInsertTextMap:ta,setFocusedSplitIndex:ti,handleInsertToSplit:eu,handleInsertConsumed:ei,handleInsertToMessage:ed,autoYesStateMap:k,makeAutoYesToggleHandler:e6,showArchived:th,onShowArchivedChange:eO,historyDisplayLimit:e$,onHistoryDisplayLimitChange:en,historyUserOnly:eJ,onHistoryUserOnlyChange:ea,onMessageSent:ey,onFilePathClick:Z,showToast:tf,tabsState:ty,tabsActions:tv,onLoadContent:eb,onLoadError:ev,onSetLoading:ez,onFilePanelSave:Q,onDirtyChange:q,onOpenFile:eL,diffContent:N,diffFilePath:T,onCloseDiff:U,fileSearch:F,fileTreeRefresh:z,onFileSelect:et,onNewFile:eE,onNewDirectory:eT,onRename:eR,onDelete:K,onUpload:e_,onMove:eN,onFileTreeReset:tj,onDiffSelect:$,onAgentInstancesChange:W,vibeLocalModel:tC,onVibeLocalModelChange:eV,vibeLocalContextWindow:tN,onVibeLocalContextWindowChange:eW,isInfoModalOpen:eG,onInfoModalClose:eo,onWorktreeUpdate:tm,fileInputRef:D,onFileInputChange:X,onKillSession:ef,onRequestSessionEnd:ex,killTarget:eg,isKillPending:ep,onKillCancel:em,onKillConfirm:eh,moveTarget:e7,isMoveDialogOpen:eQ,onMoveCancel:eC,onMoveConfirm:eS,showNewFileDialog:tx,newFileParentPath:te,onNewFileConfirm:eM,onNewFileCancel:eI,toasts:tw,onToastClose:tr,killDialogTitle:tb("session.confirmEnd",{tool:tz}),killDialogWarning:tb("session.endWarning"),cancelLabel:tp("cancel"),endLabel:tp("end")}),M&&(0,r.jsx)(e0.a,{isOpen:!0,onClose:J,title:M.split("/").pop()||tb("fileViewer.editor"),size:"full",disableClose:eY,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(s_,{worktreeId:m,filePath:M,onClose:J,onSave:G,onMaximizedChange:tu})})})]})});function sV(){let e=(0,s.useParams)().id;return(0,r.jsx)(l.GV,{children:(0,r.jsx)(sH,{worktreeId:e})})}},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:o=!0,axis:i="both",directionLock:c,directionLockThreshold:d=12,suppressWhenScrollable:u=!0,edgeStartZone:m=0,onSwipeMove:h,onSwipeEnd:x}=e,f=null!=c?c:"both"!==i,g="horizontal"===i?"horizontal":"vertical",p="both"===i||"horizontal"===i,b="both"===i||"vertical"===i,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(!o)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,g)){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)},[o,u,g,m]),E=(0,a.useCallback)(e=>{if(!o||!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(f){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!==i){e.cancelled=!0;return}}if(null!==e.committed&&e.committed!==i)return}}p&&r>s&&r>=l?k(n<0?"left":"right"):b&&s>=l&&k(a<0?"up":"down"),null==h||h({deltaX:n,deltaY:a})},[o,l,i,f,d,p,b,h]),I=(0,a.useCallback)(e=>{var a;if(!o||!N.current)return void j(!1);let i=f&&(null==(a=C.current)?void 0:a.cancelled)===!0,c=e.changedTouches[0];if(!i&&c){let e=c.clientX-N.current.x,a=c.clientY-N.current.y,o=Math.abs(e),i=Math.abs(a);o>i?p&&o>=l&&(e<0?(k("left"),null==t||t()):(k("right"),null==n||n())):b&&i>=l&&(a<0?(k("up"),null==r||r()):(k("down"),null==s||s()))}N.current=null,C.current=null,j(!1),null==x||x()},[o,l,f,p,b,t,n,r,s,x]),M=(0,a.useCallback)(()=>{N.current&&(N.current=null,C.current=null,j(!1),null==x||x())},[x]);return(0,a.useEffect)(()=>{let e=v.current;if(e)return e.addEventListener("touchstart",T),e.addEventListener("touchmove",E),e.addEventListener("touchend",I),e.addEventListener("touchcancel",M),()=>{e.removeEventListener("touchstart",T),e.removeEventListener("touchmove",E),e.removeEventListener("touchend",I),e.removeEventListener("touchcancel",M)}},[T,E,I,M]),{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,o=(0,s.c)("worktree"),[i,c]=(0,r.useState)(!1);return i?(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:o("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:()=>o,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),o=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,5235))},27307:(e,t,n)=>{"use strict";n.r(t),n.d(t,{PdfPreview:()=>i,default:()=>c});var a=n(95155),r=n(12115),s=n(18955);n(19985);let l=void 0;var o=n(3005);function i(e){let{dataUri:t,filePath:n,variant:i="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)(o.y,{size:"xl",variant:"accent"})});if("download"===i){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=i},46892:(e,t,n)=>{"use strict";n.d(t,{PL:()=>r,sb:()=>s});let a={idle:"bg-muted-foreground",ready:"bg-success",spinner:"border-info",waiting:"bg-warning"},r={idle:{className:a.idle,labelKey:"status.idle",type:"dot"},ready:{className:a.ready,labelKey:"status.ready",type:"dot"},running:{className:a.spinner,labelKey:"status.running",type:"spinner"},waiting:{className:a.waiting,labelKey:"status.waiting",type:"dot"},generating:{className:a.spinner,labelKey:"status.generating",type:"spinner"}},s={idle:"detailStatus.idle",ready:"detailStatus.ready",running:"detailStatus.running",waiting:"detailStatus.waiting"}},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),o=(0,a.useCallback)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport,n=window.innerHeight,a=e.height,s=n-a,o=s>100;t(o),r(o?s:0),l(a)},[]);return(0,a.useEffect)(()=>{if(null==window.visualViewport)return;let e=window.visualViewport;return o(),e.addEventListener("resize",o),()=>{e.removeEventListener("resize",o)}},[o]),{isKeyboardVisible:e,keyboardHeight:n,viewportHeight:s}}},53292:(e,t,n)=>{"use strict";n.d(t,{Ll:()=>a,bu:()=>r});let a=2e3,r=4e3},53482:(e,t,n)=>{"use strict";n.d(t,{i:()=>c});var a=n(95155),r=n(12115),s=n(60322),l=n(9900);function o(){return(0,a.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function i(){return(0,a.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function c(e){let{text:t,className:n="",label:c="Copy"}=e,[d,u]=(0,r.useState)(!1),m=(0,r.useRef)(null);(0,r.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=(0,r.useCallback)(async()=>{try{await (0,s.l)(t),u(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>u(!1),l.s7)}catch(e){}},[t]);return(0,a.jsxs)("button",{type:"button",onClick:h,className:"inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground transition-colors hover:bg-muted ".concat(n),"aria-label":d?"Copied":c,title:d?"Copied!":c,children:[d?(0,a.jsx)(i,{}):(0,a.jsx)(o,{}),(0,a.jsx)("span",{children:d?"Copied":c})]})}},60322:(e,t,n)=>{"use strict";n.d(t,{l:()=>r});let a=/\x1b\[[0-9;]*[a-zA-Z]|\x1b\][^\x07]*\x07|\[[0-9;]*m/g;async function r(e){var t;if(!e||0===e.trim().length)return;let n=e.replace(a,"");if(null==(t=navigator.clipboard)?void 0:t.writeText)try{await navigator.clipboard.writeText(n);return}catch(e){}let r=document.createElement("textarea");r.value=n,r.style.position="fixed",r.style.left="-9999px",r.style.top="-9999px",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();try{document.execCommand("copy")}finally{document.body.removeChild(r)}}},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:o}=e,[i,c]=(0,a.useState)(!1),[d,u]=(0,a.useState)(null),m=(0,a.useRef)(t),h=(0,a.useRef)(n),x=(0,a.useRef)(o),f=(0,a.useRef)(null),g=(0,a.useRef)(!0),p=(0,a.useRef)(t);(0,a.useEffect)(()=>{m.current=t},[t]),(0,a.useEffect)(()=>{h.current=n},[n]),(0,a.useEffect)(()=>{x.current=o},[o]),(0,a.useEffect)(()=>(g.current=!0,()=>{g.current=!1,f.current&&clearTimeout(f.current)}),[]);let b=(0,a.useCallback)(async e=>{if(!g.current)return;c(!0),u(null);let t=null,n=0;for(;n<=l;)try{if(await h.current(e),g.current){var a;c(!1),u(null),null==(a=x.current)||a.call(x)}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))}}g.current&&(c(!1),u(t))},[l]),v=(0,a.useCallback)(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),y=(0,a.useCallback)(async()=>{s||(v(),await b(m.current))},[s,v,b]);return(0,a.useEffect)(()=>{if(t!==p.current&&!s)return v(),f.current=setTimeout(()=>{b(m.current)},r),()=>{v()}},[t,s,r,v,b]),{isSaving:i,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 o(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}n.d(t,{Nt:()=>r,W5:()=>l,ZD:()=>o,q3:()=>s,sg:()=>a})},69264:(e,t,n)=>{"use strict";n.d(t,{u:()=>o});var a=n(95155),r=n(12115),s=n(18955),l=n(3005);function o(e){let{src:t,onError:n}=e,o=(0,s.c)("worktree"),[i,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:o("videoViewer.loadError")})]}):(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center p-4",children:[i&&(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:o("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:i?"none":"block"},className:"rounded-lg shadow-sm",children:o("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"],o=["w-1","h-full","cursor-col-resize","before:content-['']","before:absolute","before:inset-y-0","before:-inset-x-1"],i=["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"),[x,f]=(0,r.useState)(!1),g=(0,r.useRef)(0),p=(0,r.useRef)(null),b="horizontal"===n,v=(0,r.useCallback)(e=>{e.preventDefault(),f(!0),g.current=c(e,b)},[b]),y=(0,r.useCallback)(e=>{1===e.touches.length&&(f(!0),g.current=c(e,b))},[b]),j=(0,r.useCallback)(e=>{if(!x)return;let n=c(e,b);t(n-g.current),g.current=n},[x,b,t]),w=(0,r.useCallback)(e=>{if(!x||1!==e.touches.length)return;let n=c(e,b);t(n-g.current),g.current=n},[x,b,t]),k=(0,r.useCallback)(()=>{f(!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)(()=>(x&&(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=""}),[x,j,k,w,b]);let S=(0,r.useMemo)(()=>[...l,...b?o:i,...x?["bg-accent-500","dark:bg-accent-500","dragging",b?"w-2":"h-2"]:[]].join(" "),[b,x]);return(0,a.jsx)("div",{ref:p,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})})},76246:(e,t,n)=>{"use strict";function a(e){return e?e.split("/").map(encodeURIComponent).join("/"):""}n.d(t,{o:()=>a})},83012:(e,t,n)=>{"use strict";n.d(t,{Fx:()=>l,bg:()=>o,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 o(e,t){return!(e instanceof Date)||isNaN(e.getTime())?"":(0,r.GP)(e,"PPp",t?{locale:t}:void 0)}},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")}}}},e=>{e.O(0,[6481,6809,4909,2770,3165,4974,9948,2069,8965,6402,744,7347,8954,8441,1255,7358],()=>e(e.s=20252)),_N_E=e.O()}]);
|