@duckmind/dm-windows-x64 0.59.9 → 0.60.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,46 @@
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,`
1
+ import{createRequire as Ne}from"node:module";var I=Ne(import.meta.url);import{createRequire as Re}from"node:module";var Bt=Re(import.meta.url),S=null;async function Ce(){if(S)return S;let[{Readability:e},{JSDOM:t},{default:r}]=await Promise.all([import("@mozilla/readability"),import("jsdom"),import("turndown")]),n=new r({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});return n.addRule("removeDataUrls",{filter:(i)=>i.tagName==="IMG"&&i.getAttribute("src")?.startsWith("data:"),replacement:()=>""}),S={Readability:e,JSDOM:t,turndown:n},S}var ne="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",ie={"user-agent":ne,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((i)=>Te.test(i)))return null;let r=t.map((i)=>{if(/^0x/i.test(i))return parseInt(i,16);if(/^0[0-7]+$/.test(i))return parseInt(i,8);return parseInt(i,10)});if(r.some((i)=>!Number.isFinite(i)||i<0))return null;let n;if(r.length===1){if(r[0]>4294967295)return null;n=[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;n=[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;n=[r[0],r[1],r[2]>>>8&255,r[2]&255]}else{if(r.some((i)=>i>255))return null;n=r}return n.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 n=parseInt(r[1],16),i=parseInt(r[2],16);if(n>65535||i>65535)return null;return[n>>>8&255,n&255,i>>>8&255,i&255].join(".")}return null}function te(e){return ae.some((t)=>t.test(e))}function oe(e={}){return{...ie,...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 i of ae)if(i.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(r.startsWith("[")&&r.endsWith("]")){let i=r.slice(1,-1),a=xe(i);if(a&&te(a))return{blocked:!0,reason:`Private/internal address: ${r} (maps to ${a})`}}let n=Fe(r);if(n&&te(n))return{blocked:!0,reason:`Private/internal address: ${r} (normalizes to ${n})`};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[n,i,a,o,...s]=r;if(a!=="blob")return e;let l=s.join("/");return`https://raw.githubusercontent.com/${n}/${i}/${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 n=e;if(e=Ge(e),e!==n)console.error(`[fetcher] Rewrote GitHub URL: ${n.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:i=15000,userAgent:a,signal:o}=t,s=new AbortController,l=setTimeout(()=>s.abort(),i);if(o)o.addEventListener("abort",()=>s.abort(),{once:!0});try{let c=await fetch(e,{method:"GET",headers:{...ie,"user-agent":a||ne},redirect:"follow",signal:s.signal});clearTimeout(l);let u=c.headers.get("content-type")||"",f=c.url,d=c.headers.get("last-modified")||"",p=j(f);if(p.blocked)return{ok:!1,url:e,finalUrl:f,status:c.status,error:`Blocked: ${p.reason}`,needsBrowser:!1};let h=!1;try{h=new URL(f).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(u.includes("text/plain")&&h){let T=await c.text();return{ok:!0,url:n,finalUrl:f,status:c.status,title:f.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:f,status:c.status,error:`Unsupported content type: ${u}`,needsBrowser:!1};let y=await c.text(),m=F(c.status,y,f,e);if(m.blocked)return{ok:!1,url:e,finalUrl:f,status:c.status,error:`Blocked: ${m.reason}`,needsBrowser:!0};let w=await x(y,f),ee=G(w);if(!ee.ok)return{ok:!1,url:e,finalUrl:f,status:c.status,error:`Low quality content: ${ee.reason}`,needsBrowser:!0};return{ok:!0,url:e,finalUrl:f,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,n){let i=t.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",a=t.slice(0,30000).toLowerCase(),o=`${i} ${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(n,r,t);if(l)return{blocked:!0,reason:l};return{blocked:!1}}var He=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],Me=["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 n=new URL(e),i=new URL(t);if(n.hostname.toLowerCase()===i.hostname.toLowerCase())return;let a=i.hostname.toLowerCase();if(He.some((s)=>a===s||a.endsWith(`.${s}`)))return`redirected to login (${i.hostname})`;if(Me.some((s)=>a.startsWith(s)))return`redirected to login (${i.hostname})`;let o=r.slice(0,20000).toLowerCase();if(We.some((s)=>o.includes(s)))return`redirected to login page (${i.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 n=e.querySelector(r),i=n?.getAttribute("content")||n?.getAttribute("datetime")||"";if(i)return i}return""}async function x(e,t){let{Readability:r,JSDOM:n,turndown:i}=await Ce(),a=new n(e,{url:t});try{let o=a.window.document,s=new r(o).parse();if(s&&s.content){let c=i.turndown(s.content).replaceAll(/\n{3,}/g,`
2
2
 
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?`
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((f)=>f.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 n=t.toLowerCase(),i=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(t),desc:"login form only"}];for(let{check:a,desc:o}of i)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 k(e){try{let t=new URL(e);if(!(t.hostname==="github.com"||t.hostname.endsWith(".github.com")))return null;let r=t.pathname.split("/").filter(Boolean);if(r.length<2)return null;let[n,i]=r;if(r.length===2)return{owner:n,repo:i,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let a=r[2],o=r[3],s=r.slice(4).join("/");return{owner:n,repo:i,type:a,ref:o,path:s}}return null}catch{return null}}async function b(e,t=1e4){let r=new AbortController,n=setTimeout(()=>r.abort(),t);try{let i=await fetch(`https://api.github.com${e}`,{headers:ce,signal:r.signal});if(clearTimeout(n),!i.ok)throw Error(`GitHub API ${i.status}: ${e}`);return await i.json()}catch(i){throw clearTimeout(n),i}}async function Ue(e,t){try{let r=await 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",n="",i){try{let a;if(r==="HEAD")if(i)a=await b(`/repos/${e}/${t}/git/ref/heads/${i}`).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(n)s=s.filter((l)=>l.path.startsWith(n));return s.slice(0,50).map((l)=>({path:l.path,type:l.type==="tree"?"dir":"file",size:l.size}))}catch{return[]}}async function Je(e,t,r,n,i=1e4,a){let o=async(l)=>{let c=new AbortController,u=setTimeout(()=>c.abort(),i);try{let f=await fetch(l,{headers:{"user-agent":ce["user-agent"]},signal:c.signal});if(clearTimeout(u),f.ok)return await f.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}/${n}`)}catch{return null}try{return await Promise.any([o(`https://raw.githubusercontent.com/${e}/${t}/main/${n}`),o(`https://raw.githubusercontent.com/${e}/${t}/master/${n}`)])}catch{return null}}let s=[`https://raw.githubusercontent.com/${e}/${t}/${r}/${n}`,`https://raw.githubusercontent.com/${e}/${t}/master/${n}`];for(let l of s)try{return await o(l)}catch{}return null}async function ue(e){let t=k(e);if(!t)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:n,type:i,ref:a,path:o}=t;try{if(i==="root"||i==="tree"&&!o){let s=await b(`/repos/${r}/${n}`),[l,c]=await Promise.allSettled([Ue(r,n),le(r,n,a||"HEAD","",s.default_branch)]),u=l.status==="fulfilled"?l.value:"",f=c.status==="fulfilled"?c.value:[],d=s?.description?`
4
4
 
5
- > ${s.description}`:"",f=s?.stargazers_count==null?"":` ⭐ ${s.stargazers_count}`,y=s?.language?` · ${s.language}`:"",h=`# ${r}/${i}${f}${y}${d}
5
+ > ${s.description}`:"",p=s?.stargazers_count==null?"":` ⭐ ${s.stargazers_count}`,h=s?.language?` · ${s.language}`:"",y=`# ${r}/${n}${p}${h}${d}
6
6
 
7
- `;if(u)h+=u.slice(0,6000);else h+=`[No README found]
7
+ `;if(u)y+=u.slice(0,6000);else y+=`[No README found]
8
8
 
9
9
  Files:
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}]
10
+ ${f.map((m)=>` ${m.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${m.path}`).join(`
11
+ `)}`;return{ok:!0,title:`${r}/${n}`,content:y,tree:f.slice(0,30)}}if(i==="blob"&&o){let s;if(!a||a==="HEAD")try{s=(await b(`/repos/${r}/${n}`)).default_branch}catch{s=void 0}let l=await Je(r,n,a,o,1e4,s);if(l===null)return{ok:!1,error:`File not found: ${o}`};return{ok:!0,title:`${r}/${n}: ${o}`,content:l}}if(i==="tree"&&o){let s;if(!a||a==="HEAD")try{s=(await b(`/repos/${r}/${n}`)).default_branch}catch{s=void 0}let l=await le(r,n,a||"HEAD",o,s),c=l.map((u)=>` ${u.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${u.path}`).join(`
12
+ `);return{ok:!0,title:`${r}/${n}/${o}`,content:`[Directory: ${o}]
13
13
 
14
14
  Files:
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}
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 pe(e){try{let t=new URL(e),r=t.hostname.toLowerCase();if(!(r==="reddit.com"||r.endsWith(".reddit.com")))return null;let n=t.pathname;if(n.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:fe(e)};if(n.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:fe(e)};return null}catch{return null}}function fe(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 n=e.replace(/\/+$/,"")+".json",i=new AbortController,a=setTimeout(()=>i.abort(),15000),o=await fetch(n,{headers:qe,signal:i.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 f=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:f,contentLength:f.length,needsBrowser:!1,duration:Date.now()-r}}catch(n){return{ok:!1,url:e,finalUrl:e,status:0,error:`Reddit fetch failed: ${n.message}`,needsBrowser:!1,duration:Date.now()-r}}}function Ve(e,t,r){let n="";if(n+=`# ${e.title}
16
16
 
17
- `,i+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
17
+ `,n+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
18
18
 
19
- `,e.selftext)i+=e.selftext,i+=`
19
+ `,e.selftext)n+=e.selftext,n+=`
20
20
 
21
- `;else if(e.url)try{let n=new URL(e.url).hostname.toLowerCase();if(n!=="reddit.com"&&!n.endsWith(".reddit.com"))i+=`**Link:** ${e.url}
21
+ `;else if(e.url)try{let i=new URL(e.url).hostname.toLowerCase();if(i!=="reddit.com"&&!i.endsWith(".reddit.com"))n+=`**Link:** ${e.url}
22
22
 
23
- `}catch{i+=`**Link:** ${e.url}
23
+ `}catch{n+=`**Link:** ${e.url}
24
24
 
25
- `}if(t?.data?.children?.length>0){i+=`---
25
+ `}if(t?.data?.children?.length>0){n+=`---
26
26
 
27
27
  ## Comments
28
28
 
29
- `;let n=t.data.children.filter((a)=>a.kind==="t1").slice(0,10);for(let a of n)i+=de(a.data,0),i+=`
30
- `}if(i.length>r)i=i.slice(0,r).trim()+`
29
+ `;let i=t.data.children.filter((a)=>a.kind==="t1").slice(0,10);for(let a of i)n+=de(a.data,0),n+=`
30
+ `}if(n.length>r)n=n.slice(0,r).trim()+`
31
31
 
32
- ... (truncated)`;return i}function de(e,t){if(!e||e.body==="[deleted]"||e.body==="[removed]")return"";let r="> ".repeat(t),i="";if(i+=`${r}**u/${e.author}** (${e.score} pts)
33
- `,i+=`${r}${e.body.replaceAll(`
32
+ ... (truncated)`;return n}function de(e,t){if(!e||e.body==="[deleted]"||e.body==="[removed]")return"";let r="> ".repeat(t),n="";if(n+=`${r}**u/${e.author}** (${e.score} pts)
33
+ `,n+=`${r}${e.body.replaceAll(`
34
34
  `,`
35
35
  `+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=`
36
+ `,t<3&&e.replies?.data?.children){let i=e.replies.data.children.filter((a)=>a.kind==="t1");for(let a of i.slice(0,5))n+=`
37
+ `+de(a.data,t+1)}return n}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),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:`
41
+ `,n=t-r.length,i=Math.floor(n*0.75),a=n-i,o=i;while(o>i-100&&e[o]!==`
42
+ `)o--;if(o<=i-100)o=i;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{fileURLToPath as ot}from"node:url";import{existsSync as N,mkdirSync as lt,readFileSync as ve,writeFileSync as ct}from"node:fs";import{homedir as ut}from"node:os";import{join as _e}from"node:path";import{tmpdir as ft}from"node:os";import{existsSync as R,mkdirSync as yt,readFileSync as Ee,writeFileSync as wt}from"node:fs";import{homedir as bt}from"node:os";import{join as $e}from"node:path";import{tmpdir as vt}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 n=Xe(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}var tt=Qe(ze(import.meta.url)),rt=Ke(tt,"..","bin","cdp.mjs"),nt=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function it(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(!nt.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 n=it(e);return new Promise((i,a)=>{let o=Ze(et(),[rt,...n],{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)i(s.trim());else a(Error(l.trim()||`cdp exit ${u}`))})})}async function he(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(_) {}
@@ -325,35 +325,35 @@ ${c}`,tree:l}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
325
325
  };
326
326
  } catch(_) {}
327
327
  })();
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(", ")}
328
+ `})])}function st(e){return ot(new URL(".",e)).replace(/^\/([A-Z]:)/,"$1")}function pt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var gt=ft().replaceAll("\\","/"),ir=pt(process.env.GREEDY_SEARCH_PORT),v=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${gt}/greedysearch-chrome-profile`).replaceAll("\\","/"),ar=`${v}/DevToolsActivePort`,or=process.env.GREEDY_SEARCH_PID_FILE||`${v}/browser.pid`,sr=process.env.CDP_PAGES_CACHE||`${v}/cdp-pages.json`,lr=process.env.GREEDY_SEARCH_MODE_FILE||`${v}/browser-mode`,cr=process.env.GREEDY_SEARCH_METADATA_FILE||`${v}/browser-metadata.json`,ur=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${v}/browser-launch.lock`,fr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${v}/browser-last-activity`,pr=(process.env.CDP_SOCKET_DIR||`${v}/cdp-sockets`).replaceAll("\\","/"),gr=`${v}/visible-recovery.jsonl`,W=_e(ut(),".dm"),$=_e(W,"greedyconfig"),Y=["perplexity","google","chatgpt","gemini"],B="gemini";function dt(){try{if(N($)){let e=ve($,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((i)=>H[i]),n=t.engines.filter((i)=>!H[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${$}: ${n.join(", ")}
329
+ [greedysearch] Available engines: ${Object.keys(H).join(", ")}
330
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(", ")}
331
+ `)}}}catch{}return Y}function mt(){try{if(!N(W))lt(W,{recursive:!0});if(!N($))ct($,JSON.stringify({engines:Y,synthesizer:B},null,2)+`
332
+ `,"utf8")}catch{}}mt();var ye=["gemini","chatgpt"];function ht(){try{if(N($)){let e=ve($,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(ye.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${$}
333
+ [greedysearch] Available synthesizers: ${ye.join(", ")}
334
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}
335
+ `)}}}catch{}return B}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"},dr=dt(),mr=ht(),hr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=v;function _t(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var Et=vt().replaceAll("\\","/"),_r=_t(process.env.GREEDY_SEARCH_PORT),_=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Et}/greedysearch-chrome-profile`).replaceAll("\\","/"),Er=`${_}/DevToolsActivePort`,$r=process.env.GREEDY_SEARCH_PID_FILE||`${_}/browser.pid`,Dr=process.env.CDP_PAGES_CACHE||`${_}/cdp-pages.json`,Pr=process.env.GREEDY_SEARCH_MODE_FILE||`${_}/browser-mode`,Ar=process.env.GREEDY_SEARCH_METADATA_FILE||`${_}/browser-metadata.json`,Ir=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${_}/browser-launch.lock`,Sr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${_}/browser-last-activity`,jr=(process.env.CDP_SOCKET_DIR||`${_}/cdp-sockets`).replaceAll("\\","/"),kr=`${_}/visible-recovery.jsonl`,U=$e(bt(),".dm"),D=$e(U,"greedyconfig"),J=["perplexity","google","chatgpt","gemini"],q="gemini";function $t(){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((i)=>M[i]),n=t.engines.filter((i)=>!M[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${D}: ${n.join(", ")}
336
+ [greedysearch] Available engines: ${Object.keys(M).join(", ")}
337
+ `);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${D}, falling back to defaults: ${J.join(", ")}
338
+ `)}}}catch{}return J}function Dt(){try{if(!R(U))yt(U,{recursive:!0});if(!R(D))wt(D,JSON.stringify({engines:J,synthesizer:q},null,2)+`
339
+ `,"utf8")}catch{}}Dt();var we=["gemini","chatgpt"];function Pt(){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
340
  [greedysearch] Available synthesizers: ${we.join(", ")}
341
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(", ")}
342
+ `)}}}catch{}return q}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"},Nr=$t(),Rr=Pt(),Cr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=_;var Lr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Or=st(import.meta.url);var Tr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Fr=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 he(s);else he(s).catch(()=>{});return await g(["list"]).catch(()=>null),o}let n=await g(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:i}=JSON.parse(n);return await g(["list"]).catch(()=>null),i}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 At,readFileSync as Ae,writeFileSync as It}from"node:fs";import{homedir as St}from"node:os";import{join as Ie}from"node:path";import{tmpdir as jt}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 Nt=jt().replaceAll("\\","/"),Yr=kt(process.env.GREEDY_SEARCH_PORT),E=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Nt}/greedysearch-chrome-profile`).replaceAll("\\","/"),Br=`${E}/DevToolsActivePort`,Ur=process.env.GREEDY_SEARCH_PID_FILE||`${E}/browser.pid`,Jr=process.env.CDP_PAGES_CACHE||`${E}/cdp-pages.json`,qr=process.env.GREEDY_SEARCH_MODE_FILE||`${E}/browser-mode`,Vr=process.env.GREEDY_SEARCH_METADATA_FILE||`${E}/browser-metadata.json`,Zr=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${E}/browser-launch.lock`,Xr=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${E}/browser-last-activity`,Qr=(process.env.CDP_SOCKET_DIR||`${E}/cdp-sockets`).replaceAll("\\","/"),Kr=`${E}/visible-recovery.jsonl`,Z=Ie(St(),".dm"),P=Ie(Z,"greedyconfig"),X=["perplexity","google","chatgpt","gemini"],Q="gemini";function Rt(){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((i)=>V[i]),n=t.engines.filter((i)=>!V[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${P}: ${n.join(", ")}
344
344
  [greedysearch] Available engines: ${Object.keys(V).join(", ")}
345
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}
346
+ `)}}}catch{}return X}function Ct(){try{if(!O(Z))At(Z,{recursive:!0});if(!O(P))It(P,JSON.stringify({engines:X,synthesizer:Q},null,2)+`
347
+ `,"utf8")}catch{}}Ct();var Pe=["gemini","chatgpt"];function Lt(){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
348
  [greedysearch] Available synthesizers: ${Pe.join(", ")}
349
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)
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"},zr=Rt();var en=Lt(),K=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=E;function Ot(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(t=void 0){}multiplySelf(){return this}preMultiplySelf(){return this}translateSelf(){return this}scaleSelf(){return this}rotateSelf(){return this}};if(typeof globalThis.ImageData>"u")globalThis.ImageData=class{constructor(t=void 0,r=0,n=0){this.data=t,this.width=r,this.height=n}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(t=void 0){}}}async function Tt(){Ot();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 Se(e,t){try{let n=new(await Tt())({data:new Uint8Array(e)});await n.load();let i=await n.getText(),a=i.text?.trim();if(!a)return null;return{title:new URL(t).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${i.total} pages)
351
351
 
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)}...
352
+ ${a}`,pages:i.total}}catch(r){return{error:r.message||String(r)}}}function z(e="",t=240){let r=String(e).replaceAll(/\s+/g," ").trim();if(r.length<=t)return r;let n=r.slice(0,t),i=n.lastIndexOf(" ");return i>0?`${n.slice(0,i)}...`:`${n}...`}async function Ft(e,t,r=8000){let n=Date.now();try{let a=(await g(["evalraw",e,"Page.getFrameTree","{}"]).then((h)=>JSON.parse(h)).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()-n,needsFallback:!0};let c="";if(l.stream)try{let h=await g(["evalraw",e,"IO.read",JSON.stringify({handle:l.stream})],1e4);c=JSON.parse(h).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()-n,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()-n,needsBrowser:!0};let f=await x(c,t),d=G(f);if(!d.ok)return{url:t,status:l.httpStatusCode,error:`Low quality: ${d.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let p=A(f.markdown,r);return{url:t,finalUrl:t,status:l.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:f.publishedTime||"",byline:f.byline||"",siteName:f.siteName||"",lang:f.lang||"",title:f.title||t,snippet:f.excerpt,content:p,contentChars:p.length,source:"chrome",duration:Date.now()-n}}catch(i){return{url:t,error:i.message,source:"chrome",duration:Date.now()-n,needsFallback:!0}}}function je(e){try{return new URL(e).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function xt(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 n=new AbortController,i=setTimeout(()=>n.abort(),20000),a=Date.now();try{let o=await fetch(e,{method:"GET",redirect:"follow",signal:n.signal,headers:oe({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(i);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()),f=await Se(u,l);if(!f||f.error)return{url:e,finalUrl:l,status:o.status,error:f?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-a};let d=A(f.content,t);return{url:e,finalUrl:l,status:o.status,contentType:"application/pdf",lastModified:o.headers.get("last-modified")||"",title:f.title,snippet:z(d,320),content:d,contentChars:d.length,pages:f.pages,source:"pdf-http",duration:Date.now()-a}}catch(o){return clearTimeout(i),{url:e,finalUrl:e,error:o.message||String(o),source:"pdf-http",duration:Date.now()-a}}}async function Gt(e,t=8000){let r=Date.now();if(je(e)){let a=await xt(e,t);if(a?.content||a?.status===403)return a}if(k(e)){let a=k(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(pe(e)?.type==="post"){process.stderr.write(`[greedysearch] Using Reddit JSON API for: ${e.slice(0,60)}...
354
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`
355
+ `)}let i=await se(e,{timeoutMs:1e4});if(i.ok){let a=A(i.markdown,t);return{url:e,finalUrl:i.finalUrl,status:i.status,contentType:"text/markdown",lastModified:i.lastModified||"",publishedTime:i.publishedTime||"",byline:i.byline||"",siteName:i.siteName||"",lang:i.lang||"",title:i.title,snippet:i.excerpt,content:a,contentChars:a.length,source:"http",duration:Date.now()-r}}if(i.needsBrowser)try{let a=await C();try{let o=await Ft(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 Ht(e,t)}async function ke(e,t=4000,r=200){let n=Date.now()+t;while(Date.now()<n){try{if((await g(["eval",e,'document.readyState === "complete" && !!document.body && document.body.innerText.length > 500'])).trim()==="true")return}catch{}await new Promise((i)=>setTimeout(i,r))}}async function Ht(e,t=8000){let r=Date.now(),n;try{n=await C()}catch(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${i.message}`,source:"browser",duration:Date.now()-r}}try{await g(["nav",n,e],30000),await ke(n);let i=await g(["eval",n,String.raw`
357
357
  (function(){
358
358
  var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
359
359
  var text = (el || document.body).innerText;
@@ -363,16 +363,16 @@ ${a}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function z(e="
363
363
  url: location.href
364
364
  });
365
365
  })()
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
366
+ `]),a=JSON.parse(i),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(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:i.message,source:"browser",duration:Date.now()-r}}finally{await L(n)}}async function gn(e,t=5,r=8000,n=K){let i=e.slice(0,t);if(i.length===0)return[];let a=Math.min(i.length,Math.max(1,Number.parseInt(String(n),10)||K));process.stderr.write(`[greedysearch] Fetching content from ${i.length} sources via HTTP (concurrency ${a})...
367
+ `);let o=Array(i.length),s=0,l=0;async function c(){while(!0){let p=s++;if(p>=i.length)return;let h=i[p],y=h.canonicalUrl||h.url;process.stderr.write(`[greedysearch] [${p+1}/${i.length}] Fetching: ${y.slice(0,60)}...
368
+ `);let m=await Gt(y,r).catch((w)=>({url:y,title:"",content:null,snippet:"",contentChars:0,error:w.message,source:"error",duration:0}));if(o[p]={id:h.id,...m},m.content&&m.content.length>100)process.stderr.write(`[greedysearch] ✓ ${m.source}: ${m.content.length} chars
369
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`
370
+ `);l+=1,process.stderr.write(`PROGRESS:fetch:${l}/${i.length}
371
+ `)}}await Promise.all(Array.from({length:a},()=>c()));let u=o.filter((p)=>p.content&&p.content.length>100),f=o.filter((p)=>p.source==="http").length,d=o.filter((p)=>p.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${u.length}/${o.length} sources (HTTP: ${f}, Browser: ${d})
372
+ `),o}async function dn(e){let t=await C();try{await g(["nav",t,e],30000),await ke(t);let r=await g(["eval",t,String.raw`
373
373
  (function(){
374
374
  var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
375
375
  var text = (el || document.body).innerText;
376
376
  return text.replace(/\s+/g, ' ').trim();
377
377
  })()
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};
378
+ `]);return{url:e,content:r}}catch(r){return{url:e,content:null,error:r.message}}finally{await L(t)}}export{dn as fetchTopSource,Gt as fetchSourceContent,gn as fetchMultipleSources};
@@ -1 +1 @@
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
+ import{existsSync as s}from"node:fs";import{dirname as a,join as e}from"node:path";import{fileURLToPath as f}from"node:url";function S(n){return f(new URL(".",n)).replace(/^\/([A-Z]:)/,"$1")}function i(n,r=s){let o=new Set;for(let t of n.filter(Boolean)){if(o.has(t))continue;if(o.add(t),r(t))return t}return n.filter(Boolean).at(-1)}function m(n,{moduleDir:r,entrypoint:o=process.argv[1],env:t=process.env,exists:l=s}={}){let c=o?a(o):null,u=t.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return i([r?e(r,"..","..","extractors",n):null,r?e(r,"..","extractors",n):null,u?e(u,"extractors",n):null,c?e(c,"..","extractors",n):null],l)}function p({moduleDir:n,entrypoint:r=process.argv[1],env:o=process.env,exists:t=s}={}){let l=r?a(r):null,c=o.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return i([n?e(n,"..","..","bin","launch.mjs"):null,n?e(n,"launch.mjs"):null,c?e(c,"bin","launch.mjs"):null,l?e(l,"launch.mjs"):null,l?e(l,"..","bin","launch.mjs"):null],t)}export{p as resolveGreedySearchLaunchScript,m as resolveGreedySearchExtractorScript,S as moduleDirectory};