@duckmind/dm-darwin-x64 0.43.8 → 0.49.0
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 +147 -218
- package/extensions/dm-9router-ext/package.json +0 -6
- package/extensions/dm-9router-ext/src/index.js +1 -1
- package/extensions/dm-ask-user/package.json +0 -4
- package/extensions/dm-caveman/LICENSE +21 -0
- package/extensions/dm-caveman/extensions/caveman.js +29 -0
- package/extensions/dm-caveman/package.json +20 -0
- package/extensions/dm-cli-anything/index.js +5 -5
- package/extensions/dm-cli-anything/package.json +0 -7
- package/extensions/dm-cli-anything/skills/cli-anything/SKILL.md +1 -3
- package/extensions/dm-context/package.json +0 -1
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +0 -6
- package/extensions/dm-goal/package.json +0 -8
- package/extensions/dm-grill-me/index.js +2 -2
- package/extensions/dm-grill-me/package.json +0 -7
- package/extensions/dm-image2/package.json +0 -8
- package/extensions/dm-subagents/package.json +0 -11
- package/extensions/dm-tasks/package.json +0 -7
- package/extensions/dm-usage/package.json +0 -7
- package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +1 -8
- package/extensions/greedysearch-dm/bin/gschrome.mjs +3 -3
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +3 -3
- package/extensions/greedysearch-dm/bin/launch.mjs +4 -4
- package/extensions/greedysearch-dm/bin/search.mjs +106 -106
- package/extensions/greedysearch-dm/extractors/consensus.mjs +35 -35
- package/extensions/greedysearch-dm/extractors/gemini.mjs +38 -38
- package/extensions/greedysearch-dm/extractors/logically.mjs +35 -35
- package/extensions/greedysearch-dm/package.json +0 -10
- package/extensions/greedysearch-dm/src/search/chrome.mjs +23 -23
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +35 -35
- package/extensions/greedysearch-dm/src/search/research.mjs +77 -77
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/package.json +1 -1
- package/extensions/dm-9router-ext/README.md +0 -142
- package/extensions/dm-9router-ext/tsconfig.json +0 -17
- package/extensions/dm-ask-user/README.md +0 -226
- package/extensions/dm-cli-anything/README.md +0 -33
- package/extensions/dm-cli-anything/vendor/UPSTREAM.md +0 -14
- package/extensions/dm-context/AGENTS.md +0 -41
- package/extensions/dm-context/README.md +0 -18
- package/extensions/dm-context/tsconfig.json +0 -16
- package/extensions/dm-cua/README.md +0 -24
- package/extensions/dm-fff/README.md +0 -36
- package/extensions/dm-fff/tsconfig.json +0 -13
- package/extensions/dm-goal/CHANGELOG.md +0 -12
- package/extensions/dm-goal/README.md +0 -29
- package/extensions/dm-goal/tsconfig.json +0 -15
- package/extensions/dm-grill-me/DESIGN.md +0 -301
- package/extensions/dm-grill-me/README.md +0 -82
- package/extensions/dm-grill-me/tsconfig.json +0 -17
- package/extensions/dm-image2/README.md +0 -33
- package/extensions/dm-subagents/CHANGELOG.md +0 -1211
- package/extensions/dm-subagents/README.md +0 -29
- package/extensions/dm-subagents/biome.json +0 -26
- package/extensions/dm-subagents/tsconfig.json +0 -18
- package/extensions/dm-tasks/README.md +0 -30
- package/extensions/dm-tasks/biome.json +0 -26
- package/extensions/dm-tasks/tsconfig.json +0 -14
- package/extensions/dm-usage/README.md +0 -29
- package/extensions/greedysearch-dm/README.md +0 -222
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{randomInt as
|
|
3
|
-
`)[0]?.slice(0,8);if(!f)throw Error("No Chrome tabs found. Is Chrome running with --remote-debugging-port=9222?");let u=await
|
|
4
|
-
`)}return i}async function
|
|
2
|
+
import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_process";import{dirname as lf,join as wf}from"node:path";import{fileURLToPath as rf}from"node:url";import{basename as hf}from"node:path";function $f(n=process.env,f=process.execPath){let u=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(u?.trim())return u.trim();let g=hf(f||"").toLowerCase();if(g==="node"||g==="node.exe")return f;return"node"}var Wf=lf(rf(import.meta.url)),Qf=wf(Wf,"..","bin","cdp.mjs");function $(n,f=30000){return E(n,null,f)}function E(n,f=null,u=30000){return new Promise((g,i)=>{let o=of($f(),[Qf,...n],{stdio:[f==null?"ignore":"pipe","pipe","pipe"]});if(f!=null)o.stdin.write(f),o.stdin.end();let w="",l="";o.stdout.on("data",(h)=>w+=h),o.stderr.on("data",(h)=>l+=h);let r=setTimeout(()=>{o.kill(),i(Error(`cdp timeout: ${n[0]}`))},u);o.on("close",(h)=>{if(clearTimeout(r),h===0)g(w.trim());else i(Error(l.trim()||`cdp exit ${h}`))})})}async function bn(n){if(n)return n;let f=(await $(["list"])).split(`
|
|
3
|
+
`)[0]?.slice(0,8);if(!f)throw Error("No Chrome tabs found. Is Chrome running with --remote-debugging-port=9222?");let u=await $(["evalraw",f,"Target.createTarget",'{"url":"about:blank"}']),{targetId:g}=JSON.parse(u);await $(["list"]);let i=g.slice(0,8);try{await Bn(i)}catch(o){process.stderr.write(`[getOrOpenTab] stealth injection failed: ${o.message}
|
|
4
|
+
`)}return i}async function Bn(n){await $(["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(_) {}
|
|
@@ -209,7 +209,7 @@ import{randomInt as of}from"node:crypto";import{spawn as wf}from"node:child_proc
|
|
|
209
209
|
};
|
|
210
210
|
} catch(_) {}
|
|
211
211
|
})();
|
|
212
|
-
`})])}var d={postNav:800,postNavSlow:1200,postClick:300,postType:300,inputPoll:400,copyPoll:600,afterVerify:1500};function
|
|
212
|
+
`})])}var d={postNav:800,postNavSlow:1200,postClick:300,postType:300,inputPoll:400,copyPoll:600,afterVerify:1500};function D(n){let f=n*0.4,u=gf(-Math.floor(f),Math.floor(f)+1);return Math.max(50,Math.round(n+u))}async function z(n,f,u=15000,g=500){let i=String.raw`
|
|
213
213
|
new Promise((resolve) => {
|
|
214
214
|
const _deadline = Date.now() + ${u};
|
|
215
215
|
const _baseInterval = ${g};
|
|
@@ -228,27 +228,27 @@ import{randomInt as of}from"node:crypto";import{spawn as wf}from"node:child_proc
|
|
|
228
228
|
|
|
229
229
|
_poll();
|
|
230
230
|
})
|
|
231
|
-
`;return await
|
|
232
|
-
`)}function
|
|
231
|
+
`;return await $(["eval",n,i],u+5000)==="true"}async function qn(n){let f=n.indexOf("--stdin");if(f===-1)return n;let u=await new Promise((i)=>{let o="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(w)=>o+=w),process.stdin.on("end",()=>i(o.trim()))}),g=[...n];return g[f]=u,g}function _n(n){let f=n.includes("--short"),u=n.filter((l)=>l!=="--short"),g=u.indexOf("--tab"),i=g===-1?null:u[g+1];if(g!==-1)u=u.filter((l,r)=>r!==g&&r!==g+1);let o=u.indexOf("--locale"),w=o===-1?null:u[o+1];if(o!==-1)u=u.filter((l,r)=>r!==o&&r!==o+1);return{query:u.join(" "),tabPrefix:i,short:f,locale:w}}function Nn(n,f){if(!n.length||n[0]==="--help")process.stderr.write(f),process.exit(1)}function Vn(n,f,u=300){if(!f||n.length<=u)return n;let g=n.slice(0,u),i=g.lastIndexOf(" ");return i>0?`${g.slice(0,i)}…`:`${g}…`}function Hn(n){process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
232
|
+
`)}function Z(n,f,u=null){if(!n||typeof n!=="object")return;let g=u?` (+${Date.now()-u}ms)`:"";if(n.lastStage=f,!Array.isArray(n.stages))n.stages=[];n.stages.push({stage:f,at:Date.now()});let i=n.engine||"extractor";console.error(`[${i}] stage: ${f}${g}`)}function nn({engine:n,mode:f="headless",clipboardEmpty:u=null,fallbackUsed:g=null,blockedBy:i=null,verificationResult:o=null,inputReady:w=null,durationMs:l=null,lastStage:r=null,stages:h=null}={}){return{engine:n,mode:f,clipboardEmpty:u,fallbackUsed:g,blockedBy:i,verificationResult:o,inputReady:w,durationMs:l,lastStage:r,stages:h}}function Kn(n,f=null){if(f){let u=JSON.stringify({_envelope:f,error:n.message});process.stdout.write(`${u}
|
|
233
233
|
`)}process.stderr.write(`Error: ${n.message}
|
|
234
|
-
`),process.exit(1)}import{spawn as
|
|
234
|
+
`),process.exit(1)}import{spawn as Rf,execFileSync as In,execSync as Wn}from"node:child_process";import{existsSync as S,readFileSync as s,renameSync as af,unlinkSync as B,writeFileSync as F}from"node:fs";import Qn from"node:http";import{platform as Xn,tmpdir as Lf}from"node:os";import{join as pf}from"node:path";import{basename as Xf}from"node:path";function Un(n=process.env,f=process.execPath){let u=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(u?.trim())return u.trim();let g=Xf(f||"").toLowerCase();if(g==="node"||g==="node.exe")return f;return"node"}import{existsSync as xn}from"node:fs";import{platform as tf}from"node:os";import{join as V}from"node:path";function X(n){let f=tf()==="win32",u=process.env.SystemRoot||"C:\\Windows",g={win32:{powershell:V(u,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:V(u,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:V(u,"System32","netstat.exe"),taskkill:V(u,"System32","taskkill.exe"),tasklist:V(u,"System32","tasklist.exe"),cmd:V(u,"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=f?g.win32:g.unix,o=n.toLowerCase();if(i[o]&&xn(i[o]))return i[o];if(f&&o==="netstat"){let w=V(u,"Sysnative","netstat.exe");if(xn(w))return w}return n}import{existsSync as C,mkdirSync as Zf,readFileSync as kn,writeFileSync as jf}from"node:fs";import{homedir as Jf}from"node:os";import{join as On}from"node:path";import{tmpdir as R}from"node:os";var Q=9222,H=`${R().replaceAll("\\","/")}/greedysearch-chrome-profile`,k=`${H}/DevToolsActivePort`,bf=`${R().replaceAll("\\","/")}/cdp-pages.json`,K=`${R().replaceAll("\\","/")}/greedysearch-chrome-mode`,Ou=`${R().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,un=On(Jf(),".dm"),b=On(un,"greedyconfig"),gn=["perplexity","google","chatgpt"],on="gemini";function Bf(){try{if(C(b)){let n=kn(b,"utf8"),f=JSON.parse(n);if(Array.isArray(f.engines)&&f.engines.length>0&&f.engines.every((u)=>typeof u==="string")){let u=f.engines.filter((i)=>fn[i]),g=f.engines.filter((i)=>!fn[i]);if(g.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${b}: ${g.join(", ")}
|
|
235
235
|
[greedysearch] Available engines: ${Object.keys(fn).join(", ")}
|
|
236
236
|
`);if(u.length>0)return u;process.stderr.write(`[greedysearch] Warning: no valid engines in ${b}, falling back to defaults: ${gn.join(", ")}
|
|
237
|
-
`)}}}catch{}return gn}function
|
|
238
|
-
`,"utf8")}catch{}}
|
|
239
|
-
[greedysearch] Available synthesizers: ${
|
|
237
|
+
`)}}}catch{}return gn}function qf(){try{if(!C(un))Zf(un,{recursive:!0});if(!C(b))jf(b,JSON.stringify({engines:gn,synthesizer:on},null,2)+`
|
|
238
|
+
`,"utf8")}catch{}}qf();var An=["gemini","chatgpt"];function _f(){try{if(C(b)){let n=kn(b,"utf8"),f=JSON.parse(n);if(typeof f.synthesizer==="string"){let u=f.synthesizer.toLowerCase();if(An.includes(u))return u;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${f.synthesizer}" in ${b}
|
|
239
|
+
[greedysearch] Available synthesizers: ${An.join(", ")}
|
|
240
240
|
[greedysearch] Falling back to default: ${on}
|
|
241
|
-
`)}}}catch{}return on}var fn={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"},
|
|
241
|
+
`)}}}catch{}return on}var fn={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"},Mu=Bf();var Du=_f(),zu=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=H;import{existsSync as vu,mkdirSync as Nf,readFileSync as Dn,renameSync as Vf,unlinkSync as Hf,writeFileSync as zn}from"node:fs";import Kf from"node:http";import{platform as yn}from"node:os";import{dirname as Uf}from"node:path";var Yn=[9222,9223],xf=/^(0|false|no|off)$/i;function Af(n){return[...new Set(n.filter(Boolean))]}function Mn(n,f="explicit"){let u=new URL(n),g=u.protocol==="wss:"?"wss:":"ws:",i=u.port?Number.parseInt(u.port,10):g==="wss:"?443:80;return{source:f,wsUrl:`${g}//${u.host}${u.pathname}${u.search}`,host:u.hostname,port:i,path:`${u.pathname}${u.search}`,httpUrl:`http://${u.hostname}:${i}`}}function vn(n=process.env){return![n.GREEDY_SEARCH_REUSE_EXISTING_BROWSER,n.DM_CUA_REUSE_EXISTING_BROWSER].some((f)=>f!==void 0&&xf.test(String(f)))}function ln(n){let f=Number.parseInt(String(n??""),10);return Number.isInteger(f)&&f>0&&f<65536?f:null}function kf(n){if(!n)return null;let f=String(n).trim();if(!f)return null;let u=new URL(f.includes("://")?f:`http://${f}`),g=ln(u.port)||(u.protocol==="https:"?443:80);return{host:u.hostname,port:g,source:`env:${f}`}}function Of(n){if(!n)return[];return String(n).split(/[,\s]+/).map(ln).filter(Boolean)}function Mf({env:n=process.env,platformName:f=yn(),procVersionText:u=null}={}){if(f!=="linux")return!1;if(n.WSL_DISTRO_NAME||n.WSL_INTEROP)return!0;let g=u??(()=>{try{return Dn("/proc/version","utf8")}catch{return""}})();return/microsoft|wsl/i.test(g)}function Df({env:n=process.env,platformName:f=yn(),procVersionText:u=null,resolvConfText:g=null}={}){let i=["localhost","127.0.0.1"];if(Mf({env:n,platformName:f,procVersionText:u})){let w=(g??(()=>{try{return Dn("/etc/resolv.conf","utf8")}catch{return""}})()).match(/^\s*nameserver\s+([^\s#]+)/m);if(w)i.push(w[1]);i.push("host.docker.internal")}return Af(i)}function zf({env:n=process.env,hosts:f=Df({env:n}),autoPorts:u=Yn,excludePorts:g=[]}={}){let i=[];for(let r of["GREEDY_SEARCH_CDP_WS_URL","DM_CUA_CDP_WS_URL","CDP_WS_URL"])if(n[r])i.push({wsUrl:n[r],source:`env:${r}`});for(let r of["GREEDY_SEARCH_CDP_URL","DM_CUA_CDP_URL","CDP_URL"])try{let h=kf(n[r]);if(h)i.push(h)}catch{}for(let r of["GREEDY_SEARCH_EXISTING_CDP_PORT","DM_CUA_EXISTING_CDP_PORT","GREEDY_SEARCH_CDP_PORT","DM_CUA_CDP_PORT"]){let h=ln(n[r]);if(!h)continue;for(let W of f)i.push({host:W,port:h,source:`env:${r}`})}let o=Of(n.GREEDY_SEARCH_EXISTING_CDP_PORTS);for(let r of o)for(let h of f)i.push({host:h,port:r,source:"env:GREEDY_SEARCH_EXISTING_CDP_PORTS"});let w=new Set(g.filter(Boolean));if(vn(n))for(let r of u){if(w.has(r))continue;for(let h of f)i.push({host:h,port:r,source:"auto"})}let l=new Set;return i.filter((r)=>{let h=r.wsUrl||`${r.host}:${r.port}`;if(l.has(h))return!1;return l.add(h),!0})}async function yf(n,{timeoutMs:f=700}={}){if(n.wsUrl)return Mn(n.wsUrl,n.source);let u=n.host||"localhost",g=n.port;if(!g)return null;let i=await new Promise((o)=>{let w=Kf.get({host:u,port:g,path:"/json/version",timeout:f},(l)=>{let r="";l.setEncoding("utf8"),l.on("data",(h)=>r+=h),l.on("end",()=>o(l.statusCode===200?r:null))});w.on("error",()=>o(null)),w.setTimeout(f,()=>{w.destroy(),o(null)})});if(!i)return null;try{let o=JSON.parse(i);if(!o.webSocketDebuggerUrl)return null;let w=Mn(o.webSocketDebuggerUrl,n.source),l=w.path||new URL(o.webSocketDebuggerUrl).pathname;return{...w,host:u,port:g,httpUrl:`http://${u}:${g}`,wsUrl:`ws://${u}:${g}${l}`,path:l}}catch{return null}}async function Yf(n={}){for(let f of zf(n)){let u=await yf(f,n);if(u)return u}return null}function vf(n){if(!n)throw Error("missing CDP endpoint");let f=new URL(n.wsUrl);return`${f.host}
|
|
242
242
|
${f.pathname}${f.search}
|
|
243
|
-
`}function
|
|
244
|
-
`)[0],10):null}catch{return null}}function cn(n){try{if(
|
|
245
|
-
`)[0],10):null}catch{return null}}async function
|
|
246
|
-
`);return f}var
|
|
247
|
-
${
|
|
248
|
-
`);return}
|
|
249
|
-
`),await
|
|
250
|
-
`),await
|
|
251
|
-
`);let
|
|
243
|
+
`}function Gf(n,f){Nf(Uf(n),{recursive:!0});let u=`${n}.tmp-${process.pid}`;zn(u,vf(f),"utf8");try{Hf(n)}catch{}Vf(u,n)}async function Gn({activePortFile:n,modeFile:f,env:u=process.env,excludePorts:g=[],autoPorts:i=Yn}={}){if(!vn(u))return null;let o=await Yf({env:u,excludePorts:g,autoPorts:i});if(!o)return null;if(Gf(n,o),f)zn(f,"existing","utf8");return o}import{execFileSync as Tn,execSync as wn}from"node:child_process";import{existsSync as a,mkdirSync as Tf,readFileSync as O,unlinkSync as x,writeFileSync as A}from"node:fs";import{platform as rn,tmpdir as Rn}from"node:os";var v=Rn().replaceAll("\\","/"),L=`${v}/greedysearch-chrome-metadata.json`,U=`${v}/greedysearch-chrome-launch.lock`,Pf=15000,p=`${v}/greedysearch-chrome.pid`,I=`${v}/greedysearch-chrome-mode`,y=`${v}/greedysearch-chrome-last-activity`;function Y(n){if(!Number.isInteger(n)||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function cf(n){if(!Y(n))return null;try{if(rn()==="win32")return Tn(X("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return Tn(X("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function mf(n,f,u=Q){if(!n)return!1;let g=(w)=>String(w||"").replaceAll("\\","/").toLowerCase(),i=g(n),o=g(f);return i.includes(o)&&i.includes(`--remote-debugging-port=${u}`)&&!i.includes("--type=")}function Pn(n,f,u=Q){return mf(cf(n),f,u)}function Cf(n=Q){try{if(rn()==="win32"){let u=wn(`${X("netstat")} -ano -p TCP 2>nul`,{encoding:"utf8"}),g=new RegExp(String.raw`TCP\s+\S+:${n}\s+\S+:0\s+LISTENING\s+(\d+)`,"i"),i=u.match(g);return i?Number.parseInt(i[1],10):null}let f=wn(`${X("lsof")} -i :${n} -t 2>/dev/null || ${X("ss")} -tlnp 2>/dev/null | ${X("grep")} :${n} | ${X("grep")} -oP 'pid=\\K\\d+'`,{encoding:"utf8"}).trim();return f?Number.parseInt(f.split(`
|
|
244
|
+
`)[0],10):null}catch{return null}}function cn(n){try{if(rn()==="win32")wn(`${X("taskkill")} /F /T /PID ${n}`,{stdio:"ignore"});else{try{process.kill(-n,"SIGKILL")}catch{}try{process.kill(n,"SIGKILL")}catch{}}return!0}catch{return!1}}function G(){try{if(a(L)){let n=O(L,"utf8"),f=JSON.parse(n);if(f&&typeof f.tempDir==="string"&&typeof f.debugPort==="number")return{browserPid:Number.isInteger(f.browserPid)?f.browserPid:void 0,debugPort:f.debugPort,tempDir:f.tempDir,clientPids:Array.isArray(f.clientPids)?f.clientPids.filter((u)=>Number.isInteger(u)&&u>0):[],sessionMode:f.sessionMode==="visible"?"visible":"headless",lastActivity:Number.isFinite(f.lastActivity)?f.lastActivity:0,launchedAt:Number.isFinite(f.launchedAt)?f.launchedAt:0}}}catch{}try{let n=a(p)?Number.parseInt(O(p,"utf8").trim(),10)||void 0:void 0,f=a(I)?O(I,"utf8").trim()==="visible"?"visible":"headless":"headless",u=a(y)?Number.parseInt(O(y,"utf8").trim(),10)||0:0;return{browserPid:n,debugPort:Q,tempDir:H,clientPids:n?[n]:[],sessionMode:f,lastActivity:u,launchedAt:0}}catch{return null}}function e(n){try{A(L,JSON.stringify({browserPid:n.browserPid,debugPort:n.debugPort,tempDir:n.tempDir,clientPids:[...new Set(n.clientPids.filter((f)=>f>0))],sessionMode:n.sessionMode,lastActivity:n.lastActivity,launchedAt:n.launchedAt},null,2),"utf8")}catch{}try{if(n.browserPid)A(p,String(n.browserPid),"utf8")}catch{}try{A(I,n.sessionMode,"utf8")}catch{}try{A(y,String(n.lastActivity),"utf8")}catch{}}function mn(){try{x(L)}catch{}try{x(p)}catch{}try{x(I)}catch{}try{x(y)}catch{}}function an(n){if(!n)return n;let f={...n,clientPids:[...new Set([...n.clientPids,process.pid].filter((u)=>Y(u)||u===process.pid))]};return e(f),f}function hn(n){let f=Date.now();try{if(n)e({...n,lastActivity:f});else A(y,String(f),"utf8")}catch{}}var pu=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var Cn=!1;function Ln(){if(Cn)return;Cn=!0;let n=G();if(!n)return;if(n.browserPid){if(!Y(n.browserPid)){cn(n.browserPid),mn();return}if(!Pn(n.browserPid,n.tempDir,n.debugPort))mn();else e({...n,clientPids:n.clientPids.filter((i)=>Y(i))})}let f=Cf();if(f&&f!==n.browserPid)if(Pn(f,H,Q))e({browserPid:f,debugPort:Q,tempDir:H,clientPids:[f],sessionMode:n.sessionMode,lastActivity:Date.now(),launchedAt:Date.now()});else cn(f)}function pn(){Tf(Rn(),{recursive:!0});try{let n=JSON.stringify({pid:process.pid,ts:Date.now()});return A(U,n,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{let f=O(U,"utf8");if(JSON.parse(f).pid===process.pid)x(U)}catch{}}}}catch(n){if(n?.code!=="EEXIST")return{acquired:!1,release:()=>{}}}try{let n=O(U,"utf8"),f=JSON.parse(n),u=Date.now()-(f.ts||0);if(!Y(f.pid)||u>Pf){try{x(U)}catch{}try{let i=JSON.stringify({pid:process.pid,ts:Date.now()});return A(U,i,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{x(U)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}var If=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Fn=Lf().replaceAll("\\","/"),T=`${Fn}/greedysearch-chrome.pid`,P=`${Fn}/greedysearch-chrome-last-activity`,ef=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Ff=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;function Sf(n,f=Q){let u=String(n||"").toLowerCase();if(!u.includes(`--remote-debugging-port=${f}`)||u.includes("--type="))return null;return u.includes("--headless")}function Sn(){try{let n=tn(),f=n?Ef(n):null,u=Sf(f);if(u!==null){try{F(K,u?"headless":"visible","utf8")}catch{}return u}}catch{}try{if(!S(K))return!0;return s(K,"utf8").trim()==="headless"}catch{return!0}}function sf(){try{F(P,String(Date.now()),"utf8")}catch{}try{let n=G();if(n)hn(n)}catch{}}function Ef(n){try{if(Xn()==="win32")return In(X("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return In(X("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function tn(){try{if(Xn()==="win32"){let f=Wn(`${X("netstat")} -ano -p TCP 2>nul`,{encoding:"utf8"}),u=new RegExp(String.raw`TCP\s+\S+:${Q}\s+\S+:0\s+LISTENING\s+(\d+)`,"i"),g=f.match(u);return g?Number.parseInt(g[1],10):null}let n=Wn(`${X("lsof")} -i :${Q} -t 2>/dev/null || ${X("ss")} -tlnp 2>/dev/null | ${X("grep")} :${Q} | ${X("grep")} -oP 'pid=\\K\\d+'`,{encoding:"utf8"}).trim();return n?Number.parseInt(n.split(`
|
|
245
|
+
`)[0],10):null}catch{return null}}async function df(n=1500){try{let u=await new Promise((i,o)=>{let w=Qn.get(`http://localhost:${Q}/json/version`,(l)=>{let r="";l.on("data",(h)=>r+=h),l.on("end",()=>{try{i(JSON.parse(r))}catch{o(Error("bad JSON"))}})});w.on("error",o),w.setTimeout(1000,()=>{w.destroy(),o(Error("timeout"))})}),g=new globalThis.WebSocket(u.webSocketDebuggerUrl);await new Promise((i)=>{g.onopen=()=>{g.send(JSON.stringify({id:1,method:"Browser.close"})),setTimeout(()=>{g.close(),i()},200)},g.onerror=()=>i(),setTimeout(i,1000)})}catch{}let f=Date.now()+n;while(Date.now()<f){if(!tn())return!0;await new Promise((g)=>setTimeout(g,150))}return nu()}function nu(){try{let n=tn();if(!n&&S(T))n=Number.parseInt(s(T,"utf8").trim(),10)||null;if(!n)return!1;if(Xn()==="win32")Wn(`${X("taskkill")} /F /PID ${n}`,{stdio:"ignore"});else process.kill(n,"SIGKILL");return!0}catch{return!1}}async function sn(){if(!await M(500)){try{B(T)}catch{}try{B(P)}catch{}try{B(K)}catch{}return!1}let f=await df(1500);try{B(T)}catch{}try{B(P)}catch{}try{B(K)}catch{}if(f)process.stderr.write(`[greedysearch] Killed Chrome on port ${Q}.
|
|
246
|
+
`);return f}var en=sn;async function fu(){let f=Sn()?ef:Ff;if(f<=0)return!1;if(!S(P))return sf(),!1;try{let u=Number.parseInt(s(P,"utf8").trim(),10);if(!u)return!1;if((Date.now()-u)/60000>=f)return sn()}catch{}return!1}function M(n=3000){return new Promise((f)=>{let u=Qn.get(`http://localhost:${Q}/json/version`,(g)=>{g.resume(),f(g.statusCode===200)});u.on("error",()=>f(!1)),u.setTimeout(n,()=>{u.destroy(),f(!1)})})}async function $n(){let n=`${k}.lock`,f=`${k}.tmp`,u=5000,g=1000,i=await new Promise((o)=>{let w=Date.now(),l=()=>{try{let r=JSON.stringify({pid:process.pid,ts:Date.now()});F(n,r,{encoding:"utf8",flag:"wx"}),o(!0)}catch(r){if(r?.code!=="EEXIST"){if(Date.now()-w<1000)setTimeout(l,50);else o(!1);return}try{let h=s(n,"utf8").trim(),W=h.startsWith("{")?JSON.parse(h):{ts:Number(h)},j=Number(W?.ts)||0;if(j>0&&Date.now()-j>5000)try{B(n)}catch{}if(Date.now()-w<1000)setTimeout(l,50);else o(!1)}catch{if(Date.now()-w<1000)setTimeout(l,50);else o(!1)}}};l()});try{let o=await new Promise((h,W)=>{let j=Qn.get(`http://localhost:${Q}/json/version`,(_)=>{let N="";_.on("data",(q)=>N+=q),_.on("end",()=>h(N))});j.on("error",W),j.setTimeout(3000,()=>{j.destroy(),W(Error("timeout"))})}),{webSocketDebuggerUrl:w}=JSON.parse(o),l=new URL(w),r=`${l.pathname}${l.search}`;if(i){F(f,`localhost:${Q}
|
|
247
|
+
${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}async function En(){let n=S(T)||!!G(),f=await Gn({activePortFile:k,modeFile:K,excludePorts:n?[Q]:[]});if(f){process.stderr.write(`[greedysearch] Reusing existing browser CDP endpoint ${f.httpUrl} (${f.source}).
|
|
248
|
+
`);return}Ln();let u=await fu(),g=u?!1:await M();if(!g&&!u)await new Promise((l)=>setTimeout(l,500)),g=await M();let i=!1;if(g){let l=Sn(),r=process.env.GREEDY_SEARCH_VISIBLE==="1";if(!r&&!l)process.stderr.write(`[greedysearch] Visible Chrome detected — switching to headless mode...
|
|
249
|
+
`),await en(),await new Promise((h)=>setTimeout(h,1000)),i=!0;else if(r&&l)process.stderr.write(`[greedysearch] Headless Chrome detected — switching to visible mode...
|
|
250
|
+
`),await en(),await new Promise((h)=>setTimeout(h,1000)),i=!0}if(i?!1:await M()){await $n();try{let l=G();if(l)hn(l),an(l)}catch{}return}let w=pn();if(!w.acquired){if(await new Promise((r)=>setTimeout(r,3000)),await M(5000)){await $n();return}}try{if(await M(1000)){await $n();return}process.stderr.write(`GreedySearch Chrome not running on port ${Q} — auto-launching...
|
|
251
|
+
`);let r=[pf(If,"..","..","bin","launch.mjs")];if(process.env.GREEDY_SEARCH_VISIBLE!=="1")r.push("--headless");await new Promise((h,W)=>{Rf(Un(),r,{stdio:["ignore",process.stderr,process.stderr]}).on("close",(_)=>_===0?h():W(Error("launch.mjs failed")))})}finally{w.release()}}var uu=`
|
|
252
252
|
(function() {
|
|
253
253
|
// Google consent page (consent.google.com)
|
|
254
254
|
var g = document.querySelector('#L2AGLb, button[jsname="b3VHJd"], .tHlp8d');
|
|
@@ -265,10 +265,10 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
265
265
|
|
|
266
266
|
return null;
|
|
267
267
|
})()
|
|
268
|
-
`;async function
|
|
268
|
+
`;async function Zn(n,f){let u=await f(["eval",n,uu]).catch(()=>null);if(u&&u!=="null")await new Promise((g)=>setTimeout(g,1500))}var J={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 gu(n){return await $(["eval",n,`(() => {
|
|
269
269
|
const url = document.location.href || '';
|
|
270
270
|
return url.indexOf('/sign-up/') !== -1 || url.indexOf('redirect_url=') !== -1;
|
|
271
|
-
})()`]).catch(()=>"false")==="true"}async function
|
|
271
|
+
})()`]).catch(()=>"false")==="true"}async function dn(n){try{return JSON.parse(await $(["eval",n,`(() => {
|
|
272
272
|
const url = document.location.href || '';
|
|
273
273
|
const title = document.title || '';
|
|
274
274
|
const text = document.body?.innerText || '';
|
|
@@ -279,7 +279,7 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
279
279
|
text.includes('refresh_request_origin_azp_mismatch') ||
|
|
280
280
|
(text.includes('HTTP ERROR 405') && text.includes('This page isn'));
|
|
281
281
|
return JSON.stringify({ stale, url, title, text: text.slice(0, 500) });
|
|
282
|
-
})()`],5000))}catch{return{stale:!1,url:"",title:"",text:""}}}async function
|
|
282
|
+
})()`],5000))}catch{return{stale:!1,url:"",title:"",text:""}}}async function iu(n){for(let f of["https://consensus.app","https://clerk.consensus.app"])await $(["evalraw",n,"Storage.clearDataForOrigin",JSON.stringify({origin:f,storageTypes:"all"})]).catch((u)=>{console.error(`[consensus] Warning: failed to clear stale auth storage for ${f}: ${u.message}`)})}async function nf(n,f,u){let g=await dn(n);if(!g.stale)return!1;if(Z(f,"auth-storage-reset",u),console.error(`[consensus] Detected stale Clerk/Consensus auth state (${g.title||g.url}) — clearing per-origin storage and retrying navigation`),f.fallbackUsed="clear-stale-consensus-auth",await iu(n),await $(["nav",n,"https://consensus.app/"],20000),await new Promise((o)=>setTimeout(o,900)),(await dn(n)).stale)throw f.blockedBy="signin",f.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 ou(n,f){if(await $(["click",n,J.input]),await new Promise((g)=>setTimeout(g,D(200))),await E(["type",n,"--stdin"],f),await new Promise((g)=>setTimeout(g,D(300))),await $(["eval",n,`(document.querySelector('${J.input}')?.value || '').length >= ${Math.floor(f.length*0.8)}`])!=="true")throw Error("Consensus input did not accept text — input verification failed")}async function lu(n){let u=await $(["eval",n,`(() => {
|
|
283
283
|
if (window.__pdiInstalled) return 'already';
|
|
284
284
|
window.__pdiInstalled = true;
|
|
285
285
|
const _origOpen = XMLHttpRequest.prototype.open;
|
|
@@ -312,7 +312,7 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
312
312
|
return _origSend.apply(this, arguments);
|
|
313
313
|
};
|
|
314
314
|
return 'installed';
|
|
315
|
-
})()`]);return u==="installed"||u==="already"}async function
|
|
315
|
+
})()`]);return u==="installed"||u==="already"}async function wu(n,f=1e4){let u=`new Promise((resolve) => {
|
|
316
316
|
const _deadline = Date.now() + ${f};
|
|
317
317
|
function _check() {
|
|
318
318
|
const resps = window.__papersDetailsResps || [];
|
|
@@ -328,13 +328,13 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
_check();
|
|
331
|
-
})`,g=await
|
|
331
|
+
})`,g=await $(["eval",n,u],f+5000);return JSON.parse(g)}async function ru(n,f=8){if(!await z(n,J.paperCard,20000,500).catch(()=>!1))return console.error("[consensus] Warning: no paper cards appeared within 20s — Load More will be skipped"),0;await new Promise((i)=>setTimeout(i,800));let g=0;for(let i=0;i<f;i++){if(await $(["eval",n,`(() => {
|
|
332
332
|
const btns = Array.from(document.querySelectorAll('button'));
|
|
333
333
|
return btns.some(b => {
|
|
334
334
|
const t = (b.innerText || '').trim();
|
|
335
335
|
return /load more/i.test(t) || /more results/i.test(t) || /show more/i.test(t);
|
|
336
336
|
});
|
|
337
|
-
})()`])!=="true")break;await
|
|
337
|
+
})()`])!=="true")break;await $(["eval",n,`(() => {
|
|
338
338
|
const btns = Array.from(document.querySelectorAll('button'));
|
|
339
339
|
const btn = btns.find(b => {
|
|
340
340
|
const t = (b.innerText || '').trim();
|
|
@@ -342,20 +342,20 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
342
342
|
});
|
|
343
343
|
btn?.click();
|
|
344
344
|
return 'clicked';
|
|
345
|
-
})()`]),g++,await new Promise((
|
|
346
|
-
const btn = document.querySelector('${
|
|
345
|
+
})()`]),g++,await new Promise((w)=>setTimeout(w,1500))}return g}async function hu(n){return await $(["eval",n,`(() => {
|
|
346
|
+
const btn = document.querySelector('${J.exportButton}');
|
|
347
347
|
if (!btn) return 'no-export';
|
|
348
348
|
btn.scrollIntoView({ block: 'center' });
|
|
349
349
|
btn.click();
|
|
350
350
|
return 'opened';
|
|
351
|
-
})()`]),await new Promise((u)=>setTimeout(u,600)),await
|
|
351
|
+
})()`]),await new Promise((u)=>setTimeout(u,600)),await $(["eval",n,`(() => {
|
|
352
352
|
const btn = Array.from(document.querySelectorAll('button'))
|
|
353
353
|
.find(b => /\\.CSV/.test((b.innerText || '').trim()));
|
|
354
354
|
if (!btn) return 'no-csv';
|
|
355
355
|
btn.click();
|
|
356
356
|
return 'clicked';
|
|
357
|
-
})()`])}function
|
|
358
|
-
const cards = Array.from(document.querySelectorAll('${
|
|
357
|
+
})()`])}function $u(n){let f=n?.paperDetailsListByPaperId||{},u=Object.keys(f),g=[];for(let i=0;i<u.length;i++){let o=f[u[i]]||{},w=o.url_slug||"",l=o.paper_id||o.hash_paper_id||u[i],r;if(w)r=`https://consensus.app/papers/${w}/${l}/`;else if(o.provider_url)r=o.provider_url;else if(o.doi)r=`https://doi.org/${o.doi}`;else r=`https://consensus.app/paper/${l}`;let h=[],W=o.badges||{};if(W.study_type==="rct")h.push("RCT");else if(W.study_type==="meta_analysis")h.push("META-ANALYSIS");else if(W.study_type==="systematic_review")h.push("SYSTEMATIC REVIEW");else if(W.study_type)h.push(W.study_type.toUpperCase());if(W.rigorous_journal)h.push("RIGOROUS JOURNAL");if(W.very_rigorous_journal)h.push("VERY RIGOROUS JOURNAL");if(W.highly_cited_paper)h.push("HIGHLY CITED");if(W.large_human_trial)h.push("LARGE HUMAN TRIAL");if(o.is_retracted)h.push("RETRACTED");if(o.open_access_pdf_url)h.push("OPEN ACCESS");g.push({title:o.title||"",url:r,rank:i+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:h})}return g}async function ff(n){let f=`(() => {
|
|
358
|
+
const cards = Array.from(document.querySelectorAll('${J.paperCard}'));
|
|
359
359
|
const sources = [];
|
|
360
360
|
const seen = new Set();
|
|
361
361
|
for (const card of cards) {
|
|
@@ -377,8 +377,8 @@ ${l}`,"utf8");try{q(k)}catch{}Lf(f,k)}}catch{}finally{if(i)try{q(n)}catch{}}}asy
|
|
|
377
377
|
sources.push({ title, url, rank, snippet, tags });
|
|
378
378
|
}
|
|
379
379
|
return JSON.stringify(sources);
|
|
380
|
-
})()`,u=await
|
|
381
|
-
const prose = document.querySelector('${
|
|
380
|
+
})()`,u=await $(["eval",n,f],1e4);return JSON.parse(u)}async function Wu(n){let f=`(() => {
|
|
381
|
+
const prose = document.querySelector('${J.answerContainer}');
|
|
382
382
|
return prose?.innerText?.trim() || '';
|
|
383
|
-
})()`;return await
|
|
384
|
-
`;async function
|
|
383
|
+
})()`;return await $(["eval",n,f],1e4)||""}var Qu=`Usage: node extractors/consensus.mjs "<query>" [--tab <prefix>]
|
|
384
|
+
`;async function Xu(){let n=await qn(process.argv.slice(2));Nn(n,Qu);let{query:f,tabPrefix:u,short:g}=_n(n),i=Date.now(),w={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 En(),!u)await $(["list"]);let l=await bn(u),r=await $(["eval",l,"document.location.href"]).catch(()=>""),h=!1;try{let t=new URL(r).hostname.toLowerCase();h=t==="consensus.app"||t.endsWith(".consensus.app")}catch{}if(!h)Z(w,"nav",i),await $(["nav",l,"https://consensus.app/"],20000),await new Promise((t)=>setTimeout(t,600));await nf(l,w,i),await Zn(l,$),Z(w,"input-wait",i);let W=await z(l,J.input,15000,400);if(w.inputReady=W,!W)if(await nf(l,w,i)){let c=await z(l,J.input,15000,400);if(w.inputReady=c,c)await Zn(l,$);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((t)=>setTimeout(t,D(d.postClick))),Z(w,"type-and-submit",i),await ou(l,f),await new Promise((t)=>setTimeout(t,D(d.postType))),await $(["eval",l,`document.querySelector('${J.submitButton}')?.click()`]),await new Promise((t)=>setTimeout(t,2000)),await gu(l))throw w.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.");Z(w,"answer-wait",i),await z(l,J.answerContainer,30000,500),await lu(l),Z(w,"expand-refs",i);let j=await ru(l,8);if(j===0)console.error("[consensus] Note: 'Load more results' button not present (initial page has all references)");else console.error(`[consensus] Clicked 'Load more results' ${j} time(s) to expand references`);await new Promise((t)=>setTimeout(t,1500)),Z(w,"csv-click",i);let _=await hu(l);if(_!=="clicked")console.error(`[consensus] Export → .CSV click did not register (${_}) — falling back to DOM`);Z(w,"wait-csv-resp",i);let N=await wu(l,12000),q=[],jn="dom";if(N.ok)q=$u(N.data),jn="api-intercept",console.error(`[consensus] Captured /api/papers/details/ response with ${N.count} paper(s)`);else console.error(`[consensus] /api/papers/details/ response not captured (${N.reason}) — falling back to DOM cards`);Z(w,"extract",i);let Jn=await Wu(l);if(!Jn)throw Error("No answer extracted — Consensus may not have responded");if(q.length===0)q=await ff(l);else{let t=await ff(l),c=new Set(q.map((m)=>m.url));for(let m of t)if(!c.has(m.url))q.push(m)}let uf=await $(["eval",l,"document.location.href"]).catch(()=>"");w.durationMs=Date.now()-i,w.sourcePath=jn,Z(w,"done",i),Hn({query:f,url:uf,answer:Vn(Jn,g),sources:q,_envelope:nn(w)})}catch(l){w.durationMs=Date.now()-i,Kn(l,nn(w))}}Xu();
|