Key-free web search, clean content extraction, and local hybrid retrieval in one Go binary — with prompt-injection defenses in the data path, not in a disclaimer.
Proof of concept, very early days. Scraped providers break without notice, the injection defenses are best-effort and can be bypassed, and the on-disk index format may change without a migration path. Use with caution — this is not a dependency to put in front of anything you rely on.
┌─ CLI ──────────────┐ ┌──────────────────────────────────────────────┐
│ search fetch index │ │ search: DDG/Mojeek/SearXNG chain (HTTP-first, │
│ crawl query serve ├──►│ browser escalation on bot walls — no API keys)│
└────────────────────┘ ├─ fetch: SSRF-guarded HTTP + playwright layer │
┌─ MCP server ───────┐ ├─ extract: HTML→readability→Markdown, PDF, MD │
│ web_search web_ │ ├─ sanitize: unicode hygiene, injection │
│ fetch index query │ │ detector, URL defang, untrusted envelope │
│ web_status crawl │ ├─ store: SQLite — FTS5(BM25) + float32 cosine │
└────────────────────┘ │ vectors, RRF fusion, content-hash incremental│
└──────────────────────────────────────────────┘
Search providers want money per query. Most of the "internet" is already reachable with an HTTP GET, and the rest yields to a real browser. loci scrapes the public result pages directly (HTTP first, headless Chromium on bot walls, an opt-in solve mode where a visible browser waits for you to solve a captcha), extracts just the document — scripts and CSS are stripped, asset routes are blocked outright — and stores everything in a local index you can ask questions of, with no cloud round trip.
The indexing model follows the pattern trailhq/Graft uses for codebases, applied to web content: content-hash keyed incremental ingestion, boundary-aware chunking, and hybrid keyword+semantic retrieval served over MCP.
make build # → bin/loci
make install # → ~/.local/bin/loci; needed for the bare `loci …` below (PREFIX= / DESTDIR= to relocate)
./bin/loci doctor # check store/browser/embedder/pdf tooling
./bin/loci search "golang mcp sdk"
./bin/loci index https://example.com/a-post
./bin/loci query "what did the post say about X"
# true-local embeddings (optional, recommended):
ollama pull nomic-embed-text
loci config # then set embed.backend = "ollama" in the printed path
loci reindex --vectors # re-embed already-stored chunks
# first-time browser layer (driver download; browsers reused from ~/.cache):
loci browser install{
"mcpServers": {
"loci": { "command": "/absolute/path/to/bin/loci", "args": ["serve"] }
}
}Tools: web_search, web_fetch, web_index, web_crawl, web_query, web_status.
Web pages are adversarial input. loci assumes anything a page says may be a prompt-injection attempt aimed at the agent that eventually reads it.
- Structural quarantine. Page text reaches an agent inside a per-call salted
<untrusted-<random-hex> source="URL">envelope:web_fetchwraps the extracted document,web_querywraps each stored hit,web_searchwraps each result title and snippet, all mirrored in typed structured output withsuspicionmetadata (web_fetchexposesfetched_atandsha256as typed fields, not envelope attributes). The CLI prints the same text un-enveloped, prefixed with the detector warning when content is flagged — exceptloci query, which prints the stored envelope cut to a 600-rune preview (web_crawlreturns counters, never page text — what it stores surfaces throughweb_query). Envelope tags found inside content are neutralized first, so a page cannot forge a closing tag and escape. - Unicode hygiene. NFKC normalization; zero-width, bidi-control and tag characters removed; control chars stripped.
- Detection, never deletion. A weighted rule set (instruction overrides,
fake role lines/tags, chat-template tokens, exfil phrasing, credential strings…)
attaches
suspicion=none|low|medium|high+ signal names. Content is never silently modified beyond step 2, except that envelope content is capped at 600 KB and marked[…truncated]. - URL defanging. URLs inside search snippets arrive as
hxxps://host[.]pathso agents don't reflexively fetch planted links; real URLs stay in provenance fields. - SSRF guard. Only
http(s), no URL credentials, ≤5 redirects each re-validated, dial-time rejection of private/loopback/link-local/metadata addresses (defeats DNS rebinding).allow_private_hostexists for tests only. - Browser discipline. Assets (script/CSS/image/font) blocked by default;
per-context isolation; downloads off; captchas are only solved by you in
solvemode against a persistent profile — no captcha circumvention services. - No interpreter authority. loci itself never runs an LLM on fetched text; retrieval and interpretation stay separated by design.
Residual risk: envelope discipline depends on the host agent honoring it. That's
why the server instructions, tool descriptions, and every warning line restate it.
- Search chain (
internal/search):ddg-html → ddg-lite → mojeek → searxng → ddg-browser → bing-browser(configurable). HTTP responses are classified (ErrBotChallenge: status 202/403/429 +anomaly-modal,cf-challenge, reCAPTCHA markers…) so escalation is evidence-driven, not timer-driven. - Browser layer (
internal/browser):playwright-goover cached Chromium.autoescalates per request;forceskips HTTP;offdisables;solverelaunches headed with a persistent profile and waits for you. - Extraction (
internal/extract): goquery-based noise stripping →go-readabilitymain-content (full-body fallback) → in-house HTML→Markdown writer (htmlmd, no dead deps). PDF:pdftotext(poppler) when present, pure-Go fallback otherwise. - Store (
internal/store): pure-Go SQLite (modernc.org/sqlite, no CGO):docs(unique URL + sha256 — unchanged hashes make re-index a no-op),chunks,chunks_fts(FTS5 porter/BM25, trigger-synced),vectors(float32 blobs + in-memory cosine — exact, fast to ~10⁵ chunks; revisit beyond). Retrieval = BM25 ∪ cosine → Reciprocal Rank Fusion. Zero-vector state degrades to keyword-only transparently.
| command | purpose |
|---|---|
search <q> [-n N] [--json] |
provider-chain web search |
| `fetch [--save] [--browser[=auto | force |
index <url>… | --from-file urls.txt |
incremental indexing |
crawl <seed> [--max N] [--same-domain] |
polite BFS crawl + index |
query <q> [-k N] |
hybrid retrieval over the store |
stats / reindex --vectors |
counters / re-embed without re-fetch |
doctor |
capability report (store, ollama/models, browser, pdftotext) |
serve |
MCP server on stdio |
browser install |
first-time playwright driver setup |
config |
effective configuration as JSON + the config.toml path in use |
Config: $XDG_CONFIG_HOME/loci/config.toml (see config.example.toml), env overrides LOCI_BROWSER, LOCI_DATA_DIR, LOCI_EMBED_*, LOCI_SEARX_URLS, LOCI_IGNORE_ROBOTS.
- No JavaScript-heavy SERP fallbacks beyond DDG/Bing pages; add more parsers per provider.
- No OCR for scanned PDFs (flagged
degraded). - Brute-force vectors until ~100k chunks; then consider sqlite-vec.
crawlis BFS with a link budget; no sitemap/RSS-aware crawling yet.- Captcha policy: human-in-the-loop only.
- The
dsearch→locirename does not migrate data/config dirs orDSEARCH_*env vars; an index from the old build is ignored, so re-runindex/crawl.
make test # unit + httptest-backed integration, in-process MCP round-trip
make vet