@kitelev/exocortex-cli 16.119.0 → 16.119.1
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 +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v16.119.
|
|
2
|
+
// @kitelev/exocortex-cli v16.119.1
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -306,7 +306,7 @@ To resolve:
|
|
|
306
306
|
path = ${e}
|
|
307
307
|
url = ${t}
|
|
308
308
|
`;return{content:n+i+s,added:!0}}a(Cz,"appendGitmodulesEntry");function Pz(n,e){let t=n.split(/\r?\n/),r=[],i=!1,s=new RegExp(`^\\[submodule\\s+"${UE(e)}"\\]\\s*$`);for(let l of t){if(i){if(/^\[.+\]\s*$/.test(l)){i=!1,r.push(l);continue}continue}if(s.test(l)){i=!0;continue}r.push(l)}let o=[],c=!1;for(let l of r){let u=l.trim().length===0;u&&c||(o.push(l),c=u)}return o.join(`
|
|
309
|
-
`)}a(Pz,"stripGitmodulesEntry")});var sd=v(BE=>{"use strict";Object.defineProperty(BE,"__esModule",{value:!0});BE.gitBlobSha=Oz;async function Oz(n,e){let t=new TextEncoder,r=typeof n=="string"?t.encode(n):n,i=t.encode(`blob ${r.byteLength}\0`),s=new Uint8Array(i.byteLength+r.byteLength);return s.set(i,0),s.set(r,i.byteLength),e(s)}a(Oz,"gitBlobSha")});var VE=v(oy=>{"use strict";Object.defineProperty(oy,"__esModule",{value:!0});oy.extractAssetUid=BP;oy.detectChanges=Dz;var Fz=sd();function BP(n){let e=/^---\r?\n([\s\S]*?)\r?\n---(?=\r?\n|$)/.exec(n);if(!e)return;let t=/^exo__Asset_uid:[ \t]*["']?([^\s"']+)["']?[ \t]*$/m.exec(e[1]);return t?t[1]:void 0}a(BP,"extractAssetUid");async function Dz(n){let{localFiles:e,watermark:t,actualBaseTreeSha:r,sha1:i}=n;if(t===null)return{kind:"full-conflict",reason:"first-sync"};if(r===null)return{kind:"full-conflict",reason:"base-mismatch",detail:`watermark commit ${t.lastSyncedSha} not resolvable on remote`};if(r!==t.rootTreeSha)return{kind:"full-conflict",reason:"base-mismatch",detail:`stored root tree ${t.rootTreeSha} != actual ${r} at ${t.lastSyncedSha}`};let s=[],o=new Map;for(let[T,x]of e){let I=await(0,Fz.gitBlobSha)(x,i);o.set(T,I),s.push({path:T,blobSha:I,uid:typeof x=="string"?BP(x):void 0})}let c=[],l=[],u=[],f=[],d=new Map;for(let T of s){if(T.uid===void 0)continue;let x=d.get(T.uid)??[];x.push(T.path),d.set(T.uid,x)}let h=new Map;for(let T of t.files){if(T.uid===void 0)continue;let x=h.get(T.uid)??[];x.push(T.path),h.set(T.uid,x)}let p=new Set;for(let[T,x]of d)x.length>1&&p.add(T);for(let[T,x]of h)x.length>1&&p.add(T);for(let T of[...p].sort()){let x=d.get(T)??[],I=x.length>1?`on disk (${x.join(", ")})`:`in the sync base (${(h.get(T)??[]).join(", ")})`;f.push(`duplicate uid ${T} ${I} \u2014 uid identity suppressed for the group; every path matched by path identity (#3477)`)}let g=new Map,y=[];for(let T of t.files)T.uid!==void 0&&!p.has(T.uid)?g.set(T.uid,T):y.push(T);let w=[],b=new Set;for(let T of s){let x=T.uid!==void 0&&!p.has(T.uid)?g.get(T.uid):void 0;T.uid!==void 0&&x!==void 0?(b.add(T.uid),(x.blobSha!==T.blobSha||x.path!==T.path)&&l.push({path:T.path,uid:T.uid,blobSha:T.blobSha,...x.path!==T.path?{basePath:x.path}:{}})):w.push(T)}let S=new Map;for(let T of y)S.set(T.path,T);for(let[T,x]of g)b.has(T)||S.set(x.path,x);for(let T of w){let x=S.get(T.path);x!==void 0?(S.delete(T.path),x.blobSha!==T.blobSha&&l.push({path:T.path,uid:T.uid,blobSha:T.blobSha})):c.push({path:T.path,uid:T.uid,blobSha:T.blobSha})}for(let T of S.values())u.push({path:T.path,uid:T.uid,blobSha:T.blobSha});return{kind:"changes",added:c,modified:l,deleted:u,warnings:f,diskBlobShas:o,duplicateUids:p}}a(Dz,"detectChanges")});var ad=v(mc=>{"use strict";Object.defineProperty(mc,"__esModule",{value:!0});mc.getHeadSha=Nz;mc.getCommitInfo=kz;mc.getTree=Mz;mc.getBlobText=jz;mc.getBlobBytes=$z;var VP=Jc(),Lz="https://api.github.com";function od(n){return(n??Lz).replace(/\/$/,"")}a(od,"api");function pc(n){return n!==null&&typeof n=="object"?n:void 0}a(pc,"asRecord");function Rs(n,e){let r=pc(n)?.[e];return typeof r=="string"?r:void 0}a(Rs,"readString");async function Nz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/refs/heads/${encodeURIComponent(r)}`}),o=Rs(pc(s?.json)?.object,"sha");if(typeof o!="string"||o.length===0)throw new Error(`ExoSync: missing object.sha for ref heads/${r}`);return o}a(Nz,"getHeadSha");async function kz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/commits/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"sha"),l=Rs(o?.tree,"sha");if(!c||!l)throw new Error(`ExoSync: malformed commit response for ${r}`);let u=o?.parents,f=Array.isArray(u)?u.map(d=>Rs(d,"sha")).filter(d=>typeof d=="string"):[];return{sha:c,treeSha:l,parents:f}}a(kz,"getCommitInfo");async function Mz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/trees/${encodeURIComponent(r)}?recursive=1`}),o=pc(s?.json);if(o?.truncated===!0)throw new Error(`ExoSync: tree ${r} is truncated by GitHub (repo too large for recursive listing) \u2014 refusing to diff`);let c=o?.tree;if(!Array.isArray(c))throw new Error(`ExoSync: malformed tree response for ${r}`);let l=[];for(let u of c){let f=pc(u);if(f?.type!=="blob")continue;let d=Rs(f,"path"),h=Rs(f,"sha"),p=typeof f.size=="number"?f.size:void 0;d&&h&&l.push({path:d,blobSha:h,...p!==void 0?{size:p}:{}})}return l}a(Mz,"getTree");async function jz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/blobs/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"content");if(typeof c!="string")throw new Error(`ExoSync: malformed blob response for ${r}`);return Rs(o,"encoding")==="utf-8"?c:(0,VP.base64ToUtf8)(c)}a(jz,"getBlobText");async function $z(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/blobs/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"content");if(typeof c!="string")throw new Error(`ExoSync: malformed blob response for ${r}`);return Rs(o,"encoding")==="utf-8"?new TextEncoder().encode(c):(0,VP.base64ToBytes)(c)}a($z,"getBlobBytes")});var ay=v(qE=>{"use strict";Object.defineProperty(qE,"__esModule",{value:!0});qE.isAuthError=Uz;function Uz(n){let e=n instanceof Error?n.message:String(n);return/HTTP 401/.test(e)?!0:/HTTP 403/.test(e)&&!/rate limit/i.test(e)&&!/abuse detection/i.test(e)}a(Uz,"isAuthError")});var ly=v(cy=>{"use strict";Object.defineProperty(cy,"__esModule",{value:!0});cy.scanForSecrets=Bz;cy.redactSecrets=Vz;var qP=[{kind:"github-token",re:/gh[pousr]_[A-Za-z0-9_]{36,}/},{kind:"github-fine-grained-token",re:/github_pat_[A-Za-z0-9_]{22,}_[A-Za-z0-9_]{59,}/},{kind:"private-key",re:/-----BEGIN [A-Z ]*PRIVATE KEY-----/}];function Bz(n){let e=[];for(let[t,r]of n)for(let{kind:i,re:s}of qP)s.test(r)&&e.push({path:t,kind:i});return e}a(Bz,"scanForSecrets");function Vz(n){let e=n;for(let{kind:t,re:r}of qP)e=e.replace(new RegExp(r.source,"g"),`[REDACTED:${t}]`);return e}a(Vz,"redactSecrets")});var fy=v(uy=>{"use strict";Object.defineProperty(uy,"__esModule",{value:!0});uy.isRateLimitError=GP;uy.withRateLimitBackoff=Gz;function GP(n){let e=n instanceof Error?n.message:String(n);return/HTTP 429/.test(e)?!0:/HTTP 403/.test(e)&&(/rate limit/i.test(e)||/abuse detection/i.test(e))}a(GP,"isRateLimitError");var qz=a(n=>new Promise(e=>setTimeout(e,n)),"defaultSleep");function Gz(n,e={}){let t=e.maxRetries??3,r=e.baseDelayMs??1e3,i=e.sleep??qz,s=e.random??Math.random;return async o=>{let c=0;for(;;)try{return await n(o)}catch(l){if(!GP(l)||c>=t)throw l;let u=r*2**c*(1+s());c++,await i(u)}}}a(Gz,"withRateLimitBackoff")});var dy=v(vo=>{"use strict";Object.defineProperty(vo,"__esModule",{value:!0});vo.DEFAULT_MAX_FILE_BYTES=vo.InMemoryQuarantineStore=void 0;vo.contentEquals=Wz;vo.isSyncablePath=zz;vo.isFileSpaceSyncablePath=Hz;function Wz(n,e){if(n===void 0||e===void 0||typeof n=="string"&&typeof e=="string")return n===e;if(typeof n=="string"||typeof e=="string"||n.byteLength!==e.byteLength)return!1;for(let t=0;t<n.byteLength;t++)if(n[t]!==e[t])return!1;return!0}a(Wz,"contentEquals");var GE=class{static{a(this,"InMemoryQuarantineStore")}constructor(){this.entries=[]}async quarantine(e){this.entries.push(e)}};vo.InMemoryQuarantineStore=GE;function zz(n){return n.endsWith(".md")&&!n.includes(".local.")&&!n.includes(".conflict.")}a(zz,"isSyncablePath");function Hz(n){return!n.includes(".local.")&&!n.includes(".conflict.")}a(Hz,"isFileSpaceSyncablePath");vo.DEFAULT_MAX_FILE_BYTES=30*1024*1024});var KE=v(Ps=>{"use strict";Object.defineProperty(Ps,"__esModule",{value:!0});Ps.SyncEngine=Ps.DEFAULT_MAX_PUSH_RETRIES=void 0;Ps.isNonFastForwardError=KP;Ps.orderChildrenFirst=rH;var Kz=iy(),yt=ad(),gc=VE(),Xz=Jc(),cd=sd(),Qz=ay(),Yz=ly(),Jz=fy(),Cs=dy();Ps.DEFAULT_MAX_PUSH_RETRIES=3;function Zz(n){try{return new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{return null}}a(Zz,"decodeUtf8Strict");function eH(n){return typeof n=="string"?n:{base64:(0,Xz.bytesToBase64)(n)}}a(eH,"toCommitContent");async function WP(n,e){if(n.readBinary===void 0)throw new Error("LocalFilesPort.readBinary is required for file-mode sync (Phase C)");return n.readBinary(e)}a(WP,"readBinaryStrict");async function tH(n,e,t){if(n.writeBinary===void 0)throw new Error("LocalFilesPort.writeBinary is required for file-mode sync (Phase C)");return n.writeBinary(e,t)}a(tH,"writeBinaryStrict");function zP(n){return n.length===0||n.startsWith("/")||n.includes("\\")?!1:n.split("/").every(e=>e.length>0&&e!=="."&&e!=="..")}a(zP,"isSafeRepoRelativePath");function KP(n){let e=n instanceof Error?n.message:String(n);return/HTTP 422/.test(e)&&/git\/refs/.test(e)||/ref update mismatch/.test(e)||/HTTP 422/.test(e)&&/git\/trees/.test(e)&&/BadObjectState/.test(e)}a(KP,"isNonFastForwardError");function rH(n){let e=a(t=>t.split("/").filter(r=>r.length>0).length,"depth");return[...n].sort((t,r)=>e(r.localPath)-e(t.localPath))}a(rH,"orderChildrenFirst");function HP(n,e){let t=new Map(n.map(o=>[o.path,o])),r=new Set,i=[];for(let o of e){r.add(o.path);let c=t.get(o.path);(c===void 0||c.blobSha!==o.blobSha)&&i.push(o)}let s=n.filter(o=>!r.has(o.path));return{changed:i,deleted:s}}a(HP,"diffTrees");function tu(n){return n instanceof Error?n.message:String(n)}a(tu,"errMsg");function nH(n,e,t){if(t.size===0)return n;let r=new Map(e.files.map(o=>[o.path,o])),i=new Set(n.map(o=>o.path)),s=[];for(let o of n){if(!t.has(o.path)){s.push(o);continue}let c=r.get(o.path);c!==void 0&&s.push(c)}for(let o of t){if(i.has(o))continue;let c=r.get(o);c!==void 0&&s.push(c)}return s}a(nH,"applyWatermarkPins");var WE={mergedFiles:new Map,mergedWrites:[],quarantineEntries:[],resolvedQuarantineEntries:[],mergedCount:0,mergedPaths:[],warnings:[]};function zE(n){return new Map(n.map(e=>[e.path,e.blobSha]))}a(zE,"treeByPath");function hy(n){return[...n.quarantineEntries.map(e=>e.path),...n.resolvedQuarantineEntries.map(e=>e.path)]}a(hy,"quarantinedPathsOf");var HE=class{static{a(this,"SyncEngine")}constructor(e){this.opInProgress=!1,this.deps=e,this.transport=(0,Jz.withRateLimitBackoff)(e.transport,e.backoff)}busyResult(e){return{repoKey:e.repoKey,status:"busy",pulledCount:0,pushedCount:0,mergedCount:0,quarantinedCount:0,warnings:[],deferredDeletes:[],detail:"another sync operation is in progress (D11 guard) \u2014 retry after it finishes"}}modeOps(e){let t=e.spaceKind==="file",r=t?Cs.isFileSpaceSyncablePath:Cs.isSyncablePath,i=this.deps.maxFileBytes??Cs.DEFAULT_MAX_FILE_BYTES;return{fileMode:t,syncable:r,treeFilter:a(s=>r(s.path)&&(!t||s.size===void 0||s.size<=i),"treeFilter")}}async buildFileModeFirstSyncBase(e,t,r,i){let s=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),o=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,s,this.deps.baseURL),c=(await(0,yt.getTree)(this.transport,e.owner,e.repo,o.treeSha,this.deps.baseURL)).filter(r.treeFilter),l=[];for(let u of c){let f=t.get(u.path);f!==void 0&&await(0,cd.gitBlobSha)(f,this.deps.sha1)===u.blobSha&&l.push({path:u.path,blobSha:u.blobSha})}return i.push(`first-sync (file mode): synthetic base from ${l.length} already-identical file(s) at head ${s} \u2014 divergence resolves through the remote-wins layer (D22)`),{lastSyncedSha:s,rootTreeSha:o.treeSha,files:l,spaceKind:"file"}}async syncAll(e,t="sync",r){if(this.opInProgress)return e.map(i=>this.busyResult(i));this.opInProgress=!0;try{let i=[];for(let s of e)i.push(await this.syncLocked(s,t,r));return i}finally{this.opInProgress=!1}}async sync(e,t="sync",r){if(this.opInProgress)return this.busyResult(e);this.opInProgress=!0;try{return await this.syncLocked(e,t,r)}finally{this.opInProgress=!1}}emitProgress(e,t,r){if(e!==void 0)try{e({repoKey:t,phase:r})}catch{}}async syncLocked(e,t="sync",r){let i=[],s=[],o=[],c=a((l,u={})=>({repoKey:e.repoKey,status:l,pulledCount:0,pushedCount:0,mergedCount:0,quarantinedCount:0,warnings:i,deferredDeletes:s,...u}),"result");try{let l=await this.deps.materializationCheck.check(e);if(!l.fullyMaterialized)return i.push(`skipped: repo not fully materialized${l.reason?` (${l.reason})`:""} \u2014 deletes NOT inferred (D19)`),c("skipped-not-materialized");let u=this.modeOps(e),f=this.deps.localFilesFor(e);if(u.fileMode&&(f.readBinary===void 0||f.writeBinary===void 0))return c("error",{detail:"file-mode repo requires a LocalFilesPort with readBinary/writeBinary \u2014 refusing to sync through the text-only port (binary would corrupt)"});if(u.fileMode&&this.deps.quarantine===void 0)return c("error",{detail:"file-mode repo requires a quarantine sink (D18 remote-wins preserves losing local bytes there) \u2014 configure the quarantine repo before syncing FileSpaces"});let d=this.deps.maxFileBytes??Cs.DEFAULT_MAX_FILE_BYTES,h=new Map,p=new Set;for(let N of(await f.list()).filter(u.syncable))if(u.fileMode){let j=await WP(f,N);if(j.byteLength>d){p.add(N),i.push(`skipped oversized file ${N} (${j.byteLength} bytes > ${d} cap) \u2014 excluded from sync symmetrically (Phase C size cap)`);continue}h.set(N,j)}else h.set(N,await f.read(N));let g=await this.deps.watermarkStore.get(e.repoKey);if(g?.spaceKind==="file"&&!u.fileMode)return c("error",{detail:"watermark was written by a FILE-mode sync but the spec now resolves to asset mode \u2014 refusing (fix the conflicting Space declarations, or clear the watermark to restart)"});g!==null&&u.fileMode&&g.spaceKind!=="file"&&(i.push("watermark was written by an ASSET-mode sync \u2014 rebuilding the base through the file-mode first-sync layer (kind flip)"),g=null);let y=!1;if(g===null)if(u.fileMode)y=!0,g=await this.buildFileModeFirstSyncBase(e,h,u,i);else{let N=await this.bootstrapWatermark(e,h,i,c);if(N.kind==="settled")return N.outcome;y=!0,g=N.base}let w=g;u.fileMode&&p.size>0&&(g={...g,files:g.files.filter(N=>!p.has(N.path))}),this.emitProgress(r,e.repoKey,"detecting");let b=await(0,gc.detectChanges)({localFiles:h,watermark:g,actualBaseTreeSha:await this.resolveBaseTreeSha(e,g),sha1:this.deps.sha1});if(b.kind==="full-conflict")return c("full-conflict",{detail:`${b.reason}${b.detail?`: ${b.detail}`:""} \u2014 divergence must go through merge/quarantine (A2/A3), not overwrite`});i.push(...b.warnings);let S=this.pinLocalChanges(b,h,i,s,t);o=[...S.pushDeletionsAll.keys()];let T=await this.runPushLoop(e,g,S,h,i,u,y,p,t,r);if(o=[],T.kind!=="done"&&S.pushDeletionsAll.size>0&&s.push(...S.pushDeletionsAll.keys()),T.kind==="conflict")return c("conflict",{detail:T.detail});if(T.kind==="secret-detected")return c("error",{detail:T.detail});if(T.kind==="retry-exhausted"){i.push(...T.merge.warnings);let N=await this.buildTerminalQuarantineEntries(e,g,T.pushFiles,T.merge.quarantineEntries,h),j=[...T.merge.quarantineEntries,...T.merge.resolvedQuarantineEntries,...N];return await this.flushQuarantine(j,i),c("retry-exhausted",{detail:T.detail,quarantinedCount:j.length,...j.length>0?{quarantinedPaths:j.map(ie=>ie.path)}:{}})}let{examinedHead:x,pushedSha:I,applyWrites:R,applyDeletes:W,pushFiles:Q}=T,P=T.merge;i.push(...P.warnings),i.push(...T.deferredWarnings),s.push(...T.withheldDeletions);let D=T.deferredPaths.size>0?{deferredPaths:[...T.deferredPaths]}:{},k=T.pushedDeletions.length>0?{pushedDeletes:T.pushedDeletions}:{},X=await this.flushQuarantine([...P.quarantineEntries,...P.resolvedQuarantineEntries],i),q=new Set;if(!X&&P.resolvedQuarantineEntries.length>0){for(let N of P.resolvedQuarantineEntries)q.add(N.path);i.push(`quarantine flush failed \u2014 remote-wins apply withheld for ${q.size} path(s); local files untouched, conflict re-derives next sync (D18 durability gate)`)}if(I===void 0&&x===g.lastSyncedSha&&R.length===0&&W.length===0&&P.mergedWrites.length===0&&P.quarantineEntries.length===0&&P.resolvedQuarantineEntries.length===0&&(g.pinnedPaths?.length??0)===0&&T.alreadyInHead.length===0&&T.deferredPaths.size===0&&!y)return c("synced");let B=I??x,J=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,B,this.deps.baseURL);if(I!==void 0&&J.parents[0]!==x)return await this.checkRaceWindow(e,g,x,J.parents[0],Q,new Set(T.pushedDeletions),i,u),i.push(`race-window: watermark NOT advanced (pushed commit's parent ${J.parents[0]} != examined head ${x}) \u2014 next sync reconciles the concurrent change`),c("synced",{pushedSha:I,pushedCount:Q.size,mergedCount:P.mergedCount,quarantinedCount:P.quarantineEntries.length+P.resolvedQuarantineEntries.length,...P.mergedPaths.length>0?{mergedPaths:P.mergedPaths}:{},...hy(P).length>0?{quarantinedPaths:hy(P)}:{},...D,...k});let{pulledCount:be,pinnedPaths:ne}=await this.applyRemoteChanges(f,h,[...R,...P.mergedWrites].filter(N=>!q.has(N.path)),W.filter(N=>!q.has(N.path)),i);for(let N of P.quarantineEntries)ne.add(N.path);for(let N of T.deferredPaths)ne.add(N);for(let N of q)ne.add(N);if(u.fileMode){for(let N of p)ne.add(N);for(let N of T.remoteOversized)ne.add(N)}return await this.advanceWatermark(e,B,J.treeSha,h,[...R,...P.mergedWrites,...T.deferredRemoteChanges],w,ne,b.diskBlobShas,u,p),await this.resolveClearedPins(e,w,ne,i,new Set(P.resolvedQuarantineEntries.map(N=>N.path))),c("synced",{pushedSha:I,pulledCount:be,pushedCount:Q.size,mergedCount:P.mergedCount,quarantinedCount:P.quarantineEntries.length+P.resolvedQuarantineEntries.length,...P.mergedPaths.length>0?{mergedPaths:P.mergedPaths}:{},...hy(P).length>0?{quarantinedPaths:hy(P)}:{},...D,...k})}catch(l){let u=this.deps.redact??(f=>f);return o.length>0&&s.push(...o),(0,Qz.isAuthError)(l)?c("auth-required",{detail:u(`authentication failed: ${tu(l)} \u2014 the PAT is expired, revoked or under-scoped; update it in the per-device secure storage (R8). Never treated as success.`)}):(i.push(`sync failed: ${u(tu(l))}`),c("error",{detail:u(tu(l))}))}}async flushQuarantine(e,t){if(e.length===0)return!0;let r=this.deps.redact??(s=>s);for(let s of e)t.push(r(`quarantined ${s.path}: ${s.reason}`));let i=this.deps.quarantine;if(i===void 0)return!1;try{if(i.quarantineAll!==void 0)await i.quarantineAll(e);else for(let s of e)await i.quarantine(s);return!0}catch(s){let o=this.deps.redact??(c=>c);return t.push(`quarantine sink failed: ${o(tu(s))} \u2014 files untouched on disk; the conflict re-derives next sync (D17 degradation)`),!1}}async buildTerminalQuarantineEntries(e,t,r,i,s){let o=new Set(i.map(u=>u.path)),c=new Map;try{let u=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),f=(await(0,yt.getTree)(this.transport,e.owner,e.repo,(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,u,this.deps.baseURL)).treeSha,this.deps.baseURL)).filter(d=>r.has(d.path));for(let d of f)c.set(d.path,await(0,yt.getBlobText)(this.transport,e.owner,e.repo,d.blobSha,this.deps.baseURL))}catch{}let l=[];for(let[u,f]of r){if(o.has(u))continue;let d=s.get(u),h=d??f,p=d!==void 0&&!(0,Cs.contentEquals)(d,f),g=typeof h=="string"?(0,gc.extractAssetUid)(h):void 0,y=c.get(u);l.push({repoKey:e.repoKey,path:u,...g!==void 0?{uid:g}:{},reason:`non-fast-forward push failed after ${this.deps.maxPushRetries??Ps.DEFAULT_MAX_PUSH_RETRIES} retries (D16) \u2014 a concurrent writer keeps moving ${e.branch}; base recoverable from git history at ${t.lastSyncedSha}${p?"; the contended push payload was a merged proposal (never applied to disk) \u2014 the merge re-derives next sync":""}`,...typeof h=="string"?{localContent:h}:{localContentBytes:h},...y!==void 0?{remoteContent:y}:{}})}return l}async resolveClearedPins(e,t,r,i,s=new Set){let o=this.deps.quarantine;if(o===void 0||o.markResolved===void 0)return;let c=(t.pinnedPaths??[]).filter(l=>!r.has(l)&&!s.has(l));for(let l of c)try{await o.markResolved?.(e.repoKey,l)}catch(u){let f=this.deps.redact??(d=>d);i.push(`quarantine markResolved failed for ${l}: ${f(tu(u))} \u2014 unresolved-count may overcount until the resolver UI reconciles (CQ4)`)}}async resolveBaseTreeSha(e,t){try{return(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,t.lastSyncedSha,this.deps.baseURL)).treeSha}catch{return null}}pinLocalChanges(e,t,r,i,s){let o=e.modified.filter(h=>h.basePath!==void 0),c=[...e.added,...e.modified.filter(h=>h.basePath===void 0)],l=new Map;if(s==="pull"){for(let h of o)h.basePath!==void 0&&i.push(h.basePath),r.push(`pull-only: rename (uid ${h.uid??"?"}) ${h.basePath} \u2192 ${h.path} not pushed \u2014 propagates on the next push/Sync (#3473)`);for(let h of e.deleted)i.push(h.path),r.push(`pull-only: delete of ${h.path} not pushed \u2014 propagates on the next push/Sync (#3473)`)}else{for(let h of o)h.basePath!==void 0&&l.set(h.basePath,h.path);for(let h of e.deleted)l.set(h.path,h.path)}let u=[...c,...o,...e.deleted.map(h=>({...h}))],f=new Set(e.deleted.map(h=>h.path)),d=new Map;for(let h of[...c,...s==="pull"?[]:o]){let p=t.get(h.path);p!==void 0&&d.set(h.path,p)}return{localChanges:u,localDeletedPaths:f,pushFilesAll:d,pushDeletionsAll:l,dupUids:e.duplicateUids}}async runPushLoop(e,t,r,i,s,o,c=!1,l=new Set,u="sync",f){let{localChanges:d,localDeletedPaths:h,pushFilesAll:p,pushDeletionsAll:g,dupUids:y}=r,w=this.deps.maxPushRetries??Ps.DEFAULT_MAX_PUSH_RETRIES,b=0,S="",T,x=[],I=[],R=new Map,W=new Set,Q=[],P=WE,D=[],k=new Set,X=[],q=[],B=new Set;for(;;){S=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),x=[],I=[],P=WE,D=[],k=new Set,X=[],q=[];let J,be=new Set,ne=(t.pinnedPaths?.length??0)>0;if(S!==t.lastSyncedSha||ne||c){this.emitProgress(f,e.repoKey,"pulling-remote");let ie=await this.collectRemoteChanges(e,t,S,o,l,s,B);J=ie.headTreeByPath;let ye=this.matchLocalVsRemote(d,h,i,ie.changes,be,y,ie.headTreeByPath);if(ye.conflicts.length>0){if(u==="sync"&&this.emitProgress(f,e.repoKey,"merging"),u!=="sync"){for(let G of ye.conflicts){k.add(G.local.path),G.local.basePath!==void 0&&k.add(G.local.basePath);for(let ve of G.remotes)k.add(ve.path),ve.kind==="change"&&X.push(ve)}q.push(`${u}-only: ${ye.conflicts.length} conflict(s) deferred to a full Sync (${ye.conflicts.map(G=>G.desc).join("; ")}) \u2014 paths pinned, nothing merged`)}else if(o.fileMode)P=this.resolveFileModeConflicts(e,ye.conflicts,i,ye.applyWrites,ye.applyDeletes);else{if(this.deps.mergeLayer===void 0)return{kind:"conflict",detail:`overlapping change on ${ye.conflicts[0].desc} \u2014 merge layer (A2/A3) required; nothing pushed, nothing written`};P=await this.resolveMergeConflicts(e,t,ye.conflicts,i)}if(u==="sync")for(let G of ye.conflicts)for(let ve of G.remotes)ve.path!==G.local.path&&(k.add(ve.path),ve.kind==="change"&&X.push(ve),q.push(`conflict group ${G.desc}: remote change at ${ve.path} NOT applied \u2014 pinned to re-derive on the next sync (#3477)`))}if(x=ye.applyWrites,I=ye.applyDeletes,u==="push"&&(x.length>0||I.length>0)){for(let G of x)k.add(G.path),X.push(G);for(let G of I)k.add(G.path);q.push(`push-only: ${x.length+I.length} remote change(s) NOT applied \u2014 pinned to re-derive on the next pull/Sync`),x=[],I=[]}}R=u==="pull"?new Map:new Map([...[...p].filter(([ie])=>!be.has(ie)),...P.mergedFiles]),W=new Set,Q=[];for(let[ie,ye]of g){if(be.has(ye)){Q.push(ie);continue}R.has(ie)||W.add(ie)}if((R.size>0||W.size>0)&&J===void 0&&(J=zE(await(0,yt.getTree)(this.transport,e.owner,e.repo,t.rootTreeSha,this.deps.baseURL))),R.size>0&&J!==void 0){for(let[ie,ye]of R){let G=J.get(ie);G!==void 0&&G===await(0,cd.gitBlobSha)(ye,this.deps.sha1)&&(R.delete(ie),D.push(ie))}D.length>0&&s.push(`phantom push skipped: ${D.length} file(s) already identical in remote HEAD (${D.join(", ")}) \u2014 excluded from the commit (#3475)`)}if(W.size>0&&J!==void 0){for(let ie of[...W])J.has(ie)||W.delete(ie);R.size===0&&W.size>=J.size&&(Q.push(...W),q.push(`deletion of ALL ${W.size} remaining file(s) deferred \u2014 GitHub cannot create an empty tree; the deletes re-derive and propagate once the repo has at least one surviving file`),W.clear())}if(R.size===0&&W.size===0)break;let N=new Map;for(let[ie,ye]of R)if(typeof ye=="string")N.set(ie,ye);else{let G=Zz(ye);G!==null&&N.set(ie,G)}let j=(0,Yz.scanForSecrets)(N);if(j.length>0)return{kind:"secret-detected",detail:`secret-scan: refusing to push \u2014 ${j.map(ie=>`${ie.path} (${ie.kind})`).join(", ")} (R5); remove the secret and re-sync`};try{T=await(0,Kz.restCreateCommit)(this.transport,{owner:e.owner,repo:e.repo,branch:e.branch,files:new Map([...R].map(([ie,ye])=>[ie,eH(ye)])),deletions:[...W],message:this.deps.commitMessage?.(e,R.size,W.size)??`chore(exosync): sync ${R.size} file(s)${W.size>0?`, ${W.size} deletion(s)`:""}`,baseURL:this.deps.baseURL,redact:this.deps.redact});break}catch(ie){if(!KP(ie))throw ie;if(b++,b>w)return{kind:"retry-exhausted",detail:`non-fast-forward push failed after ${w} retries (D16 cap) \u2014 contended files routed to quarantine (D17)`,pushFiles:R,merge:P};s.push(`non-fast-forward push (attempt ${b}/${w}) \u2014 re-pulling and retrying (D16)`)}}return{kind:"done",examinedHead:S,pushedSha:T,applyWrites:x,applyDeletes:I,pushFiles:R,pushedDeletions:T!==void 0?[...W]:[],withheldDeletions:Q,merge:P,remoteOversized:B,alreadyInHead:D,deferredPaths:k,deferredRemoteChanges:X,deferredWarnings:q}}async resolveMergeConflicts(e,t,r,i){let s=this.deps.mergeLayer;if(s===void 0)return WE;let o=new Map(t.files.map(y=>[y.path,y])),c=new Map,l=[],u=[],f=[],d=[],h=0,p=a(y=>typeof y=="string"?y:void 0,"asText"),g=a((y,w,b)=>{let S=p(i.get(y.local.path)),T=p(y.remotes[0]?.content);return{repoKey:e.repoKey,path:y.local.path,...y.local.uid!==void 0?{uid:y.local.uid}:{},reason:w,...b!==void 0?{baseContent:b}:{},...S!==void 0?{localContent:S}:{},...T!==void 0?{remoteContent:T}:{}}},"entry");for(let y of r){let w=o.get(y.local.basePath??y.local.path)??o.get(y.remotes[0]?.path??""),b;if(w!==void 0&&(b=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,w.blobSha,this.deps.baseURL)),y.remotes.length>1){u.push(g(y,`ambiguous conflict: local change overlaps ${y.remotes.length} remote changes (${y.remotes.map(R=>R.path).join(", ")})`,b));continue}let S=y.remotes[0],T=p(i.get(y.local.path)),x=await s.resolve({path:y.local.path,...y.local.uid!==void 0?{uid:y.local.uid}:{},...b!==void 0?{base:b}:{},...T!==void 0?{local:T}:{},...S.kind==="change"&&typeof S.content=="string"?{remote:S.content}:{}});if(x.action==="quarantine"){u.push(g(y,x.reason,b));continue}h++,d.push(y.local.path);for(let R of x.warnings??[])f.push(`merge(${y.local.path}): ${R}`);let I=S.kind==="change"?S.content:void 0;if(x.content!==I&&c.set(y.local.path,x.content),x.content!==i.get(y.local.path)){let R=(0,gc.extractAssetUid)(x.content)??y.local.uid;l.push({path:y.local.path,kind:"change",content:x.content,blobSha:await(0,cd.gitBlobSha)(x.content,this.deps.sha1),...R!==void 0?{uid:R}:{}})}}return{mergedFiles:c,mergedWrites:l,quarantineEntries:u,resolvedQuarantineEntries:[],mergedCount:h,mergedPaths:d,warnings:f}}resolveFileModeConflicts(e,t,r,i,s){let o=[],c=[];for(let l of t){l.remotes.length>1&&c.push(`file-mode conflict on ${l.local.path} unexpectedly overlaps ${l.remotes.length} remote changes \u2014 resolving against the first`);let u=l.remotes[0],f=r.get(l.local.path);u.kind==="change"?i.push(u):s.push(u),!(l.localIsDelete||f===void 0)&&o.push({repoKey:e.repoKey,path:l.local.path,reason:`file-mode remote-wins (D18): remote ${u.kind==="change"?`version ${u.blobSha}`:"delete"} wins; this is the losing LOCAL version, preserved byte-exact`,...typeof f=="string"?{localContent:f}:{localContentBytes:f}})}return{mergedFiles:new Map,mergedWrites:[],quarantineEntries:[],resolvedQuarantineEntries:o,mergedCount:0,mergedPaths:[],warnings:c}}async applyRemoteChanges(e,t,r,i,s){let o=0,c=new Set,l=a(async(f,d)=>{try{return d?await WP(e,f):await e.read(f)}catch{return}},"tryRead"),u=a(async(f,d)=>{typeof d=="string"?await e.write(f,d):await tH(e,f,d)},"writeContent");for(let f of r){if(f.content===void 0)continue;if(!zP(f.path)){s.push(`unsafe remote path skipped on pull-apply: ${f.path}`),c.add(f.path);continue}let d=t.get(f.path),h=await l(f.path,typeof(d??f.content)!="string");if(!(0,Cs.contentEquals)(h,d)){s.push(`pull-apply skipped: ${f.path} changed on disk mid-sync (TOCTOU) \u2014 remote change re-derives next sync`),c.add(f.path);continue}await u(f.path,f.content),o++}for(let f of i){if(!zP(f.path)){s.push(`unsafe remote path skipped on pull-delete: ${f.path}`),c.add(f.path);continue}let d=t.get(f.path);if(d!==void 0){let h=await l(f.path,typeof d!="string");if(h!==void 0&&!(0,Cs.contentEquals)(h,d)){s.push(`pull-delete skipped: ${f.path} changed on disk mid-sync (TOCTOU) \u2014 delete-vs-modify re-derives next sync`),c.add(f.path);continue}await e.delete(f.path),o++}}return{pulledCount:o,pinnedPaths:c}}async advanceWatermark(e,t,r,i,s,o,c,l,u,f=new Set){let d=(await(0,yt.getTree)(this.transport,e.owner,e.repo,r,this.deps.baseURL)).filter(p=>u.treeFilter(p)&&!f.has(p.path)),h=nH(await this.buildWatermarkFiles(e,d,i,s,o,l,u),o,c);await this.deps.watermarkStore.set(e.repoKey,{lastSyncedSha:t,rootTreeSha:r,files:h,...c.size>0?{pinnedPaths:[...c]}:{},...u.fileMode?{spaceKind:"file"}:{}})}async tryMountBaseBootstrap(e,t,r,i,s){let o=this.deps.mountBaseStore,c=null;if(o!==void 0)try{c=await o.get(e.repoKey)}catch{return null}let l=!1;if(c===null&&this.deps.localBaseShaProvider!==void 0)try{let w=await this.deps.localBaseShaProvider(e);typeof w=="string"&&w.length>0&&(c=w,l=!0)}catch{}if(c===null||t.startsWith(c))return null;let u=300,f=null;try{let w=t;for(let b=0;b<u;b++){let S=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,w,this.deps.baseURL);if(S.sha===c||S.sha.startsWith(c)){f=S;break}if(S.parents.length===0)break;w=S.parents[0]}}catch{return null}if(f===null)return null;let d;try{d=(await(0,yt.getTree)(this.transport,e.owner,e.repo,f.treeSha,this.deps.baseURL)).filter(w=>(0,Cs.isSyncablePath)(w.path))}catch{return null}let h;try{let w=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,t,this.deps.baseURL);h=zE((await(0,yt.getTree)(this.transport,e.owner,e.repo,w.treeSha,this.deps.baseURL)).filter(b=>(0,Cs.isSyncablePath)(b.path)))}catch{return null}let p=d.filter(w=>!r.has(w.path)&&h.get(w.path)===w.blobSha);if(p.length>0){let w=p.slice(0,3).map(b=>b.path).join(", ")+(p.length>3?", \u2026":"");return i.push(`first-sync (asset mode): base-tree\u2286working-tree sanity guard fired \u2014 ${p.length} base file(s) absent from the working tree but UNCHANGED on remote head (${w}); the verified-ancestor base may not match the working tree's derivation commit (out-of-band submodule manipulation) \u2192 routing to merge/quarantine instead of inferring a silent deletion (#3610)`),{kind:"settled",outcome:s("full-conflict",{detail:`first-sync: base-tree\u2286working-tree sanity guard \u2014 ${p.length} base file(s) absent from the working tree are unchanged on remote head (${w}); refusing to infer a silent deletion from a base that may not match the derivation commit \u2014 divergence must go through merge/quarantine (A2/A3), never a silent delete (#3610)`})}}let g=d.map(w=>({path:w.path,blobSha:w.blobSha})),y={lastSyncedSha:f.sha,rootTreeSha:f.treeSha,files:g};if(l&&o!==void 0)try{await o.set(e.repoKey,f.sha)}catch{}return i.push(l?`first-sync (asset mode): BACKFILLED the 3-way base from the locally checked-out commit ${f.sha} (no recorded mount base) \u2014 remote head ${t} advanced since; local edits 3-way merge against it instead of false-conflicting (#3590)`:`first-sync (asset mode): reconciling against the recorded mount base ${f.sha} \u2014 remote head ${t} advanced since mount; local edits 3-way merge against it instead of false-conflicting (#3590)`),{kind:"additive-base",base:y}}async bootstrapWatermark(e,t,r,i){let s=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),o=await this.tryMountBaseBootstrap(e,s,t,r,i);if(o!==null)return o;let c=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,s,this.deps.baseURL),l=(await(0,yt.getTree)(this.transport,e.owner,e.repo,c.treeSha,this.deps.baseURL)).filter(d=>(0,Cs.isSyncablePath)(d.path));for(let d of l){let h=t.get(d.path);if(h===void 0||await(0,cd.gitBlobSha)(h,this.deps.sha1)!==d.blobSha)return{kind:"settled",outcome:i("full-conflict",{detail:`first-sync: no watermark and local content diverges from remote head at ${d.path} \u2014 A2/A3 scope`})}}let u=l.map(d=>{let h=t.get(d.path),p=typeof h=="string"?(0,gc.extractAssetUid)(h):void 0;return{path:d.path,blobSha:d.blobSha,...p?{uid:p}:{}}}),f={lastSyncedSha:s,rootTreeSha:c.treeSha,files:u};return t.size===l.length?(await this.deps.watermarkStore.set(e.repoKey,f),r.push(`watermark bootstrapped from head ${s} (local tree identical to remote)`),{kind:"settled",outcome:i("synced")}):(r.push(`first-sync (asset mode): local tree (${t.size} files) is a pure superset of remote head ${s} (${l.length} files) \u2014 ${t.size-l.length} local-only addition(s) derive as pushable adds (#3565)`),{kind:"additive-base",base:f})}async collectRemoteChanges(e,t,r,i,s=new Set,o=[],c=new Set){let l=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,r,this.deps.baseURL),u=await(0,yt.getTree)(this.transport,e.owner,e.repo,l.treeSha,this.deps.baseURL);if(i.fileMode)for(let y of u)i.syncable(y.path)&&!i.treeFilter(y)&&!c.has(y.path)&&(c.add(y.path),o.push(`skipped oversized REMOTE file ${y.path} (${y.size??"?"} bytes over cap) \u2014 excluded from sync symmetrically (Phase C size cap)`));let f=u.filter(y=>i.treeFilter(y)&&!s.has(y.path)),d=t.files.filter(y=>!c.has(y.path)&&!s.has(y.path)),{changed:h,deleted:p}=HP(d,f),g=[];for(let y of h){if(i.fileMode){let b=await(0,yt.getBlobBytes)(this.transport,e.owner,e.repo,y.blobSha,this.deps.baseURL);g.push({path:y.path,kind:"change",blobSha:y.blobSha,content:b});continue}let w=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,y.blobSha,this.deps.baseURL);g.push({path:y.path,kind:"change",blobSha:y.blobSha,content:w,uid:(0,gc.extractAssetUid)(w)})}for(let y of p)g.push({path:y.path,kind:"delete",uid:y.uid});return{changes:g,headTreeByPath:zE(u)}}matchLocalVsRemote(e,t,r,i,s,o=new Set,c){let l=new Set,u=[],f=new Map;for(let y of i)y.kind==="change"&&y.uid!==void 0&&f.set(y.uid,(f.get(y.uid)??0)+1);let d=new Set(o);for(let[y,w]of f)w>1&&d.add(y);let h=new Map,p=new Map;for(let y of i){if(y.uid!==void 0&&!d.has(y.uid)){let w=h.get(y.uid)??[];w.push(y),h.set(y.uid,w)}p.set(y.path,y)}for(let y of e){let w=new Set;if(y.uid!==void 0&&!d.has(y.uid))for(let x of h.get(y.uid)??[])x.kind==="change"&&x.path!==y.path&&(c?.has(y.path)===!0||y.basePath!==void 0&&c?.has(y.basePath)===!0)||w.add(x);let b=p.get(y.path);if(b!==void 0&&w.add(b),y.basePath!==void 0){let x=p.get(y.basePath);x!==void 0&&w.add(x)}let S=[],T=!1;for(let x of w){if(T=t.has(y.path)&&!r.has(y.path),T&&x.kind==="delete"){l.add(x);continue}if(!T&&x.kind==="change"&&x.path===y.path&&x.blobSha===y.blobSha){l.add(x),s.add(y.path);continue}if(x.kind==="delete"&&y.basePath!==void 0&&x.path===y.basePath){let I=p.get(y.path);if(I!==void 0&&I.kind==="change"&&I.blobSha===y.blobSha){l.add(x);continue}}S.push(x),l.add(x)}S.length>0&&(u.push({local:y,localIsDelete:T,remotes:S,desc:`${y.uid!==void 0&&!d.has(y.uid)?y.uid:y.path} (local ${T?"delete":"change"} vs remote ${S[0].kind} at ${S[0].path})`}),s.add(y.path))}let g=i.filter(y=>!l.has(y));return{conflicts:u,applyWrites:g.filter(y=>y.kind==="change"),applyDeletes:g.filter(y=>y.kind==="delete")}}async checkRaceWindow(e,t,r,i,s,o,c,l){try{let u=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,i,this.deps.baseURL),f=(await(0,yt.getTree)(this.transport,e.owner,e.repo,u.treeSha,this.deps.baseURL)).filter(l.treeFilter),d=r===t.lastSyncedSha?t.files:(await(0,yt.getTree)(this.transport,e.owner,e.repo,(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,r,this.deps.baseURL)).treeSha,this.deps.baseURL)).filter(l.treeFilter),{changed:h,deleted:p}=HP(d,f);for(let g of h)s.has(g.path)&&c.push(`race-window: concurrent commit ${i} changed ${g.path} between conflict check (head ${r}) and push \u2014 local version won; previous version recoverable from git history`),o.has(g.path)&&c.push(`race-window: concurrent commit ${i} changed ${g.path} which this push DELETED \u2014 the delete won; the concurrent version is recoverable from git history`);for(let g of p)s.has(g.path)&&c.push(`race-window: concurrent commit ${i} deleted ${g.path}; push re-created it`)}catch(u){let f=this.deps.redact??(d=>d);c.push(`race-window check failed: ${f(tu(u))}`)}}async buildWatermarkFiles(e,t,r,i,s,o,c){if(c.fileMode)return t.map(f=>({path:f.path,blobSha:f.blobSha}));let l=new Map;for(let f of i)f.kind==="change"&&f.blobSha!==void 0&&l.set(f.blobSha,f.uid);for(let[f,d]of r){let h=o?.get(f)??await(0,cd.gitBlobSha)(d,this.deps.sha1);l.set(h,typeof d=="string"?(0,gc.extractAssetUid)(d):void 0)}for(let f of s.files)l.has(f.blobSha)||l.set(f.blobSha,f.uid);let u=[];for(let f of t){let d;if(l.has(f.blobSha))d=l.get(f.blobSha);else{let h=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,f.blobSha,this.deps.baseURL);d=(0,gc.extractAssetUid)(h)}u.push({path:f.path,blobSha:f.blobSha,...d?{uid:d}:{}})}return u}};Ps.SyncEngine=HE});var YE=v(QE=>{"use strict";Object.defineProperty(QE,"__esModule",{value:!0});QE.diff3=iH;function XP(n,e){let t=n.length,r=e.length,i=Array.from({length:t+1},()=>new Int32Array(r+1));for(let l=t-1;l>=0;l--)for(let u=r-1;u>=0;u--)i[l][u]=n[l]===e[u]?i[l+1][u+1]+1:Math.max(i[l+1][u],i[l][u+1]);let s=new Map,o=0,c=0;for(;o<t&&c<r;)n[o]===e[c]?(s.set(o,c),o++,c++):i[o+1][c]>=i[o][c+1]?o++:c++;return s}a(XP,"lcsMatch");function XE(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}a(XE,"sliceEq");function iH(n,e,t){let r=XP(n,e),i=XP(n,t),s=[],o=0,c=0,l=0;for(;;){let u=o;for(;u<n.length&&!(r.has(u)&&i.has(u));)u++;let f=u<n.length?r.get(u):e.length,d=u<n.length?i.get(u):t.length,h=n.slice(o,u),p=e.slice(c,f),g=t.slice(l,d),y=!XE(p,h),w=!XE(g,h);if(!y&&!w)s.push(...h);else if(!y)s.push(...g);else if(!w)s.push(...p);else if(XE(p,g))s.push(...p);else return{ok:!1,conflict:{base:h,local:p,remote:g}};if(u>=n.length)break;s.push(n[u]),o=u+1,c=f+1,l=d+1}return{ok:!0,merged:s}}a(iH,"diff3")});var YP=v(fd=>{"use strict";Object.defineProperty(fd,"__esModule",{value:!0});fd.StructuredMerger=void 0;fd.splitSections=py;var QP=YE(),sH=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,ld="exo__Instance_class";function ud(n){if(n===null||typeof n!="object")return!0;if(Array.isArray(n))return n.every(ud);let e=Object.getPrototypeOf(n);return e!==Object.prototype&&e!==null?!1:Object.values(n).every(ud)}a(ud,"isPlainValue");function ca(n,e){if(n===e)return!0;if(n===null||e===null||n===void 0||e===void 0||typeof n!="object"||typeof e!="object"||Array.isArray(n)!==Array.isArray(e))return!1;if(Array.isArray(n)&&Array.isArray(e))return n.length!==e.length?!1:n.every((s,o)=>ca(s,e[o]));let t=n,r=e,i=Object.keys(t);return i.length!==Object.keys(r).length?!1:i.every(s=>ca(t[s],r[s]))}a(ca,"deepEqual");function yc(n){return typeof n=="string"?`s:${n}`:`j:${JSON.stringify(n)}`}a(yc,"setKey");function li(n){return n==null?[]:Array.isArray(n)?n:[n]}a(li,"toElements");function oH(n,e,t){let r=new Set(li(n).map(yc)),i=li(e),s=li(t),o=new Set(i.map(yc)),c=new Set(s.map(yc)),l=a(d=>o.has(d)&&c.has(d)||o.has(d)&&!r.has(d)||c.has(d)&&!r.has(d),"keep"),u=[],f=new Set;for(let d of[...i,...s]){let h=yc(d);f.has(h)||!l(h)||(f.add(h),u.push(d))}return u}a(oH,"mergeSet");function aH(n,e,t){let r=[],i=[],s=new Set;for(let c of[...Object.keys(n),...Object.keys(e),...Object.keys(t)])s.has(c)||(s.add(c),i.push(c));let o={};for(let c of i){let l=n[c],u=e[c],f=t[c];if(!ud(l)||!ud(u)||!ud(f))return{ok:!1,reason:`frontmatter key "${c}" contains a non-plain value (Date?) \u2014 the codec must round-trip scalars as strings (CORE_SCHEMA contract)`};if(Array.isArray(l)||Array.isArray(u)||Array.isArray(f)){if(!(c in e)&&!(c in t))continue;let d=oH(l,u,f),h=new Set(li(l).map(yc)),p=li(u).some(y=>!h.has(yc(y))),g=li(f).some(y=>!h.has(yc(y)));p&&g&&!ca(li(u),li(f))&&r.push(`both sides added values to multi-valued key "${c}" \u2014 union kept (D20)`),d.length>0&&(o[c]=d);continue}if(ca(u,f)){u!==void 0&&(o[c]=u);continue}if(ca(u,l)){f!==void 0&&(o[c]=f);continue}if(ca(f,l)){u!==void 0&&(o[c]=u);continue}return{ok:!1,reason:`frontmatter key "${c}" changed differently on both sides`}}return{ok:!0,value:o,warnings:r}}a(aH,"mergeFrontmatter");var cH=/^(```|~~~)/,lH=/^#{1,6}\s/;function py(n){let e=n.split(`
|
|
309
|
+
`)}a(Pz,"stripGitmodulesEntry")});var sd=v(BE=>{"use strict";Object.defineProperty(BE,"__esModule",{value:!0});BE.gitBlobSha=Oz;async function Oz(n,e){let t=new TextEncoder,r=typeof n=="string"?t.encode(n):n,i=t.encode(`blob ${r.byteLength}\0`),s=new Uint8Array(i.byteLength+r.byteLength);return s.set(i,0),s.set(r,i.byteLength),e(s)}a(Oz,"gitBlobSha")});var VE=v(oy=>{"use strict";Object.defineProperty(oy,"__esModule",{value:!0});oy.extractAssetUid=BP;oy.detectChanges=Dz;var Fz=sd();function BP(n){let e=/^---\r?\n([\s\S]*?)\r?\n---(?=\r?\n|$)/.exec(n);if(!e)return;let t=/^exo__Asset_uid:[ \t]*["']?([^\s"']+)["']?[ \t]*$/m.exec(e[1]);return t?t[1]:void 0}a(BP,"extractAssetUid");async function Dz(n){let{localFiles:e,watermark:t,actualBaseTreeSha:r,sha1:i}=n;if(t===null)return{kind:"full-conflict",reason:"first-sync"};if(r===null)return{kind:"full-conflict",reason:"base-mismatch",detail:`watermark commit ${t.lastSyncedSha} not resolvable on remote`};if(r!==t.rootTreeSha)return{kind:"full-conflict",reason:"base-mismatch",detail:`stored root tree ${t.rootTreeSha} != actual ${r} at ${t.lastSyncedSha}`};let s=[],o=new Map;for(let[T,x]of e){let I=await(0,Fz.gitBlobSha)(x,i);o.set(T,I),s.push({path:T,blobSha:I,uid:typeof x=="string"?BP(x):void 0})}let c=[],l=[],u=[],f=[],d=new Map;for(let T of s){if(T.uid===void 0)continue;let x=d.get(T.uid)??[];x.push(T.path),d.set(T.uid,x)}let h=new Map;for(let T of t.files){if(T.uid===void 0)continue;let x=h.get(T.uid)??[];x.push(T.path),h.set(T.uid,x)}let p=new Set;for(let[T,x]of d)x.length>1&&p.add(T);for(let[T,x]of h)x.length>1&&p.add(T);for(let T of[...p].sort()){let x=d.get(T)??[],I=x.length>1?`on disk (${x.join(", ")})`:`in the sync base (${(h.get(T)??[]).join(", ")})`;f.push(`duplicate uid ${T} ${I} \u2014 uid identity suppressed for the group; every path matched by path identity (#3477)`)}let g=new Map,y=[];for(let T of t.files)T.uid!==void 0&&!p.has(T.uid)?g.set(T.uid,T):y.push(T);let w=[],b=new Set;for(let T of s){let x=T.uid!==void 0&&!p.has(T.uid)?g.get(T.uid):void 0;T.uid!==void 0&&x!==void 0?(b.add(T.uid),(x.blobSha!==T.blobSha||x.path!==T.path)&&l.push({path:T.path,uid:T.uid,blobSha:T.blobSha,...x.path!==T.path?{basePath:x.path}:{}})):w.push(T)}let S=new Map;for(let T of y)S.set(T.path,T);for(let[T,x]of g)b.has(T)||S.set(x.path,x);for(let T of w){let x=S.get(T.path);x!==void 0?(S.delete(T.path),x.blobSha!==T.blobSha&&l.push({path:T.path,uid:T.uid,blobSha:T.blobSha})):c.push({path:T.path,uid:T.uid,blobSha:T.blobSha})}for(let T of S.values())u.push({path:T.path,uid:T.uid,blobSha:T.blobSha});return{kind:"changes",added:c,modified:l,deleted:u,warnings:f,diskBlobShas:o,duplicateUids:p}}a(Dz,"detectChanges")});var ad=v(mc=>{"use strict";Object.defineProperty(mc,"__esModule",{value:!0});mc.getHeadSha=Nz;mc.getCommitInfo=kz;mc.getTree=Mz;mc.getBlobText=jz;mc.getBlobBytes=$z;var VP=Jc(),Lz="https://api.github.com";function od(n){return(n??Lz).replace(/\/$/,"")}a(od,"api");function pc(n){return n!==null&&typeof n=="object"?n:void 0}a(pc,"asRecord");function Rs(n,e){let r=pc(n)?.[e];return typeof r=="string"?r:void 0}a(Rs,"readString");async function Nz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/refs/heads/${encodeURIComponent(r)}`}),o=Rs(pc(s?.json)?.object,"sha");if(typeof o!="string"||o.length===0)throw new Error(`ExoSync: missing object.sha for ref heads/${r}`);return o}a(Nz,"getHeadSha");async function kz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/commits/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"sha"),l=Rs(o?.tree,"sha");if(!c||!l)throw new Error(`ExoSync: malformed commit response for ${r}`);let u=o?.parents,f=Array.isArray(u)?u.map(d=>Rs(d,"sha")).filter(d=>typeof d=="string"):[];return{sha:c,treeSha:l,parents:f}}a(kz,"getCommitInfo");async function Mz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/trees/${encodeURIComponent(r)}?recursive=1`}),o=pc(s?.json);if(o?.truncated===!0)throw new Error(`ExoSync: tree ${r} is truncated by GitHub (repo too large for recursive listing) \u2014 refusing to diff`);let c=o?.tree;if(!Array.isArray(c))throw new Error(`ExoSync: malformed tree response for ${r}`);let l=[];for(let u of c){let f=pc(u);if(f?.type!=="blob")continue;let d=Rs(f,"path"),h=Rs(f,"sha"),p=typeof f.size=="number"?f.size:void 0;d&&h&&l.push({path:d,blobSha:h,...p!==void 0?{size:p}:{}})}return l}a(Mz,"getTree");async function jz(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/blobs/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"content");if(typeof c!="string")throw new Error(`ExoSync: malformed blob response for ${r}`);return Rs(o,"encoding")==="utf-8"?c:(0,VP.base64ToUtf8)(c)}a(jz,"getBlobText");async function $z(n,e,t,r,i){let s=await n({method:"GET",url:`${od(i)}/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}/git/blobs/${encodeURIComponent(r)}`}),o=pc(s?.json),c=Rs(o,"content");if(typeof c!="string")throw new Error(`ExoSync: malformed blob response for ${r}`);return Rs(o,"encoding")==="utf-8"?new TextEncoder().encode(c):(0,VP.base64ToBytes)(c)}a($z,"getBlobBytes")});var ay=v(qE=>{"use strict";Object.defineProperty(qE,"__esModule",{value:!0});qE.isAuthError=Uz;function Uz(n){let e=n instanceof Error?n.message:String(n);return/HTTP 401/.test(e)?!0:/HTTP 403/.test(e)&&!/rate limit/i.test(e)&&!/abuse detection/i.test(e)}a(Uz,"isAuthError")});var ly=v(cy=>{"use strict";Object.defineProperty(cy,"__esModule",{value:!0});cy.scanForSecrets=Bz;cy.redactSecrets=Vz;var qP=[{kind:"github-token",re:/gh[pousr]_[A-Za-z0-9_]{36,}/},{kind:"github-fine-grained-token",re:/github_pat_[A-Za-z0-9_]{22,}_[A-Za-z0-9_]{59,}/},{kind:"private-key",re:/-----BEGIN [A-Z ]*PRIVATE KEY-----/}];function Bz(n){let e=[];for(let[t,r]of n)for(let{kind:i,re:s}of qP)s.test(r)&&e.push({path:t,kind:i});return e}a(Bz,"scanForSecrets");function Vz(n){let e=n;for(let{kind:t,re:r}of qP)e=e.replace(new RegExp(r.source,"g"),`[REDACTED:${t}]`);return e}a(Vz,"redactSecrets")});var fy=v(uy=>{"use strict";Object.defineProperty(uy,"__esModule",{value:!0});uy.isRateLimitError=GP;uy.withRateLimitBackoff=Gz;function GP(n){let e=n instanceof Error?n.message:String(n);return/HTTP 429/.test(e)?!0:/HTTP 403/.test(e)&&(/rate limit/i.test(e)||/abuse detection/i.test(e))}a(GP,"isRateLimitError");var qz=a(n=>new Promise(e=>setTimeout(e,n)),"defaultSleep");function Gz(n,e={}){let t=e.maxRetries??3,r=e.baseDelayMs??1e3,i=e.sleep??qz,s=e.random??Math.random;return async o=>{let c=0;for(;;)try{return await n(o)}catch(l){if(!GP(l)||c>=t)throw l;let u=r*2**c*(1+s());c++,await i(u)}}}a(Gz,"withRateLimitBackoff")});var dy=v(vo=>{"use strict";Object.defineProperty(vo,"__esModule",{value:!0});vo.DEFAULT_MAX_FILE_BYTES=vo.InMemoryQuarantineStore=void 0;vo.contentEquals=Wz;vo.isSyncablePath=zz;vo.isFileSpaceSyncablePath=Hz;function Wz(n,e){if(n===void 0||e===void 0||typeof n=="string"&&typeof e=="string")return n===e;if(typeof n=="string"||typeof e=="string"||n.byteLength!==e.byteLength)return!1;for(let t=0;t<n.byteLength;t++)if(n[t]!==e[t])return!1;return!0}a(Wz,"contentEquals");var GE=class{static{a(this,"InMemoryQuarantineStore")}constructor(){this.entries=[]}async quarantine(e){this.entries.push(e)}};vo.InMemoryQuarantineStore=GE;function zz(n){return n.endsWith(".md")&&!n.includes(".local.")&&!n.includes(".conflict.")}a(zz,"isSyncablePath");function Hz(n){return!n.includes(".local.")&&!n.includes(".conflict.")}a(Hz,"isFileSpaceSyncablePath");vo.DEFAULT_MAX_FILE_BYTES=30*1024*1024});var KE=v(Ps=>{"use strict";Object.defineProperty(Ps,"__esModule",{value:!0});Ps.SyncEngine=Ps.DEFAULT_MAX_PUSH_RETRIES=void 0;Ps.isNonFastForwardError=KP;Ps.orderChildrenFirst=rH;var Kz=iy(),yt=ad(),gc=VE(),Xz=Jc(),cd=sd(),Qz=ay(),Yz=ly(),Jz=fy(),Cs=dy();Ps.DEFAULT_MAX_PUSH_RETRIES=3;function Zz(n){try{return new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{return null}}a(Zz,"decodeUtf8Strict");function eH(n){return typeof n=="string"?n:{base64:(0,Xz.bytesToBase64)(n)}}a(eH,"toCommitContent");async function WP(n,e){if(n.readBinary===void 0)throw new Error("LocalFilesPort.readBinary is required for file-mode sync (Phase C)");return n.readBinary(e)}a(WP,"readBinaryStrict");async function tH(n,e,t){if(n.writeBinary===void 0)throw new Error("LocalFilesPort.writeBinary is required for file-mode sync (Phase C)");return n.writeBinary(e,t)}a(tH,"writeBinaryStrict");function zP(n){return n.length===0||n.startsWith("/")||n.includes("\\")?!1:n.split("/").every(e=>e.length>0&&e!=="."&&e!=="..")}a(zP,"isSafeRepoRelativePath");function KP(n){let e=n instanceof Error?n.message:String(n);return/HTTP 422/.test(e)&&/git\/refs/.test(e)||/ref update mismatch/.test(e)||/HTTP 422/.test(e)&&/git\/trees/.test(e)&&/BadObjectState/.test(e)}a(KP,"isNonFastForwardError");function rH(n){let e=a(t=>t.split("/").filter(r=>r.length>0).length,"depth");return[...n].sort((t,r)=>e(r.localPath)-e(t.localPath))}a(rH,"orderChildrenFirst");function HP(n,e){let t=new Map(n.map(o=>[o.path,o])),r=new Set,i=[];for(let o of e){r.add(o.path);let c=t.get(o.path);(c===void 0||c.blobSha!==o.blobSha)&&i.push(o)}let s=n.filter(o=>!r.has(o.path));return{changed:i,deleted:s}}a(HP,"diffTrees");function tu(n){return n instanceof Error?n.message:String(n)}a(tu,"errMsg");function nH(n,e,t){if(t.size===0)return n;let r=new Map(e.files.map(o=>[o.path,o])),i=new Set(n.map(o=>o.path)),s=[];for(let o of n){if(!t.has(o.path)){s.push(o);continue}let c=r.get(o.path);c!==void 0&&s.push(c)}for(let o of t){if(i.has(o))continue;let c=r.get(o);c!==void 0&&s.push(c)}return s}a(nH,"applyWatermarkPins");var WE={mergedFiles:new Map,mergedWrites:[],quarantineEntries:[],resolvedQuarantineEntries:[],mergedCount:0,mergedPaths:[],warnings:[]};function zE(n){return new Map(n.map(e=>[e.path,e.blobSha]))}a(zE,"treeByPath");function hy(n){return[...n.quarantineEntries.map(e=>e.path),...n.resolvedQuarantineEntries.map(e=>e.path)]}a(hy,"quarantinedPathsOf");var HE=class{static{a(this,"SyncEngine")}constructor(e){this.opInProgress=!1,this.deps=e,this.transport=(0,Jz.withRateLimitBackoff)(e.transport,e.backoff)}busyResult(e){return{repoKey:e.repoKey,status:"busy",pulledCount:0,pushedCount:0,mergedCount:0,quarantinedCount:0,warnings:[],deferredDeletes:[],detail:"another sync operation is in progress (D11 guard) \u2014 retry after it finishes"}}modeOps(e){let t=e.spaceKind==="file",r=t?Cs.isFileSpaceSyncablePath:Cs.isSyncablePath,i=this.deps.maxFileBytes??Cs.DEFAULT_MAX_FILE_BYTES;return{fileMode:t,syncable:r,treeFilter:a(s=>r(s.path)&&(!t||s.size===void 0||s.size<=i),"treeFilter")}}async buildFileModeFirstSyncBase(e,t,r,i){let s=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),o=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,s,this.deps.baseURL),c=(await(0,yt.getTree)(this.transport,e.owner,e.repo,o.treeSha,this.deps.baseURL)).filter(r.treeFilter),l=[];for(let u of c){let f=t.get(u.path);f!==void 0&&await(0,cd.gitBlobSha)(f,this.deps.sha1)===u.blobSha&&l.push({path:u.path,blobSha:u.blobSha})}return i.push(`first-sync (file mode): synthetic base from ${l.length} already-identical file(s) at head ${s} \u2014 divergence resolves through the remote-wins layer (D22)`),{lastSyncedSha:s,rootTreeSha:o.treeSha,files:l,spaceKind:"file"}}async syncAll(e,t="sync",r){if(this.opInProgress)return e.map(i=>this.busyResult(i));this.opInProgress=!0;try{let i=[];for(let s of e)i.push(await this.syncLocked(s,t,r));return i}finally{this.opInProgress=!1}}async sync(e,t="sync",r){if(this.opInProgress)return this.busyResult(e);this.opInProgress=!0;try{return await this.syncLocked(e,t,r)}finally{this.opInProgress=!1}}emitProgress(e,t,r){if(e!==void 0)try{e({repoKey:t,phase:r})}catch{}}async syncLocked(e,t="sync",r){let i=[],s=[],o=[],c=a((l,u={})=>({repoKey:e.repoKey,status:l,pulledCount:0,pushedCount:0,mergedCount:0,quarantinedCount:0,warnings:i,deferredDeletes:s,...u}),"result");try{let l=await this.deps.materializationCheck.check(e);if(!l.fullyMaterialized)return i.push(`skipped: repo not fully materialized${l.reason?` (${l.reason})`:""} \u2014 deletes NOT inferred (D19)`),c("skipped-not-materialized");let u=this.modeOps(e),f=this.deps.localFilesFor(e);if(u.fileMode&&(f.readBinary===void 0||f.writeBinary===void 0))return c("error",{detail:"file-mode repo requires a LocalFilesPort with readBinary/writeBinary \u2014 refusing to sync through the text-only port (binary would corrupt)"});if(u.fileMode&&this.deps.quarantine===void 0)return c("error",{detail:"file-mode repo requires a quarantine sink (D18 remote-wins preserves losing local bytes there) \u2014 configure the quarantine repo before syncing FileSpaces"});let d=this.deps.maxFileBytes??Cs.DEFAULT_MAX_FILE_BYTES,h=new Map,p=new Set;for(let N of(await f.list()).filter(u.syncable))if(u.fileMode){let j=await WP(f,N);if(j.byteLength>d){p.add(N),i.push(`skipped oversized file ${N} (${j.byteLength} bytes > ${d} cap) \u2014 excluded from sync symmetrically (Phase C size cap)`);continue}h.set(N,j)}else h.set(N,await f.read(N));let g=await this.deps.watermarkStore.get(e.repoKey);if(g?.spaceKind==="file"&&!u.fileMode)return c("error",{detail:"watermark was written by a FILE-mode sync but the spec now resolves to asset mode \u2014 refusing (fix the conflicting Space declarations, or clear the watermark to restart)"});g!==null&&u.fileMode&&g.spaceKind!=="file"&&(i.push("watermark was written by an ASSET-mode sync \u2014 rebuilding the base through the file-mode first-sync layer (kind flip)"),g=null);let y=!1;if(g===null)if(u.fileMode)y=!0,g=await this.buildFileModeFirstSyncBase(e,h,u,i);else{let N=await this.bootstrapWatermark(e,h,i,c);if(N.kind==="settled")return N.outcome;y=!0,g=N.base}let w=g;u.fileMode&&p.size>0&&(g={...g,files:g.files.filter(N=>!p.has(N.path))}),this.emitProgress(r,e.repoKey,"detecting");let b=await(0,gc.detectChanges)({localFiles:h,watermark:g,actualBaseTreeSha:await this.resolveBaseTreeSha(e,g),sha1:this.deps.sha1});if(b.kind==="full-conflict")return c("full-conflict",{detail:`${b.reason}${b.detail?`: ${b.detail}`:""} \u2014 divergence must go through merge/quarantine (A2/A3), not overwrite`});i.push(...b.warnings);let S=this.pinLocalChanges(b,h,i,s,t);o=[...S.pushDeletionsAll.keys()];let T=await this.runPushLoop(e,g,S,h,i,u,y,p,t,r);if(o=[],T.kind!=="done"&&S.pushDeletionsAll.size>0&&s.push(...S.pushDeletionsAll.keys()),T.kind==="conflict")return c("conflict",{detail:T.detail});if(T.kind==="secret-detected")return c("error",{detail:T.detail});if(T.kind==="retry-exhausted"){i.push(...T.merge.warnings);let N=await this.buildTerminalQuarantineEntries(e,g,T.pushFiles,T.merge.quarantineEntries,h),j=[...T.merge.quarantineEntries,...T.merge.resolvedQuarantineEntries,...N];return await this.flushQuarantine(j,i),c("retry-exhausted",{detail:T.detail,quarantinedCount:j.length,...j.length>0?{quarantinedPaths:j.map(ie=>ie.path)}:{}})}let{examinedHead:x,pushedSha:I,applyWrites:R,applyDeletes:W,pushFiles:Q}=T,P=T.merge;i.push(...P.warnings),i.push(...T.deferredWarnings),s.push(...T.withheldDeletions);let D=T.deferredPaths.size>0?{deferredPaths:[...T.deferredPaths]}:{},k=T.pushedDeletions.length>0?{pushedDeletes:T.pushedDeletions}:{},X=await this.flushQuarantine([...P.quarantineEntries,...P.resolvedQuarantineEntries],i),q=new Set;if(!X&&P.resolvedQuarantineEntries.length>0){for(let N of P.resolvedQuarantineEntries)q.add(N.path);i.push(`quarantine flush failed \u2014 remote-wins apply withheld for ${q.size} path(s); local files untouched, conflict re-derives next sync (D18 durability gate)`)}if(I===void 0&&x===g.lastSyncedSha&&R.length===0&&W.length===0&&P.mergedWrites.length===0&&P.quarantineEntries.length===0&&P.resolvedQuarantineEntries.length===0&&(g.pinnedPaths?.length??0)===0&&T.alreadyInHead.length===0&&T.deferredPaths.size===0&&!y)return c("synced");let B=I??x,J=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,B,this.deps.baseURL);if(I!==void 0&&J.parents[0]!==x)return await this.checkRaceWindow(e,g,x,J.parents[0],Q,new Set(T.pushedDeletions),i,u),i.push(`race-window: watermark NOT advanced (pushed commit's parent ${J.parents[0]} != examined head ${x}) \u2014 next sync reconciles the concurrent change`),c("synced",{pushedSha:I,pushedCount:Q.size,mergedCount:P.mergedCount,quarantinedCount:P.quarantineEntries.length+P.resolvedQuarantineEntries.length,...P.mergedPaths.length>0?{mergedPaths:P.mergedPaths}:{},...hy(P).length>0?{quarantinedPaths:hy(P)}:{},...D,...k});let{pulledCount:be,pinnedPaths:ne}=await this.applyRemoteChanges(f,h,[...R,...P.mergedWrites].filter(N=>!q.has(N.path)),W.filter(N=>!q.has(N.path)),i);for(let N of P.quarantineEntries)ne.add(N.path);for(let N of T.deferredPaths)ne.add(N);for(let N of q)ne.add(N);if(u.fileMode){for(let N of p)ne.add(N);for(let N of T.remoteOversized)ne.add(N)}return await this.advanceWatermark(e,B,J.treeSha,h,[...R,...P.mergedWrites,...T.deferredRemoteChanges],w,ne,b.diskBlobShas,u,p),await this.resolveClearedPins(e,w,ne,i,new Set(P.resolvedQuarantineEntries.map(N=>N.path))),c("synced",{pushedSha:I,pulledCount:be,pushedCount:Q.size,mergedCount:P.mergedCount,quarantinedCount:P.quarantineEntries.length+P.resolvedQuarantineEntries.length,...P.mergedPaths.length>0?{mergedPaths:P.mergedPaths}:{},...hy(P).length>0?{quarantinedPaths:hy(P)}:{},...D,...k})}catch(l){let u=this.deps.redact??(f=>f);return o.length>0&&s.push(...o),(0,Qz.isAuthError)(l)?c("auth-required",{detail:u(`authentication failed: ${tu(l)} \u2014 the PAT is expired, revoked or under-scoped; update it in the per-device secure storage (R8). Never treated as success.`)}):(i.push(`sync failed: ${u(tu(l))}`),c("error",{detail:u(tu(l))}))}}async flushQuarantine(e,t){if(e.length===0)return!0;let r=this.deps.redact??(s=>s);for(let s of e)t.push(r(`quarantined ${s.path}: ${s.reason}`));let i=this.deps.quarantine;if(i===void 0)return!1;try{if(i.quarantineAll!==void 0)await i.quarantineAll(e);else for(let s of e)await i.quarantine(s);return!0}catch(s){let o=this.deps.redact??(c=>c);return t.push(`quarantine sink failed: ${o(tu(s))} \u2014 files untouched on disk; the conflict re-derives next sync (D17 degradation)`),!1}}async buildTerminalQuarantineEntries(e,t,r,i,s){let o=new Set(i.map(u=>u.path)),c=new Map;try{let u=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),f=(await(0,yt.getTree)(this.transport,e.owner,e.repo,(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,u,this.deps.baseURL)).treeSha,this.deps.baseURL)).filter(d=>r.has(d.path));for(let d of f)c.set(d.path,await(0,yt.getBlobText)(this.transport,e.owner,e.repo,d.blobSha,this.deps.baseURL))}catch{}let l=[];for(let[u,f]of r){if(o.has(u))continue;let d=s.get(u),h=d??f,p=d!==void 0&&!(0,Cs.contentEquals)(d,f),g=typeof h=="string"?(0,gc.extractAssetUid)(h):void 0,y=c.get(u);l.push({repoKey:e.repoKey,path:u,...g!==void 0?{uid:g}:{},reason:`non-fast-forward push failed after ${this.deps.maxPushRetries??Ps.DEFAULT_MAX_PUSH_RETRIES} retries (D16) \u2014 a concurrent writer keeps moving ${e.branch}; base recoverable from git history at ${t.lastSyncedSha}${p?"; the contended push payload was a merged proposal (never applied to disk) \u2014 the merge re-derives next sync":""}`,...typeof h=="string"?{localContent:h}:{localContentBytes:h},...y!==void 0?{remoteContent:y}:{}})}return l}async resolveClearedPins(e,t,r,i,s=new Set){let o=this.deps.quarantine;if(o===void 0||o.markResolved===void 0)return;let c=(t.pinnedPaths??[]).filter(l=>!r.has(l)&&!s.has(l));for(let l of c)try{await o.markResolved?.(e.repoKey,l)}catch(u){let f=this.deps.redact??(d=>d);i.push(`quarantine markResolved failed for ${l}: ${f(tu(u))} \u2014 unresolved-count may overcount until the resolver UI reconciles (CQ4)`)}}async resolveBaseTreeSha(e,t){try{return(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,t.lastSyncedSha,this.deps.baseURL)).treeSha}catch{return null}}pinLocalChanges(e,t,r,i,s){let o=e.modified.filter(h=>h.basePath!==void 0),c=[...e.added,...e.modified.filter(h=>h.basePath===void 0)],l=new Map;if(s==="pull"){for(let h of o)h.basePath!==void 0&&i.push(h.basePath),r.push(`pull-only: rename (uid ${h.uid??"?"}) ${h.basePath} \u2192 ${h.path} not pushed \u2014 propagates on the next push/Sync (#3473)`);for(let h of e.deleted)i.push(h.path),r.push(`pull-only: delete of ${h.path} not pushed \u2014 propagates on the next push/Sync (#3473)`)}else{for(let h of o)h.basePath!==void 0&&l.set(h.basePath,h.path);for(let h of e.deleted)l.set(h.path,h.path)}let u=[...c,...o,...e.deleted.map(h=>({...h}))],f=new Set(e.deleted.map(h=>h.path)),d=new Map;for(let h of[...c,...s==="pull"?[]:o]){let p=t.get(h.path);p!==void 0&&d.set(h.path,p)}return{localChanges:u,localDeletedPaths:f,pushFilesAll:d,pushDeletionsAll:l,dupUids:e.duplicateUids}}async runPushLoop(e,t,r,i,s,o,c=!1,l=new Set,u="sync",f){let{localChanges:d,localDeletedPaths:h,pushFilesAll:p,pushDeletionsAll:g,dupUids:y}=r,w=this.deps.maxPushRetries??Ps.DEFAULT_MAX_PUSH_RETRIES,b=0,S="",T,x=[],I=[],R=new Map,W=new Set,Q=[],P=WE,D=[],k=new Set,X=[],q=[],B=new Set;for(;;){S=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),x=[],I=[],P=WE,D=[],k=new Set,X=[],q=[];let J,be=new Set,ne=(t.pinnedPaths?.length??0)>0;if(S!==t.lastSyncedSha||ne||c){this.emitProgress(f,e.repoKey,"pulling-remote");let ie=await this.collectRemoteChanges(e,t,S,o,l,s,B);J=ie.headTreeByPath;let ye=this.matchLocalVsRemote(d,h,i,ie.changes,be,y,ie.headTreeByPath);if(ye.conflicts.length>0){if(u==="sync"&&this.emitProgress(f,e.repoKey,"merging"),u!=="sync"){for(let G of ye.conflicts){k.add(G.local.path),G.local.basePath!==void 0&&k.add(G.local.basePath);for(let ve of G.remotes)k.add(ve.path),ve.kind==="change"&&X.push(ve)}q.push(`${u}-only: ${ye.conflicts.length} conflict(s) deferred to a full Sync (${ye.conflicts.map(G=>G.desc).join("; ")}) \u2014 paths pinned, nothing merged`)}else if(o.fileMode)P=this.resolveFileModeConflicts(e,ye.conflicts,i,ye.applyWrites,ye.applyDeletes);else{if(this.deps.mergeLayer===void 0)return{kind:"conflict",detail:`overlapping change on ${ye.conflicts[0].desc} \u2014 merge layer (A2/A3) required; nothing pushed, nothing written`};P=await this.resolveMergeConflicts(e,t,ye.conflicts,i)}if(u==="sync")for(let G of ye.conflicts)for(let ve of G.remotes)ve.path!==G.local.path&&(k.add(ve.path),ve.kind==="change"&&X.push(ve),q.push(`conflict group ${G.desc}: remote change at ${ve.path} NOT applied \u2014 pinned to re-derive on the next sync (#3477)`))}if(x=ye.applyWrites,I=ye.applyDeletes,u==="push"&&(x.length>0||I.length>0)){for(let G of x)k.add(G.path),X.push(G);for(let G of I)k.add(G.path);q.push(`push-only: ${x.length+I.length} remote change(s) NOT applied \u2014 pinned to re-derive on the next pull/Sync`),x=[],I=[]}}R=u==="pull"?new Map:new Map([...[...p].filter(([ie])=>!be.has(ie)),...P.mergedFiles]),W=new Set,Q=[];for(let[ie,ye]of g){if(be.has(ye)){Q.push(ie);continue}R.has(ie)||W.add(ie)}if((R.size>0||W.size>0)&&J===void 0&&(J=zE(await(0,yt.getTree)(this.transport,e.owner,e.repo,t.rootTreeSha,this.deps.baseURL))),R.size>0&&J!==void 0){for(let[ie,ye]of R){let G=J.get(ie);G!==void 0&&G===await(0,cd.gitBlobSha)(ye,this.deps.sha1)&&(R.delete(ie),D.push(ie))}D.length>0&&s.push(`phantom push skipped: ${D.length} file(s) already identical in remote HEAD (${D.join(", ")}) \u2014 excluded from the commit (#3475)`)}if(W.size>0&&J!==void 0){for(let ie of[...W])J.has(ie)||W.delete(ie);R.size===0&&W.size>=J.size&&(Q.push(...W),q.push(`deletion of ALL ${W.size} remaining file(s) deferred \u2014 GitHub cannot create an empty tree; the deletes re-derive and propagate once the repo has at least one surviving file`),W.clear())}if(R.size===0&&W.size===0)break;let N=new Map;for(let[ie,ye]of R)if(typeof ye=="string")N.set(ie,ye);else{let G=Zz(ye);G!==null&&N.set(ie,G)}let j=(0,Yz.scanForSecrets)(N);if(j.length>0)return{kind:"secret-detected",detail:`secret-scan: refusing to push \u2014 ${j.map(ie=>`${ie.path} (${ie.kind})`).join(", ")} (R5); remove the secret and re-sync`};try{T=await(0,Kz.restCreateCommit)(this.transport,{owner:e.owner,repo:e.repo,branch:e.branch,files:new Map([...R].map(([ie,ye])=>[ie,eH(ye)])),deletions:[...W],message:this.deps.commitMessage?.(e,R.size,W.size)??`chore(exosync): sync ${R.size} file(s)${W.size>0?`, ${W.size} deletion(s)`:""}`,baseURL:this.deps.baseURL,redact:this.deps.redact});break}catch(ie){if(!KP(ie))throw ie;if(b++,b>w)return{kind:"retry-exhausted",detail:`non-fast-forward push failed after ${w} retries (D16 cap) \u2014 contended files routed to quarantine (D17)`,pushFiles:R,merge:P};s.push(`non-fast-forward push (attempt ${b}/${w}) \u2014 re-pulling and retrying (D16)`)}}return{kind:"done",examinedHead:S,pushedSha:T,applyWrites:x,applyDeletes:I,pushFiles:R,pushedDeletions:T!==void 0?[...W]:[],withheldDeletions:Q,merge:P,remoteOversized:B,alreadyInHead:D,deferredPaths:k,deferredRemoteChanges:X,deferredWarnings:q}}async resolveMergeConflicts(e,t,r,i){let s=this.deps.mergeLayer;if(s===void 0)return WE;let o=new Map(t.files.map(y=>[y.path,y])),c=new Map,l=[],u=[],f=[],d=[],h=0,p=a(y=>typeof y=="string"?y:void 0,"asText"),g=a((y,w,b)=>{let S=p(i.get(y.local.path)),T=p(y.remotes[0]?.content);return{repoKey:e.repoKey,path:y.local.path,...y.local.uid!==void 0?{uid:y.local.uid}:{},reason:w,...b!==void 0?{baseContent:b}:{},...S!==void 0?{localContent:S}:{},...T!==void 0?{remoteContent:T}:{}}},"entry");for(let y of r){let w=o.get(y.local.basePath??y.local.path)??o.get(y.remotes[0]?.path??""),b;if(w!==void 0&&(b=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,w.blobSha,this.deps.baseURL)),y.remotes.length>1){u.push(g(y,`ambiguous conflict: local change overlaps ${y.remotes.length} remote changes (${y.remotes.map(R=>R.path).join(", ")})`,b));continue}let S=y.remotes[0],T=p(i.get(y.local.path)),x=await s.resolve({path:y.local.path,...y.local.uid!==void 0?{uid:y.local.uid}:{},...b!==void 0?{base:b}:{},...T!==void 0?{local:T}:{},...S.kind==="change"&&typeof S.content=="string"?{remote:S.content}:{}});if(x.action==="quarantine"){u.push(g(y,x.reason,b));continue}h++,d.push(y.local.path);for(let R of x.warnings??[])f.push(`merge(${y.local.path}): ${R}`);let I=S.kind==="change"?S.content:void 0;if(x.content!==I&&c.set(y.local.path,x.content),x.content!==i.get(y.local.path)){let R=(0,gc.extractAssetUid)(x.content)??y.local.uid;l.push({path:y.local.path,kind:"change",content:x.content,blobSha:await(0,cd.gitBlobSha)(x.content,this.deps.sha1),...R!==void 0?{uid:R}:{}})}}return{mergedFiles:c,mergedWrites:l,quarantineEntries:u,resolvedQuarantineEntries:[],mergedCount:h,mergedPaths:d,warnings:f}}resolveFileModeConflicts(e,t,r,i,s){let o=[],c=[];for(let l of t){l.remotes.length>1&&c.push(`file-mode conflict on ${l.local.path} unexpectedly overlaps ${l.remotes.length} remote changes \u2014 resolving against the first`);let u=l.remotes[0],f=r.get(l.local.path);u.kind==="change"?i.push(u):s.push(u),!(l.localIsDelete||f===void 0)&&o.push({repoKey:e.repoKey,path:l.local.path,reason:`file-mode remote-wins (D18): remote ${u.kind==="change"?`version ${u.blobSha}`:"delete"} wins; this is the losing LOCAL version, preserved byte-exact`,...typeof f=="string"?{localContent:f}:{localContentBytes:f}})}return{mergedFiles:new Map,mergedWrites:[],quarantineEntries:[],resolvedQuarantineEntries:o,mergedCount:0,mergedPaths:[],warnings:c}}async applyRemoteChanges(e,t,r,i,s){let o=0,c=new Set,l=a(async(f,d)=>{try{return d?await WP(e,f):await e.read(f)}catch{return}},"tryRead"),u=a(async(f,d)=>{typeof d=="string"?await e.write(f,d):await tH(e,f,d)},"writeContent");for(let f of r){if(f.content===void 0)continue;if(!zP(f.path)){s.push(`unsafe remote path skipped on pull-apply: ${f.path}`),c.add(f.path);continue}let d=t.get(f.path),h=await l(f.path,typeof(d??f.content)!="string");if(!(0,Cs.contentEquals)(h,d)){s.push(`pull-apply skipped: ${f.path} changed on disk mid-sync (TOCTOU) \u2014 remote change re-derives next sync`),c.add(f.path);continue}await u(f.path,f.content),o++}for(let f of i){if(!zP(f.path)){s.push(`unsafe remote path skipped on pull-delete: ${f.path}`),c.add(f.path);continue}let d=t.get(f.path);if(d!==void 0){let h=await l(f.path,typeof d!="string");if(h!==void 0&&!(0,Cs.contentEquals)(h,d)){s.push(`pull-delete skipped: ${f.path} changed on disk mid-sync (TOCTOU) \u2014 delete-vs-modify re-derives next sync`),c.add(f.path);continue}await e.delete(f.path),o++}}return{pulledCount:o,pinnedPaths:c}}async advanceWatermark(e,t,r,i,s,o,c,l,u,f=new Set){let d=(await(0,yt.getTree)(this.transport,e.owner,e.repo,r,this.deps.baseURL)).filter(p=>u.treeFilter(p)&&!f.has(p.path)),h=nH(await this.buildWatermarkFiles(e,d,i,s,o,l,u),o,c);await this.deps.watermarkStore.set(e.repoKey,{lastSyncedSha:t,rootTreeSha:r,files:h,...c.size>0?{pinnedPaths:[...c]}:{},...u.fileMode?{spaceKind:"file"}:{}})}async tryMountBaseBootstrap(e,t,r,i,s){let o=this.deps.mountBaseStore,c=null;if(o!==void 0)try{c=await o.get(e.repoKey)}catch{return null}let l=!1;if(c===null&&this.deps.localBaseShaProvider!==void 0)try{let w=await this.deps.localBaseShaProvider(e);typeof w=="string"&&w.length>0&&(c=w,l=!0)}catch{}if(c===null||t.startsWith(c))return null;let u=300,f=null;try{let w=t;for(let b=0;b<u;b++){let S=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,w,this.deps.baseURL);if(S.sha===c||S.sha.startsWith(c)){f=S;break}if(S.parents.length===0)break;w=S.parents[0]}}catch{return null}if(f===null)return null;let d;try{d=(await(0,yt.getTree)(this.transport,e.owner,e.repo,f.treeSha,this.deps.baseURL)).filter(w=>(0,Cs.isSyncablePath)(w.path))}catch{return null}let h;try{let w=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,t,this.deps.baseURL);h=zE((await(0,yt.getTree)(this.transport,e.owner,e.repo,w.treeSha,this.deps.baseURL)).filter(b=>(0,Cs.isSyncablePath)(b.path)))}catch{return null}let p=d.filter(w=>!r.has(w.path)&&h.get(w.path)===w.blobSha);if(p.length>0){let w=p.slice(0,3).map(b=>b.path).join(", ")+(p.length>3?", \u2026":"");return i.push(`first-sync (asset mode): base-tree\u2286working-tree sanity guard fired \u2014 ${p.length} base file(s) absent from the working tree but UNCHANGED on remote head (${w}); the verified-ancestor base may not match the working tree's derivation commit (out-of-band submodule manipulation) \u2192 routing to merge/quarantine instead of inferring a silent deletion (#3610)`),{kind:"settled",outcome:s("full-conflict",{detail:`first-sync: base-tree\u2286working-tree sanity guard \u2014 ${p.length} base file(s) absent from the working tree are unchanged on remote head (${w}); refusing to infer a silent deletion from a base that may not match the derivation commit \u2014 divergence must go through merge/quarantine (A2/A3), never a silent delete (#3610)`})}}let g=d.map(w=>({path:w.path,blobSha:w.blobSha})),y={lastSyncedSha:f.sha,rootTreeSha:f.treeSha,files:g};if(l&&o!==void 0)try{await o.set(e.repoKey,f.sha)}catch{}return i.push(l?`first-sync (asset mode): BACKFILLED the 3-way base from the locally checked-out commit ${f.sha} (no recorded mount base) \u2014 remote head ${t} advanced since; local edits 3-way merge against it instead of false-conflicting (#3590)`:`first-sync (asset mode): reconciling against the recorded mount base ${f.sha} \u2014 remote head ${t} advanced since mount; local edits 3-way merge against it instead of false-conflicting (#3590)`),{kind:"additive-base",base:y}}async bootstrapWatermark(e,t,r,i){let s=await(0,yt.getHeadSha)(this.transport,e.owner,e.repo,e.branch,this.deps.baseURL),o=await this.tryMountBaseBootstrap(e,s,t,r,i);if(o!==null)return o;let c=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,s,this.deps.baseURL),l=(await(0,yt.getTree)(this.transport,e.owner,e.repo,c.treeSha,this.deps.baseURL)).filter(h=>(0,Cs.isSyncablePath)(h.path)),u=[],f;for(let h of l){let p=t.get(h.path);if(p===void 0||await(0,cd.gitBlobSha)(p,this.deps.sha1)!==h.blobSha){f===void 0&&(f=h.path);continue}let g=typeof p=="string"?(0,gc.extractAssetUid)(p):void 0;u.push({path:h.path,blobSha:h.blobSha,...g?{uid:g}:{}})}let d={lastSyncedSha:s,rootTreeSha:c.treeSha,files:u};return f!==void 0?this.deps.mergeLayer===void 0?{kind:"settled",outcome:i("full-conflict",{detail:`first-sync: no watermark and local content diverges from remote head at ${f} \u2014 A2/A3 scope`})}:(r.push(`first-sync (asset mode): no 3-way merge base and local diverges from remote head (first at ${f}) \u2014 reconciling ZERO-LOSS against ${u.length} byte-identical file(s) as a synthetic base: remote-only files pull, local-only files push, overlapping divergences route to the merge/quarantine layer (both versions preserved), never a silent overwrite or delete`),{kind:"additive-base",base:d}):t.size===l.length?(await this.deps.watermarkStore.set(e.repoKey,d),r.push(`watermark bootstrapped from head ${s} (local tree identical to remote)`),{kind:"settled",outcome:i("synced")}):(r.push(`first-sync (asset mode): local tree (${t.size} files) is a pure superset of remote head ${s} (${l.length} files) \u2014 ${t.size-l.length} local-only addition(s) derive as pushable adds (#3565)`),{kind:"additive-base",base:d})}async collectRemoteChanges(e,t,r,i,s=new Set,o=[],c=new Set){let l=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,r,this.deps.baseURL),u=await(0,yt.getTree)(this.transport,e.owner,e.repo,l.treeSha,this.deps.baseURL);if(i.fileMode)for(let y of u)i.syncable(y.path)&&!i.treeFilter(y)&&!c.has(y.path)&&(c.add(y.path),o.push(`skipped oversized REMOTE file ${y.path} (${y.size??"?"} bytes over cap) \u2014 excluded from sync symmetrically (Phase C size cap)`));let f=u.filter(y=>i.treeFilter(y)&&!s.has(y.path)),d=t.files.filter(y=>!c.has(y.path)&&!s.has(y.path)),{changed:h,deleted:p}=HP(d,f),g=[];for(let y of h){if(i.fileMode){let b=await(0,yt.getBlobBytes)(this.transport,e.owner,e.repo,y.blobSha,this.deps.baseURL);g.push({path:y.path,kind:"change",blobSha:y.blobSha,content:b});continue}let w=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,y.blobSha,this.deps.baseURL);g.push({path:y.path,kind:"change",blobSha:y.blobSha,content:w,uid:(0,gc.extractAssetUid)(w)})}for(let y of p)g.push({path:y.path,kind:"delete",uid:y.uid});return{changes:g,headTreeByPath:zE(u)}}matchLocalVsRemote(e,t,r,i,s,o=new Set,c){let l=new Set,u=[],f=new Map;for(let y of i)y.kind==="change"&&y.uid!==void 0&&f.set(y.uid,(f.get(y.uid)??0)+1);let d=new Set(o);for(let[y,w]of f)w>1&&d.add(y);let h=new Map,p=new Map;for(let y of i){if(y.uid!==void 0&&!d.has(y.uid)){let w=h.get(y.uid)??[];w.push(y),h.set(y.uid,w)}p.set(y.path,y)}for(let y of e){let w=new Set;if(y.uid!==void 0&&!d.has(y.uid))for(let x of h.get(y.uid)??[])x.kind==="change"&&x.path!==y.path&&(c?.has(y.path)===!0||y.basePath!==void 0&&c?.has(y.basePath)===!0)||w.add(x);let b=p.get(y.path);if(b!==void 0&&w.add(b),y.basePath!==void 0){let x=p.get(y.basePath);x!==void 0&&w.add(x)}let S=[],T=!1;for(let x of w){if(T=t.has(y.path)&&!r.has(y.path),T&&x.kind==="delete"){l.add(x);continue}if(!T&&x.kind==="change"&&x.path===y.path&&x.blobSha===y.blobSha){l.add(x),s.add(y.path);continue}if(x.kind==="delete"&&y.basePath!==void 0&&x.path===y.basePath){let I=p.get(y.path);if(I!==void 0&&I.kind==="change"&&I.blobSha===y.blobSha){l.add(x);continue}}S.push(x),l.add(x)}S.length>0&&(u.push({local:y,localIsDelete:T,remotes:S,desc:`${y.uid!==void 0&&!d.has(y.uid)?y.uid:y.path} (local ${T?"delete":"change"} vs remote ${S[0].kind} at ${S[0].path})`}),s.add(y.path))}let g=i.filter(y=>!l.has(y));return{conflicts:u,applyWrites:g.filter(y=>y.kind==="change"),applyDeletes:g.filter(y=>y.kind==="delete")}}async checkRaceWindow(e,t,r,i,s,o,c,l){try{let u=await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,i,this.deps.baseURL),f=(await(0,yt.getTree)(this.transport,e.owner,e.repo,u.treeSha,this.deps.baseURL)).filter(l.treeFilter),d=r===t.lastSyncedSha?t.files:(await(0,yt.getTree)(this.transport,e.owner,e.repo,(await(0,yt.getCommitInfo)(this.transport,e.owner,e.repo,r,this.deps.baseURL)).treeSha,this.deps.baseURL)).filter(l.treeFilter),{changed:h,deleted:p}=HP(d,f);for(let g of h)s.has(g.path)&&c.push(`race-window: concurrent commit ${i} changed ${g.path} between conflict check (head ${r}) and push \u2014 local version won; previous version recoverable from git history`),o.has(g.path)&&c.push(`race-window: concurrent commit ${i} changed ${g.path} which this push DELETED \u2014 the delete won; the concurrent version is recoverable from git history`);for(let g of p)s.has(g.path)&&c.push(`race-window: concurrent commit ${i} deleted ${g.path}; push re-created it`)}catch(u){let f=this.deps.redact??(d=>d);c.push(`race-window check failed: ${f(tu(u))}`)}}async buildWatermarkFiles(e,t,r,i,s,o,c){if(c.fileMode)return t.map(f=>({path:f.path,blobSha:f.blobSha}));let l=new Map;for(let f of i)f.kind==="change"&&f.blobSha!==void 0&&l.set(f.blobSha,f.uid);for(let[f,d]of r){let h=o?.get(f)??await(0,cd.gitBlobSha)(d,this.deps.sha1);l.set(h,typeof d=="string"?(0,gc.extractAssetUid)(d):void 0)}for(let f of s.files)l.has(f.blobSha)||l.set(f.blobSha,f.uid);let u=[];for(let f of t){let d;if(l.has(f.blobSha))d=l.get(f.blobSha);else{let h=await(0,yt.getBlobText)(this.transport,e.owner,e.repo,f.blobSha,this.deps.baseURL);d=(0,gc.extractAssetUid)(h)}u.push({path:f.path,blobSha:f.blobSha,...d?{uid:d}:{}})}return u}};Ps.SyncEngine=HE});var YE=v(QE=>{"use strict";Object.defineProperty(QE,"__esModule",{value:!0});QE.diff3=iH;function XP(n,e){let t=n.length,r=e.length,i=Array.from({length:t+1},()=>new Int32Array(r+1));for(let l=t-1;l>=0;l--)for(let u=r-1;u>=0;u--)i[l][u]=n[l]===e[u]?i[l+1][u+1]+1:Math.max(i[l+1][u],i[l][u+1]);let s=new Map,o=0,c=0;for(;o<t&&c<r;)n[o]===e[c]?(s.set(o,c),o++,c++):i[o+1][c]>=i[o][c+1]?o++:c++;return s}a(XP,"lcsMatch");function XE(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}a(XE,"sliceEq");function iH(n,e,t){let r=XP(n,e),i=XP(n,t),s=[],o=0,c=0,l=0;for(;;){let u=o;for(;u<n.length&&!(r.has(u)&&i.has(u));)u++;let f=u<n.length?r.get(u):e.length,d=u<n.length?i.get(u):t.length,h=n.slice(o,u),p=e.slice(c,f),g=t.slice(l,d),y=!XE(p,h),w=!XE(g,h);if(!y&&!w)s.push(...h);else if(!y)s.push(...g);else if(!w)s.push(...p);else if(XE(p,g))s.push(...p);else return{ok:!1,conflict:{base:h,local:p,remote:g}};if(u>=n.length)break;s.push(n[u]),o=u+1,c=f+1,l=d+1}return{ok:!0,merged:s}}a(iH,"diff3")});var YP=v(fd=>{"use strict";Object.defineProperty(fd,"__esModule",{value:!0});fd.StructuredMerger=void 0;fd.splitSections=py;var QP=YE(),sH=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/,ld="exo__Instance_class";function ud(n){if(n===null||typeof n!="object")return!0;if(Array.isArray(n))return n.every(ud);let e=Object.getPrototypeOf(n);return e!==Object.prototype&&e!==null?!1:Object.values(n).every(ud)}a(ud,"isPlainValue");function ca(n,e){if(n===e)return!0;if(n===null||e===null||n===void 0||e===void 0||typeof n!="object"||typeof e!="object"||Array.isArray(n)!==Array.isArray(e))return!1;if(Array.isArray(n)&&Array.isArray(e))return n.length!==e.length?!1:n.every((s,o)=>ca(s,e[o]));let t=n,r=e,i=Object.keys(t);return i.length!==Object.keys(r).length?!1:i.every(s=>ca(t[s],r[s]))}a(ca,"deepEqual");function yc(n){return typeof n=="string"?`s:${n}`:`j:${JSON.stringify(n)}`}a(yc,"setKey");function li(n){return n==null?[]:Array.isArray(n)?n:[n]}a(li,"toElements");function oH(n,e,t){let r=new Set(li(n).map(yc)),i=li(e),s=li(t),o=new Set(i.map(yc)),c=new Set(s.map(yc)),l=a(d=>o.has(d)&&c.has(d)||o.has(d)&&!r.has(d)||c.has(d)&&!r.has(d),"keep"),u=[],f=new Set;for(let d of[...i,...s]){let h=yc(d);f.has(h)||!l(h)||(f.add(h),u.push(d))}return u}a(oH,"mergeSet");function aH(n,e,t){let r=[],i=[],s=new Set;for(let c of[...Object.keys(n),...Object.keys(e),...Object.keys(t)])s.has(c)||(s.add(c),i.push(c));let o={};for(let c of i){let l=n[c],u=e[c],f=t[c];if(!ud(l)||!ud(u)||!ud(f))return{ok:!1,reason:`frontmatter key "${c}" contains a non-plain value (Date?) \u2014 the codec must round-trip scalars as strings (CORE_SCHEMA contract)`};if(Array.isArray(l)||Array.isArray(u)||Array.isArray(f)){if(!(c in e)&&!(c in t))continue;let d=oH(l,u,f),h=new Set(li(l).map(yc)),p=li(u).some(y=>!h.has(yc(y))),g=li(f).some(y=>!h.has(yc(y)));p&&g&&!ca(li(u),li(f))&&r.push(`both sides added values to multi-valued key "${c}" \u2014 union kept (D20)`),d.length>0&&(o[c]=d);continue}if(ca(u,f)){u!==void 0&&(o[c]=u);continue}if(ca(u,l)){f!==void 0&&(o[c]=f);continue}if(ca(f,l)){u!==void 0&&(o[c]=u);continue}return{ok:!1,reason:`frontmatter key "${c}" changed differently on both sides`}}return{ok:!0,value:o,warnings:r}}a(aH,"mergeFrontmatter");var cH=/^(```|~~~)/,lH=/^#{1,6}\s/;function py(n){let e=n.split(`
|
|
310
310
|
`),t=[],r=null,i="",s=!1,o=a(()=>{r!==null&&t.push({heading:i,text:r.join(`
|
|
311
311
|
`)})},"flush");for(let c of e){if(cH.test(c.trimStart())&&(s=!s),!s&&lH.test(c)){o(),r=[c],i=c.trim();continue}r===null&&(r=[],i=""),r.push(c)}return o(),t}a(py,"splitSections");function JE(n){return n.split(/\n{2,}/)}a(JE,"splitParagraphs");function uH(n){return n.join(`
|
|
312
312
|
|
|
@@ -619,7 +619,7 @@ Next steps:
|
|
|
619
619
|
`),process.stdout.write(` File: ${e.file}
|
|
620
620
|
`),process.stdout.write(` Commit: ${e.sha}
|
|
621
621
|
`),process.stdout.write(` URL: ${e.url}
|
|
622
|
-
`)),process.exit(0)}catch(e){let t=e instanceof Error?e:new Error(String(e)),r=new wi;t.message=r.redact(t.message),t.stack&&(t.stack=r.redact(t.stack)),ue.handle(t)}})}a(cse,"restPushCommand");function jM(n){let e=new Te;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.119.
|
|
622
|
+
`)),process.exit(0)}catch(e){let t=e instanceof Error?e:new Error(String(e)),r=new wi;t.message=r.redact(t.message),t.stack&&(t.stack=r.redact(t.stack)),ue.handle(t)}})}a(cse,"restPushCommand");function jM(n){let e=new Te;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.119.1"),e.addCommand(j4()),e.addCommand(K4()),e.addCommand(Dk()),e.addCommand(kk()),e.addCommand(c4()),e.addCommand(Uk()),e.addCommand(Bk()),e.addCommand(f4()),e.addCommand(w4()),e.addCommand(v4()),e.addCommand(A4()),e.addCommand(M4()),e.addCommand(lM()),e.addCommand(IM()),e.addCommand(xM()),e.addCommand(CM()),e.addCommand(PM()),e.addCommand(LM()),e.addCommand(MM()),e.addCommand(gM()),e.addCommand(vM()),e}a(jM,"createProgram");jM().parse();0&&(module.exports={createProgram});
|
|
623
623
|
/*! Bundled license information:
|
|
624
624
|
|
|
625
625
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED