@kitelev/exocortex-cli 15.176.0 → 15.176.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @kitelev/exocortex-cli v15.176.
|
|
2
|
+
// @kitelev/exocortex-cli v15.176.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),o=this.nTriplesSerializer.serialize(e,{newline:r}).trimEnd();return s?o?`${s}${r}${r}${o}${r}`:`${s}${r}`:o?`${o}${r}`:""}serializePrefixes(e,t){let r=Object.entries(e);return r.length===0?"":r.map(([i,s])=>`@prefix ${i}: <${s}> .`).join(t)}composePrefixes(e){return e.includeDefaultPrefixes??!0?{...x$,...e.prefixes??{}}:{...e.prefixes??{}}}serializeTriplesOnly(e,t){return this.nTriplesSerializer.serializeChunk(e,t).trimEnd()}};vm.TurtleSerializer=zv});var iC=S(bm=>{"use strict";Object.defineProperty(bm,"__esModule",{value:!0});bm.JSONLDSerializer=void 0;var rC=Ae(),nC=qt(),C$=Ne(),gl=lr(),R$={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},Hv=class{static{a(this,"JSONLDSerializer")}toDocument(e,t={}){let r={...R$,...t.context??{}},i=new Map;for(let s of e){let o=this.subjectToId(s.subject),c=this.compactIri(s.predicate.value,r),l=this.objectToJSONLD(s.object,r),u=i.get(o)??{"@id":o},f=u[c];f===void 0?u[c]=l:Array.isArray(f)?f.push(l):u[c]=[f,l],i.set(o,u)}return{"@context":r,"@graph":Array.from(i.values())}}serialize(e,t={}){let r=this.toDocument(e,t),i=t.pretty?t.indent??2:void 0;return JSON.stringify(r,null,i)}subjectToId(e){return e instanceof rC.IRI?e.value:e instanceof nC.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 rC.IRI)return{"@id":e.value};if(e instanceof nC.BlankNode)return{"@id":`_:${e.id}`};if(e instanceof C$.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}};bm.JSONLDSerializer=Hv});var Yv=S(wm=>{"use strict";Object.defineProperty(wm,"__esModule",{value:!0});wm.NTriplesParser=void 0;var I$=Yn(),sC=Ae(),Qv=Ne(),P$=qt(),yl=lr(),O$={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},Kv=class{static{a(this,"NTriplesParser")}parse(e,t={}){let r={prefixes:{...O$,...t.prefixes??{}},strict:t.strict??!1},i=[];return e.split(/\r?\n/).forEach((o,c)=>{let l=o.trim();!l||l.startsWith("#")||i.push(this.parseLine(l,c+1,r))}),i}parseLine(e,t,r){if(!e.endsWith("."))throw new Error(`Invalid RDF statement at line ${t}: missing '.' terminator`);let s=e.slice(0,-1).trim(),o=this.parseSubject(s,t,r);s=o.rest.trim();let c=this.parsePredicate(s,t,r);s=c.rest.trim();let l=this.parseObject(s,t,r);if(s=l.rest.trim(),s.length>0)throw new Error(`Unexpected tokens after object at line ${t}`);return new I$.Triple(o.node,c.node,l.node)}parseSubject(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):e.startsWith("_:")?this.consumeBlankNode(e,t):this.consumePrefixedName(e,t,r)}parsePredicate(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):this.consumePrefixedName(e,t,r)}parseObject(e,t,r){return e.startsWith("<")?this.consumeIRI(e,t,r):e.startsWith("_:")?this.consumeBlankNode(e,t):e.startsWith('"')?this.consumeLiteral(e,t,r):this.consumePrefixedName(e,t,r)}consumePrefixedName(e,t,r){let i=e.match(/^([a-zA-Z_][\w-]*):([^\s]+)(?:\s+(.*))?$/);if(!i)throw new Error(`Invalid token at line ${t}: ${e}`);let[,s,o,c]=i,l=r.prefixes[s];if(!l)throw new Error(`Unknown prefix "${s}" at line ${t}`);return{node:new sC.IRI(`${l}${o}`),rest:(c??"").trimStart()}}consumeIRI(e,t,r){let i=this.findClosingBracket(e,"<",">");if(i===-1)throw new Error(`Invalid IRI at line ${t}`);let s=e.slice(1,i),o=new sC.IRI(s),c=e.slice(i+1).trimStart();return{node:o,rest:c}}consumeBlankNode(e,t){let r=e.match(/^_:(\w+)(?:\s+(.*))?$/);if(!r)throw new Error(`Invalid blank node identifier at line ${t}`);let[,i,s]=r;return{node:new P$.BlankNode(i),rest:(s??"").trimStart()}}consumeLiteral(e,t,r){let{value:i,rest:s}=this.consumeQuotedString(e,t),o=s.trimStart();if(o.startsWith("^^")){o=o.slice(2).trimStart();let c=o.startsWith("<")?this.consumeIRI(o,t,r):this.consumePrefixedName(o,t,r);return{node:new Qv.Literal(i,c.node),rest:c.rest}}if(o.startsWith("@")){let c=o.match(/^@([a-zA-Z-]+)(?:\s+(.*))?$/);if(!c)throw new Error(`Invalid language tag at line ${t}`);let[,l,u]=c;return{node:new Qv.Literal(i,void 0,l),rest:(u??"").trimStart()}}return{node:new Qv.Literal(i),rest:o}}consumeQuotedString(e,t){if(!e.startsWith('"'))throw new Error(`Expected quoted string at line ${t}`);let r="";for(let i=1;i<e.length;i++){let s=e[i];if(s==="\\"){if(i+1>=e.length)throw new Error(`Invalid escape sequence at line ${t}`);let o=e[i+1];switch(o){case"t":r+=" ",i+=1;break;case"b":r+="\b",i+=1;break;case"n":r+=`
|
|
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 \\${o} at line ${t}`)}continue}if(s==='"'){let o=e.slice(i+1);return{value:r,rest:o}}r+=s}throw new Error(`Unterminated string literal at line ${t}`)}findClosingBracket(e,t,r){let i=0;for(let s=0;s<e.length;s++){let o=e[s];if(o===t){i++;continue}if(o===r&&(i--,i===0))return s}return-1}};wm.NTriplesParser=Kv});var oC=S(Em=>{"use strict";Object.defineProperty(Em,"__esModule",{value:!0});Em.TurtleParser=void 0;var _l=lr(),F$=Yv(),D$={rdf:_l.Namespace.RDF.iri.value,rdfs:_l.Namespace.RDFS.iri.value,owl:_l.Namespace.OWL.iri.value,xsd:_l.Namespace.XSD.iri.value,exo:_l.Namespace.EXO.iri.value,ems:_l.Namespace.EMS.iri.value},N$=/^@prefix\s+([a-zA-Z_][\w-]*):\s*<([^>]+)>\s*\.$/,Xv=class{static{a(this,"TurtleParser")}constructor(){this.nTriplesParser=new F$.NTriplesParser}parse(e,t={}){let r={...D$,...t.prefixes??{}},i=this.collectStatements(e),s=[];return i.forEach(({statement:o,lineNumber:c})=>{if(this.isPrefixStatement(o)){let u=o.match(N$);if(!u)throw new Error(`Invalid prefix declaration at line ${c}`);let[,f,d]=u;r[f]=d;return}if(o.includes(";")||o.includes(","))throw new Error(`Complex Turtle statements with ';' or ',' are not supported (line ${c})`);let l=this.normalizeShortcuts(o);s.push(this.nTriplesParser.parseLine(l,c,{prefixes:r,strict:!1}))}),s}collectStatements(e){let t=e.split(/\r?\n/),r=[],i="",s=0;if(t.forEach((o,c)=>{let l=o.trim();!l||l.startsWith("#")||(i||(s=c+1),i=i?`${i} ${l}`:l,l.endsWith(".")&&(r.push({statement:i,lineNumber:s}),i=""))}),i)throw new Error(`Unterminated Turtle statement near line ${s}`);return r}isPrefixStatement(e){return e.startsWith("@prefix")}normalizeShortcuts(e){return e.includes(" a ")?e.replace(/\sa\s/g," rdf:type "):e}};Em.TurtleParser=Xv});var aC=S(Tm=>{"use strict";Object.defineProperty(Tm,"__esModule",{value:!0});Tm.RDFSerializer=void 0;var Sl=Yn(),Ha=Ae(),Qa=Ne(),Jv=qt(),Ss=lr(),L$=tC(),k$=Gv(),M$=iC(),j$=oC(),$$=Yv(),B$=1024,U$=`
|
|
376
376
|
`,V$={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},Zv=class{static{a(this,"RDFSerializer")}constructor(e){this.store=e,this.turtleSerializer=new L$.TurtleSerializer,this.nTriplesSerializer=new k$.NTriplesSerializer,this.jsonldSerializer=new M$.JSONLDSerializer,this.turtleParser=new j$.TurtleParser,this.nTriplesParser=new $$.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??U$,i=t.batchSize??B$,s=t.includeDefaultPrefixes,o=t.prefixes,c=this,l=!1,u=[],f=[],d=0,h=a(async()=>{if(!l){if(f=await c.store.match(),e==="json-ld"){let y=c.jsonldSerializer.toDocument(f,{context:o,pretty:!1});u.push(...c.buildJsonLdChunks(y))}else if(e==="turtle"){let y=c.turtleSerializer.serializePrefixes(c.composePrefixes(o,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 b=c.turtleSerializer.serializeTriplesOnly(y,r);b&&(v=`${b}${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?{...V$,...e??{}}:{...e??{}}}parseJsonLd(e,t){let r;try{r=JSON.parse(e)}catch(u){throw new Error(`Invalid JSON-LD document: ${u.message}`)}let i=this.composePrefixes(t.prefixes,!0),s=this.extractContext(r),o={...i,...s},c=this.extractGraph(r),l=[];return c.forEach((u,f)=>{if(!u||typeof u!="object"||Array.isArray(u))throw new Error(`Invalid JSON-LD node at index ${f}`);let d=this.parseSubjectFromNode(u,o,f),h=Object.entries(u);for(let[p,y]of h){if(p==="@id"||p==="@context")continue;if(p==="@type"){this.collectTypeTriples(d,y,l,o);continue}let v=this.expandTerm(p,o),b=new Ha.IRI(v);this.collectTriplesForValue(d,b,y,l,o)}}),l}extractContext(e){if(!e||typeof e!="object"||Array.isArray(e))return{};let t=e["@context"];if(!t||typeof t!="object"||Array.isArray(t))return{};let r={};return Object.entries(t).forEach(([i,s])=>{typeof s=="string"&&(r[i]=s)}),r}extractGraph(e){if(Array.isArray(e))return e;if(!e||typeof e!="object")return[];let t=e["@graph"];return Array.isArray(t)?t:[e]}parseSubjectFromNode(e,t,r){let i=e["@id"];if(typeof i=="string"){if(i.startsWith("_:"))return new Jv.BlankNode(i.slice(2));if(this.isAbsoluteIri(i))return new Ha.IRI(i);let s=this.expandTerm(i,t);return new Ha.IRI(s)}return new Jv.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 Sl.Triple(e,s,new Ha.IRI(l)))})}collectTriplesForValue(e,t,r,i,s){if(r!=null){if(Array.isArray(r)){r.forEach(o=>this.collectTriplesForValue(e,t,o,i,s));return}if(typeof r=="object"){let o=r;if(typeof o["@id"]=="string"){let c=this.parseIdNode(o["@id"],s);i.push(new Sl.Triple(e,t,c));return}if(o["@value"]!==void 0){let c=this.parseLiteralObject(o,s);i.push(new Sl.Triple(e,t,c));return}}if(typeof r=="string"){i.push(new Sl.Triple(e,t,new Qa.Literal(r)));return}if(typeof r=="number"){let o=Number.isInteger(r)?Ss.Namespace.XSD.term("integer"):Ss.Namespace.XSD.term("decimal");i.push(new Sl.Triple(e,t,new Qa.Literal(r.toString(),o)));return}if(typeof r=="boolean"){let o=Ss.Namespace.XSD.term("boolean");i.push(new Sl.Triple(e,t,new Qa.Literal(r.toString(),o)));return}throw new Error("Unsupported JSON-LD value encountered")}}parseIdNode(e,t){if(e.startsWith("_:"))return new Jv.BlankNode(e.slice(2));if(this.isAbsoluteIri(e))return new Ha.IRI(e);let r=this.expandTerm(e,t);return new Ha.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 Qa.Literal(r,void 0,e["@language"],i):new Qa.Literal(r,void 0,e["@language"])}if(typeof e["@type"]=="string"){let i=this.expandTerm(e["@type"],t);return new Qa.Literal(r,new Ha.IRI(i))}return new Qa.Literal(r)}expandTerm(e,t){if(this.isAbsoluteIri(e))return e;let r=e.indexOf(":");if(r>0){let s=e.slice(0,r),o=e.slice(r+1),c=t[s];if(!c)throw new Error(`Unknown prefix "${s}" in JSON-LD document`);return`${c}${o}`}let i=t["@vocab"];if(i)return`${i}${e}`;throw new Error(`Unable to expand JSON-LD term "${e}"`)}isAbsoluteIri(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)}buildJsonLdChunks(e){let t=[],r=JSON.stringify(e["@context"]);return t.push(`{"@context":${r},"@graph":[`),e["@graph"].forEach((i,s)=>{let o=JSON.stringify(i);s>0?t.push(`,${o}`):t.push(o)}),t.push(`]}
|
|
377
|
-
`),t}};Tm.RDFSerializer=Zv});var eb=S(vl=>{"use strict";Object.defineProperty(vl,"__esModule",{value:!0});vl.OBSIDIAN_VAULT_SCHEME=void 0;vl.vaultPathToIRI=q$;vl.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function q$(n){let e=n.startsWith("./")?n.slice(2):n;return`${vl.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}a(q$,"vaultPathToIRI")});var rb=S(Am=>{"use strict";Object.defineProperty(Am,"__esModule",{value:!0});Am.RDFVocabularyMapper=void 0;var rr=Yn(),cC=Ae(),J=lr(),tb=class{static{a(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 rr.Triple(J.Namespace.EXO.term("Asset"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Resource"))),e.push(new rr.Triple(J.Namespace.EXO.term("Class"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Class"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDF.term("Property"))),e.push(new rr.Triple(J.Namespace.EMS.term("Task"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Project"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Area"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Workflow"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("WorkflowState"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("WorkflowTransition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Command"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Precondition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Grounding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("CommandBinding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new rr.Triple(J.Namespace.EXO.term("Instance_class"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDF.term("type"))),e.push(new rr.Triple(J.Namespace.EXO.term("Asset_isDefinedBy"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("isDefinedBy"))),e.push(new rr.Triple(J.Namespace.EXO.term("Class_superClass"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subClassOf"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property_range"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("range"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property_domain"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("domain"))),e.push(new rr.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 cC.IRI)s=r;else{let o=r.match(/^(ems|exo|exocmd)__(.+)$/);if(o){let[,c,l]=o;s=(c==="ems"?J.Namespace.EMS:c==="exocmd"?J.Namespace.EXOCMD:J.Namespace.EXO).term(l)}else s=new cC.IRI(r)}return new rr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};Am.RDFVocabularyMapper=tb});var lC=S(Cm=>{"use strict";Object.defineProperty(Cm,"__esModule",{value:!0});Cm.RDFSInferenceEngine=void 0;var W$=Yn(),xm=Ae(),nb=class{static{a(this,"RDFSInferenceEngine")}async materialize(e){let t=await e.predicates(),r=t.find(d=>d.value.includes("Class_superClass")),i=t.find(d=>d.value.includes("Instance_class"));if(!r||!i)return 0;let s=await this.buildDirectParentMap(e,r);if(s.size===0)return 0;let o=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof xm.IRI){let h=o.get(d.object.value);if(h)for(let p of h)u.push(new W$.Triple(d.subject,i,new xm.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 xm.IRI&&s.object instanceof xm.IRI){let o=s.subject.value,c=s.object.value;i.has(o)||i.set(o,new Set),i.get(o).add(c)}return i}computeAllAncestors(e){let t=new Map;for(let r of e.keys())t.has(r)||t.set(r,this.computeAncestorsBFS(r,e));return t}computeAncestorsBFS(e,t){let r=new Set,i=new Set,s=[],o=t.get(e);if(o)for(let c of o)s.push(c);for(;s.length>0;){let c=s.shift();if(i.has(c))continue;i.add(c),r.add(c);let l=t.get(c);if(l)for(let u of l)i.has(u)||s.push(u)}return r}};Cm.RDFSInferenceEngine=nb});var ob=S(Ka=>{"use strict";var G$=Ka&&Ka.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ka,"__esModule",{value:!0});Ka.NonInheritablePropertyRegistry=void 0;var z$=fe(),uC=Ae(),fC=Ne(),ib=lr(),sb=class{static{a(this,"NonInheritablePropertyRegistry")}constructor(){this.nonInheritableIRIs=new Set,this.initialized=!1}async initialize(e){this.nonInheritableIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Instance_class"));if(!r){this.initialized=!0;return}let i=await this.findNonInheritableClassIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof fC.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.nonInheritableIRIs.add(d)}}}catch{}this.initialized=!0}isNonInheritable(e){return this.nonInheritableIRIs.has(e)}get size(){return this.nonInheritableIRIs.size}get isInitialized(){return this.initialized}async findNonInheritableClassIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new fC.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof uC.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof uC.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?ib.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?ib.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?ib.Namespace.EXOCMD.term(e.substring(8)).value:null}};Ka.NonInheritablePropertyRegistry=sb;Ka.NonInheritablePropertyRegistry=sb=G$([(0,z$.injectable)()],sb)});var lb=S(Ya=>{"use strict";var H$=Ya&&Ya.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ya,"__esModule",{value:!0});Ya.PropertyCardinalityRegistry=void 0;var Q$=fe(),dC=Ae(),hC=Ne(),ab=lr(),cb=class{static{a(this,"PropertyCardinalityRegistry")}constructor(){this.multiValuedIRIs=new Set,this.initialized=!1}async initialize(e){this.multiValuedIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Property_cardinality"));if(!r){this.initialized=!0;return}let i=await this.findMultipleCardinalityIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof hC.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.multiValuedIRIs.add(d)}}}catch{}this.initialized=!0}isMultiValued(e){return this.multiValuedIRIs.has(e)}get size(){return this.multiValuedIRIs.size}get isInitialized(){return this.initialized}async findMultipleCardinalityIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new hC.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof dC.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof dC.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}};Ya.PropertyCardinalityRegistry=cb;Ya.PropertyCardinalityRegistry=cb=H$([(0,Q$.injectable)()],cb)});var db=S(br=>{"use strict";var K$=br&&br.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},Y$=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=ub;var X$=fe(),pC=Yn(),Go=Ae(),J$=ob(),Z$=lb();br.INFERRED_GRAPH=new Go.IRI("https://exocortex.my/ontology/exo#inferred");var eB="https://exocortex.my/ontology/exo#inferred/";function ub(n){return new Go.IRI(`${eB}${n}`)}a(ub,"inferredGraphForDepth");br.MAX_PROTOTYPE_DEPTH=10;var fb=class{static{a(this,"PrototypeChainMaterializer")}constructor(e,t){this.registry=e,this.cardinalityRegistry=t??null}async materialize(e){let r=(await e.predicates()).find(c=>c.value.includes("Asset_prototype"));if(!r)return 0;let i=await e.match(void 0,r,void 0);if(i.length===0)return 0;let s=new Map;for(let c of i)if(c.subject instanceof Go.IRI&&c.object instanceof Go.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let o=0;for(let[c]of s){let l=new Go.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 Go.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,b=new Go.IRI(y),w=await e.match(b,void 0,void 0),T=new Set;if(e.matchInGraph){let I=await e.matchInGraph(b,void 0,void 0,br.INFERRED_GRAPH);for(let $ of I)T.add($.predicate.value)}for(let I of w){let $=I.predicate.value;if(this.registry.isNonInheritable($)||T.has($))continue;if(d.has($)&&this.isMultiValued($)){let ce=I.object instanceof Go.IRI?I.object.value:String(I.object);if(h.get($)?.has(ce))continue;let V=h.get($);V||(V=new Set,h.set($,V)),V.add(ce);let F=new pC.Triple(l,I.predicate,I.object);await e.add(F),e.addToGraph&&(await e.addToGraph(F,br.INFERRED_GRAPH),await e.addToGraph(F,ub(v))),o++;continue}if(d.has($))continue;let q=new pC.Triple(l,I.predicate,I.object);await e.add(q),e.addToGraph&&(await e.addToGraph(q,br.INFERRED_GRAPH),await e.addToGraph(q,ub(v))),d.add($),o++}}}return o}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],o=t.get(e);for(o&&s.push(o.value);s.length>0&&r.length<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=fb;br.PrototypeChainMaterializer=fb=K$([(0,X$.injectable)(),Y$("design:paramtypes",[J$.NonInheritablePropertyRegistry,Z$.PropertyCardinalityRegistry])],fb)});var pb=S(pr=>{"use strict";var tB=pr&&pr.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},rB=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 nB=fe(),bl=Ne(),iB=Ae(),Rm=db();pr.SOURCE_VARIABLE="_source";pr.DEPTH_VARIABLE="_depth";var hb=class{static{a(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(o=>{let c=o.clone();return c.set(pr.SOURCE_VARIABLE,new bl.Literal("own")),c});let s=[];for(let o of e){let c=o.get(t),l=o.get(r),u=o.get(i),f=o.clone();if(!c||!l||!u)f.set(pr.SOURCE_VARIABLE,new bl.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(pr.SOURCE_VARIABLE,new bl.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,Rm.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=Rm.MAX_PROTOTYPE_DEPTH;i++){let s=(0,Rm.inferredGraphForDepth)(i);if((await this.tripleStore.matchInGraph(e,t,r,s)).length>0)return i}return 0}async annotateBySubject(e,t){if(!this.tripleStore.matchInGraph)return e.map(s=>{let o=s.clone();return o.set(pr.SOURCE_VARIABLE,new bl.Literal("own")),o});let r=[],i=new Map;for(let s of e){let o=s.get(t),c=s.clone();if(!o||!(o instanceof iB.IRI))c.set(pr.SOURCE_VARIABLE,new bl.Literal("own"));else{let l=o.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(o,void 0,void 0,Rm.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(pr.SOURCE_VARIABLE,new bl.Literal(u))}r.push(c)}return r}};pr.SourceAnnotator=hb;pr.SourceAnnotator=hb=tB([(0,nB.injectable)(),rB("design:paramtypes",[Object])],hb)});var gb=S(Bi=>{"use strict";var sB=Bi&&Bi.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},oB=Bi&&Bi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},mC=Bi&&Bi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.NoteToRDFConverter=void 0;var mb=fe(),mr=Yn(),zo=Ae(),mn=Ne(),gC=qt(),Kt=lr(),yC=Et(),aB=rb(),cB=Oc(),_C=eb(),Pn=a_(),lB=new Set(["archived","draft","pinned"]),wl=class{static{a(this,"NoteToRDFConverter")}constructor(e,t=cB.NullLogger){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new aB.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[f,d]of Object.entries(t)){let h=lB.has(f)?`exo__Asset_${f}`:f;if(!this.isExocortexProperty(h))continue;let p=this.propertyKeyToIRI(h),y=Array.isArray(d)?d:[d];for(let v of y)if(!(f==="exo__Asset_label"&&typeof v=="string"&&v.trim()===""))if(f==="exo__Instance_class"){let b=this.valueToClassURI(v);r.push(new mr.Triple(i,p,b))}else{let b=await this.valueToRDFObject(v,e,p);for(let w of b)if(r.push(new mr.Triple(i,p,w)),this.vocabularyMapper.hasMappingFor(f)&&w instanceof zo.IRI){let T=this.vocabularyMapper.generateMappedTriple(i,f,w);T&&r.push(T)}}if(f==="exo__Instance_class")for(let v of y){let b=this.valueToClassURI(v);if(b instanceof zo.IRI){let w=Kt.Namespace.RDF.term("type");r.push(new mr.Triple(i,w,b))}}if(f==="exo__Asset_label"){let v=Kt.Namespace.RDFS.term("label");for(let b of y)typeof b=="string"&&b.length>0&&r.push(new mr.Triple(i,v,new mn.Literal(b)))}}let o="exo__Instance_class"in t||"exo__Asset_uid"in t,c=t.exo__Asset_label,l="exo__Asset_label"in t&&c!==null&&c!==void 0&&!(typeof c=="string"&&c.trim()==="")&&!(Array.isArray(c)&&c.length===0);if(o&&!l){let f=Kt.Namespace.RDFS.term("label"),d=Kt.Namespace.EXO.term("Asset_label"),h=new mn.Literal(e.basename);r.push(new mr.Triple(i,f,h)),r.push(new mr.Triple(i,d,h))}r.push(...this.pendingExtraTriples),this.pendingExtraTriples=[];let u=await this.convertBodyWikilinks(e,i);return r.push(...u),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 zo.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 gC.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Pn.Exo003Parser.toTriple(t,i);r.push(s);let o=this.notePathToIRI(e.path);r.push(new mr.Triple(o,Kt.Namespace.RDF.term("value"),s.subject))}catch{}return r}async convertExo003Body(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.createExo003ReferenceResolver(e),c=o(t.subject),l=o(t.predicate);if(c.type==="literal")throw new Error("Body subject cannot be a literal");if(l.type!=="iri")throw new Error("Body predicate must be an IRI");let u=c.type==="iri"?new zo.IRI(c.value):new gC.BlankNode(c.value),f=new zo.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 o=this.vault.getFrontmatter(s);if(o&&Pn.Exo003Parser.isExo003Format(o)){let c=Pn.Exo003Parser.parse(o);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 o of t)try{let c=this.vault.getFrontmatter(o),l=c?this.validateExocortexAsset(c,o.basename):null;if(l){if(s)throw new Error(`Invariant violation in "${o.path}": ${l.message}`);i.push({path:o.path,reason:`Invariant violation: ${l.message}`}),this.logger.warn(`Skipping file with invariant violation: ${o.path}`,{code:l.code,property:l.property,reason:l.message});continue}let u=await this.convertNote(o);r.push(...u)}catch(c){let l=c instanceof Error?c.message:String(c);if(s)throw new Error(`Invalid IRI for file "${o.path}": ${l}`);i.push({path:o.path,reason:`Invalid IRI: ${l}`}),this.logger.warn(`Skipping file with invalid IRI: ${o.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=a(u=>u==null?!0:typeof u=="string"?u.trim()==="":Array.isArray(u)?u.length===0||u.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=["exo__Asset_uid","exo__Asset_isDefinedBy","exo__Instance_class"];for(let u of s){if(!(u in e))return{code:"MISSING_PROPERTY",property:u,message:`Required property "${u}" is missing`};if(r(e[u]))return{code:"EMPTY_PROPERTY",property:u,message:`Required property "${u}" is empty`}}let o=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let u of o)if(u in e&&r(e[u]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:u,message:`Optional property "${u}" is present but empty`};let c=e.exo__Instance_class,l=Array.isArray(c)?c:[c];for(let u of l){if(typeof u!="string")continue;let f=this.removeQuotes(u),h=(this.extractWikilink(f)??f).trim();if(/^[a-z][a-zA-Z0-9]*__/.test(h)&&/[\s()]/.test(h))return{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${u}"`}}return null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,_C.vaultPathToIRI)(r.path);zo.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 zo.IRI((0,_C.vaultPathToIRI)(e))}isExocortexProperty(e){return Kt.Namespace.fromPropertyKey(e)!==null}propertyKeyToIRI(e){let t=Kt.Namespace.fromPropertyKey(e);if(!t)throw new Error(`Invalid property key: ${e}`);return t.namespace.term(t.localName)}emitTypeTripleForEnumInstance(e,t){let r=this.vault.getFrontmatter(t);if(!r)return;let i=r.exo__Instance_class,s=Array.isArray(i)?i[0]:i;if(typeof s!="string")return;let o=this.valueToClassURI(s);o instanceof zo.IRI&&(this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.RDF.term("type"),o)),this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),o)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let o=this.vault.getFirstLinkpathDest(s,t.path);if(o){let l=this.notePathToIRI(o.path),u=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(u)){let d=new mn.Literal(u),h=this.expandClassValue(o.basename);if(h)return this.emitTypeTripleForEnumInstance(h,o),[h];let p=this.vault.getFrontmatter(o);if(p){let v=p.exo__Asset_label;if(typeof v=="string"){let b=this.expandClassValue(v);if(b)return this.emitTypeTripleForEnumInstance(b,o),[b]}}return r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype")?[l,d]:[l]}let f=this.expandClassValue(o.basename);return f?(this.emitTypeTripleForEnumInstance(f,o),[f]):[l]}if(this.isClassReference(s)){let l=this.expandClassValue(s);if(l)return[l]}let c=s.includes("|")?s.split("|")[0]:s;return this.isUUID(c)?[this.notePathToIRI(`${c}.md`)]:[new mn.Literal(i)]}if(this.isClassReference(i)){let o=this.expandClassValue(i);if(o)return[o]}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 o=this.extractWikilinkAlias(t);if(o){let c=this.expandClassValue(o);if(c)return c}if(this.isUUID(i)){let c=this.vault.getFirstLinkpathDest(i,"");if(c){let l=this.expandClassValue(c.basename);if(l)return l;let u=this.vault.getFrontmatter(c);if(u){let f=u.exo__Asset_label;if(typeof f=="string"){let d=this.expandClassValue(f);if(d)return d}}}}return 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),o=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of o){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new 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=wl;wl.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};wl.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};wl.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};Bi.NoteToRDFConverter=wl=sB([(0,mb.injectable)(),mC(0,(0,mb.inject)(yC.DI_TOKENS.IVaultAdapter)),mC(1,(0,mb.inject)(yC.DI_TOKENS.ILogger)),oB("design:paramtypes",[Object,Object])],wl)});var _b=S(Im=>{"use strict";Object.defineProperty(Im,"__esModule",{value:!0});Im.FilterContainsOptimizer=void 0;var uB=Ae(),fB=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,yb=class{static{a(this,"FilterContainsOptimizer")}constructor(){this.tripleStore=null,this.lastOptimizationHints=[]}setTripleStore(e){this.tripleStore=e}getLastOptimizationHints(){return this.lastOptimizationHints}clearHints(){this.lastOptimizationHints=[]}async optimize(e){return this.clearHints(),this.optimizeRecursive(e)}optimizeSync(e,t){return this.clearHints(),this.optimizeSyncRecursive(e,t)}async optimizeRecursive(e){return e.type==="filter"?this.optimizeFilter(e):e.type==="join"?{type:"join",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="leftjoin"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="union"?{type:"union",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="minus"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="project"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="orderby"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="slice"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="distinct"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="reduced"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="group"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="extend"?{...e,input:await this.optimizeRecursive(e.input)}:e}optimizeSyncRecursive(e,t){return e.type==="filter"?this.optimizeFilterSync(e,t):e.type==="join"?{type:"join",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="leftjoin"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="union"?{type:"union",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="minus"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="project"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="orderby"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="slice"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="distinct"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="reduced"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="group"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="extend"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e}async optimizeFilter(e){let t=this.detectContainsUUIDPattern(e.expression);if(!t)return{type:"filter",expression:e.expression,input:await this.optimizeRecursive(e.input)};let r=[];return this.tripleStore&&(r=await this.findSubjectsContainingUUID(t.uuid)),this.rewriteFilter(e,t,r)}optimizeFilterSync(e,t){let r=this.detectContainsUUIDPattern(e.expression);if(!r)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input,t)};let i=t?t.filter(s=>s.includes(r.uuid)):[];return this.rewriteFilter(e,r,i)}rewriteFilter(e,t,r){if(this.lastOptimizationHints.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${t.variable}), "${t.uuid}"))`,suggestedRewrite:r.length===1?`VALUES ?${t.variable} { <${r[0]}> }`:r.length>1?`VALUES ?${t.variable} { ${r.map(i=>`<${i}>`).join(" ")} }`:"No matching URIs found for UUID",estimatedSpeedup:r.length>0?"O(n) \u2192 O(1)":"N/A",matchedUri:r.length===1?r[0]:void 0}),r.length===0)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input)};if(r.length===1){let i=this.injectSubjectConstraint(e.input,t.variable,r[0]);if(i!==e.input)return i}return this.createValuesJoin(e,t,r)}detectContainsUUIDPattern(e){if(e.type==="function"||e.type==="functionCall"){let t=e;if((typeof t.function=="string"?t.function.toLowerCase():t.function?.value?.toLowerCase()??"")==="contains"&&t.args.length===2)return this.analyzeContainsArgs(t.args[0],t.args[1],e)}if(e.type==="logical"&&e.operator==="&&")for(let t of e.operands){let r=this.detectContainsUUIDPattern(t);if(r)return r}return null}analyzeContainsArgs(e,t,r){let i=null;if(e.type==="function"||e.type==="functionCall"){let s=e;if((typeof s.function=="string"?s.function.toLowerCase():s.function?.value?.toLowerCase()??"")==="str"&&s.args.length===1){let c=s.args[0];c.type==="variable"&&(i=c.name)}}if(!i&&e.type==="variable"&&(i=e.name),!i)return null;if(t.type==="literal"){let c=String(t.value).match(fB);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 uB.IRI&&i.value.toLowerCase().includes(e.toLowerCase())&&r.push(i.value);return r}injectSubjectConstraint(e,t,r){if(e.type==="bgp"){let i=e.triples.map(o=>o.subject.type==="variable"&&o.subject.value===t?{...o,subject:{type:"iri",value:r}}:o);if(i.some((o,c)=>o.subject!==e.triples[c].subject))return{type:"bgp",triples:i}}if(e.type==="join"){let i=this.injectSubjectConstraint(e.left,t,r),s=this.injectSubjectConstraint(e.right,t,r);if(i!==e.left||s!==e.right)return{type:"join",left:i,right:s}}if(e.type==="filter"){let i=this.injectSubjectConstraint(e.input,t,r);if(i!==e.input)return{...e,input:i}}return e}createValuesJoin(e,t,r){return{type:"join",left:{type:"values",variables:[t.variable],bindings:r.map(o=>({[t.variable]:{type:"iri",value:o}}))},right:this.optimizeSyncRecursive(e.input)}}analyzeQuery(e){let t=[];return this.analyzeRecursive(e,t),t}analyzeRecursive(e,t){if(e.type==="filter"){let r=this.detectContainsUUIDPattern(e.expression);r&&t.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${r.variable}), "${r.uuid}"))`,suggestedRewrite:`Use --optimize flag or rewrite as VALUES ?${r.variable} { <uri-containing-uuid> }`,estimatedSpeedup:"O(n) \u2192 O(1) with UUID index lookup"}),this.analyzeRecursive(e.input,t);return}e.type==="join"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="leftjoin"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="union"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="minus"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="project"?this.analyzeRecursive(e.input,t):e.type==="orderby"?this.analyzeRecursive(e.input,t):e.type==="slice"?this.analyzeRecursive(e.input,t):e.type==="distinct"?this.analyzeRecursive(e.input,t):e.type==="reduced"?this.analyzeRecursive(e.input,t):e.type==="group"?this.analyzeRecursive(e.input,t):e.type==="extend"&&this.analyzeRecursive(e.input,t)}};Im.FilterContainsOptimizer=yb});var SC=S(Pm=>{"use strict";Object.defineProperty(Pm,"__esModule",{value:!0});Pm.AlgebraOptimizer=void 0;var dB=_b(),Sb=class{static{a(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new dB.FilterContainsOptimizer}setTripleStore(e){this.tripleStore=e,this.filterContainsOptimizer.setTripleStore(e)}getOptimizationHints(){return this.filterContainsOptimizer.getLastOptimizationHints()}analyzeQuery(e){return this.filterContainsOptimizer.analyzeQuery(e)}optimize(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),t=this.filterPushDown(t),t=this.joinReordering(t),t}async optimizeAsync(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),this.tripleStore&&(t=await this.filterContainsOptimizer.optimize(t)),t=this.filterPushDown(t),t=this.joinReordering(t),t}optimizeWithSubjects(e,t){let r=e;return r=this.eliminateEmptyBGPInFilterJoin(r),r=this.filterContainsOptimizer.optimizeSync(r,t),r=this.filterPushDown(r),r=this.joinReordering(r),r}eliminateEmptyBGPInFilterJoin(e){if(e.type==="join"){if(e.left.type==="filter"){let t=e.left;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.right)}}if(e.right.type==="filter"){let t=e.right;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.left)}}return{type:"join",left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}}return e.type==="filter"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="leftjoin"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="union"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="minus"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="project"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="orderby"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="slice"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="distinct"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e}filterPushDown(e){return e.type==="filter"?this.pushDownFilter(e):e.type==="join"?{type:"join",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="leftjoin"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="union"?{type:"union",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="minus"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="project"?{...e,input:this.filterPushDown(e.input)}:e.type==="orderby"?{...e,input:this.filterPushDown(e.input)}:e.type==="slice"?{...e,input:this.filterPushDown(e.input)}:e.type==="distinct"?{...e,input:this.filterPushDown(e.input)}:e}pushDownFilter(e){let t=e.input;if(t.type==="join"){let r=this.getFilterVariables(e.expression),i=this.getOperationVariables(t.left),s=this.getOperationVariables(t.right),o=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return o&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!o?{type:"join",left:this.filterPushDown(t.left),right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:{type:"join",left:this.filterPushDown(t.left),right:this.filterPushDown(t.right)}}}return t.type==="union"?{type:"union",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:this.filterPushDown(t)}}getFilterVariables(e){let t=[];if(e.type==="variable")t.push(e.name);else if(e.type==="comparison")t.push(...this.getFilterVariables(e.left)),t.push(...this.getFilterVariables(e.right));else if(e.type==="logical")for(let r of e.operands)t.push(...this.getFilterVariables(r));else if(e.type==="function")for(let r of e.args)t.push(...this.getFilterVariables(r));return Array.from(new Set(t))}getOperationVariables(e){let t=new Set;if(e.type==="bgp")for(let r of e.triples)r.subject.type==="variable"&&t.add(r.subject.value),r.predicate.type==="variable"&&t.add(r.predicate.value),r.object.type==="variable"&&t.add(r.object.value);else if(e.type==="join"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="filter")return this.getOperationVariables(e.input);if(e.type==="leftjoin"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else if(e.type==="union"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="minus")return this.getOperationVariables(e.left);if(e.type==="project")return new Set(e.variables)}}return t}joinReordering(e){return e.type==="join"?this.reorderJoin(e):e.type==="filter"?{...e,input:this.joinReordering(e.input)}:e.type==="leftjoin"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="union"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="minus"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="project"?{...e,input:this.joinReordering(e.input)}:e.type==="orderby"?{...e,input:this.joinReordering(e.input)}:e.type==="slice"?{...e,input:this.joinReordering(e.input)}:e.type==="distinct"?{...e,input:this.joinReordering(e.input)}:e}reorderJoin(e){let t=this.isConstrained(e.left),r=this.isConstrained(e.right);if(r&&!t)return{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)};if(t&&!r)return{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)};let i=this.estimateCost(e.left);return this.estimateCost(e.right)<i?{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)}:{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)}}isConstrained(e){return e.type==="values"?!0:e.type==="bgp"?e.triples.some(t=>t.object.type!=="variable"||t.subject.type!=="variable"):e.type==="filter"?this.isConstrained(e.input):e.type==="join"?this.isConstrained(e.left)||this.isConstrained(e.right):e.type==="union"?this.isConstrained(e.left)&&this.isConstrained(e.right):!1}estimateCost(e){if(e.type==="bgp"){let t=0;for(let r of e.triples){let i=10;r.subject.type==="variable"&&(i*=10),r.predicate.type==="variable"&&(i*=20),r.object.type==="variable"&&(i*=5),t+=i}return t}if(e.type==="filter")return this.estimateCost(e.input)*.3;if(e.type==="join"){let t=this.estimateCost(e.left),r=this.estimateCost(e.right);return e.left.type==="values"||e.right.type==="values"?Math.min(t,r)*2:t*r}if(e.type==="leftjoin")return this.estimateCost(e.left)+this.estimateCost(e.right)*.5;if(e.type==="union")return this.estimateCost(e.left)+this.estimateCost(e.right);if(e.type==="values"){let t=e.bindings;return Array.isArray(t)?t.length*5:10}return e.type==="minus"?this.estimateCost(e.left)+this.estimateCost(e.right)*.3:100}setStatistics(e,t){this.stats.set(e,t)}getStatistics(e){return this.stats.get(e)}};Pm.AlgebraOptimizer=Sb});var vC=S(Om=>{"use strict";Object.defineProperty(Om,"__esModule",{value:!0});Om.AlgebraSerializer=void 0;var vb=class{static{a(this,"AlgebraSerializer")}toString(e,t=0){let r=" ".repeat(t);switch(e.type){case"bgp":return`${r}BGP [
|
|
377
|
+
`),t}};Tm.RDFSerializer=Zv});var eb=S(vl=>{"use strict";Object.defineProperty(vl,"__esModule",{value:!0});vl.OBSIDIAN_VAULT_SCHEME=void 0;vl.vaultPathToIRI=q$;vl.OBSIDIAN_VAULT_SCHEME="obsidian://vault/";function q$(n){let e=n.startsWith("./")?n.slice(2):n;return`${vl.OBSIDIAN_VAULT_SCHEME}${encodeURI(e)}`}a(q$,"vaultPathToIRI")});var rb=S(Am=>{"use strict";Object.defineProperty(Am,"__esModule",{value:!0});Am.RDFVocabularyMapper=void 0;var rr=Yn(),cC=Ae(),J=lr(),tb=class{static{a(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 rr.Triple(J.Namespace.EXO.term("Asset"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Resource"))),e.push(new rr.Triple(J.Namespace.EXO.term("Class"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDFS.term("Class"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.RDF.term("Property"))),e.push(new rr.Triple(J.Namespace.EMS.term("Task"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Project"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Area"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("Workflow"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("WorkflowState"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EMS.term("WorkflowTransition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Command"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Precondition"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("Grounding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e.push(new rr.Triple(J.Namespace.EXOCMD.term("CommandBinding"),J.Namespace.RDFS.term("subClassOf"),J.Namespace.EXO.term("Asset"))),e}generatePropertyHierarchyTriples(){let e=[];return e.push(new rr.Triple(J.Namespace.EXO.term("Instance_class"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDF.term("type"))),e.push(new rr.Triple(J.Namespace.EXO.term("Asset_isDefinedBy"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("isDefinedBy"))),e.push(new rr.Triple(J.Namespace.EXO.term("Class_superClass"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("subClassOf"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property_range"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("range"))),e.push(new rr.Triple(J.Namespace.EXO.term("Property_domain"),J.Namespace.RDFS.term("subPropertyOf"),J.Namespace.RDFS.term("domain"))),e.push(new rr.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 cC.IRI)s=r;else{let o=r.match(/^(ems|exo|exocmd)__(.+)$/);if(o){let[,c,l]=o;s=(c==="ems"?J.Namespace.EMS:c==="exocmd"?J.Namespace.EXOCMD:J.Namespace.EXO).term(l)}else s=new cC.IRI(r)}return new rr.Triple(e,i,s)}hasMappingFor(e){return this.propertyMappings.has(e)}};Am.RDFVocabularyMapper=tb});var lC=S(Cm=>{"use strict";Object.defineProperty(Cm,"__esModule",{value:!0});Cm.RDFSInferenceEngine=void 0;var W$=Yn(),xm=Ae(),nb=class{static{a(this,"RDFSInferenceEngine")}async materialize(e){let t=await e.predicates(),r=t.find(d=>d.value.includes("Class_superClass")),i=t.find(d=>d.value.includes("Instance_class"));if(!r||!i)return 0;let s=await this.buildDirectParentMap(e,r);if(s.size===0)return 0;let o=this.computeAllAncestors(s),c=await e.count(),l=await e.match(void 0,i),u=[];for(let d of l)if(d.object instanceof xm.IRI){let h=o.get(d.object.value);if(h)for(let p of h)u.push(new W$.Triple(d.subject,i,new xm.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 xm.IRI&&s.object instanceof xm.IRI){let o=s.subject.value,c=s.object.value;i.has(o)||i.set(o,new Set),i.get(o).add(c)}return i}computeAllAncestors(e){let t=new Map;for(let r of e.keys())t.has(r)||t.set(r,this.computeAncestorsBFS(r,e));return t}computeAncestorsBFS(e,t){let r=new Set,i=new Set,s=[],o=t.get(e);if(o)for(let c of o)s.push(c);for(;s.length>0;){let c=s.shift();if(i.has(c))continue;i.add(c),r.add(c);let l=t.get(c);if(l)for(let u of l)i.has(u)||s.push(u)}return r}};Cm.RDFSInferenceEngine=nb});var ob=S(Ka=>{"use strict";var G$=Ka&&Ka.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ka,"__esModule",{value:!0});Ka.NonInheritablePropertyRegistry=void 0;var z$=fe(),uC=Ae(),fC=Ne(),ib=lr(),sb=class{static{a(this,"NonInheritablePropertyRegistry")}constructor(){this.nonInheritableIRIs=new Set,this.initialized=!1}async initialize(e){this.nonInheritableIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Instance_class"));if(!r){this.initialized=!0;return}let i=await this.findNonInheritableClassIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof fC.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.nonInheritableIRIs.add(d)}}}catch{}this.initialized=!0}isNonInheritable(e){return this.nonInheritableIRIs.has(e)}get size(){return this.nonInheritableIRIs.size}get isInitialized(){return this.initialized}async findNonInheritableClassIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new fC.Literal("exo__NonInheritableProperty"));if(i.length>0&&i[0].subject instanceof uC.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof uC.IRI&&c.object.value.includes("NonInheritableProperty"))return c.object}return null}propertyKeyToIRI(e){return e.startsWith("exo__")?ib.Namespace.EXO.term(e.substring(5)).value:e.startsWith("ems__")?ib.Namespace.EMS.term(e.substring(5)).value:e.startsWith("exocmd__")?ib.Namespace.EXOCMD.term(e.substring(8)).value:null}};Ka.NonInheritablePropertyRegistry=sb;Ka.NonInheritablePropertyRegistry=sb=G$([(0,z$.injectable)()],sb)});var lb=S(Ya=>{"use strict";var H$=Ya&&Ya.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s};Object.defineProperty(Ya,"__esModule",{value:!0});Ya.PropertyCardinalityRegistry=void 0;var Q$=fe(),dC=Ae(),hC=Ne(),ab=lr(),cb=class{static{a(this,"PropertyCardinalityRegistry")}constructor(){this.multiValuedIRIs=new Set,this.initialized=!1}async initialize(e){this.multiValuedIRIs.clear();try{let t=await e.predicates(),r=t.find(c=>c.value.includes("Property_cardinality"));if(!r){this.initialized=!0;return}let i=await this.findMultipleCardinalityIRI(e,t);if(!i){this.initialized=!0;return}let s=await e.match(void 0,r,i);if(s.length===0){this.initialized=!0;return}let o=t.find(c=>c.value.includes("Asset_label"));if(!o){this.initialized=!0;return}for(let c of s){let l=await e.match(c.subject,o,void 0);for(let u of l)if(u.object instanceof hC.Literal){let f=u.object.value,d=this.propertyKeyToIRI(f);d&&this.multiValuedIRIs.add(d)}}}catch{}this.initialized=!0}isMultiValued(e){return this.multiValuedIRIs.has(e)}get size(){return this.multiValuedIRIs.size}get isInitialized(){return this.initialized}async findMultipleCardinalityIRI(e,t){let r=t.find(o=>o.value.includes("Asset_label"));if(!r)return null;let i=await e.match(void 0,r,new hC.Literal("exo__PropertyCardinalityMultiple"));if(i.length>0&&i[0].subject instanceof dC.IRI)return i[0].subject;let s=t.find(o=>o.value.includes("Instance_class"));if(s){let o=await e.match(void 0,s,void 0);for(let c of o)if(c.object instanceof dC.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}};Ya.PropertyCardinalityRegistry=cb;Ya.PropertyCardinalityRegistry=cb=H$([(0,Q$.injectable)()],cb)});var db=S(br=>{"use strict";var K$=br&&br.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},Y$=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=ub;var X$=fe(),pC=Yn(),Go=Ae(),J$=ob(),Z$=lb();br.INFERRED_GRAPH=new Go.IRI("https://exocortex.my/ontology/exo#inferred");var eB="https://exocortex.my/ontology/exo#inferred/";function ub(n){return new Go.IRI(`${eB}${n}`)}a(ub,"inferredGraphForDepth");br.MAX_PROTOTYPE_DEPTH=10;var fb=class{static{a(this,"PrototypeChainMaterializer")}constructor(e,t){this.registry=e,this.cardinalityRegistry=t??null}async materialize(e){let r=(await e.predicates()).find(c=>c.value.includes("Asset_prototype"));if(!r)return 0;let i=await e.match(void 0,r,void 0);if(i.length===0)return 0;let s=new Map;for(let c of i)if(c.subject instanceof Go.IRI&&c.object instanceof Go.IRI){let l=c.subject.value,u=c.object.value;l!==u&&s.set(l,c.object)}if(s.size===0)return 0;let o=0;for(let[c]of s){let l=new Go.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 Go.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,b=new Go.IRI(y),w=await e.match(b,void 0,void 0),T=new Set;if(e.matchInGraph){let I=await e.matchInGraph(b,void 0,void 0,br.INFERRED_GRAPH);for(let $ of I)T.add($.predicate.value)}for(let I of w){let $=I.predicate.value;if(this.registry.isNonInheritable($)||T.has($))continue;if(d.has($)&&this.isMultiValued($)){let ce=I.object instanceof Go.IRI?I.object.value:String(I.object);if(h.get($)?.has(ce))continue;let V=h.get($);V||(V=new Set,h.set($,V)),V.add(ce);let F=new pC.Triple(l,I.predicate,I.object);await e.add(F),e.addToGraph&&(await e.addToGraph(F,br.INFERRED_GRAPH),await e.addToGraph(F,ub(v))),o++;continue}if(d.has($))continue;let q=new pC.Triple(l,I.predicate,I.object);await e.add(q),e.addToGraph&&(await e.addToGraph(q,br.INFERRED_GRAPH),await e.addToGraph(q,ub(v))),d.add($),o++}}}return o}isMultiValued(e){return this.cardinalityRegistry?this.cardinalityRegistry.isMultiValued(e):!1}resolveChain(e,t){let r=[],i=new Set;i.add(e);let s=[],o=t.get(e);for(o&&s.push(o.value);s.length>0&&r.length<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=fb;br.PrototypeChainMaterializer=fb=K$([(0,X$.injectable)(),Y$("design:paramtypes",[J$.NonInheritablePropertyRegistry,Z$.PropertyCardinalityRegistry])],fb)});var pb=S(pr=>{"use strict";var tB=pr&&pr.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},rB=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 nB=fe(),bl=Ne(),iB=Ae(),Rm=db();pr.SOURCE_VARIABLE="_source";pr.DEPTH_VARIABLE="_depth";var hb=class{static{a(this,"SourceAnnotator")}constructor(e){this.tripleStore=e}async annotate(e,t,r,i){if(!this.tripleStore.matchInGraph)return e.map(o=>{let c=o.clone();return c.set(pr.SOURCE_VARIABLE,new bl.Literal("own")),c});let s=[];for(let o of e){let c=o.get(t),l=o.get(r),u=o.get(i),f=o.clone();if(!c||!l||!u)f.set(pr.SOURCE_VARIABLE,new bl.Literal("own"));else{let d=await this.determineSource(c,l,u);f.set(pr.SOURCE_VARIABLE,new bl.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,Rm.INFERRED_GRAPH)).length>0?"inherited":"own"}async getInheritanceDepth(e,t,r){if(!this.tripleStore.matchInGraph)return 0;for(let i=1;i<=Rm.MAX_PROTOTYPE_DEPTH;i++){let s=(0,Rm.inferredGraphForDepth)(i);if((await this.tripleStore.matchInGraph(e,t,r,s)).length>0)return i}return 0}async annotateBySubject(e,t){if(!this.tripleStore.matchInGraph)return e.map(s=>{let o=s.clone();return o.set(pr.SOURCE_VARIABLE,new bl.Literal("own")),o});let r=[],i=new Map;for(let s of e){let o=s.get(t),c=s.clone();if(!o||!(o instanceof iB.IRI))c.set(pr.SOURCE_VARIABLE,new bl.Literal("own"));else{let l=o.value;if(!i.has(l)){let f=await this.tripleStore.matchInGraph(o,void 0,void 0,Rm.INFERRED_GRAPH);i.set(l,f.length>0?"inherited":"own")}let u=i.get(l)??"own";c.set(pr.SOURCE_VARIABLE,new bl.Literal(u))}r.push(c)}return r}};pr.SourceAnnotator=hb;pr.SourceAnnotator=hb=tB([(0,nB.injectable)(),rB("design:paramtypes",[Object])],hb)});var gb=S(Bi=>{"use strict";var sB=Bi&&Bi.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},oB=Bi&&Bi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},mC=Bi&&Bi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Bi,"__esModule",{value:!0});Bi.NoteToRDFConverter=void 0;var mb=fe(),mr=Yn(),zo=Ae(),mn=Ne(),gC=qt(),Kt=lr(),yC=Et(),aB=rb(),cB=Oc(),_C=eb(),Pn=a_(),lB=new Set(["archived","draft","pinned"]),wl=class{static{a(this,"NoteToRDFConverter")}constructor(e,t=cB.NullLogger){this.vault=e,this.logger=t,this.BODY_WIKILINK_PATTERN=/(?<!!)\[\[([^\]|]+)(?:\|[^\]]+)?\]\]/g,this.pendingExtraTriples=[],this.vocabularyMapper=new aB.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[f,d]of Object.entries(t)){let h=lB.has(f)?`exo__Asset_${f}`:f;if(!this.isExocortexProperty(h))continue;let p=this.propertyKeyToIRI(h),y=Array.isArray(d)?d:[d];for(let v of y)if(!(f==="exo__Asset_label"&&typeof v=="string"&&v.trim()===""))if(f==="exo__Instance_class"){let b=this.valueToClassURI(v);r.push(new mr.Triple(i,p,b))}else{let b=await this.valueToRDFObject(v,e,p);for(let w of b)if(r.push(new mr.Triple(i,p,w)),this.vocabularyMapper.hasMappingFor(f)&&w instanceof zo.IRI){let T=this.vocabularyMapper.generateMappedTriple(i,f,w);T&&r.push(T)}}if(f==="exo__Instance_class")for(let v of y){let b=this.valueToClassURI(v);if(b instanceof zo.IRI){let w=Kt.Namespace.RDF.term("type");r.push(new mr.Triple(i,w,b))}}if(f==="exo__Asset_label"){let v=Kt.Namespace.RDFS.term("label");for(let b of y)typeof b=="string"&&b.length>0&&r.push(new mr.Triple(i,v,new mn.Literal(b)))}}let o="exo__Instance_class"in t||"exo__Asset_uid"in t,c=t.exo__Asset_label,l="exo__Asset_label"in t&&c!==null&&c!==void 0&&!(typeof c=="string"&&c.trim()==="")&&!(Array.isArray(c)&&c.length===0);if(o&&!l){let f=Kt.Namespace.RDFS.term("label"),d=Kt.Namespace.EXO.term("Asset_label"),h=new mn.Literal(e.basename);r.push(new mr.Triple(i,f,h)),r.push(new mr.Triple(i,d,h))}r.push(...this.pendingExtraTriples),this.pendingExtraTriples=[];let u=await this.convertBodyWikilinks(e,i);return r.push(...u),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 zo.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 gC.BlankNode(i))]}convertExo003Statement(e,t){let r=[];try{let i=this.createExo003ReferenceResolver(e),s=Pn.Exo003Parser.toTriple(t,i);r.push(s);let o=this.notePathToIRI(e.path);r.push(new mr.Triple(o,Kt.Namespace.RDF.term("value"),s.subject))}catch{}return r}async convertExo003Body(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.createExo003ReferenceResolver(e),c=o(t.subject),l=o(t.predicate);if(c.type==="literal")throw new Error("Body subject cannot be a literal");if(l.type!=="iri")throw new Error("Body predicate must be an IRI");let u=c.type==="iri"?new zo.IRI(c.value):new gC.BlankNode(c.value),f=new zo.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 o=this.vault.getFrontmatter(s);if(o&&Pn.Exo003Parser.isExo003Format(o)){let c=Pn.Exo003Parser.parse(o);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 o of t)try{let c=this.vault.getFrontmatter(o),l=c?this.validateExocortexAsset(c,o.basename):null;if(l){if(s)throw new Error(`Invariant violation in "${o.path}": ${l.message}`);i.push({path:o.path,reason:`Invariant violation: ${l.message}`}),this.logger.warn(`Skipping file with invariant violation: ${o.path}`,{code:l.code,property:l.property,reason:l.message});continue}let u=await this.convertNote(o);r.push(...u)}catch(c){let l=c instanceof Error?c.message:String(c);if(s)throw new Error(`Invalid IRI for file "${o.path}": ${l}`);i.push({path:o.path,reason:`Invalid IRI: ${l}`}),this.logger.warn(`Skipping file with invalid IRI: ${o.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=a(d=>d==null?!0:typeof d=="string"?d.trim()==="":Array.isArray(d)?d.length===0||d.every(r):!1,"isEmpty");if(!("exo__Instance_class"in e||"exo__Asset_uid"in e))return null;let s=["exo__Asset_uid","exo__Asset_isDefinedBy","exo__Instance_class"];for(let d of s){if(!(d in e))return{code:"MISSING_PROPERTY",property:d,message:`Required property "${d}" is missing`};if(r(e[d]))return{code:"EMPTY_PROPERTY",property:d,message:`Required property "${d}" is empty`}}let o=["ems__Effort_status","ems__Effort_parent","ems__Effort_lockedBy","ems__Effort_lockExpires","exo__Asset_updatedAt","ems__Effort_startTimestamp"];for(let d of o)if(d in e&&r(e[d]))return{code:"EMPTY_OPTIONAL_PROPERTY",property:d,message:`Optional property "${d}" is present but empty`};let c=e.exo__Instance_class,l=Array.isArray(c)?c:[c],u=null,f=!1;for(let d of l){if(typeof d!="string")continue;let h=this.removeQuotes(d),y=(this.extractWikilink(h)??h).trim();/^[a-z][a-zA-Z0-9]*__/.test(y)&&/[\s()]/.test(y)?u||(u={candidate:d}):f=!0}return u&&!f?{code:"INVALID_INSTANCE_CLASS_IRI",property:"exo__Instance_class",message:`Invalid Instance_class IRI: "${u.candidate}"`}:null}async validateVault(){let e=this.vault.getAllFiles(),t=[];for(let r of e){let i=(0,_C.vaultPathToIRI)(r.path);zo.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 zo.IRI((0,_C.vaultPathToIRI)(e))}isExocortexProperty(e){return Kt.Namespace.fromPropertyKey(e)!==null}propertyKeyToIRI(e){let t=Kt.Namespace.fromPropertyKey(e);if(!t)throw new Error(`Invalid property key: ${e}`);return t.namespace.term(t.localName)}emitTypeTripleForEnumInstance(e,t){let r=this.vault.getFrontmatter(t);if(!r)return;let i=r.exo__Instance_class,s=Array.isArray(i)?i[0]:i;if(typeof s!="string")return;let o=this.valueToClassURI(s);o instanceof zo.IRI&&(this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.RDF.term("type"),o)),this.pendingExtraTriples.push(new mr.Triple(e,Kt.Namespace.EXO.term("Instance_class"),o)))}async valueToRDFObject(e,t,r){if(typeof e=="string"){let i=this.removeQuotes(e),s=this.extractWikilink(i);if(s){let o=this.vault.getFirstLinkpathDest(s,t.path);if(o){let l=this.notePathToIRI(o.path),u=s.includes("|")?s.split("|")[0]:s;if(this.isUUID(u)){let d=new mn.Literal(u),h=this.expandClassValue(o.basename);if(h)return this.emitTypeTripleForEnumInstance(h,o),[h];let p=this.vault.getFrontmatter(o);if(p){let v=p.exo__Asset_label;if(typeof v=="string"){let b=this.expandClassValue(v);if(b)return this.emitTypeTripleForEnumInstance(b,o),[b]}}return r?.value.endsWith("#Asset_prototype")||r?.value.endsWith("/Asset_prototype")?[l,d]:[l]}let f=this.expandClassValue(o.basename);return f?(this.emitTypeTripleForEnumInstance(f,o),[f]):[l]}if(this.isClassReference(s)){let l=this.expandClassValue(s);if(l)return[l]}let c=s.includes("|")?s.split("|")[0]:s;return this.isUUID(c)?[this.notePathToIRI(`${c}.md`)]:[new mn.Literal(i)]}if(this.isClassReference(i)){let o=this.expandClassValue(i);if(o)return[o]}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 o=this.extractWikilinkAlias(t);if(o){let c=this.expandClassValue(o);if(c)return c}if(this.isUUID(i)){let c=this.vault.getFirstLinkpathDest(i,"");if(c){let l=this.expandClassValue(c.basename);if(l)return l;let u=this.vault.getFrontmatter(c);if(u){let f=u.exo__Asset_label;if(typeof f=="string"){let d=this.expandClassValue(f);if(d)return d}}}}return 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||/[\s()]/.test(r.localName)?null:r.namespace.term(r.localName)}extractBodyContent(e){let t=/^---\r?\n[\s\S]*?\r?\n---\r?\n?/;return e.replace(t,"")}extractBodyWikilinks(e){let t=new Set,r,i=new RegExp(this.BODY_WIKILINK_PATTERN.source,"g");for(;(r=i.exec(e))!==null;)r[1]&&t.add(r[1]);return Array.from(t)}async convertBodyWikilinks(e,t){let r=[];try{let i=await this.vault.read(e),s=this.extractBodyContent(i),o=this.extractBodyWikilinks(s),c=Kt.Namespace.EXO.term("Asset_bodyLink");for(let l of o){let u=this.vault.getFirstLinkpathDest(l,e.path);if(u){let f=this.notePathToIRI(u.path);r.push(new 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=wl;wl.SkippedFileInfo=class{constructor(n,e){this.path=n,this.reason=e}};wl.VaultValidationResult=class{constructor(n,e,t){this.triples=n,this.skippedFiles=e,this.summary=t}};wl.VaultValidationOptions=class{constructor(n=!1){this.strict=n}};Bi.NoteToRDFConverter=wl=sB([(0,mb.injectable)(),mC(0,(0,mb.inject)(yC.DI_TOKENS.IVaultAdapter)),mC(1,(0,mb.inject)(yC.DI_TOKENS.ILogger)),oB("design:paramtypes",[Object,Object])],wl)});var _b=S(Im=>{"use strict";Object.defineProperty(Im,"__esModule",{value:!0});Im.FilterContainsOptimizer=void 0;var uB=Ae(),fB=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,yb=class{static{a(this,"FilterContainsOptimizer")}constructor(){this.tripleStore=null,this.lastOptimizationHints=[]}setTripleStore(e){this.tripleStore=e}getLastOptimizationHints(){return this.lastOptimizationHints}clearHints(){this.lastOptimizationHints=[]}async optimize(e){return this.clearHints(),this.optimizeRecursive(e)}optimizeSync(e,t){return this.clearHints(),this.optimizeSyncRecursive(e,t)}async optimizeRecursive(e){return e.type==="filter"?this.optimizeFilter(e):e.type==="join"?{type:"join",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="leftjoin"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="union"?{type:"union",left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="minus"?{...e,left:await this.optimizeRecursive(e.left),right:await this.optimizeRecursive(e.right)}:e.type==="project"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="orderby"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="slice"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="distinct"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="reduced"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="group"?{...e,input:await this.optimizeRecursive(e.input)}:e.type==="extend"?{...e,input:await this.optimizeRecursive(e.input)}:e}optimizeSyncRecursive(e,t){return e.type==="filter"?this.optimizeFilterSync(e,t):e.type==="join"?{type:"join",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="leftjoin"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="union"?{type:"union",left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="minus"?{...e,left:this.optimizeSyncRecursive(e.left,t),right:this.optimizeSyncRecursive(e.right,t)}:e.type==="project"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="orderby"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="slice"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="distinct"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="reduced"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="group"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e.type==="extend"?{...e,input:this.optimizeSyncRecursive(e.input,t)}:e}async optimizeFilter(e){let t=this.detectContainsUUIDPattern(e.expression);if(!t)return{type:"filter",expression:e.expression,input:await this.optimizeRecursive(e.input)};let r=[];return this.tripleStore&&(r=await this.findSubjectsContainingUUID(t.uuid)),this.rewriteFilter(e,t,r)}optimizeFilterSync(e,t){let r=this.detectContainsUUIDPattern(e.expression);if(!r)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input,t)};let i=t?t.filter(s=>s.includes(r.uuid)):[];return this.rewriteFilter(e,r,i)}rewriteFilter(e,t,r){if(this.lastOptimizationHints.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${t.variable}), "${t.uuid}"))`,suggestedRewrite:r.length===1?`VALUES ?${t.variable} { <${r[0]}> }`:r.length>1?`VALUES ?${t.variable} { ${r.map(i=>`<${i}>`).join(" ")} }`:"No matching URIs found for UUID",estimatedSpeedup:r.length>0?"O(n) \u2192 O(1)":"N/A",matchedUri:r.length===1?r[0]:void 0}),r.length===0)return{type:"filter",expression:e.expression,input:this.optimizeSyncRecursive(e.input)};if(r.length===1){let i=this.injectSubjectConstraint(e.input,t.variable,r[0]);if(i!==e.input)return i}return this.createValuesJoin(e,t,r)}detectContainsUUIDPattern(e){if(e.type==="function"||e.type==="functionCall"){let t=e;if((typeof t.function=="string"?t.function.toLowerCase():t.function?.value?.toLowerCase()??"")==="contains"&&t.args.length===2)return this.analyzeContainsArgs(t.args[0],t.args[1],e)}if(e.type==="logical"&&e.operator==="&&")for(let t of e.operands){let r=this.detectContainsUUIDPattern(t);if(r)return r}return null}analyzeContainsArgs(e,t,r){let i=null;if(e.type==="function"||e.type==="functionCall"){let s=e;if((typeof s.function=="string"?s.function.toLowerCase():s.function?.value?.toLowerCase()??"")==="str"&&s.args.length===1){let c=s.args[0];c.type==="variable"&&(i=c.name)}}if(!i&&e.type==="variable"&&(i=e.name),!i)return null;if(t.type==="literal"){let c=String(t.value).match(fB);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 uB.IRI&&i.value.toLowerCase().includes(e.toLowerCase())&&r.push(i.value);return r}injectSubjectConstraint(e,t,r){if(e.type==="bgp"){let i=e.triples.map(o=>o.subject.type==="variable"&&o.subject.value===t?{...o,subject:{type:"iri",value:r}}:o);if(i.some((o,c)=>o.subject!==e.triples[c].subject))return{type:"bgp",triples:i}}if(e.type==="join"){let i=this.injectSubjectConstraint(e.left,t,r),s=this.injectSubjectConstraint(e.right,t,r);if(i!==e.left||s!==e.right)return{type:"join",left:i,right:s}}if(e.type==="filter"){let i=this.injectSubjectConstraint(e.input,t,r);if(i!==e.input)return{...e,input:i}}return e}createValuesJoin(e,t,r){return{type:"join",left:{type:"values",variables:[t.variable],bindings:r.map(o=>({[t.variable]:{type:"iri",value:o}}))},right:this.optimizeSyncRecursive(e.input)}}analyzeQuery(e){let t=[];return this.analyzeRecursive(e,t),t}analyzeRecursive(e,t){if(e.type==="filter"){let r=this.detectContainsUUIDPattern(e.expression);r&&t.push({type:"uuid-index-lookup",originalPattern:`FILTER(CONTAINS(STR(?${r.variable}), "${r.uuid}"))`,suggestedRewrite:`Use --optimize flag or rewrite as VALUES ?${r.variable} { <uri-containing-uuid> }`,estimatedSpeedup:"O(n) \u2192 O(1) with UUID index lookup"}),this.analyzeRecursive(e.input,t);return}e.type==="join"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="leftjoin"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="union"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="minus"?(this.analyzeRecursive(e.left,t),this.analyzeRecursive(e.right,t)):e.type==="project"?this.analyzeRecursive(e.input,t):e.type==="orderby"?this.analyzeRecursive(e.input,t):e.type==="slice"?this.analyzeRecursive(e.input,t):e.type==="distinct"?this.analyzeRecursive(e.input,t):e.type==="reduced"?this.analyzeRecursive(e.input,t):e.type==="group"?this.analyzeRecursive(e.input,t):e.type==="extend"&&this.analyzeRecursive(e.input,t)}};Im.FilterContainsOptimizer=yb});var SC=S(Pm=>{"use strict";Object.defineProperty(Pm,"__esModule",{value:!0});Pm.AlgebraOptimizer=void 0;var dB=_b(),Sb=class{static{a(this,"AlgebraOptimizer")}constructor(){this.stats=new Map,this.tripleStore=null,this.filterContainsOptimizer=new dB.FilterContainsOptimizer}setTripleStore(e){this.tripleStore=e,this.filterContainsOptimizer.setTripleStore(e)}getOptimizationHints(){return this.filterContainsOptimizer.getLastOptimizationHints()}analyzeQuery(e){return this.filterContainsOptimizer.analyzeQuery(e)}optimize(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),t=this.filterPushDown(t),t=this.joinReordering(t),t}async optimizeAsync(e){let t=e;return t=this.eliminateEmptyBGPInFilterJoin(t),this.tripleStore&&(t=await this.filterContainsOptimizer.optimize(t)),t=this.filterPushDown(t),t=this.joinReordering(t),t}optimizeWithSubjects(e,t){let r=e;return r=this.eliminateEmptyBGPInFilterJoin(r),r=this.filterContainsOptimizer.optimizeSync(r,t),r=this.filterPushDown(r),r=this.joinReordering(r),r}eliminateEmptyBGPInFilterJoin(e){if(e.type==="join"){if(e.left.type==="filter"){let t=e.left;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.right)}}if(e.right.type==="filter"){let t=e.right;if(t.input.type==="bgp"&&t.input.triples.length===0)return{type:"filter",expression:t.expression,input:this.eliminateEmptyBGPInFilterJoin(e.left)}}return{type:"join",left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}}return e.type==="filter"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="leftjoin"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="union"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="minus"?{...e,left:this.eliminateEmptyBGPInFilterJoin(e.left),right:this.eliminateEmptyBGPInFilterJoin(e.right)}:e.type==="project"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="orderby"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="slice"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e.type==="distinct"?{...e,input:this.eliminateEmptyBGPInFilterJoin(e.input)}:e}filterPushDown(e){return e.type==="filter"?this.pushDownFilter(e):e.type==="join"?{type:"join",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="leftjoin"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="union"?{type:"union",left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="minus"?{...e,left:this.filterPushDown(e.left),right:this.filterPushDown(e.right)}:e.type==="project"?{...e,input:this.filterPushDown(e.input)}:e.type==="orderby"?{...e,input:this.filterPushDown(e.input)}:e.type==="slice"?{...e,input:this.filterPushDown(e.input)}:e.type==="distinct"?{...e,input:this.filterPushDown(e.input)}:e}pushDownFilter(e){let t=e.input;if(t.type==="join"){let r=this.getFilterVariables(e.expression),i=this.getOperationVariables(t.left),s=this.getOperationVariables(t.right),o=r.every(l=>i.has(l)),c=r.every(l=>s.has(l));return o&&!c?{type:"join",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:this.filterPushDown(t.right)}:c&&!o?{type:"join",left:this.filterPushDown(t.left),right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:{type:"join",left:this.filterPushDown(t.left),right:this.filterPushDown(t.right)}}}return t.type==="union"?{type:"union",left:{type:"filter",expression:e.expression,input:this.filterPushDown(t.left)},right:{type:"filter",expression:e.expression,input:this.filterPushDown(t.right)}}:{type:"filter",expression:e.expression,input:this.filterPushDown(t)}}getFilterVariables(e){let t=[];if(e.type==="variable")t.push(e.name);else if(e.type==="comparison")t.push(...this.getFilterVariables(e.left)),t.push(...this.getFilterVariables(e.right));else if(e.type==="logical")for(let r of e.operands)t.push(...this.getFilterVariables(r));else if(e.type==="function")for(let r of e.args)t.push(...this.getFilterVariables(r));return Array.from(new Set(t))}getOperationVariables(e){let t=new Set;if(e.type==="bgp")for(let r of e.triples)r.subject.type==="variable"&&t.add(r.subject.value),r.predicate.type==="variable"&&t.add(r.predicate.value),r.object.type==="variable"&&t.add(r.object.value);else if(e.type==="join"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="filter")return this.getOperationVariables(e.input);if(e.type==="leftjoin"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else if(e.type==="union"){let r=this.getOperationVariables(e.left),i=this.getOperationVariables(e.right);return new Set([...r,...i])}else{if(e.type==="minus")return this.getOperationVariables(e.left);if(e.type==="project")return new Set(e.variables)}}return t}joinReordering(e){return e.type==="join"?this.reorderJoin(e):e.type==="filter"?{...e,input:this.joinReordering(e.input)}:e.type==="leftjoin"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="union"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="minus"?{...e,left:this.joinReordering(e.left),right:this.joinReordering(e.right)}:e.type==="project"?{...e,input:this.joinReordering(e.input)}:e.type==="orderby"?{...e,input:this.joinReordering(e.input)}:e.type==="slice"?{...e,input:this.joinReordering(e.input)}:e.type==="distinct"?{...e,input:this.joinReordering(e.input)}:e}reorderJoin(e){let t=this.isConstrained(e.left),r=this.isConstrained(e.right);if(r&&!t)return{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)};if(t&&!r)return{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)};let i=this.estimateCost(e.left);return this.estimateCost(e.right)<i?{type:"join",left:this.joinReordering(e.right),right:this.joinReordering(e.left)}:{type:"join",left:this.joinReordering(e.left),right:this.joinReordering(e.right)}}isConstrained(e){return e.type==="values"?!0:e.type==="bgp"?e.triples.some(t=>t.object.type!=="variable"||t.subject.type!=="variable"):e.type==="filter"?this.isConstrained(e.input):e.type==="join"?this.isConstrained(e.left)||this.isConstrained(e.right):e.type==="union"?this.isConstrained(e.left)&&this.isConstrained(e.right):!1}estimateCost(e){if(e.type==="bgp"){let t=0;for(let r of e.triples){let i=10;r.subject.type==="variable"&&(i*=10),r.predicate.type==="variable"&&(i*=20),r.object.type==="variable"&&(i*=5),t+=i}return t}if(e.type==="filter")return this.estimateCost(e.input)*.3;if(e.type==="join"){let t=this.estimateCost(e.left),r=this.estimateCost(e.right);return e.left.type==="values"||e.right.type==="values"?Math.min(t,r)*2:t*r}if(e.type==="leftjoin")return this.estimateCost(e.left)+this.estimateCost(e.right)*.5;if(e.type==="union")return this.estimateCost(e.left)+this.estimateCost(e.right);if(e.type==="values"){let t=e.bindings;return Array.isArray(t)?t.length*5:10}return e.type==="minus"?this.estimateCost(e.left)+this.estimateCost(e.right)*.3:100}setStatistics(e,t){this.stats.set(e,t)}getStatistics(e){return this.stats.get(e)}};Pm.AlgebraOptimizer=Sb});var vC=S(Om=>{"use strict";Object.defineProperty(Om,"__esModule",{value:!0});Om.AlgebraSerializer=void 0;var vb=class{static{a(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(
|
|
@@ -813,7 +813,7 @@ exo__BacklinksTableBlock_columns:${f==="[]"?" []":f}
|
|
|
813
813
|
`),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}`)})})}a(jN,"backfillOrphanTermsCommand");function $N(){let n=new se("backfill").description("Concept backfill tools for aiKnow assets");return n.addCommand(MN()),n.addCommand(jN()),n}a($N,"backfillCommand");var ky=require("path"),HN=require("fs"),QN=require("os");var Ny=require("child_process"),Ly=require("fs"),qN=require("path");var Zi=require("fs"),Dy=H(require("path")),UN=require("crypto");var kJ=/^---\s*\r?\n([\s\S]*?)\r?\n---\s*(?:\r?\n([\s\S]*))?$/;function BN(n){let e=n.match(kJ);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}}a(BN,"parseFile");function MJ(n,e){let t=ar.dump(n,{lineWidth:-1,quotingType:'"',forceQuotes:!1,noRefs:!0}),r=e.length>0?e:"";return`---
|
|
814
814
|
${t}---
|
|
815
815
|
${r}`}a(MJ,"serializeFile");function VN(n,e,t={}){let r=Dy.default.dirname(n),i=Dy.default.basename(n),s=Dy.default.join(r,`.${i}.tmp.${process.pid}.${(0,UN.randomBytes)(6).toString("hex")}`);try{let o=(0,Zi.readFileSync)(n,"utf8"),c;try{c=BN(o)}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=MJ(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=BN(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(o){if((0,Zi.existsSync)(s))try{(0,Zi.unlinkSync)(s)}catch{}return{success:!1,verified:!1,reason:"fs-error",error:o.message}}}a(VN,"atomicUpdateFrontmatter");var jJ=/^claude-child-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,$J=/^claude-child-([0-9a-f]{8})-(\d+)$/,BJ="EffortStatusDoing";function WN(n){return e=>new Promise((t,r)=>{n(e,(i,s,o)=>{i?r(Object.assign(i,{stdout:s,stderr:o})):t(s)})})}a(WN,"makeExecPromise");async function UJ(n=Ny.exec){let e=WN(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(`
|
|
816
|
-
`).map(s=>s.trim()).filter(Boolean)){let s=jJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let o=$J.exec(i);o&&r.push({sessionName:i,uuid:o[1],type:"short"})}return r}a(UJ,"listClaudeChildSessions");function VJ(n,e,t){let r=null,i=e.toLowerCase();function s(o){if(r)return;let c;try{c=(0,Ly.readdirSync)(o,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,qN.join)(o,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 a(s,"walk"),s(n),r}a(VJ,"findVaultFile");function qJ(n,e){try{let i=(e??(s=>(0,Ly.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(BJ):!1}catch{return!1}}a(qJ,"isTaskDoing");async function GN(n,e=Ny.exec,t){let r=await UJ(e),i=[];for(let s of r){let o=VJ(n,s.uuid,s.type);if(!o){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}qJ(o,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:o,reason:"vault task status != Doing"})}return i}a(GN,"detectOrphans");async function zN(n,e,t=Ny.exec,r=VN){let i=WN(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(o){return{ok:!1,error:`vault update failed: ${o.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}a(zN,"recoverOrphan");function WJ(){return process.env.EXOCORTEX_VAULT??(0,ky.join)((0,QN.homedir)(),"vault-2025")}a(WJ,"defaultVault");function KN(){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",WJ()).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,ky.resolve)(n.vault);if(!(0,HN.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 GN(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 o of r){let c=o.taskFilePath??"(not found in vault)";console.log(` session=${o.sessionName} uuid=${o.taskUuid} reason=${o.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 o of r){let c=await zN(o,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${o.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${o.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}a(KN,"recoverCommand");function YN(n){n.addCommand(aD()),n.addCommand(fD()),n.addCommand(dD())}a(YN,"addQuerySubcommands");function XN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.176.
|
|
816
|
+
`).map(s=>s.trim()).filter(Boolean)){let s=jJ.exec(i);if(s){r.push({sessionName:i,uuid:s[1],type:"full"});continue}let o=$J.exec(i);o&&r.push({sessionName:i,uuid:o[1],type:"short"})}return r}a(UJ,"listClaudeChildSessions");function VJ(n,e,t){let r=null,i=e.toLowerCase();function s(o){if(r)return;let c;try{c=(0,Ly.readdirSync)(o,{withFileTypes:!0})}catch{return}for(let l of c){if(r)return;if(l.name.startsWith(".")||l.name==="node_modules")continue;let u=(0,qN.join)(o,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 a(s,"walk"),s(n),r}a(VJ,"findVaultFile");function qJ(n,e){try{let i=(e??(s=>(0,Ly.readFileSync)(s,"utf8")))(n).match(/ems__Effort_status\s*:.*\[\[([^\]]+)\]\]/);return i?i[1].includes(BJ):!1}catch{return!1}}a(qJ,"isTaskDoing");async function GN(n,e=Ny.exec,t){let r=await UJ(e),i=[];for(let s of r){let o=VJ(n,s.uuid,s.type);if(!o){i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:null,reason:"vault task not found"});continue}qJ(o,t)||i.push({sessionName:s.sessionName,taskUuid:s.uuid,taskFilePath:o,reason:"vault task status != Doing"})}return i}a(GN,"detectOrphans");async function zN(n,e,t=Ny.exec,r=VN){let i=WN(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(o){return{ok:!1,error:`vault update failed: ${o.message}`}}try{await i(`tmux kill-session -t ${JSON.stringify(n.sessionName)}`)}catch{}return{ok:!0}}a(zN,"recoverOrphan");function WJ(){return process.env.EXOCORTEX_VAULT??(0,ky.join)((0,QN.homedir)(),"vault-2025")}a(WJ,"defaultVault");function KN(){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",WJ()).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,ky.resolve)(n.vault);if(!(0,HN.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 GN(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 o of r){let c=o.taskFilePath??"(not found in vault)";console.log(` session=${o.sessionName} uuid=${o.taskUuid} reason=${o.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 o of r){let c=await zN(o,!1);c.ok?(i++,console.log(`[recover] RECOVERED: ${o.sessionName}`)):(s++,console.error(`[recover] ERROR recovering ${o.sessionName}: ${c.error}`))}console.log(`[recover] Done: recovered=${i} errors=${s}`),s>0&&(process.exitCode=1)})}a(KN,"recoverCommand");function YN(n){n.addCommand(aD()),n.addCommand(fD()),n.addCommand(dD())}a(YN,"addQuerySubcommands");function XN(n){let e=new se;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.176.1");let t=e.command("exoql").description("ExoQL query execution and cache management");YN(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return YN(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(vD()),e.addCommand(ED()),e.addCommand(TD()),e.addCommand(xD()),e.addCommand(CD()),e.addCommand(FD()),e.addCommand(kD()),e.addCommand(KD()),e.addCommand(JD()),e.addCommand(nN()),e.addCommand(oN()),e.addCommand(aN()),e.addCommand(lN()),e.addCommand(vN()),e.addCommand(TN()),e.addCommand(ON()),e.addCommand(FN()),e.addCommand($N()),e.addCommand(KN()),e}a(XN,"createProgram");XN().parse();0&&(module.exports={createProgram});
|
|
817
817
|
/*! Bundled license information:
|
|
818
818
|
|
|
819
819
|
reflect-metadata/Reflect.js:
|
package/package.json
CHANGED