@duckmind/dm-darwin-arm64 0.52.3 → 0.53.1

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.
Files changed (56) hide show
  1. package/dm +0 -0
  2. package/extensions/.dm-extensions.json +15 -8
  3. package/extensions/dm-cua/bin/browser-cua.mjs +6 -6
  4. package/extensions/dm-cua/index.js +5 -5
  5. package/extensions/dm-cua/src/browser-cua-lib.mjs +2 -2
  6. package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +8 -1
  7. package/extensions/greedysearch-dm/bin/cdp-headless.mjs +1 -1
  8. package/extensions/greedysearch-dm/bin/cdp-visible.mjs +1 -1
  9. package/extensions/greedysearch-dm/bin/cdp.mjs +29 -20
  10. package/extensions/greedysearch-dm/bin/gschrome.mjs +1 -10
  11. package/extensions/greedysearch-dm/bin/kill-visible.mjs +1 -1
  12. package/extensions/greedysearch-dm/bin/launch-visible.mjs +1 -4
  13. package/extensions/greedysearch-dm/bin/launch.mjs +9 -5
  14. package/extensions/greedysearch-dm/bin/mcp.mjs +375 -0
  15. package/extensions/greedysearch-dm/bin/search.mjs +310 -156
  16. package/extensions/greedysearch-dm/bin/visible.mjs +1 -1
  17. package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +205 -68
  18. package/extensions/greedysearch-dm/extractors/chatgpt.mjs +229 -140
  19. package/extensions/greedysearch-dm/extractors/common.mjs +160 -50
  20. package/extensions/greedysearch-dm/extractors/consensus.mjs +225 -92
  21. package/extensions/greedysearch-dm/extractors/consent.mjs +44 -17
  22. package/extensions/greedysearch-dm/extractors/gemini.mjs +275 -136
  23. package/extensions/greedysearch-dm/extractors/google-ai.mjs +172 -64
  24. package/extensions/greedysearch-dm/extractors/logically.mjs +183 -69
  25. package/extensions/greedysearch-dm/extractors/perplexity.mjs +331 -65
  26. package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +118 -41
  27. package/extensions/greedysearch-dm/index.js +20 -17
  28. package/extensions/greedysearch-dm/package.json +8 -3
  29. package/extensions/greedysearch-dm/skills/greedy-search/skill.md +8 -8
  30. package/extensions/greedysearch-dm/src/fetcher.mjs +2 -2
  31. package/extensions/greedysearch-dm/src/formatters/results.js +8 -6
  32. package/extensions/greedysearch-dm/src/github.mjs +7 -7
  33. package/extensions/greedysearch-dm/src/reddit.mjs +1 -1
  34. package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +10 -9
  35. package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +48 -0
  36. package/extensions/greedysearch-dm/src/search/chrome.mjs +129 -53
  37. package/extensions/greedysearch-dm/src/search/constants.mjs +8 -8
  38. package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
  39. package/extensions/greedysearch-dm/src/search/fetch-source.mjs +154 -77
  40. package/extensions/greedysearch-dm/src/search/minimize.mjs +1 -0
  41. package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
  42. package/extensions/greedysearch-dm/src/search/pdf.mjs +1 -1
  43. package/extensions/greedysearch-dm/src/search/port-pid.mjs +1 -0
  44. package/extensions/greedysearch-dm/src/search/progress.mjs +2 -0
  45. package/extensions/greedysearch-dm/src/search/recovery.mjs +1 -1
  46. package/extensions/greedysearch-dm/src/search/research.mjs +262 -167
  47. package/extensions/greedysearch-dm/src/search/scale-aware.mjs +11 -0
  48. package/extensions/greedysearch-dm/src/search/simple-research.mjs +827 -0
  49. package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +11 -11
  50. package/extensions/greedysearch-dm/src/search/synthesis.mjs +11 -11
  51. package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +23 -20
  52. package/extensions/greedysearch-dm/src/tools/shared.js +10 -9
  53. package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +1 -1
  54. package/package.json +1 -1
  55. package/extensions/greedysearch-dm/src/search/cdp-endpoint.mjs +0 -3
  56. package/extensions/greedysearch-dm/src/utils/browser-executable.mjs +0 -1
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
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:`
2
+ import{randomInt as tt}from"node:crypto";import{spawn as et}from"node:child_process";import{basename as it}from"node:path";import{dirname as ot,join as ut}from"node:path";import{fileURLToPath as lt}from"node:url";function rt(n=process.env,t=process.execPath){let e=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(e?.trim())return e.trim();let o=it(t||"").toLowerCase();if(o==="node"||o==="node.exe")return t;return"node"}var ft=ot(lt(import.meta.url)),at=ut(ft,"..","bin","cdp.mjs"),gt=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function ht(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)=>yn(t,e));if(!gt.has(n[0]))throw Error(`cdp: unknown subcommand '${n[0]}'`);return n.map((t,e)=>yn(t,e))}function yn(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 f(n,t=30000){return nn(n,null,t)}function nn(n,t=null,e=30000){let o=ht(n);return new Promise((i,r)=>{let u=et(rt(),[at,...o],{stdio:[t==null?"ignore":"pipe","pipe","pipe"]});if(t!=null)u.stdin.write(t),u.stdin.end();let l="",a="";u.stdout.on("data",(h)=>l+=h),u.stderr.on("data",(h)=>a+=h);let g=setTimeout(()=>{u.kill(),r(Error(`cdp timeout: ${n[0]}`))},e);u.on("close",(h)=>{if(clearTimeout(g),h===0)i(l.trim());else r(Error(a.trim()||`cdp exit ${h}`))})})}function _n(n,t){let e=(u)=>String(u??"").replace(/\s+/g," ").trim(),o=e(n),i=e(t);if(!i)return!1;if(o.length<Math.ceil(i.length*0.8))return!1;let r=Math.min(40,i.length);return o.includes(i.slice(0,r))&&o.includes(i.slice(-r))}async function vn(n){if(n)return n;let t=(await f(["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 f(["evalraw",t,"Target.createTarget",'{"url":"about:blank"}']),o;try{o=JSON.parse(e)}catch(u){throw Error(`Target.createTarget returned invalid JSON: ${u.message}`)}let{targetId:i}=o;if(!i)throw Error("Target.createTarget did not return a targetId");await f(["list"]);let r=i.slice(0,8);try{await $n(r)}catch(u){process.stderr.write(`[getOrOpenTab] stealth injection failed: ${u.message}
4
+ `)}return r}async function $n(n){await f(["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(_) {}
@@ -12,40 +12,62 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
12
12
  try { delete window._phantom; } catch(_) {}
13
13
  try { delete window.Buffer; } catch(_) {}
14
14
 
15
- // Real Chrome without automation does not expose a useful webdriver value.
16
- // A literal false value is itself a common stealth tell; prefer undefined and
17
- // make the descriptor configurable like native browser properties.
18
- Object.defineProperty(navigator, 'webdriver', { get: () => undefined, configurable: true });
15
+ // Real Chrome without automation should not expose navigator.webdriver at all.
16
+ // A literal false or an own-property getter returning undefined is itself a
17
+ // common stealth tell; remove both instance and prototype properties when the
18
+ // descriptor is configurable (as it is with --disable-blink-features).
19
+ try { delete navigator.webdriver; } catch(_) {}
20
+ try { delete Navigator.prototype.webdriver; } catch(_) {}
19
21
  Object.defineProperty(navigator, 'vendor', { get: () => 'Google Inc.', configurable: true });
20
22
  Object.defineProperty(navigator, 'platform', { get: () => 'Win32', configurable: true });
21
23
  Object.defineProperty(navigator, 'maxTouchPoints', { get: () => 0, configurable: true });
22
24
  Object.defineProperty(navigator, 'pdfViewerEnabled', { get: () => true, configurable: true });
25
+ Object.defineProperty(navigator, 'productSub', { get: () => '20030107', configurable: true });
26
+ Object.defineProperty(navigator, 'product', { get: () => 'Gecko', configurable: true });
27
+ var __greedyMimeTypes = null;
28
+ function __makeMimeTypes() {
29
+ var pdf = { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
30
+ var textPdf = { type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
31
+ try { Object.setPrototypeOf(pdf, MimeType.prototype); } catch(_) {}
32
+ try { Object.setPrototypeOf(textPdf, MimeType.prototype); } catch(_) {}
33
+ var m = [pdf, textPdf];
34
+ try { Object.setPrototypeOf(m, MimeTypeArray.prototype); } catch(_) {}
35
+ m.item = function item(i) { return this[i] || null; };
36
+ m.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.type === name; }) || null; };
37
+ return m;
38
+ }
23
39
  Object.defineProperty(navigator, 'plugins', {
24
40
  get: () => {
25
- var p = [
26
- { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
27
- { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' },
28
- { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' },
29
- ];
30
- p.length = 3;
41
+ __greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
42
+ var plugin0 = { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' };
43
+ var plugin1 = { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' };
44
+ var plugin2 = { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' };
45
+ try { Object.setPrototypeOf(plugin0, Plugin.prototype); } catch(_) {}
46
+ try { Object.setPrototypeOf(plugin1, Plugin.prototype); } catch(_) {}
47
+ try { Object.setPrototypeOf(plugin2, Plugin.prototype); } catch(_) {}
48
+ var p = [plugin0, plugin1, plugin2];
49
+ p.item = function item(i) { return this[i] || null; };
50
+ p.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.name === name; }) || null; };
51
+ p.refresh = function refresh() {};
52
+ try { Object.setPrototypeOf(p, PluginArray.prototype); } catch(_) {}
53
+ try {
54
+ __greedyMimeTypes[0].enabledPlugin = p[0];
55
+ __greedyMimeTypes[1].enabledPlugin = p[0];
56
+ } catch(_) {}
31
57
  return p;
32
58
  },
59
+ configurable: true,
33
60
  });
34
61
  Object.defineProperty(navigator, 'mimeTypes', {
35
62
  get: () => {
36
- var m = [
37
- { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null },
38
- { type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null },
39
- ];
40
- m.item = function(i) { return m[i] || null; };
41
- m.namedItem = function(name) { return m.find(function(x) { return x.type === name; }) || null; };
42
- return m;
63
+ __greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
64
+ return __greedyMimeTypes;
43
65
  },
44
66
  configurable: true,
45
67
  });
46
68
  Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'], configurable: true });
47
69
  try {
48
- Object.defineProperty(navigator, 'connection', { get: () => ({ effectiveType: '4g', rtt: 50, downlink: 10, saveData: false }), configurable: true });
70
+ Object.defineProperty(navigator, 'connection', { get: () => ({ effectiveType: '4g', rtt: 50, downlink: 10, downlinkMax: Infinity, saveData: false }), configurable: true });
49
71
  } catch(_) {}
50
72
  if (!navigator.mediaDevices) {
51
73
  Object.defineProperty(navigator, 'mediaDevices', {
@@ -61,6 +83,18 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
61
83
  configurable: true,
62
84
  });
63
85
  }
86
+ // ── Missing platform APIs (headless often lacks these) ─
87
+ try {
88
+ if (!navigator.share) {
89
+ navigator.share = function() { return Promise.reject(new Error('NotAllowedError')); };
90
+ }
91
+ } catch(_) {}
92
+ try {
93
+ if (!navigator.contentIndex) {
94
+ Object.defineProperty(navigator, 'contentIndex', { get: () => ({ add: function() {}, delete: function() {}, getAll: function() { return Promise.resolve([]); } }), configurable: true });
95
+ }
96
+ } catch(_) {}
97
+
64
98
  if (!window.chrome) {
65
99
  window.chrome = {
66
100
  app: { isInstalled: false, InstallState: {}, RunningState: {} },
@@ -68,8 +102,8 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
68
102
  OnInstalledReason: {}, OnRestartRequiredReason: {}, PlatformArch: {}, PlatformNaclArch: {}, PlatformOs: {}, RequestUpdateCheckStatus: {},
69
103
  connect: () => ({}), sendMessage: () => {}, onMessage: { addListener: () => {} }
70
104
  },
71
- loadTimes: () => ({}),
72
- csi: () => ({}),
105
+ loadTimes: function() { return { requestTime: 0, startLoadTime: Date.now() - 5000, commitLoadTime: Date.now() - 3000, finishDocumentLoadTime: Date.now() - 2000, finishLoadTime: Date.now() - 1000, firstPaintTime: Date.now() - 800, navigationType: 'Other', wasFetchedViaSpdy: true, wasNpnNegotiated: true, npnNegotiatedProtocol: 'h2', wasAlternateProtocolAvailable: false, connectionInfo: 'http/2' }; },
106
+ csi: function() { var t = Date.now(); return { onloadT: t - 2000, startE: t - 5000, pageT: 'back', tran: 2 }; },
73
107
  };
74
108
  }
75
109
  var __greedyNativeFns = [];
@@ -90,6 +124,19 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
90
124
  return getParam.call(this, p);
91
125
  });
92
126
  } catch(_) {}
127
+ // ── WebGL readPixels noise ──────────────────────────
128
+ // CreepJS and other fingerprinters draw content with WebGL and read back the
129
+ // rendered pixels. Adding subtle noise breaks rendering-based fingerprinting.
130
+ try {
131
+ var origReadPixels = WebGLRenderingContext.prototype.readPixels;
132
+ WebGLRenderingContext.prototype.readPixels = __markNative(function readPixels(x, y, width, height, format, type, pixels) {
133
+ var result = origReadPixels.call(this, x, y, width, height, format, type, pixels);
134
+ if (pixels && pixels.length > 0) {
135
+ pixels[0] ^= 1;
136
+ }
137
+ return result;
138
+ });
139
+ } catch(_) {}
93
140
  Object.defineProperty(navigator, 'hardwareConcurrency', { get: () => 8, configurable: true });
94
141
  Object.defineProperty(navigator, 'deviceMemory', { get: () => 8, configurable: true });
95
142
 
@@ -97,7 +144,7 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
97
144
  // Headless rendering engines produce slightly different canvas output
98
145
  // than headed Chrome. Subtle noise breaks hash-based fingerprinting.
99
146
  try {
100
- var __canvasNoise = ((Date.now() % 997) + Math.floor(Math.random() * 997)) & 1;
147
+ var __canvasNoise = ((Date.now() & 0xFF) | 1);
101
148
  var origFill = CanvasRenderingContext2D.prototype.fillText;
102
149
  CanvasRenderingContext2D.prototype.fillText = __markNative(function fillText() {
103
150
  this.globalAlpha = 0.9995;
@@ -116,15 +163,39 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
116
163
  HTMLCanvasElement.prototype.toDataURL = __markNative(function toDataURL() {
117
164
  var ctx = this.getContext('2d');
118
165
  if (ctx) {
119
- // Add 1px noise pixel in corner (invisible but changes hash)
120
- var imgData = ctx.getImageData(0, 0, 1, 1);
121
- if (imgData) imgData.data[0] ^= __canvasNoise;
122
- ctx.putImageData(imgData, 0, 0);
166
+ // Spread noise across canvas to break hash-based fingerprinting.
167
+ // Uses a deterministic pattern so it's consistent per page load
168
+ // but varies between sessions.
169
+ var w = this.width, h = this.height;
170
+ if (w > 0 && h > 0) {
171
+ var imgData = ctx.getImageData(0, 0, Math.min(w, 4), Math.min(h, 4));
172
+ if (imgData && imgData.data) {
173
+ for (var __i = 0; __i < imgData.data.length; __i += 4) {
174
+ imgData.data[__i] ^= (__canvasNoise + __i) & 0xFF;
175
+ }
176
+ ctx.putImageData(imgData, 0, 0);
177
+ }
178
+ }
123
179
  }
124
180
  return origToDataURL.apply(this, arguments);
125
181
  });
126
182
  } catch(_) {}
127
183
 
184
+ // ── AudioContext fingerprint noise ────────────────────
185
+ // Headless Chrome's AudioContext produces slightly different output.
186
+ // Subtle noise breaks audio-based fingerprinting.
187
+ try {
188
+ var __audioSeed = ((Date.now() & 0x1F) | 1);
189
+ var origGetChannelData = AudioBuffer.prototype.getChannelData;
190
+ AudioBuffer.prototype.getChannelData = __markNative(function getChannelData(channel) {
191
+ var data = origGetChannelData.call(this, channel);
192
+ for (var __i = 0; __i < data.length; __i += 64) {
193
+ data[__i] *= 0.99999;
194
+ }
195
+ return data;
196
+ });
197
+ } catch(_) {}
198
+
128
199
  // ── window outer dimensions ──────────────────────────
129
200
  // outerWidth/Height = 0 in headless — a well-known bot signal.
130
201
  // Mirror innerWidth/Height (set by --window-size flag) so the ratio is sane.
@@ -134,9 +205,15 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
134
205
  } catch(_) {}
135
206
 
136
207
  // ── screen properties ─────────────────────────────────
208
+ // Headless Chrome often reports an 800x600 screen even when the viewport is
209
+ // 1920x1080. Keep screen metrics internally consistent with our launch flags.
137
210
  try {
138
- if (!screen.colorDepth) Object.defineProperty(screen, 'colorDepth', { get: () => 24, configurable: true });
139
- if (!screen.pixelDepth) Object.defineProperty(screen, 'pixelDepth', { get: () => 24, configurable: true });
211
+ Object.defineProperty(screen, 'width', { get: () => 1920, configurable: true });
212
+ Object.defineProperty(screen, 'height', { get: () => 1080, configurable: true });
213
+ Object.defineProperty(screen, 'availWidth', { get: () => 1920, configurable: true });
214
+ Object.defineProperty(screen, 'availHeight', { get: () => 1040, configurable: true });
215
+ Object.defineProperty(screen, 'colorDepth', { get: () => 24, configurable: true });
216
+ Object.defineProperty(screen, 'pixelDepth', { get: () => 24, configurable: true });
140
217
  } catch(_) {}
141
218
 
142
219
  // ── navigator.userAgentData (UA Client Hints) ─────────
@@ -209,10 +286,10 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
209
286
  };
210
287
  } catch(_) {}
211
288
  })();
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`
289
+ `})])}var tn={postNav:800,postNavSlow:1200,postClick:300,postType:300,inputPoll:400,copyPoll:600,afterVerify:1500};function q(n){let t=n*0.2,e=tt(-Math.floor(t),Math.floor(t)+1);return Math.max(50,Math.round(n+e))}async function B(n,t,e=15000,o=500){let i=String.raw`
213
290
  new Promise((resolve) => {
214
- const _deadline = Date.now() + ${u};
215
- const _baseInterval = ${g};
291
+ const _deadline = Date.now() + ${e};
292
+ const _baseInterval = ${o};
216
293
 
217
294
  function _jitter(ms) {
218
295
  return Math.max(50, ms + (Math.random() * ms * 0.4 - ms * 0.2));
@@ -220,7 +297,7 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
220
297
 
221
298
  function _poll() {
222
299
  try {
223
- if (document.querySelector('${f}')) { resolve(true); return; }
300
+ if (document.querySelector('${t}')) { resolve(true); return; }
224
301
  if (Date.now() < _deadline) { setTimeout(_poll, _jitter(_baseInterval)); }
225
302
  else { resolve(false); }
226
303
  } catch(_) { resolve(false); }
@@ -228,27 +305,26 @@ import{randomInt as gf}from"node:crypto";import{spawn as of}from"node:child_proc
228
305
 
229
306
  _poll();
230
307
  })
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}
308
+ `;return await f(["eval",n,i],e+5000)==="true"}async function bn(n){let t=n.indexOf("--stdin");if(t===-1)return n;let e=await new Promise((i)=>{let r="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(u)=>r+=u),process.stdin.on("end",()=>i(r.trim()))}),o=[...n];return o[t]=e,o}function mn(n){let t=n.includes("--short"),e=n.filter((l)=>l!=="--short"),o=e.indexOf("--tab"),i=o===-1?null:e[o+1];if(o!==-1)e=e.filter((l,a)=>a!==o&&a!==o+1);let r=e.indexOf("--locale"),u=r===-1?null:e[r+1];if(r!==-1)e=e.filter((l,a)=>a!==r&&a!==r+1);return{query:e.join(" "),tabPrefix:i,short:t,locale:u}}function Wn(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 o=n.slice(0,e),i=o.lastIndexOf(" ");return i>0?`${o.slice(0,i)}…`:`${o}…`}function Jn(n){process.stdout.write(`${JSON.stringify(n,null,2)}
309
+ `)}function _(n,t,e=null){if(!n||typeof n!=="object")return;let o=e?` (+${Date.now()-e}ms)`:"";if(n.lastStage=t,!Array.isArray(n.stages))n.stages=[];n.stages.push({stage:t,at:Date.now()});let i=n.engine||"extractor";console.error(`[${i}] stage: ${t}${o}`)}function en({engine:n,mode:t="headless",clipboardEmpty:e=null,fallbackUsed:o=null,blockedBy:i=null,verificationResult:r=null,inputReady:u=null,durationMs:l=null,lastStage:a=null,stages:g=null}={}){return{engine:n,mode:t,clipboardEmpty:e,fallbackUsed:o,blockedBy:i,verificationResult:r,inputReady:u,durationMs:l,lastStage:a,stages:g}}function xn(n,t=null){if(t){let e=JSON.stringify({_envelope:t,error:n.message});process.stdout.write(`${e}
233
310
  `)}process.stderr.write(`Error: ${n.message}
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
- [greedysearch] Available engines: ${Object.keys(fn).join(", ")}
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 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
- [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"},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
- ${f.pathname}${f.search}
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=`
311
+ `),process.exit(1)}import{spawn as Ut,execFileSync as gn,execSync as Te}from"node:child_process";import{basename as st}from"node:path";function Nn(n=process.env,t=process.execPath){let e=n.GREEDY_SEARCH_NODE||n.NODE_BINARY||n.NODE;if(e?.trim())return e.trim();let o=st(t||"").toLowerCase();if(o==="node"||o==="node.exe")return t;return"node"}import{existsSync as Cn,readFileSync as hn,renameSync as Mt,unlinkSync as $,writeFileSync as I}from"node:fs";import sn from"node:http";import{platform as Gn}from"node:os";import{join as At}from"node:path";import{existsSync as Zn}from"node:fs";import{platform as ct}from"node:os";import{join as j}from"node:path";function w(n){let t=ct()==="win32",e=process.env.SystemRoot||"C:\\Windows",o={win32:{powershell:j(e,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:j(e,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:j(e,"System32","netstat.exe"),taskkill:j(e,"System32","taskkill.exe"),tasklist:j(e,"System32","tasklist.exe"),cmd:j(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"}},i=t?o.win32:o.unix,r=n.toLowerCase();if(i[r]&&Zn(i[r]))return i[r];if(t&&r==="netstat"){let u=j(e,"Sysnative","netstat.exe");if(Zn(u))return u}return n}import{execFileSync as wt}from"node:child_process";import{platform as pt}from"node:os";function yt(n,t){return wt(w(n),t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000})}function _t(n){let t=String(n||"").match(/\b(\d+)\b/);return t?Number.parseInt(t[1],10):null}function vt(n){return _t(n)}function $t(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((r)=>r.endsWith(`:${t}`)))continue;let i=e.match(/\bpid=(\d+)\b/);if(i)return Number.parseInt(i[1],10)}return null}function bt(n,t){for(let e of String(n||"").split(/\r?\n/)){let o=e.trim().split(/\s+/);if(o.length<5||o[0].toUpperCase()!=="TCP")continue;if(!o.at(-2)?.toUpperCase().startsWith("LISTEN"))continue;if(!o[1].endsWith(`:${t}`))continue;let i=Number.parseInt(o.at(-1),10);if(Number.isInteger(i)&&i>0)return i}return null}function rn(n,t,e){try{return n(t,e)}catch{return null}}function Xn(n,{platformName:t=pt(),run:e=yt}={}){if(t==="win32")return bt(rn(e,"netstat",["-ano","-p","TCP"]),n);let o=rn(e,"lsof",["-nP",`-iTCP:${n}`,"-sTCP:LISTEN","-t"]),i=vt(o);if(i)return i;if(t!=="linux")return null;return $t(rn(e,"ss",["-ltnp"]),n)}import{existsSync as T,mkdirSync as mt,readFileSync as Bn,writeFileSync as Wt}from"node:fs";import{homedir as jt}from"node:os";import{join as Qn}from"node:path";import{tmpdir as Jt}from"node:os";function xt(n,t=9222){let e=Number.parseInt(String(n??""),10);return Number.isInteger(e)&&e>1024&&e<65535?e:t}var Nt=Jt().replaceAll("\\","/"),s=xt(process.env.GREEDY_SEARCH_PORT),c=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${Nt}/greedysearch-chrome-profile`).replaceAll("\\","/"),Q=`${c}/DevToolsActivePort`,P=process.env.GREEDY_SEARCH_PID_FILE||`${c}/browser.pid`,Zt=process.env.CDP_PAGES_CACHE||`${c}/cdp-pages.json`,W=process.env.GREEDY_SEARCH_MODE_FILE||`${c}/browser-mode`,kn=process.env.GREEDY_SEARCH_METADATA_FILE||`${c}/browser-metadata.json`,Vn=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${c}/browser-launch.lock`,K=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${c}/browser-last-activity`,Ze=(process.env.CDP_SOCKET_DIR||`${c}/cdp-sockets`).replaceAll("\\","/"),Xe=`${c}/visible-recovery.jsonl`,un=Qn(jt(),".dm"),v=Qn(un,"greedyconfig"),ln=["perplexity","google","chatgpt","gemini"],fn="gemini";function Xt(){try{if(T(v)){let n=Bn(v,"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((i)=>on[i]),o=t.engines.filter((i)=>!on[i]);if(o.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${v}: ${o.join(", ")}
312
+ [greedysearch] Available engines: ${Object.keys(on).join(", ")}
313
+ `);if(e.length>0)return e;process.stderr.write(`[greedysearch] Warning: no valid engines in ${v}, falling back to defaults: ${ln.join(", ")}
314
+ `)}}}catch{}return ln}function qt(){try{if(!T(un))mt(un,{recursive:!0});if(!T(v))Wt(v,JSON.stringify({engines:ln,synthesizer:fn},null,2)+`
315
+ `,"utf8")}catch{}}qt();var qn=["gemini","chatgpt"];function Bt(){try{if(T(v)){let n=Bn(v,"utf8"),t=JSON.parse(n);if(typeof t.synthesizer==="string"){let e=t.synthesizer.toLowerCase();if(qn.includes(e))return e;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${t.synthesizer}" in ${v}
316
+ [greedysearch] Available synthesizers: ${qn.join(", ")}
317
+ [greedysearch] Falling back to default: ${fn}
318
+ `)}}}catch{}return fn}var on={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"},qe=Xt();var Be=Bt(),Qe=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=c;import{execFileSync as Hn,execSync as zn}from"node:child_process";import{existsSync as Y,mkdirSync as Qt,readFileSync as X,unlinkSync as x,writeFileSync as N}from"node:fs";import{platform as On}from"node:os";var C=kn,J=Vn,kt=15000,G=P,S=W,k=K;function V(n){if(!Number.isInteger(n)||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function Vt(n){if(!V(n))return null;try{if(On()==="win32")return Hn(w("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return Hn(w("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Ht(n,t,e=s){if(!n)return!1;let o=(u)=>String(u||"").replaceAll("\\","/").toLowerCase(),i=o(n),r=o(t);return i.includes(r)&&i.includes(`--remote-debugging-port=${e}`)&&!i.includes("--type=")}function Un(n,t,e=s){return Ht(Vt(n),t,e)}function zt(n=s){try{if(On()==="win32"){let e=zn(`${w("netstat")} -ano -p TCP 2>nul`,{encoding:"utf8"}),o=new RegExp(String.raw`TCP\s+\S+:${n}\s+\S+:0\s+LISTENING\s+(\d+)`,"i"),i=e.match(o);return i?Number.parseInt(i[1],10):null}let t=zn(`${w("lsof")} -i :${n} -t 2>/dev/null || ${w("ss")} -tlnp 2>/dev/null | ${w("grep")} :${n} | ${w("grep")} -oP 'pid=\\K\\d+'`,{encoding:"utf8"}).trim();return t?Number.parseInt(t.split(`
319
+ `)[0],10):null}catch{return null}}function H(){try{if(Y(C)){let n=X(C,"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=Y(G)?Number.parseInt(X(G,"utf8").trim(),10)||void 0:void 0,t=Y(S)?X(S,"utf8").trim()==="visible"?"visible":"headless":"headless",e=Y(k)?Number.parseInt(X(k,"utf8").trim(),10)||0:0;return{browserPid:n,debugPort:s,tempDir:c,clientPids:n?[n]:[],sessionMode:t,lastActivity:e,launchedAt:0}}catch{return null}}function L(n){try{N(C,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(G,String(n.browserPid),"utf8")}catch{}try{N(S,n.sessionMode,"utf8")}catch{}try{N(k,String(n.lastActivity),"utf8")}catch{}}function Mn(){try{x(C)}catch{}try{x(G)}catch{}try{x(S)}catch{}try{x(k)}catch{}}function an(n){if(!n)return n;let t={...n,clientPids:[...new Set([...n.clientPids,process.pid].filter((e)=>V(e)||e===process.pid))]};return L(t),t}function F(n){let t=Date.now();try{if(n)L({...n,lastActivity:t});else N(k,String(t),"utf8")}catch{}}var Ae=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;var An=!1;function Dn(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD)return;if(An)return;An=!0;let n=H();if(!n)return;if(n.browserPid){if(!V(n.browserPid)){Mn();return}if(!Un(n.browserPid,n.tempDir,n.debugPort))Mn();else L({...n,clientPids:n.clientPids.filter((i)=>V(i))})}let t=zt();if(t&&t!==n.browserPid)if(Un(t,c,s))L({browserPid:t,debugPort:s,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 ${s}.
320
+ `)}function Tn(){Qt(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)x(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>kt){try{x(J)}catch{}try{let i=JSON.stringify({pid:process.pid,ts:Date.now()});return N(J,i,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{x(J)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}var Ot=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Pn=P,z=K,Dt=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,Tt=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60;function Pt(n,t=s){let e=String(n||"").toLowerCase();if(!e.includes(`--remote-debugging-port=${t}`)||e.includes("--type="))return null;return e.includes("--headless")}function Sn(){try{let n=E(),t=n?Ln(n):null,e=Pt(t);if(e!==null){try{I(W,e?"headless":"visible","utf8")}catch{}return e}}catch{}try{if(!Cn(W))return!0;return hn(W,"utf8").trim()==="headless"}catch{return!0}}function Kt(){try{I(z,String(Date.now()),"utf8")}catch{}try{let n=H();if(n)F(n)}catch{}}function Ln(n){try{if(Gn()==="win32")return gn(w("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${n}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return gn(w("ps"),["-p",String(n),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Yt(n){let t=String(n||"").replaceAll("\\","/"),e=c.replaceAll("\\","/");return t.includes(`--remote-debugging-port=${s}`)&&t.includes(`--user-data-dir=${e}`)&&!t.includes("--type=")}function E(){return Xn(s)}function d(){let n=E();return n&&Yt(Ln(n))?n:null}async function Ct(n=1500){let t=d();if(!t)return process.stderr.write(`[greedysearch] Refusing to close an unverified listener.
321
+ `),!1;try{let o=await new Promise((r,u)=>{let l=sn.get(`http://localhost:${s}/json/version`,(a)=>{let g="";a.on("data",(h)=>g+=h),a.on("end",()=>{try{r(JSON.parse(g))}catch{u(Error("bad JSON"))}})});l.on("error",u),l.setTimeout(1000,()=>{l.destroy(),u(Error("timeout"))})}),i=new globalThis.WebSocket(o.webSocketDebuggerUrl);await new Promise((r)=>{i.onopen=()=>{if(d()!==t){i.close(),r();return}i.send(JSON.stringify({id:1,method:"Browser.close"})),setTimeout(()=>{i.close(),r()},200)},i.onerror=()=>r(),setTimeout(r,1000)})}catch{}let e=Date.now()+n;while(Date.now()<e){let o=E();if(!o)return!0;if(o!==t)return!1;await new Promise((i)=>setTimeout(i,150))}return Gt(t)}function Gt(n=null){try{let t=d();if(!t||n&&t!==n)return!1;if(Gn()==="win32")gn(w("taskkill"),["/F","/PID",String(t)],{stdio:"ignore",windowsHide:!0});else process.kill(t,"SIGKILL");return!0}catch{return!1}}async function Fn(){if(!d()){if(E())process.stderr.write(`[greedysearch] Refusing to kill an unverified listener.
322
+ `);return!1}if(!await b(500)){try{$(Pn)}catch{}try{$(z)}catch{}try{$(W)}catch{}return!1}let t=await Ct(1500);try{$(Pn)}catch{}try{$(z)}catch{}try{$(W)}catch{}if(t)process.stderr.write(`[greedysearch] Killed Chrome on port ${s}.
323
+ `);return t}var Kn=Fn;async function St(){let t=Sn()?Dt:Tt;if(t<=0)return!1;if(!Cn(z))return Kt(),!1;try{let e=Number.parseInt(hn(z,"utf8").trim(),10);if(!e)return!1;if((Date.now()-e)/60000>=t)return Fn()}catch{}return!1}function b(n=3000){return new Promise((t)=>{let e=sn.get(`http://localhost:${s}/json/version`,(o)=>{o.resume(),t(o.statusCode===200)});e.on("error",()=>t(!1)),e.setTimeout(n,()=>{e.destroy(),t(!1)})})}async function Yn(n=3000,t=200){let e=Date.now()+n;while(Date.now()<e){if(!await b(300))return!0;await new Promise((o)=>setTimeout(o,t))}return!await b(300)}async function R(){let n=`${Q}.lock`,t=`${Q}.tmp`,e=5000,o=1000,i=await new Promise((r)=>{let u=Date.now(),l=()=>{try{let a=JSON.stringify({pid:process.pid,ts:Date.now()});I(n,a,{encoding:"utf8",flag:"wx"}),r(!0)}catch(a){if(a?.code!=="EEXIST"){if(Date.now()-u<1000)setTimeout(l,50);else r(!1);return}try{let g=hn(n,"utf8").trim(),h=g.startsWith("{")?JSON.parse(g):{ts:Number(g)},m=Number(h?.ts)||0;if(m>0&&Date.now()-m>5000)try{$(n)}catch{}if(Date.now()-u<1000)setTimeout(l,50);else r(!1)}catch{if(Date.now()-u<1000)setTimeout(l,50);else r(!1)}}};l()});try{let r=await new Promise((a,g)=>{let h=sn.get(`http://localhost:${s}/json/version`,(m)=>{let U="";m.on("data",(M)=>U+=M),m.on("end",()=>a(U))});h.on("error",g),h.setTimeout(3000,()=>{h.destroy(),g(Error("timeout"))})}),{webSocketDebuggerUrl:u}=JSON.parse(r),l=new URL(u).pathname;if(i){I(t,`${s}
324
+ ${l}`,"utf8");try{$(Q)}catch{}Mt(t,Q)}}catch{}finally{if(i)try{$(n)}catch{}}}async function Rn(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD&&await b()){await R();try{let r=H();if(r)F(r),an(r)}catch{}return}Dn();let n=await St(),t=n?!1:await b();if(!t&&!n)await new Promise((r)=>setTimeout(r,500)),t=await b();let e=!1;if(t){let r=Sn(),u=process.env.GREEDY_SEARCH_VISIBLE==="1";if(!u&&!r)process.stderr.write(`[greedysearch] Visible Chrome detected switching to headless mode...
325
+ `),await Kn(),await Yn(),e=!0;else if(u&&r)process.stderr.write(`[greedysearch] Headless Chrome detected — switching to visible mode...
326
+ `),await Kn(),await Yn(),e=!0}if(e?!1:await b()){await R();try{let r=H();if(r)F(r),an(r)}catch{}return}let i=Tn();if(!i.acquired){let r=Date.now()+12000,u=!1;while(Date.now()<r){if(u=await b(500),u)break;await new Promise((l)=>setTimeout(l,250))}if(u){await R();return}}try{if(await b(1000)){await R();return}process.stderr.write(`GreedySearch Chrome not running on port ${s} — auto-launching...
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=`
252
328
  (function() {
253
329
  // Google consent page (consent.google.com)
254
330
  var g = document.querySelector('#L2AGLb, button[jsname="b3VHJd"], .tHlp8d');
@@ -265,10 +341,10 @@ ${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}asy
265
341
 
266
342
  return null;
267
343
  })()
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,`(() => {
344
+ `;async function cn(n,t){let e=await t(["eval",n,Lt]).catch(()=>null);if(e&&e!=="null")await new Promise((o)=>setTimeout(o,1500))}var y={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 Ft(n){return await f(["eval",n,`(() => {
269
345
  const url = document.location.href || '';
270
346
  return url.indexOf('/sign-up/') !== -1 || url.indexOf('redirect_url=') !== -1;
271
- })()`]).catch(()=>"false")==="true"}async function dn(n){try{return JSON.parse(await $(["eval",n,`(() => {
347
+ })()`]).catch(()=>"false")==="true"}async function In(n){try{return JSON.parse(await f(["eval",n,`(() => {
272
348
  const url = document.location.href || '';
273
349
  const title = document.title || '';
274
350
  const text = document.body?.innerText || '';
@@ -279,7 +355,14 @@ ${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}asy
279
355
  text.includes('refresh_request_origin_azp_mismatch') ||
280
356
  (text.includes('HTTP ERROR 405') && text.includes('This page isn'));
281
357
  return JSON.stringify({ stale, url, title, text: text.slice(0, 500) });
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,`(() => {
358
+ })()`],5000))}catch{return{stale:!1,url:"",title:"",text:""}}}async function Rt(n){for(let t of["https://consensus.app","https://clerk.consensus.app"])await f(["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 dn(n,t,e){let o=await In(n);if(!o.stale)return!1;if(_(t,"auth-storage-reset",e),console.error(`[consensus] Detected stale Clerk/Consensus auth state (${o.title||o.url}) — clearing per-origin storage and retrying navigation`),t.fallbackUsed="clear-stale-consensus-auth",await Rt(n),await f(["nav",n,"https://consensus.app/"],20000),await new Promise((r)=>setTimeout(r,900)),(await In(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 It(n,t){await f(["click",n,y.input]),await new Promise((u)=>setTimeout(u,q(200)));let e=async()=>{await nn(["type",n,"--stdin"],t),await new Promise((u)=>setTimeout(u,q(300)))},o=async()=>{let u=await f(["eval",n,`JSON.stringify(document.querySelector('${y.input}')?.value || '')`]);try{return JSON.parse(u)}catch{return u}},i=async()=>_n(await o(),t),r=async()=>{await f(["eval",n,`(() => {
359
+ const el = document.querySelector('${y.input}');
360
+ if (!el) return false;
361
+ el.focus();
362
+ el.select();
363
+ document.execCommand('delete');
364
+ return true;
365
+ })()`])};if(await e(),await i())return;if(await r(),await e(),!await i())throw Error("Consensus input did not accept text — input verification failed")}async function dt(n){let e=await f(["eval",n,`(() => {
283
366
  if (window.__pdiInstalled) return 'already';
284
367
  window.__pdiInstalled = true;
285
368
  const _origOpen = XMLHttpRequest.prototype.open;
@@ -294,14 +377,22 @@ ${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}asy
294
377
  if (this.status === 200) {
295
378
  try {
296
379
  const parsed = JSON.parse(this.responseText);
297
- // Stack responses: the last one wins (the .CSV
298
- // request fires after Load More has settled).
299
- window.__papersDetailsResps = window.__papersDetailsResps || [];
300
- window.__papersDetailsResps.push({
380
+ // Keep only {largest, latest} instead of every
381
+ // partial Load-More response, to bound page
382
+ // memory. "latest" lets the caller detect the
383
+ // .CSV response fired after clickExportCsv;
384
+ // "largest" is the timeout fallback.
385
+ const entry = {
301
386
  at: Date.now(),
302
387
  count: Object.keys(parsed?.paperDetailsListByPaperId || {}).length,
303
388
  data: parsed,
304
- });
389
+ };
390
+ const store = window.__papersDetailsResps ||
391
+ (window.__papersDetailsResps = { largest: null, latest: null });
392
+ store.latest = entry;
393
+ if (!store.largest || entry.count > store.largest.count) {
394
+ store.largest = entry;
395
+ }
305
396
  } catch (e) {
306
397
  window.__papersDetailsErrors = window.__papersDetailsErrors || [];
307
398
  window.__papersDetailsErrors.push(String(e.message || e));
@@ -312,50 +403,92 @@ ${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}asy
312
403
  return _origSend.apply(this, arguments);
313
404
  };
314
405
  return 'installed';
315
- })()`]);return u==="installed"||u==="already"}async function wu(n,f=1e4){let u=`new Promise((resolve) => {
316
- const _deadline = Date.now() + ${f};
406
+ })()`]);return e==="installed"||e==="already"}async function Et(n,t=1e4,e=0){let o=`new Promise((resolve) => {
407
+ const _deadline = Date.now() + ${t};
408
+ const _after = ${e};
317
409
  function _check() {
318
- const resps = window.__papersDetailsResps || [];
319
- if (resps.length > 0) {
320
- const last = resps[resps.length - 1];
321
- resolve(JSON.stringify({ ok: true, count: last.count, data: last.data }));
410
+ const store = window.__papersDetailsResps;
411
+ const latest = store && store.latest;
412
+ if (latest && latest.at > _after) {
413
+ resolve(JSON.stringify({ ok: true, count: latest.count, data: latest.data }));
322
414
  return;
323
415
  }
324
416
  if (Date.now() < _deadline) {
325
417
  setTimeout(_check, 200);
326
418
  } else {
327
- resolve(JSON.stringify({ ok: false, reason: 'timeout' }));
419
+ const largest = store && store.largest;
420
+ if (largest) {
421
+ resolve(JSON.stringify({ ok: true, count: largest.count, data: largest.data, stale: true }));
422
+ } else {
423
+ resolve(JSON.stringify({ ok: false, reason: 'timeout' }));
424
+ }
328
425
  }
329
426
  }
330
427
  _check();
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
- const btns = Array.from(document.querySelectorAll('button'));
333
- return btns.some(b => {
334
- const t = (b.innerText || '').trim();
335
- return /load more/i.test(t) || /more results/i.test(t) || /show more/i.test(t);
336
- });
337
- })()`])!=="true")break;await $(["eval",n,`(() => {
338
- const btns = Array.from(document.querySelectorAll('button'));
339
- const btn = btns.find(b => {
340
- const t = (b.innerText || '').trim();
341
- return /load more/i.test(t) || /more results/i.test(t) || /show more/i.test(t);
342
- });
343
- btn?.click();
344
- return 'clicked';
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}');
428
+ })`,i=await f(["eval",n,o],t+5000);try{return JSON.parse(i)}catch{return{ok:!1,reason:"invalid-json"}}}async function ne(n,t=8){if(!await B(n,y.paperCard,20000,500).catch(()=>!1))return console.error("[consensus] Warning: no paper cards appeared within 20s — Load More will be skipped"),0;let o=String.raw`
429
+ new Promise((resolve) => {
430
+ const _paperSel = '${y.paperCard}';
431
+ const _maxClicks = ${t};
432
+ function _findLoadMore() {
433
+ const btns = Array.from(document.querySelectorAll('button'));
434
+ return btns.find(b => {
435
+ const t = (b.innerText || '').trim();
436
+ return /load more/i.test(t) || /more results/i.test(t) || /show more/i.test(t);
437
+ }) || null;
438
+ }
439
+ function _cardCount() { return document.querySelectorAll(_paperSel).length; }
440
+ let _clicks = 0;
441
+ function _waitButton(deadline, cb) {
442
+ const btn = _findLoadMore();
443
+ if (btn) { cb(btn); return; }
444
+ if (Date.now() < deadline) { setTimeout(() => _waitButton(deadline, cb), 200); }
445
+ else { cb(null); }
446
+ }
447
+ function _loop() {
448
+ if (_clicks >= _maxClicks) { resolve(JSON.stringify({ clicks: _clicks, cards: _cardCount() })); return; }
449
+ const mountDeadline = Date.now() + (_clicks === 0 ? 3000 : 500);
450
+ _waitButton(mountDeadline, (btn) => {
451
+ if (!btn || btn.disabled) { resolve(JSON.stringify({ clicks: _clicks, cards: _cardCount() })); return; }
452
+ const before = _cardCount();
453
+ btn.click();
454
+ _clicks++;
455
+ const clickDeadline = Date.now() + 4000;
456
+ (function _pollCards() {
457
+ if (_cardCount() > before || Date.now() >= clickDeadline) { _loop(); return; }
458
+ setTimeout(_pollCards, 200);
459
+ })();
460
+ });
461
+ }
462
+ _loop();
463
+ })
464
+ `,i=await f(["eval",n,o],t*5000+5000).catch(()=>null);if(!i)return 0;try{let{clicks:r,cards:u}=JSON.parse(i);return console.error(`[consensus] expandReferences: ${r} click(s), ${u} card(s)`),r}catch{return 0}}async function te(n,t=1200){let e=String.raw`
465
+ new Promise((resolve) => {
466
+ const _sel = '${y.paperCard}';
467
+ const _deadline = Date.now() + ${t};
468
+ let _last = document.querySelectorAll(_sel).length;
469
+ function _poll() {
470
+ const cur = document.querySelectorAll(_sel).length;
471
+ if (cur === _last) { resolve(cur); return; }
472
+ _last = cur;
473
+ if (Date.now() < _deadline) { setTimeout(_poll, 300); }
474
+ else { resolve(_last); }
475
+ }
476
+ setTimeout(_poll, 300);
477
+ })
478
+ `;await f(["eval",n,e],t+3000).catch(()=>null)}async function ee(n){return await f(["eval",n,`(() => {
479
+ const btn = document.querySelector('${y.exportButton}');
347
480
  if (!btn) return 'no-export';
348
481
  btn.scrollIntoView({ block: 'center' });
349
482
  btn.click();
350
483
  return 'opened';
351
- })()`]),await new Promise((u)=>setTimeout(u,600)),await $(["eval",n,`(() => {
484
+ })()`]),await new Promise((e)=>setTimeout(e,600)),await f(["eval",n,`(() => {
352
485
  const btn = Array.from(document.querySelectorAll('button'))
353
486
  .find(b => /\\.CSV/.test((b.innerText || '').trim()));
354
487
  if (!btn) return 'no-csv';
355
488
  btn.click();
356
489
  return 'clicked';
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}'));
490
+ })()`])}function ie(n){let t=n?.paperDetailsListByPaperId||{},e=Object.keys(t),o=[];for(let i=0;i<e.length;i++){let r=t[e[i]]||{},u=r.url_slug||"",l=r.paper_id||r.hash_paper_id||e[i],a;if(u)a=`https://consensus.app/papers/${u}/${l}/`;else if(r.provider_url)a=r.provider_url;else if(r.doi)a=`https://doi.org/${r.doi}`;else a=`https://consensus.app/paper/${l}`;let g=[],h=r.badges||{};if(h.study_type==="rct")g.push("RCT");else if(h.study_type==="meta_analysis")g.push("META-ANALYSIS");else if(h.study_type==="systematic_review")g.push("SYSTEMATIC REVIEW");else if(h.study_type)g.push(h.study_type.toUpperCase());if(h.rigorous_journal)g.push("RIGOROUS JOURNAL");if(h.very_rigorous_journal)g.push("VERY RIGOROUS JOURNAL");if(h.highly_cited_paper)g.push("HIGHLY CITED");if(h.large_human_trial)g.push("LARGE HUMAN TRIAL");if(r.is_retracted)g.push("RETRACTED");if(r.open_access_pdf_url)g.push("OPEN ACCESS");o.push({title:r.title||"",url:a,rank:i+1,authors:Array.isArray(r.authors)?r.authors:[],year:r.year||null,journal:r.journal||r.publisher_name||null,doi:r.doi||null,citation_count:r.citation_count||0,snippet:r.abstract_takeaway||"",tags:g})}return o}async function En(n){let t=`(() => {
491
+ const cards = Array.from(document.querySelectorAll('${y.paperCard}'));
359
492
  const sources = [];
360
493
  const seen = new Set();
361
494
  for (const card of cards) {
@@ -377,8 +510,8 @@ ${r}`,"utf8");try{B(k)}catch{}af(f,k)}}catch{}finally{if(i)try{B(n)}catch{}}}asy
377
510
  sources.push({ title, url, rank, snippet, tags });
378
511
  }
379
512
  return JSON.stringify(sources);
380
- })()`,u=await $(["eval",n,f],1e4);return JSON.parse(u)}async function Wu(n){let f=`(() => {
381
- const prose = document.querySelector('${J.answerContainer}');
513
+ })()`,e=await f(["eval",n,t],1e4);try{return JSON.parse(e)}catch{return[]}}async function re(n){let t=`(() => {
514
+ const prose = document.querySelector('${y.answerContainer}');
382
515
  return prose?.innerText?.trim() || '';
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();
516
+ })()`;return await f(["eval",n,t],1e4)||""}var oe=`Usage: node extractors/consensus.mjs "<query>" [--tab <prefix>]
517
+ `;async function ue(){let n=await bn(process.argv.slice(2));Wn(n,oe);let{query:t,tabPrefix:e,short:o}=mn(n),i=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 Rn(),!e)await f(["list"]);let l=await vn(e),a=await f(["eval",l,"document.location.href"]).catch(()=>""),g=!1;try{let p=new URL(a).hostname.toLowerCase();g=p==="consensus.app"||p.endsWith(".consensus.app")}catch{}if(!g)_(u,"nav",i),await f(["nav",l,"https://consensus.app/"],20000),await new Promise((p)=>setTimeout(p,600));await dn(l,u,i),await cn(l,f),_(u,"input-wait",i);let h=await B(l,y.input,15000,400);if(u.inputReady=h,!h)if(await dn(l,u,i)){let O=await B(l,y.input,15000,400);if(u.inputReady=O,O)await cn(l,f);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(tn.postClick))),_(u,"type-and-submit",i),await It(l,t),await new Promise((p)=>setTimeout(p,q(tn.postType))),await f(["eval",l,`document.querySelector('${y.submitButton}')?.click()`]),await new Promise((p)=>setTimeout(p,2000)),await Ft(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.");_(u,"answer-wait",i),await B(l,y.answerContainer,30000,500),await dt(l),_(u,"expand-refs",i);let m=await ne(l,8);if(m===0)console.error("[consensus] Note: 'Load more results' button not present (initial page has all references)");else console.error(`[consensus] Clicked 'Load more results' ${m} time(s) to expand references`);await te(l,1200),_(u,"csv-click",i);let U=Number(await f(["eval",l,"Date.now()"]).catch(()=>"0")||0),M=await ee(l);if(M!=="clicked")console.error(`[consensus] Export → .CSV click did not register (${M}) — falling back to DOM`);_(u,"wait-csv-resp",i);let A=await Et(l,12000,U),Z=[],wn="dom";if(A.ok)Z=ie(A.data),wn="api-intercept",console.error(`[consensus] Captured /api/papers/details/ response with ${A.count} paper(s)`);else console.error(`[consensus] /api/papers/details/ response not captured (${A.reason}) — falling back to DOM cards`);_(u,"extract",i);let pn=await re(l);if(!pn)throw Error("No answer extracted — Consensus may not have responded");if(Z.length===0)Z=await En(l);else{let p=await En(l),O=new Set(Z.map((D)=>D.url));for(let D of p)if(!O.has(D.url))Z.push(D)}let nt=await f(["eval",l,"document.location.href"]).catch(()=>"");u.durationMs=Date.now()-i,u.sourcePath=wn,_(u,"done",i),Jn({query:t,url:nt,answer:jn(pn,o),sources:Z,_envelope:en(u)})}catch(l){u.durationMs=Date.now()-i,xn(l,en(u))}}ue();