nemar-cli 0.9.0 → 0.9.1-PR965.36702c1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ ${H.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
|
|
|
102
102
|
${$} ${D.message}
|
|
103
103
|
${Q}${J}
|
|
104
104
|
${F}
|
|
105
|
-
`)}var Ap=!1;var Oz=P(()=>{t0()});var Cp;var Np=P(()=>{Cp={name:"nemar-cli",version:"0.9.0",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",ajv:"^8.20.0","ajv-formats":"^3.0.1",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 j3;var WX=P(()=>{Np();j3=Cp.version});function $0(D){if(D instanceof Error)return D.message;return String(D)}var f,T3;var K1=P(()=>{f=class f extends Error{statusCode;details;step;constructor(D,F,$,Q){super(F);this.statusCode=D;this.details=$;this.step=Q;this.name="ApiError"}};T3=class T3 extends f{mode;eta;constructor(D,F,$,Q){super(503,F,Q);this.mode=D;this.eta=$;this.name="MaintenanceError"}}});function Rp(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(Tz)return jz;return KD().apiUrl||jz}async function _(D,F={},$=!1,Q){let J=`${Rp()}${D}`,Y={"Content-Type":"application/json","X-CLI-Version":j3,...F.headers};if($){let G=KD();if(!G.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(G.apiKey)Y.Authorization=`Bearer ${G.apiKey}`}let X;try{X=await fetch(J,{...F,headers:Y})}catch(G){throw new f(0,`Network error: Could not connect to ${Rp()}`,{originalError:G instanceof Error?G.message:String(G)})}let B;try{B=await X.json()}catch{throw new f(X.status,`Invalid response from server (status ${X.status})`)}if(!X.ok){if(X.status===503&&(B.mode==="read-only"||B.mode==="full")){let G=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",W=typeof B.eta==="string"?B.eta:null,q=new T3(B.mode,G,W,B.details);throw GX(q),q}throw new f(X.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}if(Q){let G=Q.safeParse(B);if(!G.success)throw new f(X.status,`Response for ${D} did not match the expected NEMAR contract`,{issues:G.error.issues});return G.data}return B}var jz="https://api.nemar.org",Tz;var I4=P(()=>{P4();Oz();WX();K1();Tz=jz.includes("workers.dev")});async function Op(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let Q=$.toString()?`?${$.toString()}`:"";return _(`/admin/users${Q}`,{},!0)}async function jp(D){return _(`/admin/approve/${D}`,{method:"POST"},!0)}async function Tp(D){return _(`/admin/revoke/${D}`,{method:"POST"},!0)}async function wp(D,F){return _(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function wz(D,F){return _(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Pp(D){return _(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Ip(D){return _(`/admin/datasets/${D}/ci`,{},!0)}async function j6(D){return _(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function Pz(D){return _(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function Iz(D){return _(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function Sp(D,F){return _(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function X$(D){return _(`/admin/datasets/${D}/doi`,{},!0)}async function Sz(D,F){return _(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function kp(D){return _(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function vp(D,F=!1){return _(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function yp(D){return _("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function xp(D){return _("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function _p(D){return _("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(D)},!0)}async function fp(D){return _(`/admin/datasets/${D}/exemplar/remint-dois`,{method:"POST"},!0)}async function bp(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return _(`/admin/imports${F}`,{},!0)}async function gp(D){return _(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function hp(D){return _(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function T5(D,F){return _(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function up(D,F){return _("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function mp(D){let F=D?.limit??15;return _(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function lp(){return _("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function pp(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 _(`/admin/fleet/drift${$}`,{},!0)}async function w5(D,F){return _(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function dp(D){return _("/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 cp(D,F=!1){return _(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function np(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return _(`/admin/email-preferences${F}`,{},!0)}async function ip(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return _(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function kz(D){return _("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ap(){return _("/admin/summary/coverage",{},!0)}async function op(D,F,$){return _("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var P5=P(()=>{I4()});async function o8(D,F){return _(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function vz(D,F){return _(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function sp(D){return _(`/admin/datasets/${D}/files`,{},!0)}async function rp(D){let F,$=0,Q=[],J=!0;while(J){let Y=await _(`/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)Q.push(...Y.failed);if(J=Y.hasMore,F=Y.continuation_token,J&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:Q}}var I5=P(()=>{I4();K1()});async function qX(D){return _(`/datasets/${D}/ci/status`,{},!0)}async function tp(D){return _(`/datasets/${D}/manifest`,{},!0)}async function KX(D,F){return _(`/datasets/${D}/manifest/${F}`,{},!0)}function ep(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 S5(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.hasHed)F.set("has_hed","1");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()}`:"",Q=await _(`/datasets${$}`,{},D.mine?!0:"optional");return Q.datasets=Q.datasets.map(ep),Q}async function Dd(D){return _(`/datasets/resolve/${D}`,{},"optional")}async function Fd(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));if(F.hasHed)$.set("has_hed","1");return _(`/datasets/search?${$.toString()}`,{},"optional")}async function ID(D){let F=await _(`/datasets/${D}`,{},"optional");return ep(F.dataset)}async function $d(D){return _(`/datasets/${D}/versions`,{},!0)}async function zX(D){return _("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function ZX(D){return _(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function yz(D){return _(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function Qd(D,F){let $=F?`?status=${F}`:"";return _(`/datasets/${D}/access-requests${$}`,{},!0)}async function Jd(D,F){return _(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Yd(D,F){return _(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Xd(D,F){return _(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Bd(D){return _(`/datasets/${D}/collaborators`,{},!0)}async function Gd(D,F){return _(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}var HX;var w3=P(()=>{I4();HX=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var k5;var zd=P(()=>{k5=["ci_check","enrichment_check","s3_public_read","repo_public","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"]});async function v5(D){return _(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Vd(D){return _(`/datasets/${D}/publish/status`,{},!0)}async function Ed(D){return _(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Ud(D){let F=D?`?status=${D}`:"";return _(`/admin/publish/requests${F}`,{},!0)}async function Ld(D,F){return _(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function yI0(D,F=[]){if(D){let $=k5.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,k5.length)}function xI0(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 y5(D,F=!1,$=!1,Q=!1,J,Y){let G,W,q=0,K=!1,Z,z=F,E=[],U;function M(A,N,O,T){if(!Y)return;Y({step:A,stepIndex:yI0(A,N),stepTotal:k5.length,s3LockLocked:O,s3LockTotal:T,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let N,O=!0;do{if(N=await _(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:O?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:W,skip_ci_check:Q})},!0),O=!1,N.step_results)E.push(...N.step_results);if(N.s3_lock_total!==void 0)W=N.s3_lock_total;if(N.s3_lock_batch_count!==void 0)q+=N.s3_lock_batch_count;let T=N.step??N.step_results?.[N.step_results.length-1]?.step;if(T&&(T!==Z||T==="s3_lock"))M(T,N.steps_completed??[],T==="s3_lock"?q:void 0,T==="s3_lock"?W:void 0),Z=T;if(N.hasMore&&N.s3_lock_continuation_token!==void 0)G=N.s3_lock_continuation_token;else break}while(N.hasMore);if(E.length>0)N.step_results=Zd(E);return N}catch(N){if(U=N,A===5||!xI0(N)){if(N instanceof f&&E.length>0)N.stepResults=Zd(E);throw N}let T=N;if(J?.({attempt:A,maxAttempts:5,delayMs:1e4,step:T.step,error:T.message}),await new Promise((C)=>setTimeout(C,1e4)),z=!0,G!==void 0)K=!0}throw U}function Zd(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}var B$=P(()=>{zd();I4();K1()});function Nd(D){_z=D}function fz(){return _z}function G$(D){if(_z)process.stderr.write(`${D}
|
|
105
|
+
`)}var Ap=!1;var Oz=P(()=>{t0()});var Cp;var Np=P(()=>{Cp={name:"nemar-cli",version:"0.9.1-PR965.36702c1",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",ajv:"^8.20.0","ajv-formats":"^3.0.1",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 j3;var WX=P(()=>{Np();j3=Cp.version});function $0(D){if(D instanceof Error)return D.message;return String(D)}var f,T3;var K1=P(()=>{f=class f extends Error{statusCode;details;step;constructor(D,F,$,Q){super(F);this.statusCode=D;this.details=$;this.step=Q;this.name="ApiError"}};T3=class T3 extends f{mode;eta;constructor(D,F,$,Q){super(503,F,Q);this.mode=D;this.eta=$;this.name="MaintenanceError"}}});function Rp(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(Tz)return jz;return KD().apiUrl||jz}async function _(D,F={},$=!1,Q){let J=`${Rp()}${D}`,Y={"Content-Type":"application/json","X-CLI-Version":j3,...F.headers};if($){let G=KD();if(!G.apiKey&&$===!0)throw new f(401,"Not authenticated. Run 'nemar auth login' first.");if(G.apiKey)Y.Authorization=`Bearer ${G.apiKey}`}let X;try{X=await fetch(J,{...F,headers:Y})}catch(G){throw new f(0,`Network error: Could not connect to ${Rp()}`,{originalError:G instanceof Error?G.message:String(G)})}let B;try{B=await X.json()}catch{throw new f(X.status,`Invalid response from server (status ${X.status})`)}if(!X.ok){if(X.status===503&&(B.mode==="read-only"||B.mode==="full")){let G=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",W=typeof B.eta==="string"?B.eta:null,q=new T3(B.mode,G,W,B.details);throw GX(q),q}throw new f(X.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}if(Q){let G=Q.safeParse(B);if(!G.success)throw new f(X.status,`Response for ${D} did not match the expected NEMAR contract`,{issues:G.error.issues});return G.data}return B}var jz="https://api.nemar.org",Tz;var I4=P(()=>{P4();Oz();WX();K1();Tz=jz.includes("workers.dev")});async function Op(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let Q=$.toString()?`?${$.toString()}`:"";return _(`/admin/users${Q}`,{},!0)}async function jp(D){return _(`/admin/approve/${D}`,{method:"POST"},!0)}async function Tp(D){return _(`/admin/revoke/${D}`,{method:"POST"},!0)}async function wp(D,F){return _(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function wz(D,F){return _(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Pp(D){return _(`/datasets/${D}/publish`,{method:"POST"},!0)}async function Ip(D){return _(`/admin/datasets/${D}/ci`,{},!0)}async function j6(D){return _(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function Pz(D){return _(`/admin/datasets/${D}/ci/validate`,{method:"POST"},!0)}async function Iz(D){return _(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function Sp(D,F){return _(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function X$(D){return _(`/admin/datasets/${D}/doi`,{},!0)}async function Sz(D,F){return _(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function kp(D){return _(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function vp(D,F=!1){return _(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function yp(D){return _("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function xp(D){return _("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function _p(D){return _("/admin/datasets/exemplar",{method:"POST",body:JSON.stringify(D)},!0)}async function fp(D){return _(`/admin/datasets/${D}/exemplar/remint-dois`,{method:"POST"},!0)}async function bp(D){let F=D?`?status=${encodeURIComponent(D)}`:"";return _(`/admin/imports${F}`,{},!0)}async function gp(D){return _(`/admin/imports/${D}/rollback`,{method:"POST"},!0)}async function hp(D){return _(`/admin/imports/${D}/retry`,{method:"POST"},!0)}async function T5(D,F){return _(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function up(D,F){return _("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function mp(D){let F=D?.limit??15;return _(`/admin/datasets/hed-sweep?limit=${encodeURIComponent(String(F))}`,{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function lp(){return _("/admin/datasets/hed-sweep?reset=1",{method:"POST",headers:{"Content-Type":"application/json"}},!0)}async function pp(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 _(`/admin/fleet/drift${$}`,{},!0)}async function w5(D,F){return _(`/admin/datasets/${D}/enforce`,{method:"POST",body:JSON.stringify({dry_run:F})},!0)}async function dp(D){return _("/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 cp(D,F=!1){return _(`/admin/datasets/${D}/revalidate${F?"?force=true":""}`,{method:"POST"},!0)}async function np(D){let F=D?`?user=${encodeURIComponent(D)}`:"";return _(`/admin/email-preferences${F}`,{},!0)}async function ip(D,F){let $=F?`?user=${encodeURIComponent(F)}`:"";return _(`/admin/email-preferences${$}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function kz(D){return _("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}async function ap(){return _("/admin/summary/coverage",{},!0)}async function op(D,F,$){return _("/admin/manifest/dispatch",{method:"POST",body:JSON.stringify({dataset_id:D,version:F,skip_canary:$?.skipCanary??!1})},!0)}var P5=P(()=>{I4()});async function o8(D,F){return _(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function vz(D,F){return _(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function sp(D){return _(`/admin/datasets/${D}/files`,{},!0)}async function rp(D){let F,$=0,Q=[],J=!0;while(J){let Y=await _(`/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)Q.push(...Y.failed);if(J=Y.hasMore,F=Y.continuation_token,J&&!F)throw new f(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:Q}}var I5=P(()=>{I4();K1()});async function qX(D){return _(`/datasets/${D}/ci/status`,{},!0)}async function tp(D){return _(`/datasets/${D}/manifest`,{},!0)}async function KX(D,F){return _(`/datasets/${D}/manifest/${F}`,{},!0)}function ep(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 S5(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.hasHed)F.set("has_hed","1");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()}`:"",Q=await _(`/datasets${$}`,{},D.mine?!0:"optional");return Q.datasets=Q.datasets.map(ep),Q}async function Dd(D){return _(`/datasets/resolve/${D}`,{},"optional")}async function Fd(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));if(F.hasHed)$.set("has_hed","1");return _(`/datasets/search?${$.toString()}`,{},"optional")}async function ID(D){let F=await _(`/datasets/${D}`,{},"optional");return ep(F.dataset)}async function $d(D){return _(`/datasets/${D}/versions`,{},!0)}async function zX(D){return _("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function ZX(D){return _(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function yz(D){return _(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function Qd(D,F){let $=F?`?status=${F}`:"";return _(`/datasets/${D}/access-requests${$}`,{},!0)}async function Jd(D,F){return _(`/datasets/${D}/access-requests/${F}/approve`,{method:"POST"},!0)}async function Yd(D,F){return _(`/datasets/${D}/access-requests/${F}/deny`,{method:"POST"},!0)}async function Xd(D,F){return _(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function Bd(D){return _(`/datasets/${D}/collaborators`,{},!0)}async function Gd(D,F){return _(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}var HX;var w3=P(()=>{I4();HX=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/});var k5;var zd=P(()=>{k5=["ci_check","enrichment_check","s3_public_read","repo_public","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"]});async function v5(D){return _(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function Vd(D){return _(`/datasets/${D}/publish/status`,{},!0)}async function Ed(D){return _(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function Ud(D){let F=D?`?status=${D}`:"";return _(`/admin/publish/requests${F}`,{},!0)}async function Ld(D,F){return _(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function yI0(D,F=[]){if(D){let $=k5.indexOf(D);if($>=0)return $+1}return Math.min(F.length+1,k5.length)}function xI0(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 y5(D,F=!1,$=!1,Q=!1,J,Y){let G,W,q=0,K=!1,Z,z=F,E=[],U;function M(A,N,O,T){if(!Y)return;Y({step:A,stepIndex:yI0(A,N),stepTotal:k5.length,s3LockLocked:O,s3LockTotal:T,s3LockResumed:A==="s3_lock"&&K?!0:void 0})}for(let A=1;A<=5;A++)try{let N,O=!0;do{if(N=await _(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:O?z:!0,sandbox:$,s3_lock_continuation_token:G,s3_lock_total:W,skip_ci_check:Q})},!0),O=!1,N.step_results)E.push(...N.step_results);if(N.s3_lock_total!==void 0)W=N.s3_lock_total;if(N.s3_lock_batch_count!==void 0)q+=N.s3_lock_batch_count;let T=N.step??N.step_results?.[N.step_results.length-1]?.step;if(T&&(T!==Z||T==="s3_lock"))M(T,N.steps_completed??[],T==="s3_lock"?q:void 0,T==="s3_lock"?W:void 0),Z=T;if(N.hasMore&&N.s3_lock_continuation_token!==void 0)G=N.s3_lock_continuation_token;else break}while(N.hasMore);if(E.length>0)N.step_results=Zd(E);return N}catch(N){if(U=N,A===5||!xI0(N)){if(N instanceof f&&E.length>0)N.stepResults=Zd(E);throw N}let T=N;if(J?.({attempt:A,maxAttempts:5,delayMs:1e4,step:T.step,error:T.message}),await new Promise((C)=>setTimeout(C,1e4)),z=!0,G!==void 0)K=!0}throw U}function Zd(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}var B$=P(()=>{zd();I4();K1()});function Nd(D){_z=D}function fz(){return _z}function G$(D){if(_z)process.stderr.write(`${D}
|
|
106
106
|
`)}var _z=!1;var Cd={};k6(Cd,{runCommand:()=>w});var{spawn:_I0}=globalThis.Bun;async function w(D,F={}){let $={...process.env,GIT_TERMINAL_PROMPT:"0",...F.env};for(let W of F.unsetEnv??[])delete $[W];let Q=_I0({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:$}),J=!1,Y;if(F.timeout)Y=setTimeout(()=>{J=!0,Q.kill()},F.timeout);if(fz()){let W=F.cwd?` (cwd=${F.cwd})`:"";G$(H.dim(`$ ${D.join(" ")}${W}`))}let X=await new Response(Q.stdout).text(),B=await new Response(Q.stderr).text(),G=await Q.exited;if(Y)clearTimeout(Y);if(fz()){if(X.trim())G$(H.dim(X.trimEnd()));if(B.trim())G$(H.yellow(B.trimEnd()));G$(H.dim(`(exit ${G})`))}if(J)return{stdout:X,stderr:B||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:G??1};return{stdout:X,stderr:B,exitCode:G}}var z1=P(()=>{t0()});async function fI0(){try{let{exitCode:D,stderr:F}=await w(["ssh","-T","-o","BatchMode=yes","-o","ConnectTimeout=5","git@github.com"]),$=F.includes("successfully authenticated");if(!$)console.warn("SSH test to github.com failed:",{exitCode:D,stderr:F.trim().slice(0,500)});return{works:$,error:$?void 0:F.trim().slice(0,500)}}catch(D){let F=D instanceof Error?D.message:String(D);return console.warn("SSH test exception:",F),{works:!1,error:F}}}async function W$(){try{let{stdout:D,exitCode:F,stderr:$}=await w(["gh","auth","token"]);if(F!==0)return console.warn("gh CLI returned non-zero exit code:",F),console.warn("stderr:",$),{token:null,error:`gh auth token failed: ${$.trim()||"unknown error"}`};if(!D.trim())return console.warn("gh auth token returned empty output"),{token:null,error:"gh CLI returned empty token"};return{token:D.trim()}}catch(D){let F=D instanceof Error?D.message:String(D);if(console.error("Failed to get GitHub token from gh CLI:",F),F.includes("ENOENT")||F.includes("not found"))return{token:null,error:"gh CLI not installed (command not found)"};return{token:null,error:`gh CLI error: ${F}`}}}async function VX(D){try{let{stdout:F,exitCode:$,stderr:Q}=await w(["gh","api","user","--jq",".login"]);if($!==0){if(Q.includes("not logged in")||Q.includes("auth login"))return{authenticated:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};return{authenticated:!1,error:`gh CLI error: ${Q.trim()||"unknown error"}`}}let J=F.trim();if(!J)return{authenticated:!1,error:"gh CLI returned empty username"};if(D){let Y=J.toLowerCase()===D.toLowerCase();return{authenticated:!0,username:J,matches:Y,error:Y?void 0:`gh CLI authenticated as '${J}', expected '${D}'`}}return{authenticated:!0,username:J}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return{authenticated:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{authenticated:!1,error:`Failed to verify gh CLI: ${$}`}}}async function EX(D){if(!/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(D))return{accepted:!1,error:`Invalid repository format: ${D}`};let{stdout:F,exitCode:$,stderr:Q}=await w(["gh","api","/user/repository_invitations"]);if($!==0){if(Q.includes("not logged in")||Q.includes("auth login"))return{accepted:!1,error:"gh CLI not authenticated. Run 'gh auth login' to authenticate."};if(Q.includes("API rate limit")||Q.includes("403"))return{accepted:!1,error:"GitHub API rate limit exceeded. Please try again in a few minutes."};if(Q.includes("ENOENT")||Q.includes("not found"))return{accepted:!1,error:"gh CLI not installed. Install from https://cli.github.com/"};return{accepted:!1,error:`Failed to list invitations: ${Q.trim()||"unknown error"}`}}let J=null;try{J=JSON.parse(F||"[]").find((W)=>W.repository.full_name===D)?.id??null}catch(B){let G=B instanceof Error?B.message:String(B);return console.error("Failed to parse GitHub invitations response:",G),console.error(" Raw response (first 500 chars):",(F||"").slice(0,500)),{accepted:!1,error:`Failed to parse GitHub API response: ${G}`}}if(!J){let{exitCode:B}=await w(["gh","api",`/repos/${D}`,"--silent"]);if(B===0)return{accepted:!0,alreadyCollaborator:!0};return{accepted:!1,error:`No pending invitation found for ${D}. You may need to accept it manually via GitHub.`}}let{exitCode:Y,stderr:X}=await w(["gh","api","--method","PATCH",`/user/repository_invitations/${J}`]);if(Y!==0)return{accepted:!1,error:`Failed to accept invitation: ${X.trim()||"unknown error"}`};return{accepted:!0}}async function s8(D,F,$="origin"){let Q=F;if(process.env.GH_TOKEN&&F.startsWith("git@github.com:")){let J=process.env.GH_TOKEN.trim();if(!J||/\s/.test(J))return{success:!1,error:"GH_TOKEN environment variable is set but appears malformed (empty or contains whitespace)"};Q=`https://github.com/${F.replace("git@github.com:","")}`,await w(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${J}'`],{cwd:D})}else if(F.startsWith("git@github.com:")){let J=F.replace("git@github.com:",""),Y=await W$();if(Y.token)Q=`https://github.com/${J}`,await w(["git","config","credential.https://github.com.helper",`!printf 'username=x-access-token\\npassword=${Y.token}'`],{cwd:D});else{let X=await fI0();if(X.works)Q=F;else return{success:!1,error:`GitHub authentication not configured.
|
|
107
107
|
|
|
108
108
|
gh CLI failed: ${Y.error||"could not get token"}
|
|
@@ -408,7 +408,7 @@ Import Jobs (${Q.total})
|
|
|
408
408
|
${G} of ${B.length} fleet entries failed`)),process.exit(1);return}if(!D)console.error(H.red("An xx-id argument is required unless --all is passed")),process.exit(1);if(!nS0.test(D))console.error(H.red(`Invalid exemplar id "${D}". Expected xx099900-xx099999.`)),process.exit(1);let X=F.source;if(!X)try{X=Q(J).find((G)=>G.xx_id===D)?.source_id}catch(B){console.error(H.red(`Failed to load fleet file: ${$0(B)}`)),process.exit(1)}if(!X)console.error(H.red(`No source dataset for ${D}. Pass --source <nm/on id> or add it to the fleet file.`)),process.exit(1);if(!iS0.test(X))console.error(H.red(`Invalid source id "${X}". Expected an nm/on dataset id.`)),process.exit(1);try{await $({xxId:D,sourceId:X,...Y})}catch(B){console.error(H.red(`
|
|
409
409
|
Exemplar clone failed: ${$0(B)}`)),process.exit(1)}});vX.command("status").description("Show which fleet entries have been cloned and their current state").option("--fleet-file <path>","Path to the fleet JSON (default: scripts/exemplar-fleet.json)").action(async(D)=>{if(!T0())return;let{loadExemplarFleet:F}=await Promise.resolve().then(() => (XZ(),YZ)),$=D.fleetFile||dc(),Q;try{Q=F($)}catch(J){console.error(H.red(`Failed to load fleet file: ${$0(J)}`)),process.exit(1)}console.log(H.bold(`
|
|
410
410
|
Exemplar Fleet (${Q.length})
|
|
411
|
-
`));for(let J of Q)try{let Y=await ID(J.xx_id);console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.green(Y.visibility)} doi=${Y.concept_doi??"none"}`)}catch(Y){if(Y instanceof f&&Y.statusCode===404)console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.dim("not created")}`);else console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.red(`status check failed (${$0(Y)})`)}`)}});vX.command("remint-dois").description("Re-mint an exemplar's sandbox concept DOI (idempotent)").argument("<xx-id>","Exemplar dataset id (e.g., xx099900)").action(async(D)=>{if(!T0())return;let F=R(`Re-minting DOIs for ${D}...`).start();try{let $=await fp(D);F.succeed(`Re-minted ${$.concept_doi} (status: ${$.status})`);for(let Q of $.warnings??[])console.log(H.yellow(` ${Q}`))}catch($){o0($,F,"Failed to re-mint exemplar DOIs",{400:"Not an exemplar dataset",403:"Exemplar DOI re-mint is disabled in production",404:"Dataset not found"}),process.exit(1)}});d0.addCommand(vX);function gc(D,F){let $=D.enrichment.status,Q=$==="ok"?H.green("enrich:ok"):$==="failed"?H.red("enrich:failed"):H.dim("enrich:skipped"),J=D.sync.status,Y=J==="ok"?H.green("sync:ok"):J==="failed"?H.red("sync:failed"):H.dim("sync:skipped"),X=D.sync.metadata_columns_written===!0?H.green("cols:written"):D.sync.metadata_columns_error?H.red("cols:failed"):"",B=F?.showRef&&D.enrichment.ref?H.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${Q}${B} ${Y} ${X}`),D.enrichment.error)console.log(H.red(` enrichment: ${D.enrichment.error}`));if(D.sync.metadata_columns_error)console.log(H.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var yX=new y0("fleet").description("Governance drift reporting and enforcement (epic #713)");yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);if(D.visibility&&!["public","private"].includes(D.visibility))console.log(H.red("Error: --visibility must be public or private")),process.exit(1);let F=R("Scanning fleet for drift...").start();try{let $=await pp({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(H.bold(`Fleet drift (scanned ${$.scanned}):`));let Q=["PUBLIC_UNPROTECTED","RED_REQUIRED_CHECK","CONTEXT_NAME_MISMATCH","MISSING_REQUIRED_WORKFLOW","PRIVATE_WITH_STRAY_READ","DEFAULT_BRANCH_OUTLIER","DEPRECATED_WORKFLOW_PRESENT","COMPLIANT"];for(let J of Q){let Y=$.buckets[J];if(!Y||Y.length===0)continue;let X=J==="COMPLIANT"?H.green:H.yellow;if(console.log(` ${X(J.padEnd(28))} ${Y.length}`),J!=="COMPLIANT"){let B=Y.slice(0,20).join(", ");console.log(H.dim(` ${B}${Y.length>20?` ... +${Y.length-20}`:""}`))}}console.log()}catch($){if($ instanceof f)F.fail($.message);else F.fail("Failed to scan fleet"),console.log(H.red(` ${$.message}`));process.exit(1)}});yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);if(!D&&!F.all)console.log(H.red("Error: provide a dataset-id or use --all")),process.exit(1);if(D&&F.all)console.log(H.red("Error: provide a dataset-id OR --all, not both")),process.exit(1);let $=!F.apply,Q=$?"[dry-run] ":"",J=R(`${Q}Enforcing spec...`).start();try{if(D){let Y=await w5(D,$);if(J.succeed(`${Q}${D} (${Y.result.visibility})`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let[X,B]of Object.entries(Y.result.steps)){let G=B.status==="ok"?H.green:B.status==="skipped"?H.yellow:H.red;console.log(` ${G(B.status.padEnd(8))} ${X}${B.detail?H.dim(` (${B.detail})`):""}`)}}else{let Y=await dp({prefix:F.prefix,visibility:F.visibility,limit:Number.parseInt(F.limit,10)||25,dryRun:$});if(J.succeed(`${Q}processed ${Y.count} repo(s)`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let X of Y.results){if(X.error){console.log(` ${H.red("error")} ${X.dataset_id}: ${X.error}`);continue}let B=Object.entries(X.steps??{}).filter(([,W])=>W.status!=="ok").map(([W,q])=>`${W}=${q.status}`),G=B.length?H.yellow("drift"):H.green("ok");console.log(` ${G} ${X.dataset_id}${B.length?H.dim(` (${B.join(", ")})`):""}`)}}}catch(Y){if(Y instanceof f)J.fail(Y.message);else J.fail("Enforcement failed"),console.log(H.red(` ${Y.message}`));process.exit(1)}});var IX=(D)=>new Promise((F)=>setTimeout(F,D));async function aS0(D,F,$){let Q=Date.now()+F,J="no probe completed";while(Date.now()<Q){try{let Y=(await w5(D,!0)).result?.steps?.branch_ruleset;if(Y?.status==="ok")return{status:"green"};if(Y?.detail)J=Y.detail}catch(Y){J=Y instanceof f?Y.message:String(Y)}await IX($)}return{status:"timeout",detail:J}}yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);let $=Boolean(F.all||!D&&F.prefix);if(!D&&!$)console.log(H.red("Error: provide a dataset-id, or --all/--prefix")),process.exit(1);let Q;if(D)Q=[D];else{let q=R("Fetching dataset list...").start();try{let K=[];for(let z=0;;z+=200){let E=await S5({limit:200,offset:z});if(K.push(...E.datasets),E.datasets.length<200||K.length>=E.total_count)break}let Z=Number.parseInt(F.limit,10)||25;Q=Ad(K,{prefix:F.prefix}).slice(0,Z),q.succeed(`${Q.length} target(s) (from ${K.length} datasets)`)}catch(K){o0(K,q,"Failed to fetch datasets");return}}let J=Boolean(F.enforce),Y=Boolean(F.apply),X={revalidated:0,green:0,locked:0,stillRed:0,skipped:0,errors:0},B=[],G=[],W=0;for(let q of Q){if(W++,xz.has(q)&&!F.force){console.log(` [${W}/${Q.length}] ${H.dim(`${q}: skip (live; use --force)`)}`),X.skipped++;continue}try{let K=await cp(q,F.force);if(B.push(K),K.skipped)console.log(` [${W}/${Q.length}] ${q}: ${H.dim(`skipped (${K.skipped})`)}`),X.skipped++;else X.revalidated++,G.push(q),console.log(` [${W}/${Q.length}] ${q}: ${H.cyan(`revalidating (${K.triggered_by})`)}`)}catch(K){X.errors++,console.log(` [${W}/${Q.length}] ${q}: ${H.red(K instanceof f?K.message:String(K))}`)}if(W<Q.length)await IX(4000)}if(J&&G.length>0)if(D){let q=G[0],K=R(`Waiting for ${q} validation to land...`).start(),Z=await aS0(q,300000,15000);if(Z.status!=="green")K.warn(`${q}: not green within 5m \u2014 last: ${Z.detail} (real errors or still running)`),X.stillRed++;else if(X.green++,!Y)K.succeed(`${q}: green (would lock; pass --apply)`);else{let z=await w5(q,!1);if(z.result?.steps?.branch_ruleset?.status==="ok")K.succeed(`${q}: LOCKED`),X.locked++;else K.warn(`${q}: enforce ${z.result?.steps?.branch_ruleset?.status??"?"}`)}}else{let q=R("Waiting ~90s for validations to drain...").start();await IX(90000),q.text="Enforcing green datasets...";for(let K of G)try{if((await w5(K,!0)).result?.steps?.branch_ruleset?.status!=="ok"){X.stillRed++;continue}if(X.green++,Y){if((await w5(K,!1)).result?.steps?.branch_ruleset?.status==="ok")X.locked++}}catch{X.errors++}q.stop()}if(F.json){console.log(JSON.stringify({tally:X,raw:B},null,2));return}console.log(),console.log(H.cyan(`Done: revalidated=${X.revalidated} green=${X.green} locked=${X.locked} still-red=${X.stillRed} skipped=${X.skipped} errors=${X.errors}`))});d0.addCommand(yX);var cc=new y0("reindex").description("Refresh dataset metadata: enrichment + nemar.org sync + first-class D1 columns");cc.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(H.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(H.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(H.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(H.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=R(`Reindexing ${D}...`).start();try{let Z={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},z=await T5(D,Z),E=z.enrichment.status!=="failed"&&z.sync.status!=="failed";if(E)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),gc(z,{showRef:!0}),!E)process.exit(1)}catch(Z){K.fail(`Failed to reindex ${D}`),console.error(H.red($0(Z))),process.exit(1)}return}let Q=F.all?"all":F.missingMetadata?"missing-metadata":"stale",J={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(H.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);J.older_than_days=K}else if(Q==="missing-metadata")J.older_than_days=1;else if(Q==="stale")J.older_than_days=30;let Y=F.dryRun?`Listing ${Q} datasets...`:`Reindexing ${Q} datasets...`,X=R(Y).start(),B;try{B=await up(Q,J)}catch(K){X.fail("Bulk reindex failed"),console.error(H.red($0(K))),process.exit(1)}if(B.dry_run){if(X.succeed(`${B.total} datasets match filter=${Q} (dry run, no changes)`),B.datasets)for(let K of B.datasets)console.log(H.dim(` - ${K}`));return}let G=B.results??[],W=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-W;if(q===0)X.succeed(`${G.length}/${G.length} datasets reindexed in ${(B.elapsed_ms/1000).toFixed(1)}s`);else X.warn(`${W}/${G.length} ok; ${q} failed in ${(B.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)gc(K);if(q>0)process.exit(1)});d0.addCommand(cc);var nc=new y0("hed-sweep").description("Backfill HED detection (has_hed / hed_version) for existing datasets (#869)");nc.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 B=R("Resetting HED sweep state...").start();try{let G=await lp();if(B.succeed(`Cleared ${G.reset} probed HED row(s); eligible datasets are candidates again`),D.json)console.log(JSON.stringify(G,null,2))}catch(G){B.fail("Reset failed"),console.error(H.red($0(G))),process.exit(1)}return}let F=Number.parseInt(D.limit??"15",10)||15,$={processed:0,withHed:0,withoutHed:0,unknown:0,errors:0},Q=R("Sweeping datasets for HED...").start(),J=0,Y=null,X=null;try{let B;do{if(B=await mp({limit:F}),J++,$.processed+=B.processed,$.withHed+=B.withHed,$.withoutHed+=B.withoutHed,$.unknown+=B.unknown,$.errors+=B.errors.length,Y=B.remaining,D.verbose){Q.stop(),console.log(` [batch ${J}] processed=${B.processed} hed=${B.withHed} no-hed=${B.withoutHed} unknown=${B.unknown} errors=${B.errors.length} remaining=${Y??"?"}`);for(let G of B.errors)console.log(` ${H.red(G.dataset_id)}: ${G.error}`);Q.start("Sweeping datasets for HED...")}else Q.text=`Sweeping datasets for HED... ${$.processed} processed, ${Y??"?"} remaining`;if(Y!=null&&X!=null&&Y>=X){Q.warn(`No progress (remaining stuck at ${Y}); stopping - see errors`);break}if(X=Y,(Y??0)>0)await IX(1000)}while((Y??0)>0);Q.stop()}catch(B){Q.fail("HED sweep failed"),console.error(H.red($0(B))),process.exit(1)}if(D.json)console.log(JSON.stringify({...$,batches:J,remaining:Y},null,2));else{if(console.log(),Y===null)console.log(H.yellow("Warning: backend returned a null remaining count; the sweep may be incomplete - check server logs."));console.log(H.cyan(`Done in ${J} batch(es): processed=${$.processed} hed=${$.withHed} no-hed=${$.withoutHed} unknown=${$.unknown} errors=${$.errors} remaining=${Y??"unknown"}`))}if($.errors>0||Y===null)process.exit(1)});d0.addCommand(nc);var WZ=new y0("email-preferences").description("Manage email notification preferences");WZ.command("show").description("Show email notification preferences").option("--user <username>","(owner only) show another user's preferences").action(async(D)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let F=R("Fetching email preferences...").start();try{let $=await np(D.user),Q=$.username?`${$.username}'s`:"Your";F.succeed(`${Q} email notification preferences:`),console.log();let J=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let Y of J){let B=$[Y.key]?H.green("enabled"):H.dim("disabled");console.log(` ${Y.label.padEnd(40)} ${B}`)}console.log(),console.log(H.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch($){F.fail("Failed to fetch preferences"),console.error(H.red($0($)))}});WZ.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(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(J){if(J===void 0)return;let Y=J.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(H.red(`Invalid boolean value: "${J}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let J=F(D.all);$.user_approval=J,$.publication_request=J,$.announcements=J}else{let J=F(D.userApproval),Y=F(D.publicationRequest),X=F(D.announcements);if(J===void 0&&Y===void 0&&X===void 0)console.error(H.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(J!==void 0)$.user_approval=J;if(Y!==void 0)$.publication_request=Y;if(X!==void 0)$.announcements=X}let Q=R("Updating email preferences...").start();try{let J=await ip($,D.user),Y=J.username?`${J.username}'s`:"Your";Q.succeed(`${Y} email preferences updated:`),console.log(),console.log(` User approval: ${J.user_approval?H.green("enabled"):H.dim("disabled")}`),console.log(` Publication request: ${J.publication_request?H.green("enabled"):H.dim("disabled")}`),console.log(` Announcements: ${J.announcements?H.green("enabled"):H.dim("disabled")}`)}catch(J){Q.fail("Failed to update preferences"),console.error(H.red($0(J)))}});d0.addCommand(WZ);var xX=new y0("notice").description("Manage system notices displayed to CLI users");xX.command("list").description("List all notices (including expired)").action(async()=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=R("Fetching notices...").start();try{let{notices:F}=await Hd();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let J={critical:H.red.bold,warning:H.yellow,info:H.blue}[$.level]||H.white,Y=$.expires_at&&new Date($.expires_at)<new Date?H.dim(" (expired)"):"";if(console.log(` ${H.dim(`#${$.id}`)} ${J(`[${$.level.toUpperCase()}]`)} ${H.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${H.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${H.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){o0(F,D,"Failed to fetch notices")}});xX.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(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(H.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(H.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=R("Creating notice...").start();try{let $=await qd({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($){o0($,F,"Failed to create notice")}});xX.command("clear <id>").description("Delete a notice by ID").option(k0,v0).option(p0,g0).action(async(D,F)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(H.red("Invalid notice ID")),process.exit(1);if(!await x0(`Delete notice #${$}?`,F,!1))return;let J=R("Deleting notice...").start();try{await Kd($),J.succeed(`Notice #${$} deleted`)}catch(Y){o0(Y,J,"Failed to delete notice")}});d0.addCommand(xX);d0.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(k0,v0).option(p0,g0).action(async(D)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(D.to&&D.user)console.error(H.red("--to and --user are mutually exclusive. Provide exactly one.")),process.exit(1);if(!D.to&&!D.user)console.error(H.red("Provide either --to <group> or --user <username>.")),process.exit(1);if(D.to&&!["all","admins","members"].includes(D.to))console.error(H.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!uc(D.bodyFile))console.error(H.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=dS0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(H.red("Email body required. Use --body or --body-file.")),process.exit(1);let $=D.user?`user:${D.user}`:D.to,Q=D.user?{user:D.user,subject:D.subject,body:F}:{to:D.to,subject:D.subject,body:F};if(D.dryRun){let B=R("Checking recipients...").start();try{let G=await kz({...Q,dry_run:!0});if("dry_run"in G){B.succeed(`Dry run: ${G.recipient_count} recipient(s) for "${G.recipient_group}"`),console.log();for(let W of G.recipients)console.log(` ${W}`)}}catch(G){o0(G,B,"Failed to check recipients")}return}console.log(H.bold("Email preview:")),console.log(` To: ${H.cyan($)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log();let J=D.user?`Send this email to ${D.user}?`:"Send this broadcast email?";if(!await x0(J,D,!1))return;let X=R(D.user?`Sending to ${D.user}...`:"Sending broadcast...").start();try{let B=await kz(Q);if("broadcast_id"in B)if(B.failure_count>0){X.warn(`Email send: ${B.recipient_count} delivered, ${B.failure_count} failed`);for(let G of B.failed_recipients)console.log(H.red(` Failed: ${G}`))}else{let G=D.user?`Email sent to ${D.user}`:`Broadcast sent to ${B.recipient_count} recipient(s)`;X.succeed(`${G} (ID: ${B.broadcast_id})`)}}catch(B){o0(B,X,"Failed to send email")}});var oS0=1500;function sS0(D){switch(D.kind){case"ok":return H.green(`ok ${D.schema_version}`);case"stale":return H.yellow(`stale ${D.schema_version}`);case"missing":return H.red("missing");case"error":return H.red(`error ${D.status||"?"}: ${D.message}`)}}function rS0(D){return D.kind==="stale"||D.kind==="missing"}function tS0(D){let $=D.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${$}$`)}var ic=new y0("summary").description("summary.json coverage across published dataset versions");ic.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(k0,v0).option(p0,g0).action(async(D)=>{if(!T0())return;let F=R("Building coverage report...").start(),$;try{$=await ap()}catch(Z){o0(Z,F,"Failed to fetch coverage report");return}F.succeed(`Coverage: target=schema ${$.target_schema}, versions=${$.totals.versions}`);let Q=$.versions,J=null;if(D.id){if(Q=Q.filter((Z)=>Z.dataset_id===D.id),J=`dataset_id=${D.id}`,Q.length===0){console.log(H.yellow(`No rows for ${J}`));return}}else if(D.match){let Z=tS0(D.match);if(Q=Q.filter((z)=>Z.test(z.dataset_id)),J=`--match ${D.match}`,Q.length===0){console.log(H.yellow(`No rows match ${J}`));return}console.log(H.dim(`Scoped to ${Q.length} version(s) matching ${D.match}`))}if(D.json){console.log(JSON.stringify(J?{...$,versions:Q,totals:hc(Q)}:$,null,2));return}let Y=D.onlyStale?Q.filter((Z)=>Z.state.kind!=="ok"):Q;if(Y.length===0)console.log(H.green("All versions at target schema \u2014 no drift."));else{let Z=Math.max(...Y.map((E)=>E.dataset_id.length),10),z=Math.max(...Y.map((E)=>E.version.length),7);for(let E of Y)console.log(` ${E.dataset_id.padEnd(Z)} ${E.version.padEnd(z)} ${sS0(E.state)}`)}let X=J?hc(Q):$.totals;if(console.log(),console.log(` Total: ${X.versions} ${H.green(`ok=${X.ok}`)} ${H.yellow(`stale=${X.stale}`)} ${H.red(`missing=${X.missing}`)} ${H.red(`error=${X.error}`)}`),!D.fix){if(X.stale+X.missing>0)console.log(H.dim(`
|
|
411
|
+
`));for(let J of Q)try{let Y=await ID(J.xx_id);console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.green(Y.visibility)} doi=${Y.concept_doi??"none"}`)}catch(Y){if(Y instanceof f&&Y.statusCode===404)console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.dim("not created")}`);else console.log(` ${J.xx_id.padEnd(10)} ${J.modality.padEnd(6)} <- ${J.source_id.padEnd(10)} ${H.red(`status check failed (${$0(Y)})`)}`)}});vX.command("remint-dois").description("Re-mint an exemplar's sandbox concept DOI (idempotent)").argument("<xx-id>","Exemplar dataset id (e.g., xx099900)").action(async(D)=>{if(!T0())return;let F=R(`Re-minting DOIs for ${D}...`).start();try{let $=await fp(D);F.succeed(`Re-minted ${$.concept_doi} (status: ${$.status})`);for(let Q of $.warnings??[])console.log(H.yellow(` ${Q}`))}catch($){o0($,F,"Failed to re-mint exemplar DOIs",{400:"Not an exemplar dataset",403:"Exemplar DOI re-mint is disabled in production",404:"Dataset not found"}),process.exit(1)}});d0.addCommand(vX);function gc(D,F){let $=D.enrichment.status,Q=$==="ok"?H.green("enrich:ok"):$==="failed"?H.red("enrich:failed"):H.dim("enrich:skipped"),J=D.sync.status,Y=J==="ok"?H.green("sync:ok"):J==="failed"?H.red("sync:failed"):H.dim("sync:skipped"),X=D.sync.metadata_columns_written===!0?H.green("cols:written"):D.sync.metadata_columns_error?H.red("cols:failed"):"",B=F?.showRef&&D.enrichment.ref?H.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${Q}${B} ${Y} ${X}`),D.enrichment.error)console.log(H.red(` enrichment: ${D.enrichment.error}`));if(D.sync.metadata_columns_error)console.log(H.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var yX=new y0("fleet").description("Governance drift reporting and enforcement (epic #713)");yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);if(D.visibility&&!["public","private"].includes(D.visibility))console.log(H.red("Error: --visibility must be public or private")),process.exit(1);let F=R("Scanning fleet for drift...").start();try{let $=await pp({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(H.bold(`Fleet drift (scanned ${$.scanned}):`));let Q=["PUBLIC_UNPROTECTED","RED_REQUIRED_CHECK","CONTEXT_NAME_MISMATCH","MISSING_REQUIRED_WORKFLOW","PRIVATE_WITH_STRAY_READ","DEFAULT_BRANCH_OUTLIER","DEPRECATED_WORKFLOW_PRESENT","COMPLIANT"];for(let J of Q){let Y=$.buckets[J];if(!Y||Y.length===0)continue;let X=J==="COMPLIANT"?H.green:H.yellow;if(console.log(` ${X(J.padEnd(28))} ${Y.length}`),J!=="COMPLIANT"){let B=Y.slice(0,20).join(", ");console.log(H.dim(` ${B}${Y.length>20?` ... +${Y.length-20}`:""}`))}}console.log()}catch($){if($ instanceof f)F.fail($.message);else F.fail("Failed to scan fleet"),console.log(H.red(` ${$.message}`));process.exit(1)}});yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);if(!D&&!F.all)console.log(H.red("Error: provide a dataset-id or use --all")),process.exit(1);if(D&&F.all)console.log(H.red("Error: provide a dataset-id OR --all, not both")),process.exit(1);let $=!F.apply,Q=$?"[dry-run] ":"",J=R(`${Q}Enforcing spec...`).start();try{if(D){let Y=await w5(D,$);if(J.succeed(`${Q}${D} (${Y.result.visibility})`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let[X,B]of Object.entries(Y.result.steps)){let G=B.status==="ok"?H.green:B.status==="skipped"?H.yellow:H.red;console.log(` ${G(B.status.padEnd(8))} ${X}${B.detail?H.dim(` (${B.detail})`):""}`)}}else{let Y=await dp({prefix:F.prefix,visibility:F.visibility,limit:Number.parseInt(F.limit,10)||25,dryRun:$});if(J.succeed(`${Q}processed ${Y.count} repo(s)`),F.json){console.log(JSON.stringify(Y,null,2));return}for(let X of Y.results){if(X.error){console.log(` ${H.red("error")} ${X.dataset_id}: ${X.error}`);continue}let B=Object.entries(X.steps??{}).filter(([,W])=>W.status!=="ok").map(([W,q])=>`${W}=${q.status}`),G=B.length?H.yellow("drift"):H.green("ok");console.log(` ${G} ${X.dataset_id}${B.length?H.dim(` (${B.join(", ")})`):""}`)}}}catch(Y){if(Y instanceof f)J.fail(Y.message);else J.fail("Enforcement failed"),console.log(H.red(` ${Y.message}`));process.exit(1)}});var IX=(D)=>new Promise((F)=>setTimeout(F,D));async function aS0(D,F,$){let Q=Date.now()+F,J="no probe completed";while(Date.now()<Q){try{let Y=(await w5(D,!0)).result?.steps?.branch_ruleset;if(Y?.status==="ok")return{status:"green"};if(Y?.detail)J=Y.detail}catch(Y){J=Y instanceof f?Y.message:String(Y)}await IX($)}return{status:"timeout",detail:J}}yX.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(!b0())console.log(H.red("Error: Not authenticated")),process.exit(1);let $=Boolean(F.all||!D&&F.prefix);if(!D&&!$)console.log(H.red("Error: provide a dataset-id, or --all/--prefix")),process.exit(1);let Q;if(D)Q=[D];else{let q=R("Fetching dataset list...").start();try{let K=[];for(let z=0;;z+=200){let E=await S5({limit:200,offset:z});if(K.push(...E.datasets),E.datasets.length<200||K.length>=E.total_count)break}let Z=Number.parseInt(F.limit,10)||25;Q=Ad(K,{prefix:F.prefix}).slice(0,Z),q.succeed(`${Q.length} target(s) (from ${K.length} datasets)`)}catch(K){o0(K,q,"Failed to fetch datasets");return}}let J=Boolean(F.enforce),Y=Boolean(F.apply),X={revalidated:0,green:0,locked:0,stillRed:0,skipped:0,errors:0},B=[],G=[],W=0;for(let q of Q){if(W++,xz.has(q)&&!F.force){console.log(` [${W}/${Q.length}] ${H.dim(`${q}: skip (live; use --force)`)}`),X.skipped++;continue}try{let K=await cp(q,F.force);if(B.push(K),K.skipped)console.log(` [${W}/${Q.length}] ${q}: ${H.dim(`skipped (${K.skipped})`)}`),X.skipped++;else X.revalidated++,G.push(q),console.log(` [${W}/${Q.length}] ${q}: ${H.cyan(`revalidating (${K.triggered_by})`)}`)}catch(K){X.errors++,console.log(` [${W}/${Q.length}] ${q}: ${H.red(K instanceof f?K.message:String(K))}`)}if(W<Q.length)await IX(4000)}if(J&&G.length>0)if(D){let q=G[0],K=R(`Waiting for ${q} validation to land...`).start(),Z=await aS0(q,300000,15000);if(Z.status!=="green")K.warn(`${q}: not green within 5m \u2014 last: ${Z.detail} (real errors or still running)`),X.stillRed++;else if(X.green++,!Y)K.succeed(`${q}: green (would lock; pass --apply)`);else{let z=await w5(q,!1);if(z.result?.steps?.branch_ruleset?.status==="ok")K.succeed(`${q}: LOCKED`),X.locked++;else K.warn(`${q}: enforce ${z.result?.steps?.branch_ruleset?.status??"?"}`)}}else{let q=R("Waiting ~90s for validations to drain...").start();await IX(90000),q.text="Enforcing green datasets...";for(let K of G)try{if((await w5(K,!0)).result?.steps?.branch_ruleset?.status!=="ok"){X.stillRed++;continue}if(X.green++,Y){if((await w5(K,!1)).result?.steps?.branch_ruleset?.status==="ok")X.locked++}}catch{X.errors++}q.stop()}if(F.json){console.log(JSON.stringify({tally:X,raw:B},null,2));return}console.log(),console.log(H.cyan(`Done: revalidated=${X.revalidated} green=${X.green} locked=${X.locked} still-red=${X.stillRed} skipped=${X.skipped} errors=${X.errors}`))});d0.addCommand(yX);var cc=new y0("reindex").description("Refresh dataset metadata: enrichment + first-class D1 columns");cc.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 D1 metadata-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(H.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(H.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(H.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(H.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=R(`Reindexing ${D}...`).start();try{let Z={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},z=await T5(D,Z),E=z.enrichment.status!=="failed"&&z.sync.status!=="failed";if(E)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),gc(z,{showRef:!0}),!E)process.exit(1)}catch(Z){K.fail(`Failed to reindex ${D}`),console.error(H.red($0(Z))),process.exit(1)}return}let Q=F.all?"all":F.missingMetadata?"missing-metadata":"stale",J={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(H.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);J.older_than_days=K}else if(Q==="missing-metadata")J.older_than_days=1;else if(Q==="stale")J.older_than_days=30;let Y=F.dryRun?`Listing ${Q} datasets...`:`Reindexing ${Q} datasets...`,X=R(Y).start(),B;try{B=await up(Q,J)}catch(K){X.fail("Bulk reindex failed"),console.error(H.red($0(K))),process.exit(1)}if(B.dry_run){if(X.succeed(`${B.total} datasets match filter=${Q} (dry run, no changes)`),B.datasets)for(let K of B.datasets)console.log(H.dim(` - ${K}`));return}let G=B.results??[],W=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-W;if(q===0)X.succeed(`${G.length}/${G.length} datasets reindexed in ${(B.elapsed_ms/1000).toFixed(1)}s`);else X.warn(`${W}/${G.length} ok; ${q} failed in ${(B.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)gc(K);if(q>0)process.exit(1)});d0.addCommand(cc);var nc=new y0("hed-sweep").description("Backfill HED detection (has_hed / hed_version) for existing datasets (#869)");nc.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 B=R("Resetting HED sweep state...").start();try{let G=await lp();if(B.succeed(`Cleared ${G.reset} probed HED row(s); eligible datasets are candidates again`),D.json)console.log(JSON.stringify(G,null,2))}catch(G){B.fail("Reset failed"),console.error(H.red($0(G))),process.exit(1)}return}let F=Number.parseInt(D.limit??"15",10)||15,$={processed:0,withHed:0,withoutHed:0,unknown:0,errors:0},Q=R("Sweeping datasets for HED...").start(),J=0,Y=null,X=null;try{let B;do{if(B=await mp({limit:F}),J++,$.processed+=B.processed,$.withHed+=B.withHed,$.withoutHed+=B.withoutHed,$.unknown+=B.unknown,$.errors+=B.errors.length,Y=B.remaining,D.verbose){Q.stop(),console.log(` [batch ${J}] processed=${B.processed} hed=${B.withHed} no-hed=${B.withoutHed} unknown=${B.unknown} errors=${B.errors.length} remaining=${Y??"?"}`);for(let G of B.errors)console.log(` ${H.red(G.dataset_id)}: ${G.error}`);Q.start("Sweeping datasets for HED...")}else Q.text=`Sweeping datasets for HED... ${$.processed} processed, ${Y??"?"} remaining`;if(Y!=null&&X!=null&&Y>=X){Q.warn(`No progress (remaining stuck at ${Y}); stopping - see errors`);break}if(X=Y,(Y??0)>0)await IX(1000)}while((Y??0)>0);Q.stop()}catch(B){Q.fail("HED sweep failed"),console.error(H.red($0(B))),process.exit(1)}if(D.json)console.log(JSON.stringify({...$,batches:J,remaining:Y},null,2));else{if(console.log(),Y===null)console.log(H.yellow("Warning: backend returned a null remaining count; the sweep may be incomplete - check server logs."));console.log(H.cyan(`Done in ${J} batch(es): processed=${$.processed} hed=${$.withHed} no-hed=${$.withoutHed} unknown=${$.unknown} errors=${$.errors} remaining=${Y??"unknown"}`))}if($.errors>0||Y===null)process.exit(1)});d0.addCommand(nc);var WZ=new y0("email-preferences").description("Manage email notification preferences");WZ.command("show").description("Show email notification preferences").option("--user <username>","(owner only) show another user's preferences").action(async(D)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let F=R("Fetching email preferences...").start();try{let $=await np(D.user),Q=$.username?`${$.username}'s`:"Your";F.succeed(`${Q} email notification preferences:`),console.log();let J=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let Y of J){let B=$[Y.key]?H.green("enabled"):H.dim("disabled");console.log(` ${Y.label.padEnd(40)} ${B}`)}console.log(),console.log(H.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch($){F.fail("Failed to fetch preferences"),console.error(H.red($0($)))}});WZ.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(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(J){if(J===void 0)return;let Y=J.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(H.red(`Invalid boolean value: "${J}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let J=F(D.all);$.user_approval=J,$.publication_request=J,$.announcements=J}else{let J=F(D.userApproval),Y=F(D.publicationRequest),X=F(D.announcements);if(J===void 0&&Y===void 0&&X===void 0)console.error(H.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(J!==void 0)$.user_approval=J;if(Y!==void 0)$.publication_request=Y;if(X!==void 0)$.announcements=X}let Q=R("Updating email preferences...").start();try{let J=await ip($,D.user),Y=J.username?`${J.username}'s`:"Your";Q.succeed(`${Y} email preferences updated:`),console.log(),console.log(` User approval: ${J.user_approval?H.green("enabled"):H.dim("disabled")}`),console.log(` Publication request: ${J.publication_request?H.green("enabled"):H.dim("disabled")}`),console.log(` Announcements: ${J.announcements?H.green("enabled"):H.dim("disabled")}`)}catch(J){Q.fail("Failed to update preferences"),console.error(H.red($0(J)))}});d0.addCommand(WZ);var xX=new y0("notice").description("Manage system notices displayed to CLI users");xX.command("list").description("List all notices (including expired)").action(async()=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=R("Fetching notices...").start();try{let{notices:F}=await Hd();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let J={critical:H.red.bold,warning:H.yellow,info:H.blue}[$.level]||H.white,Y=$.expires_at&&new Date($.expires_at)<new Date?H.dim(" (expired)"):"";if(console.log(` ${H.dim(`#${$.id}`)} ${J(`[${$.level.toUpperCase()}]`)} ${H.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${H.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${H.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){o0(F,D,"Failed to fetch notices")}});xX.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(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(H.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(H.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=R("Creating notice...").start();try{let $=await qd({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($){o0($,F,"Failed to create notice")}});xX.command("clear <id>").description("Delete a notice by ID").option(k0,v0).option(p0,g0).action(async(D,F)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(H.red("Invalid notice ID")),process.exit(1);if(!await x0(`Delete notice #${$}?`,F,!1))return;let J=R("Deleting notice...").start();try{await Kd($),J.succeed(`Notice #${$} deleted`)}catch(Y){o0(Y,J,"Failed to delete notice")}});d0.addCommand(xX);d0.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(k0,v0).option(p0,g0).action(async(D)=>{if(!b0())console.error(H.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(D.to&&D.user)console.error(H.red("--to and --user are mutually exclusive. Provide exactly one.")),process.exit(1);if(!D.to&&!D.user)console.error(H.red("Provide either --to <group> or --user <username>.")),process.exit(1);if(D.to&&!["all","admins","members"].includes(D.to))console.error(H.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!uc(D.bodyFile))console.error(H.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=dS0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(H.red("Email body required. Use --body or --body-file.")),process.exit(1);let $=D.user?`user:${D.user}`:D.to,Q=D.user?{user:D.user,subject:D.subject,body:F}:{to:D.to,subject:D.subject,body:F};if(D.dryRun){let B=R("Checking recipients...").start();try{let G=await kz({...Q,dry_run:!0});if("dry_run"in G){B.succeed(`Dry run: ${G.recipient_count} recipient(s) for "${G.recipient_group}"`),console.log();for(let W of G.recipients)console.log(` ${W}`)}}catch(G){o0(G,B,"Failed to check recipients")}return}console.log(H.bold("Email preview:")),console.log(` To: ${H.cyan($)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log();let J=D.user?`Send this email to ${D.user}?`:"Send this broadcast email?";if(!await x0(J,D,!1))return;let X=R(D.user?`Sending to ${D.user}...`:"Sending broadcast...").start();try{let B=await kz(Q);if("broadcast_id"in B)if(B.failure_count>0){X.warn(`Email send: ${B.recipient_count} delivered, ${B.failure_count} failed`);for(let G of B.failed_recipients)console.log(H.red(` Failed: ${G}`))}else{let G=D.user?`Email sent to ${D.user}`:`Broadcast sent to ${B.recipient_count} recipient(s)`;X.succeed(`${G} (ID: ${B.broadcast_id})`)}}catch(B){o0(B,X,"Failed to send email")}});var oS0=1500;function sS0(D){switch(D.kind){case"ok":return H.green(`ok ${D.schema_version}`);case"stale":return H.yellow(`stale ${D.schema_version}`);case"missing":return H.red("missing");case"error":return H.red(`error ${D.status||"?"}: ${D.message}`)}}function rS0(D){return D.kind==="stale"||D.kind==="missing"}function tS0(D){let $=D.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${$}$`)}var ic=new y0("summary").description("summary.json coverage across published dataset versions");ic.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(k0,v0).option(p0,g0).action(async(D)=>{if(!T0())return;let F=R("Building coverage report...").start(),$;try{$=await ap()}catch(Z){o0(Z,F,"Failed to fetch coverage report");return}F.succeed(`Coverage: target=schema ${$.target_schema}, versions=${$.totals.versions}`);let Q=$.versions,J=null;if(D.id){if(Q=Q.filter((Z)=>Z.dataset_id===D.id),J=`dataset_id=${D.id}`,Q.length===0){console.log(H.yellow(`No rows for ${J}`));return}}else if(D.match){let Z=tS0(D.match);if(Q=Q.filter((z)=>Z.test(z.dataset_id)),J=`--match ${D.match}`,Q.length===0){console.log(H.yellow(`No rows match ${J}`));return}console.log(H.dim(`Scoped to ${Q.length} version(s) matching ${D.match}`))}if(D.json){console.log(JSON.stringify(J?{...$,versions:Q,totals:hc(Q)}:$,null,2));return}let Y=D.onlyStale?Q.filter((Z)=>Z.state.kind!=="ok"):Q;if(Y.length===0)console.log(H.green("All versions at target schema \u2014 no drift."));else{let Z=Math.max(...Y.map((E)=>E.dataset_id.length),10),z=Math.max(...Y.map((E)=>E.version.length),7);for(let E of Y)console.log(` ${E.dataset_id.padEnd(Z)} ${E.version.padEnd(z)} ${sS0(E.state)}`)}let X=J?hc(Q):$.totals;if(console.log(),console.log(` Total: ${X.versions} ${H.green(`ok=${X.ok}`)} ${H.yellow(`stale=${X.stale}`)} ${H.red(`missing=${X.missing}`)} ${H.red(`error=${X.error}`)}`),!D.fix){if(X.stale+X.missing>0)console.log(H.dim(`
|
|
412
412
|
Run with --fix to dispatch generate-manifest for the ${X.stale+X.missing} drifted version(s).`));return}let B=Q.filter((Z)=>rS0(Z.state));if(B.length===0){console.log(H.green(`
|
|
413
413
|
Nothing to dispatch.`));return}let G=J?` (scoped to ${J})`:"",W=await x0(`Dispatch generate-manifest for ${B.length} version(s)${G}? Each dispatch queues a runner job on nemarDatasets/.github.`,D);if(W!=="confirmed"){console.log(H.dim(W==="declined"?"Skipped":"Cancelled"));return}let q=0,K=0;console.log();for(let[Z,z]of B.entries()){let E=`${z.dataset_id}@${z.version}`,U=R(`[${Z+1}/${B.length}] dispatching ${E}...`).start();try{await op(z.dataset_id,z.version),U.succeed(`[${Z+1}/${B.length}] dispatched ${E}`),q++}catch(M){U.fail(`[${Z+1}/${B.length}] ${E}: ${$0(M)}`),K++}if(Z<B.length-1)await new Promise((M)=>setTimeout(M,oS0))}if(console.log(),console.log(K===0?H.green(`All ${q} dispatches succeeded.`):H.yellow(`${q} succeeded, ${K} failed.`)),console.log(H.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 hc(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}}d0.addCommand(ic);t0();z6();D8();J$();var eS0=/^v?\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/,Dk0=/^v\d+\.\d+\.\d+(?:-(?:rc|alpha|beta)\d*)?$/;function Fk0(D){return D.startsWith("v")?D:`v${D}`}var ac=I.string().regex(eS0,"must be a semver version, optionally v-prefixed").transform(Fk0),hs0=I.string().regex(Dk0,"must be the canonical v-prefixed tag (vX.Y.Z)");J$();var $k0=I.object({id:I.number().int(),username:I.string().nullable(),email:I.string(),github_username:I.string().nullable(),role:I.string(),orcid:I.string().nullable().optional(),created_at:I.string().optional(),approved_at:I.string().nullable().optional(),dataset_count:I.number().int().optional(),sandbox_completed:I.boolean().optional(),sandbox_completed_at:I.string().nullable().optional(),sandbox_dataset_id:I.string().nullable().optional()}).passthrough(),Qk0=I.object({prefix:I.string(),created_at:I.string(),last_used_at:I.string().nullable()}).passthrough().nullable(),oc=I.object({user:$k0,token:Qk0.optional()}).passthrough();J$();var Jk0="0.3.0",Yk0=I.enum(["openneuro","nemar","gin","other"]),sc=I.union([I.literal(0),I.literal(1)]).nullable(),rc=I.object({dataset_id:I.string(),id:I.string().optional(),name:I.string(),description:I.string().nullable().optional(),status:I.string(),visibility:I.string(),concept_doi:I.string().nullable().optional(),doi:I.string().nullable().optional(),created_at:I.string(),updated_at:I.string().optional(),owner_username:I.string().nullable().optional(),source:I.string().nullable().optional(),modalities:I.string().optional(),participants:I.number().int().nonnegative(),tasks:I.string().optional(),authors:I.string().optional(),license:I.string().optional(),file_size:I.number().nonnegative(),file_size_formatted:I.string().optional(),num_citations:I.number().int().nonnegative().optional(),n_channels:I.number().int().nullable().optional(),electrode_system:I.string().nullable().optional(),has_hed:sc.optional(),hed_version:I.string().nullable().optional(),latest_version:ac.nullable().optional()}).passthrough(),Xk0=rc.extend({file_size:I.number().nonnegative().nullable(),modalities:I.string().nullable().optional(),tasks:I.string().nullable().optional(),authors:I.string().nullable().optional(),license:I.string().nullable().optional(),owner_github:I.string().nullable().optional()}).passthrough(),Bk0=I.object({id:I.string(),name:I.string(),modalities:I.string().nullable().optional(),participants:I.number().int().nullable().optional(),doi:I.string().nullable().optional(),tasks:I.string().nullable().optional(),authors:I.string().nullable().optional(),has_hed:sc.optional(),score:I.number().optional(),snippet:I.string().optional()}).passthrough(),cs0=I.object({datasets:I.array(rc),count:I.number().int().nonnegative(),total_count:I.number().int().nonnegative().optional(),limit:I.number().int().optional(),offset:I.number().int().optional()}).passthrough(),ns0=I.object({results:I.array(Bk0),count:I.number().int().nonnegative(),method:I.string().optional(),min_score:I.number().optional()}).passthrough(),is0=I.object({dataset:Xk0}).passthrough(),as0=I.object({schema_version:I.literal(Jk0),doc_type:I.literal("dataset"),dataset_id:I.string().regex(/^[a-z]{2}\d+$/,"neuroschema dataset_id pattern"),name:I.string(),source:Yk0,recording_modality:I.array(I.string()).min(1),description:I.string().nullable().optional(),bids_version:I.string().nullable().optional(),license:I.string().nullable().optional()}).passthrough();I4();async function tc(D){return _(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function ec(D){return _(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function Dn(D){return _("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function HZ(D){return _("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function Fn(D){return _("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function $n(D,F){return _("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function Qn(D){return _("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function _X(){return(await _("/users/me",{},!0,oc)).user}async function Jn(D){return _("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function Yn(){return _("/sandbox/reset",{method:"POST"},!0)}async function Xn(){return _("/sandbox/status",{},!0)}K1();P4();z1();var Bn={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)"}}},Gk0={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 Wk0(){if(process.platform==="darwin")return"macos";if(process.platform==="win32")return"windows";return"linux"}function Gn(D,F=Wk0()){return D.installInstructions[F]}function Hk0(D){let F=D.match(/(\d+\.\d+(?:\.\d+)?)/);return F?F[1]:void 0}async function Wn(D){try{let{exitCode:F,stdout:$}=await w(D.cmd);if(F!==0)return{available:!1};return{available:!0,version:Hk0($)}}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 qZ(){let D=Object.entries(Bn);return Promise.all(D.map(async([F,$])=>{let{available:Q,version:J}=await Wn($);return{key:F,name:$.name,purpose:$.purpose,required:$.required,available:Q,version:J,installInstruction:Gn($)}}))}async function Hn(){let F=(await qZ()).filter(($)=>$.required&&!$.available);if(F.length===0)return[];console.warn(`
|
|
414
414
|
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 k3(D){let $=Gk0[D].map((X)=>Bn[X]).filter(Boolean),J=(await Promise.all($.map(async(X)=>({check:X,available:(await Wn(X)).available})))).filter((X)=>!X.available&&X.check.required).map((X)=>({tool:X.check.name,installInstruction:Gn(X.check)}));if(J.length===0)return;let Y=[`
|
|
@@ -700,7 +700,7 @@ Description:
|
|
|
700
700
|
Examples:
|
|
701
701
|
$ nemar dataset release nm000104 --type patch
|
|
702
702
|
$ nemar dataset release nm000104 --version 2.0.0
|
|
703
|
-
$ nemar dataset release nm000104 # interactive prompt`).action(async(D,F)=>{sD(),await k3("release");let $=R("Fetching dataset info...").start(),Q;try{Q=await ID(D),$.succeed(`Dataset: ${Q.name||D}`)}catch(C){if(C instanceof f)$.fail(C.message);else $.fail("Failed to fetch dataset");process.exit(1)}if(!Q.github_repo)console.log(H.red("Error: Dataset has no GitHub repository")),process.exit(1);let J;try{let C=await $d(D);if(J=C.current_version,console.log(` Current version: ${H.cyan(J)}`),C.versions.length>0){console.log(` Version DOIs: ${C.versions.length}`);for(let j of C.versions.slice(0,3))console.log(` ${j.version} - ${H.dim(j.doi)}`);if(C.versions.length>3)console.log(H.dim(` ... and ${C.versions.length-3} more`))}}catch(C){let j=C instanceof f?`${C.statusCode}: ${C.message}`:String(C);console.log(H.red(`Error: Could not fetch version history (${j})`)),console.log(" Cannot determine current version. Ensure the backend is reachable."),process.exit(1)}let Y;if(F.version){if(!OZ(F.version))console.log(H.red(`Error: Invalid version: ${F.version}`)),console.log(" Expected format: X.Y.Z (e.g., 2.0.0)"),process.exit(1);Y=F.version.replace(/^v/,"")}else if(F.type){let C=F.type;if(!["patch","minor","major"].includes(C))console.log(H.red(`Error: Invalid bump type: ${F.type}`)),console.log(" Expected: patch, minor, or major"),process.exit(1);Y=x3(J,C)}else{if(!m5(J))console.log(H.red(`Error: Cannot parse current version: ${J}`)),process.exit(1);let j=[{name:`patch ${J} -> ${x3(J,"patch")}`,value:"patch"},{name:`minor ${J} -> ${x3(J,"minor")}`,value:"minor"},{name:`major ${J} -> ${x3(J,"major")}`,value:"major"},{name:"custom version",value:"custom"}],{bumpType:S}=await e.prompt([{type:"list",name:"bumpType",message:"Select version bump type:",choices:j}]);if(S==="custom"){let{customVersion:l}=await e.prompt([{type:"input",name:"customVersion",message:"Enter version (X.Y.Z):",validate:(y)=>OZ(y)||"Invalid format. Use X.Y.Z (e.g., 2.0.0)"}]);Y=l.replace(/^v/,"")}else Y=x3(J,S)}if(console.log(),console.log(` ${H.bold("Version bump:")} ${J} -> ${H.green(Y)}`),await x0(`Create release PR for ${D} v${Y}?`,{yes:F.yes})!=="confirmed"){console.log("Cancelled.");return}let B,G=!0;if(F.dir){if(!j1(F.dir))console.log(H.red(`Error: Directory not found: ${F.dir}`)),process.exit(1);B=S6(F.dir),G=!1}else B=Nv0(l5(Cv0(),`nemar-release-${D}-`));if(G){let C=`https://github.com/${Q.github_repo}.git`,j=R("Cloning dataset...").start(),S=await Z1(C,B);if(!S.success)j.fail(`Clone failed: ${S.error}`),process.exit(1);j.succeed("Cloned dataset")}let W=`release/v${Y}`,q=R("Creating release branch...").start(),K=SD({cmd:["git","checkout","-b",W],cwd:B,stdout:"pipe",stderr:"pipe"});if(await K.exited!==0){let C=await new Response(K.stderr).text();q.fail(`Failed to create branch: ${C.trim()}`),process.exit(1)}q.succeed(`Created branch: ${W}`);let Z=l5(B,"dataset_description.json");if(!j1(Z))console.log(H.red("Error: dataset_description.json not found in repo")),process.exit(1);let z;try{z=JSON.parse(dX(Z,"utf-8"))}catch(C){if(C instanceof SyntaxError)console.log(H.red("Error: dataset_description.json contains invalid JSON"));else console.log(H.red(`Error: Could not read dataset_description.json: ${C}`));process.exit(1)}z.Version=Y,hi(Z,`${JSON.stringify(z,null,2)}
|
|
703
|
+
$ nemar dataset release nm000104 # interactive prompt`).action(async(D,F)=>{sD(),await k3("release");let $=R("Fetching dataset info...").start(),Q;try{Q=await ID(D),$.succeed(`Dataset: ${Q.name||D}`)}catch(C){if(C instanceof f)$.fail(C.message);else $.fail("Failed to fetch dataset");process.exit(1)}if(!Q.github_repo)console.log(H.red("Error: Dataset has no GitHub repository")),process.exit(1);let J;try{let C=await $d(D);if(J=C.current_version.replace(/^v/,""),console.log(` Current version: ${H.cyan(J)}`),C.versions.length>0){console.log(` Version DOIs: ${C.versions.length}`);for(let j of C.versions.slice(0,3))console.log(` ${j.version} - ${H.dim(j.doi)}`);if(C.versions.length>3)console.log(H.dim(` ... and ${C.versions.length-3} more`))}}catch(C){let j=C instanceof f?`${C.statusCode}: ${C.message}`:String(C);console.log(H.red(`Error: Could not fetch version history (${j})`)),console.log(" Cannot determine current version. Ensure the backend is reachable."),process.exit(1)}let Y;if(F.version){if(!OZ(F.version))console.log(H.red(`Error: Invalid version: ${F.version}`)),console.log(" Expected format: X.Y.Z (e.g., 2.0.0)"),process.exit(1);Y=F.version.replace(/^v/,"")}else if(F.type){let C=F.type;if(!["patch","minor","major"].includes(C))console.log(H.red(`Error: Invalid bump type: ${F.type}`)),console.log(" Expected: patch, minor, or major"),process.exit(1);Y=x3(J,C)}else{if(!m5(J))console.log(H.red(`Error: Cannot parse current version: ${J}`)),process.exit(1);let j=[{name:`patch ${J} -> ${x3(J,"patch")}`,value:"patch"},{name:`minor ${J} -> ${x3(J,"minor")}`,value:"minor"},{name:`major ${J} -> ${x3(J,"major")}`,value:"major"},{name:"custom version",value:"custom"}],{bumpType:S}=await e.prompt([{type:"list",name:"bumpType",message:"Select version bump type:",choices:j}]);if(S==="custom"){let{customVersion:l}=await e.prompt([{type:"input",name:"customVersion",message:"Enter version (X.Y.Z):",validate:(y)=>OZ(y)||"Invalid format. Use X.Y.Z (e.g., 2.0.0)"}]);Y=l.replace(/^v/,"")}else Y=x3(J,S)}if(console.log(),console.log(` ${H.bold("Version bump:")} ${J} -> ${H.green(Y)}`),await x0(`Create release PR for ${D} v${Y}?`,{yes:F.yes})!=="confirmed"){console.log("Cancelled.");return}let B,G=!0;if(F.dir){if(!j1(F.dir))console.log(H.red(`Error: Directory not found: ${F.dir}`)),process.exit(1);B=S6(F.dir),G=!1}else B=Nv0(l5(Cv0(),`nemar-release-${D}-`));if(G){let C=`https://github.com/${Q.github_repo}.git`,j=R("Cloning dataset...").start(),S=await Z1(C,B);if(!S.success)j.fail(`Clone failed: ${S.error}`),process.exit(1);j.succeed("Cloned dataset")}let W=`release/v${Y}`,q=R("Creating release branch...").start(),K=SD({cmd:["git","checkout","-b",W],cwd:B,stdout:"pipe",stderr:"pipe"});if(await K.exited!==0){let C=await new Response(K.stderr).text();q.fail(`Failed to create branch: ${C.trim()}`),process.exit(1)}q.succeed(`Created branch: ${W}`);let Z=l5(B,"dataset_description.json");if(!j1(Z))console.log(H.red("Error: dataset_description.json not found in repo")),process.exit(1);let z;try{z=JSON.parse(dX(Z,"utf-8"))}catch(C){if(C instanceof SyntaxError)console.log(H.red("Error: dataset_description.json contains invalid JSON"));else console.log(H.red(`Error: Could not read dataset_description.json: ${C}`));process.exit(1)}z.Version=Y,hi(Z,`${JSON.stringify(z,null,2)}
|
|
704
704
|
`);let E=R("Committing version bump...").start(),U=SD({cmd:["git","add","dataset_description.json"],cwd:B,stdout:"pipe",stderr:"pipe"});if(await U.exited!==0){let C=await new Response(U.stderr).text();E.fail(`Failed to stage changes: ${C.trim()}`),process.exit(1)}let M=SD({cmd:["git","commit","-m",`Bump version to ${Y}`],cwd:B,stdout:"pipe",stderr:"pipe"});if(await M.exited!==0){let C=await new Response(M.stderr).text();E.fail(`Commit failed: ${C.trim()}`),process.exit(1)}E.succeed("Committed version bump");let A=R("Pushing branch...").start(),N=await H$(B,W);if(!N.success)A.fail(`Push failed: ${N.error}`),process.exit(1);A.succeed("Pushed branch");let O=!1,T=R("Creating pull request...").start();try{let C=`Release v${Y}`,j=`## Version Bump
|
|
705
705
|
|
|
706
706
|
Bumps ${D} from ${J} to ${Y}.
|