Skip to content

[docs-utils] Add fix-package-docs skill#257577

Merged
clintandrewhall merged 9 commits intoelastic:mainfrom
clintandrewhall:fix-package-docs-skill
Mar 20, 2026
Merged

[docs-utils] Add fix-package-docs skill#257577
clintandrewhall merged 9 commits intoelastic:mainfrom
clintandrewhall:fix-package-docs-skill

Conversation

@clintandrewhall
Copy link
Copy Markdown
Contributor

@clintandrewhall clintandrewhall commented Mar 13, 2026

Summary

Two related changes:

  1. New agent skill — adds .agents/skills/fix-package-docs/SKILL.md, a step-by-step guide for an AI agent to systematically find and fix all actionable API documentation issues in a Kibana plugin or package using check_package_docs --write.

  2. unnamedExports in stats.json — the unnamed validation check was already run by check_package_docs but its results were never written to the stats.json file produced by --write. This PR adds unnamedExports to FlatStats so agents (and humans) can read it from disk alongside the other categories.

Skill coverage

The skill covers all four default validation checks (any, comments, exports, unnamed) with accurate fix guidance for each category:

Category What it flags Fix
missingComments Exported declarations with no JSDoc Add /** ... */ above the declaration
missingReturns Non-void functions missing @returns Add @returns to existing JSDoc
paramDocMismatches Functions with partial @param coverage (some but not all params documented) Add missing @param tags
missingComplexTypeInfo Interfaces, object types, and union types lacking a top-level description Add JSDoc to the type declaration
isAnyType Public API using any Replace with a specific type or unknown
unnamedExports Anonymous export default expressions with no identifiable name Give the export a name
missingExports APIs referenced but not exported Skip; flag for human review

The skill also documents the dot-notation @param convention for destructured parameters introduced in #250813, and the partial-param-doc detection introduced in #250820.

flat_stats.ts changes

  • Extracts getLink into its own file (get_link.ts) so it can be shared between report_metrics.ts and the new flat_stats.ts.
  • Adds FlatUnnamedExportEntry type and includes unnamedExports in both FlatStats.counts and the top-level array.
  • Fixes the UnnamedExport JSDoc in types.ts, which incorrectly described the cause as "a JSDoc comment above a non-declaration" — it's actually an anonymous export default expression.

Demonstrated against real packages

To validate the skill, it was applied to two kibana-operations-owned runtime packages and one additional package. All actionable issues were resolved in each case:

Package Before After
@kbn/rison missingComments: 6, missingReturns: 6, paramDocMismatches: 5 All zero
@kbn/ui-theme missingComments: 7, missingReturns: 2, paramDocMismatches: 2, missingComplexTypeInfo: 1 All zero
@kbn/json-ast missingComments: 29, missingReturns: 11, paramDocMismatches: 11, missingComplexTypeInfo: 3 All zero

Test plan

  • Run node scripts/check_package_docs.js --plugin dashboard --write and confirm target/api_docs/stats.json includes unnamedExports in both counts and as an array.
  • Verify the skill's workflow produces correct JSDoc fixes when followed against a plugin with known documentation issues.
  • Confirm check_package_docs --package @kbn/rison, --package @kbn/ui-theme, and --package @kbn/json-ast all report zero actionable issues after applying skill-guided fixes.

Adds structured flat-stats JSON output to check_package_docs and a
Claude Code skill that uses it to systematically fix API documentation
issues in Kibana plugins and packages — without needing an MCP server.

- Extract `getLink` into a shared `get_link.ts` module (was inline in
  `report_metrics.ts`); `flat_stats.ts` reuses it without duplication.
- Add `flat_stats.ts` with `buildFlatStatsForPlugin`/`writeFlatStatsFiles`
  that serialise per-plugin issue lists (path, lineNumber, type, link)
  to `<pluginDir>/target/api_docs/stats.json`.
- Add `--write` flag to the `check_package_docs` CLI (CliFlags,
  CliOptions, parse_cli_flags, runner) that triggers `writeFlatStatsFiles`.
- Add `.agents/skills/fix-package-docs/SKILL.md` — a Claude Code skill
  that replaces the MCP-tool approach. The skill runs the CLI with
  `--write`, reads the structured JSON, and guides an agent through every
  actionable issue category (missingComments, missingReturns,
  paramDocMismatches, missingComplexTypeInfo, isAnyType) with concrete
  JSDoc templates and conventions, then re-verifies.
@clintandrewhall clintandrewhall requested review from a team as code owners March 13, 2026 03:16
@clintandrewhall clintandrewhall added review release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting v9.4.0 labels Mar 13, 2026
@clintandrewhall clintandrewhall requested a review from Copilot March 13, 2026 03:19
@clintandrewhall clintandrewhall added the reviewer:claude PR review and comments with Claude label Mar 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new “fix-package-docs” agent skill and extends check_package_docs --write output so unnamed validation results are persisted to disk in target/api_docs/stats.json.

Changes:

  • Added a new agent skill guide for fixing check_package_docs validation findings.
  • Introduced --write CLI flag plumbing and flat stats.json writing per plugin/package, including unnamedExports.
  • Refactored GitHub link generation into a shared get_link.ts helper.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/kbn-docs-utils/src/types.ts Corrects UnnamedExport JSDoc to reflect actual cause (anonymous default exports).
packages/kbn-docs-utils/src/cli/types.ts Adds --write flag and writeStats option to control stats file emission.
packages/kbn-docs-utils/src/cli/tasks/report_metrics.ts Reuses shared getLink helper instead of local implementation.
packages/kbn-docs-utils/src/cli/tasks/get_link.ts New shared GitHub source-link builder for API declarations.
packages/kbn-docs-utils/src/cli/tasks/flat_stats.ts New flat stats builder/writer including unnamedExports persisted to JSON.
packages/kbn-docs-utils/src/cli/parse_cli_flags.ts Parses --write into writeStats.
packages/kbn-docs-utils/src/check_package_docs_cli.ts Wires --write to write target/api_docs/stats.json.
.agents/skills/fix-package-docs/SKILL.md New step-by-step skill for fixing API docs validation issues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .agents/skills/fix-package-docs/SKILL.md
Comment thread .agents/skills/fix-package-docs/SKILL.md Outdated
Comment thread packages/kbn-docs-utils/src/cli/tasks/flat_stats.ts
Comment thread packages/kbn-docs-utils/src/cli/tasks/flat_stats.ts Outdated
- Fix FlatStatEntry.type to use ApiDeclaration['type'] instead of string
- Eliminate duplicate missingApiItems[pluginId] lookup in buildFlatStatsForPlugin
- Fix pluginId shadowing in unnamedExports map callback
- Update stats.json example in skill to match full FlatStats schema (add apiCount, noReferences)
- Move unnamedExports to "skip; flag for human review" — fixing anonymous default exports changes the public API surface, violating the "never change runtime behavior" rule
Fixes all actionable check_package_docs validation issues:

- Add description to RisonValue type alias.
- Add full JSDoc (description, @param, @returns) to encodeUnknown, which
  was previously undocumented.
- Add @param and @returns to encode, decode, safeDecode, encodeArray, and
  decodeArray, which had descriptions but no parameter or return docs.
- Document why obj/array params are typed as `any`: these functions
  intentionally accept arbitrary runtime values (application URL state)
  whose shape is not known at compile time.

Skipped:
- isAnyType (encodeUnknown, encode): `any` is semantically correct; changing
  to `RisonValue` would break callers that pass untyped state objects.
- unnamedExports: re-export group in index.ts; requires restructuring exports.
Fixes all check_package_docs validation issues:

- Add description to the Theme type alias.
- Add description text to the deprecated tag, version, and darkMode
  constants; the @deprecated tag alone was not sufficient to satisfy
  the missing-comments check.
- Add description and @param to _setDarkMode.
- Add inline descriptions to euiLightVars and euiDarkVars, pointing
  callers toward euiThemeVars for dynamic theme support.
- Add full JSDoc (@param with dot-notation, @returns) to getEuiThemeVars.
Adds full JSDoc (description, @param, @returns) to all exported functions in
the package. Converts existing inline comment-style param docs in props.ts to
standard @param tags with dot-notation for nested opts properties. Notes the
intentional use of any for JSON value parameters in setCompilerOption and
setProp.
@clintandrewhall clintandrewhall changed the title [docs-utils] Add fix-package-docs skill and unnamedExports to stats.json [docs-utils] Add fix-package-docs skill Mar 13, 2026
@clintandrewhall clintandrewhall removed the reviewer:claude PR review and comments with Claude label Mar 13, 2026
@clintandrewhall clintandrewhall enabled auto-merge (squash) March 20, 2026 17:03
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Mar 20, 2026

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] affected Scout: [ platform / workflows_management ] plugin / local-serverless-security_complete - Scheduled workflow execution - enabling a scheduled workflow triggers executions automatically
  • [job] [logs] affected Scout: [ platform / workflows_management ] plugin / local-serverless-security_complete - Scheduled workflow execution - enabling a scheduled workflow triggers executions automatically
  • [job] [logs] affected Scout: [ security / entity_store ] plugin / local-stateful-classic - Automated email resolution integration tests - Basic email matching — two entities with same email

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/json-ast 29 0 -29
@kbn/rison 8 0 -8
@kbn/ui-theme 12 0 -12
total -49

History

@clintandrewhall clintandrewhall merged commit 7ff7c91 into elastic:main Mar 20, 2026
17 of 18 checks passed
@clintandrewhall clintandrewhall deleted the fix-package-docs-skill branch March 20, 2026 20:49
jeramysoucy pushed a commit to jeramysoucy/kibana that referenced this pull request Mar 26, 2026
There are test failures that are not at all germane to the changes made, and are in other tracked branches.  Saving an additional CI run and merging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes review v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants