Skip to content

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

Merged
vybe merged 7 commits into
devfrom
feature/ent1354-claude-sign-in
Nov 24, 2026
Merged

vybe merged 7 commits into
devfrom
feature/ent1354-claude-sign-in

Conversation

@trinity-ability

@trinity-ability trinity-ability commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

Squash-merge only. The branch history still holds an earlier design that was removed. A merge commit would bring that code into dev.

What a person sees

The first session reaches the Claude step, and the assistant's credential card shows three short steps:

  1. Open a terminal on your own computer.
  2. Run claude setup-token and follow what it says.
  3. Paste the token it prints here and press Save.

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:

  • Subscription token: tested with POST /api/subscriptions/test, then registered as primary through POST /api/subscriptions, but only after the test passes.
  • API key: tested with POST /api/settings/api-keys/anthropic/test, then saved through PUT /api/settings/api-keys/anthropic, but only after the test passes.
  • Refusal: nothing is stored. A provider that cannot be reached answers "check unavailable" (503), not a rejection. A pasted sign-in code, or anything that is not a token or key, is refused in plain words.
  • The value: it never reaches the chat, a model, a log line or an execution record. A registration writes one audit row with the name and the actor.

The Settings page is not changed.

Changes in this repo

  • Frontend: CLAUDE_TOKEN_CARD replaces the unused CLAUDE_SIGN_IN seam (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 as CLAUDE_SUBSCRIPTION (assistantCards.js, firstSession.js, AssistantCredentialField.vue). An agent's own ANTHROPIC_API_KEY card is unchanged.
  • No backend file changes: the routes above already exist.
  • docs/memory/requirements/credentials.md §3.8a.
  • The enterprise pointer is on the companion PR's head. Merge the enterprise PR first, then re-pin this branch to its merged main commit before merging this one. Without it, the instance refuses CLAUDE_SUBSCRIPTION and 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.
  • Two existing assertions were updated for the new name (assistantCredentialField, assistantWidget).
  • The enterprise side has the test-first order, the 503 on an unreachable provider, the refusals and the audit row: 210 tests pass across its assistant, credential and onboarding suites.

🤖 Generated with Claude Code

Fixes abilityai/trinity-enterprise#1354

…, 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]>
@trinity-ability

Copy link
Copy Markdown
Contributor Author

/validate-pr: REQUEST CHANGES

Validated together with the companion enterprise PR, from fresh clones (PR head 17fc4b0, companion head 8fbd6a5). Lane C, because the enterprise pointer moves.

What holds

  • Secrets stay out of the model and the records. The pasted code, the PKCE verifier and the token never reach the assistant's turn (it only receives Provided: <name> for <where>), the response, an error detail or a log line. Every refusal is raise … from None and carries only a refusal name. A 422 on the request body has its input stripped by error_handlers.py.
  • Who may sign in. Both routes require a person who is an admin (assert_person + assert_admin). The kept link is bound to the user who started it, deleted on its first use (GETDEL) and expires after 15 minutes. A replayed code, someone else's link, or an unknown or garbled state is refused as sign_in_expired.
  • Where the instance calls. The token endpoint is a fixed constant. httpx does not follow redirects by default. The pasted text selects only a key under the claude_sign_in: prefix and cannot change any URL.
  • A failed code changes nothing. A half-copied code is refused before the link is spent. A rejected, expired or odd answer is refused before register_subscription, so an existing subscription stays as it was. A missing encryption key is refused before the code is spent.
  • I re-ran the tests: 21/21 pass in test_ent1354_claude_sign_in.py. The assistant frontend specs and the ratchets pass, 158 tests. The companion's tests pass, 36.
  • Mutations that turn a test red: removing the person binding, single use, the TTL, the admin gate on start, logging the code or token, and storing on a refused code.

Must change before merge

Warnings and suggestions

  • /review has not run on this branch, so this report does not cover a structural pass.
  • Tier 1 pytest (head, seed 12345) was still pending when I checked. journey-smoke, e2e and prod-image-smoke are green, and dev-ci is green.
  • Another admin who knew a link's state could spend that link. They are still refused, but the owner has to open a fresh link. This is acceptable, but worth knowing.
  • _load_for_test is a test-only helper inside production code.
  • The model asked for the API-key name, but the turn now says Provided: CLAUDE_SUBSCRIPTION …. Check that the gateway prompt accepts the new name.
  • The card text "is already set … Saving replaces it" is shown when only an API key is set. Signing in does not replace that key; it adds the subscription.
  • §5.5: the covering module subscriptions.ts is untouched. That is fine, because the new routes are person-only and no MCP key can call them. Saying so in the router's # mcp: header would record it.
  • §2.2a: this run added the closing keyword Fixes abilityai/trinity-enterprise#1354. It is cross-tracker, so set status-in-dev by hand after merge.

API-key path (rider 5). An API key pasted into the same card is still saved through the same PUT and checked through the same test route. Only the card's name changes. A value without an sk-ant- prefix now gets the "not the whole code" refusal instead of the "API keys start with sk-ant-" one.

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

@trinity-ability trinity-ability added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 24, 2026
Trinity Agent (trinity) and others added 2 commits November 24, 2026 04:08
…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]>
@github-actions github-actions Bot removed the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 24, 2026
Trinity Agent (trinity) and others added 2 commits November 24, 2026 04:52
… 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]>
@trinity-ability

Copy link
Copy Markdown
Contributor Author

/validate-pr: REQUEST CHANGES (second validation)

Validated together with the companion enterprise PR, from fresh clones, at this PR's head c240353f1. The branch is level with dev 65a2fa586. Lane C (the submodule pointer).

The code is right. What blocks the merge is the PR's own text and the pointer.

Checks

# Check Result
1 Removed sign-in is gone ✅ in code. Every backend, docs and test file the sign-in commits touched is byte-equal to dev: models.py, routers/subscriptions.py, services/claude_sign_in_service.py (absent), stores/assistant.js, api-endpoints.md, subscription-management.md, both sign-in test files. A grep for the sign-in routes, service, provider endpoints, client id, PKCE and verifier finds nothing in src/, docs/ or tests/. ❌ in the PR title and body: both still describe the removed design (see blocker 1).
2 A pasted value stays out of the model, chat, records and logs ✅ The card sends the value only to the instance and tells the assistant only Provided: CLAUDE_SUBSCRIPTION. assistantClaudeToken.mount.spec.js checks that no turn, session storage or local storage holds the value, and that a refused paste sends the assistant nothing. The enterprise side has the same check for log lines and refusal details.
3 Token tested before it is saved ✅ Order is test, then register. A failed or unavailable test refuses before the register call, so primary and the agents on it are untouched. Mutation: disabling the test-first step turns 5 enterprise tests red. API key: see the question below.
4 Who can register ✅ The card route is interactive-admin. The instance routes it calls (POST /api/subscriptions, /test, PUT /api/settings/api-keys/anthropic) are assert_admin, which refuses agent, connector and other non-person scopes.
5 Audit row ✅ target_id is the name, plus actor, IP and request id, and a constant ask_id. The value is not in it. It is written only after a successful save, never on a refusal.
6 #4736 first session and #4749 local agents on the merged code ✅ Both are in this branch's base. 14 spec files, 294 tests pass: first-run, first-session, assistant widget and card, localMove.spec.js, plus the raw-color, loading-gate and source-text ratchets.
7 Merge order See blocker 2.

Tier 1 and Lane C checks on the PR are green, including journey-smoke, e2e, regression diff and prod-image-smoke. dev-ci is success and no dev-ci red issue is open. The secret, email, IP, file-mode and host-path greps are clean. check_journey_impact.py passes (no declaration). No gated handler is touched in this repo (§4.11 ➖).

Blockers

  • 1. Rewrite the title and body. The title still says "sign-in link and a pasted code, no terminal". The body still documents the removed sign-in: its routes, its service, the provider endpoints and client id, and a policy question that is now moot. With a squash merge the title becomes the commit on dev. Describe what the branch does now: three terminal steps, a pasted token or API key, test before register.
  • 2. Re-pin the submodule. It points at f88740be1, which is only on the companion PR's branch. Merge the companion first, then pin to the commit it creates on main. Without the companion, the instance refuses the new credential name and the card closes.
  • 3. Squash-merge only. The branch history holds the removed sign-in code. A merge commit would bring it into dev.
  • 4. Expired state (acceptance criterion 6). The card reports connected or not connected. An expired subscription is left to the existing health path, and no follow-up issue is named. Name one, or show where an expired token gets the same card again.

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?

@trinity-ability trinity-ability added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 24, 2026
…i/trinity-enterprise#1354)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot removed the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 24, 2026
@trinity-ability trinity-ability changed the title feat(assistant): connect Claude with a sign-in link and a pasted code, no terminal (abilityai/trinity-enterprise#1354) 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) Nov 24, 2026
… to main (abilityai/trinity-enterprise#1354)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@vybe vybe left a comment

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.

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.

@vybe
vybe merged commit 8d7ca11 into dev Nov 24, 2026
28 checks passed
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.

2 participants