nemar-cli 0.8.13 → 0.8.14-PR461.8df6f6a

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.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ ${W.dim(`eta: ${D.eta}`)}`:"";process.stderr.write(`${F}
95
95
  ${$} ${D.message}
96
96
  ${J}${Q}
97
97
  ${F}
98
- `)}var Ef=!1;var NW=P(()=>{xD()});var Zf;var Vf=P(()=>{Zf={name:"nemar-cli",version:"0.8.13",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","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build",prepare:"husky",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://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var _4;var oJ=P(()=>{Vf();_4=Zf.version});function w0(D){if(D instanceof Error)return D.message;return String(D)}function Uf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(RW)return CW;return JD().apiUrl||CW}async function b(D,F={},$=!1){let J=`${Uf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=JD();if(!X.apiKey&&$===!0)throw new p(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new p(0,`Network error: Could not connect to ${Uf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new p(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new rJ(B.mode,X,G,B.details);throw aJ(H),H}throw new p(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function Af(D){return b(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function Mf(D){return b(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function Nf(D){return b("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function Cf(D){return b("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function Rf(D){return b("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Of(D,F){return b("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function wf(D){return b("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function tJ(){return b("/users/me",{},!0)}async function Tf(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return b(`/admin/users${J}`,{},!0)}async function jf(D){return b(`/admin/approve/${D}`,{method:"POST"},!0)}async function Pf(D){return b(`/admin/revoke/${D}`,{method:"POST"},!0)}async function If(D,F){return b(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function OW(D,F){return b(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Sf(D){return b(`/datasets/${D}/publish`,{method:"POST"},!0)}async function kf(D){return b(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return b(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function wW(D){return b(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function eJ(D){return b(`/datasets/${D}/ci/status`,{},!0)}async function vf(D){return b(`/datasets/${D}/manifest`,{},!0)}async function DQ(D,F){return b(`/datasets/${D}/manifest/${F}`,{},!0)}function yf(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 I9(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.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await b(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(yf),J}async function xf(D){return b(`/datasets/resolve/${D}`,{},"optional")}async function _f(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return b(`/datasets/search?${$.toString()}`,{},"optional")}async function uD(D){let F=await b(`/datasets/${D}`,{},"optional");return yf(F.dataset)}async function ff(D){return b(`/datasets/${D}/versions`,{},!0)}async function FQ(D){return b("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function $Q(D){return b(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function R8(D,F){return b(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function JQ(D,F){return b(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function gf(D,F){return b(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function S9(D){return b(`/admin/datasets/${D}/doi`,{},!0)}async function TW(D,F){return b(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function jW(D){return b(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function hf(D,F){return b(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function bf(D){return b(`/datasets/${D}/collaborators`,{},!0)}async function uf(D){return b("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function mf(){return b("/sandbox/reset",{method:"POST"},!0)}async function lf(){return b("/sandbox/status",{},!0)}async function QQ(D){return b(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function pf(D){return b(`/datasets/${D}/publish/status`,{},!0)}async function df(D){return b(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function cf(D){let F=D?`?status=${D}`:"";return b(`/admin/publish/requests${F}`,{},!0)}async function nf(D,F){return b(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function az0(D){if(!(D instanceof p))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 YQ(D,F=!1,$=!1,J=!1,Q){let X,G=F,H=[],q;for(let K=1;K<=5;K++)try{let V,E=!0;do{if(V=await b(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?G:!0,sandbox:$,s3_lock_continuation_token:X,skip_ci_check:J})},!0),E=!1,V.step_results)H.push(...V.step_results);if(V.hasMore&&V.s3_lock_continuation_token!==void 0)X=V.s3_lock_continuation_token;else break}while(V.hasMore);if(H.length>0)V.step_results=Lf(H);return V}catch(V){if(q=V,K===5||!az0(V)){if(V instanceof p&&H.length>0)V.stepResults=Lf(H);throw V}let Z=V;Q?.({attempt:K,maxAttempts:5,delayMs:1e4,step:Z.step,error:Z.message}),await new Promise((L)=>setTimeout(L,1e4)),G=!0}throw q}function Lf(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function af(D,F){return b(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function of(D){return b(`/admin/datasets/${D}/files`,{},!0)}async function sf(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await b(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new p(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function rf(D){return b(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function tf(D,F=!1){return b(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function ef(D){return b("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function Dg(D){return b("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function Fg(D){return b(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function $g(){return b("/admin/sync/status",{},!0)}async function Jg(D,F){return b(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function Qg(D,F){return b("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function Yg(){return b("/admin/email-preferences",{},!0)}async function Bg(D){return b("/admin/email-preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function Xg(){return b("/notices",{},"optional")}async function Gg(){return b("/admin/notices",{},!0)}async function Wg(D){return b("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function Hg(D){return b(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function PW(D){return b("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}var CW="https://api.nemar.org",sJ,p,rJ,RW;var i8=P(()=>{x4();NW();oJ();sJ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;p=class p extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};rJ=class rJ extends p{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};RW=CW.includes("workers.dev")});function Kg(D){IW=D}function SW(){return IW}function k9(D){if(IW)process.stderr.write(`${D}
98
+ `)}var Ef=!1;var NW=P(()=>{xD()});var Zf;var Vf=P(()=>{Zf={name:"nemar-cli",version:"0.8.14-PR461.8df6f6a",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","docs:generate":"bun run scripts/generate-docs.ts","docs:serve":"mkdocs serve","docs:build":"mkdocs build",prepare:"husky",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://nemar-cli.pages.dev",engines:{bun:">=1.0.0"},files:["dist","README.md","LICENSE"],dependencies:{chalk:"^5.3.0",commander:"^12.1.0",conf:"^13.0.1","fuse.js":"^7.1.0",inquirer:"^9.2.15",ora:"^8.0.1",zod:"^3.23.8"},"lint-staged":{"src/**/*.{ts,tsx}":["biome check --fix"],"backend/src/**/*.{ts,tsx}":["biome check --fix"]},devDependencies:{"@biomejs/biome":"1.9.4","@types/bcryptjs":"^3.0.0","@types/bun":"latest","@types/inquirer":"^9.0.7",bcryptjs:"^3.0.3",husky:"^9.1.7","lint-staged":"^16.3.2",typescript:"^5.5.4",wrangler:"^4.70.0",yaml:"^2.8.4"}}});var _4;var oJ=P(()=>{Vf();_4=Zf.version});function w0(D){if(D instanceof Error)return D.message;return String(D)}function Uf(){if(process.env.TEST_API_URL)return process.env.TEST_API_URL;if(RW)return CW;return JD().apiUrl||CW}async function b(D,F={},$=!1){let J=`${Uf()}${D}`,Q={"Content-Type":"application/json","X-CLI-Version":_4,...F.headers};if($){let X=JD();if(!X.apiKey&&$===!0)throw new p(401,"Not authenticated. Run 'nemar auth login' first.");if(X.apiKey)Q.Authorization=`Bearer ${X.apiKey}`}let Y;try{Y=await fetch(J,{...F,headers:Q})}catch(X){throw new p(0,`Network error: Could not connect to ${Uf()}`,{originalError:X instanceof Error?X.message:String(X)})}let B;try{B=await Y.json()}catch{throw new p(Y.status,`Invalid response from server (status ${Y.status})`)}if(!Y.ok){if(Y.status===503&&(B.mode==="read-only"||B.mode==="full")){let X=typeof B.message==="string"?B.message:"NEMAR is in maintenance mode. Please retry shortly.",G=typeof B.eta==="string"?B.eta:null,H=new rJ(B.mode,X,G,B.details);throw aJ(H),H}throw new p(Y.status,B.error||B.message||"Request failed",B.details,typeof B.step==="string"?B.step:void 0)}return B}async function Af(D){return b(`/auth/check-username?username=${encodeURIComponent(D)}`)}async function Mf(D){return b(`/auth/check-github?username=${encodeURIComponent(D)}`)}async function Nf(D){return b("/auth/signup",{method:"POST",body:JSON.stringify(D)})}async function Cf(D){return b("/auth/login",{method:"POST",body:JSON.stringify({api_key:D})})}async function Rf(D){return b("/auth/resend-verification",{method:"POST",body:JSON.stringify({email:D})})}async function Of(D,F){return b("/auth/retrieve-key",{method:"POST",body:JSON.stringify({email:D,password:F})})}async function wf(D){return b("/auth/request-key-regeneration",{method:"POST",body:JSON.stringify({email:D})})}async function tJ(){return b("/users/me",{},!0)}async function Tf(D,F){let $=new URLSearchParams;if(D)$.set("status",D);if(F)$.set("role",F);let J=$.toString()?`?${$.toString()}`:"";return b(`/admin/users${J}`,{},!0)}async function jf(D){return b(`/admin/approve/${D}`,{method:"POST"},!0)}async function Pf(D){return b(`/admin/revoke/${D}`,{method:"POST"},!0)}async function If(D,F){return b(`/admin/users/${D}/role`,{method:"POST",body:JSON.stringify({role:F})},!0)}async function OW(D,F){return b(`/admin/datasets/${D}/visibility`,{method:"PATCH",body:JSON.stringify({visibility:F})},!0)}async function Sf(D){return b(`/datasets/${D}/publish`,{method:"POST"},!0)}async function kf(D){return b(`/admin/datasets/${D}/ci`,{},!0)}async function f4(D){return b(`/admin/datasets/${D}/ci`,{method:"POST"},!0)}async function wW(D){return b(`/admin/datasets/${D}/ci/sync`,{method:"POST"},!0)}async function eJ(D){return b(`/datasets/${D}/ci/status`,{},!0)}async function vf(D){return b(`/datasets/${D}/manifest`,{},!0)}async function DQ(D,F){return b(`/datasets/${D}/manifest/${F}`,{},!0)}function yf(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 I9(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.hasDoi)F.set("has_doi","true");if(D.recent)F.set("recent",String(D.recent));if(D.sort)F.set("sort",D.sort);if(D.limit!=null)F.set("limit",String(D.limit));if(D.offset!=null)F.set("offset",String(D.offset));if(D.owner)F.set("owner",D.owner);let $=F.toString()?`?${F.toString()}`:"",J=await b(`/datasets${$}`,{},D.mine?!0:"optional");return J.datasets=J.datasets.map(yf),J}async function xf(D){return b(`/datasets/resolve/${D}`,{},"optional")}async function _f(D,F={}){let $=new URLSearchParams({q:D});if(F.modality)$.set("modality",F.modality);if(F.limit)$.set("limit",String(F.limit));return b(`/datasets/search?${$.toString()}`,{},"optional")}async function uD(D){let F=await b(`/datasets/${D}`,{},"optional");return yf(F.dataset)}async function ff(D){return b(`/datasets/${D}/versions`,{},!0)}async function FQ(D){return b("/datasets",{method:"POST",body:JSON.stringify(D)},!0)}async function $Q(D){return b(`/datasets/${D}/finalize`,{method:"POST"},!0)}async function R8(D,F){return b(`/datasets/${D}/upload-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function JQ(D,F){return b(`/datasets/${D}/download-credentials`,{method:"POST",body:JSON.stringify({duration_seconds:F})},!0)}async function gf(D,F){return b(`/admin/datasets/${D}/doi/concept`,{method:"POST",body:JSON.stringify(F)},!0)}async function S9(D){return b(`/admin/datasets/${D}/doi`,{},!0)}async function TW(D,F){return b(`/admin/datasets/${D}/doi/update`,{method:"POST",body:JSON.stringify(F)},!0)}async function jW(D){return b(`/datasets/${D}/request-access`,{method:"POST"},!0)}async function hf(D,F){return b(`/datasets/${D}/invite`,{method:"POST",body:JSON.stringify({username:F})},!0)}async function bf(D){return b(`/datasets/${D}/collaborators`,{},!0)}async function uf(D){return b("/sandbox/complete",{method:"POST",body:JSON.stringify({dataset_id:D})},!0)}async function mf(){return b("/sandbox/reset",{method:"POST"},!0)}async function lf(){return b("/sandbox/status",{},!0)}async function QQ(D){return b(`/datasets/${D}/publish/request`,{method:"POST"},!0)}async function pf(D){return b(`/datasets/${D}/publish/status`,{},!0)}async function df(D){return b(`/datasets/${D}/publish/resend`,{method:"POST"},!0)}async function cf(D){let F=D?`?status=${D}`:"";return b(`/admin/publish/requests${F}`,{},!0)}async function nf(D,F){return b(`/admin/publish/${D}/deny`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:F})},!0)}function az0(D){if(!(D instanceof p))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 YQ(D,F=!1,$=!1,J=!1,Q){let X,G=F,H=[],q;for(let K=1;K<=5;K++)try{let V,E=!0;do{if(V=await b(`/admin/publish/${D}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resume:E?G:!0,sandbox:$,s3_lock_continuation_token:X,skip_ci_check:J})},!0),E=!1,V.step_results)H.push(...V.step_results);if(V.hasMore&&V.s3_lock_continuation_token!==void 0)X=V.s3_lock_continuation_token;else break}while(V.hasMore);if(H.length>0)V.step_results=Lf(H);return V}catch(V){if(q=V,K===5||!az0(V)){if(V instanceof p&&H.length>0)V.stepResults=Lf(H);throw V}let Z=V;Q?.({attempt:K,maxAttempts:5,delayMs:1e4,step:Z.step,error:Z.message}),await new Promise((L)=>setTimeout(L,1e4)),G=!0}throw q}function Lf(D){let F=new Map;for(let $ of D)F.set($.step,$);return Array.from(F.values())}async function af(D,F){return b(`/admin/datasets/${D}/enrichment`,{method:"POST",body:JSON.stringify(F)},!0)}async function of(D){return b(`/admin/datasets/${D}/files`,{},!0)}async function sf(D){let F,$=0,J=[],Q=!0;while(Q){let Y=await b(`/admin/datasets/${D}/s3-lock`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({continuation_token:F})},!0);if($+=Y.locked,Y.failed?.length)J.push(...Y.failed);if(Q=Y.hasMore,F=Y.continuation_token,Q&&!F)throw new p(500,"S3 lock paginated response missing continuation_token; aborting to avoid infinite loop")}return{locked:$,failed:J}}async function rf(D){return b(`/admin/datasets/${D}/reset`,{method:"POST"},!0)}async function tf(D,F=!1){return b(`/admin/datasets/${D}`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:F})},!0)}async function ef(D){return b("/admin/datasets/bulk-delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_ids:D})},!0)}async function Dg(D){return b("/admin/datasets/import",{method:"POST",body:JSON.stringify(D)},!0)}async function Fg(D){return b(`/admin/datasets/${D}/sync`,{method:"POST"},!0)}async function $g(){return b("/admin/sync/status",{},!0)}async function Jg(D,F){return b(`/admin/datasets/${D}/reindex`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F??{})},!0)}async function Qg(D,F){return b("/admin/datasets/reindex/bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filter:D,...F??{}})},!0)}async function Yg(){return b("/admin/email-preferences",{},!0)}async function Bg(D){return b("/admin/email-preferences",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(D)},!0)}async function Xg(){return b("/notices",{},"optional")}async function Gg(){return b("/admin/notices",{},!0)}async function Wg(D){return b("/admin/notices",{method:"POST",body:JSON.stringify(D)},!0)}async function Hg(D){return b(`/admin/notices/${D}`,{method:"DELETE"},!0)}async function PW(D){return b("/admin/notify",{method:"POST",body:JSON.stringify(D)},!0)}var CW="https://api.nemar.org",sJ,p,rJ,RW;var i8=P(()=>{x4();NW();oJ();sJ=/^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$/;p=class p extends Error{statusCode;details;step;constructor(D,F,$,J){super(F);this.statusCode=D;this.details=$;this.step=J;this.name="ApiError"}};rJ=class rJ extends p{mode;eta;constructor(D,F,$,J){super(503,F,J);this.mode=D;this.eta=$;this.name="MaintenanceError"}};RW=CW.includes("workers.dev")});function Kg(D){IW=D}function SW(){return IW}function k9(D){if(IW)process.stderr.write(`${D}
99
99
  `)}var IW=!1;function XD(D){if(D===0)return"0 B";let F=["B","KB","MB","GB","TB"],$=Math.min(Math.floor(Math.log(D)/Math.log(1024)),F.length-1);return`${(D/1024**$).toFixed($===0?0:1)} ${F[$]}`}function zg(D){return`${XD(D)}/s`}function oz0(D){if(D<60)return`${Math.round(D)}s`;if(D<3600)return`${Math.floor(D/60)}m ${Math.round(D%60)}s`;return`${Math.floor(D/3600)}h ${Math.floor(D%3600/60)}m`}function sz0(D,F=20){let $=Math.round(D/100*F),J=F-$;return`[${"=".repeat($)}${" ".repeat(J)}]`}class BQ{filesCompleted=0;filesTotal;bytesTotal=0;inFlight=new Map;currentFile="";startTime;lastUpdateTime;lastBytesTransferred=0;totalBytesTransferred=0;speedSamples=[];lastRenderedLine="";constructor(D=0,F=0){this.filesTotal=D,this.bytesTotal=F,this.startTime=Date.now(),this.lastUpdateTime=this.startTime}inFlightBytes(){let D=0;for(let F of this.inFlight.values())D+=F.transferred;return D}processLine(D){let F=D.file??D.action?.file;if(D.ok===!0||D.success===!0){this.filesCompleted++;let $=F??this.currentFile,J=$?this.inFlight.get($):void 0,Q=J?J.total||J.transferred:0;if(this.totalBytesTransferred+=Q,$)this.inFlight.delete($);this.render();return}if(D["byte-progress"]!==void 0){let $=F??this.currentFile;if(!$)return;this.currentFile=$;let J=this.inFlight.get($)??{transferred:0,total:0};if(J.transferred=D["byte-progress"]??J.transferred,D["total-size"]!==void 0)J.total=D["total-size"];this.inFlight.set($,J);let Q=Date.now(),Y=(Q-this.lastUpdateTime)/1000;if(Y>0.5){let B=this.totalBytesTransferred+this.inFlightBytes(),G=(B-this.lastBytesTransferred)/Y;if(G>0){if(this.speedSamples.push(G),this.speedSamples.length>5)this.speedSamples.shift()}this.lastBytesTransferred=B,this.lastUpdateTime=Q}this.render()}}incrementFilesCompleted(){this.filesCompleted++}setFilesTotal(D){this.filesTotal=D}setBytesTotal(D){this.bytesTotal=D}getPercent(){let D=this.totalBytesTransferred+this.inFlightBytes();if(this.bytesTotal>0)return Math.min(100,Math.round(D/this.bytesTotal*100));if(this.filesTotal>0)return Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100));return null}getProgress(){return{filesCompleted:this.filesCompleted,filesTotal:this.filesTotal,bytesTransferred:this.totalBytesTransferred+this.inFlightBytes(),bytesTotal:this.bytesTotal,currentFile:this.currentFile||void 0}}render(){let D=this.speedSamples.length>0?this.speedSamples.reduce((B,X)=>B+X,0)/this.speedSamples.length:0,F=this.totalBytesTransferred+this.inFlightBytes(),$=0,J=!1;if(this.bytesTotal>0)$=Math.min(100,Math.round(F/this.bytesTotal*100)),J=!0;else if(this.filesTotal>0)$=Math.min(100,Math.round(this.filesCompleted/this.filesTotal*100)),J=!0;let Q=this.filesTotal>0?`${this.filesCompleted}/${this.filesTotal} files`:`${this.filesCompleted} files`,Y;if(J)Y=`${sz0($)} ${$}% ${Q}`;else Y=Q;if(F>0){let B=this.bytesTotal>0?`${XD(F)}/${XD(this.bytesTotal)}`:XD(F);Y+=` | ${B}`}if(D>0)Y+=` | ${zg(D)}`;if(D>0){let B=0;if(this.bytesTotal>0)B=Math.max(0,this.bytesTotal-F);else for(let X of this.inFlight.values())if(X.total>X.transferred)B+=X.total-X.transferred;if(B>0){let X=B/D;if(X>0)Y+=` | ETA ${oz0(X)}`}}if(Y!==this.lastRenderedLine)process.stderr.write(`\r${W.cyan(Y)}${" ".repeat(10)}`),this.lastRenderedLine=Y}finish(D){let F=(Date.now()-this.startTime)/1000;if(process.stderr.write(`\r${" ".repeat(this.lastRenderedLine.length+15)}\r`),D>0){let $=F>0?`${zg(this.totalBytesTransferred/F)}`:"",J=[`${D} file${D!==1?"s":""} downloaded`,this.totalBytesTransferred>0?XD(this.totalBytesTransferred):"",$].filter(Boolean).join(" | ");process.stderr.write(`${W.green(J)}
100
100
  `)}}}var kW=P(()=>{xD()});var Tg={};c4(Tg,{verifyGitHubAuth:()=>y9,toS3Credentials:()=>CD,switchBranch:()=>BE0,setKeyPresent:()=>wg,selectAnnexS3Remote:()=>bW,saveDataset:()=>o8,runCommand:()=>I,resolveUpstreamRef:()=>iW,readRemoteHeadDatasetVersion:()=>nW,readLocalDatasetVersion:()=>cW,pushToGitHub:()=>o1,pushBranch:()=>PF,markInheritedOpenNeuroRemotesIgnored:()=>hW,listDatasetVersions:()=>mW,isWorkingTreeDirty:()=>aW,isGitAnnexDataset:()=>w1,isDataladDataset:()=>qE0,initOrEnableSpecialRemote:()=>Cg,initDataset:()=>n6,gitMergeFastForward:()=>sW,gitFetchOrigin:()=>oW,gitAnnexAdd:()=>i6,getVersionCommit:()=>lW,getRemoteUuid:()=>DH,getLocalDatasetInfo:()=>uW,getKeyHashDirs:()=>WE0,getKeyHashDir:()=>Og,getDatasetStats:()=>JE0,getDatasetIdFromRemote:()=>r8,getDatasetData:()=>WQ,getCurrentBranch:()=>s8,getAnnexWhereisAll:()=>eW,getAnnexS3Remotes:()=>_9,formatBytes:()=>XD,ensureLocalMainBranch:()=>f9,ensureGitAnnexInitialized:()=>fW,enableS3Remote:()=>h4,dropUnusedAnnexObjects:()=>rW,dropFiles:()=>gW,createRevertBranch:()=>pW,createDataladDataset:()=>HE0,countPendingDownload:()=>GQ,copyToAnnexRemote:()=>w8,configureS3Remote:()=>O8,configureLargefiles:()=>g4,configureGitHubRemote:()=>a8,commitRevert:()=>dW,collectFileManifest:()=>tW,cloneDataset:()=>s1,clearAnnexCredentials:()=>kD,checkPrerequisites:()=>v9,checkGitHubSSH:()=>Lg,checkGitAnnexInstalled:()=>_W,checkDownloadPrerequisites:()=>jF,checkAWSCredentials:()=>DE0,batchSetKeysPresent:()=>FH,annexRemoteExists:()=>Ng,acceptGitHubInvitation:()=>x9,NEMAR_S3_REMOTE_NAME:()=>XQ,ANNEX_REMOTE_EXISTS_RE:()=>Mg});import{existsSync as yW,readFileSync as rz0,statSync as tz0}from"fs";import{join as xW}from"path";var{spawn:Ug}=globalThis.Bun;async function I(D,F={}){let $=Ug({cmd:D,cwd:F.cwd,stdout:"pipe",stderr:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0",...F.env}}),J=!1,Q;if(F.timeout)Q=setTimeout(()=>{J=!0,$.kill()},F.timeout);if(SW()){let G=F.cwd?` (cwd=${F.cwd})`:"";k9(W.dim(`$ ${D.join(" ")}${G}`))}let Y=await new Response($.stdout).text(),B=await new Response($.stderr).text(),X=await $.exited;if(Q)clearTimeout(Q);if(SW()){if(Y.trim())k9(W.dim(Y.trimEnd()));if(B.trim())k9(W.yellow(B.trimEnd()));k9(W.dim(`(exit ${X})`))}if(J)return{stdout:Y,stderr:B||`Command timed out after ${Math.round(F.timeout/1000)}s`,exitCode:X??1};return{stdout:Y,stderr:B,exitCode:X}}function Eg(D){return D.split(".").map((F)=>{let $=Number.parseInt(F.replace(/[^0-9]/g,""),10);return Number.isNaN($)?0:$})}function ez0(D,F){let $=Eg(D),J=Eg(F);for(let Q=0;Q<Math.max($.length,J.length);Q++){let Y=$[Q]||0,B=J[Q]||0;if(Y>B)return!0;if(Y<B)return!1}return!0}async function _W(){try{let{stdout:F,exitCode:$,stderr:J}=await I(["git-annex","version"]);if($!==0)return console.warn("git-annex version returned non-zero exit code:",$),console.warn("stderr:",J),{installed:!1,minVersion:"10.0",error:`Version check failed: ${J.trim()}`};let Q=F.match(/version:\s*(\d+\.\d+)/),Y=Q?Q[1]:void 0;if(!Y)console.warn("Could not parse git-annex version from output:",F);return{installed:!0,version:Y,minVersion:"10.0",compatible:Y?ez0(Y,"10.0"):void 0}}catch(F){let $=F instanceof Error?F.message:String(F);if($.includes("ENOENT")||$.includes("not found"))return console.info("git-annex not found in PATH"),{installed:!1,minVersion:"10.0"};return console.error("Error checking git-annex installation:",$),{installed:!1,minVersion:"10.0",error:$}}}async function Lg(){if(process.env.GH_TOKEN)return{accessible:!0,username:"token-auth",useHttps:!0};try{let{stdout:D,stderr:F}=await I(["ssh","-T","-o","BatchMode=yes","-o","StrictHostKeyChecking=accept-new","-o","ConnectTimeout=10","git@github.com"]),$=D+F,J=$.match(/Hi ([^!]+)!/);if(J)return{accessible:!0,username:J[1]};if($.includes("Permission denied"))return{accessible:!1};return{accessible:$.includes("successfully authenticated")}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("SSH command not found");else console.error("Error checking GitHub SSH access:",F);return{accessible:!1}}}async function DE0(){if(process.env.AWS_ACCESS_KEY_ID&&process.env.AWS_SECRET_ACCESS_KEY)return{configured:!0,source:"environment"};try{let{stdout:D,exitCode:F}=await I(["aws","configure","get","aws_access_key_id"]);if(F===0&&D.trim())return{configured:!0,source:"aws-cli"}}catch(D){let F=D instanceof Error?D.message:String(D);if(F.includes("ENOENT")||F.includes("not found"))console.info("AWS CLI not found in PATH");else console.error("Error checking AWS credentials:",F)}return{configured:!1}}function Ag(){let D=process.platform;if(D==="darwin")return"brew install git-annex";if(D==="linux")return"apt install git-annex (Debian/Ubuntu)";return"See https://git-annex.branchable.com/install/"}async function v9(){let[D,F]=await Promise.all([_W(),Lg()]),$=[];if(!D.installed)$.push(`git-annex is not installed. Install: ${Ag()}`);else if(D.compatible===!1)$.push(`git-annex version ${D.version} is too old. Required: >= ${D.minVersion}`);if(!F.accessible){if(!(await Rg()).token)$.push("GitHub authentication not configured. Run 'gh auth login' to authenticate.")}return{gitAnnex:D,githubSSH:F,allPassed:$.length===0,errors:$}}async function w1(D){if(!yW(xW(D,".git")))return!1;try{let{exitCode:F}=await I(["git","annex","info"],{cwd:D});return F===0}catch(F){let $=F instanceof Error?F.message:String(F);if(!$.includes("ENOENT")&&!$.includes("not found"))console.error(`Error checking if ${D} is a git-annex dataset:`,$);return!1}}async function n6(D,F={}){if(!F.force&&await w1(D))return{success:!0};try{let $={};if(F.author)$.GIT_AUTHOR_NAME=F.author.name,$.GIT_AUTHOR_EMAIL=F.author.email,$.GIT_COMMITTER_NAME=F.author.name,$.GIT_COMMITTER_EMAIL=F.author.email;let{stderr:J,exitCode:Q}=await I(["git","init","-b","main",D],{...Object.keys($).length>0?{env:$}:{}});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git repository"};let Y=Object.keys($).length>0?{env:$}:{},{stderr:B,exitCode:X}=await I(["git","annex","init"],{cwd:D,...Y});if(X!==0)return{success:!1,error:B.trim()||"Failed to initialize git-annex"};let{stderr:G,exitCode:H}=await I(["git","commit","--allow-empty","-m","Initialize dataset"],{cwd:D,...Y});if(H!==0)return{success:!1,error:G.trim()||"Failed to create initial commit"};let{stderr:q,exitCode:K}=await I(["git","annex","adjust","--unlock"],{cwd:D,...Y});if(K!==0)return{success:!1,error:q.trim()||"Failed to switch to unlocked mode"};return{success:!0}}catch($){return{success:!1,error:$.message}}}async function fW(D){try{let{exitCode:F,stderr:$}=await I(["git","annex","info"],{cwd:D});if(F===0)return{success:!0};if($.includes("First run: git-annex init")){let{stderr:J,exitCode:Q}=await I(["git","annex","init"],{cwd:D});if(Q!==0)return{success:!1,error:J.trim()||"Failed to initialize git-annex"};return{success:!0}}return{success:!1,error:$.trim()||"Failed to check git-annex status"}}catch(F){return{success:!1,error:F.message}}}async function g4(D,F){let $=["*.edf","*.bdf","*.set","*.fif","*.vhdr","*.eeg","*.cnt","*.fdt"],J=["*.tsv","*.json","*.md","*.txt","*.yml","*.yaml","README*","LICENSE*","CHANGES*",".bidsignore",".gitignore"],Q=$.map((G)=>`include=${G}`).join(" or "),Y=J.map((G)=>`exclude=${G}`).join(" and "),B=`(${Q} or largerthan=100kb) and ${Y}`,X=F||B;try{let{stderr:G,exitCode:H}=await I(["git","annex","config","--set","annex.largefiles",X],{cwd:D});if(H!==0)return{success:!1,error:G.trim()||"Failed to configure largefiles"};return{success:!0}}catch(G){return{success:!1,error:G.message}}}async function i6(D,F="."){try{let{stderr:$,exitCode:J}=await I(["git","annex","add",F],{cwd:D});if(J!==0)return{success:!1,error:$.trim()||"Failed to add files to git-annex"};return{success:!0}}catch($){return{success:!1,error:$.message}}}function CD(D){return{accessKeyId:D.access_key_id,secretAccessKey:D.secret_access_key,sessionToken:D.session_token}}function vW(D){let F=[/^\(merging .* into .*\.\.\.\)$/,/^\(recording state in git\.\.\.\)$/,/^\(scanning for /,/^\(checking /];return D.split(`
101
101
  `).filter(($)=>{let J=$.trim();if(!J)return!1;if(J.includes("setting annex-ignore"))return!1;if(F.some((Q)=>Q.test(J)))return!1;return!0}).join(`
@@ -372,7 +372,7 @@ NEMAR E2E Test (nm099999)
372
372
  Upload dir: ${$.upload_dir}`)),console.log(W.dim(`Clone dir: ${$.clone_dir}`));process.exit($.passed?0:1)});var GH=new i0("sync").description("Sync dataset metadata to nemar.org datapipeline");GH.command("run").description("Sync a dataset to nemar.org").argument("<dataset-id>","Dataset ID (e.g., nm000103)").action(async(D)=>{if(!f0())return;let F=C(`Syncing ${D} to nemar.org...`).start();try{let $=await Fg(D);if($.synced)F.succeed(`${D} synced to nemar.org`);else{F.warn(`${D} sync completed with errors:`);for(let J of $.errors)console.log(W.red(` - ${J}`))}}catch($){F.fail(`Failed to sync ${D}`),console.error(W.red(w0($)))}});GH.command("status").description("Show nemar.org sync status for all published datasets").action(async()=>{if(!f0())return;let D=C("Fetching sync status...").start();try{let F=await $g();if(D.stop(),console.log(W.bold(`
373
373
  nemar.org Sync Status (${F.total} datasets)
374
374
  `)),console.log(` Synced: ${W.green(F.synced)} Failed: ${W.red(F.failed)} Pending: ${W.yellow(F.pending)}
375
- `),F.datasets.length===0){console.log(W.dim(" No published datasets found."));return}console.log(W.dim(` ${"ID".padEnd(12)} ${"Name".padEnd(40)} ${"Status".padEnd(10)} ${"Last Sync".padEnd(20)}`)),console.log(W.dim(` ${"\u2500".repeat(85)}`));for(let $ of F.datasets){let J=$.nemar_sync_status||"pending",Q=J==="synced"?W.green:J==="failed"?W.red:W.yellow,Y=$.nemar_sync_at?new Date($.nemar_sync_at).toLocaleDateString():"-",B=$.name||$.dataset_id,X=B.length>38?`${B.substring(0,35)}...`:B;if(console.log(` ${$.dataset_id.padEnd(12)} ${X.padEnd(40)} ${Q(J.padEnd(10))} ${Y}`),$.nemar_sync_error)console.log(W.red(` Error: ${$.nemar_sync_error}`))}}catch(F){D.fail("Failed to fetch sync status"),console.error(W.red(w0(F)))}});r0.addCommand(GH);function ug(D,F){let $=D.enrichment.status,J=$==="ok"?W.green("enrich:ok"):$==="failed"?W.red("enrich:failed"):W.dim("enrich:skipped"),Q=D.sync.status,Y=Q==="ok"?W.green("sync:ok"):Q==="failed"?W.red("sync:failed"):W.dim("sync:skipped"),B=D.sync.metadata_columns_written===!0?W.green("cols:written"):D.sync.metadata_columns_error?W.red("cols:failed"):"",X=F?.showRef&&D.enrichment.ref?W.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${J}${X} ${Y} ${B}`),D.enrichment.error)console.log(W.red(` enrichment: ${D.enrichment.error}`));if(D.sync.errors?.length)for(let G of D.sync.errors)console.log(W.red(` sync: ${G}`));if(D.sync.metadata_columns_error)console.log(W.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var pg=new i0("reindex").description("Refresh dataset metadata: enrichment + nemar.org sync + first-class D1 columns");pg.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 for --stale (default: 30)","30").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(!f0())return;let $=[F.all,F.missingMetadata,F.stale].filter(Boolean).length;if(D&&$>0)console.error(W.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(W.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(W.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(W.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=C(`Reindexing ${D}...`).start();try{let V={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},E=await Jg(D,V),Z=E.enrichment.status!=="failed"&&E.sync.status!=="failed";if(Z)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),ug(E,{showRef:!0}),!Z)process.exit(1)}catch(V){K.fail(`Failed to reindex ${D}`),console.error(W.red(w0(V))),process.exit(1)}return}let J=F.all?"all":F.missingMetadata?"missing-metadata":"stale",Q={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,dry_run:F.dryRun===!0};if(F.olderThan!==void 0){let K=Number.parseInt(F.olderThan,10);if(!Number.isFinite(K)||K<0)console.error(W.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);Q.older_than_days=K}let Y=F.dryRun?`Listing ${J} datasets...`:`Reindexing ${J} datasets...`,B=C(Y).start(),X;try{X=await Qg(J,Q)}catch(K){B.fail("Bulk reindex failed"),console.error(W.red(w0(K))),process.exit(1)}if(X.dry_run){if(B.succeed(`${X.total} datasets match filter=${J} (dry run, no changes)`),X.datasets)for(let K of X.datasets)console.log(W.dim(` - ${K}`));return}let G=X.results??[],H=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-H;if(q===0)B.succeed(`${G.length}/${G.length} datasets reindexed in ${(X.elapsed_ms/1000).toFixed(1)}s`);else B.warn(`${H}/${G.length} ok; ${q} failed in ${(X.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)ug(K);if(q>0)process.exit(1)});r0.addCommand(pg);var WH=new i0("email-preferences").description("Manage email notification preferences");WH.command("show").description("Show current email notification preferences").action(async()=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=C("Fetching email preferences...").start();try{let F=await Yg();D.succeed("Email notification preferences:"),console.log();let $=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let J of $){let Y=F[J.key]?W.green("enabled"):W.dim("disabled");console.log(` ${J.label.padEnd(40)} ${Y}`)}console.log(),console.log(W.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch(F){D.fail("Failed to fetch preferences"),console.error(W.red(w0(F)))}});WH.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").action(async(D)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(Q){if(Q===void 0)return;let Y=Q.toLowerCase();if(Y==="true"||Y==="1"||Y==="on"||Y==="yes")return!0;if(Y==="false"||Y==="0"||Y==="off"||Y==="no")return!1;console.error(W.red(`Invalid boolean value: "${Q}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let Q=F(D.all);$.user_approval=Q,$.publication_request=Q,$.announcements=Q}else{let Q=F(D.userApproval),Y=F(D.publicationRequest),B=F(D.announcements);if(Q===void 0&&Y===void 0&&B===void 0)console.error(W.red("No preferences specified.")),console.log(" --user-approval <bool> User approval notifications"),console.log(" --publication-request <bool> Publication request notifications"),console.log(" --announcements <bool> Announcement emails"),console.log(" --all <bool> All notifications"),process.exit(1);if(Q!==void 0)$.user_approval=Q;if(Y!==void 0)$.publication_request=Y;if(B!==void 0)$.announcements=B}let J=C("Updating email preferences...").start();try{let Q=await Bg($);J.succeed("Email preferences updated:"),console.log(),console.log(` User approval: ${Q.user_approval?W.green("enabled"):W.dim("disabled")}`),console.log(` Publication request: ${Q.publication_request?W.green("enabled"):W.dim("disabled")}`),console.log(` Announcements: ${Q.announcements?W.green("enabled"):W.dim("disabled")}`)}catch(Q){J.fail("Failed to update preferences"),console.error(W.red(w0(Q)))}});r0.addCommand(WH);var KQ=new i0("notice").description("Manage system notices displayed to CLI users");KQ.command("list").description("List all notices (including expired)").action(async()=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=C("Fetching notices...").start();try{let{notices:F}=await Gg();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let Q={critical:W.red.bold,warning:W.yellow,info:W.blue}[$.level]||W.white,Y=$.expires_at&&new Date($.expires_at)<new Date?W.dim(" (expired)"):"";if(console.log(` ${W.dim(`#${$.id}`)} ${Q(`[${$.level.toUpperCase()}]`)} ${W.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${W.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${W.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){QD(F,D,"Failed to fetch notices")}});KQ.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(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(W.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(W.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=C("Creating notice...").start();try{let $=await Wg({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($){QD($,F,"Failed to create notice")}});KQ.command("clear <id>").description("Delete a notice by ID").option(T0,j0).option(b0,y0).action(async(D,F)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(W.red("Invalid notice ID")),process.exit(1);if(!await k0(`Delete notice #${$}?`,F,!1))return;let Q=C("Deleting notice...").start();try{await Hg($),Q.succeed(`Notice #${$} deleted`)}catch(Y){QD(Y,Q,"Failed to delete notice")}});r0.addCommand(KQ);r0.command("notify").description("Send a broadcast email to users").requiredOption("--to <group>","Recipient group: all, admins, members").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(T0,j0).option(b0,y0).action(async(D)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["all","admins","members"].includes(D.to))console.error(W.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!mg(D.bodyFile))console.error(W.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=_E0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(W.red("Email body required. Use --body or --body-file.")),process.exit(1);if(D.dryRun){let Q=C("Checking recipients...").start();try{let Y=await PW({to:D.to,subject:D.subject,body:F,dry_run:!0});if("dry_run"in Y){Q.succeed(`Dry run: ${Y.recipient_count} recipient(s) in group "${Y.recipient_group}"`),console.log();for(let B of Y.recipients)console.log(` ${B}`)}}catch(Y){QD(Y,Q,"Failed to check recipients")}return}if(console.log(W.bold("Broadcast email preview:")),console.log(` To: ${W.cyan(D.to)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log(),!await k0("Send this broadcast email?",D,!1))return;let J=C("Sending broadcast...").start();try{let Q=await PW({to:D.to,subject:D.subject,body:F});if("broadcast_id"in Q)if(Q.failure_count>0){J.warn(`Broadcast sent: ${Q.recipient_count} delivered, ${Q.failure_count} failed`);for(let Y of Q.failed_recipients)console.log(W.red(` Failed: ${Y}`))}else J.succeed(`Broadcast sent to ${Q.recipient_count} recipient(s) (ID: ${Q.broadcast_id})`)}catch(Q){QD(Q,J,"Failed to send broadcast")}});xD();k6();n3();i8();x4();import{appendFileSync as gE0,existsSync as o6,mkdirSync as dg,readFileSync as EQ,writeFileSync as hE0}from"fs";import{homedir as bE0}from"os";import{join as zQ}from"path";var{spawn:cg}=globalThis.Bun;function u4(){let D=zQ(bE0(),".ssh");return{sshDir:D,privateKey:zQ(D,"nemar_ed25519"),publicKey:zQ(D,"nemar_ed25519.pub"),configFile:zQ(D,"config")}}function ng(){let D=u4();return o6(D.privateKey)&&o6(D.publicKey)}async function ig(D){let F=u4();if(!o6(F.sshDir))try{dg(F.sshDir,{mode:448})}catch($){return{success:!1,error:`Cannot create ~/.ssh directory: ${$.message}`}}if(o6(F.privateKey))try{return{success:!0,publicKey:EQ(F.publicKey,"utf-8").trim()}}catch($){return{success:!1,error:`NEMAR SSH key exists but cannot read public key: ${$.message}`}}try{let $=cg({cmd:["ssh-keygen","-t","ed25519","-f",F.privateKey,"-N","","-C",`nemar-cli-${D}`],stdout:"pipe",stderr:"pipe"}),J=await new Response($.stderr).text();if(await $.exited!==0)return{success:!1,error:`ssh-keygen failed: ${J}`};return{success:!0,publicKey:EQ(F.publicKey,"utf-8").trim()}}catch($){return{success:!1,error:`Failed to generate SSH key: ${$.message}`}}}function ag(){let D=u4();if(!o6(D.publicKey))return null;try{return EQ(D.publicKey,"utf-8").trim()}catch{return null}}function uE0(){let D=u4();if(!o6(D.configFile))return!1;try{let F=EQ(D.configFile,"utf-8");return F.includes("IdentityFile ~/.ssh/nemar_ed25519")||F.includes(`IdentityFile ${D.privateKey}`)}catch{return!1}}function og(){let D=u4();if(!o6(D.sshDir))try{dg(D.sshDir,{mode:448})}catch($){return{success:!1,error:`Cannot create ~/.ssh directory: ${$.message}`}}if(uE0())return{success:!0};let F=`
375
+ `),F.datasets.length===0){console.log(W.dim(" No published datasets found."));return}console.log(W.dim(` ${"ID".padEnd(12)} ${"Name".padEnd(40)} ${"Status".padEnd(10)} ${"Last Sync".padEnd(20)}`)),console.log(W.dim(` ${"\u2500".repeat(85)}`));for(let $ of F.datasets){let J=$.nemar_sync_status||"pending",Q=J==="synced"?W.green:J==="failed"?W.red:W.yellow,Y=$.nemar_sync_at?new Date($.nemar_sync_at).toLocaleDateString():"-",B=$.name||$.dataset_id,X=B.length>38?`${B.substring(0,35)}...`:B;if(console.log(` ${$.dataset_id.padEnd(12)} ${X.padEnd(40)} ${Q(J.padEnd(10))} ${Y}`),$.nemar_sync_error)console.log(W.red(` Error: ${$.nemar_sync_error}`))}}catch(F){D.fail("Failed to fetch sync status"),console.error(W.red(w0(F)))}});r0.addCommand(GH);function ug(D,F){let $=D.enrichment.status,J=$==="ok"?W.green("enrich:ok"):$==="failed"?W.red("enrich:failed"):W.dim("enrich:skipped"),Q=D.sync.status,Y=Q==="ok"?W.green("sync:ok"):Q==="failed"?W.red("sync:failed"):W.dim("sync:skipped"),B=D.sync.metadata_columns_written===!0?W.green("cols:written"):D.sync.metadata_columns_error?W.red("cols:failed"):"",X=F?.showRef&&D.enrichment.ref?W.dim(`@${D.enrichment.ref}`):"";if(console.log(` ${D.dataset_id.padEnd(12)} ${J}${X} ${Y} ${B}`),D.enrichment.error)console.log(W.red(` enrichment: ${D.enrichment.error}`));if(D.sync.errors?.length)for(let G of D.sync.errors)console.log(W.red(` sync: ${G}`));if(D.sync.metadata_columns_error)console.log(W.red(` metadata columns: ${D.sync.metadata_columns_error}`))}var pg=new i0("reindex").description("Refresh dataset metadata: enrichment + nemar.org sync + first-class D1 columns");pg.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 for --stale (default: 30)","30").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(!f0())return;let $=[F.all,F.missingMetadata,F.stale].filter(Boolean).length;if(D&&$>0)console.error(W.red("Provide either a dataset-id OR a bulk flag (--all/--missing-metadata/--stale), not both")),process.exit(1);if(!D&&$===0)console.error(W.red("Provide a dataset-id or one of: --all, --missing-metadata, --stale")),process.exit(1);if($>1)console.error(W.red("Use only one of --all, --missing-metadata, --stale")),process.exit(1);if(F.skipEnrichment&&F.skipSync)console.error(W.red("--skip-enrichment and --skip-sync cannot both be set")),process.exit(1);if(D){let K=C(`Reindexing ${D}...`).start();try{let V={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,...F.ref&&{ref:F.ref}},E=await Jg(D,V),Z=E.enrichment.status!=="failed"&&E.sync.status!=="failed";if(Z)K.succeed(`${D} reindexed`);else K.warn(`${D} reindexed with errors`);if(console.log(),ug(E,{showRef:!0}),!Z)process.exit(1)}catch(V){K.fail(`Failed to reindex ${D}`),console.error(W.red(w0(V))),process.exit(1)}return}let J=F.all?"all":F.missingMetadata?"missing-metadata":"stale",Q={skip_enrichment:F.skipEnrichment===!0,skip_sync:F.skipSync===!0,dry_run:F.dryRun===!0};if(F.olderThan!==void 0){let K=Number.parseInt(F.olderThan,10);if(!Number.isFinite(K)||K<0)console.error(W.red(`Invalid --older-than: "${F.olderThan}"`)),process.exit(1);Q.older_than_days=K}let Y=F.dryRun?`Listing ${J} datasets...`:`Reindexing ${J} datasets...`,B=C(Y).start(),X;try{X=await Qg(J,Q)}catch(K){B.fail("Bulk reindex failed"),console.error(W.red(w0(K))),process.exit(1)}if(X.dry_run){if(B.succeed(`${X.total} datasets match filter=${J} (dry run, no changes)`),X.datasets)for(let K of X.datasets)console.log(W.dim(` - ${K}`));return}let G=X.results??[],H=G.filter((K)=>K.enrichment.status!=="failed"&&K.sync.status!=="failed").length,q=G.length-H;if(q===0)B.succeed(`${G.length}/${G.length} datasets reindexed in ${(X.elapsed_ms/1000).toFixed(1)}s`);else B.warn(`${H}/${G.length} ok; ${q} failed in ${(X.elapsed_ms/1000).toFixed(1)}s`);console.log();for(let K of G)ug(K);if(q>0)process.exit(1)});r0.addCommand(pg);var WH=new i0("email-preferences").description("Manage email notification preferences");WH.command("show").description("Show current email notification preferences").action(async()=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=C("Fetching email preferences...").start();try{let F=await Yg();D.succeed("Email notification preferences:"),console.log();let $=[{key:"user_approval",label:"User approval notifications"},{key:"publication_request",label:"Publication request notifications"},{key:"announcements",label:"Announcement emails"}];for(let J of $){let Y=F[J.key]?W.green("enabled"):W.dim("disabled");console.log(` ${J.label.padEnd(40)} ${Y}`)}console.log(),console.log(W.dim(" Use 'nemar admin email-preferences update' to change settings."))}catch(F){D.fail("Failed to fetch preferences"),console.error(W.red(w0(F)))}});WH.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").action(async(D)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);function F(Q){if(Q===void 0)return;let Y=Q.toLowerCase();if(Y==="true"||Y==="1"||Y==="on"||Y==="yes")return!0;if(Y==="false"||Y==="0"||Y==="off"||Y==="no")return!1;console.error(W.red(`Invalid boolean value: "${Q}". Use true/false, on/off, yes/no.`)),process.exit(1)}let $={};if(D.all!==void 0){let Q=F(D.all);$.user_approval=Q,$.publication_request=Q,$.announcements=Q}else{let Q=F(D.userApproval),Y=F(D.publicationRequest),B=F(D.announcements);if(Q===void 0&&Y===void 0&&B===void 0)console.error(W.red("No preferences specified.")),console.log(" --user-approval <bool> User approval notifications"),console.log(" --publication-request <bool> Publication request notifications"),console.log(" --announcements <bool> Announcement emails"),console.log(" --all <bool> All notifications"),process.exit(1);if(Q!==void 0)$.user_approval=Q;if(Y!==void 0)$.publication_request=Y;if(B!==void 0)$.announcements=B}let J=C("Updating email preferences...").start();try{let Q=await Bg($);J.succeed("Email preferences updated:"),console.log(),console.log(` User approval: ${Q.user_approval?W.green("enabled"):W.dim("disabled")}`),console.log(` Publication request: ${Q.publication_request?W.green("enabled"):W.dim("disabled")}`),console.log(` Announcements: ${Q.announcements?W.green("enabled"):W.dim("disabled")}`)}catch(Q){J.fail("Failed to update preferences"),console.error(W.red(w0(Q)))}});r0.addCommand(WH);var KQ=new i0("notice").description("Manage system notices displayed to CLI users");KQ.command("list").description("List all notices (including expired)").action(async()=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let D=C("Fetching notices...").start();try{let{notices:F}=await Gg();if(F.length===0){D.succeed("No notices found.");return}D.succeed(`${F.length} notice(s):`),console.log();for(let $ of F){let Q={critical:W.red.bold,warning:W.yellow,info:W.blue}[$.level]||W.white,Y=$.expires_at&&new Date($.expires_at)<new Date?W.dim(" (expired)"):"";if(console.log(` ${W.dim(`#${$.id}`)} ${Q(`[${$.level.toUpperCase()}]`)} ${W.dim(`scope:${$.scope}`)}${Y}`),console.log(` ${$.message}`),console.log(` ${W.dim(`Created: ${$.created_at}`)}`),$.expires_at)console.log(` ${W.dim(`Expires: ${$.expires_at}`)}`);console.log()}}catch(F){QD(F,D,"Failed to fetch notices")}});KQ.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(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(!["info","warning","critical"].includes(D.level))console.error(W.red(`Invalid level: ${D.level}. Use info, warning, or critical.`)),process.exit(1);if(!["all","admins","members"].includes(D.scope))console.error(W.red(`Invalid scope: ${D.scope}. Use all, admins, or members.`)),process.exit(1);let F=C("Creating notice...").start();try{let $=await Wg({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($){QD($,F,"Failed to create notice")}});KQ.command("clear <id>").description("Delete a notice by ID").option(T0,j0).option(b0,y0).action(async(D,F)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);let $=Number.parseInt(D,10);if(Number.isNaN($))console.error(W.red("Invalid notice ID")),process.exit(1);if(!await k0(`Delete notice #${$}?`,F,!1))return;let Q=C("Deleting notice...").start();try{await Hg($),Q.succeed(`Notice #${$} deleted`)}catch(Y){QD(Y,Q,"Failed to delete notice")}});r0.addCommand(KQ);r0.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(T0,j0).option(b0,y0).action(async(D)=>{if(!L0())console.error(W.red("Not authenticated. Run: nemar auth login")),process.exit(1);if(D.to&&D.user)console.error(W.red("--to and --user are mutually exclusive. Provide exactly one.")),process.exit(1);if(!D.to&&!D.user)console.error(W.red("Provide either --to <group> or --user <username>.")),process.exit(1);if(D.to&&!["all","admins","members"].includes(D.to))console.error(W.red(`Invalid group: ${D.to}. Use all, admins, or members.`)),process.exit(1);let F;if(D.bodyFile){if(!mg(D.bodyFile))console.error(W.red(`File not found: ${D.bodyFile}`)),process.exit(1);F=_E0(D.bodyFile,"utf-8")}else if(D.body)F=D.body;else console.error(W.red("Email body required. Use --body or --body-file.")),process.exit(1);let $=D.user?`user:${D.user}`:D.to,J=D.user?{user:D.user,subject:D.subject,body:F}:{to:D.to,subject:D.subject,body:F};if(D.dryRun){let X=C("Checking recipients...").start();try{let G=await PW({...J,dry_run:!0});if("dry_run"in G){X.succeed(`Dry run: ${G.recipient_count} recipient(s) for "${G.recipient_group}"`),console.log();for(let H of G.recipients)console.log(` ${H}`)}}catch(G){QD(G,X,"Failed to check recipients")}return}console.log(W.bold("Email preview:")),console.log(` To: ${W.cyan($)}`),console.log(` Subject: ${D.subject}`),console.log(` Body: ${F.length>100?`${F.substring(0,100)}...`:F}`),console.log();let Q=D.user?`Send this email to ${D.user}?`:"Send this broadcast email?";if(!await k0(Q,D,!1))return;let B=C(D.user?`Sending to ${D.user}...`:"Sending broadcast...").start();try{let X=await PW(J);if("broadcast_id"in X)if(X.failure_count>0){B.warn(`Email send: ${X.recipient_count} delivered, ${X.failure_count} failed`);for(let G of X.failed_recipients)console.log(W.red(` Failed: ${G}`))}else{let G=D.user?`Email sent to ${D.user}`:`Broadcast sent to ${X.recipient_count} recipient(s)`;B.succeed(`${G} (ID: ${X.broadcast_id})`)}}catch(X){QD(X,B,"Failed to send email")}});xD();k6();n3();i8();x4();import{appendFileSync as gE0,existsSync as o6,mkdirSync as dg,readFileSync as EQ,writeFileSync as hE0}from"fs";import{homedir as bE0}from"os";import{join as zQ}from"path";var{spawn:cg}=globalThis.Bun;function u4(){let D=zQ(bE0(),".ssh");return{sshDir:D,privateKey:zQ(D,"nemar_ed25519"),publicKey:zQ(D,"nemar_ed25519.pub"),configFile:zQ(D,"config")}}function ng(){let D=u4();return o6(D.privateKey)&&o6(D.publicKey)}async function ig(D){let F=u4();if(!o6(F.sshDir))try{dg(F.sshDir,{mode:448})}catch($){return{success:!1,error:`Cannot create ~/.ssh directory: ${$.message}`}}if(o6(F.privateKey))try{return{success:!0,publicKey:EQ(F.publicKey,"utf-8").trim()}}catch($){return{success:!1,error:`NEMAR SSH key exists but cannot read public key: ${$.message}`}}try{let $=cg({cmd:["ssh-keygen","-t","ed25519","-f",F.privateKey,"-N","","-C",`nemar-cli-${D}`],stdout:"pipe",stderr:"pipe"}),J=await new Response($.stderr).text();if(await $.exited!==0)return{success:!1,error:`ssh-keygen failed: ${J}`};return{success:!0,publicKey:EQ(F.publicKey,"utf-8").trim()}}catch($){return{success:!1,error:`Failed to generate SSH key: ${$.message}`}}}function ag(){let D=u4();if(!o6(D.publicKey))return null;try{return EQ(D.publicKey,"utf-8").trim()}catch{return null}}function uE0(){let D=u4();if(!o6(D.configFile))return!1;try{let F=EQ(D.configFile,"utf-8");return F.includes("IdentityFile ~/.ssh/nemar_ed25519")||F.includes(`IdentityFile ${D.privateKey}`)}catch{return!1}}function og(){let D=u4();if(!o6(D.sshDir))try{dg(D.sshDir,{mode:448})}catch($){return{success:!1,error:`Cannot create ~/.ssh directory: ${$.message}`}}if(uE0())return{success:!0};let F=`
376
376
  # NEMAR CLI SSH key (auto-generated)
377
377
  Host github.com
378
378
  AddKeysToAgent yes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nemar-cli",
3
- "version": "0.8.13",
3
+ "version": "0.8.14-PR461.8df6f6a",
4
4
  "description": "CLI for NEMAR (Neuroelectromagnetic Data Archive and Tools Resource) dataset management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",