@duckmind/dm-windows-x64 0.59.9 → 0.60.2
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/extensions/.dm-extensions.json +4 -4
- package/extensions/dm-cua/bin/browser-cua.mjs +4 -4
- package/extensions/dm-cua/index.js +3 -3
- package/extensions/dm-cua/src/browser-cua-lib.mjs +3 -3
- package/extensions/greedysearch-dm/bin/mcp.mjs +52 -52
- package/extensions/greedysearch-dm/bin/search.mjs +130 -131
- package/extensions/greedysearch-dm/extractors/consensus.mjs +42 -43
- package/extensions/greedysearch-dm/extractors/gemini.mjs +52 -53
- package/extensions/greedysearch-dm/extractors/logically.mjs +33 -34
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +9 -10
- package/extensions/greedysearch-dm/src/search/chrome.mjs +21 -22
- package/extensions/greedysearch-dm/src/search/engines.mjs +7 -7
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +48 -48
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +119 -119
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +7 -7
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +125 -125
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +11 -11
- package/package.json +1 -1
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
2
|
+
import{createRequire as l0}from"node:module";var u0=Object.defineProperty;var m0=($)=>$;function c0($,Q){this[$]=m0.bind(null,Q)}var i0=($,Q)=>{for(var X in Q)u0($,X,{get:Q[X],enumerable:!0,configurable:!0,set:c0.bind(Q,X)})};var U=($,Q)=>()=>($&&(Q=$($=0)),Q);var L=l0(import.meta.url);import{basename as d0}from"node:path";function F($=process.env,Q=process.execPath){let X=$.GREEDY_SEARCH_NODE||$.NODE_BINARY||$.NODE;if(X?.trim())return X.trim();let W=d0(Q||"").toLowerCase();if(W==="node"||W==="node.exe")return Q;return"node"}var P=()=>{};async function n0(){if(y)return y;let[{Readability:$},{JSDOM:Q},{default:X}]=await Promise.all([import("@mozilla/readability"),import("jsdom"),import("turndown")]),W=new X({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});return W.addRule("removeDataUrls",{filter:(Z)=>Z.tagName==="IMG"&&Z.getAttribute("src")?.startsWith("data:"),replacement:()=>""}),y={Readability:$,JSDOM:Q,turndown:W},y}function r0($){if(!$||$.includes(":"))return null;let Q=$.split(".");if(Q.length<1||Q.length>4)return null;if(!Q.every((Z)=>a0.test(Z)))return null;let X=Q.map((Z)=>{if(/^0x/i.test(Z))return parseInt(Z,16);if(/^0[0-7]+$/.test(Z))return parseInt(Z,8);return parseInt(Z,10)});if(X.some((Z)=>!Number.isFinite(Z)||Z<0))return null;let W;if(X.length===1){if(X[0]>4294967295)return null;W=[X[0]>>>24&255,X[0]>>>16&255,X[0]>>>8&255,X[0]&255]}else if(X.length===2){if(X[0]>255||X[1]>16777215)return null;W=[X[0],X[1]>>>16&255,X[1]>>>8&255,X[1]&255]}else if(X.length===3){if(X[0]>255||X[1]>255||X[2]>65535)return null;W=[X[0],X[1],X[2]>>>8&255,X[2]&255]}else{if(X.some((Z)=>Z>255))return null;W=X}return W.join(".")}function t0($){let Q=$.match(o0);if(Q)return`${Q[1]}.${Q[2]}.${Q[3]}.${Q[4]}`;let X=$.match(s0);if(X){let W=parseInt(X[1],16),Z=parseInt(X[2],16);if(W>65535||Z>65535)return null;return[W>>>8&255,W&255,Z>>>8&255,Z&255].join(".")}return null}function $0($){return Z0.some((Q)=>Q.test($))}function J0($={}){return{...W0,...$}}function S($){try{if(typeof $!=="string"||!$.trim())return{blocked:!0,reason:"URL must be a non-empty string"};let Q=new URL($);if(Q.protocol!=="http:"&&Q.protocol!=="https:")return{blocked:!0,reason:`Protocol not allowed: ${Q.protocol}`};let X=Q.hostname.toLowerCase();for(let Z of Z0)if(Z.test(X))return{blocked:!0,reason:`Private/internal address: ${X}`};if(X.startsWith("[")&&X.endsWith("]")){let Z=X.slice(1,-1),K=t0(Z);if(K&&$0(K))return{blocked:!0,reason:`Private/internal address: ${X} (maps to ${K})`}}let W=r0(X);if(W&&$0(W))return{blocked:!0,reason:`Private/internal address: ${X} (normalizes to ${W})`};return{blocked:!1}}catch(Q){return{blocked:!0,reason:`Invalid URL: ${Q.message}`}}}function e0($){try{let Q=new URL($);if(!(Q.hostname==="github.com"||Q.hostname.endsWith(".github.com")))return $;let X=Q.pathname.split("/").filter(Boolean);if(X.length<5)return $;let[W,Z,K,J,...q]=X;if(K!=="blob")return $;let V=q.join("/");return`https://raw.githubusercontent.com/${W}/${Z}/${J}/${V}`}catch{return $}}async function K0($,Q={}){let X=S($);if(X.blocked)return{ok:!1,url:$,finalUrl:$,status:403,error:`Blocked: ${X.reason}`,needsBrowser:!1};let W=$;if($=e0($),$!==W)console.error(`[fetcher] Rewrote GitHub URL: ${W.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:Z=15000,userAgent:K,signal:J}=Q,q=new AbortController,V=setTimeout(()=>q.abort(),Z);if(J)J.addEventListener("abort",()=>q.abort(),{once:!0});try{let B=await fetch($,{method:"GET",headers:{...W0,"user-agent":K||X0},redirect:"follow",signal:q.signal});clearTimeout(V);let j=B.headers.get("content-type")||"",H=B.url,Y=B.headers.get("last-modified")||"",N=S(H);if(N.blocked)return{ok:!1,url:$,finalUrl:H,status:B.status,error:`Blocked: ${N.reason}`,needsBrowser:!1};let A=!1;try{A=new URL(H).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(j.includes("text/plain")&&A){let T=await B.text();return{ok:!0,url:W,finalUrl:H,status:B.status,title:H.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:Y,lastModified:Y,markdown:T,contentLength:T.length,excerpt:T.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!j.includes("text/html")&&!j.includes("application/xhtml"))return{ok:!1,url:$,finalUrl:H,status:B.status,error:`Unsupported content type: ${j}`,needsBrowser:!1};let M=await B.text(),z=h(B.status,M,H,$);if(z.blocked)return{ok:!1,url:$,finalUrl:H,status:B.status,error:`Blocked: ${z.reason}`,needsBrowser:!0};let k=await p(M,H),e=u(k);if(!e.ok)return{ok:!1,url:$,finalUrl:H,status:B.status,error:`Low quality content: ${e.reason}`,needsBrowser:!0};return{ok:!0,url:$,finalUrl:H,status:B.status,title:k.title,byline:k.byline,siteName:k.siteName,lang:k.lang,publishedTime:k.publishedTime||Y,lastModified:Y,markdown:k.markdown,excerpt:k.excerpt,contentLength:k.markdown.length,needsBrowser:!1}}catch(B){clearTimeout(V);let j=Z1(B);return{ok:!1,url:$,finalUrl:$,status:0,error:B.message,needsBrowser:j}}}function h($,Q,X,W){let Z=Q.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",K=Q.slice(0,30000).toLowerCase(),J=`${Z} ${K}`;if($===403||$===429||$===503)return{blocked:!0,reason:`HTTP ${$}`};let q=[{pattern:/class=["'][^"']*captcha["']|<div[^>]*id=["']captcha/i,reason:"captcha"},{pattern:/g-recaptcha|data-sitekey|i['"]m not a robot/i,reason:"captcha"},{pattern:/checking your browser.{0,100}please wait|cf-browser-verification/i,reason:"cloudflare challenge"},{pattern:/just a moment.{0,50}security check|ddos protection by cloudflare/i,reason:"cloudflare challenge"},{pattern:/unusual traffic.{0,50}from your computer network/i,reason:"unusual traffic"},{pattern:/bot detected|automated.{0,20}request/i,reason:"bot detection"},{pattern:/enable\s+javascript\s+to\s+view|javascript\s+is\s+required.{0,50}enabled/i,reason:"requires javascript"},{pattern:/access denied|accessdenied/i,reason:"access denied"},{pattern:/protected by anubis|anubis uses a proof-of-work/i,reason:"anubis challenge"}];for(let B of q)if(B.pattern.test(J))return{blocked:!0,reason:B.reason};let V=W1(W,X,Q);if(V)return{blocked:!0,reason:V};return{blocked:!1}}function W1($,Q,X){try{let W=new URL($),Z=new URL(Q);if(W.hostname.toLowerCase()===Z.hostname.toLowerCase())return;let K=Z.hostname.toLowerCase();if($1.some((q)=>K===q||K.endsWith(`.${q}`)))return`redirected to login (${Z.hostname})`;if(Q1.some((q)=>K.startsWith(q)))return`redirected to login (${Z.hostname})`;let J=X.slice(0,20000).toLowerCase();if(X1.some((q)=>J.includes(q)))return`redirected to login page (${Z.hostname})`}catch{}return}function Z1($){let Q=$.message.toLowerCase();return Q.includes("fetch failed")||Q.includes("unable to verify")||Q.includes("certificate")||Q.includes("timeout")}function Q0($){let Q=['meta[property="article:published_time"]','meta[name="article:published_time"]','meta[property="og:published_time"]','meta[name="publication_date"]','meta[name="date"]','meta[itemprop="datePublished"]','time[itemprop="datePublished"]','meta[name="DC.date"]'];for(let X of Q){let W=$.querySelector(X),Z=W?.getAttribute("content")||W?.getAttribute("datetime")||"";if(Z)return Z}return""}async function p($,Q){let{Readability:X,JSDOM:W,turndown:Z}=await n0(),K=new W($,{url:Q});try{let J=K.window.document,V=new X(J).parse();if(V&&V.content){let H=Z.turndown(V.content).replaceAll(/\n{3,}/g,`
|
|
3
3
|
|
|
4
|
-
`).trim(),Y=V.publishedTime
|
|
4
|
+
`).trim(),Y=V.publishedTime||Q0(J)||"";return{title:V.title||J.title||Q,byline:V.byline||"",siteName:V.siteName||"",lang:V.lang||"",publishedTime:Y,markdown:H,excerpt:H.slice(0,300).replaceAll(/\n/g," ")}}let B=J.body;if(B){let j=B.cloneNode(!0);j.querySelectorAll("script, style, nav, footer, header, aside").forEach((N)=>N.remove());let Y=(j.textContent||"").replaceAll(/\s+/g," ").trim();return{title:J.title||Q,byline:"",siteName:"",lang:"",publishedTime:Q0(J),markdown:Y,excerpt:Y.slice(0,300)}}return{title:Q,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}finally{K.window.close()}}function u($){let Q=$.markdown.trim().toLowerCase(),X=($.title||"").toLowerCase();if($.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let W=Q.toLowerCase(),Z=[{check:()=>W.includes("loading")&&W.includes("please wait"),desc:"loading page"},{check:()=>W.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>W.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>W.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>W.includes("verify you are human"),desc:"human verification"},{check:()=>W.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>W.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(Q),desc:"login form only"}];for(let{check:K,desc:J}of Z)if(K())return{ok:!1,reason:J};if(X.includes("just a moment")||X.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}var y=null,X0="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",W0,Z0,o0,s0,a0,$1,Q1,X1;var q0=U(()=>{W0={"user-agent":X0,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},Z0=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i],o0=/^::ffff:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/i,s0=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i,a0=/^(?:0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)$/i;$1=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],Q1=["login.","signin.","auth.","sso.","accounts.","idp."],X1=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"]});function C($){try{let Q=new URL($);if(!(Q.hostname==="github.com"||Q.hostname.endsWith(".github.com")))return null;let X=Q.pathname.split("/").filter(Boolean);if(X.length<2)return null;let[W,Z]=X;if(X.length===2)return{owner:W,repo:Z,type:"root"};if(X.length>=4&&(X[2]==="blob"||X[2]==="tree")){let K=X[2],J=X[3],q=X.slice(4).join("/");return{owner:W,repo:Z,type:K,ref:J,path:q}}return null}catch{return null}}async function D($,Q=1e4){let X=new AbortController,W=setTimeout(()=>X.abort(),Q);try{let Z=await fetch(`https://api.github.com${$}`,{headers:B0,signal:X.signal});if(clearTimeout(W),!Z.ok)throw Error(`GitHub API ${Z.status}: ${$}`);return await Z.json()}catch(Z){throw clearTimeout(W),Z}}async function J1($,Q){try{let X=await D(`/repos/${$}/${Q}/readme`);if(X.content&&X.encoding==="base64")return Buffer.from(X.content,"base64").toString("utf8");return""}catch{return""}}async function V0($,Q,X="HEAD",W="",Z){try{let K;if(X==="HEAD")if(Z)K=await D(`/repos/${$}/${Q}/git/ref/heads/${Z}`).catch(()=>null);else K=await Promise.any([D(`/repos/${$}/${Q}/git/ref/heads/main`),D(`/repos/${$}/${Q}/git/ref/heads/master`)]).catch(()=>null);else K=await D(`/repos/${$}/${Q}/git/ref/heads/${X}`).catch(()=>D(`/repos/${$}/${Q}/git/ref/heads/master`).catch(()=>null));if(!K?.object?.sha)return[];let q=(await D(`/repos/${$}/${Q}/git/commits/${K.object.sha}`)).tree.sha,B=(await D(`/repos/${$}/${Q}/git/trees/${q}`)).tree||[];if(W)B=B.filter((j)=>j.path.startsWith(W));return B.slice(0,50).map((j)=>({path:j.path,type:j.type==="tree"?"dir":"file",size:j.size}))}catch{return[]}}async function K1($,Q,X,W,Z=1e4,K){let J=async(V)=>{let B=new AbortController,j=setTimeout(()=>B.abort(),Z);try{let H=await fetch(V,{headers:{"user-agent":B0["user-agent"]},signal:B.signal});if(clearTimeout(j),H.ok)return await H.text();throw Error("not ok")}catch{throw clearTimeout(j),Error("failed")}};if(!X||X==="HEAD"){if(K)try{return await J(`https://raw.githubusercontent.com/${$}/${Q}/${K}/${W}`)}catch{return null}try{return await Promise.any([J(`https://raw.githubusercontent.com/${$}/${Q}/main/${W}`),J(`https://raw.githubusercontent.com/${$}/${Q}/master/${W}`)])}catch{return null}}let q=[`https://raw.githubusercontent.com/${$}/${Q}/${X}/${W}`,`https://raw.githubusercontent.com/${$}/${Q}/master/${W}`];for(let V of q)try{return await J(V)}catch{}return null}async function j0($){let Q=C($);if(!Q)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:X,repo:W,type:Z,ref:K,path:J}=Q;try{if(Z==="root"||Z==="tree"&&!J){let q=await D(`/repos/${X}/${W}`),[V,B]=await Promise.allSettled([J1(X,W),V0(X,W,K||"HEAD","",q.default_branch)]),j=V.status==="fulfilled"?V.value:"",H=B.status==="fulfilled"?B.value:[],Y=q?.description?`
|
|
5
5
|
|
|
6
|
-
> ${q.description}`:"",N=q?.stargazers_count==null?"":` ⭐ ${q.stargazers_count}`,A=q?.language?` · ${q.language}`:"",
|
|
6
|
+
> ${q.description}`:"",N=q?.stargazers_count==null?"":` ⭐ ${q.stargazers_count}`,A=q?.language?` · ${q.language}`:"",M=`# ${X}/${W}${N}${A}${Y}
|
|
7
7
|
|
|
8
|
-
`;if(j)
|
|
8
|
+
`;if(j)M+=j.slice(0,6000);else M+=`[No README found]
|
|
9
9
|
|
|
10
10
|
Files:
|
|
11
11
|
${H.map((z)=>` ${z.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${z.path}`).join(`
|
|
12
|
-
`)}`;return{ok:!0,title:`${
|
|
13
|
-
`);return{ok:!0,title:`${
|
|
12
|
+
`)}`;return{ok:!0,title:`${X}/${W}`,content:M,tree:H.slice(0,30)}}if(Z==="blob"&&J){let q;if(!K||K==="HEAD")try{q=(await D(`/repos/${X}/${W}`)).default_branch}catch{q=void 0}let V=await K1(X,W,K,J,1e4,q);if(V===null)return{ok:!1,error:`File not found: ${J}`};return{ok:!0,title:`${X}/${W}: ${J}`,content:V}}if(Z==="tree"&&J){let q;if(!K||K==="HEAD")try{q=(await D(`/repos/${X}/${W}`)).default_branch}catch{q=void 0}let V=await V0(X,W,K||"HEAD",J,q),B=V.map((j)=>` ${j.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${j.path}`).join(`
|
|
13
|
+
`);return{ok:!0,title:`${X}/${W}/${J}`,content:`[Directory: ${J}]
|
|
14
14
|
|
|
15
15
|
Files:
|
|
16
|
-
${B}`,tree:V}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(q){return{ok:!1,error:q.message}}}var
|
|
16
|
+
${B}`,tree:V}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(q){return{ok:!1,error:q.message}}}var B0;var H0=U(()=>{B0={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"}});function N0($){try{let Q=new URL($),X=Q.hostname.toLowerCase();if(!(X==="reddit.com"||X.endsWith(".reddit.com")))return null;let W=Q.pathname;if(W.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:Y0($)};if(W.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:Y0($)};return null}catch{return null}}function Y0($){try{let Q=new URL($);return`${Q.protocol}//${Q.hostname}${Q.pathname}`}catch{return $}}async function z0($,Q=8000){let X=Date.now();try{let W=$.replace(/\/+$/,"")+".json",Z=new AbortController,K=setTimeout(()=>Z.abort(),15000),J=await fetch(W,{headers:q1,signal:Z.signal});if(clearTimeout(K),!J.ok)throw Error(`Reddit API ${J.status}`);let q=await J.json();if(!Array.isArray(q)||q.length<1)throw Error("Invalid Reddit API response structure");let V=q[0],B=q[1],j=V?.data?.children?.[0]?.data;if(!j)throw Error("No post data in Reddit response");let H=V1(j,B,Q);return{ok:!0,url:$,finalUrl:$,status:200,contentType:"text/markdown",lastModified:"",title:j.title||"Reddit Post",byline:`u/${j.author}`,siteName:`r/${j.subreddit}`,lang:"en",publishedTime:new Date(j.created_utc*1000).toISOString(),excerpt:j.selftext?.slice(0,300).replace(/\n/g," ")||"",markdown:H,contentLength:H.length,needsBrowser:!1,duration:Date.now()-X}}catch(W){return{ok:!1,url:$,finalUrl:$,status:0,error:`Reddit fetch failed: ${W.message}`,needsBrowser:!1,duration:Date.now()-X}}}function V1($,Q,X){let W="";if(W+=`# ${$.title}
|
|
17
17
|
|
|
18
|
-
`,
|
|
18
|
+
`,W+=`**Subreddit:** r/${$.subreddit} | **Author:** u/${$.author} | **Score:** ${$.score}
|
|
19
19
|
|
|
20
|
-
`,$.selftext)
|
|
20
|
+
`,$.selftext)W+=$.selftext,W+=`
|
|
21
21
|
|
|
22
|
-
`;else if($.url)try{let
|
|
22
|
+
`;else if($.url)try{let Z=new URL($.url).hostname.toLowerCase();if(Z!=="reddit.com"&&!Z.endsWith(".reddit.com"))W+=`**Link:** ${$.url}
|
|
23
23
|
|
|
24
|
-
`}catch{
|
|
24
|
+
`}catch{W+=`**Link:** ${$.url}
|
|
25
25
|
|
|
26
|
-
`}if(Q?.data?.children?.length>0){
|
|
26
|
+
`}if(Q?.data?.children?.length>0){W+=`---
|
|
27
27
|
|
|
28
28
|
## Comments
|
|
29
29
|
|
|
30
|
-
`;let
|
|
31
|
-
`}if(
|
|
30
|
+
`;let Z=Q.data.children.filter((K)=>K.kind==="t1").slice(0,10);for(let K of Z)W+=G0(K.data,0),W+=`
|
|
31
|
+
`}if(W.length>X)W=W.slice(0,X).trim()+`
|
|
32
32
|
|
|
33
|
-
... (truncated)`;return
|
|
34
|
-
`,
|
|
33
|
+
... (truncated)`;return W}function G0($,Q){if(!$||$.body==="[deleted]"||$.body==="[removed]")return"";let X="> ".repeat(Q),W="";if(W+=`${X}**u/${$.author}** (${$.score} pts)
|
|
34
|
+
`,W+=`${X}${$.body.replaceAll(`
|
|
35
35
|
`,`
|
|
36
|
-
`+
|
|
37
|
-
`,Q<3&&$.replies?.data?.children){let
|
|
38
|
-
`+
|
|
36
|
+
`+X)}
|
|
37
|
+
`,Q<3&&$.replies?.data?.children){let Z=$.replies.data.children.filter((K)=>K.kind==="t1");for(let K of Z.slice(0,5))W+=`
|
|
38
|
+
`+G0(K.data,Q+1)}return W}var q1;var A0=U(()=>{q1={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"}});function b($,Q=8000){if(!$||$.length<=Q)return $;let X=`
|
|
39
39
|
|
|
40
40
|
[...content trimmed...]
|
|
41
41
|
|
|
42
|
-
`,
|
|
43
|
-
`)
|
|
44
|
-
`)q++;if(q>=$.length-K+100)q=$.length-K;let V=$.slice(0,
|
|
42
|
+
`,W=Q-X.length,Z=Math.floor(W*0.75),K=W-Z,J=Z;while(J>Z-100&&$[J]!==`
|
|
43
|
+
`)J--;if(J<=Z-100)J=Z;let q=$.length-K;while(q<$.length-K+100&&$[q]!==`
|
|
44
|
+
`)q++;if(q>=$.length-K+100)q=$.length-K;let V=$.slice(0,J).trimEnd(),B=$.slice(q).trimStart();return`${V}${X}${B}`}import{spawn as B1}from"node:child_process";import{dirname as j1,join as H1}from"node:path";import{fileURLToPath as Y1}from"node:url";function A1($){if(!Array.isArray($)||$.length===0)throw Error("cdp: args must be a non-empty array");if($[0]==="test")return $.map((Q,X)=>M0(Q,X));if(!G1.has($[0]))throw Error(`cdp: unknown subcommand '${$[0]}'`);return $.map((Q,X)=>M0(Q,X))}function M0($,Q){if(typeof $!=="string")throw Error(`cdp: argv[${Q}] must be a string (got ${typeof $})`);if($.includes("\x00"))throw Error(`cdp: argv[${Q}] contains a null byte`);return $}function c($,Q=30000){return M1($,null,Q)}function M1($,Q=null,X=30000){let W=A1($);return new Promise((Z,K)=>{let J=B1(F(),[z1,...W],{stdio:[Q==null?"ignore":"pipe","pipe","pipe"]});if(Q!=null)J.stdin.write(Q),J.stdin.end();let q="",V="";J.stdout.on("data",(j)=>q+=j),J.stderr.on("data",(j)=>V+=j);let B=setTimeout(()=>{J.kill(),K(Error(`cdp timeout: ${$[0]}`))},X);J.on("close",(j)=>{if(clearTimeout(B),j===0)Z(q.trim());else K(Error(V.trim()||`cdp exit ${j}`))})})}async function i($){await c(["evalraw",$,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
45
45
|
(function() {
|
|
46
46
|
// ── Runtime.enable / CDP detection masking ──────────────
|
|
47
47
|
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
@@ -326,21 +326,21 @@ ${B}`,tree:V}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(q){return{
|
|
|
326
326
|
};
|
|
327
327
|
} catch(_) {}
|
|
328
328
|
})();
|
|
329
|
-
`})])}var
|
|
329
|
+
`})])}var N1,z1,G1;var U0=U(()=>{P();N1=j1(Y1(import.meta.url)),z1=H1(N1,"..","bin","cdp.mjs"),G1=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"])});var x=()=>{};var l=U(()=>{x()});import{fileURLToPath as U1}from"node:url";function k0($){return U1(new URL(".",$)).replace(/^\/([A-Z]:)/,"$1")}var D0=()=>{};import{existsSync as I,mkdirSync as O1,readFileSync as b0,writeFileSync as k1}from"node:fs";import{homedir as D1}from"node:os";import{join as F0}from"node:path";import{tmpdir as v1}from"node:os";function b1($,Q=9222){let X=Number.parseInt(String($??""),10);return Number.isInteger(X)&&X>1024&&X<65535?X:Q}function y1(){try{if(I(v)){let $=b0(v,"utf8"),Q=JSON.parse($);if(Array.isArray(Q.engines)&&Q.engines.length>0&&Q.engines.every((X)=>typeof X==="string")){let X=Q.engines.filter((Z)=>d[Z]),W=Q.engines.filter((Z)=>!d[Z]);if(W.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${W.join(", ")}
|
|
330
330
|
[greedysearch] Available engines: ${Object.keys(d).join(", ")}
|
|
331
|
-
`);if(
|
|
332
|
-
`)}}}catch{}return
|
|
333
|
-
`,"utf8")}catch{}}function
|
|
334
|
-
[greedysearch] Available synthesizers: ${
|
|
335
|
-
[greedysearch] Falling back to default: ${
|
|
336
|
-
`)}}}catch{}return
|
|
337
|
-
`)[0];if(!Q)throw Error("No Chrome tabs found");return Q.slice(0,8)}async function f($="about:blank"){let Q=await
|
|
331
|
+
`);if(X.length>0)return X;process.stderr.write(`[greedysearch] Warning: no valid engines in ${v}, falling back to defaults: ${o.join(", ")}
|
|
332
|
+
`)}}}catch{}return o}function S1(){try{if(!I(n))O1(n,{recursive:!0});if(!I(v))k1(v,JSON.stringify({engines:o,synthesizer:s},null,2)+`
|
|
333
|
+
`,"utf8")}catch{}}function C1(){try{if(I(v)){let $=b0(v,"utf8"),Q=JSON.parse($);if(typeof Q.synthesizer==="string"){let X=Q.synthesizer.toLowerCase();if(v0.includes(X))return X;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${Q.synthesizer}" in ${v}
|
|
334
|
+
[greedysearch] Available synthesizers: ${v0.join(", ")}
|
|
335
|
+
[greedysearch] Falling back to default: ${s}
|
|
336
|
+
`)}}}catch{}return s}var F1,w0,O,w1,T0,T1,L0,L1,P1,P0,y$,S$,n,v,o,s="gemini",v0,d,C$,x$,a;var _=U(()=>{F1=v1().replaceAll("\\","/"),w0=b1(process.env.GREEDY_SEARCH_PORT),O=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${F1}/greedysearch-chrome-profile`).replaceAll("\\","/"),w1=`${O}/DevToolsActivePort`,T0=process.env.GREEDY_SEARCH_PID_FILE||`${O}/browser.pid`,T1=process.env.CDP_PAGES_CACHE||`${O}/cdp-pages.json`,L0=process.env.GREEDY_SEARCH_MODE_FILE||`${O}/browser-mode`,L1=process.env.GREEDY_SEARCH_METADATA_FILE||`${O}/browser-metadata.json`,P1=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${O}/browser-launch.lock`,P0=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${O}/browser-last-activity`,y$=(process.env.CDP_SOCKET_DIR||`${O}/cdp-sockets`).replaceAll("\\","/"),S$=`${O}/visible-recovery.jsonl`,n=F0(D1(),".dm"),v=F0(n,"greedyconfig"),o=["perplexity","google","chatgpt","gemini"];S1();v0=["gemini","chatgpt"];d={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"},C$=y1(),x$=C1(),a=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=O});var g$;var y0=U(()=>{_();x();l();g$=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5});async function S0(){let Q=(await G(["list"])).split(`
|
|
337
|
+
`)[0];if(!Q)throw Error("No Chrome tabs found");return Q.slice(0,8)}async function f($="about:blank"){let Q=await S0(),X=new URL($).hostname;if(X==="copilot.microsoft.com"||X==="www.perplexity.ai"||X==="perplexity.ai"||X.endsWith(".perplexity.ai")){let J=await G(["evalraw",Q,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:q}=JSON.parse(J),V=q.slice(0,8);if(await G(["list"]).catch(()=>null),X==="copilot.microsoft.com")await i(V);else i(V).catch(()=>{});return await G(["list"]).catch(()=>null),q}let Z=await G(["evalraw",Q,"Target.createTarget",JSON.stringify({url:$})]),{targetId:K}=JSON.parse(Z);return await G(["list"]).catch(()=>null),K}async function R($){try{let Q=await S0();await G(["evalraw",Q,"Target.closeTarget",JSON.stringify({targetId:$})])}catch{}}var t$,e$,$2,G;var C0=U(()=>{P();U0();x();l();D0();_();y0();t$=k0(import.meta.url),e$=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,$2=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60,G=c});function I1(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(Q=void 0){}multiplySelf(){return this}preMultiplySelf(){return this}translateSelf(){return this}scaleSelf(){return this}rotateSelf(){return this}};if(typeof globalThis.ImageData>"u")globalThis.ImageData=class{constructor(Q=void 0,X=0,W=0){this.data=Q,this.width=X,this.height=W}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(Q=void 0){}}}async function _1(){I1();let $=await import("pdf-parse"),Q=$.PDFParse??$.default;if(!Q)throw Error("pdf-parse did not export PDFParse");return Q}async function x0($,Q){try{let W=new(await _1())({data:new Uint8Array($)});await W.load();let Z=await W.getText(),K=Z.text?.trim();if(!K)return null;return{title:new URL(Q).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${Z.total} pages)
|
|
338
338
|
|
|
339
|
-
${K}`,pages:
|
|
340
|
-
`)}}if(
|
|
341
|
-
`);let K=await
|
|
342
|
-
`)}let
|
|
343
|
-
`),await
|
|
339
|
+
${K}`,pages:Z.total}}catch(X){return{error:X.message||String(X)}}}function r($="",Q=240){let X=String($).replaceAll(/\s+/g," ").trim();if(X.length<=Q)return X;let W=X.slice(0,Q),Z=W.lastIndexOf(" ");return Z>0?`${W.slice(0,Z)}...`:`${W}...`}var I0=()=>{};var g0={};i0(g0,{fetchTopSource:()=>h1,fetchSourceContent:()=>f0,fetchMultipleSources:()=>E1});async function f1($,Q,X=8000){let W=Date.now();try{let K=(await G(["evalraw",$,"Page.getFrameTree","{}"]).then((A)=>JSON.parse(A)).catch(()=>null))?.frameTree?.frame?.id||void 0,J=await G(["evalraw",$,"Network.loadNetworkResource",JSON.stringify({frameId:K,url:Q,options:{disableCache:!0,includeCredentials:!1}})],20000),V=JSON.parse(J).resource;if(!V?.success||!V.httpStatusCode)return{url:Q,error:V?.netErrorName||V?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-W,needsFallback:!0};let B="";if(V.stream)try{let A=await G(["evalraw",$,"IO.read",JSON.stringify({handle:V.stream})],1e4);B=JSON.parse(A).data||"",await G(["evalraw",$,"IO.close",JSON.stringify({handle:V.stream})]).catch(()=>{})}catch{}if(!B||B.length<100)return{url:Q,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-W,needsFallback:!0};let j=h(V.httpStatusCode,B,Q,Q);if(j.blocked)return{url:Q,status:V.httpStatusCode,error:`Blocked: ${j.reason}`,source:"chrome",duration:Date.now()-W,needsBrowser:!0};let H=await p(B,Q),Y=u(H);if(!Y.ok)return{url:Q,status:V.httpStatusCode,error:`Low quality: ${Y.reason}`,source:"chrome",duration:Date.now()-W,needsBrowser:!0};let N=b(H.markdown,X);return{url:Q,finalUrl:Q,status:V.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:H.publishedTime||"",byline:H.byline||"",siteName:H.siteName||"",lang:H.lang||"",title:H.title||Q,snippet:H.excerpt,content:N,contentChars:N.length,source:"chrome",duration:Date.now()-W}}catch(Z){return{url:Q,error:Z.message,source:"chrome",duration:Date.now()-W,needsFallback:!0}}}function _0($){try{return new URL($).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function R1($,Q=8000){let X=S($);if(X.blocked)return{url:$,finalUrl:$,status:403,error:`Blocked: ${X.reason}`,source:"pdf-http"};let W=new AbortController,Z=setTimeout(()=>W.abort(),20000),K=Date.now();try{let J=await fetch($,{method:"GET",redirect:"follow",signal:W.signal,headers:J0({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(Z);let q=J.headers.get("content-type")||"",V=J.url||$,B=Number.parseInt(J.headers.get("content-length")||"0",10);if(J.status>=400)return{url:$,finalUrl:V,status:J.status,error:`HTTP ${J.status}`,source:"pdf-http",duration:Date.now()-K};if(!q.toLowerCase().includes("application/pdf")&&!_0(V))return null;if(B>31457280)return{url:$,finalUrl:V,status:J.status,error:`PDF too large: ${B} bytes`,source:"pdf-http",duration:Date.now()-K};let j=Buffer.from(await J.arrayBuffer()),H=await x0(j,V);if(!H||H.error)return{url:$,finalUrl:V,status:J.status,error:H?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-K};let Y=b(H.content,Q);return{url:$,finalUrl:V,status:J.status,contentType:"application/pdf",lastModified:J.headers.get("last-modified")||"",title:H.title,snippet:r(Y,320),content:Y,contentChars:Y.length,pages:H.pages,source:"pdf-http",duration:Date.now()-K}}catch(J){return clearTimeout(Z),{url:$,finalUrl:$,error:J.message||String(J),source:"pdf-http",duration:Date.now()-K}}}async function f0($,Q=8000){let X=Date.now();if(_0($)){let K=await R1($,Q);if(K?.content||K?.status===403)return K}if(C($)){let K=C($);if(K&&(K.type==="root"||K.type==="tree"||K.type==="blob"&&!K.path?.includes("."))){let J=await j0($);if(J.ok){let q=b(J.content,Q);return{url:$,finalUrl:$,status:200,contentType:"text/markdown",lastModified:"",title:J.title,snippet:q.slice(0,320),content:q,contentChars:q.length,source:"github-api",...J.tree&&{tree:J.tree},duration:Date.now()-X}}process.stderr.write(`[greedysearch] GitHub API fetch failed, trying HTTP: ${J.error}
|
|
340
|
+
`)}}if(N0($)?.type==="post"){process.stderr.write(`[greedysearch] Using Reddit JSON API for: ${$.slice(0,60)}...
|
|
341
|
+
`);let K=await z0($,Q);if(K.ok){let J=b(K.markdown,Q);return{url:$,finalUrl:K.finalUrl,status:K.status,contentType:"text/markdown",lastModified:K.lastModified||"",publishedTime:K.publishedTime||"",byline:K.byline||"",siteName:K.siteName||"",lang:K.lang||"",title:K.title,snippet:K.excerpt,content:J,contentChars:J.length,source:"reddit-api",duration:Date.now()-X}}process.stderr.write(`[greedysearch] Reddit API fetch failed, falling back to HTTP: ${K.error}
|
|
342
|
+
`)}let Z=await K0($,{timeoutMs:1e4});if(Z.ok){let K=b(Z.markdown,Q);return{url:$,finalUrl:Z.finalUrl,status:Z.status,contentType:"text/markdown",lastModified:Z.lastModified||"",publishedTime:Z.publishedTime||"",byline:Z.byline||"",siteName:Z.siteName||"",lang:Z.lang||"",title:Z.title,snippet:Z.excerpt,content:K,contentChars:K.length,source:"http",duration:Date.now()-X}}if(Z.needsBrowser)try{let K=await f();try{let J=await f1(K,$,Q);if(J.content&&J.content.length>100)return J}finally{await R(K)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${$.slice(0,60)}, trying browser...
|
|
343
|
+
`),await g1($,Q)}async function R0($,Q=4000,X=200){let W=Date.now()+Q;while(Date.now()<W){try{if((await G(["eval",$,'document.readyState === "complete" && !!document.body && document.body.innerText.length > 500'])).trim()==="true")return}catch{}await new Promise((Z)=>setTimeout(Z,X))}}async function g1($,Q=8000){let X=Date.now(),W;try{W=await f()}catch(Z){return{url:$,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${Z.message}`,source:"browser",duration:Date.now()-X}}try{await G(["nav",W,$],30000),await R0(W);let Z=await G(["eval",W,String.raw`
|
|
344
344
|
(function(){
|
|
345
345
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
346
346
|
var text = (el || document.body).innerText;
|
|
@@ -350,26 +350,26 @@ ${K}`,pages:J.total}}catch(W){return{error:W.message||String(W)}}}function a($="
|
|
|
350
350
|
url: location.href
|
|
351
351
|
});
|
|
352
352
|
})()
|
|
353
|
-
`]),K=JSON.parse(
|
|
354
|
-
`);let
|
|
355
|
-
`);let z=await
|
|
353
|
+
`]),K=JSON.parse(Z),J=b(K.content,Q);return{url:$,finalUrl:K.url||$,status:200,contentType:"text/plain",lastModified:"",title:K.title,snippet:r(J,320),content:J,contentChars:J.length,source:"browser",duration:Date.now()-X}}catch(Z){return{url:$,title:"",content:null,snippet:"",contentChars:0,error:Z.message,source:"browser",duration:Date.now()-X}}finally{await R(W)}}async function E1($,Q=5,X=8000,W=a){let Z=$.slice(0,Q);if(Z.length===0)return[];let K=Math.min(Z.length,Math.max(1,Number.parseInt(String(W),10)||a));process.stderr.write(`[greedysearch] Fetching content from ${Z.length} sources via HTTP (concurrency ${K})...
|
|
354
|
+
`);let J=Array(Z.length),q=0,V=0;async function B(){while(!0){let N=q++;if(N>=Z.length)return;let A=Z[N],M=A.canonicalUrl||A.url;process.stderr.write(`[greedysearch] [${N+1}/${Z.length}] Fetching: ${M.slice(0,60)}...
|
|
355
|
+
`);let z=await f0(M,X).catch((k)=>({url:M,title:"",content:null,snippet:"",contentChars:0,error:k.message,source:"error",duration:0}));if(J[N]={id:A.id,...z},z.content&&z.content.length>100)process.stderr.write(`[greedysearch] ✓ ${z.source}: ${z.content.length} chars
|
|
356
356
|
`);else if(z.error)process.stderr.write(`[greedysearch] ✗ ${z.error.slice(0,80)}
|
|
357
|
-
`);V+=1,process.stderr.write(`PROGRESS:fetch:${V}/${
|
|
358
|
-
`)}}await Promise.all(Array.from({length:K},()=>B()));let j=
|
|
359
|
-
`),
|
|
357
|
+
`);V+=1,process.stderr.write(`PROGRESS:fetch:${V}/${Z.length}
|
|
358
|
+
`)}}await Promise.all(Array.from({length:K},()=>B()));let j=J.filter((N)=>N.content&&N.content.length>100),H=J.filter((N)=>N.source==="http").length,Y=J.filter((N)=>N.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${j.length}/${J.length} sources (HTTP: ${H}, Browser: ${Y})
|
|
359
|
+
`),J}async function h1($){let Q=await f();try{await G(["nav",Q,$],30000),await R0(Q);let X=await G(["eval",Q,String.raw`
|
|
360
360
|
(function(){
|
|
361
361
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
362
362
|
var text = (el || document.body).innerText;
|
|
363
363
|
return text.replace(/\s+/g, ' ').trim();
|
|
364
364
|
})()
|
|
365
|
-
`]);return{url:$,content:
|
|
366
|
-
`)}function
|
|
367
|
-
`)}function w($,Q){if($===void 0||$===null)return;
|
|
368
|
-
Sources:`);for(let q of
|
|
369
|
-
`).trim()}if(typeof Q.answer==="string"){
|
|
370
|
-
Sources:`);for(let q of
|
|
371
|
-
`).trim()}let K=Object.keys(Q).filter((
|
|
372
|
-
## ${
|
|
373
|
-
Sources:`);for(let B of V.slice(0,5))
|
|
374
|
-
`).trim()||"No results returned."}async function
|
|
375
|
-
`)},{type:"text",text:JSON.stringify(
|
|
365
|
+
`]);return{url:$,content:X}}catch(X){return{url:$,content:null,error:X.message}}finally{await R(Q)}}var E0=U(()=>{q0();H0();A0();C0();_();I0()});P();import{spawn as p1}from"node:child_process";import{createInterface as u1}from"node:readline";import{fileURLToPath as m1}from"node:url";import{dirname as c1,join as i1}from"node:path";var l1=c1(m1(import.meta.url)),h0=i1(l1,"search.mjs"),d1="2025-06-18",n1={name:"greedysearch",version:"1.0.0"},o1=360000;function g(...$){process.stderr.write(`[greedysearch-mcp] ${$.join(" ")}
|
|
366
|
+
`)}function p0($){process.stdout.write(`${JSON.stringify($)}
|
|
367
|
+
`)}function w($,Q){if($===void 0||$===null)return;p0({jsonrpc:"2.0",id:$,result:Q})}function E($,Q,X,W){if($===void 0||$===null)return;p0({jsonrpc:"2.0",id:$,error:{code:Q,message:X,...W?{data:W}:{}}})}var s1='Engine to use: "all" (default, fans out to configured engines and fetches top sources), "perplexity" (p), "google" (g), "chatgpt" (gpt), "gemini" (gem), "bing" (b). Research engines: "semantic-scholar" (s2) and "logically" (log).',a1={type:"object",properties:{query:{type:"string",description:"The search query"},engine:{type:"string",default:"all",description:s1},synthesize:{type:"boolean",default:!1,description:'Only for engine="all": synthesize the multi-engine results and fetched sources.'},synthesizer:{type:"string",description:'Synthesis engine for synthesize=true. Defaults to ~/.dm/greedyconfig synthesizer ("gemini" by default). Supported: "gemini", "chatgpt".'},depth:{type:"string",description:'Use "research" for the iterative research workflow. Legacy values: "fast" skips source fetching; "standard"/"deep" alias synthesize=true.'},breadth:{type:"number",default:3,description:'Only for depth="research": number of parallel research directions per round, 1-5.'},iterations:{type:"number",default:2,description:'Only for depth="research": number of iterative research rounds, 1-3.'},maxSources:{type:"number",description:'Only for depth="research": maximum fetched sources for the final report, 3-12.'},researchOutDir:{type:"string",description:'Only for depth="research": optional directory for the structured research bundle.'},writeResearchBundle:{type:"boolean",default:!0,description:'Only for depth="research": write the structured research bundle to disk.'},fullAnswer:{type:"boolean",default:!1,description:"When true, returns the complete answer instead of a truncated preview."},locale:{type:"string",description:'Force results language (e.g. "en", "de", "fr"). Defaults to GREEDY_SEARCH_LOCALE or "en".'},visible:{type:"boolean",default:!1,description:"Set to true to always use visible Chrome for this search (e.g. to solve a login/captcha challenge)."}},required:["query"]},r1={type:"object",properties:{url:{type:"string",description:"URL to fetch and extract content from"},maxChars:{type:"number",default:8000,description:"Maximum characters of extracted content to return."}},required:["url"]},t1=[{name:"greedy_search",description:"WEB/RESEARCH SEARCH ONLY — searches live web via Perplexity, Google AI, ChatGPT, and Gemini, "+'plus opt-in research through Semantic Scholar and Logically, using local headless Chrome automation (no API keys needed). Research mode (depth: "research") plans follow-up actions, fetches sources, audits citations, and writes a structured research bundle on disk. Searches take roughly 1-5 minutes.',inputSchema:a1},{name:"greedy_fetch",description:"Fetch a single URL and extract its readable content (title, byline, markdown body). Uses HTTP first, falling back to Chrome/browser rendering for JS-heavy or blocked pages.",inputSchema:r1}];function e1($){let Q=String($.engine??"all").trim()||"all",X=String($.depth??"").trim(),W=X==="research",Z=X==="fast",K=X==="standard"||X==="deep",J=Q==="all"&&!Z&&($.synthesize===!0||K),q=W?"all":Q,V=$.visible===!0||process.env.GREEDY_SEARCH_VISIBLE==="1",B=[];if($.fullAnswer??q!=="all")B.push("--full");if(W){if(B.push("--depth","research"),typeof $.breadth==="number")B.push("--breadth",String($.breadth));if(typeof $.iterations==="number")B.push("--iterations",String($.iterations));if(typeof $.maxSources==="number")B.push("--max-sources",String($.maxSources));if(typeof $.researchOutDir==="string")B.push("--research-out-dir",$.researchOutDir);if($.writeResearchBundle===!1)B.push("--no-research-bundle")}else if(Z)B.push("--fast");else if(X==="deep")B.push("--depth","deep");else if(J)B.push("--synthesize");if(J&&typeof $.synthesizer==="string")B.push("--synthesizer",$.synthesizer);if(typeof $.locale==="string"&&$.locale)B.push("--locale",$.locale);if(V)B.push("--always-visible");else B.push("--headless");return{engine:q,flags:B,visible:V}}function $$($,Q){return new Promise((X,W)=>{let{engine:Z,flags:K,visible:J}=e1(Q),q={...process.env};if(J)q.GREEDY_SEARCH_VISIBLE="1",q.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let V=p1(F(),[h0,Z,"--inline","--stdin",...K],{stdio:["pipe","pipe","pipe"],env:q});V.stdin.write($),V.stdin.end();let B="",j="",H=51200,Y=!1,N=parseInt(process.env.GREEDY_SEARCH_TIMEOUT_MS||"",10),A=Number.isNaN(N)?o1:N,M=setTimeout(()=>{if(Y)return;if(Y=!0,process.platform==="win32")V.kill();else V.kill("SIGTERM");W(Error(`greedy_search timed out after ${A}ms`))},A);M.unref(),V.stderr.on("data",(z)=>{if(j+=z,j.length>H)j=j.slice(-H);g(z.toString().trimEnd())}),V.stdout.on("data",(z)=>B+=z),V.on("error",(z)=>{if(Y)return;Y=!0,clearTimeout(M),W(z)}),V.on("close",(z)=>{if(Y)return;if(Y=!0,clearTimeout(M),z!==0){W(Error(j.trim()||`search.mjs exited with code ${z}`));return}try{X(JSON.parse(B.trim()))}catch{W(Error(`Invalid JSON from search.mjs: ${B.slice(0,200)}`))}})})}function Q$($,Q){let X=[],W=Q._needsHumanVerification;if(W)X.push("## Manual verification required"),X.push(String(W.message||"Visible Chrome is open. Solve the verification challenge, then rerun the same search."));let Z=Q._synthesis;if(Z?.answer){X.push(String(Z.answer));let J=Array.isArray(Q._sources)?Q._sources:[];if(J.length>0){X.push(`
|
|
368
|
+
Sources:`);for(let q of J.slice(0,8))X.push(`- [${q.title||q.url}](${q.url})`)}return X.join(`
|
|
369
|
+
`).trim()}if(typeof Q.answer==="string"){X.push(Q.answer);let J=Array.isArray(Q.sources)?Q.sources:[];if(J.length>0){X.push(`
|
|
370
|
+
Sources:`);for(let q of J.slice(0,8))X.push(`- [${q.title||q.url}](${q.url})`)}return X.join(`
|
|
371
|
+
`).trim()}let K=Object.keys(Q).filter((J)=>!J.startsWith("_")&&Q[J]&&typeof Q[J]==="object");for(let J of K){let q=Q[J];if(K.length>1)X.push(`
|
|
372
|
+
## ${J}`);if(q.error){X.push(`Error: ${q.error}`);continue}if(q.answer)X.push(String(q.answer));let V=Array.isArray(q.sources)?q.sources:[];if(V.length>0){X.push(`
|
|
373
|
+
Sources:`);for(let B of V.slice(0,5))X.push(`- [${B.title||B.url}](${B.url})`)}}return X.join(`
|
|
374
|
+
`).trim()||"No results returned."}async function X$($){if(!$||typeof $.query!=="string"||!$.query.trim())throw Error("query is required");let Q=await $$($.query,$);return{content:[{type:"text",text:Q$($.engine??"all",Q)||"No results returned."},{type:"text",text:JSON.stringify(Q)}]}}var t;function W$(){if(!t)t=Promise.resolve().then(() => (E0(),g0)).then(($)=>$.fetchSourceContent);return t}async function Z$($){if(!$||typeof $.url!=="string"||!$.url.trim())throw Error("url is required");let Q=typeof $.maxChars==="number"?$.maxChars:8000,W=await(await W$())($.url,Q);if(W?.error&&!W.content)return{content:[{type:"text",text:`Fetch failed: ${W.error}`}],isError:!0};return{content:[{type:"text",text:[`# ${W.title||$.url}`,"",W.byline?`By ${W.byline}`:null,W.siteName?`Source: ${W.siteName}`:null,"",W.content||"(no content extracted)"].filter((K)=>K!==null).join(`
|
|
375
|
+
`)},{type:"text",text:JSON.stringify(W)}]}}async function J$($){let{id:Q,method:X,params:W}=$;switch(X){case"initialize":{let Z=W?.protocolVersion;w(Q,{protocolVersion:typeof Z==="string"?Z:d1,capabilities:{tools:{}},serverInfo:n1});return}case"notifications/initialized":case"initialized":return;case"ping":w(Q,{});return;case"tools/list":w(Q,{tools:t1});return;case"tools/call":{let Z=W?.name,K=W?.arguments??{};try{let J;if(Z==="greedy_search")J=await X$(K);else if(Z==="greedy_fetch")J=await Z$(K);else{E(Q,-32602,`Unknown tool: ${Z}`);return}w(Q,J)}catch(J){w(Q,{content:[{type:"text",text:`Error: ${J.message||String(J)}`}],isError:!0})}return}default:if(X&&X.startsWith("notifications/"))return;E(Q,-32601,`Method not found: ${X}`)}}function K$(){let $=u1({input:process.stdin,terminal:!1});$.on("line",(Q)=>{let X=Q.trim();if(!X)return;let W;try{W=JSON.parse(X)}catch{E(null,-32700,"Parse error");return}J$(W).catch((Z)=>{g("Unhandled error:",Z?.stack||String(Z)),E(W?.id,-32603,"Internal error",String(Z?.message||Z))})}),$.on("close",()=>process.exit(0)),process.on("uncaughtException",(Q)=>{g("Uncaught exception:",Q?.stack||String(Q))}),g(`GreedySearch MCP server ready (${h0})`)}K$();
|