agentleFS
DjarvurDjarvur/ddg-search/CLAUDE.md

ddg-search

CLAUDE.md12 starsChanged 3 months agoMITView on GitHub

After any change to the code, run all three, in this order, and fix everything they report before considering the work done: This mirrors the CI pipeline (.github/workflows/ci.yml: lint → test → build, build gated on the other two). Do not report a change as finished while any of the three fails. mise lint runs with --fix, so it may rewrite files — re-read anything you edited after running it. Tooling versions come from .mise.toml — golangci-lint is pinned to…

  • Reads credentials
  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After any change to the code, run all three, in this order, and fix everything they report before considering the work done:

    line 7
  2. Distinctive:

    Every exported identifier needs a doc comment, and every package needs a package comment.

    line 93

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Mandatory check after every code change

After any change to the code, run all three, in this order, and fix everything they report before considering the work done:

mise lint     # golangci-lint run --fix ./...
mise test     # go test -cover -race ./...
go build ./...

This mirrors the CI pipeline (.github/workflows/ci.yml: lint → test → build, build gated on the other two). Do not report a change as finished while any of the three fails. mise lint runs with --fix, so it may rewrite files — re-read anything you edited after running it.

Commands

# Single test / subset
go test -run TestSearchIntegrationBasic ./internal/search/
go test -race -v ./internal/perplexity/

# Coverage the way CI measures it (threshold: total >= 50%, CI fails below)
go test -coverprofile=coverage.out -covermode=atomic -race ./...
go tool cover -func=coverage.out | grep total

# Build the three binaries individually
go build -o bin/ddg-search ./cmd/ddg-search
go build -o bin/page-dump ./cmd/page-dump
go build -o bin/perplexity-search ./cmd/perplexity-search

# Vulnerability scan (weekly in CI)
govulncheck ./...

Tooling versions come from .mise.toml — golangci-lint is pinned to GOLANGCI_VERSION (v2.13.2) and installed via go install, isolated from any system-wide golangci-lint. Keep that pin and the version in .github/workflows/ci.yml in sync.

Note: there is no Makefile — use the go build commands above.

Tests that talk to the network

internal/perplexity/integration_test.go hits the real Perplexity API and self-skips unless both PERPLEXITY_API_KEY and INTEGRATION_TEST=true are set. internal/search/integration_test.go, despite the name, is hermetic: it serves internal/search/testdata/*.html fixtures from an httptest server. There are no build tags anywhere — plain go test ./... is always safe.

Architecture

Three independent CLI binaries under cmd/, each a thin urfave/cli/v3 wrapper (flag parsing, env lookup, Fprintln(os.Stdout, …)) over one internal/ package. All logic lives in internal/; keep main.go files free of it. All three emit Markdown on stdout and debug logs on stderr, because the output is meant to be piped into an LLM.

BinaryPackageTransport
ddg-searchinternal/search (+ internal/config)scrapes html.duckduckgo.com/html with goquery
page-dumpinternal/dumpfetches a URL, converts via html-to-markdown/v2
perplexity-searchinternal/perplexityPerplexity chat API, PERPLEXITY_API_KEY required

The two retry stacks are deliberately separate

internal/search and internal/perplexity each define their own RetryOptions type, DefaultRetryOptions(), ErrRateLimited/ErrMaxRetries, isRateLimited(), and calculateDelay(). internal/config serves only the DuckDuckGo side. This duplication is intentional — the two services have different retryable-status semantics (DDG treats HTTP 202 as a rate-limit signal; Perplexity distinguishes 401/400/402 as non-retryable and breaks out of the loop). Do not unify them without a spec change, and when touching retry behaviour, check whether the change belongs to one service or both.

Jitter also differs on purpose: search uses math/rand (with a //nolint:gosec), perplexity uses crypto/rand.

perplexity.Client.Do needs an explicit method and path

Pass both to Do; never build a request and rely on resty's Send(). Send() calls Execute(r.Method, r.URL), and with those empty resty joins the empty path onto the base URL while Go's http.NewRequest defaults an empty method to GET — the request silently becomes GET https://api.perplexity.ai/ instead of POST /chat/completions, and since checkAPIError has no 404 case the wrong response parses as a valid one. That was a live bug until it was fixed; TestSearchSendsPostToChatCompletions guards it.

The answer lives at choices[0].message.content (guarded by ErrNoChoices), and sources come from search_results, falling back to the deprecated top-level citations array.

Retry nesting on the DuckDuckGo path (a real gotcha)

Searcher.Search (search.go:41) loops up to MaxRetries+1 times, and each attempt calls Client.Do (client.go:76), which itself loops up to MaxRetries+1 times. The retry counts multiply: with the default --max-retries 3, a persistently rate-limited query can issue up to 16 HTTP requests. Client.Do signals exhaustion with ErrMaxRetries, and the outer loop treats only that error as retryable — every other error returns immediately. Keep that contract if you touch either loop.

Rate-limit detection in HTML is switched off

Parser.FindRateLimitIndicator (parser.go:65) ignores its argument and always returns "", disabling the outer loop's HTML-body check. This is deliberate: the indicator words ("captcha", "blocked", "anomaly", …) produced false positives when they appeared in legitimate result snippets. The keyword-scanning helpers that used to hold this logic (Parser.IsRateLimitPage, Parser.IsEmptyResults) were dead and have been removed; rate limiting is detected from the HTTP status alone. Re-enabling body-text detection needs a snippet-safe heuristic, not just un-stubbing the function.

DuckDuckGo results are read from .result__a anchors, and hrefs are unwrapped from DDG's //duckduckgo.com/l/?uddg=… redirect form by Parser.extractURL. That unwrap must not decode the value it gets from url.Values.Get — it is already percent-decoded, and decoding twice corrupts any target URL containing %xx or +.

Skills

skills/ddg-search/ and skills/perplexity-search/ package the binaries as Claude Code skills. The skill.yaml command: fields invoke the binaries by bare name, so they assume the binaries are on PATH (go install github.com/Djarvur/ddg-search/cmd/<name>@latest). Changing a CLI flag name or the stdout format is a breaking change for these skills — update skill.yaml and SKILL.md in the same change.

Spec-driven workflow (openspec)

This repo uses openspec (openspec/config.yaml, schema: spec-driven). openspec/specs/<capability>/spec.md are the living requirements, written as ### Requirement: blocks with #### Scenario: WHEN/THEN clauses; openspec/changes/archive/<date>-<slug>/ holds completed change proposals (proposal.md, design.md, tasks.md, plus the spec deltas that were merged).

The project context in openspec/config.yaml states the working rules: write tests first, aim for 50% coverage, leave no linter errors, and pass go build / mise lint / mise test after every change. When changing behaviour, check the matching spec under openspec/specs/ and update it alongside the code.

Lint conventions

.golangci.yml enables all linters, then disables a short list with reasons inline. Practical consequences when writing code here:

  • funlen caps functions at 80 lines / 50 statements and gocognit at complexity 15 — the existing code splits helpers out (waitForRetry, searchAttempt, debugRateLimitReason) specifically to stay under these. Prefer extracting a helper over adding a //nolint.
  • wsl_v5 is active: blank line required before return and around blocks. This is the most common lint failure; mise lint --fix handles it.
  • Every exported identifier needs a doc comment, and every package needs a package comment.
  • Errors are sentinel var Err… = errors.New(…) values wrapped with %w; never return bare errors.New/fmt.Errorf strings from a new code path where a sentinel would let callers use errors.Is.
  • Existing //nolint directives all carry a justification comment — match that style if you must add one.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.