CLI-613 Merge CAG subcommand tree into docs site#448
Conversation
sonar context is a Commander passthrough, so the docs generator cannot discover CAG's clap-based subcommands on its own. Wire the docs build to download the pinned CAG binary, invoke the new `tool dump-cli-tree --pretty` command, and stitch the result into commands.json / llms.txt / the HTML tree under the sonar-context entry. New files: - build-scripts/docs/dump-cag-tree.ts — download, verify, and run dump - build-scripts/docs/merge-cag-tree.ts — exported mergeCagTree + ClidocCommand types - tests/fixtures/cag-cli-tree.json — captured CAG tree fixture - tests/unit/build-scripts/docs/merge-cag-tree.test.ts — 18 unit tests Note: docs/data/commands.json and docs/llms.txt are not updated here. They will be regenerated (bun run gen:docs) once the CAG version in SONAR_CONTEXT_AUGMENTATION_VERSION is bumped to a release that includes the dump-cli-tree command. Set CAG_BINARY_PATH=<path> to use a local build during development.
✅ Deploy Preview for sonarqube-cli canceled.
|
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 23 issue(s) found across 3 file(s):
Analyzed by SonarQube Agentic Analysis in 2.7 s |
…ctly Address Gitar review: - Clean up downloaded .tar.gz/.asc in a `finally` block so failed verifications don't leave unverified archives behind and successful runs don't waste cache. - Guard `JSON.parse` of the binary's stdout with an actionable error that includes stdout/stderr snippets. - Treat absence of `value_name` as the boolean-flag signal (CAG strips it upstream). Render variadic options (`num_args: "<min>+"`) with a trailing ellipsis (e.g. `--categories <CATEGORIES>...`). - Refresh fixture from updated CAG dump (boolean flags no longer carry value_name) and add regression tests for boolean/variadic rendering.
Address Gitar suggestion: CAG emits `default: "false"` for boolean flags that initialize to false. Surfacing this as `defaultValue` in the generated docs would advertise a stringified "false" as a meaningful default. Only carry defaultValue forward when the option actually accepts a value.
Code Review ✅ Approved 4 resolved / 4 findingsIntegrates the CAG subcommand tree into the documentation site by parsing the CLI output and merging it into the existing Commander structure. Resolved issues regarding boolean flag rendering, artifact cleanup, and unsafe JSON parsing. ✅ 4 resolved✅ Quality: Boolean CAG flags rendered as value-taking options in docs
✅ Quality: dump-cag-tree leaves downloaded .tar.gz/.asc artifacts in cache
✅ Edge Case: JSON.parse of CAG stdout is unguarded
✅ Quality: Boolean CAG flags now carry a string "false" defaultValue
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|



Summary
build-scripts/docs/dump-cag-tree.ts: downloads the pinned CAG binary (PGP-verified, cached undernode_modules/.cache/), invokestool dump-cli-tree --pretty, and returns the parsed JSON treebuild-scripts/docs/merge-cag-tree.ts: exportedmergeCagTree(cagTree, allCommands)that stitches CAG subcommands under the existingsonar-contextentry, setsisGroup: true, clears the passthrough[action] [args...], maps options toClidocOption, and assignsrequiresAuthflagsgenerate-docs.tsto callawait dumpCagTree()+mergeCagTree()after the Commander tree is serializedsonar context guidelines get,sonar context dependencies check,sonar context navigation search-signaturestests/unit/build-scripts/docs/merge-cag-tree.test.tsusing the capturedtests/fixtures/cag-cli-tree.jsonfixtureContext:
sonar contextis a Commander passthrough — it just forwards args to the CAG binary. The docs generator walks Commander only, socommands.jsoncurrently showssonar-contextwithisGroup: false, children: []. This PR bridges the gap via the newtool dump-cli-treecommand added to CAG in SonarSource/sonar-context-augmentation#286.gen:docswill fail untilSONAR_CONTEXT_AUGMENTATION_VERSIONis bumped to a version that includesdump-cli-treeandbun run fetch:signaturesis refreshed. UseCAG_BINARY_PATH=<path-to-dev-build> bun run gen:docsfor local development.After the CAG version is bumped,
bun run gen:docsshould be re-run to commit updateddocs/data/commands.jsonanddocs/llms.txt.Test plan
bun test tests/unit/build-scripts/docs/merge-cag-tree.test.ts— 18 tests passbun test tests/unit/— 1578 pass, 0 fail (no regressions)bun run --bun tsc --noEmit— no new type errors (pre-existingpicomatcherror only)bun run gen:docssucceeds without overridedocs/data/commands.jsonhassonar-contextwithisGroup: trueand all CAG subcommand entriesdocs/llms.txtcontains### sonar context guidelines get *,### sonar context navigation search-signatures *, etc.docs/commands.html#sonar-contextlocally — Subcommands panel renders the full tree