Skip to content

Add identity commands - #27

Closed
miqui wants to merge 3 commits into
mainfrom
identity-commands
Closed

miqui wants to merge 3 commits into
mainfrom
identity-commands

Conversation

@miqui

@miqui miqui commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Part of #7. This PR covers the identity commands; adapt run --identity follows in a separate PR.

Summary

  • adapt identities list | get | create | update | enable | disable | delete manage Platform identities (/v1/identities, from platform 640c00b).
  • adapt identities permissions IDENTITY [--allow RESOURCE:ACTION] [--deny RESOURCE:ACTION] shows or changes the Read/Write/Use grid. It accepts the dashboard's resource names (commands, endpoints, registries, models, mcp-tools, secrets) and the API's (execs, ingresses, …). It rejects actions Platform never checks, such as sandboxes:use. As in the dashboard, allowing Write or Use also allows Read.
  • adapt identities access IDENTITY MEMBER [--assume] [--manage] sets a member's access by member ID or email. With neither flag, it removes access.
  • adapt identities account IDENTITY CONNECTION_ID --use PERSONAL_CONNECTION_ID | --clear chooses the caller's personal account for a connection that uses personal accounts.
  • adapt identities sessions list | start | revoke manage identity sessions.
  • create accepts --name, --description, --allow and --max-session, filling in the permission resources Platform requires, so --data is only needed for connections, secrets and grants. Options override fields in --data.

Behavior

  • Names: routes accept only full UUIDs. A full UUID is always treated as an ID. Anything else must exactly match, ignoring case, the name of an identity the caller can assume or manage. Platform keeps names unique regardless of case; if two still match, the command lists their IDs instead of guessing.
  • Updates merge: Platform's update replaces the whole configuration and resets omitted fields, such as connections and secrets. update, enable, disable and permissions read the identity, apply only the change, leave grants out unless supplied, and save with the current version. A version in --data that doesn't match is refused before saving.
  • No-op changes aren't sent: every save or access change ends the identity's active sessions on Platform, so a change that alters nothing is skipped and stderr says so. Examples: enable on an enabled identity, allowing a permission it already has, re-setting a member's current access.
  • Tokens: sessions start prints the token once in its response on stdout. The stderr note never includes it, and it's never saved.
  • Revoke confirms: Platform answers 204 even when no session matched, so sessions revoke re-reads the session list and fails if the session wasn't found or isn't revoked.
  • Error hints:
    • An expired or revoked identity token's 401 now points to adapt identities sessions start instead of adapt auth login. Matching uses Platform's exact message, so /mcp's "…an identity session, or an organization API key" 401 keeps the login hint.
    • Using an identity token with a different --org gets an organization hint.
    • Identity commands used with an API key or identity token explain that they need the browser sign-in.
    • Passing a user ID where a member ID belongs gets a member-ID hint.

Docs

docs/cli-reference.md has a new Identities section covering permissions, member access, personal accounts and sessions. docs/api-coverage.md and the bundled skill are updated.

Testing

  • tests/identities/mod.rs has 34 mock-server tests:
    • Paging and the fixed page size.
    • Name lookup, including ignoring case, unknown names and ambiguous names.
    • Merged updates, supplied grants, stale versions and a server 409.
    • enable/disable, the no-op skips, and delete.
    • Permission reads, changes and invalid combinations.
    • access by email across pages, by member ID, the no-op skip, non-managers, and the member-ID hint.
    • account selecting, clearing and requiring a choice.
    • Session start (token only on stdout, never in config), duration and label validation, and revoke confirmation including a missing session.
    • The three error hints, plus create from options, options overriding --data, and required inputs.
  • Unit tests cover permission parsing, --allow/--deny application, the merge, the no-op comparison, the grid and the table rows.
  • I also ran it against a local Platform with an owner session in a throwaway org. All 33 checks passed:
    • Create, then update by name in a different case, keeping the other fields; the version went 1 → 2 → 3.
    • The stale version was refused, and all three no-op skips worked.
    • The token worked as ADAPT_TOKEN, then failed with the new 401 hint after an edit ended its session.
    • Disabled identities can't start sessions, and revoke confirmed.
    • access by email worked, and every hint appeared on the real error bodies.
    • The list, session and permission views rendered in a terminal.
    • create from options worked, with --data merging.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test --locked pass.

Known limits

  • Platform re-checks an identity's connections on every save. If a connection was removed or its allowed tools narrowed, every save fails until update supplies corrected connections, and that includes disable. delete still works. The dashboard has the same limit.
  • Name lookup, email lookup and revoke confirmation each page through a full list. Member lookup across several pages is covered only by mock tests; the local org had one member.
  • Choosing a real personal account wasn't run end to end, because it needs a connection that uses personal accounts. The error path was.

🤖 Generated with Claude Code

`adapt identities` lists, inspects, creates, updates, enables, disables
and deletes Platform identities, and starts, lists and revokes their
sessions. `permissions` shows or changes the Read/Write/Use grid with
--allow/--deny RESOURCE:ACTION, using the dashboard's resource names and
rejecting actions Platform does not check. `access` sets a member's assume
and manage access by member ID or email, and `account` chooses the
caller's personal connection for a personal-account binding. `create`
accepts --name, --description, --allow and --max-session, filling the
permission resources Platform requires, alongside --data.

Identity routes take full UUIDs, so a name is resolved case-insensitively
among the identities the caller can assume or manage; a full UUID is
always an ID. Platform's update replaces the whole configuration and
resets omitted fields, so updates merge the change onto the current
identity and save with its version. Because every save or access change
ends the identity's sessions, a change that alters nothing is not sent.

Session tokens are printed once in the start response and never saved.
Revoke confirms the result, since Platform answers 204 even when nothing
matched. An expired or revoked identity token now points to starting a
new session instead of signing in again.

Part of #7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@the-adaptile the-adaptile Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Confidence Score: 1/5

Summary

Adds identity management and scoped sessions, affecting authorization and session invalidation. Formatting, Clippy, and 147 tests passed locally; additional grant checks used mocks, and live API behavior remains unverified.

Deployed verification not applicable: adapt/platform-cli is outside the adapt/adapt and adapt/platform pilot. Its CI builds CLI artifacts without PR preview deployments. No verification webhook was sent.

Important Files Changed

File Changes
src/identities.rs Identity commands, configuration merging, grant comparison, member lookup, and session management.
src/cli.rs Identity command definitions, flags, validation, and help.
src/api.rs Identity-token authentication and organization error hints.
src/output.rs Whole-object rendering for identity details.
src/input.rs Identity selector, name, and session-label validation.
src/commands.rs Dispatches identity commands using resolved credentials and organization.
tests/identities/mod.rs Mock API, grant comparison, and terminal-output regression tests.
tests/support/mod.rs Pseudo-terminal helper for interactive-output checks.
docs/cli-reference.md Identity workflows, permissions, no-op guarantees, and session handling.
docs/api-coverage.md Identity endpoint coverage and caller-member lookup dependencies.
skills/adapt/SKILL.md Agent-facing identity workflow and token-handling guidance.

Run info

Field ID
Agent 0d6ccd7e-b62f-4075-a561-199d1a7b1bf0
Automation ec14e69d-634f-4af0-a6dd-27aa06a1f6b3
Run 096a26fb-3e11-49ff-b56d-6b2462bc4bf5

Reviewed: 0abc22f-9edc6b3 · ↻ Re-run review

Comment thread src/identities.rs Outdated

pub async fn run(api: &Api, command: IdentityCommand, json: bool) -> Result<u8> {
if let Some(result) = dispatch(api, command, json).await.map_err(explain)? {
output::print(&result, json)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: preserve identity details in terminal output

In a TTY, connections: [] makes output::print emit only No results. for get/create/update. Reproduced locally. Use a detail renderer and add a PTY regression test.

Comment thread src/identities.rs
clear: _,
} => {
let id = resolve(api, &identity).await?;
api.json(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: skip unchanged personal-account bindings

Repeated account --use and already-empty --clear still PUT. Platform unconditionally revokes the caller's sessions, interrupting agents despite unchanged settings. Compare current account bindings before writing.

Comment thread src/identities.rs Outdated
body.as_object().is_some_and(|fields| {
fields
.iter()
.all(|(field, value)| field == "version" || current.get(field) == Some(value))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: compare grants by effective access

Reapplying identical input-shaped --data.grants always writes because GET grants include name/email, unnecessarily revoking every session. Normalize grant fields/order for comparison, respecting Platform's preserved self-grant semantics.

Comment thread src/api.rs
if identity_session {
write!(
f,
"; start a new one with `adapt identities sessions start`"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Explain how to clear the expired token override

With exported ADAPT_TOKEN, the recommended session-start command reuses the expired token and returns the same 401. Tell users to unset the override before issuing with their saved browser login.

Comment thread src/api.rs
if self.status == StatusCode::FORBIDDEN && identity_session {
write!(
f,
"; an identity session works only in its own organization, so remove --org or ADAPT_ORG_ID"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Account for the saved organization in the 403 hint

Removing --org/ADAPT_ORG_ID restores the profile's saved organization, which can produce the same 403. Recommend explicitly selecting the identity's organization instead. Reproduced with a saved profile.

`output::print` treats a top-level `connections` array as table rows, so in
a terminal an identity without connections printed only "No results." for
get, create, update, enable and disable. Single identity results now go
through `output::detail`, which prints indented JSON in a terminal and
compact JSON when piped, never a table.

A new `in_terminal` test helper runs the CLI with stdout on a
pseudo-terminal; the regression test fails with the old output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/identities.rs
clear: _,
} => {
let id = resolve(api, &identity).await?;
api.json(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: skip unchanged personal-account bindings

Repeated account --use and already-empty --clear still PUT. Platform unconditionally revokes the caller's sessions, interrupting agents despite unchanged settings. Compare current account bindings before writing.

Comment thread src/identities.rs Outdated
body.as_object().is_some_and(|fields| {
fields
.iter()
.all(|(field, value)| field == "version" || current.get(field) == Some(value))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: compare grants by effective access

Reapplying identical input-shaped --data.grants always writes because GET grants include name/email, unnecessarily revoking every session. Normalize grant fields/order for comparison, respecting Platform's preserved self-grant semantics.

Comment thread src/api.rs
if identity_session {
write!(
f,
"; start a new one with `adapt identities sessions start`"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Explain how to clear the expired token override

With exported ADAPT_TOKEN, the recommended session-start command reuses the expired token and returns the same 401. Tell users to unset the override before issuing with their saved browser login.

Comment thread src/api.rs
if self.status == StatusCode::FORBIDDEN && identity_session {
write!(
f,
"; an identity session works only in its own organization, so remove --org or ADAPT_ORG_ID"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Account for the saved organization in the 403 hint

Removing --org/ADAPT_ORG_ID restores the profile's saved organization, which can produce the same 403. Recommend explicitly selecting the identity's organization instead. Reproduced with a saved profile.

Re-applying the same `grants` in `identities update --data` always saved,
because Platform's responses add each member's name and email, so every
session of the identity ended even though access did not change.

Supplied grants now count as unchanged when they would leave the same
access in place: Platform keeps the caller's own grant, gives each listed
member its access, and removes everyone else, so the comparison ignores
order, ID case, entries with no access, and response-only fields. Input
Platform would reject, such as a duplicate member or a different access
for the caller, still counts as a change so its error is shown.

This needs the caller's member ID, looked up with `/v1/whoami` and a member
list filtered by user ID, only when grants are the sole possible change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/identities.rs
};
use uuid::Uuid;

const ROOT: &str = "/v1/identities";

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] Must fix: reconcile with Platform's identity removal

Platform #235 merged since the previous review, removing these routes and rejecting identity tokens. Commands now target an unsupported API on current main. Retarget supported functionality or withdraw this feature.

Comment thread src/identities.rs
match body.get("grants") {
None => Ok(true),
Some(grants) => {
Ok::<_, anyhow::Error>(same_grants(current, grants, caller_member(api).await?))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: do not compare redacted grants as complete access

The legacy API hides grants from non-managers. An assume-only caller's update --data '{"grants":[]}' now falsely succeeds despite other members retaining access. Require canManage before skipping the write.

Comment thread src/identities.rs
/// a different access for the caller, counts as a change so its error is shown.
fn same_grants(current: &Value, supplied: &Value, me: Uuid) -> bool {
let me = me.to_string();
let access = |grant: &Value| (grant["canAssume"] == true, grant["canManage"] == true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: validate grant fields before no-op comparison

canAssume:"true" becomes false; malformed grants can return success without granting access or reaching API validation. Reproduced locally. Validate UUIDs, required booleans, and list limits before comparing.

Comment thread src/identities.rs
clear: _,
} => {
let id = resolve(api, &identity).await?;
api.json(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Must fix: skip unchanged personal-account bindings

Repeated account --use and already-empty --clear still PUT. The legacy API unconditionally revokes the caller's sessions, interrupting agents despite unchanged settings. Compare current account bindings before writing.

Comment thread src/api.rs
if identity_session {
write!(
f,
"; start a new one with `adapt identities sessions start`"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Explain how to clear the expired token override

With exported ADAPT_TOKEN, the recommended session-start command reuses the expired token and returns the same 401. Tell users to unset the override before issuing with their saved browser login.

Comment thread src/api.rs
if self.status == StatusCode::FORBIDDEN && identity_session {
write!(
f,
"; an identity session works only in its own organization, so remove --org or ADAPT_ORG_ID"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Account for the saved organization in the 403 hint

Removing --org/ADAPT_ORG_ID restores the profile's saved organization, which can produce the same 403. Recommend explicitly selecting the identity's organization instead.

@miqui

miqui commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing without merging: Platform removed scoped identities in adapt/platform#235 (the /v1/identities routes and identity session authentication), so these commands would target an API that no longer exists. Issue #7 is closed as obsolete for the same reason.

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