From ac59264520bb30a605f3d41e159b137c19058a2e Mon Sep 17 00:00:00 2001 From: Savas Neto Date: Tue, 3 Nov 2026 16:35:17 -0300 Subject: [PATCH 1/7] feat(providers): connect Claude with the user's API key; retire subscription logins Anthropic does not allow third parties to offer Claude.ai login, and the Claude subscription login used Claude Code's OAuth client id. It is gone: /claude login now connects the user's own Anthropic API key (validated against the Models API, kept only in secure storage, billed by Anthropic), and requests use x-api-key with no OAuth beta header. On startup, stored Claude OAuth logins are removed (API keys and other providers' accounts are kept) and the user sees a one-time notice. Claude subscription usage windows no longer apply to API keys. The GitHub Copilot login (/onboard-github) is unregistered: it used GitHub's Copilot OAuth app and VS Code headers and never served inference in Verboo mode. Stored Copilot tokens are ignored and purged from both the native vault and the plain-text fallback. Codex is unchanged except that third-party providers (Codex and the Anthropic key) now receive only a User-Agent instead of the Verboo session id, x-app and custom headers. Co-Authored-By: Claude Opus 5.5 --- UPSTREAM_SYNC.md | 16 + src/commands.ts | 6 +- src/commands/claude/claude.tsx | 256 ++++++------- src/commands/claude/index.ts | 2 +- src/commands/model/model.tsx | 2 +- src/components/Settings/usageProviders.ts | 12 +- .../useClaudeNativeOAuthFlow.test.tsx | 228 ----------- src/components/useClaudeNativeOAuthFlow.ts | 158 -------- .../useClaudeLoginRetiredNotification.ts | 6 + src/screens/REPL.tsx | 3 + src/services/api/claudeNativeConfig.ts | 18 +- src/services/api/claudeNativeModels.test.ts | 48 +-- src/services/api/claudeNativeModels.ts | 46 +-- src/services/api/claudeNativeOAuth.test.ts | 143 ------- src/services/api/claudeNativeOAuth.ts | 355 ------------------ src/services/api/claudeNativeUsage.test.ts | 27 +- src/services/api/claudeNativeUsage.ts | 114 +----- src/services/api/client.ts | 79 +--- .../api/openaiErrorClassification.test.ts | 5 +- src/services/api/openaiErrorClassification.ts | 2 +- src/services/oauth/verbooStartupAuth.ts | 30 +- src/utils/claudeLoginRetiredNotice.test.ts | 35 ++ src/utils/claudeLoginRetiredNotice.ts | 30 ++ .../claudeNativeCredentials.retire.test.ts | 121 ++++++ src/utils/claudeNativeCredentials.test.ts | 89 +++-- src/utils/claudeNativeCredentials.ts | 313 ++++++--------- src/utils/config.ts | 5 + .../githubModelsCredentials.hydrate.test.ts | 7 +- .../githubModelsCredentials.purge.test.ts | 52 +++ .../githubModelsCredentials.refresh.test.ts | 21 +- src/utils/githubModelsCredentials.ts | 35 +- src/utils/providerAccounts/credentials.ts | 37 +- src/utils/secureStorage/index.ts | 19 +- 33 files changed, 730 insertions(+), 1590 deletions(-) delete mode 100644 src/components/useClaudeNativeOAuthFlow.test.tsx delete mode 100644 src/components/useClaudeNativeOAuthFlow.ts create mode 100644 src/hooks/notifs/useClaudeLoginRetiredNotification.ts delete mode 100644 src/services/api/claudeNativeOAuth.test.ts delete mode 100644 src/services/api/claudeNativeOAuth.ts create mode 100644 src/utils/claudeLoginRetiredNotice.test.ts create mode 100644 src/utils/claudeLoginRetiredNotice.ts create mode 100644 src/utils/claudeNativeCredentials.retire.test.ts create mode 100644 src/utils/githubModelsCredentials.purge.test.ts diff --git a/UPSTREAM_SYNC.md b/UPSTREAM_SYNC.md index 205fc028c7..0888c7c240 100644 --- a/UPSTREAM_SYNC.md +++ b/UPSTREAM_SYNC.md @@ -53,6 +53,22 @@ em volta. Use `git grep "VERBOO-BRAND"` para localizar todos os pontos editados. - `src/commands/provider/` — arquivos **NÃO foram deletados** (upstream continua mexendo neles; deletar gera conflitos "deleted file modified upstream"). +#### `/onboard-github` (GitHub Copilot) desregistrado +- `src/commands.ts` — import e entry comentados, como o `/provider`. +- `src/utils/githubModelsCredentials.ts` — leitores e refresh retornam vazio + (`GITHUB_MODELS_LOGIN_RETIRED`); `purgeGithubModelsCredentials` apaga tokens + salvos (cofre nativo e arquivo em texto puro) na inicialização. +- `src/commands/onboard-github/` e `src/integrations/gateways/github.ts` **não + foram deletados**. + +#### Login Claude por assinatura removido (código Verboo, não upstream) +- O OAuth com o client id do Claude Code saiu: `claudeNativeOAuth.ts` e + `useClaudeNativeOAuthFlow.ts` foram deletados (eram nossos, não do upstream). +- `/claude login` conecta a chave de API da Anthropic do usuário; + `retireClaudeOAuthCredentials` remove logins OAuth antigos na inicialização. +- `src/services/api/client.ts` — provedores de terceiros (Codex, chave + Anthropic) recebem só `User-Agent`, sem headers de sessão do Verboo. + #### Mensagens reescritas - `src/utils/providerValidation.ts` (3 ocorrências) - `src/services/api/withRetry.ts` diff --git a/src/commands.ts b/src/commands.ts index ee0cc24a12..70f6aecb43 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -23,7 +23,9 @@ import diff from './commands/diff/index.js' import dream from './commands/dream/index.js' import ctx_viz from './commands/ctx_viz/index.js' import doctor from './commands/doctor/index.js' -import onboardGithub from './commands/onboard-github/index.js' +// VERBOO-BRAND: /onboard-github desregistrado — usava o app OAuth do GitHub +// Copilot e cabeçalhos do VS Code, e não funciona no modo Verboo. +// import onboardGithub from './commands/onboard-github/index.js' import knowledge from './commands/knowledge/index.js' import memory from './commands/memory/index.js' import help from './commands/help/index.js' @@ -318,7 +320,7 @@ const COMMANDS = memoize((): Command[] => [ memory, mobile, model, - onboardGithub, + // onboardGithub, // VERBOO-BRAND: ver import acima outputStyle, remoteEnv, plugin, diff --git a/src/commands/claude/claude.tsx b/src/commands/claude/claude.tsx index 738b435870..cb7c3d131d 100644 --- a/src/commands/claude/claude.tsx +++ b/src/commands/claude/claude.tsx @@ -1,8 +1,6 @@ import * as React from 'react' -import { Select } from '../../components/CustomSelect/select.js' -import { Dialog } from '../../components/design-system/Dialog.js' -import { useClaudeNativeOAuthFlow } from '../../components/useClaudeNativeOAuthFlow.js' +import TextInput from '../../components/TextInput.js' import { Box, Text, useInput } from '../../ink.js' import { useKeybinding } from '../../keybindings/useKeybinding.js' import { @@ -10,11 +8,6 @@ import { fetchClaudeNativeModels, getCachedClaudeNativeModels, } from '../../services/api/claudeNativeModels.js' -import { - CLAUDE_CONSUMER_TERMS_URL, - CLAUDE_LEGAL_URL, - CLAUDE_RISK_NOTICE_VERSION, -} from '../../services/api/claudeNativeConfig.js' import { getCachedCodexModels } from '../../services/api/codexModels.js' import { getCachedVerbooModels } from '../../services/api/verbooModels.js' import { ensureVerbooAuthenticated } from '../../services/oauth/verbooStartupAuth.js' @@ -23,166 +16,136 @@ import type { LocalJSXCommandOnDone, } from '../../types/command.js' import { + buildClaudeApiKeyCredential, clearClaudeNativeCredentials, - hasCurrentClaudeRiskAcceptance, + looksLikeAnthropicApiKey, readClaudeNativeCredentialsAsync, - type ClaudeNativeCredentialBlob, + saveClaudeNativeCredentials, } from '../../utils/claudeNativeCredentials.js' import { parseProviderLoginArgs } from '../../utils/providerAccounts/loginArgs.js' import { listProviderAccountSummaries } from '../../utils/providerAccounts/store.js' import { formatProviderAccountStatus } from '../../utils/providerAccounts/status.js' -function ClaudeLogin({ - acceptedAt, +type LoginState = + | { state: 'editing'; error?: string } + | { state: 'validating' } + +/** + * Connects the user's own Anthropic API key (Console). Requests made with it + * are billed by Anthropic to that key. The key is validated against the + * Models API before it is stored, and only ever kept in secure storage. + */ +function ClaudeApiKeyLogin({ onDone, reconnectLocalAccountId, }: { - acceptedAt: string onDone: LocalJSXCommandOnDone reconnectLocalAccountId?: string }) { - const handleAuthenticated = React.useCallback( - async ( - _tokens: unknown, - persistCredentials: (options?: { reconnectLocalAccountId?: string }) => void, - candidateCredentials: ClaudeNativeCredentialBlob, - ) => { - clearClaudeNativeModelsCache() - const models = await fetchClaudeNativeModels({ - force: true, - credentials: candidateCredentials, - }) - if (models.length === 0) { - throw new Error( - 'Login Claude concluído, mas a Models API não retornou modelos para esta conta.', - ) - } - try { - persistCredentials({ reconnectLocalAccountId }) - } catch (error) { - // Do not leave an in-memory Claude catalog unlocked when secure - // persistence failed. A failed optional login must not affect Verboo. - clearClaudeNativeModelsCache() - throw error - } - onDone( - `Login Claude concluído. ${models.length} modelo(s) adicional(is) liberado(s). O Verboo continua como prioridade; use /model para escolher.`, - { display: 'system' }, - ) - }, - [onDone], - ) - const status = useClaudeNativeOAuthFlow({ - additive: true, - reconnectLocalAccountId, - acceptedAt, - onAuthenticated: handleAuthenticated, - }) - const handleCancel = React.useCallback(() => { - status.cancel() - onDone('Login Claude cancelado. O Verboo continua disponível.', { + const [value, setValue] = React.useState('') + const [cursorOffset, setCursorOffset] = React.useState(0) + const [status, setStatus] = React.useState({ state: 'editing' }) + + const cancel = React.useCallback(() => { + onDone('Conexão Claude cancelada. O Verboo continua disponível.', { display: 'system', }) - }, [onDone, status]) + }, [onDone]) - useKeybinding('confirm:no', handleCancel, { context: 'Confirmation' }) + useKeybinding('confirm:no', cancel, { context: 'Confirmation' }) useInput((input, key, event) => { if (key.escape || (key.ctrl && input === 'c')) { event.stopImmediatePropagation() - handleCancel() + cancel() } }) - if (status.state === 'error') return {status.message} + const submit = React.useCallback( + async (raw: string) => { + const apiKey = raw.trim() + if (!looksLikeAnthropicApiKey(apiKey)) { + setStatus({ + state: 'editing', + error: 'Isso não parece uma chave de API da Anthropic (começa com sk-ant-).', + }) + return + } + setStatus({ state: 'validating' }) + const credentials = buildClaudeApiKeyCredential(apiKey) + try { + clearClaudeNativeModelsCache() + const models = await fetchClaudeNativeModels({ force: true, credentials }) + if (models.length === 0) { + setStatus({ + state: 'editing', + error: 'A chave foi aceita, mas a Anthropic não retornou nenhum modelo para ela.', + }) + return + } + const saved = saveClaudeNativeCredentials(credentials, { + localAccountId: reconnectLocalAccountId, + }) + if (!saved.success) { + clearClaudeNativeModelsCache() + setStatus({ + state: 'editing', + error: saved.warning ?? 'Não foi possível salvar a chave no armazenamento seguro.', + }) + return + } + onDone( + `Chave da Anthropic conectada (…${credentials.keyHint}). ${models.length} modelo(s) Claude liberado(s), cobrados pela Anthropic na sua chave. Use /model para escolher.`, + { display: 'system' }, + ) + } catch (error) { + clearClaudeNativeModelsCache() + const status = (error as { status?: number }).status + setStatus({ + state: 'editing', + error: + status === 401 || status === 403 + ? 'A Anthropic recusou essa chave. Confira a chave no Console da Anthropic.' + : `Não foi possível validar a chave: ${error instanceof Error ? error.message : String(error)}`, + }) + } + }, + [onDone, reconnectLocalAccountId], + ) + return ( - Login Claude nativo + Conectar Claude com sua chave de API - Entre com sua conta Claude. As credenciais ficam somente no armazenamento - seguro do Verboo Code. + Cole uma chave de API da Anthropic (console.anthropic.com → API Keys). O + uso dos modelos Claude é cobrado pela Anthropic nessa chave. A chave fica + somente no armazenamento seguro do Verboo Code. - {status.state === 'starting' ? ( - Preparando o login no navegador… - ) : status.browserOpened === false ? ( - <> - Abra esta URL para continuar: - {status.authUrl} - + {status.state === 'validating' ? ( + Validando a chave com a Anthropic… ) : ( - <> - Conclua o login no navegador. - {status.authUrl} - + + Chave: + void submit(value)} + cursorOffset={cursorOffset} + onChangeCursorOffset={setCursorOffset} + columns={60} + focus={true} + showCursor={true} + mask="*" + /> + )} - Pressione Esc ou Ctrl+C para cancelar. + {status.state === 'editing' && status.error ? ( + {status.error} + ) : null} + Enter para confirmar · Esc para cancelar ) } -function ClaudeRiskDisclosure({ - onDone, - reconnectLocalAccountId, -}: { - onDone: LocalJSXCommandOnDone - reconnectLocalAccountId?: string -}) { - const [acceptedAt, setAcceptedAt] = React.useState(null) - if (acceptedAt) { - return ( - - ) - } - - const cancel = () => - onDone('Claude não habilitado. O Verboo continua disponível.', { - display: 'system', - }) - - return ( - - - - A Anthropic informa que o OAuth de assinaturas Claude é destinado ao - Claude Code e a outros aplicativos nativos. Ela não permite que - terceiros ofereçam login Claude.ai nem roteiem solicitações usando - credenciais Free, Pro ou Max. - - - O Verboo Code não é afiliado nem endossado pela Anthropic. Este uso - pode deixar de funcionar sem aviso e pode resultar em limitação ou - suspensão da conta. Prompts, código e resultados de ferramentas serão - enviados diretamente à Anthropic. - - - O aceite registra apenas sua ciência e não concede permissão da Anthropic. - - Política: {CLAUDE_LEGAL_URL} - Termos: {CLAUDE_CONSUMER_TERMS_URL} -