Skip to content

refactor: migrate all direct Anthropic SDK usage to provider abstraction#7612

Merged
noanflaherty merged 1 commit into
mainfrom
do/provider-sendmessage-migration
Feb 24, 2026
Merged

refactor: migrate all direct Anthropic SDK usage to provider abstraction#7612
noanflaherty merged 1 commit into
mainfrom
do/provider-sendmessage-migration

Conversation

@noanflaherty
Copy link
Copy Markdown
Contributor

@noanflaherty noanflaherty commented Feb 24, 2026

Summary

  • Creates providers/anthropic-send-message.ts helper module with getAnthropicProvider(), createTimeout(), extractText(), extractAllText(), extractToolUse(), userMessage(), and userMessageWithImage() utilities
  • Migrates all 12 production files that directly used @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 analysis
  • Updates 2 test files to mock the provider helper instead of the raw SDK
  • Adds a guard test (no-direct-anthropic-sdk-imports.test.ts) that fails if any new production file imports @anthropic-ai/sdk directly

Original 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


Open with Devin

- 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>
@noanflaherty noanflaherty merged commit 5128f0b into main Feb 24, 2026
@noanflaherty noanflaherty deleted the do/provider-sendmessage-migration branch February 24, 2026 05:40
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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() + '/../..' },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

try {
grepOutput = execSync(
`git grep -l "@anthropic-ai/sdk" -- 'assistant/src/**/*.ts'`,
{ encoding: 'utf-8', cwd: process.cwd() + '/../..' },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 repo

The 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.

Suggested change
{ encoding: 'utf-8', cwd: process.cwd() + '/../..' },
{ encoding: 'utf-8', cwd: process.cwd() + '/..' },
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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