@maincode-ai/matilda-code 0.21.4 → 0.21.5

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 (97) hide show
  1. package/chunks/agent-3BUOSY5Q.js +3 -0
  2. package/chunks/agent-headless-NYPWOHZH.js +3 -0
  3. package/chunks/{anthropicContentGenerator-EFVV6ZTA.js → anthropicContentGenerator-EAQDRKHH.js} +1 -1
  4. package/chunks/{askUserQuestion-MFLZ7MGJ.js → askUserQuestion-7II3GVHO.js} +1 -1
  5. package/chunks/{chunk-FUNLOUYI.js → chunk-2HFKTFO5.js} +1 -1
  6. package/chunks/{chunk-LPWRRSAI.js → chunk-46QIOR55.js} +1 -1
  7. package/chunks/chunk-5QAKUC2D.js +14 -0
  8. package/chunks/chunk-743LSI67.js +32 -0
  9. package/chunks/{chunk-ENMM2K4Q.js → chunk-7LZNA4VT.js} +1 -1
  10. package/chunks/{chunk-3FI7EEYS.js → chunk-AMO6HY3T.js} +466 -465
  11. package/chunks/{chunk-5U3A6KMU.js → chunk-BGZJUBRA.js} +1 -1
  12. package/chunks/{chunk-SUORCDGS.js → chunk-BH56I7SB.js} +1 -1
  13. package/chunks/{chunk-C2ZWB2NT.js → chunk-FQ44TPC5.js} +1 -1
  14. package/chunks/{chunk-LQWORCPO.js → chunk-FW6Z25AA.js} +1 -1
  15. package/chunks/{chunk-QRCRXDZ5.js → chunk-JELJNWOF.js} +2 -2
  16. package/chunks/{chunk-2NN5YPDR.js → chunk-KAOSSAJ7.js} +1 -1
  17. package/chunks/{chunk-4R2OFVPK.js → chunk-L5ASITMV.js} +1 -1
  18. package/chunks/{chunk-MNGFXISD.js → chunk-LNTO3FNQ.js} +1 -1
  19. package/chunks/{chunk-QEI3OETI.js → chunk-MW3LAIJW.js} +1 -1
  20. package/chunks/{chunk-IMYUVCF7.js → chunk-N6BOYL6K.js} +1 -1
  21. package/chunks/{chunk-QLEJOI4X.js → chunk-O3OUYCSO.js} +1 -1
  22. package/chunks/{chunk-6QP5C76Y.js → chunk-OVC5Z3EX.js} +1 -1
  23. package/chunks/{chunk-NDR7ZFUA.js → chunk-OXHC3R2R.js} +1 -1
  24. package/chunks/{chunk-LCYHQMKE.js → chunk-QZWBA3NL.js} +2 -2
  25. package/chunks/{chunk-FT76AZPN.js → chunk-RQIV43CR.js} +1 -1
  26. package/chunks/{chunk-EMWHQSMS.js → chunk-SOKNPND5.js} +1 -1
  27. package/chunks/{chunk-IOCF4XSR.js → chunk-SWEYYDZO.js} +1 -1
  28. package/chunks/{chunk-QCIDUZV6.js → chunk-U3O6TMV7.js} +1 -1
  29. package/chunks/{chunk-R3H6IWFK.js → chunk-UHDKX2CR.js} +1 -1
  30. package/chunks/{chunk-UY2R3ZQ4.js → chunk-VB4MJSMC.js} +1 -1
  31. package/chunks/{chunk-XKDGRW3K.js → chunk-VBOVIARK.js} +1 -1
  32. package/chunks/{chunk-OMZ5SGMK.js → chunk-X4ML2NEE.js} +1 -1
  33. package/chunks/{chunk-S4K76QPI.js → chunk-XITA5WMN.js} +1 -1
  34. package/chunks/{chunk-MJEXA2MA.js → chunk-YTGWPLEA.js} +1 -1
  35. package/chunks/{computer-use-SPPVJT3E.js → computer-use-Y37T64HM.js} +1 -1
  36. package/chunks/contextCommand-2QR4G3UT.js +3 -0
  37. package/chunks/{cron-create-JHL5JGIM.js → cron-create-HASFXYQL.js} +1 -1
  38. package/chunks/{cron-delete-K2R3KI2W.js → cron-delete-AW4S5IYT.js} +1 -1
  39. package/chunks/{cron-list-R3YHZBHA.js → cron-list-U5U5GO6A.js} +1 -1
  40. package/chunks/{edit-SLOTIPQ6.js → edit-UNGTXCQO.js} +1 -1
  41. package/chunks/{enter-worktree-Y6PQ27LA.js → enter-worktree-3TAVEEPT.js} +1 -1
  42. package/chunks/{enterPlanMode-XXL4BNEQ.js → enterPlanMode-YXMV3Y43.js} +1 -1
  43. package/chunks/{exit-worktree-ZO3CQN6M.js → exit-worktree-NSBJWQOO.js} +1 -1
  44. package/chunks/{exitPlanMode-BNBCFLEU.js → exitPlanMode-QZBHXDLX.js} +1 -1
  45. package/chunks/{geminiContentGenerator-H3MOBIG3.js → geminiContentGenerator-MWV3AGI5.js} +1 -1
  46. package/chunks/glob-HEEVR5Z3.js +22 -0
  47. package/chunks/{grep-MFAMPUHG.js → grep-C6J3EAKZ.js} +1 -1
  48. package/chunks/{keychain-token-storage-EAJ6RT4S.js → keychain-token-storage-5MWTIAEL.js} +1 -1
  49. package/chunks/{ls-4QPI2E7A.js → ls-IBIDQ5NV.js} +1 -1
  50. package/chunks/{lsp-P3GKBOP3.js → lsp-ELR2BGT4.js} +1 -1
  51. package/chunks/matildaAgentContentGenerator-2E676SBT.js +8 -0
  52. package/chunks/matildaContentGenerator-PV6ESWMY.js +8 -0
  53. package/chunks/{matildaOAuth2-LKOMJUC6.js → matildaOAuth2-5EYRIK66.js} +1 -1
  54. package/chunks/monitor-G7537IPA.js +32 -0
  55. package/chunks/notebook-edit-HZSJ3P7O.js +17 -0
  56. package/chunks/{openaiContentGenerator-CCKR4OUB.js → openaiContentGenerator-4WFRCSV4.js} +1 -1
  57. package/chunks/read-file-4TZCSTH7.js +3 -0
  58. package/chunks/ripGrep-XIBOQFPB.js +3 -0
  59. package/chunks/scheduler-OMSSFPH3.js +8 -0
  60. package/chunks/{send-message-K3T7GVHO.js → send-message-GFPVOTSZ.js} +1 -1
  61. package/chunks/{serve-C7WLVE45.js → serve-YVF7UBR3.js} +31 -31
  62. package/chunks/shell-UPYPV7S3.js +3 -0
  63. package/chunks/{skill-D77VBROC.js → skill-6HSCMWQ4.js} +1 -1
  64. package/chunks/src-UQAE4MM3.js +3 -0
  65. package/chunks/{symbol-search-3A66G4MP.js → symbol-search-ZV6W6DPK.js} +1 -1
  66. package/chunks/{syntheticOutput-LLA4WQR7.js → syntheticOutput-XKGS6F2D.js} +1 -1
  67. package/chunks/task-create-T43QIG2F.js +3 -0
  68. package/chunks/{task-list-6I64SK7E.js → task-list-V27WHHHJ.js} +1 -1
  69. package/chunks/{task-stop-UKRXMCZV.js → task-stop-NON26GAN.js} +1 -1
  70. package/chunks/{task-update-XZWORLJB.js → task-update-DE7CUGPY.js} +1 -1
  71. package/chunks/{team-create-6SK4CNZ5.js → team-create-WNVHF2H6.js} +1 -1
  72. package/chunks/{team-delete-DEPXAMUE.js → team-delete-LIEVUGIX.js} +1 -1
  73. package/chunks/{todoWrite-DKJAYA4S.js → todoWrite-YIMKFWIL.js} +1 -1
  74. package/chunks/{tool-search-7D46IF5G.js → tool-search-HFOHXFK5.js} +1 -1
  75. package/chunks/{update-goal-EUJYH23K.js → update-goal-2ZJ53Q3T.js} +1 -1
  76. package/chunks/{web-fetch-UGTFUOQN.js → web-fetch-EVO7GDEB.js} +1 -1
  77. package/chunks/{web-search-FURCBRRK.js → web-search-SJMJGGPE.js} +1 -1
  78. package/chunks/{workflow-DG73Y76U.js → workflow-Q2MVABFH.js} +2 -2
  79. package/chunks/write-file-AT6NPYC3.js +15 -0
  80. package/cli.js +353 -353
  81. package/package.json +2 -2
  82. package/chunks/agent-U4F2PPZK.js +0 -3
  83. package/chunks/agent-headless-HVLXIG5E.js +0 -3
  84. package/chunks/chunk-QWBNNEV2.js +0 -14
  85. package/chunks/contextCommand-B6PO2N2B.js +0 -3
  86. package/chunks/glob-JHSJXAWH.js +0 -22
  87. package/chunks/matildaAgentContentGenerator-TUOJCDZF.js +0 -32
  88. package/chunks/matildaContentGenerator-K32UBTHC.js +0 -8
  89. package/chunks/monitor-LW5DPUYE.js +0 -32
  90. package/chunks/notebook-edit-XQHVR3VY.js +0 -17
  91. package/chunks/read-file-URGJTANM.js +0 -3
  92. package/chunks/ripGrep-WLBUDFPP.js +0 -3
  93. package/chunks/scheduler-KIVES2O5.js +0 -8
  94. package/chunks/shell-FC3JNLXK.js +0 -3
  95. package/chunks/src-JTFAM72X.js +0 -3
  96. package/chunks/task-create-ZZTSVXZN.js +0 -3
  97. package/chunks/write-file-NQP7YPXV.js +0 -15
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{Y as M,a as u}from"./chunk-QWBNNEV2.js";import{b as I}from"./chunk-GZPNIYVZ.js";I();import*as P from"node:crypto";import*as n from"node:fs";import*as f from"node:fs/promises";import*as O from"node:path";var C=M("ATOMIC_WRITE");async function L(t,o,e,i,w=f.rename){for(let a=0;a<=e;a++)try{await w(t,o);return}catch(c){if(!(u(c)&&(c.code==="EPERM"||c.code==="EACCES"))||a===e)throw c;await new Promise(v=>setTimeout(v,i*2**a))}}async function $(t){let e=t;for(let w=0;w<40;w++){let a;try{a=await f.lstat(e)}catch(l){if(u(l)&&l.code==="ENOENT")return e;throw l}if(!a.isSymbolicLink())return e;let c=await f.readlink(e);if(O.isAbsolute(c))e=c;else{let l=await f.realpath(O.dirname(e));e=O.resolve(l,c)}}let i=new Error(`ELOOP: too many levels of symbolic links, resolve '${t}'`);throw i.code="ELOOP",i}async function B(t,o,e,i){let w=e?.retries??3,a=e?.delayMs??50,c=e?.flush??!0,l=e?.encoding??"utf-8",v=i?.rename??f.rename,F=i?.writeFile??f.writeFile,x=i?.open??f.open,T=i?.chmod??f.chmod,A=i?.fchmod??((d,s)=>d.chmod(s)),b=i?.unlink??f.unlink,r=e?.noFollow?t:await $(t).catch(d=>{throw N(d,t)}),S;try{S=await f.stat(r)}catch(d){if(!u(d)||d.code!=="ENOENT")throw d}let W;(!e?.forceMode||e?.mode===void 0)&&(W=S!==void 0?S.mode&4095:void 0);let y=W??e?.mode,p={};typeof o=="string"&&(p.encoding=l),c&&(p.flush=!0),y!==void 0&&(p.mode=y);let k=async d=>{if(y!==void 0)try{await T(d,y)}catch(s){if(!u(s)||s.code!=="ENOSYS"&&s.code!=="ENOTSUP")throw s}},h=()=>{if(S===void 0||process.platform==="win32")return!1;let d=process.geteuid?.();return d===void 0?!1:S.uid!==d};if(S!==void 0&&S.isFile()&&h()){await f.writeFile(r,o,p),await k(r);return}let m=`${r}.${P.randomBytes(6).toString("hex")}.tmp`;try{await F(m,o,p),await k(m),await L(m,r,w,a,v)}catch(d){try{await b(m)}catch{}if(u(d)&&d.code==="EXDEV")try{if(e?.noFollow){try{await b(r)}catch(g){if(!u(g)||g.code!=="ENOENT")throw g}let s=await x(r,n.constants.O_WRONLY|n.constants.O_CREAT|n.constants.O_EXCL,y??438),E=!1;try{try{if(await s.writeFile(typeof o=="string"?Buffer.from(o,l):o),c&&await s.sync(),y!==void 0)try{await A(s,y)}catch(g){if(!u(g)||g.code!=="ENOSYS"&&g.code!=="ENOTSUP")throw g}E=!0}finally{await s.close()}}catch(g){if(!E)try{await b(r)}catch(R){C.debug(`orphan unlink failed for ${r}:`,R)}throw g}}else await F(r,o,p),await k(r);return}catch(s){throw N(s,r)}throw N(d,r)}}function N(t,o,e="atomicWriteFile"){return t instanceof Error&&!t.message.startsWith(`${e}(`)&&(t.message=`${e}(${JSON.stringify(o)}): ${t.message}`),t}async function X(t,o,e){await B(t,JSON.stringify(o,null,2),{encoding:"utf-8",...e})}function H(t){if(t<=0)return;let o=new SharedArrayBuffer(4),e=new Int32Array(o);Atomics.wait(e,0,0,t)}function Y(t,o,e,i,w=n.renameSync){for(let a=0;a<=e;a++)try{w(t,o);return}catch(c){if(!(u(c)&&(c.code==="EPERM"||c.code==="EACCES"))||a===e)throw c;H(i*2**a)}}function D(t){let e=t;for(let w=0;w<40;w++){let a;try{a=n.lstatSync(e)}catch(l){if(u(l)&&l.code==="ENOENT")return e;throw l}if(!a.isSymbolicLink())return e;let c=n.readlinkSync(e);if(O.isAbsolute(c))e=c;else{let l=n.realpathSync(O.dirname(e));e=O.resolve(l,c)}}let i=new Error(`ELOOP: too many levels of symbolic links, resolve '${t}'`);throw i.code="ELOOP",i}function V(t,o,e,i){let w=e?.retries??3,a=e?.delayMs??50,c=e?.flush??!0,l=e?.encoding??"utf-8",v=i?.rename??n.renameSync,F=i?.writeFile??n.writeFileSync,x=i?.open??n.openSync,T=i?.chmod??n.chmodSync,A=i?.fchmod??n.fchmodSync,b=i?.unlink??n.unlinkSync,r;if(e?.noFollow)r=t;else try{r=D(t)}catch(h){throw N(h,t,"atomicWriteFileSync")}let S=`${r}.${P.randomBytes(6).toString("hex")}.tmp`,W;if(!e?.forceMode||e?.mode===void 0)try{W=n.statSync(r).mode&4095}catch(h){if(!u(h)||h.code!=="ENOENT")throw h}let y=W??e?.mode,p={};typeof o=="string"&&(p.encoding=l),c&&(p.flush=!0),y!==void 0&&(p.mode=y);let k=h=>{if(y!==void 0)try{T(h,y)}catch(m){if(!u(m)||m.code!=="ENOSYS"&&m.code!=="ENOTSUP")throw m}};try{F(S,o,p),k(S),Y(S,r,w,a,v)}catch(h){try{b(S)}catch{}if(u(h)&&h.code==="EXDEV")try{if(e?.noFollow){try{b(r)}catch(s){if(!u(s)||s.code!=="ENOENT")throw s}let m=x(r,n.constants.O_WRONLY|n.constants.O_CREAT|n.constants.O_EXCL,y??438),d=!1;try{try{let s=typeof o=="string"?Buffer.from(o,l):o;if(n.writeFileSync(m,s),c&&n.fsyncSync(m),y!==void 0)try{A(m,y)}catch(E){if(!u(E)||E.code!=="ENOSYS"&&E.code!=="ENOTSUP")throw E}d=!0}finally{n.closeSync(m)}}catch(s){if(!d)try{b(r)}catch(E){C.debug(`orphan unlink failed for ${r}:`,E)}throw s}}else F(r,o,p),k(r);return}catch(m){throw N(m,r,"atomicWriteFileSync")}throw N(h,r,"atomicWriteFileSync")}}export{L as a,B as b,X as c,Y as d,V as e};
3
+ import{Z as M,a as u}from"./chunk-5QAKUC2D.js";import{b as I}from"./chunk-GZPNIYVZ.js";I();import*as P from"node:crypto";import*as n from"node:fs";import*as f from"node:fs/promises";import*as O from"node:path";var C=M("ATOMIC_WRITE");async function L(t,o,e,i,w=f.rename){for(let a=0;a<=e;a++)try{await w(t,o);return}catch(c){if(!(u(c)&&(c.code==="EPERM"||c.code==="EACCES"))||a===e)throw c;await new Promise(v=>setTimeout(v,i*2**a))}}async function $(t){let e=t;for(let w=0;w<40;w++){let a;try{a=await f.lstat(e)}catch(l){if(u(l)&&l.code==="ENOENT")return e;throw l}if(!a.isSymbolicLink())return e;let c=await f.readlink(e);if(O.isAbsolute(c))e=c;else{let l=await f.realpath(O.dirname(e));e=O.resolve(l,c)}}let i=new Error(`ELOOP: too many levels of symbolic links, resolve '${t}'`);throw i.code="ELOOP",i}async function B(t,o,e,i){let w=e?.retries??3,a=e?.delayMs??50,c=e?.flush??!0,l=e?.encoding??"utf-8",v=i?.rename??f.rename,F=i?.writeFile??f.writeFile,x=i?.open??f.open,T=i?.chmod??f.chmod,A=i?.fchmod??((d,s)=>d.chmod(s)),b=i?.unlink??f.unlink,r=e?.noFollow?t:await $(t).catch(d=>{throw N(d,t)}),S;try{S=await f.stat(r)}catch(d){if(!u(d)||d.code!=="ENOENT")throw d}let W;(!e?.forceMode||e?.mode===void 0)&&(W=S!==void 0?S.mode&4095:void 0);let y=W??e?.mode,p={};typeof o=="string"&&(p.encoding=l),c&&(p.flush=!0),y!==void 0&&(p.mode=y);let k=async d=>{if(y!==void 0)try{await T(d,y)}catch(s){if(!u(s)||s.code!=="ENOSYS"&&s.code!=="ENOTSUP")throw s}},h=()=>{if(S===void 0||process.platform==="win32")return!1;let d=process.geteuid?.();return d===void 0?!1:S.uid!==d};if(S!==void 0&&S.isFile()&&h()){await f.writeFile(r,o,p),await k(r);return}let m=`${r}.${P.randomBytes(6).toString("hex")}.tmp`;try{await F(m,o,p),await k(m),await L(m,r,w,a,v)}catch(d){try{await b(m)}catch{}if(u(d)&&d.code==="EXDEV")try{if(e?.noFollow){try{await b(r)}catch(g){if(!u(g)||g.code!=="ENOENT")throw g}let s=await x(r,n.constants.O_WRONLY|n.constants.O_CREAT|n.constants.O_EXCL,y??438),E=!1;try{try{if(await s.writeFile(typeof o=="string"?Buffer.from(o,l):o),c&&await s.sync(),y!==void 0)try{await A(s,y)}catch(g){if(!u(g)||g.code!=="ENOSYS"&&g.code!=="ENOTSUP")throw g}E=!0}finally{await s.close()}}catch(g){if(!E)try{await b(r)}catch(R){C.debug(`orphan unlink failed for ${r}:`,R)}throw g}}else await F(r,o,p),await k(r);return}catch(s){throw N(s,r)}throw N(d,r)}}function N(t,o,e="atomicWriteFile"){return t instanceof Error&&!t.message.startsWith(`${e}(`)&&(t.message=`${e}(${JSON.stringify(o)}): ${t.message}`),t}async function X(t,o,e){await B(t,JSON.stringify(o,null,2),{encoding:"utf-8",...e})}function H(t){if(t<=0)return;let o=new SharedArrayBuffer(4),e=new Int32Array(o);Atomics.wait(e,0,0,t)}function Y(t,o,e,i,w=n.renameSync){for(let a=0;a<=e;a++)try{w(t,o);return}catch(c){if(!(u(c)&&(c.code==="EPERM"||c.code==="EACCES"))||a===e)throw c;H(i*2**a)}}function D(t){let e=t;for(let w=0;w<40;w++){let a;try{a=n.lstatSync(e)}catch(l){if(u(l)&&l.code==="ENOENT")return e;throw l}if(!a.isSymbolicLink())return e;let c=n.readlinkSync(e);if(O.isAbsolute(c))e=c;else{let l=n.realpathSync(O.dirname(e));e=O.resolve(l,c)}}let i=new Error(`ELOOP: too many levels of symbolic links, resolve '${t}'`);throw i.code="ELOOP",i}function V(t,o,e,i){let w=e?.retries??3,a=e?.delayMs??50,c=e?.flush??!0,l=e?.encoding??"utf-8",v=i?.rename??n.renameSync,F=i?.writeFile??n.writeFileSync,x=i?.open??n.openSync,T=i?.chmod??n.chmodSync,A=i?.fchmod??n.fchmodSync,b=i?.unlink??n.unlinkSync,r;if(e?.noFollow)r=t;else try{r=D(t)}catch(h){throw N(h,t,"atomicWriteFileSync")}let S=`${r}.${P.randomBytes(6).toString("hex")}.tmp`,W;if(!e?.forceMode||e?.mode===void 0)try{W=n.statSync(r).mode&4095}catch(h){if(!u(h)||h.code!=="ENOENT")throw h}let y=W??e?.mode,p={};typeof o=="string"&&(p.encoding=l),c&&(p.flush=!0),y!==void 0&&(p.mode=y);let k=h=>{if(y!==void 0)try{T(h,y)}catch(m){if(!u(m)||m.code!=="ENOSYS"&&m.code!=="ENOTSUP")throw m}};try{F(S,o,p),k(S),Y(S,r,w,a,v)}catch(h){try{b(S)}catch{}if(u(h)&&h.code==="EXDEV")try{if(e?.noFollow){try{b(r)}catch(s){if(!u(s)||s.code!=="ENOENT")throw s}let m=x(r,n.constants.O_WRONLY|n.constants.O_CREAT|n.constants.O_EXCL,y??438),d=!1;try{try{let s=typeof o=="string"?Buffer.from(o,l):o;if(n.writeFileSync(m,s),c&&n.fsyncSync(m),y!==void 0)try{A(m,y)}catch(E){if(!u(E)||E.code!=="ENOSYS"&&E.code!=="ENOTSUP")throw E}d=!0}finally{n.closeSync(m)}}catch(s){if(!d)try{b(r)}catch(E){C.debug(`orphan unlink failed for ${r}:`,E)}throw s}}else F(r,o,p),k(r);return}catch(m){throw N(m,r,"atomicWriteFileSync")}throw N(h,r,"atomicWriteFileSync")}}export{L as a,B as b,X as c,Y as d,V as e};
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2025 Matilda Team
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{g as w,i as x}from"./chunk-S4K76QPI.js";import{Y as I}from"./chunk-QWBNNEV2.js";import{b as m}from"./chunk-GZPNIYVZ.js";m();m();var p=I("IMAGE_TOKENIZER"),E=class l{static PIXELS_PER_TOKEN=28*28;static MIN_TOKENS_PER_IMAGE=4;static MAX_TOKENS_PER_IMAGE=16384;static VISION_SPECIAL_TOKENS=2;async extractImageMetadata(t,e){try{if(!x(e))return p.warn(`Unsupported image format: ${e}`),{width:512,height:512,mimeType:e,dataSize:Math.floor(t.length*.75)};let n=t.replace(/^data:[^;]+;base64,/,""),r=Buffer.from(n,"base64"),i=await this.extractDimensions(r,e);return{width:i.width,height:i.height,mimeType:e,dataSize:r.length}}catch(n){return p.warn("Failed to extract image metadata:",n),{width:512,height:512,mimeType:e,dataSize:Math.floor(t.length*.75)}}}async extractDimensions(t,e){return e.includes("png")?this.extractPngDimensions(t):e.includes("jpeg")||e.includes("jpg")?this.extractJpegDimensions(t):e.includes("webp")?this.extractWebpDimensions(t):e.includes("gif")?this.extractGifDimensions(t):e.includes("bmp")?this.extractBmpDimensions(t):e.includes("tiff")?this.extractTiffDimensions(t):e.includes("heic")?this.extractHeicDimensions(t):{width:512,height:512}}extractPngDimensions(t){if(t.length<24)throw new Error("Invalid PNG: buffer too short");let e=t.subarray(0,8),n=Buffer.from([137,80,78,71,13,10,26,10]);if(!e.equals(n))throw new Error("Invalid PNG signature");let r=t.readUInt32BE(16),i=t.readUInt32BE(20);return{width:r,height:i}}extractJpegDimensions(t){if(t.length<4||t[0]!==255||t[1]!==216)throw new Error("Invalid JPEG signature");let e=2;for(;e<t.length-8;){if(t[e]!==255){e++;continue}let n=t[e+1];if(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207){let i=t.readUInt16BE(e+5);return{width:t.readUInt16BE(e+7),height:i}}let r=t.readUInt16BE(e+2);e+=2+r}throw new Error("Could not find JPEG dimensions")}extractWebpDimensions(t){if(t.length<30)throw new Error("Invalid WebP: too short");let e=t.subarray(0,4).toString("ascii"),n=t.subarray(8,12).toString("ascii");if(e!=="RIFF"||n!=="WEBP")throw new Error("Invalid WebP signature");let r=t.subarray(12,16).toString("ascii");if(r==="VP8 "){let i=t.readUInt16LE(26)&16383,a=t.readUInt16LE(28)&16383;return{width:i,height:a}}else if(r==="VP8L"){let i=t.readUInt32LE(21),a=(i&16383)+1,s=(i>>14&16383)+1;return{width:a,height:s}}else if(r==="VP8X"){let i=(t.readUInt32LE(24)&16777215)+1,a=(t.readUInt32LE(26)&16777215)+1;return{width:i,height:a}}throw new Error("Unsupported WebP format")}extractGifDimensions(t){if(t.length<10)throw new Error("Invalid GIF: too short");let e=t.subarray(0,6).toString("ascii");if(e!=="GIF87a"&&e!=="GIF89a")throw new Error("Invalid GIF signature");let n=t.readUInt16LE(6),r=t.readUInt16LE(8);return{width:n,height:r}}calculateTokens(t){return this.calculateTokensWithScaling(t.width,t.height)}calculateTokensWithScaling(t,e){let n=Math.round(e/28)*28,r=Math.round(t/28)*28,i=l.MIN_TOKENS_PER_IMAGE*l.PIXELS_PER_TOKEN,a=l.MAX_TOKENS_PER_IMAGE*l.PIXELS_PER_TOKEN;if(n*r>a){let o=Math.sqrt(e*t/a);n=Math.floor(e/o/28)*28,r=Math.floor(t/o/28)*28}else if(n*r<i){let o=Math.sqrt(i/(e*t));n=Math.ceil(e*o/28)*28,r=Math.ceil(t*o/28)*28}return Math.floor(n*r/l.PIXELS_PER_TOKEN)+l.VISION_SPECIAL_TOKENS}async calculateTokensBatch(t){let e=[];for(let{data:n,mimeType:r}of t)try{let i=await this.extractImageMetadata(n,r);e.push(this.calculateTokens(i))}catch(i){p.warn("Error calculating tokens for image:",i),e.push(l.MIN_TOKENS_PER_IMAGE+l.VISION_SPECIAL_TOKENS)}return e}extractBmpDimensions(t){if(t.length<26)throw new Error("Invalid BMP: buffer too short");if(t[0]!==66||t[1]!==77)throw new Error("Invalid BMP signature");let e=t.readUInt32LE(18),n=t.readUInt32LE(22);return{width:e,height:Math.abs(n)}}extractTiffDimensions(t){if(t.length<8)throw new Error("Invalid TIFF: buffer too short");let e=t.subarray(0,2).toString("ascii"),n=e==="II";if(!n&&!(e==="MM"))throw new Error("Invalid TIFF byte order");if((n?t.readUInt16LE(2):t.readUInt16BE(2))!==42)throw new Error("Invalid TIFF magic number");let a=n?t.readUInt32LE(4):t.readUInt32BE(4);if(a>=t.length)throw new Error("Invalid TIFF IFD offset");let s=n?t.readUInt16LE(a):t.readUInt16BE(a),o=0,h=0;for(let g=0;g<s;g++){let c=a+2+g*12;if(c+12>t.length)break;let u=n?t.readUInt16LE(c):t.readUInt16BE(c),f=(n?t.readUInt16LE(c+2):t.readUInt16BE(c+2))===3?n?t.readUInt16LE(c+8):t.readUInt16BE(c+8):n?t.readUInt32LE(c+8):t.readUInt32BE(c+8);if(u===256?o=f:u===257&&(h=f),o>0&&h>0)break}if(o===0||h===0)throw new Error("Could not find TIFF dimensions");return{width:o,height:h}}extractHeicDimensions(t){if(t.length<12)throw new Error("Invalid HEIC: buffer too short");if(t.subarray(4,8).toString("ascii")!=="ftyp")throw new Error("Invalid HEIC: missing ftyp box");let n=t.subarray(8,12).toString("ascii");if(!["heic","heix","hevc","hevx"].includes(n))throw new Error("Invalid HEIC brand");let r=0;for(;r<t.length-8;){let i=t.readUInt32BE(r);if(t.subarray(r+4,r+8).toString("ascii")==="meta"){let o=r+8+4;for(;o<r+i-8;){let h=t.readUInt32BE(o);if(t.subarray(o+4,o+8).toString("ascii")==="ispe"&&o+20<=t.length){let c=t.readUInt32BE(o+12),u=t.readUInt32BE(o+16);return{width:c,height:u}}if(h===0)break;o+=h}}if(i===0)break;r+=i}return p.warn("Could not extract HEIC dimensions, using default"),{width:512,height:512}}};var d=I("TOKENIZER"),T=class{textTokenizer;imageTokenizer;constructor(){this.textTokenizer=new w,this.imageTokenizer=new E}async calculateTokens(t){let e=performance.now();try{let{textContents:n,imageContents:r,audioContents:i,otherContents:a}=this.processAndGroupContents(t);if(n.length===0&&r.length===0&&i.length===0&&a.length===0)return{totalTokens:0,breakdown:{textTokens:0,imageTokens:0,audioTokens:0,otherTokens:0},processingTime:performance.now()-e};let s=await this.calculateTextTokens(n),o=await this.calculateImageTokens(r),h=await this.calculateAudioTokens(i),g=await this.calculateOtherTokens(a),c=s+o+h+g,u=performance.now()-e;return{totalTokens:c,breakdown:{textTokens:s,imageTokens:o,audioTokens:h,otherTokens:g},processingTime:u}}catch(n){d.error("Error calculating tokens:",n);let r=this.calculateFallbackTokens(t);return{totalTokens:r,breakdown:{textTokens:r,imageTokens:0,audioTokens:0,otherTokens:0},processingTime:performance.now()-e}}}async calculateTextTokens(t){if(t.length===0)return 0;try{return await this.textTokenizer.calculateTokens(t.join(""))}catch(e){d.warn("Error calculating text tokens:",e);let n=t.join("").length;return Math.ceil(n/4)}}async calculateImageTokens(t){if(t.length===0)return 0;try{return(await this.imageTokenizer.calculateTokensBatch(t)).reduce((n,r)=>n+r,0)}catch(e){return d.warn("Error calculating image tokens:",e),t.length*6}}async calculateAudioTokens(t){if(t.length===0)return 0;let e=0;for(let n of t)try{let r=Math.floor(n.data.length*.75);e+=Math.max(Math.ceil(r/100),10)}catch(r){d.warn("Error calculating audio tokens:",r),e+=10}return e}async calculateOtherTokens(t){if(t.length===0)return 0;try{return await this.textTokenizer.calculateTokens(t.join(""))}catch(e){d.warn("Error calculating other content tokens:",e);let n=t.join("").length;return Math.ceil(n/4)}}calculateFallbackTokens(t){try{let e=JSON.stringify(t.contents);return Math.ceil(e.length/4)}catch(e){return d.warn("Error in fallback token calculation:",e),100}}processAndGroupContents(t){let e=[],n=[],r=[],i=[];if(!t.contents)return{textContents:e,imageContents:n,audioContents:r,otherContents:i};let a=Array.isArray(t.contents)?t.contents:[t.contents];for(let s of a)this.processContent(s,e,n,r,i);return{textContents:e,imageContents:n,audioContents:r,otherContents:i}}processContent(t,e,n,r,i){if(typeof t=="string"){t.trim()&&e.push(t);return}if("parts"in t&&t.parts){for(let a of t.parts)this.processPart(a,e,n,r,i);return}this.processPart(t,e,n,r,i)}processPart(t,e,n,r,i){if(typeof t=="string"){t.trim()&&e.push(t);return}if("text"in t&&t.text){e.push(t.text);return}if("inlineData"in t&&t.inlineData){let{data:a,mimeType:s}=t.inlineData;if(s&&s.startsWith("image/")){n.push({data:a||"",mimeType:s});return}if(s&&s.startsWith("audio/")){r.push({data:a||"",mimeType:s});return}}if("fileData"in t&&t.fileData){i.push(JSON.stringify(t.fileData));return}if("functionCall"in t&&t.functionCall){i.push(JSON.stringify(t.functionCall));return}if("functionResponse"in t&&t.functionResponse){i.push(JSON.stringify(t.functionResponse));return}try{let a=JSON.stringify(t);a&&a!=="{}"&&i.push(a)}catch(a){d.warn("Failed to serialize unknown part type:",a)}}};m();export{T as a};
3
+ import{g as w,i as x}from"./chunk-XITA5WMN.js";import{Z as I}from"./chunk-5QAKUC2D.js";import{b as m}from"./chunk-GZPNIYVZ.js";m();m();var p=I("IMAGE_TOKENIZER"),E=class l{static PIXELS_PER_TOKEN=28*28;static MIN_TOKENS_PER_IMAGE=4;static MAX_TOKENS_PER_IMAGE=16384;static VISION_SPECIAL_TOKENS=2;async extractImageMetadata(t,e){try{if(!x(e))return p.warn(`Unsupported image format: ${e}`),{width:512,height:512,mimeType:e,dataSize:Math.floor(t.length*.75)};let n=t.replace(/^data:[^;]+;base64,/,""),r=Buffer.from(n,"base64"),i=await this.extractDimensions(r,e);return{width:i.width,height:i.height,mimeType:e,dataSize:r.length}}catch(n){return p.warn("Failed to extract image metadata:",n),{width:512,height:512,mimeType:e,dataSize:Math.floor(t.length*.75)}}}async extractDimensions(t,e){return e.includes("png")?this.extractPngDimensions(t):e.includes("jpeg")||e.includes("jpg")?this.extractJpegDimensions(t):e.includes("webp")?this.extractWebpDimensions(t):e.includes("gif")?this.extractGifDimensions(t):e.includes("bmp")?this.extractBmpDimensions(t):e.includes("tiff")?this.extractTiffDimensions(t):e.includes("heic")?this.extractHeicDimensions(t):{width:512,height:512}}extractPngDimensions(t){if(t.length<24)throw new Error("Invalid PNG: buffer too short");let e=t.subarray(0,8),n=Buffer.from([137,80,78,71,13,10,26,10]);if(!e.equals(n))throw new Error("Invalid PNG signature");let r=t.readUInt32BE(16),i=t.readUInt32BE(20);return{width:r,height:i}}extractJpegDimensions(t){if(t.length<4||t[0]!==255||t[1]!==216)throw new Error("Invalid JPEG signature");let e=2;for(;e<t.length-8;){if(t[e]!==255){e++;continue}let n=t[e+1];if(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207){let i=t.readUInt16BE(e+5);return{width:t.readUInt16BE(e+7),height:i}}let r=t.readUInt16BE(e+2);e+=2+r}throw new Error("Could not find JPEG dimensions")}extractWebpDimensions(t){if(t.length<30)throw new Error("Invalid WebP: too short");let e=t.subarray(0,4).toString("ascii"),n=t.subarray(8,12).toString("ascii");if(e!=="RIFF"||n!=="WEBP")throw new Error("Invalid WebP signature");let r=t.subarray(12,16).toString("ascii");if(r==="VP8 "){let i=t.readUInt16LE(26)&16383,a=t.readUInt16LE(28)&16383;return{width:i,height:a}}else if(r==="VP8L"){let i=t.readUInt32LE(21),a=(i&16383)+1,s=(i>>14&16383)+1;return{width:a,height:s}}else if(r==="VP8X"){let i=(t.readUInt32LE(24)&16777215)+1,a=(t.readUInt32LE(26)&16777215)+1;return{width:i,height:a}}throw new Error("Unsupported WebP format")}extractGifDimensions(t){if(t.length<10)throw new Error("Invalid GIF: too short");let e=t.subarray(0,6).toString("ascii");if(e!=="GIF87a"&&e!=="GIF89a")throw new Error("Invalid GIF signature");let n=t.readUInt16LE(6),r=t.readUInt16LE(8);return{width:n,height:r}}calculateTokens(t){return this.calculateTokensWithScaling(t.width,t.height)}calculateTokensWithScaling(t,e){let n=Math.round(e/28)*28,r=Math.round(t/28)*28,i=l.MIN_TOKENS_PER_IMAGE*l.PIXELS_PER_TOKEN,a=l.MAX_TOKENS_PER_IMAGE*l.PIXELS_PER_TOKEN;if(n*r>a){let o=Math.sqrt(e*t/a);n=Math.floor(e/o/28)*28,r=Math.floor(t/o/28)*28}else if(n*r<i){let o=Math.sqrt(i/(e*t));n=Math.ceil(e*o/28)*28,r=Math.ceil(t*o/28)*28}return Math.floor(n*r/l.PIXELS_PER_TOKEN)+l.VISION_SPECIAL_TOKENS}async calculateTokensBatch(t){let e=[];for(let{data:n,mimeType:r}of t)try{let i=await this.extractImageMetadata(n,r);e.push(this.calculateTokens(i))}catch(i){p.warn("Error calculating tokens for image:",i),e.push(l.MIN_TOKENS_PER_IMAGE+l.VISION_SPECIAL_TOKENS)}return e}extractBmpDimensions(t){if(t.length<26)throw new Error("Invalid BMP: buffer too short");if(t[0]!==66||t[1]!==77)throw new Error("Invalid BMP signature");let e=t.readUInt32LE(18),n=t.readUInt32LE(22);return{width:e,height:Math.abs(n)}}extractTiffDimensions(t){if(t.length<8)throw new Error("Invalid TIFF: buffer too short");let e=t.subarray(0,2).toString("ascii"),n=e==="II";if(!n&&!(e==="MM"))throw new Error("Invalid TIFF byte order");if((n?t.readUInt16LE(2):t.readUInt16BE(2))!==42)throw new Error("Invalid TIFF magic number");let a=n?t.readUInt32LE(4):t.readUInt32BE(4);if(a>=t.length)throw new Error("Invalid TIFF IFD offset");let s=n?t.readUInt16LE(a):t.readUInt16BE(a),o=0,h=0;for(let g=0;g<s;g++){let c=a+2+g*12;if(c+12>t.length)break;let u=n?t.readUInt16LE(c):t.readUInt16BE(c),f=(n?t.readUInt16LE(c+2):t.readUInt16BE(c+2))===3?n?t.readUInt16LE(c+8):t.readUInt16BE(c+8):n?t.readUInt32LE(c+8):t.readUInt32BE(c+8);if(u===256?o=f:u===257&&(h=f),o>0&&h>0)break}if(o===0||h===0)throw new Error("Could not find TIFF dimensions");return{width:o,height:h}}extractHeicDimensions(t){if(t.length<12)throw new Error("Invalid HEIC: buffer too short");if(t.subarray(4,8).toString("ascii")!=="ftyp")throw new Error("Invalid HEIC: missing ftyp box");let n=t.subarray(8,12).toString("ascii");if(!["heic","heix","hevc","hevx"].includes(n))throw new Error("Invalid HEIC brand");let r=0;for(;r<t.length-8;){let i=t.readUInt32BE(r);if(t.subarray(r+4,r+8).toString("ascii")==="meta"){let o=r+8+4;for(;o<r+i-8;){let h=t.readUInt32BE(o);if(t.subarray(o+4,o+8).toString("ascii")==="ispe"&&o+20<=t.length){let c=t.readUInt32BE(o+12),u=t.readUInt32BE(o+16);return{width:c,height:u}}if(h===0)break;o+=h}}if(i===0)break;r+=i}return p.warn("Could not extract HEIC dimensions, using default"),{width:512,height:512}}};var d=I("TOKENIZER"),T=class{textTokenizer;imageTokenizer;constructor(){this.textTokenizer=new w,this.imageTokenizer=new E}async calculateTokens(t){let e=performance.now();try{let{textContents:n,imageContents:r,audioContents:i,otherContents:a}=this.processAndGroupContents(t);if(n.length===0&&r.length===0&&i.length===0&&a.length===0)return{totalTokens:0,breakdown:{textTokens:0,imageTokens:0,audioTokens:0,otherTokens:0},processingTime:performance.now()-e};let s=await this.calculateTextTokens(n),o=await this.calculateImageTokens(r),h=await this.calculateAudioTokens(i),g=await this.calculateOtherTokens(a),c=s+o+h+g,u=performance.now()-e;return{totalTokens:c,breakdown:{textTokens:s,imageTokens:o,audioTokens:h,otherTokens:g},processingTime:u}}catch(n){d.error("Error calculating tokens:",n);let r=this.calculateFallbackTokens(t);return{totalTokens:r,breakdown:{textTokens:r,imageTokens:0,audioTokens:0,otherTokens:0},processingTime:performance.now()-e}}}async calculateTextTokens(t){if(t.length===0)return 0;try{return await this.textTokenizer.calculateTokens(t.join(""))}catch(e){d.warn("Error calculating text tokens:",e);let n=t.join("").length;return Math.ceil(n/4)}}async calculateImageTokens(t){if(t.length===0)return 0;try{return(await this.imageTokenizer.calculateTokensBatch(t)).reduce((n,r)=>n+r,0)}catch(e){return d.warn("Error calculating image tokens:",e),t.length*6}}async calculateAudioTokens(t){if(t.length===0)return 0;let e=0;for(let n of t)try{let r=Math.floor(n.data.length*.75);e+=Math.max(Math.ceil(r/100),10)}catch(r){d.warn("Error calculating audio tokens:",r),e+=10}return e}async calculateOtherTokens(t){if(t.length===0)return 0;try{return await this.textTokenizer.calculateTokens(t.join(""))}catch(e){d.warn("Error calculating other content tokens:",e);let n=t.join("").length;return Math.ceil(n/4)}}calculateFallbackTokens(t){try{let e=JSON.stringify(t.contents);return Math.ceil(e.length/4)}catch(e){return d.warn("Error in fallback token calculation:",e),100}}processAndGroupContents(t){let e=[],n=[],r=[],i=[];if(!t.contents)return{textContents:e,imageContents:n,audioContents:r,otherContents:i};let a=Array.isArray(t.contents)?t.contents:[t.contents];for(let s of a)this.processContent(s,e,n,r,i);return{textContents:e,imageContents:n,audioContents:r,otherContents:i}}processContent(t,e,n,r,i){if(typeof t=="string"){t.trim()&&e.push(t);return}if("parts"in t&&t.parts){for(let a of t.parts)this.processPart(a,e,n,r,i);return}this.processPart(t,e,n,r,i)}processPart(t,e,n,r,i){if(typeof t=="string"){t.trim()&&e.push(t);return}if("text"in t&&t.text){e.push(t.text);return}if("inlineData"in t&&t.inlineData){let{data:a,mimeType:s}=t.inlineData;if(s&&s.startsWith("image/")){n.push({data:a||"",mimeType:s});return}if(s&&s.startsWith("audio/")){r.push({data:a||"",mimeType:s});return}}if("fileData"in t&&t.fileData){i.push(JSON.stringify(t.fileData));return}if("functionCall"in t&&t.functionCall){i.push(JSON.stringify(t.functionCall));return}if("functionResponse"in t&&t.functionResponse){i.push(JSON.stringify(t.functionResponse));return}try{let a=JSON.stringify(t);a&&a!=="{}"&&i.push(a)}catch(a){d.warn("Failed to serialize unknown part type:",a)}}};m();export{T as a};
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2025 Matilda
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{e as T,v as X}from"./chunk-OMZ5SGMK.js";import{b as P}from"./chunk-TISQNFB5.js";import{c as g}from"./chunk-IOCF4XSR.js";import{Y as $,a as l}from"./chunk-QWBNNEV2.js";import{b as _}from"./chunk-GZPNIYVZ.js";import{f as W}from"./chunk-OWGSC52X.js";_();var R=W(X(),1);import*as d from"node:fs/promises";import{constants as B}from"node:fs";import*as b from"node:path";var f=$("AGENTS_TEAM_TASKS"),v=32768,A=16;function C(r){if(!r)return;let e=Buffer.byteLength(JSON.stringify(r),"utf-8");if(e>v)throw new Error(`Task metadata is too large (${e} bytes; max ${v}). Trim the payload or store the bulk content elsewhere.`)}var K={retries:{retries:30,minTimeout:5,maxTimeout:100,factor:2,randomize:!0},stale:5e3,onCompromised:r=>{f.warn("task lock compromised:",r?.message??r)}},j=new Map;function q(r){let e=j.get(r);return e||(e=new P,j.set(r,e)),e}async function h(r,e,t){return q(r).runExclusive(async()=>{let a;try{a=await R.default.lock(r,K)}catch(o){if(l(o)&&o.code==="ENOENT")return t();throw o}try{return await e()}finally{await a()}})}var z="__reciprocal__",L=new Map;function Y(r){let e=L.get(r);return e||(e=new P,L.set(r,e)),e}function G(r){if(!/^[1-9]\d*$/.test(r))throw new Error(`Invalid task ID "${r}". Task IDs must be positive integers.`)}function m(r,e){return G(e),b.join(T(r),`${e}.json`)}var O=new Set;function ie(r){return O.add(r),()=>{O.delete(r)}}function k(r){for(let e of O)try{e(r)}catch(t){f.warn(`task update listener failed: ${t}`)}}async function oe(r,e){C(e.metadata);let t=T(r);await d.mkdir(t,{recursive:!0});let a=15;for(let o=0;o<a;o++){let c=await I(t),s={id:c,subject:e.subject,description:e.description,activeForm:e.activeForm,owner:e.owner,status:"pending",blocks:[],blockedBy:[],metadata:e.metadata},n=b.join(t,`${c}.json`);try{await(await d.open(n,B.O_WRONLY|B.O_CREAT|B.O_EXCL)).close()}catch(i){if(l(i)&&i.code==="EEXIST")continue;throw i}try{await g(n,s)}catch(i){throw await d.unlink(n).catch(()=>{}),i}return k(r),s}throw new Error(`Failed to create task after ${a} attempts (ID contention).`)}async function ce(r,e){let t=m(r,e);try{let a=await d.readFile(t,"utf-8");return JSON.parse(a)}catch(a){if(l(a)&&a.code==="ENOENT")return;throw a}}var p=class extends Error{constructor(t,a,o){super(`Task #${t} is owned by "${o}". Only the leader or the owner can change status / owner / subject / description / blocks.`);this.taskId=t;this.callerName=a;this.actualOwner=o;this.name="TaskOwnershipError"}};async function F(r,e,t,a){let o=m(r,e);return h(o,async()=>{let c;try{c=await d.readFile(o,"utf-8")}catch(n){if(l(n)&&n.code==="ENOENT")return;throw n}let s=JSON.parse(c);if(a?.callerName!==void 0&&a.callerName!==z&&(t.status!==void 0||t.owner!==void 0||t.subject!==void 0||t.description!==void 0||(t.addBlocks?.length??0)>0||(t.addBlockedBy?.length??0)>0)&&s.owner&&s.owner!==a.callerName)throw new p(e,a.callerName,s.owner);if(t.addBlocks?.length){let n=new Set(s.blocks);for(let i of t.addBlocks)n.add(i);s.blocks=Array.from(n)}if(t.addBlockedBy?.length){let n=new Set(s.blockedBy);for(let i of t.addBlockedBy)n.add(i);s.blockedBy=Array.from(n)}if(t.status!==void 0&&(s.status=t.status,t.status==="completed"&&s.blocks.length>0&&await V(r,e,s.blocks)),t.owner!==void 0&&(s.owner=t.owner?t.owner:void 0),t.subject!==void 0&&(s.subject=t.subject),t.description!==void 0&&(s.description=t.description),t.activeForm!==void 0&&(s.activeForm=t.activeForm??void 0),t.metadata!==void 0){s.metadata=s.metadata??{};for(let[n,i]of Object.entries(t.metadata))n==="__proto__"||n==="constructor"||n==="prototype"||(i===null?delete s.metadata[n]:s.metadata[n]=i);Object.keys(s.metadata).length===0&&(s.metadata=void 0),C(s.metadata)}return await g(o,s),k(r),s},()=>{})}async function de(r,e,t){let a=m(r,e),o=await h(a,async()=>{let s;try{let i=await d.readFile(a,"utf-8");s=JSON.parse(i)}catch(i){if(l(i)&&i.code==="ENOENT")return null;throw i}if(t?.callerName!==void 0&&s.owner&&s.owner!==t.callerName)throw new p(e,t.callerName,s.owner);let n=new Set([...s.blocks,...s.blockedBy]);n.delete(e);try{await d.unlink(a)}catch(i){if(l(i)&&i.code==="ENOENT")return null;throw i}return n},()=>null);if(o===null)return!1;let c=await Promise.allSettled(Array.from(o).map(s=>Q(r,s,e)));for(let s of c)s.status==="rejected"&&f.warn(`deleteTask(${e}): edge cleanup failed: ${s.reason}`);return k(r),!0}async function Q(r,e,t){let a=m(r,e);await h(a,async()=>{try{let o=await d.readFile(a,"utf-8"),c=JSON.parse(o),s=c.blocks.length,n=c.blockedBy.length;if(c.blocks=c.blocks.filter(i=>i!==t),c.blockedBy=c.blockedBy.filter(i=>i!==t),c.blocks.length===s&&c.blockedBy.length===n)return;await g(a,c)}catch(o){if(l(o)&&o.code==="ENOENT")return;throw o}},()=>{})}async function x(r,e){let t=T(r),a;try{a=await d.readdir(t)}catch(n){if(l(n)&&n.code==="ENOENT")return[];let i=n instanceof Error?n.message:String(n);throw f.warn(`Failed to list tasks dir ${t}: ${i}`),n instanceof Error?n:new Error(i)}let o=a.filter(n=>n.endsWith(".json")),c=[];for(let n=0;n<o.length;n+=A){let i=o.slice(n,n+A),w=await Promise.all(i.map(async D=>{let y=b.join(t,D),S;try{S=await d.readFile(y,"utf-8")}catch(u){if(l(u)&&u.code==="ENOENT")return;let E=u instanceof Error?u.message:String(u);f.warn(`Failed to read task file ${y}: ${E}`);return}if(S.trim()!=="")try{return JSON.parse(S)}catch(u){let E=u instanceof Error?u.message:String(u);f.warn(`Quarantining corrupt task file ${y}: ${E}`);let J=`${y}.corrupt-${Date.now()}`;try{await d.rename(y,J)}catch(N){let U=N instanceof Error?N.message:String(N);f.warn(`Failed to quarantine ${y}: ${U}`)}return}}));c.push(...w)}let s=c.filter(n=>n!==void 0);return s.sort((n,i)=>Number(n.id)-Number(i.id)),e?s.filter(n=>!(e.status!==void 0&&n.status!==e.status||e.owner!==void 0&&n.owner!==e.owner||e.blockedBy!==void 0&&!n.blockedBy.includes(e.blockedBy))):s}async function le(r){let e=T(r);await d.rm(e,{recursive:!0,force:!0}),k(r)}async function V(r,e,t){let a=await Promise.allSettled(t.map(async o=>{let c=m(r,o);await h(c,async()=>{let s;try{s=await d.readFile(c,"utf-8")}catch(w){if(l(w)&&w.code==="ENOENT")return;throw w}let n=JSON.parse(s),i=n.blockedBy.length;n.blockedBy=n.blockedBy.filter(w=>w!==e),n.blockedBy.length!==i&&await g(c,n)},()=>{})}));for(let o of a)o.status==="rejected"&&f.warn(`unblockDependents(${e}): ${o.reason}`);k(r)}async function ue(r,e,t){await F(r,e,{addBlocks:[t]}),await F(r,t,{addBlockedBy:[e]})}async function fe(r,e,t,a){return a?.checkAgentBusy?Y(t).runExclusive(()=>M(r,e,t,a,!0)):M(r,e,t,a,!1)}async function M(r,e,t,a,o){if(o&&await H(r,t))return;let c=m(r,e);return h(c,async()=>{let s;try{s=await d.readFile(c,"utf-8")}catch(i){if(l(i)&&i.code==="ENOENT")return;throw i}let n=JSON.parse(s);if(n.status==="pending"&&!n.owner)return n.owner=a?.ownerName??t,n.status="in_progress",await g(c,n),k(r),n},()=>{})}async function H(r,e){let t=await x(r,{status:"in_progress"}),a=e.split("@")[0];return t.some(o=>o.owner===e||o.owner===a)}async function Z(r,e,t){let a=m(r,e);return h(a,async()=>{let o;try{o=await d.readFile(a,"utf-8")}catch(s){if(l(s)&&s.code==="ENOENT")return!1;throw s}let c=JSON.parse(o);return c.status!=="in_progress"||c.owner!==t?!1:(c.owner=void 0,c.status="pending",await g(a,c),!0)},()=>!1)}async function we(r,e){let t=e.split("@")[0],o=(await x(r,{status:"in_progress"})).filter(i=>i.owner===e||i.owner===t),c=await Promise.allSettled(o.map(i=>Z(r,i.id,i.owner))),s=c.filter(i=>i.status==="rejected");s.length>0&&f.warn(`unassignTeammateTasks: ${s.length}/${o.length} task(s) failed to unassign for ${e}`);let n=c.filter(i=>i.status==="fulfilled"&&i.value===!0).length;return n>0&&k(r),n}async function ge(r){let e=await x(r),t=new Map;for(let a of e){if(!a.owner)continue;let o=t.get(a.owner)??{inProgress:0,completed:0};a.status==="in_progress"?o.inProgress++:a.status==="completed"&&o.completed++,t.set(a.owner,o)}return t}async function I(r){let e;try{e=await d.readdir(r)}catch{return"1"}let t=0;for(let a of e){if(!a.endsWith(".json"))continue;let o=parseInt(a.replace(".json",""),10);!isNaN(o)&&o>t&&(t=o)}return String(t+1)}export{z as a,G as b,m as c,ie as d,k as e,oe as f,ce as g,p as h,F as i,de as j,x as k,le as l,ue as m,fe as n,Z as o,we as p,ge as q};
3
+ import{e as T,v as X}from"./chunk-X4ML2NEE.js";import{b as P}from"./chunk-TISQNFB5.js";import{c as g}from"./chunk-SWEYYDZO.js";import{Z as $,a as l}from"./chunk-5QAKUC2D.js";import{b as _}from"./chunk-GZPNIYVZ.js";import{f as W}from"./chunk-OWGSC52X.js";_();var R=W(X(),1);import*as d from"node:fs/promises";import{constants as B}from"node:fs";import*as b from"node:path";var f=$("AGENTS_TEAM_TASKS"),v=32768,A=16;function C(r){if(!r)return;let e=Buffer.byteLength(JSON.stringify(r),"utf-8");if(e>v)throw new Error(`Task metadata is too large (${e} bytes; max ${v}). Trim the payload or store the bulk content elsewhere.`)}var K={retries:{retries:30,minTimeout:5,maxTimeout:100,factor:2,randomize:!0},stale:5e3,onCompromised:r=>{f.warn("task lock compromised:",r?.message??r)}},j=new Map;function q(r){let e=j.get(r);return e||(e=new P,j.set(r,e)),e}async function h(r,e,t){return q(r).runExclusive(async()=>{let a;try{a=await R.default.lock(r,K)}catch(o){if(l(o)&&o.code==="ENOENT")return t();throw o}try{return await e()}finally{await a()}})}var z="__reciprocal__",L=new Map;function Y(r){let e=L.get(r);return e||(e=new P,L.set(r,e)),e}function G(r){if(!/^[1-9]\d*$/.test(r))throw new Error(`Invalid task ID "${r}". Task IDs must be positive integers.`)}function m(r,e){return G(e),b.join(T(r),`${e}.json`)}var O=new Set;function ie(r){return O.add(r),()=>{O.delete(r)}}function k(r){for(let e of O)try{e(r)}catch(t){f.warn(`task update listener failed: ${t}`)}}async function oe(r,e){C(e.metadata);let t=T(r);await d.mkdir(t,{recursive:!0});let a=15;for(let o=0;o<a;o++){let c=await I(t),s={id:c,subject:e.subject,description:e.description,activeForm:e.activeForm,owner:e.owner,status:"pending",blocks:[],blockedBy:[],metadata:e.metadata},n=b.join(t,`${c}.json`);try{await(await d.open(n,B.O_WRONLY|B.O_CREAT|B.O_EXCL)).close()}catch(i){if(l(i)&&i.code==="EEXIST")continue;throw i}try{await g(n,s)}catch(i){throw await d.unlink(n).catch(()=>{}),i}return k(r),s}throw new Error(`Failed to create task after ${a} attempts (ID contention).`)}async function ce(r,e){let t=m(r,e);try{let a=await d.readFile(t,"utf-8");return JSON.parse(a)}catch(a){if(l(a)&&a.code==="ENOENT")return;throw a}}var p=class extends Error{constructor(t,a,o){super(`Task #${t} is owned by "${o}". Only the leader or the owner can change status / owner / subject / description / blocks.`);this.taskId=t;this.callerName=a;this.actualOwner=o;this.name="TaskOwnershipError"}};async function F(r,e,t,a){let o=m(r,e);return h(o,async()=>{let c;try{c=await d.readFile(o,"utf-8")}catch(n){if(l(n)&&n.code==="ENOENT")return;throw n}let s=JSON.parse(c);if(a?.callerName!==void 0&&a.callerName!==z&&(t.status!==void 0||t.owner!==void 0||t.subject!==void 0||t.description!==void 0||(t.addBlocks?.length??0)>0||(t.addBlockedBy?.length??0)>0)&&s.owner&&s.owner!==a.callerName)throw new p(e,a.callerName,s.owner);if(t.addBlocks?.length){let n=new Set(s.blocks);for(let i of t.addBlocks)n.add(i);s.blocks=Array.from(n)}if(t.addBlockedBy?.length){let n=new Set(s.blockedBy);for(let i of t.addBlockedBy)n.add(i);s.blockedBy=Array.from(n)}if(t.status!==void 0&&(s.status=t.status,t.status==="completed"&&s.blocks.length>0&&await V(r,e,s.blocks)),t.owner!==void 0&&(s.owner=t.owner?t.owner:void 0),t.subject!==void 0&&(s.subject=t.subject),t.description!==void 0&&(s.description=t.description),t.activeForm!==void 0&&(s.activeForm=t.activeForm??void 0),t.metadata!==void 0){s.metadata=s.metadata??{};for(let[n,i]of Object.entries(t.metadata))n==="__proto__"||n==="constructor"||n==="prototype"||(i===null?delete s.metadata[n]:s.metadata[n]=i);Object.keys(s.metadata).length===0&&(s.metadata=void 0),C(s.metadata)}return await g(o,s),k(r),s},()=>{})}async function de(r,e,t){let a=m(r,e),o=await h(a,async()=>{let s;try{let i=await d.readFile(a,"utf-8");s=JSON.parse(i)}catch(i){if(l(i)&&i.code==="ENOENT")return null;throw i}if(t?.callerName!==void 0&&s.owner&&s.owner!==t.callerName)throw new p(e,t.callerName,s.owner);let n=new Set([...s.blocks,...s.blockedBy]);n.delete(e);try{await d.unlink(a)}catch(i){if(l(i)&&i.code==="ENOENT")return null;throw i}return n},()=>null);if(o===null)return!1;let c=await Promise.allSettled(Array.from(o).map(s=>Q(r,s,e)));for(let s of c)s.status==="rejected"&&f.warn(`deleteTask(${e}): edge cleanup failed: ${s.reason}`);return k(r),!0}async function Q(r,e,t){let a=m(r,e);await h(a,async()=>{try{let o=await d.readFile(a,"utf-8"),c=JSON.parse(o),s=c.blocks.length,n=c.blockedBy.length;if(c.blocks=c.blocks.filter(i=>i!==t),c.blockedBy=c.blockedBy.filter(i=>i!==t),c.blocks.length===s&&c.blockedBy.length===n)return;await g(a,c)}catch(o){if(l(o)&&o.code==="ENOENT")return;throw o}},()=>{})}async function x(r,e){let t=T(r),a;try{a=await d.readdir(t)}catch(n){if(l(n)&&n.code==="ENOENT")return[];let i=n instanceof Error?n.message:String(n);throw f.warn(`Failed to list tasks dir ${t}: ${i}`),n instanceof Error?n:new Error(i)}let o=a.filter(n=>n.endsWith(".json")),c=[];for(let n=0;n<o.length;n+=A){let i=o.slice(n,n+A),w=await Promise.all(i.map(async D=>{let y=b.join(t,D),S;try{S=await d.readFile(y,"utf-8")}catch(u){if(l(u)&&u.code==="ENOENT")return;let E=u instanceof Error?u.message:String(u);f.warn(`Failed to read task file ${y}: ${E}`);return}if(S.trim()!=="")try{return JSON.parse(S)}catch(u){let E=u instanceof Error?u.message:String(u);f.warn(`Quarantining corrupt task file ${y}: ${E}`);let J=`${y}.corrupt-${Date.now()}`;try{await d.rename(y,J)}catch(N){let U=N instanceof Error?N.message:String(N);f.warn(`Failed to quarantine ${y}: ${U}`)}return}}));c.push(...w)}let s=c.filter(n=>n!==void 0);return s.sort((n,i)=>Number(n.id)-Number(i.id)),e?s.filter(n=>!(e.status!==void 0&&n.status!==e.status||e.owner!==void 0&&n.owner!==e.owner||e.blockedBy!==void 0&&!n.blockedBy.includes(e.blockedBy))):s}async function le(r){let e=T(r);await d.rm(e,{recursive:!0,force:!0}),k(r)}async function V(r,e,t){let a=await Promise.allSettled(t.map(async o=>{let c=m(r,o);await h(c,async()=>{let s;try{s=await d.readFile(c,"utf-8")}catch(w){if(l(w)&&w.code==="ENOENT")return;throw w}let n=JSON.parse(s),i=n.blockedBy.length;n.blockedBy=n.blockedBy.filter(w=>w!==e),n.blockedBy.length!==i&&await g(c,n)},()=>{})}));for(let o of a)o.status==="rejected"&&f.warn(`unblockDependents(${e}): ${o.reason}`);k(r)}async function ue(r,e,t){await F(r,e,{addBlocks:[t]}),await F(r,t,{addBlockedBy:[e]})}async function fe(r,e,t,a){return a?.checkAgentBusy?Y(t).runExclusive(()=>M(r,e,t,a,!0)):M(r,e,t,a,!1)}async function M(r,e,t,a,o){if(o&&await H(r,t))return;let c=m(r,e);return h(c,async()=>{let s;try{s=await d.readFile(c,"utf-8")}catch(i){if(l(i)&&i.code==="ENOENT")return;throw i}let n=JSON.parse(s);if(n.status==="pending"&&!n.owner)return n.owner=a?.ownerName??t,n.status="in_progress",await g(c,n),k(r),n},()=>{})}async function H(r,e){let t=await x(r,{status:"in_progress"}),a=e.split("@")[0];return t.some(o=>o.owner===e||o.owner===a)}async function Z(r,e,t){let a=m(r,e);return h(a,async()=>{let o;try{o=await d.readFile(a,"utf-8")}catch(s){if(l(s)&&s.code==="ENOENT")return!1;throw s}let c=JSON.parse(o);return c.status!=="in_progress"||c.owner!==t?!1:(c.owner=void 0,c.status="pending",await g(a,c),!0)},()=>!1)}async function we(r,e){let t=e.split("@")[0],o=(await x(r,{status:"in_progress"})).filter(i=>i.owner===e||i.owner===t),c=await Promise.allSettled(o.map(i=>Z(r,i.id,i.owner))),s=c.filter(i=>i.status==="rejected");s.length>0&&f.warn(`unassignTeammateTasks: ${s.length}/${o.length} task(s) failed to unassign for ${e}`);let n=c.filter(i=>i.status==="fulfilled"&&i.value===!0).length;return n>0&&k(r),n}async function ge(r){let e=await x(r),t=new Map;for(let a of e){if(!a.owner)continue;let o=t.get(a.owner)??{inProgress:0,completed:0};a.status==="in_progress"?o.inProgress++:a.status==="completed"&&o.completed++,t.set(a.owner,o)}return t}async function I(r){let e;try{e=await d.readdir(r)}catch{return"1"}let t=0;for(let a of e){if(!a.endsWith(".json"))continue;let o=parseInt(a.replace(".json",""),10);!isNaN(o)&&o>t&&(t=o)}return String(t+1)}export{z as a,G as b,m as c,ie as d,k as e,oe as f,ce as g,p as h,F as i,de as j,x as k,le as l,ue as m,fe as n,Z as o,we as p,ge as q};
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2025 Matilda
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{E as l,H as M,L as A,s as g}from"./chunk-QWBNNEV2.js";import{b as h}from"./chunk-GZPNIYVZ.js";h();import*as s from"node:fs";import*as t from"node:path";var f="memory",y="MEMORY.md",x="meta.json",R="extract-cursor.json",O="consolidation.lock",T="memories";function D(r){let o=t.resolve(r);for(;;){let e=t.join(o,".git");if(s.existsSync(e))return o;let n=t.dirname(o);if(n===o)return null;o=n}}function j(r){let o=D(r);if(!o)return null;try{let e=s.readFileSync(t.join(o,".git"),"utf-8").trim();if(!e.startsWith("gitdir:"))return o;let n=t.resolve(o,e.slice(7).trim()),i=t.resolve(n,s.readFileSync(t.join(n,"commondir"),"utf-8").trim());return t.resolve(t.dirname(n))!==t.join(i,"worktrees")||s.realpathSync(s.readFileSync(t.join(n,"gitdir"),"utf-8").trim())!==t.join(s.realpathSync(o),".git")?o:t.basename(i)!==".git"?i.normalize("NFC"):t.dirname(i).normalize("NFC")}catch{return o}}function _(){return process.env.MATILDA_CODE_MEMORY_BASE_DIR?M(void 0,process.env.MATILDA_CODE_MEMORY_BASE_DIR):A.getRuntimeBaseDir()}var c=new Map;function u(r){let o=process.env.MATILDA_CODE_MEMORY_LOCAL==="1",e=o?"":_(),n=`${o?"local":e}\0${r}`,i=c.get(n);if(i!==void 0)return i;let a;if(o)a=t.join(r,g,f);else{let d=j(r)??t.resolve(r);a=t.join(e,"projects",l(d),f)}return c.set(n,a),a}function S(){c.clear()}function p(r){return t.dirname(u(r))}function I(r,o){let e=t.normalize(r),n=t.normalize(u(o)),i=t.relative(n,e);return i===""||!i.startsWith("..")&&!t.isAbsolute(i)}function v(r){return t.join(u(r),y)}function U(r){return t.join(p(r),x)}function F(r){return t.join(p(r),R)}function N(r){return t.join(p(r),O)}function E(r){return`${r}.md`}function Y(r,o){return t.join(u(r),E(o))}function z(r,o){return t.join(u(r),o)}function m(){return t.join(_(),T)}function k(){return t.join(m(),y)}function b(r){return t.join(m(),E(r))}function C(r){let o=t.normalize(r),e=t.normalize(m()),n=t.relative(e,o);return n===""||!n.startsWith("..")&&!t.isAbsolute(n)}function w(r,o){return I(r,o)||C(r)}export{f as a,y as b,x as c,R as d,O as e,T as f,_ as g,u as h,S as i,p as j,I as k,v as l,U as m,F as n,N as o,E as p,Y as q,z as r,m as s,k as t,b as u,C as v,w};
3
+ import{F as l,I as M,M as A,t as g}from"./chunk-5QAKUC2D.js";import{b as h}from"./chunk-GZPNIYVZ.js";h();import*as s from"node:fs";import*as t from"node:path";var f="memory",y="MEMORY.md",x="meta.json",R="extract-cursor.json",O="consolidation.lock",T="memories";function D(r){let o=t.resolve(r);for(;;){let e=t.join(o,".git");if(s.existsSync(e))return o;let n=t.dirname(o);if(n===o)return null;o=n}}function j(r){let o=D(r);if(!o)return null;try{let e=s.readFileSync(t.join(o,".git"),"utf-8").trim();if(!e.startsWith("gitdir:"))return o;let n=t.resolve(o,e.slice(7).trim()),i=t.resolve(n,s.readFileSync(t.join(n,"commondir"),"utf-8").trim());return t.resolve(t.dirname(n))!==t.join(i,"worktrees")||s.realpathSync(s.readFileSync(t.join(n,"gitdir"),"utf-8").trim())!==t.join(s.realpathSync(o),".git")?o:t.basename(i)!==".git"?i.normalize("NFC"):t.dirname(i).normalize("NFC")}catch{return o}}function _(){return process.env.MATILDA_CODE_MEMORY_BASE_DIR?M(void 0,process.env.MATILDA_CODE_MEMORY_BASE_DIR):A.getRuntimeBaseDir()}var c=new Map;function u(r){let o=process.env.MATILDA_CODE_MEMORY_LOCAL==="1",e=o?"":_(),n=`${o?"local":e}\0${r}`,i=c.get(n);if(i!==void 0)return i;let a;if(o)a=t.join(r,g,f);else{let d=j(r)??t.resolve(r);a=t.join(e,"projects",l(d),f)}return c.set(n,a),a}function S(){c.clear()}function p(r){return t.dirname(u(r))}function I(r,o){let e=t.normalize(r),n=t.normalize(u(o)),i=t.relative(n,e);return i===""||!i.startsWith("..")&&!t.isAbsolute(i)}function v(r){return t.join(u(r),y)}function U(r){return t.join(p(r),x)}function F(r){return t.join(p(r),R)}function N(r){return t.join(p(r),O)}function E(r){return`${r}.md`}function Y(r,o){return t.join(u(r),E(o))}function z(r,o){return t.join(u(r),o)}function m(){return t.join(_(),T)}function k(){return t.join(m(),y)}function b(r){return t.join(m(),E(r))}function C(r){let o=t.normalize(r),e=t.normalize(m()),n=t.relative(e,o);return n===""||!n.startsWith("..")&&!t.isAbsolute(n)}function w(r,o){return I(r,o)||C(r)}export{f as a,y as b,x as c,R as d,O as e,T as f,_ as g,u as h,S as i,p as j,I as k,v as l,U as m,F as n,N as o,E as p,Y as q,z as r,m as s,k as t,b as u,C as v,w};
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2025 Google LLC
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{a,c}from"./chunk-QWBNNEV2.js";import{b as E}from"./chunk-GZPNIYVZ.js";E();import{URL as g}from"node:url";var l=[/^10\./,/^127\./,/^172\.(1[6-9]|2[0-9]|3[0-1])\./,/^192\.168\./,/^::1$/,/^fc00:/,/^fe80:/],f=new Set(["UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","SELF_SIGNED_CERT_IN_CHAIN","DEPTH_ZERO_SELF_SIGNED_CERT","CERT_HAS_EXPIRED","ERR_TLS_CERT_ALTNAME_INVALID"]),T=new Set([...f,"ECONNRESET","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EAI_AGAIN","EHOSTUNREACH","ENETUNREACH"]),u=class extends Error{constructor(t,o){super(t);this.code=o;this.name="FetchError"}};function S(n){try{let e=new g(n).hostname;return l.some(t=>t.test(e))}catch{return!1}}async function A(n,e,t){let o=new AbortController,r=setTimeout(()=>o.abort(),e);try{return await fetch(n,{signal:o.signal,headers:t})}catch(s){throw a(s)&&s.code==="ABORT_ERR"?new u(`Request timed out after ${e}ms`,"ETIMEDOUT"):new u(c(s))}finally{clearTimeout(r)}}function i(n){if(!(!n||typeof n!="object")&&"code"in n&&typeof n.code=="string")return n.code}function h(n){if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);if(n instanceof Error)return n.message;if(!n||typeof n!="object")return;let e=n.message;if(typeof e=="string")return e}function m(n){if(!(n instanceof Error))return;let e=n.cause;if(!e)return;let t=i(e),o=h(e);if(!(!t&&!o))return t&&o&&!o.includes(t)?`${t}: ${o}`:o??t}function N(n,e={}){let t=c(n),o=n instanceof Error?i(n.cause)??i(n):i(n),r=m(n),s=[t,r?`(cause: ${r})`:void 0].filter(Boolean).join(" "),d=t.toLowerCase().includes("fetch failed")||o!=null&&T.has(o),R=o!=null&&f.has(o);if(!d)return s;let _=["","Troubleshooting:",...e.url?[`- Confirm you can reach ${e.url} from this machine.`]:[],"- If you are behind a proxy, pass `--proxy <url>` (or set `proxy` in settings).",...R?["- If your network uses a corporate TLS inspection CA, set `NODE_EXTRA_CA_CERTS` to your CA bundle."]:[]];return`${s}${_.join(`
3
+ import{a,c}from"./chunk-5QAKUC2D.js";import{b as E}from"./chunk-GZPNIYVZ.js";E();import{URL as g}from"node:url";var l=[/^10\./,/^127\./,/^172\.(1[6-9]|2[0-9]|3[0-1])\./,/^192\.168\./,/^::1$/,/^fc00:/,/^fe80:/],f=new Set(["UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","SELF_SIGNED_CERT_IN_CHAIN","DEPTH_ZERO_SELF_SIGNED_CERT","CERT_HAS_EXPIRED","ERR_TLS_CERT_ALTNAME_INVALID"]),T=new Set([...f,"ECONNRESET","ETIMEDOUT","ECONNREFUSED","ENOTFOUND","EAI_AGAIN","EHOSTUNREACH","ENETUNREACH"]),u=class extends Error{constructor(t,o){super(t);this.code=o;this.name="FetchError"}};function S(n){try{let e=new g(n).hostname;return l.some(t=>t.test(e))}catch{return!1}}async function A(n,e,t){let o=new AbortController,r=setTimeout(()=>o.abort(),e);try{return await fetch(n,{signal:o.signal,headers:t})}catch(s){throw a(s)&&s.code==="ABORT_ERR"?new u(`Request timed out after ${e}ms`,"ETIMEDOUT"):new u(c(s))}finally{clearTimeout(r)}}function i(n){if(!(!n||typeof n!="object")&&"code"in n&&typeof n.code=="string")return n.code}function h(n){if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);if(n instanceof Error)return n.message;if(!n||typeof n!="object")return;let e=n.message;if(typeof e=="string")return e}function m(n){if(!(n instanceof Error))return;let e=n.cause;if(!e)return;let t=i(e),o=h(e);if(!(!t&&!o))return t&&o&&!o.includes(t)?`${t}: ${o}`:o??t}function N(n,e={}){let t=c(n),o=n instanceof Error?i(n.cause)??i(n):i(n),r=m(n),s=[t,r?`(cause: ${r})`:void 0].filter(Boolean).join(" "),d=t.toLowerCase().includes("fetch failed")||o!=null&&T.has(o),R=o!=null&&f.has(o);if(!d)return s;let _=["","Troubleshooting:",...e.url?[`- Confirm you can reach ${e.url} from this machine.`]:[],"- If you are behind a proxy, pass `--proxy <url>` (or set `proxy` in settings).",...R?["- If your network uses a corporate TLS inspection CA, set `NODE_EXTRA_CA_CERTS` to your CA bundle."]:[]];return`${s}${_.join(`
4
4
  `)}`}export{S as a,A as b,N as c};
5
5
  /**
6
6
  * @license
@@ -1,6 +1,6 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import{l as we,m as Ae,n as Ge,o as qe,p as Ue,q as ne}from"./chunk-QKYGQLWC.js";import{c as je}from"./chunk-IOCF4XSR.js";import{L as Se,a as ve}from"./chunk-QWBNNEV2.js";import{b as y}from"./chunk-GZPNIYVZ.js";import{a as U,d as k}from"./chunk-OWGSC52X.js";var Ke=k((_r,Ye)=>{y();var $=U("constants"),Ot=process.cwd,oe=null,Ft=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return oe||(oe=Ot.call(process)),oe};try{process.cwd()}catch{}typeof process.chdir=="function"&&(Te=process.chdir,process.chdir=function(e){oe=null,Te.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,Te));var Te;Ye.exports=It;function It(e){$.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||r(e),e.chown=u(e.chown),e.fchown=u(e.fchown),e.lchown=u(e.lchown),e.chmod=n(e.chmod),e.fchmod=n(e.fchmod),e.lchmod=n(e.lchmod),e.chownSync=l(e.chownSync),e.fchownSync=l(e.fchownSync),e.lchownSync=l(e.lchownSync),e.chmodSync=o(e.chmodSync),e.fchmodSync=o(e.fchmodSync),e.lchmodSync=o(e.lchmodSync),e.stat=h(e.stat),e.fstat=h(e.fstat),e.lstat=h(e.lstat),e.statSync=T(e.statSync),e.fstatSync=T(e.fstatSync),e.lstatSync=T(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(i,m,c){c&&process.nextTick(c)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(i,m,c,a){a&&process.nextTick(a)},e.lchownSync=function(){}),Ft==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:function(i){function m(c,a,s){var w=Date.now(),v=0;i(c,a,function E(C){if(C&&(C.code==="EACCES"||C.code==="EPERM"||C.code==="EBUSY")&&Date.now()-w<6e4){setTimeout(function(){e.stat(a,function(R,Z){R&&R.code==="ENOENT"?i(c,a,E):s(C)})},v),v<100&&(v+=10);return}s&&s(C)})}return Object.setPrototypeOf&&Object.setPrototypeOf(m,i),m}(e.rename)),e.read=typeof e.read!="function"?e.read:function(i){function m(c,a,s,w,v,E){var C;if(E&&typeof E=="function"){var R=0;C=function(Z,Ce,ke){if(Z&&Z.code==="EAGAIN"&&R<10)return R++,i.call(e,c,a,s,w,v,C);E.apply(this,arguments)}}return i.call(e,c,a,s,w,v,C)}return Object.setPrototypeOf&&Object.setPrototypeOf(m,i),m}(e.read),e.readSync=typeof e.readSync!="function"?e.readSync:function(i){return function(m,c,a,s,w){for(var v=0;;)try{return i.call(e,m,c,a,s,w)}catch(E){if(E.code==="EAGAIN"&&v<10){v++;continue}throw E}}}(e.readSync);function t(i){i.lchmod=function(m,c,a){i.open(m,$.O_WRONLY|$.O_SYMLINK,c,function(s,w){if(s){a&&a(s);return}i.fchmod(w,c,function(v){i.close(w,function(E){a&&a(v||E)})})})},i.lchmodSync=function(m,c){var a=i.openSync(m,$.O_WRONLY|$.O_SYMLINK,c),s=!0,w;try{w=i.fchmodSync(a,c),s=!1}finally{if(s)try{i.closeSync(a)}catch{}else i.closeSync(a)}return w}}function r(i){$.hasOwnProperty("O_SYMLINK")&&i.futimes?(i.lutimes=function(m,c,a,s){i.open(m,$.O_SYMLINK,function(w,v){if(w){s&&s(w);return}i.futimes(v,c,a,function(E){i.close(v,function(C){s&&s(E||C)})})})},i.lutimesSync=function(m,c,a){var s=i.openSync(m,$.O_SYMLINK),w,v=!0;try{w=i.futimesSync(s,c,a),v=!1}finally{if(v)try{i.closeSync(s)}catch{}else i.closeSync(s)}return w}):i.futimes&&(i.lutimes=function(m,c,a,s){s&&process.nextTick(s)},i.lutimesSync=function(){})}function n(i){return i&&function(m,c,a){return i.call(e,m,c,function(s){I(s)&&(s=null),a&&a.apply(this,arguments)})}}function o(i){return i&&function(m,c){try{return i.call(e,m,c)}catch(a){if(!I(a))throw a}}}function u(i){return i&&function(m,c,a,s){return i.call(e,m,c,a,function(w){I(w)&&(w=null),s&&s.apply(this,arguments)})}}function l(i){return i&&function(m,c,a){try{return i.call(e,m,c,a)}catch(s){if(!I(s))throw s}}}function h(i){return i&&function(m,c,a){typeof c=="function"&&(a=c,c=null);function s(w,v){v&&(v.uid<0&&(v.uid+=4294967296),v.gid<0&&(v.gid+=4294967296)),a&&a.apply(this,arguments)}return c?i.call(e,m,c,s):i.call(e,m,s)}}function T(i){return i&&function(m,c){var a=c?i.call(e,m,c):i.call(e,m);return a&&(a.uid<0&&(a.uid+=4294967296),a.gid<0&&(a.gid+=4294967296)),a}}function I(i){if(!i||i.code==="ENOSYS")return!0;var m=!process.getuid||process.getuid()!==0;return!!(m&&(i.code==="EINVAL"||i.code==="EPERM"))}}});var Qe=k((Er,Be)=>{y();var ze=U("stream").Stream;Be.exports=bt;function bt(e){return{ReadStream:t,WriteStream:r};function t(n,o){if(!(this instanceof t))return new t(n,o);ze.call(this);var u=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=64*1024,o=o||{};for(var l=Object.keys(o),h=0,T=l.length;h<T;h++){var I=l[h];this[I]=o[I]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.end===void 0)this.end=1/0;else if(typeof this.end!="number")throw TypeError("end must be a Number");if(this.start>this.end)throw new Error("start must be <= end");this.pos=this.start}if(this.fd!==null){process.nextTick(function(){u._read()});return}e.open(this.path,this.flags,this.mode,function(i,m){if(i){u.emit("error",i),u.readable=!1;return}u.fd=m,u.emit("open",m),u._read()})}function r(n,o){if(!(this instanceof r))return new r(n,o);ze.call(this),this.path=n,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,o=o||{};for(var u=Object.keys(o),l=0,h=u.length;l<h;l++){var T=u[l];this[T]=o[T]}if(this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.start<0)throw new Error("start must be >= zero");this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}});var Xe=k((Or,Je)=>{"use strict";y();Je.exports=Dt;var Mt=Object.getPrototypeOf||function(e){return e.__proto__};function Dt(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Mt(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Fe=k((Ir,Oe)=>{y();var O=U("fs"),Pt=Ke(),Nt=Qe(),Lt=Xe(),ue=U("util"),L,ce;typeof Symbol=="function"&&typeof Symbol.for=="function"?(L=Symbol.for("graceful-fs.queue"),ce=Symbol.for("graceful-fs.previous")):(L="___graceful-fs.queue",ce="___graceful-fs.previous");function Rt(){}function Ze(e,t){Object.defineProperty(e,L,{get:function(){return t}})}var Y=Rt;ue.debuglog?Y=ue.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(Y=function(){var e=ue.format.apply(ue,arguments);e="GFS4: "+e.split(/\n/).join(`
3
+ import{l as we,m as Ae,n as Ge,o as qe,p as Ue,q as ne}from"./chunk-QKYGQLWC.js";import{c as je}from"./chunk-SWEYYDZO.js";import{M as Se,a as ve}from"./chunk-5QAKUC2D.js";import{b as y}from"./chunk-GZPNIYVZ.js";import{a as U,d as k}from"./chunk-OWGSC52X.js";var Ke=k((_r,Ye)=>{y();var $=U("constants"),Ot=process.cwd,oe=null,Ft=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return oe||(oe=Ot.call(process)),oe};try{process.cwd()}catch{}typeof process.chdir=="function"&&(Te=process.chdir,process.chdir=function(e){oe=null,Te.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,Te));var Te;Ye.exports=It;function It(e){$.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||r(e),e.chown=u(e.chown),e.fchown=u(e.fchown),e.lchown=u(e.lchown),e.chmod=n(e.chmod),e.fchmod=n(e.fchmod),e.lchmod=n(e.lchmod),e.chownSync=l(e.chownSync),e.fchownSync=l(e.fchownSync),e.lchownSync=l(e.lchownSync),e.chmodSync=o(e.chmodSync),e.fchmodSync=o(e.fchmodSync),e.lchmodSync=o(e.lchmodSync),e.stat=h(e.stat),e.fstat=h(e.fstat),e.lstat=h(e.lstat),e.statSync=T(e.statSync),e.fstatSync=T(e.fstatSync),e.lstatSync=T(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(i,m,c){c&&process.nextTick(c)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(i,m,c,a){a&&process.nextTick(a)},e.lchownSync=function(){}),Ft==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:function(i){function m(c,a,s){var w=Date.now(),v=0;i(c,a,function E(C){if(C&&(C.code==="EACCES"||C.code==="EPERM"||C.code==="EBUSY")&&Date.now()-w<6e4){setTimeout(function(){e.stat(a,function(R,Z){R&&R.code==="ENOENT"?i(c,a,E):s(C)})},v),v<100&&(v+=10);return}s&&s(C)})}return Object.setPrototypeOf&&Object.setPrototypeOf(m,i),m}(e.rename)),e.read=typeof e.read!="function"?e.read:function(i){function m(c,a,s,w,v,E){var C;if(E&&typeof E=="function"){var R=0;C=function(Z,Ce,ke){if(Z&&Z.code==="EAGAIN"&&R<10)return R++,i.call(e,c,a,s,w,v,C);E.apply(this,arguments)}}return i.call(e,c,a,s,w,v,C)}return Object.setPrototypeOf&&Object.setPrototypeOf(m,i),m}(e.read),e.readSync=typeof e.readSync!="function"?e.readSync:function(i){return function(m,c,a,s,w){for(var v=0;;)try{return i.call(e,m,c,a,s,w)}catch(E){if(E.code==="EAGAIN"&&v<10){v++;continue}throw E}}}(e.readSync);function t(i){i.lchmod=function(m,c,a){i.open(m,$.O_WRONLY|$.O_SYMLINK,c,function(s,w){if(s){a&&a(s);return}i.fchmod(w,c,function(v){i.close(w,function(E){a&&a(v||E)})})})},i.lchmodSync=function(m,c){var a=i.openSync(m,$.O_WRONLY|$.O_SYMLINK,c),s=!0,w;try{w=i.fchmodSync(a,c),s=!1}finally{if(s)try{i.closeSync(a)}catch{}else i.closeSync(a)}return w}}function r(i){$.hasOwnProperty("O_SYMLINK")&&i.futimes?(i.lutimes=function(m,c,a,s){i.open(m,$.O_SYMLINK,function(w,v){if(w){s&&s(w);return}i.futimes(v,c,a,function(E){i.close(v,function(C){s&&s(E||C)})})})},i.lutimesSync=function(m,c,a){var s=i.openSync(m,$.O_SYMLINK),w,v=!0;try{w=i.futimesSync(s,c,a),v=!1}finally{if(v)try{i.closeSync(s)}catch{}else i.closeSync(s)}return w}):i.futimes&&(i.lutimes=function(m,c,a,s){s&&process.nextTick(s)},i.lutimesSync=function(){})}function n(i){return i&&function(m,c,a){return i.call(e,m,c,function(s){I(s)&&(s=null),a&&a.apply(this,arguments)})}}function o(i){return i&&function(m,c){try{return i.call(e,m,c)}catch(a){if(!I(a))throw a}}}function u(i){return i&&function(m,c,a,s){return i.call(e,m,c,a,function(w){I(w)&&(w=null),s&&s.apply(this,arguments)})}}function l(i){return i&&function(m,c,a){try{return i.call(e,m,c,a)}catch(s){if(!I(s))throw s}}}function h(i){return i&&function(m,c,a){typeof c=="function"&&(a=c,c=null);function s(w,v){v&&(v.uid<0&&(v.uid+=4294967296),v.gid<0&&(v.gid+=4294967296)),a&&a.apply(this,arguments)}return c?i.call(e,m,c,s):i.call(e,m,s)}}function T(i){return i&&function(m,c){var a=c?i.call(e,m,c):i.call(e,m);return a&&(a.uid<0&&(a.uid+=4294967296),a.gid<0&&(a.gid+=4294967296)),a}}function I(i){if(!i||i.code==="ENOSYS")return!0;var m=!process.getuid||process.getuid()!==0;return!!(m&&(i.code==="EINVAL"||i.code==="EPERM"))}}});var Qe=k((Er,Be)=>{y();var ze=U("stream").Stream;Be.exports=bt;function bt(e){return{ReadStream:t,WriteStream:r};function t(n,o){if(!(this instanceof t))return new t(n,o);ze.call(this);var u=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=64*1024,o=o||{};for(var l=Object.keys(o),h=0,T=l.length;h<T;h++){var I=l[h];this[I]=o[I]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.end===void 0)this.end=1/0;else if(typeof this.end!="number")throw TypeError("end must be a Number");if(this.start>this.end)throw new Error("start must be <= end");this.pos=this.start}if(this.fd!==null){process.nextTick(function(){u._read()});return}e.open(this.path,this.flags,this.mode,function(i,m){if(i){u.emit("error",i),u.readable=!1;return}u.fd=m,u.emit("open",m),u._read()})}function r(n,o){if(!(this instanceof r))return new r(n,o);ze.call(this),this.path=n,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,o=o||{};for(var u=Object.keys(o),l=0,h=u.length;l<h;l++){var T=u[l];this[T]=o[T]}if(this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.start<0)throw new Error("start must be >= zero");this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}});var Xe=k((Or,Je)=>{"use strict";y();Je.exports=Dt;var Mt=Object.getPrototypeOf||function(e){return e.__proto__};function Dt(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Mt(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Fe=k((Ir,Oe)=>{y();var O=U("fs"),Pt=Ke(),Nt=Qe(),Lt=Xe(),ue=U("util"),L,ce;typeof Symbol=="function"&&typeof Symbol.for=="function"?(L=Symbol.for("graceful-fs.queue"),ce=Symbol.for("graceful-fs.previous")):(L="___graceful-fs.queue",ce="___graceful-fs.previous");function Rt(){}function Ze(e,t){Object.defineProperty(e,L,{get:function(){return t}})}var Y=Rt;ue.debuglog?Y=ue.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(Y=function(){var e=ue.format.apply(ue,arguments);e="GFS4: "+e.split(/\n/).join(`
4
4
  GFS4: `),console.error(e)});O[L]||(He=globalThis[L]||[],Ze(O,He),O.close=function(e){function t(r,n){return e.call(O,r,function(o){o||Ve(),typeof n=="function"&&n.apply(this,arguments)})}return Object.defineProperty(t,ce,{value:e}),t}(O.close),O.closeSync=function(e){function t(r){e.apply(O,arguments),Ve()}return Object.defineProperty(t,ce,{value:e}),t}(O.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",function(){Y(O[L]),U("assert").equal(O[L].length,0)}));var He;globalThis[L]||Ze(globalThis,O[L]);Oe.exports=Ee(Lt(O));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!O.__patched&&(Oe.exports=Ee(O),O.__patched=!0);function Ee(e){Pt(e),e.gracefulify=Ee,e.createReadStream=Ce,e.createWriteStream=ke;var t=e.readFile;e.readFile=r;function r(f,d,p){return typeof d=="function"&&(p=d,d=null),D(f,d,p);function D(P,b,x,F){return t(P,b,function(S){S&&(S.code==="EMFILE"||S.code==="ENFILE")?Q([D,[P,b,x],S,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var n=e.writeFile;e.writeFile=o;function o(f,d,p,D){return typeof p=="function"&&(D=p,p=null),P(f,d,p,D);function P(b,x,F,S,N){return n(b,x,F,function(g){g&&(g.code==="EMFILE"||g.code==="ENFILE")?Q([P,[b,x,F,S],g,N||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}var u=e.appendFile;u&&(e.appendFile=l);function l(f,d,p,D){return typeof p=="function"&&(D=p,p=null),P(f,d,p,D);function P(b,x,F,S,N){return u(b,x,F,function(g){g&&(g.code==="EMFILE"||g.code==="ENFILE")?Q([P,[b,x,F,S],g,N||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}var h=e.copyFile;h&&(e.copyFile=T);function T(f,d,p,D){return typeof p=="function"&&(D=p,p=0),P(f,d,p,D);function P(b,x,F,S,N){return h(b,x,F,function(g){g&&(g.code==="EMFILE"||g.code==="ENFILE")?Q([P,[b,x,F,S],g,N||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}var I=e.readdir;e.readdir=m;var i=/^v[0-5]\./;function m(f,d,p){typeof d=="function"&&(p=d,d=null);var D=i.test(process.version)?function(x,F,S,N){return I(x,P(x,F,S,N))}:function(x,F,S,N){return I(x,F,P(x,F,S,N))};return D(f,d,p);function P(b,x,F,S){return function(N,g){N&&(N.code==="EMFILE"||N.code==="ENFILE")?Q([D,[b,x,F],N,S||Date.now(),Date.now()]):(g&&g.sort&&g.sort(),typeof F=="function"&&F.call(this,N,g))}}}if(process.version.substr(0,4)==="v0.8"){var c=Nt(e);E=c.ReadStream,R=c.WriteStream}var a=e.ReadStream;a&&(E.prototype=Object.create(a.prototype),E.prototype.open=C);var s=e.WriteStream;s&&(R.prototype=Object.create(s.prototype),R.prototype.open=Z),Object.defineProperty(e,"ReadStream",{get:function(){return E},set:function(f){E=f},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return R},set:function(f){R=f},enumerable:!0,configurable:!0});var w=E;Object.defineProperty(e,"FileReadStream",{get:function(){return w},set:function(f){w=f},enumerable:!0,configurable:!0});var v=R;Object.defineProperty(e,"FileWriteStream",{get:function(){return v},set:function(f){v=f},enumerable:!0,configurable:!0});function E(f,d){return this instanceof E?(a.apply(this,arguments),this):E.apply(Object.create(E.prototype),arguments)}function C(){var f=this;ye(f.path,f.flags,f.mode,function(d,p){d?(f.autoClose&&f.destroy(),f.emit("error",d)):(f.fd=p,f.emit("open",p),f.read())})}function R(f,d){return this instanceof R?(s.apply(this,arguments),this):R.apply(Object.create(R.prototype),arguments)}function Z(){var f=this;ye(f.path,f.flags,f.mode,function(d,p){d?(f.destroy(),f.emit("error",d)):(f.fd=p,f.emit("open",p))})}function Ce(f,d){return new e.ReadStream(f,d)}function ke(f,d){return new e.WriteStream(f,d)}var _t=e.open;e.open=ye;function ye(f,d,p,D){return typeof p=="function"&&(D=p,p=null),P(f,d,p,D);function P(b,x,F,S,N){return _t(b,x,F,function(g,tr){g&&(g.code==="EMFILE"||g.code==="ENFILE")?Q([P,[b,x,F,S],g,N||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}return e}function Q(e){Y("ENQUEUE",e[0].name,e[1]),O[L].push(e),xe()}var ae;function Ve(){for(var e=Date.now(),t=0;t<O[L].length;++t)O[L][t].length>2&&(O[L][t][3]=e,O[L][t][4]=e);xe()}function xe(){if(clearTimeout(ae),ae=void 0,O[L].length!==0){var e=O[L].shift(),t=e[0],r=e[1],n=e[2],o=e[3],u=e[4];if(o===void 0)Y("RETRY",t.name,r),t.apply(null,r);else if(Date.now()-o>=6e4){Y("TIMEOUT",t.name,r);var l=r.pop();typeof l=="function"&&l.call(null,n)}else{var h=Date.now()-u,T=Math.max(u-o,1),I=Math.min(T*1.2,100);h>=I?(Y("RETRY",t.name,r),t.apply(null,r.concat([o]))):O[L].push(e)}ae===void 0&&(ae=setTimeout(xe,0))}}});var tt=k((Mr,et)=>{y();function A(e,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}et.exports=A;A.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};A.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};A.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var r=this._timeouts.shift();if(r===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift();else return!1;var n=this,o=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},r);return this._options.unref&&o.unref(),!0};A.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){r._operationTimeoutCb()},r._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};A.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};A.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};A.prototype.start=A.prototype.try;A.prototype.errors=function(){return this._errors};A.prototype.attempts=function(){return this._attempts};A.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,r=0,n=0;n<this._errors.length;n++){var o=this._errors[n],u=o.message,l=(e[u]||0)+1;e[u]=l,l>=r&&(t=o,r=l)}return t}});var rt=k(K=>{y();var Ct=tt();K.operation=function(e){var t=K.timeouts(e);return new Ct(t,{forever:e&&e.forever,unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})};K.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var r in e)t[r]=e[r];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o<t.retries;o++)n.push(this.createTimeout(o,t));return e&&e.forever&&!n.length&&n.push(this.createTimeout(o,t)),n.sort(function(u,l){return u-l}),n};K.createTimeout=function(e,t){var r=t.randomize?Math.random()+1:1,n=Math.round(r*t.minTimeout*Math.pow(t.factor,e));return n=Math.min(n,t.maxTimeout),n};K.wrap=function(e,t,r){if(t instanceof Array&&(r=t,t=null),!r){r=[];for(var n in e)typeof e[n]=="function"&&r.push(n)}for(var o=0;o<r.length;o++){var u=r[o],l=e[u];e[u]=function(T){var I=K.operation(t),i=Array.prototype.slice.call(arguments,1),m=i.pop();i.push(function(c){I.retry(c)||(c&&(arguments[0]=I.mainError()),m.apply(this,arguments))}),I.attempt(function(){T.apply(e,i)})}.bind(e,l),e[u].options=t}}});var it=k((Lr,nt)=>{y();nt.exports=rt()});var ot=k((Cr,fe)=>{y();fe.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&fe.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&fe.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var st=k((jr,H)=>{y();var _=globalThis.process,z=function(e){return e&&typeof e=="object"&&typeof e.removeListener=="function"&&typeof e.emit=="function"&&typeof e.reallyExit=="function"&&typeof e.listeners=="function"&&typeof e.kill=="function"&&typeof e.pid=="number"&&typeof e.on=="function"};z(_)?(ut=U("assert"),J=ot(),at=/^win/i.test(_.platform),ee=U("events"),typeof ee!="function"&&(ee=ee.EventEmitter),_.__signal_exit_emitter__?M=_.__signal_exit_emitter__:(M=_.__signal_exit_emitter__=new ee,M.count=0,M.emitted={}),M.infinite||(M.setMaxListeners(1/0),M.infinite=!0),H.exports=function(e,t){if(!z(globalThis.process))return function(){};ut.equal(typeof e,"function","a callback must be provided for exit handler"),X===!1&&Ie();var r="exit";t&&t.alwaysLast&&(r="afterexit");var n=function(){M.removeListener(r,e),M.listeners("exit").length===0&&M.listeners("afterexit").length===0&&se()};return M.on(r,e),n},se=function(){!X||!z(globalThis.process)||(X=!1,J.forEach(function(t){try{_.removeListener(t,le[t])}catch{}}),_.emit=me,_.reallyExit=be,M.count-=1)},H.exports.unload=se,B=function(t,r,n){M.emitted[t]||(M.emitted[t]=!0,M.emit(t,r,n))},le={},J.forEach(function(e){le[e]=function(){if(z(globalThis.process)){var r=_.listeners(e);r.length===M.count&&(se(),B("exit",null,e),B("afterexit",null,e),at&&e==="SIGHUP"&&(e="SIGINT"),_.kill(_.pid,e))}}}),H.exports.signals=function(){return J},X=!1,Ie=function(){X||!z(globalThis.process)||(X=!0,M.count+=1,J=J.filter(function(t){try{return _.on(t,le[t]),!0}catch{return!1}}),_.emit=ft,_.reallyExit=ct)},H.exports.load=Ie,be=_.reallyExit,ct=function(t){z(globalThis.process)&&(_.exitCode=t||0,B("exit",_.exitCode,null),B("afterexit",_.exitCode,null),be.call(_,_.exitCode))},me=_.emit,ft=function(t,r){if(t==="exit"&&z(globalThis.process)){r!==void 0&&(_.exitCode=r);var n=me.apply(this,arguments);return B("exit",_.exitCode,null),B("afterexit",_.exitCode,null),n}else return me.apply(this,arguments)}):H.exports=function(){return function(){}};var ut,J,at,ee,M,se,B,le,X,Ie,be,ct,me,ft});var mt=k((Gr,Me)=>{"use strict";y();var lt=Symbol();function kt(e,t,r){let n=t[lt];if(n)return t.stat(e,(u,l)=>{if(u)return r(u);r(null,l.mtime,n)});let o=new Date(Math.ceil(Date.now()/1e3)*1e3+5);t.utimes(e,o,o,u=>{if(u)return r(u);t.stat(e,(l,h)=>{if(l)return r(l);let T=h.mtime.getTime()%1e3===0?"s":"ms";Object.defineProperty(t,lt,{value:T}),r(null,h.mtime,T)})})}function jt(e){let t=Date.now();return e==="s"&&(t=Math.ceil(t/1e3)*1e3),new Date(t)}Me.exports.probe=kt;Me.exports.getMtime=jt});var vt=k((Ur,re)=>{"use strict";y();var At=U("path"),Ne=Fe(),Gt=it(),qt=st(),ht=mt(),q={};function te(e,t){return t.lockfilePath||`${e}.lock`}function Le(e,t,r){if(!t.realpath)return r(null,At.resolve(e));t.fs.realpath(e,r)}function Pe(e,t,r){let n=te(e,t);t.fs.mkdir(n,o=>{if(!o)return ht.probe(n,t.fs,(u,l,h)=>{if(u)return t.fs.rmdir(n,()=>{}),r(u);r(null,l,h)});if(o.code!=="EEXIST")return r(o);if(t.stale<=0)return r(Object.assign(new Error("Lock file is already being held"),{code:"ELOCKED",file:e}));t.fs.stat(n,(u,l)=>{if(u)return u.code==="ENOENT"?Pe(e,{...t,stale:0},r):r(u);if(!pt(l,t))return r(Object.assign(new Error("Lock file is already being held"),{code:"ELOCKED",file:e}));dt(e,t,h=>{if(h)return r(h);Pe(e,{...t,stale:0},r)})})})}function pt(e,t){return e.mtime.getTime()<Date.now()-t.stale}function dt(e,t,r){t.fs.rmdir(te(e,t),n=>{if(n&&n.code!=="ENOENT")return r(n);r()})}function he(e,t){let r=q[e];r.updateTimeout||(r.updateDelay=r.updateDelay||t.update,r.updateTimeout=setTimeout(()=>{r.updateTimeout=null,t.fs.stat(r.lockfilePath,(n,o)=>{let u=r.lastUpdate+t.stale<Date.now();if(n)return n.code==="ENOENT"||u?De(e,r,Object.assign(n,{code:"ECOMPROMISED"})):(r.updateDelay=1e3,he(e,t));if(!(r.mtime.getTime()===o.mtime.getTime()))return De(e,r,Object.assign(new Error("Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"}));let h=ht.getMtime(r.mtimePrecision);t.fs.utimes(r.lockfilePath,h,h,T=>{let I=r.lastUpdate+t.stale<Date.now();if(!r.released){if(T)return T.code==="ENOENT"||I?De(e,r,Object.assign(T,{code:"ECOMPROMISED"})):(r.updateDelay=1e3,he(e,t));r.mtime=h,r.lastUpdate=Date.now(),r.updateDelay=null,he(e,t)}})})},r.updateDelay),r.updateTimeout.unref&&r.updateTimeout.unref())}function De(e,t,r){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),q[e]===t&&delete q[e],t.options.onCompromised(r)}function Ut(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:Ne,onCompromised:n=>{throw n},...t},t.retries=t.retries||0,t.retries=typeof t.retries=="number"?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),Le(e,t,(n,o)=>{if(n)return r(n);let u=Gt.operation(t.retries);u.attempt(()=>{Pe(o,t,(l,h,T)=>{if(u.retry(l))return;if(l)return r(u.mainError());let I=q[o]={lockfilePath:te(o,t),mtime:h,mtimePrecision:T,options:t,lastUpdate:Date.now()};he(o,t),r(null,i=>{if(I.released)return i&&i(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));yt(o,{...t,realpath:!1},i)})})})})}function yt(e,t,r){t={fs:Ne,realpath:!0,...t},Le(e,t,(n,o)=>{if(n)return r(n);let u=q[o];if(!u)return r(Object.assign(new Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));u.updateTimeout&&clearTimeout(u.updateTimeout),u.released=!0,delete q[o],dt(o,t,r)})}function $t(e,t,r){t={stale:1e4,realpath:!0,fs:Ne,...t},t.stale=Math.max(t.stale||0,2e3),Le(e,t,(n,o)=>{if(n)return r(n);t.fs.stat(te(o,t),(u,l)=>u?u.code==="ENOENT"?r(null,!1):r(u):r(null,!pt(l,t)))})}function Wt(){return q}qt(()=>{for(let e in q){let t=q[e].options;try{t.fs.rmdirSync(te(e,t))}catch{}}});re.exports.lock=Ut;re.exports.unlock=yt;re.exports.check=$t;re.exports.getLocks=Wt});var wt=k((Wr,St)=>{"use strict";y();var Yt=Fe();function Kt(e){let t=["mkdir","realpath","stat","rmdir","utimes"],r={...e};return t.forEach(n=>{r[n]=(...o)=>{let u=o.pop(),l;try{l=e[`${n}Sync`](...o)}catch(h){return u(h)}u(null,l)}}),r}function zt(e){return(...t)=>new Promise((r,n)=>{t.push((o,u)=>{o?n(o):r(u)}),e(...t)})}function Bt(e){return(...t)=>{let r,n;if(t.push((o,u)=>{r=o,n=u}),e(...t),r)throw r;return n}}function Qt(e){if(e={...e},e.fs=Kt(e.fs||Yt),typeof e.retries=="number"&&e.retries>0||e.retries&&typeof e.retries.retries=="number"&&e.retries.retries>0)throw Object.assign(new Error("Cannot use retries with the sync api"),{code:"ESYNC"});return e}St.exports={toPromise:zt,toSync:Bt,toSyncOptions:Qt}});var er=k((Kr,W)=>{"use strict";y();var V=vt(),{toPromise:pe,toSync:de,toSyncOptions:Re}=wt();async function gt(e,t){let r=await pe(V.lock)(e,t);return pe(r)}function Jt(e,t){let r=de(V.lock)(e,Re(t));return de(r)}function Xt(e,t){return pe(V.unlock)(e,t)}function Ht(e,t){return de(V.unlock)(e,Re(t))}function Vt(e,t){return pe(V.check)(e,t)}function Zt(e,t){return de(V.check)(e,Re(t))}W.exports=gt;W.exports.lock=gt;W.exports.unlock=Xt;W.exports.lockSync=Jt;W.exports.unlockSync=Ht;W.exports.check=Vt;W.exports.checkSync=Zt});y();import*as j from"node:fs/promises";import*as G from"node:path";function We(){return G.join(Se.getGlobalMatildaDir(),Ae)}function ge(e){return G.join(We(),e)}function _e(e){return G.join(ge(e),qe)}function ur(e){return G.join(ge(e),Ue)}function Tt(e){return G.join(Se.getGlobalMatildaDir(),Ge,e)}function ie(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function ar(e,t){return`${ie(e)}@${ie(t)}`}function cr(e,t){let r=ie(e);if(!r)throw new Error(`Teammate name "${e}" sanitizes to an empty string. Choose a name with at least one alphanumeric character.`);if(r===we)throw new Error(`"${we}" is reserved for the team leader. Choose a different teammate name.`);let n=new Set(t.map(o=>o.name));if(n.has(r)){let o=[...n].join(", ")||"<none>";throw new Error(`A teammate named "${r}" already exists in this team (existing: ${o}). Choose a different name.`)}return r}function fr(e){let t=new Set(e.map(r=>r.color).filter(r=>r!==void 0));for(let r of ne)if(!t.has(r))return r;return ne[e.length%ne.length]}function sr(e){return e.map(t=>{let{color:r,...n}=t;return n})}function lr(e,t,r){return e.map(n=>n.agentId===t?{...n,isActive:r}:n)}function mr(e,t){return e.find(r=>r.agentId===t)}function hr(e,t){let r=ie(t);return e.find(n=>n.name===r)}function pr(e){let t=e.trimStart();if(/^shutdown_approved\b/i.test(t))return"shutdown_approved";if(/^shutdown_rejected\b/i.test(t))return"shutdown_rejected"}async function Et(e){let t=_e(e);try{let r=await j.readFile(t,"utf-8");return JSON.parse(r)}catch(r){if(ve(r)&&r.code==="ENOENT")return;throw r}}async function dr(e,t){let r=_e(e);await j.mkdir(G.dirname(r),{recursive:!0}),await je(r,t)}async function yr(e,t){let r=_e(e);await j.mkdir(G.dirname(r),{recursive:!0}),await j.writeFile(r,JSON.stringify(t,null,2)+`
5
5
  `,{encoding:"utf-8",flag:"wx"})}function xt(e){try{return process.kill(e,0),!0}catch(t){return ve(t)&&t.code==="EPERM"}}async function vr(e){let t;try{t=await Et(e)}catch{return!1}return t?typeof t.leadPid!="number"||t.leadPid<=0||t.leadPid!==process.pid&&xt(t.leadPid)?!1:(await $e(e),!0):(await $e(e),!0)}async function $e(e){let t=ge(e),r=Tt(e);await Promise.allSettled([j.rm(t,{recursive:!0,force:!0}),j.rm(r,{recursive:!0,force:!0})])}async function Sr(){let e=We();try{return(await j.readdir(e,{withFileTypes:!0})).filter(r=>r.isDirectory()).map(r=>r.name)}catch{return[]}}export{We as a,ge as b,_e as c,ur as d,Tt as e,ie as f,ar as g,cr as h,fr as i,sr as j,lr as k,mr as l,hr as m,pr as n,Et as o,dr as p,yr as q,vr as r,$e as s,Sr as t,Fe as u,er as v};
6
6
  /**