@modality-counter/core 0.6.6 → 0.6.7

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
@@ -421,7 +421,7 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
421
421
  `),r=/^---\n([\s\S]+?)\n---/,n=t.match(r);if(!n||!n[1])return{};let i=n[1].trim(),o=i.split(`
422
422
  `).filter(s=>s.trim());if(!o.every(s=>{let u=s.trim();return/^[#`*\-]/.test(u)?!1:s.includes(":")}))return{};try{let s=Nba.parse(i);return typeof s!="object"||s===null||Array.isArray(s)?{}:s}catch{let s={};for(let u of o){let c=u.indexOf(":");if(c>0){let l=u.slice(0,c).trim(),f=u.slice(c+1).trim();l&&(s[l]=f)}}return s}}var qqe=e=>{let t=$ba($ui(e)());return zba.translate(t)},Uba=e=>e.endsWith(".mdx")||e.endsWith(".md")?e:`${e}.mdx`,Ujt=async e=>{if(e==null)throw new Error(`Invalid file path: ${e}. Path must be relative and have .md or .mdx extension.`);let t=Uba(e),r=jba(),n=Lba(r,t);return await Bba(n)},jba=()=>{let e="";try{_NOT_DEFINED}catch(t){let r=t,n=r.stack?.match(/^\s*at\s+\/[^\s:()]+\.\w+:\d+:\d+$/m)?.[0].trim();if(n||(n=r.stack?.split(`
423
423
  `).filter(i=>i.indexOf("at load")!==-1).pop()),n||(n=r.stack?.split(`
424
- `).filter(i=>i.indexOf("at <anonymous>")!==-1).pop()),n){let i=/(?<path>[^\(\s]+):[0-9]+:[0-9]+/.exec(n)?.groups?.path.replace("file://","");e=Fba(i||"")}}return e||process.cwd()},Bba=async e=>{try{let t=await import(e);if(typeof t.default!="function")throw new Error(`MDX file at ${e} does not export a valid React component. ${t.default}`);return t.default}catch(t){throw console.error(`Failed to import MDX file: ${e}`),t}};import{YAML as Wba}from"bun";import{jsx as egi}from"react/jsx-runtime";function rgi(e,t){let r={...e};return jjt(e)&&jjt(t)&&Object.keys(t).forEach(n=>{Array.isArray(t[n])?Array.isArray(r[n])?r[n].push(...t[n]):r[n]=t[n]:jjt(t[n])&&n in e?r[n]=rgi(e[n],t[n]):r[n]=t[n]}),r}function jjt(e){return e&&typeof e=="object"&&!Array.isArray(e)}var ngi=async(e,t)=>{if(typeof e=="string"){let r=await Ujt(e);return qqe(egi(r,{...t}))}else return qqe(egi(e,{...t}))},GR=async(e,t)=>{let r=await ngi(e,t),o=igi(r).filter(a=>a.language==="yaml"||a.language==="yml").reduce((a,s)=>{let u=Wba.parse(s.code);return rgi(a,u)},{});if(typeof e=="string"){let a=tgi(e,"utf-8"),s=Jee(a);Object.assign(o,s)}return o};function Vba(e){try{let t=__dirname||Zba(__filename),r=qba(t,"prompts",e);return tgi(r,"utf-8")}catch(t){throw console.error(`Failed to read prompt file: ${e}`,t),new Error(`Could not load prompt: ${e}`)}}function igi(e){let t=/```(\w+)?\n?([\s\S]*?)\n?```/g,r=[],n;for(;(n=t.exec(e))!==null;)r.push({language:n[1]?.toLowerCase().trim()||"",code:n[2].trim()});return r}import{existsSync as Uno,readFileSync as u6s}from"fs";import{join as c6s,basename as iTe,extname as l6s,dirname as jno}from"path";var Zqe=["persona","method","workflow"],ogi=We.object({topic:We.string().describe("The topic for the Counter to discuss and debate"),context:We.string().optional().describe("Optional additional context or background for the discussion"),recommendedHeroes:We.array(We.string()).optional().describe("Optional array of recommended hero names or call signs to prioritize for the discussion"),deployedHeroes:We.array(We.string()).optional().describe("CRITICAL: Array of hero names or call signs already active in current session - prevents duplicate deployment and maintains session continuity. Use when adding heroes to existing active sessions.")}).describe("Start a party mode discussion with all Counter heroes"),agi=We.object({method:We.string().describe("The method name to execute"),params:We.record(We.string(),We.any()).optional().describe("Parameters for the method")}),sgi=We.object({callSign:We.string().describe("The callSign to deploy (e.g., 'SARAH', 'JAMES')")}).describe("Deploy a specific Counter hero persona"),ugi=We.object({callSign:We.string().describe("The workflow identifier to deploy (e.g., 'team-architect')")}).describe("Execute a specific Counter workflow for multi-step task orchestration"),cgi=We.object({types:We.array(We.enum(Zqe)).default(["persona"]).describe("Array of resource types to filter by. Defaults to ['persona'] for hero listings")}).describe("Get Counter resources filtered by type");kno();var Ghr=(e,t)=>(t&&Object.entries(e).forEach(([r,n])=>{let i=n.name!=null?n.name:r,{inputSchema:o,...a}=n;t.addTool({...a,parameters:o,name:i})}),e);tmr();tmr();var vRu=300*1e3,_Ru={initialize:1800*1e3,"tools/list":300*1e3,"resources/list":60*1e3,"prompts/list":300*1e3};async function V2(e,t,r,n){let i=e.find(o=>o.callSign===t.trim());try{if(!i)return!1;let o;r?.partyMode&&(o=`**PARTY MODE ACTIVE - ENGAGE OPENING PHASE PROTOCOLS NOW!**
424
+ `).filter(i=>i.indexOf("at <anonymous>")!==-1).pop()),n){let i=/(?<path>[^\(\s]+):[0-9]+:[0-9]+/.exec(n)?.groups?.path.replace("file://","");e=Fba(i||"")}}return e||process.cwd()},Bba=async e=>{try{let t=await import(e);if(typeof t.default!="function")throw new Error(`MDX file at ${e} does not export a valid React component. ${t.default}`);return t.default}catch(t){throw console.error(`Failed to import MDX file: ${e}`),t}};import{YAML as Wba}from"bun";import{jsx as egi}from"react/jsx-runtime";function rgi(e,t){let r={...e};return jjt(e)&&jjt(t)&&Object.keys(t).forEach(n=>{Array.isArray(t[n])?Array.isArray(r[n])?r[n].push(...t[n]):r[n]=t[n]:jjt(t[n])&&n in e?r[n]=rgi(e[n],t[n]):r[n]=t[n]}),r}function jjt(e){return e&&typeof e=="object"&&!Array.isArray(e)}var ngi=async(e,t)=>{if(typeof e=="string"){let r=await Ujt(e);return qqe(egi(r,{...t}))}else return qqe(egi(e,{...t}))},GR=async(e,t)=>{let r=await ngi(e,t),o=igi(r).filter(a=>a.language==="yaml"||a.language==="yml").reduce((a,s)=>{let u=Wba.parse(s.code);return rgi(a,u)},{});if(typeof e=="string"){let a=tgi(e,"utf-8"),s=Jee(a);Object.assign(o,s)}return o};function Vba(e){try{let t=__dirname||Zba(__filename),r=qba(t,"prompts",e);return tgi(r,"utf-8")}catch(t){throw console.error(`Failed to read prompt file: ${e}`,t),new Error(`Could not load prompt: ${e}`)}}function igi(e){let t=/```(\w+)?\n?([\s\S]*?)\n?```/g,r=[],n;for(;(n=t.exec(e))!==null;)r.push({language:n[1]?.toLowerCase().trim()||"",code:n[2].trim()});return r}import{existsSync as Uno,readFileSync as u6s}from"fs";import{join as c6s,basename as iTe,extname as l6s,dirname as jno}from"path";var Zqe=["persona","method","workflow"],ogi=We.object({topic:We.string().describe("The topic for the Counter to discuss and debate"),context:We.string().optional().describe("Optional additional context or background for the discussion"),recommendedHeroes:We.array(We.string()).optional().describe("Optional array of recommended hero names or call signs to prioritize for the discussion"),deployedHeroes:We.array(We.string()).optional().describe("CRITICAL: Array of hero names or call signs already active in current session - prevents duplicate deployment and maintains session continuity. Use when adding heroes to existing active sessions.")}).describe("Start a party mode discussion with all Counter heroes"),agi=We.object({method:We.string().describe("The method name to execute"),params:We.record(We.string(),We.any()).optional().describe("Parameters for the method")}),sgi=We.object({callSign:We.string().describe("The callSign to deploy (e.g., 'SARAH', 'JAMES')")}).describe("Deploy a specific Counter hero persona"),ugi=We.object({name:We.string().describe("The workflow identifier to deploy (e.g., 'team-architect')")}).describe("Execute a specific Counter workflow for multi-step task orchestration"),cgi=We.object({types:We.array(We.enum(Zqe)).default(["persona"]).describe("Array of resource types to filter by. Defaults to ['persona'] for hero listings")}).describe("Get Counter resources filtered by type");kno();var Ghr=(e,t)=>(t&&Object.entries(e).forEach(([r,n])=>{let i=n.name!=null?n.name:r,{inputSchema:o,...a}=n;t.addTool({...a,parameters:o,name:i})}),e);tmr();tmr();var vRu=300*1e3,_Ru={initialize:1800*1e3,"tools/list":300*1e3,"resources/list":60*1e3,"prompts/list":300*1e3};async function V2(e,t,r,n){let i=e.find(o=>o.callSign===t.trim());try{if(!i)return!1;let o;r?.partyMode&&(o=`**PARTY MODE ACTIVE - ENGAGE OPENING PHASE PROTOCOLS NOW!**
425
425
 
426
426
  **ACTIVE HEROES: ${r.activeHeroes||"UNKNOWN"}**
427
427
 
@@ -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("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:
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({name: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(`
@@ -18,7 +18,7 @@ export declare const heroDeploySchema: z.ZodObject<{
18
18
  }, z.core.$strip>;
19
19
  export type HeroDeployType = z.infer<typeof heroDeploySchema>;
20
20
  export declare const workflowDeploySchema: z.ZodObject<{
21
- callSign: z.ZodString;
21
+ name: z.ZodString;
22
22
  }, z.core.$strip>;
23
23
  export type WorkflowDeployType = z.infer<typeof workflowDeploySchema>;
24
24
  export declare const counterAssembleSchema: z.ZodObject<{
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.6",
2
+ "version": "0.6.7",
3
3
  "name": "@modality-counter/core",
4
4
  "repository": {
5
5
  "type": "git",