@vibgrate/relevance 2026.824.4 → 2026.826.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 +1 -1
- package/package.json +6 -2
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var re={};import*as Q from"node:fs";import{fileURLToPath as et}from"node:url";var W;function ke(){if(W!==void 0)return W;W=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 W;let n=new WebAssembly.Module(Q.readFileSync(t)),o=new WebAssembly.Instance(n,{}).exports,l=i=>{let f=new TextEncoder().encode(i),d=o.vg_alloc(f.length);return new Uint8Array(o.memory.buffer,d,f.length).set(f),{ptr:d,len:f.length}},r=i=>{let d=new DataView(o.memory.buffer,i,4).getUint32(0,!0),c=new TextDecoder().decode(new Uint8Array(o.memory.buffer,i+4,d));return o.vg_free(i,4+d),c};return W={version:()=>r(o.vg_version()),analyzeQueryJson:i=>{let{ptr:f,len:d}=l(i),c=r(o.vg_analyze(f,d));return o.vg_free(f,d),c},tagNodeJson:(i,f)=>{let d=l(i),c=l(f),h=r(o.vg_tag(d.ptr,d.len,c.ptr,c.len));return o.vg_free(d.ptr,d.len),o.vg_free(c.ptr,c.len),h}},W}catch{return W=null,W}}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","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"]),G={payment:["stripe","billing","invoice","checkout","charge","subscription","refund","payout","card","debit","mandate"],pay:["payment","stripe","charge","billing","invoice"],paying:["payment","stripe","charge","billing","invoice"],paid:["payment","invoice","charge"],receipt:["invoice","billing","payment","charge"],billing:["invoice","payment","subscription","stripe","charge","renewal"],billed:["billing","invoice","charge","payment"],bill:["billing","invoice","payment"],checkout:["stripe","payment","cart","session"],debit:["mandate","sepa","bacs","ach","bank","payment"],mandate:["sepa","bacs","debit"],sepa:["mandate","debit","iban","bank"],bacs:["mandate","debit","bank"],ach:["mandate","debit","bank"],stripe:["payment","billing","checkout","webhook","charge","card"],refund:["payment","invoice","stripe","charge"],invoice:["billing","payment","refund","subscription"],subscription:["billing","renewal","invoice","plan","recurring"],recurring:["subscription","renewal","mandate","debit"],renewal:["subscription","billing","renew"],card:["payment","charge","stripe"],credit:["card","payment","charge"],bank:["debit","mandate","sepa","iban","account"],charge:["payment","card","stripe"],webhook:["event","handler","callback"],price:["payment","billing","plan"],customer:["billing","account","user"],auth:["login","session","token","oauth","password","credential"],authentication:["auth","login","session","token","password"],authenticated:["auth","login","session"],login:["auth","session","password","signin","oauth"],signin:["login","auth","session"],signup:["register","onboard","account"],logout:["session","auth","signout"],password:["auth","login","credential","hash"],session:["auth","login","token"],token:["session","auth","jwt"],oauth:["auth","login","callback","provider"],google:["oauth","login","auth"],github:["oauth","login","auth"],sso:["oauth","auth","saml","login"],credential:["auth","password","token","secret"],dependency:["package","audit","vulnerability","advisory","lockfile","version"],package:["dependency","audit","vulnerability","advisory","lockfile"],vulnerability:["advisory","cve","osv","audit","vulnerable"],vulnerable:["vulnerability","advisory","audit","cve"],advisory:["vulnerability","cve","osv","audit"],cve:["vulnerability","advisory","osv"],risk:["vulnerability","audit","advisory"],security:["vulnerability","audit","advisory"],audit:["dependency","vulnerability","advisory"],scan:["audit","vulnerability","scanner"],email:["mail","smtp","sender","template","message"],mail:["email","smtp","sender"],notification:["notify","email","sms","push","alert"],notify:["notification","email","alert"],sms:["notification","message","twilio"],cart:["checkout","order","shop","basket","discount"],basket:["cart","checkout","order"],order:["cart","shipment","fulfillment","shop","checkout"],ship:["order","fulfillment","delivery","shipment"],shipment:["order","fulfillment","delivery","track"],shipping:["order","fulfillment","delivery","shipment"],shipped:["order","fulfillment","shipment"],inventory:["stock","product","catalog","restock"],stock:["inventory","product","restock"],product:["catalog","inventory","shop"],discount:["coupon","promo","cart","price"],coupon:["discount","promo","code"],chat:["message","room","conversation","presence"],message:["chat","sms","notification","thread"],conversation:["chat","message","thread"],presence:["online","typing","status"],online:["presence","status"],typing:["presence","indicator","broadcast"],video:["media","transcode","playback","stream","thumbnail"],stream:["video","playback","manifest","media"],streaming:["video","playback","manifest","media"],playback:["video","stream","media","watch"],transcode:["video","media","encode"],thumbnail:["video","image","media"],media:["video","stream","playback","asset"],analytics:["event","track","metric","funnel","report"],event:["track","analytics","webhook"],track:["event","analytics"],funnel:["conversion","analytics","event"],conversion:["funnel","analytics"],report:["metrics","export","analytics"],article:["publish","content","post","cms"],publish:["article","release","post","content"],post:["article","publish","message"],blog:["article","publish","post","cms"],content:["cms","article","markdown"],markdown:["render","article","content"],cms:["article","content","publish"],deploy:["release","rollback","pipeline","deployment"],deployment:["deploy","release","rollback","pipeline"],release:["deploy","version","rollback"],rollback:["deploy","release","deployment"],pipeline:["stage","deploy","runner","ci"],canary:["deploy","rollout","release"],push:["notification","device","token","mobile"],device:["push","token","mobile","register"],deeplink:["link","route","universal"],mobile:["push","device","deeplink","app"],ios:["mobile","universal","link","app"],android:["mobile","push","device","app"],batch:["settlement","job","etl","reconcile"],settlement:["batch","reconcile","ledger","clearing"],reconcile:["ledger","settlement","batch"],ledger:["settlement","reconcile","balance","journal"],mainframe:["batch","settlement","ebcdic","cobol","fixed"],ebcdic:["mainframe","record","convert","legacy"],cobol:["mainframe","batch","ebcdic"],etl:["batch","pipeline","extract","load","transform"],nightly:["batch","cron","schedule","job"],geocode:["address","location","map","geo"],address:["geocode","location"],map:["geo","route","location"],route:["distance","path","planner","geo"],distance:["route","haversine","geo"],location:["geo","geocode","map"],arrival:["route","eta","estimate"],translation:["locale","i18n","language","translate"],translate:["translation","locale","language"],locale:["translation","i18n","language","format"],i18n:["translation","locale","language"],language:["locale","translation","i18n"],localized:["locale","translation","format"],metric:["counter","prometheus","telemetry","export"],prometheus:["metric","exporter","monitoring"],trace:["span","telemetry","observability"],span:["trace","telemetry"],monitoring:["metric","trace","alert","observability"],telemetry:["metric","trace","span"],counter:["metric","increment"],flag:["feature","rollout","toggle","experiment"],rollout:["flag","percentage","release","experiment","deploy"],toggle:["flag","feature","switch"],experiment:["variant","assign","flag","exposure"],variant:["experiment","assign"],database:["schema","migration","sql","query","orm"],db:["database","schema","migration","sql"],migration:["database","schema","migrate","sql"],cache:["redis","ttl","store"],queue:["job","worker","task","batch"],job:["queue","worker","cron"],upload:["file","storage","blob","asset"],storage:["file","upload","bucket","blob"],permission:["role","rbac","acl","access","grant"],role:["permission","rbac","access"],error:["exception","failure","handler"],config:["settings","env","configuration"]},Se={"direct debit":["debit","mandate","sepa","bacs","bank"],"direct debits":["debit","mandate","sepa","bacs","bank"],"sign in":["login","signin","auth","session"],"signs in":["login","signin","auth","session"],"log in":["login","auth","session"],"logs in":["login","auth","session"],"logged in":["login","auth","session"],"sign up":["signup","register","account"],"signs up":["signup","register","account"],"signing up":["signup","register","account"],"signed up":["signup","register","account"],"credit card":["card","payment","charge","stripe"],"credit cards":["card","payment","charge","stripe"],"bank transfer":["bank","payment","sepa","transfer"],"rate limit":["ratelimit","throttle","quota"],"two factor":["totp","mfa","otp","auth"],"payment method":["payment","stripe","card","debit"],"payment methods":["payment","stripe","card","debit"],"push notification":["push","device","token","notification"],"push notifications":["push","device","token","notification"],"deep link":["deeplink","link","route"],"deep links":["deeplink","link","route"],"universal link":["deeplink","link","universal"],"universal links":["deeplink","link","universal"],"feature flag":["flag","rollout","toggle","experiment"],"feature flags":["flag","rollout","toggle","experiment"],"shopping cart":["cart","checkout","order"],"roll back":["rollback","deploy","release"],"rolled back":["rollback","deploy","release"],"ab test":["experiment","variant"],"sign out":["logout","session","auth"],"fixed width":["record","export","mainframe","batch"],"canary rollout":["deploy","deployment","release","pipeline"],"canary rollouts":["deploy","deployment","release","pipeline"],"blog post":["article","publish","cms","content","post","markdown"],"blog posts":["article","publish","cms","content","post","markdown"]},tt={"canary rollout":["rollout"],"canary rollouts":["rollouts"],"blog post":["post","blog"],"blog posts":["posts","blog"]},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(G)}function _e(e){if(!e)return null;if(Object.hasOwn(G,e))return e;if(e.endsWith("ies")){let t=e.slice(0,-3)+"y";if(Object.hasOwn(G,t))return t}if(e.endsWith("s")){let t=e.slice(0,-1);if(Object.hasOwn(G,t))return t}return null}function j(e){let t=new Set(e),n=oe(e),a=[],o=new Set,l=(i,f)=>{t.has(i)||o.has(i)||(o.add(i),a.push({term:i,from:f}))};for(let i=0;i+1<e.length;i++){let f=`${e[i]} ${e[i+1]}`,d=Se[f];if(d)for(let c of d)l(c,f)}let r=K(e);for(let i of e){if(n.has(i)||r.has(i))continue;let f=_e(i);if(f)for(let d of G[f])l(d,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,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 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,gt=.35,pt=/(^|\/)(tests?|testing|__tests__)(\/|$)|(^|\/)(test_[^/]*|conftest\.py)$|[._-](test|tests|spec)\.[a-z0-9]+$/i;function mt(e){return pt.test(e)}var ht=/\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 bt(e,t){return ht.test(e)?!0:t.some(n=>/^test_|_tests?$|^conftest$/.test(n.term))}function Y(e){return[...new Set(e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1&&!Te.has(t)))]}function q(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}function yt(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"?yt(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 vt(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 wt(e,t){if(!t.length||vt(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 kt(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 St=16,Rt=36,_t=.75,Et=.55;function xt(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<St?1:a<Rt?_t:Et)}return t}function Mt(e,t,n,a){let o=Y(e),l=q(e),r=new Set(o),i=K(l),f=oe(l),d=xt(l),c=o.map(m=>({term:m,weak:H.has(m)||i.has(m)||f.has(m),positional:d.get(m)??1})),h=new Set(o);for(let m of j(l))r.has(m.term)||(c.push({term:m.term,weak:!1,from:m.from,positional:d.get(m.from)??1}),h.add(m.term));if(a){let m=q(a),b=K(m);for(let p of Y(a))h.has(p)||H.has(p)||b.has(p)||(c.push({term:p,weak:!1,from:"quote",quoted:!0}),h.add(p));for(let p of j(m))h.has(p.term)||(c.push({term:p.term,weak:!1,from:p.from}),h.add(p.term))}for(let m of t?.expansions??[]){let b=String(m?.term??"").toLowerCase().trim(),p=String(m?.from??"").toLowerCase().trim(),_=Number(m?.weight);!b||!p||b.includes(" ")||h.has(b)||H.has(p)||H.has(b)||!Number.isFinite(_)||_<at||(c.push({term:b,weak:!1,from:p,packWeight:Math.min(1,_)}),h.add(b))}if(n?.trim()){let m=q(n),b=K(m);for(let p of Y(n))h.has(p)||H.has(p)||b.has(p)||(c.push({term:p,weak:!1,carried:!0}),h.add(p));for(let p of j(m))h.has(p.term)||(c.push({term:p.term,weak:!1,from:p.from,carried:!0}),h.add(p.term))}let k=c.some(m=>!m.weak);return{terms:c,hasContent:k}}function Oe(e){let t=e?.trim();return t?ee(t).length>0?ie(t):t:null}function At(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(),f=r.file.toLowerCase(),d=J(r.name);for(let c of d)o.add(c);for(let c of n){let h=ae(c.term);(d.has(c.term)||h!==null&&d.has(h)||i.includes(c.term)||f.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||j([r.term]).length>0)continue;let i=r.term.length>=8?2:1,f=null,d=(h,k)=>{if(h.length<4||h===r.term||k!==0&&r.term.length<6||Math.abs(h.length-r.term.length)>i||h[0]!==r.term[0])return;let m=Tt(r.term,h,i);if(m>i)return;let b=Ne(r.term,h);(!f||m<f.dist||m===f.dist&&(b>f.prefix||b===f.prefix&&(k<f.lex||k===f.lex&&h<f.cand)))&&(f={cand:h,dist:m,prefix:b,lex:k})};for(let h of Re())d(h,0);for(let h of o)d(h,1);if(!f)continue;let{cand:c}=f;l.has(c)||(t.terms.push({term:c,weak:!1,from:r.term}),l.add(c))}}function Tt(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,f)=>f);for(let i=1;i<=a;i++){let f=new Array(o+1);f[0]=i;let d=f[0];for(let c=1;c<=o;c++){let h=e[i-1]===t[c-1]?0:1,k=Math.min(r[c]+1,f[c-1]+1,r[c-1]+h);l&&i>1&&c>1&&e[i-1]===t[c-2]&&e[i-2]===t[c-1]&&(k=Math.min(k,l[c-2]+1)),f[c]=k,k<d&&(d=k)}if(d>n)return n+1;l=r,r=f}return r[o]}function Nt(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 f of t){let d=ae(f);(i.has(f)||d!==null&&i.has(d)||r.includes(f))&&n.set(f,(n.get(f)??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 Ot(e,t,n){let a=0,o=0,l=!1,r=[],i=e.name.toLowerCase(),f=e.qualifiedName.toLowerCase(),d=e.file.toLowerCase(),c=d.split("/"),h=new Set(c.slice(0,-1)),k=c[c.length-1].replace(/\.[a-z0-9]+$/,""),m=J(k),b=J(e.name);for(let{term:p,weak:_,from:N,packWeight:S,carried:y,quoted:A,positional:L}of t){let P=S!==void 0?Math.min(S,Ee):N&&!A?Ee:1,O=n(p)*(_?rt:1)*P*(y?it:1)*(L??1),C=(y?"\u21A9":"")+(N?`${N}\u2192${p}`:p),F=p.length>=4,D=ae(p),I=0,B=!1;i===p?(I=10*O,r.push(C)):b.has(p)||D!==null&&b.has(D)?(I=6*O,r.push(C)):k===p||D!==null&&k===D?(I=(O>=3?8:5)*O,r.push(C)):F&&i.includes(p)?(I=4*O,r.push(C)):F&&f.includes(p)||m.has(p)||D!==null&&m.has(D)?(I=3*O,r.push(C)):F&&p.length>=5&&k.includes(p)?(I=2.5*O,r.push(C)):S===void 0&&kt(p,b)?(I=2*O,r.push((y?"\u21A9":"")+(N?`~${N}\u2192${p}`:`~${p}`)),B=!0):h.has(p)?(I=2*O,r.push(C)):F&&d.includes(p)&&(I=1*O,r.push(C)),I>0&&(a+=I,_||(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 It(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 $t(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,f="";for(let d of o){let c=d.path.split("/").length;for(let h of a){let k=It(d.path,h);if(k===0)continue;let m=k/c*d.score;m>i&&(i=m,f=k===c?d.path:d.path.split("/").slice(0,k).join("/"))}}return i<=0?{boost:1,label:""}:{boost:1+xe*Math.min(i,1),label:`, topic:${f}`}}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+xe*Math.min(l,1),label:`, topic:${r.sort().join("+")}`}}function Me(e){return e.toLowerCase().replace(/\d+/g,"")}function Ct(e){let t=e[0]?.score??0;return t<=0?e:e.filter(n=>n.strong||n.score>=t/3)}function Pt(e){let t=new Set,n=[],a=[];for(let d of e)t.has(d.sym.file)?a.push(d):(t.add(d.sym.file),n.push(d));let o=n.concat(a),l=new Set;for(let d of e)d.strong&&l.add(Me(d.sym.file));if(l.size<2)return o;let r=new Map,i=[],f=[];for(let d of o){let c=Me(d.sym.file),h=r.get(c)??0;h<ft?(r.set(c,h+1),i.push(d)):f.push(d)}return i.concat(f)}function Lt(e,t,n){let a=m=>[...new Set(m)].slice(0,8).join(", "),l=ee(e).length>0?ie(e):e,r=[],i=new Map;for(let m of j(q(l))){let b=i.get(m.from)??[];b.push(m.term),i.set(m.from,b)}for(let[m,b]of i)r.push(`- "${m}" in the ask implies these codebase identifiers: ${a(b)}.`);let f=t?.taxonomy??[];if(f.length){let m=new Set,b=[];for(let y of f)for(let A of y.levels)m.has(A.path)||(m.add(A.path),b.push({path:A.path,id:A.id,depth:A.path.split("/").length,terms:A.terms}));let p=Math.max(...b.map(y=>y.depth)),_=(y,A)=>y.terms.length?`${A} ${y.id}; code for it typically uses: ${a(y.terms)}.`:`${A} ${y.id}.`;for(let y of b.filter(A=>A.depth===p))r.push(_(y,"- The ask is specifically about"));let N=new Set(b.filter(y=>y.depth===p).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=p-1;y>=1;y--)for(let A of b.filter(L=>L.depth===y&&!S.has(L.id)))r.push(_(A,"- More broadly, this is"))}else if(t?.topics?.length){let m=new Map;for(let b of t.expansions??[]){let p=m.get(b.from)??[];p.push(b.term),m.set(b.from,p)}for(let b of t.topics.slice(0,3)){let p=m.get(b.id);r.push(p?.length?`- The ask is about the "${b.id}" domain; code for it typically uses: ${a(p)}.`:`- The ask is about the "${b.id}" domain.`)}}let d=t?.standards??[];if(d.length){let m=d.filter(_=>_.kind!=="regulation"),b=d.filter(_=>_.kind==="regulation"),p=_=>_.slice(0,3).map(N=>N.publisher?`${N.name} (${N.publisher})`:N.name).join("; ");m.length&&r.push(`- Standards that govern this area: ${p(m)}.`),b.length&&r.push(`- Regulations that apply here: ${p(b)}.`)}let c=t?.categories??[];c.length&&r.push(`- Related categories: ${a(c)}.`);let h=t?.files??[];h.length&&r.push(`- Files for this kind of work are usually named or extended: ${a(h)}.`);for(let m of(t?.corrections??[]).slice(0,3))r.push(`- Read "${m.from}" in the ask as "${m.to}".`);let k=Oe(n);if(k){let m=new Set(Y(l)),b=K(q(k)),p=Y(k).filter(_=>!m.has(_)&&!H.has(_)&&!b.has(_));p.length&&r.push(`- This is a follow-up; topic words carried from the previous ask: ${a(p)}.`)}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),f=i.length>0?ie(n):n,d=Oe(o.priorQuestion),c=Mt(f,r,d,wt(n,i));At(a,c);let h=Lt(n,r,o.priorQuestion??null);if(!c.hasContent)return{version:t(),hasContent:!1,seeds:[],conceptMap:h};let k=Nt(a,c.terms.map(S=>S.term)),m=!bt(n,c.terms),b=[];for(let S of a){let{score:y,why:A,strong:L}=Ot(S,c.terms,k);if(y>0){let P=$t(S.id,r,o.topicTags),O=m&&mt(S.file)?gt:1;b.push({sym:S,score:Ae(y*O*P.boost*(1+ct*S.importance)),why:A+P.label,strong:L})}}let p=ut(b),_=0;for(let S of p.values())S>_&&(_=S);if(_>0)for(let S of b){let y=S.sym.file.slice(0,S.sym.file.lastIndexOf("/")+1),A=(p.get(y)??0)/_;S.score=Ae(S.score*(1+lt*A))}b.sort((S,y)=>y.score-S.score||(S.sym.qualifiedName<y.sym.qualifiedName?-1:1));let N=Pt(Ct(b)).slice(0,l).map(S=>({id:S.sym.id,score:S.score,why:S.why}));return{version:t(),hasContent:!0,seeds:N,conceptMap:h}}}}var Dt=!1,Ie=`vg-relevance@1.4.0+pack.${re.version}`,Wt=20,zt=8,Ft=4,Ht=.34,jt=.8,Kt=.6,Ut=.5,Vt=.45,je=new Set(["the","and","for","with","first","new","web","app","development"]),Gt=2e3,Yt=1200,Ke=550,le=2e3,qt=1200,Xt=800,Bt=1e3,Zt=600,$e=1e3,Ce=3e3,Qt=1e3,ue=e=>Math.round(Math.min(e,Ce)/Ce*1e3)/1e3,Ue=6,Jt=6,en=6,tn=10,nn=6,sn=6,rn=8,fe=4,M=re;function on(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=2)}function an(e){return e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=1)}var cn=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&&!je.has(t))}var ln=40,Pe=128,Ve=Uint8Array.from(Buffer.from(M.vectors?.data??"","base64")),de=new Map((M.vectors?.terms??[]).map((e,t)=>[e,t])),un=new Set(M.vectors?.skip??[]);function fn(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 dn(e,t){let n=Ve[e*(M.vectors?.dim??0)+t]??0;return n>127?n-256:n}var T=M.taxonomy??[],z=M.taxonomyTerms??{},Le=M.vendorNode??{},ge=M.fuzzyKeys??[],gn=M.fileHints??{},pn=M.standards??{};function mn(e){let t=[];for(let n=e;n>=0;n=T[n].parent){let a=T[n].path;for(let o of pn[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 De(e){let t=[];for(let n=e;n>=0;n=T[n].parent){for(let a of gn[T[n].path]??[])t.includes(a)||t.push(a);if(T[n].parent<0)break}return t.slice(0,sn)}var hn=ge.map(e=>({mask:Ge(e.key),grams:Ye(e.key),len:e.key.length})),pe=new Set(M.weakTerms??[]),te=new Set(M.englishGuard??[]),We=e=>e.includes(" ")?Gt:pe.has(e)?Ke:Yt,me=T.map(()=>[]);for(let[e,t]of T.entries())t.parent>=0&&me[t.parent].push(e);var ze=new Map(T.map((e,t)=>[e.path,t]));function Ge(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 bn(e){let t=0;for(let n=e;n;n&=n-1)t++;return t}function Ye(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 yn(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 vn(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 f=new Array(o+1);f[0]=i;let d=f[0];for(let c=1;c<=o;c++){let h=e[i-1]===t[c-1]?0:1,k=Math.min(f[c-1]+1,r[c]+1,r[c-1]+h);i>1&&c>1&&e[i-1]===t[c-2]&&e[i-2]===t[c-1]&&(k=Math.min(k,l[c-2]+1)),f[c]=k,k<d&&(d=k)}if(d>n)return n+1;l=r,r=f}return r[o]}var Fe=new Set(["s","es","ed","d","ing","ly","er","ers","ings"]);function wn(e){return e<Ue?0:e>=9?2:1}function kn(e,t=2){let n=Math.min(wn(e.length),t);if(n===0||de.has(e)||te.has(e))return null;let a=Ye(e),o=e.length>=6?2:1,l=null,r=n+1,i=!1,f=Ge(e);for(let c=0;c<ge.length;c++){let h=hn[c];if(Math.abs(h.len-e.length)>n||bn(f^h.mask)>n*2)continue;let k=ge[c];if(yn(a,h.grams)<o)continue;let m=vn(e,k.key,n);m>n||(m<r?(r=m,l=k,i=!1):m===r&&l&&k.ref!==l.ref&&(i=!0))}if(!l||i||r>=2&&e[0]!==l.key[0])return null;let d=e.startsWith(l.key)?e.slice(l.key.length):"";if(d&&/^(id|ids|[0-9]+)$/.test(d))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 qe=new Map;for(let[e,t]of Object.entries(M.topicPathHints??{}))for(let n of t)qe.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 Sn(){let e=ke();if(!e&&!Dt)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??""))}:Rn(),n=ce(a=>t.analyzeQuery(a),()=>t.version());return{...t,rankSymbols:n.rankSymbols}}function Rn(){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||pe.has(o)||te.has(o))continue;for(let i of z[o]??[])n.add(T[i].path);let l=Le[o];l&&n.add(l);let r=qe.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=on(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 u=M.acronyms[s];u&&o.push({acronym:s,full:u})}for(let s of o)for(let u of X(s.full))n.add(u);let l=an(e),r=` ${[...l,...o.map(s=>s.full)].join(" ")} `,i=(s,u)=>{let w=` ${u} `;for(let g=s.indexOf(w);g!==-1;g=s.indexOf(w,g+1)){let v=s.slice(0,g),x=v.lastIndexOf(" ");if(x!==-1&&cn.has(v.slice(x+1)))return!0}return!1},f=(s,u)=>u.charCodeAt(0)===97&&u.charCodeAt(1)===32?i(s,u):s.includes(` ${u} `),d=s=>s.includes(" ")?f(r,s):n.has(s),c=s=>s.length>3&&s.endsWith("s")&&!s.endsWith("ss")?s.slice(0,-1):s,h=t.map(c),k=` ${l.map(c).join(" ")} `,m=new Set(h);for(let s=0;s<h.length-1;s++)m.add(`${h[s]} ${h[s+1]}`);let b=s=>d(s)||(s.includes(" ")?f(k,s):m.has(s)),p=[],_=new Map,N=(s,u)=>_.set(s,(_.get(s)??0)+u),S=new Map,y=new Map,A=new Map,L=[],P=(s,u,w)=>{S.set(s,(S.get(s)??0)+u);let g=y.get(s)??[];g.includes(w)||g.push(w),y.set(s,g)},O=(s,u,w)=>{let g=M.vendors[s];if(!g)return;let v=A.get(s),x=ue(w);if(v&&v.score>=x)return;let E=Le[s],R=E!==void 0?ze.get(E):void 0;if(A.set(s,{name:s,from:u,topic:g.topic,score:x,files:R!==void 0?De(R):[],...E?{node:E}:{}}),E!==void 0){let $=ze.get(E);$!==void 0&&P($,w,u===s?s:`~${u}`)}};if(T.length){for(let g of o)for(let v of z[g.acronym]??[])P(v,Bt,g.acronym);for(let[g,v]of Object.entries(z)){if(!b(g))continue;let x=We(g),E=Math.floor(x/v.length);for(let R of v)P(R,E,g)}for(let g of n)M.vendors[g]&&O(g,g,le);let s=[];for(let g of t)!M.vendors[g]&&!z[g]&&s.push({token:g,from:g,maxDistance:2});for(let g=0;g<t.length-1;g++){let v=t[g],x=t[g+1],E=`${v}${x}`;if(M.vendors[E]){O(E,`${v} ${x}`,le);continue}if(z[E])continue;let R=[v,x].filter($=>!te.has($));v.length>=3&&x.length>=3&&R.some($=>$.length>=4)&&s.push({token:E,from:`${v} ${x}`,maxDistance:1})}let u=new Set,w=new Map;for(let{token:g,from:v,maxDistance:x}of s){if(g.length<Ue||u.has(g)||(u.add(g),M.vendors[g]||z[g]))continue;let E=kn(g,x);if(!E||E.distance===0)continue;let R=E.distance===1?qt:Xt;if(L.push({from:v,to:E.key.ref,distance:E.distance}),w.set(g,E.key.ref),E.key.kind==="vendor")O(E.key.ref,v,R);else if(E.key.kind==="term"){let $=z[E.key.ref]??[];for(let we of $)P(we,Math.floor(R/$.length),`~${v}`)}}if(w.size){let g=t.map(R=>w.get(R)??R);for(let R=0;R<g.length-1;R++){let $=w.get(`${t[R]}${t[R+1]}`);$&&(g[R]=$,g[R+1]="")}let v=g.filter(Boolean),x=` ${v.join(" ")} `,E=new Set(v);for(let R=0;R<v.length-1;R++)E.add(`${v[R]} ${v[R+1]}`);for(let[R,$]of Object.entries(z)){if(!(R.includes(" ")?x.includes(` ${R} `):E.has(R))||(R.includes(" ")?r.includes(` ${R} `):n.has(R)))continue;let Be=Math.floor(We(R)*Jt/10),Ze=Math.floor(Be/$.length);for(let Qe of $)P(Qe,Ze,`~${R}`)}}for(let[g,v]of S){let x=T[g]?.topic;x&&N(x,v)}}for(let s of o)for(let u of X(s.full))p.push({term:u,from:s.acronym,weight:jt});for(let s of n){let u=M.vendors[s];if(u){N(u.topic,le);for(let w of u.terms)for(let g of X(w))p.push({term:g,from:s,weight:Kt})}}for(let[s,u]of Object.entries(M.topics))for(let w of u.terms){if(!d(w))continue;let g=!w.includes(" ")&&(pe.has(w)||te.has(w));N(s,g?Ke:Qt)}if(M.vectors&&Ve.length){let s=new Map;for(let u of t){if(u.length<3||je.has(u)||un.has(u))continue;let w=fn(u);if(w)for(let g=0;g<M.vectors.dim;g++){let v=dn(w.row,g);v>=ln&&s.set(g,(s.get(g)??0)+v)}}for(let[u,w]of s){let g=M.vectors.topics[u];N(g,Math.round(Math.min(w,Pe)*Zt/Pe))}}for(let s of n){let u=M.synonyms[s];if(u)for(let w of u)for(let g of X(w))p.push({term:g,from:s,weight:Ut})}let C=[..._.entries()].filter(([,s])=>s>=$e),F=Math.max(0,...C.map(([,s])=>s)),D=F>0?C.map(([s,u])=>({id:s,score:Math.round(u/F*1e3)/1e3})).filter(s=>s.score>=Ht).sort((s,u)=>u.score-s.score||(s.id<u.id?-1:1)).slice(0,Ft):[];for(let s of D){let u=0;for(let w of M.topics[s.id]?.terms??[])for(let g of X(w))a.has(g)||u>=zt||(p.push({term:g,from:s.id,weight:Math.round(Vt*s.score*1e3)/1e3}),u+=1)}let I=new Map;for(let s of p){if(a.has(s.term))continue;let u=I.get(s.term);(!u||s.weight>u.weight)&&I.set(s.term,s)}let B=[...I.values()].sort((s,u)=>u.weight-s.weight||(s.term<u.term?-1:1)).slice(0,Wt),U=new Array(T.length).fill(0);for(let[s,u]of S){let w=s;for(;w!==void 0&&w>=0;){U[w]+=u;let g=T[w].parent;w=g>=0?g:void 0}}let be=s=>U[s]>=$e,ye=[];for(let s=0;s<T.length;s++)be(s)&&(me[s].some(u=>be(u))||ye.push(s));let ne=ye.map(s=>{let u=[];for(let v=s;v>=0&&(u.unshift(v),!(T[v].parent<0));v=T[v].parent);let w=new Set,g=v=>{for(let x of y.get(v)??[])w.add(x);for(let x of me[v]??[])g(x)};for(let v of u)for(let x of y.get(v)??[])w.add(x);return g(s),{path:T[s].path,levels:u.map(v=>({id:T[v].path.split("/").pop(),path:T[v].path,score:ue(U[v]),terms:(T[v].terms??[]).slice(0,nn)})),score:ue(U[s]),evidence:Math.round(U[s])/1e3,via:[...w].sort(),terms:(T[s].terms??[]).slice(0,tn),files:De(s),standards:mn(s)}}).sort((s,u)=>u.evidence-s.evidence||(s.path<u.path?-1:1)).slice(0,en),ve=[...A.values()].sort((s,u)=>u.score-s.score||(s.name<u.name?-1:1)),Xe=[...new Map(L.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 ne)for(let u of s.files)V.includes(u)||V.push(u);let Z=[];for(let s of ne)for(let u of s.standards)Z.some(w=>w.name===u.name)||Z.push(u);let se=[];for(let s of Z.slice(0,fe))for(let u of s.categories)se.includes(u)||se.push(u);return{version:Ie,topics:D,expansions:B,taxonomy:ne,vendors:ve,corrections:Xe,files:V.slice(0,rn),standards:Z.slice(0,fe),categories:se}}}}export{Sn as createRelevanceProvider,ce as createSymbolRanker};
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibgrate/relevance",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.826.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",
|
|
@@ -20,12 +20,16 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "node build.mjs",
|
|
22
22
|
"typecheck": "tsc --noEmit -p ./",
|
|
23
|
-
"test": "vitest run"
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"bench:ask": "tsx bench/ask-quality.bench.ts",
|
|
25
|
+
"bench:code-relevance": "tsx bench/code-relevance.bench.ts",
|
|
26
|
+
"bench:repos": "tsx bench/repo-harness/run.mjs"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"@types/node": "^26.2.0",
|
|
27
30
|
"esbuild": "^0.25.12",
|
|
28
31
|
"tsup": "^8.0.0",
|
|
32
|
+
"tsx": "^4.23.12",
|
|
29
33
|
"typescript": "^5.4.0",
|
|
30
34
|
"vitest": "^4.1.10"
|
|
31
35
|
},
|