Skip to content

feat(cli): built-in web_search and web_fetch on nginjen-lite (#625 part 1b) - #672

Merged
ajianaz merged 5 commits into
developfrom
feat/web-nginjen-lite
Nov 13, 2026
Merged

ajianaz merged 5 commits into
developfrom
feat/web-nginjen-lite

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1b of #625: built-in web_search (keyless engines) and web_fetch (HTML converters, robots.txt), on nginjen-lite 0.1.0 and tole's own HTTP client, behind the default web-builtin feature of tole-cli. The nginjen backend (NGINJEN_BASE_URL + NGINJEN_API_KEY) and the tole doctor lines follow in part 2.

Depends on: #671 (part 1a, web::vetted_get), which is merged. The latest develop is merged into this branch (a merge commit), and the PR now targets develop.

Why

Out of the box tole had no search, and its fetch returned plain text only. The owner wants nginjen's core built in, with tole's guards kept: one client, the SSRF check on every hop, and no secrets in URLs or queries.

Changes

  • crates/tole-cli/src/web_builtin.rs (new, web-builtin feature):
    • TolHttp implements nginjen-lite's HttpClient with lite's get_following_redirects around web::vetted_get, one hop at a time. On every hop:
      • check_hop refuses an https-to-http hop, and a hop whose URL carries a known secret;
      • the hop's own SSRF check runs (up front, then in the pinned resolver);
      • the bounded Pacer allows at most one request per second per host, remembering at most 64 hosts;
      • engine and robots answers are capped at 2 MiB.
    • BuiltinSearchTool (web_search):
      • DuckDuckGo Lite, then Bing, then Brave, through lite's search_with_fallbacks; a non-2xx answer moves to the next engine;
      • the query is redacted with the process secrets and capped at 512 characters before it leaves;
      • 8 results with capped fields; the answer names the engine and whether it was a fallback;
      • the engines get lite's browser-like User-Agent, because they block other agents (your ruling).
    • BuiltinFetchTool (web_fetch):
      • http(s) only, a URL carrying a known secret is refused, and the host must be public (checked before anything is sent);
      • robots.txt is checked through lite's RobotsChecker (64-origin cache, fail-open);
      • the content-type allowlist and a 512 KiB body cap apply (truncated and flagged);
      • format is markdown (default), compact, text, html or links. The tool description says compact drops inline bold, italic, code and image alt text (nginjen verify_package edit-distance: cover boundary cases / simplify early-exit; scoped-vs-bare consistency #235);
      • text is capped at 20,000 characters and links at 200;
      • requests send tole/<version> (+https://github.com/codecoradev/tole).
  • tool_roster::build: a configured TOLE_WEB_FETCH_URL / TOLE_WEB_SEARCH_URL backend still wins. Otherwise the built-in tools are registered (web-builtin); without the feature, today's direct fetcher is used and search needs a backend.
  • Cargo:
    • web-builtin = ["dep:nginjen-lite", "dep:url"], on by default;
    • nginjen-lite = { version = "0.1.0", features = ["robots"] } (no pdf, readability or ureq);
    • url, already in the tree.
  • tests/tool_specs.rs: the full-registry spec size now includes the built-in pair: 16,032 characters for 30 tools, under the unchanged 18,000 bound.
  • Docs: CHANGELOG, a README tool row, the threat-model web section, and docs/perf.md with the size and dependency table.

Final numbers (re-measured on this head; also in docs/perf.md):

Build tole release bytes tole-cli unique crates tole-core (--no-default-features)
develop before #625 18,184,632 264 58
this PR, without web-builtin 18,185,208 264 (+0) 58
this PR, default (web-builtin) 19,482,712 (+1,297,504, +7.1%) 299 (+35 by sort -u, 30 distinct crates; 4 of them build-time proc-macros) 58 (+0)

Memory: per tool, a bounded robots cache (at most 64 origins) and a bounded per-host pacer (at most 64 hosts); no threads; every input and output is capped per call.

Testing

  • TDD: the 7 unit tests in web_builtin_tests.rs went red against stubs (7 of 7 failed), then green.
  • They use local servers on 127.0.0.1 and a fake engine client, with no external network. They check:
    • conversion: HTML to markdown by default and to text, html and links, through a redirect;
    • guards: non-http(s), a URL carrying a secret, the content type, a 404, an unknown format, a private address refused with nothing reaching the server, and a big page truncated;
    • robots.txt: a disallowed path is refused, and a missing robots.txt is allowed (fail-open);
    • the hop policy: no https downgrade, and no secret-carrying hop mid-redirect;
    • the pacer: spacing per host, and its bound;
    • search: DuckDuckGo first, the fallback order on non-2xx, all engines down, and the query redacted and capped;
    • the engine body cap.
  • Gates before the merge of develop:
    • cargo fmt --all
    • cargo clippy --workspace --all-targets --all-features -- -D warnings
    • cargo test --workspace
    • cargo test -p tole-core --no-default-features
    • the no-mcp commands, which build tole-cli without web-builtin
  • After the merge (only the CHANGELOG conflicted), I re-ran on this head: fmt, the web_builtin unit tests, tool_specs and the crate counts.
  • cora review --no-llm --base feat/web-vetted-hop: no issues.
  • Mutation breaks, each restored afterwards; the tests caught all 13:
    • https downgrade allowed;
    • a secret-carrying hop allowed;
    • hops skip the policy;
    • the pacer never waits;
    • the pacer is unbounded;
    • engine bodies uncapped;
    • robots ignored;
    • any content type accepted;
    • the default format is text;
    • no tole User-Agent;
    • the query not redacted;
    • the engine order swapped;
    • the text uncapped.

…art 1a)

web::vetted_get performs a single GET through the existing vet-and-pin
resolver: the host is checked up front (a private address is refused
before any connection) and again in the connection's own resolver. No
redirect is followed (a 3xx comes back with an unread body), a non-2xx
status is a response rather than an error, the body is capped (error or
truncate and flag) and the timeout covers the hop. vet_public_url and
allow_private_from_env expose the check and the opt-out.
@ajianaz
ajianaz changed the base branch from feat/web-vetted-hop to develop November 13, 2026 09:45
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 268d75d into develop Nov 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the feat/web-nginjen-lite branch November 20, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants