@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.
Files changed (58) hide show
  1. package/dm +0 -0
  2. package/extensions/.dm-extensions.json +14 -10
  3. package/extensions/dm-cua/bin/browser-cua.mjs +6 -6
  4. package/extensions/dm-cua/index.js +5 -5
  5. package/extensions/dm-cua/src/browser-cua-lib.mjs +2 -2
  6. package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +8 -1
  7. package/extensions/greedysearch-dm/bin/cdp-headless.mjs +1 -1
  8. package/extensions/greedysearch-dm/bin/cdp-visible.mjs +1 -1
  9. package/extensions/greedysearch-dm/bin/cdp.mjs +29 -20
  10. package/extensions/greedysearch-dm/bin/gschrome.mjs +1 -8
  11. package/extensions/greedysearch-dm/bin/kill-visible.mjs +1 -1
  12. package/extensions/greedysearch-dm/bin/launch-visible.mjs +1 -2
  13. package/extensions/greedysearch-dm/bin/launch.mjs +9 -11
  14. package/extensions/greedysearch-dm/bin/mcp.mjs +375 -0
  15. package/extensions/greedysearch-dm/bin/search.mjs +309 -157
  16. package/extensions/greedysearch-dm/bin/visible.mjs +1 -1
  17. package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +205 -68
  18. package/extensions/greedysearch-dm/extractors/chatgpt.mjs +229 -140
  19. package/extensions/greedysearch-dm/extractors/common.mjs +160 -50
  20. package/extensions/greedysearch-dm/extractors/consensus.mjs +226 -93
  21. package/extensions/greedysearch-dm/extractors/consent.mjs +44 -17
  22. package/extensions/greedysearch-dm/extractors/gemini.mjs +277 -138
  23. package/extensions/greedysearch-dm/extractors/google-ai.mjs +172 -64
  24. package/extensions/greedysearch-dm/extractors/logically.mjs +183 -69
  25. package/extensions/greedysearch-dm/extractors/perplexity.mjs +331 -65
  26. package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +118 -41
  27. package/extensions/greedysearch-dm/index.js +23 -20
  28. package/extensions/greedysearch-dm/package.json +8 -3
  29. package/extensions/greedysearch-dm/skills/greedy-search/skill.md +8 -8
  30. package/extensions/greedysearch-dm/src/fetcher.mjs +2 -2
  31. package/extensions/greedysearch-dm/src/formatters/results.js +8 -6
  32. package/extensions/greedysearch-dm/src/github.mjs +7 -7
  33. package/extensions/greedysearch-dm/src/reddit.mjs +1 -1
  34. package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +10 -8
  35. package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +48 -0
  36. package/extensions/greedysearch-dm/src/search/chrome.mjs +130 -54
  37. package/extensions/greedysearch-dm/src/search/constants.mjs +6 -6
  38. package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
  39. package/extensions/greedysearch-dm/src/search/fetch-source.mjs +160 -83
  40. package/extensions/greedysearch-dm/src/search/minimize.mjs +1 -0
  41. package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
  42. package/extensions/greedysearch-dm/src/search/pdf.mjs +1 -1
  43. package/extensions/greedysearch-dm/src/search/port-pid.mjs +1 -1
  44. package/extensions/greedysearch-dm/src/search/progress.mjs +2 -0
  45. package/extensions/greedysearch-dm/src/search/recovery.mjs +1 -1
  46. package/extensions/greedysearch-dm/src/search/research.mjs +262 -167
  47. package/extensions/greedysearch-dm/src/search/scale-aware.mjs +11 -0
  48. package/extensions/greedysearch-dm/src/search/simple-research.mjs +827 -0
  49. package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +9 -9
  50. package/extensions/greedysearch-dm/src/search/synthesis.mjs +10 -10
  51. package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +23 -20
  52. package/extensions/greedysearch-dm/src/tools/shared.js +10 -9
  53. package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +1 -1
  54. package/package.json +1 -1
  55. package/extensions/greedysearch-dm/src/search/cdp-endpoint.mjs +0 -3
  56. package/extensions/greedysearch-dm/src/search/launcher-paths.mjs +0 -3
  57. package/extensions/greedysearch-dm/src/search/partial-output.mjs +0 -1
  58. package/extensions/greedysearch-dm/src/utils/browser-executable.mjs +0 -1
@@ -1,46 +1,46 @@
1
- import{createRequire as Re}from"node:module";var ke=Re(import.meta.url);import{Readability as Ce}from"@mozilla/readability";import{JSDOM as je}from"jsdom";import Oe from"turndown";var ee=new Oe({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});ee.addRule("removeDataUrls",{filter:(e)=>e.tagName==="IMG"&&e.getAttribute("src")?.startsWith("data:"),replacement:()=>""});var te="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",re={"user-agent":te,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"},Le=[/^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];function ne(e={}){return{...re,...e}}function L(e){try{let t=new URL(e),r=t.hostname.toLowerCase();for(let n of Le)if(n.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(t.protocol==="file:")return{blocked:!0,reason:"File protocol not allowed"};return{blocked:!1}}catch(t){return{blocked:!0,reason:`Invalid URL: ${t.message}`}}}function Te(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[n,i,o,a,...s]=r;if(o!=="blob")return e;let c=s.join("/");return`https://raw.githubusercontent.com/${n}/${i}/${a}/${c}`}catch{return e}}async function ie(e,t={}){let r=L(e);if(r.blocked)return{ok:!1,url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let n=e;if(e=Te(e),e!==n)console.error(`[fetcher] Rewrote GitHub URL: ${n.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:i=15000,userAgent:o,signal:a}=t,s=new AbortController,c=setTimeout(()=>s.abort(),i);if(a)a.addEventListener("abort",()=>s.abort(),{once:!0});try{let l=await fetch(e,{method:"GET",headers:{...re,"user-agent":o||te},redirect:"follow",signal:s.signal});clearTimeout(c);let f=l.headers.get("content-type")||"",u=l.url,d=l.headers.get("last-modified")||"",g=!1;try{g=new URL(u).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(f.includes("text/plain")&&g){let O=await l.text();return{ok:!0,url:n,finalUrl:u,status:l.status,title:u.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:d,lastModified:d,markdown:O,contentLength:O.length,excerpt:O.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!f.includes("text/html")&&!f.includes("application/xhtml"))return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Unsupported content type: ${f}`,needsBrowser:!1};let h=await l.text(),y=T(l.status,h,u,e);if(y.blocked)return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Blocked: ${y.reason}`,needsBrowser:!0};let p=F(h,u),E=x(p);if(!E.ok)return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Low quality content: ${E.reason}`,needsBrowser:!0};return{ok:!0,url:e,finalUrl:u,status:l.status,title:p.title,byline:p.byline,siteName:p.siteName,lang:p.lang,publishedTime:p.publishedTime||d,lastModified:d,markdown:p.markdown,excerpt:p.excerpt,contentLength:p.markdown.length,needsBrowser:!1}}catch(l){clearTimeout(c);let f=Me(l);return{ok:!1,url:e,finalUrl:e,status:0,error:l.message,needsBrowser:f}}}function T(e,t,r,n){let i=t.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",o=t.slice(0,30000).toLowerCase(),a=`${i} ${o}`;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 l of s)if(l.pattern.test(a))return{blocked:!0,reason:l.reason};let c=We(n,r,t);if(c)return{blocked:!0,reason:c};return{blocked:!1}}var Fe=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],xe=["login.","signin.","auth.","sso.","accounts.","idp."],Ge=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"];function We(e,t,r){try{let n=new URL(e),i=new URL(t);if(n.hostname.toLowerCase()===i.hostname.toLowerCase())return;let o=i.hostname.toLowerCase();if(Fe.some((s)=>o===s||o.endsWith(`.${s}`)))return`redirected to login (${i.hostname})`;if(xe.some((s)=>o.startsWith(s)))return`redirected to login (${i.hostname})`;let a=r.slice(0,20000).toLowerCase();if(Ge.some((s)=>a.includes(s)))return`redirected to login page (${i.hostname})`}catch{}return}function Me(e){let t=e.message.toLowerCase();return t.includes("fetch failed")||t.includes("unable to verify")||t.includes("certificate")||t.includes("timeout")}function z(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 n=e.querySelector(r),i=n?.getAttribute("content")||n?.getAttribute("datetime")||"";if(i)return i}return""}function F(e,t){let r=new je(e,{url:t}).window.document,n=new Ce(r).parse();if(n&&n.content){let o=ee.turndown(n.content).replaceAll(/\n{3,}/g,`
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(),a=n.publishedTime||z(r)||"";return{title:n.title||r.title||t,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:a,markdown:o,excerpt:o.slice(0,300).replaceAll(/\n/g," ")}}let i=r.body;if(i){let o=i.cloneNode(!0);o.querySelectorAll("script, style, nav, footer, header, aside").forEach((s)=>s.remove());let a=(o.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||t,byline:"",siteName:"",lang:"",publishedTime:z(r),markdown:a,excerpt:a.slice(0,300)}}return{title:t,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function x(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 n=t.toLowerCase(),i=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.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:o,desc:a}of i)if(o())return{ok:!1,reason:a};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 ae={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"};function P(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[n,i]=r;if(r.length===2)return{owner:n,repo:i,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let o=r[2],a=r[3],s=r.slice(4).join("/");return{owner:n,repo:i,type:o,ref:a,path:s}}return null}catch{return null}}async function _(e,t=1e4){let r=new AbortController,n=setTimeout(()=>r.abort(),t);try{let i=await fetch(`https://api.github.com${e}`,{headers:ae,signal:r.signal});if(clearTimeout(n),!i.ok)throw Error(`GitHub API ${i.status}: ${e}`);return await i.json()}catch(i){throw clearTimeout(n),i}}async function Ue(e,t){try{let r=await _(`/repos/${e}/${t}/readme`);if(r.content&&r.encoding==="base64")return Buffer.from(r.content,"base64").toString("utf8");return""}catch{return""}}async function oe(e,t,r="HEAD",n=""){try{let i=await _(`/repos/${e}/${t}/git/ref/heads/${r==="HEAD"?"main":r}`).catch(()=>_(`/repos/${e}/${t}/git/ref/heads/master`).catch(()=>null)),o;if(i?.object?.sha)o=(await _(`/repos/${e}/${t}/git/commits/${i.object.sha}`)).tree.sha;else{let s=await _(`/repos/${e}/${t}`);o=(await _(`/repos/${e}/${t}/branches/${s.default_branch}`)).commit.commit.tree.sha}let a=(await _(`/repos/${e}/${t}/git/trees/${o}`)).tree||[];if(n)a=a.filter((s)=>s.path.startsWith(n));return a.slice(0,50).map((s)=>({path:s.path,type:s.type==="tree"?"dir":"file",size:s.size}))}catch{return[]}}async function He(e,t,r,n,i=1e4){let o=[`https://raw.githubusercontent.com/${e}/${t}/${r&&r!=="HEAD"?r:"main"}/${n}`,`https://raw.githubusercontent.com/${e}/${t}/master/${n}`];for(let a of o){let s=new AbortController,c=setTimeout(()=>s.abort(),i);try{let l=await fetch(a,{headers:{"user-agent":ae["user-agent"]},signal:s.signal});if(clearTimeout(c),l.ok)return await l.text()}catch{clearTimeout(c)}}return null}async function se(e){let t=P(e);if(!t)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:n,type:i,ref:o,path:a}=t;try{if(i==="root"||i==="tree"&&!a){let[s,c,l]=await Promise.allSettled([_(`/repos/${r}/${n}`),Ue(r,n),oe(r,n,o||"HEAD")]);if(s.status==="rejected")return{ok:!1,error:s.reason?.message||"Repo not found"};let f=s.value,u=c.status==="fulfilled"?c.value:"",d=l.status==="fulfilled"?l.value:[],g=f?.description?`
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
- > ${f.description}`:"",h=f?.stargazers_count==null?"":` ⭐ ${f.stargazers_count}`,y=f?.language?` · ${f.language}`:"",p=`# ${r}/${n}${h}${y}${g}
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)p+=u.slice(0,6000);else p+=`[No README found]
7
+ `;if(u)h+=u.slice(0,6000);else h+=`[No README found]
8
8
 
9
9
  Files:
10
- ${d.map((E)=>` ${E.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${E.path}`).join(`
11
- `)}`;return{ok:!0,title:`${r}/${n}`,content:p,tree:d.slice(0,30)}}if(i==="blob"&&a){let s=await He(r,n,o,a);if(s===null)return{ok:!1,error:`File not found: ${a}`};return{ok:!0,title:`${r}/${n}: ${a}`,content:s}}if(i==="tree"&&a){let s=await oe(r,n,o||"HEAD",a),c=s.map((l)=>` ${l.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${l.path}`).join(`
12
- `);return{ok:!0,title:`${r}/${n}/${a}`,content:`[Directory: ${a}]
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:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{ok:!1,error:s.message}}}var Ye={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};function ce(e){try{let t=new URL(e),r=t.hostname.toLowerCase();if(!(r==="reddit.com"||r.endsWith(".reddit.com")))return null;let n=t.pathname;if(n.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:le(e)};if(n.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:le(e)};return null}catch{return null}}function le(e){try{let t=new URL(e);return`${t.protocol}//${t.hostname}${t.pathname}`}catch{return e}}async function ue(e,t=8000){let r=Date.now();try{let n=e.replaceAll(/\/?$/g,".json"),i=new AbortController,o=setTimeout(()=>i.abort(),15000),a=await fetch(n,{headers:Ye,signal:i.signal});if(clearTimeout(o),!a.ok)throw Error(`Reddit API ${a.status}`);let s=await a.json();if(!Array.isArray(s)||s.length<1)throw Error("Invalid Reddit API response structure");let c=s[0],l=s[1],f=c?.data?.children?.[0]?.data;if(!f)throw Error("No post data in Reddit response");let u=Je(f,l,t);return{ok:!0,url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:f.title||"Reddit Post",byline:`u/${f.author}`,siteName:`r/${f.subreddit}`,lang:"en",publishedTime:new Date(f.created_utc*1000).toISOString(),excerpt:f.selftext?.slice(0,300).replace(/\n/g," ")||"",markdown:u,contentLength:u.length,needsBrowser:!1,duration:Date.now()-r}}catch(n){return{ok:!1,url:e,finalUrl:e,status:0,error:`Reddit fetch failed: ${n.message}`,needsBrowser:!1,duration:Date.now()-r}}}function Je(e,t,r){let n="";if(n+=`# ${e.title}
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
- `,n+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
17
+ `,i+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
18
18
 
19
- `,e.selftext)n+=e.selftext,n+=`
19
+ `,e.selftext)i+=e.selftext,i+=`
20
20
 
21
- `;else if(e.url)try{let i=new URL(e.url).hostname.toLowerCase();if(i!=="reddit.com"&&!i.endsWith(".reddit.com"))n+=`**Link:** ${e.url}
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{n+=`**Link:** ${e.url}
23
+ `}catch{i+=`**Link:** ${e.url}
24
24
 
25
- `}if(t?.data?.children?.length>0){n+=`---
25
+ `}if(t?.data?.children?.length>0){i+=`---
26
26
 
27
27
  ## Comments
28
28
 
29
- `;let i=t.data.children.filter((o)=>o.kind==="t1").slice(0,10);for(let o of i)n+=fe(o.data,0),n+=`
30
- `}if(n.length>r)n=n.slice(0,r).trim()+`
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 n}function fe(e,t){if(!e||e.body==="[deleted]"||e.body==="[removed]")return"";let r="> ".repeat(t),n="";if(n+=`${r}**u/${e.author}** (${e.score} pts)
33
- `,n+=`${r}${e.body.replaceAll(`
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 i=e.replies.data.children.filter((o)=>o.kind==="t1");for(let o of i.slice(0,5))n+=`
37
- `+fe(o.data,t+1)}return n}function $(e,t=8000){if(!e||e.length<=t)return e;let r=`
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
- `,n=t-r.length,i=Math.floor(n*0.75),o=n-i,a=i;while(a>i-100&&e[a]!==`
42
- `)a--;if(a<=i-100)a=i;let s=e.length-o;while(s<e.length-o+100&&e[s]!==`
43
- `)s++;if(s>=e.length-o+100)s=e.length-o;let c=e.slice(0,a).trimEnd(),l=e.slice(s).trimStart();return`${c}${r}${l}`}import{platform as Wt,tmpdir as Be}from"node:os";import{spawn as Ve}from"node:child_process";import{dirname as qe,join as Ke}from"node:path";import{fileURLToPath as Xe}from"node:url";import{basename as Qe}from"node:path";import{existsSync as S,mkdirSync as rt,readFileSync as he,writeFileSync as nt}from"node:fs";import{homedir as it}from"node:os";import{join as ye}from"node:path";import{tmpdir as A}from"node:os";import{platform as ir,tmpdir as ct}from"node:os";import{existsSync as N,mkdirSync as ut,readFileSync as be,writeFileSync as ft}from"node:fs";import{homedir as pt}from"node:os";import{join as ve}from"node:path";import{tmpdir as I}from"node:os";function Ze(e=process.env,t=process.execPath){let r=e.GREEDY_SEARCH_NODE||e.NODE_BINARY||e.NODE;if(r?.trim())return r.trim();let n=Qe(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}var ze=qe(Xe(import.meta.url)),et=Ke(ze,"..","bin","cdp.mjs");function de(e,t=30000){return tt(e,null,t)}function tt(e,t=null,r=30000){return new Promise((n,i)=>{let o=Ve(Ze(),[et,...e],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)o.stdin.write(t),o.stdin.end();let a="",s="";o.stdout.on("data",(l)=>a+=l),o.stderr.on("data",(l)=>s+=l);let c=setTimeout(()=>{o.kill(),i(Error(`cdp timeout: ${e[0]}`))},r);o.on("close",(l)=>{if(clearTimeout(c),l===0)n(a.trim());else i(Error(s.trim()||`cdp exit ${l}`))})})}async function pe(e){await de(["evalraw",e,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
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 does not expose a useful webdriver value.
55
- // A literal false value is itself a common stealth tell; prefer undefined and
56
- // make the descriptor configurable like native browser properties.
57
- Object.defineProperty(navigator, 'webdriver', { get: () => undefined, configurable: true });
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
- var p = [
65
- { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
66
- { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' },
67
- { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' },
68
- ];
69
- p.length = 3;
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
- var m = [
76
- { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null },
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() % 997) + Math.floor(Math.random() * 997)) & 1;
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
- // Add 1px noise pixel in corner (invisible but changes hash)
159
- var imgData = ctx.getImageData(0, 0, 1, 1);
160
- if (imgData) imgData.data[0] ^= __canvasNoise;
161
- ctx.putImageData(imgData, 0, 0);
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
- if (!screen.colorDepth) Object.defineProperty(screen, 'colorDepth', { get: () => 24, configurable: true });
178
- if (!screen.pixelDepth) Object.defineProperty(screen, 'pixelDepth', { get: () => 24, configurable: true });
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 ot(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var Kt=ot(process.env.GREEDY_SEARCH_PORT,9222),we=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${A().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),Xt=`${we}/DevToolsActivePort`,Qt=`${A().replaceAll("\\","/")}/cdp-pages.json`,Zt=process.env.GREEDY_SEARCH_MODE_FILE||`${A().replaceAll("\\","/")}/greedysearch-chrome-mode`,zt=`${A().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,M=ye(it(),".dm"),w=ye(M,"greedyconfig"),U=["perplexity","google","chatgpt"],H="gemini";function at(){try{if(S(w)){let e=he(w,"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)=>G[i]),n=t.engines.filter((i)=>!G[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${w}: ${n.join(", ")}
252
- [greedysearch] Available engines: ${Object.keys(G).join(", ")}
253
- `);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${w}, falling back to defaults: ${U.join(", ")}
254
- `)}}}catch{}return U}function st(){try{if(!S(M))rt(M,{recursive:!0});if(!S(w))nt(w,JSON.stringify({engines:U,synthesizer:H},null,2)+`
255
- `,"utf8")}catch{}}st();var ge=["gemini","chatgpt"];function lt(){try{if(S(w)){let e=he(w,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(ge.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${w}
256
- [greedysearch] Available synthesizers: ${ge.join(", ")}
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 W={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},mr=mt(),dr=ht(),hr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=_e;var D=ct().replaceAll("\\","/"),yr=`${D}/greedysearch-chrome-metadata.json`,wr=`${D}/greedysearch-chrome-launch.lock`;var br=`${D}/greedysearch-chrome.pid`,vr=`${D}/greedysearch-chrome-mode`,_r=`${D}/greedysearch-chrome-last-activity`;var Er=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var $r=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Ee=Be().replaceAll("\\","/"),Dr=`${Ee}/greedysearch-chrome.pid`,Pr=`${Ee}/greedysearch-chrome-last-activity`,Sr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Nr=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;var m=de;async function $e(){let e=(await m(["list"])).split(`
266
- `)[0];if(!e)throw Error("No Chrome tabs found");return e.slice(0,8)}async function R(e="about:blank"){let t=await $e(),r=new URL(e).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let o=await m(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:a}=JSON.parse(o),s=a.slice(0,8);if(await m(["list"]).catch(()=>null),r==="copilot.microsoft.com")await pe(s);else pe(s).catch(()=>{});return await m(["list"]).catch(()=>null),a}let n=await m(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:i}=JSON.parse(n);return await m(["list"]).catch(()=>null),i}async function k(e){try{let t=await $e();await m(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}import{existsSync as C,mkdirSync as yt,readFileSync as Pe,writeFileSync as wt}from"node:fs";import{homedir as bt}from"node:os";import{join as Se}from"node:path";import{tmpdir as j}from"node:os";function vt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var jr=vt(process.env.GREEDY_SEARCH_PORT,9222),Ne=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${j().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),Or=`${Ne}/DevToolsActivePort`,Lr=`${j().replaceAll("\\","/")}/cdp-pages.json`,Tr=process.env.GREEDY_SEARCH_MODE_FILE||`${j().replaceAll("\\","/")}/greedysearch-chrome-mode`,Fr=`${j().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,q=Se(bt(),".dm"),v=Se(q,"greedyconfig"),K=["perplexity","google","chatgpt"],X="gemini";function _t(){try{if(C(v)){let e=Pe(v,"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)=>V[i]),n=t.engines.filter((i)=>!V[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${n.join(", ")}
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 ${v}, falling back to defaults: ${K.join(", ")}
269
- `)}}}catch{}return K}function Et(){try{if(!C(q))yt(q,{recursive:!0});if(!C(v))wt(v,JSON.stringify({engines:K,synthesizer:X},null,2)+`
270
- `,"utf8")}catch{}}Et();var De=["gemini","chatgpt"];function $t(){try{if(C(v)){let e=Pe(v,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(De.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${v}
271
- [greedysearch] Available synthesizers: ${De.join(", ")}
272
- [greedysearch] Falling back to default: ${X}
273
- `)}}}catch{}return X}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=_t();var Gr=$t(),Q=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=Ne;function Dt(){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,n=0){this.data=t,this.width=r,this.height=n}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(t=void 0){}}}async function Pt(){Dt();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 Ae(e,t){try{let n=new(await Pt())({data:new Uint8Array(e)});await n.load();let i=await n.getText(),o=i.text?.trim();if(!o)return null;return{title:new URL(t).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${i.total} pages)
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
- ${o}`,pages:i.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 n=r.slice(0,t),i=n.lastIndexOf(" ");return i>0?`${n.slice(0,i)}...`:`${n}...`}async function St(e,t,r=8000){let n=Date.now();try{let o=(await m(["evalraw",e,"Page.getFrameTree","{}"]).then((h)=>JSON.parse(h)).catch(()=>null))?.frameTree?.frame?.id||void 0,a=await m(["evalraw",e,"Network.loadNetworkResource",JSON.stringify({frameId:o,url:t,options:{disableCache:!0,includeCredentials:!1}})],20000),c=JSON.parse(a).resource;if(!c?.success||!c.httpStatusCode)return{url:t,error:c?.netErrorName||c?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-n,needsFallback:!0};let l="";if(c.stream)try{let h=await m(["evalraw",e,"IO.read",JSON.stringify({handle:c.stream})],1e4);l=JSON.parse(h).data||"",await m(["evalraw",e,"IO.close",JSON.stringify({handle:c.stream})]).catch(()=>{})}catch{}if(!l||l.length<100)return{url:t,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-n,needsFallback:!0};let f=T(c.httpStatusCode,l,t,t);if(f.blocked)return{url:t,status:c.httpStatusCode,error:`Blocked: ${f.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let u=F(l,t),d=x(u);if(!d.ok)return{url:t,status:c.httpStatusCode,error:`Low quality: ${d.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let g=$(u.markdown,r);return{url:t,finalUrl:t,status:c.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:u.publishedTime||"",byline:u.byline||"",siteName:u.siteName||"",lang:u.lang||"",title:u.title||t,snippet:u.excerpt,content:g,contentChars:g.length,source:"chrome",duration:Date.now()-n}}catch(i){return{url:t,error:i.message,source:"chrome",duration:Date.now()-n,needsFallback:!0}}}function Ie(e){try{return new URL(e).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function Nt(e,t=8000){let r=L(e);if(r.blocked)return{url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,source:"pdf-http"};let n=new AbortController,i=setTimeout(()=>n.abort(),20000),o=Date.now();try{let a=await fetch(e,{method:"GET",redirect:"follow",signal:n.signal,headers:ne({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(i);let s=a.headers.get("content-type")||"",c=a.url||e,l=Number.parseInt(a.headers.get("content-length")||"0",10);if(a.status>=400)return{url:e,finalUrl:c,status:a.status,error:`HTTP ${a.status}`,source:"pdf-http",duration:Date.now()-o};if(!s.toLowerCase().includes("application/pdf")&&!Ie(c))return null;if(l>31457280)return{url:e,finalUrl:c,status:a.status,error:`PDF too large: ${l} bytes`,source:"pdf-http",duration:Date.now()-o};let f=Buffer.from(await a.arrayBuffer()),u=await Ae(f,c);if(!u||u.error)return{url:e,finalUrl:c,status:a.status,error:u?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-o};let d=$(u.content,t);return{url:e,finalUrl:c,status:a.status,contentType:"application/pdf",lastModified:a.headers.get("last-modified")||"",title:u.title,snippet:Z(d,320),content:d,contentChars:d.length,pages:u.pages,source:"pdf-http",duration:Date.now()-o}}catch(a){return clearTimeout(i),{url:e,finalUrl:e,error:a.message||String(a),source:"pdf-http",duration:Date.now()-o}}}async function At(e,t=8000){let r=Date.now();if(Ie(e)){let o=await Nt(e,t);if(o?.content||o?.status===403)return o}if(P(e)){let o=P(e);if(o&&(o.type==="root"||o.type==="tree"||o.type==="blob"&&!o.path?.includes("."))){let a=await se(e);if(a.ok){let s=$(a.content,t);return{url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:a.title,snippet:s.slice(0,320),content:s,contentChars:s.length,source:"github-api",...a.tree&&{tree:a.tree},duration:Date.now()-r}}process.stderr.write(`[greedysearch] GitHub API fetch failed, trying HTTP: ${a.error}
276
- `)}}if(ce(e)?.type==="post"){process.stderr.write(`[greedysearch] Using Reddit JSON API for: ${e.slice(0,60)}...
277
- `);let o=await ue(e,t);if(o.ok){let a=$(o.markdown,t);return{url:e,finalUrl:o.finalUrl,status:o.status,contentType:"text/markdown",lastModified:o.lastModified||"",publishedTime:o.publishedTime||"",byline:o.byline||"",siteName:o.siteName||"",lang:o.lang||"",title:o.title,snippet:o.excerpt,content:a,contentChars:a.length,source:"reddit-api",duration:Date.now()-r}}process.stderr.write(`[greedysearch] Reddit API fetch failed, falling back to HTTP: ${o.error}
278
- `)}let i=await ie(e,{timeoutMs:1e4});if(i.ok){let o=$(i.markdown,t);return{url:e,finalUrl:i.finalUrl,status:i.status,contentType:"text/markdown",lastModified:i.lastModified||"",publishedTime:i.publishedTime||"",byline:i.byline||"",siteName:i.siteName||"",lang:i.lang||"",title:i.title,snippet:i.excerpt,content:o,contentChars:o.length,source:"http",duration:Date.now()-r}}if(i.needsBrowser)try{let o=await R();try{let a=await St(o,e,t);if(a.content&&a.content.length>100)return a}finally{await k(o)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${e.slice(0,60)}, trying browser...
279
- `),await It(e,t)}async function It(e,t=8000){let r=Date.now(),n;try{n=await R()}catch(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${i.message}`,source:"browser",duration:Date.now()-r}}try{await m(["nav",n,e],30000),await new Promise((s)=>setTimeout(s,800));let i=await m(["eval",n,String.raw`
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
- `]),o=JSON.parse(i),a=$(o.content,t);return{url:e,finalUrl:o.url||e,status:200,contentType:"text/plain",lastModified:"",title:o.title,snippet:Z(a,320),content:a,contentChars:a.length,source:"browser",duration:Date.now()-r}}catch(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:i.message,source:"browser",duration:Date.now()-r}}finally{await k(n)}}async function Qr(e,t=5,r=8000,n=Q){let i=e.slice(0,t);if(i.length===0)return[];let o=Math.min(i.length,Math.max(1,Number.parseInt(String(n),10)||Q));process.stderr.write(`[greedysearch] Fetching content from ${i.length} sources via HTTP (concurrency ${o})...
290
- `);let a=Array(i.length),s=0,c=0;async function l(){while(!0){let g=s++;if(g>=i.length)return;let h=i[g],y=h.canonicalUrl||h.url;process.stderr.write(`[greedysearch] [${g+1}/${i.length}] Fetching: ${y.slice(0,60)}...
291
- `);let p=await At(y,r).catch((E)=>({url:y,title:"",content:null,snippet:"",contentChars:0,error:E.message,source:"error",duration:0}));if(a[g]={id:h.id,...p},p.content&&p.content.length>100)process.stderr.write(`[greedysearch] ✓ ${p.source}: ${p.content.length} chars
292
- `);else if(p.error)process.stderr.write(`[greedysearch] ✗ ${p.error.slice(0,80)}
293
- `);c+=1,process.stderr.write(`PROGRESS:fetch:${c}/${i.length}
294
- `)}}await Promise.all(Array.from({length:o},()=>l()));let f=a.filter((g)=>g.content&&g.content.length>100),u=a.filter((g)=>g.source==="http").length,d=a.filter((g)=>g.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${f.length}/${a.length} sources (HTTP: ${u}, Browser: ${d})
295
- `),a}async function Zr(e){let t=await R();await m(["list"]);try{await m(["nav",t,e],30000),await new Promise((n)=>setTimeout(n,800));let r=await m(["eval",t,String.raw`
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 k(t)}}export{Zr as fetchTopSource,At as fetchSourceContent,Qr as fetchMultipleSources};
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 H}from"node:fs";import{dirname as K,join as C}from"node:path";import{fileURLToPath as M}from"node:url";function W(k){return M(new URL(".",k)).replace(/^\/([A-Z]:)/,"$1")}function N(k,w=H){let A=new Set;for(let z of k.filter(Boolean)){if(A.has(z))continue;if(A.add(z),w(z))return z}return k.filter(Boolean).at(-1)}function X(k,{moduleDir:w,entrypoint:A=process.argv[1],env:z=process.env,exists:I=H}={}){let F=A?K(A):null,G=z.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,J=[w?C(w,"..","..","extractors",k):null,w?C(w,"..","extractors",k):null,G?C(G,"extractors",k):null,F?C(F,"..","extractors",k):null];return N(J,I)}export{X as resolveGreedySearchExtractorScript,W as moduleDirectory};
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 c(){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 c())({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)
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};