Documentation
¶
Overview ¶
htmltotext.go reduces an HTML page's markup to plain text before fetch measures it against its size cap. Design R4 requires the reduction to happen BEFORE the cap is applied — otherwise markup consumes the byte budget the prose needs, and a page that is 90% tags returns almost no actual content.
This walks golang.org/x/net/html's parse tree — an existing DIRECT dependency (go.mod), already used for HTML manipulation elsewhere in this exact codebase (pkg/channels/channelassets/html) — rather than a hand-rolled tag-stripping regex, the shape CLAUDE.md's "prefer a library over a hand-rolled utility" rule explicitly rejects.
bluemonday (also already a dependency, and this repo's own choice for HTML sanitization) was the first candidate and was rejected for this specific job after a direct comparison: bluemonday.StrictPolicy().Sanitize strips every tag but inserts no whitespace at block boundaries, so "<p>A</p><p>B</p>" collapses to "AB" — two paragraphs glued into one unreadable word run. It also leaves HTML entities escaped ("&" stays "&"), because it sanitizes the token stream rather than parsing text nodes. Walking x/net/html's own tree costs a few more lines than a single Sanitize call, but keeps block-level elements from running into each other and gets entity decoding for free from the parser's own text nodes.
Command websearchd is ap-websearchd: a client-dispatched search-and-fetch sidecar. It exposes two MCP tools, search and fetch, over Streamable-HTTP, backed by a registry-selected github.com/authzed/openagentprimitives/pkg/tools/websearch provider.
It exists so that an agent's web access is CLIENT-dispatched rather than a model provider's own inline search: a server-side search/fetch result never becomes a tool.Result, so it never passes through the runner's untrusted-content wrapper, never reaches a content-guard subject, and never touches the toolguard byte budget — every control this platform has over tool output is absent by construction. Because this binary makes the HTTP request itself, its result IS a tool.Result like any other MCP tool call, and every one of those controls applies to it automatically.
It runs no user code: query and URL arguments are plain strings handed to a provider's own HTTP client (safehttp.Client() in production), never interpreted as a script — the same posture internal/cmd/apiadapter states for its own config-driven calls.
server.go turns one websearch.SearchExecutor into two MCP tools — search and fetch. This file never reads an environment variable — main.go owns the env contract and hands this Server an already-constructed executor and an already-opened (or nil) artifact store, exactly as internal/cmd/apiadapter's server.go takes an already-parsed Config and an already-resolved credential.
fetch is the entire security surface of this daemon (see the design doc's §3 R4 and §4): every check below runs in the stated order, and each one exists to close a specific gap the one before it leaves open.