@lincoln504/pi-research 1.7.18 → 1.7.19

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/docs/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ 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.19] - 2026-10-23
9
+
10
+ ### Fixed
11
+
12
+ - **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.
13
+ - **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.
14
+
15
+ ### CI
16
+
17
+ - **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.
18
+ - **The "Pack real tarball" step runs the LanceDB strip explicitly** (`npm pack --ignore-scripts` skips `prepack`).
19
+
20
+ ### Documentation
21
+
22
+ - **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.
23
+
8
24
  ## [1.7.18] - 2026-10-23
9
25
 
10
26
  ### Security
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincoln504/pi-research",
3
- "version": "1.7.18",
3
+ "version": "1.7.19",
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",
@@ -37,6 +39,7 @@
37
39
  "scripts/cleanup.cjs",
38
40
  "scripts/camoufox-layout.cjs",
39
41
  "scripts/build.cjs",
42
+ "scripts/bare-imports.cjs",
40
43
  "scripts/prepare.cjs",
41
44
  "LICENSE",
42
45
  "docs/THIRD-PARTY-NOTICES.md",
@@ -0,0 +1,61 @@
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
+ /** Bare package names an ESM bundle imports (static, dynamic and re-export forms). */
31
+ function bareImports(source) {
32
+ const out = new Set();
33
+ const re = /(?:^|[\s;}(])(?:import|export)\s*(?:[^'"()]*?\sfrom\s*)?["']([^"'./][^"']*)["']|\bimport\s*\(\s*["']([^"'./][^"']*)["']\s*\)/gm;
34
+ for (const m of source.matchAll(re)) {
35
+ const spec = m[1] ?? m[2];
36
+ if (spec.startsWith('node:') || builtinModules.includes(spec.split('/')[0])) continue;
37
+ out.add(packageName(spec));
38
+ }
39
+ return out;
40
+ }
41
+
42
+ /** Names a standalone process may import: what npm installs for a consumer, peers excluded. */
43
+ function installedRuntimeNames(pkg) {
44
+ return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.optionalDependencies ?? {})]);
45
+ }
46
+
47
+ /** Returns [{ file, name }] for every bare import that would not resolve under --legacy-peer-deps. */
48
+ function unresolvableImports(root, pkg, files = WORKER_BUNDLES) {
49
+ const allowed = installedRuntimeNames(pkg);
50
+ const bad = [];
51
+ for (const rel of files) {
52
+ const full = require('path').join(root, rel);
53
+ if (!fs.existsSync(full)) continue;
54
+ for (const name of bareImports(fs.readFileSync(full, 'utf8'))) {
55
+ if (!allowed.has(name)) bad.push({ file: rel, name });
56
+ }
57
+ }
58
+ return bad;
59
+ }
60
+
61
+ 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
- ...COMMON,
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
- const missing = REQUIRED_PEERS.filter((name) => status.get(name) === 'missing');
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, which is',
106
- 'what --legacy-peer-deps, yarn classic, and a pnpm config with',
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
- 'Install the missing package(s), or reinstall this package, which resolves',
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
- ' npm install -g @lincoln504/pi-research',
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[];
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Where the pi HOST's copies of the peer dependencies live, when they are not installed
3
+ * beside this package.
4
+ *
5
+ * `pi install` runs npm with --legacy-peer-deps, so the managed install
6
+ * (~/.pi/agent/npm) never contains @earendil-works/* or typebox: pi hands its own copies
7
+ * to extension code in-process. The standalone engine (CLI, agent skill) is launched
8
+ * through the bin shim in a plain Node process, where Node's ESM resolver walks up
9
+ * node_modules directories only — it ignores NODE_PATH and the global root — so every
10
+ * agent call died with "required runtime dependency ... is not installed alongside it",
11
+ * and the advertised remedy (`npm install -g @earendil-works/pi-coding-agent`) could not
12
+ * help: a global install is not on that resolution path either.
13
+ *
14
+ * This module finds the host's copies in the places pi is realistically installed, so the
15
+ * shim can point the resolver at them (host-resolve-hook.mjs). Plain ESM with no imports
16
+ * from this package: it is loaded by the unbundled shim before anything else, and bundled
17
+ * into the agent-skill launcher.
18
+ */
19
+
20
+ import { existsSync, realpathSync } from 'node:fs';
21
+ import { homedir } from 'node:os';
22
+ import { delimiter, dirname, join } from 'node:path';
23
+ import { spawnSync } from 'node:child_process';
24
+
25
+ /** The peer dependencies the engine imports at startup. */
26
+ export const HOST_PACKAGES = [
27
+ '@earendil-works/pi-ai',
28
+ '@earendil-works/pi-coding-agent',
29
+ '@earendil-works/pi-tui',
30
+ 'typebox',
31
+ ];
32
+
33
+ const PI_CODING_AGENT = ['@earendil-works', 'pi-coding-agent'];
34
+
35
+ function binsOnPath(name) {
36
+ const exts = process.platform === 'win32' ? (process.env['PATHEXT'] ?? '.EXE;.CMD').split(';') : [''];
37
+ const out = [];
38
+ for (const dir of (process.env['PATH'] ?? '').split(delimiter)) {
39
+ if (!dir) continue;
40
+ for (const ext of exts) {
41
+ const candidate = join(dir, name + ext);
42
+ if (existsSync(candidate)) out.push(candidate);
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+
48
+ /**
49
+ * node_modules directories that may hold the host's packages, most specific first.
50
+ * `spawnNpm` additionally asks npm for its global root (a process spawn, so it is only
51
+ * done when the cheap candidates found nothing).
52
+ */
53
+ export function candidateNodeModulesDirs({ spawnNpm = false } = {}) {
54
+ const dirs = new Set();
55
+ const explicit = process.env['PI_RESEARCH_HOST_DIR'];
56
+ if (explicit) {
57
+ dirs.add(explicit);
58
+ dirs.add(join(explicit, 'node_modules'));
59
+ }
60
+ // The directory behind the `pi` command: <root>/node_modules/@earendil-works/pi-coding-agent/...
61
+ for (const bin of binsOnPath('pi')) {
62
+ try {
63
+ const m = /^(.*[\\/]node_modules)[\\/]/.exec(realpathSync(bin));
64
+ if (m) dirs.add(m[1]);
65
+ } catch {
66
+ /* dangling link: skip */
67
+ }
68
+ }
69
+ // The global root of the Node that is running us, without spawning npm.
70
+ dirs.add(join(dirname(process.execPath), '..', 'lib', 'node_modules'));
71
+ dirs.add(join(dirname(process.execPath), 'node_modules'));
72
+ dirs.add(join(homedir(), '.bun', 'install', 'global', 'node_modules'));
73
+ if (spawnNpm) {
74
+ try {
75
+ const r = spawnSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['root', '-g'], {
76
+ encoding: 'utf8',
77
+ timeout: 8000,
78
+ shell: process.platform === 'win32',
79
+ });
80
+ if (r.status === 0 && r.stdout.trim()) dirs.add(r.stdout.trim());
81
+ } catch {
82
+ /* npm not on PATH */
83
+ }
84
+ }
85
+ return [...dirs];
86
+ }
87
+
88
+ /** The node_modules directory holding `name`, searching the candidates (and pi's own nested deps). */
89
+ function locate(name, nodeModulesDirs) {
90
+ for (const nm of nodeModulesDirs) {
91
+ if (existsSync(join(nm, name, 'package.json'))) return nm;
92
+ const nested = join(nm, ...PI_CODING_AGENT, 'node_modules');
93
+ if (existsSync(join(nested, name, 'package.json'))) return nested;
94
+ }
95
+ return null;
96
+ }
97
+
98
+ /**
99
+ * Locate every host package in `names` that the caller could not resolve itself.
100
+ * @returns {{ found: Map<string, string>, missing: string[] }} name -> node_modules dir
101
+ */
102
+ export function findHostPackages(names = HOST_PACKAGES) {
103
+ const found = new Map();
104
+ // Opt-out: insist on peers installed beside the engine (strict deployments, hermetic tests).
105
+ if (process.env['PI_RESEARCH_NO_HOST_FALLBACK'] === '1') return { found, missing: [...names] };
106
+ let pending = [...names];
107
+ for (const spawnNpm of [false, true]) {
108
+ if (pending.length === 0) break;
109
+ const dirs = candidateNodeModulesDirs({ spawnNpm });
110
+ pending = pending.filter((name) => {
111
+ const nm = locate(name, dirs);
112
+ if (nm) found.set(name, nm);
113
+ return !nm;
114
+ });
115
+ }
116
+ return { found, missing: pending };
117
+ }
118
+
119
+ /** Distinct node_modules directories from a findHostPackages() result. */
120
+ export function hostDirs(found) {
121
+ return [...new Set(found.values())];
122
+ }