Skip to content

feat: add notte search command#38

Merged
giordano-lucas merged 2 commits into
mainfrom
t3code/0577c913
May 7, 2026
Merged

feat: add notte search command#38
giordano-lucas merged 2 commits into
mainfrom
t3code/0577c913

Conversation

@giordano-lucas
Copy link
Copy Markdown
Member

Summary

  • New top-level command notte search <query> wrapping POST /search.
  • Supports --depth (standard/fast/deep) and --output-type (searchResults/sourcedAnswer).
  • Renders both response shapes in text mode (numbered results, or LLM answer + sources). HTML entities in titles, snippets, and answers are unescaped for readable terminal output. JSON mode passes the raw API response through unchanged.
  • Query accepts either quoted (notte search "what is anthropic") or unquoted (notte search what is anthropic) input.

Test plan

  • go test ./... — all pass, including new internal/cmd/search_test.go covering 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.
  • Manually invoked against the live API:
    • 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.
  • README and root help (notte --help) updated with the new command.

🤖 Generated with Claude Code

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 7, 2026

Greptile Summary

This PR adds a notte search <query> top-level command that wraps the POST /search API, rendering both searchResults and sourcedAnswer response shapes in text mode with HTML entity decoding, while passing raw JSON through unchanged in --output json mode.

  • New internal/cmd/search.go introduces the command with --depth and --output-type flags, flexible multi-word query joining, and a clean fallback path for unknown response shapes.
  • internal/cmd/search_test.go adds thorough unit tests covering both response shapes, JSON mode, API errors, missing API key, empty/whitespace queries, HTML entity decoding, and fallback behavior.

Confidence Score: 5/5

Safe to merge — the change is additive, well-tested, and does not touch any existing command paths.

The new command is isolated from existing commands, the test suite covers the key scenarios thoroughly, and the JSON/text branching logic follows the established patterns in the codebase. No existing behavior is modified.

No files require special attention.

Important Files Changed

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.

Fix All in Claude Code

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

giordano-lucas and others added 2 commits May 7, 2026 16:22
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>
@giordano-lucas giordano-lucas merged commit 0894138 into main May 7, 2026
2 checks passed
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.

1 participant