@modality-counter/core 0.6.2 → 0.6.4

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 +1 -43
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -636,7 +636,7 @@ ${l.map((x,T)=>`<STEP n="${T+1}">${Array.isArray(x)?x.join(`
636
636
 
637
637
  Available references:
638
638
 
639
- ${x}`)}return HV({message:g})}else{let{method:{references:{referenceInstructions:p}={},...g},tactical_notes:x,...T}=d,O=$T(f.scriptResult,["content"],f.scriptResult);return HV({success:f.scriptSuccess!=null?f.scriptSuccess:!0,instructions:[{message:`${o} EXECUTED!`,currentTimeAtUTC:new Date().toISOString()},T]},[{methodParams:Object.keys(c||{}).length?c:void 0,methodContent:g},...dmr(O),{references:p,tactical_notes:x}])}}catch(l){return kse(l,hz)}}},_Counter__DeployWorkflow:{description:"Deploy workflow",inputSchema:ugi,execute:async({callSign:i})=>{let o=await c0(["workflow"],e),{resolveName:a}=Xco(i,"workflow"),{promptData:s}=await V2(o,a)||{};try{if(!s)throw new Error(`WORKFLOW '${i}' not found. Available methods: ${o.map(u=>u.id).join(", ")}`);return HV(s)}catch(u){return kse(u,"_Counter__DeployWorkflow")}}},_Counter__PartyMode:{description:await cRs(),inputSchema:ogi,execute:async({topic:i,context:o="General discussion",recommendedHeroes:a,deployedHeroes:s})=>{try{let{availableHeroes:u,selectedHeroes:c}=await lRs(e,a,s),l=await c0(["persona"],e),d=(await Promise.all(c.map(async T=>({...T,deployedContent:(await V2(l,T.callSign,{partyMode:!0,activeHeroes:c})||{})?.promptData,deploymentStatus:"AUTO_DEPLOYED"})))).map(T=>({callSign:T.callSign,name:T.name,description:T.description,icon:T.deployedContent?.agent?.icon,methods:T.deployedContent?.methods,partyMode:!0})),p=d.map(T=>`${T.icon} ${T.name} (${T.callSign})`).join(", "),g=u.filter(T=>!c.some(O=>O.id===T.id)).map(T=>`${T.name} (${T.callSign})`).join(", "),x=(await GR(lyr,{activeHeroes:p,topic:i,context:o}))?.PartyMode;return HV({message:"READY_FOR_AUTO_FACILITATION",instructions:[{availableHeroesDisplay:g}]},[{partyModeProtocol:x},{activeHeroes:d}])}catch(u){return kse(u,"PartyMode")}}}};if(t!=null){let i=t;for(let o of r)i.addPrompt({name:o.id,load:async()=>`*${o.id}`})}return Ghr(n,t)};var gh={ARRAY_MIN_ITEMS:1,ARRAY_MAX_ITEMS:20,GROUP_MIN_COUNT:2,GROUP_MAX_COUNT:5,ITEM_MIN_LENGTH:30,ITEM_MAX_LENGTH:200,GROUP_ITEM_MAX:6,GROUP_ITEM_MIN:1,TOTAL_ITEMS_MIN:3,TOTAL_ITEMS_MAX:20,GROUP_NAME_PATTERN:/^[a-z0-9-]+$/};var $Te={MIN_LENGTH:20,MAX_LENGTH:500};var dut=We.lazy(()=>We.union([We.string().min(1,"Execution flow step cannot be empty"),We.array(We.lazy(()=>dut)).min(1,"Nested array must contain at least one step").max(10,"Nested array should not exceed 10 steps for clarity")])),sM=We.array(dut).min(1,"Execution flow must contain at least one step").max(15,"Execution flow should not exceed 15 steps for clarity").optional();var elo=We.string().min(gh.ITEM_MIN_LENGTH,`Output item should be at least ${gh.ITEM_MIN_LENGTH} characters`).max(gh.ITEM_MAX_LENGTH,`Output item should not exceed ${gh.ITEM_MAX_LENGTH} characters`).regex(/^[A-Z]/,"Output item should start with capital letter").refine(e=>![/comprehensive analysis/i,/detailed report/i,/complete overview/i,/thorough assessment/i].some(r=>r.test(e)),"Output item contains generic phrase - be more specific"),dRs=We.array(elo).min(gh.ARRAY_MIN_ITEMS,`Expected output should contain at least ${gh.ARRAY_MIN_ITEMS} items`).max(gh.ARRAY_MAX_ITEMS,`Expected output should not exceed ${gh.ARRAY_MAX_ITEMS} items for readability`),pRs=We.record(We.string().regex(gh.GROUP_NAME_PATTERN,"Group name should be lowercase with dashes and numbers only"),We.array(elo).min(gh.GROUP_ITEM_MIN,`Group should contain at least ${gh.GROUP_ITEM_MIN} item`).max(gh.GROUP_ITEM_MAX,`Group should not exceed ${gh.GROUP_ITEM_MAX} items for optimal cognitive load`)).refine(e=>Object.keys(e).length>=gh.GROUP_MIN_COUNT,`Nested expected_output should contain at least ${gh.GROUP_MIN_COUNT} groups`).refine(e=>Object.keys(e).length<=gh.GROUP_MAX_COUNT,`Nested expected_output should not exceed ${gh.GROUP_MAX_COUNT} groups for readability`).refine(e=>Object.values(e).reduce((r,n)=>r+n.length,0)>=gh.TOTAL_ITEMS_MIN,`Total items across all groups should be at least ${gh.TOTAL_ITEMS_MIN}`).refine(e=>Object.values(e).reduce((r,n)=>r+n.length,0)<=gh.TOTAL_ITEMS_MAX,`Total items across all groups should not exceed ${gh.TOTAL_ITEMS_MAX} for readability`),hRs=We.union([dRs,pRs]),mRs=We.string().min($Te.MIN_LENGTH,`Purpose field should be at least ${$Te.MIN_LENGTH} characters`).max($Te.MAX_LENGTH,`Purpose field should not exceed ${$Te.MAX_LENGTH} characters`).regex(/^[A-Z]/,"Purpose should start with capital letter").regex(/[.!]$/,"Purpose should end with punctuation"),gRs=We.object({description:We.string().min(1,"Parameter description is required"),type:We.enum(["string","number","integer","boolean","array","object"]).optional(),required:We.boolean().default(!1),options:We.array(We.string()).optional(),default:We.union([We.string(),We.number(),We.boolean()]).optional()}).catchall(We.unknown()),yRs=We.object({method:We.string().min(1,"Usage method is required"),parameters:We.record(We.string(),gRs).optional(),examples:We.array(We.string()).optional(),elicit:We.boolean().optional()}).strict(),bRs=We.object({name:We.string().regex(/^\*[a-z0-9-]+$/,"Method name should start with * and use lowercase with hyphens and numbers"),icon:We.string().min(1,"Method icon is required"),category:We.string().min(1,"Method category is required"),introduce:We.string().min(1,"Method introduce is required"),usage:yRs,agent_compatibility:We.array(We.string()).min(1,"Agent compatibility is required and must contain at least one agent"),references:We.record(We.string(),We.object({description:We.string().min(1,"Reference description is required"),content:We.string().optional()})).optional()}).strict(),xRs=We.object({template_ref:We.string().min(1,"Template reference filename is required"),description:We.string().min(1,"Template description is required"),when_to_trigger:We.array(We.string()).optional()}).strict(),vRs=We.array(xRs).min(1,"Template integration must be an array containing at least one template"),_Rs=We.object({method:We.string().min(1,"Method is required for composition").regex(/^\*[a-z0-9-]+(\s+[^\s]+)*$/,"Method must start with * and follow method syntax with optional parameters like [target], [target]-suffix, keywords, or --flags"),purpose:We.string().min(1,"Purpose is required for composition item").max(200,"Purpose should not exceed 200 characters for clarity"),execution_flow:sM,when_to_trigger:sM}).strict(),SRs=We.record(We.string().regex(/^[a-z0-9-]+$/,"Composition key should be lowercase with hyphens and numbers only"),_Rs).refine(e=>Object.keys(e).length>=1,"Composition must contain at least one method").refine(e=>Object.keys(e).length<=10,"Composition should not exceed 10 methods for clarity").optional(),wRs=We.record(We.string(),We.array(We.union([We.string().min(1,"Action checklist item cannot be empty"),We.record(We.string(),We.string().min(1,"Protocol reference cannot be empty"))]))).optional(),kRs=We.object({purpose:We.string().min(1,"Usage mode purpose is required"),execution_flow:sM,fallback:We.array(We.string().min(1,"Fallback step cannot be empty")).optional(),when_to_trigger:sM,usage_example:We.array(We.string().min(1,"Usage example cannot be empty")).min(1,"At least one usage example is required when usage_example is specified").max(3,"Usage examples should not exceed 5 for clarity").optional()}).strict(),ERs=We.record(We.string().regex(/^[a-z0-9-]+$/,"Usage mode key should be lowercase with hyphens and numbers only"),kRs).optional(),IRs=We.object({validation_protocols:We.record(We.string(),We.any()).optional(),action_checklists:We.union([wRs,We.array(We.string())]),mission_critical:sM}).strict(),TRs=We.any().superRefine((e,t)=>{if(e&&typeof e=="object"){let n=Object.keys(e);if(n[n.length-1]!=="mission_critical")return t.addIssue({code:"custom",message:`mission_critical must be the last property in tactical_notes (current order: ${n.join(", ")})`,path:[]}),We.NEVER}let r=IRs.safeParse(e);r.success||r.error.issues.forEach(n=>{t.addIssue({code:"custom",message:`${n.code}: ${n.message}`,path:n.path})})}),ARs=We.object({purpose:mRs,expected_output:hRs,composition:SRs}).strict(),CRs=We.object({method:bRs,methodology:ARs,template_integration:vRs.optional(),integration_protocols:We.record(We.string(),We.any()).optional(),usage_modes:ERs,multi_market_integration:We.record(We.string(),We.any()).optional(),data_sources:We.record(We.string(),We.any()).optional(),tactical_notes:TRs}).catchall(We.unknown()).refine(e=>{let t=["method","methodology","template_integration","tactical_notes","integration_protocols","usage_modes","multi_market_integration","data_sources"],n=Object.keys(e).filter(i=>!t.includes(i)).filter(i=>!i.endsWith("-tmpl")&&!i.endsWith("-protocol"));return n.length&&console.dir(n,{deep:!0}),n.length===0},{message:"Additional root properties found."});function fyr(e,t){let r=CRs.safeParse(e);if(r.success)return{success:!0,data:r.data};{let n=t?`${t}: `:"";return{success:!1,errors:r.error.issues.map(i=>`${n}${i.path.join(".")}: ${i.message}`)}}}var ORs=We.object({header_sections:We.array(We.string()).optional().describe("Header content sections"),separators:We.record(We.string(),We.string()).optional().describe("Visual separator content as Record<string, string>"),body_sections:We.array(We.string()).optional().describe("Main content sections"),footer_sections:We.array(We.string()).optional().describe("Footer content sections")}).strict().describe("Template output structure configuration - strict validation enforces consistent *_sections naming pattern"),MRs=We.record(We.string(),We.any()).describe("Display format and presentation specifications - accepts any key-value pairs"),RRs=We.object({format:We.string().optional().describe("Output format specification"),filename:We.string().optional().describe("Filename pattern for template output"),structure:ORs.optional().describe("Output structure configuration")}).describe("Template output configuration"),PRs=We.object({title:We.string().optional().describe("Section title"),description:We.string().optional().describe("Section description"),sub_sections:We.array(We.string()).optional().describe("List of sub-section descriptions"),content:We.string().optional().describe("Plaintext content for examples and long text"),type:We.string().optional().describe("Section type classification"),focus:We.string().optional().describe("Section focus area")}).catchall(We.unknown()).describe("Individual template section configuration"),DRs=We.record(We.string(),PRs).describe("Template sections and content structure"),NRs=We.object({output:RRs.optional(),display_format:MRs.optional().describe("Display format specifications")}).strict().describe("Core template configuration"),$Rs=We.object({template:NRs.describe("Required template configuration section"),execution_flow:sM.optional().describe("Root-level execution flow specification"),sections:DRs.describe("REQUIRED: Root-level sections specification")}).strict().describe("Template content structure"),FRs=We.object({name:We.string().min(1,"Template name is required and must not be empty").describe("Template name from YAML frontmatter"),description:We.string().min(1,"Template description is required and must not be empty").describe("Template description from YAML frontmatter")}).catchall($Rs).describe("Complete template file with metadata (name, description) and exactly one template-name key containing template content");function pz(e){let t=FRs.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,errors:t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`)}}var rlo=We.union([We.string().min(10,"Protocol content should be at least 10 characters"),We.array(We.union([We.string().min(3,"Array item should be at least 3 characters"),We.record(We.string(),We.any())])).min(1,"Array should not be empty"),We.record(We.string(),We.union([We.string().min(3,"Object value should be at least 3 characters"),We.array(dut),We.record(We.string(),We.any())])).refine(e=>Object.keys(e).length>0,"Object should not be empty"),We.lazy(()=>We.record(We.string(),rlo))]),tlo=We.record(We.string(),rlo).refine(e=>{let t=Object.keys(e);return t.some(n=>{let i=e[n];return typeof i=="string"?i.trim().length>=10:Array.isArray(i)?i.length>0:typeof i=="object"&&i!==null?Object.keys(i).length>0:!1})&&t.length>0},"Protocol should contain at least one meaningful section with content"),LRs=We.object({name:We.string().min(1,"Protocol name is required"),description:We.string().min(10,"Protocol description should be at least 10 characters")}).catchall(tlo).refine(e=>{let t=["name","description"],r=Object.keys(e).filter(i=>!t.includes(i));if(r.length!==1)return!1;let n=e[r[0]];return tlo.safeParse(n).success},"Protocol should have exactly one root key containing the protocol structure (in addition to name and description)");function zRs(e){let t=LRs.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,errors:t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`)}}function URs(e){let t=100;return t-=e.errors.length*25,t-=e.warnings.length*5,t-=e.advisories.length*1,Math.max(0,t)}function jRs(e){let r={filename:"unknown",type:"protocol",status:"excellent",errors:[],warnings:[],advisories:[],score:0},n=zRs(e);return!n.success&&n.errors&&n.errors.forEach(i=>{i.includes("should be at least")||i.includes("should not exceed")||i.includes("should start with")||i.includes("should use")?r.advisories.push(`ADVISORY: ${i}`):i.includes("required")||i.includes("should contain")||i.includes("should have at least")?r.errors.push(`CRITICAL: ${i}`):r.warnings.push(`WARNING: ${i}`)}),r.score=URs(r),r.errors.length===0&&r.warnings.length===0?r.status="excellent":r.errors.length===0?r.status="good_with_warnings":r.status="critical_error",r}import{describe as BRs,test as nlo,expect as ilo}from"bun:test";import{lstatSync as qRs,existsSync as ZRs}from"fs";import{join as olo,basename as WRs,dirname as put}from"path";async function VRs(e){let t=await c0(["method"],e);BRs("Category Link Validation",()=>{nlo("All method categories should have valid symbolic links",()=>{if(t.length===0){console.log("\u23ED\uFE0F Skipping category link validation - no method items found");return}let r=[];for(let n of t){let i=n.filePath,o=n.category;if(!o)continue;let a=WRs(put(i)),s=put(put(i)),u=put(s),c=olo(u,"categories"),l=olo(c,o,a);if(!ZRs(l)){r.push(`${l} not exists`);continue}try{qRs(l).isSymbolicLink()||r.push(`Not Link: ${l}`)}catch(f){r.push(`Error reading link ${l}: ${f}`)}}r.length>0&&console.error(`\u274C Link validation failures:
639
+ ${x}`)}return HV({message:g})}else{let{method:{references:{referenceInstructions:p}={},...g},tactical_notes:x,...T}=d,O=$T(f.scriptResult,["content"],f.scriptResult);return HV({success:f.scriptSuccess!=null?f.scriptSuccess:!0,instructions:[{message:`${o} EXECUTED!`,currentTimeAtUTC:new Date().toISOString()},T]},[{methodParams:Object.keys(c||{}).length?c:void 0,methodContent:g},{references:p,tactical_notes:x},...dmr(O)])}}catch(l){return kse(l,hz)}}},_Counter__DeployWorkflow:{description:"Deploy workflow",inputSchema:ugi,execute:async({callSign:i})=>{let o=await c0(["workflow"],e),{resolveName:a}=Xco(i,"workflow"),{promptData:s}=await V2(o,a)||{};try{if(!s)throw new Error(`WORKFLOW '${i}' not found. Available methods: ${o.map(u=>u.id).join(", ")}`);return HV(s)}catch(u){return kse(u,"_Counter__DeployWorkflow")}}},_Counter__PartyMode:{description:await cRs(),inputSchema:ogi,execute:async({topic:i,context:o="General discussion",recommendedHeroes:a,deployedHeroes:s})=>{try{let{availableHeroes:u,selectedHeroes:c}=await lRs(e,a,s),l=await c0(["persona"],e),d=(await Promise.all(c.map(async T=>({...T,deployedContent:(await V2(l,T.callSign,{partyMode:!0,activeHeroes:c})||{})?.promptData,deploymentStatus:"AUTO_DEPLOYED"})))).map(T=>({callSign:T.callSign,name:T.name,description:T.description,icon:T.deployedContent?.agent?.icon,methods:T.deployedContent?.methods,partyMode:!0})),p=d.map(T=>`${T.icon} ${T.name} (${T.callSign})`).join(", "),g=u.filter(T=>!c.some(O=>O.id===T.id)).map(T=>`${T.name} (${T.callSign})`).join(", "),x=(await GR(lyr,{activeHeroes:p,topic:i,context:o}))?.PartyMode;return HV({message:"READY_FOR_AUTO_FACILITATION",instructions:[{availableHeroesDisplay:g}]},[{partyModeProtocol:x},{activeHeroes:d}])}catch(u){return kse(u,"PartyMode")}}}};if(t!=null){let i=t;for(let o of r)i.addPrompt({name:o.id,load:async()=>`*${o.id}`})}return Ghr(n,t)};var gh={ARRAY_MIN_ITEMS:1,ARRAY_MAX_ITEMS:20,GROUP_MIN_COUNT:2,GROUP_MAX_COUNT:5,ITEM_MIN_LENGTH:30,ITEM_MAX_LENGTH:200,GROUP_ITEM_MAX:6,GROUP_ITEM_MIN:1,TOTAL_ITEMS_MIN:3,TOTAL_ITEMS_MAX:20,GROUP_NAME_PATTERN:/^[a-z0-9-]+$/};var $Te={MIN_LENGTH:20,MAX_LENGTH:500};var dut=We.lazy(()=>We.union([We.string().min(1,"Execution flow step cannot be empty"),We.array(We.lazy(()=>dut)).min(1,"Nested array must contain at least one step").max(10,"Nested array should not exceed 10 steps for clarity")])),sM=We.array(dut).min(1,"Execution flow must contain at least one step").max(15,"Execution flow should not exceed 15 steps for clarity").optional();var elo=We.string().min(gh.ITEM_MIN_LENGTH,`Output item should be at least ${gh.ITEM_MIN_LENGTH} characters`).max(gh.ITEM_MAX_LENGTH,`Output item should not exceed ${gh.ITEM_MAX_LENGTH} characters`).regex(/^[A-Z]/,"Output item should start with capital letter").refine(e=>![/comprehensive analysis/i,/detailed report/i,/complete overview/i,/thorough assessment/i].some(r=>r.test(e)),"Output item contains generic phrase - be more specific"),dRs=We.array(elo).min(gh.ARRAY_MIN_ITEMS,`Expected output should contain at least ${gh.ARRAY_MIN_ITEMS} items`).max(gh.ARRAY_MAX_ITEMS,`Expected output should not exceed ${gh.ARRAY_MAX_ITEMS} items for readability`),pRs=We.record(We.string().regex(gh.GROUP_NAME_PATTERN,"Group name should be lowercase with dashes and numbers only"),We.array(elo).min(gh.GROUP_ITEM_MIN,`Group should contain at least ${gh.GROUP_ITEM_MIN} item`).max(gh.GROUP_ITEM_MAX,`Group should not exceed ${gh.GROUP_ITEM_MAX} items for optimal cognitive load`)).refine(e=>Object.keys(e).length>=gh.GROUP_MIN_COUNT,`Nested expected_output should contain at least ${gh.GROUP_MIN_COUNT} groups`).refine(e=>Object.keys(e).length<=gh.GROUP_MAX_COUNT,`Nested expected_output should not exceed ${gh.GROUP_MAX_COUNT} groups for readability`).refine(e=>Object.values(e).reduce((r,n)=>r+n.length,0)>=gh.TOTAL_ITEMS_MIN,`Total items across all groups should be at least ${gh.TOTAL_ITEMS_MIN}`).refine(e=>Object.values(e).reduce((r,n)=>r+n.length,0)<=gh.TOTAL_ITEMS_MAX,`Total items across all groups should not exceed ${gh.TOTAL_ITEMS_MAX} for readability`),hRs=We.union([dRs,pRs]),mRs=We.string().min($Te.MIN_LENGTH,`Purpose field should be at least ${$Te.MIN_LENGTH} characters`).max($Te.MAX_LENGTH,`Purpose field should not exceed ${$Te.MAX_LENGTH} characters`).regex(/^[A-Z]/,"Purpose should start with capital letter").regex(/[.!]$/,"Purpose should end with punctuation"),gRs=We.object({description:We.string().min(1,"Parameter description is required"),type:We.enum(["string","number","integer","boolean","array","object"]).optional(),required:We.boolean().default(!1),options:We.array(We.string()).optional(),default:We.union([We.string(),We.number(),We.boolean()]).optional()}).catchall(We.unknown()),yRs=We.object({method:We.string().min(1,"Usage method is required"),parameters:We.record(We.string(),gRs).optional(),examples:We.array(We.string()).optional(),elicit:We.boolean().optional()}).strict(),bRs=We.object({name:We.string().regex(/^\*[a-z0-9-]+$/,"Method name should start with * and use lowercase with hyphens and numbers"),icon:We.string().min(1,"Method icon is required"),category:We.string().min(1,"Method category is required"),introduce:We.string().min(1,"Method introduce is required"),usage:yRs,agent_compatibility:We.array(We.string()).min(1,"Agent compatibility is required and must contain at least one agent"),references:We.record(We.string(),We.object({description:We.string().min(1,"Reference description is required"),content:We.string().optional()})).optional()}).strict(),xRs=We.object({template_ref:We.string().min(1,"Template reference filename is required"),description:We.string().min(1,"Template description is required"),when_to_trigger:We.array(We.string()).optional()}).strict(),vRs=We.array(xRs).min(1,"Template integration must be an array containing at least one template"),_Rs=We.object({method:We.string().min(1,"Method is required for composition").regex(/^\*[a-z0-9-]+(\s+[^\s]+)*$/,"Method must start with * and follow method syntax with optional parameters like [target], [target]-suffix, keywords, or --flags"),purpose:We.string().min(1,"Purpose is required for composition item").max(200,"Purpose should not exceed 200 characters for clarity"),execution_flow:sM,when_to_trigger:sM}).strict(),SRs=We.record(We.string().regex(/^[a-z0-9-]+$/,"Composition key should be lowercase with hyphens and numbers only"),_Rs).refine(e=>Object.keys(e).length>=1,"Composition must contain at least one method").refine(e=>Object.keys(e).length<=10,"Composition should not exceed 10 methods for clarity").optional(),wRs=We.record(We.string(),We.array(We.union([We.string().min(1,"Action checklist item cannot be empty"),We.record(We.string(),We.string().min(1,"Protocol reference cannot be empty"))]))).optional(),kRs=We.object({purpose:We.string().min(1,"Usage mode purpose is required"),execution_flow:sM,fallback:We.array(We.string().min(1,"Fallback step cannot be empty")).optional(),when_to_trigger:sM,usage_example:We.array(We.string().min(1,"Usage example cannot be empty")).min(1,"At least one usage example is required when usage_example is specified").max(3,"Usage examples should not exceed 5 for clarity").optional()}).strict(),ERs=We.record(We.string().regex(/^[a-z0-9-]+$/,"Usage mode key should be lowercase with hyphens and numbers only"),kRs).optional(),IRs=We.object({validation_protocols:We.record(We.string(),We.any()).optional(),action_checklists:We.union([wRs,We.array(We.string())]),mission_critical:sM}).strict(),TRs=We.any().superRefine((e,t)=>{if(e&&typeof e=="object"){let n=Object.keys(e);if(n[n.length-1]!=="mission_critical")return t.addIssue({code:"custom",message:`mission_critical must be the last property in tactical_notes (current order: ${n.join(", ")})`,path:[]}),We.NEVER}let r=IRs.safeParse(e);r.success||r.error.issues.forEach(n=>{t.addIssue({code:"custom",message:`${n.code}: ${n.message}`,path:n.path})})}),ARs=We.object({purpose:mRs,expected_output:hRs,composition:SRs}).strict(),CRs=We.object({method:bRs,methodology:ARs,template_integration:vRs.optional(),integration_protocols:We.record(We.string(),We.any()).optional(),usage_modes:ERs,multi_market_integration:We.record(We.string(),We.any()).optional(),data_sources:We.record(We.string(),We.any()).optional(),tactical_notes:TRs}).catchall(We.unknown()).refine(e=>{let t=["method","methodology","template_integration","tactical_notes","integration_protocols","usage_modes","multi_market_integration","data_sources"],n=Object.keys(e).filter(i=>!t.includes(i)).filter(i=>!i.endsWith("-tmpl")&&!i.endsWith("-protocol"));return n.length&&console.dir(n,{deep:!0}),n.length===0},{message:"Additional root properties found."});function fyr(e,t){let r=CRs.safeParse(e);if(r.success)return{success:!0,data:r.data};{let n=t?`${t}: `:"";return{success:!1,errors:r.error.issues.map(i=>`${n}${i.path.join(".")}: ${i.message}`)}}}var ORs=We.object({header_sections:We.array(We.string()).optional().describe("Header content sections"),separators:We.record(We.string(),We.string()).optional().describe("Visual separator content as Record<string, string>"),body_sections:We.array(We.string()).optional().describe("Main content sections"),footer_sections:We.array(We.string()).optional().describe("Footer content sections")}).strict().describe("Template output structure configuration - strict validation enforces consistent *_sections naming pattern"),MRs=We.record(We.string(),We.any()).describe("Display format and presentation specifications - accepts any key-value pairs"),RRs=We.object({format:We.string().optional().describe("Output format specification"),filename:We.string().optional().describe("Filename pattern for template output"),structure:ORs.optional().describe("Output structure configuration")}).describe("Template output configuration"),PRs=We.object({title:We.string().optional().describe("Section title"),description:We.string().optional().describe("Section description"),sub_sections:We.array(We.string()).optional().describe("List of sub-section descriptions"),content:We.string().optional().describe("Plaintext content for examples and long text"),type:We.string().optional().describe("Section type classification"),focus:We.string().optional().describe("Section focus area")}).catchall(We.unknown()).describe("Individual template section configuration"),DRs=We.record(We.string(),PRs).describe("Template sections and content structure"),NRs=We.object({output:RRs.optional(),display_format:MRs.optional().describe("Display format specifications")}).strict().describe("Core template configuration"),$Rs=We.object({template:NRs.describe("Required template configuration section"),execution_flow:sM.optional().describe("Root-level execution flow specification"),sections:DRs.describe("REQUIRED: Root-level sections specification")}).strict().describe("Template content structure"),FRs=We.object({name:We.string().min(1,"Template name is required and must not be empty").describe("Template name from YAML frontmatter"),description:We.string().min(1,"Template description is required and must not be empty").describe("Template description from YAML frontmatter")}).catchall($Rs).describe("Complete template file with metadata (name, description) and exactly one template-name key containing template content");function pz(e){let t=FRs.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,errors:t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`)}}var rlo=We.union([We.string().min(10,"Protocol content should be at least 10 characters"),We.array(We.union([We.string().min(3,"Array item should be at least 3 characters"),We.record(We.string(),We.any())])).min(1,"Array should not be empty"),We.record(We.string(),We.union([We.string().min(3,"Object value should be at least 3 characters"),We.array(dut),We.record(We.string(),We.any())])).refine(e=>Object.keys(e).length>0,"Object should not be empty"),We.lazy(()=>We.record(We.string(),rlo))]),tlo=We.record(We.string(),rlo).refine(e=>{let t=Object.keys(e);return t.some(n=>{let i=e[n];return typeof i=="string"?i.trim().length>=10:Array.isArray(i)?i.length>0:typeof i=="object"&&i!==null?Object.keys(i).length>0:!1})&&t.length>0},"Protocol should contain at least one meaningful section with content"),LRs=We.object({name:We.string().min(1,"Protocol name is required"),description:We.string().min(10,"Protocol description should be at least 10 characters")}).catchall(tlo).refine(e=>{let t=["name","description"],r=Object.keys(e).filter(i=>!t.includes(i));if(r.length!==1)return!1;let n=e[r[0]];return tlo.safeParse(n).success},"Protocol should have exactly one root key containing the protocol structure (in addition to name and description)");function zRs(e){let t=LRs.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,errors:t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`)}}function URs(e){let t=100;return t-=e.errors.length*25,t-=e.warnings.length*5,t-=e.advisories.length*1,Math.max(0,t)}function jRs(e){let r={filename:"unknown",type:"protocol",status:"excellent",errors:[],warnings:[],advisories:[],score:0},n=zRs(e);return!n.success&&n.errors&&n.errors.forEach(i=>{i.includes("should be at least")||i.includes("should not exceed")||i.includes("should start with")||i.includes("should use")?r.advisories.push(`ADVISORY: ${i}`):i.includes("required")||i.includes("should contain")||i.includes("should have at least")?r.errors.push(`CRITICAL: ${i}`):r.warnings.push(`WARNING: ${i}`)}),r.score=URs(r),r.errors.length===0&&r.warnings.length===0?r.status="excellent":r.errors.length===0?r.status="good_with_warnings":r.status="critical_error",r}import{describe as BRs,test as nlo,expect as ilo}from"bun:test";import{lstatSync as qRs,existsSync as ZRs}from"fs";import{join as olo,basename as WRs,dirname as put}from"path";async function VRs(e){let t=await c0(["method"],e);BRs("Category Link Validation",()=>{nlo("All method categories should have valid symbolic links",()=>{if(t.length===0){console.log("\u23ED\uFE0F Skipping category link validation - no method items found");return}let r=[];for(let n of t){let i=n.filePath,o=n.category;if(!o)continue;let a=WRs(put(i)),s=put(put(i)),u=put(s),c=olo(u,"categories"),l=olo(c,o,a);if(!ZRs(l)){r.push(`${l} not exists`);continue}try{qRs(l).isSymbolicLink()||r.push(`Not Link: ${l}`)}catch(f){r.push(`Error reading link ${l}: ${f}`)}}r.length>0&&console.error(`\u274C Link validation failures:
640
640
  ${r.join(`
641
641
  `)}`),ilo(r.length).toBe(0)}),nlo("should discover all method items",()=>{if(t.length===0){console.log("\u23ED\uFE0F Skipping method discovery check - no method items found");return}ilo(t.length).toBeGreaterThan(0),console.log(`\u2705 Validated ${t.length} method category links`)})})}import{describe as HRs,test as GRs,expect as JRs}from"bun:test";async function KRs(e){let t=await c0(["method"],e);HRs("General Method Validation",()=>{GRs("All method files should pass validation",async()=>{if(t.length===0){console.log("\u23ED\uFE0F Skipping method validation - no method items found");return}let r=[];for(let n of t){let{promptData:i}=await V2(t,n.callSign)||{};i&&(delete i.callSign,delete i.name,delete i.description,delete i.method.references);let o=fyr(i,n.filePath);if(!o.success){let a=o.errors?.map(s=>`
642
642
  \u2192 ${s}`).join("")||"Unknown error";r.push(`\u{1F4C4} ${n.id}:${a}`)}}if(r.length>0)throw console.error(`
@@ -999,12 +999,6 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
999
999
  template_not_found:
1000
1000
  action: "Use direct analysis mode"
1001
1001
  attribution: "Template Used: none (file not found: [filename])"
1002
- template_syntax_error:
1003
- action: "Log error, use fallback template or direct mode"
1004
- attribution: "Template Used: none (syntax error in [filename])"
1005
- circular_reference:
1006
- action: "Break loop, use direct mode"
1007
- attribution: "Template Used: none (circular reference detected)"
1008
1002
 
1009
1003
  # PERSONA PERSISTENCE PROTOCOL: Persona identity MUST persist throughout all technical operations
1010
1004
  persona_persistence:
@@ -1044,21 +1038,6 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
1044
1038
  error_handling_and_validation:
1045
1039
  purpose: "Comprehensive error prevention, detection, recovery procedures, and system validation"
1046
1040
 
1047
- method_execute_failures:
1048
- method_not_found:
1049
- symptoms: "Error: Method '*invalid-method' not found"
1050
- recovery_steps:
1051
- - "1. Check method name spelling and asterisk format"
1052
- - "2. Run \`_Counter__ExecuteMethod({method: '*assemble'})\` to see available methods"
1053
- - "3. Suggest closest matching method if possible"
1054
- code_example: "_Counter__ExecuteMethod({method: '*code'}) // Correct format"
1055
-
1056
- network_errors:
1057
- symptoms: "Cannot reach MCP method execute service"
1058
- recovery_steps:
1059
- - "1. Verify MCP connection status"
1060
- - "2. Inform user of reduced capabilities during outage"
1061
-
1062
1041
  persona_state_issues:
1063
1042
  identity_loss:
1064
1043
  symptoms: "Agent responses without <hero_signature /> or style"
@@ -1075,27 +1054,6 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
1075
1054
  - "2. Offer alternative methods within persona scope"
1076
1055
  - "3. Maintain persona identity throughout interaction"
1077
1056
 
1078
- protocol_precedence:
1079
- conflict_resolution_order: "When multiple protocols conflict, resolution follows this precedence hierarchy."
1080
-
1081
- precedence_hierarchy:
1082
- - "PRIORITY 1: template_precedence (highest - overrides restrictions for analysis methods)"
1083
- - "PRIORITY 2: persona_persistence (maintains identity consistency throughout session)"
1084
- - "PRIORITY 3: method_execute (ensures proper method execution)"
1085
-
1086
- practical_examples:
1087
- scenario_1:
1088
- situation: "User requests analysis while hero is active, template exists"
1089
- conflict: "Template wants direct analysis, persona wants hero response"
1090
- resolution: "Template wins \u2192 Use template for analysis, maintain hero_signature"
1091
- result: "Analysis uses template format, response ends with <hero_signature />"
1092
-
1093
- scenario_2:
1094
- situation: "Long technical implementation with multiple file operations"
1095
- conflict: "Technical operations might terminate persona persistence"
1096
- resolution: "Persona persistence wins \u2192 Hero identity maintained throughout"
1097
- result: "All operations maintain hero style, end with <hero_signature />"
1098
-
1099
1057
  agent_activation_execution:
1100
1058
  user_request_intelligent_matching:
1101
1059
  rule: "Match request to right method via natural language interpretation. Execute. Auto-load all references that matter to the request. Return complete answer without extra steps."
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.2",
2
+ "version": "0.6.4",
3
3
  "name": "@modality-counter/core",
4
4
  "repository": {
5
5
  "type": "git",