Skip to content

feat(web): nginjen-lite — built-in search and scrape (core version of nginjen) #625

Closed

Description

@ajianaz

What problem does this solve?

Today web_search exists only when the owner points tole at an external backend (TOLE_WEB_SEARCH_URL, method, headers, fields), and web_fetch is a plain direct GET that returns text. Out of the box tole has no search, and its fetch has no markdown or link extraction. nginjen (the owner's web tool service) does search with several engines and scrape with several output formats, but tole can only reach it as a remote backend.

The owner wants a core version of nginjen built into tole: nginjen-lite, so search and scrape work without running or configuring a separate service.

Decisions (owner, 2026-11-12)

  1. Default without an nginjen backend: built-in keyless engines (DuckDuckGo first, then the others nginjen already supports). SearXNG needs its own service or container, so it stays an optional lane, unless its aggregation can be adopted as a built-in feature later.
  2. With a backend: the nginjen backend is configured by just two variables, a base URL and an API key. When both are set, tole uses the full nginjen backend for search and scrape; otherwise the built-in lite implementation. The generic TOLE_WEB_* backend settings keep working.
  3. Unattended (cron) runs use the web tools without a per-job domain allowlist.
  4. Code: nginjen-lite is extracted from the nginjen repository with as little code as possible (search and scrape, no other dependencies) and published to crates.io; tole depends on it as a normal crates.io dependency. tole-core, tole-cli and tole-tui stay published. The extraction is tracked in the private nginjen tracker (primary: Gitea issue 137; GitHub mirror codecoradev/nginjen#190).
  5. Jina Reader fallback: off by default, opt-in only.

Findings from the nginjen repository (Apache-2.0, a single Rust binary)

  • Search (nginjen-core/src/search.rs, about 2,000 lines): DuckDuckGo Lite (default), Bing and Brave HTML scrapers, a meta-search (concurrent, interleaved, de-duplicated) and SearXNG lanes with failover, all keyless. The parsers are pure functions from HTML to results and use scraper.
  • Scrape: content_converter::convert_html(html, format) is pure over HTML (uses scraper; PDF text uses lopdf and readability uses dom_smoothie, both avoidable).
  • Backend API: POST /search and POST /scrape, bearer NGINJEN_API_KEY.
  • Why not nginjen-core: it also carries Chromium/CDP, stealth, zip/tar/flate2 and an async tokio + reqwest stack.
  • The crate names nginjen-lite, nginjen and nginjen-core are free on crates.io.

Proposed solution (tole side)

  • Depend on nginjen-lite (default features only: scraper, url, no async runtime). Implement its small blocking HttpClient trait over tole's existing HTTP client so tole keeps one client and one TLS stack.
  • web_search / web_fetch use nginjen-lite when no external backend is configured; with no search lane available, web_search is not registered (as today).
  • With NGINJEN_BASE_URL + NGINJEN_API_KEY set, use the nginjen backend for both tools.
  • Guards stay as they are in tole: http(s) only, content-type allowlist, size cap, SSRF vetting (web.rs), refusal of URLs that carry a known secret, queries redacted through the process SecretSet before leaving, results fenced like every tool result.
  • Report binary-size and dependency delta against docs/perf.md before this lands.

Alternatives considered

  • Keep only the generic HTTP backend (status quo): needs a running service and configuration for every user.
  • Embed a headless browser for JS pages: far too heavy for tole; out of scope (nginjen full covers it).
  • Depend on nginjen-core: pulls the browser stack.
  • Vendored, CI-synced copy of the code: unnecessary once nginjen-lite is a published crate.
  • Domain allowlist for web_fetch in unattended runs: proposed and rejected by the owner.

Blocked by

nginjen Gitea issue 137, mirrored as codecoradev/nginjen#190 (extract and publish nginjen-lite).

Open questions

  1. Politeness defaults for the built-in fetch: User-Agent string, robots.txt (nginjen has a robots.rs to carry over), per-host rate limit.
  2. Order of keyless engines when the first one blocks or returns nothing (nginjen's fallback order is configurable; which default list?).

Are you willing to contribute the implementation?

Yes, I can do it

Before submitting

  • I searched existing issues and didn't find a duplicate

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions