@kitelev/exocortex-cli 16.170.0 → 16.170.1
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.170.
|
|
2
|
+
// @kitelev/exocortex-cli v16.170.1
|
|
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 jl(`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 jl(`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 jl(`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}}};$l.SPARQLGenerator=e1});var Bl=E(Mn=>{"use strict";var uB=Mn&&Mn.__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]})),fB=Mn&&Mn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),nx=Mn&&Mn.__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"&&uB(t,e,r[i]);return fB(t,e),t}})();Object.defineProperty(Mn,"__esModule",{value:!0});Mn.QueryExecutor=Mn.ExoQLQueryExecutor=Mn.QueryExecutorError=void 0;var dB=Sw(),hB=Rm(),pB=$w(),mB=Bw(),gB=HC(),yB=KC(),_B=XC(),bB=Xw(),SB=ZC(),wB=tx(),vB=rx(),EB=ze(),TB=et(),AB=Sm(),Yr="http://www.w3.org/2001/XMLSchema#",IB=new Set([`${Yr}integer`,`${Yr}decimal`,`${Yr}float`,`${Yr}double`,`${Yr}nonPositiveInteger`,`${Yr}negativeInteger`,`${Yr}long`,`${Yr}int`,`${Yr}short`,`${Yr}byte`,`${Yr}nonNegativeInteger`,`${Yr}unsignedLong`,`${Yr}unsignedInt`,`${Yr}unsignedShort`,`${Yr}unsignedByte`,`${Yr}positiveInteger`]),Ul=class extends Error{static{a(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Mn.QueryExecutorError=Ul;var km=class{static{a(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new dB.BGPExecutor(e),this.filterExecutor=new hB.FilterExecutor,this.optionalExecutor=new pB.OptionalExecutor,this.unionExecutor=new mB.UnionExecutor,this.minusExecutor=new gB.MinusExecutor,this.valuesExecutor=new yB.ValuesExecutor,this.aggregateExecutor=new _B.AggregateExecutor,this.constructExecutor=new bB.ConstructExecutor,this.serviceExecutor=new SB.ServiceExecutor(t.serviceConfig),this.graphExecutor=new wB.GraphExecutor(e),this.sparqlGenerator=new vB.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 Ul(`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(()=>nx(vs())),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 EB.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(()=>nx(vs()));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 TB.Literal){let i=r.datatype?.value;if(i===`${Yr}dayTimeDuration`)try{return AB.DateTimeFunctions.parseDayTimeDuration(r.value)}catch{return r.value}if(i&&IB.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 Ul("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 Ul("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Mn.ExoQLQueryExecutor=km;Mn.QueryExecutor=km});var fx=E(fo=>{"use strict";var RB=fo&&fo.__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},OB=fo&&fo.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},t1;Object.defineProperty(fo,"__esModule",{value:!0});fo.CommandResolver=void 0;var CB=Xe(),xB=ol(),nr=ze(),qt=et(),ne=Xt(),ix=Zo(),sx=df(),PB=cl(),DB=Pf(),Vl=pb(),Mm=JO(),FB=_l(),LB=Sl(),NB=Bl(),ql=10,jm="exo__Asset",kB=ql+1,ox="08cec529-90eb-4d43-88de-ceecccea12b0",MB=ne.Namespace.EXOCMD.term("SubstitutionToken").value,ax=new Set(["today","tomorrow","todayStart","targetFolder","target","randomUUIDv4","nowTimestamp","nowDate","nowYear","nowMonth","userInputLabel","userInput","targetProperty","labelAsArray","groundingTargetClass","targetClassSelf"]);function jB(n,e){return`__SUBSTITUTE__${n}__${e}__`}a(jB,"buildSubstitutionMarker");function $B(n,e,t){let r=(0,PB.utf8ToBase64)(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`__SUBSTITUTE_P__${n}__${e}__${r}__`}a($B,"buildParameterisedMarker");var cx="3f28af98-c031-4718-8ba2-44ad0b012c52",UB=ne.Namespace.EXOCMD.term("TokenInvocation").value,lx="29e2c8f8-2d27-4e58-b467-2e85d46f8122",ux="universal-default-template",BB=new Set(["today","tomorrow","todayStart","nowTimestamp","nowDate","nowYear","nowMonth"]),r1=t1=class{static{a(this,"CommandResolver")}clearUniversalCache(){this._universalCacheReady=!1,this._universalCacheValue=null,(0,Mm.clearUniversalDefault)()}constructor(e,t=xB.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=r?await this.expandPrototypeChain(r):void 0,l=await this.expandClassHierarchy(t),u=new Map;for(let[p,_]of l){let y=await this.resolveForAsset(e,p,c);for(let S of y){let v=this.getBindingPriority(S.binding)===2?_:0,T=u.get(S.binding.id);(!T||v<T.depth)&&u.set(S.binding.id,{rc:S,depth:v})}}let f=new Set;for(let{rc:p}of u.values())if(p.binding.overrides)for(let _ of p.binding.overrides)f.add(_);let d=Array.from(u.entries()).filter(([p])=>!f.has(p)).map(([,p])=>p);d.sort((p,_)=>{let y=this.getBindingPriority(p.rc.binding),S=this.getBindingPriority(_.rc.binding);return y!==S?y-S:p.depth!==_.depth?p.depth-_.depth:(p.rc.binding.order??100)-(_.rc.binding.order??100)});let h=d.map(p=>p.rc);return this.multiCache.set(s,h),h}async expandClassHierarchy(e){let t=new Map;for(let c of e){if(c===jm){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===jm)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(jm)||s.set(jm,kB),s}async resolveForAsset(e,t,r){let i=typeof r=="string"?`s:${r}`:r?`c:${r.join("\0")}`:"",s=`${e}:${t}:${i}`,o=this.cache.get(s);if(o)return o;let c=typeof r=="string"?await this.expandPrototypeChain(r):r,l=await this.findBindings(t,c,e),u=[];for(let f of l){let d=await this.loadCommand(f.commandRef,{targetClass:f.targetClass});if(!d)continue;let h=f.precondition?{...d,precondition:f.precondition}:d;u.push({command:h,binding:f})}return u.sort((f,d)=>{let h=this.getBindingPriority(f.binding),p=this.getBindingPriority(d.binding);return h!==p?h-p:(f.binding.order??100)-(d.binding.order??100)}),this.cache.set(s,u),u}async loadCommand(e,t){let r=await this.findSubjectByUID(e);if(!r||(await this.tripleStore.match(r,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("Command"))).length===0)return null;let s=await this.getLiteralValue(r,ne.Namespace.EXO.term("Asset_label"))??"Unknown Command",o=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_labelTemplate")),c=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_icon")),l=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_confirmMessage")),u=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_successMessage")),f=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_category")),d=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_openInSameTab")),h=d!==null&&String(d).trim().toLowerCase()==="true",p=await this.loadLinkedPrecondition(r),_=await this.loadLinkedGrounding(r,0,t);return _?{id:e,name:s,labelTemplate:o??void 0,icon:c??void 0,precondition:p??void 0,grounding:_,confirmMessage:l??void 0,successMessage:u??void 0,category:f??void 0,openInSameTab:h||void 0}:null}async findBindings(e,t,r){let i=typeof t=="string"?await this.expandPrototypeChain(t):t,s=await this.tripleStore.match(void 0,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("CommandBinding")),o=[];for(let c of s){let l=c.subject,u=await this.loadBindingDefinition(l);u&&this.bindingMatches(u,e,i,r)&&o.push(u)}return o}async findPaletteEnabledCommands(){let e=await this.tripleStore.match(void 0,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("Command")),t=[],r=new Set;for(let i of e){let s=i.subject;if((await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Command_paletteEnabled")))?.toLowerCase()!=="true")continue;let c=await this.getLiteralValue(s,ne.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,ne.Namespace.EXOCMD.term("Command_paletteId")),f=await this.getLiteralValue(s,ne.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 FB.ExoQLParser().parse(r),c=new LB.ExoQLAlgebraTranslator().translate(s),u=await new NB.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 qt.Literal||h instanceof nr.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,ne.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetClass")),o=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!o&&!c)return null;let l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_variant")),d=f!==null?this.coerceVariant(f,t):void 0,h=await this.loadLinkedPreconditionFromProperty(e,ne.Namespace.EXOCMD.term("CommandBinding_precondition")),p=await this.loadLinkedStyle(e,t),_=await this.getLinkedUIDs(e,ne.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:_.length>0?_:void 0}}async loadLinkedStyle(e,t){let r=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("CommandBinding_style"),void 0);if(r.length>0){let s=r[0].object,o=null;if(s instanceof nr.IRI)o=s;else if(s instanceof qt.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,ne.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,ne.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",i=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_variant")),s=i!==null?this.coerceVariant(i,t):void 0,o=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_showIcon")),c=this.coerceBoolean(o),l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_labelClass")),u=l!==null?this.coerceLabelClass(l,t):void 0,f=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_ariaLabel")),d=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_tooltip")),h=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_keyboardShortcut")),p=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_source")),_=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:_,inline:!1}}coerceVariant(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.COMMAND_VARIANT_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle variant "${r}" not in whitelist [${Vl.COMMAND_VARIANT_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceLabelClass(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.LABEL_CLASS_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle labelClass "${r}" not in whitelist [${Vl.LABEL_CLASS_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceStyleSource(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.STYLE_SOURCE_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle source "${r}" not in whitelist [${Vl.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){if(e.targetAsset&&i&&this.matchesReference(e.targetAsset,i))return!0;if(e.targetPrototype&&r){for(let s of r)if(this.matchesReference(e.targetPrototype,s))return!0}return!!(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,ne.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 nr.IRI)s=i;else if(i instanceof qt.Literal){let h=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(h)}if(!s)return null;let o=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Precondition_hostFunction")),f=await this.tripleStore.match(s,ne.Namespace.EXOCMD.term("Precondition_query"),void 0),d;if(f.length>0){let h=f[0].object;if(h instanceof nr.IRI){let p=await this.getLiteralValue(h,ne.Namespace.EXO.term("Asset_uid"));p&&(d=p)}else h instanceof qt.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>=ql)return null;let i=await this.tripleStore.match(e,ne.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,ne.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 nr.IRI)return e;if(e instanceof qt.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>=ql)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",s=await this.resolveGroundingTypeReference(e);if(!s)return null;let o=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetProperty"));if(o&&this.looksLikeUUID(o)){let ae=await this.resolveLabelByUID(o);if(!ae)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=ae}if(s===ix.GroundingType.SERVICE_CALL){let ae=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_serviceId"));ae&&(o=ae)}let c=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueRef")),l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_targetValueLiteral")),u=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueSubstitution")),f=null;if(u&&this.looksLikeUUID(u)){let ae=await this.resolveLabelByUID(u);if(!ae)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=ae}else u&&(f=u);let d=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueQuery")),h=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_serviceCallPayload")),p=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_appendExpression")),_=await this.getObsidianWikilinkValue(e,ne.Namespace.EXOCMD.term("Grounding_isDefinedBy")),y=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),S=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetClass"));if(S&&!this.looksLikeUUID(S)){let ae=await this.findUidByLabel(S);ae&&(S=ae)}let v=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetPrototype")),T=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_targetFolder")),x=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_linkBackProperty")),O=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_inputSchema")),C=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_incrementBy")),L=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_shiftDelta")),ee;if(C!=null&&C!==""){let ae=Number.parseInt(String(C),10);Number.isFinite(ae)&&(ee=ae)}let V=await this.resolvePropertyDefaults(e,r),$=await this.resolveInheritanceRules(e,r),Y=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_propertyDefaults"));Y!==null&&Y!==""&&!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 N;s===ix.GroundingType.COMPOSITE&&(N=await this.loadCompositeSteps(e,t+1));let de;if(O)try{let ae=JSON.parse(O);ae?.properties&&(de=Object.entries(ae.properties).map(([Oe,ie])=>{let $e=ie.type,Ve=$e==="string"?"text":$e,K=ie.defaultValue!==void 0?ie.defaultValue:ie.default,oe={name:Oe,type:Ve,label:ie.title??Oe,required:Array.isArray(ae.required)&&ae.required.includes(Oe)};return K!=null&&(oe.defaultValue=String(K)),typeof ie.targetClassUid=="string"&&(oe.targetClassUid=ie.targetClassUid),oe}))}catch{}let ye=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_prefillLabelWithDate")),te=ye!==null&&String(ye).trim().toLowerCase()==="true",Re=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_labelTemplate")),X=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_direction")),ge;if(X!=null){let ae=String(X).trim().toLowerCase();ae==="forward"||ae==="rollback"?ge=ae:ae!==""&&this.logger.warn(`Grounding ${r}: exocmd__Grounding_direction value '${X}' is not 'forward' or 'rollback' \u2014 treating as undefined (will default to 'forward' at dispatch).`)}let se=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_bodyTemplate")),W=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_templateRef")),xe=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_cloneTargetBody")),be=xe!==null&&String(xe).trim().toLowerCase()==="true",re={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:y??void 0,steps:N,targetClass:S??void 0,targetPrototype:v??void 0,targetFolder:T??void 0,linkBackProperty:x??void 0,incrementBy:ee,shiftDelta:L??void 0,propertyDefault:V.length>0?V:void 0,inheritanceRule:$.length>0?$:void 0,isDefinedBy:_??void 0,prefillLabelWithDate:te||void 0,labelTemplate:Re??void 0,direction:ge,bodyTemplate:se??void 0,templateRef:W??void 0,cloneTargetBody:be||void 0};return de&&(re.inputSchema=de),re}async loadCompositeSteps(e,t){if(t>=ql)return[];let r=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let o=null;if(s.object instanceof nr.IRI)o=s.object;else if(s.object instanceof qt.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,ne.Namespace.EXOCMD.term("Grounding_propertyDefault")),i=await this.getUniversalCache();return i&&i.propertyDefaults.length>0?(0,Mm.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,ne.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,ne.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,Mm.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,ux,ne.Namespace.EXOCMD.term("Template_propertyDefault")),i=await this.resolveInheritanceRulesForSubject(t,ux,ne.Namespace.EXOCMD.term("Template_inheritanceRule"));return this._universalCacheValue={propertyDefaults:r,inheritanceRules:i},this._universalCacheValue}async findUniversalSingleton(){let e=ne.Namespace.EXOCMD.term("UniversalDefaultTemplate").value,t=await this.tripleStore.match(void 0,ne.Namespace.EXO.term("Instance_class"),void 0),r=[];for(let i of t){let s=!1;if(i.object instanceof nr.IRI)s=i.object.value===e||i.object.value.includes(lx);else if(i.object instanceof qt.Literal){let o=this.unwrapWikilink(i.object.value);s=o==="exocmd__UniversalDefaultTemplate"||o===lx}s&&i.subject instanceof nr.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,ne.Namespace.EXOCMD.term("Grounding_inheritanceRule")),i=await this.getUniversalCache();return i&&i.inheritanceRules.length>0?(0,Mm.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,ne.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,ne.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,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"),void 0),h,p;if(d.length>0){let O=await this.getObsidianName(l,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"));if(!O||!O.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(O)?(p=O,h=await this.resolveLabelByUID(O)??void 0):h=O}let _=await this.tripleStore.match(l,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassExclusion"),void 0),y=[],S=[],v=!1;for(let O of _){let C=null;if(O.object instanceof nr.IRI?C=this.iriToObsidianName(O.object.value)??O.object.value:O.object instanceof qt.Literal&&(C=this.unwrapWikilink(O.object.value)),!C){v=!0;continue}if(this.looksLikeUUID(C)){S.push(C);let L=await this.resolveLabelByUID(C);L&&y.push(L)}else y.push(C)}if(v){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 T=await this.getLiteralValue(l,ne.Namespace.EXOCMD.term("InheritanceRule_priority")),x=50;if(T!==null&&T!==""){let O=Number.parseInt(String(T),10);Number.isFinite(O)&&(x=O)}s.push({sourcePropertyName:u,targetPropertyName:f,targetClassCondition:h,targetClassConditionUid:p,targetClassExclusion:y,targetClassExclusionUids:S,priority:x})}return s}async resolveRefTripleObject(e){if(e instanceof nr.IRI)return e;if(e instanceof qt.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,ne.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 ax.has(c)?s!==void 0?$B(c,t,s):BB.has(c)?t1.parseTimeResolve(c):jB(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(ax).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"tomorrow":{let i=new Date(t);return i.setUTCDate(i.getUTCDate()+1),i.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,ne.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,ne.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,ne.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof nr.IRI){if(r.object.value===UB||r.object.value.includes(cx))return!0}else if(r.object instanceof qt.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__TokenInvocation"||i===cx)return!0}return!1}async assetIsSubstitutionToken(e){let t=await this.tripleStore.match(e,ne.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof nr.IRI){if(r.object.value===MB||r.object.value.includes(ox))return!0}else if(r.object instanceof qt.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__SubstitutionToken"||i===ox)return!0}return!1}async resolveGroundingTypeReference(e){let t=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("Grounding_type"),void 0);if(t.length===0)return null;let r=t[0].object;if(r instanceof nr.IRI)return(0,sx.resolveGroundingTypeFromIRI)(r.value);if(r instanceof qt.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,sx.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 expandPrototypeChain(e){if(!e||!this.normalizeWikilink(e))return[];let t=[e],r=new Set([this.normalizeWikilink(e).toLowerCase()]),i=e;for(let s=0;s<ql;s++){let o=this.extractUuidFromRef(i);if(!o)break;let c=null;try{let u=await this.findSubjectByUID(o);if(!u)break;c=await this.getLinkedValue(u,ne.Namespace.EXO.term("Asset_prototype"))}catch(u){this.logger.debug(this.capWarning(`[expandPrototypeChain] store lookup failed at hop ${s} for '${i}': ${String(u)}`));break}if(!c)break;let l=this.normalizeWikilink(c).toLowerCase();if(r.has(l))break;r.add(l),t.push(c),i=c}return t}extractUuidFromRef(e){let t=this.normalizeWikilink(e);if(this.looksLikeUUID(t))return t;let r=this.extractPathBasename(t);return r&&this.looksLikeUUID(r)?r: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,ne.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof qt.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 qt.Literal||i instanceof nr.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,ne.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,ne.Namespace.EXO.term("Asset_uid"));c&&o.add(c);let l=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_label"));l&&o.add(l);let u=a((h,p)=>{if(o.has(h))return;let _=r.get(h);(_===void 0||p<_)&&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:_}=h;if(_>=ql||i.has(p.value))continue;i.add(p.value);let y=await this.tripleStore.match(p,ne.Namespace.EXO.term("Class_superClass"),void 0);for(let S of y){let v=S.object;if(!(v instanceof nr.IRI))continue;let T=_+1,x=v.value.startsWith("obsidian://vault/"),O=this.iriToObsidianName(v.value);O&&u(O,T);let C=null;if(x?C=v:O&&(C=await this.resolveClassFileIRI(O)),!C)continue;let L=await this.getLiteralValue(C,ne.Namespace.EXO.term("Asset_uid"));L&&u(L,T),i.has(C.value)||f.push({fileIRI:C,depth:T})}}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,ne.Namespace.EXO.term("Asset_label"),void 0);for(let r of t)if(r.object instanceof qt.Literal&&r.object.value===e&&r.subject instanceof nr.IRI){let i=await this.tripleStore.match(r.subject,ne.Namespace.EXO.term("Asset_uid"),void 0);if(i.length>0&&i[0].object instanceof qt.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 nr.IRI){let s=await this.tripleStore.match(i,ne.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof qt.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof qt.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 nr.IRI){let c=await this.tripleStore.match(o,ne.Namespace.EXO.term("Asset_uid"),void 0);if(c.length>0&&c[0].object instanceof qt.Literal)i.push(c[0].object.value);else{let l=o.value.split("/").pop()?.replace(".md","");l&&i.push(l)}}else if(o instanceof qt.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 qt.Literal?this.normalizeWikilink(i.value):i instanceof nr.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 qt.Literal?this.unwrapWikilink(i.value):i instanceof nr.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 qt.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof nr.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,ne.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){return(0,DB.iriToObsidianName)(e)}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};fo.CommandResolver=r1;fo.CommandResolver=r1=t1=RB([(0,CB.injectable)(),OB("design:paramtypes",[Object,Object])],r1)});var i1=E(n1=>{"use strict";Object.defineProperty(n1,"__esModule",{value:!0});n1.validateExoQLAllowlist=VB;var $m=Uf();function VB(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 $m.ExoQLForbiddenKeywordError("LOAD");throw new $m.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 $m.ExoQLForbiddenKeywordError("FROM")}if(Array.isArray(e.where))for(let t of e.where)Um(t);if(Array.isArray(e.template))for(let t of e.template)Um(t)}}a(VB,"validateExoQLAllowlist");function Um(n){if(!n||typeof n!="object")return;if(n.type==="service")throw new $m.ExoQLForbiddenKeywordError("SERVICE");if(Array.isArray(n.patterns))for(let t of n.patterns)Um(t);let e=n.where;if(Array.isArray(e))for(let t of e)Um(t)}a(Um,"walkPatternForBannedKeywords")});var s1=E(Bm=>{"use strict";Object.defineProperty(Bm,"__esModule",{value:!0});Bm.DEFAULT_EVAL_CONFIG=void 0;Bm.DEFAULT_EVAL_CONFIG=Object.freeze({enabled:!0,maxNestedEvalCount:100,maxAggregateEvalMillis:1e4})});var Vm=E(o1=>{"use strict";Object.defineProperty(o1,"__esModule",{value:!0});o1.evaluateWithExoEval=YB;var qB=_l(),GB=Sl(),WB=Bl(),HB=i1(),zB=s1(),KB=Uf();async function YB(n,e={}){if(typeof n!="string")throw new TypeError("evaluateWithExoEval: sparql must be a string");let r=new qB.ExoQLParser().parse(n);if((0,HB.validateExoQLAllowlist)(r),!{...zB.DEFAULT_EVAL_CONFIG,...e.config??{}}.enabled)throw new KB.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 GB.ExoQLAlgebraTranslator().translate(r),l=new WB.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(YB,"evaluateWithExoEval")});var Vf=E(qm=>{"use strict";Object.defineProperty(qm,"__esModule",{value:!0});qm.liveClock=QB;qm.frozenClock=XB;function QB(){return{now:a(()=>new Date,"now")}}a(QB,"liveClock");function XB(n){let e=new Date(n);return{now:a(()=>new Date(e.getTime()),"now")}}a(XB,"frozenClock")});var hx=E(ho=>{"use strict";var JB=ho&&ho.__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},ZB=ho&&ho.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},qf;Object.defineProperty(ho,"__esModule",{value:!0});ho.PreconditionEvaluator=void 0;var e8=Xe(),t8=_l(),r8=Sl(),dx=Bl(),n8=Vm(),i8=Vf(),Gf=qf=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,i8.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,n8.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,qf.SENTINEL_IRI),i=new t8.ExoQLParser().parse(t),o=new r8.ExoQLAlgebraTranslator().translate(i);return new dx.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(qf.SENTINEL_IRI,t));return await new dx.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()+qf.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,_=new Date(Date.UTC(c,l,u-p)),y=_.toISOString().slice(0,10),v=new Date(_.getTime()-10080*60*1e3).toISOString().slice(0,10),T=`${c}-${String(l+1).padStart(2,"0")}-01`,x=l===0?11:l-1,C=`${l===0?c-1:c}-${String(x+1).padStart(2,"0")}-01`,L=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${i}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${y}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${v}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${T}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${C}"^^xsd:date`).replace(/\$thisYearStart/g,`"${L}"^^xsd:date`).replace(/\$today/g,`"${s}"^^xsd:date`)}};ho.PreconditionEvaluator=Gf;Gf.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Gf.ALMATY_OFFSET_MS=300*60*1e3;ho.PreconditionEvaluator=Gf=qf=JB([(0,e8.injectable)(),ZB("design:paramtypes",[Object,Object,Object])],Gf)});var px=E(po=>{"use strict";Object.defineProperty(po,"__esModule",{value:!0});po.hasUidFilename=po.hasNonUidFilename=void 0;po.registerDefaultHostFunctions=a8;var s8=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");po.hasNonUidFilename=s8;var o8=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");po.hasUidFilename=o8;function a8(n){n.registerHostFunction("hasNonUidFilename",po.hasNonUidFilename),n.registerHostFunction("hasUidFilename",po.hasUidFilename)}a(a8,"registerDefaultHostFunctions")});var Wm=E(Gm=>{"use strict";Object.defineProperty(Gm,"__esModule",{value:!0});Gm.liveUidGenerator=c8;Gm.seededUidGenerator=u8;var a1=Ai();function c8(){return{next:a(()=>(0,a1.v4)(),"next")}}a(c8,"liveUidGenerator");var l8="6ba7b810-9dad-11d1-80b4-00c04fd430c8";function u8(n){let e=0,t=(0,a1.v5)(n,l8);return{next:a(()=>{let r=`${n}#${e}`;return e+=1,(0,a1.v5)(r,t)},"next")}}a(u8,"seededUidGenerator")});var Km=E(da=>{"use strict";Object.defineProperty(da,"__esModule",{value:!0});da.registerResolver=ur;da.getResolver=f8;da.isResolverModifierAware=d8;da.getRegisteredResolverIds=h8;da.clearResolvers=p8;da.installDefaultResolvers=T8;var zm=new Map,c1=new Set;function ur(n,e,t=!1){zm.set(n,e),t&&c1.add(n)}a(ur,"registerResolver");function f8(n){return zm.get(n)}a(f8,"getResolver");function d8(n){return c1.has(n)}a(d8,"isResolverModifierAware");function h8(){return Array.from(zm.keys())}a(h8,"getRegisteredResolverIds");function p8(){zm.clear(),c1.clear()}a(p8,"clearResolvers");function wn(n){return n<10?`0${n}`:String(n)}a(wn,"pad2");var m8=["January","February","March","April","May","June","July","August","September","October","November","December"],g8=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],y8=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],_8=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function b8(n){let e=["th","st","nd","rd"],t=n%100;return`${n}${e[(t-20)%10]||e[t]||e[0]}`}a(b8,"ordinalDay");var S8=/YYYY|YY|MMMM|MMM|MM|M|Do|DD|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|A|a/g;function w8(n,e){let t=(n.getHours()+11)%12+1;return e.replace(S8,r=>{switch(r){case"YYYY":return String(n.getFullYear());case"YY":return wn(n.getFullYear()%100);case"MMMM":return m8[n.getMonth()];case"MMM":return g8[n.getMonth()];case"MM":return wn(n.getMonth()+1);case"M":return String(n.getMonth()+1);case"Do":return b8(n.getDate());case"DD":return wn(n.getDate());case"D":return String(n.getDate());case"dddd":return y8[n.getDay()];case"ddd":return _8[n.getDay()];case"HH":return wn(n.getHours());case"H":return String(n.getHours());case"hh":return wn(t);case"h":return String(t);case"mm":return wn(n.getMinutes());case"m":return String(n.getMinutes());case"ss":return wn(n.getSeconds());case"s":return String(n.getSeconds());case"A":return n.getHours()<12?"AM":"PM";case"a":return n.getHours()<12?"am":"pm";default:return r}})}a(w8,"formatDate");function mx(n,e,t){let r=n.getDate(),i=new Date(n.getTime());i.setDate(1),t==="M"?i.setMonth(i.getMonth()+e):i.setFullYear(i.getFullYear()+e);let s=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();return i.setDate(Math.min(r,s)),i}a(mx,"addMonthsClamped");function v8(n,e){if(!e)return n;let t=e.match(/^([+-])(\d+)([dwMy])?$/);if(!t)return n;let r=(t[1]==="-"?-1:1)*parseInt(t[2],10),i=t[3]??"d",s=new Date(n.getTime());switch(i){case"d":s.setDate(s.getDate()+r);break;case"w":s.setDate(s.getDate()+r*7);break;case"M":s=mx(s,r,"M");break;case"y":s=mx(s,r,"y");break}return isNaN(s.getTime())?n:s}a(v8,"applyDateOffset");function E8(n){if(!n)return{offset:null,format:null};let e=n.indexOf(":");if(e<0)return{offset:n,format:null};let t=n.slice(0,e),r=n.slice(e+1);return{offset:t||null,format:r||null}}a(E8,"parseDateModifier");function Hm(n,e){return(t,r)=>{let{offset:i,format:s}=E8(r),o=new Date;return n!==0&&o.setDate(o.getDate()+n),o=v8(o,i),w8(o,s??e)}}a(Hm,"makeDateResolver");function T8(){ur("today",()=>new Date().toISOString().slice(0,10)),ur("todayStart",()=>new Date(new Date().setHours(0,0,0,0)).toISOString()),ur("date",Hm(0,"YYYY-MM-DD"),!0),ur("now",Hm(0,"YYYY-MM-DDTHH:mm:ss"),!0),ur("tomorrow",Hm(1,"YYYY-MM-DD"),!0),ur("yesterday",Hm(-1,"YYYY-MM-DD"),!0),ur("target",n=>n.targetIRI?`"[[${n.targetIRI}]]"`:""),ur("targetFolder",n=>{if(!n.targetFilePath)return"";let e=n.targetFilePath.replace(/^\/+/,""),t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}),ur("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.")}),ur("nowTimestamp",()=>{let n=new Date;return`${n.getFullYear()}-${wn(n.getMonth()+1)}-${wn(n.getDate())}T${wn(n.getHours())}:${wn(n.getMinutes())}:${wn(n.getSeconds())}`}),ur("nowDate",()=>{let n=new Date;return`${n.getFullYear()}-${wn(n.getMonth()+1)}-${wn(n.getDate())}`}),ur("nowYear",()=>String(new Date().getFullYear())),ur("nowMonth",()=>wn(new Date().getMonth()+1)),ur("userInputLabel",n=>{let e=n.userInput?.label;return typeof e=="string"?e:""}),ur("userInput",(n,e)=>{if(!e)return null;let t=n.userInput?.[e];return typeof t=="string"?t:t==null?null:String(t)}),ur("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)}),ur("labelAsArray",n=>{let e=n.userInput?.label;return typeof e=="string"&&e.length>0?[e]:[]}),ur("groundingTargetClass",n=>n.groundingTargetClassUid?`"[[${n.groundingTargetClassUid}]]"`:null),ur("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(T8,"installDefaultResolvers")});var u1=E(Ym=>{"use strict";Object.defineProperty(Ym,"__esModule",{value:!0});Ym.resolveTemplateBody=I8;Ym.stripTemplateFrontmatter=R8;var l1=Km();(0,l1.installDefaultResolvers)();var A8=/\$([A-Za-z][A-Za-z0-9_]*)((?:[+-]\d+[dwMy])?(?::[A-Za-z0-9:./-]+)?)/g;function I8(n,e={}){return n.replace(A8,(t,r,i)=>{let s=(0,l1.getResolver)(r);if(s===void 0)return t;let o=s(e,i.length>0?i:void 0);return typeof o!="string"||o.length===0?t:(0,l1.isResolverModifierAware)(r)?o:o+i})}a(I8,"resolveTemplateBody");function R8(n){let e=n.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);return e?n.slice(e[0].length):n}a(R8,"stripTemplateFrontmatter")});var Wf=E(Gl=>{"use strict";Object.defineProperty(Gl,"__esModule",{value:!0});Gl.registerOrderSpecLoader=O8;Gl.clearOrderSpecLoader=C8;Gl.loadDefaultSpec=x8;Gl.orderProperties=P8;var Qm=null,ha,Xm=!1;function O8(n){Qm=n,ha=void 0,Xm=!1}a(O8,"registerOrderSpecLoader");function C8(){Qm=null,ha=void 0,Xm=!1}a(C8,"clearOrderSpecLoader");function x8(){if(ha!==void 0)return ha;if(!Qm)return ha=null,null;try{ha=Qm()}catch(n){Xm||(console.warn("[OrderSpecResolver] loader threw, falling back to insertion order:",n),Xm=!0),ha=null}return ha}a(x8,"loadDefaultSpec");function P8(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(P8,"orderProperties")});var Jm=E(gc=>{"use strict";Object.defineProperty(gc,"__esModule",{value:!0});gc.STRING_SCALAR_PROPERTIES=void 0;gc.needsYamlQuoting=gx;gc.quoteYamlString=yx;gc.serializeYamlScalar=B8;var D8=/^[-!&*?|>%@`"'#,[\]{}]/,F8=/[\u0000-\u001f\u007f]/,L8=/^(?:true|True|TRUE|false|False|FALSE)$/,N8=/^(?:null|Null|NULL|~)$/,k8=/^[-+]?(?:0b[01_]+|0o[0-7_]+|0x[0-9a-fA-F_]+|[0-9][0-9_]*)$/,M8=/^(?:[-+]?[0-9][0-9_]*(?:\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$/,j8=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;gc.STRING_SCALAR_PROPERTIES=new Set(["exo__Asset_label","aliases"]);function $8(n){if(n.length<2||!n.startsWith('"')||!n.endsWith('"'))return!1;let e=n.slice(1,-1);for(let t=0;t<e.length;t++){if(e[t]==="\\"){if(t+1>=e.length)return!1;t++;continue}if(e[t]==='"')return!1}return!0}a($8,"isCompleteDoubleQuotedScalar");function U8(n){return L8.test(n)||N8.test(n)||k8.test(n)||M8.test(n)||j8.test(n)}a(U8,"looksLikeNonStringScalar");function gx(n,e=!1){return n===""?!0:$8(n)?!1:!!(n!==n.trim()||/:(\s|$)/.test(n)||/\s#/.test(n)||D8.test(n)||F8.test(n)||e&&U8(n))}a(gx,"needsYamlQuoting");function yx(n){let e="";for(let t=0;t<n.length;t++){let r=n[t],i=n.charCodeAt(t);r==="\\"?e+="\\\\":r==='"'?e+='\\"':r===`
|
|
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 jl(`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}}};$l.SPARQLGenerator=e1});var Bl=E(Mn=>{"use strict";var uB=Mn&&Mn.__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]})),fB=Mn&&Mn.__setModuleDefault||(Object.create?(function(n,e){Object.defineProperty(n,"default",{enumerable:!0,value:e})}):function(n,e){n.default=e}),nx=Mn&&Mn.__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"&&uB(t,e,r[i]);return fB(t,e),t}})();Object.defineProperty(Mn,"__esModule",{value:!0});Mn.QueryExecutor=Mn.ExoQLQueryExecutor=Mn.QueryExecutorError=void 0;var dB=Sw(),hB=Rm(),pB=$w(),mB=Bw(),gB=HC(),yB=KC(),_B=XC(),bB=Xw(),SB=ZC(),wB=tx(),vB=rx(),EB=ze(),TB=et(),AB=Sm(),Yr="http://www.w3.org/2001/XMLSchema#",IB=new Set([`${Yr}integer`,`${Yr}decimal`,`${Yr}float`,`${Yr}double`,`${Yr}nonPositiveInteger`,`${Yr}negativeInteger`,`${Yr}long`,`${Yr}int`,`${Yr}short`,`${Yr}byte`,`${Yr}nonNegativeInteger`,`${Yr}unsignedLong`,`${Yr}unsignedInt`,`${Yr}unsignedShort`,`${Yr}unsignedByte`,`${Yr}positiveInteger`]),Ul=class extends Error{static{a(this,"QueryExecutorError")}constructor(e,t){super(e,t?{cause:t}:void 0),this.name="QueryExecutorError"}};Mn.QueryExecutorError=Ul;var km=class{static{a(this,"ExoQLQueryExecutor")}constructor(e,t={}){this.tripleStore=e,this.bgpExecutor=new dB.BGPExecutor(e),this.filterExecutor=new hB.FilterExecutor,this.optionalExecutor=new pB.OptionalExecutor,this.unionExecutor=new mB.UnionExecutor,this.minusExecutor=new gB.MinusExecutor,this.valuesExecutor=new yB.ValuesExecutor,this.aggregateExecutor=new _B.AggregateExecutor,this.constructExecutor=new bB.ConstructExecutor,this.serviceExecutor=new SB.ServiceExecutor(t.serviceConfig),this.graphExecutor=new wB.GraphExecutor(e),this.sparqlGenerator=new vB.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 Ul(`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(()=>nx(vs())),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 EB.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(()=>nx(vs()));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 TB.Literal){let i=r.datatype?.value;if(i===`${Yr}dayTimeDuration`)try{return AB.DateTimeFunctions.parseDayTimeDuration(r.value)}catch{return r.value}if(i&&IB.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 Ul("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 Ul("executeAsk requires an ASK operation");for await(let t of this.execute(e.where))return!0;return!1}};Mn.ExoQLQueryExecutor=km;Mn.QueryExecutor=km});var fx=E(fo=>{"use strict";var RB=fo&&fo.__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},OB=fo&&fo.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},t1;Object.defineProperty(fo,"__esModule",{value:!0});fo.CommandResolver=void 0;var CB=Xe(),xB=ol(),nr=ze(),qt=et(),ne=Xt(),ix=Zo(),sx=df(),PB=cl(),DB=Pf(),Vl=pb(),Mm=JO(),FB=_l(),LB=Sl(),NB=Bl(),ql=10,jm="exo__Asset",kB=ql+1,ox="08cec529-90eb-4d43-88de-ceecccea12b0",MB=ne.Namespace.EXOCMD.term("SubstitutionToken").value,ax=new Set(["today","tomorrow","todayStart","targetFolder","target","randomUUIDv4","nowTimestamp","nowDate","nowYear","nowMonth","userInputLabel","userInput","targetProperty","labelAsArray","groundingTargetClass","targetClassSelf"]);function jB(n,e){return`__SUBSTITUTE__${n}__${e}__`}a(jB,"buildSubstitutionMarker");function $B(n,e,t){let r=(0,PB.utf8ToBase64)(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`__SUBSTITUTE_P__${n}__${e}__${r}__`}a($B,"buildParameterisedMarker");var cx="3f28af98-c031-4718-8ba2-44ad0b012c52",UB=ne.Namespace.EXOCMD.term("TokenInvocation").value,lx="29e2c8f8-2d27-4e58-b467-2e85d46f8122",ux="universal-default-template",BB=new Set(["today","tomorrow","todayStart","nowTimestamp","nowDate","nowYear","nowMonth"]),r1=t1=class{static{a(this,"CommandResolver")}clearUniversalCache(){this._universalCacheReady=!1,this._universalCacheValue=null,(0,Mm.clearUniversalDefault)()}constructor(e,t=xB.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=r?await this.expandPrototypeChain(r):void 0,l=await this.expandClassHierarchy(t),u=new Map;for(let[p,_]of l){let y=await this.resolveForAsset(e,p,c);for(let S of y){let v=this.getBindingPriority(S.binding)===2?_:0,T=u.get(S.binding.id);(!T||v<T.depth)&&u.set(S.binding.id,{rc:S,depth:v})}}let f=new Set;for(let{rc:p}of u.values())if(p.binding.overrides)for(let _ of p.binding.overrides)f.add(_);let d=Array.from(u.entries()).filter(([p])=>!f.has(p)).map(([,p])=>p);d.sort((p,_)=>{let y=this.getBindingPriority(p.rc.binding),S=this.getBindingPriority(_.rc.binding);return y!==S?y-S:p.depth!==_.depth?p.depth-_.depth:(p.rc.binding.order??100)-(_.rc.binding.order??100)});let h=d.map(p=>p.rc);return this.multiCache.set(s,h),h}async expandClassHierarchy(e){let t=new Map;for(let c of e){if(c===jm){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===jm)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(jm)||s.set(jm,kB),s}async resolveForAsset(e,t,r){let i=typeof r=="string"?`s:${r}`:r?`c:${r.join("\0")}`:"",s=`${e}:${t}:${i}`,o=this.cache.get(s);if(o)return o;let c=typeof r=="string"?await this.expandPrototypeChain(r):r,l=await this.findBindings(t,c,e),u=[];for(let f of l){let d=await this.loadCommand(f.commandRef,{targetClass:f.targetClass});if(!d)continue;let h=f.precondition?{...d,precondition:f.precondition}:d;u.push({command:h,binding:f})}return u.sort((f,d)=>{let h=this.getBindingPriority(f.binding),p=this.getBindingPriority(d.binding);return h!==p?h-p:(f.binding.order??100)-(d.binding.order??100)}),this.cache.set(s,u),u}async loadCommand(e,t){let r=await this.findSubjectByUID(e);if(!r||(await this.tripleStore.match(r,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("Command"))).length===0)return null;let s=await this.getLiteralValue(r,ne.Namespace.EXO.term("Asset_label"))??"Unknown Command",o=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_labelTemplate")),c=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_icon")),l=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_confirmMessage")),u=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_successMessage")),f=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_category")),d=await this.getLiteralValue(r,ne.Namespace.EXOCMD.term("Command_openInSameTab")),h=d!==null&&String(d).trim().toLowerCase()==="true",p=await this.loadLinkedPrecondition(r),_=await this.loadLinkedGrounding(r,0,t);return _?{id:e,name:s,labelTemplate:o??void 0,icon:c??void 0,precondition:p??void 0,grounding:_,confirmMessage:l??void 0,successMessage:u??void 0,category:f??void 0,openInSameTab:h||void 0}:null}async findBindings(e,t,r){let i=typeof t=="string"?await this.expandPrototypeChain(t):t,s=await this.tripleStore.match(void 0,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("CommandBinding")),o=[];for(let c of s){let l=c.subject,u=await this.loadBindingDefinition(l);u&&this.bindingMatches(u,e,i,r)&&o.push(u)}return o}async findPaletteEnabledCommands(){let e=await this.tripleStore.match(void 0,ne.Namespace.RDF.term("type"),ne.Namespace.EXOCMD.term("Command")),t=[],r=new Set;for(let i of e){let s=i.subject;if((await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Command_paletteEnabled")))?.toLowerCase()!=="true")continue;let c=await this.getLiteralValue(s,ne.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,ne.Namespace.EXOCMD.term("Command_paletteId")),f=await this.getLiteralValue(s,ne.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 FB.ExoQLParser().parse(r),c=new LB.ExoQLAlgebraTranslator().translate(s),u=await new NB.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 qt.Literal||h instanceof nr.IRI?h.value:String(h):""}catch{return""}}async loadBindingDefinition(e){let t=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",i=await this.getLinkedUID(e,ne.Namespace.EXOCMD.term("CommandBinding_command"));if(!i)return null;let s=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetClass")),o=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetPrototype")),c=await this.getLinkedValue(e,ne.Namespace.EXOCMD.term("CommandBinding_targetAsset"));if(!s&&!o&&!c)return null;let l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_position")),u=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_order")),f=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBinding_variant")),d=f!==null?this.coerceVariant(f,t):void 0,h=await this.loadLinkedPreconditionFromProperty(e,ne.Namespace.EXOCMD.term("CommandBinding_precondition")),p=await this.loadLinkedStyle(e,t),_=await this.getLinkedUIDs(e,ne.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:_.length>0?_:void 0}}async loadLinkedStyle(e,t){let r=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("CommandBinding_style"),void 0);if(r.length>0){let s=r[0].object,o=null;if(s instanceof nr.IRI)o=s;else if(s instanceof qt.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,ne.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,ne.Namespace.EXO.term("Asset_uid"));if(!t)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",i=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_variant")),s=i!==null?this.coerceVariant(i,t):void 0,o=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_showIcon")),c=this.coerceBoolean(o),l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_labelClass")),u=l!==null?this.coerceLabelClass(l,t):void 0,f=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_ariaLabel")),d=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_tooltip")),h=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_keyboardShortcut")),p=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("CommandBindingStyle_source")),_=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:_,inline:!1}}coerceVariant(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.COMMAND_VARIANT_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle variant "${r}" not in whitelist [${Vl.COMMAND_VARIANT_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceLabelClass(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.LABEL_CLASS_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle labelClass "${r}" not in whitelist [${Vl.LABEL_CLASS_VALUES.join(",")}]; dropped (asset ${t})`))}}coerceStyleSource(e,t){if(e==null)return;let r=String(e).trim().toLowerCase();if(r!==""){if(Vl.STYLE_SOURCE_VALUES.includes(r))return r;this.logger.warn(this.capWarning(`CommandBindingStyle source "${r}" not in whitelist [${Vl.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){if(e.targetAsset&&i&&this.matchesReference(e.targetAsset,i))return!0;if(e.targetPrototype&&r){for(let s of r)if(this.matchesReference(e.targetPrototype,s))return!0}return!!(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,ne.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 nr.IRI)s=i;else if(i instanceof qt.Literal){let h=this.normalizeWikilink(i.value);s=await this.findSubjectByUID(h)}if(!s)return null;let o=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_uid")),c=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_label"))??"",l=await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Precondition_sparqlAsk")),u=await this.getLiteralValue(s,ne.Namespace.EXOCMD.term("Precondition_hostFunction")),f=await this.tripleStore.match(s,ne.Namespace.EXOCMD.term("Precondition_query"),void 0),d;if(f.length>0){let h=f[0].object;if(h instanceof nr.IRI){let p=await this.getLiteralValue(h,ne.Namespace.EXO.term("Asset_uid"));p&&(d=p)}else h instanceof qt.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>=ql)return null;let i=await this.tripleStore.match(e,ne.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,ne.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 nr.IRI)return e;if(e instanceof qt.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>=ql)return null;let r=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_uid"));if(!r)return null;let i=await this.getLiteralValue(e,ne.Namespace.EXO.term("Asset_label"))??"",s=await this.resolveGroundingTypeReference(e);if(!s)return null;let o=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetProperty"));if(o&&this.looksLikeUUID(o)){let ae=await this.resolveLabelByUID(o);if(!ae)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=ae}if(s===ix.GroundingType.SERVICE_CALL){let ae=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_serviceId"));ae&&(o=ae)}let c=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueRef")),l=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_targetValueLiteral")),u=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueSubstitution")),f=null;if(u&&this.looksLikeUUID(u)){let ae=await this.resolveLabelByUID(u);if(!ae)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=ae}else u&&(f=u);let d=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetValueQuery")),h=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_serviceCallPayload")),p=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_appendExpression")),_=await this.getObsidianWikilinkValue(e,ne.Namespace.EXOCMD.term("Grounding_isDefinedBy")),y=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_sparqlUpdate")),S=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetClass"));if(S&&!this.looksLikeUUID(S)){let ae=await this.findUidByLabel(S);ae&&(S=ae)}let v=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_targetPrototype")),T=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_targetFolder")),x=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_linkBackProperty")),O=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_inputSchema")),C=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_incrementBy")),L=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_shiftDelta")),ee;if(C!=null&&C!==""){let ae=Number.parseInt(String(C),10);Number.isFinite(ae)&&(ee=ae)}let V=await this.resolvePropertyDefaults(e,r),$=await this.resolveInheritanceRules(e,r),Y=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_propertyDefaults"));Y!==null&&Y!==""&&!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 N;s===ix.GroundingType.COMPOSITE&&(N=await this.loadCompositeSteps(e,t+1));let de;if(O)try{let ae=JSON.parse(O);ae?.properties&&(de=Object.entries(ae.properties).map(([Oe,ie])=>{let $e=ie.type,Ve=$e==="string"?"text":$e,K=ie.defaultValue!==void 0?ie.defaultValue:ie.default,oe={name:Oe,type:Ve,label:ie.title??Oe,required:Array.isArray(ae.required)&&ae.required.includes(Oe)};return K!=null&&(oe.defaultValue=String(K)),typeof ie.targetClassUid=="string"&&(oe.targetClassUid=ie.targetClassUid),oe}))}catch{}let ye=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_prefillLabelWithDate")),te=ye!==null&&String(ye).trim().toLowerCase()==="true",Re=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_labelTemplate")),X=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_direction")),ge;if(X!=null){let ae=String(X).trim().toLowerCase();ae==="forward"||ae==="rollback"?ge=ae:ae!==""&&this.logger.warn(`Grounding ${r}: exocmd__Grounding_direction value '${X}' is not 'forward' or 'rollback' \u2014 treating as undefined (will default to 'forward' at dispatch).`)}let se=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_bodyTemplate")),W=await this.getObsidianName(e,ne.Namespace.EXOCMD.term("Grounding_templateRef")),xe=await this.getLiteralValue(e,ne.Namespace.EXOCMD.term("Grounding_cloneTargetBody")),be=xe!==null&&String(xe).trim().toLowerCase()==="true",re={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:y??void 0,steps:N,targetClass:S??void 0,targetPrototype:v??void 0,targetFolder:T??void 0,linkBackProperty:x??void 0,incrementBy:ee,shiftDelta:L??void 0,propertyDefault:V.length>0?V:void 0,inheritanceRule:$.length>0?$:void 0,isDefinedBy:_??void 0,prefillLabelWithDate:te||void 0,labelTemplate:Re??void 0,direction:ge,bodyTemplate:se??void 0,templateRef:W??void 0,cloneTargetBody:be||void 0};return de&&(re.inputSchema=de),re}async loadCompositeSteps(e,t){if(t>=ql)return[];let r=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("Grounding_steps"),void 0),i=[];for(let s of r){let o=null;if(s.object instanceof nr.IRI)o=s.object;else if(s.object instanceof qt.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,ne.Namespace.EXOCMD.term("Grounding_propertyDefault")),i=await this.getUniversalCache();return i&&i.propertyDefaults.length>0?(0,Mm.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,ne.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,ne.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,Mm.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,ux,ne.Namespace.EXOCMD.term("Template_propertyDefault")),i=await this.resolveInheritanceRulesForSubject(t,ux,ne.Namespace.EXOCMD.term("Template_inheritanceRule"));return this._universalCacheValue={propertyDefaults:r,inheritanceRules:i},this._universalCacheValue}async findUniversalSingleton(){let e=ne.Namespace.EXOCMD.term("UniversalDefaultTemplate").value,t=await this.tripleStore.match(void 0,ne.Namespace.EXO.term("Instance_class"),void 0),r=[];for(let i of t){let s=!1;if(i.object instanceof nr.IRI)s=i.object.value===e||i.object.value.includes(lx);else if(i.object instanceof qt.Literal){let o=this.unwrapWikilink(i.object.value);s=o==="exocmd__UniversalDefaultTemplate"||o===lx}s&&i.subject instanceof nr.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,ne.Namespace.EXOCMD.term("Grounding_inheritanceRule")),i=await this.getUniversalCache();return i&&i.inheritanceRules.length>0?(0,Mm.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,ne.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,ne.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,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"),void 0),h,p;if(d.length>0){let O=await this.getObsidianName(l,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassCondition"));if(!O||!O.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(O)?(p=O,h=await this.resolveLabelByUID(O)??void 0):h=O}let _=await this.tripleStore.match(l,ne.Namespace.EXOCMD.term("InheritanceRule_targetClassExclusion"),void 0),y=[],S=[],v=!1;for(let O of _){let C=null;if(O.object instanceof nr.IRI?C=this.iriToObsidianName(O.object.value)??O.object.value:O.object instanceof qt.Literal&&(C=this.unwrapWikilink(O.object.value)),!C){v=!0;continue}if(this.looksLikeUUID(C)){S.push(C);let L=await this.resolveLabelByUID(C);L&&y.push(L)}else y.push(C)}if(v){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 T=await this.getLiteralValue(l,ne.Namespace.EXOCMD.term("InheritanceRule_priority")),x=50;if(T!==null&&T!==""){let O=Number.parseInt(String(T),10);Number.isFinite(O)&&(x=O)}s.push({sourcePropertyName:u,targetPropertyName:f,targetClassCondition:h,targetClassConditionUid:p,targetClassExclusion:y,targetClassExclusionUids:S,priority:x})}return s}async resolveRefTripleObject(e){if(e instanceof nr.IRI)return e;if(e instanceof qt.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,ne.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 ax.has(c)?s!==void 0?$B(c,t,s):BB.has(c)?t1.parseTimeResolve(c):jB(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(ax).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"tomorrow":{let i=new Date(t.getFullYear(),t.getMonth(),t.getDate()+1);return`${i.getFullYear()}-${r(i.getMonth()+1)}-${r(i.getDate())}`}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,ne.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,ne.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,ne.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof nr.IRI){if(r.object.value===UB||r.object.value.includes(cx))return!0}else if(r.object instanceof qt.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__TokenInvocation"||i===cx)return!0}return!1}async assetIsSubstitutionToken(e){let t=await this.tripleStore.match(e,ne.Namespace.EXO.term("Instance_class"),void 0);for(let r of t)if(r.object instanceof nr.IRI){if(r.object.value===MB||r.object.value.includes(ox))return!0}else if(r.object instanceof qt.Literal){let i=this.unwrapWikilink(r.object.value);if(i==="exocmd__SubstitutionToken"||i===ox)return!0}return!1}async resolveGroundingTypeReference(e){let t=await this.tripleStore.match(e,ne.Namespace.EXOCMD.term("Grounding_type"),void 0);if(t.length===0)return null;let r=t[0].object;if(r instanceof nr.IRI)return(0,sx.resolveGroundingTypeFromIRI)(r.value);if(r instanceof qt.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,sx.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 expandPrototypeChain(e){if(!e||!this.normalizeWikilink(e))return[];let t=[e],r=new Set([this.normalizeWikilink(e).toLowerCase()]),i=e;for(let s=0;s<ql;s++){let o=this.extractUuidFromRef(i);if(!o)break;let c=null;try{let u=await this.findSubjectByUID(o);if(!u)break;c=await this.getLinkedValue(u,ne.Namespace.EXO.term("Asset_prototype"))}catch(u){this.logger.debug(this.capWarning(`[expandPrototypeChain] store lookup failed at hop ${s} for '${i}': ${String(u)}`));break}if(!c)break;let l=this.normalizeWikilink(c).toLowerCase();if(r.has(l))break;r.add(l),t.push(c),i=c}return t}extractUuidFromRef(e){let t=this.normalizeWikilink(e);if(this.looksLikeUUID(t))return t;let r=this.extractPathBasename(t);return r&&this.looksLikeUUID(r)?r: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,ne.Namespace.EXO.term("Asset_uid"),void 0);for(let r of t)if(r.object instanceof qt.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 qt.Literal||i instanceof nr.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,ne.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,ne.Namespace.EXO.term("Asset_uid"));c&&o.add(c);let l=await this.getLiteralValue(s,ne.Namespace.EXO.term("Asset_label"));l&&o.add(l);let u=a((h,p)=>{if(o.has(h))return;let _=r.get(h);(_===void 0||p<_)&&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:_}=h;if(_>=ql||i.has(p.value))continue;i.add(p.value);let y=await this.tripleStore.match(p,ne.Namespace.EXO.term("Class_superClass"),void 0);for(let S of y){let v=S.object;if(!(v instanceof nr.IRI))continue;let T=_+1,x=v.value.startsWith("obsidian://vault/"),O=this.iriToObsidianName(v.value);O&&u(O,T);let C=null;if(x?C=v:O&&(C=await this.resolveClassFileIRI(O)),!C)continue;let L=await this.getLiteralValue(C,ne.Namespace.EXO.term("Asset_uid"));L&&u(L,T),i.has(C.value)||f.push({fileIRI:C,depth:T})}}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,ne.Namespace.EXO.term("Asset_label"),void 0);for(let r of t)if(r.object instanceof qt.Literal&&r.object.value===e&&r.subject instanceof nr.IRI){let i=await this.tripleStore.match(r.subject,ne.Namespace.EXO.term("Asset_uid"),void 0);if(i.length>0&&i[0].object instanceof qt.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 nr.IRI){let s=await this.tripleStore.match(i,ne.Namespace.EXO.term("Asset_uid"),void 0);return s.length>0&&s[0].object instanceof qt.Literal?s[0].object.value:i.value.split("/").pop()?.replace(".md","")??null}return i instanceof qt.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 nr.IRI){let c=await this.tripleStore.match(o,ne.Namespace.EXO.term("Asset_uid"),void 0);if(c.length>0&&c[0].object instanceof qt.Literal)i.push(c[0].object.value);else{let l=o.value.split("/").pop()?.replace(".md","");l&&i.push(l)}}else if(o instanceof qt.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 qt.Literal?this.normalizeWikilink(i.value):i instanceof nr.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 qt.Literal?this.unwrapWikilink(i.value):i instanceof nr.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 qt.Literal)return this.resolveWikilinkAlias(i.value);if(i instanceof nr.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,ne.Namespace.EXO.term("Asset_label"));return s?e.replace(`[[${r}]]`,`[[${r}|${s}]]`):e}iriToObsidianName(e){return(0,DB.iriToObsidianName)(e)}normalizeWikilink(e){let t=e.replace(/["'[\]]/g,"").trim(),r=t.indexOf("|");return r>=0?t.substring(0,r):t}};fo.CommandResolver=r1;fo.CommandResolver=r1=t1=RB([(0,CB.injectable)(),OB("design:paramtypes",[Object,Object])],r1)});var i1=E(n1=>{"use strict";Object.defineProperty(n1,"__esModule",{value:!0});n1.validateExoQLAllowlist=VB;var $m=Uf();function VB(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 $m.ExoQLForbiddenKeywordError("LOAD");throw new $m.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 $m.ExoQLForbiddenKeywordError("FROM")}if(Array.isArray(e.where))for(let t of e.where)Um(t);if(Array.isArray(e.template))for(let t of e.template)Um(t)}}a(VB,"validateExoQLAllowlist");function Um(n){if(!n||typeof n!="object")return;if(n.type==="service")throw new $m.ExoQLForbiddenKeywordError("SERVICE");if(Array.isArray(n.patterns))for(let t of n.patterns)Um(t);let e=n.where;if(Array.isArray(e))for(let t of e)Um(t)}a(Um,"walkPatternForBannedKeywords")});var s1=E(Bm=>{"use strict";Object.defineProperty(Bm,"__esModule",{value:!0});Bm.DEFAULT_EVAL_CONFIG=void 0;Bm.DEFAULT_EVAL_CONFIG=Object.freeze({enabled:!0,maxNestedEvalCount:100,maxAggregateEvalMillis:1e4})});var Vm=E(o1=>{"use strict";Object.defineProperty(o1,"__esModule",{value:!0});o1.evaluateWithExoEval=YB;var qB=_l(),GB=Sl(),WB=Bl(),HB=i1(),zB=s1(),KB=Uf();async function YB(n,e={}){if(typeof n!="string")throw new TypeError("evaluateWithExoEval: sparql must be a string");let r=new qB.ExoQLParser().parse(n);if((0,HB.validateExoQLAllowlist)(r),!{...zB.DEFAULT_EVAL_CONFIG,...e.config??{}}.enabled)throw new KB.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 GB.ExoQLAlgebraTranslator().translate(r),l=new WB.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(YB,"evaluateWithExoEval")});var Vf=E(qm=>{"use strict";Object.defineProperty(qm,"__esModule",{value:!0});qm.liveClock=QB;qm.frozenClock=XB;function QB(){return{now:a(()=>new Date,"now")}}a(QB,"liveClock");function XB(n){let e=new Date(n);return{now:a(()=>new Date(e.getTime()),"now")}}a(XB,"frozenClock")});var hx=E(ho=>{"use strict";var JB=ho&&ho.__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},ZB=ho&&ho.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},qf;Object.defineProperty(ho,"__esModule",{value:!0});ho.PreconditionEvaluator=void 0;var e8=Xe(),t8=_l(),r8=Sl(),dx=Bl(),n8=Vm(),i8=Vf(),Gf=qf=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,i8.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,n8.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,qf.SENTINEL_IRI),i=new t8.ExoQLParser().parse(t),o=new r8.ExoQLAlgebraTranslator().translate(i);return new dx.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(qf.SENTINEL_IRI,t));return await new dx.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()+qf.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,_=new Date(Date.UTC(c,l,u-p)),y=_.toISOString().slice(0,10),v=new Date(_.getTime()-10080*60*1e3).toISOString().slice(0,10),T=`${c}-${String(l+1).padStart(2,"0")}-01`,x=l===0?11:l-1,C=`${l===0?c-1:c}-${String(x+1).padStart(2,"0")}-01`,L=`${c}-01-01`;return e.replace(/\$target/g,`<${t}>`).replace(/\$now/g,`"${i}"^^xsd:dateTime`).replace(/\$yesterday/g,`"${h}"^^xsd:date`).replace(/\$thisWeekStart/g,`"${y}"^^xsd:date`).replace(/\$lastWeekStart/g,`"${v}"^^xsd:date`).replace(/\$thisMonthStart/g,`"${T}"^^xsd:date`).replace(/\$lastMonthStart/g,`"${C}"^^xsd:date`).replace(/\$thisYearStart/g,`"${L}"^^xsd:date`).replace(/\$today/g,`"${s}"^^xsd:date`)}};ho.PreconditionEvaluator=Gf;Gf.SENTINEL_IRI="urn:exocortex:cache-sentinel:target";Gf.ALMATY_OFFSET_MS=300*60*1e3;ho.PreconditionEvaluator=Gf=qf=JB([(0,e8.injectable)(),ZB("design:paramtypes",[Object,Object,Object])],Gf)});var px=E(po=>{"use strict";Object.defineProperty(po,"__esModule",{value:!0});po.hasUidFilename=po.hasNonUidFilename=void 0;po.registerDefaultHostFunctions=a8;var s8=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");po.hasNonUidFilename=s8;var o8=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");po.hasUidFilename=o8;function a8(n){n.registerHostFunction("hasNonUidFilename",po.hasNonUidFilename),n.registerHostFunction("hasUidFilename",po.hasUidFilename)}a(a8,"registerDefaultHostFunctions")});var Wm=E(Gm=>{"use strict";Object.defineProperty(Gm,"__esModule",{value:!0});Gm.liveUidGenerator=c8;Gm.seededUidGenerator=u8;var a1=Ai();function c8(){return{next:a(()=>(0,a1.v4)(),"next")}}a(c8,"liveUidGenerator");var l8="6ba7b810-9dad-11d1-80b4-00c04fd430c8";function u8(n){let e=0,t=(0,a1.v5)(n,l8);return{next:a(()=>{let r=`${n}#${e}`;return e+=1,(0,a1.v5)(r,t)},"next")}}a(u8,"seededUidGenerator")});var Km=E(da=>{"use strict";Object.defineProperty(da,"__esModule",{value:!0});da.registerResolver=ur;da.getResolver=f8;da.isResolverModifierAware=d8;da.getRegisteredResolverIds=h8;da.clearResolvers=p8;da.installDefaultResolvers=T8;var zm=new Map,c1=new Set;function ur(n,e,t=!1){zm.set(n,e),t&&c1.add(n)}a(ur,"registerResolver");function f8(n){return zm.get(n)}a(f8,"getResolver");function d8(n){return c1.has(n)}a(d8,"isResolverModifierAware");function h8(){return Array.from(zm.keys())}a(h8,"getRegisteredResolverIds");function p8(){zm.clear(),c1.clear()}a(p8,"clearResolvers");function wn(n){return n<10?`0${n}`:String(n)}a(wn,"pad2");var m8=["January","February","March","April","May","June","July","August","September","October","November","December"],g8=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],y8=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],_8=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function b8(n){let e=["th","st","nd","rd"],t=n%100;return`${n}${e[(t-20)%10]||e[t]||e[0]}`}a(b8,"ordinalDay");var S8=/YYYY|YY|MMMM|MMM|MM|M|Do|DD|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|A|a/g;function w8(n,e){let t=(n.getHours()+11)%12+1;return e.replace(S8,r=>{switch(r){case"YYYY":return String(n.getFullYear());case"YY":return wn(n.getFullYear()%100);case"MMMM":return m8[n.getMonth()];case"MMM":return g8[n.getMonth()];case"MM":return wn(n.getMonth()+1);case"M":return String(n.getMonth()+1);case"Do":return b8(n.getDate());case"DD":return wn(n.getDate());case"D":return String(n.getDate());case"dddd":return y8[n.getDay()];case"ddd":return _8[n.getDay()];case"HH":return wn(n.getHours());case"H":return String(n.getHours());case"hh":return wn(t);case"h":return String(t);case"mm":return wn(n.getMinutes());case"m":return String(n.getMinutes());case"ss":return wn(n.getSeconds());case"s":return String(n.getSeconds());case"A":return n.getHours()<12?"AM":"PM";case"a":return n.getHours()<12?"am":"pm";default:return r}})}a(w8,"formatDate");function mx(n,e,t){let r=n.getDate(),i=new Date(n.getTime());i.setDate(1),t==="M"?i.setMonth(i.getMonth()+e):i.setFullYear(i.getFullYear()+e);let s=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();return i.setDate(Math.min(r,s)),i}a(mx,"addMonthsClamped");function v8(n,e){if(!e)return n;let t=e.match(/^([+-])(\d+)([dwMy])?$/);if(!t)return n;let r=(t[1]==="-"?-1:1)*parseInt(t[2],10),i=t[3]??"d",s=new Date(n.getTime());switch(i){case"d":s.setDate(s.getDate()+r);break;case"w":s.setDate(s.getDate()+r*7);break;case"M":s=mx(s,r,"M");break;case"y":s=mx(s,r,"y");break}return isNaN(s.getTime())?n:s}a(v8,"applyDateOffset");function E8(n){if(!n)return{offset:null,format:null};let e=n.indexOf(":");if(e<0)return{offset:n,format:null};let t=n.slice(0,e),r=n.slice(e+1);return{offset:t||null,format:r||null}}a(E8,"parseDateModifier");function Hm(n,e){return(t,r)=>{let{offset:i,format:s}=E8(r),o=new Date;return n!==0&&o.setDate(o.getDate()+n),o=v8(o,i),w8(o,s??e)}}a(Hm,"makeDateResolver");function T8(){ur("today",()=>new Date().toISOString().slice(0,10)),ur("todayStart",()=>new Date(new Date().setHours(0,0,0,0)).toISOString()),ur("date",Hm(0,"YYYY-MM-DD"),!0),ur("now",Hm(0,"YYYY-MM-DDTHH:mm:ss"),!0),ur("tomorrow",Hm(1,"YYYY-MM-DD"),!0),ur("yesterday",Hm(-1,"YYYY-MM-DD"),!0),ur("target",n=>n.targetIRI?`"[[${n.targetIRI}]]"`:""),ur("targetFolder",n=>{if(!n.targetFilePath)return"";let e=n.targetFilePath.replace(/^\/+/,""),t=e.lastIndexOf("/");return t>=0?e.slice(0,t):""}),ur("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.")}),ur("nowTimestamp",()=>{let n=new Date;return`${n.getFullYear()}-${wn(n.getMonth()+1)}-${wn(n.getDate())}T${wn(n.getHours())}:${wn(n.getMinutes())}:${wn(n.getSeconds())}`}),ur("nowDate",()=>{let n=new Date;return`${n.getFullYear()}-${wn(n.getMonth()+1)}-${wn(n.getDate())}`}),ur("nowYear",()=>String(new Date().getFullYear())),ur("nowMonth",()=>wn(new Date().getMonth()+1)),ur("userInputLabel",n=>{let e=n.userInput?.label;return typeof e=="string"?e:""}),ur("userInput",(n,e)=>{if(!e)return null;let t=n.userInput?.[e];return typeof t=="string"?t:t==null?null:String(t)}),ur("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)}),ur("labelAsArray",n=>{let e=n.userInput?.label;return typeof e=="string"&&e.length>0?[e]:[]}),ur("groundingTargetClass",n=>n.groundingTargetClassUid?`"[[${n.groundingTargetClassUid}]]"`:null),ur("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(T8,"installDefaultResolvers")});var u1=E(Ym=>{"use strict";Object.defineProperty(Ym,"__esModule",{value:!0});Ym.resolveTemplateBody=I8;Ym.stripTemplateFrontmatter=R8;var l1=Km();(0,l1.installDefaultResolvers)();var A8=/\$([A-Za-z][A-Za-z0-9_]*)((?:[+-]\d+[dwMy])?(?::[A-Za-z0-9:./-]+)?)/g;function I8(n,e={}){return n.replace(A8,(t,r,i)=>{let s=(0,l1.getResolver)(r);if(s===void 0)return t;let o=s(e,i.length>0?i:void 0);return typeof o!="string"||o.length===0?t:(0,l1.isResolverModifierAware)(r)?o:o+i})}a(I8,"resolveTemplateBody");function R8(n){let e=n.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);return e?n.slice(e[0].length):n}a(R8,"stripTemplateFrontmatter")});var Wf=E(Gl=>{"use strict";Object.defineProperty(Gl,"__esModule",{value:!0});Gl.registerOrderSpecLoader=O8;Gl.clearOrderSpecLoader=C8;Gl.loadDefaultSpec=x8;Gl.orderProperties=P8;var Qm=null,ha,Xm=!1;function O8(n){Qm=n,ha=void 0,Xm=!1}a(O8,"registerOrderSpecLoader");function C8(){Qm=null,ha=void 0,Xm=!1}a(C8,"clearOrderSpecLoader");function x8(){if(ha!==void 0)return ha;if(!Qm)return ha=null,null;try{ha=Qm()}catch(n){Xm||(console.warn("[OrderSpecResolver] loader threw, falling back to insertion order:",n),Xm=!0),ha=null}return ha}a(x8,"loadDefaultSpec");function P8(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(P8,"orderProperties")});var Jm=E(gc=>{"use strict";Object.defineProperty(gc,"__esModule",{value:!0});gc.STRING_SCALAR_PROPERTIES=void 0;gc.needsYamlQuoting=gx;gc.quoteYamlString=yx;gc.serializeYamlScalar=B8;var D8=/^[-!&*?|>%@`"'#,[\]{}]/,F8=/[\u0000-\u001f\u007f]/,L8=/^(?:true|True|TRUE|false|False|FALSE)$/,N8=/^(?:null|Null|NULL|~)$/,k8=/^[-+]?(?:0b[01_]+|0o[0-7_]+|0x[0-9a-fA-F_]+|[0-9][0-9_]*)$/,M8=/^(?:[-+]?[0-9][0-9_]*(?:\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$/,j8=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;gc.STRING_SCALAR_PROPERTIES=new Set(["exo__Asset_label","aliases"]);function $8(n){if(n.length<2||!n.startsWith('"')||!n.endsWith('"'))return!1;let e=n.slice(1,-1);for(let t=0;t<e.length;t++){if(e[t]==="\\"){if(t+1>=e.length)return!1;t++;continue}if(e[t]==='"')return!1}return!0}a($8,"isCompleteDoubleQuotedScalar");function U8(n){return L8.test(n)||N8.test(n)||k8.test(n)||M8.test(n)||j8.test(n)}a(U8,"looksLikeNonStringScalar");function gx(n,e=!1){return n===""?!0:$8(n)?!1:!!(n!==n.trim()||/:(\s|$)/.test(n)||/\s#/.test(n)||D8.test(n)||F8.test(n)||e&&U8(n))}a(gx,"needsYamlQuoting");function yx(n){let e="";for(let t=0;t<n.length;t++){let r=n[t],i=n.charCodeAt(t);r==="\\"?e+="\\\\":r==='"'?e+='\\"':r===`
|
|
71
71
|
`?e+="\\n":r==="\r"?e+="\\r":r===" "?e+="\\t":i<32||i===127?e+="\\x"+i.toString(16).toUpperCase().padStart(2,"0"):e+=r}return`"${e}"`}a(yx,"quoteYamlString");function B8(n,e=!1){return typeof n!="string"?String(n):gx(n,e)?yx(n):n}a(B8,"serializeYamlScalar")});var Is=E(Zm=>{"use strict";Object.defineProperty(Zm,"__esModule",{value:!0});Zm.FrontmatterService=void 0;var _x=Wf(),f1=Jm(),Hf=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`---
|
|
72
72
|
${s}
|
|
73
73
|
---
|
|
@@ -637,7 +637,7 @@ Duplicate bindings (${n.duplicates.length}) \u2014 uid claimed by >1 test (warni
|
|
|
637
637
|
Skipped floor check for ${n.unknownPriority} requirement(s) with unparseable priority (fail-open).`),n.clean?e==="hard"&&!n.rampReady?console.error(`
|
|
638
638
|
FAIL (hard gate): ramp not ready \u2014 ${n.p0Orphans} P0 requirement(s) unbound`+(n.p0Total===0?" (no P0 requirements found)":"")+"."):console.log(`
|
|
639
639
|
OK: no hard findings (dangling tags + binding-class floor are clean).`):console.error(`
|
|
640
|
-
FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s) + ${n.activeViolations.length} active-requirement invariant violation(s) + ${n.danglingEvidence.length} dangling evidence link(s).`)}a(noe,"renderText");function ioe(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(ioe,"isHardFail");function w9(){return new ke("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage, P0 ramp-readiness").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).option("--gate <mode>","Gate mode: soft (warn only on hard findings) | hard (also block when the P0 checklist is not ramp-ready)","soft").action(async n=>{let e=n.output??"text";Se.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,Ba.resolve)(n.reqs);if(!(0,Va.existsSync)(r)||!(0,Va.statSync)(r).isDirectory())throw new Ze(r);let i=(0,Ba.resolve)(n.tests??".");if(!(0,Va.existsSync)(i)||!(0,Va.statSync)(i).isDirectory())throw new Ze(i);let[s,o]=await Promise.all([Jse(r),eoe(i)]),c=toe(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):noe(c,t),ioe(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){Se.handle(r)}})}a(w9,"requirementsAuditCommand");function v9(){let n=new ke("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(w9()),n}a(v9,"requirementsCommand");function A_(n){let e=new ke;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.170.
|
|
640
|
+
FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s) + ${n.activeViolations.length} active-requirement invariant violation(s) + ${n.danglingEvidence.length} dangling evidence link(s).`)}a(noe,"renderText");function ioe(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(ioe,"isHardFail");function w9(){return new ke("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage, P0 ramp-readiness").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).option("--gate <mode>","Gate mode: soft (warn only on hard findings) | hard (also block when the P0 checklist is not ramp-ready)","soft").action(async n=>{let e=n.output??"text";Se.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,Ba.resolve)(n.reqs);if(!(0,Va.existsSync)(r)||!(0,Va.statSync)(r).isDirectory())throw new Ze(r);let i=(0,Ba.resolve)(n.tests??".");if(!(0,Va.existsSync)(i)||!(0,Va.statSync)(i).isDirectory())throw new Ze(i);let[s,o]=await Promise.all([Jse(r),eoe(i)]),c=toe(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):noe(c,t),ioe(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){Se.handle(r)}})}a(w9,"requirementsAuditCommand");function v9(){let n=new ke("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(w9()),n}a(v9,"requirementsCommand");function A_(n){let e=new ke;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.170.1"),e.addCommand(gj()),e.addCommand(Ij()),e.addCommand(h4()),e.addCommand(y4()),e.addCommand($4()),e.addCommand(_4()),e.addCommand(V4()),e.addCommand(X4()),e.addCommand(Z4()),e.addCommand(hj()),e.addCommand(Vj()),e.addCommand(Wj()),e.addCommand(a9()),e.addCommand(l9()),e.addCommand(d9()),e.addCommand(h9()),e.addCommand(y9()),e.addCommand(Jj()),e.addCommand(i9()),e.addCommand(v9()),e}a(A_,"createProgram");A_().parse();0&&(module.exports={createProgram});
|
|
641
641
|
/*! Bundled license information:
|
|
642
642
|
|
|
643
643
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED