@cortexkit/opencode-openai-auth 1.8.4 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/{codex-request-C78nXs79.d.ts → codex-request-By530v1D.d.ts} +2 -1
  3. package/dist/{index-k7zb6wa7.js → index-25p8t63g.js} +1 -1
  4. package/dist/{index-hvmj07f7.js → index-a8wbqm6a.js} +20 -20
  5. package/dist/{index-pg5c6by3.js → index-jh90fx7y.js} +1 -1
  6. package/dist/index-n12zjwh9.js +8 -0
  7. package/dist/{index-e7gekawr.js → index-pnvp8hvs.js} +1 -1
  8. package/dist/{index-t8248wa4.js → index-v6jcz0hz.js} +21 -21
  9. package/dist/{index-nsdjapq1.js → index-zah8t2d2.js} +1 -1
  10. package/dist/{index-1htk005d.js → index-zf649dj2.js} +1 -1
  11. package/dist/index-zne9tzy9.js +91 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/rpc/port-file.js +1 -1
  15. package/dist/rpc/protocol.js +1 -1
  16. package/dist/rpc/rpc-client.js +1 -1
  17. package/dist/sidebar-state.js +1 -1
  18. package/dist/tui-preferences.js +1 -1
  19. package/dist/tui.d.ts +1 -20
  20. package/dist/v2/server.d.ts +1 -1
  21. package/dist/v2/server.js +2 -2
  22. package/package.json +2 -2
  23. package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +20 -6
  24. package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +25 -0
  25. package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +1 -1
  26. package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +55 -5
  27. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +1 -1
  28. package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +497 -0
  29. package/src/tui-compiled/raw/shared/7c97ac0cec074ae7-format.js +208 -0
  30. package/src/tui-compiled/raw/shared/b4ad0d49429f0096-map.js +98 -0
  31. package/src/tui-compiled/raw/shared/b717cdcce3966455-projection.js +90 -0
  32. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  33. package/src/tui-compiled/raw/tui.tsx +233 -634
  34. package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +20 -6
  35. package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +25 -0
  36. package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +1 -1
  37. package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +55 -5
  38. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +1 -1
  39. package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +550 -0
  40. package/src/tui-compiled/runtime/shared/7c97ac0cec074ae7-format.js +208 -0
  41. package/src/tui-compiled/runtime/shared/b4ad0d49429f0096-map.js +98 -0
  42. package/src/tui-compiled/runtime/shared/b717cdcce3966455-projection.js +90 -0
  43. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +3 -1
  44. package/src/tui-compiled/runtime/tui.js +258 -879
  45. package/dist/index-a5h82jha.js +0 -8
  46. package/dist/index-kemp2vh4.js +0 -91
  47. /package/dist/{index-hnmbhgk4.js → index-95s2mw9w.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{jf as O,kf as U,nf as b,of as m,pf as L,tf as y}from"./index-hnmbhgk4.js";import{createHash as Zz,randomUUID as v}from"node:crypto";import{chmod as t,mkdir as r,open as e,readdir as j,rename as zz,rmdir as Gz,stat as Jz,unlink as S}from"node:fs/promises";import{join as R,resolve as D}from"node:path";function l(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function F(z){if(!l(z))return!1;try{return process.kill(z,0),!0}catch(J){return J.code==="EPERM"}}function Cz(z){return(J)=>Kz(J,z)}function Kz(z,J){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(J)&&/^[0-9a-f]{16}$/.test(z.slice(J.length))}function Nz(z){let J=/^port-(\d+)\.json$/.exec(z);return J?Number(J[1]):void 0}function p(z,J){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:V,port:Q,token:K}=z;return l(V)&&Nz(J)===V&&typeof Q==="number"&&Number.isInteger(Q)&&Q>=1&&Q<=65535&&typeof K==="string"&&K.length>0}async function h(z,J){J?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await S(z).catch(()=>{})}async function Az(z,J,V={}){let Q=async()=>{let K=R(z,`port-${J.pid}.json`);if(O)return await m(z,V.secureDir??!1),await V.beforeWrite?.(),await y(K,JSON.stringify({...J,startedAt:Date.now()}),{stagePath:`${K}.${(V.stageName??v)()}.tmp`}),K;if(await r(z,{recursive:!0,mode:V.secureDir?448:void 0}),V.secureDir)await t(z,448);await V.beforeWrite?.();let W={...J,startedAt:Date.now()},Y=`${K}.${(V.stageName??v)()}.tmp`,N,G=!1;try{N=await e(Y,"wx",384),G=!0,await N.writeFile(JSON.stringify(W),"utf8"),await N.chmod(384),await N.close(),N=void 0,await zz(Y,K),G=!1}finally{if(await N?.close().catch(()=>{}),G)await S(Y).catch(()=>{})}return K};try{return await Q()}catch(K){if(K.code==="ENOENT")return await Q();throw K}}async function Oz(z,J,V,Q){let K;try{K=await j(z,{withFileTypes:!0})}catch(Y){if(Y.code==="ENOENT")return;throw Y}let W=D(J);for(let Y of K){if(!Y.isDirectory()||!V(Y.name))continue;let N=R(z,Y.name),G;try{G=await j(N)}catch(X){if(X.code==="ENOENT")continue;throw X}for(let X of G){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;let $=R(N,X),Z;try{Z=await L($)}catch(H){if(H instanceof U&&H.code!=="ENOENT")throw H;continue}if(Z===void 0)continue;let q;try{q=JSON.parse(Z)}catch{await h($,Q);continue}if(!p(q,X)){await h($,Q);continue}if(!F(q.pid))await S($).catch(()=>{})}if(D(N)!==W)await Gz(N).catch(()=>{})}}async function c(z,J){if(!F(J.pid))return null;let V=R(D(z),`port-${J.pid}.json`);try{if(O)await b(V,"file");let Q=await Jz(V);return`${V}:${Q.dev}:${Q.ino}:${Q.mtimeMs}:${Q.size}`}catch(Q){if(Q instanceof U&&Q.code!=="ENOENT")throw Q;return null}}async function a(z,J,V={}){let Q;try{if(O)await b(z,"directory");Q=await j(z)}catch(G){if(G instanceof U&&G.code!=="ENOENT")throw G;return null}let K=[];for(let G of Q){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;try{let X=JSON.parse(await L(R(z,G)));if(p(X,G))if(F(X.pid))K.push(X);else await S(R(z,G)).catch(()=>{})}catch(X){if(X instanceof U&&X.code!=="ENOENT")throw X}}if(K.length===0)return null;let W=J!==void 0&&J>=1?K.filter((G)=>G.pid===J):[];if(V.exactPid===!0&&W.length===0)return null;let Y=W.length>0?W:K,N=(G)=>typeof G.startedAt==="number"&&Number.isFinite(G.startedAt)?G.startedAt:-1/0;return Y.sort((G,X)=>N(X)-N(G))[0]??null}import{open as Qz}from"node:fs/promises";import{connect as Vz}from"node:net";import{join as Wz,resolve as o}from"node:path";var i=2000,A=new Map,T=new Map;async function Xz(z,J){let V=Wz(o(z),`port-${J.pid}.json`);if(O){let K=JSON.parse(await L(V));if(K.pid!==J.pid||K.port!==J.port||K.token!==J.token)return null;return null}let Q;try{Q=await Qz(V,"r");let K=await Q.stat(),W=JSON.parse(await Q.readFile("utf8"));if(W.pid!==J.pid||W.port!==J.port||W.token!==J.token)return null;return`${V}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch{return null}finally{await Q?.close().catch(()=>{})}}async function s(z,J,V,Q){let K=A.get(z);if(!O&&K&&await c(J,K.entry)===K.identity)return K;A.delete(z);let W=T.get(z);if(W)return W;let Y=(async()=>{let N=await(Q.discover??a)(J,V,Q);if(!N)return null;let G=await Xz(J,N);if(!G)return{entry:N,identity:""};let X={entry:N,identity:G};return A.set(z,X),X})();T.set(z,Y);try{return await Y}finally{if(T.get(z)===Y)T.delete(z)}}async function d(z,J,V,Q=i){return new Promise((K)=>{let W,Y=!1,N=!1,G=($,Z=!1)=>{if(Y)return;Y=!0,clearTimeout(X),W?.destroy(),K({value:$,stale:Z})},X=setTimeout(()=>G(null),Q);try{let $=JSON.stringify(V);W=Vz({host:"127.0.0.1",port:z.port}),W.on("connect",()=>{N=!0,W?.write(`POST /rpc/${J} HTTP/1.0\r
1
+ import{jf as O,kf as U,nf as b,of as m,pf as L,tf as y}from"./index-95s2mw9w.js";import{createHash as Zz,randomUUID as v}from"node:crypto";import{chmod as t,mkdir as r,open as e,readdir as j,rename as zz,rmdir as Gz,stat as Jz,unlink as S}from"node:fs/promises";import{join as R,resolve as D}from"node:path";function l(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function F(z){if(!l(z))return!1;try{return process.kill(z,0),!0}catch(J){return J.code==="EPERM"}}function Cz(z){return(J)=>Kz(J,z)}function Kz(z,J){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(J)&&/^[0-9a-f]{16}$/.test(z.slice(J.length))}function Nz(z){let J=/^port-(\d+)\.json$/.exec(z);return J?Number(J[1]):void 0}function p(z,J){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:V,port:Q,token:K}=z;return l(V)&&Nz(J)===V&&typeof Q==="number"&&Number.isInteger(Q)&&Q>=1&&Q<=65535&&typeof K==="string"&&K.length>0}async function h(z,J){J?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await S(z).catch(()=>{})}async function Az(z,J,V={}){let Q=async()=>{let K=R(z,`port-${J.pid}.json`);if(O)return await m(z,V.secureDir??!1),await V.beforeWrite?.(),await y(K,JSON.stringify({...J,startedAt:Date.now()}),{stagePath:`${K}.${(V.stageName??v)()}.tmp`}),K;if(await r(z,{recursive:!0,mode:V.secureDir?448:void 0}),V.secureDir)await t(z,448);await V.beforeWrite?.();let W={...J,startedAt:Date.now()},Y=`${K}.${(V.stageName??v)()}.tmp`,N,G=!1;try{N=await e(Y,"wx",384),G=!0,await N.writeFile(JSON.stringify(W),"utf8"),await N.chmod(384),await N.close(),N=void 0,await zz(Y,K),G=!1}finally{if(await N?.close().catch(()=>{}),G)await S(Y).catch(()=>{})}return K};try{return await Q()}catch(K){if(K.code==="ENOENT")return await Q();throw K}}async function Oz(z,J,V,Q){let K;try{K=await j(z,{withFileTypes:!0})}catch(Y){if(Y.code==="ENOENT")return;throw Y}let W=D(J);for(let Y of K){if(!Y.isDirectory()||!V(Y.name))continue;let N=R(z,Y.name),G;try{G=await j(N)}catch(X){if(X.code==="ENOENT")continue;throw X}for(let X of G){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;let $=R(N,X),Z;try{Z=await L($)}catch(H){if(H instanceof U&&H.code!=="ENOENT")throw H;continue}if(Z===void 0)continue;let q;try{q=JSON.parse(Z)}catch{await h($,Q);continue}if(!p(q,X)){await h($,Q);continue}if(!F(q.pid))await S($).catch(()=>{})}if(D(N)!==W)await Gz(N).catch(()=>{})}}async function c(z,J){if(!F(J.pid))return null;let V=R(D(z),`port-${J.pid}.json`);try{if(O)await b(V,"file");let Q=await Jz(V);return`${V}:${Q.dev}:${Q.ino}:${Q.mtimeMs}:${Q.size}`}catch(Q){if(Q instanceof U&&Q.code!=="ENOENT")throw Q;return null}}async function a(z,J,V={}){let Q;try{if(O)await b(z,"directory");Q=await j(z)}catch(G){if(G instanceof U&&G.code!=="ENOENT")throw G;return null}let K=[];for(let G of Q){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;try{let X=JSON.parse(await L(R(z,G)));if(p(X,G))if(F(X.pid))K.push(X);else await S(R(z,G)).catch(()=>{})}catch(X){if(X instanceof U&&X.code!=="ENOENT")throw X}}if(K.length===0)return null;let W=J!==void 0&&J>=1?K.filter((G)=>G.pid===J):[];if(V.exactPid===!0&&W.length===0)return null;let Y=W.length>0?W:K,N=(G)=>typeof G.startedAt==="number"&&Number.isFinite(G.startedAt)?G.startedAt:-1/0;return Y.sort((G,X)=>N(X)-N(G))[0]??null}import{open as Qz}from"node:fs/promises";import{connect as Vz}from"node:net";import{join as Wz,resolve as o}from"node:path";var i=2000,A=new Map,T=new Map;async function Xz(z,J){let V=Wz(o(z),`port-${J.pid}.json`);if(O){let K=JSON.parse(await L(V));if(K.pid!==J.pid||K.port!==J.port||K.token!==J.token)return null;return null}let Q;try{Q=await Qz(V,"r");let K=await Q.stat(),W=JSON.parse(await Q.readFile("utf8"));if(W.pid!==J.pid||W.port!==J.port||W.token!==J.token)return null;return`${V}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch{return null}finally{await Q?.close().catch(()=>{})}}async function s(z,J,V,Q){let K=A.get(z);if(!O&&K&&await c(J,K.entry)===K.identity)return K;A.delete(z);let W=T.get(z);if(W)return W;let Y=(async()=>{let N=await(Q.discover??a)(J,V,Q);if(!N)return null;let G=await Xz(J,N);if(!G)return{entry:N,identity:""};let X={entry:N,identity:G};return A.set(z,X),X})();T.set(z,Y);try{return await Y}finally{if(T.get(z)===Y)T.delete(z)}}async function d(z,J,V,Q=i){return new Promise((K)=>{let W,Y=!1,N=!1,G=($,Z=!1)=>{if(Y)return;Y=!0,clearTimeout(X),W?.destroy(),K({value:$,stale:Z})},X=setTimeout(()=>G(null),Q);try{let $=JSON.stringify(V);W=Vz({host:"127.0.0.1",port:z.port}),W.on("connect",()=>{N=!0,W?.write(`POST /rpc/${J} HTTP/1.0\r
2
2
  Host: 127.0.0.1:${z.port}\r
3
3
  Connection: close\r
4
4
  Content-Type: application/json\r
@@ -0,0 +1,8 @@
1
+ import{jf as H,kf as j,lf as F0,nf as q,of as w,pf as C,qf as h,rf as V0,tf as O}from"./index-95s2mw9w.js";import{randomUUID as M}from"node:crypto";import{lstat as v,mkdir as Y0,open as X0,readFile as Z0,rename as _0,rm as T,stat as L}from"node:fs/promises";import{dirname as P,join as x0}from"node:path";function Q0($,f){return`${$}.${f}.lock`}class W0 extends Error{details;constructor($){super(`Timed out acquiring ${$.name} lock for ${$.target}`);this.name="LockContentionError",this.details=$}}class I extends Error{details;constructor($){super(`Lost ${$.name} lock for ${$.target}`);this.name="LockOwnershipError",this.details=$}}async function y0($,f,B){let G=performance.now();for(;;){f.signal?.throwIfAborted();let Y=await H0({path:$,name:f.name,ttlMs:f.ttlMs,renew:f.renew??!1,...f.onStep?{onStep:f.onStep}:{},...f.onRenewalTimer?{onRenewalTimer:f.onRenewalTimer}:{}});if(Y)try{return f.signal?.throwIfAborted(),await B(Y)}finally{await Y.release(f.signal)}let Z=f.timeoutMs-(performance.now()-G);if(Z<=0)throw new W0({target:$,name:f.name,timeoutMs:f.timeoutMs});await new Promise((_)=>setTimeout(_,Math.min(25,Math.ceil(Z))))}}async function J0($,f){let B=await X0($,"wx",384),G;try{G=await B.stat()}catch{G=void 0}try{await B.writeFile(f,"utf8")}catch(Y){try{let Z=await v($).catch(()=>{return});if(G&&Z&&Z.dev===G.dev&&Z.ino===G.ino)await T($,{force:!0}).catch(()=>{})}catch{}throw Y}finally{await B.close()}}var C0=globalThis.setTimeout.bind(globalThis),R0=globalThis.clearTimeout.bind(globalThis);function S0($){let f=$?.code;return f==="ENOENT"||!H&&(f==="EINVAL"||f==="ENOTDIR")}var D0;function I0($,f){if($.dev!==f.dev||$.ino!==f.ino)return!1;if($.ino===0&&$.birthtimeMs!==f.birthtimeMs)return!1;return!0}var T0=1000;function H0($){return A0({...$,now:Date.now})}async function A0($){let f=Q0($.path,$.name),B=x0(f,"owner.json"),G=M(),Y=$.now??Date.now,Z=null,_=!1,U=!1,J,c,g0=new Promise((z)=>{c=z});function d(z){try{let K=$.onRenewalTimer?.(z);if(K&&(typeof K==="object"||typeof K==="function")&&"then"in K&&typeof K.then==="function")Promise.resolve(K).catch(()=>{})}catch{}}function a(){if(!Z)return;R0(Z),Z=null,d("cancelled")}function V(z,K){if(J||_)return;J=Object.freeze({reason:z,expectedOwnerId:G,...typeof K?.ownerId==="string"?{observedOwnerId:K.ownerId}:{},...typeof K?.expiresAt==="number"?{observedExpiresAt:K.expiresAt}:{}}),a(),c(J)}let E,A=null,x=`${f}.evicting`,X=x0(x,"owner.json"),i=M(),s=5000,n=8;async function F(){if(H)try{return JSON.parse(await C(f,!0))}catch(z){if(z.code!=="EISDIR"&&z.reason!=="wrong-kind")throw z;return await q(f,"directory",!0),JSON.parse(await C(B,!0))}try{return JSON.parse(await Z0(f,"utf8"))}catch(z){if(z.code!=="EISDIR")throw z;return JSON.parse(await Z0(B,"utf8"))}}async function j0(){if(H){let Q=await F(),W=Number(Q?.expiresAt)-Y();await O(f,`${JSON.stringify({ownerId:G,expiresAt:Y()+$.ttlMs})}
2
+ `,{deadline:performance.now()+Math.max(0,W),beforeRename:async()=>{let S=await F();if(S?.ownerId!==G||!(Number(S?.expiresAt)>Y())||!await D())throw new I({target:$.path,name:$.name})}});return}let z=`${f}.${M()}.tmp`,K,N=!1;try{K=await X0(z,"wx",384),N=!0,await K.writeFile(`${JSON.stringify({ownerId:G,expiresAt:Y()+$.ttlMs})}
3
+ `,"utf8"),await K.chmod(384),await K.close(),K=void 0;let Q=await F();if(Q?.ownerId!==G||!(Number(Q?.expiresAt)>Y())||!await D())throw new I({target:$.path,name:$.name});await _0(z,f),N=!1}finally{if(await K?.close().catch(()=>{}),N)await T(z,{force:!0}).catch(()=>{})}}async function t(){let z=`${JSON.stringify({ownerId:G,expiresAt:Y()+$.ttlMs})}
4
+ `;if(H)await h(f,z);else await J0(f,z)}async function o(z){let K=z.code;if(K!=="EEXIST"&&K!=="EISDIR")return!1;if(H){if($.onStep)await $.onStep("lease-contention-read-ready");try{if(K==="EISDIR")await q(f,"directory",!0),await C(B,!0);else await F()}catch(N){if(N.code!=="ENOENT")throw N}}return!0}async function y(){if(H)await w(P(f));try{return await t(),!0}catch(z){let K=z.code;if(await o(z))return!1;if(K==="ENOENT"){if(H)await w(P(f));else await Y0(P(f),{recursive:!0});try{return await t(),!0}catch(N){if(await o(N))return!1;throw N}}throw z}}async function m(){await new Promise((z)=>setTimeout(z,Math.floor(Math.random()*4)))}async function k(z=!0){if(z&&$.onStep)await $.onStep("lock-read-ready");let K;try{K=await F()}catch(Q){if(H&&Q.code!=="ENOENT")throw Q}let N=Number(K?.expiresAt);if(Number.isFinite(N)&&N>Y())return{status:"live"};if(typeof K?.ownerId==="string"&&Number.isFinite(N))return{status:"stale",identity:{kind:"owner",ownerId:K.ownerId,expiresAt:N}};try{let Q=await L(f),W=Number.isFinite(N)?N:Q.mtimeMs+$.ttlMs;if(W>Y())return{status:"live"};return{status:"stale",identity:{kind:"stat",dev:Q.dev,ino:Q.ino,mtimeMs:Q.mtimeMs,expiresAt:W}}}catch(Q){if(Q.code==="ENOENT"){if($.onStep)await $.onStep("lock-missing");return{status:"missing"}}throw Q}}function r(z,K){if(K.status!=="stale")return!1;let N=K.identity;if(z.kind==="owner"&&N.kind==="owner")return z.ownerId===N.ownerId&&z.expiresAt===N.expiresAt;return z.kind==="stat"&&N.kind==="stat"&&z.dev===N.dev&&z.ino===N.ino&&z.mtimeMs===N.mtimeMs&&z.expiresAt===N.expiresAt}async function D(){try{return JSON.parse(await C(X,H))?.ownerId===i}catch(z){if(H&&z.code!=="ENOENT")throw z;return!1}}async function R(z){if(H)await F0(z,"remove",()=>T(z,{recursive:!0,force:!0}));else await T(z,{recursive:!0,force:!0}).catch(()=>{})}async function u(){if(await D())await R(x)}async function q0(z){if(!z)return!1;let K;try{let N=await v(x);K={dev:N.dev,ino:N.ino,birthtimeMs:N.birthtimeMs}}catch{return!1}if(!I0(z,K))return!1;try{return await L(X),!0}catch(N){if(N.code!=="ENOENT")return!0}try{await R(x)}catch{}return!0}async function e(){if(H)await V0(x);else await Y0(x);let z;try{let K=await v(x);z={dev:K.dev,ino:K.ino,birthtimeMs:K.birthtimeMs}}catch{z=void 0}try{await D0?.beforeOwnerWrite?.(x,X);let K=await D0?.failOwnerWrite?.(x,X);if(K!==void 0)throw K;let N=`${JSON.stringify({ownerId:i,createdAt:Y()})}
5
+ `;if(H)await h(X,N);else await J0(X,N)}catch(K){let N=await q0(z);if(S0(K)&&!N)return!1;try{await u()}catch{}throw K}if($.onStep)await $.onStep("eviction-marker-acquired");return!0}async function $0(){let z;try{z=await L(x)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if(H)try{await q(x,"directory",!0)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if(z.mtimeMs+s>Y()){let N=!0;try{await L(X)}catch(Q){if(Q.code==="ENOENT")N=!1;else return"fresh"}if(N)return"fresh";if(z.mtimeMs+T0>Y())return"fresh"}if($.onStep)await $.onStep("stale-marker-stat");let K=`${x}.${M()}`;try{await _0(x,K)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if($.onStep)await $.onStep("stale-marker-claimed");return await R(K),"recovered"}async function z0(z){try{if(!await e())return!1}catch(K){if(K.code==="EEXIST"){if(H)try{await q(x,"directory",!0),await C(X,!0)}catch(N){if(N.code!=="ENOENT")throw N}return!1}throw K}try{await z()}finally{await u()}return!0}async function K0(){for(let z=0;z<n;z++){if($.onStep)await $.onStep("relinquish-read");let K;try{K=await F()}catch(N){if(H)throw N;return}if(K?.ownerId!==G)return;try{await T(f,{recursive:!0,force:!0});return}catch(N){if(H)throw N;await m()}}}function N0(){if(!$.renew||_||J)return;let z=$.renewIntervalMs??Math.max(1000,Math.floor($.ttlMs/3));if(Z=C0(()=>{Z=null;let K=(async()=>{let N=!_;try{if(!await z0(async()=>{let W=await F(),S=Y();if(_||J){N=!1;return}if(W?.ownerId!==G){V("taken-over",W),N=!1;return}if(!(Number(W?.expiresAt)>S)){V("expired",W),N=!1;return}if($.onStep)await $.onStep("renewal-owner-confirmed");if(_||J){N=!1;return}if(!await D())return;if($.onStep)await $.onStep("renewal-write-fenced");if(_||J){N=!1;return}if(!await D())return;if($.onStep)await $.onStep("renewal-write-ready");if(_||J){N=!1;return}if(await j0(),$.onStep)await $.onStep("renewal-write-finished");if(!await D()){V("marker-lost"),N=!1,await K0();return}})&&$.onStep)await $.onStep("renewal-marker-unavailable")}catch(Q){if(H&&Q instanceof j)E=Q,V("renewal-failed"),N=!1;try{let W=await F();if(W?.ownerId!==G)V("taken-over",W);else if(!(Number(W?.expiresAt)>Y()))V("expired",W)}catch{V("renewal-failed")}}finally{if($.onStep)try{await $.onStep("renewal-finished")}catch{}if(N&&!_&&!J)N0()}})();A=K,K.finally(()=>{if(A===K)A=null})},z),"unref"in Z)Z.unref();d("scheduled")}function f0(){try{let z=$.onContended?.();if(z&&(typeof z==="object"||typeof z==="function")&&"then"in z&&typeof z.then==="function")Promise.resolve(z).catch(()=>{})}catch{}return null}let g=await y();if(!g)for(let z=0;z<n;z++){if(g=await y(),g)break;let K=await k();if(K.status==="live")return f0();if(K.status==="missing")continue;if($.onStep)await $.onStep("stale-lock-observed");try{if(!await e()){await m();continue}}catch(N){if(N.code!=="EEXIST")throw N;if(await $0()==="fresh")return null;await m();continue}try{let N=await k();if(N.status==="live")return f0();if(!r(K.identity,N))continue;if(!await D())return null;if($.onStep)await $.onStep("stale-lock-confirmed");if(!await D())return null;let Q=await k(!1);if(!r(K.identity,Q))continue;if(await R(f),!await D())return null;if($.onStep)await $.onStep("stale-lock-removed");if(g=await y(),!g)return null;if($.onStep)await $.onStep("stale-lock-recreated");if(!await D())return await K0(),g=!1,null;break}finally{await u()}}if(!g)return null;return N0(),{ownerId:G,whenLost:()=>g0,hasLost:()=>J!==void 0,assertOwned:async()=>{if(E)throw E;let z;try{let K=await F();if(z=K,!_&&!J&&K?.ownerId===G&&Number(K?.expiresAt)>Y())return;V(K?.ownerId!==G?"taken-over":"expired",K)}catch(K){if(V("unreadable"),H&&K instanceof j)throw K}throw new I({target:$.path,name:$.name,expectedOwnerId:G,...typeof z?.ownerId==="string"?{observedOwnerId:z.ownerId}:{},...typeof z?.expiresAt==="number"?{observedExpiresAt:z.expiresAt}:{}})},release:async(z)=>{if(H&&U)return;_=!0,a(),await A;let K=performance.now()+s+1000,N=5;for(;;){try{let W=!1;if(await z0(async()=>{let B0;try{B0=await F()}catch(G0){if(H&&G0.code==="ENOENT"){W=!0;return}throw G0}if(B0?.ownerId!==G){W=!0;return}if($.onStep)await $.onStep("release-owner-confirmed");if(!await D())return;await R(f),W=!0})){if(H&&!W)throw new j(f,"release-not-confirmed",{code:"EIO"});U=W;return}if(z?.aborted)return;await $0()}catch(W){if(H)throw W;return}let Q=K-performance.now();if(Q<=0)break;await new Promise((W)=>setTimeout(W,Math.min(N,Q))),N=Math.min(N*2,50)}if(H)throw new j(f,"release-not-confirmed",{code:"ETIMEDOUT"})}}}import{randomUUID as U0}from"node:crypto";import{mkdir as M0,open as b,rename as L0,rm as O0}from"node:fs/promises";import{dirname as p}from"node:path";class l extends Error{constructor($){super("file or directory sync failed",{cause:$});this.name="AtomicSyncError"}}async function a0($,f,B={}){await b0($,f,B)}async function b0($,f,B,G){if(H)return O($,B.serialize?B.serialize(f):`${JSON.stringify(f,null,2)}
6
+ `,{beforeRename:B.beforeRename,stagePath:`${$}.${(B.stageName??U0)()}.tmp`,onRenamed:G,durable:B.durable,durability:B.durability,onOutcome:B.onOutcome});await M0(p($),{recursive:!0});let Y=`${$}.${(B.stageName??U0)()}.tmp`,Z,_=!1;try{if(Z=await b(Y,"wx",384),_=!0,await Z.writeFile(B.serialize?B.serialize(f):`${JSON.stringify(f,null,2)}
7
+ `,"utf8"),await Z.chmod(384),B.durable)try{await Z.sync()}catch(U){throw new l(U)}if(await Z.close(),Z=void 0,await B.beforeRename?.(),await L0(Y,$),_=!1,G?.(),B.durable){let U=await b(p($),"r");try{await U.sync()}catch(J){throw new l(J)}finally{await U.close()}}}finally{if(await Z?.close().catch(()=>{}),_)await O0(Y,{force:!0}).catch(()=>{})}}async function i0($){if(H){await q($,"file");let G=new j($,"directory-sync-unsupported",{code:"ENOTSUP"});throw G.published=!0,G}let f=await b($,"r");try{await f.sync()}finally{await f.close()}let B=await b(p($),"r");try{await B.sync()}finally{await B.close()}}var n0=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});
8
+ export{l as Ae,a0 as Be,b0 as Ce,i0 as De,H0 as Ee,Q0 as Fe,W0 as Ge,I as He,y0 as Ie,n0 as Je};
@@ -1,3 +1,3 @@
1
- import{Ab as V,yb as X}from"./index-hvmj07f7.js";import{randomUUID as Z}from"node:crypto";import{chmod as $,mkdir as G,readFile as H,rename as L,rm as T,stat as f,writeFile as g}from"node:fs/promises";import{dirname as k,resolve as w}from"node:path";var x="(no OpenCode 1 logins on this machine)";function C(b=process.env){return X(b)}async function Q(b){let z;try{z=await H(b,"utf8")}catch(q){if(q.code==="ENOENT")return;throw q}let j=JSON.parse(z);if(!j||typeof j!=="object"||Array.isArray(j))throw Error(`${b} does not hold a JSON object`);return j}function R(b){return b===void 0?void 0:JSON.stringify(b)}async function D(b){try{return(await f(b)).mode&511}catch(z){if(z.code==="ENOENT")return;throw z}}function _(b=C()){let z=new Map;return{path:w(b),async get(j){let q=(await Q(b))?.[j.path.id];return z.set(j.path.id,R(q)),q},async set(j){let q=j.path.id,W=await D(b),J=await Q(b)??{};if(!z.has(q)||z.get(q)!==R(J[q]))throw new V;J[q]=j.body,await G(k(b),{recursive:!0});let B=`${b}.${Z()}.tmp`;try{await g(B,`${JSON.stringify(J,null,2)}
1
+ import{Ab as V,yb as X}from"./index-a8wbqm6a.js";import{randomUUID as Z}from"node:crypto";import{chmod as $,mkdir as G,readFile as H,rename as L,rm as T,stat as f,writeFile as g}from"node:fs/promises";import{dirname as k,resolve as w}from"node:path";var x="(no OpenCode 1 logins on this machine)";function C(b=process.env){return X(b)}async function Q(b){let z;try{z=await H(b,"utf8")}catch(q){if(q.code==="ENOENT")return;throw q}let j=JSON.parse(z);if(!j||typeof j!=="object"||Array.isArray(j))throw Error(`${b} does not hold a JSON object`);return j}function R(b){return b===void 0?void 0:JSON.stringify(b)}async function D(b){try{return(await f(b)).mode&511}catch(z){if(z.code==="ENOENT")return;throw z}}function _(b=C()){let z=new Map;return{path:w(b),async get(j){let q=(await Q(b))?.[j.path.id];return z.set(j.path.id,R(q)),q},async set(j){let q=j.path.id,W=await D(b),J=await Q(b)??{};if(!z.has(q)||z.get(q)!==R(J[q]))throw new V;J[q]=j.body,await G(k(b),{recursive:!0});let B=`${b}.${Z()}.tmp`;try{await g(B,`${JSON.stringify(J,null,2)}
2
2
  `,{mode:W??384}),await $(B,W??384),await L(B,b)}catch(Y){throw await T(B,{force:!0}).catch(()=>{}),Y}return z.set(q,R(j.body)),!0},async all(){let j=await Q(b);if(!j||Object.keys(j).length===0)return{[x]:!0};return j}}}
3
3
  export{_ as c};