@kitelev/exocortex-cli 15.173.0 → 15.173.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v15.173.0
2
+ // @kitelev/exocortex-cli v15.173.1
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -374,7 +374,7 @@ LIMIT ${this.config.defaultLimit}`,s="\u041D\u0435 \u0443\u0434\u0430\u043B\u043
374
374
  `,i=this.composePrefixes(t),s=this.serializePrefixes(i,r),a=this.nTriplesSerializer.serialize(e,{newline:r}).trimEnd();return s?a?`${s}${r}${r}${a}${r}`:`${s}${r}`:a?`${a}${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?{...E$,...e.prefixes??{}}:{...e.prefixes??{}}}serializeTriplesOnly(e,t){return this.nTriplesSerializer.serializeChunk(e,t).trimEnd()}};gm.TurtleSerializer=Gv});var rC=S(ym=>{"use strict";Object.defineProperty(ym,"__esModule",{value:!0});ym.JSONLDSerializer=void 0;var eC=Ae(),tC=qt(),T$=Ne(),ml=lr(),A$={rdf:ml.Namespace.RDF.iri.value,rdfs:ml.Namespace.RDFS.iri.value,owl:ml.Namespace.OWL.iri.value,xsd:ml.Namespace.XSD.iri.value,exo:ml.Namespace.EXO.iri.value,ems:ml.Namespace.EMS.iri.value},zv=class{static{o(this,"JSONLDSerializer")}toDocument(e,t={}){let r={...A$,...t.context??{}},i=new Map;for(let s of e){let a=this.subjectToId(s.subject),c=this.compactIri(s.predicate.value,r),l=this.objectToJSONLD(s.object,r),u=i.get(a)??{"@id":a},f=u[c];f===void 0?u[c]=l:Array.isArray(f)?f.push(l):u[c]=[f,l],i.set(a,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 eC.IRI?e.value:e instanceof tC.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 eC.IRI)return{"@id":e.value};if(e instanceof tC.BlankNode)return{"@id":`_:${e.id}`};if(e instanceof T$.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}};ym.JSONLDSerializer=zv});var Kv=S(_m=>{"use strict";Object.defineProperty(_m,"__esModule",{value:!0});_m.NTriplesParser=void 0;var x$=Yn(),nC=Ae(),Hv=Ne(),C$=qt(),gl=lr(),I$={rdf:gl.Namespace.RDF.iri.value,rdfs:gl.Namespace.RDFS.iri.value,owl:gl.Namespace.OWL.iri.value,xsd:gl.Namespace.XSD.iri.value,exo:gl.Namespace.EXO.iri.value,ems:gl.Namespace.EMS.iri.value},Qv=class{static{o(this,"NTriplesParser")}parse(e,t={}){let r={prefixes:{...I$,...t.prefixes??{}},strict:t.strict??!1},i=[];return e.split(/\r?\n/).forEach((a,c)=>{let l=a.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(),a=this.parseSubject(s,t,r);s=a.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 x$.Triple(a.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,a,c]=i,l=r.prefixes[s];if(!l)throw new Error(`Unknown prefix "${s}" at line ${t}`);return{node:new nC.IRI(`${l}${a}`),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),a=new nC.IRI(s),c=e.slice(i+1).trimStart();return{node:a,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 C$.BlankNode(i),rest:(s??"").trimStart()}}consumeLiteral(e,t,r){let{value:i,rest:s}=this.consumeQuotedString(e,t),a=s.trimStart();if(a.startsWith("^^")){a=a.slice(2).trimStart();let c=a.startsWith("<")?this.consumeIRI(a,t,r):this.consumePrefixedName(a,t,r);return{node:new Hv.Literal(i,c.node),rest:c.rest}}if(a.startsWith("@")){let c=a.match(/^@([a-zA-Z-]+)(?:\s+(.*))?$/);if(!c)throw new Error(`Invalid language tag at line ${t}`);let[,l,u]=c;return{node:new Hv.Literal(i,void 0,l),rest:(u??"").trimStart()}}return{node:new Hv.Literal(i),rest:a}}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 a=e[i+1];switch(a){case"t":r+=" ",i+=1;break;case"b":r+="\b",i+=1;break;case"n":r+=`
375
375
  `,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 \\${a} at line ${t}`)}continue}if(s==='"'){let a=e.slice(i+1);return{value:r,rest:a}}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 a=e[s];if(a===t){i++;continue}if(a===r&&(i--,i===0))return s}return-1}};_m.NTriplesParser=Qv});var iC=S(Sm=>{"use strict";Object.defineProperty(Sm,"__esModule",{value:!0});Sm.TurtleParser=void 0;var yl=lr(),R$=Kv(),P$={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},O$=/^@prefix\s+([a-zA-Z_][\w-]*):\s*<([^>]+)>\s*\.$/,Yv=class{static{o(this,"TurtleParser")}constructor(){this.nTriplesParser=new R$.NTriplesParser}parse(e,t={}){let r={...P$,...t.prefixes??{}},i=this.collectStatements(e),s=[];return i.forEach(({statement:a,lineNumber:c})=>{if(this.isPrefixStatement(a)){let u=a.match(O$);if(!u)throw new Error(`Invalid prefix declaration at line ${c}`);let[,f,d]=u;r[f]=d;return}if(a.includes(";")||a.includes(","))throw new Error(`Complex Turtle statements with ';' or ',' are not supported (line ${c})`);let l=this.normalizeShortcuts(a);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((a,c)=>{let l=a.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}};Sm.TurtleParser=Yv});var sC=S(vm=>{"use strict";Object.defineProperty(vm,"__esModule",{value:!0});vm.RDFSerializer=void 0;var _l=Yn(),Ho=Ae(),Qo=Ne(),Xv=qt(),Ss=lr(),F$=Z3(),D$=Wv(),N$=rC(),L$=iC(),k$=Kv(),M$=1024,j$=`
376
376
  `,$$={rdf:Ss.Namespace.RDF.iri.value,rdfs:Ss.Namespace.RDFS.iri.value,owl:Ss.Namespace.OWL.iri.value,xsd:Ss.Namespace.XSD.iri.value,exo:Ss.Namespace.EXO.iri.value,ems:Ss.Namespace.EMS.iri.value},Jv=class{static{o(this,"RDFSerializer")}constructor(e){this.store=e,this.turtleSerializer=new F$.TurtleSerializer,this.nTriplesSerializer=new D$.NTriplesSerializer,this.jsonldSerializer=new N$.JSONLDSerializer,this.turtleParser=new L$.TurtleParser,this.nTriplesParser=new k$.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??j$,i=t.batchSize??M$,s=t.includeDefaultPrefixes,a=t.prefixes,c=this,l=!1,u=[],f=[],d=0,h=o(async()=>{if(!l){if(f=await c.store.match(),e==="json-ld"){let y=c.jsonldSerializer.toDocument(f,{context:a,pretty:!1});u.push(...c.buildJsonLdChunks(y))}else if(e==="turtle"){let y=c.turtleSerializer.serializePrefixes(c.composePrefixes(a,s),r);y&&u.push(`${y}${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 y=f.slice(d,d+i);d+=y.length;let v="";if(e==="turtle"){let w=c.turtleSerializer.serializeTriplesOnly(y,r);w&&(v=`${w}${r}`)}else e==="n-triples"&&(v=c.nTriplesSerializer.serializeChunk(y,r));return v?{value:v,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?{...$$,...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),a={...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,a,f),h=Object.entries(u);for(let[p,y]of h){if(p==="@id"||p==="@context")continue;if(p==="@type"){this.collectTypeTriples(d,y,l,a);continue}let v=this.expandTerm(p,a),w=new Ho.IRI(v);this.collectTriplesForValue(d,w,y,l,a)}}),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 Xv.BlankNode(i.slice(2));if(this.isAbsoluteIri(i))return new Ho.IRI(i);let s=this.expandTerm(i,t);return new Ho.IRI(s)}return new Xv.BlankNode(`jsonld_${r}`)}collectTypeTriples(e,t,r,i){let s=Ss.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 _l.Triple(e,s,new Ho.IRI(l)))})}collectTriplesForValue(e,t,r,i,s){if(r!=null){if(Array.isArray(r)){r.forEach(a=>this.collectTriplesForValue(e,t,a,i,s));return}if(typeof r=="object"){let a=r;if(typeof a["@id"]=="string"){let c=this.parseIdNode(a["@id"],s);i.push(new _l.Triple(e,t,c));return}if(a["@value"]!==void 0){let c=this.parseLiteralObject(a,s);i.push(new _l.Triple(e,t,c));return}}if(typeof r=="string"){i.push(new _l.Triple(e,t,new Qo.Literal(r)));return}if(typeof r=="number"){let a=Number.isInteger(r)?Ss.Namespace.XSD.term("integer"):Ss.Namespace.XSD.term("decimal");i.push(new _l.Triple(e,t,new Qo.Literal(r.toString(),a)));return}if(typeof r=="boolean"){let a=Ss.Namespace.XSD.term("boolean");i.push(new _l.Triple(e,t,new Qo.Literal(r.toString(),a)));return}throw new Error("Unsupported JSON-LD value encountered")}}parseIdNode(e,t){if(e.startsWith("_:"))return new Xv.BlankNode(e.slice(2));if(this.isAbsoluteIri(e))return new Ho.IRI(e);let r=this.expandTerm(e,t);return new Ho.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 Qo.Literal(r,void 0,e["@language"],i):new Qo.Literal(r,void 0,e["@language"])}if(typeof e["@type"]=="string"){let i=this.expandTerm(e["@type"],t);return new Qo.Literal(r,new Ho.IRI(i))}return new Qo.Literal(r)}expandTerm(e,t){if(this.isAbsoluteIri(e))return e;let r=e.indexOf(":");if(r>0){let s=e.slice(0,r),a=e.slice(r+1),c=t[s];if(!c)throw new Error(`Unknown prefix "${s}" in JSON-LD document`);return`${c}${a}`}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 a=JSON.stringify(i);s>0?t.push(`,${a}`):t.push(a)}),t.push(`]}
377
- `),t}};vm.RDFSerializer=Jv});var Zv=S(Sl=>{"use strict";Object.defineProperty(Sl,"__esModule",{value:!0});Sl.OBSIDIAN_VAULT_SCHEME=void 0;Sl.vaultPathToIRI=B$;Sl.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function B$(n){let e=n.startsWith("./")?n.slice(2):n;return`${Sl.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}o(B$,"vaultPathToIRI")});var tb=S(bm=>{"use strict";Object.defineProperty(bm,"__esModule",{value:!0});bm.RDFVocabularyMapper=void 0;var tr=Yn(),aC=Ae(),J=lr(),eb=class{static{o(this,"RDFVocabularyMapper")}constructor(){this.propertyMappings=new Map([["exo__Instance_class",J.Namespace.RDF.term("type")],["exo__Asset_isDefinedBy",J.Namespace.RDFS.term("isDefinedBy")],["exo__Class_superClass",J.Namespace.RDFS.term("subClassOf")],["exo__Property_range",J.Namespace.RDFS.term("range")],["exo__Property_domain",J.Namespace.RDFS.term("domain")],["exo__Property_superProperty",J.Namespace.RDFS.term("subPropertyOf")]])}generateClassHierarchyTriples(){let e=[];return e.push(new tr.Triple(J.Namespace.EXO.term("Asset"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Resource"))),e.push(new tr.Triple(J.Namespace.EXO.term("Class"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Class"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDF.term("Property"))),e.push(new tr.Triple(J.Namespace.EMS.term("Task"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Project"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Area"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Workflow"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("WorkflowState"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("WorkflowTransition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Command"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Precondition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Grounding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("CommandBinding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new tr.Triple(J.Namespace.EXO.term("Instance_class"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDF.term("type"))),e.push(new tr.Triple(J.Namespace.EXO.term("Asset_isDefinedBy"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("isDefinedBy"))),e.push(new tr.Triple(J.Namespace.EXO.term("Class_superClass"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subClassOf"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_range"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("range"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_domain"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("domain"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_superProperty"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subPropertyOf"))),e}generateMappedTriple(e,t,r){let i=this.propertyMappings.get(t);if(!i)return null;let s;if(r instanceof aC.IRI)s=r;else{let a=r.match(/^(ems|exo|exocmd)__(.+)$/);if(a){let[,c,l]=a;s=(c==="ems"?J.Namespace.EMS:c==="exocmd"?J.Namespace.EXOCMD:J.Namespace.EXO).term(l)}else s=new aC.IRI(r)}return new tr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};bm.RDFVocabularyMapper=eb});var oC=S(Em=>{"use strict";Object.defineProperty(Em,"__esModule",{value:!0});Em.RDFSInferenceEngine=void 0;var V$=Yn(),wm=Ae(),rb=class{static{o(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 a=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof wm.IRI){let h=a.get(d.object.value);if(h)for(let p of h)u.push(new V$.Triple(d.subject,i,new wm.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 wm.IRI&&s.object instanceof wm.IRI){let a=s.subject.value,c=s.object.value;i.has(a)||i.set(a,new Set),i.get(a).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=[],a=t.get(e);if(a)for(let c of a)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}};Em.RDFSInferenceEngine=rb});var sb=S(Ko=>{"use strict";var U$=Ko&&Ko.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ko,"__esModule",{value:!0});Ko.NonInheritablePropertyRegistry=void 0;var q$=fe(),cC=Ae(),lC=Ne(),nb=lr(),ib=class{static{o(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 a=t.find(c=>c.value.includes("Asset_label"));if(!a){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,a,void 0);for(let u of l)if(u.object instanceof lC.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(a=>a.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new lC.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof cC.IRI)return i[0].subject;let s=t.find(a=>a.value.includes("Instance_class"));if(s){let a=await e.match(void 0,s,void 0);for(let c of a)if(c.object instanceof cC.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?nb.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?nb.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?nb.Namespace.EXOCMD.term(e.substring(8)).value:null}};Ko.NonInheritablePropertyRegistry=ib;Ko.NonInheritablePropertyRegistry=ib=U$([(0,q$.injectable)()],ib)});var cb=S(Yo=>{"use strict";var W$=Yo&&Yo.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Yo,"__esModule",{value:!0});Yo.PropertyCardinalityRegistry=void 0;var G$=fe(),uC=Ae(),fC=Ne(),ab=lr(),ob=class{static{o(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 a=t.find(c=>c.value.includes("Asset_label"));if(!a){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,a,void 0);for(let u of l)if(u.object instanceof fC.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(a=>a.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new fC.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof uC.IRI)return i[0].subject;let s=t.find(a=>a.value.includes("Instance_class"));if(s){let a=await e.match(void 0,s,void 0);for(let c of a)if(c.object instanceof uC.IRI&&c.object.value.includes("PropertyCardinalityMultiple"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?ab.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?ab.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?ab.Namespace.EXOCMD.term(e.substring(8)).value:null}};Yo.PropertyCardinalityRegistry=ob;Yo.PropertyCardinalityRegistry=ob=W$([(0,G$.injectable)()],ob)});var fb=S(br=>{"use strict";var z$=br&&br.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},H$=br&&br.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(br,"__esModule",{value:!0});br.PrototypeChainMaterializer=br.MAX_PROTOTYPE_DEPTH=br.INFERRED_GRAPH=void 0;br.inferredGraphForDepth=lb;var Q$=fe(),dC=Yn(),qa=Ae(),K$=sb(),Y$=cb();br.INFERRED_GRAPH=new qa.IRI("https://exocortex.my/ontology/exo#inferred");var X$="https://exocortex.my/ontology/exo#inferred/";function lb(n){return new qa.IRI(`${X$}${n}`)}o(lb,"inferredGraphForDepth");br.MAX_PROTOTYPE_DEPTH=10;var ub=class{static{o(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 qa.IRI&&c.object instanceof qa.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let a=0;for(let[c]of s){let l=new qa.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 y=p.object instanceof qa.IRI?p.object.value:String(p.object),v=h.get(p.predicate.value);v||(v=new Set,h.set(p.predicate.value,v)),v.add(y)}for(let p=0;p<u.length;p++){let y=u[p],v=p+1,w=new qa.IRI(y),b=await e.match(w,void 0,void 0),T=new Set;if(e.matchInGraph){let R=await e.matchInGraph(w,void 0,void 0,br.INFERRED_GRAPH);for(let $ of R)T.add($.predicate.value)}for(let R of b){let $=R.predicate.value;if(this.registry.isNonInheritable($)||T.has($))continue;if(d.has($)&&this.isMultiValued($)){let ce=R.object instanceof qa.IRI?R.object.value:String(R.object);if(h.get($)?.has(ce))continue;let U=h.get($);U||(U=new Set,h.set($,U)),U.add(ce);let F=new dC.Triple(l,R.predicate,R.object);await e.add(F),e.addToGraph&&(await e.addToGraph(F,br.INFERRED_GRAPH),await e.addToGraph(F,lb(v))),a++;continue}if(d.has($))continue;let q=new dC.Triple(l,R.predicate,R.object);await e.add(q),e.addToGraph&&(await e.addToGraph(q,br.INFERRED_GRAPH),await e.addToGraph(q,lb(v))),d.add($),a++}}}return a}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],a=t.get(e);for(a&&s.push(a.value);s.length>0&&r.length<br.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}};br.PrototypeChainMaterializer=ub;br.PrototypeChainMaterializer=ub=z$([(0,Q$.injectable)(),H$("design:paramtypes",[K$.NonInheritablePropertyRegistry,Y$.PropertyCardinalityRegistry])],ub)});var hb=S(pr=>{"use strict";var J$=pr&&pr.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},Z$=pr&&pr.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(pr,"__esModule",{value:!0});pr.SourceAnnotator=pr.DEPTH_VARIABLE=pr.SOURCE_VARIABLE=void 0;var eB=fe(),vl=Ne(),tB=Ae(),Tm=fb();pr.SOURCE_VARIABLE="_source";pr.DEPTH_VARIABLE="_depth";var db=class{static{o(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(a=>{let c=a.clone();return c.set(pr.SOURCE_VARIABLE,new vl.Literal("own")),c});let s=[];for(let a of e){let c=a.get(t),l=a.get(r),u=a.get(i),f=a.clone();if(!c||!l||!u)f.set(pr.SOURCE_VARIABLE,new vl.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(pr.SOURCE_VARIABLE,new vl.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,Tm.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=Tm.MAX_PROTOTYPE_DEPTH;i++){let s=(0,Tm.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 a=s.clone();return a.set(pr.SOURCE_VARIABLE,new vl.Literal("own")),a});let r=[],i=new Map;for(let s of e){let a=s.get(t),c=s.clone();if(!a||!(a instanceof tB.IRI))c.set(pr.SOURCE_VARIABLE,new vl.Literal("own"));else{let l=a.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(a,void 0,void 0,Tm.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(pr.SOURCE_VARIABLE,new vl.Literal(u))}r.push(c)}return r}};pr.SourceAnnotator=db;pr.SourceAnnotator=db=J$([(0,eB.injectable)(),Z$("design:paramtypes",[Object])],db)});var mb=S(Bi=>{"use strict";var rB=Bi&&Bi.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},nB=Bi&&Bi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},hC=Bi&&Bi.__param||function(n,e){return function(t,r){e(t,r,n)}},Am;Object.defineProperty(Bi,"__esModule",{value:!0});Bi.NoteToRDFConverter=void 0;var pb=fe(),mr=Yn(),Wa=Ae(),mn=Ne(),pC=qt(),Kt=lr(),mC=Et(),iB=tb(),sB=Pc(),gC=Zv(),Pn=s_(),bl=Am=class{static{o(this,"NoteToRDFConverter")}constructor(e,t=sB.NullLogger){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new iB.RDFVocabularyMapper}async convertNote(e){let t=this.vault.getFrontmatter(e);return t?Pn.Exo003Parser.isExo003Format(t)?this.convertExo003Note(e,t):this.convertLegacyNote(e,t):[]}async convertLegacyNote(e,t){this.pendingExtraTriples=[];let r=[],i=this.notePathToIRI(e.path),s=Kt.Namespace.EXO.term("Asset_fileName");r.push(new mr.Triple(i,s,new mn.Literal(e.basename)));for(let[c,l]of Object.entries(t)){if(!this.isExocortexProperty(c))continue;let u=this.propertyKeyToIRI(c),f=Array.isArray(l)?l:[l];for(let d of f)if(c==="exo__Instance_class"){let h=this.valueToClassURI(d);r.push(new mr.Triple(i,u,h))}else{let h=await this.valueToRDFObject(d,e,u);for(let p of h)if(r.push(new mr.Triple(i,u,p)),this.vocabularyMapper.hasMappingFor(c)&&p instanceof Wa.IRI){let y=this.vocabularyMapper.generateMappedTriple(i,c,p);y&&r.push(y)}}if(c==="exo__Instance_class")for(let d of f){let h=this.valueToClassURI(d);if(h instanceof Wa.IRI){let p=Kt.Namespace.RDF.term("type");r.push(new mr.Triple(i,p,h))}}if(c==="exo__Asset_label"){let d=Kt.Namespace.RDFS.term("label");for(let h of f)typeof h=="string"&&h.length>0&&r.push(new mr.Triple(i,d,new mn.Literal(h)))}}if(!("exo__Asset_label"in t)){let c=Am.inferLabelFromBasename(e.basename);if(c!==null){let l=Kt.Namespace.RDFS.term("label"),u=Kt.Namespace.EXO.term("Asset_label"),f=new mn.Literal(c);r.push(new mr.Triple(i,l,f)),r.push(new mr.Triple(i,u,f))}}r.push(...this.pendingExtraTriples),this.pendingExtraTriples=[];let a=await this.convertBodyWikilinks(e,i);return r.push(...a),r}async convertExo003Note(e,t){let r=Pn.Exo003Parser.parse(t);if(!r.success||!r.metadata)return[];let i=r.metadata,s=[];switch(i.metadata){case Pn.Exo003MetadataType.Namespace:break;case Pn.Exo003MetadataType.Anchor:s.push(...this.convertExo003Anchor(e,i));break;case Pn.Exo003MetadataType.BlankNode:s.push(...this.convertExo003BlankNode(e,i));break;case Pn.Exo003MetadataType.Statement:s.push(...this.convertExo003Statement(e,i));break;case Pn.Exo003MetadataType.Body:s.push(...await this.convertExo003Body(e,i));break}return s}convertExo003Anchor(e,t){let r=this.notePathToIRI(e.path),i=new Wa.IRI(t.uri);return[new mr.Triple(r,Kt.Namespace.OWL.term("sameAs"),i),new mr.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 mr.Triple(r,Kt.Namespace.OWL.term("sameAs"),new pC.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Pn.Exo003Parser.toTriple(t,i);r.push(s);let a=this.notePathToIRI(e.path);r.push(new mr.Triple(a,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),a=this.createExo003ReferenceResolver(e),c=a(t.subject),l=a(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 Wa.IRI(c.value):new pC.BlankNode(c.value),f=new Wa.IRI(l.value),d=Pn.Exo003Parser.toLiteral(t,s.trim());r.push(new mr.Triple(u,f,d));let h=this.notePathToIRI(e.path);r.push(new mr.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 a=this.vault.getFrontmatter(s);if(a&&Pn.Exo003Parser.isExo003Format(a)){let c=Pn.Exo003Parser.parse(a);if(c.success&&c.metadata){let l=c.metadata;if(l.metadata===Pn.Exo003MetadataType.Anchor||l.metadata===Pn.Exo003MetadataType.Namespace)return{type:"iri",value:l.uri};if(l.metadata===Pn.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(){return(await this.convertVaultWithValidation({strict:!1})).triples}async convertVaultWithValidation(e={}){let t=this.vault.getAllFiles(),r=[],i=[],s=e.strict??!1;for(let a of t)try{let c=this.vault.getFrontmatter(a),l=c?this.validateExocortexAsset(c,a.basename):null;if(l){if(s)throw new Error(`Invariant violation in "${a.path}": ${l.message}`);i.push({path:a.path,reason:`Invariant violation: ${l.message}`}),this.logger.warn(`Skipping file with invariant violation: ${a.path}`,{code:l.code,property:l.property,reason:l.message});continue}let u=await this.convertNote(a);r.push(...u)}catch(c){let l=c instanceof Error?c.message:String(c);if(s)throw new Error(`Invalid IRI for file "${a.path}": ${l}`);i.push({path:a.path,reason:`Invalid IRI: ${l}`}),this.logger.warn(`Skipping file with invalid IRI: ${a.path}`,{reason:l})}return{triples:r,skippedFiles:i,summary:{total:t.length,indexed:t.length-i.length,skipped:i.length}}}static inferLabelFromBasename(e){return Kt.Namespace.fromPropertyKey(e)!==null?e:null}validateExocortexAsset(e,t){let r=o(f=>f==null?!0:typeof f=="string"?f.trim()==="":Array.isArray(f)?f.length===0||f.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=t?Am.inferLabelFromBasename(t):null,a=["exo__Asset_uid","exo__Asset_isDefinedBy","exo__Asset_label","exo__Instance_class"];for(let f of a)if(!(f==="exo__Asset_label"&&s!==null)){if(!(f in e))return{code:"MISSING_PROPERTY",property:f,message:`Required property "${f}" is missing`};if(r(e[f]))return{code:"EMPTY_PROPERTY",property:f,message:`Required property "${f}" is empty`}}let c=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let f of c)if(f in e&&r(e[f]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:f,message:`Optional property "${f}" is present but empty`};let l=e.exo__Instance_class,u=Array.isArray(l)?l:[l];for(let f of u){if(typeof f!="string")continue;let d=this.removeQuotes(f),p=(this.extractWikilink(d)??d).trim();if(/^[a-z][a-zA-Z0-9]*__/.test(p)&&/[\s()]/.test(p))return{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${f}"`}}return null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,gC.vaultPathToIRI)(r.path);Wa.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 Wa.IRI((0,gC.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 a=this.valueToClassURI(s);a instanceof Wa.IRI&&(this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.RDF.term("type"),a)),this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),a)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let a=this.vault.getFirstLinkpathDest(s,t.path);if(a){let c=this.notePathToIRI(a.path),l=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(l)){let f=new mn.Literal(l),d=this.expandClassValue(a.basename);if(d)return this.emitTypeTripleForEnumInstance(d,a),[d];let h=this.vault.getFrontmatter(a);if(h){let y=h.exo__Asset_label;if(typeof y=="string"){let v=this.expandClassValue(y);if(v)return this.emitTypeTripleForEnumInstance(v,a),[v]}}return r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype")?[c,f]:[c]}let u=this.expandClassValue(a.basename);return u?(this.emitTypeTripleForEnumInstance(u,a),[u]):[c]}if(this.isClassReference(s)){let c=this.expandClassValue(s);if(c)return[c]}return[new mn.Literal(i)]}if(this.isClassReference(i)){let a=this.expandClassValue(i);if(a)return[a]}return this.isISO8601DateTime(i)?[new mn.Literal(i,Kt.Namespace.XSD.term("dateTime"))]:[new mn.Literal(i)]}return typeof e=="boolean"?[new mn.Literal(e.toString())]:typeof e=="number"?[new mn.Literal(e.toString(),Kt.Namespace.XSD.term("decimal"))]:e instanceof Date?[new mn.Literal(e.toISOString(),Kt.Namespace.XSD.term("dateTime"))]:[new mn.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 mn.Literal(String(e));let t=this.removeQuotes(e),i=this.extractWikilink(t)||t,s=this.expandClassValue(i);if(s)return s;let a=this.extractWikilinkAlias(t);if(a){let c=this.expandClassValue(a);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 new mn.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?r.namespace.term(r.localName):null}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),a=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of a){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new mr.Triple(t,c,f))}else if(this.isClassReference(l)){let f=this.expandClassValue(l);f?r.push(new mr.Triple(t,c,f)):r.push(new mr.Triple(t,c,new mn.Literal(l)))}else r.push(new mr.Triple(t,c,new mn.Literal(l)))}}catch{}return r}};Bi.NoteToRDFConverter=bl;bl.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};bl.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};bl.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};Bi.NoteToRDFConverter=bl=Am=rB([(0,pb.injectable)(),hC(0,(0,pb.inject)(mC.DI_TOKENS.IVaultAdapter)),hC(1,(0,pb.inject)(mC.DI_TOKENS.ILogger)),nB("design:paramtypes",[Object,Object])],bl)});var yb=S(xm=>{"use strict";Object.defineProperty(xm,"__esModule",{value:!0});xm.FilterContainsOptimizer=void 0;var aB=Ae(),oB=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,gb=class{static{o(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(oB);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 aB.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(a=>a.subject.type==="variable"&&a.subject.value===t?{...a,subject:{type:"iri",value:r}}:a);if(i.some((a,c)=>a.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(a=>({[t.variable]:{type:"iri",value:a}}))},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)}};xm.FilterContainsOptimizer=gb});var yC=S(Cm=>{"use strict";Object.defineProperty(Cm,"__esModule",{value:!0});Cm.AlgebraOptimizer=void 0;var cB=yb(),_b=class{static{o(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new cB.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),a=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return a&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!a?{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)}};Cm.AlgebraOptimizer=_b});var _C=S(Im=>{"use strict";Object.defineProperty(Im,"__esModule",{value:!0});Im.AlgebraSerializer=void 0;var Sb=class{static{o(this,"AlgebraSerializer")}toString(e,t=0){let r=" ".repeat(t);switch(e.type){case"bgp":return`${r}BGP [
377
+ `),t}};vm.RDFSerializer=Jv});var Zv=S(Sl=>{"use strict";Object.defineProperty(Sl,"__esModule",{value:!0});Sl.OBSIDIAN_VAULT_SCHEME=void 0;Sl.vaultPathToIRI=B$;Sl.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function B$(n){let e=n.startsWith("./")?n.slice(2):n;return`${Sl.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}o(B$,"vaultPathToIRI")});var tb=S(bm=>{"use strict";Object.defineProperty(bm,"__esModule",{value:!0});bm.RDFVocabularyMapper=void 0;var tr=Yn(),aC=Ae(),J=lr(),eb=class{static{o(this,"RDFVocabularyMapper")}constructor(){this.propertyMappings=new Map([["exo__Instance_class",J.Namespace.RDF.term("type")],["exo__Asset_isDefinedBy",J.Namespace.RDFS.term("isDefinedBy")],["exo__Class_superClass",J.Namespace.RDFS.term("subClassOf")],["exo__Property_range",J.Namespace.RDFS.term("range")],["exo__Property_domain",J.Namespace.RDFS.term("domain")],["exo__Property_superProperty",J.Namespace.RDFS.term("subPropertyOf")]])}generateClassHierarchyTriples(){let e=[];return e.push(new tr.Triple(J.Namespace.EXO.term("Asset"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Resource"))),e.push(new tr.Triple(J.Namespace.EXO.term("Class"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Class"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDF.term("Property"))),e.push(new tr.Triple(J.Namespace.EMS.term("Task"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Project"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Area"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("Workflow"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("WorkflowState"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EMS.term("WorkflowTransition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Command"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Precondition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("Grounding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new tr.Triple(J.Namespace.EXOCMD.term("CommandBinding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new tr.Triple(J.Namespace.EXO.term("Instance_class"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDF.term("type"))),e.push(new tr.Triple(J.Namespace.EXO.term("Asset_isDefinedBy"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("isDefinedBy"))),e.push(new tr.Triple(J.Namespace.EXO.term("Class_superClass"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subClassOf"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_range"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("range"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_domain"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("domain"))),e.push(new tr.Triple(J.Namespace.EXO.term("Property_superProperty"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subPropertyOf"))),e}generateMappedTriple(e,t,r){let i=this.propertyMappings.get(t);if(!i)return null;let s;if(r instanceof aC.IRI)s=r;else{let a=r.match(/^(ems|exo|exocmd)__(.+)$/);if(a){let[,c,l]=a;s=(c==="ems"?J.Namespace.EMS:c==="exocmd"?J.Namespace.EXOCMD:J.Namespace.EXO).term(l)}else s=new aC.IRI(r)}return new tr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};bm.RDFVocabularyMapper=eb});var oC=S(Em=>{"use strict";Object.defineProperty(Em,"__esModule",{value:!0});Em.RDFSInferenceEngine=void 0;var V$=Yn(),wm=Ae(),rb=class{static{o(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 a=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof wm.IRI){let h=a.get(d.object.value);if(h)for(let p of h)u.push(new V$.Triple(d.subject,i,new wm.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 wm.IRI&&s.object instanceof wm.IRI){let a=s.subject.value,c=s.object.value;i.has(a)||i.set(a,new Set),i.get(a).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=[],a=t.get(e);if(a)for(let c of a)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}};Em.RDFSInferenceEngine=rb});var sb=S(Ko=>{"use strict";var U$=Ko&&Ko.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ko,"__esModule",{value:!0});Ko.NonInheritablePropertyRegistry=void 0;var q$=fe(),cC=Ae(),lC=Ne(),nb=lr(),ib=class{static{o(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 a=t.find(c=>c.value.includes("Asset_label"));if(!a){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,a,void 0);for(let u of l)if(u.object instanceof lC.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(a=>a.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new lC.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof cC.IRI)return i[0].subject;let s=t.find(a=>a.value.includes("Instance_class"));if(s){let a=await e.match(void 0,s,void 0);for(let c of a)if(c.object instanceof cC.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?nb.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?nb.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?nb.Namespace.EXOCMD.term(e.substring(8)).value:null}};Ko.NonInheritablePropertyRegistry=ib;Ko.NonInheritablePropertyRegistry=ib=U$([(0,q$.injectable)()],ib)});var cb=S(Yo=>{"use strict";var W$=Yo&&Yo.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Yo,"__esModule",{value:!0});Yo.PropertyCardinalityRegistry=void 0;var G$=fe(),uC=Ae(),fC=Ne(),ab=lr(),ob=class{static{o(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 a=t.find(c=>c.value.includes("Asset_label"));if(!a){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,a,void 0);for(let u of l)if(u.object instanceof fC.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(a=>a.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new fC.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof uC.IRI)return i[0].subject;let s=t.find(a=>a.value.includes("Instance_class"));if(s){let a=await e.match(void 0,s,void 0);for(let c of a)if(c.object instanceof uC.IRI&&c.object.value.includes("PropertyCardinalityMultiple"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?ab.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?ab.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?ab.Namespace.EXOCMD.term(e.substring(8)).value:null}};Yo.PropertyCardinalityRegistry=ob;Yo.PropertyCardinalityRegistry=ob=W$([(0,G$.injectable)()],ob)});var fb=S(br=>{"use strict";var z$=br&&br.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},H$=br&&br.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(br,"__esModule",{value:!0});br.PrototypeChainMaterializer=br.MAX_PROTOTYPE_DEPTH=br.INFERRED_GRAPH=void 0;br.inferredGraphForDepth=lb;var Q$=fe(),dC=Yn(),qa=Ae(),K$=sb(),Y$=cb();br.INFERRED_GRAPH=new qa.IRI("https://exocortex.my/ontology/exo#inferred");var X$="https://exocortex.my/ontology/exo#inferred/";function lb(n){return new qa.IRI(`${X$}${n}`)}o(lb,"inferredGraphForDepth");br.MAX_PROTOTYPE_DEPTH=10;var ub=class{static{o(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 qa.IRI&&c.object instanceof qa.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let a=0;for(let[c]of s){let l=new qa.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 y=p.object instanceof qa.IRI?p.object.value:String(p.object),v=h.get(p.predicate.value);v||(v=new Set,h.set(p.predicate.value,v)),v.add(y)}for(let p=0;p<u.length;p++){let y=u[p],v=p+1,w=new qa.IRI(y),b=await e.match(w,void 0,void 0),T=new Set;if(e.matchInGraph){let R=await e.matchInGraph(w,void 0,void 0,br.INFERRED_GRAPH);for(let $ of R)T.add($.predicate.value)}for(let R of b){let $=R.predicate.value;if(this.registry.isNonInheritable($)||T.has($))continue;if(d.has($)&&this.isMultiValued($)){let ce=R.object instanceof qa.IRI?R.object.value:String(R.object);if(h.get($)?.has(ce))continue;let U=h.get($);U||(U=new Set,h.set($,U)),U.add(ce);let F=new dC.Triple(l,R.predicate,R.object);await e.add(F),e.addToGraph&&(await e.addToGraph(F,br.INFERRED_GRAPH),await e.addToGraph(F,lb(v))),a++;continue}if(d.has($))continue;let q=new dC.Triple(l,R.predicate,R.object);await e.add(q),e.addToGraph&&(await e.addToGraph(q,br.INFERRED_GRAPH),await e.addToGraph(q,lb(v))),d.add($),a++}}}return a}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],a=t.get(e);for(a&&s.push(a.value);s.length>0&&r.length<br.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}};br.PrototypeChainMaterializer=ub;br.PrototypeChainMaterializer=ub=z$([(0,Q$.injectable)(),H$("design:paramtypes",[K$.NonInheritablePropertyRegistry,Y$.PropertyCardinalityRegistry])],ub)});var hb=S(pr=>{"use strict";var J$=pr&&pr.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},Z$=pr&&pr.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(pr,"__esModule",{value:!0});pr.SourceAnnotator=pr.DEPTH_VARIABLE=pr.SOURCE_VARIABLE=void 0;var eB=fe(),vl=Ne(),tB=Ae(),Tm=fb();pr.SOURCE_VARIABLE="_source";pr.DEPTH_VARIABLE="_depth";var db=class{static{o(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(a=>{let c=a.clone();return c.set(pr.SOURCE_VARIABLE,new vl.Literal("own")),c});let s=[];for(let a of e){let c=a.get(t),l=a.get(r),u=a.get(i),f=a.clone();if(!c||!l||!u)f.set(pr.SOURCE_VARIABLE,new vl.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(pr.SOURCE_VARIABLE,new vl.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,Tm.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=Tm.MAX_PROTOTYPE_DEPTH;i++){let s=(0,Tm.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 a=s.clone();return a.set(pr.SOURCE_VARIABLE,new vl.Literal("own")),a});let r=[],i=new Map;for(let s of e){let a=s.get(t),c=s.clone();if(!a||!(a instanceof tB.IRI))c.set(pr.SOURCE_VARIABLE,new vl.Literal("own"));else{let l=a.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(a,void 0,void 0,Tm.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(pr.SOURCE_VARIABLE,new vl.Literal(u))}r.push(c)}return r}};pr.SourceAnnotator=db;pr.SourceAnnotator=db=J$([(0,eB.injectable)(),Z$("design:paramtypes",[Object])],db)});var mb=S(Bi=>{"use strict";var rB=Bi&&Bi.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},nB=Bi&&Bi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},hC=Bi&&Bi.__param||function(n,e){return function(t,r){e(t,r,n)}},Am;Object.defineProperty(Bi,"__esModule",{value:!0});Bi.NoteToRDFConverter=void 0;var pb=fe(),mr=Yn(),Wa=Ae(),mn=Ne(),pC=qt(),Kt=lr(),mC=Et(),iB=tb(),sB=Pc(),gC=Zv(),Pn=s_(),bl=Am=class{static{o(this,"NoteToRDFConverter")}constructor(e,t=sB.NullLogger){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new iB.RDFVocabularyMapper}async convertNote(e){let t=this.vault.getFrontmatter(e);return t?Pn.Exo003Parser.isExo003Format(t)?this.convertExo003Note(e,t):this.convertLegacyNote(e,t):[]}async convertLegacyNote(e,t){this.pendingExtraTriples=[];let r=[],i=this.notePathToIRI(e.path),s=Kt.Namespace.EXO.term("Asset_fileName");r.push(new mr.Triple(i,s,new mn.Literal(e.basename)));for(let[c,l]of Object.entries(t)){if(!this.isExocortexProperty(c))continue;let u=this.propertyKeyToIRI(c),f=Array.isArray(l)?l:[l];for(let d of f)if(c==="exo__Instance_class"){let h=this.valueToClassURI(d);r.push(new mr.Triple(i,u,h))}else{let h=await this.valueToRDFObject(d,e,u);for(let p of h)if(r.push(new mr.Triple(i,u,p)),this.vocabularyMapper.hasMappingFor(c)&&p instanceof Wa.IRI){let y=this.vocabularyMapper.generateMappedTriple(i,c,p);y&&r.push(y)}}if(c==="exo__Instance_class")for(let d of f){let h=this.valueToClassURI(d);if(h instanceof Wa.IRI){let p=Kt.Namespace.RDF.term("type");r.push(new mr.Triple(i,p,h))}}if(c==="exo__Asset_label"){let d=Kt.Namespace.RDFS.term("label");for(let h of f)typeof h=="string"&&h.length>0&&r.push(new mr.Triple(i,d,new mn.Literal(h)))}}if(!("exo__Asset_label"in t)){let c=Am.inferLabelFromBasename(e.basename);if(c!==null){let l=Kt.Namespace.RDFS.term("label"),u=Kt.Namespace.EXO.term("Asset_label"),f=new mn.Literal(c);r.push(new mr.Triple(i,l,f)),r.push(new mr.Triple(i,u,f))}}r.push(...this.pendingExtraTriples),this.pendingExtraTriples=[];let a=await this.convertBodyWikilinks(e,i);return r.push(...a),r}async convertExo003Note(e,t){let r=Pn.Exo003Parser.parse(t);if(!r.success||!r.metadata)return[];let i=r.metadata,s=[];switch(i.metadata){case Pn.Exo003MetadataType.Namespace:break;case Pn.Exo003MetadataType.Anchor:s.push(...this.convertExo003Anchor(e,i));break;case Pn.Exo003MetadataType.BlankNode:s.push(...this.convertExo003BlankNode(e,i));break;case Pn.Exo003MetadataType.Statement:s.push(...this.convertExo003Statement(e,i));break;case Pn.Exo003MetadataType.Body:s.push(...await this.convertExo003Body(e,i));break}return s}convertExo003Anchor(e,t){let r=this.notePathToIRI(e.path),i=new Wa.IRI(t.uri);return[new mr.Triple(r,Kt.Namespace.OWL.term("sameAs"),i),new mr.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 mr.Triple(r,Kt.Namespace.OWL.term("sameAs"),new pC.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Pn.Exo003Parser.toTriple(t,i);r.push(s);let a=this.notePathToIRI(e.path);r.push(new mr.Triple(a,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),a=this.createExo003ReferenceResolver(e),c=a(t.subject),l=a(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 Wa.IRI(c.value):new pC.BlankNode(c.value),f=new Wa.IRI(l.value),d=Pn.Exo003Parser.toLiteral(t,s.trim());r.push(new mr.Triple(u,f,d));let h=this.notePathToIRI(e.path);r.push(new mr.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 a=this.vault.getFrontmatter(s);if(a&&Pn.Exo003Parser.isExo003Format(a)){let c=Pn.Exo003Parser.parse(a);if(c.success&&c.metadata){let l=c.metadata;if(l.metadata===Pn.Exo003MetadataType.Anchor||l.metadata===Pn.Exo003MetadataType.Namespace)return{type:"iri",value:l.uri};if(l.metadata===Pn.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(){return(await this.convertVaultWithValidation({strict:!1})).triples}async convertVaultWithValidation(e={}){let t=this.vault.getAllFiles(),r=[],i=[],s=e.strict??!1;for(let a of t)try{let c=this.vault.getFrontmatter(a),l=c?this.validateExocortexAsset(c,a.basename):null;if(l){if(s)throw new Error(`Invariant violation in "${a.path}": ${l.message}`);i.push({path:a.path,reason:`Invariant violation: ${l.message}`}),this.logger.warn(`Skipping file with invariant violation: ${a.path}`,{code:l.code,property:l.property,reason:l.message});continue}let u=await this.convertNote(a);r.push(...u)}catch(c){let l=c instanceof Error?c.message:String(c);if(s)throw new Error(`Invalid IRI for file "${a.path}": ${l}`);i.push({path:a.path,reason:`Invalid IRI: ${l}`}),this.logger.warn(`Skipping file with invalid IRI: ${a.path}`,{reason:l})}return{triples:r,skippedFiles:i,summary:{total:t.length,indexed:t.length-i.length,skipped:i.length}}}static inferLabelFromBasename(e){return Kt.Namespace.fromPropertyKey(e)!==null?e:null}validateExocortexAsset(e,t){let r=o(f=>f==null?!0:typeof f=="string"?f.trim()==="":Array.isArray(f)?f.length===0||f.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=t?Am.inferLabelFromBasename(t):null,a=["exo__Asset_uid","exo__Asset_isDefinedBy","exo__Asset_label","exo__Instance_class"];for(let f of a)if(!(f==="exo__Asset_label"&&s!==null)){if(!(f in e))return{code:"MISSING_PROPERTY",property:f,message:`Required property "${f}" is missing`};if(r(e[f]))return{code:"EMPTY_PROPERTY",property:f,message:`Required property "${f}" is empty`}}let c=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let f of c)if(f in e&&r(e[f]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:f,message:`Optional property "${f}" is present but empty`};let l=e.exo__Instance_class,u=Array.isArray(l)?l:[l];for(let f of u){if(typeof f!="string")continue;let d=this.removeQuotes(f),p=(this.extractWikilink(d)??d).trim();if(/^[a-z][a-zA-Z0-9]*__/.test(p)&&/[\s()]/.test(p))return{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${f}"`}}return null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,gC.vaultPathToIRI)(r.path);Wa.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 Wa.IRI((0,gC.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 a=this.valueToClassURI(s);a instanceof Wa.IRI&&(this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.RDF.term("type"),a)),this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),a)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let a=this.vault.getFirstLinkpathDest(s,t.path);if(a){let l=this.notePathToIRI(a.path),u=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(u)){let d=new mn.Literal(u),h=this.expandClassValue(a.basename);if(h)return this.emitTypeTripleForEnumInstance(h,a),[h];let p=this.vault.getFrontmatter(a);if(p){let v=p.exo__Asset_label;if(typeof v=="string"){let w=this.expandClassValue(v);if(w)return this.emitTypeTripleForEnumInstance(w,a),[w]}}return r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype")?[l,d]:[l]}let f=this.expandClassValue(a.basename);return f?(this.emitTypeTripleForEnumInstance(f,a),[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.notePathToIRI(`${c}.md`)]:[new mn.Literal(i)]}if(this.isClassReference(i)){let a=this.expandClassValue(i);if(a)return[a]}return this.isISO8601DateTime(i)?[new mn.Literal(i,Kt.Namespace.XSD.term("dateTime"))]:[new mn.Literal(i)]}return typeof e=="boolean"?[new mn.Literal(e.toString())]:typeof e=="number"?[new mn.Literal(e.toString(),Kt.Namespace.XSD.term("decimal"))]:e instanceof Date?[new mn.Literal(e.toISOString(),Kt.Namespace.XSD.term("dateTime"))]:[new mn.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 mn.Literal(String(e));let t=this.removeQuotes(e),i=this.extractWikilink(t)||t,s=this.expandClassValue(i);if(s)return s;let a=this.extractWikilinkAlias(t);if(a){let c=this.expandClassValue(a);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 new mn.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?r.namespace.term(r.localName):null}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),a=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of a){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new mr.Triple(t,c,f))}else if(this.isClassReference(l)){let f=this.expandClassValue(l);f?r.push(new mr.Triple(t,c,f)):r.push(new mr.Triple(t,c,new mn.Literal(l)))}else r.push(new mr.Triple(t,c,new mn.Literal(l)))}}catch{}return r}};Bi.NoteToRDFConverter=bl;bl.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};bl.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};bl.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};Bi.NoteToRDFConverter=bl=Am=rB([(0,pb.injectable)(),hC(0,(0,pb.inject)(mC.DI_TOKENS.IVaultAdapter)),hC(1,(0,pb.inject)(mC.DI_TOKENS.ILogger)),nB("design:paramtypes",[Object,Object])],bl)});var yb=S(xm=>{"use strict";Object.defineProperty(xm,"__esModule",{value:!0});xm.FilterContainsOptimizer=void 0;var aB=Ae(),oB=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,gb=class{static{o(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(oB);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 aB.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(a=>a.subject.type==="variable"&&a.subject.value===t?{...a,subject:{type:"iri",value:r}}:a);if(i.some((a,c)=>a.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(a=>({[t.variable]:{type:"iri",value:a}}))},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)}};xm.FilterContainsOptimizer=gb});var yC=S(Cm=>{"use strict";Object.defineProperty(Cm,"__esModule",{value:!0});Cm.AlgebraOptimizer=void 0;var cB=yb(),_b=class{static{o(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new cB.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),a=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return a&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!a?{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)}};Cm.AlgebraOptimizer=_b});var _C=S(Im=>{"use strict";Object.defineProperty(Im,"__esModule",{value:!0});Im.AlgebraSerializer=void 0;var Sb=class{static{o(this,"AlgebraSerializer")}toString(e,t=0){let r=" ".repeat(t);switch(e.type){case"bgp":return`${r}BGP [
378
378
  ${e.triples.map(u=>`${r} ${this.tripleToString(u)}`).join(`
379
379
  `)}
380
380
  ${r}]`;case"filter":return`${r}Filter(
@@ -805,7 +805,7 @@ exo__BacklinksTableBlock_columns:${f==="[]"?" []":f}
805
805
  `),console.log(`${"Rank".padEnd(6)}${"Term".padEnd(30)}${"Freq".padEnd(8)}Sample UIDs`),console.log("-".repeat(90)),c.forEach((u,f)=>{let d=`#${f+1}`.padEnd(6),h=u.term.padEnd(30),p=String(u.frequency).padEnd(8),y=u.sample_uids.join(", ");console.log(`${d}${h}${p}${y}`)})})}o(LN,"backfillOrphanTermsCommand");function kN(){let n=new se("backfill").description("Concept backfill tools for aiKnow assets");return n.addCommand(NN()),n.addCommand(LN()),n}o(kN,"backfillCommand");var Ny=require("path"),WN=require("fs"),GN=require("os");var Fy=require("child_process"),Dy=require("fs"),BN=require("path");var Zi=require("fs"),Oy=K(require("path")),jN=require("crypto");var IJ=/^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n([\s\S]*))?$/;function MN(n){let e=n.match(IJ);if(!e)return null;let[,t,r=""]=e,i=ar.load(t);if(i==null)return{frontmatter:{},body:r};if(typeof i!="object"||Array.isArray(i))throw new Error("frontmatter is not a YAML mapping");return{frontmatter:i,body:r}}o(MN,"parseFile");function RJ(n,e){let t=ar.dump(n,{lineWidth:-1,quotingType:'"',forceQuotes:!1,noRefs:!0}),r=e.length>0?e:"";return`---
806
806
  ${t}---
807
807
  ${r}`}o(RJ,"serializeFile");function $N(n,e,t={}){let r=Oy.default.dirname(n),i=Oy.default.basename(n),s=Oy.default.join(r,`.${i}.tmp.${process.pid}.${(0,jN.randomBytes)(6).toString("hex")}`);try{let a=(0,Zi.readFileSync)(n,"utf8"),c;try{c=MN(a)}catch(f){return{success:!1,verified:!1,reason:"parse-error",error:f.message}}if(!c)return{success:!1,verified:!1,reason:"no-frontmatter"};let l={...c.frontmatter,...e},u=RJ(l,c.body);if((0,Zi.writeFileSync)(s,u,"utf8"),(0,Zi.renameSync)(s,n),t.verifyKey!==void 0){let f=(0,Zi.readFileSync)(n,"utf8"),d;try{d=MN(f)}catch(p){return{success:!1,verified:!1,reason:"parse-error",error:p.message}}if(!d)return{success:!1,verified:!1,reason:"no-frontmatter"};let h=d.frontmatter[t.verifyKey];return h!==t.verifyValue?{success:!1,verified:!1,reason:"verify-mismatch",error:`expected ${t.verifyKey}=${String(t.verifyValue)}, got ${String(h)}`}:{success:!0,verified:!0}}return{success:!0,verified:!0}}catch(a){if((0,Zi.existsSync)(s))try{(0,Zi.unlinkSync)(s)}catch{}return{success:!1,verified:!1,reason:"fs-error",error:a.message}}}o($N,"atomicUpdateFrontmatter");var PJ=/^claude-child-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,OJ=/^claude-child-([0-9a-f]{8})-(\d+)$/,FJ="EffortStatusDoing";function VN(n){return e=>new Promise((t,r)=>{n(e,(i,s,a)=>{i?r(Object.assign(i,{stdout:s,stderr:a})):t(s)})})}o(VN,"makeExecPromise");async function DJ(n=Fy.exec){let e=VN(n),t;try{t=await e("tmux list-sessions -F '#{session_name}' 2>/dev/null")}catch{return[]}let r=[];for(let i of t.split(`
808
- `).map(s=>s.trim()).filter(Boolean)){let s=PJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let a=OJ.exec(i);a&&r.push({sessionName:i,uuid:a[1],type:"short"})}return r}o(DJ,"listClaudeChildSessions");function NJ(n,e,t){let r=null,i=e.toLowerCase();function s(a){if(r)return;let c;try{c=(0,Dy.readdirSync)(a,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,BN.join)(a,l.name);if(l.isDirectory())s(u);else if(l.name.endsWith(".md")){let f=l.name.slice(0,-3).toLowerCase();(t==="full"&&f===i||t==="short"&&f.startsWith(i))&&(r=u)}}}return o(s,"walk"),s(n),r}o(NJ,"findVaultFile");function LJ(n,e){try{let i=(e??(s=>(0,Dy.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(FJ):!1}catch{return!1}}o(LJ,"isTaskDoing");async function UN(n,e=Fy.exec,t){let r=await DJ(e),i=[];for(let s of r){let a=NJ(n,s.uuid,s.type);if(!a){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}LJ(a,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:a,reason:"vault task status != Doing"})}return i}o(UN,"detectOrphans");async function qN(n,e,t=Fy.exec,r=$N){let i=VN(t);if(e)return{ok:!0};let s=new Date().toISOString();if(n.taskFilePath)try{r(n.taskFilePath,{ems__Effort_status:"[[ems__EffortStatusFailed]]",aiTask__Task_lastError:`orphan recovery: ${n.reason}`,exo__Asset_updatedAt:s})}catch(a){return{ok:!1,error:`vault update failed: ${a.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}o(qN,"recoverOrphan");function kJ(){return process.env.EXOCORTEX_VAULT??(0,Ny.join)((0,GN.homedir)(),"vault-2025")}o(kJ,"defaultVault");function zN(){return new se("recover").description("Detect and recover orphaned claude-child tmux sessions. A session is orphaned when the corresponding vault task is not in Doing status. Default mode: dry-run (no changes). Use --apply to perform recovery.").option("--vault <path>","Path to Obsidian vault",kJ()).option("--dry-run","List orphans without applying changes (default)",!1).option("--apply","Apply orphan recovery: set Failed + kill tmux session",!1).action(async n=>{let e=(0,Ny.resolve)(n.vault);if(!(0,WN.existsSync)(e)){console.error(`[recover] vault not found: ${e}`),process.exitCode=1;return}let t=!n.apply;console.log(`[recover] vault=${e} mode=${t?"dry-run":"apply"}`);let r=await UN(e);if(r.length===0){console.log("[recover] No orphaned claude-child sessions found.");return}console.log(`[recover] Found ${r.length} orphan(s):`);for(let a of r){let c=a.taskFilePath??"(not found in vault)";console.log(` session=${a.sessionName} uuid=${a.taskUuid} reason=${a.reason}`),console.log(` file=${c}`)}if(t){console.log("[recover] Dry-run mode: no changes applied. Use --apply to recover.");return}let i=0,s=0;for(let a of r){let c=await qN(a,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${a.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${a.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}o(zN,"recoverCommand");function HN(n){n.addCommand(iF()),n.addCommand(cF()),n.addCommand(lF())}o(HN,"addQuerySubcommands");function QN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.173.0");let t=e.command("exoql").description("ExoQL query execution and cache management");HN(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return HN(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(yD()),e.addCommand(vD()),e.addCommand(bD()),e.addCommand(ED()),e.addCommand(TD()),e.addCommand(RD()),e.addCommand(DD()),e.addCommand(zD()),e.addCommand(KD()),e.addCommand(eN()),e.addCommand(nN()),e.addCommand(iN()),e.addCommand(aN()),e.addCommand(yN()),e.addCommand(bN()),e.addCommand(IN()),e.addCommand(RN()),e.addCommand(kN()),e.addCommand(zN()),e}o(QN,"createProgram");QN().parse();0&&(module.exports={createProgram});
808
+ `).map(s=>s.trim()).filter(Boolean)){let s=PJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let a=OJ.exec(i);a&&r.push({sessionName:i,uuid:a[1],type:"short"})}return r}o(DJ,"listClaudeChildSessions");function NJ(n,e,t){let r=null,i=e.toLowerCase();function s(a){if(r)return;let c;try{c=(0,Dy.readdirSync)(a,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,BN.join)(a,l.name);if(l.isDirectory())s(u);else if(l.name.endsWith(".md")){let f=l.name.slice(0,-3).toLowerCase();(t==="full"&&f===i||t==="short"&&f.startsWith(i))&&(r=u)}}}return o(s,"walk"),s(n),r}o(NJ,"findVaultFile");function LJ(n,e){try{let i=(e??(s=>(0,Dy.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(FJ):!1}catch{return!1}}o(LJ,"isTaskDoing");async function UN(n,e=Fy.exec,t){let r=await DJ(e),i=[];for(let s of r){let a=NJ(n,s.uuid,s.type);if(!a){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}LJ(a,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:a,reason:"vault task status != Doing"})}return i}o(UN,"detectOrphans");async function qN(n,e,t=Fy.exec,r=$N){let i=VN(t);if(e)return{ok:!0};let s=new Date().toISOString();if(n.taskFilePath)try{r(n.taskFilePath,{ems__Effort_status:"[[ems__EffortStatusFailed]]",aiTask__Task_lastError:`orphan recovery: ${n.reason}`,exo__Asset_updatedAt:s})}catch(a){return{ok:!1,error:`vault update failed: ${a.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}o(qN,"recoverOrphan");function kJ(){return process.env.EXOCORTEX_VAULT??(0,Ny.join)((0,GN.homedir)(),"vault-2025")}o(kJ,"defaultVault");function zN(){return new se("recover").description("Detect and recover orphaned claude-child tmux sessions. A session is orphaned when the corresponding vault task is not in Doing status. Default mode: dry-run (no changes). Use --apply to perform recovery.").option("--vault <path>","Path to Obsidian vault",kJ()).option("--dry-run","List orphans without applying changes (default)",!1).option("--apply","Apply orphan recovery: set Failed + kill tmux session",!1).action(async n=>{let e=(0,Ny.resolve)(n.vault);if(!(0,WN.existsSync)(e)){console.error(`[recover] vault not found: ${e}`),process.exitCode=1;return}let t=!n.apply;console.log(`[recover] vault=${e} mode=${t?"dry-run":"apply"}`);let r=await UN(e);if(r.length===0){console.log("[recover] No orphaned claude-child sessions found.");return}console.log(`[recover] Found ${r.length} orphan(s):`);for(let a of r){let c=a.taskFilePath??"(not found in vault)";console.log(` session=${a.sessionName} uuid=${a.taskUuid} reason=${a.reason}`),console.log(` file=${c}`)}if(t){console.log("[recover] Dry-run mode: no changes applied. Use --apply to recover.");return}let i=0,s=0;for(let a of r){let c=await qN(a,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${a.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${a.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}o(zN,"recoverCommand");function HN(n){n.addCommand(iF()),n.addCommand(cF()),n.addCommand(lF())}o(HN,"addQuerySubcommands");function QN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.173.1");let t=e.command("exoql").description("ExoQL query execution and cache management");HN(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return HN(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(yD()),e.addCommand(vD()),e.addCommand(bD()),e.addCommand(ED()),e.addCommand(TD()),e.addCommand(RD()),e.addCommand(DD()),e.addCommand(zD()),e.addCommand(KD()),e.addCommand(eN()),e.addCommand(nN()),e.addCommand(iN()),e.addCommand(aN()),e.addCommand(yN()),e.addCommand(bN()),e.addCommand(IN()),e.addCommand(RN()),e.addCommand(kN()),e.addCommand(zN()),e}o(QN,"createProgram");QN().parse();0&&(module.exports={createProgram});
809
809
  /*! Bundled license information:
810
810
 
811
811
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "15.173.0",
3
+ "version": "15.173.1",
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": {