feat: replace Anthropic API with Claude CLI for AI chat and agent panels (#159)
* feat: add claude CLI subprocess backend for AI panels Add claude_cli.rs module that spawns the local `claude` CLI as a subprocess instead of calling the Anthropic API directly. This removes the need for users to configure an API key — the CLI uses the user's existing Claude authentication. - find_claude_binary(): discovers claude in PATH or common locations - check_cli(): returns install/version status for the frontend - run_chat_stream(): spawns claude -p with stream-json for chat panel - run_agent_stream(): spawns claude with MCP vault tools for agent panel - Parses stream-json NDJSON events and emits typed Tauri events - Remove http:default capability (no longer calling APIs from frontend) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: replace Anthropic API with Claude CLI for AI chat and agent panels Remove direct Anthropic API calls and the entire tool-use loop from the frontend. Both AI Chat and AI Agent panels now delegate to the `claude` CLI subprocess via Tauri commands, streaming NDJSON events back to the UI. Key changes: - ai-chat.ts / ai-agent.ts: replace SSE/API streaming with Tauri invoke + listen - useAIChat / useAiAgent hooks: simplified to use CLI streaming callbacks - AIChatPanel / AiPanel: remove API key dialogs, model selectors, undo support - SettingsPanel: remove Anthropic key field (no longer needed) - claude_cli.rs: add comprehensive tests (37 total, 90% coverage) - mock-handlers: replace ai_chat with check_claude_cli / stream_claude_* stubs - Net -432 lines across 17 files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add --verbose flag to claude CLI subprocess args * chore: exclude search.rs and lib.rs from coverage (qmd integration + Tauri setup) --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -69,11 +69,10 @@ describe('SettingsPanel', () => {
|
||||
expect(screen.getByText(/stored locally/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows three key fields with labels', () => {
|
||||
it('shows two key fields with labels', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={emptySettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
expect(screen.getByText('Anthropic')).toBeInTheDocument()
|
||||
expect(screen.getByText('OpenAI')).toBeInTheDocument()
|
||||
expect(screen.getByText('Google AI')).toBeInTheDocument()
|
||||
})
|
||||
@@ -82,11 +81,9 @@ describe('SettingsPanel', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={populatedSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic') as HTMLInputElement
|
||||
const openaiInput = screen.getByTestId('settings-key-openai') as HTMLInputElement
|
||||
const googleInput = screen.getByTestId('settings-key-google-ai') as HTMLInputElement
|
||||
|
||||
expect(anthropicInput.value).toBe('sk-ant-api03-test123')
|
||||
expect(openaiInput.value).toBe('sk-openai-test456')
|
||||
expect(googleInput.value).toBe('')
|
||||
})
|
||||
@@ -95,14 +92,14 @@ describe('SettingsPanel', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={emptySettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic')
|
||||
fireEvent.change(anthropicInput, { target: { value: ' sk-ant-test ' } })
|
||||
const openaiInput = screen.getByTestId('settings-key-openai')
|
||||
fireEvent.change(openaiInput, { target: { value: ' sk-openai-test ' } })
|
||||
|
||||
fireEvent.click(screen.getByTestId('settings-save'))
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith({
|
||||
anthropic_key: 'sk-ant-test',
|
||||
openai_key: null,
|
||||
anthropic_key: null,
|
||||
openai_key: 'sk-openai-test',
|
||||
google_key: null,
|
||||
github_token: null,
|
||||
github_username: null,
|
||||
@@ -115,15 +112,15 @@ describe('SettingsPanel', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={populatedSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
// Clear the anthropic key field
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic')
|
||||
fireEvent.change(anthropicInput, { target: { value: ' ' } })
|
||||
// Clear the openai key field
|
||||
const openaiInput = screen.getByTestId('settings-key-openai')
|
||||
fireEvent.change(openaiInput, { target: { value: ' ' } })
|
||||
|
||||
fireEvent.click(screen.getByTestId('settings-save'))
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith({
|
||||
anthropic_key: null,
|
||||
openai_key: 'sk-openai-test456',
|
||||
openai_key: null,
|
||||
google_key: null,
|
||||
github_token: null,
|
||||
github_username: null,
|
||||
@@ -159,13 +156,13 @@ describe('SettingsPanel', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={emptySettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic')
|
||||
fireEvent.change(anthropicInput, { target: { value: 'sk-ant-test' } })
|
||||
const openaiInput = screen.getByTestId('settings-key-openai')
|
||||
fireEvent.change(openaiInput, { target: { value: 'sk-openai-test' } })
|
||||
fireEvent.keyDown(screen.getByTestId('settings-panel'), { key: 'Enter', metaKey: true })
|
||||
|
||||
expect(onSave).toHaveBeenCalledWith({
|
||||
anthropic_key: 'sk-ant-test',
|
||||
openai_key: null,
|
||||
anthropic_key: null,
|
||||
openai_key: 'sk-openai-test',
|
||||
google_key: null,
|
||||
github_token: null,
|
||||
github_username: null,
|
||||
@@ -185,11 +182,11 @@ describe('SettingsPanel', () => {
|
||||
render(
|
||||
<SettingsPanel open={true} settings={populatedSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const clearBtn = screen.getByTestId('clear-anthropic')
|
||||
const clearBtn = screen.getByTestId('clear-openai')
|
||||
fireEvent.click(clearBtn)
|
||||
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic') as HTMLInputElement
|
||||
expect(anthropicInput.value).toBe('')
|
||||
const openaiInput = screen.getByTestId('settings-key-openai') as HTMLInputElement
|
||||
expect(openaiInput.value).toBe('')
|
||||
})
|
||||
|
||||
it('shows keyboard shortcut hint in footer', () => {
|
||||
@@ -204,18 +201,18 @@ describe('SettingsPanel', () => {
|
||||
<SettingsPanel open={true} settings={populatedSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
// Verify initial state
|
||||
const anthropicInput = screen.getByTestId('settings-key-anthropic') as HTMLInputElement
|
||||
expect(anthropicInput.value).toBe('sk-ant-api03-test123')
|
||||
const openaiInput = screen.getByTestId('settings-key-openai') as HTMLInputElement
|
||||
expect(openaiInput.value).toBe('sk-openai-test456')
|
||||
|
||||
// Close and reopen with different settings
|
||||
rerender(
|
||||
<SettingsPanel open={false} settings={populatedSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const newSettings: Settings = { ...emptySettings, anthropic_key: 'new-key' }
|
||||
const newSettings: Settings = { ...emptySettings, openai_key: 'new-key' }
|
||||
rerender(
|
||||
<SettingsPanel open={true} settings={newSettings} onSave={onSave} onClose={onClose} themeManager={mockThemeManager} />
|
||||
)
|
||||
const updatedInput = screen.getByTestId('settings-key-anthropic') as HTMLInputElement
|
||||
const updatedInput = screen.getByTestId('settings-key-openai') as HTMLInputElement
|
||||
expect(updatedInput.value).toBe('new-key')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user