@neottia/searchable-core 0.2.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/NOTICE.md +5 -0
- package/README.md +71 -0
- package/config.schema.json +246 -0
- package/dist/config.d.ts +423 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +343 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +41 -0
- package/dist/errors.js.map +1 -0
- package/dist/extraction-worker.d.ts +2 -0
- package/dist/extraction-worker.d.ts.map +1 -0
- package/dist/extraction-worker.js +38 -0
- package/dist/extraction-worker.js.map +1 -0
- package/dist/fetcher.d.ts +5 -0
- package/dist/fetcher.d.ts.map +1 -0
- package/dist/fetcher.js +173 -0
- package/dist/fetcher.js.map +1 -0
- package/dist/http.d.ts +54 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +372 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/migration-worker.d.ts +2 -0
- package/dist/migration-worker.d.ts.map +1 -0
- package/dist/migration-worker.js +60 -0
- package/dist/migration-worker.js.map +1 -0
- package/dist/migration.d.ts +19 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +221 -0
- package/dist/migration.js.map +1 -0
- package/dist/providers.d.ts +9 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +210 -0
- package/dist/providers.js.map +1 -0
- package/dist/redaction.d.ts +9 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +161 -0
- package/dist/redaction.js.map +1 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +205 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schemas.d.ts +49 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +64 -0
- package/dist/schemas.js.map +1 -0
- package/dist/services.d.ts +20 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +2 -0
- package/dist/services.js.map +1 -0
- package/dist/stash.d.ts +65 -0
- package/dist/stash.d.ts.map +1 -0
- package/dist/stash.js +490 -0
- package/dist/stash.js.map +1 -0
- package/dist/tool-contracts.d.ts +104 -0
- package/dist/tool-contracts.d.ts.map +1 -0
- package/dist/tool-contracts.js +71 -0
- package/dist/tool-contracts.js.map +1 -0
- package/dist/tools.d.ts +23 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +134 -0
- package/dist/tools.js.map +1 -0
- package/dist/utf8.d.ts +2 -0
- package/dist/utf8.d.ts.map +1 -0
- package/dist/utf8.js +14 -0
- package/dist/utf8.js.map +1 -0
- package/dist/worker.d.ts +12 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +45 -0
- package/dist/worker.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dragos Cirjan
|
|
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/NOTICE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Neottia Searchable includes code and behavior adapted from @dragoscirjan/mcp-searchable.
|
|
2
|
+
Copyright (c) 2025 Templ Project. Used under the MIT License.
|
|
3
|
+
|
|
4
|
+
Mozilla Readability is distributed as a dependency under the Apache License 2.0.
|
|
5
|
+
See https://github.com/mozilla/readability for its source and license.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @neottia/searchable-core
|
|
2
|
+
|
|
3
|
+
Search, fetch, stash, grep, and ask services for repository-local web research. The package provides the shared five-tool registry and a concrete runtime used by the MCP, Pi, and OpenCode packages.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @neottia/searchable-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Node.js 22.16 or newer is required. Canonical stash files and the SQLite FTS cache require a filesystem supported by `@neottia/repository-store`.
|
|
12
|
+
|
|
13
|
+
## Configure
|
|
14
|
+
|
|
15
|
+
Searchable contributes the canonical `modules.searchable` shard to `@neottia/config`. Hosts resolve the official registry once and pass the immutable shard to the runtime and tool context. `loadSearchableConfig()` remains available for standalone use and accepts the deprecated `skills.searchable` path.
|
|
16
|
+
|
|
17
|
+
See the [unified configuration guide](../../docs/configuration.md) for shared files, profiles, precedence, secret handling, diagnostics, and migration. Configuration resolves in this order: defaults, global file, project file, selected global profile, selected project profile, environment bindings, and explicit runtime overrides. The YAML root must contain `version: 1`.
|
|
18
|
+
|
|
19
|
+
Create `.neottia/config.yml` in the project working directory:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
version: 1
|
|
23
|
+
modules:
|
|
24
|
+
searchable:
|
|
25
|
+
enabled: true
|
|
26
|
+
search:
|
|
27
|
+
provider: duckduckgo
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
DuckDuckGo requires no key. Google needs `google_api_key` and `google_cse_id`; Bing and Brave need their API keys. YAML credential values must use exact `${ENV_NAME}` references. The resolver expands only the winning reference and redacts all provider credentials from snapshots, provenance, and diagnostics. Service endpoints must use HTTP or HTTPS and cannot contain user information, a query string, or a fragment. See [`config.schema.json`](./config.schema.json) for the complete standalone shard.
|
|
31
|
+
|
|
32
|
+
## Use the concrete runtime
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createSearchableRuntime, findSearchableTool } from "@neottia/searchable-core";
|
|
36
|
+
|
|
37
|
+
const runtime = createSearchableRuntime({ cwd: process.cwd() });
|
|
38
|
+
const search = findSearchableTool("web_search");
|
|
39
|
+
if (!search) throw new Error("web_search is not registered");
|
|
40
|
+
|
|
41
|
+
const result = await search.run({ cwd: process.cwd(), services: runtime }, { query: "Neottia documentation" });
|
|
42
|
+
console.log(result);
|
|
43
|
+
await runtime.close();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The shared registry exposes `web_search`, `web_fetch`, `web_stash`, `web_grep`, and `web_ask`. Inputs and outputs pass the same Zod contracts for every delivery package.
|
|
47
|
+
|
|
48
|
+
## Runtime behavior
|
|
49
|
+
|
|
50
|
+
- Search supports DuckDuckGo, Google Custom Search, Bing, and Brave.
|
|
51
|
+
- Fetch tries the configured `direct`, `jina`, and `wayback` strategies in order. Direct fetch blocks private and special-use destinations, validates redirects, and bounds decoded response bytes.
|
|
52
|
+
- Stash writes canonical JSON records below `.neottia/searchable/pages/`. `.neottia/cache/searchable.sqlite` is a disposable FTS5 index with a separate limit of eight times the canonical quota plus 8 MiB.
|
|
53
|
+
- Grep treats query text as bounded literal terms. It reloads canonical records before returning titles, URLs, and snippets.
|
|
54
|
+
- Ask selects canonical stash context and calls the configured Ollama `/api/generate` endpoint. It parses newline-delimited JSON incrementally, bounds frames and the cumulative answer, and returns the source URLs.
|
|
55
|
+
- `modules.searchable.enabled` must resolve to `true` before any service runs.
|
|
56
|
+
|
|
57
|
+
Call `close()` when the host shuts down. Closing aborts new work and closes the injected transport.
|
|
58
|
+
|
|
59
|
+
## Legacy migration
|
|
60
|
+
|
|
61
|
+
`importLegacySearchableDatabase(store, {path: ".web_stash.db"})` previews by default. The source must be a direct child of the project root. Stop the legacy server and remove active WAL or SHM sidecars first. Set `preview: false` only after checking the report. The importer snapshots the database, checks integrity, reads only the `pages` table, waits for its worker to terminate, and leaves the source file unchanged.
|
|
62
|
+
|
|
63
|
+
## Security boundary
|
|
64
|
+
|
|
65
|
+
`web_fetch` accepts only HTTP and HTTPS URLs without user information. The default client rejects local, private, link-local, metadata, multicast, reserved, and mixed public/private DNS destinations. It pins the accepted address for the request and revalidates redirects. Jina and Wayback do not receive target URLs that contain query parameters.
|
|
66
|
+
|
|
67
|
+
Ollama is the only trusted-local network exception. That exception is confined to the model client and does not change `web_fetch` policy. Treat fetched text and model answers as untrusted input.
|
|
68
|
+
|
|
69
|
+
Errors use `{category, code, message, paths, details?}`. Diagnostics remove credential values and URL query strings. Provider response bodies and request objects are not included.
|
|
70
|
+
|
|
71
|
+
Full user documentation is at [`docs/searchable/`](../../docs/searchable/index.md).
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"enabled": {
|
|
6
|
+
"default": false,
|
|
7
|
+
"type": "boolean"
|
|
8
|
+
},
|
|
9
|
+
"root": {
|
|
10
|
+
"default": ".neottia/searchable",
|
|
11
|
+
"type": "string",
|
|
12
|
+
"minLength": 1,
|
|
13
|
+
"maxLength": 1024,
|
|
14
|
+
"pattern": "^(?!\\.{1,2}(?:\\/|$))(?!.*(?:^|\\/)\\.{1,2}(?:\\/|$))(?!\\/)(?![A-Za-z]:)[^\\\\\\0\\r\\n]+$"
|
|
15
|
+
},
|
|
16
|
+
"search": {
|
|
17
|
+
"default": {},
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"provider": {
|
|
21
|
+
"default": "duckduckgo",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"enum": ["duckduckgo", "google", "bing", "brave"]
|
|
24
|
+
},
|
|
25
|
+
"limit": {
|
|
26
|
+
"default": 5,
|
|
27
|
+
"type": "integer",
|
|
28
|
+
"minimum": 1,
|
|
29
|
+
"maximum": 100
|
|
30
|
+
},
|
|
31
|
+
"timeout_ms": {
|
|
32
|
+
"default": 10000,
|
|
33
|
+
"type": "integer",
|
|
34
|
+
"exclusiveMinimum": 0,
|
|
35
|
+
"maximum": 300000
|
|
36
|
+
},
|
|
37
|
+
"credentials": {
|
|
38
|
+
"default": {},
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": {
|
|
41
|
+
"google_api_key": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"pattern": "^\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}$"
|
|
44
|
+
},
|
|
45
|
+
"google_cse_id": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"pattern": "^\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}$"
|
|
48
|
+
},
|
|
49
|
+
"bing_api_key": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"pattern": "^\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}$"
|
|
52
|
+
},
|
|
53
|
+
"brave_api_key": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"pattern": "^\\$\\{[A-Za-z_][A-Za-z0-9_]*\\}$"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"additionalProperties": false
|
|
59
|
+
},
|
|
60
|
+
"bing_api_endpoint": {
|
|
61
|
+
"default": "https://api.bing.microsoft.com/v7.0/search",
|
|
62
|
+
"type": "string",
|
|
63
|
+
"maxLength": 8192,
|
|
64
|
+
"pattern": "^[hH][tT][tT][pP][sS]?:\\/\\/(?![^/?#]*@)[^?#]+$",
|
|
65
|
+
"format": "uri"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"additionalProperties": false
|
|
69
|
+
},
|
|
70
|
+
"fetch": {
|
|
71
|
+
"default": {},
|
|
72
|
+
"type": "object",
|
|
73
|
+
"properties": {
|
|
74
|
+
"strategies": {
|
|
75
|
+
"default": ["direct", "jina", "wayback"],
|
|
76
|
+
"minItems": 1,
|
|
77
|
+
"maxItems": 3,
|
|
78
|
+
"type": "array",
|
|
79
|
+
"items": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"enum": ["direct", "jina", "wayback"]
|
|
82
|
+
},
|
|
83
|
+
"uniqueItems": true
|
|
84
|
+
},
|
|
85
|
+
"timeout_ms": {
|
|
86
|
+
"default": 10000,
|
|
87
|
+
"type": "integer",
|
|
88
|
+
"exclusiveMinimum": 0,
|
|
89
|
+
"maximum": 300000
|
|
90
|
+
},
|
|
91
|
+
"overall_timeout_ms": {
|
|
92
|
+
"default": 20000,
|
|
93
|
+
"type": "integer",
|
|
94
|
+
"exclusiveMinimum": 0,
|
|
95
|
+
"maximum": 600000
|
|
96
|
+
},
|
|
97
|
+
"max_response_bytes": {
|
|
98
|
+
"default": 10485760,
|
|
99
|
+
"type": "integer",
|
|
100
|
+
"exclusiveMinimum": 0,
|
|
101
|
+
"maximum": 10485760
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"additionalProperties": false
|
|
105
|
+
},
|
|
106
|
+
"grep": {
|
|
107
|
+
"default": {},
|
|
108
|
+
"type": "object",
|
|
109
|
+
"properties": {
|
|
110
|
+
"limit": {
|
|
111
|
+
"default": 5,
|
|
112
|
+
"type": "integer",
|
|
113
|
+
"minimum": 1,
|
|
114
|
+
"maximum": 100
|
|
115
|
+
},
|
|
116
|
+
"snippet_bytes": {
|
|
117
|
+
"default": 512,
|
|
118
|
+
"type": "integer",
|
|
119
|
+
"minimum": 64,
|
|
120
|
+
"maximum": 16384
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"additionalProperties": false
|
|
124
|
+
},
|
|
125
|
+
"ask": {
|
|
126
|
+
"default": {},
|
|
127
|
+
"type": "object",
|
|
128
|
+
"properties": {
|
|
129
|
+
"limit": {
|
|
130
|
+
"default": 3,
|
|
131
|
+
"type": "integer",
|
|
132
|
+
"minimum": 1,
|
|
133
|
+
"maximum": 100
|
|
134
|
+
},
|
|
135
|
+
"context_bytes": {
|
|
136
|
+
"default": 131072,
|
|
137
|
+
"type": "integer",
|
|
138
|
+
"minimum": 256,
|
|
139
|
+
"maximum": 4194304
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"additionalProperties": false
|
|
143
|
+
},
|
|
144
|
+
"ollama": {
|
|
145
|
+
"default": {},
|
|
146
|
+
"type": "object",
|
|
147
|
+
"properties": {
|
|
148
|
+
"endpoint": {
|
|
149
|
+
"default": "http://localhost:11434",
|
|
150
|
+
"type": "string",
|
|
151
|
+
"maxLength": 8192,
|
|
152
|
+
"pattern": "^[hH][tT][tT][pP][sS]?:\\/\\/(?![^/?#]*@)[^?#]+$",
|
|
153
|
+
"format": "uri"
|
|
154
|
+
},
|
|
155
|
+
"model": {
|
|
156
|
+
"default": "llama3",
|
|
157
|
+
"type": "string",
|
|
158
|
+
"minLength": 1,
|
|
159
|
+
"pattern": "\\S"
|
|
160
|
+
},
|
|
161
|
+
"timeout_ms": {
|
|
162
|
+
"default": 60000,
|
|
163
|
+
"type": "integer",
|
|
164
|
+
"exclusiveMinimum": 0,
|
|
165
|
+
"maximum": 600000
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"additionalProperties": false
|
|
169
|
+
},
|
|
170
|
+
"cache": {
|
|
171
|
+
"default": {},
|
|
172
|
+
"type": "object",
|
|
173
|
+
"properties": {
|
|
174
|
+
"max_age_ms": {
|
|
175
|
+
"default": 300000,
|
|
176
|
+
"type": "integer",
|
|
177
|
+
"minimum": 0,
|
|
178
|
+
"maximum": 9007199254740991
|
|
179
|
+
},
|
|
180
|
+
"stale_policy": {
|
|
181
|
+
"default": "prompt",
|
|
182
|
+
"type": "string",
|
|
183
|
+
"enum": ["prompt", "rebuild", "fail"]
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"additionalProperties": false
|
|
187
|
+
},
|
|
188
|
+
"security": {
|
|
189
|
+
"default": {},
|
|
190
|
+
"type": "object",
|
|
191
|
+
"properties": {
|
|
192
|
+
"limits": {
|
|
193
|
+
"default": {},
|
|
194
|
+
"type": "object",
|
|
195
|
+
"properties": {
|
|
196
|
+
"max_query_bytes": {
|
|
197
|
+
"default": 16384,
|
|
198
|
+
"type": "integer",
|
|
199
|
+
"exclusiveMinimum": 0,
|
|
200
|
+
"maximum": 16384
|
|
201
|
+
},
|
|
202
|
+
"max_url_bytes": {
|
|
203
|
+
"default": 8192,
|
|
204
|
+
"type": "integer",
|
|
205
|
+
"exclusiveMinimum": 0,
|
|
206
|
+
"maximum": 8192
|
|
207
|
+
},
|
|
208
|
+
"max_title_bytes": {
|
|
209
|
+
"default": 4096,
|
|
210
|
+
"type": "integer",
|
|
211
|
+
"exclusiveMinimum": 0,
|
|
212
|
+
"maximum": 4096
|
|
213
|
+
},
|
|
214
|
+
"max_content_bytes": {
|
|
215
|
+
"default": 10485760,
|
|
216
|
+
"type": "integer",
|
|
217
|
+
"exclusiveMinimum": 0,
|
|
218
|
+
"maximum": 10485760
|
|
219
|
+
},
|
|
220
|
+
"max_results": {
|
|
221
|
+
"default": 100,
|
|
222
|
+
"type": "integer",
|
|
223
|
+
"exclusiveMinimum": 0,
|
|
224
|
+
"maximum": 100
|
|
225
|
+
},
|
|
226
|
+
"max_result_bytes": {
|
|
227
|
+
"default": 4194304,
|
|
228
|
+
"type": "integer",
|
|
229
|
+
"exclusiveMinimum": 0,
|
|
230
|
+
"maximum": 4194304
|
|
231
|
+
},
|
|
232
|
+
"max_storage_bytes": {
|
|
233
|
+
"default": 268435456,
|
|
234
|
+
"type": "integer",
|
|
235
|
+
"exclusiveMinimum": 0,
|
|
236
|
+
"maximum": 268435456
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"additionalProperties": false
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
"additionalProperties": false
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
"additionalProperties": false
|
|
246
|
+
}
|