@kitelev/exocortex-cli 15.114.8 → 15.114.10

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 +3 -3
  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 v15.114.8
2
+ // @kitelev/exocortex-cli v15.114.10
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -67,7 +67,7 @@ ${r}}`}default:throw new Mc(`Unsupported operation type for SPARQL generation: $
67
67
  `)}generateTriple(e){let t=this.generateElement(e.subject),r=this.generatePredicate(e.predicate),i=this.generateElement(e.object);return`${t} ${r} ${i}`}generatePredicate(e){return"pathType"in e?this.generatePropertyPath(e):this.generateElement(e)}generatePropertyPath(e){let t=e.items.map(r=>"pathType"in r?`(${this.generatePropertyPath(r)})`:`<${r.value}>`);switch(e.pathType){case"/":return t.join("/");case"|":return t.join("|");case"^":return`^${t[0]}`;case"+":return`${t[0]}+`;case"*":return`${t[0]}*`;case"?":return`${t[0]}?`}}generateElement(e){switch(e.type){case"variable":return`?${e.value}`;case"iri":return`<${e.value}>`;case"literal":{let r=`"${e.value.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}"`;return e.language?r+=`@${e.language}`:e.datatype&&(r+=`^^<${e.datatype}>`),r}case"blank":return`_:${e.value}`;default:throw new Mc(`Unknown element type: ${e.type}`)}}generateValues(e,t){let r=" ".repeat(t);if(e.variables.length===0||e.bindings.length===0)return"";if(e.variables.length===1){let a=e.variables[0],c=e.bindings.map(l=>{let u=l[a];return u?this.generateValuesTerm(u):"UNDEF"}).join(" ");return`${r}VALUES ?${a} { ${c} }`}let i=e.variables.map(a=>`?${a}`).join(" "),s=e.bindings.map(a=>`(${e.variables.map(l=>{let u=a[l];return u?this.generateValuesTerm(u):"UNDEF"}).join(" ")})`);return`${r}VALUES (${i}) {
68
68
  ${s.map(a=>`${r} ${a}`).join(`
69
69
  `)}
70
- ${r}}`}generateValuesTerm(e){if(e.type==="iri")return`<${e.value}>`;let r=`"${e.value.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;return e.language?r+=`@${e.language}`:e.datatype&&(r+=`^^<${e.datatype}>`),r}generateExpression(e){switch(e.type){case"variable":return`?${e.name}`;case"literal":return typeof e.value=="string"?`"${e.value.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:typeof e.value=="boolean"?e.value?"true":"false":String(e.value);case"comparison":return`(${this.generateExpression(e.left)} ${e.operator} ${this.generateExpression(e.right)})`;case"logical":return e.operator==="!"?`!(${this.generateExpression(e.operands[0])})`:`(${e.operands.map(t=>this.generateExpression(t)).join(` ${e.operator} `)})`;case"arithmetic":return`(${this.generateExpression(e.left)} ${e.operator} ${this.generateExpression(e.right)})`;case"function":return`${e.function.toUpperCase()}(${e.args.map(t=>this.generateExpression(t)).join(", ")})`;case"functionCall":return`${(typeof e.function=="string"?e.function:e.function.value).toUpperCase()}(${e.args.map(r=>this.generateExpression(r)).join(", ")})`;case"exists":return`${e.negated?"NOT EXISTS":"EXISTS"} { ${this.generateWhereClause(e.pattern,0)} }`;case"in":{let t=this.generateExpression(e.expression),r=e.list.map(i=>this.generateExpression(i)).join(", ");return e.negated?`${t} NOT IN (${r})`:`${t} IN (${r})`}default:throw new Mc(`Unknown expression type: ${e.type}`)}}collectVariablesFromOperation(e,t){switch(e.type){case"bgp":for(let r of e.triples)this.collectVariablesFromTriple(r,t);break;case"filter":this.collectVariablesFromOperation(e.input,t),this.collectVariablesFromExpression(e.expression,t);break;case"join":case"leftjoin":case"union":case"minus":this.collectVariablesFromOperation(e.left,t),this.collectVariablesFromOperation(e.right,t);break;case"values":for(let r of e.variables)t.add(r);break;case"project":for(let r of e.variables)t.add(r);this.collectVariablesFromOperation(e.input,t);break;case"extend":t.add(e.variable),this.collectVariablesFromOperation(e.input,t);break;case"orderby":case"slice":case"distinct":case"reduced":this.collectVariablesFromOperation(e.input,t);break;case"group":for(let r of e.variables)t.add(r);for(let r of e.aggregates)t.add(r.variable);this.collectVariablesFromOperation(e.input,t);break;case"subquery":this.collectVariablesFromOperation(e.query,t);break}}collectVariablesFromTriple(e,t){e.subject.type==="variable"&&t.add(e.subject.value),"type"in e.predicate&&e.predicate.type==="variable"&&t.add(e.predicate.value),e.object.type==="variable"&&t.add(e.object.value)}collectVariablesFromExpression(e,t){switch(e.type){case"variable":t.add(e.name);break;case"comparison":case"arithmetic":this.collectVariablesFromExpression(e.left,t),this.collectVariablesFromExpression(e.right,t);break;case"logical":for(let r of e.operands)this.collectVariablesFromExpression(r,t);break;case"function":case"functionCall":for(let r of e.args)this.collectVariablesFromExpression(r,t);break;case"exists":this.collectVariablesFromOperation(e.pattern,t);break;case"in":this.collectVariablesFromExpression(e.expression,t);for(let r of e.list)this.collectVariablesFromExpression(r,t);break}}};jc.SPARQLGenerator=Z1});var Ou=v(Sn=>{"use strict";var CM=Sn&&Sn.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=t);var i=Object.getOwnPropertyDescriptor(e,t);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:o(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),IM=Sn&&Sn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),f3=Sn&&Sn.__importStar||(function(){var n=o(function(e){return n=Object.getOwnPropertyNames||function(t){var r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[r.length]=i);return r},n(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=n(e),i=0;i<r.length;i++)r[i]!=="default"&&CM(t,e,r[i]);return IM(t,e),t}})();Object.defineProperty(Sn,"__esModule",{value:!0});Sn.QueryExecutor=Sn.ExoQLQueryExecutor=Sn.QueryExecutorError=void 0;var RM=E1(),PM=tp(),OM=j1(),FM=V1(),DM=e3(),NM=r3(),LM=s3(),kM=X1(),MM=o3(),jM=l3(),$M=u3(),VM=Ae(),$c=class extends Error{static{o(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Sn.QueryExecutorError=$c;var up=class{static{o(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new RM.BGPExecutor(e),this.filterExecutor=new PM.FilterExecutor,this.optionalExecutor=new OM.OptionalExecutor,this.unionExecutor=new FM.UnionExecutor,this.minusExecutor=new DM.MinusExecutor,this.valuesExecutor=new NM.ValuesExecutor,this.aggregateExecutor=new LM.AggregateExecutor,this.constructExecutor=new kM.ConstructExecutor,this.serviceExecutor=new MM.ServiceExecutor(t.serviceConfig),this.graphExecutor=new jM.GraphExecutor(e),this.sparqlGenerator=new $M.SPARQLGenerator,this.filterExecutor.setExistsEvaluator(async(r,i)=>this.evaluateExistsPattern(r,i)),this.filterExecutor.setTripleStore(e)}async evaluateExistsPattern(e,t){for await(let r of this.execute(e))if(t.merge(r)!==null)return!0;return!1}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*execute(e){switch(e.type){case"bgp":yield*this.executeBGP(e);break;case"filter":yield*this.executeFilter(e);break;case"join":yield*this.executeJoin(e);break;case"leftjoin":yield*this.executeLeftJoin(e);break;case"union":yield*this.executeUnion(e);break;case"minus":yield*this.executeMinus(e);break;case"values":yield*this.executeValues(e);break;case"project":yield*this.executeProject(e);break;case"orderby":yield*this.executeOrderBy(e);break;case"slice":yield*this.executeSlice(e);break;case"distinct":yield*this.executeDistinct(e);break;case"reduced":yield*this.executeReduced(e);break;case"group":yield*this.executeGroup(e);break;case"extend":yield*this.executeExtend(e);break;case"subquery":yield*this.executeSubquery(e);break;case"lateraljoin":yield*this.executeLateralJoin(e);break;case"service":yield*this.executeService(e);break;case"graph":yield*this.executeGraph(e);break;default:throw new $c(`Unknown operation type: ${e.type}`)}}async*executeBGP(e){yield*this.bgpExecutor.execute(e)}async*executeFilter(e){let t=this.execute(e.input);yield*this.filterExecutor.execute(e,t)}async*executeJoin(e){let t=[];for await(let a of this.execute(e.left))t.push(a);if(t.length===0)return;let r=new Set;for(let a of t)for(let c of a.variables())r.add(c);let i=this.collectOperationVariables(e.right);if([...r].some(a=>i.has(a)))for(let a of t){let c=this.substituteVariables(e.right,a);for await(let l of this.execute(c)){let u=a.merge(l);u!==null&&(yield u)}}else{let a=[];for await(let c of this.execute(e.right))a.push(c);for(let c of t)for(let l of a){let u=c.merge(l);u!==null&&(yield u)}}}async*executeLeftJoin(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.optionalExecutor.execute(i(),s())}async*executeUnion(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.unionExecutor.execute(i(),s())}async*executeMinus(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.minusExecutor.execute(i(),s())}async*executeValues(e){yield*this.valuesExecutor.execute(e)}async*executeProject(e){let{SolutionMapping:t}=await Promise.resolve().then(()=>f3(Xi())),r=new Set(e.variables);for await(let i of this.execute(e.input)){let s=new t;for(let a of i.variables())if(r.has(a)){let c=i.get(a);c!==void 0&&s.set(a,c)}yield s}}async*executeOrderBy(e){let t=[];for await(let r of this.execute(e.input))t.push(r);t.sort((r,i)=>{for(let s of e.comparators){let a=this.getExpressionValue(s.expression,r),c=this.getExpressionValue(s.expression,i),l=0;if(a===void 0&&c===void 0?l=0:a===void 0?l=1:c===void 0?l=-1:typeof a=="number"&&typeof c=="number"?l=a-c:l=String(a).localeCompare(String(c)),s.descending&&(l=-l),l!==0)return l}return 0});for(let r of t)yield r}async*executeSlice(e){let t=0,r=e.offset??0,i=e.limit;for await(let s of this.execute(e.input)){if(t>=r){if(i!==void 0&&t-r>=i)break;yield s}t++}}async*executeDistinct(e){let t=new Set;for await(let r of this.execute(e.input)){let i=this.getSolutionKey(r);t.has(i)||(t.add(i),yield r)}}async*executeReduced(e){let t=new Set;for await(let r of this.execute(e.input)){let i=this.getSolutionKey(r);t.has(i)||(t.add(i),yield r)}}async*executeGroup(e){let t=[];for await(let i of this.execute(e.input))t.push(i);let r=this.aggregateExecutor.execute(e,t);if(e.having&&e.having.length>0)for(let i of r)e.having.every(a=>this.filterExecutor.evaluateExpression(a,i)===!0)&&(yield i);else for(let i of r)yield i}async*executeExtend(e){let t=e.expression.type!=="aggregate"&&this.filterExecutor.expressionContainsExists(e.expression);for await(let r of this.execute(e.input)){let i=r.clone(),s=t?await this.evaluateExtendExpressionAsync(e.expression,r):this.evaluateExtendExpression(e.expression,r);s!==void 0&&i.set(e.variable,s),yield i}}async*executeSubquery(e){yield*this.execute(e.query)}async*executeLateralJoin(e){let t=[];for await(let r of this.execute(e.left))t.push(r);for(let r of t){let i=this.substituteVariables(e.right,r);for await(let s of this.execute(i)){let a=r.merge(s);a!==null&&(yield a)}}}substituteVariables(e,t){let r=JSON.parse(JSON.stringify(e));return this.substituteInOperation(r,t)}substituteInOperation(e,t){if(!e||typeof e!="object")return e;let r=e;return e.type==="bgp"&&e.triples?(e.triples=e.triples.map(i=>this.substituteInTriple(i,t)),e):(r.input&&(r.input=this.substituteInOperation(r.input,t)),r.left&&(r.left=this.substituteInOperation(r.left,t)),r.right&&(r.right=this.substituteInOperation(r.right,t)),r.pattern&&(r.pattern=this.substituteInOperation(r.pattern,t)),r.query&&(r.query=this.substituteInOperation(r.query,t)),r.where&&(r.where=this.substituteInOperation(r.where,t)),r.expression&&this.substituteInExpression(r.expression,t),e)}substituteInExpression(e,t){if(!(!e||typeof e!="object")){if(e.type==="exists"&&e.pattern&&(e.pattern=this.substituteInOperation(e.pattern,t)),e.left&&this.substituteInExpression(e.left,t),e.right&&this.substituteInExpression(e.right,t),e.operands)for(let r of e.operands)this.substituteInExpression(r,t);if(e.args)for(let r of e.args)this.substituteInExpression(r,t);if(e.expression&&this.substituteInExpression(e.expression,t),e.list)for(let r of e.list)this.substituteInExpression(r,t)}}substituteInTriple(e,t){return{subject:this.substituteInTripleElement(e.subject,t),predicate:e.predicate,object:this.substituteInTripleElement(e.object,t)}}substituteInTripleElement(e,t){if(e&&e.type==="variable"){let r=t.get(e.value);if(r!=null){let i=r;if(r instanceof VM.IRI||i.termType==="NamedNode")return{type:"iri",value:r.value};if(i.termType==="Literal"||typeof i.value=="string")return{type:"literal",value:i.value,datatype:i.datatype?.value??i._datatype?.value,language:i.language??i._language}}}return e}async*executeService(e){yield*this.serviceExecutor.execute(e,t=>this.sparqlGenerator.generateSelect(t))}async*executeGraph(e){let t=async function*(r,i){let s=this.currentGraphContext;this.currentGraphContext=i;try{r.type==="bgp"&&i&&this.tripleStore.matchInGraph?yield*this.executeBGPInGraph(r,i):yield*this.execute(r)}finally{this.currentGraphContext=s}}.bind(this);yield*this.graphExecutor.execute(e,t)}async*executeBGPInGraph(e,t){if(e.triples.length===0){let{SolutionMapping:r}=await Promise.resolve().then(()=>f3(Xi()));yield new r;return}yield*this.bgpExecutor.executeInGraph(e,t)}evaluateExtendExpression(e,t){if(e.type!=="aggregate")try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}async evaluateExtendExpressionAsync(e,t){if(e.type!=="aggregate")try{return await this.filterExecutor.evaluateExpressionAsync(e,t)}catch{return}}getExpressionValue(e,t){if(e.type==="variable"){let r=t.get(e.name);return r?r.value??r.id??String(r):void 0}if(e.type==="literal")return e.value}collectOperationVariables(e){let t=new Set;return this.collectVarsFromOperation(e,t),t}collectVarsFromOperation(e,t){if(!e||typeof e!="object")return;let r=e;if(r.type==="bgp"&&r.triples)for(let i of r.triples)this.collectVarsFromElement(i.subject,t),i.predicate?.type!=="path"&&this.collectVarsFromElement(i.predicate,t),this.collectVarsFromElement(i.object,t);if(r.type==="values"&&r.variables)for(let i of r.variables)t.add(i);r.expression&&this.collectVarsFromExpressionTree(r.expression,t),r.type==="extend"&&r.variable&&t.add(r.variable),r.input&&this.collectVarsFromOperation(r.input,t),r.left&&this.collectVarsFromOperation(r.left,t),r.right&&this.collectVarsFromOperation(r.right,t),r.pattern&&this.collectVarsFromOperation(r.pattern,t),r.query&&this.collectVarsFromOperation(r.query,t),r.where&&this.collectVarsFromOperation(r.where,t)}collectVarsFromElement(e,t){if(!e||typeof e!="object")return;let r=e;r.type==="variable"&&t.add(r.value),r.type==="quoted"&&(this.collectVarsFromElement(r.subject,t),this.collectVarsFromElement(r.predicate,t),this.collectVarsFromElement(r.object,t))}collectVarsFromExpressionTree(e,t){if(!e||typeof e!="object")return;let r=e;if(r.type==="variable"&&r.name&&t.add(r.name),r.type==="exists"&&r.pattern&&this.collectVarsFromOperation(r.pattern,t),r.left&&this.collectVarsFromExpressionTree(r.left,t),r.right&&this.collectVarsFromExpressionTree(r.right,t),r.operands)for(let i of r.operands)this.collectVarsFromExpressionTree(i,t);if(r.args)for(let i of r.args)this.collectVarsFromExpressionTree(i,t);if(r.expression&&this.collectVarsFromExpressionTree(r.expression,t),r.list)for(let i of r.list)this.collectVarsFromExpressionTree(i,t)}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}isConstructQuery(e){return e.type==="construct"}async executeConstruct(e){if(e.type!=="construct")throw new $c("executeConstruct requires a CONSTRUCT operation");let t=await this.executeAll(e.where);return this.constructExecutor.execute(e.template,t)}isAskQuery(e){return e.type==="ask"}async executeAsk(e){if(e.type!=="ask")throw new $c("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Sn.ExoQLQueryExecutor=up;Sn.QueryExecutor=up});var d3=v(Ds=>{"use strict";var UM=Ds&&Ds.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},BM=Ds&&Ds.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Ds,"__esModule",{value:!0});Ds.CommandResolver=void 0;var qM=ce(),Fs=Ae(),ii=ze(),we=Ar(),e_=sc(),WM=Tu(),GM=Au(),zM=Ou(),t_=10,r_=class{static{o(this,"CommandResolver")}constructor(e){this.tripleStore=e,this.cache=new Map}async resolveForAsset(e,t,r){let i=`${e}:${t}:${r??""}`,s=this.cache.get(i);if(s)return s;let a=await this.findBindings(t,r,e),c=[];for(let l of a){let u=await this.loadCommand(l.commandRef);if(!u)continue;let f=l.precondition?{...u,precondition:l.precondition}:u;c.push({command:f,binding:l})}return c.sort((l,u)=>{let f=this.getBindingPriority(l.binding),d=this.getBindingPriority(u.binding);return f!==d?f-d:(l.binding.order??100)-(u.binding.order??100)}),this.cache.set(i,c),c}async loadCommand(e){let t=await this.findSubjectByUID(e);if(!t||(await this.tripleStore.match(t,we.Namespace.RDF.term("type"),we.Namespace.EXOCMD.term("Command"))).length===0)return null;let i=await this.getLiteralValue(t,we.Namespace.EXO.term("Asset_label"))??"Unknown Command",s=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_labelTemplate")),a=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_icon")),c=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_confirmMessage")),l=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_successMessage")),u=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_category")),f=await this.loadLinkedPrecondition(t),d=await this.loadLinkedGrounding(t,0);return d?{id:e,name:i,labelTemplate:s??void 0,icon:a??void 0,precondition:f??void 0,grounding:d,confirmMessage:c??void 0,successMessage:l??void 0,category:u??void 0}:null}async findBindings(e,t,r){let i=await this.tripleStore.match(void 0,we.Namespace.RDF.term("type"),we.Namespace.EXOCMD.term("CommandBinding")),s=[];for(let a of i){let c=a.subject,l=await this.loadBindingDefinition(c);l&&this.bindingMatches(l,e,t,r)&&s.push(l)}return s}invalidateCache(){this.cache.clear()}async resolveLabel(e,t){if(!e.labelTemplate)return e.name;let r=e.labelTemplate,i=this.extractPlaceholders(e.labelTemplate);for(let{full:s,body:a}of i){let c=await this.evaluateSelectSnippet(a,t);r=r.replace(s,c)}return r}extractPlaceholders(e){let t=[],r=0;for(;r<e.length;)if(e[r]==="{"){let i=1,s=r+1;for(;s<e.length&&i>0;)e[s]==="{"?i++:e[s]==="}"&&i--,s++;if(i===0){let a=e.slice(r,s),c=e.slice(r+1,s-1);t.push({full:a,body:c})}r=s}else r++;return t}async evaluateSelectSnippet(e,t){try{let r=e.replace(/\$target/g,`<${t}>`),s=new WM.ExoQLParser().parse(r),c=new GM.ExoQLAlgebraTranslator().translate(s),u=await new zM.ExoQLQueryExecutor(this.tripleStore).executeAll(c);if(u.length===0)return"";let f=u[0],d=f.variables();if(d.length===0)return"";let h=f.get(d[0]);return h?h instanceof ii.Literal||h instanceof Fs.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,we.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetClass")),a=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!a&&!c)return null;let l=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_group")),d=await this.loadLinkedPreconditionFromProperty(e,we.Namespace.EXOCMD.term("CommandBinding_precondition"));return{id:t,label:r,commandRef:i,targetClass:s??void 0,targetPrototype:a??void 0,targetAsset:c??void 0,position:l??void 0,order:u?parseInt(u,10):void 0,group:f??void 0,precondition:d??void 0}}bindingMatches(e,t,r,i){return!!(e.targetAsset&&i&&this.matchesReference(e.targetAsset,i)||e.targetPrototype&&r&&this.matchesReference(e.targetPrototype,r)||e.targetClass&&t&&this.matchesReference(e.targetClass,t))}matchesReference(e,t){let r=this.normalizeWikilink(e),i=this.normalizeWikilink(t);if(r===i)return!0;let s=this.extractAlias(t);if(s&&r===s)return!0;let a=this.extractAlias(e);return!!(a&&a===i)}extractAlias(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(r+1).trim():null}getBindingPriority(e){return e.targetAsset?0:e.targetPrototype?1:2}async loadLinkedPrecondition(e){return this.loadLinkedPreconditionFromProperty(e,we.Namespace.EXOCMD.term("Command_precondition"))}async loadLinkedPreconditionFromProperty(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object,s=null;if(i instanceof Fs.IRI)s=i;else if(i instanceof ii.Literal){let f=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(f)}if(!s)return null;let a=await this.getLiteralValue(s,we.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,we.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,we.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,we.Namespace.EXOCMD.term("Precondition_hostFunction"));return!a||!l&&!u?null:{id:a,label:c,...l&&{sparqlAsk:l},...u&&{hostFunction:u}}}async loadLinkedGrounding(e,t){if(t>=t_)return null;let r=await this.tripleStore.match(e,we.Namespace.EXOCMD.term("Command_grounding"),void 0);if(r.length===0)return null;let i=r[0].object,s=null;if(i instanceof Fs.IRI)s=i;else if(i instanceof ii.Literal){let a=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(a)}return s?this.loadGroundingDefinition(s,t):null}async loadGroundingDefinition(e,t){if(t>=t_)return null;let r=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_label"))??"",s=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_type"));if(!s)return null;let a=this.resolveGroundingType(s);if(!a)return null;let c=await this.getObsidianName(e,we.Namespace.EXOCMD.term("Grounding_targetProperty"));if(a===e_.GroundingType.SERVICE_CALL){let w=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_serviceId"));w&&(c=w)}let l=await this.getObsidianWikilinkValue(e,we.Namespace.EXOCMD.term("Grounding_targetValue")),u=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),f=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetClass")),d=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetPrototype")),h=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetFolder")),p=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_inputSchema")),_;a===e_.GroundingType.COMPOSITE&&(_=await this.loadCompositeSteps(e,t+1));let S;if(p)try{let w=JSON.parse(p);w?.properties&&(S=Object.entries(w.properties).map(([A,R])=>({name:A,type:R.type==="string"?"text":R.type,label:R.title??A,required:Array.isArray(w.required)&&w.required.includes(A)})))}catch{}let E={id:r,label:i,type:a,targetProperty:c??void 0,targetValue:l??void 0,sparqlUpdate:u??void 0,steps:_,targetClass:f??void 0,targetPrototype:d??void 0,targetFolder:h??void 0};return S&&(E.inputSchema=S),E}async loadCompositeSteps(e,t){if(t>=t_)return[];let r=await this.tripleStore.match(e,we.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let a=null;if(s.object instanceof Fs.IRI)a=s.object;else if(s.object instanceof ii.Literal){let l=this.normalizeWikilink(s.object.value);a=await this.findSubjectByUID(l)}if(!a)continue;let c=await this.loadGroundingDefinition(a,t);c&&i.push(c)}return i}resolveGroundingType(e){let t=e.toLowerCase().trim();return Object.values(e_.GroundingType).includes(t)?t:null}async findSubjectByUID(e){if(this.tripleStore.findSubjectsByUUID){let r=await this.tripleStore.findSubjectsByUUID(e);if(r.length>0)return r[0]}let t=await this.tripleStore.match(void 0,we.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof ii.Literal&&r.object.value===e)return r.subject;return null}async getLiteralValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal||i instanceof Fs.IRI?i.value:null}async getLinkedUID(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;if(i instanceof Fs.IRI){let s=await this.tripleStore.match(i,we.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof ii.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof ii.Literal?this.normalizeWikilink(i.value):null}async getLinkedValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal?this.normalizeWikilink(i.value):i instanceof Fs.IRI?this.iriToObsidianName(i.value)??i.value:null}async getObsidianName(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal?i.value:i instanceof Fs.IRI?this.iriToObsidianName(i.value)??i.value:null}async getObsidianWikilinkValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;if(i instanceof ii.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof Fs.IRI){let s=this.iriToObsidianName(i.value);return s?`"[[${s}]]"`:i.value}return null}async resolveWikilinkAlias(e){let t=e.match(/\[\[([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\]\]/);if(!t)return e;let r=t[1],i=await this.findSubjectByUID(r);if(!i)return e;let s=await this.getLiteralValue(i,we.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){let t=e.lastIndexOf("#");if(t>=0){let i=e.substring(0,t+1),s=e.substring(t+1);if(i===we.Namespace.EMS.iri.value)return`ems__${s}`;if(i===we.Namespace.EXO.iri.value)return`exo__${s}`;if(i===we.Namespace.EXOCMD.iri.value)return`exocmd__${s}`;if(i===we.Namespace.IMS.iri.value)return`ims__${s}`;if(i===we.Namespace.ZTLK.iri.value)return`ztlk__${s}`;if(i===we.Namespace.PTMS.iri.value)return`ptms__${s}`;if(i===we.Namespace.LIT.iri.value)return`lit__${s}`;if(i===we.Namespace.INBOX.iri.value)return`inbox__${s}`}let r=e.match(/\/([^/]+)\.md$/);return r?r[1]:null}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};Ds.CommandResolver=r_;Ds.CommandResolver=r_=UM([(0,qM.injectable)(),BM("design:paramtypes",[Object])],r_)});var p3=v(Ns=>{"use strict";var HM=Ns&&Ns.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},QM=Ns&&Ns.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},Fu;Object.defineProperty(Ns,"__esModule",{value:!0});Ns.PreconditionEvaluator=void 0;var YM=ce(),XM=Tu(),KM=Au(),h3=Ou(),Du=Fu=class{static{o(this,"PreconditionEvaluator")}constructor(e){this.hostFunctions=new Map,this.askCache=new Map,this.tripleStore=e}async evaluate(e,t,r){return e?e.sparqlAsk?this.evaluateSparqlAsk(e.sparqlAsk,t):e.hostFunction?this.evaluateHostFunction(e.hostFunction,t,r):!0:!0}registerHostFunction(e,t){this.hostFunctions.set(e,t)}hasHostFunction(e){return this.hostFunctions.has(e)}invalidateCache(){this.askCache.clear()}compileAsk(e){let t=this.substituteVariables(e,Fu.SENTINEL_IRI),i=new XM.ExoQLParser().parse(t),a=new KM.ExoQLAlgebraTranslator().translate(i);return new h3.ExoQLQueryExecutor(this.tripleStore).isAskQuery(a)?a:null}evaluateHostFunction(e,t,r){let i=this.hostFunctions.get(e);if(!i)return!0;let s=r?{...r,targetIRI:t}:{targetIRI:t};return i(s)}async evaluateSparqlAsk(e,t){try{let r=this.askCache.get(e);if(r===void 0){let a=this.compileAsk(e);if(!a)return!1;r=a,this.askCache.set(e,r)}let i=JSON.parse(JSON.stringify(r).replaceAll(Fu.SENTINEL_IRI,t));return await new h3.ExoQLQueryExecutor(this.tripleStore).executeAsk(i)}catch{return!1}}substituteVariables(e,t){let r=new Date().toISOString(),i=r.slice(0,10),s=new Date,a=new Date(s.getTime()+Fu.ALMATY_OFFSET_MS),c=a.getUTCFullYear(),l=a.getUTCMonth(),u=a.getUTCDate(),f=a.getUTCDay(),h=new Date(Date.UTC(c,l,u-1)).toISOString().slice(0,10),p=(f+6)%7,_=new Date(Date.UTC(c,l,u-p)),S=_.toISOString().slice(0,10),w=new Date(_.getTime()-10080*60*1e3).toISOString().slice(0,10),A=`${c}-${String(l+1).padStart(2,"0")}-01`,R=l===0?11:l-1,W=`${l===0?c-1:c}-${String(R+1).padStart(2,"0")}-01`,be=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${r}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${S}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${w}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${A}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${W}"^^xsd:date`).replace(/\$thisYearStart/g,`"${be}"^^xsd:date`).replace(/\$today/g,`"${i}"^^xsd:date`)}};Ns.PreconditionEvaluator=Du;Du.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Du.ALMATY_OFFSET_MS=300*60*1e3;Ns.PreconditionEvaluator=Du=Fu=HM([(0,YM.injectable)(),QM("design:paramtypes",[Object])],Du)});var Un=v(fp=>{"use strict";Object.defineProperty(fp,"__esModule",{value:!0});fp.FrontmatterService=void 0;var Nu=class n{static{o(this,"FrontmatterService")}parse(e){let t=e.match(n.FRONTMATTER_REGEX);return t?{exists:!0,content:t[1],originalContent:e}:{exists:!1,content:"",originalContent:e}}updateProperty(e,t,r){t=n.normalizeIRI(t),typeof r=="string"&&(r=n.normalizeIRIValue(r));let i=this.parse(e),s=this.serializeValue(t,r);if(!i.exists)return`---
70
+ ${r}}`}generateValuesTerm(e){if(e.type==="iri")return`<${e.value}>`;let r=`"${e.value.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`;return e.language?r+=`@${e.language}`:e.datatype&&(r+=`^^<${e.datatype}>`),r}generateExpression(e){switch(e.type){case"variable":return`?${e.name}`;case"literal":return typeof e.value=="string"?`"${e.value.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:typeof e.value=="boolean"?e.value?"true":"false":String(e.value);case"comparison":return`(${this.generateExpression(e.left)} ${e.operator} ${this.generateExpression(e.right)})`;case"logical":return e.operator==="!"?`!(${this.generateExpression(e.operands[0])})`:`(${e.operands.map(t=>this.generateExpression(t)).join(` ${e.operator} `)})`;case"arithmetic":return`(${this.generateExpression(e.left)} ${e.operator} ${this.generateExpression(e.right)})`;case"function":return`${e.function.toUpperCase()}(${e.args.map(t=>this.generateExpression(t)).join(", ")})`;case"functionCall":return`${(typeof e.function=="string"?e.function:e.function.value).toUpperCase()}(${e.args.map(r=>this.generateExpression(r)).join(", ")})`;case"exists":return`${e.negated?"NOT EXISTS":"EXISTS"} { ${this.generateWhereClause(e.pattern,0)} }`;case"in":{let t=this.generateExpression(e.expression),r=e.list.map(i=>this.generateExpression(i)).join(", ");return e.negated?`${t} NOT IN (${r})`:`${t} IN (${r})`}default:throw new Mc(`Unknown expression type: ${e.type}`)}}collectVariablesFromOperation(e,t){switch(e.type){case"bgp":for(let r of e.triples)this.collectVariablesFromTriple(r,t);break;case"filter":this.collectVariablesFromOperation(e.input,t),this.collectVariablesFromExpression(e.expression,t);break;case"join":case"leftjoin":case"union":case"minus":this.collectVariablesFromOperation(e.left,t),this.collectVariablesFromOperation(e.right,t);break;case"values":for(let r of e.variables)t.add(r);break;case"project":for(let r of e.variables)t.add(r);this.collectVariablesFromOperation(e.input,t);break;case"extend":t.add(e.variable),this.collectVariablesFromOperation(e.input,t);break;case"orderby":case"slice":case"distinct":case"reduced":this.collectVariablesFromOperation(e.input,t);break;case"group":for(let r of e.variables)t.add(r);for(let r of e.aggregates)t.add(r.variable);this.collectVariablesFromOperation(e.input,t);break;case"subquery":this.collectVariablesFromOperation(e.query,t);break}}collectVariablesFromTriple(e,t){e.subject.type==="variable"&&t.add(e.subject.value),"type"in e.predicate&&e.predicate.type==="variable"&&t.add(e.predicate.value),e.object.type==="variable"&&t.add(e.object.value)}collectVariablesFromExpression(e,t){switch(e.type){case"variable":t.add(e.name);break;case"comparison":case"arithmetic":this.collectVariablesFromExpression(e.left,t),this.collectVariablesFromExpression(e.right,t);break;case"logical":for(let r of e.operands)this.collectVariablesFromExpression(r,t);break;case"function":case"functionCall":for(let r of e.args)this.collectVariablesFromExpression(r,t);break;case"exists":this.collectVariablesFromOperation(e.pattern,t);break;case"in":this.collectVariablesFromExpression(e.expression,t);for(let r of e.list)this.collectVariablesFromExpression(r,t);break}}};jc.SPARQLGenerator=Z1});var Ou=v(Sn=>{"use strict";var CM=Sn&&Sn.__createBinding||(Object.create?(function(n,e,t,r){r===void 0&&(r=t);var i=Object.getOwnPropertyDescriptor(e,t);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:o(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),IM=Sn&&Sn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),f3=Sn&&Sn.__importStar||(function(){var n=o(function(e){return n=Object.getOwnPropertyNames||function(t){var r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[r.length]=i);return r},n(e)},"ownKeys");return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=n(e),i=0;i<r.length;i++)r[i]!=="default"&&CM(t,e,r[i]);return IM(t,e),t}})();Object.defineProperty(Sn,"__esModule",{value:!0});Sn.QueryExecutor=Sn.ExoQLQueryExecutor=Sn.QueryExecutorError=void 0;var RM=E1(),PM=tp(),OM=j1(),FM=V1(),DM=e3(),NM=r3(),LM=s3(),kM=X1(),MM=o3(),jM=l3(),$M=u3(),VM=Ae(),$c=class extends Error{static{o(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Sn.QueryExecutorError=$c;var up=class{static{o(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new RM.BGPExecutor(e),this.filterExecutor=new PM.FilterExecutor,this.optionalExecutor=new OM.OptionalExecutor,this.unionExecutor=new FM.UnionExecutor,this.minusExecutor=new DM.MinusExecutor,this.valuesExecutor=new NM.ValuesExecutor,this.aggregateExecutor=new LM.AggregateExecutor,this.constructExecutor=new kM.ConstructExecutor,this.serviceExecutor=new MM.ServiceExecutor(t.serviceConfig),this.graphExecutor=new jM.GraphExecutor(e),this.sparqlGenerator=new $M.SPARQLGenerator,this.filterExecutor.setExistsEvaluator(async(r,i)=>this.evaluateExistsPattern(r,i)),this.filterExecutor.setTripleStore(e)}async evaluateExistsPattern(e,t){for await(let r of this.execute(e))if(t.merge(r)!==null)return!0;return!1}async executeAll(e){let t=[];for await(let r of this.execute(e))t.push(r);return t}async*execute(e){switch(e.type){case"bgp":yield*this.executeBGP(e);break;case"filter":yield*this.executeFilter(e);break;case"join":yield*this.executeJoin(e);break;case"leftjoin":yield*this.executeLeftJoin(e);break;case"union":yield*this.executeUnion(e);break;case"minus":yield*this.executeMinus(e);break;case"values":yield*this.executeValues(e);break;case"project":yield*this.executeProject(e);break;case"orderby":yield*this.executeOrderBy(e);break;case"slice":yield*this.executeSlice(e);break;case"distinct":yield*this.executeDistinct(e);break;case"reduced":yield*this.executeReduced(e);break;case"group":yield*this.executeGroup(e);break;case"extend":yield*this.executeExtend(e);break;case"subquery":yield*this.executeSubquery(e);break;case"lateraljoin":yield*this.executeLateralJoin(e);break;case"service":yield*this.executeService(e);break;case"graph":yield*this.executeGraph(e);break;default:throw new $c(`Unknown operation type: ${e.type}`)}}async*executeBGP(e){yield*this.bgpExecutor.execute(e)}async*executeFilter(e){let t=this.execute(e.input);yield*this.filterExecutor.execute(e,t)}async*executeJoin(e){let t=[];for await(let a of this.execute(e.left))t.push(a);if(t.length===0)return;let r=new Set;for(let a of t)for(let c of a.variables())r.add(c);let i=this.collectOperationVariables(e.right);if([...r].some(a=>i.has(a)))for(let a of t){let c=this.substituteVariables(e.right,a);for await(let l of this.execute(c)){let u=a.merge(l);u!==null&&(yield u)}}else{let a=[];for await(let c of this.execute(e.right))a.push(c);for(let c of t)for(let l of a){let u=c.merge(l);u!==null&&(yield u)}}}async*executeLeftJoin(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.optionalExecutor.execute(i(),s())}async*executeUnion(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.unionExecutor.execute(i(),s())}async*executeMinus(e){let t=[];for await(let a of this.execute(e.left))t.push(a);let r=[];for await(let a of this.execute(e.right))r.push(a);async function*i(){for(let a of t)yield a}o(i,"leftGen");async function*s(){for(let a of r)yield a}o(s,"rightGen"),yield*this.minusExecutor.execute(i(),s())}async*executeValues(e){yield*this.valuesExecutor.execute(e)}async*executeProject(e){let{SolutionMapping:t}=await Promise.resolve().then(()=>f3(Xi())),r=new Set(e.variables);for await(let i of this.execute(e.input)){let s=new t;for(let a of i.variables())if(r.has(a)){let c=i.get(a);c!==void 0&&s.set(a,c)}yield s}}async*executeOrderBy(e){let t=[];for await(let r of this.execute(e.input))t.push(r);t.sort((r,i)=>{for(let s of e.comparators){let a=this.getExpressionValue(s.expression,r),c=this.getExpressionValue(s.expression,i),l=0;if(a===void 0&&c===void 0?l=0:a===void 0?l=1:c===void 0?l=-1:typeof a=="number"&&typeof c=="number"?l=a-c:l=String(a).localeCompare(String(c)),s.descending&&(l=-l),l!==0)return l}return 0});for(let r of t)yield r}async*executeSlice(e){let t=0,r=e.offset??0,i=e.limit;for await(let s of this.execute(e.input)){if(t>=r){if(i!==void 0&&t-r>=i)break;yield s}t++}}async*executeDistinct(e){let t=new Set;for await(let r of this.execute(e.input)){let i=this.getSolutionKey(r);t.has(i)||(t.add(i),yield r)}}async*executeReduced(e){let t=new Set;for await(let r of this.execute(e.input)){let i=this.getSolutionKey(r);t.has(i)||(t.add(i),yield r)}}async*executeGroup(e){let t=[];for await(let i of this.execute(e.input))t.push(i);let r=this.aggregateExecutor.execute(e,t);if(e.having&&e.having.length>0)for(let i of r)e.having.every(a=>this.filterExecutor.evaluateExpression(a,i)===!0)&&(yield i);else for(let i of r)yield i}async*executeExtend(e){let t=e.expression.type!=="aggregate"&&this.filterExecutor.expressionContainsExists(e.expression);for await(let r of this.execute(e.input)){let i=r.clone(),s=t?await this.evaluateExtendExpressionAsync(e.expression,r):this.evaluateExtendExpression(e.expression,r);s!==void 0&&i.set(e.variable,s),yield i}}async*executeSubquery(e){yield*this.execute(e.query)}async*executeLateralJoin(e){let t=[];for await(let r of this.execute(e.left))t.push(r);for(let r of t){let i=this.substituteVariables(e.right,r);for await(let s of this.execute(i)){let a=r.merge(s);a!==null&&(yield a)}}}substituteVariables(e,t){let r=JSON.parse(JSON.stringify(e));return this.substituteInOperation(r,t)}substituteInOperation(e,t){if(!e||typeof e!="object")return e;let r=e;return e.type==="bgp"&&e.triples?(e.triples=e.triples.map(i=>this.substituteInTriple(i,t)),e):(r.input&&(r.input=this.substituteInOperation(r.input,t)),r.left&&(r.left=this.substituteInOperation(r.left,t)),r.right&&(r.right=this.substituteInOperation(r.right,t)),r.pattern&&(r.pattern=this.substituteInOperation(r.pattern,t)),r.query&&(r.query=this.substituteInOperation(r.query,t)),r.where&&(r.where=this.substituteInOperation(r.where,t)),r.expression&&this.substituteInExpression(r.expression,t),e)}substituteInExpression(e,t){if(!(!e||typeof e!="object")){if(e.type==="exists"&&e.pattern&&(e.pattern=this.substituteInOperation(e.pattern,t)),e.left&&this.substituteInExpression(e.left,t),e.right&&this.substituteInExpression(e.right,t),e.operands)for(let r of e.operands)this.substituteInExpression(r,t);if(e.args)for(let r of e.args)this.substituteInExpression(r,t);if(e.expression&&this.substituteInExpression(e.expression,t),e.list)for(let r of e.list)this.substituteInExpression(r,t)}}substituteInTriple(e,t){return{subject:this.substituteInTripleElement(e.subject,t),predicate:e.predicate,object:this.substituteInTripleElement(e.object,t)}}substituteInTripleElement(e,t){if(e&&e.type==="variable"){let r=t.get(e.value);if(r!=null){let i=r;if(r instanceof VM.IRI||i.termType==="NamedNode")return{type:"iri",value:r.value};if(i.termType==="Literal"||typeof i.value=="string")return{type:"literal",value:i.value,datatype:i.datatype?.value??i._datatype?.value,language:i.language??i._language}}}return e}async*executeService(e){yield*this.serviceExecutor.execute(e,t=>this.sparqlGenerator.generateSelect(t))}async*executeGraph(e){let t=async function*(r,i){let s=this.currentGraphContext;this.currentGraphContext=i;try{r.type==="bgp"&&i&&this.tripleStore.matchInGraph?yield*this.executeBGPInGraph(r,i):yield*this.execute(r)}finally{this.currentGraphContext=s}}.bind(this);yield*this.graphExecutor.execute(e,t)}async*executeBGPInGraph(e,t){if(e.triples.length===0){let{SolutionMapping:r}=await Promise.resolve().then(()=>f3(Xi()));yield new r;return}yield*this.bgpExecutor.executeInGraph(e,t)}evaluateExtendExpression(e,t){if(e.type!=="aggregate")try{return this.filterExecutor.evaluateExpression(e,t)}catch{return}}async evaluateExtendExpressionAsync(e,t){if(e.type!=="aggregate")try{return await this.filterExecutor.evaluateExpressionAsync(e,t)}catch{return}}getExpressionValue(e,t){if(e.type==="variable"){let r=t.get(e.name);return r?r.value??r.id??String(r):void 0}if(e.type==="literal")return e.value}collectOperationVariables(e){let t=new Set;return this.collectVarsFromOperation(e,t),t}collectVarsFromOperation(e,t){if(!e||typeof e!="object")return;let r=e;if(r.type==="bgp"&&r.triples)for(let i of r.triples)this.collectVarsFromElement(i.subject,t),i.predicate?.type!=="path"&&this.collectVarsFromElement(i.predicate,t),this.collectVarsFromElement(i.object,t);if(r.type==="values"&&r.variables)for(let i of r.variables)t.add(i);r.expression&&this.collectVarsFromExpressionTree(r.expression,t),r.type==="extend"&&r.variable&&t.add(r.variable),r.input&&this.collectVarsFromOperation(r.input,t),r.left&&this.collectVarsFromOperation(r.left,t),r.right&&this.collectVarsFromOperation(r.right,t),r.pattern&&this.collectVarsFromOperation(r.pattern,t),r.query&&this.collectVarsFromOperation(r.query,t),r.where&&this.collectVarsFromOperation(r.where,t)}collectVarsFromElement(e,t){if(!e||typeof e!="object")return;let r=e;r.type==="variable"&&t.add(r.value),r.type==="quoted"&&(this.collectVarsFromElement(r.subject,t),this.collectVarsFromElement(r.predicate,t),this.collectVarsFromElement(r.object,t))}collectVarsFromExpressionTree(e,t){if(!e||typeof e!="object")return;let r=e;if(r.type==="variable"&&r.name&&t.add(r.name),r.type==="exists"&&r.pattern&&this.collectVarsFromOperation(r.pattern,t),r.left&&this.collectVarsFromExpressionTree(r.left,t),r.right&&this.collectVarsFromExpressionTree(r.right,t),r.operands)for(let i of r.operands)this.collectVarsFromExpressionTree(i,t);if(r.args)for(let i of r.args)this.collectVarsFromExpressionTree(i,t);if(r.expression&&this.collectVarsFromExpressionTree(r.expression,t),r.list)for(let i of r.list)this.collectVarsFromExpressionTree(i,t)}getSolutionKey(e){let t=e.toJSON();return Object.keys(t).sort().map(i=>`${i}=${t[i]}`).join("|")}isConstructQuery(e){return e.type==="construct"}async executeConstruct(e){if(e.type!=="construct")throw new $c("executeConstruct requires a CONSTRUCT operation");let t=await this.executeAll(e.where);return this.constructExecutor.execute(e.template,t)}isAskQuery(e){return e.type==="ask"}async executeAsk(e){if(e.type!=="ask")throw new $c("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Sn.ExoQLQueryExecutor=up;Sn.QueryExecutor=up});var d3=v(Ds=>{"use strict";var UM=Ds&&Ds.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},BM=Ds&&Ds.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Ds,"__esModule",{value:!0});Ds.CommandResolver=void 0;var qM=ce(),Fs=Ae(),ii=ze(),we=Ar(),e_=sc(),WM=Tu(),GM=Au(),zM=Ou(),t_=10,r_=class{static{o(this,"CommandResolver")}constructor(e){this.tripleStore=e,this.cache=new Map}async resolveForAsset(e,t,r){let i=`${e}:${t}:${r??""}`,s=this.cache.get(i);if(s)return s;let a=await this.findBindings(t,r,e),c=[];for(let l of a){let u=await this.loadCommand(l.commandRef);if(!u)continue;let f=l.precondition?{...u,precondition:l.precondition}:u;c.push({command:f,binding:l})}return c.sort((l,u)=>{let f=this.getBindingPriority(l.binding),d=this.getBindingPriority(u.binding);return f!==d?f-d:(l.binding.order??100)-(u.binding.order??100)}),this.cache.set(i,c),c}async loadCommand(e){let t=await this.findSubjectByUID(e);if(!t||(await this.tripleStore.match(t,we.Namespace.RDF.term("type"),we.Namespace.EXOCMD.term("Command"))).length===0)return null;let i=await this.getLiteralValue(t,we.Namespace.EXO.term("Asset_label"))??"Unknown Command",s=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_labelTemplate")),a=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_icon")),c=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_confirmMessage")),l=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_successMessage")),u=await this.getLiteralValue(t,we.Namespace.EXOCMD.term("Command_category")),f=await this.loadLinkedPrecondition(t),d=await this.loadLinkedGrounding(t,0);return d?{id:e,name:i,labelTemplate:s??void 0,icon:a??void 0,precondition:f??void 0,grounding:d,confirmMessage:c??void 0,successMessage:l??void 0,category:u??void 0}:null}async findBindings(e,t,r){let i=await this.tripleStore.match(void 0,we.Namespace.RDF.term("type"),we.Namespace.EXOCMD.term("CommandBinding")),s=[];for(let a of i){let c=a.subject,l=await this.loadBindingDefinition(c);l&&this.bindingMatches(l,e,t,r)&&s.push(l)}return s}invalidateCache(){this.cache.clear()}async resolveLabel(e,t){if(!e.labelTemplate)return e.name;let r=e.labelTemplate,i=this.extractPlaceholders(e.labelTemplate);for(let{full:s,body:a}of i){let c=await this.evaluateSelectSnippet(a,t);r=r.replace(s,c)}return r}extractPlaceholders(e){let t=[],r=0;for(;r<e.length;)if(e[r]==="{"){let i=1,s=r+1;for(;s<e.length&&i>0;)e[s]==="{"?i++:e[s]==="}"&&i--,s++;if(i===0){let a=e.slice(r,s),c=e.slice(r+1,s-1);t.push({full:a,body:c})}r=s}else r++;return t}async evaluateSelectSnippet(e,t){try{let r=e.replace(/\$target/g,`<${t}>`),s=new WM.ExoQLParser().parse(r),c=new GM.ExoQLAlgebraTranslator().translate(s),u=await new zM.ExoQLQueryExecutor(this.tripleStore).executeAll(c);if(u.length===0)return"";let f=u[0],d=f.variables();if(d.length===0)return"";let h=f.get(d[0]);return h?h instanceof ii.Literal||h instanceof Fs.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,we.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetClass")),a=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,we.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!a&&!c)return null;let l=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("CommandBinding_group")),d=await this.loadLinkedPreconditionFromProperty(e,we.Namespace.EXOCMD.term("CommandBinding_precondition"));return{id:t,label:r,commandRef:i,targetClass:s??void 0,targetPrototype:a??void 0,targetAsset:c??void 0,position:l??void 0,order:u?parseInt(u,10):void 0,group:f??void 0,precondition:d??void 0}}bindingMatches(e,t,r,i){return!!(e.targetAsset&&i&&this.matchesReference(e.targetAsset,i)||e.targetPrototype&&r&&this.matchesReference(e.targetPrototype,r)||e.targetClass&&t&&this.matchesReference(e.targetClass,t))}matchesReference(e,t){let r=this.normalizeWikilink(e),i=this.normalizeWikilink(t);if(r===i)return!0;let s=this.extractPathBasename(i);if(s&&s===r)return!0;let a=this.extractPathBasename(r);if(a&&a===i)return!0;let c=this.extractAlias(t);if(c&&r===c)return!0;let l=this.extractAlias(e);return!!(l&&l===i)}extractPathBasename(e){let t=e.match(/\/([^/]+)\.md$/);return t?t[1]:null}extractAlias(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(r+1).trim():null}getBindingPriority(e){return e.targetAsset?0:e.targetPrototype?1:2}async loadLinkedPrecondition(e){return this.loadLinkedPreconditionFromProperty(e,we.Namespace.EXOCMD.term("Command_precondition"))}async loadLinkedPreconditionFromProperty(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object,s=null;if(i instanceof Fs.IRI)s=i;else if(i instanceof ii.Literal){let f=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(f)}if(!s)return null;let a=await this.getLiteralValue(s,we.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,we.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,we.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,we.Namespace.EXOCMD.term("Precondition_hostFunction"));return!a||!l&&!u?null:{id:a,label:c,...l&&{sparqlAsk:l},...u&&{hostFunction:u}}}async loadLinkedGrounding(e,t){if(t>=t_)return null;let r=await this.tripleStore.match(e,we.Namespace.EXOCMD.term("Command_grounding"),void 0);if(r.length===0)return null;let i=r[0].object,s=null;if(i instanceof Fs.IRI)s=i;else if(i instanceof ii.Literal){let a=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(a)}return s?this.loadGroundingDefinition(s,t):null}async loadGroundingDefinition(e,t){if(t>=t_)return null;let r=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,we.Namespace.EXO.term("Asset_label"))??"",s=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_type"));if(!s)return null;let a=this.resolveGroundingType(s);if(!a)return null;let c=await this.getObsidianName(e,we.Namespace.EXOCMD.term("Grounding_targetProperty"));if(a===e_.GroundingType.SERVICE_CALL){let w=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_serviceId"));w&&(c=w)}let l=await this.getObsidianWikilinkValue(e,we.Namespace.EXOCMD.term("Grounding_targetValue")),u=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),f=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetClass")),d=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetPrototype")),h=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_targetFolder")),p=await this.getLiteralValue(e,we.Namespace.EXOCMD.term("Grounding_inputSchema")),_;a===e_.GroundingType.COMPOSITE&&(_=await this.loadCompositeSteps(e,t+1));let S;if(p)try{let w=JSON.parse(p);w?.properties&&(S=Object.entries(w.properties).map(([A,R])=>({name:A,type:R.type==="string"?"text":R.type,label:R.title??A,required:Array.isArray(w.required)&&w.required.includes(A)})))}catch{}let E={id:r,label:i,type:a,targetProperty:c??void 0,targetValue:l??void 0,sparqlUpdate:u??void 0,steps:_,targetClass:f??void 0,targetPrototype:d??void 0,targetFolder:h??void 0};return S&&(E.inputSchema=S),E}async loadCompositeSteps(e,t){if(t>=t_)return[];let r=await this.tripleStore.match(e,we.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let a=null;if(s.object instanceof Fs.IRI)a=s.object;else if(s.object instanceof ii.Literal){let l=this.normalizeWikilink(s.object.value);a=await this.findSubjectByUID(l)}if(!a)continue;let c=await this.loadGroundingDefinition(a,t);c&&i.push(c)}return i}resolveGroundingType(e){let t=e.toLowerCase().trim();return Object.values(e_.GroundingType).includes(t)?t:null}async findSubjectByUID(e){if(this.tripleStore.findSubjectsByUUID){let r=await this.tripleStore.findSubjectsByUUID(e);if(r.length>0)return r[0]}let t=await this.tripleStore.match(void 0,we.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof ii.Literal&&r.object.value===e)return r.subject;return null}async getLiteralValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal||i instanceof Fs.IRI?i.value:null}async getLinkedUID(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;if(i instanceof Fs.IRI){let s=await this.tripleStore.match(i,we.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof ii.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof ii.Literal?this.normalizeWikilink(i.value):null}async getLinkedValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal?this.normalizeWikilink(i.value):i instanceof Fs.IRI?this.iriToObsidianName(i.value)??i.value:null}async getObsidianName(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;return i instanceof ii.Literal?i.value:i instanceof Fs.IRI?this.iriToObsidianName(i.value)??i.value:null}async getObsidianWikilinkValue(e,t){let r=await this.tripleStore.match(e,t,void 0);if(r.length===0)return null;let i=r[0].object;if(i instanceof ii.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof Fs.IRI){let s=this.iriToObsidianName(i.value);return s?`"[[${s}]]"`:i.value}return null}async resolveWikilinkAlias(e){let t=e.match(/\[\[([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\]\]/);if(!t)return e;let r=t[1],i=await this.findSubjectByUID(r);if(!i)return e;let s=await this.getLiteralValue(i,we.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){let t=e.lastIndexOf("#");if(t>=0){let i=e.substring(0,t+1),s=e.substring(t+1);if(i===we.Namespace.EMS.iri.value)return`ems__${s}`;if(i===we.Namespace.EXO.iri.value)return`exo__${s}`;if(i===we.Namespace.EXOCMD.iri.value)return`exocmd__${s}`;if(i===we.Namespace.IMS.iri.value)return`ims__${s}`;if(i===we.Namespace.ZTLK.iri.value)return`ztlk__${s}`;if(i===we.Namespace.PTMS.iri.value)return`ptms__${s}`;if(i===we.Namespace.LIT.iri.value)return`lit__${s}`;if(i===we.Namespace.INBOX.iri.value)return`inbox__${s}`}let r=e.match(/\/([^/]+)\.md$/);return r?r[1]:null}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};Ds.CommandResolver=r_;Ds.CommandResolver=r_=UM([(0,qM.injectable)(),BM("design:paramtypes",[Object])],r_)});var p3=v(Ns=>{"use strict";var HM=Ns&&Ns.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},QM=Ns&&Ns.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},Fu;Object.defineProperty(Ns,"__esModule",{value:!0});Ns.PreconditionEvaluator=void 0;var YM=ce(),XM=Tu(),KM=Au(),h3=Ou(),Du=Fu=class{static{o(this,"PreconditionEvaluator")}constructor(e){this.hostFunctions=new Map,this.askCache=new Map,this.tripleStore=e}async evaluate(e,t,r){return e?e.sparqlAsk?this.evaluateSparqlAsk(e.sparqlAsk,t):e.hostFunction?this.evaluateHostFunction(e.hostFunction,t,r):!0:!0}registerHostFunction(e,t){this.hostFunctions.set(e,t)}hasHostFunction(e){return this.hostFunctions.has(e)}invalidateCache(){this.askCache.clear()}compileAsk(e){let t=this.substituteVariables(e,Fu.SENTINEL_IRI),i=new XM.ExoQLParser().parse(t),a=new KM.ExoQLAlgebraTranslator().translate(i);return new h3.ExoQLQueryExecutor(this.tripleStore).isAskQuery(a)?a:null}evaluateHostFunction(e,t,r){let i=this.hostFunctions.get(e);if(!i)return!0;let s=r?{...r,targetIRI:t}:{targetIRI:t};return i(s)}async evaluateSparqlAsk(e,t){try{let r=this.askCache.get(e);if(r===void 0){let a=this.compileAsk(e);if(!a)return!1;r=a,this.askCache.set(e,r)}let i=JSON.parse(JSON.stringify(r).replaceAll(Fu.SENTINEL_IRI,t));return await new h3.ExoQLQueryExecutor(this.tripleStore).executeAsk(i)}catch{return!1}}substituteVariables(e,t){let r=new Date().toISOString(),i=r.slice(0,10),s=new Date,a=new Date(s.getTime()+Fu.ALMATY_OFFSET_MS),c=a.getUTCFullYear(),l=a.getUTCMonth(),u=a.getUTCDate(),f=a.getUTCDay(),h=new Date(Date.UTC(c,l,u-1)).toISOString().slice(0,10),p=(f+6)%7,_=new Date(Date.UTC(c,l,u-p)),S=_.toISOString().slice(0,10),w=new Date(_.getTime()-10080*60*1e3).toISOString().slice(0,10),A=`${c}-${String(l+1).padStart(2,"0")}-01`,R=l===0?11:l-1,W=`${l===0?c-1:c}-${String(R+1).padStart(2,"0")}-01`,be=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${r}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${S}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${w}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${A}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${W}"^^xsd:date`).replace(/\$thisYearStart/g,`"${be}"^^xsd:date`).replace(/\$today/g,`"${i}"^^xsd:date`)}};Ns.PreconditionEvaluator=Du;Du.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Du.ALMATY_OFFSET_MS=300*60*1e3;Ns.PreconditionEvaluator=Du=Fu=HM([(0,YM.injectable)(),QM("design:paramtypes",[Object])],Du)});var Un=v(fp=>{"use strict";Object.defineProperty(fp,"__esModule",{value:!0});fp.FrontmatterService=void 0;var Nu=class n{static{o(this,"FrontmatterService")}parse(e){let t=e.match(n.FRONTMATTER_REGEX);return t?{exists:!0,content:t[1],originalContent:e}:{exists:!1,content:"",originalContent:e}}updateProperty(e,t,r){t=n.normalizeIRI(t),typeof r=="string"&&(r=n.normalizeIRIValue(r));let i=this.parse(e),s=this.serializeValue(t,r);if(!i.exists)return`---
71
71
  ${s}
72
72
  ---
73
73
  ${e}`;let a=i.content;if(this.hasProperty(a,t)){let c=new RegExp(`${this.escapeRegex(t)}:.*(?:
@@ -750,7 +750,7 @@ ${Fr.dump(i,{lineWidth:-1})}---
750
750
  `);for(let c of i){console.log(` \u{1F4C4} ${c.label} (${c.uid}):`);for(let l of c.issues)console.log(` \u2022 ${l}`);console.log()}process.exitCode=5}}}catch(r){N.handle(r)}}),n}o(fF,"dynamicCommandCommand");function O2(n){let e=[],t=[];N2(n,t);let r=dF(t);for(let{filePath:i,fm:s}of t){if(!ql(s,"exocmd__Command",r))continue;let a=s.exo__Asset_uid??"",c=s.exo__Asset_label??hF(i),l=s.exocmd__Command_category,u=s.exocmd__Command_icon,f=!!s.exocmd__Command_precondition,d=s.exocmd__Command_grounding,h;if(d){let p=Dg(String(d)),_=t.find(S=>S.fm.exo__Asset_uid===p&&ql(S.fm,"exocmd__Grounding",r));_&&(h=_.fm.exocmd__Grounding_type)}e.push({filePath:i,uid:a,label:c,category:l,icon:u,hasPrecondition:f,groundingType:h})}return e}o(O2,"scanCommands");async function zH(n,e){let{tripleStore:t}=await F2(n),r=new Le.CommandResolver(t),i=await r.findBindings(),s=new Set;for(let c of i)s.add(c.commandRef);let a=[];for(let c of s){let l=await r.loadCommand(c);l&&a.push({filePath:"",uid:l.id,label:l.name,category:l.category,icon:l.icon,hasPrecondition:!!l.precondition,groundingType:l.grounding.type})}return a}o(zH,"listCommandsForTarget");function HH(n){let e=[],t=[];N2(n,t);let r=dF(t),i=new Map;for(let s of t){let a=s.fm.exo__Asset_uid;a&&i.set(a,s)}for(let{filePath:s,fm:a}of t){if(!ql(a,"exocmd__Command",r))continue;let c=a.exo__Asset_uid??"",l=a.exo__Asset_label??hF(s),u=[];c||u.push("Missing exo__Asset_uid"),a.exo__Asset_label||u.push("Missing exo__Asset_label");let f=a.exocmd__Command_grounding;if(!f)u.push("Missing exocmd__Command_grounding (required)");else{let p=Dg(String(f)),_=i.get(p);if(!_)u.push(`Grounding reference "${p}" not found in vault`);else if(!ql(_.fm,"exocmd__Grounding",r))u.push(`Grounding reference "${p}" is not an exocmd__Grounding asset`);else{let S=_.fm,E=S.exocmd__Grounding_type;E?(Object.values(Le.GroundingType).includes(E)||u.push(`Grounding "${p}" has invalid type "${E}"`),(E===Le.GroundingType.PROPERTY_SET||E===Le.GroundingType.PROPERTY_DELETE)&&!S.exocmd__Grounding_targetProperty&&u.push(`Grounding "${p}" (${E}) missing targetProperty`),E===Le.GroundingType.PROPERTY_SET&&!S.exocmd__Grounding_targetValue&&u.push(`Grounding "${p}" (property_set) missing targetValue`),E===Le.GroundingType.SERVICE_CALL&&((S.exocmd__Grounding_serviceId??S.exocmd__Grounding_targetProperty)||u.push(`Grounding "${p}" (service_call) missing serviceId and targetProperty`))):u.push(`Grounding "${p}" missing exocmd__Grounding_type`)}}let d=a.exocmd__Command_precondition;if(d){let p=Dg(String(d)),_=i.get(p);if(!_)u.push(`Precondition reference "${p}" not found in vault`);else if(!ql(_.fm,"exocmd__Precondition",r))u.push(`Precondition reference "${p}" is not an exocmd__Precondition asset`);else{let S=_.fm.exocmd__Precondition_sparqlAsk,E=_.fm.exocmd__Precondition_hostFunction;!S&&!E&&u.push(`Precondition "${p}" missing both sparqlAsk and hostFunction`)}}t.some(p=>ql(p.fm,"exocmd__CommandBinding",r)?Dg(String(p.fm.exocmd__CommandBinding_command??""))===c:!1)||u.push("No CommandBinding references this command (command will be unused)"),u.length>0&&e.push({uid:c,label:l,filePath:s,issues:u})}return e}o(HH,"validateCommands");async function F2(n){let e=new qt(n),r=await new Le.NoteToRDFConverter(e).convertVault(),i=new Le.InMemoryTripleStore;return await i.addAll(r),{tripleStore:i}}o(F2,"buildTripleStore");function D2(n,e){if(console.log(`${e}ID: ${n.id}`),console.log(`${e}Label: ${n.label}`),console.log(`${e}Type: ${n.type}`),n.targetProperty&&console.log(`${e}Target property: ${n.targetProperty}`),n.targetValue!==void 0&&console.log(`${e}Target value: ${n.targetValue}`),n.sparqlUpdate&&console.log(`${e}SPARQL UPDATE: ${n.sparqlUpdate}`),n.steps&&n.steps.length>0){console.log(`${e}Steps (${n.steps.length}):`);for(let t=0;t<n.steps.length;t++)console.log(`${e} Step ${t+1}:`),D2(n.steps[t],e+" ")}}o(D2,"printGrounding");function N2(n,e){let t;try{t=(0,ps.readdirSync)(n,{withFileTypes:!0})}catch{return}for(let r of t){let i=(0,ms.join)(n,r.name);if(r.isDirectory()){if(r.name.startsWith(".")||r.name==="node_modules")continue;N2(i,e)}else if(r.name.endsWith(".md"))try{let s=(0,ps.readFileSync)(i,"utf-8"),a=GH.parse(s);a.exists&&e.push({filePath:i,fm:QH(a.content)})}catch{}}}o(N2,"collectParsedFiles");function QH(n){let e={},t=n.split(`
751
751
  `),r="",i=null;for(let s of t){if(s.match(/^\s+-\s+/)&&r){let c=s.replace(/^\s+-\s+/,"").trim();i||(i=[]),i.push(c),e[r]=i;continue}let a=s.match(/^([a-zA-Z0-9_]+):\s*(.*)/);if(a){r=a[1],i=null;let c=a[2].trim();if((c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),c==="true"?c=!0:c==="false"&&(c=!1),c===""){e[r]=[],i=e[r];continue}e[r]=c}}return e}o(QH,"parseYamlFrontmatter");var YH=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function dF(n){let e=new Map;for(let{fm:t}of n){let r=t.exo__Asset_uid,i=t.exo__Asset_label;typeof r=="string"&&typeof i=="string"&&e.set(r,i)}return e}o(dF,"buildClassLabelIndex");function ql(n,e,t){let r=n.exo__Instance_class;if(!r)return!1;let i=Array.isArray(r)?r:[r];for(let s of i){if(typeof s!="string")continue;let a=s.match(/\[\[([^|\]]+)/),c=a?a[1]:s;if(c===e||t&&YH.test(c)&&t.get(c)===e)return!0}return!1}o(ql,"hasClass");function Dg(n){if(typeof n!="string")return"";let e=n.replace(/["'[\]]/g,"").trim(),t=e.indexOf("|");return t>=0?e.substring(0,t).trim():e}o(Dg,"normalizeWikilink");function hF(n){return(0,ms.basename)(n,".md")}o(hF,"extractLabelFromFilename");var Wl=require("fs"),Yf=require("path"),Ot=X(Bt());var XH={turtle:"turtle",ntriples:"n-triples",jsonld:"json-ld"},KH=new Ot.IRI(`${Ot.Namespace.RDF.iri.value}type`),pF=[Ot.Namespace.RDF,Ot.Namespace.RDFS,Ot.Namespace.OWL,Ot.Namespace.XSD,Ot.Namespace.EXO,Ot.Namespace.EMS,Ot.Namespace.EXOCMD,Ot.Namespace.IMS,Ot.Namespace.ZTLK,Ot.Namespace.PTMS,Ot.Namespace.LIT,Ot.Namespace.INBOX];function JH(n){let e=n.trim();if(e.startsWith("http://")||e.startsWith("https://"))return new Ot.IRI(e);let t=e.match(/^([a-zA-Z][a-zA-Z0-9]*)__(.+)$/);if(t){let[,i,s]=t,a=pF.find(c=>c.prefix===i);if(a)return a.term(s)}let r=e.match(/^([a-zA-Z][a-zA-Z0-9]*):(.+)$/);if(r){let[,i,s]=r,a=pF.find(c=>c.prefix===i);if(a)return a.term(s)}throw new He(`Unable to resolve class filter "${n}" to an IRI.`,'Use shorthand like "ems__Task", prefixed like "ems:Task", or a full IRI.')}o(JH,"resolveClassIri");function ZH(n,e){let t=new Set;for(let r of n)r.predicate.equals(KH)&&r.object instanceof Ot.IRI&&r.object.equals(e)&&t.add(r.subject.toString());return t.size===0?[]:n.filter(r=>t.has(r.subject.toString()))}o(ZH,"filterByClass");function mF(){return new Fe("convert").description("Dump vault graph as RDF (Turtle/N-Triples/JSON-LD)").option("--format <type>","Serialization format: turtle|ntriples|jsonld","turtle").option("--out <path>","Write serialized output to file (default: stdout)").option("--filter <class>","Keep only instances of the given class (e.g. ems__Task, ems:Task, or full IRI)").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--output <type>","Response format for errors: text|json (for MCP tools)","text").action(async n=>{let e=n.output||"text";N.setFormat(e);try{let t=XH[n.format];if(!t)throw new He(`Unknown format: "${n.format}". Expected one of turtle|ntriples|jsonld.`,"exocortex convert --format turtle --out vault.ttl");let r=(0,Yf.resolve)(n.vault);if(!(0,Wl.existsSync)(r))throw new xe(r);e==="text"&&!n.out||e==="text"&&console.error(`\u{1F4E6} Loading vault: ${r}...`);let i=new qt(r),a=await new Ot.NoteToRDFConverter(i).convertVault();if(n.filter){let f=JH(n.filter);a=ZH(a,f)}let c=new Ot.InMemoryTripleStore;await c.addAll(a);let u=new Ot.RDFSerializer(c).serializeTriples(a,t,{pretty:t==="json-ld",indent:2});if(n.out){let f=(0,Yf.resolve)(n.out);try{(0,Wl.mkdirSync)((0,Yf.dirname)(f),{recursive:!0}),(0,Wl.writeFileSync)(f,u,"utf-8")}catch(d){throw new ff("convert",`failed to write output to ${f}: ${d.message}`,"Check destination directory exists and is writable.",{outPath:f})}e==="text"&&console.error(`\u2705 Wrote ${a.length} triple(s) to ${f} (${n.format}).`)}else process.stdout.write(u),u.endsWith(`
752
752
  `)||process.stdout.write(`
753
- `)}catch(t){N.handle(t)}})}o(mF,"convertCommand");function gF(n){n.addCommand(cP()),n.addCommand(dP()),n.addCommand(hP())}o(gF,"addQuerySubcommands");function yF(n){let e=new Fe;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.114.8");let t=e.command("exoql").description("ExoQL query execution and cache management");gF(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return gF(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(bO()),e.addCommand(TO()),e.addCommand(AO()),e.addCommand(CO()),e.addCommand(IO()),e.addCommand(DO()),e.addCommand(MO()),e.addCommand(GO()),e.addCommand(QO()),e.addCommand(ZO()),e.addCommand(rF()),e.addCommand(nF()),e.addCommand(sF()),e.addCommand(fF()),e.addCommand(mF()),e}o(yF,"createProgram");yF().parse();0&&(module.exports={createProgram});
753
+ `)}catch(t){N.handle(t)}})}o(mF,"convertCommand");function gF(n){n.addCommand(cP()),n.addCommand(dP()),n.addCommand(hP())}o(gF,"addQuerySubcommands");function yF(n){let e=new Fe;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.114.10");let t=e.command("exoql").description("ExoQL query execution and cache management");gF(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return gF(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(bO()),e.addCommand(TO()),e.addCommand(AO()),e.addCommand(CO()),e.addCommand(IO()),e.addCommand(DO()),e.addCommand(MO()),e.addCommand(GO()),e.addCommand(QO()),e.addCommand(ZO()),e.addCommand(rF()),e.addCommand(nF()),e.addCommand(sF()),e.addCommand(fF()),e.addCommand(mF()),e}o(yF,"createProgram");yF().parse();0&&(module.exports={createProgram});
754
754
  /*! Bundled license information:
755
755
 
756
756
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "15.114.8",
3
+ "version": "15.114.10",
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": {