Skip to content

feat(cli): Generate completion command sets from route metadata - #1557

Merged
BYK merged 4 commits into
mainfrom
byk/cli-generate-completion-targets
Oct 20, 2026
Merged

BYK merged 4 commits into
mainfrom
byk/cli-generate-completion-targets

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1527.

The ORG_PROJECT_COMMANDS and ORG_ONLY_COMMANDS lists in complete.ts were maintained by hand. The only safeguard was a test that guessed org-scoped commands from their placeholder text, so a missing entry was caught after the fact, or not at all.

Target positionals now declare the completion kind through their parser. They use parseOrgProjectTarget or parseOrgTarget from src/lib/completion-target.ts instead of String. Both return their input unchanged. The kind is identified by which parser the positional uses, so it lives in parameters next to the placeholder. Shared positionals carry it automatically: LIST_TARGET_POSITIONAL, issueIdPositional, and feedbackIdPositional are tagged org/project. LIST_ORG_TARGET_POSITIONAL is new and is used by org-scoped lists (team, repo, integration, monitor and release list). A command whose positionals mix both kinds fails generation.

A new generate:completions step walks the route tree and writes src/generated/completion-targets.ts, which the __complete fast path imports. The file is gitignored like skill-content.ts. It runs inside generate:docs, so it is regenerated during dev, build, bundle, typecheck and test. complete.ts still doesn't load the route tree at runtime.

Completion changes compared with the old hand-written lists:

  • agent-conversation list now completes org/project instead of org only, because it takes the standard list target.
  • alert issues list and feedback resolve|unresolve|spam gain org/project completion, because they share a tagged positional with commands that already had it.

project create keeps its dedicated name:platform completer.

Command lookup in complete.ts now matches the first prefix of the typed words that names a command, instead of always using the first two words. Without this, nested commands like alert issues list could not be completed.

The placeholder-heuristic drift test is replaced with a check that the generated sets match extractCompletionTargets(routes). There are also unit tests for nested, variadic, hidden, and mixed-kind positionals.

via Junior system actor event.

--

View Junior Session in Sentry

Commands now declare `completionTarget: "org" | "org/project"` in
buildCommand (also accepted by buildListCommand/buildDeleteCommand;
buildOrgListCommand sets "org"). A new `generate:completions` step walks
the route tree and writes the gitignored
src/generated/completion-targets.ts, which the `__complete` fast path
imports instead of the hand-maintained ORG_PROJECT_COMMANDS and
ORG_ONLY_COMMANDS sets.

The placeholder-heuristic drift test is replaced with a check that the
generated sets match the route tree. `project create` keeps its explicit
name:platform completer.

Fixes #1527

Co-Authored-By: byk <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 20, 2026 10:08pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 20, 2026
Comment thread packages/cli/src/commands/agent-conversation/list.ts Outdated
The command takes LIST_TARGET_POSITIONAL (org/, org/project, project),
so it should use the org/project completer like its peer list commands.
@BYK

BYK commented Oct 20, 2026

Copy link
Copy Markdown
Member

Wouldn't it be better to bake this into the existing parameters dictionary, maybe with a special type instead of the String parser?

Instead of a separate `completionTarget` builder option, target
positionals now use `parseOrgTarget` / `parseOrgProjectTarget` from
src/lib/completion-target.ts in place of `String`. The generator reads
the kind straight from each command's `parameters`.

Commands sharing a tagged positional pick up completion automatically:
`alert issues list` (LIST_TARGET_POSITIONAL) and `feedback
resolve|unresolve|spam` (feedbackIdPositional). Org-scoped list commands
use the new LIST_ORG_TARGET_POSITIONAL.
@sentry-junior

sentry-junior Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Done in 68d6f53. I removed the completionTarget builder option. Target positionals now use parseOrgProjectTarget or parseOrgTarget instead of String. Both are identity parsers in src/lib/completion-target.ts. The generator reads the completion kind from each positional's parse.

Positionals that several commands share carry the kind automatically: LIST_TARGET_POSITIONAL, issueIdPositional, and feedbackIdPositional. As a result, alert issues list and feedback resolve|unresolve|spam now get completion too. Org-scoped lists use a new LIST_ORG_TARGET_POSITIONAL.

Comment thread packages/cli/src/lib/complete.ts
Comment thread packages/cli/src/lib/completion-target.ts
Comment thread packages/cli/src/lib/introspect.ts Outdated
Comment thread packages/cli/script/generate-completion-targets.ts Outdated
Add ORG_TARGET / ORG_PROJECT_TARGET / COMPLETION_TARGETS constants and
use them instead of string literals across introspect, complete, and
tests. The generator now writes src/generated/completion-targets.json
via JSON.stringify (like api-schema.json) instead of hand-assembling a
TypeScript module; complete.ts builds its path → target map from it.

Co-Authored-By: byk <burak.kaya@sentry.io>
@BYK
BYK enabled auto-merge (squash) October 20, 2026 22:29
@BYK
BYK merged commit 4196231 into main Oct 20, 2026
32 of 34 checks passed
@BYK
BYK deleted the byk/cli-generate-completion-targets branch October 20, 2026 22:30

This branch was previously deployed

1 inactive deployment
Preview — e31edae2 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate shell-completion command sets from route metadata

1 participant