@redpanda-data/docs-extensions-and-macros 5.0.4 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -151,18 +151,46 @@ const tools = [
151
151
  },
152
152
  {
153
153
  name: 'generate_rpk_docs',
154
- description: 'Generate RPK command-line documentation for a specific version. Creates AsciiDoc files for all rpk commands. Writers use this when updating CLI docs for a new release. Can run in background with progress streaming.',
154
+ description: 'Generate rpk command-line documentation using the JSON-based `rpk --print-tree` command (requires rpk v26.2.0+). Creates AsciiDoc files for all rpk commands including plugins (connect, ai, check, etc.). Supports overrides for description improvements and generates diffs between versions.',
155
155
  inputSchema: {
156
156
  type: 'object',
157
157
  properties: {
158
158
  tag: {
159
159
  type: 'string',
160
- description: 'Git tag for released content (for example "25.3.1" or "v25.3.1"). Auto-prepends "v" if not present. Use tags for GA or beta releases.'
160
+ description: 'Git tag for released content (for example "26.2.0" or "v26.2.0"). Auto-prepends "v" if not present. Use tags for GA or beta releases.'
161
161
  },
162
162
  branch: {
163
163
  type: 'string',
164
164
  description: 'Branch name for in-progress content (for example "dev", "main"). Use branches for documentation under development.'
165
165
  },
166
+ overrides: {
167
+ type: 'string',
168
+ description: 'Path to overrides JSON file for improving auto-generated descriptions (defaults to docs-data/rpk-overrides.json if present)'
169
+ },
170
+ fetch_binary: {
171
+ type: 'boolean',
172
+ description: 'Download rpk binary for the specified version instead of using local rpk. Required for versions with --print-tree support.'
173
+ },
174
+ diff: {
175
+ type: 'string',
176
+ description: 'Generate diff against previous version (for example "v26.1.9"). Shows new commands, removed commands, and flag changes.'
177
+ },
178
+ update_whats_new: {
179
+ type: 'boolean',
180
+ description: 'Update whats-new.adoc with changes from the diff (optional, defaults to false)'
181
+ },
182
+ draft_missing: {
183
+ type: 'boolean',
184
+ description: 'Generate draft pages for new commands that appear in the diff (optional, defaults to false)'
185
+ },
186
+ output_dir: {
187
+ type: 'string',
188
+ description: 'Output directory for generated AsciiDoc files (defaults to modules/reference/pages/rpk)'
189
+ },
190
+ data_dir: {
191
+ type: 'string',
192
+ description: 'Directory for versioned JSON and diff files (defaults to docs-data)'
193
+ },
166
194
  background: {
167
195
  type: 'boolean',
168
196
  description: 'Run as background job with progress updates. Returns job ID immediately instead of waiting. Default: false (run synchronously)'
package/bin/doc-tools.js CHANGED
@@ -181,6 +181,76 @@ programCli
181
181
  }
182
182
  })
183
183
 
184
+ /**
185
+ * get-antora-value
186
+ *
187
+ * @description
188
+ * Reads a value from antora.yml using a dot-separated key path.
189
+ * Useful for retrieving version attributes and other configuration in CI/CD pipelines.
190
+ *
191
+ * @why
192
+ * Automation workflows need to read the currently documented versions from antora.yml
193
+ * to determine what version to diff against when generating updated documentation.
194
+ *
195
+ * @example
196
+ * # Get the latest documented Redpanda version
197
+ * npx doc-tools get-antora-value asciidoc.attributes.latest-redpanda-tag
198
+ * # Output: v26.1.9
199
+ *
200
+ * # Get the component name
201
+ * npx doc-tools get-antora-value name
202
+ * # Output: ROOT
203
+ *
204
+ * @requirements
205
+ * - Must run from directory containing antora.yml or antora.yaml
206
+ */
207
+ programCli
208
+ .command('get-antora-value')
209
+ .description('Read a value from antora.yml by dot-path (e.g., asciidoc.attributes.latest-redpanda-tag)')
210
+ .argument('<keyPath>', 'Dot-separated path to the value (e.g., asciidoc.attributes.latest-redpanda-tag)')
211
+ .action((keyPath) => {
212
+ const value = getAntoraValue(keyPath)
213
+ if (value === undefined) {
214
+ process.exit(1)
215
+ }
216
+ console.log(value)
217
+ })
218
+
219
+ /**
220
+ * set-antora-value
221
+ *
222
+ * @description
223
+ * Sets a value in antora.yml using a dot-separated key path.
224
+ * Uses surgical text replacement to preserve formatting and comments.
225
+ *
226
+ * @why
227
+ * Automation workflows need to update version attributes in antora.yml
228
+ * after generating documentation to track the currently documented version.
229
+ *
230
+ * @example
231
+ * # Update the latest rpk version
232
+ * npx doc-tools set-antora-value asciidoc.attributes.latest-rpk-version v26.2.0
233
+ *
234
+ * # Update the latest Redpanda version
235
+ * npx doc-tools set-antora-value asciidoc.attributes.latest-redpanda-tag v26.2.0
236
+ *
237
+ * @requirements
238
+ * - Must run from directory containing antora.yml or antora.yaml
239
+ */
240
+ programCli
241
+ .command('set-antora-value')
242
+ .description('Set a value in antora.yml by dot-path (e.g., asciidoc.attributes.latest-rpk-version)')
243
+ .argument('<keyPath>', 'Dot-separated path to the value (e.g., asciidoc.attributes.latest-rpk-version)')
244
+ .argument('<value>', 'The value to set')
245
+ .action((keyPath, value) => {
246
+ const success = setAntoraValue(keyPath, value)
247
+ if (!success) {
248
+ console.error(`Failed to set ${keyPath}`)
249
+ process.exit(1)
250
+ }
251
+ console.log(`Set ${keyPath} = ${value}`)
252
+ })
253
+
184
254
  /**
185
255
  * link-readme
186
256
  *
@@ -956,80 +1026,219 @@ automation
956
1026
  * generate rpk-docs
957
1027
  *
958
1028
  * @description
959
- * Generates comprehensive CLI reference documentation for RPK (Redpanda Keeper), the official
960
- * Redpanda command-line tool. Starts Redpanda in Docker (RPK is bundled with Redpanda), executes
961
- * `rpk --help` for all commands and subcommands recursively, parses the help output, and generates
962
- * structured AsciiDoc documentation for each command with usage, flags, and descriptions.
963
- * Optionally compares RPK commands between versions to identify new or changed commands.
1029
+ * Generates comprehensive CLI reference documentation for rpk (Redpanda Keeper).
1030
+ * Clones the Redpanda source, builds rpk with Go, and parses `rpk --print-tree` JSON output.
1031
+ * Detects Linux-only commands by analyzing Go build tags in the source code.
1032
+ *
1033
+ * Key features:
1034
+ * - Clones source from GitHub (sparse checkout for speed)
1035
+ * - Builds rpk from source using Go
1036
+ * - Parses Go build tags to detect Linux-only commands
1037
+ * - Automatically includes rpk plugins (connect, ai, check, etc.)
1038
+ * - Supports overrides.json for description improvements
1039
+ * - Generates versioned JSON files for downstream consumers (tooltips, etc.)
1040
+ * - Generates diffs between versions for release notes
964
1041
  *
965
1042
  * @why
966
- * RPK has dozens of commands and subcommands with complex flags and options. The built-in help
967
- * text is the source of truth for RPK's CLI interface. Manual documentation becomes outdated as
968
- * RPK evolves. This automation extracts documentation directly from RPK's help output, ensuring
969
- * accuracy. Running RPK from Docker guarantees the exact version being documented, and diffing
970
- * between versions automatically highlights CLI changes for release notes.
1043
+ * Building from source provides accurate platform detection by analyzing Go build tags
1044
+ * (//go:build linux) rather than comparing binaries. This is faster and more reliable.
971
1045
  *
972
1046
  * @example
973
- * # Basic: Generate RPK docs for a specific version
974
- * npx doc-tools generate rpk-docs --tag v25.3.1
1047
+ * # Generate docs for a specific version
1048
+ * npx doc-tools generate rpk-docs --ref v26.2.0
975
1049
  *
976
- * # Compare RPK commands between versions
977
- * npx doc-tools generate rpk-docs \
978
- * --tag v25.3.1 \
979
- * --diff v25.2.1
1050
+ * # Generate docs for latest development branch
1051
+ * npx doc-tools generate rpk-docs --ref dev
980
1052
  *
981
- * # Use custom Docker repository
982
- * npx doc-tools generate rpk-docs \
983
- * --tag v25.3.1 \
984
- * --docker-repo docker.redpanda.com/redpandadata/redpanda
1053
+ * # Auto-detect local redpanda checkout (if available)
1054
+ * npx doc-tools generate rpk-docs
985
1055
  *
986
- * # Full workflow: document new release
987
- * VERSION=$(npx doc-tools get-redpanda-version)
988
- * npx doc-tools generate rpk-docs --tag $VERSION
1056
+ * # Generate with diff against previous version
1057
+ * npx doc-tools generate rpk-docs --ref v26.2.0 --diff v26.1.9
1058
+ *
1059
+ * # Use custom overrides file
1060
+ * npx doc-tools generate rpk-docs --ref dev --overrides custom-overrides.json
989
1061
  *
990
1062
  * @requirements
991
- * - Docker must be installed and running
992
- * - Sufficient disk space for Docker image
993
- * - Internet connection to pull Docker images
1063
+ * - Go must be installed (https://go.dev/)
1064
+ * - Git must be installed (for cloning source)
994
1065
  */
995
1066
  automation
996
1067
  .command('rpk-docs')
997
- .description('Generate AsciiDoc documentation for rpk CLI commands. Defaults to branch "dev" if neither --tag nor --branch is specified.')
998
- .option('-t, --tag <tag>', 'Git tag for released content (GA/beta)')
999
- .option('-b, --branch <branch>', 'Branch name for in-progress content')
1000
- .option('--docker-repo <repo>', 'Docker repository to use', commonOptions.dockerRepo)
1001
- .option('--console-tag <tag>', 'Redpanda Console version to use', commonOptions.consoleTag)
1002
- .option('--console-docker-repo <repo>', 'Docker repository for Console', commonOptions.consoleDockerRepo)
1003
- .option('--diff <oldTag>', 'Also diff autogenerated rpk docs from <oldTag> → <tag>')
1004
- .action((options) => {
1005
- verifyMetricsDependencies()
1068
+ .description('Generate rpk CLI documentation from source. Builds rpk and parses source for platform detection.')
1069
+ .option('-r, --ref <ref>', 'Git branch or tag to document (e.g., dev, v26.2.0). Clones from GitHub.')
1070
+ .option('--from-source <path>', 'Path to local rpk source (src/go/rpk directory)')
1071
+ .option('--from-json <path>', 'Regenerate docs from an existing versioned JSON file (skips building)')
1072
+ .option('--overrides <path>', 'Path to overrides JSON file', 'docs-data/rpk-overrides.json')
1073
+ .option('--diff <oldVersion>', 'Generate diff against previous version')
1074
+ .option('--update-whats-new [path]', 'Update what\'s-new file with rpk changes from diff (default: modules/get-started/pages/release-notes/redpanda.adoc)')
1075
+ .option('--draft-missing', 'Generate draft pages for new commands')
1076
+ .option('--output-dir <dir>', 'Output directory for generated AsciiDoc', 'modules/reference/pages/rpk')
1077
+ .option('--cloud-secret-dir <dir>', 'Output directory for rpk cloud and rpk security secret commands (defaults to partials relative to output-dir)')
1078
+ .option('--data-dir <dir>', 'Directory for versioned JSON and diff files', 'docs-data')
1079
+ .option('--preserve-from <path>', 'Path to existing docs to preserve cloud conditionals from')
1080
+ .option('--print-summary', 'Print PR summary (for GitHub Actions)')
1081
+ .option('--summary-file <path>', 'Write PR summary to file (for GitHub Actions)')
1082
+ .option('--show-info', 'Include info-level validation messages')
1083
+ .action(async (options) => {
1084
+ try {
1085
+ const { handleRpkDocsGeneration } = require('../tools/rpk-docs/rpk-docs-handler.js')
1086
+
1087
+ // Handle --update-whats-new with optional path
1088
+ let whatsNewPath = null
1089
+ if (options.updateWhatsNew !== undefined) {
1090
+ // If true (flag without path), use default; if string, use that path
1091
+ whatsNewPath = typeof options.updateWhatsNew === 'string'
1092
+ ? options.updateWhatsNew
1093
+ : 'modules/get-started/pages/release-notes/redpanda.adoc'
1094
+ }
1006
1095
 
1007
- if (options.tag && options.branch) {
1008
- console.error('Error: Cannot specify both --tag and --branch')
1096
+ const result = await handleRpkDocsGeneration({
1097
+ ref: options.ref,
1098
+ fromSource: options.fromSource,
1099
+ fromJson: options.fromJson,
1100
+ overrides: options.overrides,
1101
+ diff: options.diff,
1102
+ updateWhatsNew: whatsNewPath,
1103
+ draftMissing: options.draftMissing,
1104
+ outputDir: options.outputDir,
1105
+ cloudSecretDir: options.cloudSecretDir,
1106
+ dataDir: options.dataDir,
1107
+ preserveFrom: options.preserveFrom,
1108
+ printSummary: options.printSummary,
1109
+ showInfo: options.showInfo
1110
+ })
1111
+
1112
+ if (result.success) {
1113
+ console.log('\n✓ rpk documentation generated successfully')
1114
+
1115
+ // Write PR summary to file if requested (useful for GitHub Actions)
1116
+ if (options.summaryFile && result.prSummary) {
1117
+ fs.writeFileSync(options.summaryFile, result.prSummary, 'utf8')
1118
+ console.log(`PR summary written to: ${options.summaryFile}`)
1119
+ }
1120
+
1121
+ // Exit with warning if validation errors found
1122
+ if (result.validationResult?.summary?.totalErrors > 0) {
1123
+ console.error(`\n⚠ Validation found ${result.validationResult.summary.totalErrors} error(s)`)
1124
+ process.exit(1)
1125
+ }
1126
+
1127
+ process.exit(0)
1128
+ } else {
1129
+ console.error('Error: Generation failed')
1130
+ process.exit(1)
1131
+ }
1132
+ } catch (err) {
1133
+ console.error(`Error: ${err.message}`)
1009
1134
  process.exit(1)
1010
1135
  }
1136
+ })
1011
1137
 
1012
- const newTag = options.tag || options.branch || 'dev'
1013
- const oldTag = options.diff
1138
+ /**
1139
+ * validate rpk-overrides
1140
+ *
1141
+ * @description
1142
+ * Validates the rpk-overrides.json file against the JSON schema and checks for common issues:
1143
+ * - Schema compliance (required fields, valid types)
1144
+ * - Valid $ref references (no broken or circular refs)
1145
+ * - Valid command paths (compared against actual rpk command tree)
1146
+ * - Valid admonition locations (after_flags, after_usage, etc.)
1147
+ * - Valid platform values (linux, darwin, windows)
1148
+ *
1149
+ * @why
1150
+ * Catching override errors early prevents broken documentation. This command lets writers
1151
+ * validate their changes before generation, avoiding cryptic errors during the build process.
1152
+ *
1153
+ * @example
1154
+ * # Validate overrides with default paths
1155
+ * npx doc-tools validate rpk-overrides
1156
+ *
1157
+ * # Validate against a specific rpk tree (for complete command path validation)
1158
+ * npx doc-tools validate rpk-overrides --tree docs-data/rpk-v26.2.0.json
1159
+ *
1160
+ * # Validate a custom overrides file
1161
+ * npx doc-tools validate rpk-overrides --overrides my-overrides.json
1162
+ *
1163
+ * # Strict mode - exit with error code on validation failures
1164
+ * npx doc-tools validate rpk-overrides --strict
1165
+ *
1166
+ * @requirements
1167
+ * - rpk-overrides.schema.json in docs-data/
1168
+ */
1169
+ automation
1170
+ .command('rpk-overrides')
1171
+ .description('Validate rpk-overrides.json against schema and check for common issues')
1172
+ .option('--overrides <path>', 'Path to overrides JSON file', 'docs-data/rpk-overrides.json')
1173
+ .option('--tree <path>', 'Path to rpk tree JSON file for command path validation (e.g., docs-data/rpk-v26.2.0.json)')
1174
+ .option('--strict', 'Exit with error code on validation failures')
1175
+ .action((options) => {
1176
+ try {
1177
+ const { loadAndValidateOverrides } = require('../tools/rpk-docs/validate-overrides.js')
1178
+ const repoRoot = findRepoRoot()
1179
+ const overridesPath = path.resolve(repoRoot, options.overrides)
1180
+
1181
+ // Load tree if provided for command path validation
1182
+ let commandTree = null
1183
+ if (options.tree) {
1184
+ const treePath = path.resolve(repoRoot, options.tree)
1185
+ if (!fs.existsSync(treePath)) {
1186
+ console.error(`Error: Tree file not found: ${treePath}`)
1187
+ process.exit(1)
1188
+ }
1189
+ const treeData = JSON.parse(fs.readFileSync(treePath, 'utf8'))
1190
+ commandTree = treeData.tree || treeData
1191
+ }
1014
1192
 
1015
- if (oldTag) {
1016
- const oldDir = path.join('autogenerated', oldTag, 'rpk')
1017
- if (!fs.existsSync(oldDir)) {
1018
- console.log(`Generating rpk docs for old tag ${oldTag}…`)
1019
- runClusterDocs('rpk', oldTag, options)
1193
+ console.log(`Validating: ${overridesPath}`)
1194
+ if (commandTree) {
1195
+ console.log(`Comparing against tree from: ${options.tree}`)
1196
+ } else {
1197
+ console.log('Note: Skipping command path validation (no --tree provided)')
1020
1198
  }
1021
- }
1199
+ console.log('')
1022
1200
 
1023
- console.log(`Generating rpk docs for new tag ${newTag}…`)
1024
- runClusterDocs('rpk', newTag, options)
1201
+ const { overrides, validation } = loadAndValidateOverrides(overridesPath, commandTree)
1025
1202
 
1026
- if (oldTag) {
1027
- diffDirs('rpk', oldTag, newTag)
1028
- }
1203
+ if (!overrides) {
1204
+ console.error('Error: Could not load overrides file')
1205
+ process.exit(1)
1206
+ }
1029
1207
 
1030
- process.exit(0)
1208
+ // Print results
1209
+ console.log('=' .repeat(60))
1210
+ console.log('VALIDATION RESULTS')
1211
+ console.log('='.repeat(60))
1212
+
1213
+ if (validation.errors.length === 0 && validation.warnings.length === 0) {
1214
+ console.log('✓ No issues found')
1215
+ } else {
1216
+ console.log(validation.format())
1217
+ }
1218
+
1219
+ console.log('='.repeat(60))
1220
+ console.log(`Errors: ${validation.errors.length}`)
1221
+ console.log(`Warnings: ${validation.warnings.length}`)
1222
+ console.log('='.repeat(60))
1223
+
1224
+ // Exit with appropriate code
1225
+ if (options.strict && !validation.valid) {
1226
+ console.log('\n✗ Validation failed (strict mode)')
1227
+ process.exit(1)
1228
+ } else if (validation.valid) {
1229
+ console.log('\n✓ Validation passed')
1230
+ process.exit(0)
1231
+ } else {
1232
+ console.log('\n⚠ Validation completed with errors (use --strict to fail)')
1233
+ process.exit(0)
1234
+ }
1235
+ } catch (err) {
1236
+ console.error(`Error: ${err.message}`)
1237
+ process.exit(1)
1238
+ }
1031
1239
  })
1032
1240
 
1241
+
1033
1242
  /**
1034
1243
  * generate helm-spec
1035
1244
  *
@@ -1,5 +1,15 @@
1
1
  /**
2
- * MCP Tools - RPK Documentation Generation
2
+ * MCP Tools - rpk Documentation Generation
3
+ *
4
+ * Generates rpk CLI reference documentation by building from Go source
5
+ * and parsing build tags to detect Linux-only commands.
6
+ *
7
+ * Features:
8
+ * - Builds rpk from source (requires Go)
9
+ * - Detects Linux-only commands from Go build tags
10
+ * - Supports overrides.json for description improvements
11
+ * - Generates diffs between versions for release notes
12
+ * - Publishes versioned JSON for downstream consumers
3
13
  *
4
14
  * OPTIMIZATION: This tool calls CLI, doesn't use LLM directly.
5
15
  * - No model recommendation (CLI tool)
@@ -12,14 +22,22 @@ const { getAntoraStructure } = require('./antora');
12
22
  const { createJob } = require('./job-queue');
13
23
 
14
24
  /**
15
- * Generate RPK command documentation
25
+ * Generate rpk command documentation from source
16
26
  *
17
- * Use tags for released content (GA or beta), branches for in-progress content.
18
- * Defaults to branch "dev" if neither tag nor branch is provided.
27
+ * Clones redpanda source (or uses local checkout) and builds rpk to generate
28
+ * documentation. Parses Go build tags to detect Linux-only commands.
19
29
  *
20
30
  * @param {Object} args - Arguments
21
- * @param {string} [args.tag] - Git tag for released content (for example, "v25.3.1")
22
- * @param {string} [args.branch] - Branch name for in-progress content (for example, "dev", "main")
31
+ * @param {string} [args.ref] - Git ref to document (e.g., "dev", "v26.2.0", "main")
32
+ * @param {string} [args.tag] - Git tag (alias for ref, backward compatibility)
33
+ * @param {string} [args.branch] - Git branch (alias for ref, backward compatibility)
34
+ * @param {string} [args.from_source] - Path to local rpk source directory
35
+ * @param {string} [args.overrides] - Path to overrides JSON file (defaults to docs-data/rpk-overrides.json)
36
+ * @param {string} [args.diff] - Generate diff against this previous version
37
+ * @param {boolean} [args.update_whats_new] - Update whats-new.adoc with changes
38
+ * @param {boolean} [args.draft_missing] - Generate draft pages for new commands
39
+ * @param {string} [args.output_dir] - Output directory for generated AsciiDoc
40
+ * @param {string} [args.data_dir] - Directory for versioned JSON and diff files
23
41
  * @param {boolean} [args.background] - Run as background job
24
42
  * @returns {Object} Generation results
25
43
  */
@@ -35,23 +53,23 @@ function generateRpkDocs(args) {
35
53
  };
36
54
  }
37
55
 
38
- // Validate that tag and branch are mutually exclusive
39
- if (args.tag && args.branch) {
40
- return {
41
- success: false,
42
- error: 'Cannot specify both tag and branch',
43
- suggestion: 'Use either --tag or --branch, not both'
44
- };
45
- }
46
-
47
- // Default to 'dev' branch if neither provided
48
- const gitRef = args.tag || args.branch || 'dev';
49
- const refType = args.tag ? 'tag' : 'branch';
50
-
51
- // Normalize version (add 'v' prefix if not present and not a branch name like 'dev' or 'main')
52
- let version = gitRef;
53
- if (args.tag && !version.startsWith('v')) {
54
- version = `v${version}`;
56
+ // Determine version from ref, tag, or branch (backward compatibility)
57
+ // Priority: ref > tag > branch > 'dev' (default)
58
+ let version;
59
+ let refType;
60
+ if (args.ref) {
61
+ version = args.ref;
62
+ refType = args.ref.match(/^v?\d/) ? 'tag' : 'branch';
63
+ } else if (args.tag) {
64
+ version = args.tag.startsWith('v') ? args.tag : `v${args.tag}`;
65
+ refType = 'tag';
66
+ } else if (args.branch) {
67
+ version = args.branch;
68
+ refType = 'branch';
69
+ } else {
70
+ // No ref specified - default to 'dev'
71
+ version = 'dev';
72
+ refType = 'branch';
55
73
  }
56
74
 
57
75
  // Get doc-tools command (handles both local and installed)
@@ -60,12 +78,40 @@ function generateRpkDocs(args) {
60
78
  // Build command arguments array
61
79
  const baseArgs = ['generate', 'rpk-docs'];
62
80
 
63
- if (args.tag) {
64
- baseArgs.push('--tag');
65
- baseArgs.push(version);
66
- } else {
67
- baseArgs.push('--branch');
68
- baseArgs.push(version);
81
+ // Always use --ref (defaults to 'dev' if not specified)
82
+ baseArgs.push('--ref', version);
83
+
84
+ // Add optional arguments
85
+ if (args.from_source) {
86
+ baseArgs.push('--from-source', args.from_source);
87
+ }
88
+
89
+ if (args.overrides) {
90
+ baseArgs.push('--overrides', args.overrides);
91
+ }
92
+
93
+ if (args.diff) {
94
+ let diffVersion = args.diff;
95
+ if (!diffVersion.startsWith('v')) {
96
+ diffVersion = `v${diffVersion}`;
97
+ }
98
+ baseArgs.push('--diff', diffVersion);
99
+ }
100
+
101
+ if (args.update_whats_new) {
102
+ baseArgs.push('--update-whats-new');
103
+ }
104
+
105
+ if (args.draft_missing) {
106
+ baseArgs.push('--draft-missing');
107
+ }
108
+
109
+ if (args.output_dir) {
110
+ baseArgs.push('--output-dir', args.output_dir);
111
+ }
112
+
113
+ if (args.data_dir) {
114
+ baseArgs.push('--data-dir', args.data_dir);
69
115
  }
70
116
 
71
117
  // If background mode, create job and return immediately
@@ -79,8 +125,10 @@ function generateRpkDocs(args) {
79
125
  success: true,
80
126
  background: true,
81
127
  job_id: jobId,
82
- message: `RPK docs generation started in background. Use get_job_status with job_id: ${jobId} to check progress.`,
83
- [refType]: version
128
+ message: `rpk docs generation started in background. Use get_job_status with job_id: ${jobId} to check progress.`,
129
+ ref: version,
130
+ version: version,
131
+ ref_type: refType
84
132
  };
85
133
  }
86
134
 
@@ -115,24 +163,46 @@ function generateRpkDocs(args) {
115
163
 
116
164
  const output = result.stdout;
117
165
  const commandCountMatch = output.match(/(\d+) commands/i);
166
+ const filesGeneratedMatch = output.match(/Generated (\d+) files/i);
118
167
 
119
- return {
168
+ const response = {
120
169
  success: true,
121
- [refType]: version,
122
- files_generated: [`autogenerated/${version}/rpk/*.adoc`],
170
+ ref: version,
171
+ version: version,
172
+ ref_type: refType,
123
173
  commands_documented: commandCountMatch ? parseInt(commandCountMatch[1]) : null,
124
- output: output.trim(),
125
- summary: `Generated RPK documentation for Redpanda ${refType} ${version}`
174
+ files_generated: filesGeneratedMatch ? parseInt(filesGeneratedMatch[1]) : null,
175
+ output: output.trim()
126
176
  };
177
+
178
+ // Add diff summary if available
179
+ if (args.diff) {
180
+ response.diff_from = args.diff.startsWith('v') ? args.diff : `v${args.diff}`;
181
+ response.diff_to = version;
182
+ }
183
+
184
+ response.summary = `Generated rpk documentation for ${version}`;
185
+
186
+ return response;
127
187
  } catch (err) {
128
- return {
188
+ const response = {
129
189
  success: false,
130
190
  error: err.message,
131
191
  stdout: err.stdout || '',
132
192
  stderr: err.stderr || '',
133
- exitCode: err.status,
134
- suggestion: 'Check that the version exists in the Redpanda repository'
193
+ exitCode: err.status
135
194
  };
195
+
196
+ // Provide helpful suggestions based on error
197
+ if (err.message.includes('Go is required')) {
198
+ response.suggestion = 'Install Go from https://go.dev/ and ensure it\'s in your PATH.';
199
+ } else if (err.message.includes('not found') || err.message.includes('ENOENT')) {
200
+ response.suggestion = 'Ensure Go and Git are installed and in your PATH.';
201
+ } else {
202
+ response.suggestion = 'Check that the version/ref exists in the Redpanda repository.';
203
+ }
204
+
205
+ return response;
136
206
  }
137
207
  }
138
208