Add an npm registry search engine adapter
wigolo's code search vertical fans queries across engine adapters — adding one is a well-contained ~100-line PR, and the npm registry has a clean public JSON API (https://registry.npmjs.org/-/v1/search?text=...), so there's no scraping involved.
Where to look
- Reference adapter:
src/search/engines/mojeek.ts(implements theSearchEngineinterface —name+search()returningRawSearchResult[]) src/search/engines/hn-algolia.tsis another good API-based example- Register it in the code vertical:
src/search/core/verticals/code.ts
Acceptance
- New
src/search/engines/npm-registry.tsadapter, registered in thecodevertical - Respects
timeoutMs/maxResultsoptions like the other adapters - Unit test alongside the existing engine tests
npm testandnpm run lintgreen
Questions welcome in the thread — happy to point at anything.
I'd like to take this. Proposed approach, matching crates-io since both are public package-registry JSON APIs:
- New adapter
src/search/engines/npm-registry.tsimplementingSearchEngine(name+search()). - Call
GET https://registry.npmjs.org/-/v1/search?text=...&size=...(no scraping). - Honor
timeoutMsviaAbortSignal.timeoutandmaxResultsvia thesizequery param (clamped to the registry max of 250). - Map hits to
RawSearchResult(title = package name, url = npmjs.com package page, snippet = description + version). - Register it on the
codevertical as a secondary engine with the same weight/quality as crates.io (weight: 0.3,quality: 'high'), so npm package pages don't hijack unrelated code queries. - Unit tests next to the existing engine tests;
npm testandnpm run lintgreen.
I'll send a PR unless this should land differently.
A few routing questions that came up on the earlier npm PRs, so they don't get re-litigated per implementation.
There are already three copies of this adapter: #190 (closed, nearly landed), #261, and #361. I don't think a fourth npm engine would help — happy to fold remaining review into whichever of the open PRs you'd rather merge.
Secondary + weight. Narrow package-registry hits should stay secondary: true at weight 0.3, same as crates.io and MDN. Primary at ~0.9 is what lets an npm package page compete on every code query, including ones like pgvector HNSW ef_search tuning. Both open PRs already follow that contract.
Quality tier. The vertical tag and ENGINE_QUALITY have to match — that consistency guard is what blocked #190. On that PR you suggested 'medium' for npm: the description field is usable, but it isn't the wikipedia/MDN evidence tier. #361 currently mirrors crates.io at 'high' in both places so CI is green; I'll switch both to 'medium' if that's still the call. #261 sets the vertical tag to 'high' without a registry entry, so it would fail the same guard (unknown names default to 'medium').
PyPI? I'd hold off as a sibling of this ticket. npm (registry.npmjs.org/-/v1/search) and crates.io (/api/v1/crates?q=) both have keyless JSON search. PyPI does not: XML-RPC search was disabled, pypi.org/search is a web UI (not a public API, and not intended for unmetered traffic), and /pypi/<name>/json is exact-name lookup only. A PyPI adapter would either scrape or be a different shape of engine. If you want Python coverage later, I'd rather open a separate issue for exact-name lookup (or wait for a real search API) than stretch #144.
Happy to take review on #361, coordinate with @fuleinist on #261, or close mine if you'd rather land theirs and I'll send the extra hardening as a follow-up.
Pickup notes (still a good first issue; three earlier attempts stalled, so here's the shape that will get merged):
- Template: copy
src/search/engines/crates-io.ts, which is a keyless package-registry engine with the same structure. Use the public search endpointhttps://registry.npmjs.org/-/v1/search?text=…&size=N; no key is needed. - Registration: add it to the code vertical in
src/search/core/verticals/code.tsexactly like crates.io:weight: 0.3,secondary: true,supportsDateFilter: false. Secondary engines get demoted when their results don't match the query lexically, so a package registry can't take over general code queries. - Mapping:
title= the package name,url=https://www.npmjs.com/package/<name>,snippet= the description. Skip results without a name. - Tests: copy the crates.io engine test: a mocked response, an empty response, a malformed response, and the request URL encoding. Also add a vertical test that the engine is registered as secondary.
- Keep the PR to just this. Please don't touch other engines or weights.
Generated by Claude Code