refactor: migrate all direct Anthropic SDK usage to provider abstraction#7612
Conversation
- Create providers/anthropic-send-message.ts helper with lazy provider resolution, timeout utilities, and response extraction helpers - Migrate 12 production files from `new Anthropic()` + `client.messages.create()` to `getAnthropicProvider()` + `provider.sendMessage()` - Update clarification-resolver and contradiction-checker tests to mock the provider helper instead of @anthropic-ai/sdk - Add guard test to prevent future direct SDK imports in production code Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db93acab85
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try { | ||
| grepOutput = execSync( | ||
| `git grep -l "@anthropic-ai/sdk" -- 'assistant/src/**/*.ts'`, | ||
| { encoding: 'utf-8', cwd: process.cwd() + '/../..' }, |
There was a problem hiding this comment.
Resolve git grep from repository root
The new guard test computes cwd as process.cwd() + '/../..', which points outside this repo under the normal workflow (cd assistant && bun test from AGENTS.md), so git grep errors with fatal: not a git repository and the test fails even when there are no violations. I verified this by running cd assistant && bun test src/__tests__/no-direct-anthropic-sdk-imports.test.ts, which fails before checking imports.
Useful? React with 👍 / 👎.
| try { | ||
| grepOutput = execSync( | ||
| `git grep -l "@anthropic-ai/sdk" -- 'assistant/src/**/*.ts'`, | ||
| { encoding: 'utf-8', cwd: process.cwd() + '/../..' }, |
There was a problem hiding this comment.
🟡 Guard test cwd navigates one directory too far above the repo root
The no-direct-anthropic-sdk-imports.test.ts guard test sets the cwd for git grep to process.cwd() + '/../..', which navigates two directories up from process.cwd(). Per the project conventions (cd assistant && bun test), process.cwd() is {repo}/assistant/. Going up two levels lands at {repo}/.., which is outside the git repository.
Root Cause and Impact
When git grep is executed from outside the git repository, it exits with code 128 ("fatal: not a git repository"). The catch block only handles exit code 1 (no matches — the happy path). Since 128 !== 1, the error is re-thrown, causing the test to always fail regardless of whether violations exist:
// assistant/src/__tests__/no-direct-anthropic-sdk-imports.test.ts:23
cwd: process.cwd() + '/../..'
// From {repo}/assistant/ this resolves to {repo}/../ — outside the repoThe fix should use '/..' (one level up) instead of '/../..' (two levels up) to navigate from {repo}/assistant/ to {repo}/.
Impact: The guard test cannot work as intended — it will always throw an error instead of detecting direct @anthropic-ai/sdk imports in production files.
| { encoding: 'utf-8', cwd: process.cwd() + '/../..' }, | |
| { encoding: 'utf-8', cwd: process.cwd() + '/..' }, |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
providers/anthropic-send-message.tshelper module withgetAnthropicProvider(),createTimeout(),extractText(),extractAllText(),extractToolUse(),userMessage(), anduserMessageWithImage()utilities@anthropic-ai/sdk(new Anthropic,client.messages.create) to go through the provider abstraction (Provider.sendMessage) — covers daemon classifiers, watch handlers, messaging triaging/summarization, memory extraction/contradiction/ranking/summarization, config icon generation, and media keyframe analysisno-direct-anthropic-sdk-imports.test.ts) that fails if any new production file imports@anthropic-ai/sdkdirectlyOriginal prompt
/Users/noaflaherty/Repos/vellum-ai/vellum-assistant/.private/plans/provider-sendmessage-migration-remaining-direct-anthropic-one-pr-plan-2026-02-24.md
🤖 Generated with Claude Code