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
- {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAA6B,MAAM,UAAU,CAAC;AASnE;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAyHvE"}
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/start.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,YAAY,EAA6B,MAAM,UAAU,CAAC;AASnE;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAoJvE"}
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.startCommand = startCommand;
10
10
  const fs_1 = require("fs");
11
11
  const child_process_1 = require("child_process");
12
+ const dotenv_1 = require("dotenv");
12
13
  const types_1 = require("../types");
13
14
  const logger_1 = require("../utils/logger");
14
15
  const daemon_1 = require("../utils/daemon");
@@ -76,10 +77,31 @@ async function startCommand(options) {
76
77
  // Foreground mode (default)
77
78
  const npmScript = options.dev ? 'dev' : 'start';
78
79
  logger.info(`Starting server in foreground (${options.dev ? 'development' : 'production'} mode)...`);
79
- const env = { ...process.env };
80
+ // Issue #125: Load .env file from correct location (same as daemon mode)
81
+ const envResult = (0, dotenv_1.config)({ path: envPath });
82
+ if (envResult.error) {
83
+ logger.warn(`Failed to load .env file at ${envPath}: ${envResult.error.message}`);
84
+ logger.info('Continuing with existing environment variables');
85
+ }
86
+ // Build environment by merging process.env with .env values
87
+ const env = {
88
+ ...process.env,
89
+ ...(envResult.parsed || {}),
90
+ };
91
+ // Command line options override .env values
80
92
  if (options.port) {
81
93
  env.CM_PORT = String(options.port);
82
94
  }
95
+ // Issue #125: Security warnings for external access
96
+ const bindAddress = env.CM_BIND || '127.0.0.1';
97
+ const authToken = env.CM_AUTH_TOKEN;
98
+ if (bindAddress === '0.0.0.0') {
99
+ logger.warn('WARNING: Server is accessible from external networks (CM_BIND=0.0.0.0)');
100
+ if (!authToken) {
101
+ logger.warn('SECURITY WARNING: No authentication token configured. External access is not recommended without CM_AUTH_TOKEN.');
102
+ logger.info('Run "commandmate init" to configure a secure authentication token.');
103
+ }
104
+ }
83
105
  // Use package installation directory, not current working directory
84
106
  const packageRoot = (0, paths_1.getPackageRoot)();
85
107
  const child = (0, child_process_1.spawn)('npm', ['run', npmScript], {
@@ -19,7 +19,7 @@ const db_1 = require("./db");
19
19
  * Current schema version
20
20
  * Increment this when adding new migrations
21
21
  */
22
- exports.CURRENT_SCHEMA_VERSION = 14;
22
+ exports.CURRENT_SCHEMA_VERSION = 15;
23
23
  /**
24
24
  * Migration registry
25
25
  * All migrations should be added to this array in order
@@ -575,6 +575,81 @@ const migrations = [
575
575
  db.exec('DROP TABLE IF EXISTS repositories');
576
576
  console.log('✓ Dropped repositories and clone_jobs tables');
577
577
  }
578
+ },
579
+ {
580
+ version: 15,
581
+ name: 'add-initial-branch-column',
582
+ up: (db) => {
583
+ // Issue #111: Add initial_branch column to worktrees table
584
+ // Stores the branch name at session start for mismatch detection
585
+ db.exec(`
586
+ ALTER TABLE worktrees ADD COLUMN initial_branch TEXT;
587
+ `);
588
+ console.log('✓ Added initial_branch column to worktrees table');
589
+ },
590
+ down: (db) => {
591
+ // SQLite doesn't support DROP COLUMN directly
592
+ // Recreate table without initial_branch column
593
+ db.exec(`
594
+ -- 1. Create backup table without initial_branch
595
+ CREATE TABLE worktrees_backup AS
596
+ SELECT id, name, path, repository_path, repository_name, description,
597
+ last_user_message, last_user_message_at, last_message_summary,
598
+ favorite, status, link, cli_tool_id, updated_at, last_viewed_at
599
+ FROM worktrees;
600
+
601
+ -- 2. Drop original table
602
+ DROP TABLE worktrees;
603
+
604
+ -- 3. Recreate table without initial_branch
605
+ CREATE TABLE worktrees (
606
+ id TEXT PRIMARY KEY,
607
+ name TEXT NOT NULL,
608
+ path TEXT NOT NULL UNIQUE,
609
+ repository_path TEXT,
610
+ repository_name TEXT,
611
+ description TEXT,
612
+ last_user_message TEXT,
613
+ last_user_message_at INTEGER,
614
+ last_message_summary TEXT,
615
+ favorite INTEGER DEFAULT 0,
616
+ status TEXT DEFAULT NULL,
617
+ link TEXT DEFAULT NULL,
618
+ cli_tool_id TEXT DEFAULT 'claude',
619
+ updated_at INTEGER,
620
+ last_viewed_at TEXT
621
+ );
622
+
623
+ -- 4. Restore data
624
+ INSERT INTO worktrees (id, name, path, repository_path, repository_name,
625
+ description, last_user_message, last_user_message_at, last_message_summary,
626
+ favorite, status, link, cli_tool_id, updated_at, last_viewed_at)
627
+ SELECT id, name, path, repository_path, repository_name,
628
+ description, last_user_message, last_user_message_at, last_message_summary,
629
+ favorite, status, link, cli_tool_id, updated_at, last_viewed_at
630
+ FROM worktrees_backup;
631
+
632
+ -- 5. Drop backup
633
+ DROP TABLE worktrees_backup;
634
+
635
+ -- 6. Recreate indexes
636
+ CREATE INDEX IF NOT EXISTS idx_worktrees_updated_at
637
+ ON worktrees(updated_at DESC);
638
+
639
+ CREATE INDEX IF NOT EXISTS idx_worktrees_repository
640
+ ON worktrees(repository_path);
641
+
642
+ CREATE INDEX IF NOT EXISTS idx_worktrees_favorite
643
+ ON worktrees(favorite DESC, updated_at DESC);
644
+
645
+ CREATE INDEX IF NOT EXISTS idx_worktrees_status
646
+ ON worktrees(status);
647
+
648
+ CREATE INDEX IF NOT EXISTS idx_worktrees_cli_tool
649
+ ON worktrees(cli_tool_id);
650
+ `);
651
+ console.log('✓ Removed initial_branch column from worktrees table');
652
+ }
578
653
  }
579
654
  ];
580
655
  /**
@@ -37,6 +37,8 @@ exports.createMemo = createMemo;
37
37
  exports.updateMemo = updateMemo;
38
38
  exports.deleteMemo = deleteMemo;
39
39
  exports.reorderMemos = reorderMemos;
40
+ exports.saveInitialBranch = saveInitialBranch;
41
+ exports.getInitialBranch = getInitialBranch;
40
42
  exports.getWorktreeIdsByRepository = getWorktreeIdsByRepository;
41
43
  exports.deleteRepositoryWorktrees = deleteRepositoryWorktrees;
42
44
  const crypto_1 = require("crypto");
@@ -801,6 +803,46 @@ function reorderMemos(db, worktreeId, memoIds) {
801
803
  })();
802
804
  }
803
805
  // ============================================================
806
+ // Initial Branch Operations (Issue #111)
807
+ // ============================================================
808
+ /**
809
+ * Save initial branch for a worktree (at session start)
810
+ * Issue #111: Branch visualization feature
811
+ *
812
+ * @param db - Database instance
813
+ * @param worktreeId - ID of the worktree
814
+ * @param branchName - Branch name to save
815
+ *
816
+ * @remarks
817
+ * Uses prepared statement for SQL injection prevention
818
+ * Called from send/route.ts after startSession()
819
+ */
820
+ function saveInitialBranch(db, worktreeId, branchName) {
821
+ const stmt = db.prepare(`
822
+ UPDATE worktrees
823
+ SET initial_branch = ?
824
+ WHERE id = ?
825
+ `);
826
+ stmt.run(branchName, worktreeId);
827
+ }
828
+ /**
829
+ * Get initial branch for a worktree
830
+ * Issue #111: Branch visualization feature
831
+ *
832
+ * @param db - Database instance
833
+ * @param worktreeId - ID of the worktree
834
+ * @returns Branch name or null if not recorded
835
+ */
836
+ function getInitialBranch(db, worktreeId) {
837
+ const stmt = db.prepare(`
838
+ SELECT initial_branch
839
+ FROM worktrees
840
+ WHERE id = ?
841
+ `);
842
+ const row = stmt.get(worktreeId);
843
+ return row?.initial_branch ?? null;
844
+ }
845
+ // ============================================================
804
846
  // Repository Delete Operations (Issue #69)
805
847
  // ============================================================
806
848
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commandmate",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Git worktree management with Claude CLI and tmux sessions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[130],{5635:function(e,t,r){Promise.resolve().then(r.bind(r,53282))},53282:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return tF}});var a=r(57437),n=r(99376),s=r(63671),l=r(2265);let o={output:"",realtimeSnippet:"",isActive:!1,isThinking:!1,autoScroll:!0,lastUpdated:null},i={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:{...o},prompt:{...i},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:{...i}};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:{...i}};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:{...o},prompt:{...i}};default:return e}}var x=r(58819),h=r(43241);class p extends l.Component{static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){var r,a;console.error("[ErrorBoundary:".concat(this.props.componentName||"unknown","]"),e,t),null===(r=(a=this.props).onError)||void 0===r||r.call(a,e,t)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,a.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:r,onRetry:n}=e;return(0,a.jsxs)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-red-800 mb-2",children:[(0,a.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.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,a.jsx)("span",{className:"font-medium",children:t?"".concat(t,"でエラーが発生しました"):"エラーが発生しました"})]}),r&&(0,a.jsx)("p",{className:"text-sm text-red-600 mb-3",children:r.message}),n&&(0,a.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:r="horizontal",ariaValueNow:n=50,onDoubleClick:s,minRatio:o=.1}=e,[i,c]=(0,l.useState)(!1),d=(0,l.useRef)(0),u=(0,l.useRef)(null),m="horizontal"===r,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(!i)return;let r=v(e,m);t(r-d.current),d.current=r},[i,m,t]),f=(0,l.useCallback)(e=>{if(!i||1!==e.touches.length)return;let r=v(e,m);t(r-d.current),d.current=r},[i,m,t]),w=(0,l.useCallback)(()=>{c(!1)},[]),j=(0,l.useCallback)(()=>{s&&s()},[s]),N=(0,l.useCallback)(e=>{let r=0;m?"ArrowRight"===e.key?r=10:"ArrowLeft"===e.key&&(r=-10):"ArrowDown"===e.key?r=10:"ArrowUp"===e.key&&(r=-10),0!==r&&(e.preventDefault(),t(r))},[m,t]);(0,l.useEffect)(()=>(i&&(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=""}),[i,p,w,f,m]);let k=(0,l.useMemo)(()=>[...g,...m?b:y,...i?["bg-blue-500","dragging",m?"w-2":"h-2"]:[]].join(" "),[m,i]);return(0,a.jsx)("div",{ref:u,role:"separator","aria-orientation":r,"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:r,onClick:n}=e;return(0,a.jsx)("button",{type:"button",role:"tab","aria-selected":r,"aria-controls":"".concat(t,"-panel"),onClick:n,className:"".concat("flex-1 py-2 px-4 text-sm font-medium transition-colors"," ").concat(r?"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:r}=e,[n,s]=(0,l.useState)("right"),o=(0,l.useCallback)(()=>s("left"),[]),i=(0,l.useCallback)(()=>s("right"),[]);return(0,a.jsxs)("div",{"data-testid":"mobile-layout",className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"flex border-b border-gray-700 bg-gray-800",role:"tablist",children:[(0,a.jsx)(k,{pane:"left",isActive:"left"===n,onClick:o}),(0,a.jsx)(k,{pane:"right",isActive:"right"===n,onClick:i})]}),(0,a.jsx)("div",{id:"".concat(n,"-panel"),role:"tabpanel",className:"flex-1 overflow-hidden",children:(0,a.jsx)(p,{componentName:N[n],children:"left"===n?t:r})})]})}),S=(0,l.memo)(function(e){let{leftPane:t,rightPane:r,leftWidth:n,onResize:s,className:o}=e,i=(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(o).trim(),[o]);return(0,a.jsxs)("div",{"data-testid":"desktop-layout",role:"main",className:d,children:[(0,a.jsx)("div",{"data-testid":"left-pane","aria-label":"History pane",style:i,className:"flex-shrink-0 overflow-hidden",children:(0,a.jsx)(p,{componentName:N.left,children:t})}),(0,a.jsx)(w,{onResize:s,orientation:"horizontal",ariaValueNow:n}),(0,a.jsx)("div",{"data-testid":"right-pane","aria-label":"Terminal pane",style:c,className:"flex-grow overflow-hidden",children:(0,a.jsx)(p,{componentName:N.right,children:r})})]})}),E=(0,l.memo)(function(e){let{leftPane:t,rightPane:r,initialLeftWidth:n=50,minLeftWidth:s=20,maxLeftWidth:o=80,className:i=""}=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 r=t.offsetWidth;if(0===r)return;let a=e/r*100;m(e=>Math.min(o,Math.max(s,e+a)))},[s,o]);return c?(0,a.jsx)(C,{leftPane:t,rightPane:r}):(0,a.jsx)("div",{ref:d,className:"h-full",children:(0,a.jsx)(S,{leftPane:t,rightPane:r,leftWidth:u,onResize:h,className:i})})});var T=r(47835),M=r.n(T),L=r(34343);let R=new(r.n(L)())({fg:"#d1d5db",bg:"#1f2937",newline:!0,escapeXML:!0});function A(){return(0,a.jsxs)("div",{"data-testid":"thinking-indicator",className:"flex items-center gap-2 py-2 px-1 text-gray-400",children:[(0,a.jsxs)("span",{className:"flex gap-1",children:[(0,a.jsx)("span",{className:"animate-pulse delay-0",children:"."}),(0,a.jsx)("span",{className:"animate-pulse delay-150",children:"."}),(0,a.jsx)("span",{className:"animate-pulse delay-300",children:"."})]}),(0,a.jsx)("span",{className:"text-sm",children:"Thinking"})]})}let F=(0,l.memo)(function(e){let{output:t,isActive:r,isThinking:n=!1,autoScroll:s=!0,onScrollChange:o,className:i=""}=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:r}=e,a=(0,l.useRef)(null),[n,s]=(0,l.useState)(t),o=(0,l.useCallback)(e=>{s(e),null==r||r(e)},[r]),i=(0,l.useCallback)(()=>{let e=a.current;if(!e)return!0;let{scrollTop:t,scrollHeight:r,clientHeight:n}=e;return r-n-t<=50},[]),c=(0,l.useCallback)(()=>{let e=i();e&&!n?o(!0):!e&&n&&o(!1)},[n,i,o]),d=(0,l.useCallback)(()=>{let e=a.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),n||o(!0))},[n,o]);return{scrollRef:a,autoScroll:n,setAutoScroll:o,scrollToBottom:d,handleScroll:c}}({initialAutoScroll:s,onAutoScrollChange:o}),x=function(e){let t=R.toHtml(e);return M().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",r?"active":"",r?"border-blue-500":"",i].filter(Boolean).join(" "),[r,i]);return(0,a.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,a.jsxs)("div",{ref:c,role:"log","aria-live":"polite","aria-label":"Terminal output",className:h,onScroll:u,children:[(0,a.jsx)("div",{className:"whitespace-pre-wrap break-words",dangerouslySetInnerHTML:{__html:x}}),r&&n&&(0,a.jsx)(A,{})]}),!d&&(0,a.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 r=t.slice(0,5).join("\n");return r.length>300&&(r=r.slice(0,300)),{text:r,isTruncated:!0}}let I=(0,l.memo)(function(e){let{content:t,onFilePathClick:r}=e,n=(0,l.useMemo)(()=>(function(e){let t=e.match(P);if(!t||0===t.length)return[{type:"text",content:e}];let r=[],a=0;return t.forEach(t=>{let n=e.indexOf(t,a);n>a&&r.push({type:"text",content:e.slice(a,n)}),r.push({type:"path",content:t}),a=n+t.length}),a<e.length&&r.push({type:"text",content:e.slice(a)}),r})(t),[t]),s=(0,l.useCallback)(e=>()=>r(e),[r]);return(0,a.jsx)("span",{children:n.map((e,t)=>"path"===e.type?(0,a.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,a.jsx)("span",{children:e.content},t))})});function _(){return(0,a.jsxs)("div",{"data-testid":"pending-indicator",className:"flex items-center gap-2 text-gray-400 py-2",children:[(0,a.jsxs)("div",{className:"flex gap-1","aria-hidden":"true",children:[(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse"}),(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"150ms"}}),(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse",style:{animationDelay:"300ms"}})]}),(0,a.jsx)("span",{className:"text-sm",children:"Waiting for response..."})]})}let z=(0,l.memo)(function(e){let{message:t,onFilePathClick:r}=e,n=(0,l.useMemo)(()=>t.timestamp.toLocaleTimeString(),[t.timestamp]);return(0,a.jsxs)("div",{className:"bg-blue-900/30 border-l-4 border-blue-500 p-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-blue-400",children:"You"}),(0,a.jsx)("span",{className:"text-xs text-gray-500",children:n})]}),(0,a.jsx)("div",{className:"text-sm text-gray-200 whitespace-pre-wrap break-words",children:(0,a.jsx)(I,{content:t.content,onFilePathClick:r})})]})}),O=(0,l.memo)(function(e){let{message:t,index:r,total:n,isExpanded:s,onFilePathClick:o}=e,i=(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,a.jsxs)("div",{className:"assistant-message-item",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-gray-400",children:"Assistant"}),(0,a.jsx)("span",{className:"text-xs text-gray-500",children:i}),n>1&&(0,a.jsxs)("span",{className:"text-xs text-gray-500",children:["(",r+1,"/",n,")"]})]}),(0,a.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,a.jsx)(I,{content:u,onFilePathClick:o}),!s&&d&&(0,a.jsx)("span",{className:"text-gray-500",children:"..."})]})]})}),W=(0,l.memo)(function(e){let{messages:t,isExpanded:r,onFilePathClick:n}=e;return(0,a.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,a.jsxs)(l.Fragment,{children:[s>0&&(0,a.jsx)("div",{"data-testid":"assistant-message-divider",className:"border-t border-dashed border-gray-600"}),(0,a.jsx)(O,{message:e,index:s,total:t.length,isExpanded:r,onFilePathClick:n})]},e.id))})});function B(){return(0,a.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,a.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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,a.jsx)("span",{children:"System Message"})]})}let U=(0,l.memo)(function(e){let{pair:t,onFilePathClick:r,isExpanded:n=!1,onToggleExpand:s}=e,o=(0,l.useMemo)(()=>t.assistantMessages.some(e=>{let{isTruncated:t}=D(e.content);return t}),[t.assistantMessages]),i=(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,a.jsxs)("div",{"data-testid":"conversation-pair-card",role:"article","aria-label":d,className:c,children:["orphan"===t.status&&(0,a.jsx)(B,{}),t.userMessage&&(0,a.jsx)(z,{message:t.userMessage,onFilePathClick:r}),"pending"===t.status?(0,a.jsx)("div",{className:"bg-gray-800/30 border-l-4 border-gray-600 p-3 border-t border-gray-700",children:(0,a.jsx)(_,{})}):t.assistantMessages.length>0?(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(W,{messages:t.assistantMessages,isExpanded:n,onFilePathClick:r}),o&&(0,a.jsx)("div",{className:"absolute top-2 right-2",children:(0,a.jsxs)("button",{type:"button",onClick:i,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,a.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,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),n?"Collapse":"Expand"]})})]}):null]})});function V(){return(0,a.jsxs)("div",{"data-testid":"loading-indicator",className:"flex items-center justify-center py-4",role:"status","aria-label":"Loading messages",children:[(0,a.jsxs)("div",{className:"flex gap-1","aria-hidden":"true",children:[(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse"}),(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse delay-100"}),(0,a.jsx)("span",{className:"w-2 h-2 bg-gray-400 rounded-full animate-pulse delay-200"})]}),(0,a.jsx)("span",{className:"ml-2 text-sm text-gray-400",children:"Loading..."})]})}function H(){return(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-gray-500",children:[(0,a.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,a.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,a.jsx)("p",{className:"text-sm",children:"No messages yet"})]})}let Y=["h-full","flex","flex-col","overflow-y-auto","overflow-x-hidden","bg-gray-900","rounded-lg","border","border-gray-700"],Z=(0,l.memo)(function(e){let{messages:t,worktreeId:r,onFilePathClick:n,isLoading:s=!1,className:o=""}=e,i=(0,l.useRef)(null),c=(0,l.useRef)(0),d=(0,l.useRef)(t.length);(0,l.useLayoutEffect)(()=>{let e=i.current;e&&(c.current=e.scrollTop)}),(0,l.useLayoutEffect)(()=>{let e=i.current,r=d.current;e&&t.length===r&&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()),r=[],a=null;for(let e of t)if("user"===e.role)a={id:e.id,userMessage:e,assistantMessages:[],status:"pending"},r.push(a);else if("assistant"===e.role){if(a&&null!==a.userMessage)a.assistantMessages.push(e),a.status="completed";else if(a&&null===a.userMessage)a.assistantMessages.push(e);else{let t={id:"orphan-".concat(e.id),userMessage:null,assistantMessages:[e],status:"orphan"};r.push(t),a=t}}return r})(e),[e]),[r,a]=(0,l.useState)(new Set),n=(0,l.useCallback)(e=>{a(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),s=(0,l.useCallback)(e=>r.has(e),[r]),o=(0,l.useCallback)(()=>{a(new Set(t.map(e=>e.id)))},[t]);return{pairs:t,expandedPairs:r,toggleExpand:n,isExpanded:s,expandAll:o,collapseAll:(0,l.useCallback)(()=>{a(new Set)},[])}}(t),h=(0,l.useMemo)(()=>[...Y,o].filter(Boolean).join(" "),[o]),p=(0,l.useCallback)(e=>n(e),[n]),f=(0,l.useCallback)(e=>()=>x(e),[x]);return(0,a.jsxs)("div",{ref:i,role:"region","aria-label":"Message history",className:h,children:[(0,a.jsx)("div",{className:"sticky top-0 bg-gray-900 border-b border-gray-700 px-4 py-2 z-10",children:(0,a.jsx)("h3",{className:"text-sm font-medium text-gray-300",children:"Message History"})}),(0,a.jsx)("div",{className:"flex-1 p-4 min-h-0",children:s?(0,a.jsx)(V,{}):0===t.length?(0,a.jsx)(H,{}):u.map(e=>(0,a.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:r=200}=e,[a,n]=(0,l.useState)(t?"visible":"hidden"),s=(0,l.useRef)(null),o=(0,l.useRef)(t);(0,l.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),(0,l.useEffect)(()=>{let e=o.current;o.current=t,s.current&&(clearTimeout(s.current),s.current=null);let a=e=>{s.current=setTimeout(()=>{n(e),s.current=null},r)};t&&!e?(n("fade-in"),a("visible")):!t&&e?(n("fade-out"),a("hidden")):t?n(e=>"fade-out"===e?(a("visible"),"fade-in"):e):n(e=>"fade-in"===e?(a("hidden"),"fade-out"):e)},[t,r]);let i="hidden"!==a,c="fade-in"===a||"fade-out"===a;return{shouldRender:i,animationClass:(0,l.useMemo)(()=>{switch(a){case"fade-in":return q.fadeIn;case"fade-out":return q.fadeOut;default:return q.none}},[a]),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:r,onRespond:n,onDismiss:s,labelId:o}=e,[i,c]=(0,l.useState)(()=>{if("multiple_choice"===t.type){var e;let r=t.options.find(e=>e.isDefault);return null!==(e=null==r?void 0:r.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===i))&&void 0!==e?e:null},[t,i]),p=(null==h?void 0:h.requiresTextInput)===!0,f=r||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!==i){x(!0);try{let e=p&&d.trim()?d.trim():i.toString();await n(e)}catch(e){}finally{x(!1)}}},[f,n,i,p,d]);return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("h3",{id:o,className:"text-lg font-semibold text-yellow-800 flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-xl","aria-hidden":"true",children:"?"}),"Claudeからの確認"]}),s&&(0,a.jsx)("button",{type:"button",onClick:s,"aria-label":"close",className:"p-1 rounded hover:bg-yellow-200 transition-colors",children:(0,a.jsx)("svg",{className:"w-5 h-5 text-yellow-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,a.jsx)("p",{className:"text-gray-800 leading-relaxed",children:t.question}),f&&(0,a.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-gray-500",role:"status","aria-live":"polite",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,a.jsx)("span",{children:"送信中..."})]}),"yes_no"===t.type&&(0,a.jsx)(Q,{promptData:t,disabled:f,onYes:()=>g("yes"),onNo:()=>g("no")}),"multiple_choice"===t.type&&(0,a.jsx)($,{promptData:t,disabled:f,selectedOption:i,onSelectOption:c,textInputValue:d,onTextInputChange:u,showTextInput:p,onSubmit:b})]})}function Q(e){let{promptData:t,disabled:r,onYes:n,onNo:s}=e,l="yes"===t.defaultOption,o="no"===t.defaultOption,i="".concat(K," ").concat(J," ").concat(l?"primary default highlighted":""),c="".concat(K," ").concat(o?"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,a.jsxs)("div",{className:"flex items-center gap-3",role:"group","aria-label":"Yes or No options",children:[(0,a.jsx)("button",{type:"button",onClick:n,disabled:r,className:i,children:"Yes"}),(0,a.jsx)("button",{type:"button",onClick:s,disabled:r,className:c,children:"No"})]})}function $(e){let{promptData:t,disabled:r,selectedOption:n,onSelectOption:s,textInputValue:o,onTextInputChange:i,showTextInput:c,onSubmit:d}=e,u=(0,l.useId)(),m=(0,l.useCallback)(e=>{let t=n===e,a=r?"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(a)},[n,r]);return(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("fieldset",{children:[(0,a.jsx)("legend",{className:"sr-only",children:"Select an option"}),(0,a.jsx)("div",{className:"space-y-2",children:t.options.map(e=>(0,a.jsxs)("label",{className:m(e.number),children:[(0,a.jsx)("input",{type:"radio",name:u,value:e.number,checked:n===e.number,onChange:()=>s(e.number),disabled:r,className:"mt-1","aria-describedby":e.isDefault?"default-".concat(e.number):void 0}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsxs)("span",{className:"font-medium",children:[e.number,". ",e.label]}),e.isDefault&&(0,a.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,a.jsxs)("div",{className:"mt-3",children:[(0,a.jsx)("label",{htmlFor:"text-input-".concat(u),className:"sr-only",children:"Custom value input"}),(0,a.jsx)("input",{id:"text-input-".concat(u),type:"text",value:o,onChange:e=>i(e.target.value),disabled:r,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,a.jsx)("button",{type:"button",onClick:d,disabled:r||null===n,className:"w-full ".concat(K," ").concat(J),children:"Submit"})]})}function ee(e){let t,{promptData:r,messageId:n,visible:s,answering:o,onRespond:i,onDismiss:c}=e,{shouldRender:d,animationClass:u}=G({visible:s&&null!==r,duration:200}),m=(0,l.useId)();if(!d||!r)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,a.jsx)(p,{componentName:"PromptPanel",children:(0,a.jsx)("div",{"data-testid":"prompt-panel",role:"dialog","aria-labelledby":m,"aria-modal":"true",className:x,children:(0,a.jsx)(X,{promptData:r,answering:o,onRespond:i,onDismiss:c,labelId:m})})})}var et=r(8672);let er=(0,l.memo)(function(e){let{path:t,className:r="w-6 h-6"}=e;return(0,a.jsx)("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:t})})}),ea={back:"M15 19l-7-7 7-7",menu:"M4 6h16M4 12h16M4 18h16"};function en(e){let{worktreeName:t,repositoryName:r,status:n,onBackClick:s,onMenuClick:o}=e,i=(0,l.useMemo)(()=>et.xh[n],[n]);return(0,a.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,a.jsxs)("div",{className:"flex items-center justify-between h-14 px-4",children:[(0,a.jsx)("div",{className:"w-10 flex-shrink-0",children:s&&(0,a.jsx)("button",{type:"button",onClick:s,"aria-label":"Back",className:"p-2 -ml-2 rounded-full hover:bg-gray-100 transition-colors",children:(0,a.jsx)(er,{path:ea.back})})}),(0,a.jsxs)("div",{className:"flex-1 flex items-center justify-center min-w-0 px-2",children:["spinner"===i.type?(0,a.jsx)("span",{"data-testid":"status-indicator","aria-label":i.label,className:"w-2.5 h-2.5 rounded-full mr-2 flex-shrink-0 border-2 border-t-transparent animate-spin ".concat(i.className)}):(0,a.jsx)("span",{"data-testid":"status-indicator","aria-label":i.label,className:"w-2.5 h-2.5 rounded-full mr-2 flex-shrink-0 ".concat(i.className)}),(0,a.jsxs)("div",{className:"flex flex-col items-center min-w-0",children:[(0,a.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}),r&&(0,a.jsx)("span",{className:"text-xs text-gray-500 truncate text-center",children:r})]})]}),(0,a.jsx)("div",{className:"w-10 flex-shrink-0 flex justify-end",children:o&&(0,a.jsx)("button",{type:"button",onClick:o,"aria-label":"Menu",className:"p-2 -mr-2 rounded-full hover:bg-gray-100 transition-colors",children:(0,a.jsx)(er,{path:ea.menu})})})]})})}let es=(0,l.memo)(function(e){let{path:t,className:r="w-5 h-5"}=e;return(0,a.jsx)("svg",{className:r,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:t})})}),el=[{id:"terminal",label:"Terminal",icon:(0,a.jsx)(es,{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,a.jsx)(es,{path:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})},{id:"files",label:"Files",icon:(0,a.jsx)(es,{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,a.jsx)(es,{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,a.jsx)(es,{path:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}];function eo(e){let{activeTab:t,onTabChange:r,hasNewOutput:n=!1,hasPrompt:s=!1}=e,o=(0,l.useCallback)(e=>{r(e)},[r]),i=(0,l.useCallback)(e=>{let r=e===t;return"".concat("flex flex-col items-center justify-center flex-1 py-2 px-1 transition-colors relative"," ").concat(r?"text-blue-600 bg-blue-50":"text-gray-500 hover:text-gray-700 hover:bg-gray-50")},[t]),c=(0,l.useMemo)(()=>(0,a.jsxs)(a.Fragment,{children:[n&&(0,a.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,a.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,a.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:el.map(e=>(0,a.jsxs)("button",{type:"button",role:"tab","aria-selected":t===e.id,"aria-label":e.label,onClick:()=>o(e.id),className:i(e.id),children:[e.icon,(0,a.jsx)("span",{className:"text-xs mt-1",children:e.label}),"terminal"===e.id&&c]},e.id))})}let ei={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 ec(e){let{promptData:t,visible:r,answering:n,onRespond:s,onDismiss:o}=e,{shouldRender:i,animationClass:c}=G({visible:r&&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)(()=>{r||h(0)},[r]);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&&o&&o(),h(0),m(null)},[x,o]),v=(0,l.useCallback)(()=>{o&&o()},[o]),w=(0,l.useCallback)(e=>{e.stopPropagation()},[]);if(!i||!t)return null;let j="animate-fade-out"===c,N=x>0?"translateY(".concat(x,"px)"):void 0;return(0,a.jsxs)(p,{componentName:"MobilePromptSheet",children:[(0,a.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,a.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,a.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,a.jsx)("div",{"data-testid":"drag-handle",className:"w-10 h-1 bg-gray-300 rounded-full","aria-hidden":"true"})}),(0,a.jsx)("div",{className:"px-4 pb-6",children:(0,a.jsx)(ed,{promptData:t,answering:n,onRespond:s,labelId:d})})]})]})}function ed(e){let{promptData:t,answering:r,onRespond:n,labelId:s}=e,[o,i]=(0,l.useState)(()=>{if("multiple_choice"===t.type){var e;let r=t.options.find(e=>e.isDefault);return null!==(e=null==r?void 0:r.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===o))&&void 0!==e?e:null},[t,o]),h=(null==x?void 0:x.requiresTextInput)===!0,p=r||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!==o){m(!0);try{let e=h&&c.trim()?c.trim():o.toString();await n(e)}catch(e){}finally{m(!1)}}},[p,n,o,h,c]);return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("h3",{id:s,className:"text-lg font-semibold text-gray-900",children:"Claudeからの確認"}),(0,a.jsx)("p",{className:"text-gray-700 leading-relaxed",children:t.question}),p&&(0,a.jsxs)("div",{"data-testid":"answering-indicator",className:"flex items-center gap-2 text-sm text-gray-500",role:"status","aria-live":"polite",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,a.jsx)("span",{children:"送信中..."})]}),"yes_no"===t.type&&(0,a.jsx)(eu,{promptData:t,disabled:p,onYes:()=>f("yes"),onNo:()=>f("no")}),"multiple_choice"===t.type&&(0,a.jsx)(em,{promptData:t,disabled:p,selectedOption:o,onSelectOption:i,textInputValue:c,onTextInputChange:d,showTextInput:h,onSubmit:g})]})}let eu=(0,l.memo)(function(e){let{promptData:t,disabled:r,onYes:n,onNo:s}=e,l="yes"===t.defaultOption,o="no"===t.defaultOption;return(0,a.jsxs)("div",{className:"flex gap-3",role:"group","aria-label":"Yes or No options",children:[(0,a.jsx)("button",{type:"button",onClick:n,disabled:r,className:"flex-1 ".concat(ei.base," ").concat(ei.primary," ").concat(l?"ring-2 ring-blue-300":""),children:"Yes"}),(0,a.jsx)("button",{type:"button",onClick:s,disabled:r,className:"flex-1 ".concat(ei.base," ").concat(o?ei.defaultSelected:ei.secondary),children:"No"})]})}),em=(0,l.memo)(function(e){let{promptData:t,disabled:r,selectedOption:n,onSelectOption:s,textInputValue:o,onTextInputChange:i,showTextInput:c,onSubmit:d}=e,u=(0,l.useId)();return(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("fieldset",{children:[(0,a.jsx)("legend",{className:"sr-only",children:"Select an option"}),(0,a.jsx)("div",{className:"space-y-2",children:t.options.map(e=>{let t=n===e.number;return(0,a.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(r?"opacity-50 cursor-not-allowed":""),children:[(0,a.jsx)("input",{type:"radio",name:u,value:e.number,checked:t,onChange:()=>s(e.number),disabled:r,className:"mt-1"}),(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsxs)("span",{className:"font-medium",children:[e.number,". ",e.label]}),e.isDefault&&(0,a.jsx)("span",{className:"ml-2 text-xs text-blue-600 bg-blue-100 px-2 py-0.5 rounded",children:"デフォルト"})]})]},e.number)})})]}),c&&(0,a.jsxs)("div",{className:"mt-3",children:[(0,a.jsx)("label",{htmlFor:"text-input-".concat(u),className:"sr-only",children:"Custom value input"}),(0,a.jsx)("input",{id:"text-input-".concat(u),type:"text",value:o,onChange:e=>i(e.target.value),disabled:r,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,a.jsx)("button",{type:"button",onClick:d,disabled:r||null===n,className:"w-full ".concat(ei.base," ").concat(ei.primary),children:"Submit"})]})});var ex=r(6940);let eh={isOpen:!1,position:{x:0,y:0},targetPath:null,targetType:null};var ep=r(88964),ef=r(49465),eg=r(17689),eb=r(45675),ey=r(18930);let ev=(0,l.memo)(function(e){let{isOpen:t,position:r,targetPath:n,targetType:s,onClose:o,onNewFile:i,onNewDirectory:c,onRename:d,onDelete:u,onUpload:m}=e,x=(0,l.useRef)(null),h=(0,l.useCallback)(e=>{e&&n&&e(n),o()},[n,o]),p=[{id:"new-file",label:"New File",icon:(0,a.jsx)(ep.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(i),showFor:["directory"]},{id:"new-directory",label:"New Directory",icon:(0,a.jsx)(ef.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(c),showFor:["directory"]},{id:"upload",label:"Upload File",icon:(0,a.jsx)(eg.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(m),showFor:["directory"],showDividerAfter:!0},{id:"rename",label:"Rename",icon:(0,a.jsx)(eb.Z,{className:"w-4 h-4","aria-hidden":"true",role:"img"}),onClick:()=>h(d),showDividerAfter:"file"===s},{id:"delete",label:"Delete",icon:(0,a.jsx)(ey.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){o();return}if("ArrowDown"===e.key||"ArrowUp"===e.key){var t;let r;e.preventDefault();let a=null===(t=x.current)||void 0===t?void 0:t.querySelectorAll('[role="menuitem"]');if(!(null==a?void 0:a.length))return;let n=Array.from(a).findIndex(e=>e===document.activeElement);r="ArrowDown"===e.key?n<a.length-1?n+1:0:n>0?n-1:a.length-1,a[r].focus()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,o]),(0,l.useEffect)(()=>{if(t&&x.current){let e=x.current.querySelector('[role="menuitem"]');e&&e.focus()}},[t]),t)?(0,a.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(r.x,"px"),top:"".concat(r.y,"px")},children:p.map((e,t)=>(0,a.jsxs)(l.Fragment,{children:[(0,a.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,a.jsx)("span",{children:e.label})]}),e.showDividerAfter&&t<p.length-1&&(0,a.jsx)("div",{"data-testid":"context-menu-divider",className:"my-1 border-t border-gray-200"})]},e.id))}):null});function ew(e,t){let r=null;return function(){for(var a=arguments.length,n=Array(a),s=0;s<a;s++)n[s]=arguments[s];r&&clearTimeout(r),r=setTimeout(()=>{e(...n),r=null},t)}}function ej(e){let t=new Set;for(let r of e){t.add(r);let e=r.split("/"),a="";for(let r=0;r<e.length-1;r++)a=a?"".concat(a,"/").concat(e[r]):e[r],t.add(a)}return t}let eN=(0,l.memo)(function(e){let{expanded:t}=e;return(0,a.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,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}),ek=(0,l.memo)(function(e){let{open:t}=e;return(0,a.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,a.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,a.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"})})}),eC=(0,l.memo)(function(e){let{text:t,query:r}=e;if(!r||!r.trim())return(0,a.jsx)(a.Fragment,{children:t});let n=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=t.split(RegExp("(".concat(n,")"),"gi"));return(0,a.jsx)(a.Fragment,{children:s.map((e,t)=>e.toLowerCase()===r.toLowerCase()?(0,a.jsx)("mark",{className:"bg-yellow-200 text-gray-900 px-0.5 rounded",children:e},t):(0,a.jsx)("span",{children:e},t))})}),eS=(0,l.memo)(function(e){let{extension:t}=e,r=(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,a.jsx)("svg",{"data-testid":"file-icon",className:"w-5 h-5 ".concat(r),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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"})})}),eE=(0,l.memo)(function e(t){var r;let{item:n,path:s,depth:o,worktreeId:i,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,a.jsxs)(a.Fragment,{children:[(0,a.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(o,20),"rem")},onClick:k,onKeyDown:C,onContextMenu:S,children:[j?(0,a.jsx)("span",{className:"w-4 h-4 flex items-center justify-center",children:b?(0,a.jsx)("span",{className:"w-3 h-3 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}):(0,a.jsx)(eN,{expanded:w})}):(0,a.jsx)("span",{className:"w-4 h-4"}),j?(0,a.jsx)(ek,{open:w}):(0,a.jsx)(eS,{extension:n.extension}),(0,a.jsx)("span",{className:"flex-1 truncate text-sm text-gray-700",children:"name"===f&&p?(0,a.jsx)(eC,{text:n.name,query:p}):n.name}),(0,a.jsx)("span",{className:"text-xs text-gray-400 flex-shrink-0",children:j?void 0!==n.itemCount&&"".concat(n.itemCount," items"):void 0===(r=n.size)?"":r<1024?"".concat(r," B"):r<1048576?"".concat((r/1024).toFixed(1)," KB"):"".concat((r/1048576).toFixed(1)," MB")})]}),j&&w&&N&&(0,a.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,a.jsx)(e,{item:t,path:v,depth:o+1,worktreeId:i,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:r,onNewFile:n,onNewDirectory:s,onRename:o,onDelete:i,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:T}=function(){let[e,t]=(0,l.useState)(eh),r=(0,l.useCallback)((e,r,a)=>{e.preventDefault(),t({isOpen:!0,position:{x:e.clientX,y:e.clientY},targetPath:r,targetType:a})},[]),a=(0,l.useCallback)(()=>{t(e=>({...e,isOpen:!1}))},[]),n=(0,l.useCallback)(()=>{t(eh)},[]);return(0,l.useEffect)(()=>{if(!e.isOpen)return;let t=()=>{a()},r=setTimeout(()=>{document.addEventListener("click",t)},0);return()=>{clearTimeout(r),document.removeEventListener("click",t)}},[e.isOpen,a]),(0,l.useEffect)(()=>{if(!e.isOpen)return;let t=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[e.isOpen,a]),{menuState:e,openMenu:r,closeMenu:a,resetMenu:n}}(),M=(0,l.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{let r=e?"/api/worktrees/".concat(t,"/tree/").concat(e):"/api/worktrees/".concat(t,"/tree"),a=await fetch(r);if(!a.ok)throw Error("Failed to load directory: ".concat(a.status));return await a.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 M();e&&t&&w(t.items)}catch(t){e&&y(t instanceof Error?t.message:"Failed to load files")}finally{e&&g(!1)}})(),()=>{e=!1}},[M,u]);let L=(0,l.useCallback)(async e=>{if(!k.has(e))try{let t=await M(e);t&&k.set(e,t.items)}catch(e){console.error("[FileTreeView] Error loading children:",e)}},[k,M]),R=(0,l.useCallback)(e=>{N(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),A=(0,l.useMemo)(()=>"content"===x&&h&&0!==h.length?ej(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=(r,a)=>r.filter(r=>{let n=a?"".concat(a,"/").concat(r.name):r.name,s=r.name.toLowerCase().includes(e);if("directory"===r.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,a.jsxs)("div",{"data-testid":"file-tree-loading",className:"flex items-center justify-center p-4 ".concat(d),children:[(0,a.jsx)("span",{className:"w-5 h-5 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}),(0,a.jsx)("span",{className:"ml-2 text-sm text-gray-500",children:"Loading files..."})]}):b?(0,a.jsx)("div",{"data-testid":"file-tree-error",className:"p-4 bg-red-50 border border-red-200 rounded-lg ".concat(d),children:(0,a.jsx)("p",{className:"text-sm text-red-600",children:b})}):0===v.length?(0,a.jsx)("div",{"data-testid":"file-tree-empty",className:"p-4 text-center text-gray-500 ".concat(d),children:(0,a.jsx)("p",{className:"text-sm",children:"No files found"})}):(null==m?void 0:m.trim())&&0===F.length?(0,a.jsx)("div",{"data-testid":"file-tree-no-results",className:"p-4 text-center text-gray-500 ".concat(d),children:(0,a.jsxs)("p",{className:"text-sm",children:["No ","content"===x?"files containing":"files matching",' "',m,'"']})}):(0,a.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,a.jsx)(eE,{item:e,path:"",depth:0,worktreeId:t,expanded:j,cache:k,onToggle:R,onFileSelect:p||r,onLoadChildren:L,onContextMenu:E,searchQuery:m,searchMode:x,matchedPaths:A},e.name)),(0,a.jsx)(ev,{isOpen:S.isOpen,position:S.position,targetPath:S.targetPath,targetType:S.targetType,onClose:T,onNewFile:n,onNewDirectory:s,onRename:o,onDelete:i,onUpload:c})]})}),eM=(0,l.memo)(function(){return(0,a.jsx)("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}),eL=(0,l.memo)(function(){return(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),eR=(0,l.memo)(function(){return(0,a.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..."})}),eA=(0,l.memo)(function(e){let{query:t,mode:r,isSearching:n,error:s,onQueryChange:o,onModeChange:i,onClear:c,placeholder:d="Search files...",className:u=""}=e,m=(0,l.useRef)(null),x=(0,l.useCallback)(e=>{o(e.target.value)},[o]),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 r;null===(r=m.current)||void 0===r||r.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,a.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,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"flex-shrink-0",children:(0,a.jsx)(eM,{})}),(0,a.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,a.jsx)("div",{className:"flex-shrink-0 w-6 h-6 flex items-center justify-center",children:n?(0,a.jsx)(eR,{}):t?(0,a.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,a.jsx)(eL,{})}):null})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("span",{className:"text-xs text-gray-500 mr-1",children:"Mode:"}),(0,a.jsx)("button",{type:"button","data-testid":"mode-name",onClick:()=>i("name"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("name"===r?"bg-blue-100 text-blue-700 font-medium":"bg-gray-100 text-gray-600 hover:bg-gray-200"),"aria-pressed":"name"===r,children:"Name"}),(0,a.jsx)("button",{type:"button","data-testid":"mode-content",onClick:()=>i("content"),className:"px-2 py-0.5 text-xs rounded transition-colors ".concat("content"===r?"bg-blue-100 text-blue-700 font-medium":"bg-gray-100 text-gray-600 hover:bg-gray-200"),"aria-pressed":"content"===r,children:"Content"})]}),s&&(0,a.jsx)("div",{"data-testid":"search-error",className:"text-xs text-red-600 bg-red-50 px-2 py-1 rounded",role:"alert",children:s})]})}),eF=(0,l.memo)(function(){return(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})})}),eP=(0,l.memo)(function(){return(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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"})})}),eD=(0,l.memo)(function(){return(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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"})})}),eI=[{id:"history",label:"History",icon:(0,a.jsx)(eF,{})},{id:"files",label:"Files",icon:(0,a.jsx)(eP,{})},{id:"memo",label:"Memo",icon:(0,a.jsx)(eD,{})}],e_=(0,l.memo)(function(e){let{activeTab:t,onTabChange:r,className:n=""}=e,s=(0,l.useCallback)(e=>{r(e)},[r]),o=(0,l.useCallback)((e,t)=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),r(e))},[r]),i=(0,l.useCallback)(e=>{let r=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(r?"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,a.jsx)("div",{role:"tablist","aria-label":"Left pane view switcher",className:"flex border-b border-gray-200 bg-white ".concat(n),children:eI.map(e=>(0,a.jsxs)("button",{type:"button",role:"tab","aria-selected":t===e.id,"aria-label":e.label,tabIndex:0,onClick:()=>s(e.id),onKeyDown:t=>o(e.id,t),className:i(e.id),children:[e.icon,(0,a.jsx)("span",{children:e.label})]},e.id))})});var ez=r(10789);function eO(e){let{src:t,alt:r,onError:n}=e,[s,o]=(0,l.useState)(!1);return s?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-gray-500",children:[(0,a.jsx)("svg",{className:"w-16 h-16 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),(0,a.jsx)("p",{className:"text-sm",children:"Failed to load image"}),(0,a.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:r})]}):(0,a.jsx)("div",{className:"flex items-center justify-center p-4",children:(0,a.jsx)("img",{src:t,alt:r,onError:()=>{o(!0),null==n||n()},style:{maxWidth:"100%",maxHeight:"500px",objectFit:"contain"},className:"rounded-lg shadow-sm"})})}function eW(e){let{isOpen:t,onClose:r,worktreeId:n,filePath:s}=e,[o,i]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(!t||!s){i(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();i(t)}catch(e){m(e instanceof Error?e.message:"Failed to load file")}finally{d(!1)}})()},[t,n,s]),(0,a.jsx)(ez.u_,{isOpen:t,onClose:r,title:s,size:"xl",children:(0,a.jsxs)("div",{className:"max-h-[60vh] sm:max-h-[70vh] overflow-y-auto",children:[c&&(0,a.jsxs)("div",{className:"flex items-center justify-center py-12",children:[(0,a.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,a.jsx)("p",{className:"ml-3 text-gray-600",children:"Loading file..."})]}),u&&(0,a.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4",children:(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("svg",{className:"w-5 h-5 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.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,a.jsx)("p",{className:"text-sm text-red-800",children:u})]})}),o&&!c&&!u&&(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg overflow-hidden",children:[(0,a.jsx)("div",{className:"bg-gray-100 px-4 py-2 border-b border-gray-200",children:(0,a.jsxs)("p",{className:"text-xs text-gray-600 font-mono",children:[o.worktreePath,"/",o.path]})}),o.isImage?(0,a.jsx)(eO,{src:o.content,alt:o.path,mimeType:o.mimeType}):(0,a.jsx)("div",{className:"p-4",children:(0,a.jsx)("pre",{className:"text-sm overflow-x-auto",children:(0,a.jsx)("code",{className:"language-".concat(o.extension),children:o.content})})})]})]})})}var eB=r(54887),eU=r(53012),eV=r(23260),eH=r(57934),eY=r(12158);r(57792);var eZ=r(76865),eq=r(48736),eG=r(93807),eK=r(42208),eJ=r(74440),eX=r(47416),eQ=r(83229),e$=r(32489),e0=r(41671),e1=r(99388),e2=r(33245);function e4(e){let{type:t,iconColor:r}=e,n="h-5 w-5 ".concat(r);switch(t){case"success":return(0,a.jsx)(e0.Z,{className:n,"data-testid":"toast-icon-success"});case"error":return(0,a.jsx)(e1.Z,{className:n,"data-testid":"toast-icon-error"});default:return(0,a.jsx)(e2.Z,{className:n,"data-testid":"toast-icon-info"})}}function e5(e){let{id:t,message:r,type:n,onClose:s,duration:o=3e3}=e,i=(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)(()=>(o>0&&(i.current=setTimeout(()=>{s(t)},o)),()=>{i.current&&clearTimeout(i.current)}),[t,o,s]);let d=(0,l.useCallback)(()=>{i.current&&clearTimeout(i.current),s(t)},[t,s]);return(0,a.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,a.jsx)(e4,{type:n,iconColor:c.iconColor}),(0,a.jsx)("p",{className:"flex-1 text-sm font-medium",children:r}),(0,a.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,a.jsx)(e$.Z,{className:"h-4 w-4"})})]})}function e3(e){let{toasts:t,onClose:r}=e;return(0,a.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,a.jsx)(e5,{id:e.id,message:e.message,type:e.type,onClose:r,duration:e.duration},e.id))})}function e6(){let[e,t]=(0,l.useState)([]),r=(0,l.useRef)(0);return{toasts:e,showToast:(0,l.useCallback)(function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"info",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e3,s="toast-".concat(++r.current,"-").concat(Date.now()),l={id:s,message:e,type:a,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 e8=r(30166),e7=r(51817);let e9=(0,e8.default)(()=>Promise.all([r.e(2714),r.e(656),r.e(13)]).then(r.bind(r,70013)).then(e=>({default:e.MermaidDiagram})),{loadableGenerated:{webpack:()=>[70013]},ssr:!1,loading:()=>(0,a.jsxs)("div",{className:"mermaid-loading flex items-center gap-2 text-gray-500 p-4",children:[(0,a.jsx)(e7.Z,{className:"animate-spin h-4 w-4"}),(0,a.jsx)("span",{children:"Loading diagram..."})]})});function te(e){let{className:t,children:r,inline:n}=e;if(n)return(0,a.jsx)("code",{className:t,children:r});if(t&&t.split(" ").includes("language-mermaid")){let e=null==r?"":"string"==typeof r?r:Array.isArray(r)?r.map(e=>"string"==typeof e?e:"").join(""):String(r);return(0,a.jsx)(e9,{code:e})}return(0,a.jsx)("code",{className:t,children:r})}function tt(){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 ta(){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 tn(){try{let e="__localStorage_test__";return window.localStorage.setItem(e,"test"),window.localStorage.removeItem(e),!0}catch(e){return!1}}function ts(e){let{key:t,defaultValue:r,validate:a,serialize:n=JSON.stringify,deserialize:s=JSON.parse}=e,[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(r),u=(0,l.useCallback)(()=>{if(!tn())return r;try{let e=window.localStorage.getItem(t);if(null===e)return r;let n=s(e);if(a)return a(n)?n:r;return n}catch(e){return r}},[t,r,a,s]),m=(0,l.useCallback)(e=>{if(tn())try{let r=n(e);window.localStorage.setItem(t,r)}catch(e){}},[t,n]),x=(0,l.useCallback)(e=>{d(t=>{let r="function"==typeof e?e(t):e;return m(r),r})},[m]),h=(0,l.useCallback)(()=>{if(tn())try{window.localStorage.removeItem(t)}catch(e){}d(r)},[t,r]);return(0,l.useEffect)(()=>{i(tn()),d(u())},[u]),{value:c,setValue:x,removeValue:h,isAvailable:o}}let tl=()=>null!=window.visualViewport;var to=r(3468);let ti={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"}},tc="commandmate:md-editor-view-mode",td={WARNING_THRESHOLD:512e3};function tu(e){return"number"==typeof e&&e>=.1&&e<=.9}function tm(e){return"boolean"==typeof e}function tx(e){return"split"===e||"editor"===e||"preview"===e}function th(e){let{worktreeId:t,filePath:r,onClose:n,onSave:s,initialViewMode:o,onMaximizedChange:i}=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&&tx(e))return e;{let e=localStorage.getItem(tc);if(e&&tx(e))return e}return"split"})(o)),[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,T]=(0,l.useState)("editor"),[M,L]=(0,l.useState)(null),{toasts:R,showToast:A,removeToast:F}=e6(),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),[r,a]=(0,l.useState)(0),n=(0,l.useCallback)(()=>{if(!tl())return;let e=window.visualViewport,r=window.innerHeight-e.height,n=r>100;t(n),a(n?r:0)},[]);return(0,l.useEffect)(()=>{if(!tl())return;let e=window.visualViewport;return n(),e.addEventListener("resize",n),()=>{e.removeEventListener("resize",n)}},[n]),{isKeyboardVisible:e,keyboardHeight:r}}(),{value:B,setValue:U}=ts({key:"commandmate:md-editor-maximized",defaultValue:!1,validate:tm}),{isFullscreen:V,isFallbackMode:H,enterFullscreen:Y,exitFullscreen:Z,toggleFullscreen:q}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{elementRef:t,onEnter:r,onExit:a,onError:n}=e,[s,o]=(0,l.useState)(!1),[i,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),m=(0,l.useCallback)(()=>{let e=null!=tt();o(e),!e&&i&&c(!1)},[i]),x=(0,l.useCallback)(async()=>{if(u(null),"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1)){o(!0),c(!0),null==r||r();return}if("undefined"!=typeof document&&(document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled)&&(null==t?void 0:t.current))try{await tr(t.current),o(!0),c(!1),null==r||r()}catch(t){let e=t instanceof Error?t.message:"Failed to enter fullscreen";u(e),null==n||n(t instanceof Error?t:Error(e)),o(!0),c(!0),null==r||r()}else o(!0),c(!0),null==r||r()},[t,r,n]),h=(0,l.useCallback)(async()=>{if(u(null),i){o(!1),c(!1),null==a||a();return}if(tt())try{await ta(),o(!1),null==a||a()}catch(t){let e=t instanceof Error?t.message:"Failed to exit fullscreen";u(e),null==n||n(t instanceof Error?t:Error(e)),o(!1),c(!1),null==a||a()}else o(!1),c(!1),null==a||a()},[i,a,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:i,enterFullscreen:x,exitFullscreen:h,toggleFullscreen:p,error:d}}({elementRef:I,onEnter:()=>U(!0),onExit:()=>U(!1)}),{value:G,setValue:K}=ts({key:"commandmate:md-editor-split-ratio",defaultValue:.5,validate:tu}),{ref:J}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onSwipeLeft:t,onSwipeRight:r,onSwipeUp:a,onSwipeDown:n,threshold:s=50,enabled:o=!0}=e,i=(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(!o)return;let t=e.touches[0];x.current={x:t.clientX,y:t.clientY},d(!0)},[o]),f=(0,l.useCallback)(e=>{if(!o||!x.current)return;let t=e.touches[0],r=t.clientX-x.current.x,a=t.clientY-x.current.y,n=Math.abs(r),l=Math.abs(a);n>l&&n>=s?m(r<0?"left":"right"):l>=s&&m(a<0?"up":"down")},[o,s]),g=(0,l.useCallback)(e=>{if(!o||!x.current){d(!1);return}let l=e.changedTouches[0],i=l.clientX-x.current.x,c=l.clientY-x.current.y,u=Math.abs(i),h=Math.abs(c);u>h?u>=s&&(i<0?(m("left"),null==t||t()):(m("right"),null==r||r())):h>=s&&(c<0?(m("up"),null==a||a()):(m("down"),null==n||n())),x.current=null,d(!1)},[o,s,t,r,a,n]);return(0,l.useEffect)(()=>{let e=i.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:i,isSwiping:c,swipeDirection:u,resetSwipeDirection:h}}({onSwipeDown:()=>{V&&Z()},threshold:100,enabled:V&&z}),X=c!==u,Q=ti[f],$=z&&window.innerHeight>window.innerWidth&&"split"===f,ee=(0,l.useMemo)(()=>ew(e=>{p(e)},300),[]),et=(0,l.useCallback)(async()=>{y(!0),k(null);try{let a=await fetch("/api/worktrees/".concat(t,"/files/").concat(r)),n=await a.json();if(!a.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>td.WARNING_THRESHOLD&&S(!0)}catch(e){k(e instanceof Error?e.message:"Failed to load file")}finally{y(!1)}},[t,r]),er=(0,l.useCallback)(async()=>{if(X&&!v){j(!0);try{let a=await fetch("/api/worktrees/".concat(t,"/files/").concat(r),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:c})}),n=await a.json();if(!a.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(r)}catch(e){A(e instanceof Error?e.message:"Failed to save file","error")}finally{j(!1)}}},[t,r,c,X,v,s,A]),ea=(0,l.useCallback)(e=>{let t=e.target.value;d(t),ee(t)},[ee]),en=(0,l.useCallback)(e=>{g(e),localStorage.setItem(tc,e)},[]),es=(0,l.useCallback)(()=>{(!X||window.confirm("You have unsaved changes. Are you sure you want to close?"))&&n&&n()},[X,n]),el=(0,l.useCallback)(e=>{if(!_.current)return;let t=_.current.offsetWidth;if(0===t)return;let r=e/t;K(e=>Math.max(.1,Math.min(.9,e+r)))},[K]),eo=(0,l.useCallback)(()=>{K(.5)},[K]),ei=(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(),Z();return}},[er,q,Z,V]);(0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&V&&(e.preventDefault(),Z())};return V&&document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[V,Z]),(0,l.useEffect)(()=>{B&&!V&&Y()},[]),(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==i||i(V)},[V,i]),(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 ec=(0,l.useMemo)(()=>{let e="flex flex-col bg-white";return V&&H?"".concat(e," fixed inset-0"):"".concat(e," h-full")},[V,H]),ed=(0,l.useMemo)(()=>{if(V)return{zIndex:to.k.MAXIMIZED_EDITOR}},[V]),eu=(0,l.useMemo)(()=>{if("split"===f&&!$)return{width:"".concat(100*G,"%"),flexShrink:0}},[f,G,$]),em=(0,l.useMemo)(()=>{if("split"===f&&!$)return{width:"".concat((1-G)*100,"%"),flexShrink:0}},[f,G,$]),ex=(0,l.useMemo)(()=>{if(O&&W>0)return{paddingBottom:W}},[O,W]),eh=(0,l.useMemo)(()=>({code:te}),[]),ep=(0,l.useMemo)(()=>(0,a.jsx)(eU.UG,{remarkPlugins:[eV.Z],rehypePlugins:[eH.Z,eY.Z],components:eh,children:h}),[h,eh]);if(b)return(0,a.jsx)("div",{"data-testid":"markdown-editor",className:"flex items-center justify-center h-full bg-white",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600"}),(0,a.jsx)("p",{className:"mt-4 text-gray-600",children:"Loading..."})]})});if(N)return(0,a.jsx)("div",{"data-testid":"markdown-editor-error",className:"flex items-center justify-center h-full bg-white",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)(eZ.Z,{className:"h-12 w-12 text-red-500 mx-auto mb-4"}),(0,a.jsx)("p",{className:"text-red-600",children:N}),n&&(0,a.jsx)("button",{onClick:n,className:"mt-4 px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg",children:"Close"})]})});let ef=(0,a.jsxs)("div",{ref:e=>{I.current=e,J.current=e},"data-testid":"markdown-editor",className:ec,style:ed,onKeyDown:ei,role:V&&H?"dialog":void 0,"aria-modal":V&&H?"true":void 0,children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 bg-gray-50",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-shrink",children:[(0,a.jsx)(eq.Z,{className:"h-4 w-4 text-gray-500 flex-shrink-0"}),(0,a.jsx)("span",{className:"text-sm font-medium text-gray-700 truncate",children:r}),X&&(0,a.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,a.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!$&&(0,a.jsxs)("div",{className:"flex items-center gap-1 bg-gray-100 rounded-lg p-1",children:[(0,a.jsx)("button",{"data-testid":"view-mode-split","aria-pressed":"split"===f,onClick:()=>en("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,a.jsx)(eG.Z,{className:"h-4 w-4"})}),(0,a.jsx)("button",{"data-testid":"view-mode-editor","aria-pressed":"editor"===f,onClick:()=>en("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,a.jsx)(eq.Z,{className:"h-4 w-4"})}),(0,a.jsx)("button",{"data-testid":"view-mode-preview","aria-pressed":"preview"===f,onClick:()=>en("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,a.jsx)(eK.Z,{className:"h-4 w-4"})})]}),(0,a.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,a.jsx)(eJ.Z,{className:"h-4 w-4"}):(0,a.jsx)(eX.Z,{className:"h-4 w-4"})}),(0,a.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,a.jsx)(eQ.Z,{className:"h-4 w-4"}),v?"Saving...":"Save"]}),n&&(0,a.jsx)("button",{"data-testid":"close-button",onClick:es,className:"p-1.5 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded",title:"Close",children:(0,a.jsx)(e$.Z,{className:"h-4 w-4"})})]})]}),V&&(0,a.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,a.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,a.jsx)(eZ.Z,{className:"h-4 w-4"}),"Large file: Performance may be affected.",(0,a.jsx)("button",{onClick:()=>S(!1),className:"ml-auto text-yellow-600 hover:text-yellow-800",children:(0,a.jsx)(e$.Z,{className:"h-4 w-4"})})]}),$&&(0,a.jsxs)("div",{className:"flex border-b border-gray-200",children:[(0,a.jsxs)("button",{"data-testid":"mobile-tab-editor",onClick:()=>T("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,a.jsx)(eq.Z,{className:"h-4 w-4 inline-block mr-1"}),"Editor"]}),(0,a.jsxs)("button",{"data-testid":"mobile-tab-preview",onClick:()=>T("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,a.jsx)(eK.Z,{className:"h-4 w-4 inline-block mr-1"}),"Preview"]})]}),(0,a.jsxs)("div",{ref:_,className:"flex flex-1 overflow-hidden",style:ex,children:[$?"editor"===E&&(0,a.jsx)("div",{"data-testid":"markdown-editor-container",className:"flex flex-col overflow-hidden w-full",children:(0,a.jsx)("textarea",{ref:P,"data-testid":"markdown-editor-textarea",value:c,onChange:ea,onKeyDown:ei,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,a.jsx)("div",{"data-testid":"markdown-editor-container",className:"flex flex-col overflow-hidden transition-all duration-200 ".concat(Q.showEditor?"":"hidden"),style:"split"===f?eu:{width:Q.showEditor?"100%":"0%"},children:(0,a.jsx)("textarea",{ref:P,"data-testid":"markdown-editor-textarea",value:c,onChange:ea,onKeyDown:ei,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,a.jsx)(w,{onResize:el,onDoubleClick:eo,orientation:"horizontal",ariaValueNow:Math.round(100*G),minRatio:.1}),$?"preview"===E&&(0,a.jsx)("div",{"data-testid":"markdown-preview-container",className:"flex flex-col overflow-hidden w-full",children:(0,a.jsx)("div",{"data-testid":"markdown-preview",className:"flex-1 p-4 overflow-y-auto prose prose-sm max-w-none",children:ep})}):(0,a.jsx)("div",{"data-testid":"markdown-preview-container",className:"flex flex-col overflow-hidden transition-all duration-200 ".concat(Q.showPreview?"":"hidden"),style:"split"===f?em:{width:Q.showPreview?"100%":"0%"},children:(0,a.jsx)("div",{"data-testid":"markdown-preview",className:"flex-1 p-4 overflow-y-auto prose prose-sm max-w-none",children:ep})})]}),(0,a.jsx)(e3,{toasts:R,onClose:F})]});return V&&H&&M?(0,eB.createPortal)(ef,M):ef}let tp=[".md"],tf=[{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"]}],tg=tf.map(e=>e.extension);var tb=r(3227);function ty(e){let{value:t,saveFn:r,debounceMs:a=300,disabled:n=!1,maxRetries:s=3,onSaveComplete:o}=e,[i,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)(null),m=(0,l.useRef)(t),x=(0,l.useRef)(r),h=(0,l.useRef)(o),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=r},[r]),(0,l.useEffect)(()=>{h.current=o},[o]),(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,r=0;for(;r<=s;)try{if(await x.current(e),f.current){var a;c(!1),u(null),null===(a=h.current)||void 0===a||a.call(h)}return}catch(e){if(t=e instanceof Error?e:Error(String(e)),++r<=s){let e=1e3*Math.pow(2,r-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)},a),()=>{y()}},[t,n,a,y,b]),{isSaving:i,error:d,saveNow:v}}let tv=(0,l.memo)(function(e){var t,r;let{memo:n,onUpdate:s,onDelete:o,isSaving:i,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}=ty({value:u,saveFn:async e=>{await s(n.id,{title:e})}}),{isSaving:b,error:y,saveNow:v}=ty({value:x,saveFn:async e=>{await s(n.id,{content:e})}}),w=null!==(r=null!==(t=null!=c?c:null==f?void 0:f.message)&&void 0!==t?t:null==y?void 0:y.message)&&void 0!==r?r: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)(()=>{o(n.id)},[n.id,o]);return(0,a.jsxs)("div",{"data-testid":"memo-card",className:"bg-white border border-gray-200 rounded-lg p-4 space-y-3 ".concat(d),children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.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!=i?i:p||b)&&(0,a.jsx)("span",{"data-testid":"saving-indicator",className:"text-xs text-gray-400",children:"Saving..."}),(0,a.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,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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,a.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,a.jsx)("div",{className:"text-xs text-red-500",children:w})]})}),tw=(0,l.memo)(function(e){let{currentCount:t,maxCount:r,onAdd:n,isLoading:s=!1,className:l=""}=e,o=t>=r||s;return(0,a.jsxs)("div",{"data-testid":"memo-add-button",className:"flex flex-col items-center gap-2 ".concat(l),children:[(0,a.jsxs)("button",{type:"button",onClick:()=>{o||n()},disabled:o,"aria-label":"Add Memo","aria-disabled":o,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(o?"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,a.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,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),(0,a.jsx)("span",{className:"text-sm font-medium",children:"Add Memo"})]}),(0,a.jsxs)("span",{className:"text-xs text-gray-500",children:[Math.max(0,r-t)," remaining"]})]})}),tj=(0,l.memo)(function(e){let{worktreeId:t,className:r=""}=e,[n,s]=(0,l.useState)([]),[o,i]=(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()=>{i(!0),m(null);try{let e=await tb.nE.getAll(t);s(e.sort((e,t)=>e.position-t.position))}catch(e){m((0,tb.zG)(e))}finally{i(!1)}},[t]);(0,l.useEffect)(()=>{p()},[p]);let f=(0,l.useCallback)(async()=>{d(!0),h(null);try{let e=await tb.nE.create(t,{title:"Memo",content:""});s(t=>[...t,e])}catch(e){h((0,tb.zG)(e))}finally{d(!1)}},[t]),g=(0,l.useCallback)(async(e,r)=>{await tb.nE.update(t,e,r),s(t=>t.map(t=>t.id===e?{...t,...r}:t))},[t]),b=(0,l.useCallback)(async e=>{try{await tb.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 o?(0,a.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(r),children:(0,a.jsxs)("div",{"data-testid":"memo-loading",className:"flex flex-col items-center gap-3",children:[(0,a.jsx)("div",{className:"w-8 h-8 border-4 border-gray-200 border-t-blue-500 rounded-full animate-spin"}),(0,a.jsx)("span",{className:"text-sm text-gray-500",children:"Loading memos..."})]})}):u?(0,a.jsx)("div",{"data-testid":"memo-pane",className:"flex flex-col items-center justify-center h-full p-4 ".concat(r),children:(0,a.jsxs)("div",{className:"flex flex-col items-center gap-3 text-center",children:[(0,a.jsx)("svg",{className:"w-12 h-12 text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.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,a.jsx)("span",{className:"text-sm text-red-600",children:u}),(0,a.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,a.jsxs)("div",{"data-testid":"memo-pane",className:"flex flex-col gap-4 p-4 overflow-y-auto ".concat(r),children:[0===n.length&&!x&&(0,a.jsxs)("div",{className:"text-center py-8 text-gray-500",children:[(0,a.jsx)("p",{children:"No memos yet."}),(0,a.jsx)("p",{className:"text-sm",children:"Click the button below to add one."})]}),n.map(e=>(0,a.jsx)(tv,{memo:e,onUpdate:g,onDelete:b},e.id)),x&&(0,a.jsx)("div",{className:"text-center py-2 text-sm text-red-500",children:x}),(0,a.jsx)(tw,{currentCount:n.length,maxCount:5,onAdd:f,isLoading:c,className:"mt-2"})]})});var tN=r(98702);function tk(e){let{isOpen:t,onConfirm:r,onCancel:n}=e;return(0,a.jsx)(tN.u,{isOpen:t,onClose:n,title:"Auto Yesモードを有効にしますか?",size:"sm",showCloseButton:!0,children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"text-sm text-gray-700",children:[(0,a.jsx)("p",{className:"font-medium mb-2",children:"機能説明"}),(0,a.jsxs)("ul",{className:"list-disc list-inside space-y-1",children:[(0,a.jsx)("li",{children:"yes/no確認 → 自動で「yes」を送信"}),(0,a.jsx)("li",{children:"複数選択肢 → デフォルトまたは先頭の選択肢を自動選択"})]}),(0,a.jsx)("p",{className:"mt-1",children:"1時間後に自動でOFFになります。"})]}),(0,a.jsxs)("div",{className:"text-sm text-gray-700",children:[(0,a.jsx)("p",{className:"font-medium mb-2",children:"リスクについて"}),(0,a.jsx)("p",{children:"自動応答により、意図しない操作(ファイルの削除・上書き等)が 実行される可能性があります。内容を十分に理解した上でご利用ください。"})]}),(0,a.jsx)("div",{className:"bg-yellow-50 border-l-4 border-yellow-400 p-3",children:(0,a.jsxs)("p",{className:"text-sm text-yellow-800",children:[(0,a.jsx)("span",{className:"font-medium",children:"免責事項:"}),"Auto Yesモードの使用により発生した問題について、 開発者は一切の責任を負いません。自己責任でご利用ください。"]})}),(0,a.jsxs)("div",{className:"flex justify-end gap-3 pt-2",children:[(0,a.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,a.jsx)("button",{type:"button",onClick:r,className:"px-4 py-2 text-sm font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 text-white",children:"同意して有効化"})]})]})})}let tC=(0,l.memo)(function(e){let{enabled:t,expiresAt:r,onToggle:n,lastAutoResponse:s}=e,[o,i]=(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||!r){i("");return}let e=()=>{i(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"))}(r))};e();let a=setInterval(e,1e3);return()=>clearInterval(a)},[t,r]),(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,a.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 bg-gray-50 border-b border-gray-200",children:[(0,a.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,a.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,a.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Auto Yes"}),t&&o&&(0,a.jsx)("span",{className:"text-sm text-gray-500","aria-label":"Time remaining",children:o}),c&&(0,a.jsx)("span",{className:"text-sm text-green-600 animate-pulse",children:c}),(0,a.jsx)(tk,{isOpen:x,onConfirm:f,onCancel:g})]})}),tS=(0,l.memo)(function(e){let{worktreeName:t,repositoryName:r,description:n,status:s,onBackClick:l,onInfoClick:o,onMenuClick:i}=e,c=et.Ie[s],d=n?n.length>50?"".concat(n.substring(0,50),"..."):n:null;return(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 bg-white border-b border-gray-200",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)("button",{type:"button",onClick:i,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,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,a.jsx)("div",{className:"w-px h-6 bg-gray-300","aria-hidden":"true"}),(0,a.jsxs)("button",{type:"button",onClick:l,className:"flex items-center gap-1 text-gray-600 hover:text-gray-900 transition-colors","aria-label":"Go back to worktree list",children:[(0,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),(0,a.jsx)("span",{className:"text-sm font-medium",children:"Back"})]}),(0,a.jsx)("div",{className:"w-px h-6 bg-gray-300","aria-hidden":"true"}),"spinner"===c.type?(0,a.jsx)("span",{"data-testid":"desktop-status-indicator",title:c.label,"aria-label":c.label,className:"w-3 h-3 rounded-full flex-shrink-0 border-2 border-t-transparent animate-spin ".concat(c.className)}):(0,a.jsx)("span",{"data-testid":"desktop-status-indicator",title:c.label,"aria-label":c.label,className:"w-3 h-3 rounded-full flex-shrink-0 ".concat(c.className)}),(0,a.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h1",{className:"text-lg font-semibold text-gray-900 truncate max-w-[200px] leading-tight",children:t}),d&&(0,a.jsx)("span",{className:"text-sm text-gray-500 truncate max-w-md",title:n,children:d})]}),(0,a.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-md",children:r})]})]}),(0,a.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,a.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:(0,a.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,a.jsx)("span",{className:"text-sm font-medium",children:"Info"})]})]})}),tE=(0,l.memo)(function(e){let{worktree:t,isOpen:r,onClose:n,onWorktreeUpdate:s}=e,[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(""),[u,m]=(0,l.useState)(!1),x=(0,l.useRef)(r);(0,l.useEffect)(()=>{let e=r&&!x.current;x.current=r,e&&t&&(d(t.description||""),i(!1))},[t,r]);let h=(0,l.useCallback)(async()=>{if(t){m(!0);try{let e=await tb.Iv.updateDescription(t.id,c);s(e),i(!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)||""),i(!1)},[t]);return t?(0,a.jsx)(tN.u,{isOpen:r,onClose:n,title:"Worktree Information",size:"md",children:(0,a.jsxs)("div",{className:"space-y-4 max-h-[70vh] overflow-y-auto",children:[(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Worktree"}),(0,a.jsx)("p",{className:"text-lg font-semibold text-gray-900",children:t.name})]}),(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Repository"}),(0,a.jsx)("p",{className:"text-base text-gray-900",children:t.repositoryName}),(0,a.jsx)("p",{className:"text-xs text-gray-500 mt-1 break-all",children:t.repositoryPath})]}),(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Path"}),(0,a.jsx)("p",{className:"text-sm text-gray-700 break-all font-mono",children:t.path})]}),t.status&&(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Status"}),(0,a.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,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500",children:"Description"}),!o&&(0,a.jsx)("button",{type:"button",onClick:()=>i(!0),className:"text-sm text-blue-600 hover:text-blue-800",children:"Edit"})]}),o?(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.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,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.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,a.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,a.jsx)("div",{className:"min-h-[50px]",children:t.description?(0,a.jsx)("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:t.description}):(0,a.jsx)("p",{className:"text-sm text-gray-400 italic",children:"No description added yet"})})]}),t.link&&(0,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Link"}),(0,a.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,a.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Last Updated"}),(0,a.jsx)("p",{className:"text-sm text-gray-700",children:new Date(t.updatedAt).toLocaleString()})]})]})}):null}),tT=(0,l.memo)(function(){return(0,a.jsx)("div",{className:"flex items-center justify-center h-full min-h-[200px]",role:"status","aria-live":"polite",children:(0,a.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,a.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-gray-300 border-t-blue-600","aria-hidden":"true"}),(0,a.jsx)("p",{className:"text-gray-600",children:"Loading worktree..."})]})})}),tM=(0,l.memo)(function(e){let{message:t,onRetry:r}=e;return(0,a.jsx)("div",{className:"flex items-center justify-center h-full min-h-[200px]",role:"alert","aria-live":"assertive",children:(0,a.jsxs)("div",{className:"text-center p-6 bg-red-50 rounded-lg border border-red-200 max-w-md",children:[(0,a.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,a.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,a.jsx)("p",{className:"text-red-600 font-medium",children:"Error loading worktree"}),(0,a.jsx)("p",{className:"text-red-500 text-sm mt-2",children:t}),r&&(0,a.jsx)("button",{type:"button",onClick:r,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"})]})})}),tL=(0,l.memo)(function(e){let{worktree:t,onWorktreeUpdate:r}=e,[n,s]=(0,l.useState)(!1),[o,i]=(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&&i(t.description||"")},[t,n]);let m=(0,l.useCallback)(async()=>{if(t){d(!0);try{let e=await tb.Iv.updateDescription(t.id,o);r(e),s(!1)}catch(e){console.error("Failed to save description:",e)}finally{d(!1)}}},[t,o,r]),x=(0,l.useCallback)(()=>{i((null==t?void 0:t.description)||""),s(!1)},[t]);return t?(0,a.jsxs)("div",{className:"p-4 space-y-4 overflow-y-auto h-full",children:[(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Worktree"}),(0,a.jsx)("p",{className:"text-lg font-semibold text-gray-900",children:t.name})]}),(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Repository"}),(0,a.jsx)("p",{className:"text-base text-gray-900",children:t.repositoryName}),(0,a.jsx)("p",{className:"text-xs text-gray-500 mt-1 break-all",children:t.repositoryPath})]}),(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Path"}),(0,a.jsx)("p",{className:"text-sm text-gray-700 break-all font-mono",children:t.path})]}),t.status&&(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Status"}),(0,a.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,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500",children:"Description"}),!n&&(0,a.jsx)("button",{type:"button",onClick:()=>s(!0),className:"text-sm text-blue-600 hover:text-blue-800",children:"Edit"})]}),n?(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("textarea",{value:o,onChange:e=>i(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,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.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,a.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,a.jsx)("div",{className:"min-h-[50px]",children:t.description?(0,a.jsx)("p",{className:"text-sm text-gray-700 whitespace-pre-wrap",children:t.description}):(0,a.jsx)("p",{className:"text-sm text-gray-400 italic",children:"No description added yet"})})]}),t.link&&(0,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Link"}),(0,a.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,a.jsxs)("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:[(0,a.jsx)("h2",{className:"text-sm font-medium text-gray-500 mb-1",children:"Last Updated"}),(0,a.jsx)("p",{className:"text-sm text-gray-700",children:new Date(t.updatedAt).toLocaleString()})]})]}):(0,a.jsx)("div",{className:"text-gray-500 text-center py-8",children:"Loading worktree info..."})}),tR=(0,l.memo)(function(e){let{activeTab:t,worktreeId:r,worktree:n,messages:s,terminalOutput:l,isTerminalActive:o,isThinking:i,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,a.jsx)(p,{componentName:"TerminalDisplay",children:(0,a.jsx)(F,{output:l,isActive:o,isThinking:i,className:"h-full"})});case"history":return(0,a.jsx)(p,{componentName:"HistoryPane",children:(0,a.jsx)(Z,{messages:s,worktreeId:r,onFilePathClick:c,className:"h-full"})});case"files":var v;return(0,a.jsx)(p,{componentName:"FileTreeView",children:(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[(0,a.jsx)(eA,{query:y.query,mode:y.mode,isSearching:y.isSearching,error:y.error,onQueryChange:y.setQuery,onModeChange:y.setMode,onClear:y.clearSearch}),(0,a.jsx)(eT,{worktreeId:r,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,a.jsx)(p,{componentName:"MemoPane",children:(0,a.jsx)(tj,{worktreeId:r,className:"h-full"})});case"info":return(0,a.jsx)(tL,{worktree:n,onWorktreeUpdate:u});default:return null}}),tA=(0,l.memo)(function(e){var t,r,s;let{worktreeId:o}=e,i=(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),r=(0,l.useMemo)(()=>({setPhase:e=>t({type:"SET_PHASE",phase:e}),setTerminalOutput:(e,r)=>t({type:"SET_TERMINAL_OUTPUT",output:e,realtimeSnippet:r}),setTerminalActive:e=>t({type:"SET_TERMINAL_ACTIVE",isActive:e}),setTerminalThinking:e=>t({type:"SET_TERMINAL_THINKING",isThinking:e}),showPrompt:(e,r)=>t({type:"SHOW_PROMPT",data:e,messageId:r}),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,r)=>t({type:"UPDATE_MESSAGE",id:e,updates:r}),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:r}}(),[y,v]=(0,l.useState)(null),[w,j]=(0,l.useState)(!0),[N,k]=(0,l.useState)(null),[C,S]=(0,l.useState)(!1),[T,M]=(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:r="name",debounceMs:a=300}=e,[n,s]=(0,l.useState)(""),[o,i]=(0,l.useState)(""),[c,d]=(0,l.useState)(r),[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)(()=>ew(e=>{i(e)},a),[a]),y=(0,l.useCallback)(e=>{s(e),b(e),f(null)},[b]),v=(0,l.useCallback)(()=>{s(""),i(""),h(null),f(null),m(!1),g.current&&(g.current.abort(),g.current=null)},[]),w=(0,l.useCallback)(e=>{if(!o.trim())return e;let t=o.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t))},[o]),j=(0,l.useCallback)(()=>x&&0!==x.results.length?ej(x.results.map(e=>e.filePath)):new Set,[x]);return(0,l.useEffect)(()=>{if("content"!==c||!o.trim()){h(null);return}g.current&&g.current.abort();let e=new AbortController;return g.current=e,(async()=>{m(!0),f(null);try{var r,a;let n=await fetch("/api/worktrees/".concat(encodeURIComponent(t),"/search?q=").concat(encodeURIComponent(o),"&mode=content"),{signal:e.signal});if(!n.ok){let e=await n.json();throw Error((null===(r=e.error)||void 0===r?void 0:r.message)||"Search failed: ".concat(n.status))}let s=await n.json();if(s.success)h({mode:"content",query:o,results:s.results,totalMatches:s.totalMatches,truncated:s.truncated,executionTimeMs:s.executionTimeMs});else throw Error((null===(a=s.error)||void 0===a?void 0:a.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,o,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:o}),U=(0,l.useRef)(!1),V=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/worktrees/".concat(o));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}},[o]),H=(0,l.useCallback)(async()=>{try{let e=await fetch("/api/worktrees/".concat(o,"/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)}},[o,b]),Y=(0,l.useCallback)(async()=>{try{var e,t,r,a,n;let s=await fetch("/api/worktrees/".concat(o,"/current-output?cliTool=claude"));if(!s.ok)return;let l=await s.json(),i=null!==(t=null!==(e=l.fullOutput)&&void 0!==e?e:l.realtimeSnippet)&&void 0!==t?t:"";(i||l.isRunning)&&b.setTerminalOutput(i,null!==(r=l.realtimeSnippet)&&void 0!==r?r:""),b.setTerminalActive(null!==(a=l.isRunning)&&void 0!==a&&a),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)}},[o,b,g.prompt.visible]),q=(0,l.useCallback)(e=>{M(e)},[]),G=(0,l.useCallback)(e=>{var t;let r=null===(t=e.split(".").pop())||void 0===t?void 0:t.toLowerCase();tp.includes(r?".".concat(r):"")?R(e):M(e)},[]),K=(0,l.useCallback)(()=>{M(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)(()=>{i.push("/")},[i]),et=(0,l.useCallback)(()=>{S(!0)},[]),er=(0,l.useCallback)(()=>{S(!1)},[]),ea=(0,l.useCallback)(async e=>{b.setPromptAnswering(!0);try{let t=await fetch("/api/worktrees/".concat(o,"/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 Y()}catch(e){console.error("[WorktreeDetailRefactored] Error sending prompt response:",e)}finally{b.setPromptAnswering(!1)}},[o,b,Y]),es=(0,l.useCallback)(()=>{b.clearPrompt()},[b]),el=(0,l.useCallback)(e=>{b.setMobileActivePane(e)},[b]),ei=(0,l.useCallback)(e=>{b.setAutoScroll(e)},[b]),ed=(0,l.useCallback)(()=>{H(),Y()},[H,Y]),eu=(0,l.useCallback)(async e=>{try{let t=await fetch("/api/worktrees/".concat(o,"/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)}},[o]),em=(0,l.useCallback)(async e=>{let t=window.prompt("Enter file name (e.g., document.md):");if(!t)return;let r=t.endsWith(".md")?t:"".concat(t,".md"),a=e?"".concat(e,"/").concat(r):r;try{if(!(await fetch("/api/worktrees/".concat(o,"/files/").concat(encodeURIComponent(a)),{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("ファイルの作成に失敗しました")}},[o]),eh=(0,l.useCallback)(async e=>{let t=window.prompt("Enter directory name:");if(!t)return;let r=e?"".concat(e,"/").concat(t):t;try{if(!(await fetch("/api/worktrees/".concat(o,"/files/").concat(encodeURIComponent(r)),{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("ディレクトリの作成に失敗しました")}},[o]),ep=(0,l.useCallback)(async e=>{let t=e.split("/").pop()||"",r=window.prompt("Enter new name:",t);if(r&&r!==t)try{if(!(await fetch("/api/worktrees/".concat(o,"/files/").concat(encodeURIComponent(e)),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"rename",newName:r})})).ok)throw Error("Failed to rename");W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to rename:",e),window.alert("リネームに失敗しました")}},[o]),ef=(0,l.useCallback)(async e=>{let t=e.split("/").pop()||e;if(window.confirm('"'.concat(t,'" を削除しますか?')))try{if(!(await fetch("/api/worktrees/".concat(o,"/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("削除に失敗しました")}},[o,L]),{toasts:eg,showToast:eb,removeToast:ey}=e6(),ev=(0,l.useRef)(null),eN=(0,l.useRef)(""),ek=(0,l.useCallback)(e=>{var t;eN.current=e,null===(t=ev.current)||void 0===t||t.click()},[]),eC=(0,l.useCallback)(async e=>{var t,r,a;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===(r=n.name.split(".").pop())||void 0===r?void 0:r.toLowerCase());if(!function(e){if(!e)return!1;let t=e.toLowerCase();return tg.includes(t)}(l)){eb("Unsupported file type: ".concat(l,". Allowed: ").concat(tg.join(", ")),"error");return}let i=function(e){var t;let r=function(e){let t=e.toLowerCase();return tf.find(e=>e.extension===t)}(e);return null!==(t=null==r?void 0:r.maxFileSize)&&void 0!==t?t:5242880}(l);if(n.size>i){eb("File too large. Maximum size: ".concat((i/1024/1024).toFixed(1),"MB"),"error");return}let c=new FormData;c.append("file",n);try{let e=await fetch("/api/worktrees/".concat(o,"/upload/").concat(encodeURIComponent(s||".")),{method:"POST",body:c});if(!e.ok){let t=await e.json().catch(()=>({})),r=(null==t?void 0:null===(a=t.error)||void 0===a?void 0:a.message)||"Failed to upload file";eb(r,"error");return}let t=await e.json();eb("Uploaded: ".concat(t.filename),"success"),W(e=>e+1)}catch(e){console.error("[WorktreeDetailRefactored] Failed to upload:",e),eb("Upload failed. Please try again.","error")}},[o,eb]),{lastAutoResponse:eS}=function(e){let{worktreeId:t,cliTool:r,isPromptWaiting:a,promptData:n,autoYesEnabled:s}=e,o=(0,l.useRef)(null),[i,c]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(!a){o.current=null;return}if(!n||!s)return;let e="".concat(n.type,":").concat(n.question);if(o.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),r=null!=t?t:e.options[0];return!r||r.requiresTextInput?null:r.number.toString()}return null}(n);null!==l&&(o.current=e,c(l),fetch("/api/worktrees/".concat(t,"/prompt-response"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({answer:l,cliTool:r})}).catch(e=>{console.error("[useAutoYes] Failed to send auto-response:",e)}))},[a,n,s,t,r]),{lastAutoResponse:i}}({worktreeId:o,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(),Y()]),j(!1)},[V,H,Y]);(0,l.useEffect)(()=>{if(U.current)return;let e=!0;return(async()=>{j(!0);let t=await V();e&&(t&&await Promise.all([H(),Y()]),e&&(j(!1),U.current=!0))})(),()=>{e=!1}},[V,H,Y]),(0,l.useEffect)(()=>{if(w||N)return;let e=setInterval(async()=>{await Promise.all([Y(),V(),H()])},g.terminal.isActive?2e3:5e3);return()=>clearInterval(e)},[w,N,Y,V,H,g.terminal.isActive]),(0,l.useEffect)(()=>{b.setLayoutMode(c?"tabs":"split")},[c,b]);let eM=(0,l.useMemo)(()=>(function(e,t){var r;if(t)return"error";if(!e)return"idle";let a=null===(r=e.sessionStatusByCli)||void 0===r?void 0:r.claude;if(a){if(a.isWaitingForResponse)return"waiting";if(a.isProcessing)return"running";if(a.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]),eF=null!==(t=null==y?void 0:y.name)&&void 0!==t?t:"Unknown";return w?(0,a.jsx)(tT,{}):N?(0,a.jsx)(tM,{message:N,onRetry:eE}):c?(0,a.jsx)(p,{componentName:"WorktreeDetailRefactored",children:(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[(0,a.jsx)(en,{worktreeName:eF,repositoryName:null==y?void 0:y.repositoryName,status:eM,onBackClick:$,onMenuClick:f}),(0,a.jsx)("div",{className:"fixed top-14 inset-x-0 z-30",children:(0,a.jsx)(tC,{enabled:D,expiresAt:_,onToggle:eu,lastAutoResponse:eS})}),(0,a.jsx)("main",{className:"flex-1 pt-[6.25rem] pb-32 overflow-hidden",style:{paddingBottom:"calc(8rem + env(safe-area-inset-bottom, 0px))"},children:(0,a.jsx)(tR,{activeTab:eL,worktreeId:o,worktree:y,messages:g.messages,terminalOutput:g.terminal.output,isTerminalActive:g.terminal.isActive,isThinking:g.terminal.isThinking,onFilePathClick:q,onFileSelect:G,onWorktreeUpdate:v,onNewFile:em,onNewDirectory:eh,onRename:ep,onDelete:ef,onUpload:ek,refreshTrigger:O,fileSearch:B})}),(0,a.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,a.jsx)(ex.R,{worktreeId:o,onMessageSent:ed,cliToolId:"claude",isSessionRunning:g.terminal.isActive})}),(0,a.jsx)(eo,{activeTab:eL,onTabChange:el,hasNewOutput:!1,hasPrompt:g.prompt.visible}),!D&&(0,a.jsx)(ec,{promptData:g.prompt.data,visible:g.prompt.visible,answering:g.prompt.answering,onRespond:ea,onDismiss:es}),(0,a.jsx)(eW,{isOpen:null!==T,onClose:K,worktreeId:o,filePath:null!=T?T:""}),L&&(0,a.jsx)(tN.u,{isOpen:!0,onClose:J,title:L.split("/").pop()||"Editor",size:"full",disableClose:A,children:(0,a.jsx)("div",{className:"h-[80vh]",children:(0,a.jsx)(th,{worktreeId:o,filePath:L,onClose:J,onSave:X,onMaximizedChange:P})})}),(0,a.jsx)("input",{ref:ev,type:"file",accept:tg.join(","),onChange:eC,className:"hidden","aria-label":"Upload file"}),(0,a.jsx)(e3,{toasts:eg,onClose:ey})]})}):(0,a.jsx)(p,{componentName:"WorktreeDetailRefactored",children:(0,a.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,a.jsx)(tS,{worktreeName:eF,repositoryName:null!==(s=null==y?void 0:y.repositoryName)&&void 0!==s?s:"Unknown",description:null==y?void 0:y.description,status:eM,onBackClick:$,onInfoClick:et,onMenuClick:d}),(0,a.jsx)("div",{className:"flex-1 min-h-0",children:(0,a.jsx)(E,{leftPane:(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[(0,a.jsx)(e_,{activeTab:eR,onTabChange:Q}),(0,a.jsxs)("div",{className:"flex-1 min-h-0 overflow-hidden",children:["history"===eR&&(0,a.jsx)(Z,{messages:g.messages,worktreeId:o,onFilePathClick:q,className:"h-full"}),"files"===eR&&(0,a.jsx)(p,{componentName:"FileTreeView",children:(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[(0,a.jsx)(eA,{query:B.query,mode:B.mode,isSearching:B.isSearching,error:B.error,onQueryChange:B.setQuery,onModeChange:B.setMode,onClear:B.clearSearch}),(0,a.jsx)(eT,{worktreeId:o,onFileSelect:G,onNewFile:em,onNewDirectory:eh,onRename:ep,onDelete:ef,onUpload:ek,refreshTrigger:O,searchQuery:B.query,searchMode:B.mode,searchResults:null===(r=B.results)||void 0===r?void 0:r.results,className:"flex-1 min-h-0"})]})}),"memo"===eR&&(0,a.jsx)(p,{componentName:"MemoPane",children:(0,a.jsx)(tj,{worktreeId:o,className:"h-full"})})]})]}),rightPane:(0,a.jsx)(F,{output:g.terminal.output,isActive:g.terminal.isActive,isThinking:g.terminal.isThinking,autoScroll:g.terminal.autoScroll,onScrollChange:ei}),initialLeftWidth:40,minLeftWidth:20,maxLeftWidth:60})}),(0,a.jsx)("div",{className:"flex-shrink-0 border-t border-gray-200 p-4 bg-gray-50",children:(0,a.jsx)(ex.R,{worktreeId:o,onMessageSent:ed,cliToolId:"claude",isSessionRunning:g.terminal.isActive})}),(0,a.jsx)(tC,{enabled:D,expiresAt:_,onToggle:eu,lastAutoResponse:eS}),g.prompt.visible&&!D&&(0,a.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,a.jsx)(ee,{promptData:g.prompt.data,messageId:g.prompt.messageId,visible:g.prompt.visible,answering:g.prompt.answering,onRespond:ea,onDismiss:es})}),(0,a.jsx)(tE,{worktree:y,isOpen:C,onClose:er,onWorktreeUpdate:v}),(0,a.jsx)(eW,{isOpen:null!==T,onClose:K,worktreeId:o,filePath:null!=T?T:""}),L&&(0,a.jsx)(tN.u,{isOpen:!0,onClose:J,title:L.split("/").pop()||"Editor",size:"full",disableClose:A,children:(0,a.jsx)("div",{className:"h-[80vh]",children:(0,a.jsx)(th,{worktreeId:o,filePath:L,onClose:J,onSave:X,onMaximizedChange:P})})}),(0,a.jsx)("input",{ref:ev,type:"file",accept:tg.join(","),onChange:eC,className:"hidden","aria-label":"Upload file"}),(0,a.jsx)(e3,{toasts:eg,onClose:ey})]})})});function tF(){let e=(0,n.useParams)().id;return(0,a.jsx)(s.Vw,{children:(0,a.jsx)(tA,{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()}]);