@legit-sdk/core 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ gpgsig`+av(o)+`
84
84
  `,author:h,committer:c,signingKey:d})}i(nQ,"_addNote");async function TB({fs:e,onSign:t,dir:r,gitdir:n=Re(r,".git"),ref:a="refs/notes/commits",oid:s,note:o,force:f,author:h,committer:c,signingKey:d,cache:p={}}){try{ae("fs",e),ae("gitdir",n),ae("oid",s),ae("note",o),d&&ae("onSign",t);let m=new Le(e),g=await Co({fs:m,gitdir:n,author:h});if(!g)throw new ur("author");let b=await bl({fs:m,gitdir:n,author:g,committer:c});if(!b)throw new ur("committer");return await nQ({fs:new Le(m),cache:p,onSign:t,gitdir:n,ref:a,oid:s,note:o,force:f,author:g,committer:b,signingKey:d})}catch(m){throw m.caller="git.addNote",m}}i(TB,"addNote");var iQ=/(^|[/.])([/.]|$)|^@$|@{|[\x00-\x20\x7f~^:?*[\\]|\.lock(\/|$)/;function Iu(e,t){if(typeof e!="string")throw new TypeError("Reference name must be a string");return!iQ.test(e)&&(!!t||e.includes("/"))}i(Iu,"isValidRef");async function FB({fs:e,gitdir:t,remote:r,url:n,force:a}){if(!Iu(r,!0))throw new Tn(r,hu.clean(r));let s=await xt.get({fs:e,gitdir:t});if(!a&&(await s.getSubsections("remote")).includes(r)&&n!==await s.get(`remote.${r}.url`))throw new Rn("remote",r);await s.set(`remote.${r}.url`,n),await s.set(`remote.${r}.fetch`,`+refs/heads/*:refs/remotes/${r}/*`),await xt.save({fs:e,gitdir:t,config:s})}i(FB,"_addRemote");async function xB({fs:e,dir:t,gitdir:r=Re(t,".git"),remote:n,url:a,force:s=!1}){try{return ae("fs",e),ae("gitdir",r),ae("remote",n),ae("url",a),await FB({fs:new Le(e),gitdir:r,remote:n,url:a,force:s})}catch(o){throw o.caller="git.addRemote",o}}i(xB,"addRemote");async function oQ({fs:e,cache:t,onSign:r,gitdir:n,ref:a,tagger:s,message:o=a,gpgsig:f,object:h,signingKey:c,force:d=!1}){if(a=a.startsWith("refs/tags/")?a:`refs/tags/${a}`,!d&&await Pe.exists({fs:e,gitdir:n,ref:a}))throw new Rn("tag",a);let p=await Pe.resolve({fs:e,gitdir:n,ref:h||"HEAD"}),{type:m}=await dt({fs:e,cache:t,gitdir:n,oid:p}),g=zr.from({object:p,type:m,tag:a.replace("refs/tags/",""),tagger:s,message:o,gpgsig:f});c&&(g=await zr.sign(g,r,c));let b=await Br({fs:e,gitdir:n,type:"tag",object:g.toObject()});await Pe.writeRef({fs:e,gitdir:n,ref:a,value:b})}i(oQ,"_annotatedTag");async function OB({fs:e,onSign:t,dir:r,gitdir:n=Re(r,".git"),ref:a,tagger:s,message:o=a,gpgsig:f,object:h,signingKey:c,force:d=!1,cache:p={}}){try{ae("fs",e),ae("gitdir",n),ae("ref",a),c&&ae("onSign",t);let m=new Le(e),g=await Co({fs:m,gitdir:n,author:s});if(!g)throw new ur("tagger");return await oQ({fs:m,cache:p,onSign:t,gitdir:n,ref:a,tagger:g,message:o,gpgsig:f,object:h,signingKey:c,force:d})}catch(m){throw m.caller="git.annotatedTag",m}}i(OB,"annotatedTag");async function aQ({fs:e,gitdir:t,ref:r,object:n,checkout:a=!1,force:s=!1}){if(!Iu(r,!0))throw new Tn(r,hu.clean(r));let o=`refs/heads/${r}`;if(!s&&await Pe.exists({fs:e,gitdir:t,ref:o}))throw new Rn("branch",r,!1);let f;try{f=await Pe.resolve({fs:e,gitdir:t,ref:n||"HEAD"})}catch{}f&&await Pe.writeRef({fs:e,gitdir:t,ref:o,value:f}),a&&await Pe.writeSymbolicRef({fs:e,gitdir:t,ref:"HEAD",value:o})}i(aQ,"_branch");async function IB({fs:e,dir:t,gitdir:r=Re(t,".git"),ref:n,object:a,checkout:s=!1,force:o=!1}){try{return ae("fs",e),ae("gitdir",r),ae("ref",n),await aQ({fs:new Le(e),gitdir:r,ref:n,object:a,checkout:s,force:o})}catch(f){throw f.caller="git.branch",f}}i(IB,"branch");var PB=i((e,t)=>e==="."||t==null||t.length===0||t==="."?!0:t.length>=e.length?t.startsWith(e):e.startsWith(t),"worthWalking");async function Fv({fs:e,cache:t,onProgress:r,onPostCheckout:n,dir:a,gitdir:s,remote:o,ref:f,filepaths:h,noCheckout:c,noUpdateHead:d,dryRun:p,force:m,track:g=!0,nonBlocking:b=!1,batchSize:v=100}){let _;if(n)try{_=await Pe.resolve({fs:e,gitdir:s,ref:"HEAD"})}catch{_="0000000000000000000000000000000000000000"}let E;try{E=await Pe.resolve({fs:e,gitdir:s,ref:f})}catch(R){if(f==="HEAD")throw R;let T=`${o}/${f}`;if(E=await Pe.resolve({fs:e,gitdir:s,ref:T}),g){let F=await xt.get({fs:e,gitdir:s});await F.set(`branch.${f}.remote`,o),await F.set(`branch.${f}.merge`,`refs/heads/${f}`),await xt.save({fs:e,gitdir:s,config:F})}await Pe.writeRef({fs:e,gitdir:s,ref:`refs/heads/${f}`,value:E})}if(!c){let R;try{R=await sQ({fs:e,cache:t,onProgress:r,dir:a,gitdir:s,ref:f,force:m,filepaths:h})}catch(I){throw I instanceof st&&I.data.what===E?new wu(f,E):I}let T=R.filter(([I])=>I==="conflict").map(([I,D])=>D);if(T.length>0)throw new gu(T);let F=R.filter(([I])=>I==="error").map(([I,D])=>D);if(F.length>0)throw new Ue(F.join(", "));if(p){n&&await n({previousHead:_,newHead:E,type:h!=null&&h.length>0?"file":"branch"});return}let S=0,k=R.length;if(await It.acquire({fs:e,gitdir:s,cache:t},async function(I){await Promise.all(R.filter(([D])=>D==="delete"||D==="delete-index").map(async function([D,L]){let C=`${a}/${L}`;D==="delete"&&await e.rm(C),I.delete({filepath:L}),r&&await r({phase:"Updating workdir",loaded:++S,total:k})}))}),await It.acquire({fs:e,gitdir:s,cache:t},async function(I){for(let[D,L]of R)if(D==="rmdir"||D==="rmdir-index"){let C=`${a}/${L}`;try{D==="rmdir"&&await e.rmdir(C),I.delete({filepath:L}),r&&await r({phase:"Updating workdir",loaded:++S,total:k})}catch(j){if(j.code==="ENOTEMPTY")console.log(`Did not delete ${L} because directory is not empty`);else throw j}}}),await Promise.all(R.filter(([I])=>I==="mkdir"||I==="mkdir-index").map(async function([I,D]){let L=`${a}/${D}`;await e.mkdir(L),r&&await r({phase:"Updating workdir",loaded:++S,total:k})})),b){let I=R.filter(([L])=>L==="create"||L==="create-index"||L==="update"||L==="mkdir-index"),D=await Zk("Update Working Dir",I.map(([L,C,j,q,J])=>()=>fQ({fs:e,cache:t,gitdir:s,dir:a},[L,C,j,q,J])),r,v);await It.acquire({fs:e,gitdir:s,cache:t,allowUnmerged:!0},async function(L){await Zk("Update Index",D.map(([C,j,q])=>()=>lQ({index:L,fullpath:C,oid:j,stats:q})),r,v)})}else await It.acquire({fs:e,gitdir:s,cache:t,allowUnmerged:!0},async function(I){await Promise.all(R.filter(([D])=>D==="create"||D==="create-index"||D==="update"||D==="mkdir-index").map(async function([D,L,C,j,q]){let J=`${a}/${L}`;try{if(D!=="create-index"&&D!=="mkdir-index"){let{object:se}=await dt({fs:e,cache:t,gitdir:s,oid:C});if(q&&await e.rm(J),j===33188)await e.write(J,se);else if(j===33261)await e.write(J,se,{mode:511});else if(j===40960)await e.writelink(J,se);else throw new Ue(`Invalid mode 0o${j.toString(8)} detected in blob ${C}`)}let K=await e.lstat(J);j===33261&&(K.mode=493),D==="mkdir-index"&&(K.mode=57344),I.insert({filepath:L,stats:K,oid:C}),r&&await r({phase:"Updating workdir",loaded:++S,total:k})}catch(K){console.log(K)}}))});n&&await n({previousHead:_,newHead:E,type:h!=null&&h.length>0?"file":"branch"})}if(!d){let R=await Pe.expand({fs:e,gitdir:s,ref:f});R.startsWith("refs/heads")?await Pe.writeSymbolicRef({fs:e,gitdir:s,ref:"HEAD",value:R}):await Pe.writeRef({fs:e,gitdir:s,ref:"HEAD",value:E})}}i(Fv,"_checkout");async function sQ({fs:e,cache:t,onProgress:r,dir:n,gitdir:a,ref:s,force:o,filepaths:f}){let h=0;return ko({fs:e,cache:t,dir:n,gitdir:a,trees:[qr({ref:s}),Al(),Ba()],map:i(async function(c,[d,p,m]){if(c===".")return;if(f&&!f.some(b=>PB(c,b)))return null;switch(r&&await r({phase:"Analyzing workdir",loaded:++h}),[!!m,!!d,!!p].map(Number).join("")){case"000":return;case"001":return o&&f&&f.includes(c)?["delete",c]:void 0;case"010":switch(await d.type()){case"tree":return["mkdir",c];case"blob":return["create",c,await d.oid(),await d.mode()];case"commit":return["mkdir-index",c,await d.oid(),await d.mode()];default:return["error",`new entry Unhandled type ${await d.type()}`]}case"011":switch(`${await d.type()}-${await p.type()}`){case"tree-tree":return;case"tree-blob":case"blob-tree":return["conflict",c];case"blob-blob":return await d.oid()!==await p.oid()?o?["update",c,await d.oid(),await d.mode(),await d.mode()!==await p.mode()]:["conflict",c]:await d.mode()!==await p.mode()?o?["update",c,await d.oid(),await d.mode(),!0]:["conflict",c]:["create-index",c,await d.oid(),await d.mode()];case"commit-tree":return;case"commit-blob":return["conflict",c];default:return["error",`new entry Unhandled type ${d.type}`]}case"100":return["delete-index",c];case"101":switch(await m.type()){case"tree":return["rmdir-index",c];case"blob":return await m.oid()!==await p.oid()?o?["delete",c]:["conflict",c]:["delete",c];case"commit":return["rmdir-index",c];default:return["error",`delete entry Unhandled type ${await m.type()}`]}case"110":case"111":switch(`${await m.type()}-${await d.type()}`){case"tree-tree":return;case"blob-blob":{if(await m.oid()===await d.oid()&&await m.mode()===await d.mode()&&!o)return;if(p){if(await p.oid()!==await m.oid()&&await p.oid()!==await d.oid())return o?["update",c,await d.oid(),await d.mode(),await d.mode()!==await p.mode()]:["conflict",c]}else if(o)return["update",c,await d.oid(),await d.mode(),await d.mode()!==await m.mode()];return await d.mode()!==await m.mode()?["update",c,await d.oid(),await d.mode(),!0]:await d.oid()!==await m.oid()?["update",c,await d.oid(),await d.mode(),!1]:void 0}case"tree-blob":return["update-dir-to-blob",c,await d.oid()];case"blob-tree":return["update-blob-to-tree",c];case"commit-commit":return["mkdir-index",c,await d.oid(),await d.mode()];default:return["error",`update entry Unhandled type ${await m.type()}-${await d.type()}`]}}},"map"),reduce:i(async function(c,d){return d=gB(d),c?c&&c[0]==="rmdir"?(d.push(c),d):(d.unshift(c),d):d},"reduce")})}i(sQ,"analyze");async function lQ({index:e,fullpath:t,stats:r,oid:n}){try{e.insert({filepath:t,stats:r,oid:n})}catch(a){console.warn(`Error inserting ${t} into index:`,a)}}i(lQ,"updateIndex");async function fQ({fs:e,cache:t,gitdir:r,dir:n},[a,s,o,f,h]){let c=`${n}/${s}`;if(a!=="create-index"&&a!=="mkdir-index"){let{object:p}=await dt({fs:e,cache:t,gitdir:r,oid:o});if(h&&await e.rm(c),f===33188)await e.write(c,p);else if(f===33261)await e.write(c,p,{mode:511});else if(f===40960)await e.writelink(c,p);else throw new Ue(`Invalid mode 0o${f.toString(8)} detected in blob ${o}`)}let d=await e.lstat(c);return f===33261&&(d.mode=493),a==="mkdir-index"&&(d.mode=57344),[s,o,d]}i(fQ,"updateWorkingDir");async function Zk(e,t,r,n){let a=[];try{for(let s=0;s<t.length;s+=n){let o=t.slice(s,s+n).map(h=>h());(await Promise.allSettled(o)).forEach(h=>{h.status==="fulfilled"&&a.push(h.value)}),r&&await r({phase:"Updating workdir",loaded:s+o.length,total:t.length})}return a}catch(s){console.error(`Error during ${e}: ${s}`)}return a}i(Zk,"batchAllSettled");async function xv({fs:e,onProgress:t,onPostCheckout:r,dir:n,gitdir:a=Re(n,".git"),remote:s="origin",ref:o,filepaths:f,noCheckout:h=!1,noUpdateHead:c=o===void 0,dryRun:d=!1,force:p=!1,track:m=!0,cache:g={},nonBlocking:b=!1,batchSize:v=100}){try{ae("fs",e),ae("dir",n),ae("gitdir",a);let _=o||"HEAD";return await Fv({fs:new Le(e),cache:g,onProgress:t,onPostCheckout:r,dir:n,gitdir:a,remote:s,ref:_,filepaths:f,noCheckout:h,noUpdateHead:c,dryRun:d,force:p,track:m,nonBlocking:b,batchSize:v})}catch(_){throw _.caller="git.checkout",_}}i(xv,"checkout");var uQ=/^refs\/(heads\/|tags\/|remotes\/)?(.*)/;function Oa(e){let t=uQ.exec(e);return t?t[1]==="remotes/"&&e.endsWith("/HEAD")?t[2].slice(0,-5):t[2]:e}i(Oa,"abbreviateRef");async function Do({fs:e,gitdir:t,fullname:r=!1,test:n=!1}){let a=await Pe.resolve({fs:e,gitdir:t,ref:"HEAD",depth:2});if(n)try{await Pe.resolve({fs:e,gitdir:t,ref:a})}catch{return}if(a.startsWith("refs/"))return r?a:Oa(a)}i(Do,"_currentBranch");function cQ(e){return e=e.replace(/^git@([^:]+):/,"https://$1/"),e=e.replace(/^ssh:\/\//,"https://"),e}i(cQ,"translateSSHtoHTTP");function kB({username:e="",password:t=""}){return`Basic ${Buffer.from(`${e}:${t}`).toString("base64")}`}i(kB,"calculateBasicAuthHeader");async function Bu(e,t){let r=pB(e);for(;;){let{value:n,done:a}=await r.next();if(n&&await t(n),a)break}r.return&&r.return()}i(Bu,"forAwait");async function kd(e){let t=0,r=[];await Bu(e,s=>{r.push(s),t+=s.byteLength});let n=new Uint8Array(t),a=0;for(let s of r)n.set(s,a),a+=s.byteLength;return n}i(kd,"collect");function Qk(e){let t=e.match(/^https?:\/\/([^/]+)@/);if(t==null)return{url:e,auth:{}};t=t[1];let[r,n]=t.split(":");return e=e.replace(`${t}@`,""),{url:e,auth:{username:r,password:n}}}i(Qk,"extractAuthFromUrl");function Av(e,t){let r=t.toString(16);return"0".repeat(e-r.length)+r}i(Av,"padHex");var Hv=class Hv{static flush(){return Buffer.from("0000","utf8")}static delim(){return Buffer.from("0001","utf8")}static encode(t){typeof t=="string"&&(t=Buffer.from(t));let r=t.length+4,n=Av(4,r);return Buffer.concat([Buffer.from(n,"utf8"),t])}static streamReader(t){let r=new Od(t);return i(async function(){try{let a=await r.read(4);if(a==null)return!0;if(a=parseInt(a.toString("utf8"),16),a===0||a===1)return null;let s=await r.read(a-4);return s??!0}catch(a){return t.error=a,!0}},"read")}};i(Hv,"GitPktLine");var bt=Hv;async function eB(e){let t={},r;for(;r=await e(),r!==!0;){if(r===null)continue;r=r.toString("utf8").replace(/\n$/,"");let n=r.indexOf("=");if(n>-1){let a=r.slice(0,n),s=r.slice(n+1);t[a]=s}else t[r]=!0}return{protocolVersion:2,capabilities2:t}}i(eB,"parseCapabilitiesV2");async function tB(e,{service:t}){let r=new Set,n=new Map,a=new Map,s=bt.streamReader(e),o=await s();for(;o===null;)o=await s();if(o===!0)throw new bu;if(o.includes("version 2"))return eB(s);if(o.toString("utf8").replace(/\n$/,"")!==`# service=${t}`)throw new Ia(`# service=${t}\\n`,o.toString("utf8"));let f=await s();for(;f===null;)f=await s();if(f===!0)return{capabilities:r,refs:n,symrefs:a};if(f=f.toString("utf8"),f.includes("version 2"))return eB(s);let[h,c]=lv(f,"\0","\\x00");if(c.split(" ").map(d=>r.add(d)),h!=="0000000000000000000000000000000000000000 capabilities^{}"){let[d,p]=lv(h," "," ");for(n.set(p,d);;){let m=await s();if(m===!0)break;if(m!==null){let[g,b]=lv(m.toString("utf8")," "," ");n.set(b,g)}}}for(let d of r)if(d.startsWith("symref=")){let p=d.match(/symref=([^:]+):(.*)/);p.length===3&&a.set(p[1],p[2])}return{protocolVersion:1,capabilities:r,refs:n,symrefs:a}}i(tB,"parseRefsAdResponse");function lv(e,t,r){let n=e.trim().split(t);if(n.length!==2)throw new Ia(`Two strings separated by '${r}'`,e.toString("utf8"));return n}i(lv,"splitAndAssert");var rB=i((e,t)=>e.endsWith("?")?`${e}${t}`:`${e}/${t.replace(/^https?:\/\//,"")}`,"corsProxify"),nB=i((e,t)=>{(t.username||t.password)&&(e.Authorization=kB(t)),t.headers&&Object.assign(e,t.headers)},"updateHeaders"),fv=i(async e=>{try{let t=Buffer.from(await kd(e.body)),r=t.toString("utf8");return{preview:r.length<256?r:r.slice(0,256)+"...",response:r,data:t}}catch{return{}}},"stringifyBody"),qv=class qv{static async capabilities(){return["discover","connect"]}static async discover({http:t,onProgress:r,onAuth:n,onAuthSuccess:a,onAuthFailure:s,corsProxy:o,service:f,url:h,headers:c,protocolVersion:d}){let{url:p,auth:m}=Qk(h),g=o?rB(o,p):p;(m.username||m.password)&&(c.Authorization=kB(m)),d===2&&(c["Git-Protocol"]="version=2");let b,v,_=!1;do if(b=await t.request({onProgress:r,method:"GET",url:`${g}/info/refs?service=${f}`,headers:c}),v=!1,b.statusCode===401||b.statusCode===203){let E=_?s:n;if(E){if(m=await E(p,{...m,headers:{...c}}),m&&m.cancel)throw new gl;m&&(nB(c,m),_=!0,v=!0)}}else b.statusCode===200&&_&&a&&await a(p,m);while(v);if(b.statusCode!==200){let{response:E}=await fv(b);throw new dl(b.statusCode,b.statusMessage,E)}if(b.headers["content-type"]===`application/x-${f}-advertisement`){let E=await tB(b.body,{service:f});return E.auth=m,E}else{let{preview:E,response:R,data:T}=await fv(b);try{let F=await tB([T],{service:f});return F.auth=m,F}catch{throw new Au(E,R)}}}static async connect({http:t,onProgress:r,corsProxy:n,service:a,url:s,auth:o,body:f,headers:h}){let c=Qk(s);c&&(s=c.url),n&&(s=rB(n,s)),h["content-type"]=`application/x-${a}-request`,h.accept=`application/x-${a}-result`,nB(h,o);let d=await t.request({onProgress:r,method:"POST",url:`${s}/${a}`,body:f,headers:h});if(d.statusCode!==200){let{response:p}=fv(d);throw new dl(d.statusCode,d.statusMessage,p)}return d}};i(qv,"GitRemoteHTTP");var _l=qv,zv=class zv{static getRemoteHelperFor({url:t}){let r=new Map;r.set("http",_l),r.set("https",_l);let n=hQ({url:t});if(!n)throw new Tu(t);if(r.has(n.transport))return r.get(n.transport);throw new Ru(t,n.transport,n.transport==="ssh"?cQ(t):void 0)}};i(zv,"GitRemoteManager");var El=zv;function hQ({url:e}){if(e.startsWith("git@"))return{transport:"ssh",address:e};let t=e.match(/(\w+)(:\/\/|::)(.*)/);if(t!==null){if(t[2]==="://")return{transport:t[1],address:t[0]};if(t[2]==="::")return{transport:t[1],address:t[3]}}}i(hQ,"parseRemoteUrl");var xa=null,Vv=class Vv{static async read({fs:t,gitdir:r}){xa===null&&(xa=new cu);let n=Re(r,"shallow"),a=new Set;return await xa.acquire(n,async function(){let s=await t.read(n,{encoding:"utf8"});if(s===null||s.trim()==="")return a;s.trim().split(`
85
85
  `).map(o=>a.add(o))}),a}static async write({fs:t,gitdir:r,oids:n}){xa===null&&(xa=new cu);let a=Re(r,"shallow");if(n.size>0){let s=[...n].join(`
86
86
  `)+`
87
- `;await xa.acquire(a,async function(){await t.write(a,s,{encoding:"utf8"})})}else await xa.acquire(a,async function(){await t.rm(a)})}};i(Vv,"GitShallowManager");var Pa=Vv;async function dQ({fs:e,gitdir:t,oid:r}){let n=`objects/${r.slice(0,2)}/${r.slice(2)}`;return e.exists(`${t}/${n}`)}i(dQ,"hasObjectLoose");async function pQ({fs:e,cache:t,gitdir:r,oid:n,getExternalRefDelta:a}){let s=await e.readdir(Re(r,"objects/pack"));s=s.filter(o=>o.endsWith(".idx"));for(let o of s){let f=`${r}/objects/pack/${o}`,h=await Tv({fs:e,cache:t,filename:f,getExternalRefDelta:a});if(h.error)throw new Ue(h.error);if(h.offsets.has(n))return!0}return!1}i(pQ,"hasObjectPacked");async function iB({fs:e,cache:t,gitdir:r,oid:n,format:a="content"}){let s=i(f=>dt({fs:e,cache:t,gitdir:r,oid:f}),"getExternalRefDelta"),o=await dQ({fs:e,gitdir:r,oid:n});return o||(o=await pQ({fs:e,cache:t,gitdir:r,oid:n,getExternalRefDelta:s})),o}i(iB,"hasObject");function yQ(e){let a="5041434b"+"00000002"+"00000000";return e.slice(0,12).toString("hex")===a}i(yQ,"emptyPackfile");function BB(e,t){let r=e.map(n=>n.split("=",1)[0]);return t.filter(n=>{let a=n.split("=",1)[0];return r.includes(a)})}i(BB,"filterCapabilities");var Sp={name:"isomorphic-git",version:"0.0.0-development",agent:"git/isomorphic-git@0.0.0-development"},Gv=class Gv{constructor(){this._queue=[]}write(t){if(this._ended)throw Error("You cannot write to a FIFO that has already been ended!");if(this._waiting){let r=this._waiting;this._waiting=null,r({value:t})}else this._queue.push(t)}end(){if(this._ended=!0,this._waiting){let t=this._waiting;this._waiting=null,t({done:!0})}}destroy(t){this.error=t,this.end()}async next(){if(this._queue.length>0)return{value:this._queue.shift()};if(this._ended)return{done:!0};if(this._waiting)throw Error("You cannot call read until the previous call to read has returned!");return new Promise(t=>{this._waiting=t})}};i(Gv,"FIFO");var fl=Gv;function mQ(e){let t=e.indexOf("\r"),r=e.indexOf(`
87
+ `;await xa.acquire(a,async function(){await t.write(a,s,{encoding:"utf8"})})}else await xa.acquire(a,async function(){await t.rm(a)})}};i(Vv,"GitShallowManager");var Pa=Vv;async function dQ({fs:e,gitdir:t,oid:r}){let n=`objects/${r.slice(0,2)}/${r.slice(2)}`;return e.exists(`${t}/${n}`)}i(dQ,"hasObjectLoose");async function pQ({fs:e,cache:t,gitdir:r,oid:n,getExternalRefDelta:a}){let s=await e.readdir(Re(r,"objects/pack"));s=s.filter(o=>o.endsWith(".idx"));for(let o of s){let f=`${r}/objects/pack/${o}`,h=await Tv({fs:e,cache:t,filename:f,getExternalRefDelta:a});if(h.error)throw new Ue(h.error);if(h.offsets.has(n))return!0}return!1}i(pQ,"hasObjectPacked");async function iB({fs:e,cache:t,gitdir:r,oid:n,format:a="content"}){let s=i(f=>dt({fs:e,cache:t,gitdir:r,oid:f}),"getExternalRefDelta"),o=await dQ({fs:e,gitdir:r,oid:n});return o||(o=await pQ({fs:e,cache:t,gitdir:r,oid:n,getExternalRefDelta:s})),o}i(iB,"hasObject");function yQ(e){let a="5041434b"+"00000002"+"00000000";return e.slice(0,12).toString("hex")===a}i(yQ,"emptyPackfile");function BB(e,t){let r=e.map(n=>n.split("=",1)[0]);return t.filter(n=>{let a=n.split("=",1)[0];return r.includes(a)})}i(BB,"filterCapabilities");var Sp={name:"isomorphic-git",version:"1.34.1",agent:"git/isomorphic-git@1.34.1"},Gv=class Gv{constructor(){this._queue=[]}write(t){if(this._ended)throw Error("You cannot write to a FIFO that has already been ended!");if(this._waiting){let r=this._waiting;this._waiting=null,r({value:t})}else this._queue.push(t)}end(){if(this._ended=!0,this._waiting){let t=this._waiting;this._waiting=null,t({done:!0})}}destroy(t){this.error=t,this.end()}async next(){if(this._queue.length>0)return{value:this._queue.shift()};if(this._ended)return{done:!0};if(this._waiting)throw Error("You cannot call read until the previous call to read has returned!");return new Promise(t=>{this._waiting=t})}};i(Gv,"FIFO");var fl=Gv;function mQ(e){let t=e.indexOf("\r"),r=e.indexOf(`
88
88
  `);return t===-1&&r===-1?-1:t===-1?r+1:r===-1?t+1:r===t+1?r+1:Math.min(t,r)+1}i(mQ,"findSplit");function CB(e){let t=new fl,r="";return(async()=>(await Bu(e,n=>{for(n=n.toString("utf8"),r+=n;;){let a=mQ(r);if(a===-1)break;t.write(r.slice(0,a)),r=r.slice(a)}}),r.length>0&&t.write(r),t.end()))(),t}i(CB,"splitLines");var Yv=class Yv{static demux(t){let r=bt.streamReader(t),n=new fl,a=new fl,s=new fl,o=i(async function(){let f=await r();if(f===null)return o();if(f===!0){n.end(),s.end(),t.error?a.destroy(t.error):a.end();return}switch(f[0]){case 1:{a.write(f.slice(1));break}case 2:{s.write(f.slice(1));break}case 3:{let h=f.slice(1);s.write(h),n.end(),s.end(),a.destroy(new Error(h.toString("utf8")));return}default:n.write(f)}o()},"nextBit");return o(),{packetlines:n,packfile:a,progress:s}}};i(Yv,"GitSideBand");var Bd=Yv;async function gQ(e){let{packetlines:t,packfile:r,progress:n}=Bd.demux(e),a=[],s=[],o=[],f=!1,h=!1;return new Promise((c,d)=>{Bu(t,p=>{let m=p.toString("utf8").trim();if(m.startsWith("shallow")){let g=m.slice(-41).trim();g.length!==40&&d(new Oo(g)),a.push(g)}else if(m.startsWith("unshallow")){let g=m.slice(-41).trim();g.length!==40&&d(new Oo(g)),s.push(g)}else if(m.startsWith("ACK")){let[,g,b]=m.split(" ");o.push({oid:g,status:b}),b||(h=!0)}else m.startsWith("NAK")?(f=!0,h=!0):(h=!0,f=!0);h&&(e.error?d(e.error):c({shallows:a,unshallows:s,acks:o,nak:f,packfile:r,progress:n}))}).finally(()=>{h||(e.error?d(e.error):c({shallows:a,unshallows:s,acks:o,nak:f,packfile:r,progress:n}))})})}i(gQ,"parseUploadPackResponse");function wQ({capabilities:e=[],wants:t=[],haves:r=[],shallows:n=[],depth:a=null,since:s=null,exclude:o=[]}){let f=[];t=[...new Set(t)];let h=` ${e.join(" ")}`;for(let c of t)f.push(bt.encode(`want ${c}${h}
89
89
  `)),h="";for(let c of n)f.push(bt.encode(`shallow ${c}
90
90
  `));a!==null&&f.push(bt.encode(`deepen ${a}
@@ -166,7 +166,7 @@ gpgsig`+av(o)+`
166
166
 
167
167
  `;await s.promises.writeFile(t+"/.legit/operation",R+_)}}else console.log("No match"),await a.promises.writeFile(e,n)},"writeFile"),rename:i(async function({filePath:e,newPath:t,gitRoot:r,nodeFs:n,pathParams:a,newPathParams:s,author:o,cacheFs:f}){await f.promises.rename(e,t)},"rename"),mkdir:i(async function(e){await e.cacheFs.promises.mkdir(e.filePath,{recursive:!0})},"mkdir"),rmdir:i(async({filePath:e,gitRoot:t,nodeFs:r,cacheFs:n,pathParams:a,author:s})=>{},"rmdir")};var ps=at(Pt(),1);function gS(e){return e&&e.gitCache!==void 0?e.gitCache:e&&e.parentFs?gS(e.parentFs):{}}i(gS,"getGitCacheFromFs");var KU={type:"gitApplyCurrentChangesToVirtualFile",rootType:"file",getStats:i(async({gitRoot:e,nodeFs:t,pathParams:r,userSpaceFs:n})=>{let a=new Date(0);return{mode:420,size:40,isFile:i(()=>!0,"isFile"),isDirectory:i(()=>!1,"isDirectory"),isSymbolicLink:i(()=>!1,"isSymbolicLink"),isBlockDevice:i(()=>!1,"isBlockDevice"),isCharacterDevice:i(()=>!1,"isCharacterDevice"),isSocket:i(()=>!1,"isSocket"),isFIFO:i(()=>!1,"isFIFO"),isFileSync:i(()=>!0,"isFileSync"),isDirectorySync:i(()=>!1,"isDirectorySync"),dev:0,ino:0,nlink:1,uid:0,gid:0,rdev:0,blksize:4096,blocks:Math.ceil(40/4096),atimeMs:a,mtimeMs:a,ctimeMs:a,birthtimeMs:a,atime:a,mtime:a,ctime:a,birthtime:a}},"getStats"),getFile:i(async({gitRoot:e,nodeFs:t,pathParams:r,userSpaceFs:n})=>{try{return{type:"file",content:`
168
168
  `,mode:420,size:2}}catch{return}},"getFile"),writeFile:i(async({gitRoot:e,nodeFs:t,content:r,userSpaceFs:n,author:a})=>{let s=await nt(e,t),o=r.toString().trim(),f=await et(t,e,s,gS(n));if(!f)throw new Error(`Source branch ${s} does not exist`);let h=await et(t,e,o,gS(n));if(!h)throw new Error(`Target branch ${o} does not exist`);let c=await ps.default.readTree({fs:t,dir:e,oid:f});if(await ps.default.readTree({fs:t,dir:e,oid:h})===c)return;let p=await ps.default.commit({fs:t,dir:e,message:"Changes from "+s+" applied to "+o,tree:c.oid,noUpdateBranch:!0,author:a,parent:[f,h]}),m=await ps.default.commit({fs:t,dir:e,message:"Changes from "+s+" applied to "+o,tree:c.oid,noUpdateBranch:!0,author:a,parent:[f,p]});await ps.default.writeRef({fs:t,dir:e,ref:"refs/heads/"+Ut(o),value:p,force:!0}),await ps.default.writeRef({fs:t,dir:e,ref:"refs/heads/"+Ut(s),value:m,force:!0})},"writeFile"),rename(e){throw new Error("not implementsd")},mkdir:i(async function(e){throw new Error("not implemented")},"mkdir")};var XU={type:"gitTargetBranchVirtualFile",rootType:"file",getStats:i(async({gitRoot:e,nodeFs:t})=>{let n=(await hc(e,t)).length;return{mode:420,size:n,isFile:i(()=>!0,"isFile"),isDirectory:i(()=>!1,"isDirectory"),isSymbolicLink:i(()=>!1,"isSymbolicLink"),isBlockDevice:i(()=>!1,"isBlockDevice"),isCharacterDevice:i(()=>!1,"isCharacterDevice"),isSocket:i(()=>!1,"isSocket"),isFIFO:i(()=>!1,"isFIFO"),isFileSync:i(()=>!0,"isFileSync"),isDirectorySync:i(()=>!1,"isDirectorySync"),dev:0,ino:0,nlink:1,uid:0,gid:0,rdev:0,blksize:4096,blocks:Math.ceil(n/4096),atimeMs:Date.now(),mtimeMs:Date.now(),ctimeMs:Date.now(),birthtimeMs:Date.now(),atime:new Date,mtime:new Date,ctime:new Date,birthtime:new Date}},"getStats"),getFile:i(async({gitRoot:e,nodeFs:t})=>{let r=await hc(e,t);return{type:"file",content:r+`
169
- `,mode:420,size:r.length+1}},"getFile"),writeFile:i(async({gitRoot:e,nodeFs:t,content:r})=>{let n=r.toString().trim();if(!await et(t,e,n))throw new Error(`Branch ${n} does not exist in the repository`);await zU(e,t,n)},"writeFile"),rename(e){throw new Error("not implemented")},mkdir:i(async function(e){throw new Error("not implemented")},"mkdir")};function wS(e){return e&&e.gitCache!==void 0?e.gitCache:e&&e.parentFs?wS(e.parentFs):{}}i(wS,"getGitCache");async function wbe(e){let t=new um.Volume,r=(0,um.createFsFromVolume)(t);return _ue({...e,storageFs:e?.storageFs?e.storageFs:r,gitRoot:e?.gitRoot||"/"})}i(wbe,"openLegitFsWithMemoryFs");async function _ue({storageFs:e,gitRoot:t,anonymousBranch:r="anonymous",showKeepFiles:n=!1,initialAuthor:a={type:"local",id:"local",name:"Local User",email:"local@legitcontrol.com"},serverUrl:s="https://hub.legitcontrol.com",publicKey:o,claudeHandler:f}){await e.promises.readdir(t+"/.git").then(()=>!0).catch(()=>!1)||(await pr.default.init({fs:e,dir:"/",defaultBranch:r}),await e.promises.writeFile(t+"/.keep",""),await pr.default.add({fs:e,dir:"/",filepath:".keep",cache:wS(e)}),await pr.default.commit({fs:e,dir:"/",message:"Initial commit",author:{name:"Test",email:"test@example.com"},cache:wS(e)}),await pr.default.setConfig({fs:e,dir:t,path:"init.defaultBranch",value:r})),await pr.default.getConfig({fs:e,dir:t,path:"user.legit_user_id"})||await pr.default.setConfig({fs:e,dir:t,path:"user.legit_user_id",value:a.name}),await pr.default.getConfig({fs:e,dir:t,path:"user.name"})||await pr.default.setConfig({fs:e,dir:t,path:"user.name",value:a.name}),await pr.default.getConfig({fs:e,dir:t,path:"user.email"})||await pr.default.setConfig({fs:e,dir:t,path:"user.email",value:a.email});let m=new Dh({name:"git",storageFs:e,gitRoot:t,defaultBranch:r});m.gitCache={};let g={".legit":{".":cS,operation:dS,head:uS,operationHead:mS,operationHistory:xp,history:yS,currentBranch:GU,"target-branch":XU,"apply-changes":KU,branches:{".":WU,"[branchName]":{".legit":{".":cS,operation:dS,head:uS,operationHead:mS,operationHistory:xp,history:yS,threadName:qU},"[[...filePath]]":im}},commits:{".":hS,"[sha_1_1_2]":{".":hS,"[sha1_3__40]":{"[[...filePath]]":HU}}}},".claude":{"[[...filePath]]":YU},"[[...filePath]]":im};!f&&g[".claude"]&&delete g[".claude"];let b=new Rp({name:"git-subfs",parentFs:m,gitRoot:t,gitStorageFs:e,routerConfig:g}),v=n?[".git"]:[".git",".keep"],_=new Uh({name:"git-hidden-subfs",parentFs:m,gitRoot:t,hiddenFiles:v}),E=new jh({name:"git-ephemeral-subfs",parentFs:m,gitRoot:t,ephemeralPatterns:["**/._*","**/.DS_Store","**/.AppleDouble/","**/.AppleDB","**/.AppleDesktop","**/.Spotlight-V100","**/.TemporaryItems","**/.Trashes","**/.fseventsd","**/.VolumeIcon.icns","**/.ql_disablethumbnails","**/.~lock.*","**/lu[0-9a-zA-Z]*.tmp","**/.metaentries.json.tmp","**/**.tmp.**","**/**.sb-**"]});m.addSubFs(b),m.setHiddenFilesSubFs(_),m.setEphemeralFilesSubFs(E);let R=jU({storageFs:e,gitRoot:t}),T=NU(R,o),F=DU({fs:e,gitRepoPath:t,serverUrl:s,auth:T,anonymousBranch:r}),S=Object.assign(m,{auth:T,sync:F,setLogger(k){m.setLoggger(k)},push:i(async k=>{},"push"),shareCurrentBranch:i(async()=>{if((await T.getUser()).type==="local")throw new Error("login first - for example anonymously using legitfs.auth.signInAnonymously()");let k=await S.getCurrentBranch();return k===r&&(k=(await T.getUser()).id,await pr.default.renameBranch({fs:e,dir:t,oldref:r,ref:k})),await F.sequentialPush([k]),S.setCurrentBranch(k),k},"shareCurrentBranch"),setCurrentBranch:i(async k=>{(await pr.default.listBranches({fs:e,dir:t})).includes(k)||await F?.loadBranch(k);let C=(await pr.default.listBranches({fs:e,dir:t})).includes(k);if(console.log("branchExistsAfter",C),!C)throw new Error(`Branch ${k} does not exist`);await pr.default.setConfig({fs:e,dir:t,path:"init.defaultBranch",value:k})},"setCurrentBranch"),getCurrentBranch:i(async()=>{let k=await pr.default.getConfig({fs:e,dir:t,path:"init.defaultBranch"});if(!k)throw new Error("No current branch set");return k},"getCurrentBranch")});return S}i(_ue,"openLegitFs");var _be=i(e=>async t=>{if(!t.path.includes(".legit/branches/")||(t.path.match(/\.legit/g)||[]).length>1)return;let[r,n]=t.path.split(".legit/branches/"),[a,...s]=n.split("/"),o=s.join("/"),f=r+".legit/branches/"+a+"/.legit/operation",h=JSON.stringify(t.operationArgs,(c,d)=>Buffer.isBuffer(d)?{__buffer__:d.toString("base64")}:d);console.log(f,`[${t.fsName}].${t.operation}(${t.fd?t.fd.fd+" - ":""}${t.path})
169
+ `,mode:420,size:r.length+1}},"getFile"),writeFile:i(async({gitRoot:e,nodeFs:t,content:r})=>{let n=r.toString().trim();if(!await et(t,e,n))throw new Error(`Branch ${n} does not exist in the repository`);await zU(e,t,n)},"writeFile"),rename(e){throw new Error("not implemented")},mkdir:i(async function(e){throw new Error("not implemented")},"mkdir")};function wS(e){return e&&e.gitCache!==void 0?e.gitCache:e&&e.parentFs?wS(e.parentFs):{}}i(wS,"getGitCache");async function wbe(e){let t=new um.Volume,r=(0,um.createFsFromVolume)(t);return _ue({...e,storageFs:e?.storageFs?e.storageFs:r,gitRoot:e?.gitRoot||"/"})}i(wbe,"openLegitFsWithMemoryFs");async function _ue({storageFs:e,gitRoot:t,anonymousBranch:r="anonymous",showKeepFiles:n=!1,initialAuthor:a={type:"local",id:"local",name:"Local User",email:"local@legitcontrol.com"},serverUrl:s="https://hub.legitcontrol.com",publicKey:o,claudeHandler:f}){await e.promises.readdir(t+"/.git").then(()=>!0).catch(()=>!1)||(await pr.default.init({fs:e,dir:"/",defaultBranch:r}),await e.promises.writeFile(t+"/.gitignore",""),await e.promises.writeFile(t+"/.keep",""),await pr.default.add({fs:e,dir:"/",filepath:".keep",cache:wS(e)}),await pr.default.commit({fs:e,dir:"/",message:"Initial commit",author:{name:"Test",email:"test@example.com"},cache:wS(e)}),await pr.default.setConfig({fs:e,dir:t,path:"init.defaultBranch",value:r})),await pr.default.getConfig({fs:e,dir:t,path:"user.legit_user_id"})||await pr.default.setConfig({fs:e,dir:t,path:"user.legit_user_id",value:a.name}),await pr.default.getConfig({fs:e,dir:t,path:"user.name"})||await pr.default.setConfig({fs:e,dir:t,path:"user.name",value:a.name}),await pr.default.getConfig({fs:e,dir:t,path:"user.email"})||await pr.default.setConfig({fs:e,dir:t,path:"user.email",value:a.email});let m=new Dh({name:"git",storageFs:e,gitRoot:t,defaultBranch:r});m.gitCache={};let g={".legit":{".":cS,operation:dS,head:uS,operationHead:mS,operationHistory:xp,history:yS,currentBranch:GU,"target-branch":XU,"apply-changes":KU,branches:{".":WU,"[branchName]":{".legit":{".":cS,operation:dS,head:uS,operationHead:mS,operationHistory:xp,history:yS,threadName:qU},"[[...filePath]]":im}},commits:{".":hS,"[sha_1_1_2]":{".":hS,"[sha1_3__40]":{"[[...filePath]]":HU}}}},".claude":{"[[...filePath]]":YU},"[[...filePath]]":im};!f&&g[".claude"]&&delete g[".claude"];let b=new Rp({name:"git-subfs",parentFs:m,gitRoot:t,gitStorageFs:e,routerConfig:g}),v=n?[".git"]:[".git",".keep"],_=new Uh({name:"git-hidden-subfs",parentFs:m,gitRoot:t,hiddenFiles:v}),E=new jh({name:"git-ephemeral-subfs",parentFs:m,gitRoot:t,ephemeralPatterns:["**/._*","**/.DS_Store","**/.AppleDouble/","**/.AppleDB","**/.AppleDesktop","**/.Spotlight-V100","**/.TemporaryItems","**/.Trashes","**/.fseventsd","**/.VolumeIcon.icns","**/.ql_disablethumbnails","**/.~lock.*","**/lu[0-9a-zA-Z]*.tmp","**/.metaentries.json.tmp","**/**.tmp.**","**/**.sb-**"]});m.addSubFs(b),m.setHiddenFilesSubFs(_),m.setEphemeralFilesSubFs(E);let R=jU({storageFs:e,gitRoot:t}),T=NU(R,o),F=DU({fs:e,gitRepoPath:t,serverUrl:s,auth:T,anonymousBranch:r}),S=Object.assign(m,{auth:T,sync:F,setLogger(k){m.setLoggger(k)},push:i(async k=>{},"push"),shareCurrentBranch:i(async()=>{if((await T.getUser()).type==="local")throw new Error("login first - for example anonymously using legitfs.auth.signInAnonymously()");let k=await S.getCurrentBranch();return k===r&&(k=(await T.getUser()).id,await pr.default.renameBranch({fs:e,dir:t,oldref:r,ref:k})),await F.sequentialPush([k]),S.setCurrentBranch(k),k},"shareCurrentBranch"),setCurrentBranch:i(async k=>{(await pr.default.listBranches({fs:e,dir:t})).includes(k)||await F?.loadBranch(k);let C=(await pr.default.listBranches({fs:e,dir:t})).includes(k);if(console.log("branchExistsAfter",C),!C)throw new Error(`Branch ${k} does not exist`);await pr.default.setConfig({fs:e,dir:t,path:"init.defaultBranch",value:k})},"setCurrentBranch"),getCurrentBranch:i(async()=>{let k=await pr.default.getConfig({fs:e,dir:t,path:"init.defaultBranch"});if(!k)throw new Error("No current branch set");return k},"getCurrentBranch")});return S}i(_ue,"openLegitFs");var _be=i(e=>async t=>{if(!t.path.includes(".legit/branches/")||(t.path.match(/\.legit/g)||[]).length>1)return;let[r,n]=t.path.split(".legit/branches/"),[a,...s]=n.split("/"),o=s.join("/"),f=r+".legit/branches/"+a+"/.legit/operation",h=JSON.stringify(t.operationArgs,(c,d)=>Buffer.isBuffer(d)?{__buffer__:d.toString("base64")}:d);console.log(f,`[${t.fsName}].${t.operation}(${t.fd?t.fd.fd+" - ":""}${t.path})
170
170
 
171
171
  ${h}
172
172