@duckmind/dm-darwin-x64 0.43.0 → 0.43.4

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 ae}from"node:child_process";import{join as fe}from"node:path";import{existsSync as _,mkdirSync as P,readFileSync as L,writeFileSync as Q}from"node:fs";import{homedir as X}from"node:os";import{join as D}from"node:path";import{tmpdir as b}from"node:os";var w=`${b().replaceAll("\\","/")}/greedysearch-chrome-profile`,Ce=`${w}/DevToolsActivePort`,je=`${b().replaceAll("\\","/")}/cdp-pages.json`,Oe=`${b().replaceAll("\\","/")}/greedysearch-chrome-mode`,_e=`${b().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,k=D(X(),".dm"),d=D(k,"greedyconfig"),U=["perplexity","google","chatgpt"],y="gemini";function q(){try{if(_(d)){let t=L(d,"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)=>N[o]),s=e.engines.filter((o)=>!N[o]);if(s.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${d}: ${s.join(", ")}
2
- [greedysearch] Available engines: ${Object.keys(N).join(", ")}
3
- `);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${d}, falling back to defaults: ${U.join(", ")}
4
- `)}}}catch{}return U}function V(){try{if(!_(k))P(k,{recursive:!0});if(!_(d))Q(d,JSON.stringify({engines:U,synthesizer:y},null,2)+`
5
- `,"utf8")}catch{}}V();var j=["gemini","chatgpt"];function B(){try{if(_(d)){let t=L(d,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let i=e.synthesizer.toLowerCase();if(j.includes(i))return i;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${d}
6
- [greedysearch] Available synthesizers: ${j.join(", ")}
7
- [greedysearch] Falling back to default: ${y}
8
- `)}}}catch{}return y}var N={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"},S=q();var be=B(),we=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=w;var F=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],z=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],ee=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],G=["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 s=i.slice(0,e),o=s.lastIndexOf(" ");return o>0?`${s.slice(0,o)}...`:`${s}...`}function R(t=""){let e=v(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 M(t="",e=""){let i=R(t),s=R(e);if(!s)return i;if(!i)return s;let o=/^https?:\/\//i.test(i),a=/^https?:\/\//i.test(s);if(o&&!a)return s;if(!o&&a)return i;return s.length>i.length?s:i}function ie(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 a=o.toLowerCase();if(F.includes(a)||a.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 te(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function O(t,e){return e.some((i)=>t===i||t.endsWith(`.${i}`))}function ne(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(O(t,G))return"social";if(O(t,z))return"community";if(O(t,ee))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 oe(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 se(t){let e=Object.values(t.perEngine||{}).map((i)=>i?.rank||99);return e.length?Math.min(...e):99}var le=["reddit.com","news.ycombinator.com","lobste.rs"];function T(t){return t.smartScore*3+t.engineCount*5+oe(t.sourceType)*2+Math.max(0,7-se(t))}function ce(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 G){let o=s.replace(/\.com$/,"");if(e.includes(o))i.push(s)}return[...new Set(i)]}function J(t,e){return t===e||t.endsWith(`.${e}`)}function H(t,e=""){let i=new Map,s=Object.keys(t||{}).filter((n)=>!n.startsWith("_")),o=ce(e);for(let n of s){let c=t[n];if(!c?.sources)continue;for(let r=0;r<c.sources.length;r++){let u=c.sources[r],g=ie(u.url);if(!g||g.length<10)continue;let E=R(u.title||""),h=te(g),m=ne(h,E,g),C=0;if(o.some(($)=>J(h,$)))C+=10;if(m==="official-docs")C+=3;let A=g.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(A))C+=2;let K=o.some(($)=>J(h,$));if(m==="social"&&!K)C-=20;if(o.length>0){if(O(h,le))C-=3;else if(m==="community"&&!O(h,["stackoverflow.com","stackexchange.com"]))C-=1}let p=i.get(g)||{id:"",canonicalUrl:g,displayUrl:u.url||g,domain:h,title:"",engines:[],engineCount:0,perEngine:{},sourceType:m,isOfficial:m==="official-docs",smartScore:0};if(p.title=M(p.title,E),p.displayUrl=p.displayUrl||u.url||g,p.sourceType=p.sourceType||m,p.isOfficial=p.isOfficial||m==="official-docs",p.smartScore=Math.max(p.smartScore,C),!p.engines.includes(n))p.engines.push(n);p.perEngine[n]={rank:r+1,title:M(p.perEngine[n]?.title||"",E)},i.set(g,p)}}let a=Array.from(i.values()).map((n)=>({...n,engineCount:n.engines.length})),f=a.filter((n)=>n.sourceType!=="social"),l=a.filter((n)=>n.sourceType==="social");return f.sort((n,c)=>{let r=T(c)-T(n);if(r!==0)return r;return n.domain.localeCompare(c.domain)}),l.sort((n,c)=>{let r=T(c)-T(n);if(r!==0)return r;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 re(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 I(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()],a=e.indexOf("{"),f=e.lastIndexOf("}");if(a!==-1&&f!==-1&&a<f)o.push(e.slice(a,f+1));for(let l of[...o]){let n=re(l);if(n!==l)o.push(n)}for(let l of o)try{return JSON.parse(l)}catch{}return null}function x(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",a=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)=>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:v(t?.answer||l||i,4000),agreement:{level:o,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:a,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:v(n.answer||"",s?4500:2200),sourceIds:i.filter((c)=>c.engines.includes(l)).sort((c,r)=>(c.perEngine[l]?.rank||99)-(r.perEngine[l]?.rank||99)).map((c)=>c.id).slice(0,6)}}let a=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:v(l.fetch.snippet||"",a)}:void 0}));return["You are a research synthesizer. Combine these search engine results into a single authoritative answer.","",`Query: ${t}`,"",`Engine summaries:
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}
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
10
  ${JSON.stringify(o,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
- `)}var ge=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),pe={gemini:"gemini.mjs",chatgpt:"chatgpt.mjs"},me={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 Me(t="gemini"){return me[W(t)]||"about:blank"}async function Z(t,e,{tabPrefix:i=null,timeoutMs:s=180000,visible:o=null}={}){let a=W(t),f=pe[a];if(!f||!j.includes(a))throw Error(`Unsupported synthesizer "${t}". Supported: ${j.join(", ")}`);return new Promise((l,n)=>{let c=i?["--tab",String(i)]:[],r={...process.env,CDP_PROFILE_DIR:w};if(o!==!0)delete r.GREEDY_SEARCH_VISIBLE,delete r.GREEDY_SEARCH_ALWAYS_VISIBLE;else r.GREEDY_SEARCH_VISIBLE="1",r.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let u=ae(nodeRuntimeCommand(),[fe(ge,"..","..","extractors",f),"--stdin",...c],{stdio:["pipe","pipe","pipe"],env:r});u.stdin.write(e),u.stdin.end();let g="",E="";u.stdout.on("data",(m)=>g+=m),u.stderr.on("data",(m)=>E+=m);let h=setTimeout(()=>{u.kill(),n(Error(`${a} prompt timed out after ${s/1000}s`))},s);u.on("close",(m)=>{if(clearTimeout(h),m!==0){n(Error(E.trim()||`${a} extractor failed`));return}try{l(JSON.parse(g.trim()))}catch{n(Error(`bad JSON from ${a}: ${g.slice(0,100)}`))}})})}async function Je(t,e={}){return Z("gemini",t,e)}async function ue(t,e,{grounded:i=!1,tabPrefix:s=null,visible:o=null,synthesizer:a="gemini"}={}){let f=W(a),l=Array.isArray(e._sources)?e._sources:H(e),n=Y(t,e,l,{grounded:i}),c=await Z(f,n,{tabPrefix:s,timeoutMs:180000,visible:o}),r=I(c.answer||""),g=r&&["answer","agreement","claims","differences","caveats"].some((h)=>(h in r));if(r&&["perplexity","bing","google","chatgpt","gemini"].some((h)=>(h in r))&&!g)r=null;return{...x(r,l,c.answer||""),rawAnswer:c.answer||"",synthesizedBy:f,synthesizerSources:c.sources||[],geminiSources:f==="gemini"?c.sources||[]:[]}}async function Ge(t,e,i={}){return ue(t,e,{...i,synthesizer:"gemini"})}export{Ge as synthesizeWithGemini,ue as synthesizeResults,Z as runSynthesisPrompt,Je as runGeminiPrompt,W as normalizeSynthesizer,Me as getSynthesisStartUrl};
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};
@@ -0,0 +1 @@
1
+ import{existsSync as c}from"node:fs";import{platform as s}from"node:os";function C(o=s()){if(o==="win32")return{cloak:["C:/Program Files/CloakBrowser/CloakBrowser.exe","C:/Program Files (x86)/CloakBrowser/CloakBrowser.exe"],chrome:["C:/Program Files/Google/Chrome/Application/chrome.exe","C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"]};if(o==="darwin")return{cloak:["/Applications/CloakBrowser.app/Contents/MacOS/CloakBrowser","/Applications/Cloak Browser.app/Contents/MacOS/CloakBrowser"],chrome:["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium"]};return{cloak:["/usr/bin/cloakbrowser","/usr/local/bin/cloakbrowser","/opt/CloakBrowser/CloakBrowser"],chrome:["/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium","/snap/bin/chromium"]}}function l(o,e=c){return o.find((r)=>r&&e(r))||null}function p(o,e){for(let r of e){let a=o[r]?.trim();if(a)return{key:r,path:a}}return null}function m(o,e){if(o==="chrome"||e==="CHROME_PATH")return"Chrome";if(o==="cloak"||e==="DM_CUA_CLOAK_PATH"||e==="CLOAKBROWSER_BINARY_PATH")return"CloakBrowser";return"browser"}function _({env:o=process.env,platformName:e=s(),exists:r=c}={}){let a=(o.GREEDY_SEARCH_BROWSER||o.DM_CUA_BROWSER||"auto").toLowerCase(),n=p(o,a==="chrome"?["GREEDY_SEARCH_BROWSER_PATH","DM_CUA_BROWSER_PATH","CHROME_PATH"]:["GREEDY_SEARCH_BROWSER_PATH","DM_CUA_BROWSER_PATH","DM_CUA_CLOAK_PATH","CLOAKBROWSER_BINARY_PATH","CHROME_PATH"]);if(n)return{path:n.path,label:m(a,n.key)};let t=C(e);if(a==="cloak")return{path:l(t.cloak,r),label:"CloakBrowser"};if(a==="chrome")return{path:l(t.chrome,r),label:"Chrome"};let i=l(t.cloak,r);return{path:i||l(t.chrome,r),label:i?"CloakBrowser":"Chrome"}}export{_ as resolveBrowser,l as firstExisting,C as browserCandidates};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckmind/dm-darwin-x64",
3
- "version": "0.43.0",
3
+ "version": "0.43.4",
4
4
  "description": "DuckMind (dm) binary payload for darwin x64",
5
5
  "license": "MIT",
6
6
  "os": [