@duckmind/dm-darwin-x64 0.43.8 → 0.48.5

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.
@@ -1,12 +1,12 @@
1
- import{spawn as de}from"node:child_process";import{existsSync as O,mkdirSync as q,readFileSync as k,writeFileSync as B}from"node:fs";import{homedir as V}from"node:os";import{join as M}from"node:path";import{tmpdir as T}from"node:os";var b=`${T().replaceAll("\\","/")}/greedysearch-chrome-profile`,Re=`${b}/DevToolsActivePort`,Ne=`${T().replaceAll("\\","/")}/cdp-pages.json`,ye=`${T().replaceAll("\\","/")}/greedysearch-chrome-mode`,we=`${T().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,$=M(V(),".dm"),v=M($,"greedyconfig"),U=["perplexity","google","chatgpt"],D="gemini";function F(){try{if(O(v)){let t=k(v,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((i)=>typeof i==="string")){let i=e.engines.filter((o)=>w[o]),s=e.engines.filter((o)=>!w[o]);if(s.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${s.join(", ")}
2
- [greedysearch] Available engines: ${Object.keys(w).join(", ")}
3
- `);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${v}, falling back to defaults: ${U.join(", ")}
4
- `)}}}catch{}return U}function z(){try{if(!O($))q($,{recursive:!0});if(!O(v))B(v,JSON.stringify({engines:U,synthesizer:D},null,2)+`
5
- `,"utf8")}catch{}}z();var C=["gemini","chatgpt"];function ee(){try{if(O(v)){let t=k(v,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let i=e.synthesizer.toLowerCase();if(C.includes(i))return i;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${v}
1
+ import{spawn as ve}from"node:child_process";import{basename as B}from"node:path";function H(t=process.env,e=process.execPath){let i=t.GREEDY_SEARCH_NODE||t.NODE_BINARY||t.NODE;if(i?.trim())return i.trim();let o=B(e||"").toLowerCase();if(o==="node"||o==="node.exe")return e;return"node"}import{existsSync as O,mkdirSync as V,readFileSync as k,writeFileSync as F}from"node:fs";import{homedir as z}from"node:os";import{join as M}from"node:path";import{tmpdir as T}from"node:os";var N=`${T().replaceAll("\\","/")}/greedysearch-chrome-profile`,we=`${N}/DevToolsActivePort`,Ue=`${T().replaceAll("\\","/")}/cdp-pages.json`,We=`${T().replaceAll("\\","/")}/greedysearch-chrome-mode`,De=`${T().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,w=M(z(),".dm"),E=M(w,"greedyconfig"),U=["perplexity","google","chatgpt"],W="gemini";function ee(){try{if(O(E)){let t=k(E,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((i)=>typeof i==="string")){let i=e.engines.filter((s)=>y[s]),o=e.engines.filter((s)=>!y[s]);if(o.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${E}: ${o.join(", ")}
2
+ [greedysearch] Available engines: ${Object.keys(y).join(", ")}
3
+ `);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${E}, falling back to defaults: ${U.join(", ")}
4
+ `)}}}catch{}return U}function ie(){try{if(!O(w))V(w,{recursive:!0});if(!O(E))F(E,JSON.stringify({engines:U,synthesizer:W},null,2)+`
5
+ `,"utf8")}catch{}}ie();var C=["gemini","chatgpt"];function te(){try{if(O(E)){let t=k(E,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let i=e.synthesizer.toLowerCase();if(C.includes(i))return i;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${E}
6
6
  [greedysearch] Available synthesizers: ${C.join(", ")}
7
- [greedysearch] Falling back to default: ${D}
8
- `)}}}catch{}return D}var w={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},ie=F();var $e=ee(),Ue=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=b;var te=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],ne=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],se=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],I=["facebook.com","instagram.com","linkedin.com","pinterest.com","tiktok.com","twitter.com","x.com"];function E(t="",e=240){let i=String(t).replaceAll(/\s+/g," ").trim();if(i.length<=e)return i;let s=i.slice(0,e),o=s.lastIndexOf(" ");return o>0?`${s.slice(0,o)}...`:`${s}...`}function L(t=""){let e=E(t,180);if(!e)return"";if(/^https?:\/\//i.test(e))return"";let i=e.split(/\s+/).filter(Boolean).length,s=/[A-Z]/.test(e),o=/\d/.test(e);return e===e.toLowerCase()&&i<=4&&!s&&!o?"":e}function x(t="",e=""){let i=L(t),s=L(e);if(!s)return i;if(!i)return s;let o=/^https?:\/\//i.test(i),r=/^https?:\/\//i.test(s);if(o&&!r)return s;if(!o&&r)return i;return s.length>i.length?s:i}function oe(t){if(!t)return null;try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return null;if(e.hash="",e.hostname=e.hostname.toLowerCase(),e.protocol==="https:"&&e.port==="443"||e.protocol==="http:"&&e.port==="80")e.port="";for(let o of[...e.searchParams.keys()]){let r=o.toLowerCase();if(te.includes(r)||r.startsWith("utm_"))e.searchParams.delete(o)}e.searchParams.sort();let i=e.pathname.replace(/\/{1,10}$/,"")||"/";e.pathname=i;let s=e.toString();return i==="/"?s.replace(/\/$/,""):s}catch{return null}}function le(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function _(t,e){return e.some((i)=>t===i||t.endsWith(`.${i}`))}function ce(t,e="",i=""){let s=e.toLowerCase(),o=i.toLowerCase();if(t==="github.com"||t==="gitlab.com")return"repo";if(t==="arxiv.org"||t==="doi.org"||t==="semanticscholar.org"||t.endsWith(".semanticscholar.org")||o.includes("/paper/")||o.includes("/pdf/"))return"academic";if(_(t,I))return"social";if(_(t,ne))return"community";if(_(t,se))return"news";if(t.startsWith("docs.")||t.startsWith("developer.")||t.startsWith("developers.")||t.startsWith("api.")||s.includes("documentation")||s.includes("docs")||s.includes("reference")||o.includes("/docs/")||o.includes("/reference/")||o.includes("/api/"))return"official-docs";if(t.startsWith("blog.")||o.includes("/blog/"))return"maintainer-blog";return"website"}function re(t){switch(t){case"official-docs":return 5;case"repo":return 4;case"academic":return 4;case"maintainer-blog":return 3;case"website":return 2;case"community":return 1;case"news":return 0;case"social":return-6;default:return 0}}function ae(t){let e=Object.values(t.perEngine||{}).map((i)=>i?.rank||99);return e.length?Math.min(...e):99}var fe=["reddit.com","news.ycombinator.com","lobste.rs"];function R(t){return t.smartScore*3+t.engineCount*5+re(t.sourceType)*2+Math.max(0,7-ae(t))}function ge(t){let e=t.toLowerCase(),i=[];if(e.includes("openai")||e.includes("gpt")||e.includes("chatgpt"))i.push("openai.com","platform.openai.com","help.openai.com");if(e.includes("anthropic")||e.includes("claude"))i.push("anthropic.com","docs.anthropic.com");if(e.includes("bun"))i.push("bun.sh","bun.com");if(e.includes("next.js")||e.includes("nextjs"))i.push("nextjs.org","vercel.com");if(e.includes("playwright"))i.push("playwright.dev");if(e.includes("supabase"))i.push("supabase.com","supabase.io");if(e.includes("prisma"))i.push("prisma.io");if(e.includes("tailwind"))i.push("tailwindcss.com");if(e.includes("vite"))i.push("vitejs.dev","vite.dev");if(e.includes("astro"))i.push("astro.build");if(e.includes("svelte"))i.push("svelte.dev");if(e.includes("solid"))i.push("solidjs.com");if(e.includes("vue")||e.includes("nuxt"))i.push("vuejs.org","nuxt.com");if(e.includes("react")||e.includes("react native"))i.push("react.dev","reactnative.dev");if(e.includes("angular"))i.push("angular.io","angular.dev");if(e.includes("node.js")||e.includes("nodejs"))i.push("nodejs.org","nodejs.dev","npmjs.com");if(/\bgo\b/.test(e)||e.includes("golang"))i.push("go.dev","golang.org","pkg.go.dev");if(e.includes("deno"))i.push("deno.land","deno.com");if(e.includes("fresh"))i.push("fresh.deno.dev");if(e.includes("typescript")||e.includes("ts"))i.push("typescriptlang.org");if(e.includes("python"))i.push("python.org","docs.python.org");if(e.includes("rust"))i.push("rust-lang.org","docs.rs","crates.io");if(e.includes("zig"))i.push("ziglang.org");if(e.includes("docker"))i.push("docker.com","docs.docker.com","hub.docker.com");if(e.includes("kubernetes")||e.includes("k8s"))i.push("kubernetes.io","k8s.io");if(e.includes("postgres")||e.includes("postgresql"))i.push("postgresql.org","neon.tech","supabase.com");if(e.includes("redis"))i.push("redis.io");if(e.includes("sqlite"))i.push("sqlite.org");if(e.includes("cloudflare"))i.push("developers.cloudflare.com","cloudflare.com");if(e.includes("vercel"))i.push("vercel.com","nextjs.org");if(e.includes("netlify"))i.push("netlify.com","docs.netlify.com");if(e.includes("stripe"))i.push("stripe.com","docs.stripe.com");if(e.includes("github"))i.push("github.com","docs.github.com");if(e.includes("gitlab"))i.push("gitlab.com","docs.gitlab.com");if(e.includes("aws"))i.push("aws.amazon.com","docs.aws.amazon.com");if(e.includes("azure"))i.push("azure.microsoft.com","learn.microsoft.com");if(e.includes("gcp")||e.includes("google cloud"))i.push("cloud.google.com","developers.google.com");if(e.includes("gemini")||e.includes("google ai"))i.push("ai.google.dev","developers.google.com");for(let s of I){let o=s.replace(/\.com$/,"");if(e.includes(o))i.push(s)}return[...new Set(i)]}function H(t,e){return t===e||t.endsWith(`.${e}`)}function G(t,e=""){let i=new Map,s=Object.keys(t||{}).filter((n)=>!n.startsWith("_")),o=ge(e);for(let n of s){let c=t[n];if(!c?.sources)continue;for(let a=0;a<c.sources.length;a++){let h=c.sources[a],g=oe(h.url);if(!g||g.length<10)continue;let j=L(h.title||""),u=le(g),d=ce(u,j,g),m=0;if(o.some((y)=>H(u,y)))m+=10;if(d==="official-docs")m+=3;let X=g.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(X))m+=2;let Q=o.some((y)=>H(u,y));if(d==="social"&&!Q)m-=20;if(o.length>0){if(_(u,fe))m-=3;else if(d==="community"&&!_(u,["stackoverflow.com","stackexchange.com"]))m-=1}let p=i.get(g)||{id:"",canonicalUrl:g,displayUrl:h.url||g,domain:u,title:"",engines:[],engineCount:0,perEngine:{},sourceType:d,isOfficial:d==="official-docs",smartScore:0};if(p.title=x(p.title,j),p.displayUrl=p.displayUrl||h.url||g,p.sourceType=p.sourceType||d,p.isOfficial=p.isOfficial||d==="official-docs",p.smartScore=Math.max(p.smartScore,m),!p.engines.includes(n))p.engines.push(n);p.perEngine[n]={rank:a+1,title:x(p.perEngine[n]?.title||"",j)},i.set(g,p)}}let r=Array.from(i.values()).map((n)=>({...n,engineCount:n.engines.length})),f=r.filter((n)=>n.sourceType!=="social"),l=r.filter((n)=>n.sourceType==="social");return f.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),l.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),[...f,...l].slice(0,12).map((n,c)=>({...n,id:`S${c+1}`,title:n.title||n.domain||n.canonicalUrl}))}function pe(t){let e="",i=!1,s=!1;for(let o of String(t)){if(s){e+=o,s=!1;continue}if(o==="\\"){e+=o,s=!0;continue}if(o==='"'){i=!i,e+=o;continue}if(i&&o===`
9
- `)e+="\\n";else if(i&&o==="\r")e+="\\r";else if(i&&o==="\t")e+="\\t";else e+=o}return e}function J(t){if(!t)return null;let e=String(t).trim(),i=e.indexOf("BEGIN_JSON"),s=e.indexOf("END_JSON");if(i!==-1&&s!==-1&&i<s)e=e.slice(i+10,s).trim();else{let l=e.indexOf("{");if(l>0)e=e.slice(l)}let o=[e,e.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/```$/i,"").trim()],r=e.indexOf("{"),f=e.lastIndexOf("}");if(r!==-1&&f!==-1&&r<f)o.push(e.slice(r,f+1));for(let l of[...o]){let n=pe(l);if(n!==l)o.push(n)}for(let l of o)try{return JSON.parse(l)}catch{}return null}function P(t,e,i=""){let s=new Set(e.map((n)=>n.id)),o=["high","medium","low","mixed","conflicting"].includes(t?.agreement?.level)?t.agreement.level:"mixed",r=Array.isArray(t?.claims)?t.claims.map((n)=>({claim:E(n?.claim||"",260),support:["strong","moderate","weak","conflicting"].includes(n?.support)?n.support:"moderate",sourceIds:Array.isArray(n?.sourceIds)?n.sourceIds.filter((c)=>s.has(c)):[]})).filter((n)=>n.claim):[],f=Array.isArray(t?.recommendedSources)?t.recommendedSources.filter((n)=>s.has(n)).slice(0,6):[],l="";if(i){let n=i.indexOf("{"),c=i.lastIndexOf("}");if(n!==-1&&c!==-1&&n<c)l=i.slice(n,c+1);else l=i}return{answer:E(t?.answer||l||i,4000),agreement:{level:o,summary:E(t?.agreement?.summary||"",280)},differences:Array.isArray(t?.differences)?t.differences.map((n)=>E(n,220)).filter(Boolean).slice(0,5):[],caveats:Array.isArray(t?.caveats)?t.caveats.map((n)=>E(n,220)).filter(Boolean).slice(0,5):[],claims:r,recommendedSources:f}}function Y(t,e,i,{grounded:s=!1}={}){let o={};for(let l of["perplexity","bing","google"]){let n=e[l];if(!n)continue;if(n.error){o[l]={status:"error",error:String(n.error)};continue}o[l]={status:"ok",answer:E(n.answer||"",s?4500:2200),sourceIds:i.filter((c)=>c.engines.includes(l)).sort((c,a)=>(c.perEngine[l]?.rank||99)-(a.perEngine[l]?.rank||99)).map((c)=>c.id).slice(0,6)}}let r=s?700:300,f=i.slice(0,s?10:8).map((l)=>({id:l.id,title:l.title,domain:l.domain,canonicalUrl:l.canonicalUrl,sourceType:l.sourceType,isOfficial:l.isOfficial,engines:l.engines,engineCount:l.engineCount,fetch:l.fetch?.attempted?{ok:l.fetch.ok,publishedTime:l.fetch.publishedTime||"",byline:l.fetch.byline||"",snippet:E(l.fetch.snippet||"",r)}:void 0}));return["You are a research synthesizer. Combine these search engine results into a single authoritative answer.","",`Query: ${t}`,"",`Engine summaries:
10
- ${JSON.stringify(o,null,2)}`,"",`Source registry:
7
+ [greedysearch] Falling back to default: ${W}
8
+ `)}}}catch{}return W}var y={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},ne=ee();var Le=te(),He=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=N;var oe=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],se=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],le=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],J=["facebook.com","instagram.com","linkedin.com","pinterest.com","tiktok.com","twitter.com","x.com"];function v(t="",e=240){let i=String(t).replaceAll(/\s+/g," ").trim();if(i.length<=e)return i;let o=i.slice(0,e),s=o.lastIndexOf(" ");return s>0?`${o.slice(0,s)}...`:`${o}...`}function D(t=""){let e=v(t,180);if(!e)return"";if(/^https?:\/\//i.test(e))return"";let i=e.split(/\s+/).filter(Boolean).length,o=/[A-Z]/.test(e),s=/\d/.test(e);return e===e.toLowerCase()&&i<=4&&!o&&!s?"":e}function G(t="",e=""){let i=D(t),o=D(e);if(!o)return i;if(!i)return o;let s=/^https?:\/\//i.test(i),r=/^https?:\/\//i.test(o);if(s&&!r)return o;if(!s&&r)return i;return o.length>i.length?o:i}function ce(t){if(!t)return null;try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return null;if(e.hash="",e.hostname=e.hostname.toLowerCase(),e.protocol==="https:"&&e.port==="443"||e.protocol==="http:"&&e.port==="80")e.port="";for(let s of[...e.searchParams.keys()]){let r=s.toLowerCase();if(oe.includes(r)||r.startsWith("utm_"))e.searchParams.delete(s)}e.searchParams.sort();let i=e.pathname.replace(/\/{1,10}$/,"")||"/";e.pathname=i;let o=e.toString();return i==="/"?o.replace(/\/$/,""):o}catch{return null}}function re(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function _(t,e){return e.some((i)=>t===i||t.endsWith(`.${i}`))}function ae(t,e="",i=""){let o=e.toLowerCase(),s=i.toLowerCase();if(t==="github.com"||t==="gitlab.com")return"repo";if(t==="arxiv.org"||t==="doi.org"||t==="semanticscholar.org"||t.endsWith(".semanticscholar.org")||s.includes("/paper/")||s.includes("/pdf/"))return"academic";if(_(t,J))return"social";if(_(t,se))return"community";if(_(t,le))return"news";if(t.startsWith("docs.")||t.startsWith("developer.")||t.startsWith("developers.")||t.startsWith("api.")||o.includes("documentation")||o.includes("docs")||o.includes("reference")||s.includes("/docs/")||s.includes("/reference/")||s.includes("/api/"))return"official-docs";if(t.startsWith("blog.")||s.includes("/blog/"))return"maintainer-blog";return"website"}function fe(t){switch(t){case"official-docs":return 5;case"repo":return 4;case"academic":return 4;case"maintainer-blog":return 3;case"website":return 2;case"community":return 1;case"news":return 0;case"social":return-6;default:return 0}}function ge(t){let e=Object.values(t.perEngine||{}).map((i)=>i?.rank||99);return e.length?Math.min(...e):99}var pe=["reddit.com","news.ycombinator.com","lobste.rs"];function R(t){return t.smartScore*3+t.engineCount*5+fe(t.sourceType)*2+Math.max(0,7-ge(t))}function ue(t){let e=t.toLowerCase(),i=[];if(e.includes("openai")||e.includes("gpt")||e.includes("chatgpt"))i.push("openai.com","platform.openai.com","help.openai.com");if(e.includes("anthropic")||e.includes("claude"))i.push("anthropic.com","docs.anthropic.com");if(e.includes("bun"))i.push("bun.sh","bun.com");if(e.includes("next.js")||e.includes("nextjs"))i.push("nextjs.org","vercel.com");if(e.includes("playwright"))i.push("playwright.dev");if(e.includes("supabase"))i.push("supabase.com","supabase.io");if(e.includes("prisma"))i.push("prisma.io");if(e.includes("tailwind"))i.push("tailwindcss.com");if(e.includes("vite"))i.push("vitejs.dev","vite.dev");if(e.includes("astro"))i.push("astro.build");if(e.includes("svelte"))i.push("svelte.dev");if(e.includes("solid"))i.push("solidjs.com");if(e.includes("vue")||e.includes("nuxt"))i.push("vuejs.org","nuxt.com");if(e.includes("react")||e.includes("react native"))i.push("react.dev","reactnative.dev");if(e.includes("angular"))i.push("angular.io","angular.dev");if(e.includes("node.js")||e.includes("nodejs"))i.push("nodejs.org","nodejs.dev","npmjs.com");if(/\bgo\b/.test(e)||e.includes("golang"))i.push("go.dev","golang.org","pkg.go.dev");if(e.includes("deno"))i.push("deno.land","deno.com");if(e.includes("fresh"))i.push("fresh.deno.dev");if(e.includes("typescript")||e.includes("ts"))i.push("typescriptlang.org");if(e.includes("python"))i.push("python.org","docs.python.org");if(e.includes("rust"))i.push("rust-lang.org","docs.rs","crates.io");if(e.includes("zig"))i.push("ziglang.org");if(e.includes("docker"))i.push("docker.com","docs.docker.com","hub.docker.com");if(e.includes("kubernetes")||e.includes("k8s"))i.push("kubernetes.io","k8s.io");if(e.includes("postgres")||e.includes("postgresql"))i.push("postgresql.org","neon.tech","supabase.com");if(e.includes("redis"))i.push("redis.io");if(e.includes("sqlite"))i.push("sqlite.org");if(e.includes("cloudflare"))i.push("developers.cloudflare.com","cloudflare.com");if(e.includes("vercel"))i.push("vercel.com","nextjs.org");if(e.includes("netlify"))i.push("netlify.com","docs.netlify.com");if(e.includes("stripe"))i.push("stripe.com","docs.stripe.com");if(e.includes("github"))i.push("github.com","docs.github.com");if(e.includes("gitlab"))i.push("gitlab.com","docs.gitlab.com");if(e.includes("aws"))i.push("aws.amazon.com","docs.aws.amazon.com");if(e.includes("azure"))i.push("azure.microsoft.com","learn.microsoft.com");if(e.includes("gcp")||e.includes("google cloud"))i.push("cloud.google.com","developers.google.com");if(e.includes("gemini")||e.includes("google ai"))i.push("ai.google.dev","developers.google.com");for(let o of J){let s=o.replace(/\.com$/,"");if(e.includes(s))i.push(o)}return[...new Set(i)]}function I(t,e){return t===e||t.endsWith(`.${e}`)}function Y(t,e=""){let i=new Map,o=Object.keys(t||{}).filter((n)=>!n.startsWith("_")),s=ue(e);for(let n of o){let c=t[n];if(!c?.sources)continue;for(let a=0;a<c.sources.length;a++){let h=c.sources[a],g=ce(h.url);if(!g||g.length<10)continue;let j=D(h.title||""),u=re(g),d=ae(u,j,g),m=0;if(s.some(($)=>I(u,$)))m+=10;if(d==="official-docs")m+=3;let Q=g.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(Q))m+=2;let q=s.some(($)=>I(u,$));if(d==="social"&&!q)m-=20;if(s.length>0){if(_(u,pe))m-=3;else if(d==="community"&&!_(u,["stackoverflow.com","stackexchange.com"]))m-=1}let p=i.get(g)||{id:"",canonicalUrl:g,displayUrl:h.url||g,domain:u,title:"",engines:[],engineCount:0,perEngine:{},sourceType:d,isOfficial:d==="official-docs",smartScore:0};if(p.title=G(p.title,j),p.displayUrl=p.displayUrl||h.url||g,p.sourceType=p.sourceType||d,p.isOfficial=p.isOfficial||d==="official-docs",p.smartScore=Math.max(p.smartScore,m),!p.engines.includes(n))p.engines.push(n);p.perEngine[n]={rank:a+1,title:G(p.perEngine[n]?.title||"",j)},i.set(g,p)}}let r=Array.from(i.values()).map((n)=>({...n,engineCount:n.engines.length})),f=r.filter((n)=>n.sourceType!=="social"),l=r.filter((n)=>n.sourceType==="social");return f.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),l.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),[...f,...l].slice(0,12).map((n,c)=>({...n,id:`S${c+1}`,title:n.title||n.domain||n.canonicalUrl}))}function me(t){let e="",i=!1,o=!1;for(let s of String(t)){if(o){e+=s,o=!1;continue}if(s==="\\"){e+=s,o=!0;continue}if(s==='"'){i=!i,e+=s;continue}if(i&&s===`
9
+ `)e+="\\n";else if(i&&s==="\r")e+="\\r";else if(i&&s==="\t")e+="\\t";else e+=s}return e}function Z(t){if(!t)return null;let e=String(t).trim(),i=e.indexOf("BEGIN_JSON"),o=e.indexOf("END_JSON");if(i!==-1&&o!==-1&&i<o)e=e.slice(i+10,o).trim();else{let l=e.indexOf("{");if(l>0)e=e.slice(l)}let s=[e,e.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/```$/i,"").trim()],r=e.indexOf("{"),f=e.lastIndexOf("}");if(r!==-1&&f!==-1&&r<f)s.push(e.slice(r,f+1));for(let l of[...s]){let n=me(l);if(n!==l)s.push(n)}for(let l of s)try{return JSON.parse(l)}catch{}return null}function x(t,e,i=""){let o=new Set(e.map((n)=>n.id)),s=["high","medium","low","mixed","conflicting"].includes(t?.agreement?.level)?t.agreement.level:"mixed",r=Array.isArray(t?.claims)?t.claims.map((n)=>({claim:v(n?.claim||"",260),support:["strong","moderate","weak","conflicting"].includes(n?.support)?n.support:"moderate",sourceIds:Array.isArray(n?.sourceIds)?n.sourceIds.filter((c)=>o.has(c)):[]})).filter((n)=>n.claim):[],f=Array.isArray(t?.recommendedSources)?t.recommendedSources.filter((n)=>o.has(n)).slice(0,6):[],l="";if(i){let n=i.indexOf("{"),c=i.lastIndexOf("}");if(n!==-1&&c!==-1&&n<c)l=i.slice(n,c+1);else l=i}return{answer:v(t?.answer||l||i,4000),agreement:{level:s,summary:v(t?.agreement?.summary||"",280)},differences:Array.isArray(t?.differences)?t.differences.map((n)=>v(n,220)).filter(Boolean).slice(0,5):[],caveats:Array.isArray(t?.caveats)?t.caveats.map((n)=>v(n,220)).filter(Boolean).slice(0,5):[],claims:r,recommendedSources:f}}function A(t,e,i,{grounded:o=!1}={}){let s={};for(let l of["perplexity","bing","google"]){let n=e[l];if(!n)continue;if(n.error){s[l]={status:"error",error:String(n.error)};continue}s[l]={status:"ok",answer:v(n.answer||"",o?4500:2200),sourceIds:i.filter((c)=>c.engines.includes(l)).sort((c,a)=>(c.perEngine[l]?.rank||99)-(a.perEngine[l]?.rank||99)).map((c)=>c.id).slice(0,6)}}let r=o?700:300,f=i.slice(0,o?10:8).map((l)=>({id:l.id,title:l.title,domain:l.domain,canonicalUrl:l.canonicalUrl,sourceType:l.sourceType,isOfficial:l.isOfficial,engines:l.engines,engineCount:l.engineCount,fetch:l.fetch?.attempted?{ok:l.fetch.ok,publishedTime:l.fetch.publishedTime||"",byline:l.fetch.byline||"",snippet:v(l.fetch.snippet||"",r)}:void 0}));return["You are a research synthesizer. Combine these search engine results into a single authoritative answer.","",`Query: ${t}`,"",`Engine summaries:
10
+ ${JSON.stringify(s,null,2)}`,"",`Source registry:
11
11
  ${JSON.stringify(f,null,2)}`,"","Instructions:","- Write a clear, direct answer in markdown (use headers/bullets where they help readability)","- Cite sources inline as [S1], [S2] etc. when making specific claims","- Prefer sources with content (fetch.ok=true and non-empty snippet) for citations","- Note where the engines agree or meaningfully disagree","- List any important caveats or limitations","- recommendedSources: the 2-4 source IDs most worth reading for this query","","Respond ONLY with a JSON object wrapped in BEGIN_JSON / END_JSON markers:","","BEGIN_JSON",JSON.stringify({answer:"<your markdown answer here>",agreement:{level:"high|medium|mixed|conflicting",summary:"<one sentence>"},differences:["<notable difference between engines, if any>"],caveats:["<important caveat or limitation>"],recommendedSources:["S1","S2"]},null,2),"END_JSON"].join(`
12
- `)}import{existsSync as Z}from"node:fs";import{dirname as ue,join as N}from"node:path";import{fileURLToPath as me}from"node:url";function S(t){return me(new URL(".",t)).replace(/^\/([A-Z]:)/,"$1")}function he(t,e=Z){let i=new Set;for(let s of t.filter(Boolean)){if(i.has(s))continue;if(i.add(s),e(s))return s}return t.filter(Boolean).at(-1)}function A(t,{moduleDir:e,entrypoint:i=process.argv[1],env:s=process.env,exists:o=Z}={}){let r=i?ue(i):null,f=s.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,l=[e?N(e,"..","..","extractors",t):null,e?N(e,"..","extractors",t):null,f?N(f,"extractors",t):null,r?N(r,"..","extractors",t):null];return he(l,o)}var ve=S(import.meta.url),Ee={gemini:"gemini.mjs",chatgpt:"chatgpt.mjs"},je={gemini:"https://gemini.google.com/app",chatgpt:"https://chatgpt.com/"};function W(t="gemini"){let e=String(t||"gemini").toLowerCase();if(e==="gem")return"gemini";if(e==="gpt")return"chatgpt";return e}function Ae(t="gemini"){return je[W(t)]||"about:blank"}async function K(t,e,{tabPrefix:i=null,timeoutMs:s=180000,visible:o=null}={}){let r=W(t),f=Ee[r];if(!f||!C.includes(r))throw Error(`Unsupported synthesizer "${t}". Supported: ${C.join(", ")}`);return new Promise((l,n)=>{let c=i?["--tab",String(i)]:[],a=A(f,{moduleDir:ve}),h={...process.env,CDP_PROFILE_DIR:b};if(o!==!0)delete h.GREEDY_SEARCH_VISIBLE,delete h.GREEDY_SEARCH_ALWAYS_VISIBLE;else h.GREEDY_SEARCH_VISIBLE="1",h.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let g=de(nodeRuntimeCommand(),[a,"--stdin",...c],{stdio:["pipe","pipe","pipe"],env:h});g.stdin.write(e),g.stdin.end();let j="",u="";g.stdout.on("data",(m)=>j+=m),g.stderr.on("data",(m)=>u+=m);let d=setTimeout(()=>{g.kill(),n(Error(`${r} prompt timed out after ${s/1000}s`))},s);g.on("close",(m)=>{if(clearTimeout(d),m!==0){n(Error(u.trim()||`${r} extractor failed`));return}try{l(JSON.parse(j.trim()))}catch{n(Error(`bad JSON from ${r}: ${j.slice(0,100)}`))}})})}async function Ke(t,e={}){return K("gemini",t,e)}async function Ce(t,e,{grounded:i=!1,tabPrefix:s=null,visible:o=null,synthesizer:r="gemini"}={}){let f=W(r),l=Array.isArray(e._sources)?e._sources:G(e),n=Y(t,e,l,{grounded:i}),c=await K(f,n,{tabPrefix:s,timeoutMs:180000,visible:o}),a=J(c.answer||""),g=a&&["answer","agreement","claims","differences","caveats"].some((u)=>(u in a));if(a&&["perplexity","bing","google","chatgpt","gemini"].some((u)=>(u in a))&&!g)a=null;return{...P(a,l,c.answer||""),rawAnswer:c.answer||"",synthesizedBy:f,synthesizerSources:c.sources||[],geminiSources:f==="gemini"?c.sources||[]:[]}}async function Xe(t,e,i={}){return Ce(t,e,{...i,synthesizer:"gemini"})}export{Xe as synthesizeWithGemini,Ce as synthesizeResults,K as runSynthesisPrompt,Ke as runGeminiPrompt,W as normalizeSynthesizer,Ae as getSynthesisStartUrl};
12
+ `)}import{existsSync as S}from"node:fs";import{dirname as he,join as b}from"node:path";import{fileURLToPath as de}from"node:url";function P(t){return de(new URL(".",t)).replace(/^\/([A-Z]:)/,"$1")}function Ee(t,e=S){let i=new Set;for(let o of t.filter(Boolean)){if(i.has(o))continue;if(i.add(o),e(o))return o}return t.filter(Boolean).at(-1)}function K(t,{moduleDir:e,entrypoint:i=process.argv[1],env:o=process.env,exists:s=S}={}){let r=i?he(i):null,f=o.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,l=[e?b(e,"..","..","extractors",t):null,e?b(e,"..","extractors",t):null,f?b(f,"extractors",t):null,r?b(r,"..","extractors",t):null];return Ee(l,s)}var je=P(import.meta.url),Ce={gemini:"gemini.mjs",chatgpt:"chatgpt.mjs"},_e={gemini:"https://gemini.google.com/app",chatgpt:"https://chatgpt.com/"};function L(t="gemini"){let e=String(t||"gemini").toLowerCase();if(e==="gem")return"gemini";if(e==="gpt")return"chatgpt";return e}function Be(t="gemini"){return _e[L(t)]||"about:blank"}async function X(t,e,{tabPrefix:i=null,timeoutMs:o=180000,visible:s=null}={}){let r=L(t),f=Ce[r];if(!f||!C.includes(r))throw Error(`Unsupported synthesizer "${t}". Supported: ${C.join(", ")}`);return new Promise((l,n)=>{let c=i?["--tab",String(i)]:[],a=K(f,{moduleDir:je}),h={...process.env,CDP_PROFILE_DIR:N};if(s!==!0)delete h.GREEDY_SEARCH_VISIBLE,delete h.GREEDY_SEARCH_ALWAYS_VISIBLE;else h.GREEDY_SEARCH_VISIBLE="1",h.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let g=ve(H(),[a,"--stdin",...c],{stdio:["pipe","pipe","pipe"],env:h});g.stdin.write(e),g.stdin.end();let j="",u="";g.stdout.on("data",(m)=>j+=m),g.stderr.on("data",(m)=>u+=m);let d=setTimeout(()=>{g.kill(),n(Error(`${r} prompt timed out after ${o/1000}s`))},o);g.on("close",(m)=>{if(clearTimeout(d),m!==0){n(Error(u.trim()||`${r} extractor failed`));return}try{l(JSON.parse(j.trim()))}catch{n(Error(`bad JSON from ${r}: ${j.slice(0,100)}`))}})})}async function Ve(t,e={}){return X("gemini",t,e)}async function Oe(t,e,{grounded:i=!1,tabPrefix:o=null,visible:s=null,synthesizer:r="gemini"}={}){let f=L(r),l=Array.isArray(e._sources)?e._sources:Y(e),n=A(t,e,l,{grounded:i}),c=await X(f,n,{tabPrefix:o,timeoutMs:180000,visible:s}),a=Z(c.answer||""),g=a&&["answer","agreement","claims","differences","caveats"].some((u)=>(u in a));if(a&&["perplexity","bing","google","chatgpt","gemini"].some((u)=>(u in a))&&!g)a=null;return{...x(a,l,c.answer||""),rawAnswer:c.answer||"",synthesizedBy:f,synthesizerSources:c.sources||[],geminiSources:f==="gemini"?c.sources||[]:[]}}async function Fe(t,e,i={}){return Oe(t,e,{...i,synthesizer:"gemini"})}export{Fe as synthesizeWithGemini,Oe as synthesizeResults,X as runSynthesisPrompt,Ve as runGeminiPrompt,L as normalizeSynthesizer,Be as getSynthesisStartUrl};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckmind/dm-darwin-x64",
3
- "version": "0.43.8",
3
+ "version": "0.48.5",
4
4
  "description": "DuckMind (dm) binary payload for darwin x64",
5
5
  "license": "MIT",
6
6
  "os": [