loki-mode 9.48.2 → 9.49.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.github/workflows/loki-issue-to-pr.yml +1 -1
  2. package/SKILL.md +2 -2
  3. package/VERSION +1 -1
  4. package/autonomy/loki +137 -12
  5. package/autonomy/provider-offer.sh +47 -0
  6. package/autonomy/quickstart.sh +306 -9
  7. package/dashboard/__init__.py +1 -1
  8. package/dashboard/static/index.html +7 -1
  9. package/docs/INSTALLATION.md +1 -1
  10. package/docs/KNOWN-ISSUES.md +42 -0
  11. package/loki-ts/dist/loki.js +317 -317
  12. package/mcp/__init__.py +1 -1
  13. package/package.json +1 -1
  14. package/plugins/loki-mode/.claude-plugin/plugin.json +1 -1
  15. package/web-app/dist/assets/{AdminPage-PyyVXg4b.js → AdminPage-DpV2vW3y.js} +1 -1
  16. package/web-app/dist/assets/{Avatar-CTUlr_Xf.js → Avatar-BXeMYK1_.js} +1 -1
  17. package/web-app/dist/assets/{Badge-BQeXvmg8.js → Badge-D8WddQk1.js} +1 -1
  18. package/web-app/dist/assets/{Button-Dc6-P6pz.js → Button-CFzTTVeJ.js} +1 -1
  19. package/web-app/dist/assets/{CockpitPage-BspOJ3Fv.js → CockpitPage-D1eQe9QF.js} +4 -4
  20. package/web-app/dist/assets/{ComparePage-CFXIM--Z.js → ComparePage-uX3OPphr.js} +1 -1
  21. package/web-app/dist/assets/{ErrorBoundary-C7vQYDW9.js → ErrorBoundary-wE3oxaG6.js} +1 -1
  22. package/web-app/dist/assets/{EvidenceReceiptPanel-CqjsjTOs.js → EvidenceReceiptPanel-B_Wouz6N.js} +1 -1
  23. package/web-app/dist/assets/{GitHubIssuesPanel-DyuNDMgD.js → GitHubIssuesPanel-DRlEeFuw.js} +1 -1
  24. package/web-app/dist/assets/{GitHubPRsPanel-BtAq20xF.js → GitHubPRsPanel-CCv6_I74.js} +2 -2
  25. package/web-app/dist/assets/{HomePage-BuVFOrO8.js → HomePage-EG-jq8nR.js} +1 -1
  26. package/web-app/dist/assets/{LoginPage-CuhhrxGb.js → LoginPage-CEOnBICH.js} +1 -1
  27. package/web-app/dist/assets/{MagicPage-D2KZPX3F.js → MagicPage-DeWaFdsG.js} +1 -1
  28. package/web-app/dist/assets/MetricsPage-CG8CuSSJ.js +6 -0
  29. package/web-app/dist/assets/{NotFoundPage-CTnnaWlL.js → NotFoundPage-Mz5rOat6.js} +1 -1
  30. package/web-app/dist/assets/{ProjectPage-uJFaoM8-.js → ProjectPage-D2Fh6tVw.js} +8 -8
  31. package/web-app/dist/assets/{ProjectsPage-8lKAOBIW.js → ProjectsPage-B8cRWkWa.js} +2 -2
  32. package/web-app/dist/assets/{SettingsPage-D1BBd5qy.js → SettingsPage-DKpsst6x.js} +1 -1
  33. package/web-app/dist/assets/{ShowcasePage-CmQ0n8iO.js → ShowcasePage-qab065PM.js} +1 -1
  34. package/web-app/dist/assets/SystemSettingsPage-9qmEH2Y6.js +1 -0
  35. package/web-app/dist/assets/{TeamsPage-BS0TtVUa.js → TeamsPage-CW6lvW-0.js} +1 -1
  36. package/web-app/dist/assets/{TemplatesPage-C2zPnnf2.js → TemplatesPage-B-a61T6a.js} +1 -1
  37. package/web-app/dist/assets/{TerminalOutput-Dle1klqq.js → TerminalOutput-CJy13rAn.js} +1 -1
  38. package/web-app/dist/assets/{activity-DQp5U9f9.js → activity-CA4moIvC.js} +1 -1
  39. package/web-app/dist/assets/{bell-BqkTmgL7.js → bell-JyOeobLN.js} +1 -1
  40. package/web-app/dist/assets/{bot-DILhaIGH.js → bot-Cu4UwP5w.js} +1 -1
  41. package/web-app/dist/assets/{check-BC9x7oPm.js → check-Drzd8-9c.js} +1 -1
  42. package/web-app/dist/assets/{chevron-left--yqvAfjx.js → chevron-left-ClvdXm3Y.js} +1 -1
  43. package/web-app/dist/assets/{circle-alert-DOH6PcgZ.js → circle-alert-CstyZfKG.js} +1 -1
  44. package/web-app/dist/assets/{clock-DKSDFsE6.js → clock-Bnz6tlQN.js} +1 -1
  45. package/web-app/dist/assets/{cloud-DRBU3JYs.js → cloud-IPIgE4P3.js} +1 -1
  46. package/web-app/dist/assets/{code-xml-D2LqszR9.js → code-xml-BOZbQiOt.js} +1 -1
  47. package/web-app/dist/assets/{database-D7ceedlh.js → database-CHclPjog.js} +1 -1
  48. package/web-app/dist/assets/{dollar-sign-D0A47egY.js → dollar-sign-D6RFNgdZ.js} +1 -1
  49. package/web-app/dist/assets/{file-code-corner-CH_Qbtjo.js → file-code-corner-CNayCvOY.js} +1 -1
  50. package/web-app/dist/assets/{file-plus-CUNMjHk9.js → file-plus-BmVfFwsX.js} +1 -1
  51. package/web-app/dist/assets/folder-open-ChzGfLRr.js +11 -0
  52. package/web-app/dist/assets/{globe-gZnaGg8N.js → globe-DtXgCG3Z.js} +1 -1
  53. package/web-app/dist/assets/{hammer-BhJC5DMK.js → hammer-DCa0I_7V.js} +1 -1
  54. package/web-app/dist/assets/{index-BMmYYws0.js → index-Cu-njJ8o.js} +3 -3
  55. package/web-app/dist/assets/index-D98GzaW8.css +1 -0
  56. package/web-app/dist/assets/{layers-glXeoUbJ.js → layers-DxIhn7NZ.js} +1 -1
  57. package/web-app/dist/assets/{lightbulb-gXn8H0Lf.js → lightbulb-D7Pzhd06.js} +1 -1
  58. package/web-app/dist/assets/{loader-circle-Do2ke8xm.js → loader-circle-DXgc_u5I.js} +1 -1
  59. package/web-app/dist/assets/{lock-Bgplb1_n.js → lock-qRAVU53b.js} +1 -1
  60. package/web-app/dist/assets/{mail-j4Lo8hfB.js → mail-CHe3KyCw.js} +1 -1
  61. package/web-app/dist/assets/{minus-dhrzKSK5.js → minus-B8p0FoYZ.js} +1 -1
  62. package/web-app/dist/assets/{package-CInWQQ97.js → package-C5LDn8SI.js} +1 -1
  63. package/web-app/dist/assets/{plus-BpYvoLlZ.js → plus-CRd_FHOA.js} +1 -1
  64. package/web-app/dist/assets/{refresh-cw-F6koqEgF.js → refresh-cw-DKoSN8s3.js} +1 -1
  65. package/web-app/dist/assets/{rotate-ccw-CQ2W5S8f.js → rotate-ccw-Nf8zB8G0.js} +1 -1
  66. package/web-app/dist/assets/{save-DMCYGm06.js → save-B8ytQLgW.js} +1 -1
  67. package/web-app/dist/assets/{server-Bj8EX4Z1.js → server-D_VRDkaD.js} +1 -1
  68. package/web-app/dist/assets/{shield-alert-CiYuulCU.js → shield-alert-PsDkSyFD.js} +1 -1
  69. package/web-app/dist/assets/{thumbs-up-BqEh1puP.js → thumbs-up-Da1QQhqo.js} +11 -6
  70. package/web-app/dist/assets/{trash-2-CCwouZJJ.js → trash-2-ChoylpGQ.js} +1 -1
  71. package/web-app/dist/assets/{trending-down-Cx1vhE4o.js → trending-down-CX2fUeho.js} +1 -1
  72. package/web-app/dist/assets/{trending-up-BUhVYJ2T.js → trending-up-CGyYgZH7.js} +1 -1
  73. package/web-app/dist/assets/{upload-D5IsZeFM.js → upload-KkeVyg67.js} +1 -1
  74. package/web-app/dist/assets/{usePolling-CJbfhFcH.js → usePolling-C5f4xrXD.js} +1 -1
  75. package/web-app/dist/assets/{user-BRLhezsD.js → user-WCGccIST.js} +1 -1
  76. package/web-app/dist/index.html +2 -2
  77. package/web-app/server.py +121 -1
  78. package/web-app/dist/assets/MetricsPage-DFEYJl9z.js +0 -6
  79. package/web-app/dist/assets/SystemSettingsPage-CSHaVyuD.js +0 -6
  80. package/web-app/dist/assets/copy-BKW4U4Qr.js +0 -6
  81. package/web-app/dist/assets/folder-open-CQ_SVq94.js +0 -6
  82. package/web-app/dist/assets/git-commit-horizontal-DQUBe0oD.js +0 -6
  83. package/web-app/dist/assets/index-84JUN_aA.css +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GitHubIssuesPanel-DyuNDMgD.js","assets/index-BMmYYws0.js","assets/index-84JUN_aA.css","assets/Button-Dc6-P6pz.js","assets/thumbs-up-BqEh1puP.js","assets/refresh-cw-F6koqEgF.js","assets/circle-alert-DOH6PcgZ.js","assets/user-BRLhezsD.js","assets/rotate-ccw-CQ2W5S8f.js","assets/loader-circle-Do2ke8xm.js","assets/GitHubPRsPanel-BtAq20xF.js","assets/chevron-left--yqvAfjx.js","assets/shield-alert-CiYuulCU.js","assets/file-code-corner-CH_Qbtjo.js","assets/clock-DKSDFsE6.js","assets/check-BC9x7oPm.js","assets/ErrorBoundary-C7vQYDW9.js","assets/TerminalOutput-Dle1klqq.js","assets/lock-Bgplb1_n.js","assets/package-CInWQQ97.js","assets/file-plus-CUNMjHk9.js","assets/activity-DQp5U9f9.js","assets/bot-DILhaIGH.js","assets/hammer-BhJC5DMK.js","assets/dollar-sign-D0A47egY.js","assets/globe-gZnaGg8N.js","assets/copy-BKW4U4Qr.js","assets/git-commit-horizontal-DQUBe0oD.js","assets/upload-D5IsZeFM.js","assets/plus-BpYvoLlZ.js","assets/trash-2-CCwouZJJ.js","assets/minus-dhrzKSK5.js","assets/save-DMCYGm06.js","assets/code-xml-D2LqszR9.js","assets/trending-up-BUhVYJ2T.js","assets/layers-glXeoUbJ.js","assets/trending-down-Cx1vhE4o.js","assets/folder-open-CQ_SVq94.js","assets/server-Bj8EX4Z1.js"])))=>i.map(i=>d[i]);
2
- var sa=e=>{throw TypeError(e)};var ia=(e,t,s)=>t.has(e)||sa("Cannot "+s);var Hs=(e,t,s)=>(ia(e,t,"read from private field"),s?s.call(e):t.get(e)),ra=(e,t,s)=>t.has(e)?sa("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),na=(e,t,s,i)=>(ia(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s);import{c as ce,r as d,W as Ds,j as r,f as en,g as Kl,h as ur,i as fs,I as ql,T as Ht,R as Wt,k as ns,M as Vl,l as tr,m as Dt,S as Gl,U as _d,X as _t,n as os,Z as is,a as W,E as as,G as ze,K as xd,o as vd,p as bd,F as mi,P as Ut,_ as Qn,b as fr,q as Yl,s as Xl,t as yd,v as Sd,A as eo,L as wd,B as Ys,w as tn,x as Cd,e as kd,y as ks,z as oa,D as aa,H as jd,J as Jl,N as ri,O as Nd,u as Ed}from"./index-BMmYYws0.js";import{R as Dd,S as sr,P as Zl,E as Wi}from"./ErrorBoundary-C7vQYDW9.js";import{B as he}from"./Button-Dc6-P6pz.js";import{T as Rd,F as Pd}from"./TerminalOutput-Dle1klqq.js";import{P as Ql}from"./package-CInWQQ97.js";import{F as ee}from"./file-code-corner-CH_Qbtjo.js";import{F as mr}from"./file-plus-CUNMjHk9.js";import{C as ct}from"./clock-DKSDFsE6.js";import{A as Md}from"./activity-DQp5U9f9.js";import{B as Ld}from"./bot-DILhaIGH.js";import{C as Gt}from"./check-BC9x7oPm.js";import{L as pi}from"./loader-circle-Do2ke8xm.js";import{H as Bd}from"./hammer-BhJC5DMK.js";import{D as ec}from"./dollar-sign-D0A47egY.js";import{R as bt}from"./refresh-cw-F6koqEgF.js";import{C as Bs}from"./circle-alert-DOH6PcgZ.js";import{G as sn}from"./globe-gZnaGg8N.js";import{C as to}from"./copy-BKW4U4Qr.js";import{C as Td,G as rn,F as tc,H as nn,T as zd}from"./thumbs-up-BqEh1puP.js";import{G as sc}from"./git-commit-horizontal-DQUBe0oD.js";import{U as ic}from"./upload-D5IsZeFM.js";import{P as pr}from"./plus-BpYvoLlZ.js";import{T as so}from"./trash-2-CCwouZJJ.js";import{R as rc,E as Ad}from"./rotate-ccw-CQ2W5S8f.js";import{M as nc}from"./minus-dhrzKSK5.js";import{S as Od}from"./save-DMCYGm06.js";import{C as on}from"./code-xml-D2LqszR9.js";import{T as $d}from"./trending-up-BUhVYJ2T.js";import{L as Id}from"./layers-glXeoUbJ.js";import{T as Fd}from"./trending-down-Cx1vhE4o.js";import{F as an}from"./folder-open-CQ_SVq94.js";import{S as Hd}from"./server-Bj8EX4Z1.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GitHubIssuesPanel-DRlEeFuw.js","assets/index-Cu-njJ8o.js","assets/index-D98GzaW8.css","assets/Button-CFzTTVeJ.js","assets/thumbs-up-Da1QQhqo.js","assets/refresh-cw-DKoSN8s3.js","assets/circle-alert-CstyZfKG.js","assets/user-WCGccIST.js","assets/rotate-ccw-Nf8zB8G0.js","assets/loader-circle-DXgc_u5I.js","assets/GitHubPRsPanel-CCv6_I74.js","assets/chevron-left-ClvdXm3Y.js","assets/shield-alert-PsDkSyFD.js","assets/file-code-corner-CNayCvOY.js","assets/clock-Bnz6tlQN.js","assets/check-Drzd8-9c.js","assets/ErrorBoundary-wE3oxaG6.js","assets/TerminalOutput-CJy13rAn.js","assets/lock-qRAVU53b.js","assets/package-C5LDn8SI.js","assets/file-plus-BmVfFwsX.js","assets/activity-CA4moIvC.js","assets/bot-Cu4UwP5w.js","assets/hammer-DCa0I_7V.js","assets/dollar-sign-D6RFNgdZ.js","assets/globe-DtXgCG3Z.js","assets/folder-open-ChzGfLRr.js","assets/upload-KkeVyg67.js","assets/plus-CRd_FHOA.js","assets/trash-2-ChoylpGQ.js","assets/minus-B8p0FoYZ.js","assets/save-B8ytQLgW.js","assets/code-xml-BOZbQiOt.js","assets/trending-up-CGyYgZH7.js","assets/layers-DxIhn7NZ.js","assets/trending-down-CX2fUeho.js","assets/server-D_VRDkaD.js"])))=>i.map(i=>d[i]);
2
+ var sa=e=>{throw TypeError(e)};var ia=(e,t,s)=>t.has(e)||sa("Cannot "+s);var Hs=(e,t,s)=>(ia(e,t,"read from private field"),s?s.call(e):t.get(e)),ra=(e,t,s)=>t.has(e)?sa("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),na=(e,t,s,i)=>(ia(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s);import{c as ce,r as d,W as Ds,j as r,f as en,g as Kl,h as ur,i as fs,I as ql,T as Ht,R as Wt,k as ns,M as Vl,l as tr,m as Dt,S as Gl,U as _d,X as _t,n as os,Z as is,a as W,E as as,G as ze,K as xd,o as vd,p as bd,F as mi,P as Ut,_ as Qn,b as fr,q as Yl,s as Xl,t as yd,v as Sd,A as eo,L as wd,B as Ys,w as tn,x as Cd,e as kd,y as ks,z as oa,D as aa,H as jd,J as Jl,N as ri,O as Nd,u as Ed}from"./index-Cu-njJ8o.js";import{R as Dd,S as sr,P as Zl,E as Wi}from"./ErrorBoundary-wE3oxaG6.js";import{B as he}from"./Button-CFzTTVeJ.js";import{T as Rd,F as Pd}from"./TerminalOutput-CJy13rAn.js";import{P as Ql}from"./package-C5LDn8SI.js";import{F as ee}from"./file-code-corner-CNayCvOY.js";import{F as mr}from"./file-plus-BmVfFwsX.js";import{C as ct}from"./clock-Bnz6tlQN.js";import{A as Md}from"./activity-CA4moIvC.js";import{B as Ld}from"./bot-Cu4UwP5w.js";import{C as Gt}from"./check-Drzd8-9c.js";import{L as pi}from"./loader-circle-DXgc_u5I.js";import{H as Bd}from"./hammer-DCa0I_7V.js";import{D as ec}from"./dollar-sign-D6RFNgdZ.js";import{R as bt}from"./refresh-cw-DKoSN8s3.js";import{C as Bs}from"./circle-alert-CstyZfKG.js";import{G as sn}from"./globe-DtXgCG3Z.js";import{C as to,F as rn}from"./folder-open-ChzGfLRr.js";import{C as Td,G as nn,a as tc,F as sc,H as on,T as zd}from"./thumbs-up-Da1QQhqo.js";import{U as ic}from"./upload-KkeVyg67.js";import{P as pr}from"./plus-CRd_FHOA.js";import{T as so}from"./trash-2-ChoylpGQ.js";import{R as rc,E as Ad}from"./rotate-ccw-Nf8zB8G0.js";import{M as nc}from"./minus-B8p0FoYZ.js";import{S as Od}from"./save-B8ytQLgW.js";import{C as an}from"./code-xml-BOZbQiOt.js";import{T as $d}from"./trending-up-CGyYgZH7.js";import{L as Id}from"./layers-DxIhn7NZ.js";import{T as Fd}from"./trending-down-CX2fUeho.js";import{S as Hd}from"./server-D_VRDkaD.js";/**
3
3
  * @license lucide-react v0.577.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -222,9 +222,9 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
222
222
  \x1B[31m-- Terminal disconnected. Max reconnect attempts reached. Refresh the page to try again. --\x1B[0m`);return}const y=Math.min(Y_*Math.pow(2,v),X_);h.current=v+1,g&&g.writeln(`\r
223
223
  \x1B[33m-- Terminal disconnected. Reconnecting in ${(y/1e3).toFixed(0)}s (attempt ${v+1}/${kl})... --\x1B[0m`),a.current=setTimeout(()=>{l.current&&u()},y)},_.onerror=()=>{}},[e,c]);return d.useEffect(()=>{l.current=!0,h.current=0;const m=s.current;if(!m)return;const f=new $_({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}),_=new H_,p=new G_;f.loadAddon(_),f.loadAddon(p),f.open(m),i.current=f,n.current=_;try{_.fit()}catch{}f.onData(y=>{const x=o.current;x&&x.readyState===WebSocket.OPEN&&x.send(JSON.stringify({type:"input",data:y}))}),u();let g=null;const v=new ResizeObserver(()=>{g&&clearTimeout(g),g=setTimeout(()=>{if(!(!n.current||!i.current))try{n.current.fit(),c()}catch{}},50)});return v.observe(m),()=>{l.current=!1,v.disconnect(),g&&clearTimeout(g),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 jl={file_created:{icon:mr,color:"bg-blue-500",bgColor:"bg-blue-500/10",labelColor:"text-blue-600"},file_modified:{icon:ee,color:"bg-blue-400",bgColor:"bg-blue-400/10",labelColor:"text-blue-500"},dependency_install:{icon:Ql,color:"bg-teal-500",bgColor:"bg-teal-500/10",labelColor:"text-teal-600"},test_pass:{icon:Dt,color:"bg-green-500",bgColor:"bg-green-500/10",labelColor:"text-green-600"},test_fail:{icon:tr,color:"bg-red-500",bgColor:"bg-red-500/10",labelColor:"text-red-500"},error:{icon:tr,color:"bg-red-500",bgColor:"bg-red-500/10",labelColor:"text-red-500"},narration:{icon:Vl,color:"bg-purple-500",bgColor:"bg-purple-500/10",labelColor:"text-purple-600"},command:{icon:ns,color:"bg-gray-500",bgColor:"bg-gray-500/10",labelColor:"text-gray-600"},phase_change:{icon:Wt,color:"bg-primary",bgColor:"bg-primary/10",labelColor:"text-primary"},deploy:{icon:Wt,color:"bg-primary",bgColor:"bg-primary/10",labelColor:"text-primary"},warning:{icon:Ht,color:"bg-yellow-500",bgColor:"bg-yellow-500/10",labelColor:"text-yellow-600"},info:{icon:ql,color:"bg-gray-400",bgColor:"bg-gray-400/10",labelColor:"text-gray-500"}};function Nl(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return""}}function Z_({event:e,isLast:t,onFileClick:s}){const i=jl[e.type]||jl.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(ct,{size:10}),Nl(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(ct,{size:10}),Nl(e.timestamp)]})]})})]})}const Gr=20,El=10;function Q_({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>Gr},[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(Kl,{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>Gr&&n,l=a?e.slice(-El):e,h=a?e.length-El: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(ur,{size:12}),"Show ",h," earlier event",h!==1?"s":""]}),!n&&e.length>Gr&&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(fs,{size:12}),"Collapse older events"]}),l.map((c,u)=>r.jsx(Z_,{event:c,isLast:u===l.length-1,onFileClick:t},c.id))]})}const Dl=[{id:"terminal",label:"Terminal",icon:ns,alwaysShow:!0},{id:"activity",label:"Activity",icon:Md,alwaysShow:!0},{id:"build",label:"Build Log",icon:Cu},{id:"agents",label:"Agents",icon:Ld},{id:"quality",label:"Quality",icon:Gl}];function ex({status:e}){switch(e){case"pass":return r.jsx(Gt,{size:14,className:"text-success"});case"fail":return r.jsx(_t,{size:14,className:"text-danger"});default:return r.jsx(ct,{size:14,className:"text-muted"})}}function tx({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(_d,{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 sx({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(Gl,{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(ex,{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 ix({logs:e,logsLoading:t,agents:s,checklist:i,sessionId:n,isRunning:o,subscribe:a,buildEvents:l,onFileClick:h}){var g;const[c,u]=d.useState("terminal"),m=s&&s.length>0,f=i&&i.items&&i.items.length>0,_=e&&e.length>0,p=Dl.filter(v=>!!(v.alwaysShow||v.id==="build"&&(_||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":(g=Dl.find(v=>v.id===c))==null?void 0:g.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(J_,{sessionId:n,isActive:c==="terminal"})}),c==="build"&&r.jsx(Rd,{logs:e,loading:t,subscribe:a}),c==="agents"&&r.jsx(tx,{agents:s}),c==="activity"&&r.jsx(Q_,{events:l||[],onFileClick:h}),c==="quality"&&r.jsx(sx,{checklist:i})]})]})}const Rl={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 rx({context:e="general",className:t=""}){const s=Rl[e]||Rl.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(pi,{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 Yr=[{id:"planning",label:"Plan",color:"bg-blue-500",textColor:"text-blue-500",icon:Jd},{id:"building",label:"Build",color:"bg-primary",textColor:"text-primary",icon:Bd},{id:"testing",label:"Test",color:"bg-teal",textColor:"text-teal",icon:ni},{id:"reviewing",label:"Review",color:"bg-warning",textColor:"text-warning",icon:os},{id:"complete",label:"Done",color:"bg-success",textColor:"text-success",icon:Dt}];function nx({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=Yr.findIndex(x=>x.id===e),_=s>0?Math.min(t/s*100,100):0,p=t>0?a/t:60,g=Math.max(0,s-t),v=Math.ceil(p*g),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:`${_}%`}}),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:Yr.map((x,C)=>{const j=C<f,w=C===f,D=x.icon;return r.jsxs("div",{className:`flex items-center gap-1 phase-indicator ${w?"phase-indicator-active":""} ${j?"phase-indicator-complete":""}`,children:[r.jsx("div",{className:`phase-icon-wrapper ${w?"phase-icon-active":""} ${j?"phase-icon-complete":""}`,children:j?r.jsx(Dt,{size:14,className:"text-success phase-check-enter"}):w?r.jsx(D,{size:14,className:`${x.textColor} phase-icon-spin`}):r.jsx(D,{size:14,className:"text-muted/40"})}),r.jsx("span",{className:`text-[11px] font-medium transition-all duration-300 ${w?"text-ink":j?"text-success":"text-muted/50"}`,children:x.label}),C<Yr.length-1&&r.jsx("div",{className:`mx-1 h-px w-4 transition-all duration-500 ${j?"bg-success":"bg-border"}`})]},x.id)})}),o&&e!=="complete"&&e!=="idle"&&r.jsx(rx,{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(is,{size:12}),"Iter ",t,"/",s]}),r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(ct,{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(ec,{size:12}),"$",i.toFixed(2)]})]})]})]})}const Xr=[{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 ox({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
224
224
  focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary
225
- 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(as,{size:10})]}),r.jsx(he,{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(Bs,{size:12}),a]})]})}function ax(){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(ns,{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(as,{size:10})]})]})}function lx({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(Dt,{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(he,{variant:"danger",size:"sm",icon:Au,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(he,{variant:"secondary",size:"sm",onClick:()=>o(!0),className:"w-full",children:["Connect ",e.name]})}),n&&r.jsx(ox,{platform:e,onConnect:c})]}):r.jsx(ax,{})})]})}function cx({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 W.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 g=await W.connectVercel(p);g.success&&(i(v=>({...v,vercel:{connected:!0,user:g.user}})),t==null||t({...s,vercel:{connected:!0,user:g.user}}))},[s,t]),u=d.useCallback(async p=>{const g=await W.connectNetlify(p);g.success&&(i(v=>({...v,netlify:{connected:!0,user:g.user}})),t==null||t({...s,netlify:{connected:!0,user:g.user}}))},[s,t]),m=d.useCallback(async p=>{await W.disconnectPlatform(p),i(v=>({...v,[p]:{connected:!1}}));const g={...s,[p]:{connected:!1}};t==null||t(g)},[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(pi,{size:20,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-sm text-muted ml-2",children:"Loading connections..."})]});const _=[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:[_," of ",Xr.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(bt,{size:14})})]}),e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("div",{className:"flex items-center gap-3",children:Xr.map(p=>{const g=s[p.id];return r.jsxs("div",{className:"flex items-center gap-1.5",title:`${p.name}: ${g.connected?`Connected as ${g.user}`:"Not connected"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${g.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(bt,{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(Bs,{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:Xr.map(p=>r.jsx(lx,{platform:p,status:s[p.id],onConnect:f[p.id],onDisconnect:()=>m(p.id)},p.id))})]})}const hx=[{id:"vercel",name:"Vercel",description:"Optimized for Next.js, React, and static sites. Global CDN with instant rollbacks.",icon:sn,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:sn,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 dx({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(he,{variant:"secondary",size:"sm",icon:Wt,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(pi,{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(Dt,{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(sn,{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(Gt,{size:12,className:"text-green-500"}):r.jsx(to,{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(as,{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(Bs,{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(he,{variant:"secondary",size:"sm",icon:Wt,onClick:s,disabled:c,className:"w-full",children:"Retry"})]})]})}function ux({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 W.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(he,{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(pi,{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(Dt,{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(Gt,{size:12,className:"text-green-500"}):r.jsx(to,{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(Bs,{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(he,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Retry"})]})]})}function fx({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 W.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(Wt,{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(lc,{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(cx,{compact:!0,onStatusChange:n})})]}),r.jsx("div",{className:"space-y-3",children:hx.map(u=>r.jsx(dx,{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(ux,{sessionId:e,disabled:l})]})})}const wh=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),Nt=wh?"Cmd":"Ctrl",Pl=[{keys:[`${Nt}+K`],label:"Open Command Palette",category:"navigation"},{keys:[`${Nt}+P`],label:"Quick open file",category:"navigation"},{keys:[`${Nt}+,`],label:"Open settings",category:"navigation"},{keys:[`${Nt}+S`],label:"Save file",category:"editor"},{keys:[`${Nt}+Z`],label:"Undo",category:"editor"},{keys:[`${Nt}+Shift+Z`],label:"Redo",category:"editor"},{keys:[`${Nt}+B`],label:"Start / stop build",category:"build"},{keys:[`${Nt}+\``],label:"Toggle terminal",category:"build"},{keys:["?"],label:"Show keyboard shortcuts",category:"general"},{keys:[`${Nt}+?`],label:"Show keyboard shortcuts (alt)",category:"general"},{keys:["Escape"],label:"Close modals",category:"general"}],mx={navigation:"Navigation",editor:"Editor",build:"Build",general:"General"},px=["navigation","editor","build","general"];function gx({onToggleTerminal:e,onToggleBuild:t}){const[s,i]=d.useState(!1),n=d.useCallback(o=>{var c,u;const a=wh?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 _x({open:e,onClose:t}){const[s,i]=d.useState("");d.useEffect(()=>{e&&i("")},[e]);const n=d.useMemo(()=>{if(!s.trim())return Pl;const a=s.toLowerCase();return Pl.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(xd,{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(_t,{size:16})})]}),r.jsx("div",{className:"px-4 py-2 border-b border-border",children:r.jsxs("div",{className:"relative",children:[r.jsx(os,{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:[px.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:mx[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 xx({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 Ch="pl_recent_commands",vx=5;function kh(){try{const e=localStorage.getItem(Ch);return e?JSON.parse(e):[]}catch{return[]}}function Jr(e){try{const t=kh().filter(s=>s!==e);t.unshift(e),localStorage.setItem(Ch,JSON.stringify(t.slice(0,vx)))}catch{}}function bx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:ee,ts:ee,tsx:ee,jsx:ee,py:ee,go:ee,rs:ee,rb:ee,sh:ee,html:ac,css:ro,json:io,md:mi}[t]||no}function yx(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 Ml({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 Sx({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),_=d.useRef(null),p=d.useRef(null),g=vd(e);bd(e,t),d.useEffect(()=>{e&&(a(""),h(0),u([]),f(!1),setTimeout(()=>{var S;return(S=_.current)==null?void 0:S.focus()},50))},[e]);const v=d.useMemo(()=>kh().map(N=>s.find(k=>k.id===N)).filter(Boolean),[s]),y=d.useMemo(()=>{if(!o.trim())return s.map(N=>({cmd:N,indices:[]}));const S=[];for(const N of s){const k=yx(o,N.label);if(k){const P=k[0]*10+(k[k.length-1]-k[0]);S.push({cmd:N,indices:k,score:P})}}return S.sort((N,k)=>N.score-k.score),S.map(N=>({cmd:N.cmd,indices:N.indices}))},[s,o]),x=d.useMemo(()=>o.trim()?y.filter(S=>S.cmd.category==="setting"):[],[y,o]),C=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 W.searchFiles(i,o);u(S.filter(N=>N.type==="file"))}catch{u([])}f(!1)},200),()=>{p.current&&clearTimeout(p.current)}},[o,i]);const j=!o.trim()&&v.length>0,w=d.useMemo(()=>{const S=[];return j&&v.forEach((N,k)=>S.push({type:"recent",index:k})),C.forEach((N,k)=>S.push({type:"command",index:k})),x.length>0&&x.forEach((N,k)=>S.push({type:"setting",index:k})),c.forEach((N,k)=>S.push({type:"file",index:k})),S},[j,v,C,x,c]),D=w.length;d.useEffect(()=>{h(0)},[o]);const B=d.useCallback(S=>{const N=w[S];if(N){if(N.type==="recent"){const k=v[N.index];k&&(Jr(k.id),k.action(),t())}else if(N.type==="command"){const k=C[N.index];k&&(Jr(k.cmd.id),k.cmd.action(),t())}else if(N.type==="setting"){const k=x[N.index];k&&(Jr(k.cmd.id),k.cmd.action(),t())}else if(N.type==="file"){const k=c[N.index];k&&n&&(n(k.path,k.name),t())}}},[w,v,C,x,c,n,t]),U=d.useCallback(S=>{S.key==="ArrowDown"?(S.preventDefault(),h(N=>Math.min(N+1,D-1))):S.key==="ArrowUp"?(S.preventDefault(),h(N=>Math.max(N-1,0))):S.key==="Enter"&&D>0?B(l):S.key==="Escape"&&t()},[D,l,B,t]);if(!e)return null;let G=0;const K=()=>G++,A=C.length>0,R=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:g,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(os,{size:18,className:"text-muted"}),r.jsx("input",{ref:_,value:o,onChange:S=>a(S.target.value),onKeyDown:U,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:[j&&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(ct,{size:10})," Recent"]}),v.map((S,N)=>{const k=K(),P=S.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{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"}),C.map((S,N)=>{const k=K(),P=S.cmd.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:o.trim()?r.jsx(Ml,{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)})]}),R&&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,N)=>{const k=K(),P=S.cmd.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:r.jsx(Ml,{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,N)=>{const k=K(),P=S.type==="directory"?oo:bx(S.name);return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{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..."}),D===0&&!L&&r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted",children:"No results found"})]})]})]})}const wx=d.lazy(()=>Qn(()=>import("./GitHubIssuesPanel-DyuNDMgD.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(e=>({default:e.GitHubIssuesPanel}))),Cx=d.lazy(()=>Qn(()=>import("./GitHubPRsPanel-BtAq20xF.js"),__vite__mapDeps([10,1,2,3,11,4,5,6,12,13,14,15,16,17,18,19,20,21,22,9,23,24,25,26,27,28,29,30,8,31,32,33,34,35,36,37,38])).then(e=>({default:e.GitHubPRsPanel}))),kx=d.lazy(()=>Qn(()=>Promise.resolve().then(()=>Wx),void 0).then(e=>({default:e.CICDPanel}))),jx=3e4,Nx={modified:r.jsx(ee,{size:13,className:"text-yellow-500"}),added:r.jsx(mr,{size:13,className:"text-green-500"}),deleted:r.jsx(so,{size:13,className:"text-red-400"}),renamed:r.jsx(ee,{size:13,className:"text-blue-400"}),untracked:r.jsx(tc,{size:13,className:"text-muted"})},Ex={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?"};function Dx({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(sc,{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 Ll({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:[Nx[e.status]||r.jsx(tc,{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:Ex[e.status]||"?"})]})}function Rx({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),[_,p]=d.useState(""),[g,v]=d.useState(!1),[y,x]=d.useState(null),[C,j]=d.useState(!1),[w,D]=d.useState(""),[B,U]=d.useState(!1),[G,K]=d.useState(!1),[A,R]=d.useState(""),[E,L]=d.useState(""),[S,N]=d.useState(!1),[k,P]=d.useState(null),[J,oe]=d.useState(!1),V=d.useCallback(async()=>{u(!0),f(null);try{const[z,xe,T]=await Promise.all([W.git.status(e),W.git.log(e),W.git.branches(e)]);n(z),a(xe),h(T)}catch(z){f(z instanceof Error?z.message:"Failed to load git data")}u(!1)},[e]);d.useEffect(()=>{V()},[V]);const Z=async()=>{if(!(!_.trim()||g)){v(!0),x(null);try{const z=await W.git.commit(e,_.trim());x(`Committed: ${z.hash}`),p(""),await V()}catch(z){x(`Error: ${z instanceof Error?z.message:"Commit failed"}`)}v(!1)}},ie=async()=>{if(!(!w.trim()||B)){U(!0);try{await W.git.createBranch(e,w.trim()),D(""),j(!1),await V()}catch(z){f(z instanceof Error?z.message:"Branch creation failed")}U(!1)}},ue=async z=>{try{await W.git.checkoutBranch(e,z),await V()}catch(xe){f(xe instanceof Error?xe.message:"Checkout failed")}},fe=async()=>{oe(!0);try{await W.git.push(e),await V()}catch(z){f(z instanceof Error?z.message:"Push failed")}oe(!1)},de=async()=>{if(!(!A.trim()||S)){N(!0),P(null);try{const z=await W.git.pr(e,A.trim(),E.trim());P(z.url),R(""),L(""),K(!1)}catch(z){P(`Error: ${z instanceof Error?z.message:"PR creation failed"}`)}N(!1)}},_e=(i==null?void 0:i.files.filter(z=>z.staged))||[],He=(i==null?void 0:i.files.filter(z=>!z.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(bt,{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(Bs,{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(he,{size:"sm",variant:"secondary",icon:bt,onClick:V,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(Gt,{size:10})," Clean"]}),r.jsx("div",{className:"flex-1"}),r.jsx("button",{onClick:V,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(bt,{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:ee,count:(i==null?void 0:i.files.length)||0},{id:"history",label:"History",icon:ct},{id:"branches",label:"Branches",icon:ze,count:l.length}].map(z=>r.jsxs("button",{onClick:()=>s(z.id),className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===z.id?"bg-primary/10 text-primary":"text-muted hover:text-ink"}`,children:[r.jsx(z.icon,{size:12}),z.label,z.count!==void 0&&z.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:z.count})]},z.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(Gt,{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:[_e.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 (",_e.length,")"]}),_e.map((z,xe)=>r.jsx(Ll,{file:z},`s-${xe}`))]}),He.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 (",He.length,")"]}),He.map((z,xe)=>r.jsx(Ll,{file:z},`u-${xe}`))]}),r.jsxs("div",{className:"mt-auto border-t border-border p-3 space-y-2 flex-shrink-0",children:[r.jsx("textarea",{value:_,onChange:z=>p(z.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(he,{size:"sm",icon:sc,onClick:Z,disabled:!_.trim()||g,loading:g,children:"Commit"}),r.jsx(he,{size:"sm",variant:"secondary",icon:ic,onClick:fe,loading:J,disabled:J,children:"Push"}),r.jsx(he,{size:"sm",variant:"ghost",icon:rn,onClick:()=>K(!G),children:"PR"})]}),y&&r.jsx("p",{className:`text-[11px] font-mono ${y.startsWith("Error")?"text-red-400":"text-green-500"}`,children:y}),k&&r.jsx("p",{className:"text-[11px] font-mono text-primary",children:k.startsWith("Error")?r.jsx("span",{className:"text-red-400",children:k}):r.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-primary/80",children:k})})]}),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:z=>R(z.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:z=>L(z.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(he,{size:"sm",icon:rn,onClick:de,disabled:!A.trim()||S,loading:S,children:"Create PR"}),r.jsx(he,{size:"sm",variant:"ghost",onClick:()=>K(!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(ct,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No commits yet"})]}):o.map((z,xe)=>r.jsx(Dx,{commit:z},xe))}),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:()=>j(!C),className:"flex items-center gap-1 text-xs text-primary hover:text-primary/80 font-medium",children:[r.jsx(pr,{size:12}),"New Branch"]})}),C&&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:z=>D(z.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:z=>{z.key==="Enter"&&ie()}}),r.jsx(he,{size:"sm",onClick:ie,disabled:!w.trim()||B,loading:B,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(z=>!z.remote).map((z,xe)=>r.jsxs("button",{onClick:()=>!z.current&&ue(z.name),disabled:z.current,className:`w-full text-left flex items-center gap-2 px-3 py-2 text-xs border-b border-border transition-colors ${z.current?"bg-primary/5":"hover:bg-hover cursor-pointer"}`,children:[r.jsx(ze,{size:13,className:z.current?"text-primary":"text-muted"}),r.jsx("span",{className:`font-mono ${z.current?"text-primary font-semibold":"text-ink"}`,children:z.name}),z.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-${xe}`)),l.filter(z=>z.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(z=>z.remote).map((z,xe)=>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:z.name})]},`r-${xe}`))]})]})]})]})]})}function Zr(){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(bt,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading..."})]})})}function Qr({sessionId:e,onPushed:t}){const[s,i]=d.useState(!1),[n,o]=d.useState(null),a=async()=>{i(!0),o(null);try{await W.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(ou,{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(he,{size:"sm",icon:ic,onClick:a,loading:s,children:"Push to GitHub"})}),n&&r.jsx("p",{className:"text-[11px] text-red-400 font-mono",children:n})]})})}function Px({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 g=await W.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<jx)&&!c.current){c.current=!0;try{const[v,y,x]=await Promise.allSettled([W.getGitHubIssues(e,"open",1),W.getGitHubPRs(e,"open",1),W.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(C=>C.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(bt,{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,_=[{id:"changes",label:"Changes",icon:ee,requiresRemote:!1},{id:"issues",label:"Issues",icon:Td,count:l.issues,requiresRemote:!0},{id:"prs",label:"PRs",icon:rn,count:l.prs,requiresRemote:!0},{id:"actions",label:"Actions",icon:Ut,count:l.actions,requiresRemote:!0}],p=_;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(g=>{const v=g.requiresRemote&&!f;return r.jsxs("button",{onClick:()=>s(g.id),disabled:v,className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===g.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(g.icon,{size:12}),g.label,g.count!==void 0&&g.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:g.count})]},g.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(lc,{size:10}),o.owner,"/",o.repo]})]}),r.jsxs("div",{className:"flex-1 overflow-hidden",children:[t==="changes"&&r.jsx(Rx,{sessionId:e}),t==="issues"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx(wx,{sessionId:e})}):r.jsx(Qr,{sessionId:e,onPushed:u})),t==="prs"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx(Cx,{sessionId:e})}):r.jsx(Qr,{sessionId:e,onPushed:u})),t==="actions"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(kx,{sessionId:e})})}):r.jsx(Qr,{sessionId:e,onPushed:u}))]})]})}function Mx({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 g=await W.getCheckpoints(e);i(g),m(null)}catch{m("Failed to load checkpoints")}o(!1)},[e]);d.useEffect(()=>{f();const g=setInterval(f,15e3);return()=>clearInterval(g)},[f]);const _=d.useCallback(async g=>{if(a)return;const v=s.find(x=>x.id===g);if(!(!v||!window.confirm(`Restore to checkpoint "${v.description}"?
225
+ 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(as,{size:10})]}),r.jsx(he,{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(Bs,{size:12}),a]})]})}function ax(){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(ns,{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(as,{size:10})]})]})}function lx({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(Dt,{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(he,{variant:"danger",size:"sm",icon:Au,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(he,{variant:"secondary",size:"sm",onClick:()=>o(!0),className:"w-full",children:["Connect ",e.name]})}),n&&r.jsx(ox,{platform:e,onConnect:c})]}):r.jsx(ax,{})})]})}function cx({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 W.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 g=await W.connectVercel(p);g.success&&(i(v=>({...v,vercel:{connected:!0,user:g.user}})),t==null||t({...s,vercel:{connected:!0,user:g.user}}))},[s,t]),u=d.useCallback(async p=>{const g=await W.connectNetlify(p);g.success&&(i(v=>({...v,netlify:{connected:!0,user:g.user}})),t==null||t({...s,netlify:{connected:!0,user:g.user}}))},[s,t]),m=d.useCallback(async p=>{await W.disconnectPlatform(p),i(v=>({...v,[p]:{connected:!1}}));const g={...s,[p]:{connected:!1}};t==null||t(g)},[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(pi,{size:20,className:"text-primary animate-spin"}),r.jsx("span",{className:"text-sm text-muted ml-2",children:"Loading connections..."})]});const _=[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:[_," of ",Xr.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(bt,{size:14})})]}),e&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("div",{className:"flex items-center gap-3",children:Xr.map(p=>{const g=s[p.id];return r.jsxs("div",{className:"flex items-center gap-1.5",title:`${p.name}: ${g.connected?`Connected as ${g.user}`:"Not connected"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${g.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(bt,{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(Bs,{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:Xr.map(p=>r.jsx(lx,{platform:p,status:s[p.id],onConnect:f[p.id],onDisconnect:()=>m(p.id)},p.id))})]})}const hx=[{id:"vercel",name:"Vercel",description:"Optimized for Next.js, React, and static sites. Global CDN with instant rollbacks.",icon:sn,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:sn,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 dx({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(he,{variant:"secondary",size:"sm",icon:Wt,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(pi,{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(Dt,{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(sn,{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(Gt,{size:12,className:"text-green-500"}):r.jsx(to,{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(as,{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(Bs,{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(he,{variant:"secondary",size:"sm",icon:Wt,onClick:s,disabled:c,className:"w-full",children:"Retry"})]})]})}function ux({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 W.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(he,{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(pi,{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(Dt,{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(Gt,{size:12,className:"text-green-500"}):r.jsx(to,{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(Bs,{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(he,{variant:"secondary",size:"sm",icon:ze,onClick:a,disabled:t,className:"w-full",children:"Retry"})]})]})}function fx({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 W.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(Wt,{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(lc,{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(cx,{compact:!0,onStatusChange:n})})]}),r.jsx("div",{className:"space-y-3",children:hx.map(u=>r.jsx(dx,{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(ux,{sessionId:e,disabled:l})]})})}const wh=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),Nt=wh?"Cmd":"Ctrl",Pl=[{keys:[`${Nt}+K`],label:"Open Command Palette",category:"navigation"},{keys:[`${Nt}+P`],label:"Quick open file",category:"navigation"},{keys:[`${Nt}+,`],label:"Open settings",category:"navigation"},{keys:[`${Nt}+S`],label:"Save file",category:"editor"},{keys:[`${Nt}+Z`],label:"Undo",category:"editor"},{keys:[`${Nt}+Shift+Z`],label:"Redo",category:"editor"},{keys:[`${Nt}+B`],label:"Start / stop build",category:"build"},{keys:[`${Nt}+\``],label:"Toggle terminal",category:"build"},{keys:["?"],label:"Show keyboard shortcuts",category:"general"},{keys:[`${Nt}+?`],label:"Show keyboard shortcuts (alt)",category:"general"},{keys:["Escape"],label:"Close modals",category:"general"}],mx={navigation:"Navigation",editor:"Editor",build:"Build",general:"General"},px=["navigation","editor","build","general"];function gx({onToggleTerminal:e,onToggleBuild:t}){const[s,i]=d.useState(!1),n=d.useCallback(o=>{var c,u;const a=wh?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 _x({open:e,onClose:t}){const[s,i]=d.useState("");d.useEffect(()=>{e&&i("")},[e]);const n=d.useMemo(()=>{if(!s.trim())return Pl;const a=s.toLowerCase();return Pl.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(xd,{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(_t,{size:16})})]}),r.jsx("div",{className:"px-4 py-2 border-b border-border",children:r.jsxs("div",{className:"relative",children:[r.jsx(os,{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:[px.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:mx[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 xx({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 Ch="pl_recent_commands",vx=5;function kh(){try{const e=localStorage.getItem(Ch);return e?JSON.parse(e):[]}catch{return[]}}function Jr(e){try{const t=kh().filter(s=>s!==e);t.unshift(e),localStorage.setItem(Ch,JSON.stringify(t.slice(0,vx)))}catch{}}function bx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:ee,ts:ee,tsx:ee,jsx:ee,py:ee,go:ee,rs:ee,rb:ee,sh:ee,html:ac,css:ro,json:io,md:mi}[t]||no}function yx(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 Ml({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 Sx({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),_=d.useRef(null),p=d.useRef(null),g=vd(e);bd(e,t),d.useEffect(()=>{e&&(a(""),h(0),u([]),f(!1),setTimeout(()=>{var S;return(S=_.current)==null?void 0:S.focus()},50))},[e]);const v=d.useMemo(()=>kh().map(N=>s.find(k=>k.id===N)).filter(Boolean),[s]),y=d.useMemo(()=>{if(!o.trim())return s.map(N=>({cmd:N,indices:[]}));const S=[];for(const N of s){const k=yx(o,N.label);if(k){const P=k[0]*10+(k[k.length-1]-k[0]);S.push({cmd:N,indices:k,score:P})}}return S.sort((N,k)=>N.score-k.score),S.map(N=>({cmd:N.cmd,indices:N.indices}))},[s,o]),x=d.useMemo(()=>o.trim()?y.filter(S=>S.cmd.category==="setting"):[],[y,o]),C=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 W.searchFiles(i,o);u(S.filter(N=>N.type==="file"))}catch{u([])}f(!1)},200),()=>{p.current&&clearTimeout(p.current)}},[o,i]);const j=!o.trim()&&v.length>0,w=d.useMemo(()=>{const S=[];return j&&v.forEach((N,k)=>S.push({type:"recent",index:k})),C.forEach((N,k)=>S.push({type:"command",index:k})),x.length>0&&x.forEach((N,k)=>S.push({type:"setting",index:k})),c.forEach((N,k)=>S.push({type:"file",index:k})),S},[j,v,C,x,c]),D=w.length;d.useEffect(()=>{h(0)},[o]);const B=d.useCallback(S=>{const N=w[S];if(N){if(N.type==="recent"){const k=v[N.index];k&&(Jr(k.id),k.action(),t())}else if(N.type==="command"){const k=C[N.index];k&&(Jr(k.cmd.id),k.cmd.action(),t())}else if(N.type==="setting"){const k=x[N.index];k&&(Jr(k.cmd.id),k.cmd.action(),t())}else if(N.type==="file"){const k=c[N.index];k&&n&&(n(k.path,k.name),t())}}},[w,v,C,x,c,n,t]),U=d.useCallback(S=>{S.key==="ArrowDown"?(S.preventDefault(),h(N=>Math.min(N+1,D-1))):S.key==="ArrowUp"?(S.preventDefault(),h(N=>Math.max(N-1,0))):S.key==="Enter"&&D>0?B(l):S.key==="Escape"&&t()},[D,l,B,t]);if(!e)return null;let G=0;const K=()=>G++,A=C.length>0,R=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:g,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(os,{size:18,className:"text-muted"}),r.jsx("input",{ref:_,value:o,onChange:S=>a(S.target.value),onKeyDown:U,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:[j&&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(ct,{size:10})," Recent"]}),v.map((S,N)=>{const k=K(),P=S.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{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"}),C.map((S,N)=>{const k=K(),P=S.cmd.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:o.trim()?r.jsx(Ml,{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)})]}),R&&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,N)=>{const k=K(),P=S.cmd.icon;return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2.5 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{size:16}),r.jsx("span",{className:"flex-1 text-left",children:r.jsx(Ml,{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,N)=>{const k=K(),P=S.type==="directory"?oo:bx(S.name);return r.jsxs("button",{onClick:()=>B(k),className:`w-full flex items-center gap-3 px-4 py-2 text-sm transition-colors ${k===l?"bg-primary/10 text-primary":"text-ink hover:bg-hover"}`,children:[r.jsx(P,{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..."}),D===0&&!L&&r.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted",children:"No results found"})]})]})]})}const wx=d.lazy(()=>Qn(()=>import("./GitHubIssuesPanel-DRlEeFuw.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(e=>({default:e.GitHubIssuesPanel}))),Cx=d.lazy(()=>Qn(()=>import("./GitHubPRsPanel-CCv6_I74.js"),__vite__mapDeps([10,1,2,3,11,4,5,6,12,13,14,15,16,17,18,19,20,21,22,9,23,24,25,26,27,28,29,8,30,31,32,33,34,35,36])).then(e=>({default:e.GitHubPRsPanel}))),kx=d.lazy(()=>Qn(()=>Promise.resolve().then(()=>Wx),void 0).then(e=>({default:e.CICDPanel}))),jx=3e4,Nx={modified:r.jsx(ee,{size:13,className:"text-yellow-500"}),added:r.jsx(mr,{size:13,className:"text-green-500"}),deleted:r.jsx(so,{size:13,className:"text-red-400"}),renamed:r.jsx(ee,{size:13,className:"text-blue-400"}),untracked:r.jsx(sc,{size:13,className:"text-muted"})},Ex={modified:"M",added:"A",deleted:"D",renamed:"R",untracked:"?"};function Dx({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(tc,{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 Ll({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:[Nx[e.status]||r.jsx(sc,{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:Ex[e.status]||"?"})]})}function Rx({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),[_,p]=d.useState(""),[g,v]=d.useState(!1),[y,x]=d.useState(null),[C,j]=d.useState(!1),[w,D]=d.useState(""),[B,U]=d.useState(!1),[G,K]=d.useState(!1),[A,R]=d.useState(""),[E,L]=d.useState(""),[S,N]=d.useState(!1),[k,P]=d.useState(null),[J,oe]=d.useState(!1),V=d.useCallback(async()=>{u(!0),f(null);try{const[z,xe,T]=await Promise.all([W.git.status(e),W.git.log(e),W.git.branches(e)]);n(z),a(xe),h(T)}catch(z){f(z instanceof Error?z.message:"Failed to load git data")}u(!1)},[e]);d.useEffect(()=>{V()},[V]);const Z=async()=>{if(!(!_.trim()||g)){v(!0),x(null);try{const z=await W.git.commit(e,_.trim());x(`Committed: ${z.hash}`),p(""),await V()}catch(z){x(`Error: ${z instanceof Error?z.message:"Commit failed"}`)}v(!1)}},ie=async()=>{if(!(!w.trim()||B)){U(!0);try{await W.git.createBranch(e,w.trim()),D(""),j(!1),await V()}catch(z){f(z instanceof Error?z.message:"Branch creation failed")}U(!1)}},ue=async z=>{try{await W.git.checkoutBranch(e,z),await V()}catch(xe){f(xe instanceof Error?xe.message:"Checkout failed")}},fe=async()=>{oe(!0);try{await W.git.push(e),await V()}catch(z){f(z instanceof Error?z.message:"Push failed")}oe(!1)},de=async()=>{if(!(!A.trim()||S)){N(!0),P(null);try{const z=await W.git.pr(e,A.trim(),E.trim());P(z.url),R(""),L(""),K(!1)}catch(z){P(`Error: ${z instanceof Error?z.message:"PR creation failed"}`)}N(!1)}},_e=(i==null?void 0:i.files.filter(z=>z.staged))||[],He=(i==null?void 0:i.files.filter(z=>!z.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(bt,{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(Bs,{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(he,{size:"sm",variant:"secondary",icon:bt,onClick:V,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(Gt,{size:10})," Clean"]}),r.jsx("div",{className:"flex-1"}),r.jsx("button",{onClick:V,className:"p-1 text-muted hover:text-ink rounded transition-colors",title:"Refresh",children:r.jsx(bt,{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:ee,count:(i==null?void 0:i.files.length)||0},{id:"history",label:"History",icon:ct},{id:"branches",label:"Branches",icon:ze,count:l.length}].map(z=>r.jsxs("button",{onClick:()=>s(z.id),className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===z.id?"bg-primary/10 text-primary":"text-muted hover:text-ink"}`,children:[r.jsx(z.icon,{size:12}),z.label,z.count!==void 0&&z.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:z.count})]},z.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(Gt,{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:[_e.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 (",_e.length,")"]}),_e.map((z,xe)=>r.jsx(Ll,{file:z},`s-${xe}`))]}),He.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 (",He.length,")"]}),He.map((z,xe)=>r.jsx(Ll,{file:z},`u-${xe}`))]}),r.jsxs("div",{className:"mt-auto border-t border-border p-3 space-y-2 flex-shrink-0",children:[r.jsx("textarea",{value:_,onChange:z=>p(z.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(he,{size:"sm",icon:tc,onClick:Z,disabled:!_.trim()||g,loading:g,children:"Commit"}),r.jsx(he,{size:"sm",variant:"secondary",icon:ic,onClick:fe,loading:J,disabled:J,children:"Push"}),r.jsx(he,{size:"sm",variant:"ghost",icon:nn,onClick:()=>K(!G),children:"PR"})]}),y&&r.jsx("p",{className:`text-[11px] font-mono ${y.startsWith("Error")?"text-red-400":"text-green-500"}`,children:y}),k&&r.jsx("p",{className:"text-[11px] font-mono text-primary",children:k.startsWith("Error")?r.jsx("span",{className:"text-red-400",children:k}):r.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-primary/80",children:k})})]}),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:z=>R(z.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:z=>L(z.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(he,{size:"sm",icon:nn,onClick:de,disabled:!A.trim()||S,loading:S,children:"Create PR"}),r.jsx(he,{size:"sm",variant:"ghost",onClick:()=>K(!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(ct,{size:28,className:"text-muted/30 mb-2"}),r.jsx("p",{className:"text-xs text-muted",children:"No commits yet"})]}):o.map((z,xe)=>r.jsx(Dx,{commit:z},xe))}),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:()=>j(!C),className:"flex items-center gap-1 text-xs text-primary hover:text-primary/80 font-medium",children:[r.jsx(pr,{size:12}),"New Branch"]})}),C&&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:z=>D(z.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:z=>{z.key==="Enter"&&ie()}}),r.jsx(he,{size:"sm",onClick:ie,disabled:!w.trim()||B,loading:B,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(z=>!z.remote).map((z,xe)=>r.jsxs("button",{onClick:()=>!z.current&&ue(z.name),disabled:z.current,className:`w-full text-left flex items-center gap-2 px-3 py-2 text-xs border-b border-border transition-colors ${z.current?"bg-primary/5":"hover:bg-hover cursor-pointer"}`,children:[r.jsx(ze,{size:13,className:z.current?"text-primary":"text-muted"}),r.jsx("span",{className:`font-mono ${z.current?"text-primary font-semibold":"text-ink"}`,children:z.name}),z.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-${xe}`)),l.filter(z=>z.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(z=>z.remote).map((z,xe)=>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:z.name})]},`r-${xe}`))]})]})]})]})]})}function Zr(){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(bt,{size:20,className:"text-muted animate-spin"}),r.jsx("span",{className:"text-xs text-muted",children:"Loading..."})]})})}function Qr({sessionId:e,onPushed:t}){const[s,i]=d.useState(!1),[n,o]=d.useState(null),a=async()=>{i(!0),o(null);try{await W.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(ou,{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(he,{size:"sm",icon:ic,onClick:a,loading:s,children:"Push to GitHub"})}),n&&r.jsx("p",{className:"text-[11px] text-red-400 font-mono",children:n})]})})}function Px({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 g=await W.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<jx)&&!c.current){c.current=!0;try{const[v,y,x]=await Promise.allSettled([W.getGitHubIssues(e,"open",1),W.getGitHubPRs(e,"open",1),W.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(C=>C.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(bt,{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,_=[{id:"changes",label:"Changes",icon:ee,requiresRemote:!1},{id:"issues",label:"Issues",icon:Td,count:l.issues,requiresRemote:!0},{id:"prs",label:"PRs",icon:nn,count:l.prs,requiresRemote:!0},{id:"actions",label:"Actions",icon:Ut,count:l.actions,requiresRemote:!0}],p=_;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(g=>{const v=g.requiresRemote&&!f;return r.jsxs("button",{onClick:()=>s(g.id),disabled:v,className:`flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-btn transition-colors ${t===g.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(g.icon,{size:12}),g.label,g.count!==void 0&&g.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:g.count})]},g.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(lc,{size:10}),o.owner,"/",o.repo]})]}),r.jsxs("div",{className:"flex-1 overflow-hidden",children:[t==="changes"&&r.jsx(Rx,{sessionId:e}),t==="issues"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx(wx,{sessionId:e})}):r.jsx(Qr,{sessionId:e,onPushed:u})),t==="prs"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx(Cx,{sessionId:e})}):r.jsx(Qr,{sessionId:e,onPushed:u})),t==="actions"&&(f?r.jsx(d.Suspense,{fallback:r.jsx(Zr,{}),children:r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(kx,{sessionId:e})})}):r.jsx(Qr,{sessionId:e,onPushed:u}))]})]})}function Mx({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 g=await W.getCheckpoints(e);i(g),m(null)}catch{m("Failed to load checkpoints")}o(!1)},[e]);d.useEffect(()=>{f();const g=setInterval(f,15e3);return()=>clearInterval(g)},[f]);const _=d.useCallback(async g=>{if(a)return;const v=s.find(x=>x.id===g);if(!(!v||!window.confirm(`Restore to checkpoint "${v.description}"?
226
226
 
227
- This will revert files to this checkpoint state.`))){l(g);try{await W.restoreCheckpoint(e,g),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(nn,{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=g=>{if(!g)return"";try{return new Date(g).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(nn,{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((g,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(g.id),onMouseLeave:()=>c(null),disabled:a!==null,className:`w-3.5 h-3.5 rounded-full border-2 transition-all cursor-pointer ${g.is_current?"bg-primary border-primary shadow-sm shadow-primary/30":a===g.id?"bg-warning border-warning animate-pulse":"bg-card border-border hover:border-primary hover:bg-primary/10"} ${a!==null&&a!==g.id?"opacity-50":""}`,title:`${g.description} -- Click to restore`}),h===g.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:g.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[g.timestamp&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(ct,{size:10}),p(g.timestamp)]}),g.files_changed>0&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(ee,{size:10}),g.files_changed," file",g.files_changed!==1?"s":""]}),g.iteration>0&&r.jsxs("span",{className:"text-[11px] text-muted",children:["Iter ",g.iteration]})]}),!g.is_current&&r.jsxs("div",{className:"flex items-center gap-1 mt-1.5 text-[11px] text-primary font-medium",children:[r.jsx(rc,{size:10}),"Click to restore"]}),g.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"})]})]})]},g.id))}),u&&r.jsx("span",{className:"text-[11px] text-danger flex-shrink-0",children:u})]})}function Lx({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 Bx({file:e,isSelected:t,onToggle:s}){const[i,n]=d.useState(!0),o=e.action==="add"?r.jsx(mr,{size:14,className:"text-success"}):e.action==="delete"?r.jsx(su,{size:14,className:"text-danger"}):r.jsx(ee,{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(fr,{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(pr,{size:10}),e.additions]}),e.deletions>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-danger",children:[r.jsx(nc,{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(Lx,{line:c},`${h}-${u}`))]},h))})]})}function Tx({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(_=>{const p=new Set(_);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(ee,{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(pr,{size:12}),e.total_additions]}),r.jsxs("span",{className:"flex items-center gap-1 text-danger",children:[r.jsx(nc,{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(_t,{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,_)=>{const p=f.action==="add"?"text-success":f.action==="delete"?"text-danger":"text-blue-500";return r.jsxs("button",{onClick:()=>h(_),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors ${_===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:g=>g.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(Bx,{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(oc,{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(Gt,{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(Yd,{size:14}),"Accept All"]})]})]})]})}function Zi(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 zx(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 Ax(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 No={pending:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:ct,label:"Queued"},running:{color:"text-[#553DE9]",bg:"bg-[#553DE9]/10",Icon:gr,label:"Running"},success:{color:"text-[#1FC5A8]",bg:"bg-[#1FC5A8]/10",Icon:Yl,label:"Success"},failed:{color:"text-[#C45B5B]",bg:"bg-[#C45B5B]/10",Icon:tr,label:"Failed"},cancelled:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:oc,label:"Cancelled"},skipped:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:Xl,label:"Skipped"}};function jh(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 Nh(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 Eo({status:e}){const t=No[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 Ox({step:e}){const t=Ax(e),s=No[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:Nh(e.startedAt,e.completedAt)}),r.jsx(Eo,{status:t})]})}function $x({job:e}){const[t,s]=d.useState(!1),i=zx(e),n=No[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(fs,{size:14,className:"text-[#939084]"}):r.jsx(fr,{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:Nh(e.startedAt,e.completedAt)}),r.jsx(Eo,{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(Ox,{step:o},o.number))})]})}function Ix({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 W.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(gr,{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 Fx({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=Zi(e),_=d.useCallback(async()=>{if(!(n||a)){l(!0),c(null);try{const g=await W.getWorkflowRunDetail(t,e.databaseId);o(g)}catch(g){c(g instanceof Error?g.message:"Failed to load run details")}finally{l(!1)}}},[t,e.databaseId,n,a]),p=()=>{const g=!s;i(g),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(fs,{size:14,className:"text-[#939084] flex-shrink-0"}):r.jsx(fr,{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(Eo,{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:jh(e.createdAt)})]})]}),r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:g=>g.stopPropagation(),className:"text-[#939084] hover:text-[#553DE9] transition-colors flex-shrink-0",title:"Open on GitHub",children:r.jsx(as,{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(gr,{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(Ht,{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(g=>r.jsx($x,{job:g},g.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(ns,{size:12}),u?"Hide full logs":"View full logs"]}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Ix,{sessionId:t,runId:e.databaseId})})]})]})]})}function Hx({sessionId:e,workflows:t,onClose:s,onDispatched:i}){var _;const[n,o]=d.useState(((_=t[0])==null?void 0:_.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 W.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(Ht,{size:12}),r.jsx("span",{className:"text-xs",children:u})]}),r.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[r.jsx(he,{size:"sm",variant:"ghost",onClick:s,children:"Cancel"}),r.jsx(he,{size:"sm",icon:Ut,onClick:f,loading:h,children:"Dispatch"})]})]})}function Eh({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),[_,p]=d.useState(null),g=d.useRef(null),v=t.some(D=>D.status==="in_progress"||D.status==="queued"||D.status==="waiting"||D.status==="requested"||D.status==="pending"),y=d.useCallback(async(D=!1)=>{if(e){D&&h(!0),u(null);try{const B=await W.getWorkflowRuns(e);s(B),a(""),p(new Date)}catch(B){const U=B instanceof Error?B.message:String(B);U.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."}):U.includes("not authenticated")||U.includes("401")?u({type:"not_authenticated",message:'The gh CLI is not authenticated. Run "gh auth login" in your terminal.'}):U.includes("Could not detect")?u({type:"no_repo",message:"No GitHub remote detected. Push this project to GitHub first."}):u({type:"generic",message:U})}finally{h(!1)}}},[e]),x=d.useCallback(async()=>{if(e)try{const D=await W.getWorkflows(e);n(D.filter(B=>B.state==="active"))}catch{n([])}},[e]);d.useEffect(()=>{y(!0),x()},[y,x]),d.useEffect(()=>(v&&e?g.current=setInterval(()=>y(!1),1e4):g.current&&(clearInterval(g.current),g.current=null),()=>{g.current&&clearInterval(g.current)}),[v,e,y]);const C=t.filter(D=>Zi(D)==="success").length,j=t.filter(D=>Zi(D)==="failed").length,w=t.filter(D=>{const B=Zi(D);return B==="running"||B==="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:[_&&r.jsxs("span",{className:"text-[10px] text-[#939084] flex items-center gap-1",children:[r.jsx(hc,{size:10}),jh(_.toISOString())]}),r.jsx(he,{size:"sm",variant:"ghost",icon:bt,onClick:()=>y(!0),children:"Refresh"}),i.length>0&&r.jsx(he,{size:"sm",icon:Ut,onClick:()=>f(!m),children:"Run Workflow"})]})]}),m&&e&&i.length>0&&r.jsx("div",{className:"mb-4",children:r.jsx(Hx,{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(Ht,{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(as,{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(Ht,{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(Ht,{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(Yl,{size:12}),C," passed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#C45B5B]",children:[r.jsx(tr,{size:12}),j," failed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#553DE9]",children:[r.jsx(gr,{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(D=>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"})]})},D))}),!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(D=>r.jsx(Fx,{run:D,sessionId:e},D.databaseId))})]})}const Wx=Object.freeze(Object.defineProperty({__proto__:null,CICDPanel:Eh},Symbol.toStringTag,{value:"Module"}));function Ux({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(Dt,{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 Kx({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 g="#1FC5A8",v="rgba(31, 197, 168, 0.15)";return p>1?(g="#C45B5B",v="rgba(196, 91, 91, 0.15)"):p>.75&&(g="#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:g,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:g})]})}function qx(){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 Vx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:{icon:ee,color:"text-yellow-600",label:"JavaScript"},jsx:{icon:ee,color:"text-yellow-500",label:"JSX"},ts:{icon:ee,color:"text-blue-500",label:"TypeScript"},tsx:{icon:ee,color:"text-blue-400",label:"TSX"},py:{icon:ee,color:"text-green-600",label:"Python"},html:{icon:ee,color:"text-orange-500",label:"HTML"},css:{icon:ro,color:"text-purple-500",label:"CSS"},json:{icon:io,color:"text-green-500",label:"JSON"},md:{icon:mi,color:"text-muted",label:"Markdown"},go:{icon:ee,color:"text-cyan-600",label:"Go"},rs:{icon:ee,color:"text-orange-600",label:"Rust"}}[t]||{icon:no,color:"text-muted",label:t.toUpperCase()||"Plain Text"}}function Gx(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 Bl(e){if(e<60)return`${e}s`;const t=Math.floor(e/60),s=e%60;return`${t}m ${s}s`}function Yx({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(""),[_,p]=d.useState(!1);d.useEffect(()=>{if(!n)return;const j=()=>f(Gx(n));j();const w=setInterval(j,5e3);return()=>clearInterval(w)},[n]);const g=d.useCallback(async()=>{const j=["Built with Loki Mode",c?`Session: ${c}`:"",h?`Build time: ${Bl(h)}`:"",u?`
227
+ This will revert files to this checkpoint state.`))){l(g);try{await W.restoreCheckpoint(e,g),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(on,{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=g=>{if(!g)return"";try{return new Date(g).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(on,{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((g,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(g.id),onMouseLeave:()=>c(null),disabled:a!==null,className:`w-3.5 h-3.5 rounded-full border-2 transition-all cursor-pointer ${g.is_current?"bg-primary border-primary shadow-sm shadow-primary/30":a===g.id?"bg-warning border-warning animate-pulse":"bg-card border-border hover:border-primary hover:bg-primary/10"} ${a!==null&&a!==g.id?"opacity-50":""}`,title:`${g.description} -- Click to restore`}),h===g.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:g.description}),r.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[g.timestamp&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(ct,{size:10}),p(g.timestamp)]}),g.files_changed>0&&r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx(ee,{size:10}),g.files_changed," file",g.files_changed!==1?"s":""]}),g.iteration>0&&r.jsxs("span",{className:"text-[11px] text-muted",children:["Iter ",g.iteration]})]}),!g.is_current&&r.jsxs("div",{className:"flex items-center gap-1 mt-1.5 text-[11px] text-primary font-medium",children:[r.jsx(rc,{size:10}),"Click to restore"]}),g.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"})]})]})]},g.id))}),u&&r.jsx("span",{className:"text-[11px] text-danger flex-shrink-0",children:u})]})}function Lx({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 Bx({file:e,isSelected:t,onToggle:s}){const[i,n]=d.useState(!0),o=e.action==="add"?r.jsx(mr,{size:14,className:"text-success"}):e.action==="delete"?r.jsx(su,{size:14,className:"text-danger"}):r.jsx(ee,{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(fr,{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(pr,{size:10}),e.additions]}),e.deletions>0&&r.jsxs("span",{className:"flex items-center gap-0.5 text-[11px] text-danger",children:[r.jsx(nc,{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(Lx,{line:c},`${h}-${u}`))]},h))})]})}function Tx({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(_=>{const p=new Set(_);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(ee,{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(pr,{size:12}),e.total_additions]}),r.jsxs("span",{className:"flex items-center gap-1 text-danger",children:[r.jsx(nc,{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(_t,{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,_)=>{const p=f.action==="add"?"text-success":f.action==="delete"?"text-danger":"text-blue-500";return r.jsxs("button",{onClick:()=>h(_),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors ${_===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:g=>g.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(Bx,{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(oc,{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(Gt,{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(Yd,{size:14}),"Accept All"]})]})]})]})}function Zi(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 zx(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 Ax(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 No={pending:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:ct,label:"Queued"},running:{color:"text-[#553DE9]",bg:"bg-[#553DE9]/10",Icon:gr,label:"Running"},success:{color:"text-[#1FC5A8]",bg:"bg-[#1FC5A8]/10",Icon:Yl,label:"Success"},failed:{color:"text-[#C45B5B]",bg:"bg-[#C45B5B]/10",Icon:tr,label:"Failed"},cancelled:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:oc,label:"Cancelled"},skipped:{color:"text-[#939084]",bg:"bg-[#939084]/10",Icon:Xl,label:"Skipped"}};function jh(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 Nh(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 Eo({status:e}){const t=No[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 Ox({step:e}){const t=Ax(e),s=No[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:Nh(e.startedAt,e.completedAt)}),r.jsx(Eo,{status:t})]})}function $x({job:e}){const[t,s]=d.useState(!1),i=zx(e),n=No[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(fs,{size:14,className:"text-[#939084]"}):r.jsx(fr,{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:Nh(e.startedAt,e.completedAt)}),r.jsx(Eo,{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(Ox,{step:o},o.number))})]})}function Ix({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 W.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(gr,{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 Fx({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=Zi(e),_=d.useCallback(async()=>{if(!(n||a)){l(!0),c(null);try{const g=await W.getWorkflowRunDetail(t,e.databaseId);o(g)}catch(g){c(g instanceof Error?g.message:"Failed to load run details")}finally{l(!1)}}},[t,e.databaseId,n,a]),p=()=>{const g=!s;i(g),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(fs,{size:14,className:"text-[#939084] flex-shrink-0"}):r.jsx(fr,{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(Eo,{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:jh(e.createdAt)})]})]}),r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",onClick:g=>g.stopPropagation(),className:"text-[#939084] hover:text-[#553DE9] transition-colors flex-shrink-0",title:"Open on GitHub",children:r.jsx(as,{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(gr,{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(Ht,{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(g=>r.jsx($x,{job:g},g.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(ns,{size:12}),u?"Hide full logs":"View full logs"]}),u&&r.jsx("div",{className:"mt-2",children:r.jsx(Ix,{sessionId:t,runId:e.databaseId})})]})]})]})}function Hx({sessionId:e,workflows:t,onClose:s,onDispatched:i}){var _;const[n,o]=d.useState(((_=t[0])==null?void 0:_.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 W.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(Ht,{size:12}),r.jsx("span",{className:"text-xs",children:u})]}),r.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[r.jsx(he,{size:"sm",variant:"ghost",onClick:s,children:"Cancel"}),r.jsx(he,{size:"sm",icon:Ut,onClick:f,loading:h,children:"Dispatch"})]})]})}function Eh({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),[_,p]=d.useState(null),g=d.useRef(null),v=t.some(D=>D.status==="in_progress"||D.status==="queued"||D.status==="waiting"||D.status==="requested"||D.status==="pending"),y=d.useCallback(async(D=!1)=>{if(e){D&&h(!0),u(null);try{const B=await W.getWorkflowRuns(e);s(B),a(""),p(new Date)}catch(B){const U=B instanceof Error?B.message:String(B);U.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."}):U.includes("not authenticated")||U.includes("401")?u({type:"not_authenticated",message:'The gh CLI is not authenticated. Run "gh auth login" in your terminal.'}):U.includes("Could not detect")?u({type:"no_repo",message:"No GitHub remote detected. Push this project to GitHub first."}):u({type:"generic",message:U})}finally{h(!1)}}},[e]),x=d.useCallback(async()=>{if(e)try{const D=await W.getWorkflows(e);n(D.filter(B=>B.state==="active"))}catch{n([])}},[e]);d.useEffect(()=>{y(!0),x()},[y,x]),d.useEffect(()=>(v&&e?g.current=setInterval(()=>y(!1),1e4):g.current&&(clearInterval(g.current),g.current=null),()=>{g.current&&clearInterval(g.current)}),[v,e,y]);const C=t.filter(D=>Zi(D)==="success").length,j=t.filter(D=>Zi(D)==="failed").length,w=t.filter(D=>{const B=Zi(D);return B==="running"||B==="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:[_&&r.jsxs("span",{className:"text-[10px] text-[#939084] flex items-center gap-1",children:[r.jsx(hc,{size:10}),jh(_.toISOString())]}),r.jsx(he,{size:"sm",variant:"ghost",icon:bt,onClick:()=>y(!0),children:"Refresh"}),i.length>0&&r.jsx(he,{size:"sm",icon:Ut,onClick:()=>f(!m),children:"Run Workflow"})]})]}),m&&e&&i.length>0&&r.jsx("div",{className:"mb-4",children:r.jsx(Hx,{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(Ht,{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(as,{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(Ht,{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(Ht,{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(Yl,{size:12}),C," passed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#C45B5B]",children:[r.jsx(tr,{size:12}),j," failed"]}),r.jsxs("span",{className:"flex items-center gap-1 text-[#553DE9]",children:[r.jsx(gr,{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(D=>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"})]})},D))}),!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(D=>r.jsx(Fx,{run:D,sessionId:e},D.databaseId))})]})}const Wx=Object.freeze(Object.defineProperty({__proto__:null,CICDPanel:Eh},Symbol.toStringTag,{value:"Module"}));function Ux({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(Dt,{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 Kx({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 g="#1FC5A8",v="rgba(31, 197, 168, 0.15)";return p>1?(g="#C45B5B",v="rgba(196, 91, 91, 0.15)"):p>.75&&(g="#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:g,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:g})]})}function qx(){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 Vx(e){var i;const t=((i=e.split(".").pop())==null?void 0:i.toLowerCase())||"";return{js:{icon:ee,color:"text-yellow-600",label:"JavaScript"},jsx:{icon:ee,color:"text-yellow-500",label:"JSX"},ts:{icon:ee,color:"text-blue-500",label:"TypeScript"},tsx:{icon:ee,color:"text-blue-400",label:"TSX"},py:{icon:ee,color:"text-green-600",label:"Python"},html:{icon:ee,color:"text-orange-500",label:"HTML"},css:{icon:ro,color:"text-purple-500",label:"CSS"},json:{icon:io,color:"text-green-500",label:"JSON"},md:{icon:mi,color:"text-muted",label:"Markdown"},go:{icon:ee,color:"text-cyan-600",label:"Go"},rs:{icon:ee,color:"text-orange-600",label:"Rust"}}[t]||{icon:no,color:"text-muted",label:t.toUpperCase()||"Plain Text"}}function Gx(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 Bl(e){if(e<60)return`${e}s`;const t=Math.floor(e/60),s=e%60;return`${t}m ${s}s`}function Yx({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(""),[_,p]=d.useState(!1);d.useEffect(()=>{if(!n)return;const j=()=>f(Gx(n));j();const w=setInterval(j,5e3);return()=>clearInterval(w)},[n]);const g=d.useCallback(async()=>{const j=["Built with Loki Mode",c?`Session: ${c}`:"",h?`Build time: ${Bl(h)}`:"",u?`
228
228
  Project: ${u.substring(0,100)}${u.length>100?"...":""}`:"",`
229
229
  https://autonomi.dev`].filter(Boolean).join(`
230
230
  `);try{await navigator.clipboard.writeText(j),p(!0),setTimeout(()=>p(!1),2e3)}catch{}},[c,h,u]);if(!e)return null;const v=Vx(t),y=v.icon,x=h?h*5:0,C=h&&x>0?(x/h).toFixed(1):null;return r.jsxs("div",{className:"flex items-center gap-3 px-3 py-1 bg-card border-t border-border text-[11px] font-mono text-muted select-none flex-shrink-0",children:[r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx(y,{size:12,className:v.color}),r.jsx("span",{children:v.label})]}),r.jsx("span",{className:"text-border",children:"|"}),r.jsxs("span",{children:[o," lines"]}),r.jsx("span",{className:"text-border",children:"|"}),r.jsxs("span",{children:["Ln ",a,", Col ",l]}),r.jsx("span",{className:"text-border",children:"|"}),r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Od,{size:11}),i?r.jsx("span",{className:"text-primary animate-pulse",children:"Saving..."}):s?r.jsx("span",{className:"text-warning",children:"Unsaved"}):n?r.jsxs("span",{className:"text-success",children:["Saved ",m]}):r.jsx("span",{children:"Saved"})]}),r.jsx("div",{className:"flex-1"}),h!=null&&h>0&&r.jsxs("span",{className:"flex items-center gap-1 text-success",children:[r.jsx(hc,{size:11}),r.jsxs("span",{children:["Built in ",Bl(h)]}),C&&r.jsxs("span",{className:"text-muted ml-1",children:[r.jsx(is,{size:10,className:"inline"})," ",C,"x faster"]})]}),c&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-border",children:"|"}),r.jsx("button",{onClick:g,className:"flex items-center gap-1 hover:text-primary transition-colors",title:"Copy build summary to clipboard",children:_?r.jsxs(r.Fragment,{children:[r.jsx(Gt,{size:11,className:"text-success"}),r.jsx("span",{className:"text-success",children:"Copied!"})]}):r.jsxs(r.Fragment,{children:[r.jsx(ao,{size:11}),r.jsx("span",{children:"Share"})]})})]})]})}const Xn=[{id:"desktop",label:"Desktop",icon:yd,width:"100%",frameWidth:1920,frameClass:"device-frame-desktop"},{id:"tablet",label:"Tablet",icon:Pu,width:"768px",frameWidth:768,frameClass:"device-frame-tablet"},{id:"mobile",label:"Mobile",icon:Du,width:"375px",frameWidth:375,frameClass:"device-frame-mobile"}];function Xx({selectedDevice:e,onDeviceChange:t,containerWidth:s}){return r.jsxs("div",{className:"flex items-center gap-1",children:[Xn.map(i=>{const n=i.icon,o=e===i.id;return r.jsx("button",{onClick:()=>t(i.id),title:`${i.label} (${i.frameWidth}px)`,className:`p-1.5 rounded transition-colors ${o?"bg-primary/10 text-primary":"text-muted hover:text-ink hover:bg-hover"}`,children:r.jsx(n,{size:14})},i.id)}),s!=null&&s>0&&r.jsxs("span",{className:"text-[10px] font-mono text-muted ml-1 tabular-nums",children:[s,"px"]})]})}function Jx(){const[e,t]=d.useState("desktop"),s=Xn.find(i=>i.id===e)||Xn[0];return{device:e,setDevice:t,iframeWidth:s.width,frameClass:s.frameClass,frameWidth:s.frameWidth}}const Zx=[75,100,125];function Qx({zoom:e,onZoomChange:t}){return r.jsx("div",{className:"flex items-center gap-0.5 border border-border rounded-btn",children:Zx.map(s=>r.jsxs("button",{onClick:()=>t(s),className:`px-2 py-1 text-[10px] font-medium transition-colors ${e===s?"bg-primary/10 text-primary":"text-muted hover:text-ink hover:bg-hover"}`,title:`Zoom ${s}%`,children:[s,"%"]},s))})}function ev({data:e,size:t=80}){const i=t/11,n=[];let o=0;for(let a=0;a<e.length;a++)o=(o<<5)-o+e.charCodeAt(a)|0;for(let a=0;a<11;a++){n[a]=[];for(let l=0;l<11;l++){const h=l<3&&a<3,c=l>=8&&a<3,u=l<3&&a>=8;if((h||c||u)&&(l===0||a===0||l===2||a===2||l===10||a===10||l===8||a===8)||(l===1&&a===1||l===9&&a===1||l===1&&a===9))n[a][l]=!0;else if(h||c||u)n[a][l]=!1;else{const _=o+l*17+a*31&65535;n[a][l]=_%3!==0}}}return r.jsx("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"bg-white rounded p-1",children:n.map((a,l)=>a.map((h,c)=>h?r.jsx("rect",{x:c*i,y:l*i,width:i,height:i,fill:"#201515"},`${c}-${l}`):null))})}function tv(){const[e,t]=d.useState(!1);return r.jsxs("div",{className:"relative",children:[r.jsx("button",{onClick:()=>t(s=>!s),className:"p-1.5 rounded text-muted hover:text-ink hover:bg-hover transition-colors",title:"Screenshot",children:r.jsx(Vd,{size:14})}),e&&r.jsx("div",{className:"absolute top-full right-0 mt-1 z-20 bg-card border border-border rounded-btn shadow-lg p-2 text-xs text-muted whitespace-nowrap",children:"Right-click the preview to save as image"})]})}function sv({url:e}){const[t,s]=d.useState(!1),i=d.useCallback(async()=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)}catch{}},[e]);return r.jsxs("button",{onClick:i,className:"p-1.5 rounded text-muted hover:text-ink hover:bg-hover transition-colors relative",title:"Copy preview URL",children:[t?r.jsx(Gt,{size:14,className:"text-success"}):r.jsx(to,{size:14}),t&&r.jsx("div",{className:"copy-toast",children:"Copied!"})]})}function iv({isFullscreen:e,onToggle:t}){return r.jsx("button",{onClick:t,className:"p-1.5 rounded text-muted hover:text-ink hover:bg-hover transition-colors",title:e?"Exit fullscreen":"Fullscreen preview",children:e?r.jsx(cc,{size:14}):r.jsx(ln,{size:14})})}function Tl({messages:e}){const[t,s]=d.useState(!1),i=e.slice(-5),n=i.some(o=>o.level==="error");return i.length===0?null:r.jsxs("div",{className:`border-t border-border bg-card ${t?"":"cursor-pointer"}`,children:[r.jsxs("button",{onClick:()=>s(o=>!o),className:"w-full flex items-center gap-2 px-3 py-1.5 text-[11px] font-mono hover:bg-hover transition-colors",children:[n?r.jsx(Bs,{size:12,className:"text-danger"}):r.jsx("span",{className:"w-3 h-3 rounded-full border border-muted/40 flex items-center justify-center text-[8px] text-muted",children:"i"}),r.jsxs("span",{className:`font-medium ${n?"text-danger":"text-muted"}`,children:["Console (",i.length,")"]}),r.jsx("div",{className:"flex-1"}),t?r.jsx(fs,{size:12}):r.jsx(ur,{size:12})]}),t&&r.jsx("div",{className:"max-h-32 overflow-y-auto terminal-scroll border-t border-border",children:i.map((o,a)=>r.jsxs("div",{className:`px-3 py-1 text-[11px] font-mono border-b border-border/50 last:border-b-0 ${o.level==="error"?"bg-danger/5 text-danger":o.level==="warn"?"bg-warning/5 text-warning":"text-muted"}`,children:[r.jsx("span",{className:"uppercase text-[9px] font-semibold mr-2 opacity-60",children:o.level}),o.message]},a))})]})}function rv({onClick:e,isRefreshing:t}){const[s,i]=d.useState(!1),n=d.useCallback(()=>{i(!0),e(),setTimeout(()=>i(!1),600)},[e]);return r.jsx("button",{onClick:n,className:"p-1.5 rounded text-muted hover:text-ink hover:bg-hover transition-colors",title:"Refresh preview",children:r.jsx(Dd,{size:14,className:s||t?"animate-spin-once":""})})}function zl(){return r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center bg-card p-8",children:[r.jsxs("div",{className:"w-full max-w-md space-y-4",children:[r.jsx("div",{className:"skeleton-shimmer h-10 w-full rounded"}),r.jsx("div",{className:"skeleton-shimmer h-32 w-full rounded"}),r.jsxs("div",{className:"flex gap-4",children:[r.jsx("div",{className:"skeleton-shimmer h-20 flex-1 rounded"}),r.jsx("div",{className:"skeleton-shimmer h-20 flex-1 rounded"}),r.jsx("div",{className:"skeleton-shimmer h-20 flex-1 rounded"})]}),r.jsx("div",{className:"skeleton-shimmer h-8 w-48 rounded mx-auto"})]}),r.jsx("p",{className:"text-xs text-muted mt-6 animate-pulse",children:"Loading preview..."})]})}function nv({url:e}){const[t,s]=d.useState(!1),i=d.useRef(null);return d.useEffect(()=>{if(!t)return;const n=o=>{i.current&&!i.current.contains(o.target)&&s(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[t]),r.jsxs("div",{className:"relative",ref:i,children:[r.jsx("button",{onClick:()=>s(n=>!n),className:"p-1.5 rounded text-muted hover:text-ink hover:bg-hover transition-colors text-[10px] font-semibold",title:"Show QR code",children:"QR"}),t&&r.jsxs("div",{className:"absolute top-full right-0 mt-1 z-30 bg-card border border-border rounded-btn shadow-lg p-3",children:[r.jsx(ev,{data:e,size:100}),r.jsx("p",{className:"text-[10px] text-muted text-center mt-2 max-w-[100px] truncate",children:e})]})]})}const Al={create:"bg-primary/8 text-primary border-primary/15 hover:bg-primary/15",improve:"bg-info/8 text-info border-info/15 hover:bg-info/15",fix:"bg-danger/8 text-danger border-danger/15 hover:bg-danger/15",test:"bg-teal/8 text-teal border-teal/15 hover:bg-teal/15",deploy:"bg-warning/8 text-warning border-warning/15 hover:bg-warning/15"};function ov(e){const{projectState:t,hasSession:s,files:i,lastError:n,phase:o}=e;if(!s||t==="empty")return[{label:"Build a SaaS dashboard",prompt:"Build a modern SaaS analytics dashboard with charts and dark mode",category:"create"},{label:"Create a CLI tool",prompt:"Create a CLI tool with commands, flags, and help text",category:"create"},{label:"Build a REST API",prompt:"Build a REST API with CRUD endpoints, authentication, and database",category:"create"},{label:"Make a landing page",prompt:"Create a beautiful landing page with hero, features, pricing, and CTA sections",category:"create"}];if(t==="failed"){const a=[{label:"Fix the build errors",prompt:"Fix all build errors and get the project to compile successfully",category:"fix"},{label:"Try a different approach",prompt:"The current approach has issues. Try an alternative implementation strategy",category:"fix"}];if(n){const l=n.length>60?n.slice(0,60)+"...":n;a.unshift({label:`Fix: ${l}`,prompt:`Fix this error: ${n}`,category:"fix"})}return a.push({label:"Add error handling",prompt:"Add comprehensive error handling and fallbacks throughout the codebase",category:"improve"}),a.slice(0,4)}if(t==="building")return[];if(t==="completed"||t==="idle"){const a=[],l=i==null?void 0:i.some(m=>m.path.toLowerCase().includes("auth")),h=i==null?void 0:i.some(m=>m.path.includes(".test.")||m.path.includes(".spec.")||m.path.includes("__tests__")),c=i==null?void 0:i.some(m=>m.path.endsWith(".css")||m.path.endsWith(".scss")),u=i==null?void 0:i.some(m=>m.path.includes("Dockerfile")||m.path.includes("docker-compose"));return l||a.push({label:"Add authentication",prompt:"Add user authentication with login, signup, and session management",category:"improve"}),h||a.push({label:"Add test suite",prompt:"Add comprehensive unit tests and integration tests for all major features",category:"test"}),a.push({label:"Improve the UI",prompt:"Improve the UI with better styling, animations, and responsive design",category:"improve"}),u||a.push({label:"Add Docker support",prompt:"Add Dockerfile and docker-compose.yml for containerized deployment",category:"deploy"}),l&&a.push({label:"Add role-based access",prompt:"Add role-based access control with admin, editor, and viewer roles",category:"improve"}),c||a.push({label:"Add dark mode",prompt:"Add a dark mode toggle with proper theme support across all components",category:"improve"}),a.push({label:"Add API docs",prompt:"Add OpenAPI/Swagger documentation for all API endpoints",category:"improve"}),a.push({label:"Performance optimization",prompt:"Optimize performance: add lazy loading, caching, code splitting, and minimize bundle size",category:"improve"}),a.slice(0,4)}return[]}function av(e){const{onSelect:t,className:s=""}=e,[i,n]=d.useState(!0),[o,a]=d.useState(!1),l=d.useMemo(()=>ov(e),[e.projectState,e.hasSession,e.files,e.lastError,e.phase]),[h,c]=d.useState(0);if(d.useEffect(()=>{if(l.length<=4)return;const m=setInterval(()=>{a(!0),setTimeout(()=>{c(f=>(f+1)%l.length),a(!1)},300)},3e4);return()=>clearInterval(m)},[l.length]),l.length===0||!i)return null;const u=l.slice(h,h+4).concat(h+4>l.length?l.slice(0,h+4-l.length):[]).slice(0,4);return r.jsxs("div",{className:`${s}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Sd,{size:12,className:"text-primary"}),r.jsx("span",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider",children:"Suggestions"})]}),r.jsx("div",{className:`flex flex-wrap gap-1.5 transition-opacity duration-300 ${o?"opacity-0":"opacity-100"}`,children:u.map((m,f)=>r.jsxs("button",{onClick:()=>t(m.prompt),className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium
@@ -245,13 +245,13 @@ https://autonomi.dev`].filter(Boolean).join(`
245
245
  `);Ze=ae.pop()||"";for(const yi of ae){if(!yi.trim())continue;const Sr=yi.split(`
246
246
  `);let Yt="",Qe="";for(const Ie of Sr)Ie.startsWith("event:")?Yt=Ie.slice(6).trim():Ie.startsWith("data:")&&(Qe=Ie.slice(5).trim());if(Yt==="output"&&Qe)try{const{line:Ie}=JSON.parse(Qe);o(Ue=>Qt(Ue,ht=>ht.role==="system"&&ht.isStreaming?{content:ht.content?ht.content+`
247
247
  `+Ie:Ie}:{}))}catch{}else if(Yt==="complete"&&Qe)try{const{returncode:Ie,files_changed:Ue}=JSON.parse(Qe);o(ht=>Qt(ht,_s=>_s.role==="system"&&_s.isStreaming?{isStreaming:!1,filesChanged:Ue,returncode:Ie,content:_s.content||"Done."}:{})),(Ue==null?void 0:Ue.length)>0&&s&&s(Ue)}catch{}else if(Yt==="error"&&Qe)try{const{error:Ie}=JSON.parse(Qe);o(Ue=>Qt(Ue,ht=>ht.role==="system"&&ht.isStreaming?{isStreaming:!1,content:`Error: ${Ie}`}:{}))}catch{}}}}catch(Q){if(Q instanceof DOMException&&Q.name==="AbortError")return;await _e(T)}finally{_(!1),m(!1),U.current=null,G.current=null,(q=w.current)==null||q.focus()}},[e,s,_e]),z=async()=>{var Ze;const T=a.trim();if(!T&&!p||u)return;m(!0),C(null);let Y,q,Q="";if(p){y(!0);try{Y=await xv(p.file);const We=await W.chatImageUpload(e,p.file);q=We.filename,Q=`[Attached image: ${We.filename} (id: ${We.image_id})] Make it look like this. `}catch{C("The attachment was refused and no message was sent. Use a valid PNG, JPEG, GIF, or WebP image up to 10 MiB."),y(!1),m(!1);return}y(!1)}const le=Q+(T||"Make changes based on this screenshot."),ke={role:"user",content:T||"Make changes based on this screenshot.",timestamp:new Date().toISOString(),imageUrl:Y,imageName:q},Pe={role:"system",content:"",timestamp:new Date().toISOString(),isStreaming:!0};o(We=>[...We,ke,Pe]),l(""),p&&R(p.previewUrl),g(null);try{const We=n.filter(ae=>ae.role==="user"||ae.role==="system"&&!ae.isStreaming&&ae.content).slice(-10).map(ae=>({role:ae.role==="user"?"user":"assistant",content:ae.content})),{task_id:ut}=await W.chatStart(e,le,h,We.length>0?We:void 0);await He(ut)}catch(We){o(ut=>Qt(ut,ae=>ae.role==="system"&&ae.isStreaming?{isStreaming:!1,content:`Error: ${We instanceof Error?We.message:"Request failed"}`}:{})),m(!1),(Ze=w.current)==null||Ze.focus()}};return r.jsxs("div",{ref:K,className:`flex flex-col h-full relative ${S?"ring-2 ring-primary ring-inset":""}`,onDragOver:ie,onDragLeave:ue,onDrop:fe,children:[S&&r.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-primary/5 backdrop-blur-sm",children:r.jsxs("div",{className:"flex flex-col items-center gap-2 text-primary",children:[r.jsx(la,{size:32}),r.jsx("span",{className:"text-sm font-medium",children:"Drop image here"})]})}),r.jsxs("div",{ref:j,className:"flex-1 overflow-y-auto p-3 space-y-3 terminal-scroll",children:[n.length===0&&r.jsxs("div",{className:"flex items-start gap-2 py-6 px-2",children:[r.jsx("div",{className:"bg-primary text-white w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0",children:"L"}),r.jsx("div",{className:"max-w-[80%] rounded-lg px-3 py-2 text-xs bg-hover text-ink border-l-2 border-primary/40",children:r.jsx("p",{className:"leading-relaxed",children:"Hey! I'm Loki, your AI coding companion. Tell me what you want to build and I'll make it happen."})})]}),n.map((T,Y)=>r.jsx(uv,{msg:T,msgIndex:Y},Y)),f&&r.jsx(dv,{})]}),r.jsxs("div",{className:"border-t border-border p-2 flex-shrink-0",children:[f&&r.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[r.jsxs("span",{className:"text-[10px] text-muted font-mono flex items-center gap-1.5",children:["Loki is thinking",r.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-primary animate-bounce",style:{animationDelay:"0ms"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-primary animate-bounce",style:{animationDelay:"150ms"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-primary animate-bounce",style:{animationDelay:"300ms"}})]})]}),r.jsxs("button",{onClick:de,className:"flex items-center gap-1 text-[10px] text-red-400 hover:text-red-300 transition-colors",children:[r.jsx(sr,{className:"w-2.5 h-2.5"}),"Stop"]})]}),!f&&(i==null?void 0:i.some(T=>T.fix_status==="fixing"))&&r.jsxs("div",{className:"flex items-center gap-1.5 mb-2 px-1",children:[r.jsx(Kl,{size:10,className:"text-yellow-400 animate-spin"}),r.jsxs("span",{className:"text-[10px] text-yellow-400 font-mono",children:["Auto-fixing: ",(xe=i.find(T=>T.fix_status==="fixing"))==null?void 0:xe.name]})]}),r.jsx("div",{className:"flex items-center gap-1 mb-2",children:["quick","standard","max"].map(T=>r.jsx("button",{onClick:()=>c(T),title:fv[T],className:`text-xs font-semibold px-3 py-1.5 rounded-btn transition-colors capitalize ${h===T?"bg-primary text-white":"text-muted hover:text-ink"}`,children:T},T))}),p&&r.jsxs("div",{role:"group","aria-label":"Selected attachment","aria-live":"polite",className:"flex items-center gap-2 mb-2 px-1",children:[r.jsxs("div",{className:"relative",children:[r.jsx("img",{src:p.previewUrl,alt:`Preview of ${p.file.name}`,className:"h-16 max-w-[120px] rounded border border-border object-cover"}),r.jsx("button",{onClick:L,className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-red-500 text-white rounded-full flex items-center justify-center hover:bg-red-600",title:"Remove image","aria-label":`Remove ${p.file.name}`,children:r.jsx(_t,{size:10})})]}),r.jsxs("div",{className:"min-w-0 text-[10px] text-muted",children:[r.jsx("p",{className:"truncate max-w-[180px] text-ink",title:p.file.name,children:p.file.name}),r.jsxs("p",{children:[p.file.type," · ",_v(p.file.size)]})]}),v&&r.jsx("span",{className:"text-[10px] text-primary animate-pulse",children:"Uploading..."})]}),x&&r.jsx("p",{role:"alert",className:"mb-2 px-1 text-[11px] text-red-400",children:x}),!f&&r.jsx(av,{projectState:n.length===0?"empty":"idle",hasSession:!!e,onSelect:T=>l(T),className:"mb-2"}),r.jsx("p",{id:"chat-attachment-guidance",className:"mb-1 px-1 text-[10px] text-muted",children:"Attach one PNG, JPEG, GIF, or WebP image up to 10 MiB."}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{ref:D,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"hidden",onChange:T=>{var q;const Y=(q=T.target.files)==null?void 0:q[0];Y&&E(Y),T.target.value=""}}),r.jsx("button",{ref:B,onClick:()=>{var T;return(T=D.current)==null?void 0:T.click()},disabled:u,className:"p-1.5 text-muted hover:text-primary rounded transition-colors disabled:opacity-50",title:"Attach image (or paste/drag-and-drop)","aria-label":"Attach image","aria-describedby":"chat-attachment-guidance",children:r.jsx(la,{size:16})}),r.jsxs("div",{className:"flex-1 relative",children:[r.jsx(hv,{visible:k,filter:J,selectedIndex:V,onSelect:T=>{var Q;const Y=a.lastIndexOf("@"),q=Y>=0?a.slice(0,Y):a;l(q+T+" "),P(!1),Z(0),(Q=w.current)==null||Q.focus()},onClose:()=>P(!1)}),r.jsx("textarea",{ref:w,value:a,onChange:T=>{const Y=T.target.value;l(Y);const q=Y.lastIndexOf("@");if(q>=0){const Q=Y.slice(q);/^@\w*$/.test(Q)?(P(!0),oe(Q),Z(0)):P(!1)}else P(!1)},onKeyDown:T=>{if(k){if(T.key==="ArrowDown"){T.preventDefault(),Z(Y=>Math.min(Y+1,Jn.length-1));return}if(T.key==="ArrowUp"){T.preventDefault(),Z(Y=>Math.max(Y-1,0));return}if(T.key==="Tab"||T.key==="Enter"&&!T.shiftKey){T.preventDefault();const Y=Jn.filter(q=>q.label.toLowerCase().includes(J.toLowerCase()));if(Y[V]){const q=a.lastIndexOf("@"),Q=q>=0?a.slice(0,q):a;l(Q+Y[V].label+" "),P(!1),Z(0)}return}if(T.key==="Escape"){P(!1);return}}T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),z())},placeholder:"Ask AI to modify your project... (Shift+Enter for new line)",rows:1,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",style:{maxHeight:"120px",overflow:"auto"},disabled:u})]}),f?r.jsx(he,{size:"sm",icon:sr,onClick:de,"aria-label":"Stop streaming",className:"bg-red-500/10 hover:bg-red-500/20 text-red-400",children:"Stop"}):r.jsx(he,{size:"sm",icon:ju,onClick:z,disabled:u||!a.trim()&&!p,"aria-label":"Send message",children:"Send"})]})]})]})}function bv(e){const t=[],s=e.gatePassRate*100;t.push({label:"Quality Gates",value:s,weight:.4,description:`${Math.round(s)}% of quality gates passing`});const i=Math.min(e.testCoverage,100);t.push({label:"Test Coverage",value:i,weight:.3,description:`${Math.round(i)}% code covered by tests`});const n=e.maxIterations>0?Math.min(e.iteration/e.maxIterations*100,100):50;t.push({label:"Iteration Progress",value:n,weight:.2,description:`${e.iteration}/${e.maxIterations} iterations completed`});const a={planning:30,building:50,testing:75,reviewing:90,complete:100,idle:0}[e.phase]??40;t.push({label:"Build Phase",value:a,weight:.1,description:`Currently in ${e.phase} phase`});const l=t.reduce((h,c)=>h+c.value*c.weight,0);return{score:Math.round(Math.min(l,100)),factors:t}}function Dh(e){return e>=80?{ring:"#1FC5A8",text:"text-success",bg:"bg-success/10",label:"High"}:e>=60?{ring:"#D4A03C",text:"text-warning",bg:"bg-warning/10",label:"Medium"}:{ring:"#C45B5B",text:"text-danger",bg:"bg-danger/10",label:"Low"}}function Ol({score:e,size:t=48}){const s=t<40?3:4,i=(t-s*2)/2,n=2*Math.PI*i,o=e/100*n,a=Dh(e);return r.jsxs("div",{className:"relative inline-flex items-center justify-center",style:{width:t,height:t},children:[r.jsxs("svg",{width:t,height:t,className:"-rotate-90",children:[r.jsx("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:"currentColor",className:"text-border",strokeWidth:s}),r.jsx("circle",{cx:t/2,cy:t/2,r:i,fill:"none",stroke:a.ring,strokeWidth:s,strokeLinecap:"round",strokeDasharray:n,strokeDashoffset:n-o,className:"transition-all duration-1000 ease-out"})]}),r.jsx("span",{className:`absolute text-center font-mono font-bold ${a.text}`,style:{fontSize:t<40?"10px":"12px"},children:e})]})}function yv(e){const[t,s]=d.useState(!1),{score:i,factors:n}=bv(e),o=Dh(i);return e.compact?r.jsxs("div",{className:"relative inline-flex items-center gap-1.5",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),children:[r.jsx(Ol,{score:i,size:28}),r.jsx("span",{className:`text-xs font-medium ${o.text}`,children:o.label}),t&&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 w-56",children:[r.jsxs("div",{className:"text-xs font-semibold text-ink mb-2",children:["AI Confidence: ",i,"%"]}),n.map(a=>r.jsxs("div",{className:"flex items-center justify-between text-[11px] text-muted mb-1",children:[r.jsx("span",{children:a.label}),r.jsxs("span",{className:"font-mono",children:[Math.round(a.value),"%"]})]},a.label))]}),r.jsx("div",{className:"w-2 h-2 bg-card border-r border-b border-border rotate-45 mx-auto -mt-1"})]})]}):r.jsxs("div",{className:"card p-4",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx(Ol,{score:i,size:56}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-semibold text-ink",children:"AI Confidence"}),r.jsxs("div",{className:`text-xs font-medium ${o.text} flex items-center gap-1`,children:[o.label," Confidence",r.jsxs("div",{className:"relative",children:[r.jsx(ql,{size:12,className:"text-muted cursor-help",onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1)}),t&&r.jsx("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 z-50 w-64 pointer-events-none",children:r.jsx("div",{className:"bg-card border border-border rounded-lg shadow-lg px-3 py-2",children:r.jsx("p",{className:"text-[11px] text-muted leading-relaxed",children:"Confidence is computed from quality gate pass rate (40%), test coverage (30%), iteration progress (20%), and build phase maturity (10%)."})})})]})]})]})]}),r.jsx("div",{className:"space-y-2.5",children:n.map(a=>r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-1",children:[r.jsx("span",{className:"text-xs text-secondary",children:a.label}),r.jsxs("span",{className:"text-xs font-mono text-muted",children:[Math.round(a.value),"%"]})]}),r.jsx("div",{className:"w-full h-1.5 bg-border rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all duration-700 ease-out ${a.value>=80?"bg-success":a.value>=60?"bg-warning":"bg-danger"}`,style:{width:`${Math.min(a.value,100)}%`}})}),r.jsx("p",{className:"text-[11px] text-muted mt-0.5",children:a.description})]},a.label))})]})}function Qi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function er(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function Sv(e){return e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function wv(e){return e>=90?{label:"Excellent",color:"text-success"}:e>=75?{label:"Good",color:"text-teal"}:e>=60?{label:"Fair",color:"text-warning"}:{label:"Needs Work",color:"text-danger"}}function Cs({icon:e,label:t,value:s,subtext:i,iconColor:n="text-primary"}){return r.jsxs("div",{className:"bg-hover/40 rounded-card p-3 flex flex-col items-center text-center",children:[r.jsx(e,{size:18,className:`${n} mb-1.5`}),r.jsx("div",{className:"text-lg font-bold font-mono text-ink leading-tight",children:s}),r.jsx("div",{className:"text-[11px] text-muted font-medium mt-0.5",children:t}),i&&r.jsx("div",{className:"text-[11px] text-muted/60 mt-0.5",children:i})]})}function Cv({phase:e,maxDuration:t}){const s=t>0?e.durationSecs/t*100:0,i={planning:"bg-info",building:"bg-primary",testing:"bg-teal",reviewing:"bg-warning"};return r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-[11px] text-secondary w-16 text-right flex-shrink-0",children:e.label}),r.jsxs("div",{className:"flex-1 h-4 bg-border rounded-sm overflow-hidden relative",children:[r.jsx("div",{className:`h-full rounded-sm transition-all duration-700 ease-out ${i[e.phase]||"bg-primary"}`,style:{width:`${s}%`}}),r.jsxs("span",{className:"absolute inset-0 flex items-center px-2 text-[10px] font-mono text-white mix-blend-difference",children:[er(e.durationSecs)," | ",Qi(e.tokenCount)," tokens"]})]}),r.jsxs("span",{className:"text-[11px] font-mono text-muted w-10 text-right flex-shrink-0",children:[Math.round(e.percentage),"%"]})]})}function kv({filesCreated:e,filesModified:t,linesGenerated:s,testsGenerated:i,testPassRate:n,totalTokens:o,phaseBreakdown:a,totalTimeSecs:l,qualityScore:h,totalCost:c,iterations:u,provider:m,onShare:f,className:_=""}){const[p,g]=d.useState(!0),v=wv(h),y=Math.max(...a.map(C=>C.durationSecs),1),x=()=>{const C=["Build Insights Summary","=====================",`Provider: ${m}`,`Total Time: ${er(l)}`,`Iterations: ${u}`,`Cost: $${c.toFixed(2)}`,"","Output:",` Files Created: ${e}`,` Files Modified: ${t}`,` Lines Generated: ${s}`,` Tests Generated: ${i}`,` Test Pass Rate: ${Math.round(n*100)}%`,"","Resources:",` Total Tokens: ${Qi(o)}`,` Quality Score: ${h}/100 (${v.label})`,"","Time Breakdown:",...a.map(j=>` ${j.label}: ${er(j.durationSecs)} (${Math.round(j.percentage)}%)`)].join(`
248
- `);f==null||f(C)};return r.jsxs("div",{className:`card overflow-hidden ${_}`,children:[r.jsxs("button",{onClick:()=>g(!p),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-hover/30 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(tn,{size:14,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Build Insights"}),r.jsx("span",{className:`text-[11px] font-medium px-2 py-0.5 rounded-pill ${h>=80?"bg-success/10 text-success":h>=60?"bg-warning/10 text-warning":"bg-danger/10 text-danger"}`,children:v.label})]}),r.jsx("span",{className:"text-muted",children:p?r.jsx(ur,{size:16}):r.jsx(fs,{size:16})})]}),p&&r.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[r.jsx(Cs,{icon:ee,label:"Files",value:String(e+t),subtext:`${e} new, ${t} modified`,iconColor:"text-primary"}),r.jsx(Cs,{icon:on,label:"Lines of Code",value:Sv(s),iconColor:"text-info"}),r.jsx(Cs,{icon:ni,label:"Tests",value:String(i),subtext:`${Math.round(n*100)}% passing`,iconColor:"text-teal"})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[r.jsx(Cs,{icon:is,label:"Tokens Used",value:Qi(o),iconColor:"text-warning"}),r.jsx(Cs,{icon:ct,label:"Build Time",value:er(l),subtext:`${u} iterations`,iconColor:"text-muted"}),r.jsx(Cs,{icon:Cd,label:"Quality",value:`${h}`,subtext:v.label,iconColor:v.color})]}),r.jsxs("div",{className:"flex items-center justify-between bg-hover/40 rounded-card px-3 py-2.5",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx($d,{size:14,className:"text-primary"}),r.jsx("span",{className:"text-xs font-medium text-ink",children:"Total Cost"})]}),r.jsxs("span",{className:"text-sm font-bold font-mono text-ink",children:["$",c.toFixed(2)]})]}),a.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Id,{size:12,className:"text-muted"}),r.jsx("span",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider",children:"Time Breakdown"})]}),r.jsx("div",{className:"space-y-1.5",children:a.map(C=>r.jsx(Cv,{phase:C,maxDuration:y},C.phase))})]}),a.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(is,{size:12,className:"text-muted"}),r.jsx("span",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider",children:"Token Distribution"})]}),r.jsx("div",{className:"flex h-3 rounded-full overflow-hidden bg-border",children:a.map(C=>{const j={planning:"bg-info",building:"bg-primary",testing:"bg-teal",reviewing:"bg-warning"};return r.jsx("div",{className:`h-full transition-all duration-700 ${j[C.phase]||"bg-primary"}`,style:{width:`${C.percentage}%`},title:`${C.label}: ${Qi(C.tokenCount)} tokens (${Math.round(C.percentage)}%)`},C.phase)})}),r.jsx("div",{className:"flex items-center justify-between mt-1",children:a.map(C=>{const j={planning:"bg-info",building:"bg-primary",testing:"bg-teal",reviewing:"bg-warning"};return r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${j[C.phase]||"bg-primary"}`}),C.label]},C.phase)})})]}),f&&r.jsx("div",{className:"flex justify-end pt-1",children:r.jsxs("button",{onClick:x,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium
248
+ `);f==null||f(C)};return r.jsxs("div",{className:`card overflow-hidden ${_}`,children:[r.jsxs("button",{onClick:()=>g(!p),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-hover/30 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(tn,{size:14,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Build Insights"}),r.jsx("span",{className:`text-[11px] font-medium px-2 py-0.5 rounded-pill ${h>=80?"bg-success/10 text-success":h>=60?"bg-warning/10 text-warning":"bg-danger/10 text-danger"}`,children:v.label})]}),r.jsx("span",{className:"text-muted",children:p?r.jsx(ur,{size:16}):r.jsx(fs,{size:16})})]}),p&&r.jsxs("div",{className:"px-4 pb-4 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[r.jsx(Cs,{icon:ee,label:"Files",value:String(e+t),subtext:`${e} new, ${t} modified`,iconColor:"text-primary"}),r.jsx(Cs,{icon:an,label:"Lines of Code",value:Sv(s),iconColor:"text-info"}),r.jsx(Cs,{icon:ni,label:"Tests",value:String(i),subtext:`${Math.round(n*100)}% passing`,iconColor:"text-teal"})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[r.jsx(Cs,{icon:is,label:"Tokens Used",value:Qi(o),iconColor:"text-warning"}),r.jsx(Cs,{icon:ct,label:"Build Time",value:er(l),subtext:`${u} iterations`,iconColor:"text-muted"}),r.jsx(Cs,{icon:Cd,label:"Quality",value:`${h}`,subtext:v.label,iconColor:v.color})]}),r.jsxs("div",{className:"flex items-center justify-between bg-hover/40 rounded-card px-3 py-2.5",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx($d,{size:14,className:"text-primary"}),r.jsx("span",{className:"text-xs font-medium text-ink",children:"Total Cost"})]}),r.jsxs("span",{className:"text-sm font-bold font-mono text-ink",children:["$",c.toFixed(2)]})]}),a.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(Id,{size:12,className:"text-muted"}),r.jsx("span",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider",children:"Time Breakdown"})]}),r.jsx("div",{className:"space-y-1.5",children:a.map(C=>r.jsx(Cv,{phase:C,maxDuration:y},C.phase))})]}),a.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx(is,{size:12,className:"text-muted"}),r.jsx("span",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider",children:"Token Distribution"})]}),r.jsx("div",{className:"flex h-3 rounded-full overflow-hidden bg-border",children:a.map(C=>{const j={planning:"bg-info",building:"bg-primary",testing:"bg-teal",reviewing:"bg-warning"};return r.jsx("div",{className:`h-full transition-all duration-700 ${j[C.phase]||"bg-primary"}`,style:{width:`${C.percentage}%`},title:`${C.label}: ${Qi(C.tokenCount)} tokens (${Math.round(C.percentage)}%)`},C.phase)})}),r.jsx("div",{className:"flex items-center justify-between mt-1",children:a.map(C=>{const j={planning:"bg-info",building:"bg-primary",testing:"bg-teal",reviewing:"bg-warning"};return r.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${j[C.phase]||"bg-primary"}`}),C.label]},C.phase)})})]}),f&&r.jsx("div",{className:"flex justify-end pt-1",children:r.jsxs("button",{onClick:x,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium
249
249
  text-primary hover:bg-primary/5 rounded-card transition-colors`,children:[r.jsx(ao,{size:12}),"Share Insights"]})})]})]})}const $l=[1,2,5];function jv(e){const t=[];let s=0;const i=600,n=["planning","building","testing","reviewing","complete"],o=e.phases.length>0?e.phases:n;for(const a of o){if(t.push({timestamp:s,type:"phase_change",label:`Phase: ${a}`,phase:a}),s+=i,a==="building")for(const l of e.files.filter(h=>h.type==="file"))t.push({timestamp:s,type:"file_created",label:l.path,detail:l.path}),s+=i*.4;if(a==="testing"||a==="reviewing")for(const l of e.qualityGates){const h=l.status==="pass"?"gate_pass":"gate_fail";t.push({timestamp:s,type:h,label:l.label,phase:a}),s+=i*.3}}for(let a=1;a<=e.totalIterations;a++){const l=a/e.totalIterations*s;t.push({timestamp:l,type:"iteration",label:`Iteration ${a}/${e.totalIterations}`})}return t.sort((a,l)=>a.timestamp-l.timestamp),t}function Nv({path:e,visible:t,delay:s}){const i=e.split("/"),n=i[i.length-1],o=i.length-1;return r.jsxs("div",{className:`flex items-center gap-1.5 py-0.5 transition-all duration-500 ${t?"opacity-100 translate-x-0":"opacity-0 -translate-x-4"}`,style:{paddingLeft:`${o*16+8}px`,transitionDelay:`${s}ms`},children:[r.jsx(ee,{size:12,className:"text-primary flex-shrink-0"}),r.jsx("span",{className:"text-xs font-mono text-ink truncate",children:n})]})}function Ev({sessionId:e,files:t,phases:s,checkpoints:i,qualityGates:n,totalIterations:o,onShare:a}){var S,N;const[l,h]=d.useState(!1),[c,u]=d.useState(0),[m,f]=d.useState(0),[_,p]=d.useState(!1),g=d.useRef(null),v=d.useRef(0),y=d.useRef([]);y.current.length===0&&(y.current=jv({files:t,phases:s,qualityGates:n,totalIterations:o}));const x=y.current.length>0?y.current[y.current.length-1].timestamp+600:1,C=y.current.filter(k=>k.timestamp<=m),j=new Set(C.filter(k=>k.type==="file_created").map(k=>k.detail)),w=((S=[...C].reverse().find(k=>k.type==="phase_change"))==null?void 0:S.phase)||"idle",D=C.filter(k=>k.type==="gate_pass").length,B=C.filter(k=>k.type==="gate_fail").length,U=((N=[...C].reverse().find(k=>k.type==="iteration"))==null?void 0:N.label)||"",G=$l[c],K=d.useCallback(k=>{v.current===0&&(v.current=k);const P=(k-v.current)*G;v.current=k,f(J=>{const oe=J+P;return oe>=x?(h(!1),x):oe}),g.current=requestAnimationFrame(K)},[G,x]);d.useEffect(()=>(l?(v.current=0,g.current=requestAnimationFrame(K)):g.current&&cancelAnimationFrame(g.current),()=>{g.current&&cancelAnimationFrame(g.current)}),[l,K]);const A=()=>{h(!1),f(0)},R=k=>{f(Number(k.target.value))},E=()=>{const k=[`Build Replay: Session ${e}`,`Total iterations: ${o}`,`Files created: ${t.filter(P=>P.type==="file").length}`,`Quality gates: ${D} passed, ${B} failed`,`Phases: ${s.join(" > ")}`].join(`
250
250
  `);a==null||a(k)},L=x>0?m/x*100:0;return _?r.jsxs("div",{className:"card overflow-hidden",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-semibold text-ink uppercase tracking-wider",children:"Build Replay"}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsx("button",{onClick:()=>p(!1),className:"text-xs text-muted hover:text-ink transition-colors",children:"Collapse"})})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-0 min-h-[240px]",children:[r.jsxs("div",{className:"border-r border-border p-3 overflow-y-auto terminal-scroll max-h-[300px]",children:[r.jsx("div",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider mb-2",children:"File Tree"}),t.filter(k=>k.type==="file").length===0?r.jsx("div",{className:"text-xs text-muted py-4 text-center",children:"No files to display"}):t.filter(k=>k.type==="file").map((k,P)=>r.jsx(Nv,{path:k.path,visible:j.has(k.path),delay:P*30},k.path))]}),r.jsxs("div",{className:"p-3 overflow-y-auto terminal-scroll max-h-[300px]",children:[r.jsx("div",{className:"text-[11px] font-semibold text-muted uppercase tracking-wider mb-2",children:"Activity"}),r.jsx("div",{className:"space-y-1",children:C.slice(-20).map((k,P)=>r.jsxs("div",{className:"flex items-center gap-2 text-xs animate-fade-in",children:[k.type==="file_created"&&r.jsx(ee,{size:11,className:"text-primary flex-shrink-0"}),k.type==="phase_change"&&r.jsx(ct,{size:11,className:"text-info flex-shrink-0"}),k.type==="gate_pass"&&r.jsx(Dt,{size:11,className:"text-success flex-shrink-0"}),k.type==="gate_fail"&&r.jsx(Dt,{size:11,className:"text-danger flex-shrink-0"}),k.type==="iteration"&&r.jsx(Xl,{size:11,className:"text-muted flex-shrink-0"}),r.jsx("span",{className:`truncate ${k.type==="phase_change"?"font-semibold text-ink":k.type==="gate_fail"?"text-danger":"text-secondary"}`,children:k.label})]},`${k.timestamp}-${P}`))})]})]}),r.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-hover/50 border-t border-border text-xs text-muted",children:[r.jsx("span",{className:"font-medium text-ink capitalize",children:w}),r.jsxs("span",{children:[j.size," files"]}),r.jsxs("span",{className:"text-success",children:[D," passed"]}),B>0&&r.jsxs("span",{className:"text-danger",children:[B," failed"]}),U&&r.jsx("span",{className:"font-mono",children:U})]}),r.jsxs("div",{className:"px-4 py-2 border-t border-border",children:[r.jsx("div",{className:"relative w-full h-1.5 bg-border rounded-full overflow-hidden mb-2",children:r.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-teal rounded-full transition-all duration-100",style:{width:`${L}%`}})}),r.jsx("input",{type:"range",min:0,max:x,value:m,onChange:R,className:"w-full h-1 opacity-0 absolute cursor-pointer",style:{marginTop:"-14px"}})]}),r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-t border-border",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{onClick:()=>h(!l),className:"p-1.5 rounded-card hover:bg-hover transition-colors text-ink",title:l?"Pause":"Play",children:l?r.jsx(Zl,{size:16}):r.jsx(Ut,{size:16})}),r.jsx("button",{onClick:A,className:"p-1.5 rounded-card hover:bg-hover transition-colors text-muted",title:"Reset",children:r.jsx(rc,{size:14})}),r.jsxs("button",{onClick:()=>u((c+1)%$l.length),className:"px-2 py-1 rounded-card hover:bg-hover transition-colors text-xs font-mono text-muted",title:"Playback speed",children:[G,"x"]})]}),r.jsxs("button",{onClick:E,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/5 rounded-card transition-colors",children:[r.jsx(ao,{size:12}),"Share Replay"]})]})]}):r.jsxs("button",{onClick:()=>p(!0),className:"flex items-center gap-2 px-3 py-2 text-xs font-medium text-primary hover:bg-primary/5 rounded-card transition-colors",children:[r.jsx(Ut,{size:14}),"Replay Build"]})}function Dv(e){const t=e.toLowerCase().trim(),s=[];let i;const n=t.match(/where (?:is|are) (?:the )?(.+?)(?:\?|$)/);n&&s.push(...n[1].split(/\s+/).filter(l=>!["the","a","an","my"].includes(l)));const o=t.match(/show (?:me )?(?:all )?(.+?)(?:\?|$)/);o&&s.length===0&&s.push(...o[1].split(/\s+/).filter(l=>!["the","a","an","my","all"].includes(l)));const a=t.match(/find (?:the )?(.+?)(?:\?|$)/);return a&&s.length===0&&s.push(...a[1].split(/\s+/).filter(l=>!["the","a","an","my"].includes(l))),(t.includes("api endpoint")||t.includes("route")||t.includes("handler"))&&(i="api",s.length===0&&s.push("app.get","app.post","router","@app.route","endpoint")),(t.includes("database")||t.includes("db connection")||t.includes("schema"))&&s.length===0&&s.push("database","connection","schema","model","migration"),(t.includes("login")||t.includes("auth")||t.includes("authentication"))&&s.length===0&&s.push("auth","login","session","token","password"),(t.includes("test")||t.includes("spec"))&&(i="test",s.length===0&&s.push("describe","it(","test(","expect")),(t.includes("style")||t.includes("css")||t.includes("theme"))&&(i="css",s.length===0&&s.push("style","theme","color","font")),(t.includes("config")||t.includes("configuration")||t.includes("settings"))&&s.length===0&&s.push("config","settings","env","options"),s.length===0&&s.push(...t.split(/\s+/).filter(l=>l.length>2&&!["the","a","an","my","all","show","me","find","where","is","are","how"].includes(l))),{terms:s,filePattern:i}}function Rv(e,t){let s=0;const i=e.path.toLowerCase(),n=e.name.toLowerCase();for(const o of t){const a=o.toLowerCase();n===a?s+=100:n.includes(a)?s+=60:i.includes(a)&&(s+=30)}return s+=Math.max(0,20-e.path.split("/").length*2),s}const Pv=["Where is the login function?","Show me all API endpoints","Find the database connection","Where are the tests?","Show me the configuration files"];function Mv({sessionId:e,onOpenFile:t,className:s=""}){const[i,n]=d.useState(""),[o,a]=d.useState([]),[l,h]=d.useState(!1),[c,u]=d.useState(!1),[m,f]=d.useState(!1),_=d.useRef(null),p=d.useRef(null),g=d.useCallback(async w=>{if(!w.trim()||!e){a([]),f(!1);return}h(!0),f(!0);try{const{terms:D}=Dv(w),B=D.join(" "),G=(await W.searchFiles(e,B)).map(K=>({path:K.path,name:K.name,relevanceScore:Rv(K,D)}));G.sort((K,A)=>A.relevanceScore-K.relevanceScore),a(G.slice(0,15))}catch{a([])}finally{h(!1)}},[e]),v=w=>{n(w),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>g(w),400)},y=w=>{w.preventDefault(),p.current&&clearTimeout(p.current),g(i)},x=()=>{var w;n(""),a([]),f(!1),(w=_.current)==null||w.focus()},C=w=>{n(w),g(w)};d.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const j=w=>w.includes(".test.")||w.includes(".spec.")?"text-teal":w.endsWith(".css")||w.endsWith(".scss")?"text-pink":w.endsWith(".json")||w.endsWith(".yaml")?"text-warning":w.endsWith(".md")?"text-muted":"text-primary";return r.jsxs("div",{className:`card overflow-hidden ${s}`,children:[r.jsxs("div",{className:"px-4 pt-4 pb-2",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(os,{size:14,className:"text-primary"}),r.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Code Search"})]}),r.jsx("p",{className:"text-[11px] text-muted mb-3",children:'Search in natural language -- "Where is the login function?"'}),r.jsxs("form",{onSubmit:y,className:"relative",children:[r.jsx(os,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted"}),r.jsx("input",{ref:_,type:"text",value:i,onChange:w=>v(w.target.value),onFocus:()=>u(!0),onBlur:()=>setTimeout(()=>u(!1),200),placeholder:"Ask about your code...",className:`w-full pl-9 pr-8 py-2 text-sm bg-hover/50 border border-border rounded-card
251
251
  focus:border-primary focus:ring-1 focus:ring-primary/20 outline-none
252
252
  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(_t,{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:()=>C(w),className:`text-[11px] text-primary bg-primary/5 hover:bg-primary/10
253
253
  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(pi,{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,D)=>r.jsxs("button",{onClick:()=>t(w.path,w.lineNumber),className:`w-full flex items-center gap-3 px-4 py-2.5 text-left
254
254
  hover:bg-hover/50 transition-colors border-b border-border last:border-b-0
255
- group cursor-pointer`,children:[r.jsx(ee,{size:14,className:j(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(lu,{size:10}),w.lineNumber]}),r.jsx(eo,{size:12,className:"text-muted group-hover:text-primary transition-colors"})]})]},`${w.path}-${D}`))]})})]})}const hr={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"}},dr={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=hr[t]||hr.claude,n=dr[e]||dr.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 g=Math.round(h*p.pct),v=g*.4,y=g*.6,x=(v*i.input+y*i.output)/1e3;return{phase:p.phase,label:p.label,estimatedCost:x,estimatedTokens:g}}),u=c.reduce((p,g)=>p+g.estimatedCost,0),f=o*(e==="complex"?40:e==="simple"?15:25),_=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:_}}function Il(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=hr[t]||hr.claude,m=dr[e]||dr.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(ec,{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(is,{size:14,className:"text-primary mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:Il(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(ct,{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(is,{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(Fd,{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(ur,{size:12}):r.jsx(fs,{size:12}),"Cost breakdown by phase"]}),l&&r.jsx("div",{className:"space-y-2 mt-1 mb-2",children:c.breakdown.map(_=>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:_.label}),r.jsxs("span",{className:"text-[11px] text-muted font-mono",children:[Il(_.estimatedTokens)," tokens"]})]}),r.jsxs("span",{className:"text-xs font-mono font-semibold text-ink",children:["$",_.estimatedCost.toFixed(2)]})]},_.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(Ht,{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(he,{variant:"ghost",size:"sm",onClick:o,children:"Cancel"}),r.jsx(he,{variant:"primary",size:"sm",onClick:n,icon:is,children:"Start Build"})]})]})}function Tv({sessionId:e}){return r.jsx(Eh,{sessionId:e})}function Zn(e,t,s){var o;if(t==="directory")return s?r.jsx(an,{size:14}):r.jsx(oo,{size:14});const i=((o=e.split(".").pop())==null?void 0:o.toLowerCase())||"";return{js:r.jsx(ee,{size:14,className:"text-yellow-600"}),ts:r.jsx(ee,{size:14,className:"text-blue-500"}),tsx:r.jsx(ee,{size:14,className:"text-blue-400"}),jsx:r.jsx(ee,{size:14,className:"text-yellow-500"}),py:r.jsx(ee,{size:14,className:"text-green-600"}),html:r.jsx(ac,{size:14,className:"text-orange-500"}),css:r.jsx(ro,{size:14,className:"text-purple-500"}),json:r.jsx(io,{size:14,className:"text-green-500"}),md:r.jsx(mi,{size:14,className:"text-muted"}),go:r.jsx(ee,{size:14,className:"text-cyan-600"}),rs:r.jsx(ee,{size:14,className:"text-orange-600"}),rb:r.jsx(ee,{size:14,className:"text-red-500"}),sh:r.jsx(ee,{size:14,className:"text-green-600"})}[i]||r.jsx(no,{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 Rh(e,t){for(const s of e){if(s.path===t)return s.size;if(s.children){const i=Rh(s.children,t);if(i!==void 0)return i}}}function Ph(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Mh({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 _=new Set(f);return _.has(h.path)?_.delete(h.path):_.add(h.path),_}):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(fs,{size:14}):r.jsx(fr,{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:Zn(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:Ph(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(_t,{size:12})})]}),c&&u&&h.children&&r.jsx(Mh,{nodes:h.children,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o+1})]},h.path)})})}function Lh(e,t=""){const s=[];for(const i of e)i.type==="file"&&s.push({path:i.path,name:i.name}),i.children&&s.push(...Lh(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 W.getSecrets();t(y)}catch{}l(!1)},[]);d.useEffect(()=>{f()},[f]);const _=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 W.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 W.deleteSecret(y),await f()}catch(x){c(x instanceof Error?x.message:"Failed to delete secret")}},g=y=>{m(x=>{const C=new Set(x);return C.has(y)?C.delete(y):C.add(y),C})},v=Object.keys(e);return a?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(ri,{variant:"text",width:"180px",height:"16px"}),r.jsx(ri,{variant:"block",width:"100%",height:"60px"}),r.jsx(ri,{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(Ht,{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:()=>g(y),className:"text-muted hover:text-ink transition-colors",title:u.has(y)?"Hide value":"Show value",children:u.has(y)?r.jsx(Ad,{size:14}):r.jsx(ks,{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(so,{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:_,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(pr,{size:14}),"Add"]})]})]})]})})}function Ov({sessionId:e}){const[t,s]=d.useState(null),[i,n]=d.useState([]),[o,a]=d.useState(null),[l,h]=d.useState(""),[c,u]=d.useState(!0),[m,f]=d.useState(!1),[_,p]=d.useState(null),g=d.useCallback(async()=>{try{const x=await W.getDocsStatus(e);if(s(x),x.has_docs){const C=await W.getDocFiles(e);n(C.files)}}catch{}u(!1)},[e]);d.useEffect(()=>{g()},[g]);const v=async()=>{f(!0),p(null);try{await W.generateDocs(e);const x=setInterval(async()=>{try{const C=await W.getDocsStatus(e);if(C.has_docs){s(C);const j=await W.getDocFiles(e);n(j.files),f(!1),clearInterval(x)}}catch{}},3e3);setTimeout(()=>{clearInterval(x),f(!1)},3e5)}catch(x){p(x instanceof Error?x.message:"Failed to start doc generation"),f(!1)}},y=async x=>{try{const C=await W.getDocFileContent(e,x);a(x),h(C)}catch(C){p(C instanceof Error?C.message:"Failed to load doc file")}};return c?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(ri,{variant:"text",width:"180px",height:"16px"}),r.jsx(ri,{variant:"block",width:"100%",height:"60px"})]}):o?r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-hover",children:[r.jsxs("button",{onClick:()=>{a(null),h("")},className:"text-xs text-muted hover:text-ink flex items-center gap-1",children:[r.jsx(Jl,{size:14}),"Back to docs"]}),r.jsx("span",{className:"text-xs font-mono text-ink",children:o})]}),r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("pre",{className:"text-sm text-ink whitespace-pre-wrap font-mono leading-relaxed",children:l})})]}):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:"Documentation"}),_&&r.jsx("div",{className:"px-4 py-3 rounded-btn border border-error/30 bg-error/5 mb-4",children:r.jsx("p",{className:"text-xs text-error",children:_})}),(t==null?void 0:t.has_docs)&&t.coverage_pct>0&&r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-muted",children:"Coverage:"}),r.jsx("div",{className:"w-32 h-2 bg-border rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${Math.min(100,t.coverage_pct)}%`}})}),r.jsxs("span",{className:"text-xs font-mono text-ink",children:[t.coverage_pct,"%"]})]}),t.commits_behind>0&&r.jsxs("span",{className:"text-xs text-warning",children:[t.commits_behind," commit",t.commits_behind!==1?"s":""," behind"]})]}),r.jsx("div",{className:"flex gap-2 mb-6",children:t!=null&&t.has_docs?r.jsxs(he,{onClick:v,disabled:m,size:"sm",variant:"secondary",children:[r.jsx(bt,{size:14,className:m?"animate-spin":""}),m?"Updating...":"Update Docs"]}):r.jsx(he,{onClick:v,disabled:m,size:"sm",children:m?"Generating...":"Generate Documentation"})}),i.length>0?r.jsx("div",{className:"space-y-1",children:i.map(x=>r.jsxs("button",{onClick:()=>y(x.name),className:"w-full flex items-center gap-3 px-3 py-2 rounded-btn hover:bg-hover text-left transition-colors group",children:[r.jsx(mi,{size:14,className:"text-muted group-hover:text-ink flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm text-ink font-mono truncate block",children:x.name}),r.jsx("span",{className:"text-xs text-muted",children:x.size<1024?`${x.size} B`:`${(x.size/1024).toFixed(1)} KB`})]}),r.jsx("span",{className:"text-xs text-muted opacity-0 group-hover:opacity-100",children:"View"})]},x.name))}):t!=null&&t.has_docs?null:r.jsx("p",{className:"text-sm text-muted",children:'No documentation generated yet. Click "Generate Documentation" to create docs for this project.'}),(t==null?void 0:t.last_generated)&&r.jsxs("p",{className:"text-xs text-muted mt-4",children:["Last generated: ",new Date(t.last_generated).toLocaleString()]})]})})}function $v({session:e,onClose:t}){var ta;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,_]=d.useState("code"),[p,g]=d.useState(!1),[v,y]=d.useState(!1),[x,C]=d.useState(e),j=d.useRef(null),[w,D]=d.useState([]),[B,U]=d.useState(!1),[G,K]=d.useState(""),A=d.useRef(null),R=d.useRef(null),[E,L]=d.useState(0),[S,N]=d.useState(null),[k,P]=d.useState(!0),[J,oe]=d.useState(!0),[V,Z]=d.useState(!1),[ie,ue]=d.useState("overview"),fe=57374,[de,_e]=d.useState(null),He=d.useCallback(()=>{Z(b=>{const I=!b;return P(!I),oe(!I),I})},[]),[z,xe]=d.useState(()=>sessionStorage.getItem(`pl_buildmode_${x.id}`)||"standard"),[T,Y]=d.useState(()=>sessionStorage.getItem(`pl_provider_${x.id}`)||"claude"),[q,Q]=d.useState(null),[le,ke]=d.useState(null),[Pe,Ze]=d.useState(!1),[We,ut]=d.useState(!1),[ae,yi]=d.useState({phase:"idle",iteration:0,maxIterations:10,cost:0,startTime:0}),[Sr,Yt]=d.useState(!1),[Qe,Ie]=d.useState(null),Ue=d.useRef(null),[ht,_s]=d.useState(!1),[Bh,Do]=d.useState([]),[Ro,As]=d.useState(null),[Th,wr]=d.useState(!1),[zh,Si]=d.useState(!1),[Ah,Os]=d.useState(!1),[wi,Po]=d.useState("files"),{history:Mo,recordTokens:Lo}=qx(),[Oh,$h]=d.useState(null),[Bo,Ih]=d.useState({line:1,column:1}),[Fh,To]=d.useState(0),{device:Hh,setDevice:Wh,frameClass:zo}=Jx(),[Cr,Uh]=d.useState(100),[Ao,Kh]=d.useState(!1),[Ci,kr]=d.useState(!1),[Oo,Fv]=d.useState([]),xs=d.useRef(null),[qh,$o]=d.useState(0),{subscribe:Io}=kd(),et=d.useCallback(async()=>{try{const b=await W.getSessionDetail(x.id);C(b)}catch{}},[x.id]),Fo=d.useCallback(async()=>{try{await W.stopSession(),Ze(!1),ut(!1)}catch{}},[]),Vh=d.useCallback(async()=>{try{await W.pauseSession(),ut(!0)}catch{}},[]),Gh=d.useCallback(async()=>{try{await W.resumeSession(),ut(!1)}catch{}},[]),Ho=d.useRef("idle");d.useEffect(()=>{const b=async()=>{try{const F=await W.getStatus();Ze(F.running),ut(F.paused),F.provider&&Y(F.provider);const te=F.phase||"idle";if(te!==Ho.current&&te!=="idle"){const tt=new Date().toISOString(),Bt={starting:"Initialising build session",planning:"Planning phase started",building:"Building your project",testing:"Running tests",reviewing:"Reviewing code quality",complete:"Build complete"},kt={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."},Fs=[{id:`phase-${Date.now()}`,type:"phase_change",message:Bt[te]||`Phase: ${te}`,timestamp:tt}];kt[te]&&Fs.push({id:`narration-${Date.now()}`,type:"narration",message:kt[te],timestamp:tt}),Do(Mi=>[...Mi,...Fs]),Ho.current=te}yi({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 Ye=F.tokens_used;Ye!=null&&Lo(Ye)}catch{}};b();const I=setInterval(b,Pe?3e3:1e4);return()=>clearInterval(I)},[Pe,Lo]),d.useEffect(()=>{if(!(le!=null&&le.loading))return;const b=setInterval(()=>{ke(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(b)},[le==null?void 0:le.loading]);const[se,Yh]=d.useState(null);d.useEffect(()=>{W.getPreviewInfo(x.id).then(Yh).catch(()=>{})},[x.id]);const[$,ki]=d.useState(null),[$s,Wo]=d.useState(!1),[Uo,Ko]=d.useState(!1),[qo,ji]=d.useState(null),[Xt,Xh]=d.useState("");d.useEffect(()=>{const b=Io("file_changed",I=>{const F=I;if(!F.paths||F.paths.length===0)return;const te=new Date().toISOString(),Ye=F.paths.map((tt,Bt)=>{var Mi;const kt=(Mi=F.event_types)==null?void 0:Mi[Bt],Fs=kt==="created"||kt==="IN_CREATE";return{id:`file-${Date.now()}-${Bt}`,type:Fs?"file_created":"file_modified",message:Fs?`Created ${tt.split("/").pop()}`:`Modified ${tt.split("/").pop()}`,timestamp:te,filePath:tt}});if(Do(tt=>[...tt,...Ye]),Yt(!0),Ue.current&&clearTimeout(Ue.current),Ue.current=setTimeout(()=>Yt(!1),2e3),et(),s&&F.paths.some(Bt=>Bt===s||s.endsWith(Bt))&&Ie(s),f==="preview"){const tt=["react","vite","next","nuxt","svelte","remix"];($==null?void 0:$.running)&&($==null?void 0:$.framework)&&tt.some(kt=>$.framework.toLowerCase().includes(kt))||L(kt=>kt+1)}});return()=>{b(),Ue.current&&clearTimeout(Ue.current)}},[Io,s,f,$==null?void 0:$.running,et]);const Jh=d.useCallback(async()=>{if(!(!Qe||!x.id)){try{const b=await W.getSessionFileContent(x.id,Qe);l(b.content),c(b.content),g(!1),D(I=>I.map(F=>F.path===Qe?{...F,content:b.content,modified:!1}:F))}catch{}Ie(null)}},[Qe,x.id]);d.useEffect(()=>{if(f!=="preview")return;let b=!1;const I=async()=>{try{const te=await W.devserver.status(x.id);b||ki(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:${fe}/health`).then(b=>_e(b.ok)).catch(()=>_e(!1))},[f]);const vs=d.useCallback(async b=>{Wo(!0),ji(null);try{const I=await W.devserver.start(x.id,b);if(I.status==="error")ji(I.message||"Failed to start dev server");else{const F=await W.devserver.status(x.id);ki(F)}}catch(I){ji(I instanceof Error?I.message:"Failed to start dev server")}Wo(!1)},[x.id]),Vo=d.useRef(!1);d.useEffect(()=>{Vo.current||se!=null&&se.dev_command&&($!=null&&$.running||($==null?void 0:$.status)==="starting"||$s||(Vo.current=!0,vs(se.dev_command)))},[se==null?void 0:se.dev_command,$==null?void 0:$.running,$==null?void 0:$.status,$s,vs]);const Zh=d.useCallback(async()=>{try{await W.devserver.stop(x.id);const b=await W.devserver.status(x.id);ki(b)}catch{}},[x.id]),Qh=d.useCallback(async()=>{Ko(!0);try{const b=await W.fixProject(x.id);if(b.task_id){let F=0,te;do await new Promise(tt=>setTimeout(tt,2e3)),te=await W.chatPoll(x.id,b.task_id),F++;while(!te.complete&&F<150);const Ye=await W.devserver.status(x.id);ki(Ye)}}catch(b){ji(b instanceof Error?b.message:"Fix failed")}Ko(!1)},[x.id]),bs=$!=null&&$.running&&($!=null&&$.port)?$.framework==="expo"?`${en}/api/sessions/${encodeURIComponent(x.id)}/expo-qr`:$.portless_url||`http://localhost:${$.port}/`:null,ed=(se==null?void 0:se.preview_url)||`${en}/api/sessions/${encodeURIComponent(x.id)}/preview/index.html`,td=bs||ed,[Ni,Go]=d.useState([]),[wt,Ei]=d.useState(0);d.useEffect(()=>{const b=bs||(se==null?void 0:se.preview_url);b&&(Go([b]),Ei(0))},[bs,se==null?void 0:se.preview_url]);const Ct=Ni[wt]||td,[Yo,jr]=d.useState(Ct),sd=d.useCallback((b,I,F,te)=>{b.preventDefault(),N({x:b.clientX,y:b.clientY,path:I,name:F,type:te})},[]),id=d.useCallback(()=>{wt>0&&(Ei(b=>b-1),L(b=>b+1))},[wt]),rd=d.useCallback(()=>{wt<Ni.length-1&&(Ei(b=>b+1),L(b=>b+1))},[wt,Ni.length]),nd=d.useCallback(b=>{let I=b;if(b.startsWith("/")&&bs)try{I=`${new URL(bs).origin}${b}`}catch{const F=$==null?void 0:$.port;F&&(I=`http://localhost:${F}${b}`)}Go(F=>[...F.slice(0,wt+1),I]),Ei(F=>F+1),L(F=>F+1)},[wt,bs,$==null?void 0:$.port]);d.useEffect(()=>{try{const b=new URL(Ct,window.location.origin);jr(b.pathname+b.search+b.hash||"/")}catch{jr(Ct)}},[Ct]);const Di=d.useCallback(async()=>{ke({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.reviewProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Ri=d.useCallback(async()=>{ke({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.testProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Nr=d.useCallback(async()=>{ke({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.explainProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Er=d.useCallback(async(b,I)=>{if(window.confirm(`Delete "${I}"?`))try{await W.deleteSessionFile(x.id,b),s===b&&(i(null),o(""),l(null),c(null),g(!1)),await et()}catch(te){const Ye=te instanceof Error?te.message:"Unknown error";window.alert(`Delete failed: ${Ye}`)}},[x.id,s,et]),od=d.useCallback(b=>b.type==="file"?[{label:"Review",icon:ks,onClick:()=>{Di()}},{label:"Generate Tests",icon:ni,onClick:()=>{Ri()}},{label:"Explain",icon:Ys,onClick:()=>{Nr()}},{label:"Delete",icon:so,onClick:()=>{Er(b.path,b.name)},variant:"danger"}]:[{label:"Review Project",icon:ks,onClick:()=>{Di()}},{label:"Run Tests",icon:ni,onClick:()=>{Ri()}}],[Di,Ri,Nr,Er]),Lt=d.useCallback(async(b,I)=>{Ie(null),p&&s&&h!==null&&D(te=>te.map(Ye=>Ye.path===s?{...Ye,content:h,modified:!0}:Ye));const F=w.find(te=>te.path===b);if(F){i(b),o(I),l(F.content),c(F.content),g(F.modified);return}i(b),o(I),m(!0),g(!1);try{const te=x.id?await W.getSessionFileContent(x.id,b):await W.getFileContent(b);l(te.content),c(te.content),D(Ye=>[...Ye,{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]),Dr=d.useCallback(async()=>{var b;if(!(!s||h===null||!x.id)){y(!0);try{await W.saveSessionFile(x.id,s,h),l(h),g(!1),$h(Date.now()),D(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]),Xo=d.useCallback(b=>{const I=w.find(F=>F.path===b);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(D(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),g(te.modified)}else i(null),o(""),l(null),c(null),g(!1)}},[w,s]);d.useEffect(()=>{const b=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),p&&s&&Dr()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),U(F=>!F),K("")),(I.metaKey||I.ctrlKey)&&I.key==="k"&&(I.preventDefault(),_s(F=>!F)),I.key==="Escape"&&B&&U(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[p,s,Dr,B]),d.useEffect(()=>{B&&A.current&&A.current.focus()},[B]);const Jo=Lh(x.files),Is=G?Jo.filter(b=>b.path.toLowerCase().includes(G.toLowerCase())):Jo;d.useEffect(()=>{const b=x.files.find(I=>I.name==="index.html"&&I.type==="file");b&&Lt(b.path,b.name)},[]);const ad=d.useCallback(b=>{b!==void 0&&(c(b),g(b!==a),To(b.split(`
256
- `).length))},[a]),ld=d.useCallback(b=>{j.current=b;const I=b;if(I!=null&&I.onDidChangeCursorPosition&&I.onDidChangeCursorPosition(F=>{Ih({line:F.position.lineNumber,column:F.position.column})}),I!=null&&I.getModel){const F=I.getModel();F!=null&&F.getLineCount&&To(F.getLineCount())}},[]),cd=d.useCallback(async()=>{const b=window.prompt("New file name (e.g. src/utils.ts):");if(!(!b||!b.trim()))try{await W.createSessionFile(x.id,b.trim()),await et()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${F}`)}},[x.id,et]),hd=d.useCallback(async()=>{const b=window.prompt("New folder name (e.g. src/components):");if(!(!b||!b.trim()))try{await W.createSessionDirectory(x.id,b.trim()),await et()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${F}`)}},[x.id,et]),Zo=d.useCallback(async()=>{try{const b=await W.previewChanges(x.id,"preview current changes");As(b)}catch{}},[x.id]),dd=d.useCallback(()=>{As(null),et()},[et]),ud=d.useCallback(b=>{As(null),et()},[et]),fd=d.useCallback(()=>{As(null)},[]),Qo=s?Rh(x.files,s):void 0,md=((ta=n.split(".").pop())==null?void 0:ta.toUpperCase())||"",{showHelp:pd,setShowHelp:ea}=gx({onToggleBuild:()=>{Pe&&Fo()}}),gd=d.useMemo(()=>[{id:"preview",label:"Open Preview",category:"command",icon:ks,action:()=>_("preview"),shortcut:""},{id:"code",label:"Open Code Editor",category:"command",icon:on,action:()=>_("code")},{id:"terminal",label:"Open Terminal",category:"command",icon:ns,action:()=>oe(!0)},{id:"dashboard",label:"Open Dashboard",category:"command",icon:Rr,action:()=>_("dashboard")},{id:"deploy",label:"Deploy Project",category:"command",icon:Wt,action:()=>_("deploy")},{id:"git",label:"Git Status",category:"command",icon:ze,action:()=>_("git")},{id:"settings",label:"Settings / Config",category:"setting",icon:oa,action:()=>_("config")},{id:"quick-open",label:"Quick Open File",category:"file",icon:ee,action:()=>{U(!0),K("")},shortcut:"Cmd+P"},{id:"zen",label:"Toggle Zen Mode",category:"setting",icon:ln,action:()=>He()},{id:"sidebar",label:"Toggle File Tree",category:"setting",icon:aa,action:()=>P(b=>!b)},{id:"preview-changes",label:"Preview Pending Changes",category:"command",icon:ze,action:()=>Zo()},{id:"insights",label:"Build Insights",category:"command",icon:tn,action:()=>_("insights")},{id:"docs",label:"Documentation",category:"command",icon:Ys,action:()=>_("docs")},{id:"nl-search",label:"Natural Language Search",category:"command",icon:os,action:()=>Os(!0)}],[_,He,Zo]),Pi=d.useMemo(()=>{if(!Pe)return"idle";const b=(ae.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"},[Pe,ae.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}),Mo.length>=2&&r.jsx("div",{className:"flex items-center gap-1 border-l border-border pl-2 ml-1",children:r.jsx(Kx,{tokenHistory:Mo})}),r.jsxs("div",{className:"flex items-center gap-0.5 border-l border-border pl-2 ml-1",children:[r.jsx("button",{onClick:()=>P(b=>!b),title:k?"Hide file tree":"Show file tree",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:k?r.jsx(aa,{size:16}):r.jsx(Su,{size:16})}),r.jsx("button",{onClick:()=>oe(b=>!b),title:J?"Hide terminal/chat":"Show terminal/chat",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:J?r.jsx(xu,{size:16}):r.jsx(bu,{size:16})}),r.jsx("button",{onClick:He,title:V?"Exit zen mode":"Zen mode (hide all panels)",className:`p-1.5 rounded hover:bg-hover transition-colors ${V?"text-primary":"text-muted hover:text-ink"}`,children:V?r.jsx(cc,{size:16}):r.jsx(ln,{size:16})})]}),!Pe&&r.jsx(he,{variant:"primary",size:"sm",icon:Ut,onClick:()=>{if(!(x.prd||"").trim()){window.alert("No spec found for this project. Go to Home to start a new build.");return}Si(!0)},title:"Start build for this project",children:"Build"}),!Pe&&Pi==="complete"&&r.jsx(he,{variant:"ghost",size:"sm",icon:nn,onClick:()=>wr(!0),title:"Replay the build timeline",children:"Replay Build"}),r.jsx(Tt,{icon:os,label:"Natural language search",size:"sm",onClick:()=>Os(!0)}),Pe&&r.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[We?r.jsx(he,{variant:"ghost",size:"sm",icon:Ut,onClick:Gh,title:"Resume build",children:"Resume"}):r.jsx(he,{variant:"ghost",size:"sm",icon:Zl,onClick:Vh,title:"Pause build",children:"Pause"}),r.jsx(he,{variant:"danger",size:"sm",icon:sr,onClick:Fo,title:"Stop build",children:"Stop"})]}),r.jsx(Tt,{icon:ks,label:"Review project",size:"sm",onClick:Di,disabled:!!(le!=null&&le.loading)}),r.jsx(Tt,{icon:ni,label:"Run tests",size:"sm",onClick:Ri,disabled:!!(le!=null&&le.loading)}),r.jsx(Tt,{icon:Ys,label:"Explain project",size:"sm",onClick:Nr,disabled:!!(le!=null&&le.loading)}),r.jsx(he,{variant:"secondary",size:"sm",icon:Wt,onClick:()=>_("deploy"),title:"Deploy project",children:"Deploy"}),r.jsx(xx,{onClick:()=>ea(!0)})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1",children:r.jsx(nx,{phase:Pi,iteration:ae.iteration,maxIterations:ae.maxIterations,cost:ae.cost,startTime:ae.startTime,isRunning:Pe})}),Pe&&r.jsx("div",{className:"flex-shrink-0 pr-2",children:r.jsx(yv,{gatePassRate:.8,testCoverage:ae.iteration>2?60:20,iteration:ae.iteration,maxIterations:ae.maxIterations,phase:Pi,compact:!0})})]}),r.jsx(Mx,{sessionId:x.id,onRestore:et}),r.jsx("div",{className:"flex-1 min-h-0",children:r.jsxs(dn,{orientation:"vertical",children:[r.jsx(Zs,{defaultSize:70,minSize:40,children:r.jsxs(dn,{orientation:"horizontal",className:"h-full",children:[k&&r.jsx(Zs,{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:()=>Po("files"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${wi==="files"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(oo,{size:14}),"Files",Sr&&r.jsx("span",{className:"ml-1 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),r.jsxs("button",{onClick:()=>Po("chat"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${wi==="chat"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(Vl,{size:14}),"Chat"]}),wi==="files"&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[r.jsxs("button",{onClick:cd,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(mr,{size:12})," New"]}),r.jsxs("button",{onClick:hd,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(Pd,{size:12})," New"]})]})]}),wi==="files"?r.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:x.files.length>0?r.jsx(Mh,{nodes:x.files,selectedPath:s,onSelect:Lt,onDelete:Er,onContextMenu:sd}):r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(an,{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:z})})})]})}),k&&r.jsx(un,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),r.jsx(Zs,{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:on},{id:"preview",label:"Preview",icon:ks},{id:"deploy",label:"Deploy",icon:Wt},{id:"config",label:"Config",icon:oa},{id:"secrets",label:"Secrets",icon:du},{id:"prd",label:"Spec",icon:mi},{id:"dashboard",label:"Dashboard",icon:Rr},{id:"git",label:"Git",icon:ze},{id:"cicd",label:"CI/CD",icon:ze},{id:"insights",label:"Insights",icon:tn},{id:"docs",label:"Docs",icon:Ys}].map(b=>r.jsxs("button",{role:"tab","aria-selected":f===b.id,onClick:()=>_(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:()=>Lt(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:Zn(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(),Xo(b.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),Xo(b.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:r.jsx(_t,{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:Qo!=null?Ph(Qo):""}),r.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:md}),p&&r.jsx("button",{onClick:Dr,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"})]}),Qe===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(bt,{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:Jh,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:()=>Ie(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(jd,{}):r.jsx(Wi,{name:"Editor",children:r.jsx(Vf,{value:h??"",language:zv(n),theme:"vs",onChange:ad,onMount:ld,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(Yx,{selectedFile:s,fileName:n,isModified:p,isSaving:v,lastSavedAt:Oh,lineCount:Fh,cursorLine:Bo.line,cursorColumn:Bo.column,buildTime:ae.phase==="complete"&&ae.startTime?Math.floor((Date.now()-ae.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(ee,{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(Wi,{name:"Preview",children:r.jsxs("div",{className:`h-full flex flex-col ${Ao?"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(Tt,{icon:Jl,label:"Back",size:"sm",onClick:id,disabled:wt<=0}),r.jsx(Tt,{icon:eo,label:"Forward",size:"sm",onClick:rd,disabled:wt>=Ni.length-1}),r.jsx(rv,{onClick:()=>{kr(!0),L(b=>b+1)}}),r.jsx("input",{value:Yo,onChange:b=>jr(b.target.value),onKeyDown:b=>{b.key==="Enter"&&nd(Yo)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx(Xx,{selectedDevice:Hh,onDeviceChange:Wh,containerWidth:qh}),r.jsx(Qx,{zoom:Cr,onZoomChange:Uh}),r.jsx(sv,{url:Ct}),r.jsx(tv,{}),r.jsx(nv,{url:Ct}),r.jsx(Tt,{icon:as,label:"Open in new tab",size:"sm",onClick:()=>window.open(Ct,"_blank")}),r.jsx(iv,{isFullscreen:Ao,onToggle:()=>Kh(b=>!b)}),($==null?void 0:$.running)&&r.jsxs("button",{onClick:Zh,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(sr,{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:[Ci&&r.jsx(zl,{}),r.jsx("div",{ref:xs,className:`flex-1 bg-white overflow-auto flex justify-center ${Ci?"hidden":""}`,children:r.jsx("div",{className:`${zo} h-full preview-zoom-${Cr}`,children:r.jsx("iframe",{ref:R,src:Ct,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{kr(!1),xs.current&&$o(xs.current.clientWidth)}},E)})}),r.jsx(Tl,{messages:Oo})]}):se!=null&&se.preview_url?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[Ci&&r.jsx(zl,{}),r.jsx("div",{ref:xs,className:`flex-1 bg-white overflow-auto flex justify-center ${Ci?"hidden":""}`,children:r.jsx("div",{className:`${zo} h-full preview-zoom-${Cr}`,children:r.jsx("iframe",{ref:R,src:Ct,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{kr(!1),xs.current&&$o(xs.current.clientWidth)}},E)})}),r.jsx(Tl,{messages:Oo})]}):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(Hd,{size:28,className:"text-primary"}):se.type==="library"?r.jsx(Ql,{size:28,className:"text-primary"}):se.type==="go-app"||se.type==="rust-app"?r.jsx(ns,{size:28,className:"text-primary"}):r.jsx(an,{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:()=>vs(se.dev_command||void 0),disabled:$s,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(Ut,{size:12}),$s?"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:Xt,onChange:b=>Xh(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Xt.trim()&&vs(Xt.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:()=>Xt.trim()&&vs(Xt.trim()),disabled:$s||!Xt.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"})]})]})]}),qo&&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:qo})]}),($==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:Qh,disabled:Uo,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:Uo?"Fixing...":"Fix Error"}),r.jsx("button",{onClick:()=>vs(se.dev_command||Xt||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(`
257
- `)})]}),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:T})]}),r.jsx("div",{className:"flex gap-2",children:["claude","codex","gemini"].map(b=>r.jsx("button",{onClick:()=>{Y(b),sessionStorage.setItem(`pl_provider_${x.id}`,b),W.setProvider(b).catch(()=>{})},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${T===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:()=>{xe(b),sessionStorage.setItem(`pl_buildmode_${x.id}`,b)},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${z===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 spec found for this project."})]})}),f==="deploy"&&r.jsx(fx,{sessionId:x.id}),f==="dashboard"&&(de===!1?r.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center p-8 gap-4",children:[r.jsx(Rr,{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()=>{_e(null);try{const b=await fetch(`http://127.0.0.1:${fe}/health`);_e(b.ok)}catch{_e(!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:()=>ue(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:${fe}/`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted hover:text-primary flex items-center gap-1",children:["Open full dashboard ",r.jsx(as,{size:12})]})]}),r.jsx("iframe",{src:`http://127.0.0.1:${fe}/#${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(Px,{sessionId:x.id}),f==="cicd"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Tv,{sessionId:e.id})}),f==="docs"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Ov,{sessionId:x.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:ae.startTime?Math.floor((Date.now()-ae.startTime)/1e3):0,qualityScore:0,totalCost:ae.cost,iterations:ae.iteration,provider:T})})]})]})})]})}),J&&r.jsx(un,{className:"h-1 bg-border hover:bg-primary/30 cursor-row-resize"}),J&&r.jsx(Zs,{defaultSize:30,minSize:15,collapsible:!0,children:r.jsx(Wi,{name:"ActivityPanel",children:r.jsx(ix,{logs:null,logsLoading:!1,agents:null,checklist:null,sessionId:e.id,isRunning:x.status==="running"||x.status==="in_progress",buildMode:z,buildEvents:Bh,onFileClick:b=>Lt(b,b.split("/").pop()||b)})})})]})}),(le==null?void 0:le.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:[le.type==="review"?"Reviewing project":le.type==="test"?"Generating tests":"Analyzing project","..."]}),r.jsxs("span",{className:"text-xs font-mono text-muted",children:[le.elapsed,"s"]})]})}),q&&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(Tt,{icon:_t,label:"Close",size:"sm",onClick:()=>Q(null)})]}),r.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap",children:q})]}),S&&r.jsx(Rm,{x:S.x,y:S.y,items:od(S),onClose:()=>N(null)}),B&&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:()=>U(!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=>K(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"&&Is.length>0&&(Lt(Is[0].path,Is[0].name),U(!1)),b.key==="Escape"&&U(!1)}}),r.jsxs("div",{className:"max-h-64 overflow-y-auto",children:[Is.slice(0,20).map(b=>r.jsxs("button",{onClick:()=>{Lt(b.path,b.name),U(!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:Zn(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)),Is.length===0&&r.jsx("div",{className:"px-4 py-3 text-xs text-muted",children:"No matching files"})]})]})}),r.jsx(_x,{open:pd,onClose:()=>ea(!1)}),r.jsx(Sx,{isOpen:ht,onClose:()=>_s(!1),commands:gd,sessionId:x.id,onFileSelect:Lt}),Ro&&r.jsx(Tx,{data:Ro,onAcceptAll:dd,onAcceptSelected:ud,onReject:fd,onClose:()=>As(null)}),r.jsx(Ux,{phase:Pi,buildTime:ae.startTime?Math.floor((Date.now()-ae.startTime)/1e3):void 0}),Th&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>wr(!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:()=>wr(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(_t,{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:ae.iteration||ae.maxIterations})})]})}),Ah&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[15vh]",onClick:()=>Os(!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:()=>Os(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(_t,{size:16})})]}),r.jsx(Mv,{sessionId:x.id,onOpenFile:(b,I)=>{Lt(b,b.split("/").pop()||b),Os(!1)},className:"p-4"})]})}),zh&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>Si(!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:z==="quick"?"simple":z==="max"?"complex":"standard",provider:T,estimatedIterations:ae.maxIterations,onConfirm:async()=>{Si(!1);try{const b=x.prd||"";await W.startSession({prd:b,provider:T,projectDir:x.path}),Ze(!0)}catch(b){window.alert(`Failed to start: ${b instanceof Error?b.message:"Unknown error"}`)}},onCancel:()=>Si(!1)})})})]})}function Iv(){const{sessionId:e}=Nd(),t=Ed(),[s,i]=d.useState(null),[n,o]=d.useState(!0),[a,l]=d.useState(null);return d.useEffect(()=>{e&&(o(!0),l(null),W.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(Wi,{name:"ProjectWorkspace",children:r.jsx($v,{session:s,onClose:()=>t("/")})})})})}const kb=Object.freeze(Object.defineProperty({__proto__:null,default:Iv},Symbol.toStringTag,{value:"Module"}));export{gr as L,kb as P,ju as S};
255
+ group cursor-pointer`,children:[r.jsx(ee,{size:14,className:j(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(lu,{size:10}),w.lineNumber]}),r.jsx(eo,{size:12,className:"text-muted group-hover:text-primary transition-colors"})]})]},`${w.path}-${D}`))]})})]})}const hr={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"}},dr={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=hr[t]||hr.claude,n=dr[e]||dr.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 g=Math.round(h*p.pct),v=g*.4,y=g*.6,x=(v*i.input+y*i.output)/1e3;return{phase:p.phase,label:p.label,estimatedCost:x,estimatedTokens:g}}),u=c.reduce((p,g)=>p+g.estimatedCost,0),f=o*(e==="complex"?40:e==="simple"?15:25),_=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:_}}function Il(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=hr[t]||hr.claude,m=dr[e]||dr.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(ec,{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(is,{size:14,className:"text-primary mx-auto mb-1"}),r.jsx("div",{className:"text-xs font-mono font-semibold text-ink",children:Il(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(ct,{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(is,{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(Fd,{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(ur,{size:12}):r.jsx(fs,{size:12}),"Cost breakdown by phase"]}),l&&r.jsx("div",{className:"space-y-2 mt-1 mb-2",children:c.breakdown.map(_=>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:_.label}),r.jsxs("span",{className:"text-[11px] text-muted font-mono",children:[Il(_.estimatedTokens)," tokens"]})]}),r.jsxs("span",{className:"text-xs font-mono font-semibold text-ink",children:["$",_.estimatedCost.toFixed(2)]})]},_.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(Ht,{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(he,{variant:"ghost",size:"sm",onClick:o,children:"Cancel"}),r.jsx(he,{variant:"primary",size:"sm",onClick:n,icon:is,children:"Start Build"})]})]})}function Tv({sessionId:e}){return r.jsx(Eh,{sessionId:e})}function Zn(e,t,s){var o;if(t==="directory")return s?r.jsx(rn,{size:14}):r.jsx(oo,{size:14});const i=((o=e.split(".").pop())==null?void 0:o.toLowerCase())||"";return{js:r.jsx(ee,{size:14,className:"text-yellow-600"}),ts:r.jsx(ee,{size:14,className:"text-blue-500"}),tsx:r.jsx(ee,{size:14,className:"text-blue-400"}),jsx:r.jsx(ee,{size:14,className:"text-yellow-500"}),py:r.jsx(ee,{size:14,className:"text-green-600"}),html:r.jsx(ac,{size:14,className:"text-orange-500"}),css:r.jsx(ro,{size:14,className:"text-purple-500"}),json:r.jsx(io,{size:14,className:"text-green-500"}),md:r.jsx(mi,{size:14,className:"text-muted"}),go:r.jsx(ee,{size:14,className:"text-cyan-600"}),rs:r.jsx(ee,{size:14,className:"text-orange-600"}),rb:r.jsx(ee,{size:14,className:"text-red-500"}),sh:r.jsx(ee,{size:14,className:"text-green-600"})}[i]||r.jsx(no,{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 Rh(e,t){for(const s of e){if(s.path===t)return s.size;if(s.children){const i=Rh(s.children,t);if(i!==void 0)return i}}}function Ph(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Mh({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 _=new Set(f);return _.has(h.path)?_.delete(h.path):_.add(h.path),_}):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(fs,{size:14}):r.jsx(fr,{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:Zn(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:Ph(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(_t,{size:12})})]}),c&&u&&h.children&&r.jsx(Mh,{nodes:h.children,selectedPath:t,onSelect:s,onDelete:i,onContextMenu:n,depth:o+1})]},h.path)})})}function Lh(e,t=""){const s=[];for(const i of e)i.type==="file"&&s.push({path:i.path,name:i.name}),i.children&&s.push(...Lh(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 W.getSecrets();t(y)}catch{}l(!1)},[]);d.useEffect(()=>{f()},[f]);const _=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 W.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 W.deleteSecret(y),await f()}catch(x){c(x instanceof Error?x.message:"Failed to delete secret")}},g=y=>{m(x=>{const C=new Set(x);return C.has(y)?C.delete(y):C.add(y),C})},v=Object.keys(e);return a?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(ri,{variant:"text",width:"180px",height:"16px"}),r.jsx(ri,{variant:"block",width:"100%",height:"60px"}),r.jsx(ri,{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(Ht,{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:()=>g(y),className:"text-muted hover:text-ink transition-colors",title:u.has(y)?"Hide value":"Show value",children:u.has(y)?r.jsx(Ad,{size:14}):r.jsx(ks,{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(so,{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:_,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(pr,{size:14}),"Add"]})]})]})]})})}function Ov({sessionId:e}){const[t,s]=d.useState(null),[i,n]=d.useState([]),[o,a]=d.useState(null),[l,h]=d.useState(""),[c,u]=d.useState(!0),[m,f]=d.useState(!1),[_,p]=d.useState(null),g=d.useCallback(async()=>{try{const x=await W.getDocsStatus(e);if(s(x),x.has_docs){const C=await W.getDocFiles(e);n(C.files)}}catch{}u(!1)},[e]);d.useEffect(()=>{g()},[g]);const v=async()=>{f(!0),p(null);try{await W.generateDocs(e);const x=setInterval(async()=>{try{const C=await W.getDocsStatus(e);if(C.has_docs){s(C);const j=await W.getDocFiles(e);n(j.files),f(!1),clearInterval(x)}}catch{}},3e3);setTimeout(()=>{clearInterval(x),f(!1)},3e5)}catch(x){p(x instanceof Error?x.message:"Failed to start doc generation"),f(!1)}},y=async x=>{try{const C=await W.getDocFileContent(e,x);a(x),h(C)}catch(C){p(C instanceof Error?C.message:"Failed to load doc file")}};return c?r.jsxs("div",{className:"p-6 space-y-4",children:[r.jsx(ri,{variant:"text",width:"180px",height:"16px"}),r.jsx(ri,{variant:"block",width:"100%",height:"60px"})]}):o?r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-hover",children:[r.jsxs("button",{onClick:()=>{a(null),h("")},className:"text-xs text-muted hover:text-ink flex items-center gap-1",children:[r.jsx(Jl,{size:14}),"Back to docs"]}),r.jsx("span",{className:"text-xs font-mono text-ink",children:o})]}),r.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:r.jsx("pre",{className:"text-sm text-ink whitespace-pre-wrap font-mono leading-relaxed",children:l})})]}):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:"Documentation"}),_&&r.jsx("div",{className:"px-4 py-3 rounded-btn border border-error/30 bg-error/5 mb-4",children:r.jsx("p",{className:"text-xs text-error",children:_})}),(t==null?void 0:t.has_docs)&&t.coverage_pct>0&&r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-muted",children:"Coverage:"}),r.jsx("div",{className:"w-32 h-2 bg-border rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${Math.min(100,t.coverage_pct)}%`}})}),r.jsxs("span",{className:"text-xs font-mono text-ink",children:[t.coverage_pct,"%"]})]}),t.commits_behind>0&&r.jsxs("span",{className:"text-xs text-warning",children:[t.commits_behind," commit",t.commits_behind!==1?"s":""," behind"]})]}),r.jsx("div",{className:"flex gap-2 mb-6",children:t!=null&&t.has_docs?r.jsxs(he,{onClick:v,disabled:m,size:"sm",variant:"secondary",children:[r.jsx(bt,{size:14,className:m?"animate-spin":""}),m?"Updating...":"Update Docs"]}):r.jsx(he,{onClick:v,disabled:m,size:"sm",children:m?"Generating...":"Generate Documentation"})}),i.length>0?r.jsx("div",{className:"space-y-1",children:i.map(x=>r.jsxs("button",{onClick:()=>y(x.name),className:"w-full flex items-center gap-3 px-3 py-2 rounded-btn hover:bg-hover text-left transition-colors group",children:[r.jsx(mi,{size:14,className:"text-muted group-hover:text-ink flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm text-ink font-mono truncate block",children:x.name}),r.jsx("span",{className:"text-xs text-muted",children:x.size<1024?`${x.size} B`:`${(x.size/1024).toFixed(1)} KB`})]}),r.jsx("span",{className:"text-xs text-muted opacity-0 group-hover:opacity-100",children:"View"})]},x.name))}):t!=null&&t.has_docs?null:r.jsx("p",{className:"text-sm text-muted",children:'No documentation generated yet. Click "Generate Documentation" to create docs for this project.'}),(t==null?void 0:t.last_generated)&&r.jsxs("p",{className:"text-xs text-muted mt-4",children:["Last generated: ",new Date(t.last_generated).toLocaleString()]})]})})}function $v({session:e,onClose:t}){var ta;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,_]=d.useState("code"),[p,g]=d.useState(!1),[v,y]=d.useState(!1),[x,C]=d.useState(e),j=d.useRef(null),[w,D]=d.useState([]),[B,U]=d.useState(!1),[G,K]=d.useState(""),A=d.useRef(null),R=d.useRef(null),[E,L]=d.useState(0),[S,N]=d.useState(null),[k,P]=d.useState(!0),[J,oe]=d.useState(!0),[V,Z]=d.useState(!1),[ie,ue]=d.useState("overview"),fe=57374,[de,_e]=d.useState(null),He=d.useCallback(()=>{Z(b=>{const I=!b;return P(!I),oe(!I),I})},[]),[z,xe]=d.useState(()=>sessionStorage.getItem(`pl_buildmode_${x.id}`)||"standard"),[T,Y]=d.useState(()=>sessionStorage.getItem(`pl_provider_${x.id}`)||"claude"),[q,Q]=d.useState(null),[le,ke]=d.useState(null),[Pe,Ze]=d.useState(!1),[We,ut]=d.useState(!1),[ae,yi]=d.useState({phase:"idle",iteration:0,maxIterations:10,cost:0,startTime:0}),[Sr,Yt]=d.useState(!1),[Qe,Ie]=d.useState(null),Ue=d.useRef(null),[ht,_s]=d.useState(!1),[Bh,Do]=d.useState([]),[Ro,As]=d.useState(null),[Th,wr]=d.useState(!1),[zh,Si]=d.useState(!1),[Ah,Os]=d.useState(!1),[wi,Po]=d.useState("files"),{history:Mo,recordTokens:Lo}=qx(),[Oh,$h]=d.useState(null),[Bo,Ih]=d.useState({line:1,column:1}),[Fh,To]=d.useState(0),{device:Hh,setDevice:Wh,frameClass:zo}=Jx(),[Cr,Uh]=d.useState(100),[Ao,Kh]=d.useState(!1),[Ci,kr]=d.useState(!1),[Oo,Fv]=d.useState([]),xs=d.useRef(null),[qh,$o]=d.useState(0),{subscribe:Io}=kd(),et=d.useCallback(async()=>{try{const b=await W.getSessionDetail(x.id);C(b)}catch{}},[x.id]),Fo=d.useCallback(async()=>{try{await W.stopSession(),Ze(!1),ut(!1)}catch{}},[]),Vh=d.useCallback(async()=>{try{await W.pauseSession(),ut(!0)}catch{}},[]),Gh=d.useCallback(async()=>{try{await W.resumeSession(),ut(!1)}catch{}},[]),Ho=d.useRef("idle");d.useEffect(()=>{const b=async()=>{try{const F=await W.getStatus();Ze(F.running),ut(F.paused),F.provider&&Y(F.provider);const te=F.phase||"idle";if(te!==Ho.current&&te!=="idle"){const tt=new Date().toISOString(),Bt={starting:"Initialising build session",planning:"Planning phase started",building:"Building your project",testing:"Running tests",reviewing:"Reviewing code quality",complete:"Build complete"},kt={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."},Fs=[{id:`phase-${Date.now()}`,type:"phase_change",message:Bt[te]||`Phase: ${te}`,timestamp:tt}];kt[te]&&Fs.push({id:`narration-${Date.now()}`,type:"narration",message:kt[te],timestamp:tt}),Do(Mi=>[...Mi,...Fs]),Ho.current=te}yi({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 Ye=F.tokens_used;Ye!=null&&Lo(Ye)}catch{}};b();const I=setInterval(b,Pe?3e3:1e4);return()=>clearInterval(I)},[Pe,Lo]),d.useEffect(()=>{if(!(le!=null&&le.loading))return;const b=setInterval(()=>{ke(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(b)},[le==null?void 0:le.loading]);const[se,Yh]=d.useState(null);d.useEffect(()=>{W.getPreviewInfo(x.id).then(Yh).catch(()=>{})},[x.id]);const[$,ki]=d.useState(null),[$s,Wo]=d.useState(!1),[Uo,Ko]=d.useState(!1),[qo,ji]=d.useState(null),[Xt,Xh]=d.useState("");d.useEffect(()=>{const b=Io("file_changed",I=>{const F=I;if(!F.paths||F.paths.length===0)return;const te=new Date().toISOString(),Ye=F.paths.map((tt,Bt)=>{var Mi;const kt=(Mi=F.event_types)==null?void 0:Mi[Bt],Fs=kt==="created"||kt==="IN_CREATE";return{id:`file-${Date.now()}-${Bt}`,type:Fs?"file_created":"file_modified",message:Fs?`Created ${tt.split("/").pop()}`:`Modified ${tt.split("/").pop()}`,timestamp:te,filePath:tt}});if(Do(tt=>[...tt,...Ye]),Yt(!0),Ue.current&&clearTimeout(Ue.current),Ue.current=setTimeout(()=>Yt(!1),2e3),et(),s&&F.paths.some(Bt=>Bt===s||s.endsWith(Bt))&&Ie(s),f==="preview"){const tt=["react","vite","next","nuxt","svelte","remix"];($==null?void 0:$.running)&&($==null?void 0:$.framework)&&tt.some(kt=>$.framework.toLowerCase().includes(kt))||L(kt=>kt+1)}});return()=>{b(),Ue.current&&clearTimeout(Ue.current)}},[Io,s,f,$==null?void 0:$.running,et]);const Jh=d.useCallback(async()=>{if(!(!Qe||!x.id)){try{const b=await W.getSessionFileContent(x.id,Qe);l(b.content),c(b.content),g(!1),D(I=>I.map(F=>F.path===Qe?{...F,content:b.content,modified:!1}:F))}catch{}Ie(null)}},[Qe,x.id]);d.useEffect(()=>{if(f!=="preview")return;let b=!1;const I=async()=>{try{const te=await W.devserver.status(x.id);b||ki(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:${fe}/health`).then(b=>_e(b.ok)).catch(()=>_e(!1))},[f]);const vs=d.useCallback(async b=>{Wo(!0),ji(null);try{const I=await W.devserver.start(x.id,b);if(I.status==="error")ji(I.message||"Failed to start dev server");else{const F=await W.devserver.status(x.id);ki(F)}}catch(I){ji(I instanceof Error?I.message:"Failed to start dev server")}Wo(!1)},[x.id]),Vo=d.useRef(!1);d.useEffect(()=>{Vo.current||se!=null&&se.dev_command&&($!=null&&$.running||($==null?void 0:$.status)==="starting"||$s||(Vo.current=!0,vs(se.dev_command)))},[se==null?void 0:se.dev_command,$==null?void 0:$.running,$==null?void 0:$.status,$s,vs]);const Zh=d.useCallback(async()=>{try{await W.devserver.stop(x.id);const b=await W.devserver.status(x.id);ki(b)}catch{}},[x.id]),Qh=d.useCallback(async()=>{Ko(!0);try{const b=await W.fixProject(x.id);if(b.task_id){let F=0,te;do await new Promise(tt=>setTimeout(tt,2e3)),te=await W.chatPoll(x.id,b.task_id),F++;while(!te.complete&&F<150);const Ye=await W.devserver.status(x.id);ki(Ye)}}catch(b){ji(b instanceof Error?b.message:"Fix failed")}Ko(!1)},[x.id]),bs=$!=null&&$.running&&($!=null&&$.port)?$.framework==="expo"?`${en}/api/sessions/${encodeURIComponent(x.id)}/expo-qr`:$.portless_url||`http://localhost:${$.port}/`:null,ed=(se==null?void 0:se.preview_url)||`${en}/api/sessions/${encodeURIComponent(x.id)}/preview/index.html`,td=bs||ed,[Ni,Go]=d.useState([]),[wt,Ei]=d.useState(0);d.useEffect(()=>{const b=bs||(se==null?void 0:se.preview_url);b&&(Go([b]),Ei(0))},[bs,se==null?void 0:se.preview_url]);const Ct=Ni[wt]||td,[Yo,jr]=d.useState(Ct),sd=d.useCallback((b,I,F,te)=>{b.preventDefault(),N({x:b.clientX,y:b.clientY,path:I,name:F,type:te})},[]),id=d.useCallback(()=>{wt>0&&(Ei(b=>b-1),L(b=>b+1))},[wt]),rd=d.useCallback(()=>{wt<Ni.length-1&&(Ei(b=>b+1),L(b=>b+1))},[wt,Ni.length]),nd=d.useCallback(b=>{let I=b;if(b.startsWith("/")&&bs)try{I=`${new URL(bs).origin}${b}`}catch{const F=$==null?void 0:$.port;F&&(I=`http://localhost:${F}${b}`)}Go(F=>[...F.slice(0,wt+1),I]),Ei(F=>F+1),L(F=>F+1)},[wt,bs,$==null?void 0:$.port]);d.useEffect(()=>{try{const b=new URL(Ct,window.location.origin);jr(b.pathname+b.search+b.hash||"/")}catch{jr(Ct)}},[Ct]);const Di=d.useCallback(async()=>{ke({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.reviewProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Ri=d.useCallback(async()=>{ke({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.testProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Nr=d.useCallback(async()=>{ke({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),Q(null);try{const b=await W.explainProject(x.id);Q(b.output)}catch(b){Q(`Error: ${b instanceof Error?b.message:"Unknown"}`)}finally{ke(null)}},[x.id]),Er=d.useCallback(async(b,I)=>{if(window.confirm(`Delete "${I}"?`))try{await W.deleteSessionFile(x.id,b),s===b&&(i(null),o(""),l(null),c(null),g(!1)),await et()}catch(te){const Ye=te instanceof Error?te.message:"Unknown error";window.alert(`Delete failed: ${Ye}`)}},[x.id,s,et]),od=d.useCallback(b=>b.type==="file"?[{label:"Review",icon:ks,onClick:()=>{Di()}},{label:"Generate Tests",icon:ni,onClick:()=>{Ri()}},{label:"Explain",icon:Ys,onClick:()=>{Nr()}},{label:"Delete",icon:so,onClick:()=>{Er(b.path,b.name)},variant:"danger"}]:[{label:"Review Project",icon:ks,onClick:()=>{Di()}},{label:"Run Tests",icon:ni,onClick:()=>{Ri()}}],[Di,Ri,Nr,Er]),Lt=d.useCallback(async(b,I)=>{Ie(null),p&&s&&h!==null&&D(te=>te.map(Ye=>Ye.path===s?{...Ye,content:h,modified:!0}:Ye));const F=w.find(te=>te.path===b);if(F){i(b),o(I),l(F.content),c(F.content),g(F.modified);return}i(b),o(I),m(!0),g(!1);try{const te=x.id?await W.getSessionFileContent(x.id,b):await W.getFileContent(b);l(te.content),c(te.content),D(Ye=>[...Ye,{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]),Dr=d.useCallback(async()=>{var b;if(!(!s||h===null||!x.id)){y(!0);try{await W.saveSessionFile(x.id,s,h),l(h),g(!1),$h(Date.now()),D(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]),Xo=d.useCallback(b=>{const I=w.find(F=>F.path===b);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(D(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),g(te.modified)}else i(null),o(""),l(null),c(null),g(!1)}},[w,s]);d.useEffect(()=>{const b=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),p&&s&&Dr()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),U(F=>!F),K("")),(I.metaKey||I.ctrlKey)&&I.key==="k"&&(I.preventDefault(),_s(F=>!F)),I.key==="Escape"&&B&&U(!1)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[p,s,Dr,B]),d.useEffect(()=>{B&&A.current&&A.current.focus()},[B]);const Jo=Lh(x.files),Is=G?Jo.filter(b=>b.path.toLowerCase().includes(G.toLowerCase())):Jo;d.useEffect(()=>{const b=x.files.find(I=>I.name==="index.html"&&I.type==="file");b&&Lt(b.path,b.name)},[]);const ad=d.useCallback(b=>{b!==void 0&&(c(b),g(b!==a),To(b.split(`
256
+ `).length))},[a]),ld=d.useCallback(b=>{j.current=b;const I=b;if(I!=null&&I.onDidChangeCursorPosition&&I.onDidChangeCursorPosition(F=>{Ih({line:F.position.lineNumber,column:F.position.column})}),I!=null&&I.getModel){const F=I.getModel();F!=null&&F.getLineCount&&To(F.getLineCount())}},[]),cd=d.useCallback(async()=>{const b=window.prompt("New file name (e.g. src/utils.ts):");if(!(!b||!b.trim()))try{await W.createSessionFile(x.id,b.trim()),await et()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${F}`)}},[x.id,et]),hd=d.useCallback(async()=>{const b=window.prompt("New folder name (e.g. src/components):");if(!(!b||!b.trim()))try{await W.createSessionDirectory(x.id,b.trim()),await et()}catch(I){const F=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${F}`)}},[x.id,et]),Zo=d.useCallback(async()=>{try{const b=await W.previewChanges(x.id,"preview current changes");As(b)}catch{}},[x.id]),dd=d.useCallback(()=>{As(null),et()},[et]),ud=d.useCallback(b=>{As(null),et()},[et]),fd=d.useCallback(()=>{As(null)},[]),Qo=s?Rh(x.files,s):void 0,md=((ta=n.split(".").pop())==null?void 0:ta.toUpperCase())||"",{showHelp:pd,setShowHelp:ea}=gx({onToggleBuild:()=>{Pe&&Fo()}}),gd=d.useMemo(()=>[{id:"preview",label:"Open Preview",category:"command",icon:ks,action:()=>_("preview"),shortcut:""},{id:"code",label:"Open Code Editor",category:"command",icon:an,action:()=>_("code")},{id:"terminal",label:"Open Terminal",category:"command",icon:ns,action:()=>oe(!0)},{id:"dashboard",label:"Open Dashboard",category:"command",icon:Rr,action:()=>_("dashboard")},{id:"deploy",label:"Deploy Project",category:"command",icon:Wt,action:()=>_("deploy")},{id:"git",label:"Git Status",category:"command",icon:ze,action:()=>_("git")},{id:"settings",label:"Settings / Config",category:"setting",icon:oa,action:()=>_("config")},{id:"quick-open",label:"Quick Open File",category:"file",icon:ee,action:()=>{U(!0),K("")},shortcut:"Cmd+P"},{id:"zen",label:"Toggle Zen Mode",category:"setting",icon:ln,action:()=>He()},{id:"sidebar",label:"Toggle File Tree",category:"setting",icon:aa,action:()=>P(b=>!b)},{id:"preview-changes",label:"Preview Pending Changes",category:"command",icon:ze,action:()=>Zo()},{id:"insights",label:"Build Insights",category:"command",icon:tn,action:()=>_("insights")},{id:"docs",label:"Documentation",category:"command",icon:Ys,action:()=>_("docs")},{id:"nl-search",label:"Natural Language Search",category:"command",icon:os,action:()=>Os(!0)}],[_,He,Zo]),Pi=d.useMemo(()=>{if(!Pe)return"idle";const b=(ae.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"},[Pe,ae.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}),Mo.length>=2&&r.jsx("div",{className:"flex items-center gap-1 border-l border-border pl-2 ml-1",children:r.jsx(Kx,{tokenHistory:Mo})}),r.jsxs("div",{className:"flex items-center gap-0.5 border-l border-border pl-2 ml-1",children:[r.jsx("button",{onClick:()=>P(b=>!b),title:k?"Hide file tree":"Show file tree",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:k?r.jsx(aa,{size:16}):r.jsx(Su,{size:16})}),r.jsx("button",{onClick:()=>oe(b=>!b),title:J?"Hide terminal/chat":"Show terminal/chat",className:"p-1.5 rounded hover:bg-hover text-muted hover:text-ink transition-colors",children:J?r.jsx(xu,{size:16}):r.jsx(bu,{size:16})}),r.jsx("button",{onClick:He,title:V?"Exit zen mode":"Zen mode (hide all panels)",className:`p-1.5 rounded hover:bg-hover transition-colors ${V?"text-primary":"text-muted hover:text-ink"}`,children:V?r.jsx(cc,{size:16}):r.jsx(ln,{size:16})})]}),!Pe&&r.jsx(he,{variant:"primary",size:"sm",icon:Ut,onClick:()=>{if(!(x.prd||"").trim()){window.alert("No spec found for this project. Go to Home to start a new build.");return}Si(!0)},title:"Start build for this project",children:"Build"}),!Pe&&Pi==="complete"&&r.jsx(he,{variant:"ghost",size:"sm",icon:on,onClick:()=>wr(!0),title:"Replay the build timeline",children:"Replay Build"}),r.jsx(Tt,{icon:os,label:"Natural language search",size:"sm",onClick:()=>Os(!0)}),Pe&&r.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[We?r.jsx(he,{variant:"ghost",size:"sm",icon:Ut,onClick:Gh,title:"Resume build",children:"Resume"}):r.jsx(he,{variant:"ghost",size:"sm",icon:Zl,onClick:Vh,title:"Pause build",children:"Pause"}),r.jsx(he,{variant:"danger",size:"sm",icon:sr,onClick:Fo,title:"Stop build",children:"Stop"})]}),r.jsx(Tt,{icon:ks,label:"Review project",size:"sm",onClick:Di,disabled:!!(le!=null&&le.loading)}),r.jsx(Tt,{icon:ni,label:"Run tests",size:"sm",onClick:Ri,disabled:!!(le!=null&&le.loading)}),r.jsx(Tt,{icon:Ys,label:"Explain project",size:"sm",onClick:Nr,disabled:!!(le!=null&&le.loading)}),r.jsx(he,{variant:"secondary",size:"sm",icon:Wt,onClick:()=>_("deploy"),title:"Deploy project",children:"Deploy"}),r.jsx(xx,{onClick:()=>ea(!0)})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1",children:r.jsx(nx,{phase:Pi,iteration:ae.iteration,maxIterations:ae.maxIterations,cost:ae.cost,startTime:ae.startTime,isRunning:Pe})}),Pe&&r.jsx("div",{className:"flex-shrink-0 pr-2",children:r.jsx(yv,{gatePassRate:.8,testCoverage:ae.iteration>2?60:20,iteration:ae.iteration,maxIterations:ae.maxIterations,phase:Pi,compact:!0})})]}),r.jsx(Mx,{sessionId:x.id,onRestore:et}),r.jsx("div",{className:"flex-1 min-h-0",children:r.jsxs(dn,{orientation:"vertical",children:[r.jsx(Zs,{defaultSize:70,minSize:40,children:r.jsxs(dn,{orientation:"horizontal",className:"h-full",children:[k&&r.jsx(Zs,{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:()=>Po("files"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${wi==="files"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(oo,{size:14}),"Files",Sr&&r.jsx("span",{className:"ml-1 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),r.jsxs("button",{onClick:()=>Po("chat"),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${wi==="chat"?"text-primary border-primary":"text-muted hover:text-ink border-transparent"}`,children:[r.jsx(Vl,{size:14}),"Chat"]}),wi==="files"&&r.jsxs("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[r.jsxs("button",{onClick:cd,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(mr,{size:12})," New"]}),r.jsxs("button",{onClick:hd,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(Pd,{size:12})," New"]})]})]}),wi==="files"?r.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:x.files.length>0?r.jsx(Mh,{nodes:x.files,selectedPath:s,onSelect:Lt,onDelete:Er,onContextMenu:sd}):r.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[r.jsx(rn,{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:z})})})]})}),k&&r.jsx(un,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),r.jsx(Zs,{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:an},{id:"preview",label:"Preview",icon:ks},{id:"deploy",label:"Deploy",icon:Wt},{id:"config",label:"Config",icon:oa},{id:"secrets",label:"Secrets",icon:du},{id:"prd",label:"Spec",icon:mi},{id:"dashboard",label:"Dashboard",icon:Rr},{id:"git",label:"Git",icon:ze},{id:"cicd",label:"CI/CD",icon:ze},{id:"insights",label:"Insights",icon:tn},{id:"docs",label:"Docs",icon:Ys}].map(b=>r.jsxs("button",{role:"tab","aria-selected":f===b.id,onClick:()=>_(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:()=>Lt(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:Zn(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(),Xo(b.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),Xo(b.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:r.jsx(_t,{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:Qo!=null?Ph(Qo):""}),r.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:md}),p&&r.jsx("button",{onClick:Dr,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"})]}),Qe===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(bt,{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:Jh,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:()=>Ie(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(jd,{}):r.jsx(Wi,{name:"Editor",children:r.jsx(Vf,{value:h??"",language:zv(n),theme:"vs",onChange:ad,onMount:ld,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(Yx,{selectedFile:s,fileName:n,isModified:p,isSaving:v,lastSavedAt:Oh,lineCount:Fh,cursorLine:Bo.line,cursorColumn:Bo.column,buildTime:ae.phase==="complete"&&ae.startTime?Math.floor((Date.now()-ae.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(ee,{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(Wi,{name:"Preview",children:r.jsxs("div",{className:`h-full flex flex-col ${Ao?"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(Tt,{icon:Jl,label:"Back",size:"sm",onClick:id,disabled:wt<=0}),r.jsx(Tt,{icon:eo,label:"Forward",size:"sm",onClick:rd,disabled:wt>=Ni.length-1}),r.jsx(rv,{onClick:()=>{kr(!0),L(b=>b+1)}}),r.jsx("input",{value:Yo,onChange:b=>jr(b.target.value),onKeyDown:b=>{b.key==="Enter"&&nd(Yo)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),r.jsx(Xx,{selectedDevice:Hh,onDeviceChange:Wh,containerWidth:qh}),r.jsx(Qx,{zoom:Cr,onZoomChange:Uh}),r.jsx(sv,{url:Ct}),r.jsx(tv,{}),r.jsx(nv,{url:Ct}),r.jsx(Tt,{icon:as,label:"Open in new tab",size:"sm",onClick:()=>window.open(Ct,"_blank")}),r.jsx(iv,{isFullscreen:Ao,onToggle:()=>Kh(b=>!b)}),($==null?void 0:$.running)&&r.jsxs("button",{onClick:Zh,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(sr,{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:[Ci&&r.jsx(zl,{}),r.jsx("div",{ref:xs,className:`flex-1 bg-white overflow-auto flex justify-center ${Ci?"hidden":""}`,children:r.jsx("div",{className:`${zo} h-full preview-zoom-${Cr}`,children:r.jsx("iframe",{ref:R,src:Ct,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{kr(!1),xs.current&&$o(xs.current.clientWidth)}},E)})}),r.jsx(Tl,{messages:Oo})]}):se!=null&&se.preview_url?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[Ci&&r.jsx(zl,{}),r.jsx("div",{ref:xs,className:`flex-1 bg-white overflow-auto flex justify-center ${Ci?"hidden":""}`,children:r.jsx("div",{className:`${zo} h-full preview-zoom-${Cr}`,children:r.jsx("iframe",{ref:R,src:Ct,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",onLoad:()=>{kr(!1),xs.current&&$o(xs.current.clientWidth)}},E)})}),r.jsx(Tl,{messages:Oo})]}):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(Hd,{size:28,className:"text-primary"}):se.type==="library"?r.jsx(Ql,{size:28,className:"text-primary"}):se.type==="go-app"||se.type==="rust-app"?r.jsx(ns,{size:28,className:"text-primary"}):r.jsx(rn,{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:()=>vs(se.dev_command||void 0),disabled:$s,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(Ut,{size:12}),$s?"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:Xt,onChange:b=>Xh(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Xt.trim()&&vs(Xt.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:()=>Xt.trim()&&vs(Xt.trim()),disabled:$s||!Xt.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"})]})]})]}),qo&&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:qo})]}),($==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:Qh,disabled:Uo,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:Uo?"Fixing...":"Fix Error"}),r.jsx("button",{onClick:()=>vs(se.dev_command||Xt||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(`
257
+ `)})]}),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:T})]}),r.jsx("div",{className:"flex gap-2",children:["claude","codex","gemini"].map(b=>r.jsx("button",{onClick:()=>{Y(b),sessionStorage.setItem(`pl_provider_${x.id}`,b),W.setProvider(b).catch(()=>{})},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${T===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:()=>{xe(b),sessionStorage.setItem(`pl_buildmode_${x.id}`,b)},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${z===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 spec found for this project."})]})}),f==="deploy"&&r.jsx(fx,{sessionId:x.id}),f==="dashboard"&&(de===!1?r.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center p-8 gap-4",children:[r.jsx(Rr,{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()=>{_e(null);try{const b=await fetch(`http://127.0.0.1:${fe}/health`);_e(b.ok)}catch{_e(!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:()=>ue(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:${fe}/`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted hover:text-primary flex items-center gap-1",children:["Open full dashboard ",r.jsx(as,{size:12})]})]}),r.jsx("iframe",{src:`http://127.0.0.1:${fe}/#${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(Px,{sessionId:x.id}),f==="cicd"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Tv,{sessionId:e.id})}),f==="docs"&&r.jsx("div",{className:"h-full overflow-y-auto p-4",children:r.jsx(Ov,{sessionId:x.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:ae.startTime?Math.floor((Date.now()-ae.startTime)/1e3):0,qualityScore:0,totalCost:ae.cost,iterations:ae.iteration,provider:T})})]})]})})]})}),J&&r.jsx(un,{className:"h-1 bg-border hover:bg-primary/30 cursor-row-resize"}),J&&r.jsx(Zs,{defaultSize:30,minSize:15,collapsible:!0,children:r.jsx(Wi,{name:"ActivityPanel",children:r.jsx(ix,{logs:null,logsLoading:!1,agents:null,checklist:null,sessionId:e.id,isRunning:x.status==="running"||x.status==="in_progress",buildMode:z,buildEvents:Bh,onFileClick:b=>Lt(b,b.split("/").pop()||b)})})})]})}),(le==null?void 0:le.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:[le.type==="review"?"Reviewing project":le.type==="test"?"Generating tests":"Analyzing project","..."]}),r.jsxs("span",{className:"text-xs font-mono text-muted",children:[le.elapsed,"s"]})]})}),q&&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(Tt,{icon:_t,label:"Close",size:"sm",onClick:()=>Q(null)})]}),r.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap",children:q})]}),S&&r.jsx(Rm,{x:S.x,y:S.y,items:od(S),onClose:()=>N(null)}),B&&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:()=>U(!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=>K(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"&&Is.length>0&&(Lt(Is[0].path,Is[0].name),U(!1)),b.key==="Escape"&&U(!1)}}),r.jsxs("div",{className:"max-h-64 overflow-y-auto",children:[Is.slice(0,20).map(b=>r.jsxs("button",{onClick:()=>{Lt(b.path,b.name),U(!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:Zn(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)),Is.length===0&&r.jsx("div",{className:"px-4 py-3 text-xs text-muted",children:"No matching files"})]})]})}),r.jsx(_x,{open:pd,onClose:()=>ea(!1)}),r.jsx(Sx,{isOpen:ht,onClose:()=>_s(!1),commands:gd,sessionId:x.id,onFileSelect:Lt}),Ro&&r.jsx(Tx,{data:Ro,onAcceptAll:dd,onAcceptSelected:ud,onReject:fd,onClose:()=>As(null)}),r.jsx(Ux,{phase:Pi,buildTime:ae.startTime?Math.floor((Date.now()-ae.startTime)/1e3):void 0}),Th&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>wr(!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:()=>wr(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(_t,{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:ae.iteration||ae.maxIterations})})]})}),Ah&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[15vh]",onClick:()=>Os(!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:()=>Os(!1),className:"text-muted hover:text-ink p-1 rounded hover:bg-hover transition-colors",children:r.jsx(_t,{size:16})})]}),r.jsx(Mv,{sessionId:x.id,onOpenFile:(b,I)=>{Lt(b,b.split("/").pop()||b),Os(!1)},className:"p-4"})]})}),zh&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>Si(!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:z==="quick"?"simple":z==="max"?"complex":"standard",provider:T,estimatedIterations:ae.maxIterations,onConfirm:async()=>{Si(!1);try{const b=x.prd||"";await W.startSession({prd:b,provider:T,projectDir:x.path}),Ze(!0)}catch(b){window.alert(`Failed to start: ${b instanceof Error?b.message:"Unknown error"}`)}},onCancel:()=>Si(!1)})})})]})}function Iv(){const{sessionId:e}=Nd(),t=Ed(),[s,i]=d.useState(null),[n,o]=d.useState(!0),[a,l]=d.useState(null);return d.useEffect(()=>{e&&(o(!0),l(null),W.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(Wi,{name:"ProjectWorkspace",children:r.jsx($v,{session:s,onClose:()=>t("/")})})})})}const wb=Object.freeze(Object.defineProperty({__proto__:null,default:Iv},Symbol.toStringTag,{value:"Module"}));export{gr as L,wb as P,ju as S};