@kitelev/exocortex-cli 16.130.6 → 16.130.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v16.130.
|
|
2
|
+
// @kitelev/exocortex-cli v16.130.8
|
|
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 Al(`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 Al(`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 o=e.variables[0],c=e.bindings.map(l=>{let u=l[o];return u?this.generateValuesTerm(u):"UNDEF"}).join(" ");return`${r}VALUES ?${o} { ${c} }`}let i=e.variables.map(o=>`?${o}`).join(" "),s=e.bindings.map(o=>`(${e.variables.map(l=>{let u=o[l];return u?this.generateValuesTerm(u):"UNDEF"}).join(" ")})`);return`${r}VALUES (${i}) {
|
|
68
68
|
${s.map(o=>`${r} ${o}`).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 Al(`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}}};Il.SPARQLGenerator=jS});var Cl=w(Dn=>{"use strict";var H7=Dn&&Dn.__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:a(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),K7=Dn&&Dn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),a3=Dn&&Dn.__importStar||(function(){var n=a(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"&&H7(t,e,r[i]);return K7(t,e),t}})();Object.defineProperty(Dn,"__esModule",{value:!0});Dn.QueryExecutor=Dn.ExoQLQueryExecutor=Dn.QueryExecutorError=void 0;var Q7=iS(),X7=ym(),Y7=ES(),J7=xS(),Z7=XR(),e8=JR(),t8=t3(),r8=NS(),n8=n3(),i8=s3(),s8=o3(),o8=Ae(),a8=Ve(),c8=um(),Br="http://www.w3.org/2001/XMLSchema#",l8=new Set([`${Br}integer`,`${Br}decimal`,`${Br}float`,`${Br}double`,`${Br}nonPositiveInteger`,`${Br}negativeInteger`,`${Br}long`,`${Br}int`,`${Br}short`,`${Br}byte`,`${Br}nonNegativeInteger`,`${Br}unsignedLong`,`${Br}unsignedInt`,`${Br}unsignedShort`,`${Br}unsignedByte`,`${Br}positiveInteger`]),Rl=class extends Error{static{a(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Dn.QueryExecutorError=Rl;var Am=class{static{a(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new Q7.BGPExecutor(e),this.filterExecutor=new X7.FilterExecutor,this.optionalExecutor=new Y7.OptionalExecutor,this.unionExecutor=new J7.UnionExecutor,this.minusExecutor=new Z7.MinusExecutor,this.valuesExecutor=new e8.ValuesExecutor,this.aggregateExecutor=new t8.AggregateExecutor,this.constructExecutor=new r8.ConstructExecutor,this.serviceExecutor=new n8.ServiceExecutor(t.serviceConfig),this.graphExecutor=new i8.GraphExecutor(e),this.sparqlGenerator=new s8.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 Rl(`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 o of this.execute(e.left))t.push(o);if(t.length===0)return;let r=new Set;for(let o of t)for(let c of o.variables())r.add(c);let i=this.collectOperationVariables(e.right);if([...r].some(o=>i.has(o)))for(let o of t){let c=this.substituteVariables(e.right,o);for await(let l of this.execute(c)){let u=o.merge(l);u!==null&&(yield u)}}else{let o=[];for await(let c of this.execute(e.right))o.push(c);for(let c of t)for(let l of o){let u=c.merge(l);u!==null&&(yield u)}}}async*executeLeftJoin(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(s,"rightGen"),yield*this.optionalExecutor.execute(i(),s())}async*executeUnion(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(s,"rightGen"),yield*this.unionExecutor.execute(i(),s())}async*executeMinus(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(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(()=>a3(hs())),r=new Set(e.variables);for await(let i of this.execute(e.input)){let s=new t;for(let o of i.variables())if(r.has(o)){let c=i.get(o);c!==void 0&&s.set(o,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 o=this.getExpressionValue(s.expression,r),c=this.getExpressionValue(s.expression,i),l=0;if(o===void 0&&c===void 0?l=0:o===void 0?l=1:c===void 0?l=-1:typeof o=="number"&&typeof c=="number"?l=o-c:l=String(o).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(o=>this.filterExecutor.evaluateExpression(o,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 o=r.merge(s);o!==null&&(yield o)}}}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 o8.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(()=>a3(hs()));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);if(!r)return;if(r instanceof a8.Literal){let i=r.datatype?.value;if(i===`${Br}dayTimeDuration`)try{return c8.DateTimeFunctions.parseDayTimeDuration(r.value)}catch{return r.value}if(i&&l8.has(i)){let s=parseFloat(r.value);if(!Number.isNaN(s))return s}return r.value}return r.value??r.id??String(r)}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 Rl("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 Rl("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Dn.ExoQLQueryExecutor=Am;Dn.QueryExecutor=Am});var m3=w(ro=>{"use strict";var u8=ro&&ro.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;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--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},f8=ro&&ro.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},$S;Object.defineProperty(ro,"__esModule",{value:!0});ro.CommandResolver=void 0;var d8=Ue(),h8=Kc(),Jt=Ae(),$t=Ve(),U=zt(),c3=Bo(),l3=sf(),p8=Xc(),m8=Ip(),Pl=Jb(),Im=rR(),g8=ol(),y8=cl(),b8=Cl(),Lf=10,Rm="exo__Asset",_8=Lf+1,u3="08cec529-90eb-4d43-88de-ceecccea12b0",w8=U.Namespace.EXOCMD.term("SubstitutionToken").value,f3=new Set(["today","todayStart","targetFolder","target","randomUUIDv4","nowTimestamp","nowDate","nowYear","nowMonth","userInputLabel","userInput","targetProperty","labelAsArray","groundingTargetClass","targetClassSelf"]);function S8(n,e){return`__SUBSTITUTE__${n}__${e}__`}a(S8,"buildSubstitutionMarker");function v8(n,e,t){let r=(0,p8.utf8ToBase64)(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`__SUBSTITUTE_P__${n}__${e}__${r}__`}a(v8,"buildParameterisedMarker");var d3="3f28af98-c031-4718-8ba2-44ad0b012c52",E8=U.Namespace.EXOCMD.term("TokenInvocation").value,h3="29e2c8f8-2d27-4e58-b467-2e85d46f8122",p3="universal-default-template",T8=new Set(["today","todayStart","nowTimestamp","nowDate","nowYear","nowMonth"]),US=$S=class{static{a(this,"CommandResolver")}clearUniversalCache(){this._universalCacheReady=!1,this._universalCacheValue=null,(0,Im.clearUniversalDefault)()}constructor(e,t=h8.NullLogger){this.tripleStore=e,this.logger=t,this.cache=new Map,this.multiCache=new Map,this._ancestorDepthCache=new Map,this._legacyPropertyDefaultsWarnedGroundings=new Set,this._universalCacheReady=!1,this._universalCacheValue=null}async resolveForAssetMulti(e,t,r){if(t.length===0)return[];let i=[...t].sort().join(","),s=`${e}::${i}::${r??""}`,o=this.multiCache.get(s);if(o)return o;let c=await this.expandClassHierarchy(t),l=new Map;for(let[h,p]of c){let y=await this.resolveForAsset(e,h,r);for(let g of y){let _=this.getBindingPriority(g.binding)===2?p:0,S=l.get(g.binding.id);(!S||_<S.depth)&&l.set(g.binding.id,{rc:g,depth:_})}}let u=new Set;for(let{rc:h}of l.values())if(h.binding.overrides)for(let p of h.binding.overrides)u.add(p);let f=Array.from(l.entries()).filter(([h])=>!u.has(h)).map(([,h])=>h);f.sort((h,p)=>{let y=this.getBindingPriority(h.rc.binding),g=this.getBindingPriority(p.rc.binding);return y!==g?y-g:h.depth!==p.depth?h.depth-p.depth:(h.rc.binding.order??100)-(p.rc.binding.order??100)});let d=f.map(h=>h.rc);return this.multiCache.set(s,d),d}async expandClassHierarchy(e){let t=new Map;for(let c of e){if(c===Rm){t.set(c,new Set);continue}let l=[];try{l=await this.getClassAncestors(c)}catch{l=[]}t.set(c,new Set(l))}let r=a(c=>{for(let l of e)if(l!==c&&t.get(l)?.has(c)&&!t.get(c)?.has(l))return!0;return!1},"isAncestorOfSibling"),i=e.filter(c=>!r(c)),s=new Map,o=a((c,l)=>{let u=s.get(c);(u===void 0||l<u)&&s.set(c,l)},"setMin");for(let c of i){if(o(c,0),this.looksLikeUUID(c))try{let u=await this.resolveLabelByUID(c);u&&o(u,0)}catch{}if(c===Rm)continue;let l=[];try{l=await this.getClassAncestorsWithDepth(c)}catch{l=[]}for(let{ref:u,depth:f}of l)o(u,f)}return s.has(Rm)||s.set(Rm,_8),s}async resolveForAsset(e,t,r){let i=`${e}:${t}:${r??""}`,s=this.cache.get(i);if(s)return s;let o=await this.findBindings(t,r,e),c=[];for(let l of o){let u=await this.loadCommand(l.commandRef,{targetClass:l.targetClass});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,t){let r=await this.findSubjectByUID(e);if(!r||(await this.tripleStore.match(r,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("Command"))).length===0)return null;let s=await this.getLiteralValue(r,U.Namespace.EXO.term("Asset_label"))??"Unknown Command",o=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_labelTemplate")),c=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_icon")),l=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_confirmMessage")),u=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_successMessage")),f=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_category")),d=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_openInSameTab")),h=d!==null&&String(d).trim().toLowerCase()==="true",p=await this.loadLinkedPrecondition(r),y=await this.loadLinkedGrounding(r,0,t);return y?{id:e,name:s,labelTemplate:o??void 0,icon:c??void 0,precondition:p??void 0,grounding:y,confirmMessage:l??void 0,successMessage:u??void 0,category:f??void 0,openInSameTab:h||void 0}:null}async findBindings(e,t,r){let i=await this.tripleStore.match(void 0,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("CommandBinding")),s=[];for(let o of i){let c=o.subject,l=await this.loadBindingDefinition(c);l&&this.bindingMatches(l,e,t,r)&&s.push(l)}return s}async findPaletteEnabledCommands(){let e=await this.tripleStore.match(void 0,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("Command")),t=[],r=new Set;for(let i of e){let s=i.subject;if((await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_paletteEnabled")))?.toLowerCase()!=="true")continue;let c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid"));if(!c){this.logger.warn(`[CommandResolver] paletteEnabled command at ${s.value} has no exo__Asset_uid \u2014 skipped`);continue}let l=await this.loadCommand(c);if(!l){this.logger.warn(`[CommandResolver] paletteEnabled command ${c} could not be loaded (missing grounding?) \u2014 skipped`);continue}let u=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_paletteId")),f=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_cliName")),d=u??f??c;if(r.has(d)){this.logger.warn(`[CommandResolver] duplicate paletteId "${d}" \u2014 first registration wins, dropping ${c}`);continue}r.add(d),t.push({command:l,paletteId:d})}return t}invalidateCache(){this.cache.clear(),this.multiCache.clear(),this._ancestorDepthCache.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:o}of i){let c=await this.evaluateSelectSnippet(o,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 o=e.slice(r,s),c=e.slice(r+1,s-1);t.push({full:o,body:c})}r=s}else r++;return t}async evaluateSelectSnippet(e,t){try{let r=e.replace(/\$target/g,`<${t}>`),s=new g8.ExoQLParser().parse(r),c=new y8.ExoQLAlgebraTranslator().translate(s),u=await new b8.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 $t.Literal||h instanceof Jt.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,U.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetClass")),o=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!o&&!c)return null;let l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_variant")),d=f!==null?this.coerceVariant(f,t):void 0,h=await this.loadLinkedPreconditionFromProperty(e,U.Namespace.EXOCMD.term("CommandBinding_precondition")),p=await this.loadLinkedStyle(e,t),y=await this.getLinkedUIDs(e,U.Namespace.EXOCMD.term("CommandBinding_overrides"));return{id:t,label:r,commandRef:i,targetClass:s??void 0,targetPrototype:o??void 0,targetAsset:c??void 0,position:l??void 0,order:u?parseInt(u,10):void 0,variant:d,precondition:h??void 0,style:p??void 0,overrides:y.length>0?y:void 0}}async loadLinkedStyle(e,t){let r=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("CommandBinding_style"),void 0);if(r.length>0){let s=r[0].object,o=null;if(s instanceof Jt.IRI)o=s;else if(s instanceof $t.Literal){let c=this.normalizeWikilink(s.value);o=await this.findSubjectByUID(c)}if(o){let c=await this.loadStyleAsset(o);if(c)return c}this.logger.warn(this.capWarning(`CommandBinding ${t}: style reference unresolved, falling back to inline variant`))}let i=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_variant"));if(i!==null){let s=this.coerceVariant(i,t);if(s!==void 0)return{id:`inline:${t}`,label:"",variant:s,inline:!0}}return null}async loadStyleAsset(e){let t=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",i=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_variant")),s=i!==null?this.coerceVariant(i,t):void 0,o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_showIcon")),c=this.coerceBoolean(o),l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_labelClass")),u=l!==null?this.coerceLabelClass(l,t):void 0,f=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_ariaLabel")),d=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_tooltip")),h=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_keyboardShortcut")),p=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_source")),y=p!==null?this.coerceStyleSource(p,t):void 0;return{id:t,label:r,variant:s,showIcon:c,labelClass:u,ariaLabel:f??void 0,tooltip:d??void 0,keyboardShortcut:h??void 0,source:y,inline:!1}}coerceVariant(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.COMMAND_VARIANT_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle variant "${r}" not in whitelist [${Pl.COMMAND_VARIANT_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceLabelClass(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.LABEL_CLASS_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle labelClass "${r}" not in whitelist [${Pl.LABEL_CLASS_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceStyleSource(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.STYLE_SOURCE_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle source "${r}" not in whitelist [${Pl.STYLE_SOURCE_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceBoolean(e){if(e===null)return;let t=e.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}capWarning(e){return e.length<=200?e:e.slice(0,197)+"..."}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 o=this.extractPathBasename(r);if(o&&o===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,U.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 Jt.IRI)s=i;else if(i instanceof $t.Literal){let h=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(h)}if(!s)return null;let o=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Precondition_hostFunction")),f=await this.tripleStore.match(s,U.Namespace.EXOCMD.term("Precondition_query"),void 0),d;if(f.length>0){let h=f[0].object;if(h instanceof Jt.IRI){let p=await this.getLiteralValue(h,U.Namespace.EXO.term("Asset_uid"));p&&(d=p)}else h instanceof $t.Literal&&(d=this.normalizeWikilink(h.value))}return!o||!l&&!u&&!d?null:{id:o,label:c,...l&&{sparqlAsk:l},...u&&{hostFunction:u},...d&&{query:d}}}async loadLinkedGrounding(e,t,r){if(t>=Lf)return null;let i=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Command_grounding"),void 0);if(i.length===0)return null;if(i.length===1||!r?.targetClass){let o=await this.resolveGroundingRef(i[0].object);return o?this.loadGroundingDefinition(o,t):null}for(let o of i){let c=await this.resolveGroundingRef(o.object);if(!c)continue;let l=await this.getObsidianName(c,U.Namespace.EXOCMD.term("Grounding_targetPrototype"));if(l&&this.matchesReference(l,r.targetClass))return this.loadGroundingDefinition(c,t)}this.logger.warn(`Command ${e.value}: ${i.length} groundings declared, none matched context.targetClass='${r.targetClass}' via Grounding_targetPrototype \u2014 falling back to first grounding by iteration order (legacy behaviour). Check that one grounding's Grounding_targetPrototype references this targetClass.`);let s=await this.resolveGroundingRef(i[0].object);return s?this.loadGroundingDefinition(s,t):null}async resolveGroundingRef(e){if(e instanceof Jt.IRI)return e;if(e instanceof $t.Literal){let t=this.normalizeWikilink(e.value);return await this.findSubjectByUID(t)}return null}async loadGroundingByUid(e){let t=await this.findSubjectByUID(e);return t?this.loadGroundingDefinition(t,0):null}async loadGroundingDefinition(e,t){if(t>=Lf)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",s=await this.resolveGroundingTypeReference(e);if(!s)return null;let o=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetProperty"));if(o&&this.looksLikeUUID(o)){let Q=await this.resolveLabelByUID(o);if(!Q)return this.logger.warn(`Grounding ${r}: targetProperty wikilink UID '${o}' is not resolvable to exo__Asset_label \u2014 grounding skipped (would otherwise write a UUID-named frontmatter key).`),null;o=Q}if(s===c3.GroundingType.SERVICE_CALL){let Q=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_serviceId"));Q&&(o=Q)}let c=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueRef")),l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_targetValueLiteral")),u=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueSubstitution")),f=null;if(u&&this.looksLikeUUID(u)){let Q=await this.resolveLabelByUID(u);if(!Q)return this.logger.warn(`Grounding ${r}: targetValueSubstitution UID '${u}' is not resolvable to exo__Asset_label (SubstitutionToken instance missing or unlabelled) \u2014 grounding skipped.`),null;f=Q}else u&&(f=u);let d=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueQuery")),h=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_serviceCallPayload")),p=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_appendExpression")),y=await this.getObsidianWikilinkValue(e,U.Namespace.EXOCMD.term("Grounding_isDefinedBy")),g=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),_=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetClass"));if(_&&!this.looksLikeUUID(_)){let Q=await this.findUidByLabel(_);Q&&(_=Q)}let S=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetPrototype")),E=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_targetFolder")),T=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_linkBackProperty")),A=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_inputSchema")),x=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_incrementBy")),R=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_shiftDelta")),G;if(x!=null&&x!==""){let Q=Number.parseInt(String(x),10);Number.isFinite(Q)&&(G=Q)}let N=await this.resolvePropertyDefaults(e,r),P=await this.resolveInheritanceRules(e,r),k=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_propertyDefaults"));k!==null&&k!==""&&!this._legacyPropertyDefaultsWarnedGroundings.has(r)&&(this.logger.warn(`Grounding ${r}: deprecated exocmd__Grounding_propertyDefaults (plural) JSON predicate detected \u2014 the parser was removed in RFC v2 Phase 5 (#3167); value is ignored. Migrate to ref-form exocmd__Grounding_propertyDefault (singular) pointing to exocmd__PropertyDefault assets. See vault TBox c8f87363-d39c-45cb-9d4d-1be96d70f892 for the canonical replacement.`),this._legacyPropertyDefaultsWarnedGroundings.add(r));let D;s===c3.GroundingType.COMPOSITE&&(D=await this.loadCompositeSteps(e,t+1));let ee;if(A)try{let Q=JSON.parse(A);Q?.properties&&(ee=Object.entries(Q.properties).map(([q,fe])=>{let qe=fe.type,he=qe==="string"?"text":qe,Be=fe.defaultValue!==void 0?fe.defaultValue:fe.default,Ge={name:q,type:he,label:fe.title??q,required:Array.isArray(Q.required)&&Q.required.includes(q)};return Be!=null&&(Ge.defaultValue=String(Be)),typeof fe.targetClassUid=="string"&&(Ge.targetClassUid=fe.targetClassUid),Ge}))}catch{}let ie=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_prefillLabelWithDate")),X=ie!==null&&String(ie).trim().toLowerCase()==="true",se=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_labelTemplate")),ge=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_direction")),ce;if(ge!=null){let Q=String(ge).trim().toLowerCase();Q==="forward"||Q==="rollback"?ce=Q:Q!==""&&this.logger.warn(`Grounding ${r}: exocmd__Grounding_direction value '${ge}' is not 'forward' or 'rollback' \u2014 treating as undefined (will default to 'forward' at dispatch).`)}let B=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_bodyTemplate")),V=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_templateRef")),W={id:r,label:i,type:s,targetProperty:o??void 0,targetValueRef:c??void 0,targetValueLiteral:l??void 0,targetValueSubstitution:f??void 0,targetValueQuery:d??void 0,serviceCallPayload:h??void 0,appendExpression:p??void 0,sparqlUpdate:g??void 0,steps:D,targetClass:_??void 0,targetPrototype:S??void 0,targetFolder:E??void 0,linkBackProperty:T??void 0,incrementBy:G,shiftDelta:R??void 0,propertyDefault:N.length>0?N:void 0,inheritanceRule:P.length>0?P:void 0,isDefinedBy:y??void 0,prefillLabelWithDate:X||void 0,labelTemplate:se??void 0,direction:ce,bodyTemplate:B??void 0,templateRef:V??void 0};return ee&&(W.inputSchema=ee),W}async loadCompositeSteps(e,t){if(t>=Lf)return[];let r=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let o=null;if(s.object instanceof Jt.IRI)o=s.object;else if(s.object instanceof $t.Literal){let l=this.normalizeWikilink(s.object.value);o=await this.findSubjectByUID(l)}if(!o)continue;let c=await this.loadGroundingDefinition(o,t);c&&i.push(c)}return i}async resolvePropertyDefaults(e,t){let r=await this.resolvePropertyDefaultsForSubject(e,t,U.Namespace.EXOCMD.term("Grounding_propertyDefault")),i=await this.getUniversalCache();return i&&i.propertyDefaults.length>0?(0,Im.mergePropertyDefaults)(i.propertyDefaults,r):r}async resolvePropertyDefaultsForSubject(e,t,r){let i=await this.tripleStore.match(e,r,void 0),s=[];for(let o of i){let c=await this.resolveRefTripleObject(o.object);if(!c)continue;let l=await this.getObsidianName(c,U.Namespace.EXOCMD.term("PropertyDefault_property"));if(!l){this.logger.warn(`Grounding ${t}: PropertyDefault asset missing exocmd__PropertyDefault_property \u2014 entry skipped.`);continue}let u=this.looksLikeUUID(l)?await this.resolveLabelByUID(l):l;if(!u){this.logger.warn(`Grounding ${t}: PropertyDefault property UID '${l}' is not resolvable to exo__Asset_label \u2014 entry skipped.`);continue}let f=await this.getObsidianName(c,U.Namespace.EXOCMD.term("PropertyDefault_value"));if(!f){this.logger.warn(`Grounding ${t}: PropertyDefault '${u}' missing exocmd__PropertyDefault_value \u2014 entry skipped.`);continue}let d=await this.resolvePropertyDefaultValue(f,t,u);d!==null&&s.push({propertyName:u,value:d})}return s}async getUniversalCache(){if(this._universalCacheReady)return this._universalCacheValue;this._universalCacheReady=!0;let e=await(0,Im.loadUniversalDefault)();if(e)return this._universalCacheValue=e,e;let t=await this.findUniversalSingleton();if(!t)return this._universalCacheValue=null,null;let r=await this.resolvePropertyDefaultsForSubject(t,p3,U.Namespace.EXOCMD.term("Template_propertyDefault")),i=await this.resolveInheritanceRulesForSubject(t,p3,U.Namespace.EXOCMD.term("Template_inheritanceRule"));return this._universalCacheValue={propertyDefaults:r,inheritanceRules:i},this._universalCacheValue}async findUniversalSingleton(){let e=U.Namespace.EXOCMD.term("UniversalDefaultTemplate").value,t=await this.tripleStore.match(void 0,U.Namespace.EXO.term("Instance_class"),void 0),r=[];for(let i of t){let s=!1;if(i.object instanceof Jt.IRI)s=i.object.value===e||i.object.value.includes(h3);else if(i.object instanceof $t.Literal){let o=this.unwrapWikilink(i.object.value);s=o==="exocmd__UniversalDefaultTemplate"||o===h3}s&&i.subject instanceof Jt.IRI&&r.push(i.subject)}return r.length===0?null:(r.length===1||(r.sort((i,s)=>i.value.localeCompare(s.value)),this.logger.warn(`Multiple UniversalDefaultTemplate singletons found (${r.length}); selecting deterministically by lexicographic UID order: ${r[0].value}`)),r[0])}async resolveInheritanceRules(e,t){let r=await this.resolveInheritanceRulesForSubject(e,t,U.Namespace.EXOCMD.term("Grounding_inheritanceRule")),i=await this.getUniversalCache();return i&&i.inheritanceRules.length>0?(0,Im.mergeInheritanceRules)(i.inheritanceRules,r):r}async resolveInheritanceRulesForSubject(e,t,r){let i=await this.tripleStore.match(e,r,void 0),s=[],o=t;for(let c of i){let l=await this.resolveRefTripleObject(c.object);if(!l)continue;let u=await this.resolveLabelRef(l,U.Namespace.EXOCMD.term("InheritanceRule_sourceProperty"));if(!u){this.logger.warn(`Grounding ${o}: InheritanceRule missing/unresolvable exocmd__InheritanceRule_sourceProperty \u2014 entry skipped.`);continue}let f=await this.resolveLabelRef(l,U.Namespace.EXOCMD.term("InheritanceRule_targetProperty"));if(!f){this.logger.warn(`Grounding ${o}: InheritanceRule missing/unresolvable exocmd__InheritanceRule_targetProperty \u2014 entry skipped.`);continue}let d=await this.tripleStore.match(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"),void 0),h,p;if(d.length>0){let A=await this.getObsidianName(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"));if(!A||!A.trim()){this.logger.warn(`Grounding ${o}: InheritanceRule has exocmd__InheritanceRule_targetClassCondition triple but ref is unresolvable \u2014 entire rule skipped (would otherwise apply unconditionally, broadening scope).`);continue}this.looksLikeUUID(A)?(p=A,h=await this.resolveLabelByUID(A)??void 0):h=A}let y=await this.tripleStore.match(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassExclusion"),void 0),g=[],_=[],S=!1;for(let A of y){let x=null;if(A.object instanceof Jt.IRI?x=this.iriToObsidianName(A.object.value)??A.object.value:A.object instanceof $t.Literal&&(x=this.unwrapWikilink(A.object.value)),!x){S=!0;continue}if(this.looksLikeUUID(x)){_.push(x);let R=await this.resolveLabelByUID(x);R&&g.push(R)}else g.push(x)}if(S){this.logger.warn(`Grounding ${o}: InheritanceRule has unresolvable exocmd__InheritanceRule_targetClassExclusion entry \u2014 entire rule skipped (would otherwise expand scope by silently dropping the excluded class).`);continue}let E=await this.getLiteralValue(l,U.Namespace.EXOCMD.term("InheritanceRule_priority")),T=50;if(E!==null&&E!==""){let A=Number.parseInt(String(E),10);Number.isFinite(A)&&(T=A)}s.push({sourcePropertyName:u,targetPropertyName:f,targetClassCondition:h,targetClassConditionUid:p,targetClassExclusion:g,targetClassExclusionUids:_,priority:T})}return s}async resolveRefTripleObject(e){if(e instanceof Jt.IRI)return e;if(e instanceof $t.Literal){let t=this.normalizeWikilink(e.value);return t?this.findSubjectByUID(t):null}return null}async resolveLabelRef(e,t){let r=await this.getObsidianName(e,t);return r?this.looksLikeUUID(r)?this.resolveLabelByUID(r):r:null}async resolvePropertyDefaultValue(e,t,r){if(!this.looksLikeUUID(e))return`"[[${e}]]"`;let i=await this.findSubjectByUID(e);return i?await this.assetIsTokenInvocation(i)?this.resolveTokenInvocation(i,e,t,r):await this.assetIsSubstitutionToken(i)?this.dispatchSubstitutionToken(i,e,t,r,void 0):`"[[${e}]]"`:`"[[${e}]]"`}async dispatchSubstitutionToken(e,t,r,i,s){let o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("SubstitutionToken_resolver"));if(!o||!o.trim())return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' references SubstitutionToken '${t}' with no exocmd__SubstitutionToken_resolver \u2014 falling back to wikilink form.`),`"[[${t}]]"`;let c=o.trim();return f3.has(c)?s!==void 0?v8(c,t,s):T8.has(c)?$S.parseTimeResolve(c):S8(c,t):(this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' SubstitutionToken '${t}' declares unknown resolver-id '${c}' \u2014 falling back to wikilink form. Known ids: ${Array.from(f3).join(", ")}.`),`"[[${t}]]"`)}static parseTimeResolve(e){let t=new Date,r=a(i=>i<10?`0${i}`:String(i),"pad");switch(e){case"today":return t.toISOString().slice(0,10);case"todayStart":return new Date(new Date().setHours(0,0,0,0)).toISOString();case"nowTimestamp":return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}T${r(t.getHours())}:${r(t.getMinutes())}:${r(t.getSeconds())}`;case"nowDate":return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}`;case"nowYear":return String(t.getFullYear());case"nowMonth":return r(t.getMonth()+1);default:return""}}async resolveTokenInvocation(e,t,r,i){let s=await this.getObsidianName(e,U.Namespace.EXOCMD.term("TokenInvocation_token"));if(!s)return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' missing exocmd__TokenInvocation_token \u2014 entry skipped.`),null;let o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("TokenInvocation_parameter"))??"";if(!this.looksLikeUUID(s))return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' references non-UUID token '${s}' \u2014 entry skipped.`),null;let c=await this.findSubjectByUID(s);return c?this.dispatchSubstitutionToken(c,s,r,i,o):(this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' token ref '${s}' not found in store \u2014 entry skipped.`),null)}async assetIsTokenInvocation(e){let t=await this.tripleStore.match(e,U.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof Jt.IRI){if(r.object.value===E8||r.object.value.includes(d3))return!0}else if(r.object instanceof $t.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__TokenInvocation"||i===d3)return!0}return!1}async assetIsSubstitutionToken(e){let t=await this.tripleStore.match(e,U.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof Jt.IRI){if(r.object.value===w8||r.object.value.includes(u3))return!0}else if(r.object instanceof $t.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__SubstitutionToken"||i===u3)return!0}return!1}async resolveGroundingTypeReference(e){let t=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Grounding_type"),void 0);if(t.length===0)return null;let r=t[0].object;if(r instanceof Jt.IRI)return(0,l3.resolveGroundingTypeFromIRI)(r.value);if(r instanceof $t.Literal){let i=r.value,s=i.match(/^\[\[([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\|[^\]]*)?\]\]$/i);return s?(0,l3.resolveGroundingTypeFromIRI)(`obsidian://vault/${s[1].toLowerCase()}.md`):(this.logger.warn(`[exocmd-grounding-type-literal-form] legacy literal-string form '${i}' for exocmd__Grounding_type on <${e.value}>. Migrate to wikilink form per RFC 9d20c91f Phase 3.`),null)}return 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,U.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof $t.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 $t.Literal||i instanceof Jt.IRI?i.value:null}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)}async resolveLabelByUID(e){let t=await this.findSubjectByUID(e);return t?this.getLiteralValue(t,U.Namespace.EXO.term("Asset_label")):null}async getClassAncestors(e){return(await this.getClassAncestorsWithDepth(e)).map(r=>r.ref)}async getClassAncestorsWithDepth(e){let t=this._ancestorDepthCache.get(e);if(t)return t;let r=new Map,i=new Set,s=await this.resolveClassFileIRI(e);if(!s)return[];let o=new Set([e]),c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid"));c&&o.add(c);let l=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_label"));l&&o.add(l);let u=a((h,p)=>{if(o.has(h))return;let y=r.get(h);(y===void 0||p<y)&&r.set(h,p)},"setMin"),f=[{fileIRI:s,depth:0}];for(;f.length>0;){let h=f.shift();if(!h)break;let{fileIRI:p,depth:y}=h;if(y>=Lf||i.has(p.value))continue;i.add(p.value);let g=await this.tripleStore.match(p,U.Namespace.EXO.term("Class_superClass"),void 0);for(let _ of g){let S=_.object;if(!(S instanceof Jt.IRI))continue;let E=y+1,T=S.value.startsWith("obsidian://vault/"),A=this.iriToObsidianName(S.value);A&&u(A,E);let x=null;if(T?x=S:A&&(x=await this.resolveClassFileIRI(A)),!x)continue;let R=await this.getLiteralValue(x,U.Namespace.EXO.term("Asset_uid"));R&&u(R,E),i.has(x.value)||f.push({fileIRI:x,depth:E})}}let d=Array.from(r.entries()).map(([h,p])=>({ref:h,depth:p}));return this._ancestorDepthCache.set(e,d),d}async resolveClassFileIRI(e){if(this.looksLikeUUID(e))return this.findSubjectByUID(e);let t=await this.findUidByLabel(e);return t?this.findSubjectByUID(t):null}async findUidByLabel(e){let t=await this.tripleStore.match(void 0,U.Namespace.EXO.term("Asset_label"),void 0);for(let r of t)if(r.object instanceof $t.Literal&&r.object.value===e&&r.subject instanceof Jt.IRI){let i=await this.tripleStore.match(r.subject,U.Namespace.EXO.term("Asset_uid"),void 0);if(i.length>0&&i[0].object instanceof $t.Literal)return i[0].object.value}return 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 Jt.IRI){let s=await this.tripleStore.match(i,U.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof $t.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof $t.Literal?this.normalizeWikilink(i.value):null}async getLinkedUIDs(e,t){let r=await this.tripleStore.match(e,t,void 0),i=[];for(let s of r){let o=s.object;if(o instanceof Jt.IRI){let c=await this.tripleStore.match(o,U.Namespace.EXO.term("Asset_uid"),void 0);if(c.length>0&&c[0].object instanceof $t.Literal)i.push(c[0].object.value);else{let l=o.value.split("/").pop()?.replace(".md","");l&&i.push(l)}}else if(o instanceof $t.Literal){let c=this.normalizeWikilink(o.value);c&&i.push(c)}}return i}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 $t.Literal?this.normalizeWikilink(i.value):i instanceof Jt.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 $t.Literal?this.unwrapWikilink(i.value):i instanceof Jt.IRI?this.iriToObsidianName(i.value)??i.value:null}unwrapWikilink(e){if(!e)return e;let t=e.trim().replace(/^"|"$/g,"");if(t.startsWith("http://")||t.startsWith("https://"))return this.iriToObsidianName(t)??t;let r=t.match(/^\[\[([^\]|]+)\|([^\]]+)\]\]$/);if(r)return r[2].trim();let i=t.match(/^\[\[([^\]|]+)\]\]$/);if(i){let s=i[1].trim();return s.startsWith("http://")||s.startsWith("https://")?this.iriToObsidianName(s)??s:s}return t}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 $t.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof Jt.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,U.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){return(0,m8.iriToObsidianName)(e)}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};ro.CommandResolver=US;ro.CommandResolver=US=$S=u8([(0,d8.injectable)(),f8("design:paramtypes",[Object,Object])],US)});var VS=w(BS=>{"use strict";Object.defineProperty(BS,"__esModule",{value:!0});BS.validateExoQLAllowlist=x8;var Cm=Ff();function x8(n){if(!n||typeof n!="object")return;let e=n;if(e.type==="update"){let t=n.updates??[];for(let r of t)if(r?.type==="load")throw new Cm.ExoQLForbiddenKeywordError("LOAD");throw new Cm.ExoQLForbiddenKeywordError("UPDATE")}if(e.type==="query"){if(e.from){let t=Array.isArray(e.from.default)&&e.from.default.length>0,r=Array.isArray(e.from.named)&&e.from.named.length>0;if(t||r)throw new Cm.ExoQLForbiddenKeywordError("FROM")}if(Array.isArray(e.where))for(let t of e.where)Pm(t);if(Array.isArray(e.template))for(let t of e.template)Pm(t)}}a(x8,"validateExoQLAllowlist");function Pm(n){if(!n||typeof n!="object")return;if(n.type==="service")throw new Cm.ExoQLForbiddenKeywordError("SERVICE");if(Array.isArray(n.patterns))for(let t of n.patterns)Pm(t);let e=n.where;if(Array.isArray(e))for(let t of e)Pm(t)}a(Pm,"walkPatternForBannedKeywords")});var qS=w(Om=>{"use strict";Object.defineProperty(Om,"__esModule",{value:!0});Om.DEFAULT_EVAL_CONFIG=void 0;Om.DEFAULT_EVAL_CONFIG=Object.freeze({enabled:!0,maxNestedEvalCount:100,maxAggregateEvalMillis:1e4})});var Fm=w(GS=>{"use strict";Object.defineProperty(GS,"__esModule",{value:!0});GS.evaluateWithExoEval=F8;var A8=ol(),I8=cl(),R8=Cl(),C8=VS(),P8=qS(),O8=Ff();async function F8(n,e={}){if(typeof n!="string")throw new TypeError("evaluateWithExoEval: sparql must be a string");let r=new A8.ExoQLParser().parse(n);if((0,C8.validateExoQLAllowlist)(r),!{...P8.DEFAULT_EVAL_CONFIG,...e.config??{}}.enabled)throw new O8.ExoQLEvalDisabledError;let s="queryType"in r&&typeof r.queryType=="string"?r.queryType:"SELECT";if(!e.store)return s==="ASK"?{kind:"ask",result:!1}:s==="CONSTRUCT"?{kind:"construct",triples:[]}:{kind:"select",rows:[]};let c=new I8.ExoQLAlgebraTranslator().translate(r),l=new R8.ExoQLQueryExecutor(e.store);return l.isAskQuery(c)?{kind:"ask",result:await l.executeAsk(c)}:l.isConstructQuery(c)?{kind:"construct",triples:await l.executeConstruct(c)}:{kind:"select",rows:await l.executeAll(c)}}a(F8,"evaluateWithExoEval")});var Nf=w(Dm=>{"use strict";Object.defineProperty(Dm,"__esModule",{value:!0});Dm.liveClock=D8;Dm.frozenClock=L8;function D8(){return{now:a(()=>new Date,"now")}}a(D8,"liveClock");function L8(n){let e=new Date(n);return{now:a(()=>new Date(e.getTime()),"now")}}a(L8,"frozenClock")});var y3=w(no=>{"use strict";var N8=no&&no.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;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--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},k8=no&&no.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},kf;Object.defineProperty(no,"__esModule",{value:!0});no.PreconditionEvaluator=void 0;var M8=Ue(),j8=ol(),$8=cl(),g3=Cl(),U8=Fm(),B8=Nf(),Mf=kf=class{static{a(this,"PreconditionEvaluator")}constructor(e,t,r){this.hostFunctions=new Map,this.askCache=new Map,this.tripleStore=e,this.queryBodyResolver=t,this.clock=r?.clock??(0,B8.liveClock)()}async evaluate(e,t,r){return e?e.sparqlAsk?this.evaluateSparqlAsk(e.sparqlAsk,t):e.query?this.evaluateQueryRef(e.query,t):e.hostFunction?this.evaluateHostFunction(e.hostFunction,t,r):!0:!0}async evaluateQueryRef(e,t){if(!this.queryBodyResolver)return!1;try{let r=await this.queryBodyResolver.resolveSparql(e);if(!r)return!1;let i=this.substituteVariables(r,t),s=await(0,U8.evaluateWithExoEval)(i,{store:this.tripleStore});return s.kind!=="ask"?!1:s.result}catch{return!1}}registerHostFunction(e,t){this.hostFunctions.set(e,t)}hasHostFunction(e){return this.hostFunctions.has(e)}evaluateHostFunctionSync(e,t,r){return this.hostFunctions.has(e)?this.evaluateHostFunction(e,t,r):null}invalidateCache(){this.askCache.clear()}compileAsk(e){let t=this.substituteVariables(e,kf.SENTINEL_IRI),i=new j8.ExoQLParser().parse(t),o=new $8.ExoQLAlgebraTranslator().translate(i);return new g3.ExoQLQueryExecutor(this.tripleStore).isAskQuery(o)?o: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 o=this.compileAsk(e);if(!o)return!1;r=o,this.askCache.set(e,r)}let i=JSON.parse(JSON.stringify(r).replaceAll(kf.SENTINEL_IRI,t));return await new g3.ExoQLQueryExecutor(this.tripleStore).executeAsk(i)}catch{return!1}}substituteVariables(e,t){let r=this.clock.now(),i=r.toISOString(),s=i.slice(0,10),o=new Date(r.getTime()+kf.ALMATY_OFFSET_MS),c=o.getUTCFullYear(),l=o.getUTCMonth(),u=o.getUTCDate(),f=o.getUTCDay(),h=new Date(Date.UTC(c,l,u-1)).toISOString().slice(0,10),p=(f+6)%7,y=new Date(Date.UTC(c,l,u-p)),g=y.toISOString().slice(0,10),S=new Date(y.getTime()-10080*60*1e3).toISOString().slice(0,10),E=`${c}-${String(l+1).padStart(2,"0")}-01`,T=l===0?11:l-1,x=`${l===0?c-1:c}-${String(T+1).padStart(2,"0")}-01`,R=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${i}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${g}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${S}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${E}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${x}"^^xsd:date`).replace(/\$thisYearStart/g,`"${R}"^^xsd:date`).replace(/\$today/g,`"${s}"^^xsd:date`)}};no.PreconditionEvaluator=Mf;Mf.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Mf.ALMATY_OFFSET_MS=300*60*1e3;no.PreconditionEvaluator=Mf=kf=N8([(0,M8.injectable)(),k8("design:paramtypes",[Object,Object,Object])],Mf)});var b3=w(io=>{"use strict";Object.defineProperty(io,"__esModule",{value:!0});io.hasUidFilename=io.hasNonUidFilename=void 0;io.registerDefaultHostFunctions=G8;var V8=a(n=>{let e=n.assetUid;if(typeof e!="string"||e.trim()==="")return!1;let t=n.fileBasename;return typeof t!="string"?!1:t!==e},"hasNonUidFilename");io.hasNonUidFilename=V8;var q8=a(n=>{let e=n.assetUid;if(typeof e!="string"||e.trim()==="")return!1;let t=n.fileBasename;return typeof t!="string"?!1:t===e},"hasUidFilename");io.hasUidFilename=q8;function G8(n){n.registerHostFunction("hasNonUidFilename",io.hasNonUidFilename),n.registerHostFunction("hasUidFilename",io.hasUidFilename)}a(G8,"registerDefaultHostFunctions")});var Nm=w(Lm=>{"use strict";Object.defineProperty(Lm,"__esModule",{value:!0});Lm.liveUidGenerator=W8;Lm.seededUidGenerator=H8;var WS=Si();function W8(){return{next:a(()=>(0,WS.v4)(),"next")}}a(W8,"liveUidGenerator");var z8="6ba7b810-9dad-11d1-80b4-00c04fd430c8";function H8(n){let e=0,t=(0,WS.v5)(n,z8);return{next:a(()=>{let r=`${n}#${e}`;return e+=1,(0,WS.v5)(r,t)},"next")}}a(H8,"seededUidGenerator")});var Mm=w(ec=>{"use strict";Object.defineProperty(ec,"__esModule",{value:!0});ec.registerResolver=Kr;ec.getResolver=K8;ec.getRegisteredResolverIds=Q8;ec.clearResolvers=X8;ec.installDefaultResolvers=Y8;var km=new Map;function Kr(n,e){km.set(n,e)}a(Kr,"registerResolver");function K8(n){return km.get(n)}a(K8,"getResolver");function Q8(){return Array.from(km.keys())}a(Q8,"getRegisteredResolverIds");function X8(){km.clear()}a(X8,"clearResolvers");function ea(n){return n<10?`0${n}`:String(n)}a(ea,"pad2");function Y8(){Kr("today",()=>new Date().toISOString().slice(0,10)),Kr("todayStart",()=>new Date(new Date().setHours(0,0,0,0)).toISOString()),Kr("target",n=>n.targetIRI?`"[[${n.targetIRI}]]"`:""),Kr("targetFolder",n=>{if(!n.targetFilePath)return"";let e=n.targetFilePath.replace(/^\/+/,""),t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}),Kr("randomUUIDv4",()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();throw new Error("randomUUIDv4 resolver requires crypto.randomUUID() \u2014 runtime is missing Node crypto / Web Crypto API.")}),Kr("nowTimestamp",()=>{let n=new Date;return`${n.getFullYear()}-${ea(n.getMonth()+1)}-${ea(n.getDate())}T${ea(n.getHours())}:${ea(n.getMinutes())}:${ea(n.getSeconds())}`}),Kr("nowDate",()=>{let n=new Date;return`${n.getFullYear()}-${ea(n.getMonth()+1)}-${ea(n.getDate())}`}),Kr("nowYear",()=>String(new Date().getFullYear())),Kr("nowMonth",()=>ea(new Date().getMonth()+1)),Kr("userInputLabel",n=>{let e=n.userInput?.label;return typeof e=="string"?e:""}),Kr("userInput",(n,e)=>{if(!e)return null;let t=n.userInput?.[e];return typeof t=="string"?t:t==null?null:String(t)}),Kr("targetProperty",(n,e)=>{if(!e||!n.targetFm)return null;let t=n.targetFm[e];return t==null?null:Array.isArray(t)?t.map(String):String(t)}),Kr("labelAsArray",n=>{let e=n.userInput?.label;return typeof e=="string"&&e.length>0?[e]:[]}),Kr("groundingTargetClass",n=>n.groundingTargetClassUid?`"[[${n.groundingTargetClassUid}]]"`:null),Kr("targetClassSelf",n=>{if(!n.targetFilePath)return null;let e=n.targetFilePath.replace(/^\/+/,""),r=e.slice(e.lastIndexOf("/")+1).replace(/\.md$/i,"");return r.length>0?`"[[${r}]]"`:null})}a(Y8,"installDefaultResolvers")});var zS=w(jm=>{"use strict";Object.defineProperty(jm,"__esModule",{value:!0});jm.resolveTemplateBody=Z8;jm.stripTemplateFrontmatter=eU;var _3=Mm();(0,_3.installDefaultResolvers)();var J8=/\$([A-Za-z][A-Za-z0-9_]*)/g;function Z8(n,e={}){return n.replace(J8,(t,r)=>{let i=(0,_3.getResolver)(r);if(i===void 0)return t;let s=i(e);return typeof s=="string"&&s.length>0?s:t})}a(Z8,"resolveTemplateBody");function eU(n){let e=n.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);return e?n.slice(e[0].length):n}a(eU,"stripTemplateFrontmatter")});var jf=w(Ol=>{"use strict";Object.defineProperty(Ol,"__esModule",{value:!0});Ol.registerOrderSpecLoader=tU;Ol.clearOrderSpecLoader=rU;Ol.loadDefaultSpec=nU;Ol.orderProperties=iU;var $m=null,ta,Um=!1;function tU(n){$m=n,ta=void 0,Um=!1}a(tU,"registerOrderSpecLoader");function rU(){$m=null,ta=void 0,Um=!1}a(rU,"clearOrderSpecLoader");function nU(){if(ta!==void 0)return ta;if(!$m)return ta=null,null;try{ta=$m()}catch(n){Um||(console.warn("[OrderSpecResolver] loader threw, falling back to insertion order:",n),Um=!0),ta=null}return ta}a(nU,"loadDefaultSpec");function iU(n,e){if(!e||e.head.length===0&&e.tail.length===0)return n;let t=Object.keys(n),r=new Set(e.head),i=new Set(e.tail),s=e.head.filter(u=>Object.prototype.hasOwnProperty.call(n,u)),o=e.tail.filter(u=>Object.prototype.hasOwnProperty.call(n,u)),c=t.filter(u=>!r.has(u)&&!i.has(u));e.middleStrategy==="alphabetical"&&c.sort((u,f)=>u.localeCompare(f));let l={};for(let u of s)l[u]=n[u];for(let u of c)l[u]=n[u];for(let u of o)l[u]=n[u];return l}a(iU,"orderProperties")});var ys=w(Bm=>{"use strict";Object.defineProperty(Bm,"__esModule",{value:!0});Bm.FrontmatterService=void 0;var w3=jf(),$f=class n{static{a(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}}parseObject(e){let t=this.parse(e);if(!t.exists)return null;let r={},i=t.content.split(/\r?\n/),s=null,o=null,c=a(()=>{s!==null&&o!==null&&(r[s]=o),s=null,o=null},"flushArray");for(let l of i){let u=/^ {2}- (.*)$/.exec(l);if(u){s!==null&&o!==null&&o.push(u[1].trim());continue}c();let f=/^([^:\s][^:]*):\s*(.*)$/.exec(l);if(!f)continue;let d=f[1].trim(),h=f[2].trim();h===""?(s=d,o=[]):r[d]=h}return c(),r}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 Al(`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}}};Il.SPARQLGenerator=jS});var Cl=w(Dn=>{"use strict";var H7=Dn&&Dn.__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:a(function(){return e[t]},"get")}),Object.defineProperty(n,r,i)}):(function(n,e,t,r){r===void 0&&(r=t),n[r]=e[t]})),K7=Dn&&Dn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),a3=Dn&&Dn.__importStar||(function(){var n=a(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"&&H7(t,e,r[i]);return K7(t,e),t}})();Object.defineProperty(Dn,"__esModule",{value:!0});Dn.QueryExecutor=Dn.ExoQLQueryExecutor=Dn.QueryExecutorError=void 0;var Q7=iS(),X7=ym(),Y7=ES(),J7=xS(),Z7=XR(),e8=JR(),t8=t3(),r8=NS(),n8=n3(),i8=s3(),s8=o3(),o8=Ae(),a8=Ve(),c8=um(),Br="http://www.w3.org/2001/XMLSchema#",l8=new Set([`${Br}integer`,`${Br}decimal`,`${Br}float`,`${Br}double`,`${Br}nonPositiveInteger`,`${Br}negativeInteger`,`${Br}long`,`${Br}int`,`${Br}short`,`${Br}byte`,`${Br}nonNegativeInteger`,`${Br}unsignedLong`,`${Br}unsignedInt`,`${Br}unsignedShort`,`${Br}unsignedByte`,`${Br}positiveInteger`]),Rl=class extends Error{static{a(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Dn.QueryExecutorError=Rl;var Am=class{static{a(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new Q7.BGPExecutor(e),this.filterExecutor=new X7.FilterExecutor,this.optionalExecutor=new Y7.OptionalExecutor,this.unionExecutor=new J7.UnionExecutor,this.minusExecutor=new Z7.MinusExecutor,this.valuesExecutor=new e8.ValuesExecutor,this.aggregateExecutor=new t8.AggregateExecutor,this.constructExecutor=new r8.ConstructExecutor,this.serviceExecutor=new n8.ServiceExecutor(t.serviceConfig),this.graphExecutor=new i8.GraphExecutor(e),this.sparqlGenerator=new s8.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 Rl(`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 o of this.execute(e.left))t.push(o);if(t.length===0)return;let r=new Set;for(let o of t)for(let c of o.variables())r.add(c);let i=this.collectOperationVariables(e.right);if([...r].some(o=>i.has(o)))for(let o of t){let c=this.substituteVariables(e.right,o);for await(let l of this.execute(c)){let u=o.merge(l);u!==null&&(yield u)}}else{let o=[];for await(let c of this.execute(e.right))o.push(c);for(let c of t)for(let l of o){let u=c.merge(l);u!==null&&(yield u)}}}async*executeLeftJoin(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(s,"rightGen"),yield*this.optionalExecutor.execute(i(),s())}async*executeUnion(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(s,"rightGen"),yield*this.unionExecutor.execute(i(),s())}async*executeMinus(e){let t=[];for await(let o of this.execute(e.left))t.push(o);let r=[];for await(let o of this.execute(e.right))r.push(o);async function*i(){for(let o of t)yield o}a(i,"leftGen");async function*s(){for(let o of r)yield o}a(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(()=>a3(hs())),r=new Set(e.variables);for await(let i of this.execute(e.input)){let s=new t;for(let o of i.variables())if(r.has(o)){let c=i.get(o);c!==void 0&&s.set(o,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 o=this.getExpressionValue(s.expression,r),c=this.getExpressionValue(s.expression,i),l=0;if(o===void 0&&c===void 0?l=0:o===void 0?l=1:c===void 0?l=-1:typeof o=="number"&&typeof c=="number"?l=o-c:l=String(o).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(o=>this.filterExecutor.evaluateExpression(o,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 o=r.merge(s);o!==null&&(yield o)}}}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 o8.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(()=>a3(hs()));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);if(!r)return;if(r instanceof a8.Literal){let i=r.datatype?.value;if(i===`${Br}dayTimeDuration`)try{return c8.DateTimeFunctions.parseDayTimeDuration(r.value)}catch{return r.value}if(i&&l8.has(i)){let s=parseFloat(r.value);if(!Number.isNaN(s))return s}return r.value}return r.value??r.id??String(r)}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 Rl("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 Rl("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Dn.ExoQLQueryExecutor=Am;Dn.QueryExecutor=Am});var m3=w(ro=>{"use strict";var u8=ro&&ro.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;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--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},f8=ro&&ro.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},$S;Object.defineProperty(ro,"__esModule",{value:!0});ro.CommandResolver=void 0;var d8=Ue(),h8=Kc(),Jt=Ae(),$t=Ve(),U=zt(),c3=Bo(),l3=sf(),p8=Xc(),m8=Ip(),Pl=Jb(),Im=rR(),g8=ol(),y8=cl(),b8=Cl(),Lf=10,Rm="exo__Asset",_8=Lf+1,u3="08cec529-90eb-4d43-88de-ceecccea12b0",w8=U.Namespace.EXOCMD.term("SubstitutionToken").value,f3=new Set(["today","todayStart","targetFolder","target","randomUUIDv4","nowTimestamp","nowDate","nowYear","nowMonth","userInputLabel","userInput","targetProperty","labelAsArray","groundingTargetClass","targetClassSelf"]);function S8(n,e){return`__SUBSTITUTE__${n}__${e}__`}a(S8,"buildSubstitutionMarker");function v8(n,e,t){let r=(0,p8.utf8ToBase64)(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`__SUBSTITUTE_P__${n}__${e}__${r}__`}a(v8,"buildParameterisedMarker");var d3="3f28af98-c031-4718-8ba2-44ad0b012c52",E8=U.Namespace.EXOCMD.term("TokenInvocation").value,h3="29e2c8f8-2d27-4e58-b467-2e85d46f8122",p3="universal-default-template",T8=new Set(["today","todayStart","nowTimestamp","nowDate","nowYear","nowMonth"]),US=$S=class{static{a(this,"CommandResolver")}clearUniversalCache(){this._universalCacheReady=!1,this._universalCacheValue=null,(0,Im.clearUniversalDefault)()}constructor(e,t=h8.NullLogger){this.tripleStore=e,this.logger=t,this.cache=new Map,this.multiCache=new Map,this._ancestorDepthCache=new Map,this._legacyPropertyDefaultsWarnedGroundings=new Set,this._universalCacheReady=!1,this._universalCacheValue=null}async resolveForAssetMulti(e,t,r){if(t.length===0)return[];let i=[...t].sort().join(","),s=`${e}::${i}::${r??""}`,o=this.multiCache.get(s);if(o)return o;let c=await this.expandClassHierarchy(t),l=new Map;for(let[h,p]of c){let y=await this.resolveForAsset(e,h,r);for(let g of y){let _=this.getBindingPriority(g.binding)===2?p:0,S=l.get(g.binding.id);(!S||_<S.depth)&&l.set(g.binding.id,{rc:g,depth:_})}}let u=new Set;for(let{rc:h}of l.values())if(h.binding.overrides)for(let p of h.binding.overrides)u.add(p);let f=Array.from(l.entries()).filter(([h])=>!u.has(h)).map(([,h])=>h);f.sort((h,p)=>{let y=this.getBindingPriority(h.rc.binding),g=this.getBindingPriority(p.rc.binding);return y!==g?y-g:h.depth!==p.depth?h.depth-p.depth:(h.rc.binding.order??100)-(p.rc.binding.order??100)});let d=f.map(h=>h.rc);return this.multiCache.set(s,d),d}async expandClassHierarchy(e){let t=new Map;for(let c of e){if(c===Rm){t.set(c,new Set);continue}let l=[];try{l=await this.getClassAncestors(c)}catch{l=[]}t.set(c,new Set(l))}let r=a(c=>{for(let l of e)if(l!==c&&t.get(l)?.has(c)&&!t.get(c)?.has(l))return!0;return!1},"isAncestorOfSibling"),i=e.filter(c=>!r(c)),s=new Map,o=a((c,l)=>{let u=s.get(c);(u===void 0||l<u)&&s.set(c,l)},"setMin");for(let c of i){if(o(c,0),this.looksLikeUUID(c))try{let u=await this.resolveLabelByUID(c);u&&o(u,0)}catch{}if(c===Rm)continue;let l=[];try{l=await this.getClassAncestorsWithDepth(c)}catch{l=[]}for(let{ref:u,depth:f}of l)o(u,f)}return s.has(Rm)||s.set(Rm,_8),s}async resolveForAsset(e,t,r){let i=`${e}:${t}:${r??""}`,s=this.cache.get(i);if(s)return s;let o=await this.findBindings(t,r,e),c=[];for(let l of o){let u=await this.loadCommand(l.commandRef,{targetClass:l.targetClass});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,t){let r=await this.findSubjectByUID(e);if(!r||(await this.tripleStore.match(r,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("Command"))).length===0)return null;let s=await this.getLiteralValue(r,U.Namespace.EXO.term("Asset_label"))??"Unknown Command",o=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_labelTemplate")),c=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_icon")),l=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_confirmMessage")),u=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_successMessage")),f=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_category")),d=await this.getLiteralValue(r,U.Namespace.EXOCMD.term("Command_openInSameTab")),h=d!==null&&String(d).trim().toLowerCase()==="true",p=await this.loadLinkedPrecondition(r),y=await this.loadLinkedGrounding(r,0,t);return y?{id:e,name:s,labelTemplate:o??void 0,icon:c??void 0,precondition:p??void 0,grounding:y,confirmMessage:l??void 0,successMessage:u??void 0,category:f??void 0,openInSameTab:h||void 0}:null}async findBindings(e,t,r){let i=await this.tripleStore.match(void 0,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("CommandBinding")),s=[];for(let o of i){let c=o.subject,l=await this.loadBindingDefinition(c);l&&this.bindingMatches(l,e,t,r)&&s.push(l)}return s}async findPaletteEnabledCommands(){let e=await this.tripleStore.match(void 0,U.Namespace.RDF.term("type"),U.Namespace.EXOCMD.term("Command")),t=[],r=new Set;for(let i of e){let s=i.subject;if((await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_paletteEnabled")))?.toLowerCase()!=="true")continue;let c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid"));if(!c){this.logger.warn(`[CommandResolver] paletteEnabled command at ${s.value} has no exo__Asset_uid \u2014 skipped`);continue}let l=await this.loadCommand(c);if(!l){this.logger.warn(`[CommandResolver] paletteEnabled command ${c} could not be loaded (missing grounding?) \u2014 skipped`);continue}let u=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_paletteId")),f=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Command_cliName")),d=u??f??c;if(r.has(d)){this.logger.warn(`[CommandResolver] duplicate paletteId "${d}" \u2014 first registration wins, dropping ${c}`);continue}r.add(d),t.push({command:l,paletteId:d})}return t}invalidateCache(){this.cache.clear(),this.multiCache.clear(),this._ancestorDepthCache.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:o}of i){let c=await this.evaluateSelectSnippet(o,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 o=e.slice(r,s),c=e.slice(r+1,s-1);t.push({full:o,body:c})}r=s}else r++;return t}async evaluateSelectSnippet(e,t){try{let r=e.replace(/\$target/g,`<${t}>`),s=new g8.ExoQLParser().parse(r),c=new y8.ExoQLAlgebraTranslator().translate(s),u=await new b8.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 $t.Literal||h instanceof Jt.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,U.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetClass")),o=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,U.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!o&&!c)return null;let l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_variant")),d=f!==null?this.coerceVariant(f,t):void 0,h=await this.loadLinkedPreconditionFromProperty(e,U.Namespace.EXOCMD.term("CommandBinding_precondition")),p=await this.loadLinkedStyle(e,t),y=await this.getLinkedUIDs(e,U.Namespace.EXOCMD.term("CommandBinding_overrides"));return{id:t,label:r,commandRef:i,targetClass:s??void 0,targetPrototype:o??void 0,targetAsset:c??void 0,position:l??void 0,order:u?parseInt(u,10):void 0,variant:d,precondition:h??void 0,style:p??void 0,overrides:y.length>0?y:void 0}}async loadLinkedStyle(e,t){let r=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("CommandBinding_style"),void 0);if(r.length>0){let s=r[0].object,o=null;if(s instanceof Jt.IRI)o=s;else if(s instanceof $t.Literal){let c=this.normalizeWikilink(s.value);o=await this.findSubjectByUID(c)}if(o){let c=await this.loadStyleAsset(o);if(c)return c}this.logger.warn(this.capWarning(`CommandBinding ${t}: style reference unresolved, falling back to inline variant`))}let i=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBinding_variant"));if(i!==null){let s=this.coerceVariant(i,t);if(s!==void 0)return{id:`inline:${t}`,label:"",variant:s,inline:!0}}return null}async loadStyleAsset(e){let t=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",i=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_variant")),s=i!==null?this.coerceVariant(i,t):void 0,o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_showIcon")),c=this.coerceBoolean(o),l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_labelClass")),u=l!==null?this.coerceLabelClass(l,t):void 0,f=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_ariaLabel")),d=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_tooltip")),h=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_keyboardShortcut")),p=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("CommandBindingStyle_source")),y=p!==null?this.coerceStyleSource(p,t):void 0;return{id:t,label:r,variant:s,showIcon:c,labelClass:u,ariaLabel:f??void 0,tooltip:d??void 0,keyboardShortcut:h??void 0,source:y,inline:!1}}coerceVariant(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.COMMAND_VARIANT_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle variant "${r}" not in whitelist [${Pl.COMMAND_VARIANT_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceLabelClass(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.LABEL_CLASS_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle labelClass "${r}" not in whitelist [${Pl.LABEL_CLASS_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceStyleSource(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Pl.STYLE_SOURCE_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle source "${r}" not in whitelist [${Pl.STYLE_SOURCE_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceBoolean(e){if(e===null)return;let t=e.trim().toLowerCase();if(t==="true")return!0;if(t==="false")return!1}capWarning(e){return e.length<=200?e:e.slice(0,197)+"..."}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 o=this.extractPathBasename(r);if(o&&o===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,U.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 Jt.IRI)s=i;else if(i instanceof $t.Literal){let h=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(h)}if(!s)return null;let o=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,U.Namespace.EXOCMD.term("Precondition_hostFunction")),f=await this.tripleStore.match(s,U.Namespace.EXOCMD.term("Precondition_query"),void 0),d;if(f.length>0){let h=f[0].object;if(h instanceof Jt.IRI){let p=await this.getLiteralValue(h,U.Namespace.EXO.term("Asset_uid"));p&&(d=p)}else h instanceof $t.Literal&&(d=this.normalizeWikilink(h.value))}return!o||!l&&!u&&!d?null:{id:o,label:c,...l&&{sparqlAsk:l},...u&&{hostFunction:u},...d&&{query:d}}}async loadLinkedGrounding(e,t,r){if(t>=Lf)return null;let i=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Command_grounding"),void 0);if(i.length===0)return null;if(i.length===1||!r?.targetClass){let o=await this.resolveGroundingRef(i[0].object);return o?this.loadGroundingDefinition(o,t):null}for(let o of i){let c=await this.resolveGroundingRef(o.object);if(!c)continue;let l=await this.getObsidianName(c,U.Namespace.EXOCMD.term("Grounding_targetPrototype"));if(l&&this.matchesReference(l,r.targetClass))return this.loadGroundingDefinition(c,t)}this.logger.warn(`Command ${e.value}: ${i.length} groundings declared, none matched context.targetClass='${r.targetClass}' via Grounding_targetPrototype \u2014 falling back to first grounding by iteration order (legacy behaviour). Check that one grounding's Grounding_targetPrototype references this targetClass.`);let s=await this.resolveGroundingRef(i[0].object);return s?this.loadGroundingDefinition(s,t):null}async resolveGroundingRef(e){if(e instanceof Jt.IRI)return e;if(e instanceof $t.Literal){let t=this.normalizeWikilink(e.value);return await this.findSubjectByUID(t)}return null}async loadGroundingByUid(e){let t=await this.findSubjectByUID(e);return t?this.loadGroundingDefinition(t,0):null}async loadGroundingDefinition(e,t){if(t>=Lf)return null;let r=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,U.Namespace.EXO.term("Asset_label"))??"",s=await this.resolveGroundingTypeReference(e);if(!s)return null;let o=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetProperty"));if(o&&this.looksLikeUUID(o)){let Q=await this.resolveLabelByUID(o);if(!Q)return this.logger.warn(`Grounding ${r}: targetProperty wikilink UID '${o}' is not resolvable to exo__Asset_label \u2014 grounding skipped (would otherwise write a UUID-named frontmatter key).`),null;o=Q}if(s===c3.GroundingType.SERVICE_CALL){let Q=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_serviceId"));Q&&(o=Q)}let c=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueRef")),l=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_targetValueLiteral")),u=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueSubstitution")),f=null;if(u&&this.looksLikeUUID(u)){let Q=await this.resolveLabelByUID(u);if(!Q)return this.logger.warn(`Grounding ${r}: targetValueSubstitution UID '${u}' is not resolvable to exo__Asset_label (SubstitutionToken instance missing or unlabelled) \u2014 grounding skipped.`),null;f=Q}else u&&(f=u);let d=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetValueQuery")),h=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_serviceCallPayload")),p=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_appendExpression")),y=await this.getObsidianWikilinkValue(e,U.Namespace.EXOCMD.term("Grounding_isDefinedBy")),g=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),_=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetClass"));if(_&&!this.looksLikeUUID(_)){let Q=await this.findUidByLabel(_);Q&&(_=Q)}let S=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_targetPrototype")),E=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_targetFolder")),T=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_linkBackProperty")),A=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_inputSchema")),x=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_incrementBy")),R=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_shiftDelta")),G;if(x!=null&&x!==""){let Q=Number.parseInt(String(x),10);Number.isFinite(Q)&&(G=Q)}let N=await this.resolvePropertyDefaults(e,r),P=await this.resolveInheritanceRules(e,r),k=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_propertyDefaults"));k!==null&&k!==""&&!this._legacyPropertyDefaultsWarnedGroundings.has(r)&&(this.logger.warn(`Grounding ${r}: deprecated exocmd__Grounding_propertyDefaults (plural) JSON predicate detected \u2014 the parser was removed in RFC v2 Phase 5 (#3167); value is ignored. Migrate to ref-form exocmd__Grounding_propertyDefault (singular) pointing to exocmd__PropertyDefault assets. See vault TBox c8f87363-d39c-45cb-9d4d-1be96d70f892 for the canonical replacement.`),this._legacyPropertyDefaultsWarnedGroundings.add(r));let D;s===c3.GroundingType.COMPOSITE&&(D=await this.loadCompositeSteps(e,t+1));let ee;if(A)try{let Q=JSON.parse(A);Q?.properties&&(ee=Object.entries(Q.properties).map(([q,fe])=>{let qe=fe.type,he=qe==="string"?"text":qe,Be=fe.defaultValue!==void 0?fe.defaultValue:fe.default,Ge={name:q,type:he,label:fe.title??q,required:Array.isArray(Q.required)&&Q.required.includes(q)};return Be!=null&&(Ge.defaultValue=String(Be)),typeof fe.targetClassUid=="string"&&(Ge.targetClassUid=fe.targetClassUid),Ge}))}catch{}let ie=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_prefillLabelWithDate")),X=ie!==null&&String(ie).trim().toLowerCase()==="true",se=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_labelTemplate")),ge=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_direction")),ce;if(ge!=null){let Q=String(ge).trim().toLowerCase();Q==="forward"||Q==="rollback"?ce=Q:Q!==""&&this.logger.warn(`Grounding ${r}: exocmd__Grounding_direction value '${ge}' is not 'forward' or 'rollback' \u2014 treating as undefined (will default to 'forward' at dispatch).`)}let B=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("Grounding_bodyTemplate")),V=await this.getObsidianName(e,U.Namespace.EXOCMD.term("Grounding_templateRef")),W={id:r,label:i,type:s,targetProperty:o??void 0,targetValueRef:c??void 0,targetValueLiteral:l??void 0,targetValueSubstitution:f??void 0,targetValueQuery:d??void 0,serviceCallPayload:h??void 0,appendExpression:p??void 0,sparqlUpdate:g??void 0,steps:D,targetClass:_??void 0,targetPrototype:S??void 0,targetFolder:E??void 0,linkBackProperty:T??void 0,incrementBy:G,shiftDelta:R??void 0,propertyDefault:N.length>0?N:void 0,inheritanceRule:P.length>0?P:void 0,isDefinedBy:y??void 0,prefillLabelWithDate:X||void 0,labelTemplate:se??void 0,direction:ce,bodyTemplate:B??void 0,templateRef:V??void 0};return ee&&(W.inputSchema=ee),W}async loadCompositeSteps(e,t){if(t>=Lf)return[];let r=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let o=null;if(s.object instanceof Jt.IRI)o=s.object;else if(s.object instanceof $t.Literal){let l=this.normalizeWikilink(s.object.value);o=await this.findSubjectByUID(l)}if(!o)continue;let c=await this.loadGroundingDefinition(o,t);c&&i.push(c)}return i}async resolvePropertyDefaults(e,t){let r=await this.resolvePropertyDefaultsForSubject(e,t,U.Namespace.EXOCMD.term("Grounding_propertyDefault")),i=await this.getUniversalCache();return i&&i.propertyDefaults.length>0?(0,Im.mergePropertyDefaults)(i.propertyDefaults,r):r}async resolvePropertyDefaultsForSubject(e,t,r){let i=await this.tripleStore.match(e,r,void 0),s=[];for(let o of i){let c=await this.resolveRefTripleObject(o.object);if(!c)continue;let l=await this.getObsidianName(c,U.Namespace.EXOCMD.term("PropertyDefault_property"));if(!l){this.logger.warn(`Grounding ${t}: PropertyDefault asset missing exocmd__PropertyDefault_property \u2014 entry skipped.`);continue}let u=this.looksLikeUUID(l)?await this.resolveLabelByUID(l):l;if(!u){this.logger.warn(`Grounding ${t}: PropertyDefault property UID '${l}' is not resolvable to exo__Asset_label \u2014 entry skipped.`);continue}let f=await this.getObsidianName(c,U.Namespace.EXOCMD.term("PropertyDefault_value"));if(!f){this.logger.warn(`Grounding ${t}: PropertyDefault '${u}' missing exocmd__PropertyDefault_value \u2014 entry skipped.`);continue}let d=await this.resolvePropertyDefaultValue(f,t,u);d!==null&&s.push({propertyName:u,value:d})}return s}async getUniversalCache(){if(this._universalCacheReady)return this._universalCacheValue;this._universalCacheReady=!0;let e=await(0,Im.loadUniversalDefault)();if(e)return this._universalCacheValue=e,e;let t=await this.findUniversalSingleton();if(!t)return this._universalCacheValue=null,null;let r=await this.resolvePropertyDefaultsForSubject(t,p3,U.Namespace.EXOCMD.term("Template_propertyDefault")),i=await this.resolveInheritanceRulesForSubject(t,p3,U.Namespace.EXOCMD.term("Template_inheritanceRule"));return this._universalCacheValue={propertyDefaults:r,inheritanceRules:i},this._universalCacheValue}async findUniversalSingleton(){let e=U.Namespace.EXOCMD.term("UniversalDefaultTemplate").value,t=await this.tripleStore.match(void 0,U.Namespace.EXO.term("Instance_class"),void 0),r=[];for(let i of t){let s=!1;if(i.object instanceof Jt.IRI)s=i.object.value===e||i.object.value.includes(h3);else if(i.object instanceof $t.Literal){let o=this.unwrapWikilink(i.object.value);s=o==="exocmd__UniversalDefaultTemplate"||o===h3}s&&i.subject instanceof Jt.IRI&&r.push(i.subject)}return r.length===0?null:(r.length===1||(r.sort((i,s)=>i.value.localeCompare(s.value)),this.logger.warn(`Multiple UniversalDefaultTemplate singletons found (${r.length}); selecting deterministically by lexicographic UID order: ${r[0].value}`)),r[0])}async resolveInheritanceRules(e,t){let r=await this.resolveInheritanceRulesForSubject(e,t,U.Namespace.EXOCMD.term("Grounding_inheritanceRule")),i=await this.getUniversalCache();return i&&i.inheritanceRules.length>0?(0,Im.mergeInheritanceRules)(i.inheritanceRules,r):r}async resolveInheritanceRulesForSubject(e,t,r){let i=await this.tripleStore.match(e,r,void 0),s=[],o=t;for(let c of i){let l=await this.resolveRefTripleObject(c.object);if(!l)continue;let u=await this.resolveLabelRef(l,U.Namespace.EXOCMD.term("InheritanceRule_sourceProperty"));if(!u){this.logger.warn(`Grounding ${o}: InheritanceRule missing/unresolvable exocmd__InheritanceRule_sourceProperty \u2014 entry skipped.`);continue}let f=await this.resolveLabelRef(l,U.Namespace.EXOCMD.term("InheritanceRule_targetProperty"));if(!f){this.logger.warn(`Grounding ${o}: InheritanceRule missing/unresolvable exocmd__InheritanceRule_targetProperty \u2014 entry skipped.`);continue}let d=await this.tripleStore.match(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"),void 0),h,p;if(d.length>0){let A=await this.getObsidianName(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"));if(!A||!A.trim()){this.logger.warn(`Grounding ${o}: InheritanceRule has exocmd__InheritanceRule_targetClassCondition triple but ref is unresolvable \u2014 entire rule skipped (would otherwise apply unconditionally, broadening scope).`);continue}this.looksLikeUUID(A)?(p=A,h=await this.resolveLabelByUID(A)??void 0):h=A}let y=await this.tripleStore.match(l,U.Namespace.EXOCMD.term("InheritanceRule_targetClassExclusion"),void 0),g=[],_=[],S=!1;for(let A of y){let x=null;if(A.object instanceof Jt.IRI?x=this.iriToObsidianName(A.object.value)??A.object.value:A.object instanceof $t.Literal&&(x=this.unwrapWikilink(A.object.value)),!x){S=!0;continue}if(this.looksLikeUUID(x)){_.push(x);let R=await this.resolveLabelByUID(x);R&&g.push(R)}else g.push(x)}if(S){this.logger.warn(`Grounding ${o}: InheritanceRule has unresolvable exocmd__InheritanceRule_targetClassExclusion entry \u2014 entire rule skipped (would otherwise expand scope by silently dropping the excluded class).`);continue}let E=await this.getLiteralValue(l,U.Namespace.EXOCMD.term("InheritanceRule_priority")),T=50;if(E!==null&&E!==""){let A=Number.parseInt(String(E),10);Number.isFinite(A)&&(T=A)}s.push({sourcePropertyName:u,targetPropertyName:f,targetClassCondition:h,targetClassConditionUid:p,targetClassExclusion:g,targetClassExclusionUids:_,priority:T})}return s}async resolveRefTripleObject(e){if(e instanceof Jt.IRI)return e;if(e instanceof $t.Literal){let t=this.normalizeWikilink(e.value);return t?this.findSubjectByUID(t):null}return null}async resolveLabelRef(e,t){let r=await this.getObsidianName(e,t);return r?this.looksLikeUUID(r)?this.resolveLabelByUID(r):r:null}async resolvePropertyDefaultValue(e,t,r){if(!this.looksLikeUUID(e))return`"[[${e}]]"`;let i=await this.findSubjectByUID(e);return i?await this.assetIsTokenInvocation(i)?this.resolveTokenInvocation(i,e,t,r):await this.assetIsSubstitutionToken(i)?this.dispatchSubstitutionToken(i,e,t,r,void 0):`"[[${e}]]"`:`"[[${e}]]"`}async dispatchSubstitutionToken(e,t,r,i,s){let o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("SubstitutionToken_resolver"));if(!o||!o.trim())return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' references SubstitutionToken '${t}' with no exocmd__SubstitutionToken_resolver \u2014 falling back to wikilink form.`),`"[[${t}]]"`;let c=o.trim();return f3.has(c)?s!==void 0?v8(c,t,s):T8.has(c)?$S.parseTimeResolve(c):S8(c,t):(this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' SubstitutionToken '${t}' declares unknown resolver-id '${c}' \u2014 falling back to wikilink form. Known ids: ${Array.from(f3).join(", ")}.`),`"[[${t}]]"`)}static parseTimeResolve(e){let t=new Date,r=a(i=>i<10?`0${i}`:String(i),"pad");switch(e){case"today":return t.toISOString().slice(0,10);case"todayStart":return new Date(new Date().setHours(0,0,0,0)).toISOString();case"nowTimestamp":return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}T${r(t.getHours())}:${r(t.getMinutes())}:${r(t.getSeconds())}`;case"nowDate":return`${t.getFullYear()}-${r(t.getMonth()+1)}-${r(t.getDate())}`;case"nowYear":return String(t.getFullYear());case"nowMonth":return r(t.getMonth()+1);default:return""}}async resolveTokenInvocation(e,t,r,i){let s=await this.getObsidianName(e,U.Namespace.EXOCMD.term("TokenInvocation_token"));if(!s)return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' missing exocmd__TokenInvocation_token \u2014 entry skipped.`),null;let o=await this.getLiteralValue(e,U.Namespace.EXOCMD.term("TokenInvocation_parameter"))??"";if(!this.looksLikeUUID(s))return this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' references non-UUID token '${s}' \u2014 entry skipped.`),null;let c=await this.findSubjectByUID(s);return c?this.dispatchSubstitutionToken(c,s,r,i,o):(this.logger.warn(`Grounding ${r}: PropertyDefault '${i}' TokenInvocation '${t}' token ref '${s}' not found in store \u2014 entry skipped.`),null)}async assetIsTokenInvocation(e){let t=await this.tripleStore.match(e,U.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof Jt.IRI){if(r.object.value===E8||r.object.value.includes(d3))return!0}else if(r.object instanceof $t.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__TokenInvocation"||i===d3)return!0}return!1}async assetIsSubstitutionToken(e){let t=await this.tripleStore.match(e,U.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof Jt.IRI){if(r.object.value===w8||r.object.value.includes(u3))return!0}else if(r.object instanceof $t.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__SubstitutionToken"||i===u3)return!0}return!1}async resolveGroundingTypeReference(e){let t=await this.tripleStore.match(e,U.Namespace.EXOCMD.term("Grounding_type"),void 0);if(t.length===0)return null;let r=t[0].object;if(r instanceof Jt.IRI)return(0,l3.resolveGroundingTypeFromIRI)(r.value);if(r instanceof $t.Literal){let i=r.value,s=i.match(/^\[\[([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\|[^\]]*)?\]\]$/i);return s?(0,l3.resolveGroundingTypeFromIRI)(`obsidian://vault/${s[1].toLowerCase()}.md`):(this.logger.warn(`[exocmd-grounding-type-literal-form] legacy literal-string form '${i}' for exocmd__Grounding_type on <${e.value}>. Migrate to wikilink form per RFC 9d20c91f Phase 3.`),null)}return 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,U.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof $t.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 $t.Literal||i instanceof Jt.IRI?i.value:null}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)}async resolveLabelByUID(e){let t=await this.findSubjectByUID(e);return t?this.getLiteralValue(t,U.Namespace.EXO.term("Asset_label")):null}async getClassAncestors(e){return(await this.getClassAncestorsWithDepth(e)).map(r=>r.ref)}async getClassAncestorsWithDepth(e){let t=this._ancestorDepthCache.get(e);if(t)return t;let r=new Map,i=new Set,s=await this.resolveClassFileIRI(e);if(!s)return[];let o=new Set([e]),c=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_uid"));c&&o.add(c);let l=await this.getLiteralValue(s,U.Namespace.EXO.term("Asset_label"));l&&o.add(l);let u=a((h,p)=>{if(o.has(h))return;let y=r.get(h);(y===void 0||p<y)&&r.set(h,p)},"setMin"),f=[{fileIRI:s,depth:0}];for(;f.length>0;){let h=f.shift();if(!h)break;let{fileIRI:p,depth:y}=h;if(y>=Lf||i.has(p.value))continue;i.add(p.value);let g=await this.tripleStore.match(p,U.Namespace.EXO.term("Class_superClass"),void 0);for(let _ of g){let S=_.object;if(!(S instanceof Jt.IRI))continue;let E=y+1,T=S.value.startsWith("obsidian://vault/"),A=this.iriToObsidianName(S.value);A&&u(A,E);let x=null;if(T?x=S:A&&(x=await this.resolveClassFileIRI(A)),!x)continue;let R=await this.getLiteralValue(x,U.Namespace.EXO.term("Asset_uid"));R&&u(R,E),i.has(x.value)||f.push({fileIRI:x,depth:E})}}let d=Array.from(r.entries()).map(([h,p])=>({ref:h,depth:p}));return this._ancestorDepthCache.set(e,d),d}async resolveClassFileIRI(e){if(this.looksLikeUUID(e))return this.findSubjectByUID(e);let t=await this.findUidByLabel(e);return t?this.findSubjectByUID(t):null}async findUidByLabel(e){let t=await this.tripleStore.match(void 0,U.Namespace.EXO.term("Asset_label"),void 0);for(let r of t)if(r.object instanceof $t.Literal&&r.object.value===e&&r.subject instanceof Jt.IRI){let i=await this.tripleStore.match(r.subject,U.Namespace.EXO.term("Asset_uid"),void 0);if(i.length>0&&i[0].object instanceof $t.Literal)return i[0].object.value}return 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 Jt.IRI){let s=await this.tripleStore.match(i,U.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof $t.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof $t.Literal?this.normalizeWikilink(i.value):null}async getLinkedUIDs(e,t){let r=await this.tripleStore.match(e,t,void 0),i=[];for(let s of r){let o=s.object;if(o instanceof Jt.IRI){let c=await this.tripleStore.match(o,U.Namespace.EXO.term("Asset_uid"),void 0);if(c.length>0&&c[0].object instanceof $t.Literal)i.push(c[0].object.value);else{let l=o.value.split("/").pop()?.replace(".md","");l&&i.push(l)}}else if(o instanceof $t.Literal){let c=this.normalizeWikilink(o.value);c&&i.push(c)}}return i}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 $t.Literal?this.normalizeWikilink(i.value):i instanceof Jt.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 $t.Literal?this.unwrapWikilink(i.value):i instanceof Jt.IRI?this.iriToObsidianName(i.value)??i.value:null}unwrapWikilink(e){if(!e)return e;let t=e.trim().replace(/^"|"$/g,"");if(t.startsWith("http://")||t.startsWith("https://"))return this.iriToObsidianName(t)??t;let r=t.match(/^\[\[([^\]|]+)\|([^\]]+)\]\]$/);if(r)return r[2].trim();let i=t.match(/^\[\[([^\]|]+)\]\]$/);if(i){let s=i[1].trim();return s.startsWith("http://")||s.startsWith("https://")?this.iriToObsidianName(s)??s:s}return t}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 $t.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof Jt.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,U.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){return(0,m8.iriToObsidianName)(e)}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};ro.CommandResolver=US;ro.CommandResolver=US=$S=u8([(0,d8.injectable)(),f8("design:paramtypes",[Object,Object])],US)});var VS=w(BS=>{"use strict";Object.defineProperty(BS,"__esModule",{value:!0});BS.validateExoQLAllowlist=x8;var Cm=Ff();function x8(n){if(!n||typeof n!="object")return;let e=n;if(e.type==="update"){let t=n.updates??[];for(let r of t)if(r?.type==="load")throw new Cm.ExoQLForbiddenKeywordError("LOAD");throw new Cm.ExoQLForbiddenKeywordError("UPDATE")}if(e.type==="query"){if(e.from){let t=Array.isArray(e.from.default)&&e.from.default.length>0,r=Array.isArray(e.from.named)&&e.from.named.length>0;if(t||r)throw new Cm.ExoQLForbiddenKeywordError("FROM")}if(Array.isArray(e.where))for(let t of e.where)Pm(t);if(Array.isArray(e.template))for(let t of e.template)Pm(t)}}a(x8,"validateExoQLAllowlist");function Pm(n){if(!n||typeof n!="object")return;if(n.type==="service")throw new Cm.ExoQLForbiddenKeywordError("SERVICE");if(Array.isArray(n.patterns))for(let t of n.patterns)Pm(t);let e=n.where;if(Array.isArray(e))for(let t of e)Pm(t)}a(Pm,"walkPatternForBannedKeywords")});var qS=w(Om=>{"use strict";Object.defineProperty(Om,"__esModule",{value:!0});Om.DEFAULT_EVAL_CONFIG=void 0;Om.DEFAULT_EVAL_CONFIG=Object.freeze({enabled:!0,maxNestedEvalCount:100,maxAggregateEvalMillis:1e4})});var Fm=w(GS=>{"use strict";Object.defineProperty(GS,"__esModule",{value:!0});GS.evaluateWithExoEval=F8;var A8=ol(),I8=cl(),R8=Cl(),C8=VS(),P8=qS(),O8=Ff();async function F8(n,e={}){if(typeof n!="string")throw new TypeError("evaluateWithExoEval: sparql must be a string");let r=new A8.ExoQLParser().parse(n);if((0,C8.validateExoQLAllowlist)(r),!{...P8.DEFAULT_EVAL_CONFIG,...e.config??{}}.enabled)throw new O8.ExoQLEvalDisabledError;let s="queryType"in r&&typeof r.queryType=="string"?r.queryType:"SELECT";if(!e.store)return s==="ASK"?{kind:"ask",result:!1}:s==="CONSTRUCT"?{kind:"construct",triples:[]}:{kind:"select",rows:[]};let c=new I8.ExoQLAlgebraTranslator().translate(r),l=new R8.ExoQLQueryExecutor(e.store);return l.isAskQuery(c)?{kind:"ask",result:await l.executeAsk(c)}:l.isConstructQuery(c)?{kind:"construct",triples:await l.executeConstruct(c)}:{kind:"select",rows:await l.executeAll(c)}}a(F8,"evaluateWithExoEval")});var Nf=w(Dm=>{"use strict";Object.defineProperty(Dm,"__esModule",{value:!0});Dm.liveClock=D8;Dm.frozenClock=L8;function D8(){return{now:a(()=>new Date,"now")}}a(D8,"liveClock");function L8(n){let e=new Date(n);return{now:a(()=>new Date(e.getTime()),"now")}}a(L8,"frozenClock")});var y3=w(no=>{"use strict";var N8=no&&no.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;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--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},k8=no&&no.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},kf;Object.defineProperty(no,"__esModule",{value:!0});no.PreconditionEvaluator=void 0;var M8=Ue(),j8=ol(),$8=cl(),g3=Cl(),U8=Fm(),B8=Nf(),Mf=kf=class{static{a(this,"PreconditionEvaluator")}constructor(e,t,r){this.hostFunctions=new Map,this.askCache=new Map,this.tripleStore=e,this.queryBodyResolver=t,this.clock=r?.clock??(0,B8.liveClock)()}async evaluate(e,t,r){return e?e.sparqlAsk?this.evaluateSparqlAsk(e.sparqlAsk,t):e.query?this.evaluateQueryRef(e.query,t):e.hostFunction?this.evaluateHostFunction(e.hostFunction,t,r):!0:!0}async evaluateQueryRef(e,t){if(!this.queryBodyResolver)return!1;try{let r=await this.queryBodyResolver.resolveSparql(e);if(!r)return!1;let i=this.substituteVariables(r,t),s=await(0,U8.evaluateWithExoEval)(i,{store:this.tripleStore});return s.kind!=="ask"?!1:s.result}catch{return!1}}registerHostFunction(e,t){this.hostFunctions.set(e,t)}hasHostFunction(e){return this.hostFunctions.has(e)}evaluateHostFunctionSync(e,t,r){return this.hostFunctions.has(e)?this.evaluateHostFunction(e,t,r):null}invalidateCache(){this.askCache.clear()}compileAsk(e){let t=this.substituteVariables(e,kf.SENTINEL_IRI),i=new j8.ExoQLParser().parse(t),o=new $8.ExoQLAlgebraTranslator().translate(i);return new g3.ExoQLQueryExecutor(this.tripleStore).isAskQuery(o)?o:null}evaluateHostFunction(e,t,r){let i=this.hostFunctions.get(e);if(!i)return!0;let s=r?{...r,targetIRI:t}:{targetIRI:t};try{return i(s)}catch{return!1}}async evaluateSparqlAsk(e,t){try{let r=this.askCache.get(e);if(r===void 0){let o=this.compileAsk(e);if(!o)return!1;r=o,this.askCache.set(e,r)}let i=JSON.parse(JSON.stringify(r).replaceAll(kf.SENTINEL_IRI,t));return await new g3.ExoQLQueryExecutor(this.tripleStore).executeAsk(i)}catch{return!1}}substituteVariables(e,t){let r=this.clock.now(),i=r.toISOString(),s=i.slice(0,10),o=new Date(r.getTime()+kf.ALMATY_OFFSET_MS),c=o.getUTCFullYear(),l=o.getUTCMonth(),u=o.getUTCDate(),f=o.getUTCDay(),h=new Date(Date.UTC(c,l,u-1)).toISOString().slice(0,10),p=(f+6)%7,y=new Date(Date.UTC(c,l,u-p)),g=y.toISOString().slice(0,10),S=new Date(y.getTime()-10080*60*1e3).toISOString().slice(0,10),E=`${c}-${String(l+1).padStart(2,"0")}-01`,T=l===0?11:l-1,x=`${l===0?c-1:c}-${String(T+1).padStart(2,"0")}-01`,R=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${i}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${g}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${S}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${E}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${x}"^^xsd:date`).replace(/\$thisYearStart/g,`"${R}"^^xsd:date`).replace(/\$today/g,`"${s}"^^xsd:date`)}};no.PreconditionEvaluator=Mf;Mf.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Mf.ALMATY_OFFSET_MS=300*60*1e3;no.PreconditionEvaluator=Mf=kf=N8([(0,M8.injectable)(),k8("design:paramtypes",[Object,Object,Object])],Mf)});var b3=w(io=>{"use strict";Object.defineProperty(io,"__esModule",{value:!0});io.hasUidFilename=io.hasNonUidFilename=void 0;io.registerDefaultHostFunctions=G8;var V8=a(n=>{let e=n.assetUid;if(typeof e!="string"||e.trim()==="")return!1;let t=n.fileBasename;return typeof t!="string"?!1:t!==e},"hasNonUidFilename");io.hasNonUidFilename=V8;var q8=a(n=>{let e=n.assetUid;if(typeof e!="string"||e.trim()==="")return!1;let t=n.fileBasename;return typeof t!="string"?!1:t===e},"hasUidFilename");io.hasUidFilename=q8;function G8(n){n.registerHostFunction("hasNonUidFilename",io.hasNonUidFilename),n.registerHostFunction("hasUidFilename",io.hasUidFilename)}a(G8,"registerDefaultHostFunctions")});var Nm=w(Lm=>{"use strict";Object.defineProperty(Lm,"__esModule",{value:!0});Lm.liveUidGenerator=W8;Lm.seededUidGenerator=H8;var WS=Si();function W8(){return{next:a(()=>(0,WS.v4)(),"next")}}a(W8,"liveUidGenerator");var z8="6ba7b810-9dad-11d1-80b4-00c04fd430c8";function H8(n){let e=0,t=(0,WS.v5)(n,z8);return{next:a(()=>{let r=`${n}#${e}`;return e+=1,(0,WS.v5)(r,t)},"next")}}a(H8,"seededUidGenerator")});var Mm=w(ec=>{"use strict";Object.defineProperty(ec,"__esModule",{value:!0});ec.registerResolver=Kr;ec.getResolver=K8;ec.getRegisteredResolverIds=Q8;ec.clearResolvers=X8;ec.installDefaultResolvers=Y8;var km=new Map;function Kr(n,e){km.set(n,e)}a(Kr,"registerResolver");function K8(n){return km.get(n)}a(K8,"getResolver");function Q8(){return Array.from(km.keys())}a(Q8,"getRegisteredResolverIds");function X8(){km.clear()}a(X8,"clearResolvers");function ea(n){return n<10?`0${n}`:String(n)}a(ea,"pad2");function Y8(){Kr("today",()=>new Date().toISOString().slice(0,10)),Kr("todayStart",()=>new Date(new Date().setHours(0,0,0,0)).toISOString()),Kr("target",n=>n.targetIRI?`"[[${n.targetIRI}]]"`:""),Kr("targetFolder",n=>{if(!n.targetFilePath)return"";let e=n.targetFilePath.replace(/^\/+/,""),t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}),Kr("randomUUIDv4",()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();throw new Error("randomUUIDv4 resolver requires crypto.randomUUID() \u2014 runtime is missing Node crypto / Web Crypto API.")}),Kr("nowTimestamp",()=>{let n=new Date;return`${n.getFullYear()}-${ea(n.getMonth()+1)}-${ea(n.getDate())}T${ea(n.getHours())}:${ea(n.getMinutes())}:${ea(n.getSeconds())}`}),Kr("nowDate",()=>{let n=new Date;return`${n.getFullYear()}-${ea(n.getMonth()+1)}-${ea(n.getDate())}`}),Kr("nowYear",()=>String(new Date().getFullYear())),Kr("nowMonth",()=>ea(new Date().getMonth()+1)),Kr("userInputLabel",n=>{let e=n.userInput?.label;return typeof e=="string"?e:""}),Kr("userInput",(n,e)=>{if(!e)return null;let t=n.userInput?.[e];return typeof t=="string"?t:t==null?null:String(t)}),Kr("targetProperty",(n,e)=>{if(!e||!n.targetFm)return null;let t=n.targetFm[e];return t==null?null:Array.isArray(t)?t.map(String):String(t)}),Kr("labelAsArray",n=>{let e=n.userInput?.label;return typeof e=="string"&&e.length>0?[e]:[]}),Kr("groundingTargetClass",n=>n.groundingTargetClassUid?`"[[${n.groundingTargetClassUid}]]"`:null),Kr("targetClassSelf",n=>{if(!n.targetFilePath)return null;let e=n.targetFilePath.replace(/^\/+/,""),r=e.slice(e.lastIndexOf("/")+1).replace(/\.md$/i,"");return r.length>0?`"[[${r}]]"`:null})}a(Y8,"installDefaultResolvers")});var zS=w(jm=>{"use strict";Object.defineProperty(jm,"__esModule",{value:!0});jm.resolveTemplateBody=Z8;jm.stripTemplateFrontmatter=eU;var _3=Mm();(0,_3.installDefaultResolvers)();var J8=/\$([A-Za-z][A-Za-z0-9_]*)/g;function Z8(n,e={}){return n.replace(J8,(t,r)=>{let i=(0,_3.getResolver)(r);if(i===void 0)return t;let s=i(e);return typeof s=="string"&&s.length>0?s:t})}a(Z8,"resolveTemplateBody");function eU(n){let e=n.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);return e?n.slice(e[0].length):n}a(eU,"stripTemplateFrontmatter")});var jf=w(Ol=>{"use strict";Object.defineProperty(Ol,"__esModule",{value:!0});Ol.registerOrderSpecLoader=tU;Ol.clearOrderSpecLoader=rU;Ol.loadDefaultSpec=nU;Ol.orderProperties=iU;var $m=null,ta,Um=!1;function tU(n){$m=n,ta=void 0,Um=!1}a(tU,"registerOrderSpecLoader");function rU(){$m=null,ta=void 0,Um=!1}a(rU,"clearOrderSpecLoader");function nU(){if(ta!==void 0)return ta;if(!$m)return ta=null,null;try{ta=$m()}catch(n){Um||(console.warn("[OrderSpecResolver] loader threw, falling back to insertion order:",n),Um=!0),ta=null}return ta}a(nU,"loadDefaultSpec");function iU(n,e){if(!e||e.head.length===0&&e.tail.length===0)return n;let t=Object.keys(n),r=new Set(e.head),i=new Set(e.tail),s=e.head.filter(u=>Object.prototype.hasOwnProperty.call(n,u)),o=e.tail.filter(u=>Object.prototype.hasOwnProperty.call(n,u)),c=t.filter(u=>!r.has(u)&&!i.has(u));e.middleStrategy==="alphabetical"&&c.sort((u,f)=>u.localeCompare(f));let l={};for(let u of s)l[u]=n[u];for(let u of c)l[u]=n[u];for(let u of o)l[u]=n[u];return l}a(iU,"orderProperties")});var ys=w(Bm=>{"use strict";Object.defineProperty(Bm,"__esModule",{value:!0});Bm.FrontmatterService=void 0;var w3=jf(),$f=class n{static{a(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}}parseObject(e){let t=this.parse(e);if(!t.exists)return null;let r={},i=t.content.split(/\r?\n/),s=null,o=null,c=a(()=>{s!==null&&o!==null&&(r[s]=o),s=null,o=null},"flushArray");for(let l of i){let u=/^ {2}- (.*)$/.exec(l);if(u){s!==null&&o!==null&&o.push(u[1].trim());continue}c();let f=/^([^:\s][^:]*):\s*(.*)$/.exec(l);if(!f)continue;let d=f[1].trim(),h=f[2].trim();h===""?(s=d,o=[]):r[d]=h}return c(),r}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 o=i.content;if(this.hasProperty(o,t)){let c=new RegExp(`${this.escapeRegex(t)}:.*(?:
|
|
@@ -625,7 +625,7 @@ Orphan requirements (${n.orphans.length}) \u2014 no @req binding (warning):`);fo
|
|
|
625
625
|
Duplicate bindings (${n.duplicates.length}) \u2014 uid claimed by >1 test (warning):`);for(let e of n.duplicates){console.error(` ${e.uid}:`);for(let t of e.occurrences)console.error(` ${t.file}:${t.line}`)}}n.unknownPriority>0&&console.error(`
|
|
626
626
|
Skipped floor check for ${n.unknownPriority} requirement(s) with unparseable priority (fail-open).`),n.clean?console.log(`
|
|
627
627
|
OK: no hard findings (dangling tags + binding-class floor are clean).`):console.error(`
|
|
628
|
-
FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s).`)}a(jse,"renderText");function nj(){return new pe("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage").requiredOption("--reqs <path>","Directory tree containing req__Requirement assets (a vault or a reqs assetspace clone)").option("--tests <path>","Test-corpus root scanned for @req:<uid> tags",".").option("--output <type>","Response format: text|json","text").option("--strict","Also exit 1 on orphan requirements",!1).action(async n=>{let e=n.output??"text";ne.setFormat(e);try{let t=(0,Ox.resolve)(n.reqs);if(!(0,Wu.existsSync)(t)||!(0,Wu.statSync)(t).isDirectory())throw new ze(t);let r=(0,Ox.resolve)(n.tests??".");if(!(0,Wu.existsSync)(r)||!(0,Wu.statSync)(r).isDirectory())throw new ze(r);let[i,s]=await Promise.all([Dse(t),Nse(r)]),o=kse(i,s);e==="json"?console.log(JSON.stringify(o,null,2)):jse(o),(!o.clean||n.strict===!0&&o.orphans.length>0)&&(process.exitCode=1)}catch(t){ne.handle(t)}})}a(nj,"requirementsAuditCommand");function ij(){let n=new pe("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(nj()),n}a(ij,"requirementsCommand");function sj(n){let e=new pe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.130.
|
|
628
|
+
FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s).`)}a(jse,"renderText");function nj(){return new pe("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage").requiredOption("--reqs <path>","Directory tree containing req__Requirement assets (a vault or a reqs assetspace clone)").option("--tests <path>","Test-corpus root scanned for @req:<uid> tags",".").option("--output <type>","Response format: text|json","text").option("--strict","Also exit 1 on orphan requirements",!1).action(async n=>{let e=n.output??"text";ne.setFormat(e);try{let t=(0,Ox.resolve)(n.reqs);if(!(0,Wu.existsSync)(t)||!(0,Wu.statSync)(t).isDirectory())throw new ze(t);let r=(0,Ox.resolve)(n.tests??".");if(!(0,Wu.existsSync)(r)||!(0,Wu.statSync)(r).isDirectory())throw new ze(r);let[i,s]=await Promise.all([Dse(t),Nse(r)]),o=kse(i,s);e==="json"?console.log(JSON.stringify(o,null,2)):jse(o),(!o.clean||n.strict===!0&&o.orphans.length>0)&&(process.exitCode=1)}catch(t){ne.handle(t)}})}a(nj,"requirementsAuditCommand");function ij(){let n=new pe("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(nj()),n}a(ij,"requirementsCommand");function sj(n){let e=new pe;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.130.8"),e.addCommand(Z4()),e.addCommand(lM()),e.addCommand(Kk()),e.addCommand(Jk()),e.addCommand(S4()),e.addCommand(t4()),e.addCommand(r4()),e.addCommand(T4()),e.addCommand(D4()),e.addCommand(N4()),e.addCommand(U4()),e.addCommand(X4()),e.addCommand(xM()),e.addCommand(VM()),e.addCommand(qM()),e.addCommand(zM()),e.addCommand(HM()),e.addCommand(YM()),e.addCommand(ej()),e.addCommand(FM()),e.addCommand($M()),e.addCommand(ij()),e}a(sj,"createProgram");sj().parse();0&&(module.exports={createProgram});
|
|
629
629
|
/*! Bundled license information:
|
|
630
630
|
|
|
631
631
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED