feat(search): add 'auto' adapter — DDG primary, Brave fallback#40
Open
askalf wants to merge 2 commits into
Open
feat(search): add 'auto' adapter — DDG primary, Brave fallback#40askalf wants to merge 2 commits into
askalf wants to merge 2 commits into
Conversation
New `--search=auto` / `DEEPDIVE_SEARCH=auto` runs DuckDuckGo first and falls back to Brave Search when DDG throws (rate-limit / 5xx / network error) or returns zero results. Brave secondary is constructed only when DEEPDIVE_BRAVE_KEY is present, so `auto` degrades to DDG-only in unconfigured environments rather than erroring. Brave Search itself has been a first-class `--search=brave` adapter since before this change; this PR adds the orchestration layer the ticket asked for. Ref: OPS-8171409F0B49493D95C2EF
Tightens types around AutoSearch's optional secondary adapter so the 'auto' DDG-only degradation path compiles cleanly on a fresh checkout. Ref: OPS-8171409F0B49493D95C2EF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
--search=autoadapter that runs DuckDuckGo primary and transparently falls back to Brave Search on DDG failure (HTTP 429 / 5xx / network error) or empty result set.If
DEEPDIVE_BRAVE_KEYis unset,autodegrades to DDG-only rather than erroring — same effective behavior as the prior default. With the key set, transient DDG failures are masked by the Brave retry.Brave itself has been a first-class
--search=braveadapter since before this PR (src/search/brave.ts); this change adds the orchestration layer the ticket asked for.Why
Per ticket
OPS-8171409F0B49493D95C2EF: the planner needs a way to recover when DDG hits a rate limit or returns poor results, without forcing users to manually retry with a different--search.autois the route the ticket spec'd; the spec saidDEEPDIVE_SEARCH_ENGINE=brave|ddg|autobut the codebase already usesDEEPDIVE_SEARCH(singular surface), so I foldedautointo that existing flag rather than introducing a parallel env name.Changes
src/search/auto.ts(new, 33 lines):AutoSearchwraps primary + optional secondarySearchAdapter. On primary error OR empty result it retries the secondary, unless the abort signal is already tripped (in which case it rethrows the primary error to preserve cancellation semantics).src/search.ts: newautocase inresolveSearchAdapter. Brave secondary is constructed only whenDEEPDIVE_BRAVE_KEYis present.src/cli.ts:--searchhelp text listsautoand documents the DDG→Brave fallback contract.README.md: new Auto row in the Search adapters table.CHANGELOG.md: Unreleased entry.test/search-auto.test.mjs(new, 9 cases): primary success, primary error→fallback, primary empty→fallback, primary error with no secondary rethrows, primary empty with no secondary throws zero-results, signal/limit pass-through, aborted signal skips fallback, and the tworesolveSearchAdapter("auto", env)paths (with and withoutDEEPDIVE_BRAVE_KEY).Verification
Including the 9 new cases in
test/search-auto.test.mjs. No regressions in the existing 423-case suite.Smoke-checked adapter resolution end-to-end (no network calls, all permutations):
Ref:
OPS-8171409F0B49493D95C2EF