@juicesharp/rpiv-web-tools 2.0.0 → 2.1.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.
package/README.md CHANGED
@@ -1,293 +1,140 @@
1
- # rpiv-web-tools
1
+ # @juicesharp/rpiv-web-tools
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@juicesharp/rpiv-web-tools.svg)](https://www.npmjs.com/package/@juicesharp/rpiv-web-tools)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2
5
 
3
6
  <div align="center">
4
7
  <a href="https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-web-tools">
5
8
  <picture>
6
- <img src="https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-web-tools/docs/cover.png" alt="rpiv-web-tools cover" width="50%">
9
+ <img src="https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-web-tools/docs/cover.png" alt="rpiv-web-tools — search the web, read the page" width="50%">
7
10
  </picture>
8
11
  </a>
9
12
  </div>
10
13
 
11
- Let the model search the web and read pages. `rpiv-web-tools` adds `web_search` and `web_fetch` tools to [Pi Agent](https://github.com/badlogic/pi-mono) with pluggable providers (Brave, Tavily, Serper, Exa, You.com, Jina, Firecrawl, Perplexity, [SearXNG](https://docs.searxng.org/), [Ollama](https://ollama.com)), plus `/web-tools` for interactive provider selection and API-key setup.
12
-
13
- ![Provider selection prompt](https://raw.githubusercontent.com/juicesharp/rpiv-mono/main/packages/rpiv-web-tools/docs/config.jpg)
14
-
15
- ## Providers
16
-
17
- Pick one as the active backend; switch any time without losing the others' keys.
18
-
19
- | Provider | Env var | Signup | Fetch mode |
20
- |---|---|---|---|
21
- | Brave | `BRAVE_SEARCH_API_KEY` | [brave.com/search/api](https://brave.com/search/api/) | raw HTTP → htmlToText, `raw: true` available |
22
- | Tavily | `TAVILY_API_KEY` | [tavily.com](https://tavily.com) | native extraction (plain text) |
23
- | Serper | `SERPER_API_KEY` | [serper.dev](https://serper.dev) | raw HTTP → htmlToText, `raw: true` available |
24
- | Exa | `EXA_API_KEY` | [exa.ai](https://exa.ai) | native extraction (plain text) |
25
- | You.com | `YOUCOM_API_KEY` | [you.com](https://you.com) | native extraction (markdown) |
26
- | Jina | `JINA_API_KEY` | [jina.ai/reader](https://jina.ai/reader) | native extraction (markdown) |
27
- | Firecrawl | `FIRECRAWL_API_KEY` | [firecrawl.dev](https://firecrawl.dev) | native extraction (markdown) |
28
- | Perplexity | `PERPLEXITY_API_KEY` | [docs.perplexity.ai](https://docs.perplexity.ai/) | raw HTTP → htmlToText, `raw: true` available |
29
- | SearXNG | `SEARXNG_URL` (+ optional `SEARXNG_API_KEY`) | self-hosted | raw HTTP → htmlToText, `raw: true` available |
30
- | Ollama | `OLLAMA_HOST` / `OLLAMA_API_KEY` | local or [ollama.com](https://ollama.com) | native extraction |
31
-
32
- ## Features
33
-
34
- - **Read any URL** - fetch http/https pages with HTML-to-text extraction, or get the raw response with `raw: true` (honoured by Brave/Serper/Perplexity/SearXNG; extraction providers — Tavily/Exa/You.com/Jina/Firecrawl/Ollama — always return their parsed text).
35
- - **GitHub URL interceptor (opt-in)** - github.com URLs route through `gh`/`git` for full repository content (file tree, README, individual file contents) instead of the rendered HTML page. Off by default; enable per-user via config or per-consumer at registration time. See [§GitHub URL interceptor](#github-url-interceptor).
36
- - **Large-page spillover** - oversized responses truncate inline and spill the full body to a temp file the model can read on demand.
37
- - **SSRF guard** - refuses loopback, RFC 1918, link-local, and cloud-metadata addresses (`localhost`, `127.0.0.0/8`, `10.0.0.0/8`, `169.254.0.0/16`, `172.16.0.0/12`, `192.168.0.0/16`, `::1`, `fc00::/7`, `fe80::/10`).
38
- - **Interactive setup** - `/web-tools` lists providers (active one first, configured ones marked) and writes to `~/.config/rpiv-web-tools/config.json` (chmod 0600); per-provider env vars also work and take precedence over persisted keys.
14
+ Let the model answer from the live web instead of its training data.
15
+ `rpiv-web-tools` adds two tools to [Pi Agent](https://github.com/badlogic/pi-mono):
16
+ `web_search`, which queries a search API and returns titled results with URLs and
17
+ snippets, and `web_fetch`, which reads an http/https page as text. You pick one
18
+ of ten backends with `/web-tools`, or run SearXNG or Ollama yourself so your
19
+ queries never leave your network.
39
20
 
40
21
  ## Install
41
22
 
42
- ```bash
23
+ ```sh
43
24
  pi install npm:@juicesharp/rpiv-web-tools
44
25
  ```
45
26
 
46
- Then restart your Pi session.
47
-
48
- ## Tools
49
-
50
- - **`web_search`** - query a search provider's API and return titled snippets. Defaults to the active provider set via `/web-tools`; pass `provider` to target a different backend on a single call without switching the persisted default. 1–10 results per call.
51
- - **`web_fetch`** - read an http/https URL. Lookup order: opt-in URL interceptors
52
- (see [§GitHub URL interceptor](#github-url-interceptor)), then the active provider's native
53
- fetch endpoint when it has one (Tavily/Exa/You.com/Jina/Firecrawl/Ollama → vendor extraction;
54
- Brave/Serper/Perplexity/SearXNG → shared raw HTTP + HTML-to-text fallback). Large responses truncate
55
- inline and spill the full body to a temp file the model can read on demand.
56
-
57
- ### Schema - `web_search`
58
-
59
- ```ts
60
- web_search({
61
- query: string, // natural-language query
62
- max_results?: number, // 1-10, default 5
63
- provider?: // per-call provider override; see below
64
- | "brave" | "tavily" | "serper" | "exa" | "youcom" | "jina"
65
- | "firecrawl" | "perplexity" | "searxng" | "ollama",
66
- })
67
- ```
68
-
69
- Returns:
70
-
71
- ```ts
72
- {
73
- content: [{ type: "text", text: string }], // markdown list of "**title**\n url\n snippet"
74
- details: {
75
- query: string,
76
- backend: "brave" | "tavily" | "serper" | "exa" | "youcom" | "jina" | "firecrawl" | "perplexity" | "searxng" | "ollama",
77
- resultCount: number,
78
- results?: Array<{ title: string, url: string, snippet: string }>,
79
- }
80
- }
81
- ```
82
-
83
- Throws when the resolved provider's API key is unset (e.g. `EXA_API_KEY is not set`), the provider's API returns a non-2xx response, or an explicit `provider` names a provider with no configured credentials (no silent fallback — the caller can detect the misconfiguration).
84
-
85
- #### Per-call `provider` override
86
-
87
- The optional `provider` parameter routes a single call to a different backend than the active provider set via `/web-tools`, without mutating persisted config or restarting the session. Resolution:
88
-
89
- 1. `params.provider` (if present) — must be one of the literal provider names listed above. Unknown names throw `Unknown web_search provider: "<name>"`.
90
- 2. `config.provider` (the active provider selected via `/web-tools`).
91
- 3. `brave` (default when `config.provider` is absent).
92
-
93
- The named provider must have its own API key / base URL configured (via env var or `/web-tools`); the override does not inherit credentials from the active provider. A request for an unconfigured provider throws the provider's usual `… is not set` error rather than silently falling back, so agents can detect and react. Use this for provider comparison, falling back to a second backend when the active one returns poor results, or any multi-provider workflow that previously required a config switch and session restart.
94
-
95
- ### Schema - `web_fetch`
96
-
97
- ```ts
98
- web_fetch({
99
- url: string, // http or https only
100
- raw?: boolean, // true → return raw HTML; default false → strip to text
101
- })
102
- ```
103
-
104
- Returns:
105
-
106
- ```ts
107
- {
108
- content: [{ type: "text", text: string }], // header (URL/title/content-type) + body
109
- details: {
110
- url: string,
111
- title?: string, // <title> element, if present (HTML, non-raw)
112
- contentType?: string,
113
- contentLength?: number, // from Content-Length header
114
- truncation?: TruncationResult, // present when body exceeded inline limits
115
- fullOutputPath?: string, // temp-file path containing the un-truncated body
116
- }
117
- }
118
- ```
119
-
120
- Throws on invalid URL, non-http(s) protocol, private/loopback hostnames (SSRF guard), non-2xx response, or `image/` / `video/` / `audio/` content types. Extraction providers (Tavily/Exa/You.com/Jina/Firecrawl) additionally throw when the API returns an empty body or a vendor-level failure (e.g. Firecrawl `success: false`, Tavily `failed_results`).
121
-
122
- ## Commands
123
-
124
- - **`/web-tools`** - pick the active provider and set its API key interactively.
125
- Providers already configured show `(configured)`; the active one is listed first with a `✓`.
126
- Pressing Enter on an empty input keeps the existing key for the chosen provider while
127
- persisting the provider switch. Pass `--show` to see all per-provider keys (masked), env var status,
128
- and current URL interceptor states (see [§GitHub URL interceptor](#github-url-interceptor)).
129
-
130
- ## API key resolution (per active provider)
131
-
132
- First match wins:
133
-
134
- 1. The active provider's environment variable: `BRAVE_SEARCH_API_KEY`, `TAVILY_API_KEY`, `SERPER_API_KEY`, `EXA_API_KEY`, `YOUCOM_API_KEY`, `JINA_API_KEY`, `FIRECRAWL_API_KEY`, `PERPLEXITY_API_KEY`, `SEARXNG_API_KEY`, or `OLLAMA_API_KEY`
135
- 2. `apiKeys.<provider>` field in `~/.config/rpiv-web-tools/config.json`
136
- 3. Legacy `apiKey` field (Brave only — auto-migrated to the new shape on next save)
137
-
138
- The active provider is `config.provider` (set by `/web-tools`); falls back to `brave` if absent.
139
-
140
- ## SearXNG (self-hosted)
141
-
142
- SearXNG is the only provider that talks to an instance you control, so it needs a base URL instead of (or in addition to) an API key.
143
-
144
- ```bash
145
- export SEARXNG_URL=http://localhost:8080
146
- # Optional: only if your instance sits behind a Bearer-auth reverse proxy
147
- export SEARXNG_API_KEY=…
148
- ```
149
-
150
- Resolution order for the URL: `SEARXNG_URL` env var → `baseUrls.searxng` in `~/.config/rpiv-web-tools/config.json` → default `http://localhost:8080`. `/web-tools` prompts for the URL first and the (optional) API key second.
151
-
152
- Your instance must have `json` enabled in `settings.yml` under `search.formats` — default SearXNG installs ship with JSON disabled and will return `403 Forbidden` otherwise (per the [SearXNG search API docs](https://docs.searxng.org/dev/search_api.html)). The provider surfaces that case with an actionable hint. SearXNG's `web_fetch` reuses the same raw-HTTP + HTML-to-text pipeline as Brave/Serper, so URLs returned by `web_search` can be fetched without any extra setup.
153
-
154
- The SSRF guard (which refuses loopback and RFC-1918 addresses) applies to URLs `web_fetch` retrieves on the model's behalf, not to the SearXNG search endpoint itself: a `SEARXNG_URL` pointing at `http://localhost:8080` or another private host is intentionally reachable, since SearXNG is self-hosted by design.
155
-
156
- ### Running SearXNG locally with Docker
157
-
158
- The `searxng/searxng` entrypoint **overwrites** `/etc/searxng/settings.yml` on first start with the bundled default (ships with `formats: [html]` only). Pre-populating the mounted file doesn't stick — wait for the entrypoint, then patch:
159
-
160
- ```bash
161
- mkdir -p ~/.searxng
162
- docker run -d --name searxng --restart unless-stopped \
163
- -p 8080:8080 -v "$HOME/.searxng":/etc/searxng \
164
- -e BASE_URL=http://localhost:8080/ searxng/searxng:latest
165
- sleep 5 # wait for entrypoint to write settings.yml
166
- sed -i.bak '/^ formats:$/,/^[^ ]/ { /- html/a\
167
- - json
168
- }' ~/.searxng/settings.yml
169
- docker restart searxng
170
-
171
- # Sanity check — a number > 0 means it's wired correctly
172
- curl -sf 'http://localhost:8080/search?q=hello&format=json' | jq '.results | length'
173
- ```
174
-
175
- `403` means JSON is still disabled — re-check `~/.searxng/settings.yml`. Works identically on Docker Desktop or OrbStack. For a throwaway test instance, swap `~/.searxng` for `/tmp/searxng` and drop `--restart unless-stopped`.
176
-
177
- ## Ollama (local or cloud)
178
-
179
- Ollama provides web search and fetch as built-in capabilities — no third-party API key needed for local usage. For cloud access, an API key is required.
180
-
181
- ### Local Ollama
182
-
183
- Just run Ollama locally and it works out of the box:
184
-
185
- ```bash
186
- ollama serve
187
- ```
188
-
189
- No API key needed. The provider talks to `http://localhost:11434` by default.
190
-
191
- ### Ollama Cloud
192
-
193
- For cloud access via [Ollama Cloud](https://ollama.com), set the base URL and API key:
194
-
195
- ```bash
196
- export OLLAMA_HOST=https://ollama.com
197
- export OLLAMA_API_KEY=your_api_key # generate at https://ollama.com/settings/keys
198
- ```
199
-
200
- Or configure interactively via `/web-tools` — select "Ollama" and enter the URL and key.
201
-
202
- Resolution order:
203
- - **Base URL**: `OLLAMA_HOST` env var → `baseUrls.ollama` in config → default `http://localhost:11434`
204
- - **API key**: `OLLAMA_API_KEY` env var → `apiKeys.ollama` in config (optional for local, required for cloud)
205
-
206
- The provider automatically uses the correct API paths:
207
- - **Local** (`localhost`, `127.0.0.1`, `0.0.0.0`): `/api/experimental/web_search` and `/api/experimental/web_fetch`
208
- - **Cloud** (any other host): `/api/web_search` and `/api/web_fetch`
27
+ Restart your Pi session.
209
28
 
210
- ## GitHub URL interceptor
29
+ ## Quick start
211
30
 
212
- Routes github.com URLs through `gh` / `git` to return repository content (file tree, README, file content) instead of the rendered HTML. **Off by default.** Opt in two ways:
31
+ `web_search` needs credentials before it does anything. Run:
213
32
 
214
- ```json
215
- // ~/.config/rpiv-web-tools/config.json — end-user opt-in
216
- { "interceptors": { "github": true } }
217
33
  ```
218
-
219
- ```ts
220
- // or per-consumer at registration time (user config still wins)
221
- registerWebTools(pi, { interceptors: { github: true } });
34
+ /web-tools
222
35
  ```
223
36
 
224
- When enabled, github.com URLs are parsed into `owner/repo/ref/path`; non-code paths (`/issues`, `/pulls`, `/discussions`, `/releases`, …) fall through to the active provider. The interceptor probes for `gh`, falls back to plain `git clone` (with a stderr hint to install `gh`), and uses the `gh api` JSON view for SHA-pinned URLs and repos above `maxRepoSizeMB`. Shallow clones (`--depth 1 --single-branch`) land in `clonePath`; successful clones cache by `owner/repo@ref` for the session. Auth flows through `gh`'s normal `GH_TOKEN`/`GITHUB_TOKEN` precedence — export `GITHUB_TOKEN` to reach private repos.
37
+ Pick a provider from the list and paste its API key. Sign-up links for all ten
38
+ backends are in [Providers](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/providers.md); `brave` is the default. The active
39
+ provider is listed first with `✓`, and any provider you have already
40
+ credentialed is marked `(configured)`. Selecting SearXNG or Ollama prompts for a
41
+ base URL first — those run on your own machine.
225
42
 
226
- Replace the boolean shorthand with an object to tune the defaults; object form implies opt-in.
43
+ Prefer environment variables? Export the provider's key instead and skip the
44
+ command entirely — [Providers](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/providers.md) has the variable name per backend:
227
45
 
228
- ```json
229
- {
230
- "interceptors": {
231
- "github": {
232
- "maxRepoSizeMB": 1000,
233
- "cloneTimeoutSeconds": 90,
234
- "clonePath": "/Users/me/.cache/pi-github-repos"
235
- }
236
- }
237
- }
46
+ ```sh
47
+ export BRAVE_SEARCH_API_KEY=…
238
48
  ```
239
49
 
240
- | Field | Default | Purpose |
241
- |---|---|---|
242
- | `enabled` | `false` (top-level) / `true` (inside object form) | Master switch |
243
- | `maxRepoSizeMB` | `350` | Repos above this threshold skip the clone and use the API view |
244
- | `cloneTimeoutSeconds` | `30` | Kill the clone process after this many seconds |
245
- | `clonePath` | `$TMPDIR/pi-github-repos` | Where shallow clones land; one subdir per `owner/repo@ref` |
246
-
247
- `/web-tools --show` reports the current state at the bottom of its output (resolved token masked, `clonePath`, `maxRepoSizeMB`). The SSRF guard still runs first — a URL with a private/loopback host can't bypass it via a github.com path shape.
248
-
249
- ## Executor guidance overrides
250
-
251
- Override the `promptSnippet` / `promptGuidelines` the model sees for each tool by editing `~/.config/rpiv-web-tools/config.json`. Note the per-tool nesting under `guidance.web_search` / `guidance.web_fetch` — this differs from the flat `guidance` shape used by single-tool siblings (`rpiv-advisor`, `rpiv-todo`, `rpiv-ask-user-question`):
252
-
253
- ```json
254
- {
255
- "provider": "exa",
256
- "apiKeys": {
257
- "exa": "sk-...",
258
- "brave": "sk-..."
259
- },
260
- "interceptors": {
261
- "github": true
262
- },
263
- "guidance": {
264
- "web_search": {
265
- "promptSnippet": "Search the web for current docs and library versions",
266
- "promptGuidelines": [
267
- "Only call web_search when training-data answers may be stale.",
268
- "Always include a Sources: section with markdown hyperlinks."
269
- ]
270
- },
271
- "web_fetch": {
272
- "promptSnippet": "Fetch a specific URL and read its content"
273
- }
274
- }
275
- }
276
- ```
277
-
278
- Each field is independent: omit one and the built-in default is kept. Invalid values (empty string, wrong type, empty array) silently fall back to defaults. Changes take effect on the next Pi session start.
279
-
280
- The `interceptors` key is the GitHub URL interceptor opt-in — see [§GitHub URL interceptor](#github-url-interceptor) for the full schema (boolean shorthand or per-field overrides).
281
-
282
- ## Security note: `web_fetch` host guard
283
-
284
- `web_fetch` refuses URLs targeting loopback (`localhost`, `127.0.0.0/8`, `::1`), RFC 1918 private ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`), link-local (`169.254.0.0/16`, including cloud-metadata at `169.254.169.254`), and IPv6 unique-local / link-local (`fc00::/7`, `fe80::/10`). Attempts surface as `Refusing to fetch private/loopback address: <host>`. This blocks the most common SSRF class — direct-literal targeting of internal services or cloud-metadata endpoints — without preventing legitimate public-web fetches.
285
-
286
- The guard is host-literal only; it does NOT resolve DNS or validate redirects. A public hostname that resolves to a private IP, or a public URL that 302-redirects to one, will still reach the target. For untrusted automation environments, layer an egress proxy or firewall on top.
50
+ Then ask the model something that needs current information — it calls
51
+ `web_search`, then `web_fetch` on the URLs worth reading. `web_fetch` alone
52
+ works with no API key at all.
53
+
54
+ ## What you get
55
+
56
+ - **Answers from the live web** — `web_search` returns 1–10 titled results with
57
+ URLs and snippets per call, and the built-in guidance tells the model to cite
58
+ a `Sources:` section with markdown hyperlinks.
59
+ - **Ten backends, one switch, keys never lost** — Brave, Tavily, Serper, Exa,
60
+ You.com, Jina, Firecrawl, Perplexity, SearXNG and Ollama. Keys are stored per
61
+ provider, so switching backends preserves every other one.
62
+ - **Compare backends without touching config** — pass `provider` on a single
63
+ `web_search` call to route it elsewhere. No config write, no restart, and an
64
+ uncredentialed target throws instead of silently falling back.
65
+ - **Nothing has to leave your network** — SearXNG and Ollama are first-class
66
+ self-hosted providers with their own base-URL resolution and setup flow.
67
+ Local Ollama needs no third-party key at all.
68
+ - **Big pages don't blow up the context** — `web_fetch` truncates long bodies
69
+ and writes the full text to a temp file the model can read on demand.
70
+ - **The model can't be tricked into probing your internal network** —
71
+ `web_fetch` refuses non-http(s) protocols and private, loopback and metadata
72
+ addresses.
73
+ - **GitHub links become repository content** — opt in, and a github.com URL
74
+ returns a file tree, a directory listing, or a file's text from a cached
75
+ shallow clone rather than the rendered HTML page.
76
+
77
+ ## Configuration
78
+
79
+ `/web-tools` writes `~/.config/rpiv-web-tools/config.json` with mode `0600`
80
+ (the directory root follows `XDG_CONFIG_HOME` when it is set). Run
81
+ `/web-tools --show` to print the resolved config, with keys masked.
82
+
83
+ | Key | What it does | Default |
84
+ | --- | --- | --- |
85
+ | `provider` | Active search backend | `brave` |
86
+ | `apiKeys.<provider>` | Per-provider API key | none |
87
+ | `baseUrls.<provider>` | Instance URL for `searxng` / `ollama` | provider default |
88
+ | `interceptors.github` | Enables the GitHub URL interceptor | disabled |
89
+ | `guidance.<tool>` | Replaces the built-in tool guidance the model sees | built-in text |
90
+
91
+ Environment variables win over the file: `WEB_SEARCH_PROVIDER` pins the active
92
+ backend, and each provider's own key variable overrides `apiKeys` — see
93
+ [Providers](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/providers.md) for the variable name per backend. Provider and key
94
+ changes apply on the next tool call; guidance changes apply on the next session
95
+ start.
96
+
97
+ ## Reference
98
+
99
+ - [Tool reference](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/tools.md) — full `web_search` / `web_fetch` schemas,
100
+ result envelopes, dispatch order, truncation, and the host guard.
101
+ - [Providers](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/providers.md) — all ten backends with sign-up links and key
102
+ variable names, plus the exact resolution order for the active provider, its
103
+ key, and its base URL.
104
+ - [Self-hosted backends](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/self-hosted.md) — SearXNG and Ollama setup,
105
+ including a working Docker recipe for SearXNG.
106
+ - [Configuration](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/configuration.md) — every config key, failure behaviour,
107
+ guidance overrides, and the `/web-tools --show` output.
108
+ - [GitHub URL interceptor](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/github-interceptor.md) — opt-in forms, options,
109
+ which URLs it handles, and how content is retrieved.
110
+
111
+ ## Requirements
112
+
113
+ - **Node.js ≥ 22** and a running Pi Agent host.
114
+ - **Credentials for at least one search provider** before `web_search` works.
115
+ Unkeyed providers throw `<ENV_VAR> is not set. Run /web-tools to configure, or
116
+ export the env var.` The self-hosted route needs no vendor key: SearXNG needs
117
+ a reachable instance with `json` enabled under `search.formats`, and Ollama
118
+ needs a running instance.
119
+ - **`gh` or `git`** — only for the opt-in GitHub URL interceptor. Nothing else
120
+ in the package shells out.
121
+
122
+ ## Troubleshooting
123
+
124
+ | Symptom | Cause | Fix |
125
+ | --- | --- | --- |
126
+ | `<ENV_VAR> is not set` on every search | The resolved provider has no key | Run `/web-tools`, or check `/web-tools --show` to see which tier set the active provider |
127
+ | SearXNG returns `403 Forbidden` | The instance has JSON output disabled | Add `json` under `search.formats` in its `settings.yml` — see [self-hosted.md](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/self-hosted.md) |
128
+ | `Could not connect to Ollama at <host>` | No Ollama instance at the resolved host | Start it with `ollama serve`, or set `OLLAMA_HOST` |
129
+ | `Unknown web_search provider: "…"` | A typo in `WEB_SEARCH_PROVIDER` or in the per-call `provider` argument | Use one of the ten names in [providers.md](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/docs/providers.md) |
130
+ | `Unknown search provider: "…"` | A typo in `provider` in the config file | Run `/web-tools` to reselect, or fix the name in `config.json` |
131
+
132
+ ## Related
133
+
134
+ - [`@juicesharp/rpiv-pi`](https://www.npmjs.com/package/@juicesharp/rpiv-pi) —
135
+ the umbrella package; its `web-search-researcher` agent depends on these two
136
+ tools.
287
137
 
288
138
  ## License
289
139
 
290
- [![npm version](https://img.shields.io/npm/v/@juicesharp/rpiv-web-tools.svg)](https://www.npmjs.com/package/@juicesharp/rpiv-web-tools)
291
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
292
-
293
- MIT
140
+ MIT — see [LICENSE](https://github.com/juicesharp/rpiv-mono/blob/main/packages/rpiv-web-tools/LICENSE).
@@ -0,0 +1,137 @@
1
+ # Configuration reference
2
+
3
+ Where the config file lives, every key it accepts, how malformed values are
4
+ handled, and the full `/web-tools` command surface.
5
+
6
+ ## File location
7
+
8
+ ```
9
+ ~/.config/rpiv-web-tools/config.json
10
+ ```
11
+
12
+ The directory root is XDG-aware: when `XDG_CONFIG_HOME` is set to an absolute
13
+ path (or a `~`-prefixed one), the file is
14
+ `$XDG_CONFIG_HOME/rpiv-web-tools/config.json` instead. An unset, empty,
15
+ whitespace-only, or relative `XDG_CONFIG_HOME` is ignored and `~/.config` is
16
+ used.
17
+
18
+ **Legacy fallback is read-only and one-way.** If no file exists at the
19
+ XDG-resolved path, the always-`~/.config` location is read instead, so a config
20
+ written before you set `XDG_CONFIG_HOME` is still found. Writes always go to the
21
+ XDG-resolved path — nothing is copied back. A *malformed* file at the XDG path
22
+ does not fall back; it warns and yields an empty config.
23
+
24
+ The file is written with mode `0o600` (user read/write only). The chmod is
25
+ best-effort: some filesystems ignore it, and it never gates whether the save
26
+ succeeded. When the write itself fails, `/web-tools` says so explicitly rather
27
+ than claiming a save:
28
+
29
+ ```
30
+ Failed to save Exa API key to ~/.config/rpiv-web-tools/config.json — disk write failed
31
+ ```
32
+
33
+ ## Keys
34
+
35
+ | Key | Type | Default | What it does |
36
+ | --- | --- | --- | --- |
37
+ | `provider` | string | `"brave"` when absent | Active search backend. Tier 3 of 4 — see [providers.md](providers.md#active-provider) |
38
+ | `apiKeys` | `Record<string, string>` | `{}` | Per-provider key map, keyed by provider name |
39
+ | `baseUrls` | `Record<string, string>` | `{}` | Base URL per provider; only consulted for `searxng` and `ollama` |
40
+ | `apiKey` | string | unset | Legacy top-level Brave key. Migrated into `apiKeys.brave` and deleted on the next `/web-tools` save |
41
+ | `guidance.web_search.promptSnippet` | string | `"Search the web for up-to-date information"` | One-line description the model sees for `web_search` |
42
+ | `guidance.web_search.promptGuidelines` | string[] | 5 built-in lines | Usage rules the model sees for `web_search` |
43
+ | `guidance.web_fetch.promptSnippet` | string | `"Fetch and read content from a specific URL"` | One-line description the model sees for `web_fetch` |
44
+ | `guidance.web_fetch.promptGuidelines` | string[] | 4 built-in lines | Usage rules the model sees for `web_fetch` |
45
+ | `interceptors.github` | `boolean \| object` | absent → disabled | GitHub URL interceptor opt-in — see [github-interceptor.md](github-interceptor.md) |
46
+
47
+ Every key is optional, and unknown keys round-trip untouched — the file is never
48
+ rewritten to drop fields it does not recognise.
49
+
50
+ ## Failure behaviour
51
+
52
+ The whole file degrades to an empty config rather than crashing the session when
53
+ it is missing, is not valid JSON, is a directory, or violates the schema
54
+ outright.
55
+
56
+ Guidance validation is independently fail-soft: an empty string, a wrong type,
57
+ or an empty array in any `promptSnippet` / `promptGuidelines` field silently
58
+ falls back to the built-in default for that field alone. The other fields are
59
+ unaffected.
60
+
61
+ ## Executor guidance overrides
62
+
63
+ `promptSnippet` and `promptGuidelines` control what the model is told about each
64
+ tool. Note the per-tool nesting under `guidance.web_search` and
65
+ `guidance.web_fetch` — this differs from the flat `guidance` shape used by
66
+ single-tool siblings such as `rpiv-advisor` and `rpiv-todo`.
67
+
68
+ ```json
69
+ {
70
+ "provider": "exa",
71
+ "apiKeys": {
72
+ "exa": "sk-...",
73
+ "brave": "sk-..."
74
+ },
75
+ "interceptors": {
76
+ "github": true
77
+ },
78
+ "guidance": {
79
+ "web_search": {
80
+ "promptSnippet": "Search the web for current docs and library versions",
81
+ "promptGuidelines": [
82
+ "Only call web_search when training-data answers may be stale.",
83
+ "Always include a Sources: section with markdown hyperlinks."
84
+ ]
85
+ },
86
+ "web_fetch": {
87
+ "promptSnippet": "Fetch a specific URL and read its content"
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ Each field is independent: omit one and its built-in default is kept.
94
+
95
+ **Guidance is read once, at registration time**, so guidance edits take effect
96
+ on the next Pi session start. Provider and key config, by contrast, is re-read
97
+ on every tool call — switching provider or key needs no restart.
98
+
99
+ ## `/web-tools`
100
+
101
+ Description: *Configure the search provider and API key used by `web_search`*.
102
+
103
+ Running it with no arguments opens a provider picker (active provider first with
104
+ `✓`, already-configured providers suffixed `(configured)`), then prompts for
105
+ that provider's API key. Pressing Enter on an empty input keeps the existing key
106
+ while still persisting the provider switch. SearXNG and Ollama drive their own
107
+ flow instead: base URL first, then the optional key.
108
+
109
+ The command requires an interactive session; without one it reports
110
+ `/web-tools requires interactive mode` and does nothing.
111
+
112
+ ### `--show`
113
+
114
+ The only flag. It prints the resolved configuration without changing anything:
115
+
116
+ - the config file path in use
117
+ - the active provider and which tier it came from (`env`, `config`, `default`)
118
+ - one line per provider: the resolved key masked as first four characters,
119
+ `...`, last four characters — with the env-var and config-file values shown
120
+ separately so you can see which one won. Unset values render `(not set)`
121
+ - one `<provider> url: <resolved> (source: …)` line for each provider that
122
+ declares a base URL (SearXNG and Ollama)
123
+ - a `URL interceptors:` block reporting the GitHub interceptor's state
124
+
125
+ Any other argument is ignored and falls through to the interactive picker.
126
+
127
+ ## Environment variables
128
+
129
+ | Variable | Effect |
130
+ | --- | --- |
131
+ | `XDG_CONFIG_HOME` | Config directory root; must be absolute or `~`-prefixed, else ignored |
132
+ | `WEB_SEARCH_PROVIDER` | Pins the active provider above the config file |
133
+ | `BRAVE_SEARCH_API_KEY`, `TAVILY_API_KEY`, `SERPER_API_KEY`, `EXA_API_KEY`, `YOUCOM_API_KEY`, `JINA_API_KEY`, `FIRECRAWL_API_KEY`, `PERPLEXITY_API_KEY`, `SEARXNG_API_KEY`, `OLLAMA_API_KEY` | Per-provider keys; win over `apiKeys.<provider>` |
134
+ | `SEARXNG_URL`, `OLLAMA_HOST` | Self-hosted base URLs; win over `baseUrls.<provider>` |
135
+ | `GITHUB_TOKEN` | Read only to display it masked in `/web-tools --show`; GitHub auth itself flows through `gh` |
136
+
137
+ All values are trimmed, so an empty or whitespace-only variable counts as unset.
@@ -0,0 +1,122 @@
1
+ # GitHub URL interceptor
2
+
3
+ An opt-in URL interceptor that makes `web_fetch` return real repository content
4
+ for github.com URLs — a file tree, a directory listing, or a file's text — via
5
+ `gh` or `git`, instead of the rendered HTML page.
6
+
7
+ **It is off by default.** Nothing in this document happens until you enable it.
8
+
9
+ ## Enabling it
10
+
11
+ Two tiers. The user config file always wins over the programmatic default, and a
12
+ literal `false` at the config tier turns it off regardless of what a consumer
13
+ passed.
14
+
15
+ ```json
16
+ // config file — end-user opt-in
17
+ { "interceptors": { "github": true } }
18
+ ```
19
+
20
+ ```ts
21
+ // or per-consumer at registration time (user config still wins)
22
+ registerWebTools(pi, { interceptors: { github: true } });
23
+ ```
24
+
25
+ Resolution, in order:
26
+
27
+ 1. `interceptors.github` in the config file — `false` turns it off, `true` turns
28
+ it on, an object turns it on unless it contains `"enabled": false`.
29
+ 2. `registerWebTools(pi, { interceptors: { github: true } })`.
30
+ 3. Otherwise off.
31
+
32
+ `/web-tools --show` prints the current state under `URL interceptors:` — either
33
+ `github: disabled` with the two config snippets that toggle it, or
34
+ `github: enabled` with the masked `GITHUB_TOKEN`, `maxRepoSizeMB`, and
35
+ `clonePath`.
36
+
37
+ ## Options
38
+
39
+ Replace the boolean shorthand with an object to tune the defaults. The object
40
+ form implies opt-in.
41
+
42
+ ```json
43
+ {
44
+ "interceptors": {
45
+ "github": {
46
+ "maxRepoSizeMB": 1000,
47
+ "cloneTimeoutSeconds": 90,
48
+ "clonePath": "/Users/me/.cache/pi-github-repos"
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ | Field | Default | Purpose |
55
+ | --- | --- | --- |
56
+ | `enabled` | `false` at the top level, `true` implied inside the object form | Master switch |
57
+ | `maxRepoSizeMB` | `350` | Repos larger than this skip the clone and use the API view |
58
+ | `cloneTimeoutSeconds` | `30` | Kill the clone process after this many seconds |
59
+ | `clonePath` | `$TMPDIR/pi-github-repos` | Where shallow clones land, one subdirectory per `owner/repo` (plus ref, when the URL pins one) |
60
+
61
+ ## Which URLs it handles
62
+
63
+ Only `github.com` and `www.github.com` hosts, and only code-shaped paths:
64
+
65
+ | URL shape | Type | What `web_fetch` returns |
66
+ | --- | --- | --- |
67
+ | `/owner/repo` | root | File tree plus the README, and the local clone path |
68
+ | `/owner/repo/tree/<ref>/<path>` | tree | Directory listing for `<path>` |
69
+ | `/owner/repo/blob/<ref>/<path>` | blob | The file's text, truncated at 100K chars |
70
+
71
+ Everything else returns `null` and falls through to the normal `web_fetch`
72
+ pipeline untouched — including `/issues`, `/pull`, `/pulls`, `/discussions`,
73
+ `/releases`, `/wiki`, `/actions`, `/settings`, `/security`, `/projects`,
74
+ `/graphs`, `/compare`, `/commits`, `/tags`, `/branches`, `/stargazers`,
75
+ `/watchers`, `/network`, `/forks`, `/milestone`, `/labels`, `/packages`,
76
+ `/codespaces`, `/contribute`, `/community`, `/sponsors`, `/invitations`,
77
+ `/notifications`, `/insights`.
78
+
79
+ Binary files are reported by extension and size rather than dumped, and a path
80
+ that does not exist in the clone falls back to showing the repository root.
81
+ Clone-backed responses open with `Repository cloned to: <path>` and end with a
82
+ pointer back to it so the model can keep exploring with `read` and `bash`.
83
+ API-view fallbacks have no clone, and say so explicitly instead.
84
+
85
+ ## How content is retrieved
86
+
87
+ 1. **Cache hit** — a repo already cloned this session is reused. The cache key
88
+ is `owner/repo@ref`, or bare `owner/repo` when the URL pins no ref. A clone
89
+ that failed is evicted from the cache rather than remembered.
90
+ 2. **SHA-pinned URLs** — a 40-hex ref skips cloning and uses the `gh api` view,
91
+ with a note explaining why.
92
+ 3. **Oversized repos** — when `gh` can report the repo size and it exceeds
93
+ `maxRepoSizeMB`, the API view is used instead, with a note stating the repo
94
+ size and the threshold. Raise `maxRepoSizeMB` if you want the clone.
95
+ 4. **Shallow clone** — otherwise `--depth 1 --single-branch` into `clonePath`.
96
+ A failed clone falls back to the API view.
97
+
98
+ ## `gh` and `git`
99
+
100
+ The interceptor probes for the [`gh` CLI](https://cli.github.com) with
101
+ `gh --version`. When `gh` is present it clones through `gh repo clone` and can
102
+ use `gh api` for size checks, default branches, and the API view. When `gh` is
103
+ absent it prints once to stderr:
104
+
105
+ ```
106
+ [rpiv-web-tools] Install `gh` CLI for better GitHub repo access including private repos.
107
+ ```
108
+
109
+ and falls back to `git clone --depth 1 --single-branch`.
110
+
111
+ Authentication flows through `gh`'s own token precedence (`GH_TOKEN`,
112
+ `GITHUB_TOKEN`, `gh auth login`) — export `GITHUB_TOKEN` to reach private repos.
113
+ `rpiv-web-tools` itself reads `GITHUB_TOKEN` only to display it masked in
114
+ `/web-tools --show`; it never passes it to a request.
115
+
116
+ This is the only part of the package that shells out to an external binary.
117
+
118
+ ## Security
119
+
120
+ The `web_fetch` host guard still runs **first**, so a URL with a private or
121
+ loopback host cannot bypass it by wearing a github.com-shaped path. See
122
+ [tools.md](tools.md#host-guard).
@@ -0,0 +1,108 @@
1
+ # Providers and credential resolution
2
+
3
+ The ten search backends `rpiv-web-tools` ships with, what each one needs, and the
4
+ exact order in which the active provider, its API key, and its base URL are
5
+ resolved.
6
+
7
+ ## The ten providers
8
+
9
+ One is active at a time. Switching backends never discards the other backends'
10
+ keys — they are stored per provider under `apiKeys.<name>`.
11
+
12
+ | Provider | `provider` name | Key env var | Sign up | `web_fetch` path |
13
+ | --- | --- | --- | --- | --- |
14
+ | Brave | `brave` | `BRAVE_SEARCH_API_KEY` | [brave.com/search/api](https://brave.com/search/api/) | built-in HTTP → text, honours `raw` |
15
+ | Tavily | `tavily` | `TAVILY_API_KEY` | [tavily.com](https://tavily.com) | native extraction (plain text) |
16
+ | Serper | `serper` | `SERPER_API_KEY` | [serper.dev](https://serper.dev) | built-in HTTP → text, honours `raw` |
17
+ | Exa | `exa` | `EXA_API_KEY` | [exa.ai](https://exa.ai) | native extraction (plain text) |
18
+ | You.com | `youcom` | `YOUCOM_API_KEY` | [you.com](https://you.com) | native extraction (markdown) |
19
+ | Jina | `jina` | `JINA_API_KEY` | [jina.ai/reader](https://jina.ai/reader) | native extraction (markdown) |
20
+ | Firecrawl | `firecrawl` | `FIRECRAWL_API_KEY` | [firecrawl.dev](https://firecrawl.dev) | native extraction (markdown) |
21
+ | Perplexity | `perplexity` | `PERPLEXITY_API_KEY` | [docs.perplexity.ai](https://docs.perplexity.ai/) | built-in HTTP → text, honours `raw` |
22
+ | SearXNG | `searxng` | `SEARXNG_API_KEY` (optional) | self-hosted — see [self-hosted.md](self-hosted.md) | built-in HTTP → text, honours `raw` |
23
+ | Ollama | `ollama` | `OLLAMA_API_KEY` (optional locally) | local or [ollama.com](https://ollama.com) | native extraction |
24
+
25
+ SearXNG and Ollama also take a base URL (`SEARXNG_URL`, `OLLAMA_HOST`) because
26
+ they talk to an instance you control. Both are covered in
27
+ [self-hosted.md](self-hosted.md).
28
+
29
+ ## Active provider
30
+
31
+ Four tiers, first match wins:
32
+
33
+ 1. **The `provider` parameter on a single `web_search` call.** Validated against
34
+ the ten known names; an unknown name throws. When present, tiers 2–4 are not
35
+ consulted at all.
36
+ 2. **`WEB_SEARCH_PROVIDER`** environment variable. Trimmed; a whitespace-only
37
+ value counts as unset. Validated *only when it is the resolving tier*, so a
38
+ bogus value cannot defeat a valid per-call override — it throws on the next
39
+ `web_search` that actually resolves through it.
40
+ 3. **`provider` in the config file**, which is what `/web-tools` writes.
41
+ 4. **`brave`**, the built-in default.
42
+
43
+ `/web-tools --show` prints the resolved name together with its source
44
+ (`env`, `config`, or `default`), so you can see which tier won.
45
+
46
+ An unknown name at tier 1 or tier 2 throws:
47
+
48
+ ```
49
+ Unknown web_search provider: "bravo". Valid providers: brave, tavily, serper, exa, youcom, jina, firecrawl, perplexity, searxng, ollama.
50
+ ```
51
+
52
+ Tiers 3 and 4 are not validated at resolution time — a typo in the config file
53
+ instead surfaces `Unknown search provider: "bravo"` from the provider factory on
54
+ the next `web_search`.
55
+
56
+ ## API key
57
+
58
+ Resolved per provider, under whichever provider name won above. Three tiers,
59
+ first match wins:
60
+
61
+ 1. **The provider's own environment variable** (`BRAVE_SEARCH_API_KEY`,
62
+ `TAVILY_API_KEY`, `SERPER_API_KEY`, `EXA_API_KEY`, `YOUCOM_API_KEY`,
63
+ `JINA_API_KEY`, `FIRECRAWL_API_KEY`, `PERPLEXITY_API_KEY`,
64
+ `SEARXNG_API_KEY`, `OLLAMA_API_KEY`).
65
+ 2. **`apiKeys.<provider>`** in the config file.
66
+ 3. **Legacy top-level `apiKey`**, Brave only. It is auto-migrated into
67
+ `apiKeys.brave` and deleted from the file on the next `/web-tools` save.
68
+
69
+ Every environment value is trimmed, so an empty or whitespace-only variable is
70
+ treated as unset and resolution falls through to the next tier.
71
+
72
+ There is **no cross-provider fallback**. If the resolved provider has no key,
73
+ the call throws:
74
+
75
+ ```
76
+ EXA_API_KEY is not set. Run /web-tools to configure, or export the env var.
77
+ ```
78
+
79
+ That is deliberate — an agent can detect the misconfiguration instead of
80
+ silently getting results from a backend it did not ask for.
81
+
82
+ ## Base URL
83
+
84
+ Only consulted for providers that declare a base-URL environment variable
85
+ (SearXNG and Ollama today). Hosted providers short-circuit to the empty string.
86
+
87
+ 1. The provider's base-URL environment variable (`SEARXNG_URL`, `OLLAMA_HOST`).
88
+ 2. `baseUrls.<provider>` in the config file.
89
+ 3. The provider's built-in default (`http://localhost:8080` for SearXNG,
90
+ `http://localhost:11434` for Ollama).
91
+
92
+ `/web-tools --show` prints one `<provider> url: <resolved> (source: …)` line per
93
+ provider that declares a base URL.
94
+
95
+ ## Picker markers
96
+
97
+ The `/web-tools` provider list is ordered with the active provider first, marked
98
+ `✓`. Any provider that already resolves to a key is suffixed `(configured)`. For
99
+ SearXNG and Ollama, `(configured)` means a base URL has been set explicitly via
100
+ environment variable or config — the bare built-in default does not count,
101
+ because it only indicates the setting has never been touched.
102
+
103
+ ## Related
104
+
105
+ - [tools.md](tools.md) — the `provider` parameter and its effect on resolution.
106
+ - [configuration.md](configuration.md) — where the config file lives and what
107
+ every key does.
108
+ - [self-hosted.md](self-hosted.md) — SearXNG and Ollama setup.
@@ -0,0 +1,120 @@
1
+ # Self-hosted backends
2
+
3
+ Two of the ten providers talk to an instance you run yourself, so nothing has to
4
+ leave your network: **SearXNG** and **Ollama**. Both take a base URL in addition
5
+ to (or instead of) an API key, and both drive their own prompt flow inside
6
+ `/web-tools` — URL first, then the optional key.
7
+
8
+ ## SearXNG
9
+
10
+ [SearXNG](https://docs.searxng.org/) is a self-hosted metasearch engine. It
11
+ needs a base URL; the API key is optional and only used when the instance sits
12
+ behind a Bearer-auth reverse proxy.
13
+
14
+ ```sh
15
+ export SEARXNG_URL=http://localhost:8080
16
+ # Optional: only if your instance sits behind a Bearer-auth reverse proxy
17
+ export SEARXNG_API_KEY=…
18
+ ```
19
+
20
+ Base-URL resolution: `SEARXNG_URL` → `baseUrls.searxng` in the config file →
21
+ `http://localhost:8080`. When the resolved URL is empty, `web_search` throws
22
+ `SEARXNG_URL is not set. Run /web-tools to configure, or export the env var.`
23
+
24
+ ### JSON output must be enabled
25
+
26
+ Your instance must have `json` listed under `search.formats` in `settings.yml`.
27
+ Default SearXNG installs ship with JSON disabled and return `403 Forbidden`
28
+ otherwise (see the
29
+ [SearXNG search API docs](https://docs.searxng.org/dev/search_api.html)). The
30
+ provider surfaces that case with an actionable hint appended to the error:
31
+
32
+ - `403` → *the SearXNG instance may have JSON output disabled; enable 'json'
33
+ under 'search.formats' in its settings.yml*
34
+ - `401` → *the SearXNG instance's reverse-proxy rejected the Bearer token; check
35
+ `SEARXNG_API_KEY` or `apiKeys.searxng`*
36
+
37
+ ### Running SearXNG locally with Docker
38
+
39
+ The `searxng/searxng` entrypoint **overwrites** `/etc/searxng/settings.yml` on
40
+ first start with the bundled default (which ships `formats: [html]` only).
41
+ Pre-populating the mounted file does not stick — wait for the entrypoint, then
42
+ patch:
43
+
44
+ ```sh
45
+ mkdir -p ~/.searxng
46
+ docker run -d --name searxng --restart unless-stopped \
47
+ -p 8080:8080 -v "$HOME/.searxng":/etc/searxng \
48
+ -e BASE_URL=http://localhost:8080/ searxng/searxng:latest
49
+ sleep 5 # wait for entrypoint to write settings.yml
50
+ sed -i.bak '/^ formats:$/,/^[^ ]/ { /- html/a\
51
+ - json
52
+ }' ~/.searxng/settings.yml
53
+ docker restart searxng
54
+
55
+ # Sanity check — a number > 0 means it's wired correctly
56
+ curl -sf 'http://localhost:8080/search?q=hello&format=json' | jq '.results | length'
57
+ ```
58
+
59
+ A `403` here means JSON is still disabled — re-check `~/.searxng/settings.yml`.
60
+ Works identically on Docker Desktop and OrbStack. For a throwaway test instance,
61
+ swap `~/.searxng` for `/tmp/searxng` and drop `--restart unless-stopped`.
62
+
63
+ ### Fetching
64
+
65
+ SearXNG is search-only. `web_fetch` falls through to the built-in HTTP +
66
+ HTML-to-text pipeline, so URLs returned by `web_search` are readable with no
67
+ extra setup, and `raw: true` is honoured.
68
+
69
+ ## Ollama
70
+
71
+ [Ollama](https://ollama.com) exposes web search and web fetch as built-in
72
+ capabilities. Local use needs no third-party key; cloud use requires one.
73
+
74
+ ### Local
75
+
76
+ ```sh
77
+ ollama serve
78
+ ```
79
+
80
+ That is all — the provider talks to `http://localhost:11434` by default and no
81
+ API key is needed. If the instance is not running, the error is
82
+ `Could not connect to Ollama at <host>. Make sure Ollama is running (ollama serve).`
83
+
84
+ ### Cloud
85
+
86
+ ```sh
87
+ export OLLAMA_HOST=https://ollama.com
88
+ export OLLAMA_API_KEY=your_api_key # generate at https://ollama.com/settings/keys
89
+ ```
90
+
91
+ Or run `/web-tools`, select **Ollama**, and enter the URL and key interactively.
92
+
93
+ ### Resolution
94
+
95
+ - **Base URL**: `OLLAMA_HOST` → `baseUrls.ollama` in the config file →
96
+ `http://localhost:11434`. An empty resolved URL throws
97
+ `OLLAMA_HOST is not set. Run /web-tools to configure, or export the env var.`
98
+ - **API key**: `OLLAMA_API_KEY` → `apiKeys.ollama` in the config file. Optional
99
+ for local, required for cloud.
100
+
101
+ ### API paths
102
+
103
+ The provider picks the endpoint pair from the resolved host, so you never set it
104
+ by hand:
105
+
106
+ | Host | Search path | Fetch path |
107
+ | --- | --- | --- |
108
+ | `localhost`, `127.0.0.1`, `0.0.0.0`, `[::1]` | `/api/experimental/web_search` | `/api/experimental/web_fetch` |
109
+ | anything else (cloud) | `/api/web_search` | `/api/web_fetch` |
110
+
111
+ Ollama is a full provider: `web_fetch` uses its native extraction endpoint
112
+ rather than the built-in HTML pipeline.
113
+
114
+ ## Note on the host guard
115
+
116
+ `web_fetch` refuses private and loopback hosts, but that guard applies to URLs
117
+ fetched **on the model's behalf**, not to provider endpoints. A `SEARXNG_URL` or
118
+ `OLLAMA_HOST` pointing at `http://localhost` is intentionally reachable — these
119
+ providers are self-hosted by design. See
120
+ [tools.md](tools.md#host-guard) for the full guard.
package/docs/tools.md ADDED
@@ -0,0 +1,175 @@
1
+ # Tool reference
2
+
3
+ Complete parameter schemas, result envelopes, and failure modes for the two tools
4
+ `rpiv-web-tools` registers: `web_search` and `web_fetch`.
5
+
6
+ ## `web_search`
7
+
8
+ Registered as tool name `web_search`, label `Web Search`. Queries the active
9
+ search provider's API and returns titled results with URLs and snippets.
10
+
11
+ ### Parameters
12
+
13
+ ```ts
14
+ web_search({
15
+ query: string, // required — natural-language query
16
+ max_results?: number, // 1-10, default 5
17
+ provider?: // per-call override; see below
18
+ | "brave" | "tavily" | "serper" | "exa" | "youcom" | "jina"
19
+ | "firecrawl" | "perplexity" | "searxng" | "ollama",
20
+ })
21
+ ```
22
+
23
+ `max_results` is **clamped**, not rejected: values below `1` become `1`, values
24
+ above `10` become `10`, and an omitted value becomes `5`.
25
+
26
+ ### Result
27
+
28
+ ```ts
29
+ {
30
+ content: [{ type: "text", text: string }], // "**Search results for \"<query>\":**"
31
+ // then a numbered list of
32
+ // "**title**\n url\n snippet"
33
+ details: {
34
+ query: string,
35
+ backend: string, // the provider that actually ran
36
+ resultCount: number,
37
+ results?: Array<{ title: string, url: string, snippet: string }>,
38
+ }
39
+ }
40
+ ```
41
+
42
+ When the provider returns zero results, the envelope collapses to
43
+ `content: [{ type: "text", text: 'No results found for "<query>".' }]` with
44
+ `details.resultCount = 0` and no `results` array.
45
+
46
+ ### Throws
47
+
48
+ | Condition | Message shape |
49
+ | --- | --- |
50
+ | Resolved provider has no key | `EXA_API_KEY is not set. Run /web-tools to configure, or export the env var.` |
51
+ | Unknown provider name | `Unknown web_search provider: "<name>". Valid providers: brave, tavily, serper, exa, youcom, jina, firecrawl, perplexity, searxng, ollama.` |
52
+ | Provider API returns non-2xx | vendor-specific, with the status code |
53
+
54
+ ### Per-call `provider` override
55
+
56
+ The optional `provider` parameter routes a single call to a different backend
57
+ without mutating persisted config and without a session restart. The named
58
+ provider must have its own credentials — the override does **not** inherit the
59
+ active provider's key, and an unconfigured target throws the usual `… is not
60
+ set` error rather than silently falling back, so the caller can detect the
61
+ misconfiguration.
62
+
63
+ An override also short-circuits the `WEB_SEARCH_PROVIDER` environment variable
64
+ entirely: that tier is neither read nor validated when an override is present,
65
+ so a bogus env var cannot defeat a valid per-call override. Full four-tier
66
+ resolution is documented in [providers.md](providers.md#active-provider).
67
+
68
+ Use it for provider comparison inside one session, or to retry against a second
69
+ backend when the active one returns poor results.
70
+
71
+ ## `web_fetch`
72
+
73
+ Registered as tool name `web_fetch`, label `Web Fetch`. Reads an http/https URL
74
+ and returns its text.
75
+
76
+ ### Parameters
77
+
78
+ ```ts
79
+ web_fetch({
80
+ url: string, // required — http or https only
81
+ raw?: boolean, // true → raw response body; default false → text
82
+ })
83
+ ```
84
+
85
+ ### Result
86
+
87
+ ```ts
88
+ {
89
+ content: [{ type: "text", text: string }], // header block + body
90
+ details: {
91
+ url: string,
92
+ title?: string, // <title> element, when present
93
+ contentType?: string,
94
+ contentLength?: number, // from the Content-Length header
95
+ truncation?: TruncationResult, // present only when the body was truncated
96
+ fullOutputPath?: string, // temp file holding the un-truncated body
97
+ }
98
+ }
99
+ ```
100
+
101
+ The text content is prefixed with a header block before the body:
102
+
103
+ ```
104
+ **Fetched:** <url>
105
+ **Title:** <title>
106
+ **Content-Type:** <content-type>
107
+ ```
108
+
109
+ ### Dispatch order
110
+
111
+ `web_fetch` resolves the body through three tiers, first hit wins:
112
+
113
+ 1. **URL interceptors** — currently only the opt-in GitHub interceptor, which
114
+ returns `null` for anything that isn't a github.com code URL. The chain is
115
+ empty when the interceptor is disabled. See
116
+ [github-interceptor.md](github-interceptor.md).
117
+ 2. **The active provider's native fetch** — Tavily, Exa, You.com, Jina,
118
+ Firecrawl and Ollama carry vendor extraction endpoints.
119
+ 3. **The built-in HTTP + HTML-to-text pipeline** — used for search-only
120
+ providers (Brave, Serper, Perplexity, SearXNG) and whenever the active
121
+ provider has no `fetch` method. This path needs no API key at all, so
122
+ `web_fetch` still works when the active provider is an unkeyed search-only
123
+ backend. An unkeyed extraction provider (Tavily, Exa, You.com, Jina,
124
+ Firecrawl) throws instead, because its native fetch runs first and never
125
+ reaches this tier.
126
+
127
+ `raw: true` is honoured by tier 3 (raw response instead of extracted text).
128
+ Extraction providers always return their own parsed text.
129
+
130
+ ### Truncation and spillover
131
+
132
+ Bodies are truncated to 2000 lines / 50 KB. When truncation occurs the **full**
133
+ body is written to a temp file under `$TMPDIR/rpiv-fetch-XXXXXX/content.txt`,
134
+ the path is recorded in `details.fullOutputPath`, and a footer is appended to
135
+ the content telling the model exactly what was omitted:
136
+
137
+ ```
138
+ [Content truncated: showing 64 of 988 lines (3.2 KB of 61.4 KB).
139
+ 924 lines (58.2 KB) omitted. Full content saved to: /tmp/rpiv-fetch-Xa0k/content.txt]
140
+ ```
141
+
142
+ The model can then read the temp file to recover the rest.
143
+
144
+ ### Host guard
145
+
146
+ `web_fetch` parses the URL and refuses it before any network call when the
147
+ protocol is not `http:`/`https:`, or when the host literal falls in a
148
+ private/loopback range:
149
+
150
+ | Class | Refused hosts |
151
+ | --- | --- |
152
+ | Loopback / unspecified | `localhost`, `*.localhost`, `0.0.0.0/8`, `127.0.0.0/8`, `::1`, `::` |
153
+ | RFC 1918 | `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` |
154
+ | Link-local | `169.254.0.0/16` (including cloud metadata at `169.254.169.254`), `fe80::/10` |
155
+ | IPv6 unique-local | `fc00::/7` (`fc…`, `fd…`) |
156
+
157
+ Refusals surface as `Refusing to fetch private/loopback address: <host>`. The
158
+ guard runs **before** the interceptor chain, so a private host cannot bypass it
159
+ via a github.com-shaped path.
160
+
161
+ The guard is **host-literal only** — it does not resolve DNS and does not
162
+ validate redirects. A public hostname that resolves to a private IP, or a public
163
+ URL that 302-redirects to one, still reaches the target. For untrusted
164
+ automation environments, layer an egress proxy or firewall on top.
165
+
166
+ The guard applies to URLs `web_fetch` retrieves on the model's behalf, not to
167
+ provider endpoints: a `SEARXNG_URL` or `OLLAMA_HOST` pointing at
168
+ `http://localhost` is intentionally reachable.
169
+
170
+ ### Throws
171
+
172
+ Invalid URL, unsupported protocol, a refused private/loopback host, a non-2xx
173
+ response, or an `image/` / `video/` / `audio/` content type. Extraction
174
+ providers additionally throw on an empty body or a vendor-level failure (for
175
+ example Firecrawl `success: false`, Tavily `failed_results`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-web-tools",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Pi extension. Web search and fetch for the model with pluggable providers (Brave, Tavily, Serper, Exa, You.com, Jina, Firecrawl, Perplexity, SearXNG, Ollama).",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -50,6 +50,10 @@
50
50
  "index.ts",
51
51
  "web-tools.ts",
52
52
  "providers/",
53
+ "docs/",
54
+ "!docs/*.png",
55
+ "!docs/*.jpg",
56
+ "!docs/*.svg",
53
57
  "README.md",
54
58
  "LICENSE",
55
59
  "!**/*.test.ts"
@@ -60,7 +64,7 @@
60
64
  ]
61
65
  },
62
66
  "dependencies": {
63
- "@juicesharp/rpiv-config": "^2.0.0",
67
+ "@juicesharp/rpiv-config": "^2.1.0",
64
68
  "typebox": "^1.1.24"
65
69
  },
66
70
  "peerDependencies": {