Repository navigation
feat(assistant): connect Claude by pasting a token from claude setup-token or an API key, tested before it is saved (abilityai/trinity-enterprise#1354) - #4752
Conversation
…, no terminal (abilityai/trinity-enterprise#1354) The instance runs the sign-in `claude setup-token` runs (PKCE, Claude Code's public client id, the manual redirect, scope user:inference, a one-year token) with the instance as the client, so a person with only a browser can connect their Claude subscription: * POST /api/subscriptions/claude-sign-in makes a fresh link for the caller; the PKCE verifier stays on the instance (Redis, bound to the caller, 15 min, single use). * POST /api/subscriptions/claude-sign-in/exchange takes the pasted `<code>#<state>`, spends the link, exchanges the code and registers the token as `primary` through POST /api/subscriptions' own handler, so encryption, the first-credential connect of waiting agents and the #2572 sweep are unchanged. The token is never returned. * Refusals are named and store nothing (code_incomplete, sign_in_expired, code_rejected, anthropic_unavailable, unexpected_answer, store_unavailable); a missing encryption key is refused before the code is spent. Person + admin only. No code, state or token in any log line. The assistant's Claude card (the CLAUDE_SIGN_IN seam left by #4736) now shows three steps with the instance's link, the API key as the alternative in the same field, and a fresh link after a refused paste. The instance's Claude card is held as CLAUDE_SUBSCRIPTION, which the enterprise side routes by shape (sign-in code, sk-ant-oat01-, sk-ant-api). The enterprise pin moves to that change (trinity-enterprise branch feature/ent1354-claude-sign-in). Tests: tests/unit/test_ent1354_claude_sign_in.py (21); assistantClaudeSignIn.mount.spec.js (5, mounted through the real widget and store). Mutations: dropping the per-person binding turns test_another_persons_link_does_not_finish_for_you red; dropping the pre-exchange encryption check turns test_the_code_survives_a_missing_encryption_key red. Two existing assertions updated for the new name (assistantCredentialField, assistantWidget). Co-Authored-By: Claude Opus 5.5 <[email protected]>
/validate-pr: REQUEST CHANGESValidated together with the companion enterprise PR, from fresh clones (PR head What holds
Must change before merge
Warnings and suggestions
API-key path (rider 5). An API key pasted into the same card is still saved through the same Needs a person. These are already listed in the body: one real sign-in end to end, and the policy question of the instance acting as the CLI's OAuth client. 🤖 Generated with Claude Code |
…swers inside the assistant's wait (abilityai/trinity-enterprise#1354) - Provider timeout 30 s -> 8 s: the code is spent when the exchange starts, and the assistant's loopback gives up at 30 s with "may or may not have been stored"; the provider now ends in a named refusal well before that. - A successful exchange writes a credentials/subscription_signed_in audit row: subscription name and actor only, never the token or the code. - A paste that is plainly an API key (sk-…, ant-api…) is answered api_key_not_code with the API-key format message, without spending the link. - Tests: assert_person on both routes is pinned by principals that pass assert_admin (system scope, agent-vouched) — red with the check deleted; every refusal the exchange can give is checked for the paste; the timeout is pinned against the enterprise side's when it is mounted. - Enterprise pointer -> 3adcdca (the #1376 branch head: token tested before it is saved). Red before the fix: TestAnApiKeyInTheCodeField (x3), TestTheAuditRow, and test_the_provider_timeout_is_well_under_the_assistants_wait. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… remove the instance sign-in (abilityai/trinity-enterprise#1354) Ruled 2026-11-24 after legal's read: "we will go with terminal key creation and pasting into system." The instance no longer starts a sign-in with the provider or exchanges a code. Removed, not flagged off: - services/claude_sign_in_service.py (PKCE link, the per-person Redis-held verifier, the code exchange, the provider client id and endpoints) - POST /api/subscriptions/claude-sign-in and .../claude-sign-in/exchange, their models (ClaudeSignInLink, ClaudeSignInExchange) and the subscription_signed_in audit row - tests/unit/test_ent1354_claude_sign_in.py and its registry entry - the store's claudeSignInLink and the card's link fetch - the api-endpoints / feature-flow rows for the two routes Kept: the card, now three short steps (open a terminal on your own computer, run claude setup-token, paste the token it prints here) with an Anthropic API key as the alternative in the same field. Routing by shape, test-before-save, the plain refusals (a '#' paste is told a token is expected) and the card's audit row live in the enterprise pin, bumped to f88740b (abilityai/trinity-enterprise#1376). Tests: assistantClaudeToken.mount.spec.js (renamed from assistantClaudeSignIn) + credential field + widget + ratchets, 163 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
/validate-pr: REQUEST CHANGES (second validation)Validated together with the companion enterprise PR, from fresh clones, at this PR's head The code is right. What blocks the merge is the PR's own text and the pointer. Checks
Tier 1 and Lane C checks on the PR are green, including Blockers
Re point 7: the re-pin is not the only blocker. Items 1, 3 and 4 also stand. The companion side carries the open product question on the API-key branch. Question for the operator: the pasted API key is saved first and checked after, so a well-formed but wrong key replaces a working one. This is the unchanged Settings Save behaviour and the unchanged API-key card. Should the Claude card test an API key before saving it too, as the ruling's "tested, then registered" reads? |
…i/trinity-enterprise#1354) Co-Authored-By: Claude Opus 5.5 <[email protected]>
… to main (abilityai/trinity-enterprise#1354) Co-Authored-By: Claude Opus 5.5 <[email protected]>
vybe
left a comment
There was a problem hiding this comment.
Second independent validation found the code meets the ruling; its remaining points are closed and the submodule pointer sits on the merged enterprise commit. All required checks green. Squash merge.
For abilityai/trinity-enterprise#1354 (the private issue is closed by hand at release). Pairs with the trinity-enterprise PR on the same branch name.
What a person sees
The first session reaches the Claude step, and the assistant's credential card shows three short steps:
claude setup-tokenand follow what it says.Below that: Using an Anthropic API key instead? Paste it here. The masked field takes either one. The instance starts no sign-in of its own and exchanges no code. It only receives the token or key the person pastes.
What the instance does with the paste
This is the enterprise module, through the routes the Settings page already uses, on this instance and as the person:
POST /api/subscriptions/test, then registered asprimarythroughPOST /api/subscriptions, but only after the test passes.POST /api/settings/api-keys/anthropic/test, then saved throughPUT /api/settings/api-keys/anthropic, but only after the test passes.The Settings page is not changed.
Changes in this repo
CLAUDE_TOKEN_CARDreplaces the unusedCLAUDE_SIGN_INseam (feat(assistant): the assistant leads the first session (abilityai/trinity-enterprise#1355) #4736).claudeHelp()renders the three steps plus the API-key alternative, and the instance's Claude card is held asCLAUDE_SUBSCRIPTION(assistantCards.js,firstSession.js,AssistantCredentialField.vue). An agent's ownANTHROPIC_API_KEYcard is unchanged.docs/memory/requirements/credentials.md§3.8a.maincommit before merging this one. Without it, the instance refusesCLAUDE_SUBSCRIPTIONand the card closes.Tests
assistantClaudeToken.mount.spec.js: mounted through the real widget and store. It covers the three steps and the API-key alternative, and checks that a refused paste sends the assistant nothing. It also checks that no turn, session storage or local storage holds the value.assistantCredentialField,assistantWidget).🤖 Generated with Claude Code
Fixes abilityai/trinity-enterprise#1354