feat: sonar_search tool — Perplexity Sonar web search #54

Merged
FO
1mo ago
+241-4

What

Adds a sonar_search tool: web search via Perplexity Sonar using our own account (no Exa rate limits). Returns a concise answer + citation URLs.

Design

  • Args: query (required), model (sonar fast default / sonar-pro deeper), max_tokens (default 1000)
  • Auth: PERPLEXITY_API_KEY env → fallback perplexity.key from opencode auth.json (honors XDG_DATA_HOME)
  • API: POST https://api.perplexity.ai/chat/completions, temperature 0.2, 30s timeout
  • Returns { query, model, answer, citations }; errors surfaced (missing key, invalid model, non-2xx with status)

Why

opencode's built-in websearch is Exa-backed and rate-limited, and isn't registered for non-OpenCode providers without an env flag. This rides our existing Perplexity subscription.

Tests & docs

  • 6 unit tests (mock fetch, no network), incl. an API-key-leak regression test
  • AGENTS.md / README.md: 13 tools, sonar_search in a new Search category
  • ROADMAP S5.7

Closes #54


Summary by cubic

Adds a sonar_search tool that runs web searches through Perplexity Sonar with your own account, sidestepping the rate limits of opencode's built-in Exa-backed websearch. It returns a concise answer plus citation URLs, using the fast sonar model by default with sonar-pro for deeper research.

  • Resolves the API key from PERPLEXITY_API_KEY, falling back to perplexity.key in opencode's auth.json (honoring XDG_DATA_HOME).
  • Validates the model against an allowlist, sends with a 30-second timeout, and surfaces non-2xx responses with their status.
  • Registers the tool, adds 6 unit tests (including an API-key-leak regression test), and updates README, AGENTS, ROADMAP, and eslint globals.

Closes #54.