@duckmind/dm-darwin-arm64 0.51.8 → 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,4 +1,4 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as fr,execFileSync as Ve,execSync as pr}from"node:child_process";import{existsSync as B,readFileSync as j,renameSync as gr,unlinkSync as m,writeFileSync as K}from"node:fs";import me from"node:http";import{platform as Ye,tmpdir as mr}from"node:os";import{spawn as ze}from"node:child_process";import{dirname as et,join as tt}from"node:path";import{fileURLToPath as rt}from"node:url";import{basename as nt}from"node:path";function it(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=nt(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}var at=et(rt(import.meta.url)),ot=tt(at,"..","bin","cdp.mjs");function L(e,t=30000){return st(e,null,t)}function st(e,t=null,r=30000){return new Promise((n,i)=>{let a=ze(it(),[ot,...e],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)a.stdin.write(t),a.stdin.end();let l="",s="";a.stdout.on("data",(u)=>l+=u),a.stderr.on("data",(u)=>s+=u);let o=setTimeout(()=>{a.kill(),i(Error(`cdp timeout: ${e[0]}`))},r);a.on("close",(u)=>{if(clearTimeout(o),u===0)n(l.trim());else i(Error(s.trim()||`cdp exit ${u}`))})})}async function G(e){await L(["evalraw",e,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
2
2
|
(function() {
|
|
3
3
|
// ── Runtime.enable / CDP detection masking ──────────────
|
|
4
4
|
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
@@ -206,29 +206,29 @@ import{spawn as Bt,execFileSync as qe,execSync as pe}from"node:child_process";im
|
|
|
206
206
|
};
|
|
207
207
|
} catch(_) {}
|
|
208
208
|
})();
|
|
209
|
-
`})])}import{basename as
|
|
210
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
211
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${p}, falling back to defaults: ${
|
|
212
|
-
`)}}}catch{}return
|
|
213
|
-
`,"utf8")}catch{}}
|
|
209
|
+
`})])}import{basename as lt}from"node:path";function we(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=lt(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}import{existsSync as ye}from"node:fs";import{platform as ut}from"node:os";import{join as b}from"node:path";function x(e){let t=ut()==="win32",r=process.env.SystemRoot||"C:\\Windows",n={win32:{powershell:b(r,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:b(r,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:b(r,"System32","netstat.exe"),taskkill:b(r,"System32","taskkill.exe"),tasklist:b(r,"System32","tasklist.exe"),cmd:b(r,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},i=t?n.win32:n.unix,a=e.toLowerCase();if(i[a]&&ye(i[a]))return i[a];if(t&&a==="netstat"){let l=b(r,"Sysnative","netstat.exe");if(ye(l))return l}return e}import{existsSync as H,mkdirSync as ct,readFileSync as _e,writeFileSync as ft}from"node:fs";import{homedir as pt}from"node:os";import{join as $e}from"node:path";import{tmpdir as Q}from"node:os";function gt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var c=gt(process.env.GREEDY_SEARCH_PORT,9222),V=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Q().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),A=`${V}/DevToolsActivePort`,re=`${Q().replaceAll("\\","/")}/cdp-pages.json`,w=process.env.GREEDY_SEARCH_MODE_FILE||`${Q().replaceAll("\\","/")}/greedysearch-chrome-mode`,Br=`${Q().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,z=$e(pt(),".dm"),p=$e(z,"greedyconfig"),ee=["perplexity","google","chatgpt"],te="gemini";function mt(){try{if(H(p)){let e=_e(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)=>F[i]),n=t.engines.filter((i)=>!F[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${p}: ${n.join(", ")}
|
|
210
|
+
[greedysearch] Available engines: ${Object.keys(F).join(", ")}
|
|
211
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${p}, falling back to defaults: ${ee.join(", ")}
|
|
212
|
+
`)}}}catch{}return ee}function ht(){try{if(!H(z))ct(z,{recursive:!0});if(!H(p))ft(p,JSON.stringify({engines:ee,synthesizer:te},null,2)+`
|
|
213
|
+
`,"utf8")}catch{}}ht();var ve=["gemini","chatgpt"];function dt(){try{if(H(p)){let e=_e(p,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(ve.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${p}
|
|
214
214
|
[greedysearch] Available synthesizers: ${ve.join(", ")}
|
|
215
|
-
[greedysearch] Falling back to default: ${
|
|
216
|
-
`)}}}catch{}return
|
|
215
|
+
[greedysearch] Falling back to default: ${te}
|
|
216
|
+
`)}}}catch{}return te}var F={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},jr=mt();var qr=dt(),Hr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=V;import{existsSync as Er,mkdirSync as bt,readFileSync as xe,renameSync as wt,unlinkSync as yt,writeFileSync as Ae}from"node:fs";import vt from"node:http";import{platform as Se}from"node:os";import{dirname as _t}from"node:path";var Ce=[9222,9223],$t=/^(0|false|no|off)$/i;function Pt(e){return[...new Set(e.filter(Boolean))]}function Pe(e,t="explicit"){let r=new URL(e),n=r.protocol==="wss:"?"wss:":"ws:",i=r.port?Number.parseInt(r.port,10):n==="wss:"?443:80;return{source:t,wsUrl:`${n}//${r.host}${r.pathname}${r.search}`,host:r.hostname,port:i,path:`${r.pathname}${r.search}`,httpUrl:`http://${r.hostname}:${i}`}}function Ne(e=process.env){return![e.GREEDY_SEARCH_REUSE_EXISTING_BROWSER,e.DM_CUA_REUSE_EXISTING_BROWSER].some((t)=>t!==void 0&&$t.test(String(t)))}function ne(e){let t=Number.parseInt(String(e??""),10);return Number.isInteger(t)&&t>0&&t<65536?t:null}function xt(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=new URL(t.includes("://")?t:`http://${t}`),n=ne(r.port)||(r.protocol==="https:"?443:80);return{host:r.hostname,port:n,source:`env:${t}`}}function At(e){if(!e)return[];return String(e).split(/[,\s]+/).map(ne).filter(Boolean)}function St({env:e=process.env,platformName:t=Se(),procVersionText:r=null}={}){if(t!=="linux")return!1;if(e.WSL_DISTRO_NAME||e.WSL_INTEROP)return!0;let n=r??(()=>{try{return xe("/proc/version","utf8")}catch{return""}})();return/microsoft|wsl/i.test(n)}function Ct({env:e=process.env,platformName:t=Se(),procVersionText:r=null,resolvConfText:n=null}={}){let i=["localhost","127.0.0.1"];if(St({env:e,platformName:t,procVersionText:r})){let a=(n??(()=>{try{return xe("/etc/resolv.conf","utf8")}catch{return""}})()).match(/^\s*nameserver\s+([^\s#]+)/m);if(a)i.push(a[1]);i.push("host.docker.internal")}return Pt(i)}function Nt({env:e=process.env,hosts:t=Ct({env:e}),autoPorts:r=Ce,excludePorts:n=[]}={}){let i=[];for(let o of["GREEDY_SEARCH_CDP_WS_URL","DM_CUA_CDP_WS_URL","CDP_WS_URL"])if(e[o])i.push({wsUrl:e[o],source:`env:${o}`});for(let o of["GREEDY_SEARCH_CDP_URL","DM_CUA_CDP_URL","CDP_URL"])try{let u=xt(e[o]);if(u)i.push(u)}catch{}for(let o of["GREEDY_SEARCH_EXISTING_CDP_PORT","DM_CUA_EXISTING_CDP_PORT","GREEDY_SEARCH_CDP_PORT","DM_CUA_CDP_PORT"]){let u=ne(e[o]);if(!u)continue;for(let f of t)i.push({host:f,port:u,source:`env:${o}`})}let a=At(e.GREEDY_SEARCH_EXISTING_CDP_PORTS);for(let o of a)for(let u of t)i.push({host:u,port:o,source:"env:GREEDY_SEARCH_EXISTING_CDP_PORTS"});let l=new Set(n.filter(Boolean));if(Ne(e))for(let o of r){if(l.has(o))continue;for(let u of t)i.push({host:u,port:o,source:"auto"})}let s=new Set;return i.filter((o)=>{let u=o.wsUrl||`${o.host}:${o.port}`;if(s.has(u))return!1;return s.add(u),!0})}async function Dt(e,{timeoutMs:t=700}={}){if(e.wsUrl)return Pe(e.wsUrl,e.source);let r=e.host||"localhost",n=e.port;if(!n)return null;let i=await new Promise((a)=>{let l=vt.get({host:r,port:n,path:"/json/version",timeout:t},(s)=>{let o="";s.setEncoding("utf8"),s.on("data",(u)=>o+=u),s.on("end",()=>a(s.statusCode===200?o:null))});l.on("error",()=>a(null)),l.setTimeout(t,()=>{l.destroy(),a(null)})});if(!i)return null;try{let a=JSON.parse(i);if(!a.webSocketDebuggerUrl)return null;let l=Pe(a.webSocketDebuggerUrl,e.source),s=l.path||new URL(a.webSocketDebuggerUrl).pathname;return{...l,host:r,port:n,httpUrl:`http://${r}:${n}`,wsUrl:`ws://${r}:${n}${s}`,path:s}}catch{return null}}async function Wt(e={}){for(let t of Nt(e)){let r=await Dt(t,e);if(r)return r}return null}function Rt(e){if(!e)throw Error("missing CDP endpoint");let t=new URL(e.wsUrl);return`${t.host}
|
|
217
217
|
${t.pathname}${t.search}
|
|
218
|
-
`}function
|
|
219
|
-
|
|
220
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
[
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
`)[0],10):null}catch{return null}}async function
|
|
228
|
-
`);return t}var
|
|
229
|
-
`)[0];if(!t)throw Error("No Chrome tabs found");return t.slice(0,8)}async function
|
|
230
|
-
${o}`,"utf8");try{
|
|
231
|
-
`);return}
|
|
232
|
-
`),await
|
|
233
|
-
`),await
|
|
234
|
-
`);let o=[
|
|
218
|
+
`}function kt(e,t){bt(_t(e),{recursive:!0});let r=`${e}.tmp-${process.pid}`;Ae(r,Rt(t),"utf8");try{yt(e)}catch{}wt(r,e)}async function De({activePortFile:e,modeFile:t,env:r=process.env,excludePorts:n=[],autoPorts:i=Ce}={}){if(!Ne(r))return null;let a=await Wt({env:r,excludePorts:n,autoPorts:i});if(!a)return null;if(kt(e,a),t)Ae(t,"existing","utf8");return a}import{existsSync as Tt}from"node:fs";import{dirname as Ot,join as S}from"node:path";function Jt(e){let t=new Set;return e.filter((r)=>{if(!r||t.has(r))return!1;return t.add(r),!0})}function Ut({moduleDir:e,entrypoint:t=process.argv[1],env:r=process.env}={}){let n=t?Ot(t):null,i=r.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return Jt([i?S(i,"bin","launch.mjs"):null,e?S(e,"launch.mjs"):null,e?S(e,"..","bin","launch.mjs"):null,e?S(e,"..","..","bin","launch.mjs"):null,n?S(n,"launch.mjs"):null,n?S(n,"..","bin","launch.mjs"):null])}function We({moduleDir:e,entrypoint:t=process.argv[1],env:r=process.env,exists:n=Tt}={}){let i=Ut({moduleDir:e,entrypoint:t,env:r}),a=i.find((l)=>n(l));if(a)return a;throw Error(`GreedySearch launcher not found. Checked candidates:
|
|
219
|
+
${i.map((l)=>`- ${l}`).join(`
|
|
220
|
+
`)}`)}import{execFileSync as Mt}from"node:child_process";import{platform as Xt}from"node:os";function Bt(e,t){return Mt(x(e),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function jt(e){let t=String(e||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function qt(e){return jt(e)}function Ht(e,t){for(let r of String(e||"").split(/\r?\n/)){if(!/\bLISTEN\b/i.test(r))continue;if(!r.trim().split(/\s+/).slice(0,6).some((a)=>a.endsWith(`:${t}`)))continue;let i=r.match(/\bpid=(\d+)\b/);if(i)return Number.parseInt(i[1],10)}return null}function Qt(e,t){for(let r of String(e||"").split(/\r?\n/)){let n=r.trim().split(/\s+/);if(n.length<5||n[0].toUpperCase()!=="TCP")continue;if(!n.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!n[1].endsWith(`:${t}`))continue;let a=Number.parseInt(n.at(-1),10);if(Number.isInteger(a)&&a>0)return a}return null}function ie(e,t,r){try{return e(t,r)}catch{return null}}function Re(e,{platformName:t=Xt(),run:r=Bt}={}){if(t==="win32")return Qt(ie(r,"netstat",["-ano","-p","TCP"]),e);let n=ie(r,"lsof",["-nP",`-iTCP:${e}`,"-sTCP:LISTEN","-t"]),i=qt(n);if(i)return i;if(t!=="linux")return null;return Ht(ie(r,"ss",["-ltnp"]),e)}import{execFileSync as ke,execSync as an}from"node:child_process";import{existsSync as y,mkdirSync as Vt,readFileSync as C,unlinkSync as $,writeFileSync as P}from"node:fs";import{platform as Et,tmpdir as Xe}from"node:os";import{existsSync as E,mkdirSync as Yt,readFileSync as Be,writeFileSync as Zt}from"node:fs";import{homedir as It}from"node:os";import{join as je}from"node:path";import{tmpdir as I}from"node:os";import{execFileSync as zt}from"node:child_process";import{platform as er}from"node:os";import{existsSync as Oe}from"node:fs";import{platform as tr}from"node:os";import{join as v}from"node:path";function Kt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var D=Kt(process.env.GREEDY_SEARCH_PORT,9222),T=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${I().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),pn=`${T}/DevToolsActivePort`,gn=`${I().replaceAll("\\","/")}/cdp-pages.json`,mn=process.env.GREEDY_SEARCH_MODE_FILE||`${I().replaceAll("\\","/")}/greedysearch-chrome-mode`,hn=`${I().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,se=je(It(),".dm"),g=je(se,"greedyconfig"),le=["perplexity","google","chatgpt"],ue="gemini";function Lt(){try{if(E(g)){let e=Be(g,"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)=>ae[i]),n=t.engines.filter((i)=>!ae[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${g}: ${n.join(", ")}
|
|
221
|
+
[greedysearch] Available engines: ${Object.keys(ae).join(", ")}
|
|
222
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${g}, falling back to defaults: ${le.join(", ")}
|
|
223
|
+
`)}}}catch{}return le}function Gt(){try{if(!E(se))Yt(se,{recursive:!0});if(!E(g))Zt(g,JSON.stringify({engines:le,synthesizer:ue},null,2)+`
|
|
224
|
+
`,"utf8")}catch{}}Gt();var Te=["gemini","chatgpt"];function Ft(){try{if(E(g)){let e=Be(g,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(Te.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${g}
|
|
225
|
+
[greedysearch] Available synthesizers: ${Te.join(", ")}
|
|
226
|
+
[greedysearch] Falling back to default: ${ue}
|
|
227
|
+
`)}}}catch{}return ue}var ae={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"},dn=Lt(),bn=Ft(),wn=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=T;function ce(e){let t=tr()==="win32",r=process.env.SystemRoot||"C:\\Windows",n={win32:{powershell:v(r,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:v(r,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:v(r,"System32","netstat.exe"),taskkill:v(r,"System32","taskkill.exe"),tasklist:v(r,"System32","tasklist.exe"),cmd:v(r,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},i=t?n.win32:n.unix,a=e.toLowerCase();if(i[a]&&Oe(i[a]))return i[a];if(t&&a==="netstat"){let l=v(r,"Sysnative","netstat.exe");if(Oe(l))return l}return e}function rr(e,t){return zt(ce(e),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function nr(e){let t=String(e||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function ir(e){return nr(e)}function ar(e,t){for(let r of String(e||"").split(/\r?\n/)){if(!/\bLISTEN\b/i.test(r))continue;if(!r.trim().split(/\s+/).slice(0,6).some((i)=>i.endsWith(`:${t}`)))continue;let n=r.match(/\bpid=(\d+)\b/);if(n)return Number.parseInt(n[1],10)}return null}function or(e,t){for(let r of String(e||"").split(/\r?\n/)){let n=r.trim().split(/\s+/);if(n.length<5||n[0].toUpperCase()!=="TCP")continue;if(!n.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!n[1].endsWith(`:${t}`))continue;let i=Number.parseInt(n.at(-1),10);if(Number.isInteger(i)&&i>0)return i}return null}function oe(e,t,r){try{return e(t,r)}catch{return null}}function sr(e,{platformName:t=er(),run:r=rr}={}){if(t==="win32")return or(oe(r,"netstat",["-ano","-p","TCP"]),e);let n=oe(r,"lsof",["-nP",`-iTCP:${e}`,"-sTCP:LISTEN","-t"]),i=ir(n);if(i)return i;if(t!=="linux")return null;return ar(oe(r,"ss",["-ltnp"]),e)}var J=Xe().replaceAll("\\","/"),Y=`${J}/greedysearch-chrome-metadata.json`,_=`${J}/greedysearch-chrome-launch.lock`,lr=15000,R=`${J}/greedysearch-chrome.pid`,k=`${J}/greedysearch-chrome-mode`,N=`${J}/greedysearch-chrome-last-activity`;function O(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function ur(e){if(!O(e))return null;try{if(Et()==="win32")return ke(ce("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${e}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return ke(ce("ps"),["-p",String(e),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function fe(e,t,r=D){if(!e)return!1;let n=(l)=>String(l||"").replaceAll("\\","/").toLowerCase(),i=n(e),a=n(t);return i.includes(a)&&i.includes(`--remote-debugging-port=${r}`)&&!i.includes("--type=")}function Je(e,t,r=D){return fe(ur(e),t,r)}function cr(e=D){return sr(e)}function U(){try{if(y(Y)){let e=C(Y,"utf8"),t=JSON.parse(e);if(t&&typeof t.tempDir==="string"&&typeof t.debugPort==="number")return{browserPid:Number.isInteger(t.browserPid)?t.browserPid:void 0,debugPort:t.debugPort,tempDir:t.tempDir,clientPids:Array.isArray(t.clientPids)?t.clientPids.filter((r)=>Number.isInteger(r)&&r>0):[],sessionMode:t.sessionMode==="visible"?"visible":"headless",lastActivity:Number.isFinite(t.lastActivity)?t.lastActivity:0,launchedAt:Number.isFinite(t.launchedAt)?t.launchedAt:0}}}catch{}try{if(!(y(R)||y(k)||y(N)))return null;let e=y(R)?Number.parseInt(C(R,"utf8").trim(),10)||void 0:void 0,t=y(k)?C(k,"utf8").trim()==="visible"?"visible":"headless":"headless",r=y(N)?Number.parseInt(C(N,"utf8").trim(),10)||0:0;return{browserPid:e,debugPort:D,tempDir:T,clientPids:e?[e]:[],sessionMode:t,lastActivity:r,launchedAt:0}}catch{return null}}function Z(e){try{P(Y,JSON.stringify({browserPid:e.browserPid,debugPort:e.debugPort,tempDir:e.tempDir,clientPids:[...new Set(e.clientPids.filter((t)=>t>0))],sessionMode:e.sessionMode,lastActivity:e.lastActivity,launchedAt:e.launchedAt},null,2),"utf8")}catch{}try{if(e.browserPid)P(R,String(e.browserPid),"utf8")}catch{}try{P(k,e.sessionMode,"utf8")}catch{}try{P(N,String(e.lastActivity),"utf8")}catch{}}function Ue(){try{$(Y)}catch{}try{$(R)}catch{}try{$(k)}catch{}try{$(N)}catch{}}function qe(e){if(!e)return e;let t={...e,clientPids:[...new Set([...e.clientPids,process.pid].filter((r)=>O(r)||r===process.pid))]};return Z(t),t}function pe(e){let t=Date.now();try{if(e)Z({...e,lastActivity:t});else P(N,String(t),"utf8")}catch{}}var xn=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Me=!1;function He(){if(Me)return;Me=!0;let e=U();if(!e)return;if(e.browserPid){if(!O(e.browserPid)){Ue();return}if(!Je(e.browserPid,e.tempDir,e.debugPort))Ue();else Z({...e,clientPids:e.clientPids.filter((r)=>O(r))})}let t=cr();if(t&&t!==e.browserPid)if(Je(t,T,D))Z({browserPid:t,debugPort:D,tempDir:T,clientPids:[t],sessionMode:e.sessionMode,lastActivity:Date.now(),launchedAt:Date.now()});else return}function Qe(){Vt(Xe(),{recursive:!0});try{let e=JSON.stringify({pid:process.pid,ts:Date.now()});return P(_,e,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{let t=C(_,"utf8");if(JSON.parse(t).pid===process.pid)$(_)}catch{}}}}catch(e){if(e?.code!=="EEXIST")return{acquired:!1,release:()=>{}}}try{let e=C(_,"utf8"),t=JSON.parse(e),r=Date.now()-(t.ts||0);if(!O(t.pid)||r>lr){try{$(_)}catch{}try{let n=JSON.stringify({pid:process.pid,ts:Date.now()});return P(_,n,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{$(_)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}var hr=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Ze=mr().replaceAll("\\","/"),M=`${Ze}/greedysearch-chrome.pid`,X=`${Ze}/greedysearch-chrome-last-activity`,dr=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,br=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;function wr(e,t=c){let r=String(e||"").toLowerCase();if(!r.includes(`--remote-debugging-port=${t}`)||r.includes("--type="))return null;return r.includes("--headless")}function Ie(){try{let e=he(),t=e?Ke(e):null,r=wr(t);if(r!==null){try{K(w,r?"headless":"visible","utf8")}catch{}return r}}catch{}try{if(!B(w))return!0;return j(w,"utf8").trim()==="headless"}catch{return!0}}function yr(){try{K(X,String(Date.now()),"utf8")}catch{}try{let e=U();if(e)pe(e)}catch{}}function Ke(e){try{if(Ye()==="win32")return Ve(x("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${e}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return Ve(x("ps"),["-p",String(e),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function he(){return Re(c)}function Le(){let e=[he()];if(B(M))e.push(Number.parseInt(j(M,"utf8").trim(),10)||null);for(let t of e){if(!t)continue;if(fe(Ke(t),V,c))return t}return null}async function vr(e=1500){let t=Le();if(!t)return!1;try{let n=await new Promise((a,l)=>{let s=me.get(`http://localhost:${c}/json/version`,(o)=>{let u="";o.on("data",(f)=>u+=f),o.on("end",()=>{try{a(JSON.parse(u))}catch{l(Error("bad JSON"))}})});s.on("error",l),s.setTimeout(1000,()=>{s.destroy(),l(Error("timeout"))})}),i=new globalThis.WebSocket(n.webSocketDebuggerUrl);await new Promise((a)=>{i.onopen=()=>{i.send(JSON.stringify({id:1,method:"Browser.close"})),setTimeout(()=>{i.close(),a()},200)},i.onerror=()=>a(),setTimeout(a,1000)})}catch{}let r=Date.now()+e;while(Date.now()<r){let n=he();if(!n)return!0;if(n!==t)return!0;await new Promise((i)=>setTimeout(i,150))}return _r()}function _r(){try{let e=Le();if(!e)return!1;if(Ye()==="win32")pr(`${x("taskkill")} /F /PID ${e}`,{stdio:"ignore"});else process.kill(e,"SIGKILL");return!0}catch{return!1}}async function Ge(){if(!await W(500)){try{m(M)}catch{}try{m(X)}catch{}try{m(w)}catch{}return!1}let t=await vr(1500);try{m(M)}catch{}try{m(X)}catch{}try{m(w)}catch{}if(t)process.stderr.write(`[greedysearch] Killed Chrome on port ${c}.
|
|
228
|
+
`);return t}var Ee=Ge;async function $r(){let t=Ie()?dr:br;if(t<=0)return!1;if(!B(X))return yr(),!1;try{let r=Number.parseInt(j(X,"utf8").trim(),10);if(!r)return!1;if((Date.now()-r)/60000>=t)return Ge()}catch{}return!1}var h=L;async function de(){let t=(await h(["list"])).split(`
|
|
229
|
+
`)[0];if(!t)throw Error("No Chrome tabs found");return t.slice(0,8)}async function Xn(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 l=await h(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:s}=JSON.parse(l),o=s.slice(0,8);if(await h(["list"]).catch(()=>null),r==="copilot.microsoft.com")await G(o);else G(o).catch(()=>{});return await h(["list"]).catch(()=>null),s}let i=await h(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:a}=JSON.parse(i);return await h(["list"]).catch(()=>null),a}async function Bn(e){try{let t=await de();await h(["evalraw",t,"Target.activateTarget",JSON.stringify({targetId:e})])}catch{}}async function Pr(e){try{let t=await de();await h(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}async function jn(e=[]){if(await Promise.all(e.filter(Boolean).map((t)=>Pr(t).catch(()=>{}))),e.length>0)await h(["list"]).catch(()=>null)}function qn(e,t){try{if(!B(re))return null;let n=JSON.parse(j(re,"utf8")).find((i)=>i.url.includes(t[e]));return n?n.targetId:null}catch{return null}}function W(e=3000){return new Promise((t)=>{let r=me.get(`http://localhost:${c}/json/version`,(n)=>{n.resume(),t(n.statusCode===200)});r.on("error",()=>t(!1)),r.setTimeout(e,()=>{r.destroy(),t(!1)})})}async function ge(){let e=`${A}.lock`,t=`${A}.tmp`,r=5000,n=1000,i=await new Promise((a)=>{let l=Date.now(),s=()=>{try{let o=JSON.stringify({pid:process.pid,ts:Date.now()});K(e,o,{encoding:"utf8",flag:"wx"}),a(!0)}catch(o){if(o?.code!=="EEXIST"){if(Date.now()-l<1000)setTimeout(s,50);else a(!1);return}try{let u=j(e,"utf8").trim(),f=u.startsWith("{")?JSON.parse(u):{ts:Number(u)},d=Number(f?.ts)||0;if(d>0&&Date.now()-d>5000)try{m(e)}catch{}if(Date.now()-l<1000)setTimeout(s,50);else a(!1)}catch{if(Date.now()-l<1000)setTimeout(s,50);else a(!1)}}};s()});try{let a=await new Promise((u,f)=>{let d=me.get(`http://localhost:${c}/json/version`,(q)=>{let be="";q.on("data",(Fe)=>be+=Fe),q.on("end",()=>u(be))});d.on("error",f),d.setTimeout(3000,()=>{d.destroy(),f(Error("timeout"))})}),{webSocketDebuggerUrl:l}=JSON.parse(a),s=new URL(l),o=`${s.pathname}${s.search}`;if(i){K(t,`localhost:${c}
|
|
230
|
+
${o}`,"utf8");try{m(A)}catch{}gr(t,A)}}catch{}finally{if(i)try{m(e)}catch{}}}async function Hn(){let e=B(M)||!!U(),t=await De({activePortFile:A,modeFile:w,excludePorts:e?[c]:[]});if(t){process.stderr.write(`[greedysearch] Reusing existing browser CDP endpoint ${t.httpUrl} (${t.source}).
|
|
231
|
+
`);return}He();let r=await $r(),n=r?!1:await W();if(!n&&!r)await new Promise((s)=>setTimeout(s,500)),n=await W();let i=!1;if(n){let s=Ie(),o=process.env.GREEDY_SEARCH_VISIBLE==="1";if(!o&&!s)process.stderr.write(`[greedysearch] Visible Chrome detected — switching to headless mode...
|
|
232
|
+
`),await Ee(),await new Promise((u)=>setTimeout(u,1000)),i=!0;else if(o&&s)process.stderr.write(`[greedysearch] Headless Chrome detected — switching to visible mode...
|
|
233
|
+
`),await Ee(),await new Promise((u)=>setTimeout(u,1000)),i=!0}if(i?!1:await W()){await ge();try{let s=U();if(s)pe(s),qe(s)}catch{}return}let l=Qe();if(!l.acquired){let s=Date.now()+15000;while(Date.now()<s)if(await new Promise((o)=>setTimeout(o,250)),await W(1000)){await ge();return}throw Error(`Timed out waiting for another GreedySearch launcher on port ${c}`)}try{if(await W(1000)){await ge();return}process.stderr.write(`GreedySearch Chrome not running on port ${c} — auto-launching...
|
|
234
|
+
`);let o=[We({moduleDir:hr,entrypoint:process.argv[1]})];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")o.push("--headless");await new Promise((u,f)=>{fr(we(),o,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(q)=>q===0?u():f(Error("launch.mjs failed")))})}finally{l.release()}}export{yr as touchActivity,ge as refreshPortFile,W as probeGreedyChrome,Xn as openNewTab,Ee as killHeadlessChrome,Ge as killChrome,Ie as isChromeHeadless,qn as getFullTabFromCache,de as getAnyTab,Hn as ensureChrome,wr as detectHeadlessFromChromeCommandLine,jn as closeTabs,Pr as closeTab,$r as checkAndKillIdle,h as cdp,Bn as activateTab};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
3
|
-
`);if(
|
|
4
|
-
`)}}}catch{}return
|
|
5
|
-
`,"utf8")}catch{}}v();var
|
|
6
|
-
[greedysearch] Available synthesizers: ${
|
|
7
|
-
[greedysearch] Falling back to default: ${
|
|
8
|
-
`)}}}catch{}return
|
|
1
|
+
import{existsSync as M,mkdirSync as x,readFileSync as w,writeFileSync as H}from"node:fs";import{homedir as Z}from"node:os";import{join as z}from"node:path";import{tmpdir as Q}from"node:os";function h(K,B=9222){let q=Number.parseInt(String(K??""),10);return Number.isInteger(q)&&q>1024&&q<65535?q:B}var p=h(process.env.GREEDY_SEARCH_PORT,9222),u=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Q().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),C=`${u}/DevToolsActivePort`,f=`${Q().replaceAll("\\","/")}/cdp-pages.json`,T=process.env.GREEDY_SEARCH_MODE_FILE||`${Q().replaceAll("\\","/")}/greedysearch-chrome-mode`,O=`${Q().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,X=z(Z(),".dm"),J=z(X,"greedyconfig"),$=["perplexity","google","chatgpt"],b="gemini";function Y(){try{if(M(J)){let K=w(J,"utf8"),B=JSON.parse(K);if(Array.isArray(B.engines)&&B.engines.length>0&&B.engines.every((q)=>typeof q==="string")){let q=B.engines.filter((V)=>W[V]),j=B.engines.filter((V)=>!W[V]);if(j.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${J}: ${j.join(", ")}
|
|
2
|
+
[greedysearch] Available engines: ${Object.keys(W).join(", ")}
|
|
3
|
+
`);if(q.length>0)return q;process.stderr.write(`[greedysearch] Warning: no valid engines in ${J}, falling back to defaults: ${$.join(", ")}
|
|
4
|
+
`)}}}catch{}return $}function v(){try{if(!M(X))x(X,{recursive:!0});if(!M(J))H(J,JSON.stringify({engines:$,synthesizer:b},null,2)+`
|
|
5
|
+
`,"utf8")}catch{}}v();var k=["gemini","chatgpt"];function A(){try{if(M(J)){let K=w(J,"utf8"),B=JSON.parse(K);if(typeof B.synthesizer==="string"){let q=B.synthesizer.toLowerCase();if(k.includes(q))return q;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${B.synthesizer}" in ${J}
|
|
6
|
+
[greedysearch] Available synthesizers: ${k.join(", ")}
|
|
7
|
+
[greedysearch] Falling back to default: ${b}
|
|
8
|
+
`)}}}catch{}return b}var R={perplexity:"perplexity.ai",bing:"copilot.microsoft.com",google:"google.com",gemini:"gemini.google.com",chatgpt:"chatgpt.com","semantic-scholar":"semanticscholar.org",semanticscholar:"semanticscholar.org",s2:"semanticscholar.org",logically:"logically.app"},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"},P=Y(),D=P,L=A(),s=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=u;export{h as parseGreedySearchPort,O as VISIBLE_RECOVERY_LOG,L as SYNTHESIZER,k as SUPPORTED_SYNTHESIZERS,s as SOURCE_FETCH_CONCURRENCY,D as RESEARCH_ENGINES,f as PAGES_CACHE,u as GREEDY_PROFILE_DIR,p as GREEDY_PORT,R as ENGINE_DOMAINS,W as ENGINES,b as DEFAULT_SYNTHESIZER,$ as DEFAULT_ENGINES,T as CHROME_MODE_FILE,P as ALL_ENGINES,C as ACTIVE_PORT_FILE};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{spawn as
|
|
2
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
3
|
-
`);if(E.length>0)return E;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
4
|
-
`)}}}catch{}return
|
|
5
|
-
`,"utf8")}catch{}}
|
|
6
|
-
[greedysearch] Available synthesizers: ${
|
|
7
|
-
[greedysearch] Falling back to default: ${
|
|
8
|
-
`)}}}catch{}return
|
|
9
|
-
`),
|
|
1
|
+
import{spawn as p}from"node:child_process";import{basename as W}from"node:path";function Y(g=process.env,s=process.execPath){let E=g.GREEDY_SEARCH_NODE||g.NODE_BINARY||g.NODE;if(E?.trim())return E.trim();let l=W(s||"").toLowerCase();if(l==="node"||l==="node.exe")return s;return"node"}import{existsSync as i,mkdirSync as Z,readFileSync as L,writeFileSync as e}from"node:fs";import{homedir as J}from"node:os";import{join as z}from"node:path";import{tmpdir as c}from"node:os";function V(g,s=9222){let E=Number.parseInt(String(g??""),10);return Number.isInteger(E)&&E>1024&&E<65535?E:s}var gg=V(process.env.GREEDY_SEARCH_PORT,9222),r=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${c().replaceAll("\\","/")}/greedysearch-chrome-profile`).replaceAll("\\","/"),Eg=`${r}/DevToolsActivePort`,sg=`${c().replaceAll("\\","/")}/cdp-pages.json`,lg=process.env.GREEDY_SEARCH_MODE_FILE||`${c().replaceAll("\\","/")}/greedysearch-chrome-mode`,ag=`${c().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,n=z(J(),".dm"),R=z(n,"greedyconfig"),o=["perplexity","google","chatgpt"],H="gemini";function B(){try{if(i(R)){let g=L(R,"utf8"),s=JSON.parse(g);if(Array.isArray(s.engines)&&s.engines.length>0&&s.engines.every((E)=>typeof E==="string")){let E=s.engines.filter((a)=>S[a]),l=s.engines.filter((a)=>!S[a]);if(l.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${R}: ${l.join(", ")}
|
|
2
|
+
[greedysearch] Available engines: ${Object.keys(S).join(", ")}
|
|
3
|
+
`);if(E.length>0)return E;process.stderr.write(`[greedysearch] Warning: no valid engines in ${R}, falling back to defaults: ${o.join(", ")}
|
|
4
|
+
`)}}}catch{}return o}function K(){try{if(!i(n))Z(n,{recursive:!0});if(!i(R))e(R,JSON.stringify({engines:o,synthesizer:H},null,2)+`
|
|
5
|
+
`,"utf8")}catch{}}K();var G=["gemini","chatgpt"];function U(){try{if(i(R)){let g=L(R,"utf8"),s=JSON.parse(g);if(typeof s.synthesizer==="string"){let E=s.synthesizer.toLowerCase();if(G.includes(E))return E;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${s.synthesizer}" in ${R}
|
|
6
|
+
[greedysearch] Available synthesizers: ${G.join(", ")}
|
|
7
|
+
[greedysearch] Falling back to default: ${H}
|
|
8
|
+
`)}}}catch{}return H}var S={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"},yg=B();var Rg=U(),_g=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=r;import{existsSync as k}from"node:fs";import{dirname as Q,join as $}from"node:path";import{fileURLToPath as X}from"node:url";function j(g){return X(new URL(".",g)).replace(/^\/([A-Z]:)/,"$1")}function b(g,s=k){let E=new Set;for(let l of g.filter(Boolean)){if(E.has(l))continue;if(E.add(l),s(l))return l}return g.filter(Boolean).at(-1)}function w(g,{moduleDir:s,entrypoint:E=process.argv[1],env:l=process.env,exists:a=k}={}){let N=E?Q(E):null,f=l.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,O=[s?$(s,"..","..","extractors",g):null,s?$(s,"..","extractors",g):null,f?$(f,"extractors",g):null,N?$(N,"..","extractors",g):null];return b(O,a)}var q=j(import.meta.url);function cg(g,s,E=null,l=!1,a=null,N=null){if(a===null)a=g.includes("logically")?120000:g.includes("chatgpt")?80000:g.includes("gemini")?70000:60000;let f=[...E?["--tab",E]:[],...l?["--short"]:[],...N?["--locale",N]:[]],O=w(g,{moduleDir:q});return new Promise((D,F)=>{let A=p(Y(),[O,"--stdin",...f],{stdio:["pipe","pipe","pipe"],env:{...process.env,CDP_PROFILE_DIR:r}});A.stdin.write(s),A.stdin.end();let I="",T="";A.stdout.on("data",(y)=>I+=y),A.stderr.on("data",(y)=>{if(T+=y,process.env.GREEDY_SEARCH_CHILD_STDERR!=="0")process.stderr.write(y)});let P=setTimeout(()=>{A.kill();let y=(h,C=20)=>String(h??"").split(/\r?\n/).filter(Boolean).slice(-C).join(`
|
|
9
|
+
`),_=null;try{let h=JSON.parse(I.trim());if(h._envelope)_=h._envelope}catch{}let m=Error(`${g} timed out after ${a/1000}s`+(_?.lastStage?` (last stage: ${_.lastStage})`:""));m.engineScript=g,m.lastStage=_?.lastStage||null,m.partialErr=y(T),m.partialOut=y(I),F(m)},a);A.on("close",(y)=>{if(clearTimeout(P),y===0)try{D(JSON.parse(I.trim()))}catch{F(Error(`bad JSON from ${g}: ${I.slice(0,100)}`))}else{let _=null;try{let C=JSON.parse(I.trim());if(C._envelope)_=C._envelope}catch{}let m=T.trim()||`extractor exit ${y}`,h=Error(m);if(_)h.envelope=_;F(h)}})})}export{cg as runExtractor,S as ENGINES};
|