loki-mode 6.52.0 → 6.53.0

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 (23) 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-btjJpcIR.js → Badge-CnWBUi7C.js} +1 -1
  8. package/web-app/dist/assets/{Button-al3e4s_k.js → Button-5ThWFbkO.js} +1 -1
  9. package/web-app/dist/assets/{Card-Dy53Fy1C.js → Card-CcTmaOCN.js} +1 -1
  10. package/web-app/dist/assets/{HomePage-CpxX59f6.js → HomePage-Dx4Ae0hu.js} +1 -1
  11. package/web-app/dist/assets/{LoginPage-C4U4jQQ1.js → LoginPage-CRffqZNo.js} +1 -1
  12. package/web-app/dist/assets/{NotFoundPage-C-jR50AT.js → NotFoundPage-B1QZ92yR.js} +1 -1
  13. package/web-app/dist/assets/{ProjectPage-nrlfDm3r.js → ProjectPage-BVnDGxXk.js} +6 -5
  14. package/web-app/dist/assets/{ProjectsPage-CswR-Imw.js → ProjectsPage-2Fi6cKB-.js} +1 -1
  15. package/web-app/dist/assets/{SettingsPage-DyeqtdDr.js → SettingsPage-DOzGoyLv.js} +1 -1
  16. package/web-app/dist/assets/{TemplatesPage-CzVB6kTH.js → TemplatesPage-B-f1Gfbg.js} +1 -1
  17. package/web-app/dist/assets/{TerminalOutput-DCP_fS6c.js → TerminalOutput-DrKIbiB8.js} +1 -1
  18. package/web-app/dist/assets/{arrow-left-5SrcW4Rm.js → arrow-left-CFG0TEkb.js} +1 -1
  19. package/web-app/dist/assets/{clock-DLN9xqq3.js → clock-C-GPrW5k.js} +1 -1
  20. package/web-app/dist/assets/{external-link-C04MOXed.js → external-link-ujbkNBY4.js} +1 -1
  21. package/web-app/dist/assets/{index-BlkhGr5c.js → index-B8gGcUMo.js} +2 -2
  22. package/web-app/dist/index.html +1 -1
  23. package/web-app/server.py +34 -14
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.52.0
6
+ # Loki Mode v6.53.0
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.52.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
270
+ **v6.53.0 | [Autonomi](https://www.autonomi.dev/) flagship product | ~260 lines core**
package/VERSION CHANGED
@@ -1 +1 @@
1
- 6.52.0
1
+ 6.53.0
@@ -7,7 +7,7 @@ Modules:
7
7
  control: Session control API (start/stop/pause/resume)
8
8
  """
9
9
 
10
- __version__ = "6.52.0"
10
+ __version__ = "6.53.0"
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.52.0
5
+ **Version:** v6.53.0
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.52.0'
60
+ __version__ = '6.53.0'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loki-mode",
3
- "version": "6.52.0",
3
+ "version": "6.53.0",
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-BlkhGr5c.js";import{C as g,a as p}from"./clock-DLN9xqq3.js";/**
1
+ import{c as m,r,j as e}from"./index-B8gGcUMo.js";import{C as g,a as p}from"./clock-C-GPrW5k.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-BlkhGr5c.js";/**
1
+ import{c as p,r as u,j as e}from"./index-B8gGcUMo.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-BlkhGr5c.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-B8gGcUMo.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-BlkhGr5c.js";import{u as I,B as je}from"./Badge-btjJpcIR.js";import{P as ve,a as Ne,S as ye,E,T as we}from"./TerminalOutput-DCP_fS6c.js";import"./clock-DLN9xqq3.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 n,a as h,u as be,b as ge}from"./index-B8gGcUMo.js";import{u as I,B as je}from"./Badge-CnWBUi7C.js";import{P as ve,a as Ne,S as ye,E,T as we}from"./TerminalOutput-DrKIbiB8.js";import"./clock-C-GPrW5k.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}
2
2
 
3
3
  ## Overview
4
4
 
@@ -1 +1 @@
1
- import{g as r,u as o,r as c,j as e}from"./index-BlkhGr5c.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-B8gGcUMo.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-BlkhGr5c.js";import{A as o}from"./arrow-left-5SrcW4Rm.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-B8gGcUMo.js";import{A as o}from"./arrow-left-CFG0TEkb.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-BlkhGr5c.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-DCP_fS6c.js";import{B as Ft,P as Tl}from"./Button-al3e4s_k.js";import{C as Al,a as zl}from"./clock-DLN9xqq3.js";import{A as Ol}from"./arrow-left-5SrcW4Rm.js";import{E as Il}from"./external-link-C04MOXed.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-B8gGcUMo.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-DrKIbiB8.js";import{B as Ft,P as Tl}from"./Button-5ThWFbkO.js";import{C as Al,a as zl}from"./clock-C-GPrW5k.js";import{A as Ol}from"./arrow-left-CFG0TEkb.js";import{E as Il}from"./external-link-ujbkNBY4.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -171,14 +171,15 @@ WARNING: This link could potentially be dangerous`)){let i=window.open();if(i){t
171
171
  * Fabrice Bellard's javascript vt100 for jslinux:
172
172
  * http://bellard.org/jslinux/
173
173
  * Copyright (c) 2011 Fabrice Bellard
174
- */var B_=class{constructor(e,t,i,s={}){this._terminal=e,this._regex=t,this._handler=i,this._options=s}provideLinks(e,t){let i=N_.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(i))}_addCallbacks(e){return e.map(t=>(t.leave=this._options.leave,t.hover=(i,s)=>{if(this._options.hover){let{range:r}=t;this._options.hover(i,s,r)}},t))}};function L_(e){try{let t=new URL(e),i=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(i.toLocaleLowerCase())}catch{return!1}}var N_=class ts{static computeLink(t,i,s,r){let n=new RegExp(i.source,(i.flags||"")+"g"),[o,a]=ts._getWindowedLineStrings(t-1,s),h=o.join(""),l,d=[];for(;l=n.exec(h);){let u=l[0];if(!L_(u))continue;let[f,m]=ts._mapStrIdx(s,a,0,l.index),[_,p]=ts._mapStrIdx(s,f,m,u.length);if(f===-1||m===-1||_===-1||p===-1)continue;let S={start:{x:m+1,y:f+1},end:{x:p,y:_+1}};d.push({range:S,text:u,activate:r})}return d}static _getWindowedLineStrings(t,i){let s,r=t,n=t,o=0,a="",h=[];if(s=i.buffer.active.getLine(t)){let l=s.translateToString(!0);if(s.isWrapped&&l[0]!==" "){for(o=0;(s=i.buffer.active.getLine(--r))&&o<2048&&(a=s.translateToString(!0),o+=a.length,h.push(a),!(!s.isWrapped||a.indexOf(" ")!==-1)););h.reverse()}for(h.push(l),o=0;(s=i.buffer.active.getLine(++n))&&s.isWrapped&&o<2048&&(a=s.translateToString(!0),o+=a.length,h.push(a),a.indexOf(" ")===-1););}return[h,r]}static _mapStrIdx(t,i,s,r){let n=t.buffer.active,o=n.getNullCell(),a=s;for(;r;){let h=n.getLine(i);if(!h)return[-1,-1];for(let l=a;l<h.length;++l){h.getCell(l,o);let d=o.getChars();if(o.getWidth()&&(r-=d.length||1,l===h.length-1&&d==="")){let u=n.getLine(i+1);u&&u.isWrapped&&(u.getCell(0,o),o.getWidth()===2&&(r+=1))}if(r<0)return[i,l]}i++,a=0}return[i,a]}},T_=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function A_(e,t){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}var z_=class{constructor(e=A_,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,i=t.urlRegex||T_;this._linkProvider=this._terminal.registerLinkProvider(new B_(this._terminal,i,this._handler,t))}dispose(){var e;(e=this._linkProvider)==null||e.dispose()}};const Ro=10,O_=1e3,I_=3e4;function j_({sessionId:e,isActive:t}){const i=g.useRef(null),s=g.useRef(null),r=g.useRef(null),n=g.useRef(null),o=g.useRef(null),a=g.useRef(!0),h=g.useRef(0),l=g.useCallback(()=>{const u=n.current,f=s.current;u&&u.readyState===WebSocket.OPEN&&f&&u.send(JSON.stringify({type:"resize",cols:f.cols,rows:f.rows}))},[]),d=g.useCallback(()=>{if(!a.current)return;n.current&&(n.current.onclose=null,n.current.onerror=null,n.current.close(),n.current=null);const f=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${e}`,m=new WebSocket(f);n.current=m,m.onopen=()=>{h.current=0;const _=s.current;_&&_.writeln("\x1B[32m-- Terminal connected --\x1B[0m");const p=r.current;if(p&&_){try{p.fit()}catch{}l()}},m.onmessage=_=>{try{const p=JSON.parse(_.data);p.type==="output"&&s.current?s.current.write(p.data):p.type==="error"&&s.current&&s.current.writeln(`\x1B[31m${p.data}\x1B[0m`)}catch{s.current&&s.current.write(_.data)}},m.onclose=()=>{if(!a.current)return;const _=s.current,p=h.current;if(p>=Ro){_&&_.writeln(`\r
175
- \x1B[31m-- Terminal disconnected. Max reconnect attempts reached. Refresh the page to try again. --\x1B[0m`);return}const S=Math.min(O_*Math.pow(2,p),I_);h.current=p+1,_&&_.writeln(`\r
176
- \x1B[33m-- Terminal disconnected. Reconnecting in ${(S/1e3).toFixed(0)}s (attempt ${p+1}/${Ro})... --\x1B[0m`),o.current=setTimeout(()=>{a.current&&d()},S)},m.onerror=()=>{}},[e,l]);return g.useEffect(()=>{a.current=!0,h.current=0;const u=i.current;if(!u)return;const f=new M_({cursorBlink:!0,fontSize:13,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",theme:{background:"#1a1a2e",foreground:"#e0e0e0",cursor:"#a78bfa",selectionBackground:"#3d3d5c",black:"#1a1a2e",red:"#ff6b6b",green:"#51cf66",yellow:"#ffd43b",blue:"#74c0fc",magenta:"#da77f2",cyan:"#66d9ef",white:"#e0e0e0",brightBlack:"#4a4a6a",brightRed:"#ff8787",brightGreen:"#69db7c",brightYellow:"#ffe066",brightBlue:"#91d5ff",brightMagenta:"#e599f7",brightCyan:"#99f7f5",brightWhite:"#ffffff"},scrollback:1e4,convertEol:!0,allowProposedApi:!0}),m=new P_,_=new z_;f.loadAddon(m),f.loadAddon(_),f.open(u),s.current=f,r.current=m;try{m.fit()}catch{}f.onData(v=>{const w=n.current;w&&w.readyState===WebSocket.OPEN&&w.send(JSON.stringify({type:"input",data:v}))}),d();let p=null;const S=new ResizeObserver(()=>{p&&clearTimeout(p),p=setTimeout(()=>{if(!(!r.current||!s.current))try{r.current.fit(),l()}catch{}},50)});return S.observe(u),()=>{a.current=!1,S.disconnect(),p&&clearTimeout(p),o.current&&clearTimeout(o.current),n.current&&(n.current.onclose=null,n.current.close(),n.current=null),f.dispose(),s.current=null,r.current=null}},[d,l]),g.useEffect(()=>{if(t&&r.current&&s.current){const u=setTimeout(()=>{var f;try{(f=r.current)==null||f.fit(),l()}catch{}},50);return()=>clearTimeout(u)}},[t,l]),c.jsx("div",{ref:i,className:"h-full w-full",style:{backgroundColor:"#1a1a2e"}})}function xt(e,t){if(e.length===0)return e;const i=[...e],s=i[i.length-1];return i[i.length-1]={...s,...t(s)},i}function H_({sessionId:e,defaultMode:t,onFilesChanged:i}){const[s,r]=g.useState([]),[n,o]=g.useState(""),[a,h]=g.useState(t||"quick"),[l,d]=g.useState(!1),[u,f]=g.useState(!1),m=g.useRef(null),_=g.useRef(null),p=g.useRef(null),S=g.useRef(null);g.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[s]),g.useEffect(()=>()=>{p.current&&p.current.abort()},[]);const v=g.useCallback(async()=>{var b;if(p.current&&(p.current.abort(),p.current=null),S.current){try{await te.chatCancel(e,S.current)}catch{}S.current=null}f(!1),d(!1),r(B=>xt(B,T=>T.isStreaming?{isStreaming:!1,content:T.content+`
174
+ */var B_=class{constructor(e,t,i,s={}){this._terminal=e,this._regex=t,this._handler=i,this._options=s}provideLinks(e,t){let i=N_.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(i))}_addCallbacks(e){return e.map(t=>(t.leave=this._options.leave,t.hover=(i,s)=>{if(this._options.hover){let{range:r}=t;this._options.hover(i,s,r)}},t))}};function L_(e){try{let t=new URL(e),i=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(i.toLocaleLowerCase())}catch{return!1}}var N_=class ts{static computeLink(t,i,s,r){let n=new RegExp(i.source,(i.flags||"")+"g"),[o,a]=ts._getWindowedLineStrings(t-1,s),h=o.join(""),l,d=[];for(;l=n.exec(h);){let u=l[0];if(!L_(u))continue;let[f,m]=ts._mapStrIdx(s,a,0,l.index),[_,p]=ts._mapStrIdx(s,f,m,u.length);if(f===-1||m===-1||_===-1||p===-1)continue;let S={start:{x:m+1,y:f+1},end:{x:p,y:_+1}};d.push({range:S,text:u,activate:r})}return d}static _getWindowedLineStrings(t,i){let s,r=t,n=t,o=0,a="",h=[];if(s=i.buffer.active.getLine(t)){let l=s.translateToString(!0);if(s.isWrapped&&l[0]!==" "){for(o=0;(s=i.buffer.active.getLine(--r))&&o<2048&&(a=s.translateToString(!0),o+=a.length,h.push(a),!(!s.isWrapped||a.indexOf(" ")!==-1)););h.reverse()}for(h.push(l),o=0;(s=i.buffer.active.getLine(++n))&&s.isWrapped&&o<2048&&(a=s.translateToString(!0),o+=a.length,h.push(a),a.indexOf(" ")===-1););}return[h,r]}static _mapStrIdx(t,i,s,r){let n=t.buffer.active,o=n.getNullCell(),a=s;for(;r;){let h=n.getLine(i);if(!h)return[-1,-1];for(let l=a;l<h.length;++l){h.getCell(l,o);let d=o.getChars();if(o.getWidth()&&(r-=d.length||1,l===h.length-1&&d==="")){let u=n.getLine(i+1);u&&u.isWrapped&&(u.getCell(0,o),o.getWidth()===2&&(r+=1))}if(r<0)return[i,l]}i++,a=0}return[i,a]}},T_=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function A_(e,t){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=t}else console.warn("Opening link blocked as opener could not be cleared")}var z_=class{constructor(e=A_,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,i=t.urlRegex||T_;this._linkProvider=this._terminal.registerLinkProvider(new B_(this._terminal,i,this._handler,t))}dispose(){var e;(e=this._linkProvider)==null||e.dispose()}};const Ro=10,O_=1e3,I_=3e4;function j_({sessionId:e,isActive:t}){const i=g.useRef(null),s=g.useRef(null),r=g.useRef(null),n=g.useRef(null),o=g.useRef(null),a=g.useRef(!0),h=g.useRef(0),l=g.useCallback(()=>{const u=n.current,f=s.current;u&&u.readyState===WebSocket.OPEN&&f&&u.send(JSON.stringify({type:"resize",cols:f.cols,rows:f.rows}))},[]),d=g.useCallback(()=>{if(!a.current)return;n.current&&(n.current.onclose=null,n.current.onerror=null,n.current.close(),n.current=null);const f=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/terminal/${e}`,m=new WebSocket(f);n.current=m,m.onopen=()=>{h.current=0;const _=s.current;_&&_.writeln("\x1B[32m-- Terminal connected --\x1B[0m");const p=r.current;if(p&&_){try{p.fit()}catch{}l()}},m.onmessage=_=>{try{const p=JSON.parse(_.data);p.type==="output"&&s.current?s.current.write(p.data):p.type==="error"&&s.current&&s.current.writeln(`\x1B[31m${p.data}\x1B[0m`)}catch{s.current&&s.current.write(_.data)}},m.onclose=_=>{if(!a.current)return;const p=s.current;if(_.code===4e3){p&&p.writeln(`\r
175
+ \x1B[31m-- Terminal unavailable: `+(_.reason||"server rejected connection")+". --\x1B[0m");return}const S=h.current;if(S>=Ro){p&&p.writeln(`\r
176
+ \x1B[31m-- Terminal disconnected. Max reconnect attempts reached. Refresh the page to try again. --\x1B[0m`);return}const v=Math.min(O_*Math.pow(2,S),I_);h.current=S+1,p&&p.writeln(`\r
177
+ \x1B[33m-- Terminal disconnected. Reconnecting in ${(v/1e3).toFixed(0)}s (attempt ${S+1}/${Ro})... --\x1B[0m`),o.current=setTimeout(()=>{a.current&&d()},v)},m.onerror=()=>{}},[e,l]);return g.useEffect(()=>{a.current=!0,h.current=0;const u=i.current;if(!u)return;const f=new M_({cursorBlink:!0,fontSize:13,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",theme:{background:"#1a1a2e",foreground:"#e0e0e0",cursor:"#a78bfa",selectionBackground:"#3d3d5c",black:"#1a1a2e",red:"#ff6b6b",green:"#51cf66",yellow:"#ffd43b",blue:"#74c0fc",magenta:"#da77f2",cyan:"#66d9ef",white:"#e0e0e0",brightBlack:"#4a4a6a",brightRed:"#ff8787",brightGreen:"#69db7c",brightYellow:"#ffe066",brightBlue:"#91d5ff",brightMagenta:"#e599f7",brightCyan:"#99f7f5",brightWhite:"#ffffff"},scrollback:1e4,convertEol:!0,allowProposedApi:!0}),m=new P_,_=new z_;f.loadAddon(m),f.loadAddon(_),f.open(u),s.current=f,r.current=m;try{m.fit()}catch{}f.onData(v=>{const w=n.current;w&&w.readyState===WebSocket.OPEN&&w.send(JSON.stringify({type:"input",data:v}))}),d();let p=null;const S=new ResizeObserver(()=>{p&&clearTimeout(p),p=setTimeout(()=>{if(!(!r.current||!s.current))try{r.current.fit(),l()}catch{}},50)});return S.observe(u),()=>{a.current=!1,S.disconnect(),p&&clearTimeout(p),o.current&&clearTimeout(o.current),n.current&&(n.current.onclose=null,n.current.close(),n.current=null),f.dispose(),s.current=null,r.current=null}},[d,l]),g.useEffect(()=>{if(t&&r.current&&s.current){const u=setTimeout(()=>{var f;try{(f=r.current)==null||f.fit(),l()}catch{}},50);return()=>clearTimeout(u)}},[t,l]),c.jsx("div",{ref:i,className:"h-full w-full",style:{backgroundColor:"#1a1a2e"}})}function xt(e,t){if(e.length===0)return e;const i=[...e],s=i[i.length-1];return i[i.length-1]={...s,...t(s)},i}function H_({sessionId:e,defaultMode:t,onFilesChanged:i}){const[s,r]=g.useState([]),[n,o]=g.useState(""),[a,h]=g.useState(t||"quick"),[l,d]=g.useState(!1),[u,f]=g.useState(!1),m=g.useRef(null),_=g.useRef(null),p=g.useRef(null),S=g.useRef(null);g.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[s]),g.useEffect(()=>()=>{p.current&&p.current.abort()},[]);const v=g.useCallback(async()=>{var b;if(p.current&&(p.current.abort(),p.current=null),S.current){try{await te.chatCancel(e,S.current)}catch{}S.current=null}f(!1),d(!1),r(B=>xt(B,T=>T.isStreaming?{isStreaming:!1,content:T.content+`
177
178
  [cancelled]`}:{})),(b=_.current)==null||b.focus()},[e]),w=g.useCallback(async b=>{var K;let T=0,O;do{if(await new Promise(W=>setTimeout(W,2e3)),O=await te.chatPoll(e,b),T++,O.output_lines.length>0){const W=O.output_lines.join(`
178
179
  `);r(A=>xt(A,M=>M.role==="system"&&M.isStreaming?{content:W}:{}))}T>=150&&(O={complete:!0,output_lines:["Build timed out after 5 minutes."],files_changed:[],returncode:1})}while(!O.complete);r(W=>xt(W,A=>A.role==="system"?{isStreaming:!1,content:O.output_lines.join(`
179
180
  `)||"Done.",filesChanged:O.files_changed,returncode:O.returncode}:{})),((K=O.files_changed)==null?void 0:K.length)>0&&i&&i(O.files_changed)},[e,i]),R=g.useCallback(async b=>{var T;const B=new AbortController;p.current=B,S.current=b,f(!0);try{const O=te.chatStreamUrl(e,b),K=await fetch(O,{signal:B.signal});if(!K.ok||!K.body)throw new Error(`Stream failed: ${K.status}`);const W=K.body.getReader(),A=new TextDecoder;let M="";for(;;){const{done:C,value:P}=await W.read();if(C)break;M+=A.decode(P,{stream:!0});const x=M.split(`
180
181
 
181
182
  `);M=x.pop()||"";for(const D of x){if(!D.trim())continue;const j=D.split(`
182
183
  `);let L="",q="";for(const X of j)X.startsWith("event:")?L=X.slice(6).trim():X.startsWith("data:")&&(q=X.slice(5).trim());if(L==="output"&&q)try{const{line:X}=JSON.parse(q);r(H=>xt(H,F=>F.role==="system"&&F.isStreaming?{content:F.content?F.content+`
183
- `+X:X}:{}))}catch{}else if(L==="complete"&&q)try{const{returncode:X,files_changed:H}=JSON.parse(q);r(F=>xt(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"&&q)try{const{error:X}=JSON.parse(q);r(H=>xt(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=>xt(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"),[q,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:zt}=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[V,ps]=g.useState(null),[ms,Gr]=g.useState(!1),[Jr,gs]=g.useState(null),[Ot,ol]=g.useState("");g.useEffect(()=>{const y=zt("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"&&!(V!=null&&V.running)&&P(ee=>ee+1))});return()=>{y(),Z.current&&clearTimeout(Z.current)}},[zt,i,f,V==null?void 0:V.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=V!=null&&V.running&&(V!=null&&V.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:q,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:V!=null&&V.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")}),(V==null?void 0:V.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..."})}),V&&V.status!=="stopped"&&c.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs ${V.running?"bg-green-50 border-green-200 text-green-700":V.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":V.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 ${V.running?"bg-green-500":V.status==="starting"?"bg-yellow-500 animate-pulse":V.status==="error"?"bg-red-500":"bg-gray-400"}`}),V.running&&V.port&&c.jsxs("span",{children:["Running on port ",V.port]}),V.status==="starting"&&c.jsx("span",{children:"Starting dev server..."}),V.status==="error"&&c.jsx("span",{children:"Dev server crashed"}),V.command&&c.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:V.command})]}),V!=null&&V.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})]}),(Q.dev_command||Q.type!=="unknown")&&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(),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:"pt-2 border-t border-border",children:[c.jsx("p",{className:"text-xs text-muted mb-2",children:"Or use a custom command:"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:Ot,onChange:y=>ol(y.target.value),onKeyDown:y=>{y.key==="Enter"&&Ot.trim()&&Li(Ot.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:()=>Ot.trim()&&Li(Ot.trim()),disabled:ms||!Ot.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})]}),(V==null?void 0:V.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(),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]}),V.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:V.output.slice(-10).join(`
184
+ `+X:X}:{}))}catch{}else if(L==="complete"&&q)try{const{returncode:X,files_changed:H}=JSON.parse(q);r(F=>xt(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"&&q)try{const{error:X}=JSON.parse(q);r(H=>xt(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=>xt(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"),[q,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:zt}=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[V,ps]=g.useState(null),[ms,Gr]=g.useState(!1),[Jr,gs]=g.useState(null),[Ot,ol]=g.useState("");g.useEffect(()=>{const y=zt("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"&&!(V!=null&&V.running)&&P(ee=>ee+1))});return()=>{y(),Z.current&&clearTimeout(Z.current)}},[zt,i,f,V==null?void 0:V.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=V!=null&&V.running&&(V!=null&&V.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:q,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:V!=null&&V.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")}),(V==null?void 0:V.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..."})}),V&&V.status!=="stopped"&&c.jsxs("div",{className:`px-3 py-1 border-b flex items-center gap-2 text-xs ${V.running?"bg-green-50 border-green-200 text-green-700":V.status==="starting"?"bg-yellow-50 border-yellow-200 text-yellow-700":V.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 ${V.running?"bg-green-500":V.status==="starting"?"bg-yellow-500 animate-pulse":V.status==="error"?"bg-red-500":"bg-gray-400"}`}),V.running&&V.port&&c.jsxs("span",{children:["Running on port ",V.port]}),V.status==="starting"&&c.jsx("span",{children:"Starting dev server..."}),V.status==="error"&&c.jsx("span",{children:"Dev server crashed"}),V.command&&c.jsx("span",{className:"text-xs font-mono opacity-60 ml-auto truncate max-w-xs",children:V.command})]}),V!=null&&V.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(),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:Ot,onChange:y=>ol(y.target.value),onKeyDown:y=>{y.key==="Enter"&&Ot.trim()&&Li(Ot.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:()=>Ot.trim()&&Li(Ot.trim()),disabled:ms||!Ot.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})]}),(V==null?void 0:V.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(),className:"text-xs px-2 py-1 rounded border border-danger/40 text-danger hover:bg-danger/10 transition-colors",children:"Restart"})]}),V.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:V.output.slice(-10).join(`
184
185
  `)})]}),Q.port&&!(V!=null&&V.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:q})]}),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 ${q===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-BlkhGr5c.js";import{B as d,P as m}from"./Button-al3e4s_k.js";import{C as j}from"./Card-Dy53Fy1C.js";import{u as y,B as b}from"./Badge-btjJpcIR.js";import"./clock-DLN9xqq3.js";/**
1
+ import{c as f,u as h,r as n,a as g,j as e}from"./index-B8gGcUMo.js";import{B as d,P as m}from"./Button-5ThWFbkO.js";import{C as j}from"./Card-CcTmaOCN.js";import{u as y,B as b}from"./Badge-CnWBUi7C.js";import"./clock-C-GPrW5k.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-BlkhGr5c.js";import{C as l}from"./Card-Dy53Fy1C.js";import{E as c}from"./external-link-C04MOXed.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-B8gGcUMo.js";import{C as l}from"./Card-CcTmaOCN.js";import{E as c}from"./external-link-ujbkNBY4.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-BlkhGr5c.js";import{C as p}from"./Card-Dy53Fy1C.js";import{u as d,B as h}from"./Badge-btjJpcIR.js";import"./clock-DLN9xqq3.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-B8gGcUMo.js";import{C as p}from"./Card-CcTmaOCN.js";import{u as d,B as h}from"./Badge-CnWBUi7C.js";import"./clock-C-GPrW5k.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-BlkhGr5c.js";/**
1
+ import{c as o,r as m,j as e}from"./index-B8gGcUMo.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-BlkhGr5c.js";/**
1
+ import{c as o}from"./index-B8gGcUMo.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-BlkhGr5c.js";/**
1
+ import{c}from"./index-B8gGcUMo.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-BlkhGr5c.js";/**
1
+ import{c as a}from"./index-B8gGcUMo.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-CpxX59f6.js","assets/Badge-btjJpcIR.js","assets/clock-DLN9xqq3.js","assets/TerminalOutput-DCP_fS6c.js","assets/ProjectPage-nrlfDm3r.js","assets/Button-al3e4s_k.js","assets/arrow-left-5SrcW4Rm.js","assets/external-link-C04MOXed.js","assets/ProjectPage-9CEnUXvW.css","assets/ProjectsPage-CswR-Imw.js","assets/Card-Dy53Fy1C.js","assets/TemplatesPage-CzVB6kTH.js","assets/SettingsPage-DyeqtdDr.js","assets/NotFoundPage-C-jR50AT.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/HomePage-Dx4Ae0hu.js","assets/Badge-CnWBUi7C.js","assets/clock-C-GPrW5k.js","assets/TerminalOutput-DrKIbiB8.js","assets/ProjectPage-BVnDGxXk.js","assets/Button-5ThWFbkO.js","assets/arrow-left-CFG0TEkb.js","assets/external-link-ujbkNBY4.js","assets/ProjectPage-9CEnUXvW.css","assets/ProjectsPage-2Fi6cKB-.js","assets/Card-CcTmaOCN.js","assets/TemplatesPage-B-f1Gfbg.js","assets/SettingsPage-DOzGoyLv.js","assets/NotFoundPage-B1QZ92yR.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-CpxX59f6.js"),__vite__mapDeps([0,1,2,3]))),sg=E.lazy(()=>Pl(()=>import("./ProjectPage-nrlfDm3r.js"),__vite__mapDeps([4,3,5,2,6,7,8]))),rg=E.lazy(()=>Pl(()=>import("./ProjectsPage-CswR-Imw.js"),__vite__mapDeps([9,5,10,1,2]))),dg=E.lazy(()=>Pl(()=>import("./TemplatesPage-CzVB6kTH.js"),__vite__mapDeps([11,10,1,2]))),hg=E.lazy(()=>Pl(()=>import("./SettingsPage-DyeqtdDr.js"),__vite__mapDeps([12,10,7]))),mg=E.lazy(()=>Pl(()=>import("./LoginPage-C4U4jQQ1.js"),[])),yg=E.lazy(()=>Pl(()=>import("./NotFoundPage-C-jR50AT.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-Dx4Ae0hu.js"),__vite__mapDeps([0,1,2,3]))),sg=E.lazy(()=>Pl(()=>import("./ProjectPage-BVnDGxXk.js"),__vite__mapDeps([4,3,5,2,6,7,8]))),rg=E.lazy(()=>Pl(()=>import("./ProjectsPage-2Fi6cKB-.js"),__vite__mapDeps([9,5,10,1,2]))),dg=E.lazy(()=>Pl(()=>import("./TemplatesPage-B-f1Gfbg.js"),__vite__mapDeps([11,10,1,2]))),hg=E.lazy(()=>Pl(()=>import("./SettingsPage-DOzGoyLv.js"),__vite__mapDeps([12,10,7]))),mg=E.lazy(()=>Pl(()=>import("./LoginPage-CRffqZNo.js"),[])),yg=E.lazy(()=>Pl(()=>import("./NotFoundPage-B1QZ92yR.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-BlkhGr5c.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-B8gGcUMo.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">
package/web-app/server.py CHANGED
@@ -2583,13 +2583,22 @@ async def get_preview_info(session_id: str) -> JSONResponse:
2583
2583
  "description": "No preview available",
2584
2584
  }
2585
2585
 
2586
- # Detect project type from files
2586
+ # Detect project type from files (check root and first-level subdirectories)
2587
2587
  files = {f.name for f in target.iterdir() if f.is_file()} if target.is_dir() else set()
2588
2588
  has_package_json = "package.json" in files
2589
+ # If package.json not at root, check immediate subdirectories (e.g. project inside a folder)
2590
+ project_root = target
2591
+ if not has_package_json and target.is_dir():
2592
+ for subdir in target.iterdir():
2593
+ if subdir.is_dir() and (subdir / "package.json").exists():
2594
+ project_root = subdir
2595
+ files = {f.name for f in subdir.iterdir() if f.is_file()}
2596
+ has_package_json = True
2597
+ break
2589
2598
  has_index_html = (
2590
2599
  "index.html" in files
2591
- or (target / "public" / "index.html").exists()
2592
- or (target / "src" / "index.html").exists()
2600
+ or (project_root / "public" / "index.html").exists()
2601
+ or (project_root / "src" / "index.html").exists()
2593
2602
  )
2594
2603
  has_pyproject = "pyproject.toml" in files or "setup.py" in files or "requirements.txt" in files
2595
2604
  has_go_mod = "go.mod" in files
@@ -2601,7 +2610,7 @@ async def get_preview_info(session_id: str) -> JSONResponse:
2601
2610
  pkg_deps: dict = {}
2602
2611
  if has_package_json:
2603
2612
  try:
2604
- pkg = json.loads((target / "package.json").read_text())
2613
+ pkg = json.loads((project_root / "package.json").read_text())
2605
2614
  pkg_scripts = pkg.get("scripts", {})
2606
2615
  pkg_deps = {**pkg.get("dependencies", {}), **pkg.get("devDependencies", {})}
2607
2616
  except (json.JSONDecodeError, OSError):
@@ -2610,11 +2619,11 @@ async def get_preview_info(session_id: str) -> JSONResponse:
2610
2619
  # Determine project type and preview strategy
2611
2620
  is_react = "react" in pkg_deps or "next" in pkg_deps or "vite" in pkg_deps
2612
2621
  is_express = "express" in pkg_deps or "fastify" in pkg_deps or "koa" in pkg_deps or "hono" in pkg_deps
2613
- is_flask = has_pyproject and any((target / f).exists() for f in ["app.py", "main.py", "server.py"])
2622
+ is_flask = has_pyproject and any((project_root / f).exists() for f in ["app.py", "main.py", "server.py"])
2614
2623
  is_fastapi = has_pyproject and any(
2615
- "fastapi" in (target / f).read_text(errors="replace")
2624
+ "fastapi" in (project_root / f).read_text(errors="replace")
2616
2625
  for f in ["app.py", "main.py", "server.py"]
2617
- if (target / f).exists()
2626
+ if (project_root / f).exists()
2618
2627
  )
2619
2628
 
2620
2629
  if is_react or (has_package_json and has_index_html):
@@ -3282,13 +3291,24 @@ async def terminal_websocket(ws: WebSocket, session_id: str) -> None:
3282
3291
  await ws.accept()
3283
3292
 
3284
3293
  if not HAS_PEXPECT:
3285
- await ws.send_text(json.dumps({
3286
- "type": "output",
3287
- "data": "\r\n[Error] pexpect is not installed. "
3288
- "Run: pip install pexpect\r\n",
3289
- }))
3290
- await ws.close()
3291
- return
3294
+ # Try to install pexpect automatically
3295
+ import subprocess as _sp
3296
+ try:
3297
+ _sp.run(
3298
+ [sys.executable, "-m", "pip", "install", "--break-system-packages", "pexpect"],
3299
+ capture_output=True, timeout=30,
3300
+ )
3301
+ import pexpect as _pex # noqa: F811
3302
+ globals()["HAS_PEXPECT"] = True
3303
+ except Exception:
3304
+ await ws.send_text(json.dumps({
3305
+ "type": "output",
3306
+ "data": "\r\n[Error] pexpect is not installed and auto-install failed.\r\n"
3307
+ "Run: pip install pexpect\r\n",
3308
+ }))
3309
+ # Close with 4000 = "do not retry" custom code
3310
+ await ws.close(code=4000, reason="pexpect not installed")
3311
+ return
3292
3312
 
3293
3313
  # ---- Reuse or spawn PTY ------------------------------------------------
3294
3314
  pty = _terminal_ptys.get(session_id)