feat: add notte search command#38
Merged
Merged
Conversation
|
| Filename | Overview |
|---|---|
| internal/cmd/search.go | New search command implementation; well-structured with clear JSON/text output branching, HTML entity decoding, and graceful unknown-shape fallback. |
| internal/cmd/search_test.go | Thorough unit tests covering both response shapes, JSON mode, API errors, missing API key, empty queries, HTML entity decoding, and unknown response shapes. |
| internal/cmd/root.go | Minor addition of notte search <query> to the root help long description. |
| README.md | Adds web search section to docs and refreshes the landing/links section; no functional impact. |
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
internal/cmd/search.go:205-211
`colorizeText` constructs a new `termenv.Output` on every call. For a result set with many entries this allocates a fresh output object per number, title, and URL. The output profile (color support, TTY detection) is the same for the entire command run, so a single shared instance would be more efficient and consistent with how `GetFormatter()` is used elsewhere.
```suggestion
var termenvOutput = termenv.NewOutput(os.Stdout)
// colorizeText applies a color via the shared termenv output, respecting --no-color.
func colorizeText(s string, color termenv.ANSIColor) string {
if noColor {
return s
}
return termenvOutput.String(s).Foreground(color).String()
}
```
### Issue 2 of 2
internal/cmd/search.go:58-64
The `--depth` and `--output-type` flags accept free-form strings and send them directly to the API. Invalid values (e.g. `--depth turbo`) will silently reach the server and return an API error with no guidance at the CLI level. The valid set is already documented in the flag help text, so a quick allowlist check here would surface the mistake before the network round-trip.
```suggestion
validDepths := map[string]bool{"standard": true, "fast": true, "deep": true}
if searchDepth != "" && !validDepths[searchDepth] {
return fmt.Errorf("invalid --depth %q: must be standard, fast, or deep", searchDepth)
}
validOutputTypes := map[string]bool{"searchResults": true, "sourcedAnswer": true}
if searchOutputType != "" && !validOutputTypes[searchOutputType] {
return fmt.Errorf("invalid --output-type %q: must be searchResults or sourcedAnswer", searchOutputType)
}
body := api.SearchRequest{Q: query}
if searchDepth != "" {
body.Depth = &searchDepth
}
if searchOutputType != "" {
body.OutputType = &searchOutputType
}
```
Reviews (2): Last reviewed commit: "feat: add notte search command for web s..." | Re-trigger Greptile
Wraps the POST /search endpoint with a top-level `notte search <query>` command. Renders both response shapes (searchResults and sourcedAnswer) in text mode, HTML-unescapes titles/snippets/answers for readable output, and passes raw JSON through unchanged when --output json is used. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Validate --depth and --output-type against the documented allowlist before sending the request, so typos surface as a clear CLI error instead of an opaque API 422. - Cache the termenv.Output as a package-level var instead of re-creating it on every colorize call. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
bb26ea1 to
0b111e9
Compare
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.
Summary
notte search <query>wrappingPOST /search.--depth(standard/fast/deep) and--output-type(searchResults/sourcedAnswer).notte search "what is anthropic") or unquoted (notte search what is anthropic) input.Test plan
go test ./...— all pass, including newinternal/cmd/search_test.gocovering both response shapes, JSON mode, API errors, missing API key, empty/whitespace-only queries, fallback for unknown shapes, and HTML-entity decoding.go vet ./...— clean.notte search "what is anthropic"— numbered results render with title/URL/snippet.notte search "founder of stripe" --output-type sourcedAnswer— answer block + sources list.notte search "..." --output json— raw JSON for scripting.notte --help) updated with the new command.🤖 Generated with Claude Code