#!/usr/bin/env node
var f=/[@#$%^!?&~][a-zA-Z0-9_-]+/g;function p(t,e){let o=[],r=t.toLowerCase(),n=m(t);for(let[i,s]of Object.entries(e)){let g=[];for(let c of s.triggers||[]){let a=l(c,r,n);g.push(...a);}g.length>0&&o.push({name:i,reason:d(i,s,g),confidence:y(g),triggers_matched:g});}return o.sort((i,s)=>h(s.confidence)-h(i.confidence))}function l(t,e,o){let r=[];switch(t.type){case "keyword":if(t.match)for(let n of t.match)e.includes(n.toLowerCase())&&r.push(`keyword:${n}`);break;case "symbol":if(t.match)for(let n of t.match){let i=o.filter(s=>u(s,n));for(let s of i)r.push(`symbol:${s}`);}break;}return r}function u(t,e){if(e.endsWith("*")){let o=e.slice(0,-1);return t.startsWith(o)}return e.startsWith("^")&&e==="^*"?t.startsWith("^"):t===e}function m(t){let e=t.match(f)||[];return [...new Set(e)]}function d(t,e,o){let r=o.filter(c=>c.startsWith("keyword:")),n=o.filter(c=>c.startsWith("symbol:")),i=[];if(r.length>0){let c=r.map(a=>a.split(":")[1]);i.push(`keywords: ${c.join(", ")}`);}if(n.length>0){let c=n.map(a=>a.split(":")[1]);i.push(`symbols: ${c.join(", ")}`);}let s=e.role.split(`
`)[0].trim(),g=s.length>60?s.slice(0,57)+"...":s;return `Matched ${i.join("; ")}. ${g}`}function y(t){let e=t.filter(n=>n.startsWith("keyword:")).length,o=t.filter(n=>n.startsWith("symbol:")).length,r=e>0&&o>0;return t.length>=3||r?"high":t.length>=2?"medium":"low"}function h(t){switch(t){case "high":return 3;case "medium":return 2;case "low":return 1}}export{p as a};