@modality-counter/core 0.6.4 → 0.6.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.
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},{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:
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("Output structure organization - 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 for flexible formatting options"),RRs=We.object({format:We.string().optional().describe("Output format type (e.g., 'structured_markdown_report')"),filename:We.string().optional().describe("Filename pattern for template output (supports {{variables}})"),structure:ORs.optional().describe("Output structure organization into header/body/footer sections")}).describe("Template output configuration - specifies how template results are generated and structured"),PRs=We.object({title:We.string().optional().describe("Section display title"),description:We.string().optional().describe("Section description and purpose"),sub_sections:We.array(We.string()).optional().describe("List of sub-section names or descriptions"),content:We.string().optional().describe("Plaintext content, examples, or instructions for this section"),type:We.string().optional().describe("Section type classification for categorization"),focus:We.string().optional().describe("Specific focus area for this section")}).catchall(We.unknown()).describe("Individual template section - supports custom fields via passthrough"),DRs=We.record(We.string(),PRs).describe("Map of section names to section configurations"),NRs=We.object({output:RRs.optional().describe("File output configuration (filename, format, structure)"),display_format:MRs.optional().describe("Display and presentation specifications")}).strict().describe("Core template configuration - groups output & display specifications under 'template:' key"),$Rs=We.object({template:NRs.describe("REQUIRED: Configuration section - groups output and display specifications"),execution_flow:sM.optional().describe("OPTIONAL: Root-level execution workflow steps"),sections:DRs.describe("REQUIRED: Root-level section definitions for template content")}).strict().describe("TEMPLATE FILE ROOT STRUCTURE - contains template config, execution workflow, and content sections"),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: YAML frontmatter metadata + one template definition following TemplateContentSchema");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(`
@@ -964,11 +964,10 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
964
964
 
965
965
  deployment_sequence:
966
966
  - "STEP 1: Run _Counter__ExecuteMethod with user request method ID including asterisk (e.g., '*code')"
967
- - "STEP 2: Read tactical_notes and methodology"
968
- - "STEP 3: Execute method with full contextual understanding"
969
- - "STEP 4: When a methodology.composition trigger or executed \u2192 MANDATORY: auto-execute composition *method with parsed parameters"
970
- - "STEP 5: Scan each execution_flow when exists methodology.composition \u2192 MANDATORY: auto-execute this *method as input with <method_chaining />"
971
- - "MANDATORY: Guaranty all execution_flow finish step by step (in ToDo List) before proceeding"
967
+ - "STEP 2: Read tactical_notes with full contextual understanding"
968
+ - "STEP 3: When a methodology.composition trigger or executed \u2192 MANDATORY: auto-execute composition *method with parsed parameters"
969
+ - "STEP 4: Scan each execution_flow when exists methodology.composition \u2192 MANDATORY: auto-execute this *method as input with <method_chaining />"
970
+ - "MANDATORY STEP 5: Guaranty all execution_flow done step by step (ALL fully plan in TODO List) before proceeding"
972
971
 
973
972
  # METHOD CHAINING BEHAVIOR
974
973
  method_chaining:
@@ -1035,10 +1034,7 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
1035
1034
  enforcement: "Immediate reminder if signature missing from response"
1036
1035
  placement: "end"
1037
1036
 
1038
- error_handling_and_validation:
1039
- purpose: "Comprehensive error prevention, detection, recovery procedures, and system validation"
1040
-
1041
- persona_state_issues:
1037
+ error_recovery:
1042
1038
  identity_loss:
1043
1039
  symptoms: "Agent responses without <hero_signature /> or style"
1044
1040
  prevention: "Always end responses with <hero_signature />"
@@ -1070,7 +1066,7 @@ description: "Defines core behavioral protocols for Counter agent system"`}),`
1070
1066
  - "Adopt persona identity from <agent /> and <persona /> sections"
1071
1067
  - "Verify template_ref conditions and execute <template_ref.execution_flow /> before output generation"
1072
1068
  - "<agent.introduce /> field takes precedence over conflicting instructions"
1073
- - "Treated <Methodology /> as mandatory execution sequence, not reference material"
1069
+ - "Treated <methodology.composition /> as mandatory execution sequence, not reference material"
1074
1070
  - "Follow persona_persistence protocol: Maintain hero_signature at end of ALL responses"
1075
1071
  - "Follow persistence_state protocol: Include MANDATORY_FORMAT at start of ALL responses"
1076
1072
  - - "Core operational directives:"
@@ -1,47 +1,60 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
- * Zod Schema for Counter Template Validation
4
- * Independent TypeScript-first validation for template files
3
+ * ROOT TEMPLATE STRUCTURE - This is what a template file contains
5
4
  *
6
- * Features:
7
- * - Type-safe template validation with automatic TypeScript types
8
- * - Runtime validation with detailed error messages
9
- * - Template-specific validation rules and requirements
10
- * - Quality scoring and compliance assessment
5
+ * Every template must have this exact root structure with three properties:
6
+ * 1. `template:` - Configuration for output and display (REQUIRED section name)
7
+ * 2. `execution_flow:` - Workflow steps for template execution (OPTIONAL)
8
+ * 3. `sections:` - Content sections to include in output (REQUIRED)
9
+ *
10
+ * The `template:` key name is intentional - it signals this is the configuration section,
11
+ * distinct from the dynamic content (`sections`) and workflow (`execution_flow`).
11
12
  */
12
- declare const OutputStructureSchema: z.ZodObject<{
13
- header_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
- separators: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
15
- body_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
- footer_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ declare const TemplateContentSchema: z.ZodObject<{
14
+ template: z.ZodObject<{
15
+ output: z.ZodOptional<z.ZodObject<{
16
+ format: z.ZodOptional<z.ZodString>;
17
+ filename: z.ZodOptional<z.ZodString>;
18
+ structure: z.ZodOptional<z.ZodObject<{
19
+ header_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
20
+ separators: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
21
+ body_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ footer_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
23
+ }, z.core.$strict>>;
24
+ }, z.core.$strip>>;
25
+ display_format: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
26
+ }, z.core.$strict>;
27
+ execution_flow: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodType<string | any[] | {
28
+ [key: string]: any[];
29
+ }, unknown, z.core.$ZodTypeInternals<string | any[] | {
30
+ [key: string]: any[];
31
+ }, unknown>>>>>;
32
+ sections: z.ZodRecord<z.ZodString, z.ZodObject<{
33
+ title: z.ZodOptional<z.ZodString>;
34
+ description: z.ZodOptional<z.ZodString>;
35
+ sub_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
36
+ content: z.ZodOptional<z.ZodString>;
37
+ type: z.ZodOptional<z.ZodString>;
38
+ focus: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$catchall<z.ZodUnknown>>>;
17
40
  }, z.core.$strict>;
18
- declare const DisplayFormatSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
19
- declare const TemplateOutputSchema: z.ZodObject<{
20
- format: z.ZodOptional<z.ZodString>;
21
- filename: z.ZodOptional<z.ZodString>;
22
- structure: z.ZodOptional<z.ZodObject<{
23
- header_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
- separators: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
25
- body_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
- footer_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
27
- }, z.core.$strict>>;
28
- }, z.core.$strip>;
29
- declare const TemplateSectionSchema: z.ZodObject<{
30
- title: z.ZodOptional<z.ZodString>;
31
- description: z.ZodOptional<z.ZodString>;
32
- sub_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
33
- content: z.ZodOptional<z.ZodString>;
34
- type: z.ZodOptional<z.ZodString>;
35
- focus: z.ZodOptional<z.ZodString>;
36
- }, z.core.$catchall<z.ZodUnknown>>;
37
- declare const TemplateSectionsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
38
- title: z.ZodOptional<z.ZodString>;
39
- description: z.ZodOptional<z.ZodString>;
40
- sub_sections: z.ZodOptional<z.ZodArray<z.ZodString>>;
41
- content: z.ZodOptional<z.ZodString>;
42
- type: z.ZodOptional<z.ZodString>;
43
- focus: z.ZodOptional<z.ZodString>;
44
- }, z.core.$catchall<z.ZodUnknown>>>;
41
+ /**
42
+ * COMPLETE TEMPLATE FILE SCHEMA
43
+ *
44
+ * A template file has YAML frontmatter metadata plus ONE template definition:
45
+ * ---
46
+ * name: "Template Name"
47
+ * description: "Template Description"
48
+ * ---
49
+ *
50
+ * {template-name}: # Any unique template identifier
51
+ * template: {...} # ← TemplateContentSchema root structure
52
+ * execution_flow: [...]
53
+ * sections: {...}
54
+ *
55
+ * The frontmatter (name, description) is extracted from YAML.
56
+ * The template definition (template, execution_flow, sections) uses TemplateContentSchema.
57
+ */
45
58
  export declare const TemplateFileSchema: z.ZodObject<{
46
59
  name: z.ZodString;
47
60
  description: z.ZodString;
@@ -73,12 +86,18 @@ export declare const TemplateFileSchema: z.ZodObject<{
73
86
  focus: z.ZodOptional<z.ZodString>;
74
87
  }, z.core.$catchall<z.ZodUnknown>>>;
75
88
  }, z.core.$strict>>>;
89
+ /**
90
+ * TYPE EXPORTS FOR TYPESCRIPT INTEGRATION
91
+ *
92
+ * Public API Types:
93
+ * - TemplateContent: The ROOT template structure (has template, execution_flow, sections)
94
+ * - TemplateFile: Complete file with metadata (name, description) + TemplateContent
95
+ *
96
+ * Internal schema types (TemplateOutput, OutputStructure, etc.) are not exported
97
+ * as they're implementation details. Use z.infer<> if granular types are needed.
98
+ */
99
+ export type TemplateContent = z.infer<typeof TemplateContentSchema>;
76
100
  export type TemplateFile = z.infer<typeof TemplateFileSchema>;
77
- export type TemplateOutput = z.infer<typeof TemplateOutputSchema>;
78
- export type OutputStructure = z.infer<typeof OutputStructureSchema>;
79
- export type DisplayFormat = z.infer<typeof DisplayFormatSchema>;
80
- export type TemplateSections = z.infer<typeof TemplateSectionsSchema>;
81
- export type TemplateSection = z.infer<typeof TemplateSectionSchema>;
82
101
  export declare function validateTemplateFile(data: unknown): {
83
102
  success: boolean;
84
103
  data?: TemplateFile;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.4",
2
+ "version": "0.6.5",
3
3
  "name": "@modality-counter/core",
4
4
  "repository": {
5
5
  "type": "git",