@duckmind/dm-darwin-x64 0.52.3 → 0.52.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dm +0 -0
- package/extensions/.dm-extensions.json +6 -3
- package/extensions/greedysearch-dm/bin/gschrome.mjs +5 -7
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +2 -4
- package/extensions/greedysearch-dm/bin/launch.mjs +11 -5
- package/extensions/greedysearch-dm/bin/search.mjs +122 -120
- package/extensions/greedysearch-dm/extractors/consensus.mjs +43 -43
- package/extensions/greedysearch-dm/extractors/gemini.mjs +44 -44
- package/extensions/greedysearch-dm/extractors/logically.mjs +41 -41
- package/extensions/greedysearch-dm/index.js +18 -18
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +8 -9
- package/extensions/greedysearch-dm/src/search/chrome.mjs +25 -25
- package/extensions/greedysearch-dm/src/search/constants.mjs +8 -8
- package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +49 -49
- package/extensions/greedysearch-dm/src/search/launcher-paths.mjs +3 -0
- package/extensions/greedysearch-dm/src/search/partial-output.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/port-pid.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/recovery.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +101 -101
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +11 -11
- package/extensions/greedysearch-dm/src/search/synthesis.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +18 -18
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -9
- package/package.json +1 -1
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import{createRequire as
|
|
1
|
+
import{createRequire as Re}from"node:module";var ke=Re(import.meta.url);import{Readability as Ce}from"@mozilla/readability";import{JSDOM as je}from"jsdom";import Oe from"turndown";var ee=new Oe({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});ee.addRule("removeDataUrls",{filter:(e)=>e.tagName==="IMG"&&e.getAttribute("src")?.startsWith("data:"),replacement:()=>""});var te="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",re={"user-agent":te,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},Le=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i];function ne(e={}){return{...re,...e}}function L(e){try{let t=new URL(e),r=t.hostname.toLowerCase();for(let n of Le)if(n.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(t.protocol==="file:")return{blocked:!0,reason:"File protocol not allowed"};return{blocked:!1}}catch(t){return{blocked:!0,reason:`Invalid URL: ${t.message}`}}}function Te(e){try{let t=new URL(e);if(!(t.hostname==="github.com"||t.hostname.endsWith(".github.com")))return e;let r=t.pathname.split("/").filter(Boolean);if(r.length<5)return e;let[n,i,o,a,...s]=r;if(o!=="blob")return e;let c=s.join("/");return`https://raw.githubusercontent.com/${n}/${i}/${a}/${c}`}catch{return e}}async function ie(e,t={}){let r=L(e);if(r.blocked)return{ok:!1,url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let n=e;if(e=Te(e),e!==n)console.error(`[fetcher] Rewrote GitHub URL: ${n.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:i=15000,userAgent:o,signal:a}=t,s=new AbortController,c=setTimeout(()=>s.abort(),i);if(a)a.addEventListener("abort",()=>s.abort(),{once:!0});try{let l=await fetch(e,{method:"GET",headers:{...re,"user-agent":o||te},redirect:"follow",signal:s.signal});clearTimeout(c);let f=l.headers.get("content-type")||"",u=l.url,d=l.headers.get("last-modified")||"",g=!1;try{g=new URL(u).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(f.includes("text/plain")&&g){let O=await l.text();return{ok:!0,url:n,finalUrl:u,status:l.status,title:u.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:d,lastModified:d,markdown:O,contentLength:O.length,excerpt:O.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!f.includes("text/html")&&!f.includes("application/xhtml"))return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Unsupported content type: ${f}`,needsBrowser:!1};let h=await l.text(),y=T(l.status,h,u,e);if(y.blocked)return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Blocked: ${y.reason}`,needsBrowser:!0};let p=F(h,u),E=x(p);if(!E.ok)return{ok:!1,url:e,finalUrl:u,status:l.status,error:`Low quality content: ${E.reason}`,needsBrowser:!0};return{ok:!0,url:e,finalUrl:u,status:l.status,title:p.title,byline:p.byline,siteName:p.siteName,lang:p.lang,publishedTime:p.publishedTime||d,lastModified:d,markdown:p.markdown,excerpt:p.excerpt,contentLength:p.markdown.length,needsBrowser:!1}}catch(l){clearTimeout(c);let f=Me(l);return{ok:!1,url:e,finalUrl:e,status:0,error:l.message,needsBrowser:f}}}function T(e,t,r,n){let i=t.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",o=t.slice(0,30000).toLowerCase(),a=`${i} ${o}`;if(e===403||e===429||e===503)return{blocked:!0,reason:`HTTP ${e}`};let s=[{pattern:/class=["'][^"']*captcha["']|<div[^>]*id=["']captcha/i,reason:"captcha"},{pattern:/g-recaptcha|data-sitekey|i['"]m not a robot/i,reason:"captcha"},{pattern:/checking your browser.{0,100}please wait|cf-browser-verification/i,reason:"cloudflare challenge"},{pattern:/just a moment.{0,50}security check|ddos protection by cloudflare/i,reason:"cloudflare challenge"},{pattern:/unusual traffic.{0,50}from your computer network/i,reason:"unusual traffic"},{pattern:/bot detected|automated.{0,20}request/i,reason:"bot detection"},{pattern:/enable\s+javascript\s+to\s+view|javascript\s+is\s+required.{0,50}enabled/i,reason:"requires javascript"},{pattern:/access denied|accessdenied/i,reason:"access denied"},{pattern:/protected by anubis|anubis uses a proof-of-work/i,reason:"anubis challenge"}];for(let l of s)if(l.pattern.test(a))return{blocked:!0,reason:l.reason};let c=We(n,r,t);if(c)return{blocked:!0,reason:c};return{blocked:!1}}var Fe=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],xe=["login.","signin.","auth.","sso.","accounts.","idp."],Ge=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"];function We(e,t,r){try{let n=new URL(e),i=new URL(t);if(n.hostname.toLowerCase()===i.hostname.toLowerCase())return;let o=i.hostname.toLowerCase();if(Fe.some((s)=>o===s||o.endsWith(`.${s}`)))return`redirected to login (${i.hostname})`;if(xe.some((s)=>o.startsWith(s)))return`redirected to login (${i.hostname})`;let a=r.slice(0,20000).toLowerCase();if(Ge.some((s)=>a.includes(s)))return`redirected to login page (${i.hostname})`}catch{}return}function Me(e){let t=e.message.toLowerCase();return t.includes("fetch failed")||t.includes("unable to verify")||t.includes("certificate")||t.includes("timeout")}function z(e){let t=['meta[property="article:published_time"]','meta[name="article:published_time"]','meta[property="og:published_time"]','meta[name="publication_date"]','meta[name="date"]','meta[itemprop="datePublished"]','time[itemprop="datePublished"]','meta[name="DC.date"]'];for(let r of t){let n=e.querySelector(r),i=n?.getAttribute("content")||n?.getAttribute("datetime")||"";if(i)return i}return""}function F(e,t){let r=new je(e,{url:t}).window.document,n=new Ce(r).parse();if(n&&n.content){let o=ee.turndown(n.content).replaceAll(/\n{3,}/g,`
|
|
2
2
|
|
|
3
|
-
`).trim(),a=
|
|
3
|
+
`).trim(),a=n.publishedTime||z(r)||"";return{title:n.title||r.title||t,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:a,markdown:o,excerpt:o.slice(0,300).replaceAll(/\n/g," ")}}let i=r.body;if(i){let o=i.cloneNode(!0);o.querySelectorAll("script, style, nav, footer, header, aside").forEach((s)=>s.remove());let a=(o.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||t,byline:"",siteName:"",lang:"",publishedTime:z(r),markdown:a,excerpt:a.slice(0,300)}}return{title:t,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function x(e){let t=e.markdown.trim().toLowerCase(),r=(e.title||"").toLowerCase();if(e.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let n=t.toLowerCase(),i=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(t),desc:"login form only"}];for(let{check:o,desc:a}of i)if(o())return{ok:!1,reason:a};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}var ae={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"};function P(e){try{let t=new URL(e);if(!(t.hostname==="github.com"||t.hostname.endsWith(".github.com")))return null;let r=t.pathname.split("/").filter(Boolean);if(r.length<2)return null;let[n,i]=r;if(r.length===2)return{owner:n,repo:i,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let o=r[2],a=r[3],s=r.slice(4).join("/");return{owner:n,repo:i,type:o,ref:a,path:s}}return null}catch{return null}}async function _(e,t=1e4){let r=new AbortController,n=setTimeout(()=>r.abort(),t);try{let i=await fetch(`https://api.github.com${e}`,{headers:ae,signal:r.signal});if(clearTimeout(n),!i.ok)throw Error(`GitHub API ${i.status}: ${e}`);return await i.json()}catch(i){throw clearTimeout(n),i}}async function Ue(e,t){try{let r=await _(`/repos/${e}/${t}/readme`);if(r.content&&r.encoding==="base64")return Buffer.from(r.content,"base64").toString("utf8");return""}catch{return""}}async function oe(e,t,r="HEAD",n=""){try{let i=await _(`/repos/${e}/${t}/git/ref/heads/${r==="HEAD"?"main":r}`).catch(()=>_(`/repos/${e}/${t}/git/ref/heads/master`).catch(()=>null)),o;if(i?.object?.sha)o=(await _(`/repos/${e}/${t}/git/commits/${i.object.sha}`)).tree.sha;else{let s=await _(`/repos/${e}/${t}`);o=(await _(`/repos/${e}/${t}/branches/${s.default_branch}`)).commit.commit.tree.sha}let a=(await _(`/repos/${e}/${t}/git/trees/${o}`)).tree||[];if(n)a=a.filter((s)=>s.path.startsWith(n));return a.slice(0,50).map((s)=>({path:s.path,type:s.type==="tree"?"dir":"file",size:s.size}))}catch{return[]}}async function He(e,t,r,n,i=1e4){let o=[`https://raw.githubusercontent.com/${e}/${t}/${r&&r!=="HEAD"?r:"main"}/${n}`,`https://raw.githubusercontent.com/${e}/${t}/master/${n}`];for(let a of o){let s=new AbortController,c=setTimeout(()=>s.abort(),i);try{let l=await fetch(a,{headers:{"user-agent":ae["user-agent"]},signal:s.signal});if(clearTimeout(c),l.ok)return await l.text()}catch{clearTimeout(c)}}return null}async function se(e){let t=P(e);if(!t)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:n,type:i,ref:o,path:a}=t;try{if(i==="root"||i==="tree"&&!a){let[s,c,l]=await Promise.allSettled([_(`/repos/${r}/${n}`),Ue(r,n),oe(r,n,o||"HEAD")]);if(s.status==="rejected")return{ok:!1,error:s.reason?.message||"Repo not found"};let f=s.value,u=c.status==="fulfilled"?c.value:"",d=l.status==="fulfilled"?l.value:[],g=f?.description?`
|
|
4
4
|
|
|
5
|
-
> ${f.description}`:"",h=f?.stargazers_count==null?"":` ⭐ ${f.stargazers_count}`,y=f?.language?` · ${f.language}`:"",p=`# ${r}/${
|
|
5
|
+
> ${f.description}`:"",h=f?.stargazers_count==null?"":` ⭐ ${f.stargazers_count}`,y=f?.language?` · ${f.language}`:"",p=`# ${r}/${n}${h}${y}${g}
|
|
6
6
|
|
|
7
7
|
`;if(u)p+=u.slice(0,6000);else p+=`[No README found]
|
|
8
8
|
|
|
9
9
|
Files:
|
|
10
|
-
${
|
|
11
|
-
`)}`;return{ok:!0,title:`${r}/${
|
|
12
|
-
`);return{ok:!0,title:`${r}/${
|
|
10
|
+
${d.map((E)=>` ${E.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${E.path}`).join(`
|
|
11
|
+
`)}`;return{ok:!0,title:`${r}/${n}`,content:p,tree:d.slice(0,30)}}if(i==="blob"&&a){let s=await He(r,n,o,a);if(s===null)return{ok:!1,error:`File not found: ${a}`};return{ok:!0,title:`${r}/${n}: ${a}`,content:s}}if(i==="tree"&&a){let s=await oe(r,n,o||"HEAD",a),c=s.map((l)=>` ${l.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${l.path}`).join(`
|
|
12
|
+
`);return{ok:!0,title:`${r}/${n}/${a}`,content:`[Directory: ${a}]
|
|
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
|
|
15
|
+
${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{ok:!1,error:s.message}}}var Ye={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};function ce(e){try{let t=new URL(e),r=t.hostname.toLowerCase();if(!(r==="reddit.com"||r.endsWith(".reddit.com")))return null;let n=t.pathname;if(n.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:le(e)};if(n.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:le(e)};return null}catch{return null}}function le(e){try{let t=new URL(e);return`${t.protocol}//${t.hostname}${t.pathname}`}catch{return e}}async function ue(e,t=8000){let r=Date.now();try{let n=e.replaceAll(/\/?$/g,".json"),i=new AbortController,o=setTimeout(()=>i.abort(),15000),a=await fetch(n,{headers:Ye,signal:i.signal});if(clearTimeout(o),!a.ok)throw Error(`Reddit API ${a.status}`);let s=await a.json();if(!Array.isArray(s)||s.length<1)throw Error("Invalid Reddit API response structure");let c=s[0],l=s[1],f=c?.data?.children?.[0]?.data;if(!f)throw Error("No post data in Reddit response");let u=Je(f,l,t);return{ok:!0,url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:f.title||"Reddit Post",byline:`u/${f.author}`,siteName:`r/${f.subreddit}`,lang:"en",publishedTime:new Date(f.created_utc*1000).toISOString(),excerpt:f.selftext?.slice(0,300).replace(/\n/g," ")||"",markdown:u,contentLength:u.length,needsBrowser:!1,duration:Date.now()-r}}catch(n){return{ok:!1,url:e,finalUrl:e,status:0,error:`Reddit fetch failed: ${n.message}`,needsBrowser:!1,duration:Date.now()-r}}}function Je(e,t,r){let n="";if(n+=`# ${e.title}
|
|
16
16
|
|
|
17
|
-
`,
|
|
17
|
+
`,n+=`**Subreddit:** r/${e.subreddit} | **Author:** u/${e.author} | **Score:** ${e.score}
|
|
18
18
|
|
|
19
|
-
`,e.selftext)
|
|
19
|
+
`,e.selftext)n+=e.selftext,n+=`
|
|
20
20
|
|
|
21
|
-
`;else if(e.url)try{let
|
|
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{
|
|
23
|
+
`}catch{n+=`**Link:** ${e.url}
|
|
24
24
|
|
|
25
|
-
`}if(t?.data?.children?.length>0){
|
|
25
|
+
`}if(t?.data?.children?.length>0){n+=`---
|
|
26
26
|
|
|
27
27
|
## Comments
|
|
28
28
|
|
|
29
|
-
`;let
|
|
30
|
-
`}if(
|
|
29
|
+
`;let i=t.data.children.filter((o)=>o.kind==="t1").slice(0,10);for(let o of i)n+=fe(o.data,0),n+=`
|
|
30
|
+
`}if(n.length>r)n=n.slice(0,r).trim()+`
|
|
31
31
|
|
|
32
|
-
... (truncated)`;return
|
|
33
|
-
`,
|
|
32
|
+
... (truncated)`;return n}function fe(e,t){if(!e||e.body==="[deleted]"||e.body==="[removed]")return"";let r="> ".repeat(t),n="";if(n+=`${r}**u/${e.author}** (${e.score} pts)
|
|
33
|
+
`,n+=`${r}${e.body.replaceAll(`
|
|
34
34
|
`,`
|
|
35
35
|
`+r)}
|
|
36
|
-
`,t<3&&e.replies?.data?.children){let
|
|
37
|
-
`+fe(o.data,t+1)}return
|
|
36
|
+
`,t<3&&e.replies?.data?.children){let i=e.replies.data.children.filter((o)=>o.kind==="t1");for(let o of i.slice(0,5))n+=`
|
|
37
|
+
`+fe(o.data,t+1)}return n}function $(e,t=8000){if(!e||e.length<=t)return e;let r=`
|
|
38
38
|
|
|
39
39
|
[...content trimmed...]
|
|
40
40
|
|
|
41
|
-
`,
|
|
42
|
-
`)a--;if(a<=
|
|
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
|
|
41
|
+
`,n=t-r.length,i=Math.floor(n*0.75),o=n-i,a=i;while(a>i-100&&e[a]!==`
|
|
42
|
+
`)a--;if(a<=i-100)a=i;let s=e.length-o;while(s<e.length-o+100&&e[s]!==`
|
|
43
|
+
`)s++;if(s>=e.length-o+100)s=e.length-o;let c=e.slice(0,a).trimEnd(),l=e.slice(s).trimStart();return`${c}${r}${l}`}import{platform as Wt,tmpdir as Be}from"node:os";import{spawn as Ve}from"node:child_process";import{dirname as qe,join as Ke}from"node:path";import{fileURLToPath as Xe}from"node:url";import{basename as Qe}from"node:path";import{existsSync as S,mkdirSync as rt,readFileSync as he,writeFileSync as nt}from"node:fs";import{homedir as it}from"node:os";import{join as ye}from"node:path";import{tmpdir as A}from"node:os";import{platform as ir,tmpdir as ct}from"node:os";import{existsSync as N,mkdirSync as ut,readFileSync as be,writeFileSync as ft}from"node:fs";import{homedir as pt}from"node:os";import{join as ve}from"node:path";import{tmpdir as I}from"node:os";function Ze(e=process.env,t=process.execPath){let r=e.GREEDY_SEARCH_NODE||e.NODE_BINARY||e.NODE;if(r?.trim())return r.trim();let n=Qe(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}var ze=qe(Xe(import.meta.url)),et=Ke(ze,"..","bin","cdp.mjs");function de(e,t=30000){return tt(e,null,t)}function tt(e,t=null,r=30000){return new Promise((n,i)=>{let o=Ve(Ze(),[et,...e],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)o.stdin.write(t),o.stdin.end();let a="",s="";o.stdout.on("data",(l)=>a+=l),o.stderr.on("data",(l)=>s+=l);let c=setTimeout(()=>{o.kill(),i(Error(`cdp timeout: ${e[0]}`))},r);o.on("close",(l)=>{if(clearTimeout(c),l===0)n(a.trim());else i(Error(s.trim()||`cdp exit ${l}`))})})}async function pe(e){await de(["evalraw",e,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
44
44
|
(function() {
|
|
45
45
|
// ── Runtime.enable / CDP detection masking ──────────────
|
|
46
46
|
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
@@ -248,35 +248,35 @@ ${c}`,tree:s}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(s){return{
|
|
|
248
248
|
};
|
|
249
249
|
} catch(_) {}
|
|
250
250
|
})();
|
|
251
|
-
`})])}var we
|
|
251
|
+
`})])}function ot(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var Kt=ot(process.env.GREEDY_SEARCH_PORT,9222),we=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${A().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),Xt=`${we}/DevToolsActivePort`,Qt=`${A().replaceAll("\\","/")}/cdp-pages.json`,Zt=process.env.GREEDY_SEARCH_MODE_FILE||`${A().replaceAll("\\","/")}/greedysearch-chrome-mode`,zt=`${A().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,M=ye(it(),".dm"),w=ye(M,"greedyconfig"),U=["perplexity","google","chatgpt"],H="gemini";function at(){try{if(S(w)){let e=he(w,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((i)=>G[i]),n=t.engines.filter((i)=>!G[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${w}: ${n.join(", ")}
|
|
252
252
|
[greedysearch] Available engines: ${Object.keys(G).join(", ")}
|
|
253
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
|
|
255
|
-
`,"utf8")}catch{}}
|
|
254
|
+
`)}}}catch{}return U}function st(){try{if(!S(M))rt(M,{recursive:!0});if(!S(w))nt(w,JSON.stringify({engines:U,synthesizer:H},null,2)+`
|
|
255
|
+
`,"utf8")}catch{}}st();var ge=["gemini","chatgpt"];function lt(){try{if(S(w)){let e=he(w,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(ge.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${w}
|
|
256
256
|
[greedysearch] Available synthesizers: ${ge.join(", ")}
|
|
257
|
-
[greedysearch] Falling back to default: ${
|
|
258
|
-
`)}}}catch{}return
|
|
257
|
+
[greedysearch] Falling back to default: ${H}
|
|
258
|
+
`)}}}catch{}return H}var G={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},er=at(),tr=lt(),rr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=we;function gt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var cr=gt(process.env.GREEDY_SEARCH_PORT,9222),_e=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${I().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),ur=`${_e}/DevToolsActivePort`,fr=`${I().replaceAll("\\","/")}/cdp-pages.json`,pr=process.env.GREEDY_SEARCH_MODE_FILE||`${I().replaceAll("\\","/")}/greedysearch-chrome-mode`,gr=`${I().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Y=ve(pt(),".dm"),b=ve(Y,"greedyconfig"),J=["perplexity","google","chatgpt"],B="gemini";function mt(){try{if(N(b)){let e=be(b,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((i)=>W[i]),n=t.engines.filter((i)=>!W[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${b}: ${n.join(", ")}
|
|
259
259
|
[greedysearch] Available engines: ${Object.keys(W).join(", ")}
|
|
260
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
261
|
-
`)}}}catch{}return
|
|
262
|
-
`,"utf8")}catch{}}
|
|
263
|
-
[greedysearch] Available synthesizers: ${
|
|
264
|
-
[greedysearch] Falling back to default: ${
|
|
265
|
-
`)}}}catch{}return
|
|
266
|
-
`)[0];if(!e)throw Error("No Chrome tabs found");return e.slice(0,8)}async function
|
|
260
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${b}, falling back to defaults: ${J.join(", ")}
|
|
261
|
+
`)}}}catch{}return J}function dt(){try{if(!N(Y))ut(Y,{recursive:!0});if(!N(b))ft(b,JSON.stringify({engines:J,synthesizer:B},null,2)+`
|
|
262
|
+
`,"utf8")}catch{}}dt();var me=["gemini","chatgpt"];function ht(){try{if(N(b)){let e=be(b,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(me.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${b}
|
|
263
|
+
[greedysearch] Available synthesizers: ${me.join(", ")}
|
|
264
|
+
[greedysearch] Falling back to default: ${B}
|
|
265
|
+
`)}}}catch{}return B}var W={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},mr=mt(),dr=ht(),hr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=_e;var D=ct().replaceAll("\\","/"),yr=`${D}/greedysearch-chrome-metadata.json`,wr=`${D}/greedysearch-chrome-launch.lock`;var br=`${D}/greedysearch-chrome.pid`,vr=`${D}/greedysearch-chrome-mode`,_r=`${D}/greedysearch-chrome-last-activity`;var Er=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var $r=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Ee=Be().replaceAll("\\","/"),Dr=`${Ee}/greedysearch-chrome.pid`,Pr=`${Ee}/greedysearch-chrome-last-activity`,Sr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Nr=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;var m=de;async function $e(){let e=(await m(["list"])).split(`
|
|
266
|
+
`)[0];if(!e)throw Error("No Chrome tabs found");return e.slice(0,8)}async function R(e="about:blank"){let t=await $e(),r=new URL(e).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let o=await m(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:a}=JSON.parse(o),s=a.slice(0,8);if(await m(["list"]).catch(()=>null),r==="copilot.microsoft.com")await pe(s);else pe(s).catch(()=>{});return await m(["list"]).catch(()=>null),a}let n=await m(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:i}=JSON.parse(n);return await m(["list"]).catch(()=>null),i}async function k(e){try{let t=await $e();await m(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}import{existsSync as C,mkdirSync as yt,readFileSync as Pe,writeFileSync as wt}from"node:fs";import{homedir as bt}from"node:os";import{join as Se}from"node:path";import{tmpdir as j}from"node:os";function vt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var jr=vt(process.env.GREEDY_SEARCH_PORT,9222),Ne=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${j().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),Or=`${Ne}/DevToolsActivePort`,Lr=`${j().replaceAll("\\","/")}/cdp-pages.json`,Tr=process.env.GREEDY_SEARCH_MODE_FILE||`${j().replaceAll("\\","/")}/greedysearch-chrome-mode`,Fr=`${j().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,q=Se(bt(),".dm"),v=Se(q,"greedyconfig"),K=["perplexity","google","chatgpt"],X="gemini";function _t(){try{if(C(v)){let e=Pe(v,"utf8"),t=JSON.parse(e);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((r)=>typeof r==="string")){let r=t.engines.filter((i)=>V[i]),n=t.engines.filter((i)=>!V[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${n.join(", ")}
|
|
267
267
|
[greedysearch] Available engines: ${Object.keys(V).join(", ")}
|
|
268
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
269
|
-
`)}}}catch{}return K}function
|
|
270
|
-
`,"utf8")}catch{}}
|
|
271
|
-
[greedysearch] Available synthesizers: ${
|
|
268
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${v}, falling back to defaults: ${K.join(", ")}
|
|
269
|
+
`)}}}catch{}return K}function Et(){try{if(!C(q))yt(q,{recursive:!0});if(!C(v))wt(v,JSON.stringify({engines:K,synthesizer:X},null,2)+`
|
|
270
|
+
`,"utf8")}catch{}}Et();var De=["gemini","chatgpt"];function $t(){try{if(C(v)){let e=Pe(v,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(De.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${v}
|
|
271
|
+
[greedysearch] Available synthesizers: ${De.join(", ")}
|
|
272
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"},
|
|
273
|
+
`)}}}catch{}return X}var V={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},xr=_t();var Gr=$t(),Q=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=Ne;function Dt(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(t=void 0){}multiplySelf(){return this}preMultiplySelf(){return this}translateSelf(){return this}scaleSelf(){return this}rotateSelf(){return this}};if(typeof globalThis.ImageData>"u")globalThis.ImageData=class{constructor(t=void 0,r=0,n=0){this.data=t,this.width=r,this.height=n}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(t=void 0){}}}async function Pt(){Dt();let e=await import("pdf-parse"),t=e.PDFParse??e.default;if(!t)throw Error("pdf-parse did not export PDFParse");return t}async function Ae(e,t){try{let n=new(await Pt())({data:new Uint8Array(e)});await n.load();let i=await n.getText(),o=i.text?.trim();if(!o)return null;return{title:new URL(t).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${i.total} pages)
|
|
274
274
|
|
|
275
|
-
${o}`,pages:
|
|
275
|
+
${o}`,pages:i.total}}catch(r){return{error:r.message||String(r)}}}function Z(e="",t=240){let r=String(e).replaceAll(/\s+/g," ").trim();if(r.length<=t)return r;let n=r.slice(0,t),i=n.lastIndexOf(" ");return i>0?`${n.slice(0,i)}...`:`${n}...`}async function St(e,t,r=8000){let n=Date.now();try{let o=(await m(["evalraw",e,"Page.getFrameTree","{}"]).then((h)=>JSON.parse(h)).catch(()=>null))?.frameTree?.frame?.id||void 0,a=await m(["evalraw",e,"Network.loadNetworkResource",JSON.stringify({frameId:o,url:t,options:{disableCache:!0,includeCredentials:!1}})],20000),c=JSON.parse(a).resource;if(!c?.success||!c.httpStatusCode)return{url:t,error:c?.netErrorName||c?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-n,needsFallback:!0};let l="";if(c.stream)try{let h=await m(["evalraw",e,"IO.read",JSON.stringify({handle:c.stream})],1e4);l=JSON.parse(h).data||"",await m(["evalraw",e,"IO.close",JSON.stringify({handle:c.stream})]).catch(()=>{})}catch{}if(!l||l.length<100)return{url:t,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-n,needsFallback:!0};let f=T(c.httpStatusCode,l,t,t);if(f.blocked)return{url:t,status:c.httpStatusCode,error:`Blocked: ${f.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let u=F(l,t),d=x(u);if(!d.ok)return{url:t,status:c.httpStatusCode,error:`Low quality: ${d.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let g=$(u.markdown,r);return{url:t,finalUrl:t,status:c.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:u.publishedTime||"",byline:u.byline||"",siteName:u.siteName||"",lang:u.lang||"",title:u.title||t,snippet:u.excerpt,content:g,contentChars:g.length,source:"chrome",duration:Date.now()-n}}catch(i){return{url:t,error:i.message,source:"chrome",duration:Date.now()-n,needsFallback:!0}}}function Ie(e){try{return new URL(e).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function Nt(e,t=8000){let r=L(e);if(r.blocked)return{url:e,finalUrl:e,status:403,error:`Blocked: ${r.reason}`,source:"pdf-http"};let n=new AbortController,i=setTimeout(()=>n.abort(),20000),o=Date.now();try{let a=await fetch(e,{method:"GET",redirect:"follow",signal:n.signal,headers:ne({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(i);let s=a.headers.get("content-type")||"",c=a.url||e,l=Number.parseInt(a.headers.get("content-length")||"0",10);if(a.status>=400)return{url:e,finalUrl:c,status:a.status,error:`HTTP ${a.status}`,source:"pdf-http",duration:Date.now()-o};if(!s.toLowerCase().includes("application/pdf")&&!Ie(c))return null;if(l>31457280)return{url:e,finalUrl:c,status:a.status,error:`PDF too large: ${l} bytes`,source:"pdf-http",duration:Date.now()-o};let f=Buffer.from(await a.arrayBuffer()),u=await Ae(f,c);if(!u||u.error)return{url:e,finalUrl:c,status:a.status,error:u?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-o};let d=$(u.content,t);return{url:e,finalUrl:c,status:a.status,contentType:"application/pdf",lastModified:a.headers.get("last-modified")||"",title:u.title,snippet:Z(d,320),content:d,contentChars:d.length,pages:u.pages,source:"pdf-http",duration:Date.now()-o}}catch(a){return clearTimeout(i),{url:e,finalUrl:e,error:a.message||String(a),source:"pdf-http",duration:Date.now()-o}}}async function At(e,t=8000){let r=Date.now();if(Ie(e)){let o=await Nt(e,t);if(o?.content||o?.status===403)return o}if(P(e)){let o=P(e);if(o&&(o.type==="root"||o.type==="tree"||o.type==="blob"&&!o.path?.includes("."))){let a=await se(e);if(a.ok){let s=$(a.content,t);return{url:e,finalUrl:e,status:200,contentType:"text/markdown",lastModified:"",title:a.title,snippet:s.slice(0,320),content:s,contentChars:s.length,source:"github-api",...a.tree&&{tree:a.tree},duration:Date.now()-r}}process.stderr.write(`[greedysearch] GitHub API fetch failed, trying HTTP: ${a.error}
|
|
276
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
|
|
278
|
-
`)}let
|
|
279
|
-
`),await
|
|
277
|
+
`);let o=await ue(e,t);if(o.ok){let a=$(o.markdown,t);return{url:e,finalUrl:o.finalUrl,status:o.status,contentType:"text/markdown",lastModified:o.lastModified||"",publishedTime:o.publishedTime||"",byline:o.byline||"",siteName:o.siteName||"",lang:o.lang||"",title:o.title,snippet:o.excerpt,content:a,contentChars:a.length,source:"reddit-api",duration:Date.now()-r}}process.stderr.write(`[greedysearch] Reddit API fetch failed, falling back to HTTP: ${o.error}
|
|
278
|
+
`)}let i=await ie(e,{timeoutMs:1e4});if(i.ok){let o=$(i.markdown,t);return{url:e,finalUrl:i.finalUrl,status:i.status,contentType:"text/markdown",lastModified:i.lastModified||"",publishedTime:i.publishedTime||"",byline:i.byline||"",siteName:i.siteName||"",lang:i.lang||"",title:i.title,snippet:i.excerpt,content:o,contentChars:o.length,source:"http",duration:Date.now()-r}}if(i.needsBrowser)try{let o=await R();try{let a=await St(o,e,t);if(a.content&&a.content.length>100)return a}finally{await k(o)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${e.slice(0,60)}, trying browser...
|
|
279
|
+
`),await It(e,t)}async function It(e,t=8000){let r=Date.now(),n;try{n=await R()}catch(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${i.message}`,source:"browser",duration:Date.now()-r}}try{await m(["nav",n,e],30000),await new Promise((s)=>setTimeout(s,800));let i=await m(["eval",n,String.raw`
|
|
280
280
|
(function(){
|
|
281
281
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
282
282
|
var text = (el || document.body).innerText;
|
|
@@ -286,16 +286,16 @@ ${o}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function Q(e="
|
|
|
286
286
|
url: location.href
|
|
287
287
|
});
|
|
288
288
|
})()
|
|
289
|
-
`]),o=JSON.parse(
|
|
290
|
-
`);let a=Array(
|
|
291
|
-
`);let p=await
|
|
289
|
+
`]),o=JSON.parse(i),a=$(o.content,t);return{url:e,finalUrl:o.url||e,status:200,contentType:"text/plain",lastModified:"",title:o.title,snippet:Z(a,320),content:a,contentChars:a.length,source:"browser",duration:Date.now()-r}}catch(i){return{url:e,title:"",content:null,snippet:"",contentChars:0,error:i.message,source:"browser",duration:Date.now()-r}}finally{await k(n)}}async function Qr(e,t=5,r=8000,n=Q){let i=e.slice(0,t);if(i.length===0)return[];let o=Math.min(i.length,Math.max(1,Number.parseInt(String(n),10)||Q));process.stderr.write(`[greedysearch] Fetching content from ${i.length} sources via HTTP (concurrency ${o})...
|
|
290
|
+
`);let a=Array(i.length),s=0,c=0;async function l(){while(!0){let g=s++;if(g>=i.length)return;let h=i[g],y=h.canonicalUrl||h.url;process.stderr.write(`[greedysearch] [${g+1}/${i.length}] Fetching: ${y.slice(0,60)}...
|
|
291
|
+
`);let p=await At(y,r).catch((E)=>({url:y,title:"",content:null,snippet:"",contentChars:0,error:E.message,source:"error",duration:0}));if(a[g]={id:h.id,...p},p.content&&p.content.length>100)process.stderr.write(`[greedysearch] ✓ ${p.source}: ${p.content.length} chars
|
|
292
292
|
`);else if(p.error)process.stderr.write(`[greedysearch] ✗ ${p.error.slice(0,80)}
|
|
293
|
-
`);c+=1,process.stderr.write(`PROGRESS:fetch:${c}/${
|
|
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,
|
|
295
|
-
`),a}async function
|
|
293
|
+
`);c+=1,process.stderr.write(`PROGRESS:fetch:${c}/${i.length}
|
|
294
|
+
`)}}await Promise.all(Array.from({length:o},()=>l()));let f=a.filter((g)=>g.content&&g.content.length>100),u=a.filter((g)=>g.source==="http").length,d=a.filter((g)=>g.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${f.length}/${a.length} sources (HTTP: ${u}, Browser: ${d})
|
|
295
|
+
`),a}async function Zr(e){let t=await R();await m(["list"]);try{await m(["nav",t,e],30000),await new Promise((n)=>setTimeout(n,800));let r=await m(["eval",t,String.raw`
|
|
296
296
|
(function(){
|
|
297
297
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
298
298
|
var text = (el || document.body).innerText;
|
|
299
299
|
return text.replace(/\s+/g, ' ').trim();
|
|
300
300
|
})()
|
|
301
|
-
`]);return{url:e,content:r}}catch(r){return{url:e,content:null,error:r.message}}finally{await
|
|
301
|
+
`]);return{url:e,content:r}}catch(r){return{url:e,content:null,error:r.message}}finally{await k(t)}}export{Zr as fetchTopSource,At as fetchSourceContent,Qr as fetchMultipleSources};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{existsSync as H}from"node:fs";import{dirname as I,join as B}from"node:path";function J(b){let w=new Set;return b.filter((z)=>{if(!z||w.has(z))return!1;return w.add(z),!0})}function K({moduleDir:b,entrypoint:w=process.argv[1],env:z=process.env}={}){let A=w?I(w):null,E=z.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return J([E?B(E,"bin","launch.mjs"):null,b?B(b,"launch.mjs"):null,b?B(b,"..","bin","launch.mjs"):null,b?B(b,"..","..","bin","launch.mjs"):null,A?B(A,"launch.mjs"):null,A?B(A,"..","bin","launch.mjs"):null])}function N({moduleDir:b,entrypoint:w=process.argv[1],env:z=process.env,exists:A=H}={}){let E=K({moduleDir:b,entrypoint:w,env:z}),G=E.find((F)=>A(F));if(G)return G;throw Error(`GreedySearch launcher not found. Checked candidates:
|
|
2
|
+
${E.map((F)=>`- ${F}`).join(`
|
|
3
|
+
`)}`)}export{N as resolveGreedySearchLauncherScript,K as launcherCandidates};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(s){let r=String(s??"").trim();if(!r)return null;let e=[r],c=r.indexOf("{"),a=r.lastIndexOf("}");if(c>=0&&a>c)e.push(r.slice(c,a+1));for(let n of e)try{let t=JSON.parse(n);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return null}function i(s,r={}){let e=o(s);if(!e)return null;return{...e,_process:{...e._process&&typeof e._process==="object"?e._process:{},status:"partial",...r}}}export{i as preservePartialSearchResult,o as parseSearchJsonOutput};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execFileSync as D}from"node:child_process";import{platform as G}from"node:os";import{existsSync as $}from"node:fs";import{platform as C}from"node:os";import{join as X}from"node:path";function A(z){let B=C()==="win32",q=process.env.SystemRoot||"C:\\Windows",J={win32:{powershell:X(q,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:X(q,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:X(q,"System32","netstat.exe"),taskkill:X(q,"System32","taskkill.exe"),tasklist:X(q,"System32","tasklist.exe"),cmd:X(q,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},K=B?J.win32:J.unix,V=z.toLowerCase();if(K[V]&&$(K[V]))return K[V];if(B&&V==="netstat"){let Z=X(q,"Sysnative","netstat.exe");if($(Z))return Z}return z}function H(z,B){return D(A(z),B,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function I(z){let B=String(z||"").match(/\b(\d+)\b/);return B?Number.parseInt(B[1],10):null}function L(z){return I(z)}function M(z,B){for(let q of String(z||"").split(/\r?\n/)){if(!/\bLISTEN\b/i.test(q))continue;if(!q.trim().split(/\s+/).slice(0,6).some((V)=>V.endsWith(`:${B}`)))continue;let K=q.match(/\bpid=(\d+)\b/);if(K)return Number.parseInt(K[1],10)}return null}function O(z,B){for(let q of String(z||"").split(/\r?\n/)){let J=q.trim().split(/\s+/);if(J.length<5||J[0].toUpperCase()!=="TCP")continue;if(!J.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!J[1].endsWith(`:${B}`))continue;let V=Number.parseInt(J.at(-1),10);if(Number.isInteger(V)&&V>0)return V}return null}function Y(z,B,q){try{return z(B,q)}catch{return null}}function v(z,{platformName:B=G(),run:q=H}={}){if(B==="win32")return O(Y(q,"netstat",["-ano","-p","TCP"]),z);let J=Y(q,"lsof",["-nP",`-iTCP:${z}`,"-sTCP:LISTEN","-t"]),K=L(J);if(K)return K;if(B!=="linux")return null;return M(Y(q,"ss",["-ltnp"]),z)}export{M as parseSsPid,O as parseNetstatPid,L as parseLsofPid,v as findListeningProcessPid};
|
|
@@ -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((
|
|
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 j(q)?"needs-human":"error"}function w(q,J,z){return q._recovery={status:"failed",engines:[...J],error:z?.message||String(z)},q}function x(q){return X.filter((J)=>{let z=q?.[J];if(!z)return!1;if(z._envelope?.blockedBy)return!0;if(z._envelope?.verificationResult==="needs-human")return!0;let Q=z.error;return Q&&W(Q)})}function F(q){if(!q)return!1;let J=q.envelope;if(J?.blockedBy)return!0;if(J?.verificationResult==="needs-human")return!0;return W(q.message)}export{w as recordRecoveryFailure,j as isManualVerificationError,F as isHeadlessBlockedResult,W as isHeadlessBlockedError,x as findHeadlessBlockedEngines,m as classifyVisibleRecoveryFailure,X as HEADLESS_RECOVERY_ENGINES};
|