@duckmind/dm-darwin-arm64 0.52.6 → 0.53.1
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 +14 -10
- package/extensions/dm-cua/bin/browser-cua.mjs +6 -6
- package/extensions/dm-cua/index.js +5 -5
- package/extensions/dm-cua/src/browser-cua-lib.mjs +2 -2
- package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +8 -1
- package/extensions/greedysearch-dm/bin/cdp-headless.mjs +1 -1
- package/extensions/greedysearch-dm/bin/cdp-visible.mjs +1 -1
- package/extensions/greedysearch-dm/bin/cdp.mjs +29 -20
- package/extensions/greedysearch-dm/bin/gschrome.mjs +1 -8
- package/extensions/greedysearch-dm/bin/kill-visible.mjs +1 -1
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +1 -2
- package/extensions/greedysearch-dm/bin/launch.mjs +9 -11
- package/extensions/greedysearch-dm/bin/mcp.mjs +375 -0
- package/extensions/greedysearch-dm/bin/search.mjs +309 -157
- package/extensions/greedysearch-dm/bin/visible.mjs +1 -1
- package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +205 -68
- package/extensions/greedysearch-dm/extractors/chatgpt.mjs +229 -140
- package/extensions/greedysearch-dm/extractors/common.mjs +160 -50
- package/extensions/greedysearch-dm/extractors/consensus.mjs +226 -93
- package/extensions/greedysearch-dm/extractors/consent.mjs +44 -17
- package/extensions/greedysearch-dm/extractors/gemini.mjs +277 -138
- package/extensions/greedysearch-dm/extractors/google-ai.mjs +172 -64
- package/extensions/greedysearch-dm/extractors/logically.mjs +183 -69
- package/extensions/greedysearch-dm/extractors/perplexity.mjs +331 -65
- package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +118 -41
- package/extensions/greedysearch-dm/index.js +23 -20
- package/extensions/greedysearch-dm/package.json +8 -3
- package/extensions/greedysearch-dm/skills/greedy-search/skill.md +8 -8
- package/extensions/greedysearch-dm/src/fetcher.mjs +2 -2
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -6
- package/extensions/greedysearch-dm/src/github.mjs +7 -7
- package/extensions/greedysearch-dm/src/reddit.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +10 -8
- package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +48 -0
- package/extensions/greedysearch-dm/src/search/chrome.mjs +130 -54
- package/extensions/greedysearch-dm/src/search/constants.mjs +6 -6
- package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +160 -83
- package/extensions/greedysearch-dm/src/search/minimize.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/pdf.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/port-pid.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/progress.mjs +2 -0
- package/extensions/greedysearch-dm/src/search/recovery.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +262 -167
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +11 -0
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +827 -0
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/synthesis.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +23 -20
- package/extensions/greedysearch-dm/src/tools/shared.js +10 -9
- package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +1 -1
- package/package.json +1 -1
- package/extensions/greedysearch-dm/src/search/cdp-endpoint.mjs +0 -3
- package/extensions/greedysearch-dm/src/search/launcher-paths.mjs +0 -3
- package/extensions/greedysearch-dm/src/search/partial-output.mjs +0 -1
- package/extensions/greedysearch-dm/src/utils/browser-executable.mjs +0 -1
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import{createRequire as
|
|
1
|
+
import{createRequire as Ne}from"node:module";var I=Ne(import.meta.url);import{createRequire as Re}from"node:module";var Wt=Re(import.meta.url),k=null;async function Ce(){if(k)return k;let[{Readability:e},{JSDOM:t},{default:r}]=await Promise.all([import("@mozilla/readability"),import("jsdom"),import("turndown")]),i=new r({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});return i.addRule("removeDataUrls",{filter:(n)=>n.tagName==="IMG"&&n.getAttribute("src")?.startsWith("data:"),replacement:()=>""}),k={Readability:e,JSDOM:t,turndown:i},k}var ie="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",ne={"user-agent":ie,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"},ae=[/^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],Le=/^::ffff:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/i,Oe=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i,Te=/^(?:0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)$/i;function Fe(e){if(!e||e.includes(":"))return null;let t=e.split(".");if(t.length<1||t.length>4)return null;if(!t.every((n)=>Te.test(n)))return null;let r=t.map((n)=>{if(/^0x/i.test(n))return parseInt(n,16);if(/^0[0-7]+$/.test(n))return parseInt(n,8);return parseInt(n,10)});if(r.some((n)=>!Number.isFinite(n)||n<0))return null;let i;if(r.length===1){if(r[0]>4294967295)return null;i=[r[0]>>>24&255,r[0]>>>16&255,r[0]>>>8&255,r[0]&255]}else if(r.length===2){if(r[0]>255||r[1]>16777215)return null;i=[r[0],r[1]>>>16&255,r[1]>>>8&255,r[1]&255]}else if(r.length===3){if(r[0]>255||r[1]>255||r[2]>65535)return null;i=[r[0],r[1],r[2]>>>8&255,r[2]&255]}else{if(r.some((n)=>n>255))return null;i=r}return i.join(".")}function xe(e){let t=e.match(Le);if(t)return`${t[1]}.${t[2]}.${t[3]}.${t[4]}`;let r=e.match(Oe);if(r){let i=parseInt(r[1],16),n=parseInt(r[2],16);if(i>65535||n>65535)return null;return[i>>>8&255,i&255,n>>>8&255,n&255].join(".")}return null}function te(e){return ae.some((t)=>t.test(e))}function oe(e={}){return{...ne,...e}}function j(e){try{if(typeof e!=="string"||!e.trim())return{blocked:!0,reason:"URL must be a non-empty string"};let t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")return{blocked:!0,reason:`Protocol not allowed: ${t.protocol}`};let r=t.hostname.toLowerCase();for(let n of ae)if(n.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(r.startsWith("[")&&r.endsWith("]")){let n=r.slice(1,-1),a=xe(n);if(a&&te(a))return{blocked:!0,reason:`Private/internal address: ${r} (maps to ${a})`}}let i=Fe(r);if(i&&te(i))return{blocked:!0,reason:`Private/internal address: ${r} (normalizes to ${i})`};return{blocked:!1}}catch(t){return{blocked:!0,reason:`Invalid URL: ${t.message}`}}}function Ge(e){try{let t=new URL(e);if(!(t.hostname==="github.com"||t.hostname.endsWith(".github.com")))return e;let r=t.pathname.split("/").filter(Boolean);if(r.length<5)return e;let[i,n,a,o,...s]=r;if(a!=="blob")return e;let l=s.join("/");return`https://raw.githubusercontent.com/${i}/${n}/${o}/${l}`}catch{return e}}async function se(e,t={}){let r=j(e);if(r.blocked)return{ok:!1,url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let i=e;if(e=Ge(e),e!==i)console.error(`[fetcher] Rewrote GitHub URL: ${i.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:n=15000,userAgent:a,signal:o}=t,s=new AbortController,l=setTimeout(()=>s.abort(),n);if(o)o.addEventListener("abort",()=>s.abort(),{once:!0});try{let c=await fetch(e,{method:"GET",headers:{...ne,"user-agent":a||ie},redirect:"follow",signal:s.signal});clearTimeout(l);let u=c.headers.get("content-type")||"",p=c.url,d=c.headers.get("last-modified")||"",f=j(p);if(f.blocked)return{ok:!1,url:e,finalUrl:p,status:c.status,error:`Blocked: ${f.reason}`,needsBrowser:!1};let y=!1;try{y=new URL(p).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(u.includes("text/plain")&&y){let T=await c.text();return{ok:!0,url:i,finalUrl:p,status:c.status,title:p.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:d,lastModified:d,markdown:T,contentLength:T.length,excerpt:T.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!u.includes("text/html")&&!u.includes("application/xhtml"))return{ok:!1,url:e,finalUrl:p,status:c.status,error:`Unsupported content type: ${u}`,needsBrowser:!1};let h=await c.text(),m=F(c.status,h,p,e);if(m.blocked)return{ok:!1,url:e,finalUrl:p,status:c.status,error:`Blocked: ${m.reason}`,needsBrowser:!0};let w=await x(h,p),ee=G(w);if(!ee.ok)return{ok:!1,url:e,finalUrl:p,status:c.status,error:`Low quality content: ${ee.reason}`,needsBrowser:!0};return{ok:!0,url:e,finalUrl:p,status:c.status,title:w.title,byline:w.byline,siteName:w.siteName,lang:w.lang,publishedTime:w.publishedTime||d,lastModified:d,markdown:w.markdown,excerpt:w.excerpt,contentLength:w.markdown.length,needsBrowser:!1}}catch(c){clearTimeout(l);let u=Be(c);return{ok:!1,url:e,finalUrl:e,status:0,error:c.message,needsBrowser:u}}}function F(e,t,r,i){let n=t.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",a=t.slice(0,30000).toLowerCase(),o=`${n} ${a}`;if(e===403||e===429||e===503)return{blocked:!0,reason:`HTTP ${e}`};let s=[{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 c of s)if(c.pattern.test(o))return{blocked:!0,reason:c.reason};let l=Ye(i,r,t);if(l)return{blocked:!0,reason:l};return{blocked:!1}}var Me=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],He=["login.","signin.","auth.","sso.","accounts.","idp."],We=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"];function Ye(e,t,r){try{let i=new URL(e),n=new URL(t);if(i.hostname.toLowerCase()===n.hostname.toLowerCase())return;let a=n.hostname.toLowerCase();if(Me.some((s)=>a===s||a.endsWith(`.${s}`)))return`redirected to login (${n.hostname})`;if(He.some((s)=>a.startsWith(s)))return`redirected to login (${n.hostname})`;let o=r.slice(0,20000).toLowerCase();if(We.some((s)=>o.includes(s)))return`redirected to login page (${n.hostname})`}catch{}return}function Be(e){let t=e.message.toLowerCase();return t.includes("fetch failed")||t.includes("unable to verify")||t.includes("certificate")||t.includes("timeout")}function re(e){let t=['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 r of t){let i=e.querySelector(r),n=i?.getAttribute("content")||i?.getAttribute("datetime")||"";if(n)return n}return""}async function x(e,t){let{Readability:r,JSDOM:i,turndown:n}=await Ce(),a=new i(e,{url:t});try{let o=a.window.document,s=new r(o).parse();if(s&&s.content){let c=n.turndown(s.content).replaceAll(/\n{3,}/g,`
|
|
2
2
|
|
|
3
|
-
`).trim(),
|
|
3
|
+
`).trim(),u=s.publishedTime||re(o)||"";return{title:s.title||o.title||t,byline:s.byline||"",siteName:s.siteName||"",lang:s.lang||"",publishedTime:u,markdown:c,excerpt:c.slice(0,300).replaceAll(/\n/g," ")}}let l=o.body;if(l){let c=l.cloneNode(!0);c.querySelectorAll("script, style, nav, footer, header, aside").forEach((p)=>p.remove());let u=(c.textContent||"").replaceAll(/\s+/g," ").trim();return{title:o.title||t,byline:"",siteName:"",lang:"",publishedTime:re(o),markdown:u,excerpt:u.slice(0,300)}}return{title:t,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}finally{a.window.close()}}function G(e){let t=e.markdown.trim().toLowerCase(),r=(e.title||"").toLowerCase();if(e.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let i=t.toLowerCase(),n=[{check:()=>i.includes("loading")&&i.includes("please wait"),desc:"loading page"},{check:()=>i.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>i.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>i.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>i.includes("verify you are human"),desc:"human verification"},{check:()=>i.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>i.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(t),desc:"login form only"}];for(let{check:a,desc:o}of n)if(a())return{ok:!1,reason:o};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}var ce={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"};function S(e){try{let t=new URL(e);if(!(t.hostname==="github.com"||t.hostname.endsWith(".github.com")))return null;let r=t.pathname.split("/").filter(Boolean);if(r.length<2)return null;let[i,n]=r;if(r.length===2)return{owner:i,repo:n,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let a=r[2],o=r[3],s=r.slice(4).join("/");return{owner:i,repo:n,type:a,ref:o,path:s}}return null}catch{return null}}async function b(e,t=1e4){let r=new AbortController,i=setTimeout(()=>r.abort(),t);try{let n=await fetch(`https://api.github.com${e}`,{headers:ce,signal:r.signal});if(clearTimeout(i),!n.ok)throw Error(`GitHub API ${n.status}: ${e}`);return await n.json()}catch(n){throw clearTimeout(i),n}}async function Je(e,t){try{let r=await b(`/repos/${e}/${t}/readme`);if(r.content&&r.encoding==="base64")return Buffer.from(r.content,"base64").toString("utf8");return""}catch{return""}}async function le(e,t,r="HEAD",i="",n){try{let a;if(r==="HEAD")if(n)a=await b(`/repos/${e}/${t}/git/ref/heads/${n}`).catch(()=>null);else a=await Promise.any([b(`/repos/${e}/${t}/git/ref/heads/main`),b(`/repos/${e}/${t}/git/ref/heads/master`)]).catch(()=>null);else a=await b(`/repos/${e}/${t}/git/ref/heads/${r}`).catch(()=>b(`/repos/${e}/${t}/git/ref/heads/master`).catch(()=>null));if(!a?.object?.sha)return[];let o=(await b(`/repos/${e}/${t}/git/commits/${a.object.sha}`)).tree.sha,s=(await b(`/repos/${e}/${t}/git/trees/${o}`)).tree||[];if(i)s=s.filter((l)=>l.path.startsWith(i));return s.slice(0,50).map((l)=>({path:l.path,type:l.type==="tree"?"dir":"file",size:l.size}))}catch{return[]}}async function Ue(e,t,r,i,n=1e4,a){let o=async(l)=>{let c=new AbortController,u=setTimeout(()=>c.abort(),n);try{let p=await fetch(l,{headers:{"user-agent":ce["user-agent"]},signal:c.signal});if(clearTimeout(u),p.ok)return await p.text();throw Error("not ok")}catch{throw clearTimeout(u),Error("failed")}};if(!r||r==="HEAD"){if(a)try{return await o(`https://raw.githubusercontent.com/${e}/${t}/${a}/${i}`)}catch{return null}try{return await Promise.any([o(`https://raw.githubusercontent.com/${e}/${t}/main/${i}`),o(`https://raw.githubusercontent.com/${e}/${t}/master/${i}`)])}catch{return null}}let s=[`https://raw.githubusercontent.com/${e}/${t}/${r}/${i}`,`https://raw.githubusercontent.com/${e}/${t}/master/${i}`];for(let l of s)try{return await o(l)}catch{}return null}async function ue(e){let t=S(e);if(!t)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:i,type:n,ref:a,path:o}=t;try{if(n==="root"||n==="tree"&&!o){let s=await b(`/repos/${r}/${i}`),[l,c]=await Promise.allSettled([Je(r,i),le(r,i,a||"HEAD","",s.default_branch)]),u=l.status==="fulfilled"?l.value:"",p=c.status==="fulfilled"?c.value:[],d=s?.description?`
|
|
4
4
|
|
|
5
|
-
> ${
|
|
5
|
+
> ${s.description}`:"",f=s?.stargazers_count==null?"":` ⭐ ${s.stargazers_count}`,y=s?.language?` · ${s.language}`:"",h=`# ${r}/${i}${f}${y}${d}
|
|
6
6
|
|
|
7
|
-
`;if(u)
|
|
7
|
+
`;if(u)h+=u.slice(0,6000);else h+=`[No README found]
|
|
8
8
|
|
|
9
9
|
Files:
|
|
10
|
-
${
|
|
11
|
-
`)}`;return{ok:!0,title:`${r}/${
|
|
12
|
-
`);return{ok:!0,title:`${r}/${
|
|
10
|
+
${p.map((m)=>` ${m.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${m.path}`).join(`
|
|
11
|
+
`)}`;return{ok:!0,title:`${r}/${i}`,content:h,tree:p.slice(0,30)}}if(n==="blob"&&o){let s;if(!a||a==="HEAD")try{s=(await b(`/repos/${r}/${i}`)).default_branch}catch{s=void 0}let l=await Ue(r,i,a,o,1e4,s);if(l===null)return{ok:!1,error:`File not found: ${o}`};return{ok:!0,title:`${r}/${i}: ${o}`,content:l}}if(n==="tree"&&o){let s;if(!a||a==="HEAD")try{s=(await b(`/repos/${r}/${i}`)).default_branch}catch{s=void 0}let l=await le(r,i,a||"HEAD",o,s),c=l.map((u)=>` ${u.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${u.path}`).join(`
|
|
12
|
+
`);return{ok:!0,title:`${r}/${i}/${o}`,content:`[Directory: ${o}]
|
|
13
13
|
|
|
14
14
|
Files:
|
|
15
|
-
${c}`,tree:
|
|
15
|
+
${c}`,tree:l}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{ok:!1,error:s.message}}}var qe={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};function fe(e){try{let t=new URL(e),r=t.hostname.toLowerCase();if(!(r==="reddit.com"||r.endsWith(".reddit.com")))return null;let i=t.pathname;if(i.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:pe(e)};if(i.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:pe(e)};return null}catch{return null}}function pe(e){try{let t=new URL(e);return`${t.protocol}//${t.hostname}${t.pathname}`}catch{return e}}async function ge(e,t=8000){let r=Date.now();try{let i=e.replace(/\/+$/,"")+".json",n=new AbortController,a=setTimeout(()=>n.abort(),15000),o=await fetch(i,{headers:qe,signal:n.signal});if(clearTimeout(a),!o.ok)throw Error(`Reddit API ${o.status}`);let s=await o.json();if(!Array.isArray(s)||s.length<1)throw Error("Invalid Reddit API response structure");let l=s[0],c=s[1],u=l?.data?.children?.[0]?.data;if(!u)throw Error("No post data in Reddit response");let p=Ve(u,c,t);return{ok:!0,url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:u.title||"Reddit Post",byline:`u/${u.author}`,siteName:`r/${u.subreddit}`,lang:"en",publishedTime:new Date(u.created_utc*1000).toISOString(),excerpt:u.selftext?.slice(0,300).replace(/\n/g," ")||"",markdown:p,contentLength:p.length,needsBrowser:!1,duration:Date.now()-r}}catch(i){return{ok:!1,url:e,finalUrl:e,status:0,error:`Reddit fetch failed: ${i.message}`,needsBrowser:!1,duration:Date.now()-r}}}function Ve(e,t,r){let i="";if(i+=`# ${e.title}
|
|
16
16
|
|
|
17
|
-
`,
|
|
17
|
+
`,i+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
|
|
18
18
|
|
|
19
|
-
`,e.selftext)
|
|
19
|
+
`,e.selftext)i+=e.selftext,i+=`
|
|
20
20
|
|
|
21
|
-
`;else if(e.url)try{let
|
|
21
|
+
`;else if(e.url)try{let n=new URL(e.url).hostname.toLowerCase();if(n!=="reddit.com"&&!n.endsWith(".reddit.com"))i+=`**Link:** ${e.url}
|
|
22
22
|
|
|
23
|
-
`}catch{
|
|
23
|
+
`}catch{i+=`**Link:** ${e.url}
|
|
24
24
|
|
|
25
|
-
`}if(t?.data?.children?.length>0){
|
|
25
|
+
`}if(t?.data?.children?.length>0){i+=`---
|
|
26
26
|
|
|
27
27
|
## Comments
|
|
28
28
|
|
|
29
|
-
`;let
|
|
30
|
-
`}if(
|
|
29
|
+
`;let n=t.data.children.filter((a)=>a.kind==="t1").slice(0,10);for(let a of n)i+=de(a.data,0),i+=`
|
|
30
|
+
`}if(i.length>r)i=i.slice(0,r).trim()+`
|
|
31
31
|
|
|
32
|
-
... (truncated)`;return
|
|
33
|
-
`,
|
|
32
|
+
... (truncated)`;return i}function de(e,t){if(!e||e.body==="[deleted]"||e.body==="[removed]")return"";let r="> ".repeat(t),i="";if(i+=`${r}**u/${e.author}** (${e.score} pts)
|
|
33
|
+
`,i+=`${r}${e.body.replaceAll(`
|
|
34
34
|
`,`
|
|
35
35
|
`+r)}
|
|
36
|
-
`,t<3&&e.replies?.data?.children){let
|
|
37
|
-
`+
|
|
36
|
+
`,t<3&&e.replies?.data?.children){let n=e.replies.data.children.filter((a)=>a.kind==="t1");for(let a of n.slice(0,5))i+=`
|
|
37
|
+
`+de(a.data,t+1)}return i}function A(e,t=8000){if(!e||e.length<=t)return e;let r=`
|
|
38
38
|
|
|
39
39
|
[...content trimmed...]
|
|
40
40
|
|
|
41
|
-
`,
|
|
42
|
-
`)
|
|
43
|
-
`)s++;if(s>=e.length-
|
|
41
|
+
`,i=t-r.length,n=Math.floor(i*0.75),a=i-n,o=n;while(o>n-100&&e[o]!==`
|
|
42
|
+
`)o--;if(o<=n-100)o=n;let s=e.length-a;while(s<e.length-a+100&&e[s]!==`
|
|
43
|
+
`)s++;if(s>=e.length-a+100)s=e.length-a;let l=e.slice(0,o).trimEnd(),c=e.slice(s).trimStart();return`${l}${r}${c}`}import{spawn as Ze}from"node:child_process";import{basename as Xe}from"node:path";import{dirname as Qe,join as Ke}from"node:path";import{fileURLToPath as ze}from"node:url";import{existsSync as N,mkdirSync as ot,readFileSync as _e,writeFileSync as st}from"node:fs";import{homedir as lt}from"node:os";import{join as ve}from"node:path";import{tmpdir as ct}from"node:os";import{existsSync as R,mkdirSync as mt,readFileSync as Ee,writeFileSync as yt}from"node:fs";import{homedir as ht}from"node:os";import{join as $e}from"node:path";import{tmpdir as wt}from"node:os";function et(e=process.env,t=process.execPath){let r=e.GREEDY_SEARCH_NODE||e.NODE_BINARY||e.NODE;if(r?.trim())return r.trim();let i=Xe(t||"").toLowerCase();if(i==="node"||i==="node.exe")return t;return"node"}var tt=Qe(ze(import.meta.url)),rt=Ke(tt,"..","bin","cdp.mjs"),it=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function nt(e){if(!Array.isArray(e)||e.length===0)throw Error("cdp: args must be a non-empty array");if(e[0]==="test")return e.map((t,r)=>me(t,r));if(!it.has(e[0]))throw Error(`cdp: unknown subcommand '${e[0]}'`);return e.map((t,r)=>me(t,r))}function me(e,t){if(typeof e!=="string")throw Error(`cdp: argv[${t}] must be a string (got ${typeof e})`);if(e.includes("\x00"))throw Error(`cdp: argv[${t}] contains a null byte`);return e}function be(e,t=30000){return at(e,null,t)}function at(e,t=null,r=30000){let i=nt(e);return new Promise((n,a)=>{let o=Ze(et(),[rt,...i],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)o.stdin.write(t),o.stdin.end();let s="",l="";o.stdout.on("data",(u)=>s+=u),o.stderr.on("data",(u)=>l+=u);let c=setTimeout(()=>{o.kill(),a(Error(`cdp timeout: ${e[0]}`))},r);o.on("close",(u)=>{if(clearTimeout(c),u===0)n(s.trim());else a(Error(l.trim()||`cdp exit ${u}`))})})}async function ye(e){await be(["evalraw",e,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
44
44
|
(function() {
|
|
45
45
|
// ── Runtime.enable / CDP detection masking ──────────────
|
|
46
46
|
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
@@ -51,40 +51,62 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
51
51
|
try { delete window._phantom; } catch(_) {}
|
|
52
52
|
try { delete window.Buffer; } catch(_) {}
|
|
53
53
|
|
|
54
|
-
// Real Chrome without automation
|
|
55
|
-
// A literal false
|
|
56
|
-
//
|
|
57
|
-
|
|
54
|
+
// Real Chrome without automation should not expose navigator.webdriver at all.
|
|
55
|
+
// A literal false or an own-property getter returning undefined is itself a
|
|
56
|
+
// common stealth tell; remove both instance and prototype properties when the
|
|
57
|
+
// descriptor is configurable (as it is with --disable-blink-features).
|
|
58
|
+
try { delete navigator.webdriver; } catch(_) {}
|
|
59
|
+
try { delete Navigator.prototype.webdriver; } catch(_) {}
|
|
58
60
|
Object.defineProperty(navigator, 'vendor', { get: () => 'Google Inc.', configurable: true });
|
|
59
61
|
Object.defineProperty(navigator, 'platform', { get: () => 'Win32', configurable: true });
|
|
60
62
|
Object.defineProperty(navigator, 'maxTouchPoints', { get: () => 0, configurable: true });
|
|
61
63
|
Object.defineProperty(navigator, 'pdfViewerEnabled', { get: () => true, configurable: true });
|
|
64
|
+
Object.defineProperty(navigator, 'productSub', { get: () => '20030107', configurable: true });
|
|
65
|
+
Object.defineProperty(navigator, 'product', { get: () => 'Gecko', configurable: true });
|
|
66
|
+
var __greedyMimeTypes = null;
|
|
67
|
+
function __makeMimeTypes() {
|
|
68
|
+
var pdf = { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
|
|
69
|
+
var textPdf = { type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
|
|
70
|
+
try { Object.setPrototypeOf(pdf, MimeType.prototype); } catch(_) {}
|
|
71
|
+
try { Object.setPrototypeOf(textPdf, MimeType.prototype); } catch(_) {}
|
|
72
|
+
var m = [pdf, textPdf];
|
|
73
|
+
try { Object.setPrototypeOf(m, MimeTypeArray.prototype); } catch(_) {}
|
|
74
|
+
m.item = function item(i) { return this[i] || null; };
|
|
75
|
+
m.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.type === name; }) || null; };
|
|
76
|
+
return m;
|
|
77
|
+
}
|
|
62
78
|
Object.defineProperty(navigator, 'plugins', {
|
|
63
79
|
get: () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
__greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
|
|
81
|
+
var plugin0 = { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' };
|
|
82
|
+
var plugin1 = { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' };
|
|
83
|
+
var plugin2 = { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' };
|
|
84
|
+
try { Object.setPrototypeOf(plugin0, Plugin.prototype); } catch(_) {}
|
|
85
|
+
try { Object.setPrototypeOf(plugin1, Plugin.prototype); } catch(_) {}
|
|
86
|
+
try { Object.setPrototypeOf(plugin2, Plugin.prototype); } catch(_) {}
|
|
87
|
+
var p = [plugin0, plugin1, plugin2];
|
|
88
|
+
p.item = function item(i) { return this[i] || null; };
|
|
89
|
+
p.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.name === name; }) || null; };
|
|
90
|
+
p.refresh = function refresh() {};
|
|
91
|
+
try { Object.setPrototypeOf(p, PluginArray.prototype); } catch(_) {}
|
|
92
|
+
try {
|
|
93
|
+
__greedyMimeTypes[0].enabledPlugin = p[0];
|
|
94
|
+
__greedyMimeTypes[1].enabledPlugin = p[0];
|
|
95
|
+
} catch(_) {}
|
|
70
96
|
return p;
|
|
71
97
|
},
|
|
98
|
+
configurable: true,
|
|
72
99
|
});
|
|
73
100
|
Object.defineProperty(navigator, 'mimeTypes', {
|
|
74
101
|
get: () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{ type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null },
|
|
78
|
-
];
|
|
79
|
-
m.item = function(i) { return m[i] || null; };
|
|
80
|
-
m.namedItem = function(name) { return m.find(function(x) { return x.type === name; }) || null; };
|
|
81
|
-
return m;
|
|
102
|
+
__greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
|
|
103
|
+
return __greedyMimeTypes;
|
|
82
104
|
},
|
|
83
105
|
configurable: true,
|
|
84
106
|
});
|
|
85
107
|
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'], configurable: true });
|
|
86
108
|
try {
|
|
87
|
-
Object.defineProperty(navigator, 'connection', { get: () => ({ effectiveType: '4g', rtt: 50, downlink: 10, saveData: false }), configurable: true });
|
|
109
|
+
Object.defineProperty(navigator, 'connection', { get: () => ({ effectiveType: '4g', rtt: 50, downlink: 10, downlinkMax: Infinity, saveData: false }), configurable: true });
|
|
88
110
|
} catch(_) {}
|
|
89
111
|
if (!navigator.mediaDevices) {
|
|
90
112
|
Object.defineProperty(navigator, 'mediaDevices', {
|
|
@@ -100,6 +122,18 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
100
122
|
configurable: true,
|
|
101
123
|
});
|
|
102
124
|
}
|
|
125
|
+
// ── Missing platform APIs (headless often lacks these) ─
|
|
126
|
+
try {
|
|
127
|
+
if (!navigator.share) {
|
|
128
|
+
navigator.share = function() { return Promise.reject(new Error('NotAllowedError')); };
|
|
129
|
+
}
|
|
130
|
+
} catch(_) {}
|
|
131
|
+
try {
|
|
132
|
+
if (!navigator.contentIndex) {
|
|
133
|
+
Object.defineProperty(navigator, 'contentIndex', { get: () => ({ add: function() {}, delete: function() {}, getAll: function() { return Promise.resolve([]); } }), configurable: true });
|
|
134
|
+
}
|
|
135
|
+
} catch(_) {}
|
|
136
|
+
|
|
103
137
|
if (!window.chrome) {
|
|
104
138
|
window.chrome = {
|
|
105
139
|
app: { isInstalled: false, InstallState: {}, RunningState: {} },
|
|
@@ -107,8 +141,8 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
107
141
|
OnInstalledReason: {}, OnRestartRequiredReason: {}, PlatformArch: {}, PlatformNaclArch: {}, PlatformOs: {}, RequestUpdateCheckStatus: {},
|
|
108
142
|
connect: () => ({}), sendMessage: () => {}, onMessage: { addListener: () => {} }
|
|
109
143
|
},
|
|
110
|
-
loadTimes: ()
|
|
111
|
-
csi: ()
|
|
144
|
+
loadTimes: function() { return { requestTime: 0, startLoadTime: Date.now() - 5000, commitLoadTime: Date.now() - 3000, finishDocumentLoadTime: Date.now() - 2000, finishLoadTime: Date.now() - 1000, firstPaintTime: Date.now() - 800, navigationType: 'Other', wasFetchedViaSpdy: true, wasNpnNegotiated: true, npnNegotiatedProtocol: 'h2', wasAlternateProtocolAvailable: false, connectionInfo: 'http/2' }; },
|
|
145
|
+
csi: function() { var t = Date.now(); return { onloadT: t - 2000, startE: t - 5000, pageT: 'back', tran: 2 }; },
|
|
112
146
|
};
|
|
113
147
|
}
|
|
114
148
|
var __greedyNativeFns = [];
|
|
@@ -129,6 +163,19 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
129
163
|
return getParam.call(this, p);
|
|
130
164
|
});
|
|
131
165
|
} catch(_) {}
|
|
166
|
+
// ── WebGL readPixels noise ──────────────────────────
|
|
167
|
+
// CreepJS and other fingerprinters draw content with WebGL and read back the
|
|
168
|
+
// rendered pixels. Adding subtle noise breaks rendering-based fingerprinting.
|
|
169
|
+
try {
|
|
170
|
+
var origReadPixels = WebGLRenderingContext.prototype.readPixels;
|
|
171
|
+
WebGLRenderingContext.prototype.readPixels = __markNative(function readPixels(x, y, width, height, format, type, pixels) {
|
|
172
|
+
var result = origReadPixels.call(this, x, y, width, height, format, type, pixels);
|
|
173
|
+
if (pixels && pixels.length > 0) {
|
|
174
|
+
pixels[0] ^= 1;
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
});
|
|
178
|
+
} catch(_) {}
|
|
132
179
|
Object.defineProperty(navigator, 'hardwareConcurrency', { get: () => 8, configurable: true });
|
|
133
180
|
Object.defineProperty(navigator, 'deviceMemory', { get: () => 8, configurable: true });
|
|
134
181
|
|
|
@@ -136,7 +183,7 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
136
183
|
// Headless rendering engines produce slightly different canvas output
|
|
137
184
|
// than headed Chrome. Subtle noise breaks hash-based fingerprinting.
|
|
138
185
|
try {
|
|
139
|
-
var __canvasNoise = ((Date.now()
|
|
186
|
+
var __canvasNoise = ((Date.now() & 0xFF) | 1);
|
|
140
187
|
var origFill = CanvasRenderingContext2D.prototype.fillText;
|
|
141
188
|
CanvasRenderingContext2D.prototype.fillText = __markNative(function fillText() {
|
|
142
189
|
this.globalAlpha = 0.9995;
|
|
@@ -155,15 +202,39 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
155
202
|
HTMLCanvasElement.prototype.toDataURL = __markNative(function toDataURL() {
|
|
156
203
|
var ctx = this.getContext('2d');
|
|
157
204
|
if (ctx) {
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
205
|
+
// Spread noise across canvas to break hash-based fingerprinting.
|
|
206
|
+
// Uses a deterministic pattern so it's consistent per page load
|
|
207
|
+
// but varies between sessions.
|
|
208
|
+
var w = this.width, h = this.height;
|
|
209
|
+
if (w > 0 && h > 0) {
|
|
210
|
+
var imgData = ctx.getImageData(0, 0, Math.min(w, 4), Math.min(h, 4));
|
|
211
|
+
if (imgData && imgData.data) {
|
|
212
|
+
for (var __i = 0; __i < imgData.data.length; __i += 4) {
|
|
213
|
+
imgData.data[__i] ^= (__canvasNoise + __i) & 0xFF;
|
|
214
|
+
}
|
|
215
|
+
ctx.putImageData(imgData, 0, 0);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
162
218
|
}
|
|
163
219
|
return origToDataURL.apply(this, arguments);
|
|
164
220
|
});
|
|
165
221
|
} catch(_) {}
|
|
166
222
|
|
|
223
|
+
// ── AudioContext fingerprint noise ────────────────────
|
|
224
|
+
// Headless Chrome's AudioContext produces slightly different output.
|
|
225
|
+
// Subtle noise breaks audio-based fingerprinting.
|
|
226
|
+
try {
|
|
227
|
+
var __audioSeed = ((Date.now() & 0x1F) | 1);
|
|
228
|
+
var origGetChannelData = AudioBuffer.prototype.getChannelData;
|
|
229
|
+
AudioBuffer.prototype.getChannelData = __markNative(function getChannelData(channel) {
|
|
230
|
+
var data = origGetChannelData.call(this, channel);
|
|
231
|
+
for (var __i = 0; __i < data.length; __i += 64) {
|
|
232
|
+
data[__i] *= 0.99999;
|
|
233
|
+
}
|
|
234
|
+
return data;
|
|
235
|
+
});
|
|
236
|
+
} catch(_) {}
|
|
237
|
+
|
|
167
238
|
// ── window outer dimensions ──────────────────────────
|
|
168
239
|
// outerWidth/Height = 0 in headless — a well-known bot signal.
|
|
169
240
|
// Mirror innerWidth/Height (set by --window-size flag) so the ratio is sane.
|
|
@@ -173,9 +244,15 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
173
244
|
} catch(_) {}
|
|
174
245
|
|
|
175
246
|
// ── screen properties ─────────────────────────────────
|
|
247
|
+
// Headless Chrome often reports an 800x600 screen even when the viewport is
|
|
248
|
+
// 1920x1080. Keep screen metrics internally consistent with our launch flags.
|
|
176
249
|
try {
|
|
177
|
-
|
|
178
|
-
|
|
250
|
+
Object.defineProperty(screen, 'width', { get: () => 1920, configurable: true });
|
|
251
|
+
Object.defineProperty(screen, 'height', { get: () => 1080, configurable: true });
|
|
252
|
+
Object.defineProperty(screen, 'availWidth', { get: () => 1920, configurable: true });
|
|
253
|
+
Object.defineProperty(screen, 'availHeight', { get: () => 1040, configurable: true });
|
|
254
|
+
Object.defineProperty(screen, 'colorDepth', { get: () => 24, configurable: true });
|
|
255
|
+
Object.defineProperty(screen, 'pixelDepth', { get: () => 24, configurable: true });
|
|
179
256
|
} catch(_) {}
|
|
180
257
|
|
|
181
258
|
// ── navigator.userAgentData (UA Client Hints) ─────────
|
|
@@ -248,35 +325,35 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
248
325
|
};
|
|
249
326
|
} catch(_) {}
|
|
250
327
|
})();
|
|
251
|
-
`})])}function
|
|
252
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
253
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
254
|
-
`)}}}catch{}return
|
|
255
|
-
`,"utf8")}catch{}}
|
|
256
|
-
[greedysearch] Available synthesizers: ${
|
|
257
|
-
[greedysearch] Falling back to default: ${H}
|
|
258
|
-
`)}}}catch{}return H}var G={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"},er=at(),tr=lt(),rr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=we;function gt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var cr=gt(process.env.GREEDY_SEARCH_PORT,9222),_e=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${I().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),ur=`${_e}/DevToolsActivePort`,fr=`${I().replaceAll("\\","/")}/cdp-pages.json`,pr=process.env.GREEDY_SEARCH_MODE_FILE||`${I().replaceAll("\\","/")}/greedysearch-chrome-mode`,gr=`${I().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Y=ve(pt(),".dm"),b=ve(Y,"greedyconfig"),J=["perplexity","google","chatgpt"],B="gemini";function mt(){try{if(N(b)){let e=be(b,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((i)=>W[i]),n=t.engines.filter((i)=>!W[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${b}: ${n.join(", ")}
|
|
259
|
-
[greedysearch] Available engines: ${Object.keys(W).join(", ")}
|
|
260
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${b}, falling back to defaults: ${J.join(", ")}
|
|
261
|
-
`)}}}catch{}return J}function dt(){try{if(!N(Y))ut(Y,{recursive:!0});if(!N(b))ft(b,JSON.stringify({engines:J,synthesizer:B},null,2)+`
|
|
262
|
-
`,"utf8")}catch{}}dt();var me=["gemini","chatgpt"];function ht(){try{if(N(b)){let e=be(b,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(me.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${b}
|
|
263
|
-
[greedysearch] Available synthesizers: ${me.join(", ")}
|
|
328
|
+
`})])}function ut(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var pt=ct().replaceAll("\\","/"),tr=ut(process.env.GREEDY_SEARCH_PORT),_=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${pt}/greedysearch-chrome-profile`).replaceAll("\\","/"),rr=`${_}/DevToolsActivePort`,ir=process.env.GREEDY_SEARCH_PID_FILE||`${_}/browser.pid`,nr=process.env.CDP_PAGES_CACHE||`${_}/cdp-pages.json`,ar=process.env.GREEDY_SEARCH_MODE_FILE||`${_}/browser-mode`,or=process.env.GREEDY_SEARCH_METADATA_FILE||`${_}/browser-metadata.json`,sr=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${_}/browser-launch.lock`,lr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${_}/browser-last-activity`,cr=(process.env.CDP_SOCKET_DIR||`${_}/cdp-sockets`).replaceAll("\\","/"),ur=`${_}/visible-recovery.jsonl`,W=ve(lt(),".dm"),$=ve(W,"greedyconfig"),Y=["perplexity","google","chatgpt","gemini"],B="gemini";function ft(){try{if(N($)){let e=_e($,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((n)=>M[n]),i=t.engines.filter((n)=>!M[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${$}: ${i.join(", ")}
|
|
329
|
+
[greedysearch] Available engines: ${Object.keys(M).join(", ")}
|
|
330
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${$}, falling back to defaults: ${Y.join(", ")}
|
|
331
|
+
`)}}}catch{}return Y}function gt(){try{if(!N(W))ot(W,{recursive:!0});if(!N($))st($,JSON.stringify({engines:Y,synthesizer:B},null,2)+`
|
|
332
|
+
`,"utf8")}catch{}}gt();var he=["gemini","chatgpt"];function dt(){try{if(N($)){let e=_e($,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(he.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${$}
|
|
333
|
+
[greedysearch] Available synthesizers: ${he.join(", ")}
|
|
264
334
|
[greedysearch] Falling back to default: ${B}
|
|
265
|
-
`)}}}catch{}return B}var
|
|
266
|
-
|
|
335
|
+
`)}}}catch{}return B}var M={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"},pr=ft(),fr=dt(),gr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=_;function bt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var _t=wt().replaceAll("\\","/"),wr=bt(process.env.GREEDY_SEARCH_PORT),v=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${_t}/greedysearch-chrome-profile`).replaceAll("\\","/"),br=`${v}/DevToolsActivePort`,_r=process.env.GREEDY_SEARCH_PID_FILE||`${v}/browser.pid`,vr=process.env.CDP_PAGES_CACHE||`${v}/cdp-pages.json`,Er=process.env.GREEDY_SEARCH_MODE_FILE||`${v}/browser-mode`,$r=process.env.GREEDY_SEARCH_METADATA_FILE||`${v}/browser-metadata.json`,Dr=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${v}/browser-launch.lock`,Pr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${v}/browser-last-activity`,Ar=(process.env.CDP_SOCKET_DIR||`${v}/cdp-sockets`).replaceAll("\\","/"),Ir=`${v}/visible-recovery.jsonl`,J=$e(ht(),".dm"),D=$e(J,"greedyconfig"),U=["perplexity","google","chatgpt","gemini"],q="gemini";function vt(){try{if(R(D)){let e=Ee(D,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((n)=>H[n]),i=t.engines.filter((n)=>!H[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${D}: ${i.join(", ")}
|
|
336
|
+
[greedysearch] Available engines: ${Object.keys(H).join(", ")}
|
|
337
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${D}, falling back to defaults: ${U.join(", ")}
|
|
338
|
+
`)}}}catch{}return U}function Et(){try{if(!R(J))mt(J,{recursive:!0});if(!R(D))yt(D,JSON.stringify({engines:U,synthesizer:q},null,2)+`
|
|
339
|
+
`,"utf8")}catch{}}Et();var we=["gemini","chatgpt"];function $t(){try{if(R(D)){let e=Ee(D,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(we.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${D}
|
|
340
|
+
[greedysearch] Available synthesizers: ${we.join(", ")}
|
|
341
|
+
[greedysearch] Falling back to default: ${q}
|
|
342
|
+
`)}}}catch{}return q}var H={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"},kr=vt(),jr=$t(),Sr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=v;var Nr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Rr=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1");var Cr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Lr=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;var g=be;async function De(){let e=(await g(["list"])).split(`
|
|
343
|
+
`)[0];if(!e)throw Error("No Chrome tabs found");return e.slice(0,8)}async function C(e="about:blank"){let t=await De(),r=new URL(e).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let a=await g(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:o}=JSON.parse(a),s=o.slice(0,8);if(await g(["list"]).catch(()=>null),r==="copilot.microsoft.com")await ye(s);else ye(s).catch(()=>{});return await g(["list"]).catch(()=>null),o}let i=await g(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:n}=JSON.parse(i);return await g(["list"]).catch(()=>null),n}async function L(e){try{let t=await De();await g(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}import{existsSync as O,mkdirSync as Dt,readFileSync as Ae,writeFileSync as Pt}from"node:fs";import{homedir as At}from"node:os";import{join as Ie}from"node:path";import{tmpdir as It}from"node:os";function kt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var jt=It().replaceAll("\\","/"),Mr=kt(process.env.GREEDY_SEARCH_PORT),E=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${jt}/greedysearch-chrome-profile`).replaceAll("\\","/"),Hr=`${E}/DevToolsActivePort`,Wr=process.env.GREEDY_SEARCH_PID_FILE||`${E}/browser.pid`,Yr=process.env.CDP_PAGES_CACHE||`${E}/cdp-pages.json`,Br=process.env.GREEDY_SEARCH_MODE_FILE||`${E}/browser-mode`,Jr=process.env.GREEDY_SEARCH_METADATA_FILE||`${E}/browser-metadata.json`,Ur=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${E}/browser-launch.lock`,qr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${E}/browser-last-activity`,Vr=(process.env.CDP_SOCKET_DIR||`${E}/cdp-sockets`).replaceAll("\\","/"),Zr=`${E}/visible-recovery.jsonl`,Z=Ie(At(),".dm"),P=Ie(Z,"greedyconfig"),X=["perplexity","google","chatgpt","gemini"],Q="gemini";function St(){try{if(O(P)){let e=Ae(P,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((n)=>V[n]),i=t.engines.filter((n)=>!V[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${P}: ${i.join(", ")}
|
|
267
344
|
[greedysearch] Available engines: ${Object.keys(V).join(", ")}
|
|
268
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
269
|
-
`)}}}catch{}return
|
|
270
|
-
`,"utf8")}catch{}}
|
|
271
|
-
[greedysearch] Available synthesizers: ${
|
|
272
|
-
[greedysearch] Falling back to default: ${
|
|
273
|
-
`)}}}catch{}return
|
|
345
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${P}, falling back to defaults: ${X.join(", ")}
|
|
346
|
+
`)}}}catch{}return X}function Nt(){try{if(!O(Z))Dt(Z,{recursive:!0});if(!O(P))Pt(P,JSON.stringify({engines:X,synthesizer:Q},null,2)+`
|
|
347
|
+
`,"utf8")}catch{}}Nt();var Pe=["gemini","chatgpt"];function Rt(){try{if(O(P)){let e=Ae(P,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(Pe.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${P}
|
|
348
|
+
[greedysearch] Available synthesizers: ${Pe.join(", ")}
|
|
349
|
+
[greedysearch] Falling back to default: ${Q}
|
|
350
|
+
`)}}}catch{}return Q}var V={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"},Xr=St();var Qr=Rt(),K=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=E;function Ct(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(t=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(t=void 0,r=0,i=0){this.data=t,this.width=r,this.height=i}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(t=void 0){}}}async function Lt(){Ct();let e=await import("pdf-parse"),t=e.PDFParse??e.default;if(!t)throw Error("pdf-parse did not export PDFParse");return t}async function ke(e,t){try{let i=new(await Lt())({data:new Uint8Array(e)});await i.load();let n=await i.getText(),a=n.text?.trim();if(!a)return null;return{title:new URL(t).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${n.total} pages)
|
|
274
351
|
|
|
275
|
-
${
|
|
276
|
-
`)}}if(
|
|
277
|
-
`);let
|
|
278
|
-
`)}let
|
|
279
|
-
`),await
|
|
352
|
+
${a}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function z(e="",t=240){let r=String(e).replaceAll(/\s+/g," ").trim();if(r.length<=t)return r;let i=r.slice(0,t),n=i.lastIndexOf(" ");return n>0?`${i.slice(0,n)}...`:`${i}...`}async function Ot(e,t,r=8000){let i=Date.now();try{let a=(await g(["evalraw",e,"Page.getFrameTree","{}"]).then((y)=>JSON.parse(y)).catch(()=>null))?.frameTree?.frame?.id||void 0,o=await g(["evalraw",e,"Network.loadNetworkResource",JSON.stringify({frameId:a,url:t,options:{disableCache:!0,includeCredentials:!1}})],20000),l=JSON.parse(o).resource;if(!l?.success||!l.httpStatusCode)return{url:t,error:l?.netErrorName||l?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-i,needsFallback:!0};let c="";if(l.stream)try{let y=await g(["evalraw",e,"IO.read",JSON.stringify({handle:l.stream})],1e4);c=JSON.parse(y).data||"",await g(["evalraw",e,"IO.close",JSON.stringify({handle:l.stream})]).catch(()=>{})}catch{}if(!c||c.length<100)return{url:t,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-i,needsFallback:!0};let u=F(l.httpStatusCode,c,t,t);if(u.blocked)return{url:t,status:l.httpStatusCode,error:`Blocked: ${u.reason}`,source:"chrome",duration:Date.now()-i,needsBrowser:!0};let p=await x(c,t),d=G(p);if(!d.ok)return{url:t,status:l.httpStatusCode,error:`Low quality: ${d.reason}`,source:"chrome",duration:Date.now()-i,needsBrowser:!0};let f=A(p.markdown,r);return{url:t,finalUrl:t,status:l.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:p.publishedTime||"",byline:p.byline||"",siteName:p.siteName||"",lang:p.lang||"",title:p.title||t,snippet:p.excerpt,content:f,contentChars:f.length,source:"chrome",duration:Date.now()-i}}catch(n){return{url:t,error:n.message,source:"chrome",duration:Date.now()-i,needsFallback:!0}}}function je(e){try{return new URL(e).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function Tt(e,t=8000){let r=j(e);if(r.blocked)return{url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,source:"pdf-http"};let i=new AbortController,n=setTimeout(()=>i.abort(),20000),a=Date.now();try{let o=await fetch(e,{method:"GET",redirect:"follow",signal:i.signal,headers:oe({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(n);let s=o.headers.get("content-type")||"",l=o.url||e,c=Number.parseInt(o.headers.get("content-length")||"0",10);if(o.status>=400)return{url:e,finalUrl:l,status:o.status,error:`HTTP ${o.status}`,source:"pdf-http",duration:Date.now()-a};if(!s.toLowerCase().includes("application/pdf")&&!je(l))return null;if(c>31457280)return{url:e,finalUrl:l,status:o.status,error:`PDF too large: ${c} bytes`,source:"pdf-http",duration:Date.now()-a};let u=Buffer.from(await o.arrayBuffer()),p=await ke(u,l);if(!p||p.error)return{url:e,finalUrl:l,status:o.status,error:p?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-a};let d=A(p.content,t);return{url:e,finalUrl:l,status:o.status,contentType:"application/pdf",lastModified:o.headers.get("last-modified")||"",title:p.title,snippet:z(d,320),content:d,contentChars:d.length,pages:p.pages,source:"pdf-http",duration:Date.now()-a}}catch(o){return clearTimeout(n),{url:e,finalUrl:e,error:o.message||String(o),source:"pdf-http",duration:Date.now()-a}}}async function Ft(e,t=8000){let r=Date.now();if(je(e)){let a=await Tt(e,t);if(a?.content||a?.status===403)return a}if(S(e)){let a=S(e);if(a&&(a.type==="root"||a.type==="tree"||a.type==="blob"&&!a.path?.includes("."))){let o=await ue(e);if(o.ok){let s=A(o.content,t);return{url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:o.title,snippet:s.slice(0,320),content:s,contentChars:s.length,source:"github-api",...o.tree&&{tree:o.tree},duration:Date.now()-r}}process.stderr.write(`[greedysearch] GitHub API fetch failed, trying HTTP: ${o.error}
|
|
353
|
+
`)}}if(fe(e)?.type==="post"){process.stderr.write(`[greedysearch] Using Reddit JSON API for: ${e.slice(0,60)}...
|
|
354
|
+
`);let a=await ge(e,t);if(a.ok){let o=A(a.markdown,t);return{url:e,finalUrl:a.finalUrl,status:a.status,contentType:"text/markdown",lastModified:a.lastModified||"",publishedTime:a.publishedTime||"",byline:a.byline||"",siteName:a.siteName||"",lang:a.lang||"",title:a.title,snippet:a.excerpt,content:o,contentChars:o.length,source:"reddit-api",duration:Date.now()-r}}process.stderr.write(`[greedysearch] Reddit API fetch failed, falling back to HTTP: ${a.error}
|
|
355
|
+
`)}let n=await se(e,{timeoutMs:1e4});if(n.ok){let a=A(n.markdown,t);return{url:e,finalUrl:n.finalUrl,status:n.status,contentType:"text/markdown",lastModified:n.lastModified||"",publishedTime:n.publishedTime||"",byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",title:n.title,snippet:n.excerpt,content:a,contentChars:a.length,source:"http",duration:Date.now()-r}}if(n.needsBrowser)try{let a=await C();try{let o=await Ot(a,e,t);if(o.content&&o.content.length>100)return o}finally{await L(a)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${e.slice(0,60)}, trying browser...
|
|
356
|
+
`),await xt(e,t)}async function Se(e,t=4000,r=200){let i=Date.now()+t;while(Date.now()<i){try{if((await g(["eval",e,'document.readyState === "complete" && !!document.body && document.body.innerText.length > 500'])).trim()==="true")return}catch{}await new Promise((n)=>setTimeout(n,r))}}async function xt(e,t=8000){let r=Date.now(),i;try{i=await C()}catch(n){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${n.message}`,source:"browser",duration:Date.now()-r}}try{await g(["nav",i,e],30000),await Se(i);let n=await g(["eval",i,String.raw`
|
|
280
357
|
(function(){
|
|
281
358
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
282
359
|
var text = (el || document.body).innerText;
|
|
@@ -286,16 +363,16 @@ ${o}`,pages:i.total}}catch(r){return{error:r.message||String(r)}}}function Z(e="
|
|
|
286
363
|
url: location.href
|
|
287
364
|
});
|
|
288
365
|
})()
|
|
289
|
-
`]),
|
|
290
|
-
`);let
|
|
291
|
-
`);let
|
|
292
|
-
`);else if(
|
|
293
|
-
`);
|
|
294
|
-
`)}}await Promise.all(Array.from({length:
|
|
295
|
-
`),
|
|
366
|
+
`]),a=JSON.parse(n),o=A(a.content,t);return{url:e,finalUrl:a.url||e,status:200,contentType:"text/plain",lastModified:"",title:a.title,snippet:z(o,320),content:o,contentChars:o.length,source:"browser",duration:Date.now()-r}}catch(n){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:n.message,source:"browser",duration:Date.now()-r}}finally{await L(i)}}async function ci(e,t=5,r=8000,i=K){let n=e.slice(0,t);if(n.length===0)return[];let a=Math.min(n.length,Math.max(1,Number.parseInt(String(i),10)||K));process.stderr.write(`[greedysearch] Fetching content from ${n.length} sources via HTTP (concurrency ${a})...
|
|
367
|
+
`);let o=Array(n.length),s=0,l=0;async function c(){while(!0){let f=s++;if(f>=n.length)return;let y=n[f],h=y.canonicalUrl||y.url;process.stderr.write(`[greedysearch] [${f+1}/${n.length}] Fetching: ${h.slice(0,60)}...
|
|
368
|
+
`);let m=await Ft(h,r).catch((w)=>({url:h,title:"",content:null,snippet:"",contentChars:0,error:w.message,source:"error",duration:0}));if(o[f]={id:y.id,...m},m.content&&m.content.length>100)process.stderr.write(`[greedysearch] ✓ ${m.source}: ${m.content.length} chars
|
|
369
|
+
`);else if(m.error)process.stderr.write(`[greedysearch] ✗ ${m.error.slice(0,80)}
|
|
370
|
+
`);l+=1,process.stderr.write(`PROGRESS:fetch:${l}/${n.length}
|
|
371
|
+
`)}}await Promise.all(Array.from({length:a},()=>c()));let u=o.filter((f)=>f.content&&f.content.length>100),p=o.filter((f)=>f.source==="http").length,d=o.filter((f)=>f.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${u.length}/${o.length} sources (HTTP: ${p}, Browser: ${d})
|
|
372
|
+
`),o}async function ui(e){let t=await C();try{await g(["nav",t,e],30000),await Se(t);let r=await g(["eval",t,String.raw`
|
|
296
373
|
(function(){
|
|
297
374
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
298
375
|
var text = (el || document.body).innerText;
|
|
299
376
|
return text.replace(/\s+/g, ' ').trim();
|
|
300
377
|
})()
|
|
301
|
-
`]);return{url:e,content:r}}catch(r){return{url:e,content:null,error:r.message}}finally{await
|
|
378
|
+
`]);return{url:e,content:r}}catch(r){return{url:e,content:null,error:r.message}}finally{await L(t)}}export{ui as fetchTopSource,Ft as fetchSourceContent,ci as fetchMultipleSources};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import p from"node:http";function m(s,a=1000){return new Promise((n)=>{let t=p.get(s,(d)=>{let r="";d.on("data",(c)=>r+=c),d.on("end",()=>n({ok:d.statusCode===200,body:r}))});t.on("error",()=>n({ok:!1})),t.setTimeout(a,()=>{t.destroy(),n({ok:!1})})})}async function y(s){try{let a=await m(`http://localhost:${s}/json/version`);if(!a.ok)return;let n=JSON.parse(a.body),t=await m(`http://localhost:${s}/json/list`);if(!t.ok)return;let r=JSON.parse(t.body).find((l)=>l.type==="page")?.id;if(!r)return;let c=n.webSocketDebuggerUrl;if(typeof c!=="string")return;let w=new URL(c);if(w.hostname!=="localhost"&&w.hostname!=="127.0.0.1")return;if(!/^ws:\/\/localhost:\d+/.test(`ws://${w.host}`))return;let e=new WebSocket(`ws://localhost:${s}${w.pathname}`);await new Promise((l)=>{let f=!1,u=setTimeout(()=>o(),5000),o=()=>{if(f)return;f=!0,clearTimeout(u);try{e.close()}catch{}l()};e.onopen=()=>{try{e.send(JSON.stringify({id:1,method:"Browser.getWindowForTarget",params:{targetId:r}}))}catch{o()}},e.onmessage=(h)=>{try{let i=JSON.parse(h.data);if(i.id===1&&i.result?.windowId)e.send(JSON.stringify({id:2,method:"Browser.setWindowBounds",params:{windowId:i.result.windowId,bounds:{windowState:"minimized"}}}));else if(i.id===2)o();else if(i.id===1)o()}catch{o()}},e.onerror=o})}catch{}}export{y as minimizeViaCDP,m as httpGet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as l}from"node:fs";import{dirname as s,join as o}from"node:path";import{fileURLToPath as u}from"node:url";function S(r){return u(new URL(".",r)).replace(/^\/([A-Z]:)/,"$1")}function f(r,e=l){let t=new Set;for(let n of r.filter(Boolean)){if(t.has(n))continue;if(t.add(n),e(n))return n}return r.filter(Boolean).at(-1)}function p(r,{moduleDir:e,entrypoint:t=process.argv[1],env:n=process.env,exists:a=l}={}){let c=t?s(t):null,i=n.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return f([e?o(e,"..","..","extractors",r):null,e?o(e,"..","extractors",r):null,i?o(i,"extractors",r):null,c?o(c,"..","extractors",r):null],a)}export{p as resolveGreedySearchExtractorScript,S as moduleDirectory};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createRequire as o}from"node:module";var s=o(import.meta.url);function l(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(e=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(e=void 0,a=0,r=0){this.data=e,this.width=a,this.height=r}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(e=void 0){}}}async function
|
|
1
|
+
import{createRequire as o}from"node:module";var s=o(import.meta.url);function l(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(e=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(e=void 0,a=0,r=0){this.data=e,this.width=a,this.height=r}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(e=void 0){}}}async function d(){l();let t=await import("pdf-parse"),e=t.PDFParse??t.default;if(!e)throw Error("pdf-parse did not export PDFParse");return e}async function p(t,e){try{let r=new(await d())({data:new Uint8Array(t)});await r.load();let n=await r.getText(),i=n.text?.trim();if(!i)return null;return{title:new URL(e).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${n.total} pages)
|
|
2
2
|
|
|
3
3
|
${i}`,pages:n.total}}catch(a){return{error:a.message||String(a)}}}export{p as extractPdfMarkdown};
|