nemar-cli 0.10.37-dev.4640 → 0.10.37-dev.4659

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.
@@ -23,7 +23,7 @@ ${t}`,zM,GM,KM=(e,t,r)=>{let n=r===""?"":`with ${r.trim()}() `,s=VM.bind(null,n,
23
23
  `)}var Fl=!1;var{spawn:WF}=globalThis.Bun;function Vl(e,t=[]){let r=e.replace(YF,'("$1","<redacted>")');for(let n of t)if(n.length>=XF)r=r.split(n).join("<redacted>");return r}function QF(e){let t=["AWS_SESSION_TOKEN","AWS_SECRET_ACCESS_KEY","AWS_ACCESS_KEY_ID"],r=new Set;for(let n of[process.env,e??{}])for(let s of t){let o=n[s];if(typeof o==="string"&&o.length>0)r.add(o)}return[...r]}async function hb(e,t){let r=e.getReader(),n=new TextDecoder,s="";while(!0){let{done:o,value:i}=await r.read();if(o)break;if(i.byteLength===0)continue;t(),s+=n.decode(i,{stream:!0})}return s+n.decode()}async function mb(e,t={}){let r={...process.env,GIT_TERMINAL_PROMPT:"0",...t.env};for(let y of t.unsetEnv??[])delete r[y];let n=WF({cmd:e,cwd:t.cwd,...t.stdin===void 0?{}:{stdin:new TextEncoder().encode(t.stdin)},stdout:"pipe",stderr:"pipe",env:r}),s=!1,o,i,a=performance.now(),c=()=>{if(i!==void 0)clearTimeout(i),i=void 0},u=()=>{if(!t.onInactivityWarning)return;c(),i=setTimeout(()=>{i=void 0;try{t.onInactivityWarning?.(performance.now()-a)}catch{console.error("Could not display subprocess inactivity warning; the child result is unaffected.")}},t.inactivityWarningAfterMs??JF)};if(u(),t.timeout)o=setTimeout(()=>{s=!0,c(),n.kill()},t.timeout);let d=ic()?[...QF(r),...t.redact??[]]:[];if(ic()){let y=t.cwd?` (cwd=${t.cwd})`:"";qs(Nt.dim(Vl(`$ ${e.join(" ")}${y}`,d)))}let l=()=>{a=performance.now(),u()},p,f,h,m=n.exited.then((y)=>(c(),y));try{[p,f,h]=await Promise.all([hb(n.stdout,l),hb(n.stderr,l),m])}finally{if(c(),o)clearTimeout(o)}if(ic()){if(t.sensitiveOutput)qs(Nt.dim("[sensitive subprocess output suppressed]"));else{if(p.trim())qs(Nt.dim(Vl(p.trimEnd(),d)));if(f.trim())qs(Nt.yellow(Vl(f.trimEnd(),d)))}qs(Nt.dim(`(exit ${h})`))}if(s)return{stdout:p,stderr:f||`Command timed out after ${Math.round(t.timeout/1000)}s`,exitCode:h??1,timedOut:!0};return{stdout:p,stderr:f,exitCode:h,timedOut:!1}}var YF,XF=8,JF=120000;var gb=F(()=>{Ul();YF=/\(\s*"((?:x-amz-)[^"]*|authorization|proxy-authorization)"\s*,\s*"[^"]*"\s*\)/gi});function eV(){if(process.platform==="darwin")return"macos";if(process.platform==="win32")return"windows";return"linux"}function _b(e,t=eV()){return e.installInstructions[t]}function tV(e){let t=e.match(/(\d+\.\d+(?:\.\d+)?)/);return t?t[1]:void 0}function nV(){let e=Number(process.env.TEST_PROBE_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:rV}async function vb(e){try{let{exitCode:t,stdout:r,timedOut:n}=await mb(e.cmd,{timeout:nV()});if(n)return{available:!1,timedOut:!0};if(t!==0)return{available:!1};return{available:!0,version:tV(r)}}catch(t){let r=t instanceof Error?t.message:String(t);if(!r.includes("ENOENT")&&!r.includes("not found"))console.error(` Warning: ${e.name} check failed unexpectedly: ${r}`);return{available:!1}}}async function zl(){let e=Object.entries(yb);return Promise.all(e.map(async([t,r])=>{let{available:n,version:s,timedOut:o}=await vb(r);return{key:t,name:r.name,purpose:r.purpose,required:r.required,available:n,version:s,timedOut:o,installInstruction:_b(r)}}))}async function Z3(){let t=(await zl()).filter((r)=>r.required&&!r.available);if(t.length===0)return[];console.warn(`
24
24
  Heads up: some tools NEMAR needs for uploading/validating aren't installed yet:`);for(let r of t)console.warn(` - ${r.name} (${r.purpose})`),console.warn(` Install: ${r.installInstruction}`);return console.warn("Run `nemar doctor` anytime to re-check. You can finish signup without them.\n"),t}async function eB(e){let r=ZF[e].map((i)=>yb[i]).filter(Boolean),n=await Promise.all(r.map(async(i)=>{let a=await vb(i);return{check:i,available:a.available,timedOut:a.timedOut}}));for(let i of n)if(i.timedOut&&i.check.required)console.warn(`Warning: ${i.check.name} did not respond to a version check in time; continuing anyway.`);let s=n.filter((i)=>!i.available&&!i.timedOut&&i.check.required).map((i)=>({tool:i.check.name,installInstruction:_b(i.check)}));if(s.length===0)return;let o=[`
25
25
  Missing required tools:`];for(let i of s)o.push(` ${i.tool} not installed`),o.push(` Install: ${i.installInstruction}`);throw Error(o.join(`
26
- `))}var yb,ZF,rV=4000;var $b=F(()=>{gb();yb={git:{name:"git",purpose:"version control for dataset metadata",cmd:["git","--version"],required:!0,installInstructions:{macos:"brew install git (or install Xcode Command Line Tools)",linux:"sudo apt-get install git OR sudo dnf install git",windows:"winget install Git.Git (or https://git-scm.com/download/win)"}},"git-annex":{name:"git-annex",purpose:"large-file data transfer (upload/download)",cmd:["git-annex","version"],required:!0,installInstructions:{macos:"brew install git-annex",linux:"sudo apt-get install git-annex OR sudo dnf install git-annex",windows:"Download the installer from https://git-annex.branchable.com/install/Windows/"}},gh:{name:"GitHub CLI (gh)",purpose:"GitHub authentication + repository operations",cmd:["gh","--version"],required:!0,installInstructions:{macos:"brew install gh",linux:"See https://cli.github.com/manual/installation",windows:"winget install GitHub.cli (or: scoop install gh)"}},aws:{name:"AWS CLI",purpose:"S3 data upload/download",cmd:["aws","--version"],required:!0,installInstructions:{macos:"brew install awscli",linux:"pip install awscli OR sudo snap install aws-cli --classic",windows:"winget install Amazon.AWSCLI (or the MSI from https://aws.amazon.com/cli/)"}},deno:{name:"Deno",purpose:"BIDS validation",cmd:["deno","--version"],required:!0,installInstructions:{macos:"brew install deno (or: curl -fsSL https://deno.land/install.sh | sh)",linux:"curl -fsSL https://deno.land/install.sh | sh",windows:"winget install DenoLand.Deno (or: irm https://deno.land/install.ps1 | iex)"}}},ZF={upload:["git-annex","gh","aws","deno"],download:["gh"],clone:["git","gh"],push:["git-annex","gh"],publish:["gh","aws"],update:["git","gh"],release:["git","gh"]}});var wb;var Eb=F(()=>{wb={name:"nemar-cli",packageManager:"bun@1.4.3",version:"0.10.37-dev.4640",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js","git-annex-remote-nemar":"dist/git-annex-remote-nemar.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts src/git-annex-remote-nemar.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:scrub":"biome check scripts/scrub shared/identifier-scrub.ts test/scrub","test:scrub":"bun test --preload ./test/scrub/helpers/temp-dirs-preload.ts --path-ignore-patterns='__run_every_scrub_suite__' test/scrub test/identifier-scan.test.ts test/identifier-scrub.test.ts test/identifier-dates.test.ts test/identifier-fleet.test.ts","migrations:d1-check":"bun run scripts/d1-migration-check.ts","zarr:geometry-check":"bun run backend/scripts/zarr-geometry-conformance.ts","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend","generate-openapi":"bun run scripts/generate-openapi.ts",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},trustedDependencies:["@biomejs/biome"],devDependencies:{"@anthropic-ai/sdk":"^0.132.1","@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",ajv:"^8.20.0","ajv-formats":"^3.0.1",husky:"^9.1.7",jose:"6.2.12","lint-staged":"^16.3.2",oauth4webapi:"3.8.8","openid-client":"6.8.9",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var ac;var Gl=F(()=>{Eb();ac=wb.version});import{mkdirSync as oV,readdirSync as iV,unlinkSync as aV,writeFileSync as cV}from"fs";import{join as Kl}from"path";function dB(){Ds=!0}function lc(){return Ds}function fB(e,t=process.env){return e.includes("--debug")||t.NEMAR_DEBUG==="1"}function pB(e){Tb=e,pr(`Step: ${e}`)}function hB(){xb=!0}function mB(){return xb}function gB(){if(Rb)return;Bl=!0}function yB(){Bl=!1,Rb=!0}function _B(){return Bl}function pr(e){if(Ds)process.stderr.write(`[debug] ${e}
26
+ `))}var yb,ZF,rV=4000;var $b=F(()=>{gb();yb={git:{name:"git",purpose:"version control for dataset metadata",cmd:["git","--version"],required:!0,installInstructions:{macos:"brew install git (or install Xcode Command Line Tools)",linux:"sudo apt-get install git OR sudo dnf install git",windows:"winget install Git.Git (or https://git-scm.com/download/win)"}},"git-annex":{name:"git-annex",purpose:"large-file data transfer (upload/download)",cmd:["git-annex","version"],required:!0,installInstructions:{macos:"brew install git-annex",linux:"sudo apt-get install git-annex OR sudo dnf install git-annex",windows:"Download the installer from https://git-annex.branchable.com/install/Windows/"}},gh:{name:"GitHub CLI (gh)",purpose:"GitHub authentication + repository operations",cmd:["gh","--version"],required:!0,installInstructions:{macos:"brew install gh",linux:"See https://cli.github.com/manual/installation",windows:"winget install GitHub.cli (or: scoop install gh)"}},aws:{name:"AWS CLI",purpose:"S3 data upload/download",cmd:["aws","--version"],required:!0,installInstructions:{macos:"brew install awscli",linux:"pip install awscli OR sudo snap install aws-cli --classic",windows:"winget install Amazon.AWSCLI (or the MSI from https://aws.amazon.com/cli/)"}},deno:{name:"Deno",purpose:"BIDS validation",cmd:["deno","--version"],required:!0,installInstructions:{macos:"brew install deno (or: curl -fsSL https://deno.land/install.sh | sh)",linux:"curl -fsSL https://deno.land/install.sh | sh",windows:"winget install DenoLand.Deno (or: irm https://deno.land/install.ps1 | iex)"}}},ZF={upload:["git-annex","gh","aws","deno"],download:["gh"],clone:["git","gh"],push:["git-annex","gh"],publish:["gh","aws"],update:["git","gh"],release:["git","gh"]}});var wb;var Eb=F(()=>{wb={name:"nemar-cli",packageManager:"bun@1.4.3",version:"0.10.37-dev.4659",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js","git-annex-remote-nemar":"dist/git-annex-remote-nemar.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts src/git-annex-remote-nemar.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:scrub":"biome check scripts/scrub shared/identifier-scrub.ts test/scrub","test:scrub":"bun test --preload ./test/scrub/helpers/temp-dirs-preload.ts --path-ignore-patterns='__run_every_scrub_suite__' test/scrub test/identifier-scan.test.ts test/identifier-scrub.test.ts test/identifier-dates.test.ts test/identifier-fleet.test.ts","migrations:d1-check":"bun run scripts/d1-migration-check.ts","zarr:geometry-check":"bun run backend/scripts/zarr-geometry-conformance.ts","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend","generate-openapi":"bun run scripts/generate-openapi.ts",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},trustedDependencies:["@biomejs/biome"],devDependencies:{"@anthropic-ai/sdk":"^0.132.1","@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",ajv:"^8.20.0","ajv-formats":"^3.0.1",husky:"^9.1.7",jose:"6.2.12","lint-staged":"^16.3.2",oauth4webapi:"3.8.8","openid-client":"6.8.9",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var ac;var Gl=F(()=>{Eb();ac=wb.version});import{mkdirSync as oV,readdirSync as iV,unlinkSync as aV,writeFileSync as cV}from"fs";import{join as Kl}from"path";function dB(){Ds=!0}function lc(){return Ds}function fB(e,t=process.env){return e.includes("--debug")||t.NEMAR_DEBUG==="1"}function pB(e){Tb=e,pr(`Step: ${e}`)}function hB(){xb=!0}function mB(){return xb}function gB(){if(Rb)return;Bl=!0}function yB(){Bl=!1,Rb=!0}function _B(){return Bl}function pr(e){if(Ds)process.stderr.write(`[debug] ${e}
27
27
  `)}function fV(e){let t={};for(let[r,n]of Object.entries(e))t[r]=dV.has(r.toLowerCase())?"[REDACTED]":n;return t}function Ob(e){let t=e.indexOf("@");if(t<=0)return"***";return`${e[0]}***${e.slice(t)}`}function Hl(e,t,r=0){if(r>hV)return"[REDACTED: depth]";if(Array.isArray(t))return t.map((n)=>Hl(e,n,r+1));if(t&&typeof t==="object"){let n={};for(let[s,o]of Object.entries(t))n[s]=Hl(s,o,r+1);return n}if(typeof t==="string"){if(pV.test(e))return"[REDACTED]";return t.replace(kb,Ob)}return t}function Wl(e){return e.replace(mV,"Bearer [REDACTED]").replace(gV,"[REDACTED_AWS_KEY]").replace(yV,"$1[REDACTED]").replace(_V,"$1$2=[REDACTED]").replace(kb,Ob)}function vV(e){return Wl(e)}function bb(e,t=lV){if(e===void 0)return;let r=e;try{let n=JSON.parse(e);r=JSON.stringify(Hl("",n))}catch{}if(r=Wl(r),Buffer.byteLength(r,"utf8")>t)r=`${Buffer.from(r,"utf8").subarray(0,t).toString("utf8")}... [truncated]`;return r}function dc(e){if(!Ds)return;let t=vV(e.url);try{let r={...e,url:t,requestHeaders:e.requestHeaders?fV(e.requestHeaders):void 0,requestBody:bb(e.requestBody),responseBody:bb(e.responseBody)};uc.push(r),pr(`${e.method} ${t} -> ${e.status??"ERROR"} (${e.durationMs}ms)`)}catch(r){let n=dr(r);uc.push({method:e.method,url:t,status:e.status,durationMs:e.durationMs,note:`redaction failed: ${n}`}),pr(`redaction failed for ${e.method} ${t}: ${n}`)}}async function $V(){let e=[];try{let t=process.versions.bun?`Bun ${process.versions.bun}`:`Node ${process.version}`;e.push(`CLI version: ${ac}`),e.push(`OS/Arch: ${process.platform}/${process.arch}`),e.push(`Runtime: ${t}`)}catch(t){e.push(`(could not read CLI/OS/runtime info: ${dr(t)})`)}e.push(""),e.push("Active account:");try{let t=hn();if(t.apiKey){if(t.username)e.push(` Username: ${t.username}`);if(e.push(` API URL: ${t.apiUrl}`),t.role)e.push(` Role: ${t.role}`);e.push(` Sandbox completed: ${!!t.sandboxCompleted}`)}else e.push(" (not authenticated)")}catch(t){e.push(` (could not read account config: ${dr(t)})`)}e.push(""),e.push("External tools:");try{let t=await zl();for(let r of t){let n=r.available?r.version??"installed":r.timedOut?"(timed out)":"not installed";e.push(` ${r.name}: ${n}`)}}catch(t){e.push(` (could not probe external tools: ${dr(t)})`)}return e}async function EV(){return(await $V()).join(`
28
28
  `)}async function vB(){if(!Ds||cc!==void 0)return;try{cc=await EV()}catch(e){let t=dr(e);cc=`(could not build environment report: ${t})`,pr(`environment snapshot failed: ${t}`)}}function Ab(e){if(Sb.has(e))return{flag:e};for(let t of Sb){if(!e.startsWith(t)||e.length<=t.length)continue;if(t.length===2)return{flag:t,kind:"short-attached"};if(e[t.length]==="=")return{flag:t,kind:"long-eq"}}return null}function wV(e){let t=[];for(let r=0;r<e.length;r++){let n=e[r],s=Ab(n);if(!s){t.push(n);continue}if(s.kind==="long-eq")t.push(`${s.flag}=[REDACTED]`);else if(s.kind==="short-attached")t.push(`${s.flag}[REDACTED]`);else if(t.push(n),r+1<e.length)t.push("[REDACTED]"),r++}return t}function bV(e){let t=[];for(let r=0;r<e.length;r++){let n=e[r],s=Ab(n);if(!s){t.push(n);continue}if(!s.kind&&r+1<e.length)r++}return t}function SV(e){let t=[];for(let n of bV(e)){if(n.startsWith("-"))continue;if(t.push(n),t.length===2)break}return(t.length>0?t.join("-"):"nemar").replace(/[^a-zA-Z0-9_-]/g,"_")}function xV(e,t){let r=[];if(r.push("NEMAR CLI Debug Log"),r.push(`Generated: ${new Date().toISOString()}`),r.push(`Command: nemar ${Wl(wV(e).join(" "))}`),r.push(""),r.push(cc??"(environment snapshot unavailable)"),r.push(""),r.push("HTTP requests:"),uc.length===0)r.push(" (none)");else uc.forEach((n,s)=>{if(r.push(` [${s+1}] ${n.method} ${n.url} -> ${n.status??"ERROR"} (${n.durationMs}ms)`),n.error)r.push(` Error: ${n.error}`);if(n.note)r.push(` Note: ${n.note}`);if(n.requestHeaders)r.push(` Request headers: ${JSON.stringify(n.requestHeaders)}`);if(n.requestBody)r.push(` Request body: ${n.requestBody}`);if(n.responseBody)r.push(` Response body: ${n.responseBody}`)});return r.push(""),r.push(`Failing step: ${Tb??"(none recorded)"}`),r.push(`Exit code: ${t}`),`${r.join(`
29
29
  `)}
package/dist/index.js CHANGED
@@ -99,7 +99,7 @@ ${t}`,vQe,EQe,SQe=(e,t,n)=>{let r=n===""?"":`with ${n.trim()}() `,o=xQe.bind(nul
99
99
  `)}var xM=!1;var{spawn:vwt}=globalThis.Bun;function bp(e,t=[]){let n=e.replace(Ewt,'("$1","<redacted>")');for(let r of t)if(r.length>=Swt)n=n.split(r).join("<redacted>");return n}function ZR(e){let t=["AWS_SESSION_TOKEN","AWS_SECRET_ACCESS_KEY","AWS_ACCESS_KEY_ID"],n=new Set;for(let r of[process.env,e??{}])for(let o of t){let s=r[o];if(typeof s==="string"&&s.length>0)n.add(s)}return[...n]}async function Ige(e,t){let n=e.getReader(),r=new TextDecoder,o="";while(!0){let{done:s,value:i}=await n.read();if(s)break;if(i.byteLength===0)continue;t(),o+=r.decode(i,{stream:!0})}return o+r.decode()}async function O(e,t={}){let n={...process.env,GIT_TERMINAL_PROMPT:"0",...t.env};for(let y of t.unsetEnv??[])delete n[y];let r=vwt({cmd:e,cwd:t.cwd,...t.stdin===void 0?{}:{stdin:new TextEncoder().encode(t.stdin)},stdout:"pipe",stderr:"pipe",env:n}),o=!1,s,i,a=performance.now(),c=()=>{if(i!==void 0)clearTimeout(i),i=void 0},l=()=>{if(!t.onInactivityWarning)return;c(),i=setTimeout(()=>{i=void 0;try{t.onInactivityWarning?.(performance.now()-a)}catch{console.error("Could not display subprocess inactivity warning; the child result is unaffected.")}},t.inactivityWarningAfterMs??kwt)};if(l(),t.timeout)s=setTimeout(()=>{o=!0,c(),r.kill()},t.timeout);let d=Gg()?[...ZR(n),...t.redact??[]]:[];if(Gg()){let y=t.cwd?` (cwd=${t.cwd})`:"";Gd(u.dim(bp(`$ ${e.join(" ")}${y}`,d)))}let f=()=>{a=performance.now(),l()},p,m,h,g=r.exited.then((y)=>(c(),y));try{[p,m,h]=await Promise.all([Ige(r.stdout,f),Ige(r.stderr,f),g])}finally{if(c(),s)clearTimeout(s)}if(Gg()){if(t.sensitiveOutput)Gd(u.dim("[sensitive subprocess output suppressed]"));else{if(p.trim())Gd(u.dim(bp(p.trimEnd(),d)));if(m.trim())Gd(u.yellow(bp(m.trimEnd(),d)))}Gd(u.dim(`(exit ${h})`))}if(o)return{stdout:p,stderr:m||`Command timed out after ${Math.round(t.timeout/1000)}s`,exitCode:h??1,timedOut:!0};return{stdout:p,stderr:m,exitCode:h,timedOut:!1}}var Ewt,Swt=8,kwt=120000;var Gt=z(()=>{We();Ewt=/\(\s*"((?:x-amz-)[^"]*|authorization|proxy-authorization)"\s*,\s*"[^"]*"\s*\)/gi});function $wt(){if(process.platform==="darwin")return"macos";if(process.platform==="win32")return"windows";return"linux"}function Fge(e,t=$wt()){return e.installInstructions[t]}function Dwt(e){let t=e.match(/(\d+\.\d+(?:\.\d+)?)/);return t?t[1]:void 0}function Awt(){let e=Number(process.env.TEST_PROBE_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:Cwt}async function Mge(e){try{let{exitCode:t,stdout:n,timedOut:r}=await O(e.cmd,{timeout:Awt()});if(r)return{available:!1,timedOut:!0};if(t!==0)return{available:!1};return{available:!0,version:Dwt(n)}}catch(t){let n=t instanceof Error?t.message:String(t);if(!n.includes("ENOENT")&&!n.includes("not found"))console.error(` Warning: ${e.name} check failed unexpectedly: ${n}`);return{available:!1}}}async function zw(){let e=Object.entries(Nge);return Promise.all(e.map(async([t,n])=>{let{available:r,version:o,timedOut:s}=await Mge(n);return{key:t,name:n.name,purpose:n.purpose,required:n.required,available:r,version:o,timedOut:s,installInstruction:Fge(n)}}))}async function jge(){let t=(await zw()).filter((n)=>n.required&&!n.available);if(t.length===0)return[];console.warn(`
100
100
  Heads up: some tools NEMAR needs for uploading/validating aren't installed yet:`);for(let n of t)console.warn(` - ${n.name} (${n.purpose})`),console.warn(` Install: ${n.installInstruction}`);return console.warn("Run `nemar doctor` anytime to re-check. You can finish signup without them.\n"),t}async function wp(e){let n=Rwt[e].map((i)=>Nge[i]).filter(Boolean),r=await Promise.all(n.map(async(i)=>{let a=await Mge(i);return{check:i,available:a.available,timedOut:a.timedOut}}));for(let i of r)if(i.timedOut&&i.check.required)console.warn(`Warning: ${i.check.name} did not respond to a version check in time; continuing anyway.`);let o=r.filter((i)=>!i.available&&!i.timedOut&&i.check.required).map((i)=>({tool:i.check.name,installInstruction:Fge(i.check)}));if(o.length===0)return;let s=[`
101
101
  Missing required tools:`];for(let i of o)s.push(` ${i.tool} not installed`),s.push(` Install: ${i.installInstruction}`);throw Error(s.join(`
102
- `))}var Nge,Rwt,Cwt=4000;var Vw=z(()=>{Gt();Nge={git:{name:"git",purpose:"version control for dataset metadata",cmd:["git","--version"],required:!0,installInstructions:{macos:"brew install git (or install Xcode Command Line Tools)",linux:"sudo apt-get install git OR sudo dnf install git",windows:"winget install Git.Git (or https://git-scm.com/download/win)"}},"git-annex":{name:"git-annex",purpose:"large-file data transfer (upload/download)",cmd:["git-annex","version"],required:!0,installInstructions:{macos:"brew install git-annex",linux:"sudo apt-get install git-annex OR sudo dnf install git-annex",windows:"Download the installer from https://git-annex.branchable.com/install/Windows/"}},gh:{name:"GitHub CLI (gh)",purpose:"GitHub authentication + repository operations",cmd:["gh","--version"],required:!0,installInstructions:{macos:"brew install gh",linux:"See https://cli.github.com/manual/installation",windows:"winget install GitHub.cli (or: scoop install gh)"}},aws:{name:"AWS CLI",purpose:"S3 data upload/download",cmd:["aws","--version"],required:!0,installInstructions:{macos:"brew install awscli",linux:"pip install awscli OR sudo snap install aws-cli --classic",windows:"winget install Amazon.AWSCLI (or the MSI from https://aws.amazon.com/cli/)"}},deno:{name:"Deno",purpose:"BIDS validation",cmd:["deno","--version"],required:!0,installInstructions:{macos:"brew install deno (or: curl -fsSL https://deno.land/install.sh | sh)",linux:"curl -fsSL https://deno.land/install.sh | sh",windows:"winget install DenoLand.Deno (or: irm https://deno.land/install.ps1 | iex)"}}},Rwt={upload:["git-annex","gh","aws","deno"],download:["gh"],clone:["git","gh"],push:["git-annex","gh"],publish:["gh","aws"],update:["git","gh"],release:["git","gh"]}});var qge;var Lge=z(()=>{qge={name:"nemar-cli",packageManager:"bun@1.4.3",version:"0.10.37-dev.4640",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js","git-annex-remote-nemar":"dist/git-annex-remote-nemar.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts src/git-annex-remote-nemar.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:scrub":"biome check scripts/scrub shared/identifier-scrub.ts test/scrub","test:scrub":"bun test --preload ./test/scrub/helpers/temp-dirs-preload.ts --path-ignore-patterns='__run_every_scrub_suite__' test/scrub test/identifier-scan.test.ts test/identifier-scrub.test.ts test/identifier-dates.test.ts test/identifier-fleet.test.ts","migrations:d1-check":"bun run scripts/d1-migration-check.ts","zarr:geometry-check":"bun run backend/scripts/zarr-geometry-conformance.ts","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend","generate-openapi":"bun run scripts/generate-openapi.ts",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},trustedDependencies:["@biomejs/biome"],devDependencies:{"@anthropic-ai/sdk":"^0.132.1","@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",ajv:"^8.20.0","ajv-formats":"^3.0.1",husky:"^9.1.7",jose:"6.2.12","lint-staged":"^16.3.2",oauth4webapi:"3.8.8","openid-client":"6.8.9",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var Gs;var _p=z(()=>{Lge();Gs=qge.version});import{mkdirSync as Twt,readdirSync as Pwt,unlinkSync as Iwt,writeFileSync as Nwt}from"fs";import{join as vM}from"path";function Vge(){zg=!0}function jl(){return zg}function Wge(e,t=process.env){return e.includes("--debug")||t.NEMAR_DEBUG==="1"}function Kw(e){zge=e,In(`Step: ${e}`)}function Yo(){Hge=!0}function Kge(){return Hge}function ue(){if(Gge)return;SM=!0}function Jw(){SM=!1,Gge=!0}function Jge(){return SM}function In(e){if(zg)process.stderr.write(`[debug] ${e}
102
+ `))}var Nge,Rwt,Cwt=4000;var Vw=z(()=>{Gt();Nge={git:{name:"git",purpose:"version control for dataset metadata",cmd:["git","--version"],required:!0,installInstructions:{macos:"brew install git (or install Xcode Command Line Tools)",linux:"sudo apt-get install git OR sudo dnf install git",windows:"winget install Git.Git (or https://git-scm.com/download/win)"}},"git-annex":{name:"git-annex",purpose:"large-file data transfer (upload/download)",cmd:["git-annex","version"],required:!0,installInstructions:{macos:"brew install git-annex",linux:"sudo apt-get install git-annex OR sudo dnf install git-annex",windows:"Download the installer from https://git-annex.branchable.com/install/Windows/"}},gh:{name:"GitHub CLI (gh)",purpose:"GitHub authentication + repository operations",cmd:["gh","--version"],required:!0,installInstructions:{macos:"brew install gh",linux:"See https://cli.github.com/manual/installation",windows:"winget install GitHub.cli (or: scoop install gh)"}},aws:{name:"AWS CLI",purpose:"S3 data upload/download",cmd:["aws","--version"],required:!0,installInstructions:{macos:"brew install awscli",linux:"pip install awscli OR sudo snap install aws-cli --classic",windows:"winget install Amazon.AWSCLI (or the MSI from https://aws.amazon.com/cli/)"}},deno:{name:"Deno",purpose:"BIDS validation",cmd:["deno","--version"],required:!0,installInstructions:{macos:"brew install deno (or: curl -fsSL https://deno.land/install.sh | sh)",linux:"curl -fsSL https://deno.land/install.sh | sh",windows:"winget install DenoLand.Deno (or: irm https://deno.land/install.ps1 | iex)"}}},Rwt={upload:["git-annex","gh","aws","deno"],download:["gh"],clone:["git","gh"],push:["git-annex","gh"],publish:["gh","aws"],update:["git","gh"],release:["git","gh"]}});var qge;var Lge=z(()=>{qge={name:"nemar-cli",packageManager:"bun@1.4.3",version:"0.10.37-dev.4659",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js","git-annex-remote-nemar":"dist/git-annex-remote-nemar.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.ts src/git-annex-remote-nemar.ts --outdir dist --target bun --minify && sed '1s|#!/usr/bin/env node|#!/usr/bin/env bun|' dist/index.js > dist/index.js.tmp && mv dist/index.js.tmp dist/index.js",test:"bun test",lint:"biome check src/","lint:scrub":"biome check scripts/scrub shared/identifier-scrub.ts test/scrub","test:scrub":"bun test --preload ./test/scrub/helpers/temp-dirs-preload.ts --path-ignore-patterns='__run_every_scrub_suite__' test/scrub test/identifier-scan.test.ts test/identifier-scrub.test.ts test/identifier-dates.test.ts test/identifier-fleet.test.ts","migrations:d1-check":"bun run scripts/d1-migration-check.ts","zarr:geometry-check":"bun run backend/scripts/zarr-geometry-conformance.ts","lint:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit && tsc --noEmit -p backend","generate-openapi":"bun run scripts/generate-openapi.ts",prepublishOnly:"bun run build",prepare:"husky",postinstall:"bun scripts/postinstall-check.mjs",deploy:"wrangler deploy",preview:"wrangler dev"},keywords:["nemar","bids","neuroimaging","eeg","emg","datalad","cli"],author:"NEMAR Team",license:"CC-BY-NC-ND-4.0",repository:{type:"git",url:"git+https://github.com/nemarOrg/nemar-cli.git"},bugs:{url:"https://github.com/nemarOrg/nemar-cli/issues"},homepage:"https://docs.nemar.org",engines:{bun:">=1.0.0"},files:["dist","scripts/postinstall-check.mjs","scripts/recover-datasets.json","scripts/withdrawn-datasets.json","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1",inquirer:"^9.2.15",ora:"^8.0.1",semver:"^7.8.5",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},trustedDependencies:["@biomejs/biome"],devDependencies:{"@anthropic-ai/sdk":"^0.132.1","@asteasolutions/zod-to-openapi":"^7.3.4","@biomejs/biome":"1.9.4","@types/bun":"latest","@types/inquirer":"^9.0.7","@types/semver":"^7.8.0",ajv:"^8.20.0","ajv-formats":"^3.0.1",husky:"^9.1.7",jose:"6.2.12","lint-staged":"^16.3.2",oauth4webapi:"3.8.8","openid-client":"6.8.9",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var Gs;var _p=z(()=>{Lge();Gs=qge.version});import{mkdirSync as Twt,readdirSync as Pwt,unlinkSync as Iwt,writeFileSync as Nwt}from"fs";import{join as vM}from"path";function Vge(){zg=!0}function jl(){return zg}function Wge(e,t=process.env){return e.includes("--debug")||t.NEMAR_DEBUG==="1"}function Kw(e){zge=e,In(`Step: ${e}`)}function Yo(){Hge=!0}function Kge(){return Hge}function ue(){if(Gge)return;SM=!0}function Jw(){SM=!1,Gge=!0}function Jge(){return SM}function In(e){if(zg)process.stderr.write(`[debug] ${e}
103
103
  `)}function Lwt(e){let t={};for(let[n,r]of Object.entries(e))t[n]=jwt.has(n.toLowerCase())?"[REDACTED]":r;return t}function Xge(e){let t=e.indexOf("@");if(t<=0)return"***";return`${e[0]}***${e.slice(t)}`}function EM(e,t,n=0){if(n>Uwt)return"[REDACTED: depth]";if(Array.isArray(t))return t.map((r)=>EM(e,r,n+1));if(t&&typeof t==="object"){let r={};for(let[o,s]of Object.entries(t))r[o]=EM(o,s,n+1);return r}if(typeof t==="string"){if(qwt.test(e))return"[REDACTED]";return t.replace(Yge,Xge)}return t}function kM(e){return e.replace(Bwt,"Bearer [REDACTED]").replace(Hwt,"[REDACTED_AWS_KEY]").replace(Gwt,"$1[REDACTED]").replace(zwt,"$1$2=[REDACTED]").replace(Yge,Xge)}function Vwt(e){return kM(e)}function Uge(e,t=Mwt){if(e===void 0)return;let n=e;try{let r=JSON.parse(e);n=JSON.stringify(EM("",r))}catch{}if(n=kM(n),Buffer.byteLength(n,"utf8")>t)n=`${Buffer.from(n,"utf8").subarray(0,t).toString("utf8")}... [truncated]`;return n}function n$(e){if(!zg)return;let t=Vwt(e.url);try{let n={...e,url:t,requestHeaders:e.requestHeaders?Lwt(e.requestHeaders):void 0,requestBody:Uge(e.requestBody),responseBody:Uge(e.responseBody)};t$.push(n),In(`${e.method} ${t} -> ${e.status??"ERROR"} (${e.durationMs}ms)`)}catch(n){let r=W(n);t$.push({method:e.method,url:t,status:e.status,durationMs:e.durationMs,note:`redaction failed: ${r}`}),In(`redaction failed for ${e.method} ${t}: ${r}`)}}async function Wwt(){let e=[];try{let t=process.versions.bun?`Bun ${process.versions.bun}`:`Node ${process.version}`;e.push(`CLI version: ${Gs}`),e.push(`OS/Arch: ${process.platform}/${process.arch}`),e.push(`Runtime: ${t}`)}catch(t){e.push(`(could not read CLI/OS/runtime info: ${W(t)})`)}e.push(""),e.push("Active account:");try{let t=Yt();if(t.apiKey){if(t.username)e.push(` Username: ${t.username}`);if(e.push(` API URL: ${t.apiUrl}`),t.role)e.push(` Role: ${t.role}`);e.push(` Sandbox completed: ${!!t.sandboxCompleted}`)}else e.push(" (not authenticated)")}catch(t){e.push(` (could not read account config: ${W(t)})`)}e.push(""),e.push("External tools:");try{let t=await zw();for(let n of t){let r=n.available?n.version??"installed":n.timedOut?"(timed out)":"not installed";e.push(` ${n.name}: ${r}`)}}catch(t){e.push(` (could not probe external tools: ${W(t)})`)}return e}async function RM(){return(await Wwt()).join(`
104
104
  `)}async function Qge(){if(!zg||e$!==void 0)return;try{e$=await RM()}catch(e){let t=W(e);e$=`(could not build environment report: ${t})`,In(`environment snapshot failed: ${t}`)}}function Zge(e){if(Bge.has(e))return{flag:e};for(let t of Bge){if(!e.startsWith(t)||e.length<=t.length)continue;if(t.length===2)return{flag:t,kind:"short-attached"};if(e[t.length]==="=")return{flag:t,kind:"long-eq"}}return null}function Kwt(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],o=Zge(r);if(!o){t.push(r);continue}if(o.kind==="long-eq")t.push(`${o.flag}=[REDACTED]`);else if(o.kind==="short-attached")t.push(`${o.flag}[REDACTED]`);else if(t.push(r),n+1<e.length)t.push("[REDACTED]"),n++}return t}function Jwt(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],o=Zge(r);if(!o){t.push(r);continue}if(!o.kind&&n+1<e.length)n++}return t}function Ywt(e){let t=[];for(let r of Jwt(e)){if(r.startsWith("-"))continue;if(t.push(r),t.length===2)break}return(t.length>0?t.join("-"):"nemar").replace(/[^a-zA-Z0-9_-]/g,"_")}function Xwt(e,t){let n=[];if(n.push("NEMAR CLI Debug Log"),n.push(`Generated: ${new Date().toISOString()}`),n.push(`Command: nemar ${kM(Kwt(e).join(" "))}`),n.push(""),n.push(e$??"(environment snapshot unavailable)"),n.push(""),n.push("HTTP requests:"),t$.length===0)n.push(" (none)");else t$.forEach((r,o)=>{if(n.push(` [${o+1}] ${r.method} ${r.url} -> ${r.status??"ERROR"} (${r.durationMs}ms)`),r.error)n.push(` Error: ${r.error}`);if(r.note)n.push(` Note: ${r.note}`);if(r.requestHeaders)n.push(` Request headers: ${JSON.stringify(r.requestHeaders)}`);if(r.requestBody)n.push(` Request body: ${r.requestBody}`);if(r.responseBody)n.push(` Response body: ${r.responseBody}`)});return n.push(""),n.push(`Failing step: ${zge??"(none recorded)"}`),n.push(`Exit code: ${t}`),`${n.join(`
105
105
  `)}
@@ -941,7 +941,7 @@ ${uSe(r[1],s)}
941
941
  `))return"provenance-readme-note"}return null}if(em.test(e)&&i.length<=ZL){if(nm(v$e(i),a))return"json-blanked"}if(tm.test(e)&&i.length<=e4)try{let c=dC(i);if(c.status==="normalized"&&nm(c.bytes??null,a))return"scans-dates"}catch{}return null}function k$e(e,t,n){let r=TC(e),o=nx(e),s=(a,c,l)=>d4(a,c,l,n.collect);if(t.kind==="absent"){if(e===S$e&&n.generatedParticipants)return s("100644",n.generatedParticipants,"participants-generated");if(o&&r===".bidsignore"&&n.oursHasBidsignore)return s("100644",Gl("",Hl).content,"bidsignore-entry");if(o&&r==="CHANGES"&&n.sentences.length>0)return s("100644",n.sentences.join(""),"changes-ledger-sentence");return{kind:"absent"}}if(t.kind==="annex"){if(o&&Dp(r))return r==="CHANGES"&&n.sentences.length>0?{kind:"unannex",key:t.key,append:[...n.sentences]}:{kind:"unannex",key:t.key};return{kind:"annex",key:t.key}}let i=t.bytes?.length??t.size;if(r===".gitattributes"){let a=t.bytes?Vc(t.bytes):null;if(a===null)return{kind:"unknown",reason:"gitattributes-unread"};return s(t.mode,hf(a).content,"gitattributes-stripped")}if(o&&r===".bidsignore"){let a=t.bytes?Vc(t.bytes):null;if(a===null)return{kind:"unknown",reason:"bidsignore-unread"};return s(t.mode,Gl(a,Hl).content,"bidsignore-entry")}if(o&&r==="CHANGES"&&n.sentences.length>0){if(!t.bytes)return{kind:"unknown",reason:"changes-unread"};return s(t.mode,Buffer.concat([t.bytes,Buffer.from(n.sentences.join(""))]),"changes-ledger-sentence")}if(ho(e,i??1048576))return{kind:"annex-from-git",oid:t.oid,size:i??null};return{kind:"git",mode:t.mode,oid:t.oid}}function d4(e,t,n,r){let o=typeof t==="string"?Buffer.from(t):t,s=bf(o);return r?.computed.set(s,o),{kind:"git",mode:e,oid:s,computed:n}}function PC(e,t){if(e.kind==="absent")return t.kind==="absent";if(e.kind==="annex")return t.kind==="annex"&&t.key===e.key;if(e.kind==="git")return t.kind==="git"&&t.oid===e.oid&&t.mode===e.mode;return!1}var Fn="dataset_description.json",mOt=new Set(["DatasetDOI","Version","SourceDatasets"]);function f4(e,t){if(!t)return null;if(!e)return"unparseable";try{let n=xo(new TextDecoder("utf-8",{fatal:!0}).decode(e)),r=JSON.parse(n);return r&&typeof r==="object"&&!Array.isArray(r)?r:"unparseable"}catch{return"unparseable"}}function R$e(e,t){if(!e)return t;try{let n=Hy(e);if(n.status!=="blanked"||!n.bytes)return t;let r=JSON.parse(xo(new TextDecoder().decode(n.bytes)));return r&&typeof r==="object"&&!Array.isArray(r)?r:t}catch{return t}}function hOt(e){let t=e.SourceDatasets;if(Array.isArray(t))return t;if(t!==void 0&&t!==null&&typeof t==="object")return[t];return[]}function gOt(e,t){return{DOI:`doi:10.18112/openneuro.${e}.v${t}`,URL:`https://openneuro.org/datasets/${e}/versions/${t}`,Version:t}}function yOt(e,t,n){if(e===null)return"both-added";if(t===null)return"upstream-deleted/nemar-changed";if(n===null)return"nemar-deleted/upstream-changed";return"both-modified"}function bOt(e,t){if(e===null)return"nemar-added";if(t===null)return"nemar-deleted";return"nemar-modified"}function $$e(e){let t={kept:0,addedByNemar:0,removedByUpstream:0},n=f4(e.base.bytes,e.base.present),r=f4(e.theirs.bytes,e.theirs.present),o=f4(e.ours.bytes,e.ours.present);if(n==="unparseable"||r==="unparseable"||o==="unparseable")return{status:"unparseable",keys:[],explainedBase:!1,explained:!1,upstreamChanged:!0,sourceDatasets:t,mergedJson:null,conceptDoi:o&&o!=="unparseable"&&typeof o.DatasetDOI==="string"?o.DatasetDOI:null};if(r===null)return{status:"absent",keys:[],explainedBase:!1,explained:!1,upstreamChanged:n!==null,sourceDatasets:t,mergedJson:null,conceptDoi:o&&typeof o.DatasetDOI==="string"?o.DatasetDOI:null};let s=n??{},i=r,a=o??{},c=R$e(e.base.bytes,s),l=R$e(e.theirs.bytes,i),d=[];for(let M of[...Object.keys(i),...Object.keys(a),...Object.keys(s)])if(!d.includes(M)&&!mOt.has(M))d.push(M);let f=(M,P)=>Object.hasOwn(M,P)?nu(M[P]):null,p=[],m={},h=!0,g=!0,y=!1;for(let M of d){let P=f(s,M),G=f(i,M),se=f(a,M),De=se===P||se===f(c,M),ln=se===G||se===f(l,M),ot=P!==G;if(ot)y=!0;if(!De)h=!1;if(!De&&!ln)g=!1;let lt,ae,Ye=null;if(!ot&&(De||ln))lt="keep-ours",ae="ours";else if(ot&&(De||ln))lt="take-theirs",ae=ln?"ours":"theirs";else if(ot)lt="conflict",ae="theirs",Ye=yOt(P,G,se);else lt="correction",ae="theirs",Ye=bOt(P,se);let Pe=ae==="ours"?a:i;if(Object.hasOwn(Pe,M))m[M]=Pe[M];if(P!==G||P!==se)p.push({key:M,class:lt,subtype:Ye,base:P,theirs:G,ours:se,take:ae})}let b=(M)=>hOt(M).filter((P)=>!Uy(P,e.ds)),x=new Set(b(s).map(nu)),v=b(i),S=b(a),E=new Set(v.map(nu)),A=new Set(S.map(nu)),I=[],H=new Set,T=0,L=0;for(let M of v){let P=nu(M);if(H.has(P)||x.has(P)&&!A.has(P))continue;H.add(P),I.push(M),T++}for(let M of S){let P=nu(M);if(H.has(P)||x.has(P))continue;H.add(P),I.push(M),L++}let q=[...x].filter((M)=>!E.has(M)&&A.has(M)).length;I.push(gOt(e.ds,e.toTag));let V=typeof a.DatasetDOI==="string"?a.DatasetDOI:null,B={...m};if(V!==null)B.DatasetDOI=V;return B.Version=e.nextVersion,B.SourceDatasets=I,p.sort((M,P)=>M.key<P.key?-1:M.key>P.key?1:0),{status:"merged",keys:p,explainedBase:h,explained:g,upstreamChanged:y,sourceDatasets:{kept:T,addedByNemar:L,removedByUpstream:q},mergedJson:qc(B),conceptDoi:V}}ta();Vp();function rx(e){return e.replace(/^v/,"")}async function D$e(e){let t=e.flag?.trim()||void 0;if(t!==void 0&&!qr(t))return{tag:null,source:null,check:{name:"from-tag",status:"refused",code:"from-tag-malformed",detail:`${t} is not an OpenNeuro snapshot tag`}};let n=t===void 0?void 0:Ol(t),r=null,o=null,s=e.rows?SL(e.rows):null,i=null;if(s?.state==="known")r={tag:s.tag,source:"version-row"};else if(s?.state==="unknown")o=`the version row ${s.version} is recorded unknown`;else if(s?.state==="unexamined")i=s.version;else if(s?.state==="none")return{tag:null,source:null,check:{name:"from-tag",status:"refused",code:"never-released",detail:"no version row"}};else if(i=e.highestTag?rx(e.highestTag):null,i===null)return{tag:null,source:null,check:{name:"from-tag",status:"refused",code:"never-released",detail:"no version rows could be read and the repository has no v* tag"}};if(i!==null){let a=await e.readTagged(i),c=a===void 0?null:By(a,e.ds);if(c?.source_version_basis==="doi")r={tag:c.source_version,source:"tagged-description"};else o=a===void 0?`v${i} has no dataset_description.json`:`v${i}'s dataset_description.json names no single upstream tag`}if(r){if(n!==void 0&&!Ur(n,r.tag))return{tag:null,source:null,check:{name:"from-tag",status:"refused",code:"from-tag-disagrees",detail:`--from-tag ${n} but the mirror records ${r.tag}`}};return{tag:r.tag,source:r.source,check:{name:"from-tag",status:"ok",detail:`${r.tag} (${r.source})`}}}if(n!==void 0)return{tag:n,source:"flag",check:{name:"from-tag",status:"refused",code:"from-tag-not-recorded",detail:`${o}; --from-tag ${n} gives a dry run only`}};return{tag:null,source:null,check:{name:"from-tag",status:"refused",code:"from-tag-unknown",detail:`${o}; a mirror whose tag is unknown is never re-pulled`}}}g4();$i();ya();function ba(e){return e.startsWith(".nemar/")||e.startsWith(".github/")}var P$e=new Set(["100644","100755"]),_Ot=1048576;function NC(e){return e?`${e.mode}:${e.oid}`:"absent"}function Jy(e,t){if(!e)return Wy;let n=t.get(e.oid);if(n&&(e.mode==="120000"||P$e.has(e.mode)&&n.length<=32768)){let r=rm(e.mode,n);if(r)return{kind:"annex",key:r,mode:e.mode,oid:e.oid}}return{kind:"git",mode:e.mode,oid:e.oid,size:n?.length??null,bytes:n}}function y4(e,t,n){if(e.kind==="absent")return"both-added";if(t.kind==="absent")return"upstream-deleted/nemar-changed";if(n.kind==="absent")return"nemar-deleted/upstream-changed";return"both-modified"}function b4(e,t){if(e.kind==="absent")return"nemar-added";if(t.kind==="absent")return"nemar-deleted";return"nemar-modified"}function w4(e,t){if(!e)return t?"keep-ours":"correction";return t?"take-theirs":"conflict"}function xOt(e){if(!e)return null;if("bytes"in e)return e.bytes;return e.side.kind==="git"?e.side.bytes:null}function I$e(e,t){if("bytes"in e)return t.kind==="git"&&!!t.bytes&&t.bytes.equals(e.bytes);let n=e.side;if(mr(n)===mr(t))return!0;if(n.kind==="annex"&&t.kind==="git"&&t.bytes)return tu(n.key,t.bytes);return!1}function N$e(e,t){let n=new Map([...e].map(([s,i])=>[s,{side:i}])),r=[...e].filter(([,s])=>s.kind==="annex"||s.kind==="git"&&P$e.has(s.mode)).map(([s])=>s).sort(),o=IC(r);if(o.kind==="renamed"){let s=n.get(o.from);if(n.delete(o.from),s)n.set("README.md",s)}else if(o.kind==="created")n.set("README.md",{bytes:Buffer.from(t)});return n}function vOt(e,t){let n=[e],r=Ky(t);if(!r)return n;let o=[h4(r),`[![DOI](https://zenodo.org/badge/DOI/${r}.svg)](https://doi.org/${r})`].map((i)=>`${i}
942
942
 
943
943
  `),s=e;for(;;){let i=o.find((a)=>s.startsWith(a));if(!i)break;s=s.slice(i.length),n.push(s)}return n}function A$e(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e){let o=t.get(n);if(!o||!I$e(r,o))return!1}return!0}function O$e(e,t,n,r){let o=new Map([...e].map(([f,p])=>[f,{side:p}]));if(A$e(o,t))return"identical";let s=N$e(e,n);if(A$e(s,t))return"readme-import";let i=m4([...s.keys()].map((f)=>({path:f}))),a=new Map(s);for(let f of i.remove)a.delete(f.path);let c=i.contentSource?s.get(i.contentSource.path):void 0;a.delete("README.md");let l=t.get("README.md");if(!l||l.kind!=="git"||!l.bytes)return null;if(t.size!==a.size+1)return null;for(let[f,p]of a){let m=t.get(f);if(!m||!I$e(p,m))return null}let d=new TextDecoder().decode(l.bytes);for(let f of vOt(d,r).slice(1)){let p=Buffer.from(f);if(!c){if(p.length===0)return"readme-badge";continue}if("bytes"in c){if(c.bytes.equals(p))return"readme-badge"}else if(c.side.kind==="annex"){if(tu(c.side.key,p))return"readme-badge"}else if(c.side.kind==="git"&&c.side.bytes?.equals(p))return"readme-badge"}return null}function EOt(e,t,n,r){let o=N$e(e,t),s=m4([...o.keys()].map((p)=>({path:p}))),i=new Map;for(let[p,m]of o){if(p==="README.md"||s.remove.some((g)=>g.path===p))continue;let h="bytes"in m?null:m.side;if(!h){let g=m.bytes,y=bf(g);r?.computed.set(y,g),i.set(p,{kind:"git",mode:"100644",oid:y});continue}i.set(p,h.kind==="annex"?{kind:"unannex",key:h.key}:h.kind==="git"?{kind:"git",mode:h.mode,oid:h.oid}:{kind:"absent"})}let a=Ky(n);if(!a)return i.set("README.md",{kind:"unknown",reason:"no-concept-doi"}),i;let c=s.contentSource?o.get(s.contentSource.path):void 0,l=c?xOt(c):Buffer.alloc(0);if(l===null)return i.set("README.md",{kind:"unknown",reason:"readme-unread"}),i;let d=C$e({readmeContent:l.toString("utf8"),doiBadge:h4(a),conceptDoi:a,contentSourcePath:s.contentSource?.path}),f=d.commit?Buffer.from(d.content):l;return i.set("README.md",d4("100644",f,"readme-badge",r)),i}function SOt(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e){let o=t.get(n);if(!o||!PC(r,o))return!1}return!0}function T$e(e){if(!e)return null;try{let t=JSON.parse(xo(e.toString("utf8")));return typeof t?.DatasetDOI==="string"?t.DatasetDOI.replace(/^doi:/,""):null}catch{return null}}async function F$e(e){let{base:t,theirs:n,ours:r,upstream:o,nemar:s}=e,i=new Set([...t.keys(),...n.keys(),...r.keys()]),a=[],c=[];for(let M of[...i].sort()){if(ba(M))continue;let P=[t.get(M),n.get(M),r.get(M)];if(P.some((G)=>G?.type==="commit")){a.push(M);continue}if(NC(P[0])===NC(P[1])&&NC(P[1])===NC(P[2]))continue;c.push(M)}let l=new Set([...i].filter((M)=>nx(M)&&p4.test(M)&&!ba(M))),d=c.some((M)=>l.has(M)),f=new Set([...c,Fn,...d?l:[]]);await o.load([...f].flatMap((M)=>[t.get(M)?.oid,n.get(M)?.oid]).filter((M)=>!!M)),await s.load([...f].map((M)=>r.get(M)?.oid).filter((M)=>!!M));let p=[...r].filter(([M,P])=>P.mode==="120000"&&!ba(M));await s.load(p.map(([,M])=>M.oid));let m=new Set;for(let[,M]of p){let P=s.get(M.oid),G=P?rm(M.mode,P):null;if(G)m.add(G)}let h=new Map;for(let M of f){let P={base:Jy(t.get(M),o),theirs:Jy(n.get(M),o),ours:Jy(r.get(M),s)};if(P.ours.kind==="annex")m.add(P.ours.key);h.set(M,P)}let g=[],y=[];for(let M of c){let P=h.get(M);for(let G of[P.base,P.theirs]){if(G.kind==="git"&&!G.bytes&&o.isMissing(G.oid)&&P.ours.kind==="annex"){let se=rs(P.ours.key)?.size??null;if(se!==null&&(ho(M,_Ot)||ns.test(M)))g.push({oid:G.oid,expected:se})}if(G.kind==="annex"&&P.ours.kind==="git"&&!P.ours.bytes&&s.isMissing(P.ours.oid)&&nx(M)&&Dp(TC(M))){let se=rs(G.key)?.size??null;if(se!==null)y.push({oid:P.ours.oid,expected:se})}}}await o.fetch(g),await s.fetch(y);let b=new Set([...o.refused,...s.refused]);if(g.length+y.length>0)for(let M of c)h.set(M,{base:Jy(t.get(M),o),theirs:Jy(n.get(M),o),ours:Jy(r.get(M),s)});let x=new Set;for(let M of c){let P=h.get(M);if(P.base.kind==="annex")x.add(P.base.key);if(P.theirs.kind==="annex")x.add(P.theirs.key)}await e.prepareDeadKeys([...x].sort());let v={isDeadAtNemar:e.deadAtNemar},S={base:l4(t.keys()),theirs:l4(n.keys())},E={...v,generatedParticipants:S.base},A={...v,generatedParticipants:S.theirs},I=[],H=h.get(Fn),T=$$e({base:sx(H.base),theirs:sx(H.theirs),ours:sx(H.ours),ds:e.ds,toTag:e.toTag,nextVersion:e.nextVersion});{let M=T.upstreamChanged,P=new Set(T.keys.map((De)=>De.class)),G=T.status==="merged",se=!G?w4(M,!1):P.has("conflict")?"conflict":P.has("correction")?"correction":M?"take-theirs":"keep-ours";I.push({path:Fn,group:"description",base:mr(H.base),theirs:mr(H.theirs),ours:mr(H.ours),upstreamChanged:M,explainedBy:{base:T.explainedBase?"description":null,theirs:T.explained?"description":null},class:se,subtype:se!=="conflict"&&se!=="correction"?null:G?"per-key":se==="conflict"?y4(H.base,H.theirs,H.ours):b4(H.base,H.ours),decision:"theirs",target:G?{kind:"description"}:{kind:"unknown",reason:`description-${T.status}`},delta:!0,deleted:!1})}let L=h.get("CHANGES")?.ours,q=L?.kind==="git"&&L.bytes?tx(L.bytes.toString("utf8")).sentences:[],B=!!r.get(".bidsignore");if(d){let M=(ut)=>new Map([...l].map((Tt)=>[Tt,h.get(Tt)[ut]]).filter(([,Tt])=>Tt.kind!=="absent")),P=M("base"),G=M("theirs"),se=M("ours"),De=ox(e.ds,T$e(sx(H.base).bytes)),ln=ox(e.ds,T$e(sx(H.theirs).bytes)),ot=O$e(P,se,De,e.conceptDoi),lt=O$e(G,se,ln,e.conceptDoi),ae=(ut)=>[...ut].map(([Tt,Ar])=>`${Tt}=${mr(Ar)}`).sort().join(`
944
- `),Ye=ae(P)!==ae(G),re=w4(Ye,ot!==null||lt!==null),st=re==="keep-ours"||re==="take-theirs"&&lt!==null,Ge=st?null:EOt(G,ln,e.conceptDoi,e.collect),J=st||Ge!==null&&SOt(Ge,se),Y=(ut)=>ut.size>0?[...ut.values()][0]:Wy,de=re==="conflict"?y4(Y(P),Y(G),Y(se)):re==="correction"?b4(Y(P),Y(se)):null,ye=new Set([...l,...Ge?Ge.keys():[]]);for(let ut of[...ye].sort()){let Tt=h.get(ut)??{base:Wy,theirs:Wy,ours:Wy},Ar=J?{kind:"ours"}:Ge?.get(ut)??{kind:"absent"},Is=Ar.kind!=="ours"&&Ar.kind!=="absent"&&!PC(Ar,Tt.ours),Ie=Ar.kind==="absent"&&Tt.ours.kind!=="absent";if(mr(Tt.base)===mr(Tt.theirs)&&mr(Tt.theirs)===mr(Tt.ours)&&!Is&&!Ie)continue;I.push({path:ut,group:"readme",base:mr(Tt.base),theirs:mr(Tt.theirs),ours:mr(Tt.ours),upstreamChanged:Ye,explainedBy:{base:ot,theirs:lt},class:re,subtype:de,decision:J?"ours":"theirs",target:Ar,delta:Is,deleted:Ie})}}for(let M of c){if(M===Fn||l.has(M))continue;let P=h.get(M),G=u4(M,P.base,P.ours,E),se=u4(M,P.theirs,P.ours,A),De=G==="participants-generated"||se==="participants-generated",ot=De&&P.base.kind==="absent"&&P.theirs.kind==="absent"?!kOt(S.base,S.theirs):mr(P.base)!==mr(P.theirs),lt=G!==null||se!==null,ae=[P.base,P.theirs,P.ours].some((de)=>de.kind==="git"&&b.has(de.oid)),Ye=e.pipelineOwned?.has(M)??!1,Pe=Ye?"pipeline-owned":!lt&&ae?"unchecked":w4(ot,lt),re=!Ye&&(Pe==="keep-ours"||Pe==="take-theirs"&&se!==null),st=re?{kind:"ours"}:k$e(M,P.theirs,{sentences:q,oursHasBidsignore:B,generatedParticipants:De?S.theirs:null,collect:e.collect}),Ge=st.kind!=="ours"&&PC(st,P.ours),J=st.kind!=="ours"&&st.kind!=="absent"&&!Ge,Y=st.kind==="absent"&&P.ours.kind!=="absent";I.push({path:M,group:null,base:mr(P.base),theirs:mr(P.theirs),ours:mr(P.ours),upstreamChanged:ot,explainedBy:Ye?{base:"pipeline-owned",theirs:"pipeline-owned"}:{base:G,theirs:se},class:Pe,subtype:Pe==="pipeline-owned"?P.theirs.kind==="absent"?"regenerated":"upstream-wins":Pe==="conflict"?y4(P.base,P.theirs,P.ours):Pe==="correction"?b4(P.base,P.ours):Pe==="unchecked"?"fetch-bound":null,decision:re||Ge?"ours":"theirs",target:Ge?{kind:"ours"}:st,delta:J,deleted:Y})}return I.sort((M,P)=>M.path<P.path?-1:M.path>P.path?1:0),{decisions:I,description:T,gitlinks:a,oursKeys:m,sides:h,fetchRefused:b.size,changesSentences:q}}function kOt(e,t){return e===null||t===null?e===t:e.equals(t)}function sx(e){if(e.kind==="absent")return{present:!1,bytes:null};return{present:!0,bytes:e.kind==="git"?e.bytes:null}}var os=".nemar/ieeg-geometry.json",x4="0.1.0",ROt=/_(?:electrodes\.tsv|coordsystem\.json)$/;function Yy(e){if(e.length===0||e.startsWith("/")||/[\\\0]/.test(e))return!1;let t=e.split("/");if(t.some((n)=>n===""||n==="."||n===".."))return!1;return t[0].startsWith("sub-")&&ROt.test(t.at(-1))}var $Ot=/_space-[A-Za-z0-9]+_(?:electrodes\.tsv|coordsystem\.json)$/;function M$e(e,t,n){if(!Yy(e)||t(e))return!1;if($Ot.test(e))return!0;return e.endsWith("_coordsystem.json")&&n(`${e.slice(0,-17)}_electrodes.tsv`)}function v4(e){if(e===null)return{status:"absent",paths:[],ignored:0,hashes:new Map};let t;try{t=JSON.parse(xo(e.toString("utf8")))}catch{return{status:"unreadable",paths:[],ignored:0,hashes:new Map}}let n=t,r=n?.paths;if(!n||typeof n!=="object"||n.schema!==1||!r||typeof r!=="object"||Array.isArray(r))return{status:"unreadable",paths:[],ignored:0,hashes:new Map};let o=Object.keys(r),s=o.filter(Yy).sort(),i=new Map(s.map((a)=>{let c=r[a]?.output_sha256;return[a,typeof c==="string"&&/^[0-9a-f]{64}$/.test(c)?c:null]}));return{status:"ok",paths:s,ignored:o.length-s.length,hashes:i}}function j$e(e,t){if(t.size===0)return e;let n=JSON.parse(xo(e.toString("utf8"))),r={};for(let o of Object.keys(n.paths).sort())if(!t.has(o))r[o]=n.paths[o];return Buffer.from(`${JSON.stringify(_4({...n,paths:r}),null,2)}
944
+ `),Ye=ae(P)!==ae(G),re=w4(Ye,ot!==null||lt!==null),st=re==="keep-ours"||re==="take-theirs"&&lt!==null,Ge=st?null:EOt(G,ln,e.conceptDoi,e.collect),J=st||Ge!==null&&SOt(Ge,se),Y=(ut)=>ut.size>0?[...ut.values()][0]:Wy,de=re==="conflict"?y4(Y(P),Y(G),Y(se)):re==="correction"?b4(Y(P),Y(se)):null,ye=new Set([...l,...Ge?Ge.keys():[]]);for(let ut of[...ye].sort()){let Tt=h.get(ut)??{base:Wy,theirs:Wy,ours:Wy},Ar=J?{kind:"ours"}:Ge?.get(ut)??{kind:"absent"},Is=Ar.kind!=="ours"&&Ar.kind!=="absent"&&!PC(Ar,Tt.ours),Ie=Ar.kind==="absent"&&Tt.ours.kind!=="absent";if(mr(Tt.base)===mr(Tt.theirs)&&mr(Tt.theirs)===mr(Tt.ours)&&!Is&&!Ie)continue;I.push({path:ut,group:"readme",base:mr(Tt.base),theirs:mr(Tt.theirs),ours:mr(Tt.ours),upstreamChanged:Ye,explainedBy:{base:ot,theirs:lt},class:re,subtype:de,decision:J?"ours":"theirs",target:Ar,delta:Is,deleted:Ie})}}for(let M of c){if(M===Fn||l.has(M))continue;let P=h.get(M),G=u4(M,P.base,P.ours,E),se=u4(M,P.theirs,P.ours,A),De=G==="participants-generated"||se==="participants-generated",ot=De&&P.base.kind==="absent"&&P.theirs.kind==="absent"?!kOt(S.base,S.theirs):mr(P.base)!==mr(P.theirs),lt=G!==null||se!==null,ae=[P.base,P.theirs,P.ours].some((de)=>de.kind==="git"&&b.has(de.oid)),Ye=e.pipelineOwned?.has(M)??!1,Pe=Ye?"pipeline-owned":!lt&&ae?"unchecked":w4(ot,lt),re=!Ye&&(Pe==="keep-ours"||Pe==="take-theirs"&&se!==null),st=re?{kind:"ours"}:k$e(M,P.theirs,{sentences:q,oursHasBidsignore:B,generatedParticipants:De?S.theirs:null,collect:e.collect}),Ge=st.kind!=="ours"&&PC(st,P.ours),J=st.kind!=="ours"&&st.kind!=="absent"&&!Ge,Y=st.kind==="absent"&&P.ours.kind!=="absent";I.push({path:M,group:null,base:mr(P.base),theirs:mr(P.theirs),ours:mr(P.ours),upstreamChanged:ot,explainedBy:Ye?{base:"pipeline-owned",theirs:"pipeline-owned"}:{base:G,theirs:se},class:Pe,subtype:Pe==="pipeline-owned"?P.theirs.kind==="absent"?"regenerated":"upstream-wins":Pe==="conflict"?y4(P.base,P.theirs,P.ours):Pe==="correction"?b4(P.base,P.ours):Pe==="unchecked"?"fetch-bound":null,decision:re||Ge?"ours":"theirs",target:Ge?{kind:"ours"}:st,delta:J,deleted:Y})}return I.sort((M,P)=>M.path<P.path?-1:M.path>P.path?1:0),{decisions:I,description:T,gitlinks:a,oursKeys:m,sides:h,fetchRefused:b.size,changesSentences:q}}function kOt(e,t){return e===null||t===null?e===t:e.equals(t)}function sx(e){if(e.kind==="absent")return{present:!1,bytes:null};return{present:!0,bytes:e.kind==="git"?e.bytes:null}}var os=".nemar/ieeg-geometry.json",x4="0.1.1",ROt=/_(?:electrodes\.tsv|coordsystem\.json)$/;function Yy(e){if(e.length===0||e.startsWith("/")||/[\\\0]/.test(e))return!1;let t=e.split("/");if(t.some((n)=>n===""||n==="."||n===".."))return!1;return t[0].startsWith("sub-")&&ROt.test(t.at(-1))}var $Ot=/_space-[A-Za-z0-9]+_(?:electrodes\.tsv|coordsystem\.json)$/;function M$e(e,t,n){if(!Yy(e)||t(e))return!1;if($Ot.test(e))return!0;return e.endsWith("_coordsystem.json")&&n(`${e.slice(0,-17)}_electrodes.tsv`)}function v4(e){if(e===null)return{status:"absent",paths:[],ignored:0,hashes:new Map};let t;try{t=JSON.parse(xo(e.toString("utf8")))}catch{return{status:"unreadable",paths:[],ignored:0,hashes:new Map}}let n=t,r=n?.paths;if(!n||typeof n!=="object"||n.schema!==1||!r||typeof r!=="object"||Array.isArray(r))return{status:"unreadable",paths:[],ignored:0,hashes:new Map};let o=Object.keys(r),s=o.filter(Yy).sort(),i=new Map(s.map((a)=>{let c=r[a]?.output_sha256;return[a,typeof c==="string"&&/^[0-9a-f]{64}$/.test(c)?c:null]}));return{status:"ok",paths:s,ignored:o.length-s.length,hashes:i}}function j$e(e,t){if(t.size===0)return e;let n=JSON.parse(xo(e.toString("utf8"))),r={};for(let o of Object.keys(n.paths).sort())if(!t.has(o))r[o]=n.paths[o];return Buffer.from(`${JSON.stringify(_4({...n,paths:r}),null,2)}
945
945
  `,"utf8")}function _4(e){if(Array.isArray(e))return e.map(_4);if(e&&typeof e==="object")return Object.fromEntries(Object.keys(e).sort().map((t)=>[t,_4(e[t])]));return e}ta();Vp();Ty();Vp();var ax=["current","stale_ready","mirror_lag","stale_unverified","anomaly","unknown","not_examined","unpublished","in_progress","parked","unchecked"],om=["stale_ready","mirror_lag","stale_unverified"],DOt=["source_id_mismatch","upstream_deleted","upstream_absent","upstream_no_snapshot","upstream_tag_unparsable","recorded_tag_not_upstream","upstream_older","upstream_dates_unreadable","upstream_latest_inconsistent"];function ix(e){if(e===null||e===void 0)return Number.NaN;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(e);return Date.parse(t?`${e.replace(" ","T")}Z`:e)}function L$e(e,t){return e.find((n)=>n.tag===t)}function U$e(e,t,n){let r=L$e(t,e.tag)?.created??null,o=[e.created,r].find((d)=>d!==null&&!Number.isNaN(ix(d)));if(o===void 0)return{kind:"latest_undated"};let s=ix(o),i=t.find((d)=>ix(d.created)>s);if(i)return{kind:"latest_inconsistent",later:i.tag};if(e.tag===n)return{kind:"same"};let a=L$e(t,n);if(!a)return{kind:"recorded_absent"};let c=ix(a.created);if(Number.isNaN(c))return{kind:"recorded_undated"};let l=t.find((d)=>d.tag!==e.tag&&Number.isNaN(ix(d.created)));if(l)return{kind:"list_undated",undated:l.tag};if(s<=c)return{kind:"not_after"};return{kind:"newer",latestCreated:o}}function FC(e){let t=Object.fromEntries(ax.map((s)=>[s,0])),n=Object.fromEntries(DOt.map((s)=>[s,0])),r=0;for(let s of e){if(t[s.state]++,s.anomaly!==null)n[s.anomaly]++;if(s.probably_stale===!0)r++}let o=om.reduce((s,i)=>s+t[i],0);return{states:t,anomalies:n,stale:o,probably_stale:r}}function B$e(e,t){let n=new Map;for(let m of e)if(!m.directory)n.set(m.filename,m);let r=new Map;for(let m of t)if(!m.directory)r.set(m.filename,m);let o=0,s=0,i=0,a=0,c=0,l=0;for(let[m,h]of r){let g=n.get(m);if(g===void 0){if(o++,h.annexed)a++}else if(g.id!==h.id){if(s++,h.annexed||g.annexed)c++}}for(let[m,h]of n)if(!r.has(m)){if(i++,h.annexed)l++}let d=new Set;for(let m of n.values())d.add(m.id);let f=new Map;for(let m of r.values())if(m.annexed&&!d.has(m.id)&&!f.has(m.id))f.set(m.id,m);let p=0;for(let[m,h]of f){let g=hSe(m)??h.size;if(g===null){p=null;break}p+=g}return{added:o,changed:s,deleted:i,annexed_added:a,annexed_changed:c,annexed_deleted:l,data_changing:a+c+l>0,new_keys:f.size,bytes_to_copy:p}}var q$e=86400000;function COt(e){return e===null?Number.NaN:Date.parse(e)}var AOt=["current",...om];function H$e(e,t,n={}){let r=n.windowDays??365,o=(n.minGapDays??30)*q$e,s=t-r*q$e,i=Object.fromEntries(ax.map((h)=>[h,0])),a=0,c=0,l=0,d=0,f=0,p=0,m=new Map;for(let h of e){if(!AOt.includes(h.state)||h.upstream===null){i[h.state]++;continue}if(a++,om.includes(h.state))c++;let g=h.upstream.snapshots.map((S)=>COt(S.created)),y=g.filter((S)=>!Number.isNaN(S)).sort((S,E)=>S-E),b=g.length-y.length;f+=b;let x=b===0?y.slice(1):y,v=Number.NEGATIVE_INFINITY;for(let S of x){if(S>t){p++;continue}if(S<=s)continue;l++;let E=new Date(S).toISOString().slice(0,10);if(m.set(E,(m.get(E)??0)+1),S-v>=o)d++,v=S}}return{window_days:r,mirrors_counted:a,excluded:i,catch_up:c,per_snapshot:l,at_most_every_30_days:d,busiest_day:Math.max(0,...m.values()),upper_bound_with_patches:{catch_up:c*2,per_snapshot:l*2,at_most_every_30_days:d*2},snapshots_with_unreadable_dates:f,snapshots_dated_in_the_future:p}}uf();iC();Lc();import{readFileSync as MOt,readdirSync as jOt,statSync as LOt}from"fs";import{isAbsolute as qOt,join as E4}from"path";var OOt={clone:{flags:["--bare","--quiet","--filter=blob:limit=1m","--depth=1","--no-tags"],valued:["--branch"],url:!0},fetch:{flags:["--quiet","--depth=1","--no-tags","--no-write-fetch-head","--recurse-submodules=no","--filter=blob:none","--stdin"],remote:"origin"},"ls-remote":{flags:["--refs"],url:!0},"cat-file":{flags:["--batch"]},"ls-tree":{flags:["-r","-z","--full-tree"],endOfOptions:!0},"rev-parse":{flags:["--verify","--quiet","--show-object-format"]},"rev-list":{flags:["--objects","--missing=print","--no-object-names"]}},TOt=new Set(["fetch.negotiationAlgorithm=noop"]),POt=/^(?:https:\/\/github\.com\/[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+|file:\/\/\/\S+)$/;class wa extends Error{constructor(e){super(`refused by the re-pull planner's read-only guard: ${e}`);this.name="ReadOnlyViolation"}}function IOt(e){let t=0;while(e[t]?.startsWith("-")){if(e[t]!=="-c"||!TOt.has(e[t+1]??""))throw new wa(`git ${e[t]} ${e[t+1]??""}`.trim());t+=2}let n=e[t],r=n===void 0?void 0:OOt[n];if(n===void 0||!r)throw new wa(`git ${n??"(nothing)"}`);let o=[],s=!1;for(let a=t+1;a<e.length;a++){let c=e[a];if(s){o.push(c);continue}if(c==="--"&&r.endOfOptions){s=!0;continue}if(r.flags.includes(c))continue;if(r.valued?.includes(c)){let l=e[a+1];if(l===void 0||l.startsWith("-"))throw new wa(`git ${n} ${c} without a value`);a++;continue}if(c.startsWith("-"))throw new wa(`git ${n} ${c}`);o.push(c)}let i=o[0];if(r.url&&(i===void 0||!POt.test(i)))throw new wa(`git ${n} of a URL that is not GitHub or a local path`);if(r.remote!==void 0&&i!==r.remote)throw new wa(`git ${n} from a remote other than ${r.remote}`)}var MC=new Set;function G$e(){for(let e of MC)try{e.kill("SIGKILL")}catch{}MC.clear()}async function ss(e,t={}){IOt(e);let n=typeof t.stdin==="string"?new TextEncoder().encode(t.stdin):t.stdin,r={...process.env,GIT_TERMINAL_PROMPT:"0",LC_ALL:"C",GIT_NO_LAZY_FETCH:"1",...t.env},o=Bun.spawn(["git",...t.cwd?["-C",t.cwd]:[],...e],{...n===void 0?{}:{stdin:n},stdout:"pipe",stderr:"pipe",env:r});MC.add(o);try{let[s,i,a]=await Promise.all([new Response(o.stdout).arrayBuffer(),new Response(o.stderr).text(),o.exited]);return{stdout:Buffer.from(s),stderr:i,exitCode:a}}finally{MC.delete(o)}}function jC(e){return(t,n,r)=>ss(n,{cwd:t,env:e,stdin:r})}async function LC(e,t={}){let n=await ss(e,t);if(n.exitCode!==0)throw Error(`git ${e[0]} failed: ${n.stderr.trim().split(`
946
946
  `)[0]||`exit ${n.exitCode}`}`);return n.stdout.toString("utf8")}var NOt=new Set(["--bucket","--prefix","--region","--output"]);function FOt(e){if(e[0]!=="s3api"||e[1]!=="list-objects-v2")throw new wa(`aws ${e.slice(0,2).join(" ")}`);for(let t=2;t<e.length;t+=2){let n=e[t],r=e[t+1];if(!NOt.has(n)||r===void 0||r.startsWith("-"))throw new wa(`aws s3api list-objects-v2 ${n}`);if(n==="--output"&&r!=="json")throw new wa(`aws s3api list-objects-v2 --output ${r}`)}}async function z$e(e,t={}){FOt(e);let n=Bun.spawn(["aws",...e],{stdout:"pipe",stderr:"pipe",env:{...process.env,AWS_PAGER:"",...t}}),[r,o,s]=await Promise.all([new Response(n.stdout).arrayBuffer(),new Response(n.stderr).text(),n.exited]);return{stdout:Buffer.from(r),stderr:o,exitCode:s}}async function qC(e,t={}){let n=(t.method??"GET").toUpperCase();if(n!=="GET"&&n!=="HEAD")throw new wa(`HTTP ${n}`);return fetch(e,{...t,method:n})}ta();wo();function V$e(e){return typeof e==="string"&&/^ds\d{6}$/.test(e)}function W$e(e){return typeof e==="string"&&/^[a-z]{2}\d{6}$/.test(e)}function UC(e){return typeof e==="string"&&k_.test(e)}function BC(e){return typeof e==="string"&&Ry.test(e)}function HC(e){return typeof e==="string"&&e.length<=32&&/^[a-z]{2}(-[a-z]+)+-\d+$/.test(e)}function GC(e){if(typeof e!=="string"||e.length<3||e.length>63)return!1;if(!/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/.test(e))return!1;return!e.includes("..")&&!/^\d+\.\d+\.\d+\.\d+$/.test(e)}function K$e(e,t){if(e!==void 0&&!GC(e))return"NEMAR's remote.log names a nemar-s3 bucket that is not an S3 bucket name (3 to 63 lowercase letters, digits, dots and hyphens), so it is not used.";if(!HC(t))return"NEMAR's remote.log names a nemar-s3 datacenter that is not an AWS region name (like us-east-2), so it is not used.";return null}var Xy="nemarDatasets",UOt="OpenNeuroDatasets",Y$e={origin:"NEMAR_REPULL_ORIGIN_BASE",upstream:"NEMAR_REPULL_UPSTREAM_BASE",bucket:"NEMAR_REPULL_BUCKET_BASE"};function cx(e,t){let n=Y$e[t],r=e[n]?.trim();if(!r)return null;if(!qOt(r)||/^[a-z][a-z0-9+.-]*:/i.test(r))throw Error(`${n} is set but is not an absolute local path. It is only for tests, so it is refused rather than ignored; unset it to read the real remote.`);return r.replace(/\/+$/,"")}function ru(e){let t=e.NEMAR_REPULL_OPENNEURO_URL?.trim();if(!t)return;try{let n=new URL(t);if(n.protocol==="http:"&&["127.0.0.1","localhost","[::1]"].includes(n.hostname))return t}catch{}throw Error("NEMAR_REPULL_OPENNEURO_URL is set but is not an http://127.0.0.1, http://localhost or http://[::1] address. It is only for tests, so it is refused rather than ignored.")}function zC(e,t){return BOt(e)||t!==void 0?"test-bases":"remotes"}function BOt(e){return Object.keys(Y$e).some((t)=>cx(e,t)!==null)||ru(e)!==void 0}function ji(e,t){let n=cx(t,"origin");return n?`file://${n}/${e}`:`https://github.com/${Xy}/${e}.git`}function Qy(e,t){let n=cx(t,"upstream");return n?`file://${n}/${e}`:`https://github.com/${UOt}/${e}.git`}function Zy(e,t){return Js(e,t)}async function S4(e,t,n){let r=await LC(["ls-remote","--refs",e,...t],{env:n}),o=new Map;for(let s of r.split(`
947
947
  `)){let[i,a]=s.split("\t");if(i&&a&&/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(i))o.set(a,i)}return o}var HOt="blob:limit=1m";async function k4(e){let t=Zy(e.url,e.token??null),n=await ss(["clone","--bare","--quiet",`--filter=${HOt}`,"--depth=1","--no-tags","--branch",e.branch,e.url,e.dest],{env:t});if(n.exitCode!==0)throw Error(`git clone failed: ${sm(n)}`);if(e.extra.length>0){let r=await ss(["fetch","--quiet","--depth=1","--no-tags","origin",...e.extra.map((o)=>`+${o}:${o}`)],{cwd:e.dest,env:t});if(r.exitCode!==0)throw Error(`git fetch failed: ${sm(r)}`)}return{path:e.dest,url:e.url,env:t}}function sm(e){return e.stderr.trim().split(`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nemar-cli",
3
3
  "packageManager": "bun@1.4.3",
4
- "version": "0.10.37-dev.4640",
4
+ "version": "0.10.37-dev.4659",
5
5
  "description": "CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",