loki-mode 6.74.3 → 6.74.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/dashboard/__init__.py +1 -1
- package/docs/INSTALLATION.md +1 -1
- package/mcp/__init__.py +1 -1
- package/package.json +1 -1
- package/web-app/dist/assets/{AdminPage-DZhVlTXm.js → AdminPage-Cwqm_kDg.js} +1 -1
- package/web-app/dist/assets/{Avatar-Bbw5Q-Wz.js → Avatar-BgcFY2E5.js} +1 -1
- package/web-app/dist/assets/{Badge-iZ84_iz4.js → Badge-DeFGfZLB.js} +1 -1
- package/web-app/dist/assets/{Button-DO-Xq3YT.js → Button-Dg1EkPtN.js} +1 -1
- package/web-app/dist/assets/{ComparePage-CMjaGKwJ.js → ComparePage-D-wvMVP2.js} +1 -1
- package/web-app/dist/assets/{GitHubIssuesPanel-TLudouS-.js → GitHubIssuesPanel-B_Jm7CmJ.js} +1 -1
- package/web-app/dist/assets/{GitHubPRsPanel-bjj0yQTk.js → GitHubPRsPanel-B5i8Q99N.js} +1 -1
- package/web-app/dist/assets/{HomePage-t5G7OAGE.js → HomePage-CUDTdntY.js} +1 -1
- package/web-app/dist/assets/{LoginPage-CeQRXV4C.js → LoginPage-BobwVXx5.js} +1 -1
- package/web-app/dist/assets/{MetricsPage-B2zKVyJq.js → MetricsPage-DmM--20B.js} +1 -1
- package/web-app/dist/assets/{NotFoundPage-CxCe17V-.js → NotFoundPage-6_gjeogD.js} +1 -1
- package/web-app/dist/assets/{ProjectPage-B1Wti2GW.js → ProjectPage-C3R2wbFt.js} +5 -5
- package/web-app/dist/assets/{ProjectsPage-BDWfVwLK.js → ProjectsPage-DQr06iBk.js} +1 -1
- package/web-app/dist/assets/{SettingsPage-DlH1leQV.js → SettingsPage-eROlGKB9.js} +1 -1
- package/web-app/dist/assets/{ShowcasePage-DPnh3esb.js → ShowcasePage-DEA5tT_R.js} +1 -1
- package/web-app/dist/assets/{SystemSettingsPage-DZLDjoUr.js → SystemSettingsPage-C_rIbgZg.js} +1 -1
- package/web-app/dist/assets/{TeamsPage-BbYt_ldg.js → TeamsPage-DZGoYZnD.js} +1 -1
- package/web-app/dist/assets/{TemplatesPage-BuiIghxK.js → TemplatesPage-DVblWpbO.js} +1 -1
- package/web-app/dist/assets/{TerminalOutput-xGAottmX.js → TerminalOutput-DnESY9zk.js} +1 -1
- package/web-app/dist/assets/{activity-CmQBMOsV.js → activity-COLsZyo1.js} +1 -1
- package/web-app/dist/assets/{bell-BzaVT-q-.js → bell-BjLe9xXk.js} +1 -1
- package/web-app/dist/assets/{bot-CwK5RJjE.js → bot-Dz62aBIi.js} +1 -1
- package/web-app/dist/assets/{check-CxwV5Bzq.js → check-BQPQjkH4.js} +1 -1
- package/web-app/dist/assets/{chevron-left--TWMaYeL.js → chevron-left-BVvOVUQ8.js} +1 -1
- package/web-app/dist/assets/{circle-alert-BeU0GAf7.js → circle-alert-DqoLW238.js} +1 -1
- package/web-app/dist/assets/{clock-CasItKBM.js → clock-Cn9fFUva.js} +1 -1
- package/web-app/dist/assets/{cloud-p2bU6CXv.js → cloud-COJxbgUu.js} +1 -1
- package/web-app/dist/assets/{copy-BD_1Idwb.js → copy-DOn0hVgy.js} +1 -1
- package/web-app/dist/assets/{database-DpRtc5nU.js → database-Bj3Llvnk.js} +1 -1
- package/web-app/dist/assets/{dollar-sign-22E4a6bP.js → dollar-sign-BcmncygQ.js} +1 -1
- package/web-app/dist/assets/{file-code-corner-D1Re8J8b.js → file-code-corner-BysxoSyu.js} +1 -1
- package/web-app/dist/assets/{file-plus-BuKNP2FZ.js → file-plus-Dwi1MqSS.js} +1 -1
- package/web-app/dist/assets/{folder-open-DI7rcz5V.js → folder-open-WzXNCq2x.js} +1 -1
- package/web-app/dist/assets/{git-commit-horizontal-C4J-dLq2.js → git-commit-horizontal-D85UUfNF.js} +1 -1
- package/web-app/dist/assets/{globe-3vM1jtqs.js → globe-CegT0VaL.js} +1 -1
- package/web-app/dist/assets/{hammer-ukr7gJ35.js → hammer-ZGKvu_xy.js} +1 -1
- package/web-app/dist/assets/{index-BYtEgkrl.js → index-_2iPl2nX.js} +2 -2
- package/web-app/dist/assets/{layers-DZtUCskD.js → layers-B40lki5j.js} +1 -1
- package/web-app/dist/assets/{lightbulb-CS390qaD.js → lightbulb-CFSoqUsV.js} +1 -1
- package/web-app/dist/assets/{loader-circle-BB_MVBmf.js → loader-circle-womi7Brk.js} +1 -1
- package/web-app/dist/assets/{lock-BtBqgsZ0.js → lock-CEWBb_SL.js} +1 -1
- package/web-app/dist/assets/{mail-rabbO_5W.js → mail-DimGrYf8.js} +1 -1
- package/web-app/dist/assets/{package-MkQHuN6g.js → package-DysIuuIJ.js} +1 -1
- package/web-app/dist/assets/{plus-C_Sb_op9.js → plus-DG1hW27_.js} +1 -1
- package/web-app/dist/assets/{refresh-cw-DEs70a7E.js → refresh-cw-X31ig0S6.js} +1 -1
- package/web-app/dist/assets/{rotate-ccw-DvMVZ3AX.js → rotate-ccw-CBXooICo.js} +1 -1
- package/web-app/dist/assets/{save-DOEP5ubi.js → save-DQVrWTjZ.js} +1 -1
- package/web-app/dist/assets/{server-DJBVZTUn.js → server-BYAMALfa.js} +1 -1
- package/web-app/dist/assets/{shield-alert-xdJ97H55.js → shield-alert-B3G7vLiW.js} +1 -1
- package/web-app/dist/assets/{trash-2-DuD7ogiq.js → trash-2-ChVunC-C.js} +1 -1
- package/web-app/dist/assets/{trending-down-BYq7V2Q5.js → trending-down-DgsuOE2t.js} +1 -1
- package/web-app/dist/assets/{trending-up-BeD-iNQC.js → trending-up-CZHZsGeN.js} +1 -1
- package/web-app/dist/assets/{usePolling-2LO_f1l4.js → usePolling-ns_dFCVn.js} +1 -1
- package/web-app/dist/assets/{user-CJc2DWfN.js → user-FQUrWHhF.js} +1 -1
- package/web-app/dist/index.html +1 -1
- package/web-app/server.py +62 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GitHubIssuesPanel-
|
|
2
|
-
var ea=e=>{throw TypeError(e)};var ta=(e,t,s)=>t.has(e)||ea("Cannot "+s);var Fs=(e,t,s)=>(ta(e,t,"read from private field"),s?s.call(e):t.get(e)),sa=(e,t,s)=>t.has(e)?ea("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),ia=(e,t,s,i)=>(ta(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s);import{c as oe,r as d,W as ks,j as r,f as Wl,g as lr,h as ls,I as Ul,T as Ot,R as $t,i as es,M as Kl,k as Ji,l as kt,S as ql,U as pd,X as ft,m as ts,Z as Zt,a as K,E as ss,G as ze,K as _d,n as gd,o as xd,F as cr,P as It,_ as Xn,b as hr,p as Vl,q as Gl,s as vd,t as bd,A as Jn,L as yd,B as Jr,v as Zr,w as Sd,e as wd,x as ys,y as ra,z as na,D as Cd,H as kd,J as Nr,N as Nd,u as jd}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GitHubIssuesPanel-B_Jm7CmJ.js","assets/index-_2iPl2nX.js","assets/index-CVM4A1Fw.css","assets/Button-Dg1EkPtN.js","assets/refresh-cw-X31ig0S6.js","assets/circle-alert-DqoLW238.js","assets/user-FQUrWHhF.js","assets/rotate-ccw-CBXooICo.js","assets/loader-circle-womi7Brk.js","assets/TerminalOutput-DnESY9zk.js","assets/lock-CEWBb_SL.js","assets/package-DysIuuIJ.js","assets/file-code-corner-BysxoSyu.js","assets/file-plus-Dwi1MqSS.js","assets/clock-Cn9fFUva.js","assets/activity-COLsZyo1.js","assets/bot-Dz62aBIi.js","assets/check-BQPQjkH4.js","assets/hammer-ZGKvu_xy.js","assets/dollar-sign-BcmncygQ.js","assets/globe-CegT0VaL.js","assets/copy-DOn0hVgy.js","assets/git-commit-horizontal-D85UUfNF.js","assets/plus-DG1hW27_.js","assets/trash-2-ChVunC-C.js","assets/trending-down-DgsuOE2t.js","assets/save-DQVrWTjZ.js","assets/trending-up-CZHZsGeN.js","assets/layers-B40lki5j.js","assets/folder-open-WzXNCq2x.js","assets/server-BYAMALfa.js","assets/GitHubPRsPanel-B5i8Q99N.js","assets/chevron-left-BVvOVUQ8.js","assets/shield-alert-B3G7vLiW.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var ea=e=>{throw TypeError(e)};var ta=(e,t,s)=>t.has(e)||ea("Cannot "+s);var Fs=(e,t,s)=>(ta(e,t,"read from private field"),s?s.call(e):t.get(e)),sa=(e,t,s)=>t.has(e)?ea("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),ia=(e,t,s,i)=>(ta(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s);import{c as oe,r as d,W as ks,j as r,f as Wl,g as lr,h as ls,I as Ul,T as Ot,R as $t,i as es,M as Kl,k as Ji,l as kt,S as ql,U as pd,X as ft,m as ts,Z as Zt,a as K,E as ss,G as ze,K as _d,n as gd,o as xd,F as cr,P as It,_ as Xn,b as hr,p as Vl,q as Gl,s as vd,t as bd,A as Jn,L as yd,B as Jr,v as Zr,w as Sd,e as wd,x as ys,y as ra,z as na,D as Cd,H as kd,J as Nr,N as Nd,u as jd}from"./index-_2iPl2nX.js";import{T as Ed,R as Rd,S as Zi,C as Qr,P as Yl,F as Dd,E as $i}from"./TerminalOutput-DnESY9zk.js";import{B as ue}from"./Button-Dg1EkPtN.js";import{P as Xl}from"./package-DysIuuIJ.js";import{F as Z}from"./file-code-corner-BysxoSyu.js";import{F as dr}from"./file-plus-Dwi1MqSS.js";import{C as nt}from"./clock-Cn9fFUva.js";import{A as Pd}from"./activity-COLsZyo1.js";import{B as Md}from"./bot-Dz62aBIi.js";import{C as Ut}from"./check-BQPQjkH4.js";import{L as di}from"./loader-circle-womi7Brk.js";import{H as Ld}from"./hammer-ZGKvu_xy.js";import{D as Jl}from"./dollar-sign-BcmncygQ.js";import{R as Ct}from"./refresh-cw-X31ig0S6.js";import{C as Ds}from"./circle-alert-DqoLW238.js";import{G as en}from"./globe-CegT0VaL.js";import{C as Zn}from"./copy-DOn0hVgy.js";import{G as Zl}from"./git-commit-horizontal-D85UUfNF.js";import{P as ur}from"./plus-DG1hW27_.js";import{T as Qn}from"./trash-2-ChVunC-C.js";import{R as Ql,E as Bd}from"./rotate-ccw-CBXooICo.js";import{M as ec,T as Td}from"./trending-down-DgsuOE2t.js";import{S as zd}from"./save-DQVrWTjZ.js";import{T as Ad}from"./trending-up-CZHZsGeN.js";import{L as Od}from"./layers-B40lki5j.js";import{F as tn}from"./folder-open-WzXNCq2x.js";import{S as $d}from"./server-BYAMALfa.js";/**
|
|
3
3
|
* @license lucide-react v0.577.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -252,7 +252,7 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
|
|
|
252
252
|
\x1B[31m-- Terminal disconnected. Max reconnect attempts reached. Refresh the page to try again. --\x1B[0m`);return}const y=Math.min(ex*Math.pow(2,v),tx);h.current=v+1,_&&_.writeln(`\r
|
|
253
253
|
\x1B[33m-- Terminal disconnected. Reconnecting in ${(y/1e3).toFixed(0)}s (attempt ${v+1}/${wl})... --\x1B[0m`),a.current=setTimeout(()=>{l.current&&u()},y)},g.onerror=()=>{}},[e,c]);return d.useEffect(()=>{l.current=!0,h.current=0;const m=s.current;if(!m)return;const f=new Ug({cursorBlink:!0,fontSize:13,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",theme:{background:"#1a1a2e",foreground:"#e0e0e0",cursor:"#a78bfa",selectionBackground:"#3d3d5c",black:"#1a1a2e",red:"#ff6b6b",green:"#51cf66",yellow:"#ffd43b",blue:"#74c0fc",magenta:"#da77f2",cyan:"#66d9ef",white:"#e0e0e0",brightBlack:"#4a4a6a",brightRed:"#ff8787",brightGreen:"#69db7c",brightYellow:"#ffe066",brightBlue:"#91d5ff",brightMagenta:"#e599f7",brightCyan:"#99f7f5",brightWhite:"#ffffff"},scrollback:1e4,convertEol:!0,allowProposedApi:!0}),g=new Vg,p=new Qg;f.loadAddon(g),f.loadAddon(p),f.open(m),i.current=f,n.current=g;try{g.fit()}catch{}f.onData(y=>{const x=o.current;x&&x.readyState===WebSocket.OPEN&&x.send(JSON.stringify({type:"input",data:y}))}),u();let _=null;const v=new ResizeObserver(()=>{_&&clearTimeout(_),_=setTimeout(()=>{if(!(!n.current||!i.current))try{n.current.fit(),c()}catch{}},50)});return v.observe(m),()=>{l.current=!1,v.disconnect(),_&&clearTimeout(_),a.current&&clearTimeout(a.current),o.current&&(o.current.onclose=null,o.current.close(),o.current=null),f.dispose(),i.current=null,n.current=null}},[u,c]),d.useEffect(()=>{if(t&&n.current&&i.current){const m=setTimeout(()=>{var f;try{(f=n.current)==null||f.fit(),c()}catch{}},50);return()=>clearTimeout(m)}},[t,c]),r.jsx("div",{ref:s,className:"h-full w-full",style:{backgroundColor:"#1a1a2e"}})}const Cl={file_created:{icon:dr,color:"bg-blue-500",bgColor:"bg-blue-500/10",labelColor:"text-blue-600"},file_modified:{icon:Z,color:"bg-blue-400",bgColor:"bg-blue-400/10",labelColor:"text-blue-500"},dependency_install:{icon:Xl,color:"bg-teal-500",bgColor:"bg-teal-500/10",labelColor:"text-teal-600"},test_pass:{icon:kt,color:"bg-green-500",bgColor:"bg-green-500/10",labelColor:"text-green-600"},test_fail:{icon:Ji,color:"bg-red-500",bgColor:"bg-red-500/10",labelColor:"text-red-500"},error:{icon:Ji,color:"bg-red-500",bgColor:"bg-red-500/10",labelColor:"text-red-500"},narration:{icon:Kl,color:"bg-purple-500",bgColor:"bg-purple-500/10",labelColor:"text-purple-600"},command:{icon:es,color:"bg-gray-500",bgColor:"bg-gray-500/10",labelColor:"text-gray-600"},phase_change:{icon:$t,color:"bg-primary",bgColor:"bg-primary/10",labelColor:"text-primary"},deploy:{icon:$t,color:"bg-primary",bgColor:"bg-primary/10",labelColor:"text-primary"},warning:{icon:Ot,color:"bg-yellow-500",bgColor:"bg-yellow-500/10",labelColor:"text-yellow-600"},info:{icon:Ul,color:"bg-gray-400",bgColor:"bg-gray-400/10",labelColor:"text-gray-500"}};function kl(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return""}}function ix({event:e,isLast:t,onFileClick:s}){const i=Cl[e.type]||Cl.info,n=i.icon,o=e.type==="narration";return r.jsxs("div",{className:"flex gap-3 group",children:[r.jsxs("div",{className:"flex flex-col items-center flex-shrink-0",children:[r.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center ${i.bgColor}`,children:r.jsx(n,{size:14,className:i.labelColor})}),!t&&r.jsx("div",{className:"w-px flex-1 bg-border min-h-[16px]"})]}),r.jsx("div",{className:"flex-1 min-w-0 pb-4 ",children:o?r.jsxs("div",{className:"relative bg-purple-500/5 border border-purple-500/20 rounded-lg px-3 py-2 mt-0.5",children:[r.jsx("div",{className:"absolute -left-1.5 top-2.5 w-2.5 h-2.5 bg-purple-500/5 border-l border-b border-purple-500/20 rotate-45"}),r.jsx("p",{className:"text-xs text-ink leading-relaxed",children:e.message}),e.detail&&r.jsx("p",{className:"text-[11px] text-muted mt-1 leading-relaxed",children:e.detail}),r.jsxs("span",{className:"text-[10px] text-muted/60 mt-1.5 flex items-center gap-1",children:[r.jsx(nt,{size:10}),kl(e.timestamp)]})]}):r.jsxs("div",{className:"mt-1",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:`text-xs font-medium ${i.labelColor}`,children:e.message}),e.filePath&&s&&r.jsx("button",{onClick:()=>s(e.filePath),className:"text-[11px] font-mono text-primary hover:text-primary/80 hover:underline truncate max-w-[200px]",title:e.filePath,children:e.filePath})]}),r.jsxs("span",{className:"text-[10px] text-muted/60 flex items-center gap-1 mt-0.5",children:[r.jsx(nt,{size:10}),kl(e.timestamp)]})]})})]})}const Kr=20,Nl=10;function rx({events:e,onFileClick:t,maxHeight:s}){const i=d.useRef(null),[n,o]=d.useState(!0);if(d.useEffect(()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e.length]),d.useEffect(()=>{e.length>Kr},[e.length,n]),e.length===0)return r.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center",children:[r.jsx(Wl,{size:28,className:"text-muted/30 mb-3"}),r.jsx("p",{className:"text-xs text-muted font-medium",children:"No build events yet"}),r.jsx("p",{className:"text-[11px] text-muted/70 mt-1",children:"Events will appear here as the build progresses."})]});const a=e.length>Kr&&n,l=a?e.slice(-Nl):e,h=a?e.length-Nl:0;return r.jsxs("div",{ref:i,className:"overflow-y-auto terminal-scroll px-3 py-3",style:{maxHeight:s||"100%"},children:[a&&h>0&&r.jsxs("button",{onClick:()=>o(!1),className:"flex items-center gap-1.5 text-[11px] text-primary hover:text-primary/80 font-medium mb-3 ml-9",children:[r.jsx(lr,{size:12}),"Show ",h," earlier event",h!==1?"s":""]}),!n&&e.length>Kr&&r.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 text-[11px] text-primary hover:text-primary/80 font-medium mb-3 ml-9",children:[r.jsx(ls,{size:12}),"Collapse older events"]}),l.map((c,u)=>r.jsx(ix,{event:c,isLast:u===l.length-1,onFileClick:t},c.id))]})}const jl=[{id:"terminal",label:"Terminal",icon:es,alwaysShow:!0},{id:"activity",label:"Activity",icon:Pd,alwaysShow:!0},{id:"build",label:"Build Log",icon:Nu},{id:"agents",label:"Agents",icon:Md},{id:"quality",label:"Quality",icon:ql}];function nx({status:e}){switch(e){case"pass":return r.jsx(Ut,{size:14,className:"text-success"});case"fail":return r.jsx(ft,{size:14,className:"text-danger"});default:return r.jsx(nt,{size:14,className:"text-muted"})}}function ox({agents:e}){return!e||e.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(pd,{size:24,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted font-medium",children:"No agents active"}),r.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Agents appear here during active builds"})]}):r.jsx("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:e.map(t=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-hover text-xs",children:[r.jsx("span",{className:"font-semibold text-ink truncate",children:t.name}),r.jsx("span",{className:"text-xs font-mono text-muted-accessible px-1.5 py-0.5 rounded-btn bg-card",children:t.type}),r.jsx("span",{className:`text-xs font-semibold ${t.status==="running"?"text-success":"text-muted"}`,children:t.status}),r.jsx("span",{className:"ml-auto text-xs text-muted-accessible font-mono truncate max-w-[200px]",children:t.task})]},t.id))})}function ax({checklist:e}){return!e||!e.items||e.items.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(ql,{size:24,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted font-medium",children:"No quality gate data"}),r.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Quality gates appear during active builds"})]}):r.jsxs("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:[r.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-xs text-muted-accessible font-semibold uppercase",children:[r.jsx("span",{children:"Gate"}),r.jsxs("span",{className:"ml-auto",children:[e.passed,"/",e.total," passed"]})]}),e.items.map(t=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-btn hover:bg-hover text-xs",children:[r.jsx(nx,{status:t.status}),r.jsx("span",{className:"text-ink",children:t.label}),t.details&&r.jsx("span",{className:"ml-auto text-xs text-muted-accessible truncate max-w-[200px]",children:t.details})]},t.id))]})}function lx({logs:e,logsLoading:t,agents:s,checklist:i,sessionId:n,isRunning:o,subscribe:a,buildEvents:l,onFileClick:h}){var _;const[c,u]=d.useState("terminal"),m=s&&s.length>0,f=i&&i.items&&i.items.length>0,g=e&&e.length>0,p=jl.filter(v=>!!(v.alwaysShow||v.id==="build"&&(g||o)||v.id==="agents"&&(m||o)||v.id==="quality"&&(f||o)));return p.find(v=>v.id===c)||u("terminal"),r.jsxs("div",{className:"h-full flex flex-col bg-card",children:[r.jsx("div",{role:"tablist",className:"flex items-center border-b border-border px-2 flex-shrink-0",children:p.map(v=>{const y=v.icon,x=c===v.id;return r.jsxs("button",{role:"tab","aria-selected":x,onClick:()=>u(v.id),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${x?"border-primary text-primary":"border-transparent text-muted hover:text-ink"}`,children:[r.jsx(y,{size:14}),v.label,v.id==="agents"&&m&&r.jsx("span",{className:"ml-0.5 px-1.5 py-0.5 text-[10px] font-bold rounded-full bg-primary/10 text-primary",children:s.length}),v.id==="quality"&&f&&r.jsxs("span",{className:"ml-0.5 px-1.5 py-0.5 text-[10px] font-bold rounded-full bg-success/10 text-success",children:[i.passed,"/",i.total]})]},v.id)})}),r.jsxs("div",{role:"tabpanel","aria-label":(_=jl.find(v=>v.id===c))==null?void 0:_.label,className:"flex-1 min-h-0 overflow-hidden relative",children:[r.jsx("div",{className:"absolute inset-0",style:{visibility:c==="terminal"?"visible":"hidden",zIndex:c==="terminal"?1:0},children:r.jsx(sx,{sessionId:n,isActive:c==="terminal"})}),c==="build"&&r.jsx(Ed,{logs:e,loading:t,subscribe:a}),c==="agents"&&r.jsx(ox,{agents:s}),c==="activity"&&r.jsx(rx,{events:l||[],onFileClick:h}),c==="quality"&&r.jsx(ax,{checklist:i})]})]})}const El={ai:["Warming up the AI...","Reading your code...","Thinking about the best approach...","Running quality checks...","Almost there..."],build:["Setting things up...","Installing dependencies...","Compiling your project...","Running the build pipeline...","Finishing touches..."],deploy:["Preparing containers...","Pushing to the cloud...","Configuring services...","Running health checks...","Almost live..."],general:["Loading...","Getting things ready...","Just a moment...","Fetching data...","Almost there..."]};function cx({context:e="general",className:t=""}){const s=El[e]||El.general,[i,n]=d.useState(0),[o,a]=d.useState(!1);return d.useEffect(()=>{const l=setInterval(()=>{a(!0),setTimeout(()=>{n(h=>(h+1)%s.length),a(!1)},300)},3e3);return()=>clearInterval(l)},[s.length]),r.jsxs("div",{className:`flex items-center gap-2 ${t}`,children:[r.jsx(di,{size:14,className:"animate-spin text-primary/60"}),r.jsx("span",{className:`text-xs text-muted transition-opacity duration-300 ${o?"opacity-0":"opacity-100"}`,children:s[i]})]})}const qr=[{id:"planning",label:"Plan",color:"bg-blue-500",textColor:"text-blue-500",icon:Xd},{id:"building",label:"Build",color:"bg-primary",textColor:"text-primary",icon:Ld},{id:"testing",label:"Test",color:"bg-teal",textColor:"text-teal",icon:si},{id:"reviewing",label:"Review",color:"bg-warning",textColor:"text-warning",icon:ts},{id:"complete",label:"Done",color:"bg-success",textColor:"text-success",icon:kt}];function hx({phase:e,iteration:t,maxIterations:s,cost:i,startTime:n,isRunning:o}){const[a,l]=d.useState(0),[h,c]=d.useState(e),[u,m]=d.useState(!1);if(d.useEffect(()=>{if(!o||!n)return;const x=setInterval(()=>{l(Math.floor((Date.now()-n)/1e3))},1e3);return()=>clearInterval(x)},[o,n]),d.useEffect(()=>{if(e!==h){m(!0);const x=setTimeout(()=>{c(e),m(!1)},400);return()=>clearTimeout(x)}},[e,h]),!o&&e==="idle")return null;const f=qr.findIndex(x=>x.id===e),g=s>0?Math.min(t/s*100,100):0,p=t>0?a/t:60,_=Math.max(0,s-t),v=Math.ceil(p*_),y=x=>x<60?`${x}s`:`${Math.floor(x/60)}m ${x%60}s`;return r.jsxs("div",{className:"flex-shrink-0 build-progress-container",children:[r.jsxs("div",{className:"h-1 bg-border relative overflow-hidden",children:[r.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-teal build-progress-bar",style:{width:`${g}%`}}),o&&r.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-white/20 to-transparent animate-shimmer"})]}),r.jsxs("div",{className:`px-4 py-1.5 flex items-center gap-4 bg-card border-b border-border text-xs ${u?"phase-transitioning":""}`,children:[r.jsx("div",{className:"flex items-center gap-1",children:qr.map((x,k)=>{const N=k<f,w=k===f,R=x.icon;return r.jsxs("div",{className:`flex items-center gap-1 phase-indicator ${w?"phase-indicator-active":""} ${N?"phase-indicator-complete":""}`,children:[r.jsx("div",{className:`phase-icon-wrapper ${w?"phase-icon-active":""} ${N?"phase-icon-complete":""}`,children:N?r.jsx(kt,{size:14,className:"text-success phase-check-enter"}):w?r.jsx(R,{size:14,className:`${x.textColor} phase-icon-spin`}):r.jsx(R,{size:14,className:"text-muted/40"})}),r.jsx("span",{className:`text-[11px] font-medium transition-all duration-300 ${w?"text-ink":N?"text-success":"text-muted/50"}`,children:x.label}),k<qr.length-1&&r.jsx("div",{className:`mx-1 h-px w-4 transition-all duration-500 ${N?"bg-success":"bg-border"}`})]},x.id)})}),o&&e!=="complete"&&e!=="idle"&&r.jsx(cx,{context:"build"}),r.jsx("div",{className:"flex-1"}),r.jsxs("div",{className:"flex items-center gap-3 text-muted",children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Zt,{size:12}),"Iter ",t,"/",s]}),r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(nt,{size:12}),y(a),o&&v>0&&r.jsxs("span",{className:"text-muted/60",children:["(",y(v)," left)"]})]}),r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Jl,{size:12}),"$",i.toFixed(2)]})]})]})]})}const Vr=[{id:"vercel",name:"Vercel",description:"Optimized for Next.js, React, and static sites with global CDN.",initial:"V",color:"text-ink",bgColor:"bg-ink/10",borderColor:"border-ink/20",tokenUrl:"https://vercel.com/account/tokens",tokenUrlLabel:"Get your token from vercel.com/account/tokens",hasTokenAuth:!0},{id:"netlify",name:"Netlify",description:"Deploy with CI/CD, serverless functions, and form handling.",initial:"N",color:"text-teal-600",bgColor:"bg-teal-500/10",borderColor:"border-teal-500/20",tokenUrl:"https://app.netlify.com/user/applications#personal-access-tokens",tokenUrlLabel:"Get your token from app.netlify.com/user/applications",hasTokenAuth:!0},{id:"github",name:"GitHub",description:"Free hosting for static sites directly from a GitHub repository.",initial:"G",color:"text-purple-600",bgColor:"bg-purple-500/10",borderColor:"border-purple-500/20",tokenUrl:"https://cli.github.com/",tokenUrlLabel:"Install GitHub CLI",hasTokenAuth:!1}];function dx({platform:e,onConnect:t}){const[s,i]=d.useState(""),[n,o]=d.useState(!1),[a,l]=d.useState(null),h=d.useCallback(async c=>{if(c.preventDefault(),!!s.trim()){o(!0),l(null);try{await t(s.trim()),i("")}catch(u){l(u instanceof Error?u.message:"Connection failed")}finally{o(!1)}}},[s,t]);return r.jsxs("form",{onSubmit:h,className:"mt-3 space-y-2.5",children:[r.jsxs("div",{children:[r.jsxs("label",{htmlFor:`token-${e.id}`,className:"sr-only",children:[e.name," Token"]}),r.jsx("input",{id:`token-${e.id}`,type:"password",value:s,onChange:c=>i(c.target.value),placeholder:`${e.name} access token`,disabled:n,className:`w-full px-3 py-2 text-sm border border-border rounded-lg bg-card text-ink
|
|
254
254
|
focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary
|
|
255
|
-
placeholder:text-muted disabled:opacity-50`})]}),r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsxs("a",{href:e.tokenUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:[e.tokenUrlLabel,r.jsx(ss,{size:10})]}),r.jsx(ue,{type:"submit",variant:"primary",size:"sm",loading:n,disabled:!s.trim()||n,children:"Connect"})]}),a&&r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 mt-1",children:[r.jsx(Ds,{size:12}),a]})]})}function ux(){return r.jsxs("div",{className:"mt-3 space-y-2",children:[r.jsxs("div",{className:"flex items-start gap-2 bg-amber-500/5 border border-amber-500/15 rounded-lg px-3 py-2.5",children:[r.jsx(es,{size:14,className:"text-amber-600 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs text-muted leading-relaxed",children:[r.jsx("p",{className:"font-medium text-ink mb-1",children:"Run in your terminal:"}),r.jsx("code",{className:"block bg-ink/5 rounded px-2 py-1 font-mono text-[11px] text-ink",children:"gh auth login"})]})]}),r.jsxs("a",{href:"https://cli.github.com/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:["Install GitHub CLI",r.jsx(ss,{size:10})]})]})}function fx({platform:e,status:t,onConnect:s,onDisconnect:i}){const[n,o]=d.useState(!1),[a,l]=d.useState(!1),h=d.useCallback(async()=>{l(!0);try{i()}finally{l(!1)}},[i]),c=d.useCallback(async u=>{await s(u),o(!1)},[s]);return r.jsxs("div",{className:`border rounded-lg p-4 transition-colors ${t.connected?"border-green-500/30 bg-green-500/5":"border-border hover:border-primary/30 hover:bg-hover"}`,children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${e.bgColor}`,children:r.jsx("span",{className:`text-sm font-bold ${e.color}`,children:e.initial})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:e.name}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:e.description})]}),r.jsx("div",{className:"flex-shrink-0",children:r.jsx("span",{className:`inline-block w-2.5 h-2.5 rounded-full ${t.connected?"bg-green-500":"bg-gray-300"}`,title:t.connected?"Connected":"Not connected"})})]}),t.connected?r.jsxs("div",{className:"mt-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Connected as ",t.user||"unknown"]}),t.last_deployed&&r.jsxs("p",{className:"text-[11px] text-muted",children:["Last deployed: ",new Date(t.last_deployed).toLocaleString()]}),r.jsx(ue,{variant:"danger",size:"sm",icon:Fu,onClick:h,loading:a,className:"w-full",children:"Disconnect"})]}):r.jsx(r.Fragment,{children:e.hasTokenAuth?r.jsxs(r.Fragment,{children:[!n&&r.jsx("div",{className:"mt-3",children:r.jsxs(ue,{variant:"secondary",size:"sm",onClick:()=>o(!0),className:"w-full",children:["Connect ",e.name]})}),n&&r.jsx(dx,{platform:e,onConnect:c})]}):r.jsx(ux,{})})]})}function mx({compact:e=!1,onStatusChange:t}){const[s,i]=d.useState({vercel:{connected:!1},netlify:{connected:!1},github:{connected:!1}}),[n,o]=d.useState(!0),[a,l]=d.useState(null),h=d.useCallback(async()=>{try{const p=await K.getDeployStatus();i(p),t==null||t(p),l(null)}catch(p){l(p instanceof Error?p.message:"Failed to fetch connection status")}finally{o(!1)}},[t]);d.useEffect(()=>{h();const p=setInterval(h,3e4);return()=>clearInterval(p)},[h]);const c=d.useCallback(async p=>{const _=await K.connectVercel(p);_.success&&(i(v=>({...v,vercel:{connected:!0,user:_.user}})),t==null||t({...s,vercel:{connected:!0,user:_.user}}))},[s,t]),u=d.useCallback(async p=>{const _=await K.connectNetlify(p);_.success&&(i(v=>({...v,netlify:{connected:!0,user:_.user}})),t==null||t({...s,netlify:{connected:!0,user:_.user}}))},[s,t]),m=d.useCallback(async p=>{await K.disconnectPlatform(p),i(v=>({...v,[p]:{connected:!1}}));const _={...s,[p]:{connected:!1}};t==null||t(_)},[s,t]),f={vercel:c,netlify:u,github:async()=>{}};if(n)return r.jsxs("div",{className:"flex items-center justify-center py-8",children:[r.jsx(di,{size:20,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-sm text-muted ml-2",children:"Loading connections..."})]});const g=[s.vercel,s.netlify,s.github].filter(p=>p.connected).length;return r.jsxs("div",{className:e?"space-y-3":"space-y-4",children:[!e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-semibold text-ink",children:"Platform Connections"}),r.jsxs("p",{className:"text-[11px] text-muted mt-0.5",children:[g," of ",Vr.length," platforms connected"]})]}),r.jsx("button",{onClick:h,className:"p-1.5 text-muted hover:text-ink rounded transition-colors",title:"Refresh connection status",children:r.jsx(Ct,{size:14})})]}),e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("div",{className:"flex items-center gap-3",children:Vr.map(p=>{const _=s[p.id];return r.jsxs("div",{className:"flex items-center gap-1.5",title:`${p.name}: ${_.connected?`Connected as ${_.user}`:"Not connected"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${_.connected?"bg-green-500":"bg-gray-300"}`}),r.jsx("span",{className:"text-[11px] text-muted",children:p.name})]},p.id)})}),r.jsx("button",{onClick:h,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(Ct,{size:12})})]}),a&&r.jsxs("div",{className:"flex items-center gap-2 bg-red-500/5 border border-red-500/15 rounded-lg px-3 py-2",children:[r.jsx(Ds,{size:14,className:"text-red-500 flex-shrink-0"}),r.jsx("span",{className:"text-xs text-red-600",children:a})]}),r.jsx("div",{className:e?"space-y-2":"space-y-3",children:Vr.map(p=>r.jsx(fx,{platform:p,status:s[p.id],onConnect:f[p.id],onDisconnect:()=>m(p.id)},p.id))})]})}const px=[{id:"vercel",name:"Vercel",description:"Optimized for Next.js, React, and static sites. Global CDN with instant rollbacks.",icon:en,color:"text-ink",bgColor:"bg-ink/5",connectionKey:"vercel"},{id:"netlify",name:"Netlify",description:"Deploy with CI/CD, serverless functions, and form handling built in.",icon:en,color:"text-teal-600",bgColor:"bg-teal-500/5",connectionKey:"netlify"},{id:"github-pages",name:"GitHub Pages",description:"Free hosting for static sites directly from a GitHub repository.",icon:ze,color:"text-purple-600",bgColor:"bg-purple-500/5",connectionKey:"github"}];function _x({platform:e,deployState:t,onDeploy:s,disabled:i,connected:n}){const[o,a]=d.useState(!1),l=e.icon,h=d.useCallback(async()=>{if(t.url)try{await navigator.clipboard.writeText(t.url),a(!0),setTimeout(()=>a(!1),2e3)}catch{}},[t.url]),c=i||!n;return r.jsxs("div",{className:`border border-border rounded-lg p-4 transition-colors ${t.status==="success"?"border-green-500/30 bg-green-500/5":t.status==="error"?"border-red-500/30 bg-red-500/5":n?"hover:border-primary/30 hover:bg-hover":"opacity-60"}`,children:[r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${e.bgColor}`,children:r.jsx(l,{size:20,className:e.color})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:e.name}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:e.description})]}),r.jsx("span",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${n?"bg-green-500":"bg-gray-300"}`,title:n?"Connected":"Not connected"})]}),t.status==="idle"&&r.jsxs("div",{className:"relative group",children:[r.jsxs(ue,{variant:"secondary",size:"sm",icon:$t,onClick:s,disabled:c,className:"w-full",children:["Deploy to ",e.name]}),!n&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:r.jsxs("span",{className:"bg-ink text-white text-[10px] px-2 py-1 rounded shadow opacity-0 group-hover:opacity-100 transition-opacity",children:["Connect ",e.name," first"]})})]}),t.status==="deploying"&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-primary/5 border border-primary/20",children:[r.jsx(di,{size:14,className:"text-primary animate-spin"}),r.jsxs("span",{className:"text-xs font-medium text-primary",children:["Deploying to ",e.name,"..."]})]}),t.status==="success"&&t.url&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Deployed successfully"]}),r.jsxs("div",{className:"flex items-center gap-1.5 bg-card border border-border rounded-btn px-3 py-2",children:[r.jsx(en,{size:12,className:"text-muted flex-shrink-0"}),r.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-primary hover:underline truncate flex-1",children:t.url}),r.jsxs("button",{onClick:h,className:"flex items-center gap-1 text-[11px] text-muted hover:text-ink transition-colors flex-shrink-0",title:"Copy URL",children:[o?r.jsx(Ut,{size:12,className:"text-green-500"}):r.jsx(Zn,{size:12}),o?"Copied":"Copy"]}),r.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted hover:text-ink transition-colors flex-shrink-0",title:"Open in new tab",children:r.jsx(ss,{size:12})})]})]}),t.status==="error"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 font-medium",children:[r.jsx(Ds,{size:14}),"Deploy failed"]}),r.jsx("p",{className:"text-[11px] text-muted bg-red-500/5 border border-red-500/10 rounded px-2 py-1.5 font-mono",children:t.error||"Unknown error"}),r.jsx(ue,{variant:"secondary",size:"sm",icon:$t,onClick:s,disabled:c,className:"w-full",children:"Retry"})]})]})}function gx({sessionId:e,disabled:t}){const[s,i]=d.useState({status:"idle"}),[n,o]=d.useState(!1),a=d.useCallback(async()=>{i({status:"pushing"});try{const h=await K.githubPush(e);h.repo_url?i({status:"success",repoUrl:h.repo_url}):i({status:"error",error:h.error||"Push failed"})}catch(h){i({status:"error",error:h instanceof Error?h.message:"Push failed"})}},[e]),l=d.useCallback(async()=>{if(s.repoUrl)try{await navigator.clipboard.writeText(s.repoUrl),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},[s.repoUrl]);return r.jsxs("div",{className:"border border-border rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center bg-ink/5",children:r.jsx(ze,{size:20,className:"text-ink"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:"Push to GitHub"}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:"Create a repository and push your code to GitHub."})]})]}),s.status==="idle"&&r.jsx(ue,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Create Repo + Push"}),s.status==="pushing"&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-primary/5 border border-primary/20",children:[r.jsx(di,{size:14,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-xs font-medium text-primary",children:"Creating repository and pushing..."})]}),s.status==="success"&&s.repoUrl&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Pushed to GitHub"]}),r.jsxs("div",{className:"flex items-center gap-1.5 bg-card border border-border rounded-btn px-3 py-2",children:[r.jsx(ze,{size:12,className:"text-muted flex-shrink-0"}),r.jsx("a",{href:s.repoUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-primary hover:underline truncate flex-1",children:s.repoUrl}),r.jsxs("button",{onClick:l,className:"flex items-center gap-1 text-[11px] text-muted hover:text-ink transition-colors flex-shrink-0",title:"Copy URL",children:[n?r.jsx(Ut,{size:12,className:"text-green-500"}):r.jsx(Zn,{size:12}),n?"Copied":"Copy"]})]})]}),s.status==="error"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 font-medium",children:[r.jsx(Ds,{size:14}),"Push failed"]}),r.jsx("p",{className:"text-[11px] text-muted bg-red-500/5 border border-red-500/10 rounded px-2 py-1.5 font-mono",children:s.error}),r.jsx(ue,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Retry"})]})]})}function xx({sessionId:e}){const[t,s]=d.useState({vercel:{status:"idle"},netlify:{status:"idle"},"github-pages":{status:"idle"}}),[i,n]=d.useState({vercel:{connected:!1},netlify:{connected:!1},github:{connected:!1}}),[o,a]=d.useState(!1),l=Object.values(t).some(u=>u.status==="deploying"),h=d.useCallback(async u=>{s(m=>({...m,[u]:{status:"deploying"}}));try{const m=await K.deployProject(e,u);m.url?s(f=>({...f,[u]:{status:"success",url:m.url}})):s(f=>({...f,[u]:{status:"error",error:m.error||"Deploy failed"}}))}catch(m){s(f=>({...f,[u]:{status:"error",error:m instanceof Error?m.message:"Deploy failed"}}))}},[e]),c=u=>{var m;return((m=i[u.connectionKey])==null?void 0:m.connected)??!1};return r.jsx("div",{className:"h-full overflow-y-auto terminal-scroll",children:r.jsxs("div",{className:"p-6 max-w-2xl mx-auto space-y-6",children:[r.jsxs("div",{children:[r.jsxs("h3",{className:"text-lg font-heading font-bold text-ink flex items-center gap-2",children:[r.jsx($t,{size:20,className:"text-primary"}),"Deploy Your Project"]}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Choose a platform to deploy your project. One click to go live."})]}),r.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[r.jsxs("button",{type:"button",onClick:()=>a(!o),className:"flex items-center justify-between w-full px-4 py-3 text-left hover:bg-hover transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(rc,{size:16,className:"text-primary"}),r.jsx("span",{className:"text-sm font-medium text-ink",children:"Platform Connections"}),r.jsx("div",{className:"flex items-center gap-1 ml-2",children:["vercel","netlify","github"].map(u=>{var m,f;return r.jsx("span",{className:`w-2 h-2 rounded-full ${(m=i[u])!=null&&m.connected?"bg-green-500":"bg-gray-300"}`,title:`${u}: ${(f=i[u])!=null&&f.connected?"Connected":"Not connected"}`},u)})})]}),r.jsx("span",{className:"text-xs text-muted",children:o?"Hide":"Manage"})]}),o&&r.jsx("div",{className:"border-t border-border p-4",children:r.jsx(mx,{compact:!0,onStatusChange:n})})]}),r.jsx("div",{className:"space-y-3",children:px.map(u=>r.jsx(_x,{platform:u,deployState:t[u.id],onDeploy:()=>h(u.id),disabled:l,connected:c(u)},u.id))}),r.jsx("div",{className:"border-t border-border"}),r.jsx(gx,{sessionId:e,disabled:l})]})})}const bh=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),St=bh?"Cmd":"Ctrl",Rl=[{keys:[`${St}+K`],label:"Open Command Palette",category:"navigation"},{keys:[`${St}+P`],label:"Quick open file",category:"navigation"},{keys:[`${St}+,`],label:"Open settings",category:"navigation"},{keys:[`${St}+S`],label:"Save file",category:"editor"},{keys:[`${St}+Z`],label:"Undo",category:"editor"},{keys:[`${St}+Shift+Z`],label:"Redo",category:"editor"},{keys:[`${St}+B`],label:"Start / stop build",category:"build"},{keys:[`${St}+\``],label:"Toggle terminal",category:"build"},{keys:["?"],label:"Show keyboard shortcuts",category:"general"},{keys:[`${St}+?`],label:"Show keyboard shortcuts (alt)",category:"general"},{keys:["Escape"],label:"Close modals",category:"general"}],vx={navigation:"Navigation",editor:"Editor",build:"Build",general:"General"},bx=["navigation","editor","build","general"];function yx({onToggleTerminal:e,onToggleBuild:t}){const[s,i]=d.useState(!1),n=d.useCallback(o=>{var c,u;const a=bh?o.metaKey:o.ctrlKey,l=(c=o.target)==null?void 0:c.tagName,h=l==="INPUT"||l==="TEXTAREA"||((u=o.target)==null?void 0:u.isContentEditable);if(a&&(o.key==="?"||o.shiftKey&&o.key==="/")){o.preventDefault(),i(m=>!m);return}if(o.key==="?"&&!a&&!h){o.preventDefault(),i(m=>!m);return}if(a&&o.key==="`"){o.preventDefault(),e==null||e();return}if(a&&o.key==="b"){o.preventDefault(),t==null||t();return}o.key==="Escape"&&s&&i(!1)},[e,t,s]);return d.useEffect(()=>(window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)),[n]),{showHelp:s,setShowHelp:i}}function Sx({open:e,onClose:t}){const[s,i]=d.useState("");d.useEffect(()=>{e&&i("")},[e]);const n=d.useMemo(()=>{if(!s.trim())return Rl;const a=s.toLowerCase();return Rl.filter(l=>l.label.toLowerCase().includes(a)||l.keys.some(h=>h.toLowerCase().includes(a))||l.category.toLowerCase().includes(a))},[s]),o=d.useMemo(()=>{const a={};for(const l of n)a[l.category]||(a[l.category]=[]),a[l.category].push(l);return a},[n]);return e?r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/20",onClick:t,children:r.jsxs("div",{className:"bg-card rounded-xl shadow-2xl border border-border w-full max-w-md mx-4 overflow-hidden",onClick:a=>a.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(_d,{size:16,className:"text-primary"}),r.jsx("h2",{className:"text-sm font-heading font-bold text-ink",children:"Keyboard Shortcuts"})]}),r.jsx("button",{onClick:t,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",children:r.jsx(ft,{size:16})})]}),r.jsx("div",{className:"px-4 py-2 border-b border-border",children:r.jsxs("div",{className:"relative",children:[r.jsx(ts,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted"}),r.jsx("input",{type:"text",value:s,onChange:a=>i(a.target.value),placeholder:"Filter shortcuts...",className:"w-full pl-9 pr-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors",autoFocus:!0})]})}),r.jsxs("div",{className:"max-h-[400px] overflow-y-auto terminal-scroll",children:[bx.map(a=>{const l=o[a];return!l||l.length===0?null:r.jsxs("div",{children:[r.jsx("div",{className:"px-5 pt-3 pb-1",children:r.jsx("span",{className:"text-[10px] font-semibold text-muted uppercase tracking-wider",children:vx[a]})}),r.jsx("div",{className:"px-4 space-y-0.5 pb-2",children:l.map(h=>r.jsxs("div",{className:"flex items-center justify-between px-2 py-2 rounded-btn hover:bg-hover",children:[r.jsx("span",{className:"text-xs text-ink",children:h.label}),r.jsx("div",{className:"flex items-center gap-1",children:h.keys.map(c=>r.jsx("kbd",{className:"px-2 py-0.5 text-[11px] font-mono bg-hover border border-border rounded text-muted-accessible",children:c},c))})]},h.label))})]},a)}),n.length===0&&r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-xs text-muted",children:['No shortcuts matching "',s,'"']})})]}),r.jsx("div",{className:"px-5 py-3 border-t border-border text-center",children:r.jsxs("span",{className:"text-[11px] text-muted",children:["Press ",r.jsx("kbd",{className:"px-1.5 py-0.5 text-[10px] font-mono bg-hover border border-border rounded",children:"Escape"})," to close"]})})]})}):null}function wx({onClick:e}){return r.jsx("button",{onClick:e,title:"Keyboard shortcuts",className:"inline-flex items-center justify-center w-7 h-7 rounded-btn text-muted hover:text-ink hover:bg-hover transition-colors text-xs font-bold",children:"?"})}const yh="pl_recent_commands",Cx=5;function Sh(){try{const e=localStorage.getItem(yh);return e?JSON.parse(e):[]}catch{return[]}}function Gr(e){try{const t=Sh().filter(s=>s!==e);t.unshift(e),localStorage.setItem(yh,JSON.stringify(t.slice(0,Cx)))}catch{}}function kx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:Z,ts:Z,tsx:Z,jsx:Z,py:Z,go:Z,rs:Z,rb:Z,sh:Z,html:sc,css:to,json:eo,md:cr}[t]||so}function Nx(e,t){const s=e.toLowerCase(),i=t.toLowerCase(),n=[];let o=0;for(let a=0;a<i.length&&o<s.length;a++)i[a]===s[o]&&(n.push(a),o++);return o===s.length?n:null}function Dl({text:e,indices:t}){if(t.length===0)return r.jsx(r.Fragment,{children:e});const s=new Set(t);return r.jsx(r.Fragment,{children:e.split("").map((i,n)=>s.has(n)?r.jsx("span",{className:"text-primary font-semibold",children:i},n):r.jsx("span",{children:i},n))})}function jx({isOpen:e,onClose:t,commands:s,sessionId:i,onFileSelect:n}){const[o,a]=d.useState(""),[l,h]=d.useState(0),[c,u]=d.useState([]),[m,f]=d.useState(!1),g=d.useRef(null),p=d.useRef(null),_=gd(e);xd(e,t),d.useEffect(()=>{e&&(a(""),h(0),u([]),f(!1),setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},50))},[e]);const v=d.useMemo(()=>Sh().map(j=>s.find(C=>C.id===j)).filter(Boolean),[s]),y=d.useMemo(()=>{if(!o.trim())return s.map(j=>({cmd:j,indices:[]}));const S=[];for(const j of s){const C=Nx(o,j.label);if(C){const B=C[0]*10+(C[C.length-1]-C[0]);S.push({cmd:j,indices:C,score:B})}}return S.sort((j,C)=>j.score-C.score),S.map(j=>({cmd:j.cmd,indices:j.indices}))},[s,o]),x=d.useMemo(()=>o.trim()?y.filter(S=>S.cmd.category==="setting"):[],[y,o]),k=d.useMemo(()=>y.filter(S=>S.cmd.category!=="setting"),[y]);d.useEffect(()=>{if(!i||!o.trim()){u([]),f(!1);return}return f(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(async()=>{try{const S=await K.searchFiles(i,o);u(S.filter(j=>j.type==="file"))}catch{u([])}f(!1)},200),()=>{p.current&&clearTimeout(p.current)}},[o,i]);const N=!o.trim()&&v.length>0,w=d.useMemo(()=>{const S=[];return N&&v.forEach((j,C)=>S.push({type:"recent",index:C})),k.forEach((j,C)=>S.push({type:"command",index:C})),x.length>0&&x.forEach((j,C)=>S.push({type:"setting",index:C})),c.forEach((j,C)=>S.push({type:"file",index:C})),S},[N,v,k,x,c]),R=w.length;d.useEffect(()=>{h(0)},[o]);const T=d.useCallback(S=>{const j=w[S];if(j){if(j.type==="recent"){const C=v[j.index];C&&(Gr(C.id),C.action(),t())}else if(j.type==="command"){const C=k[j.index];C&&(Gr(C.cmd.id),C.cmd.action(),t())}else if(j.type==="setting"){const C=x[j.index];C&&(Gr(C.cmd.id),C.cmd.action(),t())}else if(j.type==="file"){const C=c[j.index];C&&n&&(n(C.path,C.name),t())}}},[w,v,k,x,c,n,t]),W=d.useCallback(S=>{S.key==="ArrowDown"?(S.preventDefault(),h(j=>Math.min(j+1,R-1))):S.key==="ArrowUp"?(S.preventDefault(),h(j=>Math.max(j-1,0))):S.key==="Enter"&&R>0?T(l):S.key==="Escape"&&t()},[R,l,T,t]);if(!e)return null;let G=0;const U=()=>G++,A=k.length>0,M=x.length>0,E=c.length>0,L=m&&o.trim().length>0;return r.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[20vh]",onClick:t,children:[r.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm"}),r.jsxs("div",{ref:_,className:"relative w-full max-w-lg bg-card rounded-xl shadow-2xl border border-border overflow-hidden",onClick:S=>S.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border",children:[r.jsx(ts,{size:18,className:"text-muted"}),r.jsx("input",{ref:g,value:o,onChange:S=>a(S.target.value),onKeyDown:W,placeholder:"Search commands, files, settings...",className:"flex-1 bg-transparent text-sm outline-none text-ink placeholder:text-muted"}),r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:"ESC"})]}),r.jsxs("div",{className:"max-h-[360px] overflow-y-auto py-1 terminal-scroll",children:[N&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider flex items-center gap-1.5",children:[r.jsx(nt,{size:10})," Recent"]}),v.map((S,j)=>{const C=U(),B=S.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:S.label}),S.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.shortcut})]},`recent-${S.id}`)})]}),A&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider",children:"Commands"}),k.map((S,j)=>{const C=U(),B=S.cmd.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:o.trim()?r.jsx(Dl,{text:S.cmd.label,indices:S.indices}):S.cmd.label}),S.cmd.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.cmd.shortcut})]},S.cmd.id)})]}),M&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider mt-1",children:"Settings"}),x.map((S,j)=>{const C=U(),B=S.cmd.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:r.jsx(Dl,{text:S.cmd.label,indices:S.indices})}),S.cmd.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.cmd.shortcut})]},`setting-${S.cmd.id}`)})]}),E&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider mt-1",children:"Files"}),c.map((S,j)=>{const C=U(),B=S.type==="directory"?io:kx(S.name);return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:14}),r.jsx("span",{className:"flex-1 text-left font-mono text-xs truncate",children:S.name}),r.jsx("span",{className:"text-[10px] text-muted truncate max-w-[200px]",children:S.path})]},`file-${S.path}`)})]}),L&&!E&&r.jsx("div",{className:"px-4 py-2 text-xs text-muted animate-pulse",children:"Searching files..."}),R===0&&!L&&r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted",children:"No results found"})]})]})]})}const Ex=d.lazy(()=>Xn(()=>import("./GitHubIssuesPanel-TLudouS-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])).then(e=>({default:e.GitHubIssuesPanel}))),Rx=d.lazy(()=>Xn(()=>import("./GitHubPRsPanel-bjj0yQTk.js"),__vite__mapDeps([31,1,2,3,32,4,5,33,12,14,17,9,10,11,13,15,16,8,18,19,20,21,22,23,24,7,25,26,27,28,29,30])).then(e=>({default:e.GitHubPRsPanel}))),Dx=d.lazy(()=>Xn(()=>Promise.resolve().then(()=>Gx),void 0).then(e=>({default:e.CICDPanel}))),Px=3e4,Mx={modified:r.jsx(Z,{size:13,className:"text-yellow-500"}),added:r.jsx(dr,{size:13,className:"text-green-500"}),deleted:r.jsx(Qn,{size:13,className:"text-red-400"}),renamed:r.jsx(Z,{size:13,className:"text-blue-400"}),untracked:r.jsx(ic,{size:13,className:"text-muted"})},Lx={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?"};function Bx({commit:e}){return r.jsx("div",{className:"px-3 py-2 border-b border-border hover:bg-hover transition-colors",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Zl,{size:14,className:"text-primary mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-xs font-medium text-ink truncate",children:e.message}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[11px] font-mono text-primary/70",children:e.short_hash}),r.jsx("span",{className:"text-[11px] text-muted",children:e.author}),r.jsx("span",{className:"text-[11px] text-muted ml-auto flex-shrink-0",children:e.date})]}),e.refs.length>0&&r.jsx("div",{className:"flex gap-1 mt-1",children:e.refs.map((t,s)=>r.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-mono bg-primary/10 text-primary rounded",children:[r.jsx(ze,{size:9}),t]},s))})]})]})})}function Pl({file:e}){return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-hover transition-colors text-xs",children:[Mx[e.status]||r.jsx(ic,{size:13}),r.jsx("span",{className:"font-mono text-ink truncate flex-1",children:e.path}),r.jsx("span",{className:`font-mono text-[10px] px-1 rounded ${e.staged?"bg-green-500/10 text-green-500":"bg-muted/10 text-muted"}`,children:Lx[e.status]||"?"})]})}function Tx({sessionId:e}){const[t,s]=d.useState("changes"),[i,n]=d.useState(null),[o,a]=d.useState([]),[l,h]=d.useState([]),[c,u]=d.useState(!0),[m,f]=d.useState(null),[g,p]=d.useState(""),[_,v]=d.useState(!1),[y,x]=d.useState(null),[k,N]=d.useState(!1),[w,R]=d.useState(""),[T,W]=d.useState(!1),[G,U]=d.useState(!1),[A,M]=d.useState(""),[E,L]=d.useState(""),[S,j]=d.useState(!1),[C,B]=d.useState(null),[X,ae]=d.useState(!1),q=d.useCallback(async()=>{u(!0),f(null);try{const[D,le,ge]=await Promise.all([K.git.status(e),K.git.log(e),K.git.branches(e)]);n(D),a(le),h(ge)}catch(D){f(D instanceof Error?D.message:"Failed to load git data")}u(!1)},[e]);d.useEffect(()=>{q()},[q]);const Q=async()=>{if(!(!g.trim()||_)){v(!0),x(null);try{const D=await K.git.commit(e,g.trim());x(`Committed: ${D.hash}`),p(""),await q()}catch(D){x(`Error: ${D instanceof Error?D.message:"Commit failed"}`)}v(!1)}},ie=async()=>{if(!(!w.trim()||T)){W(!0);try{await K.git.createBranch(e,w.trim()),R(""),N(!1),await q()}catch(D){f(D instanceof Error?D.message:"Branch creation failed")}W(!1)}},he=async D=>{try{await K.git.checkoutBranch(e,D),await q()}catch(le){f(le instanceof Error?le.message:"Checkout failed")}},de=async()=>{ae(!0);try{await K.git.push(e),await q()}catch(D){f(D instanceof Error?D.message:"Push failed")}ae(!1)},z=async()=>{if(!(!A.trim()||S)){j(!0),B(null);try{const D=await K.git.pr(e,A.trim(),E.trim());B(D.url),M(""),L(""),U(!1)}catch(D){B(`Error: ${D instanceof Error?D.message:"PR creation failed"}`)}j(!1)}},V=(i==null?void 0:i.files.filter(D=>D.staged))||[],J=(i==null?void 0:i.files.filter(D=>!D.staged))||[];return c&&!i?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading git status..."})]})}):m&&!i?r.jsx("div",{className:"h-full flex items-center justify-center p-6",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx(Ds,{size:32,className:"text-muted/40"}),r.jsx("p",{className:"text-sm text-muted",children:m}),r.jsx("p",{className:"text-xs text-muted/60",children:"This project may not be a git repository."}),r.jsx(ue,{size:"sm",variant:"secondary",icon:Ct,onClick:q,children:"Retry"})]})}):r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-hover flex-shrink-0",children:[r.jsx(ze,{size:14,className:"text-primary"}),r.jsx("span",{className:"text-xs font-semibold text-ink",children:(i==null?void 0:i.branch)||"unknown"}),i&&(i.ahead>0||i.behind>0)&&r.jsxs("span",{className:"text-[10px] text-muted font-mono",children:[i.ahead>0&&`+${i.ahead}`,i.ahead>0&&i.behind>0&&" / ",i.behind>0&&`-${i.behind}`]}),(i==null?void 0:i.clean)&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-green-500",children:[r.jsx(Ut,{size:10})," Clean"]}),r.jsx("div",{className:"flex-1"}),r.jsx("button",{onClick:q,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(Ct,{size:13,className:c?"animate-spin":""})})]}),r.jsx("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border flex-shrink-0",children:[{id:"changes",label:"Changes",icon:Z,count:(i==null?void 0:i.files.length)||0},{id:"history",label:"History",icon:nt},{id:"branches",label:"Branches",icon:ze,count:l.length}].map(D=>r.jsxs("button",{onClick:()=>s(D.id),className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===D.id?"bg-primary/10 text-primary":"text-muted hover:text-ink"}`,children:[r.jsx(D.icon,{size:12}),D.label,D.count!==void 0&&D.count>0&&r.jsx("span",{className:"ml-0.5 px-1 py-0 text-[9px] rounded-full bg-primary/20 text-primary font-mono",children:D.count})]},D.id))}),m&&r.jsx("div",{className:"px-3 py-2 bg-red-500/5 border-b border-red-500/20 text-xs text-red-400",children:m}),r.jsxs("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:[t==="changes"&&r.jsx("div",{className:"flex flex-col h-full",children:(i==null?void 0:i.files.length)===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(Ut,{size:28,className:"text-green-500/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"Working tree clean"}),r.jsx("p",{className:"text-[11px] text-muted/60 mt-0.5",children:"No changes to commit."})]}):r.jsxs(r.Fragment,{children:[V.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-green-500/5 border-b border-border",children:["Staged (",V.length,")"]}),V.map((D,le)=>r.jsx(Pl,{file:D},`s-${le}`))]}),J.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-yellow-500/5 border-b border-border",children:["Unstaged (",J.length,")"]}),J.map((D,le)=>r.jsx(Pl,{file:D},`u-${le}`))]}),r.jsxs("div",{className:"mt-auto border-t border-border p-3 space-y-2 flex-shrink-0",children:[r.jsx("textarea",{value:g,onChange:D=>p(D.target.value),placeholder:"Commit message...",rows:2,className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors resize-none font-mono"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ue,{size:"sm",icon:Zl,onClick:Q,disabled:!g.trim()||_,loading:_,children:"Commit"}),r.jsx(ue,{size:"sm",variant:"secondary",icon:ac,onClick:de,loading:X,disabled:X,children:"Push"}),r.jsx(ue,{size:"sm",variant:"ghost",icon:sn,onClick:()=>U(!G),children:"PR"})]}),y&&r.jsx("p",{className:`text-[11px] font-mono ${y.startsWith("Error")?"text-red-400":"text-green-500"}`,children:y}),C&&r.jsx("p",{className:"text-[11px] font-mono text-primary",children:C.startsWith("Error")?r.jsx("span",{className:"text-red-400",children:C}):r.jsx("a",{href:C,target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-primary/80",children:C})})]}),G&&r.jsxs("div",{className:"border-t border-border p-3 space-y-2 flex-shrink-0 bg-hover",children:[r.jsx("p",{className:"text-[11px] font-semibold text-ink",children:"Create Pull Request"}),r.jsx("input",{value:A,onChange:D=>M(D.target.value),placeholder:"PR title...",className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary"}),r.jsx("textarea",{value:E,onChange:D=>L(D.target.value),placeholder:"PR description (optional)...",rows:3,className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary resize-none"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(ue,{size:"sm",icon:sn,onClick:z,disabled:!A.trim()||S,loading:S,children:"Create PR"}),r.jsx(ue,{size:"sm",variant:"ghost",onClick:()=>U(!1),children:"Cancel"})]})]})]})}),t==="history"&&r.jsx("div",{children:o.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(nt,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No commits yet"})]}):o.map((D,le)=>r.jsx(Bx,{commit:D},le))}),t==="branches"&&r.jsxs("div",{children:[r.jsx("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:r.jsxs("button",{onClick:()=>N(!k),className:"flex items-center gap-1 text-xs text-primary hover:text-primary/80 font-medium",children:[r.jsx(ur,{size:12}),"New Branch"]})}),k&&r.jsxs("div",{className:"px-3 py-2 border-b border-border bg-hover flex items-center gap-2",children:[r.jsx("input",{value:w,onChange:D=>R(D.target.value),placeholder:"branch-name",className:"flex-1 px-2 py-1 text-xs font-mono bg-card border border-border rounded-btn outline-none focus:border-primary",onKeyDown:D=>{D.key==="Enter"&&ie()}}),r.jsx(ue,{size:"sm",onClick:ie,disabled:!w.trim()||T,loading:T,children:"Create"})]}),l.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(ze,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No branches found"})]}):r.jsxs("div",{children:[l.filter(D=>!D.remote).map((D,le)=>r.jsxs("button",{onClick:()=>!D.current&&he(D.name),disabled:D.current,className:`w-full text-left flex items-center gap-2 px-3 py-2 text-xs border-b border-border transition-colors ${D.current?"bg-primary/5":"hover:bg-hover cursor-pointer"}`,children:[r.jsx(ze,{size:13,className:D.current?"text-primary":"text-muted"}),r.jsx("span",{className:`font-mono ${D.current?"text-primary font-semibold":"text-ink"}`,children:D.name}),D.current&&r.jsx("span",{className:"ml-auto text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded font-medium",children:"current"})]},`l-${le}`)),l.filter(D=>D.remote).length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-hover border-b border-border",children:"Remote"}),l.filter(D=>D.remote).map((D,le)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs border-b border-border",children:[r.jsx(ze,{size:13,className:"text-muted/60"}),r.jsx("span",{className:"font-mono text-muted",children:D.name})]},`r-${le}`))]})]})]})]})]})}function Yr(){return r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading..."})]})})}function Xr({sessionId:e,onPushed:t}){const[s,i]=d.useState(!1),[n,o]=d.useState(null),a=async()=>{i(!0),o(null);try{await K.githubPush(e),t()}catch(l){o(l instanceof Error?l.message:"Push to GitHub failed")}i(!1)};return r.jsx("div",{className:"h-full flex items-center justify-center p-8",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 text-center max-w-xs",children:[r.jsx(au,{size:40,className:"text-muted/30"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-ink",children:"This project isn't connected to GitHub yet"}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Push your project to GitHub to access issues, pull requests, and CI/CD workflows."})]}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsx(ue,{size:"sm",icon:ac,onClick:a,loading:s,children:"Push to GitHub"})}),n&&r.jsx("p",{className:"text-[11px] text-red-400 font-mono",children:n})]})})}function zx({sessionId:e}){const[t,s]=d.useState("changes"),[i,n]=d.useState(!0),[o,a]=d.useState(null),[l,h]=d.useState({issues:0,prs:0,actions:0,fetchedAt:0}),c=d.useRef(!1),u=d.useCallback(async()=>{n(!0);try{const _=await K.getStatus();a({has_remote:!0,repo:"",owner:""})}catch{a({has_remote:!1})}n(!1)},[e]);d.useEffect(()=>{u()},[u]);const m=d.useCallback(async()=>{if(!(!(o!=null&&o.has_remote)||Date.now()-l.fetchedAt<Px)&&!c.current){c.current=!0;try{const[v,y,x]=await Promise.allSettled([K.getGitHubIssues(e,"open",1),K.getGitHubPRs(e,"open",1),K.getWorkflowRuns(e,5)]);h({issues:v.status==="fulfilled"?v.value.length:0,prs:y.status==="fulfilled"?y.value.length:0,actions:x.status==="fulfilled"?x.value.filter(k=>k.status==="in_progress").length:0,fetchedAt:Date.now()})}catch{}c.current=!1}},[e,o==null?void 0:o.has_remote,l.fetchedAt]);if(d.useEffect(()=>{o!=null&&o.has_remote&&m()},[o==null?void 0:o.has_remote,m]),d.useEffect(()=>{["issues","prs","actions"].includes(t)&&(o!=null&&o.has_remote)&&m()},[t,o==null?void 0:o.has_remote,m]),i)return r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Checking GitHub connection..."})]})});const f=(o==null?void 0:o.has_remote)??!1,g=[{id:"changes",label:"Changes",icon:Z,requiresRemote:!1},{id:"issues",label:"Issues",icon:Gd,count:l.issues,requiresRemote:!0},{id:"prs",label:"PRs",icon:sn,count:l.prs,requiresRemote:!0},{id:"actions",label:"Actions",icon:It,count:l.actions,requiresRemote:!0}],p=g;return r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border bg-hover flex-shrink-0",children:[p.map(_=>{const v=_.requiresRemote&&!f;return r.jsxs("button",{onClick:()=>s(_.id),disabled:v,className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===_.id?"bg-primary/10 text-primary":v?"text-muted/40 cursor-not-allowed":"text-muted hover:text-ink"}`,title:v?"Connect to GitHub to access this tab":void 0,children:[r.jsx(_.icon,{size:12}),_.label,_.count!==void 0&&_.count>0&&r.jsx("span",{className:"ml-0.5 px-1 py-0 text-[9px] rounded-full bg-primary/20 text-primary font-mono",children:_.count})]},_.id)}),f&&(o==null?void 0:o.owner)&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted font-mono",children:[r.jsx(rc,{size:10}),o.owner,"/",o.repo]})]}),r.jsxs("div",{className:"flex-1 overflow-hidden",children:[t==="changes"&&r.jsx(Tx,{sessionId:e}),t==="issues"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx(Ex,{sessionId:e})}):r.jsx(Xr,{sessionId:e,onPushed:u})),t==="prs"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx(Rx,{sessionId:e})}):r.jsx(Xr,{sessionId:e,onPushed:u})),t==="actions"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Dx,{sessionId:e})})}):r.jsx(Xr,{sessionId:e,onPushed:u}))]})]})}function Ax({sessionId:e,onRestore:t}){const[s,i]=d.useState([]),[n,o]=d.useState(!0),[a,l]=d.useState(null),[h,c]=d.useState(null),[u,m]=d.useState(null),f=d.useCallback(async()=>{try{const _=await K.getCheckpoints(e);i(_),m(null)}catch{m("Failed to load checkpoints")}o(!1)},[e]);d.useEffect(()=>{f();const _=setInterval(f,15e3);return()=>clearInterval(_)},[f]);const g=d.useCallback(async _=>{if(a)return;const v=s.find(x=>x.id===_);if(!(!v||!window.confirm(`Restore to checkpoint "${v.description}"?
|
|
255
|
+
placeholder:text-muted disabled:opacity-50`})]}),r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsxs("a",{href:e.tokenUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:[e.tokenUrlLabel,r.jsx(ss,{size:10})]}),r.jsx(ue,{type:"submit",variant:"primary",size:"sm",loading:n,disabled:!s.trim()||n,children:"Connect"})]}),a&&r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 mt-1",children:[r.jsx(Ds,{size:12}),a]})]})}function ux(){return r.jsxs("div",{className:"mt-3 space-y-2",children:[r.jsxs("div",{className:"flex items-start gap-2 bg-amber-500/5 border border-amber-500/15 rounded-lg px-3 py-2.5",children:[r.jsx(es,{size:14,className:"text-amber-600 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs text-muted leading-relaxed",children:[r.jsx("p",{className:"font-medium text-ink mb-1",children:"Run in your terminal:"}),r.jsx("code",{className:"block bg-ink/5 rounded px-2 py-1 font-mono text-[11px] text-ink",children:"gh auth login"})]})]}),r.jsxs("a",{href:"https://cli.github.com/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:["Install GitHub CLI",r.jsx(ss,{size:10})]})]})}function fx({platform:e,status:t,onConnect:s,onDisconnect:i}){const[n,o]=d.useState(!1),[a,l]=d.useState(!1),h=d.useCallback(async()=>{l(!0);try{i()}finally{l(!1)}},[i]),c=d.useCallback(async u=>{await s(u),o(!1)},[s]);return r.jsxs("div",{className:`border rounded-lg p-4 transition-colors ${t.connected?"border-green-500/30 bg-green-500/5":"border-border hover:border-primary/30 hover:bg-hover"}`,children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${e.bgColor}`,children:r.jsx("span",{className:`text-sm font-bold ${e.color}`,children:e.initial})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:e.name}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:e.description})]}),r.jsx("div",{className:"flex-shrink-0",children:r.jsx("span",{className:`inline-block w-2.5 h-2.5 rounded-full ${t.connected?"bg-green-500":"bg-gray-300"}`,title:t.connected?"Connected":"Not connected"})})]}),t.connected?r.jsxs("div",{className:"mt-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Connected as ",t.user||"unknown"]}),t.last_deployed&&r.jsxs("p",{className:"text-[11px] text-muted",children:["Last deployed: ",new Date(t.last_deployed).toLocaleString()]}),r.jsx(ue,{variant:"danger",size:"sm",icon:Fu,onClick:h,loading:a,className:"w-full",children:"Disconnect"})]}):r.jsx(r.Fragment,{children:e.hasTokenAuth?r.jsxs(r.Fragment,{children:[!n&&r.jsx("div",{className:"mt-3",children:r.jsxs(ue,{variant:"secondary",size:"sm",onClick:()=>o(!0),className:"w-full",children:["Connect ",e.name]})}),n&&r.jsx(dx,{platform:e,onConnect:c})]}):r.jsx(ux,{})})]})}function mx({compact:e=!1,onStatusChange:t}){const[s,i]=d.useState({vercel:{connected:!1},netlify:{connected:!1},github:{connected:!1}}),[n,o]=d.useState(!0),[a,l]=d.useState(null),h=d.useCallback(async()=>{try{const p=await K.getDeployStatus();i(p),t==null||t(p),l(null)}catch(p){l(p instanceof Error?p.message:"Failed to fetch connection status")}finally{o(!1)}},[t]);d.useEffect(()=>{h();const p=setInterval(h,3e4);return()=>clearInterval(p)},[h]);const c=d.useCallback(async p=>{const _=await K.connectVercel(p);_.success&&(i(v=>({...v,vercel:{connected:!0,user:_.user}})),t==null||t({...s,vercel:{connected:!0,user:_.user}}))},[s,t]),u=d.useCallback(async p=>{const _=await K.connectNetlify(p);_.success&&(i(v=>({...v,netlify:{connected:!0,user:_.user}})),t==null||t({...s,netlify:{connected:!0,user:_.user}}))},[s,t]),m=d.useCallback(async p=>{await K.disconnectPlatform(p),i(v=>({...v,[p]:{connected:!1}}));const _={...s,[p]:{connected:!1}};t==null||t(_)},[s,t]),f={vercel:c,netlify:u,github:async()=>{}};if(n)return r.jsxs("div",{className:"flex items-center justify-center py-8",children:[r.jsx(di,{size:20,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-sm text-muted ml-2",children:"Loading connections..."})]});const g=[s.vercel,s.netlify,s.github].filter(p=>p.connected).length;return r.jsxs("div",{className:e?"space-y-3":"space-y-4",children:[!e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-semibold text-ink",children:"Platform Connections"}),r.jsxs("p",{className:"text-[11px] text-muted mt-0.5",children:[g," of ",Vr.length," platforms connected"]})]}),r.jsx("button",{onClick:h,className:"p-1.5 text-muted hover:text-ink rounded transition-colors",title:"Refresh connection status",children:r.jsx(Ct,{size:14})})]}),e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("div",{className:"flex items-center gap-3",children:Vr.map(p=>{const _=s[p.id];return r.jsxs("div",{className:"flex items-center gap-1.5",title:`${p.name}: ${_.connected?`Connected as ${_.user}`:"Not connected"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${_.connected?"bg-green-500":"bg-gray-300"}`}),r.jsx("span",{className:"text-[11px] text-muted",children:p.name})]},p.id)})}),r.jsx("button",{onClick:h,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(Ct,{size:12})})]}),a&&r.jsxs("div",{className:"flex items-center gap-2 bg-red-500/5 border border-red-500/15 rounded-lg px-3 py-2",children:[r.jsx(Ds,{size:14,className:"text-red-500 flex-shrink-0"}),r.jsx("span",{className:"text-xs text-red-600",children:a})]}),r.jsx("div",{className:e?"space-y-2":"space-y-3",children:Vr.map(p=>r.jsx(fx,{platform:p,status:s[p.id],onConnect:f[p.id],onDisconnect:()=>m(p.id)},p.id))})]})}const px=[{id:"vercel",name:"Vercel",description:"Optimized for Next.js, React, and static sites. Global CDN with instant rollbacks.",icon:en,color:"text-ink",bgColor:"bg-ink/5",connectionKey:"vercel"},{id:"netlify",name:"Netlify",description:"Deploy with CI/CD, serverless functions, and form handling built in.",icon:en,color:"text-teal-600",bgColor:"bg-teal-500/5",connectionKey:"netlify"},{id:"github-pages",name:"GitHub Pages",description:"Free hosting for static sites directly from a GitHub repository.",icon:ze,color:"text-purple-600",bgColor:"bg-purple-500/5",connectionKey:"github"}];function _x({platform:e,deployState:t,onDeploy:s,disabled:i,connected:n}){const[o,a]=d.useState(!1),l=e.icon,h=d.useCallback(async()=>{if(t.url)try{await navigator.clipboard.writeText(t.url),a(!0),setTimeout(()=>a(!1),2e3)}catch{}},[t.url]),c=i||!n;return r.jsxs("div",{className:`border border-border rounded-lg p-4 transition-colors ${t.status==="success"?"border-green-500/30 bg-green-500/5":t.status==="error"?"border-red-500/30 bg-red-500/5":n?"hover:border-primary/30 hover:bg-hover":"opacity-60"}`,children:[r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${e.bgColor}`,children:r.jsx(l,{size:20,className:e.color})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:e.name}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:e.description})]}),r.jsx("span",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${n?"bg-green-500":"bg-gray-300"}`,title:n?"Connected":"Not connected"})]}),t.status==="idle"&&r.jsxs("div",{className:"relative group",children:[r.jsxs(ue,{variant:"secondary",size:"sm",icon:$t,onClick:s,disabled:c,className:"w-full",children:["Deploy to ",e.name]}),!n&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:r.jsxs("span",{className:"bg-ink text-white text-[10px] px-2 py-1 rounded shadow opacity-0 group-hover:opacity-100 transition-opacity",children:["Connect ",e.name," first"]})})]}),t.status==="deploying"&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-primary/5 border border-primary/20",children:[r.jsx(di,{size:14,className:"text-primary animate-spin"}),r.jsxs("span",{className:"text-xs font-medium text-primary",children:["Deploying to ",e.name,"..."]})]}),t.status==="success"&&t.url&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Deployed successfully"]}),r.jsxs("div",{className:"flex items-center gap-1.5 bg-card border border-border rounded-btn px-3 py-2",children:[r.jsx(en,{size:12,className:"text-muted flex-shrink-0"}),r.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-primary hover:underline truncate flex-1",children:t.url}),r.jsxs("button",{onClick:h,className:"flex items-center gap-1 text-[11px] text-muted hover:text-ink transition-colors flex-shrink-0",title:"Copy URL",children:[o?r.jsx(Ut,{size:12,className:"text-green-500"}):r.jsx(Zn,{size:12}),o?"Copied":"Copy"]}),r.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted hover:text-ink transition-colors flex-shrink-0",title:"Open in new tab",children:r.jsx(ss,{size:12})})]})]}),t.status==="error"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 font-medium",children:[r.jsx(Ds,{size:14}),"Deploy failed"]}),r.jsx("p",{className:"text-[11px] text-muted bg-red-500/5 border border-red-500/10 rounded px-2 py-1.5 font-mono",children:t.error||"Unknown error"}),r.jsx(ue,{variant:"secondary",size:"sm",icon:$t,onClick:s,disabled:c,className:"w-full",children:"Retry"})]})]})}function gx({sessionId:e,disabled:t}){const[s,i]=d.useState({status:"idle"}),[n,o]=d.useState(!1),a=d.useCallback(async()=>{i({status:"pushing"});try{const h=await K.githubPush(e);h.repo_url?i({status:"success",repoUrl:h.repo_url}):i({status:"error",error:h.error||"Push failed"})}catch(h){i({status:"error",error:h instanceof Error?h.message:"Push failed"})}},[e]),l=d.useCallback(async()=>{if(s.repoUrl)try{await navigator.clipboard.writeText(s.repoUrl),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},[s.repoUrl]);return r.jsxs("div",{className:"border border-border rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center bg-ink/5",children:r.jsx(ze,{size:20,className:"text-ink"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h4",{className:"text-sm font-semibold text-ink",children:"Push to GitHub"}),r.jsx("p",{className:"text-[11px] text-muted leading-snug mt-0.5",children:"Create a repository and push your code to GitHub."})]})]}),s.status==="idle"&&r.jsx(ue,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Create Repo + Push"}),s.status==="pushing"&&r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-primary/5 border border-primary/20",children:[r.jsx(di,{size:14,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-xs font-medium text-primary",children:"Creating repository and pushing..."})]}),s.status==="success"&&s.repoUrl&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 font-medium",children:[r.jsx(kt,{size:14}),"Pushed to GitHub"]}),r.jsxs("div",{className:"flex items-center gap-1.5 bg-card border border-border rounded-btn px-3 py-2",children:[r.jsx(ze,{size:12,className:"text-muted flex-shrink-0"}),r.jsx("a",{href:s.repoUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-mono text-primary hover:underline truncate flex-1",children:s.repoUrl}),r.jsxs("button",{onClick:l,className:"flex items-center gap-1 text-[11px] text-muted hover:text-ink transition-colors flex-shrink-0",title:"Copy URL",children:[n?r.jsx(Ut,{size:12,className:"text-green-500"}):r.jsx(Zn,{size:12}),n?"Copied":"Copy"]})]})]}),s.status==="error"&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-red-500 font-medium",children:[r.jsx(Ds,{size:14}),"Push failed"]}),r.jsx("p",{className:"text-[11px] text-muted bg-red-500/5 border border-red-500/10 rounded px-2 py-1.5 font-mono",children:s.error}),r.jsx(ue,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Retry"})]})]})}function xx({sessionId:e}){const[t,s]=d.useState({vercel:{status:"idle"},netlify:{status:"idle"},"github-pages":{status:"idle"}}),[i,n]=d.useState({vercel:{connected:!1},netlify:{connected:!1},github:{connected:!1}}),[o,a]=d.useState(!1),l=Object.values(t).some(u=>u.status==="deploying"),h=d.useCallback(async u=>{s(m=>({...m,[u]:{status:"deploying"}}));try{const m=await K.deployProject(e,u);m.url?s(f=>({...f,[u]:{status:"success",url:m.url}})):s(f=>({...f,[u]:{status:"error",error:m.error||"Deploy failed"}}))}catch(m){s(f=>({...f,[u]:{status:"error",error:m instanceof Error?m.message:"Deploy failed"}}))}},[e]),c=u=>{var m;return((m=i[u.connectionKey])==null?void 0:m.connected)??!1};return r.jsx("div",{className:"h-full overflow-y-auto terminal-scroll",children:r.jsxs("div",{className:"p-6 max-w-2xl mx-auto space-y-6",children:[r.jsxs("div",{children:[r.jsxs("h3",{className:"text-lg font-heading font-bold text-ink flex items-center gap-2",children:[r.jsx($t,{size:20,className:"text-primary"}),"Deploy Your Project"]}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Choose a platform to deploy your project. One click to go live."})]}),r.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[r.jsxs("button",{type:"button",onClick:()=>a(!o),className:"flex items-center justify-between w-full px-4 py-3 text-left hover:bg-hover transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(rc,{size:16,className:"text-primary"}),r.jsx("span",{className:"text-sm font-medium text-ink",children:"Platform Connections"}),r.jsx("div",{className:"flex items-center gap-1 ml-2",children:["vercel","netlify","github"].map(u=>{var m,f;return r.jsx("span",{className:`w-2 h-2 rounded-full ${(m=i[u])!=null&&m.connected?"bg-green-500":"bg-gray-300"}`,title:`${u}: ${(f=i[u])!=null&&f.connected?"Connected":"Not connected"}`},u)})})]}),r.jsx("span",{className:"text-xs text-muted",children:o?"Hide":"Manage"})]}),o&&r.jsx("div",{className:"border-t border-border p-4",children:r.jsx(mx,{compact:!0,onStatusChange:n})})]}),r.jsx("div",{className:"space-y-3",children:px.map(u=>r.jsx(_x,{platform:u,deployState:t[u.id],onDeploy:()=>h(u.id),disabled:l,connected:c(u)},u.id))}),r.jsx("div",{className:"border-t border-border"}),r.jsx(gx,{sessionId:e,disabled:l})]})})}const bh=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),St=bh?"Cmd":"Ctrl",Rl=[{keys:[`${St}+K`],label:"Open Command Palette",category:"navigation"},{keys:[`${St}+P`],label:"Quick open file",category:"navigation"},{keys:[`${St}+,`],label:"Open settings",category:"navigation"},{keys:[`${St}+S`],label:"Save file",category:"editor"},{keys:[`${St}+Z`],label:"Undo",category:"editor"},{keys:[`${St}+Shift+Z`],label:"Redo",category:"editor"},{keys:[`${St}+B`],label:"Start / stop build",category:"build"},{keys:[`${St}+\``],label:"Toggle terminal",category:"build"},{keys:["?"],label:"Show keyboard shortcuts",category:"general"},{keys:[`${St}+?`],label:"Show keyboard shortcuts (alt)",category:"general"},{keys:["Escape"],label:"Close modals",category:"general"}],vx={navigation:"Navigation",editor:"Editor",build:"Build",general:"General"},bx=["navigation","editor","build","general"];function yx({onToggleTerminal:e,onToggleBuild:t}){const[s,i]=d.useState(!1),n=d.useCallback(o=>{var c,u;const a=bh?o.metaKey:o.ctrlKey,l=(c=o.target)==null?void 0:c.tagName,h=l==="INPUT"||l==="TEXTAREA"||((u=o.target)==null?void 0:u.isContentEditable);if(a&&(o.key==="?"||o.shiftKey&&o.key==="/")){o.preventDefault(),i(m=>!m);return}if(o.key==="?"&&!a&&!h){o.preventDefault(),i(m=>!m);return}if(a&&o.key==="`"){o.preventDefault(),e==null||e();return}if(a&&o.key==="b"){o.preventDefault(),t==null||t();return}o.key==="Escape"&&s&&i(!1)},[e,t,s]);return d.useEffect(()=>(window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)),[n]),{showHelp:s,setShowHelp:i}}function Sx({open:e,onClose:t}){const[s,i]=d.useState("");d.useEffect(()=>{e&&i("")},[e]);const n=d.useMemo(()=>{if(!s.trim())return Rl;const a=s.toLowerCase();return Rl.filter(l=>l.label.toLowerCase().includes(a)||l.keys.some(h=>h.toLowerCase().includes(a))||l.category.toLowerCase().includes(a))},[s]),o=d.useMemo(()=>{const a={};for(const l of n)a[l.category]||(a[l.category]=[]),a[l.category].push(l);return a},[n]);return e?r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/20",onClick:t,children:r.jsxs("div",{className:"bg-card rounded-xl shadow-2xl border border-border w-full max-w-md mx-4 overflow-hidden",onClick:a=>a.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(_d,{size:16,className:"text-primary"}),r.jsx("h2",{className:"text-sm font-heading font-bold text-ink",children:"Keyboard Shortcuts"})]}),r.jsx("button",{onClick:t,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",children:r.jsx(ft,{size:16})})]}),r.jsx("div",{className:"px-4 py-2 border-b border-border",children:r.jsxs("div",{className:"relative",children:[r.jsx(ts,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted"}),r.jsx("input",{type:"text",value:s,onChange:a=>i(a.target.value),placeholder:"Filter shortcuts...",className:"w-full pl-9 pr-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors",autoFocus:!0})]})}),r.jsxs("div",{className:"max-h-[400px] overflow-y-auto terminal-scroll",children:[bx.map(a=>{const l=o[a];return!l||l.length===0?null:r.jsxs("div",{children:[r.jsx("div",{className:"px-5 pt-3 pb-1",children:r.jsx("span",{className:"text-[10px] font-semibold text-muted uppercase tracking-wider",children:vx[a]})}),r.jsx("div",{className:"px-4 space-y-0.5 pb-2",children:l.map(h=>r.jsxs("div",{className:"flex items-center justify-between px-2 py-2 rounded-btn hover:bg-hover",children:[r.jsx("span",{className:"text-xs text-ink",children:h.label}),r.jsx("div",{className:"flex items-center gap-1",children:h.keys.map(c=>r.jsx("kbd",{className:"px-2 py-0.5 text-[11px] font-mono bg-hover border border-border rounded text-muted-accessible",children:c},c))})]},h.label))})]},a)}),n.length===0&&r.jsx("div",{className:"px-5 py-8 text-center",children:r.jsxs("p",{className:"text-xs text-muted",children:['No shortcuts matching "',s,'"']})})]}),r.jsx("div",{className:"px-5 py-3 border-t border-border text-center",children:r.jsxs("span",{className:"text-[11px] text-muted",children:["Press ",r.jsx("kbd",{className:"px-1.5 py-0.5 text-[10px] font-mono bg-hover border border-border rounded",children:"Escape"})," to close"]})})]})}):null}function wx({onClick:e}){return r.jsx("button",{onClick:e,title:"Keyboard shortcuts",className:"inline-flex items-center justify-center w-7 h-7 rounded-btn text-muted hover:text-ink hover:bg-hover transition-colors text-xs font-bold",children:"?"})}const yh="pl_recent_commands",Cx=5;function Sh(){try{const e=localStorage.getItem(yh);return e?JSON.parse(e):[]}catch{return[]}}function Gr(e){try{const t=Sh().filter(s=>s!==e);t.unshift(e),localStorage.setItem(yh,JSON.stringify(t.slice(0,Cx)))}catch{}}function kx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:Z,ts:Z,tsx:Z,jsx:Z,py:Z,go:Z,rs:Z,rb:Z,sh:Z,html:sc,css:to,json:eo,md:cr}[t]||so}function Nx(e,t){const s=e.toLowerCase(),i=t.toLowerCase(),n=[];let o=0;for(let a=0;a<i.length&&o<s.length;a++)i[a]===s[o]&&(n.push(a),o++);return o===s.length?n:null}function Dl({text:e,indices:t}){if(t.length===0)return r.jsx(r.Fragment,{children:e});const s=new Set(t);return r.jsx(r.Fragment,{children:e.split("").map((i,n)=>s.has(n)?r.jsx("span",{className:"text-primary font-semibold",children:i},n):r.jsx("span",{children:i},n))})}function jx({isOpen:e,onClose:t,commands:s,sessionId:i,onFileSelect:n}){const[o,a]=d.useState(""),[l,h]=d.useState(0),[c,u]=d.useState([]),[m,f]=d.useState(!1),g=d.useRef(null),p=d.useRef(null),_=gd(e);xd(e,t),d.useEffect(()=>{e&&(a(""),h(0),u([]),f(!1),setTimeout(()=>{var S;return(S=g.current)==null?void 0:S.focus()},50))},[e]);const v=d.useMemo(()=>Sh().map(j=>s.find(C=>C.id===j)).filter(Boolean),[s]),y=d.useMemo(()=>{if(!o.trim())return s.map(j=>({cmd:j,indices:[]}));const S=[];for(const j of s){const C=Nx(o,j.label);if(C){const B=C[0]*10+(C[C.length-1]-C[0]);S.push({cmd:j,indices:C,score:B})}}return S.sort((j,C)=>j.score-C.score),S.map(j=>({cmd:j.cmd,indices:j.indices}))},[s,o]),x=d.useMemo(()=>o.trim()?y.filter(S=>S.cmd.category==="setting"):[],[y,o]),k=d.useMemo(()=>y.filter(S=>S.cmd.category!=="setting"),[y]);d.useEffect(()=>{if(!i||!o.trim()){u([]),f(!1);return}return f(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(async()=>{try{const S=await K.searchFiles(i,o);u(S.filter(j=>j.type==="file"))}catch{u([])}f(!1)},200),()=>{p.current&&clearTimeout(p.current)}},[o,i]);const N=!o.trim()&&v.length>0,w=d.useMemo(()=>{const S=[];return N&&v.forEach((j,C)=>S.push({type:"recent",index:C})),k.forEach((j,C)=>S.push({type:"command",index:C})),x.length>0&&x.forEach((j,C)=>S.push({type:"setting",index:C})),c.forEach((j,C)=>S.push({type:"file",index:C})),S},[N,v,k,x,c]),R=w.length;d.useEffect(()=>{h(0)},[o]);const T=d.useCallback(S=>{const j=w[S];if(j){if(j.type==="recent"){const C=v[j.index];C&&(Gr(C.id),C.action(),t())}else if(j.type==="command"){const C=k[j.index];C&&(Gr(C.cmd.id),C.cmd.action(),t())}else if(j.type==="setting"){const C=x[j.index];C&&(Gr(C.cmd.id),C.cmd.action(),t())}else if(j.type==="file"){const C=c[j.index];C&&n&&(n(C.path,C.name),t())}}},[w,v,k,x,c,n,t]),W=d.useCallback(S=>{S.key==="ArrowDown"?(S.preventDefault(),h(j=>Math.min(j+1,R-1))):S.key==="ArrowUp"?(S.preventDefault(),h(j=>Math.max(j-1,0))):S.key==="Enter"&&R>0?T(l):S.key==="Escape"&&t()},[R,l,T,t]);if(!e)return null;let G=0;const U=()=>G++,A=k.length>0,M=x.length>0,E=c.length>0,L=m&&o.trim().length>0;return r.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[20vh]",onClick:t,children:[r.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm"}),r.jsxs("div",{ref:_,className:"relative w-full max-w-lg bg-card rounded-xl shadow-2xl border border-border overflow-hidden",onClick:S=>S.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border",children:[r.jsx(ts,{size:18,className:"text-muted"}),r.jsx("input",{ref:g,value:o,onChange:S=>a(S.target.value),onKeyDown:W,placeholder:"Search commands, files, settings...",className:"flex-1 bg-transparent text-sm outline-none text-ink placeholder:text-muted"}),r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:"ESC"})]}),r.jsxs("div",{className:"max-h-[360px] overflow-y-auto py-1 terminal-scroll",children:[N&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider flex items-center gap-1.5",children:[r.jsx(nt,{size:10})," Recent"]}),v.map((S,j)=>{const C=U(),B=S.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:S.label}),S.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.shortcut})]},`recent-${S.id}`)})]}),A&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider",children:"Commands"}),k.map((S,j)=>{const C=U(),B=S.cmd.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:o.trim()?r.jsx(Dl,{text:S.cmd.label,indices:S.indices}):S.cmd.label}),S.cmd.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.cmd.shortcut})]},S.cmd.id)})]}),M&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider mt-1",children:"Settings"}),x.map((S,j)=>{const C=U(),B=S.cmd.icon;return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:r.jsx(Dl,{text:S.cmd.label,indices:S.indices})}),S.cmd.shortcut&&r.jsx("kbd",{className:"text-[10px] text-muted bg-hover px-1.5 py-0.5 rounded border border-border font-mono",children:S.cmd.shortcut})]},`setting-${S.cmd.id}`)})]}),E&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-4 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider mt-1",children:"Files"}),c.map((S,j)=>{const C=U(),B=S.type==="directory"?io:kx(S.name);return r.jsxs("button",{onClick:()=>T(C),className:`w-full flex items-center gap-3 px-4 py-2 text-sm transition-colors ${C===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(B,{size:14}),r.jsx("span",{className:"flex-1 text-left font-mono text-xs truncate",children:S.name}),r.jsx("span",{className:"text-[10px] text-muted truncate max-w-[200px]",children:S.path})]},`file-${S.path}`)})]}),L&&!E&&r.jsx("div",{className:"px-4 py-2 text-xs text-muted animate-pulse",children:"Searching files..."}),R===0&&!L&&r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted",children:"No results found"})]})]})]})}const Ex=d.lazy(()=>Xn(()=>import("./GitHubIssuesPanel-B_Jm7CmJ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])).then(e=>({default:e.GitHubIssuesPanel}))),Rx=d.lazy(()=>Xn(()=>import("./GitHubPRsPanel-B5i8Q99N.js"),__vite__mapDeps([31,1,2,3,32,4,5,33,12,14,17,9,10,11,13,15,16,8,18,19,20,21,22,23,24,7,25,26,27,28,29,30])).then(e=>({default:e.GitHubPRsPanel}))),Dx=d.lazy(()=>Xn(()=>Promise.resolve().then(()=>Gx),void 0).then(e=>({default:e.CICDPanel}))),Px=3e4,Mx={modified:r.jsx(Z,{size:13,className:"text-yellow-500"}),added:r.jsx(dr,{size:13,className:"text-green-500"}),deleted:r.jsx(Qn,{size:13,className:"text-red-400"}),renamed:r.jsx(Z,{size:13,className:"text-blue-400"}),untracked:r.jsx(ic,{size:13,className:"text-muted"})},Lx={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?"};function Bx({commit:e}){return r.jsx("div",{className:"px-3 py-2 border-b border-border hover:bg-hover transition-colors",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Zl,{size:14,className:"text-primary mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-xs font-medium text-ink truncate",children:e.message}),r.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[r.jsx("span",{className:"text-[11px] font-mono text-primary/70",children:e.short_hash}),r.jsx("span",{className:"text-[11px] text-muted",children:e.author}),r.jsx("span",{className:"text-[11px] text-muted ml-auto flex-shrink-0",children:e.date})]}),e.refs.length>0&&r.jsx("div",{className:"flex gap-1 mt-1",children:e.refs.map((t,s)=>r.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-mono bg-primary/10 text-primary rounded",children:[r.jsx(ze,{size:9}),t]},s))})]})]})})}function Pl({file:e}){return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-hover transition-colors text-xs",children:[Mx[e.status]||r.jsx(ic,{size:13}),r.jsx("span",{className:"font-mono text-ink truncate flex-1",children:e.path}),r.jsx("span",{className:`font-mono text-[10px] px-1 rounded ${e.staged?"bg-green-500/10 text-green-500":"bg-muted/10 text-muted"}`,children:Lx[e.status]||"?"})]})}function Tx({sessionId:e}){const[t,s]=d.useState("changes"),[i,n]=d.useState(null),[o,a]=d.useState([]),[l,h]=d.useState([]),[c,u]=d.useState(!0),[m,f]=d.useState(null),[g,p]=d.useState(""),[_,v]=d.useState(!1),[y,x]=d.useState(null),[k,N]=d.useState(!1),[w,R]=d.useState(""),[T,W]=d.useState(!1),[G,U]=d.useState(!1),[A,M]=d.useState(""),[E,L]=d.useState(""),[S,j]=d.useState(!1),[C,B]=d.useState(null),[X,ae]=d.useState(!1),q=d.useCallback(async()=>{u(!0),f(null);try{const[D,le,ge]=await Promise.all([K.git.status(e),K.git.log(e),K.git.branches(e)]);n(D),a(le),h(ge)}catch(D){f(D instanceof Error?D.message:"Failed to load git data")}u(!1)},[e]);d.useEffect(()=>{q()},[q]);const Q=async()=>{if(!(!g.trim()||_)){v(!0),x(null);try{const D=await K.git.commit(e,g.trim());x(`Committed: ${D.hash}`),p(""),await q()}catch(D){x(`Error: ${D instanceof Error?D.message:"Commit failed"}`)}v(!1)}},ie=async()=>{if(!(!w.trim()||T)){W(!0);try{await K.git.createBranch(e,w.trim()),R(""),N(!1),await q()}catch(D){f(D instanceof Error?D.message:"Branch creation failed")}W(!1)}},he=async D=>{try{await K.git.checkoutBranch(e,D),await q()}catch(le){f(le instanceof Error?le.message:"Checkout failed")}},de=async()=>{ae(!0);try{await K.git.push(e),await q()}catch(D){f(D instanceof Error?D.message:"Push failed")}ae(!1)},z=async()=>{if(!(!A.trim()||S)){j(!0),B(null);try{const D=await K.git.pr(e,A.trim(),E.trim());B(D.url),M(""),L(""),U(!1)}catch(D){B(`Error: ${D instanceof Error?D.message:"PR creation failed"}`)}j(!1)}},V=(i==null?void 0:i.files.filter(D=>D.staged))||[],J=(i==null?void 0:i.files.filter(D=>!D.staged))||[];return c&&!i?r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading git status..."})]})}):m&&!i?r.jsx("div",{className:"h-full flex items-center justify-center p-6",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx(Ds,{size:32,className:"text-muted/40"}),r.jsx("p",{className:"text-sm text-muted",children:m}),r.jsx("p",{className:"text-xs text-muted/60",children:"This project may not be a git repository."}),r.jsx(ue,{size:"sm",variant:"secondary",icon:Ct,onClick:q,children:"Retry"})]})}):r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-hover flex-shrink-0",children:[r.jsx(ze,{size:14,className:"text-primary"}),r.jsx("span",{className:"text-xs font-semibold text-ink",children:(i==null?void 0:i.branch)||"unknown"}),i&&(i.ahead>0||i.behind>0)&&r.jsxs("span",{className:"text-[10px] text-muted font-mono",children:[i.ahead>0&&`+${i.ahead}`,i.ahead>0&&i.behind>0&&" / ",i.behind>0&&`-${i.behind}`]}),(i==null?void 0:i.clean)&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[10px] text-green-500",children:[r.jsx(Ut,{size:10})," Clean"]}),r.jsx("div",{className:"flex-1"}),r.jsx("button",{onClick:q,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(Ct,{size:13,className:c?"animate-spin":""})})]}),r.jsx("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border flex-shrink-0",children:[{id:"changes",label:"Changes",icon:Z,count:(i==null?void 0:i.files.length)||0},{id:"history",label:"History",icon:nt},{id:"branches",label:"Branches",icon:ze,count:l.length}].map(D=>r.jsxs("button",{onClick:()=>s(D.id),className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===D.id?"bg-primary/10 text-primary":"text-muted hover:text-ink"}`,children:[r.jsx(D.icon,{size:12}),D.label,D.count!==void 0&&D.count>0&&r.jsx("span",{className:"ml-0.5 px-1 py-0 text-[9px] rounded-full bg-primary/20 text-primary font-mono",children:D.count})]},D.id))}),m&&r.jsx("div",{className:"px-3 py-2 bg-red-500/5 border-b border-red-500/20 text-xs text-red-400",children:m}),r.jsxs("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:[t==="changes"&&r.jsx("div",{className:"flex flex-col h-full",children:(i==null?void 0:i.files.length)===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(Ut,{size:28,className:"text-green-500/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"Working tree clean"}),r.jsx("p",{className:"text-[11px] text-muted/60 mt-0.5",children:"No changes to commit."})]}):r.jsxs(r.Fragment,{children:[V.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-green-500/5 border-b border-border",children:["Staged (",V.length,")"]}),V.map((D,le)=>r.jsx(Pl,{file:D},`s-${le}`))]}),J.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-yellow-500/5 border-b border-border",children:["Unstaged (",J.length,")"]}),J.map((D,le)=>r.jsx(Pl,{file:D},`u-${le}`))]}),r.jsxs("div",{className:"mt-auto border-t border-border p-3 space-y-2 flex-shrink-0",children:[r.jsx("textarea",{value:g,onChange:D=>p(D.target.value),placeholder:"Commit message...",rows:2,className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors resize-none font-mono"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ue,{size:"sm",icon:Zl,onClick:Q,disabled:!g.trim()||_,loading:_,children:"Commit"}),r.jsx(ue,{size:"sm",variant:"secondary",icon:ac,onClick:de,loading:X,disabled:X,children:"Push"}),r.jsx(ue,{size:"sm",variant:"ghost",icon:sn,onClick:()=>U(!G),children:"PR"})]}),y&&r.jsx("p",{className:`text-[11px] font-mono ${y.startsWith("Error")?"text-red-400":"text-green-500"}`,children:y}),C&&r.jsx("p",{className:"text-[11px] font-mono text-primary",children:C.startsWith("Error")?r.jsx("span",{className:"text-red-400",children:C}):r.jsx("a",{href:C,target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-primary/80",children:C})})]}),G&&r.jsxs("div",{className:"border-t border-border p-3 space-y-2 flex-shrink-0 bg-hover",children:[r.jsx("p",{className:"text-[11px] font-semibold text-ink",children:"Create Pull Request"}),r.jsx("input",{value:A,onChange:D=>M(D.target.value),placeholder:"PR title...",className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary"}),r.jsx("textarea",{value:E,onChange:D=>L(D.target.value),placeholder:"PR description (optional)...",rows:3,className:"w-full px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary resize-none"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(ue,{size:"sm",icon:sn,onClick:z,disabled:!A.trim()||S,loading:S,children:"Create PR"}),r.jsx(ue,{size:"sm",variant:"ghost",onClick:()=>U(!1),children:"Cancel"})]})]})]})}),t==="history"&&r.jsx("div",{children:o.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(nt,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No commits yet"})]}):o.map((D,le)=>r.jsx(Bx,{commit:D},le))}),t==="branches"&&r.jsxs("div",{children:[r.jsx("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:r.jsxs("button",{onClick:()=>N(!k),className:"flex items-center gap-1 text-xs text-primary hover:text-primary/80 font-medium",children:[r.jsx(ur,{size:12}),"New Branch"]})}),k&&r.jsxs("div",{className:"px-3 py-2 border-b border-border bg-hover flex items-center gap-2",children:[r.jsx("input",{value:w,onChange:D=>R(D.target.value),placeholder:"branch-name",className:"flex-1 px-2 py-1 text-xs font-mono bg-card border border-border rounded-btn outline-none focus:border-primary",onKeyDown:D=>{D.key==="Enter"&&ie()}}),r.jsx(ue,{size:"sm",onClick:ie,disabled:!w.trim()||T,loading:T,children:"Create"})]}),l.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[r.jsx(ze,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No branches found"})]}):r.jsxs("div",{children:[l.filter(D=>!D.remote).map((D,le)=>r.jsxs("button",{onClick:()=>!D.current&&he(D.name),disabled:D.current,className:`w-full text-left flex items-center gap-2 px-3 py-2 text-xs border-b border-border transition-colors ${D.current?"bg-primary/5":"hover:bg-hover cursor-pointer"}`,children:[r.jsx(ze,{size:13,className:D.current?"text-primary":"text-muted"}),r.jsx("span",{className:`font-mono ${D.current?"text-primary font-semibold":"text-ink"}`,children:D.name}),D.current&&r.jsx("span",{className:"ml-auto text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded font-medium",children:"current"})]},`l-${le}`)),l.filter(D=>D.remote).length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-3 py-1.5 text-[10px] font-semibold text-muted uppercase tracking-wider bg-hover border-b border-border",children:"Remote"}),l.filter(D=>D.remote).map((D,le)=>r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs border-b border-border",children:[r.jsx(ze,{size:13,className:"text-muted/60"}),r.jsx("span",{className:"font-mono text-muted",children:D.name})]},`r-${le}`))]})]})]})]})]})}function Yr(){return r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading..."})]})})}function Xr({sessionId:e,onPushed:t}){const[s,i]=d.useState(!1),[n,o]=d.useState(null),a=async()=>{i(!0),o(null);try{await K.githubPush(e),t()}catch(l){o(l instanceof Error?l.message:"Push to GitHub failed")}i(!1)};return r.jsx("div",{className:"h-full flex items-center justify-center p-8",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 text-center max-w-xs",children:[r.jsx(au,{size:40,className:"text-muted/30"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-ink",children:"This project isn't connected to GitHub yet"}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Push your project to GitHub to access issues, pull requests, and CI/CD workflows."})]}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsx(ue,{size:"sm",icon:ac,onClick:a,loading:s,children:"Push to GitHub"})}),n&&r.jsx("p",{className:"text-[11px] text-red-400 font-mono",children:n})]})})}function zx({sessionId:e}){const[t,s]=d.useState("changes"),[i,n]=d.useState(!0),[o,a]=d.useState(null),[l,h]=d.useState({issues:0,prs:0,actions:0,fetchedAt:0}),c=d.useRef(!1),u=d.useCallback(async()=>{n(!0);try{const _=await K.getStatus();a({has_remote:!0,repo:"",owner:""})}catch{a({has_remote:!1})}n(!1)},[e]);d.useEffect(()=>{u()},[u]);const m=d.useCallback(async()=>{if(!(!(o!=null&&o.has_remote)||Date.now()-l.fetchedAt<Px)&&!c.current){c.current=!0;try{const[v,y,x]=await Promise.allSettled([K.getGitHubIssues(e,"open",1),K.getGitHubPRs(e,"open",1),K.getWorkflowRuns(e,5)]);h({issues:v.status==="fulfilled"?v.value.length:0,prs:y.status==="fulfilled"?y.value.length:0,actions:x.status==="fulfilled"?x.value.filter(k=>k.status==="in_progress").length:0,fetchedAt:Date.now()})}catch{}c.current=!1}},[e,o==null?void 0:o.has_remote,l.fetchedAt]);if(d.useEffect(()=>{o!=null&&o.has_remote&&m()},[o==null?void 0:o.has_remote,m]),d.useEffect(()=>{["issues","prs","actions"].includes(t)&&(o!=null&&o.has_remote)&&m()},[t,o==null?void 0:o.has_remote,m]),i)return r.jsx("div",{className:"h-full flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(Ct,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Checking GitHub connection..."})]})});const f=(o==null?void 0:o.has_remote)??!1,g=[{id:"changes",label:"Changes",icon:Z,requiresRemote:!1},{id:"issues",label:"Issues",icon:Gd,count:l.issues,requiresRemote:!0},{id:"prs",label:"PRs",icon:sn,count:l.prs,requiresRemote:!0},{id:"actions",label:"Actions",icon:It,count:l.actions,requiresRemote:!0}],p=g;return r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border bg-hover flex-shrink-0",children:[p.map(_=>{const v=_.requiresRemote&&!f;return r.jsxs("button",{onClick:()=>s(_.id),disabled:v,className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===_.id?"bg-primary/10 text-primary":v?"text-muted/40 cursor-not-allowed":"text-muted hover:text-ink"}`,title:v?"Connect to GitHub to access this tab":void 0,children:[r.jsx(_.icon,{size:12}),_.label,_.count!==void 0&&_.count>0&&r.jsx("span",{className:"ml-0.5 px-1 py-0 text-[9px] rounded-full bg-primary/20 text-primary font-mono",children:_.count})]},_.id)}),f&&(o==null?void 0:o.owner)&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted font-mono",children:[r.jsx(rc,{size:10}),o.owner,"/",o.repo]})]}),r.jsxs("div",{className:"flex-1 overflow-hidden",children:[t==="changes"&&r.jsx(Tx,{sessionId:e}),t==="issues"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx(Ex,{sessionId:e})}):r.jsx(Xr,{sessionId:e,onPushed:u})),t==="prs"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx(Rx,{sessionId:e})}):r.jsx(Xr,{sessionId:e,onPushed:u})),t==="actions"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Yr,{}),children:r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Dx,{sessionId:e})})}):r.jsx(Xr,{sessionId:e,onPushed:u}))]})]})}function Ax({sessionId:e,onRestore:t}){const[s,i]=d.useState([]),[n,o]=d.useState(!0),[a,l]=d.useState(null),[h,c]=d.useState(null),[u,m]=d.useState(null),f=d.useCallback(async()=>{try{const _=await K.getCheckpoints(e);i(_),m(null)}catch{m("Failed to load checkpoints")}o(!1)},[e]);d.useEffect(()=>{f();const _=setInterval(f,15e3);return()=>clearInterval(_)},[f]);const g=d.useCallback(async _=>{if(a)return;const v=s.find(x=>x.id===_);if(!(!v||!window.confirm(`Restore to checkpoint "${v.description}"?
|
|
256
256
|
|
|
257
257
|
This will revert files to this checkpoint state.`))){l(_);try{await K.restoreCheckpoint(e,_),await f(),t==null||t()}catch{m("Failed to restore checkpoint")}l(null)}},[e,s,a,f,t]);if(n)return r.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-card border-b border-border",children:[r.jsx(rn,{size:14,className:"text-muted animate-pulse"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading checkpoints..."})]});if(u&&s.length===0||s.length===0)return null;const p=_=>{if(!_)return"";try{return new Date(_).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}};return r.jsxs("div",{className:"flex items-center gap-2 px-4 py-1.5 bg-card border-b border-border overflow-x-auto",children:[r.jsx(rn,{size:14,className:"text-muted flex-shrink-0"}),r.jsx("span",{className:"text-[11px] font-medium text-muted flex-shrink-0",children:"Checkpoints"}),r.jsx("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:s.map((_,v)=>r.jsxs("div",{className:"flex items-center gap-1",children:[v>0&&r.jsx("div",{className:"w-4 h-px bg-border flex-shrink-0"}),r.jsxs("div",{className:"relative flex-shrink-0",children:[r.jsx("button",{onClick:()=>g(_.id),onMouseEnter:()=>c(_.id),onMouseLeave:()=>c(null),disabled:a!==null,className:`w-3.5 h-3.5 rounded-full border-2 transition-all cursor-pointer ${_.is_current?"bg-primary border-primary shadow-sm shadow-primary/30":a===_.id?"bg-warning border-warning animate-pulse":"bg-card border-border hover:border-primary hover:bg-primary/10"} ${a!==null&&a!==_.id?"opacity-50":""}`,title:`${_.description} -- Click to restore`}),h===_.id&&r.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 z-50 pointer-events-none",children:[r.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg px-3 py-2 whitespace-nowrap",children:[r.jsx("p",{className:"text-xs font-medium text-ink",children:_.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[_.timestamp&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(nt,{size:10}),p(_.timestamp)]}),_.files_changed>0&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(Z,{size:10}),_.files_changed," file",_.files_changed!==1?"s":""]}),_.iteration>0&&r.jsxs("span",{className:"text-[11px] text-muted",children:["Iter ",_.iteration]})]}),!_.is_current&&r.jsxs("div",{className:"flex items-center gap-1 mt-1.5 text-[11px] text-primary font-medium",children:[r.jsx(Ql,{size:10}),"Click to restore"]}),_.is_current&&r.jsx("div",{className:"text-[11px] text-success mt-1",children:"Current"})]}),r.jsx("div",{className:"w-2 h-2 bg-card border-r border-b border-border rotate-45 mx-auto -mt-1"})]})]})]},_.id))}),u&&r.jsx("span",{className:"text-[11px] text-danger flex-shrink-0",children:u})]})}function Ox({line:e}){const t=e.type==="add"?"bg-success/10":e.type==="delete"?"bg-danger/10":"",s=e.type==="add"?"text-success":e.type==="delete"?"text-danger":"text-muted",i=e.type==="add"?"+":e.type==="delete"?"-":" ",n=e.type==="delete"?e.old_line:e.new_line;return r.jsxs("div",{className:`flex font-mono text-xs leading-5 ${t}`,children:[r.jsx("span",{className:"w-12 text-right pr-2 text-muted/60 select-none flex-shrink-0 border-r border-border",children:n||""}),r.jsx("span",{className:`w-5 text-center select-none flex-shrink-0 ${s} font-bold`,children:i}),r.jsx("span",{className:`flex-1 whitespace-pre-wrap break-all pl-1 ${e.type==="context"?"text-ink/70":s}`,children:e.content})]})}function $x({file:e,isSelected:t,onToggle:s}){const[i,n]=d.useState(!0),o=e.action==="add"?r.jsx(dr,{size:14,className:"text-success"}):e.action==="delete"?r.jsx(su,{size:14,className:"text-danger"}):r.jsx(Z,{size:14,className:"text-blue-500"}),a=e.action==="add"?"New":e.action==="delete"?"Deleted":"Modified";return r.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-hover/50",children:[r.jsx("input",{type:"checkbox",checked:t,onChange:s,className:"w-3.5 h-3.5 rounded border-border accent-primary cursor-pointer"}),r.jsxs("button",{onClick:()=>n(l=>!l),className:"flex items-center gap-1 flex-1 min-w-0 text-left",children:[r.jsx(hr,{size:14,className:`text-muted transition-transform flex-shrink-0 ${i?"rotate-90":""}`}),o,r.jsx("span",{className:"text-xs font-mono text-ink truncate",children:e.path})]}),r.jsx("span",{className:`text-[11px] font-medium px-1.5 py-0.5 rounded ${e.action==="add"?"bg-success/10 text-success":e.action==="delete"?"bg-danger/10 text-danger":"bg-blue-500/10 text-blue-500"}`,children:a}),e.additions>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-success",children:[r.jsx(ur,{size:10}),e.additions]}),e.deletions>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-danger",children:[r.jsx(ec,{size:10}),e.deletions]})]}),i&&e.hunks.length>0&&r.jsx("div",{className:"border-t border-border max-h-[300px] overflow-y-auto terminal-scroll",children:e.hunks.map((l,h)=>r.jsxs("div",{children:[h>0&&r.jsxs("div",{className:"px-3 py-1 bg-hover/30 text-[11px] text-muted font-mono border-y border-border",children:["@@ -",l.old_start,",",l.old_count," +",l.new_start,",",l.new_count," @@"]}),l.lines.map((c,u)=>r.jsx(Ox,{line:c},`${h}-${u}`))]},h))})]})}function Ix({data:e,onAcceptAll:t,onAcceptSelected:s,onReject:i,onClose:n}){const[o,a]=d.useState(()=>new Set(e.files.map(f=>f.path))),[l,h]=d.useState(0),c=d.useCallback(f=>{a(g=>{const p=new Set(g);return p.has(f)?p.delete(f):p.add(f),p})},[]),u=d.useCallback(()=>{o.size===e.files.length?a(new Set):a(new Set(e.files.map(f=>f.path)))},[o.size,e.files]),m=d.useCallback(()=>{s(Array.from(o))},[o,s]);return e.files.length===0?r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm"}),r.jsxs("div",{className:"relative bg-card rounded-xl shadow-2xl border border-border p-8 max-w-md",onClick:f=>f.stopPropagation(),children:[r.jsx("p",{className:"text-sm text-ink text-center",children:"No pending changes to preview."}),r.jsx("button",{onClick:n,className:"mt-4 w-full py-2 text-sm font-medium rounded-btn border border-border text-muted hover:text-ink hover:bg-hover transition-colors",children:"Close"})]})]}):r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:n,children:[r.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm"}),r.jsxs("div",{className:"relative bg-card rounded-xl shadow-2xl border border-border w-full max-w-5xl max-h-[85vh] flex flex-col overflow-hidden",onClick:f=>f.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[r.jsx(Z,{size:18,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-bold text-ink flex-1",children:"Change Preview"}),r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted",children:[r.jsxs("span",{className:"flex items-center gap-1 text-success",children:[r.jsx(ur,{size:12}),e.total_additions]}),r.jsxs("span",{className:"flex items-center gap-1 text-danger",children:[r.jsx(ec,{size:12}),e.total_deletions]}),r.jsxs("span",{children:[e.files.length," file",e.files.length!==1?"s":""]})]}),r.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:r.jsx(ft,{size:16})})]}),r.jsxs("div",{className:"flex flex-1 min-h-0",children:[r.jsxs("div",{className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto terminal-scroll bg-hover/30",children:[r.jsx("div",{className:"px-3 py-2 border-b border-border",children:r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:o.size===e.files.length,onChange:u,className:"w-3.5 h-3.5 rounded border-border accent-primary"}),r.jsx("span",{className:"text-[11px] font-medium text-muted",children:"Select All"})]})}),e.files.map((f,g)=>{const p=f.action==="add"?"text-success":f.action==="delete"?"text-danger":"text-blue-500";return r.jsxs("button",{onClick:()=>h(g),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors ${g===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx("input",{type:"checkbox",checked:o.has(f.path),onChange:()=>c(f.path),onClick:_=>_.stopPropagation(),className:"w-3 h-3 rounded border-border accent-primary flex-shrink-0"}),r.jsx("span",{className:"text-xs font-mono truncate flex-1",children:f.path.split("/").pop()}),r.jsx("span",{className:`text-[10px] flex-shrink-0 ${p}`,children:f.action==="add"?"+":f.action==="delete"?"-":"M"})]},f.path)})]}),r.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 terminal-scroll",children:e.files[l]&&r.jsx($x,{file:e.files[l],isSelected:o.has(e.files[l].path),onToggle:()=>c(e.files[l].path)})})]}),r.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-t border-border bg-hover/30 flex-shrink-0",children:[r.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-btn border border-danger/30 text-danger hover:bg-danger/10 transition-colors",children:[r.jsx(tc,{size:14}),"Reject"]}),r.jsx("div",{className:"flex-1"}),r.jsxs("button",{onClick:m,disabled:o.size===0,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-btn border border-primary/30 text-primary hover:bg-primary/10 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(Ut,{size:14}),"Accept Selected (",o.size,")"]}),r.jsxs("button",{onClick:t,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-btn bg-primary text-white hover:bg-primary-hover transition-colors",children:[r.jsx(qd,{size:14}),"Accept All"]})]})]})]})}function Gi(e){if(e.status==="completed")switch(e.conclusion){case"success":return"success";case"failure":return"failed";case"cancelled":return"cancelled";case"skipped":return"skipped";case"timed_out":return"failed";default:return"failed"}return e.status==="in_progress"?"running":e.status==="queued"||e.status==="waiting"||e.status==="requested"||e.status==="pending"?"pending":"running"}function Fx(e){if(e.status==="completed")switch(e.conclusion){case"success":return"success";case"failure":return"failed";case"cancelled":return"cancelled";case"skipped":return"skipped";default:return"failed"}return e.status==="in_progress"?"running":e.status==="queued"||e.status==="waiting"?"pending":"running"}function Hx(e){if(e.status==="completed")switch(e.conclusion){case"success":return"success";case"failure":return"failed";case"cancelled":return"cancelled";case"skipped":return"skipped";default:return"failed"}return e.status==="in_progress"?"running":"pending"}const Co={pending:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:nt,label:"Queued"},running:{color:"text-[#553DE9]",bg:"bg-[#553DE9]/10",Icon:fr,label:"Running"},success:{color:"text-[#1FC5A8]",bg:"bg-[#1FC5A8]/10",Icon:Vl,label:"Success"},failed:{color:"text-[#C45B5B]",bg:"bg-[#C45B5B]/10",Icon:Ji,label:"Failed"},cancelled:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:tc,label:"Cancelled"},skipped:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:Gl,label:"Skipped"}};function wh(e){const t=new Date(e),i=Math.floor((new Date().getTime()-t.getTime())/1e3);if(i<60)return`${i}s ago`;const n=Math.floor(i/60);if(n<60)return`${n}m ago`;const o=Math.floor(n/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function Ch(e,t){if(!t)return"--";const s=new Date(t).getTime()-new Date(e).getTime();if(s<0)return"--";const i=Math.floor(s/1e3);if(i<60)return`${i}s`;const n=Math.floor(i/60),o=i%60;if(n<60)return`${n}m ${o}s`;const a=Math.floor(n/60),l=n%60;return`${a}h ${l}m`}function ko({status:e}){const t=Co[e];return r.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${t.bg} ${t.color}`,children:[r.jsx(t.Icon,{size:12,className:e==="running"?"animate-spin":""}),t.label]})}function Wx({step:e}){const t=Hx(e),s=Co[t];return r.jsxs("div",{className:"flex items-center gap-2 py-1 px-3 text-xs",children:[r.jsx(s.Icon,{size:12,className:`${s.color} flex-shrink-0 ${t==="running"?"animate-spin":""}`}),r.jsx("span",{className:"text-[#201515] dark:text-[#E8E6E3] flex-1 truncate",children:e.name}),e.startedAt&&e.completedAt&&r.jsx("span",{className:"text-[#939084] font-mono flex-shrink-0",children:Ch(e.startedAt,e.completedAt)}),r.jsx(ko,{status:t})]})}function Ux({job:e}){const[t,s]=d.useState(!1),i=Fx(e),n=Co[i];return r.jsxs("div",{className:"border border-[#ECEAE3] dark:border-[#2A2A30] rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>s(!t),className:"w-full flex items-center gap-3 px-4 py-2.5 text-left hover:bg-[#F8F4F0] dark:hover:bg-[#222228] transition-colors",children:[t?r.jsx(ls,{size:14,className:"text-[#939084]"}):r.jsx(hr,{size:14,className:"text-[#939084]"}),r.jsx(n.Icon,{size:14,className:`${n.color} ${i==="running"?"animate-spin":""}`}),r.jsx("span",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3] flex-1 truncate",children:e.name}),e.startedAt&&r.jsx("span",{className:"text-xs text-[#939084] font-mono flex-shrink-0",children:Ch(e.startedAt,e.completedAt)}),r.jsx(ko,{status:i})]}),t&&e.steps&&e.steps.length>0&&r.jsx("div",{className:"border-t border-[#ECEAE3] dark:border-[#2A2A30] bg-[#FAFAF8] dark:bg-[#1A1A1F] divide-y divide-[#ECEAE3] dark:divide-[#2A2A30]",children:e.steps.map(o=>r.jsx(Wx,{step:o},o.number))})]})}function Kx({sessionId:e,runId:t}){const[s,i]=d.useState(null),[n,o]=d.useState(!1),[a,l]=d.useState(null),h=d.useCallback(async()=>{o(!0),l(null);try{const c=await K.getWorkflowRunLogs(e,t);i(c)}catch(c){l(c instanceof Error?c.message:"Failed to fetch logs")}finally{o(!1)}},[e,t]);return d.useEffect(()=>{h()},[h]),n?r.jsxs("div",{className:"bg-[#0F0F11] rounded-lg p-4 text-center",children:[r.jsx(fr,{size:16,className:"animate-spin text-[#939084] inline-block"}),r.jsx("span",{className:"text-xs text-[#939084] ml-2",children:"Loading logs..."})]}):a?r.jsx("div",{className:"bg-[#0F0F11] rounded-lg p-4",children:r.jsx("p",{className:"text-xs text-[#C45B5B] font-mono",children:a})}):r.jsx("div",{className:"bg-[#0F0F11] rounded-lg p-3 max-h-80 overflow-y-auto terminal-scroll",children:r.jsx("pre",{className:"text-xs font-mono leading-relaxed whitespace-pre-wrap text-[#E8E6E3]",children:s||"(No log output)"})})}function qx({run:e,sessionId:t}){const[s,i]=d.useState(!1),[n,o]=d.useState(null),[a,l]=d.useState(!1),[h,c]=d.useState(null),[u,m]=d.useState(!1),f=Gi(e),g=d.useCallback(async()=>{if(!(n||a)){l(!0),c(null);try{const _=await K.getWorkflowRunDetail(t,e.databaseId);o(_)}catch(_){c(_ instanceof Error?_.message:"Failed to load run details")}finally{l(!1)}}},[t,e.databaseId,n,a]),p=()=>{const _=!s;i(_),_&&g()};return r.jsxs("div",{className:"border border-[#ECEAE3] dark:border-[#2A2A30] rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:p,className:"w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-[#F8F4F0] dark:hover:bg-[#222228] transition-colors",children:[s?r.jsx(ls,{size:14,className:"text-[#939084] flex-shrink-0"}):r.jsx(hr,{size:14,className:"text-[#939084] flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3] truncate",children:e.name}),r.jsx(ko,{status:f})]}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[r.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-[#939084]",children:[r.jsx(ze,{size:12}),e.headBranch]}),r.jsx("span",{className:"text-xs text-[#939084]",children:e.event}),r.jsx("span",{className:"text-xs text-[#939084]",children:wh(e.createdAt)})]})]}),r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:_=>_.stopPropagation(),className:"text-[#939084] hover:text-[#553DE9] transition-colors flex-shrink-0",title:"Open on GitHub",children:r.jsx(ss,{size:14})})]}),s&&r.jsxs("div",{className:"border-t border-[#ECEAE3] dark:border-[#2A2A30] px-4 pb-4 pt-3 space-y-3",children:[a&&r.jsxs("div",{className:"text-center py-4",children:[r.jsx(fr,{size:16,className:"animate-spin text-[#553DE9] inline-block"}),r.jsx("span",{className:"text-xs text-[#939084] ml-2",children:"Loading jobs..."})]}),h&&r.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-[#C45B5B]/10 text-[#C45B5B]",children:[r.jsx(Ot,{size:14}),r.jsx("span",{className:"text-xs",children:h})]}),n&&n.jobs&&n.jobs.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-xs font-semibold text-[#939084] uppercase tracking-wider",children:"Jobs"}),n.jobs.map(_=>r.jsx(Ux,{job:_},_.databaseId))]}),n&&(!n.jobs||n.jobs.length===0)&&!a&&r.jsx("p",{className:"text-xs text-[#939084]",children:"No jobs found for this run."}),n&&r.jsxs("div",{className:"pt-1",children:[r.jsxs("button",{onClick:()=>m(!u),className:"inline-flex items-center gap-1.5 text-xs text-[#553DE9] hover:text-[#4432c4] transition-colors",children:[r.jsx(es,{size:12}),u?"Hide full logs":"View full logs"]}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Kx,{sessionId:t,runId:e.databaseId})})]})]})]})}function Vx({sessionId:e,workflows:t,onClose:s,onDispatched:i}){var g;const[n,o]=d.useState(((g=t[0])==null?void 0:g.name)||""),[a,l]=d.useState(""),[h,c]=d.useState(!1),[u,m]=d.useState(null),f=async()=>{if(n){c(!0),m(null);try{await K.dispatchWorkflow(e,n,a),i(),s()}catch(p){m(p instanceof Error?p.message:"Dispatch failed")}finally{c(!1)}}};return r.jsxs("div",{className:"border border-[#ECEAE3] dark:border-[#2A2A30] rounded-lg p-4 bg-[#FAFAF8] dark:bg-[#1A1A1F] space-y-3",children:[r.jsx("h4",{className:"text-sm font-semibold text-[#201515] dark:text-[#E8E6E3]",children:"Run Workflow"}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-[#939084] mb-1",children:"Workflow"}),r.jsx("select",{value:n,onChange:p=>o(p.target.value),className:"w-full px-3 py-1.5 text-sm rounded-lg border border-[#ECEAE3] dark:border-[#2A2A30] bg-white dark:bg-[#0F0F11] text-[#201515] dark:text-[#E8E6E3] focus:outline-none focus:ring-2 focus:ring-[#553DE9]/40",children:t.map(p=>r.jsxs("option",{value:p.name,children:[p.name," (",p.name,")"]},p.id))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-[#939084] mb-1",children:"Branch / ref (leave empty for default)"}),r.jsx("input",{type:"text",value:a,onChange:p=>l(p.target.value),placeholder:"main",className:"w-full px-3 py-1.5 text-sm rounded-lg border border-[#ECEAE3] dark:border-[#2A2A30] bg-white dark:bg-[#0F0F11] text-[#201515] dark:text-[#E8E6E3] focus:outline-none focus:ring-2 focus:ring-[#553DE9]/40"})]}),u&&r.jsxs("div",{className:"flex items-center gap-2 p-2 rounded bg-[#C45B5B]/10 text-[#C45B5B]",children:[r.jsx(Ot,{size:12}),r.jsx("span",{className:"text-xs",children:u})]}),r.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[r.jsx(ue,{size:"sm",variant:"ghost",onClick:s,children:"Cancel"}),r.jsx(ue,{size:"sm",icon:It,onClick:f,loading:h,children:"Dispatch"})]})]})}function kh({sessionId:e}){const[t,s]=d.useState([]),[i,n]=d.useState([]),[o,a]=d.useState(""),[l,h]=d.useState(!0),[c,u]=d.useState(null),[m,f]=d.useState(!1),[g,p]=d.useState(null),_=d.useRef(null),v=t.some(R=>R.status==="in_progress"||R.status==="queued"||R.status==="waiting"||R.status==="requested"||R.status==="pending"),y=d.useCallback(async(R=!1)=>{if(e){R&&h(!0),u(null);try{const T=await K.getWorkflowRuns(e);s(T),a(""),p(new Date)}catch(T){const W=T instanceof Error?T.message:String(T);W.includes("gh CLI not found")?u({type:"gh_not_found",message:"The gh CLI is not installed. Install it from https://cli.github.com/ to enable CI/CD integration."}):W.includes("not authenticated")||W.includes("401")?u({type:"not_authenticated",message:'The gh CLI is not authenticated. Run "gh auth login" in your terminal.'}):W.includes("Could not detect")?u({type:"no_repo",message:"No GitHub remote detected. Push this project to GitHub first."}):u({type:"generic",message:W})}finally{h(!1)}}},[e]),x=d.useCallback(async()=>{if(e)try{const R=await K.getWorkflows(e);n(R.filter(T=>T.state==="active"))}catch{n([])}},[e]);d.useEffect(()=>{y(!0),x()},[y,x]),d.useEffect(()=>(v&&e?_.current=setInterval(()=>y(!1),1e4):_.current&&(clearInterval(_.current),_.current=null),()=>{_.current&&clearInterval(_.current)}),[v,e,y]);const k=t.filter(R=>Gi(R)==="success").length,N=t.filter(R=>Gi(R)==="failed").length,w=t.filter(R=>{const T=Gi(R);return T==="running"||T==="pending"}).length;return r.jsxs("div",{className:"card p-6",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ze,{size:18,className:"text-[#553DE9]"}),r.jsx("h3",{className:"text-sm font-semibold text-[#201515] dark:text-[#E8E6E3] uppercase tracking-wider",children:"CI/CD Pipelines"}),o&&r.jsx("span",{className:"text-xs text-[#939084] font-mono",children:o})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[g&&r.jsxs("span",{className:"text-[10px] text-[#939084] flex items-center gap-1",children:[r.jsx(oc,{size:10}),wh(g.toISOString())]}),r.jsx(ue,{size:"sm",variant:"ghost",icon:Ct,onClick:()=>y(!0),children:"Refresh"}),i.length>0&&r.jsx(ue,{size:"sm",icon:It,onClick:()=>f(!m),children:"Run Workflow"})]})]}),m&&e&&i.length>0&&r.jsx("div",{className:"mb-4",children:r.jsx(Vx,{sessionId:e,workflows:i,onClose:()=>f(!1),onDispatched:()=>{setTimeout(()=>y(!1),3e3)}})}),c&&r.jsxs("div",{className:"mb-4",children:[c.type==="gh_not_found"&&r.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-[#939084]/5 border border-[#ECEAE3] dark:border-[#2A2A30]",children:[r.jsx(Ot,{size:18,className:"text-[#939084] flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3]",children:"GitHub CLI not installed"}),r.jsx("p",{className:"text-xs text-[#939084] mt-1",children:c.message}),r.jsxs("a",{href:"https://cli.github.com/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-[#553DE9] hover:text-[#4432c4] mt-2",children:["Install GitHub CLI ",r.jsx(ss,{size:10})]})]})]}),c.type==="not_authenticated"&&r.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-[#C45B5B]/5 border border-[#C45B5B]/20",children:[r.jsx(Ot,{size:18,className:"text-[#C45B5B] flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3]",children:"Not authenticated"}),r.jsx("p",{className:"text-xs text-[#939084] mt-1",children:c.message}),r.jsx("code",{className:"inline-block text-xs bg-[#0F0F11] text-[#E8E6E3] px-2 py-1 rounded mt-2 font-mono",children:"gh auth login"})]})]}),c.type==="no_repo"&&r.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-[#939084]/5 border border-[#ECEAE3] dark:border-[#2A2A30]",children:[r.jsx(ze,{size:18,className:"text-[#939084] flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3]",children:"No GitHub repository"}),r.jsx("p",{className:"text-xs text-[#939084] mt-1",children:c.message})]})]}),c.type==="generic"&&r.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-[#C45B5B]/5 border border-[#C45B5B]/20",children:[r.jsx(Ot,{size:18,className:"text-[#C45B5B] flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium text-[#201515] dark:text-[#E8E6E3]",children:"Failed to load workflow runs"}),r.jsx("p",{className:"text-xs text-[#939084] mt-1",children:c.message})]})]})]}),!l&&!c&&t.length>0&&r.jsxs("div",{className:"flex items-center gap-4 mb-4 text-xs",children:[r.jsxs("span",{className:"flex items-center gap-1 text-[#1FC5A8]",children:[r.jsx(Vl,{size:12}),k," passed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#C45B5B]",children:[r.jsx(Ji,{size:12}),N," failed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#553DE9]",children:[r.jsx(fr,{size:12,className:w>0?"animate-spin":""}),w," active"]}),v&&r.jsx("span",{className:"text-[#939084] italic",children:"Auto-refreshing every 10s"})]}),l&&r.jsx("div",{className:"space-y-3",children:[1,2,3].map(R=>r.jsx("div",{className:"border border-[#ECEAE3] dark:border-[#2A2A30] rounded-lg p-4 animate-pulse",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-4 h-4 bg-[#ECEAE3] dark:bg-[#2A2A30] rounded"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("div",{className:"h-4 bg-[#ECEAE3] dark:bg-[#2A2A30] rounded w-48"}),r.jsx("div",{className:"h-3 bg-[#ECEAE3] dark:bg-[#2A2A30] rounded w-32 mt-2"})]}),r.jsx("div",{className:"h-5 bg-[#ECEAE3] dark:bg-[#2A2A30] rounded-full w-16"})]})},R))}),!l&&!c&&t.length===0&&r.jsxs("div",{className:"text-center py-8",children:[r.jsx("p",{className:"text-[#939084] text-sm",children:"No workflow runs found"}),r.jsx("p",{className:"text-[#939084]/60 text-xs mt-1",children:"Push commits or trigger a workflow to see runs here"})]}),!l&&!c&&t.length>0&&e&&r.jsx("div",{className:"space-y-3 max-h-[600px] overflow-y-auto terminal-scroll",children:t.map(R=>r.jsx(qx,{run:R,sessionId:e},R.databaseId))})]})}const Gx=Object.freeze(Object.defineProperty({__proto__:null,CICDPanel:kh},Symbol.toStringTag,{value:"Module"}));function Yx({phase:e,buildTime:t,onDismiss:s}){const[i,n]=d.useState(!1),[o,a]=d.useState(!1),l=d.useRef(e);if(d.useEffect(()=>{if(e==="complete"&&l.current!=="complete"){n(!0),a(!1);const c=setTimeout(()=>{n(!1),a(!0),s==null||s()},3e3);return()=>clearTimeout(c)}e!=="complete"&&a(!1),l.current=e},[e,s]),!i||o)return null;const h=c=>{if(c<60)return`${c}s`;const u=Math.floor(c/60),m=c%60;return`${u}m ${m}s`};return r.jsx("div",{className:"build-celebration-overlay",onClick:()=>{n(!1),a(!0),s==null||s()},children:r.jsxs("div",{className:"build-celebration-content",onClick:c=>c.stopPropagation(),children:[r.jsx("div",{className:"build-celebration-icon",children:r.jsx(kt,{size:48,className:"text-success"})}),r.jsx("div",{className:"build-celebration-burst"}),r.jsx("h3",{className:"text-lg font-heading font-bold text-ink mt-4",children:"Your app is ready!"}),r.jsx("p",{className:"text-sm text-muted mt-1",children:t?`Built in ${h(t)}. Time to see it in action.`:"Everything looks great. Go take a look."})]})})}function Xx({tokenHistory:e,budget:t=1e5,className:s=""}){const i=e.slice(-10);if(i.length<2)return null;const n=64,o=20,a=2,l=Math.max(...i,1),h=Math.min(...i,0),c=l-h||1,u=i.map((y,x)=>({x:a+x/(i.length-1)*(n-a*2),y:a+(1-(y-h)/c)*(o-a*2)})),m=u.map((y,x)=>`${x===0?"M":"L"} ${y.x.toFixed(1)} ${y.y.toFixed(1)}`).join(" "),f=`${m} L ${u[u.length-1].x.toFixed(1)} ${o-a} L ${u[0].x.toFixed(1)} ${o-a} Z`,p=i[i.length-1]/t;let _="#1FC5A8",v="rgba(31, 197, 168, 0.15)";return p>1?(_="#C45B5B",v="rgba(196, 91, 91, 0.15)"):p>.75&&(_="#D4A03C",v="rgba(212, 160, 60, 0.15)"),r.jsxs("svg",{width:n,height:o,viewBox:`0 0 ${n} ${o}`,className:`inline-block align-middle ${s}`,"aria-label":"Token usage trend",children:[r.jsx("path",{d:f,fill:v}),r.jsx("path",{d:m,fill:"none",stroke:_,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("circle",{cx:u[u.length-1].x,cy:u[u.length-1].y,r:"2",fill:_})]})}function Jx(){const[e,t]=d.useState([]),s=d.useRef(0);return{history:e,recordTokens:n=>{n!==s.current&&(s.current=n,t(o=>{const a=[...o,n];return a.length>20?a.slice(-20):a}))}}}function Zx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:{icon:Z,color:"text-yellow-600",label:"JavaScript"},jsx:{icon:Z,color:"text-yellow-500",label:"JSX"},ts:{icon:Z,color:"text-blue-500",label:"TypeScript"},tsx:{icon:Z,color:"text-blue-400",label:"TSX"},py:{icon:Z,color:"text-green-600",label:"Python"},html:{icon:Z,color:"text-orange-500",label:"HTML"},css:{icon:to,color:"text-purple-500",label:"CSS"},json:{icon:eo,color:"text-green-500",label:"JSON"},md:{icon:cr,color:"text-muted",label:"Markdown"},go:{icon:Z,color:"text-cyan-600",label:"Go"},rs:{icon:Z,color:"text-orange-600",label:"Rust"}}[t]||{icon:so,color:"text-muted",label:t.toUpperCase()||"Plain Text"}}function Qx(e){const t=Math.floor((Date.now()-e)/1e3);return t<2?"just now":t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function Ml(e){if(e<60)return`${e}s`;const t=Math.floor(e/60),s=e%60;return`${t}m ${s}s`}function ev({selectedFile:e,fileName:t,isModified:s,isSaving:i,lastSavedAt:n,lineCount:o,cursorLine:a,cursorColumn:l,buildTime:h,sessionId:c,prd:u}){const[m,f]=d.useState(""),[g,p]=d.useState(!1);d.useEffect(()=>{if(!n)return;const N=()=>f(Qx(n));N();const w=setInterval(N,5e3);return()=>clearInterval(w)},[n]);const _=d.useCallback(async()=>{const N=["Built with Loki Mode",c?`Session: ${c}`:"",h?`Build time: ${Ml(h)}`:"",u?`
|
|
258
258
|
Project: ${u.substring(0,100)}${u.length>100?"...":""}`:"",`
|
|
@@ -282,6 +282,6 @@ https://autonomi.dev`].filter(Boolean).join(`
|
|
|
282
282
|
text-ink placeholder:text-muted`}),i&&r.jsx("button",{type:"button",onClick:x,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted hover:text-ink transition-colors",children:r.jsx(ft,{size:14})})]})]}),!m&&c&&r.jsxs("div",{className:"px-4 pb-3",children:[r.jsx("div",{className:"text-[11px] text-muted mb-1.5",children:"Try searching for:"}),r.jsx("div",{className:"flex flex-wrap gap-1",children:Pv.map(w=>r.jsx("button",{onClick:()=>k(w),className:`text-[11px] text-primary bg-primary/5 hover:bg-primary/10
|
|
283
283
|
px-2 py-1 rounded-pill border border-primary/10 transition-colors`,children:w},w))})]}),l&&r.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-xs text-muted",children:[r.jsx(di,{size:14,className:"animate-spin"}),"Searching..."]}),m&&!l&&r.jsx("div",{className:"border-t border-border",children:o.length===0?r.jsx("div",{className:"text-center py-6 text-xs text-muted",children:"No results found. Try a different query."}):r.jsxs("div",{className:"max-h-[320px] overflow-y-auto terminal-scroll",children:[r.jsxs("div",{className:"text-[11px] text-muted px-4 py-1.5 bg-hover/30 border-b border-border",children:[o.length," result",o.length!==1?"s":""," found"]}),o.map((w,R)=>r.jsxs("button",{onClick:()=>t(w.path,w.lineNumber),className:`w-full flex items-center gap-3 px-4 py-2.5 text-left
|
|
284
284
|
hover:bg-hover/50 transition-colors border-b border-border last:border-b-0
|
|
285
|
-
group cursor-pointer`,children:[r.jsx(Z,{size:14,className:N(w.path)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs font-medium text-ink group-hover:text-primary transition-colors truncate",children:w.name}),r.jsx("div",{className:"text-[11px] text-muted font-mono truncate",children:w.path}),w.matchContext&&r.jsx("div",{className:"text-[11px] text-secondary mt-0.5 truncate font-mono",children:w.matchContext})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[w.lineNumber&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-muted font-mono",children:[r.jsx(cu,{size:10}),w.lineNumber]}),r.jsx(Jn,{size:12,className:"text-muted group-hover:text-primary transition-colors"})]})]},`${w.path}-${R}`))]})})]})}const or={claude:{input:.003,output:.015,label:"Claude (Sonnet)"},codex:{input:.002,output:.008,label:"Codex (GPT-4o)"},gemini:{input:.00125,output:.005,label:"Gemini Pro"}},ar={simple:{tokens:5e4,label:"Simple",iters:3},standard:{tokens:15e4,label:"Standard",iters:8},complex:{tokens:4e5,label:"Complex",iters:15}};function Lv(e,t,s){const i=or[t]||or.claude,n=ar[e]||ar.standard,o=s||n.iters,a=[{phase:"planning",label:"Planning",pct:.15},{phase:"building",label:"Building",pct:.55},{phase:"testing",label:"Testing",pct:.2},{phase:"reviewing",label:"Review",pct:.1}],l=n.tokens*(o/n.iters),h=Math.round(l),c=a.map(p=>{const _=Math.round(h*p.pct),v=_*.4,y=_*.6,x=(v*i.input+y*i.output)/1e3;return{phase:p.phase,label:p.label,estimatedCost:x,estimatedTokens:_}}),u=c.reduce((p,_)=>p+_.estimatedCost,0),f=o*(e==="complex"?40:e==="simple"?15:25),g=f<60?`${f}s`:f<3600?`${Math.round(f/60)}min`:`${(f/3600).toFixed(1)}hr`;return{total:{low:u*.7,high:u*1.4},breakdown:c,totalTokens:h,estimatedTime:g}}function Ol(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:String(e)}function Bv({complexity:e,provider:t,templateType:s,estimatedIterations:i,onConfirm:n,onCancel:o,historicalAvgCost:a}){const[l,h]=d.useState(!1),c=Lv(e,t,i),u=or[t]||or.claude,m=ar[e]||ar.standard,f=c.total.high>5;return r.jsxs("div",{className:"card overflow-hidden max-w-md mx-auto",children:[r.jsxs("div",{className:"px-5 pt-5 pb-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Jl,{size:18,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Build Cost Estimate"})]}),r.jsx("p",{className:"text-xs text-muted",children:"Estimated cost before starting your build"})]}),r.jsxs("div",{className:"px-5 py-4",children:[r.jsxs("div",{className:"text-center mb-4",children:[r.jsxs("div",{className:"text-3xl font-bold font-mono text-ink tracking-tight",children:["$",c.total.low.toFixed(2)," -- $",c.total.high.toFixed(2)]}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Estimated total cost"})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(Zt,{size:14,className:"text-primary mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:Ol(c.totalTokens)}),r.jsx("div",{className:"text-[11px] text-muted",children:"Tokens"})]}),r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(nt,{size:14,className:"text-info mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:c.estimatedTime}),r.jsx("div",{className:"text-[11px] text-muted",children:"Est. Time"})]}),r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(Zt,{size:14,className:"text-warning mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:i||m.iters}),r.jsx("div",{className:"text-[11px] text-muted",children:"Iterations"})]})]})]}),r.jsxs("div",{className:"px-5 py-2 bg-hover/30 border-t border-b border-border",children:[r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsx("span",{className:"text-muted",children:"Provider"}),r.jsx("span",{className:"font-medium text-ink",children:u.label})]}),r.jsxs("div",{className:"flex items-center justify-between text-xs mt-1",children:[r.jsx("span",{className:"text-muted",children:"Complexity"}),r.jsx("span",{className:"font-medium text-ink",children:m.label})]}),s&&r.jsxs("div",{className:"flex items-center justify-between text-xs mt-1",children:[r.jsx("span",{className:"text-muted",children:"Template"}),r.jsx("span",{className:"font-medium text-ink",children:s})]})]}),a!==void 0&&a>0&&r.jsx("div",{className:"px-5 py-2.5 bg-primary/5 border-b border-border",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[r.jsx(Td,{size:12,className:"text-primary"}),r.jsxs("span",{className:"text-secondary",children:["Similar projects cost ",r.jsxs("span",{className:"font-mono font-semibold text-ink",children:["$",a.toFixed(2)]})," on average"]})]})}),r.jsxs("div",{className:"px-5 py-2",children:[r.jsxs("button",{onClick:()=>h(!l),className:"flex items-center gap-1.5 w-full text-xs font-medium text-primary py-1.5",children:[l?r.jsx(lr,{size:12}):r.jsx(ls,{size:12}),"Cost breakdown by phase"]}),l&&r.jsx("div",{className:"space-y-2 mt-1 mb-2",children:c.breakdown.map(g=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-secondary",children:g.label}),r.jsxs("span",{className:"text-[11px] text-muted font-mono",children:[Ol(g.estimatedTokens)," tokens"]})]}),r.jsxs("span",{className:"text-xs font-mono font-semibold text-ink",children:["$",g.estimatedCost.toFixed(2)]})]},g.phase))})]}),f&&r.jsx("div",{className:"px-5 py-2 bg-warning/8 border-t border-warning/15",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ot,{size:14,className:"text-warning mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-xs text-secondary",children:"This build may be expensive. Consider using a simpler complexity level or a more cost-effective provider."})]})}),r.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border",children:[r.jsx(ue,{variant:"ghost",size:"sm",onClick:o,children:"Cancel"}),r.jsx(ue,{variant:"primary",size:"sm",onClick:n,icon:Zt,children:"Start Build"})]})]})}function Tv({sessionId:e}){return r.jsx(kh,{sessionId:e})}function Yn(e,t,s){var o;if(t==="directory")return s?r.jsx(tn,{size:14}):r.jsx(io,{size:14});const i=((o=e.split(".").pop())==null?void 0:o.toLowerCase())||"";return{js:r.jsx(Z,{size:14,className:"text-yellow-600"}),ts:r.jsx(Z,{size:14,className:"text-blue-500"}),tsx:r.jsx(Z,{size:14,className:"text-blue-400"}),jsx:r.jsx(Z,{size:14,className:"text-yellow-500"}),py:r.jsx(Z,{size:14,className:"text-green-600"}),html:r.jsx(sc,{size:14,className:"text-orange-500"}),css:r.jsx(to,{size:14,className:"text-purple-500"}),json:r.jsx(eo,{size:14,className:"text-green-500"}),md:r.jsx(cr,{size:14,className:"text-muted"}),go:r.jsx(Z,{size:14,className:"text-cyan-600"}),rs:r.jsx(Z,{size:14,className:"text-orange-600"}),rb:r.jsx(Z,{size:14,className:"text-red-500"}),sh:r.jsx(Z,{size:14,className:"text-green-600"})}[i]||r.jsx(so,{size:14})}function zv(e){var n;const t=((n=e.split(".").pop())==null?void 0:n.toLowerCase())||"",s={js:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",py:"python",html:"html",htm:"html",css:"css",scss:"scss",less:"less",json:"json",md:"markdown",go:"go",rs:"rust",sh:"shell",bash:"shell",yml:"yaml",yaml:"yaml",xml:"xml",svg:"xml",sql:"sql",java:"java",kt:"kotlin",rb:"ruby",dockerfile:"dockerfile"},i=e.toLowerCase();return i==="dockerfile"?"dockerfile":i==="makefile"?"makefile":s[t]||"plaintext"}function jh(e,t){for(const s of e){if(s.path===t)return s.size;if(s.children){const i=jh(s.children,t);if(i!==void 0)return i}}}function Eh(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Rh({nodes:e,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o=0}){const[a,l]=d.useState(()=>{const h=new Set;return o<2&&e.filter(c=>c.type==="directory").forEach(c=>h.add(c.path)),h});return r.jsx("div",{role:o===0?"tree":"group",children:e.map(h=>{const c=h.type==="directory",u=a.has(h.path),m=h.path===t;return r.jsxs("div",{className:"group/file",children:[r.jsxs("button",{role:"treeitem","aria-label":h.name,"aria-selected":m,...c?{"aria-expanded":u}:{},onContextMenu:f=>{f.preventDefault(),n==null||n(f,h.path,h.name,h.type)},onClick:()=>{c?l(f=>{const g=new Set(f);return g.has(h.path)?g.delete(h.path):g.add(h.path),g}):s(h.path,h.name)},className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded transition-colors ${m?"bg-primary/10 text-primary":"text-ink/70 hover:bg-hover"}`,style:{paddingLeft:`${o*14+8}px`},children:[c?r.jsx("span",{className:"w-3 flex items-center justify-center flex-shrink-0 text-muted",children:u?r.jsx(ls,{size:14}):r.jsx(hr,{size:14})}):r.jsx("span",{className:"w-3 flex-shrink-0"}),r.jsx("span",{className:`w-5 flex items-center justify-center flex-shrink-0 ${c?"text-primary":""}`,children:Yn(h.name,h.type,u)}),r.jsxs("span",{className:"truncate",children:[h.name,c?"/":""]}),!c&&h.size!=null&&h.size>0&&r.jsx("span",{className:"text-xs text-muted ml-auto flex-shrink-0",children:Eh(h.size)}),!c&&i&&r.jsx("span",{role:"button",tabIndex:-1,onClick:f=>{f.stopPropagation(),i(h.path,h.name)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),i(h.path,h.name))},className:"text-muted hover:text-danger ml-1 flex-shrink-0 opacity-0 group-hover/file:opacity-100 transition-opacity cursor-pointer",title:"Delete file",children:r.jsx(ft,{size:12})})]}),c&&u&&h.children&&r.jsx(Rh,{nodes:h.children,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o+1})]},h.path)})})}function Dh(e,t=""){const s=[];for(const i of e)i.type==="file"&&s.push({path:i.path,name:i.name}),i.children&&s.push(...Dh(i.children,i.path+"/"));return s}function Av(){const[e,t]=d.useState({}),[s,i]=d.useState(""),[n,o]=d.useState(""),[a,l]=d.useState(!0),[h,c]=d.useState(null),[u,m]=d.useState(new Set),f=d.useCallback(async()=>{try{const y=await K.getSecrets();t(y)}catch{}l(!1)},[]);d.useEffect(()=>{f()},[f]);const g=async()=>{const y=s.trim();if(y){if(!/^[A-Z_][A-Z0-9_]*$/.test(y)){c("Key must be a valid ENV_VAR name (uppercase letters, digits, underscores)");return}c(null);try{await K.setSecret(y,n),i(""),o(""),await f()}catch(x){c(x instanceof Error?x.message:"Failed to set secret")}}},p=async y=>{if(window.confirm(`Delete secret "${y}"?`))try{await K.deleteSecret(y),await f()}catch(x){c(x instanceof Error?x.message:"Failed to delete secret")}},_=y=>{m(x=>{const k=new Set(x);return k.has(y)?k.delete(y):k.add(y),k})},v=Object.keys(e);return a?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(Nr,{variant:"text",width:"180px",height:"16px"}),r.jsx(Nr,{variant:"block",width:"100%",height:"60px"}),r.jsx(Nr,{variant:"block",width:"100%",height:"80px"})]}):r.jsx("div",{className:"h-full flex flex-col",children:r.jsxs("div",{className:"p-6 overflow-y-auto",children:[r.jsx("h3",{className:"text-h3 font-heading text-ink mb-2",children:"Environment Secrets"}),r.jsxs("div",{className:"flex items-start gap-2 px-4 py-3 rounded-btn border border-warning/30 bg-warning/5 mb-6",children:[r.jsx(Ot,{size:16,className:"text-warning flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-xs text-warning leading-relaxed",children:"Secrets are stored locally in plaintext and injected as environment variables during builds. They are never committed to the project repository."})]}),v.length>0&&r.jsx("div",{className:"card mb-6",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-border",children:[r.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Key"}),r.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Value"}),r.jsx("th",{className:"w-20 px-4 py-2"})]})}),r.jsx("tbody",{children:v.map(y=>r.jsxs("tr",{className:"border-b border-border last:border-b-0",children:[r.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-ink",children:y}),r.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-muted-accessible",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{children:u.has(y)?e[y]:"***"}),r.jsx("button",{onClick:()=>_(y),className:"text-muted hover:text-ink transition-colors",title:u.has(y)?"Hide value":"Show value",children:u.has(y)?r.jsx(Bd,{size:14}):r.jsx(ys,{size:14})})]})}),r.jsx("td",{className:"px-4 py-2.5 text-right",children:r.jsx("button",{onClick:()=>p(y),className:"text-muted hover:text-danger transition-colors",title:"Delete secret",children:r.jsx(Qn,{size:14})})})]},y))})]})}),v.length===0&&r.jsx("div",{className:"card p-4 mb-6",children:r.jsx("p",{className:"text-sm text-muted-accessible text-center py-4",children:"No secrets configured yet. Add your first secret below."})}),r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-3",children:"Add Secret"}),h&&r.jsx("div",{className:"text-xs text-danger mb-3 px-1",children:h}),r.jsxs("div",{className:"flex items-end gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Key"}),r.jsx("input",{type:"text",value:s,onChange:y=>i(y.target.value.toUpperCase()),placeholder:"API_KEY",className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink placeholder:text-muted"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Value"}),r.jsx("input",{type:"password",value:n,onChange:y=>o(y.target.value),placeholder:"secret value",className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink placeholder:text-muted"})]}),r.jsxs("button",{onClick:g,disabled:!s.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-btn border border-primary bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(ur,{size:14}),"Add"]})]})]})]})})}function Ov({session:e,onClose:t}){var Qo;const[s,i]=d.useState(null),[n,o]=d.useState(""),[a,l]=d.useState(null),[h,c]=d.useState(null),[u,m]=d.useState(!1),[f,g]=d.useState("code"),[p,_]=d.useState(!1),[v,y]=d.useState(!1),[x,k]=d.useState(e),N=d.useRef(null),[w,R]=d.useState([]),[T,W]=d.useState(!1),[G,U]=d.useState(""),A=d.useRef(null),M=d.useRef(null),[E,L]=d.useState(0),[S,j]=d.useState(null),[C,B]=d.useState(!0),[X,ae]=d.useState(!0),[q,Q]=d.useState(!1),[ie,he]=d.useState("overview"),de=57374,[z,V]=d.useState(null),J=d.useCallback(()=>{Q(b=>{const I=!b;return B(!I),ae(!I),I})},[]),[D,le]=d.useState(()=>sessionStorage.getItem(`pl_buildmode_${x.id}`)||"standard"),[ge,Ee]=d.useState(()=>sessionStorage.getItem(`pl_provider_${x.id}`)||"claude"),[ee,fe]=d.useState(null),[_e,Ce]=d.useState(null),[Ge,Ls]=d.useState(!1),[us,et]=d.useState(!1),[ce,ot]=d.useState({phase:"idle",iteration:0,maxIterations:10,cost:0,startTime:0}),[at,fs]=d.useState(!1),[Bs,gi]=d.useState(null),Ts=d.useRef(null),[Ph,No]=d.useState(!1),[Mh,jo]=d.useState([]),[Eo,zs]=d.useState(null),[Lh,vr]=d.useState(!1),[Bh,xi]=d.useState(!1),[Th,As]=d.useState(!1),[vi,Ro]=d.useState("files"),{history:Do,recordTokens:Po}=Jx(),[zh,Ah]=d.useState(null),[Mo,Oh]=d.useState({line:1,column:1}),[$h,Lo]=d.useState(0),{device:Ih,setDevice:Fh,frameClass:Bo}=sv(),[br,Hh]=d.useState(100),[To,Wh]=d.useState(!1),[bi,yr]=d.useState(!1),[zo,Iv]=d.useState([]),ms=d.useRef(null),[Uh,Ao]=d.useState(0),{subscribe:Oo}=wd(),Ye=d.useCallback(async()=>{try{const b=await K.getSessionDetail(x.id);k(b)}catch{}},[x.id]),$o=d.useCallback(async()=>{try{await K.stopSession(),Ls(!1),et(!1)}catch{}},[]),Kh=d.useCallback(async()=>{try{await K.pauseSession(),et(!0)}catch{}},[]),qh=d.useCallback(async()=>{try{await K.resumeSession(),et(!1)}catch{}},[]),Io=d.useRef("idle");d.useEffect(()=>{const b=async()=>{try{const F=await K.getStatus();Ls(F.running),et(F.paused),F.provider&&Ee(F.provider);const te=F.phase||"idle";if(te!==Io.current&&te!=="idle"){const Xe=new Date().toISOString(),Dt={planning:"Planning phase started",building:"Building your project",testing:"Running tests",reviewing:"Reviewing code quality",complete:"Build complete"},bt={planning:"Analyzing requirements and designing the architecture...",building:"Writing code and creating project files...",testing:"Running test suite to verify everything works...",reviewing:"Checking code quality and best practices...",complete:"All done. Your project is ready."},Is=[{id:`phase-${Date.now()}`,type:"phase_change",message:Dt[te]||`Phase: ${te}`,timestamp:Xe}];bt[te]&&Is.push({id:`narration-${Date.now()}`,type:"narration",message:bt[te],timestamp:Xe}),jo(Ei=>[...Ei,...Is]),Io.current=te}ot({phase:te,iteration:F.iteration||0,maxIterations:F.max_iterations||10,cost:F.cost||0,startTime:F.start_time?F.start_time*1e3:0});const Ke=F.tokens_used;Ke!=null&&Po(Ke)}catch{}};b();const I=setInterval(b,Ge?3e3:1e4);return()=>clearInterval(I)},[Ge,Po]),d.useEffect(()=>{if(!(_e!=null&&_e.loading))return;const b=setInterval(()=>{Ce(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(b)},[_e==null?void 0:_e.loading]);const[se,Vh]=d.useState(null);d.useEffect(()=>{K.getPreviewInfo(x.id).then(Vh).catch(()=>{})},[x.id]);const[$,yi]=d.useState(null),[Os,Fo]=d.useState(!1),[Ho,Wo]=d.useState(!1),[Uo,Si]=d.useState(null),[Kt,Gh]=d.useState("");d.useEffect(()=>{const b=Oo("file_changed",I=>{const F=I;if(!F.paths||F.paths.length===0)return;const te=new Date().toISOString(),Ke=F.paths.map((Xe,Dt)=>{var Ei;const bt=(Ei=F.event_types)==null?void 0:Ei[Dt],Is=bt==="created"||bt==="IN_CREATE";return{id:`file-${Date.now()}-${Dt}`,type:Is?"file_created":"file_modified",message:Is?`Created ${Xe.split("/").pop()}`:`Modified ${Xe.split("/").pop()}`,timestamp:te,filePath:Xe}});if(jo(Xe=>[...Xe,...Ke]),fs(!0),Ts.current&&clearTimeout(Ts.current),Ts.current=setTimeout(()=>fs(!1),2e3),Ye(),s&&F.paths.some(Dt=>Dt===s||s.endsWith(Dt))&&gi(s),f==="preview"){const Xe=["react","vite","next","nuxt","svelte","remix"];($==null?void 0:$.running)&&($==null?void 0:$.framework)&&Xe.some(bt=>$.framework.toLowerCase().includes(bt))||L(bt=>bt+1)}});return()=>{b(),Ts.current&&clearTimeout(Ts.current)}},[Oo,s,f,$==null?void 0:$.running,Ye]);const Yh=d.useCallback(async()=>{if(!(!Bs||!x.id)){try{const b=await K.getSessionFileContent(x.id,Bs);l(b.content),c(b.content),_(!1),R(I=>I.map(F=>F.path===Bs?{...F,content:b.content,modified:!1}:F))}catch{}gi(null)}},[Bs,x.id]);d.useEffect(()=>{if(f!=="preview")return;let b=!1;const I=async()=>{try{const te=await K.devserver.status(x.id);b||yi(te)}catch{}};I();const F=setInterval(I,3e3);return()=>{b=!0,clearInterval(F)}},[f,x.id]),d.useEffect(()=>{f==="dashboard"&&fetch(`http://127.0.0.1:${de}/health`).then(b=>V(b.ok)).catch(()=>V(!1))},[f]);const ps=d.useCallback(async b=>{Fo(!0),Si(null);try{const I=await K.devserver.start(x.id,b);if(I.status==="error")Si(I.message||"Failed to start dev server");else{const F=await K.devserver.status(x.id);yi(F)}}catch(I){Si(I instanceof Error?I.message:"Failed to start dev server")}Fo(!1)},[x.id]),Ko=d.useRef(!1);d.useEffect(()=>{Ko.current||se!=null&&se.dev_command&&($!=null&&$.running||($==null?void 0:$.status)==="starting"||Os||(Ko.current=!0,ps(se.dev_command)))},[se==null?void 0:se.dev_command,$==null?void 0:$.running,$==null?void 0:$.status,Os,ps]);const Xh=d.useCallback(async()=>{try{await K.devserver.stop(x.id);const b=await K.devserver.status(x.id);yi(b)}catch{}},[x.id]),Jh=d.useCallback(async()=>{Wo(!0);try{const b=await K.fixProject(x.id);if(b.task_id){let F=0,te;do await new Promise(Xe=>setTimeout(Xe,2e3)),te=await K.chatPoll(x.id,b.task_id),F++;while(!te.complete&&F<150);const Ke=await K.devserver.status(x.id);yi(Ke)}}catch(b){Si(b instanceof Error?b.message:"Fix failed")}Wo(!1)},[x.id]),_s=$!=null&&$.running&&($!=null&&$.port)?$.framework==="expo"?`/api/sessions/${encodeURIComponent(x.id)}/expo-qr`:$.portless_url||`http://localhost:${$.port}/`:null,Zh=(se==null?void 0:se.preview_url)||`/api/sessions/${encodeURIComponent(x.id)}/preview/index.html`,Qh=_s||Zh,[wi,qo]=d.useState([]),[xt,Ci]=d.useState(0);d.useEffect(()=>{const b=_s||(se==null?void 0:se.preview_url);b&&(qo([b]),Ci(0))},[_s,se==null?void 0:se.preview_url]);const vt=wi[xt]||Qh,[Vo,Sr]=d.useState(vt),ed=d.useCallback((b,I,F,te)=>{b.preventDefault(),j({x:b.clientX,y:b.clientY,path:I,name:F,type:te})},[]),td=d.useCallback(()=>{xt>0&&(Ci(b=>b-1),L(b=>b+1))},[xt]),sd=d.useCallback(()=>{xt<wi.length-1&&(Ci(b=>b+1),L(b=>b+1))},[xt,wi.length]),id=d.useCallback(b=>{let I=b;if(b.startsWith("/")&&_s)try{I=`${new URL(_s).origin}${b}`}catch{const F=$==null?void 0:$.port;F&&(I=`http://localhost:${F}${b}`)}qo(F=>[...F.slice(0,xt+1),I]),Ci(F=>F+1),L(F=>F+1)},[xt,_s,$==null?void 0:$.port]);d.useEffect(()=>{try{const b=new URL(vt,window.location.origin);Sr(b.pathname+b.search+b.hash||"/")}catch{Sr(vt)}},[vt]);const ki=d.useCallback(async()=>{Ce({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.reviewProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),Ni=d.useCallback(async()=>{Ce({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.testProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),wr=d.useCallback(async()=>{Ce({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.explainProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),Cr=d.useCallback(async(b,I)=>{if(window.confirm(`Delete "${I}"?`))try{await K.deleteSessionFile(x.id,b),s===b&&(i(null),o(""),l(null),c(null),_(!1)),await Ye()}catch(te){const Ke=te instanceof Error?te.message:"Unknown error";window.alert(`Delete failed: ${Ke}`)}},[x.id,s,Ye]),rd=d.useCallback(b=>b.type==="file"?[{label:"Review",icon:ys,onClick:()=>{ki()}},{label:"Generate Tests",icon:si,onClick:()=>{Ni()}},{label:"Explain",icon:Jr,onClick:()=>{wr()}},{label:"Delete",icon:Qn,onClick:()=>{Cr(b.path,b.name)},variant:"danger"}]:[{label:"Review Project",icon:ys,onClick:()=>{ki()}},{label:"Run Tests",icon:si,onClick:()=>{Ni()}}],[ki,Ni,wr,Cr]),Rt=d.useCallback(async(b,I)=>{gi(null),p&&s&&h!==null&&R(te=>te.map(Ke=>Ke.path===s?{...Ke,content:h,modified:!0}:Ke));const F=w.find(te=>te.path===b);if(F){i(b),o(I),l(F.content),c(F.content),_(F.modified);return}i(b),o(I),m(!0),_(!1);try{const te=x.id?await K.getSessionFileContent(x.id,b):await K.getFileContent(b);l(te.content),c(te.content),R(Ke=>[...Ke,{path:b,name:I,content:te.content,modified:!1}])}catch{l("[Error loading file]"),c("[Error loading file]")}finally{m(!1)}},[x.id,p,s,h,w]),kr=d.useCallback(async()=>{var b;if(!(!s||h===null||!x.id)){y(!0);try{await K.saveSessionFile(x.id,s,h),l(h),_(!1),Ah(Date.now()),R(F=>F.map(te=>te.path===s?{...te,content:h,modified:!1}:te));const I=((b=s.split(".").pop())==null?void 0:b.toLowerCase())||"";["html","css","js","jsx","ts","tsx"].includes(I)&&L(F=>F+1)}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Save failed: ${F}`)}finally{y(!1)}}},[s,h,x.id]),Go=d.useCallback(b=>{const I=w.find(F=>F.path===b);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(R(F=>F.filter(te=>te.path!==b)),s===b)){const F=w.filter(te=>te.path!==b);if(F.length>0){const te=F[F.length-1];i(te.path),o(te.name),l(te.content),c(te.content),_(te.modified)}else i(null),o(""),l(null),c(null),_(!1)}},[w,s]);d.useEffect(()=>{const b=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),p&&s&&kr()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),W(F=>!F),U("")),(I.metaKey||I.ctrlKey)&&I.key==="k"&&(I.preventDefault(),No(F=>!F)),I.key==="Escape"&&T&&W(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[p,s,kr,T]),d.useEffect(()=>{T&&A.current&&A.current.focus()},[T]);const Yo=Dh(x.files),$s=G?Yo.filter(b=>b.path.toLowerCase().includes(G.toLowerCase())):Yo;d.useEffect(()=>{const b=x.files.find(I=>I.name==="index.html"&&I.type==="file");b&&Rt(b.path,b.name)},[]);const nd=d.useCallback(b=>{b!==void 0&&(c(b),_(b!==a),Lo(b.split(`
|
|
286
|
-
`).length))},[a]),od=d.useCallback(b=>{N.current=b;const I=b;if(I!=null&&I.onDidChangeCursorPosition&&I.onDidChangeCursorPosition(F=>{Oh({line:F.position.lineNumber,column:F.position.column})}),I!=null&&I.getModel){const F=I.getModel();F!=null&&F.getLineCount&&Lo(F.getLineCount())}},[]),ad=d.useCallback(async()=>{const b=window.prompt("New file name (e.g. src/utils.ts):");if(!(!b||!b.trim()))try{await K.createSessionFile(x.id,b.trim()),await Ye()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${F}`)}},[x.id,Ye]),ld=d.useCallback(async()=>{const b=window.prompt("New folder name (e.g. src/components):");if(!(!b||!b.trim()))try{await K.createSessionDirectory(x.id,b.trim()),await Ye()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${F}`)}},[x.id,Ye]),Xo=d.useCallback(async()=>{try{const b=await K.previewChanges(x.id,"preview current changes");zs(b)}catch{}},[x.id]),cd=d.useCallback(()=>{zs(null),Ye()},[Ye]),hd=d.useCallback(b=>{zs(null),Ye()},[Ye]),dd=d.useCallback(()=>{zs(null)},[]),Jo=s?jh(x.files,s):void 0,ud=((Qo=n.split(".").pop())==null?void 0:Qo.toUpperCase())||"",{showHelp:fd,setShowHelp:Zo}=yx({onToggleBuild:()=>{Ge&&$o()}}),md=d.useMemo(()=>[{id:"preview",label:"Open Preview",category:"command",icon:ys,action:()=>g("preview"),shortcut:""},{id:"code",label:"Open Code Editor",category:"command",icon:Qr,action:()=>g("code")},{id:"terminal",label:"Open Terminal",category:"command",icon:es,action:()=>ae(!0)},{id:"dashboard",label:"Open Dashboard",category:"command",icon:jr,action:()=>g("dashboard")},{id:"deploy",label:"Deploy Project",category:"command",icon:$t,action:()=>g("deploy")},{id:"git",label:"Git Status",category:"command",icon:ze,action:()=>g("git")},{id:"settings",label:"Settings / Config",category:"setting",icon:ra,action:()=>g("config")},{id:"quick-open",label:"Quick Open File",category:"file",icon:Z,action:()=>{W(!0),U("")},shortcut:"Cmd+P"},{id:"zen",label:"Toggle Zen Mode",category:"setting",icon:nn,action:()=>J()},{id:"sidebar",label:"Toggle File Tree",category:"setting",icon:na,action:()=>B(b=>!b)},{id:"preview-changes",label:"Preview Pending Changes",category:"command",icon:ze,action:()=>Xo()},{id:"insights",label:"Build Insights",category:"command",icon:Zr,action:()=>g("insights")},{id:"nl-search",label:"Natural Language Search",category:"command",icon:ts,action:()=>As(!0)}],[g,J,Xo]),ji=d.useMemo(()=>{if(!Ge)return"idle";const b=(ce.phase||x.status||"").toLowerCase();return b.includes("plan")||b.includes("bootstrap")?"planning":b.includes("review")||b.includes("council")?"reviewing":b.includes("test")||b.includes("verify")?"testing":b.includes("complete")||b.includes("fulfilled")?"complete":"building"},[Ge,ce.phase,x.status]);return r.jsxs("div",{className:"flex flex-col h-full relative",children:[r.jsxs("div",{className:"bg-card px-3 py-2 flex items-center gap-3 flex-shrink-0 border-b border-border",children:[r.jsx("button",{onClick:()=>{p&&!window.confirm("Unsaved changes. Discard?")||t()},className:"text-xs font-medium px-3 py-1.5 rounded-btn border border-border text-muted hover:text-ink hover:bg-hover transition-colors",children:"Back"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h2",{className:"text-sm font-bold text-ink truncate",children:x.id}),r.jsx("p",{className:"text-xs font-mono text-muted-accessible truncate",children:x.path})]}),r.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${x.status==="completed"||x.status==="completion_promise_fulfilled"?"bg-success/10 text-success":"bg-muted/10 text-muted"}`,children:x.status}),Do.length>=2&&r.jsx("div",{className:"flex items-center gap-1 border-l border-border pl-2 ml-1",children:r.jsx(Xx,{tokenHistory:Do})}),r.jsxs("div",{className:"flex items-center gap-0.5 border-l border-border pl-2 ml-1",children:[r.jsx("button",{onClick:()=>B(b=>!b),title:C?"Hide file tree":"Show file tree",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:C?r.jsx(na,{size:16}):r.jsx(Cu,{size:16})}),r.jsx("button",{onClick:()=>ae(b=>!b),title:X?"Hide terminal/chat":"Show terminal/chat",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:X?r.jsx(bu,{size:16}):r.jsx(Su,{size:16})}),r.jsx("button",{onClick:J,title:q?"Exit zen mode":"Zen mode (hide all panels)",className:`p-1.5 rounded hover:bg-hover transition-colors ${q?"text-primary":"text-muted hover:text-ink"}`,children:q?r.jsx(nc,{size:16}):r.jsx(nn,{size:16})})]}),!Ge&&r.jsx(ue,{variant:"primary",size:"sm",icon:It,onClick:()=>{if(!(x.prd||"").trim()){window.alert("No PRD found for this project. Go to Home to start a new build.");return}xi(!0)},title:"Start build for this project",children:"Build"}),!Ge&&ji==="complete"&&r.jsx(ue,{variant:"ghost",size:"sm",icon:rn,onClick:()=>vr(!0),title:"Replay the build timeline",children:"Replay Build"}),r.jsx(Pt,{icon:ts,label:"Natural language search",size:"sm",onClick:()=>As(!0)}),Ge&&r.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[us?r.jsx(ue,{variant:"ghost",size:"sm",icon:It,onClick:qh,title:"Resume build",children:"Resume"}):r.jsx(ue,{variant:"ghost",size:"sm",icon:Yl,onClick:Kh,title:"Pause build",children:"Pause"}),r.jsx(ue,{variant:"danger",size:"sm",icon:Zi,onClick:$o,title:"Stop build",children:"Stop"})]}),r.jsx(Pt,{icon:ys,label:"Review project",size:"sm",onClick:ki,disabled:!!(_e!=null&&_e.loading)}),r.jsx(Pt,{icon:si,label:"Run tests",size:"sm",onClick:Ni,disabled:!!(_e!=null&&_e.loading)}),r.jsx(Pt,{icon:Jr,label:"Explain project",size:"sm",onClick:wr,disabled:!!(_e!=null&&_e.loading)}),r.jsx(ue,{variant:"secondary",size:"sm",icon:$t,onClick:()=>g("deploy"),title:"Deploy project",children:"Deploy"}),r.jsx(wx,{onClick:()=>Zo(!0)})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1",children:r.jsx(hx,{phase:ji,iteration:ce.iteration,maxIterations:ce.maxIterations,cost:ce.cost,startTime:ce.startTime,isRunning:Ge})}),Ge&&r.jsx("div",{className:"flex-shrink-0 pr-2",children:r.jsx(yv,{gatePassRate:.8,testCoverage:ce.iteration>2?60:20,iteration:ce.iteration,maxIterations:ce.maxIterations,phase:ji,compact:!0})})]}),r.jsx(Ax,{sessionId:x.id,onRestore:Ye}),r.jsx("div",{className:"flex-1 min-h-0",children:r.jsxs(ln,{orientation:"vertical",children:[r.jsx(Xs,{defaultSize:70,minSize:40,children:r.jsxs(ln,{orientation:"horizontal",className:"h-full",children:[C&&r.jsx(Xs,{defaultSize:20,minSize:15,children:r.jsxs("div",{className:"h-full flex flex-col border-r border-border bg-card",children:[r.jsxs("div",{className:"flex items-center border-b border-border flex-shrink-0",children:[r.jsxs("button",{onClick:()=>Ro("files"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${vi==="files"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(io,{size:14}),"Files",at&&r.jsx("span",{className:"ml-1 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),r.jsxs("button",{onClick:()=>Ro("chat"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${vi==="chat"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(Kl,{size:14}),"Chat"]}),vi==="files"&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[r.jsxs("button",{onClick:ad,title:"New File",className:"flex items-center gap-1 text-xs text-muted-accessible hover:text-primary px-2.5 py-1 rounded border border-border hover:border-primary/30 transition-colors",children:[r.jsx(dr,{size:12})," New"]}),r.jsxs("button",{onClick:ld,title:"New Folder",className:"flex items-center gap-1 text-xs text-muted-accessible hover:text-primary px-2.5 py-1 rounded border border-border hover:border-primary/30 transition-colors",children:[r.jsx(Dd,{size:12})," New"]})]})]}),vi==="files"?r.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:x.files.length>0?r.jsx(Rh,{nodes:x.files,selectedPath:s,onSelect:Rt,onDelete:Cr,onContextMenu:ed}):r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(tn,{size:28,className:"text-muted/40 mb-2"}),r.jsx("p",{className:"text-xs text-muted font-medium",children:"No files yet"}),r.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Start a build to generate your project."})]})}):r.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:r.jsx("div",{className:"flex-1 min-h-0",children:r.jsx(vv,{sessionId:x.id,defaultMode:D})})})]})}),C&&r.jsx(cn,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),r.jsx(Xs,{defaultSize:80,minSize:40,children:r.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[r.jsx("div",{className:"flex items-center border-b border-border bg-hover px-1 flex-shrink-0",role:"tablist",children:[{id:"code",label:"Code",icon:Qr},{id:"preview",label:"Preview",icon:ys},{id:"deploy",label:"Deploy",icon:$t},{id:"config",label:"Config",icon:ra},{id:"secrets",label:"Secrets",icon:fu},{id:"prd",label:"PRD",icon:cr},{id:"dashboard",label:"Dashboard",icon:jr},{id:"git",label:"Git",icon:ze},{id:"cicd",label:"CI/CD",icon:ze},{id:"insights",label:"Insights",icon:Zr}].map(b=>r.jsxs("button",{role:"tab","aria-selected":f===b.id,onClick:()=>g(b.id),className:`flex items-center gap-1.5 px-4 py-2 text-xs font-medium border-b-2 transition-colors ${f===b.id?"border-primary text-primary":"border-transparent text-muted hover:text-ink hover:border-border"}`,children:[r.jsx(b.icon,{size:14}),b.label]},b.id))}),r.jsxs("div",{className:"flex-1 min-h-0",role:"tabpanel",children:[f==="code"&&r.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[w.length>0&&r.jsx("div",{className:"flex items-center border-b border-border bg-hover overflow-x-auto flex-shrink-0",children:w.map(b=>r.jsxs("button",{onClick:()=>Rt(b.path,b.name),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-mono border-r border-border whitespace-nowrap transition-colors ${b.path===s?"bg-card text-ink":"text-muted hover:text-ink hover:bg-card"}`,children:[r.jsx("span",{className:"w-4 flex items-center justify-center",children:Yn(b.name,"file")}),b.name,b.modified&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),r.jsx("span",{role:"button",tabIndex:-1,title:"Close tab",onClick:I=>{I.stopPropagation(),Go(b.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),Go(b.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:r.jsx(ft,{size:12})})]},b.path))}),s?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-hover",children:[r.jsx("span",{className:"text-xs font-mono text-secondary truncate",children:s}),v&&r.jsx("span",{className:"text-xs text-primary animate-pulse flex-shrink-0",children:"Saving..."}),r.jsx("span",{className:"ml-auto text-xs text-muted/50 font-mono",children:Jo!=null?Eh(Jo):""}),r.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:ud}),p&&r.jsx("button",{onClick:kr,className:"text-xs font-medium px-2 py-0.5 rounded border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors",children:"Save"})]}),Bs===s&&r.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-warning/10",children:[r.jsx(Ct,{size:12,className:"text-warning"}),r.jsx("span",{className:"text-xs text-warning font-medium",children:"File changed externally"}),r.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[r.jsx("button",{onClick:Yh,className:"text-xs font-medium px-2 py-0.5 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors",children:"Reload"}),r.jsx("button",{onClick:()=>gi(null),className:"text-xs font-medium px-2 py-0.5 rounded border border-border text-muted hover:text-ink hover:bg-hover transition-colors",children:"Dismiss"})]})]}),r.jsx("div",{className:"flex-1 min-h-0",children:u?r.jsx(Cd,{}):r.jsx($i,{name:"Editor",children:r.jsx(Zf,{value:h??"",language:zv(n),theme:"vs",onChange:nd,onMount:od,options:{minimap:{enabled:!1},fontSize:13,lineNumbers:"on",wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0,padding:{top:8},renderLineHighlight:"line",smoothScrolling:!0,cursorBlinking:"smooth",folding:!0,bracketPairColorization:{enabled:!0}}})})}),r.jsx(ev,{selectedFile:s,fileName:n,isModified:p,isSaving:v,lastSavedAt:zh,lineCount:$h,cursorLine:Mo.line,cursorColumn:Mo.column,buildTime:ce.phase==="complete"&&ce.startTime?Math.floor((Date.now()-ce.startTime)/1e3):void 0,sessionId:x.id,prd:x.prd})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center p-8",children:[r.jsx(Z,{size:32,className:"text-muted/30 mb-3"}),r.jsx("p",{className:"text-sm text-muted",children:"Select a file to view its contents"}),r.jsxs("p",{className:"text-xs text-muted/60 mt-1",children:["Use the file tree or press ",r.jsx("kbd",{className:"px-1.5 py-0.5 text-[10px] font-mono bg-hover border border-border rounded",children:"Cmd+P"})," to quick open"]})]})]}),f==="preview"&&r.jsx($i,{name:"Preview",children:r.jsxs("div",{className:`h-full flex flex-col ${To?"preview-fullscreen":""}`,children:[r.jsx("div",{className:"px-3 py-1.5 border-b border-border flex items-center gap-2 bg-hover flex-shrink-0",children:$!=null&&$.running||se!=null&&se.preview_url?r.jsxs(r.Fragment,{children:[r.jsx(Pt,{icon:kd,label:"Back",size:"sm",onClick:td,disabled:xt<=0}),r.jsx(Pt,{icon:Jn,label:"Forward",size:"sm",onClick:sd,disabled:xt>=wi.length-1}),r.jsx(cv,{onClick:()=>{yr(!0),L(b=>b+1)}}),r.jsx("input",{value:Vo,onChange:b=>Sr(b.target.value),onKeyDown:b=>{b.key==="Enter"&&id(Vo)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx(tv,{selectedDevice:Ih,onDeviceChange:Fh,containerWidth:Uh}),r.jsx(rv,{zoom:br,onZoomChange:Hh}),r.jsx(av,{url:vt}),r.jsx(ov,{}),r.jsx(hv,{url:vt}),r.jsx(Pt,{icon:ss,label:"Open in new tab",size:"sm",onClick:()=>window.open(vt,"_blank")}),r.jsx(lv,{isFullscreen:To,onToggle:()=>Wh(b=>!b)}),($==null?void 0:$.running)&&r.jsxs("button",{onClick:Xh,className:"flex items-center gap-1 px-2 py-1 text-xs font-medium rounded border border-danger/40 bg-danger/10 text-danger hover:bg-danger/20 transition-colors",children:[r.jsx(Zi,{size:12}),"Stop"]})]}):se?r.jsx("div",{className:"flex-1 flex items-center gap-2 text-sm text-muted",children:r.jsx("span",{className:"font-medium text-ink",children:se.description})}):r.jsx("div",{className:"flex-1 flex items-center text-sm text-muted",children:"Detecting project type..."})}),$&&$.status!=="stopped"&&r.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs flex-shrink-0 ${$.running?"bg-green-50 border-green-200 text-green-700":$.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":$.status==="error"?"bg-red-50 border-red-200 text-red-700":"bg-gray-50 border-border text-muted"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${$.running?"bg-green-500":$.status==="starting"?"bg-yellow-500 animate-pulse":$.status==="error"?"bg-red-500":"bg-gray-400"}`}),$.running&&$.portless_url&&r.jsxs("span",{children:["Running at ",$.portless_url]}),$.running&&$.port&&!$.portless_url&&r.jsxs("span",{children:["Running on port ",$.port]}),$.status==="starting"&&r.jsx("span",{children:"Starting dev server..."}),$.status==="error"&&!$.auto_fix_status&&r.jsx("span",{children:"Dev server crashed"}),$.status==="error"&&$.auto_fix_status&&r.jsxs("span",{children:["Auto-fixing: ",$.auto_fix_status]}),$.command&&r.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:$.command})]}),$!=null&&$.running?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[bi&&r.jsx(Bl,{}),r.jsx("div",{ref:ms,className:`flex-1 bg-white overflow-auto flex justify-center ${bi?"hidden":""}`,children:r.jsx("div",{className:`${Bo} h-full preview-zoom-${br}`,children:r.jsx("iframe",{ref:M,src:vt,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{yr(!1),ms.current&&Ao(ms.current.clientWidth)}},E)})}),r.jsx(Ll,{messages:zo})]}):se!=null&&se.preview_url?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[bi&&r.jsx(Bl,{}),r.jsx("div",{ref:ms,className:`flex-1 bg-white overflow-auto flex justify-center ${bi?"hidden":""}`,children:r.jsx("div",{className:`${Bo} h-full preview-zoom-${br}`,children:r.jsx("iframe",{ref:M,src:vt,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{yr(!1),ms.current&&Ao(ms.current.clientWidth)}},E)})}),r.jsx(Ll,{messages:zo})]}):se?r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:se.type==="api"||se.type==="python-api"?r.jsx($d,{size:28,className:"text-primary"}):se.type==="library"?r.jsx(Xl,{size:28,className:"text-primary"}):se.type==="go-app"||se.type==="rust-app"?r.jsx(es,{size:28,className:"text-primary"}):r.jsx(tn,{size:28,className:"text-primary"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-heading text-ink mb-1",children:se.type.replace(/-/g," ").replace(/\b\w/g,b=>b.toUpperCase())}),r.jsx("p",{className:"text-sm text-muted",children:se.description})]}),r.jsxs("div",{className:"card p-4 max-w-md w-full space-y-3",children:[se.dev_command&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Dev Server"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("code",{className:"text-sm font-mono text-primary bg-hover px-3 py-2 rounded-btn flex-1 text-left truncate",children:se.dev_command}),r.jsxs("button",{onClick:()=>ps(se.dev_command||void 0),disabled:Os,className:"flex items-center gap-1.5 px-3 py-2 text-xs font-medium rounded-btn bg-primary text-white hover:bg-primary/90 transition-colors disabled:opacity-50",children:[r.jsx(It,{size:12}),Os?"Starting...":"Start"]})]})]}),r.jsxs("div",{className:se.dev_command?"pt-2 border-t border-border":"",children:[r.jsx("p",{className:"text-xs text-muted mb-2",children:se.dev_command?"Or use a custom command:":"Start a dev server:"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:Kt,onChange:b=>Gh(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Kt.trim()&&ps(Kt.trim())},placeholder:"e.g. npm run dev",className:"flex-1 px-3 py-1.5 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx("button",{onClick:()=>Kt.trim()&&ps(Kt.trim()),disabled:Os||!Kt.trim(),className:"px-3 py-1.5 text-xs font-medium rounded-btn border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-50",children:"Run"})]})]})]}),Uo&&r.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[r.jsx("p",{className:"text-xs text-danger font-medium mb-1",children:"Dev server error"}),r.jsx("p",{className:"text-xs text-danger/80",children:Uo})]}),($==null?void 0:$.status)==="error"&&r.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs text-danger font-medium",children:"Dev server crashed"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:Jh,disabled:Ho,className:"text-xs px-2 py-1 rounded border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-50",children:Ho?"Fixing...":"Fix Error"}),r.jsx("button",{onClick:()=>ps(se.dev_command||Kt||void 0),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]})]}),$.auto_fix_status&&r.jsxs("div",{className:"flex items-center gap-2 mb-2 px-2 py-1 rounded bg-primary/5 border border-primary/20",children:[r.jsx("div",{className:"w-2 h-2 rounded-full bg-primary animate-pulse"}),r.jsxs("span",{className:"text-[11px] text-primary font-medium",children:["Auto-fix: ",$.auto_fix_status]}),$.auto_fix_attempts!==void 0&&$.auto_fix_attempts>0&&r.jsxs("span",{className:"text-[10px] text-muted ml-auto",children:["Attempt ",$.auto_fix_attempts,"/3"]})]}),$.output.length>0&&r.jsx("pre",{className:"text-[11px] font-mono text-danger/70 bg-danger/5 p-2 rounded max-h-32 overflow-y-auto whitespace-pre-wrap",children:$.output.slice(-10).join(`
|
|
285
|
+
group cursor-pointer`,children:[r.jsx(Z,{size:14,className:N(w.path)}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs font-medium text-ink group-hover:text-primary transition-colors truncate",children:w.name}),r.jsx("div",{className:"text-[11px] text-muted font-mono truncate",children:w.path}),w.matchContext&&r.jsx("div",{className:"text-[11px] text-secondary mt-0.5 truncate font-mono",children:w.matchContext})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[w.lineNumber&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-muted font-mono",children:[r.jsx(cu,{size:10}),w.lineNumber]}),r.jsx(Jn,{size:12,className:"text-muted group-hover:text-primary transition-colors"})]})]},`${w.path}-${R}`))]})})]})}const or={claude:{input:.003,output:.015,label:"Claude (Sonnet)"},codex:{input:.002,output:.008,label:"Codex (GPT-4o)"},gemini:{input:.00125,output:.005,label:"Gemini Pro"}},ar={simple:{tokens:5e4,label:"Simple",iters:3},standard:{tokens:15e4,label:"Standard",iters:8},complex:{tokens:4e5,label:"Complex",iters:15}};function Lv(e,t,s){const i=or[t]||or.claude,n=ar[e]||ar.standard,o=s||n.iters,a=[{phase:"planning",label:"Planning",pct:.15},{phase:"building",label:"Building",pct:.55},{phase:"testing",label:"Testing",pct:.2},{phase:"reviewing",label:"Review",pct:.1}],l=n.tokens*(o/n.iters),h=Math.round(l),c=a.map(p=>{const _=Math.round(h*p.pct),v=_*.4,y=_*.6,x=(v*i.input+y*i.output)/1e3;return{phase:p.phase,label:p.label,estimatedCost:x,estimatedTokens:_}}),u=c.reduce((p,_)=>p+_.estimatedCost,0),f=o*(e==="complex"?40:e==="simple"?15:25),g=f<60?`${f}s`:f<3600?`${Math.round(f/60)}min`:`${(f/3600).toFixed(1)}hr`;return{total:{low:u*.7,high:u*1.4},breakdown:c,totalTokens:h,estimatedTime:g}}function Ol(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:String(e)}function Bv({complexity:e,provider:t,templateType:s,estimatedIterations:i,onConfirm:n,onCancel:o,historicalAvgCost:a}){const[l,h]=d.useState(!1),c=Lv(e,t,i),u=or[t]||or.claude,m=ar[e]||ar.standard,f=c.total.high>5;return r.jsxs("div",{className:"card overflow-hidden max-w-md mx-auto",children:[r.jsxs("div",{className:"px-5 pt-5 pb-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Jl,{size:18,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Build Cost Estimate"})]}),r.jsx("p",{className:"text-xs text-muted",children:"Estimated cost before starting your build"})]}),r.jsxs("div",{className:"px-5 py-4",children:[r.jsxs("div",{className:"text-center mb-4",children:[r.jsxs("div",{className:"text-3xl font-bold font-mono text-ink tracking-tight",children:["$",c.total.low.toFixed(2)," -- $",c.total.high.toFixed(2)]}),r.jsx("p",{className:"text-xs text-muted mt-1",children:"Estimated total cost"})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(Zt,{size:14,className:"text-primary mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:Ol(c.totalTokens)}),r.jsx("div",{className:"text-[11px] text-muted",children:"Tokens"})]}),r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(nt,{size:14,className:"text-info mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:c.estimatedTime}),r.jsx("div",{className:"text-[11px] text-muted",children:"Est. Time"})]}),r.jsxs("div",{className:"bg-hover/50 rounded-card px-2 py-2",children:[r.jsx(Zt,{size:14,className:"text-warning mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:i||m.iters}),r.jsx("div",{className:"text-[11px] text-muted",children:"Iterations"})]})]})]}),r.jsxs("div",{className:"px-5 py-2 bg-hover/30 border-t border-b border-border",children:[r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsx("span",{className:"text-muted",children:"Provider"}),r.jsx("span",{className:"font-medium text-ink",children:u.label})]}),r.jsxs("div",{className:"flex items-center justify-between text-xs mt-1",children:[r.jsx("span",{className:"text-muted",children:"Complexity"}),r.jsx("span",{className:"font-medium text-ink",children:m.label})]}),s&&r.jsxs("div",{className:"flex items-center justify-between text-xs mt-1",children:[r.jsx("span",{className:"text-muted",children:"Template"}),r.jsx("span",{className:"font-medium text-ink",children:s})]})]}),a!==void 0&&a>0&&r.jsx("div",{className:"px-5 py-2.5 bg-primary/5 border-b border-border",children:r.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[r.jsx(Td,{size:12,className:"text-primary"}),r.jsxs("span",{className:"text-secondary",children:["Similar projects cost ",r.jsxs("span",{className:"font-mono font-semibold text-ink",children:["$",a.toFixed(2)]})," on average"]})]})}),r.jsxs("div",{className:"px-5 py-2",children:[r.jsxs("button",{onClick:()=>h(!l),className:"flex items-center gap-1.5 w-full text-xs font-medium text-primary py-1.5",children:[l?r.jsx(lr,{size:12}):r.jsx(ls,{size:12}),"Cost breakdown by phase"]}),l&&r.jsx("div",{className:"space-y-2 mt-1 mb-2",children:c.breakdown.map(g=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-secondary",children:g.label}),r.jsxs("span",{className:"text-[11px] text-muted font-mono",children:[Ol(g.estimatedTokens)," tokens"]})]}),r.jsxs("span",{className:"text-xs font-mono font-semibold text-ink",children:["$",g.estimatedCost.toFixed(2)]})]},g.phase))})]}),f&&r.jsx("div",{className:"px-5 py-2 bg-warning/8 border-t border-warning/15",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ot,{size:14,className:"text-warning mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-xs text-secondary",children:"This build may be expensive. Consider using a simpler complexity level or a more cost-effective provider."})]})}),r.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border",children:[r.jsx(ue,{variant:"ghost",size:"sm",onClick:o,children:"Cancel"}),r.jsx(ue,{variant:"primary",size:"sm",onClick:n,icon:Zt,children:"Start Build"})]})]})}function Tv({sessionId:e}){return r.jsx(kh,{sessionId:e})}function Yn(e,t,s){var o;if(t==="directory")return s?r.jsx(tn,{size:14}):r.jsx(io,{size:14});const i=((o=e.split(".").pop())==null?void 0:o.toLowerCase())||"";return{js:r.jsx(Z,{size:14,className:"text-yellow-600"}),ts:r.jsx(Z,{size:14,className:"text-blue-500"}),tsx:r.jsx(Z,{size:14,className:"text-blue-400"}),jsx:r.jsx(Z,{size:14,className:"text-yellow-500"}),py:r.jsx(Z,{size:14,className:"text-green-600"}),html:r.jsx(sc,{size:14,className:"text-orange-500"}),css:r.jsx(to,{size:14,className:"text-purple-500"}),json:r.jsx(eo,{size:14,className:"text-green-500"}),md:r.jsx(cr,{size:14,className:"text-muted"}),go:r.jsx(Z,{size:14,className:"text-cyan-600"}),rs:r.jsx(Z,{size:14,className:"text-orange-600"}),rb:r.jsx(Z,{size:14,className:"text-red-500"}),sh:r.jsx(Z,{size:14,className:"text-green-600"})}[i]||r.jsx(so,{size:14})}function zv(e){var n;const t=((n=e.split(".").pop())==null?void 0:n.toLowerCase())||"",s={js:"javascript",jsx:"javascript",ts:"typescript",tsx:"typescript",py:"python",html:"html",htm:"html",css:"css",scss:"scss",less:"less",json:"json",md:"markdown",go:"go",rs:"rust",sh:"shell",bash:"shell",yml:"yaml",yaml:"yaml",xml:"xml",svg:"xml",sql:"sql",java:"java",kt:"kotlin",rb:"ruby",dockerfile:"dockerfile"},i=e.toLowerCase();return i==="dockerfile"?"dockerfile":i==="makefile"?"makefile":s[t]||"plaintext"}function jh(e,t){for(const s of e){if(s.path===t)return s.size;if(s.children){const i=jh(s.children,t);if(i!==void 0)return i}}}function Eh(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Rh({nodes:e,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o=0}){const[a,l]=d.useState(()=>{const h=new Set;return o<2&&e.filter(c=>c.type==="directory").forEach(c=>h.add(c.path)),h});return r.jsx("div",{role:o===0?"tree":"group",children:e.map(h=>{const c=h.type==="directory",u=a.has(h.path),m=h.path===t;return r.jsxs("div",{className:"group/file",children:[r.jsxs("button",{role:"treeitem","aria-label":h.name,"aria-selected":m,...c?{"aria-expanded":u}:{},onContextMenu:f=>{f.preventDefault(),n==null||n(f,h.path,h.name,h.type)},onClick:()=>{c?l(f=>{const g=new Set(f);return g.has(h.path)?g.delete(h.path):g.add(h.path),g}):s(h.path,h.name)},className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded transition-colors ${m?"bg-primary/10 text-primary":"text-ink/70 hover:bg-hover"}`,style:{paddingLeft:`${o*14+8}px`},children:[c?r.jsx("span",{className:"w-3 flex items-center justify-center flex-shrink-0 text-muted",children:u?r.jsx(ls,{size:14}):r.jsx(hr,{size:14})}):r.jsx("span",{className:"w-3 flex-shrink-0"}),r.jsx("span",{className:`w-5 flex items-center justify-center flex-shrink-0 ${c?"text-primary":""}`,children:Yn(h.name,h.type,u)}),r.jsxs("span",{className:"truncate",children:[h.name,c?"/":""]}),!c&&h.size!=null&&h.size>0&&r.jsx("span",{className:"text-xs text-muted ml-auto flex-shrink-0",children:Eh(h.size)}),!c&&i&&r.jsx("span",{role:"button",tabIndex:-1,onClick:f=>{f.stopPropagation(),i(h.path,h.name)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),i(h.path,h.name))},className:"text-muted hover:text-danger ml-1 flex-shrink-0 opacity-0 group-hover/file:opacity-100 transition-opacity cursor-pointer",title:"Delete file",children:r.jsx(ft,{size:12})})]}),c&&u&&h.children&&r.jsx(Rh,{nodes:h.children,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o+1})]},h.path)})})}function Dh(e,t=""){const s=[];for(const i of e)i.type==="file"&&s.push({path:i.path,name:i.name}),i.children&&s.push(...Dh(i.children,i.path+"/"));return s}function Av(){const[e,t]=d.useState({}),[s,i]=d.useState(""),[n,o]=d.useState(""),[a,l]=d.useState(!0),[h,c]=d.useState(null),[u,m]=d.useState(new Set),f=d.useCallback(async()=>{try{const y=await K.getSecrets();t(y)}catch{}l(!1)},[]);d.useEffect(()=>{f()},[f]);const g=async()=>{const y=s.trim();if(y){if(!/^[A-Z_][A-Z0-9_]*$/.test(y)){c("Key must be a valid ENV_VAR name (uppercase letters, digits, underscores)");return}c(null);try{await K.setSecret(y,n),i(""),o(""),await f()}catch(x){c(x instanceof Error?x.message:"Failed to set secret")}}},p=async y=>{if(window.confirm(`Delete secret "${y}"?`))try{await K.deleteSecret(y),await f()}catch(x){c(x instanceof Error?x.message:"Failed to delete secret")}},_=y=>{m(x=>{const k=new Set(x);return k.has(y)?k.delete(y):k.add(y),k})},v=Object.keys(e);return a?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(Nr,{variant:"text",width:"180px",height:"16px"}),r.jsx(Nr,{variant:"block",width:"100%",height:"60px"}),r.jsx(Nr,{variant:"block",width:"100%",height:"80px"})]}):r.jsx("div",{className:"h-full flex flex-col",children:r.jsxs("div",{className:"p-6 overflow-y-auto",children:[r.jsx("h3",{className:"text-h3 font-heading text-ink mb-2",children:"Environment Secrets"}),r.jsxs("div",{className:"flex items-start gap-2 px-4 py-3 rounded-btn border border-warning/30 bg-warning/5 mb-6",children:[r.jsx(Ot,{size:16,className:"text-warning flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-xs text-warning leading-relaxed",children:"Secrets are stored locally in plaintext and injected as environment variables during builds. They are never committed to the project repository."})]}),v.length>0&&r.jsx("div",{className:"card mb-6",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-border",children:[r.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Key"}),r.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Value"}),r.jsx("th",{className:"w-20 px-4 py-2"})]})}),r.jsx("tbody",{children:v.map(y=>r.jsxs("tr",{className:"border-b border-border last:border-b-0",children:[r.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-ink",children:y}),r.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-muted-accessible",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{children:u.has(y)?e[y]:"***"}),r.jsx("button",{onClick:()=>_(y),className:"text-muted hover:text-ink transition-colors",title:u.has(y)?"Hide value":"Show value",children:u.has(y)?r.jsx(Bd,{size:14}):r.jsx(ys,{size:14})})]})}),r.jsx("td",{className:"px-4 py-2.5 text-right",children:r.jsx("button",{onClick:()=>p(y),className:"text-muted hover:text-danger transition-colors",title:"Delete secret",children:r.jsx(Qn,{size:14})})})]},y))})]})}),v.length===0&&r.jsx("div",{className:"card p-4 mb-6",children:r.jsx("p",{className:"text-sm text-muted-accessible text-center py-4",children:"No secrets configured yet. Add your first secret below."})}),r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-3",children:"Add Secret"}),h&&r.jsx("div",{className:"text-xs text-danger mb-3 px-1",children:h}),r.jsxs("div",{className:"flex items-end gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Key"}),r.jsx("input",{type:"text",value:s,onChange:y=>i(y.target.value.toUpperCase()),placeholder:"API_KEY",className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink placeholder:text-muted"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Value"}),r.jsx("input",{type:"password",value:n,onChange:y=>o(y.target.value),placeholder:"secret value",className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink placeholder:text-muted"})]}),r.jsxs("button",{onClick:g,disabled:!s.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-btn border border-primary bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[r.jsx(ur,{size:14}),"Add"]})]})]})]})})}function Ov({session:e,onClose:t}){var Qo;const[s,i]=d.useState(null),[n,o]=d.useState(""),[a,l]=d.useState(null),[h,c]=d.useState(null),[u,m]=d.useState(!1),[f,g]=d.useState("code"),[p,_]=d.useState(!1),[v,y]=d.useState(!1),[x,k]=d.useState(e),N=d.useRef(null),[w,R]=d.useState([]),[T,W]=d.useState(!1),[G,U]=d.useState(""),A=d.useRef(null),M=d.useRef(null),[E,L]=d.useState(0),[S,j]=d.useState(null),[C,B]=d.useState(!0),[X,ae]=d.useState(!0),[q,Q]=d.useState(!1),[ie,he]=d.useState("overview"),de=57374,[z,V]=d.useState(null),J=d.useCallback(()=>{Q(b=>{const I=!b;return B(!I),ae(!I),I})},[]),[D,le]=d.useState(()=>sessionStorage.getItem(`pl_buildmode_${x.id}`)||"standard"),[ge,Ee]=d.useState(()=>sessionStorage.getItem(`pl_provider_${x.id}`)||"claude"),[ee,fe]=d.useState(null),[_e,Ce]=d.useState(null),[Ge,Ls]=d.useState(!1),[us,et]=d.useState(!1),[ce,ot]=d.useState({phase:"idle",iteration:0,maxIterations:10,cost:0,startTime:0}),[at,fs]=d.useState(!1),[Bs,gi]=d.useState(null),Ts=d.useRef(null),[Ph,No]=d.useState(!1),[Mh,jo]=d.useState([]),[Eo,zs]=d.useState(null),[Lh,vr]=d.useState(!1),[Bh,xi]=d.useState(!1),[Th,As]=d.useState(!1),[vi,Ro]=d.useState("files"),{history:Do,recordTokens:Po}=Jx(),[zh,Ah]=d.useState(null),[Mo,Oh]=d.useState({line:1,column:1}),[$h,Lo]=d.useState(0),{device:Ih,setDevice:Fh,frameClass:Bo}=sv(),[br,Hh]=d.useState(100),[To,Wh]=d.useState(!1),[bi,yr]=d.useState(!1),[zo,Iv]=d.useState([]),ms=d.useRef(null),[Uh,Ao]=d.useState(0),{subscribe:Oo}=wd(),Ye=d.useCallback(async()=>{try{const b=await K.getSessionDetail(x.id);k(b)}catch{}},[x.id]),$o=d.useCallback(async()=>{try{await K.stopSession(),Ls(!1),et(!1)}catch{}},[]),Kh=d.useCallback(async()=>{try{await K.pauseSession(),et(!0)}catch{}},[]),qh=d.useCallback(async()=>{try{await K.resumeSession(),et(!1)}catch{}},[]),Io=d.useRef("idle");d.useEffect(()=>{const b=async()=>{try{const F=await K.getStatus();Ls(F.running),et(F.paused),F.provider&&Ee(F.provider);const te=F.phase||"idle";if(te!==Io.current&&te!=="idle"){const Xe=new Date().toISOString(),Dt={starting:"Initialising build session",planning:"Planning phase started",building:"Building your project",testing:"Running tests",reviewing:"Reviewing code quality",complete:"Build complete"},bt={starting:"Setting up the build environment and checking prerequisites...",planning:"Analyzing requirements and designing the architecture...",building:"Writing code and creating project files...",testing:"Running test suite to verify everything works...",reviewing:"Checking code quality and best practices...",complete:"All done. Your project is ready."},Is=[{id:`phase-${Date.now()}`,type:"phase_change",message:Dt[te]||`Phase: ${te}`,timestamp:Xe}];bt[te]&&Is.push({id:`narration-${Date.now()}`,type:"narration",message:bt[te],timestamp:Xe}),jo(Ei=>[...Ei,...Is]),Io.current=te}ot({phase:te,iteration:F.iteration||0,maxIterations:F.max_iterations||10,cost:F.cost||0,startTime:F.start_time?F.start_time*1e3:0});const Ke=F.tokens_used;Ke!=null&&Po(Ke)}catch{}};b();const I=setInterval(b,Ge?3e3:1e4);return()=>clearInterval(I)},[Ge,Po]),d.useEffect(()=>{if(!(_e!=null&&_e.loading))return;const b=setInterval(()=>{Ce(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(b)},[_e==null?void 0:_e.loading]);const[se,Vh]=d.useState(null);d.useEffect(()=>{K.getPreviewInfo(x.id).then(Vh).catch(()=>{})},[x.id]);const[$,yi]=d.useState(null),[Os,Fo]=d.useState(!1),[Ho,Wo]=d.useState(!1),[Uo,Si]=d.useState(null),[Kt,Gh]=d.useState("");d.useEffect(()=>{const b=Oo("file_changed",I=>{const F=I;if(!F.paths||F.paths.length===0)return;const te=new Date().toISOString(),Ke=F.paths.map((Xe,Dt)=>{var Ei;const bt=(Ei=F.event_types)==null?void 0:Ei[Dt],Is=bt==="created"||bt==="IN_CREATE";return{id:`file-${Date.now()}-${Dt}`,type:Is?"file_created":"file_modified",message:Is?`Created ${Xe.split("/").pop()}`:`Modified ${Xe.split("/").pop()}`,timestamp:te,filePath:Xe}});if(jo(Xe=>[...Xe,...Ke]),fs(!0),Ts.current&&clearTimeout(Ts.current),Ts.current=setTimeout(()=>fs(!1),2e3),Ye(),s&&F.paths.some(Dt=>Dt===s||s.endsWith(Dt))&&gi(s),f==="preview"){const Xe=["react","vite","next","nuxt","svelte","remix"];($==null?void 0:$.running)&&($==null?void 0:$.framework)&&Xe.some(bt=>$.framework.toLowerCase().includes(bt))||L(bt=>bt+1)}});return()=>{b(),Ts.current&&clearTimeout(Ts.current)}},[Oo,s,f,$==null?void 0:$.running,Ye]);const Yh=d.useCallback(async()=>{if(!(!Bs||!x.id)){try{const b=await K.getSessionFileContent(x.id,Bs);l(b.content),c(b.content),_(!1),R(I=>I.map(F=>F.path===Bs?{...F,content:b.content,modified:!1}:F))}catch{}gi(null)}},[Bs,x.id]);d.useEffect(()=>{if(f!=="preview")return;let b=!1;const I=async()=>{try{const te=await K.devserver.status(x.id);b||yi(te)}catch{}};I();const F=setInterval(I,3e3);return()=>{b=!0,clearInterval(F)}},[f,x.id]),d.useEffect(()=>{f==="dashboard"&&fetch(`http://127.0.0.1:${de}/health`).then(b=>V(b.ok)).catch(()=>V(!1))},[f]);const ps=d.useCallback(async b=>{Fo(!0),Si(null);try{const I=await K.devserver.start(x.id,b);if(I.status==="error")Si(I.message||"Failed to start dev server");else{const F=await K.devserver.status(x.id);yi(F)}}catch(I){Si(I instanceof Error?I.message:"Failed to start dev server")}Fo(!1)},[x.id]),Ko=d.useRef(!1);d.useEffect(()=>{Ko.current||se!=null&&se.dev_command&&($!=null&&$.running||($==null?void 0:$.status)==="starting"||Os||(Ko.current=!0,ps(se.dev_command)))},[se==null?void 0:se.dev_command,$==null?void 0:$.running,$==null?void 0:$.status,Os,ps]);const Xh=d.useCallback(async()=>{try{await K.devserver.stop(x.id);const b=await K.devserver.status(x.id);yi(b)}catch{}},[x.id]),Jh=d.useCallback(async()=>{Wo(!0);try{const b=await K.fixProject(x.id);if(b.task_id){let F=0,te;do await new Promise(Xe=>setTimeout(Xe,2e3)),te=await K.chatPoll(x.id,b.task_id),F++;while(!te.complete&&F<150);const Ke=await K.devserver.status(x.id);yi(Ke)}}catch(b){Si(b instanceof Error?b.message:"Fix failed")}Wo(!1)},[x.id]),_s=$!=null&&$.running&&($!=null&&$.port)?$.framework==="expo"?`/api/sessions/${encodeURIComponent(x.id)}/expo-qr`:$.portless_url||`http://localhost:${$.port}/`:null,Zh=(se==null?void 0:se.preview_url)||`/api/sessions/${encodeURIComponent(x.id)}/preview/index.html`,Qh=_s||Zh,[wi,qo]=d.useState([]),[xt,Ci]=d.useState(0);d.useEffect(()=>{const b=_s||(se==null?void 0:se.preview_url);b&&(qo([b]),Ci(0))},[_s,se==null?void 0:se.preview_url]);const vt=wi[xt]||Qh,[Vo,Sr]=d.useState(vt),ed=d.useCallback((b,I,F,te)=>{b.preventDefault(),j({x:b.clientX,y:b.clientY,path:I,name:F,type:te})},[]),td=d.useCallback(()=>{xt>0&&(Ci(b=>b-1),L(b=>b+1))},[xt]),sd=d.useCallback(()=>{xt<wi.length-1&&(Ci(b=>b+1),L(b=>b+1))},[xt,wi.length]),id=d.useCallback(b=>{let I=b;if(b.startsWith("/")&&_s)try{I=`${new URL(_s).origin}${b}`}catch{const F=$==null?void 0:$.port;F&&(I=`http://localhost:${F}${b}`)}qo(F=>[...F.slice(0,xt+1),I]),Ci(F=>F+1),L(F=>F+1)},[xt,_s,$==null?void 0:$.port]);d.useEffect(()=>{try{const b=new URL(vt,window.location.origin);Sr(b.pathname+b.search+b.hash||"/")}catch{Sr(vt)}},[vt]);const ki=d.useCallback(async()=>{Ce({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.reviewProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),Ni=d.useCallback(async()=>{Ce({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.testProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),wr=d.useCallback(async()=>{Ce({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),fe(null);try{const b=await K.explainProject(x.id);fe(b.output)}catch(b){fe(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{Ce(null)}},[x.id]),Cr=d.useCallback(async(b,I)=>{if(window.confirm(`Delete "${I}"?`))try{await K.deleteSessionFile(x.id,b),s===b&&(i(null),o(""),l(null),c(null),_(!1)),await Ye()}catch(te){const Ke=te instanceof Error?te.message:"Unknown error";window.alert(`Delete failed: ${Ke}`)}},[x.id,s,Ye]),rd=d.useCallback(b=>b.type==="file"?[{label:"Review",icon:ys,onClick:()=>{ki()}},{label:"Generate Tests",icon:si,onClick:()=>{Ni()}},{label:"Explain",icon:Jr,onClick:()=>{wr()}},{label:"Delete",icon:Qn,onClick:()=>{Cr(b.path,b.name)},variant:"danger"}]:[{label:"Review Project",icon:ys,onClick:()=>{ki()}},{label:"Run Tests",icon:si,onClick:()=>{Ni()}}],[ki,Ni,wr,Cr]),Rt=d.useCallback(async(b,I)=>{gi(null),p&&s&&h!==null&&R(te=>te.map(Ke=>Ke.path===s?{...Ke,content:h,modified:!0}:Ke));const F=w.find(te=>te.path===b);if(F){i(b),o(I),l(F.content),c(F.content),_(F.modified);return}i(b),o(I),m(!0),_(!1);try{const te=x.id?await K.getSessionFileContent(x.id,b):await K.getFileContent(b);l(te.content),c(te.content),R(Ke=>[...Ke,{path:b,name:I,content:te.content,modified:!1}])}catch{l("[Error loading file]"),c("[Error loading file]")}finally{m(!1)}},[x.id,p,s,h,w]),kr=d.useCallback(async()=>{var b;if(!(!s||h===null||!x.id)){y(!0);try{await K.saveSessionFile(x.id,s,h),l(h),_(!1),Ah(Date.now()),R(F=>F.map(te=>te.path===s?{...te,content:h,modified:!1}:te));const I=((b=s.split(".").pop())==null?void 0:b.toLowerCase())||"";["html","css","js","jsx","ts","tsx"].includes(I)&&L(F=>F+1)}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Save failed: ${F}`)}finally{y(!1)}}},[s,h,x.id]),Go=d.useCallback(b=>{const I=w.find(F=>F.path===b);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(R(F=>F.filter(te=>te.path!==b)),s===b)){const F=w.filter(te=>te.path!==b);if(F.length>0){const te=F[F.length-1];i(te.path),o(te.name),l(te.content),c(te.content),_(te.modified)}else i(null),o(""),l(null),c(null),_(!1)}},[w,s]);d.useEffect(()=>{const b=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),p&&s&&kr()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),W(F=>!F),U("")),(I.metaKey||I.ctrlKey)&&I.key==="k"&&(I.preventDefault(),No(F=>!F)),I.key==="Escape"&&T&&W(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[p,s,kr,T]),d.useEffect(()=>{T&&A.current&&A.current.focus()},[T]);const Yo=Dh(x.files),$s=G?Yo.filter(b=>b.path.toLowerCase().includes(G.toLowerCase())):Yo;d.useEffect(()=>{const b=x.files.find(I=>I.name==="index.html"&&I.type==="file");b&&Rt(b.path,b.name)},[]);const nd=d.useCallback(b=>{b!==void 0&&(c(b),_(b!==a),Lo(b.split(`
|
|
286
|
+
`).length))},[a]),od=d.useCallback(b=>{N.current=b;const I=b;if(I!=null&&I.onDidChangeCursorPosition&&I.onDidChangeCursorPosition(F=>{Oh({line:F.position.lineNumber,column:F.position.column})}),I!=null&&I.getModel){const F=I.getModel();F!=null&&F.getLineCount&&Lo(F.getLineCount())}},[]),ad=d.useCallback(async()=>{const b=window.prompt("New file name (e.g. src/utils.ts):");if(!(!b||!b.trim()))try{await K.createSessionFile(x.id,b.trim()),await Ye()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${F}`)}},[x.id,Ye]),ld=d.useCallback(async()=>{const b=window.prompt("New folder name (e.g. src/components):");if(!(!b||!b.trim()))try{await K.createSessionDirectory(x.id,b.trim()),await Ye()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${F}`)}},[x.id,Ye]),Xo=d.useCallback(async()=>{try{const b=await K.previewChanges(x.id,"preview current changes");zs(b)}catch{}},[x.id]),cd=d.useCallback(()=>{zs(null),Ye()},[Ye]),hd=d.useCallback(b=>{zs(null),Ye()},[Ye]),dd=d.useCallback(()=>{zs(null)},[]),Jo=s?jh(x.files,s):void 0,ud=((Qo=n.split(".").pop())==null?void 0:Qo.toUpperCase())||"",{showHelp:fd,setShowHelp:Zo}=yx({onToggleBuild:()=>{Ge&&$o()}}),md=d.useMemo(()=>[{id:"preview",label:"Open Preview",category:"command",icon:ys,action:()=>g("preview"),shortcut:""},{id:"code",label:"Open Code Editor",category:"command",icon:Qr,action:()=>g("code")},{id:"terminal",label:"Open Terminal",category:"command",icon:es,action:()=>ae(!0)},{id:"dashboard",label:"Open Dashboard",category:"command",icon:jr,action:()=>g("dashboard")},{id:"deploy",label:"Deploy Project",category:"command",icon:$t,action:()=>g("deploy")},{id:"git",label:"Git Status",category:"command",icon:ze,action:()=>g("git")},{id:"settings",label:"Settings / Config",category:"setting",icon:ra,action:()=>g("config")},{id:"quick-open",label:"Quick Open File",category:"file",icon:Z,action:()=>{W(!0),U("")},shortcut:"Cmd+P"},{id:"zen",label:"Toggle Zen Mode",category:"setting",icon:nn,action:()=>J()},{id:"sidebar",label:"Toggle File Tree",category:"setting",icon:na,action:()=>B(b=>!b)},{id:"preview-changes",label:"Preview Pending Changes",category:"command",icon:ze,action:()=>Xo()},{id:"insights",label:"Build Insights",category:"command",icon:Zr,action:()=>g("insights")},{id:"nl-search",label:"Natural Language Search",category:"command",icon:ts,action:()=>As(!0)}],[g,J,Xo]),ji=d.useMemo(()=>{if(!Ge)return"idle";const b=(ce.phase||x.status||"").toLowerCase();return b.includes("starting")||b.includes("plan")||b.includes("bootstrap")?"planning":b.includes("review")||b.includes("council")?"reviewing":b.includes("test")||b.includes("verify")?"testing":b.includes("complete")||b.includes("fulfilled")?"complete":"building"},[Ge,ce.phase,x.status]);return r.jsxs("div",{className:"flex flex-col h-full relative",children:[r.jsxs("div",{className:"bg-card px-3 py-2 flex items-center gap-3 flex-shrink-0 border-b border-border",children:[r.jsx("button",{onClick:()=>{p&&!window.confirm("Unsaved changes. Discard?")||t()},className:"text-xs font-medium px-3 py-1.5 rounded-btn border border-border text-muted hover:text-ink hover:bg-hover transition-colors",children:"Back"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h2",{className:"text-sm font-bold text-ink truncate",children:x.id}),r.jsx("p",{className:"text-xs font-mono text-muted-accessible truncate",children:x.path})]}),r.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${x.status==="completed"||x.status==="completion_promise_fulfilled"?"bg-success/10 text-success":"bg-muted/10 text-muted"}`,children:x.status}),Do.length>=2&&r.jsx("div",{className:"flex items-center gap-1 border-l border-border pl-2 ml-1",children:r.jsx(Xx,{tokenHistory:Do})}),r.jsxs("div",{className:"flex items-center gap-0.5 border-l border-border pl-2 ml-1",children:[r.jsx("button",{onClick:()=>B(b=>!b),title:C?"Hide file tree":"Show file tree",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:C?r.jsx(na,{size:16}):r.jsx(Cu,{size:16})}),r.jsx("button",{onClick:()=>ae(b=>!b),title:X?"Hide terminal/chat":"Show terminal/chat",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:X?r.jsx(bu,{size:16}):r.jsx(Su,{size:16})}),r.jsx("button",{onClick:J,title:q?"Exit zen mode":"Zen mode (hide all panels)",className:`p-1.5 rounded hover:bg-hover transition-colors ${q?"text-primary":"text-muted hover:text-ink"}`,children:q?r.jsx(nc,{size:16}):r.jsx(nn,{size:16})})]}),!Ge&&r.jsx(ue,{variant:"primary",size:"sm",icon:It,onClick:()=>{if(!(x.prd||"").trim()){window.alert("No PRD found for this project. Go to Home to start a new build.");return}xi(!0)},title:"Start build for this project",children:"Build"}),!Ge&&ji==="complete"&&r.jsx(ue,{variant:"ghost",size:"sm",icon:rn,onClick:()=>vr(!0),title:"Replay the build timeline",children:"Replay Build"}),r.jsx(Pt,{icon:ts,label:"Natural language search",size:"sm",onClick:()=>As(!0)}),Ge&&r.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[us?r.jsx(ue,{variant:"ghost",size:"sm",icon:It,onClick:qh,title:"Resume build",children:"Resume"}):r.jsx(ue,{variant:"ghost",size:"sm",icon:Yl,onClick:Kh,title:"Pause build",children:"Pause"}),r.jsx(ue,{variant:"danger",size:"sm",icon:Zi,onClick:$o,title:"Stop build",children:"Stop"})]}),r.jsx(Pt,{icon:ys,label:"Review project",size:"sm",onClick:ki,disabled:!!(_e!=null&&_e.loading)}),r.jsx(Pt,{icon:si,label:"Run tests",size:"sm",onClick:Ni,disabled:!!(_e!=null&&_e.loading)}),r.jsx(Pt,{icon:Jr,label:"Explain project",size:"sm",onClick:wr,disabled:!!(_e!=null&&_e.loading)}),r.jsx(ue,{variant:"secondary",size:"sm",icon:$t,onClick:()=>g("deploy"),title:"Deploy project",children:"Deploy"}),r.jsx(wx,{onClick:()=>Zo(!0)})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1",children:r.jsx(hx,{phase:ji,iteration:ce.iteration,maxIterations:ce.maxIterations,cost:ce.cost,startTime:ce.startTime,isRunning:Ge})}),Ge&&r.jsx("div",{className:"flex-shrink-0 pr-2",children:r.jsx(yv,{gatePassRate:.8,testCoverage:ce.iteration>2?60:20,iteration:ce.iteration,maxIterations:ce.maxIterations,phase:ji,compact:!0})})]}),r.jsx(Ax,{sessionId:x.id,onRestore:Ye}),r.jsx("div",{className:"flex-1 min-h-0",children:r.jsxs(ln,{orientation:"vertical",children:[r.jsx(Xs,{defaultSize:70,minSize:40,children:r.jsxs(ln,{orientation:"horizontal",className:"h-full",children:[C&&r.jsx(Xs,{defaultSize:20,minSize:15,children:r.jsxs("div",{className:"h-full flex flex-col border-r border-border bg-card",children:[r.jsxs("div",{className:"flex items-center border-b border-border flex-shrink-0",children:[r.jsxs("button",{onClick:()=>Ro("files"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${vi==="files"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(io,{size:14}),"Files",at&&r.jsx("span",{className:"ml-1 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),r.jsxs("button",{onClick:()=>Ro("chat"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${vi==="chat"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(Kl,{size:14}),"Chat"]}),vi==="files"&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[r.jsxs("button",{onClick:ad,title:"New File",className:"flex items-center gap-1 text-xs text-muted-accessible hover:text-primary px-2.5 py-1 rounded border border-border hover:border-primary/30 transition-colors",children:[r.jsx(dr,{size:12})," New"]}),r.jsxs("button",{onClick:ld,title:"New Folder",className:"flex items-center gap-1 text-xs text-muted-accessible hover:text-primary px-2.5 py-1 rounded border border-border hover:border-primary/30 transition-colors",children:[r.jsx(Dd,{size:12})," New"]})]})]}),vi==="files"?r.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:x.files.length>0?r.jsx(Rh,{nodes:x.files,selectedPath:s,onSelect:Rt,onDelete:Cr,onContextMenu:ed}):r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(tn,{size:28,className:"text-muted/40 mb-2"}),r.jsx("p",{className:"text-xs text-muted font-medium",children:"No files yet"}),r.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Start a build to generate your project."})]})}):r.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:r.jsx("div",{className:"flex-1 min-h-0",children:r.jsx(vv,{sessionId:x.id,defaultMode:D})})})]})}),C&&r.jsx(cn,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),r.jsx(Xs,{defaultSize:80,minSize:40,children:r.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[r.jsx("div",{className:"flex items-center border-b border-border bg-hover px-1 flex-shrink-0",role:"tablist",children:[{id:"code",label:"Code",icon:Qr},{id:"preview",label:"Preview",icon:ys},{id:"deploy",label:"Deploy",icon:$t},{id:"config",label:"Config",icon:ra},{id:"secrets",label:"Secrets",icon:fu},{id:"prd",label:"PRD",icon:cr},{id:"dashboard",label:"Dashboard",icon:jr},{id:"git",label:"Git",icon:ze},{id:"cicd",label:"CI/CD",icon:ze},{id:"insights",label:"Insights",icon:Zr}].map(b=>r.jsxs("button",{role:"tab","aria-selected":f===b.id,onClick:()=>g(b.id),className:`flex items-center gap-1.5 px-4 py-2 text-xs font-medium border-b-2 transition-colors ${f===b.id?"border-primary text-primary":"border-transparent text-muted hover:text-ink hover:border-border"}`,children:[r.jsx(b.icon,{size:14}),b.label]},b.id))}),r.jsxs("div",{className:"flex-1 min-h-0",role:"tabpanel",children:[f==="code"&&r.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[w.length>0&&r.jsx("div",{className:"flex items-center border-b border-border bg-hover overflow-x-auto flex-shrink-0",children:w.map(b=>r.jsxs("button",{onClick:()=>Rt(b.path,b.name),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-mono border-r border-border whitespace-nowrap transition-colors ${b.path===s?"bg-card text-ink":"text-muted hover:text-ink hover:bg-card"}`,children:[r.jsx("span",{className:"w-4 flex items-center justify-center",children:Yn(b.name,"file")}),b.name,b.modified&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),r.jsx("span",{role:"button",tabIndex:-1,title:"Close tab",onClick:I=>{I.stopPropagation(),Go(b.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),Go(b.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:r.jsx(ft,{size:12})})]},b.path))}),s?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-hover",children:[r.jsx("span",{className:"text-xs font-mono text-secondary truncate",children:s}),v&&r.jsx("span",{className:"text-xs text-primary animate-pulse flex-shrink-0",children:"Saving..."}),r.jsx("span",{className:"ml-auto text-xs text-muted/50 font-mono",children:Jo!=null?Eh(Jo):""}),r.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:ud}),p&&r.jsx("button",{onClick:kr,className:"text-xs font-medium px-2 py-0.5 rounded border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors",children:"Save"})]}),Bs===s&&r.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-warning/10",children:[r.jsx(Ct,{size:12,className:"text-warning"}),r.jsx("span",{className:"text-xs text-warning font-medium",children:"File changed externally"}),r.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[r.jsx("button",{onClick:Yh,className:"text-xs font-medium px-2 py-0.5 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors",children:"Reload"}),r.jsx("button",{onClick:()=>gi(null),className:"text-xs font-medium px-2 py-0.5 rounded border border-border text-muted hover:text-ink hover:bg-hover transition-colors",children:"Dismiss"})]})]}),r.jsx("div",{className:"flex-1 min-h-0",children:u?r.jsx(Cd,{}):r.jsx($i,{name:"Editor",children:r.jsx(Zf,{value:h??"",language:zv(n),theme:"vs",onChange:nd,onMount:od,options:{minimap:{enabled:!1},fontSize:13,lineNumbers:"on",wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0,padding:{top:8},renderLineHighlight:"line",smoothScrolling:!0,cursorBlinking:"smooth",folding:!0,bracketPairColorization:{enabled:!0}}})})}),r.jsx(ev,{selectedFile:s,fileName:n,isModified:p,isSaving:v,lastSavedAt:zh,lineCount:$h,cursorLine:Mo.line,cursorColumn:Mo.column,buildTime:ce.phase==="complete"&&ce.startTime?Math.floor((Date.now()-ce.startTime)/1e3):void 0,sessionId:x.id,prd:x.prd})]}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center p-8",children:[r.jsx(Z,{size:32,className:"text-muted/30 mb-3"}),r.jsx("p",{className:"text-sm text-muted",children:"Select a file to view its contents"}),r.jsxs("p",{className:"text-xs text-muted/60 mt-1",children:["Use the file tree or press ",r.jsx("kbd",{className:"px-1.5 py-0.5 text-[10px] font-mono bg-hover border border-border rounded",children:"Cmd+P"})," to quick open"]})]})]}),f==="preview"&&r.jsx($i,{name:"Preview",children:r.jsxs("div",{className:`h-full flex flex-col ${To?"preview-fullscreen":""}`,children:[r.jsx("div",{className:"px-3 py-1.5 border-b border-border flex items-center gap-2 bg-hover flex-shrink-0",children:$!=null&&$.running||se!=null&&se.preview_url?r.jsxs(r.Fragment,{children:[r.jsx(Pt,{icon:kd,label:"Back",size:"sm",onClick:td,disabled:xt<=0}),r.jsx(Pt,{icon:Jn,label:"Forward",size:"sm",onClick:sd,disabled:xt>=wi.length-1}),r.jsx(cv,{onClick:()=>{yr(!0),L(b=>b+1)}}),r.jsx("input",{value:Vo,onChange:b=>Sr(b.target.value),onKeyDown:b=>{b.key==="Enter"&&id(Vo)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx(tv,{selectedDevice:Ih,onDeviceChange:Fh,containerWidth:Uh}),r.jsx(rv,{zoom:br,onZoomChange:Hh}),r.jsx(av,{url:vt}),r.jsx(ov,{}),r.jsx(hv,{url:vt}),r.jsx(Pt,{icon:ss,label:"Open in new tab",size:"sm",onClick:()=>window.open(vt,"_blank")}),r.jsx(lv,{isFullscreen:To,onToggle:()=>Wh(b=>!b)}),($==null?void 0:$.running)&&r.jsxs("button",{onClick:Xh,className:"flex items-center gap-1 px-2 py-1 text-xs font-medium rounded border border-danger/40 bg-danger/10 text-danger hover:bg-danger/20 transition-colors",children:[r.jsx(Zi,{size:12}),"Stop"]})]}):se?r.jsx("div",{className:"flex-1 flex items-center gap-2 text-sm text-muted",children:r.jsx("span",{className:"font-medium text-ink",children:se.description})}):r.jsx("div",{className:"flex-1 flex items-center text-sm text-muted",children:"Detecting project type..."})}),$&&$.status!=="stopped"&&r.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs flex-shrink-0 ${$.running?"bg-green-50 border-green-200 text-green-700":$.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":$.status==="error"?"bg-red-50 border-red-200 text-red-700":"bg-gray-50 border-border text-muted"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${$.running?"bg-green-500":$.status==="starting"?"bg-yellow-500 animate-pulse":$.status==="error"?"bg-red-500":"bg-gray-400"}`}),$.running&&$.portless_url&&r.jsxs("span",{children:["Running at ",$.portless_url]}),$.running&&$.port&&!$.portless_url&&r.jsxs("span",{children:["Running on port ",$.port]}),$.status==="starting"&&r.jsx("span",{children:"Starting dev server..."}),$.status==="error"&&!$.auto_fix_status&&r.jsx("span",{children:"Dev server crashed"}),$.status==="error"&&$.auto_fix_status&&r.jsxs("span",{children:["Auto-fixing: ",$.auto_fix_status]}),$.command&&r.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:$.command})]}),$!=null&&$.running?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[bi&&r.jsx(Bl,{}),r.jsx("div",{ref:ms,className:`flex-1 bg-white overflow-auto flex justify-center ${bi?"hidden":""}`,children:r.jsx("div",{className:`${Bo} h-full preview-zoom-${br}`,children:r.jsx("iframe",{ref:M,src:vt,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{yr(!1),ms.current&&Ao(ms.current.clientWidth)}},E)})}),r.jsx(Ll,{messages:zo})]}):se!=null&&se.preview_url?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[bi&&r.jsx(Bl,{}),r.jsx("div",{ref:ms,className:`flex-1 bg-white overflow-auto flex justify-center ${bi?"hidden":""}`,children:r.jsx("div",{className:`${Bo} h-full preview-zoom-${br}`,children:r.jsx("iframe",{ref:M,src:vt,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{yr(!1),ms.current&&Ao(ms.current.clientWidth)}},E)})}),r.jsx(Ll,{messages:zo})]}):se?r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[r.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:se.type==="api"||se.type==="python-api"?r.jsx($d,{size:28,className:"text-primary"}):se.type==="library"?r.jsx(Xl,{size:28,className:"text-primary"}):se.type==="go-app"||se.type==="rust-app"?r.jsx(es,{size:28,className:"text-primary"}):r.jsx(tn,{size:28,className:"text-primary"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-heading text-ink mb-1",children:se.type.replace(/-/g," ").replace(/\b\w/g,b=>b.toUpperCase())}),r.jsx("p",{className:"text-sm text-muted",children:se.description})]}),r.jsxs("div",{className:"card p-4 max-w-md w-full space-y-3",children:[se.dev_command&&r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Dev Server"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("code",{className:"text-sm font-mono text-primary bg-hover px-3 py-2 rounded-btn flex-1 text-left truncate",children:se.dev_command}),r.jsxs("button",{onClick:()=>ps(se.dev_command||void 0),disabled:Os,className:"flex items-center gap-1.5 px-3 py-2 text-xs font-medium rounded-btn bg-primary text-white hover:bg-primary/90 transition-colors disabled:opacity-50",children:[r.jsx(It,{size:12}),Os?"Starting...":"Start"]})]})]}),r.jsxs("div",{className:se.dev_command?"pt-2 border-t border-border":"",children:[r.jsx("p",{className:"text-xs text-muted mb-2",children:se.dev_command?"Or use a custom command:":"Start a dev server:"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:Kt,onChange:b=>Gh(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Kt.trim()&&ps(Kt.trim())},placeholder:"e.g. npm run dev",className:"flex-1 px-3 py-1.5 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx("button",{onClick:()=>Kt.trim()&&ps(Kt.trim()),disabled:Os||!Kt.trim(),className:"px-3 py-1.5 text-xs font-medium rounded-btn border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-50",children:"Run"})]})]})]}),Uo&&r.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[r.jsx("p",{className:"text-xs text-danger font-medium mb-1",children:"Dev server error"}),r.jsx("p",{className:"text-xs text-danger/80",children:Uo})]}),($==null?void 0:$.status)==="error"&&r.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs text-danger font-medium",children:"Dev server crashed"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("button",{onClick:Jh,disabled:Ho,className:"text-xs px-2 py-1 rounded border border-primary/40 bg-primary/10 text-primary hover:bg-primary/20 transition-colors disabled:opacity-50",children:Ho?"Fixing...":"Fix Error"}),r.jsx("button",{onClick:()=>ps(se.dev_command||Kt||void 0),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]})]}),$.auto_fix_status&&r.jsxs("div",{className:"flex items-center gap-2 mb-2 px-2 py-1 rounded bg-primary/5 border border-primary/20",children:[r.jsx("div",{className:"w-2 h-2 rounded-full bg-primary animate-pulse"}),r.jsxs("span",{className:"text-[11px] text-primary font-medium",children:["Auto-fix: ",$.auto_fix_status]}),$.auto_fix_attempts!==void 0&&$.auto_fix_attempts>0&&r.jsxs("span",{className:"text-[10px] text-muted ml-auto",children:["Attempt ",$.auto_fix_attempts,"/3"]})]}),$.output.length>0&&r.jsx("pre",{className:"text-[11px] font-mono text-danger/70 bg-danger/5 p-2 rounded max-h-32 overflow-y-auto whitespace-pre-wrap",children:$.output.slice(-10).join(`
|
|
287
287
|
`)})]}),se.port&&!($!=null&&$.running)&&r.jsxs("p",{className:"text-xs text-muted",children:["Server will run on port ",se.port]})]}):r.jsx("div",{className:"flex-1 flex items-center justify-center text-muted text-sm",children:"Detecting project type..."})]})}),f==="config"&&r.jsx("div",{className:"h-full flex flex-col",children:r.jsxs("div",{className:"p-6 overflow-y-auto",children:[r.jsx("h3",{className:"text-h3 font-heading text-ink mb-4",children:"Project Configuration"}),r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Provider"}),r.jsxs("p",{className:"text-xs text-muted mb-2",children:["Current session: ",r.jsx("span",{className:"font-semibold text-ink capitalize",children:ge})]}),r.jsx("div",{className:"flex gap-2",children:["claude","codex","gemini"].map(b=>r.jsx("button",{onClick:()=>{Ee(b),sessionStorage.setItem(`pl_provider_${x.id}`,b),K.setProvider(b).catch(()=>{})},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${ge===b?"border-primary bg-primary/10 text-primary":"border-border text-secondary hover:bg-hover"}`,children:b},b))})]}),r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Build Mode"}),r.jsx("div",{className:"flex gap-2",children:["quick","standard","max"].map(b=>r.jsx("button",{onClick:()=>{le(b),sessionStorage.setItem(`pl_buildmode_${x.id}`,b)},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${D===b?"border-primary bg-primary/10 text-primary":"border-border text-secondary hover:bg-hover"}`,children:b},b))})]}),r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Project Path"}),r.jsx("input",{value:x.path,readOnly:!0,className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink"})]}),r.jsxs("div",{className:"card p-4",children:[r.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Session ID"}),r.jsx("input",{value:x.id,readOnly:!0,className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink"})]})]})]})}),f==="secrets"&&r.jsx(Av,{}),f==="prd"&&r.jsx("div",{className:"h-full flex flex-col",children:r.jsxs("div",{className:"p-6 overflow-y-auto",children:[r.jsx("h3",{className:"text-h3 font-heading text-ink mb-4",children:"Product Requirements"}),x.prd?r.jsx("pre",{className:"text-sm font-mono text-ink whitespace-pre-wrap bg-hover border border-border rounded-card p-4 leading-relaxed",children:x.prd}):r.jsx("div",{className:"text-sm text-muted text-center py-8",children:"No PRD found for this project."})]})}),f==="deploy"&&r.jsx(xx,{sessionId:x.id}),f==="dashboard"&&(z===!1?r.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center p-8 gap-4",children:[r.jsx(jr,{size:48,className:"text-muted/30"}),r.jsx("h3",{className:"text-lg font-heading font-bold text-ink",children:"Dashboard Not Running"}),r.jsx("p",{className:"text-sm text-muted max-w-md",children:"The Loki Dashboard provides task boards, RARV timeline, quality gates, and cost tracking. Start it to see project analytics."}),r.jsx("button",{onClick:async()=>{V(null);try{const b=await fetch(`http://127.0.0.1:${de}/health`);V(b.ok)}catch{V(!1)}},className:"px-4 py-2 text-sm font-medium rounded-btn bg-primary text-white hover:bg-primary-hover",children:"Check Again"})]}):r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-1 px-3 py-2 border-b border-border bg-hover flex-shrink-0",children:[[{id:"overview",label:"Overview"},{id:"tasks",label:"Tasks"},{id:"timeline",label:"RARV Timeline"},{id:"quality",label:"Quality"},{id:"cost",label:"Cost"}].map(b=>r.jsx("button",{onClick:()=>he(b.id),className:`px-3 py-1.5 text-xs font-medium rounded-btn transition-colors ${ie===b.id?"bg-primary/10 text-primary":"text-muted hover:text-ink hover:bg-hover"}`,children:b.label},b.id)),r.jsx("div",{className:"flex-1"}),r.jsxs("a",{href:`http://127.0.0.1:${de}/`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted hover:text-primary flex items-center gap-1",children:["Open full dashboard ",r.jsx(ss,{size:12})]})]}),r.jsx("iframe",{src:`http://127.0.0.1:${de}/#${ie}`,className:"flex-1 w-full border-none",title:"Loki Dashboard",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms"})]})),f==="git"&&r.jsx(zx,{sessionId:x.id}),f==="cicd"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Tv,{sessionId:e.id})}),f==="insights"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(kv,{filesCreated:x.files.filter(b=>b.type==="file").length,filesModified:0,linesGenerated:0,testsGenerated:0,testPassRate:0,totalTokens:0,phaseBreakdown:[],totalTimeSecs:ce.startTime?Math.floor((Date.now()-ce.startTime)/1e3):0,qualityScore:0,totalCost:ce.cost,iterations:ce.iteration,provider:ge})})]})]})})]})}),X&&r.jsx(cn,{className:"h-1 bg-border hover:bg-primary/30 cursor-row-resize"}),X&&r.jsx(Xs,{defaultSize:30,minSize:15,collapsible:!0,children:r.jsx($i,{name:"ActivityPanel",children:r.jsx(lx,{logs:null,logsLoading:!1,agents:null,checklist:null,sessionId:e.id,isRunning:x.status==="running"||x.status==="in_progress",buildMode:D,buildEvents:Mh,onFileClick:b=>Rt(b,b.split("/").pop()||b)})})})]})}),(_e==null?void 0:_e.loading)&&r.jsx("div",{className:"absolute inset-x-0 bottom-0 z-20 bg-card border-t border-border p-4",children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin"}),r.jsxs("span",{className:"text-sm font-medium text-ink",children:[_e.type==="review"?"Reviewing project":_e.type==="test"?"Generating tests":"Analyzing project","..."]}),r.jsxs("span",{className:"text-xs font-mono text-muted",children:[_e.elapsed,"s"]})]})}),ee&&r.jsxs("div",{className:"absolute inset-x-0 bottom-0 z-20 bg-card border-t border-border p-4 max-h-64 overflow-y-auto",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs font-semibold text-ink",children:"Action Output"}),r.jsx(Pt,{icon:ft,label:"Close",size:"sm",onClick:()=>fe(null)})]}),r.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap",children:ee})]}),S&&r.jsx(Tm,{x:S.x,y:S.y,items:rd(S),onClose:()=>j(null)}),T&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[20vh]",role:"dialog","aria-modal":"true","aria-label":"Quick open file search",onClick:()=>W(!1),children:r.jsxs("div",{className:"bg-card rounded-card shadow-2xl border border-border w-full max-w-lg",onClick:b=>b.stopPropagation(),children:[r.jsx("input",{ref:A,type:"text",value:G,onChange:b=>U(b.target.value),placeholder:"Search files by name...",className:"w-full px-4 py-3 text-sm font-mono border-b border-border outline-none rounded-t-card bg-transparent",onKeyDown:b=>{b.key==="Enter"&&$s.length>0&&(Rt($s[0].path,$s[0].name),W(!1)),b.key==="Escape"&&W(!1)}}),r.jsxs("div",{className:"max-h-64 overflow-y-auto",children:[$s.slice(0,20).map(b=>r.jsxs("button",{onClick:()=>{Rt(b.path,b.name),W(!1)},className:"w-full text-left px-4 py-2 text-xs font-mono hover:bg-primary/5 flex items-center gap-2",children:[r.jsx("span",{className:"w-5 flex items-center justify-center",children:Yn(b.name,"file")}),r.jsx("span",{className:"text-ink",children:b.name}),r.jsx("span",{className:"text-muted ml-auto truncate text-xs",children:b.path})]},b.path)),$s.length===0&&r.jsx("div",{className:"px-4 py-3 text-xs text-muted",children:"No matching files"})]})]})}),r.jsx(Sx,{open:fd,onClose:()=>Zo(!1)}),r.jsx(jx,{isOpen:Ph,onClose:()=>No(!1),commands:md,sessionId:x.id,onFileSelect:Rt}),Eo&&r.jsx(Ix,{data:Eo,onAcceptAll:cd,onAcceptSelected:hd,onReject:dd,onClose:()=>zs(null)}),r.jsx(Yx,{phase:ji,buildTime:ce.startTime?Math.floor((Date.now()-ce.startTime)/1e3):void 0}),Lh&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>vr(!1),children:r.jsxs("div",{className:"bg-card rounded-card shadow-2xl border border-border w-full max-w-3xl max-h-[80vh] overflow-y-auto",onClick:b=>b.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[r.jsx("h3",{className:"text-sm font-bold text-ink",children:"Build Replay"}),r.jsx("button",{onClick:()=>vr(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(ft,{size:16})})]}),r.jsx("div",{className:"p-4",children:r.jsx(Ev,{sessionId:x.id,files:x.files.map(b=>({path:b.path,type:b.type})),phases:["planning","building","testing","reviewing","complete"],checkpoints:[],qualityGates:[],totalIterations:ce.iteration||ce.maxIterations})})]})}),Th&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[15vh]",onClick:()=>As(!1),children:r.jsxs("div",{className:"bg-card rounded-card shadow-2xl border border-border w-full max-w-lg",onClick:b=>b.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[r.jsx("h3",{className:"text-sm font-bold text-ink",children:"Search Files"}),r.jsx("button",{onClick:()=>As(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(ft,{size:16})})]}),r.jsx(Mv,{sessionId:x.id,onOpenFile:(b,I)=>{Rt(b,b.split("/").pop()||b),As(!1)},className:"p-4"})]})}),Bh&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>xi(!1),children:r.jsx("div",{className:"bg-card rounded-card shadow-2xl border border-border w-full max-w-md",onClick:b=>b.stopPropagation(),children:r.jsx(Bv,{complexity:D==="quick"?"simple":D==="max"?"complex":"standard",provider:ge,estimatedIterations:ce.maxIterations,onConfirm:async()=>{xi(!1);try{const b=x.prd||"";await K.startSession({prd:b,provider:ge,projectDir:x.path}),Ls(!0)}catch(b){window.alert(`Failed to start: ${b instanceof Error?b.message:"Unknown error"}`)}},onCancel:()=>xi(!1)})})})]})}function $v(){const{sessionId:e}=Nd(),t=jd(),[s,i]=d.useState(null),[n,o]=d.useState(!0),[a,l]=d.useState(null);return d.useEffect(()=>{e&&(o(!0),l(null),K.getSessionDetail(e).then(h=>{i(h),o(!1)}).catch(h=>{l(h instanceof Error?h.message:"Failed to load session"),o(!1)}))},[e]),n?r.jsx("div",{className:"h-screen bg-background flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"text-muted animate-pulse text-sm",children:"Loading project..."}),r.jsx("div",{className:"text-xs font-mono text-muted/50 mt-2",children:e})]})}):a||!s?r.jsx("div",{className:"h-screen bg-background flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"text-danger text-sm font-medium",children:"Project not found"}),r.jsx("p",{className:"text-xs text-muted mt-1",children:a||`Session ${e} does not exist`}),r.jsx("button",{onClick:()=>t("/"),className:"mt-4 px-4 py-2 rounded-btn text-sm font-semibold border border-primary/30 text-primary hover:bg-primary/5 transition-all",children:"Back to Home"})]})}):r.jsx("div",{className:"h-screen bg-background flex flex-col",children:r.jsx("div",{className:"flex-1 min-h-0",children:r.jsx($i,{name:"ProjectWorkspace",children:r.jsx(Ov,{session:s,onClose:()=>t("/")})})})})}const vb=Object.freeze(Object.defineProperty({__proto__:null,default:$v},Symbol.toStringTag,{value:"Module"}));export{Gd as C,sn as G,fr as L,vb as P,Eu as S};
|