nemar-cli 0.8.73-PR876.33fe2cd → 0.8.73-PR876.449f6ec
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 +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ ${W.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
|
|
|
95
95
|
${$} ${D.message}
|
|
96
96
|
${J}${Q}
|
|
97
97
|
${F}
|
|
98
|
-
`)}var df=!1;var vW=S(()=>{ND()});var nf;var cf=S(()=>{nf={name:"nemar-cli",version:"0.8.73-PR876.33fe2cd",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.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:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",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","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var _4;var DQ=S(()=>{cf();_4=nf.version});function L0(D){if(D instanceof Error)return D.message;return String(D)}function af(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(xW)return yW;return $D().apiUrl||yW}async function x(D,F={},$=!1){let J=`${af()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=$D();if(!X.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new f(0,`Network error: Could not connect to ${af()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new f(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new TF(B.mode,X,G,B.details);throw eJ(H),H}throw new f(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function sf(D){return x(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function rf(D){return x(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function tf(D){return x("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function _W(D){return x("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function ef(D){return x("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Dg(D,F){return x("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Fg(D){return x("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function $Q(){return x("/users/me",{},!0)}async function $g(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return x(`/admin/users${J}`,{},!0)}async function Jg(D){return x(`/admin/approve/${D}`,{method:"POST"},!0)}async function Qg(D){return x(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Yg(D,F){return x(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function fW(D,F){return x(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Bg(D){return x(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Xg(D){return x(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return x(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function gW(D){return x(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function hW(D){return x(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function JQ(D){return x(`/datasets/${D}/ci/status`,{},!0)}async function Gg(D){return x(`/datasets/${D}/manifest`,{},!0)}async function QQ(D,F){return x(`/datasets/${D}/manifest/${F}`,{},!0)}function Wg(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function PF(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.license)F.set("license",D.license);if(D.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await x(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Wg),J}async function Hg(D){return x(`/datasets/resolve/${D}`,{},"optional")}async function qg(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return x(`/datasets/search?${$.toString()}`,{},"optional")}async function gD(D){let F=await x(`/datasets/${D}`,{},"optional");return Wg(F.dataset)}async function Kg(D){return x(`/datasets/${D}/versions`,{},!0)}async function YQ(D){return x("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function BQ(D){return x(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function c8(D,F){return x(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function bW(D,F){return x(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function zg(D,F){return x(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function y9(D){return x(`/admin/datasets/${D}/doi`,{},!0)}async function uW(D,F){return x(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function mW(D){return x(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function Eg(D,F){let $=F?`?status=${F}`:"";return x(`/datasets/${D}/access-requests${$}`,{},!0)}async function Vg(D,F){return x(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Zg(D,F){return x(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Ug(D,F){return x(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Lg(D){return x(`/datasets/${D}/collaborators`,{},!0)}async function Ag(D){return x("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function Mg(){return x("/sandbox/reset",{method:"POST"},!0)}async function Ng(){return x("/sandbox/status",{},!0)}async function XQ(D){return x(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Rg(D){return x(`/datasets/${D}/publish/status`,{},!0)}async function Cg(D){return x(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Og(D){let F=D?`?status=${D}`:"";return x(`/admin/publish/requests${F}`,{},!0)}async function jg(D,F){return x(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function WV0(D,F=[]){if(D){let $=v9.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,v9.length)}function HV0(D){if(!(D instanceof f))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function GQ(D,F=!1,$=!1,J=!1,Q,Y){let G,H,q=0,K=!1,V,z=F,Z=[],U;function M(A,C,j,I){if(!Y)return;Y({step:A,stepIndex:WV0(A,C),stepTotal:v9.length,s3LockLocked:j,s3LockTotal:I,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let C,j=!0;do{if(C=await x(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:j?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:H,skip_ci_check:J})},!0),j=!1,C.step_results)Z.push(...C.step_results);if(C.s3_lock_total!==void 0)H=C.s3_lock_total;if(C.s3_lock_batch_count!==void 0)q+=C.s3_lock_batch_count;let I=C.step??C.step_results?.[C.step_results.length-1]?.step;if(I&&(I!==V||I==="s3_lock"))M(I,C.steps_completed??[],I==="s3_lock"?q:void 0,I==="s3_lock"?H:void 0),V=I;if(C.hasMore&&C.s3_lock_continuation_token!==void 0)G=C.s3_lock_continuation_token;else break}while(C.hasMore);if(Z.length>0)C.step_results=of(Z);return C}catch(C){if(U=C,A===5||!HV0(C)){if(C instanceof f&&Z.length>0)C.stepResults=of(Z);throw C}let I=C;if(Q?.({attempt:A,maxAttempts:5,delayMs:1e4,step:I.step,error:I.message}),await new Promise((R)=>setTimeout(R,1e4)),z=!0,G!==void 0)K=!0}throw U}function of(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function wg(D,F){return x(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function Tg(D){return x(`/admin/datasets/${D}/files`,{},!0)}async function Pg(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await x(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function Ig(D){return x(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function Sg(D,F=!1){return x(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function kg(D){return x("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function vg(D){return x("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function yg(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return x(`/admin/imports${F}`,{},!0)}async function xg(D){return x(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function _g(D){return x(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function WQ(D,F){return x(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function fg(D,F){return x("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function gg(D){let F=D?.limit??15;return x(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function hg(){return x("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function bg(D){let F=new URLSearchParams;if(D?.prefix)F.set("prefix",D.prefix);if(D?.visibility)F.set("visibility",D.visibility);if(D?.limit)F.set("limit",String(D.limit));let $=F.toString()?`?${F.toString()}`:"";return x(`/admin/fleet/drift${$}`,{},!0)}async function IF(D,F){return x(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function ug(D){return x("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:D.prefix,visibility:D.visibility,limit:D.limit,dry_run:D.dryRun})},!0)}async function mg(D,F=!1){return x(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function lg(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return x(`/admin/email-preferences${F}`,{},!0)}async function pg(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return x(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function dg(){return x("/notices",{},"optional")}async function cg(){return x("/admin/notices",{},!0)}async function ng(D){return x("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function ig(D){return x(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function lW(D){return x("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ag(){return x("/admin/summary/coverage",{},!0)}async function og(D,F,$){return x("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var yW="https://api.nemar.org",FQ,f,TF,xW,v9;var n8=S(()=>{x4();vW();DQ();FQ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;f=class f extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};TF=class TF extends f{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};xW=yW.includes("workers.dev");v9=["ci_check","enrichment_check","repo_public","s3_public_read","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});function tg(D){dW=D}function cW(){return dW}function x9(D){if(dW)process.stderr.write(`${D}
|
|
98
|
+
`)}var df=!1;var vW=S(()=>{ND()});var nf;var cf=S(()=>{nf={name:"nemar-cli",version:"0.8.73-PR876.449f6ec",description:"CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",type:"module",main:"dist/index.js",bin:{nemar:"dist/index.js"},scripts:{dev:"bun run src/index.ts",build:"bun build src/index.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:fix":"biome check --fix src/",format:"biome format --write src/",typecheck:"tsc --noEmit",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","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var _4;var DQ=S(()=>{cf();_4=nf.version});function L0(D){if(D instanceof Error)return D.message;return String(D)}function af(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(xW)return yW;return $D().apiUrl||yW}async function x(D,F={},$=!1){let J=`${af()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=$D();if(!X.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new f(0,`Network error: Could not connect to ${af()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new f(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new TF(B.mode,X,G,B.details);throw eJ(H),H}throw new f(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function sf(D){return x(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function rf(D){return x(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function tf(D){return x("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function _W(D){return x("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function ef(D){return x("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Dg(D,F){return x("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Fg(D){return x("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function $Q(){return x("/users/me",{},!0)}async function $g(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return x(`/admin/users${J}`,{},!0)}async function Jg(D){return x(`/admin/approve/${D}`,{method:"POST"},!0)}async function Qg(D){return x(`/admin/revoke/${D}`,{method:"POST"},!0)}async function Yg(D,F){return x(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function fW(D,F){return x(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Bg(D){return x(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Xg(D){return x(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return x(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function gW(D){return x(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function hW(D){return x(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function JQ(D){return x(`/datasets/${D}/ci/status`,{},!0)}async function Gg(D){return x(`/datasets/${D}/manifest`,{},!0)}async function QQ(D,F){return x(`/datasets/${D}/manifest/${F}`,{},!0)}function Wg(D){let F=D;if(!F.status)F.status="active";else if(!["active","archived","deleted"].includes(F.status))throw Error(`Invalid dataset status: ${F.status}`);if(!F.visibility)F.visibility="private";else if(!["public","private"].includes(F.visibility))throw Error(`Invalid dataset visibility: ${F.visibility}`);return F}async function PF(D={}){let F=new URLSearchParams;if(D.mine)F.set("mine","true");if(D.search)F.set("search",D.search);if(D.modality)F.set("modality",D.modality);if(D.author)F.set("author",D.author);if(D.task)F.set("task",D.task);if(D.license)F.set("license",D.license);if(D.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await x(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(Wg),J}async function Hg(D){return x(`/datasets/resolve/${D}`,{},"optional")}async function qg(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return x(`/datasets/search?${$.toString()}`,{},"optional")}async function gD(D){let F=await x(`/datasets/${D}`,{},"optional");return Wg(F.dataset)}async function Kg(D){return x(`/datasets/${D}/versions`,{},!0)}async function YQ(D){return x("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function BQ(D){return x(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function c8(D,F){return x(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function bW(D,F){return x(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function zg(D,F){return x(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function y9(D){return x(`/admin/datasets/${D}/doi`,{},!0)}async function uW(D,F){return x(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function mW(D){return x(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function Eg(D,F){let $=F?`?status=${F}`:"";return x(`/datasets/${D}/access-requests${$}`,{},!0)}async function Vg(D,F){return x(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Zg(D,F){return x(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Ug(D,F){return x(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Lg(D){return x(`/datasets/${D}/collaborators`,{},!0)}async function Ag(D){return x("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function Mg(){return x("/sandbox/reset",{method:"POST"},!0)}async function Ng(){return x("/sandbox/status",{},!0)}async function XQ(D){return x(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Rg(D){return x(`/datasets/${D}/publish/status`,{},!0)}async function Cg(D){return x(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Og(D){let F=D?`?status=${D}`:"";return x(`/admin/publish/requests${F}`,{},!0)}async function jg(D,F){return x(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function WV0(D,F=[]){if(D){let $=v9.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,v9.length)}function HV0(D){if(!(D instanceof f))return!1;if(D.statusCode===0)return!0;if(D.statusCode===429)return!0;if(D.statusCode>=500&&D.statusCode<600)return!0;if(D.statusCode===403&&/repository has been locked/i.test(D.message))return!0;return!1}async function GQ(D,F=!1,$=!1,J=!1,Q,Y){let G,H,q=0,K=!1,V,z=F,Z=[],U;function M(A,C,j,I){if(!Y)return;Y({step:A,stepIndex:WV0(A,C),stepTotal:v9.length,s3LockLocked:j,s3LockTotal:I,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let C,j=!0;do{if(C=await x(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:j?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:H,skip_ci_check:J})},!0),j=!1,C.step_results)Z.push(...C.step_results);if(C.s3_lock_total!==void 0)H=C.s3_lock_total;if(C.s3_lock_batch_count!==void 0)q+=C.s3_lock_batch_count;let I=C.step??C.step_results?.[C.step_results.length-1]?.step;if(I&&(I!==V||I==="s3_lock"))M(I,C.steps_completed??[],I==="s3_lock"?q:void 0,I==="s3_lock"?H:void 0),V=I;if(C.hasMore&&C.s3_lock_continuation_token!==void 0)G=C.s3_lock_continuation_token;else break}while(C.hasMore);if(Z.length>0)C.step_results=of(Z);return C}catch(C){if(U=C,A===5||!HV0(C)){if(C instanceof f&&Z.length>0)C.stepResults=of(Z);throw C}let I=C;if(Q?.({attempt:A,maxAttempts:5,delayMs:1e4,step:I.step,error:I.message}),await new Promise((R)=>setTimeout(R,1e4)),z=!0,G!==void 0)K=!0}throw U}function of(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function wg(D,F){return x(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function Tg(D){return x(`/admin/datasets/${D}/files`,{},!0)}async function Pg(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await x(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function Ig(D){return x(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function Sg(D,F=!1){return x(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function kg(D){return x("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function vg(D){return x("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function yg(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return x(`/admin/imports${F}`,{},!0)}async function xg(D){return x(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function _g(D){return x(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function WQ(D,F){return x(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function fg(D,F){return x("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function gg(D){let F=D?.limit??15;return x(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function hg(){return x("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function bg(D){let F=new URLSearchParams;if(D?.prefix)F.set("prefix",D.prefix);if(D?.visibility)F.set("visibility",D.visibility);if(D?.limit)F.set("limit",String(D.limit));let $=F.toString()?`?${F.toString()}`:"";return x(`/admin/fleet/drift${$}`,{},!0)}async function IF(D,F){return x(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function ug(D){return x("/admin/datasets/enforce/bulk",{method:"POST",body:JSON.stringify({prefix:D.prefix,visibility:D.visibility,limit:D.limit,dry_run:D.dryRun})},!0)}async function mg(D,F=!1){return x(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function lg(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return x(`/admin/email-preferences${F}`,{},!0)}async function pg(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return x(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function dg(){return x("/notices",{},"optional")}async function cg(){return x("/admin/notices",{},!0)}async function ng(D){return x("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function ig(D){return x(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function lW(D){return x("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ag(){return x("/admin/summary/coverage",{},!0)}async function og(D,F,$){return x("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var yW="https://api.nemar.org",FQ,f,TF,xW,v9;var n8=S(()=>{x4();vW();DQ();FQ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;f=class f extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};TF=class TF extends f{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};xW=yW.includes("workers.dev");v9=["ci_check","enrichment_check","repo_public","s3_public_read","tag_protect","doi_create","update_metadata","update_readme","create_tag","create_release","upload_to_zenodo","publish_doi","version_doi","s3_lock","sync_nemar","notify_user"]});function tg(D){dW=D}function cW(){return dW}function x9(D){if(dW)process.stderr.write(`${D}
|
|
99
99
|
`)}var dW=!1;function YD(D){if(D===0)return"0 B";let F=["B","KB","MB","GB","TB"],$=Math.min(Math.floor(Math.log(D)/Math.log(1024)),F.length-1);return`${(D/1024**$).toFixed($===0?0:1)} ${F[$]}`}function eg(D){return`${YD(D)}/s`}function qV0(D){if(D<60)return`${Math.round(D)}s`;if(D<3600)return`${Math.floor(D/60)}m ${Math.round(D%60)}s`;return`${Math.floor(D/3600)}h ${Math.floor(D%3600/60)}m`}function KV0(D,F=20){let $=Math.round(D/100*F),J=F-$;return`[${"=".repeat($)}${" ".repeat(J)}]`}class HQ{filesCompleted=0;filesTotal;bytesTotal=0;inFlight=new Map;currentFile="";startTime;lastUpdateTime;lastBytesTransferred=0;totalBytesTransferred=0;speedSamples=[];lastRenderedLine="";constructor(D=0,F=0){this.filesTotal=D,this.bytesTotal=F,this.startTime=Date.now(),this.lastUpdateTime=this.startTime}inFlightBytes(){let D=0;for(let F of this.inFlight.values())D+=F.transferred;return D}processLine(D){let F=D.file??D.action?.file;if(D.ok===!0||D.success===!0){this.filesCompleted++;let $=F??this.currentFile,J=$?this.inFlight.get($):void 0,Q=J?J.total||J.transferred:0;if(this.totalBytesTransferred+=Q,$)this.inFlight.delete($);this.render();return}if(D["byte-progress"]!==void 0){let $=F??this.currentFile;if(!$)return;this.currentFile=$;let J=this.inFlight.get($)??{transferred:0,total:0};if(J.transferred=D["byte-progress"]??J.transferred,D["total-size"]!==void 0)J.total=D["total-size"];this.inFlight.set($,J);let Q=Date.now(),Y=(Q-this.lastUpdateTime)/1000;if(Y>0.5){let B=this.totalBytesTransferred+this.inFlightBytes(),G=(B-this.lastBytesTransferred)/Y;if(G>0){if(this.speedSamples.push(G),this.speedSamples.length>5)this.speedSamples.shift()}this.lastBytesTransferred=B,this.lastUpdateTime=Q}this.render()}}incrementFilesCompleted(){this.filesCompleted++}setFilesTotal(D){this.filesTotal=D}setBytesTotal(D){this.bytesTotal=D}getPercent(){let D=this.totalBytesTransferred+this.inFlightBytes();if(this.bytesTotal>0)return Math.min(100,Math.round(D/this.bytesTotal*100));if(this.filesTotal>0)return Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100));return null}getProgress(){return{filesCompleted:this.filesCompleted,filesTotal:this.filesTotal,bytesTransferred:this.totalBytesTransferred+this.inFlightBytes(),bytesTotal:this.bytesTotal,currentFile:this.currentFile||void 0}}render(){let D=this.speedSamples.length>0?this.speedSamples.reduce((B,X)=>B+X,0)/this.speedSamples.length:0,F=this.totalBytesTransferred+this.inFlightBytes(),$=0,J=!1;if(this.bytesTotal>0)$=Math.min(100,Math.round(F/this.bytesTotal*100)),J=!0;else if(this.filesTotal>0)$=Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100)),J=!0;let Q=this.filesTotal>0?`${this.filesCompleted}/${this.filesTotal} files`:`${this.filesCompleted} files`,Y;if(J)Y=`${KV0($)} ${$}% ${Q}`;else Y=Q;if(F>0){let B=this.bytesTotal>0?`${YD(F)}/${YD(this.bytesTotal)}`:YD(F);Y+=` | ${B}`}if(D>0)Y+=` | ${eg(D)}`;if(D>0){let B=0;if(this.bytesTotal>0)B=Math.max(0,this.bytesTotal-F);else for(let X of this.inFlight.values())if(X.total>X.transferred)B+=X.total-X.transferred;if(B>0){let X=B/D;if(X>0)Y+=` | ETA ${qV0(X)}`}}if(Y!==this.lastRenderedLine)process.stderr.write(`\r${W.cyan(Y)}${" ".repeat(10)}`),this.lastRenderedLine=Y}finish(D){let F=(Date.now()-this.startTime)/1000;if(process.stderr.write(`\r${" ".repeat(this.lastRenderedLine.length+15)}\r`),D>0){let $=F>0?`${eg(this.totalBytesTransferred/F)}`:"",J=[`${D} file${D!==1?"s":""} downloaded`,this.totalBytesTransferred>0?YD(this.totalBytesTransferred):"",$].filter(Boolean).join(" | ");process.stderr.write(`${W.green(J)}
|
|
100
100
|
`)}}}var nW=S(()=>{ND()});var Eh={};r6(Eh,{verifyGitHubAuth:()=>f9,toS3Credentials:()=>PD,switchBranch:()=>RV0,setKeyPresent:()=>zh,selectAnnexS3Remote:()=>JH,saveDataset:()=>a8,runCommand:()=>T,resolveUpstreamRef:()=>qH,resolveGitHubCloneAuth:()=>qh,readRemoteHeadDatasetVersion:()=>HH,readLocalDatasetVersion:()=>WH,pushToGitHub:()=>C1,pushBranch:()=>kF,markInheritedOpenNeuroRemotesIgnored:()=>$H,listDatasetVersions:()=>YH,isWorkingTreeDirty:()=>KH,isNonFastForwardPush:()=>Wh,isGitAnnexDataset:()=>R1,isDataladDataset:()=>TV0,initOrEnableSpecialRemote:()=>Gh,initDataset:()=>n6,githubTokenCredentialHelper:()=>Hh,gitMergeFastForward:()=>EH,gitFetchOrigin:()=>zH,gitAnnexAdd:()=>i6,getVersionCommit:()=>BH,getRemoteUuid:()=>UQ,getLocalDatasetInfo:()=>QH,getKeyHashDirs:()=>jV0,getKeyHashDir:()=>Kh,getDatasetStats:()=>AV0,getDatasetIdFromRemote:()=>s8,getDatasetData:()=>VQ,getCurrentBranch:()=>o8,getAnnexWhereisAll:()=>ZQ,getAnnexS3Remotes:()=>h9,formatBytes:()=>YD,extractWhereisKeyUrl:()=>aW,ensureLocalMainBranch:()=>b9,ensureGitAnnexInitialized:()=>eW,enableS3Remote:()=>h4,dropUnusedAnnexObjects:()=>VH,dropFiles:()=>FH,detectImportMarker:()=>EQ,createRevertBranch:()=>XH,createDataladDataset:()=>wV0,countPendingDownload:()=>zQ,copyToAnnexRemote:()=>C8,configureS3Remote:()=>o1,configureLargefiles:()=>g4,configureGitHubRemote:()=>i8,commitRevert:()=>GH,collectFileManifest:()=>ZH,cloneDataset:()=>Q1,clearAnnexCredentials:()=>ID,checkPrerequisites:()=>_9,checkGitHubSSH:()=>Qh,checkGitAnnexInstalled:()=>tW,checkDownloadPrerequisites:()=>SF,checkAWSCredentials:()=>ZV0,batchSetKeysPresent:()=>UH,awsCredentialEnv:()=>KQ,annexRemoteExists:()=>Xh,acceptGitHubInvitation:()=>g9,NEMAR_S3_REMOTE_NAME:()=>qQ,ANNEX_REMOTE_EXISTS_RE:()=>Bh});import{existsSync as oW,readFileSync as zV0,statSync as EV0}from"fs";import{join as sW}from"path";var{spawn:rW}=globalThis.Bun;async function T(D,F={}){let $={...process.env,GIT_TERMINAL_PROMPT:"0",...F.env};for(let H of F.unsetEnv??[])delete $[H];let J=rW({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:$}),Q=!1,Y;if(F.timeout)Y=setTimeout(()=>{Q=!0,J.kill()},F.timeout);if(cW()){let H=F.cwd?` (cwd=${F.cwd})`:"";x9(W.dim(`$ ${D.join(" ")}${H}`))}let B=await new Response(J.stdout).text(),X=await new Response(J.stderr).text(),G=await J.exited;if(Y)clearTimeout(Y);if(cW()){if(B.trim())x9(W.dim(B.trimEnd()));if(X.trim())x9(W.yellow(X.trimEnd()));x9(W.dim(`(exit ${G})`))}if(Q)return{stdout:B,stderr:X||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:G??1};return{stdout:B,stderr:X,exitCode:G}}function Dh(D){return D.split(".").map((F)=>{let $=Number.parseInt(F.replace(/[^0-9]/g,""),10);return Number.isNaN($)?0:$})}function VV0(D,F){let $=Dh(D),J=Dh(F);for(let Q=0;Q<Math.max($.length,J.length);Q++){let Y=$[Q]||0,B=J[Q]||0;if(Y>B)return!0;if(Y<B)return!1}return!0}async function tW(){try{let{stdout:F,exitCode:$,stderr:J}=await T(["git-annex","version"]);if($!==0)return console.warn("git-annex version returned non-zero exit code:",$),console.warn("stderr:",J),{installed:!1,minVersion:"10.0",error:`Version check failed: ${J.trim()}`};let Q=F.match(/version:\s*(\d+\.\d+)/),Y=Q?Q[1]:void 0;if(!Y)console.warn("Could not parse git-annex version from output:",F);return{installed:!0,version:Y,minVersion:"10.0",compatible:Y?VV0(Y,"10.0"):void 0}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return console.info("git-annex not found in PATH"),{installed:!1,minVersion:"10.0"};return console.error("Error checking git-annex installation:",$),{installed:!1,minVersion:"10.0",error:$}}}async function Qh(){if(process.env.GH_TOKEN)return{accessible:!0,username:"token-auth",useHttps:!0};try{let{stdout:D,stderr:F}=await T(["ssh","-T","-o","BatchMode=yes","-o","StrictHostKeyChecking=accept-new","-o","ConnectTimeout=10","git@github.com"]),$=D+F,J=$.match(/Hi ([^!]+)!/);if(J)return{accessible:!0,username:J[1]};if($.includes("Permission denied"))return{accessible:!1};return{accessible:$.includes("successfully authenticated")}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("SSH command not found");else console.error("Error checking GitHub SSH access:",F);return{accessible:!1}}}async function ZV0(){if(process.env.AWS_ACCESS_KEY_ID&&process.env.AWS_SECRET_ACCESS_KEY)return{configured:!0,source:"environment"};try{let{stdout:D,exitCode:F}=await T(["aws","configure","get","aws_access_key_id"]);if(F===0&&D.trim())return{configured:!0,source:"aws-cli"}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("AWS CLI not found in PATH");else console.error("Error checking AWS credentials:",F)}return{configured:!1}}function Yh(){let D=process.platform;if(D==="darwin")return"brew install git-annex";if(D==="linux")return"apt install git-annex (Debian/Ubuntu)";return"See https://git-annex.branchable.com/install/"}async function _9(){let[D,F]=await Promise.all([tW(),Qh()]),$=[];if(!D.installed)$.push(`git-annex is not installed. Install: ${Yh()}`);else if(D.compatible===!1)$.push(`git-annex version ${D.version} is too old. Required: >= ${D.minVersion}`);if(!F.accessible){if(!(await DH()).token)$.push("GitHub authentication not configured. Run 'gh auth login' to authenticate.")}return{gitAnnex:D,githubSSH:F,allPassed:$.length===0,errors:$}}async function R1(D){if(!oW(sW(D,".git")))return!1;try{let{exitCode:F}=await T(["git","annex","info"],{cwd:D});return F===0}catch(F){let $=F instanceof Error?F.message:String(F);if(!$.includes("ENOENT")&&!$.includes("not found"))console.error(`Error checking if ${D} is a git-annex dataset:`,$);return!1}}async function n6(D,F={}){if(!F.force&&await R1(D))return{success:!0};try{let $={};if(F.author)$.GIT_AUTHOR_NAME=F.author.name,$.GIT_AUTHOR_EMAIL=F.author.email,$.GIT_COMMITTER_NAME=F.author.name,$.GIT_COMMITTER_EMAIL=F.author.email;let{stderr:J,exitCode:Q}=await T(["git","init","-b","main",D],{...Object.keys($).length>0?{env:$}:{}});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git repository"};let Y=Object.keys($).length>0?{env:$}:{},{stderr:B,exitCode:X}=await T(["git","annex","init"],{cwd:D,...Y});if(X!==0)return{success:!1,error:B.trim()||"Failed to initialize git-annex"};let{stderr:G,exitCode:H}=await T(["git","commit","--allow-empty","-m","Initialize dataset"],{cwd:D,...Y});if(H!==0)return{success:!1,error:G.trim()||"Failed to create initial commit"};let{stderr:q,exitCode:K}=await T(["git","annex","adjust","--unlock"],{cwd:D,...Y});if(K!==0)return{success:!1,error:q.trim()||"Failed to switch to unlocked mode"};return{success:!0}}catch($){return{success:!1,error:$.message}}}async function eW(D){try{let{exitCode:F,stderr:$}=await T(["git","annex","info"],{cwd:D});if(F===0)return{success:!0};if($.includes("First run: git-annex init")){let{stderr:J,exitCode:Q}=await T(["git","annex","init"],{cwd:D});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git-annex"};return{success:!0}}return{success:!1,error:$.trim()||"Failed to check git-annex status"}}catch(F){return{success:!1,error:F.message}}}async function g4(D,F){let $=["*.edf","*.bdf","*.set","*.fif","*.vhdr","*.eeg","*.cnt","*.fdt"],J=["*.tsv","*.json","*.md","*.txt","*.yml","*.yaml","README*","LICENSE*","CHANGES*",".bidsignore",".gitignore"],Q=$.map((G)=>`include=${G}`).join(" or "),Y=J.map((G)=>`exclude=${G}`).join(" and "),B=`(${Q} or largerthan=100kb) and ${Y}`,X=F||B;try{let{stderr:G,exitCode:H}=await T(["git","annex","config","--set","annex.largefiles",X],{cwd:D});if(H!==0)return{success:!1,error:G.trim()||"Failed to configure largefiles"};return{success:!0}}catch(G){return{success:!1,error:G.message}}}async function i6(D,F="."){try{let{stderr:$,exitCode:J}=await T(["git","annex","add",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||"Failed to add files to git-annex"};return{success:!0}}catch($){return{success:!1,error:$.message}}}function PD(D){return{accessKeyId:D.access_key_id,secretAccessKey:D.secret_access_key,sessionToken:D.session_token}}function iW(D){let F=[/^\(merging .* into .*\.\.\.\)$/,/^\(recording state in git\.\.\.\)$/,/^\(scanning for /,/^\(checking /];return D.split(`
|
|
101
101
|
`).filter(($)=>{let J=$.trim();if(!J)return!1;if(J.includes("setting annex-ignore"))return!1;if(F.some((Q)=>Q.test(J)))return!1;return!0}).join(`
|
|
@@ -382,7 +382,7 @@ NEMAR E2E Test (nm099999)
|
|
|
382
382
|
Upload dir: ${$.upload_dir}`)),console.log(W.dim(`Clone dir: ${$.clone_dir}`));process.exit($.passed?0:1)});var RQ=new I0("import").description("View and recover OpenNeuro import jobs");RQ.command("status").description("Show OpenNeuro import job state (failed/quarantined first)").argument("[dataset-id]","Filter to one dataset id (e.g., on007523)").option("-s, --status <status>","Filter by status (failed, quarantined, copying, ...)").action(async(D,F)=>{if(!T0())return;let $=O("Fetching import status...").start();try{let J=await yg(F.status);$.stop();let Q=J.imports;if(D)Q=Q.filter((B)=>B.dataset_id===D);let Y=J.by_status;if(console.log(W.bold(`
|
|
383
383
|
Import Jobs (${J.total})
|
|
384
384
|
`)),console.log(` ${W.yellow(`in-flight ${(Y.preparing??0)+(Y.copying??0)+(Y.finalizing??0)}`)} ${W.green(`complete ${Y.complete??0}`)} ${W.red(`failed ${Y.failed??0}`)} ${W.red(`quarantined ${Y.quarantined??0}`)} ${W.dim(`rolled_back ${Y.rolled_back??0}`)}
|
|
385
|
-
`),Q.length===0){console.log(W.dim(" No import jobs match."));return}console.log(W.dim(` ${"ID".padEnd(12)} ${"Source".padEnd(12)} ${"Stage".padEnd(10)} ${"Status".padEnd(12)} ${"Updated".padEnd(20)}`)),console.log(W.dim(` ${"\u2500".repeat(70)}`));for(let B of Q){let X=B.status==="complete"?W.green:B.status==="failed"||B.status==="quarantined"?W.red:B.status==="rolled_back"?W.dim:W.yellow,G=B.updated_at?new Date(B.updated_at).toLocaleString():"-";if(console.log(` ${B.dataset_id.padEnd(12)} ${(B.source_id||"-").padEnd(12)} ${B.stage.padEnd(10)} ${X(B.status.padEnd(12))} ${G}`),B.last_error)console.log(W.red(` ${B.last_error}`));if(B.workflow_run_url)console.log(W.dim(` run: ${B.workflow_run_url}`))}}catch(J){$.fail("Failed to fetch import status"),console.error(W.red(L0(J)))}});RQ.command("rollback").description("Roll back a failed/quarantined import (deletes repo + S3 + D1)").argument("<dataset-id>","NEMAR dataset id (e.g., on007523)").action(async(D)=>{if(!T0())return;let{proceed:F}=await D0.prompt([{type:"confirm",name:"proceed",message:W.red(`Roll back import ${D}? This deletes the GitHub repo, S3 objects, and D1 records. This cannot be undone.`),default:!1}]);if(!F){console.log(W.dim("Cancelled."));return}let $=O(`Rolling back ${D}...`).start();try{let J=await xg(D);if(!J.rolled_back){$.fail(`Rollback incomplete for ${D} (kept quarantined); retry after fixing:`);for(let Q of J.warnings)console.log(W.red(` - ${Q}`))}else if(J.warnings.length>0){$.warn(`Rolled back ${D} with warnings`);for(let Q of J.warnings)console.log(W.yellow(` - ${Q}`))}else $.succeed(`Rolled back ${D}`)}catch(J){$.fail(`Failed to roll back ${D}`),console.error(W.red(L0(J)))}});RQ.command("retry").description("Reset a failed/quarantined import to 'preparing' for re-dispatch").argument("<dataset-id>","NEMAR dataset id (e.g., on007523)").action(async(D)=>{if(!T0())return;let F=O(`Resetting ${D}...`).start();try{await _g(D),F.succeed(`${D} reset to 'preparing'. Re-run the onboard-openneuro workflow to retry.`)}catch($){F.fail(`Failed to reset ${D}`),console.error(W.red(L0($)))}});b0.addCommand(RQ);function nh(D,F){let $=D.enrichment.status,J=$==="ok"?W.green("enrich:ok"):$==="failed"?W.red("enrich:failed"):W.dim("enrich:skipped"),Q=D.sync.status,Y=Q==="ok"?W.green("sync:ok"):Q==="failed"?W.red("sync:failed"):W.dim("sync:skipped"),B=D.sync.metadata_columns_written===!0?W.green("cols:written"):D.sync.metadata_columns_error?W.red("cols:failed"):"",X=F?.showRef&&D.enrichment.ref?W.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${J}${X} ${Y} ${B}`),D.enrichment.error)console.log(W.red(` enrichment: ${D.enrichment.error}`));if(D.sync.metadata_columns_error)console.log(W.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var CQ=new I0("fleet").description("Governance drift reporting and enforcement (epic #713)");CQ.command("drift").description("Report dataset repos that are off the governance spec").option("--prefix <prefix>","Filter datasets by id prefix (e.g. nm, on)").option("--visibility <vis>","Filter by visibility: public or private").option("--limit <n>","Max repos to scan (default 25, max 50)","25").option("--json","Output raw JSON").action(async(D)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);if(D.visibility&&!["public","private"].includes(D.visibility))console.log(W.red("Error: --visibility must be public or private")),process.exit(1);let F=O("Scanning fleet for drift...").start();try{let $=await bg({prefix:D.prefix,visibility:D.visibility,limit:Number.parseInt(D.limit,10)||25});if(F.stop(),D.json){console.log(JSON.stringify($,null,2));return}console.log(),console.log(W.bold(`Fleet drift (scanned ${$.scanned}):`));let J=["PUBLIC_UNPROTECTED","RED_REQUIRED_CHECK","CONTEXT_NAME_MISMATCH","MISSING_REQUIRED_WORKFLOW","PRIVATE_WITH_STRAY_READ","DEFAULT_BRANCH_OUTLIER","DEPRECATED_WORKFLOW_PRESENT","COMPLIANT"];for(let Q of J){let Y=$.buckets[Q];if(!Y||Y.length===0)continue;let B=Q==="COMPLIANT"?W.green:W.yellow;if(console.log(` ${B(Q.padEnd(28))} ${Y.length}`),Q!=="COMPLIANT"){let X=Y.slice(0,20).join(", ");console.log(W.dim(` ${X}${Y.length>20?` ... +${Y.length-20}`:""}`))}}console.log()}catch($){if($ instanceof f)F.fail($.message);else F.fail("Failed to scan fleet"),console.log(W.red(` ${$.message}`));process.exit(1)}});CQ.command("enforce").description("Bring dataset repos to the governance spec (single or --all). Dry-run by default.").argument("[dataset-id]","Dataset to enforce (omit when using --all)").option("--all","Bulk enforce across a filtered set (owner-only)").option("--apply","Actually apply changes (default is a dry run)").option("--prefix <prefix>","Bulk: filter by id prefix").option("--visibility <vis>","Bulk: filter by visibility (public|private)").option("--limit <n>","Bulk: max repos (default 25, max 50)","25").option("--json","Output raw JSON").action(async(D,F)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);if(!D&&!F.all)console.log(W.red("Error: provide a dataset-id or use --all")),process.exit(1);if(D&&F.all)console.log(W.red("Error: provide a dataset-id OR --all, not both")),process.exit(1);let $=!F.apply,J=$?"[dry-run] ":"",Q=O(`${J}Enforcing spec...`).start();try{if(D){let Y=await IF(D,$);if(Q.succeed(`${J}${D} (${Y.result.visibility})`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let[B,X]of Object.entries(Y.result.steps)){let G=X.status==="ok"?W.green:X.status==="skipped"?W.yellow:W.red;console.log(` ${G(X.status.padEnd(8))} ${B}${X.detail?W.dim(` (${X.detail})`):""}`)}}else{let Y=await ug({prefix:F.prefix,visibility:F.visibility,limit:Number.parseInt(F.limit,10)||25,dryRun:$});if(Q.succeed(`${J}processed ${Y.count} repo(s)`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let B of Y.results){if(B.error){console.log(` ${W.red("error")} ${B.dataset_id}: ${B.error}`);continue}let X=Object.entries(B.steps??{}).filter(([,H])=>H.status!=="ok").map(([H,q])=>`${H}=${q.status}`),G=X.length?W.yellow("drift"):W.green("ok");console.log(` ${G} ${B.dataset_id}${X.length?W.dim(` (${X.join(", ")})`):""}`)}}}catch(Y){if(Y instanceof f)Q.fail(Y.message);else Q.fail("Enforcement failed"),console.log(W.red(` ${Y.message}`));process.exit(1)}});var MQ=(D)=>new Promise((F)=>setTimeout(F,D));async function BZ0(D,F,$){let J=Date.now()+F,Q="no probe completed";while(Date.now()<J){try{let Y=(await IF(D,!0)).result?.steps?.branch_ruleset;if(Y?.status==="ok")return{status:"green"};if(Y?.detail)Q=Y.detail}catch(Y){Q=Y instanceof f?Y.message:String(Y)}await MQ($)}return{status:"timeout",detail:Q}}CQ.command("revalidate").description("Re-run BIDS validation on main HEAD for unprotected datasets, then optionally enforce (epic #713)").argument("[dataset-id]","Dataset to revalidate (omit when using --all/--prefix)").option("--all","Revalidate across unprotected public datasets").option("--prefix <prefix>","Filter by id prefix (with --all), e.g. nm000 / on").option("--enforce","After a dataset goes green, run enforce (dry-run unless --apply)").option("--apply","With --enforce, actually apply the ruleset (default is a dry run)").option("--force","Override the live-dataset guard (nm000103-107)").option("--limit <n>","Max repos for --all/--prefix (default 25)","25").option("--json","Output raw JSON").action(async(D,F)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);let $=Boolean(F.all||!D&&F.prefix);if(!D&&!$)console.log(W.red("Error: provide a dataset-id, or --all/--prefix")),process.exit(1);let J;if(D)J=[D];else{let q=O("Fetching dataset list...").start();try{let K=[];for(let z=0;;z+=200){let Z=await PF({limit:200,offset:z});if(K.push(...Z.datasets),Z.datasets.length<200||K.length>=Z.total_count)break}let V=Number.parseInt(F.limit,10)||25;J=rg(K,{prefix:F.prefix}).slice(0,V),q.succeed(`${J.length} target(s) (from ${K.length} datasets)`)}catch(K){i0(K,q,"Failed to fetch datasets");return}}let Q=Boolean(F.enforce),Y=Boolean(F.apply),B={revalidated:0,green:0,locked:0,stillRed:0,skipped:0,errors:0},X=[],G=[],H=0;for(let q of J){if(H++,pW.has(q)&&!F.force){console.log(` [${H}/${J.length}] ${W.dim(`${q}: skip (live; use --force)`)}`),B.skipped++;continue}try{let K=await mg(q,F.force);if(X.push(K),K.skipped)console.log(` [${H}/${J.length}] ${q}: ${W.dim(`skipped (${K.skipped})`)}`),B.skipped++;else B.revalidated++,G.push(q),console.log(` [${H}/${J.length}] ${q}: ${W.cyan(`revalidating (${K.triggered_by})`)}`)}catch(K){B.errors++,console.log(` [${H}/${J.length}] ${q}: ${W.red(K instanceof f?K.message:String(K))}`)}if(H<J.length)await MQ(4000)}if(Q&&G.length>0)if(D){let q=G[0],K=O(`Waiting for ${q} validation to land...`).start(),V=await BZ0(q,300000,15000);if(V.status!=="green")K.warn(`${q}: not green within 5m \u2014 last: ${V.detail} (real errors or still running)`),B.stillRed++;else if(B.green++,!Y)K.succeed(`${q}: green (would lock; pass --apply)`);else{let z=await IF(q,!1);if(z.result?.steps?.branch_ruleset?.status==="ok")K.succeed(`${q}: LOCKED`),B.locked++;else K.warn(`${q}: enforce ${z.result?.steps?.branch_ruleset?.status??"?"}`)}}else{let q=O("Waiting ~90s for validations to drain...").start();await MQ(90000),q.text="Enforcing green datasets...";for(let K of G)try{if((await IF(K,!0)).result?.steps?.branch_ruleset?.status!=="ok"){B.stillRed++;continue}if(B.green++,Y){if((await IF(K,!1)).result?.steps?.branch_ruleset?.status==="ok")B.locked++}}catch{B.errors++}q.stop()}if(F.json){console.log(JSON.stringify({tally:B,raw:X},null,2));return}console.log(),console.log(W.cyan(`Done: revalidated=${B.revalidated} green=${B.green} locked=${B.locked} still-red=${B.stillRed} skipped=${B.skipped} errors=${B.errors}`))});b0.addCommand(CQ);var rh=new I0("reindex").description("Refresh dataset metadata: enrichment + nemar.org sync + first-class D1 columns");rh.argument("[dataset-id]","Dataset ID to reindex (e.g., nm000103)").option("--all","Reindex every dataset with a GitHub repo").option("--missing-metadata","Reindex only datasets with NULL metadata columns").option("--stale","Reindex only datasets whose metadata is older than --older-than days").option("--older-than <days>","Threshold in days. Default 30 for --stale, 1 (24h) for --missing-metadata recency guard.").option("--skip-enrichment","Skip the LLM enrichment step").option("--skip-sync","Skip the nemar.org sync + D1 column refresh step").option("--ref <ref>","Ref to enrich from (single-dataset only; default: main)").option("--dry-run","List matched datasets without firing the reindex (bulk only)").action(async(D,F)=>{if(!T0())return;let $=[F.all,F.missingMetadata,F.stale].filter(Boolean).length;if(D&&$>0)console.error(W.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(W.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(W.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(W.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=O(`Reindexing ${D}...`).start();try{let V={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},z=await WQ(D,V),Z=z.enrichment.status!=="failed"&&z.sync.status!=="failed";if(Z)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),nh(z,{showRef:!0}),!Z)process.exit(1)}catch(V){K.fail(`Failed to reindex ${D}`),console.error(W.red(L0(V))),process.exit(1)}return}let J=F.all?"all":F.missingMetadata?"missing-metadata":"stale",Q={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,dry_run:F.dryRun===!0};if(F.olderThan!==void 0){let K=Number.parseInt(F.olderThan,10);if(!Number.isFinite(K)||K<0)console.error(W.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);Q.older_than_days=K}else if(J==="missing-metadata")Q.older_than_days=1;else if(J==="stale")Q.older_than_days=30;let Y=F.dryRun?`Listing ${J} datasets...`:`Reindexing ${J} datasets...`,B=O(Y).start(),X;try{X=await fg(J,Q)}catch(K){B.fail("Bulk reindex failed"),console.error(W.red(L0(K))),process.exit(1)}if(X.dry_run){if(B.succeed(`${X.total} datasets match filter=${J} (dry run, no changes)`),X.datasets)for(let K of X.datasets)console.log(W.dim(` - ${K}`));return}let G=X.results??[],H=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-H;if(q===0)B.succeed(`${G.length}/${G.length} datasets reindexed in ${(X.elapsed_ms/1000).toFixed(1)}s`);else B.warn(`${H}/${G.length} ok; ${q} failed in ${(X.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)nh(K);if(q>0)process.exit(1)});b0.addCommand(rh);var th=new I0("hed-sweep").description("Backfill HED detection (has_hed / hed_version) for existing datasets (#869)");th.option("--limit <n>","Datasets per batch (server clamps to [1,30])","15").option("--reset","Clear every probed HED row so a corrected detector can re-sweep").option("--verbose","Print per-batch progress").option("--json","Output raw JSON instead of the human summary").action(async(D)=>{if(!T0())return;if(D.reset){let X=O("Resetting HED sweep state...").start();try{let G=await hg();if(X.succeed(`Cleared ${G.reset} probed HED row(s); eligible datasets are candidates again`),D.json)console.log(JSON.stringify(G,null,2))}catch(G){X.fail("Reset failed"),console.error(W.red(L0(G))),process.exit(1)}return}let F=Number.parseInt(D.limit??"15",10)||15,$={processed:0,withHed:0,withoutHed:0,unknown:0,errors:0},J=O("Sweeping datasets for HED...").start(),Q=0,Y=null,B=null;try{let X;do{if(X=await gg({limit:F}),Q++,$.processed+=X.processed,$.withHed+=X.withHed,$.withoutHed+=X.withoutHed,$.unknown+=X.unknown,$.errors+=X.errors.length,Y=X.remaining,D.verbose){J.stop(),console.log(` [batch ${Q}] processed=${X.processed} hed=${X.withHed} no-hed=${X.withoutHed} unknown=${X.unknown} errors=${X.errors.length} remaining=${Y??"?"}`);for(let G of X.errors)console.log(` ${W.red(G.dataset_id)}: ${G.error}`);J.start("Sweeping datasets for HED...")}else J.text=`Sweeping datasets for HED... ${$.processed} processed, ${Y??"?"} remaining`;if(Y!=null&&B!=null&&Y>=B){J.warn(`No progress (remaining stuck at ${Y}); stopping - see errors`);break}if(B=Y,(Y??0)>0)await MQ(1000)}while((Y??0)>0);J.stop()}catch(X){J.fail("HED sweep failed"),console.error(W.red(L0(X))),process.exit(1)}if(D.json){console.log(JSON.stringify({...$,batches:Q,remaining:Y},null,2));return}if(console.log(),console.log(W.cyan(`Done in ${Q} batch(es): processed=${$.processed} hed=${$.withHed} no-hed=${$.withoutHed} unknown=${$.unknown} errors=${$.errors} remaining=${Y??0}`)),$.errors>0)process.exit(1)});b0.addCommand(th);var fH=new I0("email-preferences").description("Manage email notification preferences");fH.command("show").description("Show email notification preferences").option("--user <username>","(owner only) show another user's preferences").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let F=O("Fetching email preferences...").start();try{let $=await lg(D.user),J=$.username?`${$.username}'s`:"Your";F.succeed(`${J} email notification preferences:`),console.log();let Q=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let Y of Q){let X=$[Y.key]?W.green("enabled"):W.dim("disabled");console.log(` ${Y.label.padEnd(40)} ${X}`)}console.log(),console.log(W.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch($){F.fail("Failed to fetch preferences"),console.error(W.red(L0($)))}});fH.command("update").description("Update email notification preferences").option("--user-approval <bool>","Enable/disable user approval notifications").option("--publication-request <bool>","Enable/disable publication request notifications").option("--announcements <bool>","Enable/disable announcement emails").option("--all <bool>","Enable/disable all notifications").option("--user <username>","(owner only) update another user's preferences").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(Q){if(Q===void 0)return;let Y=Q.toLowerCase();if(Y==="true"||Y==="1"||Y==="on"||Y==="yes")return!0;if(Y==="false"||Y==="0"||Y==="off"||Y==="no")return!1;console.error(W.red(`Invalid boolean value: "${Q}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let Q=F(D.all);$.user_approval=Q,$.publication_request=Q,$.announcements=Q}else{let Q=F(D.userApproval),Y=F(D.publicationRequest),B=F(D.announcements);if(Q===void 0&&Y===void 0&&B===void 0)console.error(W.red("No preferences specified.")),console.log(" --user-approval <bool> User approval notifications"),console.log(" --publication-request <bool> Publication request notifications"),console.log(" --announcements <bool> Announcement emails"),console.log(" --all <bool> All notifications"),process.exit(1);if(Q!==void 0)$.user_approval=Q;if(Y!==void 0)$.publication_request=Y;if(B!==void 0)$.announcements=B}let J=O("Updating email preferences...").start();try{let Q=await pg($,D.user),Y=Q.username?`${Q.username}'s`:"Your";J.succeed(`${Y} email preferences updated:`),console.log(),console.log(` User approval: ${Q.user_approval?W.green("enabled"):W.dim("disabled")}`),console.log(` Publication request: ${Q.publication_request?W.green("enabled"):W.dim("disabled")}`),console.log(` Announcements: ${Q.announcements?W.green("enabled"):W.dim("disabled")}`)}catch(Q){J.fail("Failed to update preferences"),console.error(W.red(L0(Q)))}});b0.addCommand(fH);var OQ=new I0("notice").description("Manage system notices displayed to CLI users");OQ.command("list").description("List all notices (including expired)").action(async()=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=O("Fetching notices...").start();try{let{notices:F}=await cg();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let Q={critical:W.red.bold,warning:W.yellow,info:W.blue}[$.level]||W.white,Y=$.expires_at&&new Date($.expires_at)<new Date?W.dim(" (expired)"):"";if(console.log(` ${W.dim(`#${$.id}`)} ${Q(`[${$.level.toUpperCase()}]`)} ${W.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${W.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${W.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){i0(F,D,"Failed to fetch notices")}});OQ.command("set").description("Create a new system notice").requiredOption("-m, --message <text>","Notice message text").option("-l, --level <level>","Notice level: info, warning, critical","info").option("-s, --scope <scope>","Target scope: all, admins, members","all").option("-e, --expires <datetime>","Expiry datetime (ISO 8601)").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(W.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(W.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=O("Creating notice...").start();try{let $=await ng({message:D.message,level:D.level,scope:D.scope,expires_at:D.expires});if(F.succeed(`Notice created (ID: ${$.id})`),console.log(` Level: ${$.level}`),console.log(` Scope: ${$.scope}`),console.log(` Message: ${$.message}`),$.expires_at)console.log(` Expires: ${$.expires_at}`)}catch($){i0($,F,"Failed to create notice")}});OQ.command("clear <id>").description("Delete a notice by ID").option(j0,w0).option(g0,v0).action(async(D,F)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(W.red("Invalid notice ID")),process.exit(1);if(!await P0(`Delete notice #${$}?`,F,!1))return;let Q=O("Deleting notice...").start();try{await ig($),Q.succeed(`Notice #${$} deleted`)}catch(Y){i0(Y,Q,"Failed to delete notice")}});b0.addCommand(OQ);b0.command("notify").description("Send an email to a group or a single user").option("--to <group>","Recipient group: all, admins, members").option("--user <username>","Send to a single user by username").requiredOption("--subject <text>","Email subject line").option("--body <text>","Email body (markdown)").option("--body-file <path>","Read email body from file (markdown)").option("--dry-run","Preview recipients without sending").option(j0,w0).option(g0,v0).action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(D.to&&D.user)console.error(W.red("--to and --user are mutually exclusive. Provide exactly one.")),process.exit(1);if(!D.to&&!D.user)console.error(W.red("Provide either --to <group> or --user <username>.")),process.exit(1);if(D.to&&!["all","admins","members"].includes(D.to))console.error(W.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!ah(D.bodyFile))console.error(W.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=JZ0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(W.red("Email body required. Use --body or --body-file.")),process.exit(1);let $=D.user?`user:${D.user}`:D.to,J=D.user?{user:D.user,subject:D.subject,body:F}:{to:D.to,subject:D.subject,body:F};if(D.dryRun){let X=O("Checking recipients...").start();try{let G=await lW({...J,dry_run:!0});if("dry_run"in G){X.succeed(`Dry run: ${G.recipient_count} recipient(s) for "${G.recipient_group}"`),console.log();for(let H of G.recipients)console.log(` ${H}`)}}catch(G){i0(G,X,"Failed to check recipients")}return}console.log(W.bold("Email preview:")),console.log(` To: ${W.cyan($)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log();let Q=D.user?`Send this email to ${D.user}?`:"Send this broadcast email?";if(!await P0(Q,D,!1))return;let B=O(D.user?`Sending to ${D.user}...`:"Sending broadcast...").start();try{let X=await lW(J);if("broadcast_id"in X)if(X.failure_count>0){B.warn(`Email send: ${X.recipient_count} delivered, ${X.failure_count} failed`);for(let G of X.failed_recipients)console.log(W.red(` Failed: ${G}`))}else{let G=D.user?`Email sent to ${D.user}`:`Broadcast sent to ${X.recipient_count} recipient(s)`;B.succeed(`${G} (ID: ${X.broadcast_id})`)}}catch(X){i0(X,B,"Failed to send email")}});var XZ0=1500;function GZ0(D){switch(D.kind){case"ok":return W.green(`ok ${D.schema_version}`);case"stale":return W.yellow(`stale ${D.schema_version}`);case"missing":return W.red("missing");case"error":return W.red(`error ${D.status||"?"}: ${D.message}`)}}function WZ0(D){return D.kind==="stale"||D.kind==="missing"}function HZ0(D){let $=D.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${$}$`)}var eh=new I0("summary").description("summary.json coverage across published dataset versions");eh.command("check").description("Report which (dataset_id, version) pairs have stale or missing summary.json").option("--fix","Dispatch generate-manifest for every stale/missing version").option("--id <id>","Limit to a single dataset_id (exact match)").option("--match <glob>","Limit to dataset_ids matching a glob pattern: `*` matches any run of chars, `?` matches one char. Examples: `on*`, `nm00010?`, `*99999`. Can be combined with --id (id wins if both passed).").option("--only-stale","Print only rows that are not ok (suppresses ok rows)").option("--json","Emit the full report as JSON instead of a table").option(j0,w0).option(g0,v0).action(async(D)=>{if(!T0())return;let F=O("Building coverage report...").start(),$;try{$=await ag()}catch(V){i0(V,F,"Failed to fetch coverage report");return}F.succeed(`Coverage: target=schema ${$.target_schema}, versions=${$.totals.versions}`);let J=$.versions,Q=null;if(D.id){if(J=J.filter((V)=>V.dataset_id===D.id),Q=`dataset_id=${D.id}`,J.length===0){console.log(W.yellow(`No rows for ${Q}`));return}}else if(D.match){let V=HZ0(D.match);if(J=J.filter((z)=>V.test(z.dataset_id)),Q=`--match ${D.match}`,J.length===0){console.log(W.yellow(`No rows match ${Q}`));return}console.log(W.dim(`Scoped to ${J.length} version(s) matching ${D.match}`))}if(D.json){console.log(JSON.stringify(Q?{...$,versions:J,totals:ih(J)}:$,null,2));return}let Y=D.onlyStale?J.filter((V)=>V.state.kind!=="ok"):J;if(Y.length===0)console.log(W.green("All versions at target schema \u2014 no drift."));else{let V=Math.max(...Y.map((Z)=>Z.dataset_id.length),10),z=Math.max(...Y.map((Z)=>Z.version.length),7);for(let Z of Y)console.log(` ${Z.dataset_id.padEnd(V)} ${Z.version.padEnd(z)} ${GZ0(Z.state)}`)}let B=Q?ih(J):$.totals;if(console.log(),console.log(` Total: ${B.versions} ${W.green(`ok=${B.ok}`)} ${W.yellow(`stale=${B.stale}`)} ${W.red(`missing=${B.missing}`)} ${W.red(`error=${B.error}`)}`),!D.fix){if(B.stale+B.missing>0)console.log(W.dim(`
|
|
385
|
+
`),Q.length===0){console.log(W.dim(" No import jobs match."));return}console.log(W.dim(` ${"ID".padEnd(12)} ${"Source".padEnd(12)} ${"Stage".padEnd(10)} ${"Status".padEnd(12)} ${"Updated".padEnd(20)}`)),console.log(W.dim(` ${"\u2500".repeat(70)}`));for(let B of Q){let X=B.status==="complete"?W.green:B.status==="failed"||B.status==="quarantined"?W.red:B.status==="rolled_back"?W.dim:W.yellow,G=B.updated_at?new Date(B.updated_at).toLocaleString():"-";if(console.log(` ${B.dataset_id.padEnd(12)} ${(B.source_id||"-").padEnd(12)} ${B.stage.padEnd(10)} ${X(B.status.padEnd(12))} ${G}`),B.last_error)console.log(W.red(` ${B.last_error}`));if(B.workflow_run_url)console.log(W.dim(` run: ${B.workflow_run_url}`))}}catch(J){$.fail("Failed to fetch import status"),console.error(W.red(L0(J)))}});RQ.command("rollback").description("Roll back a failed/quarantined import (deletes repo + S3 + D1)").argument("<dataset-id>","NEMAR dataset id (e.g., on007523)").action(async(D)=>{if(!T0())return;let{proceed:F}=await D0.prompt([{type:"confirm",name:"proceed",message:W.red(`Roll back import ${D}? This deletes the GitHub repo, S3 objects, and D1 records. This cannot be undone.`),default:!1}]);if(!F){console.log(W.dim("Cancelled."));return}let $=O(`Rolling back ${D}...`).start();try{let J=await xg(D);if(!J.rolled_back){$.fail(`Rollback incomplete for ${D} (kept quarantined); retry after fixing:`);for(let Q of J.warnings)console.log(W.red(` - ${Q}`))}else if(J.warnings.length>0){$.warn(`Rolled back ${D} with warnings`);for(let Q of J.warnings)console.log(W.yellow(` - ${Q}`))}else $.succeed(`Rolled back ${D}`)}catch(J){$.fail(`Failed to roll back ${D}`),console.error(W.red(L0(J)))}});RQ.command("retry").description("Reset a failed/quarantined import to 'preparing' for re-dispatch").argument("<dataset-id>","NEMAR dataset id (e.g., on007523)").action(async(D)=>{if(!T0())return;let F=O(`Resetting ${D}...`).start();try{await _g(D),F.succeed(`${D} reset to 'preparing'. Re-run the onboard-openneuro workflow to retry.`)}catch($){F.fail(`Failed to reset ${D}`),console.error(W.red(L0($)))}});b0.addCommand(RQ);function nh(D,F){let $=D.enrichment.status,J=$==="ok"?W.green("enrich:ok"):$==="failed"?W.red("enrich:failed"):W.dim("enrich:skipped"),Q=D.sync.status,Y=Q==="ok"?W.green("sync:ok"):Q==="failed"?W.red("sync:failed"):W.dim("sync:skipped"),B=D.sync.metadata_columns_written===!0?W.green("cols:written"):D.sync.metadata_columns_error?W.red("cols:failed"):"",X=F?.showRef&&D.enrichment.ref?W.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${J}${X} ${Y} ${B}`),D.enrichment.error)console.log(W.red(` enrichment: ${D.enrichment.error}`));if(D.sync.metadata_columns_error)console.log(W.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var CQ=new I0("fleet").description("Governance drift reporting and enforcement (epic #713)");CQ.command("drift").description("Report dataset repos that are off the governance spec").option("--prefix <prefix>","Filter datasets by id prefix (e.g. nm, on)").option("--visibility <vis>","Filter by visibility: public or private").option("--limit <n>","Max repos to scan (default 25, max 50)","25").option("--json","Output raw JSON").action(async(D)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);if(D.visibility&&!["public","private"].includes(D.visibility))console.log(W.red("Error: --visibility must be public or private")),process.exit(1);let F=O("Scanning fleet for drift...").start();try{let $=await bg({prefix:D.prefix,visibility:D.visibility,limit:Number.parseInt(D.limit,10)||25});if(F.stop(),D.json){console.log(JSON.stringify($,null,2));return}console.log(),console.log(W.bold(`Fleet drift (scanned ${$.scanned}):`));let J=["PUBLIC_UNPROTECTED","RED_REQUIRED_CHECK","CONTEXT_NAME_MISMATCH","MISSING_REQUIRED_WORKFLOW","PRIVATE_WITH_STRAY_READ","DEFAULT_BRANCH_OUTLIER","DEPRECATED_WORKFLOW_PRESENT","COMPLIANT"];for(let Q of J){let Y=$.buckets[Q];if(!Y||Y.length===0)continue;let B=Q==="COMPLIANT"?W.green:W.yellow;if(console.log(` ${B(Q.padEnd(28))} ${Y.length}`),Q!=="COMPLIANT"){let X=Y.slice(0,20).join(", ");console.log(W.dim(` ${X}${Y.length>20?` ... +${Y.length-20}`:""}`))}}console.log()}catch($){if($ instanceof f)F.fail($.message);else F.fail("Failed to scan fleet"),console.log(W.red(` ${$.message}`));process.exit(1)}});CQ.command("enforce").description("Bring dataset repos to the governance spec (single or --all). Dry-run by default.").argument("[dataset-id]","Dataset to enforce (omit when using --all)").option("--all","Bulk enforce across a filtered set (owner-only)").option("--apply","Actually apply changes (default is a dry run)").option("--prefix <prefix>","Bulk: filter by id prefix").option("--visibility <vis>","Bulk: filter by visibility (public|private)").option("--limit <n>","Bulk: max repos (default 25, max 50)","25").option("--json","Output raw JSON").action(async(D,F)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);if(!D&&!F.all)console.log(W.red("Error: provide a dataset-id or use --all")),process.exit(1);if(D&&F.all)console.log(W.red("Error: provide a dataset-id OR --all, not both")),process.exit(1);let $=!F.apply,J=$?"[dry-run] ":"",Q=O(`${J}Enforcing spec...`).start();try{if(D){let Y=await IF(D,$);if(Q.succeed(`${J}${D} (${Y.result.visibility})`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let[B,X]of Object.entries(Y.result.steps)){let G=X.status==="ok"?W.green:X.status==="skipped"?W.yellow:W.red;console.log(` ${G(X.status.padEnd(8))} ${B}${X.detail?W.dim(` (${X.detail})`):""}`)}}else{let Y=await ug({prefix:F.prefix,visibility:F.visibility,limit:Number.parseInt(F.limit,10)||25,dryRun:$});if(Q.succeed(`${J}processed ${Y.count} repo(s)`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let B of Y.results){if(B.error){console.log(` ${W.red("error")} ${B.dataset_id}: ${B.error}`);continue}let X=Object.entries(B.steps??{}).filter(([,H])=>H.status!=="ok").map(([H,q])=>`${H}=${q.status}`),G=X.length?W.yellow("drift"):W.green("ok");console.log(` ${G} ${B.dataset_id}${X.length?W.dim(` (${X.join(", ")})`):""}`)}}}catch(Y){if(Y instanceof f)Q.fail(Y.message);else Q.fail("Enforcement failed"),console.log(W.red(` ${Y.message}`));process.exit(1)}});var MQ=(D)=>new Promise((F)=>setTimeout(F,D));async function BZ0(D,F,$){let J=Date.now()+F,Q="no probe completed";while(Date.now()<J){try{let Y=(await IF(D,!0)).result?.steps?.branch_ruleset;if(Y?.status==="ok")return{status:"green"};if(Y?.detail)Q=Y.detail}catch(Y){Q=Y instanceof f?Y.message:String(Y)}await MQ($)}return{status:"timeout",detail:Q}}CQ.command("revalidate").description("Re-run BIDS validation on main HEAD for unprotected datasets, then optionally enforce (epic #713)").argument("[dataset-id]","Dataset to revalidate (omit when using --all/--prefix)").option("--all","Revalidate across unprotected public datasets").option("--prefix <prefix>","Filter by id prefix (with --all), e.g. nm000 / on").option("--enforce","After a dataset goes green, run enforce (dry-run unless --apply)").option("--apply","With --enforce, actually apply the ruleset (default is a dry run)").option("--force","Override the live-dataset guard (nm000103-107)").option("--limit <n>","Max repos for --all/--prefix (default 25)","25").option("--json","Output raw JSON").action(async(D,F)=>{if(!H0())console.log(W.red("Error: Not authenticated")),process.exit(1);let $=Boolean(F.all||!D&&F.prefix);if(!D&&!$)console.log(W.red("Error: provide a dataset-id, or --all/--prefix")),process.exit(1);let J;if(D)J=[D];else{let q=O("Fetching dataset list...").start();try{let K=[];for(let z=0;;z+=200){let Z=await PF({limit:200,offset:z});if(K.push(...Z.datasets),Z.datasets.length<200||K.length>=Z.total_count)break}let V=Number.parseInt(F.limit,10)||25;J=rg(K,{prefix:F.prefix}).slice(0,V),q.succeed(`${J.length} target(s) (from ${K.length} datasets)`)}catch(K){i0(K,q,"Failed to fetch datasets");return}}let Q=Boolean(F.enforce),Y=Boolean(F.apply),B={revalidated:0,green:0,locked:0,stillRed:0,skipped:0,errors:0},X=[],G=[],H=0;for(let q of J){if(H++,pW.has(q)&&!F.force){console.log(` [${H}/${J.length}] ${W.dim(`${q}: skip (live; use --force)`)}`),B.skipped++;continue}try{let K=await mg(q,F.force);if(X.push(K),K.skipped)console.log(` [${H}/${J.length}] ${q}: ${W.dim(`skipped (${K.skipped})`)}`),B.skipped++;else B.revalidated++,G.push(q),console.log(` [${H}/${J.length}] ${q}: ${W.cyan(`revalidating (${K.triggered_by})`)}`)}catch(K){B.errors++,console.log(` [${H}/${J.length}] ${q}: ${W.red(K instanceof f?K.message:String(K))}`)}if(H<J.length)await MQ(4000)}if(Q&&G.length>0)if(D){let q=G[0],K=O(`Waiting for ${q} validation to land...`).start(),V=await BZ0(q,300000,15000);if(V.status!=="green")K.warn(`${q}: not green within 5m \u2014 last: ${V.detail} (real errors or still running)`),B.stillRed++;else if(B.green++,!Y)K.succeed(`${q}: green (would lock; pass --apply)`);else{let z=await IF(q,!1);if(z.result?.steps?.branch_ruleset?.status==="ok")K.succeed(`${q}: LOCKED`),B.locked++;else K.warn(`${q}: enforce ${z.result?.steps?.branch_ruleset?.status??"?"}`)}}else{let q=O("Waiting ~90s for validations to drain...").start();await MQ(90000),q.text="Enforcing green datasets...";for(let K of G)try{if((await IF(K,!0)).result?.steps?.branch_ruleset?.status!=="ok"){B.stillRed++;continue}if(B.green++,Y){if((await IF(K,!1)).result?.steps?.branch_ruleset?.status==="ok")B.locked++}}catch{B.errors++}q.stop()}if(F.json){console.log(JSON.stringify({tally:B,raw:X},null,2));return}console.log(),console.log(W.cyan(`Done: revalidated=${B.revalidated} green=${B.green} locked=${B.locked} still-red=${B.stillRed} skipped=${B.skipped} errors=${B.errors}`))});b0.addCommand(CQ);var rh=new I0("reindex").description("Refresh dataset metadata: enrichment + nemar.org sync + first-class D1 columns");rh.argument("[dataset-id]","Dataset ID to reindex (e.g., nm000103)").option("--all","Reindex every dataset with a GitHub repo").option("--missing-metadata","Reindex only datasets with NULL metadata columns").option("--stale","Reindex only datasets whose metadata is older than --older-than days").option("--older-than <days>","Threshold in days. Default 30 for --stale, 1 (24h) for --missing-metadata recency guard.").option("--skip-enrichment","Skip the LLM enrichment step").option("--skip-sync","Skip the nemar.org sync + D1 column refresh step").option("--ref <ref>","Ref to enrich from (single-dataset only; default: main)").option("--dry-run","List matched datasets without firing the reindex (bulk only)").action(async(D,F)=>{if(!T0())return;let $=[F.all,F.missingMetadata,F.stale].filter(Boolean).length;if(D&&$>0)console.error(W.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(W.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(W.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(W.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=O(`Reindexing ${D}...`).start();try{let V={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},z=await WQ(D,V),Z=z.enrichment.status!=="failed"&&z.sync.status!=="failed";if(Z)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),nh(z,{showRef:!0}),!Z)process.exit(1)}catch(V){K.fail(`Failed to reindex ${D}`),console.error(W.red(L0(V))),process.exit(1)}return}let J=F.all?"all":F.missingMetadata?"missing-metadata":"stale",Q={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,dry_run:F.dryRun===!0};if(F.olderThan!==void 0){let K=Number.parseInt(F.olderThan,10);if(!Number.isFinite(K)||K<0)console.error(W.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);Q.older_than_days=K}else if(J==="missing-metadata")Q.older_than_days=1;else if(J==="stale")Q.older_than_days=30;let Y=F.dryRun?`Listing ${J} datasets...`:`Reindexing ${J} datasets...`,B=O(Y).start(),X;try{X=await fg(J,Q)}catch(K){B.fail("Bulk reindex failed"),console.error(W.red(L0(K))),process.exit(1)}if(X.dry_run){if(B.succeed(`${X.total} datasets match filter=${J} (dry run, no changes)`),X.datasets)for(let K of X.datasets)console.log(W.dim(` - ${K}`));return}let G=X.results??[],H=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-H;if(q===0)B.succeed(`${G.length}/${G.length} datasets reindexed in ${(X.elapsed_ms/1000).toFixed(1)}s`);else B.warn(`${H}/${G.length} ok; ${q} failed in ${(X.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)nh(K);if(q>0)process.exit(1)});b0.addCommand(rh);var th=new I0("hed-sweep").description("Backfill HED detection (has_hed / hed_version) for existing datasets (#869)");th.option("--limit <n>","Datasets per batch (server clamps to [1,30])","15").option("--reset","Clear every probed HED row so a corrected detector can re-sweep").option("--verbose","Print per-batch progress").option("--json","Output raw JSON instead of the human summary").action(async(D)=>{if(!T0())return;if(D.reset){let X=O("Resetting HED sweep state...").start();try{let G=await hg();if(X.succeed(`Cleared ${G.reset} probed HED row(s); eligible datasets are candidates again`),D.json)console.log(JSON.stringify(G,null,2))}catch(G){X.fail("Reset failed"),console.error(W.red(L0(G))),process.exit(1)}return}let F=Number.parseInt(D.limit??"15",10)||15,$={processed:0,withHed:0,withoutHed:0,unknown:0,errors:0},J=O("Sweeping datasets for HED...").start(),Q=0,Y=null,B=null;try{let X;do{if(X=await gg({limit:F}),Q++,$.processed+=X.processed,$.withHed+=X.withHed,$.withoutHed+=X.withoutHed,$.unknown+=X.unknown,$.errors+=X.errors.length,Y=X.remaining,D.verbose){J.stop(),console.log(` [batch ${Q}] processed=${X.processed} hed=${X.withHed} no-hed=${X.withoutHed} unknown=${X.unknown} errors=${X.errors.length} remaining=${Y??"?"}`);for(let G of X.errors)console.log(` ${W.red(G.dataset_id)}: ${G.error}`);J.start("Sweeping datasets for HED...")}else J.text=`Sweeping datasets for HED... ${$.processed} processed, ${Y??"?"} remaining`;if(Y!=null&&B!=null&&Y>=B){J.warn(`No progress (remaining stuck at ${Y}); stopping - see errors`);break}if(B=Y,(Y??0)>0)await MQ(1000)}while((Y??0)>0);J.stop()}catch(X){J.fail("HED sweep failed"),console.error(W.red(L0(X))),process.exit(1)}if(D.json)console.log(JSON.stringify({...$,batches:Q,remaining:Y},null,2));else{if(console.log(),Y===null)console.log(W.yellow("Warning: backend returned a null remaining count; the sweep may be incomplete - check server logs."));console.log(W.cyan(`Done in ${Q} batch(es): processed=${$.processed} hed=${$.withHed} no-hed=${$.withoutHed} unknown=${$.unknown} errors=${$.errors} remaining=${Y??"unknown"}`))}if($.errors>0||Y===null)process.exit(1)});b0.addCommand(th);var fH=new I0("email-preferences").description("Manage email notification preferences");fH.command("show").description("Show email notification preferences").option("--user <username>","(owner only) show another user's preferences").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let F=O("Fetching email preferences...").start();try{let $=await lg(D.user),J=$.username?`${$.username}'s`:"Your";F.succeed(`${J} email notification preferences:`),console.log();let Q=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let Y of Q){let X=$[Y.key]?W.green("enabled"):W.dim("disabled");console.log(` ${Y.label.padEnd(40)} ${X}`)}console.log(),console.log(W.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch($){F.fail("Failed to fetch preferences"),console.error(W.red(L0($)))}});fH.command("update").description("Update email notification preferences").option("--user-approval <bool>","Enable/disable user approval notifications").option("--publication-request <bool>","Enable/disable publication request notifications").option("--announcements <bool>","Enable/disable announcement emails").option("--all <bool>","Enable/disable all notifications").option("--user <username>","(owner only) update another user's preferences").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(Q){if(Q===void 0)return;let Y=Q.toLowerCase();if(Y==="true"||Y==="1"||Y==="on"||Y==="yes")return!0;if(Y==="false"||Y==="0"||Y==="off"||Y==="no")return!1;console.error(W.red(`Invalid boolean value: "${Q}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let Q=F(D.all);$.user_approval=Q,$.publication_request=Q,$.announcements=Q}else{let Q=F(D.userApproval),Y=F(D.publicationRequest),B=F(D.announcements);if(Q===void 0&&Y===void 0&&B===void 0)console.error(W.red("No preferences specified.")),console.log(" --user-approval <bool> User approval notifications"),console.log(" --publication-request <bool> Publication request notifications"),console.log(" --announcements <bool> Announcement emails"),console.log(" --all <bool> All notifications"),process.exit(1);if(Q!==void 0)$.user_approval=Q;if(Y!==void 0)$.publication_request=Y;if(B!==void 0)$.announcements=B}let J=O("Updating email preferences...").start();try{let Q=await pg($,D.user),Y=Q.username?`${Q.username}'s`:"Your";J.succeed(`${Y} email preferences updated:`),console.log(),console.log(` User approval: ${Q.user_approval?W.green("enabled"):W.dim("disabled")}`),console.log(` Publication request: ${Q.publication_request?W.green("enabled"):W.dim("disabled")}`),console.log(` Announcements: ${Q.announcements?W.green("enabled"):W.dim("disabled")}`)}catch(Q){J.fail("Failed to update preferences"),console.error(W.red(L0(Q)))}});b0.addCommand(fH);var OQ=new I0("notice").description("Manage system notices displayed to CLI users");OQ.command("list").description("List all notices (including expired)").action(async()=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=O("Fetching notices...").start();try{let{notices:F}=await cg();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let Q={critical:W.red.bold,warning:W.yellow,info:W.blue}[$.level]||W.white,Y=$.expires_at&&new Date($.expires_at)<new Date?W.dim(" (expired)"):"";if(console.log(` ${W.dim(`#${$.id}`)} ${Q(`[${$.level.toUpperCase()}]`)} ${W.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${W.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${W.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){i0(F,D,"Failed to fetch notices")}});OQ.command("set").description("Create a new system notice").requiredOption("-m, --message <text>","Notice message text").option("-l, --level <level>","Notice level: info, warning, critical","info").option("-s, --scope <scope>","Target scope: all, admins, members","all").option("-e, --expires <datetime>","Expiry datetime (ISO 8601)").action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(W.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(W.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=O("Creating notice...").start();try{let $=await ng({message:D.message,level:D.level,scope:D.scope,expires_at:D.expires});if(F.succeed(`Notice created (ID: ${$.id})`),console.log(` Level: ${$.level}`),console.log(` Scope: ${$.scope}`),console.log(` Message: ${$.message}`),$.expires_at)console.log(` Expires: ${$.expires_at}`)}catch($){i0($,F,"Failed to create notice")}});OQ.command("clear <id>").description("Delete a notice by ID").option(j0,w0).option(g0,v0).action(async(D,F)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(W.red("Invalid notice ID")),process.exit(1);if(!await P0(`Delete notice #${$}?`,F,!1))return;let Q=O("Deleting notice...").start();try{await ig($),Q.succeed(`Notice #${$} deleted`)}catch(Y){i0(Y,Q,"Failed to delete notice")}});b0.addCommand(OQ);b0.command("notify").description("Send an email to a group or a single user").option("--to <group>","Recipient group: all, admins, members").option("--user <username>","Send to a single user by username").requiredOption("--subject <text>","Email subject line").option("--body <text>","Email body (markdown)").option("--body-file <path>","Read email body from file (markdown)").option("--dry-run","Preview recipients without sending").option(j0,w0).option(g0,v0).action(async(D)=>{if(!H0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(D.to&&D.user)console.error(W.red("--to and --user are mutually exclusive. Provide exactly one.")),process.exit(1);if(!D.to&&!D.user)console.error(W.red("Provide either --to <group> or --user <username>.")),process.exit(1);if(D.to&&!["all","admins","members"].includes(D.to))console.error(W.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!ah(D.bodyFile))console.error(W.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=JZ0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(W.red("Email body required. Use --body or --body-file.")),process.exit(1);let $=D.user?`user:${D.user}`:D.to,J=D.user?{user:D.user,subject:D.subject,body:F}:{to:D.to,subject:D.subject,body:F};if(D.dryRun){let X=O("Checking recipients...").start();try{let G=await lW({...J,dry_run:!0});if("dry_run"in G){X.succeed(`Dry run: ${G.recipient_count} recipient(s) for "${G.recipient_group}"`),console.log();for(let H of G.recipients)console.log(` ${H}`)}}catch(G){i0(G,X,"Failed to check recipients")}return}console.log(W.bold("Email preview:")),console.log(` To: ${W.cyan($)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log();let Q=D.user?`Send this email to ${D.user}?`:"Send this broadcast email?";if(!await P0(Q,D,!1))return;let B=O(D.user?`Sending to ${D.user}...`:"Sending broadcast...").start();try{let X=await lW(J);if("broadcast_id"in X)if(X.failure_count>0){B.warn(`Email send: ${X.recipient_count} delivered, ${X.failure_count} failed`);for(let G of X.failed_recipients)console.log(W.red(` Failed: ${G}`))}else{let G=D.user?`Email sent to ${D.user}`:`Broadcast sent to ${X.recipient_count} recipient(s)`;B.succeed(`${G} (ID: ${X.broadcast_id})`)}}catch(X){i0(X,B,"Failed to send email")}});var XZ0=1500;function GZ0(D){switch(D.kind){case"ok":return W.green(`ok ${D.schema_version}`);case"stale":return W.yellow(`stale ${D.schema_version}`);case"missing":return W.red("missing");case"error":return W.red(`error ${D.status||"?"}: ${D.message}`)}}function WZ0(D){return D.kind==="stale"||D.kind==="missing"}function HZ0(D){let $=D.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${$}$`)}var eh=new I0("summary").description("summary.json coverage across published dataset versions");eh.command("check").description("Report which (dataset_id, version) pairs have stale or missing summary.json").option("--fix","Dispatch generate-manifest for every stale/missing version").option("--id <id>","Limit to a single dataset_id (exact match)").option("--match <glob>","Limit to dataset_ids matching a glob pattern: `*` matches any run of chars, `?` matches one char. Examples: `on*`, `nm00010?`, `*99999`. Can be combined with --id (id wins if both passed).").option("--only-stale","Print only rows that are not ok (suppresses ok rows)").option("--json","Emit the full report as JSON instead of a table").option(j0,w0).option(g0,v0).action(async(D)=>{if(!T0())return;let F=O("Building coverage report...").start(),$;try{$=await ag()}catch(V){i0(V,F,"Failed to fetch coverage report");return}F.succeed(`Coverage: target=schema ${$.target_schema}, versions=${$.totals.versions}`);let J=$.versions,Q=null;if(D.id){if(J=J.filter((V)=>V.dataset_id===D.id),Q=`dataset_id=${D.id}`,J.length===0){console.log(W.yellow(`No rows for ${Q}`));return}}else if(D.match){let V=HZ0(D.match);if(J=J.filter((z)=>V.test(z.dataset_id)),Q=`--match ${D.match}`,J.length===0){console.log(W.yellow(`No rows match ${Q}`));return}console.log(W.dim(`Scoped to ${J.length} version(s) matching ${D.match}`))}if(D.json){console.log(JSON.stringify(Q?{...$,versions:J,totals:ih(J)}:$,null,2));return}let Y=D.onlyStale?J.filter((V)=>V.state.kind!=="ok"):J;if(Y.length===0)console.log(W.green("All versions at target schema \u2014 no drift."));else{let V=Math.max(...Y.map((Z)=>Z.dataset_id.length),10),z=Math.max(...Y.map((Z)=>Z.version.length),7);for(let Z of Y)console.log(` ${Z.dataset_id.padEnd(V)} ${Z.version.padEnd(z)} ${GZ0(Z.state)}`)}let B=Q?ih(J):$.totals;if(console.log(),console.log(` Total: ${B.versions} ${W.green(`ok=${B.ok}`)} ${W.yellow(`stale=${B.stale}`)} ${W.red(`missing=${B.missing}`)} ${W.red(`error=${B.error}`)}`),!D.fix){if(B.stale+B.missing>0)console.log(W.dim(`
|
|
386
386
|
Run with --fix to dispatch generate-manifest for the ${B.stale+B.missing} drifted version(s).`));return}let X=J.filter((V)=>WZ0(V.state));if(X.length===0){console.log(W.green(`
|
|
387
387
|
Nothing to dispatch.`));return}let G=Q?` (scoped to ${Q})`:"",H=await P0(`Dispatch generate-manifest for ${X.length} version(s)${G}? Each dispatch queues a runner job on nemarDatasets/.github.`,D);if(H!=="confirmed"){console.log(W.dim(H==="declined"?"Skipped":"Cancelled"));return}let q=0,K=0;console.log();for(let[V,z]of X.entries()){let Z=`${z.dataset_id}@${z.version}`,U=O(`[${V+1}/${X.length}] dispatching ${Z}...`).start();try{await og(z.dataset_id,z.version),U.succeed(`[${V+1}/${X.length}] dispatched ${Z}`),q++}catch(M){U.fail(`[${V+1}/${X.length}] ${Z}: ${L0(M)}`),K++}if(V<X.length-1)await new Promise((M)=>setTimeout(M,XZ0))}if(console.log(),console.log(K===0?W.green(`All ${q} dispatches succeeded.`):W.yellow(`${q} succeeded, ${K} failed.`)),console.log(W.dim("Workflow runs will appear on https://github.com/nemarDatasets/.github/actions. Re-run `nemar admin summary check` once they complete to verify drift cleared.")),K>0)process.exitCode=1});function ih(D){return{versions:D.length,ok:D.filter((F)=>F.state.kind==="ok").length,stale:D.filter((F)=>F.state.kind==="stale").length,missing:D.filter((F)=>F.state.kind==="missing").length,error:D.filter((F)=>F.state.kind==="error").length}}b0.addCommand(eh);ND();k6();c3();n8();x4();r8();var Db={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)"}}},qZ0={upload:["git-annex","gh","aws","deno"],download:["gh"],clone:["git","gh"],push:["git-annex","gh"],publish:["gh","aws"],update:["git","gh"],release:["git","gh"]};function KZ0(){if(process.platform==="darwin")return"macos";if(process.platform==="win32")return"windows";return"linux"}function Fb(D,F=KZ0()){return D.installInstructions[F]}function zZ0(D){let F=D.match(/(\d+\.\d+(?:\.\d+)?)/);return F?F[1]:void 0}async function $b(D){try{let{exitCode:F,stdout:$}=await T(D.cmd);if(F!==0)return{available:!1};return{available:!0,version:zZ0($)}}catch(F){let $=F instanceof Error?F.message:String(F);if(!$.includes("ENOENT")&&!$.includes("not found"))console.error(` Warning: ${D.name} check failed unexpectedly: ${$}`);return{available:!1}}}async function gH(){let D=Object.entries(Db);return Promise.all(D.map(async([F,$])=>{let{available:J,version:Q}=await $b($);return{key:F,name:$.name,purpose:$.purpose,required:$.required,available:J,version:Q,installInstruction:Fb($)}}))}async function Jb(){let F=(await gH()).filter(($)=>$.required&&!$.available);if(F.length===0)return[];console.warn(`
|
|
388
388
|
Heads up: some tools NEMAR needs for uploading/validating aren't installed yet:`);for(let $ of F)console.warn(` - ${$.name} (${$.purpose})`),console.warn(` Install: ${$.installInstruction}`);return console.warn("Run `nemar doctor` anytime to re-check. You can finish signup without them.\n"),F}async function u4(D){let $=qZ0[D].map((B)=>Db[B]).filter(Boolean),Q=(await Promise.all($.map(async(B)=>({check:B,available:(await $b(B)).available})))).filter((B)=>!B.available&&B.check.required).map((B)=>({tool:B.check.name,installInstruction:Fb(B.check)}));if(Q.length===0)return;let Y=[`
|
package/package.json
CHANGED