@vibgrate/relevance 2026.825.1 → 2026.829.1
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/engine/relevance.wasm +0 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
var re={};import*as Q from"node:fs";import{fileURLToPath as et}from"node:url";var D;function ke(){if(D!==void 0)return D;D=null;try{let t=[new URL("./engine/relevance.wasm",import.meta.url),new URL("../crate/target/wasm32-unknown-unknown/release/vibgrate_relevance_kernel.wasm",import.meta.url)].map(i=>et(i)).find(i=>Q.existsSync(i));if(!t)return D;let n=new WebAssembly.Module(Q.readFileSync(t)),o=new WebAssembly.Instance(n,{}).exports,l=i=>{let m=new TextEncoder().encode(i),p=o.vg_alloc(m.length);return new Uint8Array(o.memory.buffer,p,m.length).set(m),{ptr:p,len:m.length}},r=i=>{let p=new DataView(o.memory.buffer,i,4).getUint32(0,!0),c=new TextDecoder().decode(new Uint8Array(o.memory.buffer,i+4,p));return o.vg_free(i,4+p),c};return D={version:()=>r(o.vg_version()),analyzeQueryJson:i=>{let{ptr:m,len:p}=l(i),c=r(o.vg_analyze(m,p));return o.vg_free(m,p),c},tagNodeJson:(i,m)=>{let p=l(i),c=l(m),b=r(o.vg_tag(p.ptr,p.len,c.ptr,c.len));return o.vg_free(p.ptr,p.len),o.vg_free(c.ptr,c.len),b}},D}catch{return D=null,D}}var H=new Set(["add","adds","added","adding","create","creates","created","creating","make","makes","making","made","new","newly","remove","removes","removed","removing","delete","deletes","deleted","deleting","update","updates","updated","updating","change","changes","changed","changing","set","sets","setting","setup","get","gets","getting","use","uses","used","using","want","wants","wanted","do","does","doing","done","support","supports","supported","supporting","enable","enables","enabled","enabling","disable","disables","disabled","disabling","allow","allows","allowed","implement","implements","implemented","implementing","build","builds","building","built","via","through","into","onto","way","ways","thing","things","stuff","feature","features","functionality","method","methods","option","options","ability","form","forms","page","pages","screen","screens","button","buttons","help","start","begin","work","works","working","also","currently","properly","correctly","please","happens","happen","something","somewhere","step","steps","flow","process","you","can","handle","handles","handled","handling","fail","fails","failed","failing","failure","failures","crash","crashes","crashing","issue","issues","problem","problems","pass","passes","passing","slow","slowly","slower","flaky","valid","invalid","user","users","printed","prints","returns","returned","returning","depends","depending","results","expected","actual"]),V={payment:["debit","mandate","stripe","invoice","billing","charge","card","checkout","refund","subscription"],pay:["stripe","invoice","payment","billing","charge"],paying:["invoice","billing","payment"],receipt:["invoice","billing","payment"],billing:["stripe","invoice","payment","charge","subscription"],billed:["invoice","billing","charge"],checkout:["stripe","payment","session"],debit:["mandate","payment","bacs","bank","sepa"],mandate:["debit","bacs","sepa"],sepa:["debit","mandate","bank"],bacs:["debit","mandate","bank"],stripe:["billing","webhook","payment","card","charge","checkout"],refund:["invoice","stripe","payment","charge"],invoice:["billing","payment","refund","subscription"],subscription:["invoice","billing"],recurring:["debit","mandate"],renewal:["billing","renew","subscription"],card:["stripe","payment","charge"],credit:["payment","card","charge"],bank:["debit","mandate","account","sepa"],charge:["stripe","payment","card"],customer:["billing","account"],auth:["login","oauth","password","session","token"],authentication:["auth","login","password","session","token"],authorization:["auth","oauth","permission"],authorisation:["auth","oauth","permission"],login:["auth","oauth","password","session"],signup:["account","register"],password:["auth","login"],session:["auth","login","token"],token:["auth","session"],oauth:["auth","login","callback"],google:["auth","login","oauth"],inference:["llm","completion","prompt","serving"],dependency:["advisory","vulnerability","audit","package"],package:["advisory","vulnerability","audit","dependency"],vulnerability:["advisory","audit","osv","vulnerable"],vulnerable:["advisory","vulnerability","audit"],advisory:["vulnerability","audit","osv"],cve:["advisory","vulnerability","osv"],risk:["advisory","vulnerability","audit"],security:["advisory","vulnerability","audit"],audit:["advisory","vulnerability","dependency"],scan:["scanner","vulnerability","audit"],retry:["backoff","throttle"],retries:["backoff","throttle"],email:["sender","template","message"],mail:["email","sender"],notification:["email","sms"],notify:["notification","email"],sms:["notification","message"],cart:["shop","order","discount"],order:["shop","fulfillment","cart","shipment"],shipping:["order","fulfillment","shipment"],shipped:["order","fulfillment","shipment"],inventory:["product","catalog","restock"],product:["shop","catalog","inventory"],discount:["cart"],chat:["room","presence","message"],message:["chat"],conversation:["chat","message"],online:["presence"],typing:["presence","broadcast","indicator"],video:["media","playback","thumbnail","transcode","stream"],stream:["playback","media","manifest"],streaming:["media","video","playback","manifest"],playback:["media","video","stream","watch"],transcode:["video","media"],thumbnail:["video","media"],media:["video","playback","stream"],analytics:["event","funnel","report","track"],event:["analytics","track"],track:["analytics","event"],funnel:["analytics","event","conversion"],conversion:["analytics","funnel"],report:["analytics","export","metrics"],article:["cms","publish"],publish:["article"],content:["article","cms","markdown"],markdown:["article","render"],deploy:["deployment","pipeline","release","rollback"],deployment:["pipeline","deploy","release","rollback"],release:["deploy","rollback"],rollback:["deployment","deploy","release"],pipeline:["ci","runner","stage","deploy"],canary:["deploy","release"],push:["mobile","device","token"],device:["mobile","push","register","token"],mobile:["push","device"],ios:["link","mobile","universal"],android:["push","mobile","device"],batch:["settlement","reconcile"],settlement:["batch","ledger","reconcile"],reconcile:["settlement","batch","ledger"],ledger:["settlement","reconcile"],mainframe:["settlement","batch","ebcdic","fixed"],ebcdic:["convert","record"],nightly:["batch"],geocode:["geo","address"],address:["geocode"],route:["geo","planner","distance"],distance:["route","geo"],arrival:["route","estimate"],translation:["locale"],translate:["locale","translation"],locale:["translation","format"],i18n:["locale","translation"],localized:["locale","translation","format"],metric:["export","counter","prometheus"],prometheus:["exporter","metric"],trace:["observability","span"],span:["trace"],counter:["increment","metric"],flag:["feature","experiment","rollout"],rollout:["flag","experiment","percentage"],experiment:["flag","assign","exposure","variant"],variant:["experiment","assign"],toggle:["flag","experiment","variant"],cache:["ttl","redis","memoize","eviction"],ttl:["cache","redis","eviction"],memoize:["cache","ttl"],database:["schema","migration","query","orm"],db:["database","schema","migration"],migration:["database","schema"],orm:["database","query","schema"],sql:["database","query","schema"],transaction:["database","schema"],queue:["broker","consumer","subscribe","topic"],broker:["queue","consumer","subscribe"],subscribe:["queue","broker","consumer"],consumer:["queue","broker","subscribe"],log:["logging"],logging:["log"],logger:["log","logging"],webhook:["callback","signature","idempotency"],callback:["webhook","signature"],idempotency:["webhook","callback"],throttle:["backoff","quota"],backoff:["throttle","quota"],quota:["throttle","backoff"],api:["endpoint","middleware"],endpoint:["api","middleware"],middleware:["api","endpoint"],graphql:["resolver","mutation"],resolver:["mutation"],component:["render","router"],render:["component","router"],router:["component","render"],css:["stylesheet","theme"],stylesheet:["css","theme"],theme:["css","stylesheet"],facet:["index","ranking"],ranking:["facet","index"],a11y:["aria","focus","contrast"],aria:["a11y","focus","contrast"],mock:["fixture","snapshot"],fixture:["mock","snapshot"],snapshot:["mock","fixture"],coverage:["mock","fixture"],consent:["retention","policy"],retention:["consent","policy"],csrf:["xss","sanitize"],xss:["csrf","sanitize"],logout:["session","auth"],mfa:["auth","login","sso"],sso:["auth","oauth"],jwt:["token","auth","session"],oidc:["oauth","auth","login"],cors:["origin","header"],smtp:["email","sender"],lockfile:["dependency"],language:["locale","translation","i18n"],l10n:["locale","i18n","translation"],localization:["locale","i18n","translation"],permission:["role","access"],role:["permission","access"]},Se={"direct debit":["debit","mandate","bacs","bank","sepa"],"direct debits":["debit","mandate","bacs","bank","sepa"],"sign in":["auth","login","session"],"signs in":["auth","login","session"],"log in":["login","auth","session"],"logs in":["auth","login","session"],"logged in":["login","auth","session"],"sign up":["account","register"],"signs up":["account","register"],"signing up":["account","register"],"signed up":["account","register"],"credit card":["stripe","payment","card","charge"],"credit cards":["stripe","payment","card","charge"],"two factor":["auth"],"payment method":["debit","stripe","payment","card"],"payment methods":["debit","stripe","payment","card"],"inference payment":["credit","usage"],"inference payments":["credit","usage"],"inference cost":["credit","usage"],"inference costs":["credit","usage"],"inference billing":["credit","usage"],"push notification":["push","device","token"],"push notifications":["push","device","token"],"deep link":["link"],"deep links":["link"],"universal link":["link","universal"],"universal links":["link","universal"],"feature flag":["experiment","flag","rollout"],"feature flags":["experiment","flag","rollout"],"shopping cart":["cart","order"],"roll back":["deployment","deploy","release"],"sign out":["session","auth"],"fixed width":["batch","export","record"],"canary rollout":["deployment","pipeline","deploy","release"],"canary rollouts":["deployment","pipeline","deploy","release"],"blog post":["article","cms","markdown","publish"],"blog posts":["article","cms","markdown","publish"],"signed out":["session","auth"],"rate limit":["throttle","backoff","quota"],"rate limits":["throttle","backoff","quota"],"screen reader":["a11y","aria","focus"],"dark mode":["theme","css"],"access token":["auth","session"],"refresh token":["token","session","auth"],"password reset":["password","token","auth"],"health check":["healthcheck","probe","live"],"circuit breaker":["circuit","breaker","fallback"],"api route":["router","endpoint"],"api routes":["router","endpoint"],"url route":["router","endpoint"],"url routes":["router","endpoint"],"route distance":["geo","planner","distance"],"queue message":["queue","broker","consumer"],"dead letter":["queue","broker","consumer"],"scan directory":["walk","glob"],"scan files":["walk","glob"],"search index":["facet","ranking"],"keyboard focus":["a11y","aria","focus"],"transaction rollback":["transaction","database","commit"],"rollback transaction":["transaction","database","commit"]},tt={"canary rollout":["rollout"],"canary rollouts":["rollouts"],"blog post":["post","blog"],"blog posts":["posts","blog"],"push notification":["notification"],"push notifications":["notification","notifications"],"inference payment":["payment"],"inference payments":["payment","payments"],"inference cost":["cost"],"inference costs":["cost","costs"],"inference billing":["billing"],"api route":["route"],"api routes":["route","routes"],"url route":["route"],"url routes":["route","routes"],"route distance":["route"],"queue message":["message"],"dead letter":["letter"],"scan directory":["scan"],"scan files":["scan"],"search index":["index"],"transaction rollback":["rollback"],"rollback transaction":["rollback"]},nt=new Set(["address the","address this","address that","address these","address those","address all","address my","track down","track it","track this","track that","track them","batch the","batch these","batch them","batch those","ship it","ship this","ship that"]),st=new Set(["users report","user reports","customers report","customer reports","people report","they report"]);function oe(e){let t=new Set;for(let n=0;n+1<e.length;n++){let a=`${e[n]} ${e[n+1]}`;nt.has(a)&&t.add(e[n]),st.has(a)&&t.add(e[n+1])}return t}function Re(){return Object.keys(V)}function _e(e){if(!e)return null;if(Object.hasOwn(V,e))return e;if(e.endsWith("ies")){let t=e.slice(0,-3)+"y";if(Object.hasOwn(V,t))return t}if(e.endsWith("s")){let t=e.slice(0,-1);if(Object.hasOwn(V,t))return t}return null}function q(e){let t=new Set(e),n=oe(e),a=[],o=new Set,l=(i,m)=>{t.has(i)||o.has(i)||(o.add(i),a.push({term:i,from:m}))};for(let i=0;i+1<e.length;i++){let m=`${e[i]} ${e[i+1]}`,p=Se[m];if(p)for(let c of p)l(c,m)}let r=K(e);for(let i of e){if(n.has(i)||r.has(i))continue;let m=_e(i);if(m)for(let p of V[m])l(p,i)}return a}function K(e){let t=new Set;for(let n=0;n+1<e.length;n++){let a=`${e[n]} ${e[n+1]}`;if(Se[a]){for(let o of[e[n],e[n+1]])_e(o)||t.add(o);for(let o of tt[a]??[])t.add(o)}}return t}var Te=new Set(["the","a","an","is","are","was","were","be","to","of","in","on","for","and","or","where","what","which","how","do","does","did","i","we","it","this","that","with","when","who","why","can","should","my","our","you","your","from","by","at","as","find","code","responsible","need","modify","me","implementation","explain","works","codebase","contains","file","not","no","exist","exists","existing","occurrence","occurrences","occurence","occurences","every","place","places","string","literal","text","search","locate","look","looking","show","list","all","fix","fixes","fixing","bug","bugs","broken","busted","borked","wrong","incorrect","incorrectly","figure","out","sure"]),rt=.25,xe=.7,ot=.35,it=.5,at=.5,ct=.4,Ee=.3,lt=.3;function ut(e){let t=new Map;for(let o of e){let l=t.get(o.sym.file);(l===void 0||o.score>l)&&t.set(o.sym.file,o.score)}let n=new Map;for(let[o,l]of t){let r=o.slice(0,o.lastIndexOf("/")+1),i=n.get(r)??[];i.push(l),n.set(r,i)}let a=new Map;for(let[o,l]of n)l.sort((r,i)=>i-r),a.set(o,l.slice(0,3).reduce((r,i)=>r+i,0));return a}var ft=4,dt=64,mt=.35,gt=/(^|\/)(tests?|testing|__tests__)(\/|$)|(^|\/)(test_[^/]*|conftest\.py)$|[._-](test|tests|spec)\.[a-z0-9]+$/i;function pt(e){return gt.test(e)}var ht=/(^|\.)tests?(\.|$)|(^|\.)(?:test_[^.]*|Test[A-Z][^.]*|Benchmark[A-Z][^.]*|Fuzz[A-Z][^.]*)$/;function bt(e){return ht.test(e)}var yt=/\b(?:write|writes|add|adds|create|creates|extend|extends|improve|improves|update|updates|generate|generates)\b[^.?!]{0,40}\btests?\b|\bwhere\s+(?:is|are)\b[^.?!]{0,40}\btested\b|\btest\s+coverage\b/i;function vt(e,t){return yt.test(e)?!0:t.some(n=>/^test_|_tests?$|^conftest$/.test(n.term))}function G(e){return[...new Set(e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1&&!Te.has(t)))]}function Y(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}function wt(e){let t=e.trim();return t=t.replace(/[.,;:!)\]}>]+$/g,""),t.endsWith("?")&&t.lastIndexOf("?")===t.length-1&&(t=t.slice(0,-1)),t}function ee(e){let t=[],n=new Set,a=(o,l)=>{let r=o.trim();r=l==="url"?wt(r):r.replace(/[.,;:!)\]}>?]+$/g,""),!(r.length<2||n.has(r))&&(n.add(r),t.push(r))};for(let o of e.matchAll(/https?:\/\/[^\s"'`<>]+/gi))a(o[0],"url");for(let o of e.matchAll(/(["'`])((?:(?!\1)[^\\]|\\.){2,})\1/g))a(o[2].replace(/\\(.)/g,"$1"),"quote");return t}function ie(e){let t=e;for(let n of e.matchAll(/https?:\/\/[^\s"'`<>]+/gi))t=t.split(n[0]).join(" ");for(let n of ee(e))t=t.split(n).join(" ");return t=t.replace(/(["'`])\s*\1/g," "),t.replace(/\s+/g," ").trim()}function kt(e){return/\b(where\s+is|where\s+are|find\s+(all\s+|every\s+)?occurrences?|does\s+not\s+exist|locate|search\s+for|occurrences?\s+of)\b/i.test(e)}function St(e,t){if(!t.length||kt(e))return null;let n=t.filter(a=>!/^https?:\/\//i.test(a)&&!a.includes("/"));return n.length?n.join(" "):null}function J(e){return new Set(e.split(/[^\p{L}\p{N}]+|(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[\p{L}])(?=[0-9])|(?<=[0-9])(?=[\p{L}])/u).filter(Boolean).map(t=>t.toLowerCase()))}function ae(e){return e.length>=5&&e.endsWith("ies")?e.slice(0,-3)+"y":e.length>=4&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):null}function Rt(e,t){for(let n of t){let a=Ne(e,n);if(a>=5&&a>=.6*Math.min(e.length,n.length))return!0}return!1}function Ne(e,t){let n=Math.min(e.length,t.length),a=0;for(;a<n&&e[a]===t[a];)a++;return a}var _t=16,xt=36,Et=.75,Mt=.55;function At(e){let t=new Map;for(let n of e){if(Te.has(n)||t.has(n))continue;let a=t.size;t.set(n,a<_t?1:a<xt?Et:Mt)}return t}function Tt(e,t,n,a){let o=G(e),l=Y(e),r=new Set(o),i=K(l),m=oe(l),p=At(l),c=o.map(u=>({term:u,weak:H.has(u)||i.has(u)||m.has(u),positional:p.get(u)??1})),b=new Set(o);for(let u of q(l))r.has(u.term)||(c.push({term:u.term,weak:!1,from:u.from,positional:p.get(u.from)??1}),b.add(u.term));if(a){let u=Y(a),h=K(u);for(let d of G(a))b.has(d)||H.has(d)||h.has(d)||(c.push({term:d,weak:!1,from:"quote",quoted:!0}),b.add(d));for(let d of q(u))b.has(d.term)||(c.push({term:d.term,weak:!1,from:d.from}),b.add(d.term))}for(let u of t?.expansions??[]){let h=String(u?.term??"").toLowerCase().trim(),d=String(u?.from??"").toLowerCase().trim(),x=Number(u?.weight);!h||!d||h.includes(" ")||b.has(h)||H.has(d)||H.has(h)||!Number.isFinite(x)||x<at||(c.push({term:h,weak:!1,from:d,packWeight:Math.min(1,x)}),b.add(h))}if(n?.trim()){let u=Y(n),h=K(u);for(let d of G(n))b.has(d)||H.has(d)||h.has(d)||(c.push({term:d,weak:!1,carried:!0}),b.add(d));for(let d of q(u))b.has(d.term)||(c.push({term:d.term,weak:!1,from:d.from,carried:!0}),b.add(d.term))}let w=c.some(u=>!u.weak);return{terms:c,hasContent:w}}function Oe(e){let t=e?.trim();return t?ee(t).length>0?ie(t):t:null}function Nt(e,t){let n=t.terms.filter(r=>!r.weak&&!r.from&&!r.carried&&r.term.length>=4);if(!n.length)return;let a=new Map,o=new Set;for(let r of e){let i=r.name.toLowerCase(),m=r.file.toLowerCase(),p=J(r.name);for(let c of p)o.add(c);for(let c of n){let b=ae(c.term);(p.has(c.term)||b!==null&&p.has(b)||i.includes(c.term)||m.includes(c.term))&&a.set(c.term,(a.get(c.term)??0)+1)}}let l=new Set(t.terms.map(r=>r.term));for(let r of n){if((a.get(r.term)??0)>0||q([r.term]).length>0)continue;let i=r.term.length>=8?2:1,m=null,p=(b,w)=>{if(b.length<4||b===r.term||w!==0&&r.term.length<6||Math.abs(b.length-r.term.length)>i||b[0]!==r.term[0])return;let u=Ot(r.term,b,i);if(u>i)return;let h=Ne(r.term,b);(!m||u<m.dist||u===m.dist&&(h>m.prefix||h===m.prefix&&(w<m.lex||w===m.lex&&b<m.cand)))&&(m={cand:b,dist:u,prefix:h,lex:w})};for(let b of Re())p(b,0);for(let b of o)p(b,1);if(!m)continue;let{cand:c}=m;l.has(c)||(t.terms.push({term:c,weak:!1,from:r.term}),l.add(c))}}function Ot(e,t,n){let a=e.length,o=t.length;if(Math.abs(a-o)>n)return n+1;let l=null,r=Array.from({length:o+1},(i,m)=>m);for(let i=1;i<=a;i++){let m=new Array(o+1);m[0]=i;let p=m[0];for(let c=1;c<=o;c++){let b=e[i-1]===t[c-1]?0:1,w=Math.min(r[c]+1,m[c-1]+1,r[c-1]+b);l&&i>1&&c>1&&e[i-1]===t[c-2]&&e[i-2]===t[c-1]&&(w=Math.min(w,l[c-2]+1)),m[c]=w,w<p&&(p=w)}if(p>n)return n+1;l=r,r=m}return r[o]}function It(e,t){if(t.length===0)return()=>1;let n=new Map,a=0;for(let l of e){a++;let r=l.name.toLowerCase(),i=J(l.name);for(let m of t){let p=ae(m);(i.has(m)||p!==null&&i.has(p)||r.includes(m))&&n.set(m,(n.get(m)??0)+1)}}let o=new Map;for(let l of t){let r=Math.log((a+1)/((n.get(l)??0)+1))+1;o.set(l,Math.max(.5,Math.min(8,r)))}return l=>o.get(l)??1}function $t(e,t,n){let a=0,o=0,l=!1,r=[],i=e.name.toLowerCase(),m=e.qualifiedName.toLowerCase(),p=e.file.toLowerCase(),c=p.split("/"),b=new Set(c.slice(0,-1)),w=c[c.length-1].replace(/\.[a-z0-9]+$/,""),u=J(w),h=J(e.name);for(let{term:d,weak:x,from:N,packWeight:S,carried:y,quoted:A,positional:P}of t){let L=S!==void 0?Math.min(S,xe):N&&!A?xe:1,O=n(d)*(x?rt:1)*L*(y?it:1)*(P??1),C=(y?"\u21A9":"")+(N?`${N}\u2192${d}`:d),F=d.length>=4,z=ae(d),I=0,B=!1;i===d?(I=10*O,r.push(C)):h.has(d)||z!==null&&h.has(z)?(I=6*O,r.push(C)):w===d||z!==null&&w===z?(I=(O>=3?8:5)*O,r.push(C)):F&&i.includes(d)?(I=4*O,r.push(C)):F&&m.includes(d)||u.has(d)||z!==null&&u.has(z)?(I=3*O,r.push(C)):F&&d.length>=5&&w.includes(d)?(I=2.5*O,r.push(C)):S===void 0&&Rt(d,h)?(I=2*O,r.push((y?"\u21A9":"")+(N?`~${N}\u2192${d}`:`~${d}`)),B=!0):b.has(d)?(I=2*O,r.push(C)):F&&p.includes(d)&&(I=1*O,r.push(C)),I>0&&(a+=I,x||(o+=1,B||(l=!0)))}return o===0?{score:0,why:"",strong:!1}:(a*=1+ot*Math.min(o-1,4),{score:a,why:r.length?`matched: ${r.join(", ")}`:"",strong:l})}function Ct(e,t){let n=e.split("/"),a=t.split("/"),o=0;for(;o<n.length&&o<a.length&&n[o]===a[o];)o++;return o}function Lt(e,t,n){if(!n)return{boost:1,label:""};let a=n[e];if(!a?.length)return{boost:1,label:""};let o=t?.taxonomy??[];if(o.length&&a.some(i=>i.includes("/"))){let i=0,m="";for(let p of o){let c=p.path.split("/").length;for(let b of a){let w=Ct(p.path,b);if(w===0)continue;let u=w/c*p.score;u>i&&(i=u,m=w===c?p.path:p.path.split("/").slice(0,w).join("/"))}}return i<=0?{boost:1,label:""}:{boost:1+Ee*Math.min(i,1),label:`, topic:${m}`}}if(!t?.topics?.length)return{boost:1,label:""};let l=0,r=[];for(let i of t.topics)a.includes(i.id)&&(l+=i.score,r.push(i.id));return l<=0?{boost:1,label:""}:{boost:1+Ee*Math.min(l,1),label:`, topic:${r.sort().join("+")}`}}function Me(e){return e.toLowerCase().replace(/\d+/g,"")}var Pt=2;function zt(e){return(e.name||e.qualifiedName).toLowerCase()}function Dt(e){let t=e[0]?.score??0;return t<=0?e:e.filter(n=>n.strong||n.score>=t/3)}function Wt(e){let t=new Set,n=[],a=[];for(let u of e)t.has(u.sym.file)?a.push(u):(t.add(u.sym.file),n.push(u));let o=n.concat(a),l=new Map,r=[],i=[];for(let u of o){let h=zt(u.sym),d=l.get(h)??0;l.set(h,d+1),(d<Pt?r:i).push(u)}let m=r.concat(i),p=new Set;for(let u of e)u.strong&&p.add(Me(u.sym.file));if(p.size<2)return m;let c=new Map,b=[],w=[];for(let u of m){let h=Me(u.sym.file),d=c.get(h)??0;d<ft?(c.set(h,d+1),b.push(u)):w.push(u)}return b.concat(w)}function Ft(e,t,n){let a=u=>[...new Set(u)].slice(0,8).join(", "),l=ee(e).length>0?ie(e):e,r=[],i=new Map;for(let u of q(Y(l))){let h=i.get(u.from)??[];h.push(u.term),i.set(u.from,h)}for(let[u,h]of i)r.push(`- "${u}" in the ask implies these codebase identifiers: ${a(h)}.`);let m=t?.taxonomy??[];if(m.length){let u=new Set,h=[];for(let y of m)for(let A of y.levels)u.has(A.path)||(u.add(A.path),h.push({path:A.path,id:A.id,depth:A.path.split("/").length,terms:A.terms}));let d=Math.max(...h.map(y=>y.depth)),x=(y,A)=>y.terms.length?`${A} ${y.id}; code for it typically uses: ${a(y.terms)}.`:`${A} ${y.id}.`;for(let y of h.filter(A=>A.depth===d))r.push(x(y,"- The ask is specifically about"));let N=new Set(h.filter(y=>y.depth===d).map(y=>y.id));for(let y of(t?.vendors??[]).filter(A=>A.score>0).slice(0,3)){if(N.has(y.name)){y.from!==y.name&&r.push(`- That product was typed "${y.from}".`);continue}r.push(y.from===y.name?`- It names the product "${y.name}".`:`- It names the product "${y.name}" (typed "${y.from}").`)}let S=new Set((t?.vendors??[]).map(y=>y.name));for(let y=d-1;y>=1;y--)for(let A of h.filter(P=>P.depth===y&&!S.has(P.id)))r.push(x(A,"- More broadly, this is"))}else if(t?.topics?.length){let u=new Map;for(let h of t.expansions??[]){let d=u.get(h.from)??[];d.push(h.term),u.set(h.from,d)}for(let h of t.topics.slice(0,3)){let d=u.get(h.id);r.push(d?.length?`- The ask is about the "${h.id}" domain; code for it typically uses: ${a(d)}.`:`- The ask is about the "${h.id}" domain.`)}}let p=t?.standards??[];if(p.length){let u=p.filter(x=>x.kind!=="regulation"),h=p.filter(x=>x.kind==="regulation"),d=x=>x.slice(0,3).map(N=>N.publisher?`${N.name} (${N.publisher})`:N.name).join("; ");u.length&&r.push(`- Standards that govern this area: ${d(u)}.`),h.length&&r.push(`- Regulations that apply here: ${d(h)}.`)}let c=t?.categories??[];c.length&&r.push(`- Related categories: ${a(c)}.`);let b=t?.files??[];b.length&&r.push(`- Files for this kind of work are usually named or extended: ${a(b)}.`);for(let u of(t?.corrections??[]).slice(0,3))r.push(`- Read "${u.from}" in the ask as "${u.to}".`);let w=Oe(n);if(w){let u=new Set(G(l)),h=K(Y(w)),d=G(w).filter(x=>!u.has(x)&&!H.has(x)&&!h.has(x));d.length&&r.push(`- This is a follow-up; topic words carried from the previous ask: ${a(d)}.`)}return r.length&&r.push('- Seed notation below: `a\u2192b` = ask term "a" implied identifier "b"; `~t` = word-form match; `\u21A9t` = carried from the previous ask.'),r}function Ae(e){return Math.round(e*1e6)/1e6}function ce(e,t){return{rankSymbols(n,a,o={}){let l=Math.max(1,Math.min(o.limit??16,dt)),r=null;try{r=e(n)}catch{r=null}let i=ee(n),m=i.length>0?ie(n):n,p=Oe(o.priorQuestion),c=Tt(m,r,p,St(n,i));Nt(a,c);let b=Ft(n,r,o.priorQuestion??null);if(!c.hasContent)return{version:t(),hasContent:!1,seeds:[],conceptMap:b};let w=It(a,c.terms.map(S=>S.term)),u=!vt(n,c.terms),h=[];for(let S of a){let{score:y,why:A,strong:P}=$t(S,c.terms,w);if(y>0){let L=Lt(S.id,r,o.topicTags),O=pt(S.file)||bt(S.qualifiedName),C=u&&O?mt:1;h.push({sym:S,score:Ae(y*C*L.boost*(1+ct*S.importance)),why:A+L.label,strong:P})}}let d=ut(h),x=0;for(let S of d.values())S>x&&(x=S);if(x>0)for(let S of h){let y=S.sym.file.slice(0,S.sym.file.lastIndexOf("/")+1),A=(d.get(y)??0)/x;S.score=Ae(S.score*(1+lt*A))}h.sort((S,y)=>y.score-S.score||(S.sym.qualifiedName<y.sym.qualifiedName?-1:1));let N=Wt(Dt(h)).slice(0,l).map(S=>({id:S.sym.id,score:S.score,why:S.why}));return{version:t(),hasContent:!0,seeds:N,conceptMap:b}}}}var Ht=!1,Ie=`vg-relevance@1.5.0+pack.${re.version}`,qt=20,Kt=8,jt=4,Ut=.34,Vt=.8,Gt=.6,Yt=.5,Xt=.45,qe=new Set(["the","and","for","with","first","new","web","app","development"]),Bt=2e3,Zt=1200,Ke=550,le=2e3,Qt=1200,Jt=800,en=1e3,tn=600,$e=1e3,Ce=3e3,nn=1e3,ue=e=>Math.round(Math.min(e,Ce)/Ce*1e3)/1e3,je=6,sn=6,rn=6,on=10,an=6,cn=6,ln=8,fe=4,R=re;for(let e of[R.acronyms,R.vendors,R.synonyms,R.topics,R.taxonomyTerms,R.vendorNode,R.fileHints,R.standards])e&&typeof e=="object"&&Object.setPrototypeOf(e,null);function un(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=2)}function fn(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}var dn=new Set(["the","an","our","your","their","its","this","that","these","those","each","every","another","any"]);function X(e){return e.split(" ").filter(t=>t.length>=3&&!qe.has(t))}var mn=40,Le=128,Ue=Uint8Array.from(Buffer.from(R.vectors?.data??"","base64")),de=new Map((R.vectors?.terms??[]).map((e,t)=>[e,t])),gn=new Set(R.vectors?.skip??[]);function pn(e){let t=de.get(e);if(t!==void 0)return{row:t,term:e};if(e.endsWith("s")&&e.length>4){let n=e.slice(0,-1);if(t=de.get(n),t!==void 0)return{row:t,term:n}}return null}function hn(e,t){let n=Ue[e*(R.vectors?.dim??0)+t]??0;return n>127?n-256:n}var T=R.taxonomy??[],W=R.taxonomyTerms??{},Pe=R.vendorNode??{},me=R.fuzzyKeys??[],bn=R.fileHints??{},yn=R.standards??{};function vn(e){let t=[];for(let n=e;n>=0;n=T[n].parent){let a=T[n].path;for(let o of yn[a]??[])t.some(l=>l.name===o.name)||t.push({name:o.name,publisher:o.publisher,node:a,kind:o.kind??"standard",categories:o.categories??[]});if(T[n].parent<0)break}return t.slice(0,fe)}function ze(e){let t=[];for(let n=e;n>=0;n=T[n].parent){for(let a of bn[T[n].path]??[])t.includes(a)||t.push(a);if(T[n].parent<0)break}return t.slice(0,cn)}var wn=me.map(e=>({mask:Ve(e.key),grams:Ge(e.key),len:e.key.length})),ge=new Set(R.weakTerms??[]),te=new Set(R.englishGuard??[]),De=e=>e.includes(" ")?Bt:ge.has(e)?Ke:Zt,pe=T.map(()=>[]);for(let[e,t]of T.entries())t.parent>=0&&pe[t.parent].push(e);var We=new Map(T.map((e,t)=>[e.path,t]));function Ve(e){let t=0;for(let n=0;n<e.length;n++){let a=e.charCodeAt(n)-97;t|=a>=0&&a<26?1<<a:1<<26}return t}function kn(e){let t=0;for(let n=e;n;n&=n-1)t++;return t}function Ge(e){let t=[];for(let n=0;n<e.length-1;n++)t.push(e.slice(n,n+2));return[...new Set(t)].sort()}function Sn(e,t){let n=0,a=0,o=0;for(;n<e.length&&a<t.length;)e[n]===t[a]?(o++,n++,a++):e[n]<t[a]?n++:a++;return o}function Rn(e,t,n){let a=e.length,o=t.length;if(Math.abs(a-o)>n)return n+1;let l=[],r=new Array(o+1);for(let i=0;i<=o;i++)r[i]=i;for(let i=1;i<=a;i++){let m=new Array(o+1);m[0]=i;let p=m[0];for(let c=1;c<=o;c++){let b=e[i-1]===t[c-1]?0:1,w=Math.min(m[c-1]+1,r[c]+1,r[c-1]+b);i>1&&c>1&&e[i-1]===t[c-2]&&e[i-2]===t[c-1]&&(w=Math.min(w,l[c-2]+1)),m[c]=w,w<p&&(p=w)}if(p>n)return n+1;l=r,r=m}return r[o]}var Fe=new Set(["s","es","ed","d","ing","ly","er","ers","ings"]);function _n(e){return e<je?0:e>=9?2:1}function xn(e,t=2){let n=Math.min(_n(e.length),t);if(n===0||de.has(e)||te.has(e))return null;let a=Ge(e),o=e.length>=6?2:1,l=null,r=n+1,i=!1,m=Ve(e);for(let c=0;c<me.length;c++){let b=wn[c];if(Math.abs(b.len-e.length)>n||kn(m^b.mask)>n*2)continue;let w=me[c];if(Sn(a,b.grams)<o)continue;let u=Rn(e,w.key,n);u>n||(u<r?(r=u,l=w,i=!1):u===r&&l&&w.ref!==l.ref&&(i=!0))}if(!l||i||r>=2&&e[0]!==l.key[0])return null;let p=e.startsWith(l.key)?e.slice(l.key.length):"";if(p&&/^(id|ids|[0-9]+)$/.test(p))return null;if(e.startsWith(l.key)){let c=e.slice(l.key.length);if(Fe.has(c))return null}return l.key.startsWith(e)&&Fe.has(l.key.slice(e.length))?null:{key:l,distance:r}}var he=new Map;for(let e of T){if(!e.topic)continue;let t=he.get(e.topic);(!t||e.path.split("/").length<t.split("/").length)&&he.set(e.topic,e.path)}var Ye=new Map;for(let[e,t]of Object.entries(R.topicPathHints??{}))for(let n of t)Ye.set(n,e);function He(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=2)}function En(){let e=ke();if(!e&&!Ht)throw new Error("@vibgrate/relevance: the wasm engine failed to load and this build ships no reference implementation. Reinstall the module.");let t=e?{version:()=>e.version(),analyzeQuery:a=>JSON.parse(e.analyzeQueryJson(a)),tagNode:a=>JSON.parse(e.tagNodeJson(a.qualifiedName??"",a.file??""))}:Mn(),n=ce(a=>t.analyzeQuery(a),()=>t.version());return{...t,rankSymbols:n.rankSymbols}}function Mn(){return{version:()=>Ie,tagNode(e){let t=new Set([...He(e.file??""),...He(e.qualifiedName??"")]),n=new Set;for(let o of t){if(o.length<3||ge.has(o)||te.has(o))continue;for(let i of W[o]??[])n.add(T[i].path);let l=Pe[o];l&&n.add(l);let r=Ye.get(o);if(r&&!l){let i=he.get(r);i&&n.add(i)}}return[...n].filter(o=>![...n].some(l=>l!==o&&l.startsWith(`${o}/`))).sort((o,l)=>l.split("/").length-o.split("/").length||(o<l?-1:1)).slice(0,3)},analyzeQuery(e){let t=un(e),n=new Set(t);for(let s=0;s<t.length-1;s++)n.add(`${t[s]} ${t[s+1]}`);let a=new Set(n),o=[];for(let s of[...n].sort()){let f=R.acronyms[s];f&&o.push({acronym:s,full:f})}for(let s of o)for(let f of X(s.full))n.add(f);let l=fn(e),r=` ${[...l,...o.map(s=>s.full)].join(" ")} `,i=(s,f)=>{let k=` ${f} `;for(let g=s.indexOf(k);g!==-1;g=s.indexOf(k,g+1)){let v=s.slice(0,g),M=v.lastIndexOf(" ");if(M!==-1&&dn.has(v.slice(M+1)))return!0}return!1},m=(s,f)=>f.charCodeAt(0)===97&&f.charCodeAt(1)===32?i(s,f):s.includes(` ${f} `),p=s=>s.includes(" ")?m(r,s):n.has(s),c=s=>s.length>3&&s.endsWith("s")&&!s.endsWith("ss")?s.slice(0,-1):s,b=t.map(c),w=` ${l.map(c).join(" ")} `,u=new Set(b);for(let s=0;s<b.length-1;s++)u.add(`${b[s]} ${b[s+1]}`);let h=s=>p(s)||(s.includes(" ")?m(w,s):u.has(s)),d=[],x=new Map,N=(s,f)=>x.set(s,(x.get(s)??0)+f),S=new Map,y=new Map,A=new Map,P=[],L=(s,f,k)=>{S.set(s,(S.get(s)??0)+f);let g=y.get(s)??[];g.includes(k)||g.push(k),y.set(s,g)},O=(s,f,k)=>{let g=R.vendors[s];if(!g)return;let v=A.get(s),M=ue(k);if(v&&v.score>=M)return;let E=Pe[s],_=E!==void 0?We.get(E):void 0;if(A.set(s,{name:s,from:f,topic:g.topic,score:M,files:_!==void 0?ze(_):[],...E?{node:E}:{}}),E!==void 0){let $=We.get(E);$!==void 0&&L($,k,f===s?s:`~${f}`)}};if(T.length){for(let g of o)for(let v of W[g.acronym]??[])L(v,en,g.acronym);for(let[g,v]of Object.entries(W)){if(!h(g))continue;let M=De(g),E=Math.floor(M/v.length);for(let _ of v)L(_,E,g)}for(let g of n)R.vendors[g]&&O(g,g,le);let s=[];for(let g of t)!R.vendors[g]&&!W[g]&&s.push({token:g,from:g,maxDistance:2});for(let g=0;g<t.length-1;g++){let v=t[g],M=t[g+1],E=`${v}${M}`;if(R.vendors[E]){O(E,`${v} ${M}`,le);continue}if(W[E])continue;let _=[v,M].filter($=>!te.has($));v.length>=3&&M.length>=3&&_.some($=>$.length>=4)&&s.push({token:E,from:`${v} ${M}`,maxDistance:1})}let f=new Set,k=new Map;for(let{token:g,from:v,maxDistance:M}of s){if(g.length<je||f.has(g)||(f.add(g),R.vendors[g]||W[g]))continue;let E=xn(g,M);if(!E||E.distance===0)continue;let _=E.distance===1?Qt:Jt;if(P.push({from:v,to:E.key.ref,distance:E.distance}),k.set(g,E.key.ref),E.key.kind==="vendor")O(E.key.ref,v,_);else if(E.key.kind==="term"){let $=W[E.key.ref]??[];for(let we of $)L(we,Math.floor(_/$.length),`~${v}`)}}if(k.size){let g=t.map(_=>k.get(_)??_);for(let _=0;_<g.length-1;_++){let $=k.get(`${t[_]}${t[_+1]}`);$&&(g[_]=$,g[_+1]="")}let v=g.filter(Boolean),M=` ${v.join(" ")} `,E=new Set(v);for(let _=0;_<v.length-1;_++)E.add(`${v[_]} ${v[_+1]}`);for(let[_,$]of Object.entries(W)){if(!(_.includes(" ")?M.includes(` ${_} `):E.has(_))||(_.includes(" ")?r.includes(` ${_} `):n.has(_)))continue;let Be=Math.floor(De(_)*sn/10),Ze=Math.floor(Be/$.length);for(let Qe of $)L(Qe,Ze,`~${_}`)}}for(let[g,v]of S){let M=T[g]?.topic;M&&N(M,v)}}for(let s of o)for(let f of X(s.full))d.push({term:f,from:s.acronym,weight:Vt});for(let s of n){let f=R.vendors[s];if(f){N(f.topic,le);for(let k of f.terms)for(let g of X(k))d.push({term:g,from:s,weight:Gt})}}for(let[s,f]of Object.entries(R.topics))for(let k of f.terms){if(!p(k))continue;let g=!k.includes(" ")&&(ge.has(k)||te.has(k));N(s,g?Ke:nn)}if(R.vectors&&Ue.length){let s=new Map;for(let f of t){if(f.length<3||qe.has(f)||gn.has(f))continue;let k=pn(f);if(k)for(let g=0;g<R.vectors.dim;g++){let v=hn(k.row,g);v>=mn&&s.set(g,(s.get(g)??0)+v)}}for(let[f,k]of s){let g=R.vectors.topics[f];N(g,Math.round(Math.min(k,Le)*tn/Le))}}for(let s of n){let f=R.synonyms[s];if(f)for(let k of f)for(let g of X(k))d.push({term:g,from:s,weight:Yt})}let C=[...x.entries()].filter(([,s])=>s>=$e),F=Math.max(0,...C.map(([,s])=>s)),z=F>0?C.map(([s,f])=>({id:s,score:Math.round(f/F*1e3)/1e3})).filter(s=>s.score>=Ut).sort((s,f)=>f.score-s.score||(s.id<f.id?-1:1)).slice(0,jt):[];for(let s of z){let f=0;for(let k of R.topics[s.id]?.terms??[])for(let g of X(k))a.has(g)||f>=Kt||(d.push({term:g,from:s.id,weight:Math.round(Xt*s.score*1e3)/1e3}),f+=1)}let I=new Map;for(let s of d){if(a.has(s.term))continue;let f=I.get(s.term);(!f||s.weight>f.weight)&&I.set(s.term,s)}let B=[...I.values()].sort((s,f)=>f.weight-s.weight||(s.term<f.term?-1:1)).slice(0,qt),j=new Array(T.length).fill(0);for(let[s,f]of S){let k=s;for(;k!==void 0&&k>=0;){j[k]+=f;let g=T[k].parent;k=g>=0?g:void 0}}let be=s=>j[s]>=$e,ye=[];for(let s=0;s<T.length;s++)be(s)&&(pe[s].some(f=>be(f))||ye.push(s));let ne=ye.map(s=>{let f=[];for(let v=s;v>=0&&(f.unshift(v),!(T[v].parent<0));v=T[v].parent);let k=new Set,g=v=>{for(let M of y.get(v)??[])k.add(M);for(let M of pe[v]??[])g(M)};for(let v of f)for(let M of y.get(v)??[])k.add(M);return g(s),{path:T[s].path,levels:f.map(v=>({id:T[v].path.split("/").pop(),path:T[v].path,score:ue(j[v]),terms:(T[v].terms??[]).slice(0,an)})),score:ue(j[s]),evidence:Math.round(j[s])/1e3,via:[...k].sort(),terms:(T[s].terms??[]).slice(0,on),files:ze(s),standards:vn(s)}}).sort((s,f)=>f.evidence-s.evidence||(s.path<f.path?-1:1)).slice(0,rn),ve=[...A.values()].sort((s,f)=>f.score-s.score||(s.name<f.name?-1:1)),Xe=[...new Map(P.map(s=>[`${s.from}>${s.to}`,s])).values()].sort((s,f)=>s.from<f.from?-1:1),U=[];for(let s of ve)for(let f of s.files)U.includes(f)||U.push(f);for(let s of ne)for(let f of s.files)U.includes(f)||U.push(f);let Z=[];for(let s of ne)for(let f of s.standards)Z.some(k=>k.name===f.name)||Z.push(f);let se=[];for(let s of Z.slice(0,fe))for(let f of s.categories)se.includes(f)||se.push(f);return{version:Ie,topics:z,expansions:B,taxonomy:ne,vendors:ve,corrections:Xe,files:U.slice(0,ln),standards:Z.slice(0,fe),categories:se}}}}export{En as createRelevanceProvider,ce as createSymbolRanker};
|
|
1
|
+
var oe={};import*as J from"node:fs";import{fileURLToPath as et}from"node:url";var q;function ke(){if(q!==void 0)return q;q=null;try{let t=[new URL("./engine/relevance.wasm",import.meta.url),new URL("../crate/target/wasm32-unknown-unknown/release/vibgrate_relevance_kernel.wasm",import.meta.url)].map(r=>et(r)).find(r=>J.existsSync(r));if(!t)return q;let n=new WebAssembly.Module(J.readFileSync(t)),o=new WebAssembly.Instance(n,{}).exports,l=r=>{let d=new TextEncoder().encode(r),p=o.vg_alloc(d.length);return new Uint8Array(o.memory.buffer,p,d.length).set(d),{ptr:p,len:d.length}},a=r=>{let p=new DataView(o.memory.buffer,r,4).getUint32(0,!0),f=new TextDecoder().decode(new Uint8Array(o.memory.buffer,r+4,p));return o.vg_free(r,4+p),f};return q={version:()=>a(o.vg_version()),analyzeQueryJson:r=>{let{ptr:d,len:p}=l(r),f=a(o.vg_analyze(d,p));return o.vg_free(d,p),f},tagNodeJson:(r,d)=>{let p=l(r),f=l(d),h=a(o.vg_tag(p.ptr,p.len,f.ptr,f.len));return o.vg_free(p.ptr,p.len),o.vg_free(f.ptr,f.len),h}},q}catch{return q=null,q}}var j=new Set(["add","adds","added","adding","create","creates","created","creating","make","makes","making","made","new","newly","remove","removes","removed","removing","delete","deletes","deleted","deleting","update","updates","updated","updating","change","changes","changed","changing","set","sets","setting","setup","get","gets","getting","use","uses","used","using","want","wants","wanted","do","does","doing","done","support","supports","supported","supporting","enable","enables","enabled","enabling","disable","disables","disabled","disabling","allow","allows","allowed","implement","implements","implemented","implementing","build","builds","building","built","via","through","into","onto","way","ways","thing","things","stuff","feature","features","functionality","method","methods","option","options","ability","form","forms","page","pages","screen","screens","button","buttons","help","start","begin","work","works","working","also","currently","properly","correctly","please","happens","happen","something","somewhere","step","steps","flow","process","you","can","handle","handles","handled","handling","fail","fails","failed","failing","failure","failures","crash","crashes","crashing","issue","issues","problem","problems","pass","passes","passing","slow","slowly","slower","flaky","valid","invalid","user","users","printed","prints","returns","returned","returning","depends","depending","results","expected","actual"]),Y={payment:["debit","mandate","stripe","invoice","billing","charge","card","checkout","refund","subscription"],pay:["stripe","invoice","payment","billing","charge"],paying:["invoice","billing","payment"],receipt:["invoice","billing","payment"],billing:["stripe","invoice","payment","charge","subscription"],billed:["invoice","billing","charge"],checkout:["stripe","payment","session"],debit:["mandate","payment","bacs","bank","sepa"],mandate:["debit","bacs","sepa"],sepa:["debit","mandate","bank"],bacs:["debit","mandate","bank"],stripe:["billing","webhook","payment","card","charge","checkout"],refund:["invoice","stripe","payment","charge"],invoice:["billing","payment","refund","subscription"],subscription:["invoice","billing"],recurring:["debit","mandate"],renewal:["billing","renew","subscription"],card:["stripe","payment","charge"],credit:["payment","card","charge"],bank:["debit","mandate","account","sepa"],charge:["stripe","payment","card"],customer:["billing","account"],auth:["login","oauth","password","session","token"],authentication:["auth","login","password","session","token"],authorization:["auth","oauth","permission"],authorisation:["auth","oauth","permission"],login:["auth","oauth","password","session"],signup:["account","register"],password:["auth","login"],session:["auth","login","token"],token:["auth","session"],oauth:["auth","login","callback"],google:["auth","login","oauth"],inference:["llm","completion","prompt","serving"],dependency:["advisory","vulnerability","audit","package"],package:["advisory","vulnerability","audit","dependency"],vulnerability:["advisory","audit","osv","vulnerable"],vulnerable:["advisory","vulnerability","audit"],advisory:["vulnerability","audit","osv"],cve:["advisory","vulnerability","osv"],risk:["advisory","vulnerability","audit"],security:["advisory","vulnerability","audit"],audit:["advisory","vulnerability","dependency"],scan:["scanner","vulnerability","audit"],retry:["backoff","throttle"],retries:["backoff","throttle"],email:["sender","template","message"],mail:["email","sender"],notification:["email","sms"],notify:["notification","email"],sms:["notification","message"],cart:["shop","order","discount"],order:["shop","fulfillment","cart","shipment"],shipping:["order","fulfillment","shipment"],shipped:["order","fulfillment","shipment"],inventory:["product","catalog","restock"],product:["shop","catalog","inventory"],discount:["cart"],chat:["room","presence","message"],message:["chat"],conversation:["chat","message"],online:["presence"],typing:["presence","broadcast","indicator"],video:["media","playback","thumbnail","transcode","stream"],stream:["playback","media","manifest"],streaming:["media","video","playback","manifest"],playback:["media","video","stream","watch"],transcode:["video","media"],thumbnail:["video","media"],media:["video","playback","stream"],analytics:["event","funnel","report","track"],event:["analytics","track"],track:["analytics","event"],funnel:["analytics","event","conversion"],conversion:["analytics","funnel"],report:["analytics","export","metrics"],article:["cms","publish"],publish:["article"],content:["article","cms","markdown"],markdown:["article","render"],deploy:["deployment","pipeline","release","rollback"],deployment:["pipeline","deploy","release","rollback"],release:["deploy","rollback"],rollback:["deployment","deploy","release"],pipeline:["ci","runner","stage","deploy"],canary:["deploy","release"],push:["mobile","device","token"],device:["mobile","push","register","token"],mobile:["push","device"],ios:["link","mobile","universal"],android:["push","mobile","device"],batch:["settlement","reconcile"],settlement:["batch","ledger","reconcile"],reconcile:["settlement","batch","ledger"],ledger:["settlement","reconcile"],mainframe:["settlement","batch","ebcdic","fixed"],ebcdic:["convert","record"],nightly:["batch"],geocode:["geo","address"],address:["geocode"],route:["geo","planner","distance"],distance:["route","geo"],arrival:["route","estimate"],translation:["locale"],translate:["locale","translation"],locale:["translation","format"],i18n:["locale","translation"],localized:["locale","translation","format"],metric:["export","counter","prometheus"],prometheus:["exporter","metric"],trace:["observability","span"],span:["trace"],counter:["increment","metric"],flag:["feature","experiment","rollout"],rollout:["flag","experiment","percentage"],experiment:["flag","assign","exposure","variant"],variant:["experiment","assign"],toggle:["flag","experiment","variant"],cache:["ttl","redis","memoize","eviction"],ttl:["cache","redis","eviction"],memoize:["cache","ttl"],database:["schema","migration","query","orm"],db:["database","schema","migration"],migration:["database","schema"],orm:["database","query","schema"],sql:["database","query","schema"],transaction:["database","schema"],queue:["broker","consumer","subscribe","topic"],broker:["queue","consumer","subscribe"],subscribe:["queue","broker","consumer"],consumer:["queue","broker","subscribe"],log:["logging"],logging:["log"],logger:["log","logging"],webhook:["callback","signature","idempotency"],callback:["webhook","signature"],idempotency:["webhook","callback"],throttle:["backoff","quota"],backoff:["throttle","quota"],quota:["throttle","backoff"],api:["endpoint","middleware"],endpoint:["api","middleware"],middleware:["api","endpoint"],graphql:["resolver","mutation"],resolver:["mutation"],component:["render","router"],render:["component","router"],router:["component","render"],css:["stylesheet","theme"],stylesheet:["css","theme"],theme:["css","stylesheet"],facet:["index","ranking"],ranking:["facet","index"],a11y:["aria","focus","contrast"],aria:["a11y","focus","contrast"],mock:["fixture","snapshot"],fixture:["mock","snapshot"],snapshot:["mock","fixture"],coverage:["mock","fixture"],consent:["retention","policy"],retention:["consent","policy"],csrf:["xss","sanitize"],xss:["csrf","sanitize"],logout:["session","auth"],mfa:["auth","login","sso"],sso:["auth","oauth"],jwt:["token","auth","session"],oidc:["oauth","auth","login"],cors:["origin","header"],smtp:["email","sender"],lockfile:["dependency"],language:["locale","translation","i18n"],l10n:["locale","i18n","translation"],localization:["locale","i18n","translation"],permission:["role","access"],role:["permission","access"]},Se={"direct debit":["debit","mandate","bacs","bank","sepa"],"direct debits":["debit","mandate","bacs","bank","sepa"],"sign in":["auth","login","session"],"signs in":["auth","login","session"],"log in":["login","auth","session"],"logs in":["auth","login","session"],"logged in":["login","auth","session"],"sign up":["account","register"],"signs up":["account","register"],"signing up":["account","register"],"signed up":["account","register"],"credit card":["stripe","payment","card","charge"],"credit cards":["stripe","payment","card","charge"],"two factor":["auth"],"payment method":["debit","stripe","payment","card"],"payment methods":["debit","stripe","payment","card"],"inference payment":["credit","usage"],"inference payments":["credit","usage"],"inference cost":["credit","usage"],"inference costs":["credit","usage"],"inference billing":["credit","usage"],"push notification":["push","device","token"],"push notifications":["push","device","token"],"deep link":["link"],"deep links":["link"],"universal link":["link","universal"],"universal links":["link","universal"],"feature flag":["experiment","flag","rollout"],"feature flags":["experiment","flag","rollout"],"shopping cart":["cart","order"],"roll back":["deployment","deploy","release"],"sign out":["session","auth"],"fixed width":["batch","export","record"],"canary rollout":["deployment","pipeline","deploy","release"],"canary rollouts":["deployment","pipeline","deploy","release"],"blog post":["article","cms","markdown","publish"],"blog posts":["article","cms","markdown","publish"],"signed out":["session","auth"],"rate limit":["throttle","backoff","quota"],"rate limits":["throttle","backoff","quota"],"screen reader":["a11y","aria","focus"],"dark mode":["theme","css"],"access token":["auth","session"],"refresh token":["token","session","auth"],"password reset":["password","token","auth"],"health check":["healthcheck","probe","live"],"circuit breaker":["circuit","breaker","fallback"],"api route":["router","endpoint"],"api routes":["router","endpoint"],"url route":["router","endpoint"],"url routes":["router","endpoint"],"route distance":["geo","planner","distance"],"queue message":["queue","broker","consumer"],"dead letter":["queue","broker","consumer"],"scan directory":["walk","glob"],"scan files":["walk","glob"],"search index":["facet","ranking"],"keyboard focus":["a11y","aria","focus"],"transaction rollback":["transaction","database","commit"],"rollback transaction":["transaction","database","commit"]},tt={"canary rollout":["rollout"],"canary rollouts":["rollouts"],"blog post":["post","blog"],"blog posts":["posts","blog"],"push notification":["notification"],"push notifications":["notification","notifications"],"inference payment":["payment"],"inference payments":["payment","payments"],"inference cost":["cost"],"inference costs":["cost","costs"],"inference billing":["billing"],"api route":["route"],"api routes":["route","routes"],"url route":["route"],"url routes":["route","routes"],"route distance":["route"],"queue message":["message"],"dead letter":["letter"],"scan directory":["scan"],"scan files":["scan"],"search index":["index"],"transaction rollback":["rollback"],"rollback transaction":["rollback"]},nt=new Set(["address the","address this","address that","address these","address those","address all","address my","track down","track it","track this","track that","track them","batch the","batch these","batch them","batch those","ship it","ship this","ship that"]),st=new Set(["users report","user reports","customers report","customer reports","people report","they report"]);function ie(e){let t=new Set;for(let n=0;n+1<e.length;n++){let i=`${e[n]} ${e[n+1]}`;nt.has(i)&&t.add(e[n]),st.has(i)&&t.add(e[n+1])}return t}function Re(){return Object.keys(Y)}function _e(e){if(!e)return null;if(Object.hasOwn(Y,e))return e;if(e.endsWith("ies")){let t=e.slice(0,-3)+"y";if(Object.hasOwn(Y,t))return t}if(e.endsWith("s")){let t=e.slice(0,-1);if(Object.hasOwn(Y,t))return t}return null}function U(e){let t=new Set(e),n=ie(e),i=[],o=new Set,l=(r,d)=>{t.has(r)||o.has(r)||(o.add(r),i.push({term:r,from:d}))};for(let r=0;r+1<e.length;r++){let d=`${e[r]} ${e[r+1]}`,p=Se[d];if(p)for(let f of p)l(f,d)}let a=G(e);for(let r of e){if(n.has(r)||a.has(r))continue;let d=_e(r);if(d)for(let p of Y[d])l(p,r)}return i}function G(e){let t=new Set;for(let n=0;n+1<e.length;n++){let i=`${e[n]} ${e[n+1]}`;if(Se[i]){for(let o of[e[n],e[n+1]])_e(o)||t.add(o);for(let o of tt[i]??[])t.add(o)}}return t}var Te=new Set(["the","a","an","is","are","was","were","be","to","of","in","on","for","and","or","where","what","which","how","do","does","did","i","we","it","this","that","with","when","who","why","can","should","my","our","you","your","from","by","at","as","find","code","responsible","need","modify","me","implementation","explain","works","codebase","contains","file","files","not","no","exist","exists","existing","occurrence","occurrences","occurence","occurences","every","place","places","string","literal","text","search","locate","look","looking","show","list","all","fix","fixes","fixing","bug","bugs","broken","busted","borked","wrong","incorrect","incorrectly","figure","out","sure"]),rt=.25,Ee=.7,ot=.35,it=.5,at=.5,ct=.4,xe=.3,lt=.3;function ut(e){let t=new Map;for(let o of e){let l=t.get(o.sym.file);(l===void 0||o.score>l)&&t.set(o.sym.file,o.score)}let n=new Map;for(let[o,l]of t){let a=o.slice(0,o.lastIndexOf("/")+1),r=n.get(a)??[];r.push(l),n.set(a,r)}let i=new Map;for(let[o,l]of n)l.sort((a,r)=>r-a),i.set(o,l.slice(0,3).reduce((a,r)=>a+r,0));return i}var ft=4,dt=64,mt=.35,gt=/(^|\/)(tests?|testing|__tests__)(\/|$)|(^|\/)(test_[^/]*|conftest\.py)$|[._-](test|tests|spec)\.[a-z0-9]+$/i;function pt(e){return gt.test(e)}var ht=/(^|\.)tests?(\.|$)|(^|\.)(?:test_[^.]*|Test[A-Z][^.]*|Benchmark[A-Z][^.]*|Fuzz[A-Z][^.]*)$/;function bt(e){return ht.test(e)}var yt=/\b(?:write|writes|add|adds|create|creates|extend|extends|improve|improves|update|updates|generate|generates)\b[^.?!]{0,40}\btests?\b|\bwhere\s+(?:is|are)\b[^.?!]{0,40}\btested\b|\btest\s+coverage\b/i;function vt(e,t){return yt.test(e)?!0:t.some(n=>/^test_|_tests?$|^conftest$/.test(n.term))}function B(e){return[...new Set(e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1&&!Te.has(t)))]}function X(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}function wt(e){let t=e.trim();return t=t.replace(/[.,;:!)\]}>]+$/g,""),t.endsWith("?")&&t.lastIndexOf("?")===t.length-1&&(t=t.slice(0,-1)),t}function te(e){let t=[],n=new Set,i=(o,l)=>{let a=o.trim();a=l==="url"?wt(a):a.replace(/[.,;:!)\]}>?]+$/g,""),!(a.length<2||n.has(a))&&(n.add(a),t.push(a))};for(let o of e.matchAll(/https?:\/\/[^\s"'`<>]+/gi))i(o[0],"url");for(let o of e.matchAll(/(["'`])((?:(?!\1)[^\\]|\\.){2,})\1/g))i(o[2].replace(/\\(.)/g,"$1"),"quote");return t}function ae(e){let t=e;for(let n of e.matchAll(/https?:\/\/[^\s"'`<>]+/gi))t=t.split(n[0]).join(" ");for(let n of te(e))t=t.split(n).join(" ");return t=t.replace(/(["'`])\s*\1/g," "),t.replace(/\s+/g," ").trim()}function kt(e){return/\b(where\s+is|where\s+are|find\s+(all\s+|every\s+)?occurrences?|does\s+not\s+exist|locate|search\s+for|occurrences?\s+of)\b/i.test(e)}function St(e,t){if(!t.length||kt(e))return null;let n=t.filter(i=>!/^https?:\/\//i.test(i)&&!i.includes("/"));return n.length?n.join(" "):null}function ee(e){return new Set(e.split(/[^\p{L}\p{N}]+|(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[\p{L}])(?=[0-9])|(?<=[0-9])(?=[\p{L}])/u).filter(Boolean).map(t=>t.toLowerCase()))}function ce(e){return e.length>=5&&e.endsWith("ies")?e.slice(0,-3)+"y":e.length>=4&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):null}function Rt(e,t){for(let n of t){let i=Ne(e,n);if(i>=5&&i>=.6*Math.min(e.length,n.length))return!0}return!1}function Ne(e,t){let n=Math.min(e.length,t.length),i=0;for(;i<n&&e[i]===t[i];)i++;return i}var _t=16,Et=36,xt=.75,Mt=.55;function At(e){let t=new Map;for(let n of e){if(Te.has(n)||t.has(n))continue;let i=t.size;t.set(n,i<_t?1:i<Et?xt:Mt)}return t}function Tt(e,t,n,i){let o=B(e),l=X(e),a=new Set(o),r=G(l),d=ie(l),p=At(l),f=o.map(c=>({term:c,weak:j.has(c)||r.has(c)||d.has(c),positional:p.get(c)??1})),h=new Set(o);for(let c of U(l))a.has(c.term)||(f.push({term:c.term,weak:!1,from:c.from,positional:p.get(c.from)??1}),h.add(c.term));if(i){let c=X(i),b=G(c);for(let g of B(i))h.has(g)||j.has(g)||b.has(g)||(f.push({term:g,weak:!1,from:"quote",quoted:!0}),h.add(g));for(let g of U(c))h.has(g.term)||(f.push({term:g.term,weak:!1,from:g.from}),h.add(g.term))}for(let c of t?.expansions??[]){let b=String(c?.term??"").toLowerCase().trim(),g=String(c?.from??"").toLowerCase().trim(),w=Number(c?.weight);!b||!g||b.includes(" ")||h.has(b)||j.has(g)||j.has(b)||!Number.isFinite(w)||w<at||(f.push({term:b,weak:!1,from:g,packWeight:Math.min(1,w)}),h.add(b))}if(n?.trim()){let c=X(n),b=G(c);for(let g of B(n))h.has(g)||j.has(g)||b.has(g)||(f.push({term:g,weak:!1,carried:!0}),h.add(g));for(let g of U(c))h.has(g.term)||(f.push({term:g.term,weak:!1,from:g.from,carried:!0}),h.add(g.term))}let v=f.some(c=>!c.weak);return{terms:f,hasContent:v}}function Oe(e){let t=e?.trim();return t?te(t).length>0?ae(t):t:null}function Nt(e,t){let n=t.terms.filter(a=>!a.weak&&!a.from&&!a.carried&&a.term.length>=4);if(!n.length)return;let i=new Map,o=new Set;for(let a of e){let r=a.name.toLowerCase(),d=a.file.toLowerCase(),p=ee(a.name);for(let f of p)o.add(f);for(let f of n){let h=ce(f.term);(p.has(f.term)||h!==null&&p.has(h)||r.includes(f.term)||d.includes(f.term))&&i.set(f.term,(i.get(f.term)??0)+1)}}let l=new Set(t.terms.map(a=>a.term));for(let a of n){if((i.get(a.term)??0)>0||U([a.term]).length>0)continue;let r=a.term.length>=8?2:1,d=null,p=(h,v)=>{if(h.length<4||h===a.term||v!==0&&a.term.length<6||Math.abs(h.length-a.term.length)>r||h[0]!==a.term[0])return;let c=Ot(a.term,h,r);if(c>r)return;let b=Ne(a.term,h);(!d||c<d.dist||c===d.dist&&(b>d.prefix||b===d.prefix&&(v<d.lex||v===d.lex&&h<d.cand)))&&(d={cand:h,dist:c,prefix:b,lex:v})};for(let h of Re())p(h,0);for(let h of o)p(h,1);if(!d)continue;let{cand:f}=d;l.has(f)||(t.terms.push({term:f,weak:!1,from:a.term}),l.add(f))}}function Ot(e,t,n){let i=e.length,o=t.length;if(Math.abs(i-o)>n)return n+1;let l=null,a=Array.from({length:o+1},(r,d)=>d);for(let r=1;r<=i;r++){let d=new Array(o+1);d[0]=r;let p=d[0];for(let f=1;f<=o;f++){let h=e[r-1]===t[f-1]?0:1,v=Math.min(a[f]+1,d[f-1]+1,a[f-1]+h);l&&r>1&&f>1&&e[r-1]===t[f-2]&&e[r-2]===t[f-1]&&(v=Math.min(v,l[f-2]+1)),d[f]=v,v<p&&(p=v)}if(p>n)return n+1;l=a,a=d}return a[o]}function It(e,t){if(t.length===0)return()=>1;let n=new Map,i=0;for(let l of e){i++;let a=l.name.toLowerCase(),r=ee(l.name);for(let d of t){let p=ce(d);(r.has(d)||p!==null&&r.has(p)||a.includes(d))&&n.set(d,(n.get(d)??0)+1)}}let o=new Map;for(let l of t){let a=Math.log((i+1)/((n.get(l)??0)+1))+1;o.set(l,Math.max(.5,Math.min(8,a)))}return l=>o.get(l)??1}function $t(e,t,n){let i=0,o=0,l=!1,a=!1,r=[],d=e.name.toLowerCase(),p=e.qualifiedName.toLowerCase(),f=e.file.toLowerCase(),h=f.split("/"),v=new Set(h.slice(0,-1)),c=h[h.length-1].replace(/\.[a-z0-9]+$/,""),b=ee(c),g=ee(e.name);for(let{term:w,weak:N,from:$,packWeight:S,carried:A,quoted:_,positional:C}of t){let W=S!==void 0?Math.min(S,Ee):$&&!_?Ee:1,O=n(w)*(N?rt:1)*W*(A?it:1)*(C??1),P=(A?"\u21A9":"")+($?`${$}\u2192${w}`:w),D=w.length>=4,z=ce(w),I=0,F=!1,K=!1;d===w?(I=10*O,K=!0,r.push(P)):g.has(w)||z!==null&&g.has(z)?(I=6*O,K=!0,r.push(P)):c===w||z!==null&&c===z?(I=(O>=3?8:5)*O,K=!0,r.push(P)):D&&d.includes(w)?(I=4*O,r.push(P)):D&&p.includes(w)||b.has(w)||z!==null&&b.has(z)?(I=3*O,r.push(P)):D&&w.length>=5&&c.includes(w)?(I=2.5*O,r.push(P)):S===void 0&&Rt(w,g)?(I=2*O,r.push((A?"\u21A9":"")+($?`~${$}\u2192${w}`:`~${w}`)),F=!0):v.has(w)?(I=2*O,r.push(P)):D&&f.includes(w)&&(I=1*O,r.push(P)),I>0&&(i+=I,N||(o+=1,F||(l=!0),K&&(a=!0)))}return o===0?{score:0,why:"",strong:!1,direct:!1}:(i*=1+ot*Math.min(o-1,4),{score:i,why:r.length?`matched: ${r.join(", ")}`:"",strong:l,direct:a})}function Ct(e,t){let n=e.split("/"),i=t.split("/"),o=0;for(;o<n.length&&o<i.length&&n[o]===i[o];)o++;return o}function Lt(e,t,n){if(!n)return{boost:1,label:""};let i=n[e];if(!i?.length)return{boost:1,label:""};let o=t?.taxonomy??[];if(o.length&&i.some(r=>r.includes("/"))){let r=0,d="";for(let p of o){let f=p.path.split("/").length;for(let h of i){let v=Ct(p.path,h);if(v===0)continue;let c=v/f*p.score;c>r&&(r=c,d=v===f?p.path:p.path.split("/").slice(0,v).join("/"))}}return r<=0?{boost:1,label:""}:{boost:1+xe*Math.min(r,1),label:`, topic:${d}`}}if(!t?.topics?.length)return{boost:1,label:""};let l=0,a=[];for(let r of t.topics)i.includes(r.id)&&(l+=r.score,a.push(r.id));return l<=0?{boost:1,label:""}:{boost:1+xe*Math.min(l,1),label:`, topic:${a.sort().join("+")}`}}function Me(e){return e.toLowerCase().replace(/\d+/g,"")}var Pt=2;function zt(e){return(e.name||e.qualifiedName).toLowerCase()}function Dt(e){let t=e[0]?.score??0;return t<=0?e:e.filter(n=>n.strong||n.score>=t/3)}function Wt(e){let t=new Set,n=[],i=[];for(let c of e)t.has(c.sym.file)?i.push(c):(t.add(c.sym.file),n.push(c));let o=n.concat(i),l=new Map,a=[],r=[];for(let c of o){let b=zt(c.sym),g=l.get(b)??0;l.set(b,g+1),(g<Pt?a:r).push(c)}let d=a.concat(r),p=new Set;for(let c of e)c.strong&&p.add(Me(c.sym.file));if(p.size<2)return d;let f=new Map,h=[],v=[];for(let c of d){let b=Me(c.sym.file),g=f.get(b)??0;g<ft?(f.set(b,g+1),h.push(c)):v.push(c)}return h.concat(v)}function Ft(e,t,n){let i=c=>[...new Set(c)].slice(0,8).join(", "),l=te(e).length>0?ae(e):e,a=[],r=new Map;for(let c of U(X(l))){let b=r.get(c.from)??[];b.push(c.term),r.set(c.from,b)}for(let[c,b]of r)a.push(`- "${c}" in the ask implies these codebase identifiers: ${i(b)}.`);let d=t?.taxonomy??[];if(d.length){let c=new Set,b=[];for(let S of d)for(let A of S.levels)c.has(A.path)||(c.add(A.path),b.push({path:A.path,id:A.id,depth:A.path.split("/").length,terms:A.terms}));let g=Math.max(...b.map(S=>S.depth)),w=(S,A)=>S.terms.length?`${A} ${S.id}; code for it typically uses: ${i(S.terms)}.`:`${A} ${S.id}.`;for(let S of b.filter(A=>A.depth===g))a.push(w(S,"- The ask is specifically about"));let N=new Set(b.filter(S=>S.depth===g).map(S=>S.id));for(let S of(t?.vendors??[]).filter(A=>A.score>0).slice(0,3)){if(N.has(S.name)){S.from!==S.name&&a.push(`- That product was typed "${S.from}".`);continue}a.push(S.from===S.name?`- It names the product "${S.name}".`:`- It names the product "${S.name}" (typed "${S.from}").`)}let $=new Set((t?.vendors??[]).map(S=>S.name));for(let S=g-1;S>=1;S--)for(let A of b.filter(_=>_.depth===S&&!$.has(_.id)))a.push(w(A,"- More broadly, this is"))}else if(t?.topics?.length){let c=new Map;for(let b of t.expansions??[]){let g=c.get(b.from)??[];g.push(b.term),c.set(b.from,g)}for(let b of t.topics.slice(0,3)){let g=c.get(b.id);a.push(g?.length?`- The ask is about the "${b.id}" domain; code for it typically uses: ${i(g)}.`:`- The ask is about the "${b.id}" domain.`)}}let p=t?.standards??[];if(p.length){let c=p.filter(w=>w.kind!=="regulation"),b=p.filter(w=>w.kind==="regulation"),g=w=>w.slice(0,3).map(N=>N.publisher?`${N.name} (${N.publisher})`:N.name).join("; ");c.length&&a.push(`- Standards that govern this area: ${g(c)}.`),b.length&&a.push(`- Regulations that apply here: ${g(b)}.`)}let f=t?.categories??[];f.length&&a.push(`- Related categories: ${i(f)}.`);let h=t?.files??[];h.length&&a.push(`- Files for this kind of work are usually named or extended: ${i(h)}.`);for(let c of(t?.corrections??[]).slice(0,3))a.push(`- Read "${c.from}" in the ask as "${c.to}".`);let v=Oe(n);if(v){let c=new Set(B(l)),b=G(X(v)),g=B(v).filter(w=>!c.has(w)&&!j.has(w)&&!b.has(w));g.length&&a.push(`- This is a follow-up; topic words carried from the previous ask: ${i(g)}.`)}return a.length&&a.push('- Seed notation below: `a\u2192b` = ask term "a" implied identifier "b"; `~t` = word-form match; `\u21A9t` = carried from the previous ask.'),a}var qt=/^\s*at\s+\S.*\((?:node:|internal\/|[^()]*[/\\]node_modules[/\\]|[^()]*[/\\]\.pnpm[/\\])[^()]*\)\s*$/i,Ht=/^\s*at\s+(?:node:|internal\/|\/?(?:[^\s()]*[/\\])?node_modules[/\\])\S*\s*$/i;function Kt(e){if(!e.includes(" at ")&&!/^\s*at\s/m.test(e))return e;let n=e.split(`
|
|
2
|
+
`).filter(i=>!qt.test(i)&&!Ht.test(i)).join(`
|
|
3
|
+
`).trim();return n.length>0?n:e}function Ae(e){return Math.round(e*1e6)/1e6}function le(e,t){return{rankSymbols(n,i,o={}){let l=Math.max(1,Math.min(o.limit??16,dt)),a=Kt(n),r=null;try{r=e(a)}catch{r=null}let d=te(a),p=d.length>0?ae(a):a,f=Oe(o.priorQuestion),h=Tt(p,r,f,St(n,d));Nt(i,h);let v=Ft(n,r,o.priorQuestion??null);if(!h.hasContent)return{version:t(),hasContent:!1,seeds:[],conceptMap:v};let c=It(i,h.terms.map(_=>_.term)),b=!vt(a,h.terms),g=[];for(let _ of i){let{score:C,why:W,strong:O,direct:P}=$t(_,h.terms,c);if(C>0){let D=Lt(_.id,r,o.topicTags),z=pt(_.file)||bt(_.qualifiedName),I=b&&z?mt:1;g.push({sym:_,score:Ae(C*I*D.boost*(1+ct*_.importance)),why:W+D.label,strong:O,direct:P})}}let w=ut(g),N=0;for(let _ of w.values())_>N&&(N=_);if(N>0)for(let _ of g){let C=_.sym.file.slice(0,_.sym.file.lastIndexOf("/")+1),W=(w.get(C)??0)/N;_.score=Ae(_.score*(1+lt*W))}g.sort((_,C)=>C.score-_.score||(_.sym.qualifiedName<C.sym.qualifiedName?-1:1));let $=Wt(Dt(g)).slice(0,l);if(!$.some(_=>_.direct))return{version:t(),hasContent:!1,seeds:[],conceptMap:v};let A=$.map(_=>({id:_.sym.id,score:_.score,why:_.why}));return{version:t(),hasContent:!0,seeds:A,conceptMap:v}}}}var jt=!1,Ie=`vg-relevance@1.5.0+pack.${oe.version}`,Ut=20,Gt=8,Vt=4,Yt=.34,Bt=.8,Xt=.6,Zt=.5,Qt=.45,He=new Set(["the","and","for","with","first","new","web","app","development"]),Jt=2e3,en=1200,Ke=550,ue=2e3,tn=1200,nn=800,sn=1e3,rn=600,$e=1e3,Ce=3e3,on=1e3,fe=e=>Math.round(Math.min(e,Ce)/Ce*1e3)/1e3,je=6,an=6,cn=6,ln=10,un=6,fn=6,dn=8,de=4,R=oe;for(let e of[R.acronyms,R.vendors,R.synonyms,R.topics,R.taxonomyTerms,R.vendorNode,R.fileHints,R.standards])e&&typeof e=="object"&&Object.setPrototypeOf(e,null);function mn(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=2)}function gn(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}var pn=new Set(["the","an","our","your","their","its","this","that","these","those","each","every","another","any"]);function Z(e){return e.split(" ").filter(t=>t.length>=3&&!He.has(t))}var hn=40,Le=128,Ue=Uint8Array.from(Buffer.from(R.vectors?.data??"","base64")),me=new Map((R.vectors?.terms??[]).map((e,t)=>[e,t])),bn=new Set(R.vectors?.skip??[]);function yn(e){let t=me.get(e);if(t!==void 0)return{row:t,term:e};if(e.endsWith("s")&&e.length>4){let n=e.slice(0,-1);if(t=me.get(n),t!==void 0)return{row:t,term:n}}return null}function vn(e,t){let n=Ue[e*(R.vectors?.dim??0)+t]??0;return n>127?n-256:n}var T=R.taxonomy??[],H=R.taxonomyTerms??{},Pe=R.vendorNode??{},ge=R.fuzzyKeys??[],wn=R.fileHints??{},kn=R.standards??{};function Sn(e){let t=[];for(let n=e;n>=0;n=T[n].parent){let i=T[n].path;for(let o of kn[i]??[])t.some(l=>l.name===o.name)||t.push({name:o.name,publisher:o.publisher,node:i,kind:o.kind??"standard",categories:o.categories??[]});if(T[n].parent<0)break}return t.slice(0,de)}function ze(e){let t=[];for(let n=e;n>=0;n=T[n].parent){for(let i of wn[T[n].path]??[])t.includes(i)||t.push(i);if(T[n].parent<0)break}return t.slice(0,fn)}var Rn=ge.map(e=>({mask:Ge(e.key),grams:Ve(e.key),len:e.key.length})),pe=new Set(R.weakTerms??[]),ne=new Set(R.englishGuard??[]),De=e=>e.includes(" ")?Jt:pe.has(e)?Ke:en,he=T.map(()=>[]);for(let[e,t]of T.entries())t.parent>=0&&he[t.parent].push(e);var We=new Map(T.map((e,t)=>[e.path,t]));function Ge(e){let t=0;for(let n=0;n<e.length;n++){let i=e.charCodeAt(n)-97;t|=i>=0&&i<26?1<<i:1<<26}return t}function _n(e){let t=0;for(let n=e;n;n&=n-1)t++;return t}function Ve(e){let t=[];for(let n=0;n<e.length-1;n++)t.push(e.slice(n,n+2));return[...new Set(t)].sort()}function En(e,t){let n=0,i=0,o=0;for(;n<e.length&&i<t.length;)e[n]===t[i]?(o++,n++,i++):e[n]<t[i]?n++:i++;return o}function xn(e,t,n){let i=e.length,o=t.length;if(Math.abs(i-o)>n)return n+1;let l=[],a=new Array(o+1);for(let r=0;r<=o;r++)a[r]=r;for(let r=1;r<=i;r++){let d=new Array(o+1);d[0]=r;let p=d[0];for(let f=1;f<=o;f++){let h=e[r-1]===t[f-1]?0:1,v=Math.min(d[f-1]+1,a[f]+1,a[f-1]+h);r>1&&f>1&&e[r-1]===t[f-2]&&e[r-2]===t[f-1]&&(v=Math.min(v,l[f-2]+1)),d[f]=v,v<p&&(p=v)}if(p>n)return n+1;l=a,a=d}return a[o]}var Fe=new Set(["s","es","ed","d","ing","ly","er","ers","ings"]);function Mn(e){return e<je?0:e>=9?2:1}function An(e,t=2){let n=Math.min(Mn(e.length),t);if(n===0||me.has(e)||ne.has(e))return null;let i=Ve(e),o=e.length>=6?2:1,l=null,a=n+1,r=!1,d=Ge(e);for(let f=0;f<ge.length;f++){let h=Rn[f];if(Math.abs(h.len-e.length)>n||_n(d^h.mask)>n*2)continue;let v=ge[f];if(En(i,h.grams)<o)continue;let c=xn(e,v.key,n);c>n||(c<a?(a=c,l=v,r=!1):c===a&&l&&v.ref!==l.ref&&(r=!0))}if(!l||r||a>=2&&e[0]!==l.key[0])return null;let p=e.startsWith(l.key)?e.slice(l.key.length):"";if(p&&/^(id|ids|[0-9]+)$/.test(p))return null;if(e.startsWith(l.key)){let f=e.slice(l.key.length);if(Fe.has(f))return null}return l.key.startsWith(e)&&Fe.has(l.key.slice(e.length))?null:{key:l,distance:a}}var be=new Map;for(let e of T){if(!e.topic)continue;let t=be.get(e.topic);(!t||e.path.split("/").length<t.split("/").length)&&be.set(e.topic,e.path)}var Ye=new Map;for(let[e,t]of Object.entries(R.topicPathHints??{}))for(let n of t)Ye.set(n,e);function qe(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=2)}function Tn(){let e=ke();if(!e&&!jt)throw new Error("@vibgrate/relevance: the wasm engine failed to load and this build ships no reference implementation. Reinstall the module.");let t=e?{version:()=>e.version(),analyzeQuery:i=>JSON.parse(e.analyzeQueryJson(i)),tagNode:i=>JSON.parse(e.tagNodeJson(i.qualifiedName??"",i.file??""))}:Nn(),n=le(i=>t.analyzeQuery(i),()=>t.version());return{...t,rankSymbols:n.rankSymbols}}function Nn(){return{version:()=>Ie,tagNode(e){let t=new Set([...qe(e.file??""),...qe(e.qualifiedName??"")]),n=new Set;for(let o of t){if(o.length<3||pe.has(o)||ne.has(o))continue;for(let r of H[o]??[])n.add(T[r].path);let l=Pe[o];l&&n.add(l);let a=Ye.get(o);if(a&&!l){let r=be.get(a);r&&n.add(r)}}return[...n].filter(o=>![...n].some(l=>l!==o&&l.startsWith(`${o}/`))).sort((o,l)=>l.split("/").length-o.split("/").length||(o<l?-1:1)).slice(0,3)},analyzeQuery(e){let t=mn(e),n=new Set(t);for(let s=0;s<t.length-1;s++)n.add(`${t[s]} ${t[s+1]}`);let i=new Set(n),o=[];for(let s of[...n].sort()){let u=R.acronyms[s];u&&o.push({acronym:s,full:u})}for(let s of o)for(let u of Z(s.full))n.add(u);let l=gn(e),a=` ${[...l,...o.map(s=>s.full)].join(" ")} `,r=(s,u)=>{let k=` ${u} `;for(let m=s.indexOf(k);m!==-1;m=s.indexOf(k,m+1)){let y=s.slice(0,m),M=y.lastIndexOf(" ");if(M!==-1&&pn.has(y.slice(M+1)))return!0}return!1},d=(s,u)=>u.charCodeAt(0)===97&&u.charCodeAt(1)===32?r(s,u):s.includes(` ${u} `),p=s=>s.includes(" ")?d(a,s):n.has(s),f=s=>s.length>3&&s.endsWith("s")&&!s.endsWith("ss")?s.slice(0,-1):s,h=t.map(f),v=` ${l.map(f).join(" ")} `,c=new Set(h);for(let s=0;s<h.length-1;s++)c.add(`${h[s]} ${h[s+1]}`);let b=s=>p(s)||(s.includes(" ")?d(v,s):c.has(s)),g=[],w=new Map,N=(s,u)=>w.set(s,(w.get(s)??0)+u),$=new Map,S=new Map,A=new Map,_=[],C=(s,u,k)=>{$.set(s,($.get(s)??0)+u);let m=S.get(s)??[];m.includes(k)||m.push(k),S.set(s,m)},W=(s,u,k)=>{let m=R.vendors[s];if(!m)return;let y=A.get(s),M=fe(k);if(y&&y.score>=M)return;let x=Pe[s],E=x!==void 0?We.get(x):void 0;if(A.set(s,{name:s,from:u,topic:m.topic,score:M,files:E!==void 0?ze(E):[],...x?{node:x}:{}}),x!==void 0){let L=We.get(x);L!==void 0&&C(L,k,u===s?s:`~${u}`)}};if(T.length){for(let m of o)for(let y of H[m.acronym]??[])C(y,sn,m.acronym);for(let[m,y]of Object.entries(H)){if(!b(m))continue;let M=De(m),x=Math.floor(M/y.length);for(let E of y)C(E,x,m)}for(let m of n)R.vendors[m]&&W(m,m,ue);let s=[];for(let m of t)!R.vendors[m]&&!H[m]&&s.push({token:m,from:m,maxDistance:2});for(let m=0;m<t.length-1;m++){let y=t[m],M=t[m+1],x=`${y}${M}`;if(R.vendors[x]){W(x,`${y} ${M}`,ue);continue}if(H[x])continue;let E=[y,M].filter(L=>!ne.has(L));y.length>=3&&M.length>=3&&E.some(L=>L.length>=4)&&s.push({token:x,from:`${y} ${M}`,maxDistance:1})}let u=new Set,k=new Map;for(let{token:m,from:y,maxDistance:M}of s){if(m.length<je||u.has(m)||(u.add(m),R.vendors[m]||H[m]))continue;let x=An(m,M);if(!x||x.distance===0)continue;let E=x.distance===1?tn:nn;if(_.push({from:y,to:x.key.ref,distance:x.distance}),k.set(m,x.key.ref),x.key.kind==="vendor")W(x.key.ref,y,E);else if(x.key.kind==="term"){let L=H[x.key.ref]??[];for(let we of L)C(we,Math.floor(E/L.length),`~${y}`)}}if(k.size){let m=t.map(E=>k.get(E)??E);for(let E=0;E<m.length-1;E++){let L=k.get(`${t[E]}${t[E+1]}`);L&&(m[E]=L,m[E+1]="")}let y=m.filter(Boolean),M=` ${y.join(" ")} `,x=new Set(y);for(let E=0;E<y.length-1;E++)x.add(`${y[E]} ${y[E+1]}`);for(let[E,L]of Object.entries(H)){if(!(E.includes(" ")?M.includes(` ${E} `):x.has(E))||(E.includes(" ")?a.includes(` ${E} `):n.has(E)))continue;let Xe=Math.floor(De(E)*an/10),Ze=Math.floor(Xe/L.length);for(let Qe of L)C(Qe,Ze,`~${E}`)}}for(let[m,y]of $){let M=T[m]?.topic;M&&N(M,y)}}for(let s of o)for(let u of Z(s.full))g.push({term:u,from:s.acronym,weight:Bt});for(let s of n){let u=R.vendors[s];if(u){N(u.topic,ue);for(let k of u.terms)for(let m of Z(k))g.push({term:m,from:s,weight:Xt})}}for(let[s,u]of Object.entries(R.topics))for(let k of u.terms){if(!p(k))continue;let m=!k.includes(" ")&&(pe.has(k)||ne.has(k));N(s,m?Ke:on)}if(R.vectors&&Ue.length){let s=new Map;for(let u of t){if(u.length<3||He.has(u)||bn.has(u))continue;let k=yn(u);if(k)for(let m=0;m<R.vectors.dim;m++){let y=vn(k.row,m);y>=hn&&s.set(m,(s.get(m)??0)+y)}}for(let[u,k]of s){let m=R.vectors.topics[u];N(m,Math.round(Math.min(k,Le)*rn/Le))}}for(let s of n){let u=R.synonyms[s];if(u)for(let k of u)for(let m of Z(k))g.push({term:m,from:s,weight:Zt})}let O=[...w.entries()].filter(([,s])=>s>=$e),P=Math.max(0,...O.map(([,s])=>s)),D=P>0?O.map(([s,u])=>({id:s,score:Math.round(u/P*1e3)/1e3})).filter(s=>s.score>=Yt).sort((s,u)=>u.score-s.score||(s.id<u.id?-1:1)).slice(0,Vt):[];for(let s of D){let u=0;for(let k of R.topics[s.id]?.terms??[])for(let m of Z(k))i.has(m)||u>=Gt||(g.push({term:m,from:s.id,weight:Math.round(Qt*s.score*1e3)/1e3}),u+=1)}let z=new Map;for(let s of g){if(i.has(s.term))continue;let u=z.get(s.term);(!u||s.weight>u.weight)&&z.set(s.term,s)}let I=[...z.values()].sort((s,u)=>u.weight-s.weight||(s.term<u.term?-1:1)).slice(0,Ut),F=new Array(T.length).fill(0);for(let[s,u]of $){let k=s;for(;k!==void 0&&k>=0;){F[k]+=u;let m=T[k].parent;k=m>=0?m:void 0}}let K=s=>F[s]>=$e,ye=[];for(let s=0;s<T.length;s++)K(s)&&(he[s].some(u=>K(u))||ye.push(s));let se=ye.map(s=>{let u=[];for(let y=s;y>=0&&(u.unshift(y),!(T[y].parent<0));y=T[y].parent);let k=new Set,m=y=>{for(let M of S.get(y)??[])k.add(M);for(let M of he[y]??[])m(M)};for(let y of u)for(let M of S.get(y)??[])k.add(M);return m(s),{path:T[s].path,levels:u.map(y=>({id:T[y].path.split("/").pop(),path:T[y].path,score:fe(F[y]),terms:(T[y].terms??[]).slice(0,un)})),score:fe(F[s]),evidence:Math.round(F[s])/1e3,via:[...k].sort(),terms:(T[s].terms??[]).slice(0,ln),files:ze(s),standards:Sn(s)}}).sort((s,u)=>u.evidence-s.evidence||(s.path<u.path?-1:1)).slice(0,cn),ve=[...A.values()].sort((s,u)=>u.score-s.score||(s.name<u.name?-1:1)),Be=[...new Map(_.map(s=>[`${s.from}>${s.to}`,s])).values()].sort((s,u)=>s.from<u.from?-1:1),V=[];for(let s of ve)for(let u of s.files)V.includes(u)||V.push(u);for(let s of se)for(let u of s.files)V.includes(u)||V.push(u);let Q=[];for(let s of se)for(let u of s.standards)Q.some(k=>k.name===u.name)||Q.push(u);let re=[];for(let s of Q.slice(0,de))for(let u of s.categories)re.includes(u)||re.push(u);return{version:Ie,topics:D,expansions:I,taxonomy:se,vendors:ve,corrections:Be,files:V.slice(0,dn),standards:Q.slice(0,de),categories:re}}}}export{Tn as createRelevanceProvider,le as createSymbolRanker};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibgrate/relevance",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.829.1",
|
|
4
4
|
"description": "Vibgrate relevance kernel: query analysis over the compiled relevance pack. Proprietary distribution — the compiled WASM engine plus a minified wrapper; the relevance pack and the reference implementation are not included.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|