@lincoln504/pi-research 1.6.4 → 1.6.6

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.
Files changed (63) hide show
  1. package/README.md +12 -8
  2. package/agent-skill/pi-research/README.md +4 -3
  3. package/agent-skill/pi-research/SKILL.md +1 -1
  4. package/dist/cli.mjs +587 -149
  5. package/dist/pdf-extract-worker.mjs +1289 -0
  6. package/dist/prompts/research-tool-usage.md +2 -1
  7. package/dist/prompts/researcher.md +1 -1
  8. package/dist/prompts/system-coordinator.md +2 -2
  9. package/dist/prompts/system-lead-router.md +1 -1
  10. package/docs/AGENT-SKILL.md +4 -3
  11. package/docs/ARCHITECTURE.md +24 -22
  12. package/docs/CHANGELOG.md +73 -1
  13. package/docs/CONFIGURATION.md +3 -2
  14. package/docs/SDK.md +7 -12
  15. package/package.json +7 -4
  16. package/scripts/build.cjs +35 -0
  17. package/scripts/setup.cjs +12 -10
  18. package/src/cleanup/research-cleanup.ts +11 -5
  19. package/src/cli.ts +7 -5
  20. package/src/config.ts +9 -3
  21. package/src/core/interfaces/knowledge-interfaces.ts +8 -0
  22. package/src/core/interfaces/orchestration-interfaces.ts +1 -1
  23. package/src/core/interfaces/research-plan-types.ts +6 -0
  24. package/src/core/llm/agentic-repair.ts +40 -3
  25. package/src/core/llm/llm-utils.ts +93 -5
  26. package/src/core/llm/model-registry-factory.ts +2 -15
  27. package/src/core/pi-ai-skew.ts +351 -0
  28. package/src/core/pi-version.ts +1 -1
  29. package/src/core/planning-service.ts +110 -15
  30. package/src/core/planning-utils.ts +3 -0
  31. package/src/core/service-registry.ts +8 -6
  32. package/src/index.ts +14 -0
  33. package/src/infrastructure/browser/config.ts +6 -7
  34. package/src/infrastructure/browser/ensure-browser.ts +14 -7
  35. package/src/infrastructure/browser/thread-worker-browser.ts +18 -19
  36. package/src/knowledge/chunker.ts +22 -4
  37. package/src/knowledge/embedder-init.ts +41 -1
  38. package/src/knowledge/store.ts +68 -1
  39. package/src/observers/research-observer-impl.ts +4 -1
  40. package/src/orchestration/deep-research-orchestrator.ts +3 -3
  41. package/src/orchestration/headless-observer.ts +33 -0
  42. package/src/orchestration/quick-research-orchestrator.ts +17 -3
  43. package/src/orchestration/research-orchestration-service.ts +27 -4
  44. package/src/orchestration/session-state.ts +36 -7
  45. package/src/prompts/research-tool-usage.md +2 -1
  46. package/src/prompts/researcher.md +1 -1
  47. package/src/prompts/system-coordinator.md +2 -2
  48. package/src/prompts/system-lead-router.md +1 -1
  49. package/src/sdk.ts +12 -4
  50. package/src/tools/research-knowledge-search.ts +23 -7
  51. package/src/tools/research-tool-definition.ts +1 -1
  52. package/src/tools/scrape.ts +12 -9
  53. package/src/tools/search.ts +12 -6
  54. package/src/tools/security.ts +6 -1
  55. package/src/tools/stackexchange.ts +6 -1
  56. package/src/utils/cancellation.ts +34 -1
  57. package/src/utils/llm-usage.ts +8 -0
  58. package/src/utils/log-utils.ts +1 -1
  59. package/src/web-research/browser-search.ts +6 -5
  60. package/src/web-research/pdf-extract-worker.mjs +1289 -0
  61. package/src/web-research/pdf-extract-worker.ts +42 -0
  62. package/src/web-research/pdf-extraction.ts +392 -0
  63. package/src/web-research/web-scraper.ts +3 -111
@@ -67,6 +67,14 @@ function warnIfUnpriced(model: Model<any>, tokens: number, cost: number): void {
67
67
  * `tokens > 0 || cost > 0`, so a response whose usage is all-zero across the board
68
68
  * emits nothing — harmless in practice because cache fields are summed into `tokens`,
69
69
  * so a reported cache split implies a nonzero total.
70
+ *
71
+ * Accuracy note: for the openai-completions API family (which includes OpenRouter),
72
+ * pi-ai's usage normalization ALWAYS sets cacheRead/cacheWrite, defaulting missing
73
+ * upstream fields to 0 — so on those providers a route without prompt caching shows the
74
+ * counter at 0 rather than omitting it. The 0-vs-absent distinction only holds for APIs
75
+ * that omit the fields outright. A run showing llm_cache_read_tokens_total stuck at 0
76
+ * with nonzero input tokens is therefore most simply read as "this route reports no
77
+ * cached tokens", not "our prompts defeat the cache".
70
78
  */
71
79
  function recordCacheTokens(parsed: Partial<TokenUsage>, labels: Record<string, string>): void {
72
80
  if (typeof parsed.cacheRead === 'number') {
@@ -38,7 +38,7 @@ export function buildDefaultDebugLogPath(): string {
38
38
  * Check whether debug/verbose logging is enabled.
39
39
  *
40
40
  * Reads PI_RESEARCH_DEBUG env var. Config SAVES sync config.DEBUG into this
41
- * env var (see config.ts buildEnvValues); plain config LOADS do not mutate
41
+ * env var (see the DEBUG → PI_RESEARCH_DEBUG bridge in config.ts createConfig); plain config LOADS do not mutate
42
42
  * process.env, so a DEBUG=true line in config.env enables verbose logging for
43
43
  * a process only after a save has run in it — export PI_RESEARCH_DEBUG=true
44
44
  * in the environment to guarantee it from process start.
@@ -331,11 +331,12 @@ export async function performSearch(
331
331
  metrics.increment('browser_search_total_failures_total', 1, { cause: 'native_binding' });
332
332
  throw new Error(
333
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 the script (global install: ` +
337
- `npm install -g @lincoln504/pi-research --allow-scripts=better-sqlite3; ` +
338
- `project install: npm approve-scripts better-sqlite3, then npm rebuild better-sqlite3), then retry.` +
334
+ `This is an incomplete install, not a network problem: better-sqlite3 13 ` +
335
+ `ships prebuilt bindings for every supported platform and loads them at ` +
336
+ `runtime, so a missing binding means an old or broken npm install. ` +
337
+ `Upgrade npm to ≥12 (npm install -g npm@12) and reinstall this package — ` +
338
+ `modern npm skips the needless recompile that fails on toolchain-less ` +
339
+ `machines, and the prebuilt binding then loads as-is.` +
339
340
  (sampleWorkerError ? ` Last worker error: ${sampleWorkerError}` : '')
340
341
  );
341
342
  }