@kitelev/exocortex-cli 16.176.0 → 16.176.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v16.176.0
2
+ // @kitelev/exocortex-cli v16.176.2
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -209,7 +209,7 @@ ${s}`}return`${r}: ${i}`}).join(`
209
209
  `,o=await this.sparqlService.query(s);return this.buildEnumValues(o)}buildEnumValues(e){let t=[],r=new Set;for(let i of e){let s=this.getBindingValue(i,"instance");if(!s||r.has(s))continue;r.add(s);let o=this.getBindingValue(i,"label")??s,l=`[[${this.fromFullIRI(s)}]]`;t.push({value:l,label:o})}return t}buildRankProperty(e){let t=e.match(/^([a-z]+)__(.+)$/);if(!t)return null;let[,r,i]=t;return`${r}__${i}_rank`}normalizeClassName(e){return e.replace(/\[\[|\]\]/g,"").trim()}getBindingValue(e,t){let r=e.get(t);if(r!=null)return String(r)}toFullIRI(e){if(e.startsWith("http://")||e.startsWith("https://"))return e;let t=e.match(/^([a-z]+)__(.+)$/);if(t){let[,r,i]=t;return`https://exocortex.my/ontology/${r}#${i}`}return e}fromFullIRI(e){let t=e.match(/https:\/\/exocortex\.my\/ontology\/([a-z]+)#(.+)$/);if(t){let[,r,i]=t;return`${r}__${i}`}return e}};Po.EnumValueResolver=Ov;Po.EnumValueResolver=Ov=MG([(0,$G.injectable)(),jG("design:paramtypes",[Object,Object])],Ov)});var xv=T(qi=>{"use strict";var UG=qi&&qi.__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},BG=qi&&qi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},VG=qi&&qi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(qi,"__esModule",{value:!0});qi.AssetConversionService=void 0;var _P=Je(),bP=na(),qG=Os(),Ig=ga(),GG=Wt(),Cv=class{static{a(this,"AssetConversionService")}constructor(e){this.vault=e,this.frontmatterService=new qG.FrontmatterService}async convertTaskToProject(e){try{let t=await this.vault.read(e),r=this.removeInstanceClassProperty(t);return r=this.frontmatterService.updateProperty(r,"exo__Instance_class",`["[[${bP.AssetClass.PROJECT}]]"]`),await this.vault.modify(e,r),Ig.LoggingService.info(`Converted Task to Project: ${e.basename} (${e.path})`),e}catch(t){let r=`Failed to convert Task to Project: ${e.path}`;throw Ig.LoggingService.error(r,t instanceof Error?t:void 0),new Error(r)}}async convertProjectToTask(e){try{let t=await this.vault.read(e),r=this.removeInstanceClassProperty(t);return r=this.frontmatterService.updateProperty(r,"exo__Instance_class",`["[[${bP.AssetClass.TASK}]]"]`),await this.vault.modify(e,r),Ig.LoggingService.info(`Converted Project to Task: ${e.basename} (${e.path})`),e}catch(t){let r=`Failed to convert Project to Task: ${e.path}`;throw Ig.LoggingService.error(r,t instanceof Error?t:void 0),new Error(r)}}removeInstanceClassProperty(e){let t=this.frontmatterService.parse(e);if(!t.exists)return e;let r=/^exo__Instance_class:.*$(\n {2}-.*$)*/gm,i=t.content.replace(r,"").replace(/\n\n+/g,`
210
210
  `).trim();return e.replace(/^---\n[\s\S]*?\n---/,`---
211
211
  ${i}
212
- ---`)}};qi.AssetConversionService=Cv;qi.AssetConversionService=Cv=UG([(0,_P.injectable)(),VG(0,(0,_P.inject)(GG.DI_TOKENS.IVaultAdapter)),BG("design:paramtypes",[Object])],Cv)});var Fv=T(Gi=>{"use strict";var WG=Gi&&Gi.__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},HG=Gi&&Gi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},SP=Gi&&Gi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Gi,"__esModule",{value:!0});Gi.SessionEventService=void 0;var Pv=Je(),zG=Ai(),wP=na(),KG=zr(),YG=wo(),vP=Wt(),Dv=class{static{a(this,"SessionEventService")}constructor(e,t){this.vault=e,this.vaultSettings=t,this.folderPathCache=null}async createSessionStartEvent(e){return this.createSessionEvent(e,wP.AssetClass.SESSION_START_EVENT)}async createSessionEndEvent(e){return this.createSessionEvent(e,wP.AssetClass.SESSION_END_EVENT)}getSessionEventFolder(){if(this.folderPathCache!==null)return this.folderPathCache;let e=this.vault.getDefaultNewFileParent();return this.folderPathCache=e?.path||"",this.folderPathCache}async createSessionEvent(e,t){let r=(0,zG.v4)(),i=KG.DateFormatter.toLocalTimestamp(new Date),s={exo__Asset_uid:r,exo__Asset_createdAt:i,exo__Asset_isDefinedBy:this.vaultSettings.getOwnerIdentity(),exo__Instance_class:[`"[[${t}]]"`],ems__SessionEvent_timestamp:i,ems__Session_area:`"[[${e}]]"`},o=YG.MetadataHelpers.buildFileContent(s),c=this.getSessionEventFolder();c&&!await this.vault.exists(c)&&await this.vault.createFolder(c);let l=c?`${c}/${r}.md`:`${r}.md`;return await this.vault.create(l,o)}};Gi.SessionEventService=Dv;Gi.SessionEventService=Dv=WG([(0,Pv.injectable)(),SP(0,(0,Pv.inject)(vP.DI_TOKENS.IVaultAdapter)),SP(1,(0,Pv.inject)(vP.DI_TOKENS.IVaultSettings)),HG("design:paramtypes",[Object,Object])],Dv)});var kv=T(Wi=>{"use strict";var XG=Wi&&Wi.__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},QG=Wi&&Wi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},EP=Wi&&Wi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Wi,"__esModule",{value:!0});Wi.URIConstructionService=void 0;var Lv=Je(),TP=Wt(),JG=ll(),Nv=class{static{a(this,"URIConstructionService")}constructor(e,t=JG.NullLogger){this.fileSystem=e,this.logger=t,this.defaultOntologyURL="https://exocortex.my/default/",this.strictValidation=!0}configure(e){e?.defaultOntologyURL&&(this.defaultOntologyURL=e.defaultOntologyURL),e?.strictValidation!==void 0&&(this.strictValidation=e.strictValidation)}async constructAssetURI(e){let t=this.extractUID(e);if(!t){if(this.strictValidation)throw new Error(`Asset missing exo__Asset_uid: ${e.path}`);return this.logger.warn(`Asset ${e.path} missing UID, using filename fallback`),this.constructFallbackURI(e)}let r=await this.resolveOntologyURL(e);if(!this.validateOntologyURL(r))throw new Error(`Invalid ontology URL: ${r}`);return`${r.endsWith("/")?r:`${r}/`}${t}`}validateOntologyURL(e){if(!e)return!1;try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}async resolveOntologyURL(e){let t=e.frontmatter?.exo__Asset_isDefinedBy;if(!t||typeof t!="string")return this.defaultOntologyURL;let r=this.extractWikiLink(t),i=r,s=await this.fileSystem.fileExists(r);return!s&&!r.endsWith(".md")&&(i=`${r}.md`,s=await this.fileSystem.fileExists(i)),s?(await this.fileSystem.getFileMetadata(i))?.exo__Ontology_url||this.defaultOntologyURL:(this.logger.warn(`Ontology file not found: ${r}, using default`),this.defaultOntologyURL)}extractUID(e){let t=e.frontmatter?.exo__Asset_uid;return typeof t=="string"?t:null}extractWikiLink(e){return e.replace(/^\[\[|\]\]$/g,"")}constructFallbackURI(e){let t=e.path.split("/").pop()?.replace(".md","")||"unknown";return`${this.defaultOntologyURL}${t}`}};Wi.URIConstructionService=Nv;Wi.URIConstructionService=Nv=XG([(0,Lv.injectable)(),EP(0,(0,Lv.inject)(TP.DI_TOKENS.IFileSystemAdapter)),EP(1,(0,Lv.inject)(TP.DI_TOKENS.ILogger)),QG("design:paramtypes",[Object,Object])],Nv)});var jv=T(Hi=>{"use strict";var ZG=Hi&&Hi.__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},eW=Hi&&Hi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},tW=Hi&&Hi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Hi,"__esModule",{value:!0});Hi.GenericAssetCreationService=void 0;var IP=Je(),id=zr(),rW=wo(),nW=ws(),iW=Jt(),sW=Wt(),Ps=vp(),oW=Wf(),aW=Ym(),Mv=class{static{a(this,"GenericAssetCreationService")}constructor(e){this.vault=e,this.clock=(0,oW.liveClock)(),this.uidGen=(0,aW.liveUidGenerator)()}withDeterminism(e){return e.clock&&(this.clock=e.clock),e.uidGenerator&&(this.uidGen=e.uidGenerator),this}async createAsset(e,t){let{folderPath:r,path:i,content:s}=this.buildAsset(e,t);return this.vault.getAbstractFileByPath(r)||await this.vault.createFolder(r),await this.vault.create(i,s)}buildAsset(e,t){let r=this.uidGen.next(),i=this.generateFrontmatter(e,t||[],r),s=rW.MetadataHelpers.buildFileContent(i,e.body),o=e.folderPath||this.getDefaultFolderPath(e),c=`${r}.md`,l=o?`${o}/${c}`:c;return{uid:r,folderPath:o,path:l,frontmatter:i,content:s}}generateFrontmatter(e,t=[],r=this.uidGen.next()){let i={},s=new Map;for(let c of t)s.set(c.name,c.fieldType);i.exo__Asset_uid=r,i.exo__Asset_createdAt=e.timezone?this.generateTimestampInTimezone(e.timezone):id.DateFormatter.toLocalTimestamp(this.clock.now());let o=e.classRefForm==="uuid"&&e.classUid?e.classUid:e.className;if(i.exo__Instance_class=[this.formatWikilink(o)],e.createdBy&&e.createdBy.trim()!==""&&(i.exo__Asset_createdBy=this.formatWikilink(e.createdBy.trim())),e.label&&e.label.trim()!==""){let c=e.label.trim();i.exo__Asset_label=c;let l=[c];if(e.aliases)for(let u of e.aliases)l.includes(u)||l.push(u);i.aliases=l}if(e.parentFile&&e.parentMetadata&&this.inheritParentContext(i,e),e.propertyValues){for(let[c,l]of Object.entries(e.propertyValues))if(!(c==="exo__Asset_uid"||c==="exo__Asset_createdAt"||c==="exo__Asset_createdBy"||c==="exo__Instance_class"||c==="exo__Asset_label"||c==="aliases")&&l!=null)if(e.shapeRegistry!==void 0)Array.isArray(l)?i[c]=l.map(u=>this.quoteWikilinkValue(String(u))):i[c]=this.formatPropertyValueWithCardinality(c,String(l),e.shapeRegistry);else{let u=s.get(c);i[c]=this.formatValue(l,u)}}return i}inheritParentContext(e,t){let r=t.parentMetadata||{},i=t.parentFile?.basename;if(t.className==="ems__Task"||t.className.startsWith("ems__Task")){let s=r.exo__Instance_class,c=this.isAreaClass(s,t.classResolver)?"ems__Effort_area":"ems__Effort_parent";e[c]=i?this.formatWikilink(i):null}if(t.className==="ems__Project"||t.className.startsWith("ems__Project")){let s=r.exo__Instance_class,c=this.isAreaClass(s,t.classResolver)?"ems__Effort_area":"ems__Effort_parent";e[c]=i?this.formatWikilink(i):null}if(r.exo__Asset_isDefinedBy){let s=r.exo__Asset_isDefinedBy;e.exo__Asset_isDefinedBy=typeof s=="string"?this.formatWikilink(s):s}}isAreaClass(e,t){if(!e)return!1;let r=Array.isArray(e)?e:[e],i=a(()=>null,"noopResolver");return r.some(s=>{let o=nW.WikiLinkHelpers.resolveSymbolic(String(s),t??i);return o.includes("Area")||o.includes("ems__Area")})}getDefaultFolderPath(e){if(e.parentFile?.parent?.path)return e.parentFile.parent.path;let t={ems__Task:"tasks",ems__Project:"projects",ems__Area:"areas",ems__Meeting:"meetings",exo__Event:"events",ims__Concept:"concepts"};if(t[e.className])return t[e.className];for(let[r,i]of Object.entries(t))if(e.className.startsWith(r))return i;return"assets"}formatValue(e,t){if(e==null)return null;if(!t)return this.formatInferredValue(e);switch(t){case Ps.PropertyFieldType.Text:return String(e);case Ps.PropertyFieldType.Wikilink:case Ps.PropertyFieldType.Reference:case Ps.PropertyFieldType.StatusSelect:case Ps.PropertyFieldType.SizeSelect:return this.formatWikilink(String(e));case Ps.PropertyFieldType.Number:return typeof e=="number"?e:Number(e)||0;case Ps.PropertyFieldType.Boolean:return this.formatBoolean(e);case Ps.PropertyFieldType.Date:case Ps.PropertyFieldType.DateTime:case Ps.PropertyFieldType.Timestamp:return this.formatTimestamp(e);default:return String(e)}}formatInferredValue(e){return typeof e=="boolean"||typeof e=="number"?e:e instanceof Date?id.DateFormatter.toLocalTimestamp(e):typeof e=="string"?e.startsWith("[[")||e.startsWith('"[[')?this.formatWikilink(e):e:String(e)}formatWikilink(e){return e.startsWith('"[[')&&e.endsWith(']]"')?e:e.startsWith("[[")&&e.endsWith("]]")?`"${e}"`:`"[[${e}]]"`}formatBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="string"){let t=e.toLowerCase().trim();return t==="true"||t==="yes"||t==="1"}return typeof e=="number"?e!==0:!!e}formatTimestamp(e){if(e instanceof Date)return id.DateFormatter.toLocalTimestamp(e);if(typeof e=="string"){if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(e))return e.replace("Z","");let t=new Date(e);return isNaN(t.getTime())?e:id.DateFormatter.toLocalTimestamp(t)}if(typeof e=="number"){let t=new Date(e);if(!isNaN(t.getTime()))return id.DateFormatter.toLocalTimestamp(t)}return String(e)}formatPropertyValueWithCardinality(e,t,r){let i=this.quoteWikilinkValue(t);return i.includes("[[")&&this.shouldEmitAsArray(e,r)?[i]:i}quoteWikilinkValue(e){return e.includes("[[")?e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`:e}shouldEmitAsArray(e,t){if(!t)return!1;let r=iW.Namespace.fromPropertyKey(e);if(!r)return!1;let i=r.namespace.term(r.localName).value;return t.get(i)?.cardinality==="Multiple"}generateTimestampInTimezone(e){let t=this.clock.now(),i=new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(t),s=a(o=>i.find(c=>c.type===o)?.value||"00","get");return`${s("year")}-${s("month")}-${s("day")}T${s("hour")}:${s("minute")}:${s("second")}`}};Hi.GenericAssetCreationService=Mv;Hi.GenericAssetCreationService=Mv=ZG([(0,IP.injectable)(),tW(0,(0,IP.inject)(sW.DI_TOKENS.IVaultAdapter)),eW("design:paramtypes",[Object])],Mv)});var RP=T(zi=>{"use strict";var cW=zi&&zi.__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},lW=zi&&zi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},uW=zi&&zi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(zi,"__esModule",{value:!0});zi.ArchiveAssetService=void 0;var AP=Je(),fW=Wt(),dW=Os(),$v=class{static{a(this,"ArchiveAssetService")}constructor(e){this.vault=e,this.frontmatterService=new dW.FrontmatterService}async archiveAsset(e){let t=await this.vault.read(e),r=this.frontmatterService.updateProperty(t,"archived","true");r=this.frontmatterService.removeProperty(r,"aliases"),r!==t&&await this.vault.modify(e,r)}};zi.ArchiveAssetService=$v;zi.ArchiveAssetService=$v=cW([(0,AP.injectable)(),uW(0,(0,AP.inject)(fW.DI_TOKENS.IVaultAdapter)),lW("design:paramtypes",[Object])],$v)});var CP=T(Ki=>{"use strict";var hW=Ki&&Ki.__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},pW=Ki&&Ki.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},mW=Ki&&Ki.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Ki,"__esModule",{value:!0});Ki.FixMissingLabelService=void 0;var OP=Je(),gW=Wt(),yW=Os(),Uv=class{static{a(this,"FixMissingLabelService")}constructor(e){this.vault=e,this.frontmatterService=new yW.FrontmatterService}async fixMissingLabel(e){let t=await this.vault.read(e);if(this.hasNonEmptyLabel(t))return;let r=this.frontmatterService.updateProperty(t,"exo__Asset_label",e.basename);r!==t&&await this.vault.modify(e,r)}hasNonEmptyLabel(e){let t=this.frontmatterService.parse(e);if(!t.exists)return!1;let r=t.content.match(/^exo__Asset_label:\s*(.*)$/m);if(!r)return!1;let i=r[1].trim();return!(i===""||i==='""'||i==="''")}};Ki.FixMissingLabelService=Uv;Ki.FixMissingLabelService=Uv=hW([(0,OP.injectable)(),mW(0,(0,OP.inject)(gW.DI_TOKENS.IVaultAdapter)),pW("design:paramtypes",[Object])],Uv)});var xP=T(Do=>{"use strict";var _W=Do&&Do.__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},bW=Do&&Do.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Do,"__esModule",{value:!0});Do.GraphQueryService=void 0;var SW=Je(),sd=ze(),wW=et(),ba=Jt(),vW=Eb(),Ds={INSTANCE_CLASS:ba.Namespace.EXO.term("Instance_class"),ASSET_LABEL:ba.Namespace.EXO.term("Asset_label"),ASSET_PROTOTYPE:ba.Namespace.EXO.term("Asset_prototype"),ASSET_IS_ARCHIVED:ba.Namespace.EXO.term("Asset_isArchived"),EFFORT_PARENT:ba.Namespace.EMS.term("Effort_parent"),REFERENCES:ba.Namespace.EXO.term("references"),REFERENCED_BY:ba.Namespace.EXO.term("referencedBy"),RDF_TYPE:ba.Namespace.RDF.term("type")},Bv=class{static{a(this,"GraphQueryService")}constructor(e,t={},r){this.subscribers=new Set,this.nodeCache=new Map,this.lastCacheUpdate=0,this.tripleStore=e,this.logger=r,this.config={defaultLimit:t.defaultLimit??100,maxLimit:t.maxLimit??1e4,defaultDepth:t.defaultDepth??2,maxDepth:t.maxDepth??10,includeArchivedByDefault:t.includeArchivedByDefault??!1,cacheTTL:t.cacheTTL??3e4}}async loadGraphData(e={}){let t=Date.now(),r=await this.loadNodes(e),i=await this.loadEdges(r,e),s=this.computeStats(r,i),o=Date.now()-t;return o>100&&r.length>0&&this.logger?.debug(`GraphQueryService: loaded ${r.length} nodes in ${o}ms (${(o/r.length).toFixed(2)}ms/node)`),{nodes:r,edges:i,stats:s,lastUpdated:Date.now(),version:1}}async loadNodesIncremental(e={}){let t=Math.min(e.limit??this.config.defaultLimit,this.config.maxLimit),r=e.offset??0,i=await this.loadNodes({...e,limit:t+1,offset:r}),s=i.length>t,o=s?i.slice(0,t):i,c=await this.loadEdges(o,e);return{nodes:o,edges:c,hasMore:s,totalCount:void 0,cursor:s?String(r+t):void 0}}async loadConnectedNodes(e,t={}){let r=Math.min(t.depth??this.config.defaultDepth,this.config.maxDepth),i=Math.min(t.limit??this.config.maxLimit,this.config.maxLimit),s=new Set,o=[{id:e,currentDepth:0}],c=[];for(;o.length>0&&c.length<i;){let u=o.shift();if(!u)break;let{id:f,currentDepth:d}=u;if(s.has(f))continue;s.add(f);let h=await this.getNodeById(f,t);if(h&&(c.push(h),d<r)){let p=await this.getConnectedNodeIds(f);for(let y of p)s.has(y)||o.push({id:y,currentDepth:d+1})}}let l=await this.loadEdges(c,t);return{nodes:c,edges:l,hasMore:o.length>0,totalCount:s.size+o.length}}async getNodeById(e,t={}){let r=this.getCachedNode(e);if(r)return{...r};let i=this.idToIRI(e),s=await this.tripleStore.match(i,void 0,void 0);if(s.length===0)return null;let o=this.triplesToNode(e,s,t);return o&&this.cacheNode(o),o}subscribe(e){return this.subscribers.add(e),{unsubscribe:a(()=>{this.subscribers.delete(e)},"unsubscribe")}}notifyChange(e){for(let t of this.subscribers)try{t(e)}catch(r){this.logger?.error("GraphQueryService: error in subscriber callback",r instanceof Error?r:new Error(String(r)))}this.invalidateCache()}async getStats(){let e=await this.loadNodes({includeArchived:!0}),t=await this.loadEdges(e,{});return this.computeStats(e,t)}clearCache(){this.nodeCache.clear(),this.lastCacheUpdate=0}async loadNodes(e){let t=e.includeArchived??this.config.includeArchivedByDefault,r=e.limit??this.config.maxLimit,i=e.offset??0,s=await this.tripleStore.match(void 0,Ds.INSTANCE_CLASS,void 0),o=s;if(e.classes&&e.classes.length>0){let p=new Set(e.classes);o=s.filter(y=>{let _=this.getObjectValue(y.object);return _&&p.has(_)})}let c=new Set;for(let p of o)c.add(this.subjectToId(p.subject));let f=Array.from(c).slice(i,i+r).map(p=>this.getNodeById(p,e));return(await Promise.all(f)).filter(p=>!(!p||!t&&p.isArchived))}async loadEdges(e,t){let r=new Set(e.map(o=>o.id)),i=[],s=new Set;for(let o of e){let c=this.idToIRI(o.id),l=await this.tripleStore.match(c,void 0,void 0);for(let u of l){let f=this.tripleToEdge(o.id,u,r);f&&f.id&&!s.has(f.id)&&(!t.edgeTypes||t.edgeTypes.includes(f.type))&&(s.add(f.id),i.push(f))}}return i}async getConnectedNodeIds(e){let t=this.idToIRI(e),r=[],i=await this.tripleStore.match(t,void 0,void 0);for(let o of i){let c=this.objectToId(o.object);c&&r.push(c)}let s=await this.tripleStore.match(void 0,void 0,t);for(let o of s)r.push(this.subjectToId(o.subject));return[...new Set(r)]}triplesToNode(e,t,r){let i={},s,o,c,l,u=!1;for(let h of t){let p=h.predicate.value,y=this.getObjectValue(h.object);if(p===Ds.INSTANCE_CLASS.value)s=y;else if(p===Ds.ASSET_LABEL.value)o=y;else if(p===Ds.ASSET_PROTOTYPE.value)c=this.objectToId(h.object)??y;else if(p===Ds.EFFORT_PARENT.value)l=this.objectToId(h.object)??y;else if(p===Ds.ASSET_IS_ARCHIVED.value)u=y==="true"||y==="1";else{let _=this.predicateToPropertyName(p);_&&(i[_]=y)}}if(u&&!(r.includeArchived??this.config.includeArchivedByDefault))return null;let f=this.idToPath(e),d=o??this.pathToTitle(f);return{id:e,path:f,title:d,label:d,assetClass:s,isArchived:u,uri:e.startsWith("http")?e:void 0,prototype:c,parent:l,properties:Object.keys(i).length>0?i:void 0}}tripleToEdge(e,t,r){let i=t.predicate.value,s=this.objectToId(t.object);if(!s||!r.has(s)||s===e)return null;let o=this.predicateToEdgeType(i);if(!o)return null;let c=(0,vW.createEdgeId)(e,s,o,i),l=this.predicateToLabel(i);return{id:c,source:e,target:s,type:o,predicate:i,label:l}}predicateToEdgeType(e){return e===Ds.EFFORT_PARENT.value?"hierarchy":e===Ds.ASSET_PROTOTYPE.value?"prototype":e===Ds.REFERENCES.value?"forward-link":e===Ds.REFERENCED_BY.value?"backlink":e.includes("Asset_")||e.includes("Instance_")?null:"semantic"}predicateToLabel(e){let t=e.lastIndexOf("#"),r=e.lastIndexOf("/"),i=Math.max(t,r);return i>=0?e.substring(i+1):e}predicateToPropertyName(e){return this.predicateToLabel(e).replace(/_/g,"__").replace(/#/g,"_")}computeStats(e,t){let r={},i={backlink:0,"forward-link":0,hierarchy:0,prototype:0,semantic:0,reference:0};for(let c of e){let l=c.assetClass??"unknown";r[l]=(r[l]??0)+1}for(let c of t)i[c.type]=(i[c.type]??0)+1;let s=new Map,o=new Map;for(let c of t)o.set(c.source,(o.get(c.source)??0)+1),s.set(c.target,(s.get(c.target)??0)+1);for(let c of e)c.inDegree=s.get(c.id)??0,c.outDegree=o.get(c.id)??0,c.weight=c.inDegree+c.outDegree;return{nodeCount:e.length,edgeCount:t.length,nodesByClass:r,edgesByType:i,computedAt:Date.now()}}idToIRI(e){return e.startsWith("http://")||e.startsWith("https://")?new sd.IRI(e):new sd.IRI(`obsidian://vault/${encodeURIComponent(e)}`)}subjectToId(e){if(e instanceof sd.IRI){let t=e.value;return t.startsWith("obsidian://vault/")?decodeURIComponent(t.replace("obsidian://vault/","")):t}return e.toString()}objectToId(e){if(e instanceof sd.IRI){let t=e.value;return t.startsWith("obsidian://vault/")?decodeURIComponent(t.replace("obsidian://vault/","")):t}return null}getObjectValue(e){if(e instanceof wW.Literal||e instanceof sd.IRI)return e.value}idToPath(e){if(e.startsWith("obsidian://vault/"))return decodeURIComponent(e.replace("obsidian://vault/",""));if(e.startsWith("http://")||e.startsWith("https://")){let t=e.match(/\/([^/]+\.md)$/);if(t)return t[1]}return e}pathToTitle(e){return(e.split("/").pop()??e).replace(/\.md$/,"")}getCachedNode(e){return Date.now()-this.lastCacheUpdate>this.config.cacheTTL?(this.clearCache(),null):this.nodeCache.get(e)??null}cacheNode(e){this.nodeCache.set(e.id,e),this.lastCacheUpdate===0&&(this.lastCacheUpdate=Date.now())}invalidateCache(){this.clearCache()}};Do.GraphQueryService=Bv;Do.GraphQueryService=Bv=_W([(0,SW.injectable)(),bW("design:paramtypes",[Object,Object,Object])],Bv)});var DP=T(Fo=>{"use strict";var EW=Fo&&Fo.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},TW=Fo&&Fo.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Fo,"__esModule",{value:!0});Fo.TypeRegistry=void 0;var IW=Je(),Fs=ze(),PP=qt(),AW=et(),RW=ga(),Tt=Tb(),Vv=class{static{a(this,"TypeRegistry")}constructor(e=null,t={}){this.nodeTypes=new Map,this.edgeTypes=new Map,this.typeHierarchy=new Map,this.subscribers=new Set,this.discoveryComplete=!1,this.tripleStore=e,this.config={autoDiscoverTypes:t.autoDiscoverTypes??!0,includeBuiltInStyles:t.includeBuiltInStyles??!0,styleResolution:t.styleResolution??{mergeStyles:!0,inheritParentStyles:!0,defaultNodeStyle:Tt.DEFAULT_NODE_STYLE,defaultEdgeStyle:Tt.DEFAULT_EDGE_STYLE},maxInheritanceDepth:t.maxInheritanceDepth??10},this.config.includeBuiltInStyles&&this.registerBuiltInTypes()}registerNodeType(e){let r=this.nodeTypes.get(e.uri)?"type-updated":"type-added";this.nodeTypes.set(e.uri,e),e.parentTypes&&e.parentTypes.length>0&&this.typeHierarchy.set(e.uri,e.parentTypes),this.emit({type:r,typeUri:e.uri,definition:e})}registerEdgeType(e){let r=this.edgeTypes.get(e.uri)?"type-updated":"type-added";this.edgeTypes.set(e.uri,e),this.emit({type:r,typeUri:e.uri,definition:e})}unregisterType(e){let t=this.nodeTypes.delete(e),r=this.edgeTypes.delete(e);this.typeHierarchy.delete(e),(t||r)&&this.emit({type:"type-removed",typeUri:e})}getNodeType(e){return this.nodeTypes.get(e)}getEdgeType(e){return this.edgeTypes.get(e)}getAllNodeTypes(){return Array.from(this.nodeTypes.values())}getAllEdgeTypes(){return Array.from(this.edgeTypes.values())}getParentTypes(e,t=this.config.maxInheritanceDepth){let r=[],i=new Set,s=[{uri:e,currentDepth:0}];for(;s.length>0;){let o=s.shift();if(!o)break;let{uri:c,currentDepth:l}=o;if(i.has(c)||(i.add(c),l>=t))continue;let u=this.typeHierarchy.get(c)??[];for(let f of u)i.has(f)||(r.push(f),s.push({uri:f,currentDepth:l+1}))}return r}getChildTypes(e){let t=[];for(let[r,i]of this.typeHierarchy)i.includes(e)&&t.push(r);return t}isSubtypeOf(e,t){return e===t?!0:this.getParentTypes(e).includes(t)}resolveNodeType(e){let t=[],r="unknown",i="custom";if(e.assetClass){let c=this.normalizeTypeUri(e.assetClass);t.push(c),r=c,i="exo:Instance_class"}let s=e.properties?.[Tt.RDF_TYPE_PREDICATES.RDF_TYPE];s&&!t.includes(s)&&(t.push(s),r==="unknown"&&(r=s,i="rdf:type"));for(let c of[...t]){let l=this.getParentTypes(c);for(let u of l)t.includes(u)||t.push(u)}let o=this.resolveNodeStyle(t);return{primaryType:r,types:t,resolvedStyle:o,source:i}}resolveEdgeType(e){let t=e.predicate??e.type,r=e.predicate?"rdf:type":"custom",i=this.resolveEdgeStyle(t);return{primaryType:t,resolvedStyle:i,source:r}}resolveNodeStyle(e){let{mergeStyles:t,defaultNodeStyle:r}=this.config.styleResolution,i={...r},s=[];for(let o of e){let c=this.nodeTypes.get(o);c&&s.push(c)}if(s.sort((o,c)=>o.priority-c.priority),t)for(let o of s)i=(0,Tt.mergeNodeStyles)(i,o.style);else if(s.length>0){let o=s[s.length-1];i=(0,Tt.mergeNodeStyles)(i,o.style)}return i}resolveEdgeStyle(e){let{defaultEdgeStyle:t}=this.config.styleResolution,r={...t},i=this.edgeTypes.get(e);return i&&(r=(0,Tt.mergeEdgeStyles)(r,i.style)),r}filterNodes(e,t){return e.filter(r=>{let i=this.resolveNodeType(r);return!(t.includeNodeTypes&&t.includeNodeTypes.length>0&&!t.includeNodeTypes.some(o=>i.types.includes(o)||t.includeInferred&&this.isSubtypeOf(i.primaryType,o))||t.excludeNodeTypes&&t.excludeNodeTypes.length>0&&t.excludeNodeTypes.some(o=>i.types.includes(o)||t.includeInferred&&this.isSubtypeOf(i.primaryType,o))||!t.includeDeprecated&&this.nodeTypes.get(i.primaryType)?.deprecated)})}filterEdges(e,t){return e.filter(r=>{let i=r.predicate??r.type;return!(t.includeEdgeTypes&&t.includeEdgeTypes.length>0&&!t.includeEdgeTypes.includes(i)||t.excludeEdgeTypes&&t.excludeEdgeTypes.length>0&&t.excludeEdgeTypes.includes(i))})}groupNodesByType(e,t,r={}){let{groupByNodeType:i=!0,groupByParentType:s=!1,groupLevel:o=0,maxGroups:c=20,customGroupFn:l}=r,u=new Map;for(let h of e){let p=this.resolveNodeType(h),y;if(l?y=l(p.types):s&&p.types.length>o?y=p.types[o]??p.primaryType:i?y=p.primaryType:y="all",!u.has(y)){let S=this.nodeTypes.get(y)?.label??(0,Tt.extractLocalName)(y);u.set(y,{nodeIds:new Set,label:S})}let _=u.get(y);_&&_.nodeIds.add(h.id)}let f=Array.from(u.entries()).map(([h,p])=>({id:h,label:p.label,nodeIds:Array.from(p.nodeIds)}));if(f.length>c){f.sort((y,_)=>_.nodeIds.length-y.nodeIds.length);let h=f.slice(0,c-1),p=f.slice(c-1).flatMap(y=>y.nodeIds);h.push({id:"other",label:"Other",nodeIds:p}),f=h}let d=new Map;for(let h of f)for(let p of h.nodeIds)d.set(p,h.id);return f.map((h,p)=>{let y=new Set(h.nodeIds),_=[],w=[];for(let x of t){let O=y.has(x.source),C=y.has(x.target);O&&C?x.id&&_.push(x.id):(O||C)&&x.id&&w.push(x.id)}let E=`hsl(${p*137.5%360}, 70%, 50%)`;return{id:h.id,label:h.label,nodeIds:h.nodeIds,internalEdgeIds:_,externalEdgeIds:w,color:E,stats:{nodeCount:h.nodeIds.length,internalEdgeCount:_.length,externalEdgeCount:w.length}}})}validateTypes(e,t){let r=[],i=[];for(let s of e){let o=this.resolveNodeType(s);if(o.primaryType!=="unknown"){let c=this.nodeTypes.get(o.primaryType);!c&&o.source!=="inferred"&&i.push({code:"UNREGISTERED_NODE_TYPE",message:`Node type "${o.primaryType}" is not registered`,elementId:s.id,suggestion:"Register the type with registerNodeType()"}),c?.deprecated&&i.push({code:"DEPRECATED_NODE_TYPE",message:`Node uses deprecated type "${o.primaryType}"`,elementId:s.id,suggestion:"Migrate to a non-deprecated type"})}else i.push({code:"MISSING_NODE_TYPE",message:"Node has no type information",elementId:s.id,suggestion:"Add exo:Instance_class or rdf:type to the node"})}for(let s of t){let o=s.predicate??s.type,c=this.edgeTypes.get(o);if(c?.domain&&c.domain.length>0){let l=e.find(u=>u.id===s.source);if(l){let u=this.resolveNodeType(l);c.domain.some(d=>u.types.includes(d))||r.push({code:"DOMAIN_VIOLATION",message:"Edge source does not match expected domain",elementId:s.id,expected:c.domain,actual:u.types})}}if(c?.range&&c.range.length>0){let l=e.find(u=>u.id===s.target);if(l){let u=this.resolveNodeType(l);c.range.some(d=>u.types.includes(d))||r.push({code:"RANGE_VIOLATION",message:"Edge target does not match expected range",elementId:s.id,expected:c.range,actual:u.types})}}}return{valid:r.length===0,errors:r,warnings:i}}async discoverTypes(){if(!this.tripleStore||this.discoveryComplete)return;let e=await this.tripleStore.match(void 0,new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDF_TYPE),void 0);for(let r of e){let i=this.getObjectValue(r.object);if(i&&(0,Tt.isClassType)(i)){let s=this.getSubjectValue(r.subject);s&&await this.discoverNodeType(s)}}let t=await this.tripleStore.match(void 0,new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_SUBCLASS_OF),void 0);for(let r of t){let i=this.getSubjectValue(r.subject),s=this.getObjectValue(r.object);if(i&&s){let o=this.typeHierarchy.get(i)??[];if(!o.includes(s)){o.push(s),this.typeHierarchy.set(i,o);let c=this.nodeTypes.get(i);c&&(c.parentTypes=o)}}}this.discoveryComplete=!0,this.emit({type:"hierarchy-updated",rootTypes:this.getRootTypes()})}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}clear(){this.nodeTypes.clear(),this.edgeTypes.clear(),this.typeHierarchy.clear(),this.discoveryComplete=!1,this.config.includeBuiltInStyles&&this.registerBuiltInTypes()}registerBuiltInTypes(){for(let[e,t]of Object.entries(Tt.BUILT_IN_NODE_STYLES))this.nodeTypes.set(e,{uri:e,label:(0,Tt.extractLocalName)(e),source:"custom",style:(0,Tt.mergeNodeStyles)(Tt.DEFAULT_NODE_STYLE,t),priority:1});for(let[e,t]of Object.entries(Tt.BUILT_IN_EDGE_STYLES))this.edgeTypes.set(e,{uri:e,label:(0,Tt.extractLocalName)(e),source:"custom",style:(0,Tt.mergeEdgeStyles)(Tt.DEFAULT_EDGE_STYLE,t),priority:1})}async discoverNodeType(e){if(this.nodeTypes.has(e)||!this.tripleStore)return;let t=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_LABEL),void 0),r=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_COMMENT),void 0),i=t.length>0?this.getObjectValue(t[0].object)??(0,Tt.extractLocalName)(e):(0,Tt.extractLocalName)(e),s=r.length>0?this.getObjectValue(r[0].object):void 0,o="rdfs:Class",c=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDF_TYPE),void 0);for(let f of c)if(this.getObjectValue(f.object)===Tt.RDF_TYPE_PREDICATES.OWL_CLASS){o="owl:Class";break}let l=Tt.BUILT_IN_NODE_STYLES[e]??Tt.BUILT_IN_NODE_STYLES[(0,Tt.extractLocalName)(e)],u={uri:e,label:i,description:s,source:o,style:(0,Tt.mergeNodeStyles)(Tt.DEFAULT_NODE_STYLE,l??{}),priority:1};this.registerNodeType(u)}normalizeTypeUri(e){let t=e.match(/^\[\[(.+?)\]\]$/);return t?t[1]:e}getSubjectValue(e){if(e instanceof Fs.IRI)return e.value;if(e instanceof PP.BlankNode)return`_:${e.id}`;if(typeof e=="object"&&e!==null&&"termType"in e)return e.toString()}getObjectValue(e){if(e instanceof AW.Literal||e instanceof Fs.IRI)return e.value;if(e instanceof PP.BlankNode)return`_:${e.id}`}getRootTypes(){let e=new Set;for(let r of this.typeHierarchy.values())for(let i of r)e.add(i);let t=[];for(let r of this.nodeTypes.keys()){let i=this.typeHierarchy.get(r);(!i||i.length===0)&&e.has(r)&&t.push(r)}return t}emit(e){for(let t of this.subscribers)try{t(e)}catch(r){RW.LoggingService.error("TypeRegistry: error in subscriber callback",r instanceof Error?r:new Error(String(r)))}}};Fo.TypeRegistry=Vv;Fo.TypeRegistry=Vv=EW([(0,IW.injectable)(),TW("design:paramtypes",[Object,Object])],Vv)});var FP=T(Ag=>{"use strict";Object.defineProperty(Ag,"__esModule",{value:!0});Ag.SPARQL_PREFIXES=void 0;Ag.SPARQL_PREFIXES=`PREFIX exo: <https://exocortex.my/ontology/exo#>
212
+ ---`)}};qi.AssetConversionService=Cv;qi.AssetConversionService=Cv=UG([(0,_P.injectable)(),VG(0,(0,_P.inject)(GG.DI_TOKENS.IVaultAdapter)),BG("design:paramtypes",[Object])],Cv)});var Fv=T(Gi=>{"use strict";var WG=Gi&&Gi.__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},HG=Gi&&Gi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},SP=Gi&&Gi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Gi,"__esModule",{value:!0});Gi.SessionEventService=void 0;var Pv=Je(),zG=Ai(),wP=na(),KG=zr(),YG=wo(),vP=Wt(),Dv=class{static{a(this,"SessionEventService")}constructor(e,t){this.vault=e,this.vaultSettings=t,this.folderPathCache=null}async createSessionStartEvent(e){return this.createSessionEvent(e,wP.AssetClass.SESSION_START_EVENT)}async createSessionEndEvent(e){return this.createSessionEvent(e,wP.AssetClass.SESSION_END_EVENT)}getSessionEventFolder(){if(this.folderPathCache!==null)return this.folderPathCache;let e=this.vault.getDefaultNewFileParent();return this.folderPathCache=e?.path||"",this.folderPathCache}async createSessionEvent(e,t){let r=(0,zG.v4)(),i=KG.DateFormatter.toLocalTimestamp(new Date),s={exo__Asset_uid:r,exo__Asset_createdAt:i,exo__Asset_isDefinedBy:this.vaultSettings.getOwnerIdentity(),exo__Instance_class:[`"[[${t}]]"`],ems__SessionEvent_timestamp:i,ems__Session_area:`"[[${e}]]"`},o=YG.MetadataHelpers.buildFileContent(s),c=this.getSessionEventFolder();c&&!await this.vault.exists(c)&&await this.vault.createFolder(c);let l=c?`${c}/${r}.md`:`${r}.md`;return await this.vault.create(l,o)}};Gi.SessionEventService=Dv;Gi.SessionEventService=Dv=WG([(0,Pv.injectable)(),SP(0,(0,Pv.inject)(vP.DI_TOKENS.IVaultAdapter)),SP(1,(0,Pv.inject)(vP.DI_TOKENS.IVaultSettings)),HG("design:paramtypes",[Object,Object])],Dv)});var kv=T(Wi=>{"use strict";var XG=Wi&&Wi.__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},QG=Wi&&Wi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},EP=Wi&&Wi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Wi,"__esModule",{value:!0});Wi.URIConstructionService=void 0;var Lv=Je(),TP=Wt(),JG=ll(),Nv=class{static{a(this,"URIConstructionService")}constructor(e,t=JG.NullLogger){this.fileSystem=e,this.logger=t,this.defaultOntologyURL="https://exocortex.my/default/",this.strictValidation=!0}configure(e){e?.defaultOntologyURL&&(this.defaultOntologyURL=e.defaultOntologyURL),e?.strictValidation!==void 0&&(this.strictValidation=e.strictValidation)}async constructAssetURI(e){let t=this.extractUID(e);if(!t){if(this.strictValidation)throw new Error(`Asset missing exo__Asset_uid: ${e.path}`);return this.logger.warn(`Asset ${e.path} missing UID, using filename fallback`),this.constructFallbackURI(e)}let r=await this.resolveOntologyURL(e);if(!this.validateOntologyURL(r))throw new Error(`Invalid ontology URL: ${r}`);return`${r.endsWith("/")?r:`${r}/`}${t}`}validateOntologyURL(e){if(!e)return!1;try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}}async resolveOntologyURL(e){let t=e.frontmatter?.exo__Asset_isDefinedBy;if(!t||typeof t!="string")return this.defaultOntologyURL;let r=this.extractWikiLink(t),i=r,s=await this.fileSystem.fileExists(r);return!s&&!r.endsWith(".md")&&(i=`${r}.md`,s=await this.fileSystem.fileExists(i)),s?(await this.fileSystem.getFileMetadata(i))?.exo__Ontology_url||this.defaultOntologyURL:(this.logger.warn(`Ontology file not found: ${r}, using default`),this.defaultOntologyURL)}extractUID(e){let t=e.frontmatter?.exo__Asset_uid;return typeof t=="string"?t:null}extractWikiLink(e){return e.replace(/^\[\[|\]\]$/g,"")}constructFallbackURI(e){let t=e.path.split("/").pop()?.replace(".md","")||"unknown";return`${this.defaultOntologyURL}${t}`}};Wi.URIConstructionService=Nv;Wi.URIConstructionService=Nv=XG([(0,Lv.injectable)(),EP(0,(0,Lv.inject)(TP.DI_TOKENS.IFileSystemAdapter)),EP(1,(0,Lv.inject)(TP.DI_TOKENS.ILogger)),QG("design:paramtypes",[Object,Object])],Nv)});var jv=T(Hi=>{"use strict";var ZG=Hi&&Hi.__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},eW=Hi&&Hi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},tW=Hi&&Hi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Hi,"__esModule",{value:!0});Hi.GenericAssetCreationService=void 0;var IP=Je(),id=zr(),rW=wo(),nW=ws(),iW=Jt(),sW=Wt(),Ps=vp(),oW=Wf(),aW=Ym(),Mv=class{static{a(this,"GenericAssetCreationService")}constructor(e){this.vault=e,this.clock=(0,oW.liveClock)(),this.uidGen=(0,aW.liveUidGenerator)()}withDeterminism(e){return e.clock&&(this.clock=e.clock),e.uidGenerator&&(this.uidGen=e.uidGenerator),this}async createAsset(e,t){let{folderPath:r,path:i,content:s}=this.buildAsset(e,t);return this.vault.getAbstractFileByPath(r)||await this.vault.createFolder(r),await this.vault.create(i,s)}buildAsset(e,t){let r=this.uidGen.next(),i=this.generateFrontmatter(e,t||[],r),s=rW.MetadataHelpers.buildFileContent(i,e.body),o=e.folderPath||this.getDefaultFolderPath(e),c=`${r}.md`,l=o?`${o}/${c}`:c;return{uid:r,folderPath:o,path:l,frontmatter:i,content:s}}generateFrontmatter(e,t=[],r=this.uidGen.next()){let i={},s=new Map;for(let u of t)s.set(u.name,u.fieldType);i.exo__Asset_uid=r;let o=e.timezone?this.generateTimestampInTimezone(e.timezone):id.DateFormatter.toLocalTimestamp(this.clock.now());i.exo__Asset_createdAt=o,i.exo__Asset_updatedAt=o;let c=e.classRefForm==="uuid"&&e.classUid?e.classUid:e.className;i.exo__Instance_class=[this.formatWikilink(c)];let l=e.propertyValues?.exo__Instance_class;if(l!=null){let u=i.exo__Instance_class,f=Array.isArray(l)?l:[l];for(let d of f){if(d==null||String(d).trim()==="")continue;let h=this.formatWikilink(String(d));u.includes(h)||u.push(h)}}if(e.createdBy&&e.createdBy.trim()!==""&&(i.exo__Asset_createdBy=this.formatWikilink(e.createdBy.trim())),e.label&&e.label.trim()!==""){let u=e.label.trim();i.exo__Asset_label=u;let f=[u];if(e.aliases)for(let d of e.aliases)f.includes(d)||f.push(d);i.aliases=f}if(e.parentFile&&e.parentMetadata&&this.inheritParentContext(i,e),e.propertyValues){for(let[u,f]of Object.entries(e.propertyValues))if(!(u==="exo__Asset_uid"||u==="exo__Asset_createdAt"||u==="exo__Asset_updatedAt"||u==="exo__Asset_createdBy"||u==="exo__Instance_class"||u==="exo__Asset_label"||u==="aliases")&&f!=null)if(e.shapeRegistry!==void 0)Array.isArray(f)?i[u]=f.map(d=>this.quoteWikilinkValue(String(d))):i[u]=this.formatPropertyValueWithCardinality(u,String(f),e.shapeRegistry);else{let d=s.get(u);i[u]=this.formatValue(f,d)}}return i}inheritParentContext(e,t){let r=t.parentMetadata||{},i=t.parentFile?.basename;if(t.className==="ems__Task"||t.className.startsWith("ems__Task")){let s=r.exo__Instance_class,c=this.isAreaClass(s,t.classResolver)?"ems__Effort_area":"ems__Effort_parent";e[c]=i?this.formatWikilink(i):null}if(t.className==="ems__Project"||t.className.startsWith("ems__Project")){let s=r.exo__Instance_class,c=this.isAreaClass(s,t.classResolver)?"ems__Effort_area":"ems__Effort_parent";e[c]=i?this.formatWikilink(i):null}if(r.exo__Asset_isDefinedBy){let s=r.exo__Asset_isDefinedBy;e.exo__Asset_isDefinedBy=typeof s=="string"?this.formatWikilink(s):s}}isAreaClass(e,t){if(!e)return!1;let r=Array.isArray(e)?e:[e],i=a(()=>null,"noopResolver");return r.some(s=>{let o=nW.WikiLinkHelpers.resolveSymbolic(String(s),t??i);return o.includes("Area")||o.includes("ems__Area")})}getDefaultFolderPath(e){if(e.parentFile?.parent?.path)return e.parentFile.parent.path;let t={ems__Task:"tasks",ems__Project:"projects",ems__Area:"areas",ems__Meeting:"meetings",exo__Event:"events",ims__Concept:"concepts"};if(t[e.className])return t[e.className];for(let[r,i]of Object.entries(t))if(e.className.startsWith(r))return i;return"assets"}formatValue(e,t){if(e==null)return null;if(!t)return this.formatInferredValue(e);switch(t){case Ps.PropertyFieldType.Text:return String(e);case Ps.PropertyFieldType.Wikilink:case Ps.PropertyFieldType.Reference:case Ps.PropertyFieldType.StatusSelect:case Ps.PropertyFieldType.SizeSelect:return this.formatWikilink(String(e));case Ps.PropertyFieldType.Number:return typeof e=="number"?e:Number(e)||0;case Ps.PropertyFieldType.Boolean:return this.formatBoolean(e);case Ps.PropertyFieldType.Date:case Ps.PropertyFieldType.DateTime:case Ps.PropertyFieldType.Timestamp:return this.formatTimestamp(e);default:return String(e)}}formatInferredValue(e){return typeof e=="boolean"||typeof e=="number"?e:e instanceof Date?id.DateFormatter.toLocalTimestamp(e):typeof e=="string"?e.startsWith("[[")||e.startsWith('"[[')?this.formatWikilink(e):e:String(e)}formatWikilink(e){return e.startsWith('"[[')&&e.endsWith(']]"')?e:e.startsWith("[[")&&e.endsWith("]]")?`"${e}"`:`"[[${e}]]"`}formatBoolean(e){if(typeof e=="boolean")return e;if(typeof e=="string"){let t=e.toLowerCase().trim();return t==="true"||t==="yes"||t==="1"}return typeof e=="number"?e!==0:!!e}formatTimestamp(e){if(e instanceof Date)return id.DateFormatter.toLocalTimestamp(e);if(typeof e=="string"){if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.test(e))return e;if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(e))return e.replace("Z","");let t=new Date(e);return isNaN(t.getTime())?e:id.DateFormatter.toLocalTimestamp(t)}if(typeof e=="number"){let t=new Date(e);if(!isNaN(t.getTime()))return id.DateFormatter.toLocalTimestamp(t)}return String(e)}formatPropertyValueWithCardinality(e,t,r){let i=this.quoteWikilinkValue(t);return i.includes("[[")&&this.shouldEmitAsArray(e,r)?[i]:i}quoteWikilinkValue(e){return e.includes("[[")?e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`:e}shouldEmitAsArray(e,t){if(!t)return!1;let r=iW.Namespace.fromPropertyKey(e);if(!r)return!1;let i=r.namespace.term(r.localName).value;return t.get(i)?.cardinality==="Multiple"}generateTimestampInTimezone(e){let t=this.clock.now(),i=new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(t),s=a(o=>i.find(c=>c.type===o)?.value||"00","get");return`${s("year")}-${s("month")}-${s("day")}T${s("hour")}:${s("minute")}:${s("second")}`}};Hi.GenericAssetCreationService=Mv;Hi.GenericAssetCreationService=Mv=ZG([(0,IP.injectable)(),tW(0,(0,IP.inject)(sW.DI_TOKENS.IVaultAdapter)),eW("design:paramtypes",[Object])],Mv)});var RP=T(zi=>{"use strict";var cW=zi&&zi.__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},lW=zi&&zi.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},uW=zi&&zi.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(zi,"__esModule",{value:!0});zi.ArchiveAssetService=void 0;var AP=Je(),fW=Wt(),dW=Os(),$v=class{static{a(this,"ArchiveAssetService")}constructor(e){this.vault=e,this.frontmatterService=new dW.FrontmatterService}async archiveAsset(e){let t=await this.vault.read(e),r=this.frontmatterService.updateProperty(t,"archived","true");r=this.frontmatterService.removeProperty(r,"aliases"),r!==t&&await this.vault.modify(e,r)}};zi.ArchiveAssetService=$v;zi.ArchiveAssetService=$v=cW([(0,AP.injectable)(),uW(0,(0,AP.inject)(fW.DI_TOKENS.IVaultAdapter)),lW("design:paramtypes",[Object])],$v)});var CP=T(Ki=>{"use strict";var hW=Ki&&Ki.__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},pW=Ki&&Ki.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)},mW=Ki&&Ki.__param||function(n,e){return function(t,r){e(t,r,n)}};Object.defineProperty(Ki,"__esModule",{value:!0});Ki.FixMissingLabelService=void 0;var OP=Je(),gW=Wt(),yW=Os(),Uv=class{static{a(this,"FixMissingLabelService")}constructor(e){this.vault=e,this.frontmatterService=new yW.FrontmatterService}async fixMissingLabel(e){let t=await this.vault.read(e);if(this.hasNonEmptyLabel(t))return;let r=this.frontmatterService.updateProperty(t,"exo__Asset_label",e.basename);r!==t&&await this.vault.modify(e,r)}hasNonEmptyLabel(e){let t=this.frontmatterService.parse(e);if(!t.exists)return!1;let r=t.content.match(/^exo__Asset_label:\s*(.*)$/m);if(!r)return!1;let i=r[1].trim();return!(i===""||i==='""'||i==="''")}};Ki.FixMissingLabelService=Uv;Ki.FixMissingLabelService=Uv=hW([(0,OP.injectable)(),mW(0,(0,OP.inject)(gW.DI_TOKENS.IVaultAdapter)),pW("design:paramtypes",[Object])],Uv)});var xP=T(Do=>{"use strict";var _W=Do&&Do.__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},bW=Do&&Do.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Do,"__esModule",{value:!0});Do.GraphQueryService=void 0;var SW=Je(),sd=ze(),wW=et(),ba=Jt(),vW=Eb(),Ds={INSTANCE_CLASS:ba.Namespace.EXO.term("Instance_class"),ASSET_LABEL:ba.Namespace.EXO.term("Asset_label"),ASSET_PROTOTYPE:ba.Namespace.EXO.term("Asset_prototype"),ASSET_IS_ARCHIVED:ba.Namespace.EXO.term("Asset_isArchived"),EFFORT_PARENT:ba.Namespace.EMS.term("Effort_parent"),REFERENCES:ba.Namespace.EXO.term("references"),REFERENCED_BY:ba.Namespace.EXO.term("referencedBy"),RDF_TYPE:ba.Namespace.RDF.term("type")},Bv=class{static{a(this,"GraphQueryService")}constructor(e,t={},r){this.subscribers=new Set,this.nodeCache=new Map,this.lastCacheUpdate=0,this.tripleStore=e,this.logger=r,this.config={defaultLimit:t.defaultLimit??100,maxLimit:t.maxLimit??1e4,defaultDepth:t.defaultDepth??2,maxDepth:t.maxDepth??10,includeArchivedByDefault:t.includeArchivedByDefault??!1,cacheTTL:t.cacheTTL??3e4}}async loadGraphData(e={}){let t=Date.now(),r=await this.loadNodes(e),i=await this.loadEdges(r,e),s=this.computeStats(r,i),o=Date.now()-t;return o>100&&r.length>0&&this.logger?.debug(`GraphQueryService: loaded ${r.length} nodes in ${o}ms (${(o/r.length).toFixed(2)}ms/node)`),{nodes:r,edges:i,stats:s,lastUpdated:Date.now(),version:1}}async loadNodesIncremental(e={}){let t=Math.min(e.limit??this.config.defaultLimit,this.config.maxLimit),r=e.offset??0,i=await this.loadNodes({...e,limit:t+1,offset:r}),s=i.length>t,o=s?i.slice(0,t):i,c=await this.loadEdges(o,e);return{nodes:o,edges:c,hasMore:s,totalCount:void 0,cursor:s?String(r+t):void 0}}async loadConnectedNodes(e,t={}){let r=Math.min(t.depth??this.config.defaultDepth,this.config.maxDepth),i=Math.min(t.limit??this.config.maxLimit,this.config.maxLimit),s=new Set,o=[{id:e,currentDepth:0}],c=[];for(;o.length>0&&c.length<i;){let u=o.shift();if(!u)break;let{id:f,currentDepth:d}=u;if(s.has(f))continue;s.add(f);let h=await this.getNodeById(f,t);if(h&&(c.push(h),d<r)){let p=await this.getConnectedNodeIds(f);for(let y of p)s.has(y)||o.push({id:y,currentDepth:d+1})}}let l=await this.loadEdges(c,t);return{nodes:c,edges:l,hasMore:o.length>0,totalCount:s.size+o.length}}async getNodeById(e,t={}){let r=this.getCachedNode(e);if(r)return{...r};let i=this.idToIRI(e),s=await this.tripleStore.match(i,void 0,void 0);if(s.length===0)return null;let o=this.triplesToNode(e,s,t);return o&&this.cacheNode(o),o}subscribe(e){return this.subscribers.add(e),{unsubscribe:a(()=>{this.subscribers.delete(e)},"unsubscribe")}}notifyChange(e){for(let t of this.subscribers)try{t(e)}catch(r){this.logger?.error("GraphQueryService: error in subscriber callback",r instanceof Error?r:new Error(String(r)))}this.invalidateCache()}async getStats(){let e=await this.loadNodes({includeArchived:!0}),t=await this.loadEdges(e,{});return this.computeStats(e,t)}clearCache(){this.nodeCache.clear(),this.lastCacheUpdate=0}async loadNodes(e){let t=e.includeArchived??this.config.includeArchivedByDefault,r=e.limit??this.config.maxLimit,i=e.offset??0,s=await this.tripleStore.match(void 0,Ds.INSTANCE_CLASS,void 0),o=s;if(e.classes&&e.classes.length>0){let p=new Set(e.classes);o=s.filter(y=>{let _=this.getObjectValue(y.object);return _&&p.has(_)})}let c=new Set;for(let p of o)c.add(this.subjectToId(p.subject));let f=Array.from(c).slice(i,i+r).map(p=>this.getNodeById(p,e));return(await Promise.all(f)).filter(p=>!(!p||!t&&p.isArchived))}async loadEdges(e,t){let r=new Set(e.map(o=>o.id)),i=[],s=new Set;for(let o of e){let c=this.idToIRI(o.id),l=await this.tripleStore.match(c,void 0,void 0);for(let u of l){let f=this.tripleToEdge(o.id,u,r);f&&f.id&&!s.has(f.id)&&(!t.edgeTypes||t.edgeTypes.includes(f.type))&&(s.add(f.id),i.push(f))}}return i}async getConnectedNodeIds(e){let t=this.idToIRI(e),r=[],i=await this.tripleStore.match(t,void 0,void 0);for(let o of i){let c=this.objectToId(o.object);c&&r.push(c)}let s=await this.tripleStore.match(void 0,void 0,t);for(let o of s)r.push(this.subjectToId(o.subject));return[...new Set(r)]}triplesToNode(e,t,r){let i={},s,o,c,l,u=!1;for(let h of t){let p=h.predicate.value,y=this.getObjectValue(h.object);if(p===Ds.INSTANCE_CLASS.value)s=y;else if(p===Ds.ASSET_LABEL.value)o=y;else if(p===Ds.ASSET_PROTOTYPE.value)c=this.objectToId(h.object)??y;else if(p===Ds.EFFORT_PARENT.value)l=this.objectToId(h.object)??y;else if(p===Ds.ASSET_IS_ARCHIVED.value)u=y==="true"||y==="1";else{let _=this.predicateToPropertyName(p);_&&(i[_]=y)}}if(u&&!(r.includeArchived??this.config.includeArchivedByDefault))return null;let f=this.idToPath(e),d=o??this.pathToTitle(f);return{id:e,path:f,title:d,label:d,assetClass:s,isArchived:u,uri:e.startsWith("http")?e:void 0,prototype:c,parent:l,properties:Object.keys(i).length>0?i:void 0}}tripleToEdge(e,t,r){let i=t.predicate.value,s=this.objectToId(t.object);if(!s||!r.has(s)||s===e)return null;let o=this.predicateToEdgeType(i);if(!o)return null;let c=(0,vW.createEdgeId)(e,s,o,i),l=this.predicateToLabel(i);return{id:c,source:e,target:s,type:o,predicate:i,label:l}}predicateToEdgeType(e){return e===Ds.EFFORT_PARENT.value?"hierarchy":e===Ds.ASSET_PROTOTYPE.value?"prototype":e===Ds.REFERENCES.value?"forward-link":e===Ds.REFERENCED_BY.value?"backlink":e.includes("Asset_")||e.includes("Instance_")?null:"semantic"}predicateToLabel(e){let t=e.lastIndexOf("#"),r=e.lastIndexOf("/"),i=Math.max(t,r);return i>=0?e.substring(i+1):e}predicateToPropertyName(e){return this.predicateToLabel(e).replace(/_/g,"__").replace(/#/g,"_")}computeStats(e,t){let r={},i={backlink:0,"forward-link":0,hierarchy:0,prototype:0,semantic:0,reference:0};for(let c of e){let l=c.assetClass??"unknown";r[l]=(r[l]??0)+1}for(let c of t)i[c.type]=(i[c.type]??0)+1;let s=new Map,o=new Map;for(let c of t)o.set(c.source,(o.get(c.source)??0)+1),s.set(c.target,(s.get(c.target)??0)+1);for(let c of e)c.inDegree=s.get(c.id)??0,c.outDegree=o.get(c.id)??0,c.weight=c.inDegree+c.outDegree;return{nodeCount:e.length,edgeCount:t.length,nodesByClass:r,edgesByType:i,computedAt:Date.now()}}idToIRI(e){return e.startsWith("http://")||e.startsWith("https://")?new sd.IRI(e):new sd.IRI(`obsidian://vault/${encodeURIComponent(e)}`)}subjectToId(e){if(e instanceof sd.IRI){let t=e.value;return t.startsWith("obsidian://vault/")?decodeURIComponent(t.replace("obsidian://vault/","")):t}return e.toString()}objectToId(e){if(e instanceof sd.IRI){let t=e.value;return t.startsWith("obsidian://vault/")?decodeURIComponent(t.replace("obsidian://vault/","")):t}return null}getObjectValue(e){if(e instanceof wW.Literal||e instanceof sd.IRI)return e.value}idToPath(e){if(e.startsWith("obsidian://vault/"))return decodeURIComponent(e.replace("obsidian://vault/",""));if(e.startsWith("http://")||e.startsWith("https://")){let t=e.match(/\/([^/]+\.md)$/);if(t)return t[1]}return e}pathToTitle(e){return(e.split("/").pop()??e).replace(/\.md$/,"")}getCachedNode(e){return Date.now()-this.lastCacheUpdate>this.config.cacheTTL?(this.clearCache(),null):this.nodeCache.get(e)??null}cacheNode(e){this.nodeCache.set(e.id,e),this.lastCacheUpdate===0&&(this.lastCacheUpdate=Date.now())}invalidateCache(){this.clearCache()}};Do.GraphQueryService=Bv;Do.GraphQueryService=Bv=_W([(0,SW.injectable)(),bW("design:paramtypes",[Object,Object,Object])],Bv)});var DP=T(Fo=>{"use strict";var EW=Fo&&Fo.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(o=n[c])&&(s=(i<3?o(s):i>3?o(e,t,s):o(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},TW=Fo&&Fo.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Fo,"__esModule",{value:!0});Fo.TypeRegistry=void 0;var IW=Je(),Fs=ze(),PP=qt(),AW=et(),RW=ga(),Tt=Tb(),Vv=class{static{a(this,"TypeRegistry")}constructor(e=null,t={}){this.nodeTypes=new Map,this.edgeTypes=new Map,this.typeHierarchy=new Map,this.subscribers=new Set,this.discoveryComplete=!1,this.tripleStore=e,this.config={autoDiscoverTypes:t.autoDiscoverTypes??!0,includeBuiltInStyles:t.includeBuiltInStyles??!0,styleResolution:t.styleResolution??{mergeStyles:!0,inheritParentStyles:!0,defaultNodeStyle:Tt.DEFAULT_NODE_STYLE,defaultEdgeStyle:Tt.DEFAULT_EDGE_STYLE},maxInheritanceDepth:t.maxInheritanceDepth??10},this.config.includeBuiltInStyles&&this.registerBuiltInTypes()}registerNodeType(e){let r=this.nodeTypes.get(e.uri)?"type-updated":"type-added";this.nodeTypes.set(e.uri,e),e.parentTypes&&e.parentTypes.length>0&&this.typeHierarchy.set(e.uri,e.parentTypes),this.emit({type:r,typeUri:e.uri,definition:e})}registerEdgeType(e){let r=this.edgeTypes.get(e.uri)?"type-updated":"type-added";this.edgeTypes.set(e.uri,e),this.emit({type:r,typeUri:e.uri,definition:e})}unregisterType(e){let t=this.nodeTypes.delete(e),r=this.edgeTypes.delete(e);this.typeHierarchy.delete(e),(t||r)&&this.emit({type:"type-removed",typeUri:e})}getNodeType(e){return this.nodeTypes.get(e)}getEdgeType(e){return this.edgeTypes.get(e)}getAllNodeTypes(){return Array.from(this.nodeTypes.values())}getAllEdgeTypes(){return Array.from(this.edgeTypes.values())}getParentTypes(e,t=this.config.maxInheritanceDepth){let r=[],i=new Set,s=[{uri:e,currentDepth:0}];for(;s.length>0;){let o=s.shift();if(!o)break;let{uri:c,currentDepth:l}=o;if(i.has(c)||(i.add(c),l>=t))continue;let u=this.typeHierarchy.get(c)??[];for(let f of u)i.has(f)||(r.push(f),s.push({uri:f,currentDepth:l+1}))}return r}getChildTypes(e){let t=[];for(let[r,i]of this.typeHierarchy)i.includes(e)&&t.push(r);return t}isSubtypeOf(e,t){return e===t?!0:this.getParentTypes(e).includes(t)}resolveNodeType(e){let t=[],r="unknown",i="custom";if(e.assetClass){let c=this.normalizeTypeUri(e.assetClass);t.push(c),r=c,i="exo:Instance_class"}let s=e.properties?.[Tt.RDF_TYPE_PREDICATES.RDF_TYPE];s&&!t.includes(s)&&(t.push(s),r==="unknown"&&(r=s,i="rdf:type"));for(let c of[...t]){let l=this.getParentTypes(c);for(let u of l)t.includes(u)||t.push(u)}let o=this.resolveNodeStyle(t);return{primaryType:r,types:t,resolvedStyle:o,source:i}}resolveEdgeType(e){let t=e.predicate??e.type,r=e.predicate?"rdf:type":"custom",i=this.resolveEdgeStyle(t);return{primaryType:t,resolvedStyle:i,source:r}}resolveNodeStyle(e){let{mergeStyles:t,defaultNodeStyle:r}=this.config.styleResolution,i={...r},s=[];for(let o of e){let c=this.nodeTypes.get(o);c&&s.push(c)}if(s.sort((o,c)=>o.priority-c.priority),t)for(let o of s)i=(0,Tt.mergeNodeStyles)(i,o.style);else if(s.length>0){let o=s[s.length-1];i=(0,Tt.mergeNodeStyles)(i,o.style)}return i}resolveEdgeStyle(e){let{defaultEdgeStyle:t}=this.config.styleResolution,r={...t},i=this.edgeTypes.get(e);return i&&(r=(0,Tt.mergeEdgeStyles)(r,i.style)),r}filterNodes(e,t){return e.filter(r=>{let i=this.resolveNodeType(r);return!(t.includeNodeTypes&&t.includeNodeTypes.length>0&&!t.includeNodeTypes.some(o=>i.types.includes(o)||t.includeInferred&&this.isSubtypeOf(i.primaryType,o))||t.excludeNodeTypes&&t.excludeNodeTypes.length>0&&t.excludeNodeTypes.some(o=>i.types.includes(o)||t.includeInferred&&this.isSubtypeOf(i.primaryType,o))||!t.includeDeprecated&&this.nodeTypes.get(i.primaryType)?.deprecated)})}filterEdges(e,t){return e.filter(r=>{let i=r.predicate??r.type;return!(t.includeEdgeTypes&&t.includeEdgeTypes.length>0&&!t.includeEdgeTypes.includes(i)||t.excludeEdgeTypes&&t.excludeEdgeTypes.length>0&&t.excludeEdgeTypes.includes(i))})}groupNodesByType(e,t,r={}){let{groupByNodeType:i=!0,groupByParentType:s=!1,groupLevel:o=0,maxGroups:c=20,customGroupFn:l}=r,u=new Map;for(let h of e){let p=this.resolveNodeType(h),y;if(l?y=l(p.types):s&&p.types.length>o?y=p.types[o]??p.primaryType:i?y=p.primaryType:y="all",!u.has(y)){let S=this.nodeTypes.get(y)?.label??(0,Tt.extractLocalName)(y);u.set(y,{nodeIds:new Set,label:S})}let _=u.get(y);_&&_.nodeIds.add(h.id)}let f=Array.from(u.entries()).map(([h,p])=>({id:h,label:p.label,nodeIds:Array.from(p.nodeIds)}));if(f.length>c){f.sort((y,_)=>_.nodeIds.length-y.nodeIds.length);let h=f.slice(0,c-1),p=f.slice(c-1).flatMap(y=>y.nodeIds);h.push({id:"other",label:"Other",nodeIds:p}),f=h}let d=new Map;for(let h of f)for(let p of h.nodeIds)d.set(p,h.id);return f.map((h,p)=>{let y=new Set(h.nodeIds),_=[],w=[];for(let x of t){let O=y.has(x.source),C=y.has(x.target);O&&C?x.id&&_.push(x.id):(O||C)&&x.id&&w.push(x.id)}let E=`hsl(${p*137.5%360}, 70%, 50%)`;return{id:h.id,label:h.label,nodeIds:h.nodeIds,internalEdgeIds:_,externalEdgeIds:w,color:E,stats:{nodeCount:h.nodeIds.length,internalEdgeCount:_.length,externalEdgeCount:w.length}}})}validateTypes(e,t){let r=[],i=[];for(let s of e){let o=this.resolveNodeType(s);if(o.primaryType!=="unknown"){let c=this.nodeTypes.get(o.primaryType);!c&&o.source!=="inferred"&&i.push({code:"UNREGISTERED_NODE_TYPE",message:`Node type "${o.primaryType}" is not registered`,elementId:s.id,suggestion:"Register the type with registerNodeType()"}),c?.deprecated&&i.push({code:"DEPRECATED_NODE_TYPE",message:`Node uses deprecated type "${o.primaryType}"`,elementId:s.id,suggestion:"Migrate to a non-deprecated type"})}else i.push({code:"MISSING_NODE_TYPE",message:"Node has no type information",elementId:s.id,suggestion:"Add exo:Instance_class or rdf:type to the node"})}for(let s of t){let o=s.predicate??s.type,c=this.edgeTypes.get(o);if(c?.domain&&c.domain.length>0){let l=e.find(u=>u.id===s.source);if(l){let u=this.resolveNodeType(l);c.domain.some(d=>u.types.includes(d))||r.push({code:"DOMAIN_VIOLATION",message:"Edge source does not match expected domain",elementId:s.id,expected:c.domain,actual:u.types})}}if(c?.range&&c.range.length>0){let l=e.find(u=>u.id===s.target);if(l){let u=this.resolveNodeType(l);c.range.some(d=>u.types.includes(d))||r.push({code:"RANGE_VIOLATION",message:"Edge target does not match expected range",elementId:s.id,expected:c.range,actual:u.types})}}}return{valid:r.length===0,errors:r,warnings:i}}async discoverTypes(){if(!this.tripleStore||this.discoveryComplete)return;let e=await this.tripleStore.match(void 0,new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDF_TYPE),void 0);for(let r of e){let i=this.getObjectValue(r.object);if(i&&(0,Tt.isClassType)(i)){let s=this.getSubjectValue(r.subject);s&&await this.discoverNodeType(s)}}let t=await this.tripleStore.match(void 0,new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_SUBCLASS_OF),void 0);for(let r of t){let i=this.getSubjectValue(r.subject),s=this.getObjectValue(r.object);if(i&&s){let o=this.typeHierarchy.get(i)??[];if(!o.includes(s)){o.push(s),this.typeHierarchy.set(i,o);let c=this.nodeTypes.get(i);c&&(c.parentTypes=o)}}}this.discoveryComplete=!0,this.emit({type:"hierarchy-updated",rootTypes:this.getRootTypes()})}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}clear(){this.nodeTypes.clear(),this.edgeTypes.clear(),this.typeHierarchy.clear(),this.discoveryComplete=!1,this.config.includeBuiltInStyles&&this.registerBuiltInTypes()}registerBuiltInTypes(){for(let[e,t]of Object.entries(Tt.BUILT_IN_NODE_STYLES))this.nodeTypes.set(e,{uri:e,label:(0,Tt.extractLocalName)(e),source:"custom",style:(0,Tt.mergeNodeStyles)(Tt.DEFAULT_NODE_STYLE,t),priority:1});for(let[e,t]of Object.entries(Tt.BUILT_IN_EDGE_STYLES))this.edgeTypes.set(e,{uri:e,label:(0,Tt.extractLocalName)(e),source:"custom",style:(0,Tt.mergeEdgeStyles)(Tt.DEFAULT_EDGE_STYLE,t),priority:1})}async discoverNodeType(e){if(this.nodeTypes.has(e)||!this.tripleStore)return;let t=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_LABEL),void 0),r=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDFS_COMMENT),void 0),i=t.length>0?this.getObjectValue(t[0].object)??(0,Tt.extractLocalName)(e):(0,Tt.extractLocalName)(e),s=r.length>0?this.getObjectValue(r[0].object):void 0,o="rdfs:Class",c=await this.tripleStore.match(new Fs.IRI(e),new Fs.IRI(Tt.RDF_TYPE_PREDICATES.RDF_TYPE),void 0);for(let f of c)if(this.getObjectValue(f.object)===Tt.RDF_TYPE_PREDICATES.OWL_CLASS){o="owl:Class";break}let l=Tt.BUILT_IN_NODE_STYLES[e]??Tt.BUILT_IN_NODE_STYLES[(0,Tt.extractLocalName)(e)],u={uri:e,label:i,description:s,source:o,style:(0,Tt.mergeNodeStyles)(Tt.DEFAULT_NODE_STYLE,l??{}),priority:1};this.registerNodeType(u)}normalizeTypeUri(e){let t=e.match(/^\[\[(.+?)\]\]$/);return t?t[1]:e}getSubjectValue(e){if(e instanceof Fs.IRI)return e.value;if(e instanceof PP.BlankNode)return`_:${e.id}`;if(typeof e=="object"&&e!==null&&"termType"in e)return e.toString()}getObjectValue(e){if(e instanceof AW.Literal||e instanceof Fs.IRI)return e.value;if(e instanceof PP.BlankNode)return`_:${e.id}`}getRootTypes(){let e=new Set;for(let r of this.typeHierarchy.values())for(let i of r)e.add(i);let t=[];for(let r of this.nodeTypes.keys()){let i=this.typeHierarchy.get(r);(!i||i.length===0)&&e.has(r)&&t.push(r)}return t}emit(e){for(let t of this.subscribers)try{t(e)}catch(r){RW.LoggingService.error("TypeRegistry: error in subscriber callback",r instanceof Error?r:new Error(String(r)))}}};Fo.TypeRegistry=Vv;Fo.TypeRegistry=Vv=EW([(0,IW.injectable)(),TW("design:paramtypes",[Object,Object])],Vv)});var FP=T(Ag=>{"use strict";Object.defineProperty(Ag,"__esModule",{value:!0});Ag.SPARQL_PREFIXES=void 0;Ag.SPARQL_PREFIXES=`PREFIX exo: <https://exocortex.my/ontology/exo#>
213
213
  PREFIX ems: <https://exocortex.my/ontology/ems#>
214
214
  PREFIX ims: <https://exocortex.my/ontology/ims#>
215
215
  PREFIX gtd: <https://exocortex.my/ontology/gtd#>
@@ -638,7 +638,7 @@ Duplicate bindings (${n.duplicates.length}) \u2014 uid claimed by >1 test (warni
638
638
  Skipped floor check for ${n.unknownPriority} requirement(s) with unparseable priority (fail-open).`),n.clean?e==="hard"&&!n.rampReady?console.error(`
639
639
  FAIL (hard gate): ramp not ready \u2014 ${n.p0Orphans} P0 requirement(s) unbound`+(n.p0Total===0?" (no P0 requirements found)":"")+"."):console.log(`
640
640
  OK: no hard findings (dangling tags + binding-class floor are clean).`):console.error(`
641
- FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s) + ${n.activeViolations.length} active-requirement invariant violation(s) + ${n.danglingEvidence.length} dangling evidence link(s).`)}a(Ioe,"renderText");function Aoe(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(Aoe,"isHardFail");function x9(){return new ke("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage, P0 ramp-readiness").requiredOption("--reqs <path>","Directory tree containing req__Requirement assets (a vault or a reqs assetspace clone)").option("--tests <path>","Test-corpus root scanned for @req:<uid> tags",".").option("--output <type>","Response format: text|json","text").option("--strict","Also exit 1 on orphan requirements",!1).option("--gate <mode>","Gate mode: soft (warn only on hard findings) | hard (also block when the P0 checklist is not ramp-ready)","soft").action(async n=>{let e=n.output??"text";be.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,qa.resolve)(n.reqs);if(!(0,Ga.existsSync)(r)||!(0,Ga.statSync)(r).isDirectory())throw new Qe(r);let i=(0,qa.resolve)(n.tests??".");if(!(0,Ga.existsSync)(i)||!(0,Ga.statSync)(i).isDirectory())throw new Qe(i);let[s,o]=await Promise.all([Soe(r),voe(i)]),c=Eoe(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):Ioe(c,t),Aoe(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){be.handle(r)}})}a(x9,"requirementsAuditCommand");function P9(){let n=new ke("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(x9()),n}a(P9,"requirementsCommand");function P_(n){let e=new ke;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(n??"16.176.0"),e.addCommand(R4()),e.addCommand(N4()),e.addCommand(Sj()),e.addCommand(Tj()),e.addCommand(Xj()),e.addCommand(Ij()),e.addCommand(Pj()),e.addCommand(Zj()),e.addCommand(c4()),e.addCommand(u4()),e.addCommand(T4()),e.addCommand(Q4()),e.addCommand(e9()),e.addCommand(g9()),e.addCommand(_9()),e.addCommand(w9()),e.addCommand(v9()),e.addCommand(A9()),e.addCommand(a9()),e.addCommand(h9()),e.addCommand(P9()),e}a(P_,"createProgram");P_().parse();0&&(module.exports={createProgram});
641
+ FAIL: ${n.dangling.length} dangling + ${n.floorViolations.length} floor violation(s) + ${n.activeViolations.length} active-requirement invariant violation(s) + ${n.danglingEvidence.length} dangling evidence link(s).`)}a(Ioe,"renderText");function Aoe(n,e,t){return!n.clean||t&&n.orphans.length>0||e==="hard"&&!n.rampReady}a(Aoe,"isHardFail");function x9(){return new ke("audit").description("Audit requirement\u2194test traceability: orphans, dangling @req tags, duplicate bindings, binding-class floor, coverage, P0 ramp-readiness").requiredOption("--reqs <path>","Directory tree containing req__Requirement assets (a vault or a reqs assetspace clone)").option("--tests <path>","Test-corpus root scanned for @req:<uid> tags",".").option("--output <type>","Response format: text|json","text").option("--strict","Also exit 1 on orphan requirements",!1).option("--gate <mode>","Gate mode: soft (warn only on hard findings) | hard (also block when the P0 checklist is not ramp-ready)","soft").action(async n=>{let e=n.output??"text";be.setFormat(e);let t=n.gate==="hard"?"hard":"soft";try{let r=(0,qa.resolve)(n.reqs);if(!(0,Ga.existsSync)(r)||!(0,Ga.statSync)(r).isDirectory())throw new Qe(r);let i=(0,qa.resolve)(n.tests??".");if(!(0,Ga.existsSync)(i)||!(0,Ga.statSync)(i).isDirectory())throw new Qe(i);let[s,o]=await Promise.all([Soe(r),voe(i)]),c=Eoe(s,o);e==="json"?console.log(JSON.stringify({...c,gate:t},null,2)):Ioe(c,t),Aoe(c,t,n.strict===!0)&&(process.exitCode=1)}catch(r){be.handle(r)}})}a(x9,"requirementsAuditCommand");function P9(){let n=new ke("requirements").description("Requirements-management tooling (RFC 0003): traceability checker");return n.addCommand(x9()),n}a(P9,"requirementsCommand");function P_(n){let e=new ke;return e.name("exocortex").description("CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more").version(n??"16.176.2"),e.addCommand(R4()),e.addCommand(N4()),e.addCommand(Sj()),e.addCommand(Tj()),e.addCommand(Xj()),e.addCommand(Ij()),e.addCommand(Pj()),e.addCommand(Zj()),e.addCommand(c4()),e.addCommand(u4()),e.addCommand(T4()),e.addCommand(Q4()),e.addCommand(e9()),e.addCommand(g9()),e.addCommand(_9()),e.addCommand(w9()),e.addCommand(v9()),e.addCommand(A9()),e.addCommand(a9()),e.addCommand(h9()),e.addCommand(P9()),e}a(P_,"createProgram");P_().parse();0&&(module.exports={createProgram});
642
642
  /*! Bundled license information:
643
643
 
644
644
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "16.176.0",
3
+ "version": "16.176.2",
4
4
  "description": "CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more",
5
5
  "main": "dist/index.js",
6
6
  "bin": {