@duckmind/dm-windows-x64 0.59.9 → 0.60.4
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/extensions/.dm-extensions.json +6 -6
- package/extensions/dm-cua/bin/browser-cua.mjs +4 -4
- package/extensions/dm-cua/index.js +3 -3
- package/extensions/dm-cua/src/browser-cua-lib.mjs +3 -3
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +5 -3
- package/extensions/greedysearch-dm/bin/mcp.mjs +52 -52
- package/extensions/greedysearch-dm/bin/search.mjs +130 -131
- package/extensions/greedysearch-dm/extractors/consensus.mjs +42 -43
- package/extensions/greedysearch-dm/extractors/gemini.mjs +52 -53
- package/extensions/greedysearch-dm/extractors/logically.mjs +33 -34
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +9 -10
- package/extensions/greedysearch-dm/src/search/chrome.mjs +21 -22
- package/extensions/greedysearch-dm/src/search/engines.mjs +7 -7
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +48 -48
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +119 -119
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +7 -7
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +125 -125
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +11 -11
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as Gt,execFileSync as ue,execSync as cn}from"node:child_process";import{basename as Re}from"node:path";function de(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=Re(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}import{existsSync as ce,readFileSync as V,renameSync as Ft,unlinkSync as h,writeFileSync as R}from"node:fs";import fe from"node:http";import{platform as Ue}from"node:os";import{spawn as Le}from"node:child_process";import{basename as Ve}from"node:path";import{dirname as Ie,join as Ee}from"node:path";import{fileURLToPath as Ye}from"node:url";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=Ve(t||"").toLowerCase();if(n==="node"||n==="node.exe")return t;return"node"}var Ge=Ie(Ye(import.meta.url)),Fe=Ee(Ge,"..","bin","cdp.mjs"),Ke=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function et(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(!Ke.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 I(e,t=30000){return tt(e,null,t)}function tt(e,t=null,r=30000){let n=et(e);return new Promise((i,a)=>{let o=Le(ze(),[Fe,...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 f=setTimeout(()=>{o.kill(),a(Error(`cdp timeout: ${e[0]}`))},r);o.on("close",(u)=>{if(clearTimeout(f),u===0)i(s.trim());else a(Error(l.trim()||`cdp exit ${u}`))})})}async function E(e){await I(["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(_) {}
|
|
@@ -283,28 +283,27 @@ import{spawn as Jt,execFileSync as se,execSync as Zr}from"node:child_process";im
|
|
|
283
283
|
};
|
|
284
284
|
} catch(_) {}
|
|
285
285
|
})();
|
|
286
|
-
`})])}import{existsSync as
|
|
286
|
+
`})])}import{existsSync as he}from"node:fs";import{platform as rt}from"node:os";import{join as _}from"node:path";function C(e){let t=rt()==="win32",r=process.env.SystemRoot||"C:\\Windows",n={win32:{powershell:_(r,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:_(r,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:_(r,"System32","netstat.exe"),taskkill:_(r,"System32","taskkill.exe"),tasklist:_(r,"System32","tasklist.exe"),cmd:_(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]&&he(i[a]))return i[a];if(t&&a==="netstat"){let o=_(r,"Sysnative","netstat.exe");if(he(o))return o}return e}import{execFileSync as nt}from"node:child_process";import{platform as it}from"node:os";function at(e,t){return nt(C(e),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function ot(e){let t=String(e||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function st(e){return ot(e)}function lt(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 ut(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 Y(e,t,r){try{return e(t,r)}catch{return null}}function ye(e,{platformName:t=it(),run:r=at}={}){if(t==="win32")return ut(Y(r,"netstat",["-ano","-p","TCP"]),e);let n=Y(r,"lsof",["-nP",`-iTCP:${e}`,"-sTCP:LISTEN","-t"]),i=st(n);if(i)return i;if(t!=="linux")return null;return lt(Y(r,"ss",["-ltnp"]),e)}import{existsSync as be}from"node:fs";import{dirname as ct,join as k}from"node:path";import{fileURLToPath as ft}from"node:url";function we(e){return ft(new URL(".",e)).replace(/^\/([A-Z]:)/,"$1")}function pt(e,t=be){let r=new Set;for(let n of e.filter(Boolean)){if(r.has(n))continue;if(r.add(n),t(n))return n}return e.filter(Boolean).at(-1)}function _e({moduleDir:e,entrypoint:t=process.argv[1],env:r=process.env,exists:n=be}={}){let i=t?ct(t):null,a=r.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return pt([e?k(e,"..","..","bin","launch.mjs"):null,e?k(e,"launch.mjs"):null,a?k(a,"bin","launch.mjs"):null,i?k(i,"launch.mjs"):null,i?k(i,"..","bin","launch.mjs"):null],n)}import{existsSync as O,mkdirSync as gt,readFileSync as xe,writeFileSync as dt}from"node:fs";import{homedir as mt}from"node:os";import{join as Pe}from"node:path";import{tmpdir as ht}from"node:os";function yt(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var bt=ht().replaceAll("\\","/"),g=yt(process.env.GREEDY_SEARCH_PORT),p=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${bt}/greedysearch-chrome-profile`).replaceAll("\\","/"),D=`${p}/DevToolsActivePort`,Ae=process.env.GREEDY_SEARCH_PID_FILE||`${p}/browser.pid`,te=process.env.CDP_PAGES_CACHE||`${p}/cdp-pages.json`,j=process.env.GREEDY_SEARCH_MODE_FILE||`${p}/browser-mode`,Tr=process.env.GREEDY_SEARCH_METADATA_FILE||`${p}/browser-metadata.json`,Wr=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${p}/browser-launch.lock`,Se=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${p}/browser-last-activity`,Mr=(process.env.CDP_SOCKET_DIR||`${p}/cdp-sockets`).replaceAll("\\","/"),Or=`${p}/visible-recovery.jsonl`,F=Pe(mt(),".dm"),d=Pe(F,"greedyconfig"),K=["perplexity","google","chatgpt","gemini"],ee="gemini";function wt(){try{if(O(d)){let e=xe(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)=>G[i]),n=t.engines.filter((i)=>!G[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${d}: ${n.join(", ")}
|
|
287
287
|
[greedysearch] Available engines: ${Object.keys(G).join(", ")}
|
|
288
288
|
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${d}, falling back to defaults: ${K.join(", ")}
|
|
289
|
-
`)}}}catch{}return K}function
|
|
290
|
-
`,"utf8")}catch{}}
|
|
291
|
-
[greedysearch] Available synthesizers: ${
|
|
289
|
+
`)}}}catch{}return K}function _t(){try{if(!O(F))gt(F,{recursive:!0});if(!O(d))dt(d,JSON.stringify({engines:K,synthesizer:ee},null,2)+`
|
|
290
|
+
`,"utf8")}catch{}}_t();var ve=["gemini","chatgpt"];function vt(){try{if(O(d)){let e=xe(d,"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 ${d}
|
|
291
|
+
[greedysearch] Available synthesizers: ${ve.join(", ")}
|
|
292
292
|
[greedysearch] Falling back to default: ${ee}
|
|
293
|
-
`)}}}catch{}return ee}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"},
|
|
293
|
+
`)}}}catch{}return ee}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"},Jr=wt();var qr=vt(),Hr=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=p;import{execFileSync as Ce,execSync as Br}from"node:child_process";import{existsSync as J,mkdirSync as xt,readFileSync as $,unlinkSync as P,writeFileSync as A}from"node:fs";import{platform as Pt}from"node:os";import{existsSync as q,mkdirSync as At,readFileSync as Te,writeFileSync as St}from"node:fs";import{homedir as Ct}from"node:os";import{join as We}from"node:path";import{tmpdir as jt}from"node:os";import{existsSync as $e}from"node:fs";import{platform as Ht}from"node:os";import{join as v}from"node:path";import{execFileSync as Ut}from"node:child_process";import{platform as Xt}from"node:os";function $t(e,t=9222){let r=Number.parseInt(String(e??""),10);return Number.isInteger(r)&&r>1024&&r<65535?r:t}var kt=jt().replaceAll("\\","/"),S=$t(process.env.GREEDY_SEARCH_PORT),c=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${kt}/greedysearch-chrome-profile`).replaceAll("\\","/"),Ir=`${c}/DevToolsActivePort`,Dt=process.env.GREEDY_SEARCH_PID_FILE||`${c}/browser.pid`,Er=process.env.CDP_PAGES_CACHE||`${c}/cdp-pages.json`,Nt=process.env.GREEDY_SEARCH_MODE_FILE||`${c}/browser-mode`,Tt=process.env.GREEDY_SEARCH_METADATA_FILE||`${c}/browser-metadata.json`,Wt=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${c}/browser-launch.lock`,Mt=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${c}/browser-last-activity`,Yr=(process.env.CDP_SOCKET_DIR||`${c}/cdp-sockets`).replaceAll("\\","/"),Gr=`${c}/visible-recovery.jsonl`,ie=We(Ct(),".dm"),m=We(ie,"greedyconfig"),ae=["perplexity","google","chatgpt","gemini"],oe="gemini";function Ot(){try{if(q(m)){let e=Te(m,"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)=>re[i]),n=t.engines.filter((i)=>!re[i]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${m}: ${n.join(", ")}
|
|
294
294
|
[greedysearch] Available engines: ${Object.keys(re).join(", ")}
|
|
295
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${m}, falling back to defaults: ${
|
|
296
|
-
`)}}}catch{}return
|
|
297
|
-
`,"utf8")}catch{}}
|
|
298
|
-
[greedysearch] Available synthesizers: ${
|
|
299
|
-
[greedysearch] Falling back to default: ${
|
|
300
|
-
`)}}}catch{}return
|
|
301
|
-
`)
|
|
302
|
-
`)
|
|
303
|
-
`)
|
|
304
|
-
`);return!1
|
|
305
|
-
`);return t}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
`),await
|
|
309
|
-
`)
|
|
310
|
-
`);let o=[qt(Xt,"..","..","bin","launch.mjs")];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")o.push("--headless");await new Promise((s,l)=>{Jt(pe(),o,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(u)=>u===0?s():l(Error("launch.mjs failed")))})}finally{n.release()}}export{Qt as touchActivity,Q as refreshPortFile,y as probeGreedyChrome,Kr as openNewTab,We as killHeadlessChrome,Xe as killChrome,He as isChromeHeadless,rn as getFullTabFromCache,ce as getAnyTab,nn as ensureChrome,Zt as detectHeadlessFromChromeCommandLine,tn as closeTabs,It as closeTab,Lt as checkAndKillIdle,b as cdp,en as activateTab};
|
|
295
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${m}, falling back to defaults: ${ae.join(", ")}
|
|
296
|
+
`)}}}catch{}return ae}function Jt(){try{if(!q(ie))At(ie,{recursive:!0});if(!q(m))St(m,JSON.stringify({engines:ae,synthesizer:oe},null,2)+`
|
|
297
|
+
`,"utf8")}catch{}}Jt();var je=["gemini","chatgpt"];function qt(){try{if(q(m)){let e=Te(m,"utf8"),t=JSON.parse(e);if(typeof t.synthesizer==="string"){let r=t.synthesizer.toLowerCase();if(je.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${m}
|
|
298
|
+
[greedysearch] Available synthesizers: ${je.join(", ")}
|
|
299
|
+
[greedysearch] Falling back to default: ${oe}
|
|
300
|
+
`)}}}catch{}return oe}var re={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"},Fr=Ot(),Kr=qt(),en=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=c;function se(e){let t=Ht()==="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]&&$e(i[a]))return i[a];if(t&&a==="netstat"){let o=v(r,"Sysnative","netstat.exe");if($e(o))return o}return e}function Bt(e,t){return Ut(se(e),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function Qt(e){let t=String(e||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function Zt(e){return Qt(e)}function Rt(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 Lt(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 ne(e,t,r){try{return e(t,r)}catch{return null}}function Vt(e,{platformName:t=Xt(),run:r=Bt}={}){if(t==="win32")return Lt(ne(r,"netstat",["-ano","-p","TCP"]),e);let n=ne(r,"lsof",["-nP",`-iTCP:${e}`,"-sTCP:LISTEN","-t"]),i=Zt(n);if(i)return i;if(t!=="linux")return null;return Rt(ne(r,"ss",["-ltnp"]),e)}var H=Tt,x=Wt,zt=15000,U=Dt,X=Nt,N=Mt;function T(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function It(e){if(!T(e))return null;try{if(Pt()==="win32")return Ce(se("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${e}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return Ce(se("ps"),["-p",String(e),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Et(e,t,r=S){if(!e)return!1;let n=(o)=>String(o||"").replaceAll("\\","/").toLowerCase(),i=n(e),a=n(t);return i.includes(a)&&i.includes(`--remote-debugging-port=${r}`)&&!i.includes("--type=")}function ke(e,t,r=S){return Et(It(e),t,r)}function Yt(e=S){return Vt(e)}function W(){try{if(J(H)){let e=$(H,"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{let e=J(U)?Number.parseInt($(U,"utf8").trim(),10)||void 0:void 0,t=J(X)?$(X,"utf8").trim()==="visible"?"visible":"headless":"headless",r=J(N)?Number.parseInt($(N,"utf8").trim(),10)||0:0;return{browserPid:e,debugPort:S,tempDir:c,clientPids:e?[e]:[],sessionMode:t,lastActivity:r,launchedAt:0}}catch{return null}}function B(e){try{A(H,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)A(U,String(e.browserPid),"utf8")}catch{}try{A(X,e.sessionMode,"utf8")}catch{}try{A(N,String(e.lastActivity),"utf8")}catch{}}function De(){try{P(H)}catch{}try{P(U)}catch{}try{P(X)}catch{}try{P(N)}catch{}}function le(e){if(!e)return e;let t={...e,clientPids:[...new Set([...e.clientPids,process.pid].filter((r)=>T(r)||r===process.pid))]};return B(t),t}function Q(e){let t=Date.now();try{if(e)B({...e,lastActivity:t});else A(N,String(t),"utf8")}catch{}}var sn=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Ne=!1;function Me(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD)return;if(Ne)return;Ne=!0;let e=W();if(!e)return;if(e.browserPid){if(!T(e.browserPid)){De();return}if(!ke(e.browserPid,e.tempDir,e.debugPort))De();else B({...e,clientPids:e.clientPids.filter((r)=>T(r))})}let t=Yt();if(t&&t!==e.browserPid)if(ke(t,c,S))B({browserPid:t,debugPort:S,tempDir:c,clientPids:[t],sessionMode:e.sessionMode,lastActivity:Date.now(),launchedAt:Date.now()});else process.stderr.write(`[greedysearch] Refusing to kill unverified listener ${t} on port ${S}.
|
|
301
|
+
`)}function Oe(){xt(c,{recursive:!0});try{let e=JSON.stringify({pid:process.pid,ts:Date.now()});return A(x,e,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{let t=$(x,"utf8");if(JSON.parse(t).pid===process.pid)P(x)}catch{}}}}catch(e){if(e?.code!=="EEXIST")return{acquired:!1,release:()=>{}}}try{let e=$(x,"utf8"),t=JSON.parse(e),r=Date.now()-(t.ts||0);if(!T(t.pid)||r>zt){try{P(x)}catch{}try{let n=JSON.stringify({pid:process.pid,ts:Date.now()});return A(x,n,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{P(x)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}var Kt=we(import.meta.url),Je=Ae,M=Se,er=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,tr=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;function rr(e,t=g){let r=String(e||"").toLowerCase();if(!r.includes(`--remote-debugging-port=${t}`)||r.includes("--type="))return null;return r.includes("--headless")}function Xe(){try{let e=z(),t=e?Be(e):null,r=rr(t);if(r!==null){try{R(j,r?"headless":"visible","utf8")}catch{}return r}}catch{}try{if(!ce(j))return!0;return V(j,"utf8").trim()==="headless"}catch{return!0}}function nr(){try{R(M,String(Date.now()),"utf8")}catch{}try{let e=W();if(e)Q(e)}catch{}}function Be(e){try{if(Ue()==="win32")return ue(C("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${e}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return ue(C("ps"),["-p",String(e),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function ir(e){let t=String(e||"").replaceAll("\\","/"),r=p.replaceAll("\\","/");return t.includes(`--remote-debugging-port=${g}`)&&t.includes(`--user-data-dir=${r}`)&&!t.includes("--type=")}function z(){return ye(g)}function L(){let e=z();return e&&ir(Be(e))?e:null}async function ar(e=1500){let t=L();if(!t)return process.stderr.write(`[greedysearch] Refusing to close an unverified listener.
|
|
302
|
+
`),!1;try{let n=await new Promise((a,o)=>{let s=fe.get(`http://localhost:${g}/json/version`,(l)=>{let f="";l.on("data",(u)=>f+=u),l.on("end",()=>{try{a(JSON.parse(f))}catch{o(Error("bad JSON"))}})});s.on("error",o),s.setTimeout(1000,()=>{s.destroy(),o(Error("timeout"))})}),i=new globalThis.WebSocket(n.webSocketDebuggerUrl);await new Promise((a)=>{i.onopen=()=>{if(L()!==t){i.close(),a();return}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=z();if(!n)return!0;if(n!==t)return!1;await new Promise((i)=>setTimeout(i,150))}return or(t)}function or(e=null){try{let t=L();if(!t||e&&t!==e)return!1;if(Ue()==="win32")ue(C("taskkill"),["/F","/PID",String(t)],{stdio:"ignore",windowsHide:!0});else process.kill(t,"SIGKILL");return!0}catch{return!1}}async function Qe(){if(!L()){if(z())process.stderr.write(`[greedysearch] Refusing to kill an unverified listener.
|
|
303
|
+
`);return!1}if(!await y(500)){try{h(Je)}catch{}try{h(M)}catch{}try{h(j)}catch{}return!1}let t=await ar(1500);try{h(Je)}catch{}try{h(M)}catch{}try{h(j)}catch{}if(t)process.stderr.write(`[greedysearch] Killed Chrome on port ${g}.
|
|
304
|
+
`);return t}var qe=Qe;async function sr(){let t=Xe()?er:tr;if(t<=0)return!1;if(!ce(M))return nr(),!1;try{let r=Number.parseInt(V(M,"utf8").trim(),10);if(!r)return!1;if((Date.now()-r)/60000>=t)return Qe()}catch{}return!1}var b=I;async function pe(){let t=(await b(["list"])).split(`
|
|
305
|
+
`)[0];if(!t)throw Error("No Chrome tabs found");return t.slice(0,8)}async function vn(e="about:blank"){let t=await pe(),r=new URL(e).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let o=await b(["evalraw",t,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:s}=JSON.parse(o),l=s.slice(0,8);if(await b(["list"]).catch(()=>null),r==="copilot.microsoft.com")await E(l);else E(l).catch(()=>{});return await b(["list"]).catch(()=>null),s}let i=await b(["evalraw",t,"Target.createTarget",JSON.stringify({url:e})]),{targetId:a}=JSON.parse(i);return await b(["list"]).catch(()=>null),a}async function xn(e){try{let t=await pe();await b(["evalraw",t,"Target.activateTarget",JSON.stringify({targetId:e})])}catch{}}async function lr(e){try{let t=await pe();await b(["evalraw",t,"Target.closeTarget",JSON.stringify({targetId:e})])}catch{}}async function Pn(e=[]){if(await Promise.all(e.filter(Boolean).map((t)=>lr(t).catch(()=>{}))),e.length>0)await b(["list"]).catch(()=>null)}function An(e,t){try{if(!ce(te))return null;let n=JSON.parse(V(te,"utf8")).find((i)=>i.url.includes(t[e]));return n?n.targetId:null}catch{return null}}function y(e=3000){return new Promise((t)=>{let r=fe.get(`http://localhost:${g}/json/version`,(n)=>{n.resume(),t(n.statusCode===200)});r.on("error",()=>t(!1)),r.setTimeout(e,()=>{r.destroy(),t(!1)})})}async function He(e=3000,t=200){let r=Date.now()+e;while(Date.now()<r){if(!await y(300))return!0;await new Promise((n)=>setTimeout(n,t))}return!await y(300)}async function Z(){let e=`${D}.lock`,t=`${D}.tmp`,r=5000,n=1000,i=await new Promise((a)=>{let o=Date.now(),s=()=>{try{let l=JSON.stringify({pid:process.pid,ts:Date.now()});R(e,l,{encoding:"utf8",flag:"wx"}),a(!0)}catch(l){if(l?.code!=="EEXIST"){if(Date.now()-o<1000)setTimeout(s,50);else a(!1);return}try{let f=V(e,"utf8").trim(),u=f.startsWith("{")?JSON.parse(f):{ts:Number(f)},w=Number(u?.ts)||0;if(w>0&&Date.now()-w>5000)try{h(e)}catch{}if(Date.now()-o<1000)setTimeout(s,50);else a(!1)}catch{if(Date.now()-o<1000)setTimeout(s,50);else a(!1)}}};s()});try{let a=await new Promise((l,f)=>{let u=fe.get(`http://localhost:${g}/json/version`,(w)=>{let ge="";w.on("data",(Ze)=>ge+=Ze),w.on("end",()=>l(ge))});u.on("error",f),u.setTimeout(3000,()=>{u.destroy(),f(Error("timeout"))})}),{webSocketDebuggerUrl:o}=JSON.parse(a),s=new URL(o).pathname;if(i){R(t,`${g}
|
|
306
|
+
${s}`,"utf8");try{h(D)}catch{}Ft(t,D)}}catch{}finally{if(i)try{h(e)}catch{}}}async function Sn(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD&&await y()){await Z();try{let a=W();if(a)Q(a),le(a)}catch{}return}Me();let e=await sr(),t=e?!1:await y();if(!t&&!e)await new Promise((a)=>setTimeout(a,500)),t=await y();let r=!1;if(t){let a=Xe(),o=process.env.GREEDY_SEARCH_VISIBLE==="1";if(!o&&!a)process.stderr.write(`[greedysearch] Visible Chrome detected — switching to headless mode...
|
|
307
|
+
`),await qe(),await He(),r=!0;else if(o&&a)process.stderr.write(`[greedysearch] Headless Chrome detected — switching to visible mode...
|
|
308
|
+
`),await qe(),await He(),r=!0}if(r?!1:await y()){await Z();try{let a=W();if(a)Q(a),le(a)}catch{}return}let i=Oe();if(!i.acquired){let a=Date.now()+12000,o=!1;while(Date.now()<a){if(o=await y(500),o)break;await new Promise((s)=>setTimeout(s,250))}if(o){await Z();return}}try{if(await y(1000)){await Z();return}process.stderr.write(`GreedySearch Chrome not running on port ${g} — auto-launching...
|
|
309
|
+
`);let s=[_e({moduleDir:Kt,entrypoint:process.argv[1],env:process.env})];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")s.push("--headless");await new Promise((l,f)=>{Gt(de(),s,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(w)=>w===0?l():f(Error("launch.mjs failed")))})}finally{i.release()}}export{nr as touchActivity,Z as refreshPortFile,y as probeGreedyChrome,vn as openNewTab,qe as killHeadlessChrome,Qe as killChrome,Xe as isChromeHeadless,An as getFullTabFromCache,pe as getAnyTab,Sn as ensureChrome,rr as detectHeadlessFromChromeCommandLine,Pn as closeTabs,lr as closeTab,sr as checkAndKillIdle,b as cdp,xn as activateTab};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{spawn as J}from"node:child_process";import{basename as
|
|
1
|
+
import{spawn as J}from"node:child_process";import{basename as v}from"node:path";function u(n=process.env,e=process.execPath){let s=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(s?.trim())return s.trim();let i=v(e||"").toLowerCase();if(i==="node"||i==="node.exe")return e;return"node"}import{existsSync as S,mkdirSync as j,readFileSync as N,writeFileSync as w}from"node:fs";import{homedir as P}from"node:os";import{join as T}from"node:path";import{tmpdir as b}from"node:os";function x(n,e=9222){let s=Number.parseInt(String(n??""),10);return Number.isInteger(s)&&s>1024&&s<65535?s:e}var U=b().replaceAll("\\","/"),sn=x(process.env.GREEDY_SEARCH_PORT),r=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${U}/greedysearch-chrome-profile`).replaceAll("\\","/"),en=`${r}/DevToolsActivePort`,rn=process.env.GREEDY_SEARCH_PID_FILE||`${r}/browser.pid`,an=process.env.CDP_PAGES_CACHE||`${r}/cdp-pages.json`,En=process.env.GREEDY_SEARCH_MODE_FILE||`${r}/browser-mode`,ln=process.env.GREEDY_SEARCH_METADATA_FILE||`${r}/browser-metadata.json`,on=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${r}/browser-launch.lock`,tn=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${r}/browser-last-activity`,gn=(process.env.CDP_SOCKET_DIR||`${r}/cdp-sockets`).replaceAll("\\","/"),cn=`${r}/visible-recovery.jsonl`,A=T(P(),".dm"),l=T(A,"greedyconfig"),D=["perplexity","google","chatgpt","gemini"],p="gemini";function k(){try{if(S(l)){let n=N(l,"utf8"),e=JSON.parse(n);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((s)=>typeof s==="string")){let s=e.engines.filter((a)=>y[a]),i=e.engines.filter((a)=>!y[a]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${l}: ${i.join(", ")}
|
|
2
2
|
[greedysearch] Available engines: ${Object.keys(y).join(", ")}
|
|
3
|
-
`);if(
|
|
4
|
-
`)}}}catch{}return
|
|
5
|
-
`,"utf8")}catch{}}z();var
|
|
6
|
-
[greedysearch] Available synthesizers: ${
|
|
3
|
+
`);if(s.length>0)return s;process.stderr.write(`[greedysearch] Warning: no valid engines in ${l}, falling back to defaults: ${D.join(", ")}
|
|
4
|
+
`)}}}catch{}return D}function z(){try{if(!S(A))j(A,{recursive:!0});if(!S(l))w(l,JSON.stringify({engines:D,synthesizer:p},null,2)+`
|
|
5
|
+
`,"utf8")}catch{}}z();var L=["gemini","chatgpt"];function V(){try{if(S(l)){let n=N(l,"utf8"),e=JSON.parse(n);if(typeof e.synthesizer==="string"){let s=e.synthesizer.toLowerCase();if(L.includes(s))return s;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${l}
|
|
6
|
+
[greedysearch] Available synthesizers: ${L.join(", ")}
|
|
7
7
|
[greedysearch] Falling back to default: ${p}
|
|
8
|
-
`)}}}catch{}return p}var y={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"},
|
|
9
|
-
`),
|
|
8
|
+
`)}}}catch{}return p}var y={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"},_n=k();var Rn=V(),mn=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=r;import{existsSync as Y}from"node:fs";import{dirname as B,join as h}from"node:path";import{fileURLToPath as K}from"node:url";function G(n){return K(new URL(".",n)).replace(/^\/([A-Z]:)/,"$1")}function Z(n,e=Y){let s=new Set;for(let i of n.filter(Boolean)){if(s.has(i))continue;if(s.add(i),e(i))return i}return n.filter(Boolean).at(-1)}function F(n,{moduleDir:e,entrypoint:s=process.argv[1],env:i=process.env,exists:a=Y}={}){let R=s?B(s):null,m=i.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return Z([e?h(e,"..","..","extractors",n):null,e?h(e,"..","extractors",n):null,m?h(m,"extractors",n):null,R?h(R,"..","extractors",n):null],a)}var W=G(import.meta.url);function un(n,e,s=null,i=!1,a=null,R=null){if(a===null)a=n.includes("logically")?120000:n.includes("chatgpt")?80000:n.includes("gemini")?70000:60000;let m=[...s?["--tab",s]:[],...i?["--short"]:[],...R?["--locale",R]:[]];return new Promise((H,C)=>{let $=F(n,{moduleDir:W}),c=J(u(),[$,"--stdin",...m],{stdio:["pipe","pipe","pipe"],env:{...process.env,CDP_PROFILE_DIR:r}});c.stdin.write(e),c.stdin.end();let _="",f="";c.stdout.on("data",(E)=>_+=E),c.stderr.on("data",(E)=>{if(f+=E,process.env.GREEDY_SEARCH_CHILD_STDERR!=="0")process.stderr.write(E)});let O=setTimeout(()=>{c.kill();let E=(g,I=20)=>String(g??"").split(/\r?\n/).filter(Boolean).slice(-I).join(`
|
|
9
|
+
`),o=null;try{let g=JSON.parse(_.trim());if(g._envelope)o=g._envelope}catch{}let t=Error(`${n} timed out after ${a/1000}s`+(o?.lastStage?` (last stage: ${o.lastStage})`:""));t.engineScript=n,t.lastStage=o?.lastStage||null,t.partialErr=E(f),t.partialOut=E(_),C(t)},a);c.on("close",(E)=>{if(clearTimeout(O),E===0)try{H(JSON.parse(_.trim()))}catch{C(Error(`bad JSON from ${n}: ${_.slice(0,100)}`))}else{let o=null;try{let I=JSON.parse(_.trim());if(I._envelope)o=I._envelope}catch{}let t=f.trim()||`extractor exit ${E}`,g=Error(t);if(o)g.envelope=o;C(g)}})})}export{un as runExtractor,y as ENGINES};
|