Skip to content

✨ feat: Add swappable AI providers#9

Merged
bdougie merged 5 commits intomainfrom
feat/swappable-ai-providers
Mar 17, 2026
Merged

✨ feat: Add swappable AI providers#9
bdougie merged 5 commits intomainfrom
feat/swappable-ai-providers

Conversation

@bdougie
Copy link
Copy Markdown
Contributor

@bdougie bdougie commented Mar 17, 2026

Summary

  • Adds a provider registry so sweeper can dispatch fixes via Claude CLI, Codex CLI, or Ollama HTTP API
  • Ollama executor sends file content in the prompt, extracts unified diffs from responses, and applies them with patch -p1
  • Provider/model/token usage is recorded in telemetry JSONL (fix_attempt events) for all providers
  • Ollama parses prompt_eval_count and eval_count from the API response for token tracking

Test plan

  • go build ./... passes
  • go test ./... passes (90.2% coverage)
  • End-to-end test with --provider ollama --model qwen2.5-coder:7b against a Go project with lint issues
  • Verified .sweeper/telemetry/*.jsonl contains provider, model, prompt_tokens, output_tokens in fix_attempt events
  • Confirmed ~/.tapes/tapes.db is not modified (read-only access, integrity check passes)

bdougie added 4 commits March 17, 2026 10:19
Introduce a provider registry so sweeper can use different AI backends
instead of being hardcoded to Claude. Well-scoped subagent tasks like
lint fixes can now run on smaller/cheaper models via Ollama or use
alternative CLI harnesses like Codex.

Two provider categories:
- CLI (claude, codex): have built-in file tools, sweeper sends prompts
- API (ollama): text-in/text-out, sweeper includes file content in
  prompts and applies returned unified diffs via patch

New flags: --provider, --model, --api-base
VM isolation validated to only work with CLI providers.
1. Remove unused allowedTools param from NewCodexExecutor — codex CLI
   has no tool restriction mechanism
2. Add 100KB size cap to readFileContent to prevent blowing up API
   token limits on large files
3. Extract availableLocked() to avoid reentrant RLock in registry
4. Validate --provider early in cmd/run.go so typos error instead of
   silently falling back to claude; agent.New logs a warning on fallback
5. Remove duplicate agentPreamble from ollama system message — prompt
   builders already include it
6. Remove --no-backup-if-mismatch from patch invocation (macOS
   incompatible); add comment about path assumptions
7. Replace custom contains() helper with strings.Contains in agent tests
1. extractDiff: fall back to plain ``` blocks when model omits the
   "diff" language tag — matches blocks starting with "diff " or "--- "
2. parseMinimal: skip go compiler package headers (": # testproject")
   that were being parsed as lint issues and sent to the model
3. normalizeIssuePaths: resolve linter output paths relative to the
   target dir so "../../../tmp/project/main.go" and "./main.go" merge
   into a single fix task instead of splitting into two
Record provider, model, prompt_tokens, and output_tokens on every
worker.Result so the JSONL telemetry captures per-provider stats.
Ollama token counts are parsed from prompt_eval_count/eval_count in
the API response. Claude and codex set provider name only (no token
data available from CLI invocations).
@bdougie bdougie changed the title feat: swappable AI provider system (claude, codex, ollama) ✨ feat: Add swappable AI providers Mar 17, 2026
…viders

# Conflicts:
#	pkg/worker/claude.go
#	pkg/worker/codex.go
#	pkg/worker/ollama.go
@bdougie bdougie merged commit 65604e5 into main Mar 17, 2026
6 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