@kitelev/exocortex-cli 15.105.4 → 15.105.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @kitelev/exocortex-cli v15.105.4
2
+ // @kitelev/exocortex-cli v15.105.5
3
3
  // CLI tool for Exocortex knowledge management system - SPARQL queries, task management, and more
4
4
  // License: MIT
5
5
 
@@ -88,7 +88,7 @@ ${Object.entries(t).map(([a,c])=>this.serializeValue(a,c)).join(`
88
88
  ${r}`}return`${e}: ${String(t)}`}escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}};cp.FrontmatterService=Pu;Pu.FRONTMATTER_REGEX=/^---\n([\s\S]*?)\n---/;Pu.IRI_PREFIX_MAP={"https://exocortex.my/ontology/ems#":"ems__","https://exocortex.my/ontology/exo#":"exo__","https://exocortex.my/ontology/exocmd#":"exocmd__","https://exocortex.my/ontology/ims#":"ims__","https://exocortex.my/ontology/ztlk#":"ztlk__","https://exocortex.my/ontology/ptms#":"ptms__","https://exocortex.my/ontology/lit#":"lit__","https://exocortex.my/ontology/inbox#":"inbox__"}});var Vr=v(lp=>{"use strict";Object.defineProperty(lp,"__esModule",{value:!0});lp.DateFormatter=void 0;var e_=class n{static{o(this,"DateFormatter")}static toISOTimestamp(e){return e.toISOString().replace(/\.\d{3}Z$/,"Z")}static toLocalTimestamp(e){let t=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0"),s=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0");return`${t}-${r}-${i}T${s}:${a}:${c}`}static toDateWikilink(e){let t=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`"[[${t}-${r}-${i}]]"`}static getTodayWikilink(){return n.toDateWikilink(new Date)}static toDateString(e){let t=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${t}-${r}-${i}`}static parseWikilink(e){let r=e.replace(/^["']|["']$/g,"").match(/\[\[(\d{4}-\d{2}-\d{2})\]\]/);return r?r[1]:null}static addDays(e,t){let r=new Date(e);return r.setDate(r.getDate()+t),r}static isSameDay(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}static getTodayStartTimestamp(){let e=new Date;return e.setHours(0,0,0,0),n.toLocalTimestamp(e)}static toTimestampAtStartOfDay(e){let t=e.split("-").map(Number);if(t.length!==3||t.some(isNaN))throw new Error(`Invalid date format: ${e}. Expected YYYY-MM-DD`);let[r,i,s]=t,a=new Date(r,i-1,s,0,0,0,0);if(isNaN(a.getTime()))throw new Error(`Invalid date values: ${e}`);return n.toLocalTimestamp(a)}static normalizeTimestamp(e){if(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(e))return e;let t=new Date(e);if(isNaN(t.getTime()))throw new Error(`Invalid timestamp format: ${e}`);return n.toISOTimestamp(t)}static isISOTimestamp(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(e)}};lp.DateFormatter=e_});var ya=v(up=>{"use strict";Object.defineProperty(up,"__esModule",{value:!0});up.LoggingService=void 0;var Du=class{static{o(this,"LoggingService")}static setVerbose(e){this.isVerbose=e}static setDevelopmentMode(e){this.isDevelopment=e}static checkIsDevelopment(){return this.isDevelopment!==void 0?this.isDevelopment:typeof process<"u"?(this.isDevelopment=!1,this.isDevelopment):(this.isDevelopment=!1,this.isDevelopment)}static debug(e,t){this.isVerbose&&console.debug(`[Exocortex] ${e}`,t??"")}static info(e,t){console.log(`[Exocortex] ${e}`,t??"")}static warn(e,t){console.warn(`[Exocortex] ${e}`,t??"")}static error(e,t,r){let i=this.checkIsDevelopment(),s=r?` [${r}]`:"";if(i){let a=t?.stack?`
89
89
  Stack trace:
90
90
  ${t.stack}`:"";console.error(`[Exocortex ERROR]${s} ${e}${a}`,t??"")}else{let a=t?.message?`
91
- Details: ${t.message}`:"";console.error(`[Exocortex ERROR]${s} ${e}${a}`)}}};up.LoggingService=Du;Du.isVerbose=!1;Du.isDevelopment=void 0});var u3=v(ii=>{"use strict";var UM=ii&&ii.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},BM=ii&&ii.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(ii,"__esModule",{value:!0});ii.GroundingExecutor=ii.ServiceRegistry=void 0;var qM=ve(),WM=gn(),po=rc(),GM=Yi(),zM=Vr(),HM=ya(),fp=class{static{o(this,"ServiceRegistry")}constructor(){this.services=new Map}register(e,t){this.services.set(e,t)}get(e){return this.services.get(e)}has(e){return this.services.has(e)}getRegisteredIds(){return Array.from(this.services.keys())}};ii.ServiceRegistry=fp;var l3=20,t_=class{static{o(this,"GroundingExecutor")}constructor(e,t,r){this.frontmatterService=new GM.FrontmatterService,this.fileReader=e,this.fileWriter=t,this.serviceRegistry=r}async execute(e,t,r,i){try{switch(e.type){case po.GroundingType.PROPERTY_SET:return await this.executePropertySet(e,t,r,i);case po.GroundingType.PROPERTY_DELETE:return await this.executePropertyDelete(e,r);case po.GroundingType.COMPOSITE:return await this.executeComposite(e,t,r,i,0);case po.GroundingType.SERVICE_CALL:return await this.executeServiceCall(e,t,r,i);case po.GroundingType.CREATE_INSTANCE:return await this.executeCreateInstance(e,t,i);case po.GroundingType.SPARQL_UPDATE:return{success:!1,error:"sparql_update grounding not yet implemented. Use property_set/property_delete instead."};default:return{success:!1,error:`Unknown grounding type: ${e.type}`}}}catch(s){return{success:!1,error:s instanceof Error?s.message:String(s)}}}async executePropertySet(e,t,r,i){if(!e.targetProperty)return{success:!1,error:"property_set requires targetProperty"};if(e.targetValue===void 0)return{success:!1,error:"property_set requires targetValue"};if(/\$(input|value)\b/.test(e.targetValue)&&(i===void 0||i.value===void 0||i.value===null))return{success:!1,error:"property_set: targetValue contains $input/$value placeholder but no userInput.value provided"};let a=this.substituteVariables(e.targetValue,t,i),c=await this.fileReader.readFile(r),l=this.frontmatterService.updateProperty(c,e.targetProperty,a);return await this.fileWriter.updateFile(r,l),{success:!0}}async executePropertyDelete(e,t){if(!e.targetProperty)return{success:!1,error:"property_delete requires targetProperty"};let r=await this.fileReader.readFile(t),i=this.frontmatterService.removeProperty(r,e.targetProperty);return await this.fileWriter.updateFile(t,i),{success:!0}}async executeComposite(e,t,r,i,s){if(s>=l3)return{success:!1,error:`Composite grounding exceeded maximum depth of ${l3}`};let a=e.steps??[];if(a.length===0)return{success:!0};let c;try{c=await this.fileReader.readFile(r)}catch{}let l=[];try{for(let u=0;u<a.length;u++){let f=a[u],d=await this.executeStep(f,t,r,i,s+1);if(!d.success)return await this.rollback(c,r,l),{success:!1,error:`Composite step ${u} failed: ${d.error}`};l.push(u)}return{success:!0}}catch(u){return await this.rollback(c,r,l),{success:!1,error:`Composite execution failed: ${u instanceof Error?u.message:String(u)}`}}}async executeServiceCall(e,t,r,i){let s=e.targetProperty;if(!s)return{success:!1,error:"service_call requires targetProperty as serviceId"};if(s==="convertToTask")return await this.executeConvertToTask(r);let a=this.serviceRegistry.get(s);if(!a)return{success:!1,error:`Service not found: "${s}". Registered services: ${this.serviceRegistry.getRegisteredIds().join(", ")||"none"}`};let c=i;if(e.targetValue)try{let l=JSON.parse(e.targetValue);typeof l=="object"&&l!==null&&(c={...l,...i??{}})}catch{}return await a.execute(t,c),{success:!0}}async executeConvertToTask(e){let t=await this.fileReader.readFile(e),r=this.frontmatterService.updateProperty(t,"exo__Instance_class",'["[[ems__Task]]"]');return await this.fileWriter.updateFile(e,r),{success:!0}}async executeCreateInstance(e,t,r){if(!e.targetFolder)return{success:!1,error:"create_instance requires targetFolder"};let i=(0,WM.v4)(),s=r?.label??"Untitled",a={exo__Asset_uid:i,exo__Asset_createdAt:new Date().toISOString(),exo__Asset_label:s};if(s!=="Untitled"&&(a.aliases=[s]),e.targetClass&&(a.exo__Instance_class=[`"[[${e.targetClass}]]"`]),e.targetPrototype&&(a.exo__Asset_prototype=`"[[${e.targetPrototype}]]"`),t&&(a.exo__Asset_source=`"[[${t}]]"`),r)for(let[u,f]of Object.entries(r))u!=="label"&&f!=null&&(a[u]=f);let c=this.frontmatterService.createFrontmatter("",a),l=`${e.targetFolder}/${i}.md`;return await this.fileWriter.createFile(l,c),{success:!0}}async executeStep(e,t,r,i,s){return e.type===po.GroundingType.COMPOSITE?this.executeComposite(e,t,r,i,s):this.execute(e,t,r,i)}async rollback(e,t,r){if(e!==void 0)try{await this.fileWriter.updateFile(t,e)}catch(i){HM.LoggingService.error(`[GroundingExecutor] Rollback failed for ${t}`,i instanceof Error?i:new Error(String(i)))}}substituteVariables(e,t,r){let i=new Date,s=i.toISOString(),a=zM.DateFormatter.toLocalTimestamp(i),c=s.slice(0,10),l=e.replace(/\$target/g,t).replace(/\$nowLocal/g,a).replace(/\$now/g,s).replace(/\$today/g,c);if(r?.value!==void 0&&r.value!==null){let u=String(r.value);l=l.replace(/\$input\b/g,u).replace(/\$value\b/g,u)}return l}};ii.GroundingExecutor=t_;ii.GroundingExecutor=t_=UM([(0,qM.injectable)(),BM("design:paramtypes",[Object,Object,fp])],t_)});var Fu=v(Fs=>{"use strict";var QM=Fs&&Fs.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},YM=Fs&&Fs.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Fs,"__esModule",{value:!0});Fs.WorkflowEngine=void 0;var XM=ve(),r_=class{static{o(this,"WorkflowEngine")}constructor(e){this.definition=e}getAvailableTransitions(e){return this.definition.transitions.filter(t=>t.from===e&&!t.isRollback)}getRollbackTransitions(e){return this.definition.transitions.filter(t=>t.from===e&&t.isRollback)}getAllTransitions(e){return this.definition.transitions.filter(t=>t.from===e)}canTransition(e,t){return this.definition.transitions.some(r=>r.from===e&&r.to===t)}getPreviousStatus(e){return this.definition.transitions.find(r=>r.from===e&&r.isRollback)?.to??null}getNextStates(e){return this.getAvailableTransitions(e).map(t=>t.to)}isTerminalState(e){return this.definition.terminalStates.includes(e)}isInitialState(e){return this.definition.initialState===e}getTimestampsForStatus(e){return this.definition.states.find(r=>r.status===e)?.timestampOnEnter??[]}getTransition(e,t){return this.definition.transitions.find(r=>r.from===e&&r.to===t)}getOrderedStates(){return this.definition.states.map(e=>e.status)}getDefinition(){return this.definition}validate(){let e=[],t=new Set(this.definition.states.map(i=>i.status));this.definition.states.length===0&&e.push("Workflow must have at least one state"),t.has(this.definition.initialState)||e.push(`Initial state "${this.definition.initialState}" is not in the states list`);for(let i of this.definition.terminalStates)t.has(i)||e.push(`Terminal state "${i}" is not in the states list`);for(let i of this.definition.transitions)t.has(i.from)||e.push(`Transition "${i.label}" references unknown source state "${i.from}"`),t.has(i.to)||e.push(`Transition "${i.label}" references unknown target state "${i.to}"`);for(let i of this.definition.states){if(this.definition.terminalStates.includes(i.status))continue;this.definition.transitions.filter(a=>a.from===i.status&&!a.isRollback).length===0&&e.push(`State "${i.status}" has no outgoing forward transitions (dead end)`)}let r=new Set;for(let i of this.definition.transitions){let s=`${i.from}\u2192${i.to}`;r.has(s)&&e.push(`Duplicate transition: ${s}`),r.add(s)}return{valid:e.length===0,errors:e}}};Fs.WorkflowEngine=r_;Fs.WorkflowEngine=r_=QM([(0,XM.injectable)(),YM("design:paramtypes",[Object])],r_)});var f3=v(Xi=>{"use strict";Object.defineProperty(Xi,"__esModule",{value:!0});Xi.EFFORT_WORKFLOW_PROPERTY=Xi.WorkflowTransitionProperty=Xi.WorkflowStateProperty=Xi.WorkflowProperty=void 0;Xi.WorkflowProperty={TARGET_CLASS:"ems__Workflow_targetClass",INITIAL_STATE:"ems__Workflow_initialState",TERMINAL_STATES:"ems__Workflow_terminalStates",IS_DEFAULT:"ems__Workflow_isDefault"};Xi.WorkflowStateProperty={WORKFLOW:"ems__WorkflowState_workflow",STATUS:"ems__WorkflowState_status",ORDER:"ems__WorkflowState_order",OPTIONAL:"ems__WorkflowState_optional",TIMESTAMP_ON_ENTER:"ems__WorkflowState_timestampOnEnter",BADGE_COLOR:"ems__WorkflowState_badgeColor"};Xi.WorkflowTransitionProperty={WORKFLOW:"ems__WorkflowTransition_workflow",FROM:"ems__WorkflowTransition_from",TO:"ems__WorkflowTransition_to",LABEL:"ems__WorkflowTransition_label",ICON:"ems__WorkflowTransition_icon",IS_ROLLBACK:"ems__WorkflowTransition_isRollback"};Xi.EFFORT_WORKFLOW_PROPERTY="ems__Effort_workflow"});var Ki=v(dp=>{"use strict";Object.defineProperty(dp,"__esModule",{value:!0});dp.MetadataHelpers=void 0;var n_=class{static{o(this,"MetadataHelpers")}static findAllReferencingProperties(e,t){let r=[];for(let[i,s]of Object.entries(e))this.containsReference(s,t)&&r.push(i);return r}static findReferencingProperty(e,t){for(let[r,i]of Object.entries(e))if(this.containsReference(i,t))return r}static containsReference(e,t){if(!e)return!1;let r=t.replace(/\.md$/,"");if(typeof e=="string"){let i=/\[\[([^\[\]]+)\]\]/g,s;for(;(s=i.exec(e))!==null;){let c=s[1].split("|")[0].trim();if(c===r||c.endsWith(`/${r}`))return!0}return!1}return Array.isArray(e)?e.some(i=>this.containsReference(i,t)):!1}static isAssetArchived(e){let t=e?.exo__Asset_isArchived;if(t!=null){if(t===!0||t===1)return!0;if(typeof t=="string"){let i=t.toLowerCase().trim();if(i==="true"||i==="yes"||i==="1")return!0}if(typeof t=="boolean")return t}let r=e?.archived;if(r==null)return!1;if(typeof r=="boolean")return r;if(typeof r=="number")return r!==0;if(typeof r=="string"){let i=r.toLowerCase().trim();return i==="true"||i==="yes"||i==="1"}return!1}static getPropertyValue(e,t){return t==="Name"||t==="title"?e.title:t==="created"?e.created:t==="modified"?e.modified:t==="path"?e.path:e.metadata?.[t]}static ensureQuoted(e){return!e||e==='""'?'""':e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`}static buildFileContent(e,t){let r=Object.entries(e).map(([a,c])=>{if(Array.isArray(c)){let l=c.map(u=>` - ${u}`).join(`
91
+ Details: ${t.message}`:"";console.error(`[Exocortex ERROR]${s} ${e}${a}`)}}};up.LoggingService=Du;Du.isVerbose=!1;Du.isDevelopment=void 0});var u3=v(ii=>{"use strict";var UM=ii&&ii.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},BM=ii&&ii.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(ii,"__esModule",{value:!0});ii.GroundingExecutor=ii.ServiceRegistry=void 0;var qM=ve(),WM=gn(),po=rc(),GM=Yi(),zM=Vr(),HM=ya(),fp=class{static{o(this,"ServiceRegistry")}constructor(){this.services=new Map}register(e,t){this.services.set(e,t)}get(e){return this.services.get(e)}has(e){return this.services.has(e)}getRegisteredIds(){return Array.from(this.services.keys())}};ii.ServiceRegistry=fp;var l3=20,t_=class{static{o(this,"GroundingExecutor")}constructor(e,t,r){this.frontmatterService=new GM.FrontmatterService,this.fileReader=e,this.fileWriter=t,this.serviceRegistry=r}async execute(e,t,r,i){try{switch(e.type){case po.GroundingType.PROPERTY_SET:return await this.executePropertySet(e,t,r,i);case po.GroundingType.PROPERTY_DELETE:return await this.executePropertyDelete(e,r);case po.GroundingType.COMPOSITE:return await this.executeComposite(e,t,r,i,0);case po.GroundingType.SERVICE_CALL:return await this.executeServiceCall(e,t,r,i);case po.GroundingType.CREATE_INSTANCE:return await this.executeCreateInstance(e,t,i);case po.GroundingType.SPARQL_UPDATE:return{success:!1,error:"sparql_update grounding not yet implemented. Use property_set/property_delete instead."};default:return{success:!1,error:`Unknown grounding type: ${e.type}`}}}catch(s){return{success:!1,error:s instanceof Error?s.message:String(s)}}}async executePropertySet(e,t,r,i){if(!e.targetProperty)return{success:!1,error:"property_set requires targetProperty"};if(e.targetValue===void 0)return{success:!1,error:"property_set requires targetValue"};if(/\$(input|value)\b/.test(e.targetValue)&&(i===void 0||i.value===void 0||i.value===null))return{success:!1,error:"property_set: targetValue contains $input/$value placeholder but no userInput.value provided"};let a=this.substituteVariables(e.targetValue,t,i),c=await this.fileReader.readFile(r),l=this.frontmatterService.updateProperty(c,e.targetProperty,a);return await this.fileWriter.updateFile(r,l),{success:!0}}async executePropertyDelete(e,t){if(!e.targetProperty)return{success:!1,error:"property_delete requires targetProperty"};let r=await this.fileReader.readFile(t),i=this.frontmatterService.removeProperty(r,e.targetProperty);return await this.fileWriter.updateFile(t,i),{success:!0}}async executeComposite(e,t,r,i,s){if(s>=l3)return{success:!1,error:`Composite grounding exceeded maximum depth of ${l3}`};let a=e.steps??[];if(a.length===0)return{success:!0};let c;try{c=await this.fileReader.readFile(r)}catch{}let l=[];try{for(let u=0;u<a.length;u++){let f=a[u],d=await this.executeStep(f,t,r,i,s+1);if(!d.success)return await this.rollback(c,r,l),{success:!1,error:`Composite step ${u} failed: ${d.error}`};l.push(u)}return{success:!0}}catch(u){return await this.rollback(c,r,l),{success:!1,error:`Composite execution failed: ${u instanceof Error?u.message:String(u)}`}}}async executeServiceCall(e,t,r,i){let s=e.targetProperty;if(!s)return{success:!1,error:"service_call requires targetProperty as serviceId"};if(s==="convertToTask")return await this.executeConvertToTask(r);if(s==="updateProperty"){if(e.targetValue==="ems__Task")return await this.executeConvertToTask(r);if(e.targetValue==="ems__Project")return await this.executeConvertToProject(r)}let a=this.serviceRegistry.get(s);if(!a)return{success:!1,error:`Service not found: "${s}". Registered services: ${this.serviceRegistry.getRegisteredIds().join(", ")||"none"}`};let c=i;if(e.targetValue)try{let l=JSON.parse(e.targetValue);typeof l=="object"&&l!==null&&(c={...l,...i??{}})}catch{}return await a.execute(t,c),{success:!0}}async executeConvertToTask(e){let t=await this.fileReader.readFile(e),r=this.frontmatterService.updateProperty(t,"exo__Instance_class",'["[[ems__Task]]"]');return await this.fileWriter.updateFile(e,r),{success:!0}}async executeConvertToProject(e){let t=await this.fileReader.readFile(e),r=this.frontmatterService.updateProperty(t,"exo__Instance_class",'["[[ems__Project]]"]');return await this.fileWriter.updateFile(e,r),{success:!0}}async executeCreateInstance(e,t,r){if(!e.targetFolder)return{success:!1,error:"create_instance requires targetFolder"};let i=(0,WM.v4)(),s=r?.label??"Untitled",a={exo__Asset_uid:i,exo__Asset_createdAt:new Date().toISOString(),exo__Asset_label:s};if(s!=="Untitled"&&(a.aliases=[s]),e.targetClass&&(a.exo__Instance_class=[`"[[${e.targetClass}]]"`]),e.targetPrototype&&(a.exo__Asset_prototype=`"[[${e.targetPrototype}]]"`),t&&(a.exo__Asset_source=`"[[${t}]]"`),r)for(let[u,f]of Object.entries(r))u!=="label"&&f!=null&&(a[u]=f);let c=this.frontmatterService.createFrontmatter("",a),l=`${e.targetFolder}/${i}.md`;return await this.fileWriter.createFile(l,c),{success:!0}}async executeStep(e,t,r,i,s){return e.type===po.GroundingType.COMPOSITE?this.executeComposite(e,t,r,i,s):this.execute(e,t,r,i)}async rollback(e,t,r){if(e!==void 0)try{await this.fileWriter.updateFile(t,e)}catch(i){HM.LoggingService.error(`[GroundingExecutor] Rollback failed for ${t}`,i instanceof Error?i:new Error(String(i)))}}substituteVariables(e,t,r){let i=new Date,s=i.toISOString(),a=zM.DateFormatter.toLocalTimestamp(i),c=s.slice(0,10),l=e.replace(/\$target/g,t).replace(/\$nowLocal/g,a).replace(/\$now/g,s).replace(/\$today/g,c);if(r?.value!==void 0&&r.value!==null){let u=String(r.value);l=l.replace(/\$input\b/g,u).replace(/\$value\b/g,u)}return l}};ii.GroundingExecutor=t_;ii.GroundingExecutor=t_=UM([(0,qM.injectable)(),BM("design:paramtypes",[Object,Object,fp])],t_)});var Fu=v(Fs=>{"use strict";var QM=Fs&&Fs.__decorate||function(n,e,t,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var c=n.length-1;c>=0;c--)(a=n[c])&&(s=(i<3?a(s):i>3?a(e,t,s):a(e,t))||s);return i>3&&s&&Object.defineProperty(e,t,s),s},YM=Fs&&Fs.__metadata||function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};Object.defineProperty(Fs,"__esModule",{value:!0});Fs.WorkflowEngine=void 0;var XM=ve(),r_=class{static{o(this,"WorkflowEngine")}constructor(e){this.definition=e}getAvailableTransitions(e){return this.definition.transitions.filter(t=>t.from===e&&!t.isRollback)}getRollbackTransitions(e){return this.definition.transitions.filter(t=>t.from===e&&t.isRollback)}getAllTransitions(e){return this.definition.transitions.filter(t=>t.from===e)}canTransition(e,t){return this.definition.transitions.some(r=>r.from===e&&r.to===t)}getPreviousStatus(e){return this.definition.transitions.find(r=>r.from===e&&r.isRollback)?.to??null}getNextStates(e){return this.getAvailableTransitions(e).map(t=>t.to)}isTerminalState(e){return this.definition.terminalStates.includes(e)}isInitialState(e){return this.definition.initialState===e}getTimestampsForStatus(e){return this.definition.states.find(r=>r.status===e)?.timestampOnEnter??[]}getTransition(e,t){return this.definition.transitions.find(r=>r.from===e&&r.to===t)}getOrderedStates(){return this.definition.states.map(e=>e.status)}getDefinition(){return this.definition}validate(){let e=[],t=new Set(this.definition.states.map(i=>i.status));this.definition.states.length===0&&e.push("Workflow must have at least one state"),t.has(this.definition.initialState)||e.push(`Initial state "${this.definition.initialState}" is not in the states list`);for(let i of this.definition.terminalStates)t.has(i)||e.push(`Terminal state "${i}" is not in the states list`);for(let i of this.definition.transitions)t.has(i.from)||e.push(`Transition "${i.label}" references unknown source state "${i.from}"`),t.has(i.to)||e.push(`Transition "${i.label}" references unknown target state "${i.to}"`);for(let i of this.definition.states){if(this.definition.terminalStates.includes(i.status))continue;this.definition.transitions.filter(a=>a.from===i.status&&!a.isRollback).length===0&&e.push(`State "${i.status}" has no outgoing forward transitions (dead end)`)}let r=new Set;for(let i of this.definition.transitions){let s=`${i.from}\u2192${i.to}`;r.has(s)&&e.push(`Duplicate transition: ${s}`),r.add(s)}return{valid:e.length===0,errors:e}}};Fs.WorkflowEngine=r_;Fs.WorkflowEngine=r_=QM([(0,XM.injectable)(),YM("design:paramtypes",[Object])],r_)});var f3=v(Xi=>{"use strict";Object.defineProperty(Xi,"__esModule",{value:!0});Xi.EFFORT_WORKFLOW_PROPERTY=Xi.WorkflowTransitionProperty=Xi.WorkflowStateProperty=Xi.WorkflowProperty=void 0;Xi.WorkflowProperty={TARGET_CLASS:"ems__Workflow_targetClass",INITIAL_STATE:"ems__Workflow_initialState",TERMINAL_STATES:"ems__Workflow_terminalStates",IS_DEFAULT:"ems__Workflow_isDefault"};Xi.WorkflowStateProperty={WORKFLOW:"ems__WorkflowState_workflow",STATUS:"ems__WorkflowState_status",ORDER:"ems__WorkflowState_order",OPTIONAL:"ems__WorkflowState_optional",TIMESTAMP_ON_ENTER:"ems__WorkflowState_timestampOnEnter",BADGE_COLOR:"ems__WorkflowState_badgeColor"};Xi.WorkflowTransitionProperty={WORKFLOW:"ems__WorkflowTransition_workflow",FROM:"ems__WorkflowTransition_from",TO:"ems__WorkflowTransition_to",LABEL:"ems__WorkflowTransition_label",ICON:"ems__WorkflowTransition_icon",IS_ROLLBACK:"ems__WorkflowTransition_isRollback"};Xi.EFFORT_WORKFLOW_PROPERTY="ems__Effort_workflow"});var Ki=v(dp=>{"use strict";Object.defineProperty(dp,"__esModule",{value:!0});dp.MetadataHelpers=void 0;var n_=class{static{o(this,"MetadataHelpers")}static findAllReferencingProperties(e,t){let r=[];for(let[i,s]of Object.entries(e))this.containsReference(s,t)&&r.push(i);return r}static findReferencingProperty(e,t){for(let[r,i]of Object.entries(e))if(this.containsReference(i,t))return r}static containsReference(e,t){if(!e)return!1;let r=t.replace(/\.md$/,"");if(typeof e=="string"){let i=/\[\[([^\[\]]+)\]\]/g,s;for(;(s=i.exec(e))!==null;){let c=s[1].split("|")[0].trim();if(c===r||c.endsWith(`/${r}`))return!0}return!1}return Array.isArray(e)?e.some(i=>this.containsReference(i,t)):!1}static isAssetArchived(e){let t=e?.exo__Asset_isArchived;if(t!=null){if(t===!0||t===1)return!0;if(typeof t=="string"){let i=t.toLowerCase().trim();if(i==="true"||i==="yes"||i==="1")return!0}if(typeof t=="boolean")return t}let r=e?.archived;if(r==null)return!1;if(typeof r=="boolean")return r;if(typeof r=="number")return r!==0;if(typeof r=="string"){let i=r.toLowerCase().trim();return i==="true"||i==="yes"||i==="1"}return!1}static getPropertyValue(e,t){return t==="Name"||t==="title"?e.title:t==="created"?e.created:t==="modified"?e.modified:t==="path"?e.path:e.metadata?.[t]}static ensureQuoted(e){return!e||e==='""'?'""':e.startsWith('"')&&e.endsWith('"')?e:`"${e}"`}static buildFileContent(e,t){let r=Object.entries(e).map(([a,c])=>{if(Array.isArray(c)){let l=c.map(u=>` - ${u}`).join(`
92
92
  `);return`${a}:
93
93
  ${l}`}return`${a}: ${c}`}).join(`
94
94
  `),i=t;if(i===void 0){let a=e.exo__Asset_label;typeof a=="string"&&a.trim()!==""&&(i=`# ${a}`)}let s=i?`
@@ -750,7 +750,7 @@ ${Dr.dump(i,{lineWidth:-1})}---
750
750
  `);for(let c of i){console.log(` \u{1F4C4} ${c.label} (${c.uid}):`);for(let l of c.issues)console.log(` \u2022 ${l}`);console.log()}process.exitCode=5}}}catch(r){F.handle(r)}}),n}o(tD,"dynamicCommandCommand");function A2(n){let e=[],t=[];I2(n,t);for(let{filePath:r,fm:i}of t){if(!Vl(i,"exocmd__Command"))continue;let s=i.exo__Asset_uid??"",a=i.exo__Asset_label??rD(r),c=i.exocmd__Command_category,l=i.exocmd__Command_icon,u=!!i.exocmd__Command_precondition,f=i.exocmd__Command_grounding,d;if(f){let h=Og(String(f)),p=t.find(_=>_.fm.exo__Asset_uid===h&&Vl(_.fm,"exocmd__Grounding"));p&&(d=p.fm.exocmd__Grounding_type)}e.push({filePath:r,uid:s,label:a,category:c,icon:l,hasPrecondition:u,groundingType:d})}return e}o(A2,"scanCommands");async function pH(n,e){let{tripleStore:t}=await x2(n),r=new jt.CommandResolver(t),i=await r.findBindings(),s=new Set;for(let c of i)s.add(c.commandRef);let a=[];for(let c of s){let l=await r.loadCommand(c);l&&a.push({filePath:"",uid:l.id,label:l.name,category:l.category,icon:l.icon,hasPrecondition:!!l.precondition,groundingType:l.grounding.type})}return a}o(pH,"listCommandsForTarget");function mH(n){let e=[],t=[];I2(n,t);let r=new Map;for(let i of t){let s=i.fm.exo__Asset_uid;s&&r.set(s,i)}for(let{filePath:i,fm:s}of t){if(!Vl(s,"exocmd__Command"))continue;let a=s.exo__Asset_uid??"",c=s.exo__Asset_label??rD(i),l=[];a||l.push("Missing exo__Asset_uid"),s.exo__Asset_label||l.push("Missing exo__Asset_label");let u=s.exocmd__Command_grounding;if(!u)l.push("Missing exocmd__Command_grounding (required)");else{let h=Og(String(u)),p=r.get(h);if(!p)l.push(`Grounding reference "${h}" not found in vault`);else if(!Vl(p.fm,"exocmd__Grounding"))l.push(`Grounding reference "${h}" is not an exocmd__Grounding asset`);else{let _=p.fm,S=_.exocmd__Grounding_type;S?(Object.values(jt.GroundingType).includes(S)||l.push(`Grounding "${h}" has invalid type "${S}"`),(S===jt.GroundingType.PROPERTY_SET||S===jt.GroundingType.PROPERTY_DELETE)&&!_.exocmd__Grounding_targetProperty&&l.push(`Grounding "${h}" (${S}) missing targetProperty`),S===jt.GroundingType.PROPERTY_SET&&!_.exocmd__Grounding_targetValue&&l.push(`Grounding "${h}" (property_set) missing targetValue`),S===jt.GroundingType.SERVICE_CALL&&((_.exocmd__Grounding_serviceId??_.exocmd__Grounding_targetProperty)||l.push(`Grounding "${h}" (service_call) missing serviceId and targetProperty`))):l.push(`Grounding "${h}" missing exocmd__Grounding_type`)}}let f=s.exocmd__Command_precondition;if(f){let h=Og(String(f)),p=r.get(h);if(!p)l.push(`Precondition reference "${h}" not found in vault`);else if(!Vl(p.fm,"exocmd__Precondition"))l.push(`Precondition reference "${h}" is not an exocmd__Precondition asset`);else{let _=p.fm.exocmd__Precondition_sparqlAsk,S=p.fm.exocmd__Precondition_hostFunction;!_&&!S&&l.push(`Precondition "${h}" missing both sparqlAsk and hostFunction`)}}t.some(h=>Vl(h.fm,"exocmd__CommandBinding")?Og(String(h.fm.exocmd__CommandBinding_command??""))===a:!1)||l.push("No CommandBinding references this command (command will be unused)"),l.length>0&&e.push({uid:a,label:c,filePath:i,issues:l})}return e}o(mH,"validateCommands");async function x2(n){let e=new Zt(n),r=await new jt.NoteToRDFConverter(e).convertVault(),i=new jt.InMemoryTripleStore;return await i.addAll(r),{tripleStore:i}}o(x2,"buildTripleStore");function C2(n,e){if(console.log(`${e}ID: ${n.id}`),console.log(`${e}Label: ${n.label}`),console.log(`${e}Type: ${n.type}`),n.targetProperty&&console.log(`${e}Target property: ${n.targetProperty}`),n.targetValue!==void 0&&console.log(`${e}Target value: ${n.targetValue}`),n.sparqlUpdate&&console.log(`${e}SPARQL UPDATE: ${n.sparqlUpdate}`),n.steps&&n.steps.length>0){console.log(`${e}Steps (${n.steps.length}):`);for(let t=0;t<n.steps.length;t++)console.log(`${e} Step ${t+1}:`),C2(n.steps[t],e+" ")}}o(C2,"printGrounding");function I2(n,e){let t;try{t=(0,ds.readdirSync)(n,{withFileTypes:!0})}catch{return}for(let r of t){let i=(0,hs.join)(n,r.name);if(r.isDirectory()){if(r.name.startsWith(".")||r.name==="node_modules")continue;I2(i,e)}else if(r.name.endsWith(".md"))try{let s=(0,ds.readFileSync)(i,"utf-8"),a=hH.parse(s);a.exists&&e.push({filePath:i,fm:gH(a.content)})}catch{}}}o(I2,"collectParsedFiles");function gH(n){let e={},t=n.split(`
751
751
  `),r="",i=null;for(let s of t){if(s.match(/^\s+-\s+/)&&r){let c=s.replace(/^\s+-\s+/,"").trim();i||(i=[]),i.push(c),e[r]=i;continue}let a=s.match(/^([a-zA-Z0-9_]+):\s*(.*)/);if(a){r=a[1],i=null;let c=a[2].trim();if((c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),c==="true"?c=!0:c==="false"&&(c=!1),c===""){e[r]=[],i=e[r];continue}e[r]=c}}return e}o(gH,"parseYamlFrontmatter");function Vl(n,e){let t=n.exo__Instance_class;if(!t)return!1;let r=Array.isArray(t)?t:[t];for(let i of r){if(typeof i!="string")continue;let s=i.match(/\[\[([^|\]]+)/);if((s?s[1]:i)===e)return!0}return!1}o(Vl,"hasClass");function Og(n){if(typeof n!="string")return"";let e=n.replace(/["'[\]]/g,"").trim(),t=e.indexOf("|");return t>=0?e.substring(0,t).trim():e}o(Og,"normalizeWikilink");function rD(n){return(0,hs.basename)(n,".md")}o(rD,"extractLabelFromFilename");var Ul=require("fs"),zf=require("path"),Ot=X(Bt());var yH={turtle:"turtle",ntriples:"n-triples",jsonld:"json-ld"},_H=new Ot.IRI(`${Ot.Namespace.RDF.iri.value}type`),nD=[Ot.Namespace.RDF,Ot.Namespace.RDFS,Ot.Namespace.OWL,Ot.Namespace.XSD,Ot.Namespace.EXO,Ot.Namespace.EMS,Ot.Namespace.EXOCMD,Ot.Namespace.IMS,Ot.Namespace.ZTLK,Ot.Namespace.PTMS,Ot.Namespace.LIT,Ot.Namespace.INBOX];function vH(n){let e=n.trim();if(e.startsWith("http://")||e.startsWith("https://"))return new Ot.IRI(e);let t=e.match(/^([a-zA-Z][a-zA-Z0-9]*)__(.+)$/);if(t){let[,i,s]=t,a=nD.find(c=>c.prefix===i);if(a)return a.term(s)}let r=e.match(/^([a-zA-Z][a-zA-Z0-9]*):(.+)$/);if(r){let[,i,s]=r,a=nD.find(c=>c.prefix===i);if(a)return a.term(s)}throw new ze(`Unable to resolve class filter "${n}" to an IRI.`,'Use shorthand like "ems__Task", prefixed like "ems:Task", or a full IRI.')}o(vH,"resolveClassIri");function SH(n,e){let t=new Set;for(let r of n)r.predicate.equals(_H)&&r.object instanceof Ot.IRI&&r.object.equals(e)&&t.add(r.subject.toString());return t.size===0?[]:n.filter(r=>t.has(r.subject.toString()))}o(SH,"filterByClass");function iD(){return new De("convert").description("Dump vault graph as RDF (Turtle/N-Triples/JSON-LD)").option("--format <type>","Serialization format: turtle|ntriples|jsonld","turtle").option("--out <path>","Write serialized output to file (default: stdout)").option("--filter <class>","Keep only instances of the given class (e.g. ems__Task, ems:Task, or full IRI)").option("--vault <path>","Path to Obsidian vault",process.cwd()).option("--output <type>","Response format for errors: text|json (for MCP tools)","text").action(async n=>{let e=n.output||"text";F.setFormat(e);try{let t=yH[n.format];if(!t)throw new ze(`Unknown format: "${n.format}". Expected one of turtle|ntriples|jsonld.`,"exocortex convert --format turtle --out vault.ttl");let r=(0,zf.resolve)(n.vault);if(!(0,Ul.existsSync)(r))throw new xe(r);e==="text"&&!n.out||e==="text"&&console.error(`\u{1F4E6} Loading vault: ${r}...`);let i=new Zt(r),a=await new Ot.NoteToRDFConverter(i).convertVault();if(n.filter){let f=vH(n.filter);a=SH(a,f)}let c=new Ot.InMemoryTripleStore;await c.addAll(a);let u=new Ot.RDFSerializer(c).serializeTriples(a,t,{pretty:t==="json-ld",indent:2});if(n.out){let f=(0,zf.resolve)(n.out);try{(0,Ul.mkdirSync)((0,zf.dirname)(f),{recursive:!0}),(0,Ul.writeFileSync)(f,u,"utf-8")}catch(d){throw new cf("convert",`failed to write output to ${f}: ${d.message}`,"Check destination directory exists and is writable.",{outPath:f})}e==="text"&&console.error(`\u2705 Wrote ${a.length} triple(s) to ${f} (${n.format}).`)}else process.stdout.write(u),u.endsWith(`
752
752
  `)||process.stdout.write(`
753
- `)}catch(t){F.handle(t)}})}o(iD,"convertCommand");function sD(n){n.addCommand(JR()),n.addCommand(rO()),n.addCommand(nO())}o(sD,"addQuerySubcommands");function aD(n){let e=new De;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.105.4");let t=e.command("exoql").description("ExoQL query execution and cache management");sD(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return sD(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(fP()),e.addCommand(pP()),e.addCommand(mP()),e.addCommand(yP()),e.addCommand(_P()),e.addCommand(EP()),e.addCommand(CP()),e.addCommand(LP()),e.addCommand(jP()),e.addCommand(qP()),e.addCommand(zP()),e.addCommand(HP()),e.addCommand(YP()),e.addCommand(tD()),e.addCommand(iD()),e}o(aD,"createProgram");aD().parse();0&&(module.exports={createProgram});
753
+ `)}catch(t){F.handle(t)}})}o(iD,"convertCommand");function sD(n){n.addCommand(JR()),n.addCommand(rO()),n.addCommand(nO())}o(sD,"addQuerySubcommands");function aD(n){let e=new De;e.name("exocortex").description("CLI tool for Exocortex knowledge management system").version(n??"15.105.5");let t=e.command("exoql").description("ExoQL query execution and cache management");sD(t);let r=e.command("sparql").description("(deprecated) Use 'exoql' instead");return sD(r),r.hook("preAction",()=>{console.error('\u26A0\uFE0F "sparql" is deprecated. Use "exoql" instead.')}),e.addCommand(fP()),e.addCommand(pP()),e.addCommand(mP()),e.addCommand(yP()),e.addCommand(_P()),e.addCommand(EP()),e.addCommand(CP()),e.addCommand(LP()),e.addCommand(jP()),e.addCommand(qP()),e.addCommand(zP()),e.addCommand(HP()),e.addCommand(YP()),e.addCommand(tD()),e.addCommand(iD()),e}o(aD,"createProgram");aD().parse();0&&(module.exports={createProgram});
754
754
  /*! Bundled license information:
755
755
 
756
756
  reflect-metadata/Reflect.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitelev/exocortex-cli",
3
- "version": "15.105.4",
3
+ "version": "15.105.5",
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": {