@lincoln504/pi-research 1.7.18 → 1.7.20
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/README.md +9 -24
- package/agent-skill/pi-research/SKILL.md +1 -1
- package/agent-skill/pi-research/scripts/run.mjs +140 -35
- package/dist/cli-bin.mjs +39 -7
- package/dist/host-resolve-hook.mjs +37 -0
- package/dist/host-roots.mjs +151 -0
- package/dist/thread-worker.mjs +8520 -59
- package/docs/AGENT-SKILL.md +6 -14
- package/docs/ARCHITECTURE.md +7 -6
- package/docs/CHANGELOG.md +36 -0
- package/docs/CONFIGURATION.md +6 -4
- package/docs/PI-EXTENSION.md +1 -1
- package/docs/SDK.md +6 -18
- package/docs/TROUBLESHOOTING.md +78 -0
- package/package.json +5 -1
- package/scripts/bare-imports.cjs +74 -0
- package/scripts/build.cjs +16 -1
- package/src/cli-bin.mjs +39 -7
- package/src/host-resolve-hook.mjs +37 -0
- package/src/host-roots.d.mts +4 -0
- package/src/host-roots.mjs +151 -0
- package/src/infrastructure/browser/thread-worker.mjs +8520 -59
package/docs/AGENT-SKILL.md
CHANGED
|
@@ -21,21 +21,13 @@ npm install -g @lincoln504/pi-research # the engine (puts `pi-research` on PAT
|
|
|
21
21
|
pi-research skill install # link the skill into every detected agent
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
prebuilt binaries, and the stealth browser self-provisions on its first use (the first
|
|
27
|
-
scrape takes a few minutes). On npm 10 through 11.19 the `postinstall` fetch runs
|
|
28
|
-
during install instead; that is the npm bundled with Node 24/25 (11.19.0) and with
|
|
29
|
-
the Node 22.22.2 floor (10.9.7). No approval is required (see the [README](../README.md#install)).
|
|
30
|
-
|
|
31
|
-
The global install also brings the `@earendil-works/pi-*` host packages in as peer
|
|
32
|
-
dependencies (npm ≥7 resolves them). If your install skips peers
|
|
33
|
-
(`--legacy-peer-deps`, yarn classic), the engine cannot import its model registry —
|
|
34
|
-
the launcher says so and exits 78. Add the package it needs directly:
|
|
24
|
+
The stealth browser (about 1 GB) downloads once, at install or on the first scrape depending
|
|
25
|
+
on your npm version; nothing needs approving (see [Troubleshooting](TROUBLESHOOTING.md#the-first-scrape-takes-minutes-or-install-downloads-over-a-gigabyte)).
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
The `@earendil-works/pi-*` host packages and `typebox` are peer dependencies. A global install
|
|
28
|
+
brings them in; an install that skips peers (`pi install`, `--legacy-peer-deps`, yarn classic) has the
|
|
29
|
+
launcher look for pi's own copies, and if it finds none it exits 78 naming the fix. See
|
|
30
|
+
[Troubleshooting](TROUBLESHOOTING.md#the-agent-skill-or-cli-says-cannot-start--missing-required-runtime-dependencies).
|
|
39
31
|
|
|
40
32
|
`skill install` targets only agents already set up under `$HOME`, never overwrites a
|
|
41
33
|
different skill in the slot, and records what it created so `pi-research skill uninstall`
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -26,7 +26,7 @@ pi CLI
|
|
|
26
26
|
task's complexity, guided by the tool's usage prompt (`src/prompts/research-tool-usage.md`).
|
|
27
27
|
CLI and SDK callers pass the depth explicitly.
|
|
28
28
|
2. Depth 0 takes the quick path; depth 1–3 takes the deep path (below). The pi extension's
|
|
29
|
-
tool and the TUI
|
|
29
|
+
tool and the TUI offer levels 1–3 unless `PI_RESEARCH_QUICK_RESEARCH=true` opts in to depth 0; the CLI, SDK, and agent skill can pass 0 (the CLI gates it on the same setting).
|
|
30
30
|
3. On the deep path the coordinator plans the research tracks and runs one initial
|
|
31
31
|
search burst, then hands each researcher a set of result URLs to start from.
|
|
32
32
|
4. Researchers scrape and read those pages through the scrape tooling and return cited
|
|
@@ -44,9 +44,9 @@ point. It dispatches on depth.
|
|
|
44
44
|
|
|
45
45
|
Depth 0 — quick (`QuickResearchOrchestrator`): a single researcher runs directly with
|
|
46
46
|
all tools; there is no coordinator, no planning phase, and no rounds. Depth 0 is
|
|
47
|
-
reachable
|
|
48
|
-
agent skill can pass). The pi extension's `research` tool has a minimum depth of 1
|
|
49
|
-
an in-session agent
|
|
47
|
+
reachable through the SDK (`runQuickResearch`) or the CLI (`--depth 0`, which the
|
|
48
|
+
agent skill can pass). The pi extension's `research` tool has a minimum depth of 1 unless
|
|
49
|
+
`PI_RESEARCH_QUICK_RESEARCH=true`, so an in-session agent cannot request quick mode by default.
|
|
50
50
|
|
|
51
51
|
Depth 1–3 — deep (`DeepResearchOrchestrator`): the run proceeds in **rounds**. A round
|
|
52
52
|
is one coordinate → research → route cycle — the round's agenda is planned (by the
|
|
@@ -321,7 +321,8 @@ why floating ranges are not trusted here. Rationale in full:
|
|
|
321
321
|
`src/infrastructure/browser/thread-worker-browser.ts`.
|
|
322
322
|
|
|
323
323
|
The launcher replacement (2026-10-05). `camoufox-js` `0.12.0` was replaced by
|
|
324
|
-
`@camoufox/camoufox` `0.5.7` after the former broke every fresh install
|
|
324
|
+
`@camoufox/camoufox` `0.5.7` after the former broke every fresh install; that package was
|
|
325
|
+
later renamed on npm, and the launcher is now `camoufox` `0.5.8`. On 2026-10-03
|
|
325
326
|
`v156.0.1-beta.34` was published to the `daijro/camoufox` releases WITHOUT the prerelease
|
|
326
327
|
flag, and the 156-series browser schema had dropped `navigator.product` (with
|
|
327
328
|
`appName`/`appCodeName`). `camoufox-js` `0.12.0` still sent those properties, and its
|
|
@@ -390,7 +391,7 @@ Validation library — `typebox` (TypeBox 1.x, unscoped package name) is a PEER
|
|
|
390
391
|
warns on every startup when a host-provided package (`typebox`, `@sinclair/typebox`, the
|
|
391
392
|
`@earendil-works/pi-*` packages) sits in `dependencies`, because an installed copy can bypass the
|
|
392
393
|
loader and create a second live module instance (`resource-loader.js`,
|
|
393
|
-
`collectExtensionPackageWarnings`;
|
|
394
|
+
`collectExtensionPackageWarnings`; `docs/packages.md` in the pi repository). Under pi the host's own copy is used,
|
|
394
395
|
so the two agree on `Value.Check`/`Convert` by construction. `@earendil-works/pi-ai` and
|
|
395
396
|
`@earendil-works/pi-coding-agent` 1.0.0 through 1.4.0 all pin `1.3.27` (re-checked 2026-10-21 in
|
|
396
397
|
the published 1.4.0 packages' `package.json`, previously 2026-10-17 in 1.3.0), which is why the devDependency, and so every test run and
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ 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.20] - 2026-10-23
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **The host-package lookup finds pi 1.x's managed install.** On a real machine (a user's `~/.local/bin/pi` is a shell script that runs `~/.pi/agent/install/releases/<version>/node_modules/.bin/pi`) nothing was found, so the agent skill and CLI still stopped with "missing required runtime dependencies" after 1.7.19 although pi's own copies were on disk. `src/host-roots.mjs` now also searches `<agent dir>/install/releases/<current-version>/node_modules` (`~/.pi/agent`, or `PI_CODING_AGENT_DIR`); the version string is validated so it cannot point outside the releases directory.
|
|
13
|
+
|
|
14
|
+
### Security
|
|
15
|
+
|
|
16
|
+
- **Hardening of that lookup, from review of 1.7.19.** Relative `PATH` entries are ignored (a `pi` planted at `./node_modules/.bin/pi` in an untrusted checkout could nominate that checkout's `node_modules`); `npm root -g` runs from the home directory instead of the current directory; on Windows it runs `npm-cli.js` with the running Node, with no shell, so a planted `npm.cmd` in the current directory can no longer be executed by cmd.exe's current-directory-first search.
|
|
17
|
+
|
|
18
|
+
### CI
|
|
19
|
+
|
|
20
|
+
- **`scripts/bare-imports.cjs` sees minified `import{a}from"x"`, `import"x"` and `require("x")` forms**, not only whitespace-separated `import ... from "x"` (a build with minification would have slipped past the gate). Specifiers must look like package names, so string fragments no longer match.
|
|
21
|
+
|
|
22
|
+
### Documentation
|
|
23
|
+
|
|
24
|
+
- **New `docs/TROUBLESHOOTING.md`** holds what used to be spread over the README and three other docs: the worker-start failure of 1.7.9-1.7.18, a `pi update` that errors because of a malformed source, the host-package lookup order and its fixes, the one-time browser download, and the old `sharp` audit finding. The README keeps one line and a link for each (10.2 KB to 6.9 KB), drops audit and install-script history, no longer says the standalone CLI "installs it as a dependency" (the host packages are peers), and mentions quick mode (depth 0).
|
|
25
|
+
- **Corrected:** `docs/ARCHITECTURE.md` said an in-session agent can never request quick mode and named the replaced `@camoufox/camoufox` launcher as current; `SECURITY.md` described a consumer override as still needed; `docs/PI-EXTENSION.md` omitted depth 0; `docs/SDK.md` and `docs/AGENT-SKILL.md` named one peer where four are needed and carried changelog narrative; `docs/CONFIGURATION.md` and `.env.example` now list `PI_RESEARCH_HOST_DIR` and `PI_RESEARCH_NO_HOST_FALLBACK` and no longer call `.env.example` exhaustive.
|
|
26
|
+
- **The ES, JA and ZH documents** had in-page links to anchors GitHub does not create (`{#id}` heading suffixes) and carried the stale `approve-scripts`/`better-sqlite3` and one-peer install text; the suffixes are gone, the links point at the real headings, and the install text matches the English docs.
|
|
27
|
+
|
|
28
|
+
## [1.7.19] - 2026-10-23
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **Search workers no longer die at import for every `pi install` user (v1.7.9-v1.7.18).** The browser worker (`dist/thread-worker.mjs`, a poolifier cluster child, i.e. a plain Node process) imported the peer dependency `typebox`, which became a peer in 1.7.9. pi installs with `--legacy-peer-deps`, so peers are never installed there, and pi supplies `typebox` to extension code only in-process: the worker exited with code 1 within ~200 ms (`ERR_MODULE_NOT_FOUND`), every search failed with "Worker exited before completing the task", and pool auto-recovery looped. Found on a user's machine (Jasper's logs: 669 worker exits across 4 days, each pool start killing all three workers) and reproduced from a clean `pi install` of 1.7.15. The strict-resolution install the release job ran has peers present and could not see it, and the repository's dev tree has `typebox` as a devDependency. The worker is now bundled with `typebox` inline (`scripts/build.cjs`: everything npm installs for a consumer stays external, everything else is bundled), growing it from ~140 KB to ~530 KB.
|
|
33
|
+
- **The agent skill and the standalone CLI work from a `pi install` tree.** The engine's bin shim stopped with "required runtime dependency ... is not installed alongside it" on every call, because the pi-managed tree has no host packages and Node's ESM resolver ignores NODE_PATH and the global npm root, so the documented remedy (`npm install -g @earendil-works/pi-coding-agent`) could not help either (reproduced on a machine that HAS a global pi). The shim now finds the host's copies where pi or a global npm install puts them (`src/host-roots.mjs`: `PI_RESEARCH_HOST_DIR`, the directory behind `pi` on PATH, the running Node's global root, bun's global root, then `npm root -g`) and registers a resolve hook (`src/host-resolve-hook.mjs`) that falls back to them for the four host packages only, after normal resolution fails. The skill launcher uses the same lookup before refusing to start. `PI_RESEARCH_NO_HOST_FALLBACK=1` turns it off. When nothing is found, the message names the commands that work for the layout, including `npm install --prefix <install root> --legacy-peer-deps ...`, which `pi update` keeps.
|
|
34
|
+
|
|
35
|
+
### CI
|
|
36
|
+
|
|
37
|
+
- **A second consumer install in the shape `pi install` uses** (`npm install --legacy-peer-deps`, peers absent) runs in both `ci.yml` and the release `test-install` job, and `verify-package.cjs installed` now statically scans the worker bundles for imports that are not installed dependencies (`scripts/bare-imports.cjs`) and STARTS both worker bundles standalone. Run against the published 1.7.18 it fails on all three counts.
|
|
38
|
+
- **The "Pack real tarball" step runs the LanceDB strip explicitly** (`npm pack --ignore-scripts` skips `prepack`).
|
|
39
|
+
|
|
40
|
+
### Documentation
|
|
41
|
+
|
|
42
|
+
- **README:** the peer-dependency paragraph describes the host lookup and the working remedies; the `sharp` note says 1.7.18 removed the need for an override; a troubleshooting entry for a `pi update` that errors because `settings.json` lists `npm:lincoln504/pi-research` (no `@`), which npm reads as a GitHub shorthand and which makes pi install the repository's main branch and register the extension twice.
|
|
43
|
+
|
|
8
44
|
## [1.7.18] - 2026-10-23
|
|
9
45
|
|
|
10
46
|
### Security
|
package/docs/CONFIGURATION.md
CHANGED
|
@@ -58,7 +58,7 @@ CPU/RAM-sensitive and set only via `PI_RESEARCH_WORKER_THREADS`.
|
|
|
58
58
|
|
|
59
59
|
Every setting is also an environment variable. The repo's
|
|
60
60
|
[`.env.example`](https://github.com/Lincoln504/pi-research/blob/main/.env.example)
|
|
61
|
-
is
|
|
61
|
+
is a commented template with inline notes; this section is the reference, grouping the
|
|
62
62
|
variables with their defaults and valid ranges.
|
|
63
63
|
Out-of-range numeric values are clamped (with a warning); an invalid enum value
|
|
64
64
|
falls back to the default (with a warning).
|
|
@@ -75,12 +75,12 @@ Research
|
|
|
75
75
|
| `PI_RESEARCH_MAX_RESEARCHERS` (TUI) | `3` | 1–5 | Parallel researchers. |
|
|
76
76
|
| `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` (TUI) `[project]` | `1` | 0–3 | Depth for `/research` and the CLI when `--depth` is omitted (0=quick single-pass — requires `PI_RESEARCH_QUICK_RESEARCH` —, 1=normal, 2=deep, 3=ultra). The agent-facing `research` tool-usage prompt renders its depth guidance relative to this setting too: when quick is the configured default, depth 0 is the ordinary choice; a user who keeps the default (1) gets byte-identical guidance. |
|
|
77
77
|
| `PI_RESEARCH_QUICK_RESEARCH` (TUI) `[project]` | `false` | `true` · `false` | Opt-in gate for depth-0 (quick) research. When `false` (default), the agent-facing `research` tool keeps its upstream `minimum: 1` schema — agents can neither see nor send depth 0 — and a `DEFAULT_RESEARCH_DEPTH` of 0 resolves to 1. Toggling applies on the next session. |
|
|
78
|
-
| `PI_RESEARCH_QUICK_MAX_QUERIES` | `3` | 1–10 | Max queries per `search` call in quick (depth 0) research. Applies to every quick run — the pi extension tool, the CLI, and the SDK's `--depth 0` — since they share the same researcher session factory. Deliberately below deep research's 30-query cap; the ceiling
|
|
78
|
+
| `PI_RESEARCH_QUICK_MAX_QUERIES` | `3` | 1–10 | Max queries per `search` call in quick (depth 0) research. Applies to every quick run — the pi extension tool, the CLI, and the SDK's `--depth 0` — since they share the same researcher session factory. Deliberately below deep research's 30-query cap; the ceiling is 10. |
|
|
79
79
|
| `PI_RESEARCH_QUICK_MAX_SCRAPE_URLS` | `5` | 1–20 | Max URLs fetched per scrape batch in quick (depth 0) research. Separate from `PI_RESEARCH_MAX_SCRAPE_URLS` (deep, `8`) because quick mode answers a single-fact question and the deep budget pulls in pages that question does not need; `PI_RESEARCH_MAX_SCRAPE_BATCHES` still caps how many batches a quick run may use. Applies to every quick run (pi extension tool, CLI, SDK `--depth 0`). |
|
|
80
80
|
| `PI_RESEARCH_MAX_SCRAPE_BATCHES` (TUI) | `2` | 0–99 | Scrape batches per researcher (0 = unlimited). When prompt caching is known to be active for the resolved research model (Anthropic API models, or a provider route explicitly configured for Anthropic-style cache control), the effective limit is this value plus one — the cached prompt prefix makes the extra batch cheap. |
|
|
81
81
|
| `PI_RESEARCH_MAX_GATHERING_CALLS` | `12` | 1–100 | Shared web-gathering calls per researcher (`search` + `security_search` + `stackexchange` + `youtube_transcript`). |
|
|
82
82
|
| `PI_RESEARCH_MAX_CONCURRENT_SCRAPES` | `3` | 1–20 | Concurrent URLs fetched per scrape batch. |
|
|
83
|
-
| `PI_RESEARCH_MAX_SCRAPE_URLS` | `8` | 1–20 | Maximum URLs fetched per scrape batch. URLs past the cap are listed under "Not Fetched — Over Batch Cap" and must be requested in a later batch.
|
|
83
|
+
| `PI_RESEARCH_MAX_SCRAPE_URLS` | `8` | 1–20 | Maximum URLs fetched per scrape batch. URLs past the cap are listed under "Not Fetched — Over Batch Cap" and must be requested in a later batch. |
|
|
84
84
|
| `PI_RESEARCH_SCRAPE_SECOND_PAGE` | `false` | true/false | Also fetch DuckDuckGo results page 2 for every search query, roughly doubling the candidate links each query contributes. Each query's page-2 fetch degrades gracefully — if page 2 fails or does not exist, the page-1 results are kept. |
|
|
85
85
|
| `PI_RESEARCH_MAX_RETRIES` | `2` | 0–5 | Retries per researcher request. |
|
|
86
86
|
| `PI_RESEARCH_RETRY_DELAY_MS` | `2000` | 100–10000 | Base delay between retries. |
|
|
@@ -164,7 +164,9 @@ Diagnostics & platform
|
|
|
164
164
|
| `PI_RESEARCH_STATE_DIR` | `~/.pi/research/state` | Override the state directory (active sessions, browser status, project registry). |
|
|
165
165
|
| `PI_RESEARCH_TUI_REFRESH_DEBOUNCE_MS` | `100` | TUI refresh debounce (0–1000 ms). |
|
|
166
166
|
| `PI_RESEARCH_SKIP_HEALTHCHECK` | _(unset)_ | Set `1`/`true` to skip the pre-flight browser/embedding health check and rely on per-task timeouts. **Depth 0 (quick) only** — depth 1-3 runs have no such pre-flight check, so this has no effect on them. |
|
|
167
|
-
| `
|
|
167
|
+
| `PI_RESEARCH_HOST_DIR` | _(unset)_ | A `node_modules` directory (or its parent) holding pi's copies of the peer dependencies (`@earendil-works/pi-*`, `typebox`). Searched first when the standalone engine cannot find them beside itself. See [Troubleshooting](TROUBLESHOOTING.md#the-agent-skill-or-cli-says-cannot-start--missing-required-runtime-dependencies). |
|
|
168
|
+
| `PI_RESEARCH_NO_HOST_FALLBACK` | _(unset)_ | Set `1` to turn the host-package lookup off and require peers installed beside the engine. |
|
|
169
|
+
| `PI_RESEARCH_PDF_WORKER` | _(unset)_ | Set `off` to force PDF parsing onto the main thread (in-process, no worker), bypassing the worker-threads offload. Kill-switch for worker or bundling issues; the default runs the parse in a worker when its bundle is present. |
|
|
168
170
|
| `PI_RESEARCH_USE_XVFB` | _(unset)_ | Linux only. Bare-TTY runs are true-headless and need no X server; set `true` to opt into a virtual framebuffer (`sudo apt install xvfb`). |
|
|
169
171
|
| `PI_RESEARCH_SKILL_DIR` | _(auto)_ | Override the bundled research-skill source directory used by the skill installer. |
|
|
170
172
|
| `PI_RESEARCH_PURGE_BROWSERS` | _(unset)_ | Read by the bundled `scripts/cleanup.cjs`: set `1` to also delete the shared camoufox browser cache (kept by default because other installs may use it). Note npm ≥7 does not run `preuninstall`, so that script does not fire on `npm uninstall` — see [AGENT-SKILL.md](AGENT-SKILL.md). |
|
package/docs/PI-EXTENSION.md
CHANGED
|
@@ -7,7 +7,7 @@ TUI registered directly in the pi process.
|
|
|
7
7
|
### Usage
|
|
8
8
|
|
|
9
9
|
The `research` tool is auto-registered, so the model invokes it
|
|
10
|
-
from natural language, and the tool understands the depth needed (1–3) from the query.
|
|
10
|
+
from natural language, and the tool understands the depth needed (1–3, or 0 when quick mode is enabled) from the query.
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
13
|
pi -p "research the latest developments in WebAssembly"
|
package/docs/SDK.md
CHANGED
|
@@ -13,24 +13,12 @@ run the `pi` extension, which keeps its own private copy your scripts can't impo
|
|
|
13
13
|
npm install @lincoln504/pi-research
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
The `@earendil-works/pi-*` host packages are peer dependencies, so npm ≥7 installs them
|
|
17
|
-
with the command above. If your install skips peers
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
npm
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
npm 12, the current npm, blocks dependency install scripts by default. Nothing
|
|
25
|
-
here needs them: the only native piece on the launch path is `impit`, which ships
|
|
26
|
-
prebuilt binaries, and the stealth browser self-provisions on its first use. On npm 10
|
|
27
|
-
through 11.19 the `postinstall` fetch runs during install instead; that is the npm
|
|
28
|
-
bundled with Node 24/25 (11.19.0) and with the Node 22.22.2 floor (10.9.7). (The
|
|
29
|
-
`npm approve-scripts better-sqlite3` + `npm rebuild` pair documented by earlier
|
|
30
|
-
releases repaired the old `camoufox-js` launcher, whose `better-sqlite3` binding came
|
|
31
|
-
from an install script — the 2026-10-05 move to `@camoufox/camoufox` removed that
|
|
32
|
-
dependency entirely, and on npm 12.0.2 an approval does not make a skipped script run
|
|
33
|
-
anyway.)
|
|
16
|
+
The `@earendil-works/pi-*` host packages and `typebox` are peer dependencies, so npm ≥7 installs them
|
|
17
|
+
with the command above. If your install skips peers (`--legacy-peer-deps`, yarn classic), add the
|
|
18
|
+
four it needs (`@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui`,
|
|
19
|
+
`typebox`) or see [Troubleshooting](TROUBLESHOOTING.md#the-agent-skill-or-cli-says-cannot-start--missing-required-runtime-dependencies).
|
|
20
|
+
The stealth browser (about 1 GB) downloads once, at install or on the first scrape depending on your
|
|
21
|
+
npm version ([details](TROUBLESHOOTING.md#the-first-scrape-takes-minutes-or-install-downloads-over-a-gigabyte)).
|
|
34
22
|
|
|
35
23
|
Then pick the model: pass `model` to `initResearchSDK`, or set `PI_RESEARCH_MODEL`
|
|
36
24
|
(env or `~/.pi/research/config.env`). The SDK never follows the model selected
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
## Searches fail with "Worker exited before completing the task"
|
|
4
|
+
|
|
5
|
+
Releases **1.7.9 through 1.7.18** broke every search for installs made with `pi install`: the
|
|
6
|
+
browser worker imported a package that `pi install` never installs, so each worker exited at
|
|
7
|
+
start-up. Update to **1.7.19 or newer**:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pi update npm:@lincoln504/pi-research
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then restart open pi sessions; a running session keeps the code it already loaded. To see which
|
|
14
|
+
version is installed, read `~/.pi/agent/npm/node_modules/@lincoln504/pi-research/package.json`.
|
|
15
|
+
|
|
16
|
+
For any other failure, set `PI_RESEARCH_DEBUG=true` and read the debug log (`$TMPDIR/pi-research.log`,
|
|
17
|
+
or `PI_RESEARCH_LOG_PATH`). Repeated `Worker exited with code 1` lines mean the browser worker is not
|
|
18
|
+
starting; the first error above the first exit says why. See [Configuration](CONFIGURATION.md#where-files-live).
|
|
19
|
+
|
|
20
|
+
## `pi update` prints errors for this extension
|
|
21
|
+
|
|
22
|
+
Check `~/.pi/agent/settings.json` (or run `pi list`) for a source spelled
|
|
23
|
+
`npm:lincoln504/pi-research`, without the `@`. npm reads `lincoln504/pi-research` as a GitHub
|
|
24
|
+
`user/repo`, so pi installs the repository's main branch instead of the published release (building
|
|
25
|
+
it, and registering the extension a second time). Remove the wrong entry and keep the right one:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pi remove npm:lincoln504/pi-research
|
|
29
|
+
pi list # should show npm:@lincoln504/pi-research once
|
|
30
|
+
pi update npm:@lincoln504/pi-research
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A source with a version (`npm:@lincoln504/pi-research@1.7.9`) is pinned and never updates; remove and
|
|
34
|
+
reinstall it to move versions. A bare `pi update` updates pi itself; use `pi update --extensions` for
|
|
35
|
+
every extension or name the source for just this one.
|
|
36
|
+
|
|
37
|
+
## The agent skill or CLI says "cannot start — missing required runtime dependencies"
|
|
38
|
+
|
|
39
|
+
The `@earendil-works/pi-*` packages and `typebox` are **peer dependencies**. Inside pi nothing is
|
|
40
|
+
needed: pi supplies them to the extension. The standalone engine (the CLI, the agent skill and the
|
|
41
|
+
SDK) runs as a plain Node process, and an install that skips peers (`pi install` always does, as do
|
|
42
|
+
`npm install --legacy-peer-deps`, yarn classic and pnpm with `auto-install-peers=false`) has none
|
|
43
|
+
beside it.
|
|
44
|
+
|
|
45
|
+
The engine looks for pi's own copies, in this order, and uses them when it finds them:
|
|
46
|
+
|
|
47
|
+
1. the directory named by `PI_RESEARCH_HOST_DIR` (a `node_modules` directory, or its parent)
|
|
48
|
+
2. the directory behind the `pi` command on `PATH` (absolute `PATH` entries only)
|
|
49
|
+
3. pi's managed install, `<agent dir>/install/releases/<current version>/node_modules`
|
|
50
|
+
(`~/.pi/agent` unless `PI_CODING_AGENT_DIR` is set)
|
|
51
|
+
4. the global npm root of the Node that is running, bun's global root, then `npm root -g`
|
|
52
|
+
|
|
53
|
+
`PI_RESEARCH_NO_HOST_FALLBACK=1` turns the lookup off. If nothing is found, the message names the
|
|
54
|
+
missing packages and these fixes; any one is enough:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# into the tree pi-research is installed in (for pi: ~/.pi/agent/npm); kept across `pi update`
|
|
58
|
+
npm install --prefix ~/.pi/agent/npm --legacy-peer-deps @earendil-works/pi-ai @earendil-works/pi-coding-agent @earendil-works/pi-tui typebox
|
|
59
|
+
# or globally; a global install is found automatically
|
|
60
|
+
npm install -g @earendil-works/pi-coding-agent
|
|
61
|
+
# or a standalone engine that brings its peers in with it
|
|
62
|
+
npm install -g @lincoln504/pi-research
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## The first scrape takes minutes, or install downloads over a gigabyte
|
|
66
|
+
|
|
67
|
+
The stealth browser (about 1 GB installed) is fetched by the `postinstall` script on npm 10 through
|
|
68
|
+
11.19, which includes the npm bundled with the Node 22.22.2 floor (10.9.7) and with Node 24/25
|
|
69
|
+
(11.19.0). npm 12 blocks dependency install scripts by default, so there the browser is fetched on the
|
|
70
|
+
first scrape instead. Either way it is a one-time download. Set `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1`
|
|
71
|
+
to defer it deliberately.
|
|
72
|
+
|
|
73
|
+
## `npm audit` reports a high-severity `sharp` chain under `@lancedb/lancedb`
|
|
74
|
+
|
|
75
|
+
This affects releases before **1.7.18** only. LanceDB pins an old `@huggingface/transformers` as an
|
|
76
|
+
optional dependency and npm ignores a dependency's `overrides`. From 1.7.18 the package ships LanceDB
|
|
77
|
+
bundled with those optional edges removed, so nothing needs overriding; update instead. On an older
|
|
78
|
+
release the consumer-side override is in [AUDIT-GATE.md](AUDIT-GATE.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincoln504/pi-research",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.20",
|
|
4
4
|
"description": "Web research for your agents with smart and safe tooling + knowledge store",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"src/",
|
|
19
19
|
"dist/cli-bin.mjs",
|
|
20
|
+
"dist/host-roots.mjs",
|
|
21
|
+
"dist/host-resolve-hook.mjs",
|
|
20
22
|
"dist/cli.mjs",
|
|
21
23
|
"dist/thread-worker.mjs",
|
|
22
24
|
"dist/pdf-extract-worker.mjs",
|
|
@@ -32,11 +34,13 @@
|
|
|
32
34
|
"docs/CONFIGURATION.md",
|
|
33
35
|
"docs/KNOWLEDGE-STORE.md",
|
|
34
36
|
"docs/AGENT-SKILL.md",
|
|
37
|
+
"docs/TROUBLESHOOTING.md",
|
|
35
38
|
"docs/ARCHITECTURE.md",
|
|
36
39
|
"scripts/setup.cjs",
|
|
37
40
|
"scripts/cleanup.cjs",
|
|
38
41
|
"scripts/camoufox-layout.cjs",
|
|
39
42
|
"scripts/build.cjs",
|
|
43
|
+
"scripts/bare-imports.cjs",
|
|
40
44
|
"scripts/prepare.cjs",
|
|
41
45
|
"LICENSE",
|
|
42
46
|
"docs/THIRD-PARTY-NOTICES.md",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bare-specifier scan for the shipped standalone-process bundles.
|
|
5
|
+
*
|
|
6
|
+
* The browser worker (a poolifier cluster child) and the PDF worker (a worker_thread) are
|
|
7
|
+
* plain Node processes: they get no help from pi's extension loader, which aliases
|
|
8
|
+
* `typebox` and `@earendil-works/*` for in-process extension code only. A bare import in
|
|
9
|
+
* one of these bundles therefore has to resolve from the INSTALLED package's own
|
|
10
|
+
* node_modules, i.e. it must be a real dependency. A peer dependency is not enough:
|
|
11
|
+
* `pi install` runs npm with --legacy-peer-deps, so peers are never installed there.
|
|
12
|
+
* v1.7.9-v1.7.18 shipped a worker importing the peer `typebox`; every search worker died
|
|
13
|
+
* at import (ERR_MODULE_NOT_FOUND, exit code 1) for every `pi install` user.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const { builtinModules } = require('module');
|
|
18
|
+
|
|
19
|
+
const WORKER_BUNDLES = [
|
|
20
|
+
'src/infrastructure/browser/thread-worker.mjs',
|
|
21
|
+
'dist/thread-worker.mjs',
|
|
22
|
+
'src/web-research/pdf-extract-worker.mjs',
|
|
23
|
+
'dist/pdf-extract-worker.mjs',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function packageName(spec) {
|
|
27
|
+
return spec.startsWith('@') ? spec.split('/').slice(0, 2).join('/') : spec.split('/')[0];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Bare package names a bundle imports, in every form esbuild emits or a hand-written file may
|
|
32
|
+
* use: `import x from "p"` / `import{x}from"p"` (minified, no whitespace), `import "p"`,
|
|
33
|
+
* `export … from "p"`, `import("p")` and `require("p")` / `createRequire(...)("p")`.
|
|
34
|
+
* Text that merely MENTIONS an import inside a string is matched too; that fails closed (a
|
|
35
|
+
* false alarm to look at, never a missed import).
|
|
36
|
+
*/
|
|
37
|
+
function bareImports(source) {
|
|
38
|
+
const out = new Set();
|
|
39
|
+
const patterns = [
|
|
40
|
+
/\bfrom\s*["']([@A-Za-z0-9_][^"'\s]*)["']/g,
|
|
41
|
+
/\bimport\s*["']([@A-Za-z0-9_][^"'\s]*)["']/g,
|
|
42
|
+
/\bimport\s*\(\s*["']([@A-Za-z0-9_][^"'\s]*)["']\s*\)/g,
|
|
43
|
+
/\brequire\s*\(\s*["']([@A-Za-z0-9_][^"'\s]*)["']\s*\)/g,
|
|
44
|
+
];
|
|
45
|
+
for (const re of patterns) {
|
|
46
|
+
for (const m of source.matchAll(re)) {
|
|
47
|
+
const spec = m[1];
|
|
48
|
+
if (spec.startsWith('node:') || builtinModules.includes(spec.split('/')[0])) continue;
|
|
49
|
+
out.add(packageName(spec));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Names a standalone process may import: what npm installs for a consumer, peers excluded. */
|
|
56
|
+
function installedRuntimeNames(pkg) {
|
|
57
|
+
return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.optionalDependencies ?? {})]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Returns [{ file, name }] for every bare import that would not resolve under --legacy-peer-deps. */
|
|
61
|
+
function unresolvableImports(root, pkg, files = WORKER_BUNDLES) {
|
|
62
|
+
const allowed = installedRuntimeNames(pkg);
|
|
63
|
+
const bad = [];
|
|
64
|
+
for (const rel of files) {
|
|
65
|
+
const full = require('path').join(root, rel);
|
|
66
|
+
if (!fs.existsSync(full)) continue;
|
|
67
|
+
for (const name of bareImports(fs.readFileSync(full, 'utf8'))) {
|
|
68
|
+
if (!allowed.has(name)) bad.push({ file: rel, name });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return bad;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { WORKER_BUNDLES, bareImports, installedRuntimeNames, unresolvableImports };
|
package/scripts/build.cjs
CHANGED
|
@@ -36,6 +36,7 @@ const COMMON = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const p = (...segs) => path.join(ROOT, ...segs);
|
|
39
|
+
const { installedRuntimeNames } = require('./bare-imports.cjs');
|
|
39
40
|
|
|
40
41
|
// The out-of-process WebGPU viability probe is plain .mjs (not bundled). It must
|
|
41
42
|
// sit next to the bundled entry points so the embedder can resolve it relative to
|
|
@@ -57,6 +58,9 @@ function copyWebGpuProbe() {
|
|
|
57
58
|
function copyCliBin() {
|
|
58
59
|
fs.mkdirSync(p('dist'), { recursive: true });
|
|
59
60
|
fs.copyFileSync(p('src', 'cli-bin.mjs'), p('dist', 'cli-bin.mjs'));
|
|
61
|
+
// The shim imports these two next to itself (peer-dependency fallback; see host-roots.mjs).
|
|
62
|
+
fs.copyFileSync(p('src', 'host-roots.mjs'), p('dist', 'host-roots.mjs'));
|
|
63
|
+
fs.copyFileSync(p('src', 'host-resolve-hook.mjs'), p('dist', 'host-resolve-hook.mjs'));
|
|
60
64
|
// copyFileSync preserves the SOURCE mode. The source is committed executable
|
|
61
65
|
// (100755) so this is belt-and-braces, but nothing about the shipped bin should
|
|
62
66
|
// depend on the source file's mode or on the umask of whatever builds it. The
|
|
@@ -70,8 +74,19 @@ function copyCliBin() {
|
|
|
70
74
|
// Build the browser worker bundle. Factored out so the cli target can guarantee
|
|
71
75
|
// it exists when built in isolation (`build:cli`), not only via `build all`.
|
|
72
76
|
function buildWorker() {
|
|
77
|
+
// The worker is a poolifier cluster child: a plain Node process that gets no help from
|
|
78
|
+
// pi's extension loader (which aliases the peer `typebox` for in-process code only), and
|
|
79
|
+
// `pi install` never installs peers (--legacy-peer-deps). So what npm really installs for
|
|
80
|
+
// a consumer — dependencies and optionalDependencies — stays external, and everything
|
|
81
|
+
// else it imports (today: `typebox`) is bundled in. v1.7.9-v1.7.18 left typebox external,
|
|
82
|
+
// and every worker died at import for `pi install` users. verify-package.cjs scans the
|
|
83
|
+
// result (scripts/bare-imports.cjs) so a future peer import fails the build, not a user.
|
|
84
|
+
const pkg = require(p('package.json'));
|
|
85
|
+
const external = [...installedRuntimeNames(pkg)].flatMap((n) => [n, `${n}/*`]);
|
|
86
|
+
const { packages: _external, ...common } = COMMON;
|
|
73
87
|
return esbuild.build({
|
|
74
|
-
...
|
|
88
|
+
...common,
|
|
89
|
+
external,
|
|
75
90
|
entryPoints: [p('src', 'infrastructure', 'browser', 'thread-worker.ts')],
|
|
76
91
|
outfile: p('src', 'infrastructure', 'browser', 'thread-worker.mjs'),
|
|
77
92
|
});
|
package/src/cli-bin.mjs
CHANGED
|
@@ -35,7 +35,10 @@
|
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
import { existsSync } from 'node:fs';
|
|
38
|
+
import { register } from 'node:module';
|
|
39
|
+
import { dirname } from 'node:path';
|
|
38
40
|
import { fileURLToPath } from 'node:url';
|
|
41
|
+
import { findHostPackages, hostDirs } from './host-roots.mjs';
|
|
39
42
|
|
|
40
43
|
const REQUIRED_PEERS = [
|
|
41
44
|
'@earendil-works/pi-ai',
|
|
@@ -84,9 +87,27 @@ function probePeer(name) {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
const status = new Map(REQUIRED_PEERS.map((name) => [name, probePeer(name)]));
|
|
87
|
-
|
|
90
|
+
let missing = REQUIRED_PEERS.filter((name) => status.get(name) === 'missing');
|
|
88
91
|
const broken = REQUIRED_PEERS.filter((name) => status.get(name) === 'broken');
|
|
89
92
|
|
|
93
|
+
// Peers that do not resolve from here are very often still on the machine: pi keeps its own
|
|
94
|
+
// copies, and a global `npm install -g @earendil-works/pi-coding-agent` puts them in the
|
|
95
|
+
// global root. Node's ESM resolver never looks in either from this package's directory
|
|
96
|
+
// (a `pi install` managed tree, installed with --legacy-peer-deps, has no peers at all), so
|
|
97
|
+
// register a resolve hook that falls back to them. See host-roots.mjs. Only names that
|
|
98
|
+
// failed normal resolution are searched for, and only those the search found are rescued.
|
|
99
|
+
if (missing.length > 0 && broken.length === 0) {
|
|
100
|
+
try {
|
|
101
|
+
const { found } = findHostPackages(missing);
|
|
102
|
+
if (found.size > 0) {
|
|
103
|
+
register('./host-resolve-hook.mjs', import.meta.url, { data: { dirs: hostDirs(found) } });
|
|
104
|
+
missing = missing.filter((name) => !found.has(name));
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
/* fall through to the message below */
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
90
111
|
if (missing.length > 0 || broken.length > 0) {
|
|
91
112
|
// The remedy names the packages that are ACTUALLY absent. It used to hardcode
|
|
92
113
|
// `npm install -g @earendil-works/pi-coding-agent` with the comment "add just
|
|
@@ -94,6 +115,10 @@ if (missing.length > 0 || broken.length > 0) {
|
|
|
94
115
|
// one: the instruction named a package the user already had, and following it
|
|
95
116
|
// changed nothing. Reported by review 2026-10-01.
|
|
96
117
|
const needsInstall = [...missing, ...broken];
|
|
118
|
+
// The tree this package sits in, when it is a node_modules install (the pi-managed one).
|
|
119
|
+
const installRoot = /^(.*)[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+[\\/]dist$/.exec(
|
|
120
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
121
|
+
)?.[1];
|
|
97
122
|
const lines = [
|
|
98
123
|
'',
|
|
99
124
|
'Error: pi-research cannot start — it is missing required runtime dependencies:',
|
|
@@ -102,15 +127,22 @@ if (missing.length > 0 || broken.length > 0) {
|
|
|
102
127
|
'',
|
|
103
128
|
'These are PEER dependencies. pi provides its own copies when it loads this',
|
|
104
129
|
'package as an extension, and npm >= 7 installs them automatically for a',
|
|
105
|
-
'standalone (global or project) install. This install skipped them
|
|
106
|
-
'
|
|
107
|
-
'auto-install-peers=false do
|
|
130
|
+
'standalone (global or project) install. This install skipped them (what',
|
|
131
|
+
'--legacy-peer-deps, which `pi install` always passes, yarn classic and a pnpm',
|
|
132
|
+
'config with auto-install-peers=false do), and no copy was found where pi or a',
|
|
133
|
+
'global npm install would have put one.',
|
|
108
134
|
'',
|
|
109
|
-
'
|
|
110
|
-
'them as peers:',
|
|
135
|
+
'Any ONE of these fixes it:',
|
|
111
136
|
'',
|
|
137
|
+
...(installRoot
|
|
138
|
+
? [
|
|
139
|
+
` npm install --prefix "${installRoot}" --legacy-peer-deps ${needsInstall.join(' ')}`,
|
|
140
|
+
' # into the tree this package is installed in (kept across `pi update`)',
|
|
141
|
+
]
|
|
142
|
+
: []),
|
|
112
143
|
` npm install -g ${needsInstall.join(' ')}`,
|
|
113
|
-
'
|
|
144
|
+
' # a global install is found automatically',
|
|
145
|
+
' export PI_RESEARCH_HOST_DIR=/path/to/node_modules # a directory that holds them',
|
|
114
146
|
'',
|
|
115
147
|
];
|
|
116
148
|
process.stderr.write(lines.join('\n'));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESM resolve hook (registered by the bin shim via module.register) that falls back to the
|
|
3
|
+
* host's own copies of the peer dependencies — see host-roots.mjs for why the engine needs
|
|
4
|
+
* it. It only ever acts AFTER normal resolution failed, and only for the host packages, so
|
|
5
|
+
* an install that has them beside the engine is never affected.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const HOST = new Set(['@earendil-works/pi-ai', '@earendil-works/pi-coding-agent', '@earendil-works/pi-tui', 'typebox']);
|
|
12
|
+
let dirs = [];
|
|
13
|
+
|
|
14
|
+
function packageName(specifier) {
|
|
15
|
+
return specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function initialize(data) {
|
|
19
|
+
dirs = Array.isArray(data?.dirs) ? data.dirs : [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
23
|
+
try {
|
|
24
|
+
return await nextResolve(specifier, context);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (err?.code !== 'ERR_MODULE_NOT_FOUND' || !HOST.has(packageName(specifier))) throw err;
|
|
27
|
+
for (const nm of dirs) {
|
|
28
|
+
try {
|
|
29
|
+
// A parent that lives IN the node_modules directory makes Node's lookup start there.
|
|
30
|
+
return await nextResolve(specifier, { ...context, parentURL: pathToFileURL(join(nm, '__host__.mjs')).href });
|
|
31
|
+
} catch {
|
|
32
|
+
/* try the next location */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const HOST_PACKAGES: string[];
|
|
2
|
+
export function candidateNodeModulesDirs(options?: { spawnNpm?: boolean }): string[];
|
|
3
|
+
export function findHostPackages(names?: string[]): { found: Map<string, string>; missing: string[] };
|
|
4
|
+
export function hostDirs(found: Map<string, string>): string[];
|