@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,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{randomInt as
|
|
3
|
-
`)[0]?.slice(0,8);if(!t)throw Error("No Chrome tabs found. Is Chrome running with --remote-debugging-port=9222?");let e=await
|
|
4
|
-
`)}return
|
|
2
|
+
import{randomInt as rt}from"node:crypto";import{spawn as it}from"node:child_process";import{basename as ot}from"node:path";import{dirname as lt,join as ft}from"node:path";import{fileURLToPath as at}from"node:url";function ut(n=process.env,t=process.execPath){let e=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(e?.trim())return e.trim();let i=ot(t||"").toLowerCase();if(i==="node"||i==="node.exe")return t;return"node"}var gt=lt(at(import.meta.url)),st=ft(gt,"..","bin","cdp.mjs"),ht=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function ct(n){if(!Array.isArray(n)||n.length===0)throw Error("cdp: args must be a non-empty array");if(n[0]==="test")return n.map((t,e)=>_n(t,e));if(!ht.has(n[0]))throw Error(`cdp: unknown subcommand '${n[0]}'`);return n.map((t,e)=>_n(t,e))}function _n(n,t){if(typeof n!=="string")throw Error(`cdp: argv[${t}] must be a string (got ${typeof n})`);if(n.includes("\x00"))throw Error(`cdp: argv[${t}] contains a null byte`);return n}function a(n,t=30000){return en(n,null,t)}function en(n,t=null,e=30000){let i=ct(n);return new Promise((r,o)=>{let u=it(ut(),[st,...i],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)u.stdin.write(t),u.stdin.end();let l="",g="";u.stdout.on("data",(s)=>l+=s),u.stderr.on("data",(s)=>g+=s);let f=setTimeout(()=>{u.kill(),o(Error(`cdp timeout: ${n[0]}`))},e);u.on("close",(s)=>{if(clearTimeout(f),s===0)r(l.trim());else o(Error(g.trim()||`cdp exit ${s}`))})})}function mn(n,t){let e=(u)=>String(u??"").replace(/\s+/g," ").trim(),i=e(n),r=e(t);if(!r)return!1;if(i.length<Math.ceil(r.length*0.8))return!1;let o=Math.min(40,r.length);return i.includes(r.slice(0,o))&&i.includes(r.slice(-o))}async function $n(n){if(n)return n;let t=(await a(["list"])).split(`
|
|
3
|
+
`)[0]?.slice(0,8);if(!t)throw Error("No Chrome tabs found. Is Chrome running with --remote-debugging-port=9222?");let e=await a(["evalraw",t,"Target.createTarget",'{"url":"about:blank"}']),i;try{i=JSON.parse(e)}catch(u){throw Error(`Target.createTarget returned invalid JSON: ${u.message}`)}let{targetId:r}=i;if(!r)throw Error("Target.createTarget did not return a targetId");await a(["list"]);let o=r.slice(0,8);try{await bn(o)}catch(u){process.stderr.write(`[getOrOpenTab] stealth injection failed: ${u.message}
|
|
4
|
+
`)}return o}async function bn(n){await a(["evalraw",n,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
5
5
|
(function() {
|
|
6
6
|
// ── Runtime.enable / CDP detection masking ──────────────
|
|
7
7
|
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
@@ -286,10 +286,10 @@ import{randomInt as tt}from"node:crypto";import{spawn as et}from"node:child_proc
|
|
|
286
286
|
};
|
|
287
287
|
} catch(_) {}
|
|
288
288
|
})();
|
|
289
|
-
`})])}var
|
|
289
|
+
`})])}var rn={postNav:800,postNavSlow:1200,postClick:300,postType:300,inputPoll:400,copyPoll:600,afterVerify:1500};function q(n){let t=n*0.2,e=rt(-Math.floor(t),Math.floor(t)+1);return Math.max(50,Math.round(n+e))}async function B(n,t,e=15000,i=500){let r=String.raw`
|
|
290
290
|
new Promise((resolve) => {
|
|
291
291
|
const _deadline = Date.now() + ${e};
|
|
292
|
-
const _baseInterval = ${
|
|
292
|
+
const _baseInterval = ${i};
|
|
293
293
|
|
|
294
294
|
function _jitter(ms) {
|
|
295
295
|
return Math.max(50, ms + (Math.random() * ms * 0.4 - ms * 0.2));
|
|
@@ -305,26 +305,25 @@ import{randomInt as tt}from"node:crypto";import{spawn as et}from"node:child_proc
|
|
|
305
305
|
|
|
306
306
|
_poll();
|
|
307
307
|
})
|
|
308
|
-
`;return await
|
|
309
|
-
`)}function
|
|
308
|
+
`;return await a(["eval",n,r],e+5000)==="true"}async function Wn(n){let t=n.indexOf("--stdin");if(t===-1)return n;let e=await new Promise((r)=>{let o="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(u)=>o+=u),process.stdin.on("end",()=>r(o.trim()))}),i=[...n];return i[t]=e,i}function xn(n){let t=n.includes("--short"),e=n.filter((l)=>l!=="--short"),i=e.indexOf("--tab"),r=i===-1?null:e[i+1];if(i!==-1)e=e.filter((l,g)=>g!==i&&g!==i+1);let o=e.indexOf("--locale"),u=o===-1?null:e[o+1];if(o!==-1)e=e.filter((l,g)=>g!==o&&g!==o+1);return{query:e.join(" "),tabPrefix:r,short:t,locale:u}}function jn(n,t){if(!n.length||n[0]==="--help")process.stderr.write(t),process.exit(1)}function Jn(n,t,e=300){if(!t||n.length<=e)return n;let i=n.slice(0,e),r=i.lastIndexOf(" ");return r>0?`${i.slice(0,r)}…`:`${i}…`}function Nn(n){process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
309
|
+
`)}function y(n,t,e=null){if(!n||typeof n!=="object")return;let i=e?` (+${Date.now()-e}ms)`:"";if(n.lastStage=t,!Array.isArray(n.stages))n.stages=[];n.stages.push({stage:t,at:Date.now()});let r=n.engine||"extractor";console.error(`[${r}] stage: ${t}${i}`)}function on({engine:n,mode:t="headless",clipboardEmpty:e=null,fallbackUsed:i=null,blockedBy:r=null,verificationResult:o=null,inputReady:u=null,durationMs:l=null,lastStage:g=null,stages:f=null}={}){return{engine:n,mode:t,clipboardEmpty:e,fallbackUsed:i,blockedBy:r,verificationResult:o,inputReady:u,durationMs:l,lastStage:g,stages:f}}function Zn(n,t=null){if(t){let e=JSON.stringify({_envelope:t,error:n.message});process.stdout.write(`${e}
|
|
310
310
|
`)}process.stderr.write(`Error: ${n.message}
|
|
311
|
-
`),process.exit(1)}import{spawn as
|
|
312
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
313
|
-
`);if(e.length>0)return e;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
314
|
-
`)}}}catch{}return
|
|
315
|
-
`,"utf8")}catch{}}
|
|
316
|
-
[greedysearch] Available synthesizers: ${
|
|
317
|
-
[greedysearch] Falling back to default: ${
|
|
318
|
-
`)}}}catch{}return
|
|
319
|
-
`)
|
|
320
|
-
`)
|
|
321
|
-
`)
|
|
322
|
-
`);return!1
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
`),await
|
|
326
|
-
`)
|
|
327
|
-
`);let u=[At(Ot,"..","..","bin","launch.mjs")];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")u.push("--headless");await new Promise((l,a)=>{Ut(Nn(),u,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(h)=>h===0?l():a(Error("launch.mjs failed")))})}finally{i.release()}}var Lt=`
|
|
311
|
+
`),process.exit(1)}import{spawn as Pt,execFileSync as hn,execSync as de}from"node:child_process";import{basename as pt}from"node:path";function Xn(n=process.env,t=process.execPath){let e=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(e?.trim())return e.trim();let i=pt(t||"").toLowerCase();if(i==="node"||i==="node.exe")return t;return"node"}import{existsSync as Sn,readFileSync as cn,renameSync as Kt,unlinkSync as $,writeFileSync as E}from"node:fs";import pn from"node:http";import{platform as Ln}from"node:os";import{existsSync as qn}from"node:fs";import{platform as wt}from"node:os";import{join as x}from"node:path";function _(n){let t=wt()==="win32",e=process.env.SystemRoot||"C:\\Windows",i={win32:{powershell:x(e,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:x(e,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:x(e,"System32","netstat.exe"),taskkill:x(e,"System32","taskkill.exe"),tasklist:x(e,"System32","tasklist.exe"),cmd:x(e,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},r=t?i.win32:i.unix,o=n.toLowerCase();if(r[o]&&qn(r[o]))return r[o];if(t&&o==="netstat"){let u=x(e,"Sysnative","netstat.exe");if(qn(u))return u}return n}import{execFileSync as yt}from"node:child_process";import{platform as vt}from"node:os";function _t(n,t){return yt(_(n),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function mt(n){let t=String(n||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function $t(n){return mt(n)}function bt(n,t){for(let e of String(n||"").split(/\r?\n/)){if(!/\bLISTEN\b/i.test(e))continue;if(!e.trim().split(/\s+/).slice(0,6).some((o)=>o.endsWith(`:${t}`)))continue;let r=e.match(/\bpid=(\d+)\b/);if(r)return Number.parseInt(r[1],10)}return null}function Wt(n,t){for(let e of String(n||"").split(/\r?\n/)){let i=e.trim().split(/\s+/);if(i.length<5||i[0].toUpperCase()!=="TCP")continue;if(!i.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!i[1].endsWith(`:${t}`))continue;let r=Number.parseInt(i.at(-1),10);if(Number.isInteger(r)&&r>0)return r}return null}function un(n,t,e){try{return n(t,e)}catch{return null}}function P(n,{platformName:t=vt(),run:e=_t}={}){if(t==="win32")return Wt(un(e,"netstat",["-ano","-p","TCP"]),n);let i=un(e,"lsof",["-nP",`-iTCP:${n}`,"-sTCP:LISTEN","-t"]),r=$t(i);if(r)return r;if(t!=="linux")return null;return bt(un(e,"ss",["-ltnp"]),n)}import{existsSync as Bn}from"node:fs";import{dirname as xt,join as Q}from"node:path";import{fileURLToPath as jt}from"node:url";function Qn(n){return jt(new URL(".",n)).replace(/^\/([A-Z]:)/,"$1")}function Jt(n,t=Bn){let e=new Set;for(let i of n.filter(Boolean)){if(e.has(i))continue;if(e.add(i),t(i))return i}return n.filter(Boolean).at(-1)}function kn({moduleDir:n,entrypoint:t=process.argv[1],env:e=process.env,exists:i=Bn}={}){let r=t?xt(t):null,o=e.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null;return Jt([n?Q(n,"..","..","bin","launch.mjs"):null,n?Q(n,"launch.mjs"):null,o?Q(o,"bin","launch.mjs"):null,r?Q(r,"launch.mjs"):null,r?Q(r,"..","bin","launch.mjs"):null],i)}import{existsSync as K,mkdirSync as Nt,readFileSync as Vn,writeFileSync as Zt}from"node:fs";import{homedir as Xt}from"node:os";import{join as Un}from"node:path";import{tmpdir as qt}from"node:os";function Bt(n,t=9222){let e=Number.parseInt(String(n??""),10);return Number.isInteger(e)&&e>1024&&e<65535?e:t}var Qt=qt().replaceAll("\\","/"),h=Bt(process.env.GREEDY_SEARCH_PORT),c=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Qt}/greedysearch-chrome-profile`).replaceAll("\\","/"),k=`${c}/DevToolsActivePort`,C=process.env.GREEDY_SEARCH_PID_FILE||`${c}/browser.pid`,kt=process.env.CDP_PAGES_CACHE||`${c}/cdp-pages.json`,W=process.env.GREEDY_SEARCH_MODE_FILE||`${c}/browser-mode`,zn=process.env.GREEDY_SEARCH_METADATA_FILE||`${c}/browser-metadata.json`,An=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${c}/browser-launch.lock`,Y=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${c}/browser-last-activity`,ze=(process.env.CDP_SOCKET_DIR||`${c}/cdp-sockets`).replaceAll("\\","/"),Ae=`${c}/visible-recovery.jsonl`,fn=Un(Xt(),".dm"),m=Un(fn,"greedyconfig"),an=["perplexity","google","chatgpt","gemini"],gn="gemini";function Ht(){try{if(K(m)){let n=Vn(m,"utf8"),t=JSON.parse(n);if(Array.isArray(t.engines)&&t.engines.length>0&&t.engines.every((e)=>typeof e==="string")){let e=t.engines.filter((r)=>ln[r]),i=t.engines.filter((r)=>!ln[r]);if(i.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${m}: ${i.join(", ")}
|
|
312
|
+
[greedysearch] Available engines: ${Object.keys(ln).join(", ")}
|
|
313
|
+
`);if(e.length>0)return e;process.stderr.write(`[greedysearch] Warning: no valid engines in ${m}, falling back to defaults: ${an.join(", ")}
|
|
314
|
+
`)}}}catch{}return an}function Vt(){try{if(!K(fn))Nt(fn,{recursive:!0});if(!K(m))Zt(m,JSON.stringify({engines:an,synthesizer:gn},null,2)+`
|
|
315
|
+
`,"utf8")}catch{}}Vt();var Hn=["gemini","chatgpt"];function Ut(){try{if(K(m)){let n=Vn(m,"utf8"),t=JSON.parse(n);if(typeof t.synthesizer==="string"){let e=t.synthesizer.toLowerCase();if(Hn.includes(e))return e;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${m}
|
|
316
|
+
[greedysearch] Available synthesizers: ${Hn.join(", ")}
|
|
317
|
+
[greedysearch] Falling back to default: ${gn}
|
|
318
|
+
`)}}}catch{}return gn}var ln={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"},Me=Ht();var Oe=Ut(),De=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=c;import{execFileSync as Mn,execSync as Ke}from"node:child_process";import{existsSync as G,mkdirSync as zt,readFileSync as X,unlinkSync as J,writeFileSync as N}from"node:fs";import{platform as At}from"node:os";var S=zn,j=An,Mt=15000,L=C,F=W,H=Y;function V(n){if(!Number.isInteger(n)||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function Ot(n){if(!V(n))return null;try{if(At()==="win32")return Mn(_("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return Mn(_("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Dt(n,t,e=h){if(!n)return!1;let i=(u)=>String(u||"").replaceAll("\\","/").toLowerCase(),r=i(n),o=i(t);return r.includes(o)&&r.includes(`--remote-debugging-port=${e}`)&&!r.includes("--type=")}function On(n,t,e=h){return Dt(Ot(n),t,e)}function Tt(n=h){return P(n)}function U(){try{if(G(S)){let n=X(S,"utf8"),t=JSON.parse(n);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((e)=>Number.isInteger(e)&&e>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 n=G(L)?Number.parseInt(X(L,"utf8").trim(),10)||void 0:void 0,t=G(F)?X(F,"utf8").trim()==="visible"?"visible":"headless":"headless",e=G(H)?Number.parseInt(X(H,"utf8").trim(),10)||0:0;return{browserPid:n,debugPort:h,tempDir:c,clientPids:n?[n]:[],sessionMode:t,lastActivity:e,launchedAt:0}}catch{return null}}function R(n){try{N(S,JSON.stringify({browserPid:n.browserPid,debugPort:n.debugPort,tempDir:n.tempDir,clientPids:[...new Set(n.clientPids.filter((t)=>t>0))],sessionMode:n.sessionMode,lastActivity:n.lastActivity,launchedAt:n.launchedAt},null,2),"utf8")}catch{}try{if(n.browserPid)N(L,String(n.browserPid),"utf8")}catch{}try{N(F,n.sessionMode,"utf8")}catch{}try{N(H,String(n.lastActivity),"utf8")}catch{}}function Dn(){try{J(S)}catch{}try{J(L)}catch{}try{J(F)}catch{}try{J(H)}catch{}}function sn(n){if(!n)return n;let t={...n,clientPids:[...new Set([...n.clientPids,process.pid].filter((e)=>V(e)||e===process.pid))]};return R(t),t}function I(n){let t=Date.now();try{if(n)R({...n,lastActivity:t});else N(H,String(t),"utf8")}catch{}}var Fe=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Tn=!1;function Pn(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD)return;if(Tn)return;Tn=!0;let n=U();if(!n)return;if(n.browserPid){if(!V(n.browserPid)){Dn();return}if(!On(n.browserPid,n.tempDir,n.debugPort))Dn();else R({...n,clientPids:n.clientPids.filter((r)=>V(r))})}let t=Tt();if(t&&t!==n.browserPid)if(On(t,c,h))R({browserPid:t,debugPort:h,tempDir:c,clientPids:[t],sessionMode:n.sessionMode,lastActivity:Date.now(),launchedAt:Date.now()});else process.stderr.write(`[greedysearch] Refusing to kill unverified listener ${t} on port ${h}.
|
|
319
|
+
`)}function Kn(){zt(c,{recursive:!0});try{let n=JSON.stringify({pid:process.pid,ts:Date.now()});return N(j,n,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{let t=X(j,"utf8");if(JSON.parse(t).pid===process.pid)J(j)}catch{}}}}catch(n){if(n?.code!=="EEXIST")return{acquired:!1,release:()=>{}}}try{let n=X(j,"utf8"),t=JSON.parse(n),e=Date.now()-(t.ts||0);if(!V(t.pid)||e>Mt){try{J(j)}catch{}try{let r=JSON.stringify({pid:process.pid,ts:Date.now()});return N(j,r,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{J(j)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}var Ct=Qn(import.meta.url),Cn=C,z=Y,Yt=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Gt=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;function St(n,t=h){let e=String(n||"").toLowerCase();if(!e.includes(`--remote-debugging-port=${t}`)||e.includes("--type="))return null;return e.includes("--headless")}function Fn(){try{let n=tn(),t=n?Rn(n):null,e=St(t);if(e!==null){try{E(W,e?"headless":"visible","utf8")}catch{}return e}}catch{}try{if(!Sn(W))return!0;return cn(W,"utf8").trim()==="headless"}catch{return!0}}function Lt(){try{E(z,String(Date.now()),"utf8")}catch{}try{let n=U();if(n)I(n)}catch{}}function Rn(n){try{if(Ln()==="win32")return hn(_("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return hn(_("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Ft(n){let t=String(n||"").replaceAll("\\","/"),e=c.replaceAll("\\","/");return t.includes(`--remote-debugging-port=${h}`)&&t.includes(`--user-data-dir=${e}`)&&!t.includes("--type=")}function tn(){return P(h)}function nn(){let n=tn();return n&&Ft(Rn(n))?n:null}async function Rt(n=1500){let t=nn();if(!t)return process.stderr.write(`[greedysearch] Refusing to close an unverified listener.
|
|
320
|
+
`),!1;try{let i=await new Promise((o,u)=>{let l=pn.get(`http://localhost:${h}/json/version`,(g)=>{let f="";g.on("data",(s)=>f+=s),g.on("end",()=>{try{o(JSON.parse(f))}catch{u(Error("bad JSON"))}})});l.on("error",u),l.setTimeout(1000,()=>{l.destroy(),u(Error("timeout"))})}),r=new globalThis.WebSocket(i.webSocketDebuggerUrl);await new Promise((o)=>{r.onopen=()=>{if(nn()!==t){r.close(),o();return}r.send(JSON.stringify({id:1,method:"Browser.close"})),setTimeout(()=>{r.close(),o()},200)},r.onerror=()=>o(),setTimeout(o,1000)})}catch{}let e=Date.now()+n;while(Date.now()<e){let i=tn();if(!i)return!0;if(i!==t)return!1;await new Promise((r)=>setTimeout(r,150))}return It(t)}function It(n=null){try{let t=nn();if(!t||n&&t!==n)return!1;if(Ln()==="win32")hn(_("taskkill"),["/F","/PID",String(t)],{stdio:"ignore",windowsHide:!0});else process.kill(t,"SIGKILL");return!0}catch{return!1}}async function In(){if(!nn()){if(tn())process.stderr.write(`[greedysearch] Refusing to kill an unverified listener.
|
|
321
|
+
`);return!1}if(!await b(500)){try{$(Cn)}catch{}try{$(z)}catch{}try{$(W)}catch{}return!1}let t=await Rt(1500);try{$(Cn)}catch{}try{$(z)}catch{}try{$(W)}catch{}if(t)process.stderr.write(`[greedysearch] Killed Chrome on port ${h}.
|
|
322
|
+
`);return t}var Yn=In;async function dt(){let t=Fn()?Yt:Gt;if(t<=0)return!1;if(!Sn(z))return Lt(),!1;try{let e=Number.parseInt(cn(z,"utf8").trim(),10);if(!e)return!1;if((Date.now()-e)/60000>=t)return In()}catch{}return!1}function b(n=3000){return new Promise((t)=>{let e=pn.get(`http://localhost:${h}/json/version`,(i)=>{i.resume(),t(i.statusCode===200)});e.on("error",()=>t(!1)),e.setTimeout(n,()=>{e.destroy(),t(!1)})})}async function Gn(n=3000,t=200){let e=Date.now()+n;while(Date.now()<e){if(!await b(300))return!0;await new Promise((i)=>setTimeout(i,t))}return!await b(300)}async function d(){let n=`${k}.lock`,t=`${k}.tmp`,e=5000,i=1000,r=await new Promise((o)=>{let u=Date.now(),l=()=>{try{let g=JSON.stringify({pid:process.pid,ts:Date.now()});E(n,g,{encoding:"utf8",flag:"wx"}),o(!0)}catch(g){if(g?.code!=="EEXIST"){if(Date.now()-u<1000)setTimeout(l,50);else o(!1);return}try{let f=cn(n,"utf8").trim(),s=f.startsWith("{")?JSON.parse(f):{ts:Number(f)},v=Number(s?.ts)||0;if(v>0&&Date.now()-v>5000)try{$(n)}catch{}if(Date.now()-u<1000)setTimeout(l,50);else o(!1)}catch{if(Date.now()-u<1000)setTimeout(l,50);else o(!1)}}};l()});try{let o=await new Promise((g,f)=>{let s=pn.get(`http://localhost:${h}/json/version`,(v)=>{let A="";v.on("data",(M)=>A+=M),v.on("end",()=>g(A))});s.on("error",f),s.setTimeout(3000,()=>{s.destroy(),f(Error("timeout"))})}),{webSocketDebuggerUrl:u}=JSON.parse(o),l=new URL(u).pathname;if(r){E(t,`${h}
|
|
323
|
+
${l}`,"utf8");try{$(k)}catch{}Kt(t,k)}}catch{}finally{if(r)try{$(n)}catch{}}}async function dn(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD&&await b()){await d();try{let o=U();if(o)I(o),sn(o)}catch{}return}Pn();let n=await dt(),t=n?!1:await b();if(!t&&!n)await new Promise((o)=>setTimeout(o,500)),t=await b();let e=!1;if(t){let o=Fn(),u=process.env.GREEDY_SEARCH_VISIBLE==="1";if(!u&&!o)process.stderr.write(`[greedysearch] Visible Chrome detected — switching to headless mode...
|
|
324
|
+
`),await Yn(),await Gn(),e=!0;else if(u&&o)process.stderr.write(`[greedysearch] Headless Chrome detected — switching to visible mode...
|
|
325
|
+
`),await Yn(),await Gn(),e=!0}if(e?!1:await b()){await d();try{let o=U();if(o)I(o),sn(o)}catch{}return}let r=Kn();if(!r.acquired){let o=Date.now()+12000,u=!1;while(Date.now()<o){if(u=await b(500),u)break;await new Promise((l)=>setTimeout(l,250))}if(u){await d();return}}try{if(await b(1000)){await d();return}process.stderr.write(`GreedySearch Chrome not running on port ${h} — auto-launching...
|
|
326
|
+
`);let l=[kn({moduleDir:Ct,entrypoint:process.argv[1],env:process.env})];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")l.push("--headless");await new Promise((g,f)=>{Pt(Xn(),l,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(v)=>v===0?g():f(Error("launch.mjs failed")))})}finally{r.release()}}var Et=`
|
|
328
327
|
(function() {
|
|
329
328
|
// Google consent page (consent.google.com)
|
|
330
329
|
var g = document.querySelector('#L2AGLb, button[jsname="b3VHJd"], .tHlp8d');
|
|
@@ -341,10 +340,10 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
341
340
|
|
|
342
341
|
return null;
|
|
343
342
|
})()
|
|
344
|
-
`;async function
|
|
343
|
+
`;async function wn(n,t){let e=await t(["eval",n,Et]).catch(()=>null);if(e&&e!=="null")await new Promise((i)=>setTimeout(i,1500))}var w={input:'textarea[name="newMessage"]',submitButton:'button[aria-label="Submit search"]',answerContainer:'div[class*="prose"]',paperCard:'a[data-testid="search-result"]',exportButton:'button[aria-label="Export"]'};async function ne(n){return await a(["eval",n,`(() => {
|
|
345
344
|
const url = document.location.href || '';
|
|
346
345
|
return url.indexOf('/sign-up/') !== -1 || url.indexOf('redirect_url=') !== -1;
|
|
347
|
-
})()`]).catch(()=>"false")==="true"}async function
|
|
346
|
+
})()`]).catch(()=>"false")==="true"}async function En(n){try{return JSON.parse(await a(["eval",n,`(() => {
|
|
348
347
|
const url = document.location.href || '';
|
|
349
348
|
const title = document.title || '';
|
|
350
349
|
const text = document.body?.innerText || '';
|
|
@@ -355,14 +354,14 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
355
354
|
text.includes('refresh_request_origin_azp_mismatch') ||
|
|
356
355
|
(text.includes('HTTP ERROR 405') && text.includes('This page isn'));
|
|
357
356
|
return JSON.stringify({ stale, url, title, text: text.slice(0, 500) });
|
|
358
|
-
})()`],5000))}catch{return{stale:!1,url:"",title:"",text:""}}}async function
|
|
359
|
-
const el = document.querySelector('${
|
|
357
|
+
})()`],5000))}catch{return{stale:!1,url:"",title:"",text:""}}}async function te(n){for(let t of["https://consensus.app","https://clerk.consensus.app"])await a(["evalraw",n,"Storage.clearDataForOrigin",JSON.stringify({origin:t,storageTypes:"all"})]).catch((e)=>{console.error(`[consensus] Warning: failed to clear stale auth storage for ${t}: ${e.message}`)})}async function nt(n,t,e){let i=await En(n);if(!i.stale)return!1;if(y(t,"auth-storage-reset",e),console.error(`[consensus] Detected stale Clerk/Consensus auth state (${i.title||i.url}) — clearing per-origin storage and retrying navigation`),t.fallbackUsed="clear-stale-consensus-auth",await te(n),await a(["nav",n,"https://consensus.app/"],20000),await new Promise((o)=>setTimeout(o,900)),(await En(n)).stale)throw t.blockedBy="signin",t.verificationResult="needs-human",Error("Consensus auth session is stale — visible Chrome is open. Please sign in again, then rerun the search.");return!0}async function ee(n,t){await a(["click",n,w.input]),await new Promise((u)=>setTimeout(u,q(200)));let e=async()=>{await en(["type",n,"--stdin"],t),await new Promise((u)=>setTimeout(u,q(300)))},i=async()=>{let u=await a(["eval",n,`JSON.stringify(document.querySelector('${w.input}')?.value || '')`]);try{return JSON.parse(u)}catch{return u}},r=async()=>mn(await i(),t),o=async()=>{await a(["eval",n,`(() => {
|
|
358
|
+
const el = document.querySelector('${w.input}');
|
|
360
359
|
if (!el) return false;
|
|
361
360
|
el.focus();
|
|
362
361
|
el.select();
|
|
363
362
|
document.execCommand('delete');
|
|
364
363
|
return true;
|
|
365
|
-
})()`])};if(await e(),await
|
|
364
|
+
})()`])};if(await e(),await r())return;if(await o(),await e(),!await r())throw Error("Consensus input did not accept text — input verification failed")}async function re(n){let e=await a(["eval",n,`(() => {
|
|
366
365
|
if (window.__pdiInstalled) return 'already';
|
|
367
366
|
window.__pdiInstalled = true;
|
|
368
367
|
const _origOpen = XMLHttpRequest.prototype.open;
|
|
@@ -403,7 +402,7 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
403
402
|
return _origSend.apply(this, arguments);
|
|
404
403
|
};
|
|
405
404
|
return 'installed';
|
|
406
|
-
})()`]);return e==="installed"||e==="already"}async function
|
|
405
|
+
})()`]);return e==="installed"||e==="already"}async function ie(n,t=1e4,e=0){let i=`new Promise((resolve) => {
|
|
407
406
|
const _deadline = Date.now() + ${t};
|
|
408
407
|
const _after = ${e};
|
|
409
408
|
function _check() {
|
|
@@ -425,9 +424,9 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
425
424
|
}
|
|
426
425
|
}
|
|
427
426
|
_check();
|
|
428
|
-
})`,
|
|
427
|
+
})`,r=await a(["eval",n,i],t+5000);try{return JSON.parse(r)}catch{return{ok:!1,reason:"invalid-json"}}}async function oe(n,t=8){if(!await B(n,w.paperCard,20000,500).catch(()=>!1))return console.error("[consensus] Warning: no paper cards appeared within 20s — Load More will be skipped"),0;let i=String.raw`
|
|
429
428
|
new Promise((resolve) => {
|
|
430
|
-
const _paperSel = '${
|
|
429
|
+
const _paperSel = '${w.paperCard}';
|
|
431
430
|
const _maxClicks = ${t};
|
|
432
431
|
function _findLoadMore() {
|
|
433
432
|
const btns = Array.from(document.querySelectorAll('button'));
|
|
@@ -461,9 +460,9 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
461
460
|
}
|
|
462
461
|
_loop();
|
|
463
462
|
})
|
|
464
|
-
`,
|
|
463
|
+
`,r=await a(["eval",n,i],t*5000+5000).catch(()=>null);if(!r)return 0;try{let{clicks:o,cards:u}=JSON.parse(r);return console.error(`[consensus] expandReferences: ${o} click(s), ${u} card(s)`),o}catch{return 0}}async function ue(n,t=1200){let e=String.raw`
|
|
465
464
|
new Promise((resolve) => {
|
|
466
|
-
const _sel = '${
|
|
465
|
+
const _sel = '${w.paperCard}';
|
|
467
466
|
const _deadline = Date.now() + ${t};
|
|
468
467
|
let _last = document.querySelectorAll(_sel).length;
|
|
469
468
|
function _poll() {
|
|
@@ -475,20 +474,20 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
475
474
|
}
|
|
476
475
|
setTimeout(_poll, 300);
|
|
477
476
|
})
|
|
478
|
-
`;await
|
|
479
|
-
const btn = document.querySelector('${
|
|
477
|
+
`;await a(["eval",n,e],t+3000).catch(()=>null)}async function le(n){return await a(["eval",n,`(() => {
|
|
478
|
+
const btn = document.querySelector('${w.exportButton}');
|
|
480
479
|
if (!btn) return 'no-export';
|
|
481
480
|
btn.scrollIntoView({ block: 'center' });
|
|
482
481
|
btn.click();
|
|
483
482
|
return 'opened';
|
|
484
|
-
})()`]),await new Promise((e)=>setTimeout(e,600)),await
|
|
483
|
+
})()`]),await new Promise((e)=>setTimeout(e,600)),await a(["eval",n,`(() => {
|
|
485
484
|
const btn = Array.from(document.querySelectorAll('button'))
|
|
486
485
|
.find(b => /\\.CSV/.test((b.innerText || '').trim()));
|
|
487
486
|
if (!btn) return 'no-csv';
|
|
488
487
|
btn.click();
|
|
489
488
|
return 'clicked';
|
|
490
|
-
})()`])}function
|
|
491
|
-
const cards = Array.from(document.querySelectorAll('${
|
|
489
|
+
})()`])}function fe(n){let t=n?.paperDetailsListByPaperId||{},e=Object.keys(t),i=[];for(let r=0;r<e.length;r++){let o=t[e[r]]||{},u=o.url_slug||"",l=o.paper_id||o.hash_paper_id||e[r],g;if(u)g=`https://consensus.app/papers/${u}/${l}/`;else if(o.provider_url)g=o.provider_url;else if(o.doi)g=`https://doi.org/${o.doi}`;else g=`https://consensus.app/paper/${l}`;let f=[],s=o.badges||{};if(s.study_type==="rct")f.push("RCT");else if(s.study_type==="meta_analysis")f.push("META-ANALYSIS");else if(s.study_type==="systematic_review")f.push("SYSTEMATIC REVIEW");else if(s.study_type)f.push(s.study_type.toUpperCase());if(s.rigorous_journal)f.push("RIGOROUS JOURNAL");if(s.very_rigorous_journal)f.push("VERY RIGOROUS JOURNAL");if(s.highly_cited_paper)f.push("HIGHLY CITED");if(s.large_human_trial)f.push("LARGE HUMAN TRIAL");if(o.is_retracted)f.push("RETRACTED");if(o.open_access_pdf_url)f.push("OPEN ACCESS");i.push({title:o.title||"",url:g,rank:r+1,authors:Array.isArray(o.authors)?o.authors:[],year:o.year||null,journal:o.journal||o.publisher_name||null,doi:o.doi||null,citation_count:o.citation_count||0,snippet:o.abstract_takeaway||"",tags:f})}return i}async function tt(n){let t=`(() => {
|
|
490
|
+
const cards = Array.from(document.querySelectorAll('${w.paperCard}'));
|
|
492
491
|
const sources = [];
|
|
493
492
|
const seen = new Set();
|
|
494
493
|
for (const card of cards) {
|
|
@@ -510,8 +509,8 @@ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}asy
|
|
|
510
509
|
sources.push({ title, url, rank, snippet, tags });
|
|
511
510
|
}
|
|
512
511
|
return JSON.stringify(sources);
|
|
513
|
-
})()`,e=await
|
|
514
|
-
const prose = document.querySelector('${
|
|
512
|
+
})()`,e=await a(["eval",n,t],1e4);try{return JSON.parse(e)}catch{return[]}}async function ae(n){let t=`(() => {
|
|
513
|
+
const prose = document.querySelector('${w.answerContainer}');
|
|
515
514
|
return prose?.innerText?.trim() || '';
|
|
516
|
-
})()`;return await
|
|
517
|
-
`;async function
|
|
515
|
+
})()`;return await a(["eval",n,t],1e4)||""}var ge=`Usage: node extractors/consensus.mjs "<query>" [--tab <prefix>]
|
|
516
|
+
`;async function se(){let n=await Wn(process.argv.slice(2));jn(n,ge);let{query:t,tabPrefix:e,short:i}=xn(n),r=Date.now(),u={engine:"consensus",mode:process.env.GREEDY_SEARCH_VISIBLE==="1"?"visible":"headless",clipboardEmpty:null,fallbackUsed:null,blockedBy:null,verificationResult:null,inputReady:null};try{if(process.env.GREEDY_SEARCH_VISIBLE!=="1"&&process.env.GREEDY_SEARCH_ALWAYS_VISIBLE!=="1")process.env.GREEDY_SEARCH_HEADLESS="1";if(await dn(),!e)await a(["list"]);let l=await $n(e),g=await a(["eval",l,"document.location.href"]).catch(()=>""),f=!1;try{let p=new URL(g).hostname.toLowerCase();f=p==="consensus.app"||p.endsWith(".consensus.app")}catch{}if(!f)y(u,"nav",r),await a(["nav",l,"https://consensus.app/"],20000),await new Promise((p)=>setTimeout(p,600));await nt(l,u,r),await wn(l,a),y(u,"input-wait",r);let s=await B(l,w.input,15000,400);if(u.inputReady=s,!s)if(await nt(l,u,r)){let D=await B(l,w.input,15000,400);if(u.inputReady=D,D)await wn(l,a);else throw Error("Consensus input not found after stale auth recovery — page may not have loaded or is in unexpected state")}else throw Error("Consensus input not found — page may not have loaded or is in unexpected state");if(await new Promise((p)=>setTimeout(p,q(rn.postClick))),y(u,"type-and-submit",r),await ee(l,t),await new Promise((p)=>setTimeout(p,q(rn.postType))),await a(["eval",l,`document.querySelector('${w.submitButton}')?.click()`]),await new Promise((p)=>setTimeout(p,2000)),await ne(l))throw u.blockedBy="signin",Error("Consensus requires sign-in — please sign in or create a free account in the visible browser window. Once signed in, cookies persist for future runs.");y(u,"answer-wait",r),await B(l,w.answerContainer,30000,500),await re(l),y(u,"expand-refs",r);let v=await oe(l,8);if(v===0)console.error("[consensus] Note: 'Load more results' button not present (initial page has all references)");else console.error(`[consensus] Clicked 'Load more results' ${v} time(s) to expand references`);await ue(l,1200),y(u,"csv-click",r);let A=Number(await a(["eval",l,"Date.now()"]).catch(()=>"0")||0),M=await le(l);if(M!=="clicked")console.error(`[consensus] Export → .CSV click did not register (${M}) — falling back to DOM`);y(u,"wait-csv-resp",r);let O=await ie(l,12000,A),Z=[],yn="dom";if(O.ok)Z=fe(O.data),yn="api-intercept",console.error(`[consensus] Captured /api/papers/details/ response with ${O.count} paper(s)`);else console.error(`[consensus] /api/papers/details/ response not captured (${O.reason}) — falling back to DOM cards`);y(u,"extract",r);let vn=await ae(l);if(!vn)throw Error("No answer extracted — Consensus may not have responded");if(Z.length===0)Z=await tt(l);else{let p=await tt(l),D=new Set(Z.map((T)=>T.url));for(let T of p)if(!D.has(T.url))Z.push(T)}let et=await a(["eval",l,"document.location.href"]).catch(()=>"");u.durationMs=Date.now()-r,u.sourcePath=yn,y(u,"done",r),Nn({query:t,url:et,answer:Jn(vn,i),sources:Z,_envelope:on(u)})}catch(l){u.durationMs=Date.now()-r,Zn(l,on(u))}}se();
|