@kennyfrc/websearch
v2.0.1
Published
Brave Search CLI with batch support and locale-aware headers
Readme
websearch
websearch is a Bun-powered CLI that calls the Brave Search API, automatically enabling operators and extra snippets while supporting single or batched queries.
Tutorial
Follow these steps to run your first search.
Install dependencies:
bun installCreate
~/.config/webserch/config.tomlwith your Brave token:apiKey = "YOUR_BRAVE_API_TOKEN"Execute a query:
bun run src/main.ts query --q "hello world"The CLI prints the top results with their extra snippets. Repeat the command with different queries as needed.
How-to guides
- Override defaults for a single query
- Supply flags like
--country=us --lang=en-US --count=5 --offset=10alongside--q.
- Supply flags like
- Run multiple queries in one invocation
- Use
--batchto provide a list:bun run src/main.ts query --batch "bun runtime" "brave search api limits".
- Use
- Compile a standalone binary
- Run
bun run build, then executenode dist/main.js query --q "typescript"without Bun.
- Run
Reference
- Command
websearch query --q <string> --country <code> --lang <code> --count <int> --offset <int> --freshness <window> --batch <string...>--qis optional when--batchis provided; extra snippets and operators are always enabled.
- Flags
--country: two-letter ISO code; uppercased automatically.--lang: language tag; normalized toen-USstyle.--count/--offset: positive integers validated by Commander.--freshness: Brave freshness window such asd1,w1, orm6.--batch: runs each query sequentially, reusing other options.
- Configuration
- File:
~/.config/webserch/config.toml- Keys:
apiKey,endpoint,defaultCountry,defaultLanguage,defaultFreshness.
- Keys:
- Environment overrides:
WEBSEARCH_API_KEY,BRAVE_API_KEY,BRAVE_SEARCH_API_KEY.
- File:
- Headers
Accept-LanguageandAccept-Locationderive from CLI flags or system locale hints.User-Agentidentifies the CLI and Bun runtime.
Explanation
- Bun ships direct TypeScript execution, removing separate build steps during development.
- Brave requires
extra_snippets=trueandoperators=truefor richer responses; the CLI enforces both, along withAccept-*headers taken from host locales. - Configuration falls back from environment variables to TOML to avoid leaking API keys into command histories.
- Batch execution reuses network headers but handles errors per query, so one failure does not abort the remaining searches.
