loki-mode 6.56.0 → 6.57.1

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 (22) hide show
  1. package/SKILL.md +2 -2
  2. package/VERSION +1 -1
  3. package/dashboard/__init__.py +1 -1
  4. package/docs/INSTALLATION.md +1 -1
  5. package/mcp/__init__.py +1 -1
  6. package/package.json +1 -1
  7. package/web-app/dist/assets/{Badge-BDr4DPCT.js → Badge-wQU9blAB.js} +1 -1
  8. package/web-app/dist/assets/{Button-WBFGRnUr.js → Button-DV8ro4oS.js} +1 -1
  9. package/web-app/dist/assets/{Card-DzOT34Rr.js → Card-B4GJw1Yl.js} +1 -1
  10. package/web-app/dist/assets/{HomePage-B8kMCXMB.js → HomePage-BrwjWs5_.js} +3 -3
  11. package/web-app/dist/assets/{LoginPage-D9lCyiqM.js → LoginPage-KBUVD4pE.js} +1 -1
  12. package/web-app/dist/assets/{NotFoundPage-DzeZ0uQ6.js → NotFoundPage-CDzHJO08.js} +1 -1
  13. package/web-app/dist/assets/{ProjectPage-C-k0iy0i.js → ProjectPage-CNuYm1A5.js} +2 -2
  14. package/web-app/dist/assets/{ProjectsPage-jys_pHzp.js → ProjectsPage-uJimVYlj.js} +1 -1
  15. package/web-app/dist/assets/{SettingsPage-Cz_RXr82.js → SettingsPage-BiSUXmC2.js} +1 -1
  16. package/web-app/dist/assets/{TemplatesPage-COnhb_Wq.js → TemplatesPage-_MJc-qGU.js} +1 -1
  17. package/web-app/dist/assets/{TerminalOutput-CmdEXHHd.js → TerminalOutput-B5rIKYNW.js} +1 -1
  18. package/web-app/dist/assets/{arrow-left-DAZzI0L-.js → arrow-left-BaOs4kgD.js} +1 -1
  19. package/web-app/dist/assets/{clock-BHGf6zSk.js → clock-Csnz1n2_.js} +1 -1
  20. package/web-app/dist/assets/{external-link-DLYjfP9j.js → external-link-i7ZDkWbe.js} +1 -1
  21. package/web-app/dist/assets/{index-B8Eg1YHL.js → index-1UyN_URb.js} +2 -2
  22. package/web-app/dist/index.html +1 -1
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: loki-mode
3
3
  description: Multi-agent autonomous startup system. Triggers on "Loki Mode". Takes PRD to deployed product with minimal human intervention. Requires --dangerously-skip-permissions flag.
4
4
  ---
5
5
 
6
- # Loki Mode v6.56.0
6
+ # Loki Mode v6.57.1
7
7
 
8
8
  **You are an autonomous agent. You make decisions. You do not ask questions. You do not stop.**
9
9
 
@@ -267,4 +267,4 @@ The following features are documented in skill modules but not yet fully automat
267
267
  | Quality gates 3-reviewer system | Implemented (v5.35.0) | 5 specialist reviewers in `skills/quality-gates.md`; execution in run.sh |
268
268
  | Benchmarks (HumanEval, SWE-bench) | Infrastructure only | Runner scripts and datasets exist in `benchmarks/`; no published results |
269
269
 
270
- **v6.56.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
270
+ **v6.57.1 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
package/VERSION CHANGED
@@ -1 +1 @@
1
- 6.56.0
1
+ 6.57.1
@@ -7,7 +7,7 @@ Modules:
7
7
  control: Session control API (start/stop/pause/resume)
8
8
  """
9
9
 
10
- __version__ = "6.56.0"
10
+ __version__ = "6.57.1"
11
11
 
12
12
  # Expose the control app for easy import
13
13
  try:
@@ -2,7 +2,7 @@
2
2
 
3
3
  The flagship product of [Autonomi](https://www.autonomi.dev/). Complete installation instructions for all platforms and use cases.
4
4
 
5
- **Version:** v6.56.0
5
+ **Version:** v6.57.1
6
6
 
7
7
  ---
8
8
 
package/mcp/__init__.py CHANGED
@@ -57,4 +57,4 @@ try:
57
57
  except ImportError:
58
58
  __all__ = ['mcp']
59
59
 
60
- __version__ = '6.56.0'
60
+ __version__ = '6.57.1'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loki-mode",
3
- "version": "6.56.0",
3
+ "version": "6.57.1",
4
4
  "description": "Loki Mode by Autonomi - Multi-agent autonomous startup system for Claude Code, Codex CLI, and Gemini CLI",
5
5
  "keywords": [
6
6
  "agent",
@@ -1,4 +1,4 @@
1
- import{c as m,r,j as e}from"./index-B8Eg1YHL.js";import{C as g,a as p}from"./clock-BHGf6zSk.js";/**
1
+ import{c as m,r,j as e}from"./index-1UyN_URb.js";import{C as g,a as p}from"./clock-Csnz1n2_.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as p,r as u,j as e}from"./index-B8Eg1YHL.js";/**
1
+ import{c as p,r as u,j as e}from"./index-1UyN_URb.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{j as s}from"./index-B8Eg1YHL.js";const n={none:"p-0",sm:"p-3",md:"p-4",lg:"p-6"};function p({hover:e=!1,padding:d="md",className:t="",children:a,onClick:r}){return s.jsx("div",{role:r?"button":void 0,tabIndex:r?0:void 0,onClick:r,onKeyDown:r?o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),r())}:void 0,className:["bg-white border border-[#ECEAE3] rounded-[5px] shadow-card",e&&"hover:shadow-card-hover transition-shadow duration-200",r&&"cursor-pointer",n[d],t].filter(Boolean).join(" "),children:a})}export{p as C};
1
+ import{j as s}from"./index-1UyN_URb.js";const n={none:"p-0",sm:"p-3",md:"p-4",lg:"p-6"};function p({hover:e=!1,padding:d="md",className:t="",children:a,onClick:r}){return s.jsx("div",{role:r?"button":void 0,tabIndex:r?0:void 0,onClick:r,onKeyDown:r?o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),r())}:void 0,className:["bg-white border border-[#ECEAE3] rounded-[5px] shadow-card",e&&"hover:shadow-card-hover transition-shadow duration-200",r&&"cursor-pointer",n[d],t].filter(Boolean).join(" "),children:a})}export{p as C};
@@ -1,4 +1,4 @@
1
- import{j as e,r as n,a as h,u as be,b as ge}from"./index-B8Eg1YHL.js";import{u as I,B as je}from"./Badge-BDr4DPCT.js";import{P as ve,a as Ne,S as ye,E,T as we}from"./TerminalOutput-CmdEXHHd.js";import"./clock-BHGf6zSk.js";function ke(t){if(t<60)return`${Math.round(t)}s`;if(t<3600)return`${Math.floor(t/60)}m ${Math.round(t%60)}s`;const s=Math.floor(t/3600),l=Math.floor(t%3600/60);return`${s}h ${l}m`}function Se(t,s){if(!t||t<=0)return"--";const l={simple:{opus:1,haiku:1,total:3},standard:{opus:2,haiku:2,total:5},complex:{opus:3,haiku:3,total:8}},r=l[s]||l.standard;return t<=r.opus?"Opus":t>r.total-r.haiku?"Haiku":"Sonnet"}function Ce({status:t,prdSummary:s,onStop:l,onPause:r,onResume:a,isPaused:c}){const i=t?Se(t.iteration??0,t.complexity||"standard"):"--",o=c??(t==null?void 0:t.paused)??!1;return e.jsxs("div",{className:"card px-5 py-3 flex items-center gap-6 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Phase"}),e.jsx("span",{className:"font-mono font-semibold text-ink",children:(t==null?void 0:t.phase)||"idle"})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Complexity"}),e.jsx("span",{className:`font-mono font-semibold ${(t==null?void 0:t.complexity)==="complex"?"text-warning":(t==null?void 0:t.complexity)==="simple"?"text-success":"text-ink"}`,children:(t==null?void 0:t.complexity)||"standard"})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Model"}),e.jsx("span",{className:`font-mono font-semibold px-2 py-0.5 rounded-md text-xs ${i==="Opus"?"bg-primary/10 text-primary":i==="Haiku"?"bg-success/10 text-success":"bg-primary/10 text-primary"}`,children:i})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Tasks"}),e.jsx("span",{className:"font-mono text-ink",children:t!=null&&t.current_task?e.jsx("span",{className:"text-xs",children:t.current_task}):e.jsx("span",{className:"text-muted",children:"--"})}),((t==null?void 0:t.pending_tasks)??0)>0&&e.jsxs("span",{className:"text-xs text-primary font-mono",children:["+",t==null?void 0:t.pending_tasks," pending"]})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium flex-shrink-0",children:"Building"}),e.jsx("span",{className:"text-xs font-mono text-ink truncate max-w-[220px]",title:s,children:s.length>60?s.slice(0,60)+"...":s})]})]}),e.jsx("div",{className:"flex-1"}),((t==null?void 0:t.uptime)??0)>0&&e.jsx("span",{className:"font-mono text-xs text-muted",children:ke((t==null?void 0:t.uptime)??0)}),(r||a)&&e.jsxs("button",{onClick:o?a:r,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-btn text-xs font-semibold border border-warning/30 text-warning hover:bg-warning/10 transition-colors",children:[o?e.jsx(ve,{size:14}):e.jsx(Ne,{size:14}),o?"Resume":"Pause"]}),l&&e.jsxs("button",{onClick:l,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-btn text-xs font-semibold bg-danger/10 text-danger border border-danger/20 hover:bg-danger/20 transition-colors",children:[e.jsx(ye,{size:14}),"Stop"]})]})}function Ee({status:t}){const s=[{label:"Iteration",value:t?t.iteration.toString():"--",color:"text-primary"},{label:"Agents",value:t?t.running_agents.toString():"--",color:t&&t.running_agents>0?"text-success":"text-muted"},{label:"Pending",value:t?t.pending_tasks.toString():"--",color:t&&t.pending_tasks>0?"text-warning":"text-muted"},{label:"Provider",value:(t==null?void 0:t.provider)||"--",color:"text-primary"}];return e.jsx("div",{className:"grid grid-cols-4 gap-3",children:s.map(l=>e.jsxs("div",{className:"card p-4 text-center",children:[e.jsx("div",{className:`text-2xl font-bold font-mono ${l.color}`,children:l.value}),e.jsx("div",{className:"text-xs text-muted font-medium mt-1 uppercase tracking-wider",children:l.label})]},l.label))})}function Pe({plan:t,loading:s,onConfirm:l,onCancel:r}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm",children:e.jsxs("div",{className:"card w-full max-w-lg mx-4 p-6 rounded-card shadow-card-hover",children:[e.jsx("h2",{className:"text-lg font-bold text-ink mb-4",children:"Build Estimate"}),s?e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-muted",children:"Analyzing PRD..."}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-muted hover:text-ink transition-colors",children:"Cancel"}),e.jsx("button",{onClick:l,className:"px-4 py-2 text-sm font-medium text-primary hover:text-primary/80 transition-colors underline",children:"Skip analysis, build now"})]})]}):t?e.jsxs(e.Fragment,{children:[t.returncode!==0&&e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-btn bg-warning/10 border border-warning/20 text-warning text-xs",children:["loki plan exited with code ",t.returncode," - showing partial results"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Complexity"}),e.jsx("div",{className:"text-base font-bold text-ink capitalize",children:t.complexity})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Est. Cost"}),e.jsx("div",{className:"text-base font-bold text-ink",children:t.cost_estimate})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Iterations"}),e.jsx("div",{className:"text-base font-bold text-ink",children:t.iterations})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Phases"}),e.jsx("div",{className:"text-xs text-ink capitalize",children:t.phases.join(", ")})]})]}),t.output_text&&e.jsxs("details",{className:"mb-4",children:[e.jsx("summary",{className:"text-xs text-muted cursor-pointer hover:text-ink transition-colors",children:"Raw output"}),e.jsx("pre",{className:"mt-2 text-xs font-mono text-muted-accessible bg-black/5 rounded-card p-3 overflow-auto max-h-40 whitespace-pre-wrap",children:t.output_text})]}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-muted hover:text-ink transition-colors",children:"Cancel"}),e.jsx("button",{onClick:l,className:"px-5 py-2 rounded-card text-sm font-semibold bg-primary text-white hover:bg-primary/90 transition-all shadow-button",children:"Start Build"})]})]}):e.jsx("div",{className:"text-sm text-muted py-4",children:"No plan data available."})]})})}function _e({onSubmit:t,running:s,error:l,provider:r,onProviderChange:a,initialPrd:c}){const[i,o]=n.useState(""),[m,b]=n.useState(""),[f,y]=n.useState("claude"),[d,g]=n.useState(""),j=r??f,[v,w]=n.useState(!1),[k,T]=n.useState([]),[x,P]=n.useState(!1),[N,M]=n.useState(!1),[_,A]=n.useState(!1),[z,F]=n.useState(null),[L,$]=n.useState(!1),[O,D]=n.useState(!1);n.useEffect(()=>{h.getTemplates().then(u=>{T(u),P(!1)}).catch(()=>{T([]),P(!0)})},[]),n.useEffect(()=>{c&&o(c)},[c]),n.useEffect(()=>{if(c)return;const u=localStorage.getItem("loki-prd-draft");u&&o(u),h.getPrdPrefill().then(({content:S})=>{S&&o(S)}).catch(()=>{})},[c]),n.useEffect(()=>{i.trim()?localStorage.setItem("loki-prd-draft",i):localStorage.removeItem("loki-prd-draft")},[i]),n.useEffect(()=>{const u=S=>{i.trim()&&S.preventDefault()};return window.addEventListener("beforeunload",u),()=>window.removeEventListener("beforeunload",u)},[i]);const R=n.useCallback(async(u,S)=>{b(S),w(!1);try{const G=await h.getTemplateContent(u);o(G.content)}catch{o(`# ${S}
1
+ import{j as e,r as l,a as h,u as be,b as ge}from"./index-1UyN_URb.js";import{u as I,B as je}from"./Badge-wQU9blAB.js";import{P as ve,a as Ne,S as ye,E as C,T as we}from"./TerminalOutput-B5rIKYNW.js";import"./clock-Csnz1n2_.js";function ke(t){if(t<60)return`${Math.round(t)}s`;if(t<3600)return`${Math.floor(t/60)}m ${Math.round(t%60)}s`;const s=Math.floor(t/3600),n=Math.floor(t%3600/60);return`${s}h ${n}m`}function Se(t,s){if(!t||t<=0)return"--";const n={simple:{opus:1,haiku:1,total:3},standard:{opus:2,haiku:2,total:5},complex:{opus:3,haiku:3,total:8}},r=n[s]||n.standard;return t<=r.opus?"Opus":t>r.total-r.haiku?"Haiku":"Sonnet"}function Ce({status:t,prdSummary:s,onStop:n,onPause:r,onResume:a,isPaused:c}){const i=t?Se(t.iteration??0,t.complexity||"standard"):"--",o=c??(t==null?void 0:t.paused)??!1;return e.jsxs("div",{className:"card px-5 py-3 flex items-center gap-6 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Phase"}),e.jsx("span",{className:"font-mono font-semibold text-ink",children:(t==null?void 0:t.phase)||"idle"})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Complexity"}),e.jsx("span",{className:`font-mono font-semibold ${(t==null?void 0:t.complexity)==="complex"?"text-warning":(t==null?void 0:t.complexity)==="simple"?"text-success":"text-ink"}`,children:(t==null?void 0:t.complexity)||"standard"})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Model"}),e.jsx("span",{className:`font-mono font-semibold px-2 py-0.5 rounded-md text-xs ${i==="Opus"?"bg-primary/10 text-primary":i==="Haiku"?"bg-success/10 text-success":"bg-primary/10 text-primary"}`,children:i})]}),e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium",children:"Tasks"}),e.jsx("span",{className:"font-mono text-ink",children:t!=null&&t.current_task?e.jsx("span",{className:"text-xs",children:t.current_task}):e.jsx("span",{className:"text-muted",children:"--"})}),((t==null?void 0:t.pending_tasks)??0)>0&&e.jsxs("span",{className:"text-xs text-primary font-mono",children:["+",t==null?void 0:t.pending_tasks," pending"]})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-5 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-xs text-muted uppercase tracking-wider font-medium flex-shrink-0",children:"Building"}),e.jsx("span",{className:"text-xs font-mono text-ink truncate max-w-[220px]",title:s,children:s.length>60?s.slice(0,60)+"...":s})]})]}),e.jsx("div",{className:"flex-1"}),((t==null?void 0:t.uptime)??0)>0&&e.jsx("span",{className:"font-mono text-xs text-muted",children:ke((t==null?void 0:t.uptime)??0)}),(r||a)&&e.jsxs("button",{onClick:o?a:r,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-btn text-xs font-semibold border border-warning/30 text-warning hover:bg-warning/10 transition-colors",children:[o?e.jsx(ve,{size:14}):e.jsx(Ne,{size:14}),o?"Resume":"Pause"]}),n&&e.jsxs("button",{onClick:n,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-btn text-xs font-semibold bg-danger/10 text-danger border border-danger/20 hover:bg-danger/20 transition-colors",children:[e.jsx(ye,{size:14}),"Stop"]})]})}function Ee({status:t}){const s=[{label:"Iteration",value:t?t.iteration.toString():"--",color:"text-primary"},{label:"Agents",value:t?t.running_agents.toString():"--",color:t&&t.running_agents>0?"text-success":"text-muted"},{label:"Pending",value:t?t.pending_tasks.toString():"--",color:t&&t.pending_tasks>0?"text-warning":"text-muted"},{label:"Provider",value:(t==null?void 0:t.provider)||"--",color:"text-primary"}];return e.jsx("div",{className:"grid grid-cols-4 gap-3",children:s.map(n=>e.jsxs("div",{className:"card p-4 text-center",children:[e.jsx("div",{className:`text-2xl font-bold font-mono ${n.color}`,children:n.value}),e.jsx("div",{className:"text-xs text-muted font-medium mt-1 uppercase tracking-wider",children:n.label})]},n.label))})}function Pe({plan:t,loading:s,onConfirm:n,onCancel:r}){return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-sm",children:e.jsxs("div",{className:"card w-full max-w-lg mx-4 p-6 rounded-card shadow-card-hover",children:[e.jsx("h2",{className:"text-lg font-bold text-ink mb-4",children:"Build Estimate"}),s?e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-muted",children:"Analyzing PRD..."}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsx("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-muted hover:text-ink transition-colors",children:"Cancel"}),e.jsx("button",{onClick:n,className:"px-4 py-2 text-sm font-medium text-primary hover:text-primary/80 transition-colors underline",children:"Skip analysis, build now"})]})]}):t?e.jsxs(e.Fragment,{children:[t.returncode!==0&&e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-btn bg-warning/10 border border-warning/20 text-warning text-xs",children:["loki plan exited with code ",t.returncode," - showing partial results"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Complexity"}),e.jsx("div",{className:"text-base font-bold text-ink capitalize",children:t.complexity})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Est. Cost"}),e.jsx("div",{className:"text-base font-bold text-ink",children:t.cost_estimate})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Iterations"}),e.jsx("div",{className:"text-base font-bold text-ink",children:t.iterations})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Phases"}),e.jsx("div",{className:"text-xs text-ink capitalize",children:t.phases.join(", ")})]})]}),t.output_text&&e.jsxs("details",{className:"mb-4",children:[e.jsx("summary",{className:"text-xs text-muted cursor-pointer hover:text-ink transition-colors",children:"Raw output"}),e.jsx("pre",{className:"mt-2 text-xs font-mono text-muted-accessible bg-black/5 rounded-card p-3 overflow-auto max-h-40 whitespace-pre-wrap",children:t.output_text})]}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-muted hover:text-ink transition-colors",children:"Cancel"}),e.jsx("button",{onClick:n,className:"px-5 py-2 rounded-card text-sm font-semibold bg-primary text-white hover:bg-primary/90 transition-all shadow-button",children:"Start Build"})]})]}):e.jsx("div",{className:"text-sm text-muted py-4",children:"No plan data available."})]})})}function _e({onSubmit:t,running:s,error:n,provider:r,onProviderChange:a,initialPrd:c}){const[i,o]=l.useState(""),[m,b]=l.useState(""),[f,y]=l.useState("claude"),[d,g]=l.useState(""),j=r??f,[v,w]=l.useState(!1),[k,T]=l.useState([]),[x,E]=l.useState(!1),[N,M]=l.useState(!1),[P,A]=l.useState(!1),[z,_]=l.useState(null),[F,$]=l.useState(!1),[O,B]=l.useState(!1);l.useEffect(()=>{h.getTemplates().then(p=>{T(p),E(!1)}).catch(()=>{T([]),E(!0)})},[]),l.useEffect(()=>{c&&o(c)},[c]),l.useEffect(()=>{if(c)return;const p=localStorage.getItem("loki-prd-draft");p&&o(p),h.getPrdPrefill().then(({content:L})=>{L&&o(L)}).catch(()=>{})},[c]),l.useEffect(()=>{i.trim()?localStorage.setItem("loki-prd-draft",i):localStorage.removeItem("loki-prd-draft")},[i]);const R=l.useCallback(async(p,L)=>{b(L),w(!1);try{const G=await h.getTemplateContent(p);o(G.content)}catch{o(`# ${L}
2
2
 
3
3
  ## Overview
4
4
 
@@ -14,5 +14,5 @@ Describe your project here...
14
14
 
15
15
  - Requirement 1
16
16
  - Requirement 2
17
- `)}},[]),q=async()=>{if(!(!i.trim()||L)){$(!0),F(null),D(!0);try{const u=await h.planSession(i,j);F(u)}catch{F({complexity:"unknown",cost_estimate:"N/A",iterations:0,phases:[],output_text:"Failed to run loki plan. The CLI may not be available.",returncode:1})}finally{$(!1)}}},H=async()=>{if(!(!i.trim()||s||N)){D(!1),M(!0);try{await t(i,j,d.trim()||void 0,_?"quick":void 0)}finally{M(!1)}}};return e.jsxs(e.Fragment,{children:[O&&e.jsx(Pe,{plan:z,loading:L,onConfirm:H,onCancel:()=>D(!1)}),e.jsxs("div",{className:"card p-6 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Product Requirements"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>w(!v),className:"text-xs font-medium px-3 py-1.5 rounded-card border border-primary/20 text-primary hover:bg-primary/5 transition-colors",children:m||"Templates"}),v&&e.jsx("div",{className:"absolute right-0 top-full mt-1 w-56 card rounded-card overflow-hidden z-20 shadow-card-hover",children:e.jsxs("div",{className:"py-1 max-h-64 overflow-y-auto terminal-scroll",children:[x&&e.jsx("div",{className:"px-3 py-2 text-xs text-warning border-b border-warning/10",children:"Could not load templates from server. Check that the backend is running."}),!x&&k.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-muted",children:"Loading..."}),k.map(u=>e.jsx("button",{onClick:()=>R(u.filename,u.name),className:"w-full text-left px-3 py-2 text-sm text-ink hover:bg-primary/5 transition-colors",children:u.name},u.filename))]})})]})})]}),e.jsx("textarea",{value:i,onChange:u=>o(u.target.value),placeholder:"Paste your PRD here, or select a template above to get started...",className:"flex-1 min-h-[280px] w-full bg-card rounded-card border border-border-light px-4 py-3 text-sm font-mono text-ink placeholder:text-primary/60 resize-none focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/30 transition-all",spellCheck:!1}),e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-xs text-muted font-medium mb-1 uppercase tracking-wider",children:"Project Directory"}),e.jsx("input",{type:"text",value:d,onChange:u=>g(u.target.value),placeholder:"Leave blank to auto-create, or type a path (e.g. /Users/you/my-project)",className:"w-full bg-card rounded-card border border-border-light px-4 py-2 text-sm font-mono text-ink placeholder:text-primary/60/70 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/30 transition-all",spellCheck:!1}),e.jsx("p",{className:"text-xs text-muted-accessible mt-1",children:"Type a path or leave blank to auto-create under ~/purple-lab-projects/"})]}),l&&e.jsx("div",{className:"mt-3 px-3 py-2 rounded-btn bg-danger/10 border border-danger/20 text-danger text-xs font-medium",children:l}),e.jsxs("div",{className:"flex items-center gap-3 mt-4",children:[e.jsxs("button",{onClick:()=>A(!_),title:"Quick Mode: 3 iterations max, faster builds",className:`flex items-center gap-1.5 px-3 py-1.5 rounded-card text-xs font-semibold border transition-all ${_?"bg-primary/10 border-primary/30 text-primary":"border-border-light text-muted hover:text-ink hover:bg-card"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${_?"bg-primary":"bg-muted/40"}`}),"Quick"]}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted font-mono",children:[i.length.toLocaleString()," chars"]}),e.jsx("button",{onClick:q,disabled:!i.trim()||s||N||L,className:`px-6 py-2.5 rounded-card text-sm font-semibold transition-all ${!i.trim()||s||N||L?"bg-primary/10 text-muted cursor-not-allowed":"bg-primary text-white hover:bg-primary/90 shadow-button"}`,children:L?"Analyzing...":N?"Starting...":s?"Building...":"Start Build"})]})]})]})}const B=[{key:"reason",label:"Reason",description:"Analyzing task, planning approach"},{key:"act",label:"Act",description:"Implementing changes, writing code"},{key:"reflect",label:"Reflect",description:"Reviewing output, self-critique"},{key:"verify",label:"Verify",description:"Testing, validation, quality gates"}];function Fe(t){if(!t)return"reason";const s=t.toLowerCase();return s.includes("reason")||s.includes("plan")?"reason":s.includes("act")||s.includes("implement")||s.includes("code")?"act":s.includes("reflect")||s.includes("review")?"reflect":s.includes("verify")||s.includes("test")||s.includes("check")?"verify":"idle"}function Le({currentPhase:t,iteration:s}){const l=Fe(t);return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"RARV Cycle"}),e.jsxs("span",{className:"font-mono text-xs text-muted",children:["Iteration ",s]})]}),e.jsx("div",{className:"flex items-center justify-center mb-5",children:e.jsxs("svg",{viewBox:"0 0 120 120",className:"w-28 h-28",children:[B.map((r,a)=>{const c=r.key===l,i=l!=="idle"&&B.findIndex(f=>f.key===l)>a,o=(a*90-90)*(Math.PI/180),m=60+40*Math.cos(o),b=60+40*Math.sin(o);return e.jsxs("g",{children:[a<B.length-1&&e.jsx("line",{x1:m,y1:b,x2:60+40*Math.cos(((a+1)*90-90)*(Math.PI/180)),y2:60+40*Math.sin(((a+1)*90-90)*(Math.PI/180)),stroke:i?"#553DE9":"#ECEAE3",strokeWidth:i?2:1,strokeDasharray:i?"none":"4 3"}),a===B.length-1&&e.jsx("line",{x1:m,y1:b,x2:60+40*Math.cos(-90*(Math.PI/180)),y2:60+40*Math.sin(-90*(Math.PI/180)),stroke:"#ECEAE3",strokeWidth:1,strokeDasharray:"4 3"}),e.jsx("circle",{cx:m,cy:b,r:c?14:10,fill:c||i?"#553DE9":"#E8E4FD",stroke:c?"#4432c4":i?"#553DE9":"#ECEAE3",strokeWidth:c?3:1.5,className:c?"phase-active":""}),e.jsx("text",{x:m,y:b+(a===0?-20:a===2?24:0),textAnchor:"middle",className:"text-[9px] font-semibold fill-ink",dx:a===1?22:a===3?-22:0,children:r.label[0]})]},r.key)}),e.jsx("text",{x:"60",y:"64",textAnchor:"middle",className:"text-lg font-bold font-mono fill-primary",children:s})]})}),e.jsx("div",{className:"space-y-2",children:B.map(r=>{const a=r.key===l;return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-card transition-all duration-200 ${a?"bg-primary/8 border border-primary/20":"opacity-50"}`,children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${a?"bg-primary phase-active":"bg-border"}`}),e.jsxs("div",{children:[e.jsx("span",{className:`text-sm font-semibold ${a?"text-primary":"text-muted"}`,children:r.label}),a&&e.jsx("p",{className:"text-xs text-muted mt-0.5",children:r.description})]})]},r.key)})})]})}const W={architect:"bg-primary/10 text-primary border-primary/20",developer:"bg-primary/10 text-primary border-primary/20",tester:"bg-success/10 text-success border-success/20",reviewer:"bg-warning/10 text-warning border-warning/20",planner:"bg-primary/60/20 text-ink border-primary/60/30",default:"bg-border/30 text-muted border-border/50"};function Re(t){if(!t)return W.default;const s=t.toLowerCase();for(const[l,r]of Object.entries(W))if(s.includes(l))return r;return W.default}function Te({agents:t,loading:s}){const l=(t==null?void 0:t.filter(a=>a.alive))||[],r=(t==null?void 0:t.filter(a=>!a.alive))||[];return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Agents"}),e.jsxs("span",{className:"font-mono text-xs text-muted",children:[l.length," active"]})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading agents..."}),!s&&(t==null?void 0:t.length)===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No agents running"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Start a build to spawn agents"})]}),l.length>0&&e.jsx("div",{className:"space-y-2 mb-4",children:l.map(a=>e.jsx(K,{agent:a},a.id))}),r.length>0&&e.jsxs("details",{className:"mt-3",children:[e.jsxs("summary",{className:"text-xs text-muted cursor-pointer hover:text-ink transition-colors",children:[r.length," completed"]}),e.jsx("div",{className:"space-y-1.5 mt-2",children:r.slice(0,10).map(a=>e.jsx(K,{agent:a,compact:!0},a.id))})]})]})}function K({agent:t,compact:s}){const l=Re(t.type||t.name||"");return s?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-btn bg-hover text-xs",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted/30"}),e.jsx("span",{className:"font-medium text-muted truncate",children:t.name||t.id}),e.jsx("span",{className:"text-primary/60 ml-auto",children:t.type})]}):e.jsxs("div",{className:`flex items-start gap-3 px-3 py-2.5 rounded-card border ${l}`,children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.alive?"bg-success phase-active":"bg-muted/30"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold truncate",children:t.name||t.id}),t.type&&e.jsx("span",{className:"text-xs font-mono font-medium opacity-70",children:t.type})]}),t.task&&e.jsx("p",{className:"text-xs opacity-70 mt-0.5 truncate",children:t.task}),t.status&&t.status!=="unknown"&&e.jsx("span",{className:"inline-block text-xs font-mono mt-1 opacity-60",children:t.status})]}),t.pid&&e.jsxs("span",{className:"text-xs font-mono text-muted-accessible flex-shrink-0",children:["PID ",t.pid]})]})}const Me={pass:{badge:"bg-success/10 text-success border-success/20",dot:"bg-success",label:"Pass"},fail:{badge:"bg-danger/10 text-danger border-danger/20",dot:"bg-danger",label:"Fail"},skip:{badge:"bg-muted/10 text-muted border-muted/20",dot:"bg-muted/40",label:"Skip"},pending:{badge:"bg-warning/10 text-warning border-warning/20",dot:"bg-warning",label:"Pending"}};function $e({item:t}){const[s,l]=n.useState(!1),r=Me[t.status];return e.jsxs("div",{className:`border rounded-card overflow-hidden ${r.badge}`,children:[e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",onClick:()=>t.details&&l(!s),children:[e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${r.dot}`}),e.jsx("span",{className:"text-sm font-medium flex-1 truncate",children:t.label}),e.jsx("span",{className:"text-xs font-mono font-semibold uppercase tracking-wider flex-shrink-0",children:r.label}),t.details&&e.jsx("span",{className:"text-xs text-muted/60 flex-shrink-0",children:s?"v":">"})]}),s&&t.details&&e.jsx("div",{className:"px-3 pb-2.5 pt-0",children:e.jsx("p",{className:"text-xs font-mono opacity-70 leading-relaxed",children:t.details})})]})}function Ie({checklist:t,loading:s}){const l=t&&t.total>0?t.passed/t.total*100:0;return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Quality Gates"}),t&&e.jsxs("span",{className:"font-mono text-xs text-muted",children:[t.passed,"/",t.total," passed"]})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading gates..."}),!s&&!t&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No quality gate data"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Gates run during verification phase"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-3 text-xs",children:[e.jsxs("span",{className:"text-success font-medium",children:[t.passed," passed"]}),t.failed>0&&e.jsxs("span",{className:"text-danger font-medium",children:[t.failed," failed"]}),t.skipped>0&&e.jsxs("span",{className:"text-muted",children:[t.skipped," skipped"]}),t.pending>0&&e.jsxs("span",{className:"text-warning",children:[t.pending," pending"]})]}),e.jsx("div",{className:"w-full h-2 bg-charcoal/10 rounded-full overflow-hidden mb-4",children:e.jsx("div",{className:"h-full bg-success rounded-full transition-all duration-500",style:{width:`${l}%`}})}),e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto terminal-scroll",children:t.items.map(r=>e.jsx($e,{item:r},r.id))})]})]})}const Ae={".py":"bg-success",".ts":"bg-primary",".tsx":"bg-primary",".md":"bg-warning",".sh":"bg-primary"};function De(t){const s=t.substring(t.lastIndexOf("."));return Ae[s]||"bg-muted"}function Be(t){return t==null?"":t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/(1024*1024)).toFixed(1)}MB`}const V=100;function X({node:t,depth:s,onSelectFile:l,selectedPath:r}){const[a,c]=n.useState(!1),[i,o]=n.useState(V),m=t.type==="directory",b=t.path===r,f=m&&a?t.children??[]:[],y=f.length>i;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:`w-full flex items-center gap-2 px-2 py-1 rounded-btn text-left text-sm transition-colors hover:bg-hover ${b?"bg-primary/10 text-primary":"text-ink"}`,style:{paddingLeft:`${s*16+8}px`},onClick:()=>{m?(c(!a),a&&o(V)):l(t.path)},children:[m?e.jsx("span",{className:"font-mono text-xs text-muted w-3 flex-shrink-0",children:a?"v":">"}):e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${De(t.name)}`}),e.jsx("span",{className:`truncate ${m?"font-medium":"font-mono text-xs"}`,children:t.name}),!m&&t.size!==void 0&&e.jsx("span",{className:"ml-auto text-xs font-mono text-muted-accessible flex-shrink-0",children:Be(t.size)})]}),f.length>0&&e.jsxs("div",{children:[f.slice(0,i).map(d=>e.jsx(X,{node:d,depth:s+1,onSelectFile:l,selectedPath:r},d.path)),y&&e.jsxs("button",{type:"button",className:"w-full text-left text-xs text-primary hover:text-primary/80 py-1 transition-colors",style:{paddingLeft:`${(s+1)*16+8}px`},onClick:()=>o(d=>d+V),children:["Show more (",f.length-i," remaining)"]})]})]})}function ze({files:t,loading:s}){const[l,r]=n.useState(null),[a,c]=n.useState(null),[i,o]=n.useState(!1),[m,b]=n.useState(null),f=n.useCallback(async d=>{c(null),r(d),o(!0),b(null);try{const g=await h.getFileContent(d);c(g.content)}catch(g){const j=g instanceof Error?g.message:"Unknown error",v=g instanceof TypeError||j==="Request timeout",w=j.includes("404")||j.includes("not found")||j.includes("Not found");b(v?"Network error - server may be unreachable":w?"File not found - it may have been deleted or renamed":j),c(null)}finally{o(!1)}},[]),y=n.useCallback(d=>{f(d)},[f]);return e.jsxs("div",{className:"card p-6 flex flex-col",style:{minHeight:"300px"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"File Browser"}),e.jsx("span",{className:"font-mono text-xs text-muted",children:".loki/"})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading files..."}),!s&&(!t||t.length===0)&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No project files found"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Start a session to generate .loki/ state"})]}),t&&t.length>0&&e.jsxs("div",{className:"flex gap-4 flex-1 min-h-0",children:[e.jsx("div",{className:"w-1/2 overflow-y-auto terminal-scroll pr-2",children:t.map(d=>e.jsx(X,{node:d,depth:0,onSelectFile:y,selectedPath:l},d.path))}),e.jsxs("div",{className:"w-1/2 bg-charcoal/5 rounded-card p-3 overflow-hidden flex flex-col",children:[!l&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted text-xs",children:"Select a file to preview"}),l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs font-mono text-primary mb-2 truncate",children:l}),e.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:i?e.jsx("div",{className:"text-muted text-xs",children:"Loading..."}):m?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-6",children:[e.jsx("p",{className:"text-danger text-xs font-medium",children:"Failed to load file"}),e.jsx("p",{className:"text-muted-accessible text-xs text-center max-w-[200px] break-words",children:m}),e.jsx("button",{type:"button",onClick:()=>l&&f(l),className:"mt-1 px-3 py-1 text-xs font-semibold rounded-btn border border-primary/20 text-primary hover:bg-primary/5 transition-colors",children:"Retry"})]}):e.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap break-words leading-relaxed",children:a})})]})]})]})]})}const Y=5e5;function Z(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString()}function Ue(t){if(!t)return"Never";try{const s=new Date(t),r=new Date().getTime()-s.getTime(),a=Math.floor(r/(1e3*60*60));return a<1?"Just now":a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}catch{return t}}function Oe({memory:t,loading:s}){const l=t?[{label:"Episodic",count:t.episodic_count,color:"text-primary",bg:"bg-primary/10",border:"border-primary/20"},{label:"Semantic",count:t.semantic_count,color:"text-success",bg:"bg-success/10",border:"border-success/20"},{label:"Skills",count:t.skill_count,color:"text-warning",bg:"bg-warning/10",border:"border-warning/20"}]:[],r=t?Math.min(t.total_tokens/Y*100,100):0;return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Memory System"}),t&&e.jsx("span",{className:"font-mono text-xs text-muted",children:Ue(t.last_consolidation)})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading memory..."}),!s&&!t&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No memory data available"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Memory populates during autonomous runs"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-3 gap-3 mb-4",children:l.map(a=>e.jsxs("div",{className:`${a.bg} border ${a.border} rounded-card p-3 text-center`,children:[e.jsx("div",{className:`text-2xl font-bold font-mono ${a.color}`,children:a.count}),e.jsx("div",{className:"text-xs text-muted-accessible font-medium mt-1 uppercase tracking-wider",children:a.label})]},a.label))}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs text-muted font-medium",children:"Token Usage"}),e.jsxs("span",{className:"text-xs font-mono text-ink",children:[Z(t.total_tokens)," / ",Z(Y)]})]}),e.jsx("div",{className:"w-full h-2 bg-charcoal/10 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${r>80?"bg-danger":r>50?"bg-warning":"bg-info"}`,style:{width:`${r}%`}})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted",children:"Last Consolidation"}),e.jsx("span",{className:"font-mono text-ink",children:t.last_consolidation?new Date(t.last_consolidation).toLocaleString():"Never"})]})]})]})}function qe({visible:t}){const[s,l]=n.useState("markdown"),[r,a]=n.useState(null),[c,i]=n.useState(null),[o,m]=n.useState(!1),[b,f]=n.useState(!1),[y,d]=n.useState(null),[g,j]=n.useState(!1);if(!t)return null;const v=async()=>{m(!0),d(null),a(null),i(null);try{const x=await h.generateReport(s);a(x)}catch(x){d(x instanceof Error?x.message:"Failed to generate report")}finally{m(!1)}},w=async()=>{f(!0),d(null);try{const x=await h.shareSession();i(x)}catch(x){d(x instanceof Error?x.message:"Failed to share session")}finally{f(!1)}},k=async x=>{try{await navigator.clipboard.writeText(x),j(!0),setTimeout(()=>j(!1),2e3)}catch{}},T=()=>{if(!r)return;const x=new Blob([r.content],{type:s==="html"?"text/html":"text/markdown"}),P=URL.createObjectURL(x),N=document.createElement("a");N.href=P,N.download=`loki-report.${s==="html"?"html":"md"}`,N.click(),URL.revokeObjectURL(P)};return e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Session Report"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-1 card rounded-card p-1",children:["markdown","html"].map(x=>e.jsx("button",{onClick:()=>l(x),className:`px-3 py-1 text-xs font-semibold rounded-btn transition-all ${s===x?"bg-primary text-white shadow-sm":"text-muted hover:text-ink hover:bg-hover"}`,children:x.toUpperCase()},x))}),e.jsx("button",{onClick:v,disabled:o,className:"px-4 py-1.5 rounded-card text-xs font-semibold bg-primary text-white hover:bg-primary/90 disabled:opacity-50 transition-all",children:o?"Generating...":"Generate Report"})]})]}),y&&e.jsx("div",{className:"mb-3 px-3 py-2 rounded-btn bg-danger/10 border border-danger/20 text-danger text-xs",children:y}),r&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:"text-xs text-muted",children:["Report generated (",r.format,")"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>k(r.content),className:"px-3 py-1 text-xs font-medium text-muted hover:text-ink border border-border-light rounded-btn hover:bg-hover transition-all",children:g?"Copied":"Copy"}),e.jsx("button",{onClick:T,className:"px-3 py-1 text-xs font-medium text-muted hover:text-ink border border-border-light rounded-btn hover:bg-hover transition-all",children:"Download"}),e.jsx("button",{onClick:w,disabled:b,className:"px-3 py-1 text-xs font-medium bg-primary/10 text-primary border border-primary/20 rounded-btn hover:bg-primary/20 disabled:opacity-50 transition-all",children:b?"Sharing...":"Share as Gist"})]}),c&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 px-3 py-2 rounded-btn bg-success/10 border border-success/20",children:[e.jsx("span",{className:"text-xs text-success font-medium",children:"Shared:"}),c.url?e.jsx("a",{href:c.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary underline flex-1 truncate",children:c.url}):e.jsx("span",{className:"text-xs text-muted flex-1",children:"No URL returned"}),c.url&&e.jsx("button",{onClick:()=>k(c.url),className:"text-xs text-muted hover:text-ink",children:"Copy URL"})]}),e.jsx("pre",{className:"text-[11px] font-mono text-ink bg-black/5 rounded-card p-3 overflow-auto max-h-64 whitespace-pre-wrap terminal-scroll",children:r.content||"(empty report)"})]})]})}function J({visible:t}){const s=n.useCallback(()=>h.getMetrics(),[]),{data:l,loading:r}=I(s,15e3,t);return t?e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Session Metrics"}),r&&e.jsx("div",{className:"w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin"})]}),l?e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Iterations"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:l.iterations??0})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Gate Pass Rate"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:typeof l.quality_gate_pass_rate=="number"?`${l.quality_gate_pass_rate.toFixed(0)}%`:"N/A"})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Tokens Used"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:(l.tokens_used??0).toLocaleString()})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Time Elapsed"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:l.time_elapsed||"N/A"})]})]}):e.jsx("div",{className:"text-sm text-muted py-4 text-center",children:r?"Loading metrics...":"No metrics available"})]}):null}function He(t){switch(t){case"completed":case"complete":case"done":return"completed";case"in_progress":return"running";case"started":return"started";case"error":case"failed":return"failed";default:return"empty"}}const Ge={completed:"Completed",complete:"Completed",done:"Completed",in_progress:"In Progress",started:"Started",error:"Failed",failed:"Failed",empty:"Empty"};function We({onLoadSession:t}){const s=n.useCallback(()=>h.getSessionsHistory(),[]),{data:l,loading:r}=I(s,6e4,!0);return r&&!l?e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider mb-3",children:"Past Builds"}),e.jsx("div",{className:"text-sm text-muted",children:"Loading..."})]}):!l||l.length===0?null:e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider mb-3",children:"Past Builds"}),e.jsx("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto terminal-scroll",children:l.map(a=>{const c=a.file_count;return e.jsxs("button",{onClick:()=>t==null?void 0:t(a),className:"text-left px-4 py-3 rounded-card card hover:bg-hover transition-all group cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-mono text-muted-accessible",children:a.date}),e.jsxs("div",{className:"flex items-center gap-2",children:[c!==void 0&&c>0&&e.jsxs("span",{className:"text-xs font-mono text-muted-accessible",children:[c," files"]}),e.jsx(je,{status:He(a.status),children:Ge[a.status]||a.status})]})]}),e.jsx("div",{className:"text-xs text-ink truncate group-hover:text-primary transition-colors",children:a.prd_snippet||a.id}),e.jsx("div",{className:"text-xs font-mono text-muted-accessible mt-0.5 truncate",children:a.path})]},a.id)})})]})}function Ze(){const t=be(),[s,l]=n.useState(null),[r,a]=n.useState(()=>sessionStorage.getItem("pl_running")==="1"),[c,i]=n.useState(!1),[o,m]=n.useState(()=>sessionStorage.getItem("pl_prd")),[b,f]=n.useState(!1),[y,d]=n.useState(!1),[g,j]=n.useState(!1),[v,w]=n.useState(()=>sessionStorage.getItem("pl_tab")||"terminal"),[k,T]=n.useState(()=>sessionStorage.getItem("pl_provider")||"claude"),[x,P]=n.useState(void 0);n.useEffect(()=>{const p=sessionStorage.getItem("pl_template");p&&(sessionStorage.removeItem("pl_template"),h.getTemplateContent(p).then(({content:U})=>{U&&P(U)}).catch(()=>{}))},[]);const[N,M]=n.useState(null),[_,A]=n.useState(null),[z,F]=n.useState(null),L=n.useCallback(p=>{if(!p){M(null),A(null),F(null);return}M(p.status),A(p.agents),F(p.logs),a(p.status.running??!1),i(p.status.paused??!1)},[]),{connected:$,subscribe:O}=ge(L),D=n.useCallback(()=>h.getStatus(),[]),{data:R}=I(D,3e4,!$);n.useEffect(()=>{N===null&&R!==null&&(a(R.running??!1),i(R.paused??!1))},[R,N]),n.useEffect(()=>{sessionStorage.setItem("pl_running",r?"1":"0"),r&&f(!0)},[r]),n.useEffect(()=>{o?sessionStorage.setItem("pl_prd",o):sessionStorage.removeItem("pl_prd")},[o]),n.useEffect(()=>{sessionStorage.setItem("pl_provider",k)},[k]),n.useEffect(()=>{sessionStorage.setItem("pl_tab",v)},[v]);const q=n.useCallback(()=>h.getMemorySummary(),[]),H=n.useCallback(()=>h.getChecklist(),[]),u=n.useCallback(()=>h.getFiles(),[]),{data:S,loading:G}=I(q,3e4,r),{data:ee,loading:te}=I(H,3e4,r),{data:se,loading:ae}=I(u,3e4,r),C=N??R,re=_,ne=z,le=_===null,ie=z===null,ce=n.useCallback(async(p,U,he,fe)=>{l(null),f(!1),d(!1),w("terminal");try{await h.startSession({prd:p,provider:U,projectDir:he,mode:fe}),m(p),a(!0)}catch(Q){l(Q instanceof Error?Q.message:"Failed to start session")}},[]),oe=n.useCallback(async()=>{try{(await h.stopSession()).stopped&&(a(!1),i(!1),m(null),M(null),A(null),F(null))}catch{a(!1),i(!1),m(null)}sessionStorage.removeItem("pl_running"),sessionStorage.removeItem("pl_prd"),sessionStorage.removeItem("pl_tab")},[]),de=n.useCallback(p=>{t(`/project/${p.id}`)},[t]),xe=n.useCallback(p=>{T(p)},[]),me=n.useCallback(async()=>{try{await h.pauseSession(),i(!0)}catch{}},[]),ue=n.useCallback(async()=>{try{await h.resumeSession(),i(!1)}catch{}},[]),pe=o&&o.replace(/^#+\s*/gm,"").split(`
18
- `).find(p=>p.trim().length>0)||null;return e.jsxs("div",{className:"min-h-screen bg-[#FAF9F6] relative",children:[e.jsx("div",{className:"pattern-nodes"}),e.jsx("div",{className:"max-w-[1920px] mx-auto px-6 py-6 relative z-10",children:r?e.jsxs(e.Fragment,{children:[e.jsx(E,{name:"ControlBar",children:e.jsx(Ce,{status:C,prdSummary:pe,onStop:oe,onPause:me,onResume:ue,isPaused:c})}),e.jsx("div",{className:"mt-4",children:e.jsx(E,{name:"StatusOverview",children:e.jsx(Ee,{status:C})})}),e.jsxs("div",{className:"mt-4 grid grid-cols-12 gap-6",style:{height:"calc(100vh - 340px)",minHeight:"400px"},children:[e.jsx("div",{className:"col-span-3 flex flex-col gap-6",children:e.jsx(E,{name:"PhaseVisualizer",children:e.jsx(Le,{currentPhase:(C==null?void 0:C.phase)||"idle",iteration:(C==null?void 0:C.iteration)||0})})}),e.jsxs("div",{className:"col-span-5 flex flex-col gap-0 min-h-0",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>w("terminal"),className:`px-3 py-1.5 text-xs font-semibold rounded-lg transition-all ${v==="terminal"?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:"Terminal"}),e.jsx("button",{onClick:()=>w("metrics"),className:`px-3 py-1.5 text-xs font-semibold rounded-lg transition-all ${v==="metrics"?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:"Metrics"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(E,{name:"Terminal",children:v==="terminal"?e.jsx(we,{logs:ne,loading:ie,subscribe:O}):e.jsx(J,{visible:!0})})})]}),e.jsxs("div",{className:"col-span-4 flex flex-col gap-6 overflow-y-auto",children:[e.jsx(E,{name:"AgentDashboard",children:e.jsx(Te,{agents:re,loading:le})}),e.jsx(E,{name:"QualityGates",children:e.jsx(Ie,{checklist:ee,loading:te})})]})]}),e.jsxs("div",{className:"mt-6 grid grid-cols-12 gap-6",children:[e.jsx("div",{className:"col-span-6",children:e.jsx(E,{name:"FileBrowser",children:e.jsx(ze,{files:se,loading:ae})})}),e.jsx("div",{className:"col-span-6",children:e.jsx(E,{name:"MemoryViewer",children:e.jsx(Oe,{memory:S,loading:G})})})]})]}):e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"text-center mt-8 mb-8",children:[e.jsx("h2",{className:"font-heading text-h1 text-[#36342E]",children:"Describe it. Build it. Ship it."}),e.jsx("p",{className:"text-[#6B6960] mt-2 text-base max-w-lg mx-auto",children:"Paste a PRD or pick a template. Purple Lab spins up autonomous agents to build your project from scratch."})]}),e.jsx("div",{className:"w-full max-w-3xl",children:e.jsx(_e,{onSubmit:ce,running:r,error:s,provider:k,onProviderChange:xe,initialPrd:x})}),b&&!r&&e.jsxs("div",{className:"w-full max-w-3xl mt-4 flex flex-col gap-4",children:[e.jsx("button",{onClick:async()=>{try{const p=await h.getSessionsHistory();p.length>0&&t(`/project/${p[0].id}`)}catch{}},className:"w-full px-6 py-4 rounded-card text-base font-bold bg-[#553DE9] text-white hover:bg-[#553DE9]/90 transition-all shadow-lg shadow-[#553DE9]/20",children:"View Project -- Browse Files and Preview"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>d(!y),className:"px-4 py-2 rounded-card text-sm font-semibold border border-[#553DE9]/30 text-[#553DE9] hover:bg-[#553DE9]/5 transition-all",children:y?"Hide Report":"Report"}),e.jsx("button",{onClick:()=>j(!g),className:"px-4 py-2 rounded-card text-sm font-semibold border border-[#ECEAE3] text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0] transition-all",children:g?"Hide Metrics":"Metrics"})]}),e.jsx(qe,{visible:y}),e.jsx(J,{visible:g})]}),e.jsx("div",{className:"w-full max-w-3xl mt-4",children:e.jsx(We,{onLoadSession:de})}),e.jsxs("div",{className:"mt-6 text-xs text-[#6B6960] flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${$?"bg-[#1FC5A8]":"bg-[#C45B5B]"}`}),$?"Connected to Purple Lab backend":"Waiting for backend connection..."]})]})})]})}export{Ze as default};
17
+ `)}},[]),q=async()=>{if(!(!i.trim()||F)){$(!0),_(null),B(!0);try{const p=await h.planSession(i,j);_(p)}catch{_({complexity:"unknown",cost_estimate:"N/A",iterations:0,phases:[],output_text:"Failed to run loki plan. The CLI may not be available.",returncode:1})}finally{$(!1)}}},H=async()=>{if(!(!i.trim()||s||N)){B(!1),M(!0);try{await t(i,j,d.trim()||void 0,P?"quick":void 0)}finally{M(!1)}}};return e.jsxs(e.Fragment,{children:[O&&e.jsx(Pe,{plan:z,loading:F,onConfirm:H,onCancel:()=>B(!1)}),e.jsxs("div",{className:"card p-6 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Product Requirements"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>w(!v),className:"text-xs font-medium px-3 py-1.5 rounded-card border border-primary/20 text-primary hover:bg-primary/5 transition-colors",children:m||"Templates"}),v&&e.jsx("div",{className:"absolute right-0 top-full mt-1 w-56 card rounded-card overflow-hidden z-20 shadow-card-hover",children:e.jsxs("div",{className:"py-1 max-h-64 overflow-y-auto terminal-scroll",children:[x&&e.jsx("div",{className:"px-3 py-2 text-xs text-warning border-b border-warning/10",children:"Could not load templates from server. Check that the backend is running."}),!x&&k.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-muted",children:"Loading..."}),k.map(p=>e.jsx("button",{onClick:()=>R(p.filename,p.name),className:"w-full text-left px-3 py-2 text-sm text-ink hover:bg-primary/5 transition-colors",children:p.name},p.filename))]})})]})})]}),e.jsx("textarea",{value:i,onChange:p=>o(p.target.value),placeholder:"Paste your PRD here, or select a template above to get started...",className:"flex-1 min-h-[280px] w-full bg-card rounded-card border border-border-light px-4 py-3 text-sm font-mono text-ink placeholder:text-primary/60 resize-none focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/30 transition-all",spellCheck:!1}),e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-xs text-muted font-medium mb-1 uppercase tracking-wider",children:"Project Directory"}),e.jsx("input",{type:"text",value:d,onChange:p=>g(p.target.value),placeholder:"Leave blank to auto-create, or type a path (e.g. /Users/you/my-project)",className:"w-full bg-card rounded-card border border-border-light px-4 py-2 text-sm font-mono text-ink placeholder:text-primary/60/70 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/30 transition-all",spellCheck:!1}),e.jsx("p",{className:"text-xs text-muted-accessible mt-1",children:"Type a path or leave blank to auto-create under ~/purple-lab-projects/"})]}),n&&e.jsx("div",{className:"mt-3 px-3 py-2 rounded-btn bg-danger/10 border border-danger/20 text-danger text-xs font-medium",children:n}),e.jsxs("div",{className:"flex items-center gap-3 mt-4",children:[e.jsxs("button",{onClick:()=>A(!P),title:"Quick Mode: 3 iterations max, faster builds",className:`flex items-center gap-1.5 px-3 py-1.5 rounded-card text-xs font-semibold border transition-all ${P?"bg-primary/10 border-primary/30 text-primary":"border-border-light text-muted hover:text-ink hover:bg-card"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${P?"bg-primary":"bg-muted/40"}`}),"Quick"]}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted font-mono",children:[i.length.toLocaleString()," chars"]}),e.jsx("button",{onClick:q,disabled:!i.trim()||s||N||F,className:`px-6 py-2.5 rounded-card text-sm font-semibold transition-all ${!i.trim()||s||N||F?"bg-primary/10 text-muted cursor-not-allowed":"bg-primary text-white hover:bg-primary/90 shadow-button"}`,children:F?"Analyzing...":N?"Starting...":s?"Building...":"Start Build"})]})]})]})}const D=[{key:"reason",label:"Reason",description:"Analyzing task, planning approach"},{key:"act",label:"Act",description:"Implementing changes, writing code"},{key:"reflect",label:"Reflect",description:"Reviewing output, self-critique"},{key:"verify",label:"Verify",description:"Testing, validation, quality gates"}];function Fe(t){if(!t)return"reason";const s=t.toLowerCase();return s.includes("reason")||s.includes("plan")?"reason":s.includes("act")||s.includes("implement")||s.includes("code")?"act":s.includes("reflect")||s.includes("review")?"reflect":s.includes("verify")||s.includes("test")||s.includes("check")?"verify":"idle"}function Re({currentPhase:t,iteration:s}){const n=Fe(t);return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"RARV Cycle"}),e.jsxs("span",{className:"font-mono text-xs text-muted",children:["Iteration ",s]})]}),e.jsx("div",{className:"flex items-center justify-center mb-5",children:e.jsxs("svg",{viewBox:"0 0 120 120",className:"w-28 h-28",children:[D.map((r,a)=>{const c=r.key===n,i=n!=="idle"&&D.findIndex(f=>f.key===n)>a,o=(a*90-90)*(Math.PI/180),m=60+40*Math.cos(o),b=60+40*Math.sin(o);return e.jsxs("g",{children:[a<D.length-1&&e.jsx("line",{x1:m,y1:b,x2:60+40*Math.cos(((a+1)*90-90)*(Math.PI/180)),y2:60+40*Math.sin(((a+1)*90-90)*(Math.PI/180)),stroke:i?"#553DE9":"#ECEAE3",strokeWidth:i?2:1,strokeDasharray:i?"none":"4 3"}),a===D.length-1&&e.jsx("line",{x1:m,y1:b,x2:60+40*Math.cos(-90*(Math.PI/180)),y2:60+40*Math.sin(-90*(Math.PI/180)),stroke:"#ECEAE3",strokeWidth:1,strokeDasharray:"4 3"}),e.jsx("circle",{cx:m,cy:b,r:c?14:10,fill:c||i?"#553DE9":"#E8E4FD",stroke:c?"#4432c4":i?"#553DE9":"#ECEAE3",strokeWidth:c?3:1.5,className:c?"phase-active":""}),e.jsx("text",{x:m,y:b+(a===0?-20:a===2?24:0),textAnchor:"middle",className:"text-[9px] font-semibold fill-ink",dx:a===1?22:a===3?-22:0,children:r.label[0]})]},r.key)}),e.jsx("text",{x:"60",y:"64",textAnchor:"middle",className:"text-lg font-bold font-mono fill-primary",children:s})]})}),e.jsx("div",{className:"space-y-2",children:D.map(r=>{const a=r.key===n;return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-card transition-all duration-200 ${a?"bg-primary/8 border border-primary/20":"opacity-50"}`,children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${a?"bg-primary phase-active":"bg-border"}`}),e.jsxs("div",{children:[e.jsx("span",{className:`text-sm font-semibold ${a?"text-primary":"text-muted"}`,children:r.label}),a&&e.jsx("p",{className:"text-xs text-muted mt-0.5",children:r.description})]})]},r.key)})})]})}const W={architect:"bg-primary/10 text-primary border-primary/20",developer:"bg-primary/10 text-primary border-primary/20",tester:"bg-success/10 text-success border-success/20",reviewer:"bg-warning/10 text-warning border-warning/20",planner:"bg-primary/60/20 text-ink border-primary/60/30",default:"bg-border/30 text-muted border-border/50"};function Le(t){if(!t)return W.default;const s=t.toLowerCase();for(const[n,r]of Object.entries(W))if(s.includes(n))return r;return W.default}function Te({agents:t,loading:s}){const n=(t==null?void 0:t.filter(a=>a.alive))||[],r=(t==null?void 0:t.filter(a=>!a.alive))||[];return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Agents"}),e.jsxs("span",{className:"font-mono text-xs text-muted",children:[n.length," active"]})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading agents..."}),!s&&(t==null?void 0:t.length)===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No agents running"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Start a build to spawn agents"})]}),n.length>0&&e.jsx("div",{className:"space-y-2 mb-4",children:n.map(a=>e.jsx(K,{agent:a},a.id))}),r.length>0&&e.jsxs("details",{className:"mt-3",children:[e.jsxs("summary",{className:"text-xs text-muted cursor-pointer hover:text-ink transition-colors",children:[r.length," completed"]}),e.jsx("div",{className:"space-y-1.5 mt-2",children:r.slice(0,10).map(a=>e.jsx(K,{agent:a,compact:!0},a.id))})]})]})}function K({agent:t,compact:s}){const n=Le(t.type||t.name||"");return s?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-btn bg-hover text-xs",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted/30"}),e.jsx("span",{className:"font-medium text-muted truncate",children:t.name||t.id}),e.jsx("span",{className:"text-primary/60 ml-auto",children:t.type})]}):e.jsxs("div",{className:`flex items-start gap-3 px-3 py-2.5 rounded-card border ${n}`,children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.alive?"bg-success phase-active":"bg-muted/30"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold truncate",children:t.name||t.id}),t.type&&e.jsx("span",{className:"text-xs font-mono font-medium opacity-70",children:t.type})]}),t.task&&e.jsx("p",{className:"text-xs opacity-70 mt-0.5 truncate",children:t.task}),t.status&&t.status!=="unknown"&&e.jsx("span",{className:"inline-block text-xs font-mono mt-1 opacity-60",children:t.status})]}),t.pid&&e.jsxs("span",{className:"text-xs font-mono text-muted-accessible flex-shrink-0",children:["PID ",t.pid]})]})}const Me={pass:{badge:"bg-success/10 text-success border-success/20",dot:"bg-success",label:"Pass"},fail:{badge:"bg-danger/10 text-danger border-danger/20",dot:"bg-danger",label:"Fail"},skip:{badge:"bg-muted/10 text-muted border-muted/20",dot:"bg-muted/40",label:"Skip"},pending:{badge:"bg-warning/10 text-warning border-warning/20",dot:"bg-warning",label:"Pending"}};function $e({item:t}){const[s,n]=l.useState(!1),r=Me[t.status];return e.jsxs("div",{className:`border rounded-card overflow-hidden ${r.badge}`,children:[e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3 py-2.5 text-left",onClick:()=>t.details&&n(!s),children:[e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${r.dot}`}),e.jsx("span",{className:"text-sm font-medium flex-1 truncate",children:t.label}),e.jsx("span",{className:"text-xs font-mono font-semibold uppercase tracking-wider flex-shrink-0",children:r.label}),t.details&&e.jsx("span",{className:"text-xs text-muted/60 flex-shrink-0",children:s?"v":">"})]}),s&&t.details&&e.jsx("div",{className:"px-3 pb-2.5 pt-0",children:e.jsx("p",{className:"text-xs font-mono opacity-70 leading-relaxed",children:t.details})})]})}function Ie({checklist:t,loading:s}){const n=t&&t.total>0?t.passed/t.total*100:0;return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Quality Gates"}),t&&e.jsxs("span",{className:"font-mono text-xs text-muted",children:[t.passed,"/",t.total," passed"]})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading gates..."}),!s&&!t&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No quality gate data"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Gates run during verification phase"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-3 text-xs",children:[e.jsxs("span",{className:"text-success font-medium",children:[t.passed," passed"]}),t.failed>0&&e.jsxs("span",{className:"text-danger font-medium",children:[t.failed," failed"]}),t.skipped>0&&e.jsxs("span",{className:"text-muted",children:[t.skipped," skipped"]}),t.pending>0&&e.jsxs("span",{className:"text-warning",children:[t.pending," pending"]})]}),e.jsx("div",{className:"w-full h-2 bg-charcoal/10 rounded-full overflow-hidden mb-4",children:e.jsx("div",{className:"h-full bg-success rounded-full transition-all duration-500",style:{width:`${n}%`}})}),e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto terminal-scroll",children:t.items.map(r=>e.jsx($e,{item:r},r.id))})]})]})}const Ae={".py":"bg-success",".ts":"bg-primary",".tsx":"bg-primary",".md":"bg-warning",".sh":"bg-primary"};function Be(t){const s=t.substring(t.lastIndexOf("."));return Ae[s]||"bg-muted"}function De(t){return t==null?"":t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/(1024*1024)).toFixed(1)}MB`}const V=100;function X({node:t,depth:s,onSelectFile:n,selectedPath:r}){const[a,c]=l.useState(!1),[i,o]=l.useState(V),m=t.type==="directory",b=t.path===r,f=m&&a?t.children??[]:[],y=f.length>i;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:`w-full flex items-center gap-2 px-2 py-1 rounded-btn text-left text-sm transition-colors hover:bg-hover ${b?"bg-primary/10 text-primary":"text-ink"}`,style:{paddingLeft:`${s*16+8}px`},onClick:()=>{m?(c(!a),a&&o(V)):n(t.path)},children:[m?e.jsx("span",{className:"font-mono text-xs text-muted w-3 flex-shrink-0",children:a?"v":">"}):e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${Be(t.name)}`}),e.jsx("span",{className:`truncate ${m?"font-medium":"font-mono text-xs"}`,children:t.name}),!m&&t.size!==void 0&&e.jsx("span",{className:"ml-auto text-xs font-mono text-muted-accessible flex-shrink-0",children:De(t.size)})]}),f.length>0&&e.jsxs("div",{children:[f.slice(0,i).map(d=>e.jsx(X,{node:d,depth:s+1,onSelectFile:n,selectedPath:r},d.path)),y&&e.jsxs("button",{type:"button",className:"w-full text-left text-xs text-primary hover:text-primary/80 py-1 transition-colors",style:{paddingLeft:`${(s+1)*16+8}px`},onClick:()=>o(d=>d+V),children:["Show more (",f.length-i," remaining)"]})]})]})}function ze({files:t,loading:s}){const[n,r]=l.useState(null),[a,c]=l.useState(null),[i,o]=l.useState(!1),[m,b]=l.useState(null),f=l.useCallback(async d=>{c(null),r(d),o(!0),b(null);try{const g=await h.getFileContent(d);c(g.content)}catch(g){const j=g instanceof Error?g.message:"Unknown error",v=g instanceof TypeError||j==="Request timeout",w=j.includes("404")||j.includes("not found")||j.includes("Not found");b(v?"Network error - server may be unreachable":w?"File not found - it may have been deleted or renamed":j),c(null)}finally{o(!1)}},[]),y=l.useCallback(d=>{f(d)},[f]);return e.jsxs("div",{className:"card p-6 flex flex-col",style:{minHeight:"300px"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"File Browser"}),e.jsx("span",{className:"font-mono text-xs text-muted",children:".loki/"})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading files..."}),!s&&(!t||t.length===0)&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No project files found"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Start a session to generate .loki/ state"})]}),t&&t.length>0&&e.jsxs("div",{className:"flex gap-4 flex-1 min-h-0",children:[e.jsx("div",{className:"w-1/2 overflow-y-auto terminal-scroll pr-2",children:t.map(d=>e.jsx(X,{node:d,depth:0,onSelectFile:y,selectedPath:n},d.path))}),e.jsxs("div",{className:"w-1/2 bg-charcoal/5 rounded-card p-3 overflow-hidden flex flex-col",children:[!n&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted text-xs",children:"Select a file to preview"}),n&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs font-mono text-primary mb-2 truncate",children:n}),e.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:i?e.jsx("div",{className:"text-muted text-xs",children:"Loading..."}):m?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-6",children:[e.jsx("p",{className:"text-danger text-xs font-medium",children:"Failed to load file"}),e.jsx("p",{className:"text-muted-accessible text-xs text-center max-w-[200px] break-words",children:m}),e.jsx("button",{type:"button",onClick:()=>n&&f(n),className:"mt-1 px-3 py-1 text-xs font-semibold rounded-btn border border-primary/20 text-primary hover:bg-primary/5 transition-colors",children:"Retry"})]}):e.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap break-words leading-relaxed",children:a})})]})]})]})]})}const Y=5e5;function Z(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString()}function Ue(t){if(!t)return"Never";try{const s=new Date(t),r=new Date().getTime()-s.getTime(),a=Math.floor(r/(1e3*60*60));return a<1?"Just now":a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}catch{return t}}function Oe({memory:t,loading:s}){const n=t?[{label:"Episodic",count:t.episodic_count,color:"text-primary",bg:"bg-primary/10",border:"border-primary/20"},{label:"Semantic",count:t.semantic_count,color:"text-success",bg:"bg-success/10",border:"border-success/20"},{label:"Skills",count:t.skill_count,color:"text-warning",bg:"bg-warning/10",border:"border-warning/20"}]:[],r=t?Math.min(t.total_tokens/Y*100,100):0;return e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Memory System"}),t&&e.jsx("span",{className:"font-mono text-xs text-muted",children:Ue(t.last_consolidation)})]}),s&&!t&&e.jsx("div",{className:"text-center py-8 text-muted text-sm",children:"Loading memory..."}),!s&&!t&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted text-sm",children:"No memory data available"}),e.jsx("p",{className:"text-primary/60 text-xs mt-1",children:"Memory populates during autonomous runs"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-3 gap-3 mb-4",children:n.map(a=>e.jsxs("div",{className:`${a.bg} border ${a.border} rounded-card p-3 text-center`,children:[e.jsx("div",{className:`text-2xl font-bold font-mono ${a.color}`,children:a.count}),e.jsx("div",{className:"text-xs text-muted-accessible font-medium mt-1 uppercase tracking-wider",children:a.label})]},a.label))}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-xs text-muted font-medium",children:"Token Usage"}),e.jsxs("span",{className:"text-xs font-mono text-ink",children:[Z(t.total_tokens)," / ",Z(Y)]})]}),e.jsx("div",{className:"w-full h-2 bg-charcoal/10 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${r>80?"bg-danger":r>50?"bg-warning":"bg-info"}`,style:{width:`${r}%`}})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted",children:"Last Consolidation"}),e.jsx("span",{className:"font-mono text-ink",children:t.last_consolidation?new Date(t.last_consolidation).toLocaleString():"Never"})]})]})]})}function qe({visible:t}){const[s,n]=l.useState("markdown"),[r,a]=l.useState(null),[c,i]=l.useState(null),[o,m]=l.useState(!1),[b,f]=l.useState(!1),[y,d]=l.useState(null),[g,j]=l.useState(!1);if(!t)return null;const v=async()=>{m(!0),d(null),a(null),i(null);try{const x=await h.generateReport(s);a(x)}catch(x){d(x instanceof Error?x.message:"Failed to generate report")}finally{m(!1)}},w=async()=>{f(!0),d(null);try{const x=await h.shareSession();i(x)}catch(x){d(x instanceof Error?x.message:"Failed to share session")}finally{f(!1)}},k=async x=>{try{await navigator.clipboard.writeText(x),j(!0),setTimeout(()=>j(!1),2e3)}catch{}},T=()=>{if(!r)return;const x=new Blob([r.content],{type:s==="html"?"text/html":"text/markdown"}),E=URL.createObjectURL(x),N=document.createElement("a");N.href=E,N.download=`loki-report.${s==="html"?"html":"md"}`,N.click(),URL.revokeObjectURL(E)};return e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Session Report"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-1 card rounded-card p-1",children:["markdown","html"].map(x=>e.jsx("button",{onClick:()=>n(x),className:`px-3 py-1 text-xs font-semibold rounded-btn transition-all ${s===x?"bg-primary text-white shadow-sm":"text-muted hover:text-ink hover:bg-hover"}`,children:x.toUpperCase()},x))}),e.jsx("button",{onClick:v,disabled:o,className:"px-4 py-1.5 rounded-card text-xs font-semibold bg-primary text-white hover:bg-primary/90 disabled:opacity-50 transition-all",children:o?"Generating...":"Generate Report"})]})]}),y&&e.jsx("div",{className:"mb-3 px-3 py-2 rounded-btn bg-danger/10 border border-danger/20 text-danger text-xs",children:y}),r&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:"text-xs text-muted",children:["Report generated (",r.format,")"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>k(r.content),className:"px-3 py-1 text-xs font-medium text-muted hover:text-ink border border-border-light rounded-btn hover:bg-hover transition-all",children:g?"Copied":"Copy"}),e.jsx("button",{onClick:T,className:"px-3 py-1 text-xs font-medium text-muted hover:text-ink border border-border-light rounded-btn hover:bg-hover transition-all",children:"Download"}),e.jsx("button",{onClick:w,disabled:b,className:"px-3 py-1 text-xs font-medium bg-primary/10 text-primary border border-primary/20 rounded-btn hover:bg-primary/20 disabled:opacity-50 transition-all",children:b?"Sharing...":"Share as Gist"})]}),c&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 px-3 py-2 rounded-btn bg-success/10 border border-success/20",children:[e.jsx("span",{className:"text-xs text-success font-medium",children:"Shared:"}),c.url?e.jsx("a",{href:c.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary underline flex-1 truncate",children:c.url}):e.jsx("span",{className:"text-xs text-muted flex-1",children:"No URL returned"}),c.url&&e.jsx("button",{onClick:()=>k(c.url),className:"text-xs text-muted hover:text-ink",children:"Copy URL"})]}),e.jsx("pre",{className:"text-[11px] font-mono text-ink bg-black/5 rounded-card p-3 overflow-auto max-h-64 whitespace-pre-wrap terminal-scroll",children:r.content||"(empty report)"})]})]})}function J({visible:t}){const s=l.useCallback(()=>h.getMetrics(),[]),{data:n,loading:r}=I(s,15e3,t);return t?e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider",children:"Session Metrics"}),r&&e.jsx("div",{className:"w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin"})]}),n?e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Iterations"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:n.iterations??0})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Gate Pass Rate"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:typeof n.quality_gate_pass_rate=="number"?`${n.quality_gate_pass_rate.toFixed(0)}%`:"N/A"})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Tokens Used"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:(n.tokens_used??0).toLocaleString()})]}),e.jsxs("div",{className:"card rounded-card p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-1",children:"Time Elapsed"}),e.jsx("div",{className:"text-xl font-bold text-ink",children:n.time_elapsed||"N/A"})]})]}):e.jsx("div",{className:"text-sm text-muted py-4 text-center",children:r?"Loading metrics...":"No metrics available"})]}):null}function He(t){switch(t){case"completed":case"complete":case"done":return"completed";case"in_progress":return"running";case"started":return"started";case"error":case"failed":return"failed";default:return"empty"}}const Ge={completed:"Completed",complete:"Completed",done:"Completed",in_progress:"In Progress",started:"Started",error:"Failed",failed:"Failed",empty:"Empty"};function We({onLoadSession:t}){const s=l.useCallback(()=>h.getSessionsHistory(),[]),{data:n,loading:r}=I(s,6e4,!0);return r&&!n?e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider mb-3",children:"Past Builds"}),e.jsx("div",{className:"text-sm text-muted",children:"Loading..."})]}):!n||n.length===0?null:e.jsxs("div",{className:"card p-4 rounded-card",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink uppercase tracking-wider mb-3",children:"Past Builds"}),e.jsx("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto terminal-scroll",children:n.map(a=>{const c=a.file_count;return e.jsxs("button",{onClick:()=>t==null?void 0:t(a),className:"text-left px-4 py-3 rounded-card card hover:bg-hover transition-all group cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-mono text-muted-accessible",children:a.date}),e.jsxs("div",{className:"flex items-center gap-2",children:[c!==void 0&&c>0&&e.jsxs("span",{className:"text-xs font-mono text-muted-accessible",children:[c," files"]}),e.jsx(je,{status:He(a.status),children:Ge[a.status]||a.status})]})]}),e.jsx("div",{className:"text-xs text-ink truncate group-hover:text-primary transition-colors",children:a.prd_snippet||a.id}),e.jsx("div",{className:"text-xs font-mono text-muted-accessible mt-0.5 truncate",children:a.path})]},a.id)})})]})}function Ze(){const t=be(),[s,n]=l.useState(null),[r,a]=l.useState(()=>sessionStorage.getItem("pl_running")==="1"),[c,i]=l.useState(!1),[o,m]=l.useState(()=>sessionStorage.getItem("pl_prd")),[b,f]=l.useState(!1),[y,d]=l.useState(!1),[g,j]=l.useState(!1),[v,w]=l.useState(()=>sessionStorage.getItem("pl_tab")||"terminal"),[k,T]=l.useState(()=>sessionStorage.getItem("pl_provider")||"claude"),[x,E]=l.useState(void 0);l.useEffect(()=>{const u=sessionStorage.getItem("pl_template");u&&(sessionStorage.removeItem("pl_template"),h.getTemplateContent(u).then(({content:U})=>{U&&E(U)}).catch(()=>{}))},[]);const[N,M]=l.useState(null),[P,A]=l.useState(null),[z,_]=l.useState(null),F=l.useCallback(u=>{if(!u){M(null),A(null),_(null);return}M(u.status),A(u.agents),_(u.logs),a(u.status.running??!1),i(u.status.paused??!1)},[]),{connected:$,subscribe:O}=ge(F),B=l.useCallback(()=>h.getStatus(),[]),{data:R}=I(B,3e4,!$);l.useEffect(()=>{N===null&&R!==null&&(a(R.running??!1),i(R.paused??!1))},[R,N]),l.useEffect(()=>{sessionStorage.setItem("pl_running",r?"1":"0"),r&&f(!0)},[r]),l.useEffect(()=>{o?sessionStorage.setItem("pl_prd",o):sessionStorage.removeItem("pl_prd")},[o]),l.useEffect(()=>{sessionStorage.setItem("pl_provider",k)},[k]),l.useEffect(()=>{sessionStorage.setItem("pl_tab",v)},[v]);const q=l.useCallback(()=>h.getMemorySummary(),[]),H=l.useCallback(()=>h.getChecklist(),[]),p=l.useCallback(()=>h.getFiles(),[]),{data:L,loading:G}=I(q,3e4,r),{data:ee,loading:te}=I(H,3e4,r),{data:se,loading:ae}=I(p,3e4,r),S=N??R,re=P,ne=z,le=P===null,ie=z===null,ce=l.useCallback(async(u,U,he,fe)=>{n(null),f(!1),d(!1),w("terminal");try{await h.startSession({prd:u,provider:U,projectDir:he,mode:fe}),m(u),a(!0)}catch(Q){n(Q instanceof Error?Q.message:"Failed to start session")}},[]),oe=l.useCallback(async()=>{try{(await h.stopSession()).stopped&&(a(!1),i(!1),m(null),M(null),A(null),_(null))}catch{a(!1),i(!1),m(null)}sessionStorage.removeItem("pl_running"),sessionStorage.removeItem("pl_prd"),sessionStorage.removeItem("pl_tab")},[]),de=l.useCallback(u=>{t(`/project/${u.id}`)},[t]),xe=l.useCallback(u=>{T(u)},[]),me=l.useCallback(async()=>{try{await h.pauseSession(),i(!0)}catch{}},[]),ue=l.useCallback(async()=>{try{await h.resumeSession(),i(!1)}catch{}},[]),pe=o&&o.replace(/^#+\s*/gm,"").split(`
18
+ `).find(u=>u.trim().length>0)||null;return e.jsxs("div",{className:"min-h-screen bg-[#FAF9F6] relative",children:[e.jsx("div",{className:"pattern-nodes"}),e.jsx("div",{className:"max-w-[1920px] mx-auto px-6 py-6 relative z-10",children:r?e.jsxs(e.Fragment,{children:[e.jsx(C,{name:"ControlBar",children:e.jsx(Ce,{status:S,prdSummary:pe,onStop:oe,onPause:me,onResume:ue,isPaused:c})}),e.jsx("div",{className:"mt-4",children:e.jsx(C,{name:"StatusOverview",children:e.jsx(Ee,{status:S})})}),e.jsxs("div",{className:"mt-4 grid grid-cols-12 gap-6",style:{height:"calc(100vh - 340px)",minHeight:"400px"},children:[e.jsx("div",{className:"col-span-3 flex flex-col gap-6",children:e.jsx(C,{name:"PhaseVisualizer",children:e.jsx(Re,{currentPhase:(S==null?void 0:S.phase)||"idle",iteration:(S==null?void 0:S.iteration)||0})})}),e.jsxs("div",{className:"col-span-5 flex flex-col gap-0 min-h-0",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>w("terminal"),className:`px-3 py-1.5 text-xs font-semibold rounded-lg transition-all ${v==="terminal"?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:"Terminal"}),e.jsx("button",{onClick:()=>w("metrics"),className:`px-3 py-1.5 text-xs font-semibold rounded-lg transition-all ${v==="metrics"?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:"Metrics"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(C,{name:"Terminal",children:v==="terminal"?e.jsx(we,{logs:ne,loading:ie,subscribe:O}):e.jsx(J,{visible:!0})})})]}),e.jsxs("div",{className:"col-span-4 flex flex-col gap-6 overflow-y-auto",children:[e.jsx(C,{name:"AgentDashboard",children:e.jsx(Te,{agents:re,loading:le})}),e.jsx(C,{name:"QualityGates",children:e.jsx(Ie,{checklist:ee,loading:te})})]})]}),e.jsxs("div",{className:"mt-6 grid grid-cols-12 gap-6",children:[e.jsx("div",{className:"col-span-6",children:e.jsx(C,{name:"FileBrowser",children:e.jsx(ze,{files:se,loading:ae})})}),e.jsx("div",{className:"col-span-6",children:e.jsx(C,{name:"MemoryViewer",children:e.jsx(Oe,{memory:L,loading:G})})})]})]}):e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"text-center mt-8 mb-8",children:[e.jsx("h2",{className:"font-heading text-h1 text-[#36342E]",children:"Describe it. Build it. Ship it."}),e.jsx("p",{className:"text-[#6B6960] mt-2 text-base max-w-lg mx-auto",children:"Paste a PRD or pick a template. Purple Lab spins up autonomous agents to build your project from scratch."})]}),e.jsx("div",{className:"w-full max-w-3xl",children:e.jsx(_e,{onSubmit:ce,running:r,error:s,provider:k,onProviderChange:xe,initialPrd:x})}),b&&!r&&e.jsxs("div",{className:"w-full max-w-3xl mt-4 flex flex-col gap-4",children:[e.jsx("button",{onClick:async()=>{try{const u=await h.getSessionsHistory();u.length>0&&t(`/project/${u[0].id}`)}catch{}},className:"w-full px-6 py-4 rounded-card text-base font-bold bg-[#553DE9] text-white hover:bg-[#553DE9]/90 transition-all shadow-lg shadow-[#553DE9]/20",children:"View Project -- Browse Files and Preview"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>d(!y),className:"px-4 py-2 rounded-card text-sm font-semibold border border-[#553DE9]/30 text-[#553DE9] hover:bg-[#553DE9]/5 transition-all",children:y?"Hide Report":"Report"}),e.jsx("button",{onClick:()=>j(!g),className:"px-4 py-2 rounded-card text-sm font-semibold border border-[#ECEAE3] text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0] transition-all",children:g?"Hide Metrics":"Metrics"})]}),e.jsx(qe,{visible:y}),e.jsx(J,{visible:g})]}),e.jsx("div",{className:"w-full max-w-3xl mt-4",children:e.jsx(We,{onLoadSession:de})}),e.jsxs("div",{className:"mt-6 text-xs text-[#6B6960] flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${$?"bg-[#1FC5A8]":"bg-[#C45B5B]"}`}),$?"Connected to Purple Lab backend":"Waiting for backend connection..."]})]})})]})}export{Ze as default};
@@ -1 +1 @@
1
- import{g as r,u as o,r as c,j as e}from"./index-B8Eg1YHL.js";function x(){const{user:l,loading:t,login:i,isLocalMode:n}=r(),s=o();return c.useEffect(()=>{!t&&(l||n)&&s("/",{replace:!0})},[l,t,n,s]),t?e.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center text-[#6B6960] text-sm",children:"Loading..."}):e.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-sm mx-auto px-6",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"font-heading text-3xl font-bold text-[#36342E] mb-1",children:"Purple Lab"}),e.jsx("p",{className:"text-sm text-[#6B6960]",children:"Autonomous agent workspace powered by Loki"})]}),e.jsxs("div",{className:"bg-white rounded-lg border border-[#ECEAE3] shadow-sm p-6 space-y-4",children:[e.jsx("h2",{className:"text-base font-medium text-[#36342E] text-center",children:"Sign in to continue"}),e.jsxs("button",{type:"button",onClick:()=>i("github"),className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-[5px] border border-[#ECEAE3] bg-[#24292f] text-white text-sm font-medium hover:bg-[#1b1f23] transition-colors",children:[e.jsx("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})}),"Sign in with GitHub"]}),e.jsxs("button",{type:"button",onClick:()=>i("google"),className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-[5px] border border-[#ECEAE3] bg-white text-[#36342E] text-sm font-medium hover:bg-[#F8F4F0] transition-colors",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Sign in with Google"]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-[#ECEAE3]"})}),e.jsx("div",{className:"relative flex justify-center text-xs",children:e.jsx("span",{className:"bg-white px-2 text-[#939084]",children:"or"})})]}),e.jsx("button",{type:"button",onClick:()=>s("/"),className:"w-full text-center text-sm text-[#6B6960] hover:text-[#553DE9] transition-colors py-1",children:"Continue without account (local mode)"})]}),e.jsx("p",{className:"text-xs text-[#939084] text-center mt-4",children:"Local mode stores everything on your machine. Sign in for cloud sync and collaboration."})]})})}export{x as default};
1
+ import{g as r,u as o,r as c,j as e}from"./index-1UyN_URb.js";function x(){const{user:l,loading:t,login:i,isLocalMode:n}=r(),s=o();return c.useEffect(()=>{!t&&(l||n)&&s("/",{replace:!0})},[l,t,n,s]),t?e.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center text-[#6B6960] text-sm",children:"Loading..."}):e.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-sm mx-auto px-6",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"font-heading text-3xl font-bold text-[#36342E] mb-1",children:"Purple Lab"}),e.jsx("p",{className:"text-sm text-[#6B6960]",children:"Autonomous agent workspace powered by Loki"})]}),e.jsxs("div",{className:"bg-white rounded-lg border border-[#ECEAE3] shadow-sm p-6 space-y-4",children:[e.jsx("h2",{className:"text-base font-medium text-[#36342E] text-center",children:"Sign in to continue"}),e.jsxs("button",{type:"button",onClick:()=>i("github"),className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-[5px] border border-[#ECEAE3] bg-[#24292f] text-white text-sm font-medium hover:bg-[#1b1f23] transition-colors",children:[e.jsx("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"})}),"Sign in with GitHub"]}),e.jsxs("button",{type:"button",onClick:()=>i("google"),className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 rounded-[5px] border border-[#ECEAE3] bg-white text-[#36342E] text-sm font-medium hover:bg-[#F8F4F0] transition-colors",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Sign in with Google"]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-[#ECEAE3]"})}),e.jsx("div",{className:"relative flex justify-center text-xs",children:e.jsx("span",{className:"bg-white px-2 text-[#939084]",children:"or"})})]}),e.jsx("button",{type:"button",onClick:()=>s("/"),className:"w-full text-center text-sm text-[#6B6960] hover:text-[#553DE9] transition-colors py-1",children:"Continue without account (local mode)"})]}),e.jsx("p",{className:"text-xs text-[#939084] text-center mt-4",children:"Local mode stores everything on your machine. Sign in for cloud sync and collaboration."})]})})}export{x as default};
@@ -1 +1 @@
1
- import{j as e,L as t,H as s}from"./index-B8Eg1YHL.js";import{A as o}from"./arrow-left-DAZzI0L-.js";function i(){return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[60vh] p-8 text-center",children:[e.jsx("div",{className:"text-6xl font-heading font-bold text-primary/20 mb-4",children:"404"}),e.jsx("h1",{className:"text-h3 font-heading font-bold text-ink mb-2",children:"Page not found"}),e.jsx("p",{className:"text-sm text-muted-accessible mb-6 max-w-xs",children:"The page you are looking for does not exist or has been moved."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>window.history.back(),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs font-medium rounded-btn border border-border text-secondary hover:bg-hover transition-colors",children:[e.jsx(o,{size:14}),"Go Back"]}),e.jsxs(t,{to:"/",className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs font-medium rounded-btn bg-primary text-white hover:bg-[#4432c4] transition-colors shadow-button",children:[e.jsx(s,{size:14}),"Home"]})]})]})}export{i as default};
1
+ import{j as e,L as t,H as s}from"./index-1UyN_URb.js";import{A as o}from"./arrow-left-BaOs4kgD.js";function i(){return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[60vh] p-8 text-center",children:[e.jsx("div",{className:"text-6xl font-heading font-bold text-primary/20 mb-4",children:"404"}),e.jsx("h1",{className:"text-h3 font-heading font-bold text-ink mb-2",children:"Page not found"}),e.jsx("p",{className:"text-sm text-muted-accessible mb-6 max-w-xs",children:"The page you are looking for does not exist or has been moved."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>window.history.back(),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs font-medium rounded-btn border border-border text-secondary hover:bg-hover transition-colors",children:[e.jsx(o,{size:14}),"Go Back"]}),e.jsxs(t,{to:"/",className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs font-medium rounded-btn bg-primary text-white hover:bg-[#4432c4] transition-colors shadow-button",children:[e.jsx(s,{size:14}),"Home"]})]})]})}export{i as default};
@@ -1,4 +1,4 @@
1
- var an=e=>{throw TypeError(e)};var ln=(e,t,i)=>t.has(e)||an("Cannot "+i);var ti=(e,t,i)=>(ln(e,t,"read from private field"),i?i.call(e):t.get(e)),hn=(e,t,i)=>t.has(e)?an("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),cn=(e,t,i,s)=>(ln(e,t,"write to private field"),s?s.call(e,i):t.set(e,i),i);import{c as de,r as g,W as qt,j as c,a as te,M as Ao,T as zo,X as yi,b as wl,E as hi,B as dn,S as xl,F as Oo,d as Cl,A as kl,e as ws,f as El,u as Ml}from"./index-B8Eg1YHL.js";import{S as is,T as Dl,P as xs,a as Rl,E as Vi,R as Pl,C as Bl,b as Ll,c as Nl}from"./TerminalOutput-CmdEXHHd.js";import{B as Ft,P as Tl}from"./Button-WBFGRnUr.js";import{C as Al,a as zl}from"./clock-BHGf6zSk.js";import{A as Ol}from"./arrow-left-DAZzI0L-.js";import{E as Il}from"./external-link-DLYjfP9j.js";/**
1
+ var an=e=>{throw TypeError(e)};var ln=(e,t,i)=>t.has(e)||an("Cannot "+i);var ti=(e,t,i)=>(ln(e,t,"read from private field"),i?i.call(e):t.get(e)),hn=(e,t,i)=>t.has(e)?an("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),cn=(e,t,i,s)=>(ln(e,t,"write to private field"),s?s.call(e,i):t.set(e,i),i);import{c as de,r as g,W as qt,j as c,a as te,M as Ao,T as zo,X as yi,b as wl,E as hi,B as dn,S as xl,F as Oo,d as Cl,A as kl,e as ws,f as El,u as Ml}from"./index-1UyN_URb.js";import{S as is,T as Dl,P as xs,a as Rl,E as Vi,R as Pl,C as Bl,b as Ll,c as Nl}from"./TerminalOutput-B5rIKYNW.js";import{B as Ft,P as Tl}from"./Button-DV8ro4oS.js";import{C as Al,a as zl}from"./clock-Csnz1n2_.js";import{A as Ol}from"./arrow-left-BaOs4kgD.js";import{E as Il}from"./external-link-i7ZDkWbe.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -181,5 +181,5 @@ WARNING: This link could potentially be dangerous`)){let i=window.open();if(i){t
181
181
 
182
182
  `);M=x.pop()||"";for(const D of x){if(!D.trim())continue;const j=D.split(`
183
183
  `);let L="",V="";for(const X of j)X.startsWith("event:")?L=X.slice(6).trim():X.startsWith("data:")&&(V=X.slice(5).trim());if(L==="output"&&V)try{const{line:X}=JSON.parse(V);r(H=>Ct(H,F=>F.role==="system"&&F.isStreaming?{content:F.content?F.content+`
184
- `+X:X}:{}))}catch{}else if(L==="complete"&&V)try{const{returncode:X,files_changed:H}=JSON.parse(V);r(F=>Ct(F,$=>$.role==="system"&&$.isStreaming?{isStreaming:!1,filesChanged:H,returncode:X,content:$.content||"Done."}:{})),(H==null?void 0:H.length)>0&&i&&i(H)}catch{}else if(L==="error"&&V)try{const{error:X}=JSON.parse(V);r(H=>Ct(H,F=>F.role==="system"&&F.isStreaming?{isStreaming:!1,content:`Error: ${X}`}:{}))}catch{}}}}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;await w(b)}finally{f(!1),d(!1),p.current=null,S.current=null,(T=_.current)==null||T.focus()}},[e,i,w]),k=async()=>{var O;const b=n.trim();if(!b||l)return;const B={role:"user",content:b,timestamp:new Date().toISOString()},T={role:"system",content:"",timestamp:new Date().toISOString(),isStreaming:!0};r(K=>[...K,B,T]),o(""),d(!0);try{const{task_id:K}=await te.chatStart(e,b,a);await R(K)}catch(K){r(W=>Ct(W,A=>A.role==="system"&&A.isStreaming?{isStreaming:!1,content:`Error: ${K instanceof Error?K.message:"Request failed"}`}:{})),d(!1),(O=_.current)==null||O.focus()}};return c.jsxs("div",{className:"flex flex-col h-full",children:[c.jsxs("div",{ref:m,className:"flex-1 overflow-y-auto p-3 space-y-3 terminal-scroll",children:[s.length===0&&c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(Ao,{size:28,className:"text-muted/30 mb-3"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No messages yet"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-1 max-w-[200px]",children:"Ask the AI to build, modify, or explain your code."})]}),s.map((b,B)=>c.jsx("div",{className:`flex ${b.role==="user"?"justify-end":"justify-start"}`,children:c.jsxs("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-xs ${b.role==="user"?"bg-primary/10 text-ink":"bg-hover text-ink border-l-2 border-primary/40"}`,children:[c.jsxs("pre",{className:"whitespace-pre-wrap font-mono text-xs leading-relaxed overflow-x-auto",children:[b.content,b.isStreaming&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-primary/60 animate-pulse ml-0.5 align-text-bottom"})]}),b.filesChanged&&b.filesChanged.length>0&&c.jsxs("div",{className:"mt-2 pt-2 border-t border-border",children:[c.jsx("span",{className:"text-xs text-muted font-semibold uppercase",children:"Files changed:"}),c.jsx("ul",{className:"mt-1 space-y-0.5",children:b.filesChanged.map((T,O)=>c.jsx("li",{className:"text-xs font-mono text-muted",children:T},O))})]}),b.role==="system"&&!b.isStreaming&&b.returncode!==void 0&&c.jsx("div",{className:"mt-1 text-[10px] text-muted",children:b.returncode===0?"Done":`Exit code: ${b.returncode}`})]})},B))]}),c.jsxs("div",{className:"border-t border-border p-2 flex-shrink-0",children:[u&&c.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[c.jsx("span",{className:"text-[10px] text-muted font-mono",children:"Streaming..."}),c.jsxs("button",{onClick:v,className:"flex items-center gap-1 text-[10px] text-red-400 hover:text-red-300 transition-colors",children:[c.jsx(is,{className:"w-2.5 h-2.5"}),"Stop"]})]}),c.jsx("div",{className:"flex items-center gap-1 mb-2",children:["quick","standard","max"].map(b=>c.jsx("button",{onClick:()=>h(b),className:`text-xs font-semibold px-3 py-1.5 rounded-btn transition-colors capitalize ${a===b?"bg-primary text-white":"text-muted hover:text-ink"}`,children:b},b))}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{ref:_,type:"text",value:n,onChange:b=>o(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),k())},placeholder:"Ask AI to modify your project...",className:"flex-1 px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors",disabled:l}),u?c.jsx(Ft,{size:"sm",icon:is,onClick:v,"aria-label":"Stop streaming",className:"bg-red-500/10 hover:bg-red-500/20 text-red-400",children:"Stop"}):c.jsx(Ft,{size:"sm",icon:vh,onClick:k,disabled:l||!n.trim(),"aria-label":"Send message",children:"Send"})]})]})]})}const Po=[{id:"terminal",label:"Terminal",icon:zo},{id:"build",label:"Build Log",icon:mh},{id:"agents",label:"Agents",icon:Hl},{id:"quality",label:"Quality",icon:Io},{id:"chat",label:"AI Chat",icon:Ao}];function $_({status:e}){switch(e){case"pass":return c.jsx(zl,{size:14,className:"text-success"});case"fail":return c.jsx(yi,{size:14,className:"text-danger"});default:return c.jsx(Al,{size:14,className:"text-muted"})}}function F_({agents:e}){return!e||e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(kh,{size:24,className:"text-muted/30 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No agents active"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Agents will appear here during builds."})]}):c.jsx("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:e.map(t=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-hover text-xs",children:[c.jsx("span",{className:"font-semibold text-ink truncate",children:t.name}),c.jsx("span",{className:"text-xs font-mono text-muted-accessible px-1.5 py-0.5 rounded-btn bg-card",children:t.type}),c.jsx("span",{className:`text-xs font-semibold ${t.status==="running"?"text-success":"text-muted"}`,children:t.status}),c.jsx("span",{className:"ml-auto text-xs text-muted-accessible font-mono truncate max-w-[200px]",children:t.task})]},t.id))})}function W_({checklist:e}){return!e||!e.items||e.items.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(Io,{size:24,className:"text-muted/30 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No quality gate data"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Quality gates will appear during builds."})]}):c.jsxs("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:[c.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-xs text-muted-accessible font-semibold uppercase",children:[c.jsx("span",{children:"Gate"}),c.jsxs("span",{className:"ml-auto",children:[e.passed,"/",e.total," passed"]})]}),e.items.map(t=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-btn hover:bg-hover text-xs",children:[c.jsx($_,{status:t.status}),c.jsx("span",{className:"text-ink",children:t.label}),t.details&&c.jsx("span",{className:"ml-auto text-xs text-muted-accessible truncate max-w-[200px]",children:t.details})]},t.id))]})}function K_({logs:e,logsLoading:t,agents:i,checklist:s,sessionId:r,subscribe:n,buildMode:o}){var l;const[a,h]=g.useState("terminal");return c.jsxs("div",{className:"h-full flex flex-col bg-card",children:[c.jsx("div",{role:"tablist",className:"flex items-center border-b border-border px-2 flex-shrink-0",children:Po.map(d=>{const u=d.icon,f=a===d.id;return c.jsxs("button",{role:"tab","aria-selected":f,onClick:()=>h(d.id),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${f?"border-primary text-primary":"border-transparent text-muted hover:text-ink"}`,children:[c.jsx(u,{size:14}),d.label]},d.id)})}),c.jsxs("div",{role:"tabpanel","aria-label":(l=Po.find(d=>d.id===a))==null?void 0:l.label,className:"flex-1 min-h-0 overflow-hidden relative",children:[c.jsx("div",{className:"absolute inset-0",style:{visibility:a==="terminal"?"visible":"hidden",zIndex:a==="terminal"?1:0},children:c.jsx(j_,{sessionId:r,isActive:a==="terminal"})}),a==="build"&&c.jsx(Dl,{logs:e,loading:t,subscribe:n}),a==="agents"&&c.jsx(F_,{agents:i}),a==="quality"&&c.jsx(W_,{checklist:s}),a==="chat"&&c.jsx(H_,{sessionId:r,defaultMode:o})]})]})}const Za=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),li=Za?"Cmd":"Ctrl",U_=[{keys:[`${li}+S`],label:"Save file"},{keys:[`${li}+P`],label:"Quick open file"},{keys:[`${li}+\``],label:"Toggle terminal"},{keys:[`${li}+B`],label:"Start / stop build"},{keys:[`${li}+?`],label:"Show keyboard shortcuts"},{keys:["Escape"],label:"Close modals"}];function q_({onToggleTerminal:e,onToggleBuild:t}){const[i,s]=g.useState(!1),r=g.useCallback(n=>{const o=Za?n.metaKey:n.ctrlKey;if(o&&(n.key==="?"||n.shiftKey&&n.key==="/")){n.preventDefault(),s(a=>!a);return}if(o&&n.key==="`"){n.preventDefault(),e==null||e();return}if(o&&n.key==="b"){n.preventDefault(),t==null||t();return}n.key==="Escape"&&i&&s(!1)},[e,t,i]);return g.useEffect(()=>(window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)),[r]),{showHelp:i,setShowHelp:s}}function V_({open:e,onClose:t}){return e?c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/20",onClick:t,children:c.jsxs("div",{className:"bg-card rounded-card shadow-card-hover border border-border w-full max-w-md mx-4",onClick:i=>i.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ch,{size:16,className:"text-primary"}),c.jsx("h2",{className:"text-sm font-heading font-bold text-ink",children:"Keyboard Shortcuts"})]}),c.jsx("button",{onClick:t,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",children:c.jsx(yi,{size:16})})]}),c.jsx("div",{className:"p-4 space-y-1",children:U_.map(i=>c.jsxs("div",{className:"flex items-center justify-between px-2 py-2 rounded-btn hover:bg-hover",children:[c.jsx("span",{className:"text-xs text-ink",children:i.label}),c.jsx("div",{className:"flex items-center gap-1",children:i.keys.map(s=>c.jsx("kbd",{className:"px-2 py-0.5 text-[11px] font-mono bg-hover border border-border rounded text-muted-accessible",children:s},s))})]},i.label))}),c.jsx("div",{className:"px-5 py-3 border-t border-border text-center",children:c.jsxs("span",{className:"text-[11px] text-muted",children:["Press ",c.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 Y_({onClick:e}){return c.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:"?"})}function Pr(e,t,i){var n;if(t==="directory")return i?c.jsx(Fs,{size:14}):c.jsx(oh,{size:14});const s=((n=e.split(".").pop())==null?void 0:n.toLowerCase())||"";return{js:c.jsx(Ge,{size:14,className:"text-yellow-600"}),ts:c.jsx(Ge,{size:14,className:"text-blue-500"}),tsx:c.jsx(Ge,{size:14,className:"text-blue-400"}),jsx:c.jsx(Ge,{size:14,className:"text-yellow-500"}),py:c.jsx(Ge,{size:14,className:"text-green-600"}),html:c.jsx(Xl,{size:14,className:"text-orange-500"}),css:c.jsx(Ql,{size:14,className:"text-purple-500"}),json:c.jsx(ql,{size:14,className:"text-green-500"}),md:c.jsx(Oo,{size:14,className:"text-muted"}),go:c.jsx(Ge,{size:14,className:"text-cyan-600"}),rs:c.jsx(Ge,{size:14,className:"text-orange-600"}),rb:c.jsx(Ge,{size:14,className:"text-red-500"}),sh:c.jsx(Ge,{size:14,className:"text-green-600"})}[s]||c.jsx(th,{size:14})}function X_(e){var r;const t=((r=e.split(".").pop())==null?void 0:r.toLowerCase())||"",i={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"},s=e.toLowerCase();return s==="dockerfile"?"dockerfile":s==="makefile"?"makefile":i[t]||"plaintext"}function Qa(e,t){for(const i of e){if(i.path===t)return i.size;if(i.children){const s=Qa(i.children,t);if(s!==void 0)return s}}}function el(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function tl({nodes:e,selectedPath:t,onSelect:i,onDelete:s,onContextMenu:r,depth:n=0}){const[o,a]=g.useState(()=>{const h=new Set;return n<2&&e.filter(l=>l.type==="directory").forEach(l=>h.add(l.path)),h});return c.jsx("div",{role:n===0?"tree":"group",children:e.map(h=>{const l=h.type==="directory",d=o.has(h.path),u=h.path===t;return c.jsxs("div",{className:"group/file",children:[c.jsxs("button",{role:"treeitem","aria-label":h.name,"aria-selected":u,...l?{"aria-expanded":d}:{},onContextMenu:f=>{f.preventDefault(),r==null||r(f,h.path,h.name,h.type)},onClick:()=>{l?a(f=>{const m=new Set(f);return m.has(h.path)?m.delete(h.path):m.add(h.path),m}):i(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 ${u?"bg-primary/10 text-primary":"text-ink/70 hover:bg-hover"}`,style:{paddingLeft:`${n*14+8}px`},children:[l?c.jsx("span",{className:"w-3 flex items-center justify-center flex-shrink-0 text-muted",children:d?c.jsx(Bl,{size:14}):c.jsx(Ll,{size:14})}):c.jsx("span",{className:"w-3 flex-shrink-0"}),c.jsx("span",{className:`w-5 flex items-center justify-center flex-shrink-0 ${l?"text-primary":""}`,children:Pr(h.name,h.type,d)}),c.jsxs("span",{className:"truncate",children:[h.name,l?"/":""]}),!l&&h.size!=null&&h.size>0&&c.jsx("span",{className:"text-xs text-muted ml-auto flex-shrink-0",children:el(h.size)}),!l&&s&&c.jsx("span",{role:"button",tabIndex:-1,onClick:f=>{f.stopPropagation(),s(h.path,h.name)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),s(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:c.jsx(yi,{size:12})})]}),l&&d&&h.children&&c.jsx(tl,{nodes:h.children,selectedPath:t,onSelect:i,onDelete:s,onContextMenu:r,depth:n+1})]},h.path)})})}function il(e,t=""){const i=[];for(const s of e)s.type==="file"&&i.push({path:s.path,name:s.name}),s.children&&i.push(...il(s.children,s.path+"/"));return i}function G_(){const[e,t]=g.useState({}),[i,s]=g.useState(""),[r,n]=g.useState(""),[o,a]=g.useState(!0),[h,l]=g.useState(null),[d,u]=g.useState(new Set),f=g.useCallback(async()=>{try{const v=await te.getSecrets();t(v)}catch{}a(!1)},[]);g.useEffect(()=>{f()},[f]);const m=async()=>{const v=i.trim();if(v){if(!/^[A-Z_][A-Z0-9_]*$/.test(v)){l("Key must be a valid ENV_VAR name (uppercase letters, digits, underscores)");return}l(null);try{await te.setSecret(v,r),s(""),n(""),await f()}catch(w){l(w instanceof Error?w.message:"Failed to set secret")}}},_=async v=>{if(window.confirm(`Delete secret "${v}"?`))try{await te.deleteSecret(v),await f()}catch(w){l(w instanceof Error?w.message:"Failed to delete secret")}},p=v=>{u(w=>{const R=new Set(w);return R.has(v)?R.delete(v):R.add(v),R})},S=Object.keys(e);return o?c.jsxs("div",{className:"p-6 space-y-4",children:[c.jsx(ws,{variant:"text",width:"180px",height:"16px"}),c.jsx(ws,{variant:"block",width:"100%",height:"60px"}),c.jsx(ws,{variant:"block",width:"100%",height:"80px"})]}):c.jsx("div",{className:"h-full flex flex-col",children:c.jsxs("div",{className:"p-6 overflow-y-auto",children:[c.jsx("h3",{className:"text-h3 font-heading text-ink mb-2",children:"Environment Secrets"}),c.jsxs("div",{className:"flex items-start gap-2 px-4 py-3 rounded-btn border border-warning/30 bg-warning/5 mb-6",children:[c.jsx(Nl,{size:16,className:"text-warning flex-shrink-0 mt-0.5"}),c.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."})]}),S.length>0&&c.jsx("div",{className:"card mb-6",children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"border-b border-border",children:[c.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Key"}),c.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Value"}),c.jsx("th",{className:"w-20 px-4 py-2"})]})}),c.jsx("tbody",{children:S.map(v=>c.jsxs("tr",{className:"border-b border-border last:border-b-0",children:[c.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-ink",children:v}),c.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-muted-accessible",children:c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx("span",{children:d.has(v)?e[v]:"***"}),c.jsx("button",{onClick:()=>p(v),className:"text-muted hover:text-ink transition-colors",title:d.has(v)?"Hide value":"Show value",children:d.has(v)?c.jsx(Kl,{size:14}):c.jsx(hi,{size:14})})]})}),c.jsx("td",{className:"px-4 py-2.5 text-right",children:c.jsx("button",{onClick:()=>_(v),className:"text-muted hover:text-danger transition-colors",title:"Delete secret",children:c.jsx(jo,{size:14})})})]},v))})]})}),S.length===0&&c.jsx("div",{className:"card p-4 mb-6",children:c.jsx("p",{className:"text-sm text-muted-accessible text-center py-4",children:"No secrets configured yet. Add your first secret below."})}),c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-3",children:"Add Secret"}),h&&c.jsx("div",{className:"text-xs text-danger mb-3 px-1",children:h}),c.jsxs("div",{className:"flex items-end gap-3",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Key"}),c.jsx("input",{type:"text",value:i,onChange:v=>s(v.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"})]}),c.jsxs("div",{className:"flex-1",children:[c.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Value"}),c.jsx("input",{type:"password",value:r,onChange:v=>n(v.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"})]}),c.jsxs("button",{onClick:m,disabled:!i.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:[c.jsx(Tl,{size:14}),"Add"]})]})]})]})})}function J_({session:e,onClose:t}){var on;const[i,s]=g.useState(null),[r,n]=g.useState(""),[o,a]=g.useState(null),[h,l]=g.useState(null),[d,u]=g.useState(!1),[f,m]=g.useState("code"),[_,p]=g.useState(!1),[S,v]=g.useState(!1),[w,R]=g.useState(e),k=g.useRef(null),[b,B]=g.useState([]),[T,O]=g.useState(!1),[K,W]=g.useState(""),A=g.useRef(null),M=g.useRef(null),[C,P]=g.useState(0),[x,D]=g.useState(null),[j,L]=g.useState("standard"),[V,X]=g.useState("claude"),[H,F]=g.useState(null),[$,ie]=g.useState(null),[le,ne]=g.useState(!1),[Te,qe]=g.useState(!1),[je,bt]=g.useState(!1),[Ke,Ae]=g.useState(null),Z=g.useRef(null),{subscribe:Ot}=wl(),ht=g.useCallback(async()=>{try{const y=await te.getSessionDetail(w.id);R(y)}catch{}},[w.id]),Xr=g.useCallback(async()=>{try{await te.stopSession(),ne(!1),qe(!1)}catch{}},[]),sl=g.useCallback(async()=>{try{await te.pauseSession(),qe(!0)}catch{}},[]),rl=g.useCallback(async()=>{try{await te.resumeSession(),qe(!1)}catch{}},[]);g.useEffect(()=>{const y=async()=>{try{const Y=await te.getStatus();ne(Y.running),qe(Y.paused),Y.provider&&X(Y.provider)}catch{}};y();const I=setInterval(y,1e4);return()=>clearInterval(I)},[]),g.useEffect(()=>{if(!($!=null&&$.loading))return;const y=setInterval(()=>{ie(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(y)},[$==null?void 0:$.loading]);const[Q,nl]=g.useState(null);g.useEffect(()=>{te.getPreviewInfo(w.id).then(nl).catch(()=>{})},[w.id]);const[U,ps]=g.useState(null),[ms,Gr]=g.useState(!1),[Jr,gs]=g.useState(null),[yt,ol]=g.useState("");g.useEffect(()=>{const y=Ot("file_changed",I=>{const Y=I;!Y.paths||Y.paths.length===0||(bt(!0),Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>bt(!1),2e3),ht(),i&&Y.paths.some(Ve=>Ve===i||i.endsWith(Ve))&&Ae(i),f==="preview"&&!(U!=null&&U.running)&&P(ee=>ee+1))});return()=>{y(),Z.current&&clearTimeout(Z.current)}},[Ot,i,f,U==null?void 0:U.running,ht]);const al=g.useCallback(async()=>{if(!(!Ke||!w.id)){try{const y=await te.getSessionFileContent(w.id,Ke);a(y.content),l(y.content),p(!1),B(I=>I.map(Y=>Y.path===Ke?{...Y,content:y.content,modified:!1}:Y))}catch{}Ae(null)}},[Ke,w.id]);g.useEffect(()=>{if(f!=="preview")return;let y=!1;const I=async()=>{try{const ee=await te.devserver.status(w.id);y||ps(ee)}catch{}};I();const Y=setInterval(I,3e3);return()=>{y=!0,clearInterval(Y)}},[f,w.id]);const Li=g.useCallback(async y=>{Gr(!0),gs(null);try{const I=await te.devserver.start(w.id,y);if(I.status==="error")gs(I.message||"Failed to start dev server");else{const Y=await te.devserver.status(w.id);ps(Y)}}catch(I){gs(I instanceof Error?I.message:"Failed to start dev server")}Gr(!1)},[w.id]),ll=g.useCallback(async()=>{try{await te.devserver.stop(w.id);const y=await te.devserver.status(w.id);ps(y)}catch{}},[w.id]),vs=U!=null&&U.running&&(U!=null&&U.url)?`/proxy/${encodeURIComponent(w.id)}/`:null,hl=(Q==null?void 0:Q.preview_url)||`/api/sessions/${encodeURIComponent(w.id)}/preview/index.html`,cl=vs||hl,[Ni,Zr]=g.useState([]),[st,Ti]=g.useState(0);g.useEffect(()=>{const y=vs||(Q==null?void 0:Q.preview_url);y&&(Zr([y]),Ti(0))},[vs,Q==null?void 0:Q.preview_url]);const It=Ni[st]||cl,[Qr,en]=g.useState(It),dl=g.useCallback((y,I,Y,ee)=>{y.preventDefault(),D({x:y.clientX,y:y.clientY,path:I,name:Y,type:ee})},[]),ul=g.useCallback(()=>{st>0&&(Ti(y=>y-1),P(y=>y+1))},[st]),fl=g.useCallback(()=>{st<Ni.length-1&&(Ti(y=>y+1),P(y=>y+1))},[st,Ni.length]),_l=g.useCallback(y=>{Zr(I=>[...I.slice(0,st+1),y]),Ti(I=>I+1),P(I=>I+1)},[st]);g.useEffect(()=>{en(It)},[It]);const Ai=g.useCallback(async()=>{ie({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.reviewProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),zi=g.useCallback(async()=>{ie({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.testProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),Ss=g.useCallback(async()=>{ie({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.explainProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),bs=g.useCallback(async(y,I)=>{if(window.confirm(`Delete "${I}"?`))try{await te.deleteSessionFile(w.id,y),i===y&&(s(null),n(""),a(null),l(null),p(!1)),await ht()}catch(ee){const Ve=ee instanceof Error?ee.message:"Unknown error";window.alert(`Delete failed: ${Ve}`)}},[w.id,i,ht]),pl=g.useCallback(y=>y.type==="file"?[{label:"Review",icon:hi,onClick:()=>{Ai()}},{label:"Generate Tests",icon:Cs,onClick:()=>{zi()}},{label:"Explain",icon:dn,onClick:()=>{Ss()}},{label:"Delete",icon:jo,onClick:()=>{bs(y.path,y.name)},variant:"danger"}]:[{label:"Review Project",icon:hi,onClick:()=>{Ai()}},{label:"Run Tests",icon:Cs,onClick:()=>{zi()}}],[Ai,zi,Ss,bs]),Qt=g.useCallback(async(y,I)=>{Ae(null),_&&i&&h!==null&&B(ee=>ee.map(Ve=>Ve.path===i?{...Ve,content:h,modified:!0}:Ve));const Y=b.find(ee=>ee.path===y);if(Y){s(y),n(I),a(Y.content),l(Y.content),p(Y.modified);return}s(y),n(I),u(!0),p(!1);try{const ee=w.id?await te.getSessionFileContent(w.id,y):await te.getFileContent(y);a(ee.content),l(ee.content),B(Ve=>[...Ve,{path:y,name:I,content:ee.content,modified:!1}])}catch{a("[Error loading file]"),l("[Error loading file]")}finally{u(!1)}},[w.id,_,i,h,b]),ys=g.useCallback(async()=>{var y;if(!(!i||h===null||!w.id)){v(!0);try{await te.saveSessionFile(w.id,i,h),a(h),p(!1),B(Y=>Y.map(ee=>ee.path===i?{...ee,content:h,modified:!1}:ee));const I=((y=i.split(".").pop())==null?void 0:y.toLowerCase())||"";["html","css","js","jsx","ts","tsx"].includes(I)&&P(Y=>Y+1)}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Save failed: ${Y}`)}finally{v(!1)}}},[i,h,w.id]),tn=g.useCallback(y=>{const I=b.find(Y=>Y.path===y);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(B(Y=>Y.filter(ee=>ee.path!==y)),i===y)){const Y=b.filter(ee=>ee.path!==y);if(Y.length>0){const ee=Y[Y.length-1];s(ee.path),n(ee.name),a(ee.content),l(ee.content),p(ee.modified)}else s(null),n(""),a(null),l(null),p(!1)}},[b,i]);g.useEffect(()=>{const y=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),_&&i&&ys()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),O(Y=>!Y),W("")),I.key==="Escape"&&T&&O(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[_,i,ys,T]),g.useEffect(()=>{T&&A.current&&A.current.focus()},[T]);const sn=il(w.files),ei=K?sn.filter(y=>y.path.toLowerCase().includes(K.toLowerCase())):sn;g.useEffect(()=>{const y=w.files.find(I=>I.name==="index.html"&&I.type==="file");y&&Qt(y.path,y.name)},[]);const ml=g.useCallback(y=>{y!==void 0&&(l(y),p(y!==o))},[o]),gl=g.useCallback(y=>{k.current=y},[]),vl=g.useCallback(async()=>{const y=window.prompt("New file name (e.g. src/utils.ts):");if(!(!y||!y.trim()))try{await te.createSessionFile(w.id,y.trim()),await ht()}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${Y}`)}},[w.id,ht]),Sl=g.useCallback(async()=>{const y=window.prompt("New folder name (e.g. src/components):");if(!(!y||!y.trim()))try{await te.createSessionDirectory(w.id,y.trim()),await ht()}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${Y}`)}},[w.id,ht]),rn=i?Qa(w.files,i):void 0,bl=((on=r.split(".").pop())==null?void 0:on.toUpperCase())||"",{showHelp:yl,setShowHelp:nn}=q_({onToggleBuild:()=>{le&&Xr()}});return c.jsxs("div",{className:"flex flex-col h-full relative",children:[c.jsxs("div",{className:"bg-card px-3 py-2 flex items-center gap-3 flex-shrink-0 border-b border-border",children:[c.jsx("button",{onClick:()=>{_&&!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"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("h2",{className:"text-sm font-bold text-ink truncate",children:w.id}),c.jsx("p",{className:"text-xs font-mono text-muted-accessible truncate",children:w.path})]}),c.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${w.status==="completed"||w.status==="completion_promise_fulfilled"?"bg-success/10 text-success":"bg-muted/10 text-muted"}`,children:w.status}),!le&&c.jsx(Ft,{variant:"primary",size:"sm",icon:xs,onClick:async()=>{try{const y=w.prd||"";if(!y.trim()){window.alert("No PRD found for this project. Go to Home to start a new build.");return}await te.startSession({prd:y,provider:V,projectDir:w.path}),ne(!0)}catch(y){window.alert(`Failed to start: ${y instanceof Error?y.message:"Unknown error"}`)}},title:"Start build for this project",children:"Build"}),le&&c.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[Te?c.jsx(Ft,{variant:"ghost",size:"sm",icon:xs,onClick:rl,title:"Resume build",children:"Resume"}):c.jsx(Ft,{variant:"ghost",size:"sm",icon:Rl,onClick:sl,title:"Pause build",children:"Pause"}),c.jsx(Ft,{variant:"danger",size:"sm",icon:is,onClick:Xr,title:"Stop build",children:"Stop"})]}),c.jsx(ct,{icon:hi,label:"Review project",size:"sm",onClick:Ai,disabled:!!($!=null&&$.loading)}),c.jsx(ct,{icon:Cs,label:"Run tests",size:"sm",onClick:zi,disabled:!!($!=null&&$.loading)}),c.jsx(ct,{icon:dn,label:"Explain project",size:"sm",onClick:Ss,disabled:!!($!=null&&$.loading)}),c.jsx(Y_,{onClick:()=>nn(!0)})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsxs(Us,{orientation:"vertical",children:[c.jsx(ui,{defaultSize:70,minSize:40,children:c.jsxs(Us,{orientation:"horizontal",className:"h-full",children:[c.jsx(ui,{defaultSize:20,minSize:15,children:c.jsxs("div",{className:"h-full flex flex-col border-r border-border bg-card",children:[c.jsxs("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[c.jsxs("span",{className:"text-xs text-muted-accessible uppercase tracking-wider font-semibold flex-1",children:["Files",je&&c.jsx("span",{className:"ml-2 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),c.jsxs("button",{onClick:vl,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:[c.jsx(Jl,{size:12})," New"]}),c.jsxs("button",{onClick:Sl,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:[c.jsx(rh,{size:12})," New"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:w.files.length>0?c.jsx(tl,{nodes:w.files,selectedPath:i,onSelect:Qt,onDelete:bs,onContextMenu:dl}):c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(Fs,{size:28,className:"text-muted/40 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No files yet"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Start a build to generate your project."})]})})]})}),c.jsx(qs,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),c.jsx(ui,{defaultSize:80,minSize:40,children:c.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[c.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:Fl},{id:"preview",label:"Preview",icon:hi},{id:"config",label:"Config",icon:xl},{id:"secrets",label:"Secrets",icon:lh},{id:"prd",label:"PRD",icon:Oo}].map(y=>c.jsxs("button",{role:"tab","aria-selected":f===y.id,onClick:()=>m(y.id),className:`flex items-center gap-1.5 px-4 py-2 text-xs font-medium border-b-2 transition-colors ${f===y.id?"border-primary text-primary":"border-transparent text-muted hover:text-ink hover:border-border"}`,children:[c.jsx(y.icon,{size:14}),y.label]},y.id))}),c.jsxs("div",{className:"flex-1 min-h-0",role:"tabpanel",children:[f==="code"&&c.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[b.length>0&&c.jsx("div",{className:"flex items-center border-b border-border bg-hover overflow-x-auto flex-shrink-0",children:b.map(y=>c.jsxs("button",{onClick:()=>Qt(y.path,y.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 ${y.path===i?"bg-card text-ink":"text-muted hover:text-ink hover:bg-card"}`,children:[c.jsx("span",{className:"w-4 flex items-center justify-center",children:Pr(y.name,"file")}),y.name,y.modified&&c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),c.jsx("span",{role:"button",tabIndex:-1,title:"Close tab",onClick:I=>{I.stopPropagation(),tn(y.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),tn(y.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:c.jsx(yi,{size:12})})]},y.path))}),i?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-hover",children:[c.jsx("span",{className:"text-xs font-mono text-secondary truncate",children:i}),S&&c.jsx("span",{className:"text-xs text-primary animate-pulse flex-shrink-0",children:"Saving..."}),c.jsx("span",{className:"ml-auto text-xs text-muted/50 font-mono",children:rn!=null?el(rn):""}),c.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:bl}),_&&c.jsx("button",{onClick:ys,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"})]}),Ke===i&&c.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-warning/10",children:[c.jsx(_h,{size:12,className:"text-warning"}),c.jsx("span",{className:"text-xs text-warning font-medium",children:"File changed externally"}),c.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[c.jsx("button",{onClick:al,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"}),c.jsx("button",{onClick:()=>Ae(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"})]})]}),c.jsx("div",{className:"flex-1 min-h-0",children:d?c.jsx(Cl,{}):c.jsx(Vi,{name:"Editor",children:c.jsx(Tc,{value:h??"",language:X_(r),theme:"vs",onChange:ml,onMount:gl,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}}})})})]}):c.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center p-8",children:[c.jsx(Ge,{size:32,className:"text-muted/30 mb-3"}),c.jsx("p",{className:"text-sm text-muted",children:"Select a file to view its contents"}),c.jsxs("p",{className:"text-xs text-muted/60 mt-1",children:["Use the file tree or press ",c.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"&&c.jsx(Vi,{name:"Preview",children:c.jsxs("div",{className:"h-full flex flex-col",children:[c.jsx("div",{className:"px-3 py-1.5 border-b border-border flex items-center gap-2 bg-hover",children:U!=null&&U.running||Q!=null&&Q.preview_url?c.jsxs(c.Fragment,{children:[c.jsx(ct,{icon:Ol,label:"Back",size:"sm",onClick:ul,disabled:st<=0}),c.jsx(ct,{icon:kl,label:"Forward",size:"sm",onClick:fl,disabled:st>=Ni.length-1}),c.jsx(ct,{icon:Pl,label:"Refresh",size:"sm",onClick:()=>P(y=>y+1)}),c.jsx("input",{value:Qr,onChange:y=>en(y.target.value),onKeyDown:y=>{y.key==="Enter"&&_l(Qr)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),c.jsx(ct,{icon:Il,label:"Open in new tab",size:"sm",onClick:()=>window.open(It,"_blank")}),(U==null?void 0:U.running)&&c.jsxs("button",{onClick:ll,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:[c.jsx(is,{size:12}),"Stop"]})]}):Q?c.jsx("div",{className:"flex-1 flex items-center gap-2 text-sm text-muted",children:c.jsx("span",{className:"font-medium text-ink",children:Q.description})}):c.jsx("div",{className:"flex-1 flex items-center text-sm text-muted",children:"Detecting project type..."})}),U&&U.status!=="stopped"&&c.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs ${U.running?"bg-green-50 border-green-200 text-green-700":U.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":U.status==="error"?"bg-red-50 border-red-200 text-red-700":"bg-gray-50 border-border text-muted"}`,children:[c.jsx("span",{className:`w-2 h-2 rounded-full ${U.running?"bg-green-500":U.status==="starting"?"bg-yellow-500 animate-pulse":U.status==="error"?"bg-red-500":"bg-gray-400"}`}),U.running&&U.portless_url&&c.jsxs("span",{children:["Running at ",U.portless_url]}),U.running&&U.port&&!U.portless_url&&c.jsxs("span",{children:["Running on port ",U.port]}),U.status==="starting"&&c.jsx("span",{children:"Starting dev server..."}),U.status==="error"&&c.jsx("span",{children:"Dev server crashed"}),U.command&&c.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:U.command})]}),U!=null&&U.running?c.jsx("div",{className:"flex-1 bg-white",children:c.jsx("iframe",{ref:M,src:It,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},C)}):Q!=null&&Q.preview_url?c.jsx("div",{className:"flex-1 bg-white",children:c.jsx("iframe",{ref:M,src:It,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},C)}):Q?c.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[c.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:Q.type==="api"||Q.type==="python-api"?c.jsx(bh,{size:28,className:"text-primary"}):Q.type==="library"?c.jsx(uh,{size:28,className:"text-primary"}):Q.type==="go-app"||Q.type==="rust-app"?c.jsx(zo,{size:28,className:"text-primary"}):c.jsx(Fs,{size:28,className:"text-primary"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-heading text-ink mb-1",children:Q.type.replace(/-/g," ").replace(/\b\w/g,y=>y.toUpperCase())}),c.jsx("p",{className:"text-sm text-muted",children:Q.description})]}),c.jsxs("div",{className:"card p-4 max-w-md w-full space-y-3",children:[Q.dev_command&&c.jsxs(c.Fragment,{children:[c.jsx("p",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Dev Server"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"text-sm font-mono text-primary bg-hover px-3 py-2 rounded-btn flex-1 text-left truncate",children:Q.dev_command}),c.jsxs("button",{onClick:()=>Li(Q.dev_command||void 0),disabled:ms,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:[c.jsx(xs,{size:12}),ms?"Starting...":"Start"]})]})]}),c.jsxs("div",{className:Q.dev_command?"pt-2 border-t border-border":"",children:[c.jsx("p",{className:"text-xs text-muted mb-2",children:Q.dev_command?"Or use a custom command:":"Start a dev server:"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:yt,onChange:y=>ol(y.target.value),onKeyDown:y=>{y.key==="Enter"&&yt.trim()&&Li(yt.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"}),c.jsx("button",{onClick:()=>yt.trim()&&Li(yt.trim()),disabled:ms||!yt.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"})]})]})]}),Jr&&c.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[c.jsx("p",{className:"text-xs text-danger font-medium mb-1",children:"Dev server error"}),c.jsx("p",{className:"text-xs text-danger/80",children:Jr})]}),(U==null?void 0:U.status)==="error"&&c.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("p",{className:"text-xs text-danger font-medium",children:"Dev server crashed"}),c.jsx("button",{onClick:()=>Li(Q.dev_command||yt||void 0),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]}),U.output.length>0&&c.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:U.output.slice(-10).join(`
184
+ `+X:X}:{}))}catch{}else if(L==="complete"&&V)try{const{returncode:X,files_changed:H}=JSON.parse(V);r(F=>Ct(F,$=>$.role==="system"&&$.isStreaming?{isStreaming:!1,filesChanged:H,returncode:X,content:$.content||"Done."}:{})),(H==null?void 0:H.length)>0&&i&&i(H)}catch{}else if(L==="error"&&V)try{const{error:X}=JSON.parse(V);r(H=>Ct(H,F=>F.role==="system"&&F.isStreaming?{isStreaming:!1,content:`Error: ${X}`}:{}))}catch{}}}}catch(O){if(O instanceof DOMException&&O.name==="AbortError")return;await w(b)}finally{f(!1),d(!1),p.current=null,S.current=null,(T=_.current)==null||T.focus()}},[e,i,w]),k=async()=>{var O;const b=n.trim();if(!b||l)return;const B={role:"user",content:b,timestamp:new Date().toISOString()},T={role:"system",content:"",timestamp:new Date().toISOString(),isStreaming:!0};r(K=>[...K,B,T]),o(""),d(!0);try{const{task_id:K}=await te.chatStart(e,b,a);await R(K)}catch(K){r(W=>Ct(W,A=>A.role==="system"&&A.isStreaming?{isStreaming:!1,content:`Error: ${K instanceof Error?K.message:"Request failed"}`}:{})),d(!1),(O=_.current)==null||O.focus()}};return c.jsxs("div",{className:"flex flex-col h-full",children:[c.jsxs("div",{ref:m,className:"flex-1 overflow-y-auto p-3 space-y-3 terminal-scroll",children:[s.length===0&&c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(Ao,{size:28,className:"text-muted/30 mb-3"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No messages yet"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-1 max-w-[200px]",children:"Ask the AI to build, modify, or explain your code."})]}),s.map((b,B)=>c.jsx("div",{className:`flex ${b.role==="user"?"justify-end":"justify-start"}`,children:c.jsxs("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-xs ${b.role==="user"?"bg-primary/10 text-ink":"bg-hover text-ink border-l-2 border-primary/40"}`,children:[c.jsxs("pre",{className:"whitespace-pre-wrap font-mono text-xs leading-relaxed overflow-x-auto",children:[b.content,b.isStreaming&&c.jsx("span",{className:"inline-block w-1.5 h-3.5 bg-primary/60 animate-pulse ml-0.5 align-text-bottom"})]}),b.filesChanged&&b.filesChanged.length>0&&c.jsxs("div",{className:"mt-2 pt-2 border-t border-border",children:[c.jsx("span",{className:"text-xs text-muted font-semibold uppercase",children:"Files changed:"}),c.jsx("ul",{className:"mt-1 space-y-0.5",children:b.filesChanged.map((T,O)=>c.jsx("li",{className:"text-xs font-mono text-muted",children:T},O))})]}),b.role==="system"&&!b.isStreaming&&b.returncode!==void 0&&c.jsx("div",{className:"mt-1 text-[10px] text-muted",children:b.returncode===0?"Done":`Exit code: ${b.returncode}`})]})},B))]}),c.jsxs("div",{className:"border-t border-border p-2 flex-shrink-0",children:[u&&c.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[c.jsx("span",{className:"text-[10px] text-muted font-mono",children:"Streaming..."}),c.jsxs("button",{onClick:v,className:"flex items-center gap-1 text-[10px] text-red-400 hover:text-red-300 transition-colors",children:[c.jsx(is,{className:"w-2.5 h-2.5"}),"Stop"]})]}),c.jsx("div",{className:"flex items-center gap-1 mb-2",children:["quick","standard","max"].map(b=>c.jsx("button",{onClick:()=>h(b),className:`text-xs font-semibold px-3 py-1.5 rounded-btn transition-colors capitalize ${a===b?"bg-primary text-white":"text-muted hover:text-ink"}`,children:b},b))}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{ref:_,type:"text",value:n,onChange:b=>o(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),k())},placeholder:"Ask AI to modify your project...",className:"flex-1 px-3 py-1.5 text-xs bg-card border border-border rounded-btn outline-none focus:border-primary transition-colors",disabled:l}),u?c.jsx(Ft,{size:"sm",icon:is,onClick:v,"aria-label":"Stop streaming",className:"bg-red-500/10 hover:bg-red-500/20 text-red-400",children:"Stop"}):c.jsx(Ft,{size:"sm",icon:vh,onClick:k,disabled:l||!n.trim(),"aria-label":"Send message",children:"Send"})]})]})]})}const Po=[{id:"terminal",label:"Terminal",icon:zo},{id:"build",label:"Build Log",icon:mh},{id:"agents",label:"Agents",icon:Hl},{id:"quality",label:"Quality",icon:Io},{id:"chat",label:"AI Chat",icon:Ao}];function $_({status:e}){switch(e){case"pass":return c.jsx(zl,{size:14,className:"text-success"});case"fail":return c.jsx(yi,{size:14,className:"text-danger"});default:return c.jsx(Al,{size:14,className:"text-muted"})}}function F_({agents:e}){return!e||e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(kh,{size:24,className:"text-muted/30 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No agents active"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Agents will appear here during builds."})]}):c.jsx("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:e.map(t=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-btn bg-hover text-xs",children:[c.jsx("span",{className:"font-semibold text-ink truncate",children:t.name}),c.jsx("span",{className:"text-xs font-mono text-muted-accessible px-1.5 py-0.5 rounded-btn bg-card",children:t.type}),c.jsx("span",{className:`text-xs font-semibold ${t.status==="running"?"text-success":"text-muted"}`,children:t.status}),c.jsx("span",{className:"ml-auto text-xs text-muted-accessible font-mono truncate max-w-[200px]",children:t.task})]},t.id))})}function W_({checklist:e}){return!e||!e.items||e.items.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(Io,{size:24,className:"text-muted/30 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No quality gate data"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Quality gates will appear during builds."})]}):c.jsxs("div",{className:"p-2 space-y-1 overflow-y-auto terminal-scroll",children:[c.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-xs text-muted-accessible font-semibold uppercase",children:[c.jsx("span",{children:"Gate"}),c.jsxs("span",{className:"ml-auto",children:[e.passed,"/",e.total," passed"]})]}),e.items.map(t=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-btn hover:bg-hover text-xs",children:[c.jsx($_,{status:t.status}),c.jsx("span",{className:"text-ink",children:t.label}),t.details&&c.jsx("span",{className:"ml-auto text-xs text-muted-accessible truncate max-w-[200px]",children:t.details})]},t.id))]})}function K_({logs:e,logsLoading:t,agents:i,checklist:s,sessionId:r,subscribe:n,buildMode:o}){var l;const[a,h]=g.useState("terminal");return c.jsxs("div",{className:"h-full flex flex-col bg-card",children:[c.jsx("div",{role:"tablist",className:"flex items-center border-b border-border px-2 flex-shrink-0",children:Po.map(d=>{const u=d.icon,f=a===d.id;return c.jsxs("button",{role:"tab","aria-selected":f,onClick:()=>h(d.id),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors border-b-2 ${f?"border-primary text-primary":"border-transparent text-muted hover:text-ink"}`,children:[c.jsx(u,{size:14}),d.label]},d.id)})}),c.jsxs("div",{role:"tabpanel","aria-label":(l=Po.find(d=>d.id===a))==null?void 0:l.label,className:"flex-1 min-h-0 overflow-hidden relative",children:[c.jsx("div",{className:"absolute inset-0",style:{visibility:a==="terminal"?"visible":"hidden",zIndex:a==="terminal"?1:0},children:c.jsx(j_,{sessionId:r,isActive:a==="terminal"})}),a==="build"&&c.jsx(Dl,{logs:e,loading:t,subscribe:n}),a==="agents"&&c.jsx(F_,{agents:i}),a==="quality"&&c.jsx(W_,{checklist:s}),a==="chat"&&c.jsx(H_,{sessionId:r,defaultMode:o})]})]})}const Za=typeof navigator<"u"&&/Mac/.test(navigator.userAgent),li=Za?"Cmd":"Ctrl",U_=[{keys:[`${li}+S`],label:"Save file"},{keys:[`${li}+P`],label:"Quick open file"},{keys:[`${li}+\``],label:"Toggle terminal"},{keys:[`${li}+B`],label:"Start / stop build"},{keys:[`${li}+?`],label:"Show keyboard shortcuts"},{keys:["Escape"],label:"Close modals"}];function q_({onToggleTerminal:e,onToggleBuild:t}){const[i,s]=g.useState(!1),r=g.useCallback(n=>{const o=Za?n.metaKey:n.ctrlKey;if(o&&(n.key==="?"||n.shiftKey&&n.key==="/")){n.preventDefault(),s(a=>!a);return}if(o&&n.key==="`"){n.preventDefault(),e==null||e();return}if(o&&n.key==="b"){n.preventDefault(),t==null||t();return}n.key==="Escape"&&i&&s(!1)},[e,t,i]);return g.useEffect(()=>(window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)),[r]),{showHelp:i,setShowHelp:s}}function V_({open:e,onClose:t}){return e?c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/20",onClick:t,children:c.jsxs("div",{className:"bg-card rounded-card shadow-card-hover border border-border w-full max-w-md mx-4",onClick:i=>i.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ch,{size:16,className:"text-primary"}),c.jsx("h2",{className:"text-sm font-heading font-bold text-ink",children:"Keyboard Shortcuts"})]}),c.jsx("button",{onClick:t,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",children:c.jsx(yi,{size:16})})]}),c.jsx("div",{className:"p-4 space-y-1",children:U_.map(i=>c.jsxs("div",{className:"flex items-center justify-between px-2 py-2 rounded-btn hover:bg-hover",children:[c.jsx("span",{className:"text-xs text-ink",children:i.label}),c.jsx("div",{className:"flex items-center gap-1",children:i.keys.map(s=>c.jsx("kbd",{className:"px-2 py-0.5 text-[11px] font-mono bg-hover border border-border rounded text-muted-accessible",children:s},s))})]},i.label))}),c.jsx("div",{className:"px-5 py-3 border-t border-border text-center",children:c.jsxs("span",{className:"text-[11px] text-muted",children:["Press ",c.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 Y_({onClick:e}){return c.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:"?"})}function Pr(e,t,i){var n;if(t==="directory")return i?c.jsx(Fs,{size:14}):c.jsx(oh,{size:14});const s=((n=e.split(".").pop())==null?void 0:n.toLowerCase())||"";return{js:c.jsx(Ge,{size:14,className:"text-yellow-600"}),ts:c.jsx(Ge,{size:14,className:"text-blue-500"}),tsx:c.jsx(Ge,{size:14,className:"text-blue-400"}),jsx:c.jsx(Ge,{size:14,className:"text-yellow-500"}),py:c.jsx(Ge,{size:14,className:"text-green-600"}),html:c.jsx(Xl,{size:14,className:"text-orange-500"}),css:c.jsx(Ql,{size:14,className:"text-purple-500"}),json:c.jsx(ql,{size:14,className:"text-green-500"}),md:c.jsx(Oo,{size:14,className:"text-muted"}),go:c.jsx(Ge,{size:14,className:"text-cyan-600"}),rs:c.jsx(Ge,{size:14,className:"text-orange-600"}),rb:c.jsx(Ge,{size:14,className:"text-red-500"}),sh:c.jsx(Ge,{size:14,className:"text-green-600"})}[s]||c.jsx(th,{size:14})}function X_(e){var r;const t=((r=e.split(".").pop())==null?void 0:r.toLowerCase())||"",i={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"},s=e.toLowerCase();return s==="dockerfile"?"dockerfile":s==="makefile"?"makefile":i[t]||"plaintext"}function Qa(e,t){for(const i of e){if(i.path===t)return i.size;if(i.children){const s=Qa(i.children,t);if(s!==void 0)return s}}}function el(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function tl({nodes:e,selectedPath:t,onSelect:i,onDelete:s,onContextMenu:r,depth:n=0}){const[o,a]=g.useState(()=>{const h=new Set;return n<2&&e.filter(l=>l.type==="directory").forEach(l=>h.add(l.path)),h});return c.jsx("div",{role:n===0?"tree":"group",children:e.map(h=>{const l=h.type==="directory",d=o.has(h.path),u=h.path===t;return c.jsxs("div",{className:"group/file",children:[c.jsxs("button",{role:"treeitem","aria-label":h.name,"aria-selected":u,...l?{"aria-expanded":d}:{},onContextMenu:f=>{f.preventDefault(),r==null||r(f,h.path,h.name,h.type)},onClick:()=>{l?a(f=>{const m=new Set(f);return m.has(h.path)?m.delete(h.path):m.add(h.path),m}):i(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 ${u?"bg-primary/10 text-primary":"text-ink/70 hover:bg-hover"}`,style:{paddingLeft:`${n*14+8}px`},children:[l?c.jsx("span",{className:"w-3 flex items-center justify-center flex-shrink-0 text-muted",children:d?c.jsx(Bl,{size:14}):c.jsx(Ll,{size:14})}):c.jsx("span",{className:"w-3 flex-shrink-0"}),c.jsx("span",{className:`w-5 flex items-center justify-center flex-shrink-0 ${l?"text-primary":""}`,children:Pr(h.name,h.type,d)}),c.jsxs("span",{className:"truncate",children:[h.name,l?"/":""]}),!l&&h.size!=null&&h.size>0&&c.jsx("span",{className:"text-xs text-muted ml-auto flex-shrink-0",children:el(h.size)}),!l&&s&&c.jsx("span",{role:"button",tabIndex:-1,onClick:f=>{f.stopPropagation(),s(h.path,h.name)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),s(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:c.jsx(yi,{size:12})})]}),l&&d&&h.children&&c.jsx(tl,{nodes:h.children,selectedPath:t,onSelect:i,onDelete:s,onContextMenu:r,depth:n+1})]},h.path)})})}function il(e,t=""){const i=[];for(const s of e)s.type==="file"&&i.push({path:s.path,name:s.name}),s.children&&i.push(...il(s.children,s.path+"/"));return i}function G_(){const[e,t]=g.useState({}),[i,s]=g.useState(""),[r,n]=g.useState(""),[o,a]=g.useState(!0),[h,l]=g.useState(null),[d,u]=g.useState(new Set),f=g.useCallback(async()=>{try{const v=await te.getSecrets();t(v)}catch{}a(!1)},[]);g.useEffect(()=>{f()},[f]);const m=async()=>{const v=i.trim();if(v){if(!/^[A-Z_][A-Z0-9_]*$/.test(v)){l("Key must be a valid ENV_VAR name (uppercase letters, digits, underscores)");return}l(null);try{await te.setSecret(v,r),s(""),n(""),await f()}catch(w){l(w instanceof Error?w.message:"Failed to set secret")}}},_=async v=>{if(window.confirm(`Delete secret "${v}"?`))try{await te.deleteSecret(v),await f()}catch(w){l(w instanceof Error?w.message:"Failed to delete secret")}},p=v=>{u(w=>{const R=new Set(w);return R.has(v)?R.delete(v):R.add(v),R})},S=Object.keys(e);return o?c.jsxs("div",{className:"p-6 space-y-4",children:[c.jsx(ws,{variant:"text",width:"180px",height:"16px"}),c.jsx(ws,{variant:"block",width:"100%",height:"60px"}),c.jsx(ws,{variant:"block",width:"100%",height:"80px"})]}):c.jsx("div",{className:"h-full flex flex-col",children:c.jsxs("div",{className:"p-6 overflow-y-auto",children:[c.jsx("h3",{className:"text-h3 font-heading text-ink mb-2",children:"Environment Secrets"}),c.jsxs("div",{className:"flex items-start gap-2 px-4 py-3 rounded-btn border border-warning/30 bg-warning/5 mb-6",children:[c.jsx(Nl,{size:16,className:"text-warning flex-shrink-0 mt-0.5"}),c.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."})]}),S.length>0&&c.jsx("div",{className:"card mb-6",children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"border-b border-border",children:[c.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Key"}),c.jsx("th",{className:"text-left px-4 py-2 text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Value"}),c.jsx("th",{className:"w-20 px-4 py-2"})]})}),c.jsx("tbody",{children:S.map(v=>c.jsxs("tr",{className:"border-b border-border last:border-b-0",children:[c.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-ink",children:v}),c.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-muted-accessible",children:c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx("span",{children:d.has(v)?e[v]:"***"}),c.jsx("button",{onClick:()=>p(v),className:"text-muted hover:text-ink transition-colors",title:d.has(v)?"Hide value":"Show value",children:d.has(v)?c.jsx(Kl,{size:14}):c.jsx(hi,{size:14})})]})}),c.jsx("td",{className:"px-4 py-2.5 text-right",children:c.jsx("button",{onClick:()=>_(v),className:"text-muted hover:text-danger transition-colors",title:"Delete secret",children:c.jsx(jo,{size:14})})})]},v))})]})}),S.length===0&&c.jsx("div",{className:"card p-4 mb-6",children:c.jsx("p",{className:"text-sm text-muted-accessible text-center py-4",children:"No secrets configured yet. Add your first secret below."})}),c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-3",children:"Add Secret"}),h&&c.jsx("div",{className:"text-xs text-danger mb-3 px-1",children:h}),c.jsxs("div",{className:"flex items-end gap-3",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Key"}),c.jsx("input",{type:"text",value:i,onChange:v=>s(v.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"})]}),c.jsxs("div",{className:"flex-1",children:[c.jsx("label",{className:"block text-xs text-muted-accessible mb-1",children:"Value"}),c.jsx("input",{type:"password",value:r,onChange:v=>n(v.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"})]}),c.jsxs("button",{onClick:m,disabled:!i.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:[c.jsx(Tl,{size:14}),"Add"]})]})]})]})})}function J_({session:e,onClose:t}){var on;const[i,s]=g.useState(null),[r,n]=g.useState(""),[o,a]=g.useState(null),[h,l]=g.useState(null),[d,u]=g.useState(!1),[f,m]=g.useState("code"),[_,p]=g.useState(!1),[S,v]=g.useState(!1),[w,R]=g.useState(e),k=g.useRef(null),[b,B]=g.useState([]),[T,O]=g.useState(!1),[K,W]=g.useState(""),A=g.useRef(null),M=g.useRef(null),[C,P]=g.useState(0),[x,D]=g.useState(null),[j,L]=g.useState("standard"),[V,X]=g.useState("claude"),[H,F]=g.useState(null),[$,ie]=g.useState(null),[le,ne]=g.useState(!1),[Te,qe]=g.useState(!1),[je,bt]=g.useState(!1),[Ke,Ae]=g.useState(null),Z=g.useRef(null),{subscribe:Ot}=wl(),ht=g.useCallback(async()=>{try{const y=await te.getSessionDetail(w.id);R(y)}catch{}},[w.id]),Xr=g.useCallback(async()=>{try{await te.stopSession(),ne(!1),qe(!1)}catch{}},[]),sl=g.useCallback(async()=>{try{await te.pauseSession(),qe(!0)}catch{}},[]),rl=g.useCallback(async()=>{try{await te.resumeSession(),qe(!1)}catch{}},[]);g.useEffect(()=>{const y=async()=>{try{const Y=await te.getStatus();ne(Y.running),qe(Y.paused),Y.provider&&X(Y.provider)}catch{}};y();const I=setInterval(y,1e4);return()=>clearInterval(I)},[]),g.useEffect(()=>{if(!($!=null&&$.loading))return;const y=setInterval(()=>{ie(I=>I?{...I,elapsed:Math.floor((Date.now()-I.startTime)/1e3)}:null)},1e3);return()=>clearInterval(y)},[$==null?void 0:$.loading]);const[Q,nl]=g.useState(null);g.useEffect(()=>{te.getPreviewInfo(w.id).then(nl).catch(()=>{})},[w.id]);const[U,ps]=g.useState(null),[ms,Gr]=g.useState(!1),[Jr,gs]=g.useState(null),[yt,ol]=g.useState("");g.useEffect(()=>{const y=Ot("file_changed",I=>{const Y=I;!Y.paths||Y.paths.length===0||(bt(!0),Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>bt(!1),2e3),ht(),i&&Y.paths.some(Ve=>Ve===i||i.endsWith(Ve))&&Ae(i),f==="preview"&&!(U!=null&&U.running)&&P(ee=>ee+1))});return()=>{y(),Z.current&&clearTimeout(Z.current)}},[Ot,i,f,U==null?void 0:U.running,ht]);const al=g.useCallback(async()=>{if(!(!Ke||!w.id)){try{const y=await te.getSessionFileContent(w.id,Ke);a(y.content),l(y.content),p(!1),B(I=>I.map(Y=>Y.path===Ke?{...Y,content:y.content,modified:!1}:Y))}catch{}Ae(null)}},[Ke,w.id]);g.useEffect(()=>{if(f!=="preview")return;let y=!1;const I=async()=>{try{const ee=await te.devserver.status(w.id);y||ps(ee)}catch{}};I();const Y=setInterval(I,3e3);return()=>{y=!0,clearInterval(Y)}},[f,w.id]);const Li=g.useCallback(async y=>{Gr(!0),gs(null);try{const I=await te.devserver.start(w.id,y);if(I.status==="error")gs(I.message||"Failed to start dev server");else{const Y=await te.devserver.status(w.id);ps(Y)}}catch(I){gs(I instanceof Error?I.message:"Failed to start dev server")}Gr(!1)},[w.id]),ll=g.useCallback(async()=>{try{await te.devserver.stop(w.id);const y=await te.devserver.status(w.id);ps(y)}catch{}},[w.id]),vs=U!=null&&U.running&&(U!=null&&U.port)?U.portless_url||`http://localhost:${U.port}/`:null,hl=(Q==null?void 0:Q.preview_url)||`/api/sessions/${encodeURIComponent(w.id)}/preview/index.html`,cl=vs||hl,[Ni,Zr]=g.useState([]),[st,Ti]=g.useState(0);g.useEffect(()=>{const y=vs||(Q==null?void 0:Q.preview_url);y&&(Zr([y]),Ti(0))},[vs,Q==null?void 0:Q.preview_url]);const It=Ni[st]||cl,[Qr,en]=g.useState(It),dl=g.useCallback((y,I,Y,ee)=>{y.preventDefault(),D({x:y.clientX,y:y.clientY,path:I,name:Y,type:ee})},[]),ul=g.useCallback(()=>{st>0&&(Ti(y=>y-1),P(y=>y+1))},[st]),fl=g.useCallback(()=>{st<Ni.length-1&&(Ti(y=>y+1),P(y=>y+1))},[st,Ni.length]),_l=g.useCallback(y=>{Zr(I=>[...I.slice(0,st+1),y]),Ti(I=>I+1),P(I=>I+1)},[st]);g.useEffect(()=>{en(It)},[It]);const Ai=g.useCallback(async()=>{ie({type:"review",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.reviewProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),zi=g.useCallback(async()=>{ie({type:"test",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.testProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),Ss=g.useCallback(async()=>{ie({type:"explain",loading:!0,startTime:Date.now(),elapsed:0}),F(null);try{const y=await te.explainProject(w.id);F(y.output)}catch(y){F(`Error: ${y instanceof Error?y.message:"Unknown"}`)}finally{ie(null)}},[w.id]),bs=g.useCallback(async(y,I)=>{if(window.confirm(`Delete "${I}"?`))try{await te.deleteSessionFile(w.id,y),i===y&&(s(null),n(""),a(null),l(null),p(!1)),await ht()}catch(ee){const Ve=ee instanceof Error?ee.message:"Unknown error";window.alert(`Delete failed: ${Ve}`)}},[w.id,i,ht]),pl=g.useCallback(y=>y.type==="file"?[{label:"Review",icon:hi,onClick:()=>{Ai()}},{label:"Generate Tests",icon:Cs,onClick:()=>{zi()}},{label:"Explain",icon:dn,onClick:()=>{Ss()}},{label:"Delete",icon:jo,onClick:()=>{bs(y.path,y.name)},variant:"danger"}]:[{label:"Review Project",icon:hi,onClick:()=>{Ai()}},{label:"Run Tests",icon:Cs,onClick:()=>{zi()}}],[Ai,zi,Ss,bs]),Qt=g.useCallback(async(y,I)=>{Ae(null),_&&i&&h!==null&&B(ee=>ee.map(Ve=>Ve.path===i?{...Ve,content:h,modified:!0}:Ve));const Y=b.find(ee=>ee.path===y);if(Y){s(y),n(I),a(Y.content),l(Y.content),p(Y.modified);return}s(y),n(I),u(!0),p(!1);try{const ee=w.id?await te.getSessionFileContent(w.id,y):await te.getFileContent(y);a(ee.content),l(ee.content),B(Ve=>[...Ve,{path:y,name:I,content:ee.content,modified:!1}])}catch{a("[Error loading file]"),l("[Error loading file]")}finally{u(!1)}},[w.id,_,i,h,b]),ys=g.useCallback(async()=>{var y;if(!(!i||h===null||!w.id)){v(!0);try{await te.saveSessionFile(w.id,i,h),a(h),p(!1),B(Y=>Y.map(ee=>ee.path===i?{...ee,content:h,modified:!1}:ee));const I=((y=i.split(".").pop())==null?void 0:y.toLowerCase())||"";["html","css","js","jsx","ts","tsx"].includes(I)&&P(Y=>Y+1)}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Save failed: ${Y}`)}finally{v(!1)}}},[i,h,w.id]),tn=g.useCallback(y=>{const I=b.find(Y=>Y.path===y);if(!(I!=null&&I.modified&&!window.confirm("Unsaved changes. Close anyway?"))&&(B(Y=>Y.filter(ee=>ee.path!==y)),i===y)){const Y=b.filter(ee=>ee.path!==y);if(Y.length>0){const ee=Y[Y.length-1];s(ee.path),n(ee.name),a(ee.content),l(ee.content),p(ee.modified)}else s(null),n(""),a(null),l(null),p(!1)}},[b,i]);g.useEffect(()=>{const y=I=>{(I.metaKey||I.ctrlKey)&&I.key==="s"&&(I.preventDefault(),_&&i&&ys()),(I.metaKey||I.ctrlKey)&&I.key==="p"&&(I.preventDefault(),O(Y=>!Y),W("")),I.key==="Escape"&&T&&O(!1)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[_,i,ys,T]),g.useEffect(()=>{T&&A.current&&A.current.focus()},[T]);const sn=il(w.files),ei=K?sn.filter(y=>y.path.toLowerCase().includes(K.toLowerCase())):sn;g.useEffect(()=>{const y=w.files.find(I=>I.name==="index.html"&&I.type==="file");y&&Qt(y.path,y.name)},[]);const ml=g.useCallback(y=>{y!==void 0&&(l(y),p(y!==o))},[o]),gl=g.useCallback(y=>{k.current=y},[]),vl=g.useCallback(async()=>{const y=window.prompt("New file name (e.g. src/utils.ts):");if(!(!y||!y.trim()))try{await te.createSessionFile(w.id,y.trim()),await ht()}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Create file failed: ${Y}`)}},[w.id,ht]),Sl=g.useCallback(async()=>{const y=window.prompt("New folder name (e.g. src/components):");if(!(!y||!y.trim()))try{await te.createSessionDirectory(w.id,y.trim()),await ht()}catch(I){const Y=I instanceof Error?I.message:"Unknown error";window.alert(`Create folder failed: ${Y}`)}},[w.id,ht]),rn=i?Qa(w.files,i):void 0,bl=((on=r.split(".").pop())==null?void 0:on.toUpperCase())||"",{showHelp:yl,setShowHelp:nn}=q_({onToggleBuild:()=>{le&&Xr()}});return c.jsxs("div",{className:"flex flex-col h-full relative",children:[c.jsxs("div",{className:"bg-card px-3 py-2 flex items-center gap-3 flex-shrink-0 border-b border-border",children:[c.jsx("button",{onClick:()=>{_&&!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"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("h2",{className:"text-sm font-bold text-ink truncate",children:w.id}),c.jsx("p",{className:"text-xs font-mono text-muted-accessible truncate",children:w.path})]}),c.jsx("span",{className:`text-xs font-semibold px-2 py-0.5 rounded-full ${w.status==="completed"||w.status==="completion_promise_fulfilled"?"bg-success/10 text-success":"bg-muted/10 text-muted"}`,children:w.status}),!le&&c.jsx(Ft,{variant:"primary",size:"sm",icon:xs,onClick:async()=>{try{const y=w.prd||"";if(!y.trim()){window.alert("No PRD found for this project. Go to Home to start a new build.");return}await te.startSession({prd:y,provider:V,projectDir:w.path}),ne(!0)}catch(y){window.alert(`Failed to start: ${y instanceof Error?y.message:"Unknown error"}`)}},title:"Start build for this project",children:"Build"}),le&&c.jsxs("div",{className:"flex items-center gap-1 border-l border-border pl-3 ml-1",children:[Te?c.jsx(Ft,{variant:"ghost",size:"sm",icon:xs,onClick:rl,title:"Resume build",children:"Resume"}):c.jsx(Ft,{variant:"ghost",size:"sm",icon:Rl,onClick:sl,title:"Pause build",children:"Pause"}),c.jsx(Ft,{variant:"danger",size:"sm",icon:is,onClick:Xr,title:"Stop build",children:"Stop"})]}),c.jsx(ct,{icon:hi,label:"Review project",size:"sm",onClick:Ai,disabled:!!($!=null&&$.loading)}),c.jsx(ct,{icon:Cs,label:"Run tests",size:"sm",onClick:zi,disabled:!!($!=null&&$.loading)}),c.jsx(ct,{icon:dn,label:"Explain project",size:"sm",onClick:Ss,disabled:!!($!=null&&$.loading)}),c.jsx(Y_,{onClick:()=>nn(!0)})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsxs(Us,{orientation:"vertical",children:[c.jsx(ui,{defaultSize:70,minSize:40,children:c.jsxs(Us,{orientation:"horizontal",className:"h-full",children:[c.jsx(ui,{defaultSize:20,minSize:15,children:c.jsxs("div",{className:"h-full flex flex-col border-r border-border bg-card",children:[c.jsxs("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[c.jsxs("span",{className:"text-xs text-muted-accessible uppercase tracking-wider font-semibold flex-1",children:["Files",je&&c.jsx("span",{className:"ml-2 text-[10px] font-normal text-primary animate-pulse",children:"changed"})]}),c.jsxs("button",{onClick:vl,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:[c.jsx(Jl,{size:12})," New"]}),c.jsxs("button",{onClick:Sl,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:[c.jsx(rh,{size:12})," New"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto terminal-scroll",children:w.files.length>0?c.jsx(tl,{nodes:w.files,selectedPath:i,onSelect:Qt,onDelete:bs,onContextMenu:dl}):c.jsxs("div",{className:"flex flex-col items-center justify-center p-6 text-center h-full",children:[c.jsx(Fs,{size:28,className:"text-muted/40 mb-2"}),c.jsx("p",{className:"text-xs text-muted font-medium",children:"No files yet"}),c.jsx("p",{className:"text-[11px] text-muted/70 mt-0.5",children:"Start a build to generate your project."})]})})]})}),c.jsx(qs,{className:"w-1 bg-border hover:bg-primary/30 transition-colors cursor-col-resize"}),c.jsx(ui,{defaultSize:80,minSize:40,children:c.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[c.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:Fl},{id:"preview",label:"Preview",icon:hi},{id:"config",label:"Config",icon:xl},{id:"secrets",label:"Secrets",icon:lh},{id:"prd",label:"PRD",icon:Oo}].map(y=>c.jsxs("button",{role:"tab","aria-selected":f===y.id,onClick:()=>m(y.id),className:`flex items-center gap-1.5 px-4 py-2 text-xs font-medium border-b-2 transition-colors ${f===y.id?"border-primary text-primary":"border-transparent text-muted hover:text-ink hover:border-border"}`,children:[c.jsx(y.icon,{size:14}),y.label]},y.id))}),c.jsxs("div",{className:"flex-1 min-h-0",role:"tabpanel",children:[f==="code"&&c.jsxs("div",{className:"h-full flex flex-col min-w-0",children:[b.length>0&&c.jsx("div",{className:"flex items-center border-b border-border bg-hover overflow-x-auto flex-shrink-0",children:b.map(y=>c.jsxs("button",{onClick:()=>Qt(y.path,y.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 ${y.path===i?"bg-card text-ink":"text-muted hover:text-ink hover:bg-card"}`,children:[c.jsx("span",{className:"w-4 flex items-center justify-center",children:Pr(y.name,"file")}),y.name,y.modified&&c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary"}),c.jsx("span",{role:"button",tabIndex:-1,title:"Close tab",onClick:I=>{I.stopPropagation(),tn(y.path)},onKeyDown:I=>{I.key==="Enter"&&(I.stopPropagation(),tn(y.path))},className:"text-muted hover:text-danger ml-1 cursor-pointer",children:c.jsx(yi,{size:12})})]},y.path))}),i?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-hover",children:[c.jsx("span",{className:"text-xs font-mono text-secondary truncate",children:i}),S&&c.jsx("span",{className:"text-xs text-primary animate-pulse flex-shrink-0",children:"Saving..."}),c.jsx("span",{className:"ml-auto text-xs text-muted/50 font-mono",children:rn!=null?el(rn):""}),c.jsx("span",{className:"text-xs text-muted font-mono uppercase",children:bl}),_&&c.jsx("button",{onClick:ys,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"})]}),Ke===i&&c.jsxs("div",{className:"px-4 py-1.5 border-b border-border flex items-center gap-2 flex-shrink-0 bg-warning/10",children:[c.jsx(_h,{size:12,className:"text-warning"}),c.jsx("span",{className:"text-xs text-warning font-medium",children:"File changed externally"}),c.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[c.jsx("button",{onClick:al,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"}),c.jsx("button",{onClick:()=>Ae(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"})]})]}),c.jsx("div",{className:"flex-1 min-h-0",children:d?c.jsx(Cl,{}):c.jsx(Vi,{name:"Editor",children:c.jsx(Tc,{value:h??"",language:X_(r),theme:"vs",onChange:ml,onMount:gl,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}}})})})]}):c.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center p-8",children:[c.jsx(Ge,{size:32,className:"text-muted/30 mb-3"}),c.jsx("p",{className:"text-sm text-muted",children:"Select a file to view its contents"}),c.jsxs("p",{className:"text-xs text-muted/60 mt-1",children:["Use the file tree or press ",c.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"&&c.jsx(Vi,{name:"Preview",children:c.jsxs("div",{className:"h-full flex flex-col",children:[c.jsx("div",{className:"px-3 py-1.5 border-b border-border flex items-center gap-2 bg-hover",children:U!=null&&U.running||Q!=null&&Q.preview_url?c.jsxs(c.Fragment,{children:[c.jsx(ct,{icon:Ol,label:"Back",size:"sm",onClick:ul,disabled:st<=0}),c.jsx(ct,{icon:kl,label:"Forward",size:"sm",onClick:fl,disabled:st>=Ni.length-1}),c.jsx(ct,{icon:Pl,label:"Refresh",size:"sm",onClick:()=>P(y=>y+1)}),c.jsx("input",{value:Qr,onChange:y=>en(y.target.value),onKeyDown:y=>{y.key==="Enter"&&_l(Qr)},className:"flex-1 px-3 py-1 text-xs font-mono bg-card border border-border rounded-btn"}),c.jsx(ct,{icon:Il,label:"Open in new tab",size:"sm",onClick:()=>window.open(It,"_blank")}),(U==null?void 0:U.running)&&c.jsxs("button",{onClick:ll,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:[c.jsx(is,{size:12}),"Stop"]})]}):Q?c.jsx("div",{className:"flex-1 flex items-center gap-2 text-sm text-muted",children:c.jsx("span",{className:"font-medium text-ink",children:Q.description})}):c.jsx("div",{className:"flex-1 flex items-center text-sm text-muted",children:"Detecting project type..."})}),U&&U.status!=="stopped"&&c.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs ${U.running?"bg-green-50 border-green-200 text-green-700":U.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":U.status==="error"?"bg-red-50 border-red-200 text-red-700":"bg-gray-50 border-border text-muted"}`,children:[c.jsx("span",{className:`w-2 h-2 rounded-full ${U.running?"bg-green-500":U.status==="starting"?"bg-yellow-500 animate-pulse":U.status==="error"?"bg-red-500":"bg-gray-400"}`}),U.running&&U.portless_url&&c.jsxs("span",{children:["Running at ",U.portless_url]}),U.running&&U.port&&!U.portless_url&&c.jsxs("span",{children:["Running on port ",U.port]}),U.status==="starting"&&c.jsx("span",{children:"Starting dev server..."}),U.status==="error"&&c.jsx("span",{children:"Dev server crashed"}),U.command&&c.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:U.command})]}),U!=null&&U.running?c.jsx("div",{className:"flex-1 bg-white",children:c.jsx("iframe",{ref:M,src:It,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},C)}):Q!=null&&Q.preview_url?c.jsx("div",{className:"flex-1 bg-white",children:c.jsx("iframe",{ref:M,src:It,title:"Project Preview",className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups"},C)}):Q?c.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[c.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:Q.type==="api"||Q.type==="python-api"?c.jsx(bh,{size:28,className:"text-primary"}):Q.type==="library"?c.jsx(uh,{size:28,className:"text-primary"}):Q.type==="go-app"||Q.type==="rust-app"?c.jsx(zo,{size:28,className:"text-primary"}):c.jsx(Fs,{size:28,className:"text-primary"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-heading text-ink mb-1",children:Q.type.replace(/-/g," ").replace(/\b\w/g,y=>y.toUpperCase())}),c.jsx("p",{className:"text-sm text-muted",children:Q.description})]}),c.jsxs("div",{className:"card p-4 max-w-md w-full space-y-3",children:[Q.dev_command&&c.jsxs(c.Fragment,{children:[c.jsx("p",{className:"text-xs font-semibold text-muted-accessible uppercase tracking-wider",children:"Dev Server"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"text-sm font-mono text-primary bg-hover px-3 py-2 rounded-btn flex-1 text-left truncate",children:Q.dev_command}),c.jsxs("button",{onClick:()=>Li(Q.dev_command||void 0),disabled:ms,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:[c.jsx(xs,{size:12}),ms?"Starting...":"Start"]})]})]}),c.jsxs("div",{className:Q.dev_command?"pt-2 border-t border-border":"",children:[c.jsx("p",{className:"text-xs text-muted mb-2",children:Q.dev_command?"Or use a custom command:":"Start a dev server:"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:yt,onChange:y=>ol(y.target.value),onKeyDown:y=>{y.key==="Enter"&&yt.trim()&&Li(yt.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"}),c.jsx("button",{onClick:()=>yt.trim()&&Li(yt.trim()),disabled:ms||!yt.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"})]})]})]}),Jr&&c.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[c.jsx("p",{className:"text-xs text-danger font-medium mb-1",children:"Dev server error"}),c.jsx("p",{className:"text-xs text-danger/80",children:Jr})]}),(U==null?void 0:U.status)==="error"&&c.jsxs("div",{className:"card p-3 max-w-md w-full border-danger/30 bg-danger/5",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("p",{className:"text-xs text-danger font-medium",children:"Dev server crashed"}),c.jsx("button",{onClick:()=>Li(Q.dev_command||yt||void 0),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]}),U.output.length>0&&c.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:U.output.slice(-10).join(`
185
185
  `)})]}),Q.port&&!(U!=null&&U.running)&&c.jsxs("p",{className:"text-xs text-muted",children:["Server will run on port ",Q.port]})]}):c.jsx("div",{className:"flex-1 flex items-center justify-center text-muted text-sm",children:"Detecting project type..."})]})}),f==="config"&&c.jsx("div",{className:"h-full flex flex-col",children:c.jsxs("div",{className:"p-6 overflow-y-auto",children:[c.jsx("h3",{className:"text-h3 font-heading text-ink mb-4",children:"Project Configuration"}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Provider"}),c.jsxs("p",{className:"text-xs text-muted mb-2",children:["Current session: ",c.jsx("span",{className:"font-semibold text-ink capitalize",children:V})]}),c.jsx("div",{className:"flex gap-2",children:["claude","codex","gemini"].map(y=>c.jsx("button",{onClick:()=>{X(y),te.setProvider(y).catch(()=>{})},className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${V===y?"border-primary bg-primary/10 text-primary":"border-border text-secondary hover:bg-hover"}`,children:y},y))})]}),c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Build Mode"}),c.jsx("div",{className:"flex gap-2",children:["quick","standard","max"].map(y=>c.jsx("button",{onClick:()=>L(y),className:`px-4 py-2 rounded-btn text-sm font-medium border transition-colors capitalize ${j===y?"border-primary bg-primary/10 text-primary":"border-border text-secondary hover:bg-hover"}`,children:y},y))})]}),c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Project Path"}),c.jsx("input",{value:w.path,readOnly:!0,className:"w-full px-3 py-2 text-sm font-mono bg-hover border border-border rounded-btn text-ink"})]}),c.jsxs("div",{className:"card p-4",children:[c.jsx("label",{className:"block text-xs font-semibold text-muted-accessible uppercase tracking-wider mb-2",children:"Session ID"}),c.jsx("input",{value:w.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"&&c.jsx(G_,{}),f==="prd"&&c.jsx("div",{className:"h-full flex flex-col",children:c.jsxs("div",{className:"p-6 overflow-y-auto",children:[c.jsx("h3",{className:"text-h3 font-heading text-ink mb-4",children:"Product Requirements"}),w.prd?c.jsx("pre",{className:"text-sm font-mono text-ink whitespace-pre-wrap bg-hover border border-border rounded-card p-4 leading-relaxed",children:w.prd}):c.jsx("div",{className:"text-sm text-muted text-center py-8",children:"No PRD found for this project."})]})})]})]})})]})}),c.jsx(qs,{className:"h-1 bg-border hover:bg-primary/30 cursor-row-resize"}),c.jsx(ui,{defaultSize:30,minSize:15,collapsible:!0,children:c.jsx(Vi,{name:"ActivityPanel",children:c.jsx(K_,{logs:null,logsLoading:!1,agents:null,checklist:null,sessionId:e.id,buildMode:j})})})]})}),($==null?void 0:$.loading)&&c.jsx("div",{className:"absolute inset-x-0 bottom-0 z-20 bg-card border-t border-border p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin"}),c.jsxs("span",{className:"text-sm font-medium text-ink",children:[$.type==="review"?"Reviewing project":$.type==="test"?"Generating tests":"Analyzing project","..."]}),c.jsxs("span",{className:"text-xs font-mono text-muted",children:[$.elapsed,"s"]})]})}),H&&c.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:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("span",{className:"text-xs font-semibold text-ink",children:"Action Output"}),c.jsx(ct,{icon:yi,label:"Close",size:"sm",onClick:()=>F(null)})]}),c.jsx("pre",{className:"text-xs font-mono text-ink whitespace-pre-wrap",children:H})]}),x&&c.jsx(gd,{x:x.x,y:x.y,items:pl(x),onClose:()=>D(null)}),T&&c.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:()=>O(!1),children:c.jsxs("div",{className:"bg-card rounded-card shadow-2xl border border-border w-full max-w-lg",onClick:y=>y.stopPropagation(),children:[c.jsx("input",{ref:A,type:"text",value:K,onChange:y=>W(y.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:y=>{y.key==="Enter"&&ei.length>0&&(Qt(ei[0].path,ei[0].name),O(!1)),y.key==="Escape"&&O(!1)}}),c.jsxs("div",{className:"max-h-64 overflow-y-auto",children:[ei.slice(0,20).map(y=>c.jsxs("button",{onClick:()=>{Qt(y.path,y.name),O(!1)},className:"w-full text-left px-4 py-2 text-xs font-mono hover:bg-primary/5 flex items-center gap-2",children:[c.jsx("span",{className:"w-5 flex items-center justify-center",children:Pr(y.name,"file")}),c.jsx("span",{className:"text-ink",children:y.name}),c.jsx("span",{className:"text-muted ml-auto truncate text-xs",children:y.path})]},y.path)),ei.length===0&&c.jsx("div",{className:"px-4 py-3 text-xs text-muted",children:"No matching files"})]})]})}),c.jsx(V_,{open:yl,onClose:()=>nn(!1)})]})}function hp(){const{sessionId:e}=El(),t=Ml(),[i,s]=g.useState(null),[r,n]=g.useState(!0),[o,a]=g.useState(null);return g.useEffect(()=>{e&&(n(!0),a(null),te.getSessionDetail(e).then(h=>{s(h),n(!1)}).catch(h=>{a(h instanceof Error?h.message:"Failed to load session"),n(!1)}))},[e]),r?c.jsx("div",{className:"h-screen bg-background flex items-center justify-center",children:c.jsxs("div",{className:"text-center",children:[c.jsx("div",{className:"text-muted animate-pulse text-sm",children:"Loading project..."}),c.jsx("div",{className:"text-xs font-mono text-muted/50 mt-2",children:e})]})}):o||!i?c.jsx("div",{className:"h-screen bg-background flex items-center justify-center",children:c.jsxs("div",{className:"text-center",children:[c.jsx("p",{className:"text-danger text-sm font-medium",children:"Project not found"}),c.jsx("p",{className:"text-xs text-muted mt-1",children:o||`Session ${e} does not exist`}),c.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"})]})}):c.jsx("div",{className:"h-screen bg-background flex flex-col",children:c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(Vi,{name:"ProjectWorkspace",children:c.jsx(J_,{session:i,onClose:()=>t("/")})})})})}export{hp as default};
@@ -1,4 +1,4 @@
1
- import{c as f,u as h,r as n,a as g,j as e}from"./index-B8Eg1YHL.js";import{B as d,P as m}from"./Button-WBFGRnUr.js";import{C as j}from"./Card-DzOT34Rr.js";import{u as y,B as b}from"./Badge-BDr4DPCT.js";import"./clock-BHGf6zSk.js";/**
1
+ import{c as f,u as h,r as n,a as g,j as e}from"./index-1UyN_URb.js";import{B as d,P as m}from"./Button-DV8ro4oS.js";import{C as j}from"./Card-B4GJw1Yl.js";import{u as y,B as b}from"./Badge-wQU9blAB.js";import"./clock-Csnz1n2_.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as t,a,j as e}from"./index-B8Eg1YHL.js";import{C as l}from"./Card-DzOT34Rr.js";import{E as c}from"./external-link-DLYjfP9j.js";const h=[{id:"claude",name:"Claude",description:"Anthropic Claude Code -- full features"},{id:"codex",name:"Codex",description:"OpenAI Codex CLI -- degraded mode"},{id:"gemini",name:"Gemini",description:"Google Gemini CLI -- degraded mode"}];function p(){const[i,n]=t.useState("claude"),[o,r]=t.useState(!1),[d,x]=t.useState("");t.useEffect(()=>{a.getCurrentProvider().then(s=>n(s.provider)).catch(()=>{}),a.getStatus().then(s=>x(s.version||"")).catch(()=>{})},[]);const m=async s=>{n(s),r(!0);try{await a.setProvider(s)}catch{}finally{r(!1)}};return e.jsxs("div",{className:"max-w-[800px] mx-auto px-6 py-8",children:[e.jsx("h1",{className:"font-heading text-h1 text-[#36342E] mb-8",children:"Settings"}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-sm font-semibold text-[#36342E] uppercase tracking-wide mb-4",children:"Provider"}),e.jsx("div",{className:"flex flex-col gap-3",children:h.map(s=>e.jsx(l,{hover:!0,onClick:()=>m(s.id),className:i===s.id?"ring-2 ring-[#553DE9] border-[#553DE9]":"",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center flex-shrink-0 ${i===s.id?"border-[#553DE9]":"border-[#ECEAE3]"}`,children:i===s.id&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#553DE9]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#36342E]",children:s.name}),e.jsx("p",{className:"text-xs text-[#6B6960]",children:s.description})]})]})},s.id))}),o&&e.jsx("p",{className:"text-xs text-[#6B6960] mt-2",children:"Saving..."})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-sm font-semibold text-[#36342E] uppercase tracking-wide mb-4",children:"About"}),e.jsx(l,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[d&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"Version"}),e.jsxs("span",{className:"text-sm font-medium text-[#36342E]",children:["v",d]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"Documentation"}),e.jsxs("a",{href:"https://www.autonomi.dev/docs",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-[#553DE9] hover:underline",children:["autonomi.dev/docs ",e.jsx(c,{size:12})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"GitHub"}),e.jsxs("a",{href:"https://github.com/asklokesh/loki-mode",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-[#553DE9] hover:underline",children:["asklokesh/loki-mode ",e.jsx(c,{size:12})]})]})]})})]})]})}export{p as default};
1
+ import{r as t,a,j as e}from"./index-1UyN_URb.js";import{C as l}from"./Card-B4GJw1Yl.js";import{E as c}from"./external-link-i7ZDkWbe.js";const h=[{id:"claude",name:"Claude",description:"Anthropic Claude Code -- full features"},{id:"codex",name:"Codex",description:"OpenAI Codex CLI -- degraded mode"},{id:"gemini",name:"Gemini",description:"Google Gemini CLI -- degraded mode"}];function p(){const[i,n]=t.useState("claude"),[o,r]=t.useState(!1),[d,x]=t.useState("");t.useEffect(()=>{a.getCurrentProvider().then(s=>n(s.provider)).catch(()=>{}),a.getStatus().then(s=>x(s.version||"")).catch(()=>{})},[]);const m=async s=>{n(s),r(!0);try{await a.setProvider(s)}catch{}finally{r(!1)}};return e.jsxs("div",{className:"max-w-[800px] mx-auto px-6 py-8",children:[e.jsx("h1",{className:"font-heading text-h1 text-[#36342E] mb-8",children:"Settings"}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-sm font-semibold text-[#36342E] uppercase tracking-wide mb-4",children:"Provider"}),e.jsx("div",{className:"flex flex-col gap-3",children:h.map(s=>e.jsx(l,{hover:!0,onClick:()=>m(s.id),className:i===s.id?"ring-2 ring-[#553DE9] border-[#553DE9]":"",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center flex-shrink-0 ${i===s.id?"border-[#553DE9]":"border-[#ECEAE3]"}`,children:i===s.id&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-[#553DE9]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[#36342E]",children:s.name}),e.jsx("p",{className:"text-xs text-[#6B6960]",children:s.description})]})]})},s.id))}),o&&e.jsx("p",{className:"text-xs text-[#6B6960] mt-2",children:"Saving..."})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-sm font-semibold text-[#36342E] uppercase tracking-wide mb-4",children:"About"}),e.jsx(l,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[d&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"Version"}),e.jsxs("span",{className:"text-sm font-medium text-[#36342E]",children:["v",d]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"Documentation"}),e.jsxs("a",{href:"https://www.autonomi.dev/docs",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-[#553DE9] hover:underline",children:["autonomi.dev/docs ",e.jsx(c,{size:12})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-[#6B6960]",children:"GitHub"}),e.jsxs("a",{href:"https://github.com/asklokesh/loki-mode",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-[#553DE9] hover:underline",children:["asklokesh/loki-mode ",e.jsx(c,{size:12})]})]})]})})]})]})}export{p as default};
@@ -1 +1 @@
1
- import{u as c,r,a as x,j as t}from"./index-B8Eg1YHL.js";import{C as p}from"./Card-DzOT34Rr.js";import{u as d,B as h}from"./Badge-BDr4DPCT.js";import"./clock-BHGf6zSk.js";const g=[{key:"all",label:"All"},{key:"website",label:"Website"},{key:"api",label:"API"},{key:"cli",label:"CLI"},{key:"bot",label:"Bot"},{key:"data",label:"Data"},{key:"other",label:"Other"}];function u(l){return l.replace(/\.md$/i,"").replace(/[-_]/g," ").replace(/\b\w/g,a=>a.toUpperCase())}function k(){const l=c(),[a,o]=r.useState("all"),n=r.useCallback(()=>x.getTemplates(),[]),{data:s}=d(n,6e4,!0),i=r.useMemo(()=>s?a==="all"?s:s.filter(e=>(e.category||"other")===a):[],[s,a]),m=e=>{sessionStorage.setItem("pl_template",e),l("/")};return t.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8",children:[t.jsx("h1",{className:"font-heading text-h1 text-[#36342E] mb-6",children:"Templates"}),t.jsx("div",{className:"flex items-center gap-1 mb-6",role:"tablist",children:g.map(e=>t.jsx("button",{role:"tab","aria-selected":a===e.key,onClick:()=>o(e.key),className:`px-3 py-1.5 text-xs font-semibold rounded-[3px] transition-colors ${a===e.key?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:e.label},e.key))}),s?i.length===0?t.jsx("p",{className:"text-sm text-[#6B6960] py-12 text-center",children:"No templates in this category."}):t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:i.map(e=>t.jsxs(p,{hover:!0,onClick:()=>m(e.filename),children:[t.jsx("div",{className:"mb-2",children:t.jsx(h,{status:"version",children:e.category||"other"})}),t.jsx("h3",{className:"text-sm font-medium text-[#36342E] mb-1",children:u(e.name)}),t.jsx("p",{className:"text-xs text-[#6B6960]",children:e.filename})]},e.filename))}):t.jsx("p",{className:"text-sm text-[#6B6960]",children:"Loading templates..."})]})}export{k as default};
1
+ import{u as c,r,a as x,j as t}from"./index-1UyN_URb.js";import{C as p}from"./Card-B4GJw1Yl.js";import{u as d,B as h}from"./Badge-wQU9blAB.js";import"./clock-Csnz1n2_.js";const g=[{key:"all",label:"All"},{key:"website",label:"Website"},{key:"api",label:"API"},{key:"cli",label:"CLI"},{key:"bot",label:"Bot"},{key:"data",label:"Data"},{key:"other",label:"Other"}];function u(l){return l.replace(/\.md$/i,"").replace(/[-_]/g," ").replace(/\b\w/g,a=>a.toUpperCase())}function k(){const l=c(),[a,o]=r.useState("all"),n=r.useCallback(()=>x.getTemplates(),[]),{data:s}=d(n,6e4,!0),i=r.useMemo(()=>s?a==="all"?s:s.filter(e=>(e.category||"other")===a):[],[s,a]),m=e=>{sessionStorage.setItem("pl_template",e),l("/")};return t.jsxs("div",{className:"max-w-[1400px] mx-auto px-6 py-8",children:[t.jsx("h1",{className:"font-heading text-h1 text-[#36342E] mb-6",children:"Templates"}),t.jsx("div",{className:"flex items-center gap-1 mb-6",role:"tablist",children:g.map(e=>t.jsx("button",{role:"tab","aria-selected":a===e.key,onClick:()=>o(e.key),className:`px-3 py-1.5 text-xs font-semibold rounded-[3px] transition-colors ${a===e.key?"bg-[#553DE9] text-white":"text-[#6B6960] hover:text-[#36342E] hover:bg-[#F8F4F0]"}`,children:e.label},e.key))}),s?i.length===0?t.jsx("p",{className:"text-sm text-[#6B6960] py-12 text-center",children:"No templates in this category."}):t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:i.map(e=>t.jsxs(p,{hover:!0,onClick:()=>m(e.filename),children:[t.jsx("div",{className:"mb-2",children:t.jsx(h,{status:"version",children:e.category||"other"})}),t.jsx("h3",{className:"text-sm font-medium text-[#36342E] mb-1",children:u(e.name)}),t.jsx("p",{className:"text-xs text-[#6B6960]",children:e.filename})]},e.filename))}):t.jsx("p",{className:"text-sm text-[#6B6960]",children:"Loading templates..."})]})}export{k as default};
@@ -1,4 +1,4 @@
1
- import{c as o,r as m,j as e}from"./index-B8Eg1YHL.js";/**
1
+ import{c as o,r as m,j as e}from"./index-1UyN_URb.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as o}from"./index-B8Eg1YHL.js";/**
1
+ import{c as o}from"./index-1UyN_URb.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c}from"./index-B8Eg1YHL.js";/**
1
+ import{c}from"./index-1UyN_URb.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as a}from"./index-B8Eg1YHL.js";/**
1
+ import{c as a}from"./index-1UyN_URb.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/HomePage-B8kMCXMB.js","assets/Badge-BDr4DPCT.js","assets/clock-BHGf6zSk.js","assets/TerminalOutput-CmdEXHHd.js","assets/ProjectPage-C-k0iy0i.js","assets/Button-WBFGRnUr.js","assets/arrow-left-DAZzI0L-.js","assets/external-link-DLYjfP9j.js","assets/ProjectPage-9CEnUXvW.css","assets/ProjectsPage-jys_pHzp.js","assets/Card-DzOT34Rr.js","assets/TemplatesPage-COnhb_Wq.js","assets/SettingsPage-Cz_RXr82.js","assets/NotFoundPage-DzeZ0uQ6.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/HomePage-BrwjWs5_.js","assets/Badge-wQU9blAB.js","assets/clock-Csnz1n2_.js","assets/TerminalOutput-B5rIKYNW.js","assets/ProjectPage-CNuYm1A5.js","assets/Button-DV8ro4oS.js","assets/arrow-left-BaOs4kgD.js","assets/external-link-i7ZDkWbe.js","assets/ProjectPage-9CEnUXvW.css","assets/ProjectsPage-uJimVYlj.js","assets/Card-B4GJw1Yl.js","assets/TemplatesPage-_MJc-qGU.js","assets/SettingsPage-BiSUXmC2.js","assets/NotFoundPage-CDzHJO08.js"])))=>i.map(i=>d[i]);
2
2
  var S0=Object.defineProperty;var b0=(i,o,r)=>o in i?S0(i,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[o]=r;var Bn=(i,o,r)=>b0(i,typeof o!="symbol"?o+"":o,r);(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const d of document.querySelectorAll('link[rel="modulepreload"]'))f(d);new MutationObserver(d=>{for(const h of d)if(h.type==="childList")for(const g of h.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&f(g)}).observe(document,{childList:!0,subtree:!0});function r(d){const h={};return d.integrity&&(h.integrity=d.integrity),d.referrerPolicy&&(h.referrerPolicy=d.referrerPolicy),d.crossOrigin==="use-credentials"?h.credentials="include":d.crossOrigin==="anonymous"?h.credentials="omit":h.credentials="same-origin",h}function f(d){if(d.ep)return;d.ep=!0;const h=r(d);fetch(d.href,h)}})();function E0(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Bf={exports:{}},Ln={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -183,4 +183,4 @@ Please change the parent <Route path="${B}"> to <Route path="${B==="/"?"*":`${B}
183
183
  *
184
184
  * This source code is licensed under the ISC license.
185
185
  * See the LICENSE file in the root directory of this source tree.
186
- */const $1=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Kh=Jt("x",$1),Jh=`${window.location.origin}/api`,W1=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;function F1(){const i={"Content-Type":"application/json"};try{const o=localStorage.getItem("pl_auth_token");o&&(i.Authorization=`Bearer ${o}`)}catch{}return i}async function W(i,o){const r=await fetch(`${Jh}${i}`,{...o,headers:{...F1(),...o==null?void 0:o.headers}});if(!r.ok){const f=await r.text().catch(()=>"");throw new Error(`API error ${r.status}: ${r.statusText}${f?` - ${f}`:""}`)}return r.json()}const qa={startSession:i=>W("/session/start",{method:"POST",body:JSON.stringify(i)}),stopSession:()=>W("/session/stop",{method:"POST"}),pauseSession:()=>W("/session/pause",{method:"POST"}),resumeSession:()=>W("/session/resume",{method:"POST"}),getPrdPrefill:()=>W("/session/prd-prefill"),getStatus:()=>W("/session/status"),getAgents:()=>W("/session/agents"),getLogs:(i=200)=>W(`/session/logs?lines=${i}`),getMemorySummary:()=>W("/session/memory"),getChecklist:()=>W("/session/checklist"),getFiles:()=>W("/session/files"),getFileContent:i=>W(`/session/files/content?path=${encodeURIComponent(i)}`),getSessionFileContent:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/file?path=${encodeURIComponent(o)}`),getTemplates:()=>W("/templates"),getTemplateContent:i=>W(`/templates/${encodeURIComponent(i)}`),planSession:(i,o)=>W("/session/plan",{method:"POST",body:JSON.stringify({prd:i,provider:o})}),generateReport:(i="markdown")=>W("/session/report",{method:"POST",body:JSON.stringify({format:i})}),shareSession:()=>W("/session/share",{method:"POST"}),getCurrentProvider:()=>W("/provider/current"),setProvider:i=>W("/provider/set",{method:"POST",body:JSON.stringify({provider:i})}),getMetrics:()=>W("/session/metrics"),getSessionsHistory:()=>W("/sessions/history"),getSessionDetail:i=>W(`/sessions/${encodeURIComponent(i)}`),onboardRepo:i=>W("/session/onboard",{method:"POST",body:JSON.stringify({path:i})}),saveSessionFile:(i,o,r)=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"PUT",body:JSON.stringify({path:o,content:r})}),createSessionFile:(i,o,r="")=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"POST",body:JSON.stringify({path:o,content:r})}),deleteSessionFile:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"DELETE",body:JSON.stringify({path:o})}),createSessionDirectory:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/directory`,{method:"POST",body:JSON.stringify({path:o})}),reviewProject:i=>W(`/sessions/${encodeURIComponent(i)}/review`,{method:"POST"}),testProject:i=>W(`/sessions/${encodeURIComponent(i)}/test`,{method:"POST"}),explainProject:i=>W(`/sessions/${encodeURIComponent(i)}/explain`,{method:"POST"}),exportProject:i=>W(`/sessions/${encodeURIComponent(i)}/export`,{method:"POST"}),chatMessage:(i,o,r="quick")=>W(`/sessions/${encodeURIComponent(i)}/chat`,{method:"POST",body:JSON.stringify({message:o,mode:r})}),chatStart:(i,o,r="quick")=>W(`/sessions/${encodeURIComponent(i)}/chat`,{method:"POST",body:JSON.stringify({message:o,mode:r})}),chatPoll:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}`),chatStreamUrl:(i,o)=>`${Jh}/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}/stream`,chatCancel:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}/cancel`,{method:"POST"}),getPreviewInfo:i=>W(`/sessions/${encodeURIComponent(i)}/preview-info`),devserver:{start:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/devserver/start`,{method:"POST",body:JSON.stringify({command:o||null})}),stop:i=>W(`/sessions/${encodeURIComponent(i)}/devserver/stop`,{method:"POST"}),status:i=>W(`/sessions/${encodeURIComponent(i)}/devserver/status`)},getSecrets:()=>W("/secrets"),setSecret:(i,o)=>W("/secrets",{method:"POST",body:JSON.stringify({key:i,value:o})}),deleteSecret:i=>W(`/secrets/${encodeURIComponent(i)}`,{method:"DELETE"}),getMe:()=>W("/auth/me"),getGitHubAuthUrl:()=>W("/auth/github/url"),getGoogleAuthUrl:()=>W("/auth/google/url"),githubCallback:(i,o)=>W("/auth/github/callback",{method:"POST",body:JSON.stringify({code:i,state:o})}),googleCallback:(i,o,r)=>W("/auth/google/callback",{method:"POST",body:JSON.stringify({code:i,state:o,redirect_uri:r||`${window.location.origin}${window.location.pathname}`})})};class I1{constructor(o){Bn(this,"ws",null);Bn(this,"listeners",new Map);Bn(this,"reconnectTimer",null);Bn(this,"url");this.url=o||W1}connect(){var o;((o=this.ws)==null?void 0:o.readyState)!==WebSocket.OPEN&&(this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.emit("connected",{message:"WebSocket connected"})},this.ws.onmessage=r=>{try{const f=JSON.parse(r.data);this.emit(f.type,f.data||f)}catch{}},this.ws.onclose=()=>{this.emit("disconnected",{}),this.scheduleReconnect()},this.ws.onerror=()=>{var r;(r=this.ws)==null||r.close()})}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},3e3))}on(o,r){return this.listeners.has(o)||this.listeners.set(o,new Set),this.listeners.get(o).add(r),()=>{var f;return(f=this.listeners.get(o))==null?void 0:f.delete(r)}}emit(o,r){var f,d;(f=this.listeners.get(o))==null||f.forEach(h=>h(r)),(d=this.listeners.get("*"))==null||d.forEach(h=>h({type:o,data:r}))}send(o){var r;((r=this.ws)==null?void 0:r.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(o))}disconnect(){var o;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(o=this.ws)==null||o.close(),this.ws=null}}const Vf="pl_auth_token",kh=E.createContext({user:null,loading:!0,login:()=>{},logout:()=>{},isLocalMode:!0});function P1(i,o,r){o(!1),r({email:i.sub||i.email||"",name:i.name||"",avatar_url:i.avatar||"",authenticated:!0})}function tg({children:i}){const[o,r]=E.useState(null),[f,d]=E.useState(!0),[h,g]=E.useState(!0),_=Ff(),S=je();E.useEffect(()=>{let j=!1;async function w(){const Z=new URLSearchParams(window.location.search),Y=Z.get("token"),G=Z.get("code");if(Y)localStorage.setItem(Vf,Y),window.history.replaceState({},"",window.location.pathname);else if(G)try{const B=sessionStorage.getItem("pl_oauth_provider")||"github",F=sessionStorage.getItem("pl_oauth_state")||"";sessionStorage.removeItem("pl_oauth_state"),sessionStorage.removeItem("pl_oauth_provider");let K;if(B==="google"?K=await qa.googleCallback(G,F):K=await qa.githubCallback(G,F),!j){localStorage.setItem(Vf,K.token),window.history.replaceState({},"",window.location.pathname),g(!1),r({email:K.user.email,name:K.user.name,avatar_url:K.user.avatar_url,authenticated:!0}),d(!1);return}}catch{window.history.replaceState({},"",window.location.pathname)}try{const B=await qa.getMe();if(j)return;B.local_mode?(g(!0),r(null)):B.authenticated?P1(B,g,r):(g(!1),r(null))}catch{if(j)return;g(!0),r(null)}finally{j||d(!1)}}return w(),()=>{j=!0}},[]);const y=E.useCallback(j=>{j==="github"?qa.getGitHubAuthUrl().then(w=>{try{const Y=new URL(w.url).searchParams.get("state");Y&&(sessionStorage.setItem("pl_oauth_state",Y),sessionStorage.setItem("pl_oauth_provider","github"))}catch{}window.location.href=w.url}).catch(()=>{}):j==="google"&&qa.getGoogleAuthUrl().then(w=>{try{const Y=new URL(w.url).searchParams.get("state");Y&&(sessionStorage.setItem("pl_oauth_state",Y),sessionStorage.setItem("pl_oauth_provider","google"))}catch{}window.location.href=w.url}).catch(()=>{})},[]),M=E.useCallback(()=>{localStorage.removeItem(Vf),r(null),S.pathname!=="/login"&&_("/login",{replace:!0})},[_,S.pathname]),z=E.useMemo(()=>({user:o,loading:f,login:y,logout:M,isLocalMode:h}),[o,f,y,M,h]);return O.jsx(kh.Provider,{value:z,children:i})}function $h(){return E.useContext(kh)}const Th="pl_sidebar_collapsed",eg=[{to:"/",label:"Home",icon:N1},{to:"/projects",label:"Projects",icon:M1},{to:"/templates",label:"Templates",icon:U1}],lg=[{to:"/settings",label:"Settings",icon:Vh}];function ag(){const[i,o]=E.useState(typeof window<"u"?window.innerWidth<768:!1);return E.useEffect(()=>{const r=()=>o(window.innerWidth<768);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),i}function ng({wsConnected:i,version:o}){const r=ag(),f=je(),[d,h]=E.useState(!1),[g,_]=E.useState(()=>{try{return localStorage.getItem(Th)==="1"}catch{return!1}});E.useEffect(()=>{try{localStorage.setItem(Th,g?"1":"0")}catch{}},[g]),E.useEffect(()=>{r&&h(!1)},[f.pathname,r]);const S=r?d:!g,y=S?240:64,M=j=>["flex items-center gap-3 px-3 py-2 text-sm transition-colors rounded-[5px]",!S&&"justify-center",j?"bg-[#553DE9]/8 text-[#553DE9] font-medium border-l-2 border-[#553DE9]":"text-[#36342E] hover:bg-[#F8F4F0]"].filter(Boolean).join(" "),z=O.jsxs("aside",{className:"flex flex-col h-full border-r border-[#ECEAE3] bg-white transition-[width] duration-200",style:{width:y,minWidth:y},children:[O.jsxs("div",{className:"flex items-center justify-between px-4 h-14 border-b border-[#ECEAE3]",children:[S&&O.jsxs("div",{className:"flex flex-col",children:[O.jsx("span",{className:"font-heading text-lg font-bold leading-tight text-[#36342E]",children:"Purple Lab"}),O.jsx("span",{className:"text-xs text-[#6B6960]",children:"Powered by Loki"})]}),r?O.jsx("button",{type:"button","aria-label":d?"Close menu":"Open menu",title:d?"Close menu":"Open menu",onClick:()=>h(!d),className:"inline-flex items-center justify-center w-7 h-7 rounded-[3px] text-[#939084] hover:bg-[#F8F4F0] transition-colors",children:d?O.jsx(Kh,{size:16}):O.jsx(L1,{size:16})}):O.jsx("button",{type:"button","aria-label":g?"Expand sidebar":"Collapse sidebar",title:g?"Expand sidebar":"Collapse sidebar",onClick:()=>_(!g),className:"inline-flex items-center justify-center w-7 h-7 rounded-[3px] text-[#939084] hover:bg-[#F8F4F0] transition-colors",children:g?O.jsx(V1,{size:16}):O.jsx(Q1,{size:16})})]}),O.jsxs("nav",{className:"flex-1 px-2 py-3 flex flex-col gap-1","aria-label":"Main navigation",children:[eg.map(j=>O.jsxs(di,{to:j.to,end:j.to==="/",className:({isActive:w})=>M(w),title:S?void 0:j.label,children:[O.jsx(j.icon,{size:18}),S&&O.jsx("span",{children:j.label})]},j.to)),O.jsx("div",{className:"my-2 border-t border-[#ECEAE3]"}),lg.map(j=>O.jsxs(di,{to:j.to,className:({isActive:w})=>M(w),title:S?void 0:j.label,children:[O.jsx(j.icon,{size:18}),S&&O.jsx("span",{children:j.label})]},j.to))]}),O.jsxs("div",{className:"px-3 py-3 border-t border-[#ECEAE3] flex flex-col gap-2",children:[O.jsx(ug,{collapsed:!S}),O.jsxs("div",{className:["flex items-center gap-2 text-xs",!S&&"justify-center"].filter(Boolean).join(" "),children:[O.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${i?"bg-[#1FC5A8]":"bg-[#C45B5B]"}`}),S&&O.jsx("span",{className:"text-[#6B6960]",children:i?"Connected":"Disconnected"})]}),S&&o&&O.jsxs("span",{className:"text-xs text-[#6B6960]",children:["v",o]}),O.jsxs("a",{href:"https://www.autonomi.dev/docs",target:"_blank",rel:"noopener noreferrer",className:["flex items-center gap-2 text-xs text-[#6B6960] hover:text-[#36342E] transition-colors",!S&&"justify-center"].filter(Boolean).join(" "),title:S?void 0:"Documentation",children:[O.jsx(E1,{size:14}),S&&O.jsx("span",{children:"Docs"})]})]})]});return r&&d?O.jsxs(O.Fragment,{children:[O.jsx("div",{className:"fixed inset-0 z-40 bg-ink/20",onClick:()=>h(!1)}),O.jsx("div",{className:"fixed inset-y-0 left-0 z-50",children:z})]}):z}function ug({collapsed:i}){const{user:o,logout:r,isLocalMode:f}=$h(),[d,h]=E.useState(!1),g=E.useRef(null);return E.useEffect(()=>{function _(S){g.current&&!g.current.contains(S.target)&&h(!1)}if(d)return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[d]),f||!o?O.jsxs("div",{className:["flex items-center gap-2 text-xs",i&&"justify-center"].filter(Boolean).join(" "),title:i?"Local Mode":void 0,children:[O.jsx(G1,{size:14,className:"text-[#939084] flex-shrink-0"}),!i&&O.jsx("span",{className:"text-[#939084]",children:"Local Mode"})]}):O.jsxs("div",{className:"relative",ref:g,"data-testid":"user-section",children:[O.jsxs("button",{type:"button",onClick:()=>h(!d),className:["flex items-center gap-2 w-full text-left text-xs rounded-[3px] py-1 px-1 hover:bg-[#F8F4F0] transition-colors",i&&"justify-center"].filter(Boolean).join(" "),title:i?o.name||o.email:void 0,children:[o.avatar_url?O.jsx("img",{src:o.avatar_url,alt:"",className:"w-5 h-5 rounded-full flex-shrink-0"}):O.jsx("div",{className:"w-5 h-5 rounded-full bg-[#553DE9] flex items-center justify-center text-white text-[10px] font-bold flex-shrink-0",children:(o.name||o.email||"?")[0].toUpperCase()}),!i&&O.jsxs(O.Fragment,{children:[O.jsx("span",{className:"text-[#36342E] truncate flex-1",children:o.name||o.email}),O.jsx(T1,{size:12,className:`text-[#939084] transition-transform ${d?"":"rotate-180"}`})]})]}),d&&O.jsxs("div",{className:"absolute bottom-full left-0 mb-1 w-48 bg-white border border-[#ECEAE3] rounded-lg shadow-lg py-1 z-50",children:[O.jsxs("div",{className:"px-3 py-2 border-b border-[#ECEAE3]",children:[O.jsx("p",{className:"text-xs font-medium text-[#36342E] truncate",children:o.name}),O.jsx("p",{className:"text-xs text-[#939084] truncate",children:o.email})]}),O.jsxs(di,{to:"/settings",onClick:()=>h(!1),className:"flex items-center gap-2 px-3 py-2 text-xs text-[#36342E] hover:bg-[#F8F4F0] transition-colors",children:[O.jsx(Vh,{size:14}),"Settings"]}),O.jsxs("button",{type:"button",onClick:()=>{h(!1),r()},className:"flex items-center gap-2 px-3 py-2 text-xs text-[#C45B5B] hover:bg-[#F8F4F0] transition-colors w-full text-left",children:[O.jsx(H1,{size:14}),"Sign out"]})]})]})}const zh="pl_onboarding_complete",wn=[{icon:R1,title:"Write your PRD",description:"Describe what you want to build, or choose a template to get started quickly."},{icon:k1,title:"Use the terminal",description:"Run commands directly in the integrated terminal to install dependencies or debug."},{icon:_1,title:"Preview in real-time",description:"Switch to the Preview tab to see your app running with live reload."},{icon:Y1,title:"Iterate with AI Chat",description:"Ask the AI to modify, fix, or explain your code in the chat panel."}];function ig(){const[i,o]=E.useState(!1),[r,f]=E.useState(0);E.useEffect(()=>{try{localStorage.getItem(zh)!=="1"&&o(!0)}catch{}},[]);const d=()=>{o(!1);try{localStorage.setItem(zh,"1")}catch{}},h=()=>{r<wn.length-1?f(r+1):d()};if(!i)return null;const g=wn[r],_=g.icon;return O.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/30",children:O.jsxs("div",{className:"bg-card rounded-card shadow-card-hover border border-border w-full max-w-sm mx-4",children:[O.jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-2",children:[O.jsxs("span",{className:"text-[11px] font-mono text-muted-accessible",children:[r+1," / ",wn.length]}),O.jsx("button",{onClick:d,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",title:"Skip onboarding",children:O.jsx(Kh,{size:14})})]}),O.jsxs("div",{className:"px-5 pb-4 text-center",children:[O.jsx("div",{className:"w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center mx-auto mb-4",children:O.jsx(_,{size:24,className:"text-primary"})}),O.jsx("h3",{className:"text-sm font-heading font-bold text-ink mb-1",children:g.title}),O.jsx("p",{className:"text-xs text-muted-accessible leading-relaxed",children:g.description})]}),O.jsx("div",{className:"flex items-center justify-center gap-1.5 pb-4",children:wn.map((S,y)=>O.jsx("div",{className:`w-1.5 h-1.5 rounded-full transition-colors ${y===r?"bg-primary":"bg-border"}`},y))}),O.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-border",children:[O.jsx("button",{onClick:d,className:"text-xs text-muted hover:text-ink transition-colors",children:"Skip"}),O.jsx("button",{onClick:h,className:"inline-flex items-center gap-1.5 px-4 py-1.5 text-xs font-medium rounded-btn bg-primary text-white hover:bg-primary-hover transition-colors",children:r<wn.length-1?O.jsxs(O.Fragment,{children:["Next",O.jsx(S1,{size:12})]}):"Get Started"})]})]})})}function cg(i){const[o,r]=E.useState(!1),f=E.useRef(null),d=E.useRef(i);E.useEffect(()=>{d.current=i},[i]),E.useEffect(()=>{const g=new I1;return f.current=g,g.on("connected",()=>r(!0)),g.on("disconnected",()=>{r(!1),d.current&&d.current(null)}),g.on("state_update",_=>{d.current&&_&&typeof _=="object"&&d.current(_)}),g.connect(),()=>{g.disconnect(),f.current=null}},[]);const h=E.useCallback((g,_)=>{var S;return((S=f.current)==null?void 0:S.on(g,_))||(()=>{})},[]);return{connected:o,subscribe:h}}function fg(){const[i,o]=E.useState(""),{connected:r}=cg(()=>{});return E.useEffect(()=>{qa.getStatus().then(f=>{o(f.version||"")}).catch(()=>{})},[]),O.jsxs("div",{className:"flex h-screen bg-[#FAF9F6]",children:[O.jsx(ig,{}),O.jsx("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:absolute focus:z-50 focus:top-2 focus:left-2 focus:px-4 focus:py-2 focus:bg-white focus:text-[#553DE9] focus:rounded-[3px] focus:shadow-card",children:"Skip to main content"}),O.jsx(ng,{wsConnected:r,version:i}),O.jsx("main",{id:"main-content",className:"flex-1 overflow-auto",children:O.jsx(Cv,{})})]})}function _h({children:i}){const{user:o,loading:r,isLocalMode:f}=$h();return r?O.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center text-[#6B6960] text-sm",children:"Loading..."}):f?O.jsx(O.Fragment,{children:i}):o?O.jsx(O.Fragment,{children:i}):O.jsx(Mv,{to:"/login",replace:!0})}function hi({variant:i="text",width:o,height:r,className:f=""}){const d="animate-pulse bg-[#ECEAE3]/60 rounded";if(i==="circle"){const h=o||"2rem";return O.jsx("div",{className:`${d} rounded-full flex-shrink-0 ${f}`,style:{width:h,height:h}})}return i==="block"?O.jsx("div",{className:`${d} rounded-btn ${f}`,style:{width:o||"100%",height:r||"4rem"}}):O.jsx("div",{className:`${d} rounded-btn ${f}`,style:{width:o||"100%",height:r||"0.75rem"}})}function bg(){return O.jsx("div",{className:"p-4 space-y-3",children:[...Array(12)].map((i,o)=>O.jsxs("div",{className:"flex items-center gap-3",children:[O.jsx(hi,{variant:"text",width:"1.5rem",height:"10px",className:"flex-shrink-0 opacity-40"}),O.jsx(hi,{variant:"text",width:`${20+Math.random()*60}%`,height:"10px"})]},o))})}const og=E.lazy(()=>Pl(()=>import("./HomePage-B8kMCXMB.js"),__vite__mapDeps([0,1,2,3]))),sg=E.lazy(()=>Pl(()=>import("./ProjectPage-C-k0iy0i.js"),__vite__mapDeps([4,3,5,2,6,7,8]))),rg=E.lazy(()=>Pl(()=>import("./ProjectsPage-jys_pHzp.js"),__vite__mapDeps([9,5,10,1,2]))),dg=E.lazy(()=>Pl(()=>import("./TemplatesPage-COnhb_Wq.js"),__vite__mapDeps([11,10,1,2]))),hg=E.lazy(()=>Pl(()=>import("./SettingsPage-Cz_RXr82.js"),__vite__mapDeps([12,10,7]))),mg=E.lazy(()=>Pl(()=>import("./LoginPage-D9lCyiqM.js"),[])),yg=E.lazy(()=>Pl(()=>import("./NotFoundPage-DzeZ0uQ6.js"),__vite__mapDeps([13,6])));function Il(){return O.jsxs("div",{className:"h-screen bg-[#FAF9F6] flex flex-col items-center justify-center gap-3",children:[O.jsx(hi,{variant:"block",width:"200px",height:"24px"}),O.jsx(hi,{variant:"text",width:"140px",height:"12px",className:"opacity-50"})]})}function vg(){return O.jsx(tg,{children:O.jsxs(Dv,{children:[O.jsx(il,{path:"/login",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(mg,{})})}),O.jsx(il,{path:"/project/:sessionId",element:O.jsx(_h,{children:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(sg,{})})})}),O.jsxs(il,{element:O.jsx(_h,{children:O.jsx(fg,{})}),children:[O.jsx(il,{path:"/",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(og,{})})}),O.jsx(il,{path:"/projects",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(rg,{})})}),O.jsx(il,{path:"/templates",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(dg,{})})}),O.jsx(il,{path:"/settings",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(hg,{})})}),O.jsx(il,{path:"*",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(yg,{})})})]})]})})}N0.createRoot(document.getElementById("root")).render(O.jsx(E.StrictMode,{children:O.jsx(l1,{children:O.jsx(vg,{})})}));export{S1 as A,E1 as B,_1 as E,R1 as F,N1 as H,Xh as L,Y1 as M,Vh as S,k1 as T,pg as W,Kh as X,qa as a,cg as b,Jt as c,bg as d,hi as e,Sg as f,$h as g,O as j,E as r,Ff as u};
186
+ */const $1=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Kh=Jt("x",$1),Jh=`${window.location.origin}/api`,W1=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;function F1(){const i={"Content-Type":"application/json"};try{const o=localStorage.getItem("pl_auth_token");o&&(i.Authorization=`Bearer ${o}`)}catch{}return i}async function W(i,o){const r=await fetch(`${Jh}${i}`,{...o,headers:{...F1(),...o==null?void 0:o.headers}});if(!r.ok){const f=await r.text().catch(()=>"");throw new Error(`API error ${r.status}: ${r.statusText}${f?` - ${f}`:""}`)}return r.json()}const qa={startSession:i=>W("/session/start",{method:"POST",body:JSON.stringify(i)}),stopSession:()=>W("/session/stop",{method:"POST"}),pauseSession:()=>W("/session/pause",{method:"POST"}),resumeSession:()=>W("/session/resume",{method:"POST"}),getPrdPrefill:()=>W("/session/prd-prefill"),getStatus:()=>W("/session/status"),getAgents:()=>W("/session/agents"),getLogs:(i=200)=>W(`/session/logs?lines=${i}`),getMemorySummary:()=>W("/session/memory"),getChecklist:()=>W("/session/checklist"),getFiles:()=>W("/session/files"),getFileContent:i=>W(`/session/files/content?path=${encodeURIComponent(i)}`),getSessionFileContent:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/file?path=${encodeURIComponent(o)}`),getTemplates:()=>W("/templates"),getTemplateContent:i=>W(`/templates/${encodeURIComponent(i)}`),planSession:(i,o)=>W("/session/plan",{method:"POST",body:JSON.stringify({prd:i,provider:o})}),generateReport:(i="markdown")=>W("/session/report",{method:"POST",body:JSON.stringify({format:i})}),shareSession:()=>W("/session/share",{method:"POST"}),getCurrentProvider:()=>W("/provider/current"),setProvider:i=>W("/provider/set",{method:"POST",body:JSON.stringify({provider:i})}),getMetrics:()=>W("/session/metrics"),getSessionsHistory:()=>W("/sessions/history"),getSessionDetail:i=>W(`/sessions/${encodeURIComponent(i)}`),onboardRepo:i=>W("/session/onboard",{method:"POST",body:JSON.stringify({path:i})}),saveSessionFile:(i,o,r)=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"PUT",body:JSON.stringify({path:o,content:r})}),createSessionFile:(i,o,r="")=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"POST",body:JSON.stringify({path:o,content:r})}),deleteSessionFile:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/file`,{method:"DELETE",body:JSON.stringify({path:o})}),createSessionDirectory:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/directory`,{method:"POST",body:JSON.stringify({path:o})}),reviewProject:i=>W(`/sessions/${encodeURIComponent(i)}/review`,{method:"POST"}),testProject:i=>W(`/sessions/${encodeURIComponent(i)}/test`,{method:"POST"}),explainProject:i=>W(`/sessions/${encodeURIComponent(i)}/explain`,{method:"POST"}),exportProject:i=>W(`/sessions/${encodeURIComponent(i)}/export`,{method:"POST"}),chatMessage:(i,o,r="quick")=>W(`/sessions/${encodeURIComponent(i)}/chat`,{method:"POST",body:JSON.stringify({message:o,mode:r})}),chatStart:(i,o,r="quick")=>W(`/sessions/${encodeURIComponent(i)}/chat`,{method:"POST",body:JSON.stringify({message:o,mode:r})}),chatPoll:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}`),chatStreamUrl:(i,o)=>`${Jh}/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}/stream`,chatCancel:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/chat/${encodeURIComponent(o)}/cancel`,{method:"POST"}),getPreviewInfo:i=>W(`/sessions/${encodeURIComponent(i)}/preview-info`),devserver:{start:(i,o)=>W(`/sessions/${encodeURIComponent(i)}/devserver/start`,{method:"POST",body:JSON.stringify({command:o||null})}),stop:i=>W(`/sessions/${encodeURIComponent(i)}/devserver/stop`,{method:"POST"}),status:i=>W(`/sessions/${encodeURIComponent(i)}/devserver/status`)},getSecrets:()=>W("/secrets"),setSecret:(i,o)=>W("/secrets",{method:"POST",body:JSON.stringify({key:i,value:o})}),deleteSecret:i=>W(`/secrets/${encodeURIComponent(i)}`,{method:"DELETE"}),getMe:()=>W("/auth/me"),getGitHubAuthUrl:()=>W("/auth/github/url"),getGoogleAuthUrl:()=>W("/auth/google/url"),githubCallback:(i,o)=>W("/auth/github/callback",{method:"POST",body:JSON.stringify({code:i,state:o})}),googleCallback:(i,o,r)=>W("/auth/google/callback",{method:"POST",body:JSON.stringify({code:i,state:o,redirect_uri:r||`${window.location.origin}${window.location.pathname}`})})};class I1{constructor(o){Bn(this,"ws",null);Bn(this,"listeners",new Map);Bn(this,"reconnectTimer",null);Bn(this,"url");this.url=o||W1}connect(){var o;((o=this.ws)==null?void 0:o.readyState)!==WebSocket.OPEN&&(this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.emit("connected",{message:"WebSocket connected"})},this.ws.onmessage=r=>{try{const f=JSON.parse(r.data);this.emit(f.type,f.data||f)}catch{}},this.ws.onclose=()=>{this.emit("disconnected",{}),this.scheduleReconnect()},this.ws.onerror=()=>{var r;(r=this.ws)==null||r.close()})}scheduleReconnect(){this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},3e3))}on(o,r){return this.listeners.has(o)||this.listeners.set(o,new Set),this.listeners.get(o).add(r),()=>{var f;return(f=this.listeners.get(o))==null?void 0:f.delete(r)}}emit(o,r){var f,d;(f=this.listeners.get(o))==null||f.forEach(h=>h(r)),(d=this.listeners.get("*"))==null||d.forEach(h=>h({type:o,data:r}))}send(o){var r;((r=this.ws)==null?void 0:r.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(o))}disconnect(){var o;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(o=this.ws)==null||o.close(),this.ws=null}}const Vf="pl_auth_token",kh=E.createContext({user:null,loading:!0,login:()=>{},logout:()=>{},isLocalMode:!0});function P1(i,o,r){o(!1),r({email:i.sub||i.email||"",name:i.name||"",avatar_url:i.avatar||"",authenticated:!0})}function tg({children:i}){const[o,r]=E.useState(null),[f,d]=E.useState(!0),[h,g]=E.useState(!0),_=Ff(),S=je();E.useEffect(()=>{let j=!1;async function w(){const Z=new URLSearchParams(window.location.search),Y=Z.get("token"),G=Z.get("code");if(Y)localStorage.setItem(Vf,Y),window.history.replaceState({},"",window.location.pathname);else if(G)try{const B=sessionStorage.getItem("pl_oauth_provider")||"github",F=sessionStorage.getItem("pl_oauth_state")||"";sessionStorage.removeItem("pl_oauth_state"),sessionStorage.removeItem("pl_oauth_provider");let K;if(B==="google"?K=await qa.googleCallback(G,F):K=await qa.githubCallback(G,F),!j){localStorage.setItem(Vf,K.token),window.history.replaceState({},"",window.location.pathname),g(!1),r({email:K.user.email,name:K.user.name,avatar_url:K.user.avatar_url,authenticated:!0}),d(!1);return}}catch{window.history.replaceState({},"",window.location.pathname)}try{const B=await qa.getMe();if(j)return;B.local_mode?(g(!0),r(null)):B.authenticated?P1(B,g,r):(g(!1),r(null))}catch{if(j)return;g(!0),r(null)}finally{j||d(!1)}}return w(),()=>{j=!0}},[]);const y=E.useCallback(j=>{j==="github"?qa.getGitHubAuthUrl().then(w=>{try{const Y=new URL(w.url).searchParams.get("state");Y&&(sessionStorage.setItem("pl_oauth_state",Y),sessionStorage.setItem("pl_oauth_provider","github"))}catch{}window.location.href=w.url}).catch(()=>{}):j==="google"&&qa.getGoogleAuthUrl().then(w=>{try{const Y=new URL(w.url).searchParams.get("state");Y&&(sessionStorage.setItem("pl_oauth_state",Y),sessionStorage.setItem("pl_oauth_provider","google"))}catch{}window.location.href=w.url}).catch(()=>{})},[]),M=E.useCallback(()=>{localStorage.removeItem(Vf),r(null),S.pathname!=="/login"&&_("/login",{replace:!0})},[_,S.pathname]),z=E.useMemo(()=>({user:o,loading:f,login:y,logout:M,isLocalMode:h}),[o,f,y,M,h]);return O.jsx(kh.Provider,{value:z,children:i})}function $h(){return E.useContext(kh)}const Th="pl_sidebar_collapsed",eg=[{to:"/",label:"Home",icon:N1},{to:"/projects",label:"Projects",icon:M1},{to:"/templates",label:"Templates",icon:U1}],lg=[{to:"/settings",label:"Settings",icon:Vh}];function ag(){const[i,o]=E.useState(typeof window<"u"?window.innerWidth<768:!1);return E.useEffect(()=>{const r=()=>o(window.innerWidth<768);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),i}function ng({wsConnected:i,version:o}){const r=ag(),f=je(),[d,h]=E.useState(!1),[g,_]=E.useState(()=>{try{return localStorage.getItem(Th)==="1"}catch{return!1}});E.useEffect(()=>{try{localStorage.setItem(Th,g?"1":"0")}catch{}},[g]),E.useEffect(()=>{r&&h(!1)},[f.pathname,r]);const S=r?d:!g,y=S?240:64,M=j=>["flex items-center gap-3 px-3 py-2 text-sm transition-colors rounded-[5px]",!S&&"justify-center",j?"bg-[#553DE9]/8 text-[#553DE9] font-medium border-l-2 border-[#553DE9]":"text-[#36342E] hover:bg-[#F8F4F0]"].filter(Boolean).join(" "),z=O.jsxs("aside",{className:"flex flex-col h-full border-r border-[#ECEAE3] bg-white transition-[width] duration-200",style:{width:y,minWidth:y},children:[O.jsxs("div",{className:"flex items-center justify-between px-4 h-14 border-b border-[#ECEAE3]",children:[S&&O.jsxs("div",{className:"flex flex-col",children:[O.jsx("span",{className:"font-heading text-lg font-bold leading-tight text-[#36342E]",children:"Purple Lab"}),O.jsx("span",{className:"text-xs text-[#6B6960]",children:"Powered by Loki"})]}),r?O.jsx("button",{type:"button","aria-label":d?"Close menu":"Open menu",title:d?"Close menu":"Open menu",onClick:()=>h(!d),className:"inline-flex items-center justify-center w-7 h-7 rounded-[3px] text-[#939084] hover:bg-[#F8F4F0] transition-colors",children:d?O.jsx(Kh,{size:16}):O.jsx(L1,{size:16})}):O.jsx("button",{type:"button","aria-label":g?"Expand sidebar":"Collapse sidebar",title:g?"Expand sidebar":"Collapse sidebar",onClick:()=>_(!g),className:"inline-flex items-center justify-center w-7 h-7 rounded-[3px] text-[#939084] hover:bg-[#F8F4F0] transition-colors",children:g?O.jsx(V1,{size:16}):O.jsx(Q1,{size:16})})]}),O.jsxs("nav",{className:"flex-1 px-2 py-3 flex flex-col gap-1","aria-label":"Main navigation",children:[eg.map(j=>O.jsxs(di,{to:j.to,end:j.to==="/",className:({isActive:w})=>M(w),title:S?void 0:j.label,children:[O.jsx(j.icon,{size:18}),S&&O.jsx("span",{children:j.label})]},j.to)),O.jsx("div",{className:"my-2 border-t border-[#ECEAE3]"}),lg.map(j=>O.jsxs(di,{to:j.to,className:({isActive:w})=>M(w),title:S?void 0:j.label,children:[O.jsx(j.icon,{size:18}),S&&O.jsx("span",{children:j.label})]},j.to))]}),O.jsxs("div",{className:"px-3 py-3 border-t border-[#ECEAE3] flex flex-col gap-2",children:[O.jsx(ug,{collapsed:!S}),O.jsxs("div",{className:["flex items-center gap-2 text-xs",!S&&"justify-center"].filter(Boolean).join(" "),children:[O.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${i?"bg-[#1FC5A8]":"bg-[#C45B5B]"}`}),S&&O.jsx("span",{className:"text-[#6B6960]",children:i?"Connected":"Disconnected"})]}),S&&o&&O.jsxs("span",{className:"text-xs text-[#6B6960]",children:["v",o]}),O.jsxs("a",{href:"https://www.autonomi.dev/docs",target:"_blank",rel:"noopener noreferrer",className:["flex items-center gap-2 text-xs text-[#6B6960] hover:text-[#36342E] transition-colors",!S&&"justify-center"].filter(Boolean).join(" "),title:S?void 0:"Documentation",children:[O.jsx(E1,{size:14}),S&&O.jsx("span",{children:"Docs"})]})]})]});return r&&d?O.jsxs(O.Fragment,{children:[O.jsx("div",{className:"fixed inset-0 z-40 bg-ink/20",onClick:()=>h(!1)}),O.jsx("div",{className:"fixed inset-y-0 left-0 z-50",children:z})]}):z}function ug({collapsed:i}){const{user:o,logout:r,isLocalMode:f}=$h(),[d,h]=E.useState(!1),g=E.useRef(null);return E.useEffect(()=>{function _(S){g.current&&!g.current.contains(S.target)&&h(!1)}if(d)return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[d]),f||!o?O.jsxs("div",{className:["flex items-center gap-2 text-xs",i&&"justify-center"].filter(Boolean).join(" "),title:i?"Local Mode":void 0,children:[O.jsx(G1,{size:14,className:"text-[#939084] flex-shrink-0"}),!i&&O.jsx("span",{className:"text-[#939084]",children:"Local Mode"})]}):O.jsxs("div",{className:"relative",ref:g,"data-testid":"user-section",children:[O.jsxs("button",{type:"button",onClick:()=>h(!d),className:["flex items-center gap-2 w-full text-left text-xs rounded-[3px] py-1 px-1 hover:bg-[#F8F4F0] transition-colors",i&&"justify-center"].filter(Boolean).join(" "),title:i?o.name||o.email:void 0,children:[o.avatar_url?O.jsx("img",{src:o.avatar_url,alt:"",className:"w-5 h-5 rounded-full flex-shrink-0"}):O.jsx("div",{className:"w-5 h-5 rounded-full bg-[#553DE9] flex items-center justify-center text-white text-[10px] font-bold flex-shrink-0",children:(o.name||o.email||"?")[0].toUpperCase()}),!i&&O.jsxs(O.Fragment,{children:[O.jsx("span",{className:"text-[#36342E] truncate flex-1",children:o.name||o.email}),O.jsx(T1,{size:12,className:`text-[#939084] transition-transform ${d?"":"rotate-180"}`})]})]}),d&&O.jsxs("div",{className:"absolute bottom-full left-0 mb-1 w-48 bg-white border border-[#ECEAE3] rounded-lg shadow-lg py-1 z-50",children:[O.jsxs("div",{className:"px-3 py-2 border-b border-[#ECEAE3]",children:[O.jsx("p",{className:"text-xs font-medium text-[#36342E] truncate",children:o.name}),O.jsx("p",{className:"text-xs text-[#939084] truncate",children:o.email})]}),O.jsxs(di,{to:"/settings",onClick:()=>h(!1),className:"flex items-center gap-2 px-3 py-2 text-xs text-[#36342E] hover:bg-[#F8F4F0] transition-colors",children:[O.jsx(Vh,{size:14}),"Settings"]}),O.jsxs("button",{type:"button",onClick:()=>{h(!1),r()},className:"flex items-center gap-2 px-3 py-2 text-xs text-[#C45B5B] hover:bg-[#F8F4F0] transition-colors w-full text-left",children:[O.jsx(H1,{size:14}),"Sign out"]})]})]})}const zh="pl_onboarding_complete",wn=[{icon:R1,title:"Write your PRD",description:"Describe what you want to build, or choose a template to get started quickly."},{icon:k1,title:"Use the terminal",description:"Run commands directly in the integrated terminal to install dependencies or debug."},{icon:_1,title:"Preview in real-time",description:"Switch to the Preview tab to see your app running with live reload."},{icon:Y1,title:"Iterate with AI Chat",description:"Ask the AI to modify, fix, or explain your code in the chat panel."}];function ig(){const[i,o]=E.useState(!1),[r,f]=E.useState(0);E.useEffect(()=>{try{localStorage.getItem(zh)!=="1"&&o(!0)}catch{}},[]);const d=()=>{o(!1);try{localStorage.setItem(zh,"1")}catch{}},h=()=>{r<wn.length-1?f(r+1):d()};if(!i)return null;const g=wn[r],_=g.icon;return O.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-ink/30",children:O.jsxs("div",{className:"bg-card rounded-card shadow-card-hover border border-border w-full max-w-sm mx-4",children:[O.jsxs("div",{className:"flex items-center justify-between px-5 pt-5 pb-2",children:[O.jsxs("span",{className:"text-[11px] font-mono text-muted-accessible",children:[r+1," / ",wn.length]}),O.jsx("button",{onClick:d,className:"text-muted hover:text-ink transition-colors p-1 rounded-btn hover:bg-hover",title:"Skip onboarding",children:O.jsx(Kh,{size:14})})]}),O.jsxs("div",{className:"px-5 pb-4 text-center",children:[O.jsx("div",{className:"w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center mx-auto mb-4",children:O.jsx(_,{size:24,className:"text-primary"})}),O.jsx("h3",{className:"text-sm font-heading font-bold text-ink mb-1",children:g.title}),O.jsx("p",{className:"text-xs text-muted-accessible leading-relaxed",children:g.description})]}),O.jsx("div",{className:"flex items-center justify-center gap-1.5 pb-4",children:wn.map((S,y)=>O.jsx("div",{className:`w-1.5 h-1.5 rounded-full transition-colors ${y===r?"bg-primary":"bg-border"}`},y))}),O.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-border",children:[O.jsx("button",{onClick:d,className:"text-xs text-muted hover:text-ink transition-colors",children:"Skip"}),O.jsx("button",{onClick:h,className:"inline-flex items-center gap-1.5 px-4 py-1.5 text-xs font-medium rounded-btn bg-primary text-white hover:bg-primary-hover transition-colors",children:r<wn.length-1?O.jsxs(O.Fragment,{children:["Next",O.jsx(S1,{size:12})]}):"Get Started"})]})]})})}function cg(i){const[o,r]=E.useState(!1),f=E.useRef(null),d=E.useRef(i);E.useEffect(()=>{d.current=i},[i]),E.useEffect(()=>{const g=new I1;return f.current=g,g.on("connected",()=>r(!0)),g.on("disconnected",()=>{r(!1),d.current&&d.current(null)}),g.on("state_update",_=>{d.current&&_&&typeof _=="object"&&d.current(_)}),g.connect(),()=>{g.disconnect(),f.current=null}},[]);const h=E.useCallback((g,_)=>{var S;return((S=f.current)==null?void 0:S.on(g,_))||(()=>{})},[]);return{connected:o,subscribe:h}}function fg(){const[i,o]=E.useState(""),{connected:r}=cg(()=>{});return E.useEffect(()=>{qa.getStatus().then(f=>{o(f.version||"")}).catch(()=>{})},[]),O.jsxs("div",{className:"flex h-screen bg-[#FAF9F6]",children:[O.jsx(ig,{}),O.jsx("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:absolute focus:z-50 focus:top-2 focus:left-2 focus:px-4 focus:py-2 focus:bg-white focus:text-[#553DE9] focus:rounded-[3px] focus:shadow-card",children:"Skip to main content"}),O.jsx(ng,{wsConnected:r,version:i}),O.jsx("main",{id:"main-content",className:"flex-1 overflow-auto",children:O.jsx(Cv,{})})]})}function _h({children:i}){const{user:o,loading:r,isLocalMode:f}=$h();return r?O.jsx("div",{className:"h-screen bg-[#FAF9F6] flex items-center justify-center text-[#6B6960] text-sm",children:"Loading..."}):f?O.jsx(O.Fragment,{children:i}):o?O.jsx(O.Fragment,{children:i}):O.jsx(Mv,{to:"/login",replace:!0})}function hi({variant:i="text",width:o,height:r,className:f=""}){const d="animate-pulse bg-[#ECEAE3]/60 rounded";if(i==="circle"){const h=o||"2rem";return O.jsx("div",{className:`${d} rounded-full flex-shrink-0 ${f}`,style:{width:h,height:h}})}return i==="block"?O.jsx("div",{className:`${d} rounded-btn ${f}`,style:{width:o||"100%",height:r||"4rem"}}):O.jsx("div",{className:`${d} rounded-btn ${f}`,style:{width:o||"100%",height:r||"0.75rem"}})}function bg(){return O.jsx("div",{className:"p-4 space-y-3",children:[...Array(12)].map((i,o)=>O.jsxs("div",{className:"flex items-center gap-3",children:[O.jsx(hi,{variant:"text",width:"1.5rem",height:"10px",className:"flex-shrink-0 opacity-40"}),O.jsx(hi,{variant:"text",width:`${20+Math.random()*60}%`,height:"10px"})]},o))})}const og=E.lazy(()=>Pl(()=>import("./HomePage-BrwjWs5_.js"),__vite__mapDeps([0,1,2,3]))),sg=E.lazy(()=>Pl(()=>import("./ProjectPage-CNuYm1A5.js"),__vite__mapDeps([4,3,5,2,6,7,8]))),rg=E.lazy(()=>Pl(()=>import("./ProjectsPage-uJimVYlj.js"),__vite__mapDeps([9,5,10,1,2]))),dg=E.lazy(()=>Pl(()=>import("./TemplatesPage-_MJc-qGU.js"),__vite__mapDeps([11,10,1,2]))),hg=E.lazy(()=>Pl(()=>import("./SettingsPage-BiSUXmC2.js"),__vite__mapDeps([12,10,7]))),mg=E.lazy(()=>Pl(()=>import("./LoginPage-KBUVD4pE.js"),[])),yg=E.lazy(()=>Pl(()=>import("./NotFoundPage-CDzHJO08.js"),__vite__mapDeps([13,6])));function Il(){return O.jsxs("div",{className:"h-screen bg-[#FAF9F6] flex flex-col items-center justify-center gap-3",children:[O.jsx(hi,{variant:"block",width:"200px",height:"24px"}),O.jsx(hi,{variant:"text",width:"140px",height:"12px",className:"opacity-50"})]})}function vg(){return O.jsx(tg,{children:O.jsxs(Dv,{children:[O.jsx(il,{path:"/login",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(mg,{})})}),O.jsx(il,{path:"/project/:sessionId",element:O.jsx(_h,{children:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(sg,{})})})}),O.jsxs(il,{element:O.jsx(_h,{children:O.jsx(fg,{})}),children:[O.jsx(il,{path:"/",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(og,{})})}),O.jsx(il,{path:"/projects",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(rg,{})})}),O.jsx(il,{path:"/templates",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(dg,{})})}),O.jsx(il,{path:"/settings",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(hg,{})})}),O.jsx(il,{path:"*",element:O.jsx(E.Suspense,{fallback:O.jsx(Il,{}),children:O.jsx(yg,{})})})]})]})})}N0.createRoot(document.getElementById("root")).render(O.jsx(E.StrictMode,{children:O.jsx(l1,{children:O.jsx(vg,{})})}));export{S1 as A,E1 as B,_1 as E,R1 as F,N1 as H,Xh as L,Y1 as M,Vh as S,k1 as T,pg as W,Kh as X,qa as a,cg as b,Jt as c,bg as d,hi as e,Sg as f,$h as g,O as j,E as r,Ff as u};
@@ -8,7 +8,7 @@
8
8
  <link rel="preconnect" href="https://fonts.googleapis.com">
9
9
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
10
  <link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
11
- <script type="module" crossorigin src="/assets/index-B8Eg1YHL.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-1UyN_URb.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-UNfgZjJl.css">
13
13
  </head>
14
14
  <body class="bg-background text-ink font-sans antialiased">