eslint-plugin-traceability 1.7.1 → 1.8.1

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +76 -37
  3. package/SECURITY.md +132 -0
  4. package/lib/src/index.d.ts +6 -35
  5. package/lib/src/index.js +8 -5
  6. package/lib/src/maintenance/batch.d.ts +5 -0
  7. package/lib/src/maintenance/batch.js +5 -0
  8. package/lib/src/maintenance/cli.js +34 -212
  9. package/lib/src/maintenance/commands.d.ts +32 -0
  10. package/lib/src/maintenance/commands.js +139 -0
  11. package/lib/src/maintenance/detect.d.ts +2 -0
  12. package/lib/src/maintenance/detect.js +4 -0
  13. package/lib/src/maintenance/flags.d.ts +99 -0
  14. package/lib/src/maintenance/flags.js +121 -0
  15. package/lib/src/maintenance/report.d.ts +2 -0
  16. package/lib/src/maintenance/report.js +2 -0
  17. package/lib/src/maintenance/update.d.ts +4 -0
  18. package/lib/src/maintenance/update.js +4 -0
  19. package/lib/src/rules/helpers/require-story-io.d.ts +3 -0
  20. package/lib/src/rules/helpers/require-story-io.js +20 -6
  21. package/lib/src/rules/helpers/valid-annotation-options.js +15 -4
  22. package/lib/src/rules/helpers/valid-annotation-utils.js +5 -0
  23. package/lib/src/rules/helpers/valid-story-reference-helpers.d.ts +3 -4
  24. package/lib/src/utils/reqAnnotationDetection.d.ts +4 -1
  25. package/lib/src/utils/reqAnnotationDetection.js +43 -15
  26. package/lib/tests/config/flat-config-presets-integration.test.d.ts +1 -0
  27. package/lib/tests/config/flat-config-presets-integration.test.js +75 -0
  28. package/lib/tests/maintenance/cli.test.js +89 -0
  29. package/lib/tests/plugin-default-export-and-configs.test.js +0 -2
  30. package/lib/tests/rules/prefer-implements-annotation.test.js +28 -0
  31. package/lib/tests/rules/require-req-annotation.test.js +8 -1
  32. package/lib/tests/rules/require-story-annotation.test.js +9 -4
  33. package/lib/tests/utils/ts-language-options.d.ts +1 -7
  34. package/lib/tests/utils/ts-language-options.js +8 -5
  35. package/package.json +11 -7
  36. package/user-docs/api-reference.md +527 -0
  37. package/user-docs/eslint-9-setup-guide.md +722 -0
  38. package/user-docs/examples.md +74 -0
  39. package/user-docs/migration-guide.md +174 -0
@@ -1,27 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
3
  Object.defineProperty(exports, "__esModule", { value: true });
7
4
  exports.runMaintenanceCli = runMaintenanceCli;
8
- const path_1 = __importDefault(require("path"));
9
- const detect_1 = require("./detect");
10
- const batch_1 = require("./batch");
11
- const update_1 = require("./update");
12
- const report_1 = require("./report");
13
- const EXIT_OK = 0;
14
- const EXIT_STALE = 1;
15
- const EXIT_USAGE = 2;
16
- /**
17
- * Extract the subcommand and its arguments from a raw argv array.
18
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
19
- * @req REQ-MAINT-SAFE - Centralize parsing of CLI command and arguments
20
- */
21
- function parseCliInput(rawArgv) {
22
- const [, , command, ...rest] = rawArgv;
23
- return { command, args: rest };
24
- }
5
+ const commands_1 = require("./commands");
6
+ const flags_1 = require("./flags");
25
7
  /**
26
8
  * Maintenance CLI entry point.
27
9
  * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
@@ -33,217 +15,57 @@ function parseCliInput(rawArgv) {
33
15
  * @req REQ-MAINT-SAFE - Provide clear exit codes and avoid unsafe defaults
34
16
  */
35
17
  function runMaintenanceCli(rawArgv) {
36
- const { command, args } = parseCliInput(rawArgv);
18
+ const initialNormalized = (0, flags_1.normalizeCliArgs)(rawArgv);
19
+ const { subcommand: command } = initialNormalized;
37
20
  if (!command || command === "-h" || command === "--help") {
21
+ /**
22
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
23
+ * @req REQ-MAINT-SAFE - Handle help requests safely and provide discoverable usage output
24
+ */
38
25
  printHelp();
39
- return EXIT_OK;
26
+ return commands_1.EXIT_OK;
40
27
  }
28
+ // Re-use the normalized arguments object for handlers so that they
29
+ // receive the subcommand name and its raw argument vector unchanged.
30
+ const normalized = initialNormalized;
41
31
  try {
42
32
  switch (command) {
43
33
  case "detect":
44
- return handleDetect(args);
34
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-DETECT - Dispatch to detection handler
35
+ return (0, commands_1.handleDetect)(normalized);
45
36
  case "verify":
46
- return handleVerify(args);
37
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-VERIFY - Dispatch to verification handler
38
+ return (0, commands_1.handleVerify)(normalized);
47
39
  case "report":
48
- return handleReport(args);
49
- case "update":
50
- return handleUpdate(args);
40
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-REPORT - Dispatch to reporting handler
41
+ return (0, commands_1.handleReport)(normalized);
42
+ case "update": {
43
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-UPDATE - Dispatch to update handler
44
+ const result = (0, commands_1.handleUpdate)(normalized);
45
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-SAFE - Print help on usage errors from update
46
+ if (result === commands_1.EXIT_USAGE) {
47
+ printHelp();
48
+ }
49
+ return result;
50
+ }
51
51
  default:
52
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md @req REQ-MAINT-SAFE - Handle unknown commands safely with diagnostics
52
53
  console.error(`Unknown command: ${command}`);
53
54
  printHelp();
54
- return EXIT_USAGE;
55
+ return commands_1.EXIT_USAGE;
55
56
  }
56
57
  }
57
58
  catch (error) {
58
- // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
59
- // @req REQ-MAINT-SAFE - Catch unexpected errors and emit concise diagnostics
59
+ /**
60
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
61
+ * @req REQ-MAINT-SAFE - Catch unexpected errors and surface concise diagnostics without crashing
62
+ */
60
63
  const message = error instanceof Error
61
64
  ? error.message
62
65
  : "Unknown error in maintenance CLI";
63
66
  console.error(`traceability-maint failed: ${message}`);
64
- return EXIT_USAGE;
65
- }
66
- }
67
- /**
68
- * Initialize default flags for the maintenance CLI.
69
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
70
- * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
71
- */
72
- function createDefaultFlags() {
73
- return {
74
- root: process.cwd(),
75
- json: false,
76
- };
77
- }
78
- /**
79
- * Handle a single CLI argument and update the flags accordingly.
80
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
81
- * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
82
- */
83
- function applyFlag(flags, args, index) {
84
- const arg = args[index];
85
- if (arg === "--root" && typeof args[index + 1] === "string") {
86
- flags.root = path_1.default.resolve(args[index + 1]);
87
- return index + 1;
88
- }
89
- if (arg === "--json") {
90
- flags.json = true;
91
- return index;
92
- }
93
- if (arg === "--format" && typeof args[index + 1] === "string") {
94
- const value = args[index + 1];
95
- if (value === "text" || value === "json") {
96
- flags.format = value;
97
- }
98
- else {
99
- throw new Error(`Invalid format: ${value}. Expected 'text' or 'json'.`);
100
- }
101
- return index + 1;
102
- }
103
- if (arg === "--from" && typeof args[index + 1] === "string") {
104
- flags.from = args[index + 1];
105
- return index + 1;
106
- }
107
- if (arg === "--to" && typeof args[index + 1] === "string") {
108
- flags.to = args[index + 1];
109
- return index + 1;
110
- }
111
- if (arg === "--dry-run") {
112
- flags.dryRun = true;
113
- return index;
114
- }
115
- return index;
116
- }
117
- /**
118
- * Basic flag parser for maintenance CLI subcommands.
119
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
120
- * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
121
- */
122
- function parseFlags(args) {
123
- const flags = createDefaultFlags();
124
- for (let i = 0; i < args.length; i += 1) {
125
- i = applyFlag(flags, args, i);
126
- }
127
- return flags;
128
- }
129
- /**
130
- * Handle the `detect` subcommand for stale @story annotations.
131
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
132
- * @req REQ-MAINT-DETECT - CLI surface for detection of stale annotations
133
- * @req REQ-MAINT-SAFE - Return specific exit codes for stale vs clean states
134
- */
135
- function handleDetect(args) {
136
- const flags = parseFlags(args);
137
- const root = flags.root;
138
- const stale = (0, detect_1.detectStaleAnnotations)(root);
139
- if (flags.json) {
140
- // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
141
- // @req REQ-MAINT-REPORT - JSON-friendly output for tooling integration
142
- console.log(JSON.stringify({ root, stale }));
143
- }
144
- else {
145
- if (stale.length === 0) {
146
- console.log("No stale @story annotations found.");
147
- }
148
- else {
149
- stale.forEach((story) => {
150
- console.log(story);
151
- });
152
- console.log(`Found ${stale.length} stale @story annotation${stale.length === 1 ? "" : "s"}.
153
- Run 'traceability-maint report' for a structured summary.`);
154
- }
155
- }
156
- return stale.length === 0 ? EXIT_OK : EXIT_STALE;
157
- }
158
- /**
159
- * Handle the `verify` subcommand to validate traceability annotations.
160
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
161
- * @req REQ-MAINT-VERIFY - CLI surface for verification of annotations
162
- * @req REQ-MAINT-SAFE - Return distinct exit codes for verification failures
163
- */
164
- function handleVerify(args) {
165
- const flags = parseFlags(args);
166
- const root = flags.root;
167
- const valid = (0, batch_1.verifyAnnotations)(root);
168
- if (valid) {
169
- console.log(`All traceability annotations under ${root} are valid.`);
170
- return EXIT_OK;
171
- }
172
- console.log(`Stale or invalid traceability annotations detected under ${root}.\nRun 'traceability-maint detect' or 'traceability-maint report' for details.`);
173
- return EXIT_STALE;
174
- }
175
- /**
176
- * Handle the `report` subcommand to generate a maintenance report.
177
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
178
- * @req REQ-MAINT-REPORT - CLI surface for human-readable maintenance reports
179
- * @req REQ-MAINT-SAFE - Support machine-readable formats for safe automation
180
- */
181
- function handleReport(args) {
182
- const flags = parseFlags(args);
183
- const root = flags.root;
184
- const format = flags.format ?? "text";
185
- const report = (0, report_1.generateMaintenanceReport)(root);
186
- if (format === "json") {
187
- console.log(JSON.stringify({ root, report }));
188
- }
189
- else {
190
- if (!report) {
191
- console.log("No stale @story annotations found. Nothing to report.");
192
- }
193
- else {
194
- console.log(`# Traceability Maintenance Report for ${root}`);
195
- console.log("");
196
- console.log("Stale story references:");
197
- console.log(report);
198
- }
199
- }
200
- return EXIT_OK;
201
- }
202
- /**
203
- * Handle the `update` subcommand to rewrite @story annotation references.
204
- * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
205
- * @req REQ-MAINT-UPDATE - CLI surface for updating annotation references
206
- * @req REQ-MAINT-SAFE - Provide dry-run mode and explicit parameter checks
207
- */
208
- function handleUpdate(args) {
209
- const flags = parseFlags(args);
210
- const root = flags.root;
211
- if (!flags.from || !flags.to) {
212
- console.error("'update' requires --from <oldPath> and --to <newPath>.");
213
- printHelp();
214
- return EXIT_USAGE;
215
- }
216
- const from = flags.from;
217
- const to = flags.to;
218
- if (flags.dryRun) {
219
- // For now, we cannot get a per-file diff without changing the maintenance API.
220
- // We conservatively reuse generateMaintenanceReport to indicate potential impact.
221
- const beforeReport = (0, report_1.generateMaintenanceReport)(root);
222
- const potentialChanges = beforeReport ? beforeReport.split("\n").length : 0;
223
- const summary = {
224
- root,
225
- from,
226
- to,
227
- estimatedStaleCount: potentialChanges,
228
- };
229
- if (flags.json) {
230
- console.log(JSON.stringify({ mode: "dry-run", ...summary }));
231
- }
232
- else {
233
- console.log("Dry run: no files were modified.");
234
- console.log(`Would update @story annotations from '${from}' to '${to}' under ${root}.`);
235
- console.log(`Estimated stale annotations before update: ${summary.estimatedStaleCount}.`);
236
- }
237
- return EXIT_OK;
238
- }
239
- const count = (0, update_1.updateAnnotationReferences)(root, from, to);
240
- if (flags.json) {
241
- console.log(JSON.stringify({ root, from, to, updated: count }));
242
- }
243
- else {
244
- console.log(`Updated ${count} @story annotation${count === 1 ? "" : "s"} from '${from}' to '${to}' under ${root}.`);
67
+ return commands_1.EXIT_USAGE;
245
68
  }
246
- return EXIT_OK;
247
69
  }
248
70
  /**
249
71
  * Print CLI usage help for the maintenance tools.
@@ -0,0 +1,32 @@
1
+ import { NormalizedCliArgs } from "./flags";
2
+ export declare const EXIT_OK = 0;
3
+ export declare const EXIT_STALE = 1;
4
+ export declare const EXIT_USAGE = 2;
5
+ /**
6
+ * Handle the `detect` subcommand for stale @story annotations.
7
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
8
+ * @req REQ-MAINT-DETECT - CLI surface for detection of stale annotations
9
+ * @req REQ-MAINT-SAFE - Return specific exit codes for stale vs clean states
10
+ */
11
+ export declare function handleDetect(normalized: NormalizedCliArgs): number;
12
+ /**
13
+ * Handle the `verify` subcommand to validate traceability annotations.
14
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
15
+ * @req REQ-MAINT-VERIFY - CLI surface for verification of annotations
16
+ * @req REQ-MAINT-SAFE - Return distinct exit codes for verification failures
17
+ */
18
+ export declare function handleVerify(normalized: NormalizedCliArgs): number;
19
+ /**
20
+ * Handle the `report` subcommand to generate a maintenance report.
21
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
22
+ * @req REQ-MAINT-REPORT - CLI surface for human-readable maintenance reports
23
+ * @req REQ-MAINT-SAFE - Support machine-readable formats for safe automation
24
+ */
25
+ export declare function handleReport(normalized: NormalizedCliArgs): number;
26
+ /**
27
+ * Handle the `update` subcommand to rewrite @story annotation references.
28
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
29
+ * @req REQ-MAINT-UPDATE - CLI surface for updating annotation references
30
+ * @req REQ-MAINT-SAFE - Provide dry-run mode and explicit parameter checks
31
+ */
32
+ export declare function handleUpdate(normalized: NormalizedCliArgs): number;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXIT_USAGE = exports.EXIT_STALE = exports.EXIT_OK = void 0;
4
+ exports.handleDetect = handleDetect;
5
+ exports.handleVerify = handleVerify;
6
+ exports.handleReport = handleReport;
7
+ exports.handleUpdate = handleUpdate;
8
+ /**
9
+ * Subcommand handlers for the traceability-maint CLI.
10
+ *
11
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
12
+ * @req REQ-MAINT-DETECT - CLI support for detection of stale annotations
13
+ * @req REQ-MAINT-VERIFY - CLI support for verification of annotations
14
+ * @req REQ-MAINT-REPORT - CLI support for human-readable reports
15
+ * @req REQ-MAINT-UPDATE - CLI support for updating annotation references
16
+ * @req REQ-MAINT-SAFE - Provide clear exit codes and avoid unsafe defaults
17
+ */
18
+ const detect_1 = require("./detect");
19
+ const batch_1 = require("./batch");
20
+ const update_1 = require("./update");
21
+ const report_1 = require("./report");
22
+ const flags_1 = require("./flags");
23
+ exports.EXIT_OK = 0;
24
+ exports.EXIT_STALE = 1;
25
+ exports.EXIT_USAGE = 2;
26
+ /**
27
+ * Handle the `detect` subcommand for stale @story annotations.
28
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
29
+ * @req REQ-MAINT-DETECT - CLI surface for detection of stale annotations
30
+ * @req REQ-MAINT-SAFE - Return specific exit codes for stale vs clean states
31
+ */
32
+ function handleDetect(normalized) {
33
+ const flags = (0, flags_1.parseFlags)(normalized);
34
+ const root = flags.root;
35
+ const stale = (0, detect_1.detectStaleAnnotations)(root);
36
+ if (flags.json) {
37
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
38
+ // @req REQ-MAINT-REPORT - JSON-friendly output for tooling integration
39
+ console.log(JSON.stringify({ root, stale }));
40
+ }
41
+ else if (stale.length === 0) {
42
+ console.log("No stale @story annotations found.");
43
+ }
44
+ else {
45
+ stale.forEach((story) => {
46
+ console.log(story);
47
+ });
48
+ console.log(`Found ${stale.length} stale @story annotation${stale.length === 1 ? "" : "s"}.
49
+ Run 'traceability-maint report' for a structured summary.`);
50
+ }
51
+ return stale.length === 0 ? exports.EXIT_OK : exports.EXIT_STALE;
52
+ }
53
+ /**
54
+ * Handle the `verify` subcommand to validate traceability annotations.
55
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
56
+ * @req REQ-MAINT-VERIFY - CLI surface for verification of annotations
57
+ * @req REQ-MAINT-SAFE - Return distinct exit codes for verification failures
58
+ */
59
+ function handleVerify(normalized) {
60
+ const flags = (0, flags_1.parseFlags)(normalized);
61
+ const root = flags.root;
62
+ const valid = (0, batch_1.verifyAnnotations)(root);
63
+ if (valid) {
64
+ console.log(`All traceability annotations under ${root} are valid.`);
65
+ return exports.EXIT_OK;
66
+ }
67
+ console.log(`Stale or invalid traceability annotations detected under ${root}.\nRun 'traceability-maint detect' or 'traceability-maint report' for details.`);
68
+ return exports.EXIT_STALE;
69
+ }
70
+ /**
71
+ * Handle the `report` subcommand to generate a maintenance report.
72
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
73
+ * @req REQ-MAINT-REPORT - CLI surface for human-readable maintenance reports
74
+ * @req REQ-MAINT-SAFE - Support machine-readable formats for safe automation
75
+ */
76
+ function handleReport(normalized) {
77
+ const flags = (0, flags_1.parseFlags)(normalized);
78
+ const root = flags.root;
79
+ const format = flags.format ?? "text";
80
+ const report = (0, report_1.generateMaintenanceReport)(root);
81
+ if (format === "json") {
82
+ console.log(JSON.stringify({ root, report }));
83
+ }
84
+ else if (!report) {
85
+ console.log("No stale @story annotations found. Nothing to report.");
86
+ }
87
+ else {
88
+ console.log(`# Traceability Maintenance Report for ${root}`);
89
+ console.log("");
90
+ console.log("Stale story references:");
91
+ console.log(report);
92
+ }
93
+ return exports.EXIT_OK;
94
+ }
95
+ /**
96
+ * Handle the `update` subcommand to rewrite @story annotation references.
97
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
98
+ * @req REQ-MAINT-UPDATE - CLI surface for updating annotation references
99
+ * @req REQ-MAINT-SAFE - Provide dry-run mode and explicit parameter checks
100
+ */
101
+ function handleUpdate(normalized) {
102
+ const flags = (0, flags_1.parseFlags)(normalized);
103
+ const root = flags.root;
104
+ if (!flags.from || !flags.to) {
105
+ console.error("'update' requires --from <oldPath> and --to <newPath>.");
106
+ return exports.EXIT_USAGE;
107
+ }
108
+ const from = flags.from;
109
+ const to = flags.to;
110
+ if (flags.dryRun) {
111
+ // For now, we cannot get a per-file diff without changing the maintenance API.
112
+ // We conservatively reuse generateMaintenanceReport to indicate potential impact.
113
+ const beforeReport = (0, report_1.generateMaintenanceReport)(root);
114
+ const potentialChanges = beforeReport ? beforeReport.split("\n").length : 0;
115
+ const summary = {
116
+ root,
117
+ from,
118
+ to,
119
+ estimatedStaleCount: potentialChanges,
120
+ };
121
+ if (flags.json) {
122
+ console.log(JSON.stringify({ mode: "dry-run", ...summary }));
123
+ }
124
+ else {
125
+ console.log("Dry run: no files were modified.");
126
+ console.log(`Would update @story annotations from '${from}' to '${to}' under ${root}.`);
127
+ console.log(`Estimated stale annotations before update: ${summary.estimatedStaleCount}.`);
128
+ }
129
+ return exports.EXIT_OK;
130
+ }
131
+ const count = (0, update_1.updateAnnotationReferences)(root, from, to);
132
+ if (flags.json) {
133
+ console.log(JSON.stringify({ root, from, to, updated: count }));
134
+ }
135
+ else {
136
+ console.log(`Updated ${count} @story annotation${count === 1 ? "" : "s"} from '${from}' to '${to}' under ${root}.`);
137
+ }
138
+ return exports.EXIT_OK;
139
+ }
@@ -2,5 +2,7 @@
2
2
  * Detect stale annotation references that point to moved or deleted story files
3
3
  * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
4
4
  * @req REQ-MAINT-DETECT - Detect stale annotation references
5
+ * @param codebasePath Path to the codebase root, treated as a workspace root and resolved against process.cwd().
6
+ * @returns A de-duplicated array of stale @story paths (as strings) whose resolved targets no longer exist on disk.
5
7
  */
6
8
  export declare function detectStaleAnnotations(codebasePath: string): string[];
@@ -42,6 +42,8 @@ const storyReferenceUtils_1 = require("../utils/storyReferenceUtils");
42
42
  * Detect stale annotation references that point to moved or deleted story files
43
43
  * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
44
44
  * @req REQ-MAINT-DETECT - Detect stale annotation references
45
+ * @param codebasePath Path to the codebase root, treated as a workspace root and resolved against process.cwd().
46
+ * @returns A de-duplicated array of stale @story paths (as strings) whose resolved targets no longer exist on disk.
45
47
  */
46
48
  function detectStaleAnnotations(codebasePath) {
47
49
  const cwd = process.cwd();
@@ -58,6 +60,8 @@ function detectStaleAnnotations(codebasePath) {
58
60
  // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
59
61
  // @req REQ-MAINT-DETECT - Iterate over all files in the isolated workspace root
60
62
  const files = (0, utils_1.getAllFiles)(workspaceRoot);
63
+ // @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
64
+ // @req REQ-MAINT-DETECT - Loop over each workspace file to inspect its @story annotations
61
65
  for (const file of files) {
62
66
  processFileForStaleAnnotations(file, workspaceRoot, cwd, stale);
63
67
  }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Parsed representation of raw CLI input (argv) for the maintenance tools.
3
+ *
4
+ * Separates Node/V8 internals from the actual subcommand and its arguments.
5
+ *
6
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
7
+ * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
8
+ */
9
+ export interface ParsedCliInput {
10
+ /**
11
+ * The raw argv as passed to the Node.js process (e.g., process.argv).
12
+ */
13
+ readonly argv: string[];
14
+ /**
15
+ * The Node.js executable path (argv[0]).
16
+ */
17
+ readonly node: string;
18
+ /**
19
+ * The executed script path (argv[1]).
20
+ */
21
+ readonly script: string;
22
+ /**
23
+ * The maintenance subcommand being invoked (first argument after script).
24
+ */
25
+ readonly subcommand: string | undefined;
26
+ /**
27
+ * Remaining arguments after the subcommand, to be interpreted as flags
28
+ * or positional arguments for that subcommand.
29
+ */
30
+ readonly args: string[];
31
+ }
32
+ /**
33
+ * Parse raw Node.js argv into a structured CLI input for the maintenance tools.
34
+ *
35
+ * This performs only minimal, predictable splitting to support higher-level
36
+ * flag parsing in a safe and testable way.
37
+ *
38
+ * @param argv - Raw argv array, usually process.argv.
39
+ * @returns ParsedCliInput with node, script, subcommand, and remaining args.
40
+ *
41
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
42
+ * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
43
+ */
44
+ export declare function parseCliInput(argv: string[]): ParsedCliInput;
45
+ /**
46
+ * Normalized view of CLI arguments relevant to a maintenance subcommand.
47
+ *
48
+ * This strips away Node/V8 internals and script paths, exposing only the
49
+ * subcommand name and its raw arguments for further flag parsing.
50
+ *
51
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
52
+ * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
53
+ */
54
+ export interface NormalizedCliArgs {
55
+ /**
56
+ * The maintenance subcommand being invoked (first argument after script).
57
+ */
58
+ readonly subcommand: string | undefined;
59
+ /**
60
+ * Remaining arguments after the subcommand, to be interpreted as flags
61
+ * or positional arguments for that subcommand.
62
+ */
63
+ readonly args: string[];
64
+ }
65
+ /**
66
+ * Normalize raw argv into a subcommand-centric view for flag parsing.
67
+ *
68
+ * Uses parseCliInput to safely separate Node/V8 internals from the
69
+ * subcommand and its arguments, then exposes only the pieces relevant
70
+ * to subcommand-specific flag parsing.
71
+ *
72
+ * @param rawArgv - Raw argv array, usually process.argv.
73
+ * @returns NormalizedCliArgs with subcommand and remaining args.
74
+ *
75
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
76
+ * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
77
+ */
78
+ export declare function normalizeCliArgs(rawArgv: string[]): NormalizedCliArgs;
79
+ export interface ParsedFlags {
80
+ root: string;
81
+ json: boolean;
82
+ format?: "text" | "json";
83
+ from?: string;
84
+ to?: string;
85
+ dryRun?: boolean;
86
+ }
87
+ /**
88
+ * Basic flag parser for maintenance CLI subcommands.
89
+ *
90
+ * Consumes already-normalized CLI arguments (subcommand and its raw args)
91
+ * and produces a ParsedFlags structure with minimal, predictable behavior.
92
+ *
93
+ * @param normalized - Normalized CLI arguments for a maintenance subcommand.
94
+ * @returns ParsedFlags with defaults applied and any recognized flags set.
95
+ *
96
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
97
+ * @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
98
+ */
99
+ export declare function parseFlags(normalized: NormalizedCliArgs): ParsedFlags;