@kitelev/exocortex-cli 16.154.0 → 16.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v16.154.0
2
+ // @kitelev/exocortex-cli v16.156.0
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -220,7 +220,7 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>`});var Nv=w(Zr=>{"use strict";va
220
220
  `,i=this.composePrefixes(t),s=this.serializePrefixes(i,r),o=this.nTriplesSerializer.serialize(e,{newline:r}).trimEnd();return s?o?`${s}${r}${r}${o}${r}`:`${s}${r}`:o?`${o}${r}`:""}serializePrefixes(e,t){let r=Object.entries(e);return r.length===0?"":r.map(([i,s])=>`@prefix ${i}: <${s}> .`).join(t)}composePrefixes(e){return e.includeDefaultPrefixes??!0?{...$G,...e.prefixes??{}}:{...e.prefixes??{}}}serializeTriplesOnly(e,t){return this.nTriplesSerializer.serializeChunk(e,t).trimEnd()}};Ag.TurtleSerializer=$v});var h3=w(Ig=>{"use strict";Object.defineProperty(Ig,"__esModule",{value:!0});Ig.JSONLDSerializer=void 0;var f3=Oe(),d3=jt(),UG=Ge(),Yl=zt(),BG={rdf:Yl.Namespace.RDF.iri.value,rdfs:Yl.Namespace.RDFS.iri.value,owl:Yl.Namespace.OWL.iri.value,xsd:Yl.Namespace.XSD.iri.value,exo:Yl.Namespace.EXO.iri.value,ems:Yl.Namespace.EMS.iri.value},Uv=class{static{a(this,"JSONLDSerializer")}toDocument(e,t={}){let r={...BG,...t.context??{}},i=new Map;for(let s of e){let o=this.subjectToId(s.subject),c=this.compactIri(s.predicate.value,r),l=this.objectToJSONLD(s.object,r),u=i.get(o)??{"@id":o},f=u[c];f===void 0?u[c]=l:Array.isArray(f)?f.push(l):u[c]=[f,l],i.set(o,u)}return{"@context":r,"@graph":Array.from(i.values())}}serialize(e,t={}){let r=this.toDocument(e,t),i=t.pretty?t.indent??2:void 0;return JSON.stringify(r,null,i)}subjectToId(e){return e instanceof f3.IRI?e.value:e instanceof d3.BlankNode?`_:${e.id}`:String(e)}compactIri(e,t){for(let[r,i]of Object.entries(t))if(e.startsWith(i)){let s=e.slice(i.length);if(s.length>0)return`${r}:${s}`}return e}objectToJSONLD(e,t){if(e instanceof f3.IRI)return{"@id":e.value};if(e instanceof d3.BlankNode)return{"@id":`_:${e.id}`};if(e instanceof UG.Literal){let r={"@value":e.value};return e.datatype?r["@type"]=this.compactIri(e.datatype.value,t):e.language&&(r["@language"]=e.language,e.hasDirection()&&e.direction&&(r["@direction"]=e.direction)),r}return e}};Ig.JSONLDSerializer=Uv});var qv=w(xg=>{"use strict";Object.defineProperty(xg,"__esModule",{value:!0});xg.NTriplesParser=void 0;var VG=Qn(),p3=Oe(),Bv=Ge(),qG=jt(),Xl=zt(),GG={rdf:Xl.Namespace.RDF.iri.value,rdfs:Xl.Namespace.RDFS.iri.value,owl:Xl.Namespace.OWL.iri.value,xsd:Xl.Namespace.XSD.iri.value,exo:Xl.Namespace.EXO.iri.value,ems:Xl.Namespace.EMS.iri.value},Vv=class{static{a(this,"NTriplesParser")}parse(e,t={}){let r={prefixes:{...GG,...t.prefixes??{}},strict:t.strict??!1},i=[];return e.split(/\r?\n/).forEach((o,c)=>{let l=o.trim();!l||l.startsWith("#")||i.push(this.parseLine(l,c+1,r))}),i}parseLine(e,t,r){if(!e.endsWith("."))throw new Error(`Invalid RDF statement at line ${t}: missing '.' terminator`);let s=e.slice(0,-1).trim(),o=this.parseSubject(s,t,r);s=o.rest.trim();let c=this.parsePredicate(s,t,r);s=c.rest.trim();let l=this.parseObject(s,t,r);if(s=l.rest.trim(),s.length>0)throw new Error(`Unexpected tokens after object at line ${t}`);return new VG.Triple(o.node,c.node,l.node)}parseSubject(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):e.startsWith("_:")?this.consumeBlankNode(e,t):this.consumePrefixedName(e,t,r)}parsePredicate(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):this.consumePrefixedName(e,t,r)}parseObject(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):e.startsWith("_:")?this.consumeBlankNode(e,t):e.startsWith('"')?this.consumeLiteral(e,t,r):this.consumePrefixedName(e,t,r)}consumePrefixedName(e,t,r){let i=e.match(/^([a-zA-Z_][\w-]*):([^\s]+)(?:\s+(.*))?$/);if(!i)throw new Error(`Invalid token at line ${t}: ${e}`);let[,s,o,c]=i,l=r.prefixes[s];if(!l)throw new Error(`Unknown prefix "${s}" at line ${t}`);return{node:new p3.IRI(`${l}${o}`),rest:(c??"").trimStart()}}consumeIRI(e,t,r){let i=this.findClosingBracket(e,"<",">");if(i===-1)throw new Error(`Invalid IRI at line ${t}`);let s=e.slice(1,i),o=new p3.IRI(s),c=e.slice(i+1).trimStart();return{node:o,rest:c}}consumeBlankNode(e,t){let r=e.match(/^_:(\w+)(?:\s+(.*))?$/);if(!r)throw new Error(`Invalid blank node identifier at line ${t}`);let[,i,s]=r;return{node:new qG.BlankNode(i),rest:(s??"").trimStart()}}consumeLiteral(e,t,r){let{value:i,rest:s}=this.consumeQuotedString(e,t),o=s.trimStart();if(o.startsWith("^^")){o=o.slice(2).trimStart();let c=o.startsWith("<")?this.consumeIRI(o,t,r):this.consumePrefixedName(o,t,r);return{node:new Bv.Literal(i,c.node),rest:c.rest}}if(o.startsWith("@")){let c=o.match(/^@([a-zA-Z-]+)(?:\s+(.*))?$/);if(!c)throw new Error(`Invalid language tag at line ${t}`);let[,l,u]=c;return{node:new Bv.Literal(i,void 0,l),rest:(u??"").trimStart()}}return{node:new Bv.Literal(i),rest:o}}consumeQuotedString(e,t){if(!e.startsWith('"'))throw new Error(`Expected quoted string at line ${t}`);let r="";for(let i=1;i<e.length;i++){let s=e[i];if(s==="\\"){if(i+1>=e.length)throw new Error(`Invalid escape sequence at line ${t}`);let o=e[i+1];switch(o){case"t":r+=" ",i+=1;break;case"b":r+="\b",i+=1;break;case"n":r+=`
221
221
  `,i+=1;break;case"r":r+="\r",i+=1;break;case"f":r+="\f",i+=1;break;case'"':r+='"',i+=1;break;case"\\":r+="\\",i+=1;break;case"u":{let c=e.slice(i+2,i+6);if(c.length!==4||!/^[0-9a-fA-F]{4}$/.test(c))throw new Error(`Invalid \\u escape at line ${t}`);r+=String.fromCharCode(parseInt(c,16)),i+=5;break}case"U":{let c=e.slice(i+2,i+10);if(c.length!==8||!/^[0-9a-fA-F]{8}$/.test(c))throw new Error(`Invalid \\U escape at line ${t}`);r+=String.fromCodePoint(parseInt(c,16)),i+=9;break}default:throw new Error(`Unknown escape sequence \\${o} at line ${t}`)}continue}if(s==='"'){let o=e.slice(i+1);return{value:r,rest:o}}r+=s}throw new Error(`Unterminated string literal at line ${t}`)}findClosingBracket(e,t,r){let i=0;for(let s=0;s<e.length;s++){let o=e[s];if(o===t){i++;continue}if(o===r&&(i--,i===0))return s}return-1}};xg.NTriplesParser=Vv});var m3=w(Rg=>{"use strict";Object.defineProperty(Rg,"__esModule",{value:!0});Rg.TurtleParser=void 0;var Jl=zt(),WG=qv(),HG={rdf:Jl.Namespace.RDF.iri.value,rdfs:Jl.Namespace.RDFS.iri.value,owl:Jl.Namespace.OWL.iri.value,xsd:Jl.Namespace.XSD.iri.value,exo:Jl.Namespace.EXO.iri.value,ems:Jl.Namespace.EMS.iri.value},zG=/^@prefix\s+([a-zA-Z_][\w-]*):\s*<([^>]+)>\s*\.$/,Gv=class{static{a(this,"TurtleParser")}constructor(){this.nTriplesParser=new WG.NTriplesParser}parse(e,t={}){let r={...HG,...t.prefixes??{}},i=this.collectStatements(e),s=[];return i.forEach(({statement:o,lineNumber:c})=>{if(this.isPrefixStatement(o)){let u=o.match(zG);if(!u)throw new Error(`Invalid prefix declaration at line ${c}`);let[,f,d]=u;r[f]=d;return}if(o.includes(";")||o.includes(","))throw new Error(`Complex Turtle statements with ';' or ',' are not supported (line ${c})`);let l=this.normalizeShortcuts(o);s.push(this.nTriplesParser.parseLine(l,c,{prefixes:r,strict:!1}))}),s}collectStatements(e){let t=e.split(/\r?\n/),r=[],i="",s=0;if(t.forEach((o,c)=>{let l=o.trim();!l||l.startsWith("#")||(i||(s=c+1),i=i?`${i} ${l}`:l,l.endsWith(".")&&(r.push({statement:i,lineNumber:s}),i=""))}),i)throw new Error(`Unterminated Turtle statement near line ${s}`);return r}isPrefixStatement(e){return e.startsWith("@prefix")}normalizeShortcuts(e){return e.includes(" a ")?e.replace(/\sa\s/g," rdf:type "):e}};Rg.TurtleParser=Gv});var g3=w(Cg=>{"use strict";Object.defineProperty(Cg,"__esModule",{value:!0});Cg.RDFSerializer=void 0;var Zl=Qn(),_c=Oe(),Sc=Ge(),Wv=jt(),Rs=zt(),KG=u3(),QG=jv(),YG=h3(),XG=m3(),JG=qv(),ZG=1024,eW=`
222
222
  `,tW={rdf:Rs.Namespace.RDF.iri.value,rdfs:Rs.Namespace.RDFS.iri.value,owl:Rs.Namespace.OWL.iri.value,xsd:Rs.Namespace.XSD.iri.value,exo:Rs.Namespace.EXO.iri.value,ems:Rs.Namespace.EMS.iri.value},Hv=class{static{a(this,"RDFSerializer")}constructor(e){this.store=e,this.turtleSerializer=new KG.TurtleSerializer,this.nTriplesSerializer=new QG.NTriplesSerializer,this.jsonldSerializer=new YG.JSONLDSerializer,this.turtleParser=new XG.TurtleParser,this.nTriplesParser=new JG.NTriplesParser}async serialize(e,t={}){let r=await this.store.match();return this.serializeTriples(r,e,t)}serializeTriples(e,t,r={}){switch(t){case"turtle":return this.turtleSerializer.serialize(e,{prefixes:r.prefixes,includeDefaultPrefixes:r.includeDefaultPrefixes,newline:r.newline});case"n-triples":return this.nTriplesSerializer.serialize(e,{newline:r.newline});case"json-ld":return this.jsonldSerializer.serialize(e,{context:r.prefixes,pretty:r.pretty,indent:r.indent});default:throw new Error(`Unsupported serialization format: ${t}`)}}stream(e,t={}){let r=t.newline??eW,i=t.batchSize??ZG,s=t.includeDefaultPrefixes,o=t.prefixes,c=this,l=!1,u=[],f=[],d=0,h=a(async()=>{if(!l){if(f=await c.store.match(),e==="json-ld"){let g=c.jsonldSerializer.toDocument(f,{context:o,pretty:!1});u.push(...c.buildJsonLdChunks(g))}else if(e==="turtle"){let g=c.turtleSerializer.serializePrefixes(c.composePrefixes(o,s),r);g&&u.push(`${g}${r}${r}`)}l=!0}},"ensureInitialized");return{async next(){if(await h(),u.length>0)return{value:u.shift(),done:!1};if(e==="json-ld")return{value:void 0,done:!0};if(d>=f.length)return{value:void 0,done:!0};let g=f.slice(d,d+i);d+=g.length;let y="";if(e==="turtle"){let b=c.turtleSerializer.serializeTriplesOnly(g,r);b&&(y=`${b}${r}`)}else e==="n-triples"&&(y=c.nTriplesSerializer.serializeChunk(g,r));return y?{value:y,done:!1}:this.next()},async return(){return u=[],f=[],d=0,{value:void 0,done:!0}},[Symbol.asyncIterator](){return this}}}async load(e,t,r={}){let i=this.parse(e,t,r);return r.mode!=="append"&&await this.store.clear(),await this.store.addAll(i),i.length}parse(e,t,r={}){switch(t){case"turtle":return this.turtleParser.parse(e,this.buildTurtleParseOptions(r));case"n-triples":return this.nTriplesParser.parse(e,this.buildNTriplesParseOptions(r));case"json-ld":return this.parseJsonLd(e,r);default:throw new Error(`Unsupported serialization format: ${t}`)}}buildTurtleParseOptions(e){return{prefixes:this.composePrefixes(e.prefixes,!0),strict:e.strict}}buildNTriplesParseOptions(e){return{prefixes:this.composePrefixes(e.prefixes,!0),strict:e.strict}}composePrefixes(e,t){return t??!0?{...tW,...e??{}}:{...e??{}}}parseJsonLd(e,t){let r;try{r=JSON.parse(e)}catch(u){throw new Error(`Invalid JSON-LD document: ${u.message}`)}let i=this.composePrefixes(t.prefixes,!0),s=this.extractContext(r),o={...i,...s},c=this.extractGraph(r),l=[];return c.forEach((u,f)=>{if(!u||typeof u!="object"||Array.isArray(u))throw new Error(`Invalid JSON-LD node at index ${f}`);let d=this.parseSubjectFromNode(u,o,f),h=Object.entries(u);for(let[p,g]of h){if(p==="@id"||p==="@context")continue;if(p==="@type"){this.collectTypeTriples(d,g,l,o);continue}let y=this.expandTerm(p,o),b=new _c.IRI(y);this.collectTriplesForValue(d,b,g,l,o)}}),l}extractContext(e){if(!e||typeof e!="object"||Array.isArray(e))return{};let t=e["@context"];if(!t||typeof t!="object"||Array.isArray(t))return{};let r={};return Object.entries(t).forEach(([i,s])=>{typeof s=="string"&&(r[i]=s)}),r}extractGraph(e){if(Array.isArray(e))return e;if(!e||typeof e!="object")return[];let t=e["@graph"];return Array.isArray(t)?t:[e]}parseSubjectFromNode(e,t,r){let i=e["@id"];if(typeof i=="string"){if(i.startsWith("_:"))return new Wv.BlankNode(i.slice(2));if(this.isAbsoluteIri(i))return new _c.IRI(i);let s=this.expandTerm(i,t);return new _c.IRI(s)}return new Wv.BlankNode(`jsonld_${r}`)}collectTypeTriples(e,t,r,i){let s=Rs.Namespace.RDF.term("type");(Array.isArray(t)?t:[t]).forEach(c=>{if(typeof c!="string")throw new Error("Invalid @type value in JSON-LD node");let l=this.expandTerm(c,i);r.push(new Zl.Triple(e,s,new _c.IRI(l)))})}collectTriplesForValue(e,t,r,i,s){if(r!=null){if(Array.isArray(r)){r.forEach(o=>this.collectTriplesForValue(e,t,o,i,s));return}if(typeof r=="object"){let o=r;if(typeof o["@id"]=="string"){let c=this.parseIdNode(o["@id"],s);i.push(new Zl.Triple(e,t,c));return}if(o["@value"]!==void 0){let c=this.parseLiteralObject(o,s);i.push(new Zl.Triple(e,t,c));return}}if(typeof r=="string"){i.push(new Zl.Triple(e,t,new Sc.Literal(r)));return}if(typeof r=="number"){let o=Number.isInteger(r)?Rs.Namespace.XSD.term("integer"):Rs.Namespace.XSD.term("decimal");i.push(new Zl.Triple(e,t,new Sc.Literal(r.toString(),o)));return}if(typeof r=="boolean"){let o=Rs.Namespace.XSD.term("boolean");i.push(new Zl.Triple(e,t,new Sc.Literal(r.toString(),o)));return}throw new Error("Unsupported JSON-LD value encountered")}}parseIdNode(e,t){if(e.startsWith("_:"))return new Wv.BlankNode(e.slice(2));if(this.isAbsoluteIri(e))return new _c.IRI(e);let r=this.expandTerm(e,t);return new _c.IRI(r)}parseLiteralObject(e,t){let r=e["@value"];if(typeof r!="string")throw new Error("JSON-LD literal values must be strings");if(typeof e["@language"]=="string"){let i=e["@direction"];return i==="ltr"||i==="rtl"?new Sc.Literal(r,void 0,e["@language"],i):new Sc.Literal(r,void 0,e["@language"])}if(typeof e["@type"]=="string"){let i=this.expandTerm(e["@type"],t);return new Sc.Literal(r,new _c.IRI(i))}return new Sc.Literal(r)}expandTerm(e,t){if(this.isAbsoluteIri(e))return e;let r=e.indexOf(":");if(r>0){let s=e.slice(0,r),o=e.slice(r+1),c=t[s];if(!c)throw new Error(`Unknown prefix "${s}" in JSON-LD document`);return`${c}${o}`}let i=t["@vocab"];if(i)return`${i}${e}`;throw new Error(`Unable to expand JSON-LD term "${e}"`)}isAbsoluteIri(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)}buildJsonLdChunks(e){let t=[],r=JSON.stringify(e["@context"]);return t.push(`{"@context":${r},"@graph":[`),e["@graph"].forEach((i,s)=>{let o=JSON.stringify(i);s>0?t.push(`,${o}`):t.push(o)}),t.push(`]}
223
- `),t}};Cg.RDFSerializer=Hv});var zv=w(Ro=>{"use strict";Object.defineProperty(Ro,"__esModule",{value:!0});Ro.OBSIDIAN_VAULT_SCHEME=void 0;Ro.vaultPathToIRI=rW;Ro.iriToVaultPath=nW;Ro.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function rW(n){let e=n.startsWith("./")?n.slice(2):n;return`${Ro.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}a(rW,"vaultPathToIRI");function nW(n){if(!n.startsWith(Ro.OBSIDIAN_VAULT_SCHEME))return null;let e=n.slice(Ro.OBSIDIAN_VAULT_SCHEME.length);try{return decodeURI(e)}catch{return null}}a(nW,"iriToVaultPath")});var Qv=w(Og=>{"use strict";Object.defineProperty(Og,"__esModule",{value:!0});Og.RDFVocabularyMapper=void 0;var cr=Qn(),y3=Oe(),he=zt(),Kv=class{static{a(this,"RDFVocabularyMapper")}constructor(){this.propertyMappings=new Map([["exo__Instance_class",he.Namespace.RDF.term("type")],["exo__Asset_isDefinedBy",he.Namespace.RDFS.term("isDefinedBy")],["exo__Class_superClass",he.Namespace.RDFS.term("subClassOf")],["exo__Property_range",he.Namespace.RDFS.term("range")],["exo__Property_domain",he.Namespace.RDFS.term("domain")],["exo__Property_superProperty",he.Namespace.RDFS.term("subPropertyOf")]])}generateClassHierarchyTriples(){let e=[];return e.push(new cr.Triple(he.Namespace.EXO.term("Asset"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDFS.term("Resource"))),e.push(new cr.Triple(he.Namespace.EXO.term("Class"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDFS.term("Class"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDF.term("Property"))),e.push(new cr.Triple(he.Namespace.EMS.term("Task"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Project"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Area"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Workflow"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("WorkflowState"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("WorkflowTransition"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Command"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Precondition"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Grounding"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("CommandBinding"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new cr.Triple(he.Namespace.EXO.term("Instance_class"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDF.term("type"))),e.push(new cr.Triple(he.Namespace.EXO.term("Asset_isDefinedBy"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("isDefinedBy"))),e.push(new cr.Triple(he.Namespace.EXO.term("Class_superClass"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("subClassOf"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_range"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("range"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_domain"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("domain"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_superProperty"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("subPropertyOf"))),e}generateMappedTriple(e,t,r){let i=this.propertyMappings.get(t);if(!i)return null;let s;if(r instanceof y3.IRI)s=r;else{let o=r.match(/^(ems|exo|exocmd)__(.+)$/);if(o){let[,c,l]=o;s=(c==="ems"?he.Namespace.EMS:c==="exocmd"?he.Namespace.EXOCMD:he.Namespace.EXO).term(l)}else s=new y3.IRI(r)}return new cr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};Og.RDFVocabularyMapper=Kv});var b3=w(Fg=>{"use strict";Object.defineProperty(Fg,"__esModule",{value:!0});Fg.RDFSInferenceEngine=void 0;var iW=Qn(),Pg=Oe(),Yv=class{static{a(this,"RDFSInferenceEngine")}async materialize(e){let t=await e.predicates(),r=t.find(d=>d.value.includes("Class_superClass")),i=t.find(d=>d.value.includes("Instance_class"));if(!r||!i)return 0;let s=await this.buildDirectParentMap(e,r);if(s.size===0)return 0;let o=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof Pg.IRI){let h=o.get(d.object.value);if(h)for(let p of h)u.push(new iW.Triple(d.subject,i,new Pg.IRI(p)))}return u.length>0&&await e.addAll(u),await e.count()-c}async buildDirectParentMap(e,t){let r=await e.match(void 0,t),i=new Map;for(let s of r)if(s.subject instanceof Pg.IRI&&s.object instanceof Pg.IRI){let o=s.subject.value,c=s.object.value;i.has(o)||i.set(o,new Set),i.get(o).add(c)}return i}computeAllAncestors(e){let t=new Map;for(let r of e.keys())t.has(r)||t.set(r,this.computeAncestorsBFS(r,e));return t}computeAncestorsBFS(e,t){let r=new Set,i=new Set,s=[],o=t.get(e);if(o)for(let c of o)s.push(c);for(;s.length>0;){let c=s.shift();if(i.has(c))continue;i.add(c),r.add(c);let l=t.get(c);if(l)for(let u of l)i.has(u)||s.push(u)}return r}};Fg.RDFSInferenceEngine=Yv});var Zv=w(wc=>{"use strict";var sW=wc&&wc.__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};Object.defineProperty(wc,"__esModule",{value:!0});wc.NonInheritablePropertyRegistry=void 0;var oW=Be(),_3=Oe(),S3=Ge(),Xv=zt(),Jv=class{static{a(this,"NonInheritablePropertyRegistry")}constructor(){this.nonInheritableIRIs=new Set,this.initialized=!1}async initialize(e){this.nonInheritableIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Instance_class"));if(!r){this.initialized=!0;return}let i=await this.findNonInheritableClassIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof S3.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.nonInheritableIRIs.add(d)}}}catch{}this.initialized=!0}isNonInheritable(e){return this.nonInheritableIRIs.has(e)}get size(){return this.nonInheritableIRIs.size}get isInitialized(){return this.initialized}async findNonInheritableClassIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new S3.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof _3.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof _3.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?Xv.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?Xv.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?Xv.Namespace.EXOCMD.term(e.substring(8)).value:null}};wc.NonInheritablePropertyRegistry=Jv;wc.NonInheritablePropertyRegistry=Jv=sW([(0,oW.injectable)()],Jv)});var rE=w(vc=>{"use strict";var aW=vc&&vc.__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};Object.defineProperty(vc,"__esModule",{value:!0});vc.PropertyCardinalityRegistry=void 0;var cW=Be(),w3=Oe(),v3=Ge(),eE=zt(),tE=class{static{a(this,"PropertyCardinalityRegistry")}constructor(){this.multiValuedIRIs=new Set,this.initialized=!1}async initialize(e){this.multiValuedIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Property_cardinality"));if(!r){this.initialized=!0;return}let i=await this.findMultipleCardinalityIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof v3.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.multiValuedIRIs.add(d)}}}catch{}this.initialized=!0}isMultiValued(e){return this.multiValuedIRIs.has(e)}get size(){return this.multiValuedIRIs.size}get isInitialized(){return this.initialized}async findMultipleCardinalityIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new v3.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof w3.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof w3.IRI&&c.object.value.includes("PropertyCardinalityMultiple"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?eE.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?eE.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?eE.Namespace.EXOCMD.term(e.substring(8)).value:null}};vc.PropertyCardinalityRegistry=tE;vc.PropertyCardinalityRegistry=tE=aW([(0,cW.injectable)()],tE)});var sE=w(xr=>{"use strict";var lW=xr&&xr.__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},uW=xr&&xr.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(xr,"__esModule",{value:!0});xr.PrototypeChainMaterializer=xr.MAX_PROTOTYPE_DEPTH=xr.INFERRED_GRAPH=void 0;xr.inferredGraphForDepth=nE;var fW=Be(),E3=Qn(),da=Oe(),dW=Zv(),hW=rE();xr.INFERRED_GRAPH=new da.IRI("https://exocortex.my/ontology/exo#inferred");var pW="https://exocortex.my/ontology/exo#inferred/";function nE(n){return new da.IRI(`${pW}${n}`)}a(nE,"inferredGraphForDepth");xr.MAX_PROTOTYPE_DEPTH=10;var iE=class{static{a(this,"PrototypeChainMaterializer")}constructor(e,t){this.registry=e,this.cardinalityRegistry=t??null}async materialize(e){let r=(await e.predicates()).find(c=>c.value.includes("Asset_prototype"));if(!r)return 0;let i=await e.match(void 0,r,void 0);if(i.length===0)return 0;let s=new Map;for(let c of i)if(c.subject instanceof da.IRI&&c.object instanceof da.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let o=0;for(let[c]of s){let l=new da.IRI(c),u=this.resolveChain(c,s);if(u.length===0)continue;let f=await e.match(l,void 0,void 0),d=new Set,h=new Map;for(let p of f)if(d.add(p.predicate.value),this.isMultiValued(p.predicate.value)){let g=p.object instanceof da.IRI?p.object.value:String(p.object),y=h.get(p.predicate.value);y||(y=new Set,h.set(p.predicate.value,y)),y.add(g)}for(let p=0;p<u.length;p++){let g=u[p],y=p+1,b=new da.IRI(g),S=await e.match(b,void 0,void 0),v=new Set;if(e.matchInGraph){let I=await e.matchInGraph(b,void 0,void 0,xr.INFERRED_GRAPH);for(let A of I)v.add(A.predicate.value)}for(let I of S){let A=I.predicate.value;if(this.registry.isNonInheritable(A)||v.has(A))continue;if(d.has(A)&&this.isMultiValued(A)){let R=I.object instanceof da.IRI?I.object.value:String(I.object);if(h.get(A)?.has(R))continue;let L=h.get(A);L||(L=new Set,h.set(A,L)),L.add(R);let P=new E3.Triple(l,I.predicate,I.object);await e.add(P),e.addToGraph&&(await e.addToGraph(P,xr.INFERRED_GRAPH),await e.addToGraph(P,nE(y))),o++;continue}if(d.has(A))continue;let T=new E3.Triple(l,I.predicate,I.object);await e.add(T),e.addToGraph&&(await e.addToGraph(T,xr.INFERRED_GRAPH),await e.addToGraph(T,nE(y))),d.add(A),o++}}}return o}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],o=t.get(e);for(o&&s.push(o.value);s.length>0&&r.length<xr.MAX_PROTOTYPE_DEPTH;){let c=s.shift();if(c===void 0)break;if(i.has(c))continue;i.add(c),r.push(c);let l=t.get(c);l&&!i.has(l.value)&&s.push(l.value)}return r}};xr.PrototypeChainMaterializer=iE;xr.PrototypeChainMaterializer=iE=lW([(0,fW.injectable)(),uW("design:paramtypes",[dW.NonInheritablePropertyRegistry,hW.PropertyCardinalityRegistry])],iE)});var A3=w(Lg=>{"use strict";Object.defineProperty(Lg,"__esModule",{value:!0});Lg.IRICanonicalizer=void 0;var T3=Oe(),mW=Ge(),gW=jt(),yW=Qn(),oE=/^obsidian:\/\/vault\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.md$/i,Dg=class n{static{a(this,"IRICanonicalizer")}static extractSynthAUid(e){let t=oE.exec(e);return t?t[1].toLowerCase():null}static canonicalize(e,t){if(t.size===0)return{triples:e,remapCount:0,uniqueRemapCount:0};let r=new Map,i=new Set,s=0;return{triples:e.map(c=>{let l=n.remapIfSynthA(c.subject,t,r,i),u=n.remapIfSynthA(c.object,t,r,i);return l===c.subject&&u===c.object?c:(s++,new yW.Triple(l,c.predicate,u))}),remapCount:s,uniqueRemapCount:i.size}}static remapIfSynthA(e,t,r,i){if(e instanceof mW.Literal||e instanceof gW.BlankNode||!(e instanceof T3.IRI))return e;let s=oE.exec(e.value);if(!s)return e;let o=s[1].toLowerCase(),c=t.get(o);if(!c||c===e.value)return e;i.add(o);let l=r.get(c);return l||(l=new T3.IRI(c),r.set(c,l)),l}};Lg.IRICanonicalizer=Dg;Dg.SYNTH_A_IRI_PATTERN=oE});var kg=w(Ng=>{"use strict";Object.defineProperty(Ng,"__esModule",{value:!0});Ng.derivePath=R3;Ng.deriveLegacyFlatPath=bW;var x3="assetspaces",I3=/^[A-Za-z0-9._-]+$/;function R3(n){if(typeof n!="string")return null;let e=n.trim();if(e.length===0||/^file:\/\//i.test(e))return null;e=e.replace(/\/+$/,""),e=e.replace(/\.git$/i,"");let t=null;if(!e.includes("://")){let o=/^[^/@\s]+@[^/:\s]+:(.+)$/.exec(e);o&&(t=o[1])}if(t===null){let o=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"");o=o.replace(/^[^/@]+@/,"");let c=o.indexOf("/");if(c<0)return null;t=o.slice(c+1)}let r=t.split("/").filter(o=>o.length>0);if(r.length<2)return null;let i=r[0],s=r[1];return i==="."||i===".."||s==="."||s===".."||!I3.test(i)||!I3.test(s)?null:`${x3}/${i}/${s}`}a(R3,"derivePath");function bW(n){let e=R3(n);if(e===null)return null;let t=e.split("/")[2];if(t===void 0||t.length===0)return null;let r=t.startsWith("exoas-")?t.slice(6):t;return r.length===0?null:`${x3}/${r}`}a(bW,"deriveLegacyFlatPath")});var Mg=w(Qi=>{"use strict";Object.defineProperty(Qi,"__esModule",{value:!0});Qi.FILE_SPACE_CLASS_UID=void 0;Qi.frontmatterDeclaresFileSpace=SW;Qi.discoverFileSpaceExclusions=vW;var _W=kg();Qi.FILE_SPACE_CLASS_UID="aad8913e-5e9f-4047-879d-93cc46befd52";var C3=/\[\[([^\]|]+)(?:\|[^\]]*)?\]\]/g,aE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function P3(n){let e=Array.isArray(n)?n:[n],t=[];for(let r of e){if(typeof r!="string")continue;C3.lastIndex=0;let i;for(;(i=C3.exec(r))!==null;)t.push(i[1].trim())}return t}a(P3,"wikilinkTargets");function SW(n){return n?P3(n.exo__Instance_class).some(e=>aE.test(e)&&e.toLowerCase()===Qi.FILE_SPACE_CLASS_UID):!1}a(SW,"frontmatterDeclaresFileSpace");function O3(n,e){try{return n.getFrontmatter(e)}catch{return null}}a(O3,"readFrontmatterSafe");function wW(n){let e=n.exo__AssetSpace_source;if(typeof e=="string"&&e.length>0)return e;let t=n.exo__AssetSpace_git;return typeof t=="string"&&t.length>0?t:null}a(wW,"readSource");function vW(n){let e=[],t=[],r=[],i=new Map,s=a((c,l)=>{if(aE.test(c))return c.toLowerCase()===Qi.FILE_SPACE_CLASS_UID;let u=n.getFirstLinkpathDest(c,l);if(u==null)return!1;let f=i.get(u.path);if(f!==void 0)return f;let h=O3(n,u)?.exo__Asset_uid,p=typeof h=="string"&&h.toLowerCase()===Qi.FILE_SPACE_CLASS_UID;return i.set(u.path,p),p},"isFileSpaceClassRef"),o=a(c=>c.some(l=>aE.test(l)&&l.toLowerCase()===Qi.FILE_SPACE_CLASS_UID),"hasUuidFormRef");for(let c of n.getAllFiles()){let l=O3(n,c);if(!l)continue;let u=P3(l.exo__Instance_class);if(!u.some(p=>s(p,c.path)))continue;t.push(c.path),o(u)||r.push(`FileSpace declaration ${c.path} references the class via a label-form link only \u2014 the sync layer will not pick it up; use the UUID-form wikilink [[${Qi.FILE_SPACE_CLASS_UID}]] (UID-canon)`);let f=wW(l);if(f===null){r.push(`FileSpace declaration ${c.path} has no exo__AssetSpace_source/_git \u2014 mount path underivable, content NOT excluded from the index`);continue}let d=(0,_W.derivePath)(f);if(d===null){r.push(`FileSpace declaration ${c.path}: cannot derive mount path from source "${f}" \u2014 content NOT excluded from the index`);continue}let h=`${d}/`;c.path.startsWith(h)&&r.push(`FileSpace declaration ${c.path} lies INSIDE its own mount ${h} \u2014 it will be excluded from the index together with the content; move the declaration outside the mount folder`),e.push(h)}return{prefixes:e,declarationPaths:t,warnings:r}}a(vW,"discoverFileSpaceExclusions")});var F3=w(Zn=>{"use strict";var EW=Zn&&Zn.__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},TW=Zn&&Zn.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Zn,"__esModule",{value:!0});Zn.LazyAssetGraphLoader=Zn.MAX_LAZY_DEPTH=void 0;var AW=Be(),IW=Oe(),cE=zt();Zn.MAX_LAZY_DEPTH=10;var lE=class{static{a(this,"LazyAssetGraphLoader")}constructor(e,t,r){this.converter=e,this.fileResolver=t,this.store=r,this.loadedIRIs=new Set,this.instanceClassPredicate=cE.Namespace.EXO.term("Instance_class"),this.superClassPredicate=cE.Namespace.EXO.term("Class_superClass"),this.prototypePredicate=cE.Namespace.EXO.term("Asset_prototype")}async ensureFileLoaded(e,t=0){if(t>=Zn.MAX_LAZY_DEPTH)return;let r=this.converter.notePathToIRI(e.path).value;if(!this.loadedIRIs.has(r)){this.loadedIRIs.add(r);try{let i=await this.converter.convertNote(e);if(!this.loadedIRIs.has(r)||(await this.store.addAll(i),!this.loadedIRIs.has(r)))return;await this.walkClassAndPrototypeRelations(i,t+1)}catch(i){throw this.loadedIRIs.delete(r),i}}}async ensureLoadedByIRI(e,t=0){if(t>=Zn.MAX_LAZY_DEPTH||this.loadedIRIs.has(e.value))return;let r=this.fileResolver.resolveByIRI(e);r!==null&&await this.ensureFileLoaded(r,t)}isLoaded(e){return this.loadedIRIs.has(e.value)}forget(e){this.loadedIRIs.delete(e.value)}clearAll(){this.loadedIRIs.clear()}get loadedCount(){return this.loadedIRIs.size}clearForTests(){this.loadedIRIs.clear()}async walkClassAndPrototypeRelations(e,t){let r=[];for(let i of e){if(!(i.object instanceof IW.IRI))continue;let s=i.predicate.value;(s===this.instanceClassPredicate.value||s===this.superClassPredicate.value||s===this.prototypePredicate.value)&&r.push(i.object)}for(let i of r)await this.ensureLoadedByIRI(i,t)}};Zn.LazyAssetGraphLoader=lE;Zn.LazyAssetGraphLoader=lE=EW([(0,AW.injectable)(),TW("design:paramtypes",[Object,Object,Object])],lE)});var fE=w(_r=>{"use strict";var xW=_r&&_r.__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},RW=_r&&_r.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(_r,"__esModule",{value:!0});_r.SourceAnnotator=_r.DEPTH_VARIABLE=_r.SOURCE_VARIABLE=void 0;var CW=Be(),eu=Ge(),OW=Oe(),jg=sE();_r.SOURCE_VARIABLE="_source";_r.DEPTH_VARIABLE="_depth";var uE=class{static{a(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(o=>{let c=o.clone();return c.set(_r.SOURCE_VARIABLE,new eu.Literal("own")),c});let s=[];for(let o of e){let c=o.get(t),l=o.get(r),u=o.get(i),f=o.clone();if(!c||!l||!u)f.set(_r.SOURCE_VARIABLE,new eu.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(_r.SOURCE_VARIABLE,new eu.Literal(d))}s.push(f)}return s}async annotateSingle(e,t,r,i){return(await this.annotate([e],t,r,i))[0]}async determineSource(e,t,r){return this.tripleStore.matchInGraph&&(await this.tripleStore.matchInGraph(e,t,r,jg.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=jg.MAX_PROTOTYPE_DEPTH;i++){let s=(0,jg.inferredGraphForDepth)(i);if((await this.tripleStore.matchInGraph(e,t,r,s)).length>0)return i}return 0}async annotateBySubject(e,t){if(!this.tripleStore.matchInGraph)return e.map(s=>{let o=s.clone();return o.set(_r.SOURCE_VARIABLE,new eu.Literal("own")),o});let r=[],i=new Map;for(let s of e){let o=s.get(t),c=s.clone();if(!o||!(o instanceof OW.IRI))c.set(_r.SOURCE_VARIABLE,new eu.Literal("own"));else{let l=o.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(o,void 0,void 0,jg.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(_r.SOURCE_VARIABLE,new eu.Literal(u))}r.push(c)}return r}};_r.SourceAnnotator=uE;_r.SourceAnnotator=uE=xW([(0,CW.injectable)(),RW("design:paramtypes",[Object])],uE)});var mE=w(ei=>{"use strict";var PW=ei&&ei.__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},FW=ei&&ei.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},D3=ei&&ei.__param||function(n,e){return function(t,r){e(t,r,n)}},pE;Object.defineProperty(ei,"__esModule",{value:!0});ei.NoteToRDFConverter=void 0;ei.normaliseExcludedFolders=M3;ei.isPathExcluded=j3;var dE=Be(),lr=Qn(),Yi=Oe(),bn=Ge(),L3=jt(),Kt=zt(),N3=Bt(),DW=Qv(),LW=ol(),hE=zv(),Un=Z_(),NW=Mg(),k3=new Set(["archived","draft","pinned","aliases"]);function M3(n){return Array.isArray(n)?n.map(e=>String(e).replace(/\\/g,"/").trim()).filter(e=>e.length>0).map(e=>e.endsWith("/")?e:`${e}/`):[]}a(M3,"normaliseExcludedFolders");function j3(n,e){if(e.length===0)return!1;let t=n.replace(/\\/g,"/");for(let r of e)if(t.startsWith(r))return!0;return!1}a(j3,"isPathExcluded");function kW(n){if(!n)return"";let e=n.replace(/\\/g,"/");for(;e.startsWith("/");)e=e.slice(1);for(;e.endsWith("/");)e=e.slice(0,-1);return e.length>0?`${e}/`:""}a(kW,"normaliseSubjectIriPrefix");var Ec=pE=class{static{a(this,"NoteToRDFConverter")}constructor(e,t=LW.NullLogger,r={}){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new DW.RDFVocabularyMapper,this.subjectIriPrefix=kW(r.subjectIriPrefix)}async convertNote(e){return this.convertNoteFromFrontmatter(e,this.vault.getFrontmatter(e))}async convertNoteFromFrontmatter(e,t){if(!t)return[];let r=this.notePathToIRI(e.path),i=Kt.Namespace.EXO.term("Asset_filename"),s=new lr.Triple(r,i,new bn.Literal(e.basename));if(Un.Exo003Parser.isExo003Format(t)){let o=await this.convertExo003Note(e,t);return[s,...o]}return this.convertLegacyNote(e,t,s)}async convertLegacyNote(e,t,r){this.pendingExtraTriples=[];let i=[r],s=this.notePathToIRI(e.path),o,c,l,u=!1,f=Kt.Namespace.EXO.term("Statement").value;for(let[y,b]of Object.entries(t)){let S=k3.has(y)?`exo__Asset_${y}`:y;if(!this.isExocortexProperty(S))continue;let v=this.propertyKeyToIRI(S),I=Array.isArray(b)?b:[b];for(let A of I)if(!((y==="exo__Asset_label"||k3.has(y))&&(A==null||typeof A=="string"&&A.trim()==="")))if(y==="exo__Instance_class"){let T=this.valueToClassURI(A);i.push(new lr.Triple(s,v,T))}else{let T=await this.valueToRDFObject(A,e,v);if(S==="exo__Statement_subject"&&o===void 0){let R=T.find(B=>B instanceof Yi.IRI);R&&(o=R)}else if(S==="exo__Statement_predicate"&&c===void 0){let R=T.find(B=>B instanceof Yi.IRI);R&&(c=R)}else S==="exo__Statement_object"&&l===void 0&&(l=T[0]);for(let R of T)if(i.push(new lr.Triple(s,v,R)),this.vocabularyMapper.hasMappingFor(y)&&R instanceof Yi.IRI){let B=this.vocabularyMapper.generateMappedTriple(s,y,R);B&&i.push(B)}}if(y==="exo__Instance_class")for(let A of I){let T=this.valueToClassURI(A);if(T instanceof Yi.IRI){let R=Kt.Namespace.RDF.term("type");i.push(new lr.Triple(s,R,T)),T.value===f&&(u=!0)}}if(y==="exo__Asset_label"){let A=Kt.Namespace.RDFS.term("label");for(let T of I)typeof T=="string"&&T.length>0&&i.push(new lr.Triple(s,A,new bn.Literal(T)))}}let d="exo__Instance_class"in t||"exo__Asset_uid"in t,h=t.exo__Asset_label,p="exo__Asset_label"in t&&h!==null&&h!==void 0&&!(typeof h=="string"&&h.trim()==="")&&!(Array.isArray(h)&&h.length===0);if(d&&!p){let y=Kt.Namespace.RDFS.term("label"),b=Kt.Namespace.EXO.term("Asset_label"),S=new bn.Literal(e.basename);i.push(new lr.Triple(s,y,S)),i.push(new lr.Triple(s,b,S))}i.push(...this.pendingExtraTriples),this.pendingExtraTriples=[],u&&o&&c&&l&&i.push(new lr.Triple(o,c,l));let g=await this.convertBodyWikilinks(e,s);return i.push(...g),i}async convertExo003Note(e,t){let r=Un.Exo003Parser.parse(t);if(!r.success||!r.metadata)return[];let i=r.metadata,s=[];switch(i.metadata){case Un.Exo003MetadataType.Namespace:break;case Un.Exo003MetadataType.Anchor:s.push(...this.convertExo003Anchor(e,i));break;case Un.Exo003MetadataType.BlankNode:s.push(...this.convertExo003BlankNode(e,i));break;case Un.Exo003MetadataType.Statement:s.push(...this.convertExo003Statement(e,i));break;case Un.Exo003MetadataType.Body:s.push(...await this.convertExo003Body(e,i));break}return s}convertExo003Anchor(e,t){let r=this.notePathToIRI(e.path),i=new Yi.IRI(t.uri);return[new lr.Triple(r,Kt.Namespace.OWL.term("sameAs"),i),new lr.Triple(i,Kt.Namespace.OWL.term("sameAs"),r)]}convertExo003BlankNode(e,t){let r=this.notePathToIRI(e.path),i=t.uri.replace(/[^a-zA-Z0-9_-]/g,"_");return[new lr.Triple(r,Kt.Namespace.OWL.term("sameAs"),new L3.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Un.Exo003Parser.toTriple(t,i);r.push(s);let o=this.notePathToIRI(e.path);r.push(new lr.Triple(o,Kt.Namespace.RDF.term("value"),s.subject))}catch{}return r}async convertExo003Body(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.createExo003ReferenceResolver(e),c=o(t.subject),l=o(t.predicate);if(c.type==="literal")throw new Error("Body subject cannot be a literal");if(l.type!=="iri")throw new Error("Body predicate must be an IRI");let u=c.type==="iri"?new Yi.IRI(c.value):new L3.BlankNode(c.value),f=new Yi.IRI(l.value),d=Un.Exo003Parser.toLiteral(t,s.trim());r.push(new lr.Triple(u,f,d));let h=this.notePathToIRI(e.path);r.push(new lr.Triple(h,Kt.Namespace.RDF.term("value"),u))}catch{}return r}createExo003ReferenceResolver(e){return t=>{let r=this.extractWikilink(t),i=r||t,s=this.vault.getFirstLinkpathDest(i,e.path);if(s){let o=this.vault.getFrontmatter(s);if(o&&Un.Exo003Parser.isExo003Format(o)){let c=Un.Exo003Parser.parse(o);if(c.success&&c.metadata){let l=c.metadata;if(l.metadata===Un.Exo003MetadataType.Anchor||l.metadata===Un.Exo003MetadataType.Namespace)return{type:"iri",value:l.uri};if(l.metadata===Un.Exo003MetadataType.BlankNode)return{type:"blank",value:l.uri.replace(/[^a-zA-Z0-9_-]/g,"_")}}}return{type:"iri",value:this.notePathToIRI(s.path).value}}return!r&&t.includes("://")?{type:"iri",value:t}:{type:"literal",value:t}}}async convertVault(e={}){return(await this.convertVaultWithValidation({strict:!1,excludedFolders:e.excludedFolders})).triples}async convertVaultWithValidation(e={}){let t=this.vault.getAllFiles(),r=[],i=[],s=e.strict??!1,o=0,c=0,l=(0,NW.discoverFileSpaceExclusions)(this.vault);for(let y of l.warnings)this.logger.warn(`FileSpace discovery: ${y}`);let u=[...M3(e.excludedFolders),...l.prefixes],f=u.length===0?t:t.filter(y=>!j3(y.path,u)),d=e.onProgress,h=e.progressIntervalFiles&&e.progressIntervalFiles>0?e.progressIntervalFiles:pE.INDEX_PROGRESS_INTERVAL,p=f.length,g=0;for(let y of f){if(g++,d&&g%h===0&&g<p)try{d(g,p)}catch{}try{let b=this.vault.getFrontmatter(y),S=b?this.validateExocortexAsset(b,y.basename):null;if(S){if(s)throw new Error(`Invariant violation in "${y.path}": ${S.message}`);i.push({path:y.path,reason:`Invariant violation: ${S.message}`}),o++,this.logger.info(`Skipping file with invariant violation: ${y.path}`,{code:S.code,property:S.property,reason:S.message});continue}let v=await this.convertNote(y);r.push(...v)}catch(b){let S=b instanceof Error?b.message:String(b);if(s)throw new Error(`Invalid IRI for file "${y.path}": ${S}`);i.push({path:y.path,reason:`Invalid IRI: ${S}`}),c++,this.logger.info(`Skipping file with invalid IRI: ${y.path}`,{reason:S})}}return o>0&&this.logger.warn(`Skipped ${o} file${o===1?"":"s"} with invariant violations during indexing (paths in developer console)`,{count:o}),c>0&&this.logger.warn(`Skipped ${c} file${c===1?"":"s"} with invalid IRI during indexing (paths in developer console)`,{count:c}),{triples:r,skippedFiles:i,summary:{total:f.length,indexed:f.length-i.length,skipped:i.length},fileSpaces:l}}static inferLabelFromBasename(e){return Kt.Namespace.fromPropertyKey(e)!==null?e:null}validateExocortexAsset(e,t){let r=a(d=>d==null?!0:typeof d=="string"?d.trim()==="":Array.isArray(d)?d.length===0||d.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=["exo__Asset_uid","exo__Instance_class"];for(let d of s){if(!(d in e))return{code:"MISSING_PROPERTY",property:d,message:`Required property "${d}" is missing`};if(r(e[d]))return{code:"EMPTY_PROPERTY",property:d,message:`Required property "${d}" is empty`}}let o=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let d of o)if(d in e&&r(e[d]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:d,message:`Optional property "${d}" is present but empty`};let c=e.exo__Instance_class,l=Array.isArray(c)?c:[c],u=null,f=!1;for(let d of l){if(typeof d!="string")continue;let h=this.removeQuotes(d),g=(this.extractWikilink(h)??h).trim();/^[a-z][a-zA-Z0-9]*__/.test(g)&&/[\s()]/.test(g)?u||(u={candidate:d}):f=!0}return u&&!f?{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${u.candidate}"`}:null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,hE.vaultPathToIRI)(r.path);Yi.IRI.isValidIRI(i)||t.push({path:r.path,reason:`Path "${r.path}" cannot be converted to a valid IRI`})}return t}notePathToIRI(e){return new Yi.IRI((0,hE.vaultPathToIRI)(`${this.subjectIriPrefix}${e}`))}synthesizeWikilinkTargetIRI(e){return new Yi.IRI((0,hE.vaultPathToIRI)(e))}isExocortexProperty(e){return Kt.Namespace.fromPropertyKey(e)!==null}propertyKeyToIRI(e){let t=Kt.Namespace.fromPropertyKey(e);if(!t)throw new Error(`Invalid property key: ${e}`);return t.namespace.term(t.localName)}emitTypeTripleForEnumInstance(e,t){let r=this.vault.getFrontmatter(t);if(!r)return;let i=r.exo__Instance_class,s=Array.isArray(i)?i[0]:i;if(typeof s!="string")return;let o=this.valueToClassURI(s);o instanceof Yi.IRI&&(this.pendingExtraTriples.push(new lr.Triple(e,Kt.Namespace.RDF.term("type"),o)),this.pendingExtraTriples.push(new lr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),o)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let o=this.vault.getFirstLinkpathDest(s,t.path);if(o){let l=this.notePathToIRI(o.path),u=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(u)){let d=new bn.Literal(u);if(r?.value.endsWith("#Grounding_targetValueRef")||r?.value.endsWith("#Grounding_targetValueSubstitution")||r?.value.endsWith("#Grounding_targetClass")||r?.value.endsWith("#Grounding_type")||r?.value.endsWith("#PropertyDefault_value"))return[l];let p=this.expandClassValue(o.basename);if(p)return this.emitTypeTripleForEnumInstance(p,o),[p];let g=this.vault.getFrontmatter(o);if(g){let I=g.exo__Asset_label;if(typeof I=="string"){let A=this.expandClassValue(I);if(A)return this.emitTypeTripleForEnumInstance(A,o),[A]}}let y=r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype"),S=((typeof process<"u"?process.env:void 0)?.EXOCORTEX_DUAL_STORAGE_PREDICATES??"").split(",").map(I=>I.trim()).filter(Boolean),v=S.length>0&&S.some(I=>r?.value.endsWith(`#${I}`));return y||v?[l,d]:[l]}let f=this.expandClassValue(o.basename);return f?(this.emitTypeTripleForEnumInstance(f,o),[f]):[l]}if(this.isClassReference(s)){let l=this.expandClassValue(s);if(l)return[l]}let c=s.includes("|")?s.split("|")[0]:s;return this.isUUID(c)?[this.synthesizeWikilinkTargetIRI(`${c}.md`)]:[new bn.Literal(i)]}if(this.isClassReference(i)){let o=this.expandClassValue(i);if(o)return[o]}return this.isISO8601DateTime(i)?[new bn.Literal(i,Kt.Namespace.XSD.term("dateTime"))]:[new bn.Literal(i)]}return typeof e=="boolean"?[new bn.Literal(e.toString())]:typeof e=="number"?[new bn.Literal(e.toString(),Kt.Namespace.XSD.term("decimal"))]:e instanceof Date?[new bn.Literal(e.toISOString(),Kt.Namespace.XSD.term("dateTime"))]:[new bn.Literal(String(e))]}isISO8601DateTime(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/.test(e)}removeQuotes(e){let t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.substring(1,t.length-1):e}extractWikilink(e){let t=e.match(/^\[\[([^\]]+)\]\]$/);if(!t)return null;let r=t[1];return r.includes("|")?r.split("|")[0]:r}extractWikilinkAlias(e){let t=e.match(/^\[\[([^\]]+)\]\]$/);if(!t)return null;let r=t[1],i=r.indexOf("|");return i>=0?r.substring(i+1).trim():null}valueToClassURI(e){if(typeof e!="string")return new bn.Literal(String(e));let t=this.removeQuotes(e),i=this.extractWikilink(t)||t,s=this.expandClassValue(i);if(s)return s;let o=this.extractWikilinkAlias(t);if(o){let c=this.expandClassValue(o);if(c)return c}if(this.isUUID(i)){let c=this.vault.getFirstLinkpathDest(i,"");if(c){let l=this.expandClassValue(c.basename);if(l)return l;let u=this.vault.getFrontmatter(c);if(u){let f=u.exo__Asset_label;if(typeof f=="string"){let d=this.expandClassValue(f);if(d)return d}}return this.notePathToIRI(c.path)}}return new bn.Literal(t)}isClassReference(e){return/\s/.test(e)?!1:Kt.Namespace.fromPropertyKey(e)!==null}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}expandClassValue(e){let t=this.removeQuotes(e),r=Kt.Namespace.fromPropertyKey(t);return!r||/[\s()]/.test(r.localName)?null:r.namespace.term(r.localName)}extractBodyContent(e){let t=/^---\r?\n[\s\S]*?\r?\n---\r?\n?/;return e.replace(t,"")}extractBodyWikilinks(e){let t=new Set,r,i=new RegExp(this.BODY_WIKILINK_PATTERN.source,"g");for(;(r=i.exec(e))!==null;)r[1]&&t.add(r[1]);return Array.from(t)}async convertBodyWikilinks(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of o){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new lr.Triple(t,c,f))}else if(this.isClassReference(l)){let f=this.expandClassValue(l);f?r.push(new lr.Triple(t,c,f)):r.push(new lr.Triple(t,c,new bn.Literal(l)))}else r.push(new lr.Triple(t,c,new bn.Literal(l)))}}catch{}return r}};ei.NoteToRDFConverter=Ec;Ec.INDEX_PROGRESS_INTERVAL=200;Ec.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};Ec.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};Ec.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};ei.NoteToRDFConverter=Ec=pE=PW([(0,dE.injectable)(),D3(0,(0,dE.inject)(N3.DI_TOKENS.IVaultAdapter)),D3(1,(0,dE.inject)(N3.DI_TOKENS.ILogger)),FW("design:paramtypes",[Object,Object,Object])],Ec)});var yE=w($g=>{"use strict";Object.defineProperty($g,"__esModule",{value:!0});$g.FilterContainsOptimizer=void 0;var MW=Oe(),jW=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,gE=class{static{a(this,"FilterContainsOptimizer")}constructor(){this.tripleStore=null,this.lastOptimizationHints=[]}setTripleStore(e){this.tripleStore=e}getLastOptimizationHints(){return this.lastOptimizationHints}clearHints(){this.lastOptimizationHints=[]}async optimize(e){return this.clearHints(),this.optimizeRecursive(e)}optimizeSync(e,t){return this.clearHints(),this.optimizeSyncRecursive(e,t)}async optimizeRecursive(e){return e.type==="filter"?this.optimizeFilter(e):e.type==="join"?{type:"join",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="leftjoin"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="union"?{type:"union",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="minus"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="project"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="orderby"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="slice"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="distinct"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="reduced"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="group"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="extend"?{...e,input:await this.optimizeRecursive(e.input)}:e}optimizeSyncRecursive(e,t){return e.type==="filter"?this.optimizeFilterSync(e,t):e.type==="join"?{type:"join",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="leftjoin"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="union"?{type:"union",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="minus"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="project"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="orderby"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="slice"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="distinct"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="reduced"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="group"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="extend"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e}async optimizeFilter(e){let t=this.detectContainsUUIDPattern(e.expression);if(!t)return{type:"filter",expression:e.expression,input:await this.optimizeRecursive(e.input)};let r=[];return this.tripleStore&&(r=await this.findSubjectsContainingUUID(t.uuid)),this.rewriteFilter(e,t,r)}optimizeFilterSync(e,t){let r=this.detectContainsUUIDPattern(e.expression);if(!r)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input,t)};let i=t?t.filter(s=>s.includes(r.uuid)):[];return this.rewriteFilter(e,r,i)}rewriteFilter(e,t,r){if(this.lastOptimizationHints.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${t.variable}), "${t.uuid}"))`,suggestedRewrite:r.length===1?`VALUES ?${t.variable} { <${r[0]}> }`:r.length>1?`VALUES ?${t.variable} { ${r.map(i=>`<${i}>`).join(" ")} }`:"No matching URIs found for UUID",estimatedSpeedup:r.length>0?"O(n) \u2192 O(1)":"N/A",matchedUri:r.length===1?r[0]:void 0}),r.length===0)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input)};if(r.length===1){let i=this.injectSubjectConstraint(e.input,t.variable,r[0]);if(i!==e.input)return i}return this.createValuesJoin(e,t,r)}detectContainsUUIDPattern(e){if(e.type==="function"||e.type==="functionCall"){let t=e;if((typeof t.function=="string"?t.function.toLowerCase():t.function?.value?.toLowerCase()??"")==="contains"&&t.args.length===2)return this.analyzeContainsArgs(t.args[0],t.args[1],e)}if(e.type==="logical"&&e.operator==="&&")for(let t of e.operands){let r=this.detectContainsUUIDPattern(t);if(r)return r}return null}analyzeContainsArgs(e,t,r){let i=null;if(e.type==="function"||e.type==="functionCall"){let s=e;if((typeof s.function=="string"?s.function.toLowerCase():s.function?.value?.toLowerCase()??"")==="str"&&s.args.length===1){let c=s.args[0];c.type==="variable"&&(i=c.name)}}if(!i&&e.type==="variable"&&(i=e.name),!i)return null;if(t.type==="literal"){let c=String(t.value).match(jW);if(c)return{variable:i,uuid:c[0].toLowerCase(),originalExpression:r}}return null}async findSubjectsContainingUUID(e){if(!this.tripleStore)return[];if(this.tripleStore.findSubjectsByUUID)return(await this.tripleStore.findSubjectsByUUID(e)).map(s=>s.value);let t=await this.tripleStore.subjects(),r=[];for(let i of t)i instanceof MW.IRI&&i.value.toLowerCase().includes(e.toLowerCase())&&r.push(i.value);return r}injectSubjectConstraint(e,t,r){if(e.type==="bgp"){let i=e.triples.map(o=>o.subject.type==="variable"&&o.subject.value===t?{...o,subject:{type:"iri",value:r}}:o);if(i.some((o,c)=>o.subject!==e.triples[c].subject))return{type:"bgp",triples:i}}if(e.type==="join"){let i=this.injectSubjectConstraint(e.left,t,r),s=this.injectSubjectConstraint(e.right,t,r);if(i!==e.left||s!==e.right)return{type:"join",left:i,right:s}}if(e.type==="filter"){let i=this.injectSubjectConstraint(e.input,t,r);if(i!==e.input)return{...e,input:i}}return e}createValuesJoin(e,t,r){return{type:"join",left:{type:"values",variables:[t.variable],bindings:r.map(o=>({[t.variable]:{type:"iri",value:o}}))},right:this.optimizeSyncRecursive(e.input)}}analyzeQuery(e){let t=[];return this.analyzeRecursive(e,t),t}analyzeRecursive(e,t){if(e.type==="filter"){let r=this.detectContainsUUIDPattern(e.expression);r&&t.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${r.variable}), "${r.uuid}"))`,suggestedRewrite:`Use --optimize flag or rewrite as VALUES ?${r.variable} { <uri-containing-uuid> }`,estimatedSpeedup:"O(n) \u2192 O(1) with UUID index lookup"}),this.analyzeRecursive(e.input,t);return}e.type==="join"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="leftjoin"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="union"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="minus"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="project"?this.analyzeRecursive(e.input,t):e.type==="orderby"?this.analyzeRecursive(e.input,t):e.type==="slice"?this.analyzeRecursive(e.input,t):e.type==="distinct"?this.analyzeRecursive(e.input,t):e.type==="reduced"?this.analyzeRecursive(e.input,t):e.type==="group"?this.analyzeRecursive(e.input,t):e.type==="extend"&&this.analyzeRecursive(e.input,t)}};$g.FilterContainsOptimizer=gE});var $3=w(Ug=>{"use strict";Object.defineProperty(Ug,"__esModule",{value:!0});Ug.AlgebraOptimizer=void 0;var $W=yE(),bE=class{static{a(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new $W.FilterContainsOptimizer}setTripleStore(e){this.tripleStore=e,this.filterContainsOptimizer.setTripleStore(e)}getOptimizationHints(){return this.filterContainsOptimizer.getLastOptimizationHints()}analyzeQuery(e){return this.filterContainsOptimizer.analyzeQuery(e)}optimize(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),t=this.filterPushDown(t),t=this.joinReordering(t),t}async optimizeAsync(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),this.tripleStore&&(t=await this.filterContainsOptimizer.optimize(t)),t=this.filterPushDown(t),t=this.joinReordering(t),t}optimizeWithSubjects(e,t){let r=e;return r=this.eliminateEmptyBGPInFilterJoin(r),r=this.filterContainsOptimizer.optimizeSync(r,t),r=this.filterPushDown(r),r=this.joinReordering(r),r}eliminateEmptyBGPInFilterJoin(e){if(e.type==="join"){if(e.left.type==="filter"){let t=e.left;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.right)}}if(e.right.type==="filter"){let t=e.right;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.left)}}return{type:"join",left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}}return e.type==="filter"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="leftjoin"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="union"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="minus"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="project"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="orderby"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="slice"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="distinct"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e}filterPushDown(e){return e.type==="filter"?this.pushDownFilter(e):e.type==="join"?{type:"join",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="leftjoin"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="union"?{type:"union",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="minus"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="project"?{...e,input:this.filterPushDown(e.input)}:e.type==="orderby"?{...e,input:this.filterPushDown(e.input)}:e.type==="slice"?{...e,input:this.filterPushDown(e.input)}:e.type==="distinct"?{...e,input:this.filterPushDown(e.input)}:e}pushDownFilter(e){let t=e.input;if(t.type==="join"){let r=this.getFilterVariables(e.expression),i=this.getOperationVariables(t.left),s=this.getOperationVariables(t.right),o=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return o&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!o?{type:"join",left:this.filterPushDown(t.left),right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:{type:"join",left:this.filterPushDown(t.left),right:this.filterPushDown(t.right)}}}return t.type==="union"?{type:"union",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:this.filterPushDown(t)}}getFilterVariables(e){let t=[];if(e.type==="variable")t.push(e.name);else if(e.type==="comparison")t.push(...this.getFilterVariables(e.left)),t.push(...this.getFilterVariables(e.right));else if(e.type==="logical")for(let r of e.operands)t.push(...this.getFilterVariables(r));else if(e.type==="function")for(let r of e.args)t.push(...this.getFilterVariables(r));return Array.from(new Set(t))}getOperationVariables(e){let t=new Set;if(e.type==="bgp")for(let r of e.triples)r.subject.type==="variable"&&t.add(r.subject.value),r.predicate.type==="variable"&&t.add(r.predicate.value),r.object.type==="variable"&&t.add(r.object.value);else if(e.type==="join"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="filter")return this.getOperationVariables(e.input);if(e.type==="leftjoin"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else if(e.type==="union"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="minus")return this.getOperationVariables(e.left);if(e.type==="project")return new Set(e.variables)}}return t}joinReordering(e){return e.type==="join"?this.reorderJoin(e):e.type==="filter"?{...e,input:this.joinReordering(e.input)}:e.type==="leftjoin"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="union"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="minus"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="project"?{...e,input:this.joinReordering(e.input)}:e.type==="orderby"?{...e,input:this.joinReordering(e.input)}:e.type==="slice"?{...e,input:this.joinReordering(e.input)}:e.type==="distinct"?{...e,input:this.joinReordering(e.input)}:e}reorderJoin(e){let t=this.isConstrained(e.left),r=this.isConstrained(e.right);if(r&&!t)return{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)};if(t&&!r)return{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)};let i=this.estimateCost(e.left);return this.estimateCost(e.right)<i?{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)}:{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)}}isConstrained(e){return e.type==="values"?!0:e.type==="bgp"?e.triples.some(t=>t.object.type!=="variable"||t.subject.type!=="variable"):e.type==="filter"?this.isConstrained(e.input):e.type==="join"?this.isConstrained(e.left)||this.isConstrained(e.right):e.type==="union"?this.isConstrained(e.left)&&this.isConstrained(e.right):!1}estimateCost(e){if(e.type==="bgp"){let t=0;for(let r of e.triples){let i=10;r.subject.type==="variable"&&(i*=10),r.predicate.type==="variable"&&(i*=20),r.object.type==="variable"&&(i*=5),t+=i}return t}if(e.type==="filter")return this.estimateCost(e.input)*.3;if(e.type==="join"){let t=this.estimateCost(e.left),r=this.estimateCost(e.right);return e.left.type==="values"||e.right.type==="values"?Math.min(t,r)*2:t*r}if(e.type==="leftjoin")return this.estimateCost(e.left)+this.estimateCost(e.right)*.5;if(e.type==="union")return this.estimateCost(e.left)+this.estimateCost(e.right);if(e.type==="values"){let t=e.bindings;return Array.isArray(t)?t.length*5:10}return e.type==="minus"?this.estimateCost(e.left)+this.estimateCost(e.right)*.3:100}setStatistics(e,t){this.stats.set(e,t)}getStatistics(e){return this.stats.get(e)}};Ug.AlgebraOptimizer=bE});var U3=w(Bg=>{"use strict";Object.defineProperty(Bg,"__esModule",{value:!0});Bg.AlgebraSerializer=void 0;var _E=class{static{a(this,"AlgebraSerializer")}toString(e,t=0){let r=" ".repeat(t);switch(e.type){case"bgp":return`${r}BGP [
223
+ `),t}};Cg.RDFSerializer=Hv});var zv=w(Ro=>{"use strict";Object.defineProperty(Ro,"__esModule",{value:!0});Ro.OBSIDIAN_VAULT_SCHEME=void 0;Ro.vaultPathToIRI=rW;Ro.iriToVaultPath=nW;Ro.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function rW(n){let e=n.startsWith("./")?n.slice(2):n;return`${Ro.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}a(rW,"vaultPathToIRI");function nW(n){if(!n.startsWith(Ro.OBSIDIAN_VAULT_SCHEME))return null;let e=n.slice(Ro.OBSIDIAN_VAULT_SCHEME.length);try{return decodeURI(e)}catch{return null}}a(nW,"iriToVaultPath")});var Qv=w(Og=>{"use strict";Object.defineProperty(Og,"__esModule",{value:!0});Og.RDFVocabularyMapper=void 0;var cr=Qn(),y3=Oe(),he=zt(),Kv=class{static{a(this,"RDFVocabularyMapper")}constructor(){this.propertyMappings=new Map([["exo__Instance_class",he.Namespace.RDF.term("type")],["exo__Asset_isDefinedBy",he.Namespace.RDFS.term("isDefinedBy")],["exo__Class_superClass",he.Namespace.RDFS.term("subClassOf")],["exo__Property_range",he.Namespace.RDFS.term("range")],["exo__Property_domain",he.Namespace.RDFS.term("domain")],["exo__Property_superProperty",he.Namespace.RDFS.term("subPropertyOf")]])}generateClassHierarchyTriples(){let e=[];return e.push(new cr.Triple(he.Namespace.EXO.term("Asset"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDFS.term("Resource"))),e.push(new cr.Triple(he.Namespace.EXO.term("Class"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDFS.term("Class"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.RDF.term("Property"))),e.push(new cr.Triple(he.Namespace.EMS.term("Task"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Project"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Area"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("Workflow"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("WorkflowState"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EMS.term("WorkflowTransition"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Command"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Precondition"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("Grounding"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e.push(new cr.Triple(he.Namespace.EXOCMD.term("CommandBinding"),he.Namespace.RDFS.term("subClassOf"),he.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new cr.Triple(he.Namespace.EXO.term("Instance_class"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDF.term("type"))),e.push(new cr.Triple(he.Namespace.EXO.term("Asset_isDefinedBy"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("isDefinedBy"))),e.push(new cr.Triple(he.Namespace.EXO.term("Class_superClass"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("subClassOf"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_range"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("range"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_domain"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("domain"))),e.push(new cr.Triple(he.Namespace.EXO.term("Property_superProperty"),he.Namespace.RDFS.term("subPropertyOf"),he.Namespace.RDFS.term("subPropertyOf"))),e}generateMappedTriple(e,t,r){let i=this.propertyMappings.get(t);if(!i)return null;let s;if(r instanceof y3.IRI)s=r;else{let o=r.match(/^(ems|exo|exocmd)__(.+)$/);if(o){let[,c,l]=o;s=(c==="ems"?he.Namespace.EMS:c==="exocmd"?he.Namespace.EXOCMD:he.Namespace.EXO).term(l)}else s=new y3.IRI(r)}return new cr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};Og.RDFVocabularyMapper=Kv});var b3=w(Fg=>{"use strict";Object.defineProperty(Fg,"__esModule",{value:!0});Fg.RDFSInferenceEngine=void 0;var iW=Qn(),Pg=Oe(),Yv=class{static{a(this,"RDFSInferenceEngine")}async materialize(e){let t=await e.predicates(),r=t.find(d=>d.value.includes("Class_superClass")),i=t.find(d=>d.value.includes("Instance_class"));if(!r||!i)return 0;let s=await this.buildDirectParentMap(e,r);if(s.size===0)return 0;let o=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof Pg.IRI){let h=o.get(d.object.value);if(h)for(let p of h)u.push(new iW.Triple(d.subject,i,new Pg.IRI(p)))}return u.length>0&&await e.addAll(u),await e.count()-c}async buildDirectParentMap(e,t){let r=await e.match(void 0,t),i=new Map;for(let s of r)if(s.subject instanceof Pg.IRI&&s.object instanceof Pg.IRI){let o=s.subject.value,c=s.object.value;i.has(o)||i.set(o,new Set),i.get(o).add(c)}return i}computeAllAncestors(e){let t=new Map;for(let r of e.keys())t.has(r)||t.set(r,this.computeAncestorsBFS(r,e));return t}computeAncestorsBFS(e,t){let r=new Set,i=new Set,s=[],o=t.get(e);if(o)for(let c of o)s.push(c);for(;s.length>0;){let c=s.shift();if(i.has(c))continue;i.add(c),r.add(c);let l=t.get(c);if(l)for(let u of l)i.has(u)||s.push(u)}return r}};Fg.RDFSInferenceEngine=Yv});var Zv=w(wc=>{"use strict";var sW=wc&&wc.__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};Object.defineProperty(wc,"__esModule",{value:!0});wc.NonInheritablePropertyRegistry=void 0;var oW=Be(),_3=Oe(),S3=Ge(),Xv=zt(),Jv=class{static{a(this,"NonInheritablePropertyRegistry")}constructor(){this.nonInheritableIRIs=new Set,this.initialized=!1}async initialize(e){this.nonInheritableIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Instance_class"));if(!r){this.initialized=!0;return}let i=await this.findNonInheritableClassIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof S3.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.nonInheritableIRIs.add(d)}}}catch{}this.initialized=!0}isNonInheritable(e){return this.nonInheritableIRIs.has(e)}get size(){return this.nonInheritableIRIs.size}get isInitialized(){return this.initialized}async findNonInheritableClassIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new S3.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof _3.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof _3.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?Xv.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?Xv.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?Xv.Namespace.EXOCMD.term(e.substring(8)).value:null}};wc.NonInheritablePropertyRegistry=Jv;wc.NonInheritablePropertyRegistry=Jv=sW([(0,oW.injectable)()],Jv)});var rE=w(vc=>{"use strict";var aW=vc&&vc.__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};Object.defineProperty(vc,"__esModule",{value:!0});vc.PropertyCardinalityRegistry=void 0;var cW=Be(),w3=Oe(),v3=Ge(),eE=zt(),tE=class{static{a(this,"PropertyCardinalityRegistry")}constructor(){this.multiValuedIRIs=new Set,this.initialized=!1}async initialize(e){this.multiValuedIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Property_cardinality"));if(!r){this.initialized=!0;return}let i=await this.findMultipleCardinalityIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof v3.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.multiValuedIRIs.add(d)}}}catch{}this.initialized=!0}isMultiValued(e){return this.multiValuedIRIs.has(e)}get size(){return this.multiValuedIRIs.size}get isInitialized(){return this.initialized}async findMultipleCardinalityIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new v3.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof w3.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof w3.IRI&&c.object.value.includes("PropertyCardinalityMultiple"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?eE.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?eE.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?eE.Namespace.EXOCMD.term(e.substring(8)).value:null}};vc.PropertyCardinalityRegistry=tE;vc.PropertyCardinalityRegistry=tE=aW([(0,cW.injectable)()],tE)});var sE=w(xr=>{"use strict";var lW=xr&&xr.__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},uW=xr&&xr.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(xr,"__esModule",{value:!0});xr.PrototypeChainMaterializer=xr.MAX_PROTOTYPE_DEPTH=xr.INFERRED_GRAPH=void 0;xr.inferredGraphForDepth=nE;var fW=Be(),E3=Qn(),da=Oe(),dW=Zv(),hW=rE();xr.INFERRED_GRAPH=new da.IRI("https://exocortex.my/ontology/exo#inferred");var pW="https://exocortex.my/ontology/exo#inferred/";function nE(n){return new da.IRI(`${pW}${n}`)}a(nE,"inferredGraphForDepth");xr.MAX_PROTOTYPE_DEPTH=10;var iE=class{static{a(this,"PrototypeChainMaterializer")}constructor(e,t){this.registry=e,this.cardinalityRegistry=t??null}async materialize(e){let r=(await e.predicates()).find(c=>c.value.includes("Asset_prototype"));if(!r)return 0;let i=await e.match(void 0,r,void 0);if(i.length===0)return 0;let s=new Map;for(let c of i)if(c.subject instanceof da.IRI&&c.object instanceof da.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let o=0;for(let[c]of s){let l=new da.IRI(c),u=this.resolveChain(c,s);if(u.length===0)continue;let f=await e.match(l,void 0,void 0),d=new Set,h=new Map;for(let p of f)if(d.add(p.predicate.value),this.isMultiValued(p.predicate.value)){let g=p.object instanceof da.IRI?p.object.value:String(p.object),y=h.get(p.predicate.value);y||(y=new Set,h.set(p.predicate.value,y)),y.add(g)}for(let p=0;p<u.length;p++){let g=u[p],y=p+1,b=new da.IRI(g),S=await e.match(b,void 0,void 0),v=new Set;if(e.matchInGraph){let I=await e.matchInGraph(b,void 0,void 0,xr.INFERRED_GRAPH);for(let A of I)v.add(A.predicate.value)}for(let I of S){let A=I.predicate.value;if(this.registry.isNonInheritable(A)||v.has(A))continue;if(d.has(A)&&this.isMultiValued(A)){let R=I.object instanceof da.IRI?I.object.value:String(I.object);if(h.get(A)?.has(R))continue;let L=h.get(A);L||(L=new Set,h.set(A,L)),L.add(R);let P=new E3.Triple(l,I.predicate,I.object);await e.add(P),e.addToGraph&&(await e.addToGraph(P,xr.INFERRED_GRAPH),await e.addToGraph(P,nE(y))),o++;continue}if(d.has(A))continue;let T=new E3.Triple(l,I.predicate,I.object);await e.add(T),e.addToGraph&&(await e.addToGraph(T,xr.INFERRED_GRAPH),await e.addToGraph(T,nE(y))),d.add(A),o++}}}return o}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],o=t.get(e);for(o&&s.push(o.value);s.length>0&&r.length<xr.MAX_PROTOTYPE_DEPTH;){let c=s.shift();if(c===void 0)break;if(i.has(c))continue;i.add(c),r.push(c);let l=t.get(c);l&&!i.has(l.value)&&s.push(l.value)}return r}};xr.PrototypeChainMaterializer=iE;xr.PrototypeChainMaterializer=iE=lW([(0,fW.injectable)(),uW("design:paramtypes",[dW.NonInheritablePropertyRegistry,hW.PropertyCardinalityRegistry])],iE)});var A3=w(Lg=>{"use strict";Object.defineProperty(Lg,"__esModule",{value:!0});Lg.IRICanonicalizer=void 0;var T3=Oe(),mW=Ge(),gW=jt(),yW=Qn(),oE=/^obsidian:\/\/vault\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.md$/i,Dg=class n{static{a(this,"IRICanonicalizer")}static extractSynthAUid(e){let t=oE.exec(e);return t?t[1].toLowerCase():null}static canonicalize(e,t){if(t.size===0)return{triples:e,remapCount:0,uniqueRemapCount:0};let r=new Map,i=new Set,s=0;return{triples:e.map(c=>{let l=n.remapIfSynthA(c.subject,t,r,i),u=n.remapIfSynthA(c.object,t,r,i);return l===c.subject&&u===c.object?c:(s++,new yW.Triple(l,c.predicate,u))}),remapCount:s,uniqueRemapCount:i.size}}static remapIfSynthA(e,t,r,i){if(e instanceof mW.Literal||e instanceof gW.BlankNode||!(e instanceof T3.IRI))return e;let s=oE.exec(e.value);if(!s)return e;let o=s[1].toLowerCase(),c=t.get(o);if(!c||c===e.value)return e;i.add(o);let l=r.get(c);return l||(l=new T3.IRI(c),r.set(c,l)),l}};Lg.IRICanonicalizer=Dg;Dg.SYNTH_A_IRI_PATTERN=oE});var kg=w(Ng=>{"use strict";Object.defineProperty(Ng,"__esModule",{value:!0});Ng.derivePath=R3;Ng.deriveLegacyFlatPath=bW;var x3="assetspaces",I3=/^[A-Za-z0-9._-]+$/;function R3(n){if(typeof n!="string")return null;let e=n.trim();if(e.length===0||/^file:\/\//i.test(e))return null;e=e.replace(/\/+$/,""),e=e.replace(/\.git$/i,"");let t=null;if(!e.includes("://")){let o=/^[^/@\s]+@[^/:\s]+:(.+)$/.exec(e);o&&(t=o[1])}if(t===null){let o=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"");o=o.replace(/^[^/@]+@/,"");let c=o.indexOf("/");if(c<0)return null;t=o.slice(c+1)}let r=t.split("/").filter(o=>o.length>0);if(r.length<2)return null;let i=r[0],s=r[1];return i==="."||i===".."||s==="."||s===".."||!I3.test(i)||!I3.test(s)?null:`${x3}/${i}/${s}`}a(R3,"derivePath");function bW(n){let e=R3(n);if(e===null)return null;let t=e.split("/")[2];if(t===void 0||t.length===0)return null;let r=t.startsWith("exoas-")?t.slice(6):t;return r.length===0?null:`${x3}/${r}`}a(bW,"deriveLegacyFlatPath")});var Mg=w(Qi=>{"use strict";Object.defineProperty(Qi,"__esModule",{value:!0});Qi.FILE_SPACE_CLASS_UID=void 0;Qi.frontmatterDeclaresFileSpace=SW;Qi.discoverFileSpaceExclusions=vW;var _W=kg();Qi.FILE_SPACE_CLASS_UID="aad8913e-5e9f-4047-879d-93cc46befd52";var C3=/\[\[([^\]|]+)(?:\|[^\]]*)?\]\]/g,aE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function P3(n){let e=Array.isArray(n)?n:[n],t=[];for(let r of e){if(typeof r!="string")continue;C3.lastIndex=0;let i;for(;(i=C3.exec(r))!==null;)t.push(i[1].trim())}return t}a(P3,"wikilinkTargets");function SW(n){return n?P3(n.exo__Instance_class).some(e=>aE.test(e)&&e.toLowerCase()===Qi.FILE_SPACE_CLASS_UID):!1}a(SW,"frontmatterDeclaresFileSpace");function O3(n,e){try{return n.getFrontmatter(e)}catch{return null}}a(O3,"readFrontmatterSafe");function wW(n){let e=n.exo__AssetSpace_source;if(typeof e=="string"&&e.length>0)return e;let t=n.exo__AssetSpace_git;return typeof t=="string"&&t.length>0?t:null}a(wW,"readSource");function vW(n){let e=[],t=[],r=[],i=new Map,s=a((c,l)=>{if(aE.test(c))return c.toLowerCase()===Qi.FILE_SPACE_CLASS_UID;let u=n.getFirstLinkpathDest(c,l);if(u==null)return!1;let f=i.get(u.path);if(f!==void 0)return f;let h=O3(n,u)?.exo__Asset_uid,p=typeof h=="string"&&h.toLowerCase()===Qi.FILE_SPACE_CLASS_UID;return i.set(u.path,p),p},"isFileSpaceClassRef"),o=a(c=>c.some(l=>aE.test(l)&&l.toLowerCase()===Qi.FILE_SPACE_CLASS_UID),"hasUuidFormRef");for(let c of n.getAllFiles()){let l=O3(n,c);if(!l)continue;let u=P3(l.exo__Instance_class);if(!u.some(p=>s(p,c.path)))continue;t.push(c.path),o(u)||r.push(`FileSpace declaration ${c.path} references the class via a label-form link only \u2014 the sync layer will not pick it up; use the UUID-form wikilink [[${Qi.FILE_SPACE_CLASS_UID}]] (UID-canon)`);let f=wW(l);if(f===null){r.push(`FileSpace declaration ${c.path} has no exo__AssetSpace_source/_git \u2014 mount path underivable, content NOT excluded from the index`);continue}let d=(0,_W.derivePath)(f);if(d===null){r.push(`FileSpace declaration ${c.path}: cannot derive mount path from source "${f}" \u2014 content NOT excluded from the index`);continue}let h=`${d}/`;c.path.startsWith(h)&&r.push(`FileSpace declaration ${c.path} lies INSIDE its own mount ${h} \u2014 it will be excluded from the index together with the content; move the declaration outside the mount folder`),e.push(h)}return{prefixes:e,declarationPaths:t,warnings:r}}a(vW,"discoverFileSpaceExclusions")});var F3=w(Zn=>{"use strict";var EW=Zn&&Zn.__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},TW=Zn&&Zn.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Zn,"__esModule",{value:!0});Zn.LazyAssetGraphLoader=Zn.MAX_LAZY_DEPTH=void 0;var AW=Be(),IW=Oe(),cE=zt();Zn.MAX_LAZY_DEPTH=10;var lE=class{static{a(this,"LazyAssetGraphLoader")}constructor(e,t,r){this.converter=e,this.fileResolver=t,this.store=r,this.loadedIRIs=new Set,this.instanceClassPredicate=cE.Namespace.EXO.term("Instance_class"),this.superClassPredicate=cE.Namespace.EXO.term("Class_superClass"),this.prototypePredicate=cE.Namespace.EXO.term("Asset_prototype")}async ensureFileLoaded(e,t=0){if(t>=Zn.MAX_LAZY_DEPTH)return;let r=this.converter.notePathToIRI(e.path).value;if(!this.loadedIRIs.has(r)){this.loadedIRIs.add(r);try{let i=await this.converter.convertNote(e);if(!this.loadedIRIs.has(r)||(await this.store.addAll(i),!this.loadedIRIs.has(r)))return;await this.walkClassAndPrototypeRelations(i,t+1)}catch(i){throw this.loadedIRIs.delete(r),i}}}async ensureLoadedByIRI(e,t=0){if(t>=Zn.MAX_LAZY_DEPTH||this.loadedIRIs.has(e.value))return;let r=this.fileResolver.resolveByIRI(e);r!==null&&await this.ensureFileLoaded(r,t)}isLoaded(e){return this.loadedIRIs.has(e.value)}notePathToIRI(e){return this.converter.notePathToIRI(e)}forget(e){this.loadedIRIs.delete(e.value)}clearAll(){this.loadedIRIs.clear()}get loadedCount(){return this.loadedIRIs.size}clearForTests(){this.loadedIRIs.clear()}async walkClassAndPrototypeRelations(e,t){let r=[];for(let i of e){if(!(i.object instanceof IW.IRI))continue;let s=i.predicate.value;(s===this.instanceClassPredicate.value||s===this.superClassPredicate.value||s===this.prototypePredicate.value)&&r.push(i.object)}for(let i of r)await this.ensureLoadedByIRI(i,t)}};Zn.LazyAssetGraphLoader=lE;Zn.LazyAssetGraphLoader=lE=EW([(0,AW.injectable)(),TW("design:paramtypes",[Object,Object,Object])],lE)});var fE=w(_r=>{"use strict";var xW=_r&&_r.__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},RW=_r&&_r.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(_r,"__esModule",{value:!0});_r.SourceAnnotator=_r.DEPTH_VARIABLE=_r.SOURCE_VARIABLE=void 0;var CW=Be(),eu=Ge(),OW=Oe(),jg=sE();_r.SOURCE_VARIABLE="_source";_r.DEPTH_VARIABLE="_depth";var uE=class{static{a(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(o=>{let c=o.clone();return c.set(_r.SOURCE_VARIABLE,new eu.Literal("own")),c});let s=[];for(let o of e){let c=o.get(t),l=o.get(r),u=o.get(i),f=o.clone();if(!c||!l||!u)f.set(_r.SOURCE_VARIABLE,new eu.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(_r.SOURCE_VARIABLE,new eu.Literal(d))}s.push(f)}return s}async annotateSingle(e,t,r,i){return(await this.annotate([e],t,r,i))[0]}async determineSource(e,t,r){return this.tripleStore.matchInGraph&&(await this.tripleStore.matchInGraph(e,t,r,jg.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=jg.MAX_PROTOTYPE_DEPTH;i++){let s=(0,jg.inferredGraphForDepth)(i);if((await this.tripleStore.matchInGraph(e,t,r,s)).length>0)return i}return 0}async annotateBySubject(e,t){if(!this.tripleStore.matchInGraph)return e.map(s=>{let o=s.clone();return o.set(_r.SOURCE_VARIABLE,new eu.Literal("own")),o});let r=[],i=new Map;for(let s of e){let o=s.get(t),c=s.clone();if(!o||!(o instanceof OW.IRI))c.set(_r.SOURCE_VARIABLE,new eu.Literal("own"));else{let l=o.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(o,void 0,void 0,jg.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(_r.SOURCE_VARIABLE,new eu.Literal(u))}r.push(c)}return r}};_r.SourceAnnotator=uE;_r.SourceAnnotator=uE=xW([(0,CW.injectable)(),RW("design:paramtypes",[Object])],uE)});var mE=w(ei=>{"use strict";var PW=ei&&ei.__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},FW=ei&&ei.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},D3=ei&&ei.__param||function(n,e){return function(t,r){e(t,r,n)}},pE;Object.defineProperty(ei,"__esModule",{value:!0});ei.NoteToRDFConverter=void 0;ei.normaliseExcludedFolders=M3;ei.isPathExcluded=j3;var dE=Be(),lr=Qn(),Yi=Oe(),bn=Ge(),L3=jt(),Kt=zt(),N3=Bt(),DW=Qv(),LW=ol(),hE=zv(),Un=Z_(),NW=Mg(),k3=new Set(["archived","draft","pinned","aliases"]);function M3(n){return Array.isArray(n)?n.map(e=>String(e).replace(/\\/g,"/").trim()).filter(e=>e.length>0).map(e=>e.endsWith("/")?e:`${e}/`):[]}a(M3,"normaliseExcludedFolders");function j3(n,e){if(e.length===0)return!1;let t=n.replace(/\\/g,"/");for(let r of e)if(t.startsWith(r))return!0;return!1}a(j3,"isPathExcluded");function kW(n){if(!n)return"";let e=n.replace(/\\/g,"/");for(;e.startsWith("/");)e=e.slice(1);for(;e.endsWith("/");)e=e.slice(0,-1);return e.length>0?`${e}/`:""}a(kW,"normaliseSubjectIriPrefix");var Ec=pE=class{static{a(this,"NoteToRDFConverter")}constructor(e,t=LW.NullLogger,r={}){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new DW.RDFVocabularyMapper,this.subjectIriPrefix=kW(r.subjectIriPrefix)}async convertNote(e){return this.convertNoteFromFrontmatter(e,this.vault.getFrontmatter(e))}async convertNoteFromFrontmatter(e,t){if(!t)return[];let r=this.notePathToIRI(e.path),i=Kt.Namespace.EXO.term("Asset_filename"),s=new lr.Triple(r,i,new bn.Literal(e.basename));if(Un.Exo003Parser.isExo003Format(t)){let o=await this.convertExo003Note(e,t);return[s,...o]}return this.convertLegacyNote(e,t,s)}async convertLegacyNote(e,t,r){this.pendingExtraTriples=[];let i=[r],s=this.notePathToIRI(e.path),o,c,l,u=!1,f=Kt.Namespace.EXO.term("Statement").value;for(let[y,b]of Object.entries(t)){let S=k3.has(y)?`exo__Asset_${y}`:y;if(!this.isExocortexProperty(S))continue;let v=this.propertyKeyToIRI(S),I=Array.isArray(b)?b:[b];for(let A of I)if(!((y==="exo__Asset_label"||k3.has(y))&&(A==null||typeof A=="string"&&A.trim()==="")))if(y==="exo__Instance_class"){let T=this.valueToClassURI(A);i.push(new lr.Triple(s,v,T))}else{let T=await this.valueToRDFObject(A,e,v);if(S==="exo__Statement_subject"&&o===void 0){let R=T.find(B=>B instanceof Yi.IRI);R&&(o=R)}else if(S==="exo__Statement_predicate"&&c===void 0){let R=T.find(B=>B instanceof Yi.IRI);R&&(c=R)}else S==="exo__Statement_object"&&l===void 0&&(l=T[0]);for(let R of T)if(i.push(new lr.Triple(s,v,R)),this.vocabularyMapper.hasMappingFor(y)&&R instanceof Yi.IRI){let B=this.vocabularyMapper.generateMappedTriple(s,y,R);B&&i.push(B)}}if(y==="exo__Instance_class")for(let A of I){let T=this.valueToClassURI(A);if(T instanceof Yi.IRI){let R=Kt.Namespace.RDF.term("type");i.push(new lr.Triple(s,R,T)),T.value===f&&(u=!0)}}if(y==="exo__Asset_label"){let A=Kt.Namespace.RDFS.term("label");for(let T of I)typeof T=="string"&&T.length>0&&i.push(new lr.Triple(s,A,new bn.Literal(T)))}}let d="exo__Instance_class"in t||"exo__Asset_uid"in t,h=t.exo__Asset_label,p="exo__Asset_label"in t&&h!==null&&h!==void 0&&!(typeof h=="string"&&h.trim()==="")&&!(Array.isArray(h)&&h.length===0);if(d&&!p){let y=Kt.Namespace.RDFS.term("label"),b=Kt.Namespace.EXO.term("Asset_label"),S=new bn.Literal(e.basename);i.push(new lr.Triple(s,y,S)),i.push(new lr.Triple(s,b,S))}i.push(...this.pendingExtraTriples),this.pendingExtraTriples=[],u&&o&&c&&l&&i.push(new lr.Triple(o,c,l));let g=await this.convertBodyWikilinks(e,s);return i.push(...g),i}async convertExo003Note(e,t){let r=Un.Exo003Parser.parse(t);if(!r.success||!r.metadata)return[];let i=r.metadata,s=[];switch(i.metadata){case Un.Exo003MetadataType.Namespace:break;case Un.Exo003MetadataType.Anchor:s.push(...this.convertExo003Anchor(e,i));break;case Un.Exo003MetadataType.BlankNode:s.push(...this.convertExo003BlankNode(e,i));break;case Un.Exo003MetadataType.Statement:s.push(...this.convertExo003Statement(e,i));break;case Un.Exo003MetadataType.Body:s.push(...await this.convertExo003Body(e,i));break}return s}convertExo003Anchor(e,t){let r=this.notePathToIRI(e.path),i=new Yi.IRI(t.uri);return[new lr.Triple(r,Kt.Namespace.OWL.term("sameAs"),i),new lr.Triple(i,Kt.Namespace.OWL.term("sameAs"),r)]}convertExo003BlankNode(e,t){let r=this.notePathToIRI(e.path),i=t.uri.replace(/[^a-zA-Z0-9_-]/g,"_");return[new lr.Triple(r,Kt.Namespace.OWL.term("sameAs"),new L3.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Un.Exo003Parser.toTriple(t,i);r.push(s);let o=this.notePathToIRI(e.path);r.push(new lr.Triple(o,Kt.Namespace.RDF.term("value"),s.subject))}catch{}return r}async convertExo003Body(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.createExo003ReferenceResolver(e),c=o(t.subject),l=o(t.predicate);if(c.type==="literal")throw new Error("Body subject cannot be a literal");if(l.type!=="iri")throw new Error("Body predicate must be an IRI");let u=c.type==="iri"?new Yi.IRI(c.value):new L3.BlankNode(c.value),f=new Yi.IRI(l.value),d=Un.Exo003Parser.toLiteral(t,s.trim());r.push(new lr.Triple(u,f,d));let h=this.notePathToIRI(e.path);r.push(new lr.Triple(h,Kt.Namespace.RDF.term("value"),u))}catch{}return r}createExo003ReferenceResolver(e){return t=>{let r=this.extractWikilink(t),i=r||t,s=this.vault.getFirstLinkpathDest(i,e.path);if(s){let o=this.vault.getFrontmatter(s);if(o&&Un.Exo003Parser.isExo003Format(o)){let c=Un.Exo003Parser.parse(o);if(c.success&&c.metadata){let l=c.metadata;if(l.metadata===Un.Exo003MetadataType.Anchor||l.metadata===Un.Exo003MetadataType.Namespace)return{type:"iri",value:l.uri};if(l.metadata===Un.Exo003MetadataType.BlankNode)return{type:"blank",value:l.uri.replace(/[^a-zA-Z0-9_-]/g,"_")}}}return{type:"iri",value:this.notePathToIRI(s.path).value}}return!r&&t.includes("://")?{type:"iri",value:t}:{type:"literal",value:t}}}async convertVault(e={}){return(await this.convertVaultWithValidation({strict:!1,excludedFolders:e.excludedFolders})).triples}async convertVaultWithValidation(e={}){let t=this.vault.getAllFiles(),r=[],i=[],s=e.strict??!1,o=0,c=0,l=(0,NW.discoverFileSpaceExclusions)(this.vault);for(let y of l.warnings)this.logger.warn(`FileSpace discovery: ${y}`);let u=[...M3(e.excludedFolders),...l.prefixes],f=u.length===0?t:t.filter(y=>!j3(y.path,u)),d=e.onProgress,h=e.progressIntervalFiles&&e.progressIntervalFiles>0?e.progressIntervalFiles:pE.INDEX_PROGRESS_INTERVAL,p=f.length,g=0;for(let y of f){if(g++,d&&g%h===0&&g<p)try{d(g,p)}catch{}try{let b=this.vault.getFrontmatter(y),S=b?this.validateExocortexAsset(b,y.basename):null;if(S){if(s)throw new Error(`Invariant violation in "${y.path}": ${S.message}`);i.push({path:y.path,reason:`Invariant violation: ${S.message}`}),o++,this.logger.info(`Skipping file with invariant violation: ${y.path}`,{code:S.code,property:S.property,reason:S.message});continue}let v=await this.convertNote(y);r.push(...v)}catch(b){let S=b instanceof Error?b.message:String(b);if(s)throw new Error(`Invalid IRI for file "${y.path}": ${S}`);i.push({path:y.path,reason:`Invalid IRI: ${S}`}),c++,this.logger.info(`Skipping file with invalid IRI: ${y.path}`,{reason:S})}}return o>0&&this.logger.warn(`Skipped ${o} file${o===1?"":"s"} with invariant violations during indexing (paths in developer console)`,{count:o}),c>0&&this.logger.warn(`Skipped ${c} file${c===1?"":"s"} with invalid IRI during indexing (paths in developer console)`,{count:c}),{triples:r,skippedFiles:i,summary:{total:f.length,indexed:f.length-i.length,skipped:i.length},fileSpaces:l}}static inferLabelFromBasename(e){return Kt.Namespace.fromPropertyKey(e)!==null?e:null}validateExocortexAsset(e,t){let r=a(d=>d==null?!0:typeof d=="string"?d.trim()==="":Array.isArray(d)?d.length===0||d.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=["exo__Asset_uid","exo__Instance_class"];for(let d of s){if(!(d in e))return{code:"MISSING_PROPERTY",property:d,message:`Required property "${d}" is missing`};if(r(e[d]))return{code:"EMPTY_PROPERTY",property:d,message:`Required property "${d}" is empty`}}let o=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let d of o)if(d in e&&r(e[d]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:d,message:`Optional property "${d}" is present but empty`};let c=e.exo__Instance_class,l=Array.isArray(c)?c:[c],u=null,f=!1;for(let d of l){if(typeof d!="string")continue;let h=this.removeQuotes(d),g=(this.extractWikilink(h)??h).trim();/^[a-z][a-zA-Z0-9]*__/.test(g)&&/[\s()]/.test(g)?u||(u={candidate:d}):f=!0}return u&&!f?{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${u.candidate}"`}:null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,hE.vaultPathToIRI)(r.path);Yi.IRI.isValidIRI(i)||t.push({path:r.path,reason:`Path "${r.path}" cannot be converted to a valid IRI`})}return t}notePathToIRI(e){return new Yi.IRI((0,hE.vaultPathToIRI)(`${this.subjectIriPrefix}${e}`))}synthesizeWikilinkTargetIRI(e){return new Yi.IRI((0,hE.vaultPathToIRI)(e))}isExocortexProperty(e){return Kt.Namespace.fromPropertyKey(e)!==null}propertyKeyToIRI(e){let t=Kt.Namespace.fromPropertyKey(e);if(!t)throw new Error(`Invalid property key: ${e}`);return t.namespace.term(t.localName)}emitTypeTripleForEnumInstance(e,t){let r=this.vault.getFrontmatter(t);if(!r)return;let i=r.exo__Instance_class,s=Array.isArray(i)?i[0]:i;if(typeof s!="string")return;let o=this.valueToClassURI(s);o instanceof Yi.IRI&&(this.pendingExtraTriples.push(new lr.Triple(e,Kt.Namespace.RDF.term("type"),o)),this.pendingExtraTriples.push(new lr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),o)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let o=this.vault.getFirstLinkpathDest(s,t.path);if(o){let l=this.notePathToIRI(o.path),u=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(u)){let d=new bn.Literal(u);if(r?.value.endsWith("#Grounding_targetValueRef")||r?.value.endsWith("#Grounding_targetValueSubstitution")||r?.value.endsWith("#Grounding_targetClass")||r?.value.endsWith("#Grounding_type")||r?.value.endsWith("#PropertyDefault_value"))return[l];let p=this.expandClassValue(o.basename);if(p)return this.emitTypeTripleForEnumInstance(p,o),[p];let g=this.vault.getFrontmatter(o);if(g){let I=g.exo__Asset_label;if(typeof I=="string"){let A=this.expandClassValue(I);if(A)return this.emitTypeTripleForEnumInstance(A,o),[A]}}let y=r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype"),S=((typeof process<"u"?process.env:void 0)?.EXOCORTEX_DUAL_STORAGE_PREDICATES??"").split(",").map(I=>I.trim()).filter(Boolean),v=S.length>0&&S.some(I=>r?.value.endsWith(`#${I}`));return y||v?[l,d]:[l]}let f=this.expandClassValue(o.basename);return f?(this.emitTypeTripleForEnumInstance(f,o),[f]):[l]}if(this.isClassReference(s)){let l=this.expandClassValue(s);if(l)return[l]}let c=s.includes("|")?s.split("|")[0]:s;return this.isUUID(c)?[this.synthesizeWikilinkTargetIRI(`${c}.md`)]:[new bn.Literal(i)]}if(this.isClassReference(i)){let o=this.expandClassValue(i);if(o)return[o]}return this.isISO8601DateTime(i)?[new bn.Literal(i,Kt.Namespace.XSD.term("dateTime"))]:[new bn.Literal(i)]}return typeof e=="boolean"?[new bn.Literal(e.toString())]:typeof e=="number"?[new bn.Literal(e.toString(),Kt.Namespace.XSD.term("decimal"))]:e instanceof Date?[new bn.Literal(e.toISOString(),Kt.Namespace.XSD.term("dateTime"))]:[new bn.Literal(String(e))]}isISO8601DateTime(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/.test(e)}removeQuotes(e){let t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.substring(1,t.length-1):e}extractWikilink(e){let t=e.match(/^\[\[([^\]]+)\]\]$/);if(!t)return null;let r=t[1];return r.includes("|")?r.split("|")[0]:r}extractWikilinkAlias(e){let t=e.match(/^\[\[([^\]]+)\]\]$/);if(!t)return null;let r=t[1],i=r.indexOf("|");return i>=0?r.substring(i+1).trim():null}valueToClassURI(e){if(typeof e!="string")return new bn.Literal(String(e));let t=this.removeQuotes(e),i=this.extractWikilink(t)||t,s=this.expandClassValue(i);if(s)return s;let o=this.extractWikilinkAlias(t);if(o){let c=this.expandClassValue(o);if(c)return c}if(this.isUUID(i)){let c=this.vault.getFirstLinkpathDest(i,"");if(c){let l=this.expandClassValue(c.basename);if(l)return l;let u=this.vault.getFrontmatter(c);if(u){let f=u.exo__Asset_label;if(typeof f=="string"){let d=this.expandClassValue(f);if(d)return d}}return this.notePathToIRI(c.path)}}return new bn.Literal(t)}isClassReference(e){return/\s/.test(e)?!1:Kt.Namespace.fromPropertyKey(e)!==null}isUUID(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}expandClassValue(e){let t=this.removeQuotes(e),r=Kt.Namespace.fromPropertyKey(t);return!r||/[\s()]/.test(r.localName)?null:r.namespace.term(r.localName)}extractBodyContent(e){let t=/^---\r?\n[\s\S]*?\r?\n---\r?\n?/;return e.replace(t,"")}extractBodyWikilinks(e){let t=new Set,r,i=new RegExp(this.BODY_WIKILINK_PATTERN.source,"g");for(;(r=i.exec(e))!==null;)r[1]&&t.add(r[1]);return Array.from(t)}async convertBodyWikilinks(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of o){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new lr.Triple(t,c,f))}else if(this.isClassReference(l)){let f=this.expandClassValue(l);f?r.push(new lr.Triple(t,c,f)):r.push(new lr.Triple(t,c,new bn.Literal(l)))}else r.push(new lr.Triple(t,c,new bn.Literal(l)))}}catch{}return r}};ei.NoteToRDFConverter=Ec;Ec.INDEX_PROGRESS_INTERVAL=200;Ec.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};Ec.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};Ec.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};ei.NoteToRDFConverter=Ec=pE=PW([(0,dE.injectable)(),D3(0,(0,dE.inject)(N3.DI_TOKENS.IVaultAdapter)),D3(1,(0,dE.inject)(N3.DI_TOKENS.ILogger)),FW("design:paramtypes",[Object,Object,Object])],Ec)});var yE=w($g=>{"use strict";Object.defineProperty($g,"__esModule",{value:!0});$g.FilterContainsOptimizer=void 0;var MW=Oe(),jW=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,gE=class{static{a(this,"FilterContainsOptimizer")}constructor(){this.tripleStore=null,this.lastOptimizationHints=[]}setTripleStore(e){this.tripleStore=e}getLastOptimizationHints(){return this.lastOptimizationHints}clearHints(){this.lastOptimizationHints=[]}async optimize(e){return this.clearHints(),this.optimizeRecursive(e)}optimizeSync(e,t){return this.clearHints(),this.optimizeSyncRecursive(e,t)}async optimizeRecursive(e){return e.type==="filter"?this.optimizeFilter(e):e.type==="join"?{type:"join",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="leftjoin"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="union"?{type:"union",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="minus"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="project"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="orderby"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="slice"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="distinct"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="reduced"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="group"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="extend"?{...e,input:await this.optimizeRecursive(e.input)}:e}optimizeSyncRecursive(e,t){return e.type==="filter"?this.optimizeFilterSync(e,t):e.type==="join"?{type:"join",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="leftjoin"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="union"?{type:"union",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="minus"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="project"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="orderby"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="slice"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="distinct"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="reduced"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="group"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="extend"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e}async optimizeFilter(e){let t=this.detectContainsUUIDPattern(e.expression);if(!t)return{type:"filter",expression:e.expression,input:await this.optimizeRecursive(e.input)};let r=[];return this.tripleStore&&(r=await this.findSubjectsContainingUUID(t.uuid)),this.rewriteFilter(e,t,r)}optimizeFilterSync(e,t){let r=this.detectContainsUUIDPattern(e.expression);if(!r)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input,t)};let i=t?t.filter(s=>s.includes(r.uuid)):[];return this.rewriteFilter(e,r,i)}rewriteFilter(e,t,r){if(this.lastOptimizationHints.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${t.variable}), "${t.uuid}"))`,suggestedRewrite:r.length===1?`VALUES ?${t.variable} { <${r[0]}> }`:r.length>1?`VALUES ?${t.variable} { ${r.map(i=>`<${i}>`).join(" ")} }`:"No matching URIs found for UUID",estimatedSpeedup:r.length>0?"O(n) \u2192 O(1)":"N/A",matchedUri:r.length===1?r[0]:void 0}),r.length===0)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input)};if(r.length===1){let i=this.injectSubjectConstraint(e.input,t.variable,r[0]);if(i!==e.input)return i}return this.createValuesJoin(e,t,r)}detectContainsUUIDPattern(e){if(e.type==="function"||e.type==="functionCall"){let t=e;if((typeof t.function=="string"?t.function.toLowerCase():t.function?.value?.toLowerCase()??"")==="contains"&&t.args.length===2)return this.analyzeContainsArgs(t.args[0],t.args[1],e)}if(e.type==="logical"&&e.operator==="&&")for(let t of e.operands){let r=this.detectContainsUUIDPattern(t);if(r)return r}return null}analyzeContainsArgs(e,t,r){let i=null;if(e.type==="function"||e.type==="functionCall"){let s=e;if((typeof s.function=="string"?s.function.toLowerCase():s.function?.value?.toLowerCase()??"")==="str"&&s.args.length===1){let c=s.args[0];c.type==="variable"&&(i=c.name)}}if(!i&&e.type==="variable"&&(i=e.name),!i)return null;if(t.type==="literal"){let c=String(t.value).match(jW);if(c)return{variable:i,uuid:c[0].toLowerCase(),originalExpression:r}}return null}async findSubjectsContainingUUID(e){if(!this.tripleStore)return[];if(this.tripleStore.findSubjectsByUUID)return(await this.tripleStore.findSubjectsByUUID(e)).map(s=>s.value);let t=await this.tripleStore.subjects(),r=[];for(let i of t)i instanceof MW.IRI&&i.value.toLowerCase().includes(e.toLowerCase())&&r.push(i.value);return r}injectSubjectConstraint(e,t,r){if(e.type==="bgp"){let i=e.triples.map(o=>o.subject.type==="variable"&&o.subject.value===t?{...o,subject:{type:"iri",value:r}}:o);if(i.some((o,c)=>o.subject!==e.triples[c].subject))return{type:"bgp",triples:i}}if(e.type==="join"){let i=this.injectSubjectConstraint(e.left,t,r),s=this.injectSubjectConstraint(e.right,t,r);if(i!==e.left||s!==e.right)return{type:"join",left:i,right:s}}if(e.type==="filter"){let i=this.injectSubjectConstraint(e.input,t,r);if(i!==e.input)return{...e,input:i}}return e}createValuesJoin(e,t,r){return{type:"join",left:{type:"values",variables:[t.variable],bindings:r.map(o=>({[t.variable]:{type:"iri",value:o}}))},right:this.optimizeSyncRecursive(e.input)}}analyzeQuery(e){let t=[];return this.analyzeRecursive(e,t),t}analyzeRecursive(e,t){if(e.type==="filter"){let r=this.detectContainsUUIDPattern(e.expression);r&&t.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${r.variable}), "${r.uuid}"))`,suggestedRewrite:`Use --optimize flag or rewrite as VALUES ?${r.variable} { <uri-containing-uuid> }`,estimatedSpeedup:"O(n) \u2192 O(1) with UUID index lookup"}),this.analyzeRecursive(e.input,t);return}e.type==="join"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="leftjoin"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="union"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="minus"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="project"?this.analyzeRecursive(e.input,t):e.type==="orderby"?this.analyzeRecursive(e.input,t):e.type==="slice"?this.analyzeRecursive(e.input,t):e.type==="distinct"?this.analyzeRecursive(e.input,t):e.type==="reduced"?this.analyzeRecursive(e.input,t):e.type==="group"?this.analyzeRecursive(e.input,t):e.type==="extend"&&this.analyzeRecursive(e.input,t)}};$g.FilterContainsOptimizer=gE});var $3=w(Ug=>{"use strict";Object.defineProperty(Ug,"__esModule",{value:!0});Ug.AlgebraOptimizer=void 0;var $W=yE(),bE=class{static{a(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new $W.FilterContainsOptimizer}setTripleStore(e){this.tripleStore=e,this.filterContainsOptimizer.setTripleStore(e)}getOptimizationHints(){return this.filterContainsOptimizer.getLastOptimizationHints()}analyzeQuery(e){return this.filterContainsOptimizer.analyzeQuery(e)}optimize(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),t=this.filterPushDown(t),t=this.joinReordering(t),t}async optimizeAsync(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),this.tripleStore&&(t=await this.filterContainsOptimizer.optimize(t)),t=this.filterPushDown(t),t=this.joinReordering(t),t}optimizeWithSubjects(e,t){let r=e;return r=this.eliminateEmptyBGPInFilterJoin(r),r=this.filterContainsOptimizer.optimizeSync(r,t),r=this.filterPushDown(r),r=this.joinReordering(r),r}eliminateEmptyBGPInFilterJoin(e){if(e.type==="join"){if(e.left.type==="filter"){let t=e.left;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.right)}}if(e.right.type==="filter"){let t=e.right;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.left)}}return{type:"join",left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}}return e.type==="filter"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="leftjoin"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="union"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="minus"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="project"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="orderby"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="slice"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="distinct"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e}filterPushDown(e){return e.type==="filter"?this.pushDownFilter(e):e.type==="join"?{type:"join",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="leftjoin"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="union"?{type:"union",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="minus"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="project"?{...e,input:this.filterPushDown(e.input)}:e.type==="orderby"?{...e,input:this.filterPushDown(e.input)}:e.type==="slice"?{...e,input:this.filterPushDown(e.input)}:e.type==="distinct"?{...e,input:this.filterPushDown(e.input)}:e}pushDownFilter(e){let t=e.input;if(t.type==="join"){let r=this.getFilterVariables(e.expression),i=this.getOperationVariables(t.left),s=this.getOperationVariables(t.right),o=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return o&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!o?{type:"join",left:this.filterPushDown(t.left),right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:{type:"join",left:this.filterPushDown(t.left),right:this.filterPushDown(t.right)}}}return t.type==="union"?{type:"union",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:this.filterPushDown(t)}}getFilterVariables(e){let t=[];if(e.type==="variable")t.push(e.name);else if(e.type==="comparison")t.push(...this.getFilterVariables(e.left)),t.push(...this.getFilterVariables(e.right));else if(e.type==="logical")for(let r of e.operands)t.push(...this.getFilterVariables(r));else if(e.type==="function")for(let r of e.args)t.push(...this.getFilterVariables(r));return Array.from(new Set(t))}getOperationVariables(e){let t=new Set;if(e.type==="bgp")for(let r of e.triples)r.subject.type==="variable"&&t.add(r.subject.value),r.predicate.type==="variable"&&t.add(r.predicate.value),r.object.type==="variable"&&t.add(r.object.value);else if(e.type==="join"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="filter")return this.getOperationVariables(e.input);if(e.type==="leftjoin"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else if(e.type==="union"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="minus")return this.getOperationVariables(e.left);if(e.type==="project")return new Set(e.variables)}}return t}joinReordering(e){return e.type==="join"?this.reorderJoin(e):e.type==="filter"?{...e,input:this.joinReordering(e.input)}:e.type==="leftjoin"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="union"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="minus"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="project"?{...e,input:this.joinReordering(e.input)}:e.type==="orderby"?{...e,input:this.joinReordering(e.input)}:e.type==="slice"?{...e,input:this.joinReordering(e.input)}:e.type==="distinct"?{...e,input:this.joinReordering(e.input)}:e}reorderJoin(e){let t=this.isConstrained(e.left),r=this.isConstrained(e.right);if(r&&!t)return{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)};if(t&&!r)return{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)};let i=this.estimateCost(e.left);return this.estimateCost(e.right)<i?{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)}:{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)}}isConstrained(e){return e.type==="values"?!0:e.type==="bgp"?e.triples.some(t=>t.object.type!=="variable"||t.subject.type!=="variable"):e.type==="filter"?this.isConstrained(e.input):e.type==="join"?this.isConstrained(e.left)||this.isConstrained(e.right):e.type==="union"?this.isConstrained(e.left)&&this.isConstrained(e.right):!1}estimateCost(e){if(e.type==="bgp"){let t=0;for(let r of e.triples){let i=10;r.subject.type==="variable"&&(i*=10),r.predicate.type==="variable"&&(i*=20),r.object.type==="variable"&&(i*=5),t+=i}return t}if(e.type==="filter")return this.estimateCost(e.input)*.3;if(e.type==="join"){let t=this.estimateCost(e.left),r=this.estimateCost(e.right);return e.left.type==="values"||e.right.type==="values"?Math.min(t,r)*2:t*r}if(e.type==="leftjoin")return this.estimateCost(e.left)+this.estimateCost(e.right)*.5;if(e.type==="union")return this.estimateCost(e.left)+this.estimateCost(e.right);if(e.type==="values"){let t=e.bindings;return Array.isArray(t)?t.length*5:10}return e.type==="minus"?this.estimateCost(e.left)+this.estimateCost(e.right)*.3:100}setStatistics(e,t){this.stats.set(e,t)}getStatistics(e){return this.stats.get(e)}};Ug.AlgebraOptimizer=bE});var U3=w(Bg=>{"use strict";Object.defineProperty(Bg,"__esModule",{value:!0});Bg.AlgebraSerializer=void 0;var _E=class{static{a(this,"AlgebraSerializer")}toString(e,t=0){let r=" ".repeat(t);switch(e.type){case"bgp":return`${r}BGP [
224
224
  ${e.triples.map(u=>`${r} ${this.tripleToString(u)}`).join(`
225
225
  `)}
226
226
  ${r}]`;case"filter":return`${r}Filter(
@@ -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(cae,"renderText");function lae(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(lae,"isHardFail");function Yj(){return new Se("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";ce.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,Ma.resolve)(n.reqs);if(!(0,ja.existsSync)(r)||!(0,ja.statSync)(r).isDirectory())throw new qe(r);let i=(0,Ma.resolve)(n.tests??".");if(!(0,ja.existsSync)(i)||!(0,ja.statSync)(i).isDirectory())throw new qe(i);let[s,o]=await Promise.all([nae(r),sae(i)]),c=oae(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):cae(c,t),lae(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){ce.handle(r)}})}a(Yj,"requirementsAuditCommand");function Xj(){let n=new Se("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(Yj()),n}a(Xj,"requirementsCommand");function Ab(n){let e=new Se;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.154.0"),e.addCommand(W4()),e.addCommand(tj()),e.addCommand(VM()),e.addCommand(HM()),e.addCommand(p4()),e.addCommand(zM()),e.addCommand(y4()),e.addCommand(I4()),e.addCommand(R4()),e.addCommand(V4()),e.addCommand(yj()),e.addCommand(Sj()),e.addCommand(Mj()),e.addCommand(jj()),e.addCommand(Bj()),e.addCommand(Vj()),e.addCommand(Hj()),e.addCommand(xj()),e.addCommand(Lj()),e.addCommand(Xj()),e}a(Ab,"createProgram");Ab().parse();0&&(module.exports={createProgram});
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(cae,"renderText");function lae(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(lae,"isHardFail");function Yj(){return new Se("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";ce.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,Ma.resolve)(n.reqs);if(!(0,ja.existsSync)(r)||!(0,ja.statSync)(r).isDirectory())throw new qe(r);let i=(0,Ma.resolve)(n.tests??".");if(!(0,ja.existsSync)(i)||!(0,ja.statSync)(i).isDirectory())throw new qe(i);let[s,o]=await Promise.all([nae(r),sae(i)]),c=oae(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):cae(c,t),lae(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){ce.handle(r)}})}a(Yj,"requirementsAuditCommand");function Xj(){let n=new Se("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(Yj()),n}a(Xj,"requirementsCommand");function Ab(n){let e=new Se;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"16.156.0"),e.addCommand(W4()),e.addCommand(tj()),e.addCommand(VM()),e.addCommand(HM()),e.addCommand(p4()),e.addCommand(zM()),e.addCommand(y4()),e.addCommand(I4()),e.addCommand(R4()),e.addCommand(V4()),e.addCommand(yj()),e.addCommand(Sj()),e.addCommand(Mj()),e.addCommand(jj()),e.addCommand(Bj()),e.addCommand(Vj()),e.addCommand(Hj()),e.addCommand(xj()),e.addCommand(Lj()),e.addCommand(Xj()),e}a(Ab,"createProgram");Ab().parse();0&&(module.exports={createProgram});
641
641
  /*! Bundled license information:
642
642
 
643
643
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "16.154.0",
3
+ "version": "16.156.0",
4
4
  "description": "CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more",
5
5
  "main": "dist/index.js",
6
6
  "bin": {