@duckmind/dm-darwin-x64 0.43.4 → 0.48.5
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 +242 -50
- package/extensions/dm-9router-ext/package.json +2 -19
- package/extensions/dm-9router-ext/src/index.js +5 -0
- package/extensions/dm-ask-user/index.js +10 -0
- package/extensions/dm-ask-user/package.json +1 -21
- package/extensions/dm-cli-anything/package.json +0 -6
- package/extensions/dm-context/package.json +2 -12
- package/extensions/dm-context/src/context.js +1 -0
- package/extensions/dm-context/src/index.js +7 -0
- package/extensions/dm-context/src/utils.js +1 -0
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +1 -28
- package/extensions/dm-fff/src/index.js +15 -0
- package/extensions/dm-fff/src/query.js +1 -0
- package/extensions/dm-goal/package.json +2 -31
- package/extensions/dm-goal/src/goal.js +43 -0
- package/extensions/dm-grill-me/index.js +174 -0
- package/extensions/dm-grill-me/package.json +1 -26
- package/extensions/dm-image2/package.json +0 -7
- package/extensions/dm-subagents/package.json +1 -32
- package/extensions/dm-subagents/src/agents/agent-management.js +37 -0
- package/extensions/dm-subagents/src/agents/agent-memory.js +6 -0
- package/extensions/dm-subagents/src/agents/agent-scope.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-selection.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +7 -0
- package/extensions/dm-subagents/src/agents/agents.js +11 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -0
- package/extensions/dm-subagents/src/agents/frontmatter.js +6 -0
- package/extensions/dm-subagents/src/agents/identity.js +1 -0
- package/extensions/dm-subagents/src/agents/proactive-skills.js +1 -0
- package/extensions/dm-subagents/src/agents/skills.js +6 -0
- package/extensions/dm-subagents/src/extension/config.js +2 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -0
- package/extensions/dm-subagents/src/extension/doctor.js +16 -0
- package/extensions/dm-subagents/src/extension/fanout-child.js +231 -0
- package/extensions/dm-subagents/src/extension/index.js +367 -0
- package/extensions/dm-subagents/src/extension/rpc.js +8 -0
- package/extensions/dm-subagents/src/extension/schemas.js +1 -0
- package/extensions/dm-subagents/src/extension/{tool-description.ts → tool-description.js} +6 -126
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +13 -0
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +5 -0
- package/extensions/dm-subagents/src/intercom/result-intercom.js +3 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +3 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +46 -0
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +14 -0
- package/extensions/dm-subagents/src/runs/background/async-resume.js +8 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +12 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +2 -0
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +1 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +1 -0
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +17 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +3 -0
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +1 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +8 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +4 -0
- package/extensions/dm-subagents/src/runs/background/run-status.js +23 -0
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +4 -0
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +11 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +78 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -0
- package/extensions/dm-subagents/src/runs/background/wait.js +11 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +12 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +102 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +51 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +14 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +7 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +2 -0
- package/extensions/dm-subagents/src/shared/atomic-json.js +1 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +5 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +1 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +6 -0
- package/extensions/dm-subagents/src/shared/formatters.js +9 -0
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +2 -0
- package/extensions/dm-subagents/src/shared/model-info.js +1 -0
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +1 -0
- package/extensions/dm-subagents/src/shared/session-identity.js +1 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +2 -0
- package/extensions/dm-subagents/src/shared/settings.js +23 -0
- package/extensions/dm-subagents/src/shared/status-format.js +1 -0
- package/extensions/dm-subagents/src/shared/types.js +8 -0
- package/extensions/dm-subagents/src/shared/utils.js +2 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +7 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/slash-commands.js +38 -0
- package/extensions/dm-subagents/src/slash/slash-live-state.js +6 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +1 -0
- package/extensions/dm-subagents/src/tui/render.js +4 -0
- package/extensions/dm-tasks/package.json +1 -30
- package/extensions/dm-tasks/src/auto-clear.js +1 -0
- package/extensions/dm-tasks/src/index.js +212 -0
- package/extensions/dm-tasks/src/process-tracker.js +1 -0
- package/extensions/dm-tasks/src/task-store.js +1 -0
- package/extensions/dm-tasks/src/tasks-config.js +1 -0
- package/extensions/dm-tasks/src/types.js +0 -0
- package/extensions/dm-tasks/src/ui/settings-menu.js +1 -0
- package/extensions/dm-tasks/src/ui/task-widget.js +1 -0
- package/extensions/dm-usage/index.js +9 -0
- package/extensions/dm-usage/package.json +1 -18
- package/extensions/greedysearch-dm/bin/search.mjs +51 -51
- package/extensions/greedysearch-dm/index.js +20 -0
- package/extensions/greedysearch-dm/package.json +1 -22
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -0
- package/extensions/greedysearch-dm/src/formatters/sources.js +1 -0
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +1 -0
- package/extensions/greedysearch-dm/src/search/research.mjs +59 -59
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +20 -0
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -0
- package/extensions/greedysearch-dm/src/types.js +0 -0
- package/extensions/greedysearch-dm/src/utils/helpers.js +1 -0
- package/package.json +1 -1
- package/extensions/dm-9router-ext/src/index.ts +0 -541
- package/extensions/dm-ask-user/index.ts +0 -857
- package/extensions/dm-context/src/context.ts +0 -158
- package/extensions/dm-context/src/index.ts +0 -439
- package/extensions/dm-context/src/utils.ts +0 -6
- package/extensions/dm-fff/src/index.ts +0 -1023
- package/extensions/dm-fff/src/query.ts +0 -87
- package/extensions/dm-goal/src/goal.ts +0 -1073
- package/extensions/dm-grill-me/index.ts +0 -1085
- package/extensions/dm-subagents/src/agents/agent-management.ts +0 -1052
- package/extensions/dm-subagents/src/agents/agent-memory.ts +0 -254
- package/extensions/dm-subagents/src/agents/agent-scope.ts +0 -6
- package/extensions/dm-subagents/src/agents/agent-selection.ts +0 -25
- package/extensions/dm-subagents/src/agents/agent-serializer.ts +0 -121
- package/extensions/dm-subagents/src/agents/agents.ts +0 -1553
- package/extensions/dm-subagents/src/agents/chain-serializer.ts +0 -277
- package/extensions/dm-subagents/src/agents/frontmatter.ts +0 -93
- package/extensions/dm-subagents/src/agents/identity.ts +0 -30
- package/extensions/dm-subagents/src/agents/proactive-skills.ts +0 -191
- package/extensions/dm-subagents/src/agents/skills.ts +0 -729
- package/extensions/dm-subagents/src/extension/config.ts +0 -39
- package/extensions/dm-subagents/src/extension/control-notices.ts +0 -92
- package/extensions/dm-subagents/src/extension/doctor.ts +0 -214
- package/extensions/dm-subagents/src/extension/fanout-child.ts +0 -172
- package/extensions/dm-subagents/src/extension/index.ts +0 -656
- package/extensions/dm-subagents/src/extension/rpc.ts +0 -369
- package/extensions/dm-subagents/src/extension/schemas.ts +0 -309
- package/extensions/dm-subagents/src/intercom/intercom-bridge.ts +0 -180
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.ts +0 -519
- package/extensions/dm-subagents/src/intercom/result-intercom.ts +0 -377
- package/extensions/dm-subagents/src/profiles/profiles.ts +0 -637
- package/extensions/dm-subagents/src/runs/background/async-execution.ts +0 -1065
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.ts +0 -441
- package/extensions/dm-subagents/src/runs/background/async-resume.ts +0 -391
- package/extensions/dm-subagents/src/runs/background/async-status.ts +0 -395
- package/extensions/dm-subagents/src/runs/background/chain-append.ts +0 -282
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.ts +0 -191
- package/extensions/dm-subagents/src/runs/background/completion-batcher.ts +0 -166
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.ts +0 -63
- package/extensions/dm-subagents/src/runs/background/control-channel.ts +0 -332
- package/extensions/dm-subagents/src/runs/background/fleet-view.ts +0 -515
- package/extensions/dm-subagents/src/runs/background/notify.ts +0 -225
- package/extensions/dm-subagents/src/runs/background/parallel-groups.ts +0 -45
- package/extensions/dm-subagents/src/runs/background/result-watcher.ts +0 -315
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.ts +0 -84
- package/extensions/dm-subagents/src/runs/background/run-status.ts +0 -434
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.ts +0 -514
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.ts +0 -368
- package/extensions/dm-subagents/src/runs/background/subagent-runner.ts +0 -3171
- package/extensions/dm-subagents/src/runs/background/top-level-async.ts +0 -13
- package/extensions/dm-subagents/src/runs/background/wait.ts +0 -353
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.ts +0 -1333
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.ts +0 -1313
- package/extensions/dm-subagents/src/runs/foreground/execution.ts +0 -1239
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.ts +0 -3613
- package/extensions/dm-subagents/src/runs/shared/acceptance.ts +0 -879
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.ts +0 -116
- package/extensions/dm-subagents/src/runs/shared/completion-guard.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dm-args.ts +0 -271
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.ts +0 -295
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.ts +0 -175
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -365
- package/extensions/dm-subagents/src/runs/shared/model-fallback.ts +0 -292
- package/extensions/dm-subagents/src/runs/shared/model-scope.ts +0 -128
- package/extensions/dm-subagents/src/runs/shared/nested-events.ts +0 -908
- package/extensions/dm-subagents/src/runs/shared/nested-path.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/nested-render.ts +0 -115
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.ts +0 -198
- package/extensions/dm-subagents/src/runs/shared/run-history.ts +0 -60
- package/extensions/dm-subagents/src/runs/shared/single-output.ts +0 -180
- package/extensions/dm-subagents/src/runs/shared/structured-output.ts +0 -77
- package/extensions/dm-subagents/src/runs/shared/subagent-control.ts +0 -223
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.ts +0 -342
- package/extensions/dm-subagents/src/runs/shared/tool-budget.ts +0 -74
- package/extensions/dm-subagents/src/runs/shared/turn-budget.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.ts +0 -206
- package/extensions/dm-subagents/src/runs/shared/worktree.ts +0 -600
- package/extensions/dm-subagents/src/shared/artifacts.ts +0 -113
- package/extensions/dm-subagents/src/shared/atomic-json.ts +0 -86
- package/extensions/dm-subagents/src/shared/child-transcript.ts +0 -212
- package/extensions/dm-subagents/src/shared/file-coalescer.ts +0 -40
- package/extensions/dm-subagents/src/shared/fork-context.ts +0 -194
- package/extensions/dm-subagents/src/shared/formatters.ts +0 -133
- package/extensions/dm-subagents/src/shared/jsonl-writer.ts +0 -81
- package/extensions/dm-subagents/src/shared/model-info.ts +0 -78
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/extensions/dm-subagents/src/shared/session-identity.ts +0 -10
- package/extensions/dm-subagents/src/shared/session-tokens.ts +0 -44
- package/extensions/dm-subagents/src/shared/settings.ts +0 -450
- package/extensions/dm-subagents/src/shared/status-format.ts +0 -49
- package/extensions/dm-subagents/src/shared/types.ts +0 -1257
- package/extensions/dm-subagents/src/shared/utils.ts +0 -554
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.ts +0 -420
- package/extensions/dm-subagents/src/slash/prompt-workflows.ts +0 -330
- package/extensions/dm-subagents/src/slash/slash-bridge.ts +0 -176
- package/extensions/dm-subagents/src/slash/slash-commands.ts +0 -1296
- package/extensions/dm-subagents/src/slash/slash-live-state.ts +0 -292
- package/extensions/dm-subagents/src/tui/render-helpers.ts +0 -80
- package/extensions/dm-subagents/src/tui/render.ts +0 -1748
- package/extensions/dm-tasks/src/auto-clear.ts +0 -91
- package/extensions/dm-tasks/src/index.ts +0 -1145
- package/extensions/dm-tasks/src/process-tracker.ts +0 -140
- package/extensions/dm-tasks/src/task-store.ts +0 -305
- package/extensions/dm-tasks/src/tasks-config.ts +0 -23
- package/extensions/dm-tasks/src/types.ts +0 -40
- package/extensions/dm-tasks/src/ui/settings-menu.ts +0 -100
- package/extensions/dm-tasks/src/ui/task-widget.ts +0 -265
- package/extensions/dm-usage/index.ts +0 -1718
- package/extensions/greedysearch-dm/index.ts +0 -177
- package/extensions/greedysearch-dm/src/formatters/results.ts +0 -163
- package/extensions/greedysearch-dm/src/formatters/sources.ts +0 -116
- package/extensions/greedysearch-dm/src/formatters/synthesis.ts +0 -87
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.ts +0 -370
- package/extensions/greedysearch-dm/src/tools/shared.ts +0 -187
- package/extensions/greedysearch-dm/src/types.ts +0 -110
- package/extensions/greedysearch-dm/src/utils/helpers.ts +0 -40
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{createRequire as Vr}from"node:module";var Fr=Object.defineProperty;var Yr=(t)=>t;function Gr(t,e){this[t]=Yr.bind(null,e)}var et=(t,e)=>{for(var r in e)Fr(t,r,{get:e[r],enumerable:!0,configurable:!0,set:Gr.bind(e,r)})};var gt=(t,e)=>()=>(t&&(e=t(t=0)),e);var dr=Vr(import.meta.url);var lr={};et(lr,{fetchTopSource:()=>ma,fetchSourceContent:()=>ar,fetchMultipleSources:()=>ca});import{createRequire as $n}from"node:module";import{Readability as cn}from"@mozilla/readability";import{JSDOM as mn}from"jsdom";import bn from"turndown";import{platform as
|
|
1
|
+
import{createRequire as Vr}from"node:module";var Fr=Object.defineProperty;var Yr=(t)=>t;function Gr(t,e){this[t]=Yr.bind(null,e)}var et=(t,e)=>{for(var r in e)Fr(t,r,{get:e[r],enumerable:!0,configurable:!0,set:Gr.bind(e,r)})};var gt=(t,e)=>()=>(t&&(e=t(t=0)),e);var dr=Vr(import.meta.url);var lr={};et(lr,{fetchTopSource:()=>ma,fetchSourceContent:()=>ar,fetchMultipleSources:()=>ca});import{createRequire as $n}from"node:module";import{Readability as cn}from"@mozilla/readability";import{JSDOM as mn}from"jsdom";import bn from"turndown";import{platform as $i,tmpdir as An}from"node:os";import{spawn as Rn}from"node:child_process";import{dirname as Jn,join as Hn}from"node:path";import{fileURLToPath as Fn}from"node:url";import{basename as Yn}from"node:path";import{existsSync as mt,mkdirSync as Gn,readFileSync as Ke,writeFileSync as Vn}from"node:fs";import{homedir as dn}from"node:os";import{join as Ue}from"node:path";import{tmpdir as _t}from"node:os";import{platform as Di,tmpdir as Zn}from"node:os";import{existsSync as bt,mkdirSync as Bn,readFileSync as Ie,writeFileSync as Kn}from"node:fs";import{homedir as Un}from"node:os";import{join as Xe}from"node:path";import{tmpdir as kt}from"node:os";import{existsSync as yt,mkdirSync as ra,readFileSync as qe,writeFileSync as na}from"node:fs";import{homedir as aa}from"node:os";import{join as tr}from"node:path";import{tmpdir as st}from"node:os";function _n(t={}){return{...Fe,...t}}function Ye(t){try{let e=new URL(t),r=e.hostname.toLowerCase();for(let n of yn)if(n.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(e.protocol==="file:")return{blocked:!0,reason:"File protocol not allowed"};return{blocked:!1}}catch(e){return{blocked:!0,reason:`Invalid URL: ${e.message}`}}}function kn(t){try{let e=new URL(t);if(!(e.hostname==="github.com"||e.hostname.endsWith(".github.com")))return t;let r=e.pathname.split("/").filter(Boolean);if(r.length<5)return t;let[n,a,l,i,...f]=r;if(l!=="blob")return t;let o=f.join("/");return`https://raw.githubusercontent.com/${n}/${a}/${i}/${o}`}catch{return t}}async function sn(t,e={}){let r=Ye(t);if(r.blocked)return{ok:!1,url:t,finalUrl:t,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let n=t;if(t=kn(t),t!==n)console.error(`[fetcher] Rewrote GitHub URL: ${n.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:a=15000,userAgent:l,signal:i}=e,f=new AbortController,o=setTimeout(()=>f.abort(),a);if(i)i.addEventListener("abort",()=>f.abort(),{once:!0});try{let g=await fetch(t,{method:"GET",headers:{...Fe,"user-agent":l||He},redirect:"follow",signal:f.signal});clearTimeout(o);let p=g.headers.get("content-type")||"",h=g.url,m=g.headers.get("last-modified")||"",c=!1;try{c=new URL(h).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(p.includes("text/plain")&&c){let C=await g.text();return{ok:!0,url:n,finalUrl:h,status:g.status,title:h.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:m,lastModified:m,markdown:C,contentLength:C.length,excerpt:C.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!p.includes("text/html")&&!p.includes("application/xhtml"))return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Unsupported content type: ${p}`,needsBrowser:!1};let y=await g.text(),b=Ge(g.status,y,h,t);if(b.blocked)return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Blocked: ${b.reason}`,needsBrowser:!0};let w=Ve(y,h),k=de(w);if(!k.ok)return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Low quality content: ${k.reason}`,needsBrowser:!0};return{ok:!0,url:t,finalUrl:h,status:g.status,title:w.title,byline:w.byline,siteName:w.siteName,lang:w.lang,publishedTime:w.publishedTime||m,lastModified:m,markdown:w.markdown,excerpt:w.excerpt,contentLength:w.markdown.length,needsBrowser:!1}}catch(g){clearTimeout(o);let p=Cn(g);return{ok:!1,url:t,finalUrl:t,status:0,error:g.message,needsBrowser:p}}}function Ge(t,e,r,n){let a=e.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",l=e.slice(0,30000).toLowerCase(),i=`${a} ${l}`;if(t===403||t===429||t===503)return{blocked:!0,reason:`HTTP ${t}`};let f=[{pattern:/class=["'][^"']*captcha["']|<div[^>]*id=["']captcha/i,reason:"captcha"},{pattern:/g-recaptcha|data-sitekey|i['"]m not a robot/i,reason:"captcha"},{pattern:/checking your browser.{0,100}please wait|cf-browser-verification/i,reason:"cloudflare challenge"},{pattern:/just a moment.{0,50}security check|ddos protection by cloudflare/i,reason:"cloudflare challenge"},{pattern:/unusual traffic.{0,50}from your computer network/i,reason:"unusual traffic"},{pattern:/bot detected|automated.{0,20}request/i,reason:"bot detection"},{pattern:/enable\s+javascript\s+to\s+view|javascript\s+is\s+required.{0,50}enabled/i,reason:"requires javascript"},{pattern:/access denied|accessdenied/i,reason:"access denied"},{pattern:/protected by anubis|anubis uses a proof-of-work/i,reason:"anubis challenge"}];for(let g of f)if(g.pattern.test(i))return{blocked:!0,reason:g.reason};let o=En(n,r,e);if(o)return{blocked:!0,reason:o};return{blocked:!1}}function En(t,e,r){try{let n=new URL(t),a=new URL(e);if(n.hostname.toLowerCase()===a.hostname.toLowerCase())return;let l=a.hostname.toLowerCase();if(vn.some((f)=>l===f||l.endsWith(`.${f}`)))return`redirected to login (${a.hostname})`;if(jn.some((f)=>l.startsWith(f)))return`redirected to login (${a.hostname})`;let i=r.slice(0,20000).toLowerCase();if(Dn.some((f)=>i.includes(f)))return`redirected to login page (${a.hostname})`}catch{}return}function Cn(t){let e=t.message.toLowerCase();return e.includes("fetch failed")||e.includes("unable to verify")||e.includes("certificate")||e.includes("timeout")}function Te(t){let e=['meta[property="article:published_time"]','meta[name="article:published_time"]','meta[property="og:published_time"]','meta[name="publication_date"]','meta[name="date"]','meta[itemprop="datePublished"]','time[itemprop="datePublished"]','meta[name="DC.date"]'];for(let r of e){let n=t.querySelector(r),a=n?.getAttribute("content")||n?.getAttribute("datetime")||"";if(a)return a}return""}function Ve(t,e){let r=new mn(t,{url:e}).window.document,n=new cn(r).parse();if(n&&n.content){let l=Je.turndown(n.content).replaceAll(/\n{3,}/g,`
|
|
2
2
|
|
|
3
|
-
`).trim(),i=n.publishedTime||Te(r)||"";return{title:n.title||r.title||e,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:i,markdown:l,excerpt:l.slice(0,300).replaceAll(/\n/g," ")}}let a=r.body;if(a){let l=a.cloneNode(!0);l.querySelectorAll("script, style, nav, footer, header, aside").forEach((f)=>f.remove());let i=(l.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||e,byline:"",siteName:"",lang:"",publishedTime:Te(r),markdown:i,excerpt:i.slice(0,300)}}return{title:e,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function de(t){let e=t.markdown.trim().toLowerCase(),r=(t.title||"").toLowerCase();if(t.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let n=e.toLowerCase(),a=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(e),desc:"login form only"}];for(let{check:l,desc:i}of a)if(l())return{ok:!1,reason:i};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}function
|
|
3
|
+
`).trim(),i=n.publishedTime||Te(r)||"";return{title:n.title||r.title||e,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:i,markdown:l,excerpt:l.slice(0,300).replaceAll(/\n/g," ")}}let a=r.body;if(a){let l=a.cloneNode(!0);l.querySelectorAll("script, style, nav, footer, header, aside").forEach((f)=>f.remove());let i=(l.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||e,byline:"",siteName:"",lang:"",publishedTime:Te(r),markdown:i,excerpt:i.slice(0,300)}}return{title:e,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function de(t){let e=t.markdown.trim().toLowerCase(),r=(t.title||"").toLowerCase();if(t.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let n=e.toLowerCase(),a=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(e),desc:"login form only"}];for(let{check:l,desc:i}of a)if(l())return{ok:!1,reason:i};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}function Gt(t){try{let e=new URL(t);if(!(e.hostname==="github.com"||e.hostname.endsWith(".github.com")))return null;let r=e.pathname.split("/").filter(Boolean);if(r.length<2)return null;let[n,a]=r;if(r.length===2)return{owner:n,repo:a,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let l=r[2],i=r[3],f=r.slice(4).join("/");return{owner:n,repo:a,type:l,ref:i,path:f}}return null}catch{return null}}async function K(t,e=1e4){let r=new AbortController,n=setTimeout(()=>r.abort(),e);try{let a=await fetch(`https://api.github.com${t}`,{headers:Ze,signal:r.signal});if(clearTimeout(n),!a.ok)throw Error(`GitHub API ${a.status}: ${t}`);return await a.json()}catch(a){throw clearTimeout(n),a}}async function Nn(t,e){try{let r=await K(`/repos/${t}/${e}/readme`);if(r.content&&r.encoding==="base64")return Buffer.from(r.content,"base64").toString("utf8");return""}catch{return""}}async function Oe(t,e,r="HEAD",n=""){try{let a=await K(`/repos/${t}/${e}/git/ref/heads/${r==="HEAD"?"main":r}`).catch(()=>K(`/repos/${t}/${e}/git/ref/heads/master`).catch(()=>null)),l;if(a?.object?.sha)l=(await K(`/repos/${t}/${e}/git/commits/${a.object.sha}`)).tree.sha;else{let f=await K(`/repos/${t}/${e}`);l=(await K(`/repos/${t}/${e}/branches/${f.default_branch}`)).commit.commit.tree.sha}let i=(await K(`/repos/${t}/${e}/git/trees/${l}`)).tree||[];if(n)i=i.filter((f)=>f.path.startsWith(n));return i.slice(0,50).map((f)=>({path:f.path,type:f.type==="tree"?"dir":"file",size:f.size}))}catch{return[]}}async function Tn(t,e,r,n,a=1e4){let l=[`https://raw.githubusercontent.com/${t}/${e}/${r&&r!=="HEAD"?r:"main"}/${n}`,`https://raw.githubusercontent.com/${t}/${e}/master/${n}`];for(let i of l){let f=new AbortController,o=setTimeout(()=>f.abort(),a);try{let g=await fetch(i,{headers:{"user-agent":Ze["user-agent"]},signal:f.signal});if(clearTimeout(o),g.ok)return await g.text()}catch{clearTimeout(o)}}return null}async function On(t){let e=Gt(t);if(!e)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:n,type:a,ref:l,path:i}=e;try{if(a==="root"||a==="tree"&&!i){let[f,o,g]=await Promise.allSettled([K(`/repos/${r}/${n}`),Nn(r,n),Oe(r,n,l||"HEAD")]);if(f.status==="rejected")return{ok:!1,error:f.reason?.message||"Repo not found"};let p=f.value,h=o.status==="fulfilled"?o.value:"",m=g.status==="fulfilled"?g.value:[],c=p?.description?`
|
|
4
4
|
|
|
5
5
|
> ${p.description}`:"",y=p?.stargazers_count==null?"":` ⭐ ${p.stargazers_count}`,b=p?.language?` · ${p.language}`:"",w=`# ${r}/${n}${y}${b}${c}
|
|
6
6
|
|
|
@@ -248,35 +248,35 @@ ${o}`,tree:f}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(f){return{
|
|
|
248
248
|
};
|
|
249
249
|
} catch(_) {}
|
|
250
250
|
})();
|
|
251
|
-
`})])}function zn(){try{if(
|
|
252
|
-
[greedysearch] Available engines: ${Object.keys(Jt).join(", ")}
|
|
253
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${V}, falling back to defaults: ${Vt.join(", ")}
|
|
254
|
-
`)}}}catch{}return Vt}function Sn(){try{if(!ct(Gt))Gn(Gt,{recursive:!0});if(!ct(V))Vn(V,JSON.stringify({engines:Vt,synthesizer:dt},null,2)+`
|
|
255
|
-
`,"utf8")}catch{}}function un(){try{if(ct(V)){let t=Ke(V,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let r=e.synthesizer.toLowerCase();if(We.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${V}
|
|
256
|
-
[greedysearch] Available synthesizers: ${We.join(", ")}
|
|
257
|
-
[greedysearch] Falling back to default: ${dt}
|
|
258
|
-
`)}}}catch{}return dt}function qn(){try{if(mt(d)){let t=Ie(d,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Ht[a]),n=e.engines.filter((a)=>!Ht[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${d}: ${n.join(", ")}
|
|
251
|
+
`})])}function zn(){try{if(mt(V)){let t=Ke(V,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Ht[a]),n=e.engines.filter((a)=>!Ht[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${V}: ${n.join(", ")}
|
|
259
252
|
[greedysearch] Available engines: ${Object.keys(Ht).join(", ")}
|
|
260
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
261
|
-
`)}}}catch{}return
|
|
262
|
-
`,"utf8")}catch{}}function
|
|
263
|
-
[greedysearch] Available synthesizers: ${
|
|
264
|
-
[greedysearch] Falling back to default: ${
|
|
265
|
-
`)}}}catch{}return
|
|
266
|
-
`)[0];if(!t)throw Error("No Chrome tabs found");return t.slice(0,8)}async function xt(t="about:blank"){let e=await ue(),r=new URL(t).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let l=await P(["evalraw",e,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:i}=JSON.parse(l),f=i.slice(0,8);if(await P(["list"]).catch(()=>null),r==="copilot.microsoft.com")await Le(f);else Le(f).catch(()=>{});return await P(["list"]).catch(()=>null),i}let n=await P(["evalraw",e,"Target.createTarget",JSON.stringify({url:t})]),{targetId:a}=JSON.parse(n);return await P(["list"]).catch(()=>null),a}async function Qt(t){try{let e=await ue();await P(["evalraw",e,"Target.closeTarget",JSON.stringify({targetId:t})])}catch{}}function la(){try{if(bt(Z)){let t=qe(Z,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Ft[a]),n=e.engines.filter((a)=>!Ft[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${Z}: ${n.join(", ")}
|
|
253
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${V}, falling back to defaults: ${dt.join(", ")}
|
|
254
|
+
`)}}}catch{}return dt}function Sn(){try{if(!mt(Vt))Gn(Vt,{recursive:!0});if(!mt(V))Vn(V,JSON.stringify({engines:dt,synthesizer:Zt},null,2)+`
|
|
255
|
+
`,"utf8")}catch{}}function un(){try{if(mt(V)){let t=Ke(V,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let r=e.synthesizer.toLowerCase();if(We.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${V}
|
|
256
|
+
[greedysearch] Available synthesizers: ${We.join(", ")}
|
|
257
|
+
[greedysearch] Falling back to default: ${Zt}
|
|
258
|
+
`)}}}catch{}return Zt}function qn(){try{if(bt(d)){let t=Ie(d,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Ft[a]),n=e.engines.filter((a)=>!Ft[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${d}: ${n.join(", ")}
|
|
267
259
|
[greedysearch] Available engines: ${Object.keys(Ft).join(", ")}
|
|
268
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
269
|
-
`)}}}catch{}return
|
|
270
|
-
`,"utf8")}catch{}}function
|
|
260
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${d}, falling back to defaults: ${Kt.join(", ")}
|
|
261
|
+
`)}}}catch{}return Kt}function ta(){try{if(!bt(Bt))Bn(Bt,{recursive:!0});if(!bt(d))Kn(d,JSON.stringify({engines:Kt,synthesizer:Ut},null,2)+`
|
|
262
|
+
`,"utf8")}catch{}}function ea(){try{if(bt(d)){let t=Ie(d,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let r=e.synthesizer.toLowerCase();if(Me.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${d}
|
|
263
|
+
[greedysearch] Available synthesizers: ${Me.join(", ")}
|
|
264
|
+
[greedysearch] Falling back to default: ${Ut}
|
|
265
|
+
`)}}}catch{}return Ut}async function ue(){let t=(await P(["list"])).split(`
|
|
266
|
+
`)[0];if(!t)throw Error("No Chrome tabs found");return t.slice(0,8)}async function Qt(t="about:blank"){let e=await ue(),r=new URL(t).hostname;if(r==="copilot.microsoft.com"||r==="www.perplexity.ai"||r==="perplexity.ai"||r.endsWith(".perplexity.ai")){let l=await P(["evalraw",e,"Target.createTarget",JSON.stringify({url:"about:blank"})]),{targetId:i}=JSON.parse(l),f=i.slice(0,8);if(await P(["list"]).catch(()=>null),r==="copilot.microsoft.com")await Le(f);else Le(f).catch(()=>{});return await P(["list"]).catch(()=>null),i}let n=await P(["evalraw",e,"Target.createTarget",JSON.stringify({url:t})]),{targetId:a}=JSON.parse(n);return await P(["list"]).catch(()=>null),a}async function zt(t){try{let e=await ue();await P(["evalraw",e,"Target.closeTarget",JSON.stringify({targetId:t})])}catch{}}function la(){try{if(yt(Z)){let t=qe(Z,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Yt[a]),n=e.engines.filter((a)=>!Yt[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${Z}: ${n.join(", ")}
|
|
267
|
+
[greedysearch] Available engines: ${Object.keys(Yt).join(", ")}
|
|
268
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${Z}, falling back to defaults: ${Xt.join(", ")}
|
|
269
|
+
`)}}}catch{}return Xt}function ia(){try{if(!yt(It))ra(It,{recursive:!0});if(!yt(Z))na(Z,JSON.stringify({engines:Xt,synthesizer:xt},null,2)+`
|
|
270
|
+
`,"utf8")}catch{}}function fa(){try{if(yt(Z)){let t=qe(Z,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let r=e.synthesizer.toLowerCase();if(Ae.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${Z}
|
|
271
271
|
[greedysearch] Available synthesizers: ${Ae.join(", ")}
|
|
272
|
-
[greedysearch] Falling back to default: ${
|
|
273
|
-
`)}}}catch{}return
|
|
272
|
+
[greedysearch] Falling back to default: ${xt}
|
|
273
|
+
`)}}}catch{}return xt}function ga(){if(typeof globalThis.DOMMatrix>"u")globalThis.DOMMatrix=class{constructor(t=void 0){}multiplySelf(){return this}preMultiplySelf(){return this}translateSelf(){return this}scaleSelf(){return this}rotateSelf(){return this}};if(typeof globalThis.ImageData>"u")globalThis.ImageData=class{constructor(t=void 0,e=0,r=0){this.data=t,this.width=e,this.height=r}};if(typeof globalThis.Path2D>"u")globalThis.Path2D=class{constructor(t=void 0){}}}async function oa(){ga();let t=await import("pdf-parse"),e=t.PDFParse??t.default;if(!e)throw Error("pdf-parse did not export PDFParse");return e}async function pa(t,e){try{let r=new(await oa())({data:new Uint8Array(t)});await r.load();let n=await r.getText(),a=n.text?.trim();if(!a)return null;return{title:new URL(e).pathname.split("/").pop()||"Document.pdf",content:`## PDF Content (${n.total} pages)
|
|
274
274
|
|
|
275
|
-
${a}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function rr(t="",e=240){let r=String(t).replaceAll(/\s+/g," ").trim();if(r.length<=e)return r;let n=r.slice(0,e),a=n.lastIndexOf(" ");return a>0?`${n.slice(0,a)}...`:`${n}...`}async function ha(t,e,r=8000){let n=Date.now();try{let a=(await P(["evalraw",t,"Page.getFrameTree","{}"]).then((m)=>JSON.parse(m)).catch(()=>null))?.frameTree?.frame?.id||void 0,l=await P(["evalraw",t,"Network.loadNetworkResource",JSON.stringify({frameId:a,url:e,options:{disableCache:!0,includeCredentials:!1}})],20000),i=JSON.parse(l).resource;if(!i?.success||!i.httpStatusCode)return{url:e,error:i?.netErrorName||i?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-n,needsFallback:!0};let f="";if(i.stream)try{let m=await P(["evalraw",t,"IO.read",JSON.stringify({handle:i.stream})],1e4);f=JSON.parse(m).data||"",await P(["evalraw",t,"IO.close",JSON.stringify({handle:i.stream})]).catch(()=>{})}catch{}if(!f||f.length<100)return{url:e,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-n,needsFallback:!0};let o=Ge(i.httpStatusCode,f,e,e);if(o.blocked)return{url:e,status:i.httpStatusCode,error:`Blocked: ${o.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let g=Ve(f,e),p=de(g);if(!p.ok)return{url:e,status:i.httpStatusCode,error:`Low quality: ${p.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let h=q(g.markdown,r);return{url:e,finalUrl:e,status:i.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:g.publishedTime||"",byline:g.byline||"",siteName:g.siteName||"",lang:g.lang||"",title:g.title||e,snippet:g.excerpt,content:h,contentChars:h.length,source:"chrome",duration:Date.now()-n}}catch(a){return{url:e,error:a.message,source:"chrome",duration:Date.now()-n,needsFallback:!0}}}function nr(t){try{return new URL(t).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function wa(t,e=8000){let r=Ye(t);if(r.blocked)return{url:t,finalUrl:t,status:403,error:`Blocked: ${r.reason}`,source:"pdf-http"};let n=new AbortController,a=setTimeout(()=>n.abort(),20000),l=Date.now();try{let i=await fetch(t,{method:"GET",redirect:"follow",signal:n.signal,headers:_n({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(a);let f=i.headers.get("content-type")||"",o=i.url||t,g=Number.parseInt(i.headers.get("content-length")||"0",10);if(i.status>=400)return{url:t,finalUrl:o,status:i.status,error:`HTTP ${i.status}`,source:"pdf-http",duration:Date.now()-l};if(!f.toLowerCase().includes("application/pdf")&&!nr(o))return null;if(g>31457280)return{url:t,finalUrl:o,status:i.status,error:`PDF too large: ${g} bytes`,source:"pdf-http",duration:Date.now()-l};let p=Buffer.from(await i.arrayBuffer()),h=await pa(p,o);if(!h||h.error)return{url:t,finalUrl:o,status:i.status,error:h?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-l};let m=q(h.content,e);return{url:t,finalUrl:o,status:i.status,contentType:"application/pdf",lastModified:i.headers.get("last-modified")||"",title:h.title,snippet:rr(m,320),content:m,contentChars:m.length,pages:h.pages,source:"pdf-http",duration:Date.now()-l}}catch(i){return clearTimeout(a),{url:t,finalUrl:t,error:i.message||String(i),source:"pdf-http",duration:Date.now()-l}}}async function ar(t,e=8000){let r=Date.now();if(nr(t)){let a=await wa(t,e);if(a?.content||a?.status===403)return a}if(
|
|
275
|
+
${a}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function rr(t="",e=240){let r=String(t).replaceAll(/\s+/g," ").trim();if(r.length<=e)return r;let n=r.slice(0,e),a=n.lastIndexOf(" ");return a>0?`${n.slice(0,a)}...`:`${n}...`}async function ha(t,e,r=8000){let n=Date.now();try{let a=(await P(["evalraw",t,"Page.getFrameTree","{}"]).then((m)=>JSON.parse(m)).catch(()=>null))?.frameTree?.frame?.id||void 0,l=await P(["evalraw",t,"Network.loadNetworkResource",JSON.stringify({frameId:a,url:e,options:{disableCache:!0,includeCredentials:!1}})],20000),i=JSON.parse(l).resource;if(!i?.success||!i.httpStatusCode)return{url:e,error:i?.netErrorName||i?.netError||"loadNetworkResource failed",source:"chrome",duration:Date.now()-n,needsFallback:!0};let f="";if(i.stream)try{let m=await P(["evalraw",t,"IO.read",JSON.stringify({handle:i.stream})],1e4);f=JSON.parse(m).data||"",await P(["evalraw",t,"IO.close",JSON.stringify({handle:i.stream})]).catch(()=>{})}catch{}if(!f||f.length<100)return{url:e,error:"Empty response body from Network.loadNetworkResource",source:"chrome",duration:Date.now()-n,needsFallback:!0};let o=Ge(i.httpStatusCode,f,e,e);if(o.blocked)return{url:e,status:i.httpStatusCode,error:`Blocked: ${o.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let g=Ve(f,e),p=de(g);if(!p.ok)return{url:e,status:i.httpStatusCode,error:`Low quality: ${p.reason}`,source:"chrome",duration:Date.now()-n,needsBrowser:!0};let h=q(g.markdown,r);return{url:e,finalUrl:e,status:i.httpStatusCode,contentType:"text/markdown",lastModified:"",publishedTime:g.publishedTime||"",byline:g.byline||"",siteName:g.siteName||"",lang:g.lang||"",title:g.title||e,snippet:g.excerpt,content:h,contentChars:h.length,source:"chrome",duration:Date.now()-n}}catch(a){return{url:e,error:a.message,source:"chrome",duration:Date.now()-n,needsFallback:!0}}}function nr(t){try{return new URL(t).pathname.toLowerCase().endsWith(".pdf")}catch{return!1}}async function wa(t,e=8000){let r=Ye(t);if(r.blocked)return{url:t,finalUrl:t,status:403,error:`Blocked: ${r.reason}`,source:"pdf-http"};let n=new AbortController,a=setTimeout(()=>n.abort(),20000),l=Date.now();try{let i=await fetch(t,{method:"GET",redirect:"follow",signal:n.signal,headers:_n({accept:"application/pdf,application/octet-stream;q=0.9,*/*;q=0.5"})});clearTimeout(a);let f=i.headers.get("content-type")||"",o=i.url||t,g=Number.parseInt(i.headers.get("content-length")||"0",10);if(i.status>=400)return{url:t,finalUrl:o,status:i.status,error:`HTTP ${i.status}`,source:"pdf-http",duration:Date.now()-l};if(!f.toLowerCase().includes("application/pdf")&&!nr(o))return null;if(g>31457280)return{url:t,finalUrl:o,status:i.status,error:`PDF too large: ${g} bytes`,source:"pdf-http",duration:Date.now()-l};let p=Buffer.from(await i.arrayBuffer()),h=await pa(p,o);if(!h||h.error)return{url:t,finalUrl:o,status:i.status,error:h?.error||"PDF text extraction failed",source:"pdf-http",duration:Date.now()-l};let m=q(h.content,e);return{url:t,finalUrl:o,status:i.status,contentType:"application/pdf",lastModified:i.headers.get("last-modified")||"",title:h.title,snippet:rr(m,320),content:m,contentChars:m.length,pages:h.pages,source:"pdf-http",duration:Date.now()-l}}catch(i){return clearTimeout(a),{url:t,finalUrl:t,error:i.message||String(i),source:"pdf-http",duration:Date.now()-l}}}async function ar(t,e=8000){let r=Date.now();if(nr(t)){let a=await wa(t,e);if(a?.content||a?.status===403)return a}if(Gt(t)){let a=Gt(t);if(a&&(a.type==="root"||a.type==="tree"||a.type==="blob"&&!a.path?.includes("."))){let l=await On(t);if(l.ok){let i=q(l.content,e);return{url:t,finalUrl:t,status:200,contentType:"text/markdown",lastModified:"",title:l.title,snippet:i.slice(0,320),content:i,contentChars:i.length,source:"github-api",...l.tree&&{tree:l.tree},duration:Date.now()-r}}process.stderr.write(`[greedysearch] GitHub API fetch failed, trying HTTP: ${l.error}
|
|
276
276
|
`)}}if(Ln(t)?.type==="post"){process.stderr.write(`[greedysearch] Using Reddit JSON API for: ${t.slice(0,60)}...
|
|
277
277
|
`);let a=await Wn(t,e);if(a.ok){let l=q(a.markdown,e);return{url:t,finalUrl:a.finalUrl,status:a.status,contentType:"text/markdown",lastModified:a.lastModified||"",publishedTime:a.publishedTime||"",byline:a.byline||"",siteName:a.siteName||"",lang:a.lang||"",title:a.title,snippet:a.excerpt,content:l,contentChars:l.length,source:"reddit-api",duration:Date.now()-r}}process.stderr.write(`[greedysearch] Reddit API fetch failed, falling back to HTTP: ${a.error}
|
|
278
|
-
`)}let n=await sn(t,{timeoutMs:1e4});if(n.ok){let a=q(n.markdown,e);return{url:t,finalUrl:n.finalUrl,status:n.status,contentType:"text/markdown",lastModified:n.lastModified||"",publishedTime:n.publishedTime||"",byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",title:n.title,snippet:n.excerpt,content:a,contentChars:a.length,source:"http",duration:Date.now()-r}}if(n.needsBrowser)try{let a=await
|
|
279
|
-
`),await $a(t,e)}async function $a(t,e=8000){let r=Date.now(),n;try{n=await
|
|
278
|
+
`)}let n=await sn(t,{timeoutMs:1e4});if(n.ok){let a=q(n.markdown,e);return{url:t,finalUrl:n.finalUrl,status:n.status,contentType:"text/markdown",lastModified:n.lastModified||"",publishedTime:n.publishedTime||"",byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",title:n.title,snippet:n.excerpt,content:a,contentChars:a.length,source:"http",duration:Date.now()-r}}if(n.needsBrowser)try{let a=await Qt();try{let l=await ha(a,t,e);if(l.content&&l.content.length>100)return l}finally{await zt(a)}}catch{}return process.stderr.write(`[greedysearch] HTTP failed for ${t.slice(0,60)}, trying browser...
|
|
279
|
+
`),await $a(t,e)}async function $a(t,e=8000){let r=Date.now(),n;try{n=await Qt()}catch(a){return{url:t,title:"",content:null,snippet:"",contentChars:0,error:`openNewTab failed: ${a.message}`,source:"browser",duration:Date.now()-r}}try{await P(["nav",n,t],30000),await new Promise((f)=>setTimeout(f,800));let a=await P(["eval",n,String.raw`
|
|
280
280
|
(function(){
|
|
281
281
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
282
282
|
var text = (el || document.body).innerText;
|
|
@@ -286,19 +286,19 @@ ${a}`,pages:n.total}}catch(r){return{error:r.message||String(r)}}}function rr(t=
|
|
|
286
286
|
url: location.href
|
|
287
287
|
});
|
|
288
288
|
})()
|
|
289
|
-
`]),l=JSON.parse(a),i=q(l.content,e);return{url:t,finalUrl:l.url||t,status:200,contentType:"text/plain",lastModified:"",title:l.title,snippet:rr(i,320),content:i,contentChars:i.length,source:"browser",duration:Date.now()-r}}catch(a){return{url:t,title:"",content:null,snippet:"",contentChars:0,error:a.message,source:"browser",duration:Date.now()-r}}finally{await
|
|
289
|
+
`]),l=JSON.parse(a),i=q(l.content,e);return{url:t,finalUrl:l.url||t,status:200,contentType:"text/plain",lastModified:"",title:l.title,snippet:rr(i,320),content:i,contentChars:i.length,source:"browser",duration:Date.now()-r}}catch(a){return{url:t,title:"",content:null,snippet:"",contentChars:0,error:a.message,source:"browser",duration:Date.now()-r}}finally{await zt(n)}}async function ca(t,e=5,r=8000,n=Re){let a=t.slice(0,e);if(a.length===0)return[];let l=Math.min(a.length,Math.max(1,Number.parseInt(String(n),10)||Re));process.stderr.write(`[greedysearch] Fetching content from ${a.length} sources via HTTP (concurrency ${l})...
|
|
290
290
|
`);let i=Array(a.length),f=0,o=0;async function g(){while(!0){let c=f++;if(c>=a.length)return;let y=a[c],b=y.canonicalUrl||y.url;process.stderr.write(`[greedysearch] [${c+1}/${a.length}] Fetching: ${b.slice(0,60)}...
|
|
291
291
|
`);let w=await ar(b,r).catch((k)=>({url:b,title:"",content:null,snippet:"",contentChars:0,error:k.message,source:"error",duration:0}));if(i[c]={id:y.id,...w},w.content&&w.content.length>100)process.stderr.write(`[greedysearch] ✓ ${w.source}: ${w.content.length} chars
|
|
292
292
|
`);else if(w.error)process.stderr.write(`[greedysearch] ✗ ${w.error.slice(0,80)}
|
|
293
293
|
`);o+=1,process.stderr.write(`PROGRESS:fetch:${o}/${a.length}
|
|
294
294
|
`)}}await Promise.all(Array.from({length:l},()=>g()));let p=i.filter((c)=>c.content&&c.content.length>100),h=i.filter((c)=>c.source==="http").length,m=i.filter((c)=>c.source==="browser").length;return process.stderr.write(`[greedysearch] Fetched ${p.length}/${i.length} sources (HTTP: ${h}, Browser: ${m})
|
|
295
|
-
`),i}async function ma(t){let e=await
|
|
295
|
+
`),i}async function ma(t){let e=await Qt();await P(["list"]);try{await P(["nav",e,t],30000),await new Promise((n)=>setTimeout(n,800));let r=await P(["eval",e,String.raw`
|
|
296
296
|
(function(){
|
|
297
297
|
var el = document.querySelector('article, [role="main"], main, .post-content, .article-body, #content, .content');
|
|
298
298
|
var text = (el || document.body).innerText;
|
|
299
299
|
return text.replace(/\s+/g, ' ').trim();
|
|
300
300
|
})()
|
|
301
|
-
`]);return{url:t,content:r}}catch(r){return{url:t,content:null,error:r.message}}finally{await
|
|
301
|
+
`]);return{url:t,content:r}}catch(r){return{url:t,content:null,error:r.message}}finally{await zt(e)}}var gi,Je,He="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",Fe,yn,vn,jn,Dn,Ze,Pn,Xn,xn,Qe,Oi,Pi,Li,Wi,Vt,V,dt,Zt="gemini",We,Ht,Mi,Ai,Ri,ze,Ji,Hi,Fi,Yi,Bt,d,Kt,Ut="gemini",Me,Ft,Gi,Vi,di,at,Zi,Bi,Ki,Ui,Ii,Xi,xi,Se,Qi,zi,Si,ui,P,er,nf,af,lf,ff,It,Z,Xt,xt="gemini",Ae,Yt,gf,of,Re;var ir=gt(()=>{gi=$n(import.meta.url),Je=new bn({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});Je.addRule("removeDataUrls",{filter:(t)=>t.tagName==="IMG"&&t.getAttribute("src")?.startsWith("data:"),replacement:()=>""});Fe={"user-agent":He,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},yn=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i];vn=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],jn=["login.","signin.","auth.","sso.","accounts.","idp."],Dn=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"];Ze={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"};Pn={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};Xn=Jn(Fn(import.meta.url)),xn=Hn(Xn,"..","bin","cdp.mjs");Qe=`${_t().replaceAll("\\","/")}/greedysearch-chrome-profile`,Oi=`${Qe}/DevToolsActivePort`,Pi=`${_t().replaceAll("\\","/")}/cdp-pages.json`,Li=`${_t().replaceAll("\\","/")}/greedysearch-chrome-mode`,Wi=`${_t().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Vt=Ue(dn(),".dm"),V=Ue(Vt,"greedyconfig"),dt=["perplexity","google","chatgpt"];Sn();We=["gemini","chatgpt"];Ht={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"},Mi=zn(),Ai=un(),Ri=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=Qe;ze=`${kt().replaceAll("\\","/")}/greedysearch-chrome-profile`,Ji=`${ze}/DevToolsActivePort`,Hi=`${kt().replaceAll("\\","/")}/cdp-pages.json`,Fi=`${kt().replaceAll("\\","/")}/greedysearch-chrome-mode`,Yi=`${kt().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Bt=Xe(Un(),".dm"),d=Xe(Bt,"greedyconfig"),Kt=["perplexity","google","chatgpt"];ta();Me=["gemini","chatgpt"];Ft={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"},Gi=qn(),Vi=ea(),di=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=ze;at=Zn().replaceAll("\\","/"),Zi=`${at}/greedysearch-chrome-metadata.json`,Bi=`${at}/greedysearch-chrome-launch.lock`,Ki=`${at}/greedysearch-chrome.pid`,Ui=`${at}/greedysearch-chrome-mode`,Ii=`${at}/greedysearch-chrome-last-activity`,Xi=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,xi=import.meta.dirname||new URL(".",import.meta.url).pathname.replace(/^\/([A-Z]:)/,"$1"),Se=An().replaceAll("\\","/"),Qi=`${Se}/greedysearch-chrome.pid`,zi=`${Se}/greedysearch-chrome-last-activity`,Si=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5,ui=Number.parseInt(process.env.GREEDY_SEARCH_VISIBLE_IDLE_TIMEOUT_MINUTES||"60",10)||60,P=xe;er=`${st().replaceAll("\\","/")}/greedysearch-chrome-profile`,nf=`${er}/DevToolsActivePort`,af=`${st().replaceAll("\\","/")}/cdp-pages.json`,lf=`${st().replaceAll("\\","/")}/greedysearch-chrome-mode`,ff=`${st().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,It=tr(aa(),".dm"),Z=tr(It,"greedyconfig"),Xt=["perplexity","google","chatgpt"];ia();Ae=["gemini","chatgpt"];Yt={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"},gf=la(),of=fa(),Re=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=er});var gr={};et(gr,{writeSourcesToFiles:()=>ka});import{mkdirSync as ba,writeFileSync as ya}from"node:fs";import{join as fr}from"node:path";function ka(t,e=_a){return ba(e,{recursive:!0}),t.map((r)=>{if(!r.content||r.content.length<10)return r;let n=String(r.id||"unknown").replace(/[^a-zA-Z0-9_-]/g,""),a=(r.canonicalUrl||r.url||"").replace(/^https?:\/\//,"").replace(/[^a-zA-Z0-9]/g,"-").slice(0,40),l=`${n}-${a}.md`,i=fr(e,l),f=`---
|
|
302
302
|
url: ${r.finalUrl||r.url}
|
|
303
303
|
title: ${r.title||""}
|
|
304
304
|
source: ${r.source||"unknown"}
|
|
@@ -306,7 +306,7 @@ status: ${r.status||""}
|
|
|
306
306
|
chars: ${r.contentChars||r.content.length}
|
|
307
307
|
---
|
|
308
308
|
|
|
309
|
-
`;ya(i,f+r.content,"utf8");let{content:o,...g}=r;return{...g,contentPath:i,contentChars:r.contentChars||o.length}})}var _a;var or=gt(()=>{_a=fr(process.cwd(),".dm","greedysearch-sources")});var
|
|
309
|
+
`;ya(i,f+r.content,"utf8");let{content:o,...g}=r;return{...g,contentPath:i,contentChars:r.contentChars||o.length}})}var _a;var or=gt(()=>{_a=fr(process.cwd(),".dm","greedysearch-sources")});var St={};et(St,{parseGitHubUrl:()=>wr,fetchGitHubContent:()=>ja});function wr(t){try{let e=new URL(t);if(!(e.hostname==="github.com"||e.hostname.endsWith(".github.com")))return null;let r=e.pathname.split("/").filter(Boolean);if(r.length<2)return null;let[n,a]=r;if(r.length===2)return{owner:n,repo:a,type:"root"};if(r.length>=4&&(r[2]==="blob"||r[2]==="tree")){let l=r[2],i=r[3],f=r.slice(4).join("/");return{owner:n,repo:a,type:l,ref:i,path:f}}return null}catch{return null}}async function U(t,e=1e4){let r=new AbortController,n=setTimeout(()=>r.abort(),e);try{let a=await fetch(`https://api.github.com${t}`,{headers:hr,signal:r.signal});if(clearTimeout(n),!a.ok)throw Error(`GitHub API ${a.status}: ${t}`);return await a.json()}catch(a){throw clearTimeout(n),a}}async function sa(t,e){try{let r=await U(`/repos/${t}/${e}/readme`);if(r.content&&r.encoding==="base64")return Buffer.from(r.content,"base64").toString("utf8");return""}catch{return""}}async function pr(t,e,r="HEAD",n=""){try{let a=await U(`/repos/${t}/${e}/git/ref/heads/${r==="HEAD"?"main":r}`).catch(()=>U(`/repos/${t}/${e}/git/ref/heads/master`).catch(()=>null)),l;if(a?.object?.sha)l=(await U(`/repos/${t}/${e}/git/commits/${a.object.sha}`)).tree.sha;else{let f=await U(`/repos/${t}/${e}`);l=(await U(`/repos/${t}/${e}/branches/${f.default_branch}`)).commit.commit.tree.sha}let i=(await U(`/repos/${t}/${e}/git/trees/${l}`)).tree||[];if(n)i=i.filter((f)=>f.path.startsWith(n));return i.slice(0,50).map((f)=>({path:f.path,type:f.type==="tree"?"dir":"file",size:f.size}))}catch{return[]}}async function va(t,e,r,n,a=1e4){let l=[`https://raw.githubusercontent.com/${t}/${e}/${r&&r!=="HEAD"?r:"main"}/${n}`,`https://raw.githubusercontent.com/${t}/${e}/master/${n}`];for(let i of l){let f=new AbortController,o=setTimeout(()=>f.abort(),a);try{let g=await fetch(i,{headers:{"user-agent":hr["user-agent"]},signal:f.signal});if(clearTimeout(o),g.ok)return await g.text()}catch{clearTimeout(o)}}return null}async function ja(t){let e=wr(t);if(!e)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:r,repo:n,type:a,ref:l,path:i}=e;try{if(a==="root"||a==="tree"&&!i){let[f,o,g]=await Promise.allSettled([U(`/repos/${r}/${n}`),sa(r,n),pr(r,n,l||"HEAD")]);if(f.status==="rejected")return{ok:!1,error:f.reason?.message||"Repo not found"};let p=f.value,h=o.status==="fulfilled"?o.value:"",m=g.status==="fulfilled"?g.value:[],c=p?.description?`
|
|
310
310
|
|
|
311
311
|
> ${p.description}`:"",y=p?.stargazers_count==null?"":` ⭐ ${p.stargazers_count}`,b=p?.language?` · ${p.language}`:"",w=`# ${r}/${n}${y}${b}${c}
|
|
312
312
|
|
|
@@ -318,7 +318,7 @@ ${m.map((k)=>` ${k.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${k.path}`).join
|
|
|
318
318
|
`);return{ok:!0,title:`${r}/${n}/${i}`,content:`[Directory: ${i}]
|
|
319
319
|
|
|
320
320
|
Files:
|
|
321
|
-
${o}`,tree:f}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(f){return{ok:!1,error:f.message}}}var hr;var
|
|
321
|
+
${o}`,tree:f}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(f){return{ok:!1,error:f.message}}}var hr;var ut=gt(()=>{hr={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"}});var qt={};et(qt,{truncateContent:()=>Ca,trimContentHeadTail:()=>Ea});function Ea(t,e=8000){if(!t||t.length<=e)return t;let r=`
|
|
322
322
|
|
|
323
323
|
[...content trimmed...]
|
|
324
324
|
|
|
@@ -326,16 +326,16 @@ ${o}`,tree:f}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(f){return{
|
|
|
326
326
|
`)i--;if(i<=a-100)i=a;let f=t.length-l;while(f<t.length-l+100&&t[f]!==`
|
|
327
327
|
`)f++;if(f>=t.length-l+100)f=t.length-l;let o=t.slice(0,i).trimEnd(),g=t.slice(f).trimStart();return`${o}${r}${g}`}function Ca(t,e=8000){if(!t||t.length<=e)return t;let r=t.slice(0,e),n=r.lastIndexOf(" ");return n>0?`${r.slice(0,n)}...`:`${r}...`}var jr={};et(jr,{shouldUseBrowser:()=>Fa,rewriteGitHubUrl:()=>_r,isPrivateUrl:()=>yr,fetchSourceHttp:()=>Wa,extractContent:()=>sr,detectBotBlock:()=>kr,defaultFetchHeaders:()=>La,checkContentQuality:()=>vr});import{Readability as Na}from"@mozilla/readability";import{JSDOM as Ta}from"jsdom";import Oa from"turndown";function La(t={}){return{...br,...t}}function yr(t){try{let e=new URL(t),r=e.hostname.toLowerCase();for(let n of Pa)if(n.test(r))return{blocked:!0,reason:`Private/internal address: ${r}`};if(e.protocol==="file:")return{blocked:!0,reason:"File protocol not allowed"};return{blocked:!1}}catch(e){return{blocked:!0,reason:`Invalid URL: ${e.message}`}}}function _r(t){try{let e=new URL(t);if(!(e.hostname==="github.com"||e.hostname.endsWith(".github.com")))return t;let r=e.pathname.split("/").filter(Boolean);if(r.length<5)return t;let[n,a,l,i,...f]=r;if(l!=="blob")return t;let o=f.join("/");return`https://raw.githubusercontent.com/${n}/${a}/${i}/${o}`}catch{return t}}async function Wa(t,e={}){let r=yr(t);if(r.blocked)return{ok:!1,url:t,finalUrl:t,status:403,error:`Blocked: ${r.reason}`,needsBrowser:!1};let n=t;if(t=_r(t),t!==n)console.error(`[fetcher] Rewrote GitHub URL: ${n.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:a=15000,userAgent:l,signal:i}=e,f=new AbortController,o=setTimeout(()=>f.abort(),a);if(i)i.addEventListener("abort",()=>f.abort(),{once:!0});try{let g=await fetch(t,{method:"GET",headers:{...br,"user-agent":l||mr},redirect:"follow",signal:f.signal});clearTimeout(o);let p=g.headers.get("content-type")||"",h=g.url,m=g.headers.get("last-modified")||"",c=!1;try{c=new URL(h).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(p.includes("text/plain")&&c){let C=await g.text();return{ok:!0,url:n,finalUrl:h,status:g.status,title:h.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:m,lastModified:m,markdown:C,contentLength:C.length,excerpt:C.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!p.includes("text/html")&&!p.includes("application/xhtml"))return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Unsupported content type: ${p}`,needsBrowser:!1};let y=await g.text(),b=kr(g.status,y,h,t);if(b.blocked)return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Blocked: ${b.reason}`,needsBrowser:!0};let w=sr(y,h),k=vr(w);if(!k.ok)return{ok:!1,url:t,finalUrl:h,status:g.status,error:`Low quality content: ${k.reason}`,needsBrowser:!0};return{ok:!0,url:t,finalUrl:h,status:g.status,title:w.title,byline:w.byline,siteName:w.siteName,lang:w.lang,publishedTime:w.publishedTime||m,lastModified:m,markdown:w.markdown,excerpt:w.excerpt,contentLength:w.markdown.length,needsBrowser:!1}}catch(g){clearTimeout(o);let p=Ha(g);return{ok:!1,url:t,finalUrl:t,status:0,error:g.message,needsBrowser:p}}}function kr(t,e,r,n){let a=e.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",l=e.slice(0,30000).toLowerCase(),i=`${a} ${l}`;if(t===403||t===429||t===503)return{blocked:!0,reason:`HTTP ${t}`};let f=[{pattern:/class=["'][^"']*captcha["']|<div[^>]*id=["']captcha/i,reason:"captcha"},{pattern:/g-recaptcha|data-sitekey|i['"]m not a robot/i,reason:"captcha"},{pattern:/checking your browser.{0,100}please wait|cf-browser-verification/i,reason:"cloudflare challenge"},{pattern:/just a moment.{0,50}security check|ddos protection by cloudflare/i,reason:"cloudflare challenge"},{pattern:/unusual traffic.{0,50}from your computer network/i,reason:"unusual traffic"},{pattern:/bot detected|automated.{0,20}request/i,reason:"bot detection"},{pattern:/enable\s+javascript\s+to\s+view|javascript\s+is\s+required.{0,50}enabled/i,reason:"requires javascript"},{pattern:/access denied|accessdenied/i,reason:"access denied"},{pattern:/protected by anubis|anubis uses a proof-of-work/i,reason:"anubis challenge"}];for(let g of f)if(g.pattern.test(i))return{blocked:!0,reason:g.reason};let o=Ja(n,r,e);if(o)return{blocked:!0,reason:o};return{blocked:!1}}function Ja(t,e,r){try{let n=new URL(t),a=new URL(e);if(n.hostname.toLowerCase()===a.hostname.toLowerCase())return;let l=a.hostname.toLowerCase();if(Ma.some((f)=>l===f||l.endsWith(`.${f}`)))return`redirected to login (${a.hostname})`;if(Aa.some((f)=>l.startsWith(f)))return`redirected to login (${a.hostname})`;let i=r.slice(0,20000).toLowerCase();if(Ra.some((f)=>i.includes(f)))return`redirected to login page (${a.hostname})`}catch{}return}function Ha(t){let e=t.message.toLowerCase();return e.includes("fetch failed")||e.includes("unable to verify")||e.includes("certificate")||e.includes("timeout")}function $r(t){let e=['meta[property="article:published_time"]','meta[name="article:published_time"]','meta[property="og:published_time"]','meta[name="publication_date"]','meta[name="date"]','meta[itemprop="datePublished"]','time[itemprop="datePublished"]','meta[name="DC.date"]'];for(let r of e){let n=t.querySelector(r),a=n?.getAttribute("content")||n?.getAttribute("datetime")||"";if(a)return a}return""}function sr(t,e){let r=new Ta(t,{url:e}).window.document,n=new Na(r).parse();if(n&&n.content){let l=cr.turndown(n.content).replaceAll(/\n{3,}/g,`
|
|
328
328
|
|
|
329
|
-
`).trim(),i=n.publishedTime||$r(r)||"";return{title:n.title||r.title||e,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:i,markdown:l,excerpt:l.slice(0,300).replaceAll(/\n/g," ")}}let a=r.body;if(a){let l=a.cloneNode(!0);l.querySelectorAll("script, style, nav, footer, header, aside").forEach((f)=>f.remove());let i=(l.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||e,byline:"",siteName:"",lang:"",publishedTime:$r(r),markdown:i,excerpt:i.slice(0,300)}}return{title:e,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function vr(t){let e=t.markdown.trim().toLowerCase(),r=(t.title||"").toLowerCase();if(t.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let n=e.toLowerCase(),a=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(e),desc:"login form only"}];for(let{check:l,desc:i}of a)if(l())return{ok:!1,reason:i};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}function Fa(t){try{let e=new URL(t),r=e.hostname.toLowerCase(),n=e.pathname.toLowerCase();if(["react.dev","nextjs.org","vuejs.org","angular.io","svelte.dev","docs.expo.dev","tailwindcss.com","storybook.js.org"].some((a)=>r===a||r.endsWith(`.${a}`)))return!0;if(n.includes("/playground")||n.includes("/demo")||n.includes("/app"))return!0;if(e.hash&&e.hash.length>1)return!0;return!1}catch{return!1}}var cr,mr="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",br,Pa,Ma,Aa,Ra;var Dr=gt(()=>{cr=new Oa({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});cr.addRule("removeDataUrls",{filter:(t)=>t.tagName==="IMG"&&t.getAttribute("src")?.startsWith("data:"),replacement:()=>""});br={"user-agent":mr,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},Pa=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i];Ma=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],Aa=["login.","signin.","auth.","sso.","accounts.","idp."],Ra=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"]});import{spawn as Ya}from"node:child_process";import{existsSync as Ga,mkdirSync as qt,writeFileSync as W}from"node:fs";import{join as D}from"node:path";import{fileURLToPath as Va}from"node:url";var Zr=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],Br=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],Kr=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],_e=["facebook.com","instagram.com","linkedin.com","pinterest.com","tiktok.com","twitter.com","x.com"];function T(t="",e=240){let r=String(t).replaceAll(/\s+/g," ").trim();if(r.length<=e)return r;let n=r.slice(0,e),a=n.lastIndexOf(" ");return a>0?`${n.slice(0,a)}...`:`${n}...`}function Nt(t=""){let e=T(t,180);if(!e)return"";if(/^https?:\/\//i.test(e))return"";let r=e.split(/\s+/).filter(Boolean).length,n=/[A-Z]/.test(e),a=/\d/.test(e);return e===e.toLowerCase()&&r<=4&&!n&&!a?"":e}function Tt(t="",e=""){let r=Nt(t),n=Nt(e);if(!n)return r;if(!r)return n;let a=/^https?:\/\//i.test(r),l=/^https?:\/\//i.test(n);if(a&&!l)return n;if(!a&&l)return r;return n.length>r.length?n:r}function M(t){if(!t)return null;try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return null;if(e.hash="",e.hostname=e.hostname.toLowerCase(),e.protocol==="https:"&&e.port==="443"||e.protocol==="http:"&&e.port==="80")e.port="";for(let a of[...e.searchParams.keys()]){let l=a.toLowerCase();if(Zr.includes(l)||l.startsWith("utm_"))e.searchParams.delete(a)}e.searchParams.sort();let r=e.pathname.replace(/\/{1,10}$/,"")||"/";e.pathname=r;let n=e.toString();return r==="/"?n.replace(/\/$/,""):n}catch{return null}}function Ur(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function rt(t,e){return e.some((r)=>t===r||t.endsWith(`.${r}`))}function Ot(t,e="",r=""){let n=e.toLowerCase(),a=r.toLowerCase();if(t==="github.com"||t==="gitlab.com")return"repo";if(t==="arxiv.org"||t==="doi.org"||t==="semanticscholar.org"||t.endsWith(".semanticscholar.org")||a.includes("/paper/")||a.includes("/pdf/"))return"academic";if(rt(t,_e))return"social";if(rt(t,Br))return"community";if(rt(t,Kr))return"news";if(t.startsWith("docs.")||t.startsWith("developer.")||t.startsWith("developers.")||t.startsWith("api.")||n.includes("documentation")||n.includes("docs")||n.includes("reference")||a.includes("/docs/")||a.includes("/reference/")||a.includes("/api/"))return"official-docs";if(t.startsWith("blog.")||a.includes("/blog/"))return"maintainer-blog";return"website"}function Ir(t){switch(t){case"official-docs":return 5;case"repo":return 4;case"academic":return 4;case"maintainer-blog":return 3;case"website":return 2;case"community":return 1;case"news":return 0;case"social":return-6;default:return 0}}function Xr(t){let e=Object.values(t.perEngine||{}).map((r)=>r?.rank||99);return e.length?Math.min(...e):99}var xr=["reddit.com","news.ycombinator.com","lobste.rs"];function X(t){return t.smartScore*3+t.engineCount*5+Ir(t.sourceType)*2+Math.max(0,7-Xr(t))}function Qr(t){let e=t.toLowerCase(),r=[];if(e.includes("openai")||e.includes("gpt")||e.includes("chatgpt"))r.push("openai.com","platform.openai.com","help.openai.com");if(e.includes("anthropic")||e.includes("claude"))r.push("anthropic.com","docs.anthropic.com");if(e.includes("bun"))r.push("bun.sh","bun.com");if(e.includes("next.js")||e.includes("nextjs"))r.push("nextjs.org","vercel.com");if(e.includes("playwright"))r.push("playwright.dev");if(e.includes("supabase"))r.push("supabase.com","supabase.io");if(e.includes("prisma"))r.push("prisma.io");if(e.includes("tailwind"))r.push("tailwindcss.com");if(e.includes("vite"))r.push("vitejs.dev","vite.dev");if(e.includes("astro"))r.push("astro.build");if(e.includes("svelte"))r.push("svelte.dev");if(e.includes("solid"))r.push("solidjs.com");if(e.includes("vue")||e.includes("nuxt"))r.push("vuejs.org","nuxt.com");if(e.includes("react")||e.includes("react native"))r.push("react.dev","reactnative.dev");if(e.includes("angular"))r.push("angular.io","angular.dev");if(e.includes("node.js")||e.includes("nodejs"))r.push("nodejs.org","nodejs.dev","npmjs.com");if(/\bgo\b/.test(e)||e.includes("golang"))r.push("go.dev","golang.org","pkg.go.dev");if(e.includes("deno"))r.push("deno.land","deno.com");if(e.includes("fresh"))r.push("fresh.deno.dev");if(e.includes("typescript")||e.includes("ts"))r.push("typescriptlang.org");if(e.includes("python"))r.push("python.org","docs.python.org");if(e.includes("rust"))r.push("rust-lang.org","docs.rs","crates.io");if(e.includes("zig"))r.push("ziglang.org");if(e.includes("docker"))r.push("docker.com","docs.docker.com","hub.docker.com");if(e.includes("kubernetes")||e.includes("k8s"))r.push("kubernetes.io","k8s.io");if(e.includes("postgres")||e.includes("postgresql"))r.push("postgresql.org","neon.tech","supabase.com");if(e.includes("redis"))r.push("redis.io");if(e.includes("sqlite"))r.push("sqlite.org");if(e.includes("cloudflare"))r.push("developers.cloudflare.com","cloudflare.com");if(e.includes("vercel"))r.push("vercel.com","nextjs.org");if(e.includes("netlify"))r.push("netlify.com","docs.netlify.com");if(e.includes("stripe"))r.push("stripe.com","docs.stripe.com");if(e.includes("github"))r.push("github.com","docs.github.com");if(e.includes("gitlab"))r.push("gitlab.com","docs.gitlab.com");if(e.includes("aws"))r.push("aws.amazon.com","docs.aws.amazon.com");if(e.includes("azure"))r.push("azure.microsoft.com","learn.microsoft.com");if(e.includes("gcp")||e.includes("google cloud"))r.push("cloud.google.com","developers.google.com");if(e.includes("gemini")||e.includes("google ai"))r.push("ai.google.dev","developers.google.com");for(let n of _e){let a=n.replace(/\.com$/,"");if(e.includes(a))r.push(n)}return[...new Set(r)]}function ye(t,e){return t===e||t.endsWith(`.${e}`)}function Pt(t,e=""){let r=new Map,n=Object.keys(t||{}).filter((g)=>!g.startsWith("_")),a=Qr(e);for(let g of n){let p=t[g];if(!p?.sources)continue;for(let h=0;h<p.sources.length;h++){let m=p.sources[h],c=M(m.url);if(!c||c.length<10)continue;let y=Nt(m.title||""),b=Ur(c),w=Ot(b,y,c),k=0;if(a.some((N)=>ye(b,N)))k+=10;if(w==="official-docs")k+=3;let C=c.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(C))k+=2;let _=a.some((N)=>ye(b,N));if(w==="social"&&!_)k-=20;if(a.length>0){if(rt(b,xr))k-=3;else if(w==="community"&&!rt(b,["stackoverflow.com","stackexchange.com"]))k-=1}let s=r.get(c)||{id:"",canonicalUrl:c,displayUrl:m.url||c,domain:b,title:"",engines:[],engineCount:0,perEngine:{},sourceType:w,isOfficial:w==="official-docs",smartScore:0};if(s.title=Tt(s.title,y),s.displayUrl=s.displayUrl||m.url||c,s.sourceType=s.sourceType||w,s.isOfficial=s.isOfficial||w==="official-docs",s.smartScore=Math.max(s.smartScore,k),!s.engines.includes(g))s.engines.push(g);s.perEngine[g]={rank:h+1,title:Tt(s.perEngine[g]?.title||"",y)},r.set(c,s)}}let l=Array.from(r.values()).map((g)=>({...g,engineCount:g.engines.length})),i=l.filter((g)=>g.sourceType!=="social"),f=l.filter((g)=>g.sourceType==="social");return i.sort((g,p)=>{let h=X(p)-X(g);if(h!==0)return h;return g.domain.localeCompare(p.domain)}),f.sort((g,p)=>{let h=X(p)-X(g);if(h!==0)return h;return g.domain.localeCompare(p.domain)}),[...i,...f].slice(0,12).map((g,p)=>({...g,id:`S${p+1}`,title:g.title||g.domain||g.canonicalUrl}))}function ke(t,e){let r=new Map(e.map((n)=>[n.id,n]));return t.map((n)=>{let a=r.get(n.id);if(!a)return n;let l=Tt(n.title,a.title||"");return{...n,title:l||n.title,fetch:{attempted:!0,ok:!a.error&&a.contentChars>100,status:a.status||null,finalUrl:a.finalUrl||a.url||n.canonicalUrl,contentType:a.contentType||"",lastModified:a.lastModified||"",publishedTime:a.publishedTime||"",byline:a.byline||"",siteName:a.siteName||"",lang:a.lang||"",title:a.title||"",snippet:a.snippet||"",contentChars:a.contentChars||0,source:a.source||"unknown",duration:a.duration||0,error:a.error||""}}})}import{existsSync as ot,mkdirSync as zr,readFileSync as se,writeFileSync as Sr}from"node:fs";import{homedir as ur}from"node:os";import{join as ve}from"node:path";import{tmpdir as pt}from"node:os";var ht=`${pt().replaceAll("\\","/")}/greedysearch-chrome-profile`,Hl=`${ht}/DevToolsActivePort`,Fl=`${pt().replaceAll("\\","/")}/cdp-pages.json`,Yl=`${pt().replaceAll("\\","/")}/greedysearch-chrome-mode`,Gl=`${pt().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Wt=ve(ur(),".dm"),G=ve(Wt,"greedyconfig"),Mt=["perplexity","google","chatgpt"],At="gemini";function qr(){try{if(ot(G)){let t=se(G,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Lt[a]),n=e.engines.filter((a)=>!Lt[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${G}: ${n.join(", ")}
|
|
330
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
331
|
-
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${G}, falling back to defaults: ${
|
|
332
|
-
`)}}}catch{}return
|
|
333
|
-
`,"utf8")}catch{}}tn();var nt=["gemini","chatgpt"];function en(){try{if(ot(G)){let t=
|
|
329
|
+
`).trim(),i=n.publishedTime||$r(r)||"";return{title:n.title||r.title||e,byline:n.byline||"",siteName:n.siteName||"",lang:n.lang||"",publishedTime:i,markdown:l,excerpt:l.slice(0,300).replaceAll(/\n/g," ")}}let a=r.body;if(a){let l=a.cloneNode(!0);l.querySelectorAll("script, style, nav, footer, header, aside").forEach((f)=>f.remove());let i=(l.textContent||"").replaceAll(/\s+/g," ").trim();return{title:r.title||e,byline:"",siteName:"",lang:"",publishedTime:$r(r),markdown:i,excerpt:i.slice(0,300)}}return{title:e,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}function vr(t){let e=t.markdown.trim().toLowerCase(),r=(t.title||"").toLowerCase();if(t.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let n=e.toLowerCase(),a=[{check:()=>n.includes("loading")&&n.includes("please wait"),desc:"loading page"},{check:()=>n.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>n.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>n.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>n.includes("verify you are human"),desc:"human verification"},{check:()=>n.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>n.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(e),desc:"login form only"}];for(let{check:l,desc:i}of a)if(l())return{ok:!1,reason:i};if(r.includes("just a moment")||r.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}function Fa(t){try{let e=new URL(t),r=e.hostname.toLowerCase(),n=e.pathname.toLowerCase();if(["react.dev","nextjs.org","vuejs.org","angular.io","svelte.dev","docs.expo.dev","tailwindcss.com","storybook.js.org"].some((a)=>r===a||r.endsWith(`.${a}`)))return!0;if(n.includes("/playground")||n.includes("/demo")||n.includes("/app"))return!0;if(e.hash&&e.hash.length>1)return!0;return!1}catch{return!1}}var cr,mr="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",br,Pa,Ma,Aa,Ra;var Dr=gt(()=>{cr=new Oa({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});cr.addRule("removeDataUrls",{filter:(t)=>t.tagName==="IMG"&&t.getAttribute("src")?.startsWith("data:"),replacement:()=>""});br={"user-agent":mr,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},Pa=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i];Ma=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],Aa=["login.","signin.","auth.","sso.","accounts.","idp."],Ra=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"]});import{spawn as Ya}from"node:child_process";import{existsSync as Ga,mkdirSync as te,writeFileSync as W}from"node:fs";import{join as D}from"node:path";import{fileURLToPath as Va}from"node:url";var Zr=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],Br=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],Kr=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],ke=["facebook.com","instagram.com","linkedin.com","pinterest.com","tiktok.com","twitter.com","x.com"];function T(t="",e=240){let r=String(t).replaceAll(/\s+/g," ").trim();if(r.length<=e)return r;let n=r.slice(0,e),a=n.lastIndexOf(" ");return a>0?`${n.slice(0,a)}...`:`${n}...`}function Tt(t=""){let e=T(t,180);if(!e)return"";if(/^https?:\/\//i.test(e))return"";let r=e.split(/\s+/).filter(Boolean).length,n=/[A-Z]/.test(e),a=/\d/.test(e);return e===e.toLowerCase()&&r<=4&&!n&&!a?"":e}function Ot(t="",e=""){let r=Tt(t),n=Tt(e);if(!n)return r;if(!r)return n;let a=/^https?:\/\//i.test(r),l=/^https?:\/\//i.test(n);if(a&&!l)return n;if(!a&&l)return r;return n.length>r.length?n:r}function M(t){if(!t)return null;try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return null;if(e.hash="",e.hostname=e.hostname.toLowerCase(),e.protocol==="https:"&&e.port==="443"||e.protocol==="http:"&&e.port==="80")e.port="";for(let a of[...e.searchParams.keys()]){let l=a.toLowerCase();if(Zr.includes(l)||l.startsWith("utm_"))e.searchParams.delete(a)}e.searchParams.sort();let r=e.pathname.replace(/\/{1,10}$/,"")||"/";e.pathname=r;let n=e.toString();return r==="/"?n.replace(/\/$/,""):n}catch{return null}}function Ur(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function rt(t,e){return e.some((r)=>t===r||t.endsWith(`.${r}`))}function Pt(t,e="",r=""){let n=e.toLowerCase(),a=r.toLowerCase();if(t==="github.com"||t==="gitlab.com")return"repo";if(t==="arxiv.org"||t==="doi.org"||t==="semanticscholar.org"||t.endsWith(".semanticscholar.org")||a.includes("/paper/")||a.includes("/pdf/"))return"academic";if(rt(t,ke))return"social";if(rt(t,Br))return"community";if(rt(t,Kr))return"news";if(t.startsWith("docs.")||t.startsWith("developer.")||t.startsWith("developers.")||t.startsWith("api.")||n.includes("documentation")||n.includes("docs")||n.includes("reference")||a.includes("/docs/")||a.includes("/reference/")||a.includes("/api/"))return"official-docs";if(t.startsWith("blog.")||a.includes("/blog/"))return"maintainer-blog";return"website"}function Ir(t){switch(t){case"official-docs":return 5;case"repo":return 4;case"academic":return 4;case"maintainer-blog":return 3;case"website":return 2;case"community":return 1;case"news":return 0;case"social":return-6;default:return 0}}function Xr(t){let e=Object.values(t.perEngine||{}).map((r)=>r?.rank||99);return e.length?Math.min(...e):99}var xr=["reddit.com","news.ycombinator.com","lobste.rs"];function X(t){return t.smartScore*3+t.engineCount*5+Ir(t.sourceType)*2+Math.max(0,7-Xr(t))}function Qr(t){let e=t.toLowerCase(),r=[];if(e.includes("openai")||e.includes("gpt")||e.includes("chatgpt"))r.push("openai.com","platform.openai.com","help.openai.com");if(e.includes("anthropic")||e.includes("claude"))r.push("anthropic.com","docs.anthropic.com");if(e.includes("bun"))r.push("bun.sh","bun.com");if(e.includes("next.js")||e.includes("nextjs"))r.push("nextjs.org","vercel.com");if(e.includes("playwright"))r.push("playwright.dev");if(e.includes("supabase"))r.push("supabase.com","supabase.io");if(e.includes("prisma"))r.push("prisma.io");if(e.includes("tailwind"))r.push("tailwindcss.com");if(e.includes("vite"))r.push("vitejs.dev","vite.dev");if(e.includes("astro"))r.push("astro.build");if(e.includes("svelte"))r.push("svelte.dev");if(e.includes("solid"))r.push("solidjs.com");if(e.includes("vue")||e.includes("nuxt"))r.push("vuejs.org","nuxt.com");if(e.includes("react")||e.includes("react native"))r.push("react.dev","reactnative.dev");if(e.includes("angular"))r.push("angular.io","angular.dev");if(e.includes("node.js")||e.includes("nodejs"))r.push("nodejs.org","nodejs.dev","npmjs.com");if(/\bgo\b/.test(e)||e.includes("golang"))r.push("go.dev","golang.org","pkg.go.dev");if(e.includes("deno"))r.push("deno.land","deno.com");if(e.includes("fresh"))r.push("fresh.deno.dev");if(e.includes("typescript")||e.includes("ts"))r.push("typescriptlang.org");if(e.includes("python"))r.push("python.org","docs.python.org");if(e.includes("rust"))r.push("rust-lang.org","docs.rs","crates.io");if(e.includes("zig"))r.push("ziglang.org");if(e.includes("docker"))r.push("docker.com","docs.docker.com","hub.docker.com");if(e.includes("kubernetes")||e.includes("k8s"))r.push("kubernetes.io","k8s.io");if(e.includes("postgres")||e.includes("postgresql"))r.push("postgresql.org","neon.tech","supabase.com");if(e.includes("redis"))r.push("redis.io");if(e.includes("sqlite"))r.push("sqlite.org");if(e.includes("cloudflare"))r.push("developers.cloudflare.com","cloudflare.com");if(e.includes("vercel"))r.push("vercel.com","nextjs.org");if(e.includes("netlify"))r.push("netlify.com","docs.netlify.com");if(e.includes("stripe"))r.push("stripe.com","docs.stripe.com");if(e.includes("github"))r.push("github.com","docs.github.com");if(e.includes("gitlab"))r.push("gitlab.com","docs.gitlab.com");if(e.includes("aws"))r.push("aws.amazon.com","docs.aws.amazon.com");if(e.includes("azure"))r.push("azure.microsoft.com","learn.microsoft.com");if(e.includes("gcp")||e.includes("google cloud"))r.push("cloud.google.com","developers.google.com");if(e.includes("gemini")||e.includes("google ai"))r.push("ai.google.dev","developers.google.com");for(let n of ke){let a=n.replace(/\.com$/,"");if(e.includes(a))r.push(n)}return[...new Set(r)]}function _e(t,e){return t===e||t.endsWith(`.${e}`)}function Lt(t,e=""){let r=new Map,n=Object.keys(t||{}).filter((g)=>!g.startsWith("_")),a=Qr(e);for(let g of n){let p=t[g];if(!p?.sources)continue;for(let h=0;h<p.sources.length;h++){let m=p.sources[h],c=M(m.url);if(!c||c.length<10)continue;let y=Tt(m.title||""),b=Ur(c),w=Pt(b,y,c),k=0;if(a.some((N)=>_e(b,N)))k+=10;if(w==="official-docs")k+=3;let C=c.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(C))k+=2;let _=a.some((N)=>_e(b,N));if(w==="social"&&!_)k-=20;if(a.length>0){if(rt(b,xr))k-=3;else if(w==="community"&&!rt(b,["stackoverflow.com","stackexchange.com"]))k-=1}let s=r.get(c)||{id:"",canonicalUrl:c,displayUrl:m.url||c,domain:b,title:"",engines:[],engineCount:0,perEngine:{},sourceType:w,isOfficial:w==="official-docs",smartScore:0};if(s.title=Ot(s.title,y),s.displayUrl=s.displayUrl||m.url||c,s.sourceType=s.sourceType||w,s.isOfficial=s.isOfficial||w==="official-docs",s.smartScore=Math.max(s.smartScore,k),!s.engines.includes(g))s.engines.push(g);s.perEngine[g]={rank:h+1,title:Ot(s.perEngine[g]?.title||"",y)},r.set(c,s)}}let l=Array.from(r.values()).map((g)=>({...g,engineCount:g.engines.length})),i=l.filter((g)=>g.sourceType!=="social"),f=l.filter((g)=>g.sourceType==="social");return i.sort((g,p)=>{let h=X(p)-X(g);if(h!==0)return h;return g.domain.localeCompare(p.domain)}),f.sort((g,p)=>{let h=X(p)-X(g);if(h!==0)return h;return g.domain.localeCompare(p.domain)}),[...i,...f].slice(0,12).map((g,p)=>({...g,id:`S${p+1}`,title:g.title||g.domain||g.canonicalUrl}))}function se(t,e){let r=new Map(e.map((n)=>[n.id,n]));return t.map((n)=>{let a=r.get(n.id);if(!a)return n;let l=Ot(n.title,a.title||"");return{...n,title:l||n.title,fetch:{attempted:!0,ok:!a.error&&a.contentChars>100,status:a.status||null,finalUrl:a.finalUrl||a.url||n.canonicalUrl,contentType:a.contentType||"",lastModified:a.lastModified||"",publishedTime:a.publishedTime||"",byline:a.byline||"",siteName:a.siteName||"",lang:a.lang||"",title:a.title||"",snippet:a.snippet||"",contentChars:a.contentChars||0,source:a.source||"unknown",duration:a.duration||0,error:a.error||""}}})}import{existsSync as ot,mkdirSync as zr,readFileSync as ve,writeFileSync as Sr}from"node:fs";import{homedir as ur}from"node:os";import{join as je}from"node:path";import{tmpdir as pt}from"node:os";var ht=`${pt().replaceAll("\\","/")}/greedysearch-chrome-profile`,Hl=`${ht}/DevToolsActivePort`,Fl=`${pt().replaceAll("\\","/")}/cdp-pages.json`,Yl=`${pt().replaceAll("\\","/")}/greedysearch-chrome-mode`,Gl=`${pt().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,Mt=je(ur(),".dm"),G=je(Mt,"greedyconfig"),At=["perplexity","google","chatgpt"],Rt="gemini";function qr(){try{if(ot(G)){let t=ve(G,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((r)=>typeof r==="string")){let r=e.engines.filter((a)=>Wt[a]),n=e.engines.filter((a)=>!Wt[a]);if(n.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${G}: ${n.join(", ")}
|
|
330
|
+
[greedysearch] Available engines: ${Object.keys(Wt).join(", ")}
|
|
331
|
+
`);if(r.length>0)return r;process.stderr.write(`[greedysearch] Warning: no valid engines in ${G}, falling back to defaults: ${At.join(", ")}
|
|
332
|
+
`)}}}catch{}return At}function tn(){try{if(!ot(Mt))zr(Mt,{recursive:!0});if(!ot(G))Sr(G,JSON.stringify({engines:At,synthesizer:Rt},null,2)+`
|
|
333
|
+
`,"utf8")}catch{}}tn();var nt=["gemini","chatgpt"];function en(){try{if(ot(G)){let t=ve(G,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let r=e.synthesizer.toLowerCase();if(nt.includes(r))return r;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${G}
|
|
334
334
|
[greedysearch] Available synthesizers: ${nt.join(", ")}
|
|
335
|
-
[greedysearch] Falling back to default: ${
|
|
336
|
-
`)}}}catch{}return
|
|
337
|
-
`)e+="\\n";else if(r&&a==="\r")e+="\\r";else if(r&&a==="\t")e+="\\t";else e+=a}return e}function wt(t){if(!t)return null;let e=String(t).trim(),r=e.indexOf("BEGIN_JSON"),n=e.indexOf("END_JSON");if(r!==-1&&n!==-1&&r<n)e=e.slice(r+10,n).trim();else{let f=e.indexOf("{");if(f>0)e=e.slice(f)}let a=[e,e.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/```$/i,"").trim()],l=e.indexOf("{"),i=e.lastIndexOf("}");if(l!==-1&&i!==-1&&l<i)a.push(e.slice(l,i+1));for(let f of[...a]){let o=rn(f);if(o!==f)a.push(o)}for(let f of a)try{return JSON.parse(f)}catch{}return null}import{spawn as
|
|
338
|
-
`||n==="\r"){if(!r)e+=" ";r=!0}else e+=n,r=!1;return e.trim()}function Er(t){return new Set(String(t).toLowerCase().normalize("NFD").replaceAll(/[\u0300-\u036f]/g,"").split(/[^\w]+/).filter((e)=>e.length>1))}function
|
|
335
|
+
[greedysearch] Falling back to default: ${Rt}
|
|
336
|
+
`)}}}catch{}return Rt}var Wt={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"},De=qr(),Jt=De,Vl=en(),dl=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=ht;function rn(t){let e="",r=!1,n=!1;for(let a of String(t)){if(n){e+=a,n=!1;continue}if(a==="\\"){e+=a,n=!0;continue}if(a==='"'){r=!r,e+=a;continue}if(r&&a===`
|
|
337
|
+
`)e+="\\n";else if(r&&a==="\r")e+="\\r";else if(r&&a==="\t")e+="\\t";else e+=a}return e}function wt(t){if(!t)return null;let e=String(t).trim(),r=e.indexOf("BEGIN_JSON"),n=e.indexOf("END_JSON");if(r!==-1&&n!==-1&&r<n)e=e.slice(r+10,n).trim();else{let f=e.indexOf("{");if(f>0)e=e.slice(f)}let a=[e,e.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/```$/i,"").trim()],l=e.indexOf("{"),i=e.lastIndexOf("}");if(l!==-1&&i!==-1&&l<i)a.push(e.slice(l,i+1));for(let f of[...a]){let o=rn(f);if(o!==f)a.push(o)}for(let f of a)try{return JSON.parse(f)}catch{}return null}import{spawn as gn}from"node:child_process";import{basename as nn}from"node:path";function $t(t=process.env,e=process.execPath){let r=t.GREEDY_SEARCH_NODE||t.NODE_BINARY||t.NODE;if(r?.trim())return r.trim();let n=nn(e||"").toLowerCase();if(n==="node"||n==="node.exe")return e;return"node"}import{existsSync as Ee}from"node:fs";import{dirname as an,join as ct}from"node:path";import{fileURLToPath as ln}from"node:url";function Ce(t){return ln(new URL(".",t)).replace(/^\/([A-Z]:)/,"$1")}function fn(t,e=Ee){let r=new Set;for(let n of t.filter(Boolean)){if(r.has(n))continue;if(r.add(n),e(n))return n}return t.filter(Boolean).at(-1)}function Ne(t,{moduleDir:e,entrypoint:r=process.argv[1],env:n=process.env,exists:a=Ee}={}){let l=r?an(r):null,i=n.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,f=[e?ct(e,"..","..","extractors",t):null,e?ct(e,"..","extractors",t):null,i?ct(i,"extractors",t):null,l?ct(l,"..","extractors",t):null];return fn(f,a)}var on=Ce(import.meta.url),pn={gemini:"gemini.mjs",chatgpt:"chatgpt.mjs"};function hn(t="gemini"){let e=String(t||"gemini").toLowerCase();if(e==="gem")return"gemini";if(e==="gpt")return"chatgpt";return e}async function wn(t,e,{tabPrefix:r=null,timeoutMs:n=180000,visible:a=null}={}){let l=hn(t),i=pn[l];if(!i||!nt.includes(l))throw Error(`Unsupported synthesizer "${t}". Supported: ${nt.join(", ")}`);return new Promise((f,o)=>{let g=r?["--tab",String(r)]:[],p=Ne(i,{moduleDir:on}),h={...process.env,CDP_PROFILE_DIR:ht};if(a!==!0)delete h.GREEDY_SEARCH_VISIBLE,delete h.GREEDY_SEARCH_ALWAYS_VISIBLE;else h.GREEDY_SEARCH_VISIBLE="1",h.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let m=gn($t(),[p,"--stdin",...g],{stdio:["pipe","pipe","pipe"],env:h});m.stdin.write(e),m.stdin.end();let c="",y="";m.stdout.on("data",(w)=>c+=w),m.stderr.on("data",(w)=>y+=w);let b=setTimeout(()=>{m.kill(),o(Error(`${l} prompt timed out after ${n/1000}s`))},n);m.on("close",(w)=>{if(clearTimeout(b),w!==0){o(Error(y.trim()||`${l} extractor failed`));return}try{f(JSON.parse(c.trim()))}catch{o(Error(`bad JSON from ${l}: ${c.slice(0,100)}`))}})})}async function x(t,e={}){return wn("gemini",t,e)}var da=Va(new URL(".",import.meta.url)).replace(/^\/([A-Z]:)/,"$1");function Za(t=da){let e=[D(t,"search.mjs"),D(t,"..","bin","search.mjs"),D(t,"..","..","bin","search.mjs")];for(let r of e)if(Ga(r))return r;return e[e.length-1]}var Ba=Za(),Ka=D(process.cwd(),".dm","greedysearch-research");function Ua(t){return String(t||"research").toLowerCase().replaceAll(/[^a-z0-9]+/g,"-").replaceAll(/^-|-$/g,"").slice(0,60)||"research"}function B(t,e=1/0){let r=new Set,n=[];for(let a of t||[]){let l=T(String(a||""),1000);if(!l||r.has(l))continue;if(r.add(l),n.push(l),n.length>=e)break}return n}async function Ia(...t){let{fetchMultipleSources:e}=await Promise.resolve().then(() => (ir(),lr));return e(...t)}async function le(...t){let{writeSourcesToFiles:e}=await Promise.resolve().then(() => (or(),gr));return e(...t)}function Xa({breadth:t=3,iterations:e=2,maxSources:r}){let n=ee(t,1,5,3),a=ee(e,1,3,2),l=ee(r??Math.max(5,n*a*2),3,12,8);return{breadth:n,iterations:a,maxSources:l}}function ee(t,e,r,n){let a=Number.parseInt(String(t??""),10);if(!Number.isFinite(a))return n;return Math.min(r,Math.max(e,a))}function xa(t,e,r,{expand:n=!0,includeOriginal:a=!0,exclude:l=[]}={}){let i=Array.isArray(t?.queries)?t.queries:[],f=[],o=new Set([...l].map((g)=>A(g).toLowerCase()));for(let g of i){let p=typeof g==="string"?g:g?.query,h=typeof g==="string"?"":g?.researchGoal||"";re(f,p,h,{exclude:o})}if(a)re(f,e,"Original user query",{prepend:!0,exclude:o});if(n){let g=[{query:`${e} official docs GitHub`,researchGoal:"Find primary project docs, repository details, and maintainer claims."},{query:`${e} benchmarks limitations compatibility`,researchGoal:"Validate performance claims and uncover unsupported APIs or caveats."},{query:`${e} alternatives comparison production use cases`,researchGoal:"Compare against conventional headless browsers and identify when to choose it."},{query:`${e} anti bot detection Cloudflare screenshots visual rendering`,researchGoal:"Check automation risks, rendering gaps, screenshots, and bot-detection behavior."}];for(let p of g){if(f.length>=r)break;re(f,p.query,p.researchGoal,{exclude:o})}}return f.slice(0,r)}function re(t,e,r="",{prepend:n=!1,exclude:a=new Set}={}){if(!e||typeof e!=="string")return;let l=A(e);if(!l||a.has(l.toLowerCase())||t.some((f)=>f.query.toLowerCase()===l.toLowerCase()))return;let i={query:l,researchGoal:T(r,320)};if(n)t.unshift(i);else t.push(i)}function A(t){return za(Qa(String(t)))}function Qa(t){let e="",r=0;while(r<t.length){let n=t.indexOf("[",r);if(n===-1){e+=t.slice(r);break}let a=t.indexOf("]",n+1);if(a===-1||t[a+1]!=="("||a===n+1){e+=t.slice(r,n+1),r=n+1;continue}let l=t.indexOf(")",a+2);if(l===-1){e+=t.slice(r,n+1),r=n+1;continue}let i=t.slice(a+2,l).trimStart();if(!i.startsWith("http://")&&!i.startsWith("https://")){e+=t.slice(r,n+1),r=n+1;continue}e+=t.slice(r,n),e+=t.slice(n+1,a),r=l+1}return e}function za(t){let e="",r=!1;for(let n of t)if(n===" "||n==="\t"||n===`
|
|
338
|
+
`||n==="\r"){if(!r)e+=" ";r=!0}else e+=n,r=!1;return e.trim()}function Er(t){return new Set(String(t).toLowerCase().normalize("NFD").replaceAll(/[\u0300-\u036f]/g,"").split(/[^\w]+/).filter((e)=>e.length>1))}function Et(t,e){let r=Er(t),n=Er(e),a=new Set([...r,...n]).size;if(a===0)return 1;let l=0;for(let i of r)if(n.has(i))l++;return l/a}function Or(t,e,{threshold:r=0.75,roundIndex:n=0,originalQuery:a=null}={}){let l=A(t).toLowerCase();if(e.has(l))return!0;if(a&&n>0&&l===A(a).toLowerCase())return!0;for(let i of e)if(Et(l,i)>=r)return!0;return!1}function Sa(t,e,r,n){let a=e.map((l)=>({queries:l.queries?.map((i)=>i.query||"")||[],learnings:l.learnings||[],gaps:l.gaps||[]}));return["You are evaluating the quality of an iterative research run.","Assess coverage across: official sources, limitations/risks, benchmarks/performance, production usage, and counter-evidence.","Score each dimension 0-10. Overall score 0-10.","Identify remaining knowledge gaps.","Propose targeted next actions (search queries or direct URL fetches) that would most improve the research.","Decide whether to continue or stop.","terminationReason must be one of: quality_threshold | max_rounds | no_novel_actions | insufficient_evidence.","",`Original research question: ${t}`,`Rounds completed: ${JSON.stringify(a,null,2)}`,`Accumulated learnings: ${JSON.stringify(r.slice(0,12),null,2)}`,`Known gaps: ${JSON.stringify(n.slice(0,8),null,2)}`,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({score:7.5,coverage:{officialSources:8,limitations:5,benchmarks:7,productionUseCases:6,counterEvidence:4},knowledgeGaps:["specific gap or missing evidence"],shouldContinue:!0,terminationReason:"quality_threshold",nextActions:[{type:"search",query:"targeted search query"},{type:"fetchUrl",url:"https://example.com/primary-doc"}]},null,2),"END_JSON"].join(`
|
|
339
339
|
`)}function ua(t,e,r,n,a){let l=[],i=[{template:(f)=>`${f} official documentation`,label:"official docs"},{template:(f)=>`${f} GitHub issues discussions`,label:"community signals"},{template:(f)=>`${f} benchmarks performance comparison`,label:"benchmarks"},{template:(f)=>`${f} limitations risks caveats`,label:"limitations"},{template:(f)=>`${f} production deployment experience`,label:"production usage"},{template:(f)=>`${e} ${f} counter evidence`,label:"counter-evidence"}];for(let f=0;f<t.length&&l.length<n;f++){let o=t[f],g=i[f%i.length],p=g.template(o);if(!Or(p,r,{roundIndex:a}))l.push({query:p,researchGoal:`Gap-driven: ${o} (${g.label})`})}return l}async function qa(t,e,r,n,a){try{let l=await x(Sa(t,e,r,n),{timeoutMs:120000}),i=lt(l,{}),f=typeof i.score==="number"?Math.min(10,Math.max(0,i.score)):a.length>0?a[a.length-1]:5,o=Array.isArray(i.knowledgeGaps)?i.knowledgeGaps.map((m)=>String(m)).filter(Boolean).slice(0,6):[],g=Array.isArray(i.nextActions)?i.nextActions.slice(0,5):[],p=typeof i.shouldContinue==="boolean"?i.shouldContinue:f<8,h=i.terminationReason||null;return{score:f,coverage:i.coverage||{},knowledgeGaps:o,shouldContinue:p,nextActions:g,terminationReason:h||(f>=8.5?"quality_threshold":null),evaluationError:""}}catch(l){return process.stderr.write(`[greedysearch] Quality evaluation failed: ${l.message}
|
|
340
340
|
`),{score:a.length>0?a[a.length-1]:5,coverage:{},knowledgeGaps:[],shouldContinue:!0,nextActions:[],terminationReason:null,evaluationError:l.message}}}function tl(t){let e={};for(let r of Object.keys(t||{}).filter((n)=>!n.startsWith("_"))){let n=t?.[r];if(!n)continue;e[r]=n.error?{status:"error",error:String(n.error)}:{status:"ok",answer:T(n.answer||"",1400),sources:Array.isArray(n.sources)?n.sources.slice(0,5).map((a)=>({title:T(a.title||"",160),url:a.url||""})):[]}}return e}function el(t,e,r=[],n=[],a=[]){let l=n.length>0?`
|
|
341
341
|
Known knowledge gaps to target:
|
|
@@ -347,38 +347,38 @@ ${a.map((f)=>`- ${f}`).join(`
|
|
|
347
347
|
Prior learnings to build on:
|
|
348
348
|
${r.map((f)=>`- ${f}`).join(`
|
|
349
349
|
`)}`:"",l,i,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({actions:[{type:"search",query:"specific search query",researchGoal:"what this action should clarify"},{type:"fetchUrl",url:"https://example.com/docs/relevant-page",researchGoal:"extract specific information from this page"}]},null,2),"END_JSON"].join(`
|
|
350
|
-
`)}function Pr(t){if(!t||typeof t!=="object")return null;let e=t.type,r=T(t.researchGoal||"",320);if(e==="search"){if(t.query==null)return null;let n=A(t.query);return n?{type:"search",query:n,researchGoal:r}:null}if(e==="fetchUrl"){if(t.url==null)return null;let n=M(t.url);return n?{type:"fetchUrl",url:n,researchGoal:r}:null}return null}async function rl(t,{locale:e=null,short:r=!0,usedQueries:n,usedUrls:a,maxChars:l=8000}={}){if(t.type==="search"){let i=A(t.query).toLowerCase();n.add(i);try{let f=await ml(t.query,{locale:e,short:r}),o=
|
|
351
|
-
`)}function pl(t,e){let r=Array.isArray(t?.extractions)?t.extractions:[],n=new Map,a=new Map;for(let l of e||[]){if(l?.id)a.set(String(l.id),l);let i=
|
|
350
|
+
`)}function Pr(t){if(!t||typeof t!=="object")return null;let e=t.type,r=T(t.researchGoal||"",320);if(e==="search"){if(t.query==null)return null;let n=A(t.query);return n?{type:"search",query:n,researchGoal:r}:null}if(e==="fetchUrl"){if(t.url==null)return null;let n=M(t.url);return n?{type:"fetchUrl",url:n,researchGoal:r}:null}return null}async function rl(t,{locale:e=null,short:r=!0,usedQueries:n,usedUrls:a,maxChars:l=8000}={}){if(t.type==="search"){let i=A(t.query).toLowerCase();n.add(i);try{let f=await ml(t.query,{locale:e,short:r}),o=Lt(f,t.query);return{ok:!0,action:t,result:f,sources:o}}catch(f){return{ok:!1,action:t,error:f.message,sources:[]}}}if(t.type==="fetchUrl"){let i=M(t.url);if(a.has(i))return{ok:!1,action:t,error:`URL already fetched: ${i}`,sources:[]};try{let f=await nl(i,l);a.add(i);let o=ll(i),g={id:"",canonicalUrl:f.finalUrl||i,displayUrl:f.url||i,domain:o,title:f.title||i,engines:["fetch"],engineCount:1,perEngine:{},sourceType:Pt(o,f.title||"",f.finalUrl||i),isOfficial:!1,smartScore:0,fetch:{attempted:!0,ok:!f.error&&(f.contentChars||0)>100,status:f.status||null,finalUrl:f.finalUrl||i,content:f.content||"",contentChars:f.contentChars||0,snippet:f.snippet||"",error:f.error||""}};return{ok:!0,action:t,result:null,sources:[g],fetchResult:{id:g.id,url:i,finalUrl:f.finalUrl||i,title:f.title||"",content:f.content||"",contentChars:f.contentChars||0,snippet:f.snippet||"",status:f.status||null,error:f.error||"",source:f.source||"http",duration:f.duration||0}}}catch(f){return{ok:!1,action:t,error:f.message,sources:[]}}}return{ok:!1,action:t,error:`Unknown action type: ${t.type}`,sources:[]}}async function nl(t,e){return await al(t,e)}async function al(t,e=8000){let r=Date.now();try{let{parseGitHubUrl:n,fetchGitHubContent:a}=await Promise.resolve().then(() => (ut(),St)),l=n(t);if(l&&(l.type==="root"||l.type==="tree"||l.type==="blob"&&!l.path?.includes("."))){let i=await a(t);if(i.ok){let{trimContentHeadTail:f}=await Promise.resolve().then(() => qt),o=f(i.content,e);return{url:t,finalUrl:t,status:200,title:i.title,snippet:o.slice(0,320),content:o,contentChars:o.length,source:"github-api",duration:Date.now()-r}}}}catch{}try{let{fetchSourceHttp:n}=await Promise.resolve().then(() => (Dr(),jr)),{trimContentHeadTail:a}=await Promise.resolve().then(() => qt),l=await n(t,{timeoutMs:1e4});if(l.ok){let i=a(l.markdown,e);return{url:t,finalUrl:l.finalUrl,status:l.status,title:l.title,snippet:l.excerpt,content:i,contentChars:i.length,source:"http",duration:Date.now()-r}}}catch{}return{url:t,title:"",content:"",contentChars:0,snippet:"",error:"HTTP fetch failed",source:"error",duration:Date.now()-r}}function ll(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}async function il(t,e){let r=[],{parseGitHubUrl:n}=await Promise.resolve().then(() => (ut(),St));for(let a of t){if(a.type!=="fetchUrl"){r.push(a);continue}let l=n(a.url);if(!l||l.type!=="root"){r.push(a);continue}let{owner:i,repo:f}=l,o=`https://github.com/${i}/${f}`;if(e.has(o))continue;let g=[o],p=[`${o}/blob/main/CONTRIBUTING.md`,`${o}/blob/master/CONTRIBUTING.md`,`${o}/blob/main/CHANGELOG.md`,`${o}/blob/master/CHANGELOG.md`,`${o}/blob/main/docs/README.md`];for(let h of p){if(g.length>=3)break;if(!e.has(h))g.push(h)}for(let h of g)r.push({type:"fetchUrl",url:h,researchGoal:a.researchGoal||`Fetch GitHub content for ${i}/${f}`})}return r}function fl(t,e){let r=wt(t?.answer||"")||{},n=Array.isArray(r?.actions)?r.actions:[],a=[];for(let l of n){let i=Pr(l);if(i&&a.length<e)a.push(i)}return a}function gl(t){return(t||[]).map((e)=>({type:"search",query:typeof e==="string"?e:e.query,researchGoal:typeof e==="string"?"":e.researchGoal||""})).filter((e)=>e.query)}function Dt(t){return M(t?.finalUrl||t?.canonicalUrl||t?.url||"")||t?.id||""}function ol(t,e,r,n=new Set){let a=(e||[]).filter((i)=>i.status!=="closed").slice(0,12).map((i)=>({id:i.id,question:i.question})),l=(r||[]).filter((i)=>i?.content||i?.snippet).filter((i)=>!n.has(Dt(i))).slice(0,6).map((i,f)=>({id:i.id||`F${f+1}`,title:i.title||"",url:i.finalUrl||i.url||i.canonicalUrl||"",content:T(i.content||i.snippet||"",5000)}));return["You are doing goal-based evidence extraction for an iterative research run.","For each source, extract only information that helps answer the open questions.","Use original wording/details where useful. Do not invent answers; leave questions open if evidence is insufficient.","If a source answers one or more tracked questions, identify those question IDs explicitly.","Also propose genuinely new sub-questions discovered from the evidence.","",`Original research question: ${t}`,`Open question ledger: ${JSON.stringify(a,null,2)}`,`Fetched sources: ${JSON.stringify(l,null,2)}`,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({extractions:[{sourceId:"S1",url:"https://example.com/source",rational:"why this source matters for the goal",evidence:"specific quoted/paraphrased evidence with numbers, dates, caveats",summary:"concise contribution to the research question",answers:[{id:"Q1",evidence:"brief evidence that closes the question"}],newQuestions:["new sub-question raised by this source"]}]},null,2),"END_JSON"].join(`
|
|
351
|
+
`)}function pl(t,e){let r=Array.isArray(t?.extractions)?t.extractions:[],n=new Map,a=new Map;for(let l of e||[]){if(l?.id)a.set(String(l.id),l);let i=Dt(l);if(i)n.set(i,l)}return r.map((l)=>{let i=a.get(String(l?.sourceId||""))||n.get(M(l?.url||"")||""),f=String(l?.sourceId||i?.id||""),o=M(l?.url||i?.finalUrl||i?.url||""),g=Array.isArray(l?.answers)?l.answers.map((p)=>({id:String(p?.id||""),evidence:T(p?.evidence||"",500),sourceIds:[f].filter(Boolean)})).filter((p)=>p.id):[];return{sourceId:f,url:o,title:i?.title||l?.title||"",rational:T(l?.rational||"",700),evidence:T(l?.evidence||"",1600),summary:T(l?.summary||"",700),answers:g,newQuestions:B(l?.newQuestions||[],6)}}).filter((l)=>l.sourceId||l.url||l.summary||l.evidence)}async function hl({query:t,questions:e,fetchedSources:r,extractedSourceKeys:n}){let a=(r||[]).filter((l)=>(l?.content||l?.snippet)&&!n.has(Dt(l)));if(a.length===0)return{evidence:[],error:""};try{let l=await x(ol(t,e,a,n),{timeoutMs:120000}),i=lt(l,{extractions:[]}),f=pl(i,a);for(let o of a){let g=Dt(o);if(g)n.add(g)}return{evidence:f,error:""}}catch(l){return{evidence:[],error:l.message||String(l)}}}function wl(t,e,r,n,a=[],l=[]){let i=n.filter((f)=>f?.content||f?.snippet).slice(0,10).map((f,o)=>({id:`F${o+1}`,title:f.title||"",url:f.finalUrl||f.url||"",snippet:T(f.content||f.snippet||"",3000)}));return["You are extracting compact research state from live multi-engine search results.","Create dense, non-overlapping learnings with exact names, numbers, dates, limitations, and caveats where available.","Also propose follow-up search queries that would most improve confidence or fill gaps.","",`Original research question: ${t}`,`Round queries: ${JSON.stringify(e,null,2)}`,`Question ledger: ${JSON.stringify(a,null,2)}`,`Extracted source evidence: ${JSON.stringify(l.slice(-12),null,2)}`,`Engine summaries: ${JSON.stringify(r,null,2)}`,`Fetched source snippets: ${JSON.stringify(i,null,2)}`,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({learnings:["concise, information-dense learning"],answeredQuestions:[{id:"Q1",evidence:"brief evidence that closes this question",sourceIds:["S1"]}],newQuestions:["new sub-question discovered from the evidence"],followUpQueries:["specific next search query"],gaps:["important uncertainty or missing evidence"]},null,2),"END_JSON"].join(`
|
|
352
352
|
`)}function $l(t,e,r,n=[],a=[]){let l=e.flatMap((o)=>o.learnings||[]),i=e.flatMap((o)=>o.gaps||[]),f=r.slice(0,12).map((o)=>({id:o.id,title:o.title,domain:o.domain,url:o.canonicalUrl,type:o.sourceType,engines:o.engines,fetch:o.fetch?.attempted?{ok:o.fetch.ok,snippet:T(o.fetch.snippet||"",1200),publishedTime:o.fetch.publishedTime||""}:void 0}));return["You are writing the final research report for an iterative deep-research run.","Produce a thorough markdown report organized into clear sections.","","Use the learnings and source registry below. Every substantive claim MUST be backed by an [S1] citation.",'Where engines disagree, surface the conflicting claims explicitly in the "differences" array.','Include a "Key Claims" structure that maps each distinct claim to its supporting source IDs.',"","Report structure:","1. ## Summary — A 2-4 sentence executive summary of findings","2. ## Key Findings — The main findings, organized by theme or question, each with inline citations","3. ## Areas of Disagreement — Where engines or sources conflict (if any)","4. ## Limitations & Caveats — Important qualifiers, gaps, or uncertainties","",`Original research question: ${t}`,`Learnings: ${JSON.stringify(l,null,2)}`,`Known gaps/caveats: ${JSON.stringify(i,null,2)}`,`Question ledger: ${JSON.stringify(n,null,2)}`,`Goal-based extracted evidence: ${JSON.stringify(a.slice(-20),null,2)}`,`Source registry: ${JSON.stringify(f,null,2)}`,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({answer:"markdown report with sections and inline [S1] citations",agreement:{level:"high|medium|low|mixed|conflicting",summary:"one-sentence confidence summary"},differences:["notable disagreement or conflict between sources"],caveats:["important caveat or qualification"],claims:[{claim:"specific factual statement from the research",support:"strong|moderate|weak|conflicting",sourceIds:["S1","S2"]}],recommendedSources:["S1","S2"]},null,2),"END_JSON"].join(`
|
|
353
353
|
`)}function cl(t,e=[],r=[],n=[]){let a=e.slice(0,12).map((o)=>({id:o.id,title:o.title,domain:o.domain,url:o.canonicalUrl,type:o.sourceType,engines:o.engines})),l=n.slice(-20),i=new Set;for(let o of l)for(let g of o.answers||[])if(g?.id)i.add(g.id);let f=(r||[]).filter((o)=>o.status!=="closed").map((o)=>({id:o.id,question:o.question}));return["You are writing the final research report from goal-based extracted evidence.","Per-round learnings were not produced, but the per-source evidence extraction step succeeded.","Synthesize a thorough markdown report using ONLY the evidence below. Every substantive claim MUST be backed by an [S1] citation.","","Report structure:","1. ## Summary — A 2-4 sentence executive summary of findings","2. ## Key Findings — The main findings, organized by theme or question, each with inline citations","3. ## Limitations & Caveats — Important qualifiers, gaps, or uncertainties","",`Original research question: ${t}`,`Per-source extracted evidence: ${JSON.stringify(l,null,2)}`,`Source registry: ${JSON.stringify(a,null,2)}`,`Questions already answered by the evidence: ${JSON.stringify(Array.from(i))}`,`Questions still open after this evidence: ${JSON.stringify(f)}`,"","Respond ONLY with JSON wrapped in BEGIN_JSON / END_JSON markers:","BEGIN_JSON",JSON.stringify({answer:"markdown report with sections and inline [S1] citations",agreement:{level:"high|medium|low|mixed|conflicting",summary:"one-sentence confidence summary"},differences:["notable disagreement or conflict between sources"],caveats:["important caveat or qualification"],claims:[{claim:"specific factual statement supported by the evidence",support:"strong|moderate|weak|conflicting",sourceIds:["S1","S2"]}],recommendedSources:["S1","S2"]},null,2),"END_JSON"].join(`
|
|
354
|
-
`)}async function ml(t,{locale:e=null,short:r=!0}={}){let n=[Ba,"all","--inline","--stdin","--fast"];if(!r)n.push("--full");if(e)n.push("--locale",e);return new Promise((a,l)=>{let i=Ya(
|
|
354
|
+
`)}async function ml(t,{locale:e=null,short:r=!0}={}){let n=[Ba,"all","--inline","--stdin","--fast"];if(!r)n.push("--full");if(e)n.push("--locale",e);return new Promise((a,l)=>{let i=Ya($t(),n,{stdio:["pipe","pipe","pipe"],env:{...process.env,GREEDY_SEARCH_RESEARCH_CHILD:"1"}});i.stdin.write(t),i.stdin.end();let f="",o="",g="";i.stdout.on("data",(h)=>f+=h),i.stderr.on("data",(h)=>{o+=h,g+=h.toString();let m=g.split(`
|
|
355
355
|
`);g=m.pop()||"";for(let c of m)if(yl(c))process.stderr.write(`${c}
|
|
356
|
-
`)});let p=setTimeout(()=>{i.kill(),l(Error(`research child search timed out for: ${t}`))},140000);i.on("close",(h)=>{if(clearTimeout(p),h!==0){l(Error(o.trim()||`search child exited with code ${h}`));return}try{a(JSON.parse(f.trim()))}catch{l(Error(`Invalid JSON from research child: ${f.slice(0,200)}`))}})})}function bl(t){let e=new Map;for(let r of t.flat()){let n=M(r.canonicalUrl||r.url);if(!n)continue;let a=e.get(n);if(!a){e.set(n,{...r,canonicalUrl:n});continue}a.engines=[...new Set([...a.engines||[],...r.engines||[]])],a.engineCount=a.engines.length,a.smartScore=Math.max(a.smartScore||0,r.smartScore||0)}return Array.from(e.values()).sort((r,n)=>{let a=X(n)-X(r);if(a!==0)return a;return(r.domain||"").localeCompare(n.domain||"")}).slice(0,12).map((r,n)=>({...r,id:`S${n+1}`}))}function yl(t){return/^PROGRESS:/.test(t)||/^\[greedysearch\]/.test(t)||/^\[(bing|perplexity|google|gemini|chatgpt|logically|semantic-scholar)\]/.test(t)||/^GreedySearch Chrome/.test(t)||/^Launching GreedySearch Chrome/.test(t)||/^Headless mode/.test(t)||/^Ready\.?$/.test(t)}function lt(t,e={}){return wt(t?.answer||"")||e}function _l(t,e){if(!t||!Array.isArray(e))return{cited:[],missing:[],unfetched:[],ok:!0};let r=/\b[SF](\d+)\b/g,n=new Set,a;while((a=r.exec(t))!==null)n.add(`S${a[1]}`),n.add(`F${a[1]}`);let l=new Map;for(let g of e){let p=g?.id;if(p)l.set(p,g)}let i=Array.from(n),f=[],o=[];for(let g of i){let p=l.get(g);if(!p){let h=g.match(/^(S|F)(\d+)$/);if(h){let m=parseInt(h[2],10)-1;if(m>=0&&m<e.length){let c=e[m];if(c){if(!(c.fetch?.ok||c.content&&c.content.length>100||c.contentChars&&c.contentChars>100))o.push(g);continue}}}f.push(g)}else if(!(p.fetch?.ok||p.content&&p.content.length>100||p.contentChars&&p.contentChars>100))o.push(g)}return{cited:i,missing:f,unfetched:o,ok:f.length===0}}function Cr({sources:t=[],fetchedSources:e=[],synthesis:r={},citationAudit:n=null,gaps:a=[],questions:l=[],rounds:i=[],qualityScore:f=0,qualityThreshold:o=8.5,maxSources:g=8,requireCitations:p=!0,requireQuestions:h=!0}={}){let m=e.filter((N)=>N?.fetch?.ok||(N?.contentChars||0)>100||String(N?.content||"").length>100),c=t.filter((N)=>["official-docs","repo","maintainer-blog","academic"].includes(String(N?.sourceType||""))),y=Array.isArray(r?.claims)?r.claims:[],b=n?n.cited?.length||0:0,w=
|
|
357
|
-
`)}function
|
|
358
|
-
`):e}async function El({query:t,rounds:e,sources:r,fetchedSources:n,evidenceItems:a=[],synthesis:l,citationAudit:i,floor:f,manifest:o,allGaps:g=[],questions:p=[],outDir:h=null}){let m=new Date().toISOString().replaceAll(/[:.]/g,"-").slice(0,19),c=h||D(Ka,`${m}_${Ua(t)}`),y=D(c,"reports"),b=D(c,"sources"),w=D(c,"data");
|
|
356
|
+
`)});let p=setTimeout(()=>{i.kill(),l(Error(`research child search timed out for: ${t}`))},140000);i.on("close",(h)=>{if(clearTimeout(p),h!==0){l(Error(o.trim()||`search child exited with code ${h}`));return}try{a(JSON.parse(f.trim()))}catch{l(Error(`Invalid JSON from research child: ${f.slice(0,200)}`))}})})}function bl(t){let e=new Map;for(let r of t.flat()){let n=M(r.canonicalUrl||r.url);if(!n)continue;let a=e.get(n);if(!a){e.set(n,{...r,canonicalUrl:n});continue}a.engines=[...new Set([...a.engines||[],...r.engines||[]])],a.engineCount=a.engines.length,a.smartScore=Math.max(a.smartScore||0,r.smartScore||0)}return Array.from(e.values()).sort((r,n)=>{let a=X(n)-X(r);if(a!==0)return a;return(r.domain||"").localeCompare(n.domain||"")}).slice(0,12).map((r,n)=>({...r,id:`S${n+1}`}))}function yl(t){return/^PROGRESS:/.test(t)||/^\[greedysearch\]/.test(t)||/^\[(bing|perplexity|google|gemini|chatgpt|logically|semantic-scholar)\]/.test(t)||/^GreedySearch Chrome/.test(t)||/^Launching GreedySearch Chrome/.test(t)||/^Headless mode/.test(t)||/^Ready\.?$/.test(t)}function lt(t,e={}){return wt(t?.answer||"")||e}function _l(t,e){if(!t||!Array.isArray(e))return{cited:[],missing:[],unfetched:[],ok:!0};let r=/\b[SF](\d+)\b/g,n=new Set,a;while((a=r.exec(t))!==null)n.add(`S${a[1]}`),n.add(`F${a[1]}`);let l=new Map;for(let g of e){let p=g?.id;if(p)l.set(p,g)}let i=Array.from(n),f=[],o=[];for(let g of i){let p=l.get(g);if(!p){let h=g.match(/^(S|F)(\d+)$/);if(h){let m=parseInt(h[2],10)-1;if(m>=0&&m<e.length){let c=e[m];if(c){if(!(c.fetch?.ok||c.content&&c.content.length>100||c.contentChars&&c.contentChars>100))o.push(g);continue}}}f.push(g)}else if(!(p.fetch?.ok||p.content&&p.content.length>100||p.contentChars&&p.contentChars>100))o.push(g)}return{cited:i,missing:f,unfetched:o,ok:f.length===0}}function Cr({sources:t=[],fetchedSources:e=[],synthesis:r={},citationAudit:n=null,gaps:a=[],questions:l=[],rounds:i=[],qualityScore:f=0,qualityThreshold:o=8.5,maxSources:g=8,requireCitations:p=!0,requireQuestions:h=!0}={}){let m=e.filter((N)=>N?.fetch?.ok||(N?.contentChars||0)>100||String(N?.content||"").length>100),c=t.filter((N)=>["official-docs","repo","maintainer-blog","academic"].includes(String(N?.sourceType||""))),y=Array.isArray(r?.claims)?r.claims:[],b=n?n.cited?.length||0:0,w=ie(l),k=(l||[]).filter((N)=>!N.createdRound||N.reason==="Original research question"),C=ie(k),_=Math.min(4,Math.max(2,Number(g)||8)),s={roundsRun:i.length>=1,fetchedSources:m.length>=_,primarySources:c.length>=1,qualityScore:f>=Math.min(o,8),claimsExtracted:!p||y.length>0,citationsPresent:!p||b>0,citationsValid:!p||n?.ok===!0,unfetchedCitations:!p||(n?.unfetched||[]).length===0,requiredQuestionsClosed:!h||C.open===0};return{floorMet:Object.values(s).every(Boolean),checks:s,metrics:{fetchedOk:m.length,primarySources:c.length,claims:y.length,cited:b,gaps:a.length,openQuestions:w.open,closedQuestions:w.closed,totalQuestions:w.total,openRequiredQuestions:C.open,closedRequiredQuestions:C.closed,totalRequiredQuestions:C.total,qualityScore:f,minFetched:_}}}function Nr(t,e){let r=new Map;for(let n of e||[]){let a=M(n?.canonicalUrl||n?.finalUrl||n?.url);if(a&&n?.id)r.set(a,n.id)}return(t||[]).map((n,a)=>{let l=M(n?.finalUrl||n?.canonicalUrl||n?.url);return{...n,id:n?.id||r.get(l)||`F${a+1}`}})}function kl(t){return[{id:"Q1",question:T(A(t),320),status:"open",reason:"Original research question",evidence:[],sourceIds:[]}]}function sl(t){let e=0;for(let r of t||[]){let n=Number.parseInt(String(r.id||"").replace(/^Q/i,""),10);if(Number.isFinite(n))e=Math.max(e,n)}return`Q${e+1}`}function Lr(t,e){let r=A(e).toLowerCase();return(t||[]).find((n)=>n.question?.toLowerCase()===r||Et(n.question||"",r)>=0.82)}function ne(t,e,{reason:r="",round:n=null}={}){let a=T(A(e),320);if(!a)return null;let l=Lr(t,a);if(l)return l;let i={id:sl(t),question:a,status:"open",reason:T(r,240),createdRound:n,evidence:[],sourceIds:[]};return t.push(i),i}function jt(t,e,{evidence:r="",sourceIds:n=[],round:a=null}={}){let l=t.find((i)=>i.id===e)||Lr(t,e);if(!l)return null;if(l.status="closed",l.closedRound=l.closedRound||a,r)l.evidence=B([...l.evidence||[],r],4);if(Array.isArray(n))l.sourceIds=B([...l.sourceIds||[],...n],8);return l}function ie(t){let e=t.length,r=t.filter((n)=>n.status==="closed").length;return{total:e,closed:r,open:Math.max(0,e-r)}}function vt(t,{roundNumber:e,actions:r=[],learningPayload:n={}}={}){for(let o of r){let g=o?.action||o,p=g?.researchGoal&&g.researchGoal!=="Original user query"?g.researchGoal:g?.query||g?.url||"";if(p)ne(t,p,{reason:"Planned research action",round:e})}let a=5,l=t.filter((o)=>o.status==="open"&&o.reason==="Discovered gap/follow-up");if(l.length>a){let o=l.sort((g,p)=>(g.createdRound||0)-(p.createdRound||0)).slice(0,l.length-a);for(let g of o)g.status="resolved",g.closedRound=e,g.evidence=B([...g.evidence||[],"Auto-resolved to cap open-question ledger"],4)}let i=Array.isArray(n.answeredQuestions)?n.answeredQuestions:[];for(let o of i){if(typeof o==="string"){jt(t,o,{round:e});continue}let g=o?.id||o?.question;if(!g&&o?.question){let p=ne(t,o.question,{reason:"Answered during learning extraction",round:e});if(p)jt(t,p.id,{round:e});continue}jt(t,g,{evidence:o?.evidence||o?.answer||"",sourceIds:Array.isArray(o?.sourceIds)?o.sourceIds:[],round:e})}let f=Array.isArray(n.newQuestions)?n.newQuestions:[];for(let o of f)ne(t,o,{reason:"Discovered gap/follow-up",round:e});return t}function vl(t,e){if(!Array.isArray(t)||t.length===0)return[];let r=["arxiv.org","semanticscholar.org","doi.org"],n=new Set,a=[];for(let l of t){let i=l?.canonicalUrl||l?.finalUrl||l?.url||"";if(!i)continue;let f="";try{f=new URL(i).hostname.toLowerCase().replace(/^www\./,"")}catch{continue}if(!r.some((g)=>f===g||f.endsWith(`.${g}`)))continue;if(e.has(i)||n.has(i))continue;n.add(i);let o=i.includes("/pdf/")?i.replace(/\/pdf\//,"/html/").replace(/\.pdf$/i,""):i;a.push({url:o,label:l?.title||l?.id||f})}return a.slice(0,2)}function jl(t,e,r){if(!e?.answer||r?.ok!==!0)return t;let n=Array.isArray(e.claims)?e.claims:[],a=Array.isArray(r.cited)?r.cited:[];if(n.length===0||a.length===0)return t;for(let l of t){if(l.status==="closed")continue;let i=null,f=0;for(let o of n){let g=Et(l.question||"",o.claim||"");if(g>f)f=g,i=o}if(l.id==="Q1"||f>=0.18)jt(t,l.id,{evidence:i?.claim||"Answered in final cited synthesis",sourceIds:Array.isArray(i?.sourceIds)?i.sourceIds:a.slice(0,4)})}return t}function Dl(t){if(!t.length)return"No tracked questions.";return t.map((e)=>{let r=e.sourceIds?.length?` (${e.sourceIds.join(", ")})`:"";return`- [${e.status==="closed"?"x":" "}] ${e.id}: ${e.question}${r}`}).join(`
|
|
357
|
+
`)}function ae(t,e="None recorded."){let r=B(t);return r.length?r.map((n)=>`- ${n}`).join(`
|
|
358
|
+
`):e}async function El({query:t,rounds:e,sources:r,fetchedSources:n,evidenceItems:a=[],synthesis:l,citationAudit:i,floor:f,manifest:o,allGaps:g=[],questions:p=[],outDir:h=null}){let m=new Date().toISOString().replaceAll(/[:.]/g,"-").slice(0,19),c=h||D(Ka,`${m}_${Ua(t)}`),y=D(c,"reports"),b=D(c,"sources"),w=D(c,"data");te(y,{recursive:!0}),te(b,{recursive:!0}),te(w,{recursive:!0});let k=await le(n,b),C=B([...g,...e.flatMap((_)=>_.gaps||[])]);return W(D(c,"STATUS.md"),[f.floorMet?"STATUS: DONE":"STATUS: PARTIAL","",`Query: ${t}`,`Stop reason: ${o.terminationReason||"max_rounds"}`,"","## Deterministic floor checks",...Object.entries(f.checks).map(([_,s])=>`- [${s?"x":" "}] ${_}`),"","## Questions",Dl(p),"","## Open gaps",ae(C),""].join(`
|
|
359
359
|
`),"utf8"),W(D(c,"OUTLINE.md"),["# Research bundle outline","","- `reports/SUMMARY.md` — final cited report","- `reports/CLAIMS.md` — extracted claims with support/source IDs","- `reports/EVIDENCE.md` — goal-based source evidence","- `reports/GAPS.md` — remaining caveats and uncertainties","- `sources/` — fetched source markdown files","- `data/manifest.json` — machine-readable run metadata","- `data/rounds.json` — per-round actions/learnings/gaps","- `data/sources.json` — ranked source registry","- `data/questions.json` — open/closed question ledger",""].join(`
|
|
360
360
|
`),"utf8"),W(D(y,"SUMMARY.md"),String(l.answer||""),"utf8"),W(D(y,"CLAIMS.md"),["# Key claims","",...Array.isArray(l.claims)&&l.claims.length?l.claims.map((_)=>{let s=Array.isArray(_.sourceIds)?_.sourceIds.join(", "):"";return`- ${_.claim||""} (${_.support||"support unknown"}${s?`; ${s}`:""})`}):["No structured claims were extracted."],""].join(`
|
|
361
361
|
`),"utf8"),W(D(y,"EVIDENCE.md"),["# Extracted evidence","",...a.length?a.map((_)=>[`## ${_.sourceId||_.url||"Source"}`,_.url?`<${_.url}>`:"",_.rational?`**Rational:** ${_.rational}`:"",_.evidence?`**Evidence:** ${_.evidence}`:"",_.summary?`**Summary:** ${_.summary}`:"",""].filter(Boolean).join(`
|
|
362
362
|
`)):["No goal-based evidence was extracted."],""].join(`
|
|
363
|
-
`),"utf8"),W(D(y,"GAPS.md"),["# Gaps and caveats","","## Caveats",
|
|
363
|
+
`),"utf8"),W(D(y,"GAPS.md"),["# Gaps and caveats","","## Caveats",ae(l.caveats||[]),"","## Research gaps",ae(C),""].join(`
|
|
364
364
|
`),"utf8"),W(D(w,"manifest.json"),JSON.stringify({...o,floor:f,citationAudit:i},null,2),"utf8"),W(D(w,"rounds.json"),JSON.stringify(e,null,2),"utf8"),W(D(w,"sources.json"),JSON.stringify(r,null,2),"utf8"),W(D(w,"questions.json"),JSON.stringify(p,null,2),"utf8"),W(D(w,"evidence.json"),JSON.stringify(a,null,2),"utf8"),W(D(b,"index.md"),["# Source index","",...k.map((_)=>{let s=_.title||_.url,N=_.finalUrl||_.url,R=_.contentPath?` — ${_.contentPath}`:"";return`- ${_.id||"?"}: [${s}](${N})${R}`}),""].join(`
|
|
365
|
-
`),"utf8"),{dir:c,statusPath:D(c,"STATUS.md"),summaryPath:D(y,"SUMMARY.md"),manifestPath:D(w,"manifest.json"),sourceCount:k.length,sourceFiles:k}}async function
|
|
365
|
+
`),"utf8"),{dir:c,statusPath:D(c,"STATUS.md"),summaryPath:D(y,"SUMMARY.md"),manifestPath:D(w,"manifest.json"),sourceCount:k.length,sourceFiles:k}}async function Tf({query:t,breadth:e=3,iterations:r=2,maxSources:n,locale:a=null,short:l=!1,qualityThreshold:i=8.5,writeBundle:f=process.env.GREEDY_RESEARCH_BUNDLE!=="0",researchOutDir:o=null}={}){let g=Xa({breadth:e,iterations:r,maxSources:n}),p=[],h=[],m=[],c=kl(t),y=null,b=[],w=[],k=[],C=new Set,_=new Set,s=new Set,N=[],R="max_rounds",Wr=new Date().toISOString(),Mr=Date.now(),fe=0,ge=0,oe=0,pe=[];process.stderr.write(`[greedysearch] Research mode: breadth ${g.breadth}, iterations ${g.iterations}, qualityThreshold ${i}, engines ${Jt.join(",")}, synthesizer gemini
|
|
366
366
|
`);for(let v=0;v<g.iterations;v++){let E=v+1,J=Math.max(1,Math.ceil(g.breadth/2**v));if(process.stderr.write(`PROGRESS:research:round-${E}:planning
|
|
367
367
|
`),!y)try{let $=await x(el(t,J,h,m,[...s]),{timeoutMs:120000}),j=fl($,J);if(v===0)j.unshift({type:"search",query:t,researchGoal:"Original user query"});j=await il(j,s),y=j}catch($){process.stderr.write(`[greedysearch] Action planning failed, using fallback queries: ${$.message}
|
|
368
368
|
`);let j=xa(null,t,J,{includeOriginal:v===0,exclude:_});y=gl(j)}let z=(y||[]).filter(($)=>{if($.type==="search"){let j=!Or($.query,_,{roundIndex:v,originalQuery:t});if(!j)process.stderr.write(`[greedysearch] Novelty gate rejected search: ${$.query}
|
|
369
369
|
`);return j}if($.type==="fetchUrl"){let j=!s.has($.url);if(!j)process.stderr.write(`[greedysearch] Novelty gate rejected fetch: ${$.url}
|
|
370
|
-
`);return j}return!1}).slice(0,J),
|
|
370
|
+
`);return j}return!1}).slice(0,J),we=vl(b,s);if(!z.some(($)=>$.type==="fetchUrl")&&we.length>0){let $=we[0];z.push({type:"fetchUrl",url:$.url,researchGoal:`Direct fetch of known academic source: ${$.label||$.url}`}),process.stderr.write(`[greedysearch] Forced fetchUrl for academic source: ${$.url}
|
|
371
371
|
`)}let S=[];for(let $=0;$<z.length;$++){let j=z[$];process.stderr.write(`PROGRESS:research:round-${E}:action-${$+1}/${z.length}
|
|
372
372
|
`),process.stderr.write(`[greedysearch] Action ${$+1}/${z.length} [${j.type}]: ${(j.query||j.url).slice(0,80)}
|
|
373
|
-
`);let Y=await rl(j,{locale:a,short:l,usedQueries:_,usedUrls:s,maxChars:8000});if(S.push(Y),
|
|
374
|
-
`)}let
|
|
375
|
-
`);let $=await Ia(b,Math.min(
|
|
373
|
+
`);let Y=await rl(j,{locale:a,short:l,usedQueries:_,usedUrls:s,maxChars:8000});if(S.push(Y),fe++,j.type==="search")ge++;if(j.type==="fetchUrl")oe++;if(!Y.ok)pe.push({round:E,type:j.type,target:j.query||j.url,error:Y.error}),process.stderr.write(`[greedysearch] Action failed: ${Y.error}
|
|
374
|
+
`)}let $e=S.filter(($)=>$.action.type==="search"),ce=S.filter(($)=>$.action.type==="fetchUrl");vt(c,{roundNumber:E,actions:S}),b=bl([b,$e.flatMap(($)=>$.sources||[]),ce.flatMap(($)=>$.sources||[])]);for(let $ of ce)if($.fetchResult)w.push($.fetchResult);w=Tr(w);let Ct=Math.max(0,g.maxSources-w.filter(($)=>$?.content||$?.contentChars>100).length);if(Ct>0&&b.length>0){process.stderr.write(`PROGRESS:research:round-${E}:fetching
|
|
375
|
+
`);let $=await Ia(b,Math.min(Ct,b.length),8000,Math.min(3,Ct||1));w=Tr([...w,...$]),b=se(b,w)}w=Nr(w,b),process.stderr.write(`PROGRESS:research:round-${E}:evidence
|
|
376
376
|
`);let u=await hl({query:t,questions:c,fetchedSources:w,extractedSourceKeys:C});if(u.error)process.stderr.write(`[greedysearch] Evidence extraction failed: ${u.error}
|
|
377
|
-
`);k=[...k,...u.evidence];for(let $ of u.evidence)
|
|
378
|
-
`);let H={learnings:[],followUpQueries:[],gaps:[]},
|
|
379
|
-
`)}let
|
|
380
|
-
`);let L=await qa(t,p,h,m,N);N.push(L.score),m=B([...m,...L.knowledgeGaps||[]]),
|
|
381
|
-
`),L.score>=i&&
|
|
377
|
+
`);k=[...k,...u.evidence];for(let $ of u.evidence)vt(c,{roundNumber:E,learningPayload:{answeredQuestions:$.answers||[],newQuestions:$.newQuestions||[]}});let Hr=S.map(($)=>({query:$.action.query||$.action.url||"",researchGoal:$.action.researchGoal||""}));process.stderr.write(`PROGRESS:research:round-${E}:learning
|
|
378
|
+
`);let H={learnings:[],followUpQueries:[],gaps:[]},me="";try{let $=await x(wl(t,Hr,$e.map((j)=>({query:j.action.query,researchGoal:j.action.researchGoal,error:j.error||"",engines:tl(j.result)})),w,c,k),{timeoutMs:120000});H={...H,...lt($,H)}}catch($){me=$.message,process.stderr.write(`[greedysearch] Learning extraction failed: ${$.message}
|
|
379
|
+
`)}let be=Array.isArray(H.learnings)?H.learnings.map(($)=>String($)).filter(Boolean).slice(0,8):[],Nt=Array.isArray(H.gaps)?H.gaps.map(($)=>String($)).filter(Boolean).slice(0,6):[];h=B([...h,...be]),m=B([...m,...Nt]),vt(c,{roundNumber:E,actions:[],learningPayload:H,gaps:Nt}),p.push({round:E,actions:S.map(($)=>({type:$.action.type,query:$.action.query||"",url:$.action.url||"",researchGoal:$.action.researchGoal||"",error:$.error||"",sourceCount:$.sources?.length||0})),learnings:be,gaps:Nt,evidence:u.evidence,evidenceError:u.error,learningError:me}),process.stderr.write(`PROGRESS:research:round-${E}:evaluating
|
|
380
|
+
`);let L=await qa(t,p,h,m,N);N.push(L.score),m=B([...m,...L.knowledgeGaps||[]]),vt(c,{roundNumber:E,gaps:L.knowledgeGaps||[]});let ye=Cr({sources:b,fetchedSources:w,gaps:m,questions:c,rounds:p,qualityScore:L.score,qualityThreshold:i,maxSources:g.maxSources,requireCitations:!1,requireQuestions:!1});if(process.stderr.write(`[greedysearch] Quality score round ${E}: ${L.score.toFixed(1)} (shouldContinue: ${L.shouldContinue}, floor: ${ye.floorMet})
|
|
381
|
+
`),L.score>=i&&ye.floorMet&&(!L.shouldContinue||L.terminationReason==="quality_threshold")){R=L.terminationReason||"quality_threshold",process.stderr.write(`[greedysearch] Research floor reached (score: ${L.score.toFixed(1)}). Terminating early.
|
|
382
382
|
`);break}let I=Math.max(1,Math.ceil(J/2)),F=(H.followUpQueries||[]).map(($)=>({type:"search",query:A(String($)),researchGoal:"Follow-up from learning extraction"})).filter(($)=>$.query&&$.query.toLowerCase()!==t.toLowerCase()).slice(0,I);if(F.length<I&&L.nextActions.length>0){let $=L.nextActions.map((Y)=>Pr(Y)).filter(Boolean);F=[...F,...$].slice(0,I)}if(F.length<I&&m.length>0){let $=ua(m,t,_,I-F.length,v+1),j=$.map((Y)=>({type:"search",query:Y.query,researchGoal:Y.researchGoal}));if(F=[...F,...j].slice(0,I),$.length>0)process.stderr.write(`[greedysearch] Generated ${$.length} gap-driven fallback actions.
|
|
383
383
|
`)}y=F.length>=I?F:null}process.stderr.write(`PROGRESS:research:final-report
|
|
384
384
|
`);let O={answer:h.length?h.map((v)=>`- ${v}`).join(`
|
|
@@ -386,6 +386,6 @@ ${r.map((f)=>`- ${f}`).join(`
|
|
|
386
386
|
`),O.error=v.message}if(!(O.synthesized===!0&&Array.isArray(O.claims)&&O.claims.length>0)&&k.length>0){process.stderr.write(`[greedysearch] Falling back to evidence-based synthesis (no per-round learnings).
|
|
387
387
|
`);try{let v=cl(t,b,c,k),E=await x(v,{timeoutMs:180000}),J=lt(E,{});O={...O,...J,rawAnswer:E.answer||O.answer||"",geminiSources:E.sources||O.geminiSources||[],synthesized:!0,synthesisMode:"evidence_fallback"}}catch(v){process.stderr.write(`[greedysearch] Evidence-based synthesis failed: ${v.message}
|
|
388
388
|
`),O.evidenceFallbackError=v.message}}let Ar=new Date().toISOString(),Rr=Date.now()-Mr,Jr=N.at(-1)||0;w=Nr(w,b),process.stderr.write(`PROGRESS:research:audit-citations
|
|
389
|
-
`);let it=_l(O.answer||"",b);jl(c,O,it);let Q=Cr({sources:b,fetchedSources:w,synthesis:O,citationAudit:it,gaps:m,questions:c,rounds:p,qualityScore:Jr,qualityThreshold:i,maxSources:g.maxSources});if(Q.floorMet&&R==="max_rounds")R="done_floor_met";else if(!Q.floorMet&&R==="quality_threshold")R="max_rounds_floor_unmet";let
|
|
390
|
-
`);try{tt=await El({query:t,rounds:p,sources:b,fetchedSources:w,evidenceItems:k,synthesis:O,citationAudit:it,floor:Q,manifest:
|
|
391
|
-
`),{query:t,_research:{mode:"iterative",breadth:g.breadth,iterations:g.iterations,maxSources:g.maxSources,rounds:p,learnings:h,gaps:m,evidence:k,questions:c,questionProgress:
|
|
389
|
+
`);let it=_l(O.answer||"",b);jl(c,O,it);let Q=Cr({sources:b,fetchedSources:w,synthesis:O,citationAudit:it,gaps:m,questions:c,rounds:p,qualityScore:Jr,qualityThreshold:i,maxSources:g.maxSources});if(Q.floorMet&&R==="max_rounds")R="done_floor_met";else if(!Q.floorMet&&R==="quality_threshold")R="max_rounds_floor_unmet";let he={startedAt:Wr,finishedAt:Ar,durationMs:Rr,engines:Jt,synthesizer:"gemini",rounds:p.length,actionsRun:fe,searches:ge,fetches:oe,sourcesFetched:w.filter((v)=>v?.contentChars>100).length,engineFailures:pe,terminationReason:R,floorMet:Q.floorMet},tt=null,ft;if(f){process.stderr.write(`PROGRESS:research:bundle
|
|
390
|
+
`);try{tt=await El({query:t,rounds:p,sources:b,fetchedSources:w,evidenceItems:k,synthesis:O,citationAudit:it,floor:Q,manifest:he,allGaps:m,questions:c,outDir:o}),ft=tt.sourceFiles,delete tt.sourceFiles}catch(v){tt={error:v.message||String(v)},ft=await le(w)}}else ft=await le(w);return process.stderr.write(`PROGRESS:research:done
|
|
391
|
+
`),{query:t,_research:{mode:"iterative",breadth:g.breadth,iterations:g.iterations,maxSources:g.maxSources,rounds:p,learnings:h,gaps:m,evidence:k,questions:c,questionProgress:ie(c),qualityHistory:N,terminationReason:R,qualityThreshold:i,floor:Q,bundle:tt,manifest:he},_citationAudit:it,_sources:b,_fetchedSources:ft,_synthesis:O,_confidence:{sourcesCount:b.length,fetchedSourceSuccessRate:w.length>0?Number((w.filter((v)=>v.contentChars>100).length/w.length).toFixed(2)):0,agreementLevel:O.agreement?.level||"mixed",floorMet:Q.floorMet}}}function Tr(t){let e=new Map;for(let n of t){let a=n?.id||M(n?.finalUrl||n?.url||"");if(!a)continue;let l=e.get(a);if(!l||(n.contentChars||0)>(l.contentChars||0))e.set(a,n)}let r=[];for(let n of e.values()){let a=String(n.content||n.snippet||""),l=r.findIndex((i)=>{let f=String(i.content||i.snippet||"");if(a.length<400||f.length<400)return!1;return Et(a.slice(0,4000),f.slice(0,4000))>=0.9});if(l===-1){r.push(n);continue}if((n.contentChars||0)>(r[l].contentChars||0))r[l]=n}return r}export{Pr as validateAction,vt as updateQuestionLedger,Er as tokenSet,Tf as runResearchMode,Za as resolveGreedySearchSearchScript,gl as queriesToActions,fl as parseActionPlan,xa as normalizeResearchQueries,Et as jaccardSimilarity,Or as isDuplicateQuery,kl as createQuestionLedger,Cr as computeResearchFloor,Xa as clampResearchOptions,ua as buildFallbackQueriesFromGaps,_l as auditCitations};
|