dsh-web-discovery 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/cordis.patch.yml +6 -0
- package/lib/client.js +33 -0
- package/lib/client.js.map +7 -0
- package/lib/discovery.mjs +410 -0
- package/lib/discovery.mjs.map +7 -0
- package/lib/index.js +542 -0
- package/lib/index.js.map +7 -0
- package/package.json +66 -4
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,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-web-discovery
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Discovery companion for **[`dsh-web-missions`](https://github.com/janpauldahlke/dsh-web-missions)**
|
|
4
|
+
(npm: `dsh-web-missions`). Happy-path opener for web research missions:
|
|
5
|
+
the model gets candidate URLs from **local** search engines, encapsulated in
|
|
6
|
+
their own package — the mission core only sees **URLs in / URLs out**.
|
|
7
|
+
|
|
8
|
+
Agent/dev handover: see **`HANDOVER.md`**. Publish/curate this package on npm
|
|
9
|
+
and pin the profile to a known-good version alongside missions.
|
|
10
|
+
|
|
11
|
+
Two engines, both local, both optional (D-M7.2):
|
|
12
|
+
|
|
13
|
+
| Engine | Transport | Config |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| **SearXNG** | HTTP JSON — `GET {endpoint}/search?q=…&format=json` → `results[{url,title,content}]` | `searxng_endpoint` (default `http://127.0.0.1:8888/searxng` — not :8080, that port is llama) |
|
|
16
|
+
| **`browser39 search`** | CLI — `browser39 search <q> --output json --no-persist` (fetch-shaped SERP page; DDG `uddg` redirect unwrap) | `browser39_bin` (default `browser39`; `BROWSER39_BIN` override) |
|
|
17
|
+
|
|
18
|
+
**Missing discovery is a supported state** (D-M7.3): no SearXNG running + no
|
|
19
|
+
browser39 binary → the tool returns `no_engine` and the mission core degrades
|
|
20
|
+
to fixtures / human-supplied URLs. No DIY SERP scraping in our code (Eris
|
|
21
|
+
scar, D4).
|
|
22
|
+
|
|
23
|
+
## The one tool
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
discovery_search { query, engine?, limit?, mission_id?, cwd? }
|
|
27
|
+
→ { ok: true, query, engine, count, urls: [{ url, title?, snippet? }],
|
|
28
|
+
recorded: "<mission_id>/discovery.json" | null }
|
|
29
|
+
| { ok: false, error: "no_engine: …" | "search_failed: …" | "unknown_mission: …" }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `engine` pins `searxng` or `browser39`; omitted = auto (searxng first, then
|
|
33
|
+
browser39 — first engine that answers wins).
|
|
34
|
+
- With `mission_id`, hits are recorded into
|
|
35
|
+
`<cwd>/.dsh/web-missions/<mission_id>/discovery.json` (one-way bridge:
|
|
36
|
+
companion writes, the core surfaces it on `mission_status`). Discovered
|
|
37
|
+
URLs are **not ledger rows** (D-M7.4) — they become rows only when the
|
|
38
|
+
core fetches them, through the allowlist gate.
|
|
39
|
+
|
|
40
|
+
## Config (per cwd, at tool-call time)
|
|
41
|
+
|
|
42
|
+
`<cwd>/.dsh/web-discovery/config.json` (optional; corrupt = fail loud),
|
|
43
|
+
env overrides win: `SEARXNG_ENDPOINT`, `BROWSER39_BIN`. A knob set to the
|
|
44
|
+
empty string disables that engine.
|
|
45
|
+
|
|
46
|
+
## Egress note (S6)
|
|
47
|
+
|
|
48
|
+
SearXNG still egresses to upstream engines (Google/Bing/DDG). The no-cloud-LLM
|
|
49
|
+
claim is untouched (no LLM in the loop); the allowlist covers **fetch** only —
|
|
50
|
+
discovery results are candidates, gated when fetched.
|
|
51
|
+
|
|
52
|
+
## Build / test
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
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 CLI, no network)
|
|
57
|
+
```
|
package/cordis.patch.yml
ADDED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// src/host/discovery-port.ts
|
|
2
|
+
var DISCOVERY_ENGINES = ["searxng", "browser39"];
|
|
3
|
+
var DiscoveryEngineError = class extends Error {
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "DiscoveryEngineError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/host/engines/searxng.ts
|
|
12
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
13
|
+
var DEFAULT_LIMIT = 10;
|
|
14
|
+
function asString(v) {
|
|
15
|
+
return typeof v === "string" && v.trim() !== "" ? v : void 0;
|
|
16
|
+
}
|
|
17
|
+
function mapSearxngRow(row) {
|
|
18
|
+
const url = asString(row.url);
|
|
19
|
+
if (!url) return null;
|
|
20
|
+
let isHttp = false;
|
|
21
|
+
try {
|
|
22
|
+
const u = new URL(url);
|
|
23
|
+
isHttp = u.protocol === "http:" || u.protocol === "https:";
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!isHttp) return null;
|
|
28
|
+
const hit = { url };
|
|
29
|
+
const title = asString(row.title);
|
|
30
|
+
if (title) hit.title = title;
|
|
31
|
+
const snippet = asString(row.content);
|
|
32
|
+
if (snippet) hit.snippet = snippet;
|
|
33
|
+
return hit;
|
|
34
|
+
}
|
|
35
|
+
function createSearxngEngine(opts) {
|
|
36
|
+
const endpoint = opts.endpoint.replace(/\/+$/, "");
|
|
37
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
38
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
39
|
+
return {
|
|
40
|
+
kind: "searxng",
|
|
41
|
+
async search(query, searchOpts = {}) {
|
|
42
|
+
if (!endpoint) {
|
|
43
|
+
throw new DiscoveryEngineError("searxng_unreachable", "searxng endpoint is not configured");
|
|
44
|
+
}
|
|
45
|
+
const limit = searchOpts.limit ?? DEFAULT_LIMIT;
|
|
46
|
+
const qs = new URLSearchParams({ q: query, format: "json" });
|
|
47
|
+
const res = await fetchImpl(`${endpoint}/search?${qs.toString()}`, {
|
|
48
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
49
|
+
headers: { accept: "application/json" }
|
|
50
|
+
}).catch((error) => {
|
|
51
|
+
throw new DiscoveryEngineError(
|
|
52
|
+
"searxng_unreachable",
|
|
53
|
+
`searxng unreachable at ${endpoint}: ${error instanceof Error ? error.message : String(error)}`
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
throw new DiscoveryEngineError("searxng_unreachable", `searxng ${res.status} at ${endpoint}`);
|
|
58
|
+
}
|
|
59
|
+
let body;
|
|
60
|
+
try {
|
|
61
|
+
body = await res.json();
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new DiscoveryEngineError(
|
|
64
|
+
"searxng_unreachable",
|
|
65
|
+
`searxng replied non-JSON from ${endpoint}: ${error instanceof Error ? error.message : String(error)}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const results = body?.results;
|
|
69
|
+
if (!Array.isArray(results)) {
|
|
70
|
+
throw new DiscoveryEngineError("searxng_unreachable", `searxng reply has no results[] from ${endpoint}`);
|
|
71
|
+
}
|
|
72
|
+
const hits = [];
|
|
73
|
+
for (const row of results) {
|
|
74
|
+
const hit = mapSearxngRow(row);
|
|
75
|
+
if (hit) hits.push(hit);
|
|
76
|
+
if (hits.length >= limit) break;
|
|
77
|
+
}
|
|
78
|
+
return hits;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/host/engines/browser39.ts
|
|
84
|
+
import { execFile } from "node:child_process";
|
|
85
|
+
function defaultRunner(timeoutMs) {
|
|
86
|
+
return (bin, args) => new Promise((resolve) => {
|
|
87
|
+
execFile(
|
|
88
|
+
bin,
|
|
89
|
+
args,
|
|
90
|
+
{ timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, windowsHide: true },
|
|
91
|
+
(error, stdout, stderr) => {
|
|
92
|
+
if (error) {
|
|
93
|
+
const status = error.status;
|
|
94
|
+
resolve({
|
|
95
|
+
code: typeof status === "number" ? status : -1,
|
|
96
|
+
stdout: String(stdout ?? ""),
|
|
97
|
+
stderr: String(stderr ?? ""),
|
|
98
|
+
spawnError: error.code ?? (error instanceof Error ? error.name : void 0)
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
resolve({ code: 0, stdout: String(stdout ?? ""), stderr: String(stderr ?? "") });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
108
|
+
var DEFAULT_LIMIT2 = 10;
|
|
109
|
+
var SERP_CHROME_HOST = "duckduckgo.com";
|
|
110
|
+
function unwrapSerpHref(href) {
|
|
111
|
+
let u;
|
|
112
|
+
try {
|
|
113
|
+
u = new URL(href);
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") return null;
|
|
118
|
+
if (u.hostname.toLowerCase() !== SERP_CHROME_HOST) return u.toString();
|
|
119
|
+
if (u.pathname !== "/l/") return null;
|
|
120
|
+
const target = u.searchParams.get("uddg");
|
|
121
|
+
if (!target) return null;
|
|
122
|
+
let t;
|
|
123
|
+
try {
|
|
124
|
+
t = new URL(target);
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (t.protocol !== "http:" && t.protocol !== "https:") return null;
|
|
129
|
+
if (t.hostname.toLowerCase() === SERP_CHROME_HOST) return null;
|
|
130
|
+
return t.toString();
|
|
131
|
+
}
|
|
132
|
+
function mapSerpPage(page, limit) {
|
|
133
|
+
const links = Array.isArray(page.links) ? page.links : [];
|
|
134
|
+
const seen = /* @__PURE__ */ new Set();
|
|
135
|
+
const hits = [];
|
|
136
|
+
for (const link of links) {
|
|
137
|
+
if (hits.length >= limit) break;
|
|
138
|
+
const href = typeof link.href === "string" ? link.href : "";
|
|
139
|
+
const url = unwrapSerpHref(href);
|
|
140
|
+
if (!url) continue;
|
|
141
|
+
const key = url.toLowerCase();
|
|
142
|
+
if (seen.has(key)) continue;
|
|
143
|
+
seen.add(key);
|
|
144
|
+
const hit = { url };
|
|
145
|
+
const title = typeof link.text === "string" && link.text.trim() !== "" ? link.text.trim() : void 0;
|
|
146
|
+
if (title) hit.title = title;
|
|
147
|
+
hits.push(hit);
|
|
148
|
+
}
|
|
149
|
+
return hits;
|
|
150
|
+
}
|
|
151
|
+
function createBrowser39Engine(opts) {
|
|
152
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
153
|
+
const runner = opts.runner ?? defaultRunner(timeoutMs);
|
|
154
|
+
return {
|
|
155
|
+
kind: "browser39",
|
|
156
|
+
async search(query, searchOpts = {}) {
|
|
157
|
+
const limit = searchOpts.limit ?? DEFAULT_LIMIT2;
|
|
158
|
+
let result;
|
|
159
|
+
try {
|
|
160
|
+
result = await runner(opts.bin, ["search", query, "--output", "json", "--no-persist"]);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
throw new DiscoveryEngineError(
|
|
163
|
+
"browser39_missing",
|
|
164
|
+
`browser39 search failed to run: ${error instanceof Error ? error.message : String(error)}`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const spawnError = result.spawnError;
|
|
168
|
+
if (spawnError === "ENOENT" || spawnError === void 0 && result.code === -1 && result.stdout === "" && result.stderr !== "" && /ENOENT/.test(result.stderr)) {
|
|
169
|
+
throw new DiscoveryEngineError("browser39_missing", `browser39 binary not found: ${opts.bin}`);
|
|
170
|
+
}
|
|
171
|
+
if (result.code !== 0) {
|
|
172
|
+
const tail = result.stderr.trim().split("\n").slice(-3).join(" ");
|
|
173
|
+
throw new DiscoveryEngineError("browser39_failed", `browser39 search exited ${result.code}: ${tail || "no stderr"}`);
|
|
174
|
+
}
|
|
175
|
+
let page;
|
|
176
|
+
try {
|
|
177
|
+
page = JSON.parse(result.stdout);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw new DiscoveryEngineError(
|
|
180
|
+
"browser39_failed",
|
|
181
|
+
`browser39 search returned non-JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (page === null || typeof page !== "object") {
|
|
185
|
+
throw new DiscoveryEngineError("browser39_failed", "browser39 search returned a non-object reply");
|
|
186
|
+
}
|
|
187
|
+
const status = typeof page.status === "number" ? page.status : 200;
|
|
188
|
+
if (status === 202 || status < 200 || status >= 300) {
|
|
189
|
+
throw new DiscoveryEngineError(
|
|
190
|
+
"browser39_blocked",
|
|
191
|
+
`browser39 search blocked by the search engine (HTTP ${status} \u2014 bot challenge or rate limit); retry later or use another engine`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return mapSerpPage(page, limit);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/host/discovery-tool.ts
|
|
200
|
+
function engineReason(kind, error) {
|
|
201
|
+
switch (error.code) {
|
|
202
|
+
case "searxng_unreachable":
|
|
203
|
+
return "searxng not running at the configured endpoint";
|
|
204
|
+
case "browser39_missing":
|
|
205
|
+
return "browser39 search binary not found";
|
|
206
|
+
case "browser39_blocked":
|
|
207
|
+
return "browser39 blocked by the search engine (bot challenge / rate limit)";
|
|
208
|
+
default:
|
|
209
|
+
return `${kind} engine error (${error.code})`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function runDiscoverySearch(deps, rawQuery, opts = {}) {
|
|
213
|
+
const query = rawQuery.trim();
|
|
214
|
+
if (!query) {
|
|
215
|
+
return { ok: false, error: "query_required: pass a non-empty search query" };
|
|
216
|
+
}
|
|
217
|
+
const limit = opts.limit ?? 10;
|
|
218
|
+
const candidates = opts.engine ? [opts.engine] : DISCOVERY_ENGINES.filter((k) => deps.engines[k] !== void 0);
|
|
219
|
+
if (candidates.length === 0) {
|
|
220
|
+
return {
|
|
221
|
+
ok: false,
|
|
222
|
+
error: "no_engine: no discovery engines configured (searxng endpoint not configured; browser39 search not configured) \u2014 missing discovery is a supported state; supply URLs directly (fixtures or manual)"
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const failures = [];
|
|
226
|
+
for (const kind of candidates) {
|
|
227
|
+
const engine = deps.engines[kind];
|
|
228
|
+
if (!engine) {
|
|
229
|
+
failures.push(
|
|
230
|
+
kind === "searxng" ? "searxng endpoint not configured" : "browser39 search not configured"
|
|
231
|
+
);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const urls = await engine.search(query, { limit });
|
|
236
|
+
return { ok: true, query, engine: engine.kind, count: urls.length, urls };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (error instanceof DiscoveryEngineError && (error.code === "searxng_unreachable" || error.code === "browser39_missing" || error.code === "browser39_blocked")) {
|
|
239
|
+
failures.push(engineReason(engine.kind, error));
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (error instanceof DiscoveryEngineError && error.code === "browser39_failed") {
|
|
243
|
+
return { ok: false, error: `search_failed: ${error.message}` };
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
error: `search_failed: ${error instanceof Error ? error.message : String(error)}`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const reason = candidates.length === 1 && opts.engine ? `${opts.engine}: ${failures[0] ?? "unavailable"}` : failures.join("; ");
|
|
252
|
+
return { ok: false, error: `no_engine: ${reason} \u2014 missing discovery is a supported state; supply URLs directly (fixtures or manual)` };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/host/discovery-store.ts
|
|
256
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
257
|
+
import { dirname, join } from "node:path";
|
|
258
|
+
var DISCOVERY_FILENAME = "discovery.json";
|
|
259
|
+
var DiscoveryStoreError = class extends Error {
|
|
260
|
+
constructor(code, message) {
|
|
261
|
+
super(message);
|
|
262
|
+
this.code = code;
|
|
263
|
+
this.name = "DiscoveryStoreError";
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
function discoveryPath(missionDir) {
|
|
267
|
+
return join(missionDir, DISCOVERY_FILENAME);
|
|
268
|
+
}
|
|
269
|
+
function readDiscoveryFile(missionDir) {
|
|
270
|
+
const path = discoveryPath(missionDir);
|
|
271
|
+
let raw;
|
|
272
|
+
try {
|
|
273
|
+
raw = readFileSync(path, "utf8");
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (error.code === "ENOENT") return null;
|
|
276
|
+
throw new DiscoveryStoreError("discovery_unwritable", `cannot read ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
const parsed = JSON.parse(raw);
|
|
280
|
+
if (parsed === null || typeof parsed !== "object" || !Array.isArray(parsed.urls) || typeof parsed.updated_at !== "string") {
|
|
281
|
+
throw new Error("bad shape");
|
|
282
|
+
}
|
|
283
|
+
return parsed;
|
|
284
|
+
} catch (error) {
|
|
285
|
+
throw new DiscoveryStoreError("discovery_corrupt", `${path} is not valid discovery.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function recordDiscovery(missionDir, hits, via) {
|
|
289
|
+
const at = via.at ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
290
|
+
if (typeof at !== "string" || at.length === 0) {
|
|
291
|
+
throw new DiscoveryStoreError("bad_provenance", `via.at must be an ISO timestamp string (got ${String(via.at)})`);
|
|
292
|
+
}
|
|
293
|
+
const file = readDiscoveryFile(missionDir) ?? { updated_at: at, urls: [] };
|
|
294
|
+
const seen = new Set(file.urls.map((u) => u.url.toLowerCase()));
|
|
295
|
+
for (const hit of hits) {
|
|
296
|
+
const key = hit.url.toLowerCase();
|
|
297
|
+
if (seen.has(key)) continue;
|
|
298
|
+
seen.add(key);
|
|
299
|
+
file.urls.push({ ...hit, via: { ...via, at } });
|
|
300
|
+
}
|
|
301
|
+
file.updated_at = at;
|
|
302
|
+
const path = discoveryPath(missionDir);
|
|
303
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
304
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
305
|
+
try {
|
|
306
|
+
writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
|
|
307
|
+
renameSync(tmp, path);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
throw new DiscoveryStoreError("discovery_unwritable", `cannot write ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
310
|
+
}
|
|
311
|
+
return file;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/host/config.ts
|
|
315
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
316
|
+
import { join as join2 } from "node:path";
|
|
317
|
+
var CONFIG_DIR = "web-discovery";
|
|
318
|
+
var CONFIG_FILENAME = "config.json";
|
|
319
|
+
var DEFAULT_SEARXNG_ENDPOINT = "http://127.0.0.1:8888/searxng";
|
|
320
|
+
var DEFAULT_BROWSER39_BIN = "browser39";
|
|
321
|
+
var DEFAULT_CONFIG = {
|
|
322
|
+
searxngEndpoint: DEFAULT_SEARXNG_ENDPOINT,
|
|
323
|
+
browser39Bin: DEFAULT_BROWSER39_BIN
|
|
324
|
+
};
|
|
325
|
+
var DiscoveryConfigError = class extends Error {
|
|
326
|
+
constructor(code, message) {
|
|
327
|
+
super(message);
|
|
328
|
+
this.code = code;
|
|
329
|
+
this.name = "DiscoveryConfigError";
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var FIELDS = [
|
|
333
|
+
{ key: "searxngEndpoint", kind: "string" },
|
|
334
|
+
{ key: "browser39Bin", kind: "string" }
|
|
335
|
+
];
|
|
336
|
+
function configPath(cwd) {
|
|
337
|
+
return join2(cwd, ".dsh", CONFIG_DIR, CONFIG_FILENAME);
|
|
338
|
+
}
|
|
339
|
+
function readDiscoveryConfig(cwd, env = process.env) {
|
|
340
|
+
let file = {};
|
|
341
|
+
const path = configPath(cwd);
|
|
342
|
+
try {
|
|
343
|
+
const raw = readFileSync2(path, "utf8");
|
|
344
|
+
const parsed = JSON.parse(raw);
|
|
345
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
346
|
+
throw new DiscoveryConfigError("config_corrupt", `${path} must be a JSON object`);
|
|
347
|
+
}
|
|
348
|
+
file = parsed;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (error.code === "ENOENT") {
|
|
351
|
+
} else if (error instanceof DiscoveryConfigError) {
|
|
352
|
+
throw error;
|
|
353
|
+
} else {
|
|
354
|
+
throw new DiscoveryConfigError(
|
|
355
|
+
"config_corrupt",
|
|
356
|
+
`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const config = { ...DEFAULT_CONFIG };
|
|
361
|
+
for (const spec of FIELDS) {
|
|
362
|
+
if (spec.key in file) {
|
|
363
|
+
const value = file[spec.key];
|
|
364
|
+
if (typeof value !== "string") {
|
|
365
|
+
throw new DiscoveryConfigError(
|
|
366
|
+
"config_corrupt",
|
|
367
|
+
`${path}: ${spec.key} must be a string`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
config[spec.key] = value;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const endpoint = env.SEARXNG_ENDPOINT;
|
|
374
|
+
if (endpoint !== void 0) config.searxngEndpoint = endpoint;
|
|
375
|
+
const bin = env.BROWSER39_BIN;
|
|
376
|
+
if (bin !== void 0) config.browser39Bin = bin;
|
|
377
|
+
return config;
|
|
378
|
+
}
|
|
379
|
+
function enginesForConfig(config) {
|
|
380
|
+
return {
|
|
381
|
+
searxng: config.searxngEndpoint.trim() !== "",
|
|
382
|
+
browser39: config.browser39Bin.trim() !== ""
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
export {
|
|
386
|
+
CONFIG_DIR,
|
|
387
|
+
CONFIG_FILENAME,
|
|
388
|
+
DEFAULT_BROWSER39_BIN,
|
|
389
|
+
DEFAULT_CONFIG,
|
|
390
|
+
DEFAULT_SEARXNG_ENDPOINT,
|
|
391
|
+
DISCOVERY_ENGINES,
|
|
392
|
+
DISCOVERY_FILENAME,
|
|
393
|
+
DiscoveryConfigError,
|
|
394
|
+
DiscoveryEngineError,
|
|
395
|
+
DiscoveryStoreError,
|
|
396
|
+
configPath,
|
|
397
|
+
createBrowser39Engine,
|
|
398
|
+
createSearxngEngine,
|
|
399
|
+
defaultRunner,
|
|
400
|
+
discoveryPath,
|
|
401
|
+
enginesForConfig,
|
|
402
|
+
mapSearxngRow,
|
|
403
|
+
mapSerpPage,
|
|
404
|
+
readDiscoveryConfig,
|
|
405
|
+
readDiscoveryFile,
|
|
406
|
+
recordDiscovery,
|
|
407
|
+
runDiscoverySearch,
|
|
408
|
+
unwrapSerpHref
|
|
409
|
+
};
|
|
410
|
+
//# sourceMappingURL=discovery.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/host/discovery-port.ts", "../src/host/engines/searxng.ts", "../src/host/engines/browser39.ts", "../src/host/discovery-tool.ts", "../src/host/discovery-store.ts", "../src/host/config.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * DiscoveryPort (D-M7.1): the named port the companion hides both engines\n * behind. The mission core never calls an engine \u2014 it only sees URLs in /\n * URLs out (plan/M_7_discovery.md \"Companion shape\").\n *\n * Engines are OPTIONAL (D-M7.2): no SearXNG running, no `browser39 search`\n * binary \u2192 the port reports `no_engine` (D-M7.3), a supported state, not a\n * failure. The core degrades to fixtures / human-supplied URLs.\n */\n\n/** One discovered URL (D-M7.1 shape: `{url, title?, snippet?}`). */\nexport interface DiscoveryHit {\n url: string\n title?: string\n snippet?: string\n}\n\nexport type DiscoveryEngineKind = 'searxng' | 'browser39'\n\nexport const DISCOVERY_ENGINES: readonly DiscoveryEngineKind[] = ['searxng', 'browser39']\n\nexport interface SearchOptions {\n /** Max results to return (default 10). */\n limit?: number\n /** Pin one engine; absent = auto (try searxng, then browser39). */\n engine?: DiscoveryEngineKind\n}\n\n/** A concrete local engine. `search` resolves to 0..n hits (empty = no\n * results, NOT no_engine \u2014 the engine was reachable and said \"nothing\"). */\nexport interface DiscoveryEngine {\n readonly kind: DiscoveryEngineKind\n search(query: string, opts?: SearchOptions): Promise<DiscoveryHit[]>\n}\n\n/** The port shape as consumed by (future) mission-core integrations. */\nexport interface DiscoveryPort {\n search(query: string, opts?: SearchOptions): Promise<DiscoveryHit[]>\n}\n\nexport type DiscoveryErrorCode =\n /** No engine available (SearXNG unreachable / absent, browser39 binary missing). Supported state. */\n | 'no_engine'\n /** SearXNG endpoint configured but nothing answers (maps to no_engine at the tool layer). */\n | 'searxng_unreachable'\n /** browser39 binary not found (maps to no_engine at the tool layer). */\n | 'browser39_missing'\n /** browser39 binary exists but the search failed (network, engine error) \u2014 NOT no_engine. */\n | 'browser39_failed'\n /** The search engine blocked the request (e.g. DDG bot challenge \u2014 the CLI\n * reports HTTP 202 with no results). Engine-availability failure \u2192 maps to\n * no_engine at the tool layer (fall through / next engine), not search_failed. */\n | 'browser39_blocked'\n\n/** Engine-level failure with a stable code (never thrown into the tool layer\n * unrendered \u2014 the tool maps it to the `{ ok: false, error }` contract). */\nexport class DiscoveryEngineError extends Error {\n constructor(\n readonly code: DiscoveryErrorCode,\n message: string,\n ) {\n super(message)\n this.name = 'DiscoveryEngineError'\n }\n}\n", "/**\n * SearXNG engine (D-M7.2, engine 1): self-hosted SearXNG, HTTP JSON API.\n *\n * Query: GET {endpoint}/search?q=<query>&format=json\n * Reply: { query, results: [{ url, title, content, engine, category, score, \u2026 }], \u2026 }\n *\n * `endpoint` is the instance base INCLUDING any path prefix (default\n * `http://127.0.0.1:8888/searxng` \u2014 NOT :8080, that port is llama; the\n * operator hand-sets a different instance in ENV.md). The engine is *still\n * egress to upstream engines* (SearXNG fans out to Google/Bing/DDG, S6):\n * results are CANDIDATES \u2014 every candidate still passes the mission core's\n * allowlist gate when fetched.\n *\n * Absence = supported state: unreachable endpoint / non-JSON reply /\n * non-2xx \u2192 `searxng_unreachable` (the tool layer reports `no_engine`).\n * Reachable-but-empty \u2192 `[]` (the engine answered \"nothing\").\n *\n * Pure: the fetch implementation is injected (the smoke drives a local\n * stub speaking the real API shape \u2014 no network, no container).\n */\nimport { DiscoveryEngineError, type DiscoveryEngine, type DiscoveryHit, type SearchOptions } from '../discovery-port.ts'\n\nexport interface SearxngEngineOptions {\n /** Instance base incl. path prefix, e.g. `http://127.0.0.1:8888/searxng`. */\n endpoint: string\n /** Injectable fetch (default: globalThis.fetch). */\n fetchImpl?: typeof fetch\n /** Per-query timeout in ms (default 10000). */\n timeoutMs?: number\n}\n\nconst DEFAULT_TIMEOUT_MS = 10_000\nconst DEFAULT_LIMIT = 10\n\ninterface SearxngResultRow {\n url?: unknown\n title?: unknown\n content?: unknown\n}\n\nfunction asString(v: unknown): string | undefined {\n return typeof v === 'string' && v.trim() !== '' ? v : undefined\n}\n\n/** Map one SearXNG result row to the DiscoveryPort hit shape (skips rows\n * without an http(s) url). */\nexport function mapSearxngRow(row: SearxngResultRow): DiscoveryHit | null {\n const url = asString(row.url)\n if (!url) return null\n let isHttp = false\n try {\n const u = new URL(url)\n isHttp = u.protocol === 'http:' || u.protocol === 'https:'\n } catch {\n return null\n }\n if (!isHttp) return null\n const hit: DiscoveryHit = { url }\n const title = asString(row.title)\n if (title) hit.title = title\n const snippet = asString(row.content)\n if (snippet) hit.snippet = snippet\n return hit\n}\n\nexport function createSearxngEngine(opts: SearxngEngineOptions): DiscoveryEngine {\n const endpoint = opts.endpoint.replace(/\\/+$/, '')\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const fetchImpl = opts.fetchImpl ?? fetch\n\n return {\n kind: 'searxng',\n async search(query: string, searchOpts: SearchOptions = {}): Promise<DiscoveryHit[]> {\n if (!endpoint) {\n throw new DiscoveryEngineError('searxng_unreachable', 'searxng endpoint is not configured')\n }\n const limit = searchOpts.limit ?? DEFAULT_LIMIT\n const qs = new URLSearchParams({ q: query, format: 'json' })\n const res = await fetchImpl(`${endpoint}/search?${qs.toString()}`, {\n signal: AbortSignal.timeout(timeoutMs),\n headers: { accept: 'application/json' },\n }).catch((error: unknown) => {\n throw new DiscoveryEngineError(\n 'searxng_unreachable',\n `searxng unreachable at ${endpoint}: ${error instanceof Error ? error.message : String(error)}`,\n )\n })\n if (!res.ok) {\n throw new DiscoveryEngineError('searxng_unreachable', `searxng ${res.status} at ${endpoint}`)\n }\n let body: unknown\n try {\n body = await res.json()\n } catch (error) {\n throw new DiscoveryEngineError(\n 'searxng_unreachable',\n `searxng replied non-JSON from ${endpoint}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n const results = (body as { results?: unknown })?.results\n if (!Array.isArray(results)) {\n throw new DiscoveryEngineError('searxng_unreachable', `searxng reply has no results[] from ${endpoint}`)\n }\n const hits: DiscoveryHit[] = []\n for (const row of results as SearxngResultRow[]) {\n const hit = mapSearxngRow(row)\n if (hit) hits.push(hit)\n if (hits.length >= limit) break\n }\n return hits\n },\n }\n}\n", "/**\n * browser39-search engine (D-M7.2, engine 2): the `browser39 search` CLI,\n * same JSON transport family as the fetcher (local CLI \u2192 JSON, S1).\n *\n * Probed live (2026-10-13, @aquintanar/browser39@2.0.0):\n * browser39 search <query> --output json --no-persist\n * emits ONE JSON object \u2014 a FETCH-SHAPED page of the SERP, not a structured\n * result list:\n * { url, title, status, markdown, links: [{ i, text, href }] }\n * The actual results are the SERP anchor links. With the default DuckDuckGo\n * backend the hrefs are redirect wrappers:\n * https://duckduckgo.com/l/?uddg=<urlencoded target>&rut=<token>\n * so the adapter must unwrap `uddg` to the real target URL (Eris scar: the\n * unwrap is a query-param read, never HTML scraping \u2014 D4).\n *\n * Mapping rules (deterministic):\n * - keep links with an absolute http(s) href;\n * - `duckduckgo.com/l/` (and any `duckduckgo.com` site chrome) \u2192 unwrap the\n * `uddg` param to the target; skip if the target is missing/not http(s);\n * - skip targets whose host is the SERP engine's own host (duckduckgo.com) \u2014\n * those are chrome (logo, /html/, feedback), not results;\n * - title = the anchor text (the SERP result title);\n * - snippet: the JSON reply carries none (markdown has titles + dates only)\n * \u2192 omitted;\n * - dedupe by lowercased url, first-seen wins; `limit` caps the output.\n *\n * Absence = supported state: binary missing (spawn ENOENT) \u2192\n * `browser39_missing`; present but non-zero exit / non-JSON \u2192\n * `browser39_failed` (a query failure, NOT no_engine).\n *\n * Pure: the CLI runner is injected (the smoke drives a fake binary emitting\n * the captured reply shape \u2014 no network).\n */\nimport { execFile } from 'node:child_process'\nimport {\n DiscoveryEngineError,\n type DiscoveryEngine,\n type DiscoveryHit,\n type SearchOptions,\n} from '../discovery-port.ts'\n\nexport interface Browser39CliResult {\n code: number\n stdout: string\n stderr: string\n /** Set when the SPAWN itself failed (e.g. `ENOENT` = binary missing) \u2014\n * distinct from a spawn that ran and exited non-zero. */\n spawnError?: string\n}\n\nexport type Browser39Runner = (bin: string, args: string[]) => Promise<Browser39CliResult>\n\n/** Default runner: async execFile with a timeout; spawn errors (ENOENT =\n * binary missing) resolve to `{ code: -1, spawnError }`-style results so\n * the engine can distinguish missing-binary from failed-query. */\nexport function defaultRunner(timeoutMs: number): Browser39Runner {\n return (bin, args) =>\n new Promise<Browser39CliResult>((resolve) => {\n execFile(\n bin,\n args,\n { timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, windowsHide: true },\n (error, stdout, stderr) => {\n if (error) {\n const status = (error as { status?: number }).status\n resolve({\n code: typeof status === 'number' ? status : -1,\n stdout: String(stdout ?? ''),\n stderr: String(stderr ?? ''),\n spawnError: (error as NodeJS.ErrnoException).code ?? (error instanceof Error ? error.name : undefined),\n })\n } else {\n resolve({ code: 0, stdout: String(stdout ?? ''), stderr: String(stderr ?? '') })\n }\n },\n )\n })\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000\nconst DEFAULT_LIMIT = 10\nconst SERP_CHROME_HOST = 'duckduckgo.com'\n\nexport interface Browser39EngineOptions {\n /** Binary path (default 'browser39' \u2014 resolved on PATH by execFile; the\n * core's BROWSER39_BIN convention is honored at the config layer). */\n bin: string\n runner?: Browser39Runner\n timeoutMs?: number\n}\n\ninterface SerpLink {\n i?: unknown\n text?: unknown\n href?: unknown\n}\n\ninterface SerpPage {\n url?: unknown\n title?: unknown\n status?: unknown\n links?: unknown\n}\n\n/** Unwrap a SERP href to a candidate result URL, or null when it is not one:\n * relative/non-http hrefs \u2192 null; `duckduckgo.com/l/?uddg=\u2026` \u2192 the decoded\n * target (must be http(s)); `duckduckgo.com` site chrome (incl. a target\n * that decodes back to duckduckgo.com) \u2192 null; anything else \u2192 as-is. */\nexport function unwrapSerpHref(href: string): string | null {\n let u: URL\n try {\n u = new URL(href)\n } catch {\n return null\n }\n if (u.protocol !== 'http:' && u.protocol !== 'https:') return null\n if (u.hostname.toLowerCase() !== SERP_CHROME_HOST) return u.toString()\n // DDG host: only /l/ redirect wrappers with a valid uddg target count.\n if (u.pathname !== '/l/') return null\n const target = u.searchParams.get('uddg')\n if (!target) return null\n let t: URL\n try {\n t = new URL(target)\n } catch {\n return null\n }\n if (t.protocol !== 'http:' && t.protocol !== 'https:') return null\n if (t.hostname.toLowerCase() === SERP_CHROME_HOST) return null\n return t.toString()\n}\n\n/** Map a fetch-shaped SERP page to result hits (deduped, limited). Exported\n * for the smoke (pure, no I/O). */\nexport function mapSerpPage(page: SerpPage, limit: number): DiscoveryHit[] {\n const links = Array.isArray(page.links) ? (page.links as SerpLink[]) : []\n const seen = new Set<string>()\n const hits: DiscoveryHit[] = []\n for (const link of links) {\n if (hits.length >= limit) break\n const href = typeof link.href === 'string' ? link.href : ''\n const url = unwrapSerpHref(href)\n if (!url) continue\n const key = url.toLowerCase()\n if (seen.has(key)) continue\n seen.add(key)\n const hit: DiscoveryHit = { url }\n const title = typeof link.text === 'string' && link.text.trim() !== '' ? link.text.trim() : undefined\n if (title) hit.title = title\n hits.push(hit)\n }\n return hits\n}\n\nexport function createBrowser39Engine(opts: Browser39EngineOptions): DiscoveryEngine {\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS\n const runner = opts.runner ?? defaultRunner(timeoutMs)\n\n return {\n kind: 'browser39',\n async search(query: string, searchOpts: SearchOptions = {}): Promise<DiscoveryHit[]> {\n const limit = searchOpts.limit ?? DEFAULT_LIMIT\n let result: Browser39CliResult\n try {\n result = await runner(opts.bin, ['search', query, '--output', 'json', '--no-persist'])\n } catch (error) {\n throw new DiscoveryEngineError(\n 'browser39_missing',\n `browser39 search failed to run: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n const spawnError = result.spawnError\n if (spawnError === 'ENOENT' || (spawnError === undefined && result.code === -1 && result.stdout === '' && result.stderr !== '' && /ENOENT/.test(result.stderr))) {\n throw new DiscoveryEngineError('browser39_missing', `browser39 binary not found: ${opts.bin}`)\n }\n if (result.code !== 0) {\n const tail = result.stderr.trim().split('\\n').slice(-3).join(' ')\n throw new DiscoveryEngineError('browser39_failed', `browser39 search exited ${result.code}: ${tail || 'no stderr'}`)\n }\n let page: SerpPage\n try {\n page = JSON.parse(result.stdout) as SerpPage\n } catch (error) {\n throw new DiscoveryEngineError(\n 'browser39_failed',\n `browser39 search returned non-JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n if (page === null || typeof page !== 'object') {\n throw new DiscoveryEngineError('browser39_failed', 'browser39 search returned a non-object reply')\n }\n // The CLI's own structured status (the upstream engine's HTTP response).\n // A block \u2014 notably DDG's bot-challenge page, which answers HTTP 202\n // (\"select all squares containing a duck\", no result links) \u2014 must be a\n // loud failure so the tool layer falls through / reports no_engine,\n // never a silent 0-hit success. (We read the CLI's status field, not\n // the HTML.)\n const status = typeof page.status === 'number' ? page.status : 200\n if (status === 202 || status < 200 || status >= 300) {\n throw new DiscoveryEngineError(\n 'browser39_blocked',\n `browser39 search blocked by the search engine (HTTP ${status} \u2014 bot challenge or rate limit); retry later or use another engine`,\n )\n }\n return mapSerpPage(page, limit)\n },\n }\n}\n", "/**\n * Discovery tool logic (pure): engine selection + the no_engine contract\n * (D-M7.3).\n *\n * Selection:\n * - explicit `engine` pin \u2192 that engine only; absent or unreachable \u2192\n * `no_engine` (naming the engine + why).\n * - no pin \u2192 auto: try `searxng` then `browser39` (in that order, the ones\n * present in `deps.engines`); the first engine that answers wins. ALL of\n * them absent/unreachable \u2192 `no_engine` with the combined reasons.\n *\n * `no_engine` is a SUPPORTED STATE (missing discovery is fine \u2014 the core\n * degrades to fixtures/human-supplied URLs), so it renders as a clean\n * `{ ok: false, error: 'no_engine: \u2026' }`, never a crash. A pinned or\n * auto-selected engine that EXISTS but fails a query (browser39 non-zero\n * exit) surfaces as `search_failed: \u2026` \u2014 that is a query failure, not an\n * absent engine.\n */\nimport {\n DISCOVERY_ENGINES,\n DiscoveryEngineError,\n type DiscoveryEngine,\n type DiscoveryEngineKind,\n type DiscoveryHit,\n type SearchOptions,\n} from './discovery-port.ts'\n\nexport interface DiscoveryToolDeps {\n /** Engines present by config (endpoint configured / binary expected). */\n engines: Partial<Record<DiscoveryEngineKind, DiscoveryEngine>>\n}\n\nexport type DiscoveryToolResult =\n | { ok: true; query: string; engine: DiscoveryEngineKind; count: number; urls: DiscoveryHit[] }\n | { ok: false; error: string }\n\nfunction engineReason(kind: DiscoveryEngineKind, error: DiscoveryEngineError): string {\n switch (error.code) {\n case 'searxng_unreachable':\n return 'searxng not running at the configured endpoint'\n case 'browser39_missing':\n return 'browser39 search binary not found'\n case 'browser39_blocked':\n return 'browser39 blocked by the search engine (bot challenge / rate limit)'\n default:\n return `${kind} engine error (${error.code})`\n }\n}\n\nexport async function runDiscoverySearch(\n deps: DiscoveryToolDeps,\n rawQuery: string,\n opts: SearchOptions = {},\n): Promise<DiscoveryToolResult> {\n const query = rawQuery.trim()\n if (!query) {\n return { ok: false, error: 'query_required: pass a non-empty search query' }\n }\n const limit = opts.limit ?? 10\n\n const candidates: DiscoveryEngineKind[] = opts.engine\n ? [opts.engine]\n : DISCOVERY_ENGINES.filter((k) => deps.engines[k] !== undefined)\n\n if (candidates.length === 0) {\n return {\n ok: false,\n error:\n 'no_engine: no discovery engines configured ' +\n '(searxng endpoint not configured; browser39 search not configured) ' +\n '\u2014 missing discovery is a supported state; supply URLs directly (fixtures or manual)',\n }\n }\n\n const failures: string[] = []\n for (const kind of candidates) {\n const engine = deps.engines[kind]\n if (!engine) {\n failures.push(\n kind === 'searxng' ? 'searxng endpoint not configured' : 'browser39 search not configured',\n )\n continue\n }\n try {\n const urls = await engine.search(query, { limit })\n return { ok: true, query, engine: engine.kind, count: urls.length, urls }\n } catch (error) {\n if (\n error instanceof DiscoveryEngineError &&\n (error.code === 'searxng_unreachable' || error.code === 'browser39_missing' || error.code === 'browser39_blocked')\n ) {\n failures.push(engineReason(engine.kind, error))\n continue\n }\n if (error instanceof DiscoveryEngineError && error.code === 'browser39_failed') {\n return { ok: false, error: `search_failed: ${error.message}` }\n }\n // Unexpected engine-internal error \u2014 surface it, don't loop on it.\n return {\n ok: false,\n error: `search_failed: ${error instanceof Error ? error.message : String(error)}`,\n }\n }\n }\n\n const reason =\n candidates.length === 1 && opts.engine\n ? `${opts.engine}: ${failures[0] ?? 'unavailable'}`\n : failures.join('; ')\n return { ok: false, error: `no_engine: ${reason} \u2014 missing discovery is a supported state; supply URLs directly (fixtures or manual)` }\n}\n", "/**\n * Discovery ledger file (the bridge to the core's optional surface).\n *\n * The companion writes `<missionRoot>/<mission_id>/discovery.json` \u2014 data the\n * mission core SURFACES (a `discovery` object on mission_status, M7 7.2).\n * The core never calls an engine; this file is the only coupling, and it is\n * one-way: companion writes, core reads.\n *\n * D-M7.4: discovered URLs are NOT ledger rows \u2014 no manifest/fetched rows, no\n * pages/ artifacts, no budget here. They become rows only when the core\n * fetches them (through the allowlist gate).\n *\n * File shape (v0):\n * {\n * \"updated_at\": \"<ISO of the last record>\",\n * \"urls\": [\n * { \"url\": \"\u2026\", \"title?\": \"\u2026\", \"snippet?\": \"\u2026\",\n * \"via\": { \"query\": \"\u2026\", \"engine\": \"searxng|browser39\", \"at\": \"<ISO>\" } }\n * ]\n * }\n *\n * Record semantics: append new URLs (deduped case-insensitively,\n * first-seen provenance wins), refresh `updated_at`, rewrite atomically\n * (temp + rename, the core's fs discipline). Absent file = nothing\n * discovered yet. Corrupt file = fail loud (never guess over operator data).\n */\nimport { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport type { DiscoveryEngineKind, DiscoveryHit } from './discovery-port.ts'\n\nexport const DISCOVERY_FILENAME = 'discovery.json'\n\nexport interface DiscoveryProvenance {\n query: string\n engine: DiscoveryEngineKind\n at: string\n}\n\nexport interface DiscoveryUrlEntry extends DiscoveryHit {\n via: DiscoveryProvenance\n}\n\nexport interface DiscoveryFile {\n updated_at: string\n urls: DiscoveryUrlEntry[]\n}\n\nexport class DiscoveryStoreError extends Error {\n constructor(\n readonly code: 'unknown_mission' | 'discovery_corrupt' | 'discovery_unwritable' | 'bad_provenance',\n message: string,\n ) {\n super(message)\n this.name = 'DiscoveryStoreError'\n }\n}\n\nexport function discoveryPath(missionDir: string): string {\n return join(missionDir, DISCOVERY_FILENAME)\n}\n\n/** Read the discovery file for a mission dir; null when absent. Corrupt \u2192\n * DiscoveryStoreError (fail loud). */\nexport function readDiscoveryFile(missionDir: string): DiscoveryFile | null {\n const path = discoveryPath(missionDir)\n let raw: string\n try {\n raw = readFileSync(path, 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null\n throw new DiscoveryStoreError('discovery_unwritable', `cannot read ${path}: ${error instanceof Error ? error.message : String(error)}`)\n }\n try {\n const parsed = JSON.parse(raw) as unknown\n if (\n parsed === null ||\n typeof parsed !== 'object' ||\n !Array.isArray((parsed as DiscoveryFile).urls) ||\n typeof (parsed as DiscoveryFile).updated_at !== 'string'\n ) {\n throw new Error('bad shape')\n }\n return parsed as DiscoveryFile\n } catch (error) {\n throw new DiscoveryStoreError('discovery_corrupt', `${path} is not valid discovery.json: ${error instanceof Error ? error.message : String(error)}`)\n }\n}\n\n/** Merge `hits` (from one query) into the mission's discovery file and\n * return the written file. `missionDir` must exist (the core owns mission\n * dirs \u2014 unknown dir = unknown_mission, never created here). */\nexport function recordDiscovery(\n missionDir: string,\n hits: DiscoveryHit[],\n via: DiscoveryProvenance,\n): DiscoveryFile {\n // `updated_at` must always land as a string: the core REJECTS a discovery\n // file without one (fail loud), so a missing `via.at` falls back to now\n // (the record moment) instead of writing a file the core cannot read.\n const at = via.at ?? new Date().toISOString()\n if (typeof at !== 'string' || at.length === 0) {\n throw new DiscoveryStoreError('bad_provenance', `via.at must be an ISO timestamp string (got ${String(via.at)})`)\n }\n const file = readDiscoveryFile(missionDir) ?? { updated_at: at, urls: [] }\n const seen = new Set(file.urls.map((u) => u.url.toLowerCase()))\n for (const hit of hits) {\n const key = hit.url.toLowerCase()\n if (seen.has(key)) continue\n seen.add(key)\n file.urls.push({ ...hit, via: { ...via, at } })\n }\n file.updated_at = at\n const path = discoveryPath(missionDir)\n const tmp = `${path}.tmp-${process.pid}`\n mkdirSync(dirname(path), { recursive: true })\n try {\n writeFileSync(tmp, JSON.stringify(file, null, 2) + '\\n')\n renameSync(tmp, path)\n } catch (error) {\n throw new DiscoveryStoreError('discovery_unwritable', `cannot write ${path}: ${error instanceof Error ? error.message : String(error)}`)\n }\n return file\n}\n", "/**\n * Discovery config (companion's own knobs \u2014 the mission core carries NO\n * engine config; V5 encapsulation check).\n *\n * Source order (per cwd, resolved at tool-call time like the core):\n * 1. defaults below;\n * 2. `<cwd>/.dsh/web-discovery/config.json` \u2014 OPTIONAL file; every field\n * optional, merges over defaults; corrupt \u2192 fail loud (same discipline\n * as the core's config); unknown keys ignored;\n * 3. env overrides: SEARXNG_ENDPOINT, BROWSER39_BIN (same names the core\n * honors \u2014 one mechanism across the pair).\n *\n * A knob set to the EMPTY STRING disables that engine (the tool layer then\n * reports it as absent \u2192 no_engine).\n */\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport type { DiscoveryEngineKind } from './discovery-port.ts'\n\nexport interface DiscoveryConfig {\n /** SearXNG instance base incl. path prefix. NOT :8080 \u2014 that port is llama. */\n searxngEndpoint: string\n /** browser39 binary (path or PATH name). Empty = engine disabled. */\n browser39Bin: string\n}\n\nexport const CONFIG_DIR = 'web-discovery'\nexport const CONFIG_FILENAME = 'config.json'\n\n/** Plan default: self-hosted instance on this box (operator hand-sets in ENV.md). */\nexport const DEFAULT_SEARXNG_ENDPOINT = 'http://127.0.0.1:8888/searxng'\n/** Plan default: `browser39` on PATH (the core's BROWSER39_BIN override wins). */\nexport const DEFAULT_BROWSER39_BIN = 'browser39'\n\nexport const DEFAULT_CONFIG: DiscoveryConfig = {\n searxngEndpoint: DEFAULT_SEARXNG_ENDPOINT,\n browser39Bin: DEFAULT_BROWSER39_BIN,\n}\n\nexport class DiscoveryConfigError extends Error {\n constructor(\n readonly code: 'config_corrupt',\n message: string,\n ) {\n super(message)\n this.name = 'DiscoveryConfigError'\n }\n}\n\ntype FieldSpec =\n | { key: 'searxngEndpoint'; kind: 'string' }\n | { key: 'browser39Bin'; kind: 'string' }\n\nconst FIELDS: readonly FieldSpec[] = [\n { key: 'searxngEndpoint', kind: 'string' },\n { key: 'browser39Bin', kind: 'string' },\n]\n\nexport function configPath(cwd: string): string {\n return join(cwd, '.dsh', CONFIG_DIR, CONFIG_FILENAME)\n}\n\nexport function readDiscoveryConfig(cwd: string, env: NodeJS.ProcessEnv = process.env): DiscoveryConfig {\n let file: Record<string, unknown> = {}\n const path = configPath(cwd)\n try {\n const raw = readFileSync(path, 'utf8')\n const parsed: unknown = JSON.parse(raw)\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new DiscoveryConfigError('config_corrupt', `${path} must be a JSON object`)\n }\n file = parsed as Record<string, unknown>\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n // absent file = all defaults\n } else if (error instanceof DiscoveryConfigError) {\n throw error\n } else {\n throw new DiscoveryConfigError(\n 'config_corrupt',\n `${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n\n const config: DiscoveryConfig = { ...DEFAULT_CONFIG }\n for (const spec of FIELDS) {\n if (spec.key in file) {\n const value = file[spec.key]\n if (typeof value !== 'string') {\n throw new DiscoveryConfigError(\n 'config_corrupt',\n `${path}: ${spec.key} must be a string`,\n )\n }\n config[spec.key] = value\n }\n }\n // env overrides win over the file (operator can redirect without touching disk).\n const endpoint = env.SEARXNG_ENDPOINT\n if (endpoint !== undefined) config.searxngEndpoint = endpoint\n const bin = env.BROWSER39_BIN\n if (bin !== undefined) config.browser39Bin = bin\n return config\n}\n\nexport interface EnginePresence {\n searxng: boolean\n browser39: boolean\n}\n\n/** Which engines exist per config (empty string = disabled). */\nexport function enginesForConfig(config: DiscoveryConfig): EnginePresence {\n return {\n searxng: config.searxngEndpoint.trim() !== '',\n browser39: config.browser39Bin.trim() !== '',\n }\n}\n\nexport type { DiscoveryEngineKind }\n"],
|
|
5
|
+
"mappings": ";AAmBO,IAAM,oBAAoD,CAAC,WAAW,WAAW;AAqCjF,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,YACW,MACT,SACA;AACA,UAAM,OAAO;AAHJ;AAIT,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