Skip to content

feat(kb)!: short canonical names for slo commands - #833

Closed
kdelemme wants to merge 4 commits into
elastic:mainfrom
kdelemme:feat/kb-slo-command-aliases
Closed

kdelemme wants to merge 4 commits into
elastic:mainfrom
kdelemme:feat/kb-slo-command-aliases

Conversation

@kdelemme

@kdelemme kdelemme commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary

All 15 commands under elastic kb slo used Kibana's legacy OpenAPI operationId names as-is (find-slos-op, get-slo-op, get-definitions-op, …). slo is the only Kibana namespace where every command has an -op suffix, and most names repeat slo inside the slo namespace.

This PR gives them short CLI names that follow one rule: list* for paginated results, get* for a single element.

Upstream @elastic/schemas name CLI name
find-slos-op list
create-slo-op create
get-slo-op get
update-slo-op update
delete-slo-op delete
enable-slo-op enable
disable-slo-op disable
reset-slo-op reset
get-definitions-op list-definitions
get-snapshot-op get-snapshot
bulk-snapshot-op bulk-snapshot
bulk-delete-op bulk-delete
bulk-delete-status-op bulk-delete-status
delete-rollup-data-op delete-rollup-data
delete-slo-instances-op delete-instances

Breaking change

The old *-op names are not kept as aliases. The CLI is in technical preview, so this is a clean break, as in #199 and #201. Invoking an old name exits 1 with unknown command.

commands.allowed / commands.blocked entries that name an old path (e.g. stack.kb.slo.delete-slo-op) no longer match anything. A blocked entry like that stops blocking the renamed command, so it needs to be updated to the new path (stack.kb.slo.delete).

An earlier revision of this PR kept every old name as a Commander alias, with alias-aware policy matching. That support was removed in 0ddf5b5; nothing in the factory, policy, or lazy-leaf code changes in the final diff.

Changes

  • KB naming table (src/kb/command-names.ts, new, no imports): a static map keyed by namespace → upstream name → CLI name, plus resolveKbCommandName(). Only slo is populated; unmapped commands keep their upstream name. def.name stays the upstream identifier for loadKbApi and request building.
  • KB registration (src/kb/register.ts): real and stub leaves are registered under the resolved name. The namespaced argv sniff (kb <namespace> <token>) matches CLI names; the flat sniff (kb <token>) keeps matching upstream names only, so short names like list or get cannot match across namespaces. Name collisions inside a namespace are rejected by Commander's addCommand (covered by a test).
  • Functional test codegen (codegen/functional/kb.ts): each definition gets cliPath = [namespace, cliName], so generated scripts call stack kb slo list etc., while test/functional/kb/definitions/slo_*.yml stays client-agnostic.
  • Generated schema: docs/cli/schema.json regenerated; the diff is limited to the 15 stack kb slo command names.

Testing

  • npm test on Node 24.22.3 (tsc -b build + unit suite + license check): 2464 pass / 0 fail / 2 skipped.
  • eslint on the changed files and scripts/check-spdx.mjs: clean.
  • New tests: naming table contents, drift against the Kibana manifest, valid and unique CLI names per namespace, prototype-key safety, registration without aliases, lazy sniffing (CLI name loads the real leaf; upstream name stays on stubs), stub-to-real-leaf swap for a renamed command, spawned __complete and cli-schema checks, an end-to-end stack kb slo find-slos-op → unknown command check, and the codegen cliPath mapping.
  • ELASTIC_ENVIRONMENT=stack npm run codegen:functional:kb: generated slo_*.sh call only CLI names; no -op name in a command position.
  • Built CLI, run by hand: kb slo --help lists only the CLI names; kb slo find-slos-op and kb slo get-slo-op exit 1 with unknown command; kb slo get --id x --dry-run exits 0.
  • Not re-run after the alias removal: the Node 22 unit run, scripts/heap-check, and the startup-time A/B. The final change removes code from the startup path. hyperfine is not available locally, so scripts/perf-check was not run; the perf CI job is the authoritative gate.

Notes for reviewers

  • With --json, an unknown command (old name or otherwise, e.g. kb spaces not-a-command) prints Commander's plain-text error rather than the {"error": …} shape. This is existing behaviour and is not changed here.

🤖 Generated with Claude Code

Rename the 15 `elastic kb slo` commands from Kibana's legacy operationId
names (`find-slos-op`, `get-slo-op`, ...) to short canonical names that
follow one rule: `list*` for paginated results, `get*` for a single
element (`list`, `get`, `create`, `list-definitions`, `get-snapshot`, ...).
Every legacy `*-op` name stays registered as a Commander alias.

- factory: `CommandConfig.aliases`, validated and registered by
  `defineCommand`; lazy stub leaves carry the same aliases.
- policy: `isCommandAllowed` accepts a list of dot-paths; leaves match
  through their canonical path or any alias path, so an existing
  `commands.blocked` entry such as `stack.kb.slo.delete-slo-op` still
  blocks the renamed `stack.kb.slo.delete`.
- kb: `src/kb/aliases.ts` naming table keyed by upstream
  `@elastic/schemas` names; registration, the namespaced argv sniff and
  stub leaves use it. The flat `kb <token>` sniff keeps matching upstream
  names only.
- codegen: KB functional scripts invoke the canonical names via `cliPath`.
- docs: regenerated `docs/cli/schema.json`; alias matching documented in
  the configuration reference.
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:09
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Elastic Docs Style Checker (Vale)

Summary: 2 suggestions found

💡 Suggestions (2): Optional style improvements. Apply when helpful.
File Line Rule Message
docs/cli/configuration_reference.md 69 Elastic.Semicolons Use semicolons sparingly. Consider splitting the sentence or using a comma or conjunction.
docs/cli/configuration_reference.md 70 Elastic.Semicolons Use semicolons sparingly. Consider splitting the sentence or using a comma or conjunction.

The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale.

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

🟢 Approval recommended

No active review issues are blocking approval.

No open issues 🎉

What changed in this PR

Gives all 15 elastic kb slo commands shorter canonical names while retaining their legacy names as aliases. The change integrates with the CLI’s shared command factory and lazy-loading architecture.

Changes:

  • Adds a Kibana naming registry used by command registration and functional-test generation.
  • Supports leaf aliases in command validation, lazy loading, and policy enforcement.
  • Updates the generated CLI schema, policy documentation, and tests for naming, completion, and compatibility.
File Description
test/​lib/​lazy-leaf.test.ts Tests stub aliases and alias-triggered loading.
test/​kb/​register.test.ts Tests canonical registration and lazy invocation through either name.
test/​kb/​aliases.test.ts Checks mappings, legacy compatibility, uniqueness, and prototype-key safety.
test/​factory.test.ts Tests alias validation, invocation, help output, and policies.
test/​completion-cli.test.ts Checks completion for canonical names and legacy aliases.
test/​cli-schema.test.ts Verifies canonical names and aliases in schema output.
src/​lib/​lazy-leaf.ts Registers aliases on lightweight command stubs.
src/​kb/​register.ts Applies resolved names and recognizes aliases during lazy loading.
src/​kb/​aliases.ts Defines the SLO naming registry and lookup helpers.
src/​factory.ts Validates and registers aliases; enforces alias-aware policies.
src/​factory-core.ts Adds alias configuration and alias-aware policy matching and visibility.
docs/​cli/​schema.json Records canonical names and legacy aliases for all 15 SLO commands.
docs/​cli/​configuration_reference.md Documents policy matching through leaf aliases.
codegen/​functional/​test/​mapper.test.ts Tests mapping upstream actions to canonical CLI paths.
codegen/​functional/​kb.ts Generates functional-test commands using canonical names.

Review effort: Balanced

Group aliases (e.g. stack.kibana) are not matched by commands.allowed or
commands.blocked; entries must use canonical group names.
The 15 `elastic kb slo` commands are registered under their short names
only. Kibana operationId names such as `find-slos-op` are no longer
aliases: the CLI is in technical preview, so renames are clean breaks
(as in elastic#199 and elastic#201). Generic command alias support and alias-aware
policy matching are removed with them.

BREAKING CHANGE: `elastic kb slo` commands answer to their short names only
(`find-slos-op` → `list`, `get-definitions-op` → `list-definitions`, ...).
Update `commands.allowed`/`commands.blocked` entries that name the old paths.
@kdelemme kdelemme changed the title feat(kb): short canonical names for slo commands feat(kb)!: short canonical names for slo commands Nov 30, 2026
@kdelemme
kdelemme marked this pull request as ready for review November 30, 2026 16:16
@JoshMock

Copy link
Copy Markdown
Member

PRs that correct or clean up the names of APIs, due to unwanted naming artifacts in the Kibana OAS files or similar such issues, should be handled upstream in @elastic/schemas, which in turn is largely generated code, whose generator lives in a private Elastic repo elastic-client-generator-js.

The generator is likely the best place for this change. A fix there should be done in such a way that, if/when the OAS definition is cleaned up, the generator continues to work and just skips any cleanup steps that are no longer needed.

Closing this so you can contribute there first, then open a new PR here for any follow-up bits that can't be handled by fixing schema definitions.

@JoshMock JoshMock closed this Nov 30, 2026
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.

3 participants