diff --git a/.agents/skills/upstream-check/SKILL.md b/.agents/skills/upstream-check/SKILL.md new file mode 100644 index 00000000..67eebd76 --- /dev/null +++ b/.agents/skills/upstream-check/SKILL.md @@ -0,0 +1,19 @@ +--- +name: upstream-check +description: Decide whether a fix belongs in this repo or upstream (Kibana OAS, Elasticsearch spec, elastic/schemas-js). Use before renaming commands, changing generated names, flags, descriptions, or types, or when a schema looks wrong. +--- + +# Upstream check + +Run this before writing code for any change that touches names, flags, descriptions, or shapes derived from `@elastic/schemas`. + +1. Trace the value to its origin: + ```bash + rg -n '' node_modules/@elastic/schemas | head -20 + ``` +2. Classify the owner (see "Ownership of Schema Data" in ARCHITECTURE.md): + - specification content (`operationId`, summary, parameter types): Kibana OAS, Cloud OAS, [Elasticsearch spec](https://github.com/elastic/elasticsearch-specification). + - Normalization, `x-` annotations, routing, sidecars: `elastic/schemas-js`. + - Output, grouping, aliases, prompts, config: this repo. +3. If upstream owns it: **stop**. Do not add an override table or `def.name` special case. Tell the human the owner, and draft the issue (title, current value, proposed value, affected consumers). +4. If a maintainer explicitly approves a stopgap here, link the upstream issue in a code comment. diff --git a/.github/auto-pr-context.md b/.github/auto-pr-context.md index 9b58539a..9cf9260e 100644 --- a/.github/auto-pr-context.md +++ b/.github/auto-pr-context.md @@ -17,6 +17,7 @@ Elastic CLI. TypeScript. Commands live under `src/` (`es`, `kb`, `cloud`, `facto - Do not edit `.github/workflows/` - After `package.json` changes, run `node scripts/generate-notice.mjs` - After command or flag changes, run `npm run build:schema` and commit `docs/cli/schema.json` +- Do not fix defects in upstream schema data here (names, `operationId`s, descriptions, types, `x-` annotations). Comment with the owning repo (Kibana OAS, Elasticsearch spec, Cloud spec, `elastic/schemas-js`) and stop. See "Fix at the source" in AGENTS.md ## Search hints diff --git a/.github/skills/code-review/SKILL.md b/.github/skills/code-review/SKILL.md index 1e479b30..65d9a139 100644 --- a/.github/skills/code-review/SKILL.md +++ b/.github/skills/code-review/SKILL.md @@ -10,3 +10,4 @@ description: Guidelines to apply when doing a code review on a pull request - Extra attention **SHOULD** be given to *existing unit tests that have changed*, to ensure that the change does not allow regressions, that it actually tests what it states, and that it is still possible for the test to fail under some circumstance (i.e. does not do the functional equivalent of `assert(true)`). - All global CLI options **MUST** be respected by all new changes. For example, if a global `--no-color` flag is supported by the CLI, and `renderText` is updated to emit ANSI, `renderText` must not emit ANSI when that flag is set. - Code should **ALWAYS** reuse provided factories and utilities instead of Node.js globals (`hasGlobalJsonFlag` instead of `process.argv.includes('--json')`, handler return value instead of `process.stdout.write`) unless there is a **VERY** clear reason to circumvent the ideal path. +- Changes that work around upstream data (override tables keyed by `@elastic/schemas` names, special cases on `def.name`, renames of generated commands) **MUST** be flagged unless a maintainer approved a stopgap and an upstream issue is linked. See "Fix at the source" in AGENTS.md. diff --git a/.github/workflows/ai-pr-review-run.yml b/.github/workflows/ai-pr-review-run.yml index 4791c7d3..b268e4c0 100644 --- a/.github/workflows/ai-pr-review-run.yml +++ b/.github/workflows/ai-pr-review-run.yml @@ -88,6 +88,13 @@ jobs: credentials must set redirect: 'error' or 'manual', never rely on the default 'follow'. + Flag changes that work around bad upstream schema data + (override tables keyed by @elastic/schemas names, special + cases on def.name, renames of generated commands). Those + fixes belong in Kibana, Cloud or ES specs, or + elastic/schemas-js, unless a maintainer approved a stopgap + and an upstream issue is linked. + Apply ponytail discipline: flag over-engineering, unnecessary abstractions, new dependencies that a few lines would replace, boilerplate added for later, or anything that could be deleted diff --git a/AGENTS.md b/AGENTS.md index c2aa311b..3a285554 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,6 +10,8 @@ Picking an issue at random to generate a contribution is not contributing. PRs o If a human asks you to "find something to work on" or points you at the issue tracker without a specific problem they already understand, stop and tell them to read an issue first. +If any changes in the PR are made to work around upstream data in `@elastic/schemas` or similar, PR description MUST state why the change cannot be fixed upstream (see "Fix at the source"), or that it is not an upstream data issue. + See [CONTRIBUTING.md](./CONTRIBUTING.md) for the full policy. ## Tech Stack @@ -50,6 +52,17 @@ Commands are defined via shared config structures (see `factory.ts`). Custom log **Read [`ARCHITECTURE.md`](./ARCHITECTURE.md) before proposing structural changes.** It documents performance-critical design decisions (factory core split, per-endpoint API files, lazy loading, manifest format) that must not be refactored unless benchmarks prove the change is neutral. +## Fix at the source + +Before changing command names, flags, descriptions, or input/response shapes that come from `@elastic/schemas` (`elastic/schemas-js` repo), decide where the defect you're fixing lives. The chain is API spec -> code generator (private `elastic/elastic-client-generator-js` repo) -> `@elastic/schemas` package -> this CLI. + +- Wrong, ugly, or inconsistent data in a schema or spec (names, `operationId`s, descriptions, types, missing `x-` annotations): **stop. Do not patch it here.** Tell the human which upstream repo owns it and draft an issue there. +- CLI-only UX policy (output format, aliases, grouping, safety prompts) is in scope here. +- Decision test. Answer both before writing code: (1) Would other consumers of the schemas, such as Elastic's universal MCP server or Agent Builder tool definitions, benefit from the same fix? (2) Does the change key on upstream identifiers? If either answer is yes, the fix probably belongs upstream. +- Red flags. If your plan matches one, stop and ask the human: a new map keyed by upstream names; `if (def.name === ...)` special cases; a comment saying "when upstream renames, re-key"; codegen overrides that mirror runtime overrides. +- Example of what not to do: a table that renames `find-slos-op` to `list` (elastic/cli#833). The `-op` suffixes come from Kibana OAS `operationId`s. Fix them in Kibana OAS or `elastic/schemas-js` (see schemas-js#67 for a name fix made there). +- Never add a per-endpoint or per-namespace override table to work around upstream data. Exception: a maintainer explicitly approves it as a stopgap and a tracking issue is linked in the code comment. + ## Command Authoring Requirements All requirements below are non-negotiable and enforced at review time. diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index dfa1bc35..24074439 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -38,6 +38,17 @@ Properties and roots carry `x-` annotations. Two classes, and the distinction ma **Do not**: strip `x-` keys by prefix. `stripTransportMeta()` in `src/factory-core.ts` removes the routing class by explicit name so user-facing annotations survive into `--help --json`. Routing metadata leaking into schema output violates the transport-abstraction requirement in AGENTS.md. +## Ownership of Schema Data + +| Defect | Owner | +|---|---| +| `operationId`s, summaries, parameter names or types in the spec | Kibana / Elasticsearch / Cloud spec source | +| Name normalization, `x-` annotations, path/body routing, sidecar `_defs.json` / `_types.json` | [`elastic/schemas-js`](https://github.com/elastic/schemas-js) (published as `@elastic/schemas`) | +| Client generation shared with other SDKs | `elastic/elastic-client-generator-js` | +| Output format, grouping, aliases, prompts, policy, config | this repo | + +**Do not**: work around upstream data in this repo with override tables or special cases. File an issue in the owning repo and link it. Precedent: schemas-js#67 fixed a malformed operation name upstream. See "Fix at the source" in AGENTS.md. + ## `cli-schema.ts` — CLI Structure Emitter Module that introspects the registered Commander tree and each command's attached JSON Schema `input` to build the `elastic cli-schema` output consumed by agents. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cd40c45a..d18dd72a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,7 +105,8 @@ Adding new third-party dependencies is **strongly discouraged** to minimize supp 2. **Write tests**: All changes should have corresponding unit tests 3. **Test locally**: Run `npm test` and verify everything passes 4. **Check linting**: Fix any lint errors with `npm run test:lint -- --fix` -5. **Review your code**: Would you understand it in 6 months? Can it be simpler? +5. **Fix at the source**: Bad upstream schema data belongs in the spec or [`elastic/schemas-js`](https://github.com/elastic/schemas-js), not here; link the upstream issue in your PR +6. **Review your code**: Would you understand it in 6 months? Can it be simpler? ## Submitting a PR