@kitelev/exocortex-cli 16.9.2 → 16.9.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.
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.9.2
2
+ // @kitelev/exocortex-cli v16.9.3
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -764,7 +764,7 @@ ${r}`}o(NY,"serializeFile");function _D(n,e,t={}){let r=Bg.default.dirname(n),i=
764
764
  `).map(s=>s.trim()).filter(Boolean)){let s=LY.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let a=kY.exec(i);a&&r.push({sessionName:i,uuid:a[1],type:"short"})}return r}o(MY,"listClaudeChildSessions");function $Y(n,e,t){let r=null,i=e.toLowerCase();function s(a){if(r)return;let c;try{c=(0,qg.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,bD.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($Y,"findVaultFile");function VY(n,e){try{let i=(e??(s=>(0,qg.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(jY):!1}catch{return!1}}o(VY,"isTaskDoing");async function wD(n,e=Ug.exec,t){let r=await MY(e),i=[];for(let s of r){let a=$Y(n,s.uuid,s.type);if(!a){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}VY(a,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:a,reason:"vault task status != Doing"})}return i}o(wD,"detectOrphans");async function vD(n,e,t=Ug.exec,r=_D){let i=SD(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(vD,"recoverOrphan");function BY(){return process.env.EXOCORTEX_VAULT??(0,Wg.join)((0,TD.homedir)(),"vault-2025")}o(BY,"defaultVault");function AD(){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",BY()).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,Wg.resolve)(n.vault);if(!(0,ED.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 wD(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 vD(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(AD,"recoverCommand");var mE=require("fs"),Gg=require("path"),Gn=ce(Sr());function UY(n,e){return e.concat([n])}o(UY,"collectAlso");var qY="https://exocortex.my/ontology/find#Alias_sparql",WY="https://exocortex.my/ontology/exo#Asset_label";function eu(n){if(n&&typeof n=="object"&&"value"in n){let e=n.value;return typeof e=="string"?e:String(e)}return String(n)}o(eu,"nodeValue");async function GY(n,e){let t=await n.match(void 0,void 0,void 0),r=[];for(let s of t)eu(s.predicate)!==WY||eu(s.object)!==e||r.push(eu(s.subject));if(r.length===0)return null;let i=[];for(let s of r)for(let a of t)eu(a.predicate)===qY&&eu(a.subject)===s&&i.push(eu(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(GY,"resolveAliasFragment");var zY=/^([a-z][a-zA-Z0-9]*)__([A-Za-z0-9_]+)$/,HY="https://exocortex.my/ontology/";function QY(n,e){let t=zY.exec(e);if(t){let i=`<${HY}${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(QY,"bindValueLiteral");function xD(){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)",UY,[]).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=>{he.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,Gg.resolve)(n.vault);if(!(0,mE.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,Gg.resolve)(w);if(!(0,mE.existsSync)(T))throw new Fe(T);let C=new kt(T),$=await new Gn.NoteToRDFConverter(C).convertVault();i=i.concat($)}let a=new Gn.InMemoryTripleStore;await a.addAll(i);let c;if(n.class){let w=await GY(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 { ${QY(w,n.class)} }`}else c=n.sparql;let l=Hl(c);l=eo(l);let u=new Gn.ExoQLParser,f=to(Za(e));for(let w of s){let T=to(Za((0,Gg.resolve)(w)));for(let[C,M]of T)f.has(C)||f.set(C,M)}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 M=C.slice(v.length),$;try{$=decodeURIComponent(M)}catch{$=M}process.stdout.write($+`
765
765
  `)}}catch(e){he.handle(e),process.exit(5)}})}o(xD,"findCommand");var yE=require("fs"),_E=require("path"),tt=ce(Sr());var PD=ce(Sr()),qt=ce(CD());var RD="obsidian://vault/";function aX(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(RD))r=decodeURI(r.slice(RD.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(aX,"createCliPathResolver");var oX=["createAsset","openFile","sparqlSelect","getActiveFileIRI","getActiveFilePath","trashFile","duplicateFile"],gE=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 OD(n){return{async execute(){throw new gE(n)}}}o(OD,"notImplementedService");function FD(n,e){for(let t of oX)n.register(t,OD(t));for(let t of["updateProperty","removeProperty","setStatus"])n.register(t,OD(t));if(e){if(e.fsAdapter){let t=new PD.FrontmatterService,r=aX(e.fsAdapter);n.register("updateProperty",(0,qt.createUpdatePropertyService)(e.fsAdapter,t,r)),n.register("removeProperty",(0,qt.createRemovePropertyService)(e.fsAdapter,t,r)),n.register("setStatus",(0,qt.createSetStatusService)(e.fsAdapter,t,r))}n.register("createRelatedTask",(0,qt.createCreateRelatedTaskService)(e.vaultAdapter,e.genericAssetCreationService)),n.register("createRelatedProject",(0,qt.createCreateRelatedProjectService)(e.vaultAdapter,e.genericAssetCreationService)),n.register("archiveAsset",(0,qt.createArchiveAssetService)(e.vaultAdapter,e.archiveAssetService)),n.register("planForEvening",(0,qt.createPlanForEveningService)(e.vaultAdapter,e.taskStatusService)),n.register("cleanProperties",(0,qt.createCleanPropertiesService)(e.vaultAdapter,e.propertyCleanupService)),n.register("renameToUid",(0,qt.createRenameToUidService)(e.vaultAdapter,e.renameToUidService)),n.register("repairFolder",(0,qt.createRepairFolderService)(e.vaultAdapter,e.folderRepairService)),n.register("fixMissingLabel",(0,qt.createFixMissingLabelService)(e.vaultAdapter,e.fixMissingLabelService))}}o(FD,"populateCliServiceRegistry");var cX=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;async function lX(){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(`
766
766
  `).map(t=>t.trim()).filter(t=>t.length>0)}o(lX,"readStdinLines");function zg(n){if(n&&typeof n=="object"&&"value"in n){let e=n.value;return typeof e=="string"?e:String(e)}return String(n)}o(zg,"nodeValue");async function uX(n,e){let t=new tt.IRI("https://exocortex.my/ontology/exocmd#Command_cliName"),r=await n.match(void 0,t,void 0),i=[];for(let s of r)if(zg(s.object)===e){let l=zg(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(uX,"resolveSlugToUuid");async function fX(n,e){let t=new tt.IRI("https://exocortex.my/ontology/exocmd#Command_destructive"),r=await n.match(void 0,t,void 0);for(let i of r)if(zg(i.subject).includes(e)){let a=zg(i.object);if(a==="true"||a==="True")return!0}return!1}o(fX,"isDestructive");async function dX(n,e,t,r,i){let s=(0,_E.resolve)(n,r);if(!(0,yE.existsSync)(s))return console.error(`\u274C Target file not found: ${r}`),!1;let c=await new tt.CommandResolver(e).loadCommand(t);if(!c)return console.error(`\u274C Command with UID "${t}" not found.`),!1;if(await fX(e,t)&&!i.dryRun&&!i.yes)return console.error(`\u274C Command "${c.name}" is marked destructive. Add --dry-run to preview, or --yes to apply.`),!1;let u=(0,tt.vaultPathToIRI)(r);if(!await new tt.PreconditionEvaluator(e).evaluate(c.precondition,u))return console.error(`\u274C Precondition not satisfied for "${c.name}" on "${r}".`),!1;if(i.dryRun)return console.log(`\u{1F50D} Dry-run: would apply "${c.name}" to "${r}" (precondition passed).`),!0;let h=new tt.ServiceRegistry,p=new kt(n),y=new tt.GenericAssetCreationService(p),S=new tt.ArchiveAssetService(p),v=new tt.PropertyCleanupService(p),w=new tt.FixMissingLabelService(p),T=new tt.RenameToUidService(p),C=new tt.FolderRepairService(p),M=new tt.TaskStatusService(p,new tt.EffortStatusWorkflow,new tt.StatusTimestampService(p)),$=new mr(n);FD(h,{vaultAdapter:p,fsAdapter:$,genericAssetCreationService:y,archiveAssetService:S,taskStatusService:M,propertyCleanupService:v,fixMissingLabelService:w,renameToUidService:T,folderRepairService:C});let ee=new tt.GroundingExecutor($,$,h),B;if(i.input)try{let P=JSON.parse(i.input);if(typeof P!="object"||P===null||Array.isArray(P))throw new Error("must be a JSON object");B=P}catch(P){let D=P instanceof Error?P.message:String(P);return console.error(`\u274C --input: invalid JSON object (${D})`),!1}let z=await ee.execute(c.grounding,u,r,B);if(z.success){let P=c.successMessage??`Applied "${c.name}" to "${r}".`;return console.log(`\u2705 ${P}`),!0}else return console.error(`\u274C "${c.name}" failed on "${r}": ${z.error}`),!1}o(dX,"executeOnTarget");function DD(){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").action(async(n,e,t)=>{he.setFormat("text");try{let r=(0,_E.resolve)(t.vault);if(!(0,yE.existsSync)(r))throw new Fe(r);let i=new kt(r),a=await new tt.NoteToRDFConverter(i).convertVault(),c=new tt.InMemoryTripleStore;await c.addAll(a);let l;if(cX.test(n))l=n;else{let h=await uX(c,n);h||(console.error(`\u274C No command found with UUID or cliName "${n}".`),process.exit(3)),l=h}let u;if(e)u=[e];else if(u=await lX(),u.length===0)throw new Bt("No target path provided and stdin is empty.","exocortex apply <uuid> <path> OR exocortex find ... | exocortex apply <uuid>");let f=0,d=0;for(let h of u)await dX(r,c,l,h,t)?f++:d++;u.length>1&&console.log(`
767
- \u{1F4CA} Applied to ${f}/${u.length} target(s) (${d} failed).`),d>0&&process.exit(5)}catch(r){he.handle(r),process.exit(5)}})}o(DD,"applyCommand");function ND(n){let e=new Ie;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.9.2"),e.addCommand(xD()),e.addCommand(DD()),e.addCommand(iF()),e.addCommand(cF()),e.addCommand(DF()),e.addCommand(fF()),e.addCommand(dF()),e.addCommand(yF()),e.addCommand(kF()),e.addCommand(WF()),e.addCommand(HF()),e.addCommand(QF()),e.addCommand(YF()),e.addCommand(oD()),e.addCommand(cD()),e.addCommand(mD()),e.addCommand(AD()),e}o(ND,"createProgram");ND().parse();0&&(module.exports={createProgram});
767
+ \u{1F4CA} Applied to ${f}/${u.length} target(s) (${d} failed).`),d>0&&process.exit(5)}catch(r){he.handle(r),process.exit(5)}})}o(DD,"applyCommand");function ND(n){let e=new Ie;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.9.3"),e.addCommand(xD()),e.addCommand(DD()),e.addCommand(iF()),e.addCommand(cF()),e.addCommand(DF()),e.addCommand(fF()),e.addCommand(dF()),e.addCommand(yF()),e.addCommand(kF()),e.addCommand(WF()),e.addCommand(HF()),e.addCommand(QF()),e.addCommand(YF()),e.addCommand(oD()),e.addCommand(cD()),e.addCommand(mD()),e.addCommand(AD()),e}o(ND,"createProgram");ND().parse();0&&(module.exports={createProgram});
768
768
  /*! Bundled license information:
769
769
 
770
770
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "16.9.2",
3
+ "version": "16.9.3",
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": {