@lincoln504/pi-research 1.6.1 → 1.6.2
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 +7 -5
- package/agent-skill/pi-research/SKILL.md +1 -1
- package/dist/cli.mjs +59 -17
- package/docs/CHANGELOG.md +22 -0
- package/package.json +1 -1
- package/src/cli.ts +40 -12
- package/src/infrastructure/browser/browser-error-utils.ts +21 -0
- package/src/infrastructure/browser/config.ts +43 -0
- package/src/skill-install/skill-installer.ts +44 -7
- package/src/web-research/browser-search.ts +19 -1
package/README.md
CHANGED
|
@@ -44,11 +44,13 @@ npm install -g @lincoln504/pi-research
|
|
|
44
44
|
pi-research skill install
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
On npm 12 or newer, add `--allow-scripts` to either install above. npm 12 stopped running dependency install scripts by default, and the stealth browser's native dependencies are built by one — without it searches fail with a missing-module error rather than a warning at install time.
|
|
48
|
+
|
|
49
|
+
In pi it works out of the box on the session's model and pi's configuration. Standalone use ([agent skill](docs/AGENT-SKILL.md) or [SDK](docs/SDK.md)) needs a model configured. See [Configuration](docs/CONFIGURATION.md). The first install downloads the stealth browser engine, which takes a few minutes.
|
|
48
50
|
|
|
49
51
|
### How it works
|
|
50
52
|
|
|
51
|
-
A research run loops through agent teams: a coordinator plans and
|
|
53
|
+
A research run loops through agent teams: a coordinator plans and starts with a search, researcher agents scrape and read in parallel, and a research lead decides whether to go another round — then writes the report from every report collected. The result is one cited Markdown report with findings optionally saved to the knowledge store.
|
|
52
54
|
|
|
53
55
|
Three depth levels (normal, deep, ultra) set the team size and number of rounds. A natural-language request is enough — the tool picks the right one:
|
|
54
56
|
|
|
@@ -64,10 +66,10 @@ Three depth levels (normal, deep, ultra) set the team size and number of rounds.
|
|
|
64
66
|
### Why pi-research
|
|
65
67
|
|
|
66
68
|
- **No quota and no monthly fee.** Most AI search providers cap free searches and then charge, with results served from their index on their servers. pi-research searches and scrapes locally through DuckDuckGo in a stealth browser.
|
|
67
|
-
- **The index
|
|
69
|
+
- **The index is local.** Every finding can be saved to a local [LanceDB](https://lancedb.com) knowledge store that seeds future runs, so repeat questions get faster and cheaper answers.
|
|
68
70
|
- **Cited reports rather than raw dumps.** Each run returns one sourced Markdown report instead of raw web content pasted into the conversation. Context efficient and easy to verify.
|
|
69
71
|
- **Read-only by design.** The research agent cannot run shell commands or write, edit, or delete anything — the right shape for an agent whose whole job is reading untrusted web pages. Prompt injection picked up mid-run has nothing to act on.
|
|
70
|
-
- **Search a little or a lot.** Depth levels
|
|
72
|
+
- **Search a little or a lot.** Depth levels range from a quick pass to a large-scale investigation.
|
|
71
73
|
|
|
72
74
|
### Requirements / limitations
|
|
73
75
|
|
|
@@ -75,7 +77,7 @@ Three depth levels (normal, deep, ultra) set the team size and number of rounds.
|
|
|
75
77
|
- An LLM with a 100k+ context window (an API key or a local model)
|
|
76
78
|
- Internet access on a residential IP, since search, scraping, and YouTube transcripts get bot-blocked from datacenter/VPS/cloud IPs
|
|
77
79
|
- pi. The pi extension uses the host's copy while the standalone CLI and agent skill install it as a dependency.
|
|
78
|
-
- Cloudflare and similar systems block scraping on some sites. A run
|
|
80
|
+
- Cloudflare Turnstile and similar systems block scraping on some sites. A run compensates with a wide pool of search results to scrape.
|
|
79
81
|
|
|
80
82
|
### Channels
|
|
81
83
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: pi-research
|
|
3
3
|
description: "Multi-agent web research for any coding agent. Use for anything requiring current information from the internet — news, trends, product/service/company facts, statistics, people, places, events, APIs, library behavior, or 'what is X / how does X work' questions. Also use to search a local knowledge store of previously researched findings before doing live research. Powered by the pi-research engine (search, stealth scraping, security databases, Stack Exchange). Not for reading local files, running project commands, or analyzing this repository's own source."
|
|
4
4
|
license: MIT
|
|
5
|
-
metadata: { "author": "Lincoln Deen", "version": "1.6.
|
|
5
|
+
metadata: { "author": "Lincoln Deen", "version": "1.6.2", "package": "@lincoln504/pi-research", "engine": "pi-research-sdk", "openclaw": { "requires": { "bins": ["node"] } } }
|
|
6
6
|
allowed-tools: Bash(node:*)
|
|
7
7
|
---
|
|
8
8
|
|
package/dist/cli.mjs
CHANGED
|
@@ -10283,9 +10283,17 @@ function detectHarnesses(opts) {
|
|
|
10283
10283
|
}
|
|
10284
10284
|
} catch {
|
|
10285
10285
|
}
|
|
10286
|
-
|
|
10286
|
+
const broken = (installed === "owned-symlink" || installed === "owned-copy") && !isUsableSkillDir(absSkillPath);
|
|
10287
|
+
return { ...h, present, absSkillsDir, absSkillPath, installed, broken };
|
|
10287
10288
|
});
|
|
10288
10289
|
}
|
|
10290
|
+
function isUsableSkillDir(p) {
|
|
10291
|
+
try {
|
|
10292
|
+
return fs16.existsSync(path18.join(p, "SKILL.md")) && fs16.existsSync(path18.join(p, "scripts", "run.mjs"));
|
|
10293
|
+
} catch {
|
|
10294
|
+
return false;
|
|
10295
|
+
}
|
|
10296
|
+
}
|
|
10289
10297
|
function isSymlinkPresent(p) {
|
|
10290
10298
|
try {
|
|
10291
10299
|
return fs16.lstatSync(p).isSymbolicLink();
|
|
@@ -10455,8 +10463,8 @@ function reconcileSkillInstalls(opts = {}) {
|
|
|
10455
10463
|
const keep = [];
|
|
10456
10464
|
for (const e of manifest.entries) {
|
|
10457
10465
|
if (e.type !== "symlink") {
|
|
10458
|
-
const
|
|
10459
|
-
if (
|
|
10466
|
+
const stale = currentVersion !== null && e.version !== currentVersion;
|
|
10467
|
+
if (stale && source !== null && fs16.existsSync(e.path) && isOwnedCopy(e.path)) {
|
|
10460
10468
|
const dir2 = path18.dirname(e.path);
|
|
10461
10469
|
const base2 = path18.basename(e.path);
|
|
10462
10470
|
try {
|
|
@@ -10533,14 +10541,8 @@ function reconcileSkillInstalls(opts = {}) {
|
|
|
10533
10541
|
keep.push(e);
|
|
10534
10542
|
continue;
|
|
10535
10543
|
}
|
|
10536
|
-
const targetLive = fs16.existsSync(e.path);
|
|
10537
|
-
|
|
10538
|
-
try {
|
|
10539
|
-
dest = path18.resolve(path18.dirname(e.path), fs16.readlinkSync(e.path));
|
|
10540
|
-
} catch {
|
|
10541
|
-
}
|
|
10542
|
-
const stale = source !== null && dest !== null && dest !== path18.resolve(source);
|
|
10543
|
-
if (!targetLive || stale) {
|
|
10544
|
+
const targetLive = fs16.existsSync(e.path) && isUsableSkillDir(e.path);
|
|
10545
|
+
if (!targetLive) {
|
|
10544
10546
|
if (source !== null) {
|
|
10545
10547
|
try {
|
|
10546
10548
|
fs16.unlinkSync(e.path);
|
|
@@ -12318,6 +12320,7 @@ import * as crypto4 from "node:crypto";
|
|
|
12318
12320
|
import { join as join8 } from "node:path";
|
|
12319
12321
|
import { existsSync as existsSync6, mkdirSync as mkdirSync3 } from "node:fs";
|
|
12320
12322
|
import { platform, homedir as homedir3 } from "node:os";
|
|
12323
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
12321
12324
|
function getWindowsCamoufoxDir() {
|
|
12322
12325
|
return join8(homedir3(), "AppData", "Local", "camoufox", "camoufox", "Cache");
|
|
12323
12326
|
}
|
|
@@ -12426,6 +12429,20 @@ function resolveHeadlessMode() {
|
|
|
12426
12429
|
if (process.env["PI_RESEARCH_USE_XVFB"] === "true") return "virtual";
|
|
12427
12430
|
return true;
|
|
12428
12431
|
}
|
|
12432
|
+
function probeBrowserNativeDeps(load = defaultNativeDepLoad) {
|
|
12433
|
+
try {
|
|
12434
|
+
load();
|
|
12435
|
+
return { ok: true };
|
|
12436
|
+
} catch (err) {
|
|
12437
|
+
return { ok: false, error: err instanceof Error ? err.message.split("\n")[0].trim() : String(err) };
|
|
12438
|
+
}
|
|
12439
|
+
}
|
|
12440
|
+
function defaultNativeDepLoad() {
|
|
12441
|
+
const require2 = createRequire3(import.meta.url);
|
|
12442
|
+
const Database = require2("better-sqlite3");
|
|
12443
|
+
const db = new Database(":memory:");
|
|
12444
|
+
db.close();
|
|
12445
|
+
}
|
|
12429
12446
|
function isBrowserAvailable() {
|
|
12430
12447
|
if (isFullMockMode()) return false;
|
|
12431
12448
|
try {
|
|
@@ -12518,6 +12535,11 @@ function isPoolShutdownError(error) {
|
|
|
12518
12535
|
// same transient swap the "being reset" string covers, not a hard fault.
|
|
12519
12536
|
err.message.includes("Cannot execute a task on not started pool"));
|
|
12520
12537
|
}
|
|
12538
|
+
var NATIVE_BINDING_FAILURE = /Could not locate the bindings file|ERR_DLOPEN_FAILED|NODE_MODULE_VERSION|was compiled against a different Node\.js version|invalid ELF header|Cannot find module '[^']*\.node'/;
|
|
12539
|
+
function isNativeBindingError(error) {
|
|
12540
|
+
const msg2 = error instanceof Error ? error.message : String(error);
|
|
12541
|
+
return NATIVE_BINDING_FAILURE.test(msg2);
|
|
12542
|
+
}
|
|
12521
12543
|
var BENIGN_NAVIGATION_FAILURE = /page\.goto: (?:Timeout \d+ *ms exceeded|net::|NS_ERROR_|SEC_ERROR_|MOZILLA_PKIX_ERROR_)/;
|
|
12522
12544
|
function isBenignScrapeFailure(error) {
|
|
12523
12545
|
const msg2 = error instanceof Error ? error.message : String(error);
|
|
@@ -15749,7 +15771,7 @@ import { FixedClusterPool, WorkerChoiceStrategies } from "poolifier";
|
|
|
15749
15771
|
// src/infrastructure/browser/ensure-browser.ts
|
|
15750
15772
|
init_logger();
|
|
15751
15773
|
import { spawn as spawn2 } from "node:child_process";
|
|
15752
|
-
import { createRequire as
|
|
15774
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
15753
15775
|
import { createHash as createHash2 } from "node:crypto";
|
|
15754
15776
|
import { existsSync as existsSync7, readdirSync as readdirSync3, statSync as statSync3, fstatSync, openSync as openSync4, closeSync as closeSync4, rmSync } from "node:fs";
|
|
15755
15777
|
import { join as join11, dirname as dirname8 } from "node:path";
|
|
@@ -15776,7 +15798,7 @@ function isBrowserBinaryPresent() {
|
|
|
15776
15798
|
}
|
|
15777
15799
|
function resolveCamoufoxBin() {
|
|
15778
15800
|
try {
|
|
15779
|
-
const require2 =
|
|
15801
|
+
const require2 = createRequire4(import.meta.url);
|
|
15780
15802
|
const pkgJson = require2.resolve("camoufox-js/package.json");
|
|
15781
15803
|
const bin = join11(dirname8(pkgJson), "..", ".bin", process.platform === "win32" ? "camoufox-js.cmd" : "camoufox-js");
|
|
15782
15804
|
if (existsSync7(bin)) return bin;
|
|
@@ -17532,6 +17554,12 @@ async function performSearch(queries, config, signal, onProgress, container = ge
|
|
|
17532
17554
|
} else if (timeoutCount + errorCount === filteredQueries.length) {
|
|
17533
17555
|
reason = `${timeoutCount} queries timed out and ${errorCount} queries failed`;
|
|
17534
17556
|
}
|
|
17557
|
+
if (isNativeBindingError(sampleWorkerError)) {
|
|
17558
|
+
metrics.increment("browser_search_total_failures_total", 1, { cause: "native_binding" });
|
|
17559
|
+
throw new Error(
|
|
17560
|
+
`Search completely failed: ${reason}, all with a missing native module. This is an incomplete install, not a network problem: the browser engine's native dependencies were never built. npm 12 does not run dependency install scripts by default \u2014 reinstall allowing them (npm install @lincoln504/pi-research --allow-scripts, or npm approve-scripts --allow-scripts-pending), then retry.` + (sampleWorkerError ? ` Last worker error: ${sampleWorkerError}` : "")
|
|
17561
|
+
);
|
|
17562
|
+
}
|
|
17535
17563
|
throw new Error(
|
|
17536
17564
|
`Search completely failed: ${reason}. Browser workers may be unavailable, DuckDuckGo is unreachable, or the system is under extreme load.` + (sampleWorkerError ? ` Last worker error: ${sampleWorkerError}` : "")
|
|
17537
17565
|
);
|
|
@@ -26707,11 +26735,12 @@ async function cmdStatus(json) {
|
|
|
26707
26735
|
const paths = resolvedConfigPaths();
|
|
26708
26736
|
const cfg = getConfig(process.cwd(), "cli");
|
|
26709
26737
|
const browserInstalled = isBrowserAvailable();
|
|
26738
|
+
const nativeDeps = probeBrowserNativeDeps();
|
|
26710
26739
|
const summary = {
|
|
26711
26740
|
package: "@lincoln504/pi-research",
|
|
26712
26741
|
version: PKG_VERSION,
|
|
26713
26742
|
cli: `node ${process.argv[1]}`,
|
|
26714
|
-
ready: !det.problem,
|
|
26743
|
+
ready: !det.problem && nativeDeps.ok,
|
|
26715
26744
|
credentials: {
|
|
26716
26745
|
source: det.source,
|
|
26717
26746
|
apiKeyConfigured: det.apiKeyConfigured,
|
|
@@ -26722,6 +26751,9 @@ async function cmdStatus(json) {
|
|
|
26722
26751
|
},
|
|
26723
26752
|
browser: {
|
|
26724
26753
|
installed: browserInstalled,
|
|
26754
|
+
nativeDepsOk: nativeDeps.ok,
|
|
26755
|
+
nativeDepsError: nativeDeps.ok ? null : nativeDeps.error,
|
|
26756
|
+
nativeDepsFix: nativeDeps.ok ? null : "Reinstall allowing dependency install scripts: npm install -g @lincoln504/pi-research --allow-scripts (npm 12 turns them off by default).",
|
|
26725
26757
|
// Same remedy the health check prints, so both surfaces name one command.
|
|
26726
26758
|
fix: browserInstalled ? null : "npx camoufox-js fetch",
|
|
26727
26759
|
note: browserInstalled ? null : "Stealth browser not installed \u2014 scraping falls back to plain fetch, which some sites block. npm 11.19+ blocks install scripts by default, which skips this package's postinstall."
|
|
@@ -26739,7 +26771,16 @@ async function cmdStatus(json) {
|
|
|
26739
26771
|
toStdout(`ready: ${summary.ready ? "yes" : "no"}
|
|
26740
26772
|
|
|
26741
26773
|
`);
|
|
26742
|
-
toStdout(configBlock(det,
|
|
26774
|
+
toStdout(configBlock(det, det.problem ? "\u2014 fix the problem above, then re-run." : void 0) + "\n");
|
|
26775
|
+
if (!summary.browser.nativeDepsOk) {
|
|
26776
|
+
toStdout(`
|
|
26777
|
+
browser engine: BROKEN \u2014 native dependencies were never built, so no search can run.
|
|
26778
|
+
`);
|
|
26779
|
+
toStdout(` ${summary.browser.nativeDepsFix}
|
|
26780
|
+
`);
|
|
26781
|
+
toStdout(` Underlying error: ${summary.browser.nativeDepsError}
|
|
26782
|
+
`);
|
|
26783
|
+
}
|
|
26743
26784
|
if (!summary.browser.installed) {
|
|
26744
26785
|
toStdout(`
|
|
26745
26786
|
stealth browser: NOT INSTALLED \u2014 run: ${summary.browser.fix}
|
|
@@ -26812,7 +26853,7 @@ async function cmdSkill(s) {
|
|
|
26812
26853
|
toStdout(pretty({
|
|
26813
26854
|
command: "skill",
|
|
26814
26855
|
action: "status",
|
|
26815
|
-
agents: agents.map((d) => ({ id: d.id, label: d.label, present: d.present, installed: d.installed, path: d.absSkillPath }))
|
|
26856
|
+
agents: agents.map((d) => ({ id: d.id, label: d.label, present: d.present, installed: d.installed, broken: d.broken, path: d.absSkillPath }))
|
|
26816
26857
|
}));
|
|
26817
26858
|
return EXIT.OK;
|
|
26818
26859
|
}
|
|
@@ -26820,7 +26861,8 @@ async function cmdSkill(s) {
|
|
|
26820
26861
|
|
|
26821
26862
|
`);
|
|
26822
26863
|
for (const d of agents) {
|
|
26823
|
-
const
|
|
26864
|
+
const kind = d.installed === "owned-copy" ? "copy" : "symlink";
|
|
26865
|
+
const state = !d.present ? "agent not detected" : d.installed === "none" ? "not installed" : d.installed === "foreign" ? "a different skill occupies this slot \u2014 left untouched" : d.broken ? `BROKEN ${kind} \u2014 target is missing or incomplete; re-run \`${BINARY_NAME} skill install\`` : `installed (${kind})`;
|
|
26824
26866
|
const loc = d.installed === "owned-symlink" || d.installed === "owned-copy" ? ` \u2192 ${d.absSkillPath}` : "";
|
|
26825
26867
|
toStdout(` ${d.label.padEnd(18)} ${state}${loc}
|
|
26826
26868
|
`);
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,28 @@ 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.6.2] - 2026-08-24
|
|
9
|
+
|
|
10
|
+
An agent-skill run reported that every search had failed and concluded it had hit an
|
|
11
|
+
unfixable environment problem. It was half right: the install really was broken, but
|
|
12
|
+
nothing in the tool would say so, and one of the two causes was the tool's own doing.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **A second install captured the skill links of the first.** `reconcileSkillInstalls()` runs on every engine-touching CLI invocation and resolves its source from whichever copy is being invoked. It re-pointed any owned link whose destination differed — including a perfectly healthy one — so an ordinary second install captured the user's global Claude/Codex/OpenClaw skill links merely by being run once. That is a documented setup, not an exotic one: `docs/SDK.md` instructs users to `npm install @lincoln504/pi-research` INTO their project so the SDK imports resolve, and anything that then ran the project-local CLI moved the global skill into the project. Moving, cleaning or deleting the project later killed the skill with an opaque `Cannot find module …/scripts/run.mjs`. Reconcile now repairs only a link that is dangling or whose target has been gutted — the case it was written for, which is what an update that relocates the package actually produces. Choosing between two live installs is what the explicit `skill install` is for. Two existing tests asserted the old behaviour and were unfaithful in the same way: each described "package relocated by an update" while leaving the old directory on disk, so the link never dangled (`src/skill-install/skill-installer.ts`).
|
|
17
|
+
- **`skill status` called a dead skill installed.** Detection tested that the link existed, never that it resolved, so a dangling symlink reported as `installed (symlink)` — leaving the harness's later "Cannot find module" as the only signal anything was wrong. A link or copy whose target is missing, or which lacks `SKILL.md` / `scripts/run.mjs`, is now reported as BROKEN with the command that repairs it (`src/skill-install/skill-installer.ts`, `src/cli.ts`).
|
|
18
|
+
- **`status` reported a build that cannot search as ready.** npm 12 turns dependency install scripts off by default. `camoufox-js` needs `better-sqlite3` to launch a browser at all, and its binding is produced by exactly such a script — so the module imports fine and throws only at first use. `ready` was derived from credentials alone and said yes; `isBrowserAvailable()` only stats the camoufox binary and never sees it. Measured across every native dependency this package ships: better-sqlite3 is the ONLY one that fails that way — onnxruntime-node carries its binding inside its own tarball, and lancedb, impit and html-to-markdown resolve prebuilt platform packages, which is why the knowledge store kept answering while search was dead. `status` now opens an in-memory database to settle it, gates `ready` on the result, and prints the remedy. The old comment claiming "nothing else fails" was wrong and is corrected (`src/infrastructure/browser/config.ts`, `src/cli.ts`).
|
|
19
|
+
- **A broken install was reported as a network outage.** With no binding, every browser worker dies identically and the run said browser workers may be unavailable, DuckDuckGo unreachable, or the system under extreme load. All three were false and none is actionable — a calling agent read it and gave up rather than reinstalling. A total search failure whose workers all died on a missing native module now says it is an incomplete install and names the flag that fixes it (`src/infrastructure/browser/browser-error-utils.ts`, `src/web-research/browser-search.ts`).
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- **README documents the npm 12 install flag** on the install commands themselves, and drops a claim that a run flags unreachable pages. Turnstile is named because it is the challenge readers actually hit, and a handful of inflated verbs are now plain ones.
|
|
24
|
+
|
|
25
|
+
### Verified
|
|
26
|
+
|
|
27
|
+
- 2938 unit tests over 233 files, lint, type-check over source and tests, dependency-cruiser.
|
|
28
|
+
- The failure mode was reproduced and the remedy measured: a scripts-blocked install of 1.6.1 fails `better-sqlite3` at first use and passes every other native dependency. A live agent-skill run through the installed link completes clean with zero binding errors.
|
|
29
|
+
|
|
8
30
|
## [1.6.1] - 2026-08-23
|
|
9
31
|
|
|
10
32
|
A report that contained no analysis was being delivered as a completed run, because
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -45,7 +45,7 @@ import { getConfig, getGlobalConfigDir, getGlobalEnvFilePath, getInterfaceEnvFil
|
|
|
45
45
|
import { getAgentDir } from '@earendil-works/pi-coding-agent';
|
|
46
46
|
import { buildModelRegistry, safeGetAvailable } from './core/llm/model-registry-factory.ts';
|
|
47
47
|
import { RESEARCH_TOOL_NAMES } from './constants.ts';
|
|
48
|
-
import { isBrowserAvailable } from './infrastructure/browser/config.ts';
|
|
48
|
+
import { isBrowserAvailable, probeBrowserNativeDeps } from './infrastructure/browser/config.ts';
|
|
49
49
|
|
|
50
50
|
// ---------------------------------------------------------------------------
|
|
51
51
|
// Constants
|
|
@@ -796,19 +796,25 @@ async function cmdStatus(json?: boolean): Promise<number> {
|
|
|
796
796
|
// (scripts/setup.cjs), which npm 11.19+ BLOCKS BY DEFAULT — it now warns
|
|
797
797
|
// "packages have install scripts not yet covered by allowScripts" and carries
|
|
798
798
|
// on, so the browser is simply absent on an otherwise successful install.
|
|
799
|
-
//
|
|
800
|
-
//
|
|
801
|
-
//
|
|
802
|
-
//
|
|
803
|
-
//
|
|
804
|
-
//
|
|
805
|
-
//
|
|
799
|
+
// A missing browser DEGRADES capability rather than breaking the tool — the fetch
|
|
800
|
+
// path still serves most pages — so it is reported alongside `ready` rather than
|
|
801
|
+
// folded into it. isBrowserAvailable() is a resolve + existsSync; it never launches
|
|
802
|
+
// anything.
|
|
803
|
+
//
|
|
804
|
+
// The browser's NATIVE DEPENDENCIES are a separate and harsher question, and were
|
|
805
|
+
// previously assumed away here with "nothing else fails". Measured: better-sqlite3,
|
|
806
|
+
// which camoufox-js needs to launch at all, is built by a dependency install script
|
|
807
|
+
// and does NOT survive a scripts-blocked install. When it is missing every browser
|
|
808
|
+
// worker dies and SEARCH IS DEAD — not degraded — while the knowledge store keeps
|
|
809
|
+
// working because onnxruntime and lancedb both ship their binaries. That is not a
|
|
810
|
+
// capability note, so it gates `ready`: a build that cannot search cannot research.
|
|
806
811
|
const browserInstalled = isBrowserAvailable();
|
|
812
|
+
const nativeDeps = probeBrowserNativeDeps();
|
|
807
813
|
const summary = {
|
|
808
814
|
package: '@lincoln504/pi-research',
|
|
809
815
|
version: PKG_VERSION,
|
|
810
816
|
cli: `node ${process.argv[1]}`,
|
|
811
|
-
ready: !det.problem,
|
|
817
|
+
ready: !det.problem && nativeDeps.ok,
|
|
812
818
|
credentials: {
|
|
813
819
|
source: det.source,
|
|
814
820
|
apiKeyConfigured: det.apiKeyConfigured,
|
|
@@ -819,6 +825,11 @@ async function cmdStatus(json?: boolean): Promise<number> {
|
|
|
819
825
|
},
|
|
820
826
|
browser: {
|
|
821
827
|
installed: browserInstalled,
|
|
828
|
+
nativeDepsOk: nativeDeps.ok,
|
|
829
|
+
nativeDepsError: nativeDeps.ok ? null : nativeDeps.error,
|
|
830
|
+
nativeDepsFix: nativeDeps.ok
|
|
831
|
+
? null
|
|
832
|
+
: 'Reinstall allowing dependency install scripts: npm install -g @lincoln504/pi-research --allow-scripts (npm 12 turns them off by default).',
|
|
822
833
|
// Same remedy the health check prints, so both surfaces name one command.
|
|
823
834
|
fix: browserInstalled ? null : 'npx camoufox-js fetch',
|
|
824
835
|
note: browserInstalled
|
|
@@ -837,7 +848,19 @@ async function cmdStatus(json?: boolean): Promise<number> {
|
|
|
837
848
|
|
|
838
849
|
toStdout(`pi-research ${PKG_VERSION}\n`);
|
|
839
850
|
toStdout(`ready: ${summary.ready ? 'yes' : 'no'}\n\n`);
|
|
840
|
-
|
|
851
|
+
// The hint points at the CONFIG block, so it belongs to a credential problem only.
|
|
852
|
+
// `ready` can now also be false because the browser's native deps are missing, and
|
|
853
|
+
// that is reported below with its own remedy — sending the reader back to a config
|
|
854
|
+
// block that has nothing wrong with it would be its own small lie.
|
|
855
|
+
toStdout(configBlock(det, det.problem ? '— fix the problem above, then re-run.' : undefined) + '\n');
|
|
856
|
+
if (!summary.browser.nativeDepsOk) {
|
|
857
|
+
// Printed BEFORE the browser-download note: a missing binary is a degradation the
|
|
858
|
+
// fetch path covers, while a missing binding means no search runs at all. The more
|
|
859
|
+
// severe problem has to be the one the reader sees first.
|
|
860
|
+
toStdout(`\nbrowser engine: BROKEN — native dependencies were never built, so no search can run.\n`);
|
|
861
|
+
toStdout(` ${summary.browser.nativeDepsFix}\n`);
|
|
862
|
+
toStdout(` Underlying error: ${summary.browser.nativeDepsError}\n`);
|
|
863
|
+
}
|
|
841
864
|
if (!summary.browser.installed) {
|
|
842
865
|
toStdout(`\nstealth browser: NOT INSTALLED — run: ${summary.browser.fix}\n`);
|
|
843
866
|
toStdout(` ${summary.browser.note}\n`);
|
|
@@ -940,16 +963,21 @@ async function cmdSkill(s: NonNullable<ParsedArgs['skill']>): Promise<number> {
|
|
|
940
963
|
if (s.json) {
|
|
941
964
|
toStdout(pretty({
|
|
942
965
|
command: 'skill', action: 'status',
|
|
943
|
-
agents: agents.map((d) => ({ id: d.id, label: d.label, present: d.present, installed: d.installed, path: d.absSkillPath })),
|
|
966
|
+
agents: agents.map((d) => ({ id: d.id, label: d.label, present: d.present, installed: d.installed, broken: d.broken, path: d.absSkillPath })),
|
|
944
967
|
}));
|
|
945
968
|
return EXIT.OK;
|
|
946
969
|
}
|
|
947
970
|
toStdout(`pi-research agent skill — install status\n\n`);
|
|
948
971
|
for (const d of agents) {
|
|
972
|
+
// A broken install must not read as a working one. It said "installed (symlink)"
|
|
973
|
+
// for a link whose target had been deleted, so the only sign anything was wrong
|
|
974
|
+
// came later, from the harness, as "Cannot find module …/scripts/run.mjs".
|
|
975
|
+
const kind = d.installed === 'owned-copy' ? 'copy' : 'symlink';
|
|
949
976
|
const state = !d.present ? 'agent not detected'
|
|
950
977
|
: d.installed === 'none' ? 'not installed'
|
|
951
978
|
: d.installed === 'foreign' ? 'a different skill occupies this slot — left untouched'
|
|
952
|
-
: `
|
|
979
|
+
: d.broken ? `BROKEN ${kind} — target is missing or incomplete; re-run \`${BINARY_NAME} skill install\``
|
|
980
|
+
: `installed (${kind})`;
|
|
953
981
|
const loc = d.installed === 'owned-symlink' || d.installed === 'owned-copy' ? ` → ${d.absSkillPath}` : '';
|
|
954
982
|
toStdout(` ${d.label.padEnd(18)} ${state}${loc}\n`);
|
|
955
983
|
}
|
|
@@ -124,6 +124,27 @@ export function isPoolShutdownError(error: unknown): boolean {
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* A native addon that is missing or unloadable, i.e. a BROKEN INSTALL rather than
|
|
129
|
+
* anything about the page, the network or the load on the machine.
|
|
130
|
+
*
|
|
131
|
+
* The case that produced this: npm 12 turns `allowScripts` OFF by default, so a
|
|
132
|
+
* plain `npm install` no longer runs dependency lifecycle scripts — including the
|
|
133
|
+
* one that fetches/builds `better-sqlite3`, which `camoufox-js` needs to launch a
|
|
134
|
+
* browser at all. Every browser worker then dies with "Could not locate the
|
|
135
|
+
* bindings file", every query fails, and the run reported that DuckDuckGo might be
|
|
136
|
+
* unreachable or the machine under extreme load. Neither was true, and the advice
|
|
137
|
+
* that follows from each is useless. An install fault has to say so.
|
|
138
|
+
*/
|
|
139
|
+
const NATIVE_BINDING_FAILURE =
|
|
140
|
+
/Could not locate the bindings file|ERR_DLOPEN_FAILED|NODE_MODULE_VERSION|was compiled against a different Node\.js version|invalid ELF header|Cannot find module '[^']*\.node'/;
|
|
141
|
+
|
|
142
|
+
/** True when the failure is a missing/unloadable native addon — a broken install. */
|
|
143
|
+
export function isNativeBindingError(error: unknown): boolean {
|
|
144
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
145
|
+
return NATIVE_BINDING_FAILURE.test(msg);
|
|
146
|
+
}
|
|
147
|
+
|
|
127
148
|
/** Playwright navigation failures whose cause is at the remote end — see below. */
|
|
128
149
|
const BENIGN_NAVIGATION_FAILURE =
|
|
129
150
|
/page\.goto: (?:Timeout \d+ *ms exceeded|net::|NS_ERROR_|SEC_ERROR_|MOZILLA_PKIX_ERROR_)/;
|
|
@@ -12,6 +12,7 @@ import { platform, homedir } from 'node:os';
|
|
|
12
12
|
import type { Config } from '../../config.ts';
|
|
13
13
|
import { getConfig } from '../../config.ts';
|
|
14
14
|
import { getLogger } from '../../logger.ts';
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
15
16
|
|
|
16
17
|
// ============================================================================
|
|
17
18
|
// Binary Cache Management
|
|
@@ -310,6 +311,48 @@ export function resolveHeadlessMode(): boolean | 'virtual' {
|
|
|
310
311
|
*
|
|
311
312
|
* Single point of control: all existing skipTests() checks use this function.
|
|
312
313
|
*/
|
|
314
|
+
/**
|
|
315
|
+
* Whether the browser stack's NATIVE dependencies can actually load.
|
|
316
|
+
*
|
|
317
|
+
* `isBrowserAvailable()` answers a different question — is the camoufox binary on
|
|
318
|
+
* disk — and a browser can be fully downloaded and still unable to launch. camoufox-js
|
|
319
|
+
* requires `better-sqlite3`, whose binding is produced by a dependency INSTALL SCRIPT,
|
|
320
|
+
* and npm 12 turns those off by default. The module then imports fine and throws only
|
|
321
|
+
* when first used, so nothing notices until every browser worker dies mid-run with
|
|
322
|
+
* "Could not locate the bindings file" and the run reports a network problem it does
|
|
323
|
+
* not have.
|
|
324
|
+
*
|
|
325
|
+
* Measured, not assumed: of this package's native dependencies, only better-sqlite3
|
|
326
|
+
* fails a scripts-blocked install. onnxruntime-node ships its binding inside its own
|
|
327
|
+
* tarball, and lancedb, impit and html-to-markdown all resolve prebuilt platform
|
|
328
|
+
* packages, so the knowledge store keeps working while search is dead — exactly the
|
|
329
|
+
* split seen in the field.
|
|
330
|
+
*
|
|
331
|
+
* Opening an in-memory database is the only check that settles it: resolving the
|
|
332
|
+
* module or stat-ing a path does not, because the failure is in the binding lookup at
|
|
333
|
+
* first use. It costs a few milliseconds and is confined to diagnostics.
|
|
334
|
+
*/
|
|
335
|
+
export function probeBrowserNativeDeps(
|
|
336
|
+
/** Injected for tests. Production callers pass nothing. */
|
|
337
|
+
load: () => void = defaultNativeDepLoad,
|
|
338
|
+
): { ok: true } | { ok: false; error: string } {
|
|
339
|
+
try {
|
|
340
|
+
load();
|
|
341
|
+
return { ok: true };
|
|
342
|
+
} catch (err) {
|
|
343
|
+
// First line only: the bindings error enumerates every path it tried, which is
|
|
344
|
+
// pages of noise in a status block. The rest is in the log if it is wanted.
|
|
345
|
+
return { ok: false, error: err instanceof Error ? err.message.split('\n')[0]!.trim() : String(err) };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function defaultNativeDepLoad(): void {
|
|
350
|
+
const require = createRequire(import.meta.url);
|
|
351
|
+
const Database = require('better-sqlite3') as new (p: string) => { close(): void };
|
|
352
|
+
const db = new Database(':memory:');
|
|
353
|
+
db.close();
|
|
354
|
+
}
|
|
355
|
+
|
|
313
356
|
export function isBrowserAvailable(): boolean {
|
|
314
357
|
if (isFullMockMode()) return false;
|
|
315
358
|
try {
|
|
@@ -325,6 +325,14 @@ export interface DetectedHarness extends HarnessDef {
|
|
|
325
325
|
absSkillPath: string;
|
|
326
326
|
/** Current install state of THIS skill at that path. */
|
|
327
327
|
installed: 'none' | 'owned-symlink' | 'owned-copy' | 'foreign';
|
|
328
|
+
/**
|
|
329
|
+
* Ours, but not usable: the symlink dangles, or the directory it resolves to is
|
|
330
|
+
* missing SKILL.md / scripts/run.mjs. Reported because the alternative is what
|
|
331
|
+
* actually happened — `skill status` said "installed (symlink)" for a link whose
|
|
332
|
+
* target had been deleted, so the only signal the user got was the harness failing
|
|
333
|
+
* later with "Cannot find module …/scripts/run.mjs".
|
|
334
|
+
*/
|
|
335
|
+
broken: boolean;
|
|
328
336
|
}
|
|
329
337
|
|
|
330
338
|
export function detectHarnesses(opts?: { home?: string }): DetectedHarness[] {
|
|
@@ -342,10 +350,28 @@ export function detectHarnesses(opts?: { home?: string }): DetectedHarness[] {
|
|
|
342
350
|
else installed = 'foreign';
|
|
343
351
|
}
|
|
344
352
|
} catch { /* none */ }
|
|
345
|
-
|
|
353
|
+
const broken = (installed === 'owned-symlink' || installed === 'owned-copy')
|
|
354
|
+
&& !isUsableSkillDir(absSkillPath);
|
|
355
|
+
return { ...h, present, absSkillsDir, absSkillPath, installed, broken };
|
|
346
356
|
});
|
|
347
357
|
}
|
|
348
358
|
|
|
359
|
+
/**
|
|
360
|
+
* The two files a skill directory is useless without: the manifest a harness reads to
|
|
361
|
+
* discover the skill, and the launcher it executes. A link or copy can exist while the
|
|
362
|
+
* thing it points at does not — the target was deleted, moved, or partially removed —
|
|
363
|
+
* and the harness then fails at invocation time with "Cannot find module …/run.mjs",
|
|
364
|
+
* which says nothing about the install being the problem. Checked rather than assumed
|
|
365
|
+
* so both `skill status` and the startup reconcile can tell a live install from a
|
|
366
|
+
* hollow one.
|
|
367
|
+
*/
|
|
368
|
+
function isUsableSkillDir(p: string): boolean {
|
|
369
|
+
try {
|
|
370
|
+
return fs.existsSync(path.join(p, 'SKILL.md'))
|
|
371
|
+
&& fs.existsSync(path.join(p, 'scripts', 'run.mjs'));
|
|
372
|
+
} catch { return false; }
|
|
373
|
+
}
|
|
374
|
+
|
|
349
375
|
function isSymlinkPresent(p: string): boolean {
|
|
350
376
|
try { return fs.lstatSync(p).isSymbolicLink(); } catch { return false; }
|
|
351
377
|
}
|
|
@@ -695,12 +721,23 @@ export function reconcileSkillInstalls(opts: InstallOptions = {}): ReconcileResu
|
|
|
695
721
|
// Only ever touch links we own; a foreign link at this path stays + tracked.
|
|
696
722
|
if (!isOwnedSymlink(e.path)) { keep.push(e); continue; }
|
|
697
723
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
const
|
|
703
|
-
|
|
724
|
+
// A target that resolves but has been gutted (partial delete, interrupted
|
|
725
|
+
// install, pruned tree) is as dead as one that is gone — and it fails later,
|
|
726
|
+
// at invocation, with an error that never mentions the install. Treat both as
|
|
727
|
+
// needing repair.
|
|
728
|
+
const targetLive = fs.existsSync(e.path) && isUsableSkillDir(e.path); // existsSync follows the link
|
|
729
|
+
|
|
730
|
+
// A link pointing at a DIFFERENT but perfectly live pi-research install is left
|
|
731
|
+
// alone. Re-pointing it was a silent hijack: reconcile runs on every
|
|
732
|
+
// engine-touching CLI invocation, from whichever copy of the package is being
|
|
733
|
+
// invoked, so any second install captured the user's skill links just by being
|
|
734
|
+
// run once. docs/SDK.md tells users to `npm install @lincoln504/pi-research` INTO
|
|
735
|
+
// their project, so the second install is a documented, ordinary setup — and when
|
|
736
|
+
// that project was later moved or cleaned, the global skill died with an opaque
|
|
737
|
+
// "Cannot find module .../run.mjs". Self-healing only needs the dangling case
|
|
738
|
+
// (`!targetLive`), which is what an update that relocates the package produces;
|
|
739
|
+
// choosing between two live installs is what the explicit `skill install` is for.
|
|
740
|
+
if (!targetLive) {
|
|
704
741
|
if (source !== null) {
|
|
705
742
|
// Re-point to the current package source (handles update/reinstall).
|
|
706
743
|
try {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { runWorkerSearch } from '../infrastructure/browser/task-execution-service.ts';
|
|
8
8
|
import { getMaxWorkers, COLD_START_ALLOWANCE_MS } from '../infrastructure/browser/config.ts';
|
|
9
|
-
import { isTaskTimeoutError } from '../infrastructure/browser/browser-error-utils.ts';
|
|
9
|
+
import { isTaskTimeoutError, isNativeBindingError } from '../infrastructure/browser/browser-error-utils.ts';
|
|
10
10
|
import { logger } from '../logger.ts';
|
|
11
11
|
import { safeUnref } from '../utils/safe-unref.ts';
|
|
12
12
|
import { normalizeUrl } from '../utils/url-utils.ts';
|
|
@@ -321,6 +321,24 @@ export async function performSearch(
|
|
|
321
321
|
reason = `${timeoutCount} queries timed out and ${errorCount} queries failed`;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
// A missing native addon is a BROKEN INSTALL, and the generic advice below
|
|
325
|
+
// actively misleads: it sends the reader to check their network and their
|
|
326
|
+
// machine load when neither is involved and neither can be acted on. npm 12
|
|
327
|
+
// defaults `allowScripts` to off, so a plain install no longer builds
|
|
328
|
+
// camoufox-js's better-sqlite3 dependency and every browser worker dies
|
|
329
|
+
// identically. Say that instead, and say what fixes it.
|
|
330
|
+
if (isNativeBindingError(sampleWorkerError)) {
|
|
331
|
+
metrics.increment('browser_search_total_failures_total', 1, { cause: 'native_binding' });
|
|
332
|
+
throw new Error(
|
|
333
|
+
`Search completely failed: ${reason}, all with a missing native module. ` +
|
|
334
|
+
`This is an incomplete install, not a network problem: the browser engine's ` +
|
|
335
|
+
`native dependencies were never built. npm 12 does not run dependency install ` +
|
|
336
|
+
`scripts by default — reinstall allowing them (npm install @lincoln504/pi-research ` +
|
|
337
|
+
`--allow-scripts, or npm approve-scripts --allow-scripts-pending), then retry.` +
|
|
338
|
+
(sampleWorkerError ? ` Last worker error: ${sampleWorkerError}` : '')
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
324
342
|
throw new Error(
|
|
325
343
|
`Search completely failed: ${reason}. ` +
|
|
326
344
|
`Browser workers may be unavailable, DuckDuckGo is unreachable, or the system is under extreme load.` +
|