@lincoln504/pi-research 1.7.22 → 1.7.24

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.
@@ -2123,9 +2123,13 @@ function getSocksProxyEndpoint() {
2123
2123
  return cached;
2124
2124
  }
2125
2125
  const cfg = JSON.parse(readFileSync(file, "utf8"));
2126
- const host = cfg.host ?? "127.0.0.1";
2127
- const port = cfg.port ?? 1080;
2128
- cached = host ? { host, port } : null;
2126
+ const host = cfg.host === void 0 ? "127.0.0.1" : typeof cfg.host === "string" ? cfg.host.trim() : "";
2127
+ const port = cfg.port === void 0 ? 1080 : Number.isInteger(cfg.port) ? cfg.port : -1;
2128
+ if (host === "" || port < 1 || port > 65535) {
2129
+ cached = null;
2130
+ return cached;
2131
+ }
2132
+ cached = { host, port };
2129
2133
  return cached;
2130
2134
  } catch {
2131
2135
  cached = null;
@@ -2147,9 +2151,7 @@ function loadSocksProxyPrefs() {
2147
2151
  function isProxyHopAddress(ip, proxy = getSocksProxyEndpoint()) {
2148
2152
  if (!proxy) return false;
2149
2153
  const addr = ip.trim().toLowerCase().replace(/^\[|\]$/g, "");
2150
- if (addr === "" || addr === "0.0.0.0" || addr === "::" || addr === "::0") return true;
2151
- const proxyHost = proxy.host.trim().toLowerCase().replace(/^\[|\]$/g, "");
2152
- return addr === proxyHost;
2154
+ return addr === "" || addr === "0.0.0.0" || addr === "::" || addr === "::0";
2153
2155
  }
2154
2156
 
2155
2157
  // src/infrastructure/browser/thread-worker-messaging.ts
package/docs/CHANGELOG.md CHANGED
@@ -5,6 +5,145 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.7.24] - 2026-10-30
9
+
10
+ ### Fixed
11
+
12
+ - **The SOCKS proxy forwarded requests one way and black-holed every response.** 1.7.23 replaced
13
+ `client.pipe(upstream); upstream.pipe(client);` with `pipeline([client, upstream], ...)` while
14
+ closing an fd leak. `pipeline([a, b])` means `a → b`, so the return path was removed: the proxy
15
+ accepted the SOCKS handshake, connected upstream, forwarded the client's request, and never sent
16
+ a byte back. Every browser request through a configured proxy therefore timed out, and every
17
+ research run with `~/.pi/research/proxy.json` present failed: `Search completely failed: all 36
18
+ queries encountered worker errors` after seven minutes, twice on 2026-10-30, plus a 32-query run
19
+ on 2026-10-29. The tunnel is now two directional `pipeline()` calls, which keeps the fd-leak fix
20
+ (both sockets are still destroyed when either ends) and restores the return path. Normal tunnel
21
+ teardown no longer logs `Premature close` once per request. The tunnel wiring moved into an
22
+ exported `attachTunnel()` so it can be tested without network egress:
23
+ `test/unit/scripts/ddg-socks-proxy-tunnel.test.ts` pins both directions and the teardown rule.
24
+ The published 1.7.23 npm tarball carries the broken script, so upgrading is the only fix for a
25
+ consumer who runs the shipped proxy.
26
+ - **`pipeline()` throws on a dead endpoint, and the throw lands where nothing catches it.** Browsers
27
+ open speculative SOCKS connections and drop them, and the proxy's own 8s data deadline cuts both
28
+ ends on a stall, so `attachTunnel` regularly runs against an already-destroyed socket.
29
+ `pipeline()` raises `ERR_STREAM_UNABLE_TO_PIPE` synchronously, and the call sits inside a
30
+ socket `'connect'` handler — outside every promise chain and `try` in the file — so it killed the
31
+ daemon. Measured while validating this release: 20 restarts in 25 minutes, every one this
32
+ error. Attaching to a dead pair is now a no-op, the attach path is wrapped, half-close and
33
+ already-dead teardown no longer log, and the crash guards have tests.
34
+ - **The proxy now exits non-zero when it cannot listen.** `server.on('error')` logged the failure
35
+ and left the process running without a listening socket, the one state a supervisor cannot see:
36
+ `Restart=always` never fires and every browser request fails at connect. It exits so the
37
+ supervisor retries. This covers `EADDRINUSE` (port already taken) and other listen failures such
38
+ as `EACCES`.
39
+ - **The main-module guard broke when the script was installed as a symlink.** It compared
40
+ `process.argv[1]` with `import.meta.url` as strings. The documented install links
41
+ `~/.pi/research/scripts/ddg-socks-proxy.mjs` to the copy in the repo, so `argv[1]` is the symlink
42
+ and `import.meta.url` is the real path: the comparison says "imported", the proxy exits 0 without
43
+ ever listening, and the supervisor reports a healthy service that refuses every connection. (A
44
+ symlinked directory with a relative entry is fine — Node resolves the cwd. A symlinked script
45
+ file is not.) It now compares real paths (`realpathSync`), and a test spawns the script through a
46
+ temp symlink and asserts it reaches "listening".
47
+ - **A broken proxy reported a clean bill of health.** `health` proved only that the browser was
48
+ installed (`BrowserCapability` never touches the network) and `BrowserRuntime` returns
49
+ `ready (idle)` without probing when the scheduler is idle, so a one-way tunnel produced "All
50
+ systems operational" while every search failed. There is now a **critical** `SocksProxy` health
51
+ component: when `proxy.json` exists it speaks SOCKS5 to the proxy, sends one request to
52
+ **DuckDuckGo's own front door** (`lite.duckduckgo.com:80`, which exercises the proxy's pinned
53
+ addresses rather than ordinary DNS), and requires **bytes back**, because the observed failure
54
+ accepts the handshake and then forwards nothing. If DuckDuckGo answers nothing it probes a
55
+ neutral host, so the report distinguishes "the tunnel is dead" (restart the proxy) from "the
56
+ tunnel works but DuckDuckGo's pinned front doors are dead" (repin or drop the proxy). Explicit
57
+ 4s/5s per-probe budgets keep the pair inside the 25s registration timeout.
58
+ `src/infrastructure/browser/proxy-health.ts`; tests `test/unit/infrastructure/proxy-health.test.ts`
59
+ cover the healthy path, a black-holed tunnel, a ruleset refusal, a refused connection, a
60
+ non-SOCKS greeting, the not-configured case, the dead-pin/neutral-host split, the two-sample
61
+ retry, and abort handling.
62
+ - **A broken proxy is no longer mistaken for a busy pool.** `isBusyPoolHealthFailure` treats any set
63
+ of timeout-shaped probe failures as "pool busy, proceed" so sustained load cannot abort a healthy
64
+ run. A dead proxy produces exactly that signature, so the gate always said "operational" and let
65
+ the whole search burst run into the dead tunnel. An unhealthy `SocksProxy` now makes the gate
66
+ return false. Test: `test/unit/healthcheck/index.test.ts`.
67
+ - **A deep run now checks the proxy before it searches.** Only the quick orchestrator and the UI
68
+ health gate ran a pre-flight check, so a deep run spent its entire burst first. The orchestrator
69
+ probes at the start (3s connect + 3s data, a second sample at 3s/4s, then the neutral-host check)
70
+ and fails immediately with the diagnosis. It requires two failed samples before stopping a run,
71
+ because one refused connect during a proxy restart must not abort work the next probe would
72
+ clear. The run's `AbortSignal` is passed through, so Esc during a dead proxy's probe sequence
73
+ cancels at once instead of waiting it out. The deep start path is covered by
74
+ `test/integration/research-workflow.test.ts`; the diagnostic path it calls is unit-tested.
75
+ - **`Search completely failed` now names a broken proxy instead of listing three guesses.** When the
76
+ proxy probe fails on the total-failure path, the error says what is wrong and what to do, rather
77
+ than "Browser workers may be unavailable, DuckDuckGo is unreachable, or the system is under
78
+ extreme load".
79
+ - **A 5xx with a stated cool-off burned the retry budget in seconds and killed the run** (issue
80
+ #22, "503 + provider Retry-After > 60s is retried 3x at 1s/2s and kills the whole run": eight
81
+ consecutive runs lost on 2026-10-28 while the search burst had already collected 48-104 results).
82
+ Gaps closed in `src/utils/provider-errors.ts` and the retry callers:
83
+ - `isRateLimitError` now classifies the 5xx overload class as capacity, so it takes the long-wait
84
+ path instead of the ordinary 1s/2s curve. The numeric match is anchored to status context
85
+ (`http`/`status`/`code`/`error`/`response`/`returned`, or a 5xx followed by a provider/gateway
86
+ word) so a message that merely contains "502ms" or "max_tokens=500" is not misread as an
87
+ outage — this classifier also drives the run-level stop threshold.
88
+ - `parseRetryAfterMs` now reads pi's own sentence — `Server requested 120s retry delay (max:
89
+ 60s)` — which is the only statement of when the pool reopens, plus the prose `retry after Ns`
90
+ form. Its doc comment no longer claims the 60s exponential ceiling applies to a stated window.
91
+ - A stated window is no longer clamped to 60s. 60s is the ceiling for the **exponential**
92
+ backoff, not for a window the provider stated: clamping 120s to 60s guaranteed the next attempt
93
+ failed too. Stated windows are honoured up to 180s (`STATED_RETRY_AFTER_MAX_MS`) and the
94
+ exponential fallback keeps its 60s ceiling.
95
+ - Total capacity waiting per researcher is bounded at 240s
96
+ (`RATE_LIMIT_TOTAL_WAIT_MAX_MS`). Past it the loop stops and reports the provider's window and
97
+ the time to rerun ("Rerun after 22:10:00Z") instead of sleeping into the run timeout and
98
+ reporting a failure with no cause.
99
+ - The planner/router/synthesizer retries now take the same total bound (`maxTotalDelayMs` in
100
+ `retryWithBackoff`, set to `RATE_LIMIT_TOTAL_WAIT_MAX_MS` in `planning-service.ts`). Their
101
+ per-attempt delay already honoured a stated window; without a sum bound, two 180s windows were
102
+ six minutes of sleeping inside one 900s run. Tests: `test/unit/utils/provider-errors.test.ts`
103
+ (classification and stated windows) and `test/unit/web-research/retry-utils.test.ts` (the
104
+ total-wait cap).
105
+
106
+ ### Documentation
107
+
108
+ - **`docs/TROUBLESHOOTING.md` gained the two failures that actually happened:** every search failing
109
+ with "all N queries encountered worker errors" (proxy diagnosis in five steps, including the one
110
+ `curl` that proves forwarding, and the reminder that a supervisor keeps the code it started with),
111
+ and "`health` says everything is OK but nothing can be searched" (what `health` did and did not
112
+ prove, and what the `SocksProxy` component now reports).
113
+ - **The proxy section now ships a systemd unit** instead of "run under cron", and states the
114
+ failure mode the pins have: they are a snapshot of DuckDuckGo's front doors, so both dying at once
115
+ cannot self-heal. `docs/CONFIGURATION.md` says the proxy is critical when configured and that
116
+ `DDG_PIN_IPS` needs a restart.
117
+
118
+ ## [1.7.23] - 2026-10-26
119
+
120
+ ### Security
121
+
122
+ - **The `undici` floor admits three advisories for consumers.** `package.json` declared `undici ^8.11.2` (and the `jsdom` override `^8.10.2`), and the ranges `>=8.0.0 <8.12.2` carry GHSA-xjj6-f33q-929c (unhandled error on excessive content-encodings, CVSS 7.5), GHSA-4qv8-2p9j-2685 (unbounded memory in the EventSource parser) and GHSA-f72v-6w45-q472 (SRI bypass). This repo's own lock was already at 8.12.3, but the tarball ships no lockfile and npm `overrides` do not reach consumers — a consumer's hoisted `undici` only has to Satisfy `^8.11.2`, and the scraper uses `undici`'s `fetch` against hostile servers, so the content-encoding crash is reachable there. The floor is now `^8.12.2` in both places.
123
+ - **`SECURITY.md` claimed `*.key` files are refused; the read guard did not refuse them.** The `DENIED_BASENAME` list had no `key` extension, so `server.key`, `private.key` and `tls.key` were readable by a researcher session — the exfiltration path the guard exists to close. The list now covers `*.key`, the `id_*_sk` key forms (`id_ecdsa_sk`, `id_rsa_sk` — the `id_*` pattern only accepted a dot suffix), `.dockerconfigjson`, and the `.terraform` directory (credential directory, now in `DENIED_SEGMENTS`). Tests: `test/unit/tools/read-guard.test.ts`.
124
+ - **The standalone SOCKS proxy's IPv6 guard had drifted from the TS classifier.** `scripts/lib/private-addresses.mjs` claims to mirror `isPrivateIpv6` in `src/web-research/scraper-utils.ts`, but was missing the IPv4-tunneling ranges: site-local `fec0::/10`, 6to4 `2002::/16`, Teredo `2001:0::/32` and NAT64 `64:ff9b::/96` — literals like `64:ff9b::a9fe:a9fe` (the cloud-metadata address via NAT64) passed the guard. With the proxy the only SSRF backstop for proxied traffic, that was a live hole. The ranges are now ported with parity tests, and the port also fixed a pre-existing gap the TS classifier does not have: the `fc00::/7` check only covered `fc::` and missed `fd::`. Teredo is checked as `2001:0::/32` (second hextet zero), NOT the whole `2001::/32`, so public DNS like `2001:4860:4860::8888` stays allowed.
125
+ - **The browser's rebinding backstop exempted the proxy host itself.** `isProxyHopAddress` treated an origin address equal to the configured proxy host (normally `127.0.0.1`) as "the hop" and skipped the check — but with the proxy on loopback, an origin of `127.0.0.1` is indistinguishable from a genuine loopback origin, which the guard must poison. Measured camoufox behaviour reports the hop as `0.0.0.0`, which the unspecified-address exemption still covers, so dropping the host equality loses no legitimate scrape. `getSocksProxyEndpoint` now also type-checks `host`/`port` from the JSON (a numeric host or an out-of-range port means "no proxy", not a nonsense endpoint). Tests: `test/unit/infrastructure/thread-worker-ssrf-subresource.test.ts`.
126
+ - **The SOCKS proxy leaked memory and file descriptors, and its logs were injectable.** (a) The handshake `data` listener stayed attached after the handshake, so `buf` grew without bound for the lifetime of every long-lived proxied connection — it is now detached at the handshake's end and capped at 4096 bytes (a well-formed SOCKS request is under 300 bytes). (b) `client.pipe(upstream)` / `upstream.pipe(client)` left the upstream socket open on a client RST (fd leak); `stream.pipeline` now destroys both ends when either ends. (c) `targetHost` is raw domain bytes from a SOCKS client and can carry newlines into the cron log (CodeQL `js/log-injection`); it is now `JSON.stringify`-ed. (d) A refused connection to ANY host rotated the DuckDuckGo pin index, shifting pin order for unrelated destinations; rotation now only applies to DDG hosts. Tests: `test/unit/scripts/ddg-socks-proxy-guard.test.ts`, `test/unit/scripts/private-addresses.test.ts`.
127
+ - **Seven open CodeQL alerts, all now fixed.** `js/log-injection` ×2 in `scripts/ddg-socks-proxy.mjs` (the log-injection above), `js/insecure-temporary-file` in `test/unit/infrastructure/thread-worker-ssrf-subresource.test.ts` (the proxy-config temp file now uses `mkdtemp` at 0700 + a 0600 write), and `js/unused-local-variable` ×4 in `scripts/lib/private-addresses.mjs` (the hextet destructure now takes only the hextets it uses).
128
+ - **Hand-rolled SQL quoting, in eight places, is now one helper.** Every DataFusion string literal in the knowledge store was built by a local `.replace(/'/g, "''")` on attacker-influenced input (stored URLs, workspace paths, ingestion types). `src/knowledge/sql-utils.ts` `sqlString()` is now the single escaping rule, used at all nine sites (`store.ts`, `store-operations.ts`), with tests pinning the doubled-quote rule and the absence of any backslash/backtick/newline rule. `test/unit/knowledge/sql-utils.test.ts`.
129
+ - **The guarded `read` had a check-then-use TOCTOU.** `assertReadAllowed` resolves symlinks, then `readFile(p)` runs a moment later: a local attacker with write access to the project can swap `p` for a symlink in between. The read now opens with `O_NOFOLLOW` (a final-component symlink is refused at open with `ELOOP`), stats the fd (only regular files are read), and reads through the fd, so the bytes come from the file the fd points at. The residual gap — an *intermediate* path component swapped for a directory symlink — cannot be closed with Node's public API (no `openat` walk); it requires a local attacker with write access to the project and no read access elsewhere, and is rated Low and documented in `SECURITY.md`. Test: the final-component-symlink backstop in `test/unit/tools/read-guard.test.ts`.
130
+
131
+ ### Fixed
132
+
133
+ - **The `retry-utils` jitter comment was wrong.** It said "±50% jitter"; the code applies `0–50%` positive jitter. The comment now says so.
134
+ - **CI scripts no longer build shell strings — and now resolve npm as the CLI bundled in the Node distribution.** `scripts/ensure-native-deps.cjs` (two sites) and `scripts/use-npm12.cjs` interpolated `spec` / the npm prefix into `execSync` / `execFileSync` shell strings; both now use argv arrays, so a value read from an installed `package.json` or a `RUNNER_TEMP` path with spaces is never parsed by a shell. The argv arrays exposed a Windows-only failure the shell strings had masked: a bare `npm` in a shell-less spawn is unresolvable on Windows (the npm on PATH is a `.cmd` shim, so `ENOENT`; direct `.cmd` spawns are rejected outright with `EINVAL` since the CVE-2024-27980 hardening in Node 18.20.2 / 20.12.2 / 21.7.3, so `npm.cmd` is not a fix; `shell: true` would re-parse the arguments the hardening removed). `scripts/lib/npm-cmd.cjs` resolves the npm CLI bundled inside the Node distribution (`<node-dir>/node_modules/npm/bin/npm-cli.js` — the nodejs.org/CI layout — or `<node-dir>/../lib/node_modules/npm/bin/npm-cli.js` — the nvm/Homebrew layout) and runs it directly with the Node binary: no PATH lookup, no shim, no shell, arguments stay a clean argv array. `scripts/use-npm12.cjs` (the "Use npm 12" step of every CI leg — the step that was dying with `spawnSync npm ENOENT` on both windows-latest legs) and `scripts/ensure-native-deps.cjs` use it. Test: `test/unit/scripts/npm-cmd.test.ts`.
135
+ - **`madge` is a devDependency, not an `npx --yes` fetch.** The `dep-graph` CI job ran `npx --yes madge@8.0.0` with `contents: write` permissions and `persist-credentials: false`; the unlocked transitive tree of an `npx` fetch is the one uncontrolled install in that job. `deps:generate` now runs the pinned devDependency.
136
+
137
+ ### Changed
138
+
139
+ - **`@typescript-eslint` recommended ruleset enabled.** The ESLint config applied `@typescript-eslint/no-unused-vars` only; the full recommended ruleset (23 rules) now runs over `src/`. The three `ban-ts-comment` findings it surfaced were dead `@ts-ignore` suppressions (the suppressed lines are error-free, which is why `@ts-ignore` and not `@ts-expect-error` was used) — removed, leaving the explanatory text as plain comments. `no-explicit-any` is set to **warn**, not off: 333 sites across 70 files, each a boundary type (camoufox/Playwright JSON, LLM responses) needing a deliberate shape decision. It is a tracked warning surfaced by every lint run, not a silenced rule; the full `any → unknown + narrowing` pass is its own project and must not ride on a security release.
140
+ - **`youtubei.js` 18.2.0 → 18.3.0** (lock refresh; the range was already `^18.0.0`), **`webgpu` 0.6.0 → 0.6.2** (the `^0.6.0` range resolved forward on the refresh), and the local `node_modules` was re-synced to the lock (`impit` was at 0.14.6 against 0.14.7 in `package.json` and the lock).
141
+
142
+ ### Documentation
143
+
144
+ - **Four env vars were read by the code but undocumented in `.env.example` and `docs/CONFIGURATION.md`:** `PI_RESEARCH_PROXY_JSON` (SOCKS proxy config file path), `DDG_SOCKS_PORT` and `DDG_PIN_IPS` (the local SOCKS proxy's port and pinned DuckDuckGo front-doors, read by `scripts/ddg-socks-proxy.mjs`), and `PI_CODING_AGENT_DIR` (the pi agent directory the standalone engine/launcher reads host config from).
145
+ - **`docs/THIRD-PARTY-NOTICES.md` corrected in two places.** (a) The notice said "no third-party code is inlined"; the browser worker bundle (`dist/thread-worker.mjs` and its shipped copy) inlines `typebox` (MIT) — that is now documented. (b) The `ua-parser-js` section claimed the `overrides` pin keeps "this MIT-licensed package free of AGPL-licensed code in its dependency tree"; an npm `overrides` field only applies to the package that carries it, so a consumer's install resolves camoufox's `^2.0.2` declaration itself and typically installs the 2.x (AGPL) copy. The notice now states that the pin protects this repo's own tree only, that no AGPL code is bundled into or redistributed by this package, and why the pin is behavior-neutral.
146
+
8
147
  ## [1.7.22] - 2026-10-25
9
148
 
10
149
  ### Fixed
@@ -179,6 +179,10 @@ Diagnostics & platform
179
179
  | `PLAYWRIGHT_INSTALL_DEPS` | _(unset)_ | Linux only. Set `true` during `npm install` to also install system libraries via `npx playwright install-deps` (same as `npm run install:system-deps`). |
180
180
  | `PI_RESEARCH_STRICT_SETUP` | _(unset)_ | Read by the bundled `scripts/setup.cjs` during `npm install`. Set `1`/`true` to make a failed browser download fail the install instead of deferring it to first use. |
181
181
  | `PI_RESEARCH_CONFIG_DIR_NAME` | `.pi` | Override the host config-directory name under your home dir (advanced; e.g. set to share another harness's config root). |
182
+ | `PI_RESEARCH_PROXY_JSON` | `~/.pi/research/proxy.json` | Path of the SOCKS proxy config file the browser workers read (`{"host":"127.0.0.1","port":1080}`), routing every browser request through the local SOCKS proxy. Read fresh per scrape, so toggling needs no restart. When the file exists, the proxy is a **critical** health component and a run refuses to start if it is not forwarding. See [Troubleshooting](TROUBLESHOOTING.md). |
183
+ | `DDG_SOCKS_PORT` | `1080` | Port the local SOCKS proxy (`scripts/ddg-socks-proxy.mjs`) listens on. Read by the proxy script, not the main runtime. Supervise it with systemd (see [Troubleshooting](TROUBLESHOOTING.md#the-socks-proxy-refuses-a-url-with-connection-not-allowed-by-ruleset)); a proxy started by hand keeps whatever code it loaded until it is restarted. |
184
+ | `DDG_PIN_IPS` | `52.250.42.157,40.89.244.232` | Pinned DuckDuckGo front-door IPs for the local SOCKS proxy (comma-separated). The proxy rotates past any address that stalls, so the list self-heals; change it only for a different egress path. Both pins dying at once is a real failure mode (DuckDuckGo moves its front doors) — repin, or remove `proxy.json` when direct egress works. |
185
+ | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | Override the pi agent directory the standalone engine/launcher looks in for host config (settings.json, models.json). |
182
186
 
183
187
  Testing only — never enable in production
184
188
 
@@ -5,10 +5,12 @@ license covers this project's own source code only.
5
5
 
6
6
  This package depends on third-party software distributed under its own license
7
7
  terms. Dependencies are resolved and installed by npm at install time (by
8
- reference); they are **not** bundled into this package's published artifacts, with the one exception
9
- below (the esbuild-bundled entry points — `dist/cli.mjs`, `dist/thread-worker.mjs` — are
10
- built with `--packages=external`, and the remaining `dist/` files are copied
11
- first-party sources, so no third-party code is inlined).
8
+ reference); they are **not** bundled into this package's published artifacts, with the
9
+ two exceptions below: `@lancedb/lancedb` is redistributed in the tarball, and the
10
+ esbuild-bundled browser worker `dist/thread-worker.mjs` (and its copy shipped at
11
+ `src/infrastructure/browser/thread-worker.mjs`) inlines exactly one third-party
12
+ package, `typebox` (MIT — see below). `dist/cli.mjs` inlines no third-party code,
13
+ and the remaining `dist/` files are copied first-party sources.
12
14
 
13
15
  ### Bundled third-party code: `@lancedb/lancedb`
14
16
 
@@ -24,6 +26,17 @@ resolve its pinned `@huggingface/transformers` 3.0.2 and `sharp` 0.33.5 (see `do
24
26
  license file in the bundle. The per-platform LanceDB native bindings are NOT bundled; npm installs
25
27
  them separately.
26
28
 
29
+ ### Inlined third-party code: `typebox`
30
+
31
+ The browser worker bundle (`dist/thread-worker.mjs`, and the copy of it shipped at
32
+ `src/infrastructure/browser/thread-worker.mjs`) inlines exactly one third-party
33
+ package: `typebox`, **MIT**, Copyright the TypeBox authors (https://github.com/sinclairtypebox/typebox).
34
+ The worker is a poolifier cluster child: a plain Node process that gets no help from
35
+ pi's extension loader (which aliases the peer `typebox` for in-process code only),
36
+ and `pi install` never installs peers — so `typebox` is bundled into the worker
37
+ rather than resolved at runtime. (`dist/cli.mjs` inlines nothing; only the worker
38
+ bundle does.)
39
+
27
40
  ### Notable dependency licensing
28
41
 
29
42
  camoufox / Camoufox browser
@@ -40,16 +53,19 @@ own license.
40
53
 
41
54
  ua-parser-js
42
55
 
43
- `ua-parser-js` 2.x is licensed under AGPL-3.0-or-later. To keep this MIT-licensed
44
- package free of AGPL-licensed code in its dependency tree, `package.json`
45
- `overrides` pins `ua-parser-js` to the `1.x` line, which is MIT-licensed. The
46
- 1.x and 2.x APIs are compatible for the only surface our direct dependency
47
- (`camoufox`, which declares `^2.0.2`) uses — it calls just
56
+ `ua-parser-js` 2.x is licensed under AGPL-3.0-or-later. `package.json`
57
+ `overrides` pins `ua-parser-js` to the `1.x` line (MIT) **in this package's own
58
+ install tree** — i.e. this repository and its CI. The pin does NOT reach
59
+ consumers: an npm `overrides` field only applies to the package that carries it,
60
+ and the published tarball ships no lockfile, so a consumer's install resolves
61
+ camoufox's declared `ua-parser-js ^2.0.2` itself and typically installs the 2.x
62
+ (AGPL) copy alongside it. That is a property of the consumer's dependency tree,
63
+ not of this package's artifacts: camoufox calls only
48
64
  `new UAParser(ua).getBrowser().name` and `.getOS().name`, both present in 1.x and
49
- verified against the pinned `1.0.41` — and the pin is behavior-neutral for this
50
- package's usage (no custom `navigator.userAgent`/`fingerprint` is passed to Camoufox).
51
- Re-check that surface on every `camoufox` bump: a 2.x-only call would make
52
- this override a runtime break, not just a licensing choice.
65
+ 2.x, so the pin is behavior-neutral here, and no AGPL code is bundled into, or
66
+ redistributed by, this package. Re-check that call surface on every `camoufox`
67
+ bump: a 2.x-only call would make the pin a runtime break, not just a licensing
68
+ choice.
53
69
 
54
70
  youtubei.js / bgutils-js / jsdom (YouTube transcripts)
55
71
 
@@ -70,10 +70,102 @@ Updating fixes it. To confirm the cause on an affected build, disable the proxy
70
70
 
71
71
  **What the fix does and does not cover.** The check it exempts compares the address Firefox actually connected to against the address the hostname resolves to — that comparison is what catches DNS rebinding. A SOCKS5 proxy makes it impossible: Firefox never sees the origin address. So with a proxy configured, a page that rebinds a public hostname to an internal address is not caught at bake time. Two things still apply. Request-time DNS validation still runs on every navigation and every subresource the page pulls in, and rejects a hostname that resolves into private space before the request is allowed out. And `scripts/ddg-socks-proxy.mjs` (the proxy this project ships instructions for) now refuses to CONNECT to a loopback, private, link-local, CGNAT, multicast or reserved destination, checking both the requested host and every address it resolves to. A third-party SOCKS proxy you point `proxy.json` at does not have that guard — do not route through one you do not trust.
72
72
 
73
+ ## Every search fails: "Search completely failed: all N queries encountered worker errors"
74
+
75
+ This is the whole burst failing, not one query. Most of the time it is network reachability for
76
+ the search provider, and the most common local cause is a configured SOCKS proxy that is not
77
+ forwarding. The error now names it when it can:
78
+
79
+ ```
80
+ Search completely failed: all 36 queries encountered worker errors.
81
+ SOCKS proxy check: proxy at 127.0.0.1:1080 completed the SOCKS handshake to lite.duckduckgo.com:80
82
+ but returned no data within 3000ms (...). Every browser request is routed through the configured
83
+ proxy, so no search can succeed until it forwards traffic or ~/.pi/research/proxy.json is removed.
84
+ ```
85
+
86
+ Diagnose in this order.
87
+
88
+ 1. **Is a proxy configured?** `cat ~/.pi/research/proxy.json`. Absent means the browser connects
89
+ directly. Present means 100% of browser traffic goes through it, so a dead proxy is a dead
90
+ system.
91
+ 2. **Is it forwarding?** One command, and it must print an HTTP status code:
92
+ ```bash
93
+ curl -sS -x socks5h://127.0.0.1:1080 -o /dev/null -w '%{http_code}\n' https://example.com/
94
+ ```
95
+ `000` after 15s means the proxy is not returning data. `curl: (97)` means the proxy refused the
96
+ destination (see the ruleset section below).
97
+ 3. **Is the proxy process running the current script?** A systemd unit or a cron job keeps the code
98
+ it started with. After `pi update`, restart it:
99
+ ```bash
100
+ systemctl --user restart ddg-socks-proxy.service # or whatever supervises it
101
+ ```
102
+ Verify what it actually loaded: `systemctl --user show ddg-socks-proxy.service -p ExecStart`.
103
+ 4. **Read the proxy's own log.** With the unit below it goes to journald
104
+ (`journalctl --user -u ddg-socks-proxy -n 50`); a unit that appends to a file puts it in that
105
+ file instead. `connected but sent no data within 8000ms` repeated, or `tunnel closed: Premature
106
+ close` in bulk, means the tunnel is established and nothing comes back.
107
+ 5. **No proxy needed?** Remove it: `mv ~/.pi/research/proxy.json ~/.pi/research/proxy.json.off`.
108
+ The file is read per scrape, so no restart is needed. Do this whenever direct egress works —
109
+ the proxy exists for an egress path that can reach only one DuckDuckGo front-door, and most
110
+ machines do not need it.
111
+
112
+ If the proxy is healthy, the same error means the provider itself: DuckDuckGo timing out, or a
113
+ blocked egress path. Check `PI_RESEARCH_SEARCH_TIMEOUT_MS` (45s by default) against a slow link,
114
+ and try `curl https://lite.duckduckgo.com/lite/` from the same machine.
115
+
116
+ ## `health` says everything is OK but nothing can be searched
117
+
118
+ Fixed in the release that adds the `SocksProxy` health component. Before it, `health` proved only
119
+ that the browser was installed: `BrowserCapability` never touches the network, and `BrowserRuntime`
120
+ returns `ready (idle)` without probing when the scheduler is idle. A one-way proxy therefore
121
+ reported a clean bill of health while every run failed.
122
+
123
+ Current builds check the configured proxy by speaking SOCKS5 to it and requiring **bytes back**, so a
124
+ tunnel that connects and then returns nothing is reported as:
125
+
126
+ ```
127
+ [FAIL] **SocksProxy** [CRITICAL]
128
+ - Error: proxy at 127.0.0.1:1080 completed the SOCKS handshake to lite.duckduckgo.com:80 but returned no data within 5000ms (...)
129
+ ```
130
+
131
+ That check also runs before a research run starts, so the run stops in seconds with a diagnosis
132
+ instead of spending its whole search burst first. Two other signals are worth knowing:
133
+
134
+ - A readiness-probe timeout alone is treated as "pool busy" and the run proceeds. That rule is
135
+ deliberate (a loaded machine queues probes behind real work), and a broken proxy is excluded
136
+ from it.
137
+ - `PI_RESEARCH_SKIP_HEALTHCHECK=1` skips the pre-flight check entirely. It does not skip the
138
+ proxy probe.
139
+
73
140
  ## The SOCKS proxy refuses a URL with "connection not allowed by ruleset"
74
141
 
75
142
  That is `scripts/ddg-socks-proxy.mjs` blocking an SSRF attempt, not a bug: the destination was loopback, private, link-local (`169.254.169.254` metadata included), CGNAT, multicast or reserved, spelled either as the host or as the address it resolves to. The log line names it: `[ddg-socks] refused private/reserved destination <host>:<port>` or `refused <host> — resolves to private/reserved <addr>`. A research run never needs such a destination. If you added the proxy for a private mirror, run that request without the proxy.
76
143
 
144
+ Running the proxy under systemd (recommended over cron: it restarts, and its output lands in the
145
+ journal) — the unit is a local file, not something this package installs:
146
+
147
+ ```ini
148
+ [Unit]
149
+ Description=DDG SOCKS5 pin proxy for pi-research
150
+ After=network-online.target
151
+
152
+ [Service]
153
+ WorkingDirectory=%h/.pi/agent/extensions/pi-research # or the npm install path
154
+ Environment=DDG_SOCKS_PORT=1080
155
+ Environment=DDG_PIN_IPS=52.250.42.157,40.89.244.232
156
+ ExecStart=/usr/bin/node scripts/ddg-socks-proxy.mjs
157
+ Restart=always
158
+ RestartSec=5
159
+
160
+ [Install]
161
+ WantedBy=default.target
162
+ ```
163
+
164
+ Point `ExecStart` at the Node binary that runs pi (`command -v node`). `DDG_PIN_IPS` is read only by
165
+ the proxy, so changing it needs a restart. The pins are a snapshot of DuckDuckGo's front doors: if
166
+ both go dead the proxy cannot recover by itself, and `curl` through it will stall — repin, or drop
167
+ the proxy if direct egress works on your machine.
168
+
77
169
  ## A research run used a different model than `~/.pi/research/config.env` says
78
170
 
79
171
  Before the release that fingerprints the config sources, `getConfig()` cached configuration for the life of the process and never re-read it. Editing `config.env` from another shell, editor or pi session therefore did not affect a session that was already running, however long it lived. Restart pi (the loaded code and the loaded config are both fixed at start-up) or set the value through `/research-config`, which calls `resetConfig()`. Confirm what a run actually used: the report footer names the model, and the log carries `Using model for researcher <id>: <provider>/<model>`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincoln504/pi-research",
3
- "version": "1.7.22",
3
+ "version": "1.7.24",
4
4
  "description": "Web research for your agents with smart and safe tooling + knowledge store",
5
5
  "type": "module",
6
6
  "private": false,
@@ -112,7 +112,7 @@
112
112
  "install:system-deps": "node scripts/setup.cjs --system-deps",
113
113
  "//deps:check": "dependency-cruiser 18.5 refuses Node 25 (supports ^22 || ^24 || >=26) while engines allows >=22.22.2: run this script under Node 22 or 24 (see .nvmrc).",
114
114
  "deps:check": "depcruise --config config/tooling/dependency-cruiser.cjs --output-type err-long src",
115
- "deps:generate": "npx --yes madge@8.0.0 --image docs/deps.svg src/index.ts",
115
+ "deps:generate": "madge --image docs/deps.svg src/index.ts",
116
116
  "verify:changelog": "node scripts/verify-changelog.cjs",
117
117
  "lock:restore-stubs": "node scripts/restore-lock-stubs.cjs",
118
118
  "analyze:dependencies": "ncu",
@@ -139,8 +139,8 @@
139
139
  "pdf-oxide-wasm": "^0.3.77",
140
140
  "playwright-core": "1.62.1",
141
141
  "poolifier": "^6.0.1",
142
- "undici": "^8.11.2",
143
- "youtubei.js": "^18.0.0"
142
+ "undici": "^8.12.2",
143
+ "youtubei.js": "^18.3.0"
144
144
  },
145
145
  "bundleDependencies": [
146
146
  "@lancedb/lancedb",
@@ -149,14 +149,14 @@
149
149
  ],
150
150
  "optionalDependencies": {
151
151
  "@huggingface/transformers": "4.3.1",
152
- "webgpu": "^0.6.0",
153
152
  "@lancedb/lancedb-darwin-arm64": "0.40.0",
154
- "@lancedb/lancedb-linux-x64-gnu": "0.40.0",
155
153
  "@lancedb/lancedb-linux-arm64-gnu": "0.40.0",
156
- "@lancedb/lancedb-linux-x64-musl": "0.40.0",
157
154
  "@lancedb/lancedb-linux-arm64-musl": "0.40.0",
155
+ "@lancedb/lancedb-linux-x64-gnu": "0.40.0",
156
+ "@lancedb/lancedb-linux-x64-musl": "0.40.0",
157
+ "@lancedb/lancedb-win32-arm64-msvc": "0.40.0",
158
158
  "@lancedb/lancedb-win32-x64-msvc": "0.40.0",
159
- "@lancedb/lancedb-win32-arm64-msvc": "0.40.0"
159
+ "webgpu": "^0.6.0"
160
160
  },
161
161
  "peerDependencies": {
162
162
  "@earendil-works/pi-ai": ">=0.99.0 <2",
@@ -172,7 +172,7 @@
172
172
  "vite": "^8.3.1",
173
173
  "adm-zip": "^0.6.1",
174
174
  "jsdom": {
175
- "undici": "^8.10.2"
175
+ "undici": "^8.12.2"
176
176
  },
177
177
  "sharp": "^0.35.0",
178
178
  "@lancedb/lancedb": {
@@ -191,6 +191,7 @@
191
191
  "dependency-cruiser": "^18.5.0",
192
192
  "depngn": "^0.6.0",
193
193
  "eslint": "10.13.0",
194
+ "madge": "^8.0.0",
194
195
  "npm-check-updates": "^23.1.0",
195
196
  "typebox": "1.3.27",
196
197
  "typescript": ">=6.0.3 <6.1.0",