@kitelev/exocortex-cli 16.212.1 → 16.212.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/dist/index.js +7 -6
- 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.212.
|
|
2
|
+
// @kitelev/exocortex-cli v16.212.3
|
|
3
3
|
// CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
|
|
4
4
|
// License: MIT
|
|
5
5
|
|
|
@@ -532,7 +532,7 @@ Hidden by precondition (${n.hidden.length}):`),n.hidden.length===0)console.log("
|
|
|
532
532
|
`),console.log(` Instances: ${c}`),console.log(` Properties: ${f.length}
|
|
533
533
|
`),f.length===0){console.log(" No properties found.");return}let p=Math.max(...f.map(h=>h.name.length),10);console.log(" \u250C"+"\u2500".repeat(p+2)+"\u252C"+"\u2500".repeat(10)+"\u2510"),console.log(" \u2502 "+"Property".padEnd(p)+" \u2502 "+"Usage".padEnd(8)+" \u2502"),console.log(" \u251C"+"\u2500".repeat(p+2)+"\u253C"+"\u2500".repeat(10)+"\u2524");for(let h of f)console.log(" \u2502 "+h.name.padEnd(p)+" \u2502 "+h.usageCount.toString().padStart(8)+" \u2502");console.log(" \u2514"+"\u2500".repeat(p+2)+"\u2534"+"\u2500".repeat(10)+"\u2518")}}a(xle,"showClassDetails");function T$(n){let e=n.replace(/^<|>$/g,""),t=e.lastIndexOf("#");if(t!==-1)return e.substring(t+1);let r=e.lastIndexOf("/");return r!==-1?e.substring(r+1):e}a(T$,"extractLocalName");ft();var I$=require("fs"),x$=require("path"),yl=Se(Ze());Oi();Rt();ur();fr();jt();fr();Tf();function A$(n,e){return e.concat([n])}a(A$,"collect");function Rle(n,e){let t={},r=a((i,s)=>{let o=i.indexOf("=");if(o<=0)throw new Error(`Invalid --param "${i}" \u2014 expected name=value.`);let c=i.slice(0,o),l=i.slice(o+1);t[c]={value:s==="iri"?(0,yl.vaultPathToIRI)(l):l,kind:s}},"add");for(let i of n)r(i,"literal");for(let i of e)r(i,"iri");return Object.keys(t).length>0?t:void 0}a(Rle,"buildParams");function R$(){return new xe("run-query").description("Execute a query__NamedQuery asset (read-only SELECT / ASK / CONSTRUCT) by UID and print its result.").argument("<uid>","UID of the query__NamedQuery asset to run").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--format <type>","Output format: table|json","table").option("--output <type>","Response format: text|json (for MCP tools)","text").option("--use-cache","Use persistent cache (faster for repeated queries)").option("--current-asset <path>","Vault-relative path injected as $currentAsset (an IRI) into the query body").option("--param <name=value>","Literal parameter $<name> substituted as an escaped string. Repeatable.",A$,[]).option("--param-iri <name=path>","IRI parameter $<name>; value is a vault-relative path resolved to an IRI. Repeatable.",A$,[]).action(async(n,e)=>{let t=e.output||"text",r=t==="json"||e.format==="json";we.setFormat(t);try{let i=(0,x$.resolve)(e.vault);if(!(0,I$.existsSync)(i))throw new Xe(i);r||console.log(`\u{1F4E6} Loading vault: ${i}...`);let s;e.useCache??!1?s=(await new Pi(i).loadOrBuild()).triples:s=await new yl.NoteToRDFConverter(new Mt(i)).convertVault();let o=new yl.InMemoryTripleStore;await o.addAll(s);let c=v_(o,i),l={};e.currentAsset&&(l.currentAsset=(0,yl.vaultPathToIRI)(e.currentAsset));let u=Rle(e.param,e.paramIri);u&&(l.params=u);let f=await c.run(n,l);f===null&&we.handleWithMessage(`No resolvable query__NamedQuery for UID "${n}" (asset not found, or it has no \`\`\`sparql code-block).`,3,"VALIDATION_FILE_NOT_FOUND"),Cle(f,r)}catch(i){we.handle(i)}})}a(R$,"runQueryCommand");function Cle(n,e){if(n.kind==="ask"){console.log(e?JSON.stringify(dt.success({kind:"ask",result:n.result}),null,2):String(n.result));return}if(n.kind==="construct"){let t=n.triples.map(r=>({subject:r.subject.toString(),predicate:r.predicate.toString(),object:r.object.toString()}));if(e)console.log(JSON.stringify(dt.success({kind:"construct",triples:t,count:t.length}),null,2));else{console.log(`\u{1F4CA} CONSTRUCT \u2014 ${t.length} triple(s):
|
|
534
534
|
`);for(let r of t)console.log(`${r.subject} ${r.predicate} ${r.object} .`)}return}if(e){let t=n.rows.map(r=>{let i={};for(let s of r.variables()){let o=r.get(s);i[s]=o?o.toString():null}return i});console.log(JSON.stringify(dt.success({kind:"select",rows:t,count:t.length}),null,2))}else console.log(new Ef().format(n.rows))}a(Cle,"printResult");ft();var j$=require("path"),lR=require("fs"),$$=require("fs"),Ni=Se(Ze());Oi();var rR=class extends Error{static{a(this,"ClassNotFoundError")}constructor(e,t){let r=`Class '${e}' not found in vault`;t&&t.length>0&&(r+=`
|
|
535
|
-
Available classes: ${t.join(", ")}`),super(r),this.name="ClassNotFoundError"}},A_=class{constructor(e){this.fsAdapter=e;this.cache=new Map}static{a(this,"ClassResolverService")}async resolve(e,t){if(this.isUUID(t))return t;let r=await this.getOrBuildIndex(e),i=r.get(t);if(!i){let s=Array.from(r.keys()).filter(o=>!this.isUUID(o));throw new rR(t,s)}return i}async listClasses(e){let t=await this.getOrBuildIndex(e);return Array.from(t.keys())}async getOrBuildIndex(e){if(this.cache.has(e))return this.cache.get(e);let t=await this.buildIndex(e);return this.cache.set(e,t),t}async buildIndex(e){let t=new Map,r=await this.fsAdapter.getMarkdownFiles(),i=[],s=new Set;for(let o of r)try{let c=await this.fsAdapter.getFileMetadata(o),l=this.getBasename(o),u=c.exo__Asset_uid;!u&&this.isUUID(l)&&(u=l);let f=u?String(u):void 0,d=c.exo__Asset_label,p=typeof d=="string"?d:void 0,h=c.exo__Instance_class,g=h?(Array.isArray(h)?h:[h]).map(y=>String(y)):[];i.push({basename:l,uid:f,label:p,classValues:g}),f&&(p==="exo__Class"||p==="ims__Class")&&s.add(f)}catch{continue}for(let o of i)o.uid&&this.isClassDefinition(o.classValues,s)&&(o.basename&&t.set(o.basename,o.uid),o.label&&o.label!==o.basename&&t.set(o.label,o.uid));return t}isClassDefinition(e,t){return e.some(r=>{if(r.includes("ims__Class")||r.includes("exo__Class"))return!0;for(let i of t)if(i&&r.includes(i))return!0;return!1})}getBasename(e){let t=e.split("/");return t[t.length-1].replace(/\.md$/,"")}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 nR=class extends Error{static{a(this,"WikilinkNotFoundError")}constructor(e,t){let r=t?`|${t}`:"";super(`Wikilink [[${e}${r}]] \u2014 file not found in vault`),this.name="WikilinkNotFoundError"}},ic=class{constructor(e){this.fsAdapter=e}static{a(this,"WikilinkValidator")}static{this.WIKILINK_PATTERN=/\[\[([^\]|]+)(?:\|[^\]]*)?]]/g}async validatePropertyValues(e){for(let[,t]of Object.entries(e)){let r=Array.isArray(t)?t:[t];for(let i of r)await this.validateValue(i)}}async validateValue(e){let t=this.extractWikilinks(e);for(let r of t)await this.validateWikilink(r.uuid,r.label)}extractWikilinks(e){let t=[],r=/\[\[([^\]|]+)(?:\|([^\]]*))?\]\]/g,i;for(;(i=r.exec(e))!==null;)t.push({uuid:i[1].trim(),label:i[2]?.trim()});return t}async validateWikilink(e,t){if(!this.looksLikeUUID(e)||await this.fsAdapter.findFileByUidFilename(e))return;if(!await this.fsAdapter.findFileByUID(e))throw new nR(e,t)}looksLikeUUID(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)}};hx();var sc=class n{constructor(e){this.vaultPath=e;this.cache=null}static{a(this,"PropertyNameValidator")}static{this.KEY_SHAPE=/^([A-Za-z][A-Za-z0-9]*)__.+$/}static{this.PROPERTY_METACLASS_UIDS=["38277bfa-d7f9-4a75-b856-b23276ab0db3","9a1cf31c-9d41-4ef3-9023-584a8d087d16","ae56ca4c-b610-42a4-a25d-058c23673296"]}static{this.PROPERTY_METACLASS_LABELS=["exo__Property","exo__ObjectProperty","exo__DatatypeProperty"]}static{this.CLASS_METACLASS_UID="8619c4fc-64f1-4869-b17e-e34186cacca9"}static{this.CLASS_METACLASS_LABEL="exo__Class"}async validate(e){let{names:t,prefixes:r}=await this.collect();if(t.size!==0)for(let i of e){let s=n.KEY_SHAPE.exec(i);if(!s||t.has(i))continue;let o=s[1],c=r.has(o)?o:void 0,l=n.suggest(i,t,c);throw new gh(i,l)}}async collect(){if(this.cache)return this.cache;let{readdir:e,readFile:t}=await import("fs/promises"),r=[],i=[],s=a(async u=>{let f;try{f=await e(u,{withFileTypes:!0})}catch{return}for(let d of f){let p=`${u}/${d.name}`;if(d.isDirectory())await s(p);else if(d.isFile()&&d.name.endsWith(".md")){let h;try{h=await t(p,"utf-8")}catch{continue}n.scan(h,r,i)}}},"walk");await s(this.vaultPath);let o=n.buildPropertyMetaclassClosure(r),c=new Set,l=new Set;for(let u of i){if(!u.classRefs.some(d=>o.has(d)))continue;c.add(u.name);let f=n.KEY_SHAPE.exec(u.name);f&&l.add(f[1])}return this.cache={names:c,prefixes:l},this.cache}static scan(e,t,r){let i=n.parseFrontmatter(e);if(!i)return;let s=n.asArray(i.exo__Instance_class).flatMap(c=>n.refHalves(c));if(s.length===0)return;let o=n.cleanLabel(i.exo__Asset_label);if(s.some(c=>n.isClassMetaclass(c))){let c=i.exo__Asset_uid,l=typeof c=="string"?c.trim():null,u=n.asArray(i.exo__Class_superClass).flatMap(f=>n.refHalves(f));t.push({uid:l,label:o,superRefs:u});return}o===null||!n.KEY_SHAPE.test(o)||r.push({classRefs:s,name:o})}static buildPropertyMetaclassClosure(e){let t=new Set([...n.PROPERTY_METACLASS_UIDS,...n.PROPERTY_METACLASS_LABELS]),r=!0;for(;r;){r=!1;for(let i of e)i.uid!==null&&t.has(i.uid)||i.label!==null&&t.has(i.label)||i.superRefs.some(o=>t.has(o))&&(i.uid!==null&&t.add(i.uid),i.label!==null&&t.add(i.label),r=!0)}return t}static isClassMetaclass(e){return e===n.CLASS_METACLASS_UID||e===n.CLASS_METACLASS_LABEL}static refHalves(e){let t=String(e).replace(/^["']|["']$/g,"").trim(),r=/\[\[([^\]]+)\]\]/.exec(t);return(r?r[1]:t).split("|").map(s=>s.trim()).filter(s=>s.length>0)}static cleanLabel(e){if(typeof e!="string")return null;let t=e.replace(/^["']|["']$/g,"").trim();return t.length>0?t:null}static asArray(e){return Array.isArray(e)?e.map(String):typeof e=="string"?[e]:[]}static parseFrontmatter(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e);if(!t)return null;let r={},i=t[1].split(/\r?\n/),s=null,o=null;for(let c of i){let l=/^ {2}- (.*)$/.exec(c);if(l){s&&o&&o.push(l[1].trim());continue}s&&o&&(r[s]=o,s=null,o=null);let u=/^([^:]+):\s*(.*)$/.exec(c);if(!u)continue;let f=u[1].trim(),d=u[2].trim();d===""?(s=f,o=[]):r[f]=d}return s&&o&&(r[s]=o),r}static suggest(e,t,r){let i=r?[...t].filter(o=>o.startsWith(`${r}__`)):[...t],s=Math.max(3,Math.floor(e.length*.4));return i.map(o=>({name:o,distance:n.levenshtein(e,o)})).filter(o=>o.distance<=s).sort((o,c)=>o.distance-c.distance||o.name.localeCompare(c.name)).slice(0,3).map(o=>o.name)}static levenshtein(e,t){let r=e.length,i=t.length;if(r===0)return i;if(i===0)return r;let s=Array.from({length:i+1},(c,l)=>l),o=new Array(i+1);for(let c=1;c<=r;c++){o[0]=c;for(let l=1;l<=i;l++){let u=e[c-1]===t[l-1]?0:1;o[l]=Math.min(s[l]+1,o[l-1]+1,s[l-1]+u)}[s,o]=[o,s]}return s[i]}};var C$="ems__Effort",Ole="ems__EffortStatus",I_=class{constructor(e){this.fsAdapter=e;this.statusUidCache=new Map}static{a(this,"EffortStatusResolver")}async isStatusBearing(e){let t=new Set,r=[e];for(;r.length>0;){let i=r.shift();if(i===void 0)break;if(t.has(i))continue;if(t.add(i),i===C$)return!0;let s=await this.resolveClassFile(i);if(!s)continue;let o;try{o=await this.fsAdapter.getFileMetadata(s)}catch{continue}if(o.exo__Asset_label===C$)return!0;let c=o.exo__Class_superClass,l=Array.isArray(c)?c:c!=null?[c]:[];for(let u of l){let f=Fle(String(u));f&&!t.has(f)&&r.push(f)}}return!1}async resolveStatusUid(e){let t=Ple(e),r=this.statusUidCache.get(t);if(r!==void 0)return r;let i=null,s=await this.fsAdapter.findFilesByMetadata({exo__Asset_label:t});for(let o of s)try{let c=await this.fsAdapter.getFileMetadata(o);if(c.exo__Asset_uid){i=String(c.exo__Asset_uid);break}}catch{continue}return this.statusUidCache.set(t,i),i}async resolveClassFile(e){if(Dle(e))return this.fsAdapter.findFileByUidFilename(e);let t=await this.fsAdapter.findFilesByMetadata({exo__Asset_label:e});return t.length>0?t[0]:null}};function Ple(n){let e=n.trim();if(e.startsWith("ems__"))return e;let t=e.charAt(0).toUpperCase()+e.slice(1);return`${Ole}${t}`}a(Ple,"toStatusEnumLabel");function Fle(n){return n.trim().replace(/^["']|["']$/g,"").replace(/^\[\[|\]\]$/g,"").split("|")[0].trim()||null}a(Fle,"extractRef");function Dle(n){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n)}a(Dle,"isUuid");Rt();jt();var Of=require("fs"),iR=require("path"),P$=Se(Ze());function x_(n){(0,P$.registerOrderSpecLoader)(()=>{let e=Lle(n);for(let t of e){let r=Nle(t);if(r)return r}return null})}a(x_,"registerOrderSpecFromVault");function Lle(n){return[(0,iR.join)(n,"assetspaces","exo")]}a(Lle,"collectCandidateDirs");function Nle(n){if(!(0,Of.existsSync)(n))return null;let e;try{e=(0,Of.readdirSync)(n)}catch{return null}for(let t of e){if(!t.endsWith(".md"))continue;let r=(0,iR.join)(n,t),i;try{i=(0,Of.readFileSync)(r,"utf-8")}catch{continue}let s=kle(i);if(s&&/^exo__FrontmatterOrderSpec_default:\s*true\b/m.test(s))return{head:O$(s,"exo__FrontmatterOrderSpec_head"),tail:O$(s,"exo__FrontmatterOrderSpec_tail"),middleStrategy:Mle(s,"exo__FrontmatterOrderSpec_middleStrategy")??"alphabetical"}}return null}a(Nle,"scanDirForDefault");function kle(n){let e=n.match(/^---\n([\s\S]*?)\n---/);return e?e[1]:null}a(kle,"extractFrontmatter");function Mle(n,e){let t=new RegExp(`^${F$(e)}:\\s*(.+)$`,"m"),r=n.match(t);return r?r[1].trim():null}a(Mle,"extractScalar");function O$(n,e){let t=new RegExp(`^${F$(e)}:\\s*\\n((?: -.*\\n?)+)`,"m"),r=n.match(t);return r?r[1].split(`
|
|
535
|
+
Available classes: ${t.join(", ")}`),super(r),this.name="ClassNotFoundError"}},A_=class{constructor(e){this.fsAdapter=e;this.cache=new Map}static{a(this,"ClassResolverService")}async resolve(e,t){if(this.isUUID(t))return t;let r=await this.getOrBuildIndex(e),i=r.get(t);if(!i){let s=Array.from(r.keys()).filter(o=>!this.isUUID(o));throw new rR(t,s)}return i}async listClasses(e){let t=await this.getOrBuildIndex(e);return Array.from(t.keys())}async getOrBuildIndex(e){if(this.cache.has(e))return this.cache.get(e);let t=await this.buildIndex(e);return this.cache.set(e,t),t}async buildIndex(e){let t=new Map,r=await this.fsAdapter.getMarkdownFiles(),i=[],s=new Set;for(let o of r)try{let c=await this.fsAdapter.getFileMetadata(o),l=this.getBasename(o),u=c.exo__Asset_uid;!u&&this.isUUID(l)&&(u=l);let f=u?String(u):void 0,d=c.exo__Asset_label,p=typeof d=="string"?d:void 0,h=c.exo__Instance_class,g=h?(Array.isArray(h)?h:[h]).map(y=>String(y)):[];i.push({basename:l,uid:f,label:p,classValues:g}),f&&(p==="exo__Class"||p==="ims__Class")&&s.add(f)}catch{continue}for(let o of i)o.uid&&this.isClassDefinition(o.classValues,s)&&(o.basename&&t.set(o.basename,o.uid),o.label&&o.label!==o.basename&&t.set(o.label,o.uid));return t}isClassDefinition(e,t){return e.some(r=>{if(r.includes("ims__Class")||r.includes("exo__Class"))return!0;for(let i of t)if(i&&r.includes(i))return!0;return!1})}getBasename(e){let t=e.split("/");return t[t.length-1].replace(/\.md$/,"")}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 nR=class extends Error{static{a(this,"WikilinkNotFoundError")}constructor(e,t){let r=t?`|${t}`:"";super(`Wikilink [[${e}${r}]] \u2014 file not found in vault`),this.name="WikilinkNotFoundError"}},ic=class{constructor(e){this.fsAdapter=e}static{a(this,"WikilinkValidator")}static{this.WIKILINK_PATTERN=/\[\[([^\]|]+)(?:\|[^\]]*)?]]/g}async validatePropertyValues(e){for(let[,t]of Object.entries(e)){let r=Array.isArray(t)?t:[t];for(let i of r)await this.validateValue(i)}}async validateValue(e){let t=this.extractWikilinks(e);for(let r of t)await this.validateWikilink(r.uuid,r.label)}extractWikilinks(e){let t=[],r=/\[\[([^\]|]+)(?:\|([^\]]*))?\]\]/g,i;for(;(i=r.exec(e))!==null;)t.push({uuid:i[1].trim(),label:i[2]?.trim()});return t}async validateWikilink(e,t){if(!this.looksLikeUUID(e)||await this.fsAdapter.findFileByUidFilename(e))return;if(!await this.fsAdapter.findFileByUID(e))throw new nR(e,t)}looksLikeUUID(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)}};hx();var sc=class n{constructor(e){this.vaultPath=e;this.cache=null}static{a(this,"PropertyNameValidator")}static{this.KEY_SHAPE=/^([A-Za-z][A-Za-z0-9]*)__.+$/}static{this.PROPERTY_METACLASS_UIDS=["38277bfa-d7f9-4a75-b856-b23276ab0db3","9a1cf31c-9d41-4ef3-9023-584a8d087d16","ae56ca4c-b610-42a4-a25d-058c23673296"]}static{this.PROPERTY_METACLASS_LABELS=["exo__Property","exo__ObjectProperty","exo__DatatypeProperty"]}static{this.CLASS_METACLASS_UID="8619c4fc-64f1-4869-b17e-e34186cacca9"}static{this.CLASS_METACLASS_LABEL="exo__Class"}async validate(e){let{names:t,prefixes:r}=await this.collect();if(t.size!==0)for(let i of e){let s=n.KEY_SHAPE.exec(i);if(!s||t.has(i))continue;let o=s[1],c=r.has(o)?o:void 0,l=n.suggest(i,t,c);throw new gh(i,l)}}async isUnknownName(e){let{names:t}=await this.collect();return t.size===0||!n.KEY_SHAPE.test(e)?!1:!t.has(e)}async collect(){if(this.cache)return this.cache;let{readdir:e,readFile:t}=await import("fs/promises"),r=[],i=[],s=a(async u=>{let f;try{f=await e(u,{withFileTypes:!0})}catch{return}for(let d of f){let p=`${u}/${d.name}`;if(d.isDirectory())await s(p);else if(d.isFile()&&d.name.endsWith(".md")){let h;try{h=await t(p,"utf-8")}catch{continue}n.scan(h,r,i)}}},"walk");await s(this.vaultPath);let o=n.buildPropertyMetaclassClosure(r),c=new Set,l=new Set;for(let u of i){if(!u.classRefs.some(d=>o.has(d)))continue;c.add(u.name);let f=n.KEY_SHAPE.exec(u.name);f&&l.add(f[1])}return this.cache={names:c,prefixes:l},this.cache}static scan(e,t,r){let i=n.parseFrontmatter(e);if(!i)return;let s=n.asArray(i.exo__Instance_class).flatMap(c=>n.refHalves(c));if(s.length===0)return;let o=n.cleanLabel(i.exo__Asset_label);if(s.some(c=>n.isClassMetaclass(c))){let c=i.exo__Asset_uid,l=typeof c=="string"?c.trim():null,u=n.asArray(i.exo__Class_superClass).flatMap(f=>n.refHalves(f));t.push({uid:l,label:o,superRefs:u});return}o===null||!n.KEY_SHAPE.test(o)||r.push({classRefs:s,name:o})}static buildPropertyMetaclassClosure(e){let t=new Set([...n.PROPERTY_METACLASS_UIDS,...n.PROPERTY_METACLASS_LABELS]),r=!0;for(;r;){r=!1;for(let i of e)i.uid!==null&&t.has(i.uid)||i.label!==null&&t.has(i.label)||i.superRefs.some(o=>t.has(o))&&(i.uid!==null&&t.add(i.uid),i.label!==null&&t.add(i.label),r=!0)}return t}static isClassMetaclass(e){return e===n.CLASS_METACLASS_UID||e===n.CLASS_METACLASS_LABEL}static refHalves(e){let t=String(e).replace(/^["']|["']$/g,"").trim(),r=/\[\[([^\]]+)\]\]/.exec(t);return(r?r[1]:t).split("|").map(s=>s.trim()).filter(s=>s.length>0)}static cleanLabel(e){if(typeof e!="string")return null;let t=e.replace(/^["']|["']$/g,"").trim();return t.length>0?t:null}static asArray(e){return Array.isArray(e)?e.map(String):typeof e=="string"?[e]:[]}static parseFrontmatter(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e);if(!t)return null;let r={},i=t[1].split(/\r?\n/),s=null,o=null;for(let c of i){let l=/^ {2}- (.*)$/.exec(c);if(l){s&&o&&o.push(l[1].trim());continue}s&&o&&(r[s]=o,s=null,o=null);let u=/^([^:]+):\s*(.*)$/.exec(c);if(!u)continue;let f=u[1].trim(),d=u[2].trim();d===""?(s=f,o=[]):r[f]=d}return s&&o&&(r[s]=o),r}static suggest(e,t,r){let i=r?[...t].filter(o=>o.startsWith(`${r}__`)):[...t],s=Math.max(3,Math.floor(e.length*.4));return i.map(o=>({name:o,distance:n.levenshtein(e,o)})).filter(o=>o.distance<=s).sort((o,c)=>o.distance-c.distance||o.name.localeCompare(c.name)).slice(0,3).map(o=>o.name)}static levenshtein(e,t){let r=e.length,i=t.length;if(r===0)return i;if(i===0)return r;let s=Array.from({length:i+1},(c,l)=>l),o=new Array(i+1);for(let c=1;c<=r;c++){o[0]=c;for(let l=1;l<=i;l++){let u=e[c-1]===t[l-1]?0:1;o[l]=Math.min(s[l]+1,o[l-1]+1,s[l-1]+u)}[s,o]=[o,s]}return s[i]}};var C$="ems__Effort",Ole="ems__EffortStatus",I_=class{constructor(e){this.fsAdapter=e;this.statusUidCache=new Map}static{a(this,"EffortStatusResolver")}async isStatusBearing(e){let t=new Set,r=[e];for(;r.length>0;){let i=r.shift();if(i===void 0)break;if(t.has(i))continue;if(t.add(i),i===C$)return!0;let s=await this.resolveClassFile(i);if(!s)continue;let o;try{o=await this.fsAdapter.getFileMetadata(s)}catch{continue}if(o.exo__Asset_label===C$)return!0;let c=o.exo__Class_superClass,l=Array.isArray(c)?c:c!=null?[c]:[];for(let u of l){let f=Fle(String(u));f&&!t.has(f)&&r.push(f)}}return!1}async resolveStatusUid(e){let t=Ple(e),r=this.statusUidCache.get(t);if(r!==void 0)return r;let i=null,s=await this.fsAdapter.findFilesByMetadata({exo__Asset_label:t});for(let o of s)try{let c=await this.fsAdapter.getFileMetadata(o);if(c.exo__Asset_uid){i=String(c.exo__Asset_uid);break}}catch{continue}return this.statusUidCache.set(t,i),i}async resolveClassFile(e){if(Dle(e))return this.fsAdapter.findFileByUidFilename(e);let t=await this.fsAdapter.findFilesByMetadata({exo__Asset_label:e});return t.length>0?t[0]:null}};function Ple(n){let e=n.trim();if(e.startsWith("ems__"))return e;let t=e.charAt(0).toUpperCase()+e.slice(1);return`${Ole}${t}`}a(Ple,"toStatusEnumLabel");function Fle(n){return n.trim().replace(/^["']|["']$/g,"").replace(/^\[\[|\]\]$/g,"").split("|")[0].trim()||null}a(Fle,"extractRef");function Dle(n){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(n)}a(Dle,"isUuid");Rt();jt();var Of=require("fs"),iR=require("path"),P$=Se(Ze());function x_(n){(0,P$.registerOrderSpecLoader)(()=>{let e=Lle(n);for(let t of e){let r=Nle(t);if(r)return r}return null})}a(x_,"registerOrderSpecFromVault");function Lle(n){return[(0,iR.join)(n,"assetspaces","exo")]}a(Lle,"collectCandidateDirs");function Nle(n){if(!(0,Of.existsSync)(n))return null;let e;try{e=(0,Of.readdirSync)(n)}catch{return null}for(let t of e){if(!t.endsWith(".md"))continue;let r=(0,iR.join)(n,t),i;try{i=(0,Of.readFileSync)(r,"utf-8")}catch{continue}let s=kle(i);if(s&&/^exo__FrontmatterOrderSpec_default:\s*true\b/m.test(s))return{head:O$(s,"exo__FrontmatterOrderSpec_head"),tail:O$(s,"exo__FrontmatterOrderSpec_tail"),middleStrategy:Mle(s,"exo__FrontmatterOrderSpec_middleStrategy")??"alphabetical"}}return null}a(Nle,"scanDirForDefault");function kle(n){let e=n.match(/^---\n([\s\S]*?)\n---/);return e?e[1]:null}a(kle,"extractFrontmatter");function Mle(n,e){let t=new RegExp(`^${F$(e)}:\\s*(.+)$`,"m"),r=n.match(t);return r?r[1].trim():null}a(Mle,"extractScalar");function O$(n,e){let t=new RegExp(`^${F$(e)}:\\s*\\n((?: -.*\\n?)+)`,"m"),r=n.match(t);return r?r[1].split(`
|
|
536
536
|
`).map(i=>i.trim()).filter(i=>i.startsWith("- ")).map(i=>i.slice(2).trim()):[]}a(O$,"extractList");function F$(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}a(F$,"escapeRegex");var Pf=Se(require("path")),oR=Se(Ze());async function oc(n,e,t){let r=e.endsWith(".md")?e:`${e}.md`;if(e.includes("/")&&await n.fileExists(r))return r;let i=Pf.default.dirname(t),s=i!=="."?`${i}/${r}`:r;if(await n.fileExists(s))return s;let c=await n.findFileByUID(e);return c||(await n.getMarkdownFiles()).find(f=>{let d=Pf.default.basename(f,".md"),p=Pf.default.basename(r,".md");return d===p})||null}a(oc,"findReferencedFile");function aR(n){return n.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/$/,"")}a(aR,"normalizePath");async function R_(n,e){let t=(0,oR.extractAssetReference)(e);if(!t||t.startsWith("!"))return null;let r=await oc(n,t,"");if(!r)return null;let i=Pf.default.dirname(r);return i==="."?"":i}a(R_,"resolveCoLocationFolder");function sR(n){let e=n;for(;Array.isArray(e);){if(e.length===0)return null;e=e[0]}return(0,oR.extractAssetReference)(e)}a(sR,"wikilinkTarget");async function D$(n,e,t,r){let i=new Set;if(e&&i.add(e),t&&i.add(t),i.size===0)return null;let s=sR(r),o=await n.getMarkdownFiles(),c=new Map;for(let d of o){let p;try{p=await n.getFileMetadata(d)}catch{continue}if(sR(p.exo__Asset_isDefinedBy)!==s)continue;let h=p.exo__Instance_class;if(!(Array.isArray(h)?h:[h]).some(A=>{let O=sR(A);return O!==null&&i.has(O)}))continue;let S=Pf.default.dirname(d),w=S==="."?"":S;c.set(w,(c.get(w)??0)+1)}if(c.size===0)return null;let l=null,u=-1,f=Array.from(c.entries()).sort((d,p)=>d[0]<p[0]?-1:d[0]>p[0]?1:0);for(let[d,p]of f)p>u&&(l=d,u=p);return l}a(D$,"resolveNeighbourFolderByClass");var k$="01 Inbox",Vle="Asia/Almaty",qle="4ef3962d-b8a7-42b5-bd28-88ec846f1d13",M$="Backlog",Ch="ems__Effort_status",Gle={aliases:"--aliases <a,b>"};function Wle(n){if(!n||n.length===0)return{};let e={};for(let t of n){let r=t.indexOf("=");if(r===-1)throw new Error(`Invalid property format: "${t}". Expected "key=value" format.`);let i=t.substring(0,r).trim(),s=t.substring(r+1).trim();if(!i)throw new Error(`Invalid property format: "${t}". Key cannot be empty.`);let o=Gle[(0,Ni.canonicalYamlKey)(i)];if(o!==void 0)throw new Error(`Refusing to set "${i}" via --property \u2014 create manages this field itself. Use: ${o}`);let c=e[i];c===void 0?e[i]=s:Array.isArray(c)?c.push(s):e[i]=[c,s]}return e}a(Wle,"parseProperties");async function Hle(n){if(n.bodyFile){if(!(0,lR.existsSync)(n.bodyFile))throw new Error(`Body file not found: ${n.bodyFile}`);return(0,$$.readFileSync)(n.bodyFile,"utf-8")}if(n.body==="-")return zle(3e4);if(n.body)return n.body}a(Hle,"resolveBody");function zle(n){return new Promise((e,t)=>{let r=[],i=setTimeout(()=>{process.stdin.removeAllListeners(),process.stdin.destroy(),t(new Error(`Stdin read timed out after ${n}ms. Ensure you pipe content to stdin or close the pipe.`))},n);process.stdin.on("data",s=>{r.push(s)}),process.stdin.on("end",()=>{clearTimeout(i),e(Buffer.concat(r).toString("utf-8"))}),process.stdin.on("error",s=>{clearTimeout(i),t(s)}),process.stdin.isTTY&&(clearTimeout(i),e("")),process.stdin.resume()})}a(zle,"readStdin");function U$(){return new xe("create").description("Create a new vault asset with auto-generated UUID, timestamp, and frontmatter").requiredOption("--class <name>","Class short name (e.g. ztlk__PermanentNote) or UUID").requiredOption("--label <text>","Human-readable label for the asset").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--aliases <names...>","Additional aliases for the asset").option("--property <key=value...>","Property key-value pairs (repeatable; the SAME key passed more than once accumulates into a YAML array)",Yle,[]).option("--body <text>","Markdown body content (use '-' to read from stdin)").option("--body-file <path>","Read body content from file").option("--dry-run","Preview frontmatter without writing file").option("--created-by <uuid>","Creator UUID (defaults to ExoAssistant)").option("--status <name>","ems__Effort_status for status-bearing classes (default: Backlog; e.g. Draft, Doing, Done). Errors for non-status-bearing classes.").option("--no-status","For a status-bearing class, do NOT inject the default ems__Effort_status \u2014 create a status-less prototype/template (issue #3928). No-op for a non-status-bearing class. Mutually exclusive with --status / --property ems__Effort_status.").option("--yes","Accepted for symmetry with the apply subcommands (create is non-interactive; no-op)").option("--timezone <tz>","Timezone for timestamps (defaults to Asia/Almaty)").option("--skip-wikilink-validation","Skip wikilink existence validation").option("--validate","Run SHACL-lite conformance validation on the new asset BEFORE writing it; a non-conformant asset is refused and no file is created (same shapes as `validate schema --shapes-mode`). Opt-in: omit the flag and create behaves exactly as before.").action(async n=>{try{let e=(0,j$.resolve)(n.vault);if(!(0,lR.existsSync)(e))throw new Xe(e);if(x_(e),!n.label||n.label.trim().length===0)throw new Error("Label cannot be empty");let t=n.label.trim(),r=Wle(n.property);await new sc(e).validate(Object.keys(r));let s=await Hle(n);s&&(s=s.replace(/\\n/g,`
|
|
537
537
|
`));let o=new Gn(e),c=new A_(o),l=new ic(o),u=await c.resolve(e,n.class),f=new I_(o),d=n.status===!1,p=typeof n.status=="string"?n.status:void 0,h=Ch in r;if(d&&h)throw new Error(`Cannot pass both --no-status and --property ${Ch}=... (ambiguous \u2014 cannot both suppress and set the status). Use one.`);if(p&&h)throw new Error(`Cannot pass both --status and --property ${Ch}=... (ambiguous). Use one.`);if(!h&&!d){let j=await f.isStatusBearing(u);if(p){if(!j)throw new Error(`--status only applies to status-bearing classes (ems__Effort subclasses); '${n.class}' is not one.`);let $=await f.resolveStatusUid(p);if(!$)throw new Error(`Unknown status '${p}' \u2014 no matching ems__EffortStatus<Name> enum asset found in the vault.`);r[Ch]=`[[${$}]]`}else if(j){let $=await f.resolveStatusUid(M$);$?r[Ch]=`[[${$}]]`:process.stderr.write(`\u26A0 status-bearing class but no ${M$} status enum found in the vault \u2014 created without ems__Effort_status.
|
|
538
538
|
`)}}let g=Object.keys(r).length>0?r:void 0;g&&!n.skipWikilinkValidation&&await l.validatePropertyValues(g);let y=k$,S=g?.exo__Asset_isDefinedBy,w=Array.isArray(S)?S[0]:S;if(w){let j=await R_(o,w);j&&(y=j)}if(y===k$){let j=await D$(o,u,n.class,w);j&&(y=j)}let A;try{A=await Ni.ShapeLoader.loadFromVaultFS(e)}catch{A=new Ni.ShapeRegistry}let O=new Mt(e),v=new Ni.GenericAssetCreationService(O),x={className:n.class,classRefForm:"uuid",classUid:u,label:t,aliases:n.aliases,folderPath:y,createdBy:n.createdBy||qle,timezone:n.timezone||Vle,body:s,propertyValues:g,shapeRegistry:A};if(n.validate){let j=(0,Ni.liveUidGenerator)().next(),$=(0,Ni.liveClock)().now();v.withDeterminism({uidGenerator:{next:a(()=>j,"next")},clock:{now:a(()=>new Date($.getTime()),"now")}});let q=v.buildAsset(x),{CandidateShaclValidator:ge}=await Promise.resolve().then(()=>(N$(),L$)),ye=new ge(e),{violations:Q,warnings:oe}=await ye.validateCandidate(q.path,q.content);for(let J of oe)process.stderr.write(`\u26A0 SHACL warning on ${J.propertyPath} (${J.constraint}): ${J.message}
|
|
@@ -544,10 +544,11 @@ ${w}
|
|
|
544
544
|
--- END PREVIEW ---
|
|
545
545
|
`):(0,Nf.writeFileSync)(r,w,"utf-8"),A&&process.stderr.write(A+`
|
|
546
546
|
`);let O={path:i,property:l,value:c,updatedAt:y,...A?{coLocationWarning:!0}:{}};process.stdout.write(JSON.stringify(O)+`
|
|
547
|
-
`),process.exit(0)}catch(t){we.handle(t)}})}a(B$,"setPropertyCommand");ft();var ia=require("path"),kf=require("fs"),uR=Se(Ze());Rt();jt();function Zle(n){let e=n.input!==void 0,t=n.property!==void 0;if(e&&t)throw new nt("Pass --input OR --property, not both.","remove-property <path> --property <name>");if(e){let r;try{r=JSON.parse(n.input)}catch(s){let o=s instanceof Error?s.message:String(s);throw new Error(`--input: invalid JSON (${o})`)}if(typeof r!="object"||r===null||Array.isArray(r))throw new Error('--input must be a JSON object of the form {"property":"<name>"}');let i=r.property;if(typeof i!="string"||i.trim().length===0)throw new Error("--input.property must be a non-empty string");return i.trim()}if(t){let r=n.property.trim();if(r.length===0)throw new Error("--property must be a non-empty name");return r}throw new nt("No property provided.",`remove-property <path> --property <name> OR remove-property <path> --input '{"property":"<name>"}'`)}a(Zle,"resolveProperty");function V$(){return new xe("remove-property").description("Delete a non-guarded frontmatter property from an existing vault asset (bumps exo__Asset_updatedAt when a change occurs). The delete-side counterpart of set-property; refuses state-machine-guarded properties (status/zone/parent/label/fact-timestamps) \u2014 those keep their dedicated `apply` commands. Issue #3926.").argument("<path>","Vault-relative path to the target asset").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--input <json>",`JSON {"property":"<name>"} \u2014 the property to remove (symmetric with set-property's --input).`).option("--property <name>","Property name to remove (convenience form; use --input for scripting)").option("--timezone <tz>","Timezone for the exo__Asset_updatedAt bump (defaults to Asia/Almaty)").option("--frozen-clock <iso>","Freeze the updatedAt clock to an ISO timestamp for test/replay").option("--dry-run","Preview the resulting frontmatter without writing").option("--yes","Accepted for symmetry with the apply/create subcommands (remove-property is non-interactive; no-op)").action(async(n,e)=>{try{let t=(0,ia.resolve)(e.vault);if(!(0,kf.existsSync)(t))throw new Xe(t);let r=(0,ia.resolve)(t,n),i=(0,ia.relative)(t,r);if(i===".."||i.startsWith(`..${ia.sep}`)||(0,ia.isAbsolute)(i))throw new Error(`Target is outside the vault: ${n} (vault: ${t})`);let s;try{s=(0,kf.readFileSync)(r,"utf-8")}catch(
|
|
548
|
-
|
|
547
|
+
`),process.exit(0)}catch(t){we.handle(t)}})}a(B$,"setPropertyCommand");ft();var ia=require("path"),kf=require("fs"),uR=Se(Ze());Rt();jt();function Zle(n){let e=n.input!==void 0,t=n.property!==void 0;if(e&&t)throw new nt("Pass --input OR --property, not both.","remove-property <path> --property <name>");if(e){let r;try{r=JSON.parse(n.input)}catch(s){let o=s instanceof Error?s.message:String(s);throw new Error(`--input: invalid JSON (${o})`)}if(typeof r!="object"||r===null||Array.isArray(r))throw new Error('--input must be a JSON object of the form {"property":"<name>"}');let i=r.property;if(typeof i!="string"||i.trim().length===0)throw new Error("--input.property must be a non-empty string");return i.trim()}if(t){let r=n.property.trim();if(r.length===0)throw new Error("--property must be a non-empty name");return r}throw new nt("No property provided.",`remove-property <path> --property <name> OR remove-property <path> --input '{"property":"<name>"}'`)}a(Zle,"resolveProperty");function V$(){return new xe("remove-property").description("Delete a non-guarded frontmatter property from an existing vault asset (bumps exo__Asset_updatedAt when a change occurs). The delete-side counterpart of set-property; refuses state-machine-guarded properties (status/zone/parent/label/fact-timestamps) \u2014 those keep their dedicated `apply` commands. Issue #3926.").argument("<path>","Vault-relative path to the target asset").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--input <json>",`JSON {"property":"<name>"} \u2014 the property to remove (symmetric with set-property's --input).`).option("--property <name>","Property name to remove (convenience form; use --input for scripting)").option("--timezone <tz>","Timezone for the exo__Asset_updatedAt bump (defaults to Asia/Almaty)").option("--frozen-clock <iso>","Freeze the updatedAt clock to an ISO timestamp for test/replay").option("--dry-run","Preview the resulting frontmatter without writing").option("--yes","Accepted for symmetry with the apply/create subcommands (remove-property is non-interactive; no-op)").action(async(n,e)=>{try{let t=(0,ia.resolve)(e.vault);if(!(0,kf.existsSync)(t))throw new Xe(t);let r=(0,ia.resolve)(t,n),i=(0,ia.relative)(t,r);if(i===".."||i.startsWith(`..${ia.sep}`)||(0,ia.isAbsolute)(i))throw new Error(`Target is outside the vault: ${n} (vault: ${t})`);let s;try{s=(0,kf.readFileSync)(r,"utf-8")}catch(S){throw S.code==="ENOENT"?new Error(`Target file not found: ${n}`):S}if(!/^\s*exo__Asset_uid:/m.test(s))throw new Error(`Not a vault asset (no exo__Asset_uid): ${i}. remove-property only mutates existing assets.`);let o=Zle(e),c=uR.FrontmatterService.normalizeIRI(o),l=Df(P_,c);if(l!==void 0)throw new Error(`Refusing to remove "${c}" \u2014 ${l}.`);let u=Df(O_,c);if(u!==void 0)throw new Error(`Refusing to remove "${c}" via remove-property \u2014 it has a dedicated guarded command so the state machine / precondition is not bypassed. Use: exocortex ${u} --vault <v>`);let f=new uR.FrontmatterService,d=f.removeProperty(s,(0,Oh.canonicalYamlKey)(c)),p=d!==s,h=d,g;if(p){let S=e.frozenClock?new Date(e.frozenClock):new Date,w=e.timezone??Ff;g=Lf(S,w),h=f.updateProperty(d,bl,g)}p||await new sc(t).isUnknownName(c)&&process.stderr.write(`\u26A0\uFE0F Nothing was removed, and "${c}" is not a property in the mounted TBox \u2014 check the spelling (an undeclared property is removable, so this is a hint, not a refusal).
|
|
548
|
+
`),e.dryRun?process.stderr.write(`--- DRY RUN PREVIEW ---
|
|
549
|
+
${h}
|
|
549
550
|
--- END PREVIEW ---
|
|
550
|
-
`):
|
|
551
|
+
`):p&&(0,kf.writeFileSync)(r,h,"utf-8");let y={path:i,property:c,removed:p,...g?{updatedAt:g}:{}};process.stdout.write(JSON.stringify(y)+`
|
|
551
552
|
`),process.exit(0)}catch(t){we.handle(t)}})}a(V$,"removePropertyCommand");ft();var sa=require("path"),cc=require("fs"),q$=Se(Ze());Rt();jt();function eue(n){return new Promise((e,t)=>{let r=[],i=setTimeout(()=>{t(new Error(`Timed out reading body from stdin after ${n}ms`))},n);process.stdin.on("data",s=>r.push(Buffer.from(s))),process.stdin.on("end",()=>{clearTimeout(i),e(Buffer.concat(r).toString("utf-8"))}),process.stdin.on("error",s=>{clearTimeout(i),t(s)})})}a(eue,"readStdin");async function tue(n){if(n.bodyFile){if(!(0,cc.existsSync)(n.bodyFile))throw new Error(`Body file not found: ${n.bodyFile}`);return(0,cc.readFileSync)(n.bodyFile,"utf-8")}if(n.body==="-")return eue(3e4);if(n.body!==void 0)return n.body}a(tue,"resolveNewBody");function G$(){return new xe("set-body").description("Overwrite the markdown BODY of an existing vault asset (frontmatter untouched, exo__Asset_updatedAt bumped, new-body wikilinks validated). The dogfood body-rewrite path \u2014 no raw backup\u2192rm\u2192Write. Issue #3943.").argument("<path>","Vault-relative path to the asset to rewrite").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--body-file <path>","Read the new body from a file").option("--body <text>","New body text ('-' reads from stdin)").option("--timezone <tz>","Timezone for the exo__Asset_updatedAt bump (defaults to Asia/Almaty)").option("--frozen-clock <iso>","Freeze the updatedAt clock to an ISO timestamp for test/replay").option("--dry-run","Preview the resulting content without writing").option("--skip-wikilink-validation","Skip wikilink existence validation for the new body").action(async(n,e)=>{try{let t=(0,sa.resolve)(e.vault);if(!(0,cc.existsSync)(t))throw new Xe(t);let r=(0,sa.resolve)(t,n),i=(0,sa.relative)(t,r);if(i===".."||i.startsWith(`..${sa.sep}`)||(0,sa.isAbsolute)(i))throw new Error(`Target is outside the vault: ${n} (vault: ${t})`);if(e.bodyFile===void 0&&e.body===void 0)throw new Error("Provide the new body via --body-file <path>, --body <text>, or --body - (stdin).");let s;try{s=(0,cc.readFileSync)(r,"utf-8")}catch(w){throw w.code==="ENOENT"?new Error(`Target file not found: ${n}`):w}if(!/^\s*exo__Asset_uid:/m.test(s))throw new Error(`Not a vault asset (no exo__Asset_uid): ${i}. set-body only rewrites existing assets.`);let o=new q$.FrontmatterService,c=o.parse(s);if(!c.exists)throw new Error(`No frontmatter block found in ${i}; set-body preserves the frontmatter and only rewrites the body.`);let l=`---
|
|
552
553
|
${c.content}
|
|
553
554
|
---`,u=await tue(e)??"";u=u.replace(/\\n/g,`
|
|
@@ -634,7 +635,7 @@ Next steps:
|
|
|
634
635
|
`).map(r=>r.trim()).filter(r=>r.length>0),t=e[e.length-1];if(t!==void 0)try{return JSON.parse(t)}catch{return}}a(ode,"parseLastJsonLine");function sU(n,e){return e.filter(t=>{let r=n[t];return typeof r!="string"||r.trim().length===0})}a(sU,"missingStringFields");var Z_=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:iU,message:"Invalid request: expected a JSON-RPC object"}};let t=e.id,r=t===void 0;if(typeof e.method!="string")return r?null:{jsonrpc:"2.0",id:t??null,error:{code:iU,message:"Invalid request: missing method"}};if(r)return null;let i=t??null;switch(e.method){case"initialize":return{jsonrpc:"2.0",id:i,result:{protocolVersion:ide,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:nU}};case"tools/call":return{jsonrpc:"2.0",id:i,result:await this.callTool(e.params??{})};default:return{jsonrpc:"2.0",id:i,error:{code:sde,message:`Method not found: ${e.method}`}}}}async callTool(e){let t=e.name,r=e.arguments??{},i;if(t==="create_asset"){let c=sU(r,["vault","class","label"]);if(c.length>0)return Wf(`create_asset: missing required argument(s): ${c.join(", ")}`,!0);let l=eU(r);if(l!==null)return Wf(`create_asset: ${l}`,!0);i=tU(r)}else if(t==="create_effort"){let c=sU(r,["vault","command","target"]);if(c.length>0)return Wf(`create_effort: missing required argument(s): ${c.join(", ")}`,!0);i=rU(r)}else return Wf(`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 Wf(`exocortex-cli exited ${s.exitCode}
|
|
635
636
|
${c}`,!0)}let o=ode(s.stdout);return Wf(o===void 0?s.stdout.trim():JSON.stringify(o))}};var cU=require("child_process");var ade=32*1024*1024;function lU(n){return e=>new Promise(t=>{(0,cU.execFile)(process.execPath,[n,...e],{maxBuffer:ade},(r,i,s)=>{let o=0;if(r){let c=r.code;o=typeof c=="number"?c:1}t({stdout:i,stderr:s,exitCode:o})})})}a(lU,"createSelfCliRunner");async function cde(n,e,t){let r=(0,uU.createInterface)({input:e,crlfDelay:1/0});for await(let i of r){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:oU,message:"Parse error: invalid JSON"}})+`
|
|
636
637
|
`);continue}let c;try{c=await n.handle(o)}catch(l){c={jsonrpc:"2.0",id:typeof o?.id=="string"||typeof o?.id=="number"?o.id:null,error:{code:aU,message:`Internal error: ${l instanceof Error?l.message:String(l)}`}}}c!==null&&t(JSON.stringify(c)+`
|
|
637
|
-
`)}}a(cde,"runStdioServer");function fU(n){return new xe("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],r=new Z_({runCli:lU(t),version:n??"unknown"});await cde(r,process.stdin,i=>process.stdout.write(i))})}a(fU,"mcpCommand");function eS(n){let e=new xe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(n??"16.212.
|
|
638
|
+
`)}}a(cde,"runStdioServer");function fU(n){return new xe("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],r=new Z_({runCli:lU(t),version:n??"unknown"});await cde(r,process.stdin,i=>process.stdout.write(i))})}a(fU,"mcpCommand");function eS(n){let e=new xe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(n??"16.212.3"),e.addCommand(Y$()),e.addCommand(n6()),e.addCommand(z5()),e.addCommand(X5()),e.addCommand(g$()),e.addCommand(J5()),e.addCommand(i$()),e.addCommand(v$()),e.addCommand(R$()),e.addCommand(U$()),e.addCommand(B$()),e.addCommand(V$()),e.addCommand(G$()),e.addCommand(W$()),e.addCommand(v6()),e.addCommand(I6()),e.addCommand(B6()),e.addCommand(q6()),e.addCommand(H6()),e.addCommand(z6()),e.addCommand(X6()),e.addCommand(F6()),e.addCommand(j6()),e.addCommand(J6()),e.addCommand(fU(n??"16.212.3")),e}a(eS,"createProgram");eS().parse();0&&(module.exports={createProgram});
|
|
638
639
|
/*! Bundled license information:
|
|
639
640
|
|
|
640
641
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED