repoburg 1.3.310 → 1.3.312

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.
@@ -1,4 +1,4 @@
1
- var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-NpywVkQl.js";/**
1
+ var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-7ikRAI4J.js";/**
2
2
  * @license lucide-react v0.469.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/TerminalView-CdL80e84.js","assets/TerminalView-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalView-BF35pnWS.js","assets/TerminalView-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
2
  var U0=Object.defineProperty;var B0=(e,n,r)=>n in e?U0(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var at=(e,n,r)=>B0(e,typeof n!="symbol"?n+"":n,r);(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))o(l);new MutationObserver(l=>{for(const c of l)if(c.type==="childList")for(const d of c.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&o(d)}).observe(document,{childList:!0,subtree:!0});function r(l){const c={};return l.integrity&&(c.integrity=l.integrity),l.referrerPolicy&&(c.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?c.credentials="include":l.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function o(l){if(l.ep)return;l.ep=!0;const c=r(l);fetch(l.href,c)}})();function tv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fu={exports:{}},mi={},Uu={exports:{}},He={};/**
3
3
  * @license React
4
4
  * react.production.min.js
@@ -833,9 +833,9 @@ ${_}
833
833
  stack: (r && r.stack) || '', line: 0, col: 0
834
834
  }, '*');
835
835
  });
836
- }`;function HE(e){return`(${WE})(${JSON.stringify(e)});`}function Gg(e){return e.replace(/<\/script/gi,"<\\/script")}function VE(e,n){const r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(r,"gi");let l=-1,c;for(;(c=o.exec(e))!==null;)l=c.index;return l}function qg(e,n,r){const o=VE(e,n);return o===-1?e+r:e.slice(0,o)+r+e.slice(o)}function KE(e,n,r){let o=e;const l=`<script>${Gg(n)}<\/script>`;if(/<\/head>/i.test(o)?o=qg(o,"</head>",l):/<html[^>]*>/i.test(o)?o=o.replace(/(<html[^>]*>)/i,`$1<head>${l}</head>`):o=`${l}${o}`,r){const c=`<script>${Gg(r)}<\/script>`;o=qg(o,"</body>",c)}return o}function GE(){const e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?`tab-${e.randomUUID()}`:`tab-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function qE(e){var r;if(!(e instanceof Ui)||e.status!==409)return null;const n=(r=e.body)==null?void 0:r.state;return n&&typeof n=="object"?n:null}function XE({appId:e,workspace:n=""}){const r=x.useRef(null),o=x.useRef({pinned:!1,data:null}),[l,c]=x.useState(null),[d,f]=x.useState(null),[h,m]=x.useState([]);x.useEffect(()=>{let S=!0;const E=GE(),T=b=>{const _=o.current.version;typeof b.version=="number"&&typeof _=="number"&&b.version<_||(o.current=b)};Ww(e,b=>{var _,z;return(z=(_=r.current)==null?void 0:_.contentWindow)==null?void 0:z.postMessage(b,"*")},n);const C=async b=>{var P,U,Q,J,oe,me,Se,Me,ee,ie,te,F,Z,q,I,$,ue,B,X,ce,be,_e,Ae,je;if(b.source!==((P=r.current)==null?void 0:P.contentWindow))return;const _=b.data;if(!_||_.source!=="agentpane-app")return;if(_.report==="error"){const ge={message:String(_.message??"Unknown error"),stack:String(_.stack??"")};m(he=>{const Ve=he[he.length-1];return Ve&&Ve.message===ge.message?he:[...he,ge].slice(-20)});return}if(typeof _.method!="string")return;let z=!0,M,L,G=null;try{switch(_.method){case"getApp":M={id:e,workspace:n};break;case"getState":try{const ge=await jm(e,n);T(ge),M=ge}catch{M=o.current}break;case"setState":{const ge=((U=_.params)==null?void 0:U.data)??null,he=(Q=_.params)==null?void 0:Q.ifVersion,Ve={data:ge,writer:E};typeof he=="number"&&(Ve.ifVersion=he);try{const Ie=await Cv(e,Ve,n);T(Ie),M=Ie}catch(Ie){if(G=qE(Ie),!G)throw Ie;T(G);const mt=Ie.body;throw new Error(typeof(mt==null?void 0:mt.error)=="string"?mt.error:"App state changed since that version")}break}case"createSession":{const ge=_.params??{},he=await qd({title:typeof ge.title=="string"?ge.title:void 0,runtime_type:typeof ge.runtime_type=="string"?ge.runtime_type:void 0,model:typeof ge.model=="string"?ge.model:void 0,model_reasoning_effort:typeof ge.model_reasoning_effort=="string"?ge.model_reasoning_effort:void 0,cwd:typeof ge.cwd=="string"?ge.cwd:void 0,origin_app_id:e,origin_app_workspace:n});dl(he.id,e),R.getState().addSession(he),M=he;break}case"submitTurn":{const ge=String(((J=_.params)==null?void 0:J.sessionId)??"");if(!await _m(e,ge))throw new Error(`submitTurn: ${ge} is not a session of this app`);const he=String(((oe=_.params)==null?void 0:oe.prompt)??""),Ve=await BE(e,(me=_.params)==null?void 0:me.attachments,mt=>Xk(e,mt)),Ie=await dv(ge,he,Ve.length?Ve:void 0,{originAppId:e});dl(ge,e),M=Ie;break}case"getSession":{M=await _m(e,String(((Se=_.params)==null?void 0:Se.sessionId)??""));break}case"listSessions":{const ge=(Me=_.params)==null?void 0:Me.lifecycle,he=(ee=_.params)==null?void 0:ee.running;M=await Ok(e,n,{lifecycle:ge==="working"||ge==="finished"?ge:void 0,running:typeof he=="boolean"?he:void 0});break}case"getSessionInfo":{M=await $k(e,n,String(((ie=_.params)==null?void 0:ie.sessionId)??""));break}case"cancelTurn":{M=await Pk(e,String(((te=_.params)==null?void 0:te.sessionId)??""));break}case"setSessionLifecycle":{M=await zk(e,String(((F=_.params)==null?void 0:F.sessionId)??""),String(((Z=_.params)==null?void 0:Z.lifecycle)??""));break}case"callTool":{const ge=(q=_.params)==null?void 0:q.args;M=await Fk(e,n,String(((I=_.params)==null?void 0:I.tool)??""),ge&&typeof ge=="object"?ge:{});break}case"listProviders":{M=await Xy();break}case"listModels":{const ge=typeof(($=_.params)==null?void 0:$.runtime)=="string"?_.params.runtime.trim():"";if(!ge)throw new Error("listModels: runtime is required");const he=(ue=_.params)==null?void 0:ue.cwd;M=await Nv(ge,typeof he=="string"&&he?he:void 0);break}case"pickDirectory":{if(R.getState().activeAppTabId!==e)throw new Error("pickDirectory: the app is not on screen — call it from a click in the app");M=await pv();break}case"resolveToolCall":{const ge=String(((B=_.params)==null?void 0:B.callId)??""),he=(X=_.params)==null?void 0:X.result;await Vk(ge,he),M={ok:!0};break}case"openSession":{if(R.getState().activeAppTabId!==e)throw new Error("openSession: the app is not on screen — call it from a click in the app");const ge=typeof((ce=_.params)==null?void 0:ce.sessionId)=="string"?_.params.sessionId.trim():"";if(!ge)throw new Error("openSession: sessionId is required");try{await R.getState().revealSession(ge)}catch(he){throw new Error(`openSession: ${he instanceof Error?he.message:String(he)}`)}M={ok:!0};break}case"uploadFile":{const ge=await UE((be=_.params)==null?void 0:be.file);try{M=Kg(await Gk(e,ge))}catch(he){throw new Error(`uploadFile: ${he instanceof Error?he.message:String(he)}`)}break}case"getFile":{const ge=rx(e,(_e=_.params)==null?void 0:_e.ref),he=ge?await qk(e,ge):null;M=he?Kg(he):null;break}default:throw new Error(`Unknown bridge method: ${_.method}`)}}catch(ge){z=!1,L=ge instanceof Error?ge.message:String(ge)}(je=(Ae=r.current)==null?void 0:Ae.contentWindow)==null||je.postMessage(G?{source:"agentpane-host",id:_.id,ok:z,error:L,code:"conflict",state:G}:{source:"agentpane-host",id:_.id,ok:z,result:M,error:L},"*")};return window.addEventListener("message",C),Yw(e,b=>{var _,z;typeof b.workspace=="string"&&b.workspace!==n||b.writer!==E&&((z=(_=r.current)==null?void 0:_.contentWindow)==null||z.postMessage({source:"agentpane-host",event:"state_changed",payload:typeof b.version=="number"?{version:b.version}:{}},"*"))}),qw(e,()=>{Em(e).then(b=>{S&&(c(b),m([]))}).catch(()=>{})}),(async()=>{try{const[b,_,z]=await Promise.all([Em(e),jm(e,n),Lk(e).catch(()=>[])]);if(!S)return;o.current=_,z.forEach(M=>dl(M.id,e)),c(b)}catch(b){S&&f(b instanceof Error?b.message:String(b))}})(),()=>{S=!1,Hw(e),Xw(e),Qw(e),window.removeEventListener("message",C)}},[e,n]),x.useEffect(()=>{l&&Vw(e,l.manifest.headlessSessions===!0)},[e,l]);const v=x.useMemo(()=>l?KE(l.html,HE({appId:e,apiOrigin:sx()}),l.js):"",[l,e]);if(d)return a.jsxs("div",{className:"empty-state",style:{padding:"24px"},children:["Mini app failed to load: ",d]});if(!v)return a.jsx("div",{className:"empty-state",style:{padding:"24px"},children:"Loading mini app…"});const k=(l==null?void 0:l.diagnostics)??[],y=k.some(S=>S.severity==="error");return a.jsxs("div",{className:"miniapp-runtime",children:[k.length>0&&a.jsxs("div",{className:`miniapp-diagnostics${y?"":" miniapp-diagnostics-warn"}`,"data-testid":"miniapp-diagnostics",children:[a.jsx("div",{className:"miniapp-diagnostics-title",children:y?`Compile errors in ${(l==null?void 0:l.sourceFile)??"the app logic"} — the pane serves the last code that parsed:`:"Warnings — the app runs, but fix these:"}),k.map((S,E)=>a.jsxs("div",{className:"miniapp-diag",children:[S.file,":",S.line,":",S.column," — ",S.message]},E))]}),a.jsx("iframe",{ref:r,className:"miniapp-frame",sandbox:"allow-scripts allow-popups allow-popups-to-escape-sandbox",allow:"loopback-network; local-network; local-network-access",title:`Mini app: ${e}`,srcDoc:v}),h.length>0&&a.jsx("div",{className:"miniapp-rt-errors","data-testid":"miniapp-rt-errors",children:h.map((S,E)=>a.jsxs("div",{className:"miniapp-rt-error",children:[a.jsx("div",{className:"miniapp-rt-error-message",children:S.message}),S.stack&&a.jsx("pre",{className:"miniapp-rt-error-stack",children:S.stack})]},E))})]})}function YE({appId:e,active:n}){const r=R(y=>y.apps),o=R(y=>y.workspaces),l=R(y=>y.appWorkspaces),c=R(y=>y.setAppWorkspace),d=R(y=>y.setActiveAppTab),f=R(y=>y.startAppEdit),h=r.find(y=>y.id===e),m=l[e]??"",v=o.filter(y=>y.deleted!==1),k=m!==""&&!v.some(y=>y.path===m)?m:null;return a.jsxs("div",{className:`miniapp-view ${n?"":"miniapp-view-hidden"}`,children:[a.jsxs("div",{className:"miniapp-header",children:[a.jsx(Do,{iconNode:h==null?void 0:h.iconNode,size:14,className:"miniapp-header-icon"}),a.jsx("span",{className:"miniapp-header-title",children:(h==null?void 0:h.title)??e}),a.jsxs("select",{className:"miniapp-workspace-select",title:"Workspace this app instance is bound to (state and pinning are scoped per workspace)",value:m,onChange:y=>c(e,y.target.value),children:[a.jsx("option",{value:"",children:"All workspaces (global)"}),v.map(y=>a.jsx("option",{value:y.path,children:y.label||y.path.split("/").pop()||y.path},y.path)),k&&a.jsx("option",{value:k,children:`${k} (unknown workspace)`})]}),a.jsxs("button",{className:"miniapp-header-btn",title:"Edit this app with the agent (opens an edit session on the app folder)",onClick:()=>void f(e),children:[a.jsx(V1,{size:13}),"Edit"]}),a.jsx("button",{className:"miniapp-header-close",title:"Close app",onClick:()=>d(null),children:a.jsx(Tn,{size:14})})]}),a.jsx("div",{className:"miniapp-body",children:a.jsx(XE,{appId:e,workspace:m},`${e}:${m}`)})]})}function QE({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l}){const[c,d]=x.useState(!1),f=x.useRef(0),h=x.useRef(0),m=x.useCallback(y=>{const S=y.clientX-f.current,E=e==="left"?h.current+S:h.current-S,T=Math.min(r,Math.max(n,E));l(T)},[e,n,r,l]),v=x.useCallback(()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",v),document.body.classList.remove("is-resizing"),d(!1)},[m]);return{onPointerDown:x.useCallback(y=>{var S,E;y.preventDefault(),y.stopPropagation();try{(E=(S=y.currentTarget)==null?void 0:S.setPointerCapture)==null||E.call(S,y.pointerId)}catch{}f.current=y.clientX,h.current=o(),d(!0),document.body.classList.add("is-resizing"),window.addEventListener("pointermove",m),window.addEventListener("pointerup",v)},[o,m,v]),dragging:c}}function Xg({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l}){const{onPointerDown:c,dragging:d}=QE({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l});return a.jsx("div",{className:`resize-handle ${e}${d?" dragging":""}`,onPointerDown:c,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e} panel`,"data-resizing":d?"":void 0})}const ZE=x.lazy(()=>f1(()=>import("./TerminalView-CdL80e84.js"),__vite__mapDeps([0,1])));function JE(){Lt.trackRender("IdeWorkspace");const e=R(S=>S.sidebarWidth),n=R(S=>S.rightPanelWidth),r=R(S=>S.setSidebarWidth),o=R(S=>S.setRightPanelWidth),l=R(S=>S.rightPanelCollapsed),c=R(S=>S.vscodeViewOpen),d=R(S=>S.usageViewOpen),f=R(S=>S.terminalViewOpen),[h,m]=x.useState(!1);f&&!h&&m(!0);const v=R(S=>S.activeAppTabId),k=R(S=>S.openAppTabs);x.useEffect(()=>{const S=()=>{const E=Nl(),{rightPanelWidth:T,setRightPanelWidth:C}=R.getState();T>E&&C(E)};return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const y=l?`${e}px 6px 1fr ${jk}px`:`${e}px 6px 1fr 6px ${n}px`;return a.jsxs("div",{className:"ide-root",children:[a.jsx(OE,{}),a.jsxs("div",{className:`ide-layout ${c||d||f?"ide-hidden":""}`,style:{gridTemplateColumns:y},children:[a.jsx(tN,{}),a.jsx(Xg,{side:"left",minWidth:kd,maxWidth:Sd,getWidth:()=>R.getState().sidebarWidth,setWidth:r}),a.jsxs("div",{className:"ide-center",children:[a.jsx(rN,{}),a.jsxs("div",{className:"ide-render",children:[k.map(S=>a.jsx(YE,{appId:S,active:v===S},S)),v==null&&a.jsx(vC,{})]}),a.jsx(jC,{})]}),!l&&a.jsx(Xg,{side:"right",minWidth:bl,maxWidth:Nl(),getWidth:()=>R.getState().rightPanelWidth,setWidth:o}),a.jsx(YC,{})]}),c&&a.jsx(uE,{}),d&&a.jsx(LE,{}),h&&a.jsx(x.Suspense,{fallback:null,children:a.jsx(ZE,{visible:f})}),a.jsx(oE,{})]})}function ej(){const{showNewSessionDialog:e,setShowNewSessionDialog:n,createSession:r,lastModelConfig:o}=R(),l=(o==null?void 0:o.provider)??"codex",c=(o==null?void 0:o.model)??"",d=(o==null?void 0:o.reasoning)??"",[f,h]=x.useState(""),[m,v]=x.useState(c),[k,y]=x.useState(d),[S,E]=x.useState("");if(!e)return null;const T=jf(l),C=m?Fd(l,m):[];function b(){r({title:f.trim()||void 0,model:m||void 0,model_reasoning_effort:k||void 0,cwd:S.trim()||void 0,runtime_type:l}),h(""),E("")}function _(M){M.key==="Escape"&&n(!1)}function z(M){var P;v(M);const L=Fd(l,M);L.some(U=>U.effort===k)||y(Ud(l,M)??((P=L[0])==null?void 0:P.effort)??"")}return a.jsx("div",{className:"dialog-overlay",onClick:()=>n(!1),children:a.jsxs("div",{className:"dialog",onClick:M=>M.stopPropagation(),onKeyDown:_,children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",children:"New Session"}),a.jsx("button",{className:"dialog-close",onClick:()=>n(!1),children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("label",{className:"dialog-label",children:["Title (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:f,onChange:M=>h(M.target.value),placeholder:"e.g. refactor auth module",autoFocus:!0})]}),a.jsxs("label",{className:"dialog-label",children:["Model",a.jsxs("select",{className:"dialog-input dialog-select",value:m,onChange:M=>z(M.target.value),children:[a.jsx("option",{value:"",children:"Default (Codex picks)"}),T.map(M=>a.jsxs("option",{value:M.slug,children:[M.displayName," — ",M.description]},M.slug))]})]}),C.length>0&&a.jsxs("label",{className:"dialog-label",children:["Thinking Level",a.jsxs("select",{className:"dialog-input dialog-select",value:k,onChange:M=>y(M.target.value),children:[a.jsxs("option",{value:"",children:["Default (",Ud(l,m),")"]}),C.map(M=>a.jsx("option",{value:M.effort,children:M.label},M.effort))]})]}),a.jsxs("label",{className:"dialog-label",children:["Working Directory (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:S,onChange:M=>E(M.target.value),placeholder:"e.g. /Users/me/projects/my-app"})]})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:()=>n(!1),children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:b,children:"Create"})]})]})})}function tj(e,n){const r=n!==""&&(e===n||e.startsWith(`${n}/`)),o=[r?{label:"~",path:n}:{label:"/",path:"/"}],l=e.slice(r?n.length:0);let c=o[0].path;for(const d of l.split("/").filter(Boolean))c=c==="/"?`/${d}`:`${c}/${d}`,o.push({label:d,path:c});return o}function nj(e){const n=e.filter(l=>l.deleted===0).at(-1);if(!n)return;const r=gr(n.path),o=r.lastIndexOf("/");return o>0?r.slice(0,o):void 0}function sj(){return R(n=>n.showAddWorkspaceDialog)?a.jsx(rj,{}):null}function rj(){var P;const e=R(U=>U.setShowAddWorkspaceDialog),n=R(U=>U.workspaces),r=R(U=>U.createWorkspaceAt),o=R(U=>U.addToast),[l,c]=x.useState(null),[d,f]=x.useState(!0),[h,m]=x.useState(null),[v,k]=x.useState(!1),y=x.useRef(0),[S]=x.useState(()=>nj(R.getState().workspaces)),E=x.useRef(null),T=x.useCallback(()=>{v||e(!1)},[v,e]);Io(T);const C=x.useCallback(async(U,Q=!1)=>{const J=++y.current;f(!0);let oe=null,me=null;try{oe=await cm(U)}catch(Se){if(me=hr(Se),Q&&U)try{oe=await cm(),me=null}catch(Me){me=hr(Me)}}J===y.current&&(oe&&c(oe),m(me),f(!1))},[]);x.useEffect(()=>{C(S,!0)},[C,S]);const b=l==null?void 0:l.path;x.useEffect(()=>{E.current&&(E.current.scrollTop=0)},[b]);const _=new Set(n.filter(U=>U.deleted===0).map(U=>gr(U.path)));async function z(U){if(!v){k(!0),m(null);try{const Q=await r(U);e(!1),o("success",`Workspace added — ${Q.path}`)}catch(Q){m(hr(Q)),k(!1)}}}const M=l?tj(l.path,l.home):[],L=((P=M.at(-1))==null?void 0:P.label)??"",G=l!==null&&_.has(gr(l.path));return a.jsx("div",{className:"dialog-overlay",onClick:T,children:a.jsxs("div",{className:"dialog folder-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"folder-dialog-title",onClick:U=>U.stopPropagation(),children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",id:"folder-dialog-title",children:"Add workspace"}),a.jsx("button",{className:"dialog-close",onClick:T,"aria-label":"Close",disabled:v,children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("p",{className:"dialog-hint",children:["Choose a project folder",l&&a.jsxs(a.Fragment,{children:[" ","on ",a.jsx("strong",{children:l.hostname})]}),"."]}),a.jsxs("div",{className:"folder-nav",children:[a.jsx("button",{className:"folder-up",onClick:()=>(l==null?void 0:l.parent)&&void C(l.parent),disabled:!(l!=null&&l.parent),"aria-label":"Parent folder",title:"Parent folder",children:a.jsx(Mv,{size:14})}),a.jsx("nav",{className:"folder-crumbs","aria-label":"Folder path",children:M.map((U,Q)=>a.jsxs(x.Fragment,{children:[Q>0&&a.jsx(Li,{size:12,className:"folder-crumb-sep","aria-hidden":"true"}),Q===M.length-1?a.jsx("span",{className:"folder-crumb current","aria-current":"location",title:U.path,children:U.label}):a.jsx("button",{className:"folder-crumb",onClick:()=>void C(U.path),title:U.path,children:U.label})]},U.path))}),d&&l&&a.jsx(mn,{size:14,className:"spin folder-spinner","aria-label":"Loading"})]}),a.jsx("ul",{ref:E,className:`folder-list${d&&l?" loading":""}`,"aria-label":"Folders",children:l?l.folders.length===0?a.jsx("li",{className:"folder-empty",children:"No folders here."}):l.folders.map(U=>a.jsxs("li",{className:"folder-item",children:[a.jsxs("button",{className:"folder-row",onClick:()=>void C(U.path),title:U.path,"aria-label":U.git?`${U.name} (git repository)`:U.name,children:[U.git?a.jsx(j1,{size:15,className:"folder-icon git","aria-hidden":"true"}):a.jsx(Rl,{size:15,className:"folder-icon","aria-hidden":"true"}),a.jsx("span",{className:"folder-name",children:U.name}),a.jsx(Li,{size:13,className:"folder-chevron","aria-hidden":"true"})]}),_.has(gr(U.path))?a.jsx("span",{className:"folder-tag",children:"Added"}):a.jsx("button",{className:"folder-add",onClick:()=>void z(U.path),disabled:v,"aria-label":`Add ${U.name}`,children:"Add"})]},U.path)):d&&a.jsxs("li",{className:"folder-empty",role:"status",children:[a.jsx(mn,{size:14,className:"spin"})," Loading folders…"]})}),(l==null?void 0:l.truncated)&&a.jsxs("p",{className:"folder-note",children:["Showing the first ",l.folders.length," folders."]}),h&&a.jsx("p",{className:"folder-error",role:"alert",children:h})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:T,disabled:v,children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:()=>l&&void z(l.path),disabled:!l||d||v||G,children:v?"Adding…":G?"Already added":`Add “${L}”`})]})]})})}const Wd=6e4,Hd=60*Wd,ul=24*Hd;function oj(e,n=Date.now()){const r=Date.parse(e);if(Number.isNaN(r))return"";const o=Math.max(0,n-r);return o<Wd?"just now":o<Hd?`${Math.floor(o/Wd)} min ago`:o<ul?`${Math.floor(o/Hd)} h ago`:o<2*ul?"yesterday":o<7*ul?`${Math.floor(o/ul)} days ago`:new Date(r).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function ij(){const e=R(n=>n.importSessionsWorkspace);return e?a.jsx(aj,{workspace:e},e):null}function aj({workspace:e}){const n=R(P=>P.setImportSessionsWorkspace),r=R(P=>P.importSessions),[o,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState({}),[m,v]=x.useState(new Set),[k,y]=x.useState(!1),[S,E]=x.useState(new Map),T=x.useCallback(()=>{k||n(null)},[k,n]);Io(T),x.useEffect(()=>{let P=!1;return bv(e).then(({sessions:U,errors:Q})=>{if(P)return;const J=Object.values(Q);if(J.length===wd.length){d([...new Set(J)].join("; "));return}l(U),h(Q)}).catch(U=>{P||d(hr(U))}),()=>{P=!0}},[e]);function C(P){v(U=>{const Q=new Set(U);return Q.has(P)?Q.delete(P):Q.add(P),Q})}const b=o??[],_=P=>Qu({runtime:P.runtime,id:P.session_id}),z=b.length>0&&b.every(P=>m.has(_(P)));async function M(){const P=b.filter(J=>m.has(_(J))).map(J=>({runtime:J.runtime,id:J.session_id}));if(P.length===0)return;y(!0);const{failed:U}=await r(e,P);if(y(!1),U.length===0){n(null);return}const Q=new Set(U.map(Qu));l(J=>(J??[]).filter(oe=>!m.has(_(oe))||Q.has(_(oe)))),v(Q),E(new Map(U.map(J=>[Qu(J),J.error])))}const L=e.split("/").pop()||e,G=m.size;return a.jsx("div",{className:"dialog-overlay",onClick:T,children:a.jsxs("div",{className:"dialog import-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"import-dialog-title",onClick:P=>P.stopPropagation(),children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",id:"import-dialog-title",children:"Import sessions"}),a.jsx("button",{className:"dialog-close",onClick:T,"aria-label":"Close",disabled:k,children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("p",{className:"dialog-hint",children:["Sessions you started with ",a.jsx("code",{children:"claude"})," or ",a.jsx("code",{children:"codex"})," in"," ",a.jsx("strong",{title:e,children:L}),", in a terminal or an IDE. An imported session keeps its history and continues the same conversation."]}),c?a.jsxs("p",{className:"import-error",role:"alert",children:["Could not list the sessions — ",c]}):o===null?a.jsxs("div",{className:"import-loading",role:"status",children:[a.jsx(mn,{size:14,className:"spin"})," Looking for sessions…"]}):o.length===0?a.jsxs("div",{className:"import-empty",children:["No Claude Code or Codex sessions to import here. Sessions you start with ",a.jsx("code",{children:"claude"})," or"," ",a.jsx("code",{children:"codex"})," in this folder will show up here.",a.jsx(Yg,{errors:f})]}):a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"import-select-all",children:[a.jsx("input",{type:"checkbox",checked:z,disabled:k,onChange:()=>v(z?new Set:new Set(b.map(_)))}),"Select all (",o.length,")"]}),a.jsx("ul",{className:"import-list",children:o.map(P=>{const U=_(P),Q=S.get(U);return a.jsx("li",{children:a.jsxs("label",{className:`import-row${m.has(U)?" selected":""}`,children:[a.jsx("input",{type:"checkbox",checked:m.has(U),disabled:k,onChange:()=>C(U)}),a.jsxs("span",{className:"import-row-main",children:[a.jsx("span",{className:"import-row-title",title:P.title,children:P.title}),a.jsxs("span",{className:"import-row-meta",children:[a.jsx("span",{className:`import-row-runtime ${P.runtime}`,children:Ql[P.runtime]}),a.jsx("span",{title:new Date(P.last_modified).toLocaleString(),children:oj(P.last_modified)}),P.git_branch&&a.jsxs("span",{className:"import-row-branch",title:"Git branch",children:[a.jsx(Pv,{size:10})," ",P.git_branch]})]}),P.recently_active&&a.jsxs("span",{className:"import-row-warn",children:[a.jsx(tc,{size:11})," Active in the last few minutes. If it is still open in a terminal, close it there first: both would write to the same session."]}),Q&&a.jsx("span",{className:"import-row-error",role:"alert",children:Q})]})]})},U)})}),a.jsx(Yg,{errors:f})]})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:T,disabled:k,children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:()=>void M(),disabled:G===0||k,children:k?a.jsxs(a.Fragment,{children:[a.jsx(mn,{size:12,className:"spin"})," Importing…"]}):G>1?`Import ${G} sessions`:"Import"})]})]})})}function Yg({errors:e}){const n=Object.entries(e);return n.length===0?null:a.jsx(a.Fragment,{children:n.map(([r,o])=>a.jsxs("p",{className:"import-note",children:["Could not list the ",Ql[r]," sessions — ",o]},r))})}const lj=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,cj=512*1024;function uj(e){const n=e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"");return/^[a-z0-9]/.test(n)?n:""}function dj(){const{appCatalogOpen:e,closeAppCatalog:n,apps:r,installExampleApp:o,createSkeletonApp:l,importAppFolder:c}=R(),[d,f]=x.useState("examples"),[h,m]=x.useState(null),[v,k]=x.useState(null),[y,S]=x.useState(!1),[E,T]=x.useState(""),[C,b]=x.useState(""),[_,z]=x.useState(""),[M,L]=x.useState(""),[G,P]=x.useState(null),[U,Q]=x.useState(""),J=x.useRef(null);if(x.useEffect(()=>{e&&(m(null),Uk().then(m).catch(()=>m([])))},[e]),x.useEffect(()=>{J.current&&(J.current.webkitdirectory=!0)},[d]),!e)return null;const oe=new Set(r.map(F=>F.id));async function me(F){k(F);try{await o(F)&&n()}finally{k(null)}}async function Se(){if(y)return;const F=E.trim(),Z=C.trim();if(!(!F||!Z)){S(!0);try{await l({id:F,title:Z,description:_.trim()||void 0,icon:M.trim()||void 0})&&(T(""),b(""),z(""),L(""),n())}finally{S(!1)}}}async function Me(F){const Z=Array.from(F.target.files??[]),q={};let I="";for(const $ of Z){const B=($.webkitRelativePath??"").split("/");!I&&B.length>1&&(I=B[0]);const X=B[B.length-1];if(!(!X||!lj.test(X))&&!($.size>cj))try{q[X]=await $.text()}catch{}}P(Object.keys(q).length>0?q:null),Q(uj(I))}async function ee(){if(!(y||!G||!U.trim())){S(!0);try{await c(U.trim(),G)&&(P(null),Q(""),n())}finally{S(!1)}}}function ie(F){F.key==="Escape"&&n()}const te=[{key:"examples",label:"Examples"},{key:"new",label:"New App"},{key:"upload",label:"Upload"}];return a.jsx("div",{className:"dialog-overlay",onClick:n,children:a.jsxs("div",{className:"dialog app-catalog",onClick:F=>F.stopPropagation(),onKeyDown:ie,children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",children:"Add Mini App"}),a.jsx("button",{className:"dialog-close",onClick:n,children:"✕"})]}),a.jsx("div",{className:"catalog-tabs",children:te.map(F=>a.jsx("button",{className:`catalog-tab${d===F.key?" active":""}`,onClick:()=>f(F.key),children:F.label},F.key))}),a.jsxs("div",{className:"dialog-body catalog-body",children:[d==="examples"&&a.jsx("div",{className:"catalog-examples",children:h===null?a.jsx("div",{className:"empty-state",style:{padding:"12px"},children:"Loading examples…"}):h.length===0?a.jsx("div",{className:"empty-state",style:{padding:"12px"},children:"No example apps available."}):h.map(F=>{const Z=oe.has(F.id);return a.jsxs("div",{className:"example-row",children:[a.jsx(Do,{iconNode:F.iconNode,size:14,className:"sidebar-app-icon"}),a.jsxs("div",{className:"example-info",children:[a.jsx("span",{className:"example-title",children:F.title}),F.description&&a.jsx("span",{className:"example-desc",children:F.description})]}),a.jsx("button",{className:"example-install",disabled:Z||v===F.id,onClick:()=>me(F.id),title:Z?"Already installed":"Install this example",children:Z?"Installed":v===F.id?"Installing…":"Install"})]},F.id)})}),d==="new"&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"dialog-label",children:["App id (folder name)",a.jsx("input",{className:"dialog-input",type:"text",value:E,onChange:F=>T(F.target.value),placeholder:"e.g. todo-list",autoFocus:!0})]}),a.jsxs("label",{className:"dialog-label",children:["Title",a.jsx("input",{className:"dialog-input",type:"text",value:C,onChange:F=>b(F.target.value),placeholder:"e.g. Todo List"})]}),a.jsxs("label",{className:"dialog-label",children:["Description (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:_,onChange:F=>z(F.target.value),placeholder:"What does this app do?"})]}),a.jsxs("label",{className:"dialog-label",children:[a.jsxs("span",{children:["Icon (optional, a"," ",a.jsx("a",{href:"https://lucide.dev/icons",target:"_blank",rel:"noreferrer",children:"Lucide icon"})," ","name)"]}),a.jsx("input",{className:"dialog-input",type:"text",value:M,onChange:F=>L(F.target.value),placeholder:"e.g. notebook-pen",spellCheck:!1,autoCapitalize:"off"})]}),a.jsxs("button",{className:"dialog-btn-create catalog-action-btn",disabled:y||!E.trim()||!C.trim(),onClick:Se,children:[a.jsx(pr,{size:13})," Create App"]})]}),d==="upload"&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"catalog-upload-hint",children:"Select an app folder from disk. Text files only (manifest.json, index.html, app.ts (or legacy app.js), …). A missing manifest.json is generated from the folder name."}),a.jsx("input",{ref:J,type:"file",multiple:!0,onChange:Me}),G&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"dialog-label",children:["App id",a.jsx("input",{className:"dialog-input",type:"text",value:U,onChange:F=>Q(F.target.value)})]}),a.jsxs("div",{className:"catalog-upload-summary",children:[Object.keys(G).length," file(s):"," ",Object.keys(G).slice(0,6).join(", "),Object.keys(G).length>6?", …":""]})]}),a.jsxs("button",{className:"dialog-btn-create catalog-action-btn",disabled:y||!G||!U.trim(),onClick:ee,children:[a.jsx(Z1,{size:13})," Import App"]})]})]}),a.jsx("div",{className:"dialog-footer",children:a.jsx("button",{className:"dialog-btn-cancel",onClick:n,children:"Close"})})]})})}function fj(){const e=R(k=>k.showCommandPalette),n=R(k=>k.setShowCommandPalette),r=R(),[o,l]=x.useState(""),[c,d]=x.useState(0),f=x.useRef(null),h=x.useMemo(()=>{const k=r.activeSessionId?r.sessionDetails[r.activeSessionId]:null,y=ql(k);return[{id:"new-session",label:"New Session",hint:"Create a new Codex session",icon:pr,action:()=>r.setShowNewSessionDialog(!0),available:!0},{id:"delete-session",label:"Delete Session",hint:"Delete the active session",icon:us,action:()=>{r.activeSessionId&&r.deleteSession(r.activeSessionId)},available:!!r.activeSessionId},{id:"send-message",label:"Send Message",hint:"Focus the message input",icon:Hi,action:()=>{const S=document.querySelector(".cmd-input");S==null||S.focus()},available:!!r.activeSessionId&&!y},{id:"cancel-turn",label:"Cancel Turn",hint:"Cancel the running turn",icon:yr,action:()=>r.cancelTurn(),available:y},{id:"tab-turns",label:"Switch to Turns Tab",hint:"View conversation timeline",icon:O1,action:()=>r.switchRightTab("turns"),available:!!r.activeSessionId},{id:"tab-sidecar",label:"Ask Sidecar",hint:"Ask about this session — status, blockers, what is left",icon:vr,action:()=>r.switchRightTab("sidecar"),available:!!r.activeSessionId},{id:"toggle-right-panel",label:"Toggle Right Panel",hint:r.rightPanelCollapsed?"Expand the right panel":"Collapse the right panel to its icon rail",icon:W1,action:()=>r.toggleRightPanel(),available:!0},{id:"close-tab",label:"Close Tab",hint:"Close the active session tab",icon:Tn,action:()=>{r.activeSessionId&&r.closeTab(r.activeSessionId)},available:!!r.activeSessionId}]},[r]),m=x.useMemo(()=>{const k=o.toLowerCase().trim(),y=h.filter(S=>S.available);return k?y.filter(S=>S.label.toLowerCase().includes(k)||S.hint.toLowerCase().includes(k)):y},[h,o]);x.useEffect(()=>{e&&(l(""),d(0),setTimeout(()=>{var k;return(k=f.current)==null?void 0:k.focus()},50))},[e]);function v(k){if(k.key==="ArrowDown")k.preventDefault(),d(y=>Math.min(y+1,m.length-1));else if(k.key==="ArrowUp")k.preventDefault(),d(y=>Math.max(y-1,0));else if(k.key==="Enter"){k.preventDefault();const y=m[c];y&&(y.action(),n(!1))}else k.key==="Escape"&&n(!1)}return e?a.jsx("div",{className:"palette-overlay",onClick:()=>n(!1),children:a.jsxs("div",{className:"palette",onClick:k=>k.stopPropagation(),children:[a.jsxs("div",{className:"palette-search",children:[a.jsx("input",{ref:f,type:"text",placeholder:"Type a command…",value:o,onChange:k=>{l(k.target.value),d(0)},onKeyDown:v}),a.jsx("span",{className:"palette-esc",children:"ESC"})]}),m.length===0?a.jsx("div",{className:"palette-empty",children:"No matching commands"}):a.jsx("div",{className:"palette-list",children:m.map((k,y)=>{const S=k.icon;return a.jsxs("div",{className:`palette-item ${y===c?"selected":""}`,onClick:()=>{k.action(),n(!1)},onMouseEnter:()=>d(y),children:[a.jsx("span",{className:"palette-item-icon",children:a.jsx(S,{size:16})}),a.jsx("span",{className:"palette-item-label",children:k.label}),a.jsx("span",{className:"palette-item-hint",children:k.hint}),y===c&&a.jsx(T1,{size:12,className:"palette-item-enter"})]},k.id)})}),a.jsxs("div",{className:"palette-footer",children:[a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"↑"}),a.jsx("span",{className:"kbd",children:"↓"})," Navigate"]}),a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"↵"})," Select"]}),a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"Esc"})," Close"]})]})]})}):null}const Qg=/^[a-z][a-z0-9-]{1,30}$/,pj=2e3;function hj(){const{showRemoteModal:e,setShowRemoteModal:n,selectSession:r}=R(),[o,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(!1),[m,v]=x.useState(!1),[k,y]=x.useState(!1),[S,E]=x.useState(!1),[T,C]=x.useState("main"),[b,_]=x.useState(""),[z,M]=x.useState(!1),[L,G]=x.useState(null),P=x.useRef(null);Wi(P,()=>E(!1),S);const U=m||k,Q=x.useCallback(async()=>{h(!0),d(null);try{const F=await fetch(`${rn()}/remote/status`,{headers:{Accept:"application/json"}});if(!F.ok)throw new Error(`status ${F.status}`);l(await F.json())}catch{l(null),d("Machine management is only available from this machine's local pane.")}finally{h(!1)}},[]);x.useEffect(()=>{e&&(C("main"),G(null),Q())},[e,Q]);const J=L!==null&&L.state==="running";if(x.useEffect(()=>{if(!J)return;const F=setInterval(async()=>{try{const Z=await fetch(`${rn()}/remote/enable`,{headers:{Accept:"application/json"}});Z.ok&&G(await Z.json())}catch{}},pj);return()=>clearInterval(F)},[J]),!e)return null;const oe=!!(o!=null&&o.tunnel.provisioned)&&!!(o!=null&&o.service.running)&&!!(o!=null&&o.connection.ok);function me(F){F.key==="Escape"&&n(!1)}async function Se(F){if(Qg.test(F)){M(!0);try{const Z=await fetch(`${rn()}/remote/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mahlas:F})});if(!Z.ok)throw new Error(`enable ${Z.status}`);G(await Z.json()),C("setup")}catch{d("Could not start the setup — check the daemon logs.")}finally{M(!1)}}}function Me(){L!=null&&L.troubleshootingSessionId&&(r(L.troubleshootingSessionId),n(!1))}async function ee(){v(!0);try{await fetch(`${rn()}/remote/disable`,{method:"POST"}),await Q()}catch{d("Could not stop the tunnel service — check the service logs.")}finally{v(!1)}}async function ie(){if(E(!1),!!window.confirm(`Remove the tunnel completely?
836
+ }`;function HE(e){return`(${WE})(${JSON.stringify(e)});`}function Gg(e){return e.replace(/<\/script/gi,"<\\/script")}function VE(e,n){const r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(r,"gi");let l=-1,c;for(;(c=o.exec(e))!==null;)l=c.index;return l}function qg(e,n,r){const o=VE(e,n);return o===-1?e+r:e.slice(0,o)+r+e.slice(o)}function KE(e,n,r){let o=e;const l=`<script>${Gg(n)}<\/script>`;if(/<\/head>/i.test(o)?o=qg(o,"</head>",l):/<html[^>]*>/i.test(o)?o=o.replace(/(<html[^>]*>)/i,`$1<head>${l}</head>`):o=`${l}${o}`,r){const c=`<script>${Gg(r)}<\/script>`;o=qg(o,"</body>",c)}return o}function GE(){const e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?`tab-${e.randomUUID()}`:`tab-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function qE(e){var r;if(!(e instanceof Ui)||e.status!==409)return null;const n=(r=e.body)==null?void 0:r.state;return n&&typeof n=="object"?n:null}function XE({appId:e,workspace:n=""}){const r=x.useRef(null),o=x.useRef({pinned:!1,data:null}),[l,c]=x.useState(null),[d,f]=x.useState(null),[h,m]=x.useState([]);x.useEffect(()=>{let S=!0;const E=GE(),T=b=>{const _=o.current.version;typeof b.version=="number"&&typeof _=="number"&&b.version<_||(o.current=b)};Ww(e,b=>{var _,z;return(z=(_=r.current)==null?void 0:_.contentWindow)==null?void 0:z.postMessage(b,"*")},n);const C=async b=>{var P,U,Q,J,oe,me,Se,Me,ee,ie,te,F,Z,q,I,$,ue,B,X,ce,be,_e,Ae,je;if(b.source!==((P=r.current)==null?void 0:P.contentWindow))return;const _=b.data;if(!_||_.source!=="agentpane-app")return;if(_.report==="error"){const ge={message:String(_.message??"Unknown error"),stack:String(_.stack??"")};m(he=>{const Ve=he[he.length-1];return Ve&&Ve.message===ge.message?he:[...he,ge].slice(-20)});return}if(typeof _.method!="string")return;let z=!0,M,L,G=null;try{switch(_.method){case"getApp":M={id:e,workspace:n};break;case"getState":try{const ge=await jm(e,n);T(ge),M=ge}catch{M=o.current}break;case"setState":{const ge=((U=_.params)==null?void 0:U.data)??null,he=(Q=_.params)==null?void 0:Q.ifVersion,Ve={data:ge,writer:E};typeof he=="number"&&(Ve.ifVersion=he);try{const Ie=await Cv(e,Ve,n);T(Ie),M=Ie}catch(Ie){if(G=qE(Ie),!G)throw Ie;T(G);const mt=Ie.body;throw new Error(typeof(mt==null?void 0:mt.error)=="string"?mt.error:"App state changed since that version")}break}case"createSession":{const ge=_.params??{},he=await qd({title:typeof ge.title=="string"?ge.title:void 0,runtime_type:typeof ge.runtime_type=="string"?ge.runtime_type:void 0,model:typeof ge.model=="string"?ge.model:void 0,model_reasoning_effort:typeof ge.model_reasoning_effort=="string"?ge.model_reasoning_effort:void 0,cwd:typeof ge.cwd=="string"?ge.cwd:void 0,origin_app_id:e,origin_app_workspace:n});dl(he.id,e),R.getState().addSession(he),M=he;break}case"submitTurn":{const ge=String(((J=_.params)==null?void 0:J.sessionId)??"");if(!await _m(e,ge))throw new Error(`submitTurn: ${ge} is not a session of this app`);const he=String(((oe=_.params)==null?void 0:oe.prompt)??""),Ve=await BE(e,(me=_.params)==null?void 0:me.attachments,mt=>Xk(e,mt)),Ie=await dv(ge,he,Ve.length?Ve:void 0,{originAppId:e});dl(ge,e),M=Ie;break}case"getSession":{M=await _m(e,String(((Se=_.params)==null?void 0:Se.sessionId)??""));break}case"listSessions":{const ge=(Me=_.params)==null?void 0:Me.lifecycle,he=(ee=_.params)==null?void 0:ee.running;M=await Ok(e,n,{lifecycle:ge==="working"||ge==="finished"?ge:void 0,running:typeof he=="boolean"?he:void 0});break}case"getSessionInfo":{M=await $k(e,n,String(((ie=_.params)==null?void 0:ie.sessionId)??""));break}case"cancelTurn":{M=await Pk(e,String(((te=_.params)==null?void 0:te.sessionId)??""));break}case"setSessionLifecycle":{M=await zk(e,String(((F=_.params)==null?void 0:F.sessionId)??""),String(((Z=_.params)==null?void 0:Z.lifecycle)??""));break}case"callTool":{const ge=(q=_.params)==null?void 0:q.args;M=await Fk(e,n,String(((I=_.params)==null?void 0:I.tool)??""),ge&&typeof ge=="object"?ge:{});break}case"listProviders":{M=await Xy();break}case"listModels":{const ge=typeof(($=_.params)==null?void 0:$.runtime)=="string"?_.params.runtime.trim():"";if(!ge)throw new Error("listModels: runtime is required");const he=(ue=_.params)==null?void 0:ue.cwd;M=await Nv(ge,typeof he=="string"&&he?he:void 0);break}case"pickDirectory":{if(R.getState().activeAppTabId!==e)throw new Error("pickDirectory: the app is not on screen — call it from a click in the app");M=await pv();break}case"resolveToolCall":{const ge=String(((B=_.params)==null?void 0:B.callId)??""),he=(X=_.params)==null?void 0:X.result;await Vk(ge,he),M={ok:!0};break}case"openSession":{if(R.getState().activeAppTabId!==e)throw new Error("openSession: the app is not on screen — call it from a click in the app");const ge=typeof((ce=_.params)==null?void 0:ce.sessionId)=="string"?_.params.sessionId.trim():"";if(!ge)throw new Error("openSession: sessionId is required");try{await R.getState().revealSession(ge)}catch(he){throw new Error(`openSession: ${he instanceof Error?he.message:String(he)}`)}M={ok:!0};break}case"uploadFile":{const ge=await UE((be=_.params)==null?void 0:be.file);try{M=Kg(await Gk(e,ge))}catch(he){throw new Error(`uploadFile: ${he instanceof Error?he.message:String(he)}`)}break}case"getFile":{const ge=rx(e,(_e=_.params)==null?void 0:_e.ref),he=ge?await qk(e,ge):null;M=he?Kg(he):null;break}default:throw new Error(`Unknown bridge method: ${_.method}`)}}catch(ge){z=!1,L=ge instanceof Error?ge.message:String(ge)}(je=(Ae=r.current)==null?void 0:Ae.contentWindow)==null||je.postMessage(G?{source:"agentpane-host",id:_.id,ok:z,error:L,code:"conflict",state:G}:{source:"agentpane-host",id:_.id,ok:z,result:M,error:L},"*")};return window.addEventListener("message",C),Yw(e,b=>{var _,z;typeof b.workspace=="string"&&b.workspace!==n||b.writer!==E&&((z=(_=r.current)==null?void 0:_.contentWindow)==null||z.postMessage({source:"agentpane-host",event:"state_changed",payload:typeof b.version=="number"?{version:b.version}:{}},"*"))}),qw(e,()=>{Em(e).then(b=>{S&&(c(b),m([]))}).catch(()=>{})}),(async()=>{try{const[b,_,z]=await Promise.all([Em(e),jm(e,n),Lk(e).catch(()=>[])]);if(!S)return;o.current=_,z.forEach(M=>dl(M.id,e)),c(b)}catch(b){S&&f(b instanceof Error?b.message:String(b))}})(),()=>{S=!1,Hw(e),Xw(e),Qw(e),window.removeEventListener("message",C)}},[e,n]),x.useEffect(()=>{l&&Vw(e,l.manifest.headlessSessions===!0)},[e,l]);const v=x.useMemo(()=>l?KE(l.html,HE({appId:e,apiOrigin:sx()}),l.js):"",[l,e]);if(d)return a.jsxs("div",{className:"empty-state",style:{padding:"24px"},children:["Mini app failed to load: ",d]});if(!v)return a.jsx("div",{className:"empty-state",style:{padding:"24px"},children:"Loading mini app…"});const k=(l==null?void 0:l.diagnostics)??[],y=k.some(S=>S.severity==="error");return a.jsxs("div",{className:"miniapp-runtime",children:[k.length>0&&a.jsxs("div",{className:`miniapp-diagnostics${y?"":" miniapp-diagnostics-warn"}`,"data-testid":"miniapp-diagnostics",children:[a.jsx("div",{className:"miniapp-diagnostics-title",children:y?`Compile errors in ${(l==null?void 0:l.sourceFile)??"the app logic"} — the pane serves the last code that parsed:`:"Warnings — the app runs, but fix these:"}),k.map((S,E)=>a.jsxs("div",{className:"miniapp-diag",children:[S.file,":",S.line,":",S.column," — ",S.message]},E))]}),a.jsx("iframe",{ref:r,className:"miniapp-frame",sandbox:"allow-scripts allow-popups allow-popups-to-escape-sandbox",allow:"loopback-network; local-network; local-network-access",title:`Mini app: ${e}`,srcDoc:v}),h.length>0&&a.jsx("div",{className:"miniapp-rt-errors","data-testid":"miniapp-rt-errors",children:h.map((S,E)=>a.jsxs("div",{className:"miniapp-rt-error",children:[a.jsx("div",{className:"miniapp-rt-error-message",children:S.message}),S.stack&&a.jsx("pre",{className:"miniapp-rt-error-stack",children:S.stack})]},E))})]})}function YE({appId:e,active:n}){const r=R(y=>y.apps),o=R(y=>y.workspaces),l=R(y=>y.appWorkspaces),c=R(y=>y.setAppWorkspace),d=R(y=>y.setActiveAppTab),f=R(y=>y.startAppEdit),h=r.find(y=>y.id===e),m=l[e]??"",v=o.filter(y=>y.deleted!==1),k=m!==""&&!v.some(y=>y.path===m)?m:null;return a.jsxs("div",{className:`miniapp-view ${n?"":"miniapp-view-hidden"}`,children:[a.jsxs("div",{className:"miniapp-header",children:[a.jsx(Do,{iconNode:h==null?void 0:h.iconNode,size:14,className:"miniapp-header-icon"}),a.jsx("span",{className:"miniapp-header-title",children:(h==null?void 0:h.title)??e}),a.jsxs("select",{className:"miniapp-workspace-select",title:"Workspace this app instance is bound to (state and pinning are scoped per workspace)",value:m,onChange:y=>c(e,y.target.value),children:[a.jsx("option",{value:"",children:"All workspaces (global)"}),v.map(y=>a.jsx("option",{value:y.path,children:y.label||y.path.split("/").pop()||y.path},y.path)),k&&a.jsx("option",{value:k,children:`${k} (unknown workspace)`})]}),a.jsxs("button",{className:"miniapp-header-btn",title:"Edit this app with the agent (opens an edit session on the app folder)",onClick:()=>void f(e),children:[a.jsx(V1,{size:13}),"Edit"]}),a.jsx("button",{className:"miniapp-header-close",title:"Close app",onClick:()=>d(null),children:a.jsx(Tn,{size:14})})]}),a.jsx("div",{className:"miniapp-body",children:a.jsx(XE,{appId:e,workspace:m},`${e}:${m}`)})]})}function QE({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l}){const[c,d]=x.useState(!1),f=x.useRef(0),h=x.useRef(0),m=x.useCallback(y=>{const S=y.clientX-f.current,E=e==="left"?h.current+S:h.current-S,T=Math.min(r,Math.max(n,E));l(T)},[e,n,r,l]),v=x.useCallback(()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",v),document.body.classList.remove("is-resizing"),d(!1)},[m]);return{onPointerDown:x.useCallback(y=>{var S,E;y.preventDefault(),y.stopPropagation();try{(E=(S=y.currentTarget)==null?void 0:S.setPointerCapture)==null||E.call(S,y.pointerId)}catch{}f.current=y.clientX,h.current=o(),d(!0),document.body.classList.add("is-resizing"),window.addEventListener("pointermove",m),window.addEventListener("pointerup",v)},[o,m,v]),dragging:c}}function Xg({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l}){const{onPointerDown:c,dragging:d}=QE({side:e,minWidth:n,maxWidth:r,getWidth:o,setWidth:l});return a.jsx("div",{className:`resize-handle ${e}${d?" dragging":""}`,onPointerDown:c,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${e} panel`,"data-resizing":d?"":void 0})}const ZE=x.lazy(()=>f1(()=>import("./TerminalView-BF35pnWS.js"),__vite__mapDeps([0,1])));function JE(){Lt.trackRender("IdeWorkspace");const e=R(S=>S.sidebarWidth),n=R(S=>S.rightPanelWidth),r=R(S=>S.setSidebarWidth),o=R(S=>S.setRightPanelWidth),l=R(S=>S.rightPanelCollapsed),c=R(S=>S.vscodeViewOpen),d=R(S=>S.usageViewOpen),f=R(S=>S.terminalViewOpen),[h,m]=x.useState(!1);f&&!h&&m(!0);const v=R(S=>S.activeAppTabId),k=R(S=>S.openAppTabs);x.useEffect(()=>{const S=()=>{const E=Nl(),{rightPanelWidth:T,setRightPanelWidth:C}=R.getState();T>E&&C(E)};return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);const y=l?`${e}px 6px 1fr ${jk}px`:`${e}px 6px 1fr 6px ${n}px`;return a.jsxs("div",{className:"ide-root",children:[a.jsx(OE,{}),a.jsxs("div",{className:`ide-layout ${c||d||f?"ide-hidden":""}`,style:{gridTemplateColumns:y},children:[a.jsx(tN,{}),a.jsx(Xg,{side:"left",minWidth:kd,maxWidth:Sd,getWidth:()=>R.getState().sidebarWidth,setWidth:r}),a.jsxs("div",{className:"ide-center",children:[a.jsx(rN,{}),a.jsxs("div",{className:"ide-render",children:[k.map(S=>a.jsx(YE,{appId:S,active:v===S},S)),v==null&&a.jsx(vC,{})]}),a.jsx(jC,{})]}),!l&&a.jsx(Xg,{side:"right",minWidth:bl,maxWidth:Nl(),getWidth:()=>R.getState().rightPanelWidth,setWidth:o}),a.jsx(YC,{})]}),c&&a.jsx(uE,{}),d&&a.jsx(LE,{}),h&&a.jsx(x.Suspense,{fallback:null,children:a.jsx(ZE,{visible:f})}),a.jsx(oE,{})]})}function ej(){const{showNewSessionDialog:e,setShowNewSessionDialog:n,createSession:r,lastModelConfig:o}=R(),l=(o==null?void 0:o.provider)??"codex",c=(o==null?void 0:o.model)??"",d=(o==null?void 0:o.reasoning)??"",[f,h]=x.useState(""),[m,v]=x.useState(c),[k,y]=x.useState(d),[S,E]=x.useState("");if(!e)return null;const T=jf(l),C=m?Fd(l,m):[];function b(){r({title:f.trim()||void 0,model:m||void 0,model_reasoning_effort:k||void 0,cwd:S.trim()||void 0,runtime_type:l}),h(""),E("")}function _(M){M.key==="Escape"&&n(!1)}function z(M){var P;v(M);const L=Fd(l,M);L.some(U=>U.effort===k)||y(Ud(l,M)??((P=L[0])==null?void 0:P.effort)??"")}return a.jsx("div",{className:"dialog-overlay",onClick:()=>n(!1),children:a.jsxs("div",{className:"dialog",onClick:M=>M.stopPropagation(),onKeyDown:_,children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",children:"New Session"}),a.jsx("button",{className:"dialog-close",onClick:()=>n(!1),children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("label",{className:"dialog-label",children:["Title (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:f,onChange:M=>h(M.target.value),placeholder:"e.g. refactor auth module",autoFocus:!0})]}),a.jsxs("label",{className:"dialog-label",children:["Model",a.jsxs("select",{className:"dialog-input dialog-select",value:m,onChange:M=>z(M.target.value),children:[a.jsx("option",{value:"",children:"Default (Codex picks)"}),T.map(M=>a.jsxs("option",{value:M.slug,children:[M.displayName," — ",M.description]},M.slug))]})]}),C.length>0&&a.jsxs("label",{className:"dialog-label",children:["Thinking Level",a.jsxs("select",{className:"dialog-input dialog-select",value:k,onChange:M=>y(M.target.value),children:[a.jsxs("option",{value:"",children:["Default (",Ud(l,m),")"]}),C.map(M=>a.jsx("option",{value:M.effort,children:M.label},M.effort))]})]}),a.jsxs("label",{className:"dialog-label",children:["Working Directory (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:S,onChange:M=>E(M.target.value),placeholder:"e.g. /Users/me/projects/my-app"})]})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:()=>n(!1),children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:b,children:"Create"})]})]})})}function tj(e,n){const r=n!==""&&(e===n||e.startsWith(`${n}/`)),o=[r?{label:"~",path:n}:{label:"/",path:"/"}],l=e.slice(r?n.length:0);let c=o[0].path;for(const d of l.split("/").filter(Boolean))c=c==="/"?`/${d}`:`${c}/${d}`,o.push({label:d,path:c});return o}function nj(e){const n=e.filter(l=>l.deleted===0).at(-1);if(!n)return;const r=gr(n.path),o=r.lastIndexOf("/");return o>0?r.slice(0,o):void 0}function sj(){return R(n=>n.showAddWorkspaceDialog)?a.jsx(rj,{}):null}function rj(){var P;const e=R(U=>U.setShowAddWorkspaceDialog),n=R(U=>U.workspaces),r=R(U=>U.createWorkspaceAt),o=R(U=>U.addToast),[l,c]=x.useState(null),[d,f]=x.useState(!0),[h,m]=x.useState(null),[v,k]=x.useState(!1),y=x.useRef(0),[S]=x.useState(()=>nj(R.getState().workspaces)),E=x.useRef(null),T=x.useCallback(()=>{v||e(!1)},[v,e]);Io(T);const C=x.useCallback(async(U,Q=!1)=>{const J=++y.current;f(!0);let oe=null,me=null;try{oe=await cm(U)}catch(Se){if(me=hr(Se),Q&&U)try{oe=await cm(),me=null}catch(Me){me=hr(Me)}}J===y.current&&(oe&&c(oe),m(me),f(!1))},[]);x.useEffect(()=>{C(S,!0)},[C,S]);const b=l==null?void 0:l.path;x.useEffect(()=>{E.current&&(E.current.scrollTop=0)},[b]);const _=new Set(n.filter(U=>U.deleted===0).map(U=>gr(U.path)));async function z(U){if(!v){k(!0),m(null);try{const Q=await r(U);e(!1),o("success",`Workspace added — ${Q.path}`)}catch(Q){m(hr(Q)),k(!1)}}}const M=l?tj(l.path,l.home):[],L=((P=M.at(-1))==null?void 0:P.label)??"",G=l!==null&&_.has(gr(l.path));return a.jsx("div",{className:"dialog-overlay",onClick:T,children:a.jsxs("div",{className:"dialog folder-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"folder-dialog-title",onClick:U=>U.stopPropagation(),children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",id:"folder-dialog-title",children:"Add workspace"}),a.jsx("button",{className:"dialog-close",onClick:T,"aria-label":"Close",disabled:v,children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("p",{className:"dialog-hint",children:["Choose a project folder",l&&a.jsxs(a.Fragment,{children:[" ","on ",a.jsx("strong",{children:l.hostname})]}),"."]}),a.jsxs("div",{className:"folder-nav",children:[a.jsx("button",{className:"folder-up",onClick:()=>(l==null?void 0:l.parent)&&void C(l.parent),disabled:!(l!=null&&l.parent),"aria-label":"Parent folder",title:"Parent folder",children:a.jsx(Mv,{size:14})}),a.jsx("nav",{className:"folder-crumbs","aria-label":"Folder path",children:M.map((U,Q)=>a.jsxs(x.Fragment,{children:[Q>0&&a.jsx(Li,{size:12,className:"folder-crumb-sep","aria-hidden":"true"}),Q===M.length-1?a.jsx("span",{className:"folder-crumb current","aria-current":"location",title:U.path,children:U.label}):a.jsx("button",{className:"folder-crumb",onClick:()=>void C(U.path),title:U.path,children:U.label})]},U.path))}),d&&l&&a.jsx(mn,{size:14,className:"spin folder-spinner","aria-label":"Loading"})]}),a.jsx("ul",{ref:E,className:`folder-list${d&&l?" loading":""}`,"aria-label":"Folders",children:l?l.folders.length===0?a.jsx("li",{className:"folder-empty",children:"No folders here."}):l.folders.map(U=>a.jsxs("li",{className:"folder-item",children:[a.jsxs("button",{className:"folder-row",onClick:()=>void C(U.path),title:U.path,"aria-label":U.git?`${U.name} (git repository)`:U.name,children:[U.git?a.jsx(j1,{size:15,className:"folder-icon git","aria-hidden":"true"}):a.jsx(Rl,{size:15,className:"folder-icon","aria-hidden":"true"}),a.jsx("span",{className:"folder-name",children:U.name}),a.jsx(Li,{size:13,className:"folder-chevron","aria-hidden":"true"})]}),_.has(gr(U.path))?a.jsx("span",{className:"folder-tag",children:"Added"}):a.jsx("button",{className:"folder-add",onClick:()=>void z(U.path),disabled:v,"aria-label":`Add ${U.name}`,children:"Add"})]},U.path)):d&&a.jsxs("li",{className:"folder-empty",role:"status",children:[a.jsx(mn,{size:14,className:"spin"})," Loading folders…"]})}),(l==null?void 0:l.truncated)&&a.jsxs("p",{className:"folder-note",children:["Showing the first ",l.folders.length," folders."]}),h&&a.jsx("p",{className:"folder-error",role:"alert",children:h})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:T,disabled:v,children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:()=>l&&void z(l.path),disabled:!l||d||v||G,children:v?"Adding…":G?"Already added":`Add “${L}”`})]})]})})}const Wd=6e4,Hd=60*Wd,ul=24*Hd;function oj(e,n=Date.now()){const r=Date.parse(e);if(Number.isNaN(r))return"";const o=Math.max(0,n-r);return o<Wd?"just now":o<Hd?`${Math.floor(o/Wd)} min ago`:o<ul?`${Math.floor(o/Hd)} h ago`:o<2*ul?"yesterday":o<7*ul?`${Math.floor(o/ul)} days ago`:new Date(r).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function ij(){const e=R(n=>n.importSessionsWorkspace);return e?a.jsx(aj,{workspace:e},e):null}function aj({workspace:e}){const n=R(P=>P.setImportSessionsWorkspace),r=R(P=>P.importSessions),[o,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState({}),[m,v]=x.useState(new Set),[k,y]=x.useState(!1),[S,E]=x.useState(new Map),T=x.useCallback(()=>{k||n(null)},[k,n]);Io(T),x.useEffect(()=>{let P=!1;return bv(e).then(({sessions:U,errors:Q})=>{if(P)return;const J=Object.values(Q);if(J.length===wd.length){d([...new Set(J)].join("; "));return}l(U),h(Q)}).catch(U=>{P||d(hr(U))}),()=>{P=!0}},[e]);function C(P){v(U=>{const Q=new Set(U);return Q.has(P)?Q.delete(P):Q.add(P),Q})}const b=o??[],_=P=>Qu({runtime:P.runtime,id:P.session_id}),z=b.length>0&&b.every(P=>m.has(_(P)));async function M(){const P=b.filter(J=>m.has(_(J))).map(J=>({runtime:J.runtime,id:J.session_id}));if(P.length===0)return;y(!0);const{failed:U}=await r(e,P);if(y(!1),U.length===0){n(null);return}const Q=new Set(U.map(Qu));l(J=>(J??[]).filter(oe=>!m.has(_(oe))||Q.has(_(oe)))),v(Q),E(new Map(U.map(J=>[Qu(J),J.error])))}const L=e.split("/").pop()||e,G=m.size;return a.jsx("div",{className:"dialog-overlay",onClick:T,children:a.jsxs("div",{className:"dialog import-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"import-dialog-title",onClick:P=>P.stopPropagation(),children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",id:"import-dialog-title",children:"Import sessions"}),a.jsx("button",{className:"dialog-close",onClick:T,"aria-label":"Close",disabled:k,children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[a.jsxs("p",{className:"dialog-hint",children:["Sessions you started with ",a.jsx("code",{children:"claude"})," or ",a.jsx("code",{children:"codex"})," in"," ",a.jsx("strong",{title:e,children:L}),", in a terminal or an IDE. An imported session keeps its history and continues the same conversation."]}),c?a.jsxs("p",{className:"import-error",role:"alert",children:["Could not list the sessions — ",c]}):o===null?a.jsxs("div",{className:"import-loading",role:"status",children:[a.jsx(mn,{size:14,className:"spin"})," Looking for sessions…"]}):o.length===0?a.jsxs("div",{className:"import-empty",children:["No Claude Code or Codex sessions to import here. Sessions you start with ",a.jsx("code",{children:"claude"})," or"," ",a.jsx("code",{children:"codex"})," in this folder will show up here.",a.jsx(Yg,{errors:f})]}):a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"import-select-all",children:[a.jsx("input",{type:"checkbox",checked:z,disabled:k,onChange:()=>v(z?new Set:new Set(b.map(_)))}),"Select all (",o.length,")"]}),a.jsx("ul",{className:"import-list",children:o.map(P=>{const U=_(P),Q=S.get(U);return a.jsx("li",{children:a.jsxs("label",{className:`import-row${m.has(U)?" selected":""}`,children:[a.jsx("input",{type:"checkbox",checked:m.has(U),disabled:k,onChange:()=>C(U)}),a.jsxs("span",{className:"import-row-main",children:[a.jsx("span",{className:"import-row-title",title:P.title,children:P.title}),a.jsxs("span",{className:"import-row-meta",children:[a.jsx("span",{className:`import-row-runtime ${P.runtime}`,children:Ql[P.runtime]}),a.jsx("span",{title:new Date(P.last_modified).toLocaleString(),children:oj(P.last_modified)}),P.git_branch&&a.jsxs("span",{className:"import-row-branch",title:"Git branch",children:[a.jsx(Pv,{size:10})," ",P.git_branch]})]}),P.recently_active&&a.jsxs("span",{className:"import-row-warn",children:[a.jsx(tc,{size:11})," Active in the last few minutes. If it is still open in a terminal, close it there first: both would write to the same session."]}),Q&&a.jsx("span",{className:"import-row-error",role:"alert",children:Q})]})]})},U)})}),a.jsx(Yg,{errors:f})]})]}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:T,disabled:k,children:"Cancel"}),a.jsx("button",{className:"dialog-btn-create",onClick:()=>void M(),disabled:G===0||k,children:k?a.jsxs(a.Fragment,{children:[a.jsx(mn,{size:12,className:"spin"})," Importing…"]}):G>1?`Import ${G} sessions`:"Import"})]})]})})}function Yg({errors:e}){const n=Object.entries(e);return n.length===0?null:a.jsx(a.Fragment,{children:n.map(([r,o])=>a.jsxs("p",{className:"import-note",children:["Could not list the ",Ql[r]," sessions — ",o]},r))})}const lj=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,cj=512*1024;function uj(e){const n=e.toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"");return/^[a-z0-9]/.test(n)?n:""}function dj(){const{appCatalogOpen:e,closeAppCatalog:n,apps:r,installExampleApp:o,createSkeletonApp:l,importAppFolder:c}=R(),[d,f]=x.useState("examples"),[h,m]=x.useState(null),[v,k]=x.useState(null),[y,S]=x.useState(!1),[E,T]=x.useState(""),[C,b]=x.useState(""),[_,z]=x.useState(""),[M,L]=x.useState(""),[G,P]=x.useState(null),[U,Q]=x.useState(""),J=x.useRef(null);if(x.useEffect(()=>{e&&(m(null),Uk().then(m).catch(()=>m([])))},[e]),x.useEffect(()=>{J.current&&(J.current.webkitdirectory=!0)},[d]),!e)return null;const oe=new Set(r.map(F=>F.id));async function me(F){k(F);try{await o(F)&&n()}finally{k(null)}}async function Se(){if(y)return;const F=E.trim(),Z=C.trim();if(!(!F||!Z)){S(!0);try{await l({id:F,title:Z,description:_.trim()||void 0,icon:M.trim()||void 0})&&(T(""),b(""),z(""),L(""),n())}finally{S(!1)}}}async function Me(F){const Z=Array.from(F.target.files??[]),q={};let I="";for(const $ of Z){const B=($.webkitRelativePath??"").split("/");!I&&B.length>1&&(I=B[0]);const X=B[B.length-1];if(!(!X||!lj.test(X))&&!($.size>cj))try{q[X]=await $.text()}catch{}}P(Object.keys(q).length>0?q:null),Q(uj(I))}async function ee(){if(!(y||!G||!U.trim())){S(!0);try{await c(U.trim(),G)&&(P(null),Q(""),n())}finally{S(!1)}}}function ie(F){F.key==="Escape"&&n()}const te=[{key:"examples",label:"Examples"},{key:"new",label:"New App"},{key:"upload",label:"Upload"}];return a.jsx("div",{className:"dialog-overlay",onClick:n,children:a.jsxs("div",{className:"dialog app-catalog",onClick:F=>F.stopPropagation(),onKeyDown:ie,children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",children:"Add Mini App"}),a.jsx("button",{className:"dialog-close",onClick:n,children:"✕"})]}),a.jsx("div",{className:"catalog-tabs",children:te.map(F=>a.jsx("button",{className:`catalog-tab${d===F.key?" active":""}`,onClick:()=>f(F.key),children:F.label},F.key))}),a.jsxs("div",{className:"dialog-body catalog-body",children:[d==="examples"&&a.jsx("div",{className:"catalog-examples",children:h===null?a.jsx("div",{className:"empty-state",style:{padding:"12px"},children:"Loading examples…"}):h.length===0?a.jsx("div",{className:"empty-state",style:{padding:"12px"},children:"No example apps available."}):h.map(F=>{const Z=oe.has(F.id);return a.jsxs("div",{className:"example-row",children:[a.jsx(Do,{iconNode:F.iconNode,size:14,className:"sidebar-app-icon"}),a.jsxs("div",{className:"example-info",children:[a.jsx("span",{className:"example-title",children:F.title}),F.description&&a.jsx("span",{className:"example-desc",children:F.description})]}),a.jsx("button",{className:"example-install",disabled:Z||v===F.id,onClick:()=>me(F.id),title:Z?"Already installed":"Install this example",children:Z?"Installed":v===F.id?"Installing…":"Install"})]},F.id)})}),d==="new"&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"dialog-label",children:["App id (folder name)",a.jsx("input",{className:"dialog-input",type:"text",value:E,onChange:F=>T(F.target.value),placeholder:"e.g. todo-list",autoFocus:!0})]}),a.jsxs("label",{className:"dialog-label",children:["Title",a.jsx("input",{className:"dialog-input",type:"text",value:C,onChange:F=>b(F.target.value),placeholder:"e.g. Todo List"})]}),a.jsxs("label",{className:"dialog-label",children:["Description (optional)",a.jsx("input",{className:"dialog-input",type:"text",value:_,onChange:F=>z(F.target.value),placeholder:"What does this app do?"})]}),a.jsxs("label",{className:"dialog-label",children:[a.jsxs("span",{children:["Icon (optional, a"," ",a.jsx("a",{href:"https://lucide.dev/icons",target:"_blank",rel:"noreferrer",children:"Lucide icon"})," ","name)"]}),a.jsx("input",{className:"dialog-input",type:"text",value:M,onChange:F=>L(F.target.value),placeholder:"e.g. notebook-pen",spellCheck:!1,autoCapitalize:"off"})]}),a.jsxs("button",{className:"dialog-btn-create catalog-action-btn",disabled:y||!E.trim()||!C.trim(),onClick:Se,children:[a.jsx(pr,{size:13})," Create App"]})]}),d==="upload"&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"catalog-upload-hint",children:"Select an app folder from disk. Text files only (manifest.json, index.html, app.ts (or legacy app.js), …). A missing manifest.json is generated from the folder name."}),a.jsx("input",{ref:J,type:"file",multiple:!0,onChange:Me}),G&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"dialog-label",children:["App id",a.jsx("input",{className:"dialog-input",type:"text",value:U,onChange:F=>Q(F.target.value)})]}),a.jsxs("div",{className:"catalog-upload-summary",children:[Object.keys(G).length," file(s):"," ",Object.keys(G).slice(0,6).join(", "),Object.keys(G).length>6?", …":""]})]}),a.jsxs("button",{className:"dialog-btn-create catalog-action-btn",disabled:y||!G||!U.trim(),onClick:ee,children:[a.jsx(Z1,{size:13})," Import App"]})]})]}),a.jsx("div",{className:"dialog-footer",children:a.jsx("button",{className:"dialog-btn-cancel",onClick:n,children:"Close"})})]})})}function fj(){const e=R(k=>k.showCommandPalette),n=R(k=>k.setShowCommandPalette),r=R(),[o,l]=x.useState(""),[c,d]=x.useState(0),f=x.useRef(null),h=x.useMemo(()=>{const k=r.activeSessionId?r.sessionDetails[r.activeSessionId]:null,y=ql(k);return[{id:"new-session",label:"New Session",hint:"Create a new Codex session",icon:pr,action:()=>r.setShowNewSessionDialog(!0),available:!0},{id:"delete-session",label:"Delete Session",hint:"Delete the active session",icon:us,action:()=>{r.activeSessionId&&r.deleteSession(r.activeSessionId)},available:!!r.activeSessionId},{id:"send-message",label:"Send Message",hint:"Focus the message input",icon:Hi,action:()=>{const S=document.querySelector(".cmd-input");S==null||S.focus()},available:!!r.activeSessionId&&!y},{id:"cancel-turn",label:"Cancel Turn",hint:"Cancel the running turn",icon:yr,action:()=>r.cancelTurn(),available:y},{id:"tab-turns",label:"Switch to Turns Tab",hint:"View conversation timeline",icon:O1,action:()=>r.switchRightTab("turns"),available:!!r.activeSessionId},{id:"tab-sidecar",label:"Ask Sidecar",hint:"Ask about this session — status, blockers, what is left",icon:vr,action:()=>r.switchRightTab("sidecar"),available:!!r.activeSessionId},{id:"toggle-right-panel",label:"Toggle Right Panel",hint:r.rightPanelCollapsed?"Expand the right panel":"Collapse the right panel to its icon rail",icon:W1,action:()=>r.toggleRightPanel(),available:!0},{id:"close-tab",label:"Close Tab",hint:"Close the active session tab",icon:Tn,action:()=>{r.activeSessionId&&r.closeTab(r.activeSessionId)},available:!!r.activeSessionId}]},[r]),m=x.useMemo(()=>{const k=o.toLowerCase().trim(),y=h.filter(S=>S.available);return k?y.filter(S=>S.label.toLowerCase().includes(k)||S.hint.toLowerCase().includes(k)):y},[h,o]);x.useEffect(()=>{e&&(l(""),d(0),setTimeout(()=>{var k;return(k=f.current)==null?void 0:k.focus()},50))},[e]);function v(k){if(k.key==="ArrowDown")k.preventDefault(),d(y=>Math.min(y+1,m.length-1));else if(k.key==="ArrowUp")k.preventDefault(),d(y=>Math.max(y-1,0));else if(k.key==="Enter"){k.preventDefault();const y=m[c];y&&(y.action(),n(!1))}else k.key==="Escape"&&n(!1)}return e?a.jsx("div",{className:"palette-overlay",onClick:()=>n(!1),children:a.jsxs("div",{className:"palette",onClick:k=>k.stopPropagation(),children:[a.jsxs("div",{className:"palette-search",children:[a.jsx("input",{ref:f,type:"text",placeholder:"Type a command…",value:o,onChange:k=>{l(k.target.value),d(0)},onKeyDown:v}),a.jsx("span",{className:"palette-esc",children:"ESC"})]}),m.length===0?a.jsx("div",{className:"palette-empty",children:"No matching commands"}):a.jsx("div",{className:"palette-list",children:m.map((k,y)=>{const S=k.icon;return a.jsxs("div",{className:`palette-item ${y===c?"selected":""}`,onClick:()=>{k.action(),n(!1)},onMouseEnter:()=>d(y),children:[a.jsx("span",{className:"palette-item-icon",children:a.jsx(S,{size:16})}),a.jsx("span",{className:"palette-item-label",children:k.label}),a.jsx("span",{className:"palette-item-hint",children:k.hint}),y===c&&a.jsx(T1,{size:12,className:"palette-item-enter"})]},k.id)})}),a.jsxs("div",{className:"palette-footer",children:[a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"↑"}),a.jsx("span",{className:"kbd",children:"↓"})," Navigate"]}),a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"↵"})," Select"]}),a.jsxs("span",{className:"palette-footer-hint",children:[a.jsx("span",{className:"kbd",children:"Esc"})," Close"]})]})]})}):null}const Qg=/^[a-z][a-z0-9-]{1,30}$/,pj=2e3;function hj(){const{showRemoteModal:e,setShowRemoteModal:n,selectSession:r}=R(),[o,l]=x.useState(null),[c,d]=x.useState(null),[f,h]=x.useState(!1),[m,v]=x.useState(!1),[k,y]=x.useState(!1),[S,E]=x.useState(!1),[T,C]=x.useState("main"),[b,_]=x.useState(""),[z,M]=x.useState(!1),[L,G]=x.useState(null),P=x.useRef(null);Wi(P,()=>E(!1),S);const U=m||k,Q=x.useCallback(async()=>{h(!0),d(null);try{const F=await fetch(`${rn()}/remote/status`,{headers:{Accept:"application/json"}});if(!F.ok)throw new Error(`status ${F.status}`);l(await F.json())}catch{l(null),d("Machine management is only available from this machine's local pane.")}finally{h(!1)}},[]);x.useEffect(()=>{e&&(C("main"),G(null),Q())},[e,Q]);const J=L!==null&&L.state==="running";if(x.useEffect(()=>{if(!J)return;const F=setInterval(async()=>{try{const Z=await fetch(`${rn()}/remote/enable`,{headers:{Accept:"application/json"}});Z.ok&&G(await Z.json())}catch{}},pj);return()=>clearInterval(F)},[J]),!e)return null;const oe=!!(o!=null&&o.tunnel.provisioned)&&!!(o!=null&&o.service.running)&&!!(o!=null&&o.connection.ok);function me(F){F.key==="Escape"&&n(!1)}async function Se(F){if(Qg.test(F)){M(!0);try{const Z=await fetch(`${rn()}/remote/enable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mahlas:F})});if(!Z.ok)throw new Error(`enable ${Z.status}`);G(await Z.json()),C("setup")}catch{d("Could not start the setup — check the daemon logs.")}finally{M(!1)}}}function Me(){L!=null&&L.troubleshootingSessionId&&(r(L.troubleshootingSessionId),n(!1))}async function ee(){v(!0);try{await fetch(`${rn()}/remote/disable`,{method:"POST"}),await Q()}catch{d("Could not stop the tunnel service — check the service logs.")}finally{v(!1)}}async function ie(){if(E(!1),!!window.confirm(`Remove the tunnel completely?
837
837
 
838
- This deletes the Cloudflare tunnel, its DNS record and Access app, and this machine's remote state. The mahlas is released.
838
+ This deletes the Cloudflare tunnel, its DNS record and sign-in sessions, and this machine's remote state. The mahlas is released.
839
839
 
840
840
  This cannot be undone.`)){y(!0);try{const Z=await fetch(`${rn()}/remote/uninstall`,{method:"DELETE"});if(!Z.ok)throw new Error(`uninstall ${Z.status}`);await Q()}catch{d("Could not remove the tunnel — check the daemon logs.")}finally{y(!1)}}}function te(){if(!L)return a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"dialog-label",children:["Machine name (mahlas)",a.jsx("input",{className:"dialog-input",value:b,onChange:I=>_(I.target.value.toLowerCase()),placeholder:"my-macbook",autoFocus:!0})]}),a.jsx("div",{className:"dialog-label",style:{opacity:.7,marginTop:-4},children:"The machine will be reachable at https://<name>.repoburg.com"}),a.jsxs("div",{className:"dialog-footer",children:[a.jsx("button",{className:"dialog-btn-cancel",onClick:()=>C("main"),children:"Back"}),a.jsxs("button",{className:"dialog-btn-create",disabled:!Qg.test(b)||z,onClick:()=>void Se(b),children:[z?a.jsx(mn,{size:14,className:"spin",style:{verticalAlign:"middle",marginRight:6}}):null,"Start setup"]})]})]});const F=["detect","provision","install","verify","ready"],Z=F.indexOf(L.step),q=L.state==="ready";return a.jsxs(a.Fragment,{children:[L.state==="running"&&a.jsxs("div",{className:"dialog-label",style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx(mn,{size:14,className:"spin"})," Setting up the remote tunnel…"]}),L.state==="ready"&&a.jsxs("div",{className:"dialog-label",style:{color:"var(--green)",display:"flex",alignItems:"center",gap:6},children:[a.jsx(Cs,{size:14})," Setup complete — you can close this window."]}),L.state==="ready"&&L.hostname&&a.jsxs("div",{className:"dialog-label",children:["This machine is accessible at"," ",a.jsx("a",{href:`https://${L.hostname}`,target:"_blank",rel:"noreferrer",children:L.hostname})]}),a.jsx("ol",{className:"dialog-label",style:{margin:"4px 0",paddingLeft:0,listStyle:"none"},children:F.map((I,$)=>{const ue=q||Z>-1&&$<Z,B=!q&&$===Z&&L.state==="running";return a.jsxs("li",{style:{display:"flex",alignItems:"center",gap:6,opacity:ue||B?1:.4,color:ue?"var(--green)":void 0},children:[ue?a.jsx(Cs,{size:13}):B?a.jsx(mn,{size:13,className:"spin"}):a.jsx(b1,{size:9,style:{marginLeft:2,marginRight:2}}),I]},I)})}),L.logs.length>0&&a.jsx("div",{className:"dialog-label",style:{opacity:.7,fontSize:12,whiteSpace:"pre-wrap"},children:L.logs.slice(-3).map(I=>I.message).join(`
841
841
  `)}),L.state==="troubleshooting"&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"dialog-label",style:{color:"var(--red)"},children:"Setup failed — a troubleshooting session is open and the agent is working on the fix in the background."}),a.jsx("div",{className:"dialog-footer",children:a.jsx("button",{className:"dialog-btn-create",onClick:Me,children:"Open troubleshooting session"})})]}),L.state==="failed"&&a.jsxs("div",{className:"dialog-label",style:{color:"var(--red)"},children:["Setup failed: ",L.error]}),a.jsx("div",{className:"dialog-footer",children:a.jsx("button",{className:"dialog-btn-cancel",onClick:()=>void Q(),children:"Refresh status"})})]})}return a.jsx("div",{className:"dialog-overlay",onClick:()=>n(!1),children:a.jsxs("div",{className:"dialog",onClick:F=>F.stopPropagation(),onKeyDown:me,children:[a.jsxs("div",{className:"dialog-header",children:[a.jsx("span",{className:"dialog-title",children:"Remote Access"}),a.jsx("button",{className:"dialog-close",onClick:()=>n(!1),children:a.jsx(Tn,{size:16})})]}),a.jsxs("div",{className:"dialog-body",children:[f&&a.jsxs("div",{className:"dialog-label",style:{display:"flex",alignItems:"center",gap:6},children:[a.jsx(mn,{size:14,className:"spin"})," Loading machine status…"]}),c&&a.jsx("div",{className:"dialog-label",style:{color:"var(--red)"},children:c}),T==="setup"?te():a.jsxs(a.Fragment,{children:[oe&&(o==null?void 0:o.tunnel.hostname)&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"dialog-label",children:["This machine is reachable at"," ",a.jsx("a",{href:`https://${o.tunnel.hostname}`,target:"_blank",rel:"noreferrer",children:o.tunnel.hostname})]}),a.jsxs("div",{style:{position:"relative",display:"flex",marginTop:8},children:[a.jsxs("button",{className:"dialog-btn-cancel",style:{flex:1,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>void ee(),disabled:U,children:[m?a.jsx(mn,{size:14,className:"spin",style:{verticalAlign:"middle",marginRight:6}}):null,"Stop tunnel connection"]}),a.jsx("button",{className:"dialog-btn-cancel",style:{width:30,borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0,display:"inline-flex",alignItems:"center",justifyContent:"center"},onClick:()=>E(F=>!F),disabled:U,"aria-label":"More tunnel actions","aria-haspopup":"menu","aria-expanded":S,children:k?a.jsx(mn,{size:14,className:"spin"}):a.jsx(_o,{size:14})}),S&&a.jsx("div",{ref:P,className:"ctx-menu",role:"menu",style:{position:"absolute",right:0,top:"calc(100% + 4px)",zIndex:10},children:a.jsxs("div",{className:"ctx-menu-item ctx-danger",role:"menuitem",onClick:()=>void ie(),children:[a.jsx(us,{size:12})," Remove tunnel"]})})]})]}),!oe&&a.jsx(a.Fragment,{children:o!=null&&o.tunnel.provisioned&&o.tunnel.mahlas&&o.tunnel.hostname?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"dialog-label",children:["Tunnel exists as"," ",a.jsx("a",{href:`https://${o.tunnel.hostname}`,target:"_blank",rel:"noreferrer",children:o.tunnel.hostname})," ","but the connection is stopped."]}),a.jsxs("button",{className:"dialog-btn-create",style:{width:"100%"},onClick:()=>void Se(o.tunnel.mahlas),disabled:z,children:[z?a.jsx(mn,{size:14,className:"spin",style:{verticalAlign:"middle",marginRight:6}}):a.jsx(Lm,{size:16,style:{verticalAlign:"middle",marginRight:6}}),"Resume tunnel connection"]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("button",{className:"dialog-btn-create",style:{width:"100%"},onClick:()=>C("setup"),children:[a.jsx(Lm,{size:16,style:{verticalAlign:"middle",marginRight:6}}),"Make this machine remote"]}),a.jsx("div",{className:"dialog-label",style:{opacity:.7,marginTop:-4},children:"The daemon sets everything up and shows the progress here."})]})})]})]})]})})}const mj={success:k1,error:Jl,info:R1,warn:tc},gj=4e3;function vj({toast:e}){const n=R(d=>d.removeToast),r=mj[e.type],o=x.useRef(null);x.useEffect(()=>{function d(){o.current=setTimeout(()=>n(e.id),gj)}return d(),()=>{o.current&&clearTimeout(o.current)}},[e.id,n]);function l(){o.current&&(clearTimeout(o.current),o.current=null)}function c(){o.current=setTimeout(()=>n(e.id),2e3)}return a.jsxs("div",{className:`toast toast-${e.type}`,onMouseEnter:l,onMouseLeave:c,children:[a.jsx(r,{size:16}),a.jsx("span",{className:"toast-message",children:e.message}),e.undoAction&&a.jsxs("button",{className:"toast-undo",onClick:()=>{var d;(d=e.undoAction)==null||d.call(e),n(e.id)},children:[a.jsx(Q1,{size:12})," ",e.undoLabel||"Undo"]}),a.jsx("button",{className:"toast-close",onClick:()=>n(e.id),children:a.jsx(Tn,{size:14})})]})}function yj(){const e=R(n=>n.toasts);return e.length===0?null:a.jsx("div",{className:"toast-container",children:e.map(n=>a.jsx(vj,{toast:n},n.id))})}function xj(){const[e]=x.useState(Sk),[n,r]=x.useState(!1),[o,l]=x.useState(!1),c=x.useRef(void 0);x.useEffect(()=>()=>clearTimeout(c.current),[]);async function d(){await Fi(wm)&&(r(!0),l(!0),clearTimeout(c.current),c.current=setTimeout(()=>r(!1),1500))}return a.jsxs("main",{className:"daemon-download",children:[a.jsx("h1",{className:"daemon-download-title",children:"Repoburg"}),e&&a.jsx("p",{className:"daemon-download-text",children:"Open the Repoburg app to continue."}),a.jsxs("div",{className:"daemon-download-install",children:[e&&a.jsx("p",{className:"daemon-download-label",children:"Not installed? Run this in Terminal:"}),a.jsxs("div",{className:"daemon-download-cmd",onCopy:()=>l(!0),children:[a.jsx("span",{className:"daemon-download-prompt","aria-hidden":"true",children:"$"}),a.jsx("code",{children:wm}),a.jsx("button",{type:"button",className:`daemon-download-copy${n?" copied":""}`,onClick:()=>void d(),"aria-label":"Copy the install command",title:n?"Copied":"Copy",children:n?a.jsx(Cs,{size:15}):a.jsx(Oi,{size:15})})]}),!e&&a.jsx("p",{className:"daemon-download-meta",children:"Apple Silicon · macOS 13+"})]}),o&&a.jsx("p",{className:"daemon-download-hint",children:"Paste it into Terminal and press Return. Repoburg installs and opens in your menu bar."}),(e||o)&&a.jsxs("p",{className:"daemon-download-waiting",role:"status",children:[a.jsx(mn,{size:13,className:"spin"}),"Waiting for Repoburg to start…"]})]})}let Jn=null,Ao=null,Ai=1e3;const wj=1e4;function Vd(){Jn&&(Jn.readyState===WebSocket.OPEN||Jn.readyState===WebSocket.CONNECTING)||(Jn=new WebSocket(uw("/ws")),Jn.onopen=()=>{const e=Ai>1e3;if(Ai=1e3,R.getState().setWsConnected(!0),R.getState().addLogEntry("INFO","WebSocket connected"),e){Zw();const n=R.getState();n.activeSessionId&&(n.refreshActiveSession(),n.addToast("info","WebSocket reconnected — session state reconciled"))}},Jn.onclose=()=>{R.getState().setWsConnected(!1),R.getState().addLogEntry("WARN","WebSocket disconnected"),R.getState().addToast("warn","WebSocket disconnected — reconnecting…"),Sj()},Jn.onerror=()=>{},Jn.onmessage=e=>{try{const n=JSON.parse(e.data);Lt.trackWsEvent(typeof n.event=="string"?n.event:"unknown",typeof e.data=="string"?e.data.length:0);const r=bj[n.event];r&&r(n.data)}catch{}})}function kj(){Ao&&(clearTimeout(Ao),Ao=null),Jn&&(Jn.onclose=null,Jn.close(),Jn=null),R.getState().setWsConnected(!1)}function Sj(){Ao||(Ao=window.setTimeout(()=>{Ao=null,Vd()},Ai),Ai=Math.min(Ai*2,wj))}const bj={"turn:created":e=>{const n=e;R.getState().onTurnCreated(n.sessionId,n.turn)},"turn:started":e=>{const n=e;Lt.note(`turn:started — ${n.turnId.slice(0,8)}`),R.getState().onTurnStarted(n.sessionId,n.turnId)},"item:started":e=>{const n=e;Vu(n.sessionId,n.turnId,n.item),R.getState().onItemStarted(n.sessionId,n.turnId,n.item)},"item:updated":e=>{const n=e;Vu(n.sessionId,n.turnId,n.item),R.getState().onItemUpdated(n.sessionId,n.turnId,n.item)},"item:completed":e=>{const n=e;Vu(n.sessionId,n.turnId,n.item),R.getState().onItemCompleted(n.sessionId,n.turnId,n.item)},"item:delta":e=>{const n=e,r=hw(n.sessionId,n.turnId,n.itemId,n.delta);R.getState().onItemDelta(n.sessionId,n.turnId,n.itemId,n.delta,r)},"streams:snapshot":e=>{const n=e,r=R.getState();for(const o of mw(n.sessionId??null,Array.isArray(n.streams)?n.streams:[]))r.onItemText(o.sessionId,o.turnId,o.itemId,o.text)},"widget:delta":e=>{const n=e;typeof n.itemId!="string"||typeof n.html!="string"||R.getState().onWidgetDelta(n.sessionId,n.turnId,n.itemId,typeof n.title=="string"?n.title:"",n.html)},"turn:completed":e=>{const n=e;Lt.note(`turn:completed — ${n.turnId.slice(0,8)}`),gi(n.sessionId,n.turnId),R.getState().onTurnCompleted(n.sessionId,n.turnId,n.usage,n.hasUnreviewed,n.response??void 0)},"turn:tokenUsage":e=>{const n=e;R.getState().onTokenUsageUpdated(n.sessionId,n.turnId,n.usage)},"turn:contextUsage":e=>{const n=e,r={totalTokens:n.totalTokens,contextWindow:n.contextWindow,percentage:n.percentage,...n.autoCompactThreshold?{autoCompactThreshold:n.autoCompactThreshold}:{}};R.getState().onContextUsageUpdated(n.sessionId,r)},"turn:failed":e=>{const n=e;gi(n.sessionId,n.turnId),R.getState().onTurnFailed(n.sessionId,n.turnId,n.error,n.resumeState)},"turn:interrupted":e=>{const n=e;Lt.note(`turn:interrupted — ${n.turnId.slice(0,8)} (${n.reason})`),gi(n.sessionId,n.turnId),R.getState().onTurnInterrupted(n.sessionId,n.turnId,{reason:n.reason,interruptedAt:n.interruptedAt,attempts:n.attempts,detail:n.detail??null,resumeAt:n.resumeAt??null})},"turn:resuming":e=>{const n=e;gi(n.sessionId,n.turnId),R.getState().onTurnResuming(n.sessionId,n.turnId,n.attempt)},"turn:resumed":e=>{const n=e;R.getState().onTurnResumed(n.sessionId,n.turnId)},"turn:retrying":e=>{const n=e;R.getState().onTurnRetrying(n.sessionId,n.turnId,{attempt:n.attempt,maxRetries:n.maxRetries,retryDelayMs:n.retryDelayMs,errorStatus:n.errorStatus??null,error:n.error??null})},"turn:cancelled":e=>{const n=e;gi(n.sessionId,n.turnId),R.getState().onTurnCancelled(n.sessionId,n.turnId)},"session:title":e=>{const n=e;R.getState().onSessionTitle(n.sessionId,n.title)},"session:touched":e=>{const n=e;R.getState().onSessionTouched(n.sessionId)},"session:created":e=>{const{session:n}=e;n.origin_app_id&&dl(n.id,n.origin_app_id),R.getState().addSession(n)},"session:resync":e=>{const n=e,r=R.getState();r.activeSessionId===n.sessionId&&r.refreshActiveSession()},"session:updated":e=>{const n=e;R.getState().onSessionUpdated(n.session)},background_tasks:e=>{const n=e;Lt.note(`background_tasks — ${n.tasks.length} live (${n.tasks.map(r=>r.task_type).join(", ")||"none"})`),R.getState().onBackgroundTasksChanged(n.sessionId,n.tasks)},"background_tasks:snapshot":e=>{const n=e;R.getState().onBackgroundTasksSnapshot(n.sessions??{})},"signed_out_turns:snapshot":e=>{const n=e;R.getState().onSignedOutTurnsSnapshot(n.turns??[])},"thread:created":e=>{const n=e;R.getState().onThreadCreated(n.sessionId,n.thread,n.turn)},"thread:followup":e=>{const n=e;R.getState().onThreadFollowup(n.sessionId,n.threadId,n.turn)},"thread:resolved":e=>{const n=e;R.getState().onThreadResolved(n.sessionId,n.threadId,n.status)},"thread:deleted":e=>{const n=e;R.getState().onThreadDeleted(n.sessionId,n.threadId)},"app:tool_call":e=>{const n=e;Kw(n.appId,n.callId,n.tool,n.args??{},n.workspace,n.caller)},"app:source:updated":e=>{Jw(e.appId),R.getState().refreshApps()},"app:state_changed":e=>{const{appId:n,...r}=e;kv(n,r)}};function Nj(){const e=R(n=>n.init);return x.useEffect(()=>{lw();function n(){e(),Vd()}const{daemonStatus:r,setDaemonStatus:o}=R.getState();let l=null;r==="ready"?n():l=Nk({onMissing:()=>o("missing"),onReady:()=>{o("ready"),n()}});function c(){if(document.visibilityState!=="visible")return;const d=R.getState(),f=d.activeSessionId;if(!f)return;const h=d.sessionDetails[f];d.wsConnected||Vd(),h&&h.is_running===1&&(d.refreshActiveSession(),d.addLogEntry("INFO","Tab returned — reconciling session state"))}return document.addEventListener("visibilitychange",c),()=>{l==null||l(),kj(),document.removeEventListener("visibilitychange",c)}},[e]),null}const ax="agentpaneView";function Kd(e){return{tab:Xd(e),vscode:e.vscodeViewOpen,usage:e.usageViewOpen,terminal:e.terminalViewOpen}}function lx(e,n){return e.tab===n.tab&&e.vscode===n.vscode&&e.usage===n.usage&&e.terminal===n.terminal}function Zg(e){return e.tab===null&&!e.vscode&&!e.usage&&!e.terminal}function Jg(e,n){return n.tab!==null&&!e.tabOrder.includes(n.tab)?!1:!lx(n,Kd(e))}function ev(e){const n=e==null?void 0:e[ax];return typeof(n==null?void 0:n.index)!="number"?null:{...n,view:{...n.view,terminal:!!n.view.terminal}}}function Tj(e,n){e.getState().vscodeViewOpen!==n.vscode&&e.getState().toggleVscodeView(),e.getState().usageViewOpen!==n.usage&&e.getState().toggleUsageView(),e.getState().terminalViewOpen!==n.terminal&&e.getState().toggleTerminalView();const r=e.getState();if(n.tab===null)return;const{kind:o,id:l}=mr(n.tab);o==="app"?r.openAppTab(l):r.activeSessionId===l?r.setActiveAppTab(null):r.selectSession(l)}function Cj(e){let n=ev(window.history.state)??{index:0,newest:0,view:Kd(e.getState())},r=n.newest,o=!1;const l=new Map([[n.index,n.view]]),c=y=>{const S=e.getState();for(let E=n.index+y;E>=0&&E<=r;E+=y){const T=l.get(E);if(!T||Jg(S,T))return!0}return!1},d=()=>{const y=c(-1),S=c(1),E=e.getState();(E.canGoBack!==y||E.canGoForward!==S)&&e.setState({canGoBack:y,canGoForward:S})},f=()=>({[ax]:{...n,newest:r}}),h=()=>{window.history.replaceState({...window.history.state,...f()},"")},m=y=>{if(l.set(n.index,n.view),Zg(n.view))n={...n,view:y},h();else{n={index:n.index+1,newest:n.index+1,view:y},r=n.index;for(const S of l.keys())S>r&&l.delete(S);window.history.pushState(f(),"")}l.set(n.index,y)},v=y=>{const S=ev(y.state);if(!S)return;l.set(S.index,S.view),r=Math.max(r,S.index);const E=e.getState(),T=Math.sign(S.index-n.index);if(T!==0&&!Jg(E,S.view)){const C=S.index+T;window.history.go(C<0||C>r?n.index-S.index:T);return}n=S,h(),o=!0;try{Tj(e,S.view)}finally{o=!1}d()};h(),d(),window.addEventListener("popstate",v);const k=e.subscribe((y,S)=>{const E=y.activeSessionId!==S.activeSessionId||y.activeAppTabId!==S.activeAppTabId||y.vscodeViewOpen!==S.vscodeViewOpen||y.usageViewOpen!==S.usageViewOpen||y.terminalViewOpen!==S.terminalViewOpen;if(!(!E&&y.tabOrder===S.tabOrder)){if(E&&!o){const T=Kd(y);!Zg(T)&&!lx(T,n.view)&&m(T)}d()}});return()=>{k(),window.removeEventListener("popstate",v)}}function Ej(){const e=R(c=>c.loading),n=R(c=>c.error),r=R(c=>c.sessions),o=R(c=>c.daemonStatus),l=R(c=>c.setShowCommandPalette);return x.useEffect(()=>Lt.start(),[]),x.useEffect(()=>Cj(R),[]),x.useEffect(()=>{function c(d){(d.metaKey||d.ctrlKey)&&d.key==="k"&&(d.preventDefault(),l(!0))}return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[l]),a.jsxs(a.Fragment,{children:[a.jsx(Nj,{}),o==="missing"?a.jsx(xj,{}):o==="checking"||e&&r.length===0?a.jsx("div",{className:"empty-state",children:"Loading sessions…"}):n&&r.length===0?a.jsxs("div",{className:"empty-state",children:["Error: ",n]}):a.jsxs(a.Fragment,{children:[a.jsx(JE,{}),a.jsx(ej,{}),a.jsx(sj,{}),a.jsx(ij,{}),a.jsx(dj,{}),a.jsx(hj,{}),a.jsx(fj,{}),a.jsx(yj,{})]})]})}Q0.createRoot(document.getElementById("root")).render(a.jsx(ct.StrictMode,{children:a.jsx(Ej,{})}));export{$i as R,Tn as X,uw as b,ye as c,a as j,x as r,R as u};
@@ -10,7 +10,7 @@
10
10
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;450;510;590;600&family=JetBrains+Mono:wght@400;500&display=swap"
11
11
  rel="stylesheet"
12
12
  />
13
- <script type="module" crossorigin src="/assets/index-NpywVkQl.js"></script>
13
+ <script type="module" crossorigin src="/assets/index-7ikRAI4J.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/assets/index-wFHgyM6i.css">
15
15
  </head>
16
16
  <body>
@@ -36,14 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.authManager = void 0;
39
+ exports.authManager = exports.PUBLIC_KEY = void 0;
40
40
  const fs_extra_1 = __importDefault(require("fs-extra"));
41
41
  const path_1 = __importDefault(require("path"));
42
42
  const os_1 = __importDefault(require("os"));
43
43
  const jose = __importStar(require("jose"));
44
44
  const REPOBURG_DIR = path_1.default.join(os_1.default.homedir(), '.repoburg');
45
45
  const TOKEN_PATH = path_1.default.join(REPOBURG_DIR, 'token.jwt');
46
- const PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
46
+ /** The public half of the account server's signing key (device tokens, edge tokens). */
47
+ exports.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
47
48
  MCowBQYDK2VwAyEAcNJkxXJrYEa4cZmcq80A1Ns0y/HIt/WWEiWJ5F3E9ZE=
48
49
  -----END PUBLIC KEY-----`;
49
50
  class AuthManager {
@@ -53,7 +54,7 @@ class AuthManager {
53
54
  }
54
55
  async loadPublicKey() {
55
56
  try {
56
- const keyData = PUBLIC_KEY;
57
+ const keyData = exports.PUBLIC_KEY;
57
58
  console.log(`[AuthManager] Loading hardcoded public key: ${keyData.substring(0, 50)}...`);
58
59
  this.publicKey = await jose.importSPKI(keyData, 'EdDSA');
59
60
  }
@@ -77,9 +77,10 @@ async function main() {
77
77
  // route. See middleware/originGuard.ts for who is allowed and why.
78
78
  app.use(originGuard_1.originGuard);
79
79
  app.use((0, cors_1.default)(originGuard_1.corsOptions));
80
- // CF Access guard for the embedded pane: when the machine has a tunnel and
81
- // Access is configured, /api/* traffic must carry a valid Access JWT.
82
- app.use('/api', checkRemoteAuth_1.checkRemoteAuth);
80
+ // Tunnel guard: a request that came through the tunnel needs the edge
81
+ // gate's token (or, on a tunnel still behind CF Access, an Access JWT) on
82
+ // every route. Local requests pass. See middleware/checkRemoteAuth.ts.
83
+ app.use(checkRemoteAuth_1.checkRemoteAuth);
83
84
  // Embedded agent-pane API. MUST precede express.json() — Fastify parses its
84
85
  // own request bodies; the stream can only be consumed once.
85
86
  app.all('/api/*', (0, agentPane_1.createPaneDelegate)(pane));
@@ -138,10 +139,10 @@ async function main() {
138
139
  ws.on('error', (error) => console.error('WebSocket error:', error));
139
140
  });
140
141
  // Single upgrade router: '/tabtape/...' -> tabtape live viewing, '/ws' ->
141
- // embedded agent-pane (guarded by CF Access when configured), '/ws/terminal'
142
- // -> a shell of the pane (never without CF Access through the tunnel),
143
- // everything else -> daemon wss.
144
- const paneUpgrade = (0, agentPane_1.createUpgradeRouter)(pane, wss, checkRemoteAuth_1.checkRemoteWsAuth, checkRemoteAuth_1.checkTerminalWsAuth);
142
+ // embedded agent-pane, '/ws/terminal' -> a shell of the pane, '/vscode' ->
143
+ // VS Code, everything else -> daemon wss. Tunnel upgrades of any kind pass
144
+ // the tunnel guard first (checkRemoteWsAuth), the same one as HTTP routes.
145
+ const paneUpgrade = (0, agentPane_1.createUpgradeRouter)(pane, wss);
145
146
  server.on('upgrade', (req, socket, head) => {
146
147
  const url = req.url ?? '';
147
148
  if (url === tabtape_1.TABTAPE_MOUNT || url.startsWith(`${tabtape_1.TABTAPE_MOUNT}/`)) {
@@ -151,7 +152,14 @@ async function main() {
151
152
  socket.destroy();
152
153
  return;
153
154
  }
154
- paneUpgrade(req, socket, head);
155
+ void (0, checkRemoteAuth_1.checkRemoteWsAuth)(req).then((allowed) => {
156
+ if (allowed) {
157
+ paneUpgrade(req, socket, head);
158
+ return;
159
+ }
160
+ socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
161
+ socket.destroy();
162
+ }, () => socket.destroy());
155
163
  });
156
164
  // Spec: loopback binding only — remote access is exclusively via the
157
165
  // cloudflared tunnel; the daemon must never listen on public interfaces.
@@ -1,87 +1,72 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remoteAuthFailure = remoteAuthFailure;
3
4
  exports.checkRemoteAuth = checkRemoteAuth;
4
5
  exports.checkRemoteWsAuth = checkRemoteWsAuth;
5
- exports.checkTerminalWsAuth = checkTerminalWsAuth;
6
6
  const tunnel_state_1 = require("../remote/tunnel-state");
7
- const access_jwt_1 = require("../remote/access-jwt");
7
+ const edge_jwt_1 = require("../remote/edge-jwt");
8
8
  const originGuard_1 = require("./originGuard");
9
9
  /**
10
- * Guard for daemon endpoints that must not be reachable by anonymous tunnel
11
- * traffic once CF Access is configured.
10
+ * Guard for requests that ARRIVED THROUGH THE TUNNEL: every route, every
11
+ * WebSocket upgrade (the pane API, the shell, the MCP gateway, the SPA).
12
12
  *
13
- * Only requests that ARRIVED THROUGH THE TUNNEL (Host = the machine's
14
- * <mahlas>.repoburg.com hostname) need the Access JWT. Requests with a
15
- * local Host header — the local pane at localhost:9998 and the public
16
- * pane host agent.repoburg.com calling into the visitor's own daemon —
17
- * pass through: the loopback binding is the boundary there, and remote
18
- * clients cannot forge the Host through the CF edge (routing is by
19
- * hostname/SNI).
13
+ * Who needs a credential is decided by the Host header:
14
+ * - loopback (the local pane at localhost:9998, agent.repoburg.com calling
15
+ * the visitor's own daemon, the Mac app): no — the loopback binding is the
16
+ * boundary there;
17
+ * - `<mahlas>.repoburg.com` (tunnel traffic; remote clients cannot forge the
18
+ * Host through the CF edge, routing is by hostname/SNI): yes, always;
19
+ * - a host of REPOBURG_ALLOWED_ORIGINS (the owner's own proxy): no;
20
+ * - anything else: yes (it cannot be this machine's tunnel, so it fails).
21
+ *
22
+ * The credential (fail closed: without it, 401) is an edge token
23
+ * (X-Repoburg-Edge-Auth) from the account server's edge gate, for this
24
+ * hostname and the pinned owner email (MUH-108).
20
25
  */
21
- function isLocalHostHeader(host) {
26
+ function needsCredential(host) {
22
27
  if (!host)
23
- return true; // no Host header = non-HTTP client tooling
24
- return (0, originGuard_1.isLoopbackHost)(host);
28
+ return false; // no Host header = non-HTTP client tooling, not a browser
29
+ if ((0, originGuard_1.isLoopbackHost)(host))
30
+ return false;
31
+ if ((0, originGuard_1.isTunnelHost)(host))
32
+ return true;
33
+ return !(0, originGuard_1.isExtraOriginHost)(host);
25
34
  }
26
- async function checkRemoteAuth(req, res, next) {
27
- const state = (0, tunnel_state_1.loadTunnelState)();
28
- const config = state?.accessTeamDomain && state.accessAud
29
- ? { teamDomain: state.accessTeamDomain, aud: state.accessAud }
30
- : null;
31
- if (!config || !state || isLocalHostHeader(req.headers.host)) {
32
- // No Access configured, or local usage — loopback binding is the boundary.
33
- next();
34
- return;
35
- }
36
- // Fail closed: Access is configured but the owner email was never pinned
37
- // (state from before email pinging). Re-provision the machine.
38
- if (!state.ownerEmail) {
39
- res.status(401).json({ error: 'Tunnel owner email is missing — re-provision this machine.' });
40
- return;
41
- }
42
- const assertion = req.headers['cf-access-jwt-assertion'];
43
- if (typeof assertion !== 'string') {
44
- res.status(401).json({ error: 'Cloudflare Access authentication required.' });
45
- return;
35
+ const header = (headers, name) => {
36
+ const value = headers[name];
37
+ return typeof value === 'string' ? value : undefined;
38
+ };
39
+ /** Why the request may not pass, or null when it may. */
40
+ async function remoteAuthFailure(headers, state = (0, tunnel_state_1.loadTunnelState)()) {
41
+ if (!needsCredential(headers.host))
42
+ return null;
43
+ if (!state || (0, originGuard_1.hostnameOf)(headers.host ?? '') !== state.hostname) {
44
+ return 'This machine has no tunnel at this address.';
46
45
  }
46
+ // Fail closed: state from before email pinning. Re-provision the machine.
47
+ if (!state.ownerEmail)
48
+ return 'Tunnel owner email is missing — re-provision this machine.';
49
+ const edgeToken = header(headers, edge_jwt_1.EDGE_AUTH_HEADER);
50
+ if (!edgeToken)
51
+ return 'Sign in to this machine first.';
47
52
  try {
48
- await (0, access_jwt_1.verifyAccessJwt)(assertion, config, { ownerEmail: state.ownerEmail });
49
- next();
53
+ await (0, edge_jwt_1.verifyEdgeJwt)(edgeToken, { hostname: state.hostname, ownerEmail: state.ownerEmail });
54
+ return null;
50
55
  }
51
56
  catch {
52
- res.status(401).json({ error: 'Invalid or expired Cloudflare Access token.' });
57
+ return 'Invalid or expired sign-in token.';
53
58
  }
54
59
  }
55
- /** Same guard for WebSocket upgrades: false = reject and destroy the socket. */
56
- async function checkRemoteWsAuth(req) {
57
- const state = (0, tunnel_state_1.loadTunnelState)();
58
- if (!state?.accessTeamDomain || !state.accessAud)
59
- return true; // no Access configured
60
- if (isLocalHostHeader(req.headers.host))
61
- return true; // local usage
62
- if (!state.ownerEmail)
63
- return false; // fail closed: no pinned owner email
64
- const assertion = req.headers['cf-access-jwt-assertion'];
65
- if (typeof assertion !== 'string')
66
- return false;
67
- try {
68
- await (0, access_jwt_1.verifyAccessJwt)(assertion, { teamDomain: state.accessTeamDomain, aud: state.accessAud }, { ownerEmail: state.ownerEmail });
69
- return true;
70
- }
71
- catch {
72
- return false;
60
+ /** Express middleware for every route. */
61
+ async function checkRemoteAuth(req, res, next) {
62
+ const failure = await remoteAuthFailure(req.headers);
63
+ if (failure) {
64
+ res.status(401).json({ error: failure });
65
+ return;
73
66
  }
67
+ next();
74
68
  }
75
- /**
76
- * The guard for a shell over WebSocket. Stricter than checkRemoteWsAuth: tunnel
77
- * traffic never reaches a shell without Access, even on a machine that has no
78
- * Access configured.
79
- */
80
- async function checkTerminalWsAuth(req) {
81
- if (isLocalHostHeader(req.headers.host))
82
- return true;
83
- const state = (0, tunnel_state_1.loadTunnelState)();
84
- if (!state?.accessTeamDomain || !state.accessAud)
85
- return false;
86
- return checkRemoteWsAuth(req);
69
+ /** The same guard for WebSocket upgrades: false = reject and destroy the socket. */
70
+ async function checkRemoteWsAuth(req) {
71
+ return (await remoteAuthFailure(req.headers)) === null;
87
72
  }