@kitelev/exocortex-cli 16.21.0 → 16.22.0

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v16.21.0
2
+ // @kitelev/exocortex-cli v16.22.0
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -761,7 +761,7 @@ ${r}`}o(nX,"serializeFile");function RD(n,e,t={}){let r=Ug.default.dirname(n),i=
761
761
  `).map(s=>s.trim()).filter(Boolean)){let s=iX.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let a=sX.exec(i);a&&r.push({sessionName:i,uuid:a[1],type:"short"})}return r}o(oX,"listClaudeChildSessions");function cX(n,e,t){let r=null,i=e.toLowerCase();function s(a){if(r)return;let c;try{c=(0,Wg.readdirSync)(a,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,OD.join)(a,l.name);if(l.isDirectory())s(u);else if(l.name.endsWith(".md")){let f=l.name.slice(0,-3).toLowerCase();(t==="full"&&f===i||t==="short"&&f.startsWith(i))&&(r=u)}}}return o(s,"walk"),s(n),r}o(cX,"findVaultFile");function lX(n,e){try{let i=(e??(s=>(0,Wg.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(aX):!1}catch{return!1}}o(lX,"isTaskDoing");async function FD(n,e=qg.exec,t){let r=await oX(e),i=[];for(let s of r){let a=cX(n,s.uuid,s.type);if(!a){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}lX(a,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:a,reason:"vault task status != Doing"})}return i}o(FD,"detectOrphans");async function DD(n,e,t=qg.exec,r=RD){let i=PD(t);if(e)return{ok:!0};let s=new Date().toISOString();if(n.taskFilePath)try{r(n.taskFilePath,{ems__Effort_status:"[[ems__EffortStatusFailed]]",aiTask__Task_lastError:`orphan recovery: ${n.reason}`,exo__Asset_updatedAt:s})}catch(a){return{ok:!1,error:`vault update failed: ${a.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}o(DD,"recoverOrphan");function uX(){return process.env.EXOCORTEX_VAULT??(0,Gg.join)((0,LD.homedir)(),"vault-2025")}o(uX,"defaultVault");function kD(){return new Ie("recover").description("Detect and recover orphaned claude-child tmux sessions. A session is orphaned when the corresponding vault task is not in Doing status. Default mode: dry-run (no changes). Use --apply to perform recovery.").option("--vault <path>","Path to Obsidian vault",uX()).option("--dry-run","List orphans without applying changes (default)",!1).option("--apply","Apply orphan recovery: set Failed + kill tmux session",!1).action(async n=>{let e=(0,Gg.resolve)(n.vault);if(!(0,ND.existsSync)(e)){console.error(`[recover] vault not found: ${e}`),process.exitCode=1;return}let t=!n.apply;console.log(`[recover] vault=${e} mode=${t?"dry-run":"apply"}`);let r=await FD(e);if(r.length===0){console.log("[recover] No orphaned claude-child sessions found.");return}console.log(`[recover] Found ${r.length} orphan(s):`);for(let a of r){let c=a.taskFilePath??"(not found in vault)";console.log(` session=${a.sessionName} uuid=${a.taskUuid} reason=${a.reason}`),console.log(` file=${c}`)}if(t){console.log("[recover] Dry-run mode: no changes applied. Use --apply to recover.");return}let i=0,s=0;for(let a of r){let c=await DD(a,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${a.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${a.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}o(kD,"recoverCommand");var _2=require("fs"),zg=require("path"),Gn=ce(fr());function fX(n,e){return e.concat([n])}o(fX,"collectAlso");var dX="https://exocortex.my/ontology/find#Alias_sparql",hX="https://exocortex.my/ontology/exo#Asset_label";function Yl(n){if(n&&typeof n=="object"&&"value"in n){let e=n.value;return typeof e=="string"?e:String(e)}return String(n)}o(Yl,"nodeValue");async function pX(n,e){let t=await n.match(void 0,void 0,void 0),r=[];for(let s of t)Yl(s.predicate)!==hX||Yl(s.object)!==e||r.push(Yl(s.subject));if(r.length===0)return null;let i=[];for(let s of r)for(let a of t)Yl(a.predicate)===dX&&Yl(a.subject)===s&&i.push(Yl(a.object));if(i.length===0)return null;if(i.length>1)throw new Bt(`Ambiguous find__Alias "${e}" \u2014 ${i.length} instances define a sparql fragment`,`Ensure exactly one find__Alias asset has exo:Asset_label "${e}"`);return i[0]}o(pX,"resolveAliasFragment");var mX=/^([a-z][a-zA-Z0-9]*)__([A-Za-z0-9_]+)$/,gX="https://exocortex.my/ontology/";function yX(n,e){let t=mX.exec(e);if(t){let i=`<${gX}${t[1]}#${t[2]}>`;return n.replace(/\?value\b/g,i)}let r=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return n.replace(/\?value\b/g,`"${r}"`)}o(yX,"bindValueLiteral");function jD(){return new Ie("find").description("Find vault assets via SPARQL \u2014 outputs file paths one per line (RFC 8e83442b T1.1)").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--also <path>","Additional vault to include (repeatable)",fX,[]).option("--sparql <query>","SPARQL SELECT query (must bind ?path)").option("--class <value>","Filter by class label via find__Alias 'class' (e.g. ems__Task)").action(async n=>{pe.setFormat("text");try{if(n.sparql&&n.class)throw new Bt("--sparql and --class are mutually exclusive","Pass either a raw --sparql query or a find__Alias-backed flag like --class");if(!n.sparql&&!n.class)throw new Bt("one of --sparql <query> or --class <value> is required",'exocortex find --class ems__Task OR exocortex find --sparql "SELECT ?path WHERE { ... }"');let e=(0,zg.resolve)(n.vault);if(!(0,_2.existsSync)(e))throw new Fe(e);let t=new kt(e),i=await new Gn.NoteToRDFConverter(t).convertVault(),s=n.also||[];for(let w of s){let T=(0,zg.resolve)(w);if(!(0,_2.existsSync)(T))throw new Fe(T);let C=new kt(T),L=await new Gn.NoteToRDFConverter(C).convertVault();i=i.concat(L)}let a=new Gn.InMemoryTripleStore;await a.addAll(i);let c;if(n.class){let w=await pX(a,"class");if(w===null)throw new Bt('No find__Alias with exo:Asset_label "class" was found in the vault',"Seed a find__Alias asset (label=class) or fall back to exocortex find --sparql");c=`SELECT ?path WHERE { ${yX(w,n.class)} }`}else c=n.sparql;let l=ql(c);l=Xa(l);let u=new Gn.ExoQLParser,f=Ja(Ya(e));for(let w of s){let T=Ja(Ya((0,zg.resolve)(w)));for(let[C,V]of T)f.has(C)||f.set(C,V)}f.size>0&&u.setVaultPrefixes(f);let d=u.parse(l),p=new Gn.ExoQLAlgebraTranslator().translate(d);p.type!=="construct"&&(p=new Gn.AlgebraOptimizer().optimize(p));let S=await new Gn.ExoQLQueryExecutor(a).executeAll(p),v="obsidian://vault/";for(let w of S){let C=w.toJSON().path;if(typeof C!="string"||!C.startsWith(v))continue;let V=C.slice(v.length),L;try{L=decodeURIComponent(V)}catch{L=V}process.stdout.write(L+`
762
762
  `)}}catch(e){pe.handle(e),process.exit(5)}})}o(jD,"findCommand");var w2=require("fs"),v2=require("path"),De=ce(fr());var qD=ce(fr()),Ft=ce(VD());var BD="obsidian://vault/";function OX(n){let e=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;return{async resolveTargetPath(t){if(!t)throw new Error("Cannot resolve empty targetIRI to a vault path");let r=t;if(r.startsWith(BD))r=decodeURI(r.slice(BD.length));else if(e.test(r)){let i=await n.findFileByUID(r);if(!i)throw new Error(`No vault file found for UID: ${r}`);r=i}if(r.endsWith(".md")||(r=`${r}.md`),!await n.fileExists(r))throw new Error(`Cannot resolve target file for IRI "${t}" (tried "${r}")`);return r}}}o(OX,"createCliPathResolver");var PX=["openFile","sparqlSelect","getActiveFileIRI","getActiveFilePath","trashFile","duplicateFile"],S2=class extends Error{constructor(t){super(`Service "${t}" is not implemented in the CLI (no-op stub). dyncommand exec on this service_call grounding cannot change vault state. See CLI parity issues #2865-#2868 for port status.`);this.serviceId=t;this.name="CliServiceNotImplementedError"}static{o(this,"CliServiceNotImplementedError")}};function UD(n){return{async execute(){throw new S2(n)}}}o(UD,"notImplementedService");function FX(n){return e=>{let t=n.getFirstLinkpathDest(e,"");if(!t||!("basename"in t))return null;let i=n.getFrontmatter(t)?.exo__Asset_label;return typeof i=="string"&&i.length>0?i:null}}o(FX,"createCliClassResolver");function WD(n,e){for(let t of PX)n.register(t,UD(t));for(let t of["updateProperty","removeProperty","setStatus","createAsset"])n.register(t,UD(t));if(e){if(e.fsAdapter){let t=new qD.FrontmatterService,r=OX(e.fsAdapter);n.register("updateProperty",(0,Ft.createUpdatePropertyService)(e.fsAdapter,t,r)),n.register("removeProperty",(0,Ft.createRemovePropertyService)(e.fsAdapter,t,r)),n.register("setStatus",(0,Ft.createSetStatusService)(e.fsAdapter,t,r)),n.register("createAsset",(0,Ft.createCreateAssetService)(e.vaultAdapter,e.fsAdapter,FX(e.vaultAdapter)))}n.register("createRelatedTask",(0,Ft.createCreateRelatedTaskService)(e.vaultAdapter,e.genericAssetCreationService)),n.register("createRelatedProject",(0,Ft.createCreateRelatedProjectService)(e.vaultAdapter,e.genericAssetCreationService)),n.register("archiveAsset",(0,Ft.createArchiveAssetService)(e.vaultAdapter,e.archiveAssetService)),n.register("planForEvening",(0,Ft.createPlanForEveningService)(e.vaultAdapter,e.taskStatusService)),n.register("cleanProperties",(0,Ft.createCleanPropertiesService)(e.vaultAdapter,e.propertyCleanupService)),n.register("renameToUid",(0,Ft.createRenameToUidService)(e.vaultAdapter,e.renameToUidService)),n.register("repairFolder",(0,Ft.createRepairFolderService)(e.vaultAdapter,e.folderRepairService)),n.register("fixMissingLabel",(0,Ft.createFixMissingLabelService)(e.vaultAdapter,e.fixMissingLabelService))}}o(WD,"populateCliServiceRegistry");var DX=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;async function NX(){if(process.stdin.isTTY)return[];let n=[];for await(let t of process.stdin)n.push(t);return Buffer.concat(n).toString("utf-8").split(`
763
763
  `).map(t=>t.trim()).filter(t=>t.length>0)}o(NX,"readStdinLines");function Qg(n){if(n&&typeof n=="object"&&"value"in n){let e=n.value;return typeof e=="string"?e:String(e)}return String(n)}o(Qg,"nodeValue");async function LX(n,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_cliName"),r=await n.match(void 0,t,void 0),i=[];for(let s of r)if(Qg(s.object)===e){let l=Qg(s.subject).match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.md$/i);l&&i.push(l[1])}if(i.length===0)return null;if(i.length>1)throw new Bt(`Ambiguous cliName "${e}" \u2014 resolves to ${i.length} commands: ${i.join(", ")}`,"Use the UUID directly: exocortex apply <uuid> <path>");return i[0]}o(LX,"resolveSlugToUuid");async function kX(n,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_destructive"),r=await n.match(void 0,t,void 0);for(let i of r)if(Qg(i.subject).includes(e)){let a=Qg(i.object);if(a==="true"||a==="True")return!0}return!1}o(kX,"isDestructive");async function jX(n,e,t,r,i,s,a){let c=(0,v2.resolve)(n,r);if(!(0,w2.existsSync)(c))return console.error(`\u274C Target file not found: ${r}`),!1;let u=await new De.CommandResolver(e).loadCommand(t);if(!u)return console.error(`\u274C Command with UID "${t}" not found.`),!1;if(await kX(e,t)&&!i.dryRun&&!i.yes)return console.error(`\u274C Command "${u.name}" is marked destructive. Add --dry-run to preview, or --yes to apply.`),!1;let d=(0,De.vaultPathToIRI)(r);if(!await new De.PreconditionEvaluator(e,void 0,{clock:s}).evaluate(u.precondition,d))return console.error(`\u274C Precondition not satisfied for "${u.name}" on "${r}".`),!1;if(i.dryRun)return console.log(`\u{1F50D} Dry-run: would apply "${u.name}" to "${r}" (precondition passed).`),!0;let y=new De.ServiceRegistry,S=new kt(n),v=new De.GenericAssetCreationService(S).withDeterminism({clock:s,uidGenerator:a}),w=new De.ArchiveAssetService(S),T=new De.PropertyCleanupService(S),C=new De.FixMissingLabelService(S),V=new De.RenameToUidService(S),L=new De.FolderRepairService(S),ee=new De.TaskStatusService(S,new De.EffortStatusWorkflow,new De.StatusTimestampService(S)),B=new pr(n);WD(y,{vaultAdapter:S,fsAdapter:B,genericAssetCreationService:v,archiveAssetService:w,taskStatusService:ee,propertyCleanupService:T,fixMissingLabelService:C,renameToUidService:V,folderRepairService:L});let W=new De.GroundingExecutor(B,B,y,void 0,{clock:s,uidGenerator:a}),F;if(i.input)try{let G=JSON.parse(i.input);if(typeof G!="object"||G===null||Array.isArray(G))throw new Error("must be a JSON object");F=G}catch(G){let Re=G instanceof Error?G.message:String(G);return console.error(`\u274C --input: invalid JSON object (${Re})`),!1}let D=await W.execute(u.grounding,d,r,F);if(D.success){let G=u.successMessage??`Applied "${u.name}" to "${r}".`;return console.log(`\u2705 ${G}`),!0}else return console.error(`\u274C "${u.name}" failed on "${r}": ${D.error}`),!1}o(jX,"executeOnTarget");function GD(){return new Ie("apply").description("Apply an exocmd__Command to one or more vault assets (RFC 8e83442b T1.2). Pass a path arg or pipe paths via stdin.").argument("<cmd>","Command UUID or cliName slug").argument("[path]","Vault-relative path to target asset (omit to read paths from stdin)").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--dry-run","Preview without writing").option("--yes","Skip destructive-command confirmation").option("--input <json>","JSON userInput for service_call groundings").option("--seed <uuid>","Deterministic UID seed for test/replay (uses seededUidGenerator)").option("--frozen-clock <iso>","Freeze clock to ISO timestamp for test/replay (uses frozenClock)").action(async(n,e,t)=>{pe.setFormat("text");try{let r=(0,v2.resolve)(t.vault);if(!(0,w2.existsSync)(r))throw new Fe(r);let i=t.frozenClock?(0,De.frozenClock)(t.frozenClock):(0,De.liveClock)(),s=t.seed?(0,De.seededUidGenerator)(t.seed):(0,De.liveUidGenerator)(),a=new kt(r),l=await new De.NoteToRDFConverter(a).convertVault(),u=new De.InMemoryTripleStore;await u.addAll(l);let f;if(DX.test(n))f=n;else{let y=await LX(u,n);y||(console.error(`\u274C No command found with UUID or cliName "${n}".`),process.exit(3)),f=y}let d;if(e)d=[e];else if(d=await NX(),d.length===0)throw new Bt("No target path provided and stdin is empty.","exocortex apply <uuid> <path> OR exocortex find ... | exocortex apply <uuid>");let h=0,p=0;for(let y of d)await jX(r,u,f,y,t,i,s)?h++:p++;d.length>1&&console.log(`
764
- \u{1F4CA} Applied to ${h}/${d.length} target(s) (${p} failed).`),p>0&&process.exit(5)}catch(r){pe.handle(r),process.exit(5)}})}o(GD,"applyCommand");function zD(n){let e=new Ie;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.21.0"),e.addCommand(jD()),e.addCommand(GD()),e.addCommand(pF()),e.addCommand(_F()),e.addCommand(WF()),e.addCommand(wF()),e.addCommand(vF()),e.addCommand(IF()),e.addCommand(HF()),e.addCommand(tD()),e.addCommand(iD()),e.addCommand(sD()),e.addCommand(oD()),e.addCommand(_D()),e.addCommand(bD()),e.addCommand(xD()),e.addCommand(kD()),e}o(zD,"createProgram");zD().parse();0&&(module.exports={createProgram});
764
+ \u{1F4CA} Applied to ${h}/${d.length} target(s) (${p} failed).`),p>0&&process.exit(5)}catch(r){pe.handle(r),process.exit(5)}})}o(GD,"applyCommand");function zD(n){let e=new Ie;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.22.0"),e.addCommand(jD()),e.addCommand(GD()),e.addCommand(pF()),e.addCommand(_F()),e.addCommand(WF()),e.addCommand(wF()),e.addCommand(vF()),e.addCommand(IF()),e.addCommand(HF()),e.addCommand(tD()),e.addCommand(iD()),e.addCommand(sD()),e.addCommand(oD()),e.addCommand(_D()),e.addCommand(bD()),e.addCommand(xD()),e.addCommand(kD()),e}o(zD,"createProgram");zD().parse();0&&(module.exports={createProgram});
765
765
  /*! Bundled license information:
766
766
 
767
767
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "16.21.0",
3
+ "version": "16.22.0",
4
4
  "description": "CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more",
5
5
  "main": "dist/index.js",
6
6
  "bin": {