@duckmind/dm-darwin-x64 0.52.3 → 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 (56) hide show
  1. package/dm +0 -0
  2. package/extensions/.dm-extensions.json +15 -8
  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 -10
  11. package/extensions/greedysearch-dm/bin/kill-visible.mjs +1 -1
  12. package/extensions/greedysearch-dm/bin/launch-visible.mjs +1 -4
  13. package/extensions/greedysearch-dm/bin/launch.mjs +9 -5
  14. package/extensions/greedysearch-dm/bin/mcp.mjs +375 -0
  15. package/extensions/greedysearch-dm/bin/search.mjs +310 -156
  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 +225 -92
  21. package/extensions/greedysearch-dm/extractors/consent.mjs +44 -17
  22. package/extensions/greedysearch-dm/extractors/gemini.mjs +275 -136
  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 +20 -17
  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 -9
  35. package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +48 -0
  36. package/extensions/greedysearch-dm/src/search/chrome.mjs +129 -53
  37. package/extensions/greedysearch-dm/src/search/constants.mjs +8 -8
  38. package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
  39. package/extensions/greedysearch-dm/src/search/fetch-source.mjs +154 -77
  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 -0
  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 +11 -11
  50. package/extensions/greedysearch-dm/src/search/synthesis.mjs +11 -11
  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/utils/browser-executable.mjs +0 -1
@@ -1,18 +1,18 @@
1
- import{createRequire as Ie}from"node:module";var Re=Ie(import.meta.url);import{Readability as je}from"@mozilla/readability";import{JSDOM as Ce}from"jsdom";import Le from"turndown";var ee=new Le({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"},Oe=[/^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 ie(e={}){return{...re,...e}}function O(e){try{let t=new URL(e),r=t.hostname.toLowerCase();for(let i of Oe)if(i.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[i,n,o,a,...s]=r;if(o!=="blob")return e;let c=s.join("/");return`https://raw.githubusercontent.com/${i}/${n}/${a}/${c}`}catch{return e}}async function ne(e,t={}){let r=O(e);if(r.blocked)return{ok:!1,url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let i=e;if(e=Te(e),e!==i)console.error(`[fetcher] Rewrote GitHub URL: ${i.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:n=15000,userAgent:o,signal:a}=t,s=new AbortController,c=setTimeout(()=>s.abort(),n);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,m=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 L=await l.text();return{ok:!0,url:i,finalUrl:u,status:l.status,title:u.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:m,lastModified:m,markdown:L,contentLength:L.length,excerpt:L.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),_=x(p);if(!_.ok)return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Low quality content: ${_.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||m,lastModified:m,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,i){let n=t.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",o=t.slice(0,30000).toLowerCase(),a=`${n} ${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(i,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 i=new URL(e),n=new URL(t);if(i.hostname.toLowerCase()===n.hostname.toLowerCase())return;let o=n.hostname.toLowerCase();if(Fe.some((s)=>o===s||o.endsWith(`.${s}`)))return`redirected to login (${n.hostname})`;if(xe.some((s)=>o.startsWith(s)))return`redirected to login (${n.hostname})`;let a=r.slice(0,20000).toLowerCase();if(Ge.some((s)=>a.includes(s)))return`redirected to login page (${n.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 i=e.querySelector(r),n=i?.getAttribute("content")||i?.getAttribute("datetime")||"";if(n)return n}return""}function F(e,t){let r=new Ce(e,{url:t}).window.document,i=new je(r).parse();if(i&&i.content){let o=ee.turndown(i.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=i.publishedTime||z(r)||"";return{title:i.title||r.title||t,byline:i.byline||"",siteName:i.siteName||"",lang:i.lang||"",publishedTime:a,markdown:o,excerpt:o.slice(0,300).replaceAll(/\n/g," ")}}let n=r.body;if(n){let o=n.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 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:o,desc:a}of n)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 D(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 o=r[2],a=r[3],s=r.slice(4).join("/");return{owner:i,repo:n,type:o,ref:a,path:s}}return null}catch{return null}}async function $(e,t=1e4){let r=new AbortController,i=setTimeout(()=>r.abort(),t);try{let n=await fetch(`https://api.github.com${e}`,{headers:ae,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 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",i=""){try{let n=await $(`/repos/${e}/${t}/git/ref/heads/${r==="HEAD"?"main":r}`).catch(()=>$(`/repos/${e}/${t}/git/ref/heads/master`).catch(()=>null)),o;if(n?.object?.sha)o=(await $(`/repos/${e}/${t}/git/commits/${n.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(i)a=a.filter((s)=>s.path.startsWith(i));return a.slice(0,50).map((s)=>({path:s.path,type:s.type==="tree"?"dir":"file",size:s.size}))}catch{return[]}}async function Je(e,t,r,i,n=1e4){let o=[`https://raw.githubusercontent.com/${e}/${t}/${r&&r!=="HEAD"?r:"main"}/${i}`,`https://raw.githubusercontent.com/${e}/${t}/master/${i}`];for(let a of o){let s=new AbortController,c=setTimeout(()=>s.abort(),n);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=D(e);if(!t)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:i,type:n,ref:o,path:a}=t;try{if(n==="root"||n==="tree"&&!a){let[s,c,l]=await Promise.allSettled([$(`/repos/${r}/${i}`),Ue(r,i),oe(r,i,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:"",m=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}/${i}${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
- ${m.map((_)=>` ${_.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${_.path}`).join(`
11
- `)}`;return{ok:!0,title:`${r}/${i}`,content:p,tree:m.slice(0,30)}}if(n==="blob"&&a){let s=await Je(r,i,o,a);if(s===null)return{ok:!1,error:`File not found: ${a}`};return{ok:!0,title:`${r}/${i}: ${a}`,content:s}}if(n==="tree"&&a){let s=await oe(r,i,o||"HEAD",a),c=s.map((l)=>` ${l.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${l.path}`).join(`
12
- `);return{ok:!0,title:`${r}/${i}/${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 He={"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 i=t.pathname;if(i.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:le(e)};if(i.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 i=e.replaceAll(/\/?$/g,".json"),n=new AbortController,o=setTimeout(()=>n.abort(),15000),a=await fetch(i,{headers:He,signal:n.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=Be(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(i){return{ok:!1,url:e,finalUrl:e,status:0,error:`Reddit fetch failed: ${i.message}`,needsBrowser:!1,duration:Date.now()-r}}}function Be(e,t,r){let i="";if(i+=`# ${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
17
  `,i+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
18
18
 
@@ -26,21 +26,21 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
26
26
 
27
27
  ## Comments
28
28
 
29
- `;let n=t.data.children.filter((o)=>o.kind==="t1").slice(0,10);for(let o of n)i+=fe(o.data,0),i+=`
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
30
  `}if(i.length>r)i=i.slice(0,r).trim()+`
31
31
 
32
- ... (truncated)`;return i}function fe(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)
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
33
  `,i+=`${r}${e.body.replaceAll(`
34
34
  `,`
35
35
  `+r)}
36
- `,t<3&&e.replies?.data?.children){let n=e.replies.data.children.filter((o)=>o.kind==="t1");for(let o of n.slice(0,5))i+=`
37
- `+fe(o.data,t+1)}return i}function P(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
- `,i=t-r.length,n=Math.floor(i*0.75),o=i-n,a=n;while(a>n-100&&e[a]!==`
42
- `)a--;if(a<=n-100)a=n;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 Ft,tmpdir as Ye}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 Ze}from"node:path";import{existsSync as S,mkdirSync as rt,readFileSync as he,writeFileSync as it}from"node:fs";import{homedir as nt}from"node:os";import{join as ye}from"node:path";import{tmpdir as k}from"node:os";import{platform as er,tmpdir as lt}from"node:os";import{existsSync as N,mkdirSync as ct,readFileSync as ve,writeFileSync as ut}from"node:fs";import{homedir as ft}from"node:os";import{join as be}from"node:path";import{tmpdir as A}from"node:os";function Qe(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=Ze(t||"").toLowerCase();if(i==="node"||i==="node.exe")return t;return"node"}var ze=qe(Xe(import.meta.url)),et=Ke(ze,"..","bin","cdp.mjs");function me(e,t=30000){return tt(e,null,t)}function tt(e,t=null,r=30000){return new Promise((i,n)=>{let o=Ve(Qe(),[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(),n(Error(`cdp timeout: ${e[0]}`))},r);o.on("close",(l)=>{if(clearTimeout(c),l===0)i(a.trim());else n(Error(s.trim()||`cdp exit ${l}`))})})}async function pe(e){await me(["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
- `})])}var we=`${k().replaceAll("\\","/")}/greedysearch-chrome-profile`,Yt=`${we}/DevToolsActivePort`,Vt=`${k().replaceAll("\\","/")}/cdp-pages.json`,qt=`${k().replaceAll("\\","/")}/greedysearch-chrome-mode`,Kt=`${k().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,M=ye(nt(),".dm"),w=ye(M,"greedyconfig"),U=["perplexity","google","chatgpt"],J="gemini";function ot(){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((n)=>G[n]),i=t.engines.filter((n)=>!G[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${w}: ${i.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 at(){try{if(!S(M))rt(M,{recursive:!0});if(!S(w))it(w,JSON.stringify({engines:U,synthesizer:J},null,2)+`
255
- `,"utf8")}catch{}}at();var ge=["gemini","chatgpt"];function st(){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: ${J}
258
- `)}}}catch{}return J}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"},Xt=ot(),Zt=st(),Qt=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=we;var $e=`${A().replaceAll("\\","/")}/greedysearch-chrome-profile`,or=`${$e}/DevToolsActivePort`,ar=`${A().replaceAll("\\","/")}/cdp-pages.json`,sr=`${A().replaceAll("\\","/")}/greedysearch-chrome-mode`,lr=`${A().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,H=be(ft(),".dm"),v=be(H,"greedyconfig"),B=["perplexity","google","chatgpt"],Y="gemini";function pt(){try{if(N(v)){let e=ve(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((n)=>W[n]),i=t.engines.filter((n)=>!W[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${i.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 ${v}, falling back to defaults: ${B.join(", ")}
261
- `)}}}catch{}return B}function gt(){try{if(!N(H))ct(H,{recursive:!0});if(!N(v))ut(v,JSON.stringify({engines:B,synthesizer:Y},null,2)+`
262
- `,"utf8")}catch{}}gt();var de=["gemini","chatgpt"];function dt(){try{if(N(v)){let e=ve(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}
263
- [greedysearch] Available synthesizers: ${de.join(", ")}
264
- [greedysearch] Falling back to default: ${Y}
265
- `)}}}catch{}return Y}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"},cr=pt(),ur=dt(),fr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=$e;var E=lt().replaceAll("\\","/"),pr=`${E}/greedysearch-chrome-metadata.json`,gr=`${E}/greedysearch-chrome-launch.lock`;var dr=`${E}/greedysearch-chrome.pid`,mr=`${E}/greedysearch-chrome-mode`,hr=`${E}/greedysearch-chrome-last-activity`;var yr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var wr=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),_e=Ye().replaceAll("\\","/"),vr=`${_e}/greedysearch-chrome.pid`,br=`${_e}/greedysearch-chrome-last-activity`,$r=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,_r=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;var d=me;async function Pe(){let e=(await d(["list"])).split(`
266
- `)[0];if(!e)throw Error("No Chrome tabs found");return e.slice(0,8)}async function I(e="about:blank"){let t=await Pe(),r=new URL(e).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let o=await d(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:a}=JSON.parse(o),s=a.slice(0,8);if(await d(["list"]).catch(()=>null),r==="copilot.microsoft.com")await pe(s);else pe(s).catch(()=>{});return await d(["list"]).catch(()=>null),a}let i=await d(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:n}=JSON.parse(i);return await d(["list"]).catch(()=>null),n}async function R(e){try{let t=await Pe();await d(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}import{existsSync as j,mkdirSync as mt,readFileSync as De,writeFileSync as ht}from"node:fs";import{homedir as yt}from"node:os";import{join as Se}from"node:path";import{tmpdir as C}from"node:os";var Ne=`${C().replaceAll("\\","/")}/greedysearch-chrome-profile`,kr=`${Ne}/DevToolsActivePort`,Ar=`${C().replaceAll("\\","/")}/cdp-pages.json`,Ir=`${C().replaceAll("\\","/")}/greedysearch-chrome-mode`,Rr=`${C().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,q=Se(yt(),".dm"),b=Se(q,"greedyconfig"),K=["perplexity","google","chatgpt"],X="gemini";function wt(){try{if(j(b)){let e=De(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((n)=>V[n]),i=t.engines.filter((n)=>!V[n]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${b}: ${i.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(", ")}
334
+ [greedysearch] Falling back to default: ${B}
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 ${b}, falling back to defaults: ${K.join(", ")}
269
- `)}}}catch{}return K}function vt(){try{if(!j(q))mt(q,{recursive:!0});if(!j(b))ht(b,JSON.stringify({engines:K,synthesizer:X},null,2)+`
270
- `,"utf8")}catch{}}vt();var Ee=["gemini","chatgpt"];function bt(){try{if(j(b)){let e=De(b,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(Ee.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${b}
271
- [greedysearch] Available synthesizers: ${Ee.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"},jr=wt();var Cr=bt(),Z=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=Ne;function $t(){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 _t(){$t();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 _t())({data:new Uint8Array(e)});await i.load();let n=await i.getText(),o=n.text?.trim();if(!o)return null;return{title:new URL(t).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${n.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:n.total}}catch(r){return{error:r.message||String(r)}}}function Q(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 Pt(e,t,r=8000){let i=Date.now();try{let o=(await d(["evalraw",e,"Page.getFrameTree","{}"]).then((h)=>JSON.parse(h)).catch(()=>null))?.frameTree?.frame?.id||void 0,a=await d(["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()-i,needsFallback:!0};let l="";if(c.stream)try{let h=await d(["evalraw",e,"IO.read",JSON.stringify({handle:c.stream})],1e4);l=JSON.parse(h).data||"",await d(["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()-i,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()-i,needsBrowser:!0};let u=F(l,t),m=x(u);if(!m.ok)return{url:t,status:c.httpStatusCode,error:`Low quality: ${m.reason}`,source:"chrome",duration:Date.now()-i,needsBrowser:!0};let g=P(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()-i}}catch(n){return{url:t,error:n.message,source:"chrome",duration:Date.now()-i,needsFallback:!0}}}function Ae(e){try{return new URL(e).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function Et(e,t=8000){let r=O(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),o=Date.now();try{let a=await fetch(e,{method:"GET",redirect:"follow",signal:i.signal,headers:ie({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(n);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")&&!Ae(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 ke(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 m=P(u.content,t);return{url:e,finalUrl:c,status:a.status,contentType:"application/pdf",lastModified:a.headers.get("last-modified")||"",title:u.title,snippet:Q(m,320),content:m,contentChars:m.length,pages:u.pages,source:"pdf-http",duration:Date.now()-o}}catch(a){return clearTimeout(n),{url:e,finalUrl:e,error:a.message||String(a),source:"pdf-http",duration:Date.now()-o}}}async function Dt(e,t=8000){let r=Date.now();if(Ae(e)){let o=await Et(e,t);if(o?.content||o?.status===403)return o}if(D(e)){let o=D(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=P(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=P(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 n=await ne(e,{timeoutMs:1e4});if(n.ok){let o=P(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:o,contentChars:o.length,source:"http",duration:Date.now()-r}}if(n.needsBrowser)try{let o=await I();try{let a=await Pt(o,e,t);if(a.content&&a.content.length>100)return a}finally{await R(o)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${e.slice(0,60)}, trying browser...
279
- `),await St(e,t)}async function St(e,t=8000){let r=Date.now(),i;try{i=await I()}catch(n){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${n.message}`,source:"browser",duration:Date.now()-r}}try{await d(["nav",i,e],30000),await new Promise((s)=>setTimeout(s,800));let n=await d(["eval",i,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:n.total}}catch(r){return{error:r.message||String(r)}}}function Q(e="
286
363
  url: location.href
287
364
  });
288
365
  })()
289
- `]),o=JSON.parse(n),a=P(o.content,t);return{url:e,finalUrl:o.url||e,status:200,contentType:"text/plain",lastModified:"",title:o.title,snippet:Q(a,320),content:a,contentChars:a.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 R(i)}}async function Br(e,t=5,r=8000,i=Z){let n=e.slice(0,t);if(n.length===0)return[];let o=Math.min(n.length,Math.max(1,Number.parseInt(String(i),10)||Z));process.stderr.write(`[greedysearch] Fetching content from ${n.length} sources via HTTP (concurrency ${o})...
290
- `);let a=Array(n.length),s=0,c=0;async function l(){while(!0){let g=s++;if(g>=n.length)return;let h=n[g],y=h.canonicalUrl||h.url;process.stderr.write(`[greedysearch] [${g+1}/${n.length}] Fetching: ${y.slice(0,60)}...
291
- `);let p=await Dt(y,r).catch((_)=>({url:y,title:"",content:null,snippet:"",contentChars:0,error:_.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}/${n.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,m=a.filter((g)=>g.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${f.length}/${a.length} sources (HTTP: ${u}, Browser: ${m})
295
- `),a}async function Yr(e){let t=await I();await d(["list"]);try{await d(["nav",t,e],30000),await new Promise((i)=>setTimeout(i,800));let r=await d(["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 R(t)}}export{Yr as fetchTopSource,Dt as fetchSourceContent,Br 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};
@@ -0,0 +1 @@
1
+ import{execFileSync as g}from"node:child_process";import{platform as b}from"node:os";import{existsSync as s}from"node:fs";import{platform as o}from"node:os";import{join as e}from"node:path";function p(t){let r=o()==="win32",n=process.env.SystemRoot||"C:\\Windows",u={win32:{powershell:e(n,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:e(n,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:e(n,"System32","netstat.exe"),taskkill:e(n,"System32","taskkill.exe"),tasklist:e(n,"System32","tasklist.exe"),cmd:e(n,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},i=r?u.win32:u.unix,f=t.toLowerCase();if(i[f]&&s(i[f]))return i[f];if(r&&f==="netstat"){let l=e(n,"Sysnative","netstat.exe");if(s(l))return l}return t}function C(t,r){return g(p(t),r,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function I(t){let r=String(t||"").match(/\b(\d+)\b/);return r?Number.parseInt(r[1],10):null}function N(t){return I(t)}function P(t,r){for(let n of String(t||"").split(/\r?\n/)){if(!/\bLISTEN\b/i.test(n))continue;if(!n.trim().split(/\s+/).slice(0,6).some((f)=>f.endsWith(`:${r}`)))continue;let i=n.match(/\bpid=(\d+)\b/);if(i)return Number.parseInt(i[1],10)}return null}function T(t,r){for(let n of String(t||"").split(/\r?\n/)){let u=n.trim().split(/\s+/);if(u.length<5||u[0].toUpperCase()!=="TCP")continue;if(!u.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!u[1].endsWith(`:${r}`))continue;let i=Number.parseInt(u.at(-1),10);if(Number.isInteger(i)&&i>0)return i}return null}function c(t,r,n){try{return t(r,n)}catch{return null}}function E(t,{platformName:r=b(),run:n=C}={}){if(r==="win32")return T(c(n,"netstat",["-ano","-p","TCP"]),t);let u=c(n,"lsof",["-nP",`-iTCP:${t}`,"-sTCP:LISTEN","-t"]),i=N(u);if(i)return i;if(r!=="linux")return null;return P(c(n,"ss",["-ltnp"]),t)}export{P as parseSsPid,T as parseNetstatPid,N as parseLsofPid,E as findListeningProcessPid};
@@ -0,0 +1,2 @@
1
+ function F(G){if(G<1000)return"0s";let q=Math.round(G/1000);if(q<60)return`${q}s`;let H=Math.floor(q/60),K=q%60;return`${H}m ${K}s`}function y(G,q=20){let H=Math.round(G*q),K=q-H;return"["+"█".repeat(H)+"░".repeat(K)+"]"}function L({totalActions:G=0,totalRounds:q=0,totalFetches:H=0,silent:K=!1}={}){let X=Date.now(),Y=0,U=0,Z=0,J=[],x=null,O=null,$=0,V=500;function B(j){if(J.push(j),J.length>5)J.shift()}function k(){if(J.length===0)return null;return J.reduce((j,C)=>j+C,0)/J.length}function v(j){let C=Date.now()-X,Q=G+H+q,W=Y+Z+U,I=Q>0?Math.min(1,W/Q):0,N=y(I),D=k(),P=Math.max(0,Q-W),E=D?D*P:null,_=E?F(E):"—",f=O?` ${O}`:"";return`${N} ${W}/${Q} (${j}${f}, ETA ${_})`}function z(j){if(K)return;let C=Date.now();if(C-$<V&&j!=="done")return;$=C,process.stderr.write(`[greedysearch] ${v(j)}
2
+ `)}return{startRound(j){U=j-1},endRound(){U++,z("round")},startAction(j,C){x=Date.now(),O=`${j}:${(C||"").slice(0,40)}`,z(j)},endAction(){if(x)B(Date.now()-x),x=null;Y++,z("action")},startFetch(j){x=Date.now(),O=`fetch:${(j||"").slice(0,40)}`,z("fetch")},endFetch(j=!0){if(x)B(Date.now()-x),x=null;Z++,z(j?"fetch":"fetch-failed")},print(){z("progress")},finish(){z("done")},getElapsedMs(){return Date.now()-X}}}export{L as createProgressTracker};
@@ -1 +1 @@
1
- var X=["perplexity","bing","chatgpt","semantic-scholar","logically"],Z=/timed out|timeout|verification|captcha|cloudflare|turnstile|input not found|ask-input|clipboard|copy button hidden|sign.in|login required/i,$=/needs-human|verification required|please solve|captcha|cloudflare|turnstile|could not be completed automatically|manual intervention|sign.in|login required/i;function W(q){return Z.test(String(q||""))}function j(q){return $.test(String(q||""))}function m(q){return X.filter((z)=>{let J=q?.[z];if(!J)return!1;if(J._envelope?.blockedBy)return!0;if(J._envelope?.verificationResult==="needs-human")return!0;let Q=J.error;return Q&&W(Q)})}function w(q){if(!q)return!1;let z=q.envelope;if(z?.blockedBy)return!0;if(z?.verificationResult==="needs-human")return!0;return W(q.message)}export{j as isManualVerificationError,w as isHeadlessBlockedResult,W as isHeadlessBlockedError,m as findHeadlessBlockedEngines,X as HEADLESS_RECOVERY_ENGINES};
1
+ var J=["perplexity","bing","chatgpt","semantic-scholar","logically"],q=new Set(["rate-limit"]),Q=/timed out|timeout|verification|captcha|cloudflare|turnstile|input not found|ask-input|copy button hidden|sign.in|login required/i,W=/needs-human|verification required|please solve|captcha|cloudflare|turnstile|could not be completed automatically|manual intervention|sign.in|login required/i;function z(f){return Q.test(String(f||""))}function X(f){return W.test(String(f||""))}function Z(f){return q.has(f)}function $(f){return J.filter((h)=>{let j=f?.[h];if(!j)return!1;let w=j._envelope?.blockedBy;if(w){if(q.has(w))return!1;return!0}if(j._envelope?.verificationResult==="needs-human")return!0;let x=j.error;return x&&z(x)})}function m(f){if(!f)return!1;let h=f.envelope;if(h?.blockedBy){if(q.has(h.blockedBy))return!1;return!0}if(h?.verificationResult==="needs-human")return!0;return z(f.message)}export{Z as isNonRecoverableBlockedBy,X as isManualVerificationError,m as isHeadlessBlockedResult,z as isHeadlessBlockedError,$ as findHeadlessBlockedEngines,J as HEADLESS_RECOVERY_ENGINES};