@coreframe/vite 0.2.46 → 0.2.47

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.
@@ -174,4 +174,4 @@ let n=u(({className:n,...r},i)=>l(ne,{ref:i,iconNode:t,className:O(`lucide-${k(j
174
174
  `,hostAttributes:{"aria-live":`polite`,id:`coreframe-managed-dev`},hostStyles:{pointerEvents:`none`,position:`fixed`},zIndex:2147483647});return queueMicrotask(()=>{e&&s(t.container)}),()=>{e=!1,t.host?.remove()}},[r]);let l={"--managed-dev-bottom-offset":Ee(e),"--managed-dev-right-offset":Ee(a)};return o?y(S(`div`,{className:H.surface,style:l,children:[i?n:null,i&&c?t:null]}),o):null}function Te({bottomOffset:e,indicator:t,rightOffset:n}){let[r,i]=_(),[a,o]=_(ve),[c,l]=_(),[u,f]=_(),p=ye.find(({id:e})=>e===r),m=e=>{i(e),l(void 0),f(void 0)},h=async e=>{if(e.type!==`configure-codex`){if(e.type===`acknowledge-codex`){m(void 0);return}f(qe(e))}},g=t??x(q,{}),v={pending:!1,reloadPage:()=>l(`Page reload simulated.`),restartVite:()=>l(`Vite restart simulated.`),success:c};return x(we,{bottomOffset:e,indicator:d(g)&&g.type===q?s(g,{paused:p?.status.mode===`waiting`}):g,openOnMount:!0,rightOffset:n,children:p?x(Oe,{act:h,checkFailure:He(p.status),codex:p.codex,codexOptions:a,developmentControls:v,dismissCheckFailure:()=>void 0,dismissError:()=>void 0,error:p.error,onBack:()=>m(void 0),onClose:()=>G(!1),setCodexOptions:o,status:p.status,success:u??p.success},p.id):x(De,{developmentControls:v,onClose:()=>G(!1),onSelect:e=>m(e)})})}function Ee(e){return typeof e==`number`?`${e}px`:e??`0px`}function De({developmentControls:e,onClose:t,onSelect:n}){return x(K,{debug:!0,developmentControls:e,icon:ie,onClose:t,title:`Managed dev overlay scenarios`,children:x(`div`,{className:H.scenarioList,children:be.map(e=>S(`button`,{className:H.scenarioButton,onClick:()=>n(e.id),type:`button`,children:[x(`span`,{className:H.scenarioLabel,children:e.label}),x(`span`,{className:H.scenarioDescription,children:e.description})]},e.id))})})}function K({children:e,debug:t=!1,developmentControls:n,icon:r,onBack:i,onClose:a,title:o}){let s=g(null),c=g(null),[l,u]=_(!1);return m(()=>{let e=e=>{let t=e.composedPath(),n=c.current;n&&!t.includes(n)&&u(!1);let r=s.current;r&&!t.includes(r)&&a()},t=e=>{e.key===`Escape`&&(e.preventDefault(),a())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[a]),S(`dialog`,{"aria-labelledby":`coreframe-managed-title`,"aria-modal":`true`,className:H.dialog,id:`coreframe-managed-dev-dialog`,open:!0,ref:s,children:[S(`div`,{className:H.header,children:[S(`h2`,{className:H.title,id:`coreframe-managed-title`,children:[x(r,{"aria-hidden":`true`,className:H.titleIcon,size:18}),o]}),S(`div`,{className:H.headerActions,children:[i?x(`button`,{"aria-label":`Back to scenarios`,className:H.iconButton,onClick:i,type:`button`,children:x(re,{"aria-hidden":`true`,size:18})}):null,n?S(`div`,{className:H.developmentControlsDropdown,ref:c,children:[x(`button`,{"aria-expanded":l,"aria-haspopup":`menu`,"aria-label":`Development controls`,className:H.iconButton,onClick:()=>u(e=>!e),type:`button`,children:x(ue,{"aria-hidden":`true`,size:18})}),l?x(ke,{controls:n}):null]}):null,x(`button`,{"aria-label":`Close managed development`,className:H.iconButton,onClick:a,type:`button`,children:x(B,{"aria-hidden":`true`,size:18})})]})]}),x(`div`,{className:H.drawerBody,children:e}),t?x(`footer`,{className:H.debugFooter,children:`Debug preview · project actions are simulated locally`}):null]})}function q({color:e=`#228be6`,paused:t=!1,size:n=14,warningColor:r=`#fd7e14`}){let i=v(Ye,Xe,Ze),a={"--managed-dev-indicator-color":t?r:e,"--managed-dev-indicator-size":typeof n==`number`?`${n}px`:n};return x(`button`,{"aria-controls":`coreframe-managed-dev-dialog`,"aria-expanded":i,"aria-label":`${i?`Hide`:`Show`} Coreframe managed development`,className:H.indicatorButton,onClick:xe,style:a,type:`button`,children:x(`span`,{className:H.indicatorDot})})}function Oe({act:e,checkFailure:t,codex:n,codexOptions:r,developmentControls:i,dismissCheckFailure:a,dismissError:o,error:s,onBack:c,onClose:l,pendingAction:u,setCodexOptions:d,status:f,success:p}){let[h,v]=_({value:``}),[y,C]=_(()=>({paths:new Set})),w=g(null),T=f?.codexCompletion,E=f?.draft,D=f?.pendingRebase,O=f?.target,k=!T&&!p&&!n,A=y.fingerprint===E?.fingerprint?y.paths:new Set(E?.untracked??[]),j=h.fingerprint===E?.fingerprint&&h.proposal===f?.proposal?h.value:f?.proposal??``,M=!!(E?.untracked.length&&E.untracked.every(e=>A.has(e))),N=t=>{d(t),e({codex:t,type:`configure-codex`})};return m(()=>{let e=w.current;e&&n?.phase===`running`&&(e.scrollTop=e.scrollHeight)},[n]),t?x(K,{debug:!!c,developmentControls:i,icon:z,onBack:c,onClose:l,title:`Managed development check failed`,children:S(`div`,{className:H.content,children:[x(`div`,{className:H.checkFailure,role:`alert`,children:S(`div`,{className:H.checkMessage,children:[S(`p`,{className:H.checkCommand,children:[t.check.command,` failed`]}),x(`p`,{className:H.checkGuidance,children:Ue(t)}),x(`p`,{className:H.checkGuidance,children:`Copy the output and paste it into your agent orchestration tool.`})]})}),S(X,{children:[x(Q,{ariaLabel:`Dismiss error`,icon:B,iconOnly:!0,onClick:()=>a(t),children:`Dismiss`}),x(Q,{ariaLabel:`Copy output for ${t.check.command}`,icon:ce,iconOnly:!0,onClick:()=>void navigator.clipboard.writeText(t.check.output??``),children:`Copy output`})]})]})}):x(K,{debug:!!c,developmentControls:i,icon:Le({codex:n,completion:T,status:f,success:p}),onBack:c,onClose:l,title:T?`Codex conflict resolution finished`:p?.heading??(n?.phase===`complete`?`Finishing synchronization…`:n?.phase===`error`?`Conflict resolution failed.`:n?`Resolving conflicts with Codex…`:Ie(f)),children:S(`div`,{className:H.content,children:[p&&!T?S(`div`,{className:H.actionSuccess,role:`status`,children:[x(F,{"aria-hidden":`true`,className:H.successIcon,size:18}),x(`p`,{className:H.paragraph,children:p.message})]}):null,s?S(b,{children:[x(`div`,{className:H.actionError,role:`alert`,children:x(Z,{children:s})}),x(X,{children:x(Q,{ariaLabel:`Dismiss error`,icon:B,iconOnly:!0,onClick:o,children:`Dismiss`})})]}):null,T||!p&&n?S(b,{children:[x(Ae,{commits:T?.commits??n?.commits??[],completion:T,messages:T?.messages??n?.messages??[],outputRef:w,totalCommits:T?.totalCommits??n?.totalCommits,working:n?.phase===`running`}),!T&&n?.phase===`running`?x(X,{children:x(Q,{ariaLabel:`Cancel conflict resolution`,busy:u?.type===`cancel-codex`,icon:B,onClick:()=>void e({type:`cancel-codex`}),children:`Cancel`})}):null]}):k&&f?.setupFailure?S(b,{children:[S(`div`,{className:H.setupFailure,role:`alert`,children:[x(Z,{children:f.setupFailure.message}),x(`pre`,{className:H.codexOutput,children:f.setupFailure.output})]}),S(X,{children:[x(Q,{ariaLabel:`Dismiss error`,icon:B,iconOnly:!0,onClick:l,children:`Dismiss`}),x(Q,{ariaLabel:`Copy diagnostics`,disabledReason:f.busy,icon:ce,iconOnly:!0,onClick:()=>void navigator.clipboard.writeText(Ge(f.setupFailure)),children:`Copy diagnostics`}),f.setupFailure.stage===`dependencies`?x(Q,{ariaLabel:`Retry install`,busy:u?.type===`retry-install`,disabledReason:f.busy,icon:I,iconOnly:!0,onClick:()=>void e({type:`retry-install`}),primary:!0,children:`Retry install`}):f.setupFailure.stage===`codegen`?x(Q,{ariaLabel:`Retry codegen`,busy:u?.type===`retry-codegen`,disabledReason:f.busy,icon:I,iconOnly:!0,onClick:()=>void e({type:`retry-codegen`}),primary:!0,children:`Retry codegen`}):x(Q,{busy:u?.type===`reset-database`,disabledReason:f.busy,icon:L,onClick:()=>{globalThis.confirm(`Reset the local database? This permanently deletes its current data, then reapplies migrations and seed scripts.`)&&e({type:`reset-database`})},primary:!0,children:`Reset database`})]})]}):k&&ze(f)?S(b,{children:[x(`p`,{className:H.paragraph,children:f?.message}),x(X,{children:x(Q,{ariaLabel:`Retry managed development`,busy:u?.type===`retry-supervisor`,disabledReason:f?.busy,icon:I,immediatelyEnabled:!0,onClick:()=>void e({type:`retry-supervisor`}),primary:!0,children:`Retry managed development`})})]}):k?x(`p`,{className:H.paragraph,children:f?f.busy||f.message||Re(f):`Checking managed development status…`}):null,T&&!s?x(X,{children:x(Q,{busy:u?.type===`acknowledge-codex`,disabledReason:f?.busy,icon:F,onClick:()=>void e({id:T.id,type:`acknowledge-codex`}),primary:!0,children:`Continue`})}):null,k&&f?.mode===`waiting`&&f.message&&!Be(f)?S(`p`,{className:H.paragraph,children:[`To re-enable managed development, run `,x(`code`,{children:`git switch main`}),` in the primary checkout. Synchronization will resume automatically.`]}):null,k&&O&&!E?x(`pre`,{className:H.pendingCommits,children:(O.commits??[O]).map(e=>`${e.shortCommit} ${e.subject}`).join(`
175
175
  `)}):null,k?f?.warnings.map((e,t)=>x(`p`,{className:`${H.paragraph} ${H.warning}`,children:e},`${t}-${e}`)):null,k&&E?S(b,{children:[S(`div`,{className:H.files,children:[E.untracked.map(e=>x(Fe,{checked:A.has(e),label:x(`span`,{className:H.filePath,children:e}),onChange:t=>C(()=>{let n=new Set(A);return t?n.add(e):n.delete(e),{fingerprint:E.fingerprint,paths:n}})},e)),E.untracked.length>0?x(Fe,{checked:M,label:`Include all untracked files`,onChange:e=>C({fingerprint:E.fingerprint,paths:e?new Set(E.untracked):new Set})}):null]}),f.proposal===void 0?S(X,{children:[O?x(Q,{busy:u?.type===`reject`,disabledReason:f.busy,icon:L,onClick:()=>void e({type:`reject`}),children:`Reject`}):null,x(Q,{busy:u?.type===`message`,disabledReason:f.busy,icon:R,onClick:()=>void e({type:`message`,fingerprint:E.fingerprint,untracked:[...A]}),primary:!0,children:`Generate commit message`})]}):S(b,{children:[x(`textarea`,{"aria-label":`Commit message`,className:H.message,onChange:e=>v({fingerprint:E.fingerprint,proposal:f.proposal,value:e.target.value}),value:j}),O?x(J,{disabled:!!f.busy,onChange:N,value:r}):null,S(X,{children:[O?x(Q,{busy:u?.type===`reject`,disabledReason:f.busy,icon:L,onClick:()=>void e({type:`reject`}),children:`Reject`}):null,x(Q,{busy:u?.type===(O?`apply`:`commit`),disabledReason:f.busy,icon:de,onClick:()=>{e(O?{type:`apply`,target:O.commit,fingerprint:E.fingerprint,untracked:[...A],message:j,codex:r}:{type:`commit`,fingerprint:E.fingerprint,untracked:[...A],message:j})},primary:!0,children:O?`Commit and refresh`:`Commit changes`})]})]})]}):k&&D?S(b,{children:[x(`p`,{className:H.paragraph,children:D.applied>0?`The update replayed ${D.applied} of ${D.applied+D.commits.length} commits before stopping on a conflict. The cleanly applied commits are already on your branch; Codex can resolve the rest.`:`The update stopped on a conflict before any commit could be replayed. Codex can resolve your commits.`}),x(`div`,{className:H.files,children:D.files.map(e=>x(`span`,{className:H.filePath,children:e},e))}),D.commits.length>0?x(`pre`,{className:H.pendingCommits,children:D.commits.map(e=>`${e.shortCommit} ${e.subject}`).join(`
176
176
  `)}):null,x(J,{disabled:!!f.busy,onChange:N,value:r}),S(X,{children:[x(Q,{busy:u?.type===`decline-rebase`,disabledReason:f.busy,icon:B,onClick:()=>void e({type:`decline-rebase`}),children:`Decline`}),x(Q,{busy:u?.type===`resolve-rebase`,disabledReason:f.busy,icon:R,onClick:()=>void e({codex:r,type:`resolve-rebase`}),primary:!0,children:`Resolve with Codex`})]})]}):k&&O?S(b,{children:[x(J,{disabled:!!f.busy,onChange:N,value:r}),x(X,{children:x(Q,{busy:u?.type===`prepare`,disabledReason:f.busy,icon:I,onClick:()=>void e({type:`prepare`,target:O.commit,codex:r}),primary:!0,children:O.source===`upstream`?`Refresh`:String(O.source)===`dev`?`Sync with dev`:`Sync with main`})})]}):null]})})}function J({disabled:e=!1,onChange:t,value:i}){return S(`div`,{className:H.codexOptions,children:[S(`label`,{className:H.codexOption,children:[x(`span`,{className:H.codexOptionLabel,children:`Codex model`}),x(`select`,{"aria-label":`Codex model`,className:H.codexOptionSelect,disabled:e,onChange:e=>t({...i,model:e.target.value}),value:i.model,children:r.map(e=>x(`option`,{value:e,children:e},e))})]}),S(`label`,{className:H.codexOption,children:[x(`span`,{className:H.codexOptionLabel,children:`Reasoning effort`}),x(`select`,{"aria-label":`Reasoning effort`,className:H.codexOptionSelect,disabled:e,onChange:e=>t({...i,effort:e.target.value}),value:i.effort,children:n.map(e=>x(`option`,{value:e,children:e},e))})]})]})}function ke({controls:e}){return S(`div`,{"aria-label":`Development controls`,className:H.developmentControls,role:`menu`,children:[S(X,{children:[x(Q,{immediatelyEnabled:!0,icon:I,onClick:e.reloadPage,role:`menuitem`,children:`Reload page`}),x(Q,{busy:e.pending,immediatelyEnabled:!0,icon:L,onClick:e.restartVite,primary:!0,role:`menuitem`,children:e.pending?`Restarting Vite…`:`Restart Vite`})]}),e.error?x(`div`,{className:H.actionError,role:`alert`,children:x(Z,{children:`Vite restart failed: ${e.error}`})}):null,e.success?S(`div`,{className:H.actionSuccess,role:`status`,children:[x(F,{"aria-hidden":`true`,className:H.successIcon,size:18}),x(`p`,{className:H.paragraph,children:e.success})]}):null]})}function Ae({commits:t,completion:n,messages:r,outputRef:i,totalCommits:a,working:o}){let s=[...r].reverse().find(e=>e.kind===`user`),c=[...r].reverse().find(e=>e.kind!==`user`),l=n?[...r].reverse().find(e=>e.kind===`agent`&&e.text===n.finalMessage):c,u=r.filter(e=>e.kind!==`user`&&e!==l),d=n?l??{author:[...r].reverse().find(e=>e.kind===`agent`)?.author,kind:`agent`,text:n.finalMessage}:c,f=l?`message-${r.lastIndexOf(l)}`:`completion`;return S(b,{children:[o?x(`div`,{className:H.codexWorking,children:x(e,{className:H.codexWorkingSpinner,label:`Codex is resolving conflicts`,children:x(je,{})})}):null,S(`div`,{"aria-live":n?void 0:`polite`,className:H.codexTranscript,ref:i,role:`log`,children:[s?x(Y,{message:s}):null,u.length>0?S(`details`,{children:[S(`summary`,{className:H.codexHistorySummary,children:[`History (`,u.length,`)`]}),x(`div`,{className:H.codexHistoryList,children:u.map((e,t)=>x(Y,{message:e},`history-${t}`))})]}):null,d?x(Y,{message:d,showAge:!0},f):x(`p`,{className:H.codexWaiting,children:`Waiting for Codex output…`}),a?x(Me,{rebased:t.length,total:a}):null]})]})}function je(){let e=g(0),[t,n]=_(0);return m(()=>{e.current=Date.now();let t=globalThis.setInterval(()=>{n(Math.floor((Date.now()-e.current)/1e3))},1e3);return()=>globalThis.clearInterval(t)},[]),S(b,{children:[`Working for `,Pe(t),`...`]})}function Me({rebased:e,total:t}){let n=Math.min(e,t),r=Math.round(n/t*100);return S(`section`,{"aria-label":`Rebase progress`,className:H.rebaseProgress,children:[S(`div`,{className:H.rebaseProgressLabel,children:[S(`strong`,{children:[r,`% rebased`]}),S(`span`,{children:[n,` of `,t,` commits`]})]}),x(`div`,{"aria-valuemax":t,"aria-valuemin":0,"aria-valuenow":n,className:H.rebaseProgressTrack,role:`progressbar`,children:x(`span`,{className:H.rebaseProgressFill,style:{width:`${r}%`}})})]})}function Y({message:e,showAge:t=!1}){let n=e.kind===`user`?`Request`:e.kind===`thought`?`Codex thought`:e.author??`Codex`,r=e.kind===`user`?H.codexMessageUser:e.kind===`thought`?H.codexMessageThought:H.codexMessageAgent;return S(`section`,{className:`${H.codexMessage} ${r}`,children:[S(`div`,{className:H.codexMessageHeader,children:[x(`h3`,{className:H.codexMessageLabel,children:n}),t?x(Ne,{}):null]}),x(`p`,{className:H.codexMessageText,children:e.text})]})}function Ne(){let e=g(0),[t,n]=_(0);return m(()=>{e.current=Date.now();let t=globalThis.setInterval(()=>{n(Math.floor((Date.now()-e.current)/1e3))},1e3);return()=>globalThis.clearInterval(t)},[]),S(`span`,{"aria-hidden":`true`,className:H.codexMessageAge,children:[Pe(t),` ago`]})}function Pe(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}m ${n}s`:`${n}s`}function Fe({checked:e,label:t,onChange:n}){return S(`label`,{className:H.checkbox,children:[x(`input`,{checked:e,onChange:e=>n(e.target.checked),type:`checkbox`}),t]})}function X({children:e}){return x(`div`,{className:H.actions,children:e})}function Z({children:e}){return S(`div`,{className:H.errorMessage,children:[x(z,{"aria-hidden":`true`,className:H.errorIcon,size:18}),x(`p`,{className:H.paragraph,children:e})]})}function Q({ariaLabel:e,busy:t,children:n,disabledReason:r,icon:i,iconOnly:a=!1,immediatelyEnabled:o=!1,onClick:s,primary:c=!1,role:l}){let[u,d]=_(!0),[f,p]=_(),g=h(),v=r?`Please wait: ${r.replace(/[.\u2026]+$/,``)}.`:t?`Waiting for ${e??(typeof n==`string`?`“${n}”`:`this action`)} to finish.`:u&&!o?`Please wait a moment. This prevents accidental clicks.`:void 0;m(()=>{let e=globalThis.setTimeout(()=>d(!1),1e3);return()=>globalThis.clearTimeout(e)},[]);let b=e=>{let t=e.getBoundingClientRect(),n=e.closest(`[data-isolet-root]`);n&&p({left:Math.max(12,Math.min(t.left,window.innerWidth-292)),top:t.top-8,root:n})};return S(`span`,{"aria-describedby":v?g:void 0,"aria-label":v?e??(typeof n==`string`?n:void 0):void 0,className:H.buttonContainer,onBlur:()=>p(void 0),onFocus:e=>b(e.currentTarget),onKeyDown:e=>{e.key===`Escape`&&v&&f&&(e.stopPropagation(),p(void 0))},onMouseEnter:e=>b(e.currentTarget),onMouseLeave:()=>p(void 0),onPointerDown:e=>{v&&e.currentTarget.focus()},tabIndex:v?0:void 0,children:[S(`button`,{"aria-label":e,"aria-busy":!!t,"aria-describedby":v?g:void 0,className:`${H.button} ${a?H.iconOnly:``} ${c?H.primary:``}`,disabled:!!v,onClick:s,role:l,title:!v&&a?e:void 0,type:`button`,children:[t?x(pe,{"aria-hidden":`true`,className:H.buttonSpinner,size:16}):i?x(i,{"aria-hidden":`true`,size:16}):null,a?null:n]}),v?x(`span`,{className:H.srOnly,id:g,children:v}):null,v&&f?y(x(`span`,{className:H.disabledTooltip,role:`tooltip`,style:{left:f.left,top:f.top},children:v}),f.root):null]})}function Ie(e){return e?e.mode===`waiting`&&e.message?`Managed development paused`:e.mode===`unmanaged`?`Managed development unavailable`:e.mode===`error`?`Managed development stopped`:e.setupFailure?.stage===`dependencies`?`Dependency installation failed`:e.setupFailure?.stage===`codegen`?`Panda codegen failed`:e.setupFailure?.stage===`migration`?`Database setup failed`:e.draft?e.proposal===void 0?`Review local changes`:`Confirm your commit`:e.pendingRebase?`Resolve update conflicts`:e.target?.source===`upstream`?`Refresh from upstream`:String(e.target?.source)===`dev`?`Sync with local dev`:e.target?`Sync with local main`:e.checks?.commands.some(e=>e.status===`failed`)?`Managed development checks failed`:e.warnings.length>0?`Managed development warning`:`Managed development status`:`Checking managed development`}function Le({codex:e,completion:t,status:n,success:r}){return e||t?R:n?.setupFailure?.stage===`migration`?le:n?.setupFailure?.stage===`dependencies`?me:n?.setupFailure?.stage===`codegen`?I:n?.draft?de:n?.pendingRebase?R:n?.target?.source===`upstream`?se:n?.target?I:n?.checks?.commands.some(e=>e.status===`failed`)?fe:r?F:n?n.mode===`waiting`?oe:n.mode===`unmanaged`?ae:n.mode===`error`||n.warnings.length>0?z:F:I}function Re(e){return e.mode===`waiting`?`Waiting for managed development to start.`:e.mode===`unmanaged`?`Managed synchronization is unavailable for this session.`:e.mode===`error`?`Managed synchronization stopped.`:e.draft&&!e.target?`Commit the local changes before managed development checks for updates.`:e.pendingRebase?`The update stopped on a conflict and needs Codex to finish replaying your commits.`:e.target&&e.target.source!==`upstream`?String(e.target?.source)===`dev`?`New changes are available in local dev.`:`New changes are available in local main.`:e.target?`A newer main commit is ready.`:`Managed development is active. No updates are available.`}function ze(e){return e?.mode===`error`&&e.message?.startsWith(a)===!0}function Be(e){return e?.message?.startsWith(o)===!0}function Ve(e){return e.mode!==`managed`||!!(e.busy||e.codexCompletion||e.draft||e.message||e.pendingRebase||e.setupFailure||e.target||e.warnings.length>0)}function He(e){if(!e?.checks||Ve(e))return;let t=e.checks.commands.find(e=>e.status===`failed`&&!e.dismissed);return t?{check:t,commit:e.checks.commit,trigger:e.checks.trigger}:void 0}function Ue({commit:e,trigger:t}){let n=e.slice(0,12);return t===`codegen-recovery`?`Managed dev ran this check after Panda codegen recovered for commit ${n}.`:t===`dependency-recovery`?`Managed dev ran this check after dependency installation recovered for commit ${n}.`:t===`database-recovery`?`Managed dev ran this check after database setup recovered for commit ${n}.`:`Managed dev ran this check after synchronizing the accepted update at commit ${n}.`}function $(e,t=He(e)){return e?e.mode===`waiting`?!!e.message:!!(t||Ve(e)):!1}function We(e){let t=new Set(e.filter(e=>e.kind===`user`)),n=[...t].reduce((e,t)=>e+t.text.length,0),r=!1;for(let i of[...e].reverse())if(i.kind!==`user`){if(n+i.text.length>1e5&&r)break;t.add(i),r=!0,n+=i.text.length}return e.filter(e=>t.has(e))}function Ge(e){return[e.message,`Commit: ${e.commit}`,`Command: ${e.command}`,``,e.output].join(`
177
- `)}function Ke(){let[e,n]=_(),[r,i]=_(!1),[a,o]=_(),s=he(),c=g(void 0);return m(()=>{if(!s)return;let e=e=>{if(e.requestId===c.current){if(e.state===`busy`){i(!0);return}if(c.current=void 0,i(!1),e.state===`error`){o(void 0),n(e.error??`The Vite restart failed.`);return}n(void 0),o(`Vite restarted.`)}},r=()=>{c.current&&(c.current=void 0,i(!1),o(void 0),n(`The connection was interrupted during the restart. Reconnect before trying again.`))};return s.on(t.actionResult,e),s.on(V.disconnect,r),()=>{s.off(t.actionResult,e),s.off(V.disconnect,r)}},[s]),{error:e,pending:r,reloadPage:()=>globalThis.location.reload(),restartVite:()=>{if(r)return;if(n(void 0),o(void 0),!s){n(`The Vite HMR connection is unavailable.`);return}let e=globalThis.crypto.getRandomValues(new Uint32Array(4)).join(`-`);c.current=e,i(!0),s.send(t.action,{action:{type:`restart-vite`},requestId:e})},success:a}}function qe(e){return e.type===`apply`?{heading:`Refresh complete`,message:`Your changes were committed and the project is up to date.`}:e.type===`prepare`?{heading:`Refresh complete`,message:`Your project is up to date.`}:e.type===`commit`?{heading:`Changes committed`,message:`Your local changes are committed. Checking for managed development updates…`,preserveDuringStatus:!0}:e.type===`reject`?{heading:`Update dismissed`,message:`No further action is required.`}:e.type===`configure-codex`?{heading:`Codex preferences saved`,message:`The selected model and effort will be used for future conflict resolution.`}:e.type===`decline-rebase`?{heading:`Codex resolution declined`,message:`The cleanly applied commits stay on your branch.`}:e.type===`resolve-rebase`?{heading:`Refresh complete`,message:`Codex resolved the remaining conflicts and the project is up to date.`}:e.type===`retry-install`?{heading:`Setup complete`,message:`Dependencies installed and the project is ready.`}:e.type===`retry-codegen`?{heading:`Codegen complete`,message:`Panda generated code is ready.`}:e.type===`reset-database`?{heading:`Database reset complete`,message:`The database was recreated, migrated, and seeded.`}:e.type===`retry-supervisor`?{heading:`Managed development reconnected`,message:`The managed development supervisor is connected again.`}:e.type===`cancel-codex`?{heading:`Update cancelled`,message:`The Codex conflict resolution was cancelled.`}:{heading:`Action complete`,message:`No further action is required.`}}function Je(){let[e,t]=_(),[n,r]=_(),[a,o]=_(!1),[s,c]=_(),[l,u]=_(),[d,p]=_(ve),[h,v]=_(),y=g(void 0),b=g(void 0),x=g(new Map),S=ge();m(()=>{if(!S)return;let e=x.current,n=!1,a=()=>{o(!0),n&&(n=!1,S.send(i.statusRequest))},s=()=>{n=!0,o(!1),t(void 0),r(void 0),c(void 0),v(void 0),e.clear(),y.current=void 0,u(void 0),G(!1)},l=({status:n})=>{let i=$(n);if(Be(n)){for(let[t,n]of e)n.type!==`retry-supervisor`&&e.delete(t);[...e.values()].some(e=>e.type===`retry-supervisor`)||v(void 0),y.current=void 0,u(void 0),r(void 0),c(void 0)}o(!0),t(n),n.codexOptions&&p(e=>({...e,...n.codexOptions})),n.codexCompletion&&b.current!==n.codexCompletion.id&&(b.current=n.codexCompletion.id,G(!0));let a=!n.busy&&!n.codexCompletion?[...e.entries()].filter(([,e])=>e.type===`acknowledge-codex`).map(([e])=>e):[];if(a.length>0){for(let t of a)e.delete(t);v([...e.values()].at(-1)),c(void 0),i||G(!1)}i&&c(e=>e?.preserveDuringStatus?e:void 0)},d=n=>{let i=e.get(n.requestId);i&&(e.delete(n.requestId),v([...e.values()].at(-1)),n.status&&t(n.status),n.error?(y.current?.requestId===n.requestId&&(y.current=void 0,u(void 0)),r(n.error),i.type===`acknowledge-codex`&&G(!0)):n.status?.codexCompletion?(b.current=n.status.codexCompletion.id,y.current=void 0,u(void 0),c(void 0),G(!0)):i.type===`acknowledge-codex`||i.type===`dismiss-check`?(c(void 0),n.status&&!$(n.status)&&G(!1)):i.type===`configure-codex`||i.type===`cancel-codex`?c(void 0):n.status&&(i.type===`commit`||!$(n.status))&&c(qe(i)))},f=t=>{if(!e.has(t.requestId))return;if(t.phase===`start`){let e={commits:t.commits,messages:[t.message],phase:`running`,requestId:t.requestId,totalCommits:t.totalCommits};y.current=e,u(e),G(!0);return}let n=y.current;if(!n||n.requestId!==t.requestId)return;let r=t.phase===`message`?{...n,messages:We([...n.messages,t.message])}:t.phase===`complete`?{commits:n.commits,messages:n.messages,phase:`complete`,requestId:t.requestId,totalCommits:n.totalCommits}:t.phase===`progress`?{...n,commits:t.commits,totalCommits:t.totalCommits??n.totalCommits}:{...n,phase:`error`};y.current=r,u(r)};S.on(V.connect,a),S.on(V.disconnect,s),S.on(i.status,l),S.on(i.actionResult,d),S.on(i.codex,f),S.send(i.statusRequest);let m=globalThis.setInterval(()=>{e.size>0&&S.send(i.statusRequest,{requestIds:[...e.keys()]})},1e3);return()=>{globalThis.clearInterval(m),e.clear(),y.current=void 0,S.off(V.connect,a),S.off(V.disconnect,s),S.off(i.status,l),S.off(i.actionResult,d),S.off(i.codex,f)}},[S]);let C=async e=>{if(e.type===`acknowledge-codex`&&(b.current=e.id),r(void 0),c(void 0),e.type!==`cancel-codex`&&(y.current=void 0,u(void 0)),!S){r(`The Vite HMR connection is unavailable.`);return}let t=globalThis.crypto.getRandomValues(new Uint32Array(4)).join(`-`);x.current.set(t,e),v(e),S.send(i.action,{action:e,requestId:t})},w=f(()=>c(void 0),[]);return{act:C,checkFailure:!n&&!s&&!l&&!e?.codexCompletion?He(e):void 0,codex:l,codexOptions:d,dismissCheckFailure:e=>{if(!e.check.failureId){G(!1);return}C({failureId:e.check.failureId,type:`dismiss-check`})},dismissError:()=>r(void 0),dismissSuccess:w,error:n,hmrReady:a,pendingAction:h,setCodexOptions:p,status:e,success:s}}function Ye(e){return W.add(e),()=>W.delete(e)}function Xe(){return U}function Ze(){return!1}export{Se as ManagedDevOverlay,q as ManagedDevOverlayIndicator,xe as toggleManagedDevOverlay};
177
+ `)}function Ke(){let[e,n]=_(),[r,i]=_(!1),[a,o]=_(),s=he(),c=g(void 0);return m(()=>{if(!s)return;let e=e=>{if(e.requestId===c.current){if(e.state===`busy`){i(!0);return}if(c.current=void 0,i(!1),e.state===`error`){o(void 0),n(e.error??`The Vite restart failed.`);return}n(void 0),o(`Vite restarted.`)}},r=()=>{c.current&&(c.current=void 0,i(!1),o(void 0),n(`The connection was interrupted during the restart. Reconnect before trying again.`))};return s.on(t.actionResult,e),s.on(V.disconnect,r),()=>{s.off(t.actionResult,e),s.off(V.disconnect,r)}},[s]),{error:e,pending:r,reloadPage:()=>globalThis.location.reload(),restartVite:()=>{if(r)return;if(n(void 0),o(void 0),!s){n(`The Vite HMR connection is unavailable.`);return}let e=globalThis.crypto.getRandomValues(new Uint32Array(4)).join(`-`);c.current=e,i(!0),s.send(t.action,{action:{type:`restart-vite`},requestId:e})},success:a}}function qe(e){return e.type===`apply`?{heading:`Refresh complete`,message:`Your changes were committed and the project is up to date.`}:e.type===`prepare`?{heading:`Refresh complete`,message:`Your project is up to date.`}:e.type===`commit`?{heading:`Changes committed`,message:`Your local changes are committed. Checking for managed development updates…`,preserveDuringStatus:!0}:e.type===`reject`?{heading:`Update dismissed`,message:`No further action is required.`}:e.type===`configure-codex`?{heading:`Codex preferences saved`,message:`The selected model and effort will be used for future conflict resolution.`}:e.type===`decline-rebase`?{heading:`Codex resolution declined`,message:`The cleanly applied commits stay on your branch.`}:e.type===`resolve-rebase`?{heading:`Refresh complete`,message:`Codex resolved the remaining conflicts and the project is up to date.`}:e.type===`retry-install`?{heading:`Setup complete`,message:`Dependencies installed and the project is ready.`}:e.type===`retry-codegen`?{heading:`Codegen complete`,message:`Panda generated code is ready.`}:e.type===`reset-database`?{heading:`Database reset complete`,message:`The database was recreated, migrated, and seeded.`}:e.type===`retry-supervisor`?{heading:`Managed development reconnected`,message:`The managed development supervisor is connected again.`}:e.type===`cancel-codex`?{heading:`Update cancelled`,message:`The Codex conflict resolution was cancelled.`}:{heading:`Action complete`,message:`No further action is required.`}}function Je(){let[e,t]=_(),[n,r]=_(),[a,o]=_(!1),[s,c]=_(),[l,u]=_(),[d,p]=_(ve),[h,v]=_(),y=g(void 0),b=g(void 0),x=g(new Map),S=ge();m(()=>{if(!S)return;let e=x.current,n=e=>{try{S.send(i.diagnostic,e)}catch{}},a,s=!1,l=()=>{n({type:`connected`}),o(!0),s&&(s=!1,S.send(i.statusRequest))},d=()=>{n({type:`disconnected`}),a=void 0,s=!0,o(!1),t(void 0),r(void 0),c(void 0),v(void 0),e.clear(),y.current=void 0,u(void 0),G(!1)},f=({status:i})=>{let s=JSON.stringify([i.trace,i.mode,i.busy]);s!==a&&(a=s,n({type:`status-received`,sessionId:i.trace?.sessionId,revision:i.trace?.revision,requestId:i.trace?.operationId,busy:!!i.busy}));let l=$(i);if(Be(i)){for(let[t,n]of e)n.type!==`retry-supervisor`&&e.delete(t);[...e.values()].some(e=>e.type===`retry-supervisor`)||v(void 0),y.current=void 0,u(void 0),r(void 0),c(void 0)}o(!0),t(i),i.codexOptions&&p(e=>({...e,...i.codexOptions})),i.codexCompletion&&b.current!==i.codexCompletion.id&&(b.current=i.codexCompletion.id,G(!0));let d=!i.busy&&!i.codexCompletion?[...e.entries()].filter(([,e])=>e.type===`acknowledge-codex`).map(([e])=>e):[];if(d.length>0){for(let t of d)e.delete(t);v([...e.values()].at(-1)),c(void 0),l||G(!1)}l&&c(e=>e?.preserveDuringStatus?e:void 0)},m=i=>{n({type:`action-result-received`,requestId:i.requestId,sessionId:i.status?.trace?.sessionId,revision:i.status?.trace?.revision,busy:!!i.status?.busy,pending:e.has(i.requestId)});let a=e.get(i.requestId);a&&(e.delete(i.requestId),v([...e.values()].at(-1)),i.status&&t(i.status),i.error?(y.current?.requestId===i.requestId&&(y.current=void 0,u(void 0)),r(i.error),a.type===`acknowledge-codex`&&G(!0)):i.status?.codexCompletion?(b.current=i.status.codexCompletion.id,y.current=void 0,u(void 0),c(void 0),G(!0)):a.type===`acknowledge-codex`||a.type===`dismiss-check`?(c(void 0),i.status&&!$(i.status)&&G(!1)):a.type===`configure-codex`||a.type===`cancel-codex`?c(void 0):i.status&&(a.type===`commit`||!$(i.status))&&c(qe(a)))},h=t=>{if(!e.has(t.requestId))return;if(t.phase===`start`){let e={commits:t.commits,messages:[t.message],phase:`running`,requestId:t.requestId,totalCommits:t.totalCommits};y.current=e,u(e),G(!0);return}let n=y.current;if(!n||n.requestId!==t.requestId)return;let r=t.phase===`message`?{...n,messages:We([...n.messages,t.message])}:t.phase===`complete`?{commits:n.commits,messages:n.messages,phase:`complete`,requestId:t.requestId,totalCommits:n.totalCommits}:t.phase===`progress`?{...n,commits:t.commits,totalCommits:t.totalCommits??n.totalCommits}:{...n,phase:`error`};y.current=r,u(r)};S.on(V.connect,l),S.on(V.disconnect,d),S.on(i.status,f),S.on(i.actionResult,m),S.on(i.codex,h),S.send(i.statusRequest);let g=globalThis.setInterval(()=>{e.size>0&&S.send(i.statusRequest,{requestIds:[...e.keys()]})},1e3);return()=>{globalThis.clearInterval(g),e.clear(),y.current=void 0,S.off(V.connect,l),S.off(V.disconnect,d),S.off(i.status,f),S.off(i.actionResult,m),S.off(i.codex,h)}},[S]);let C=async e=>{if(e.type===`acknowledge-codex`&&(b.current=e.id),r(void 0),c(void 0),e.type!==`cancel-codex`&&(y.current=void 0,u(void 0)),!S){r(`The Vite HMR connection is unavailable.`);return}let t=globalThis.crypto.getRandomValues(new Uint32Array(4)).join(`-`);x.current.set(t,e),v(e),S.send(i.action,{action:e,requestId:t})},w=f(()=>c(void 0),[]);return{act:C,checkFailure:!n&&!s&&!l&&!e?.codexCompletion?He(e):void 0,codex:l,codexOptions:d,dismissCheckFailure:e=>{if(!e.check.failureId){G(!1);return}C({failureId:e.check.failureId,type:`dismiss-check`})},dismissError:()=>r(void 0),dismissSuccess:w,error:n,hmrReady:a,pendingAction:h,setCodexOptions:p,status:e,success:s}}function Ye(e){return W.add(e),()=>W.delete(e)}function Xe(){return U}function Ze(){return!1}export{Se as ManagedDevOverlay,q as ManagedDevOverlayIndicator,xe as toggleManagedDevOverlay};
@@ -1 +1 @@
1
- import{mkdir as e,writeFile as t}from"node:fs/promises";import n from"node:path";import{readProjectConfig as r}from"@coreframe/config";import{randomUUID as i}from"node:crypto";import{managedDevEnv as a,managedDevEvents as o,managedDevFlutterRestartFileEnv as s,managedDevSupervisorRecoveryErrorPrefix as c}from"@coreframe/dev-contracts/managed-dev";import{startManagedDevSession as l}from"@coreframe/dev/managed-dev";import{connectDevSupervisor as u,connectExistingDevSupervisor as d}from"@coreframe/dev/supervisor";const f=Symbol.for(`@coreframe/vite/managed-dev-session-states`),p=(()=>{let e=globalThis;return e[f]??=new Map})(),m=[100,500,2e3];function h({connectSupervisor:f,env:p=process.env,recoverSupervisor:h,startSession:v=l}={}){let x=p[a]===`1`,S=f??d,C=h??f??u,w,T,E,D,O,k,A,j,M,N=!1,P=!1,F=!1,I=!1,L=!1,R=new Map,z=new WeakMap,B=new WeakMap,V=(e,t)=>{let n=B.get(e)??new Map;n.set(t.requestId,t),n.size>100&&n.delete(n.keys().next().value),B.set(e,n),e.send(o.actionResult,t)},H={mode:`waiting`,warnings:[]},U=()=>{let e=T;return D?.(),D=void 0,O?.(),O=void 0,T=void 0,E=void 0,e},W=()=>M??=(async()=>{L=!0,await A,await j,I=!1;let e=w,t=T,n=E;w=void 0,U(),e&&k&&await _(k,e),t&&(n&&await t.release(n).catch(()=>void 0),t.close())})();return{name:`coreframe:managed-dev`,apply:`serve`,config(){return{define:{"import.meta.env.COREFRAME_MANAGED_DEV":JSON.stringify(x)}}},configureServer(a){if(!x)return;let l=a.config.root;k=l;let u=!1,d=!1,f=()=>w?.getStatus()??H,h=()=>{L||a.ws.send(o.status,{status:f()})},M=()=>{d||L||(d=!0,queueMicrotask(()=>{d=!1,Promise.resolve(a.restart()).catch(e=>{let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development restart failed: ${t}`,{error:e instanceof Error?e:void 0})})}))},G=(e,t)=>{if(L||T!==e||!I||t.event!==`managed-dev`)return;if(t.kind===`status`){H=t.status,h();return}if(t.kind===`restart`){u=!0,R.size===0&&(u=!1,M());return}let n=R.get(t.requestId);!n||!t.codex||typeof t.codex!=`object`||n.client.send(o.codex,{...t.codex,requestId:n.requestId})},K=async e=>{let t,n=!1,r=e.onEvent(t=>G(e,t)),i=e.onClose(t=>{n=!0,!L&&T===e&&P&&!F&&!j&&(I=!1,q(t))});T=e,D=r,O=i;try{await e.subscribe([`managed-dev`]);let r=await e.acquireManagedDev({env:p});if(t=r.leaseId,n||L||T!==e)throw Error(`The development supervisor disconnected while managed development was attaching.`);E=r.leaseId,H=r.status,I=!0,P=!0,h()}catch(n){throw T===e?U():(r(),i()),t&&await e.release(t).catch(()=>void 0),e.close(),n}};function q(e,t=!1){if(L||!P)return Promise.resolve();if(j)return j;I=!1,N=!1,U()?.close(),H={message:t?`Managed development supervisor retrying connection.`:`Managed development supervisor disconnected. Reconnecting…`,mode:`waiting`,warnings:[]},h();let n=(async()=>{let t=e;for(let e=0;e<4;e+=1){if(L||(e>0&&await new Promise(t=>setTimeout(t,m[e-1]??2e3)),L))return;try{let e=await C({cwd:l,env:p,requiredResources:[`managed-dev`]});if(!e)throw Error(`No managed development supervisor is available.`);if(L){e.close();return}await K(e),N=!1;return}catch(n){t=n;let r=y(n);a.config.logger.error(`Coreframe managed development supervisor recovery attempt ${e+1} failed: ${r}`,{error:n instanceof Error?n:void 0}),e+1<4&&(H={message:`Managed development supervisor recovery is retrying (${e+2}/4).`,mode:`waiting`,warnings:[]},h())}}if(L)return;let n=y(t),r=`${c}4 attempts: ${n} Retry to reconnect managed development.`;N=!0,H={message:r,mode:`error`,warnings:[r]},a.config.logger.error(`Coreframe managed development supervisor recovery failed: ${n}`,{error:t instanceof Error?t:void 0}),h()})();return j=n,n.then(()=>{j===n&&(j=void 0)},()=>{j===n&&(j=void 0)}),n}let J=(e,t)=>{P&&T===e&&b(t)&&(I=!1,q(t))},Y=async(e,t)=>{let n=e?.requestIds;if(Array.isArray(n))for(let e of n.slice(0,100)){let n=B.get(t)?.get(e);n?t.send(o.actionResult,n):typeof e==`string`&&!z.get(t)?.has(e)&&V(t,{requestId:e,error:`The server has no result for this request. Check the current status before trying again.`})}let r=T;if(r&&I)try{H=(await r.managedDevStatus()).status}catch(e){let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development status failed: ${t}`,{error:e instanceof Error?e:void 0}),J(r,e)}t.send(o.status,{status:f()})},X=async(e,t)=>{if(e.action.type===`retry-supervisor`){try{if(!P||!N)throw Error(`Managed development supervisor recovery is not available.`);await q(void 0,!0);let n=f();if(N)throw Error(n.message??`Managed development supervisor recovery failed.`);V(t,{requestId:e.requestId,status:n})}catch(n){let r=y(n);a.config.logger.error(`Coreframe managed development action failed: ${r}`,{error:n instanceof Error?n:void 0}),V(t,{error:r,requestId:e.requestId,status:f()})}return}let n;try{if(!I)throw Error(`Managed development is still initializing.`);let n=T;if(n){let r=i();R.set(r,{client:t,requestId:e.requestId});try{let i=await n.managedDevAction({action:e.action,requestId:r});i.status&&(H=i.status),V(t,{...i,requestId:e.requestId}),!i.error&&u&&(u=!1,M())}catch(e){throw J(n,e),e}finally{R.delete(r)}return}let r=w;if(!r)throw Error(`Managed development is still initializing.`);let s=await r.action(e.action,{onCodexEvent:n=>t.send(o.codex,{...n,requestId:e.requestId})});V(t,{requestId:e.requestId,...s}),u&&(u=!1,queueMicrotask(()=>{W().then(()=>a.restart()).catch(e=>{let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development restart failed: ${t}`,{error:e instanceof Error?e:void 0})})}));return}catch(e){n=e}let r=n instanceof Error?n.message:String(n);a.config.logger.error(`Coreframe managed development action failed: ${r}`,{error:n instanceof Error?n:void 0}),V(t,{error:r,requestId:e.requestId,status:f()})},Z=async(e,t)=>{let n=z.get(t)??new Set;if(z.set(t,n),n.has(e.requestId))return;let r=B.get(t)?.get(e.requestId);if(r){t.send(o.actionResult,r);return}n.add(e.requestId);try{await X(e,t)}finally{n.delete(e.requestId)}};a.ws.on(o.statusRequest,Y),a.ws.on(o.action,Z),A=(async()=>{let o,c;try{if(F=!0,o=await S({cwd:l,env:p,requiredResources:[`managed-dev`]}),o){if(L){o.close();return}await K(o);return}let d=await r({cwd:l});if(L)return;if(c=await v({config:d,cwd:l,env:p,onRestart:()=>{u=!0},onFlutterRestart:async()=>{let r=p[s];if(r)try{await e(n.dirname(r),{recursive:!0}),await t(r,`${i()}\n`,{mode:384})}catch(e){let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe Flutter restart request failed: ${t}`,{error:e instanceof Error?e:void 0})}},onStatusChange:e=>{H=e,h()}}),w=c,H=c.getStatus(),L){w=void 0,await c.close();return}if(await g(l,c),L){w=void 0,await _(l,c);return}I=!0}catch(e){if(o&&T===o&&(U(),o.close()),w===c&&(w=void 0),!L){let t=e instanceof Error?e.message:String(e);H={message:t,mode:`error`,warnings:[t]},a.config.logger.error(`Coreframe managed development initialization failed: ${t}`,{error:e instanceof Error?e:void 0}),h()}}finally{F=!1}})(),a.httpServer?.once(`close`,()=>{a.ws.off(o.statusRequest,Y),a.ws.off(o.action,Z),W()})},async closeBundle(){await W()}}}async function g(e,t){await v(e,async e=>{let n=e.session;e.session=void 0,await n?.close();try{await t.activate(),e.session=t}catch(e){throw await t.close(),e}})}async function _(e,t){await v(e,async e=>{e.session===t&&(e.session=void 0),await t.close()})}async function v(e,t){let n=p.get(e);n||(n={transition:Promise.resolve()},p.set(e,n));let r=n.transition,i;n.transition=new Promise(e=>{i=()=>e()}),await r;try{await t(n)}finally{i()}}function y(e){return e instanceof Error?e.message:String(e)}function b(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.retryable===!0||t.code===`LEASE_EXPIRED`||t.code===`SUPERVISOR_STOPPING`}export{h as coreframeManagedDevPlugin};
1
+ import{mkdir as e,writeFile as t}from"node:fs/promises";import n from"node:path";import{readProjectConfig as r}from"@coreframe/config";import{randomUUID as i}from"node:crypto";import{managedDevEnv as a,managedDevEvents as o,managedDevFlutterRestartFileEnv as s,managedDevSupervisorRecoveryErrorPrefix as c}from"@coreframe/dev-contracts/managed-dev";import{startManagedDevSession as l}from"@coreframe/dev/managed-dev";import{DevDiagnostics as u,connectDevSupervisor as d,connectExistingDevSupervisor as f,devDiagnosticError as p,devDiagnosticPhase as ee}from"@coreframe/dev/supervisor";const m=Symbol.for(`@coreframe/vite/managed-dev-session-states`),h=(()=>{let e=globalThis;return e[m]??=new Map})(),te=[100,500,2e3];function g({connectSupervisor:m,env:h=process.env,recoverSupervisor:g,startSession:y=l}={}){let x=h[a]===`1`,S=m??f,C=g??m??d,w,T,E,D,O,k,A,j,M,N=!1,P=!1,F=!1,I=!1,L=!1,R,z=new Map,B=new WeakMap,V=new WeakMap,H=(e,t)=>{let n=V.get(e)??new Map;n.set(t.requestId,t),n.size>100&&n.delete(n.keys().next().value),V.set(e,n),R?.event(`action.result-sent`,{operationId:t.requestId,failed:!!t.error,sessionId:t.status?.trace?.sessionId,revision:t.status?.trace?.revision,busy:!!t.status?.busy}),e.send(o.actionResult,t)},U={mode:`waiting`,warnings:[]},W=()=>{let e=T;return D?.(),D=void 0,O?.(),O=void 0,T=void 0,E=void 0,e},G=()=>M??=(async()=>{L=!0,await A,await j,I=!1;let e=w,t=T,n=E;w=void 0,W(),e&&k&&await v(k,e),t&&(n&&await t.release(n).catch(()=>void 0),t.close()),R?.event(`vite.detached`),R?.close()})();return{name:`coreframe:managed-dev`,apply:`serve`,config(){return{define:{"import.meta.env.COREFRAME_MANAGED_DEV":JSON.stringify(x)}}},configureServer(a){if(!x)return;let l=a.config.root;R=new u(l,`vite`),R.event(`vite.attached`),k=l;let d=!1,f=!1,m=()=>w?.getStatus()??U,g,M=(e,t)=>{let n=JSON.stringify([e.trace,e.mode,e.busy]);n!==g&&(g=n,R?.event(`status.sent`,{sessionId:e.trace?.sessionId,revision:e.trace?.revision,operationId:e.trace?.operationId,mode:e.mode,busy:!!e.busy,delivery:t},`debug`))},K=()=>{if(!L){let e=m();M(e,`broadcast`),a.ws.send(o.status,{status:e})}},q=()=>{f||L||(f=!0,R?.event(`vite.restart-queued`),queueMicrotask(()=>{f=!1,Promise.resolve(a.restart()).catch(e=>{R?.event(`vite.restart-failed`,p(e),`error`);let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development restart failed: ${t}`,{error:e instanceof Error?e:void 0})})}))},re=(e,t)=>{if(L||T!==e||!I||t.event!==`managed-dev`)return;if(t.kind===`status`){U=t.status,K();return}if(t.kind===`restart`){d=!0,z.size===0&&(d=!1,q());return}let n=z.get(t.requestId);!n||!t.codex||typeof t.codex!=`object`||n.client.send(o.codex,{...t.codex,requestId:n.requestId})},J=async e=>{R?.event(`supervisor.connecting`,{supervisorId:e.state?.supervisorId,supervisorPid:e.state?.pid});let t,n=!1,r=e.onEvent(t=>re(e,t)),i=e.onClose(t=>{n=!0,!L&&T===e&&P&&!F&&!j&&(I=!1,Y(t))});T=e,D=r,O=i;try{await e.subscribe([`managed-dev`]);let r=await e.acquireManagedDev({env:h});if(R?.event(`supervisor.connected`,{supervisorId:e.state?.supervisorId,leaseId:r.leaseId}),t=r.leaseId,n||L||T!==e)throw Error(`The development supervisor disconnected while managed development was attaching.`);E=r.leaseId,U=r.status,I=!0,P=!0,K()}catch(n){throw T===e?W():(r(),i()),t&&await e.release(t).catch(()=>void 0),e.close(),n}};function Y(e,t=!1){if(L||!P)return Promise.resolve();if(j)return j;I=!1,R?.event(`supervisor.recovery-started`,{explicit:t,...p(e)},`warn`),N=!1,W()?.close(),U={message:t?`Managed development supervisor retrying connection.`:`Managed development supervisor disconnected. Reconnecting…`,mode:`waiting`,warnings:[]},K();let n=(async()=>{let t=e;for(let e=0;e<4;e+=1){if(L||(e>0&&await new Promise(t=>setTimeout(t,te[e-1]??2e3)),L))return;try{let e=await C({cwd:l,env:h,requiredResources:[`managed-dev`]});if(!e)throw Error(`No managed development supervisor is available.`);if(L){e.close();return}await J(e),N=!1;return}catch(n){R?.event(`supervisor.recovery-failed`,{attempt:e+1,...p(n)},`warn`),t=n;let r=b(n);a.config.logger.error(`Coreframe managed development supervisor recovery attempt ${e+1} failed: ${r}`,{error:n instanceof Error?n:void 0}),e+1<4&&(U={message:`Managed development supervisor recovery is retrying (${e+2}/4).`,mode:`waiting`,warnings:[]},K())}}if(L)return;let n=b(t),r=`${c}4 attempts: ${n} Retry to reconnect managed development.`;N=!0,U={message:r,mode:`error`,warnings:[r]},a.config.logger.error(`Coreframe managed development supervisor recovery failed: ${n}`,{error:t instanceof Error?t:void 0}),K()})();return j=n,n.then(()=>{j===n&&(j=void 0)},()=>{j===n&&(j=void 0)}),n}let X=(e,t)=>{P&&T===e&&ne(t)&&(I=!1,Y(t))},Z=async(e,t)=>{let n=e?.requestIds;if(Array.isArray(n))for(let e of n.slice(0,100)){let n=V.get(t)?.get(e);n?(R?.event(`action.result-replayed`,{operationId:n.requestId},`debug`),t.send(o.actionResult,n)):typeof e==`string`&&!B.get(t)?.has(e)&&H(t,{requestId:e,error:`The server has no result for this request. Check the current status before trying again.`})}let r=T;if(r&&I)try{U=(await r.managedDevStatus()).status}catch(e){let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development status failed: ${t}`,{error:e instanceof Error?e:void 0}),X(r,e)}let i=m();M(i,`response`),t.send(o.status,{status:i})},Q=e=>{if(!e||typeof e!=`object`)return;let t=e;if(![`status-received`,`action-result-received`,`connected`,`disconnected`].includes(t.type))return;let n=e=>typeof e==`string`&&/^[a-zA-Z0-9-]{1,160}$/.test(e)?e:void 0;R?.event(`overlay.${t.type}`,{operationId:n(t.requestId),sessionId:n(t.sessionId),revision:Number.isSafeInteger(t.revision)&&t.revision>=0?t.revision:void 0,busy:typeof t.busy==`boolean`?t.busy:void 0,pending:typeof t.pending==`boolean`?t.pending:void 0},`debug`)},ie=async(e,t)=>{if(e.action.type===`retry-supervisor`){try{if(!P||!N)throw Error(`Managed development supervisor recovery is not available.`);await Y(void 0,!0);let n=m();if(N)throw Error(n.message??`Managed development supervisor recovery failed.`);H(t,{requestId:e.requestId,status:n})}catch(n){let r=b(n);a.config.logger.error(`Coreframe managed development action failed: ${r}`,{error:n instanceof Error?n:void 0}),H(t,{error:r,requestId:e.requestId,status:m()})}return}let n;try{if(!I)throw Error(`Managed development is still initializing.`);let n=T;if(n){let r=i();z.set(r,{client:t,requestId:e.requestId});try{let i=await n.managedDevAction({action:e.action,requestId:r,operationId:e.requestId});i.status&&(U=i.status),H(t,{...i,requestId:e.requestId}),!i.error&&d&&(d=!1,q())}catch(e){throw X(n,e),e}finally{z.delete(r)}return}let r=w;if(!r)throw Error(`Managed development is still initializing.`);let s=await r.action(e.action,{operationId:e.requestId,onCodexEvent:n=>t.send(o.codex,{...n,requestId:e.requestId})});H(t,{requestId:e.requestId,...s}),d&&(d=!1,queueMicrotask(()=>{G().then(()=>a.restart()).catch(e=>{let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe managed development restart failed: ${t}`,{error:e instanceof Error?e:void 0})})}));return}catch(e){n=e}let r=n instanceof Error?n.message:String(n);a.config.logger.error(`Coreframe managed development action failed: ${r}`,{error:n instanceof Error?n:void 0}),H(t,{error:r,requestId:e.requestId,status:m()})},$=async(e,t)=>{let n=B.get(t)??new Set;if(B.set(t,n),n.has(e.requestId))return;let r=V.get(t)?.get(e.requestId);if(r){t.send(o.actionResult,r);return}n.add(e.requestId);try{await R.run({operationId:e.requestId,actionType:e.action.type},()=>ee(`vite.action`,()=>ie(e,t)))}finally{n.delete(e.requestId)}};a.ws.on(o.statusRequest,Z),a.ws.on(o.action,$),a.ws.on(o.diagnostic,Q),A=(async()=>{let o,c;try{if(F=!0,o=await S({cwd:l,env:h,requiredResources:[`managed-dev`]}),o){if(L){o.close();return}await J(o);return}let u=await r({cwd:l});if(L)return;if(c=await y({config:u,cwd:l,env:h,onRestart:()=>{d=!0},onFlutterRestart:async()=>{let r=h[s];if(r)try{await e(n.dirname(r),{recursive:!0}),await t(r,`${i()}\n`,{mode:384})}catch(e){let t=e instanceof Error?e.message:String(e);a.config.logger.error(`Coreframe Flutter restart request failed: ${t}`,{error:e instanceof Error?e:void 0})}},onStatusChange:e=>{U=e,K()}}),w=c,U=c.getStatus(),L){w=void 0,await c.close();return}if(await _(l,c),L){w=void 0,await v(l,c);return}I=!0}catch(e){if(R?.event(`vite.initialization-failed`,p(e),`error`),o&&T===o&&(W(),o.close()),w===c&&(w=void 0),!L){let t=e instanceof Error?e.message:String(e);U={message:t,mode:`error`,warnings:[t]},a.config.logger.error(`Coreframe managed development initialization failed: ${t}`,{error:e instanceof Error?e:void 0}),K()}}finally{F=!1}})(),a.httpServer?.once(`close`,()=>{a.ws.off(o.statusRequest,Z),a.ws.off(o.action,$),a.ws.off(o.diagnostic,Q),G()})},async closeBundle(){await G()}}}async function _(e,t){await y(e,async e=>{let n=e.session;e.session=void 0,await n?.close();try{await t.activate(),e.session=t}catch(e){throw await t.close(),e}})}async function v(e,t){await y(e,async e=>{e.session===t&&(e.session=void 0),await t.close()})}async function y(e,t){let n=h.get(e);n||(n={transition:Promise.resolve()},h.set(e,n));let r=n.transition,i;n.transition=new Promise(e=>{i=()=>e()}),await r;try{await t(n)}finally{i()}}function b(e){return e instanceof Error?e.message:String(e)}function ne(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.retryable===!0||t.code===`LEASE_EXPIRED`||t.code===`SUPERVISOR_STOPPING`}export{g as coreframeManagedDevPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/vite",
3
- "version": "0.2.46",
3
+ "version": "0.2.47",
4
4
  "description": "Vite plugins and build integrations for Coreframe apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,11 +57,11 @@
57
57
  "obug": "^2.1.3",
58
58
  "unplugin": "^2.3.11",
59
59
  "vite-plugin-hashed-favicons": "^2.1.1",
60
- "@coreframe/config": "^0.1.18",
60
+ "@coreframe/dashboard": "^0.3.26",
61
+ "@coreframe/dev": "^0.1.31",
61
62
  "@coreframe/assets": "^0.1.21",
62
- "@coreframe/dashboard": "^0.3.25",
63
- "@coreframe/dev": "^0.1.30",
64
- "@coreframe/dev-contracts": "^0.1.10",
63
+ "@coreframe/config": "^0.1.18",
64
+ "@coreframe/dev-contracts": "^0.1.11",
65
65
  "@coreframe/flutter-js": "^0.1.32",
66
66
  "@coreframe/flutter-tools": "^0.1.29",
67
67
  "@coreframe/lib": "^0.2.16"