dsh-web-discovery 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jan (HagbardCeline) / janpauldahlke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,131 @@
1
- # Temporary Holding Version
1
+ # dsh-web-discovery
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **URL supply is the scarce resource.** That is the conclusion of this project!!!
4
+
5
+ Discovery companion for **[`dsh-web-missions`](https://github.com/janpauldahlke/dsh-web-missions)**
6
+ (npm: `dsh-web-missions`). Happy-path opener for web research missions:
7
+ the model gets candidate URLs from search engines behind a DiscoveryPort —
8
+ the mission core only sees **URLs in / URLs out**.
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.
14
+
15
+ Three engines, all optional (D-M7.2 / P_08):
16
+
17
+ | Engine | Transport | Config |
18
+ | --- | --- | --- |
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) |
22
+
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
25
+ to fixtures / human-supplied URLs. No DIY SERP scraping in our code (Eris
26
+ scar, D4). Serper credits are scarce — hermetic tests never call the live API.
27
+
28
+ ## The one tool
29
+
30
+ ```
31
+ discovery_search { query, engine?, limit?, mission_id?, cwd? }
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: …" | … }
37
+ ```
38
+
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
44
+ `<cwd>/.dsh/web-missions/<mission_id>/discovery.json` (one-way bridge:
45
+ companion writes, the core surfaces it on `mission_status`). Discovered
46
+ URLs are **not ledger rows** (D-M7.4) — they become rows only when the
47
+ core fetches them, through the allowlist gate.
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
+
62
+ ## Config (per cwd, at tool-call time)
63
+
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 &lt;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.
120
+
121
+ ## Egress note (S6)
122
+
123
+ Serper / SearXNG / browser39 still egress to upstream engines. The allowlist
124
+ covers **fetch** only — discovery results are candidates, gated when fetched.
125
+
126
+ ## Build / test
127
+
128
+ ```
129
+ npm run build # lib/index.js (host) + lib/discovery.mjs (core) + lib/client.js (no-op)
130
+ npm test # hermetic smoke (stub Serper + stub SearXNG + fake browser39; no live Serper)
131
+ ```
@@ -0,0 +1,6 @@
1
+ # dsh-web-discovery layer: one Loader row for the companion package.
2
+ # Host half = package root export (lib/index.js); the client face is a no-op
3
+ # stub (M7 companion is tool-only) kept for C9 shape parity with the siblings.
4
+ - insert:
5
+ - id: dsh-web-discovery
6
+ name: dsh-web-discovery
package/lib/client.js ADDED
@@ -0,0 +1,33 @@
1
+ window.__ModuleLoader__.load({ id: "dsh-web-discovery", factory: (require) => {
2
+ var module = { exports: {} }; var exports = module.exports;
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/client/index.ts
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ apply: () => apply,
26
+ name: () => name
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var name = "dsh-web-discovery";
30
+ function apply(_ctx) {
31
+ }
32
+ return module.exports; } });
33
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/client/index.ts"],
4
+ "sourcesContent": ["/**\n * Browser half: intentional no-op. The M7 companion is tool-only (no pane).\n * Cordis still requires `name` + `apply` on every loaded plugin face \u2014\n * `export {}` alone \u2192 \"invalid plugin, expect \u2026 apply method\".\n */\nexport const name = 'dsh-web-discovery'\n\nexport function apply(_ctx: unknown): void {\n // no UI \u2014 host tools only\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,OAAO;AAEb,SAAS,MAAM,MAAqB;AAE3C;",
6
+ "names": []
7
+ }