wiki-plugin-similarity 0.3.1 → 0.4.0
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/client/similarity.js +40 -26
- package/client/similarity.js.map +3 -3
- package/package.json +1 -1
- package/pages/about-similarity-plugin +18 -8
- package/server/server.js +39 -5
package/client/similarity.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* wiki-plugin-similarity - 0.
|
|
2
|
-
(()=>{var A={high:.78,medium:.68,low:.58},
|
|
3
|
-
`)){let
|
|
1
|
+
/* wiki-plugin-similarity - 0.4.0 - Wed, 10 Jun 2026 23:23:44 GMT */
|
|
2
|
+
(()=>{var A={high:.78,medium:.68,low:.58},I=A.medium,z=10,F=t=>{let e=[],i=null,s=null,o="search",x=!1,b=!1,L=null,y=null,d=(m,w)=>m===w||m.startsWith(w)&&/^[\s:]/.test(m.slice(w.length)),n=(m,w)=>m.slice(w.length).replace(/^\s*:?\s*/,"").trim();for(let m of t.split(`
|
|
3
|
+
`)){let w=m.trim();if(!w||w.startsWith("#"))continue;let p=w.toUpperCase();if(d(p,"LIVE")){x=!0;continue}if(d(p,"AUTHOR")){!e.length&&o==="search"&&(o="author");continue}if(d(p,"REPORT")){o==="search"&&(o="report");continue}if(d(p,"BUILD")){o==="search"&&(o="build");continue}if(d(p,"FORCE")){b=!0;continue}if(d(p,"GHOST")){L=n(w,"GHOST"),o==="search"&&(o="ghost");continue}if(d(p,"BUTTON")){y=n(w,"BUTTON");continue}if(d(p,"LIST")){!e.length&&o==="search"&&(o="list");continue}if(d(p,"SIMILAR")){let r=n(p,"SIMILAR").toLowerCase();i=A[r]||I,!e.length&&o==="search"&&(o="similar");continue}if(d(p,"THRESHOLD")){let r=n(w,"THRESHOLD");i=A[r.toLowerCase()]??(parseFloat(r)||I);continue}if(d(p,"LIMIT")){s=parseInt(n(w,"LIMIT"))||z;continue}e.push(["PUBLIC","LOCAL","PRIVATE"].includes(p)?p:w)}return{mode:o,specs:e,threshold:i??I,limit:s??z,live:x,force:b,ghostUrl:L,label:y}},J=t=>t.includes("*")||t.includes("?"),W=t=>t==="PUBLIC"||t==="LOCAL"||t==="PRIVATE",K=t=>t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),D=new Map,Y=async(t,e)=>{if(D.has(t))return D.get(t);let i=`${e}/system/indexed-domains.json?pattern=${encodeURIComponent(t)}`,s=await fetch(i);if(!s.ok)throw new Error(`indexed-domains failed: ${s.status}`);let o=await s.json();return D.set(t,o),o},Q=async(t,e)=>{t.length||(t=[window.location.hostname]);let i=new Set,s=[];for(let o of t)if(o==="*"||J(o)||W(o))for(let x of await Y(o,e))i.has(x.domain)||(i.add(x.domain),s.push(x));else i.has(o)||(i.add(o),s.push({domain:o,page_count:null}));return s},O=new Map,X=()=>{let t=window.location.hostname;return t==="localhost"||t.endsWith(".localhost")||t==="127.0.0.1"},Z=t=>X()?`${window.location.origin}/system/semantic-vectors.json?domain=${encodeURIComponent(t)}`:`${window.location.protocol}//${t}/system/semantic-vectors.json`,q=async t=>{if(O.has(t))return O.get(t);let e=await fetch(Z(t));if(!e.ok)return[];let i=await e.json();return O.set(t,i),i},M=async(t,e)=>{let i=await fetch(`${e}/system/embed.json?text=${encodeURIComponent(t)}`);if(!i.ok)throw new Error(`embed failed: ${i.status}`);return(await i.json()).vector},tt=async(t,e)=>{let s=(await q(e)).find(o=>o.slug===t);return s?s.vector:null},U=(t,e,{threshold:i,limit:s,excludeSlug:o,excludeDomain:x})=>{let b=[];for(let{domain:L,pages:y}of e)for(let{slug:d,title:n,vector:m}of y){if(d===o&&L===x)continue;let w=0;for(let p=0;p<t.length;p++)w+=t[p]*m[p];w>=i&&b.push({domain:L,slug:d,title:n,score:w})}return b.sort((L,y)=>y.score-L.score),b.slice(0,s)},H=async(t,e)=>{let i=await Q(t,e);return(await Promise.all(i.map(async({domain:o})=>({domain:o,pages:await q(o)})))).filter(o=>o.pages.length>0)},N=t=>`sim-cache-${t}`,et=t=>{try{let e=JSON.parse(localStorage.getItem(N(t.id))||"null");return e?.text===(t.text||"")?e:null}catch{return null}},R=(t,e)=>{try{localStorage.setItem(N(t.id),JSON.stringify({text:t.text||"",ts:Date.now(),...e}))}catch{}},st=t=>{let e=Math.floor((Date.now()-t)/1e3);return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:e<86400?`${Math.floor(e/3600)}h ago`:`${Math.floor(e/86400)}d ago`},T=`
|
|
4
4
|
.sim-form { display:flex; gap:6px; margin-bottom:8px; }
|
|
5
5
|
.sim-input { flex:1; padding:6px 8px; font-size:14px; border:1px solid #ccc; border-radius:3px; }
|
|
6
6
|
.sim-btn { padding:6px 14px; background:#c4561d; color:white; border:none;
|
|
@@ -24,49 +24,63 @@
|
|
|
24
24
|
.sim-list td { padding:3px 8px 3px 0; border-bottom:1px solid #f0f0f0; vertical-align:middle; }
|
|
25
25
|
.sim-list td:last-child { text-align:right; color:#999; font-size:11px; }
|
|
26
26
|
.sim-list .sim-flag { margin-right:6px; }
|
|
27
|
-
`,
|
|
27
|
+
`,nt=(t,e)=>`<img class="sim-flag remote" src="${window.wiki.site(t).flag()}"
|
|
28
28
|
title="${t} \u2014 score ${e.toFixed(3)}"
|
|
29
|
-
data-site="${t}">`,
|
|
30
|
-
<style>${
|
|
29
|
+
data-site="${t}">`,P=(t,e,i,s)=>`<a class="sim-link" data-title="${i}" data-slug="${e}" data-site="${t}" href="#">${nt(t,s)} ${i}</a>`,it=(t,e)=>{let{mode:i,specs:s,threshold:o,limit:x,force:b,ghostUrl:L,label:y}=F(e?.text||"");if(i==="ghost")t.html(`
|
|
30
|
+
<style>${T}</style>
|
|
31
31
|
<div class="similarity" data-id="${e.id}">
|
|
32
|
-
<div class="sim-
|
|
32
|
+
<div class="sim-form">
|
|
33
|
+
<button class="sim-btn">${y||"Open"}</button>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="sim-status"></div>
|
|
36
|
+
</div>`);else if(i==="build")t.html(`
|
|
37
|
+
<style>${T}</style>
|
|
38
|
+
<div class="similarity" data-id="${e.id}">
|
|
39
|
+
<div class="sim-form">
|
|
40
|
+
<button class="sim-btn">${y||`Index ${s.length?s.join(", "):"*"}${b?" (force)":""}`}</button>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="sim-status"></div>
|
|
43
|
+
</div>`);else if(i==="list"){let d=s.length?s.join(", "):"*";t.html(`
|
|
44
|
+
<style>${T}</style>
|
|
45
|
+
<div class="similarity" data-id="${e.id}">
|
|
46
|
+
<div class="sim-status">Loading indexed domains (${d})\u2026</div>
|
|
33
47
|
<div class="sim-list"></div>
|
|
34
|
-
</div>`)}else if(i==="similar"){let
|
|
35
|
-
<style>${
|
|
48
|
+
</div>`)}else if(i==="similar"){let d=s.length?s.join(", "):"current domain";t.html(`
|
|
49
|
+
<style>${T}</style>
|
|
36
50
|
<div class="similarity" data-id="${e.id}">
|
|
37
|
-
<div class="sim-status">Finding similar pages across ${
|
|
51
|
+
<div class="sim-status">Finding similar pages across ${d}\u2026</div>
|
|
38
52
|
<div class="sim-results"></div>
|
|
39
|
-
</div>`)}else if(i==="author"){let
|
|
40
|
-
<style>${
|
|
53
|
+
</div>`)}else if(i==="author"||i==="report"){let d=s.length?s.join(", "):"(current domain)",n=i==="report"?"Report":"Author";t.html(`
|
|
54
|
+
<style>${T}</style>
|
|
41
55
|
<div class="similarity" data-id="${e.id}">
|
|
42
56
|
<div class="sim-form">
|
|
43
57
|
<input class="sim-input" type="text" placeholder="Search wiki pages\u2026" />
|
|
44
|
-
<button class="sim-btn"
|
|
58
|
+
<button class="sim-btn">${n}</button>
|
|
45
59
|
</div>
|
|
46
|
-
<div class="sim-status">Domains: ${
|
|
60
|
+
<div class="sim-status">Domains: ${d}</div>
|
|
47
61
|
<div class="sim-results"></div>
|
|
48
|
-
</div>`)}else{let
|
|
49
|
-
<style>${
|
|
62
|
+
</div>`)}else{let d=s.length?s.join(", "):"(current domain)";t.html(`
|
|
63
|
+
<style>${T}</style>
|
|
50
64
|
<div class="similarity" data-id="${e.id}">
|
|
51
65
|
<div class="sim-form">
|
|
52
66
|
<input class="sim-input" type="text" placeholder="Search wiki pages\u2026" />
|
|
53
67
|
<button class="sim-btn">Search</button>
|
|
54
68
|
</div>
|
|
55
|
-
<div class="sim-status">Domains: ${
|
|
69
|
+
<div class="sim-status">Domains: ${d}</div>
|
|
56
70
|
<div class="sim-results"></div>
|
|
57
|
-
</div>`)}},
|
|
71
|
+
</div>`)}},ot=(t,e)=>{let{mode:i,specs:s,threshold:o,limit:x,live:b,force:L,ghostUrl:y}=F(e?.text||""),d=window.location.origin,n=t.find(".sim-status")[0],m=b?null:et(e);t.on("dblclick",r=>{$(r.target).closest(".sim-input").length||window.wiki.textEditor(t,e)}),t.on("click",".sim-link",function(r){r.preventDefault();let g=$(this),c=r.shiftKey?null:t.parents(".page");window.wiki.doInternalLink(g.data("title"),c,g.data("site"))});let w=!s.length||s.length===1&&s[0]==="*"?"on farm":s.length===1?`on ${s[0]}`:"in domains",p=r=>r?` \xB7 cached ${st(r)}`:"";if(i==="list"){let r=t.find(".sim-list")[0],g=s.length?s.join(","):"*",c=(l,f)=>{let a=l.reduce((u,h)=>u+(h.page_count||0),0);n.style.display="none",r.innerHTML=`<h3>Indexed Farm Domains</h3>
|
|
58
72
|
<table>
|
|
59
73
|
<tr><th>Domain</th><th>Pages</th></tr>
|
|
60
|
-
${
|
|
74
|
+
${l.map(({domain:u,page_count:h})=>`
|
|
61
75
|
<tr>
|
|
62
|
-
<td><img class="sim-flag remote" src="${window.wiki.site(
|
|
63
|
-
title="${
|
|
64
|
-
<td>${
|
|
76
|
+
<td><img class="sim-flag remote" src="${window.wiki.site(u).flag()}"
|
|
77
|
+
title="${u}" data-site="${u}"> ${u}</td>
|
|
78
|
+
<td>${h!=null?h.toLocaleString():"\u2014"}</td>
|
|
65
79
|
</tr>`).join("")}
|
|
66
80
|
</table>
|
|
67
|
-
<p class="sim-count">${
|
|
68
|
-
`);
|
|
69
|
-
`),
|
|
81
|
+
<p class="sim-count">${l.length} domains \u2014 ${a.toLocaleString()} pages${p(f)}</p>`};m?.domains?c(m.domains,m.ts):(async()=>{try{let l=`${d}/system/indexed-domains.json?pattern=${encodeURIComponent(g)}&limit=${x}`,f=await fetch(l);if(!f.ok)throw new Error(`indexed-domains failed: ${f.status}`);let a=await f.json();if(!a.length){n.textContent="No indexed domains found";return}c(a,null),R(e,{domains:a})}catch(l){n.textContent=`Error: ${l.message}`}})()}else if(i==="similar"){let r=t.find(".sim-results")[0],g=(c,l)=>{if(!c.length){n.textContent=`No similar pages found above threshold ${o}`;return}r.innerHTML=`<h3>Similar Pages</h3><ul>${c.map(({domain:f,slug:a,title:u,score:h})=>`<li>${P(f,a,u,h)}</li>`).join("")}</ul><p class="sim-count">${c.length} found ${w}${p(l)}</p>`,n.style.display="none"};m?.scored?g(m.scored,m.ts):(async()=>{try{let c=t.parents(".page"),l=c.find(".title").text().trim()||document.title,f=K(l),a=window.location.hostname,u=await H(s,d),h=u.reduce((C,k)=>C+k.pages.length,0);n.textContent=`Searching ${h.toLocaleString()} pages\u2026`;let v=await tt(f,a);if(!v){n.textContent="Embedding page (not yet indexed)\u2026";let C=c.find(".item").map((k,j)=>$(j).text().trim()).get().filter(Boolean).join(`
|
|
82
|
+
`);v=await M(C||l,d)}let E=U(v,u,{threshold:o,limit:x,excludeSlug:f,excludeDomain:a});g(E,null),E.length&&R(e,{scored:E})}catch(c){n.textContent=`Error: ${c.message}`}})()}else if(i==="ghost"){let r=t.find(".sim-btn")[0],g=async()=>{if(!y){n.textContent="No URL \u2014 GHOST needs a page-json URL";return}r.disabled=!0,n.textContent="Fetching\u2026";try{let c=await fetch(y);if(!c.ok)throw new Error(`fetch failed: ${c.status}`);let l=await c.json();window.wiki.showResult(window.wiki.newPage(l),{$page:t.parents(".page")}),n.textContent=""}catch(c){n.textContent=`Error: ${c.message}`}finally{r.disabled=!1}};r.addEventListener("click",g)}else if(i==="build"){let r=t.find(".sim-btn")[0],g=async()=>{r.disabled=!0,n.textContent="Building index\u2026 (may take a while for large scopes)";try{let c=encodeURIComponent((s.length?s:["*"]).join(",")),l=await fetch(`http://api.localhost/build-index.json?domains=${c}&force=${L?1:0}`);if(!l.ok)throw new Error(`build-index failed: ${l.status}`);let f=await l.json();window.wiki.showResult(window.wiki.newPage(f),{$page:t.parents(".page")}),n.textContent=""}catch(c){n.textContent=`Error: ${c.message}`}finally{r.disabled=!1}};r.addEventListener("click",g)}else if(i==="report"){let r=t.find(".sim-input")[0],g=t.find(".sim-btn")[0],c=async()=>{let l=r.value.trim();if(l){g.disabled=!0,n.textContent="Generating report\u2026";try{let f=await fetch("http://localhost:8000/search-report",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:l,domains:s.length?s:["*"],limit:x})});if(!f.ok)throw new Error(`search-report failed: ${f.status}`);let a=await f.json(),u=window.wiki.newPage(a);window.wiki.showResult(u,{$page:t.parents(".page")}),n.textContent=""}catch(f){n.textContent=`Error: ${f.message}`}finally{g.disabled=!1}}};g.addEventListener("click",c),r.addEventListener("keydown",l=>{l.key==="Enter"&&c()})}else if(i==="author"){let r=t.find(".sim-input")[0],g=t.find(".sim-btn")[0],c=t.find(".sim-results")[0],l=null;(async()=>{try{m||(n.textContent="Resolving domains\u2026"),l=await H(s,d);let a=l.reduce((u,h)=>u+h.pages.length,0);n.textContent=`Ready \u2014 ${a.toLocaleString()} pages across ${l.length} domains`}catch(a){n.textContent=`Load error: ${a.message}`}})();let f=async()=>{let a=r.value.trim();if(!(!a||!l)){g.disabled=!0,n.textContent="Embedding query\u2026",c.innerHTML="";try{let u=await M(a,d),h=U(u,l,{threshold:o,limit:x,excludeSlug:null,excludeDomain:null}),v=new Set,E=[];for(let{title:S}of h)v.has(S)||(v.add(S),E.push(S));let C=()=>Math.floor(Math.random()*18446744073709552e3).toString(16).padStart(16,"0"),k=E.map(S=>`- [[${S}]]`).join(`
|
|
83
|
+
`),j=[{type:"markdown",id:C(),text:`# Similar Pages
|
|
70
84
|
|
|
71
|
-
${
|
|
85
|
+
${k}`},{type:"markdown",id:C(),text:"# Reference Links"},...h.map(({domain:S,slug:V,title:G,score:_})=>({type:"reference",id:C(),site:S,slug:V,title:G,text:`score ${_.toFixed(3)}`}))],B=window.wiki.newPage({title:`${a} Results`,story:j,journal:[]});window.wiki.showResult(B,{$page:t.parents(".page")}),n.textContent=`${h.length} pages found`,R(e,{scored:h,query:a})}catch(u){n.textContent=`Error: ${u.message}`}finally{g.disabled=!1}}};g.addEventListener("click",f),r.addEventListener("keydown",a=>{a.key==="Enter"&&f()})}else{let r=t.find(".sim-input")[0],g=t.find(".sim-btn")[0],c=t.find(".sim-results")[0],l=null;m?.scored&&(r.value=m.query||"",c.innerHTML=m.scored.map(({domain:a,slug:u,title:h,score:v})=>`<div class="sim-result">${P(a,u,h,v)}</div>`).join("")+`<p class="sim-count">Top ${m.scored.length} for "${m.query||""}"${p(m.ts)}</p>`,n.textContent=""),(async()=>{try{m||(n.textContent="Resolving domains\u2026"),l=await H(s,d);let a=l.reduce((u,h)=>u+h.pages.length,0);n.textContent=`Ready \u2014 ${a.toLocaleString()} pages across ${l.length} domains`}catch(a){n.textContent=`Load error: ${a.message}`}})();let f=async()=>{let a=r.value.trim();if(!(!a||!l)){g.disabled=!0,n.textContent="Embedding query\u2026",c.innerHTML="";try{let u=await M(a,d),h=U(u,l,{threshold:o,limit:x,excludeSlug:null,excludeDomain:null});c.innerHTML=h.map(({domain:v,slug:E,title:C,score:k})=>`<div class="sim-result">${P(v,E,C,k)}</div>`).join("")+`<p class="sim-count">Top ${h.length} for "${a}"</p>`,n.textContent="",R(e,{scored:h,query:a})}catch(u){n.textContent=`Error: ${u.message}`}finally{g.disabled=!1}}};g.addEventListener("click",f),r.addEventListener("keydown",a=>{a.key==="Enter"&&f()})}};typeof window<"u"&&(window.plugins=window.plugins||{},window.plugins.similarity={emit:it,bind:ot});})();
|
|
72
86
|
//# sourceMappingURL=similarity.js.map
|
package/client/similarity.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/client/similarity.js"],
|
|
4
|
-
"sourcesContent": ["// wiki-plugin-similarity\n//\n// One item type: similarity\n//\n// DSL in item.text (newline-separated lines):\n// * all indexed domains on this server\n// david.* glob pattern\n// *.fish glob pattern\n// david.hitchhikers.earth explicit domain name\n// # comment ignored\n// LIST list indexed domains (mode directive)\n// SIMILAR: high threshold preset AND ambient mode trigger\n// THRESHOLD: 0.72 exact cosine threshold (overrides SIMILAR:)\n// LIMIT: 8 max results shown (default 10)\n//\n// Mode is determined by the FIRST meaningful line (Ward's ALL-CAPS convention):\n// LIST \u2192 show a table of all indexed domains and their page counts;\n// optional glob patterns on subsequent lines filter the list\n// SIMILAR: \u2192 ambient mode \u2014 automatically find pages similar to this page\n// (other) \u2192 search form mode \u2014 user types a query, results appear\n//\n// Server endpoints required:\n// GET /system/indexed-domains.json?pattern=glob1,glob2\n// GET /system/semantic-vectors.json?domain=\n// GET /system/embed.json?text=query\n\n// \u2500\u2500 DSL Parser \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst SIMILAR_THRESHOLDS = { high: 0.78, medium: 0.68, low: 0.58 }\nconst DEFAULT_THRESHOLD = SIMILAR_THRESHOLDS.medium\nconst DEFAULT_LIMIT = 10\n\n// parseDSL returns { mode, specs, threshold, limit }\n//\n// mode: 'similar' if SIMILAR: is the first meaningful line (ambient auto-run),\n// 'search' otherwise (interactive search form).\n//\n// Ward's convention: ALL-CAPS keyword as first word signals a mode switch.\n// Placing SIMILAR: first makes the item ambient; placing domain specs first\n// (or leaving text empty) keeps it as an interactive search form.\n\nconst parseDSL = text => {\n const specs = []\n let threshold = null\n let limit = null\n let mode = 'search' // default: interactive search form\n let live = false // default: cache results in localStorage\n\n // Match a keyword at the start of a line (case-insensitive), requiring it to\n // be followed by end-of-string, whitespace, or colon \u2014 not by more word chars.\n // This prevents domain specs like \"similarity.example.com\" matching SIMILAR.\n const isCmd = (upper, kw) => upper === kw || (upper.startsWith(kw) && /^[\\s:]/.test(upper.slice(kw.length)))\n // Extract the value after the keyword, tolerating optional colon and whitespace.\n // Returns '' for bare commands (e.g. \"SIMILAR\" alone), callers use their default.\n const val = (line, kw) => line.slice(kw.length).replace(/^\\s*:?\\s*/, '').trim()\n\n for (const raw of text.split('\\n')) {\n const line = raw.trim()\n if (!line || line.startsWith('#')) continue\n\n const upper = line.toUpperCase()\n if (isCmd(upper, 'LIVE')) { live = true; continue }\n if (isCmd(upper, 'AUTHOR')) {\n if (!specs.length && mode === 'search') mode = 'author'\n continue\n }\n if (isCmd(upper, 'LIST')) {\n if (!specs.length && mode === 'search') mode = 'list'\n continue\n }\n if (isCmd(upper, 'SIMILAR')) {\n const level = val(upper, 'SIMILAR').toLowerCase()\n threshold = SIMILAR_THRESHOLDS[level] || DEFAULT_THRESHOLD // '' \u2192 medium\n if (!specs.length && mode === 'search') mode = 'similar'\n continue\n }\n if (isCmd(upper, 'THRESHOLD')) {\n threshold = parseFloat(val(line, 'THRESHOLD')) || DEFAULT_THRESHOLD // '' \u2192 medium\n continue\n }\n if (isCmd(upper, 'LIMIT')) {\n limit = parseInt(val(line, 'LIMIT')) || DEFAULT_LIMIT // '' \u2192 10\n continue\n }\n // Anything else is a domain spec (glob or explicit domain)\n specs.push(line)\n }\n\n return {\n mode,\n specs,\n threshold: threshold ?? DEFAULT_THRESHOLD,\n limit: limit ?? DEFAULT_LIMIT,\n live,\n }\n}\n\nconst isGlob = spec => spec.includes('*') || spec.includes('?')\n\n// \u2500\u2500 Slug \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst slugify = title => title.toLowerCase().replace(/\\s+/g, '-').replace(/[^a-z0-9-]/g, '')\n\n// \u2500\u2500 Domain resolution \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst domainCache = new Map()\n\nconst resolveDomainsForSpec = async (spec, origin) => {\n if (domainCache.has(spec)) return domainCache.get(spec)\n const url = `${origin}/system/indexed-domains.json?pattern=${encodeURIComponent(spec)}`\n const res = await fetch(url)\n if (!res.ok) throw new Error(`indexed-domains failed: ${res.status}`)\n const list = await res.json()\n domainCache.set(spec, list)\n return list\n}\n\nconst resolveDomains = async (specs, origin) => {\n if (!specs.length) specs = [window.location.hostname]\n const seen = new Set()\n const result = []\n for (const spec of specs) {\n if (spec === '*' || isGlob(spec)) {\n for (const item of await resolveDomainsForSpec(spec, origin)) {\n if (!seen.has(item.domain)) { seen.add(item.domain); result.push(item) }\n }\n } else if (!seen.has(spec)) {\n seen.add(spec); result.push({ domain: spec, page_count: null })\n }\n }\n return result\n}\n\n// \u2500\u2500 Vector loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst vectorCache = new Map()\n\n// Detect whether the wiki is running on localhost (or a .localhost subdomain).\n// On localhost we proxy all domain vector fetches through the local server's\n// ?domain= parameter \u2014 this reads vectors directly from the farm folder on disk,\n// avoiding any need for remote servers to have this plugin installed, and\n// sidestepping CORS entirely.\nconst isLocalhost = () => {\n const h = window.location.hostname\n return h === 'localhost' || h.endsWith('.localhost') || h === '127.0.0.1'\n}\n\nconst vectorUrl = domain => {\n if (isLocalhost()) {\n // Route through our local server \u2014 serves any farm domain from disk\n return `${window.location.origin}/system/semantic-vectors.json?domain=${encodeURIComponent(domain)}`\n }\n // On a real server, fetch directly from the remote wiki \u2014 use same protocol\n // as the current page to avoid mixed-content blocks on HTTPS sites\n return `${window.location.protocol}//${domain}/system/semantic-vectors.json`\n}\n\nconst loadVectors = async domain => {\n if (vectorCache.has(domain)) return vectorCache.get(domain)\n const res = await fetch(vectorUrl(domain))\n if (!res.ok) return []\n const data = await res.json()\n vectorCache.set(domain, data)\n return data\n}\n\n// \u2500\u2500 Embedding \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst getEmbedding = async (text, origin) => {\n const res = await fetch(`${origin}/system/embed.json?text=${encodeURIComponent(text)}`)\n if (!res.ok) throw new Error(`embed failed: ${res.status}`)\n return (await res.json()).vector\n}\n\n// Look up an existing page vector from the current domain's cached index.\n// Returns the float[] vector if found, null otherwise.\nconst lookupPageVector = async (slug, domain) => {\n const pages = await loadVectors(domain)\n const entry = pages.find(p => p.slug === slug)\n return entry ? entry.vector : null\n}\n\n// \u2500\u2500 Cosine search \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cosineScan = (queryVec, domainEntries, { threshold, limit, excludeSlug, excludeDomain }) => {\n const results = []\n for (const { domain, pages } of domainEntries) {\n for (const { slug, title, vector } of pages) {\n if (slug === excludeSlug && domain === excludeDomain) continue\n let dot = 0\n for (let i = 0; i < queryVec.length; i++) dot += queryVec[i] * vector[i]\n if (dot >= threshold) results.push({ domain, slug, title, score: dot })\n }\n }\n results.sort((a, b) => b.score - a.score)\n return results.slice(0, limit)\n}\n\n// \u2500\u2500 Shared domain loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst loadDomainEntries = async (specs, origin) => {\n const domains = await resolveDomains(specs, origin)\n const entries = await Promise.all(\n domains.map(async ({ domain }) => ({ domain, pages: await loadVectors(domain) }))\n )\n return entries.filter(e => e.pages.length > 0)\n}\n\n// \u2500\u2500 Result cache (localStorage) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Cache is keyed by item id. Invalidated when item.text changes (DSL edited).\n// LIVE mode bypasses the cache entirely.\n\nconst cacheKey = id => `sim-cache-${id}`\n\nconst readCache = item => {\n try {\n const c = JSON.parse(localStorage.getItem(cacheKey(item.id)) || 'null')\n return c?.text === (item.text || '') ? c : null\n } catch { return null }\n}\n\nconst writeCache = (item, data) => {\n try {\n localStorage.setItem(cacheKey(item.id), JSON.stringify({\n text: item.text || '',\n ts: Date.now(),\n ...data,\n }))\n } catch { /* storage unavailable or full */ }\n}\n\nconst cacheAge = ts => {\n const s = Math.floor((Date.now() - ts) / 1000)\n if (s < 60) return `${s}s ago`\n if (s < 3600) return `${Math.floor(s / 60)}m ago`\n if (s < 86400) return `${Math.floor(s / 3600)}h ago`\n return `${Math.floor(s / 86400)}d ago`\n}\n\n// \u2500\u2500 Styles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst STYLES = `\n .sim-form { display:flex; gap:6px; margin-bottom:8px; }\n .sim-input { flex:1; padding:6px 8px; font-size:14px; border:1px solid #ccc; border-radius:3px; }\n .sim-btn { padding:6px 14px; background:#c4561d; color:white; border:none;\n border-radius:3px; cursor:pointer; font-size:14px; }\n .sim-btn:disabled { opacity:0.5; cursor:not-allowed; }\n .sim-status { font-size:12px; color:#888; margin-bottom:6px; min-height:16px; }\n .sim-results { margin-top:4px; }\n .sim-result { display:flex; align-items:center; gap:8px; padding:3px 0;\n border-bottom:1px solid #f0f0f0; }\n .sim-flag { width:16px; height:16px; vertical-align:middle; margin-right:4px; }\n .sim-link { font-size:14px; color:#406; flex:1; }\n .sim-domain { font-size:11px; color:#999; }\n .similar-results h3, .sim-list h3 { margin:4px 0 6px; font-size:14px; color:#555; }\n .similar-results ul { margin:0; padding-left:18px; }\n .similar-results li { font-size:14px; padding:2px 0; }\n .similar-results .sim-domain { margin-left:6px; }\n .sim-count { font-size:12px; color:#888; margin:4px 0 0; }\n .sim-list table { border-collapse:collapse; width:100%; font-size:13px; }\n .sim-list th { text-align:left; font-size:11px; color:#888; padding:2px 8px 4px 0;\n border-bottom:1px solid #ddd; }\n .sim-list td { padding:3px 8px 3px 0; border-bottom:1px solid #f0f0f0; vertical-align:middle; }\n .sim-list td:last-child { text-align:right; color:#999; font-size:11px; }\n .sim-list .sim-flag { margin-right:6px; }\n`\n\nconst siteFlag = (domain, score) =>\n `<img class=\"sim-flag remote\" src=\"${window.wiki.site(domain).flag()}\"\n title=\"${domain} \u2014 score ${score.toFixed(3)}\"\n data-site=\"${domain}\">`\n\n// \u2500\u2500 similarity item \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst simLink = (domain, slug, title, score) =>\n `<a class=\"sim-link\" data-title=\"${title}\" data-slug=\"${slug}\" data-site=\"${domain}\" href=\"#\">` +\n `${siteFlag(domain, score)} ${title}</a>`\n\nexport const emit = (div, item) => {\n const { mode, specs, threshold, limit } = parseDSL(item?.text || '')\n if (mode === 'list') {\n const label = specs.length ? specs.join(', ') : '*'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-status\">Loading indexed domains (${label})\u2026</div>\n <div class=\"sim-list\"></div>\n </div>`)\n } else if (mode === 'similar') {\n const label = specs.length ? specs.join(', ') : 'current domain'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-status\">Finding similar pages across ${label}\u2026</div>\n <div class=\"sim-results\"></div>\n </div>`)\n } else if (mode === 'author') {\n const label = specs.length ? specs.join(', ') : '(current domain)'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <input class=\"sim-input\" type=\"text\" placeholder=\"Search wiki pages\u2026\" />\n <button class=\"sim-btn\">Author</button>\n </div>\n <div class=\"sim-status\">Domains: ${label}</div>\n <div class=\"sim-results\"></div>\n </div>`)\n } else {\n const label = specs.length ? specs.join(', ') : '(current domain)'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <input class=\"sim-input\" type=\"text\" placeholder=\"Search wiki pages\u2026\" />\n <button class=\"sim-btn\">Search</button>\n </div>\n <div class=\"sim-status\">Domains: ${label}</div>\n <div class=\"sim-results\"></div>\n </div>`)\n }\n}\n\nexport const bind = (div, item) => {\n const { mode, specs, threshold, limit, live } = parseDSL(item?.text || '')\n const origin = window.location.origin\n const status = div.find('.sim-status')[0]\n const cache = live ? null : readCache(item)\n\n div.on('dblclick', () => window.wiki.textEditor(div, item))\n div.on('click', '.sim-link', function (e) {\n e.preventDefault()\n const $a = $(this)\n window.wiki.doInternalLink($a.data('title'), div.parents('.page'), $a.data('site'))\n })\n\n const scopeLabel = !specs.length || (specs.length === 1 && specs[0] === '*')\n ? 'on farm'\n : specs.length === 1 ? `on ${specs[0]}` : 'in domains'\n\n const cacheNote = ts => ts ? ` \u00B7 cached ${cacheAge(ts)}` : ''\n\n if (mode === 'list') {\n const listDiv = div.find('.sim-list')[0]\n const patterns = specs.length ? specs.join(',') : '*'\n\n const renderList = (domains, ts) => {\n const totalPages = domains.reduce((n, d) => n + (d.page_count || 0), 0)\n status.style.display = 'none'\n listDiv.innerHTML = `<h3>Indexed Farm Domains</h3>\n <table>\n <tr><th>Domain</th><th>Pages</th></tr>\n ${domains.map(({ domain, page_count }) => `\n <tr>\n <td><img class=\"sim-flag remote\" src=\"${window.wiki.site(domain).flag()}\"\n title=\"${domain}\" data-site=\"${domain}\"> ${domain}</td>\n <td>${page_count != null ? page_count.toLocaleString() : '\u2014'}</td>\n </tr>`).join('')}\n </table>\n <p class=\"sim-count\">${domains.length} domains \u2014 ${totalPages.toLocaleString()} pages${cacheNote(ts)}</p>`\n }\n\n if (cache?.domains) {\n renderList(cache.domains, cache.ts)\n } else {\n ;(async () => {\n try {\n const url = `${origin}/system/indexed-domains.json?pattern=${encodeURIComponent(patterns)}&limit=${limit}`\n const res = await fetch(url)\n if (!res.ok) throw new Error(`indexed-domains failed: ${res.status}`)\n const domains = await res.json()\n if (!domains.length) { status.textContent = 'No indexed domains found'; return }\n renderList(domains, null)\n writeCache(item, { domains })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n }\n })()\n }\n\n } else if (mode === 'similar') {\n const results = div.find('.sim-results')[0]\n\n const renderScored = (scored, ts) => {\n if (!scored.length) {\n status.textContent = `No similar pages found above threshold ${threshold}`\n return\n }\n results.innerHTML = `<h3>Similar Pages</h3><ul>${\n scored.map(({ domain, slug, title, score }) =>\n `<li>${simLink(domain, slug, title, score)}</li>`).join('')\n }</ul><p class=\"sim-count\">${scored.length} found ${scopeLabel}${cacheNote(ts)}</p>`\n status.style.display = 'none'\n }\n\n if (cache?.scored) {\n renderScored(cache.scored, cache.ts)\n } else {\n ;(async () => {\n try {\n const $page = div.parents('.page')\n const pageTitle = $page.find('.title').text().trim() || document.title\n const currentSlug = slugify(pageTitle)\n const currentDomain = window.location.hostname\n\n const domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Searching ${total.toLocaleString()} pages\u2026`\n\n let qVec = await lookupPageVector(currentSlug, currentDomain)\n if (!qVec) {\n status.textContent = 'Embedding page (not yet indexed)\u2026'\n const pageText = $page.find('.item').map((_, el) => $(el).text().trim()).get().filter(Boolean).join('\\n')\n qVec = await getEmbedding(pageText || pageTitle, origin)\n }\n\n const scored = cosineScan(qVec, domainEntries, {\n threshold, limit, excludeSlug: currentSlug, excludeDomain: currentDomain,\n })\n renderScored(scored, null)\n if (scored.length) writeCache(item, { scored })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n }\n })()\n }\n\n } else if (mode === 'author') {\n // Author mode \u2014 same search form but creates a ghost page from results\n const input = div.find('.sim-input')[0]\n const btn = div.find('.sim-btn')[0]\n const results = div.find('.sim-results')[0]\n let domainEntries = null\n\n ;(async () => {\n try {\n if (!cache) status.textContent = 'Resolving domains\u2026'\n domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Ready \u2014 ${total.toLocaleString()} pages across ${domainEntries.length} domains`\n } catch (e) {\n status.textContent = `Load error: ${e.message}`\n }\n })()\n\n const doAuthor = async () => {\n const query = input.value.trim()\n if (!query || !domainEntries) return\n btn.disabled = true\n status.textContent = 'Embedding query\u2026'\n results.innerHTML = ''\n try {\n const qVec = await getEmbedding(query, origin)\n const scored = cosineScan(qVec, domainEntries,\n { threshold, limit, excludeSlug: null, excludeDomain: null })\n\n // Unique titles for wiki-link list\n const seenTitles = new Set()\n const uniqueTitles = []\n for (const { title } of scored) {\n if (!seenTitles.has(title)) { seenTitles.add(title); uniqueTitles.push(title) }\n }\n\n const hexId = () => Math.floor(Math.random() * 0xffffffffffffffff).toString(16).padStart(16, '0')\n const primaryLines = uniqueTitles.map(t => `- [[${t}]]`).join('\\n')\n\n const story = [\n { type: 'markdown', id: hexId(), text: `# Similar Pages\\n\\n${primaryLines}` },\n { type: 'markdown', id: hexId(), text: '# Reference Links' },\n ...scored.map(({ domain, slug, title, score }) => ({\n type: 'reference', id: hexId(), site: domain, slug, title,\n text: `score ${score.toFixed(3)}`,\n })),\n ]\n\n const pageObj = window.wiki.newPage({ title: `${query} Results`, story, journal: [] })\n window.wiki.showResult(pageObj, { $page: div.parents('.page') })\n\n status.textContent = `${scored.length} pages found`\n writeCache(item, { scored, query })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doAuthor)\n input.addEventListener('keydown', e => { if (e.key === 'Enter') doAuthor() })\n\n } else {\n // Search form mode\n const input = div.find('.sim-input')[0]\n const btn = div.find('.sim-btn')[0]\n const results = div.find('.sim-results')[0]\n let domainEntries = null\n\n // Show cached results immediately while domains preload in background\n if (cache?.scored) {\n input.value = cache.query || ''\n results.innerHTML = cache.scored.map(({ domain, slug, title, score }) =>\n `<div class=\"sim-result\">${simLink(domain, slug, title, score)}</div>`).join('') +\n `<p class=\"sim-count\">Top ${cache.scored.length} for \"${cache.query || ''}\"${cacheNote(cache.ts)}</p>`\n status.textContent = ''\n }\n\n ;(async () => {\n try {\n if (!cache) status.textContent = 'Resolving domains\u2026'\n domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Ready \u2014 ${total.toLocaleString()} pages across ${domainEntries.length} domains`\n } catch (e) {\n status.textContent = `Load error: ${e.message}`\n }\n })()\n\n const doSearch = async () => {\n const query = input.value.trim()\n if (!query || !domainEntries) return\n btn.disabled = true\n status.textContent = 'Embedding query\u2026'\n results.innerHTML = ''\n try {\n const qVec = await getEmbedding(query, origin)\n const scored = cosineScan(qVec, domainEntries,\n { threshold, limit, excludeSlug: null, excludeDomain: null })\n results.innerHTML = scored.map(({ domain, slug, title, score }) =>\n `<div class=\"sim-result\">${simLink(domain, slug, title, score)}</div>`).join('') +\n `<p class=\"sim-count\">Top ${scored.length} for \"${query}\"</p>`\n status.textContent = ''\n writeCache(item, { scored, query })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doSearch)\n input.addEventListener('keydown', e => { if (e.key === 'Enter') doSearch() })\n }\n}\n\n// \u2500\u2500 Register item type with the wiki \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nif (typeof window !== 'undefined') {\n window.plugins = window.plugins || {}\n window.plugins.similarity = { emit, bind }\n}\n"],
|
|
5
|
-
"mappings": ";MA4BA,IAAMA,EAAqB,CAAE,KAAM,IAAM,OAAQ,IAAM,IAAK,GAAK,EAC3DC,EAAqBD,EAAmB,OACxCE,EAAqB,GAWrBC,EAAWC,GAAQ,CACvB,IAAMC,EAAU,CAAC,EACbC,EAAY,KACZC,EAAY,KACZC,EAAY,SACZC,EAAY,GAKVC,EAAS,CAACC,EAAOC,IAAOD,IAAUC,GAAOD,EAAM,WAAWC,CAAE,GAAK,SAAS,KAAKD,EAAM,MAAMC,EAAG,MAAM,CAAC,EAGrGC,EAAS,CAACC,EAAMF,IAAOE,EAAK,MAAMF,EAAG,MAAM,EAAE,QAAQ,YAAa,EAAE,EAAE,KAAK,EAEjF,QAAWG,KAAOX,EAAK,MAAM;AAAA,CAAI,EAAG,CACl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,EAAc,MAAM,UAC7F,OAASY,EAAG,CACViB,EAAO,YAAc,eAAejB,EAAE,OAAO,EAC/C,CACF,GAAG,EAEH,IAAMkD,EAAW,SAAY,CAC3B,IAAMR,EAAQH,EAAM,MAAM,KAAK,EAC/B,GAAI,GAACG,GAAS,CAACtD,GACf,CAAAoD,EAAI,SAAW,GACfvB,EAAO,YAAc,wBACrB1B,EAAQ,UAAY,GACpB,GAAI,CACF,IAAM4C,EAAO,MAAMtD,EAAa6D,EAAO5E,CAAM,EACvC+D,EAAS3C,EAAWiD,EAAM/C,EAC9B,CAAE,UAAAvC,EAAW,MAAAC,EAAO,YAAa,KAAM,cAAe,IAAK,CAAC,EAC9DyC,EAAQ,UAAYsC,EAAO,IAAI,CAAC,CAAE,OAAAnD,EAAQ,KAAAK,EAAM,MAAApB,EAAO,MAAAgD,CAAM,IAC3D,2BAA2BC,EAAQlC,EAAQK,EAAMpB,EAAOgD,CAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,EAC/E,4BAA4BkB,EAAO,MAAM,SAASa,CAAK,QACzDzB,EAAO,YAAc,GACrBZ,EAAWhC,EAAM,CAAE,OAAAwD,EAAQ,MAAAa,CAAM,CAAC,CACpC,OAAS1C,EAAG,CACViB,EAAO,YAAc,UAAUjB,EAAE,OAAO,EAC1C,QAAE,CACAwC,EAAI,SAAW,EACjB,EACF,EAEAA,EAAI,iBAAiB,QAASU,CAAQ,EACtCX,EAAM,iBAAiB,UAAWvC,GAAK,CAAMA,EAAE,MAAQ,SAASkD,EAAS,CAAE,CAAC,CAC9E,CACF,EAII,OAAO,OAAW,MACpB,OAAO,QAAU,OAAO,SAAW,CAAC,EACpC,OAAO,QAAQ,WAAa,CAAE,KAAArC,GAAM,KAAAG,EAAK",
|
|
6
|
-
"names": ["SIMILAR_THRESHOLDS", "DEFAULT_THRESHOLD", "DEFAULT_LIMIT", "parseDSL", "text", "specs", "threshold", "limit", "mode", "live", "isCmd", "upper", "kw", "val", "line", "raw", "level", "isGlob", "spec", "slugify", "title", "domainCache", "resolveDomainsForSpec", "origin", "url", "res", "list", "resolveDomains", "seen", "result", "item", "vectorCache", "isLocalhost", "h", "vectorUrl", "domain", "loadVectors", "data", "getEmbedding", "lookupPageVector", "slug", "entry", "p", "cosineScan", "queryVec", "domainEntries", "excludeSlug", "excludeDomain", "results", "pages", "vector", "dot", "i", "a", "b", "loadDomainEntries", "domains", "e", "cacheKey", "id", "readCache", "c", "writeCache", "cacheAge", "ts", "s", "STYLES", "siteFlag", "score", "simLink", "emit", "div", "
|
|
4
|
+
"sourcesContent": ["// wiki-plugin-similarity\n//\n// One item type: similarity\n//\n// DSL in item.text (newline-separated lines):\n// * all indexed domains on this server\n// david.* glob pattern\n// *.fish glob pattern\n// david.hitchhikers.earth explicit domain name\n// # comment ignored\n// LIST list indexed domains (mode directive)\n// SIMILAR: high threshold preset AND ambient mode trigger\n// THRESHOLD: 0.72 exact cosine threshold (overrides SIMILAR:)\n// LIMIT: 8 max results shown (default 10)\n//\n// Mode is determined by the FIRST meaningful line (Ward's ALL-CAPS convention):\n// LIST \u2192 show a table of all indexed domains and their page counts;\n// optional glob patterns on subsequent lines filter the list\n// SIMILAR: \u2192 ambient mode \u2014 automatically find pages similar to this page\n// (other) \u2192 search form mode \u2014 user types a query, results appear\n//\n// Server endpoints required:\n// GET /system/indexed-domains.json?pattern=glob1,glob2\n// GET /system/semantic-vectors.json?domain=\n// GET /system/embed.json?text=query\n\n// \u2500\u2500 DSL Parser \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst SIMILAR_THRESHOLDS = { high: 0.78, medium: 0.68, low: 0.58 }\nconst DEFAULT_THRESHOLD = SIMILAR_THRESHOLDS.medium\nconst DEFAULT_LIMIT = 10\n\n// parseDSL returns { mode, specs, threshold, limit }\n//\n// mode: 'similar' if SIMILAR: is the first meaningful line (ambient auto-run),\n// 'search' otherwise (interactive search form).\n//\n// Ward's convention: ALL-CAPS keyword as first word signals a mode switch.\n// Placing SIMILAR: first makes the item ambient; placing domain specs first\n// (or leaving text empty) keeps it as an interactive search form.\n\nconst parseDSL = text => {\n const specs = []\n let threshold = null\n let limit = null\n let mode = 'search' // default: interactive search form\n let live = false // default: cache results in localStorage\n let force = false // BUILD mode: re-embed even when index is fresh\n let ghostUrl = null // GHOST mode: page-json URL to open as a ghost page\n let label = null // BUTTON: custom button caption (GHOST / BUILD modes)\n\n // Match a keyword at the start of a line (case-insensitive), requiring it to\n // be followed by end-of-string, whitespace, or colon \u2014 not by more word chars.\n // This prevents domain specs like \"similarity.example.com\" matching SIMILAR.\n const isCmd = (upper, kw) => upper === kw || (upper.startsWith(kw) && /^[\\s:]/.test(upper.slice(kw.length)))\n // Extract the value after the keyword, tolerating optional colon and whitespace.\n // Returns '' for bare commands (e.g. \"SIMILAR\" alone), callers use their default.\n const val = (line, kw) => line.slice(kw.length).replace(/^\\s*:?\\s*/, '').trim()\n\n for (const raw of text.split('\\n')) {\n const line = raw.trim()\n if (!line || line.startsWith('#')) continue\n\n const upper = line.toUpperCase()\n if (isCmd(upper, 'LIVE')) { live = true; continue }\n if (isCmd(upper, 'AUTHOR')) {\n if (!specs.length && mode === 'search') mode = 'author'\n continue\n }\n if (isCmd(upper, 'REPORT')) {\n if (mode === 'search') mode = 'report'\n continue\n }\n if (isCmd(upper, 'BUILD')) {\n if (mode === 'search') mode = 'build'\n continue\n }\n if (isCmd(upper, 'FORCE')) { force = true; continue }\n if (isCmd(upper, 'GHOST')) {\n ghostUrl = val(line, 'GHOST')\n if (mode === 'search') mode = 'ghost'\n continue\n }\n if (isCmd(upper, 'BUTTON')) { label = val(line, 'BUTTON'); continue }\n if (isCmd(upper, 'LIST')) {\n if (!specs.length && mode === 'search') mode = 'list'\n continue\n }\n if (isCmd(upper, 'SIMILAR')) {\n const level = val(upper, 'SIMILAR').toLowerCase()\n threshold = SIMILAR_THRESHOLDS[level] || DEFAULT_THRESHOLD // '' \u2192 medium\n if (!specs.length && mode === 'search') mode = 'similar'\n continue\n }\n if (isCmd(upper, 'THRESHOLD')) {\n const tv = val(line, 'THRESHOLD')\n threshold = SIMILAR_THRESHOLDS[tv.toLowerCase()] ?? (parseFloat(tv) || DEFAULT_THRESHOLD)\n continue\n }\n if (isCmd(upper, 'LIMIT')) {\n limit = parseInt(val(line, 'LIMIT')) || DEFAULT_LIMIT // '' \u2192 10\n continue\n }\n // Anything else is a domain spec (glob, explicit domain, or scope keyword)\n specs.push(['PUBLIC', 'LOCAL', 'PRIVATE'].includes(upper) ? upper : line)\n }\n\n return {\n mode,\n specs,\n threshold: threshold ?? DEFAULT_THRESHOLD,\n limit: limit ?? DEFAULT_LIMIT,\n live,\n force,\n ghostUrl,\n label,\n }\n}\n\nconst isGlob = spec => spec.includes('*') || spec.includes('?')\n\n// Scope keywords expand server-side: PUBLIC (Nextcloud mirror farms),\n// LOCAL (primary farm), PRIVATE (public domains with restricted: true)\nconst isScope = spec => spec === 'PUBLIC' || spec === 'LOCAL' || spec === 'PRIVATE'\n\n// \u2500\u2500 Slug \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst slugify = title => title.toLowerCase().replace(/\\s+/g, '-').replace(/[^a-z0-9-]/g, '')\n\n// \u2500\u2500 Domain resolution \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst domainCache = new Map()\n\nconst resolveDomainsForSpec = async (spec, origin) => {\n if (domainCache.has(spec)) return domainCache.get(spec)\n const url = `${origin}/system/indexed-domains.json?pattern=${encodeURIComponent(spec)}`\n const res = await fetch(url)\n if (!res.ok) throw new Error(`indexed-domains failed: ${res.status}`)\n const list = await res.json()\n domainCache.set(spec, list)\n return list\n}\n\nconst resolveDomains = async (specs, origin) => {\n if (!specs.length) specs = [window.location.hostname]\n const seen = new Set()\n const result = []\n for (const spec of specs) {\n if (spec === '*' || isGlob(spec) || isScope(spec)) {\n for (const item of await resolveDomainsForSpec(spec, origin)) {\n if (!seen.has(item.domain)) { seen.add(item.domain); result.push(item) }\n }\n } else if (!seen.has(spec)) {\n seen.add(spec); result.push({ domain: spec, page_count: null })\n }\n }\n return result\n}\n\n// \u2500\u2500 Vector loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst vectorCache = new Map()\n\n// Detect whether the wiki is running on localhost (or a .localhost subdomain).\n// On localhost we proxy all domain vector fetches through the local server's\n// ?domain= parameter \u2014 this reads vectors directly from the farm folder on disk,\n// avoiding any need for remote servers to have this plugin installed, and\n// sidestepping CORS entirely.\nconst isLocalhost = () => {\n const h = window.location.hostname\n return h === 'localhost' || h.endsWith('.localhost') || h === '127.0.0.1'\n}\n\nconst vectorUrl = domain => {\n if (isLocalhost()) {\n // Route through our local server \u2014 serves any farm domain from disk\n return `${window.location.origin}/system/semantic-vectors.json?domain=${encodeURIComponent(domain)}`\n }\n // On a real server, fetch directly from the remote wiki \u2014 use same protocol\n // as the current page to avoid mixed-content blocks on HTTPS sites\n return `${window.location.protocol}//${domain}/system/semantic-vectors.json`\n}\n\nconst loadVectors = async domain => {\n if (vectorCache.has(domain)) return vectorCache.get(domain)\n const res = await fetch(vectorUrl(domain))\n if (!res.ok) return []\n const data = await res.json()\n vectorCache.set(domain, data)\n return data\n}\n\n// \u2500\u2500 Embedding \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst getEmbedding = async (text, origin) => {\n const res = await fetch(`${origin}/system/embed.json?text=${encodeURIComponent(text)}`)\n if (!res.ok) throw new Error(`embed failed: ${res.status}`)\n return (await res.json()).vector\n}\n\n// Look up an existing page vector from the current domain's cached index.\n// Returns the float[] vector if found, null otherwise.\nconst lookupPageVector = async (slug, domain) => {\n const pages = await loadVectors(domain)\n const entry = pages.find(p => p.slug === slug)\n return entry ? entry.vector : null\n}\n\n// \u2500\u2500 Cosine search \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst cosineScan = (queryVec, domainEntries, { threshold, limit, excludeSlug, excludeDomain }) => {\n const results = []\n for (const { domain, pages } of domainEntries) {\n for (const { slug, title, vector } of pages) {\n if (slug === excludeSlug && domain === excludeDomain) continue\n let dot = 0\n for (let i = 0; i < queryVec.length; i++) dot += queryVec[i] * vector[i]\n if (dot >= threshold) results.push({ domain, slug, title, score: dot })\n }\n }\n results.sort((a, b) => b.score - a.score)\n return results.slice(0, limit)\n}\n\n// \u2500\u2500 Shared domain loading \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst loadDomainEntries = async (specs, origin) => {\n const domains = await resolveDomains(specs, origin)\n const entries = await Promise.all(\n domains.map(async ({ domain }) => ({ domain, pages: await loadVectors(domain) }))\n )\n return entries.filter(e => e.pages.length > 0)\n}\n\n// \u2500\u2500 Result cache (localStorage) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// Cache is keyed by item id. Invalidated when item.text changes (DSL edited).\n// LIVE mode bypasses the cache entirely.\n\nconst cacheKey = id => `sim-cache-${id}`\n\nconst readCache = item => {\n try {\n const c = JSON.parse(localStorage.getItem(cacheKey(item.id)) || 'null')\n return c?.text === (item.text || '') ? c : null\n } catch { return null }\n}\n\nconst writeCache = (item, data) => {\n try {\n localStorage.setItem(cacheKey(item.id), JSON.stringify({\n text: item.text || '',\n ts: Date.now(),\n ...data,\n }))\n } catch { /* storage unavailable or full */ }\n}\n\nconst cacheAge = ts => {\n const s = Math.floor((Date.now() - ts) / 1000)\n if (s < 60) return `${s}s ago`\n if (s < 3600) return `${Math.floor(s / 60)}m ago`\n if (s < 86400) return `${Math.floor(s / 3600)}h ago`\n return `${Math.floor(s / 86400)}d ago`\n}\n\n// \u2500\u2500 Styles \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst STYLES = `\n .sim-form { display:flex; gap:6px; margin-bottom:8px; }\n .sim-input { flex:1; padding:6px 8px; font-size:14px; border:1px solid #ccc; border-radius:3px; }\n .sim-btn { padding:6px 14px; background:#c4561d; color:white; border:none;\n border-radius:3px; cursor:pointer; font-size:14px; }\n .sim-btn:disabled { opacity:0.5; cursor:not-allowed; }\n .sim-status { font-size:12px; color:#888; margin-bottom:6px; min-height:16px; }\n .sim-results { margin-top:4px; }\n .sim-result { display:flex; align-items:center; gap:8px; padding:3px 0;\n border-bottom:1px solid #f0f0f0; }\n .sim-flag { width:16px; height:16px; vertical-align:middle; margin-right:4px; }\n .sim-link { font-size:14px; color:#406; flex:1; }\n .sim-domain { font-size:11px; color:#999; }\n .similar-results h3, .sim-list h3 { margin:4px 0 6px; font-size:14px; color:#555; }\n .similar-results ul { margin:0; padding-left:18px; }\n .similar-results li { font-size:14px; padding:2px 0; }\n .similar-results .sim-domain { margin-left:6px; }\n .sim-count { font-size:12px; color:#888; margin:4px 0 0; }\n .sim-list table { border-collapse:collapse; width:100%; font-size:13px; }\n .sim-list th { text-align:left; font-size:11px; color:#888; padding:2px 8px 4px 0;\n border-bottom:1px solid #ddd; }\n .sim-list td { padding:3px 8px 3px 0; border-bottom:1px solid #f0f0f0; vertical-align:middle; }\n .sim-list td:last-child { text-align:right; color:#999; font-size:11px; }\n .sim-list .sim-flag { margin-right:6px; }\n`\n\nconst siteFlag = (domain, score) =>\n `<img class=\"sim-flag remote\" src=\"${window.wiki.site(domain).flag()}\"\n title=\"${domain} \u2014 score ${score.toFixed(3)}\"\n data-site=\"${domain}\">`\n\n// \u2500\u2500 similarity item \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst simLink = (domain, slug, title, score) =>\n `<a class=\"sim-link\" data-title=\"${title}\" data-slug=\"${slug}\" data-site=\"${domain}\" href=\"#\">` +\n `${siteFlag(domain, score)} ${title}</a>`\n\nexport const emit = (div, item) => {\n const { mode, specs, threshold, limit, force, ghostUrl, label } = parseDSL(item?.text || '')\n if (mode === 'ghost') {\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <button class=\"sim-btn\">${label || 'Open'}</button>\n </div>\n <div class=\"sim-status\"></div>\n </div>`)\n } else if (mode === 'build') {\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <button class=\"sim-btn\">${label || `Index ${specs.length ? specs.join(', ') : '*'}${force ? ' (force)' : ''}`}</button>\n </div>\n <div class=\"sim-status\"></div>\n </div>`)\n } else if (mode === 'list') {\n const label = specs.length ? specs.join(', ') : '*'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-status\">Loading indexed domains (${label})\u2026</div>\n <div class=\"sim-list\"></div>\n </div>`)\n } else if (mode === 'similar') {\n const label = specs.length ? specs.join(', ') : 'current domain'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-status\">Finding similar pages across ${label}\u2026</div>\n <div class=\"sim-results\"></div>\n </div>`)\n } else if (mode === 'author' || mode === 'report') {\n const label = specs.length ? specs.join(', ') : '(current domain)'\n const btnLabel = mode === 'report' ? 'Report' : 'Author'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <input class=\"sim-input\" type=\"text\" placeholder=\"Search wiki pages\u2026\" />\n <button class=\"sim-btn\">${btnLabel}</button>\n </div>\n <div class=\"sim-status\">Domains: ${label}</div>\n <div class=\"sim-results\"></div>\n </div>`)\n } else {\n const label = specs.length ? specs.join(', ') : '(current domain)'\n div.html(`\n <style>${STYLES}</style>\n <div class=\"similarity\" data-id=\"${item.id}\">\n <div class=\"sim-form\">\n <input class=\"sim-input\" type=\"text\" placeholder=\"Search wiki pages\u2026\" />\n <button class=\"sim-btn\">Search</button>\n </div>\n <div class=\"sim-status\">Domains: ${label}</div>\n <div class=\"sim-results\"></div>\n </div>`)\n }\n}\n\nexport const bind = (div, item) => {\n const { mode, specs, threshold, limit, live, force, ghostUrl } = parseDSL(item?.text || '')\n const origin = window.location.origin\n const status = div.find('.sim-status')[0]\n const cache = live ? null : readCache(item)\n\n div.on('dblclick', e => {\n if ($(e.target).closest('.sim-input').length) return\n window.wiki.textEditor(div, item)\n })\n div.on('click', '.sim-link', function (e) {\n e.preventDefault()\n const $a = $(this)\n // shift-click appends at the end of the lineup instead of truncating after this page\n const $page = e.shiftKey ? null : div.parents('.page')\n window.wiki.doInternalLink($a.data('title'), $page, $a.data('site'))\n })\n\n const scopeLabel = !specs.length || (specs.length === 1 && specs[0] === '*')\n ? 'on farm'\n : specs.length === 1 ? `on ${specs[0]}` : 'in domains'\n\n const cacheNote = ts => ts ? ` \u00B7 cached ${cacheAge(ts)}` : ''\n\n if (mode === 'list') {\n const listDiv = div.find('.sim-list')[0]\n const patterns = specs.length ? specs.join(',') : '*'\n\n const renderList = (domains, ts) => {\n const totalPages = domains.reduce((n, d) => n + (d.page_count || 0), 0)\n status.style.display = 'none'\n listDiv.innerHTML = `<h3>Indexed Farm Domains</h3>\n <table>\n <tr><th>Domain</th><th>Pages</th></tr>\n ${domains.map(({ domain, page_count }) => `\n <tr>\n <td><img class=\"sim-flag remote\" src=\"${window.wiki.site(domain).flag()}\"\n title=\"${domain}\" data-site=\"${domain}\"> ${domain}</td>\n <td>${page_count != null ? page_count.toLocaleString() : '\u2014'}</td>\n </tr>`).join('')}\n </table>\n <p class=\"sim-count\">${domains.length} domains \u2014 ${totalPages.toLocaleString()} pages${cacheNote(ts)}</p>`\n }\n\n if (cache?.domains) {\n renderList(cache.domains, cache.ts)\n } else {\n ;(async () => {\n try {\n const url = `${origin}/system/indexed-domains.json?pattern=${encodeURIComponent(patterns)}&limit=${limit}`\n const res = await fetch(url)\n if (!res.ok) throw new Error(`indexed-domains failed: ${res.status}`)\n const domains = await res.json()\n if (!domains.length) { status.textContent = 'No indexed domains found'; return }\n renderList(domains, null)\n writeCache(item, { domains })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n }\n })()\n }\n\n } else if (mode === 'similar') {\n const results = div.find('.sim-results')[0]\n\n const renderScored = (scored, ts) => {\n if (!scored.length) {\n status.textContent = `No similar pages found above threshold ${threshold}`\n return\n }\n results.innerHTML = `<h3>Similar Pages</h3><ul>${\n scored.map(({ domain, slug, title, score }) =>\n `<li>${simLink(domain, slug, title, score)}</li>`).join('')\n }</ul><p class=\"sim-count\">${scored.length} found ${scopeLabel}${cacheNote(ts)}</p>`\n status.style.display = 'none'\n }\n\n if (cache?.scored) {\n renderScored(cache.scored, cache.ts)\n } else {\n ;(async () => {\n try {\n const $page = div.parents('.page')\n const pageTitle = $page.find('.title').text().trim() || document.title\n const currentSlug = slugify(pageTitle)\n const currentDomain = window.location.hostname\n\n const domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Searching ${total.toLocaleString()} pages\u2026`\n\n let qVec = await lookupPageVector(currentSlug, currentDomain)\n if (!qVec) {\n status.textContent = 'Embedding page (not yet indexed)\u2026'\n const pageText = $page.find('.item').map((_, el) => $(el).text().trim()).get().filter(Boolean).join('\\n')\n qVec = await getEmbedding(pageText || pageTitle, origin)\n }\n\n const scored = cosineScan(qVec, domainEntries, {\n threshold, limit, excludeSlug: currentSlug, excludeDomain: currentDomain,\n })\n renderScored(scored, null)\n if (scored.length) writeCache(item, { scored })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n }\n })()\n }\n\n } else if (mode === 'ghost') {\n // Ghost mode \u2014 fetch page-json from any URL and open it as a ghost page\n const btn = div.find('.sim-btn')[0]\n\n const doGhost = async () => {\n if (!ghostUrl) { status.textContent = 'No URL \u2014 GHOST needs a page-json URL'; return }\n btn.disabled = true\n status.textContent = 'Fetching\u2026'\n try {\n const res = await fetch(ghostUrl)\n if (!res.ok) throw new Error(`fetch failed: ${res.status}`)\n const page = await res.json()\n window.wiki.showResult(window.wiki.newPage(page), { $page: div.parents('.page') })\n status.textContent = ''\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doGhost)\n\n } else if (mode === 'build') {\n // Build mode \u2014 trigger a semantic index build; result opens as a ghost page\n const btn = div.find('.sim-btn')[0]\n\n const doBuild = async () => {\n btn.disabled = true\n status.textContent = 'Building index\u2026 (may take a while for large scopes)'\n try {\n const domains = encodeURIComponent((specs.length ? specs : ['*']).join(','))\n const res = await fetch(\n `http://api.localhost/build-index.json?domains=${domains}&force=${force ? 1 : 0}`)\n if (!res.ok) throw new Error(`build-index failed: ${res.status}`)\n const page = await res.json()\n window.wiki.showResult(window.wiki.newPage(page), { $page: div.parents('.page') })\n status.textContent = ''\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doBuild)\n\n } else if (mode === 'report') {\n // Report mode \u2014 server-side ranked/bundled search, opens result as ghost page\n const input = div.find('.sim-input')[0]\n const btn = div.find('.sim-btn')[0]\n\n const doReport = async () => {\n const query = input.value.trim()\n if (!query) return\n btn.disabled = true\n status.textContent = 'Generating report\u2026'\n try {\n const res = await fetch('http://localhost:8000/search-report', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ query, domains: specs.length ? specs : ['*'], limit }),\n })\n if (!res.ok) throw new Error(`search-report failed: ${res.status}`)\n const page = await res.json()\n const pageObj = window.wiki.newPage(page)\n window.wiki.showResult(pageObj, { $page: div.parents('.page') })\n status.textContent = ''\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doReport)\n input.addEventListener('keydown', e => { if (e.key === 'Enter') doReport() })\n\n } else if (mode === 'author') {\n // Author mode \u2014 same search form but creates a ghost page from results\n const input = div.find('.sim-input')[0]\n const btn = div.find('.sim-btn')[0]\n const results = div.find('.sim-results')[0]\n let domainEntries = null\n\n ;(async () => {\n try {\n if (!cache) status.textContent = 'Resolving domains\u2026'\n domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Ready \u2014 ${total.toLocaleString()} pages across ${domainEntries.length} domains`\n } catch (e) {\n status.textContent = `Load error: ${e.message}`\n }\n })()\n\n const doAuthor = async () => {\n const query = input.value.trim()\n if (!query || !domainEntries) return\n btn.disabled = true\n status.textContent = 'Embedding query\u2026'\n results.innerHTML = ''\n try {\n const qVec = await getEmbedding(query, origin)\n const scored = cosineScan(qVec, domainEntries,\n { threshold, limit, excludeSlug: null, excludeDomain: null })\n\n // Unique titles for wiki-link list\n const seenTitles = new Set()\n const uniqueTitles = []\n for (const { title } of scored) {\n if (!seenTitles.has(title)) { seenTitles.add(title); uniqueTitles.push(title) }\n }\n\n const hexId = () => Math.floor(Math.random() * 0xffffffffffffffff).toString(16).padStart(16, '0')\n const primaryLines = uniqueTitles.map(t => `- [[${t}]]`).join('\\n')\n\n const story = [\n { type: 'markdown', id: hexId(), text: `# Similar Pages\\n\\n${primaryLines}` },\n { type: 'markdown', id: hexId(), text: '# Reference Links' },\n ...scored.map(({ domain, slug, title, score }) => ({\n type: 'reference', id: hexId(), site: domain, slug, title,\n text: `score ${score.toFixed(3)}`,\n })),\n ]\n\n const pageObj = window.wiki.newPage({ title: `${query} Results`, story, journal: [] })\n window.wiki.showResult(pageObj, { $page: div.parents('.page') })\n\n status.textContent = `${scored.length} pages found`\n writeCache(item, { scored, query })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doAuthor)\n input.addEventListener('keydown', e => { if (e.key === 'Enter') doAuthor() })\n\n } else {\n // Search form mode\n const input = div.find('.sim-input')[0]\n const btn = div.find('.sim-btn')[0]\n const results = div.find('.sim-results')[0]\n let domainEntries = null\n\n // Show cached results immediately while domains preload in background\n if (cache?.scored) {\n input.value = cache.query || ''\n results.innerHTML = cache.scored.map(({ domain, slug, title, score }) =>\n `<div class=\"sim-result\">${simLink(domain, slug, title, score)}</div>`).join('') +\n `<p class=\"sim-count\">Top ${cache.scored.length} for \"${cache.query || ''}\"${cacheNote(cache.ts)}</p>`\n status.textContent = ''\n }\n\n ;(async () => {\n try {\n if (!cache) status.textContent = 'Resolving domains\u2026'\n domainEntries = await loadDomainEntries(specs, origin)\n const total = domainEntries.reduce((n, e) => n + e.pages.length, 0)\n status.textContent = `Ready \u2014 ${total.toLocaleString()} pages across ${domainEntries.length} domains`\n } catch (e) {\n status.textContent = `Load error: ${e.message}`\n }\n })()\n\n const doSearch = async () => {\n const query = input.value.trim()\n if (!query || !domainEntries) return\n btn.disabled = true\n status.textContent = 'Embedding query\u2026'\n results.innerHTML = ''\n try {\n const qVec = await getEmbedding(query, origin)\n const scored = cosineScan(qVec, domainEntries,\n { threshold, limit, excludeSlug: null, excludeDomain: null })\n results.innerHTML = scored.map(({ domain, slug, title, score }) =>\n `<div class=\"sim-result\">${simLink(domain, slug, title, score)}</div>`).join('') +\n `<p class=\"sim-count\">Top ${scored.length} for \"${query}\"</p>`\n status.textContent = ''\n writeCache(item, { scored, query })\n } catch (e) {\n status.textContent = `Error: ${e.message}`\n } finally {\n btn.disabled = false\n }\n }\n\n btn.addEventListener('click', doSearch)\n input.addEventListener('keydown', e => { if (e.key === 'Enter') doSearch() })\n }\n}\n\n// \u2500\u2500 Register item type with the wiki \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nif (typeof window !== 'undefined') {\n window.plugins = window.plugins || {}\n window.plugins.similarity = { emit, bind }\n}\n"],
|
|
5
|
+
"mappings": ";MA4BA,IAAMA,EAAqB,CAAE,KAAM,IAAM,OAAQ,IAAM,IAAK,GAAK,EAC3DC,EAAqBD,EAAmB,OACxCE,EAAqB,GAWrBC,EAAWC,GAAQ,CACvB,IAAMC,EAAU,CAAC,EACbC,EAAY,KAC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AAK",
|
|
6
|
+
"names": ["SIMILAR_THRESHOLDS", "DEFAULT_THRESHOLD", "DEFAULT_LIMIT", "parseDSL", "text", "specs", "threshold", "limit", "mode", "live", "force", "ghostUrl", "label", "isCmd", "upper", "kw", "val", "line", "raw", "level", "tv", "isGlob", "spec", "isScope", "slugify", "title", "domainCache", "resolveDomainsForSpec", "origin", "url", "res", "list", "resolveDomains", "seen", "result", "item", "vectorCache", "isLocalhost", "h", "vectorUrl", "domain", "loadVectors", "data", "getEmbedding", "lookupPageVector", "slug", "entry", "p", "cosineScan", "queryVec", "domainEntries", "excludeSlug", "excludeDomain", "results", "pages", "vector", "dot", "i", "a", "b", "loadDomainEntries", "domains", "e", "cacheKey", "id", "readCache", "c", "writeCache", "cacheAge", "ts", "s", "STYLES", "siteFlag", "score", "simLink", "emit", "div", "btnLabel", "bind", "status", "cache", "$a", "$page", "scopeLabel", "cacheNote", "listDiv", "patterns", "renderList", "totalPages", "n", "d", "page_count", "renderScored", "scored", "pageTitle", "currentSlug", "currentDomain", "total", "qVec", "pageText", "_", "el", "btn", "doGhost", "page", "doBuild", "input", "doReport", "query", "pageObj", "doAuthor", "seenTitles", "uniqueTitles", "hexId", "primaryLines", "t", "story", "doSearch"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
{
|
|
5
5
|
"type": "markdown",
|
|
6
6
|
"id": "61ccb2d2cdb60c71",
|
|
7
|
-
"text": "The Similarity plugin adds semantic similarity search to a Federated Wiki farm. One item type — **similarity** — with behaviour controlled by a DSL: interactive search
|
|
7
|
+
"text": "The Similarity plugin adds semantic similarity search to a Federated Wiki farm. One item type — **similarity** — with behaviour controlled by a DSL: interactive search, ambient similar-pages panel, domain listing, ranked search reports, ghost-page authoring, index building, and generic report buttons."
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"type": "markdown",
|
|
11
11
|
"id": "a3f7c8d2e1b94056",
|
|
12
|
-
"text": "**Version:** 0.
|
|
12
|
+
"text": "**Version:** 0.4.0 — [GitHub](https://github.com/Hitchhikers-Guide-to-the-Galaxy/wiki-plugin-similarity) · [npm](https://www.npmjs.com/package/wiki-plugin-similarity)"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"type": "similarity",
|
|
@@ -19,12 +19,22 @@
|
|
|
19
19
|
{
|
|
20
20
|
"type": "markdown",
|
|
21
21
|
"id": "bdf93e3860d64ebb",
|
|
22
|
-
"text": "##
|
|
22
|
+
"text": "## The DSL"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"type": "markdown",
|
|
26
26
|
"id": "0d628d43edf9f8e8",
|
|
27
|
-
"text": "The item's `text` field configures
|
|
27
|
+
"text": "The item's `text` field configures what the item does. Mode commands come first; the rest are options and domain specs:\n\n```\nSIMILAR ambient mode — similar pages to this one\nSIMILAR high threshold preset (high=0.78 / medium=0.68 / low=0.58)\nLIST table of indexed domains with page counts\nAUTHOR search → ghost page of [[wiki links]] + references\nREPORT server-side ranked report (stubs dropped, forks bundled)\nBUILD button that builds semantic indexes\nGHOST <url> button that opens any page-json URL as a ghost page\n\nTHRESHOLD 0.72 exact cosine threshold\nLIMIT 8 max results (default 10)\nLIVE bypass the localStorage cache\nFORCE BUILD: re-embed even when the index is fresh\nBUTTON <text> custom button caption (BUILD / GHOST)\n```\n\nColons and extra whitespace are optional — `LIMIT: 8`, `LIMIT 8`, and `LIMIT:8` all work. Leave `text` empty for an interactive search form on the current domain."
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "markdown",
|
|
31
|
+
"id": "1e2f3a4b5c6d7e8f",
|
|
32
|
+
"text": "## Domain Specs and Scopes"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"type": "markdown",
|
|
36
|
+
"id": "2f3a4b5c6d7e8f90",
|
|
37
|
+
"text": "Any other line is a domain spec. Scope keywords expand server-side:\n\n```\n* all indexed domains, all farms\nPUBLIC the Nextcloud mirror farm\nLOCAL the localhost farm\nPRIVATE public wikis with restricted: true in the farm config\ndavid.* glob pattern\ndavid.hitchhikers.earth explicit domain\n# comment ignored\n```\n\nSpecs combine — `LOCAL` and `david.*` on separate lines searches both."
|
|
28
38
|
},
|
|
29
39
|
{
|
|
30
40
|
"type": "markdown",
|
|
@@ -34,7 +44,7 @@
|
|
|
34
44
|
{
|
|
35
45
|
"type": "markdown",
|
|
36
46
|
"id": "4f91a3b2d8e05c11",
|
|
37
|
-
"text": "**Search** (default) —
|
|
47
|
+
"text": "**Search** (default) — interactive form; results appear inline as scored links. Shift-click a result to append it at the end of the lineup instead of truncating.\n\n**Similar** — runs on page load using the current page's pre-computed vector (no embed call if already indexed). Ranked *Similar Pages* list.\n\n**List** — table of indexed domains with page counts; supports scopes, globs, and `LIMIT`.\n\n**Author** — same search, but opens a ghost page with `# Similar Pages` ([[wiki links]], deduplicated) and `# Reference Links` (all results as reference items with scores).\n\n**Report** — posts to the farm API's `/search-report`: candidates from semantic scan ∪ title matching, stubs dropped, forks and near-duplicates bundled under the strongest copy with a one-click lineup link, ranked by semantic × richness × recency + title boost. Opens as a ghost page. *(localhost only — needs the FastAPI service.)*\n\n**Build** — a button that triggers semantic index building via `/build-index.json`; the build report opens as a ghost page. Add `FORCE` to re-embed fresh domains. *(localhost only.)*\n\n**Ghost** — a generic button: `GHOST <url>` fetches any endpoint returning fedwiki page JSON and opens it as a ghost page. Caption set with `BUTTON <text>`."
|
|
38
48
|
},
|
|
39
49
|
{
|
|
40
50
|
"type": "markdown",
|
|
@@ -44,7 +54,7 @@
|
|
|
44
54
|
{
|
|
45
55
|
"type": "markdown",
|
|
46
56
|
"id": "9a1b2c3d4e5f6001",
|
|
47
|
-
"text": "Results are cached in `localStorage` keyed by item id and invalidated whenever the item's `text` changes. Add `LIVE` anywhere in the DSL to bypass the cache
|
|
57
|
+
"text": "Results are cached in `localStorage` keyed by item id and invalidated whenever the item's `text` changes. Add `LIVE` anywhere in the DSL to bypass the cache."
|
|
48
58
|
},
|
|
49
59
|
{
|
|
50
60
|
"type": "markdown",
|
|
@@ -54,7 +64,7 @@
|
|
|
54
64
|
{
|
|
55
65
|
"type": "markdown",
|
|
56
66
|
"id": "4b1bbe95544548eb",
|
|
57
|
-
"text": "Pages are pre-indexed as 384-dimensional embedding vectors using BAAI/bge-small-en-v1.5 via fastembed. The plugin loads `semantic-vectors.json` index files directly in the browser and scores them with cosine similarity in JavaScript — no remote search engine required.\n\nThe
|
|
67
|
+
"text": "Pages are pre-indexed as 384-dimensional embedding vectors using BAAI/bge-small-en-v1.5 via fastembed. The plugin loads `semantic-vectors.json` index files directly in the browser and scores them with cosine similarity in JavaScript — no remote search engine required.\n\nThe server component registers `/system/indexed-domains.json`, `/system/semantic-vectors.json`, and `/system/embed.json` routes, and understands the scope keywords. See [[Similarity Indexing]] for building indices and [[Build Semantic Index]] for triggering builds from the wiki."
|
|
58
68
|
}
|
|
59
69
|
],
|
|
60
70
|
"journal": [
|
|
@@ -70,7 +80,7 @@
|
|
|
70
80
|
}
|
|
71
81
|
]
|
|
72
82
|
},
|
|
73
|
-
"date":
|
|
83
|
+
"date": 1781133629000,
|
|
74
84
|
"certificate": "from marvin"
|
|
75
85
|
}
|
|
76
86
|
],
|
package/server/server.js
CHANGED
|
@@ -51,8 +51,41 @@ const globMatch = (pattern, str) => {
|
|
|
51
51
|
return dp[p][s]
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// Scope keywords (exact uppercase, per DSL convention):
|
|
55
|
+
// * all farms
|
|
56
|
+
// PUBLIC domains in the extra farms (Nextcloud mirror)
|
|
57
|
+
// LOCAL domains in the primary (localhost) farm
|
|
58
|
+
// PRIVATE public domains marked "restricted": true in the farm config
|
|
59
|
+
|
|
60
|
+
// Collect restricted domains from config-*.json files at each public farm root
|
|
61
|
+
const loadRestricted = () => {
|
|
62
|
+
const restricted = new Set()
|
|
63
|
+
for (const farm of EXTRA_FARMS) {
|
|
64
|
+
let files
|
|
65
|
+
try { files = fs.readdirSync(farm) } catch { continue }
|
|
66
|
+
for (const f of files) {
|
|
67
|
+
if (!/^config-.*\.json$/.test(f)) continue
|
|
68
|
+
try {
|
|
69
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(farm, f), 'utf8'))
|
|
70
|
+
for (const [domain, opts] of Object.entries(cfg.wikiDomains || {})) {
|
|
71
|
+
if (opts && opts.restricted) restricted.add(domain)
|
|
72
|
+
}
|
|
73
|
+
} catch { /* ignore malformed config */ }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return restricted
|
|
77
|
+
}
|
|
78
|
+
const RESTRICTED = loadRestricted()
|
|
79
|
+
|
|
80
|
+
// kind: 'local' for the primary farm, 'public' for extra farms
|
|
81
|
+
const matchesAny = (domain, kind, patterns) =>
|
|
82
|
+
patterns.some(p => {
|
|
83
|
+
if (p === '*') return true
|
|
84
|
+
if (p === 'PUBLIC') return kind === 'public'
|
|
85
|
+
if (p === 'LOCAL') return kind === 'local'
|
|
86
|
+
if (p === 'PRIVATE') return kind === 'public' && RESTRICTED.has(domain)
|
|
87
|
+
return globMatch(p, domain)
|
|
88
|
+
})
|
|
56
89
|
|
|
57
90
|
// ── Multi-farm helpers ────────────────────────────────────────────────────────
|
|
58
91
|
|
|
@@ -70,11 +103,12 @@ const findInFarms = (farmRoot, domain, relPath) => {
|
|
|
70
103
|
// ── Discover indexed domains ───────────────────────────────────────────────────
|
|
71
104
|
|
|
72
105
|
const findIndexedDomains = (farmRoot, patterns) => {
|
|
73
|
-
|
|
106
|
+
// primary farm is 'local'; extra farms (Nextcloud mirror) are 'public'
|
|
107
|
+
const farms = [[farmRoot, 'local'], ...EXTRA_FARMS.map(f => [f, 'public'])]
|
|
74
108
|
const seen = new Set()
|
|
75
109
|
const results = []
|
|
76
110
|
|
|
77
|
-
for (const farm of farms) {
|
|
111
|
+
for (const [farm, kind] of farms) {
|
|
78
112
|
let entries
|
|
79
113
|
try { entries = fs.readdirSync(farm, { withFileTypes: true }) } catch { continue }
|
|
80
114
|
|
|
@@ -82,7 +116,7 @@ const findIndexedDomains = (farmRoot, patterns) => {
|
|
|
82
116
|
if (!ent.isDirectory()) continue
|
|
83
117
|
const domain = ent.name
|
|
84
118
|
if (seen.has(domain)) continue // first farm wins
|
|
85
|
-
if (!matchesAny(domain, patterns)) continue
|
|
119
|
+
if (!matchesAny(domain, kind, patterns)) continue
|
|
86
120
|
const vecFile = path.join(farm, domain, 'status', 'semantic-vectors.json')
|
|
87
121
|
try { fs.accessSync(vecFile, fs.constants.F_OK) } catch { continue }
|
|
88
122
|
seen.add(domain)
|