commandmate 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +11 -11
  3. package/.next/app-path-routes-manifest.json +1 -1
  4. package/.next/build-manifest.json +2 -2
  5. package/.next/cache/.tsbuildinfo +1 -1
  6. package/.next/cache/config.json +3 -3
  7. package/.next/cache/webpack/client-production/0.pack +0 -0
  8. package/.next/cache/webpack/client-production/1.pack +0 -0
  9. package/.next/cache/webpack/client-production/2.pack +0 -0
  10. package/.next/cache/webpack/client-production/index.pack +0 -0
  11. package/.next/cache/webpack/client-production/index.pack.old +0 -0
  12. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  13. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  14. package/.next/cache/webpack/server-production/0.pack +0 -0
  15. package/.next/cache/webpack/server-production/index.pack +0 -0
  16. package/.next/next-server.js.nft.json +1 -1
  17. package/.next/prerender-manifest.json +1 -1
  18. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  19. package/.next/server/app/_not-found.html +1 -1
  20. package/.next/server/app/_not-found.rsc +1 -1
  21. package/.next/server/app/api/worktrees/[id]/route.js +1 -1
  22. package/.next/server/app/api/worktrees/[id]/send/route.js +1 -1
  23. package/.next/server/app/index.html +2 -2
  24. package/.next/server/app/index.rsc +2 -2
  25. package/.next/server/app/page.js +1 -1
  26. package/.next/server/app/page_client-reference-manifest.js +1 -1
  27. package/.next/server/app/worktrees/[id]/files/[...path]/page_client-reference-manifest.js +1 -1
  28. package/.next/server/app/worktrees/[id]/page.js +5 -5
  29. package/.next/server/app/worktrees/[id]/page_client-reference-manifest.js +1 -1
  30. package/.next/server/app/worktrees/[id]/simple-terminal/page_client-reference-manifest.js +1 -1
  31. package/.next/server/app/worktrees/[id]/terminal/page_client-reference-manifest.js +1 -1
  32. package/.next/server/app-paths-manifest.json +8 -8
  33. package/.next/server/chunks/7425.js +84 -17
  34. package/.next/server/functions-config-manifest.json +1 -1
  35. package/.next/server/middleware-manifest.json +5 -5
  36. package/.next/server/pages/404.html +1 -1
  37. package/.next/server/pages/500.html +1 -1
  38. package/.next/server/server-reference-manifest.json +1 -1
  39. package/.next/static/chunks/app/{page-9cd00de9cc0abc43.js → page-96a8aa2ec30a44e9.js} +1 -1
  40. package/.next/static/chunks/app/worktrees/[id]/page-aea2d5e7e28955be.js +1 -0
  41. package/.next/static/css/{e174aa24f94ce607.css → 376b339640084689.css} +1 -1
  42. package/.next/trace +5 -5
  43. package/dist/cli/commands/start.d.ts.map +1 -1
  44. package/dist/cli/commands/start.js +23 -1
  45. package/dist/server/src/lib/db-migrations.js +76 -1
  46. package/dist/server/src/lib/db.js +42 -0
  47. package/package.json +1 -1
  48. package/.next/static/chunks/app/worktrees/[id]/page-8c6676303b63fdaf.js +0 -1
  49. /package/.next/static/{KtDmF-FzoCLvoKXEcXyU- → 8o5rUyZun0GklIHWDgkmv}/_buildManifest.js +0 -0
  50. /package/.next/static/{KtDmF-FzoCLvoKXEcXyU- → 8o5rUyZun0GklIHWDgkmv}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1931],{14564:function(e,t,a){Promise.resolve().then(a.bind(a,89707))},89707:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return C}});var s=a(57437),r=a(2265),l=a(63671),n=a(27648),i=a(10789),c=a(94747),o=a(69073),d=a(3227);function x(e){var t,a,l,x;let{worktree:m,onSessionKilled:p,onStatusChanged:u}=e,{id:h,name:g,description:y,lastMessagesByCli:b,updatedAt:v,isSessionRunning:f,isWaitingForResponse:j,favorite:N,status:w,link:k,sessionStatusByCli:C}=m,[S,z]=(0,r.useState)(!1),[P,E]=(0,r.useState)(N||!1),[A,L]=(0,r.useState)(!1),[R,T]=(0,r.useState)(w||null),[D,I]=(0,r.useState)(!1),O=v?(0,c.Q)(new Date(v),{addSuffix:!0,locale:o.ja}):null,M="main"===g||"master"===g,F=async e=>{if(e.preventDefault(),e.stopPropagation(),confirm("「".concat(g,"」のセッションを終了しますか?\n\n※全てのメッセージ履歴が削除されます。ログファイルは保持されます。")))try{z(!0),await d.Iv.killSession(h),p&&p()}catch(t){let e=(0,d.zG)(t);alert("セッションの終了に失敗しました: ".concat(e))}finally{z(!1)}},W=async e=>{e.preventDefault(),e.stopPropagation();try{L(!0);let e=!P;await d.Iv.toggleFavorite(h,e),E(e)}catch(t){let e=(0,d.zG)(t);alert("お気に入りの更新に失敗しました: ".concat(e))}finally{L(!1)}},_=async(e,t)=>{t.preventDefault(),t.stopPropagation();try{I(!0),await d.Iv.updateStatus(h,e),T(e),u&&u()}catch(t){let e=(0,d.zG)(t);alert("ステータスの更新に失敗しました: ".concat(e))}finally{I(!1)}};return(0,s.jsx)(n.default,{href:"/worktrees/".concat(h),className:"block",children:(0,s.jsxs)(i.Zb,{hover:!0,padding:"lg",className:"h-full",children:[(0,s.jsx)(i.Ol,{children:(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)(i.ll,{className:"flex items-center gap-2 flex-wrap",children:[(0,s.jsx)("button",{onClick:W,disabled:A,className:"flex-shrink-0 transition-colors hover:scale-110",title:P?"お気に入りを解除":"お気に入りに追加",children:(0,s.jsx)("svg",{className:"w-5 h-5 ".concat(P?"fill-yellow-400 text-yellow-400":"fill-none text-gray-400"),stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.48 3.499a.562.562 0 011.04 0l2.125 5.111a.563.563 0 00.475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 00-.182.557l1.285 5.385a.562.562 0 01-.84.61l-4.725-2.885a.563.563 0 00-.586 0L6.982 20.54a.562.562 0 01-.84-.61l1.285-5.386a.562.562 0 00-.182-.557l-4.204-3.602a.563.563 0 01.321-.988l5.518-.442a.563.563 0 00.475-.345L11.48 3.5z"})})}),(0,s.jsx)("span",{className:"truncate",children:g}),M&&(0,s.jsx)(i.Ct,{variant:"info",children:"Main"}),f&&j&&(0,s.jsx)(i.Ct,{variant:"warning",dot:!0,children:"レスポンス待ち"}),f&&!j&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,children:"レスポンス完了"})]}),f&&(0,s.jsx)(i.zx,{variant:"danger",size:"sm",onClick:F,disabled:S,className:"flex-shrink-0",children:S?"終了中...":"終了"})]})}),(0,s.jsx)(i.aY,{children:(0,s.jsxs)("div",{className:"space-y-3",children:[y&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Description"}),(0,s.jsx)("p",{className:"text-sm text-gray-700 line-clamp-2 whitespace-pre-wrap",children:y})]}),k&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Link"}),(0,s.jsxs)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),k&&window.open(k,"_blank","noopener,noreferrer")},className:"flex items-center gap-1 text-sm text-blue-600 hover:text-blue-800 hover:underline transition-colors",title:"Open link in new tab",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),(0,s.jsx)("span",{className:"truncate",children:k})]})]}),(b||C)&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-2",children:"Last Messages & Status"}),(0,s.jsx)("div",{className:"space-y-1.5",children:((null==b?void 0:b.claude)||(null==C?void 0:C.claude))&&(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,s.jsx)(i.Ct,{variant:"info",className:"text-xs",children:"Claude"}),(null==C?void 0:null===(t=C.claude)||void 0===t?void 0:t.isRunning)&&(null==C?void 0:null===(a=C.claude)||void 0===a?void 0:a.isWaitingForResponse)&&(0,s.jsx)(i.Ct,{variant:"warning",dot:!0,className:"text-xs",children:"待機中"}),(null==C?void 0:null===(l=C.claude)||void 0===l?void 0:l.isRunning)&&!(null==C?void 0:null===(x=C.claude)||void 0===x?void 0:x.isWaitingForResponse)&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,className:"text-xs",children:"完了"})]}),(null==b?void 0:b.claude)&&(0,s.jsx)("p",{className:"text-sm text-gray-700 line-clamp-1 flex-1",children:b.claude})]})})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Status"}),(0,s.jsxs)("div",{className:"flex gap-1 flex-wrap",children:[(0,s.jsx)("button",{onClick:e=>_(null,e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat(null===R?"bg-gray-100 text-gray-700 border-gray-400":"bg-white text-gray-600 border-gray-200 hover:bg-gray-50"),children:"Not set"}),(0,s.jsx)("button",{onClick:e=>_("todo",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("todo"===R?"bg-gray-100 text-gray-700 border-gray-400":"bg-white text-gray-600 border-gray-200 hover:bg-gray-50"),children:"ToDo"}),(0,s.jsx)("button",{onClick:e=>_("doing",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("doing"===R?"bg-blue-100 text-blue-700 border-blue-400":"bg-white text-gray-600 border-gray-200 hover:bg-blue-50"),children:"Doing"}),(0,s.jsx)("button",{onClick:e=>_("done",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("done"===R?"bg-green-100 text-green-700 border-green-400":"bg-white text-gray-600 border-gray-200 hover:bg-green-50"),children:"Done"})]})]}),O&&(0,s.jsxs)("div",{className:"flex items-center text-xs text-gray-500",children:[(0,s.jsx)("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,s.jsxs)("span",{children:["Updated ",O]})]})]})})]})})}var m=a(40257);function p(e){let t=m.env.NEXT_PUBLIC_WORKTREE_REPOS;return!!t&&t.split(",").map(e=>e.trim()).includes(e)}function u(e){let{initialWorktrees:t=[]}=e,[a,l]=(0,r.useState)(t),[n,c]=(0,r.useState)([]),[o,m]=(0,r.useState)(!t.length),[u,h]=(0,r.useState)(null),[g,y]=(0,r.useState)(""),[b,v]=(0,r.useState)("updated"),[f,j]=(0,r.useState)("desc"),[N,w]=(0,r.useState)(null),[k,C]=(0,r.useState)(null),[S,z]=(0,r.useState)(null),P=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{e||m(!0),h(null);let t=await d.Iv.getAll();l(t.worktrees),c(t.repositories)}catch(e){h((0,d.zG)(e))}finally{e||m(!1)}},[]),E=e=>!!(e&&"session_status_changed"===e.type),{status:A}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{worktreeIds:t=[],onMessage:a,onStatusChange:s,autoReconnect:l=!0,reconnectDelay:n=3e3}=e,[i,c]=(0,r.useState)("disconnected"),o=(0,r.useRef)(null),d=(0,r.useRef)(),x=(0,r.useRef)(new Set),m=(0,r.useCallback)(e=>{c(e),null==s||s(e)},[s]),p=(0,r.useCallback)(()=>{var e;if((null===(e=o.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;m("connecting");let t="https:"===window.location.protocol?"wss:":"ws:",s=new WebSocket("".concat(t,"//").concat(window.location.host));s.onopen=()=>{m("connected"),x.current.forEach(e=>{s.send(JSON.stringify({type:"subscribe",worktreeId:e}))})},s.onmessage=e=>{try{let t=JSON.parse(e.data);null==a||a(t)}catch(e){console.error("Failed to parse WebSocket message:",e)}},s.onerror=()=>{m("error")},s.onclose=()=>{m("disconnected"),o.current=null,l&&(d.current=setTimeout(()=>{p()},n))},o.current=s},[m,a,l,n]),u=(0,r.useCallback)(()=>{d.current&&clearTimeout(d.current),o.current&&(o.current.close(1e3,"Client disconnect"),o.current=null),m("disconnected")},[m]),h=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&(o.current.send(JSON.stringify({type:"subscribe",worktreeId:e})),x.current.add(e))},[]),g=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&(o.current.send(JSON.stringify({type:"unsubscribe",worktreeId:e})),x.current.delete(e))},[]),y=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify(e))},[]);return(0,r.useEffect)(()=>(p(),()=>{u()}),[]),(0,r.useEffect)(()=>{"connected"===i&&t.length>0&&t.forEach(e=>{h(e)})},[i,t]),{status:i,subscribe:h,unsubscribe:g,sendMessage:y,connect:p,disconnect:u}}({onMessage:(0,r.useCallback)(e=>{if(E(e.data)){let t=e.data;l(e=>e.map(e=>e.id===t.worktreeId?{...e,isSessionRunning:t.isRunning}:e))}"broadcast"===e.type&&P(!0)},[P])});(0,r.useEffect)(()=>{t.length||P()},[t.length,P]),(0,r.useEffect)(()=>{let e=setInterval(()=>{P(!0)},5e3);return()=>clearInterval(e)},[P]);let L=(0,r.useMemo)(()=>{let e=[...a];if(N&&(e=e.filter(e=>e.repositoryPath===N)),null!==k&&(e="unset"===k?e.filter(e=>!e.status):e.filter(e=>e.status===k)),g){let t=g.toLowerCase();e=e.filter(e=>{var a,s;return e.name.toLowerCase().includes(t)||e.path.toLowerCase().includes(t)||e.repositoryName.toLowerCase().includes(t)||(null===(a=e.lastMessageSummary)||void 0===a?void 0:a.toLowerCase().includes(t))||(null===(s=e.description)||void 0===s?void 0:s.toLowerCase().includes(t))})}return e.sort((e,t)=>{let a=0;switch(b){case"name":a=e.name.localeCompare(t.name);break;case"updated":a=(e.updatedAt?new Date(e.updatedAt).getTime():0)-(t.updatedAt?new Date(t.updatedAt).getTime():0);break;case"favorite":a=(e.favorite?1:0)-(t.favorite?1:0)}return"asc"===f?a:-a}),e},[a,N,k,g,b,f]),R=(0,r.useMemo)(()=>{let e=new Map;for(let t of L){let a=t.repositoryPath||"unknown";e.has(a)||e.set(a,[]),e.get(a).push(t)}return e},[L]),T=e=>{b===e?j(e=>"asc"===e?"desc":"asc"):(v(e),j("asc"))},D=async(e,t)=>{var a;let s=(null===(a=n.find(t=>t.path===e))||void 0===a?void 0:a.worktreeCount)||0,r=p(e),l='Delete repository "'.concat(t,'"?\n\nThis will delete:\n- ').concat(s," worktree(s)\n- Related chat history\n- Related memos\n\n* Log files will be preserved");if(r&&(l+='\n\nWARNING: This repository is configured in environment variable (WORKTREE_REPOS).\nIt will be re-registered when you run "Sync All".\nTo permanently remove it, also update the environment variable.'),"delete"===prompt(l+='\n\nType "delete" to confirm:')){z(e);try{await d.J1.delete(e),N===e&&w(null),await P()}catch(e){h((0,d.zG)(e))}finally{z(null)}}};return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,s.jsxs)(i.Ct,{variant:"gray",children:[a.length," branches"]}),n.length>0&&(0,s.jsxs)(i.Ct,{variant:"info",children:[n.length," ",1===n.length?"repository":"repositories"]}),"connected"===A&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,children:"Live"})]}),(0,s.jsx)("div",{className:"flex gap-2 w-full sm:w-auto",children:(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:()=>P(),disabled:o,children:o?"Loading...":"Refresh"})})]}),(0,s.jsx)("div",{className:"flex flex-col sm:flex-row gap-3",children:(0,s.jsx)("input",{type:"text",placeholder:"Search worktrees...",value:g,onChange:e=>y(e.target.value),className:"input flex-1"})}),n.length>1&&(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[(0,s.jsxs)(i.zx,{variant:null===N?"primary":"ghost",size:"sm",onClick:()=>w(null),children:["All (",a.length,")"]}),n.map(e=>(0,s.jsxs)("div",{className:"relative group inline-flex items-center",children:[(0,s.jsxs)(i.zx,{variant:N===e.path?"primary":"ghost",size:"sm",onClick:()=>w(e.path),className:"pr-6",children:[e.name," (",e.worktreeCount,")",p(e.path)&&(0,s.jsx)("span",{title:"Configured in environment variable",className:"ml-1 text-amber-500",children:"!"})]}),(0,s.jsx)("button",{className:"absolute right-1 opacity-0 group-hover:opacity-100 text-gray-400 hover:text-red-500 transition-opacity px-1",onClick:t=>{t.stopPropagation(),D(e.path,e.name)},disabled:S===e.path,title:"Delete repository",children:S===e.path?"...":"x"})]},e.path))]}),(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[(0,s.jsx)(i.zx,{variant:null===k?"primary":"ghost",size:"sm",onClick:()=>C(null),children:"All"}),(0,s.jsx)(i.zx,{variant:"todo"===k?"primary":"ghost",size:"sm",onClick:()=>C("todo"),children:"\uD83D\uDCDD ToDo"}),(0,s.jsx)(i.zx,{variant:"doing"===k?"primary":"ghost",size:"sm",onClick:()=>C("doing"),children:"\uD83D\uDEA7 Doing"}),(0,s.jsx)(i.zx,{variant:"done"===k?"primary":"ghost",size:"sm",onClick:()=>C("done"),children:"✅ Done"}),(0,s.jsx)(i.zx,{variant:"unset"===k?"primary":"ghost",size:"sm",onClick:()=>C("unset"),children:"Not set"})]}),(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600 self-center",children:"Sort by:"}),(0,s.jsxs)(i.zx,{variant:"favorite"===b?"primary":"ghost",size:"sm",onClick:()=>T("favorite"),children:["⭐ Favorite ","favorite"===b&&("asc"===f?"↑":"↓")]}),(0,s.jsxs)(i.zx,{variant:"name"===b?"primary":"ghost",size:"sm",onClick:()=>T("name"),children:["Name ","name"===b&&("asc"===f?"↑":"↓")]}),(0,s.jsxs)(i.zx,{variant:"updated"===b?"primary":"ghost",size:"sm",onClick:()=>T("updated"),children:["Updated ","updated"===b&&("asc"===f?"↑":"↓")]})]}),u&&(0,s.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-red-800",children:u})}),o&&!a.length&&(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,s.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading worktrees..."})]}),!o&&!u&&0===L.length&&(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,s.jsx)("p",{className:"mt-4 text-gray-600",children:g?"No worktrees found matching your search":"No worktrees found"})]}),!o&&L.length>0&&(0,s.jsx)("div",{className:"space-y-8",children:Array.from(R.entries()).map(e=>{let[t,a]=e,r=n.find(e=>e.path===t),l=(null==r?void 0:r.name)||"Unknown Repository";return(0,s.jsxs)("div",{className:"space-y-4",children:[(n.length>1||!N)&&(0,s.jsxs)("div",{className:"flex items-center gap-3 pb-2 border-b border-gray-200",children:[(0,s.jsx)("h3",{className:"text-xl font-semibold text-gray-900",children:l}),(0,s.jsx)(i.Ct,{variant:"gray",children:a.length})]}),(0,s.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:a.map(e=>(0,s.jsx)(x,{worktree:e,onSessionKilled:P,onStatusChanged:P},e.id))})]},t)})})]})}a(99376),a(34343),a(6940);class h{static getInstance(){return h.instance||(h.instance=new h),h.instance}normalize(e){let t=e.match(/^ssh:\/\/git@([^:\/]+)(:\d+)?\/(.+?)(\.git)?$/);if(t)return"https://".concat(t[1],"/").concat(t[3]).toLowerCase().replace(/\/$/,"");let a=e.match(/^git@([^:]+):(.+?)(\.git)?$/);return a?"https://".concat(a[1],"/").concat(a[2]).toLowerCase().replace(/\/$/,""):e.replace(/\.git\/?$/,"").replace(/\/$/,"").toLowerCase()}isSameRepository(e,t){return this.normalize(e)===this.normalize(t)}extractRepoName(e){let t=e.match(/^ssh:\/\/git@[^\/]+\/(.+?)(\.git)?$/);if(t){let e=t[1].split("/");return e[e.length-1]}let a=e.match(/:(.+?)(\.git)?$/);if(a&&e.startsWith("git@")){let e=a[1].split("/");return e[e.length-1]}let s=e.match(/\/([^\/]+?)(\.git)?$/);return s?s[1]:""}getUrlType(e){return e.startsWith("https://")?"https":e.startsWith("git@")||e.startsWith("ssh://")?"ssh":null}validate(e){if(!e||"string"!=typeof e||""===e.trim())return{valid:!1,error:"EMPTY_URL"};let t=e.trim();return t.startsWith("https://")?/^https:\/\/[^\/]+\/[^\/]+\/[^\/]+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}:t.startsWith("git@")?/^git@[^:]+:.+\/.+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}:t.startsWith("ssh://")&&/^ssh:\/\/git@[^\/]+(:\d+)?\/[^\/]+\/.+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}}constructor(){}}function g(e){let{onRepositoryAdded:t}=e,[a,l]=(0,r.useState)(!1),[n,c]=(0,r.useState)("local"),[o,x]=(0,r.useState)(""),[m,p]=(0,r.useState)(""),[u,g]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[v,f]=(0,r.useState)(!1),[j,N]=(0,r.useState)(null),[w,k]=(0,r.useState)(null),[C,S]=(0,r.useState)(null),z=h.getInstance(),P=(0,r.useCallback)(async e=>{try{let s=await d.J1.getCloneStatus(e);if("completed"===s.status)S("Repository cloned successfully"),f(!1),N(null),p(""),l(!1),t&&t();else if("failed"===s.status){var a;k((null===(a=s.error)||void 0===a?void 0:a.message)||"Clone failed"),f(!1),N(null)}else("running"===s.status||"pending"===s.status)&&setTimeout(()=>P(e),2e3)}catch(e){k((0,d.zG)(e)),f(!1),N(null)}},[t]);(0,r.useEffect)(()=>{j&&v&&P(j)},[j,v,P]);let E=async e=>{if(e.preventDefault(),!o.trim()){k("Repository path is required");return}k(null),S(null),g(!0);try{let e=await d.J1.scan(o);S(e.message),x(""),l(!1),t&&t()}catch(e){k((0,d.zG)(e))}finally{g(!1)}},A=async e=>{if(e.preventDefault(),!m.trim()){k("Clone URL is required");return}let t=z.validate(m.trim());if(!t.valid){"EMPTY_URL"===t.error?k("Clone URL is required"):k("Invalid URL format");return}k(null),S(null),f(!0);try{let e=await d.J1.clone(m.trim());N(e.jobId)}catch(e){k((0,d.zG)(e)),f(!1)}},L=async()=>{k(null),S(null),b(!0);try{let e=await d.J1.sync();S(e.message),t&&t()}catch(e){k((0,d.zG)(e))}finally{b(!1)}},R=()=>{l(!1),x(""),p(""),k(null),c("local")};return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[!a&&(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:()=>l(!0),children:"+ Add Repository"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:L,disabled:y,children:y?"Syncing...":"Sync All"})]}),a&&(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{children:(0,s.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Add New Repository"})}),(0,s.jsxs)("div",{className:"flex border-b border-gray-200",role:"tablist",children:[(0,s.jsx)("button",{role:"tab","aria-selected":"local"===n,onClick:()=>c("local"),className:"px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ".concat("local"===n?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"Local Path"}),(0,s.jsx)("button",{role:"tab","aria-selected":"url"===n,onClick:()=>c("url"),className:"px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ".concat("url"===n?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"Clone URL"})]}),"local"===n&&(0,s.jsxs)("form",{onSubmit:E,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"Enter the absolute path to a git repository containing worktrees."}),(0,s.jsx)("label",{htmlFor:"repositoryPath",className:"block text-sm font-medium text-gray-700 mb-2",children:"Repository Path"}),(0,s.jsx)("input",{id:"repositoryPath",type:"text",value:o,onChange:e=>x(e.target.value),placeholder:"/absolute/path/to/repository",className:"input w-full font-mono text-sm",disabled:u}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Example: /Users/username/projects/my-repo"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{type:"submit",variant:"primary",disabled:u||!o.trim(),children:u?"Scanning...":"Scan & Add"}),(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:R,disabled:u,children:"Cancel"})]})]}),"url"===n&&(0,s.jsxs)("form",{onSubmit:A,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"Enter a git clone URL to clone a remote repository."}),(0,s.jsx)("label",{htmlFor:"cloneUrl",className:"block text-sm font-medium text-gray-700 mb-2",children:"Clone URL"}),(0,s.jsx)("input",{id:"cloneUrl",type:"text",value:m,onChange:e=>p(e.target.value),placeholder:"https://github.com/user/repo.git",className:"input w-full font-mono text-sm",disabled:v}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Supports HTTPS and SSH URLs"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{type:"submit",variant:"primary",disabled:v||!m.trim(),children:v?"Cloning...":"Clone"}),(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:R,disabled:v,children:"Cancel"})]})]})]})}),C&&(0,s.jsx)("div",{className:"p-4 bg-green-50 border border-green-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-green-800",children:C})}),w&&(0,s.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-red-800",children:w})})]})}function y(e){var t;let{appId:a,pollInterval:l=3e4,showResponseTime:n=!1,compact:i=!1}=e,[c,o]=(0,r.useState)(null),[d,x]=(0,r.useState)(!0),m=(0,r.useCallback)(async()=>{try{let e=await fetch("/api/external-apps/".concat(a,"/health"));if(e.ok){let t=await e.json();o(t)}else o({id:a,healthy:!1,lastChecked:Date.now(),error:"Failed to check health"})}catch(e){o({id:a,healthy:!1,lastChecked:Date.now(),error:"Network error"})}finally{x(!1)}},[a]);if((0,r.useEffect)(()=>{m();let e=setInterval(m,l);return()=>clearInterval(e)},[m,l]),d)return(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full bg-gray-300 animate-pulse"}),!i&&(0,s.jsx)("span",{className:"text-xs text-gray-400",children:"Checking..."})]});let p=null!==(t=null==c?void 0:c.healthy)&&void 0!==t&&t,u=p?"bg-green-500":"bg-gray-400",h=p?"Running":"Stopped";return i?(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full ".concat(u),title:h}):(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full ".concat(u)}),(0,s.jsx)("span",{className:"text-xs ".concat(p?"text-green-600":"text-gray-500"),children:h}),n&&(null==c?void 0:c.responseTime)!==void 0&&(0,s.jsxs)("span",{className:"text-xs text-gray-400",children:["(",c.responseTime,"ms)"]})]})}function b(e){var t;let{app:a,onEdit:l,onDelete:n}=e,[c,o]=(0,r.useState)(!1),[d,x]=(0,r.useState)(!1),m=async()=>{x(!0);try{await n(a.id)}finally{x(!1),o(!1)}},p="/proxy/".concat(a.pathPrefix,"/");return(0,s.jsxs)(i.Zb,{padding:"md",className:"relative",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("h4",{className:"text-base font-semibold text-gray-900 truncate",children:a.displayName}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-0.5 font-mono truncate",children:a.name})]}),(0,s.jsx)(i.Ct,{variant:{sveltekit:"warning",streamlit:"error",nextjs:"info",other:"gray"}[a.appType]||"gray",children:{sveltekit:"SvelteKit",streamlit:"Streamlit",nextjs:"Next.js",other:"Other"}[t=a.appType]||t})]}),(0,s.jsxs)("div",{className:"space-y-2 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Status"}),(0,s.jsx)(y,{appId:a.id,pollInterval:3e4})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Port"}),(0,s.jsxs)("span",{className:"text-sm font-mono text-gray-900",children:[":",a.targetPort]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Path"}),(0,s.jsxs)("span",{className:"text-sm font-mono text-gray-900 truncate max-w-[150px]",children:["/proxy/",a.pathPrefix,"/"]})]}),a.websocketEnabled&&(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"WebSocket"}),(0,s.jsx)(i.Ct,{variant:"info",children:"Enabled"})]}),!a.enabled&&(0,s.jsx)("div",{className:"mt-2 py-1 px-2 bg-yellow-50 border border-yellow-200 rounded text-xs text-yellow-700",children:"This app is disabled"})]}),c?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("p",{className:"text-sm text-gray-600",children:['Delete "',a.displayName,'"?']}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{variant:"danger",size:"sm",onClick:m,disabled:d,loading:d,children:"Delete"}),(0,s.jsx)(i.zx,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:d,children:"Cancel"})]})]}):(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:()=>window.open(p,"_blank"),disabled:!a.enabled,children:"Open"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:()=>l(a),children:"Settings"}),(0,s.jsx)(i.zx,{variant:"ghost",size:"sm",onClick:()=>o(!0),className:"text-red-600 hover:bg-red-50",children:"Delete"})]})]})}let v={MIN:1024,MAX:65535},f=/^[a-zA-Z0-9-]+$/,j={sveltekit:"SvelteKit",streamlit:"Streamlit",nextjs:"Next.js",other:"Other"},N=["sveltekit","streamlit","nextjs","other"].map(e=>({value:e,label:j[e]}));function w(e){let{isOpen:t,onClose:a,editApp:l,onSave:n}=e,c=!!l,[o,d]=(0,r.useState)(""),[x,m]=(0,r.useState)(""),[p,u]=(0,r.useState)(""),[h,g]=(0,r.useState)(""),[y,b]=(0,r.useState)(""),[j,w]=(0,r.useState)(!1),[k,C]=(0,r.useState)(""),[S,z]=(0,r.useState)(!0),[P,E]=(0,r.useState)({}),[A,L]=(0,r.useState)(!1),[R,T]=(0,r.useState)(null);(0,r.useEffect)(()=>{t&&(l?(d(l.displayName),m(l.name),u(l.pathPrefix),g(l.targetPort),b(l.appType),w(l.websocketEnabled),C(l.description||""),z(l.enabled)):(d(""),m(""),u(""),g(""),b(""),w(!1),C(""),z(!0)),E({}),T(null))},[t,l]);let D=async e=>{e.preventDefault(),T(null);let t=function(e,t){var a,s,r,l;let n={};return((null===(a=e.displayName)||void 0===a?void 0:a.trim())||(n.displayName="Display name is required"),t||((null===(s=e.name)||void 0===s?void 0:s.trim())?f.test(e.name)||(n.name="Only alphanumeric characters and hyphens are allowed"):n.name="Identifier name is required",(null===(r=e.pathPrefix)||void 0===r?void 0:r.trim())?f.test(e.pathPrefix)||(n.pathPrefix="Only alphanumeric characters and hyphens are allowed"):n.pathPrefix="Path prefix is required"),e.targetPort)?"number"!=typeof e.targetPort||Number.isInteger(l=e.targetPort)&&l>=v.MIN&&l<=v.MAX||(n.targetPort="Port must be between ".concat(v.MIN," and ").concat(v.MAX)):n.targetPort="Port number is required",t||e.appType||(n.appType="App type is required"),n}({displayName:o,name:x,pathPrefix:p,targetPort:h,appType:y},c);if(Object.keys(t).length>0){E(t);return}E({}),L(!0);try{if(c&&l){let e=await fetch("/api/external-apps/".concat(l.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:o,description:k||void 0,targetPort:h||void 0,websocketEnabled:j,enabled:S})});if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to update app")}}else{let e=await fetch("/api/external-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:o,name:x,pathPrefix:p,targetPort:h,appType:y,websocketEnabled:j,description:k||void 0})});if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to create app")}}n(),a()}catch(e){T(e instanceof Error?e.message:"An error occurred")}finally{L(!1)}};return(0,s.jsx)(i.u_,{isOpen:t,onClose:a,title:c?"Edit External App":"Add External App",size:"md",children:(0,s.jsxs)("form",{onSubmit:D,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"displayName",className:"block text-sm font-medium text-gray-700 mb-1",children:["Display Name ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"displayName",type:"text",value:o,onChange:e=>d(e.target.value),className:"input w-full ".concat(P.displayName?"border-red-500":""),placeholder:"My App",disabled:A}),P.displayName&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.displayName})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"name",className:"block text-sm font-medium text-gray-700 mb-1",children:["Identifier Name ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"name",type:"text",value:x,onChange:e=>m(e.target.value),className:"input w-full font-mono ".concat(P.name?"border-red-500":""),placeholder:"my-app",disabled:A}),(0,s.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"Alphanumeric and hyphens only. Cannot be changed later."}),P.name&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.name})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"pathPrefix",className:"block text-sm font-medium text-gray-700 mb-1",children:["Path Prefix ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("span",{className:"text-sm text-gray-500 mr-1",children:"/proxy/"}),(0,s.jsx)("input",{id:"pathPrefix",type:"text",value:p,onChange:e=>u(e.target.value),className:"input flex-1 font-mono ".concat(P.pathPrefix?"border-red-500":""),placeholder:"app-name",disabled:A}),(0,s.jsx)("span",{className:"text-sm text-gray-500 ml-1",children:"/"})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"URL path for accessing this app. Cannot be changed later."}),P.pathPrefix&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.pathPrefix})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"targetPort",className:"block text-sm font-medium text-gray-700 mb-1",children:["Port Number ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"targetPort",type:"number",value:h,onChange:e=>g(e.target.value?parseInt(e.target.value,10):""),className:"input w-full font-mono ".concat(P.targetPort?"border-red-500":""),placeholder:"5173",min:v.MIN,max:v.MAX,disabled:A}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-gray-500",children:["Target port (",v.MIN,"-",v.MAX,")"]}),P.targetPort&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.targetPort})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"appType",className:"block text-sm font-medium text-gray-700 mb-1",children:["App Type ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsxs)("select",{id:"appType",value:y,onChange:e=>b(e.target.value),className:"input w-full ".concat(P.appType?"border-red-500":""),disabled:A,children:[(0,s.jsx)("option",{value:"",children:"Select app type..."}),N.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]}),P.appType&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.appType})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"description",className:"block text-sm font-medium text-gray-700 mb-1",children:"Description"}),(0,s.jsx)("textarea",{id:"description",value:k,onChange:e=>C(e.target.value),className:"input w-full",placeholder:"Optional description...",rows:2,disabled:A})]}),(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("input",{id:"websocketEnabled",type:"checkbox",checked:j,onChange:e=>w(e.target.checked),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",disabled:A}),(0,s.jsx)("label",{htmlFor:"websocketEnabled",className:"ml-2 text-sm text-gray-700",children:"Enable WebSocket support"})]}),c&&(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("input",{id:"enabled",type:"checkbox",checked:S,onChange:e=>z(e.target.checked),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",disabled:A}),(0,s.jsx)("label",{htmlFor:"enabled",className:"ml-2 text-sm text-gray-700",children:"App is enabled"})]}),R&&(0,s.jsx)("div",{className:"p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700",children:R}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-4 border-t border-gray-200",children:[(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:a,disabled:A,children:"Cancel"}),(0,s.jsx)(i.zx,{type:"submit",variant:"primary",loading:A,children:c?"Save Changes":"Add App"})]})]})})}function k(){let[e,t]=(0,r.useState)([]),[a,l]=(0,r.useState)(!0),[n,c]=(0,r.useState)(null),[o,d]=(0,r.useState)(!1),[x,m]=(0,r.useState)(null),p=(0,r.useCallback)(async()=>{try{c(null);let e=await fetch("/api/external-apps");if(!e.ok)throw Error("Failed to fetch external apps");let a=await e.json();t(a.apps||[])}catch(e){c(e instanceof Error?e.message:"An error occurred")}finally{l(!1)}},[]);(0,r.useEffect)(()=>{p();let e=setInterval(p,6e4);return()=>clearInterval(e)},[p]);let u=(0,r.useCallback)(e=>{m(e),d(!0)},[]),h=(0,r.useCallback)(()=>{m(null),d(!0)},[]),g=(0,r.useCallback)(async e=>{try{let t=await fetch("/api/external-apps/".concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to delete app")}p()}catch(e){console.error("Failed to delete app:",e)}},[p]),y=(0,r.useCallback)(()=>{p()},[p]),v=(0,r.useCallback)(()=>{d(!1),m(null)},[]);return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"External Apps"}),(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:h,children:"+ Add App"})]}),a?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,s.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),(0,s.jsx)("span",{className:"ml-3 text-gray-600",children:"Loading apps..."})]})}):n?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"text-center py-8",children:[(0,s.jsx)("p",{className:"text-red-600 mb-4",children:"Failed to load external apps"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:p,children:"Retry"})]})}):0===e.length?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"text-center py-8",children:[(0,s.jsx)("p",{className:"text-gray-500 mb-4",children:"No external apps registered yet."}),(0,s.jsx)("p",{className:"text-sm text-gray-400 mb-4",children:"Add an external app to proxy requests to other frontend applications."}),(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:h,children:"Add Your First App"})]})}):(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:e.map(e=>(0,s.jsx)(b,{app:e,onEdit:u,onDelete:g},e.id))}),(0,s.jsx)(w,{isOpen:o,onClose:v,editApp:x,onSave:y})]})}function C(){let[e,t]=(0,r.useState)(0),a=(0,r.useCallback)(()=>{t(e=>e+1)},[]);return(0,s.jsx)(l.Vw,{children:(0,s.jsxs)("div",{className:"container-custom py-8 overflow-auto h-full",children:[(0,s.jsxs)("div",{className:"mb-8",children:[(0,s.jsx)("h1",{className:"mb-2",children:"CommandMate"}),(0,s.jsx)("p",{className:"text-lg text-gray-600",children:"Git worktree management with Claude CLI and tmux sessions"})]}),(0,s.jsx)("div",{className:"mb-8",children:(0,s.jsx)(g,{onRepositoryAdded:a})}),(0,s.jsx)(u,{},e),(0,s.jsx)("div",{className:"mt-8",children:(0,s.jsx)(k,{})})]})})}}},function(e){e.O(0,[7648,9365,6725,816,2853,2971,2117,1744],function(){return e(e.s=14564)}),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1931],{14564:function(e,t,a){Promise.resolve().then(a.bind(a,89707))},89707:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return C}});var s=a(57437),r=a(2265),l=a(63671),n=a(27648),i=a(10789),c=a(94747),o=a(69073),d=a(3227);function x(e){var t,a,l,x;let{worktree:m,onSessionKilled:p,onStatusChanged:u}=e,{id:h,name:g,description:y,lastMessagesByCli:b,updatedAt:v,isSessionRunning:f,isWaitingForResponse:j,favorite:N,status:w,link:k,sessionStatusByCli:C}=m,[S,z]=(0,r.useState)(!1),[P,E]=(0,r.useState)(N||!1),[A,L]=(0,r.useState)(!1),[R,T]=(0,r.useState)(w||null),[D,I]=(0,r.useState)(!1),O=v?(0,c.Q)(new Date(v),{addSuffix:!0,locale:o.ja}):null,M="main"===g||"master"===g,F=async e=>{if(e.preventDefault(),e.stopPropagation(),confirm("「".concat(g,"」のセッションを終了しますか?\n\n※全てのメッセージ履歴が削除されます。ログファイルは保持されます。")))try{z(!0),await d.Iv.killSession(h),p&&p()}catch(t){let e=(0,d.zG)(t);alert("セッションの終了に失敗しました: ".concat(e))}finally{z(!1)}},W=async e=>{e.preventDefault(),e.stopPropagation();try{L(!0);let e=!P;await d.Iv.toggleFavorite(h,e),E(e)}catch(t){let e=(0,d.zG)(t);alert("お気に入りの更新に失敗しました: ".concat(e))}finally{L(!1)}},_=async(e,t)=>{t.preventDefault(),t.stopPropagation();try{I(!0),await d.Iv.updateStatus(h,e),T(e),u&&u()}catch(t){let e=(0,d.zG)(t);alert("ステータスの更新に失敗しました: ".concat(e))}finally{I(!1)}};return(0,s.jsx)(n.default,{href:"/worktrees/".concat(h),className:"block",children:(0,s.jsxs)(i.Zb,{hover:!0,padding:"lg",className:"h-full",children:[(0,s.jsx)(i.Ol,{children:(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)(i.ll,{className:"flex items-center gap-2 flex-wrap",children:[(0,s.jsx)("button",{onClick:W,disabled:A,className:"flex-shrink-0 transition-colors hover:scale-110",title:P?"お気に入りを解除":"お気に入りに追加",children:(0,s.jsx)("svg",{className:"w-5 h-5 ".concat(P?"fill-yellow-400 text-yellow-400":"fill-none text-gray-400"),stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.48 3.499a.562.562 0 011.04 0l2.125 5.111a.563.563 0 00.475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 00-.182.557l1.285 5.385a.562.562 0 01-.84.61l-4.725-2.885a.563.563 0 00-.586 0L6.982 20.54a.562.562 0 01-.84-.61l1.285-5.386a.562.562 0 00-.182-.557l-4.204-3.602a.563.563 0 01.321-.988l5.518-.442a.563.563 0 00.475-.345L11.48 3.5z"})})}),(0,s.jsx)("span",{className:"truncate",children:g}),M&&(0,s.jsx)(i.Ct,{variant:"info",children:"Main"}),f&&j&&(0,s.jsx)(i.Ct,{variant:"warning",dot:!0,children:"レスポンス待ち"}),f&&!j&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,children:"レスポンス完了"})]}),f&&(0,s.jsx)(i.zx,{variant:"danger",size:"sm",onClick:F,disabled:S,className:"flex-shrink-0",children:S?"終了中...":"終了"})]})}),(0,s.jsx)(i.aY,{children:(0,s.jsxs)("div",{className:"space-y-3",children:[y&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Description"}),(0,s.jsx)("p",{className:"text-sm text-gray-700 line-clamp-2 whitespace-pre-wrap",children:y})]}),k&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Link"}),(0,s.jsxs)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),k&&window.open(k,"_blank","noopener,noreferrer")},className:"flex items-center gap-1 text-sm text-blue-600 hover:text-blue-800 hover:underline transition-colors",title:"Open link in new tab",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),(0,s.jsx)("span",{className:"truncate",children:k})]})]}),(b||C)&&(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-2",children:"Last Messages & Status"}),(0,s.jsx)("div",{className:"space-y-1.5",children:((null==b?void 0:b.claude)||(null==C?void 0:C.claude))&&(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,s.jsx)(i.Ct,{variant:"info",className:"text-xs",children:"Claude"}),(null==C?void 0:null===(t=C.claude)||void 0===t?void 0:t.isRunning)&&(null==C?void 0:null===(a=C.claude)||void 0===a?void 0:a.isWaitingForResponse)&&(0,s.jsx)(i.Ct,{variant:"warning",dot:!0,className:"text-xs",children:"待機中"}),(null==C?void 0:null===(l=C.claude)||void 0===l?void 0:l.isRunning)&&!(null==C?void 0:null===(x=C.claude)||void 0===x?void 0:x.isWaitingForResponse)&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,className:"text-xs",children:"完了"})]}),(null==b?void 0:b.claude)&&(0,s.jsx)("p",{className:"text-sm text-gray-700 line-clamp-1 flex-1",children:b.claude})]})})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"Status"}),(0,s.jsxs)("div",{className:"flex gap-1 flex-wrap",children:[(0,s.jsx)("button",{onClick:e=>_(null,e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat(null===R?"bg-gray-100 text-gray-700 border-gray-400":"bg-white text-gray-600 border-gray-200 hover:bg-gray-50"),children:"Not set"}),(0,s.jsx)("button",{onClick:e=>_("todo",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("todo"===R?"bg-gray-100 text-gray-700 border-gray-400":"bg-white text-gray-600 border-gray-200 hover:bg-gray-50"),children:"ToDo"}),(0,s.jsx)("button",{onClick:e=>_("doing",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("doing"===R?"bg-blue-100 text-blue-700 border-blue-400":"bg-white text-gray-600 border-gray-200 hover:bg-blue-50"),children:"Doing"}),(0,s.jsx)("button",{onClick:e=>_("done",e),disabled:D,className:"px-2 py-1 text-xs font-medium rounded border transition-colors disabled:opacity-50 ".concat("done"===R?"bg-green-100 text-green-700 border-green-400":"bg-white text-gray-600 border-gray-200 hover:bg-green-50"),children:"Done"})]})]}),O&&(0,s.jsxs)("div",{className:"flex items-center text-xs text-gray-500",children:[(0,s.jsx)("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,s.jsxs)("span",{children:["Updated ",O]})]})]})})]})})}var m=a(40257);function p(e){let t=m.env.NEXT_PUBLIC_WORKTREE_REPOS;return!!t&&t.split(",").map(e=>e.trim()).includes(e)}function u(e){let{initialWorktrees:t=[]}=e,[a,l]=(0,r.useState)(t),[n,c]=(0,r.useState)([]),[o,m]=(0,r.useState)(!t.length),[u,h]=(0,r.useState)(null),[g,y]=(0,r.useState)(""),[b,v]=(0,r.useState)("updated"),[f,j]=(0,r.useState)("desc"),[N,w]=(0,r.useState)(null),[k,C]=(0,r.useState)(null),[S,z]=(0,r.useState)(null),P=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{e||m(!0),h(null);let t=await d.Iv.getAll();l(t.worktrees),c(t.repositories)}catch(e){h((0,d.zG)(e))}finally{e||m(!1)}},[]),E=e=>!!(e&&"session_status_changed"===e.type),{status:A}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{worktreeIds:t=[],onMessage:a,onStatusChange:s,autoReconnect:l=!0,reconnectDelay:n=3e3}=e,[i,c]=(0,r.useState)("disconnected"),o=(0,r.useRef)(null),d=(0,r.useRef)(),x=(0,r.useRef)(new Set),m=(0,r.useCallback)(e=>{c(e),null==s||s(e)},[s]),p=(0,r.useCallback)(()=>{var e;if((null===(e=o.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;m("connecting");let t="https:"===window.location.protocol?"wss:":"ws:",s=new WebSocket("".concat(t,"//").concat(window.location.host));s.onopen=()=>{m("connected"),x.current.forEach(e=>{s.send(JSON.stringify({type:"subscribe",worktreeId:e}))})},s.onmessage=e=>{try{let t=JSON.parse(e.data);null==a||a(t)}catch(e){console.error("Failed to parse WebSocket message:",e)}},s.onerror=()=>{m("error")},s.onclose=()=>{m("disconnected"),o.current=null,l&&(d.current=setTimeout(()=>{p()},n))},o.current=s},[m,a,l,n]),u=(0,r.useCallback)(()=>{d.current&&clearTimeout(d.current),o.current&&(o.current.close(1e3,"Client disconnect"),o.current=null),m("disconnected")},[m]),h=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&(o.current.send(JSON.stringify({type:"subscribe",worktreeId:e})),x.current.add(e))},[]),g=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&(o.current.send(JSON.stringify({type:"unsubscribe",worktreeId:e})),x.current.delete(e))},[]),y=(0,r.useCallback)(e=>{var t;(null===(t=o.current)||void 0===t?void 0:t.readyState)===WebSocket.OPEN&&o.current.send(JSON.stringify(e))},[]);return(0,r.useEffect)(()=>(p(),()=>{u()}),[]),(0,r.useEffect)(()=>{"connected"===i&&t.length>0&&t.forEach(e=>{h(e)})},[i,t]),{status:i,subscribe:h,unsubscribe:g,sendMessage:y,connect:p,disconnect:u}}({onMessage:(0,r.useCallback)(e=>{if(E(e.data)){let t=e.data;l(e=>e.map(e=>e.id===t.worktreeId?{...e,isSessionRunning:t.isRunning}:e))}"broadcast"===e.type&&P(!0)},[P])});(0,r.useEffect)(()=>{t.length||P()},[t.length,P]),(0,r.useEffect)(()=>{let e=setInterval(()=>{P(!0)},5e3);return()=>clearInterval(e)},[P]);let L=(0,r.useMemo)(()=>{let e=[...a];if(N&&(e=e.filter(e=>e.repositoryPath===N)),null!==k&&(e="unset"===k?e.filter(e=>!e.status):e.filter(e=>e.status===k)),g){let t=g.toLowerCase();e=e.filter(e=>{var a,s;return e.name.toLowerCase().includes(t)||e.path.toLowerCase().includes(t)||e.repositoryName.toLowerCase().includes(t)||(null===(a=e.lastMessageSummary)||void 0===a?void 0:a.toLowerCase().includes(t))||(null===(s=e.description)||void 0===s?void 0:s.toLowerCase().includes(t))})}return e.sort((e,t)=>{let a=0;switch(b){case"name":a=e.name.localeCompare(t.name);break;case"updated":a=(e.updatedAt?new Date(e.updatedAt).getTime():0)-(t.updatedAt?new Date(t.updatedAt).getTime():0);break;case"favorite":a=(e.favorite?1:0)-(t.favorite?1:0)}return"asc"===f?a:-a}),e},[a,N,k,g,b,f]),R=(0,r.useMemo)(()=>{let e=new Map;for(let t of L){let a=t.repositoryPath||"unknown";e.has(a)||e.set(a,[]),e.get(a).push(t)}return e},[L]),T=e=>{b===e?j(e=>"asc"===e?"desc":"asc"):(v(e),j("asc"))},D=async(e,t)=>{var a;let s=(null===(a=n.find(t=>t.path===e))||void 0===a?void 0:a.worktreeCount)||0,r=p(e),l='Delete repository "'.concat(t,'"?\n\nThis will delete:\n- ').concat(s," worktree(s)\n- Related chat history\n- Related memos\n\n* Log files will be preserved");if(r&&(l+='\n\nWARNING: This repository is configured in environment variable (WORKTREE_REPOS).\nIt will be re-registered when you run "Sync All".\nTo permanently remove it, also update the environment variable.'),"delete"===prompt(l+='\n\nType "delete" to confirm:')){z(e);try{await d.J1.delete(e),N===e&&w(null),await P()}catch(e){h((0,d.zG)(e))}finally{z(null)}}};return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,s.jsxs)(i.Ct,{variant:"gray",children:[a.length," branches"]}),n.length>0&&(0,s.jsxs)(i.Ct,{variant:"info",children:[n.length," ",1===n.length?"repository":"repositories"]}),"connected"===A&&(0,s.jsx)(i.Ct,{variant:"success",dot:!0,children:"Live"})]}),(0,s.jsx)("div",{className:"flex gap-2 w-full sm:w-auto",children:(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:()=>P(),disabled:o,children:o?"Loading...":"Refresh"})})]}),(0,s.jsx)("div",{className:"flex flex-col sm:flex-row gap-3",children:(0,s.jsx)("input",{type:"text",placeholder:"Search worktrees...",value:g,onChange:e=>y(e.target.value),className:"input flex-1"})}),n.length>0&&(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[(0,s.jsxs)(i.zx,{variant:null===N?"primary":"ghost",size:"sm",onClick:()=>w(null),children:["All (",a.length,")"]}),n.map(e=>(0,s.jsxs)("div",{className:"relative group inline-flex items-center",children:[(0,s.jsxs)(i.zx,{variant:N===e.path?"primary":"ghost",size:"sm",onClick:()=>w(e.path),className:"pr-6",children:[e.name," (",e.worktreeCount,")",p(e.path)&&(0,s.jsx)("span",{title:"Configured in environment variable",className:"ml-1 text-amber-500",children:"!"})]}),(0,s.jsx)("button",{className:"absolute right-1 opacity-0 group-hover:opacity-100 text-gray-400 hover:text-red-500 transition-opacity px-1",onClick:t=>{t.stopPropagation(),D(e.path,e.name)},disabled:S===e.path,title:"Delete repository",children:S===e.path?"...":"x"})]},e.path))]}),(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[(0,s.jsx)(i.zx,{variant:null===k?"primary":"ghost",size:"sm",onClick:()=>C(null),children:"All"}),(0,s.jsx)(i.zx,{variant:"todo"===k?"primary":"ghost",size:"sm",onClick:()=>C("todo"),children:"\uD83D\uDCDD ToDo"}),(0,s.jsx)(i.zx,{variant:"doing"===k?"primary":"ghost",size:"sm",onClick:()=>C("doing"),children:"\uD83D\uDEA7 Doing"}),(0,s.jsx)(i.zx,{variant:"done"===k?"primary":"ghost",size:"sm",onClick:()=>C("done"),children:"✅ Done"}),(0,s.jsx)(i.zx,{variant:"unset"===k?"primary":"ghost",size:"sm",onClick:()=>C("unset"),children:"Not set"})]}),(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600 self-center",children:"Sort by:"}),(0,s.jsxs)(i.zx,{variant:"favorite"===b?"primary":"ghost",size:"sm",onClick:()=>T("favorite"),children:["⭐ Favorite ","favorite"===b&&("asc"===f?"↑":"↓")]}),(0,s.jsxs)(i.zx,{variant:"name"===b?"primary":"ghost",size:"sm",onClick:()=>T("name"),children:["Name ","name"===b&&("asc"===f?"↑":"↓")]}),(0,s.jsxs)(i.zx,{variant:"updated"===b?"primary":"ghost",size:"sm",onClick:()=>T("updated"),children:["Updated ","updated"===b&&("asc"===f?"↑":"↓")]})]}),u&&(0,s.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-red-800",children:u})}),o&&!a.length&&(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,s.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading worktrees..."})]}),!o&&!u&&0===L.length&&(0,s.jsxs)("div",{className:"text-center py-12",children:[(0,s.jsx)("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,s.jsx)("p",{className:"mt-4 text-gray-600",children:g?"No worktrees found matching your search":"No worktrees found"})]}),!o&&L.length>0&&(0,s.jsx)("div",{className:"space-y-8",children:Array.from(R.entries()).map(e=>{let[t,a]=e,r=n.find(e=>e.path===t),l=(null==r?void 0:r.name)||"Unknown Repository";return(0,s.jsxs)("div",{className:"space-y-4",children:[(n.length>1||!N)&&(0,s.jsxs)("div",{className:"flex items-center gap-3 pb-2 border-b border-gray-200",children:[(0,s.jsx)("h3",{className:"text-xl font-semibold text-gray-900",children:l}),(0,s.jsx)(i.Ct,{variant:"gray",children:a.length})]}),(0,s.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:a.map(e=>(0,s.jsx)(x,{worktree:e,onSessionKilled:P,onStatusChanged:P},e.id))})]},t)})})]})}a(99376),a(34343),a(6940);class h{static getInstance(){return h.instance||(h.instance=new h),h.instance}normalize(e){let t=e.match(/^ssh:\/\/git@([^:\/]+)(:\d+)?\/(.+?)(\.git)?$/);if(t)return"https://".concat(t[1],"/").concat(t[3]).toLowerCase().replace(/\/$/,"");let a=e.match(/^git@([^:]+):(.+?)(\.git)?$/);return a?"https://".concat(a[1],"/").concat(a[2]).toLowerCase().replace(/\/$/,""):e.replace(/\.git\/?$/,"").replace(/\/$/,"").toLowerCase()}isSameRepository(e,t){return this.normalize(e)===this.normalize(t)}extractRepoName(e){let t=e.match(/^ssh:\/\/git@[^\/]+\/(.+?)(\.git)?$/);if(t){let e=t[1].split("/");return e[e.length-1]}let a=e.match(/:(.+?)(\.git)?$/);if(a&&e.startsWith("git@")){let e=a[1].split("/");return e[e.length-1]}let s=e.match(/\/([^\/]+?)(\.git)?$/);return s?s[1]:""}getUrlType(e){return e.startsWith("https://")?"https":e.startsWith("git@")||e.startsWith("ssh://")?"ssh":null}validate(e){if(!e||"string"!=typeof e||""===e.trim())return{valid:!1,error:"EMPTY_URL"};let t=e.trim();return t.startsWith("https://")?/^https:\/\/[^\/]+\/[^\/]+\/[^\/]+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}:t.startsWith("git@")?/^git@[^:]+:.+\/.+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}:t.startsWith("ssh://")&&/^ssh:\/\/git@[^\/]+(:\d+)?\/[^\/]+\/.+(\.git)?$/.test(t)?{valid:!0}:{valid:!1,error:"INVALID_URL_FORMAT"}}constructor(){}}function g(e){let{onRepositoryAdded:t}=e,[a,l]=(0,r.useState)(!1),[n,c]=(0,r.useState)("local"),[o,x]=(0,r.useState)(""),[m,p]=(0,r.useState)(""),[u,g]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[v,f]=(0,r.useState)(!1),[j,N]=(0,r.useState)(null),[w,k]=(0,r.useState)(null),[C,S]=(0,r.useState)(null),z=h.getInstance(),P=(0,r.useCallback)(async e=>{try{let s=await d.J1.getCloneStatus(e);if("completed"===s.status)S("Repository cloned successfully"),f(!1),N(null),p(""),l(!1),t&&t();else if("failed"===s.status){var a;k((null===(a=s.error)||void 0===a?void 0:a.message)||"Clone failed"),f(!1),N(null)}else("running"===s.status||"pending"===s.status)&&setTimeout(()=>P(e),2e3)}catch(e){k((0,d.zG)(e)),f(!1),N(null)}},[t]);(0,r.useEffect)(()=>{j&&v&&P(j)},[j,v,P]);let E=async e=>{if(e.preventDefault(),!o.trim()){k("Repository path is required");return}k(null),S(null),g(!0);try{let e=await d.J1.scan(o);S(e.message),x(""),l(!1),t&&t()}catch(e){k((0,d.zG)(e))}finally{g(!1)}},A=async e=>{if(e.preventDefault(),!m.trim()){k("Clone URL is required");return}let t=z.validate(m.trim());if(!t.valid){"EMPTY_URL"===t.error?k("Clone URL is required"):k("Invalid URL format");return}k(null),S(null),f(!0);try{let e=await d.J1.clone(m.trim());N(e.jobId)}catch(e){k((0,d.zG)(e)),f(!1)}},L=async()=>{k(null),S(null),b(!0);try{let e=await d.J1.sync();S(e.message),t&&t()}catch(e){k((0,d.zG)(e))}finally{b(!1)}},R=()=>{l(!1),x(""),p(""),k(null),c("local")};return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[!a&&(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:()=>l(!0),children:"+ Add Repository"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:L,disabled:y,children:y?"Syncing...":"Sync All"})]}),a&&(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{children:(0,s.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Add New Repository"})}),(0,s.jsxs)("div",{className:"flex border-b border-gray-200",role:"tablist",children:[(0,s.jsx)("button",{role:"tab","aria-selected":"local"===n,onClick:()=>c("local"),className:"px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ".concat("local"===n?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"Local Path"}),(0,s.jsx)("button",{role:"tab","aria-selected":"url"===n,onClick:()=>c("url"),className:"px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ".concat("url"===n?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"Clone URL"})]}),"local"===n&&(0,s.jsxs)("form",{onSubmit:E,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"Enter the absolute path to a git repository containing worktrees."}),(0,s.jsx)("label",{htmlFor:"repositoryPath",className:"block text-sm font-medium text-gray-700 mb-2",children:"Repository Path"}),(0,s.jsx)("input",{id:"repositoryPath",type:"text",value:o,onChange:e=>x(e.target.value),placeholder:"/absolute/path/to/repository",className:"input w-full font-mono text-sm",disabled:u}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Example: /Users/username/projects/my-repo"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{type:"submit",variant:"primary",disabled:u||!o.trim(),children:u?"Scanning...":"Scan & Add"}),(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:R,disabled:u,children:"Cancel"})]})]}),"url"===n&&(0,s.jsxs)("form",{onSubmit:A,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"Enter a git clone URL to clone a remote repository."}),(0,s.jsx)("label",{htmlFor:"cloneUrl",className:"block text-sm font-medium text-gray-700 mb-2",children:"Clone URL"}),(0,s.jsx)("input",{id:"cloneUrl",type:"text",value:m,onChange:e=>p(e.target.value),placeholder:"https://github.com/user/repo.git",className:"input w-full font-mono text-sm",disabled:v}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Supports HTTPS and SSH URLs"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{type:"submit",variant:"primary",disabled:v||!m.trim(),children:v?"Cloning...":"Clone"}),(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:R,disabled:v,children:"Cancel"})]})]})]})}),C&&(0,s.jsx)("div",{className:"p-4 bg-green-50 border border-green-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-green-800",children:C})}),w&&(0,s.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,s.jsx)("p",{className:"text-sm text-red-800",children:w})})]})}function y(e){var t;let{appId:a,pollInterval:l=3e4,showResponseTime:n=!1,compact:i=!1}=e,[c,o]=(0,r.useState)(null),[d,x]=(0,r.useState)(!0),m=(0,r.useCallback)(async()=>{try{let e=await fetch("/api/external-apps/".concat(a,"/health"));if(e.ok){let t=await e.json();o(t)}else o({id:a,healthy:!1,lastChecked:Date.now(),error:"Failed to check health"})}catch(e){o({id:a,healthy:!1,lastChecked:Date.now(),error:"Network error"})}finally{x(!1)}},[a]);if((0,r.useEffect)(()=>{m();let e=setInterval(m,l);return()=>clearInterval(e)},[m,l]),d)return(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full bg-gray-300 animate-pulse"}),!i&&(0,s.jsx)("span",{className:"text-xs text-gray-400",children:"Checking..."})]});let p=null!==(t=null==c?void 0:c.healthy)&&void 0!==t&&t,u=p?"bg-green-500":"bg-gray-400",h=p?"Running":"Stopped";return i?(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full ".concat(u),title:h}):(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full ".concat(u)}),(0,s.jsx)("span",{className:"text-xs ".concat(p?"text-green-600":"text-gray-500"),children:h}),n&&(null==c?void 0:c.responseTime)!==void 0&&(0,s.jsxs)("span",{className:"text-xs text-gray-400",children:["(",c.responseTime,"ms)"]})]})}function b(e){var t;let{app:a,onEdit:l,onDelete:n}=e,[c,o]=(0,r.useState)(!1),[d,x]=(0,r.useState)(!1),m=async()=>{x(!0);try{await n(a.id)}finally{x(!1),o(!1)}},p="/proxy/".concat(a.pathPrefix,"/");return(0,s.jsxs)(i.Zb,{padding:"md",className:"relative",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("h4",{className:"text-base font-semibold text-gray-900 truncate",children:a.displayName}),(0,s.jsx)("p",{className:"text-xs text-gray-500 mt-0.5 font-mono truncate",children:a.name})]}),(0,s.jsx)(i.Ct,{variant:{sveltekit:"warning",streamlit:"error",nextjs:"info",other:"gray"}[a.appType]||"gray",children:{sveltekit:"SvelteKit",streamlit:"Streamlit",nextjs:"Next.js",other:"Other"}[t=a.appType]||t})]}),(0,s.jsxs)("div",{className:"space-y-2 mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Status"}),(0,s.jsx)(y,{appId:a.id,pollInterval:3e4})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Port"}),(0,s.jsxs)("span",{className:"text-sm font-mono text-gray-900",children:[":",a.targetPort]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"Path"}),(0,s.jsxs)("span",{className:"text-sm font-mono text-gray-900 truncate max-w-[150px]",children:["/proxy/",a.pathPrefix,"/"]})]}),a.websocketEnabled&&(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-sm text-gray-600",children:"WebSocket"}),(0,s.jsx)(i.Ct,{variant:"info",children:"Enabled"})]}),!a.enabled&&(0,s.jsx)("div",{className:"mt-2 py-1 px-2 bg-yellow-50 border border-yellow-200 rounded text-xs text-yellow-700",children:"This app is disabled"})]}),c?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("p",{className:"text-sm text-gray-600",children:['Delete "',a.displayName,'"?']}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(i.zx,{variant:"danger",size:"sm",onClick:m,disabled:d,loading:d,children:"Delete"}),(0,s.jsx)(i.zx,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:d,children:"Cancel"})]})]}):(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:()=>window.open(p,"_blank"),disabled:!a.enabled,children:"Open"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:()=>l(a),children:"Settings"}),(0,s.jsx)(i.zx,{variant:"ghost",size:"sm",onClick:()=>o(!0),className:"text-red-600 hover:bg-red-50",children:"Delete"})]})]})}let v={MIN:1024,MAX:65535},f=/^[a-zA-Z0-9-]+$/,j={sveltekit:"SvelteKit",streamlit:"Streamlit",nextjs:"Next.js",other:"Other"},N=["sveltekit","streamlit","nextjs","other"].map(e=>({value:e,label:j[e]}));function w(e){let{isOpen:t,onClose:a,editApp:l,onSave:n}=e,c=!!l,[o,d]=(0,r.useState)(""),[x,m]=(0,r.useState)(""),[p,u]=(0,r.useState)(""),[h,g]=(0,r.useState)(""),[y,b]=(0,r.useState)(""),[j,w]=(0,r.useState)(!1),[k,C]=(0,r.useState)(""),[S,z]=(0,r.useState)(!0),[P,E]=(0,r.useState)({}),[A,L]=(0,r.useState)(!1),[R,T]=(0,r.useState)(null);(0,r.useEffect)(()=>{t&&(l?(d(l.displayName),m(l.name),u(l.pathPrefix),g(l.targetPort),b(l.appType),w(l.websocketEnabled),C(l.description||""),z(l.enabled)):(d(""),m(""),u(""),g(""),b(""),w(!1),C(""),z(!0)),E({}),T(null))},[t,l]);let D=async e=>{e.preventDefault(),T(null);let t=function(e,t){var a,s,r,l;let n={};return((null===(a=e.displayName)||void 0===a?void 0:a.trim())||(n.displayName="Display name is required"),t||((null===(s=e.name)||void 0===s?void 0:s.trim())?f.test(e.name)||(n.name="Only alphanumeric characters and hyphens are allowed"):n.name="Identifier name is required",(null===(r=e.pathPrefix)||void 0===r?void 0:r.trim())?f.test(e.pathPrefix)||(n.pathPrefix="Only alphanumeric characters and hyphens are allowed"):n.pathPrefix="Path prefix is required"),e.targetPort)?"number"!=typeof e.targetPort||Number.isInteger(l=e.targetPort)&&l>=v.MIN&&l<=v.MAX||(n.targetPort="Port must be between ".concat(v.MIN," and ").concat(v.MAX)):n.targetPort="Port number is required",t||e.appType||(n.appType="App type is required"),n}({displayName:o,name:x,pathPrefix:p,targetPort:h,appType:y},c);if(Object.keys(t).length>0){E(t);return}E({}),L(!0);try{if(c&&l){let e=await fetch("/api/external-apps/".concat(l.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:o,description:k||void 0,targetPort:h||void 0,websocketEnabled:j,enabled:S})});if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to update app")}}else{let e=await fetch("/api/external-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:o,name:x,pathPrefix:p,targetPort:h,appType:y,websocketEnabled:j,description:k||void 0})});if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to create app")}}n(),a()}catch(e){T(e instanceof Error?e.message:"An error occurred")}finally{L(!1)}};return(0,s.jsx)(i.u_,{isOpen:t,onClose:a,title:c?"Edit External App":"Add External App",size:"md",children:(0,s.jsxs)("form",{onSubmit:D,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"displayName",className:"block text-sm font-medium text-gray-700 mb-1",children:["Display Name ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"displayName",type:"text",value:o,onChange:e=>d(e.target.value),className:"input w-full ".concat(P.displayName?"border-red-500":""),placeholder:"My App",disabled:A}),P.displayName&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.displayName})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"name",className:"block text-sm font-medium text-gray-700 mb-1",children:["Identifier Name ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"name",type:"text",value:x,onChange:e=>m(e.target.value),className:"input w-full font-mono ".concat(P.name?"border-red-500":""),placeholder:"my-app",disabled:A}),(0,s.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"Alphanumeric and hyphens only. Cannot be changed later."}),P.name&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.name})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"pathPrefix",className:"block text-sm font-medium text-gray-700 mb-1",children:["Path Prefix ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("span",{className:"text-sm text-gray-500 mr-1",children:"/proxy/"}),(0,s.jsx)("input",{id:"pathPrefix",type:"text",value:p,onChange:e=>u(e.target.value),className:"input flex-1 font-mono ".concat(P.pathPrefix?"border-red-500":""),placeholder:"app-name",disabled:A}),(0,s.jsx)("span",{className:"text-sm text-gray-500 ml-1",children:"/"})]}),(0,s.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"URL path for accessing this app. Cannot be changed later."}),P.pathPrefix&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.pathPrefix})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"targetPort",className:"block text-sm font-medium text-gray-700 mb-1",children:["Port Number ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)("input",{id:"targetPort",type:"number",value:h,onChange:e=>g(e.target.value?parseInt(e.target.value,10):""),className:"input w-full font-mono ".concat(P.targetPort?"border-red-500":""),placeholder:"5173",min:v.MIN,max:v.MAX,disabled:A}),(0,s.jsxs)("p",{className:"mt-1 text-xs text-gray-500",children:["Target port (",v.MIN,"-",v.MAX,")"]}),P.targetPort&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.targetPort})]}),!c&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"appType",className:"block text-sm font-medium text-gray-700 mb-1",children:["App Type ",(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsxs)("select",{id:"appType",value:y,onChange:e=>b(e.target.value),className:"input w-full ".concat(P.appType?"border-red-500":""),disabled:A,children:[(0,s.jsx)("option",{value:"",children:"Select app type..."}),N.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]}),P.appType&&(0,s.jsx)("p",{className:"mt-1 text-xs text-red-500",children:P.appType})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"description",className:"block text-sm font-medium text-gray-700 mb-1",children:"Description"}),(0,s.jsx)("textarea",{id:"description",value:k,onChange:e=>C(e.target.value),className:"input w-full",placeholder:"Optional description...",rows:2,disabled:A})]}),(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("input",{id:"websocketEnabled",type:"checkbox",checked:j,onChange:e=>w(e.target.checked),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",disabled:A}),(0,s.jsx)("label",{htmlFor:"websocketEnabled",className:"ml-2 text-sm text-gray-700",children:"Enable WebSocket support"})]}),c&&(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("input",{id:"enabled",type:"checkbox",checked:S,onChange:e=>z(e.target.checked),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500",disabled:A}),(0,s.jsx)("label",{htmlFor:"enabled",className:"ml-2 text-sm text-gray-700",children:"App is enabled"})]}),R&&(0,s.jsx)("div",{className:"p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700",children:R}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-4 border-t border-gray-200",children:[(0,s.jsx)(i.zx,{type:"button",variant:"ghost",onClick:a,disabled:A,children:"Cancel"}),(0,s.jsx)(i.zx,{type:"submit",variant:"primary",loading:A,children:c?"Save Changes":"Add App"})]})]})})}function k(){let[e,t]=(0,r.useState)([]),[a,l]=(0,r.useState)(!0),[n,c]=(0,r.useState)(null),[o,d]=(0,r.useState)(!1),[x,m]=(0,r.useState)(null),p=(0,r.useCallback)(async()=>{try{c(null);let e=await fetch("/api/external-apps");if(!e.ok)throw Error("Failed to fetch external apps");let a=await e.json();t(a.apps||[])}catch(e){c(e instanceof Error?e.message:"An error occurred")}finally{l(!1)}},[]);(0,r.useEffect)(()=>{p();let e=setInterval(p,6e4);return()=>clearInterval(e)},[p]);let u=(0,r.useCallback)(e=>{m(e),d(!0)},[]),h=(0,r.useCallback)(()=>{m(null),d(!0)},[]),g=(0,r.useCallback)(async e=>{try{let t=await fetch("/api/external-apps/".concat(e),{method:"DELETE"});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to delete app")}p()}catch(e){console.error("Failed to delete app:",e)}},[p]),y=(0,r.useCallback)(()=>{p()},[p]),v=(0,r.useCallback)(()=>{d(!1),m(null)},[]);return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-gray-900",children:"External Apps"}),(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:h,children:"+ Add App"})]}),a?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,s.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),(0,s.jsx)("span",{className:"ml-3 text-gray-600",children:"Loading apps..."})]})}):n?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"text-center py-8",children:[(0,s.jsx)("p",{className:"text-red-600 mb-4",children:"Failed to load external apps"}),(0,s.jsx)(i.zx,{variant:"secondary",size:"sm",onClick:p,children:"Retry"})]})}):0===e.length?(0,s.jsx)(i.Zb,{padding:"lg",children:(0,s.jsxs)("div",{className:"text-center py-8",children:[(0,s.jsx)("p",{className:"text-gray-500 mb-4",children:"No external apps registered yet."}),(0,s.jsx)("p",{className:"text-sm text-gray-400 mb-4",children:"Add an external app to proxy requests to other frontend applications."}),(0,s.jsx)(i.zx,{variant:"primary",size:"sm",onClick:h,children:"Add Your First App"})]})}):(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:e.map(e=>(0,s.jsx)(b,{app:e,onEdit:u,onDelete:g},e.id))}),(0,s.jsx)(w,{isOpen:o,onClose:v,editApp:x,onSave:y})]})}function C(){let[e,t]=(0,r.useState)(0),a=(0,r.useCallback)(()=>{t(e=>e+1)},[]);return(0,s.jsx)(l.Vw,{children:(0,s.jsxs)("div",{className:"container-custom py-8 overflow-auto h-full",children:[(0,s.jsxs)("div",{className:"mb-8",children:[(0,s.jsx)("h1",{className:"mb-2",children:"CommandMate"}),(0,s.jsx)("p",{className:"text-lg text-gray-600",children:"Git worktree management with Claude CLI and tmux sessions"})]}),(0,s.jsx)("div",{className:"mb-8",children:(0,s.jsx)(g,{onRepositoryAdded:a})}),(0,s.jsx)(u,{},e),(0,s.jsx)("div",{className:"mt-8",children:(0,s.jsx)(k,{})})]})})}}},function(e){e.O(0,[7648,9365,6725,816,2853,2971,2117,1744],function(){return e(e.s=14564)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[130],{5635:function(e,t,a){Promise.resolve().then(a.bind(a,45437))},45437:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return tD}});var r=a(57437),n=a(99376),s=a(63671),l=a(2265);let i={output:"",realtimeSnippet:"",isActive:!1,isThinking:!1,autoScroll:!0,lastUpdated:null},o={data:null,messageId:null,visible:!1,answering:!1},c={mode:"split",mobileActivePane:"terminal",leftPaneTab:"history",splitRatio:.5},d={type:null,message:null,retryable:!1,retryCount:0};function u(){return{phase:"idle",terminal:{...i},prompt:{...o},layout:{...c},error:{...d},messages:[],wsConnected:!1}}function m(e,t){switch(t.type){case"SET_PHASE":return{...e,phase:t.phase};case"SET_TERMINAL_OUTPUT":return{...e,terminal:{...e.terminal,output:t.output,realtimeSnippet:t.realtimeSnippet,lastUpdated:new Date}};case"SET_TERMINAL_ACTIVE":return{...e,terminal:{...e.terminal,isActive:t.isActive}};case"SET_TERMINAL_THINKING":return{...e,terminal:{...e.terminal,isThinking:t.isThinking}};case"SET_AUTO_SCROLL":return{...e,terminal:{...e.terminal,autoScroll:t.enabled}};case"SHOW_PROMPT":return{...e,phase:"prompt",prompt:{data:t.data,messageId:t.messageId,visible:!0,answering:!1}};case"CLEAR_PROMPT":return{...e,prompt:{...o}};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"SET_ERROR":return{...e,error:t.error};case"CLEAR_ERROR":return{...e,error:{...d}};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};case"START_WAITING_FOR_RESPONSE":return{...e,phase:"waiting",terminal:{...e.terminal,isActive:!0,output:"",realtimeSnippet:""},prompt:{...o}};case"RESPONSE_RECEIVED":return{...e,phase:"complete",messages:[...e.messages,t.message],terminal:{...e.terminal,isActive:!1,isThinking:!1}};case"SESSION_ENDED":return{...e,phase:"idle",terminal:{...i},prompt:{...o}};default:return e}}var x=a(58819),h=a(43241);class p extends l.Component{static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){var a,r;console.error("[ErrorBoundary:".concat(this.props.componentName||"unknown","]"),e,t),null===(a=(r=this.props).onError)||void 0===a||a.call(r,e,t)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,r.jsx)(f,{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 f(e){let{componentName:t,error:a,onRetry:n}=e;return(0,r.jsxs)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-red-800 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?"".concat(t,"でエラーが発生しました"):"エラーが発生しました"})]}),a&&(0,r.jsx)("p",{className:"text-sm text-red-600 mb-3",children:a.message}),n&&(0,r.jsx)("button",{onClick:n,className:"px-4 py-2 bg-red-600 text-white rounded hover:bg-red-700 transition-colors text-sm",children:"再試行"})]})}let g=["flex-shrink-0","bg-gray-700","transition-colors","duration-150","hover:bg-blue-500","focus:outline-none","focus:ring-2","focus:ring-blue-500","focus:ring-offset-2","focus:ring-offset-gray-900"],b=["w-1","h-full","cursor-col-resize","hover:w-2"],y=["h-1","w-full","cursor-row-resize","hover:h-2"];function v(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 w=(0,l.memo)(function(e){let{onResize:t,orientation:a="horizontal",ariaValueNow:n=50,onDoubleClick:s,minRatio:i=.1}=e,[o,c]=(0,l.useState)(!1),d=(0,l.useRef)(0),u=(0,l.useRef)(null),m="horizontal"===a,x=(0,l.useCallback)(e=>{e.preventDefault(),c(!0),d.current=v(e,m)},[m]),h=(0,l.useCallback)(e=>{1===e.touches.length&&(c(!0),d.current=v(e,m))},[m]),p=(0,l.useCallback)(e=>{if(!o)return;let a=v(e,m);t(a-d.current),d.current=a},[o,m,t]),f=(0,l.useCallback)(e=>{if(!o||1!==e.touches.length)return;let a=v(e,m);t(a-d.current),d.current=a},[o,m,t]),w=(0,l.useCallback)(()=>{c(!1)},[]),j=(0,l.useCallback)(()=>{s&&s()},[s]),N=(0,l.useCallback)(e=>{let a=0;m?"ArrowRight"===e.key?a=10:"ArrowLeft"===e.key&&(a=-10):"ArrowDown"===e.key?a=10:"ArrowUp"===e.key&&(a=-10),0!==a&&(e.preventDefault(),t(a))},[m,t]);(0,l.useEffect)(()=>(o&&(document.addEventListener("mousemove",p),document.addEventListener("mouseup",w),document.addEventListener("touchmove",f),document.addEventListener("touchend",w),document.body.style.userSelect="none",document.body.style.cursor=m?"col-resize":"row-resize"),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",w),document.removeEventListener("touchmove",f),document.removeEventListener("touchend",w),document.body.style.userSelect="",document.body.style.cursor=""}),[o,p,w,f,m]);let k=(0,l.useMemo)(()=>[...g,...m?b:y,...o?["bg-blue-500","dragging",m?"w-2":"h-2"]:[]].join(" "),[m,o]);return(0,r.jsx)("div",{ref:u,role:"separator","aria-orientation":a,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":"Resize panes. Use ".concat(m?"left and right":"up and down"," arrow keys to adjust."),tabIndex:0,className:k,onMouseDown:x,onTouchStart:h,onKeyDown:N,onDoubleClick:j})}),j={left:"History",right:"Terminal"},N={left:"HistoryPane",right:"TerminalPane"},k=(0,l.memo)(function(e){let{pane:t,isActive:a,onClick:n}=e;return(0,r.jsx)("button",{type:"button",role:"tab","aria-selected":a,"aria-controls":"".concat(t,"-panel"),onClick:n,className:"".concat("flex-1 py-2 px-4 text-sm font-medium transition-colors"," ").concat(a?"text-blue-400 border-b-2 border-blue-400 bg-gray-900":"text-gray-400 hover:text-gray-300"),children:j[t]})}),C=(0,l.memo)(function(e){let{leftPane:t,rightPane:a}=e,[n,s]=(0,l.useState)("right"),i=(0,l.useCallback)(()=>s("left"),[]),o=(0,l.useCallback)(()=>s("right"),[]);return(0,r.jsxs)("div",{"data-testid":"mobile-layout",className:"flex flex-col h-full",children:[(0,r.jsxs)("div",{className:"flex border-b border-gray-700 bg-gray-800",role:"tablist",children:[(0,r.jsx)(k,{pane:"left",isActive:"left"===n,onClick:i}),(0,r.jsx)(k,{pane:"right",isActive:"right"===n,onClick:o})]}),(0,r.jsx)("div",{id:"".concat(n,"-panel"),role:"tabpanel",className:"flex-1 overflow-hidden",children:(0,r.jsx)(p,{componentName:N[n],children:"left"===n?t:a})})]})}),S=(0,l.memo)(function(e){let{leftPane:t,rightPane:a,leftWidth:n,onResize:s,className:i}=e,o=(0,l.useMemo)(()=>({width:"".concat(n,"%")}),[n]),c=(0,l.useMemo)(()=>({width:"".concat(100-n,"%")}),[n]),d=(0,l.useMemo)(()=>"flex h-full min-h-0 ".concat(i).trim(),[i]);return(0,r.jsxs)("div",{"data-testid":"desktop-layout",role:"main",className:d,children:[(0,r.jsx)("div",{"data-testid":"left-pane","aria-label":"History pane",style:o,className:"flex-shrink-0 overflow-hidden",children:(0,r.jsx)(p,{componentName:N.left,children:t})}),(0,r.jsx)(w,{onResize:s,orientation:"horizontal",ariaValueNow:n}),(0,r.jsx)("div",{"data-testid":"right-pane","aria-label":"Terminal pane",style:c,className:"flex-grow overflow-hidden",children:(0,r.jsx)(p,{componentName:N.right,children:a})})]})}),E=(0,l.memo)(function(e){let{leftPane:t,rightPane:a,initialLeftWidth:n=50,minLeftWidth:s=20,maxLeftWidth:i=80,className:o=""}=e,c=(0,x.d)(),d=(0,l.useRef)(null),[u,m]=(0,l.useState)(n),h=(0,l.useCallback)(e=>{let t=d.current;if(!t)return;let a=t.offsetWidth;if(0===a)return;let r=e/a*100;m(e=>Math.min(i,Math.max(s,e+r)))},[s,i]);return c?(0,r.jsx)(C,{leftPane:t,rightPane:a}):(0,r.jsx)("div",{ref:d,className:"h-full",children:(0,r.jsx)(S,{leftPane:t,rightPane:a,leftWidth:u,onResize:h,className:o})})});var M=a(47835),T=a.n(M),L=a(34343);let R=new(a.n(L)())({fg:"#d1d5db",bg:"#1f2937",newline:!0,escapeXML:!0});function A(){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 F=(0,l.memo)(function(e){let{output:t,isActive:a,isThinking:n=!1,autoScroll:s=!0,onScrollChange:i,className:o=""}=e,{scrollRef:c,autoScroll:d,handleScroll:u,scrollToBottom:m}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{initialAutoScroll:t=!0,onAutoScrollChange:a}=e,r=(0,l.useRef)(null),[n,s]=(0,l.useState)(t),i=(0,l.useCallback)(e=>{s(e),null==a||a(e)},[a]),o=(0,l.useCallback)(()=>{let e=r.current;if(!e)return!0;let{scrollTop:t,scrollHeight:a,clientHeight:n}=e;return a-n-t<=50},[]),c=(0,l.useCallback)(()=>{let e=o();e&&!n?i(!0):!e&&n&&i(!1)},[n,o,i]),d=(0,l.useCallback)(()=>{let e=r.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),n||i(!0))},[n,i]);return{scrollRef:r,autoScroll:n,setAutoScroll:i,scrollToBottom:d,handleScroll:c}}({initialAutoScroll:s,onAutoScrollChange:i}),x=function(e){let t=R.toHtml(e);return T().sanitize(t,{ALLOWED_TAGS:["span","br"],ALLOWED_ATTR:["style"],ALLOW_DATA_ATTR:!1})}(t||"");(0,l.useEffect)(()=>{d&&c.current&&c.current.scrollTo({top:c.current.scrollHeight,behavior:"smooth"})},[x,d,c]);let h=(0,l.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",a?"active":"",a?"border-blue-500":"",o].filter(Boolean).join(" "),[a,o]);return(0,r.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,r.jsxs)("div",{ref:c,role:"log","aria-live":"polite","aria-label":"Terminal output",className:h,onScroll:u,children:[(0,r.jsx)("div",{className:"whitespace-pre-wrap break-words",dangerouslySetInnerHTML:{__html:x}}),a&&n&&(0,r.jsx)(A,{})]}),!d&&(0,r.jsx)("button",{onClick:m,className:"absolute bottom-4 right-4 bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md text-sm shadow-lg transition-colors","aria-label":"Scroll to bottom",children:"Scroll to bottom"})]})}),P=/(\/[^\s\n<>"']+\.[a-zA-Z0-9]+)/g;function D(e){let t=e.split("\n");if(t.length<=5&&e.length<=300)return{text:e,isTruncated:!1};let a=t.slice(0,5).join("\n");return a.length>300&&(a=a.slice(0,300)),{text:a,isTruncated:!0}}let I=(0,l.memo)(function(e){let{content:t,onFilePathClick:a}=e,n=(0,l.useMemo)(()=>(function(e){let t=e.match(P);if(!t||0===t.length)return[{type:"text",content:e}];let a=[],r=0;return t.forEach(t=>{let n=e.indexOf(t,r);n>r&&a.push({type:"text",content:e.slice(r,n)}),a.push({type:"path",content:t}),r=n+t.length}),r<e.length&&a.push({type:"text",content:e.slice(r)}),a})(t),[t]),s=(0,l.useCallback)(e=>()=>a(e),[a]);return(0,r.jsx)("span",{children:n.map((e,t)=>"path"===e.type?(0,r.jsx)("button",{type:"button",onClick:s(e.content),className:"text-blue-400 hover:text-blue-300 hover:underline cursor-pointer font-mono text-sm","aria-label":"Open file: ".concat(e.content),children:e.content},t):(0,r.jsx)("span",{children:e.content},t))})});function _(){return(0,r.jsxs)("div",{"data-testid":"pending-indicator",className:"flex items-center gap-2 text-gray-400 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-gray-400 rounded-full animate-pulse"}),(0,r.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"150ms"}}),(0,r.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"300ms"}})]}),(0,r.jsx)("span",{className:"text-sm",children:"Waiting for response..."})]})}let z=(0,l.memo)(function(e){let{message:t,onFilePathClick:a}=e,n=(0,l.useMemo)(()=>t.timestamp.toLocaleTimeString(),[t.timestamp]);return(0,r.jsxs)("div",{className:"bg-blue-900/30 border-l-4 border-blue-500 p-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-blue-400",children:"You"}),(0,r.jsx)("span",{className:"text-xs text-gray-500",children:n})]}),(0,r.jsx)("div",{className:"text-sm text-gray-200 whitespace-pre-wrap break-words",children:(0,r.jsx)(I,{content:t.content,onFilePathClick:a})})]})}),O=(0,l.memo)(function(e){let{message:t,index:a,total:n,isExpanded:s,onFilePathClick:i}=e,o=(0,l.useMemo)(()=>t.timestamp.toLocaleTimeString(),[t.timestamp]),{text:c,isTruncated:d}=(0,l.useMemo)(()=>D(t.content),[t.content]),u=s||!d?t.content:c;return(0,r.jsxs)("div",{className:"assistant-message-item",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("span",{className:"text-xs font-medium text-gray-400",children:"Assistant"}),(0,r.jsx)("span",{className:"text-xs text-gray-500",children:o}),n>1&&(0,r.jsxs)("span",{className:"text-xs text-gray-500",children:["(",a+1,"/",n,")"]})]}),(0,r.jsxs)("div",{className:"text-sm text-gray-200 whitespace-pre-wrap break-words [word-break:break-word] max-w-full overflow-x-hidden",children:[(0,r.jsx)(I,{content:u,onFilePathClick:i}),!s&&d&&(0,r.jsx)("span",{className:"text-gray-500",children:"..."})]})]})}),W=(0,l.memo)(function(e){let{messages:t,isExpanded:a,onFilePathClick:n}=e;return(0,r.jsx)("div",{className:"bg-gray-800/50 border-l-4 border-gray-600 p-3 border-t border-gray-700 space-y-3",children:t.map((e,s)=>(0,r.jsxs)(l.Fragment,{children:[s>0&&(0,r.jsx)("div",{"data-testid":"assistant-message-divider",className:"border-t border-dashed border-gray-600"}),(0,r.jsx)(O,{message:e,index:s,total:t.length,isExpanded:a,onFilePathClick:n})]},e.id))})});function B(){return(0,r.jsxs)("div",{"data-testid":"orphan-indicator",className:"bg-yellow-900/20 text-yellow-400 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:"System Message"})]})}let U=(0,l.memo)(function(e){let{pair:t,onFilePathClick:a,isExpanded:n=!1,onToggleExpand:s}=e,i=(0,l.useMemo)(()=>t.assistantMessages.some(e=>{let{isTruncated:t}=D(e.content);return t}),[t.assistantMessages]),o=(0,l.useCallback)(()=>{s&&s()},[s]),c=(0,l.useMemo)(()=>{let e="pending"===t.status?"pending":"orphan"===t.status?"orphan border-l-4 border-yellow-600":"";return"".concat("border border-gray-700 rounded-lg overflow-hidden mb-4 transition-colors"," ").concat(e).trim()},[t.status]),d=(0,l.useMemo)(()=>{if(t.userMessage){let e=t.userMessage.content.substring(0,50);return"Conversation: ".concat(e).concat(t.userMessage.content.length>50?"...":"")}return"System message"},[t.userMessage]);return(0,r.jsxs)("div",{"data-testid":"conversation-pair-card",role:"article","aria-label":d,className:c,children:["orphan"===t.status&&(0,r.jsx)(B,{}),t.userMessage&&(0,r.jsx)(z,{message:t.userMessage,onFilePathClick:a}),"pending"===t.status?(0,r.jsx)("div",{className:"bg-gray-800/30 border-l-4 border-gray-600 p-3 border-t border-gray-700",children:(0,r.jsx)(_,{})}):t.assistantMessages.length>0?(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(W,{messages:t.assistantMessages,isExpanded:n,onFilePathClick:a}),i&&(0,r.jsx)("div",{className:"absolute top-2 right-2",children:(0,r.jsxs)("button",{type:"button",onClick:o,className:"text-xs text-blue-400 hover:text-blue-300 flex items-center gap-1 transition-colors bg-gray-800/80 px-2 py-1 rounded","aria-expanded":n,"aria-label":n?"Collapse message":"Expand message",children:[(0,r.jsx)("svg",{className:"w-3 h-3 transition-transform ".concat(n?"rotate-180":""),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"})}),n?"Collapse":"Expand"]})})]}):null]})});function V(){return(0,r.jsxs)("div",{"data-testid":"loading-indicator",className:"flex items-center justify-center py-4",role:"status","aria-label":"Loading messages",children:[(0,r.jsxs)("div",{className:"flex gap-1","aria-hidden":"true",children:[(0,r.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse"}),(0,r.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse delay-100"}),(0,r.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse delay-200"})]}),(0,r.jsx)("span",{className:"ml-2 text-sm text-gray-400",children:"Loading..."})]})}function H(){return(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-gray-500",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:"No messages yet"})]})}let Z=["h-full","flex","flex-col","overflow-y-auto","overflow-x-hidden","bg-gray-900","rounded-lg","border","border-gray-700"],Y=(0,l.memo)(function(e){let{messages:t,worktreeId:a,onFilePathClick:n,isLoading:s=!1,className:i=""}=e,o=(0,l.useRef)(null),c=(0,l.useRef)(0),d=(0,l.useRef)(t.length);(0,l.useLayoutEffect)(()=>{let e=o.current;e&&(c.current=e.scrollTop)}),(0,l.useLayoutEffect)(()=>{let e=o.current,a=d.current;e&&t.length===a&&requestAnimationFrame(()=>{e.scrollTop=c.current}),d.current=t.length},[t.length]);let{pairs:u,isExpanded:m,toggleExpand:x}=function(e){let t=(0,l.useMemo)(()=>(function(e){if(0===e.length)return[];let t=[...e].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),a=[],r=null;for(let e of t)if("user"===e.role)r={id:e.id,userMessage:e,assistantMessages:[],status:"pending"},a.push(r);else if("assistant"===e.role){if(r&&null!==r.userMessage)r.assistantMessages.push(e),r.status="completed";else if(r&&null===r.userMessage)r.assistantMessages.push(e);else{let t={id:"orphan-".concat(e.id),userMessage:null,assistantMessages:[e],status:"orphan"};a.push(t),r=t}}return a})(e),[e]),[a,r]=(0,l.useState)(new Set),n=(0,l.useCallback)(e=>{r(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},[]),s=(0,l.useCallback)(e=>a.has(e),[a]),i=(0,l.useCallback)(()=>{r(new Set(t.map(e=>e.id)))},[t]);return{pairs:t,expandedPairs:a,toggleExpand:n,isExpanded:s,expandAll:i,collapseAll:(0,l.useCallback)(()=>{r(new Set)},[])}}(t),h=(0,l.useMemo)(()=>[...Z,i].filter(Boolean).join(" "),[i]),p=(0,l.useCallback)(e=>n(e),[n]),f=(0,l.useCallback)(e=>()=>x(e),[x]);return(0,r.jsxs)("div",{ref:o,role:"region","aria-label":"Message history",className:h,children:[(0,r.jsx)("div",{className:"sticky top-0 bg-gray-900 border-b border-gray-700 px-4 py-2 z-10",children:(0,r.jsx)("h3",{className:"text-sm font-medium text-gray-300",children:"Message History"})}),(0,r.jsx)("div",{className:"flex-1 p-4 min-h-0",children:s?(0,r.jsx)(V,{}):0===t.length?(0,r.jsx)(H,{}):u.map(e=>(0,r.jsx)(U,{pair:e,onFilePathClick:p,isExpanded:m(e.id),onToggleExpand:f(e.id)},e.id))})]})}),q={fadeIn:"animate-fade-in",fadeOut:"animate-fade-out",none:""};function G(e){let{visible:t,duration:a=200}=e,[r,n]=(0,l.useState)(t?"visible":"hidden"),s=(0,l.useRef)(null),i=(0,l.useRef)(t);(0,l.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),(0,l.useEffect)(()=>{let e=i.current;i.current=t,s.current&&(clearTimeout(s.current),s.current=null);let r=e=>{s.current=setTimeout(()=>{n(e),s.current=null},a)};t&&!e?(n("fade-in"),r("visible")):!t&&e?(n("fade-out"),r("hidden")):t?n(e=>"fade-out"===e?(r("visible"),"fade-in"):e):n(e=>"fade-in"===e?(r("hidden"),"fade-out"):e)},[t,a]);let o="hidden"!==r,c="fade-in"===r||"fade-out"===r;return{shouldRender:o,animationClass:(0,l.useMemo)(()=>{switch(r){case"fade-in":return q.fadeIn;case"fade-out":return q.fadeOut;default:return q.none}},[r]),isAnimating:c}}let K="\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(),J="bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500";function X(e){let{promptData:t,answering:a,onRespond:n,onDismiss:s,labelId:i}=e,[o,c]=(0,l.useState)(()=>{if("multiple_choice"===t.type){var e;let a=t.options.find(e=>e.isDefault);return null!==(e=null==a?void 0:a.number)&&void 0!==e?e:null}return null}),[d,u]=(0,l.useState)(""),[m,x]=(0,l.useState)(!1),h=(0,l.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!==(e=t.options.find(e=>e.number===o))&&void 0!==e?e:null},[t,o]),p=(null==h?void 0:h.requiresTextInput)===!0,f=a||m,g=(0,l.useCallback)(async e=>{if(!f){x(!0);try{await n(e)}catch(e){}finally{x(!1)}}},[f,n]),b=(0,l.useCallback)(async()=>{if(!f&&null!==o){x(!0);try{let e=p&&d.trim()?d.trim():o.toString();await n(e)}catch(e){}finally{x(!1)}}},[f,n,o,p,d]);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:i,className:"text-lg font-semibold text-yellow-800 flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xl","aria-hidden":"true",children:"?"}),"Claudeからの確認"]}),s&&(0,r.jsx)("button",{type:"button",onClick:s,"aria-label":"close",className:"p-1 rounded hover:bg-yellow-200 transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5 text-yellow-700",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"})})})]}),(0,r.jsx)("p",{className:"text-gray-800 leading-relaxed",children:t.question}),f&&(0,r.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-gray-500",role:"status","aria-live":"polite",children:[(0,r.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,r.jsx)("span",{children:"送信中..."})]}),"yes_no"===t.type&&(0,r.jsx)(Q,{promptData:t,disabled:f,onYes:()=>g("yes"),onNo:()=>g("no")}),"multiple_choice"===t.type&&(0,r.jsx)($,{promptData:t,disabled:f,selectedOption:o,onSelectOption:c,textInputValue:d,onTextInputChange:u,showTextInput:p,onSubmit:b})]})}function Q(e){let{promptData:t,disabled:a,onYes:n,onNo:s}=e,l="yes"===t.defaultOption,i="no"===t.defaultOption,o="".concat(K," ").concat(J," ").concat(l?"primary default highlighted":""),c="".concat(K," ").concat(i?"bg-gray-600 text-white hover:bg-gray-700 primary default highlighted":"bg-white border-2 border-gray-300 hover:bg-gray-50 text-gray-800 focus:ring-gray-500");return(0,r.jsxs)("div",{className:"flex items-center gap-3",role:"group","aria-label":"Yes or No options",children:[(0,r.jsx)("button",{type:"button",onClick:n,disabled:a,className:o,children:"Yes"}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:a,className:c,children:"No"})]})}function $(e){let{promptData:t,disabled:a,selectedOption:n,onSelectOption:s,textInputValue:i,onTextInputChange:o,showTextInput:c,onSubmit:d}=e,u=(0,l.useId)(),m=(0,l.useCallback)(e=>{let t=n===e,r=a?"opacity-50 cursor-not-allowed":"";return"".concat("flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all"," ").concat(t?"bg-blue-50 border-2 border-blue-500":"bg-white border-2 border-gray-200 hover:border-gray-300"," ").concat(r)},[n,a]);return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("fieldset",{children:[(0,r.jsx)("legend",{className:"sr-only",children:"Select an option"}),(0,r.jsx)("div",{className:"space-y-2",children:t.options.map(e=>(0,r.jsxs)("label",{className:m(e.number),children:[(0,r.jsx)("input",{type:"radio",name:u,value:e.number,checked:n===e.number,onChange:()=>s(e.number),disabled:a,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-blue-600 bg-blue-100 px-2 py-0.5 rounded",children:"デフォルト"})]})]},e.number))})]}),c&&(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("label",{htmlFor:"text-input-".concat(u),className:"sr-only",children:"Custom value input"}),(0,r.jsx)("input",{id:"text-input-".concat(u),type:"text",value:i,onChange:e=>o(e.target.value),disabled:a,placeholder:"値を入力してください...",className:"w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500 disabled:opacity-50"})]}),(0,r.jsx)("button",{type:"button",onClick:d,disabled:a||null===n,className:"w-full ".concat(K," ").concat(J),children:"Submit"})]})}function ee(e){let t,{promptData:a,messageId:n,visible:s,answering:i,onRespond:o,onDismiss:c}=e,{shouldRender:d,animationClass:u}=G({visible:s&&null!==a,duration:200}),m=(0,l.useId)();if(!d||!a)return null;let x=(t="opacity-100","animate-fade-in"===u?t="opacity-100 transform translate-y-0":"animate-fade-out"===u&&(t="opacity-0 transform translate-y-2"),"".concat("bg-yellow-50 border-2 border-yellow-300 rounded-lg p-4 shadow-lg transition-all duration-200 ease-in-out"," ").concat(u," ").concat(t));return(0,r.jsx)(p,{componentName:"PromptPanel",children:(0,r.jsx)("div",{"data-testid":"prompt-panel",role:"dialog","aria-labelledby":m,"aria-modal":"true",className:x,children:(0,r.jsx)(X,{promptData:a,answering:i,onRespond:o,onDismiss:c,labelId:m})})})}var et=a(8672);function ea(e,t){let a=null;return function(){for(var r=arguments.length,n=Array(r),s=0;s<r;s++)n[s]=arguments[s];a&&clearTimeout(a),a=setTimeout(()=>{e(...n),a=null},t)}}function er(e){let t=new Set;for(let a of e){t.add(a);let e=a.split("/"),r="";for(let a=0;a<e.length-1;a++)r=r?"".concat(r,"/").concat(e[a]):e[a],t.add(r)}return t}function en(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:30;return e.length<=t?e:"".concat(e.substring(0,t-3),"...")}let es=(0,l.memo)(function(e){let{path:t,className:a="w-6 h-6"}=e;return(0,r.jsx)("svg",{className:a,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})})}),el={back:"M15 19l-7-7 7-7",menu:"M4 6h16M4 12h16M4 18h16"};function ei(e){let{worktreeName:t,repositoryName:a,status:n,gitStatus:s,onBackClick:i,onMenuClick:o}=e,c=(0,l.useMemo)(()=>et.xh[n],[n]);return(0,r.jsx)("header",{"data-testid":"mobile-header",role:"banner",className:"fixed top-0 inset-x-0 bg-white border-b border-gray-200 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:i&&(0,r.jsx)("button",{type:"button",onClick:i,"aria-label":"Back",className:"p-2 -ml-2 rounded-full hover:bg-gray-100 transition-colors",children:(0,r.jsx)(es,{path:el.back})})}),(0,r.jsxs)("div",{className:"flex-1 flex items-center justify-center min-w-0 px-2",children:["spinner"===c.type?(0,r.jsx)("span",{"data-testid":"status-indicator","aria-label":c.label,className:"w-2.5 h-2.5 rounded-full mr-2 flex-shrink-0 border-2 border-t-transparent animate-spin ".concat(c.className)}):(0,r.jsx)("span",{"data-testid":"status-indicator","aria-label":c.label,className:"w-2.5 h-2.5 rounded-full mr-2 flex-shrink-0 ".concat(c.className)}),(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-gray-900 truncate text-center leading-tight",children:t}),(0,r.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[a&&(0,r.jsx)("span",{className:"truncate max-w-[100px] text-center",children:a}),s&&"(unknown)"!==s.currentBranch&&(0,r.jsxs)(r.Fragment,{children:[a&&(0,r.jsx)("span",{className:"text-gray-300",children:"/"}),(0,r.jsx)("span",{className:"truncate max-w-[80px] font-mono",title:s.currentBranch,"data-testid":"mobile-branch-name",children:en(s.currentBranch,20)}),s.isDirty&&(0,r.jsx)("span",{className:"text-amber-500",title:"Uncommitted changes",children:"*"})]})]})]})]}),(0,r.jsx)("div",{className:"w-10 flex-shrink-0 flex justify-end",children:o&&(0,r.jsx)("button",{type:"button",onClick:o,"aria-label":"Menu",className:"p-2 -mr-2 rounded-full hover:bg-gray-100 transition-colors",children:(0,r.jsx)(es,{path:el.menu})})})]})})}let eo=(0,l.memo)(function(e){let{path:t,className:a="w-5 h-5"}=e;return(0,r.jsx)("svg",{className:a,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})})}),ec=[{id:"terminal",label:"Terminal",icon:(0,r.jsx)(eo,{path:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})},{id:"history",label:"History",icon:(0,r.jsx)(eo,{path:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})},{id:"files",label:"Files",icon:(0,r.jsx)(eo,{path:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})},{id:"memo",label:"Memo",icon:(0,r.jsx)(eo,{path:"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"})},{id:"info",label:"Info",icon:(0,r.jsx)(eo,{path:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}];function ed(e){let{activeTab:t,onTabChange:a,hasNewOutput:n=!1,hasPrompt:s=!1}=e,i=(0,l.useCallback)(e=>{a(e)},[a]),o=(0,l.useCallback)(e=>{let a=e===t;return"".concat("flex flex-col items-center justify-center flex-1 py-2 px-1 transition-colors relative"," ").concat(a?"text-blue-600 bg-blue-50":"text-gray-500 hover:text-gray-700 hover:bg-gray-50")},[t]),c=(0,l.useMemo)(()=>(0,r.jsxs)(r.Fragment,{children:[n&&(0,r.jsx)("span",{"data-testid":"new-output-badge",className:"absolute top-1 right-1 w-2 h-2 bg-green-500 rounded-full","aria-label":"New output available"}),s&&(0,r.jsx)("span",{"data-testid":"prompt-badge",className:"absolute top-1 right-3 w-2 h-2 bg-yellow-500 rounded-full","aria-label":"Prompt waiting"})]}),[n,s]);return(0,r.jsx)("nav",{"data-testid":"mobile-tab-bar",role:"tablist","aria-label":"Mobile navigation",className:"fixed bottom-0 inset-x-0 bg-white border-t border-gray-200 flex pb-safe z-40",children:ec.map(e=>(0,r.jsxs)("button",{type:"button",role:"tab","aria-selected":t===e.id,"aria-label":e.label,onClick:()=>i(e.id),className:o(e.id),children:[e.icon,(0,r.jsx)("span",{className:"text-xs mt-1",children:e.label}),"terminal"===e.id&&c]},e.id))})}let eu={base:"px-6 py-3 rounded-lg font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus:ring-2 focus:ring-offset-2",primary:"bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500",secondary:"bg-white border-2 border-gray-300 hover:bg-gray-50 text-gray-800 focus:ring-gray-500",defaultSelected:"bg-gray-600 text-white hover:bg-gray-700"};function em(e){let{promptData:t,visible:a,answering:n,onRespond:s,onDismiss:i}=e,{shouldRender:o,animationClass:c}=G({visible:a&&null!==t,duration:300}),d=(0,l.useId)(),[u,m]=(0,l.useState)(null),[x,h]=(0,l.useState)(0),f=(0,l.useRef)(null);(0,l.useEffect)(()=>{a||h(0)},[a]);let g=(0,l.useCallback)(e=>{m(e.touches[0].clientY)},[]),b=(0,l.useCallback)(e=>{if(null===u)return;let t=e.touches[0].clientY-u;t>0&&h(t)},[u]),y=(0,l.useCallback)(()=>{x>100&&i&&i(),h(0),m(null)},[x,i]),v=(0,l.useCallback)(()=>{i&&i()},[i]),w=(0,l.useCallback)(e=>{e.stopPropagation()},[]);if(!o||!t)return null;let j="animate-fade-out"===c,N=x>0?"translateY(".concat(x,"px)"):void 0;return(0,r.jsxs)(p,{componentName:"MobilePromptSheet",children:[(0,r.jsx)("div",{"data-testid":"prompt-overlay",onClick:v,className:"fixed inset-0 bg-black/50 z-50 transition-opacity duration-300 ".concat(j?"opacity-0":"opacity-100"," ").concat(j?"pointer-events-none":""),"aria-hidden":"true"}),(0,r.jsxs)("div",{ref:f,"data-testid":"mobile-prompt-sheet",role:"dialog","aria-modal":"true","aria-labelledby":d,onClick:w,onTouchStart:g,onTouchMove:b,onTouchEnd:y,style:{transform:N},className:"fixed bottom-0 inset-x-0 bg-white rounded-t-2xl z-50 pb-safe transform transition-transform duration-300 ".concat(j?"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-gray-300 rounded-full","aria-hidden":"true"})}),(0,r.jsx)("div",{className:"px-4 pb-6",children:(0,r.jsx)(ex,{promptData:t,answering:n,onRespond:s,labelId:d})})]})]})}function ex(e){let{promptData:t,answering:a,onRespond:n,labelId:s}=e,[i,o]=(0,l.useState)(()=>{if("multiple_choice"===t.type){var e;let a=t.options.find(e=>e.isDefault);return null!==(e=null==a?void 0:a.number)&&void 0!==e?e:null}return null}),[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)(!1),x=(0,l.useMemo)(()=>{var e;return"multiple_choice"!==t.type?null:null!==(e=t.options.find(e=>e.number===i))&&void 0!==e?e:null},[t,i]),h=(null==x?void 0:x.requiresTextInput)===!0,p=a||u,f=(0,l.useCallback)(async e=>{if(!p){m(!0);try{await n(e)}catch(e){}finally{m(!1)}}},[p,n]),g=(0,l.useCallback)(async()=>{if(!p&&null!==i){m(!0);try{let e=h&&c.trim()?c.trim():i.toString();await n(e)}catch(e){}finally{m(!1)}}},[p,n,i,h,c]);return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)("h3",{id:s,className:"text-lg font-semibold text-gray-900",children:"Claudeからの確認"}),(0,r.jsx)("p",{className:"text-gray-700 leading-relaxed",children:t.question}),p&&(0,r.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-gray-500",role:"status","aria-live":"polite",children:[(0,r.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,r.jsx)("span",{children:"送信中..."})]}),"yes_no"===t.type&&(0,r.jsx)(eh,{promptData:t,disabled:p,onYes:()=>f("yes"),onNo:()=>f("no")}),"multiple_choice"===t.type&&(0,r.jsx)(ep,{promptData:t,disabled:p,selectedOption:i,onSelectOption:o,textInputValue:c,onTextInputChange:d,showTextInput:h,onSubmit:g})]})}let eh=(0,l.memo)(function(e){let{promptData:t,disabled:a,onYes:n,onNo:s}=e,l="yes"===t.defaultOption,i="no"===t.defaultOption;return(0,r.jsxs)("div",{className:"flex gap-3",role:"group","aria-label":"Yes or No options",children:[(0,r.jsx)("button",{type:"button",onClick:n,disabled:a,className:"flex-1 ".concat(eu.base," ").concat(eu.primary," ").concat(l?"ring-2 ring-blue-300":""),children:"Yes"}),(0,r.jsx)("button",{type:"button",onClick:s,disabled:a,className:"flex-1 ".concat(eu.base," ").concat(i?eu.defaultSelected:eu.secondary),children:"No"})]})}),ep=(0,l.memo)(function(e){let{promptData:t,disabled:a,selectedOption:n,onSelectOption:s,textInputValue:i,onTextInputChange:o,showTextInput:c,onSubmit:d}=e,u=(0,l.useId)();return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("fieldset",{children:[(0,r.jsx)("legend",{className:"sr-only",children:"Select an option"}),(0,r.jsx)("div",{className:"space-y-2",children:t.options.map(e=>{let t=n===e.number;return(0,r.jsxs)("label",{className:"flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all ".concat(t?"bg-blue-50 border-2 border-blue-500":"bg-white border-2 border-gray-200 hover:border-gray-300"," ").concat(a?"opacity-50 cursor-not-allowed":""),children:[(0,r.jsx)("input",{type:"radio",name:u,value:e.number,checked:t,onChange:()=>s(e.number),disabled:a,className:"mt-1"}),(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",{className:"ml-2 text-xs text-blue-600 bg-blue-100 px-2 py-0.5 rounded",children:"デフォルト"})]})]},e.number)})})]}),c&&(0,r.jsxs)("div",{className:"mt-3",children:[(0,r.jsx)("label",{htmlFor:"text-input-".concat(u),className:"sr-only",children:"Custom value input"}),(0,r.jsx)("input",{id:"text-input-".concat(u),type:"text",value:i,onChange:e=>o(e.target.value),disabled:a,placeholder:"値を入力してください...",className:"w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500 disabled:opacity-50"})]}),(0,r.jsx)("button",{type:"button",onClick:d,disabled:a||null===n,className:"w-full ".concat(eu.base," ").concat(eu.primary),children:"Submit"})]})});var ef=a(6940);let eg={isOpen:!1,position:{x:0,y:0},targetPath:null,targetType:null};var eb=a(88964),ey=a(49465),ev=a(17689),ew=a(45675),ej=a(18930);let eN=(0,l.memo)(function(e){let{isOpen:t,position:a,targetPath:n,targetType:s,onClose:i,onNewFile:o,onNewDirectory:c,onRename:d,onDelete:u,onUpload:m}=e,x=(0,l.useRef)(null),h=(0,l.useCallback)(e=>{e&&n&&e(n),i()},[n,i]),p=[{id:"new-file",label:"New File",icon:(0,r.jsx)(eb.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(o),showFor:["directory"]},{id:"new-directory",label:"New Directory",icon:(0,r.jsx)(ey.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(c),showFor:["directory"]},{id:"upload",label:"Upload File",icon:(0,r.jsx)(ev.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(m),showFor:["directory"],showDividerAfter:!0},{id:"rename",label:"Rename",icon:(0,r.jsx)(ew.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(d),showDividerAfter:"file"===s},{id:"delete",label:"Delete",icon:(0,r.jsx)(ej.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(u),variant:"danger"}].filter(e=>!e.showFor||s&&e.showFor.includes(s));return((0,l.useEffect)(()=>{if(!t)return;let e=e=>{if("Escape"===e.key){i();return}if("ArrowDown"===e.key||"ArrowUp"===e.key){var t;let a;e.preventDefault();let r=null===(t=x.current)||void 0===t?void 0:t.querySelectorAll('[role="menuitem"]');if(!(null==r?void 0:r.length))return;let n=Array.from(r).findIndex(e=>e===document.activeElement);a="ArrowDown"===e.key?n<r.length-1?n+1:0:n>0?n-1:r.length-1,r[a].focus()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,i]),(0,l.useEffect)(()=>{if(t&&x.current){let e=x.current.querySelector('[role="menuitem"]');e&&e.focus()}},[t]),t)?(0,r.jsx)("div",{ref:x,"data-testid":"context-menu",role:"menu","aria-label":"File actions",className:"fixed z-50 min-w-[160px] py-1 bg-white rounded-lg shadow-lg border border-gray-200 animate-in fade-in-0 zoom-in-95 duration-100",style:{left:"".concat(a.x,"px"),top:"".concat(a.y,"px")},children:p.map((e,t)=>(0,r.jsxs)(l.Fragment,{children:[(0,r.jsxs)("button",{role:"menuitem",onClick:e.onClick,disabled:!n,className:"w-full flex items-center gap-3 px-3 py-2 text-sm transition-colors focus:outline-none focus:bg-gray-100 ".concat("danger"===e.variant?"text-red-600 hover:bg-red-50 focus:bg-red-50":"text-gray-700 hover:bg-gray-100"," ").concat(n?"":"opacity-50 cursor-not-allowed"),children:[e.icon,(0,r.jsx)("span",{children:e.label})]}),e.showDividerAfter&&t<p.length-1&&(0,r.jsx)("div",{"data-testid":"context-menu-divider",className:"my-1 border-t border-gray-200"})]},e.id))}):null}),ek=(0,l.memo)(function(e){let{expanded:t}=e;return(0,r.jsx)("svg",{"data-testid":"chevron-icon",className:"w-4 h-4 text-gray-500 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"})})}),eC=(0,l.memo)(function(e){let{open:t}=e;return(0,r.jsx)("svg",{"data-testid":"folder-icon",className:"w-5 h-5 text-yellow-500",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"})})}),eS=(0,l.memo)(function(e){let{text:t,query:a}=e;if(!a||!a.trim())return(0,r.jsx)(r.Fragment,{children:t});let n=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=t.split(RegExp("(".concat(n,")"),"gi"));return(0,r.jsx)(r.Fragment,{children:s.map((e,t)=>e.toLowerCase()===a.toLowerCase()?(0,r.jsx)("mark",{className:"bg-yellow-200 text-gray-900 px-0.5 rounded",children:e},t):(0,r.jsx)("span",{children:e},t))})}),eE=(0,l.memo)(function(e){let{extension:t}=e,a=(0,l.useMemo)(()=>t&&({ts:"text-blue-500",tsx:"text-blue-500",js:"text-yellow-400",jsx:"text-yellow-400",json:"text-yellow-600",md:"text-gray-500",css:"text-pink-500",scss:"text-pink-500",html:"text-orange-500",py:"text-green-500"})[t]||"text-gray-400",[t]);return(0,r.jsx)("svg",{"data-testid":"file-icon",className:"w-5 h-5 ".concat(a),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"})})}),eM=(0,l.memo)(function e(t){var a;let{item:n,path:s,depth:i,worktreeId:o,expanded:c,cache:d,onToggle:u,onFileSelect:m,onLoadChildren:x,onContextMenu:h,searchQuery:p,searchMode:f,matchedPaths:g}=t,[b,y]=(0,l.useState)(!1),v=s?"".concat(s,"/").concat(n.name):n.name,w=c.has(v),j="directory"===n.type,N=d.get(v),k=(0,l.useCallback)(async()=>{j?(w||N||(y(!0),await x(v),y(!1)),u(v)):null==m||m(v)},[j,w,N,v,x,u,m]),C=(0,l.useCallback)(e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),k())},[k]),S=(0,l.useCallback)(e=>{null==h||h(e,v,j?"directory":"file")},[v,j,h]);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":j?w:void 0,tabIndex:0,className:"flex items-center gap-2 py-1.5 pr-2 cursor-pointer hover:bg-gray-100 rounded transition-colors",style:{paddingLeft:"".concat(.5+1*Math.min(i,20),"rem")},onClick:k,onKeyDown:C,onContextMenu:S,children:[j?(0,r.jsx)("span",{className:"w-4 h-4 flex items-center justify-center",children:b?(0,r.jsx)("span",{className:"w-3 h-3 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}):(0,r.jsx)(ek,{expanded:w})}):(0,r.jsx)("span",{className:"w-4 h-4"}),j?(0,r.jsx)(eC,{open:w}):(0,r.jsx)(eE,{extension:n.extension}),(0,r.jsx)("span",{className:"flex-1 truncate text-sm text-gray-700",children:"name"===f&&p?(0,r.jsx)(eS,{text:n.name,query:p}):n.name}),(0,r.jsx)("span",{className:"text-xs text-gray-400 flex-shrink-0",children:j?void 0!==n.itemCount&&"".concat(n.itemCount," items"):void 0===(a=n.size)?"":a<1024?"".concat(a," B"):a<1048576?"".concat((a/1024).toFixed(1)," KB"):"".concat((a/1048576).toFixed(1)," MB")})]}),j&&w&&N&&(0,r.jsx)("div",{role:"group",children:N.filter(e=>{let t=v?"".concat(v,"/").concat(e.name):e.name;if(!(null==p?void 0:p.trim()))return!0;if("name"===f){let t=p.toLowerCase();return!!e.name.toLowerCase().includes(t)||"directory"===e.type}if("content"===f&&g&&g.size>0){if(g.has(t))return!0;if("directory"===e.type){for(let e of g)if(e.startsWith(t+"/"))return!0}return!1}return!0}).map(t=>(0,r.jsx)(e,{item:t,path:v,depth:i+1,worktreeId:o,expanded:c,cache:d,onToggle:u,onFileSelect:m,onLoadChildren:x,onContextMenu:h,searchQuery:p,searchMode:f,matchedPaths:g},t.name))})]})}),eT=(0,l.memo)(function(e){let{worktreeId:t,onFileSelect:a,onNewFile:n,onNewDirectory:s,onRename:i,onDelete:o,onUpload:c,className:d="",refreshTrigger:u=0,searchQuery:m,searchMode:x,searchResults:h,onSearchResultSelect:p}=e,[f,g]=(0,l.useState)(!0),[b,y]=(0,l.useState)(null),[v,w]=(0,l.useState)([]),[j,N]=(0,l.useState)(new Set),[k,C]=(0,l.useState)(()=>new Map),{menuState:S,openMenu:E,closeMenu:M}=function(){let[e,t]=(0,l.useState)(eg),a=(0,l.useCallback)((e,a,r)=>{e.preventDefault(),t({isOpen:!0,position:{x:e.clientX,y:e.clientY},targetPath:a,targetType:r})},[]),r=(0,l.useCallback)(()=>{t(e=>({...e,isOpen:!1}))},[]),n=(0,l.useCallback)(()=>{t(eg)},[]);return(0,l.useEffect)(()=>{if(!e.isOpen)return;let t=()=>{r()},a=setTimeout(()=>{document.addEventListener("click",t)},0);return()=>{clearTimeout(a),document.removeEventListener("click",t)}},[e.isOpen,r]),(0,l.useEffect)(()=>{if(!e.isOpen)return;let t=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[e.isOpen,r]),{menuState:e,openMenu:a,closeMenu:r,resetMenu:n}}(),T=(0,l.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{let a=e?"/api/worktrees/".concat(t,"/tree/").concat(e):"/api/worktrees/".concat(t,"/tree"),r=await fetch(a);if(!r.ok)throw Error("Failed to load directory: ".concat(r.status));return await r.json()}catch(e){throw console.error("[FileTreeView] Error fetching directory:",e),e}},[t]);(0,l.useEffect)(()=>{let e=!0;return(async()=>{g(!0),y(null),C(new Map);try{let t=await T();e&&t&&w(t.items)}catch(t){e&&y(t instanceof Error?t.message:"Failed to load files")}finally{e&&g(!1)}})(),()=>{e=!1}},[T,u]);let L=(0,l.useCallback)(async e=>{if(!k.has(e))try{let t=await T(e);t&&k.set(e,t.items)}catch(e){console.error("[FileTreeView] Error loading children:",e)}},[k,T]),R=(0,l.useCallback)(e=>{N(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},[]),A=(0,l.useMemo)(()=>"content"===x&&h&&0!==h.length?er(h.map(e=>e.filePath)):new Set,[x,h]);(0,l.useEffect)(()=>{A.size>0&&N(e=>{let t=new Set(e);for(let e of A)(k.has(e)||(null==h?void 0:h.some(t=>t.filePath.startsWith(e+"/"))))&&t.add(e);return t})},[A,k,h]);let F=(0,l.useMemo)(()=>{if(!(null==m?void 0:m.trim()))return v;if("name"===x){let e=m.toLowerCase(),t=(a,r)=>a.filter(a=>{let n=r?"".concat(r,"/").concat(a.name):a.name,s=a.name.toLowerCase().includes(e);if("directory"===a.type){let e=k.get(n);if(e&&t(e,n).length>0)return!0}return s});return t(v,"")}return"content"===x&&A.size>0?v.filter(e=>{if(A.has(e.name))return!0;if("directory"===e.type){for(let t of A)if(t.startsWith(e.name+"/")||t===e.name)return!0}return!1}):v},[v,m,x,A,k]);return f?(0,r.jsxs)("div",{"data-testid":"file-tree-loading",className:"flex items-center justify-center p-4 ".concat(d),children:[(0,r.jsx)("span",{className:"w-5 h-5 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}),(0,r.jsx)("span",{className:"ml-2 text-sm text-gray-500",children:"Loading files..."})]}):b?(0,r.jsx)("div",{"data-testid":"file-tree-error",className:"p-4 bg-red-50 border border-red-200 rounded-lg ".concat(d),children:(0,r.jsx)("p",{className:"text-sm text-red-600",children:b})}):0===v.length?(0,r.jsx)("div",{"data-testid":"file-tree-empty",className:"p-4 text-center text-gray-500 ".concat(d),children:(0,r.jsx)("p",{className:"text-sm",children:"No files found"})}):(null==m?void 0:m.trim())&&0===F.length?(0,r.jsx)("div",{"data-testid":"file-tree-no-results",className:"p-4 text-center text-gray-500 ".concat(d),children:(0,r.jsxs)("p",{className:"text-sm",children:["No ","content"===x?"files containing":"files matching",' "',m,'"']})}):(0,r.jsxs)("div",{"data-testid":"file-tree-view",role:"tree","aria-label":"File tree",className:"overflow-auto bg-white ".concat(d),children:[F.map(e=>(0,r.jsx)(eM,{item:e,path:"",depth:0,worktreeId:t,expanded:j,cache:k,onToggle:R,onFileSelect:p||a,onLoadChildren:L,onContextMenu:E,searchQuery:m,searchMode:x,matchedPaths:A},e.name)),(0,r.jsx)(eN,{isOpen:S.isOpen,position:S.position,targetPath:S.targetPath,targetType:S.targetType,onClose:M,onNewFile:n,onNewDirectory:s,onRename:i,onDelete:o,onUpload:c})]})}),eL=(0,l.memo)(function(){return(0,r.jsx)("svg",{className:"w-4 h-4 text-gray-400",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"})})}),eR=(0,l.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"})})}),eA=(0,l.memo)(function(){return(0,r.jsx)("div",{"data-testid":"search-loading",className:"w-4 h-4 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin","aria-label":"Searching..."})}),eF=(0,l.memo)(function(e){let{query:t,mode:a,isSearching:n,error:s,onQueryChange:i,onModeChange:o,onClear:c,placeholder:d="Search files...",className:u=""}=e,m=(0,l.useRef)(null),x=(0,l.useCallback)(e=>{i(e.target.value)},[i]),h=(0,l.useCallback)(()=>{var e;c(),null===(e=m.current)||void 0===e||e.focus()},[c]),p=(0,l.useCallback)(e=>{if("Escape"===e.key){if(t)h();else{var a;null===(a=m.current)||void 0===a||a.blur()}}},[t,h]);return(0,l.useEffect)(()=>{if(!(window.innerWidth<768)){let e=setTimeout(()=>{var e;null===(e=m.current)||void 0===e||e.focus()},100);return()=>clearTimeout(e)}},[]),(0,r.jsxs)("div",{"data-testid":"search-bar",className:"flex flex-col gap-2 p-2 bg-white border-b border-gray-200 ".concat(u),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)(eL,{})}),(0,r.jsx)("input",{ref:m,type:"text","data-testid":"search-input",value:t,onChange:x,onKeyDown:p,placeholder:d,className:"flex-1 min-w-0 px-2 py-1 text-sm bg-gray-50 border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500","aria-label":"Search files","aria-busy":n}),(0,r.jsx)("div",{className:"flex-shrink-0 w-6 h-6 flex items-center justify-center",children:n?(0,r.jsx)(eA,{}):t?(0,r.jsx)("button",{type:"button","data-testid":"search-clear",onClick:h,className:"p-1 text-gray-400 hover:text-gray-600 rounded transition-colors","aria-label":"Clear search",children:(0,r.jsx)(eR,{})}):null})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("span",{className:"text-xs text-gray-500 mr-1",children:"Mode:"}),(0,r.jsx)("button",{type:"button","data-testid":"mode-name",onClick:()=>o("name"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("name"===a?"bg-blue-100 text-blue-700 font-medium":"bg-gray-100 text-gray-600 hover:bg-gray-200"),"aria-pressed":"name"===a,children:"Name"}),(0,r.jsx)("button",{type:"button","data-testid":"mode-content",onClick:()=>o("content"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("content"===a?"bg-blue-100 text-blue-700 font-medium":"bg-gray-100 text-gray-600 hover:bg-gray-200"),"aria-pressed":"content"===a,children:"Content"})]}),s&&(0,r.jsx)("div",{"data-testid":"search-error",className:"text-xs text-red-600 bg-red-50 px-2 py-1 rounded",role:"alert",children:s})]})}),eP=(0,l.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:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})})}),eD=(0,l.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:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})})}),eI=(0,l.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:"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"})})}),e_=[{id:"history",label:"History",icon:(0,r.jsx)(eP,{})},{id:"files",label:"Files",icon:(0,r.jsx)(eD,{})},{id:"memo",label:"Memo",icon:(0,r.jsx)(eI,{})}],ez=(0,l.memo)(function(e){let{activeTab:t,onTabChange:a,className:n=""}=e,s=(0,l.useCallback)(e=>{a(e)},[a]),i=(0,l.useCallback)((e,t)=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),a(e))},[a]),o=(0,l.useCallback)(e=>{let a=e===t;return"".concat("flex items-center gap-2 px-4 py-2 text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-inset"," ").concat(a?"bg-blue-50 text-blue-600 border-b-2 border-blue-600":"text-gray-500 hover:text-gray-700 hover:bg-gray-50")},[t]);return(0,r.jsx)("div",{role:"tablist","aria-label":"Left pane view switcher",className:"flex border-b border-gray-200 bg-white ".concat(n),children:e_.map(e=>(0,r.jsxs)("button",{type:"button",role:"tab","aria-selected":t===e.id,"aria-label":e.label,tabIndex:0,onClick:()=>s(e.id),onKeyDown:t=>i(e.id,t),className:o(e.id),children:[e.icon,(0,r.jsx)("span",{children:e.label})]},e.id))})});var eO=a(10789);function eW(e){let{src:t,alt:a,onError:n}=e,[s,i]=(0,l.useState)(!1);return s?(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-gray-500",children:[(0,r.jsx)("svg",{className:"w-16 h-16 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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,r.jsx)("p",{className:"text-sm",children:"Failed to load image"}),(0,r.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:a})]}):(0,r.jsx)("div",{className:"flex items-center justify-center p-4",children:(0,r.jsx)("img",{src:t,alt:a,onError:()=>{i(!0),null==n||n()},style:{maxWidth:"100%",maxHeight:"500px",objectFit:"contain"},className:"rounded-lg shadow-sm"})})}function eB(e){let{isOpen:t,onClose:a,worktreeId:n,filePath:s}=e,[i,o]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(!t||!s){o(null),m(null);return}(async()=>{d(!0),m(null);try{let e=await fetch("/api/worktrees/".concat(n,"/files/").concat(s));if(!e.ok){let t=await e.json();throw Error(t.error||"Failed to load file")}let t=await e.json();o(t)}catch(e){m(e instanceof Error?e.message:"Failed to load file")}finally{d(!1)}})()},[t,n,s]),(0,r.jsx)(eO.u_,{isOpen:t,onClose:a,title:s,size:"xl",children:(0,r.jsxs)("div",{className:"max-h-[60vh] sm:max-h-[70vh] overflow-y-auto",children:[c&&(0,r.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,r.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,r.jsx)("p",{className:"ml-3 text-gray-600",children:"Loading file..."})]}),u&&(0,r.jsx)("div",{className:"bg-red-50 border border-red-200 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-red-600",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-red-800",children:u})]})}),i&&!c&&!u&&(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg overflow-hidden",children:[(0,r.jsx)("div",{className:"bg-gray-100 px-4 py-2 border-b border-gray-200",children:(0,r.jsxs)("p",{className:"text-xs text-gray-600 font-mono",children:[i.worktreePath,"/",i.path]})}),i.isImage?(0,r.jsx)(eW,{src:i.content,alt:i.path,mimeType:i.mimeType}):(0,r.jsx)("div",{className:"p-4",children:(0,r.jsx)("pre",{className:"text-sm overflow-x-auto",children:(0,r.jsx)("code",{className:"language-".concat(i.extension),children:i.content})})})]})]})})}var eU=a(54887),eV=a(53012),eH=a(23260),eZ=a(57934),eY=a(12158);a(57792);var eq=a(76865),eG=a(48736),eK=a(93807),eJ=a(42208),eX=a(74440),eQ=a(47416),e$=a(83229),e0=a(32489),e1=a(41671),e2=a(99388),e4=a(33245);function e5(e){let{type:t,iconColor:a}=e,n="h-5 w-5 ".concat(a);switch(t){case"success":return(0,r.jsx)(e1.Z,{className:n,"data-testid":"toast-icon-success"});case"error":return(0,r.jsx)(e2.Z,{className:n,"data-testid":"toast-icon-error"});default:return(0,r.jsx)(e4.Z,{className:n,"data-testid":"toast-icon-info"})}}function e3(e){let{id:t,message:a,type:n,onClose:s,duration:i=3e3}=e,o=(0,l.useRef)(null),c=function(e){switch(e){case"success":return{bgColor:"bg-green-50",borderColor:"border-green-200",textColor:"text-green-800",iconColor:"text-green-500"};case"error":return{bgColor:"bg-red-50",borderColor:"border-red-200",textColor:"text-red-800",iconColor:"text-red-500"};default:return{bgColor:"bg-blue-50",borderColor:"border-blue-200",textColor:"text-blue-800",iconColor:"text-blue-500"}}}(n);(0,l.useEffect)(()=>(i>0&&(o.current=setTimeout(()=>{s(t)},i)),()=>{o.current&&clearTimeout(o.current)}),[t,i,s]);let d=(0,l.useCallback)(()=>{o.current&&clearTimeout(o.current),s(t)},[t,s]);return(0,r.jsxs)("div",{"data-testid":"toast-".concat(t),role:"alert",className:"\n ".concat(c.bgColor,"\n ").concat(c.borderColor,"\n ").concat(c.textColor,"\n border rounded-lg shadow-lg p-4 min-w-[300px] max-w-[400px]\n flex items-start gap-3\n animate-slide-in\n "),children:[(0,r.jsx)(e5,{type:n,iconColor:c.iconColor}),(0,r.jsx)("p",{className:"flex-1 text-sm font-medium",children:a}),(0,r.jsx)("button",{"data-testid":"toast-close-button",onClick:d,"aria-label":"Close notification",className:"\n ".concat(c.textColor,"\n hover:opacity-70\n focus:outline-none focus:ring-2 focus:ring-offset-2\n transition-opacity\n "),children:(0,r.jsx)(e0.Z,{className:"h-4 w-4"})})]})}function e6(e){let{toasts:t,onClose:a}=e;return(0,r.jsx)("div",{"data-testid":"toast-container","aria-live":"polite",className:"fixed bottom-4 right-4 z-50 flex flex-col gap-2",children:t.map(e=>(0,r.jsx)(e3,{id:e.id,message:e.message,type:e.type,onClose:a,duration:e.duration},e.id))})}function e8(){let[e,t]=(0,l.useState)([]),a=(0,l.useRef)(0);return{toasts:e,showToast:(0,l.useCallback)(function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e3,s="toast-".concat(++a.current,"-").concat(Date.now()),l={id:s,message:e,type:r,duration:n};return t(e=>[...e,l]),s},[]),removeToast:(0,l.useCallback)(e=>{t(t=>t.filter(t=>t.id!==e))},[]),clearToasts:(0,l.useCallback)(()=>{t([])},[])}}var e7=a(30166),e9=a(51817);let te=(0,e7.default)(()=>Promise.all([a.e(2714),a.e(656),a.e(13)]).then(a.bind(a,70013)).then(e=>({default:e.MermaidDiagram})),{loadableGenerated:{webpack:()=>[70013]},ssr:!1,loading:()=>(0,r.jsxs)("div",{className:"mermaid-loading flex items-center gap-2 text-gray-500 p-4",children:[(0,r.jsx)(e9.Z,{className:"animate-spin h-4 w-4"}),(0,r.jsx)("span",{children:"Loading diagram..."})]})});function tt(e){let{className:t,children:a,inline:n}=e;if(n)return(0,r.jsx)("code",{className:t,children:a});if(t&&t.split(" ").includes("language-mermaid")){let e=null==a?"":"string"==typeof a?a:Array.isArray(a)?a.map(e=>"string"==typeof e?e:"").join(""):String(a);return(0,r.jsx)(te,{code:e})}return(0,r.jsx)("code",{className:t,children:a})}function ta(){return"undefined"==typeof document?null:document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||null}async function tr(e){if(e.requestFullscreen)return e.requestFullscreen();if(e.webkitRequestFullscreen)return e.webkitRequestFullscreen();if(e.mozRequestFullScreen)return e.mozRequestFullScreen();if(e.msRequestFullscreen)return e.msRequestFullscreen();throw Error("Fullscreen API not supported")}async function tn(){if("undefined"!=typeof document){if(document.exitFullscreen)return document.exitFullscreen();if(document.webkitExitFullscreen)return document.webkitExitFullscreen();if(document.mozCancelFullScreen)return document.mozCancelFullScreen();if(document.msExitFullscreen)return document.msExitFullscreen()}}function ts(){try{let e="__localStorage_test__";return window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e),!0}catch(e){return!1}}function tl(e){let{key:t,defaultValue:a,validate:r,serialize:n=JSON.stringify,deserialize:s=JSON.parse}=e,[i,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)(a),u=(0,l.useCallback)(()=>{if(!ts())return a;try{let e=window.localStorage.getItem(t);if(null===e)return a;let n=s(e);if(r)return r(n)?n:a;return n}catch(e){return a}},[t,a,r,s]),m=(0,l.useCallback)(e=>{if(ts())try{let a=n(e);window.localStorage.setItem(t,a)}catch(e){}},[t,n]),x=(0,l.useCallback)(e=>{d(t=>{let a="function"==typeof e?e(t):e;return m(a),a})},[m]),h=(0,l.useCallback)(()=>{if(ts())try{window.localStorage.removeItem(t)}catch(e){}d(a)},[t,a]);return(0,l.useEffect)(()=>{o(ts()),d(u())},[u]),{value:c,setValue:x,removeValue:h,isAvailable:i}}let ti=()=>null!=window.visualViewport;var to=a(3468);let tc={split:{showEditor:!0,showPreview:!0,editorWidth:"w-1/2",previewWidth:"w-1/2"},editor:{showEditor:!0,showPreview:!1,editorWidth:"w-full",previewWidth:"w-0"},preview:{showEditor:!1,showPreview:!0,editorWidth:"w-0",previewWidth:"w-full"}},td="commandmate:md-editor-view-mode",tu={WARNING_THRESHOLD:512e3};function tm(e){return"number"==typeof e&&e>=.1&&e<=.9}function tx(e){return"boolean"==typeof e}function th(e){return"split"===e||"editor"===e||"preview"===e}function tp(e){let{worktreeId:t,filePath:a,onClose:n,onSave:s,initialViewMode:i,onMaximizedChange:o}=e,[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)(""),[h,p]=(0,l.useState)(""),[f,g]=(0,l.useState)(()=>(function(e){if(e&&th(e))return e;{let e=localStorage.getItem(td);if(e&&th(e))return e}return"split"})(i)),[b,y]=(0,l.useState)(!0),[v,j]=(0,l.useState)(!1),[N,k]=(0,l.useState)(null),[C,S]=(0,l.useState)(!1),[E,M]=(0,l.useState)("editor"),[T,L]=(0,l.useState)(null),{toasts:R,showToast:A,removeToast:F}=e8(),P=(0,l.useRef)(null),D=(0,l.useRef)(null),I=(0,l.useRef)(null),_=(0,l.useRef)(null),z=(0,x.d)(),{isKeyboardVisible:O,keyboardHeight:W}=function(){let[e,t]=(0,l.useState)(!1),[a,r]=(0,l.useState)(0),n=(0,l.useCallback)(()=>{if(!ti())return;let e=window.visualViewport,a=window.innerHeight-e.height,n=a>100;t(n),r(n?a:0)},[]);return(0,l.useEffect)(()=>{if(!ti())return;let e=window.visualViewport;return n(),e.addEventListener("resize",n),()=>{e.removeEventListener("resize",n)}},[n]),{isKeyboardVisible:e,keyboardHeight:a}}(),{value:B,setValue:U}=tl({key:"commandmate:md-editor-maximized",defaultValue:!1,validate:tx}),{isFullscreen:V,isFallbackMode:H,enterFullscreen:Z,exitFullscreen:Y,toggleFullscreen:q}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{elementRef:t,onEnter:a,onExit:r,onError:n}=e,[s,i]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),m=(0,l.useCallback)(()=>{let e=null!=ta();i(e),!e&&o&&c(!1)},[o]),x=(0,l.useCallback)(async()=>{if(u(null),"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1)){i(!0),c(!0),null==a||a();return}if("undefined"!=typeof document&&(document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled)&&(null==t?void 0:t.current))try{await tr(t.current),i(!0),c(!1),null==a||a()}catch(t){let e=t instanceof Error?t.message:"Failed to enter fullscreen";u(e),null==n||n(t instanceof Error?t:Error(e)),i(!0),c(!0),null==a||a()}else i(!0),c(!0),null==a||a()},[t,a,n]),h=(0,l.useCallback)(async()=>{if(u(null),o){i(!1),c(!1),null==r||r();return}if(ta())try{await tn(),i(!1),null==r||r()}catch(t){let e=t instanceof Error?t.message:"Failed to exit fullscreen";u(e),null==n||n(t instanceof Error?t:Error(e)),i(!1),c(!1),null==r||r()}else i(!1),c(!1),null==r||r()},[o,r,n]),p=(0,l.useCallback)(async()=>{s?await h():await x()},[s,x,h]);return(0,l.useEffect)(()=>{if("undefined"!=typeof document)return document.addEventListener("fullscreenchange",m),document.addEventListener("webkitfullscreenchange",m),document.addEventListener("mozfullscreenchange",m),document.addEventListener("MSFullscreenChange",m),()=>{document.removeEventListener("fullscreenchange",m),document.removeEventListener("webkitfullscreenchange",m),document.removeEventListener("mozfullscreenchange",m),document.removeEventListener("MSFullscreenChange",m)}},[m]),{isFullscreen:s,isFallbackMode:o,enterFullscreen:x,exitFullscreen:h,toggleFullscreen:p,error:d}}({elementRef:I,onEnter:()=>U(!0),onExit:()=>U(!1)}),{value:G,setValue:K}=tl({key:"commandmate:md-editor-split-ratio",defaultValue:.5,validate:tm}),{ref:J}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onSwipeLeft:t,onSwipeRight:a,onSwipeUp:r,onSwipeDown:n,threshold:s=50,enabled:i=!0}=e,o=(0,l.useRef)(null),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null),x=(0,l.useRef)(null),h=(0,l.useCallback)(()=>{m(null)},[]),p=(0,l.useCallback)(e=>{if(!i)return;let t=e.touches[0];x.current={x:t.clientX,y:t.clientY},d(!0)},[i]),f=(0,l.useCallback)(e=>{if(!i||!x.current)return;let t=e.touches[0],a=t.clientX-x.current.x,r=t.clientY-x.current.y,n=Math.abs(a),l=Math.abs(r);n>l&&n>=s?m(a<0?"left":"right"):l>=s&&m(r<0?"up":"down")},[i,s]),g=(0,l.useCallback)(e=>{if(!i||!x.current){d(!1);return}let l=e.changedTouches[0],o=l.clientX-x.current.x,c=l.clientY-x.current.y,u=Math.abs(o),h=Math.abs(c);u>h?u>=s&&(o<0?(m("left"),null==t||t()):(m("right"),null==a||a())):h>=s&&(c<0?(m("up"),null==r||r()):(m("down"),null==n||n())),x.current=null,d(!1)},[i,s,t,a,r,n]);return(0,l.useEffect)(()=>{let e=o.current;if(e)return e.addEventListener("touchstart",p),e.addEventListener("touchmove",f),e.addEventListener("touchend",g),()=>{e.removeEventListener("touchstart",p),e.removeEventListener("touchmove",f),e.removeEventListener("touchend",g)}},[p,f,g]),{ref:o,isSwiping:c,swipeDirection:u,resetSwipeDirection:h}}({onSwipeDown:()=>{V&&Y()},threshold:100,enabled:V&&z}),X=c!==u,Q=tc[f],$=z&&window.innerHeight>window.innerWidth&&"split"===f,ee=(0,l.useMemo)(()=>ea(e=>{p(e)},300),[]),et=(0,l.useCallback)(async()=>{y(!0),k(null);try{let r=await fetch("/api/worktrees/".concat(t,"/files/").concat(a)),n=await r.json();if(!r.ok||!n.success){var e;throw Error((null===(e=n.error)||void 0===e?void 0:e.message)||"Failed to load file")}let s=n.content||"";d(s),m(s),p(s),new Blob([s]).size>tu.WARNING_THRESHOLD&&S(!0)}catch(e){k(e instanceof Error?e.message:"Failed to load file")}finally{y(!1)}},[t,a]),er=(0,l.useCallback)(async()=>{if(X&&!v){j(!0);try{let r=await fetch("/api/worktrees/".concat(t,"/files/").concat(a),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:c})}),n=await r.json();if(!r.ok||!n.success){var e;throw Error((null===(e=n.error)||void 0===e?void 0:e.message)||"Failed to save file")}m(c),A("File saved successfully","success"),s&&s(a)}catch(e){A(e instanceof Error?e.message:"Failed to save file","error")}finally{j(!1)}}},[t,a,c,X,v,s,A]),en=(0,l.useCallback)(e=>{let t=e.target.value;d(t),ee(t)},[ee]),es=(0,l.useCallback)(e=>{g(e),localStorage.setItem(td,e)},[]),el=(0,l.useCallback)(()=>{(!X||window.confirm("You have unsaved changes. Are you sure you want to close?"))&&n&&n()},[X,n]),ei=(0,l.useCallback)(e=>{if(!_.current)return;let t=_.current.offsetWidth;if(0===t)return;let a=e/t;K(e=>Math.max(.1,Math.min(.9,e+a)))},[K]),eo=(0,l.useCallback)(()=>{K(.5)},[K]),ec=(0,l.useCallback)(e=>{if((e.ctrlKey||e.metaKey)&&"s"===e.key){e.preventDefault(),er();return}if((e.ctrlKey||e.metaKey)&&e.shiftKey&&"F"===e.key){e.preventDefault(),q();return}if("Escape"===e.key&&V){e.preventDefault(),Y();return}},[er,q,Y,V]);(0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&V&&(e.preventDefault(),Y())};return V&&document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[V,Y]),(0,l.useEffect)(()=>{B&&!V&&Z()},[]),(0,l.useEffect)(()=>{if("undefined"==typeof document)return;let e=document.getElementById("markdown-editor-portal");return e||((e=document.createElement("div")).id="markdown-editor-portal",document.body.appendChild(e)),L(e),()=>{let e=document.getElementById("markdown-editor-portal");e&&0===e.childNodes.length&&e.remove()}},[]),(0,l.useEffect)(()=>{null==o||o(V)},[V,o]),(0,l.useEffect)(()=>{et()},[et]),(0,l.useEffect)(()=>{let e=e=>{X&&(e.preventDefault(),e.returnValue="")};return X?(D.current=e,window.addEventListener("beforeunload",e)):D.current&&(window.removeEventListener("beforeunload",D.current),D.current=null),()=>{D.current&&window.removeEventListener("beforeunload",D.current)}},[X]);let ed=(0,l.useMemo)(()=>{let e="flex flex-col bg-white";return V&&H?"".concat(e," fixed inset-0"):"".concat(e," h-full")},[V,H]),eu=(0,l.useMemo)(()=>{if(V)return{zIndex:to.k.MAXIMIZED_EDITOR}},[V]),em=(0,l.useMemo)(()=>{if("split"===f&&!$)return{width:"".concat(100*G,"%"),flexShrink:0}},[f,G,$]),ex=(0,l.useMemo)(()=>{if("split"===f&&!$)return{width:"".concat((1-G)*100,"%"),flexShrink:0}},[f,G,$]),eh=(0,l.useMemo)(()=>{if(O&&W>0)return{paddingBottom:W}},[O,W]),ep=(0,l.useMemo)(()=>({code:tt}),[]),ef=(0,l.useMemo)(()=>(0,r.jsx)(eV.UG,{remarkPlugins:[eH.Z],rehypePlugins:[eZ.Z,eY.Z],components:ep,children:h}),[h,ep]);if(b)return(0,r.jsx)("div",{"data-testid":"markdown-editor",className:"flex items-center justify-center h-full bg-white",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,r.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading..."})]})});if(N)return(0,r.jsx)("div",{"data-testid":"markdown-editor-error",className:"flex items-center justify-center h-full bg-white",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)(eq.Z,{className:"h-12 w-12 text-red-500 mx-auto mb-4"}),(0,r.jsx)("p",{className:"text-red-600",children:N}),n&&(0,r.jsx)("button",{onClick:n,className:"mt-4 px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg",children:"Close"})]})});let eg=(0,r.jsxs)("div",{ref:e=>{I.current=e,J.current=e},"data-testid":"markdown-editor",className:ed,style:eu,onKeyDown:ec,role:V&&H?"dialog":void 0,"aria-modal":V&&H?"true":void 0,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 bg-gray-50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-shrink",children:[(0,r.jsx)(eG.Z,{className:"h-4 w-4 text-gray-500 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-sm font-medium text-gray-700 truncate",children:a}),X&&(0,r.jsx)("span",{"data-testid":"dirty-indicator",className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 flex-shrink-0",children:"Unsaved"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!$&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-gray-100 rounded-lg p-1",children:[(0,r.jsx)("button",{"data-testid":"view-mode-split","aria-pressed":"split"===f,onClick:()=>es("split"),className:"p-1.5 rounded ".concat("split"===f?"bg-white shadow-sm text-blue-600":"text-gray-500 hover:text-gray-700"),title:"Split view",children:(0,r.jsx)(eK.Z,{className:"h-4 w-4"})}),(0,r.jsx)("button",{"data-testid":"view-mode-editor","aria-pressed":"editor"===f,onClick:()=>es("editor"),className:"p-1.5 rounded ".concat("editor"===f?"bg-white shadow-sm text-blue-600":"text-gray-500 hover:text-gray-700"),title:"Editor only",children:(0,r.jsx)(eG.Z,{className:"h-4 w-4"})}),(0,r.jsx)("button",{"data-testid":"view-mode-preview","aria-pressed":"preview"===f,onClick:()=>es("preview"),className:"p-1.5 rounded ".concat("preview"===f?"bg-white shadow-sm text-blue-600":"text-gray-500 hover:text-gray-700"),title:"Preview only",children:(0,r.jsx)(eJ.Z,{className:"h-4 w-4"})})]}),(0,r.jsx)("button",{"data-testid":"maximize-button",onClick:q,className:"p-1.5 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded",title:V?"Exit fullscreen (ESC)":"Enter fullscreen (Ctrl+Shift+F)","aria-pressed":V,children:V?(0,r.jsx)(eX.Z,{className:"h-4 w-4"}):(0,r.jsx)(eQ.Z,{className:"h-4 w-4"})}),(0,r.jsxs)("button",{"data-testid":"save-button",onClick:er,disabled:!X||v,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ".concat(X&&!v?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-100 text-gray-400 cursor-not-allowed"),children:[(0,r.jsx)(e$.Z,{className:"h-4 w-4"}),v?"Saving...":"Save"]}),n&&(0,r.jsx)("button",{"data-testid":"close-button",onClick:el,className:"p-1.5 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded",title:"Close",children:(0,r.jsx)(e0.Z,{className:"h-4 w-4"})})]})]}),V&&(0,r.jsxs)("div",{"data-testid":"maximize-hint",className:"flex items-center justify-center px-4 py-1 bg-gray-800 text-gray-300 text-xs",children:["Press ESC to exit fullscreen ",z&&"(or swipe down)"]}),C&&(0,r.jsxs)("div",{"data-testid":"large-file-warning",className:"flex items-center gap-2 px-4 py-2 bg-yellow-50 border-b border-yellow-200 text-yellow-800 text-sm",children:[(0,r.jsx)(eq.Z,{className:"h-4 w-4"}),"Large file: Performance may be affected.",(0,r.jsx)("button",{onClick:()=>S(!1),className:"ml-auto text-yellow-600 hover:text-yellow-800",children:(0,r.jsx)(e0.Z,{className:"h-4 w-4"})})]}),$&&(0,r.jsxs)("div",{className:"flex border-b border-gray-200",children:[(0,r.jsxs)("button",{"data-testid":"mobile-tab-editor",onClick:()=>M("editor"),className:"flex-1 py-2 text-sm font-medium ".concat("editor"===E?"text-blue-600 border-b-2 border-blue-600":"text-gray-500"),children:[(0,r.jsx)(eG.Z,{className:"h-4 w-4 inline-block mr-1"}),"Editor"]}),(0,r.jsxs)("button",{"data-testid":"mobile-tab-preview",onClick:()=>M("preview"),className:"flex-1 py-2 text-sm font-medium ".concat("preview"===E?"text-blue-600 border-b-2 border-blue-600":"text-gray-500"),children:[(0,r.jsx)(eJ.Z,{className:"h-4 w-4 inline-block mr-1"}),"Preview"]})]}),(0,r.jsxs)("div",{ref:_,className:"flex flex-1 overflow-hidden",style:eh,children:[$?"editor"===E&&(0,r.jsx)("div",{"data-testid":"markdown-editor-container",className:"flex flex-col overflow-hidden w-full",children:(0,r.jsx)("textarea",{ref:P,"data-testid":"markdown-editor-textarea",value:c,onChange:en,onKeyDown:ec,className:"flex-1 p-4 font-mono text-sm resize-none focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-inset",placeholder:"Start typing markdown...",spellCheck:!1})}):(0,r.jsx)("div",{"data-testid":"markdown-editor-container",className:"flex flex-col overflow-hidden transition-all duration-200 ".concat(Q.showEditor?"":"hidden"),style:"split"===f?em:{width:Q.showEditor?"100%":"0%"},children:(0,r.jsx)("textarea",{ref:P,"data-testid":"markdown-editor-textarea",value:c,onChange:en,onKeyDown:ec,className:"flex-1 p-4 font-mono text-sm resize-none focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-inset",placeholder:"Start typing markdown...",spellCheck:!1})}),"split"===f&&Q.showEditor&&Q.showPreview&&!$&&(0,r.jsx)(w,{onResize:ei,onDoubleClick:eo,orientation:"horizontal",ariaValueNow:Math.round(100*G),minRatio:.1}),$?"preview"===E&&(0,r.jsx)("div",{"data-testid":"markdown-preview-container",className:"flex flex-col overflow-hidden w-full",children:(0,r.jsx)("div",{"data-testid":"markdown-preview",className:"flex-1 p-4 overflow-y-auto prose prose-sm max-w-none",children:ef})}):(0,r.jsx)("div",{"data-testid":"markdown-preview-container",className:"flex flex-col overflow-hidden transition-all duration-200 ".concat(Q.showPreview?"":"hidden"),style:"split"===f?ex:{width:Q.showPreview?"100%":"0%"},children:(0,r.jsx)("div",{"data-testid":"markdown-preview",className:"flex-1 p-4 overflow-y-auto prose prose-sm max-w-none",children:ef})})]}),(0,r.jsx)(e6,{toasts:R,onClose:F})]});return V&&H&&T?(0,eU.createPortal)(eg,T):eg}let tf=[".md"],tg=[{extension:".png",maxFileSize:5242880,allowedMimeTypes:["image/png"],magicBytes:[{bytes:[137,80,78,71,13,10,26,10]}]},{extension:".jpg",maxFileSize:5242880,allowedMimeTypes:["image/jpeg"],magicBytes:[{bytes:[255,216,255]}]},{extension:".jpeg",maxFileSize:5242880,allowedMimeTypes:["image/jpeg"],magicBytes:[{bytes:[255,216,255]}]},{extension:".gif",maxFileSize:5242880,allowedMimeTypes:["image/gif"],magicBytes:[{bytes:[71,73,70,56,55,97]},{bytes:[71,73,70,56,57,97]}]},{extension:".webp",maxFileSize:5242880,allowedMimeTypes:["image/webp"],magicBytes:[{bytes:[82,73,70,70],offset:0}]},{extension:".txt",maxFileSize:5242880,allowedMimeTypes:["text/plain"]},{extension:".log",maxFileSize:5242880,allowedMimeTypes:["text/plain"]},{extension:".md",maxFileSize:5242880,allowedMimeTypes:["text/markdown","text/plain"]},{extension:".csv",maxFileSize:5242880,allowedMimeTypes:["text/csv"]},{extension:".json",maxFileSize:5242880,allowedMimeTypes:["application/json"]},{extension:".yaml",maxFileSize:5242880,allowedMimeTypes:["text/yaml","application/x-yaml"]},{extension:".yml",maxFileSize:5242880,allowedMimeTypes:["text/yaml","application/x-yaml"]}],tb=tg.map(e=>e.extension);var ty=a(3227);function tv(e){let{value:t,saveFn:a,debounceMs:r=300,disabled:n=!1,maxRetries:s=3,onSaveComplete:i}=e,[o,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),m=(0,l.useRef)(t),x=(0,l.useRef)(a),h=(0,l.useRef)(i),p=(0,l.useRef)(null),f=(0,l.useRef)(!0),g=(0,l.useRef)(t);(0,l.useEffect)(()=>{m.current=t},[t]),(0,l.useEffect)(()=>{x.current=a},[a]),(0,l.useEffect)(()=>{h.current=i},[i]),(0,l.useEffect)(()=>(f.current=!0,()=>{f.current=!1,p.current&&clearTimeout(p.current)}),[]);let b=(0,l.useCallback)(async e=>{if(!f.current)return;c(!0),u(null);let t=null,a=0;for(;a<=s;)try{if(await x.current(e),f.current){var r;c(!1),u(null),null===(r=h.current)||void 0===r||r.call(h)}return}catch(e){if(t=e instanceof Error?e:Error(String(e)),++a<=s){let e=1e3*Math.pow(2,a-1);await new Promise(t=>setTimeout(t,e))}}f.current&&(c(!1),u(t))},[s]),y=(0,l.useCallback)(()=>{p.current&&(clearTimeout(p.current),p.current=null)},[]),v=(0,l.useCallback)(async()=>{n||(y(),await b(m.current))},[n,y,b]);return(0,l.useEffect)(()=>{if(t!==g.current&&!n)return y(),p.current=setTimeout(()=>{b(m.current)},r),()=>{y()}},[t,n,r,y,b]),{isSaving:o,error:d,saveNow:v}}let tw=(0,l.memo)(function(e){var t,a;let{memo:n,onUpdate:s,onDelete:i,isSaving:o,error:c,className:d=""}=e,[u,m]=(0,l.useState)(n.title),[x,h]=(0,l.useState)(n.content),{isSaving:p,error:f,saveNow:g}=tv({value:u,saveFn:async e=>{await s(n.id,{title:e})}}),{isSaving:b,error:y,saveNow:v}=tv({value:x,saveFn:async e=>{await s(n.id,{content:e})}}),w=null!==(a=null!==(t=null!=c?c:null==f?void 0:f.message)&&void 0!==t?t:null==y?void 0:y.message)&&void 0!==a?a:null,j=(0,l.useCallback)(e=>{m(e.target.value)},[]),N=(0,l.useCallback)(e=>{h(e.target.value)},[]),k=(0,l.useCallback)(()=>{g()},[g]),C=(0,l.useCallback)(()=>{v()},[v]),S=(0,l.useCallback)(()=>{i(n.id)},[n.id,i]);return(0,r.jsxs)("div",{"data-testid":"memo-card",className:"bg-white border border-gray-200 rounded-lg p-4 space-y-3 ".concat(d),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("input",{type:"text",value:u,onChange:j,onBlur:k,placeholder:"Memo title",className:"flex-1 text-sm font-medium text-gray-900 bg-transparent border-none focus:outline-none focus:ring-0 p-0"}),(null!=o?o:p||b)&&(0,r.jsx)("span",{"data-testid":"saving-indicator",className:"text-xs text-gray-400",children:"Saving..."}),(0,r.jsx)("button",{type:"button",onClick:S,"aria-label":"Delete memo",className:"p-1 text-gray-400 hover:text-red-500 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:x,onChange:N,onBlur:C,placeholder:"Enter memo content...",rows:4,className:"w-full text-sm text-gray-700 bg-gray-50 border border-gray-200 rounded-md p-2 resize-y focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),w&&(0,r.jsx)("div",{className:"text-xs text-red-500",children:w})]})}),tj=(0,l.memo)(function(e){let{currentCount:t,maxCount:a,onAdd:n,isLoading:s=!1,className:l=""}=e,i=t>=a||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:()=>{i||n()},disabled:i,"aria-label":"Add Memo","aria-disabled":i,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-blue-500\n ".concat(i?"border-gray-200 text-gray-400 cursor-not-allowed opacity-50":"border-gray-300 text-gray-600 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50","\n "),children:[s?(0,r.jsx)("span",{"data-testid":"loading-indicator",className:"w-5 h-5 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}):(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:"Add Memo"})]}),(0,r.jsxs)("span",{className:"text-xs text-gray-500",children:[Math.max(0,a-t)," remaining"]})]})}),tN=(0,l.memo)(function(e){let{worktreeId:t,className:a=""}=e,[n,s]=(0,l.useState)([]),[i,o]=(0,l.useState)(!0),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null),[x,h]=(0,l.useState)(null),p=(0,l.useCallback)(async()=>{o(!0),m(null);try{let e=await ty.nE.getAll(t);s(e.sort((e,t)=>e.position-t.position))}catch(e){m((0,ty.zG)(e))}finally{o(!1)}},[t]);(0,l.useEffect)(()=>{p()},[p]);let f=(0,l.useCallback)(async()=>{d(!0),h(null);try{let e=await ty.nE.create(t,{title:"Memo",content:""});s(t=>[...t,e])}catch(e){h((0,ty.zG)(e))}finally{d(!1)}},[t]),g=(0,l.useCallback)(async(e,a)=>{await ty.nE.update(t,e,a),s(t=>t.map(t=>t.id===e?{...t,...a}:t))},[t]),b=(0,l.useCallback)(async e=>{try{await ty.nE.delete(t,e),s(t=>t.filter(t=>t.id!==e))}catch(e){console.error("Failed to delete memo:",e)}},[t]),y=(0,l.useCallback)(()=>{p()},[p]);return i?(0,r.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(a),children:(0,r.jsxs)("div",{"data-testid":"memo-loading",className:"flex flex-col items-center gap-3",children:[(0,r.jsx)("div",{className:"w-8 h-8 border-4 border-gray-200 border-t-blue-500 rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm text-gray-500",children:"Loading memos..."})]})}):u?(0,r.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(a),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-red-400",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-red-600",children:u}),(0,r.jsx)("button",{type:"button",onClick:y,"aria-label":"Retry",className:"px-4 py-2 text-sm font-medium text-white bg-blue-500 rounded-lg hover:bg-blue-600 transition-colors",children:"Retry"})]})}):(0,r.jsxs)("div",{"data-testid":"memo-pane",className:"flex flex-col gap-4 p-4 overflow-y-auto ".concat(a),children:[0===n.length&&!x&&(0,r.jsxs)("div",{className:"text-center py-8 text-gray-500",children:[(0,r.jsx)("p",{children:"No memos yet."}),(0,r.jsx)("p",{className:"text-sm",children:"Click the button below to add one."})]}),n.map(e=>(0,r.jsx)(tw,{memo:e,onUpdate:g,onDelete:b},e.id)),x&&(0,r.jsx)("div",{className:"text-center py-2 text-sm text-red-500",children:x}),(0,r.jsx)(tj,{currentCount:n.length,maxCount:5,onAdd:f,isLoading:c,className:"mt-2"})]})});var tk=a(98702);function tC(e){let{isOpen:t,onConfirm:a,onCancel:n}=e;return(0,r.jsx)(tk.u,{isOpen:t,onClose:n,title:"Auto Yesモードを有効にしますか?",size:"sm",showCloseButton:!0,children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"text-sm text-gray-700",children:[(0,r.jsx)("p",{className:"font-medium mb-2",children:"機能説明"}),(0,r.jsxs)("ul",{className:"list-disc list-inside space-y-1",children:[(0,r.jsx)("li",{children:"yes/no確認 → 自動で「yes」を送信"}),(0,r.jsx)("li",{children:"複数選択肢 → デフォルトまたは先頭の選択肢を自動選択"})]}),(0,r.jsx)("p",{className:"mt-1",children:"1時間後に自動でOFFになります。"})]}),(0,r.jsxs)("div",{className:"text-sm text-gray-700",children:[(0,r.jsx)("p",{className:"font-medium mb-2",children:"リスクについて"}),(0,r.jsx)("p",{children:"自動応答により、意図しない操作(ファイルの削除・上書き等)が 実行される可能性があります。内容を十分に理解した上でご利用ください。"})]}),(0,r.jsx)("div",{className:"bg-yellow-50 border-l-4 border-yellow-400 p-3",children:(0,r.jsxs)("p",{className:"text-sm text-yellow-800",children:[(0,r.jsx)("span",{className:"font-medium",children:"免責事項:"}),"Auto Yesモードの使用により発生した問題について、 開発者は一切の責任を負いません。自己責任でご利用ください。"]})}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,r.jsx)("button",{type:"button",onClick:n,className:"px-4 py-2 text-sm font-medium rounded-md bg-gray-200 hover:bg-gray-300 text-gray-700",children:"キャンセル"}),(0,r.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-sm font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 text-white",children:"同意して有効化"})]})]})})}let tS=(0,l.memo)(function(e){let{enabled:t,expiresAt:a,onToggle:n,lastAutoResponse:s}=e,[i,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)(!1),[x,h]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(!t||!a){o("");return}let e=()=>{o(function(e){let t=Math.max(0,e-Date.now());return"".concat(Math.floor(t/6e4).toString().padStart(2,"0"),":").concat(Math.floor(t%6e4/1e3).toString().padStart(2,"0"))}(a))};e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t,a]),(0,l.useEffect)(()=>{if(!s)return;d('Auto responded: "'.concat(s,'"'));let e=setTimeout(()=>d(null),2e3);return()=>clearTimeout(e)},[s]);let p=(0,l.useCallback)(()=>{t?(m(!0),n(!1).finally(()=>m(!1))):h(!0)},[t,n]),f=(0,l.useCallback)(()=>{h(!1),m(!0),n(!0).finally(()=>m(!1))},[n]),g=(0,l.useCallback)(()=>{h(!1)},[]);return(0,r.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 bg-gray-50 border-b border-gray-200",children:[(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":t,"aria-label":"Auto Yes mode",disabled:u,onClick:p,className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ".concat(t?"bg-blue-600":"bg-gray-300"," ").concat(u?"opacity-50":""),children:(0,r.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition-transform ".concat(t?"translate-x-6":"translate-x-1")})}),(0,r.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Auto Yes"}),t&&i&&(0,r.jsx)("span",{className:"text-sm text-gray-500","aria-label":"Time remaining",children:i}),c&&(0,r.jsx)("span",{className:"text-sm text-green-600 animate-pulse",children:c}),(0,r.jsx)(tC,{isOpen:x,onConfirm:f,onCancel:g})]})}),tE=(0,l.memo)(function(e){let{isBranchMismatch:t,currentBranch:a,initialBranch:n}=e,[s,i]=(0,l.useState)(!1);return((0,l.useEffect)(()=>{i(!1)},[a]),!t||s||null===n)?null:(0,r.jsxs)("div",{"data-testid":"branch-mismatch-alert",role:"alert",className:"flex items-center gap-3 px-4 py-2 bg-amber-50 border border-amber-200 text-amber-800 rounded-lg",children:[(0,r.jsx)(eq.Z,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),(0,r.jsx)("div",{className:"flex-1 min-w-0",children:(0,r.jsxs)("span",{className:"text-sm",children:["Branch changed from"," ",(0,r.jsx)("span",{className:"font-medium",children:n})," ","to"," ",(0,r.jsx)("span",{className:"font-medium",children:a})]})}),(0,r.jsx)("button",{type:"button",onClick:()=>i(!0),className:"p-1 rounded hover:bg-amber-100 transition-colors","aria-label":"Dismiss alert",children:(0,r.jsx)(e0.Z,{className:"w-4 h-4"})})]})}),tM=(0,l.memo)(function(e){let{worktreeName:t,repositoryName:a,description:n,status:s,gitStatus:l,onBackClick:i,onInfoClick:o,onMenuClick:c}=e,d=et.Ie[s],u=n?en(n,50):null;return(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 bg-white border-b border-gray-200",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("button",{type:"button",onClick:c,className:"p-2 -ml-2 rounded-lg text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors","aria-label":"Toggle sidebar",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:"M4 6h16M4 12h16M4 18h16"})})}),(0,r.jsx)("div",{className:"w-px h-6 bg-gray-300","aria-hidden":"true"}),(0,r.jsxs)("button",{type:"button",onClick:i,className:"flex items-center gap-1 text-gray-600 hover:text-gray-900 transition-colors","aria-label":"Go back to worktree list",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:"M15 19l-7-7 7-7"})}),(0,r.jsx)("span",{className:"text-sm font-medium",children:"Back"})]}),(0,r.jsx)("div",{className:"w-px h-6 bg-gray-300","aria-hidden":"true"}),"spinner"===d.type?(0,r.jsx)("span",{"data-testid":"desktop-status-indicator",title:d.label,"aria-label":d.label,className:"w-3 h-3 rounded-full flex-shrink-0 border-2 border-t-transparent animate-spin ".concat(d.className)}):(0,r.jsx)("span",{"data-testid":"desktop-status-indicator",title:d.label,"aria-label":d.label,className:"w-3 h-3 rounded-full flex-shrink-0 ".concat(d.className)}),(0,r.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h1",{className:"text-lg font-semibold text-gray-900 truncate max-w-[200px] leading-tight",children:t}),u&&(0,r.jsx)("span",{className:"text-sm text-gray-500 truncate max-w-md",title:n,children:u})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[(0,r.jsx)("span",{className:"truncate max-w-[200px]",children:a}),l&&"(unknown)"!==l.currentBranch&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-gray-300",children:"/"}),(0,r.jsx)("span",{className:"truncate max-w-[150px] font-mono",title:l.currentBranch,"data-testid":"desktop-branch-name",children:en(l.currentBranch,30)}),l.isDirty&&(0,r.jsx)("span",{className:"text-amber-500",title:"Uncommitted changes",children:"*"})]})]})]})]}),(0,r.jsxs)("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 px-3 py-1.5 text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors","aria-label":"View worktree information",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:"Info"})]})]})}),tT=(0,l.memo)(function(e){let{worktree:t,isOpen:a,onClose:n,onWorktreeUpdate:s}=e,[i,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)(!1),x=(0,l.useRef)(a);(0,l.useEffect)(()=>{let e=a&&!x.current;x.current=a,e&&t&&(d(t.description||""),o(!1))},[t,a]);let h=(0,l.useCallback)(async()=>{if(t){m(!0);try{let e=await ty.Iv.updateDescription(t.id,c);s(e),o(!1)}catch(e){console.error("Failed to save description:",e)}finally{m(!1)}}},[t,c,s]),p=(0,l.useCallback)(()=>{d((null==t?void 0:t.description)||""),o(!1)},[t]);return t?(0,r.jsx)(tk.u,{isOpen:a,onClose:n,title:"Worktree Information",size:"md",children:(0,r.jsxs)("div",{className:"space-y-4 max-h-[70vh] overflow-y-auto",children:[(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Worktree"}),(0,r.jsx)("p",{className:"text-lg font-semibold text-gray-900",children:t.name})]}),(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Repository"}),(0,r.jsx)("p",{className:"text-base text-gray-900",children:t.repositoryName}),(0,r.jsx)("p",{className:"text-xs text-gray-500 mt-1 break-all",children:t.repositoryPath})]}),(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Path"}),(0,r.jsx)("p",{className:"text-sm text-gray-700 break-all font-mono",children:t.path})]}),t.status&&(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Status"}),(0,r.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ".concat("done"===t.status?"bg-green-100 text-green-800":"doing"===t.status?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"),children:t.status.toUpperCase()})]}),(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500",children:"Description"}),!i&&(0,r.jsx)("button",{type:"button",onClick:()=>o(!0),className:"text-sm text-blue-600 hover:text-blue-800",children:"Edit"})]}),i?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("textarea",{value:c,onChange:e=>d(e.target.value),placeholder:"Add notes about this branch...",className:"w-full min-h-[150px] p-3 border border-gray-300 rounded-lg resize-y focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",autoFocus:!0}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:h,disabled:u,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 text-sm font-medium",children:u?"Saving...":"Save"}),(0,r.jsx)("button",{type:"button",onClick:p,disabled:u,className:"px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 disabled:opacity-50 text-sm font-medium",children:"Cancel"})]})]}):(0,r.jsx)("div",{className:"min-h-[50px]",children:t.description?(0,r.jsx)("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:t.description}):(0,r.jsx)("p",{className:"text-sm text-gray-400 italic",children:"No description added yet"})})]}),t.link&&(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Link"}),(0,r.jsx)("a",{href:t.link,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline break-all",children:t.link})]}),t.updatedAt&&(0,r.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Last Updated"}),(0,r.jsx)("p",{className:"text-sm text-gray-700",children:new Date(t.updatedAt).toLocaleString()})]})]})}):null}),tL=(0,l.memo)(function(){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)("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,r.jsx)("p",{className:"text-gray-600",children:"Loading worktree..."})]})})}),tR=(0,l.memo)(function(e){let{message:t,onRetry:a}=e;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-red-50 rounded-lg border border-red-200 max-w-md",children:[(0,r.jsx)("svg",{className:"mx-auto h-12 w-12 text-red-400 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-red-600 font-medium",children:"Error loading worktree"}),(0,r.jsx)("p",{className:"text-red-500 text-sm mt-2",children:t}),a&&(0,r.jsx)("button",{type:"button",onClick:a,className:"mt-4 px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2",children:"Retry"})]})})}),tA=(0,l.memo)(function(e){let{worktree:t,onWorktreeUpdate:a}=e,[n,s]=(0,l.useState)(!1),[i,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(!1),u=(0,l.useRef)(null==t?void 0:t.id);(0,l.useEffect)(()=>{let e=(null==t?void 0:t.id)!==u.current;u.current=null==t?void 0:t.id,e&&t&&!n&&o(t.description||"")},[t,n]);let m=(0,l.useCallback)(async()=>{if(t){d(!0);try{let e=await ty.Iv.updateDescription(t.id,i);a(e),s(!1)}catch(e){console.error("Failed to save description:",e)}finally{d(!1)}}},[t,i,a]),x=(0,l.useCallback)(()=>{o((null==t?void 0:t.description)||""),s(!1)},[t]);return t?(0,r.jsxs)("div",{className:"p-4 space-y-4 overflow-y-auto h-full",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Worktree"}),(0,r.jsx)("p",{className:"text-lg font-semibold text-gray-900",children:t.name})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Repository"}),(0,r.jsx)("p",{className:"text-base text-gray-900",children:t.repositoryName}),(0,r.jsx)("p",{className:"text-xs text-gray-500 mt-1 break-all",children:t.repositoryPath})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Path"}),(0,r.jsx)("p",{className:"text-sm text-gray-700 break-all font-mono",children:t.path})]}),t.status&&(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Status"}),(0,r.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ".concat("done"===t.status?"bg-green-100 text-green-800":"doing"===t.status?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"),children:t.status.toUpperCase()})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500",children:"Description"}),!n&&(0,r.jsx)("button",{type:"button",onClick:()=>s(!0),className:"text-sm text-blue-600 hover:text-blue-800",children:"Edit"})]}),n?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("textarea",{value:i,onChange:e=>o(e.target.value),placeholder:"Add notes about this branch...",className:"w-full min-h-[150px] p-3 border border-gray-300 rounded-lg resize-y focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",autoFocus:!0}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)("button",{type:"button",onClick:m,disabled:c,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 text-sm font-medium",children:c?"Saving...":"Save"}),(0,r.jsx)("button",{type:"button",onClick:x,disabled:c,className:"px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 disabled:opacity-50 text-sm font-medium",children:"Cancel"})]})]}):(0,r.jsx)("div",{className:"min-h-[50px]",children:t.description?(0,r.jsx)("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:t.description}):(0,r.jsx)("p",{className:"text-sm text-gray-400 italic",children:"No description added yet"})})]}),t.link&&(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Link"}),(0,r.jsx)("a",{href:t.link,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline break-all",children:t.link})]}),t.updatedAt&&(0,r.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Last Updated"}),(0,r.jsx)("p",{className:"text-sm text-gray-700",children:new Date(t.updatedAt).toLocaleString()})]})]}):(0,r.jsx)("div",{className:"text-gray-500 text-center py-8",children:"Loading worktree info..."})}),tF=(0,l.memo)(function(e){let{activeTab:t,worktreeId:a,worktree:n,messages:s,terminalOutput:l,isTerminalActive:i,isThinking:o,onFilePathClick:c,onFileSelect:d,onWorktreeUpdate:u,onNewFile:m,onNewDirectory:x,onRename:h,onDelete:f,onUpload:g,refreshTrigger:b,fileSearch:y}=e;switch(t){case"terminal":return(0,r.jsx)(p,{componentName:"TerminalDisplay",children:(0,r.jsx)(F,{output:l,isActive:i,isThinking:o,className:"h-full"})});case"history":return(0,r.jsx)(p,{componentName:"HistoryPane",children:(0,r.jsx)(Y,{messages:s,worktreeId:a,onFilePathClick:c,className:"h-full"})});case"files":var v;return(0,r.jsx)(p,{componentName:"FileTreeView",children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(eF,{query:y.query,mode:y.mode,isSearching:y.isSearching,error:y.error,onQueryChange:y.setQuery,onModeChange:y.setMode,onClear:y.clearSearch}),(0,r.jsx)(eT,{worktreeId:a,onFileSelect:d,onNewFile:m,onNewDirectory:x,onRename:h,onDelete:f,onUpload:g,refreshTrigger:b,searchQuery:y.query,searchMode:y.mode,searchResults:null===(v=y.results)||void 0===v?void 0:v.results,className:"flex-1 min-h-0"})]})});case"memo":return(0,r.jsx)(p,{componentName:"MemoPane",children:(0,r.jsx)(tN,{worktreeId:a,className:"h-full"})});case"info":return(0,r.jsx)(tA,{worktree:n,onWorktreeUpdate:u});default:return null}}),tP=(0,l.memo)(function(e){var t,a,s;let{worktreeId:i}=e,o=(0,n.useRouter)(),c=(0,x.d)(),{toggle:d,openMobileDrawer:f}=(0,h.Sz)(),{state:g,actions:b}=function(){let[e,t]=(0,l.useReducer)(m,void 0,u),a=(0,l.useMemo)(()=>({setPhase:e=>t({type:"SET_PHASE",phase:e}),setTerminalOutput:(e,a)=>t({type:"SET_TERMINAL_OUTPUT",output:e,realtimeSnippet:a}),setTerminalActive:e=>t({type:"SET_TERMINAL_ACTIVE",isActive:e}),setTerminalThinking:e=>t({type:"SET_TERMINAL_THINKING",isThinking:e}),showPrompt:(e,a)=>t({type:"SHOW_PROMPT",data:e,messageId:a}),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,a)=>t({type:"UPDATE_MESSAGE",id:e,updates:a}),clearMessages:()=>t({type:"CLEAR_MESSAGES"}),startWaitingForResponse:e=>t({type:"START_WAITING_FOR_RESPONSE",cliToolId:e}),responseReceived:e=>t({type:"RESPONSE_RECEIVED",message:e}),sessionEnded:()=>t({type:"SESSION_ENDED"}),setAutoScroll:e=>t({type:"SET_AUTO_SCROLL",enabled:e}),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})}),[]);return{state:e,dispatch:t,actions:a}}(),[y,v]=(0,l.useState)(null),[w,j]=(0,l.useState)(!0),[N,k]=(0,l.useState)(null),[C,S]=(0,l.useState)(!1),[M,T]=(0,l.useState)(null),[L,R]=(0,l.useState)(null),[A,P]=(0,l.useState)(!1),[D,I]=(0,l.useState)(!1),[_,z]=(0,l.useState)(null),[O,W]=(0,l.useState)(0),B=function(e){let{worktreeId:t,initialMode:a="name",debounceMs:r=300}=e,[n,s]=(0,l.useState)(""),[i,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(a),[u,m]=(0,l.useState)(!1),[x,h]=(0,l.useState)(null),[p,f]=(0,l.useState)(null),g=(0,l.useRef)(null),b=(0,l.useMemo)(()=>ea(e=>{o(e)},r),[r]),y=(0,l.useCallback)(e=>{s(e),b(e),f(null)},[b]),v=(0,l.useCallback)(()=>{s(""),o(""),h(null),f(null),m(!1),g.current&&(g.current.abort(),g.current=null)},[]),w=(0,l.useCallback)(e=>{if(!i.trim())return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t))},[i]),j=(0,l.useCallback)(()=>x&&0!==x.results.length?er(x.results.map(e=>e.filePath)):new Set,[x]);return(0,l.useEffect)(()=>{if("content"!==c||!i.trim()){h(null);return}g.current&&g.current.abort();let e=new AbortController;return g.current=e,(async()=>{m(!0),f(null);try{var a,r;let n=await fetch("/api/worktrees/".concat(encodeURIComponent(t),"/search?q=").concat(encodeURIComponent(i),"&mode=content"),{signal:e.signal});if(!n.ok){let e=await n.json();throw Error((null===(a=e.error)||void 0===a?void 0:a.message)||"Search failed: ".concat(n.status))}let s=await n.json();if(s.success)h({mode:"content",query:i,results:s.results,totalMatches:s.totalMatches,truncated:s.truncated,executionTimeMs:s.executionTimeMs});else throw Error((null===(r=s.error)||void 0===r?void 0:r.message)||"Search failed")}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;f(e instanceof Error?e.message:"An error occurred while searching"),h(null)}finally{m(!1)}})(),()=>{e.abort()}},[c,i,t]),(0,l.useEffect)(()=>{"name"===c&&(h(null),m(!1),f(null))},[c]),{query:n,mode:c,isSearching:u,results:x,error:p,setQuery:y,setMode:d,clearSearch:v,filterByName:w,getMatchedPaths:j}}({worktreeId:i}),U=(0,l.useRef)(!1),V=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/worktrees/".concat(i));if(!e.ok)throw Error("Failed to fetch worktree: ".concat(e.status));let t=await e.json();return v(t),t}catch(e){return k(e instanceof Error?e.message:"Unknown error"),null}},[i]),H=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/worktrees/".concat(i,"/messages?cliTool=claude"));if(!e.ok)throw Error("Failed to fetch messages: ".concat(e.status));let t=await e.json();b.setMessages(t.map(e=>({...e,timestamp:new Date(e.timestamp)})))}catch(e){console.error("[WorktreeDetailRefactored] Error fetching messages:",e)}},[i,b]),Z=(0,l.useCallback)(async()=>{try{var e,t,a,r,n;let s=await fetch("/api/worktrees/".concat(i,"/current-output?cliTool=claude"));if(!s.ok)return;let l=await s.json(),o=null!==(t=null!==(e=l.fullOutput)&&void 0!==e?e:l.realtimeSnippet)&&void 0!==t?t:"";(o||l.isRunning)&&b.setTerminalOutput(o,null!==(a=l.realtimeSnippet)&&void 0!==a?a:""),b.setTerminalActive(null!==(r=l.isRunning)&&void 0!==r&&r),b.setTerminalThinking(null!==(n=l.thinking)&&void 0!==n&&n),l.isPromptWaiting&&l.promptData?b.showPrompt(l.promptData,"prompt-".concat(Date.now())):!l.isPromptWaiting&&g.prompt.visible&&b.clearPrompt(),l.autoYes&&(I(l.autoYes.enabled),z(l.autoYes.expiresAt))}catch(e){console.error("[WorktreeDetailRefactored] Error fetching current output:",e)}},[i,b,g.prompt.visible]),q=(0,l.useCallback)(e=>{T(e)},[]),G=(0,l.useCallback)(e=>{var t;let a=null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase();tf.includes(a?".".concat(a):"")?R(e):T(e)},[]),K=(0,l.useCallback)(()=>{T(null)},[]),J=(0,l.useCallback)(()=>{R(null)},[]),X=(0,l.useCallback)(e=>{console.log("[WorktreeDetailRefactored] File saved:",e)},[]),Q=(0,l.useCallback)(e=>{b.setLeftPaneTab(e)},[b]),$=(0,l.useCallback)(()=>{o.push("/")},[o]),et=(0,l.useCallback)(()=>{S(!0)},[]),en=(0,l.useCallback)(()=>{S(!1)},[]),es=(0,l.useCallback)(async e=>{b.setPromptAnswering(!0);try{let t=await fetch("/api/worktrees/".concat(i,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({answer:e,cliTool:"claude"})});if(!t.ok)throw Error("Failed to send prompt response: ".concat(t.status));b.clearPrompt(),await Z()}catch(e){console.error("[WorktreeDetailRefactored] Error sending prompt response:",e)}finally{b.setPromptAnswering(!1)}},[i,b,Z]),el=(0,l.useCallback)(()=>{b.clearPrompt()},[b]),eo=(0,l.useCallback)(e=>{b.setMobileActivePane(e)},[b]),ec=(0,l.useCallback)(e=>{b.setAutoScroll(e)},[b]),eu=(0,l.useCallback)(()=>{H(),Z()},[H,Z]),ex=(0,l.useCallback)(async e=>{try{let t=await fetch("/api/worktrees/".concat(i,"/auto-yes"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})});if(t.ok){let e=await t.json();I(e.enabled),z(e.expiresAt)}}catch(e){console.error("[WorktreeDetailRefactored] Error toggling auto-yes:",e)}},[i]),eh=(0,l.useCallback)(async e=>{let t=window.prompt("Enter file name (e.g., document.md):");if(!t)return;let a=t.endsWith(".md")?t:"".concat(t,".md"),r=e?"".concat(e,"/").concat(a):a;try{if(!(await fetch("/api/worktrees/".concat(i,"/files/").concat(encodeURIComponent(r)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"file",content:""})})).ok)throw Error("Failed to create file");W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to create file:",e),window.alert("ファイルの作成に失敗しました")}},[i]),ep=(0,l.useCallback)(async e=>{let t=window.prompt("Enter directory name:");if(!t)return;let a=e?"".concat(e,"/").concat(t):t;try{if(!(await fetch("/api/worktrees/".concat(i,"/files/").concat(encodeURIComponent(a)),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"directory"})})).ok)throw Error("Failed to create directory");W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to create directory:",e),window.alert("ディレクトリの作成に失敗しました")}},[i]),eg=(0,l.useCallback)(async e=>{let t=e.split("/").pop()||"",a=window.prompt("Enter new name:",t);if(a&&a!==t)try{if(!(await fetch("/api/worktrees/".concat(i,"/files/").concat(encodeURIComponent(e)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"rename",newName:a})})).ok)throw Error("Failed to rename");W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to rename:",e),window.alert("リネームに失敗しました")}},[i]),eb=(0,l.useCallback)(async e=>{let t=e.split("/").pop()||e;if(window.confirm('"'.concat(t,'" を削除しますか?')))try{if(!(await fetch("/api/worktrees/".concat(i,"/files/").concat(encodeURIComponent(e),"?recursive=true"),{method:"DELETE"})).ok)throw Error("Failed to delete");(L===e||(null==L?void 0:L.startsWith("".concat(e,"/"))))&&R(null),W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to delete:",e),window.alert("削除に失敗しました")}},[i,L]),{toasts:ey,showToast:ev,removeToast:ew}=e8(),ej=(0,l.useRef)(null),eN=(0,l.useRef)(""),ek=(0,l.useCallback)(e=>{var t;eN.current=e,null===(t=ej.current)||void 0===t||t.click()},[]),eC=(0,l.useCallback)(async e=>{var t,a,r;let n=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!n)return;e.target.value="";let s=eN.current,l=".".concat(null===(a=n.name.split(".").pop())||void 0===a?void 0:a.toLowerCase());if(!function(e){if(!e)return!1;let t=e.toLowerCase();return tb.includes(t)}(l)){ev("Unsupported file type: ".concat(l,". Allowed: ").concat(tb.join(", ")),"error");return}let o=function(e){var t;let a=function(e){let t=e.toLowerCase();return tg.find(e=>e.extension===t)}(e);return null!==(t=null==a?void 0:a.maxFileSize)&&void 0!==t?t:5242880}(l);if(n.size>o){ev("File too large. Maximum size: ".concat((o/1024/1024).toFixed(1),"MB"),"error");return}let c=new FormData;c.append("file",n);try{let e=await fetch("/api/worktrees/".concat(i,"/upload/").concat(encodeURIComponent(s||".")),{method:"POST",body:c});if(!e.ok){let t=await e.json().catch(()=>({})),a=(null==t?void 0:null===(r=t.error)||void 0===r?void 0:r.message)||"Failed to upload file";ev(a,"error");return}let t=await e.json();ev("Uploaded: ".concat(t.filename),"success"),W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to upload:",e),ev("Upload failed. Please try again.","error")}},[i,ev]),{lastAutoResponse:eS}=function(e){let{worktreeId:t,cliTool:a,isPromptWaiting:r,promptData:n,autoYesEnabled:s}=e,i=(0,l.useRef)(null),[o,c]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(!r){i.current=null;return}if(!n||!s)return;let e="".concat(n.type,":").concat(n.question);if(i.current===e)return;let l=function(e){if("yes_no"===e.type)return"y";if("multiple_choice"===e.type){let t=e.options.find(e=>e.isDefault),a=null!=t?t:e.options[0];return!a||a.requiresTextInput?null:a.number.toString()}return null}(n);null!==l&&(i.current=e,c(l),fetch("/api/worktrees/".concat(t,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({answer:l,cliTool:a})}).catch(e=>{console.error("[useAutoYes] Failed to send auto-response:",e)}))},[r,n,s,t,a]),{lastAutoResponse:o}}({worktreeId:i,cliTool:"claude",isPromptWaiting:g.prompt.visible,promptData:g.prompt.data,autoYesEnabled:D}),eE=(0,l.useCallback)(async()=>{k(null),j(!0),await V()&&await Promise.all([H(),Z()]),j(!1)},[V,H,Z]);(0,l.useEffect)(()=>{if(U.current)return;let e=!0;return(async()=>{j(!0);let t=await V();e&&(t&&await Promise.all([H(),Z()]),e&&(j(!1),U.current=!0))})(),()=>{e=!1}},[V,H,Z]),(0,l.useEffect)(()=>{if(w||N)return;let e=setInterval(async()=>{await Promise.all([Z(),V(),H()])},g.terminal.isActive?2e3:5e3);return()=>clearInterval(e)},[w,N,Z,V,H,g.terminal.isActive]),(0,l.useEffect)(()=>{b.setLayoutMode(c?"tabs":"split")},[c,b]);let eM=(0,l.useMemo)(()=>(function(e,t){var a;if(t)return"error";if(!e)return"idle";let r=null===(a=e.sessionStatusByCli)||void 0===a?void 0:a.claude;if(r){if(r.isWaitingForResponse)return"waiting";if(r.isProcessing)return"running";if(r.isRunning)return"ready"}return e.isWaitingForResponse?"waiting":e.isProcessing?"running":e.isSessionRunning?"ready":"idle"})(y,null!==g.error.type),[y,g.error.type]),eL=(0,l.useMemo)(()=>g.layout.mobileActivePane,[g.layout.mobileActivePane]),eR=(0,l.useMemo)(()=>g.layout.leftPaneTab,[g.layout.leftPaneTab]),eA=null!==(t=null==y?void 0:y.name)&&void 0!==t?t:"Unknown";return w?(0,r.jsx)(tL,{}):N?(0,r.jsx)(tR,{message:N,onRetry:eE}):c?(0,r.jsx)(p,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(ei,{worktreeName:eA,repositoryName:null==y?void 0:y.repositoryName,status:eM,gitStatus:null==y?void 0:y.gitStatus,onBackClick:$,onMenuClick:f}),(null==y?void 0:y.gitStatus)&&y.gitStatus.isBranchMismatch&&(0,r.jsx)("div",{className:"fixed top-14 inset-x-0 z-35",children:(0,r.jsx)(tE,{isBranchMismatch:y.gitStatus.isBranchMismatch,currentBranch:y.gitStatus.currentBranch,initialBranch:y.gitStatus.initialBranch})}),(0,r.jsx)("div",{className:"fixed top-14 inset-x-0 z-30",children:(0,r.jsx)(tS,{enabled:D,expiresAt:_,onToggle:ex,lastAutoResponse:eS})}),(0,r.jsx)("main",{className:"flex-1 pt-[6.25rem] pb-32 overflow-hidden",style:{paddingBottom:"calc(8rem + env(safe-area-inset-bottom, 0px))"},children:(0,r.jsx)(tF,{activeTab:eL,worktreeId:i,worktree:y,messages:g.messages,terminalOutput:g.terminal.output,isTerminalActive:g.terminal.isActive,isThinking:g.terminal.isThinking,onFilePathClick:q,onFileSelect:G,onWorktreeUpdate:v,onNewFile:eh,onNewDirectory:ep,onRename:eg,onDelete:eb,onUpload:ek,refreshTrigger:O,fileSearch:B})}),(0,r.jsx)("div",{className:"fixed left-0 right-0 border-t border-gray-200 bg-white p-2 z-30",style:{bottom:"calc(4rem + env(safe-area-inset-bottom, 0px))"},children:(0,r.jsx)(ef.R,{worktreeId:i,onMessageSent:eu,cliToolId:"claude",isSessionRunning:g.terminal.isActive})}),(0,r.jsx)(ed,{activeTab:eL,onTabChange:eo,hasNewOutput:!1,hasPrompt:g.prompt.visible}),!D&&(0,r.jsx)(em,{promptData:g.prompt.data,visible:g.prompt.visible,answering:g.prompt.answering,onRespond:es,onDismiss:el}),(0,r.jsx)(eB,{isOpen:null!==M,onClose:K,worktreeId:i,filePath:null!=M?M:""}),L&&(0,r.jsx)(tk.u,{isOpen:!0,onClose:J,title:L.split("/").pop()||"Editor",size:"full",disableClose:A,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(tp,{worktreeId:i,filePath:L,onClose:J,onSave:X,onMaximizedChange:P})})}),(0,r.jsx)("input",{ref:ej,type:"file",accept:tb.join(","),onChange:eC,className:"hidden","aria-label":"Upload file"}),(0,r.jsx)(e6,{toasts:ey,onClose:ew})]})}):(0,r.jsx)(p,{componentName:"WorktreeDetailRefactored",children:(0,r.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,r.jsx)(tM,{worktreeName:eA,repositoryName:null!==(s=null==y?void 0:y.repositoryName)&&void 0!==s?s:"Unknown",description:null==y?void 0:y.description,status:eM,gitStatus:null==y?void 0:y.gitStatus,onBackClick:$,onInfoClick:et,onMenuClick:d}),(null==y?void 0:y.gitStatus)&&(0,r.jsx)(tE,{isBranchMismatch:y.gitStatus.isBranchMismatch,currentBranch:y.gitStatus.currentBranch,initialBranch:y.gitStatus.initialBranch}),(0,r.jsx)("div",{className:"flex-1 min-h-0",children:(0,r.jsx)(E,{leftPane:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(ez,{activeTab:eR,onTabChange:Q}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["history"===eR&&(0,r.jsx)(Y,{messages:g.messages,worktreeId:i,onFilePathClick:q,className:"h-full"}),"files"===eR&&(0,r.jsx)(p,{componentName:"FileTreeView",children:(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsx)(eF,{query:B.query,mode:B.mode,isSearching:B.isSearching,error:B.error,onQueryChange:B.setQuery,onModeChange:B.setMode,onClear:B.clearSearch}),(0,r.jsx)(eT,{worktreeId:i,onFileSelect:G,onNewFile:eh,onNewDirectory:ep,onRename:eg,onDelete:eb,onUpload:ek,refreshTrigger:O,searchQuery:B.query,searchMode:B.mode,searchResults:null===(a=B.results)||void 0===a?void 0:a.results,className:"flex-1 min-h-0"})]})}),"memo"===eR&&(0,r.jsx)(p,{componentName:"MemoPane",children:(0,r.jsx)(tN,{worktreeId:i,className:"h-full"})})]})]}),rightPane:(0,r.jsx)(F,{output:g.terminal.output,isActive:g.terminal.isActive,isThinking:g.terminal.isThinking,autoScroll:g.terminal.autoScroll,onScrollChange:ec}),initialLeftWidth:40,minLeftWidth:20,maxLeftWidth:60})}),(0,r.jsx)("div",{className:"flex-shrink-0 border-t border-gray-200 p-4 bg-gray-50",children:(0,r.jsx)(ef.R,{worktreeId:i,onMessageSent:eu,cliToolId:"claude",isSessionRunning:g.terminal.isActive})}),(0,r.jsx)(tS,{enabled:D,expiresAt:_,onToggle:ex,lastAutoResponse:eS}),g.prompt.visible&&!D&&(0,r.jsx)("div",{className:"fixed bottom-20 left-1/2 transform -translate-x-1/2 z-50 w-full max-w-2xl px-4",children:(0,r.jsx)(ee,{promptData:g.prompt.data,messageId:g.prompt.messageId,visible:g.prompt.visible,answering:g.prompt.answering,onRespond:es,onDismiss:el})}),(0,r.jsx)(tT,{worktree:y,isOpen:C,onClose:en,onWorktreeUpdate:v}),(0,r.jsx)(eB,{isOpen:null!==M,onClose:K,worktreeId:i,filePath:null!=M?M:""}),L&&(0,r.jsx)(tk.u,{isOpen:!0,onClose:J,title:L.split("/").pop()||"Editor",size:"full",disableClose:A,children:(0,r.jsx)("div",{className:"h-[80vh]",children:(0,r.jsx)(tp,{worktreeId:i,filePath:L,onClose:J,onSave:X,onMaximizedChange:P})})}),(0,r.jsx)("input",{ref:ej,type:"file",accept:tb.join(","),onChange:eC,className:"hidden","aria-label":"Upload file"}),(0,r.jsx)(e6,{toasts:ey,onClose:ew})]})})});function tD(){let e=(0,n.useParams)().id;return(0,r.jsx)(s.Vw,{children:(0,r.jsx)(tP,{worktreeId:e})})}}},function(e){e.O(0,[7851,7648,4851,9365,2957,816,2853,2971,2117,1744],function(){return e(e.s=5635)}),_N_E=e.O()}]);