Skip to content

feat(search): configure WebSearch in operator settings - #2241

Merged
jbeda merged 3 commits into
mainfrom
impl/2235-websearch-settings
Oct 10, 2026
Merged

jbeda merged 3 commits into
mainfrom
impl/2235-websearch-settings

Conversation

@jbeda

@jbeda jbeda commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add strict operator-owned websearch settings for generic HTTP and SearXNG backends
  • add auth.yaml support for generic WebSearch credentials and preserve source precedence
  • validate endpoint configuration, document behavior, and cover embedded-server composition

Verification

  • task test
  • task docs
  • task lint
  • task test:race

Closes #2235

@jbeda

jbeda commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Plan archive

  • Slug: 2235-websearch-settings
  • Local plan: .scratch/issue-2235-websearch-settings-plan.md
  • Branch / baseline: impl/2235-websearch-settings / 8c86c07a01435f200b8caad728c9c4a70f6bc449
  • Published after implementation; verification below remains a plan record, while PR checks are authoritative.

WebSearch operator settings

Slug: 2235-websearch-settings
Implementation branch: impl/2235-websearch-settings
Base branch: main
Issue: #2235

Goal and scope

Make WebSearch deployment configuration durable and operator-owned by adding an operator-only websearch: subtree to settings.yaml. It must work for standalone mecated and the embedded server started by mecatui, without allowing a project file to direct process-wide outbound search.

The subtree exposes the current non-secret mecated controls:

websearch:
  enabled: false
  url: https://search.example/api/search
  auth_header: X-API-Key
  query_param: query
  searxng_url: https://searx.example/search

Add providers.websearch.api_key to the operator-owned auth.yaml credential schema for the generic websearch.url backend. WEBSEARCH_API_KEY remains its higher-priority environment override. Existing Exa and Brave credential configuration remains unchanged.

Non-goals: new backend protocols, SearXNG-specific authentication options, secret values in settings.yaml, new WebSearch controls for non-daemon command roots, private-network egress policy, and broad diagnostic redaction.

Current behavior and proposed approach

mecated alone reads SEARXNG_URL and WEBSEARCH_API_KEY and exposes --websearch, --websearch-url, --websearch-auth-header, and --websearch-query-param (cmd/mecated/main.go:1846-1849, :1979-1984). internal/app.buildSearchProvider resolves the shared provider once for all catalog profiles as off → explicit URL → SearXNG → Brave → Exa (internal/app/build.go:6566-6636). Embedded mecatui gets Exa/Brave credentials but has no SearXNG/generic-endpoint path (cmd/mecatui/main.go:1509-1531).

Add a strict, operator-tier-only websearch: settings section in internal/adapter/permconfig/schema.go, resolver accessors and project-tier rejection/warning, then fold its values into app.Config before catalog construction. This follows the existing resolver/application pattern instead of adding os.Getenv reads to internal/app. Add the subtree to internal/configgen/build.go, then regenerate the configuration reference and settings skeleton.

Use the existing generic HTTP adapter; no new provider abstraction is warranted. Settings must be read by the shared app composition path so conventional settings discovery reaches both server forms.

Material contracts

Configuration ownership and precedence

  • websearch: is strict and accepted only from user-global and explicitly supplied operator settings files. Project loading must recognize and strip the whole websearch: block before strict nested decoding, preserving other project rules even when that ignored block is malformed; it emits a value-free warning and can never affect outbound endpoint selection.
  • Explicit mecated flags retain priority over settings. The complete effective selection order is:
    1. explicit --websearch=off (the kill switch wins over everything);
    2. an explicit nonempty --websearch-url (which also wins over websearch.enabled: false);
    3. websearch.enabled: false;
    4. websearch.url, then websearch.searxng_url, then SEARXNG_URL;
    5. Brave credential (BRAVE_API_KEY, then auth.yaml);
    6. Exa, anonymous unless credentialed (EXA_API_KEY, then auth.yaml).
      Explicit --websearch-auth-header and --websearch-query-param override their settings values when the selected generic URL tier uses them. An empty endpoint flag does not disable a configured endpoint or count as an endpoint override.
  • websearch.auth_header and websearch.query_param apply only to the generic URL tier. Their existing defaults remain Authorization/Bearer and q.
  • WEBSEARCH_API_KEY wins over auth.yaml providers.websearch.api_key. Extend the shared immutable credential snapshot, app.ProviderCredentials, and app.Config so both roots resolve that one source consistently before app build. The credential is used only by the generic URL tier. Exa and Brave retain their existing auth.yaml provider names and environment precedence.
  • A selected malformed/configuration-invalid HTTP tier remains BackendDown; it does not fall through to a lower backend or become operator-disabled. --websearch=off / enabled: false remains the only disabled outcome.
  • Standalone flags remain standalone; embedded mecatui receives the operator settings behavior but does not gain copies of the mecated flags. In connected-client mode, the remote server remains the owner of WebSearch configuration.

Endpoint safety and diagnostics

  • Reject configured generic and SearXNG endpoints containing URL query strings, userinfo, or fragments before provider construction. Queries are supplied by the adapter, so configured endpoints need none; rejecting all three avoids credential disclosure while retaining full diagnostics for accepted endpoints.
  • Do not broadly redact accepted endpoint diagnostics: valid operator endpoints remain visible to aid diagnosis. Rejected userinfo endpoints must not be echoed in validation diagnostics.
  • Existing API-key scrubbing and non-logging guarantees remain in force.

Observable acceptance checks

  • A user-global or explicit operator settings file selects the configured generic endpoint or SearXNG endpoint in both mecated composition and embedded mecatui; the latter no longer depends on the mecated-only environment wiring.
  • An explicit nonempty --websearch-url wins over enabled: false; the existing --websearch=off kill switch still wins over every backend input. Settings endpoint values then win over SEARXNG_URL; individual explicit header/query flags win over their settings values; WEBSEARCH_API_KEY wins over providers.websearch.api_key; existing Brave/Exa precedence is unchanged.
  • A project websearch: block, including one malformed inside its ignored subtree, cannot select or disable a backend and produces a value-free operator-only warning without discarding the file's applicable permission rules.
  • Generic settings carry the configured header/query behavior and resolve their API key through the shared credential snapshot from the documented environment/auth-file source without disclosing it or applying it to SearXNG/Brave.
  • URLs containing userinfo or fragments fail in the centralized HTTP-provider validation path without exposing rejected userinfo, including parse-failure errors; a valid endpoint remains visible in startup diagnostics. Invalid selected endpoints retain BackendDown semantics.
  • Documentation presents the complete precedence ladder and clearly separates endpoint settings from credentials.

Implementation tasks

  1. Add strict operator settings and resolution.

    • Introduce the websearch: schema section and strict decoding in internal/adapter/permconfig/schema.go, with generated-reference doc comments.
    • Extend resolver capture/accessors and project-tier filtering in internal/adapter/permconfig/resolve.go (and its focused tests). Strip an ignored project websearch: mapping before strict nested decode so it cannot cause the rest of the project file's permission rules to be lost; emit only a value-free warning.
    • Register the new top-level subtree with an operator tier in internal/configgen/build.go and update config-generation coverage where needed.
    • Completion check: resolver tests establish source ordering, absence-vs-explicit values, strict unknown-key handling, and project rejection without exposing configuration values.
  2. Extend the generic WebSearch credential lifecycle.

    • Add websearch to the recognized auth-file provider set and shared immutable credential snapshot in internal/cliconfig; project it through app.ProviderCredentials and app.Config before app.Build constructs the search provider, rather than retaining a mecated-only environment read.
    • Preserve WEBSEARCH_API_KEY as the environment override and extend test-owned auth-file fixtures for environment/file precedence and unknown-provider validation.
    • Completion check: no credential value reaches logs/diagnostics, and providers.websearch.api_key is available only to the generic URL backend.
  3. Fold resolved settings into shared application composition.

    • Add the required non-secret settings/config fields and explicit-flag presence markers, then fold after final resolver creation but before the build-once search provider is constructed (internal/app/build.go). Apply the stated per-control precedence and let shared composition apply settings to embedded mecatui.
    • Update mecated wiring only as needed to supply explicitness/provenance; do not duplicate settings loading in command roots. Keep connected mecatui server-owned.
    • Completion check: focused app/composition tests prove the complete precedence ladder, one selected provider shared by catalog variants, disabled versus backend-down semantics, and embedded settings behavior.
  4. Validate endpoint shape without obscuring useful diagnostics.

    • Centralize parsing/validation in the HTTP-provider construction path for every generic, SearXNG settings, legacy-environment, and CLI endpoint. Reject non-HTTP(S), missing-host, userinfo, and fragments before any error formatting; userinfo rejection must use a fixed/sanitized error so app diagnostics cannot disclose it.
    • Retain accepted endpoint diagnostics and existing no-key logging behavior; do not change unrelated HTTP adapter controls.
    • Completion check: adapter/app tests cover valid endpoint diagnostics, rejected userinfo and fragment behavior, and non-fallback after invalid selected configuration.
  5. Regenerate and update operator documentation.

    • Run task docs:configref to regenerate internal/configgen/settings.skeleton.yaml and user-docs/reference/configuration.md from schema comments.
    • Update user-docs/features/sessions/tools.md with the complete backend/configuration precedence and user-docs/operating/settings.md / provider configuration guidance with the new websearch: and providers.websearch.api_key examples and ownership boundaries. Update generated CLI docs only if flag wording changes.
    • Completion check: examples distinguish settings.yaml endpoint controls from auth.yaml keys and describe behavior for standalone versus embedded servers.

Verification

  • Focused offline Go tests for internal/adapter/permconfig, internal/cliconfig, internal/app, relevant cmd/mecated/cmd/mecatui composition seams, and engine/adapter/search; use injected environments, diagnostics, and test-owned auth/settings directories in accordance with test isolation rules.
  • Run task docs after documentation/generation changes and task test for the integrated change set. Before PR readiness, run task lint && task test:race and the offline go run ./cmd/mecademo gate required by AGENTS.md.
  • The implementation branch's initial code panel review should compare from the start commit captured when plan-implement creates impl/2235-websearch-settings; any later fixes receive targeted incremental review.
  • If implementation produces a PR, preserve this full publishable plan in its identifiable plan comment and verify comment/readback equivalence before PR-ready handoff.

Decisions and risks

Settled: websearch: is operator-only; it contains the five non-secret controls above; explicit daemon flags outrank settings; settings outrank legacy endpoint environment variables; generic credentials use providers.websearch.api_key with WEBSEARCH_API_KEY priority; valid endpoint diagnostics stay visible; userinfo and fragments are rejected.

Risk: websearch.url and websearch.searxng_url can both be configured. Their intentional ordering is generic URL first, matching the present explicit-URL-over-SearXNG contract. This plan does not add mutual-exclusion validation because a clear deterministic precedence already exists.

@jbeda
jbeda merged commit 56c5534 into main Oct 10, 2026
39 checks passed
@jbeda
jbeda deleted the impl/2235-websearch-settings branch October 10, 2026 01:41
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 13, 2026
2 tasks

This branch was successfully deployed

1 active deployment
Preview — 7f0046ad Deployed Oct 9, 2026 by vercel[bot]
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.

Configure SearXNG endpoint in operator settings

1 participant