@kitelev/exocortex-cli 15.43.1 → 15.43.3
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/README.md +10 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -496,7 +496,11 @@ npx @kitelev/exocortex-cli archive --dry-run \
|
|
|
496
496
|
- `--year <year>` - Filter by resolution/end timestamp year (e.g. `2025`) **[required for archive mode]**
|
|
497
497
|
- `--dry-run` - Preview without writing files
|
|
498
498
|
- `--no-referenced` - Skip assets that are still referenced by active (non-archived) files **(default behavior)**. Pass `--referenced` to include them anyway.
|
|
499
|
-
|
|
499
|
+
|
|
500
|
+
**Exit codes:**
|
|
501
|
+
|
|
502
|
+
- `0` — Success (assets archived or dry-run preview completed)
|
|
503
|
+
- `1` — Error (invalid options, vault not found, missing required flags)
|
|
500
504
|
|
|
501
505
|
**What archive does:**
|
|
502
506
|
|
|
@@ -561,6 +565,11 @@ npx @kitelev/exocortex-cli unarchive --dry-run \
|
|
|
561
565
|
- `--archive-vault <path>` - Path to the archive vault **[required]**
|
|
562
566
|
- `--dry-run` - Preview without writing files
|
|
563
567
|
|
|
568
|
+
**Exit codes:**
|
|
569
|
+
|
|
570
|
+
- `0` — Success (asset restored or dry-run preview completed)
|
|
571
|
+
- `1` — Error (UUID not found in archive vault, invalid UUID format, vault not found)
|
|
572
|
+
|
|
564
573
|
**What unarchive does:**
|
|
565
574
|
|
|
566
575
|
1. Finds asset by UUID in archive vault (direct filename match, then frontmatter scan)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v15.43.
|
|
2
|
+
// @kitelev/exocortex-cli v15.43.3
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -603,7 +603,7 @@ Available classes: ${t.join(", ")}`),super(r),this.name="ClassNotFoundError"}},w
|
|
|
603
603
|
${ur.dump(i,{lineWidth:-1})}---
|
|
604
604
|
`}async transferFile(e,t){let r=e.content,i=e.metadata.exo__Asset_isDefinedBy;if(i){let a=this.extractWikilinkTarget(String(i));if(a){let c=this.getArchiveOntologyName(a);r=r.replace(String(i),String(i).replace(a,c))}}let s=e.uuid+".md";await this.archiveFs.writeFile(s,r),await this.activeFs.deleteFile(e.relativePath)}extractWikilinkTarget(e){let t=e.match(/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/);return t?t[1]:null}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}};var mv=X(require("path"));var yp=class{constructor(e,t){this.activeFs=e;this.archiveFs=t}static{o(this,"ArchiveVerifyService")}async verify(){let e=await this.activeFs.getMarkdownFiles(),t=await this.archiveFs.getMarkdownFiles(),r=new Set;for(let l of t){let u=mv.default.basename(l,".md");this.isUUID(u)&&r.add(u.toLowerCase())}let i=[],s=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;for(let l of e)try{let u=await this.activeFs.readFile(l);if(this.extractFrontmatter(u).archived===!0)continue;let h=u.match(s);if(h){let d=new Set;for(let p of h){let v=p.toLowerCase();r.has(v)&&!d.has(v)&&(d.add(v),i.push({uuid:v,referenced_from:l}))}}}catch{continue}let a=await this.checkArchiveOntologies(t),c=i.length===0&&a.length===0;return{broken_links:i.length,broken_link_details:i,missing_ontologies:a,stats:{active_files:e.length,archive_files:t.length},ok:c}}async checkArchiveOntologies(e){let t=new Set;for(let i of e)if(!mv.default.basename(i,".md").startsWith("!"))try{let a=await this.archiveFs.readFile(i),l=this.extractFrontmatter(a).exo__Asset_isDefinedBy;if(l){let u=this.extractWikilinkTarget(String(l));if(u&&u.startsWith("!")){let f=u.endsWith("_archive")?u:u+"_archive";t.add(f)}}}catch{continue}let r=[];for(let i of t){let s=i+".md";await this.archiveFs.fileExists(s)||r.push(i)}return r.sort()}extractWikilinkTarget(e){let t=e.match(/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/);return t?t[1]:null}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}};var rI=X(require("path"));var gv=100,vp=class{constructor(e,t){this.activeFs=e;this.archiveFs=t}static{o(this,"ArchiveCascadeService")}async cascade(e){let t={iterations:0,total_moved:0,still_blocked:0,iterations_detail:[]};for(let r=0;r<gv;r++){let i=await this.activeFs.getMarkdownFiles(),s=await this.readAllFiles(i),a=s.filter(h=>h.isArchived&&h.uuid),c=s.filter(h=>!h.isArchived);if(a.length===0)break;let l=this.buildReferenceSet(c.map(h=>h.content)),u=a.filter(h=>!l.has(h.uuid.toLowerCase()));if(u.length===0){t.still_blocked=a.length;break}let f=[];if(e.dryRun)for(let h of u)f.push(h.uuid);else{await this.createArchiveOntologies(u);for(let h of u)await this.transferFile(h),f.push(h.uuid)}if(t.iterations++,t.total_moved+=f.length,t.iterations_detail.push({iteration:t.iterations,moved:f}),e.dryRun){let h=a.length-u.length;t.still_blocked=h;break}}if(t.iterations>=gv)throw new Error(`MAX_ITERATIONS (${gv}) exceeded during cascade archive. This likely indicates a bug. Moved ${t.total_moved} assets before stopping.`);if(t.iterations>0&&t.still_blocked===0&&!e.dryRun){let r=await this.activeFs.getMarkdownFiles(),i=await this.readAllFiles(r);t.still_blocked=i.filter(s=>s.isArchived&&s.uuid).length}return t}async readAllFiles(e){let t=[];for(let r of e)try{let i=await this.activeFs.readFile(r),s=this.extractFrontmatter(i),a=s.archived===!0,c=this.extractUUID(r,s);t.push({relativePath:r,uuid:c||"",metadata:s,content:i,isArchived:a})}catch{continue}return t}buildReferenceSet(e){let t=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,r=new Set;for(let i of e){let s=i.match(t);if(s)for(let a of s)r.add(a.toLowerCase())}return r}async createArchiveOntologies(e){let t=this.collectOntologies(e),r=0;for(let[i]of t.entries()){let s=i+"_archive",a=s+".md";if(!await this.archiveFs.fileExists(a))try{let l=await this.activeFs.readFile(i+".md"),u=this.extractFrontmatter(l),f=u.exo__Ontology_url;if(f){let h=String(f).replace(/#$/,"")+"/archive#",d=this.buildOntologyFile(s,h,u);await this.archiveFs.writeFile(a,d),r++}}catch{continue}}return r}collectOntologies(e){let t=new Map;for(let r of e){let i=r.metadata.exo__Asset_isDefinedBy;if(!i)continue;let s=this.extractWikilinkTarget(String(i));if(!s)continue;let a=t.get(s)||[];a.push(r),t.set(s,a)}return t}buildOntologyFile(e,t,r){let i={exo__Instance_class:r.exo__Instance_class||"exo__Ontology",exo__Asset_label:`${r.exo__Asset_label||e} (Archive)`,exo__Ontology_url:t};return`---
|
|
605
605
|
${ur.dump(i,{lineWidth:-1})}---
|
|
606
|
-
`}async transferFile(e){let t=e.content,r=e.metadata.exo__Asset_isDefinedBy;if(r){let s=this.extractWikilinkTarget(String(r));if(s){let a=s+"_archive";t=t.replace(String(r),String(r).replace(s,a))}}let i=e.uuid+".md";await this.archiveFs.writeFile(i,t),await this.activeFs.deleteFile(e.relativePath)}extractWikilinkTarget(e){let t=e.match(/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/);return t?t[1]:null}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}extractUUID(e,t){let r=t.exo__Asset_uid;if(r)return String(r);let i=rI.default.basename(e,".md");return this.isUUID(i)?i:null}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}};var _p=class{constructor(e){this.fs=e}static{o(this,"ArchiveStatsService")}async collect(){let e=await this.fs.getMarkdownFiles(),t={total:0,by_class:{},by_year:{},cross:{}};for(let r of e)try{let i=await this.fs.readFile(r),s=this.extractFrontmatter(i);t.total++;let a=this.extractClass(s);t.by_class[a]=(t.by_class[a]??0)+1;let c=this.extractYear(s);t.by_year[c]=(t.by_year[c]??0)+1,t.cross[a]||(t.cross[a]={}),t.cross[a][c]=(t.cross[a][c]??0)+1}catch{continue}return t}extractClass(e){let t=e.exo__Instance_class;if(!t)return"unknown";let r=Array.isArray(t)?t[0]:t,i=String(r).replace(/^"|"$/g,""),s=i.match(/\[\[[^\]|]+\|([^\]]+)\]\]/);if(s)return s[1];let a=i.match(/\[\[([^\]]+)\]\]/);return a?a[1]:i||"unknown"}extractYear(e){let t=e.ems__Effort_resolutionTimestamp??e.ems__Effort_endTimestamp;if(!t)return"unknown";if(t instanceof Date){let s=t.getFullYear();return isNaN(s)?"unknown":s.toString()}let i=String(t).match(/^(\d{4})/);return i?i[1]:"unknown"}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}};function nI(){return new He("archive").description("Archive assets from active vault to archive vault (automated asset archival)").requiredOption("--vault <path>","Path to the active vault").requiredOption("--archive-vault <path>","Path to the archive vault").option("--class <names>","Comma-separated class short names or UUIDs (e.g. ems__Task,ems__Meeting)").option("--year <year>","Filter by resolution/end timestamp year (e.g. 2025)").option("--dry-run","Preview without writing files",!1).option("--no-referenced","Skip assets referenced by non-archived (default: true)").option("--
|
|
606
|
+
`}async transferFile(e){let t=e.content,r=e.metadata.exo__Asset_isDefinedBy;if(r){let s=this.extractWikilinkTarget(String(r));if(s){let a=s+"_archive";t=t.replace(String(r),String(r).replace(s,a))}}let i=e.uuid+".md";await this.archiveFs.writeFile(i,t),await this.activeFs.deleteFile(e.relativePath)}extractWikilinkTarget(e){let t=e.match(/\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/);return t?t[1]:null}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}extractUUID(e,t){let r=t.exo__Asset_uid;if(r)return String(r);let i=rI.default.basename(e,".md");return this.isUUID(i)?i:null}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}};var _p=class{constructor(e){this.fs=e}static{o(this,"ArchiveStatsService")}async collect(){let e=await this.fs.getMarkdownFiles(),t={total:0,by_class:{},by_year:{},cross:{}};for(let r of e)try{let i=await this.fs.readFile(r),s=this.extractFrontmatter(i);t.total++;let a=this.extractClass(s);t.by_class[a]=(t.by_class[a]??0)+1;let c=this.extractYear(s);t.by_year[c]=(t.by_year[c]??0)+1,t.cross[a]||(t.cross[a]={}),t.cross[a][c]=(t.cross[a][c]??0)+1}catch{continue}return t}extractClass(e){let t=e.exo__Instance_class;if(!t)return"unknown";let r=Array.isArray(t)?t[0]:t,i=String(r).replace(/^"|"$/g,""),s=i.match(/\[\[[^\]|]+\|([^\]]+)\]\]/);if(s)return s[1];let a=i.match(/\[\[([^\]]+)\]\]/);return a?a[1]:i||"unknown"}extractYear(e){let t=e.ems__Effort_resolutionTimestamp??e.ems__Effort_endTimestamp;if(!t)return"unknown";if(t instanceof Date){let s=t.getFullYear();return isNaN(s)?"unknown":s.toString()}let i=String(t).match(/^(\d{4})/);return i?i[1]:"unknown"}extractFrontmatter(e){let t=e.match(/^---\n([\s\S]*?)\n---/);if(!t)return{};try{let r=ur.load(t[1]);return typeof r=="object"&&r!==null?r:{}}catch{return{}}}};function nI(){return new He("archive").description("Archive assets from active vault to archive vault (automated asset archival)").requiredOption("--vault <path>","Path to the active vault").requiredOption("--archive-vault <path>","Path to the archive vault").option("--class <names>","Comma-separated class short names or UUIDs (e.g. ems__Task,ems__Meeting)").option("--year <year>","Filter by resolution/end timestamp year (e.g. 2025)").option("--dry-run","Preview without writing files",!1).option("--no-referenced","Skip assets referenced by non-archived (default: true)").option("--verify","Verify archive integrity instead of archiving (read-only)",!1).option("--cascade","Iteratively resolve archived-to-archived chains (no --class/--year needed)",!1).option("--stats","Print archive vault statistics by class and year (read-only)",!1).action(async n=>{try{let e=(0,yv.resolve)(n.vault);if(!(0,vv.existsSync)(e))throw new Qe(e);let t=(0,yv.resolve)(n.archiveVault);if(!(0,vv.existsSync)(t))throw new Qe(t);if(n.stats){let d=new Ot(t),v=await new _p(d).collect();process.stderr.write(gU(v)),process.stdout.write(JSON.stringify(v)+`
|
|
607
607
|
`),process.exit(0)}if(n.verify){let d=new Ot(e),p=new Ot(t),w=await new yp(d,p).verify();process.stdout.write(JSON.stringify(w,null,2)+`
|
|
608
608
|
`),process.exit(w.ok?0:1)}if(n.cascade){let d=new Ot(e),p=new Ot(t),w=await new vp(d,p).cascade({vaultPath:e,archiveVaultPath:t,dryRun:n.dryRun||!1});n.dryRun&&(process.stderr.write(`--- CASCADE DRY RUN PREVIEW ---
|
|
609
609
|
`),process.stderr.write(`Would move: ${w.total_moved} assets
|
|
@@ -627,7 +627,7 @@ ${ur.dump(i,{lineWidth:-1})}---
|
|
|
627
627
|
`),c.isDefinedBy&&process.stderr.write(`isDefinedBy: ${c.isDefinedBy}
|
|
628
628
|
`),process.stderr.write(`--- END PREVIEW ---
|
|
629
629
|
`)),process.stdout.write(JSON.stringify(c)+`
|
|
630
|
-
`),process.exit(0)}catch(e){q.handle(e)}})}o(iI,"unarchiveCommand");var Gr=new He;Gr.name("exocortex").description("CLI tool for Exocortex knowledge management system").version("15.43.
|
|
630
|
+
`),process.exit(0)}catch(e){q.handle(e)}})}o(iI,"unarchiveCommand");var Gr=new He;Gr.name("exocortex").description("CLI tool for Exocortex knowledge management system").version("15.43.3");var Sv=Gr.command("sparql").description("SPARQL query execution and cache management");Sv.addCommand(pA());Sv.addCommand(vA());Sv.addCommand(_A());Gr.addCommand(CC());Gr.addCommand(OC());Gr.addCommand(RC());Gr.addCommand(DC());Gr.addCommand(NC());Gr.addCommand($C());Gr.addCommand(qC());Gr.addCommand(HC());Gr.addCommand(YC());Gr.addCommand(eI());Gr.addCommand(nI());Gr.addCommand(iI());Gr.parse();
|
|
631
631
|
/*! Bundled license information:
|
|
632
632
|
|
|
633
633
|
reflect-metadata/Reflect.js:
|