@duckmind/dm-darwin-x64 0.43.2 → 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.
- package/dm +0 -0
- package/extensions/.dm-extensions.json +4 -3
- package/extensions/greedysearch-dm/bin/search.mjs +135 -135
- package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/research.mjs +100 -100
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{spawn as
|
|
2
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
3
|
-
`);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
4
|
-
`)}}}catch{}return U}function
|
|
5
|
-
`,"utf8")}catch{}}
|
|
6
|
-
[greedysearch] Available synthesizers: ${
|
|
7
|
-
[greedysearch] Falling back to default: ${
|
|
8
|
-
`)}}}catch{}return
|
|
9
|
-
`)e+="\\n";else if(i&&o==="\r")e+="\\r";else if(i&&o==="\t")e+="\\t";else e+=o}return e}function
|
|
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
|
-
`)}
|
|
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};
|