dsh-web-discovery 1.0.0 → 1.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 +97 -23
- package/lib/discovery.mjs +587 -91
- package/lib/discovery.mjs.map +4 -4
- package/lib/index.js +763 -129
- package/lib/index.js.map +4 -4
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,57 +1,131 @@
|
|
|
1
1
|
# dsh-web-discovery
|
|
2
2
|
|
|
3
|
+
**URL supply is the scarce resource.** That is the conclusion of this project!!!
|
|
4
|
+
|
|
3
5
|
Discovery companion for **[`dsh-web-missions`](https://github.com/janpauldahlke/dsh-web-missions)**
|
|
4
6
|
(npm: `dsh-web-missions`). Happy-path opener for web research missions:
|
|
5
|
-
the model gets candidate URLs from
|
|
6
|
-
|
|
7
|
+
the model gets candidate URLs from search engines behind a DiscoveryPort —
|
|
8
|
+
the mission core only sees **URLs in / URLs out**.
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
**Cordis cut:** sibling Loader plugin in the same profile as missions — not an
|
|
11
|
+
npm dependency of missions. Seam = `discovery_search` on the tools face +
|
|
12
|
+
one-way `discovery.json`. Publish/curate this package on npm and enable both
|
|
13
|
+
bundles side by side.
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
Three engines, all optional (D-M7.2 / P_08):
|
|
12
16
|
|
|
13
17
|
| Engine | Transport | Config |
|
|
14
18
|
| --- | --- | --- |
|
|
15
|
-
| **
|
|
16
|
-
| **`browser39 search`** | CLI — `
|
|
19
|
+
| **Serper.dev** | HTTP JSON — `POST https://google.serper.dev/search` → `organic[{title,link,snippet}]` | `SERPER_API_KEY` in profile/process env (`~/.dsh/.env`); optional cwd `serperApiKey` override; optional `serperEndpoint` / `SERPER_ENDPOINT` |
|
|
20
|
+
| **`browser39 search`** | CLI — npm `@aquintanar/browser39@2.0.0` `bin.js` (not PATH cargo) | `browser39Bin` / `BROWSER39_BIN` (default auto) |
|
|
21
|
+
| **SearXNG** | HTTP JSON — `GET {endpoint}/search?q=…&format=json` → `results[{url,title,content}]` | `searxngEndpoint` / `SEARXNG_ENDPOINT` (default `http://127.0.0.1:8888/searxng` — not :8080, that port is llama) |
|
|
17
22
|
|
|
18
|
-
**Missing discovery is a supported state** (D-M7.3): no
|
|
19
|
-
browser39
|
|
23
|
+
**Missing discovery is a supported state** (D-M7.3): no Serper key + no SearXNG
|
|
24
|
+
+ no browser39 → the tool returns `no_engine` and the mission core degrades
|
|
20
25
|
to fixtures / human-supplied URLs. No DIY SERP scraping in our code (Eris
|
|
21
|
-
scar, D4).
|
|
26
|
+
scar, D4). Serper credits are scarce — hermetic tests never call the live API.
|
|
22
27
|
|
|
23
28
|
## The one tool
|
|
24
29
|
|
|
25
30
|
```
|
|
26
31
|
discovery_search { query, engine?, limit?, mission_id?, cwd? }
|
|
27
|
-
→ { ok:
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
→ { v:1, ok:true, query, engine, count, dropped, categorizer,
|
|
33
|
+
urls: [{ i, url, host, title?, snippet?, flags, label }],
|
|
34
|
+
notes?: ["serper: …"], // prior engine failures on auto fall-through
|
|
35
|
+
recorded?: "<mission_id>/discovery.json" }
|
|
36
|
+
| { v:1, ok:false, error: "no_engine: …" | "search_failed: …" | "budget_exhausted: …" | … }
|
|
30
37
|
```
|
|
31
38
|
|
|
32
|
-
- `engine` pins `
|
|
33
|
-
browser39 — first engine that answers wins
|
|
34
|
-
|
|
39
|
+
- `engine` pins `serper`, `browser39`, or `searxng`; omitted = auto
|
|
40
|
+
(**serper → browser39 → searxng** — first engine that answers wins;
|
|
41
|
+
earlier failures stay in `notes`). Wall-clock budget 45s (`budget_exhausted`).
|
|
42
|
+
- `limit` default **5** (clamped 1..50).
|
|
43
|
+
- With `mission_id`, lean hits are recorded into
|
|
35
44
|
`<cwd>/.dsh/web-missions/<mission_id>/discovery.json` (one-way bridge:
|
|
36
45
|
companion writes, the core surfaces it on `mission_status`). Discovered
|
|
37
46
|
URLs are **not ledger rows** (D-M7.4) — they become rows only when the
|
|
38
47
|
core fetches them, through the allowlist gate.
|
|
39
48
|
|
|
49
|
+
### Programmatic port (tests / non-Cordis)
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { createDiscoveryPort } from 'dsh-web-discovery/discovery'
|
|
53
|
+
const port = createDiscoveryPort(cwd)
|
|
54
|
+
const hits = await port.search('query', { engine: 'auto' /* or pin */, limit: 5 })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Export for hermetic tests and non-Cordis callers. Under Cordis, the live
|
|
58
|
+
contract is the **sibling plugin** (`discovery_search` + `discovery.json`), not
|
|
59
|
+
missions importing this package. The agent still invokes `discovery_search` as
|
|
60
|
+
the first tool (no auto-search on `mission_start`).
|
|
61
|
+
|
|
40
62
|
## Config (per cwd, at tool-call time)
|
|
41
63
|
|
|
42
|
-
`<cwd>/.dsh/web-discovery/config.json` (optional; corrupt = fail loud)
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
`<cwd>/.dsh/web-discovery/config.json` (optional; corrupt = fail loud).
|
|
65
|
+
|
|
66
|
+
| Knob | Default | Env |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| `serperApiKey` | `""` | optional cwd override; prefer **`SERPER_API_KEY`** in `~/.dsh/.env` (profile — all plugins see it) |
|
|
69
|
+
| `serperEndpoint` | `https://google.serper.dev/search` | `SERPER_ENDPOINT` |
|
|
70
|
+
| `searxngEndpoint` | `http://127.0.0.1:8888/searxng` | `SEARXNG_ENDPOINT` |
|
|
71
|
+
| `browser39Bin` | `browser39` (npm resolve) | `BROWSER39_BIN` |
|
|
72
|
+
| `receiptCharBudget` | `6000` | `RECEIPT_CHAR_BUDGET` |
|
|
73
|
+
| `categorizerEndpoint` | `""` (off) | `CATEGORIZER_ENDPOINT` |
|
|
74
|
+
| `categorizerModel` | `local-categorizer` | `CATEGORIZER_MODEL` |
|
|
75
|
+
| `categorizerApiKeyEnv` | `""` | `CATEGORIZER_API_KEY_ENV` |
|
|
76
|
+
| `categorizerTimeoutMs` | `5000` | `CATEGORIZER_TIMEOUT_MS` |
|
|
77
|
+
| `aliasWebSearch` | `false` | `ALIAS_WEB_SEARCH` |
|
|
78
|
+
|
|
79
|
+
Empty string on an engine knob disables that engine. Put the Serper key in
|
|
80
|
+
**`~/.dsh/.env`** as `SERPER_API_KEY=…` (DSH `loadLayeredEnv` — shared by every
|
|
81
|
+
plugin in the profile). Never commit or log a real key; do not put it in a
|
|
82
|
+
workspace repo.
|
|
83
|
+
|
|
84
|
+
## LLM categorizer (opt-in, P_04)
|
|
85
|
+
|
|
86
|
+
Off unless `categorizerEndpoint` is set. OpenAI-compatible chat completions;
|
|
87
|
+
labels override heuristics; flags stay heuristic. Failures never fail the
|
|
88
|
+
search (`categorizer: "heuristic (llm unavailable)"`).
|
|
89
|
+
|
|
90
|
+
- Localhost endpoint → `llm-local`; anything else → `llm-remote`.
|
|
91
|
+
- **Remote endpoints break local-first / ISO** — only use if you accept query
|
|
92
|
+
titles/snippets leaving the box to that host.
|
|
93
|
+
- Local recipe: a 1–2B Q4 model on **llama.cpp CPU** on its **own port** (not
|
|
94
|
+
`:8080` — that is the 27B coding model). Measure p90 while the big model runs;
|
|
95
|
+
kill if >5s average or <15% gain (DECISIONS §9).
|
|
96
|
+
|
|
97
|
+
## Optional `web_search` alias (P_07)
|
|
98
|
+
|
|
99
|
+
Set `ALIAS_WEB_SEARCH=1` **and** disable the stock DSH web-search plugin so
|
|
100
|
+
names do not collide. Shape: `{ queries: string[] }` →
|
|
101
|
+
`{ content?, sources:[{url,title?,snippet?}], truncated }`. Thin wrapper over
|
|
102
|
+
the same core; v0 uses `queries[0]` only. Rollback = unset the env / re-enable
|
|
103
|
+
stock plugin.
|
|
104
|
+
|
|
105
|
+
## SearXNG (optional Docker)
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Operator-owned — no install script in this repo (DECISIONS §8 #7).
|
|
109
|
+
# Critical: enable JSON format or /search?format=json returns 403.
|
|
110
|
+
docker run -d --name searxng -p 8888:8080 \
|
|
111
|
+
-e SEARXNG_SECRET="$(openssl rand -hex 16)" \
|
|
112
|
+
-v "$PWD/searxng:/etc/searxng" \
|
|
113
|
+
searxng/searxng:latest
|
|
114
|
+
# In settings.yml: search.formats: [html, json]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Queries still leave the box through upstream engines (Serper → Google; or
|
|
118
|
+
DDG/Google/Bing via SearXNG / browser39). The no-cloud-LLM claim is about the
|
|
119
|
+
agent loop, not SERP egress.
|
|
45
120
|
|
|
46
121
|
## Egress note (S6)
|
|
47
122
|
|
|
48
|
-
SearXNG still
|
|
49
|
-
|
|
50
|
-
discovery results are candidates, gated when fetched.
|
|
123
|
+
Serper / SearXNG / browser39 still egress to upstream engines. The allowlist
|
|
124
|
+
covers **fetch** only — discovery results are candidates, gated when fetched.
|
|
51
125
|
|
|
52
126
|
## Build / test
|
|
53
127
|
|
|
54
128
|
```
|
|
55
129
|
npm run build # lib/index.js (host) + lib/discovery.mjs (core) + lib/client.js (no-op)
|
|
56
|
-
npm test # hermetic smoke (stub SearXNG + fake browser39
|
|
130
|
+
npm test # hermetic smoke (stub Serper + stub SearXNG + fake browser39; no live Serper)
|
|
57
131
|
```
|