hammoc 1.1.2 → 1.1.3

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 (25) hide show
  1. package/package.json +4 -1
  2. package/packages/client/dist/assets/{index-DgAO9S7x.js → index-Beq1jpLo.js} +2 -2
  3. package/packages/client/dist/assets/{index-B-d8nJ3b.js → index-CJJ7qZd7.js} +1 -1
  4. package/packages/client/dist/index.html +1 -1
  5. package/packages/client/dist/sw.js +1 -1
  6. package/packages/server/dist/controllers/serverController.d.ts.map +1 -1
  7. package/packages/server/dist/controllers/serverController.js +10 -2
  8. package/packages/server/dist/controllers/serverController.js.map +1 -1
  9. package/packages/server/dist/services/historyParser.d.ts +1 -0
  10. package/packages/server/dist/services/historyParser.d.ts.map +1 -1
  11. package/packages/server/dist/services/historyParser.js +5 -1
  12. package/packages/server/dist/services/historyParser.js.map +1 -1
  13. package/packages/server/dist/services/projectService.d.ts +5 -0
  14. package/packages/server/dist/services/projectService.d.ts.map +1 -1
  15. package/packages/server/dist/services/projectService.js +41 -3
  16. package/packages/server/dist/services/projectService.js.map +1 -1
  17. package/packages/server/dist/services/queueService.d.ts.map +1 -1
  18. package/packages/server/dist/services/queueService.js +30 -26
  19. package/packages/server/dist/services/queueService.js.map +1 -1
  20. package/packages/server/dist/services/sessionService.d.ts.map +1 -1
  21. package/packages/server/dist/services/sessionService.js +5 -0
  22. package/packages/server/dist/services/sessionService.js.map +1 -1
  23. package/packages/shared/dist/types/session.d.ts +1 -0
  24. package/packages/shared/dist/types/session.d.ts.map +1 -1
  25. package/packages/shared/dist/types/session.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hammoc",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Web-based IDE for managing Claude Code sessions, projects, and workflows",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -60,12 +60,15 @@
60
60
  "cors": "^2.8.5",
61
61
  "cross-env": "^10.1.0",
62
62
  "express": "^4.21.0",
63
+ "express-rate-limit": "^8.3.1",
64
+ "helmet": "^8.1.0",
63
65
  "i18next": "^24.2.3",
64
66
  "js-yaml": "^4.1.1",
65
67
  "multer": "^2.1.1",
66
68
  "node-pty": "^1.0.0",
67
69
  "simple-git": "^3.27.0",
68
70
  "socket.io": "^4.8.0",
71
+ "web-push": "^3.6.7",
69
72
  "zod": "^4.3.6"
70
73
  },
71
74
  "devDependencies": {
@@ -787,7 +787,7 @@ Please change the parent <Route path="${x}"> to <Route path="${x==="/"?"*":`${x}
787
787
  \${}
788
788
  } else {
789
789
  \${}
790
- }`,{label:"if",detail:"/ else block",type:"keyword"}),Dt('import ${name} "${module}"\n${}',{label:"import",detail:"declaration",type:"keyword"})],c2=new Ig,s3=new Set(["SourceFile","Block","FunctionDecl","MethodDecl","FunctionLiteral","ForStatement","SwitchStatement","TypeSwitchStatement","IfStatement"]);function Ec(t,e){return(r,n)=>{e:for(let i=r.node.firstChild,s=0,a=null;;){for(;!i;){if(!s)break e;s--,i=a.nextSibling,a=a.parent}e&&i.name==e||i.name=="SpecList"?(s++,a=i,i=i.firstChild):(i.name=="DefName"&&n(i,t),i=i.nextSibling)}return!0}}const Gpe={FunctionDecl:Ec("function"),VarDecl:Ec("var","VarSpec"),ConstDecl:Ec("constant","ConstSpec"),TypeDecl:Ec("type","TypeSpec"),ImportDecl:Ec("constant","ImportSpec"),Parameter:Ec("var"),__proto__:null};function a3(t,e){let r=c2.get(e);if(r)return r;let n=[],i=!0;function s(a,o){let l=t.sliceString(a.from,a.to);n.push({label:l,type:o})}return e.cursor(Jt.IncludeAnonymous).iterate(a=>{if(i)i=!1;else if(a.name){let o=Gpe[a.name];if(o&&o(a,s)||s3.has(a.name))return!1}else if(a.to-a.from>8192){for(let o of a3(t,a.node))n.push(o);return!1}}),c2.set(e,n),n}const d2=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,o3=["String","LineComment","BlockComment","DefName","LabelName","FieldName",".","?."],Hpe=t=>{let e=mr(t.state).resolveInner(t.pos,-1);if(o3.indexOf(e.name)>-1)return null;let r=e.name=="VariableName"||e.to-e.from<20&&d2.test(t.state.sliceDoc(e.from,e.to));if(!r&&!t.explicit)return null;let n=[];for(let i=e;i;i=i.parent)s3.has(i.name)&&(n=n.concat(a3(t.state.doc,i)));return{options:n,from:r?e.from:t.pos,validFor:d2}},uy=Ni.define({name:"go",parser:Bpe.configure({props:[ps.add({IfStatement:Rn({except:/^\s*({|else\b)/}),LabeledStatement:Gg,"SwitchBlock SelectBlock":t=>{let e=t.textAfter,r=/^\s*\}/.test(e),n=/^\s*(case|default)\b/.test(e);return t.baseIndent+(r||n?0:t.unit)},Block:Va({closing:"}"}),BlockComment:()=>null,Statement:Rn({except:/^{/})}),Mi.add({"Block SwitchBlock SelectBlock LiteralValue InterfaceType StructType SpecList":to,BlockComment(t){return{from:t.from+2,to:t.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case\b|default\b|\})$/}});let Kpe=t=>({label:t,type:"keyword"});const Jpe="interface struct chan map package go return break continue goto fallthrough else defer range true false nil".split(" ").map(Kpe);function eme(){let t=Fpe.concat(Jpe);return new us(uy,[uy.data.of({autocomplete:Rw(o3,Kg(t))}),uy.data.of({autocomplete:Hpe})])}const tme={".ts":()=>Hu({typescript:!0}),".tsx":()=>Hu({typescript:!0,jsx:!0}),".js":()=>Hu(),".jsx":()=>Hu({jsx:!0}),".json":()=>vde(),".md":()=>jhe(),".html":()=>A4(),".css":()=>_4(),".py":()=>Jfe(),".go":()=>eme(),".rs":()=>yOe(),".java":()=>QOe(),".c":()=>cy(),".cpp":()=>cy(),".h":()=>cy(),".yaml":()=>o2(),".yml":()=>o2()};function l3(t){const e=t.lastIndexOf(".");if(e===-1)return null;const r=t.slice(e).toLowerCase(),n=tme[r];return n?n():null}function c3(t){return t.toLowerCase().endsWith(".md")}const rme=new Set([".png",".jpg",".jpeg",".gif",".svg",".webp",".bmp",".ico"]);function qo(t){const e=t.lastIndexOf(".");return e===-1?!1:rme.has(t.slice(e).toLowerCase())}const u2={openFile:null,content:"",originalContent:"",isDirty:!1,isLoading:!1,isSaving:!1,isTruncated:!1,isMarkdownPreview:!1,error:null,pendingNavigation:null,targetLine:null,recentFiles:{}},bn=Zn((t,e)=>({...u2,openFileInEditor:async(r,n,i)=>{const s=c3(n)&&Ht.getState().preferences.markdownDefaultMode==="preview";t({openFile:{projectSlug:r,path:n},isLoading:!0,error:null,isTruncated:!1,isMarkdownPreview:s,content:"",originalContent:"",isDirty:!1,targetLine:i??null});try{const a=await ni.readFile(r,n);if(a.isBinary){t({error:we.t("notification:file.binaryNotEditable"),isLoading:!1});return}const o=a.content??"";t({content:o,originalContent:o,isLoading:!1,isTruncated:a.isTruncated})}catch(a){t({error:a.message,isLoading:!1})}},saveFile:async()=>{const{openFile:r,content:n}=e();if(!r)return!1;t({isSaving:!0});try{return await ni.writeFile(r.projectSlug,r.path,n),t({originalContent:n,isDirty:!1,isSaving:!1}),!0}catch{return t({isSaving:!1}),!1}},requestFileNavigation:(r,n,i)=>{e().isDirty?t({pendingNavigation:{projectSlug:r,path:n,targetLine:i}}):e().openFileInEditor(r,n,i)},confirmPendingNavigation:()=>{const{pendingNavigation:r}=e();r&&(t({pendingNavigation:null}),e().openFileInEditor(r.projectSlug,r.path,r.targetLine))},cancelPendingNavigation:()=>{t({pendingNavigation:null})},closeEditor:()=>{const{recentFiles:r}=e();t({...u2,recentFiles:r})},setContent:r=>{t({content:r,isDirty:r!==e().originalContent})},resetError:()=>t({error:null}),toggleMarkdownPreview:()=>{t({isMarkdownPreview:!e().isMarkdownPreview})},addRecentFile:(r,n)=>{const s=(e().recentFiles[r]??[]).filter(o=>o!==n),a=[n,...s].slice(0,5);t({recentFiles:{...e().recentFiles,[r]:a}})}})),nme={stories:"document.stories",qa:"document.qa"};function h2(t,e){const r=nme[t];return r?e(r):t}const fp={brainstorming:"/BMad:agents:analyst","market-research":"/BMad:agents:analyst","competitor-analysis":"/BMad:agents:analyst",brief:"/BMad:agents:analyst",prd:"/BMad:agents:pm","front-end-spec":"/BMad:agents:ux-expert",architecture:"/BMad:agents:architect","ui-architecture":"/BMad:agents:architect"},ime=new Set(["brainstorming","brief"]),sme=new Set(["prd","architecture"]);function ame(t){const e=new Map;for(const s of t.supplementary??[])e.set(s.key,s);const r=["brainstorming","market-research","competitor-analysis","brief"],n=["front-end-spec","ui-architecture"],i=[];for(const s of r){const a=e.get(s);a&&i.push({key:a.key,label:a.label,exists:a.exists,path:a.path,optional:!0,agentCommand:fp[a.key],recommended:!t.prd.exists&&ime.has(a.key)})}i.push({key:"prd",label:"PRD",exists:t.prd.exists,path:t.prd.path,agentCommand:fp.prd,sharded:t.prd.sharded,shardedPath:t.prd.shardedPath,shardedFiles:t.prd.shardedFiles});for(const s of n){const a=e.get(s);a&&i.push({key:a.key,label:a.label,exists:a.exists,path:a.path,optional:!0,agentCommand:fp[a.key]})}return i.push({key:"architecture",label:"Architecture",exists:t.architecture.exists,path:t.architecture.path,agentCommand:fp.architecture,sharded:t.architecture.sharded,shardedPath:t.architecture.shardedPath,shardedFiles:t.architecture.shardedFiles}),i}function tk({entries:t,basePath:e,onOpenFile:r,expandedDocs:n,toggleDoc:i,keyPrefix:s}){return d.jsx("div",{className:"space-y-0.5",children:t.map(a=>{const o=`${s}/${a.name}`;if(a.isDir&&a.children){const l=n.has(o);return d.jsxs("div",{children:[d.jsxs("button",{onClick:()=>i(o),className:"text-xs text-gray-600 dark:text-gray-300 hover:underline cursor-pointer inline-flex items-center gap-1",children:[a.name,"/",d.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[a.children.length,"개"]}),d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${l?"rotate-180":""}`})]}),l&&d.jsx("div",{className:"mt-0.5 ml-4",children:d.jsx(tk,{entries:a.children,basePath:e?`${e}/${a.name}`:a.name,onOpenFile:r,expandedDocs:n,toggleDoc:i,keyPrefix:o})})]},a.name)}return d.jsx("button",{onClick:()=>r(e?`${e}/${a.name}`:a.name),className:"block text-xs text-gray-600 dark:text-gray-300 hover:underline cursor-pointer",children:a.name},a.name)})})}function ome({doc:t,isDocExpanded:e,toggleDoc:r,handleOpenDoc:n,handleCreateDoc:i,expandedDocs:s,t:a}){const o=t.sharded&&t.shardedFiles&&t.shardedFiles.length>0,l=sme.has(t.key);return d.jsxs("div",{children:[d.jsxs("div",{className:`flex items-center gap-2 py-1 px-2 -mx-2 rounded-md transition-colors ${l?"bg-gray-100/50 dark:bg-[#253040]/30":""}`,children:[t.exists?d.jsx(As,{className:`w-4 h-4 flex-shrink-0 ${t.optional?"text-green-400 dark:text-green-600":"text-green-600 dark:text-green-400"}`}):t.optional?d.jsx(rj,{className:"w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0"}):d.jsx(Ao,{className:"w-4 h-4 text-red-600 dark:text-red-400 flex-shrink-0"}),t.exists&&o?d.jsxs("button",{onClick:()=>r(t.key),className:"font-semibold text-gray-900 dark:text-white hover:underline cursor-pointer inline-flex items-center gap-1",children:[t.label,d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${e?"rotate-180":""}`})]}):d.jsx("span",{className:t.exists?t.optional?"text-gray-700 dark:text-gray-200":"font-semibold text-gray-900 dark:text-white":t.optional?"text-gray-500 dark:text-gray-400":"font-semibold text-gray-900 dark:text-gray-100",children:t.label}),o&&d.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded",children:a("document.sharded")}),d.jsx("span",{className:"flex-1"}),!o&&t.exists&&d.jsx("button",{onClick:()=>n(t.path),className:"text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:underline cursor-pointer truncate max-w-[50%]",children:t.path}),!t.exists&&!t.optional&&d.jsx("span",{className:"text-xs px-2 py-0.5 bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300 rounded-full",children:a("document.writeRequired")}),!t.exists&&t.recommended&&d.jsx("span",{className:"text-xs px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 rounded-full",children:a("document.writeRecommended")}),!t.exists&&t.agentCommand&&d.jsx("button",{onClick:()=>i(t.agentCommand),className:`p-0.5 rounded transition-colors cursor-pointer ${!t.optional||t.recommended?"bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-900/50":"bg-gray-100 dark:bg-[#253040]/50 text-gray-400 dark:text-gray-500 hover:bg-gray-200 dark:hover:bg-[#253040] hover:text-gray-500 dark:hover:text-gray-400"}`,title:a("document.writeGo"),children:d.jsx(Yee,{className:"w-3.5 h-3.5"})})]}),e&&o&&d.jsxs("div",{className:"mt-1 ml-6 space-y-1",children:[d.jsx("button",{onClick:()=>n(t.path),className:"block text-xs text-gray-600 dark:text-gray-300 hover:underline cursor-pointer",children:t.path}),d.jsx(tk,{entries:[{name:`${t.shardedPath}`,isDir:!0,children:t.shardedFiles}],basePath:"",onOpenFile:n,expandedDocs:s,toggleDoc:r,keyPrefix:t.key})]})]})}function lme({documents:t,auxiliaryDocuments:e,projectSlug:r}){const{t:n}=Ce("common"),i=En(),s=bn(b=>b.requestFileNavigation),[a,o]=k.useState(new Set),l=b=>{o(y=>{const g=new Set(y);return g.has(b)?g.delete(b):g.add(b),g})},c=b=>{i(`/project/${r}/session/${Kr()}?agent=${encodeURIComponent(b)}`)},u=b=>{s(r,b)},h=ame(t),O=h.filter(b=>!b.optional).length,p=h.filter(b=>!b.optional&&b.exists).length;return d.jsxs("div",{role:"region","aria-label":n("document.statusTitle"),className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5",children:[d.jsxs("div",{className:"flex items-center justify-between mb-4",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Fa,{className:"w-5 h-5 text-gray-600 dark:text-gray-300"}),d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:n("document.statusTitle")})]}),O>0&&d.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-[#253040] text-gray-500 dark:text-gray-300",children:n("document.requiredCount",{done:p,total:O})})]}),d.jsxs("div",{className:"space-y-1 text-sm",children:[h.map(b=>d.jsx(ome,{doc:b,isDocExpanded:a.has(b.key),toggleDoc:l,handleOpenDoc:u,handleCreateDoc:c,expandedDocs:a,t:n},b.key)),e.length>0&&d.jsxs("div",{className:"border-t border-gray-200 dark:border-[#253040] mt-2 pt-2 space-y-1",children:[d.jsx("p",{className:"text-[11px] uppercase tracking-wider font-medium text-gray-500 dark:text-gray-400 mb-1",children:n("document.deliverables")}),e.map(b=>{const y=b.files&&b.files.length>0,g=a.has(`aux-${b.type}`);return d.jsxs("div",{children:[d.jsxs("div",{className:"flex items-center gap-2 py-1 px-2 -mx-2 rounded-md",children:[d.jsx(Ns,{className:"w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0"}),y?d.jsxs("button",{onClick:()=>l(`aux-${b.type}`),className:"text-gray-700 dark:text-gray-200 hover:underline cursor-pointer inline-flex items-center gap-1",children:[h2(b.type,n),d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${g?"rotate-180":""}`})]}):d.jsx("span",{className:"text-gray-700 dark:text-gray-200",children:h2(b.type,n)}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("document.count",{count:b.fileCount})})]}),g&&y&&d.jsx("div",{className:"mt-1 ml-6",children:d.jsx(tk,{entries:b.files,basePath:b.path,onOpenFile:u,expandedDocs:a,toggleDoc:l,keyPrefix:`aux-${b.type}`})})]},b.type)})]})]})]})}const cme={Done:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300",Draft:"bg-gray-100 dark:bg-[#253040] text-gray-600 dark:text-gray-200",Approved:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300","In Progress":"bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300",Blocked:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"};function dme(t){return t>=100?"bg-green-500 dark:bg-green-400":t>=50?"bg-blue-500 dark:bg-blue-400":t>0?"bg-amber-500 dark:bg-amber-400":"bg-gray-300 dark:bg-gray-600"}function ume(t){return cme[t]??"bg-gray-100 dark:bg-[#253040] text-gray-600 dark:text-gray-200"}function hme({epics:t,projectSlug:e,storyBasePath:r}){const{t:n}=Ce("common"),[i,s]=k.useState(new Set),a=bn(c=>c.requestFileNavigation),o=c=>{!e||!r||a(e,`${r}/${c}`)},l=c=>{s(u=>{const h=new Set(u);return h.has(c)?h.delete(c):h.add(c),h})};return d.jsxs("div",{role:"region","aria-label":n("epic.progressTitle"),className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[d.jsx(ite,{className:"w-5 h-5 text-gray-600 dark:text-gray-300"}),d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:n("epic.progressTitle")})]}),d.jsxs("div",{className:"space-y-3 text-sm",children:[t.map(c=>{const u=c.stories.filter(x=>x.status==="Done").length,h=c.stories.length,O=c.plannedStories??h,p=Math.max(O,h),b=p>0?u/p*100:0,y=i.has(c.number),g=h>0||O>0;return d.jsxs("div",{className:"group",children:[g?d.jsxs("div",{onClick:()=>l(c.number),className:"flex items-center justify-between hover:bg-gray-100 dark:hover:bg-[#253040]/50 rounded-md transition-colors cursor-pointer px-2 py-1.5 -mx-2",children:[d.jsx("span",{className:"text-gray-700 dark:text-gray-200 truncate mr-2",children:typeof c.number=="string"?c.name:d.jsxs(d.Fragment,{children:[c.number,". ",c.name]})}),d.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d.jsxs("span",{className:`text-xs font-medium ${b>=100?"text-green-600 dark:text-green-400":"text-gray-500 dark:text-gray-300"}`,children:[u,"/",O]}),d.jsx(Xn,{className:`w-4 h-4 text-gray-500 dark:text-gray-400 transition-transform ${y?"rotate-180":""}`})]})]}):d.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 -mx-2",children:[d.jsx("span",{className:"text-gray-700 dark:text-gray-200 truncate mr-2",children:typeof c.number=="string"?c.name:d.jsxs(d.Fragment,{children:[c.number,". ",c.name]})}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("epic.storiesUndefined")})]}),p>0&&d.jsx("div",{className:"h-2 bg-gray-200 dark:bg-[#253040] rounded-full overflow-hidden mt-1 mx-0",children:d.jsx("div",{className:`h-full rounded-full transition-all ${dme(b)}`,style:{width:`${b}%`}})}),y&&g&&d.jsxs("div",{className:"mt-2 ml-4 space-y-1",children:[h>0?c.stories.map(x=>{var _,$;const v=((_=x.file.match(/^(?:BE-)?(\d+\.\d+)/))==null?void 0:_[1])??(($=x.file.match(/^BS-(\d+)/))==null?void 0:$[1])??null,w=x.file.startsWith("BE-")?"BE-":x.file.startsWith("BS-")?"BS-":"",Q=x.title?`${w}${v??""}${v?". ":""}${x.title}`:x.file;return d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[d.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate",children:Q}),e&&r&&d.jsx("button",{onClick:()=>o(x.file),className:"flex-shrink-0 text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer",title:x.file,children:d.jsx(Fa,{className:"w-3.5 h-3.5"})})]}),d.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${ume(x.status)}`,children:x.status})]},x.file)}):d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("epic.plannedStoriesNoFiles",{count:O})}),h>0&&O>h&&d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:n("epic.unwrittenStories",{count:O-h})})]})]},c.number)}),t.length===0&&d.jsx("p",{className:"text-gray-500 dark:text-gray-300",children:n("epic.noEpics")})]})]})}function fme(t,e){return t.find(r=>r.key===e)}function Ku(t,e){var r;return((r=fme(t,e))==null?void 0:r.exists)??!1}function r0(t){return t.epics.flatMap(e=>e.stories)}function hy(t,...e){for(const r of t.epics){const n=r.stories.find(i=>e.includes(i.status));if(n)return n}}function d3(t,e){return t.epics.reduce((r,n)=>r+n.stories.filter(i=>i.status===e).length,0)}function fl(t){var e;return((e=t.match(/^(\d+\.\d+)/))==null?void 0:e[1])??t}function Ome(t){const e=r0(t);if(e.length===0){const s=t.epics[0];return s?`${s.number}.1`:"1.1"}let r=0,n=0;for(const s of e){const a=s.file.match(/^(\d+)\.(\d+)/);if(a){const o=parseInt(a[1],10),l=parseInt(a[2],10);(o>r||o===r&&l>n)&&(r=o,n=l)}}const i=t.epics.find(s=>s.number===r);if(i){const s=i.stories.length,a=i.plannedStories??s;if(s>=a){const o=t.epics.map(l=>typeof l.number=="number"?l.number:parseInt(String(l.number),10)).filter(l=>!isNaN(l)&&l>r).sort((l,c)=>l-c);if(o.length>0)return`${o[0]}.1`}}return`${r}.${n+1}`}function pme(t){if(!t.documents.prd.exists)return{phase:"pre-prd",label:we.t("common:phase.prePrd")};if(!t.documents.architecture.exists)return{phase:"pre-architecture",label:we.t("common:phase.preArchitecture")};const e=r0(t),r=t.epics.reduce((i,s)=>i+(s.plannedStories??s.stories.length),0),n=e.filter(i=>i.status!=="Done");return e.length>0&&n.length===0&&r<=e.length?{phase:"completed",label:we.t("common:phase.completed")}:{phase:"implementation",label:we.t("common:phase.implementation")}}function mme(t){const e=t.documents.supplementary,r=[],n=Ku(e,"brainstorming"),i=Ku(e,"brief"),s=i?"primary":"secondary";return n||r.push({id:"brainstorming",title:we.t("common:rec.brainstorming"),description:we.t("common:rec.brainstormingDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*brainstorm",variant:"primary",iconKey:"lightbulb"}),i||r.push({id:"brief",title:we.t("common:rec.projectBrief"),description:we.t("common:rec.projectBriefDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*create-project-brief",variant:"primary",iconKey:"clipboard"}),r.push({id:"create-prd",title:we.t("common:rec.createPrd"),description:we.t("common:rec.createPrdDesc"),agentCommand:"/BMad:agents:pm",taskCommand:"*create-prd",variant:s,iconKey:"file-text"}),Ku(e,"market-research")||r.push({id:"market-research",title:we.t("common:rec.marketResearch"),description:we.t("common:rec.marketResearchDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*perform-market-research",variant:"secondary",iconKey:"search"}),Ku(e,"competitor-analysis")||r.push({id:"competitor-analysis",title:we.t("common:rec.competitorAnalysis"),description:we.t("common:rec.competitorAnalysisDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*create-competitor-analysis",variant:"secondary",iconKey:"users"}),r}function gme(t){const e=t.documents.supplementary,r=[],n=Ku(e,"front-end-spec");return r.push({id:"create-backend-arch",title:we.t("common:rec.backendArch"),description:we.t("common:rec.backendArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-backend-architecture",variant:"primary",iconKey:"blocks"}),n&&r.push({id:"create-frontend-arch",title:we.t("common:rec.feArch"),description:we.t("common:rec.feArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-front-end-architecture",variant:"primary",iconKey:"layout"}),r.push({id:"create-fullstack-arch",title:we.t("common:rec.fullstackArch"),description:we.t("common:rec.fullstackArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-full-stack-architecture",variant:"primary",iconKey:"blocks"}),n||r.push({id:"fe-spec",title:we.t("common:rec.feSpec"),description:we.t("common:rec.feSpecDesc"),agentCommand:"/BMad:agents:ux-expert",taskCommand:"*create-front-end-spec",variant:"secondary",iconKey:"palette"}),r}function Op(t,...e){const r=["Review","Ready for Review","Ready for Done"];for(const n of t.epics){const i=n.stories.find(s=>r.includes(s.status)&&e.includes(s.gateResult));if(i)return i}}function bme(t){const e=[],r=Op(t,"PASS","WAIVED"),n=Op(t,"FIXED"),i=Op(t,"FAIL","CONCERNS"),s=Op(t,void 0),a=hy(t,"In Progress","InProgress"),o=hy(t,"Approved"),l=hy(t,"Draft"),c=r0(t),u=t.epics.reduce((y,g)=>y+(g.plannedStories??g.stories.length),0),h=d3(t,"Done"),O=c.filter(y=>y.status!=="Done");if(r){const y=fl(r.file),g=r.title?`${y}. ${r.title}`:r.file;e.push({id:"commit-and-mark-done",title:we.t("common:rec.commitAndMarkDone"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`Please review the current changes with git diff, commit only the files related to story ${y}, then update the story status to Done.`,variant:"primary",iconKey:"git-commit",storyFile:r.file}),e.push({id:"mark-done",title:we.t("common:rec.markDone"),description:we.t("common:rec.markDoneDesc"),agentCommand:"/BMad:agents:dev",taskCommand:`Update story ${y} status to Done. The QA gate has passed.`,variant:"secondary",iconKey:"check-circle",storyFile:r.file}),e.push({id:"request-qa-review",title:we.t("common:rec.requestQAReview"),description:g,agentCommand:"/BMad:agents:qa",taskCommand:`*review ${y}`,variant:"secondary",iconKey:"rotate-ccw",storyFile:r.file})}if(n){const y=fl(n.file),g=n.title?`${y}. ${n.title}`:n.file,x=e.length>0;e.push({id:"review-fixed",title:we.t("common:rec.qaReview"),description:we.t("common:rec.qaReviewDesc",{label:g}),agentCommand:"/BMad:agents:qa",taskCommand:`*review ${y}`,variant:x?"secondary":"primary",iconKey:"check-circle",storyFile:n.file})}if(i){const y=fl(i.file),g=i.title?`${y}. ${i.title}`:i.file,x=e.length>0;e.push({id:"review-apply-fixes",title:we.t("common:rec.applyQaFixes"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`*review-qa ${y}
790
+ }`,{label:"if",detail:"/ else block",type:"keyword"}),Dt('import ${name} "${module}"\n${}',{label:"import",detail:"declaration",type:"keyword"})],c2=new Ig,s3=new Set(["SourceFile","Block","FunctionDecl","MethodDecl","FunctionLiteral","ForStatement","SwitchStatement","TypeSwitchStatement","IfStatement"]);function Ec(t,e){return(r,n)=>{e:for(let i=r.node.firstChild,s=0,a=null;;){for(;!i;){if(!s)break e;s--,i=a.nextSibling,a=a.parent}e&&i.name==e||i.name=="SpecList"?(s++,a=i,i=i.firstChild):(i.name=="DefName"&&n(i,t),i=i.nextSibling)}return!0}}const Gpe={FunctionDecl:Ec("function"),VarDecl:Ec("var","VarSpec"),ConstDecl:Ec("constant","ConstSpec"),TypeDecl:Ec("type","TypeSpec"),ImportDecl:Ec("constant","ImportSpec"),Parameter:Ec("var"),__proto__:null};function a3(t,e){let r=c2.get(e);if(r)return r;let n=[],i=!0;function s(a,o){let l=t.sliceString(a.from,a.to);n.push({label:l,type:o})}return e.cursor(Jt.IncludeAnonymous).iterate(a=>{if(i)i=!1;else if(a.name){let o=Gpe[a.name];if(o&&o(a,s)||s3.has(a.name))return!1}else if(a.to-a.from>8192){for(let o of a3(t,a.node))n.push(o);return!1}}),c2.set(e,n),n}const d2=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,o3=["String","LineComment","BlockComment","DefName","LabelName","FieldName",".","?."],Hpe=t=>{let e=mr(t.state).resolveInner(t.pos,-1);if(o3.indexOf(e.name)>-1)return null;let r=e.name=="VariableName"||e.to-e.from<20&&d2.test(t.state.sliceDoc(e.from,e.to));if(!r&&!t.explicit)return null;let n=[];for(let i=e;i;i=i.parent)s3.has(i.name)&&(n=n.concat(a3(t.state.doc,i)));return{options:n,from:r?e.from:t.pos,validFor:d2}},uy=Ni.define({name:"go",parser:Bpe.configure({props:[ps.add({IfStatement:Rn({except:/^\s*({|else\b)/}),LabeledStatement:Gg,"SwitchBlock SelectBlock":t=>{let e=t.textAfter,r=/^\s*\}/.test(e),n=/^\s*(case|default)\b/.test(e);return t.baseIndent+(r||n?0:t.unit)},Block:Va({closing:"}"}),BlockComment:()=>null,Statement:Rn({except:/^{/})}),Mi.add({"Block SwitchBlock SelectBlock LiteralValue InterfaceType StructType SpecList":to,BlockComment(t){return{from:t.from+2,to:t.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case\b|default\b|\})$/}});let Kpe=t=>({label:t,type:"keyword"});const Jpe="interface struct chan map package go return break continue goto fallthrough else defer range true false nil".split(" ").map(Kpe);function eme(){let t=Fpe.concat(Jpe);return new us(uy,[uy.data.of({autocomplete:Rw(o3,Kg(t))}),uy.data.of({autocomplete:Hpe})])}const tme={".ts":()=>Hu({typescript:!0}),".tsx":()=>Hu({typescript:!0,jsx:!0}),".js":()=>Hu(),".jsx":()=>Hu({jsx:!0}),".json":()=>vde(),".md":()=>jhe(),".html":()=>A4(),".css":()=>_4(),".py":()=>Jfe(),".go":()=>eme(),".rs":()=>yOe(),".java":()=>QOe(),".c":()=>cy(),".cpp":()=>cy(),".h":()=>cy(),".yaml":()=>o2(),".yml":()=>o2()};function l3(t){const e=t.lastIndexOf(".");if(e===-1)return null;const r=t.slice(e).toLowerCase(),n=tme[r];return n?n():null}function c3(t){return t.toLowerCase().endsWith(".md")}const rme=new Set([".png",".jpg",".jpeg",".gif",".svg",".webp",".bmp",".ico"]);function qo(t){const e=t.lastIndexOf(".");return e===-1?!1:rme.has(t.slice(e).toLowerCase())}const u2={openFile:null,content:"",originalContent:"",isDirty:!1,isLoading:!1,isSaving:!1,isTruncated:!1,isMarkdownPreview:!1,error:null,pendingNavigation:null,targetLine:null,recentFiles:{}},bn=Zn((t,e)=>({...u2,openFileInEditor:async(r,n,i)=>{const s=c3(n)&&Ht.getState().preferences.markdownDefaultMode==="preview";t({openFile:{projectSlug:r,path:n},isLoading:!0,error:null,isTruncated:!1,isMarkdownPreview:s,content:"",originalContent:"",isDirty:!1,targetLine:i??null});try{const a=await ni.readFile(r,n);if(a.isBinary){t({error:we.t("notification:file.binaryNotEditable"),isLoading:!1});return}const o=a.content??"";t({content:o,originalContent:o,isLoading:!1,isTruncated:a.isTruncated})}catch(a){t({error:a.message,isLoading:!1})}},saveFile:async()=>{const{openFile:r,content:n}=e();if(!r)return!1;t({isSaving:!0});try{return await ni.writeFile(r.projectSlug,r.path,n),t({originalContent:n,isDirty:!1,isSaving:!1}),!0}catch{return t({isSaving:!1}),!1}},requestFileNavigation:(r,n,i)=>{e().isDirty?t({pendingNavigation:{projectSlug:r,path:n,targetLine:i}}):e().openFileInEditor(r,n,i)},confirmPendingNavigation:()=>{const{pendingNavigation:r}=e();r&&(t({pendingNavigation:null}),e().openFileInEditor(r.projectSlug,r.path,r.targetLine))},cancelPendingNavigation:()=>{t({pendingNavigation:null})},closeEditor:()=>{const{recentFiles:r}=e();t({...u2,recentFiles:r})},setContent:r=>{t({content:r,isDirty:r!==e().originalContent})},resetError:()=>t({error:null}),toggleMarkdownPreview:()=>{t({isMarkdownPreview:!e().isMarkdownPreview})},addRecentFile:(r,n)=>{const s=(e().recentFiles[r]??[]).filter(o=>o!==n),a=[n,...s].slice(0,5);t({recentFiles:{...e().recentFiles,[r]:a}})}})),nme={stories:"document.stories",qa:"document.qa"};function h2(t,e){const r=nme[t];return r?e(r):t}const fp={brainstorming:"/BMad:agents:analyst","market-research":"/BMad:agents:analyst","competitor-analysis":"/BMad:agents:analyst",brief:"/BMad:agents:analyst",prd:"/BMad:agents:pm","front-end-spec":"/BMad:agents:ux-expert",architecture:"/BMad:agents:architect","ui-architecture":"/BMad:agents:architect"},ime=new Set(["brainstorming","brief"]),sme=new Set(["prd","architecture"]);function ame(t){const e=new Map;for(const s of t.supplementary??[])e.set(s.key,s);const r=["brainstorming","market-research","competitor-analysis","brief"],n=["front-end-spec","ui-architecture"],i=[];for(const s of r){const a=e.get(s);a&&i.push({key:a.key,label:a.label,exists:a.exists,path:a.path,optional:!0,agentCommand:fp[a.key],recommended:!t.prd.exists&&ime.has(a.key)})}i.push({key:"prd",label:"PRD",exists:t.prd.exists,path:t.prd.path,agentCommand:fp.prd,sharded:t.prd.sharded,shardedPath:t.prd.shardedPath,shardedFiles:t.prd.shardedFiles});for(const s of n){const a=e.get(s);a&&i.push({key:a.key,label:a.label,exists:a.exists,path:a.path,optional:!0,agentCommand:fp[a.key]})}return i.push({key:"architecture",label:"Architecture",exists:t.architecture.exists,path:t.architecture.path,agentCommand:fp.architecture,sharded:t.architecture.sharded,shardedPath:t.architecture.shardedPath,shardedFiles:t.architecture.shardedFiles}),i}function tk({entries:t,basePath:e,onOpenFile:r,expandedDocs:n,toggleDoc:i,keyPrefix:s}){return d.jsx("div",{className:"space-y-0.5",children:t.map(a=>{const o=`${s}/${a.name}`;if(a.isDir&&a.children){const l=n.has(o);return d.jsxs("div",{children:[d.jsxs("button",{onClick:()=>i(o),className:"text-xs text-gray-600 dark:text-gray-300 hover:underline cursor-pointer inline-flex items-center gap-1",children:[a.name,"/",d.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[a.children.length,"개"]}),d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${l?"rotate-180":""}`})]}),l&&d.jsx("div",{className:"mt-0.5 ml-4",children:d.jsx(tk,{entries:a.children,basePath:e?`${e}/${a.name}`:a.name,onOpenFile:r,expandedDocs:n,toggleDoc:i,keyPrefix:o})})]},a.name)}return d.jsx("button",{onClick:()=>r(e?`${e}/${a.name}`:a.name),className:"block text-xs text-left text-gray-600 dark:text-gray-300 hover:underline cursor-pointer",children:a.name},a.name)})})}function ome({doc:t,isDocExpanded:e,toggleDoc:r,handleOpenDoc:n,handleCreateDoc:i,expandedDocs:s,t:a}){const o=t.sharded&&t.shardedFiles&&t.shardedFiles.length>0,l=sme.has(t.key);return d.jsxs("div",{children:[d.jsxs("div",{className:`flex items-center gap-2 py-1 px-2 -mx-2 rounded-md transition-colors ${l?"bg-gray-100/50 dark:bg-[#253040]/30":""}`,children:[t.exists?d.jsx(As,{className:`w-4 h-4 flex-shrink-0 ${t.optional?"text-green-400 dark:text-green-600":"text-green-600 dark:text-green-400"}`}):t.optional?d.jsx(rj,{className:"w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0"}):d.jsx(Ao,{className:"w-4 h-4 text-red-600 dark:text-red-400 flex-shrink-0"}),t.exists&&o?d.jsxs("button",{onClick:()=>r(t.key),className:"font-semibold text-gray-900 dark:text-white hover:underline cursor-pointer inline-flex items-center gap-1",children:[t.label,d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${e?"rotate-180":""}`})]}):d.jsx("span",{className:t.exists?t.optional?"text-gray-700 dark:text-gray-200":"font-semibold text-gray-900 dark:text-white":t.optional?"text-gray-500 dark:text-gray-400":"font-semibold text-gray-900 dark:text-gray-100",children:t.label}),o&&d.jsx("span",{className:"text-xs px-1.5 py-0.5 bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded",children:a("document.sharded")}),d.jsx("span",{className:"flex-1"}),!o&&t.exists&&d.jsx("button",{onClick:()=>n(t.path),className:"text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:underline cursor-pointer truncate max-w-[50%]",children:t.path}),!t.exists&&!t.optional&&d.jsx("span",{className:"text-xs px-2 py-0.5 bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300 rounded-full",children:a("document.writeRequired")}),!t.exists&&t.recommended&&d.jsx("span",{className:"text-xs px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 rounded-full",children:a("document.writeRecommended")}),!t.exists&&t.agentCommand&&d.jsx("button",{onClick:()=>i(t.agentCommand),className:`p-0.5 rounded transition-colors cursor-pointer ${!t.optional||t.recommended?"bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-900/50":"bg-gray-100 dark:bg-[#253040]/50 text-gray-400 dark:text-gray-500 hover:bg-gray-200 dark:hover:bg-[#253040] hover:text-gray-500 dark:hover:text-gray-400"}`,title:a("document.writeGo"),children:d.jsx(Yee,{className:"w-3.5 h-3.5"})})]}),e&&o&&d.jsxs("div",{className:"mt-1 ml-6 space-y-1",children:[d.jsx("button",{onClick:()=>n(t.path),className:"block text-xs text-left text-gray-600 dark:text-gray-300 hover:underline cursor-pointer",children:t.path}),d.jsx(tk,{entries:[{name:`${t.shardedPath}`,isDir:!0,children:t.shardedFiles}],basePath:"",onOpenFile:n,expandedDocs:s,toggleDoc:r,keyPrefix:t.key})]})]})}function lme({documents:t,auxiliaryDocuments:e,projectSlug:r}){const{t:n}=Ce("common"),i=En(),s=bn(b=>b.requestFileNavigation),[a,o]=k.useState(new Set),l=b=>{o(y=>{const g=new Set(y);return g.has(b)?g.delete(b):g.add(b),g})},c=b=>{i(`/project/${r}/session/${Kr()}?agent=${encodeURIComponent(b)}`)},u=b=>{s(r,b)},h=ame(t),O=h.filter(b=>!b.optional).length,p=h.filter(b=>!b.optional&&b.exists).length;return d.jsxs("div",{role:"region","aria-label":n("document.statusTitle"),className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5",children:[d.jsxs("div",{className:"flex items-center justify-between mb-4",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Fa,{className:"w-5 h-5 text-gray-600 dark:text-gray-300"}),d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:n("document.statusTitle")})]}),O>0&&d.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-[#253040] text-gray-500 dark:text-gray-300",children:n("document.requiredCount",{done:p,total:O})})]}),d.jsxs("div",{className:"space-y-1 text-sm",children:[h.map(b=>d.jsx(ome,{doc:b,isDocExpanded:a.has(b.key),toggleDoc:l,handleOpenDoc:u,handleCreateDoc:c,expandedDocs:a,t:n},b.key)),e.length>0&&d.jsxs("div",{className:"border-t border-gray-200 dark:border-[#253040] mt-2 pt-2 space-y-1",children:[d.jsx("p",{className:"text-[11px] uppercase tracking-wider font-medium text-gray-500 dark:text-gray-400 mb-1",children:n("document.deliverables")}),e.map(b=>{const y=b.files&&b.files.length>0,g=a.has(`aux-${b.type}`);return d.jsxs("div",{children:[d.jsxs("div",{className:"flex items-center gap-2 py-1 px-2 -mx-2 rounded-md",children:[d.jsx(Ns,{className:"w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0"}),y?d.jsxs("button",{onClick:()=>l(`aux-${b.type}`),className:"text-gray-700 dark:text-gray-200 hover:underline cursor-pointer inline-flex items-center gap-1",children:[h2(b.type,n),d.jsx(Xn,{className:`w-3 h-3 text-gray-500 dark:text-gray-400 transition-transform ${g?"rotate-180":""}`})]}):d.jsx("span",{className:"text-gray-700 dark:text-gray-200",children:h2(b.type,n)}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("document.count",{count:b.fileCount})})]}),g&&y&&d.jsx("div",{className:"mt-1 ml-6",children:d.jsx(tk,{entries:b.files,basePath:b.path,onOpenFile:u,expandedDocs:a,toggleDoc:l,keyPrefix:`aux-${b.type}`})})]},b.type)})]})]})]})}const cme={Done:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300",Draft:"bg-gray-100 dark:bg-[#253040] text-gray-600 dark:text-gray-200",Approved:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300","In Progress":"bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300",Blocked:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"};function dme(t){return t>=100?"bg-green-500 dark:bg-green-400":t>=50?"bg-blue-500 dark:bg-blue-400":t>0?"bg-amber-500 dark:bg-amber-400":"bg-gray-300 dark:bg-gray-600"}function ume(t){return cme[t]??"bg-gray-100 dark:bg-[#253040] text-gray-600 dark:text-gray-200"}function hme({epics:t,projectSlug:e,storyBasePath:r}){const{t:n}=Ce("common"),[i,s]=k.useState(new Set),a=bn(c=>c.requestFileNavigation),o=c=>{!e||!r||a(e,`${r}/${c}`)},l=c=>{s(u=>{const h=new Set(u);return h.has(c)?h.delete(c):h.add(c),h})};return d.jsxs("div",{role:"region","aria-label":n("epic.progressTitle"),className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[d.jsx(ite,{className:"w-5 h-5 text-gray-600 dark:text-gray-300"}),d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:n("epic.progressTitle")})]}),d.jsxs("div",{className:"space-y-3 text-sm",children:[t.map(c=>{const u=c.stories.filter(x=>x.status==="Done").length,h=c.stories.length,O=c.plannedStories??h,p=Math.max(O,h),b=p>0?u/p*100:0,y=i.has(c.number),g=h>0||O>0;return d.jsxs("div",{className:"group",children:[g?d.jsxs("div",{onClick:()=>l(c.number),className:"flex items-center justify-between hover:bg-gray-100 dark:hover:bg-[#253040]/50 rounded-md transition-colors cursor-pointer px-2 py-1.5 -mx-2",children:[d.jsx("span",{className:"text-gray-700 dark:text-gray-200 truncate mr-2",children:typeof c.number=="string"?c.name:d.jsxs(d.Fragment,{children:[c.number,". ",c.name]})}),d.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d.jsxs("span",{className:`text-xs font-medium ${b>=100?"text-green-600 dark:text-green-400":"text-gray-500 dark:text-gray-300"}`,children:[u,"/",O]}),d.jsx(Xn,{className:`w-4 h-4 text-gray-500 dark:text-gray-400 transition-transform ${y?"rotate-180":""}`})]})]}):d.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 -mx-2",children:[d.jsx("span",{className:"text-gray-700 dark:text-gray-200 truncate mr-2",children:typeof c.number=="string"?c.name:d.jsxs(d.Fragment,{children:[c.number,". ",c.name]})}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("epic.storiesUndefined")})]}),p>0&&d.jsx("div",{className:"h-2 bg-gray-200 dark:bg-[#253040] rounded-full overflow-hidden mt-1 mx-0",children:d.jsx("div",{className:`h-full rounded-full transition-all ${dme(b)}`,style:{width:`${b}%`}})}),y&&g&&d.jsxs("div",{className:"mt-2 ml-4 space-y-1",children:[h>0?c.stories.map(x=>{var _,$;const v=((_=x.file.match(/^(?:BE-)?(\d+\.\d+)/))==null?void 0:_[1])??(($=x.file.match(/^BS-(\d+)/))==null?void 0:$[1])??null,w=x.file.startsWith("BE-")?"BE-":x.file.startsWith("BS-")?"BS-":"",Q=x.title?`${w}${v??""}${v?". ":""}${x.title}`:x.file;return d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[d.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-300 truncate",children:Q}),e&&r&&d.jsx("button",{onClick:()=>o(x.file),className:"flex-shrink-0 text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer",title:x.file,children:d.jsx(Fa,{className:"w-3.5 h-3.5"})})]}),d.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${ume(x.status)}`,children:x.status})]},x.file)}):d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("epic.plannedStoriesNoFiles",{count:O})}),h>0&&O>h&&d.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:n("epic.unwrittenStories",{count:O-h})})]})]},c.number)}),t.length===0&&d.jsx("p",{className:"text-gray-500 dark:text-gray-300",children:n("epic.noEpics")})]})]})}function fme(t,e){return t.find(r=>r.key===e)}function Ku(t,e){var r;return((r=fme(t,e))==null?void 0:r.exists)??!1}function r0(t){return t.epics.flatMap(e=>e.stories)}function hy(t,...e){for(const r of t.epics){const n=r.stories.find(i=>e.includes(i.status));if(n)return n}}function d3(t,e){return t.epics.reduce((r,n)=>r+n.stories.filter(i=>i.status===e).length,0)}function fl(t){var e;return((e=t.match(/^(\d+\.\d+)/))==null?void 0:e[1])??t}function Ome(t){const e=r0(t);if(e.length===0){const s=t.epics[0];return s?`${s.number}.1`:"1.1"}let r=0,n=0;for(const s of e){const a=s.file.match(/^(\d+)\.(\d+)/);if(a){const o=parseInt(a[1],10),l=parseInt(a[2],10);(o>r||o===r&&l>n)&&(r=o,n=l)}}const i=t.epics.find(s=>s.number===r);if(i){const s=i.stories.length,a=i.plannedStories??s;if(s>=a){const o=t.epics.map(l=>typeof l.number=="number"?l.number:parseInt(String(l.number),10)).filter(l=>!isNaN(l)&&l>r).sort((l,c)=>l-c);if(o.length>0)return`${o[0]}.1`}}return`${r}.${n+1}`}function pme(t){if(!t.documents.prd.exists)return{phase:"pre-prd",label:we.t("common:phase.prePrd")};if(!t.documents.architecture.exists)return{phase:"pre-architecture",label:we.t("common:phase.preArchitecture")};const e=r0(t),r=t.epics.reduce((i,s)=>i+(s.plannedStories??s.stories.length),0),n=e.filter(i=>i.status!=="Done");return e.length>0&&n.length===0&&r<=e.length?{phase:"completed",label:we.t("common:phase.completed")}:{phase:"implementation",label:we.t("common:phase.implementation")}}function mme(t){const e=t.documents.supplementary,r=[],n=Ku(e,"brainstorming"),i=Ku(e,"brief"),s=i?"primary":"secondary";return n||r.push({id:"brainstorming",title:we.t("common:rec.brainstorming"),description:we.t("common:rec.brainstormingDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*brainstorm",variant:"primary",iconKey:"lightbulb"}),i||r.push({id:"brief",title:we.t("common:rec.projectBrief"),description:we.t("common:rec.projectBriefDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*create-project-brief",variant:"primary",iconKey:"clipboard"}),r.push({id:"create-prd",title:we.t("common:rec.createPrd"),description:we.t("common:rec.createPrdDesc"),agentCommand:"/BMad:agents:pm",taskCommand:"*create-prd",variant:s,iconKey:"file-text"}),Ku(e,"market-research")||r.push({id:"market-research",title:we.t("common:rec.marketResearch"),description:we.t("common:rec.marketResearchDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*perform-market-research",variant:"secondary",iconKey:"search"}),Ku(e,"competitor-analysis")||r.push({id:"competitor-analysis",title:we.t("common:rec.competitorAnalysis"),description:we.t("common:rec.competitorAnalysisDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*create-competitor-analysis",variant:"secondary",iconKey:"users"}),r}function gme(t){const e=t.documents.supplementary,r=[],n=Ku(e,"front-end-spec");return r.push({id:"create-backend-arch",title:we.t("common:rec.backendArch"),description:we.t("common:rec.backendArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-backend-architecture",variant:"primary",iconKey:"blocks"}),n&&r.push({id:"create-frontend-arch",title:we.t("common:rec.feArch"),description:we.t("common:rec.feArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-front-end-architecture",variant:"primary",iconKey:"layout"}),r.push({id:"create-fullstack-arch",title:we.t("common:rec.fullstackArch"),description:we.t("common:rec.fullstackArchDesc"),agentCommand:"/BMad:agents:architect",taskCommand:"*create-full-stack-architecture",variant:"primary",iconKey:"blocks"}),n||r.push({id:"fe-spec",title:we.t("common:rec.feSpec"),description:we.t("common:rec.feSpecDesc"),agentCommand:"/BMad:agents:ux-expert",taskCommand:"*create-front-end-spec",variant:"secondary",iconKey:"palette"}),r}function Op(t,...e){const r=["Review","Ready for Review","Ready for Done"];for(const n of t.epics){const i=n.stories.find(s=>r.includes(s.status)&&e.includes(s.gateResult));if(i)return i}}function bme(t){const e=[],r=Op(t,"PASS","WAIVED"),n=Op(t,"FIXED"),i=Op(t,"FAIL","CONCERNS"),s=Op(t,void 0),a=hy(t,"In Progress","InProgress"),o=hy(t,"Approved"),l=hy(t,"Draft"),c=r0(t),u=t.epics.reduce((y,g)=>y+(g.plannedStories??g.stories.length),0),h=d3(t,"Done"),O=c.filter(y=>y.status!=="Done");if(r){const y=fl(r.file),g=r.title?`${y}. ${r.title}`:r.file;e.push({id:"commit-and-mark-done",title:we.t("common:rec.commitAndMarkDone"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`Please review the current changes with git diff, commit only the files related to story ${y}, then update the story status to Done.`,variant:"primary",iconKey:"git-commit",storyFile:r.file}),e.push({id:"mark-done",title:we.t("common:rec.markDone"),description:we.t("common:rec.markDoneDesc"),agentCommand:"/BMad:agents:dev",taskCommand:`Update story ${y} status to Done. The QA gate has passed.`,variant:"secondary",iconKey:"check-circle",storyFile:r.file}),e.push({id:"request-qa-review",title:we.t("common:rec.requestQAReview"),description:g,agentCommand:"/BMad:agents:qa",taskCommand:`*review ${y}`,variant:"secondary",iconKey:"rotate-ccw",storyFile:r.file})}if(n){const y=fl(n.file),g=n.title?`${y}. ${n.title}`:n.file,x=e.length>0;e.push({id:"review-fixed",title:we.t("common:rec.qaReview"),description:we.t("common:rec.qaReviewDesc",{label:g}),agentCommand:"/BMad:agents:qa",taskCommand:`*review ${y}`,variant:x?"secondary":"primary",iconKey:"check-circle",storyFile:n.file})}if(i){const y=fl(i.file),g=i.title?`${y}. ${i.title}`:i.file,x=e.length>0;e.push({id:"review-apply-fixes",title:we.t("common:rec.applyQaFixes"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`*review-qa ${y}
791
791
 
792
792
  ${we.t("board:workflow.resolveGateOutro")}`,variant:x?"secondary":"primary",iconKey:"wrench",storyFile:i.file})}if(s){const y=fl(s.file),g=s.title?`${y}. ${s.title}`:s.file,x=e.length>0;e.push({id:"review-story",title:we.t("common:rec.qaReview"),description:we.t("common:rec.qaReviewDesc",{label:g}),agentCommand:"/BMad:agents:qa",taskCommand:`*review ${y}`,variant:x?"secondary":"primary",iconKey:"check-circle",storyFile:s.file})}if(a){const y=fl(a.file),g=a.title?`${y}. ${a.title}`:a.file,x=e.length>0;e.push({id:"continue-dev",title:we.t("common:rec.continueDev"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`*develop-story ${y}`,variant:x?"secondary":"primary",iconKey:"code",storyFile:a.file})}if(o){const y=fl(o.file),g=o.title?`${y}. ${o.title}`:o.file,x=e.length>0;e.push({id:"start-dev",title:we.t("common:rec.startDev"),description:g,agentCommand:"/BMad:agents:dev",taskCommand:`*develop-story ${y}`,variant:x?"secondary":"primary",iconKey:"play",storyFile:o.file}),e.push({id:"validate-fix-approved-story",title:we.t("common:rec.validateAndFixStory"),description:g,agentCommand:"/BMad:agents:po",taskCommand:`*validate-story-draft ${y}`,variant:"secondary",iconKey:"shield-check",storyFile:o.file,chainPrompts:[we.t("common:rec.validateFixPrompt"),we.t("common:rec.approveAfterFixPrompt")]}),e.push({id:"validate-approved-story",title:we.t("common:rec.validateStoryOnly"),description:g,agentCommand:"/BMad:agents:po",taskCommand:`*validate-story-draft ${y} ${we.t("common:rec.validateOnlyApproveHint")}`,variant:"secondary",iconKey:"shield-check",storyFile:o.file})}if(l){const y=fl(l.file),g=l.title?`${y}. ${l.title}`:l.file,x=e.length>0;e.push({id:"validate-fix-story",title:we.t("common:rec.validateAndFixStory"),description:g,agentCommand:"/BMad:agents:po",taskCommand:`*validate-story-draft ${y}`,variant:x?"secondary":"primary",iconKey:"shield-check",storyFile:l.file,chainPrompts:[we.t("common:rec.validateFixPrompt"),we.t("common:rec.approveAfterFixPrompt")]}),e.push({id:"validate-story",title:we.t("common:rec.validateStoryOnly"),description:g,agentCommand:"/BMad:agents:po",taskCommand:`*validate-story-draft ${y} ${we.t("common:rec.validateOnlyApproveHint")}`,variant:"secondary",iconKey:"shield-check",storyFile:l.file})}const p=e.length>0,b=u>c.length;if(c.length>0&&O.length,O.length===0&&(!p||b)){const y=Ome(t);e.push({id:"create-story",title:c.length===0?we.t("common:rec.createFirstStory"):we.t("common:rec.createNextStory"),description:b?we.t("common:rec.storiesRemaining",{count:u-h}):we.t("common:rec.createStoryDesc"),agentCommand:"/BMad:agents:sm",taskCommand:`*draft ${y}`,variant:p?"secondary":"primary",iconKey:"plus-circle"})}return e}function xme(t){const e=[];return r0(t),d3(t,"Done"),e.push({id:"brainstorm-features",title:we.t("common:rec.newFeatureBrainstorm"),description:we.t("common:rec.newFeatureBrainstormDesc"),agentCommand:"/BMad:agents:analyst",taskCommand:"*brainstorm",variant:"primary",iconKey:"lightbulb"}),e.push({id:"new-epic",title:we.t("common:rec.addNewEpic"),description:we.t("common:rec.addNewEpicDesc"),agentCommand:"/BMad:agents:pm",taskCommand:"*brownfield-create-epic",variant:"primary",iconKey:"plus-circle"}),e.push({id:"add-brownfield-story",title:we.t("common:rec.addStoryToEpic"),description:we.t("common:rec.addStoryToEpicDesc"),agentCommand:"/BMad:agents:sm",taskCommand:"*brownfield-create-story",variant:"secondary",iconKey:"file-text"}),e}function yme(t){const e=pme(t);let r;switch(e.phase){case"pre-prd":r=mme(t);break;case"pre-architecture":r=gme(t);break;case"implementation":r=bme(t);break;case"completed":r=xme(t);break}return{phase:e,recommendations:r}}const ln={getBoard:t=>qe.get(`/projects/${t}/board`),createIssue:(t,e)=>qe.post(`/projects/${t}/board/issues`,e),updateIssue:(t,e,r)=>qe.patch(`/projects/${t}/board/issues/${e}`,r),deleteIssue:(t,e)=>qe.delete(`/projects/${t}/board/issues/${e}`),uploadAttachment:(t,e,r)=>{const n=new FormData;return n.append("file",r),qe.upload(`/projects/${t}/board/issues/${e}/attachments`,n)},deleteAttachment:(t,e,r)=>qe.delete(`/projects/${t}/board/issues/${e}/attachments/${r}`),getAttachmentUrl:(t,e,r)=>`/api/projects/${t}/board/issues/${e}/attachments/${r}`,getNextBrownfieldNum:(t,e)=>qe.get(`/projects/${t}/board/next-brownfield-num?type=${e}`)},vme={"file-text":Fa,lightbulb:bre,search:vd,users:fj,clipboard:nj,blocks:Gee,palette:qre,layout:lj,code:Pte,"check-circle":As,wrench:sw,"shield-check":Wu,play:pf,"plus-circle":pte};function Sme({rec:t,onClick:e}){const r=vme[t.iconKey]??Sm,n=t.variant==="primary";return d.jsxs("button",{onClick:e,className:`w-full flex items-center gap-3 px-4 py-3 rounded-lg transition-colors text-left cursor-pointer ${n?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 hover:bg-blue-100 dark:hover:bg-blue-900/30":"bg-gray-100/80 dark:bg-[#253040]/50 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040]"}`,children:[d.jsx(r,{className:`w-4 h-4 flex-shrink-0 ${n?"text-blue-600 dark:text-blue-400":"text-gray-500 dark:text-gray-400"}`}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsx("span",{className:"text-sm font-medium block",children:t.title}),d.jsx("span",{className:`text-xs block truncate ${n?"text-blue-600/70 dark:text-blue-400/70":"text-gray-500 dark:text-gray-300"}`,children:t.description})]}),d.jsx(Sm,{className:`w-3.5 h-3.5 flex-shrink-0 ${n?"text-blue-400 dark:text-blue-500":"text-gray-400 dark:text-gray-500"}`})]})}function wme({data:t,projectSlug:e}){const{t:r}=Ce("common"),n=En(),{phase:i,recommendations:s}=yme(t),a=async c=>{var O;if(c.id==="start-dev"&&c.storyFile)try{const p=`story-${((O=c.storyFile.match(/^(\d+\.\d+)/))==null?void 0:O[1])??c.storyFile}`;await ln.updateIssue(e,p,{status:"In Progress"})}catch(p){console.warn("Failed to transition story to In Progress:",p)}const u=Kr(),h=new URLSearchParams({agent:c.agentCommand});if(c.taskCommand&&h.set("task",c.taskCommand),c.chainPrompts)for(const p of c.chainPrompts)h.append("chain",p);n(`/project/${e}/session/${u}?${h.toString()}`)},o=()=>{const c=Kr();n(`/project/${e}/session/${c}`)},l=i.phase==="completed";return d.jsxs("div",{className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5",children:[d.jsxs("div",{className:"flex items-center justify-between mb-4",children:[d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:r(l?"nextSteps.title":"nextSteps.tasks")}),d.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full ${l?"bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400":"bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400"}`,children:[l&&d.jsx(Zre,{className:"w-3 h-3 inline-block mr-1 -mt-0.5"}),i.label]})]}),d.jsx("div",{className:"space-y-2",children:s.map(c=>d.jsx(Sme,{rec:c,onClick:()=>a(c)},c.id))}),d.jsxs("div",{className:"mt-4 pt-3 border-t border-gray-200 dark:border-[#253040] flex items-center gap-3",children:[d.jsxs("button",{onClick:o,className:"text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex items-center gap-1 cursor-pointer",children:[d.jsx(kr,{className:"w-3 h-3"}),r("nextSteps.newSession")]}),d.jsx("span",{className:"text-gray-200 dark:text-gray-700",children:"|"}),d.jsxs("button",{onClick:()=>n(`/project/${e}/queue`),className:"text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex items-center gap-1 cursor-pointer",children:[d.jsx(Ag,{className:"w-3 h-3"}),r("nextSteps.queueTask")]}),d.jsx("span",{className:"text-gray-200 dark:text-gray-700",children:"|"}),d.jsxs("button",{onClick:()=>n(`/project/${e}/files`),className:"text-xs text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex items-center gap-1 cursor-pointer",children:[d.jsx(Ns,{className:"w-3 h-3"}),r("nextSteps.fileExplore")]})]})]})}let Ro=null,fy=0;function u3(){Ro&&(clearTimeout(Ro),Ro=null)}function pp(t,e){u3(),t({error:e,isLoading:!1}),Ro=setTimeout(()=>{t({error:null}),Ro=null},5e3)}function mp(t){return t instanceof Jr?t.message:we.t("notification:board.loadError")}function kme(){if(typeof window>"u")return"kanban";const t=localStorage.getItem("bmad-board-viewMode");return t==="kanban"||t==="list"?t:window.matchMedia("(max-width: 767px)").matches?"list":"kanban"}function Qme(){if(typeof window>"u")return 4;const t=localStorage.getItem("bmad-board-visibleColumns");if(t){const e=parseInt(t,10);if(e>=2&&e<=10)return e}return 4}const ei=Zn((t,e)=>({items:[],boardConfig:KP,viewMode:kme(),visibleColumns:Qme(),isLoading:!1,error:null,fetchBoard:async r=>{const n=++fy;t({isLoading:!0,items:[],error:null});try{const i=await ln.getBoard(r);if(n!==fy)return;u3(),t({items:i.items,boardConfig:i.config??KP,isLoading:!1,error:null})}catch(i){if(n!==fy)return;pp(t,mp(i))}},createIssue:async(r,n)=>{t({isLoading:!0});try{const i=await ln.createIssue(r,n);return await e().fetchBoard(r),i}catch(i){throw pp(t,mp(i)),i}},updateIssue:async(r,n,i)=>{t({isLoading:!0});try{await ln.updateIssue(r,n,i),await e().fetchBoard(r)}catch(s){throw pp(t,mp(s)),s}},deleteIssue:async(r,n)=>{t({isLoading:!0});try{await ln.deleteIssue(r,n),await e().fetchBoard(r)}catch(i){throw pp(t,mp(i)),i}},setViewMode:r=>{localStorage.setItem("bmad-board-viewMode",r),t({viewMode:r})},setVisibleColumns:r=>{const n=Math.max(2,Math.min(10,r));localStorage.setItem("bmad-board-visibleColumns",String(n)),t({visibleColumns:n})},setBoardConfig:r=>{t({boardConfig:r})},clearError:()=>{Ro&&(clearTimeout(Ro),Ro=null),t({error:null})}})),rk=[{id:"qa-failed",label:"QA Failed",colorClass:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400",conditions:[{field:"status",value:"Ready for Review"},{field:"gateResult",value:"FAIL"}]},{id:"qa-concerns",label:"QA Concerns",colorClass:"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400",conditions:[{field:"status",value:"Ready for Review"},{field:"gateResult",value:"CONCERNS"}]},{id:"qa-passed",label:"QA Passed",colorClass:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400",conditions:[{field:"status",value:"Ready for Review"},{field:"gateResult",value:"PASS"}]},{id:"qa-waived",label:"QA Waived",colorClass:"bg-teal-100 text-teal-800 dark:bg-teal-900/30 dark:text-teal-400",conditions:[{field:"status",value:"Ready for Review"},{field:"gateResult",value:"WAIVED"}]},{id:"qa-fixed",label:"QA Fixed",colorClass:"bg-sky-100 text-sky-800 dark:bg-sky-900/30 dark:text-sky-400",conditions:[{field:"status",value:"Ready for Review"},{field:"gateResult",value:"FIXED"}]},{id:"open",label:"Open",colorClass:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300",conditions:[{field:"status",value:"Open"}]},{id:"draft",label:"Draft",colorClass:"bg-slate-100 text-slate-700 dark:bg-slate-700 dark:text-slate-300",conditions:[{field:"status",value:"Draft"}]},{id:"approved",label:"Approved",colorClass:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",conditions:[{field:"status",value:"Approved"}]},{id:"in-progress",label:"In Progress",colorClass:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",conditions:[{field:"status",value:"In Progress"}]},{id:"in-progress",label:"In Progress",colorClass:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",conditions:[{field:"status",value:"InProgress"}]},{id:"blocked",label:"Blocked",colorClass:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",conditions:[{field:"status",value:"Blocked"}]},{id:"ready-for-review",label:"Ready for Review",colorClass:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400",conditions:[{field:"status",value:"Ready for Review"}]},{id:"ready-for-done",label:"Ready for Done",colorClass:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400",conditions:[{field:"status",value:"Ready for Done"}]},{id:"done",label:"Done",colorClass:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",conditions:[{field:"status",value:"Done"}]},{id:"closed",label:"Closed",colorClass:"bg-gray-200 text-gray-600 dark:bg-gray-600 dark:text-gray-400",conditions:[{field:"status",value:"Closed"}]},{id:"promoted",label:"Promoted",colorClass:"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400",conditions:[{field:"status",value:"Promoted"}]}],_me={id:"unknown",label:"Unknown",colorClass:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300",conditions:[]};function Qd(t){for(const e of rk)if(e.conditions.every(n=>{const i=t[n.field];return i!=null&&String(i)===n.value}))return e;return{..._me,label:t.status}}const f2=[...new Set(rk.map(t=>t.id))];function Pme(t){return rk.find(e=>e.id===t)}const O2={critical:"bg-red-500",high:"bg-orange-500",medium:"bg-yellow-500",low:"bg-gray-400"};function $me(){const{t}=Ce("common"),{projectSlug:e}=jn(),r=En(),{items:n,fetchBoard:i}=ei();k.useEffect(()=>{e&&i(e)},[e,i]);const s=n.filter(a=>a.type==="issue").slice(-5).reverse();return d.jsxs("div",{className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040]",children:[d.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-[#253040]",children:[d.jsx("h2",{className:"font-semibold text-gray-900 dark:text-white",children:t("overview.recentIssues")}),d.jsxs("button",{onClick:()=>r(`/project/${e}/board`),className:"text-sm text-blue-600 dark:text-blue-400 hover:underline flex items-center gap-1",children:[t("overview.viewBoard"),d.jsx(Sm,{className:"w-3.5 h-3.5"})]})]}),s.length===0?d.jsxs("div",{className:"py-8 px-5 text-center",children:[d.jsx("div",{className:"inline-flex items-center justify-center w-10 h-10 rounded-xl bg-gray-100 dark:bg-[#253040]/50 mb-3",children:d.jsx(ji,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})}),d.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t("overview.noIssues")})]}):d.jsx("div",{className:"divide-y divide-gray-100 dark:divide-gray-700",children:s.map(a=>{const o=Qd(a);return d.jsxs("button",{onClick:()=>r(`/project/${e}/board`),className:"w-full flex items-center gap-3 px-5 py-3 hover:bg-gray-100/50 dark:hover:bg-[#253040]/50 transition-colors text-left",children:[a.severity&&d.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${O2[a.severity]??O2.low}`}),d.jsx("span",{className:"text-sm text-gray-900 dark:text-white truncate flex-1",children:a.title}),d.jsx("span",{className:`text-[11px] px-1.5 py-0.5 rounded-full flex-shrink-0 ${o.colorClass}`,children:o.label})]},a.id)})})]})}function Cme(){return d.jsxs("div",{className:"space-y-4 animate-pulse",children:[d.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-950/30 dark:to-indigo-950/30 rounded-xl border border-blue-200 dark:border-blue-800/50 p-5",children:[d.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[d.jsxs("div",{className:"flex items-center gap-4",children:[d.jsx("div",{className:"h-7 w-14 bg-blue-200 dark:bg-blue-800 rounded-md"}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx("div",{className:"h-8 w-12 bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-16 bg-gray-200 dark:bg-[#253040] rounded ml-1"})]})]}),d.jsxs("div",{className:"flex items-center gap-6",children:[d.jsx("div",{className:"h-4 w-24 bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-24 bg-gray-200 dark:bg-[#253040] rounded"})]})]}),d.jsx("div",{className:"mt-3 h-2.5 bg-blue-100 dark:bg-blue-900/40 rounded-full"})]}),d.jsxs("div",{className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5 space-y-3",children:[d.jsx("div",{className:"h-5 w-36 bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-full bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-2/3 bg-gray-200 dark:bg-[#253040] rounded"})]}),d.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:Array.from({length:2}).map((t,e)=>d.jsxs("div",{className:"bg-gray-50 dark:bg-[#263240] rounded-xl border border-gray-200 dark:border-[#253040] p-5 space-y-4",children:[d.jsx("div",{className:"h-5 w-32 bg-gray-200 dark:bg-[#253040] rounded"}),d.jsxs("div",{className:"space-y-2",children:[d.jsx("div",{className:"h-4 w-full bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-3/4 bg-gray-200 dark:bg-[#253040] rounded"}),d.jsx("div",{className:"h-4 w-1/2 bg-gray-200 dark:bg-[#253040] rounded"})]})]},e))})]})}function Tme(t){const e=t.length,r=t.reduce((a,o)=>a+(o.plannedStories??o.stories.length),0),n=t.reduce((a,o)=>a+o.stories.filter(l=>l.status==="Done").length,0),i=t.filter(a=>{const o=a.plannedStories??a.stories.length;return o>0&&a.stories.filter(l=>l.status==="Done").length>=o}).length,s=r>0?Math.round(n/r*100):0;return{totalEpics:e,doneEpics:i,totalStories:r,doneStories:n,pct:s}}function Rme({epics:t,isRefreshing:e}){const{t:r}=Ce("common"),{totalEpics:n,doneEpics:i,totalStories:s,doneStories:a,pct:o}=Tme(t);return d.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-950/30 dark:to-indigo-950/30 rounded-xl border border-blue-200 dark:border-blue-800/50 p-5",children:[d.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[d.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[d.jsx("span",{className:"text-sm font-semibold px-3 py-1 bg-blue-600 dark:bg-blue-500 text-white rounded-md",children:r("overview.bmadLabel")}),d.jsx(Lg,{isRefreshing:e}),d.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[d.jsxs("span",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:[o,"%"]}),d.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-300 ml-1",children:r("overview.completedStatus")})]})]}),d.jsxs("div",{className:"flex items-center gap-6",children:[d.jsxs("div",{className:"flex items-center gap-1.5",children:[d.jsx(ure,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"}),d.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-200",children:[d.jsxs("span",{className:"font-semibold text-gray-900 dark:text-white",children:[i,"/",n]})," ",r("overview.epicsLabel")]})]}),d.jsxs("div",{className:"flex items-center gap-1.5",children:[d.jsx(Kee,{className:"w-4 h-4 text-indigo-500 dark:text-indigo-400"}),d.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-200",children:[d.jsxs("span",{className:"font-semibold text-gray-900 dark:text-white",children:[a,"/",s]})," ",r("overview.storiesLabel")]})]})]})]}),d.jsx("div",{className:"mt-3 h-2.5 bg-blue-100 dark:bg-blue-900/40 rounded-full overflow-hidden",children:d.jsx("div",{className:"h-full bg-blue-500 dark:bg-blue-400 rounded-full transition-all",style:{width:`${o}%`}})})]})}function Eme({data:t,isLoading:e,isRefreshing:r,error:n,retry:i,projectSlug:s}){const{t:a}=Ce("common");return d.jsxs("div",{className:"px-6 pt-6 space-y-4",children:[e&&d.jsx(Cme,{}),n&&d.jsxs("div",{role:"alert",className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl p-4",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(Oa,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),d.jsx("span",{className:"text-sm font-medium text-red-800 dark:text-red-200",children:a("overview.bmadLoadFailed")})]}),d.jsx("p",{className:"text-xs text-red-700 dark:text-red-300 mb-2",children:n}),d.jsx("button",{onClick:i,className:"text-xs px-3 py-1 bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-300 rounded hover:bg-red-200 dark:hover:bg-red-800/50 transition-colors",children:a("button.retry")})]}),t&&d.jsxs(d.Fragment,{children:[d.jsx(Rme,{epics:t.epics,isRefreshing:r}),d.jsx(wme,{data:t,projectSlug:s}),d.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[d.jsx(lme,{documents:t.documents,auxiliaryDocuments:t.auxiliaryDocuments,projectSlug:s}),d.jsx(hme,{epics:t.epics,projectSlug:s,storyBasePath:t.config.devStoryLocation})]})]})]})}function jme(){const{projectSlug:t}=jn(),{projects:e}=Ga(),r=e.find(u=>u.projectSlug===t),n=(r==null?void 0:r.isBmadProject)??!1,{data:i,isLoading:s,isRefreshing:a,error:o,retry:l}=Qie(n?t:void 0),c=n?d.jsx($me,{}):void 0;return d.jsxs(d.Fragment,{children:[n&&t&&d.jsxs(d.Fragment,{children:[d.jsx(Eme,{data:i,isLoading:s,isRefreshing:a,error:o,retry:l,projectSlug:t}),d.jsx("div",{className:"mx-6 border-t border-gray-200 dark:border-[#253040]"})]}),d.jsx($ie,{quickActionsSlot:c})]})}const qn={getStatus:t=>qe.get(`/projects/${t}/queue/status`),getStories:t=>qe.get(`/projects/${t}/queue/stories`),getTemplates:t=>qe.get(`/projects/${t}/queue/templates`),saveTemplate:(t,e,r)=>qe.post(`/projects/${t}/queue/templates`,{name:e,template:r}),updateTemplate:(t,e,r,n)=>qe.put(`/projects/${t}/queue/templates/${e}`,{name:r,template:n}),deleteTemplate:(t,e)=>qe.delete(`/projects/${t}/queue/templates/${e}`),getGlobalTemplates:t=>qe.get(`/projects/${t}/queue/global-templates`),saveGlobalTemplate:(t,e,r)=>qe.post(`/projects/${t}/queue/global-templates`,{name:e,template:r}),updateGlobalTemplate:(t,e,r,n)=>qe.put(`/projects/${t}/queue/global-templates/${e}`,{name:r,template:n}),deleteGlobalTemplate:(t,e)=>qe.delete(`/projects/${t}/queue/global-templates/${e}`)};let gp=null,Ol=null;const si=Zn((t,e)=>({script:"",parsedItems:[],warnings:[],isRunning:!1,isPaused:!1,isCompleted:!1,isErrored:!1,isStarting:!1,isAborted:!1,currentIndex:0,totalItems:0,pauseReason:void 0,lockedSessionId:null,currentModel:void 0,completedItems:new Set,errorItem:null,itemSessionIds:new Map,isReordering:!1,setScript:r=>{t({script:r}),gp&&clearTimeout(gp),gp=setTimeout(()=>{e().parseScript(),gp=null},300)},parseScript:()=>{const{script:r}=e(),n=oq(r);t({parsedItems:n.items,warnings:n.warnings})},handleProgress:r=>{if(e().isAborted)return;const n={currentIndex:r.currentIndex,totalItems:r.totalItems,pauseReason:r.pauseReason,lockedSessionId:r.sessionId,isStarting:!1};switch(r.status){case"running":n.isRunning=!0,n.isPaused=!1,n.isCompleted=!1,n.isErrored=!1,n.errorItem=null;break;case"paused":n.isRunning=!0,n.isPaused=!0;break;case"completed":n.isRunning=!1,n.isPaused=!1,n.isCompleted=!0,n.lockedSessionId=null;break;case"aborted":n.isRunning=!1,n.isPaused=!1,n.isCompleted=!1,n.isErrored=!1,n.errorItem=null,n.pauseReason=void 0,n.lockedSessionId=null;break;case"error":n.isRunning=!1,n.isPaused=!1,n.isErrored=!0,n.lockedSessionId=null;break}if(r.status==="running"&&r.sessionId){const i=new Map(e().itemSessionIds);i.set(r.currentIndex,r.sessionId),n.itemSessionIds=i}t(n)},handleItemComplete:r=>{e().isAborted||t(n=>{const i=new Map(n.itemSessionIds);return r.sessionId&&i.set(r.itemIndex,r.sessionId),{completedItems:new Set([...n.completedItems,r.itemIndex]),itemSessionIds:i}})},handleError:r=>{e().isAborted||t({errorItem:{index:r.itemIndex,error:r.error}})},setStarting:r=>{t({isStarting:r,isAborted:!1,...r?{errorItem:null}:{}})},syncFromStatus:r=>{const n=r.totalItems>0?Math.min(r.currentIndex,r.totalItems):r.currentIndex,i=r.isRunning||n>0?new Set(Array.from({length:n},(s,a)=>a)):new Set;t({isRunning:r.isRunning,isPaused:r.isPaused,isCompleted:r.isCompleted??!1,isErrored:r.isErrored??!1,isAborted:!1,isReordering:!1,currentIndex:Math.min(r.currentIndex,r.totalItems>0?r.totalItems:r.currentIndex),totalItems:r.totalItems,pauseReason:r.pauseReason,lockedSessionId:r.lockedSessionId,currentModel:r.currentModel,completedItems:i,errorItem:r.lastError?{index:r.lastError.itemIndex,error:r.lastError.error}:null,...r.items&&r.items.length>0?{parsedItems:r.items}:{},itemSessionIds:r.completedSessionIds?new Map(Object.entries(r.completedSessionIds).map(([s,a])=>[Number(s),a])):new Map})},handleItemsUpdated:r=>{e().isAborted||(Ol&&(clearTimeout(Ol),Ol=null),t({parsedItems:r.items,totalItems:r.totalItems,currentIndex:r.currentIndex,isReordering:!1}))},optimisticReorder:(r,n)=>{const{parsedItems:i,currentIndex:s,isPaused:a}=e(),o=a?s:s+1,l=r.map(c=>i[c]);Ol&&clearTimeout(Ol),Ol=setTimeout(()=>{e().isReordering&&(qn.getStatus(n).then(c=>e().syncFromStatus(c)).catch(()=>t({isReordering:!1})),Ol=null)},3e3),t({parsedItems:[...i.slice(0,o),...l],isReordering:!0})},reset:()=>{t({isRunning:!1,isPaused:!1,isCompleted:!1,isErrored:!1,isStarting:!1,isAborted:!0,currentIndex:0,totalItems:0,pauseReason:void 0,lockedSessionId:null,currentModel:void 0,completedItems:new Set,errorItem:null,itemSessionIds:new Map,isReordering:!1})}}));function Xme({session:t,onClick:e,onDelete:r,onRename:n,selectionMode:i,selected:s,onToggleSelect:a,agentInfo:o,isEditing:l,onEditStart:c,onEditEnd:u,isQueueActive:h}){const{t:O}=Ce("chat"),[p,b]=k.useState(!1),y=k.useRef(null),[g,x]=k.useState(t.name||""),v=k.useRef(null),w=()=>{if(i){a==null||a(t.sessionId);return}p||e(t.sessionId)},Q=X=>{X.stopPropagation(),b(I=>!I)},_=X=>{X.stopPropagation(),b(!1),r==null||r(t.sessionId)},$=X=>{X.stopPropagation(),b(!1),x(t.name||""),c==null||c(t.sessionId)},P=X=>{X.stopPropagation(),b(!1),n==null||n(t.sessionId,null)},T=()=>{const X=g.trim();n==null||n(t.sessionId,X||null),u==null||u()},E=()=>{u==null||u()};k.useEffect(()=>{l&&v.current&&(v.current.focus(),v.current.select())},[l]);const N=k.useCallback(X=>{y.current&&!y.current.contains(X.target)&&b(!1)},[]);k.useEffect(()=>{if(p)return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[p,N]);const A=X=>{X.stopPropagation(),a==null||a(t.sessionId)};return d.jsxs("div",{role:"button",tabIndex:0,onClick:w,onKeyDown:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),w())},className:`relative w-full text-left p-4 bg-gray-50 dark:bg-[#263240] rounded-lg border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 dark:focus-visible:ring-offset-[#1c2129] cursor-pointer ${s?"border-blue-500 dark:border-blue-400 bg-blue-50 dark:bg-blue-900/20":"border-gray-200 dark:border-[#253040] hover:border-blue-500 dark:hover:border-blue-400"}`,"aria-label":`${O("sessionListItem.ariaLabel",{prompt:t.firstPrompt||O("sessionListItem.emptySession")})}. ${O("sessionListItem.messageCount",{count:t.messageCount})}. ${Ll(t.modified)}`,children:[d.jsxs("div",{className:"flex items-start gap-3",children:[i&&d.jsx("div",{className:"flex-shrink-0 pt-0.5",children:d.jsx("input",{type:"checkbox",checked:s||!1,onChange:A,onClick:X=>X.stopPropagation(),className:"w-4 h-4 rounded border-gray-300 dark:border-[#2d3a4a] text-blue-600 focus:ring-blue-500 dark:bg-[#253040]","aria-label":O("sessionListItem.checkbox",{prompt:t.firstPrompt||O("sessionListItem.emptySession")})})}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5 min-w-0",children:[t.name&&d.jsx("span",{className:"flex-shrink-0 inline-block text-[11px] leading-tight font-medium px-1.5 py-px rounded bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300 max-w-[40%] truncate",children:t.name}),o&&d.jsxs("span",{className:"flex-shrink-0 inline-block text-[11px] leading-tight font-medium px-1.5 py-px rounded bg-purple-100 dark:bg-purple-900/40 text-purple-700 dark:text-purple-300","data-testid":"session-agent-badge",children:[o.icon&&d.jsx("span",{children:o.icon})," ",o.name]}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate font-mono",children:t.sessionId})]}),l?d.jsx("input",{ref:v,type:"text",value:g,onChange:X=>x(X.target.value),onKeyDown:X=>{X.key==="Enter"&&(X.stopPropagation(),X.preventDefault(),T()),X.key==="Escape"&&(X.stopPropagation(),X.preventDefault(),E())},onBlur:T,onClick:X=>X.stopPropagation(),placeholder:O("sessionListItem.nameInput"),className:"w-full text-sm font-medium bg-white dark:bg-[#253040] border border-blue-500 rounded px-2 py-1 mb-2 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500"}):d.jsx("p",{className:"text-gray-900 dark:text-white font-medium truncate mb-1",children:t.firstPrompt||O("sessionListItem.emptySession")}),d.jsxs("div",{className:"flex items-center justify-between text-sm text-gray-500 dark:text-gray-300",children:[d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsxs("span",{className:"relative flex h-2 w-2 mr-1",title:t.isStreaming?O("sessionListItem.streaming"):O("sessionListItem.waiting"),children:[t.isStreaming&&d.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),d.jsx("span",{className:`relative inline-flex rounded-full h-2 w-2 ${t.isStreaming?"bg-green-500":"bg-gray-300 dark:bg-gray-600"}`})]}),h&&d.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] font-medium px-1.5 py-px rounded bg-indigo-100 dark:bg-indigo-900/40 text-indigo-600 dark:text-indigo-300",title:O("sessionListItem.queueActive"),children:[d.jsx(Ag,{className:"w-3 h-3"}),O("sessionListItem.queue")]}),d.jsx(Wo,{className:"w-4 h-4","aria-hidden":"true"}),d.jsx("span",{children:O("sessionListItem.messageCount",{count:t.messageCount})})]}),d.jsx("span",{children:Ll(t.modified)})]})]})]}),(r||n)&&!i&&d.jsxs("div",{ref:y,className:"absolute top-2 right-2 z-10",children:[d.jsx("button",{type:"button",onClick:Q,"aria-label":O("sessionListItem.menu"),"aria-expanded":p,className:"p-1 rounded-md text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-[#253040] focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",children:d.jsx(Ba,{className:"w-4 h-4","aria-hidden":"true"})}),p&&d.jsxs("div",{className:"absolute right-0 mt-1 w-36 bg-white dark:bg-[#263240] rounded-md shadow-lg border border-gray-200 dark:border-[#253040] py-1",role:"menu",children:[n&&d.jsxs("button",{type:"button",onClick:$,role:"menuitem",className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] transition-colors",children:[d.jsx(Ng,{className:"w-4 h-4","aria-hidden":"true"}),O("sessionListItem.rename")]}),n&&t.name&&d.jsxs("button",{type:"button",onClick:P,role:"menuitem",className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] transition-colors",children:[d.jsx(Vt,{className:"w-4 h-4","aria-hidden":"true"}),O("sessionListItem.removeName")]}),r&&d.jsxs("button",{type:"button",onClick:_,role:"menuitem",className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:[d.jsx(Ds,{className:"w-4 h-4","aria-hidden":"true"}),O("sessionListItem.delete")]})]})]})]})}function Ame(){return d.jsx("div",{className:"w-full p-4 bg-gray-50 dark:bg-[#263240] rounded-lg border border-gray-200 dark:border-[#253040] animate-pulse",children:d.jsx("div",{className:"flex items-start gap-3",children:d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-baseline gap-1.5 mb-1",children:[d.jsx("div",{className:"h-4 bg-blue-100 dark:bg-blue-900/40 rounded w-16 flex-shrink-0"}),d.jsx("div",{className:"h-3 bg-gray-200 dark:bg-[#253040] rounded w-24"})]}),d.jsx("div",{className:"h-5 bg-gray-200 dark:bg-[#253040] rounded w-3/4 mb-2"}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx("div",{className:"w-2 h-2 bg-gray-300 dark:bg-gray-600 rounded-full"}),d.jsx("div",{className:"h-4 bg-gray-200 dark:bg-[#253040] rounded w-16"})]}),d.jsx("div",{className:"h-4 bg-gray-200 dark:bg-[#253040] rounded w-14"})]})]})})})}function h3({icon:t=Wo,title:e,description:r,actionLabel:n,onAction:i}){return d.jsxs("div",{className:"text-center py-6 md:py-12 px-4",role:"status","aria-label":e,children:[d.jsx(t,{className:"w-10 h-10 md:w-16 md:h-16 mx-auto text-gray-400 dark:text-gray-500 mb-3 md:mb-4","aria-hidden":"true"}),d.jsx("p",{className:"text-base md:text-lg font-medium text-gray-900 dark:text-white mb-1 md:mb-2",children:e}),d.jsx("p",{className:"text-sm md:text-base text-gray-500 dark:text-gray-300 mb-3 md:mb-4",children:r}),n&&i&&d.jsxs("button",{onClick:i,className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-[#1c2129]",children:[d.jsx(kr,{className:"w-5 h-5","aria-hidden":"true"}),n]})]})}function Nme({pullDistance:t,threshold:e,isRefreshing:r}){const{t:n}=Ce("common"),s=Math.min(t/e,1)*180;return t===0&&!r?null:d.jsxs("div",{className:"flex justify-center py-4 transition-all",style:{height:t},children:[d.jsx(Ir,{className:`w-6 h-6 text-blue-600 ${r?"animate-spin":""}`,style:{transform:`rotate(${s}deg)`},"aria-hidden":"true"}),r&&d.jsx("span",{className:"sr-only",children:n("pullToRefresh")})]})}function Dme({onRefresh:t,threshold:e=80,disabled:r=!1}){const n=k.useRef(null),[i,s]=k.useState(0),[a,o]=k.useState(!1),l=k.useRef(0),c=k.useRef(!1),u=k.useRef(!1),h=k.useRef(0),O=k.useRef(!1),p=k.useRef(t);p.current=t;const b=15;return k.useEffect(()=>{const y=n.current;if(!y)return;const g=_=>{let $=_.parentElement;for(;$&&$!==document.documentElement;){const{overflowY:P}=getComputedStyle($);if((P==="auto"||P==="scroll")&&$.scrollHeight>$.clientHeight)return $;$=$.parentElement}return document.documentElement},x=y.scrollHeight>y.clientHeight?y:g(y),v=_=>{const P=_.touches[0].clientY-l.current;if(x.scrollTop>0||P<=0){c.current=!1,u.current=!1,h.current=0,s(0),y.removeEventListener("touchmove",v);return}if(!u.current){if(P<b)return;u.current=!0}const T=P-b,E=Math.min(T*.5,e*1.5);h.current=E,s(E),_.preventDefault()},w=_=>{r||O.current||x.scrollTop>0||(l.current=_.touches[0].clientY,c.current=!0,u.current=!1,y.addEventListener("touchmove",v,{passive:!1}))},Q=async()=>{if(y.removeEventListener("touchmove",v),!!c.current)if(c.current=!1,u.current=!1,h.current>=e&&!O.current){O.current=!0,o(!0),s(e);try{await p.current()}finally{O.current=!1,o(!1),h.current=0,s(0)}}else h.current=0,s(0)};return y.addEventListener("touchstart",w,{passive:!0}),y.addEventListener("touchend",Q),()=>{y.removeEventListener("touchstart",w),y.removeEventListener("touchmove",v),y.removeEventListener("touchend",Q)}},[r,e]),{containerRef:n,isPulling:i>0,pullDistance:i,isRefreshing:a}}const Lme=76,Ime=56;function Mme(t=5){const[e,r]=k.useState(t);return k.useEffect(()=>{const n=()=>{const i=window.innerHeight-Ime,s=Math.ceil(i/Lme);r(Math.min(Math.max(s,3),10))};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),e}const p2=80;function zme(){const{t}=Ce("chat"),{projectSlug:e}=jn(),r=En(),n=fs(),{sessions:i,isLoading:s,error:a,isRefreshing:o,isLoadingMore:l,hasMore:c,fetchSessions:u,loadMoreSessions:h,deleteSession:O,deleteSessions:p,renameSession:b,includeEmpty:y,setIncludeEmpty:g,searchQuery:x,searchContent:v,isSearching:w,searchSessions:Q,clearSearch:_,setSearchContent:$}=ua(),P=si(Me=>Me.isRunning||Me.isPaused?Me.lockedSessionId:null),T=Mme(5),[E,N]=k.useState(!1),[A,X]=k.useState(new Set),[I,W]=k.useState(null),[Y,te]=k.useState(null),[ee,B]=k.useState(!1),[D,R]=k.useState(!1),[M,U]=k.useState(""),z=k.useRef(void 0),K=k.useMemo(()=>i.filter(Me=>!Me.firstPrompt||Me.messageCount===0).map(Me=>Me.sessionId),[i]);k.useEffect(()=>{if(!e)return;let Me=null,It,Mt=0;const ge=10,ke=()=>{Me==null||Me.emit("project:join",e)};function H(){try{Me=Ct(),ke(),Me.on("connect",ke)}catch{++Mt<ge&&(It=setTimeout(H,200))}}return H(),()=>{clearTimeout(It),Me&&(Me.off("connect",ke),Me.emit("project:leave",e))}},[e]);const oe=k.useRef(!0);k.useEffect(()=>{e&&(clearTimeout(z.current),U(""),_(e)),oe.current=!0},[e,_,n.key]),k.useEffect(()=>{if(oe.current){oe.current=!1;return}e&&u(e,{limit:20})},[y,e,u]),k.useEffect(()=>()=>clearTimeout(z.current),[]),k.useEffect(()=>{const Me=It=>{It.key==="Escape"&&E&&(N(!1),X(new Set))};return document.addEventListener("keydown",Me),()=>document.removeEventListener("keydown",Me)},[E]);const le=k.useCallback(async()=>{e&&await u(e,{limit:20})},[e,u]),{containerRef:Z,pullDistance:V,isRefreshing:ne}=Dme({onRefresh:le,threshold:p2,disabled:s||!!a}),G=k.useCallback(Me=>{U(Me),clearTimeout(z.current),Me.trim()?z.current=setTimeout(()=>{e&&Q(e,Me.trim(),v)},300):e&&_(e)},[e,v,Q,_]),he=k.useCallback(()=>{const Me=!v;$(Me),M.trim()&&e&&(clearTimeout(z.current),Q(e,M.trim(),Me))},[v,$,M,e,Q]),se=k.useCallback(()=>{U(""),clearTimeout(z.current),e&&_(e)},[e,_]),ce=k.useCallback(()=>{e&&x&&Q(e,x,v)},[e,x,v,Q]),re=k.useCallback(()=>{const Me=Kr();r(`/project/${e}/session/${Me}`)},[r,e]),Qe=k.useCallback(Me=>r(`/project/${e}/session/${Me}`),[r,e]),me=k.useCallback((Me,It)=>{e&&b(e,Me,It)},[e,b]),xe=k.useCallback(Me=>te(Me),[]),ht=k.useCallback(async()=>{!Y||!e||(await O(e,Y),te(null))},[Y,e,O]),St=k.useCallback(Me=>{X(It=>{const Mt=new Set(It);return Mt.has(Me)?Mt.delete(Me):Mt.add(Me),Mt})},[]),wt=k.useCallback(()=>{X(new Set(i.map(Me=>Me.sessionId)))},[i]),zt=k.useCallback(async()=>{!e||A.size===0||(B(!1),await p(e,[...A]),X(new Set),N(!1))},[e,A,p]),or=k.useCallback(async()=>{!e||K.length===0||(R(!1),await p(e,K))},[e,K,p]);return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"sticky top-0 z-[5] bg-white dark:bg-[#1c2129] border-b border-gray-200 dark:border-[#253040]",children:d.jsx("div",{className:"flex items-center justify-between px-4 py-2",children:E?d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("button",{onClick:()=>{N(!1),X(new Set)},className:"p-1.5 hover:bg-gray-200 dark:hover:bg-[#253040] rounded-lg text-gray-600 dark:text-gray-300","aria-label":t("session.exitSelection"),children:d.jsx(Vt,{className:"w-4 h-4"})}),d.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-200",children:t("session.selectedCount",{count:A.size})})]}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx("button",{onClick:A.size<i.length?wt:()=>X(new Set),className:"px-3 py-1.5 text-xs rounded-lg hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-600 dark:text-gray-300",children:A.size<i.length?t("session.selectAll"):t("session.deselectAll")}),d.jsxs("button",{onClick:()=>B(!0),disabled:A.size===0,className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded-lg bg-red-100 dark:bg-red-600 text-red-700 dark:text-white hover:bg-red-200 dark:hover:bg-red-500 disabled:opacity-50 transition-colors",children:[d.jsx(Ds,{className:"w-3.5 h-3.5"}),t("session.delete")]})]})]}):d.jsxs(d.Fragment,{children:[d.jsx(Lg,{isRefreshing:o,className:"ml-1"}),d.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[d.jsxs("button",{onClick:re,className:"inline-flex items-center gap-1.5 px-3 py-1.5 bg-blue-100 dark:bg-blue-600 text-blue-700 dark:text-white text-xs font-medium rounded-lg hover:bg-blue-200 dark:hover:bg-blue-500 transition-colors",children:[d.jsx(kr,{className:"w-3.5 h-3.5"}),t("session.newSession")]}),d.jsx("div",{className:"w-px h-5 bg-gray-200 dark:bg-[#253040] ml-2"}),d.jsx("button",{onClick:()=>g(!y),className:`p-1.5 rounded-lg transition-colors ${y?"bg-blue-100 dark:bg-blue-600 text-blue-700 dark:text-white":"hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300"}`,"aria-label":t(y?"session.hideEmpty":"session.showEmpty"),title:t(y?"session.hideEmpty":"session.showEmpty"),children:y?d.jsx(Jc,{className:"w-4 h-4"}):d.jsx(Qh,{className:"w-4 h-4"})}),y&&K.length>0&&d.jsxs("button",{onClick:()=>R(!0),className:"inline-flex items-center gap-1 px-2.5 py-1.5 text-xs rounded-lg bg-red-100 dark:bg-red-600 text-red-700 dark:text-white hover:bg-red-200 dark:hover:bg-red-500 transition-colors",children:[d.jsx(Ds,{className:"w-3.5 h-3.5"}),t("session.deleteEmpty")]}),i.length>0&&d.jsx("button",{onClick:()=>{N(!0),X(new Set)},className:"p-1.5 hover:bg-gray-200 dark:hover:bg-[#253040] rounded-lg text-gray-500 dark:text-gray-300","aria-label":t("session.selectionMode"),children:d.jsx(vne,{className:"w-4 h-4"})}),d.jsx("button",{onClick:le,disabled:s||o,className:"p-1.5 hover:bg-gray-200 dark:hover:bg-[#253040] rounded-lg disabled:opacity-50 text-gray-500 dark:text-gray-300","aria-label":t("session.refresh"),children:d.jsx(Ir,{className:`w-4 h-4 ${o?"animate-spin":""}`})})]})]})})}),!E&&d.jsxs("div",{className:"px-4 pt-3 pb-1 bg-white dark:bg-[#1c2129]",children:[d.jsxs("div",{role:"search",className:"relative",children:[d.jsx(vd,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500 dark:text-gray-400 pointer-events-none","aria-hidden":"true"}),d.jsx("input",{type:"text",value:M,onChange:Me=>G(Me.target.value),placeholder:t("session.searchPlaceholder"),"aria-label":t("session.searchPlaceholder"),className:"w-full pl-10 pr-9 py-2 text-sm bg-gray-100 dark:bg-[#263240] border border-gray-200 dark:border-[#253040] rounded-lg text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),M&&d.jsx("button",{onClick:se,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded","aria-label":t("session.clearSearch"),children:d.jsx(Vt,{className:"w-4 h-4"})})]}),M.trim()&&d.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[d.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm text-gray-600 dark:text-gray-300",children:[d.jsx("input",{type:"checkbox",checked:v,onChange:he,className:"rounded border-gray-300 dark:border-[#2d3a4a] text-blue-600 focus:ring-blue-500"}),t("session.searchContent")]}),d.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:t(v?"session.searchContentCap":"session.searchContentHint")})]})]}),d.jsx(Nme,{pullDistance:V,threshold:p2,isRefreshing:ne}),d.jsxs("div",{ref:Z,className:"flex-1 overflow-auto","aria-live":"polite",children:[w&&d.jsxs("div",{className:"flex items-center justify-center py-12 gap-2 text-gray-500 dark:text-gray-300",role:"status",children:[d.jsx(vt,{className:"w-5 h-5 animate-spin","aria-hidden":"true"}),d.jsx("span",{children:t("session.searching")})]}),!w&&a&&x&&d.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-3 text-gray-500 dark:text-gray-300",children:[d.jsx("p",{className:"text-sm",children:t("session.searchError")}),d.jsx("button",{onClick:ce,className:"px-4 py-2 text-sm bg-blue-100 dark:bg-blue-600 text-blue-700 dark:text-white rounded-lg hover:bg-blue-200 dark:hover:bg-blue-500 transition-colors",children:t("session.refresh")})]}),!w&&s&&!o&&d.jsx("div",{className:"p-4 space-y-3","aria-label":t("session.loading"),role:"status",children:Array.from({length:T}).map((Me,It)=>d.jsx(Ame,{},It))}),!w&&!s&&i.length===0&&x&&!a&&d.jsx("div",{className:"flex items-center justify-center py-12 text-gray-500 dark:text-gray-300",children:d.jsx("p",{className:"text-sm",children:t("session.searchNoResults")})}),!w&&!s&&i.length===0&&!x&&!a&&d.jsx(h3,{title:t("session.empty.title"),description:t("session.empty.description"),actionLabel:t("session.empty.action"),onAction:re}),!w&&!s&&i.length>0&&d.jsxs("div",{className:"p-4 space-y-3",children:[i.map(Me=>d.jsx(Xme,{session:Me,agentInfo:null,onClick:Qe,onDelete:xe,onRename:me,selectionMode:E,selected:A.has(Me.sessionId),onToggleSelect:St,isEditing:I===Me.sessionId,onEditStart:It=>W(It),onEditEnd:()=>W(null),isQueueActive:P===Me.sessionId},Me.sessionId)),c&&e&&d.jsx("button",{onClick:()=>h(e,{limit:20}),disabled:l,className:"w-full py-3 text-sm text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:bg-gray-50 dark:hover:bg-[#263240]/50 rounded-lg transition-colors disabled:opacity-50 flex items-center justify-center gap-2","data-testid":"load-more-sessions",children:l?d.jsxs(d.Fragment,{children:[d.jsx(vt,{className:"w-4 h-4 animate-spin","aria-hidden":"true"}),t("session.loadingMore")]}):t("session.loadMore")})]})]}),d.jsx(Ma,{isOpen:!!Y,title:t("session.confirmDelete.title"),message:t("session.confirmDelete.message"),confirmText:t("session.confirmDelete.confirm"),cancelText:t("session.confirmDelete.cancel"),variant:"danger",onConfirm:ht,onCancel:()=>te(null)}),d.jsx(Ma,{isOpen:ee,title:t("session.confirmBatchDelete.title"),message:t("session.confirmBatchDelete.message",{count:A.size}),confirmText:t("session.confirmDelete.confirm"),cancelText:t("session.confirmDelete.cancel"),variant:"danger",onConfirm:zt,onCancel:()=>B(!1)}),d.jsx(Ma,{isOpen:D,title:t("session.confirmEmptyDelete.title"),message:t("session.confirmEmptyDelete.message",{count:K.length}),confirmText:t("session.confirmDelete.confirm"),cancelText:t("session.confirmDelete.cancel"),variant:"danger",onConfirm:or,onCancel:()=>R(!1)})]})}function qme(t,e){if(e.length===0)return t;if(t.length===0)return e;const r=new Map;for(const c of e)if(c.type==="user"){const u=c.content.trim(),h=r.get(u)??[];h.push(c),r.set(u,h)}const n=new Set,i=new Set,s=new Map;for(const c of t)if(c._optimistic&&c.type==="user"){const u=c.content.trim(),h=r.get(u);if(h&&h.length>0){const O=h.shift();n.add(O.id),i.add(c.id),s.set(O.id,c.id)}}const a=new Map(t.filter(c=>c._optimistic).map(c=>[c.id,c])),o=new Map;for(const c of t)c.type==="user"&&c.images&&c.images.length>0&&!c._optimistic&&o.set(c.content,c.images);const l=[];for(const c of e)if(c.type==="user"&&n.has(c.id)){const u=s.get(c.id),h=u?a.get(u):void 0;h!=null&&h.images&&h.images.length>0?l.push({...c,images:h.images}):l.push(c)}else c.type==="user"&&!c.images&&o.has(c.content)?l.push({...c,images:o.get(c.content)}):l.push(c);for(const c of t)c._optimistic&&!i.has(c.id)&&l.push(c);return l}const Cu=new Map,Ume=5,gt=Zn((t,e)=>({messages:[],currentProjectSlug:null,currentSessionId:null,isLoading:!1,isLoadingMore:!1,error:null,pagination:null,lastAgentCommand:null,fetchMessages:async(r,n,i)=>{var o,l,c,u,h;const s=e(),a=s.currentSessionId===n;ot.message("fetchMessages called",{projectSlug:r,sessionId:n,silent:i==null?void 0:i.silent,minMessageCount:i==null?void 0:i.minMessageCount,isSameSession:a,currentMsgCount:s.messages.length,isStreaming:Ee.getState().isStreaming}),a||t({messages:[],pagination:null}),!(i!=null&&i.silent)&&!a&&t({isLoading:!0}),t({error:null,currentProjectSlug:r,currentSessionId:n});try{const O=await ea.getMessages(r,n);if(i!=null&&i.minMessageCount&&O.messages.length<i.minMessageCount){ot.message("fetchMessages → stale data guard (minMessageCount)",{serverCount:O.messages.length,minRequired:i.minMessageCount});return}const p=e().messages,b=Ee.getState(),y=(((o=O.pagination)==null?void 0:o.offset)??0)>0,x=b.streamCompletedAt!==null&&Date.now()-b.streamCompletedAt<1e4,v=b.streamingMessageId==="restoring",w=i!=null&&i.force?!1:x,Q=!y&&(v&&O.messages.length<=p.length||!v&&O.messages.length<p.length&&(b.isStreaming||w||b.isCompacting));if(ot.message("fetchMessages → guard check",{shouldGuard:Q,isRestoring:v,isPaginationFetch:y,serverCount:O.messages.length,currentCount:p.length,serverLessThanCurrent:O.messages.length<p.length,isStreaming:b.isStreaming,segmentsPendingClear:b.segmentsPendingClear,isInCooldown:x,isCompacting:b.isCompacting,streamCompletedAt:b.streamCompletedAt,guardConditionMet:b.isStreaming||w||b.isCompacting,paginationOffset:(l=O.pagination)==null?void 0:l.offset,currentAssistantCount:p.filter(P=>P.type==="assistant").length,serverAssistantCount:O.messages.filter(P=>P.type==="assistant").length}),Q){ot.message("fetchMessages → streaming guard BLOCKED update",{serverCount:O.messages.length,currentCount:p.length,isStreaming:b.isStreaming,segmentsPendingClear:b.segmentsPendingClear,isInCooldown:x,isCompacting:b.isCompacting}),t({isLoading:!1});return}const _=qme(p,O.messages);_.sort((P,T)=>new Date(P.timestamp).getTime()-new Date(T.timestamp).getTime());const $=P=>P.map((T,E)=>`${E}:${T.type}:${(T.content||"").slice(0,30)}`);if(ot.message("fetchMessages → messages updated",{serverCount:O.messages.length,currentCount:p.length,reconciledCount:_.length,serverTypes:O.messages.map(P=>P.type),currentTypes:p.map(P=>P.type),reconciledTypes:_.map(P=>P.type),serverMsgs:$(O.messages),currentMsgs:$(p),reconciledMsgs:$(_),paginationTotal:(c=O.pagination)==null?void 0:c.total,paginationOffset:(u=O.pagination)==null?void 0:u.offset,paginationHasMore:(h=O.pagination)==null?void 0:h.hasMore}),i!=null&&i.silent&&_.length===p.length&&_.every((T,E)=>{const N=p[E];return N&&T.type===N.type&&T.timestamp===N.timestamp&&T.content===N.content})){ot.message("fetchMessages → silent skip (no change)",{count:_.length}),t({isLoading:!1});return}ot.message("DEDUP fetchMessages → setting messages",{serverCount:O.messages.length,reconciledCount:_.length,reconciledTypes:_.map(P=>P.type),isStreaming:Ee.getState().isStreaming,segCount:Ee.getState().streamingSegments.length}),t({messages:_,pagination:O.pagination,lastAgentCommand:O.lastAgentCommand??null,isLoading:!1})}catch(O){if(i!=null&&i.silent)return;const p=O instanceof Jr?O.message:we.t("notification:message.loadError");t({error:p,isLoading:!1})}},fetchMoreMessages:async()=>{const r=e(),{currentProjectSlug:n,currentSessionId:i,pagination:s,messages:a,isLoadingMore:o}=r;if(!(!n||!i||!(s!=null&&s.hasMore)||o)){t({isLoadingMore:!0});try{const l=await ea.getMessages(n,i,{limit:s.limit,offset:s.offset+s.limit}),c=[...l.messages,...a];c.sort((u,h)=>new Date(u.timestamp).getTime()-new Date(h.timestamp).getTime()),t({messages:c,pagination:l.pagination,lastAgentCommand:l.lastAgentCommand??e().lastAgentCommand,isLoadingMore:!1})}catch{t({isLoadingMore:!1})}}},clearMessages:()=>{t({messages:[],currentProjectSlug:null,currentSessionId:null,pagination:null,lastAgentCommand:null,error:null})},addOptimisticMessage:(r,n,i)=>{const s=e(),{messages:a}=s,o=a[a.length-1];if(o!=null&&o._optimistic&&(o==null?void 0:o.type)==="user"&&(o==null?void 0:o.content.trim())===r.trim()&&Date.now()-new Date(o.timestamp).getTime()<1e3)return;const l=r.trim(),c=i??new Date().toISOString(),u=`${s.currentSessionId??""}:${c}:${l}`;let h=n;if(n&&n.length>0&&n.every(p=>p.data)){if(Cu.set(u,n),Cu.size>Ume){const p=Cu.keys().next().value;p&&Cu.delete(p)}}else if(n&&n.length>0&&n.every(p=>!p.data)){const p=Cu.get(u);p&&(h=p)}const O={id:`optimistic-${Kr()}`,type:"user",content:l,timestamp:i??new Date().toISOString(),_optimistic:!0,...h&&h.length>0?{images:h}:{}};t({messages:[...a,O]})},addMessages:r=>{r.length!==0&&t(n=>{const i=new Set(n.messages.map(o=>o.id)),s=r.filter(o=>!i.has(o.id));if(ot.message("DEDUP addMessages",{incomingCount:r.length,incomingTypes:r.map(o=>o.type),existingCount:n.messages.length,existingTypes:n.messages.map(o=>o.type),uniqueCount:s.length,duplicateCount:r.length-s.length}),s.length===0)return n;const a=[...n.messages,...s];return a.sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime()),{messages:a}})}})),ki=Zn(t=>({chainItems:[],setChainItems:e=>t({chainItems:e}),clearChainItems:()=>t({chainItems:[]})})),m2=1e3;let wr=null;const pl=new Map,ml=new Map;function BS(t){return t.type==="text"}function FS(t){return t.type==="thinking"}function GS(t){return t.type==="tool"}function f3(t){return t.type==="system"}function O3(t){return t.type==="interactive"}function p3(t){return t.type==="task_notification"}function m3(t){return t.type==="tool_summary"}function g3(t){return t.type==="result_error"}const Ee=Zn((t,e)=>({isStreaming:!1,streamingSessionId:null,streamingMessageId:null,streamingSegments:[],streamingStartedAt:null,lastResultError:null,selectedModel:"",activeModel:null,thinkingExpanded:!1,isCompacting:!1,isSessionLocked:!1,segmentsPendingClear:!1,segmentClearGeneration:0,streamCompletedAt:null,streamCompleteCount:0,projectSettings:null,permissionMode:(()=>{const r=Ht.getState().preferences;return r.permissionMode==="latest"?r.lastPermissionMode??"default":r.permissionMode??"default"})(),contextUsage:null,subscriptionRateLimit:null,apiHealth:null,setStreaming:r=>t({isStreaming:r}),sendMessage:(r,n)=>{const i=Ct(),{workingDirectory:s,sessionId:a,resume:o,attachments:l}=n,c=gt.getState();ot.state("sendMessage",{content:r.slice(0,50),sessionId:a,resume:o,currentMsgCount:c.messages.length,currentMsgTypes:c.messages.map(p=>p.type),segmentCount:e().streamingSegments.length,segmentsPendingClear:e().segmentsPendingClear}),wr&&(clearTimeout(wr),wr=null),e().streamingSegments.length>0&&t({streamingSegments:[]});const u=r.trim()==="/compact";t({isStreaming:!0,isCompacting:u}),wr=setTimeout(()=>{const p=e();p.isStreaming&&p.streamingSegments.length===0&&!p.streamingSessionId&&t({streamingSessionId:a??"pending",streamingMessageId:"pending",streamingSegments:[],streamingStartedAt:new Date}),wr=null},m2);const h=e().projectSettings,O=(h==null?void 0:h.permissionModeOverride)??e().permissionMode;i.emit("chat:send",{content:r,workingDirectory:s,sessionId:a,resume:o,permissionMode:O,...(()=>{const p=Ht.getState().preferences.defaultModel||"",b=(h==null?void 0:h.modelOverride)??p,y=e().selectedModel||b;return y?{model:y}:{}})(),images:l==null?void 0:l.map(p=>({mimeType:p.mimeType,data:p.data,name:p.name}))})},startStreaming:(r,n)=>{ot.state("startStreaming",{sessionId:r,messageId:n,hadDelayTimeout:!!wr,msgCount:gt.getState().messages.length}),wr&&(clearTimeout(wr),wr=null),e().isSessionLocked&&ft.dismiss("session-locked"),t({isStreaming:!0,isSessionLocked:!1,streamingSessionId:r,streamingMessageId:n,streamingSegments:[],streamingStartedAt:new Date,lastResultError:null,segmentsPendingClear:!1,segmentClearGeneration:e().segmentClearGeneration+1,streamCompletedAt:null})},appendStreamingContent:r=>{if(!r)return;const n=e().streamingSegments,i=n[n.length-1];if((i==null?void 0:i.type)==="text"){const s=[...n];s[s.length-1]={type:"text",content:i.content+r},t({streamingSegments:s})}else t({streamingSegments:[...n,{type:"text",content:r}]})},addStreamingThinking:r=>{if(!r)return;const n=e().streamingSegments,i=n[n.length-1];if((i==null?void 0:i.type)==="thinking"){const s=[...n];s[s.length-1]={type:"thinking",content:i.content+r},t({streamingSegments:s})}else t({streamingSegments:[...n,{type:"thinking",content:r}]})},addStreamingToolCall:r=>{const n=e().streamingSegments;if(n.some(a=>a.type==="tool"&&a.toolCall.id===r.id))return;const i=pl.get(r.id);i&&pl.delete(r.id);const s=ml.get(r.id);s&&ml.delete(r.id),t({...e().isCompacting&&{isCompacting:!1},streamingSegments:[...n,{type:"tool",toolCall:{...r,...s&&{input:s},startedAt:r.startedAt??Date.now()},status:"pending",...i&&{permissionId:i,permissionStatus:"waiting"}}]})},updateStreamingToolCallInput:(r,n,i)=>{const s=e().streamingSegments;if(!s.some(l=>l.type==="tool"&&l.toolCall.id===r)){i&&ml.set(r,n);return}const o=s.map(l=>l.type==="tool"&&l.toolCall.id===r?{...l,toolCall:{...l.toolCall,input:n}}:l);t({streamingSegments:o})},updateStreamingToolCall:(r,n,i)=>{const a=e().streamingSegments.map(o=>{if(o.type!=="tool"||o.toolCall.id!==r)return o;const l=o.toolCall.startedAt?Date.now()-o.toolCall.startedAt:void 0;return{...o,toolCall:{...o.toolCall,output:n,duration:l},status:i?"error":"completed",...o.permissionStatus==="waiting"&&{permissionStatus:i?"denied":"approved"}}});t({streamingSegments:a})},completeStreaming:()=>{const r=e();r.isStreaming&&(ot.state("completeStreaming",{sessionId:r.streamingSessionId,messageId:r.streamingMessageId,segmentCount:r.streamingSegments.length,msgCount:gt.getState().messages.length}),pl.clear(),ml.clear(),wr&&(clearTimeout(wr),wr=null),t({isStreaming:!1,isCompacting:!1,streamingSessionId:null,streamingMessageId:null,segmentsPendingClear:!0,segmentClearGeneration:e().segmentClearGeneration+1,streamCompletedAt:Date.now(),streamCompleteCount:e().streamCompleteCount+1}))},abortStreaming:()=>{const r=e();ot.state("abortStreaming",{sessionId:r.streamingSessionId,segmentCount:r.streamingSegments.length,msgCount:gt.getState().messages.length}),pl.clear(),ml.clear(),wr&&(clearTimeout(wr),wr=null),t({isStreaming:!1,isCompacting:!1,streamingSessionId:null,streamingMessageId:null,streamingSegments:[],streamingStartedAt:null,segmentsPendingClear:!1,streamCompletedAt:Date.now()})},abortResponse:()=>{const r=e();if(!r.isStreaming)return;pl.clear(),ml.clear(),wr&&(clearTimeout(wr),wr=null),Ct().emit("chat:abort"),ki.getState().clearChainItems();const i=r.streamingSegments.map(l=>l.type==="tool"&&l.status==="pending"?{...l,status:"error",toolCall:{...l.toolCall,output:we.t("notification:chat.aborted")}}:l);t({isStreaming:!1,isCompacting:!1,streamingSessionId:null,streamingMessageId:null,streamingSegments:i,segmentsPendingClear:!0,segmentClearGeneration:e().segmentClearGeneration+1,streamCompletedAt:Date.now()});const s=e().segmentClearGeneration,{currentProjectSlug:a,currentSessionId:o}=gt.getState();a&&o?gt.getState().fetchMessages(a,o,{silent:!0,force:!0}).then(()=>{e().clearStreamingSegments(s)}).catch(()=>{}):e().clearStreamingSegments(s)},setPermissionMode:r=>{if(t({permissionMode:r}),Ht.getState().updatePreference("lastPermissionMode",r),(Ht.getState().preferences.permissionSyncPolicy==="always"?"always":"streaming")==="streaming"&&!e().isStreaming)return;const s=Ct(),a=gt.getState().currentProjectSlug??void 0;s.emit("permission:mode-change",{mode:r,projectSlug:a})},setContextUsage:r=>t({contextUsage:r}),resetContextUsage:()=>t({contextUsage:null}),setSubscriptionRateLimit:r=>t({subscriptionRateLimit:r}),setApiHealth:r=>t({apiHealth:r}),clearStreamingSegments:r=>{const n=e();r!==void 0&&r!==n.segmentClearGeneration||(ot.state("clearStreamingSegments",{clearedSegmentCount:n.streamingSegments.length,segmentTypes:n.streamingSegments.map(i=>i.type),msgCount:gt.getState().messages.length,isStreaming:n.isStreaming,wasPending:n.segmentsPendingClear,generation:r,currentGeneration:n.segmentClearGeneration}),pl.clear(),ml.clear(),t({streamingSegments:[],segmentsPendingClear:!1,streamingStartedAt:null}))},updateStreamingSessionId:r=>t({streamingSessionId:r}),addSystemSegment:(r,n="compact")=>{const i=e().streamingSegments;t({streamingSegments:[...i,{type:"system",subtype:n,message:r}]})},addInteractiveSegment:r=>{const n=e().streamingSegments;n.some(i=>i.type==="interactive"&&i.id===r.id)||t({streamingSegments:[...n,{type:"interactive",id:r.id,interactionType:r.interactionType,toolCall:r.toolCall,choices:r.choices,questions:r.questions,multiSelect:r.multiSelect,status:"waiting"}]})},setToolPermission:(r,n)=>{const i=e().streamingSegments,s=i.findIndex(l=>l.type==="tool"&&l.toolCall.id===r);if(ot.state("setToolPermission",{toolCallId:r,permissionId:n,foundIdx:s,segmentToolIds:i.filter(l=>l.type==="tool").map(l=>l.toolCall.id)}),s===-1){pl.set(r,n);return}const a=[...i],o=a[s];o.type==="tool"&&(a[s]={...o,permissionId:n,permissionStatus:"waiting"},t({streamingSegments:a}))},respondToolPermission:(r,n)=>{const i=Ct(),s=e().streamingSegments,a=s.findIndex(c=>c.type==="tool"&&c.toolCall.id===r);if(a===-1)return;const o=s[a];if(o.type!=="tool"||!o.permissionId)return;i.emit("permission:respond",{requestId:o.permissionId,approved:n,interactionType:"permission"});const l=[...s];l[a]={...o,permissionStatus:n?"approved":"denied"},t({streamingSegments:l})},respondToInteractive:(r,n)=>{const i=Ct(),s=e().streamingSegments,a=s.findIndex(h=>h.type==="interactive"&&h.id===r);if(a===-1)return;const o=s[a];if(o.type!=="interactive")return;const l=[...s];if(l[a]={...o,status:"sending"},t({streamingSegments:l}),!i.connected){const h=[...e().streamingSegments],O=h[a];(O==null?void 0:O.type)==="interactive"&&(h[a]={...O,status:"error",errorMessage:we.t("notification:streaming.disconnectedRetry")},t({streamingSegments:h}));return}i.emit("permission:respond",{requestId:r,approved:n.approved,interactionType:o.interactionType,response:n.value});const c=[...e().streamingSegments],u=c[a];(u==null?void 0:u.type)==="interactive"&&(c[a]={...u,status:"responded",response:n.value??(n.approved?we.t("chat:interactive.approved"):we.t("chat:interactive.rejected"))},t({streamingSegments:c}))},updateToolProgress:(r,n)=>{const s=e().streamingSegments.map(a=>{if(a.type!=="tool"||a.toolCall.id!==r)return a;const o=Date.now()-n*1e3;return{...a,toolCall:{...a.toolCall,startedAt:o}}});t({streamingSegments:s})},addTaskNotification:r=>{const n=e().streamingSegments;t({streamingSegments:[...n,{type:"task_notification",taskId:r.taskId,status:r.status,outputFile:r.outputFile,summary:r.summary,toolUseId:r.toolUseId}]})},addToolSummary:(r,n)=>{const i=e().streamingSegments;t({streamingSegments:[...i,{type:"tool_summary",summary:r,precedingToolUseIds:n}]})},startStreamingDelay:r=>{wr&&clearTimeout(wr),t({isStreaming:!0}),wr=setTimeout(()=>{const n=e();n.isStreaming&&n.streamingSegments.length===0&&!n.streamingSessionId&&t({streamingSessionId:r??"pending",streamingMessageId:"pending",streamingSegments:[],streamingStartedAt:new Date}),wr=null},m2)},restoreStreaming:r=>{ot.state("DEDUP restoreStreaming called",{sessionId:r,prevSessionId:e().streamingSessionId,prevIsStreaming:e().isStreaming,prevSegmentCount:e().streamingSegments.length,msgCount:gt.getState().messages.length,msgTypes:gt.getState().messages.map(n=>n.type)}),ot.state("restoreStreaming",{sessionId:r,prevSessionId:e().streamingSessionId,prevSegmentCount:e().streamingSegments.length,msgCount:gt.getState().messages.length}),wr&&(clearTimeout(wr),wr=null),e().isSessionLocked&&ft.dismiss("session-locked"),t({isStreaming:!0,isSessionLocked:!1,streamingSessionId:r,streamingMessageId:"restoring",streamingSegments:[],streamingStartedAt:new Date,lastResultError:null,segmentsPendingClear:!1,segmentClearGeneration:e().segmentClearGeneration+1})},setSelectedModel:r=>t({selectedModel:r}),resetSelectedModel:()=>{const r=e().projectSettings,n=Ht.getState().preferences.defaultModel||"",i=(r==null?void 0:r.modelOverride)??n;t({selectedModel:i})},resetPermissionMode:()=>{const r=e().projectSettings;if(r!=null&&r.permissionModeOverride){t({permissionMode:r.permissionModeOverride});return}const n=Ht.getState().preferences;if(n.permissionMode==="latest"){const i=n.lastPermissionMode??e().permissionMode;t({permissionMode:i})}else t({permissionMode:n.permissionMode??"default"})},setActiveModel:r=>t({activeModel:r}),toggleThinkingExpanded:()=>t(r=>({thinkingExpanded:!r.thinkingExpanded})),setProjectSettings:r=>t({projectSettings:r}),addResultError:r=>{const n=e().streamingSegments;t({lastResultError:r,streamingSegments:[...n,{type:"result_error",subtype:r.subtype,errors:r.errors,totalCostUSD:r.totalCostUSD,numTurns:r.numTurns,result:r.result}]})}})),Vme=Object.freeze(Object.defineProperty({__proto__:null,isInteractiveSegment:O3,isResultErrorSegment:g3,isSystemSegment:f3,isTaskNotificationSegment:p3,isTextSegment:BS,isThinkingSegment:FS,isToolSegment:GS,isToolSummarySegment:m3,useChatStore:Ee},Symbol.toStringTag,{value:"Module"}));function Yme(t){const{isRunning:e,isPaused:r,isStarting:n,isCompleted:i,currentIndex:s,totalItems:a,lockedSessionId:o,pauseReason:l,completedItems:c,errorItem:u,itemSessionIds:h}=si(aw(Q=>({isRunning:Q.isRunning,isPaused:Q.isPaused,isStarting:Q.isStarting,isCompleted:Q.isCompleted,currentIndex:Q.currentIndex,totalItems:Q.totalItems,lockedSessionId:Q.lockedSessionId,pauseReason:Q.pauseReason,completedItems:Q.completedItems,errorItem:Q.errorItem,itemSessionIds:Q.itemSessionIds})));k.useEffect(()=>{const Q=Ct(),{handleProgress:_,handleItemComplete:$,handleError:P,handleItemsUpdated:T,syncFromStatus:E}=si.getState();Q.emit("project:join",t);const N=W=>_(W),A=W=>$(W),X=W=>P(W),I=W=>T(W);return Q.on("queue:progress",N),Q.on("queue:itemComplete",A),Q.on("queue:error",X),Q.on("queue:itemsUpdated",I),qn.getStatus(t).then(W=>{E(W)}).catch(()=>{}),()=>{Q.off("queue:progress",N),Q.off("queue:itemComplete",A),Q.off("queue:error",X),Q.off("queue:itemsUpdated",I),Q.emit("project:leave",t),si.getState().reset()}},[t]);const O=k.useCallback((Q,_)=>{const $=Ct(),P=Ee.getState().permissionMode;si.getState().setStarting(!0),$.emit("queue:start",{items:Q,sessionId:_,projectSlug:t,permissionMode:P})},[t]),p=k.useCallback(()=>{Ct().emit("queue:pause",{projectSlug:t})},[t]),b=k.useCallback(()=>{Ct().emit("queue:resume",{projectSlug:t})},[t]),y=k.useCallback(()=>{Ct().emit("queue:abort",{projectSlug:t}),si.getState().reset()},[t]),g=k.useCallback(()=>{Ct().emit("queue:dismiss",{projectSlug:t}),si.getState().reset()},[t]),x=k.useCallback(Q=>{Ct().emit("queue:removeItem",{projectSlug:t,itemIndex:Q})},[t]),v=k.useCallback(Q=>{Ct().emit("queue:addItem",{projectSlug:t,rawLine:Q})},[t]),w=k.useCallback(Q=>{si.getState().optimisticReorder(Q,t),Ct().emit("queue:reorderItems",{projectSlug:t,newOrder:Q})},[t]);return{isRunning:e,isPaused:r,isStarting:n,isCompleted:i,progress:{current:s,total:a},lockedSessionId:o,pauseReason:l,completedItems:c,errorItem:u,itemSessionIds:h,start:O,pause:p,resume:b,abort:y,removeItem:x,addItem:v,reorderItems:w,dismiss:g}}function zn(t){return`Minified Redux error #${t}; visit https://redux.js.org/Errors?code=${t} for the full message or use the non-minified dev environment for full errors. `}var Wme=typeof Symbol=="function"&&Symbol.observable||"@@observable",g2=Wme,b2=()=>Math.random().toString(36).substring(7).split("").join("."),Zme={INIT:`@@redux/INIT${b2()}`,REPLACE:`@@redux/REPLACE${b2()}`},x2=Zme;function Bme(t){if(typeof t!="object"||t===null)return!1;let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e||Object.getPrototypeOf(t)===null}function b3(t,e,r){if(typeof t!="function")throw new Error(zn(2));if(typeof e=="function"&&typeof r=="function"||typeof r=="function"&&typeof arguments[3]=="function")throw new Error(zn(0));if(typeof e=="function"&&typeof r>"u"&&(r=e,e=void 0),typeof r<"u"){if(typeof r!="function")throw new Error(zn(1));return r(b3)(t,e)}let n=t,i=e,s=new Map,a=s,o=0,l=!1;function c(){a===s&&(a=new Map,s.forEach((g,x)=>{a.set(x,g)}))}function u(){if(l)throw new Error(zn(3));return i}function h(g){if(typeof g!="function")throw new Error(zn(4));if(l)throw new Error(zn(5));let x=!0;c();const v=o++;return a.set(v,g),function(){if(x){if(l)throw new Error(zn(6));x=!1,c(),a.delete(v),s=null}}}function O(g){if(!Bme(g))throw new Error(zn(7));if(typeof g.type>"u")throw new Error(zn(8));if(typeof g.type!="string")throw new Error(zn(17));if(l)throw new Error(zn(9));try{l=!0,i=n(i,g)}finally{l=!1}return(s=a).forEach(v=>{v()}),g}function p(g){if(typeof g!="function")throw new Error(zn(10));n=g,O({type:x2.REPLACE})}function b(){const g=h;return{subscribe(x){if(typeof x!="object"||x===null)throw new Error(zn(11));function v(){const Q=x;Q.next&&Q.next(u())}return v(),{unsubscribe:g(v)}},[g2](){return this}}}return O({type:x2.INIT}),{dispatch:O,subscribe:h,getState:u,replaceReducer:p,[g2]:b}}function y2(t,e){return function(...r){return e(t.apply(this,r))}}function v2(t,e){if(typeof t=="function")return y2(t,e);if(typeof t!="object"||t===null)throw new Error(zn(16));const r={};for(const n in t){const i=t[n];typeof i=="function"&&(r[n]=y2(i,e))}return r}function x3(...t){return t.length===0?e=>e:t.length===1?t[0]:t.reduce((e,r)=>(...n)=>e(r(...n)))}function Fme(...t){return e=>(r,n)=>{const i=e(r,n);let s=()=>{throw new Error(zn(15))};const a={getState:i.getState,dispatch:(l,...c)=>s(l,...c)},o=t.map(l=>l(a));return s=x3(...o)(i.dispatch),{...i,dispatch:s}}}var Oy={exports:{}},py={};/**
793
793
  * @license React
@@ -1349,7 +1349,7 @@ ${a}`:a;return d.jsxs("div",{"data-testid":"tool-result-bash",children:[d.jsx(v0
1349
1349
  focus:outline-none focus:ring-2 focus:ring-blue-500`}),d.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-300",children:t("advanced.maxBudgetDesc")})]})]})}const Om=[{id:"global",titleKey:"tabs.global",icon:aa},{id:"project",titleKey:"tabs.project",icon:Zte},{id:"notifications",titleKey:"tabs.notifications",icon:Eg},{id:"advanced",titleKey:"tabs.advanced",icon:sw},{id:"help",titleKey:"tabs.help",icon:xte},{id:"about",titleKey:"tabs.about",icon:tw}],NRe=Om.map(t=>t.id);function aE(){const{t}=Ce("settings"),{t:e}=Ce("common"),r=En(),{tab:n}=jn(),{logout:i}=Xo(),s=n&&NRe.includes(n)?n:"global",[a,o]=k.useState(s),l=k.useRef(null),c=()=>{r("/")},u=k.useCallback(async()=>{await i(),r("/login",{replace:!0})},[i,r]),h=k.useRef(null),O=b=>{const y=a!==b;o(g=>g===b?null:b),h.current=y?b:null};k.useEffect(()=>{const b=h.current;b&&(h.current=null,requestAnimationFrame(()=>{const y=document.getElementById(`settings-section-${b}`),g=l.current;if(y&&g){const x=y.getBoundingClientRect(),v=g.getBoundingClientRect(),w=g.scrollTop+(x.top-v.top);g.scrollTop=w}}))},[a]);const p=b=>{switch(b){case"global":return d.jsx(vRe,{});case"project":return d.jsx(kRe,{});case"notifications":return d.jsxs(d.Fragment,{children:[d.jsxs("h3",{className:"text-sm font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2",children:[d.jsx(Eg,{className:"w-4 h-4"}),"Web Push"]}),d.jsx(PRe,{}),d.jsx("hr",{className:"my-8 border-gray-200 dark:border-[#2d3a4a]"}),d.jsxs("h3",{className:"text-sm font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2",children:[d.jsx(Dg,{className:"w-4 h-4"}),"Telegram"]}),d.jsx(QRe,{})]});case"advanced":return d.jsx(ARe,{});case"help":return d.jsx(ERe,{});case"about":return d.jsx(XRe,{})}};return d.jsxs("div",{className:"h-dvh flex flex-col bg-white dark:bg-[#1c2129] transition-colors duration-200",children:[d.jsx("header",{className:"flex-shrink-0 sticky top-0 z-10 bg-gray-50 dark:bg-[#263240] border-b border-gray-200 dark:border-[#253040]",children:d.jsxs("div",{className:"content-container flex items-center px-4 py-3 min-h-14",children:[d.jsx("button",{onClick:c,className:`p-2 -ml-2 mr-3 hover:bg-gray-100 dark:hover:bg-[#253040] rounded-lg\r
1350
1350
  text-gray-700 dark:text-gray-200\r
1351
1351
  focus:outline-none focus:ring-2 focus:ring-blue-500`,"aria-label":t("page.backAriaLabel"),children:d.jsx(Rg,{className:"w-5 h-5","aria-hidden":"true"})}),d.jsx("h1",{className:"text-lg font-semibold text-gray-900 dark:text-white flex-1",children:t("page.title")}),d.jsx($h,{className:"hidden sm:block"}),d.jsx("button",{onClick:u,"aria-label":e("project.logout"),title:e("project.logout"),className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-[#253040] text-red-600 dark:text-red-400 transition-colors",children:d.jsx(Cre,{className:"w-5 h-5","aria-hidden":"true"})})]})}),d.jsxs("div",{className:"content-container hidden md:flex flex-1 overflow-hidden w-full",children:[d.jsx("nav",{className:"flex-shrink-0 border-r border-gray-200 dark:border-[#253040] overflow-y-auto py-4 px-3",children:Om.map(b=>d.jsxs("button",{onClick:()=>r(`/settings/${b.id}`),className:`flex items-center gap-3 w-full px-4 py-2.5 text-sm rounded-lg transition-colors mb-1
1352
- ${s===b.id?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300 font-medium":"text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040]"}`,children:[d.jsx(b.icon,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}),d.jsx("span",{className:"whitespace-nowrap",children:t(b.titleKey)})]},b.id))}),d.jsxs("main",{className:"flex-1 min-w-0 overflow-y-auto p-6",children:[d.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-white mb-4",children:t(Om.find(b=>b.id===s).titleKey)}),p(s)]})]}),d.jsx("div",{ref:l,className:"content-container md:hidden flex-1 overflow-y-auto w-full",style:{scrollBehavior:"auto"},children:Om.map(b=>d.jsx(xRe,{sectionId:b.id,title:t(b.titleKey),icon:b.icon,isExpanded:a===b.id,onToggle:()=>O(b.id),children:p(b.id)},b.id))})]})}const oE=[{id:"overview",labelKey:"tabs.overview",icon:lj,path:""},{id:"board",labelKey:"tabs.board",icon:Lv,path:"/board"},{id:"sessions",labelKey:"tabs.sessions",icon:Wo,path:"/sessions"},{id:"queue",labelKey:"tabs.queue",icon:Ag,path:"/queue"},{id:"files",labelKey:"tabs.files",icon:Ns,path:"/files"},{id:"git",labelKey:"tabs.git",icon:No,path:"/git"},{id:"terminal",labelKey:"tabs.terminal",icon:Es,path:"/terminal"}];function DRe(){const{t}=Ce("common"),{projectSlug:e}=jn(),r=En(),n=fs(),{projects:i,fetchProjects:s}=Ga(),{connectionStatus:a,reconnectAttempt:o,lastError:l,connect:c}=Ek(),u=Ut(_=>_.terminalAccess),h=(u==null?void 0:u.enabled)!==!1,O=(u==null?void 0:u.allowed)??!0;k.useEffect(()=>{i.length===0&&s()},[i.length,s]);const[p,b]=k.useState(!1),y=k.useRef(null);Ch(y,()=>b(!1));const g=k.useMemo(()=>{const _=i.find($=>$.projectSlug===e);return(_==null?void 0:_.originalPath)||e||""},[i,e]),x=k.useMemo(()=>{const _=g.replace(/\\/g,"/").split("/");return _[_.length-1]||g},[g]),v=k.useMemo(()=>{const _=`/project/${e}`;for(const $ of[...oE].reverse())if($.path&&n.pathname.startsWith(`${_}${$.path}`))return $.id;return"overview"},[n.pathname,e]),w=()=>r("/"),Q=_=>{r(`/project/${e}${_}`)};return d.jsxs("div",{className:"h-dvh flex flex-col bg-white dark:bg-[#1c2129] transition-colors duration-200",children:[d.jsxs("header",{className:"flex-shrink-0 sticky top-0 z-10 bg-[#243648] dark:bg-[#171e24] border-b border-slate-200 dark:border-slate-700/50",children:[d.jsxs("div",{className:"content-container flex items-center justify-between px-4 py-3 min-h-14",children:[d.jsxs("div",{className:"flex items-stretch min-w-0 flex-1",children:[d.jsx("button",{onClick:w,className:"self-center p-2 -ml-2 mr-2 hover:bg-white/10 dark:hover:bg-[#253040] rounded-lg text-white/80 dark:text-gray-200","aria-label":t("layout.back"),children:d.jsx(Rg,{className:"w-5 h-5"})}),d.jsx(km,{}),d.jsx("div",{className:"w-px self-stretch bg-gray-200 dark:bg-[#253040] mx-3"}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsx("h1",{className:"text-base font-semibold truncate text-white dark:text-white",children:x}),d.jsx("p",{className:"text-xs text-white/60 dark:text-gray-400 truncate",children:g})]})]}),d.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[d.jsx(fD,{status:a,reconnectAttempt:o,lastError:l,onReconnect:c,compact:!0}),d.jsx($h,{className:"hidden sm:block"}),d.jsx("button",{onClick:()=>window.location.reload(),"aria-label":t("layout.refresh"),className:"hidden sm:block p-2 rounded-lg hover:bg-white/10 dark:hover:bg-[#253040] text-white/80 dark:text-gray-200 transition-colors",children:d.jsx(Ir,{className:"w-5 h-5","aria-hidden":"true"})}),d.jsx("button",{onClick:()=>r("/settings"),"aria-label":t("project.settings"),className:"hidden sm:block p-2 rounded-lg hover:bg-white/10 dark:hover:bg-[#253040] text-white/80 dark:text-gray-200 transition-colors",children:d.jsx(aa,{className:"w-5 h-5","aria-hidden":"true"})}),d.jsxs("div",{className:"relative sm:hidden",ref:y,children:[d.jsx("button",{onClick:()=>b(!p),className:"p-2 hover:bg-white/10 dark:hover:bg-[#253040] rounded-lg text-white/80 dark:text-gray-200","aria-label":t("project.menuLabel"),"aria-expanded":p,"aria-haspopup":"menu",children:d.jsx(Ba,{className:"w-5 h-5"})}),p&&d.jsxs("div",{role:"menu",className:"absolute right-0 top-full mt-2 w-48 bg-white dark:bg-[#263240] rounded-lg shadow-lg border border-gray-200 dark:border-[#253040] z-50 py-1",children:[d.jsxs("button",{role:"menuitem",onClick:()=>window.location.reload(),className:"w-full px-4 py-2 text-left text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] flex items-center gap-2",children:[d.jsx(Ir,{className:"w-4 h-4"}),t("layout.refresh")]}),d.jsx("div",{className:"border-t border-gray-200 dark:border-[#253040] my-1"}),d.jsxs("button",{role:"menuitem",onClick:()=>{r("/settings"),b(!1)},className:"w-full px-4 py-2 text-left text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] flex items-center gap-2",children:[d.jsx(aa,{className:"w-4 h-4"}),t("project.settings")]})]})]})]})]}),d.jsx("nav",{className:"content-container flex px-4","aria-label":t("layout.projectTabs"),children:oE.map(_=>{if(_.id==="terminal"&&!h)return null;const $=v===_.id,P=_.icon,T=_.id==="terminal"&&!O;return d.jsxs("button",{onClick:T?void 0:()=>Q(_.path),disabled:T,className:`flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${T?"border-transparent opacity-50 cursor-not-allowed text-gray-500 dark:text-gray-400":$?"border-blue-300 text-blue-200 dark:text-blue-400":"border-transparent text-white/50 dark:text-gray-300 hover:text-white/80 dark:hover:text-gray-300 hover:border-white/30 dark:hover:border-[#2d3a4a]"}`,"aria-current":$?"page":void 0,"aria-disabled":T||void 0,"aria-label":T?t("layout.terminalDisabled"):void 0,children:[d.jsx(P,{className:"w-4 h-4"}),d.jsx("span",{className:"hidden sm:inline",children:t(_.labelKey)})]},_.id)})})]}),d.jsx("main",{className:"flex-1 overflow-auto",children:d.jsx("div",{className:"content-container h-full",children:d.jsx(PK,{})})})]})}let pm=!1,q1=null;const xI="cli-status-cache",LRe=3600*1e3;function IRe(){try{const t=sessionStorage.getItem(xI);if(!t)return null;const{status:e,timestamp:r}=JSON.parse(t);return Date.now()-r>LRe?null:e!=null&&e.authenticated||e!=null&&e.apiKeySet?e:null}catch{return null}}function MRe(t){try{sessionStorage.setItem(xI,JSON.stringify({status:t,timestamp:Date.now()}))}catch{}}const lE=IRe();lE&&(pm=!0,q1=lE);function Ac({children:t}){const{t:e}=Ce("common"),{isAuthenticated:r,isLoading:n,checkAuth:i}=Xo(),s=fs(),[a,o]=k.useState(q1),[l,c]=k.useState(!pm),[u,h]=k.useState(null),[O,p]=k.useState(!1),b=k.useCallback(async(g=!1)=>{if(!g&&pm)return;c(!0),h(null);const x=2,v=1500;for(let w=0;w<=x;w++)try{const Q=await qe.get("/cli-status");console.log("[AuthGuard] CLI status response:",Q),o(Q),q1=Q,pm=!0,MRe(Q);const _=!Q.authenticated&&!Q.apiKeySet;p(_),c(!1);return}catch(Q){if(console.error("[AuthGuard] CLI status fetch failed (attempt",w+1,"):",Q),Q instanceof Jr&&Q.status===401){console.warn("[AuthGuard] Session expired during CLI status check, re-checking auth"),c(!1),Xo.getState().recheckAuth();return}if(w<x){await new Promise(_=>setTimeout(_,v));continue}h(Q instanceof Error?Q.message:e("error.cliStatusFailed")),p(!1),c(!1)}},[]);if(k.useEffect(()=>{i()},[i]),k.useEffect(()=>{r&&!n&&s.pathname!=="/onboarding"?b():s.pathname==="/onboarding"&&c(!1)},[r,n,s.pathname,b]),n)return d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-100 dark:bg-[#1c2129]",children:d.jsx(kh,{size:"lg"})});if(!r)return d.jsx(Pv,{to:"/login",state:{from:s},replace:!0});if(l&&s.pathname!=="/onboarding")return d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-[#1c2129]",role:"status","aria-label":e("loading"),children:d.jsxs("div",{className:"flex flex-col items-center gap-3",children:[d.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500","aria-hidden":"true"}),d.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-300",children:e("cliStatusChecking")})]})});if(O&&s.pathname!=="/onboarding")return d.jsx(Pv,{to:"/onboarding",replace:!0});const y={cliStatus:a,isLoading:l,error:u,refetch:b,isReady:(a==null?void 0:a.authenticated)===!0||(a==null?void 0:a.apiKeySet)===!0};return d.jsx(Une,{value:y,children:t})}function zRe({children:t}){const{isAuthenticated:e,isLoading:r,checkAuth:n}=Xo(),i=En();return k.useEffect(()=>{n()},[n]),k.useEffect(()=>{!r&&e&&i("/",{replace:!0})},[e,r,i]),r?d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-100 dark:bg-[#1c2129]",children:d.jsx(kh,{size:"lg"})}):e?null:d.jsx(d.Fragment,{children:t})}function qRe({content:t}){return d.jsx("div",{className:"flex-1 overflow-y-auto p-4 bg-white dark:bg-[#1c2129]",children:d.jsx("div",{className:"max-w-4xl mx-auto",children:d.jsx(S0,{content:t})})})}const URe=k.lazy(()=>J(()=>import("./index-B-d8nJ3b.js"),[]));function VRe(){const{openFile:t,content:e,isDirty:r,isLoading:n,isSaving:i,isTruncated:s,error:a,isMarkdownPreview:o,saveFile:l,closeEditor:c,setContent:u,resetError:h,openFileInEditor:O,toggleMarkdownPreview:p,pendingNavigation:b,confirmPendingNavigation:y,cancelPendingNavigation:g}=bn(),{t:x}=Ce("common"),[v,w]=k.useState(!1),Q=k.useRef(null),_=k.useRef(null),{resolvedTheme:$}=Cd(),P=Td(),T=pa(U=>U.activePanel),E=pa(U=>U.panelWidth),N=480,[A,X]=k.useState(()=>typeof window<"u"?window.innerWidth:1024);k.useEffect(()=>{const U=()=>X(window.innerWidth);return window.addEventListener("resize",U),()=>window.removeEventListener("resize",U)},[]);const W=!(P||T!==null&&A-E<N)&&T?E:0,Y=t?c3(t.path):!1,te=k.useMemo(()=>{const U=[Ye.lineWrapping];if(t){const z=l3(t.path);z&&U.push(z)}return s&&U.push(Ye.editable.of(!1)),U},[t,s]),ee=k.useCallback(async()=>{if(!r||i)return;await l()?ft.success(x("editor.fileSaved")):ft.error(x("editor.fileSaveFailed"))},[r,i,l]),B=k.useCallback(()=>{b&&g(),r?w(!0):c()},[r,c,b,g]);k.useEffect(()=>{t&&(_.current={...t})},[t]);const D=k.useCallback(()=>{_.current&&O(_.current.projectSlug,_.current.path)},[O]);u0(!!t,B,D),k.useEffect(()=>{if(!t)return;const U=z=>{if((z.ctrlKey||z.metaKey)&&z.key==="s"){z.preventDefault(),ee();return}if(z.key==="Escape"){if(z.stopImmediatePropagation(),b)return;if(v){w(!1);return}B()}};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},[t,ee,B,v,b]),k.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]),k.useEffect(()=>{var U;!o&&Y&&((U=Q.current)==null||U.focus())},[o,Y]);const R=k.useCallback(U=>{Q.current=U;const z=bn.getState().targetLine;z&&requestAnimationFrame(()=>{try{const K=Math.min(z,U.state.doc.lines),oe=U.state.doc.line(K);U.dispatch({selection:{anchor:oe.from},effects:Ye.scrollIntoView(oe.from,{y:"start",yMargin:8})})}catch{}bn.setState({targetLine:null})})},[]);if(!t)return null;const M=t.path;return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 z-[55] transition-[right] duration-300 ease-in-out",style:{right:W},onClick:U=>{U.stopPropagation(),B()}}),d.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col bg-white dark:bg-[#1c2129] transition-[right] duration-300 ease-in-out",style:{right:W},children:[d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-[#253040] bg-gray-50 dark:bg-[#263240]",children:[d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(Fa,{className:"w-4 h-4 shrink-0 text-gray-500 dark:text-gray-300"}),d.jsx("span",{className:"truncate text-sm font-mono text-gray-700 dark:text-gray-200",children:M}),r&&d.jsx("span",{className:"text-xs font-bold text-amber-500 shrink-0",children:"M"})]}),d.jsxs("div",{className:"flex items-center gap-2 ml-3 shrink-0",children:[Y&&d.jsx("button",{onClick:p,className:"flex items-center gap-1 px-3 py-1 text-sm font-medium whitespace-nowrap text-gray-700 dark:text-gray-200 bg-gray-100 dark:bg-[#253040] hover:bg-gray-200 dark:hover:bg-[#2d3a4a] rounded transition-colors",title:x(o?"editor.editMode":"editor.previewLabel"),"aria-label":x(o?"editor.editMode":"editor.previewLabel"),children:o?d.jsxs(d.Fragment,{children:[d.jsx(Ng,{className:"w-4 h-4"}),d.jsx("span",{children:x("editor.editLabel")})]}):d.jsxs(d.Fragment,{children:[d.jsx(Jc,{className:"w-4 h-4"}),d.jsx("span",{children:x("editor.previewLabel")})]})}),d.jsx("button",{onClick:ee,disabled:!r||i,title:x("editor.saveShortcut"),className:"px-3 py-1 text-sm font-medium whitespace-nowrap text-white bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 rounded disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:x(i?"editor.saving":"editor.save")}),d.jsx("button",{onClick:B,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300","aria-label":x("editor.close"),children:d.jsx(Vt,{className:"w-5 h-5"})})]})]}),n?d.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"ml-2 text-sm text-gray-500 dark:text-gray-300",children:x("editor.loadingFile")})]}):a?d.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 text-red-500",children:[d.jsx("p",{children:a}),d.jsx("button",{onClick:()=>{h(),O(t.projectSlug,t.path)},className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors",children:x("button.retry")})]}):d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"px-4 py-2 bg-amber-50 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300 text-xs border-b border-amber-200 dark:border-amber-800",children:x("editor.fileTruncated")}),o&&Y?d.jsx(qRe,{content:e}):d.jsx("div",{className:"flex-1 min-h-0 [&_.cm-editor]:h-full [&_.cm-scroller]:!overflow-auto","aria-label":`Editing ${M}`,children:d.jsx(k.Suspense,{fallback:d.jsxs("div",{className:"h-full flex items-center justify-center",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"ml-2 text-sm text-gray-500 dark:text-gray-300",children:x("editor.loadingEditor")})]}),children:d.jsx(URe,{value:e,extensions:te,theme:$==="dark"?sD:"light",onChange:U=>u(U),onCreateEditor:R,height:"100%",style:{height:"100%"},basicSetup:{lineNumbers:!0,highlightActiveLine:!0,tabSize:2,foldGutter:!1},readOnly:s})})})]})]}),d.jsx(Ma,{isOpen:v,title:x("editor.unsavedTitle"),message:x("editor.unsavedCloseMessage"),confirmText:x("editor.closeWithoutSaving"),cancelText:x("button.cancel"),variant:"danger",onConfirm:()=>{c(),w(!1)},onCancel:()=>w(!1)}),d.jsx(Ma,{isOpen:!!b,title:x("editor.unsavedTitle"),message:x("editor.unsavedOpenMessage",{path:(b==null?void 0:b.path)??""}),confirmText:x("editor.openWithoutSaving"),cancelText:x("button.cancel"),variant:"danger",onConfirm:y,onCancel:g})]})}const Ip=.25,YRe=.1,WRe=10;function ZRe(){const{openImage:t,zoomLevel:e,closeViewer:r,setZoom:n,resetView:i}=Vo(),{t:s}=Ce("common"),[a,o]=k.useState(!0),[l,c]=k.useState(!1),[u,h]=k.useState(!1),[O,p]=k.useState({x:0,y:0}),b=k.useRef({x:0,y:0}),y=k.useRef({x:0,y:0}),g=k.useRef(null),x=Td(),v=pa(R=>R.activePanel),w=pa(R=>R.panelWidth),Q=480,[_,$]=k.useState(()=>typeof window<"u"?window.innerWidth:1024);k.useEffect(()=>{const R=()=>$(window.innerWidth);return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[]);const T=!(x||v!==null&&_-w<Q)&&v?w:0,E=k.useCallback(()=>{r()},[r]);k.useEffect(()=>{t&&(g.current={...t})},[t]);const N=k.useCallback(()=>{g.current&&Vo.getState().openImageViewer(g.current.projectSlug,g.current.path)},[]);u0(!!t,E,N),k.useEffect(()=>{t&&(o(!0),c(!1),p({x:0,y:0}))},[t]),k.useEffect(()=>{if(!t)return;const R=M=>{M.key==="Escape"&&(M.stopImmediatePropagation(),E())};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[t,E]),k.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]);const A=k.useCallback(R=>{R.preventDefault();const M=R.deltaY>0?-Ip:Ip;n(e+M)},[e,n]),X=k.useCallback(R=>{R.button===0&&(h(!0),b.current={x:R.clientX,y:R.clientY},y.current={...O})},[O]),I=k.useCallback(R=>{u&&p({x:y.current.x+(R.clientX-b.current.x),y:y.current.y+(R.clientY-b.current.y)})},[u]),W=k.useCallback(()=>{h(!1)},[]),Y=k.useCallback(()=>{i(),p({x:0,y:0})},[i]);if(!t)return null;const te=t.path,ee=te.includes("/")?te.split("/").pop():te,B=`/api/projects/${t.projectSlug}/fs/raw?path=${encodeURIComponent(te)}`,D=Math.round(e*100);return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 z-[55] transition-[right] duration-300 ease-in-out",style:{right:T},onClick:E}),d.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col bg-white dark:bg-[#1c2129] transition-[right] duration-300 ease-in-out",style:{right:T},children:[d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-[#253040] bg-gray-50 dark:bg-[#263240]",children:[d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(y$,{className:"w-4 h-4 shrink-0 text-gray-500 dark:text-gray-300"}),d.jsx("span",{className:"truncate text-sm font-mono text-gray-700 dark:text-gray-200",children:te})]}),d.jsxs("div",{className:"flex items-center gap-1 ml-3",children:[d.jsx("button",{onClick:()=>n(e-Ip),disabled:e<=YRe,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300 disabled:opacity-40",title:s("imageViewer.zoomOut"),children:d.jsx(qne,{className:"w-4 h-4"})}),d.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-300 w-12 text-center tabular-nums",children:[D,"%"]}),d.jsx("button",{onClick:()=>n(e+Ip),disabled:e>=WRe,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300 disabled:opacity-40",title:s("imageViewer.zoomIn"),children:d.jsx(Mne,{className:"w-4 h-4"})}),d.jsx("button",{onClick:Y,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300",title:s("imageViewer.resetZoom"),children:d.jsx(rw,{className:"w-4 h-4"})}),d.jsx("div",{className:"w-px h-5 bg-gray-200 dark:bg-[#253040] mx-1"}),d.jsx("button",{onClick:E,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300","aria-label":s("imageViewer.close"),children:d.jsx(Vt,{className:"w-5 h-5"})})]})]}),d.jsxs("div",{className:`flex-1 overflow-hidden flex items-center justify-center bg-gray-100 dark:bg-gray-950 ${u?"cursor-grabbing":"cursor-grab"}`,onWheel:A,onMouseDown:X,onMouseMove:I,onMouseUp:W,onMouseLeave:W,children:[a&&!l&&d.jsxs("div",{className:"absolute flex items-center gap-2",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-300",children:s("imageViewer.loadingImage")})]}),l?d.jsxs("div",{className:"flex flex-col items-center gap-2 text-red-500",children:[d.jsx(y$,{className:"w-12 h-12 opacity-50"}),d.jsx("p",{className:"text-sm",children:s("imageViewer.loadFailed")}),d.jsx("p",{className:"text-xs text-gray-400",children:ee})]}):d.jsx("img",{src:B,alt:ee,draggable:!1,className:"select-none transition-opacity duration-200",style:{transform:`translate(${O.x}px, ${O.y}px) scale(${e})`,opacity:a?0:1,maxWidth:"none",maxHeight:"none"},onLoad:()=>o(!1),onError:()=>{o(!1),c(!0)}})]})]})]})}function BRe({entryType:t,initialValue:e,onConfirm:r,onCancel:n}){const{t:i}=Ce("common"),[s,a]=k.useState(e),o=k.useRef(null);k.useEffect(()=>{if(o.current&&(o.current.focus(),e)){const u=e.lastIndexOf("."),h=u>0?u:e.length;o.current.setSelectionRange(0,h)}},[]);const l=u=>{u.key==="Enter"?(u.preventDefault(),r(s)):u.key==="Escape"&&(u.preventDefault(),n())},c=()=>{s.trim()?r(s):n()};return d.jsxs("div",{className:"flex flex-col items-center gap-1 p-2 rounded-lg",children:[t==="directory"?d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}):d.jsx(Nl,{className:"w-8 h-8 text-gray-500 dark:text-gray-400"}),d.jsx("input",{ref:o,type:"text",value:s,onChange:u=>a(u.target.value),onKeyDown:l,onBlur:c,className:"text-xs text-center w-full bg-white dark:bg-[#1c2129] dark:text-white border border-blue-500 rounded px-1 py-0 outline-none h-4 leading-4","aria-label":i("files.renameAria")})]})}function FRe({projectSlug:t,currentPath:e,showHidden:r,onFileSelect:n,onNavigate:i,enableContextMenu:s=!1,onCreateEntry:a,onDeleteEntry:o,onRenameEntry:l,onCopy:c,onCut:u,onPaste:h,onDownload:O,hasClipboard:p=!1,cutPath:b,refreshTrigger:y,onFileDrop:g,isUploading:x=!1}){const{t:v}=Ce("common"),[w,Q]=k.useState([]),[_,$]=k.useState(!0),[P,T]=k.useState(!1),[E,N]=k.useState(null),[A,X]=k.useState(null),[I,W]=k.useState(null),[Y,te]=k.useState(null),ee=bn(me=>{var xe;return((xe=me.openFile)==null?void 0:xe.path)??null}),B=k.useCallback(async()=>{$(!0),N(null),Q([]);try{const me=await ni.listDirectory(t,e);Q(me.entries)}catch(me){N(me.message)}finally{$(!1)}},[t,e]);k.useEffect(()=>{B()},[B]),k.useEffect(()=>{y===void 0||y===0||B()},[y]),k.useEffect(()=>{if(!_){T(!1);return}const me=setTimeout(()=>T(!0),300);return()=>clearTimeout(me)},[_]);const D=k.useMemo(()=>{const me=_0(w);return r?me:me.filter(xe=>!Q0.includes(xe.name))},[w,r]),R=k.useCallback(me=>{const xe=e==="."?me.name:`${e}/${me.name}`;me.type==="directory"?i(xe):n(xe)},[e,i,n]),M=k.useCallback((me,xe)=>{if(!s)return;me.preventDefault(),me.stopPropagation(),me.nativeEvent.stopImmediatePropagation();const ht=e==="."?xe.name:`${e}/${xe.name}`,St=xe.type==="directory"?ht:e;X({x:me.clientX,y:me.clientY,targetPath:ht,targetType:xe.type,parentPath:St})},[s,e]),U=k.useCallback((me,xe)=>{if(!s)return;me.stopPropagation();const ht=me.currentTarget.getBoundingClientRect(),St=e==="."?xe.name:`${e}/${xe.name}`,wt=xe.type==="directory"?St:e;X({x:ht.right,y:ht.bottom,targetPath:St,targetType:xe.type,parentPath:wt})},[s,e]),z=k.useCallback(me=>{if(!s)return;const xe=me.target;xe instanceof Element&&xe.closest("[data-grid-item]")||(me.preventDefault(),me.stopPropagation(),me.nativeEvent.stopImmediatePropagation(),X({x:me.clientX,y:me.clientY,targetPath:e,targetType:"directory",parentPath:e}))},[s,e]),K=k.useCallback(me=>{A&&(W({mode:"create",parentPath:A.parentPath,entryType:me,initialValue:""}),X(null))},[A]),oe=k.useCallback(()=>{if(!A)return;const me=A.targetPath.includes("/")?A.targetPath.split("/").pop():A.targetPath;W({mode:"rename",parentPath:e,targetPath:A.targetPath,entryType:A.targetType,initialValue:me}),X(null)},[A,e]),le=k.useCallback(async me=>{if(!I||!me.trim()){W(null);return}try{I.mode==="create"?(await(a==null?void 0:a(I.parentPath,I.entryType,me.trim())),await B()):I.mode==="rename"&&I.targetPath&&me.trim()!==I.initialValue&&(await(l==null?void 0:l(I.targetPath,me.trim())),await B())}catch{}W(null)},[I,a,l,B]),Z=k.useCallback(()=>{if(!A)return;const me=A.targetPath.includes("/")?A.targetPath.split("/").pop():A.targetPath;te({path:A.targetPath,name:me,type:A.targetType}),X(null)},[A]),V=k.useCallback(async()=>{if(Y){try{await(o==null?void 0:o(Y.path)),await B()}catch{}te(null)}},[Y,o,B]),[ne,G]=k.useState(!1),he=k.useRef(0),se=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),he.current++,he.current===1&&G(!0))},[g]),ce=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),me.dataTransfer.dropEffect="copy")},[g]),re=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),he.current=Math.max(0,he.current-1),he.current===0&&G(!1))},[g]),Qe=k.useCallback(me=>{if(!g)return;me.preventDefault(),he.current=0,G(!1);const xe=Array.from(me.dataTransfer.files);xe.length>0&&g(xe)},[g]);return k.useEffect(()=>{const me=()=>{he.current=0,G(!1)};return window.addEventListener("dragend",me),window.addEventListener("drop",me),()=>{window.removeEventListener("dragend",me),window.removeEventListener("drop",me)}},[]),_&&w.length===0?P?d.jsxs("div",{className:"flex items-center gap-2 p-4 text-sm text-gray-500 dark:text-gray-300 justify-center",children:[d.jsx(vt,{className:"w-4 h-4 animate-spin"}),d.jsx("span",{children:v("loadingStatus")})]}):null:E&&w.length===0?d.jsx("div",{className:"p-4",children:d.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 dark:text-red-400",children:[d.jsx(ji,{className:"w-3.5 h-3.5"}),d.jsx("span",{children:E}),d.jsx("button",{className:"text-xs text-blue-500 dark:text-blue-400 hover:underline cursor-pointer ml-2",onClick:B,children:v("button.retry")})]})}):d.jsxs("div",{className:"p-2 relative",onContextMenu:z,onDragEnter:se,onDragOver:ce,onDragLeave:re,onDrop:Qe,children:[ne&&d.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-blue-50/80 dark:bg-blue-900/30 border-2 border-dashed border-blue-400 dark:border-blue-500 rounded-lg pointer-events-none",children:d.jsxs("div",{className:"flex flex-col items-center gap-2 text-blue-600 dark:text-blue-400",children:[d.jsx(Ph,{className:"w-8 h-8"}),d.jsx("span",{className:"text-sm font-medium",children:v("files.dropHere")})]})}),x&&d.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/60 dark:bg-[#1c2129]/60 rounded-lg pointer-events-none",children:d.jsxs("div",{className:"flex items-center gap-2 text-gray-600 dark:text-gray-300",children:[d.jsx(vt,{className:"w-5 h-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:v("files.uploading")})]})}),(I==null?void 0:I.mode)==="create"&&d.jsx("div",{className:"mb-2",children:d.jsx(Sg,{initialValue:I.initialValue,entryType:I.entryType,depth:0,onConfirm:le,onCancel:()=>W(null)})}),D.length===0&&!I?d.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 italic text-center py-8",children:v("files.emptyFolder")}):d.jsxs("div",{className:"grid grid-cols-5 sm:grid-cols-7 md:grid-cols-9 gap-1",children:[e!=="."&&d.jsxs("div",{"data-grid-item":!0,role:"button",tabIndex:0,className:"group relative flex flex-col items-center gap-1 p-2 rounded-lg cursor-pointer transition-colors hover:bg-gray-100 dark:hover:bg-[#253040]/50",onClick:()=>{const me=e.includes("/")?e.substring(0,e.lastIndexOf("/")):".";i(me)},onKeyDown:me=>{if(me.key==="Enter"){const xe=e.includes("/")?e.substring(0,e.lastIndexOf("/")):".";i(xe)}},children:[d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}),d.jsx("span",{className:"text-xs text-center w-full truncate text-gray-500 dark:text-gray-300",children:v("files.parentDir")})]}),D.map(me=>{const xe=e==="."?me.name:`${e}/${me.name}`,ht=ee===xe;return(I==null?void 0:I.mode)==="rename"&&I.targetPath===xe?d.jsx(BRe,{entryType:me.type,initialValue:I.initialValue,onConfirm:le,onCancel:()=>W(null)},me.name):d.jsxs("div",{"data-grid-item":!0,role:"button",tabIndex:0,className:`group relative flex flex-col items-center gap-1 p-2 rounded-lg cursor-pointer select-none transition-colors hover:bg-gray-100 dark:hover:bg-[#253040]/50 ${ht?"bg-blue-50 dark:bg-blue-900/20 ring-1 ring-blue-300 dark:ring-blue-700":""} ${b===xe?"opacity-50":""}`,onClick:()=>R(me),onKeyDown:wt=>{wt.key==="Enter"&&R(me)},onContextMenu:wt=>M(wt,me),children:[me.type==="directory"?d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}):d.jsx(Nl,{className:"w-8 h-8 text-gray-500 dark:text-gray-400"}),d.jsx("span",{className:`text-xs text-center w-full truncate ${ht?"text-blue-600 dark:text-blue-400":"text-gray-700 dark:text-gray-200"}`,children:me.name}),s&&d.jsx("button",{className:"absolute top-1 right-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-gray-200 dark:hover:bg-[#2d3a4a] transition-opacity",onClick:wt=>U(wt,me),"aria-label":v("files.moreMenu"),children:d.jsx(Ba,{className:"w-3 h-3 text-gray-400"})})]},me.name)})]}),A&&d.jsx(pI,{x:A.x,y:A.y,targetType:A.targetType,onNewFile:()=>K("file"),onNewFolder:()=>K("directory"),onRename:()=>oe(),onDelete:()=>Z(),onClose:()=>X(null),onCopy:c?()=>{c(A.targetPath),X(null)}:void 0,onCut:u?()=>{u(A.targetPath),X(null)}:void 0,onPaste:h?()=>{const me=A.targetType==="directory"?A.targetPath:e;h(me).catch(()=>{}).finally(()=>B()),X(null)}:void 0,onDownload:O?()=>{O(A.targetPath),X(null)}:void 0,hasClipboard:p}),Y&&d.jsx(mI,{name:Y.name,type:Y.type,onConfirm:V,onCancel:()=>te(null)})]})}const GRe=[".env",".git","node_modules",".next",".cache","__pycache__",".DS_Store","dist",".turbo"],cE={FILE_ALREADY_EXISTS:"files.crudErrors.alreadyExists",PARENT_NOT_FOUND:"files.crudErrors.parentNotFound",PROTECTED_PATH:"files.crudErrors.protectedPath",RENAME_TARGET_EXISTS:"files.crudErrors.targetExists",COPY_TARGET_EXISTS:"files.crudErrors.targetExists",COPY_TOO_LARGE:"files.crudErrors.copyTooLarge",PATH_TRAVERSAL:"files.crudErrors.outsideRoot"};function HRe(){const{t}=Ce("common"),{projectSlug:e}=jn(),r=k.useCallback((Z,V)=>{const ne=Z;return ne.code&&cE[ne.code]?`${V}: ${t(cE[ne.code])}`:`${V}: ${Z.message}`},[t]),[n,i]=k.useState(""),[s,a]=k.useState(!1),o=Ht(Z=>Z.preferences.fileExplorerViewMode??"grid"),[l,c]=k.useState(o),[u,h]=k.useState("."),{toasts:O,showToast:p,removeToast:b}=gj(),[y,g]=k.useState(null),x=k.useRef(null),[v,w]=k.useState(!1),[Q,_]=k.useState(0),[$,P]=k.useState(null),[T,E]=k.useState(!1);k.useEffect(()=>{if(!n.trim()||!e){P(null),E(!1);return}E(!0);const Z=setTimeout(async()=>{try{const V=await ni.searchFiles(e,n.trim(),s),ne=s?V.results:V.results.filter(G=>!G.path.split("/").some(se=>GRe.includes(se)));P(ne)}catch{P([])}finally{E(!1)}},300);return()=>clearTimeout(Z)},[n,e,s]);const N=k.useCallback(Z=>{qo(Z)?Vo.getState().openImageViewer(e,Z):bn.getState().requestFileNavigation(e,Z)},[e]),A=k.useCallback(Z=>{Z.type==="file"&&(qo(Z.path)?Vo.getState().openImageViewer(e,Z.path):bn.getState().requestFileNavigation(e,Z.path)),i("")},[e]),X=k.useCallback(async(Z,V,ne)=>{try{const G=Z==="."?ne:`${Z}/${ne}`;await ni.createEntry(e,G,V),p({message:V==="directory"?t("files.toast.folderCreated",{name:ne}):t("files.toast.fileCreated",{name:ne}),type:"success"})}catch(G){throw p({message:r(G,t("files.toast.createFailed")),type:"error"}),G}},[e,p,t,r]),I=k.useCallback(async Z=>{try{const V=Z.includes("/")?Z.split("/").pop():Z;await ni.deleteEntry(e,Z),p({message:t("files.toast.deleted",{name:V}),type:"success"})}catch(V){throw p({message:r(V,t("files.toast.deleteFailed")),type:"error"}),V}},[e,p,t,r]),W=k.useCallback(async(Z,V)=>{try{const ne=Z.includes("/")?Z.substring(0,Z.lastIndexOf("/")):".",G=ne==="."?V:`${ne}/${V}`;await ni.renameEntry(e,Z,G),p({message:t("files.toast.renamed",{name:V}),type:"success"})}catch(ne){throw p({message:r(ne,t("files.toast.renameFailed")),type:"error"}),ne}},[e,p,t,r]),Y=k.useCallback(Z=>{g({path:Z,operation:"copy"});const V=Z.includes("/")?Z.split("/").pop():Z;p({message:t("files.toast.copied",{name:V}),type:"success"})},[p,t]),te=k.useCallback(Z=>{g({path:Z,operation:"cut"});const V=Z.includes("/")?Z.split("/").pop():Z;p({message:t("files.toast.cut",{name:V}),type:"success"})},[p,t]),ee=k.useCallback(async Z=>{if(!y||!e)return{};const V=y,ne=V.path.includes("/")?V.path.split("/").pop():V.path,G=V.path.includes("/")?V.path.substring(0,V.path.lastIndexOf("/")):".";if(V.operation==="cut"&&G===Z)return{};const he=V.operation==="cut";try{let se=ne;if(!he&&G===Z){const re=ne.match(/^(.+?)(\.tar\.\w+)$/);let Qe,me;if(re)Qe=re[1],me=re[2];else{const wt=ne.lastIndexOf(".");Qe=wt>0?ne.substring(0,wt):ne,me=wt>0?ne.substring(wt):""}const xe=await ni.listDirectory(e,Z),ht=new Set(xe.entries.map(wt=>wt.name));se=`${Qe} - Copy${me}`;let St=2;for(;ht.has(se);)se=`${Qe} - Copy (${St})${me}`,St++}const ce=Z==="."?se:`${Z}/${se}`;return he?(await ni.renameEntry(e,V.path,ce),p({message:t("files.toast.moved",{name:se}),type:"success"}),g(re=>(re==null?void 0:re.path)===V.path&&(re==null?void 0:re.operation)==="cut"?null:re)):(await ni.copyEntry(e,V.path,ce),p({message:t("files.toast.pasted",{name:se}),type:"success"})),he&&G!==Z?{sourceDir:G}:{}}catch(se){throw p({message:r(se,t("files.toast.pasteFailed")),type:"error"}),se}},[y,e,p,t,r]),B=k.useCallback(async Z=>{if(!e)return;const V=ni.getDownloadUrl(e,Z);try{if(!(await fetch(V,{method:"HEAD"})).ok){p({message:t("files.toast.downloadFailed"),type:"error"});return}const G=document.createElement("a");G.href=V,G.download=Z.includes("/")?Z.split("/").pop():Z,document.body.appendChild(G),G.click(),document.body.removeChild(G)}catch{p({message:t("files.toast.downloadFailed"),type:"error"})}},[e,p,t]),D=k.useRef(!1),R=k.useCallback(async Z=>{if(!(Z.length===0||!e)){if(D.current){p({message:t("files.toast.uploadInProgress"),type:"info"});return}D.current=!0,w(!0);try{const V=await ni.uploadFiles(e,u,Z),ne=V.files.length;p({message:ne===1?t("files.toast.uploaded",{name:V.files[0].path.split("/").pop()}):t("files.toast.uploadedMultiple",{count:ne}),type:"success"}),_(G=>G+1)}catch(V){p({message:r(V,t("files.toast.uploadFailed")),type:"error"})}finally{D.current=!1,w(!1),x.current&&(x.current.value="")}}},[e,u,p,t,r]),M=k.useCallback(()=>{var Z;(Z=x.current)==null||Z.click()},[]),U=k.useCallback(async Z=>{const V=Z.target.files;!V||V.length===0||await R(Array.from(V))},[R]),z=k.useCallback(Z=>{var ne;const V=(ne=Z.clipboardData)==null?void 0:ne.files;!V||V.length===0||(Z.preventDefault(),R(Array.from(V)))},[R]),K=k.useRef(null);k.useEffect(()=>{const Z=K.current;if(Z)return Z.addEventListener("paste",z),()=>Z.removeEventListener("paste",z)},[z]);const oe=(()=>{if(u===".")return[{name:t("files.root"),path:"."}];const Z=u.split("/"),V=[{name:t("files.root"),path:"."}];for(let ne=0;ne<Z.length;ne++)V.push({name:Z[ne],path:Z.slice(0,ne+1).join("/")});return V})();if(!e)return d.jsx("div",{className:"flex items-center justify-center h-full text-gray-500 dark:text-gray-300",children:t("files.projectNotFound")});const le=$!==null||T;return d.jsxs("div",{ref:K,className:"flex flex-col h-full",tabIndex:-1,children:[d.jsx("input",{ref:x,type:"file",multiple:!0,className:"hidden",onChange:U}),d.jsx("div",{className:"sticky top-0 z-[5] bg-white dark:bg-[#1c2129] border-b border-gray-200 dark:border-[#253040]",children:d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 gap-3",children:[le?d.jsx("div",{}):d.jsx("nav",{"aria-label":t("files.breadcrumb"),className:"flex-shrink min-w-0",children:d.jsx("ol",{className:"flex items-center gap-0.5 text-xs",children:oe.map((Z,V)=>d.jsxs("li",{className:"flex items-center gap-0.5 min-w-0",children:[V>0&&d.jsx(Yo,{className:"w-3 h-3 text-gray-400 dark:text-gray-500 flex-shrink-0","aria-hidden":"true"}),V===oe.length-1?d.jsxs("span",{className:"inline-flex items-center gap-1 font-medium text-gray-800 dark:text-gray-200 truncate","aria-current":"page",children:[V===0&&d.jsx(x$,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400 flex-shrink-0"}),Z.name]}):d.jsxs("button",{onClick:()=>h(Z.path),className:`inline-flex items-center gap-1 text-gray-500 dark:text-gray-300
1352
+ ${s===b.id?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300 font-medium":"text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040]"}`,children:[d.jsx(b.icon,{className:"w-4 h-4 flex-shrink-0","aria-hidden":"true"}),d.jsx("span",{className:"whitespace-nowrap",children:t(b.titleKey)})]},b.id))}),d.jsxs("main",{className:"flex-1 min-w-0 overflow-y-auto p-6",children:[d.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-white mb-4",children:t(Om.find(b=>b.id===s).titleKey)}),p(s)]})]}),d.jsx("div",{ref:l,className:"content-container md:hidden flex-1 overflow-y-auto w-full",style:{scrollBehavior:"auto"},children:Om.map(b=>d.jsx(xRe,{sectionId:b.id,title:t(b.titleKey),icon:b.icon,isExpanded:a===b.id,onToggle:()=>O(b.id),children:p(b.id)},b.id))})]})}const oE=[{id:"overview",labelKey:"tabs.overview",icon:lj,path:""},{id:"board",labelKey:"tabs.board",icon:Lv,path:"/board"},{id:"sessions",labelKey:"tabs.sessions",icon:Wo,path:"/sessions"},{id:"queue",labelKey:"tabs.queue",icon:Ag,path:"/queue"},{id:"files",labelKey:"tabs.files",icon:Ns,path:"/files"},{id:"git",labelKey:"tabs.git",icon:No,path:"/git"},{id:"terminal",labelKey:"tabs.terminal",icon:Es,path:"/terminal"}];function DRe(){const{t}=Ce("common"),{projectSlug:e}=jn(),r=En(),n=fs(),{projects:i,fetchProjects:s}=Ga(),{connectionStatus:a,reconnectAttempt:o,lastError:l,connect:c}=Ek(),u=Ut(_=>_.terminalAccess),h=(u==null?void 0:u.enabled)!==!1,O=(u==null?void 0:u.allowed)??!0;k.useEffect(()=>{i.length===0&&s()},[i.length,s]);const[p,b]=k.useState(!1),y=k.useRef(null);Ch(y,()=>b(!1));const g=k.useMemo(()=>{const _=i.find($=>$.projectSlug===e);return(_==null?void 0:_.originalPath)||e||""},[i,e]),x=k.useMemo(()=>{const _=g.replace(/\\/g,"/").split("/");return _[_.length-1]||g},[g]),v=k.useMemo(()=>{const _=`/project/${e}`;for(const $ of[...oE].reverse())if($.path&&n.pathname.startsWith(`${_}${$.path}`))return $.id;return"overview"},[n.pathname,e]),w=()=>r("/"),Q=_=>{r(`/project/${e}${_}`)};return d.jsxs("div",{className:"h-dvh flex flex-col bg-white dark:bg-[#1c2129] transition-colors duration-200",children:[d.jsxs("header",{className:"flex-shrink-0 sticky top-0 z-10 bg-[#243648] dark:bg-[#171e24] border-b border-slate-200 dark:border-slate-700/50",children:[d.jsxs("div",{className:"content-container flex items-center justify-between px-4 py-3 min-h-14",children:[d.jsxs("div",{className:"flex items-stretch min-w-0 flex-1",children:[d.jsx("button",{onClick:w,className:"self-center p-2 -ml-2 mr-2 hover:bg-white/10 dark:hover:bg-[#253040] rounded-lg text-white/80 dark:text-gray-200","aria-label":t("layout.back"),children:d.jsx(Rg,{className:"w-5 h-5"})}),d.jsx(km,{}),d.jsx("div",{className:"w-px self-stretch bg-gray-200 dark:bg-[#253040] mx-3"}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsx("h1",{className:"text-base font-semibold truncate text-white dark:text-white",children:x}),d.jsx("p",{className:"text-xs text-white/60 dark:text-gray-400 truncate",children:g})]})]}),d.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[d.jsx(fD,{status:a,reconnectAttempt:o,lastError:l,onReconnect:c,compact:!0}),d.jsx($h,{className:"hidden sm:block"}),d.jsx("button",{onClick:()=>window.location.reload(),"aria-label":t("layout.refresh"),className:"hidden sm:block p-2 rounded-lg hover:bg-white/10 dark:hover:bg-[#253040] text-white/80 dark:text-gray-200 transition-colors",children:d.jsx(Ir,{className:"w-5 h-5","aria-hidden":"true"})}),d.jsx("button",{onClick:()=>r("/settings"),"aria-label":t("project.settings"),className:"hidden sm:block p-2 rounded-lg hover:bg-white/10 dark:hover:bg-[#253040] text-white/80 dark:text-gray-200 transition-colors",children:d.jsx(aa,{className:"w-5 h-5","aria-hidden":"true"})}),d.jsxs("div",{className:"relative sm:hidden",ref:y,children:[d.jsx("button",{onClick:()=>b(!p),className:"p-2 hover:bg-white/10 dark:hover:bg-[#253040] rounded-lg text-white/80 dark:text-gray-200","aria-label":t("project.menuLabel"),"aria-expanded":p,"aria-haspopup":"menu",children:d.jsx(Ba,{className:"w-5 h-5"})}),p&&d.jsxs("div",{role:"menu",className:"absolute right-0 top-full mt-2 w-48 bg-white dark:bg-[#263240] rounded-lg shadow-lg border border-gray-200 dark:border-[#253040] z-50 py-1",children:[d.jsxs("button",{role:"menuitem",onClick:()=>window.location.reload(),className:"w-full px-4 py-2 text-left text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] flex items-center gap-2",children:[d.jsx(Ir,{className:"w-4 h-4"}),t("layout.refresh")]}),d.jsx("div",{className:"border-t border-gray-200 dark:border-[#253040] my-1"}),d.jsxs("button",{role:"menuitem",onClick:()=>{r("/settings"),b(!1)},className:"w-full px-4 py-2 text-left text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-[#253040] flex items-center gap-2",children:[d.jsx(aa,{className:"w-4 h-4"}),t("project.settings")]})]})]})]})]}),d.jsx("nav",{className:"content-container flex px-4","aria-label":t("layout.projectTabs"),children:oE.map(_=>{if(_.id==="terminal"&&!h)return null;const $=v===_.id,P=_.icon,T=_.id==="terminal"&&!O;return d.jsxs("button",{onClick:T?void 0:()=>Q(_.path),disabled:T,className:`flex items-center gap-2 px-4 py-2.5 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${T?"border-transparent opacity-50 cursor-not-allowed text-gray-500 dark:text-gray-400":$?"border-blue-300 text-blue-200 dark:text-blue-400":"border-transparent text-white/50 dark:text-gray-300 hover:text-white/80 dark:hover:text-gray-300 hover:border-white/30 dark:hover:border-[#2d3a4a]"}`,"aria-current":$?"page":void 0,"aria-disabled":T||void 0,"aria-label":T?t("layout.terminalDisabled"):void 0,children:[d.jsx(P,{className:"w-4 h-4"}),d.jsx("span",{className:"hidden sm:inline",children:t(_.labelKey)})]},_.id)})})]}),d.jsx("main",{className:"flex-1 overflow-auto",children:d.jsx("div",{className:"content-container h-full",children:d.jsx(PK,{})})})]})}let pm=!1,q1=null;const xI="cli-status-cache",LRe=3600*1e3;function IRe(){try{const t=sessionStorage.getItem(xI);if(!t)return null;const{status:e,timestamp:r}=JSON.parse(t);return Date.now()-r>LRe?null:e!=null&&e.authenticated||e!=null&&e.apiKeySet?e:null}catch{return null}}function MRe(t){try{sessionStorage.setItem(xI,JSON.stringify({status:t,timestamp:Date.now()}))}catch{}}const lE=IRe();lE&&(pm=!0,q1=lE);function Ac({children:t}){const{t:e}=Ce("common"),{isAuthenticated:r,isLoading:n,checkAuth:i}=Xo(),s=fs(),[a,o]=k.useState(q1),[l,c]=k.useState(!pm),[u,h]=k.useState(null),[O,p]=k.useState(!1),b=k.useCallback(async(g=!1)=>{if(!g&&pm)return;c(!0),h(null);const x=2,v=1500;for(let w=0;w<=x;w++)try{const Q=await qe.get("/cli-status");console.log("[AuthGuard] CLI status response:",Q),o(Q),q1=Q,pm=!0,MRe(Q);const _=!Q.authenticated&&!Q.apiKeySet;p(_),c(!1);return}catch(Q){if(console.error("[AuthGuard] CLI status fetch failed (attempt",w+1,"):",Q),Q instanceof Jr&&Q.status===401){console.warn("[AuthGuard] Session expired during CLI status check, re-checking auth"),c(!1),Xo.getState().recheckAuth();return}if(w<x){await new Promise(_=>setTimeout(_,v));continue}h(Q instanceof Error?Q.message:e("error.cliStatusFailed")),p(!1),c(!1)}},[]);if(k.useEffect(()=>{i()},[i]),k.useEffect(()=>{r&&!n&&s.pathname!=="/onboarding"?b():s.pathname==="/onboarding"&&c(!1)},[r,n,s.pathname,b]),n)return d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-100 dark:bg-[#1c2129]",children:d.jsx(kh,{size:"lg"})});if(!r)return d.jsx(Pv,{to:"/login",state:{from:s},replace:!0});if(l&&s.pathname!=="/onboarding")return d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-[#1c2129]",role:"status","aria-label":e("loading"),children:d.jsxs("div",{className:"flex flex-col items-center gap-3",children:[d.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500","aria-hidden":"true"}),d.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-300",children:e("cliStatusChecking")})]})});if(O&&s.pathname!=="/onboarding")return d.jsx(Pv,{to:"/onboarding",replace:!0});const y={cliStatus:a,isLoading:l,error:u,refetch:b,isReady:(a==null?void 0:a.authenticated)===!0||(a==null?void 0:a.apiKeySet)===!0};return d.jsx(Une,{value:y,children:t})}function zRe({children:t}){const{isAuthenticated:e,isLoading:r,checkAuth:n}=Xo(),i=En();return k.useEffect(()=>{n()},[n]),k.useEffect(()=>{!r&&e&&i("/",{replace:!0})},[e,r,i]),r?d.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-100 dark:bg-[#1c2129]",children:d.jsx(kh,{size:"lg"})}):e?null:d.jsx(d.Fragment,{children:t})}function qRe({content:t}){return d.jsx("div",{className:"flex-1 overflow-y-auto p-4 bg-white dark:bg-[#1c2129]",children:d.jsx("div",{className:"max-w-4xl mx-auto",children:d.jsx(S0,{content:t})})})}const URe=k.lazy(()=>J(()=>import("./index-CJJ7qZd7.js"),[]));function VRe(){const{openFile:t,content:e,isDirty:r,isLoading:n,isSaving:i,isTruncated:s,error:a,isMarkdownPreview:o,saveFile:l,closeEditor:c,setContent:u,resetError:h,openFileInEditor:O,toggleMarkdownPreview:p,pendingNavigation:b,confirmPendingNavigation:y,cancelPendingNavigation:g}=bn(),{t:x}=Ce("common"),[v,w]=k.useState(!1),Q=k.useRef(null),_=k.useRef(null),{resolvedTheme:$}=Cd(),P=Td(),T=pa(U=>U.activePanel),E=pa(U=>U.panelWidth),N=480,[A,X]=k.useState(()=>typeof window<"u"?window.innerWidth:1024);k.useEffect(()=>{const U=()=>X(window.innerWidth);return window.addEventListener("resize",U),()=>window.removeEventListener("resize",U)},[]);const W=!(P||T!==null&&A-E<N)&&T?E:0,Y=t?c3(t.path):!1,te=k.useMemo(()=>{const U=[Ye.lineWrapping];if(t){const z=l3(t.path);z&&U.push(z)}return s&&U.push(Ye.editable.of(!1)),U},[t,s]),ee=k.useCallback(async()=>{if(!r||i)return;await l()?ft.success(x("editor.fileSaved")):ft.error(x("editor.fileSaveFailed"))},[r,i,l]),B=k.useCallback(()=>{b&&g(),r?w(!0):c()},[r,c,b,g]);k.useEffect(()=>{t&&(_.current={...t})},[t]);const D=k.useCallback(()=>{_.current&&O(_.current.projectSlug,_.current.path)},[O]);u0(!!t,B,D),k.useEffect(()=>{if(!t)return;const U=z=>{if((z.ctrlKey||z.metaKey)&&z.key==="s"){z.preventDefault(),ee();return}if(z.key==="Escape"){if(z.stopImmediatePropagation(),b)return;if(v){w(!1);return}B()}};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},[t,ee,B,v,b]),k.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]),k.useEffect(()=>{var U;!o&&Y&&((U=Q.current)==null||U.focus())},[o,Y]);const R=k.useCallback(U=>{Q.current=U;const z=bn.getState().targetLine;z&&requestAnimationFrame(()=>{try{const K=Math.min(z,U.state.doc.lines),oe=U.state.doc.line(K);U.dispatch({selection:{anchor:oe.from},effects:Ye.scrollIntoView(oe.from,{y:"start",yMargin:8})})}catch{}bn.setState({targetLine:null})})},[]);if(!t)return null;const M=t.path;return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 z-[55] transition-[right] duration-300 ease-in-out",style:{right:W},onClick:U=>{U.stopPropagation(),B()}}),d.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col bg-white dark:bg-[#1c2129] transition-[right] duration-300 ease-in-out",style:{right:W},children:[d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-[#253040] bg-gray-50 dark:bg-[#263240]",children:[d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(Fa,{className:"w-4 h-4 shrink-0 text-gray-500 dark:text-gray-300"}),d.jsx("span",{className:"truncate text-sm font-mono text-gray-700 dark:text-gray-200",children:M}),r&&d.jsx("span",{className:"text-xs font-bold text-amber-500 shrink-0",children:"M"})]}),d.jsxs("div",{className:"flex items-center gap-2 ml-3 shrink-0",children:[Y&&d.jsx("button",{onClick:p,className:"flex items-center gap-1 px-3 py-1 text-sm font-medium whitespace-nowrap text-gray-700 dark:text-gray-200 bg-gray-100 dark:bg-[#253040] hover:bg-gray-200 dark:hover:bg-[#2d3a4a] rounded transition-colors",title:x(o?"editor.editMode":"editor.previewLabel"),"aria-label":x(o?"editor.editMode":"editor.previewLabel"),children:o?d.jsxs(d.Fragment,{children:[d.jsx(Ng,{className:"w-4 h-4"}),d.jsx("span",{children:x("editor.editLabel")})]}):d.jsxs(d.Fragment,{children:[d.jsx(Jc,{className:"w-4 h-4"}),d.jsx("span",{children:x("editor.previewLabel")})]})}),d.jsx("button",{onClick:ee,disabled:!r||i,title:x("editor.saveShortcut"),className:"px-3 py-1 text-sm font-medium whitespace-nowrap text-white bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 rounded disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:x(i?"editor.saving":"editor.save")}),d.jsx("button",{onClick:B,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300","aria-label":x("editor.close"),children:d.jsx(Vt,{className:"w-5 h-5"})})]})]}),n?d.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"ml-2 text-sm text-gray-500 dark:text-gray-300",children:x("editor.loadingFile")})]}):a?d.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 text-red-500",children:[d.jsx("p",{children:a}),d.jsx("button",{onClick:()=>{h(),O(t.projectSlug,t.path)},className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors",children:x("button.retry")})]}):d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"px-4 py-2 bg-amber-50 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300 text-xs border-b border-amber-200 dark:border-amber-800",children:x("editor.fileTruncated")}),o&&Y?d.jsx(qRe,{content:e}):d.jsx("div",{className:"flex-1 min-h-0 [&_.cm-editor]:h-full [&_.cm-scroller]:!overflow-auto","aria-label":`Editing ${M}`,children:d.jsx(k.Suspense,{fallback:d.jsxs("div",{className:"h-full flex items-center justify-center",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"ml-2 text-sm text-gray-500 dark:text-gray-300",children:x("editor.loadingEditor")})]}),children:d.jsx(URe,{value:e,extensions:te,theme:$==="dark"?sD:"light",onChange:U=>u(U),onCreateEditor:R,height:"100%",style:{height:"100%"},basicSetup:{lineNumbers:!0,highlightActiveLine:!0,tabSize:2,foldGutter:!1},readOnly:s})})})]})]}),d.jsx(Ma,{isOpen:v,title:x("editor.unsavedTitle"),message:x("editor.unsavedCloseMessage"),confirmText:x("editor.closeWithoutSaving"),cancelText:x("button.cancel"),variant:"danger",onConfirm:()=>{c(),w(!1)},onCancel:()=>w(!1)}),d.jsx(Ma,{isOpen:!!b,title:x("editor.unsavedTitle"),message:x("editor.unsavedOpenMessage",{path:(b==null?void 0:b.path)??""}),confirmText:x("editor.openWithoutSaving"),cancelText:x("button.cancel"),variant:"danger",onConfirm:y,onCancel:g})]})}const Ip=.25,YRe=.1,WRe=10;function ZRe(){const{openImage:t,zoomLevel:e,closeViewer:r,setZoom:n,resetView:i}=Vo(),{t:s}=Ce("common"),[a,o]=k.useState(!0),[l,c]=k.useState(!1),[u,h]=k.useState(!1),[O,p]=k.useState({x:0,y:0}),b=k.useRef({x:0,y:0}),y=k.useRef({x:0,y:0}),g=k.useRef(null),x=Td(),v=pa(R=>R.activePanel),w=pa(R=>R.panelWidth),Q=480,[_,$]=k.useState(()=>typeof window<"u"?window.innerWidth:1024);k.useEffect(()=>{const R=()=>$(window.innerWidth);return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[]);const T=!(x||v!==null&&_-w<Q)&&v?w:0,E=k.useCallback(()=>{r()},[r]);k.useEffect(()=>{t&&(g.current={...t})},[t]);const N=k.useCallback(()=>{g.current&&Vo.getState().openImageViewer(g.current.projectSlug,g.current.path)},[]);u0(!!t,E,N),k.useEffect(()=>{t&&(o(!0),c(!1),p({x:0,y:0}))},[t]),k.useEffect(()=>{if(!t)return;const R=M=>{M.key==="Escape"&&(M.stopImmediatePropagation(),E())};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[t,E]),k.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]);const A=k.useCallback(R=>{R.preventDefault();const M=R.deltaY>0?-Ip:Ip;n(e+M)},[e,n]),X=k.useCallback(R=>{R.button===0&&(h(!0),b.current={x:R.clientX,y:R.clientY},y.current={...O})},[O]),I=k.useCallback(R=>{u&&p({x:y.current.x+(R.clientX-b.current.x),y:y.current.y+(R.clientY-b.current.y)})},[u]),W=k.useCallback(()=>{h(!1)},[]),Y=k.useCallback(()=>{i(),p({x:0,y:0})},[i]);if(!t)return null;const te=t.path,ee=te.includes("/")?te.split("/").pop():te,B=`/api/projects/${t.projectSlug}/fs/raw?path=${encodeURIComponent(te)}`,D=Math.round(e*100);return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 z-[55] transition-[right] duration-300 ease-in-out",style:{right:T},onClick:E}),d.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col bg-white dark:bg-[#1c2129] transition-[right] duration-300 ease-in-out",style:{right:T},children:[d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-[#253040] bg-gray-50 dark:bg-[#263240]",children:[d.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d.jsx(y$,{className:"w-4 h-4 shrink-0 text-gray-500 dark:text-gray-300"}),d.jsx("span",{className:"truncate text-sm font-mono text-gray-700 dark:text-gray-200",children:te})]}),d.jsxs("div",{className:"flex items-center gap-1 ml-3",children:[d.jsx("button",{onClick:()=>n(e-Ip),disabled:e<=YRe,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300 disabled:opacity-40",title:s("imageViewer.zoomOut"),children:d.jsx(qne,{className:"w-4 h-4"})}),d.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-300 w-12 text-center tabular-nums",children:[D,"%"]}),d.jsx("button",{onClick:()=>n(e+Ip),disabled:e>=WRe,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300 disabled:opacity-40",title:s("imageViewer.zoomIn"),children:d.jsx(Mne,{className:"w-4 h-4"})}),d.jsx("button",{onClick:Y,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300",title:s("imageViewer.resetZoom"),children:d.jsx(rw,{className:"w-4 h-4"})}),d.jsx("div",{className:"w-px h-5 bg-gray-200 dark:bg-[#253040] mx-1"}),d.jsx("button",{onClick:E,className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-[#253040] text-gray-500 dark:text-gray-300","aria-label":s("imageViewer.close"),children:d.jsx(Vt,{className:"w-5 h-5"})})]})]}),d.jsxs("div",{className:`flex-1 overflow-hidden flex items-center justify-center bg-gray-100 dark:bg-gray-950 ${u?"cursor-grabbing":"cursor-grab"}`,onWheel:A,onMouseDown:X,onMouseMove:I,onMouseUp:W,onMouseLeave:W,children:[a&&!l&&d.jsxs("div",{className:"absolute flex items-center gap-2",children:[d.jsx(vt,{className:"w-8 h-8 animate-spin text-gray-400"}),d.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-300",children:s("imageViewer.loadingImage")})]}),l?d.jsxs("div",{className:"flex flex-col items-center gap-2 text-red-500",children:[d.jsx(y$,{className:"w-12 h-12 opacity-50"}),d.jsx("p",{className:"text-sm",children:s("imageViewer.loadFailed")}),d.jsx("p",{className:"text-xs text-gray-400",children:ee})]}):d.jsx("img",{src:B,alt:ee,draggable:!1,className:"select-none transition-opacity duration-200",style:{transform:`translate(${O.x}px, ${O.y}px) scale(${e})`,opacity:a?0:1,maxWidth:"none",maxHeight:"none"},onLoad:()=>o(!1),onError:()=>{o(!1),c(!0)}})]})]})]})}function BRe({entryType:t,initialValue:e,onConfirm:r,onCancel:n}){const{t:i}=Ce("common"),[s,a]=k.useState(e),o=k.useRef(null);k.useEffect(()=>{if(o.current&&(o.current.focus(),e)){const u=e.lastIndexOf("."),h=u>0?u:e.length;o.current.setSelectionRange(0,h)}},[]);const l=u=>{u.key==="Enter"?(u.preventDefault(),r(s)):u.key==="Escape"&&(u.preventDefault(),n())},c=()=>{s.trim()?r(s):n()};return d.jsxs("div",{className:"flex flex-col items-center gap-1 p-2 rounded-lg",children:[t==="directory"?d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}):d.jsx(Nl,{className:"w-8 h-8 text-gray-500 dark:text-gray-400"}),d.jsx("input",{ref:o,type:"text",value:s,onChange:u=>a(u.target.value),onKeyDown:l,onBlur:c,className:"text-xs text-center w-full bg-white dark:bg-[#1c2129] dark:text-white border border-blue-500 rounded px-1 py-0 outline-none h-4 leading-4","aria-label":i("files.renameAria")})]})}function FRe({projectSlug:t,currentPath:e,showHidden:r,onFileSelect:n,onNavigate:i,enableContextMenu:s=!1,onCreateEntry:a,onDeleteEntry:o,onRenameEntry:l,onCopy:c,onCut:u,onPaste:h,onDownload:O,hasClipboard:p=!1,cutPath:b,refreshTrigger:y,onFileDrop:g,isUploading:x=!1}){const{t:v}=Ce("common"),[w,Q]=k.useState([]),[_,$]=k.useState(!0),[P,T]=k.useState(!1),[E,N]=k.useState(null),[A,X]=k.useState(null),[I,W]=k.useState(null),[Y,te]=k.useState(null),ee=bn(me=>{var xe;return((xe=me.openFile)==null?void 0:xe.path)??null}),B=k.useCallback(async()=>{$(!0),N(null),Q([]);try{const me=await ni.listDirectory(t,e);Q(me.entries)}catch(me){N(me.message)}finally{$(!1)}},[t,e]);k.useEffect(()=>{B()},[B]),k.useEffect(()=>{y===void 0||y===0||B()},[y]),k.useEffect(()=>{if(!_){T(!1);return}const me=setTimeout(()=>T(!0),300);return()=>clearTimeout(me)},[_]);const D=k.useMemo(()=>{const me=_0(w);return r?me:me.filter(xe=>!Q0.includes(xe.name))},[w,r]),R=k.useCallback(me=>{const xe=e==="."?me.name:`${e}/${me.name}`;me.type==="directory"?i(xe):n(xe)},[e,i,n]),M=k.useCallback((me,xe)=>{if(!s)return;me.preventDefault(),me.stopPropagation(),me.nativeEvent.stopImmediatePropagation();const ht=e==="."?xe.name:`${e}/${xe.name}`,St=xe.type==="directory"?ht:e;X({x:me.clientX,y:me.clientY,targetPath:ht,targetType:xe.type,parentPath:St})},[s,e]),U=k.useCallback((me,xe)=>{if(!s)return;me.stopPropagation();const ht=me.currentTarget.getBoundingClientRect(),St=e==="."?xe.name:`${e}/${xe.name}`,wt=xe.type==="directory"?St:e;X({x:ht.right,y:ht.bottom,targetPath:St,targetType:xe.type,parentPath:wt})},[s,e]),z=k.useCallback(me=>{if(!s)return;const xe=me.target;xe instanceof Element&&xe.closest("[data-grid-item]")||(me.preventDefault(),me.stopPropagation(),me.nativeEvent.stopImmediatePropagation(),X({x:me.clientX,y:me.clientY,targetPath:e,targetType:"directory",parentPath:e}))},[s,e]),K=k.useCallback(me=>{A&&(W({mode:"create",parentPath:A.parentPath,entryType:me,initialValue:""}),X(null))},[A]),oe=k.useCallback(()=>{if(!A)return;const me=A.targetPath.includes("/")?A.targetPath.split("/").pop():A.targetPath;W({mode:"rename",parentPath:e,targetPath:A.targetPath,entryType:A.targetType,initialValue:me}),X(null)},[A,e]),le=k.useCallback(async me=>{if(!I||!me.trim()){W(null);return}try{I.mode==="create"?(await(a==null?void 0:a(I.parentPath,I.entryType,me.trim())),await B()):I.mode==="rename"&&I.targetPath&&me.trim()!==I.initialValue&&(await(l==null?void 0:l(I.targetPath,me.trim())),await B())}catch{}W(null)},[I,a,l,B]),Z=k.useCallback(()=>{if(!A)return;const me=A.targetPath.includes("/")?A.targetPath.split("/").pop():A.targetPath;te({path:A.targetPath,name:me,type:A.targetType}),X(null)},[A]),V=k.useCallback(async()=>{if(Y){try{await(o==null?void 0:o(Y.path)),await B()}catch{}te(null)}},[Y,o,B]),[ne,G]=k.useState(!1),he=k.useRef(0),se=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),he.current++,he.current===1&&G(!0))},[g]),ce=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),me.dataTransfer.dropEffect="copy")},[g]),re=k.useCallback(me=>{g&&me.dataTransfer.types.includes("Files")&&(me.preventDefault(),he.current=Math.max(0,he.current-1),he.current===0&&G(!1))},[g]),Qe=k.useCallback(me=>{if(!g)return;me.preventDefault(),he.current=0,G(!1);const xe=Array.from(me.dataTransfer.files);xe.length>0&&g(xe)},[g]);return k.useEffect(()=>{const me=()=>{he.current=0,G(!1)};return window.addEventListener("dragend",me),window.addEventListener("drop",me),()=>{window.removeEventListener("dragend",me),window.removeEventListener("drop",me)}},[]),_&&w.length===0?P?d.jsxs("div",{className:"flex items-center gap-2 p-4 text-sm text-gray-500 dark:text-gray-300 justify-center",children:[d.jsx(vt,{className:"w-4 h-4 animate-spin"}),d.jsx("span",{children:v("loadingStatus")})]}):null:E&&w.length===0?d.jsx("div",{className:"p-4",children:d.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 dark:text-red-400",children:[d.jsx(ji,{className:"w-3.5 h-3.5"}),d.jsx("span",{children:E}),d.jsx("button",{className:"text-xs text-blue-500 dark:text-blue-400 hover:underline cursor-pointer ml-2",onClick:B,children:v("button.retry")})]})}):d.jsxs("div",{className:"p-2 relative",onContextMenu:z,onDragEnter:se,onDragOver:ce,onDragLeave:re,onDrop:Qe,children:[ne&&d.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-blue-50/80 dark:bg-blue-900/30 border-2 border-dashed border-blue-400 dark:border-blue-500 rounded-lg pointer-events-none",children:d.jsxs("div",{className:"flex flex-col items-center gap-2 text-blue-600 dark:text-blue-400",children:[d.jsx(Ph,{className:"w-8 h-8"}),d.jsx("span",{className:"text-sm font-medium",children:v("files.dropHere")})]})}),x&&d.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/60 dark:bg-[#1c2129]/60 rounded-lg pointer-events-none",children:d.jsxs("div",{className:"flex items-center gap-2 text-gray-600 dark:text-gray-300",children:[d.jsx(vt,{className:"w-5 h-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:v("files.uploading")})]})}),(I==null?void 0:I.mode)==="create"&&d.jsx("div",{className:"mb-2",children:d.jsx(Sg,{initialValue:I.initialValue,entryType:I.entryType,depth:0,onConfirm:le,onCancel:()=>W(null)})}),D.length===0&&!I?d.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400 italic text-center py-8",children:v("files.emptyFolder")}):d.jsxs("div",{className:"grid grid-cols-5 sm:grid-cols-7 md:grid-cols-9 gap-1",children:[e!=="."&&d.jsxs("div",{"data-grid-item":!0,role:"button",tabIndex:0,className:"group relative flex flex-col items-center gap-1 p-2 rounded-lg cursor-pointer transition-colors hover:bg-gray-100 dark:hover:bg-[#253040]/50",onClick:()=>{const me=e.includes("/")?e.substring(0,e.lastIndexOf("/")):".";i(me)},onKeyDown:me=>{if(me.key==="Enter"){const xe=e.includes("/")?e.substring(0,e.lastIndexOf("/")):".";i(xe)}},children:[d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}),d.jsx("span",{className:"text-xs text-center w-full truncate text-gray-500 dark:text-gray-300",children:v("files.parentDir")})]}),D.map(me=>{const xe=e==="."?me.name:`${e}/${me.name}`,ht=ee===xe;return(I==null?void 0:I.mode)==="rename"&&I.targetPath===xe?d.jsx(BRe,{entryType:me.type,initialValue:I.initialValue,onConfirm:le,onCancel:()=>W(null)},me.name):d.jsxs("div",{"data-grid-item":!0,role:"button",tabIndex:0,className:`group relative flex flex-col items-center gap-1 p-2 rounded-lg cursor-pointer select-none transition-colors hover:bg-gray-100 dark:hover:bg-[#253040]/50 ${ht?"bg-blue-50 dark:bg-blue-900/20 ring-1 ring-blue-300 dark:ring-blue-700":""} ${b===xe?"opacity-50":""}`,onClick:()=>R(me),onKeyDown:wt=>{wt.key==="Enter"&&R(me)},onContextMenu:wt=>M(wt,me),children:[me.type==="directory"?d.jsx(Dl,{className:"w-8 h-8 text-blue-500 dark:text-blue-400"}):d.jsx(Nl,{className:"w-8 h-8 text-gray-500 dark:text-gray-400"}),d.jsx("span",{className:`text-xs text-center w-full truncate ${ht?"text-blue-600 dark:text-blue-400":"text-gray-700 dark:text-gray-200"}`,children:me.name}),s&&d.jsx("button",{className:"absolute top-1 right-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-gray-200 dark:hover:bg-[#2d3a4a] transition-opacity",onClick:wt=>U(wt,me),"aria-label":v("files.moreMenu"),children:d.jsx(Ba,{className:"w-3 h-3 text-gray-400"})})]},me.name)})]}),A&&d.jsx(pI,{x:A.x,y:A.y,targetType:A.targetType,onNewFile:()=>K("file"),onNewFolder:()=>K("directory"),onRename:()=>oe(),onDelete:()=>Z(),onClose:()=>X(null),onCopy:c?()=>{c(A.targetPath),X(null)}:void 0,onCut:u?()=>{u(A.targetPath),X(null)}:void 0,onPaste:h?()=>{const me=A.targetType==="directory"?A.targetPath:e;h(me).catch(()=>{}).finally(()=>B()),X(null)}:void 0,onDownload:O?()=>{O(A.targetPath),X(null)}:void 0,hasClipboard:p}),Y&&d.jsx(mI,{name:Y.name,type:Y.type,onConfirm:V,onCancel:()=>te(null)})]})}const GRe=[".env",".git","node_modules",".next",".cache","__pycache__",".DS_Store","dist",".turbo"],cE={FILE_ALREADY_EXISTS:"files.crudErrors.alreadyExists",PARENT_NOT_FOUND:"files.crudErrors.parentNotFound",PROTECTED_PATH:"files.crudErrors.protectedPath",RENAME_TARGET_EXISTS:"files.crudErrors.targetExists",COPY_TARGET_EXISTS:"files.crudErrors.targetExists",COPY_TOO_LARGE:"files.crudErrors.copyTooLarge",PATH_TRAVERSAL:"files.crudErrors.outsideRoot"};function HRe(){const{t}=Ce("common"),{projectSlug:e}=jn(),r=k.useCallback((Z,V)=>{const ne=Z;return ne.code&&cE[ne.code]?`${V}: ${t(cE[ne.code])}`:`${V}: ${Z.message}`},[t]),[n,i]=k.useState(""),[s,a]=k.useState(!1),o=Ht(Z=>Z.preferences.fileExplorerViewMode??"grid"),[l,c]=k.useState(o),[u,h]=k.useState("."),{toasts:O,showToast:p,removeToast:b}=gj(),[y,g]=k.useState(null),x=k.useRef(null),[v,w]=k.useState(!1),[Q,_]=k.useState(0),[$,P]=k.useState(null),[T,E]=k.useState(!1);k.useEffect(()=>{if(!n.trim()||!e){P(null),E(!1);return}E(!0);const Z=setTimeout(async()=>{try{const V=await ni.searchFiles(e,n.trim(),s),ne=s?V.results:V.results.filter(G=>!G.path.split("/").some(se=>GRe.includes(se)));P(ne)}catch{P([])}finally{E(!1)}},300);return()=>clearTimeout(Z)},[n,e,s]);const N=k.useCallback(Z=>{qo(Z)?Vo.getState().openImageViewer(e,Z):bn.getState().requestFileNavigation(e,Z)},[e]),A=k.useCallback(Z=>{Z.type==="file"&&(qo(Z.path)?Vo.getState().openImageViewer(e,Z.path):bn.getState().requestFileNavigation(e,Z.path)),i("")},[e]),X=k.useCallback(async(Z,V,ne)=>{try{const G=Z==="."?ne:`${Z}/${ne}`;await ni.createEntry(e,G,V),p({message:V==="directory"?t("files.toast.folderCreated",{name:ne}):t("files.toast.fileCreated",{name:ne}),type:"success"})}catch(G){throw p({message:r(G,t("files.toast.createFailed")),type:"error"}),G}},[e,p,t,r]),I=k.useCallback(async Z=>{try{const V=Z.includes("/")?Z.split("/").pop():Z;await ni.deleteEntry(e,Z),p({message:t("files.toast.deleted",{name:V}),type:"success"})}catch(V){throw p({message:r(V,t("files.toast.deleteFailed")),type:"error"}),V}},[e,p,t,r]),W=k.useCallback(async(Z,V)=>{try{const ne=Z.includes("/")?Z.substring(0,Z.lastIndexOf("/")):".",G=ne==="."?V:`${ne}/${V}`;await ni.renameEntry(e,Z,G),p({message:t("files.toast.renamed",{name:V}),type:"success"})}catch(ne){throw p({message:r(ne,t("files.toast.renameFailed")),type:"error"}),ne}},[e,p,t,r]),Y=k.useCallback(Z=>{g({path:Z,operation:"copy"});const V=Z.includes("/")?Z.split("/").pop():Z;p({message:t("files.toast.copied",{name:V}),type:"success"})},[p,t]),te=k.useCallback(Z=>{g({path:Z,operation:"cut"});const V=Z.includes("/")?Z.split("/").pop():Z;p({message:t("files.toast.cut",{name:V}),type:"success"})},[p,t]),ee=k.useCallback(async Z=>{if(!y||!e)return{};const V=y,ne=V.path.includes("/")?V.path.split("/").pop():V.path,G=V.path.includes("/")?V.path.substring(0,V.path.lastIndexOf("/")):".";if(V.operation==="cut"&&G===Z)return{};const he=V.operation==="cut";try{let se=ne;if(!he&&G===Z){const re=ne.match(/^(.+?)(\.tar\.\w+)$/);let Qe,me;if(re)Qe=re[1],me=re[2];else{const wt=ne.lastIndexOf(".");Qe=wt>0?ne.substring(0,wt):ne,me=wt>0?ne.substring(wt):""}const xe=await ni.listDirectory(e,Z),ht=new Set(xe.entries.map(wt=>wt.name));se=`${Qe} - Copy${me}`;let St=2;for(;ht.has(se);)se=`${Qe} - Copy (${St})${me}`,St++}const ce=Z==="."?se:`${Z}/${se}`;return he?(await ni.renameEntry(e,V.path,ce),p({message:t("files.toast.moved",{name:se}),type:"success"}),g(re=>(re==null?void 0:re.path)===V.path&&(re==null?void 0:re.operation)==="cut"?null:re)):(await ni.copyEntry(e,V.path,ce),p({message:t("files.toast.pasted",{name:se}),type:"success"})),he&&G!==Z?{sourceDir:G}:{}}catch(se){throw p({message:r(se,t("files.toast.pasteFailed")),type:"error"}),se}},[y,e,p,t,r]),B=k.useCallback(async Z=>{if(!e)return;const V=ni.getDownloadUrl(e,Z);try{if(!(await fetch(V,{method:"HEAD"})).ok){p({message:t("files.toast.downloadFailed"),type:"error"});return}const G=document.createElement("a");G.href=V,G.download=Z.includes("/")?Z.split("/").pop():Z,document.body.appendChild(G),G.click(),document.body.removeChild(G)}catch{p({message:t("files.toast.downloadFailed"),type:"error"})}},[e,p,t]),D=k.useRef(!1),R=k.useCallback(async Z=>{if(!(Z.length===0||!e)){if(D.current){p({message:t("files.toast.uploadInProgress"),type:"info"});return}D.current=!0,w(!0);try{const V=await ni.uploadFiles(e,u,Z),ne=V.files.length;p({message:ne===1?t("files.toast.uploaded",{name:V.files[0].path.split("/").pop()}):t("files.toast.uploadedMultiple",{count:ne}),type:"success"}),_(G=>G+1)}catch(V){p({message:r(V,t("files.toast.uploadFailed")),type:"error"})}finally{D.current=!1,w(!1),x.current&&(x.current.value="")}}},[e,u,p,t,r]),M=k.useCallback(()=>{var Z;(Z=x.current)==null||Z.click()},[]),U=k.useCallback(async Z=>{const V=Z.target.files;!V||V.length===0||await R(Array.from(V))},[R]),z=k.useCallback(Z=>{var ne;const V=(ne=Z.clipboardData)==null?void 0:ne.files;!V||V.length===0||(Z.preventDefault(),R(Array.from(V)))},[R]),K=k.useRef(null);k.useEffect(()=>{const Z=K.current;if(Z)return Z.addEventListener("paste",z),()=>Z.removeEventListener("paste",z)},[z]);const oe=(()=>{if(u===".")return[{name:t("files.root"),path:"."}];const Z=u.split("/"),V=[{name:t("files.root"),path:"."}];for(let ne=0;ne<Z.length;ne++)V.push({name:Z[ne],path:Z.slice(0,ne+1).join("/")});return V})();if(!e)return d.jsx("div",{className:"flex items-center justify-center h-full text-gray-500 dark:text-gray-300",children:t("files.projectNotFound")});const le=$!==null||T;return d.jsxs("div",{ref:K,className:"flex flex-col h-full",tabIndex:-1,children:[d.jsx("input",{ref:x,type:"file",multiple:!0,className:"hidden",onChange:U}),d.jsx("div",{className:"sticky top-0 z-[5] bg-white dark:bg-[#1c2129] border-b border-gray-200 dark:border-[#253040]",children:d.jsxs("div",{className:"flex items-center justify-between px-4 py-2 gap-3",children:[le?d.jsx("div",{}):d.jsx("nav",{"aria-label":t("files.breadcrumb"),className:"flex-shrink min-w-0",children:d.jsx("ol",{className:"flex items-center gap-0.5 text-xs",children:oe.map((Z,V)=>d.jsxs("li",{className:"flex items-center gap-0.5 min-w-0",children:[V>0&&d.jsx(Yo,{className:"w-3 h-3 text-gray-400 dark:text-gray-500 flex-shrink-0","aria-hidden":"true"}),V===oe.length-1?d.jsxs("span",{className:"inline-flex items-center gap-1 font-medium text-gray-800 dark:text-gray-200 truncate","aria-current":"page",children:[V===0&&d.jsx(x$,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400 flex-shrink-0"}),Z.name]}):d.jsxs("button",{onClick:()=>h(Z.path),className:`inline-flex items-center gap-1 text-gray-500 dark:text-gray-300
1353
1353
  hover:text-blue-600 dark:hover:text-blue-400 transition-colors truncate`,children:[V===0&&d.jsx(x$,{className:"w-3.5 h-3.5 flex-shrink-0"}),Z.name]})]},Z.path))})}),d.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[d.jsxs("div",{className:"relative flex items-center",children:[d.jsx(vd,{className:"absolute left-2.5 w-3.5 h-3.5 text-gray-400 pointer-events-none","aria-hidden":"true"}),d.jsx("input",{type:"text",value:n,onChange:Z=>i(Z.target.value),placeholder:t("files.searchPlaceholder"),className:`w-36 sm:w-44 pl-8 pr-7 py-1.5 text-xs bg-gray-100 dark:bg-[#263240] dark:text-white
1354
1354
  border border-gray-200 dark:border-[#253040] rounded-lg
1355
1355
  focus:outline-none focus:ring-1 focus:ring-blue-500 focus:w-56