@lincoln504/pi-research 0.1.12 → 1.0.0

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 (248) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +64 -115
  3. package/dist/cli.mjs +23211 -0
  4. package/dist/prompts/research-knowledge-relevance-triage.md +35 -0
  5. package/dist/prompts/research-knowledge-search-extractor.md +41 -0
  6. package/dist/prompts/research-tool-usage.md +92 -0
  7. package/dist/prompts/researcher.md +89 -0
  8. package/dist/prompts/system-coordinator.md +75 -0
  9. package/dist/prompts/system-lead-evaluator.md +118 -0
  10. package/dist/thread-worker.mjs +2611 -0
  11. package/dist/webgpu-probe.mjs +80 -0
  12. package/docs/AGENT-SKILL.md +102 -0
  13. package/docs/ARCHITECTURE.md +306 -80
  14. package/docs/CONFIGURATION.md +249 -0
  15. package/docs/KNOWLEDGE-STORE.md +213 -0
  16. package/docs/PI-EXTENSION.md +91 -0
  17. package/docs/SDK.md +113 -0
  18. package/docs/THIRD-PARTY-NOTICES.md +64 -0
  19. package/package.json +102 -36
  20. package/scripts/build.cjs +140 -0
  21. package/scripts/cleanup.cjs +149 -0
  22. package/scripts/prepare.cjs +28 -0
  23. package/scripts/setup.cjs +134 -0
  24. package/skills/pi-research/README.md +90 -0
  25. package/skills/pi-research/SKILL.md +102 -0
  26. package/skills/pi-research/references/configuration.md +77 -0
  27. package/skills/pi-research/scripts/run.mjs +237 -0
  28. package/src/cleanup/research-cleanup.ts +140 -0
  29. package/src/cli.ts +1044 -0
  30. package/src/config.ts +1036 -147
  31. package/src/constants.ts +115 -84
  32. package/src/core/health-check-service.ts +265 -0
  33. package/src/core/interfaces/health-check-interfaces.ts +50 -0
  34. package/src/core/interfaces/knowledge-interfaces.ts +190 -0
  35. package/src/core/interfaces/observer-interfaces.ts +67 -0
  36. package/src/core/interfaces/orchestration-interfaces.ts +86 -0
  37. package/src/core/interfaces/planning-interfaces.ts +100 -0
  38. package/src/core/interfaces/process-interfaces.ts +37 -0
  39. package/src/core/interfaces/research-plan-types.ts +52 -0
  40. package/src/core/interfaces/scheduler-interfaces.ts +91 -0
  41. package/src/core/interfaces/service-names.ts +39 -0
  42. package/src/core/interfaces/state-manager-interfaces.ts +29 -0
  43. package/src/core/interfaces/steering-interfaces.ts +31 -0
  44. package/src/core/llm/agentic-repair.ts +169 -0
  45. package/src/core/llm/inject-date.ts +52 -0
  46. package/src/core/llm/llm-timeout.ts +64 -0
  47. package/src/core/llm/llm-utils.ts +86 -0
  48. package/src/core/llm/model-registry-factory.ts +287 -0
  49. package/src/core/llm/pi-ai-completion.ts +29 -0
  50. package/src/core/llm/prompts.ts +50 -0
  51. package/src/core/llm/research-model-resolver.ts +91 -0
  52. package/src/core/planning-constants.ts +13 -0
  53. package/src/core/planning-service.ts +649 -0
  54. package/src/core/planning-utils.ts +299 -0
  55. package/src/core/scheduler-factory.ts +48 -0
  56. package/src/core/scheduler-service.ts +123 -0
  57. package/src/core/service-initialization.ts +194 -0
  58. package/src/core/service-interfaces.ts +48 -0
  59. package/src/core/service-registry.ts +659 -0
  60. package/src/healthcheck/index.ts +271 -265
  61. package/src/healthcheck/registry.ts +130 -0
  62. package/src/index.ts +639 -50
  63. package/src/infrastructure/browser/browser-cleanup.ts +309 -0
  64. package/src/infrastructure/browser/browser-client.ts +199 -0
  65. package/src/infrastructure/browser/browser-error-utils.ts +160 -0
  66. package/src/infrastructure/browser/browser-lifecycle.ts +120 -0
  67. package/src/infrastructure/browser/browser-server.ts +174 -0
  68. package/src/infrastructure/browser/browser-task-scheduler.ts +461 -0
  69. package/src/infrastructure/browser/cleanup-utils.ts +155 -0
  70. package/src/infrastructure/browser/client-agent.ts +31 -0
  71. package/src/infrastructure/browser/config.ts +288 -0
  72. package/src/infrastructure/browser/ensure-browser.ts +205 -0
  73. package/src/infrastructure/browser/index.ts +37 -0
  74. package/src/infrastructure/browser/priority-task-queue.ts +226 -0
  75. package/src/infrastructure/browser/scheduler-factory.ts +354 -0
  76. package/src/infrastructure/browser/task-execution-service.ts +209 -0
  77. package/src/infrastructure/browser/thread-worker-browser.ts +282 -0
  78. package/src/infrastructure/browser/thread-worker-lifecycle.ts +323 -0
  79. package/src/infrastructure/browser/thread-worker-messaging.ts +662 -0
  80. package/src/infrastructure/browser/thread-worker-types.ts +25 -0
  81. package/src/infrastructure/browser/thread-worker.mjs +2611 -0
  82. package/src/infrastructure/browser/thread-worker.ts +168 -0
  83. package/src/infrastructure/browser/worker-pool-manager.ts +449 -0
  84. package/src/infrastructure/embedding/embedding-client.ts +205 -0
  85. package/src/infrastructure/embedding/embedding-factory.ts +324 -0
  86. package/src/infrastructure/embedding/embedding-server.ts +535 -0
  87. package/src/infrastructure/file-lock-service.ts +592 -0
  88. package/src/infrastructure/gpu-resource-service.ts +191 -0
  89. package/src/infrastructure/knowledge-store-service.ts +475 -0
  90. package/src/infrastructure/metrics-service.ts +129 -0
  91. package/src/infrastructure/process-lifecycle-service.ts +253 -0
  92. package/src/infrastructure/scheduler-factory-service.ts +58 -0
  93. package/src/infrastructure/service-initialization.ts +292 -0
  94. package/src/infrastructure/state/state-backup-manager.ts +290 -0
  95. package/src/infrastructure/state/state-browser-api.ts +62 -0
  96. package/src/infrastructure/state/state-browser-manager.ts +70 -0
  97. package/src/infrastructure/state/state-manager-service.ts +264 -0
  98. package/src/infrastructure/state/state-manager.ts +547 -0
  99. package/src/infrastructure/state/state-metrics.ts +92 -0
  100. package/src/infrastructure/state/state-migration.ts +103 -0
  101. package/src/infrastructure/state/state-path-configuration.ts +119 -0
  102. package/src/infrastructure/state/state-session-api.ts +94 -0
  103. package/src/infrastructure/state/state-session-manager.ts +127 -0
  104. package/src/infrastructure/state/state-validator.ts +93 -0
  105. package/src/infrastructure/types/state-types.ts +85 -0
  106. package/src/knowledge/chunker.ts +157 -0
  107. package/src/knowledge/embedder-init.ts +413 -0
  108. package/src/knowledge/embedder-utils.ts +296 -0
  109. package/src/knowledge/embedder.ts +592 -0
  110. package/src/knowledge/index.ts +126 -0
  111. package/src/knowledge/lancedb-loader.ts +35 -0
  112. package/src/knowledge/migration.ts +17 -0
  113. package/src/knowledge/model-config.ts +132 -0
  114. package/src/knowledge/onnx-env.ts +48 -0
  115. package/src/knowledge/store-operations.ts +291 -0
  116. package/src/knowledge/store-schema.ts +79 -0
  117. package/src/knowledge/store.ts +1251 -0
  118. package/src/knowledge/transformers-loader.ts +31 -0
  119. package/src/knowledge/webgpu-probe.mjs +80 -0
  120. package/src/knowledge/webgpu-viability.ts +255 -0
  121. package/src/knowledge/writer-queue.ts +252 -0
  122. package/src/logger.ts +316 -122
  123. package/src/observers/research-observer-impl.ts +459 -0
  124. package/src/orchestration/deep-research-orchestrator.ts +524 -773
  125. package/src/orchestration/deep-research-types.ts +47 -35
  126. package/src/orchestration/headless-observer.ts +114 -0
  127. package/src/orchestration/orchestration-types.ts +33 -0
  128. package/src/orchestration/quick-research-orchestrator.ts +463 -0
  129. package/src/orchestration/research-orchestration-service.ts +549 -0
  130. package/src/orchestration/research-session-service.ts +178 -0
  131. package/src/orchestration/research-synthesis-service.ts +348 -0
  132. package/src/orchestration/researcher-executor.ts +394 -0
  133. package/src/orchestration/researcher.ts +115 -42
  134. package/src/orchestration/service-initialization.ts +109 -0
  135. package/src/orchestration/session-context.ts +7 -3
  136. package/src/orchestration/session-state.ts +672 -0
  137. package/src/prompts/research-knowledge-relevance-triage.md +35 -0
  138. package/src/prompts/research-knowledge-search-extractor.md +41 -0
  139. package/src/prompts/research-tool-usage.md +63 -16
  140. package/src/prompts/researcher.md +59 -136
  141. package/src/prompts/system-coordinator.md +64 -13
  142. package/src/prompts/system-lead-evaluator.md +82 -189
  143. package/src/research-config.ts +872 -0
  144. package/src/sdk.ts +847 -0
  145. package/src/security/cisa-kev.ts +72 -9
  146. package/src/security/cvss.ts +92 -0
  147. package/src/security/ecosystem.ts +45 -0
  148. package/src/security/github-advisories.ts +168 -428
  149. package/src/security/github-advisory-types.ts +282 -0
  150. package/src/security/index.ts +63 -177
  151. package/src/security/nvd-client.ts +550 -0
  152. package/src/security/nvd-types.ts +179 -0
  153. package/src/security/osv-client.ts +246 -0
  154. package/src/security/osv-types.ts +285 -0
  155. package/src/security/types.ts +67 -53
  156. package/src/skill-install/skill-installer.ts +519 -0
  157. package/src/stackexchange/index.ts +81 -27
  158. package/src/stackexchange/output/compact.ts +7 -6
  159. package/src/stackexchange/output/table.ts +11 -7
  160. package/src/stackexchange/queries.ts +0 -10
  161. package/src/stackexchange/rest-client.ts +141 -66
  162. package/src/stackexchange/types.ts +0 -17
  163. package/src/tool.ts +15 -423
  164. package/src/tools/grep.ts +32 -310
  165. package/src/tools/health-tool-definition.ts +101 -0
  166. package/src/tools/index.ts +38 -9
  167. package/src/tools/research-knowledge-search.ts +974 -0
  168. package/src/tools/research-knowledge-types.ts +77 -0
  169. package/src/tools/research-tool-definition.ts +494 -0
  170. package/src/tools/scrape.ts +286 -388
  171. package/src/tools/search.ts +98 -153
  172. package/src/tools/security.ts +107 -80
  173. package/src/tools/stackexchange.ts +58 -35
  174. package/src/tools/youtube-transcript.ts +163 -0
  175. package/src/tui/knowledge-search-panel.ts +86 -0
  176. package/src/tui/pulse.ts +86 -0
  177. package/src/tui/research-health.ts +124 -0
  178. package/src/tui/research-panel-color-utils.ts +340 -0
  179. package/src/tui/research-panel-format.ts +54 -0
  180. package/src/tui/research-panel-state.ts +404 -0
  181. package/src/tui/research-panel-wave.ts +280 -0
  182. package/src/tui/research-panel.ts +339 -435
  183. package/src/tui/research-tui-manager.ts +233 -0
  184. package/src/tui/tui-controller.ts +137 -0
  185. package/src/types/extension-context.ts +18 -49
  186. package/src/types/index.ts +61 -0
  187. package/src/types/llm.ts +68 -29
  188. package/src/types/research-panel-types.ts +61 -0
  189. package/src/utils/circuit-breaker.ts +146 -0
  190. package/src/utils/citation-utils.ts +97 -0
  191. package/src/utils/disk-space-checker.ts +55 -0
  192. package/src/utils/error-tracker.ts +265 -0
  193. package/src/utils/host-config.ts +45 -0
  194. package/src/utils/input-validation.ts +8 -10
  195. package/src/utils/json-utils.ts +150 -16
  196. package/src/utils/llm-usage.ts +54 -0
  197. package/src/utils/log-rotation.ts +125 -0
  198. package/src/utils/log-utils.ts +159 -0
  199. package/src/utils/make-resource-loader.ts +3 -1
  200. package/src/utils/metrics-summary.ts +459 -0
  201. package/src/utils/metrics.ts +302 -0
  202. package/src/utils/research-export.ts +28 -12
  203. package/src/utils/safe-unref.ts +31 -0
  204. package/src/utils/shared-links.ts +195 -90
  205. package/src/utils/shutdown-manager.ts +65 -0
  206. package/src/utils/stdio-capture.ts +407 -0
  207. package/src/utils/text-utils.ts +264 -7
  208. package/src/utils/tool-usage-tracker.ts +83 -16
  209. package/src/utils/url-utils.ts +255 -0
  210. package/src/utils/user-agent.ts +28 -0
  211. package/src/web-research/browser-search.ts +179 -0
  212. package/src/web-research/retry-utils.ts +173 -77
  213. package/src/web-research/scraper-types.ts +72 -0
  214. package/src/web-research/scraper-utils.ts +434 -0
  215. package/src/web-research/search.ts +78 -218
  216. package/src/web-research/types.ts +9 -24
  217. package/src/web-research/utils.ts +2 -143
  218. package/src/web-research/web-scraper.ts +477 -0
  219. package/src/youtube/index.ts +154 -0
  220. package/src/youtube/potoken.ts +259 -0
  221. package/src/youtube/transcript-client.ts +390 -0
  222. package/src/youtube/video-id.ts +118 -0
  223. package/config/searxng/default-settings.yml +0 -189
  224. package/config/searxng/limiter.toml +0 -34
  225. package/config/tooling/eslint.config.js +0 -73
  226. package/config/tooling/vitest.config.integration.ts +0 -17
  227. package/config/tooling/vitest.config.ts +0 -40
  228. package/config/tooling/vitest.config.unit.ts +0 -12
  229. package/docs/assets/README-banner.jpg +0 -0
  230. package/scripts/setup.js +0 -174
  231. package/src/infrastructure/searxng-lifecycle.ts +0 -577
  232. package/src/infrastructure/searxng-manager.ts +0 -1183
  233. package/src/infrastructure/state-manager.ts +0 -918
  234. package/src/orchestration/deep-research-reducer.ts +0 -129
  235. package/src/orchestration/id-utils.ts +0 -63
  236. package/src/security/nvd.ts +0 -532
  237. package/src/security/osv.ts +0 -487
  238. package/src/stackexchange/cache.ts +0 -111
  239. package/src/stackexchange/output/index.ts +0 -7
  240. package/src/stackexchange/output/json.ts +0 -21
  241. package/src/tui/searxng-status.ts +0 -80
  242. package/src/utils/inject-date.ts +0 -29
  243. package/src/utils/research-error.ts +0 -205
  244. package/src/utils/searxng-config.ts +0 -94
  245. package/src/utils/session-state.ts +0 -295
  246. package/src/web-research/dependencies.ts +0 -20
  247. package/src/web-research/scrapers.ts +0 -935
  248. package/tsconfig.json +0 -40
@@ -0,0 +1,249 @@
1
+ ## Configuration
2
+
3
+ Every front-end (the pi extension, the standalone CLI / agent skill — the surface
4
+ OpenClaw and other skills-aware hosts run — and the SDK) shares one configuration
5
+ model. This document covers the
6
+ settings exposed in the `/research-config` TUI first, then the complete
7
+ environment-variable reference, and finally how the configuration layers resolve.
8
+
9
+ ![The /research-config settings TUI](media/04-config.gif)
10
+
11
+ ### Settings in the TUI
12
+
13
+ Run `/research-config` in the pi extension to open an interactive menu. Selecting a
14
+ setting and pressing `Enter` / `Space` cycles its value; the change is saved
15
+ immediately. A setting is written to one of two scopes:
16
+
17
+ - `[project]` — saved per working directory in the central project registry, so
18
+ a given repo can carry its own value without changing your global default.
19
+ - user — saved to the shared base file (`config.env`), applying to every
20
+ directory and front-end unless a higher layer overrides it.
21
+
22
+ | Setting | Scope | Values | Env var |
23
+ |---------|-------|--------|---------|
24
+ | `/research` depth | project | normal · deep · ultra | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` |
25
+ | Knowledge Mode | project | none · project · global | `PI_RESEARCH_KNOWLEDGE_STORE_MODE` |
26
+ | Researcher Timeout | user | 3 · 5 · 10 · 15 · 20 · 30 (minutes) | `PI_RESEARCH_TIMEOUT_MS` |
27
+ | Max Concurrency | user | 1 – 5 | `PI_RESEARCH_MAX_RESEARCHERS` |
28
+ | Scrape Batches | user | unlimited · 1 · 2 · 3 · 5 · 10 · 15 | `PI_RESEARCH_MAX_SCRAPE_BATCHES` |
29
+ | Auto-export Report | user | true · false | `PI_RESEARCH_REPORT_EXPORT_ENABLED` |
30
+ | Embedding Model | user | one of the supported models | `PI_RESEARCH_EMBEDDING_MODEL` |
31
+ | Embedding Device | user | GPU · CPU | `PI_RESEARCH_EMBEDDING_DEVICE` |
32
+ | Cache Retention | user | 7 · 14 · 30 · 60 · 90 · 180 · 365 (days) | `PI_RESEARCH_CACHE_TTL_DAYS` |
33
+ | Debug Logging | user | true · false | `PI_RESEARCH_DEBUG` |
34
+
35
+ Embedding Device offers two choices in the menu. GPU maps to the
36
+ auto-detect path: pi-research probes whether WebGPU actually runs on this machine
37
+ and falls back to CPU if it does not. CPU forces CPU-only
38
+ inference. Raw forced-GPU (no probe) is reachable only through the
39
+ `PI_RESEARCH_EMBEDDING_DEVICE=webgpu` environment variable, for benchmarking — see
40
+ the [knowledge store doc](KNOWLEDGE-STORE.md).
41
+
42
+ The Embedding Model, Embedding Device, and Cache Retention rows appear
43
+ only when Knowledge Mode is not `none`.
44
+
45
+ The menu also offers actions that are not settings: Run Health Check, Store
46
+ Status, Clear Project / User Store, Session Metrics, Clear Debug Logs, and
47
+ Install / Remove in External Agents (the coding-agent
48
+ skill installer). Browser worker count is deliberately not in the menu — it is
49
+ CPU/RAM-sensitive and set only via `PI_RESEARCH_WORKER_THREADS`.
50
+
51
+ ### Environment variables
52
+
53
+ Every setting is also an environment variable. The repo's
54
+ [`.env.example`](https://github.com/Lincoln504/pi-research/blob/main/.env.example)
55
+ is the canonical, exhaustive list with inline notes; this section groups the same
56
+ variables with their defaults and valid ranges.
57
+ Out-of-range numeric values are clamped (with a warning); an invalid enum value
58
+ falls back to the default (with a warning).
59
+
60
+ The TUI-exposed variables are marked `(TUI)`. The `[project]` mark indicates a
61
+ project-scoped key (saved per directory in the registry); all others are
62
+ user-scoped.
63
+
64
+ Research
65
+
66
+ | Variable | Default | Range | Description |
67
+ |----------|---------|-------|-------------|
68
+ | `PI_RESEARCH_TIMEOUT_MS` (TUI) | `300000` | 180000–1800000 | Per-researcher timeout (3–30 min). |
69
+ | `PI_RESEARCH_MAX_RESEARCHERS` (TUI) | `3` | 1–5 | Parallel researchers. |
70
+ | `PI_RESEARCH_DEFAULT_RESEARCH_DEPTH` (TUI) `[project]` | `1` | 1–3 | Depth for `/research` and the CLI when `--depth` is omitted (1=normal, 2=deep, 3=ultra). |
71
+ | `PI_RESEARCH_MAX_SCRAPE_BATCHES` (TUI) | `2` | 0–99 | Scrape batches per researcher (0 = unlimited). |
72
+ | `PI_RESEARCH_MAX_GATHERING_CALLS` | `12` | 1–100 | Shared web-gathering calls per researcher (`search` + `security_search` + `stackexchange` + `youtube_transcript`). Local `grep` has its own separate budget. |
73
+ | `PI_RESEARCH_MAX_CONCURRENT_SCRAPES` | `3` | 1–20 | Concurrent URLs fetched per scrape batch. |
74
+ | `PI_RESEARCH_MAX_RETRIES` | `2` | 0–5 | Retries per researcher request. |
75
+ | `PI_RESEARCH_RETRY_DELAY_MS` | `2000` | 100–10000 | Base delay between retries. |
76
+ | `PI_RESEARCH_WORKER_THREADS` | `4` | 1–10 | Browser worker processes. Higher = more throughput, more CPU/RAM. |
77
+ | `PI_RESEARCH_WORKER_CONCURRENCY` | `2` | 1–10 | Tasks per worker process. |
78
+ | `PI_RESEARCH_MODEL` | _(session model)_ | — | Model override for researcher sub-agents (deep and quick) and knowledge synthesis. The coordinator and evaluator keep using the session model. Accepts `provider/id` or a bare model id. |
79
+ | `PI_RESEARCH_DISABLED_TOOLS` | _(none)_ | — | Comma-separated research tools to disable for a run (`search`, `scrape`, `security_search`, `stackexchange`, `youtube_transcript`, `grep`). Removed from every researcher's toolset and named in the coordinator/evaluator prompt. |
80
+ | `PI_RESEARCH_REPORT_EXPORT_ENABLED` (TUI) | `false` | — | Front-ends write a Markdown report to disk and surface its path. |
81
+ | `PI_RESEARCH_REPORT_EXPORT_DIR` | _(smart cwd)_ | — | Pin exported reports to a fixed directory, bypassing the cwd-relative resolution. Useful for the agent skill, which runs from the host agent's arbitrary directory. |
82
+ | `PI_RESEARCH_MAX_SCRAPE_TOKEN_FRACTION_FOR_SCRAPING` | `0.15` | 0.05–1.0 | Max fraction of the context window used for initial scrape context. |
83
+ | `PI_RESEARCH_AVG_TOKENS_PER_SCRAPE` | `2500` | 500–10000 | Estimated tokens per scrape result, used for planning. |
84
+
85
+ YouTube transcripts
86
+
87
+ | Variable | Default | Range | Description |
88
+ |----------|---------|-------|-------------|
89
+ | `PI_RESEARCH_YOUTUBE_TRANSCRIPT_MAX_VIDEOS` | `3` | 1–5 | Videos transcribed per `youtube_transcript` call. |
90
+ | `PI_RESEARCH_YOUTUBE_TRANSCRIPT_TIMEOUT_MS` | `20000` | 5000–120000 | Per-video transcript timeout. |
91
+ | `PI_RESEARCH_YOUTUBE_TRANSCRIPT_LANG` | `en` | — | Preferred caption language (BCP-47 prefix). |
92
+ | `PI_RESEARCH_YOUTUBE_QUERY_EVERY_N` | `5` | 1–100 | Append `youtube` to roughly one-in-N search queries (1 = every query). |
93
+ | `PI_RESEARCH_YOUTUBE_POTOKEN_REQUEST_KEY` | _(built-in)_ | — | Advanced: override the BotGuard PoToken web request key (only if YouTube rotates the public key and transcripts start failing). |
94
+
95
+ Timeouts
96
+
97
+ | Variable | Default | Range | Description |
98
+ |----------|---------|-------|-------------|
99
+ | `PI_RESEARCH_LLM_TIMEOUT_MS` | `300000` | 60000–600000 | Coordinator / evaluator / repair / knowledge LLM call timeout. |
100
+ | `PI_RESEARCH_SCRAPE_TIMEOUT_MS` | `15000` | 5000–120000 | Per-page scrape (page-load) timeout. |
101
+ | `PI_RESEARCH_SEARCH_TIMEOUT_MS` | `45000` | 5000–120000 | Browser search page timeout. |
102
+ | `PI_RESEARCH_BROWSER_TASK_TIMEOUT_MS` | `10000` | 2000–120000 | Queue-wait / overhead margin added to each browser op's own timeout (a search task ceiling is `SEARCH_TIMEOUT_MS` + this; a scrape is `SCRAPE_TIMEOUT_MS` + this). |
103
+ | `PI_RESEARCH_HEALTH_CHECK_TIMEOUT_MS` | `10000` | 2000–120000 | Pre-flight health-check timeout. |
104
+
105
+ LLM output & reasoning
106
+
107
+ These are advanced, env-only knobs (not in the TUI).
108
+
109
+ | Variable | Default | Range | Description |
110
+ |----------|---------|-------|-------------|
111
+ | `PI_RESEARCH_LLM_THINKING_LEVEL` | `off` | off · minimal · low · medium · high | Chain-of-thought level for all engine LLM work (coordinator, evaluator, synthesis, JSON-repair, knowledge extraction, and researcher sub-agents). Off by default — these calls emit structured JSON / cited reports, so a thinking block only consumes the output budget and can truncate the answer. Clamped per model by pi. |
112
+ | `PI_RESEARCH_PLANNING_MAX_TOKENS` | `16384` | 1024–131072 | Max output tokens for the plan + mid-round evaluator decision. Clamped to the model's real ceiling. |
113
+ | `PI_RESEARCH_SYNTHESIS_MAX_TOKENS` | `32768` | 1024–131072 | Max output tokens for the final synthesized report. Clamped to the model's real ceiling. |
114
+
115
+ Knowledge store
116
+
117
+ See the [knowledge store doc](KNOWLEDGE-STORE.md) for what each value does.
118
+
119
+ | Variable | Default | Range | Description |
120
+ |----------|---------|-------|-------------|
121
+ | `PI_RESEARCH_KNOWLEDGE_STORE_MODE` (TUI) `[project]` | `global` | none · project · global | Store scope: one shared store across every directory (`global`), scoped to the current directory (`project`), or disabled (`none`). |
122
+ | `PI_RESEARCH_EMBEDDING_MODEL` (TUI) | `onnx-community/granite-embedding-small-english-r2-ONNX` | — | Embedding model. Changing it clears the store and starts fresh. |
123
+ | `PI_RESEARCH_EMBEDDING_DEVICE` (TUI) | `auto` | auto · webgpu · cpu | Inference backend. `auto` probes WebGPU viability out-of-process and falls back to CPU; `cpu` forces CPU; `webgpu` forces the GPU path with no probe (advanced — can hard-crash on a software GPU). The TUI exposes only `auto` (as "GPU") and `cpu`. |
124
+ | `PI_RESEARCH_CACHE_TTL_DAYS` (TUI) | `30` | 1–365 | How long cached findings are kept before eviction. |
125
+ | `PI_RESEARCH_KNOWLEDGE_STORE_MAX_SERVE_AGE_DAYS` | `0` | 0–3650 | Max age a cached scrape may be *served* at read time before it's treated as a miss and re-scraped fresh. `0` = disabled (serve at any age up to the TTL). Cache age is always surfaced to the model regardless. |
126
+ | `PI_RESEARCH_MIGRATION_STRATEGY` | `backup` | drop · backup · re-embed | What to do with stored data when the embedding model changes. |
127
+ | `PI_RESEARCH_KNOWLEDGE_DIR` | _(auto)_ | — | Override the knowledge-store database directory. Default: `~/.pi/research/knowledge_db`. |
128
+ | `PI_RESEARCH_EMBEDDING_MODEL_INIT_TIMEOUT_MS` | `300000` | 10000–600000 | Embedding-model initialization timeout (first-time download can be slow). |
129
+ | `PI_RESEARCH_WEBGPU_REPROBE` | _(unset)_ | — | Set `1` to discard the cached WebGPU-viability verdict and probe again on next use. |
130
+
131
+ API keys (all optional)
132
+
133
+ | Variable | Description |
134
+ |----------|-------------|
135
+ | `PI_RESEARCH_API_KEY` / `PI_RESEARCH_PROVIDER` | Explicit LLM credentials for SDK / CLI mode (not needed when using pi's own auth). Provider is required alongside the key. |
136
+ | `STACKEXCHANGE_API_KEY` | Raises the Stack Exchange tool's limit from 300/day to 10,000/day. Obtain at <https://stackapps.com/apps/oauth>. |
137
+ | `GITHUB_TOKEN` | Raises the security tool's GitHub Advisory limit from 60/hr to 5000/hr (any default-scope token). |
138
+ | `NVD_API_KEY` | Raises the security tool's NVD limit ~10× and tightens request spacing. Request at <https://nvd.nist.gov/developers/request-an-api-key>. Recommended when using severity-filtered security searches: those issue a second (CVSS v2) NVD query to catch v2-only CVEs, which roughly doubles request time against the 6 s/request unauthenticated throttle. |
139
+
140
+ Diagnostics & platform
141
+
142
+ | Variable | Default | Description |
143
+ |----------|---------|-------------|
144
+ | `PI_RESEARCH_DEBUG` (TUI) | `false` | Verbose INFO+DEBUG logging to the log file. |
145
+ | `PI_RESEARCH_CONSOLE_LOG` | `false` | Mirror logs to stdout/stderr (useful in CI / headless). |
146
+ | `PI_RESEARCH_LOG_PATH` | _(OS temp)_ | Override the verbose log file path. Browser workers inherit it automatically. |
147
+ | `PI_RESEARCH_LOG_FILE` | _(unset)_ | Send browser worker-thread logs to a separate file. If unset, workers log to `PI_RESEARCH_LOG_PATH`. |
148
+ | `PI_RESEARCH_TMP_DIR` | `~/.cache/pi-research/profiles` | Transient per-worker browser-profile directory. Disk-backed by default (kept off a RAM-backed `/tmp` so per-worker profiles don't add memory pressure). Point under the system temp dir to opt into tmpfs/RAM. |
149
+ | `PI_RESEARCH_STATE_DIR` | `~/.pi/research/state` | Override the state directory (active sessions, browser status, project registry). |
150
+ | `PI_RESEARCH_TUI_REFRESH_DEBOUNCE_MS` | `100` | TUI refresh debounce (0–1000 ms). |
151
+ | `PI_RESEARCH_SKIP_HEALTHCHECK` | _(unset)_ | Set `1`/`true` to skip the pre-flight browser/embedding health check and rely on per-task timeouts. |
152
+ | `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`). |
153
+ | `PI_RESEARCH_SKILL_DIR` | _(auto)_ | Override the bundled research-skill source directory used by the skill installer. |
154
+ | `PI_RESEARCH_PURGE_BROWSERS` | _(unset)_ | Set `1` during `npm uninstall` to also delete the shared camoufox browser cache (kept by default because other installs may use it). |
155
+ | `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` | _(unset)_ | Set `1` during `npm install` to skip the camoufox browser download (fetched lazily on first use instead; standard Playwright convention). |
156
+ | `PLAYWRIGHT_INSTALL_DEPS` | _(unset)_ | Linux only. Set `true` during `npm install` to also install system libraries via `npx playwright install-deps` (same as `npm run install:system-deps`). |
157
+ | `PI_RESEARCH_CONFIG_DIR_NAME` | `.pi` | Override the host config-directory name under your home dir (advanced; e.g. set to share another harness's config root). |
158
+
159
+ Testing only — never enable in production
160
+
161
+ | Variable | Description |
162
+ |----------|-------------|
163
+ | `PI_RESEARCH_MOCK_SEARCH` | Return fabricated search results instead of real web data. |
164
+ | `PI_RESEARCH_MOCK_SCRAPE` | Return fabricated scrape results instead of real page content. |
165
+ | `PI_RESEARCH_FORCE_READY` | Bypass readiness checks and run even when critical services failed to initialize. |
166
+ | `PI_RESEARCH_ALLOW_LOOPBACK_SCRAPE` | Permit scraping loopback/private/internal addresses, bypassing SSRF protection. |
167
+
168
+ ### How configuration is layered
169
+
170
+ Configuration resolves from the following layers, lowest to highest precedence
171
+ (later wins):
172
+
173
+ ```
174
+ built-in defaults
175
+ < ~/.pi/research/config.env (base, shared; edited by /research-config)
176
+ < ~/.pi/research/{pi,cli}.env (optional per-front-end overlay)
177
+ < legacy .pi-research.env in the cwd (deprecated; auto-migrated to the registry)
178
+ < project registry (~/.pi/research/state/project-settings.json, per directory)
179
+ < process.env (real shell env always wins)
180
+ ```
181
+
182
+ Base file. `config.env` holds your shared, user-scoped settings. The
183
+ `/research-config` TUI edits only this file (and the project registry) — never the
184
+ overlays or the merged view — so overlay values are never baked back into the base.
185
+
186
+ Per-front-end overlays. Each front-end reads only its own optional overlay,
187
+ layered over the shared base, so they can be configured independently. Exactly two
188
+ exist:
189
+
190
+ - `~/.pi/research/pi.env` — the pi extension
191
+ - `~/.pi/research/cli.env` — the standalone CLI / agent skill (the surface OpenClaw
192
+ and other skills-aware hosts run)
193
+
194
+ The overlay files do not exist by default; create the one you need by hand. There is
195
+ intentionally no `sdk.env`: the SDK is a library configured from code (see
196
+ [SDK.md](SDK.md)), not from a global file.
197
+
198
+ Example — give the standalone CLI / agent skill its own model and depth without
199
+ touching the pi extension:
200
+
201
+ ```sh
202
+ # ~/.pi/research/config.env (shared baseline)
203
+ PI_RESEARCH_KNOWLEDGE_STORE_MODE=project
204
+
205
+ # ~/.pi/research/cli.env (standalone CLI / agent skill only)
206
+ PI_RESEARCH_MODEL=openrouter/anthropic/claude-sonnet-4-6
207
+ PI_RESEARCH_DEFAULT_RESEARCH_DEPTH=2
208
+ ```
209
+
210
+ Project registry. Project-scoped settings (research depth and knowledge-store
211
+ mode) are stored per directory in `project-settings.json`, keyed by normalized
212
+ working-directory path. They override the base and overlays for that directory only.
213
+ In the pi extension the `/research-config` TUI writes them. On the standalone CLI you can
214
+ set the knowledge-store mode per directory directly:
215
+
216
+ ```sh
217
+ pi-research knowledge-config # show the mode here and where it comes from
218
+ pi-research knowledge-config set none|project|global
219
+ ```
220
+
221
+ Under the agent skill you don't have to run this yourself — you ask the agent (e.g. "disable the
222
+ knowledge store here" / "make it project-scoped") and it runs the same command on your
223
+ behalf. Either way it lands in the registry (above `config.env` in precedence), so a
224
+ per-directory value overrides a machine-wide `config.env` default; a real environment
225
+ variable still outranks both.
226
+
227
+ process.env. A real environment variable always wins. For a one-off override,
228
+ just export the variable for that process.
229
+
230
+ > The base file is not loaded automatically by your shell. Either use the
231
+ > `/research-config` TUI (which writes it), export variables in your shell, or use a
232
+ > loader such as direnv. `.env.example` is a reference, not an active config file.
233
+
234
+ ### Where files live
235
+
236
+ All pi-research state lives under its own namespace, `~/.pi/research/`:
237
+
238
+ | Path | Contents |
239
+ |------|----------|
240
+ | `~/.pi/research/config.env` | Shared base configuration (user-scoped settings). |
241
+ | `~/.pi/research/{pi,cli}.env` | Optional per-front-end overlays. |
242
+ | `~/.pi/research/state/project-settings.json` | Project registry (per-directory settings). |
243
+ | `~/.pi/research/state/` | Active sessions, browser status, locks. |
244
+ | `~/.pi/research/knowledge_db/` | The knowledge store (LanceDB), unless `PI_RESEARCH_KNOWLEDGE_DIR` is set. |
245
+ | `~/.cache/pi-research/profiles/` | Transient browser profiles, unless `PI_RESEARCH_TMP_DIR` is set. |
246
+ | `~/.cache/pi-research/webgpu-viability.json` | Cached WebGPU-viability verdict (see the knowledge store doc). |
247
+
248
+ Paths can be relocated with `PI_RESEARCH_STATE_DIR`, `PI_RESEARCH_KNOWLEDGE_DIR`,
249
+ and `PI_RESEARCH_TMP_DIR`.
@@ -0,0 +1,213 @@
1
+ ## Knowledge Store
2
+
3
+ The knowledge store is a local vector database of past research findings. It is used
4
+ in two distinct ways, and it is an optional cache — research works without it:
5
+
6
+ - **Knowledge-first answering (advisory).** The `research_knowledge_search` tool
7
+ answers a repeat or overlapping question directly from stored results. The agent is
8
+ asked to try it *before* the live `research` tool, but this is guidance the model
9
+ follows — it is not enforced, and `research_knowledge_search` is a separate tool, not
10
+ a gate in front of `research`.
11
+ - **Seeding a live run (automatic).** A live `research` run never answers from the
12
+ store; instead the orchestrator hands each researcher the previously useful URLs for
13
+ its goal as starting points to re-scrape live.
14
+
15
+ ![Knowledge-store hit — a cached answer returned without a live run](media/03-knowledge-store.gif)
16
+
17
+ Together these make repeat work faster and cheaper.
18
+
19
+ ### What it stores
20
+
21
+ The store is a [LanceDB](https://lancedb.com) table on disk. After each research
22
+ round, the cited URLs from the researchers' reports are enqueued and written in the
23
+ background: each source's summary (and, when available, its full scraped Markdown) is
24
+ split into chunks, each chunk is embedded into a vector, and the rows are stored.
25
+
26
+ Each row carries the embedding vector, the source URL (normalized for
27
+ deduplication), the summary text and full content, a timestamp, and scope flags. A
28
+ content hash dedupes re-ingested URLs: an unchanged page is skipped; a changed page
29
+ replaces the old rows. The full page Markdown is cached once per document so a stored
30
+ finding can be rehydrated later without re-scraping.
31
+
32
+ Writes never block a research run — they go through an asynchronous writer queue that
33
+ is drained at the end of the round and on shutdown.
34
+
35
+ ### Scopes: none, project, global
36
+
37
+ The store's reach is set by Knowledge Mode (`PI_RESEARCH_KNOWLEDGE_STORE_MODE`),
38
+ a project-scoped setting you can change per directory:
39
+
40
+ | Mode | Behavior |
41
+ |------|----------|
42
+ | `global` (default) | One store shared across every directory. A finding cached in one project is retrievable from any other. |
43
+ | `project` | Findings are scoped to the working directory they were created in; only that directory retrieves them. |
44
+ | `none` | The store is disabled — no data is read or written. The `research_knowledge_search` tool stays registered (so re-enabling the mode later needs no pi restart) but is not advertised to the agent: its prompt guidance is stripped, and any direct call returns a "knowledge store is disabled" result. The `/knowledge-store` command is unavailable. |
45
+
46
+ Change the mode for the current directory with the `/research-config` TUI (Knowledge Mode)
47
+ in the pi extension, or with `pi-research knowledge-config set none|project|global` on the
48
+ standalone CLI (`pi-research knowledge-config` shows the current mode and its source). Under
49
+ the agent skill you don't have to run anything — you ask the agent to change it and it runs that
50
+ command for you. All persist to the per-directory project registry; a per-directory value
51
+ overrides a machine-wide `PI_RESEARCH_KNOWLEDGE_STORE_MODE` in `config.env`, and a real
52
+ environment variable overrides everything. The change applies on the next run — no restart.
53
+
54
+ All scopes share one physical LanceDB directory; project vs. global rows are
55
+ distinguished by columns (a normalized workspace path and a global flag) and filtered
56
+ at query time, not by separate folders. The default database directory is
57
+ `~/.pi/research/knowledge_db/` (override with `PI_RESEARCH_KNOWLEDGE_DIR`).
58
+
59
+ The embedding model is lazy — it only downloads and initializes the first time
60
+ the store is actually written or searched, so the `global` default adds no startup
61
+ cost until a run caches its first page.
62
+
63
+ ### How a run uses the store
64
+
65
+ The store is driven by the orchestrator, not called ad hoc by researcher agents,
66
+ which keeps its use deterministic:
67
+
68
+ 1. Before each researcher starts, the orchestrator searches the store for the
69
+ researcher's goal and injects any matching historical URLs — each with its prior
70
+ summary — into that researcher's prompt as suggested starting points to re-scrape.
71
+ 2. After the round, the cited URLs and their descriptions are enqueued into the
72
+ writer queue for the next session.
73
+
74
+ Separately, the `research_knowledge_search` tool (and the SDK's `searchKnowledge()`)
75
+ lets the model query the store directly: it rehydrates the most relevant stored
76
+ documents, asks a background LLM whether they answer the question, and returns a
77
+ synthesized answer with citations — or reports that live research is needed.
78
+
79
+ ### Embeddings and the model
80
+
81
+ Embeddings are computed locally with
82
+ [`@huggingface/transformers`](https://github.com/huggingface/transformers.js) over
83
+ ONNX. The default model is
84
+ `onnx-community/granite-embedding-small-english-r2-ONNX` (English; a 512-token
85
+ chunk window). Each supported model defines its own chunk size, pooling strategy,
86
+ and prefixes, and produces a fixed vector dimension that the table's schema is built
87
+ around.
88
+
89
+ Supported models (`PI_RESEARCH_EMBEDDING_MODEL`):
90
+
91
+ | Model | Languages |
92
+ |-------|-----------|
93
+ | `onnx-community/granite-embedding-small-english-r2-ONNX` (default) | English |
94
+ | `Xenova/multilingual-e5-small` | Multilingual |
95
+ | `Xenova/multilingual-e5-base` | Multilingual |
96
+ | `Xenova/bge-m3` | Multilingual |
97
+ | `onnx-community/embeddinggemma-300m-ONNX` | Multilingual |
98
+ | `onnx-community/Qwen3-Embedding-0.6B-ONNX` | Multilingual |
99
+ | `Xenova/all-MiniLM-L6-v2` | English |
100
+ | `Xenova/bge-small-en-v1.5` | English |
101
+ | `Xenova/all-mpnet-base-v2` | English |
102
+
103
+ Changing the model invalidates existing vectors (they have a different dimension and
104
+ meaning), so the store is migrated (see Changing the model, below).
105
+ The model is downloaded from Hugging Face on first use and cached; the first download
106
+ can take a few minutes (raise `PI_RESEARCH_EMBEDDING_MODEL_INIT_TIMEOUT_MS` on a slow
107
+ connection).
108
+
109
+ ### Device selection
110
+
111
+ Embeddings run on either the GPU (WebGPU, via the runtime's bundled Dawn backend) or
112
+ the CPU. The backend is chosen by `PI_RESEARCH_EMBEDDING_DEVICE`:
113
+
114
+ - `auto` (default; shown as GPU in the TUI) — pi-research probes WebGPU
115
+ viability in a disposable child process: it loads the model and runs one real
116
+ embedding there. If that succeeds, the GPU is used; if it fails, the CPU is used.
117
+ The verdict is cached, so the probe runs at most once per machine + model.
118
+ - `cpu` (shown as CPU in the TUI) — forces CPU inference, no probe.
119
+ - `webgpu` — forces the GPU path with no probe. Advanced / env-only; see below.
120
+
121
+ Why the probe exists. Some hosts — VMs, containers, CI runners, headless machines
122
+ with a software Vulkan driver — expose a GPU the native backend cannot run compute
123
+ on. That failure is a native segfault, not a catchable error, so it terminates the
124
+ process. The `auto` probe tests viability in a child process (whose crash cannot
125
+ affect the main process) and falls back to CPU. Forcing `webgpu` skips this check and
126
+ can crash on such a host, so the `/research-config` menu offers only GPU (= `auto`)
127
+ and CPU. Raw `webgpu` stays available through the environment variable for
128
+ benchmarking on a host with a known-good GPU.
129
+
130
+ The cached verdict lives at `~/.cache/pi-research/webgpu-viability.json`, keyed by
131
+ platform, architecture, Node major version, and model. Set
132
+ `PI_RESEARCH_WEBGPU_REPROBE=1` to discard it and probe again (for example after a
133
+ driver upgrade).
134
+
135
+ ### Platform support (no Intel Mac)
136
+
137
+ The store depends on two native components — the ONNX runtime for embeddings and
138
+ LanceDB for vector storage — that ship prebuilt binaries only for certain
139
+ platform/architecture pairs:
140
+
141
+ | Platform | Architecture | Knowledge store |
142
+ |----------|--------------|-----------------|
143
+ | macOS | Apple Silicon (arm64) | Supported |
144
+ | macOS | Intel (x64) | Not available |
145
+ | Linux | x64 / arm64 | Supported |
146
+ | Windows | x64 / arm64 | Supported |
147
+
148
+ Intel Macs (`darwin-x64`) have no prebuilt binary for either component, so the
149
+ knowledge store cannot run there. The degradation is automatic:
150
+
151
+ - Research still works. Search, scraping, YouTube transcripts, the security databases,
152
+ Stack Exchange, planning, and synthesis are unaffected — only the store is missing.
153
+ - The health check reports the store as disabled, not unhealthy: its health component
154
+ returns disabled (native embedding/vector stack unavailable on this platform) with a
155
+ healthy status, so the missing component does not drag overall health to "unhealthy"
156
+ or block a quick (depth-0) run.
157
+ - `research_knowledge_search` does no caching or retrieval; every run goes to the live web.
158
+
159
+ No configuration is needed on an Intel Mac.
160
+
161
+ ### Retention and eviction
162
+
163
+ Cached findings are kept for `PI_RESEARCH_CACHE_TTL_DAYS` (default 30; range 1–365).
164
+ Eviction is checked when the store opens and removes only rows older than the cutoff
165
+ within the current scope. Lower the value for fresher data and less disk; raise it to
166
+ keep history longer.
167
+
168
+ ### Changing the model: migration
169
+
170
+ When the configured embedding model differs from the one the stored vectors were
171
+ built with, the store is migrated according to `PI_RESEARCH_MIGRATION_STRATEGY`:
172
+
173
+ | Strategy | What happens |
174
+ |----------|--------------|
175
+ | `backup` (default) | The old table is renamed aside (`knowledge_backup_<timestamp>.lance`) and a fresh table is created for the new model. Old data is preserved on disk but not searched. |
176
+ | `drop` | The old table is discarded and a fresh one created. Fast; no backup. |
177
+ | `re-embed` | Every stored document is re-embedded with the new model into a new table, preserving history. Slowest. |
178
+
179
+ If the chosen strategy fails, pi-research falls back to `backup`, then to `drop`,
180
+ rather than leaving the store in a broken state. Changing the model from the
181
+ `/research-config` menu always clears the current store and starts fresh.
182
+
183
+ ### Managing the store
184
+
185
+ From `/research-config`:
186
+
187
+ - Store Status — entry counts (project and user), the active embedding model
188
+ and device, and the on-disk path.
189
+ - Clear Project Store / Clear User Store — permanently delete the
190
+ project-scoped or global rows (shown according to the current mode).
191
+ - Run Health Check — exercises the browser pool, GPU/embedding, and knowledge
192
+ store connectivity, and reports the store's health state.
193
+
194
+ The store grows copy-on-write (each run appends a version), so it is compacted
195
+ automatically after any run that changed the stored data — stale versions and
196
+ indices are pruned to keep it bounded. There is no manual maintenance command.
197
+
198
+ ### Settings
199
+
200
+ | Setting | Variable | Default |
201
+ |---------|----------|---------|
202
+ | Knowledge Mode (project-scoped) | `PI_RESEARCH_KNOWLEDGE_STORE_MODE` | `global` |
203
+ | Embedding model | `PI_RESEARCH_EMBEDDING_MODEL` | `onnx-community/granite-embedding-small-english-r2-ONNX` |
204
+ | Embedding device | `PI_RESEARCH_EMBEDDING_DEVICE` | `auto` |
205
+ | Cache retention (days) | `PI_RESEARCH_CACHE_TTL_DAYS` | `30` |
206
+ | Migration strategy | `PI_RESEARCH_MIGRATION_STRATEGY` | `backup` |
207
+ | Database directory | `PI_RESEARCH_KNOWLEDGE_DIR` | `~/.pi/research/knowledge_db` |
208
+ | Model init timeout (ms) | `PI_RESEARCH_EMBEDDING_MODEL_INIT_TIMEOUT_MS` | `300000` |
209
+ | Re-probe WebGPU | `PI_RESEARCH_WEBGPU_REPROBE` | _(unset)_ |
210
+
211
+ See [CONFIGURATION.md](CONFIGURATION.md) for the full configuration model, and
212
+ [ARCHITECTURE.md](ARCHITECTURE.md) for how the store fits into the
213
+ engine.
@@ -0,0 +1,91 @@
1
+ ## Pi Extension
2
+
3
+ pi-research integrates as a [pi](https://github.com/earendil-works/pi)
4
+ extension (`src/index.ts`) — a multi-agent web research engine with a real-time
5
+ TUI, registered directly in the pi process.
6
+
7
+ ### Usage
8
+
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.
11
+
12
+ ```bash
13
+ pi -p "research the latest developments in WebAssembly"
14
+ pi -p "do a thorough deep-dive on the AI inference hardware landscape"
15
+ ```
16
+
17
+ Three slash commands are also registered:
18
+
19
+ | Command | Description |
20
+ |---------|-------------|
21
+ | `/research <query>` | Invokes the `research` tool directly at the configured default depth (`PI_RESEARCH_DEFAULT_RESEARCH_DEPTH`, 1 by default) — a plain live run with no LLM turn. It does not parse an inline depth and does **not** consult the knowledge store; use `/knowledge-store <query>` for a store-only lookup. |
22
+ | `/research-config` | Opens the interactive TUI settings dashboard. |
23
+ | `/knowledge-store <query>` | Searches the local knowledge store for a query and returns a synthesised answer from previously researched findings. Unavailable when Knowledge Mode is `none`. The store auto-manages its own compaction, so there is no maintenance subcommand. |
24
+
25
+ ![Running a live investigation with the /research slash command](media/01-slash-research.gif)
26
+
27
+ ### Tools
28
+
29
+ The extension registers three tools:
30
+
31
+ | Tool | Registered |
32
+ |------|-----------|
33
+ | `research` | always |
34
+ | `health` | always |
35
+ | `research_knowledge_search` | always (see note) |
36
+
37
+ `research_knowledge_search` is registered unconditionally so a Knowledge Mode
38
+ change takes effect without restarting pi (pi has no unregister API). When
39
+ `PI_RESEARCH_KNOWLEDGE_STORE_MODE` is `none` the tool is not advertised to the
40
+ agent — its prompt guidance is stripped, and any call returns a "store disabled"
41
+ result; the `/knowledge-store` command is likewise unavailable. Advertisement and
42
+ the store's read/write paths are gated on the live mode, not on this registration.
43
+
44
+ Tool exclusion — the `research` tool honors an `excludeTools` list taken from
45
+ the pi session context when the host forwards one.
46
+
47
+ ### TUI
48
+
49
+ During a run pi-research renders a live progress panel:
50
+
51
+ - Researcher slices — one per agent: status, URLs scraped, actions taken.
52
+ - Wave animation — active-crawl indicator.
53
+ - Token usage — model tokens + estimated cost (non-decreasing guard).
54
+ - Status flashes — green on success, red on failure.
55
+ - Steering messages — queued and active mid-run user guidance.
56
+
57
+ | Key | Action |
58
+ |-----|--------|
59
+ | `Escape` | Cancel active research |
60
+ | Arrow keys | Navigate the `/research-config` menu |
61
+ | `Enter` / `Space` | Cycle a setting's value |
62
+
63
+ ### Configuration
64
+
65
+ Manage settings through `/research-config`, which edits two layers:
66
+
67
+ - Global — base `~/.pi/research/config.env` (applies to all front-ends).
68
+ - Project — the centralized registry (`~/.pi/research/state/project-settings.json`),
69
+ scoped per working directory. Only depth and knowledge-store mode are
70
+ project-scoped, so a given repo can carry its own research depth without
71
+ changing your global default.
72
+
73
+ To configure the pi extension independently of the other front-ends, add an
74
+ optional overlay at `~/.pi/research/pi.env` (it layers over `config.env` for the
75
+ pi extension only). The full configuration model, precedence, and the complete
76
+ environment-variable list live in [CONFIGURATION.md](CONFIGURATION.md).
77
+
78
+ ### Coding-agent skill installer
79
+
80
+ The `/research-config` menu can install the `pi-research` skill into your other
81
+ coding agents (Claude, Codex, OpenClaw) so they can run web research through the
82
+ CLI, and remove it again — with exact, manifest-tracked cleanup. See
83
+ [AGENT-SKILL.md](AGENT-SKILL.md) for the full installation flow.
84
+
85
+ ### Lifecycle
86
+
87
+ - `activate` — registers commands, tools, the TUI controller, and initializes services.
88
+ - `deactivate` — drains the writer queue, closes LanceDB, terminates the browser pool, disposes the embedding model.
89
+ - `session_shutdown` — branches on `event.reason`: a `quit` triggers process-exit cleanup; reload / new / resume / fork clean up without exiting.
90
+
91
+ Extension state is isolated per pi session, so `/reload` is safe.