pi-webapp 0.1.45 → 0.1.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.
- package/README.md +9 -9
- package/README.zh-CN.md +9 -9
- package/bin/pi-webapp.mjs +21 -2
- package/desktop/launcher-handoff.mjs +45 -0
- package/dist/extension.js +30 -30
- package/dist/hosted-recovery.js +2 -2
- package/dist/hosted-worker.js +2 -2
- package/docs/desktop.md +38 -1
- package/package.json +4 -2
- package/web/dist/.vite/manifest.json +23 -23
- package/web/dist/assets/{app-hNL3Xxgd.js → app-DV6jw_lV.js} +86 -86
- package/web/dist/assets/app.js +4 -4
- package/web/dist/assets/{graphql-CRj-Kn5i.js → graphql-BJ_4HOLm.js} +1 -1
- package/web/dist/assets/{http-CyOctAOg.js → http-DXj-QPkN.js} +1 -1
- package/web/dist/assets/{php-BOTeIUQe.js → php-CnqpwLKI.js} +1 -1
- package/web/dist/assets/{plugin-DQnJE00I.js → plugin-BT2I2835.js} +1 -1
- package/web/dist/assets/{plugin-DCTf1UFm.js → plugin-CR1bEvHB.js} +1 -1
- package/web/dist/assets/{plugin-BrSFQWLr.js → plugin-S5t8fcf3.js} +1 -1
- package/web/dist/assets/{rst-CXOl9lK0.js → rst-CWQJ5Yif.js} +1 -1
- package/web/dist/assets/{ruby-BjwE7Pjp.js → ruby-CWbKAyt-.js} +1 -1
- package/web/dist/assets/{svelte-CgWeBJ9P.js → svelte-047iPa3M.js} +1 -1
- package/web/dist/assets/{vue-DlwySTUd.js → vue-CjffZrRU.js} +1 -1
package/dist/hosted-recovery.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new r.Error().stack;e&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[e]="43a186bd-1846-4778-96c1-c9d698dbad69",r._sentryDebugIdIdentifier="sentry-dbid-43a186bd-1846-4778-96c1-c9d698dbad69")}catch{}})();import{resolve as je}from"node:path";import{lstat as ie,readdir as Oe,rename as oe}from"node:fs/promises";import{join as k}from"node:path";import{createHash as de}from"node:crypto";var o=class extends Error{code;status;reason;constructor(e,t,n={}){super(t),this.name="HostedPluginError",this.code=e,this.status=n.status,this.reason=n.reason}};var L=r=>r.code==="ENOENT";var Ue={files:4096,total:128*1024*1024,js:16*1024*1024,css:4*1024*1024,font:8*1024*1024,other:2*1024*1024};var y=r=>de("sha256").update(r).digest("hex");import{constants as J}from"node:fs";import{DatabaseSync as ue}from"node:sqlite";import{lstat as V,mkdir as pe,open as A,rename as he,unlink as X}from"node:fs/promises";import{dirname as we,join as K,resolve as ge}from"node:path";import{randomUUID as me}from"node:crypto";import{setTimeout as ye}from"node:timers/promises";async function S(r){await pe(r,{recursive:!0,mode:448});let e=await V(r);if(!e.isDirectory()||e.isSymbolicLink())throw new o("invalid_storage","Plugin storage must be a real directory")}async function g(r,e){let t;try{t=await A(r,J.O_RDONLY|J.O_NONBLOCK|(J.O_NOFOLLOW??0))}catch(n){if(L(n))return null;throw n}try{let n=await t.stat();if(!n.isFile()||n.nlink>1||n.size>e)throw new o("invalid_storage","Invalid storage record size or type");let i=Buffer.alloc(Math.min(n.size+1,e+1)),s=0;for(;s<i.length;){let a=await t.read(i,s,i.length-s,s);if(!a.bytesRead)break;s+=a.bytesRead}if(s>e||s!==n.size)throw new o("invalid_storage","Storage record changed during read");return i.subarray(0,s)}finally{await t.close()}}async function E(r,e=2*1024*1024){let t=await g(r,e);if(!t)return null;try{return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t))}catch{throw new o("invalid_storage","Invalid JSON storage record; original bytes preserved")}}async function I(r){let e=await g(r,2097152);if(e===null)return null;let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e))}catch{throw new o("gc_recovery_required",`Invalid journal ${r}; stop all owners and inspect original bytes`)}if(!t||typeof t!="object"||Array.isArray(t))throw new o("gc_recovery_required",`Invalid journal ${r}; original bytes preserved`);return t}async function b(r,e){let t=`${r}.${me()}.tmp`,n=await A(t,"wx",384);try{try{await n.writeFile(JSON.stringify(e)),await n.sync()}finally{await n.close()}await he(t,r);let i;try{i=await A(we(r),"r"),await i.sync()}catch(s){if(!["EINVAL","EPERM","EACCES","EISDIR","ENOTSUP","EBADF"].includes(s.code??""))throw s}finally{await i?.close()}}finally{await X(t).catch(()=>{})}}var Y='{"version":2,"mechanism":"sqlite-exclusive"}',M=r=>r.toString("utf8")===Y,C=new Set;async function ve(r,e,t=0){await S(r);let n=K(r,`${e}.lock`),i=K(r,`${e}.ownership.sqlite`),s=e==="runtime"?"runtime_owned":"storage_busy",a=()=>new o(s,"Another host owns this plugin storage or a legacy ownership lock remains; stop all owners and verify a backup before offline recovery"),c;try{c=await A(i,"wx",384)}catch(h){if(h.code!=="EEXIST")throw h}finally{await c?.close()}let f=await V(i);if(!f.isFile()||f.isSymbolicLink()||f.nlink!==1||f.size>1024*1024)throw new o("invalid_storage","Ownership database must be a small, single-link regular file");let l=new ue(i,{allowExtension:!1}),u=ge(i),p=Date.now()+t,m=!1;try{for(;;){if(!C.has(u))try{l.exec("BEGIN EXCLUSIVE"),C.add(u),m=!0;break}catch(w){if(w.errcode!==5)throw w}if(Date.now()>=p)throw new o(s,"Another host owns this plugin storage; wait for it to stop before retrying");await ye(10)}let h=await g(n,4096);if(h===null){let w;try{w=await A(n,"wx",384),await w.writeFile(Y),await w.sync()}catch(_){if(_.code!=="EEXIST")throw _}finally{await w?.close()}h=await g(n,4096)}if(h===null||!M(h))throw a()}catch(h){throw l.close(),m&&C.delete(u),h}let v=!1;return async()=>{if(v)return;let h=await g(n,4096);if(h===null||!M(h))throw new o("invalid_storage","Ownership fence changed while held; preserve custody and inspect storage");await X(n),l.close(),C.delete(u),v=!0}}async function R(r,e,t=2e3){let n=await ve(r,"transaction",t);try{return await e()}finally{await n()}}import{lstat as F,mkdir as be,open as Q,realpath as Z,readdir as W,link as ke,rename as Ie,unlink as x,copyFile as _e,rm as xe}from"node:fs/promises";import{dirname as Se,isAbsolute as ee,join as d,relative as te,resolve as Ee,sep as U,win32 as Re}from"node:path";import{randomUUID as G}from"node:crypto";var N=192*1024*1024,H=512*1024,re=r=>typeof r=="string"&&/^[a-f0-9-]{36}$/.test(r);function Pe(r){if(!r||typeof r!="object"||Array.isArray(r))throw new o("invalid_input","Expected object input");return r}function ne(r){if(typeof r!="string"||!/^[\w.-]{1,160}$/.test(r)||r==="."||r==="..")throw new o("invalid_input","Invalid state key");return r}function T(r){if(r&&(!re(r.stateRef)||typeof r.version!="string"||!Number.isSafeInteger(r.generation)||r.generation<1||!Number.isSafeInteger(r.schema)||r.schema<1||typeof r.enabled!="boolean"||typeof r.operationId!="string"))throw new o("invalid_storage","Invalid active plugin record");return r}var D=class{root;pluginId;legacy;checkpoint;constructor(e,t,n,i){this.root=d(e,y(t)),this.pluginId=t,this.legacy=n,this.checkpoint=i}active(){return E(d(this.root,"active.json")).then(T)}async recover(){return R(this.root,async()=>{let e=await this.active(),t=await I(d(this.root,"transition.json"));if(!t)return{active:e,recovered:"none"};if(!t.next||!Object.hasOwn(t,"before")||Object.keys(t).some(a=>!["version","before","next"].includes(a))||Object.hasOwn(t,"version")&&t.version!==1)throw new o("invalid_storage","Invalid activation journal; stop all owners and inspect transition.json");T(t.next),T(t.before);let n=e?.operationId===t.next.operationId?"committed":"not_committed";if(!((a,c)=>a===null||c===null?a===c:["version","generation","stateRef","schema","enabled","operationId"].every(f=>a[f]===c[f]))(e,n==="committed"?t.next:t.before))throw new o("gc_recovery_required","Activation journal does not match the active pointer; original bytes preserved");let s=t.before;if(n==="committed"&&s&&s.stateRef!==e.stateRef&&await b(d(this.root,"previous.json"),s),n==="committed"){let a=await I(d(this.root,"fork.json"));a?.version===1&&a.stateRef===e.stateRef&&Object.keys(a).every(c=>["version","stateRef"].includes(c))&&await x(d(this.root,"fork.json"))}return await x(d(this.root,"transition.json")),{active:e,recovered:n}})}async activate(e,t){return R(this.root,async()=>{let n=await this.active();if((n?.generation??0)!==e)throw new o("stale_generation","Plugin activation changed concurrently");let i=await I(d(this.root,"fork.json"));if(i&&(i.version!==1||i.stateRef!==t.stateRef||Object.keys(i).some(a=>!["version","stateRef"].includes(a))))throw new o("gc_recovery_required","Activation refused: unresolved fork.json belongs to another target; stop all owners and inspect it");let s=T({...t,generation:e+1,operationId:G()});await S(d(this.root,"states")),await S(d(this.root,"states",s.stateRef)),await b(d(this.root,"transition.json"),{version:1,before:n,next:s}),await this.checkpoint?.("prepared");try{await b(d(this.root,"active.json"),s)}catch(a){if((await this.active())?.operationId!==s.operationId)throw a}await this.checkpoint?.("committed");try{n&&n.stateRef!==s.stateRef&&await b(d(this.root,"previous.json"),n),await x(d(this.root,"transition.json")),await x(d(this.root,"fork.json")).catch(()=>{})}catch{}return await this.checkpoint?.("cleaned"),s})}async forkState(e){return R(this.root,async()=>{let t=await this.assertGeneration(e,!1),n=G(),i=d(this.root,"states",n);if(await I(d(this.root,"fork.json")))throw new o("gc_recovery_required","Unresolved fork.json; stop all owners and inspect the reserved state before retrying");await b(d(this.root,"fork.json"),{version:1,stateRef:n}),await S(i);let s=d(this.root,"states",t.stateRef);for(let a of await W(s)){if(!/^[a-f0-9]{64}\.json$/.test(a))throw new o("invalid_storage","Unexpected state file");if(!await g(d(s,a),N))throw new o("invalid_storage","Missing state file");await _e(d(s,a),d(i,a))}return await this.checkpoint?.("forked"),n})}async collect(e){return R(this.root,async()=>{for(let l of["transition.json","fork.json"])if(await g(d(this.root,l),2*1024*1024))throw new o("gc_recovery_required",`GC refused: unresolved ${l}; stop all owners and inspect recovery references`);let t=await this.active(),n=T(await I(d(this.root,"previous.json")));if(!t&&await g(d(this.root,"active.json"),2*1024*1024))throw new o("gc_recovery_required","GC refused: null active pointer; restore activation metadata before cleanup");let i=[t,n].filter(l=>!!l),s=d(this.root,"states");await S(s);let a=await W(s),c=new Set(i.map(l=>l.stateRef));for(let l of a){if(!re(l))throw new o("gc_recovery_required","GC refused: unexpected state directory; inspect states before cleanup");let u=d(s,l),p=await F(u);if(!p.isDirectory()||p.isSymbolicLink())throw new o("gc_recovery_required","GC refused: linked/non-directory state snapshot");for(let m of await W(u)){let v=await F(d(u,m));if(!/^[a-f0-9]{64}\.json$/.test(m)||!v.isFile()||v.isSymbolicLink()||v.nlink!==1)throw new o("gc_recovery_required","GC refused: unexpected snapshot content; original bytes preserved");if(!c.has(l)){let h=await E(d(u,m),N);if(!h)throw new o("gc_recovery_required","GC refused: missing snapshot record");if(Object.hasOwn(h,"committed")){let w=h;if(Object.keys(w).some(_=>!["requestId","inputHash","nextHash","committed"].includes(_))||w.committed!==!0||!/^[a-f0-9]{64}$/.test(w.inputHash)||!/^[a-f0-9]{64}$/.test(w.nextHash)||typeof w.requestId!="string")throw new o("gc_recovery_required",`GC refused: unresolved file intent in states/${l}; reconcile the workspace save before cleanup`)}else{if(Object.keys(h).some(w=>!["revision","schema","value","requestId","inputHash"].includes(w)))throw new o("gc_recovery_required","GC refused: unknown snapshot envelope; original bytes preserved");this.validateState(h)}}}}for(let l of c)if(!a.includes(l))throw new o("gc_recovery_required","GC refused: referenced snapshot is missing; restore recovery data first");let f=await e(i);for(let l of a)c.has(l)||await xe(d(s,l),{recursive:!0,force:!0});return f})}async assertGeneration(e,t=!0){let n=await this.active();if(!n||n.generation!==e||t&&!n.enabled)throw new o("stale_generation","Plugin generation is no longer active");return n}scopeKey(e){if(!e.scope||typeof e.scope.cwd!="string"||!e.scope.cwd||typeof e.scope.sessionId!="string"||!e.scope.sessionId||typeof e.scope.workspaceId!="string"||!e.scope.workspaceId)throw new o("invalid_scope","Missing authenticated plugin scope");return JSON.stringify([e.scope.workspaceId,e.scope.cwd,e.scope.sessionId])}statePath(e,t,n){return d(this.root,"states",e.stateRef,`${y(this.scopeKey(t)+":state:"+n)}.json`)}async call(e,t,n){if(!Number.isSafeInteger(e.generation)||!/^[\w-]{1,160}$/.test(e.requestId))throw new o("invalid_lease","Invalid invocation lease");this.scopeKey(e);let i=Pe(n);return R(this.root,async()=>{let s=await this.assertGeneration(e.generation);switch(t){case"state.read":{let a=await E(this.statePath(s,e,ne(i.key)),N);return a?(this.validateState(a),{revision:a.revision,schema:a.schema,value:a.value}):null}case"state.compareAndSwap":{let a=this.statePath(s,e,ne(i.key));if(!Number.isSafeInteger(i.expectedRevision)||i.expectedRevision<0||i.schema!==s.schema||!Object.hasOwn(i,"value"))throw new o("invalid_input","Invalid state revision or schema");if(JSON.stringify(i.value)===void 0)throw new o("invalid_input","State value must be JSON serializable");let c=JSON.stringify(i);if(Buffer.byteLength(c)>N)throw new o("state_too_large","Plugin state exceeds limit");let f=await E(a,N);f&&this.validateState(f);let l=y(c);if(f?.requestId===e.requestId&&f.inputHash===l)return{revision:f.revision,schema:f.schema,value:f.value};if((f?.revision??0)!==i.expectedRevision)throw new o("revision_conflict","Plugin state changed concurrently");let u={revision:i.expectedRevision+1,schema:s.schema,value:i.value,requestId:e.requestId,inputHash:l};return await b(a,u),{revision:u.revision,schema:u.schema,value:u.value}}case"workspace.read":{let{target:a}=await this.fileTarget(e.scope.cwd,i.path),c=i.maxBytes===void 0?H:i.maxBytes;if(!Number.isSafeInteger(c)||c<=0||c>H)throw new o("invalid_input","Invalid workspace read limit");let f=await g(a,c);return f?{text:new TextDecoder("utf-8",{fatal:!0}).decode(f),hash:y(f)}:null}case"workspace.commit":return this.commitFile(s,e,i);case"legacy.read":return this.legacy?this.legacy(e):null;default:throw new o("method_denied","Unknown host broker method")}})}validateState(e){if(!Number.isSafeInteger(e.revision)||e.revision<1||!Number.isSafeInteger(e.schema)||e.schema<1||!Object.hasOwn(e,"value")||typeof e.requestId!="string"||!/^[a-f0-9]{64}$/.test(e.inputHash))throw new o("invalid_storage","Invalid plugin state; original bytes preserved")}async fileTarget(e,t,n=!1){if(typeof t!="string"||t.length>4096||!t.endsWith(".excalidraw")||t.includes("\\")||t.includes("\0")||ee(t)||Re.isAbsolute(t))throw new o("invalid_path","Use a workspace-relative .excalidraw path");let i=await Z(e),s=Ee(i,t),a=te(i,s);if(!a||a===".."||a.startsWith(`..${U}`)||ee(a))throw new o("invalid_path","Workspace path escapes root");let c=i,f=a.split(U);for(let u=0;u<f.length;u++){c=d(c,f[u]);let p;try{p=await F(c)}catch(m){if(!L(m))throw m;if(u<f.length-1){if(!n||te(i,c)!=="diagrams")throw new o("invalid_path","Workspace directory does not exist");try{await be(c,{mode:448})}catch(v){if(v.code!=="EEXIST")throw v}p=await F(c)}}if(p&&(p.isSymbolicLink()||(u<f.length-1?!p.isDirectory():!p.isFile()||p.nlink!==1)))throw new o("invalid_path","Workspace path contains a link or non-regular file")}let l=await Z(Se(s));if(l!==i&&!l.startsWith(i+U))throw new o("invalid_path","Workspace directory changed");return{target:s,parent:l}}async commitFile(e,t,n){if(typeof n.text!="string"||Buffer.byteLength(n.text)>H||!(n.expectedHash===null||typeof n.expectedHash=="string"&&/^[a-f0-9]{64}$/.test(n.expectedHash)))throw new o("invalid_input","Invalid file content or expected hash");let{target:i,parent:s}=await this.fileTarget(t.scope.cwd,n.path,!0),a=d(this.root,"states",e.stateRef,`${y(this.scopeKey(t)+":file:"+t.requestId+":"+String(n.path))}.json`),c=y(JSON.stringify(n)),f=y(n.text),l=await E(a);if(l&&(l.requestId!==t.requestId||l.inputHash!==c||l.nextHash!==f))throw new o("duplicate_request","Request ID was reused with different content");let u;try{u=await Q(`${i}.lock`,"wx",384)}catch(m){throw m.code==="EEXIST"?new o("file_busy","Workspace file is locked; original file preserved"):m}let p;try{await u.writeFile(JSON.stringify({pid:process.pid,requestId:t.requestId}));let m=await g(i,H),v=m?y(m):null;if(l&&v===f)return{hash:f};if(l?.committed||v!==n.expectedHash)throw new o("file_conflict","Workspace file already exists or changed externally");await b(a,{requestId:t.requestId,inputHash:c,nextHash:f,committed:!1}),p=d(s,`.plugin-${G()}.tmp`);let h=await Q(p,"wx",384);try{await h.writeFile(n.text),await h.sync()}finally{await h.close()}if((await this.fileTarget(t.scope.cwd,n.path)).parent!==s)throw new o("file_conflict","Workspace directory changed during save");let _=await g(i,H);if((_?y(_):null)!==n.expectedHash)throw new o("file_conflict","Workspace file changed during save");if(await this.assertGeneration(t.generation),n.expectedHash===null){try{await ke(p,i)}catch(B){throw B.code==="EEXIST"?new o("file_conflict","Workspace file was created concurrently"):B}await x(p),p=void 0}else await Ie(p,i),p=void 0;return await b(a,{requestId:t.requestId,inputHash:c,nextHash:f,committed:!0}),{hash:f}}finally{p&&await x(p).catch(()=>{}),await u.close(),await x(`${i}.lock`)}}};var z="ALL_HOSTS_AND_PLUGIN_WORKERS_STOPPED_AND_BACKUP_VERIFIED";async function $(r){let e=[];async function t(n,i=""){let s=await ie(n);if(!s.isDirectory()||s.isSymbolicLink())throw new o("invalid_storage","Recovery refuses linked/non-directory storage");for(let a of(await Oe(n)).sort()){let c=k(n,a),f=i+a,l=await ie(c);if(l.isSymbolicLink())throw new o("invalid_storage","Recovery refuses links");if(l.isDirectory())await t(c,f+"/");else{if(e.length>=1e4)throw new o("invalid_storage","Recovery inspection budget exceeded");let u=await g(c,192*1024*1024);if(!u)throw new o("invalid_storage","Recovery input disappeared");e.push({path:f,bytes:u.length,sha256:y(u)})}}}return await t(r),{fingerprint:y(JSON.stringify(e)),files:e,warning:"Offline only: externally stop/fence ALL hosts and plugin workers, back up storage and workspace files. Never infer stopped ownership from PID alone."}}async function se(r,e,t,n){let i=new D(r,e),s=await $(i.root);if(n!==z)throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");if(s.fingerprint!==t)throw new o("recovery_changed","Storage changed since inspection");return i.recover()}async function ae(r,e,t,n){let i=new D(r,e),s=i.root;if(n!==z)throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");let a=await $(s);if(a.fingerprint!==t)throw new o("recovery_changed","Storage changed since inspection");if(await g(k(s,"transition.json"),2*1024*1024))throw new o("gc_recovery_required","Reconcile transition.json using broker.recover before resolving a fork");let c=await I(k(s,"fork.json")),f=await i.active(),l=await I(k(s,"previous.json"));if(!c||c.version!==1||!/^[a-f0-9-]{36}$/.test(c.stateRef)||Object.keys(c).some(p=>!["version","stateRef"].includes(p))||!f||l&&typeof l.stateRef!="string"||[f?.stateRef,l?.stateRef].includes(c.stateRef))throw new o("gc_recovery_required","Fork is unknown or referenced by active/previous; original bytes preserved");let u=`recovered-${t}-fork.json`;if(a.files.some(p=>p.path===u))throw new o("recovery_changed","Recovery evidence already exists");return await oe(k(s,"fork.json"),k(s,u)),{recovered:"fork.json",stateRef:c.stateRef,fingerprint:t}}async function ce(r,e,t){if(t!==z||!/^[a-f0-9]{64}$/.test(e))throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");let n=await $(r);if(n.fingerprint!==e)throw new o("recovery_changed","Storage changed since inspection; nothing recovered, inspect again");let i=[];for(let s of n.files.filter(a=>["runtime.lock","transaction.lock"].includes(a.path))){let a=await g(k(r,s.path),2097152);a&&!M(a)&&i.push(s)}for(let s of i){let a=`recovered-${e}-${s.path}.json`;if(n.files.some(c=>c.path===a))throw new o("recovery_changed","Recovery evidence already exists")}for(let s of i)await oe(k(r,s.path),k(r,`recovered-${e}-${s.path}.json`));return await b(k(r,`recovery-${e}.json`),{version:1,fingerprint:e,locks:i,confirmation:t,recoveredAt:new Date().toISOString()}),{recovered:i.map(s=>s.path),fingerprint:e}}var[P,le,O,j,q,...Ae]=process.argv.slice(2),Ne=le&&!Ae.length&&(P==="inspect"&&!O&&!j&&!q||P==="recover-locks"&&O&&j&&!q||["recover-fork","reconcile-transition"].includes(P??"")&&O&&j&&q);if(!Ne)console.error(`Offline only. Usage: node --experimental-strip-types scripts/hosted-stopped-recovery.ts
|
|
1
|
+
(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new r.Error().stack;e&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[e]="88e9f089-75f2-4e73-bd5d-c496ea630f50",r._sentryDebugIdIdentifier="sentry-dbid-88e9f089-75f2-4e73-bd5d-c496ea630f50")}catch{}})();import{resolve as je}from"node:path";import{lstat as ie,readdir as Oe,rename as oe}from"node:fs/promises";import{join as k}from"node:path";import{createHash as de}from"node:crypto";var o=class extends Error{code;status;reason;constructor(e,t,n={}){super(t),this.name="HostedPluginError",this.code=e,this.status=n.status,this.reason=n.reason}};var L=r=>r.code==="ENOENT";var Ue={files:4096,total:128*1024*1024,js:16*1024*1024,css:4*1024*1024,font:8*1024*1024,other:2*1024*1024};var y=r=>de("sha256").update(r).digest("hex");import{constants as J}from"node:fs";import{DatabaseSync as ue}from"node:sqlite";import{lstat as V,mkdir as pe,open as A,rename as he,unlink as X}from"node:fs/promises";import{dirname as we,join as K,resolve as ge}from"node:path";import{randomUUID as me}from"node:crypto";import{setTimeout as ye}from"node:timers/promises";async function S(r){await pe(r,{recursive:!0,mode:448});let e=await V(r);if(!e.isDirectory()||e.isSymbolicLink())throw new o("invalid_storage","Plugin storage must be a real directory")}async function g(r,e){let t;try{t=await A(r,J.O_RDONLY|J.O_NONBLOCK|(J.O_NOFOLLOW??0))}catch(n){if(L(n))return null;throw n}try{let n=await t.stat();if(!n.isFile()||n.nlink>1||n.size>e)throw new o("invalid_storage","Invalid storage record size or type");let i=Buffer.alloc(Math.min(n.size+1,e+1)),s=0;for(;s<i.length;){let a=await t.read(i,s,i.length-s,s);if(!a.bytesRead)break;s+=a.bytesRead}if(s>e||s!==n.size)throw new o("invalid_storage","Storage record changed during read");return i.subarray(0,s)}finally{await t.close()}}async function E(r,e=2*1024*1024){let t=await g(r,e);if(!t)return null;try{return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t))}catch{throw new o("invalid_storage","Invalid JSON storage record; original bytes preserved")}}async function I(r){let e=await g(r,2097152);if(e===null)return null;let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e))}catch{throw new o("gc_recovery_required",`Invalid journal ${r}; stop all owners and inspect original bytes`)}if(!t||typeof t!="object"||Array.isArray(t))throw new o("gc_recovery_required",`Invalid journal ${r}; original bytes preserved`);return t}async function b(r,e){let t=`${r}.${me()}.tmp`,n=await A(t,"wx",384);try{try{await n.writeFile(JSON.stringify(e)),await n.sync()}finally{await n.close()}await he(t,r);let i;try{i=await A(we(r),"r"),await i.sync()}catch(s){if(!["EINVAL","EPERM","EACCES","EISDIR","ENOTSUP","EBADF"].includes(s.code??""))throw s}finally{await i?.close()}}finally{await X(t).catch(()=>{})}}var Y='{"version":2,"mechanism":"sqlite-exclusive"}',M=r=>r.toString("utf8")===Y,C=new Set;async function ve(r,e,t=0){await S(r);let n=K(r,`${e}.lock`),i=K(r,`${e}.ownership.sqlite`),s=e==="runtime"?"runtime_owned":"storage_busy",a=()=>new o(s,"Another host owns this plugin storage or a legacy ownership lock remains; stop all owners and verify a backup before offline recovery"),c;try{c=await A(i,"wx",384)}catch(h){if(h.code!=="EEXIST")throw h}finally{await c?.close()}let f=await V(i);if(!f.isFile()||f.isSymbolicLink()||f.nlink!==1||f.size>1024*1024)throw new o("invalid_storage","Ownership database must be a small, single-link regular file");let l=new ue(i,{allowExtension:!1}),u=ge(i),p=Date.now()+t,m=!1;try{for(;;){if(!C.has(u))try{l.exec("BEGIN EXCLUSIVE"),C.add(u),m=!0;break}catch(w){if(w.errcode!==5)throw w}if(Date.now()>=p)throw new o(s,"Another host owns this plugin storage; wait for it to stop before retrying");await ye(10)}let h=await g(n,4096);if(h===null){let w;try{w=await A(n,"wx",384),await w.writeFile(Y),await w.sync()}catch(_){if(_.code!=="EEXIST")throw _}finally{await w?.close()}h=await g(n,4096)}if(h===null||!M(h))throw a()}catch(h){throw l.close(),m&&C.delete(u),h}let v=!1;return async()=>{if(v)return;let h=await g(n,4096);if(h===null||!M(h))throw new o("invalid_storage","Ownership fence changed while held; preserve custody and inspect storage");await X(n),l.close(),C.delete(u),v=!0}}async function R(r,e,t=2e3){let n=await ve(r,"transaction",t);try{return await e()}finally{await n()}}import{lstat as F,mkdir as be,open as Q,realpath as Z,readdir as W,link as ke,rename as Ie,unlink as x,copyFile as _e,rm as xe}from"node:fs/promises";import{dirname as Se,isAbsolute as ee,join as d,relative as te,resolve as Ee,sep as U,win32 as Re}from"node:path";import{randomUUID as G}from"node:crypto";var N=192*1024*1024,H=512*1024,re=r=>typeof r=="string"&&/^[a-f0-9-]{36}$/.test(r);function Pe(r){if(!r||typeof r!="object"||Array.isArray(r))throw new o("invalid_input","Expected object input");return r}function ne(r){if(typeof r!="string"||!/^[\w.-]{1,160}$/.test(r)||r==="."||r==="..")throw new o("invalid_input","Invalid state key");return r}function T(r){if(r&&(!re(r.stateRef)||typeof r.version!="string"||!Number.isSafeInteger(r.generation)||r.generation<1||!Number.isSafeInteger(r.schema)||r.schema<1||typeof r.enabled!="boolean"||typeof r.operationId!="string"))throw new o("invalid_storage","Invalid active plugin record");return r}var D=class{root;pluginId;legacy;checkpoint;constructor(e,t,n,i){this.root=d(e,y(t)),this.pluginId=t,this.legacy=n,this.checkpoint=i}active(){return E(d(this.root,"active.json")).then(T)}async recover(){return R(this.root,async()=>{let e=await this.active(),t=await I(d(this.root,"transition.json"));if(!t)return{active:e,recovered:"none"};if(!t.next||!Object.hasOwn(t,"before")||Object.keys(t).some(a=>!["version","before","next"].includes(a))||Object.hasOwn(t,"version")&&t.version!==1)throw new o("invalid_storage","Invalid activation journal; stop all owners and inspect transition.json");T(t.next),T(t.before);let n=e?.operationId===t.next.operationId?"committed":"not_committed";if(!((a,c)=>a===null||c===null?a===c:["version","generation","stateRef","schema","enabled","operationId"].every(f=>a[f]===c[f]))(e,n==="committed"?t.next:t.before))throw new o("gc_recovery_required","Activation journal does not match the active pointer; original bytes preserved");let s=t.before;if(n==="committed"&&s&&s.stateRef!==e.stateRef&&await b(d(this.root,"previous.json"),s),n==="committed"){let a=await I(d(this.root,"fork.json"));a?.version===1&&a.stateRef===e.stateRef&&Object.keys(a).every(c=>["version","stateRef"].includes(c))&&await x(d(this.root,"fork.json"))}return await x(d(this.root,"transition.json")),{active:e,recovered:n}})}async activate(e,t){return R(this.root,async()=>{let n=await this.active();if((n?.generation??0)!==e)throw new o("stale_generation","Plugin activation changed concurrently");let i=await I(d(this.root,"fork.json"));if(i&&(i.version!==1||i.stateRef!==t.stateRef||Object.keys(i).some(a=>!["version","stateRef"].includes(a))))throw new o("gc_recovery_required","Activation refused: unresolved fork.json belongs to another target; stop all owners and inspect it");let s=T({...t,generation:e+1,operationId:G()});await S(d(this.root,"states")),await S(d(this.root,"states",s.stateRef)),await b(d(this.root,"transition.json"),{version:1,before:n,next:s}),await this.checkpoint?.("prepared");try{await b(d(this.root,"active.json"),s)}catch(a){if((await this.active())?.operationId!==s.operationId)throw a}await this.checkpoint?.("committed");try{n&&n.stateRef!==s.stateRef&&await b(d(this.root,"previous.json"),n),await x(d(this.root,"transition.json")),await x(d(this.root,"fork.json")).catch(()=>{})}catch{}return await this.checkpoint?.("cleaned"),s})}async forkState(e){return R(this.root,async()=>{let t=await this.assertGeneration(e,!1),n=G(),i=d(this.root,"states",n);if(await I(d(this.root,"fork.json")))throw new o("gc_recovery_required","Unresolved fork.json; stop all owners and inspect the reserved state before retrying");await b(d(this.root,"fork.json"),{version:1,stateRef:n}),await S(i);let s=d(this.root,"states",t.stateRef);for(let a of await W(s)){if(!/^[a-f0-9]{64}\.json$/.test(a))throw new o("invalid_storage","Unexpected state file");if(!await g(d(s,a),N))throw new o("invalid_storage","Missing state file");await _e(d(s,a),d(i,a))}return await this.checkpoint?.("forked"),n})}async collect(e){return R(this.root,async()=>{for(let l of["transition.json","fork.json"])if(await g(d(this.root,l),2*1024*1024))throw new o("gc_recovery_required",`GC refused: unresolved ${l}; stop all owners and inspect recovery references`);let t=await this.active(),n=T(await I(d(this.root,"previous.json")));if(!t&&await g(d(this.root,"active.json"),2*1024*1024))throw new o("gc_recovery_required","GC refused: null active pointer; restore activation metadata before cleanup");let i=[t,n].filter(l=>!!l),s=d(this.root,"states");await S(s);let a=await W(s),c=new Set(i.map(l=>l.stateRef));for(let l of a){if(!re(l))throw new o("gc_recovery_required","GC refused: unexpected state directory; inspect states before cleanup");let u=d(s,l),p=await F(u);if(!p.isDirectory()||p.isSymbolicLink())throw new o("gc_recovery_required","GC refused: linked/non-directory state snapshot");for(let m of await W(u)){let v=await F(d(u,m));if(!/^[a-f0-9]{64}\.json$/.test(m)||!v.isFile()||v.isSymbolicLink()||v.nlink!==1)throw new o("gc_recovery_required","GC refused: unexpected snapshot content; original bytes preserved");if(!c.has(l)){let h=await E(d(u,m),N);if(!h)throw new o("gc_recovery_required","GC refused: missing snapshot record");if(Object.hasOwn(h,"committed")){let w=h;if(Object.keys(w).some(_=>!["requestId","inputHash","nextHash","committed"].includes(_))||w.committed!==!0||!/^[a-f0-9]{64}$/.test(w.inputHash)||!/^[a-f0-9]{64}$/.test(w.nextHash)||typeof w.requestId!="string")throw new o("gc_recovery_required",`GC refused: unresolved file intent in states/${l}; reconcile the workspace save before cleanup`)}else{if(Object.keys(h).some(w=>!["revision","schema","value","requestId","inputHash"].includes(w)))throw new o("gc_recovery_required","GC refused: unknown snapshot envelope; original bytes preserved");this.validateState(h)}}}}for(let l of c)if(!a.includes(l))throw new o("gc_recovery_required","GC refused: referenced snapshot is missing; restore recovery data first");let f=await e(i);for(let l of a)c.has(l)||await xe(d(s,l),{recursive:!0,force:!0});return f})}async assertGeneration(e,t=!0){let n=await this.active();if(!n||n.generation!==e||t&&!n.enabled)throw new o("stale_generation","Plugin generation is no longer active");return n}scopeKey(e){if(!e.scope||typeof e.scope.cwd!="string"||!e.scope.cwd||typeof e.scope.sessionId!="string"||!e.scope.sessionId||typeof e.scope.workspaceId!="string"||!e.scope.workspaceId)throw new o("invalid_scope","Missing authenticated plugin scope");return JSON.stringify([e.scope.workspaceId,e.scope.cwd,e.scope.sessionId])}statePath(e,t,n){return d(this.root,"states",e.stateRef,`${y(this.scopeKey(t)+":state:"+n)}.json`)}async call(e,t,n){if(!Number.isSafeInteger(e.generation)||!/^[\w-]{1,160}$/.test(e.requestId))throw new o("invalid_lease","Invalid invocation lease");this.scopeKey(e);let i=Pe(n);return R(this.root,async()=>{let s=await this.assertGeneration(e.generation);switch(t){case"state.read":{let a=await E(this.statePath(s,e,ne(i.key)),N);return a?(this.validateState(a),{revision:a.revision,schema:a.schema,value:a.value}):null}case"state.compareAndSwap":{let a=this.statePath(s,e,ne(i.key));if(!Number.isSafeInteger(i.expectedRevision)||i.expectedRevision<0||i.schema!==s.schema||!Object.hasOwn(i,"value"))throw new o("invalid_input","Invalid state revision or schema");if(JSON.stringify(i.value)===void 0)throw new o("invalid_input","State value must be JSON serializable");let c=JSON.stringify(i);if(Buffer.byteLength(c)>N)throw new o("state_too_large","Plugin state exceeds limit");let f=await E(a,N);f&&this.validateState(f);let l=y(c);if(f?.requestId===e.requestId&&f.inputHash===l)return{revision:f.revision,schema:f.schema,value:f.value};if((f?.revision??0)!==i.expectedRevision)throw new o("revision_conflict","Plugin state changed concurrently");let u={revision:i.expectedRevision+1,schema:s.schema,value:i.value,requestId:e.requestId,inputHash:l};return await b(a,u),{revision:u.revision,schema:u.schema,value:u.value}}case"workspace.read":{let{target:a}=await this.fileTarget(e.scope.cwd,i.path),c=i.maxBytes===void 0?H:i.maxBytes;if(!Number.isSafeInteger(c)||c<=0||c>H)throw new o("invalid_input","Invalid workspace read limit");let f=await g(a,c);return f?{text:new TextDecoder("utf-8",{fatal:!0}).decode(f),hash:y(f)}:null}case"workspace.commit":return this.commitFile(s,e,i);case"legacy.read":return this.legacy?this.legacy(e):null;default:throw new o("method_denied","Unknown host broker method")}})}validateState(e){if(!Number.isSafeInteger(e.revision)||e.revision<1||!Number.isSafeInteger(e.schema)||e.schema<1||!Object.hasOwn(e,"value")||typeof e.requestId!="string"||!/^[a-f0-9]{64}$/.test(e.inputHash))throw new o("invalid_storage","Invalid plugin state; original bytes preserved")}async fileTarget(e,t,n=!1){if(typeof t!="string"||t.length>4096||!t.endsWith(".excalidraw")||t.includes("\\")||t.includes("\0")||ee(t)||Re.isAbsolute(t))throw new o("invalid_path","Use a workspace-relative .excalidraw path");let i=await Z(e),s=Ee(i,t),a=te(i,s);if(!a||a===".."||a.startsWith(`..${U}`)||ee(a))throw new o("invalid_path","Workspace path escapes root");let c=i,f=a.split(U);for(let u=0;u<f.length;u++){c=d(c,f[u]);let p;try{p=await F(c)}catch(m){if(!L(m))throw m;if(u<f.length-1){if(!n||te(i,c)!=="diagrams")throw new o("invalid_path","Workspace directory does not exist");try{await be(c,{mode:448})}catch(v){if(v.code!=="EEXIST")throw v}p=await F(c)}}if(p&&(p.isSymbolicLink()||(u<f.length-1?!p.isDirectory():!p.isFile()||p.nlink!==1)))throw new o("invalid_path","Workspace path contains a link or non-regular file")}let l=await Z(Se(s));if(l!==i&&!l.startsWith(i+U))throw new o("invalid_path","Workspace directory changed");return{target:s,parent:l}}async commitFile(e,t,n){if(typeof n.text!="string"||Buffer.byteLength(n.text)>H||!(n.expectedHash===null||typeof n.expectedHash=="string"&&/^[a-f0-9]{64}$/.test(n.expectedHash)))throw new o("invalid_input","Invalid file content or expected hash");let{target:i,parent:s}=await this.fileTarget(t.scope.cwd,n.path,!0),a=d(this.root,"states",e.stateRef,`${y(this.scopeKey(t)+":file:"+t.requestId+":"+String(n.path))}.json`),c=y(JSON.stringify(n)),f=y(n.text),l=await E(a);if(l&&(l.requestId!==t.requestId||l.inputHash!==c||l.nextHash!==f))throw new o("duplicate_request","Request ID was reused with different content");let u;try{u=await Q(`${i}.lock`,"wx",384)}catch(m){throw m.code==="EEXIST"?new o("file_busy","Workspace file is locked; original file preserved"):m}let p;try{await u.writeFile(JSON.stringify({pid:process.pid,requestId:t.requestId}));let m=await g(i,H),v=m?y(m):null;if(l&&v===f)return{hash:f};if(l?.committed||v!==n.expectedHash)throw new o("file_conflict","Workspace file already exists or changed externally");await b(a,{requestId:t.requestId,inputHash:c,nextHash:f,committed:!1}),p=d(s,`.plugin-${G()}.tmp`);let h=await Q(p,"wx",384);try{await h.writeFile(n.text),await h.sync()}finally{await h.close()}if((await this.fileTarget(t.scope.cwd,n.path)).parent!==s)throw new o("file_conflict","Workspace directory changed during save");let _=await g(i,H);if((_?y(_):null)!==n.expectedHash)throw new o("file_conflict","Workspace file changed during save");if(await this.assertGeneration(t.generation),n.expectedHash===null){try{await ke(p,i)}catch(B){throw B.code==="EEXIST"?new o("file_conflict","Workspace file was created concurrently"):B}await x(p),p=void 0}else await Ie(p,i),p=void 0;return await b(a,{requestId:t.requestId,inputHash:c,nextHash:f,committed:!0}),{hash:f}}finally{p&&await x(p).catch(()=>{}),await u.close(),await x(`${i}.lock`)}}};var z="ALL_HOSTS_AND_PLUGIN_WORKERS_STOPPED_AND_BACKUP_VERIFIED";async function $(r){let e=[];async function t(n,i=""){let s=await ie(n);if(!s.isDirectory()||s.isSymbolicLink())throw new o("invalid_storage","Recovery refuses linked/non-directory storage");for(let a of(await Oe(n)).sort()){let c=k(n,a),f=i+a,l=await ie(c);if(l.isSymbolicLink())throw new o("invalid_storage","Recovery refuses links");if(l.isDirectory())await t(c,f+"/");else{if(e.length>=1e4)throw new o("invalid_storage","Recovery inspection budget exceeded");let u=await g(c,192*1024*1024);if(!u)throw new o("invalid_storage","Recovery input disappeared");e.push({path:f,bytes:u.length,sha256:y(u)})}}}return await t(r),{fingerprint:y(JSON.stringify(e)),files:e,warning:"Offline only: externally stop/fence ALL hosts and plugin workers, back up storage and workspace files. Never infer stopped ownership from PID alone."}}async function se(r,e,t,n){let i=new D(r,e),s=await $(i.root);if(n!==z)throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");if(s.fingerprint!==t)throw new o("recovery_changed","Storage changed since inspection");return i.recover()}async function ae(r,e,t,n){let i=new D(r,e),s=i.root;if(n!==z)throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");let a=await $(s);if(a.fingerprint!==t)throw new o("recovery_changed","Storage changed since inspection");if(await g(k(s,"transition.json"),2*1024*1024))throw new o("gc_recovery_required","Reconcile transition.json using broker.recover before resolving a fork");let c=await I(k(s,"fork.json")),f=await i.active(),l=await I(k(s,"previous.json"));if(!c||c.version!==1||!/^[a-f0-9-]{36}$/.test(c.stateRef)||Object.keys(c).some(p=>!["version","stateRef"].includes(p))||!f||l&&typeof l.stateRef!="string"||[f?.stateRef,l?.stateRef].includes(c.stateRef))throw new o("gc_recovery_required","Fork is unknown or referenced by active/previous; original bytes preserved");let u=`recovered-${t}-fork.json`;if(a.files.some(p=>p.path===u))throw new o("recovery_changed","Recovery evidence already exists");return await oe(k(s,"fork.json"),k(s,u)),{recovered:"fork.json",stateRef:c.stateRef,fingerprint:t}}async function ce(r,e,t){if(t!==z||!/^[a-f0-9]{64}$/.test(e))throw new o("confirmation_required","Explicit stopped-owner and verified-backup confirmation required");let n=await $(r);if(n.fingerprint!==e)throw new o("recovery_changed","Storage changed since inspection; nothing recovered, inspect again");let i=[];for(let s of n.files.filter(a=>["runtime.lock","transaction.lock"].includes(a.path))){let a=await g(k(r,s.path),2097152);a&&!M(a)&&i.push(s)}for(let s of i){let a=`recovered-${e}-${s.path}.json`;if(n.files.some(c=>c.path===a))throw new o("recovery_changed","Recovery evidence already exists")}for(let s of i)await oe(k(r,s.path),k(r,`recovered-${e}-${s.path}.json`));return await b(k(r,`recovery-${e}.json`),{version:1,fingerprint:e,locks:i,confirmation:t,recoveredAt:new Date().toISOString()}),{recovered:i.map(s=>s.path),fingerprint:e}}var[P,le,O,j,q,...Ae]=process.argv.slice(2),Ne=le&&!Ae.length&&(P==="inspect"&&!O&&!j&&!q||P==="recover-locks"&&O&&j&&!q||["recover-fork","reconcile-transition"].includes(P??"")&&O&&j&&q);if(!Ne)console.error(`Offline only. Usage: node --experimental-strip-types scripts/hosted-stopped-recovery.ts
|
|
2
2
|
inspect BROKER_ROOT
|
|
3
3
|
recover-locks BROKER_ROOT FINGERPRINT CONFIRMATION
|
|
4
4
|
reconcile-transition DATA_ROOT PLUGIN_ID FINGERPRINT CONFIRMATION
|
|
5
5
|
recover-fork DATA_ROOT PLUGIN_ID FINGERPRINT CONFIRMATION
|
|
6
6
|
CONFIRMATION = ALL_HOSTS_AND_PLUGIN_WORKERS_STOPPED_AND_BACKUP_VERIFIED`),process.exitCode=2;else try{let r=je(le),e=P==="inspect"?await $(r):P==="recover-locks"?await ce(r,O,j):P==="recover-fork"?await ae(r,O,j,q):await se(r,O,j,q);console.log(JSON.stringify(e,null,2))}catch(r){console.error(r instanceof Error?r.message:"Recovery failed"),process.exitCode=1}var mt=void 0;export{mt as default};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=88e9f089-75f2-4e73-bd5d-c496ea630f50
|
package/dist/hosted-worker.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="
|
|
1
|
+
(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="513be217-6d55-414e-a860-8b287375f9a1",t._sentryDebugIdIdentifier="sentry-dbid-513be217-6d55-414e-a860-8b287375f9a1")}catch{}})();import{AsyncLocalStorage as y}from"node:async_hooks";import{pathToFileURL as b}from"node:url";function c(t){let e=t&&typeof t=="object"?t:{};return{code:typeof e.code=="string"&&/^[\w.-]{1,80}$/.test(e.code)?e.code:"plugin_failed",message:t instanceof Error?t.message:"Plugin operation failed",...Number.isInteger(e.status)&&Number(e.status)>=400&&Number(e.status)<=599?{status:Number(e.status)}:{},...typeof e.reason=="string"&&/^[\w.-]{1,80}$/.test(e.reason)?{reason:e.reason}:{}}}var l=new y,s=new Map,v=0,n,a=t=>{process.connected&&process.send?.(t)};process.on("message",t=>{if(!t||typeof t!="object")return;let e=t;if(e.type==="broker-response"&&typeof e.id=="string"){let r=s.get(e.id);if(!r)return;if(s.delete(e.id),e.ok)r.resolve(e.value);else{let o=e.error;r.reject(Object.assign(new Error(o?.message??"Host broker rejected request"),{code:o?.code,status:o?.status,reason:o?.reason}))}return}if(e.type!=="request"||typeof e.id!="string"||typeof e.method!="string")return;let i=e.id;(async()=>{switch(e.method){case"initialize":{if(n)throw new Error("Already initialized");let r=e.input,o=await import(b(r.entry).href);if(typeof o.createRuntime!="function")throw new Error("Missing createRuntime export");return n=await o.createRuntime({pluginId:r.pluginId,version:r.version,generation:r.generation,broker:{call(f,g){let u=l.getStore();if(!u)return Promise.reject(new Error("Broker calls require an active invocation"));if(s.size>=64)return Promise.reject(new Error("Too many broker requests"));let d=`b${++v}`;return new Promise((m,w)=>{s.set(d,{resolve:m,reject:w}),a({type:"broker-request",id:d,invocationId:u.requestId,method:f,input:g})})}}}),{initialized:!0}}case"describe":if(!n)throw new Error("Not initialized");return n.describe();case"health":if(!n)throw new Error("Not initialized");return n.health();case"invoke":{if(!n)throw new Error("Not initialized");let r=e.input;return l.run(r,()=>n.invoke(r))}case"dispose":return await n?.dispose?.(),{disposed:!0};default:throw new Error("Unknown runtime operation")}})().then(r=>a({type:"response",id:i,ok:!0,value:r}),r=>a({type:"response",id:i,ok:!1,error:c(r)}))});process.on("disconnect",()=>{for(let t of s.values())t.reject(new Error("Host disconnected"));s.clear(),process.exitCode=1,Promise.resolve(n?.dispose?.()).finally(()=>process.exit(1))});var H=void 0;export{H as default};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=513be217-6d55-414e-a860-8b287375f9a1
|
package/docs/desktop.md
CHANGED
|
@@ -215,7 +215,7 @@ keeps its existing name; this rename is for the native desktop application.
|
|
|
215
215
|
|
|
216
216
|
Download builds from **[GitHub Releases](https://github.com/chengzhiyi/pi-webapp/releases)**,
|
|
217
217
|
not the npm package, source ZIP or an expired Actions artifact. The current
|
|
218
|
-
[build
|
|
218
|
+
[build 14 release](https://github.com/chengzhiyi/pi-webapp/releases/tag/desktop-v0.1.39-b14) offers macOS arm64/Intel, Windows x64, and Linux x64 test installers. Build 12 fixes quit responsiveness, loading-window shutdown alerts and backend-stop recovery. It also supports persistent stable/preview business-package updates from Settings; older build 10 shells need this one-time installer upgrade.
|
|
219
219
|
Use each release's actual asset list and acceptance notes, not matrix configuration
|
|
220
220
|
alone, to determine support.
|
|
221
221
|
|
|
@@ -445,3 +445,40 @@ support. Custom icons are configured for all platforms; the icon replacement
|
|
|
445
445
|
has only been verified in a packaged macOS arm64 app.
|
|
446
446
|
Formal signing, automatic desktop updates, tray integration, completion
|
|
447
447
|
notifications and cross-platform end-to-end QA are not included in this delivery.
|
|
448
|
+
|
|
449
|
+
### Existing shared launchers and safe handoff (build 14)
|
|
450
|
+
|
|
451
|
+
Installing a newer shell preserves a running shared backend; it does not change
|
|
452
|
+
that launcher's environment. A build 10 launcher can therefore keep reporting
|
|
453
|
+
`PI_WEBAPP_DESKTOP_RELEASE_CHANNELS=0` after build 12 attaches. Package restarts
|
|
454
|
+
inherit that environment. Installing build 12 again cannot resolve this.
|
|
455
|
+
|
|
456
|
+
Build 14 adds **pi → 安全切换到当前桌面启动器…** and a Settings action.
|
|
457
|
+
First update the old backend's stable business package to a release advertising
|
|
458
|
+
handoff protocol 1. The new shell then authenticates the exact owner and requests
|
|
459
|
+
`POST /api/desktop/handoff`. The bridge refuses current/background chats,
|
|
460
|
+
terminals, authentication or update activity, closes new mutation admission,
|
|
461
|
+
and acquires the real hosted save/worker-drain lease. Only then may it write a
|
|
462
|
+
request-bound private handoff journal. A failed save restores admission and
|
|
463
|
+
preserves the original backend.
|
|
464
|
+
|
|
465
|
+
The supervisor closes Pi's RPC input after that drain and records completion
|
|
466
|
+
only after the child exits successfully. This path has **no force-stop timer**.
|
|
467
|
+
The new shell waits for the exact receipt and old supervisor PID to disappear;
|
|
468
|
+
a missing state file alone is insufficient. It validates the selected business
|
|
469
|
+
package before draining, preserves the exact URL/token (and therefore the local
|
|
470
|
+
storage origin), and launches that same package with its own Node/runtime and
|
|
471
|
+
channel capabilities. Replacement owners and mismatched receipts are never
|
|
472
|
+
claimed as successful handoffs. A private native intent preserves the original
|
|
473
|
+
address across interruption; recovery requires the same stopped receipt, a dead
|
|
474
|
+
old supervisor, and the exact selected package, followed by the same authenticated
|
|
475
|
+
successor capability checks. Completed/cancelled intents retain the known origin
|
|
476
|
+
on subsequent ordinary starts without reviving an old handoff. Unsupported predecessors are directed to stable
|
|
477
|
+
package bootstrap, rather than repeated installation of the already installed
|
|
478
|
+
shell. An unresolved exit/launch failure leaves diagnostic receipts for recovery;
|
|
479
|
+
it does not authorize killing an old owner or clearing its lock.
|
|
480
|
+
|
|
481
|
+
Settings separately identifies the current window (a display-only UA marker),
|
|
482
|
+
the backend launcher and its real capabilities, the shell at backend startup,
|
|
483
|
+
and the business package. The UA marker grants no capability. Native **About pi**
|
|
484
|
+
remains authoritative for the app location/version/build.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-webapp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"piWebappDesktopProtocol": 1,
|
|
6
6
|
"piWebappDataVersion": 1,
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"pi-webapp": "./bin/pi-webapp.mjs"
|
|
31
31
|
},
|
|
32
32
|
"pi": {
|
|
33
|
-
"image": "https://cdn.jsdelivr.net/npm/pi-webapp@0.1.
|
|
33
|
+
"image": "https://cdn.jsdelivr.net/npm/pi-webapp@0.1.47/assets/cover-webapp.png",
|
|
34
34
|
"extensions": [
|
|
35
35
|
"./dist/extension.js"
|
|
36
36
|
]
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"bin",
|
|
42
42
|
"desktop/managed-release.mjs",
|
|
43
43
|
"desktop/stop-outcome.mjs",
|
|
44
|
+
"desktop/launcher-handoff.mjs",
|
|
44
45
|
"desktop/release-version.mjs",
|
|
45
46
|
"desktop/check-pty.cjs",
|
|
46
47
|
"dist",
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
"desktop:prepare": "npm run build && node scripts/prepare-desktop.mjs",
|
|
70
71
|
"desktop:start": "electron desktop",
|
|
71
72
|
"desktop:smoke": "node scripts/smoke-desktop.mjs",
|
|
73
|
+
"desktop:smoke:handoff": "node scripts/smoke-desktop-handoff.mjs",
|
|
72
74
|
"desktop:smoke:legacy": "node scripts/smoke-desktop-legacy.mjs",
|
|
73
75
|
"desktop:package": "node scripts/package-desktop.mjs",
|
|
74
76
|
"build": "node scripts/build.mjs",
|
|
@@ -122,13 +122,13 @@
|
|
|
122
122
|
"isDynamicEntry": true
|
|
123
123
|
},
|
|
124
124
|
"../../node_modules/@shikijs/langs/dist/graphql.mjs": {
|
|
125
|
-
"file": "assets/graphql-
|
|
125
|
+
"file": "assets/graphql-BJ_4HOLm.js",
|
|
126
126
|
"name": "graphql",
|
|
127
127
|
"src": "../../node_modules/@shikijs/langs/dist/graphql.mjs",
|
|
128
128
|
"isDynamicEntry": true,
|
|
129
129
|
"imports": [
|
|
130
130
|
"_javascript-D_ijBMSX.js",
|
|
131
|
-
"_app-
|
|
131
|
+
"_app-DV6jw_lV.js",
|
|
132
132
|
"index.html"
|
|
133
133
|
]
|
|
134
134
|
},
|
|
@@ -161,12 +161,12 @@
|
|
|
161
161
|
]
|
|
162
162
|
},
|
|
163
163
|
"../../node_modules/@shikijs/langs/dist/http.mjs": {
|
|
164
|
-
"file": "assets/http-
|
|
164
|
+
"file": "assets/http-DXj-QPkN.js",
|
|
165
165
|
"name": "http",
|
|
166
166
|
"src": "../../node_modules/@shikijs/langs/dist/http.mjs",
|
|
167
167
|
"isDynamicEntry": true,
|
|
168
168
|
"imports": [
|
|
169
|
-
"_app-
|
|
169
|
+
"_app-DV6jw_lV.js",
|
|
170
170
|
"../../node_modules/@shikijs/langs/dist/xml.mjs",
|
|
171
171
|
"../../node_modules/@shikijs/langs/dist/graphql.mjs",
|
|
172
172
|
"index.html",
|
|
@@ -275,7 +275,7 @@
|
|
|
275
275
|
]
|
|
276
276
|
},
|
|
277
277
|
"../../node_modules/@shikijs/langs/dist/php.mjs": {
|
|
278
|
-
"file": "assets/php-
|
|
278
|
+
"file": "assets/php-CnqpwLKI.js",
|
|
279
279
|
"name": "php",
|
|
280
280
|
"src": "../../node_modules/@shikijs/langs/dist/php.mjs",
|
|
281
281
|
"isDynamicEntry": true,
|
|
@@ -284,7 +284,7 @@
|
|
|
284
284
|
"../../node_modules/@shikijs/langs/dist/xml.mjs",
|
|
285
285
|
"../../node_modules/@shikijs/langs/dist/sql.mjs",
|
|
286
286
|
"_javascript-D_ijBMSX.js",
|
|
287
|
-
"_app-
|
|
287
|
+
"_app-DV6jw_lV.js",
|
|
288
288
|
"../../node_modules/@shikijs/langs/dist/css.mjs",
|
|
289
289
|
"../../node_modules/@shikijs/langs/dist/java.mjs",
|
|
290
290
|
"index.html"
|
|
@@ -315,7 +315,7 @@
|
|
|
315
315
|
"isDynamicEntry": true
|
|
316
316
|
},
|
|
317
317
|
"../../node_modules/@shikijs/langs/dist/rst.mjs": {
|
|
318
|
-
"file": "assets/rst-
|
|
318
|
+
"file": "assets/rst-CWQJ5Yif.js",
|
|
319
319
|
"name": "rst",
|
|
320
320
|
"src": "../../node_modules/@shikijs/langs/dist/rst.mjs",
|
|
321
321
|
"isDynamicEntry": true,
|
|
@@ -324,7 +324,7 @@
|
|
|
324
324
|
"../../node_modules/@shikijs/langs/dist/cpp.mjs",
|
|
325
325
|
"../../node_modules/@shikijs/langs/dist/python.mjs",
|
|
326
326
|
"_javascript-D_ijBMSX.js",
|
|
327
|
-
"_app-
|
|
327
|
+
"_app-DV6jw_lV.js",
|
|
328
328
|
"../../node_modules/@shikijs/langs/dist/yaml.mjs",
|
|
329
329
|
"../../node_modules/@shikijs/langs/dist/cmake.mjs",
|
|
330
330
|
"../../node_modules/@shikijs/langs/dist/ruby.mjs",
|
|
@@ -340,7 +340,7 @@
|
|
|
340
340
|
]
|
|
341
341
|
},
|
|
342
342
|
"../../node_modules/@shikijs/langs/dist/ruby.mjs": {
|
|
343
|
-
"file": "assets/ruby-
|
|
343
|
+
"file": "assets/ruby-CWbKAyt-.js",
|
|
344
344
|
"name": "ruby",
|
|
345
345
|
"src": "../../node_modules/@shikijs/langs/dist/ruby.mjs",
|
|
346
346
|
"isDynamicEntry": true,
|
|
@@ -353,7 +353,7 @@
|
|
|
353
353
|
"../../node_modules/@shikijs/langs/dist/graphql.mjs",
|
|
354
354
|
"../../node_modules/@shikijs/langs/dist/cpp.mjs",
|
|
355
355
|
"../../node_modules/@shikijs/langs/dist/c.mjs",
|
|
356
|
-
"_app-
|
|
356
|
+
"_app-DV6jw_lV.js",
|
|
357
357
|
"../../node_modules/@shikijs/langs/dist/lua.mjs",
|
|
358
358
|
"../../node_modules/@shikijs/langs/dist/yaml.mjs",
|
|
359
359
|
"../../node_modules/@shikijs/langs/dist/java.mjs",
|
|
@@ -388,13 +388,13 @@
|
|
|
388
388
|
"isDynamicEntry": true
|
|
389
389
|
},
|
|
390
390
|
"../../node_modules/@shikijs/langs/dist/svelte.mjs": {
|
|
391
|
-
"file": "assets/svelte-
|
|
391
|
+
"file": "assets/svelte-047iPa3M.js",
|
|
392
392
|
"name": "svelte",
|
|
393
393
|
"src": "../../node_modules/@shikijs/langs/dist/svelte.mjs",
|
|
394
394
|
"isDynamicEntry": true,
|
|
395
395
|
"imports": [
|
|
396
396
|
"_javascript-D_ijBMSX.js",
|
|
397
|
-
"_app-
|
|
397
|
+
"_app-DV6jw_lV.js",
|
|
398
398
|
"../../node_modules/@shikijs/langs/dist/css.mjs",
|
|
399
399
|
"index.html"
|
|
400
400
|
]
|
|
@@ -430,14 +430,14 @@
|
|
|
430
430
|
"isDynamicEntry": true
|
|
431
431
|
},
|
|
432
432
|
"../../node_modules/@shikijs/langs/dist/vue.mjs": {
|
|
433
|
-
"file": "assets/vue-
|
|
433
|
+
"file": "assets/vue-CjffZrRU.js",
|
|
434
434
|
"name": "vue",
|
|
435
435
|
"src": "../../node_modules/@shikijs/langs/dist/vue.mjs",
|
|
436
436
|
"isDynamicEntry": true,
|
|
437
437
|
"imports": [
|
|
438
438
|
"../../node_modules/@shikijs/langs/dist/css.mjs",
|
|
439
439
|
"_javascript-D_ijBMSX.js",
|
|
440
|
-
"_app-
|
|
440
|
+
"_app-DV6jw_lV.js",
|
|
441
441
|
"../../node_modules/@shikijs/langs/dist/html.mjs",
|
|
442
442
|
"_html-derivative-C2Epw9Yg.js",
|
|
443
443
|
"index.html"
|
|
@@ -704,22 +704,22 @@
|
|
|
704
704
|
]
|
|
705
705
|
},
|
|
706
706
|
"../../src/plugins/builtin/files/client/plugin.tsx": {
|
|
707
|
-
"file": "assets/plugin-
|
|
707
|
+
"file": "assets/plugin-CR1bEvHB.js",
|
|
708
708
|
"name": "plugin",
|
|
709
709
|
"src": "../../src/plugins/builtin/files/client/plugin.tsx",
|
|
710
710
|
"isDynamicEntry": true,
|
|
711
711
|
"imports": [
|
|
712
|
-
"_app-
|
|
712
|
+
"_app-DV6jw_lV.js",
|
|
713
713
|
"index.html"
|
|
714
714
|
]
|
|
715
715
|
},
|
|
716
716
|
"../../src/plugins/builtin/git/client/plugin.tsx": {
|
|
717
|
-
"file": "assets/plugin-
|
|
717
|
+
"file": "assets/plugin-S5t8fcf3.js",
|
|
718
718
|
"name": "plugin",
|
|
719
719
|
"src": "../../src/plugins/builtin/git/client/plugin.tsx",
|
|
720
720
|
"isDynamicEntry": true,
|
|
721
721
|
"imports": [
|
|
722
|
-
"_app-
|
|
722
|
+
"_app-DV6jw_lV.js",
|
|
723
723
|
"index.html"
|
|
724
724
|
],
|
|
725
725
|
"css": [
|
|
@@ -727,20 +727,20 @@
|
|
|
727
727
|
]
|
|
728
728
|
},
|
|
729
729
|
"../../src/plugins/builtin/terminal/client/plugin.tsx": {
|
|
730
|
-
"file": "assets/plugin-
|
|
730
|
+
"file": "assets/plugin-BT2I2835.js",
|
|
731
731
|
"name": "plugin",
|
|
732
732
|
"src": "../../src/plugins/builtin/terminal/client/plugin.tsx",
|
|
733
733
|
"isDynamicEntry": true,
|
|
734
734
|
"imports": [
|
|
735
|
-
"_app-
|
|
735
|
+
"_app-DV6jw_lV.js",
|
|
736
736
|
"index.html"
|
|
737
737
|
],
|
|
738
738
|
"css": [
|
|
739
739
|
"assets/plugin.css"
|
|
740
740
|
]
|
|
741
741
|
},
|
|
742
|
-
"_app-
|
|
743
|
-
"file": "assets/app-
|
|
742
|
+
"_app-DV6jw_lV.js": {
|
|
743
|
+
"file": "assets/app-DV6jw_lV.js",
|
|
744
744
|
"name": "app",
|
|
745
745
|
"isDynamicEntry": true,
|
|
746
746
|
"imports": [
|
|
@@ -895,7 +895,7 @@
|
|
|
895
895
|
"isEntry": true,
|
|
896
896
|
"dynamicImports": [
|
|
897
897
|
"../../src/host/client/telemetry-client.ts",
|
|
898
|
-
"_app-
|
|
898
|
+
"_app-DV6jw_lV.js"
|
|
899
899
|
]
|
|
900
900
|
}
|
|
901
901
|
}
|