Skip to content

feat: CLI hide accepted invitations from zitadel invitation list and name the invitation before cancelling - #3176

Merged
vitorbari merged 49 commits into
mainfrom
2853-cli-invitation-list-and-cancel
Nov 18, 2026
Merged

vitorbari merged 49 commits into
mainfrom
2853-cli-invitation-list-and-cancel

Conversation

@vitorbari

Copy link
Copy Markdown
Contributor

Replaces #3083, which could not leave its stack. The analytics now stack on top of this one.

Summary

Hides accepted invitations from zitadel invitation list by default, as the console does, and reads an invitation before zitadel invitation cancel asks to cancel it (#2853).

  • invitation list: --status is repeatable and defaults to pending, expired and rejected; the server filters, so paging stays exact. The footer, or the empty message when nothing is left, says accepted invitations are left out and how to list them.
  • invitation cancel: reads the invitation first, so the question names who it is for and its role, and an accepted or expired invitation fails with E_VALIDATION before anything is asked. Without an id it picks from pending and declined invitations; a declined one is removed with its own wording.
  • The API reference's CLI sample spells one --status per status, and names every status for an unfiltered list.
  • SKILL.md and a @zitadel/cli changeset.

🤖 Generated with Claude Code

vitorbari and others added 30 commits November 10, 2026 14:43
Hand-written commands over the invitations contract (#2849), in a new
Project administration help group. The link appears only in create's
output; telemetry records the role and whether it replaced one.

Refs #2858

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CLI loads commands from an explicit COMMANDS table, so the
invitation commands were unreachable and missing from the reference
and the docs. Adds the topic and its help group row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implements the CLI half of #2859 (ADR 086 §9): after the API confirms a
create or replace, the command sends invitation_created with role and
invitation_journey_id through a new BaseCommand.trackEvent, replacing
the role/is_replace dimensions. The catalog lists the CLI event as
emitted and the console's three invitation events as planned, and a
catalog test holds every trackEvent call's properties to the catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ADR 086 gains a dated amendment: a cancelled journey ended at
invitation_created and read as one nobody opened. invitation cancel now
reads the invitation before confirming, names it in the question,
refuses one that is no longer pending, and sends invitation_cancelled
with role and invitation_journey_id after the delete. The catalog lists
it emitted for the CLI and planned for the console.

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

# Conflicts:
#	apps/cli/src/lib/backend/index.ts
#	apps/cli/tests/unit/commands/api-coverage.test.ts
…analytics

# Conflicts:
#	apps/cli/src/commands/invitation/cancel.ts
#	apps/cli/src/commands/invitation/create.ts
#	apps/cli/src/lib/backend/index.ts
A dry run now answers with the request it would send. --replaces reads
the original first: an accepted one is refused before anything is
asked, and a replacement without --name keeps the original's name, as
the server does. The name prompt asks one question, and list gains a
unit test.

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

# Conflicts:
#	apps/cli/skills/zitadel-cli/SKILL.md
#	apps/cli/src/commands/invitation/create.ts
A dry run of invitation cancel <id> now reads nothing: the read that
names the invitation in the question moves into prepare. Also lists the
amendment in the ADR index, fixes the telemetry page's grammar, and
adds a changeset for the invitation events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- create --dry-run answers before connecting or reading the original.
- cancel --dry-run needs the id instead of reading the pending list.
- The printed link and the picker's hints are escaped for the terminal.
- --name counts characters, as the API's maxLength does.
- The API reference's CLI samples spell invitation create and list
  with their flags, and fall back to the api call for team invitations.

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

# Conflicts:
#	apps/cli/skills/zitadel-cli/SKILL.md
#	apps/cli/src/commands/invitation/cancel.ts
A non-interactive run, like a dry run, now refuses an omitted id before
reading the pending list, so a down server cannot hide the missing
input. Regenerates the CLI README, which lacked the invitation commands.

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

# Conflicts:
#	apps/cli/src/commands/invitation/cancel.ts
Follow-ups and retries are { id, flags } suggestions, refusals take no
suggester, list declares --all's exclusion through relatedFlags, and its
page carries only the token. Regenerates the CLI README.

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

# Conflicts:
#	docs/adrs/086-invitations.md
Lookup names the inviter; decline refuses the inviter (inv.self_reject) and
accept a creator who lost admin (inv.inviter_not_admin). Invitations carry
rejected_at and keep metadata on decline, cancel removes a declined one, and
the list takes a repeatable status filter and expand=inviter. Amends ADR 086.

The redeem handlers stay stubs, and the list answers 501 for several statuses
or expand, until the implementation lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	apps/api/internal/api/generated/oas_handlers_gen.go
#	apps/api/internal/api/generated/oas_schemas_gen.go
#	apps/api/internal/api/generated/oas_server_gen.go
#	apps/api/internal/api/generated/oas_unimplemented_gen.go
#	packages/go/api/oas_client_gen.go
#	packages/go/api/oas_schemas_gen.go
…etadata

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No guard in the server limits lookup, accept or reject; the edge does, so
per ADR 078 §7 they declare no 429. Amends ADR 086.

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

One who and when for accept and decline; status says which. Replaces
accepted_by, accepted_at and rejected_at, and amends ADR 086.

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

# Conflicts:
#	apps/cli/src/index.ts
main replaced literalKeys with keysOf and bans let, so the product-event
check uses keysOf and finds an event's const without a mutable binding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cli-invitation-list-contract

# Conflicts:
#	docs/adrs/086-invitations.md
Follows the contract in #3072: --status is repeatable and defaults to
every status but accepted, as the console does; invitation get reports
responded_by and responded_at; invitation cancel also removes a declined
invitation, without sending invitation_cancelled for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- create --replaces reads the original before any question, and a dry
  run reads it too, so an accepted one is refused the same way in both.
- The invitation id schema has one home (invitation/id.ts); the name
  limit and the list's statuses and types come from the generated
  schema; refusals are declared as const satisfies.
- Unit tests for the invitation service, and for create's and cancel's
  questions, refusals and the requests they do not send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A named pending or declined invitation is asked about by who it is for,
its role and what the cancel does to it; an accepted or expired one is
refused with E_VALIDATION before anything is asked.

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

Copilot AI 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.

🔵 Needs a closer look

The new release note should be folded into the existing pending changeset to follow repository policy and avoid publishing an outdated pending-only picker description.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Update the existing pending changeset instead of adding a second

.changeset/​cli-invitation-list-contract.md:5

Please fold this release note into the existing pending .changeset/cli-invitation-commands.md instead of adding a second changeset. .changeset/README.md:79–81 requires follow-ups to unreleased changes to update their pending entry; keeping both also publishes the older pending-only picker description alongside this update. Retain the existing minor bump and update its summary with the new list and cancellation behavior.

1 resolved since last review

Review effort: Balanced

…eset

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

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified in the invitation-list filtering and cancellation changes.

No open issues 🎉

Review effort: Balanced

@mridang mridang 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.

Looked at this as a fresh read of the diff against the repo and its AGENTS.md files. The behaviour is right and CI is green. These are the gaps worth closing, mostly around tests and a few places that will drift.

verb: "cancel",
name: `cancel ${invitationId}`,
message: `Cancel ${invitationId} so its link stops working?`,
message: ({ invitation }) => {

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.

The question now embeds metadata.name, which is whatever another administrator typed, and the non-interactive E_CONFIRMATION_REQUIRED refusal carries the same question in its hint and details.question. invitation-list.spec.ts and invitation-get.spec.ts both run servesAHostileInvitation through inEveryRendering, but invitation-cancel.spec.ts only runs it on a plain invitation, so nothing proves this new path stays free of control characters in any rendering. The mock needs a DELETE that honours the hostile invitation too, or a cancel-specific variant of the helper. Worth a spec before merge.

return this.connect();
// A dry run stops before this, so it needs no connection: the read
// that names a named invitation in the question happens here.
prepare: async () => {

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.

A dry run with a named id never reaches this prepare, so cancel inv_x --dry-run on an accepted or expired invitation answers ok with a dry-run result, and the real run then refuses with E_VALIDATION. That is the same hole as the dry-run-predicts-refusals idea; fine to defer, but say so in the description so it is a known limit and not a surprise.

throw refusalError(NO_ID_REFUSAL, {});
}
const invitationId = args.invitationId ?? (await this.pickPending());
const target = args.invitationId ?? (await this.pickCancellable());

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.

target is a string or an Invitation, and the typeof target === "string" check is repeated here and again in prepare. Resolving it once into the same shape ({ id, invitation? }, or reading the named one lazily behind one helper) would drop both branches.

hint: "Find one with `zitadel invitation list --status pending`.",
next: [{ id: "invitation:list", flags: { status: "pending" } }],
hint: "Find one with `zitadel invitation list --status pending --status rejected`.",
next: [{ id: "invitation:list", flags: { status: ["pending", "rejected"] } }],

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.

The pair ["pending", "rejected"] is written out six times across this file and InvitationService.cancellable(), plus the !== "pending" && !== "rejected" test in readCancellable. One CANCELLABLE_STATUSES const (typed readonly InvitationStatus[], with a includes check in readCancellable) keeps the picker, the refusals, the hints and the guard from drifting apart when the server's rule changes.

const NOT_CANCELLABLE_REFUSAL = {
message: "{id} is {status}, so there is nothing to cancel",
hint: "Only a pending or declined invitation can be cancelled.",
next: [{ id: "invitation:list", flags: { status: ["pending", "rejected"] } }],

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.

This refusal is shared by accepted and expired, but its next lists pending and rejected invitations, which does not help someone who just hit an expired one. For expired the actionable step is invitation create --replaces <id> (ADR 086 revokes an expired original and creates again), and for accepted it is grant list. A per-status next, or at least a hint that says an expired invitation keeps its row until it is replaced, would turn a dead end into a path.

return escapeControlCharacters(
`${whom === undefined ? "" : `${whom}, `}expires ${invitation.expires_at}`,
`${whom === undefined ? "" : `${whom}, `}${
invitation.status === "pending" ? `expires ${invitation.expires_at}` : "declined"

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.

The picker hint and the questions say "declined", while invitation list prints rejected in its status column and --status only accepts rejected. Someone who picks the declined row here, then looks for it with list, sees a different word. Either use rejected here or add "declined" to the --status rejected description in list.ts.

const empty = "No invitations yet.";
const footer: string[] = [];
// A list that found nothing drops the footer, so the default says it here.
const empty =

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.

The default now drops accepted invitations, but only the human rendering says so (empty and footer). A script running invitation list --json gets a subset with nothing in the envelope to say a filter was applied, and a script that counted all invitations changes meaning silently. Consider echoing the applied statuses in data (or a warning when it defaulted) so the envelope states what it filtered. The same default also leaves invitation get's hint ("Find one with zitadel invitation list") unable to find an accepted invitation, which get reads.

}

/** Every invitation status, which `invitation list` lists only when asked. */
const INVITATION_STATUSES = ["pending", "accepted", "rejected", "expired"];

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.

Listing everything now needs four repeated flags, and this constant, the invitationIds test helper and the footer message all spell that out by hand. A --status all (or --include-accepted) would remove all three: the sample could say --status all, the helper could use it, and the footer would point at one flag. If you would rather not add a value, deriving the list from the operation's status enum at least keeps this from drifting when the API gains a status.


const result = await app.run(LIST);

expect(result.stderr).toContain("pass --status accepted to list them");

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.

apps/cli/tests/AGENTS.md says wording is asserted in a unit test and a spec "asserts that the command refused, never the words", and a spec uses the matcher vocabulary in matchers.ts, not result.stderr.toContain. The empty message and footer wording (and the OPEN_STATUSES default) belong in tests/unit/cli/commands/invitation/list.test.ts, which this PR does not touch. The spec can keep the observable claim, that accepted invitations stay out of the list, with toPrint/toSay.

@mridang mridang 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.

Approving. I read the full diff against the repo and its AGENTS.md files, and CI is green.

What I checked and found sound: invitation list defaults to pending, expired and rejected and the server does the filtering, so paging stays exact. The empty message and footer both say accepted invitations are left out and how to list them. invitation cancel reads the invitation before it asks, so the question names who it is for and its role, and an accepted or expired invitation is refused with E_VALIDATION before anything is asked. This matches ADR 086's rule that cancel deletes a pending or rejected invitation and an expired one keeps its row, and the mock's DELETE answers the same way. The picker offers pending and declined invitations, the next suggestions and hints all carry the repeated --status, and SKILL.md, the README, the command reference, the docs sample and the changeset are updated together.

The inline comments from my earlier review stand. None blocks the merge, but these are the ones I would pick up first, in this PR or right after: a hostile-name case in the cancel spec, since the question now embeds metadata.name; moving the empty-message and footer wording out of the spec and into list.test.ts; and one CANCELLABLE_STATUSES const in place of six copies of the pending/rejected pair. The dry-run limit (a named id is not read, so it cannot predict the refusal) is worth a line in the description as a known limit.

Nothing here changes the behaviour the PR sets out to deliver.

…ist-and-cancel

# Conflicts:
#	apps/cli/src/cli/commands/invitation/cancel.ts
The question embeds an invitation's name, which another administrator
typed. The cancel spec now runs a hostile name through every rendering,
asking and forced, and checks the non-interactive refusal spells it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vitorbari
vitorbari enabled stacked auto-merge November 18, 2026 13:40
stacked auto-merge was automatically disabled November 18, 2026 13:40

Auto-merge was disabled for another pull request in the stack

@vitorbari
vitorbari added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit e5a1d0b Nov 18, 2026
17 checks passed
@vitorbari
vitorbari deleted the 2853-cli-invitation-list-and-cancel branch November 18, 2026 13:49
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 18, 2026

This branch was successfully deployed

1 active deployment
Preview — 0c279c0e Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants