@kitelev/exocortex-cli 16.241.11 → 16.241.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v16.241.
|
|
2
|
+
// @kitelev/exocortex-cli v16.241.12
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -606,7 +606,7 @@ ${g}
|
|
|
606
606
|
`);return}e.dryRun||(0,ip.writeFileSync)(n,c,"utf-8"),process.stdout.write(JSON.stringify({path:i,changed:!0,dryRun:!!e.dryRun,removed:o.removed,...e.canonicalizeKeys?{canonicalized:l}:{},...u?{updatedAt:u}:{},...e.dryRun?{diff:i0e(s,c)}:{}})+`
|
|
607
607
|
`)}catch(t){ce.handle(t)}})}a(N7,"repairFrontmatterCommand");at();var k7=require("fs"),M7=require("path"),ds=ee(Ve());Fo();Rt();Ut();ar();Aw();var s0e="https://exocortex.my/ontology/find#Alias_sparql",o0e="https://exocortex.my/ontology/exo#Asset_label";function sp(r){if(r&&typeof r=="object"&&"value"in r){let e=r.value;return typeof e=="string"?e:String(e)}return String(r)}a(sp,"nodeValue");async function a0e(r,e){let t=await r.match(void 0,void 0,void 0),n=[];for(let s of t)sp(s.predicate)!==o0e||sp(s.object)!==e||n.push(sp(s.subject));if(n.length===0)return null;let i=[];for(let s of n)for(let o of t)sp(o.predicate)===s0e&&sp(o.subject)===s&&i.push(sp(o.object));if(i.length===0)return null;if(i.length>1)throw new Ke(`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]}a(a0e,"resolveAliasFragment");var c0e=/^([a-z][a-zA-Z0-9]*)__([A-Za-z0-9_]+)$/,l0e="https://exocortex.my/ontology/";function u0e(r,e){let t=c0e.exec(e);if(t){let i=`<${l0e}${t[1]}#${t[2]}>`;return r.replace(/\?value\b/g,i)}let n=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return r.replace(/\?value\b/g,`"${n}"`)}a(u0e,"bindValueLiteral");function j7(){return new pe("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("--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 r=>{ce.setFormat("text");try{if(r.sparql&&r.class)throw new Ke("--sparql and --class are mutually exclusive","Pass either a raw --sparql query or a find__Alias-backed flag like --class");if(!r.sparql&&!r.class)throw new Ke("one of --sparql <query> or --class <value> is required",'exocortex find --class ems__Task OR exocortex find --sparql "SELECT ?path WHERE { ... }"');let e=(0,M7.resolve)(r.vault);if(!(0,k7.existsSync)(e))throw new ke(e);let t=new Zt(e),i=await new ds.NoteToRDFConverter(t).convertVault(),s=new ds.InMemoryTripleStore;await s.addAll(i);let o;if(r.class){let b=await a0e(s,"class");if(b===null)throw new Ke('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");o=`SELECT ?path WHERE { ${u0e(b,r.class)} }`}else o=r.sparql;let c=vw(o);c=Xd(c);let l=new ds.ExoQLParser,u=Tw(Ew(e));u.size>0&&l.setVaultPrefixes(u);let f=l.parse(c),p=new ds.ExoQLAlgebraTranslator().translate(f);p.type!=="construct"&&(p=new ds.AlgebraOptimizer().optimize(p));let g=await new ds.ExoQLQueryExecutor(s).executeAll(p),m="obsidian://vault/";for(let b of g){let E=b.toJSON().path;if(typeof E!="string"||!E.startsWith(m))continue;let I=E.slice(m.length),w;try{w=decodeURIComponent(I)}catch{w=I}process.stdout.write(w+`
|
|
608
608
|
`)}}catch(e){ce.handle(e),process.exit(5)}})}a(j7,"findCommand");at();var mP=require("fs"),Qa=require("path"),De=ee(Ve());Rt();Ut();ar();Fo();var Cn=ee(Ve());var Ww=new Map([["exo__Asset_uid",Cn.Namespace.EXO.term("Asset_uid").value],["exo__Asset_label",Cn.Namespace.EXO.term("Asset_label").value],["aliases",Cn.Namespace.EXO.term("Asset_aliases").value]]),zw=class r extends mi{constructor(t,n){super(t);this.source=n;this.indexPromise=null;this.pathKeys=new Map;this.stats={indexedLookups:0,scanFallbacks:0,candidateReads:0,zeroTripleReads:0}}static{a(this,"TripleStoreIndexedFsAdapter")}async findFilesByMetadata(t){let n=Object.entries(t);if(!(n.length>0&&n.every(([u,f])=>Ww.has(u)&&this.normalizeValue(f).length>0)))return this.stats.scanFallbacks++,super.findFilesByMetadata(t);let s=await this.ensureIndex();this.stats.indexedLookups++;let o=null;for(let[u,f]of n){let d=s.get(u)?.get(this.normalizeValue(f))??[];if(o=o===null?[...d]:o.filter(p=>d.includes(p)),o.length===0)return[]}let c=[...o??[]].filter(u=>!r.hasDotSegment(u)).sort(),l=[];for(let u of c){this.stats.candidateReads++;try{let f=await this.getFileMetadata(u);this.matchesQuery(f,t)&&l.push(u)}catch{continue}}return l}async createFile(t,n){let i=await super.createFile(t,n);return await this.reindexOwnWrite(t,n),i}async updateFile(t,n){await super.updateFile(t,n),await this.reindexOwnWrite(t,n)}async writeFile(t,n){await super.writeFile(t,n),await this.reindexOwnWrite(t,n)}async deleteFile(t){await super.deleteFile(t),this.forget(await this.ensureIndex(),r.rel(t))}async renameFile(t,n){await super.renameFile(t,n);let i=await this.ensureIndex(),s=r.rel(t),o=[...this.pathKeys.get(s)??[]];this.forget(i,s);let c=r.rel(n);for(let[l,u]of o)this.addKey(i,l,u,c)}async reindexOwnWrite(t,n){let i=await this.ensureIndex(),s=r.rel(t);this.forget(i,s);let o;try{o=this.extractFrontmatter(n)}catch{return}this.indexFrontmatter(i,s,o)}static rel(t){return t.replace(/\\/g,"/").replace(/^\.\//,"")}static hasDotSegment(t){return t.split("/").some(n=>n.startsWith("."))}async ensureIndex(){return this.indexPromise===null&&(this.indexPromise=this.buildIndex()),this.indexPromise}async buildIndex(){let t=new Map;for(let u of Ww.keys())t.set(u,new Map);let n=new Map;for(let[u,f]of Ww)n.set(f,u);let i=new Map,s=new Map,o=new Map,c=[];for(let u of this.source.explicitTriples){let f=n.get(u.predicate.value);if(f===void 0)continue;let d=r.subjectToPath(u);if(d===null)continue;c.push([f,d,u.object]);let p=u.object;if(f==="exo__Asset_uid"){p instanceof Cn.Literal&&!i.has(d)&&i.set(d,p.value);continue}if(p instanceof Cn.Literal)r.push(s,d,p.value);else if(p instanceof Cn.IRI){let h=Cn.Namespace.fromTermIRI(p.value);h&&(r.push(s,d,`${h.namespace.prefix}__${h.localName}`),f==="exo__Asset_label"&&r.push(o,p.value,d))}}let l=new Map;for(let[u,f]of o)l.set(u,f.map(d=>i.get(d)).filter(d=>d!==void 0));for(let[u,f,d]of c){let p=r.keysForObject(d,l,s);for(let h of p)this.addKey(t,u,this.normalizeValue(h),f)}for(let u of this.source.zeroTriplePaths){this.stats.zeroTripleReads++;try{this.indexFrontmatter(t,u,await this.getFileMetadata(u))}catch{continue}}return t}indexFrontmatter(t,n,i){for(let s of Ww.keys()){let o=i[s],c=Array.isArray(o)?o:[o];for(let l of c)this.addKey(t,s,this.normalizeValue(l),n)}}addKey(t,n,i,s){if(i.length===0)return;let o=t.get(n);if(o===void 0)return;let c=o.get(i);c===void 0?o.set(i,[s]):c.includes(s)||c.push(s),r.push(this.pathKeys,s,[n,i])}forget(t,n){let i=this.pathKeys.get(n);if(i){for(let[s,o]of i){let c=t.get(s)?.get(o);if(!c)continue;let l=c.indexOf(n);l>=0&&c.splice(l,1)}this.pathKeys.delete(n)}}static push(t,n,i){let s=t.get(n);s===void 0?t.set(n,[i]):s.push(i)}static subjectToPath(t){let n=t.subject;if(!(n instanceof Cn.IRI))return null;let i=(0,Cn.iriToVaultPath)(n.value);return i===null||i.startsWith("/")||i.startsWith("..")||i.includes("/../")?null:i}static keysForObject(t,n,i){if(t instanceof Cn.Literal)return[t.value];if(!(t instanceof Cn.IRI))return[];let s=Cn.Namespace.fromTermIRI(t.value);if(s)return[`${s.namespace.prefix}__${s.localName}`,...n.get(t.value)??[]];let o=(0,Cn.iriToVaultPath)(t.value);if(o!==null){let c=o.lastIndexOf("/"),l=c===-1?o:o.slice(c+1);return[l.endsWith(".md")?l.slice(0,-3):l,...i.get(o)??[]]}return[t.value]}};var W7=ee(Ve()),zt=ee(V7());var G7="obsidian://vault/";function F0e(r){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 n=t;if(n.startsWith(G7))n=decodeURI(n.slice(G7.length));else if(e.test(n)){let i=await r.findFileByUID(n);if(!i)throw new Error(`No vault file found for UID: ${n}`);n=i}if(n.endsWith(".md")||(n=`${n}.md`),!await r.fileExists(n))throw new Error(`Cannot resolve target file for IRI "${t}" (tried "${n}")`);return n}}}a(F0e,"createCliPathResolver");var D0e=["openFile","sparqlSelect","getActiveFileIRI","getActiveFilePath","trashFile","duplicateFile"],hP=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{a(this,"CliServiceNotImplementedError")}};function q7(r){return{async execute(){throw new hP(r)}}}a(q7,"notImplementedService");function L0e(r){return e=>{let t=r.getFirstLinkpathDest(e,"");if(!t||!("basename"in t))return null;let i=r.getFrontmatter(t)?.exo__Asset_label;return typeof i=="string"&&i.length>0?i:null}}a(L0e,"createCliClassResolver");function z7(r,e){for(let t of D0e)r.register(t,q7(t));for(let t of["updateProperty","removeProperty","setStatus","createAsset"])r.register(t,q7(t));if(e){if(e.fsAdapter){let t=new W7.FrontmatterService,n=F0e(e.fsAdapter);r.register("updateProperty",(0,zt.createUpdatePropertyService)(e.fsAdapter,t,n)),r.register("removeProperty",(0,zt.createRemovePropertyService)(e.fsAdapter,t,n)),r.register("setStatus",(0,zt.createSetStatusService)(e.fsAdapter,t,n)),r.register("createAsset",(0,zt.createCreateAssetService)(e.vaultAdapter,e.fsAdapter,L0e(e.vaultAdapter))),r.register("instantiatePrototypeSubtree",(0,zt.createInstantiatePrototypeSubtreeService)(e.vaultAdapter,e.fsAdapter))}r.register("createRelatedTask",(0,zt.createCreateRelatedTaskService)(e.vaultAdapter,e.genericAssetCreationService)),r.register("createRelatedProject",(0,zt.createCreateRelatedProjectService)(e.vaultAdapter,e.genericAssetCreationService)),r.register("archiveAsset",(0,zt.createArchiveAssetService)(e.vaultAdapter,e.archiveAssetService)),r.register("planForEvening",(0,zt.createPlanForEveningService)(e.vaultAdapter,e.taskStatusService)),r.register("cleanProperties",(0,zt.createCleanPropertiesService)(e.vaultAdapter,e.propertyCleanupService)),r.register("renameToUid",(0,zt.createRenameToUidService)(e.vaultAdapter,e.renameToUidService)),r.register("repairFolder",(0,zt.createRepairFolderService)(e.vaultAdapter,e.folderRepairService)),r.register("fixMissingLabel",(0,zt.createFixMissingLabelService)(e.vaultAdapter,e.fixMissingLabelService))}}a(z7,"populateCliServiceRegistry");Ba();function N0e(r,e){let t=r.getAbstractFileByPath(e),n=t!==null&&"basename"in t?t:null,i=n?r.getFrontmatter(n):null,s=i&&typeof i=="object"?i.exo__Asset_label:void 0;return{uuid:n?.basename??e.replace(/^.*\//,"").replace(/\.md$/,""),path:e,label:typeof s=="string"?s:""}}a(N0e,"buildCreatedAsset");var k0e=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;async function M0e(){if(process.stdin.isTTY)return[];let r=[];for await(let t of process.stdin)r.push(t);return Buffer.concat(r).toString("utf-8").split(`
|
|
609
|
-
`).map(t=>t.trim()).filter(t=>t.length>0)}a(M0e,"readStdinLines");function Yw(r){if(r&&typeof r=="object"&&"value"in r){let e=r.value;return typeof e=="string"?e:String(e)}return String(r)}a(Yw,"nodeValue");async function j0e(r,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_cliName"),n=await r.match(void 0,t,void 0),i=[];for(let s of n)if(Yw(s.object)===e){let l=Yw(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 Ke(`Ambiguous cliName "${e}" \u2014 resolves to ${i.length} commands: ${i.join(", ")}`,"Use the UUID directly: exocortex apply <uuid> <path>");return i[0]}a(j0e,"resolveSlugToUuid");async function $0e(r,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_destructive"),n=await r.match(void 0,t,void 0);for(let i of n)if(Yw(i.subject).includes(e)){let o=Yw(i.object);if(o==="true"||o==="True")return!0}return!1}a($0e,"isDestructive");async function U0e(r,e,t,n,i,s,o,c,l){let u={ok:!1,created:[],executed:!1},f=(0,Qa.resolve)(r,s);if(!(0,mP.existsSync)(f))return console.error(`\u274C Target file not found: ${s}`),u;let d=(0,Qa.relative)(r,f);if(d===".."||d.startsWith(`..${Qa.sep}`)||(0,Qa.isAbsolute)(d))return console.error(`\u274C Target is outside the vault: ${s} (vault: ${r})`),u;let p=new De.CommandResolver(e,Ow),h=await p.loadCommand(i);if(!h)return console.error(`\u274C Command with UID "${i}" not found.`),u;if(await $0e(e,i)&&!o.dryRun&&!o.yes)return console.error(`\u274C Command "${h.name}" is marked destructive. Add --dry-run to preview, or --yes to apply.`),u;let m=(0,De.vaultPathToIRI)(d),b=new Zt(r),_=new De.FolderRepairService(b),E=new De.PreconditionEvaluator(e,void 0,{clock:c});(0,De.registerDefaultHostFunctions)(E),E.registerHostFunction("isInWrongFolder",Rw(b,_)),E.registerHostFunction("hasObsoleteProperties",Cw(b));let I=b.getAbstractFileByPath(d),w=I!==null&&"basename"in I?I:null,S=w?b.getFrontmatter(w):null,R=S&&typeof S=="object"?S.exo__Asset_uid:void 0,P={targetIRI:m,filePath:d,fileBasename:w?.basename,assetUid:typeof R=="string"?R:void 0};if(!await E.evaluate(h.precondition,m,P))return console.error(`\u274C Precondition not satisfied for "${h.name}" on "${d}".`),u;if(o.dryRun)return o.json||console.log(`\u{1F50D} Dry-run: would apply "${h.name}" to "${d}" (precondition passed).`),{ok:!0,created:[],executed:!1};let M=new De.ServiceRegistry,U=new De.GenericAssetCreationService(b).withDeterminism({clock:c,uidGenerator:l}),D=new De.ArchiveAssetService(b),Q=new De.PropertyCleanupService(b),ue=new De.FixMissingLabelService(b),$=new De.RenameToUidService(b),le=new De.TaskStatusService(b,new De.EffortStatusWorkflow,new De.StatusTimestampService(b));z7(M,{vaultAdapter:b,fsAdapter:n,genericAssetCreationService:U,archiveAssetService:D,taskStatusService:le,propertyCleanupService:Q,fixMissingLabelService:ue,renameToUidService:$,folderRepairService:_});let H=new De.NamedQueryRunner(new Jd(e,n),e),ie=new De.GroundingExecutor(n,n,M,(0,De.createVaultFrontmatterClassLabelResolver)(n),{clock:c,uidGenerator:l,workflowResolver:t,groundingLoader:a(ne=>p.loadGroundingByUid(ne),"groundingLoader"),templateLoader:a(async ne=>{let Ie=await n.findFileByUID(ne);return Ie?(0,De.stripTemplateFrontmatter)(await n.readFile(Ie)):null},"templateLoader"),namedQueryRunner:H,refToFolder:(0,De.createVaultFrontmatterRefToFolderResolver)(n),refToFrontmatter:(0,De.createVaultFrontmatterRefToFrontmatterResolver)(n)}),V;if(o.input)try{let ne=JSON.parse(o.input);if(typeof ne!="object"||ne===null||Array.isArray(ne))throw new Error("must be a JSON object");V=ne}catch(ne){let Ie=ne instanceof Error?ne.message:String(ne);return console.error(`\u274C --input: invalid JSON object (${Ie})`),u}let z=await ie.execute(h.grounding,m,d,V);if(z.success){let ne=[];z.openPath&&ne.push(z.openPath),z.createdPaths&&ne.push(...z.createdPaths);let Ie=[],Z=new Set;for(let Y of ne)Z.has(Y)||(Z.add(Y),Ie.push(N0e(b,Y)));if(!o.json){let Y=h.successMessage??`Applied "${h.name}" to "${d}".`,se=z.openPath??z.createdPaths?.[0],X=se?` \u2192 ${se}`:"";console.log(`\u2705 ${Y}${X}`)}return{ok:!0,created:Ie,executed:!0}}else return console.error(`\u274C "${h.name}" failed on "${d}": ${z.error}`),{ok:!1,created:[],executed:!0}}a(U0e,"executeOnTarget");function H7(){return new pe("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 a grounding. Value-setting commands need a value key, e.g. set-planned-start / set-scheduled-date: --input '{"value":"<ISO>"}'
|
|
609
|
+
`).map(t=>t.trim()).filter(t=>t.length>0)}a(M0e,"readStdinLines");function Yw(r){if(r&&typeof r=="object"&&"value"in r){let e=r.value;return typeof e=="string"?e:String(e)}return String(r)}a(Yw,"nodeValue");async function j0e(r,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_cliName"),n=await r.match(void 0,t,void 0),i=[];for(let s of n)if(Yw(s.object)===e){let l=Yw(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 Ke(`Ambiguous cliName "${e}" \u2014 resolves to ${i.length} commands: ${i.join(", ")}`,"Use the UUID directly: exocortex apply <uuid> <path>");return i[0]}a(j0e,"resolveSlugToUuid");async function $0e(r,e){let t=new De.IRI("https://exocortex.my/ontology/exocmd#Command_destructive"),n=await r.match(void 0,t,void 0);for(let i of n)if(Yw(i.subject).includes(e)){let o=Yw(i.object);if(o==="true"||o==="True")return!0}return!1}a($0e,"isDestructive");async function U0e(r,e,t,n,i,s,o,c,l){let u={ok:!1,created:[],executed:!1},f=(0,Qa.resolve)(r,s);if(!(0,mP.existsSync)(f))return console.error(`\u274C Target file not found: ${s}`),u;let d=(0,Qa.relative)(r,f);if(d===".."||d.startsWith(`..${Qa.sep}`)||(0,Qa.isAbsolute)(d))return console.error(`\u274C Target is outside the vault: ${s} (vault: ${r})`),u;let p=new De.CommandResolver(e,Ow),h=await p.loadCommand(i);if(!h)return console.error(`\u274C Command with UID "${i}" not found.`),u;if(await $0e(e,i)&&!o.dryRun&&!o.yes)return console.error(`\u274C Command "${h.name}" is marked destructive. Add --dry-run to preview, or --yes to apply.`),u;let m=(0,De.vaultPathToIRI)(d),b=new Zt(r),_=new De.FolderRepairService(b),E=new De.PreconditionEvaluator(e,void 0,{clock:c});(0,De.registerDefaultHostFunctions)(E),E.registerHostFunction("isInWrongFolder",Rw(b,_)),E.registerHostFunction("hasObsoleteProperties",Cw(b));let I=b.getAbstractFileByPath(d),w=I!==null&&"basename"in I?I:null,S=w?b.getFrontmatter(w):null,R=S&&typeof S=="object"?S.exo__Asset_uid:void 0,P={targetIRI:m,filePath:d,fileBasename:w?.basename,assetUid:typeof R=="string"?R:void 0};if(!await E.evaluate(h.precondition,m,P))return console.error(`\u274C Precondition not satisfied for "${h.name}" on "${d}".`),u;if(o.dryRun)return o.json||console.log(`\u{1F50D} Dry-run: would apply "${h.name}" to "${d}" (precondition passed).`),{ok:!0,created:[],executed:!1};let M=new De.ServiceRegistry,U=new De.GenericAssetCreationService(b).withDeterminism({clock:c,uidGenerator:l}),D=new De.ArchiveAssetService(b),Q=new De.PropertyCleanupService(b),ue=new De.FixMissingLabelService(b),$=new De.RenameToUidService(b),le=new De.TaskStatusService(b,new De.EffortStatusWorkflow,new De.StatusTimestampService(b));z7(M,{vaultAdapter:b,fsAdapter:n,genericAssetCreationService:U,archiveAssetService:D,taskStatusService:le,propertyCleanupService:Q,fixMissingLabelService:ue,renameToUidService:$,folderRepairService:_});let H=new De.NamedQueryRunner(new Jd(e,n),e),ie=new De.GroundingExecutor(n,n,M,(0,De.createVaultFrontmatterClassLabelResolver)(n),{clock:c,uidGenerator:l,workflowResolver:t,groundingLoader:a(ne=>p.loadGroundingByUid(ne),"groundingLoader"),templateLoader:a(async ne=>{let Ie=await n.findFileByUID(ne);return Ie?(0,De.stripTemplateFrontmatter)(await n.readFile(Ie)):null},"templateLoader"),namedQueryRunner:H,refToFolder:(0,De.createVaultFrontmatterRefToFolderResolver)(n),refToFrontmatter:(0,De.createVaultFrontmatterRefToFrontmatterResolver)(n)}),V;if(o.input)try{let ne=JSON.parse(o.input);if(typeof ne!="object"||ne===null||Array.isArray(ne))throw new Error("must be a JSON object");V=ne}catch(ne){let Ie=ne instanceof Error?ne.message:String(ne);return console.error(`\u274C --input: invalid JSON object (${Ie})`),u}let z=await ie.execute(h.grounding,m,d,V);if(z.success){let ne=[];z.openPath&&ne.push(z.openPath),z.createdPaths&&ne.push(...z.createdPaths);let Ie=[],Z=new Set;for(let Y of ne)Z.has(Y)||(Z.add(Y),Ie.push(N0e(b,Y)));if(!o.json){let Y=h.successMessage??`Applied "${h.name}" to "${d}".`,se=z.openPath??z.createdPaths?.[0],X=se?` \u2192 ${se}`:"";console.log(`\u2705 ${Y}${X}`)}return{ok:!0,created:Ie,executed:!0}}else return console.error(`\u274C "${h.name}" failed on "${d}": ${z.error}`),{ok:!1,created:[],executed:!0}}a(U0e,"executeOnTarget");function H7(){return new pe("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 a grounding. Value-setting commands need a value key, e.g. set-planned-start / set-scheduled-date: --input '{"value":"<ISO>"}'. A command whose grounding declares its own input key uses THAT key: set-label: --input '{"label":"New label"}'. Asset-reference inputs (set-parent: --input '{"parent":"<uid>"}'; set-blocker: --input '{"blocker":"<uid>"}') take a BARE uid; a copied [[uid]] or [[uid|alias]] is accepted and unwrapped, anything else that still looks like a link is refused. The required key is named in the error if omitted.`).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)").option("--json","Emit a machine-readable JSON result ({command,target,created:[{uuid,path,label}]}) instead of human-readable output").option("--use-cache","Use the persistent triple cache (hit / delta / rebuild) instead of a full vault parse; a mutation is picked up by the NEXT --use-cache process as a delta unless --write-through is also given").option("--write-through","With --use-cache: after a grounding executed, fold the mutation into the persistent cache in this process, so the next --use-cache process is a plain hit (the delta is paid by this writer instead of the next reader). Refused without --use-cache").action(async(r,e,t)=>{if(ce.setFormat("text"),t.writeThrough&&!t.useCache){process.stderr.write(`\u274C --write-through requires --use-cache (there is no cache to write through to without it); nothing was applied
|
|
610
610
|
`),process.exit(2);return}try{let n=(0,Qa.resolve)(t.vault);if(!(0,mP.existsSync)(n))throw new ke(n);Mw(n);let i=t.frozenClock?(0,De.frozenClock)(t.frozenClock):(0,De.liveClock)(),s=t.seed?(0,De.seededUidGenerator)(t.seed):(0,De.liveUidGenerator)(),o=t.useCache??!1,c=await hi(n,{useCache:o});o&&process.stderr.write(`${yu(c)}
|
|
611
611
|
`);let l=new De.InMemoryTripleStore;await l.addAll(c.triples);let u=new zw(n,{explicitTriples:c.triples.slice(0,c.explicitCount),zeroTriplePaths:c.zeroTriplePaths}),f=new De.WorkflowResolver(l),d;if(k0e.test(r))d=r;else{let _=await j0e(l,r);_||(console.error(`\u274C No command found with UUID or cliName "${r}".`),process.exit(3)),d=_}let p;if(e)p=[e];else if(p=await M0e(),p.length===0)throw new Ke("No target path provided and stdin is empty.","exocortex apply <uuid> <path> OR exocortex find ... | exocortex apply <uuid>");let h=0,g=0,m=!1,b=[];for(let _ of p){let E=await U0e(n,l,f,u,d,_,t,i,s);E.ok?h++:g++,E.executed&&(m=!0),b.push(...E.created)}if(o&&t.writeThrough&&m&&c.cacheManager){let _=await fO(c.cacheManager);process.stderr.write(`${dO(_)}
|
|
612
612
|
`)}if(p.length>1&&!t.json&&console.log(`
|
|
@@ -685,7 +685,7 @@ Next steps:
|
|
|
685
685
|
`).map(n=>n.trim()).filter(n=>n.length>0),t=e[e.length-1];if(t!==void 0)try{return JSON.parse(t)}catch{return}}a(E_e,"parseLastJsonLine");function Z8(r,e){return e.filter(t=>{let n=r[t];return typeof n!="string"||n.trim().length===0})}a(Z8,"missingStringFields");var gE=class{constructor(e){this.deps=e}static{a(this,"McpServer")}async handle(e){if(typeof e!="object"||e===null||Array.isArray(e))return{jsonrpc:"2.0",id:null,error:{code:J8,message:"Invalid request: expected a JSON-RPC object"}};let t=e.id,n=t===void 0;if(typeof e.method!="string")return n?null:{jsonrpc:"2.0",id:t??null,error:{code:J8,message:"Invalid request: missing method"}};if(n)return null;let i=t??null;switch(e.method){case"initialize":return{jsonrpc:"2.0",id:i,result:{protocolVersion:S_e,capabilities:{tools:{}},serverInfo:{name:"exocortex",version:this.deps.version}}};case"ping":return{jsonrpc:"2.0",id:i,result:{}};case"tools/list":return{jsonrpc:"2.0",id:i,result:{tools:Q8}};case"tools/call":return{jsonrpc:"2.0",id:i,result:await this.callTool(e.params??{})};default:return{jsonrpc:"2.0",id:i,error:{code:w_e,message:`Method not found: ${e.method}`}}}}async callTool(e){let t=e.name,n=e.arguments??{},i;if(t==="create_asset"){let c=Z8(n,["vault","class","label"]);if(c.length>0)return pp(`create_asset: missing required argument(s): ${c.join(", ")}`,!0);let l=K8(n);if(l!==null)return pp(`create_asset: ${l}`,!0);i=Y8(n)}else if(t==="create_effort"){let c=Z8(n,["vault","command","target"]);if(c.length>0)return pp(`create_effort: missing required argument(s): ${c.join(", ")}`,!0);i=X8(n)}else return pp(`Unknown tool: ${String(t)}`,!0);let s=await this.deps.runCli(i);if(s.exitCode!==0){let c=s.stderr.trim()||s.stdout.trim()||"(no diagnostic output)";return pp(`exocortex-cli exited ${s.exitCode}
|
|
686
686
|
${c}`,!0)}let o=E_e(s.stdout);return pp(o===void 0?s.stdout.trim():JSON.stringify(o))}};var rV=require("child_process");var v_e=32*1024*1024;function nV(r){return e=>new Promise(t=>{(0,rV.execFile)(process.execPath,[r,...e],{maxBuffer:v_e},(n,i,s)=>{let o=0;if(n){let c=n.code;o=typeof c=="number"?c:1}t({stdout:i,stderr:s,exitCode:o})})})}a(nV,"createSelfCliRunner");async function T_e(r,e,t){let n=(0,iV.createInterface)({input:e,crlfDelay:1/0});for await(let i of n){let s=i.trim();if(s.length===0)continue;let o;try{o=JSON.parse(s)}catch{t(JSON.stringify({jsonrpc:"2.0",id:null,error:{code:eV,message:"Parse error: invalid JSON"}})+`
|
|
687
687
|
`);continue}let c;try{c=await r.handle(o)}catch(l){c={jsonrpc:"2.0",id:typeof o?.id=="string"||typeof o?.id=="number"?o.id:null,error:{code:tV,message:`Internal error: ${l instanceof Error?l.message:String(l)}`}}}c!==null&&t(JSON.stringify(c)+`
|
|
688
|
-
`)}}a(T_e,"runStdioServer");function sV(r){return new pe("mcp").description("Run an MCP (Model Context Protocol) stdio server exposing create_asset / create_effort tools backed by this CLI").option("--entry <path>","Path to the CLI entry script the tools invoke (defaults to this process's script)").action(async e=>{let t=e.entry??process.argv[1],n=new gE({runCli:nV(t),version:r??"unknown"});await T_e(n,process.stdin,i=>process.stdout.write(i))})}a(sV,"mcpCommand");function yE(r){let e=new pe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(r??"16.241.
|
|
688
|
+
`)}}a(T_e,"runStdioServer");function sV(r){return new pe("mcp").description("Run an MCP (Model Context Protocol) stdio server exposing create_asset / create_effort tools backed by this CLI").option("--entry <path>","Path to the CLI entry script the tools invoke (defaults to this process's script)").action(async e=>{let t=e.entry??process.argv[1],n=new gE({runCli:nV(t),version:r??"unknown"});await T_e(n,process.stdin,i=>process.stdout.write(i))})}a(sV,"mcpCommand");function yE(r){let e=new pe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(r??"16.241.12"),e.addCommand(j7()),e.addCommand(H7()),e.addCommand(P6()),e.addCommand(N6()),e.addCommand(n7()),e.addCommand(k6()),e.addCommand(V6()),e.addCommand(G6()),e.addCommand(f7()),e.addCommand(g7()),e.addCommand(C7()),e.addCommand(P7()),e.addCommand(F7()),e.addCommand(L7()),e.addCommand(N7()),e.addCommand(b8()),e.addCommand(w8()),e.addCommand(k8()),e.addCommand(j8()),e.addCommand(B8()),e.addCommand(V8()),e.addCommand(W8()),e.addCommand(R8()),e.addCommand(D8()),e.addCommand(z8()),e.addCommand(sV(r??"16.241.12")),e}a(yE,"createProgram");yE().parse();0&&(module.exports={createProgram});
|
|
689
689
|
/*! Bundled license information:
|
|
690
690
|
|
|
691
691
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED