@juicesharp/rpiv-web-tools 1.20.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,281 +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 the active provider's search API and return titled snippets.
51
- 1–10 results per call.
52
- - **`web_fetch`** - read an http/https URL. Lookup order: opt-in URL interceptors
53
- (see [§GitHub URL interceptor](#github-url-interceptor)), then the active provider's native
54
- fetch endpoint when it has one (Tavily/Exa/You.com/Jina/Firecrawl/Ollama → vendor extraction;
55
- Brave/Serper/Perplexity/SearXNG → shared raw HTTP + HTML-to-text fallback). Large responses truncate
56
- inline and spill the full body to a temp file the model can read on demand.
57
-
58
- ### Schema - `web_search`
59
-
60
- ```ts
61
- web_search({
62
- query: string, // natural-language query
63
- max_results?: number, // 1-10, default 5
64
- })
65
- ```
66
-
67
- Returns:
68
-
69
- ```ts
70
- {
71
- content: [{ type: "text", text: string }], // markdown list of "**title**\n url\n snippet"
72
- details: {
73
- query: string,
74
- backend: "brave" | "tavily" | "serper" | "exa" | "youcom" | "jina" | "firecrawl" | "perplexity" | "searxng" | "ollama",
75
- resultCount: number,
76
- results?: Array<{ title: string, url: string, snippet: string }>,
77
- }
78
- }
79
- ```
80
-
81
- Throws when the active provider's API key is unset (e.g. `EXA_API_KEY is not set`) or the provider's API returns a non-2xx response.
82
-
83
- ### Schema - `web_fetch`
84
-
85
- ```ts
86
- web_fetch({
87
- url: string, // http or https only
88
- raw?: boolean, // true → return raw HTML; default false → strip to text
89
- })
90
- ```
91
-
92
- Returns:
93
-
94
- ```ts
95
- {
96
- content: [{ type: "text", text: string }], // header (URL/title/content-type) + body
97
- details: {
98
- url: string,
99
- title?: string, // <title> element, if present (HTML, non-raw)
100
- contentType?: string,
101
- contentLength?: number, // from Content-Length header
102
- truncation?: TruncationResult, // present when body exceeded inline limits
103
- fullOutputPath?: string, // temp-file path containing the un-truncated body
104
- }
105
- }
106
- ```
107
-
108
- 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`).
109
-
110
- ## Commands
111
-
112
- - **`/web-tools`** - pick the active provider and set its API key interactively.
113
- Providers already configured show `(configured)`; the active one is listed first with a `✓`.
114
- Pressing Enter on an empty input keeps the existing key for the chosen provider while
115
- persisting the provider switch. Pass `--show` to see all per-provider keys (masked), env var status,
116
- and current URL interceptor states (see [§GitHub URL interceptor](#github-url-interceptor)).
117
-
118
- ## API key resolution (per active provider)
119
-
120
- First match wins:
121
-
122
- 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`
123
- 2. `apiKeys.<provider>` field in `~/.config/rpiv-web-tools/config.json`
124
- 3. Legacy `apiKey` field (Brave only — auto-migrated to the new shape on next save)
125
-
126
- The active provider is `config.provider` (set by `/web-tools`); falls back to `brave` if absent.
127
-
128
- ## SearXNG (self-hosted)
129
-
130
- 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.
131
-
132
- ```bash
133
- export SEARXNG_URL=http://localhost:8080
134
- # Optional: only if your instance sits behind a Bearer-auth reverse proxy
135
- export SEARXNG_API_KEY=…
136
- ```
137
-
138
- 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.
27
+ Restart your Pi session.
139
28
 
140
- 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.
29
+ ## Quick start
141
30
 
142
- 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.
31
+ `web_search` needs credentials before it does anything. Run:
143
32
 
144
- ### Running SearXNG locally with Docker
145
-
146
- 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:
147
-
148
- ```bash
149
- mkdir -p ~/.searxng
150
- docker run -d --name searxng --restart unless-stopped \
151
- -p 8080:8080 -v "$HOME/.searxng":/etc/searxng \
152
- -e BASE_URL=http://localhost:8080/ searxng/searxng:latest
153
- sleep 5 # wait for entrypoint to write settings.yml
154
- sed -i.bak '/^ formats:$/,/^[^ ]/ { /- html/a\
155
- - json
156
- }' ~/.searxng/settings.yml
157
- docker restart searxng
158
-
159
- # Sanity check — a number > 0 means it's wired correctly
160
- curl -sf 'http://localhost:8080/search?q=hello&format=json' | jq '.results | length'
161
- ```
162
-
163
- `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`.
164
-
165
- ## Ollama (local or cloud)
166
-
167
- 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.
168
-
169
- ### Local Ollama
170
-
171
- Just run Ollama locally and it works out of the box:
172
-
173
- ```bash
174
- ollama serve
175
- ```
176
-
177
- No API key needed. The provider talks to `http://localhost:11434` by default.
178
-
179
- ### Ollama Cloud
180
-
181
- For cloud access via [Ollama Cloud](https://ollama.com), set the base URL and API key:
182
-
183
- ```bash
184
- export OLLAMA_HOST=https://ollama.com
185
- export OLLAMA_API_KEY=your_api_key # generate at https://ollama.com/settings/keys
186
- ```
187
-
188
- Or configure interactively via `/web-tools` — select "Ollama" and enter the URL and key.
189
-
190
- Resolution order:
191
- - **Base URL**: `OLLAMA_HOST` env var → `baseUrls.ollama` in config → default `http://localhost:11434`
192
- - **API key**: `OLLAMA_API_KEY` env var → `apiKeys.ollama` in config (optional for local, required for cloud)
193
-
194
- The provider automatically uses the correct API paths:
195
- - **Local** (`localhost`, `127.0.0.1`, `0.0.0.0`): `/api/experimental/web_search` and `/api/experimental/web_fetch`
196
- - **Cloud** (any other host): `/api/web_search` and `/api/web_fetch`
197
-
198
- ## GitHub URL interceptor
199
-
200
- 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:
201
-
202
- ```json
203
- // ~/.config/rpiv-web-tools/config.json — end-user opt-in
204
- { "interceptors": { "github": true } }
205
33
  ```
206
-
207
- ```ts
208
- // or per-consumer at registration time (user config still wins)
209
- registerWebTools(pi, { interceptors: { github: true } });
210
- ```
211
-
212
- 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.
213
-
214
- Replace the boolean shorthand with an object to tune the defaults; object form implies opt-in.
215
-
216
- ```json
217
- {
218
- "interceptors": {
219
- "github": {
220
- "maxRepoSizeMB": 1000,
221
- "cloneTimeoutSeconds": 90,
222
- "clonePath": "/Users/me/.cache/pi-github-repos"
223
- }
224
- }
225
- }
34
+ /web-tools
226
35
  ```
227
36
 
228
- | Field | Default | Purpose |
229
- |---|---|---|
230
- | `enabled` | `false` (top-level) / `true` (inside object form) | Master switch |
231
- | `maxRepoSizeMB` | `350` | Repos above this threshold skip the clone and use the API view |
232
- | `cloneTimeoutSeconds` | `30` | Kill the clone process after this many seconds |
233
- | `clonePath` | `$TMPDIR/pi-github-repos` | Where shallow clones land; one subdir per `owner/repo@ref` |
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.
234
42
 
235
- `/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.
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:
236
45
 
237
- ## Executor guidance overrides
238
-
239
- 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`):
240
-
241
- ```json
242
- {
243
- "provider": "exa",
244
- "apiKeys": {
245
- "exa": "sk-...",
246
- "brave": "sk-..."
247
- },
248
- "interceptors": {
249
- "github": true
250
- },
251
- "guidance": {
252
- "web_search": {
253
- "promptSnippet": "Search the web for current docs and library versions",
254
- "promptGuidelines": [
255
- "Only call web_search when training-data answers may be stale.",
256
- "Always include a Sources: section with markdown hyperlinks."
257
- ]
258
- },
259
- "web_fetch": {
260
- "promptSnippet": "Fetch a specific URL and read its content"
261
- }
262
- }
263
- }
46
+ ```sh
47
+ export BRAVE_SEARCH_API_KEY=…
264
48
  ```
265
49
 
266
- 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.
267
-
268
- 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).
269
-
270
- ## Security note: `web_fetch` host guard
271
-
272
- `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.
273
-
274
- 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.
275
137
 
276
138
  ## License
277
139
 
278
- [![npm version](https://img.shields.io/npm/v/@juicesharp/rpiv-web-tools.svg)](https://www.npmjs.com/package/@juicesharp/rpiv-web-tools)
279
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
280
-
281
- 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).