@aisdlc/cli 4.3.1 → 4.5.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.
package/dist/index.js CHANGED
@@ -5,10 +5,13 @@ import { Command } from "commander";
5
5
  import pc12 from "picocolors";
6
6
 
7
7
  // src/commands/check.ts
8
+ import * as fs from "fs";
9
+ import * as path2 from "path";
8
10
  import pc2 from "picocolors";
9
11
  import {
10
12
  checkGherkinInSync as checkGherkinInSync2,
11
13
  extractGherkinFeatures,
14
+ scaffoldGherkinSteps,
12
15
  syncPdacDigests,
13
16
  verifyArtifactDuplicates as verifyArtifactDuplicates2,
14
17
  verifyArtifactsSchemas as verifyArtifactsSchemas2,
@@ -100,8 +103,14 @@ function buildQualityViolations(result) {
100
103
  metric: "unit-test",
101
104
  message: `Function [${u.functionName}] lacks direct unit test`
102
105
  }));
106
+ const untestedUi = (result.untestedUiComponents || []).map((c) => ({
107
+ file: c.file,
108
+ component: c.componentName,
109
+ metric: "ui-test",
110
+ message: `UI component [${c.componentName}] lacks UI/E2E test`
111
+ }));
103
112
  const cov = (result.coverageViolations || []).map((message) => ({ metric: "coverage", message }));
104
- return [...fnViolations, ...untested, ...cov];
113
+ return [...fnViolations, ...untested, ...untestedUi, ...cov];
105
114
  }
106
115
  function emitQualityJson(result) {
107
116
  const violations = buildQualityViolations(result);
@@ -115,6 +124,7 @@ function emitQualityJson(result) {
115
124
  passCount: result.passCount,
116
125
  failCount: result.failCount,
117
126
  untestedFunctionsCount: result.untestedFunctions?.length || 0,
127
+ untestedUiComponentsCount: result.untestedUiComponents?.length || 0,
118
128
  coverageViolationsCount: result.coverageViolations?.length || 0,
119
129
  baselineViolationsCount: result.baselineViolationsCount || 0,
120
130
  toleratedViolationsCount: result.toleratedViolationsCount || 0,
@@ -145,6 +155,13 @@ function printQualityTestAndCoverageGaps(result) {
145
155
  console.log(` ${pc.red("\u2716")} ${pc.bold(u.file)} [${u.functionName}]`);
146
156
  }
147
157
  }
158
+ const untestedUi = result.untestedUiComponents || [];
159
+ if (untestedUi.length > 0) {
160
+ console.log(pc.red("\n UI components lacking UI/E2E tests:"));
161
+ for (const c of untestedUi.slice(0, 15)) {
162
+ console.log(` ${pc.red("\u2716")} ${pc.bold(c.file)} [${c.componentName}]`);
163
+ }
164
+ }
148
165
  for (const cv of result.coverageViolations || []) {
149
166
  console.log(` ${pc.red("\u2716")} ${cv}`);
150
167
  }
@@ -1037,19 +1054,23 @@ async function runVerifySecurityAsync(options = {}) {
1037
1054
  const isOk = resultSecrets.success && resultSast.success && !hasExpired;
1038
1055
  return handleSecurityOutput(options, resultSecrets, resultSast, isOk, hasExpired);
1039
1056
  }
1040
- function emitGherkinVerifyJson(result) {
1041
- const violations = [
1042
- ...result.missingFiles.map((f) => ({
1043
- type: "MISSING_FEATURE",
1044
- file: f,
1045
- message: `Missing .feature file: ${f}`
1046
- })),
1047
- ...result.outOfSyncFiles.map((f) => ({
1048
- type: "OUT_OF_SYNC_FEATURE",
1057
+ function buildGherkinViolations(result) {
1058
+ const orphans = result.orphanFeatureFiles ?? [];
1059
+ const missingSteps = result.missingStepFiles ?? [];
1060
+ return [
1061
+ ...result.missingFiles.map((f) => ({ type: "MISSING_FEATURE", file: f, message: `Missing .feature file: ${f}` })),
1062
+ ...result.outOfSyncFiles.map((f) => ({ type: "OUT_OF_SYNC_FEATURE", file: f, message: `Out-of-sync .feature file: ${f}` })),
1063
+ ...orphans.map((f) => ({ type: "ORPHAN_FEATURE", file: f, message: `Manual/orphan .feature file without Markdown source: ${f}` })),
1064
+ ...missingSteps.map((f) => ({
1065
+ type: "MISSING_STEP_FILE",
1049
1066
  file: f,
1050
- message: `Out-of-sync .feature file: ${f}`
1067
+ message: `Missing deterministic step definition file in tests/steps/ for: ${f}. Run 'aisdlc gherkin scaffold ${f} --lang <lang> --fallback'.`
1051
1068
  }))
1052
1069
  ];
1070
+ }
1071
+ function emitGherkinVerifyJson(result) {
1072
+ const orphans = result.orphanFeatureFiles ?? [];
1073
+ const missingSteps = result.missingStepFiles ?? [];
1053
1074
  const payload = {
1054
1075
  gate: "gherkin",
1055
1076
  success: result.inSync,
@@ -1057,22 +1078,30 @@ function emitGherkinVerifyJson(result) {
1057
1078
  summary: {
1058
1079
  totalFeatures: result.totalFeatures,
1059
1080
  missingCount: result.missingFiles.length,
1060
- outOfSyncCount: result.outOfSyncFiles.length
1081
+ outOfSyncCount: result.outOfSyncFiles.length,
1082
+ orphanFeatureCount: orphans.length,
1083
+ missingStepFileCount: missingSteps.length
1061
1084
  },
1062
- violations
1085
+ violations: buildGherkinViolations(result)
1063
1086
  };
1064
1087
  console.log(JSON.stringify(payload, null, 2));
1065
1088
  }
1089
+ function printGherkinIssueList(items, tag, suffix = "") {
1090
+ for (const f of items) {
1091
+ const extra = suffix ? suffix.replace("{file}", f) : "";
1092
+ console.log(` ${pc.red("\u2716")} [${tag}] ${f}${extra}`);
1093
+ }
1094
+ }
1066
1095
  function printGherkinVerifyConsole(result) {
1067
- const totalOut = result.missingFiles.length + result.outOfSyncFiles.length;
1096
+ const orphans = result.orphanFeatureFiles ?? [];
1097
+ const missingSteps = result.missingStepFiles ?? [];
1098
+ const totalOut = result.missingFiles.length + result.outOfSyncFiles.length + orphans.length + missingSteps.length;
1068
1099
  console.log(` Evaluated features: ${pc.bold(String(result.totalFeatures))}`);
1069
- console.log(` Out-of-sync / missing: ${totalOut > 0 ? pc.red(String(totalOut)) : pc.green("0")}`);
1070
- for (const f of result.missingFiles) {
1071
- console.log(` ${pc.red("\u2716")} [MISSING] ${f}`);
1072
- }
1073
- for (const f of result.outOfSyncFiles) {
1074
- console.log(` ${pc.red("\u2716")} [OUT_OF_SYNC] ${f}`);
1075
- }
1100
+ console.log(` Violations / missing: ${totalOut > 0 ? pc.red(String(totalOut)) : pc.green("0")}`);
1101
+ printGherkinIssueList(result.missingFiles, "MISSING");
1102
+ printGherkinIssueList(result.outOfSyncFiles, "OUT_OF_SYNC");
1103
+ printGherkinIssueList(orphans, "ORPHAN_FEATURE");
1104
+ printGherkinIssueList(missingSteps, "MISSING_STEP_FILE", " (run: aisdlc gherkin scaffold {file} --lang <lang> --fallback)");
1076
1105
  console.log(result.inSync ? pc.green("\n\u2714 BDD Synchronization COMPLIANT\n") : pc.red("\n\u2716 BDD Synchronization BLOCKED\n"));
1077
1106
  }
1078
1107
  function runVerifyGherkin(options = {}) {
@@ -1252,41 +1281,63 @@ async function runVerifyAllAsync(options = {}) {
1252
1281
  }
1253
1282
 
1254
1283
  // src/commands/check.ts
1284
+ function detectDefaultScaffoldLanguage(rootDir) {
1285
+ if (fs.existsSync(path2.join(rootDir, "pyproject.toml")) || fs.existsSync(path2.join(rootDir, "requirements.txt"))) return "py";
1286
+ if (fs.existsSync(path2.join(rootDir, "go.mod"))) return "go";
1287
+ if (fs.existsSync(path2.join(rootDir, "Cargo.toml"))) return "rs";
1288
+ return "ts";
1289
+ }
1290
+ function autoScaffoldMissingSteps(rootDir) {
1291
+ const sync = checkGherkinInSync2({ rootDir });
1292
+ const missing = sync.missingStepFiles ?? [];
1293
+ if (missing.length === 0) return 0;
1294
+ const lang = detectDefaultScaffoldLanguage(rootDir);
1295
+ let count = 0;
1296
+ for (const fp of missing) {
1297
+ if (scaffoldGherkinSteps({ rootDir, featurePath: fp, lang, allowFallback: true }).success) {
1298
+ count++;
1299
+ }
1300
+ }
1301
+ return count;
1302
+ }
1255
1303
  function runAutoFix(rootDir, silent) {
1256
1304
  const gherkinRes = extractGherkinFeatures({ rootDir });
1305
+ const scaffoldedCount = autoScaffoldMissingSteps(rootDir);
1257
1306
  const pdacRes = syncPdacDigests({ rootDir });
1258
1307
  if (!silent) {
1259
1308
  if (gherkinRes.features.length > 0) {
1260
1309
  console.log(` ${pc2.cyan("\u{1F527} [AUTO-FIX]")} Synchronized ${pc2.bold(String(gherkinRes.features.length))} .feature files (${gherkinRes.totalScenarios} scenarios).`);
1261
1310
  }
1311
+ if (scaffoldedCount > 0) {
1312
+ console.log(` ${pc2.cyan("\u{1F527} [AUTO-FIX]")} Scaffolded ${pc2.bold(String(scaffoldedCount))} deterministic step files in tests/steps/.`);
1313
+ }
1262
1314
  if (pdacRes.syncedCount > 0) {
1263
1315
  console.log(` ${pc2.cyan("\u{1F527} [AUTO-FIX]")} Synchronized ${pc2.bold(String(pdacRes.syncedCount))} SHA-256 digests across ${pdacRes.updatedFiles.length} files.`);
1264
1316
  }
1265
1317
  }
1266
1318
  return { gherkinCount: gherkinRes.features.length, digestsCount: pdacRes.syncedCount };
1267
1319
  }
1320
+ function buildGherkinFailedGate(totalOut, hasMissingSteps) {
1321
+ const remediation = hasMissingSteps ? "Run 'aisdlc gherkin scaffold <feature-file> --lang <lang> --fallback' to generate step definitions in tests/steps/." : "Run 'aisdlc check --fix' to extract and regenerate .feature files, and remove orphan manual .feature files.";
1322
+ return {
1323
+ name: "BDD Synchronization (Gherkin -> .feature & steps)",
1324
+ status: "FAILED",
1325
+ message: `${totalOut} Gherkin sync/step-scaffold violation(s) detected`,
1326
+ remediation
1327
+ };
1328
+ }
1268
1329
  function auditGherkinGate(rootDir, wasAutoFixed) {
1269
1330
  const syncCheck = checkGherkinInSync2({ rootDir });
1270
- if (wasAutoFixed) {
1271
- return {
1272
- name: "BDD Synchronization (Gherkin -> .feature)",
1273
- status: "FIXED",
1274
- message: `${syncCheck.totalFeatures} specifications automatically synchronized`
1275
- };
1276
- }
1331
+ const orphans = syncCheck.orphanFeatureFiles ?? [];
1332
+ const missingSteps = syncCheck.missingStepFiles ?? [];
1277
1333
  if (!syncCheck.inSync) {
1278
- const totalOut = syncCheck.missingFiles.length + syncCheck.outOfSyncFiles.length;
1279
- return {
1280
- name: "BDD Synchronization (Gherkin -> .feature)",
1281
- status: "FAILED",
1282
- message: `${totalOut} out-of-sync or missing .feature file(s)`,
1283
- remediation: "Run 'aisdlc check --fix' to extract and regenerate .feature files."
1284
- };
1334
+ const totalOut = syncCheck.missingFiles.length + syncCheck.outOfSyncFiles.length + orphans.length + missingSteps.length;
1335
+ return buildGherkinFailedGate(totalOut, missingSteps.length > 0);
1285
1336
  }
1286
1337
  return {
1287
- name: "BDD Synchronization (Gherkin -> .feature)",
1288
- status: "PASSED",
1289
- message: `${syncCheck.totalFeatures} specifications up to date on disk`
1338
+ name: "BDD Synchronization (Gherkin -> .feature & steps)",
1339
+ status: wasAutoFixed ? "FIXED" : "PASSED",
1340
+ message: wasAutoFixed ? `${syncCheck.totalFeatures} specifications automatically synchronized` : `${syncCheck.totalFeatures} specifications and step scaffolds up to date on disk`
1290
1341
  };
1291
1342
  }
1292
1343
  function auditPdacGate(rootDir, wasAutoFixed) {
@@ -1598,7 +1649,7 @@ import * as readline2 from "readline";
1598
1649
  import pc3 from "picocolors";
1599
1650
  import {
1600
1651
  extractGherkinFeatures as extractGherkinFeatures2,
1601
- scaffoldGherkinSteps
1652
+ scaffoldGherkinSteps as scaffoldGherkinSteps2
1602
1653
  } from "@aisdlc/core";
1603
1654
  function printGherkinResult(result) {
1604
1655
  console.log(` Generated .feature files: ${pc3.bold(String(result.features.length))}`);
@@ -1675,7 +1726,7 @@ async function handleInteractiveMissing(initialResult, featurePath, options, roo
1675
1726
  const confirmed = await ask(
1676
1727
  `Native BDD generator is not installed (${initialResult.installCommand}, license: ${initialResult.license}). Install now? [y/N]: `
1677
1728
  );
1678
- return scaffoldGherkinSteps({
1729
+ return scaffoldGherkinSteps2({
1679
1730
  rootDir,
1680
1731
  featurePath,
1681
1732
  lang: options.lang,
@@ -1696,7 +1747,7 @@ async function runGherkinScaffold(featurePath, options) {
1696
1747
  const rootDir = options.root || process.cwd();
1697
1748
  const useJson = isJsonOutput(options);
1698
1749
  const isInteractive = Boolean(process.stdin.isTTY && process.stdout.isTTY && !useJson && !options.silent);
1699
- let result = scaffoldGherkinSteps({
1750
+ let result = scaffoldGherkinSteps2({
1700
1751
  rootDir,
1701
1752
  featurePath,
1702
1753
  lang: options.lang,
@@ -2038,7 +2089,7 @@ function runInit(targetDir = ".", options = {}) {
2038
2089
  }
2039
2090
 
2040
2091
  // src/commands/kpi.ts
2041
- import * as fs from "fs";
2092
+ import * as fs2 from "fs";
2042
2093
  import pc6 from "picocolors";
2043
2094
  import {
2044
2095
  aggregatePrKpis,
@@ -2050,15 +2101,15 @@ import {
2050
2101
  } from "@aisdlc/core";
2051
2102
  function applyKpiPrOutput(options, markdown) {
2052
2103
  if (options.updateFile) {
2053
- if (!fs.existsSync(options.updateFile)) {
2104
+ if (!fs2.existsSync(options.updateFile)) {
2054
2105
  console.error(pc6.red(`
2055
2106
  \u2716 [ERROR] Target file '${options.updateFile}' does not exist.
2056
2107
  `));
2057
2108
  return false;
2058
2109
  }
2059
- const original = fs.readFileSync(options.updateFile, "utf-8");
2110
+ const original = fs2.readFileSync(options.updateFile, "utf-8");
2060
2111
  const updated = injectKpisIntoPrBody(original, markdown);
2061
- fs.writeFileSync(options.updateFile, updated, "utf-8");
2112
+ fs2.writeFileSync(options.updateFile, updated, "utf-8");
2062
2113
  console.log(pc6.green(`\u2714 [UPDATED] KPI summary injected into '${options.updateFile}'.`));
2063
2114
  } else {
2064
2115
  console.log("\n" + markdown + "\n");
@@ -2154,7 +2205,7 @@ async function runMcpServer(options = {}) {
2154
2205
  }
2155
2206
 
2156
2207
  // src/commands/report.ts
2157
- import * as path2 from "path";
2208
+ import * as path3 from "path";
2158
2209
  import { spawn } from "child_process";
2159
2210
  import pc8 from "picocolors";
2160
2211
  import {
@@ -2163,7 +2214,7 @@ import {
2163
2214
  generateQualityReport
2164
2215
  } from "@aisdlc/core";
2165
2216
  function openInBrowser(filePath) {
2166
- const resolved = path2.resolve(filePath);
2217
+ const resolved = path3.resolve(filePath);
2167
2218
  const platform = process.platform;
2168
2219
  try {
2169
2220
  if (platform === "win32") {
@@ -2184,7 +2235,7 @@ function printDashboardMetrics(result, rootDir) {
2184
2235
  console.log(` Global traceability: ${pc8.green(String(result.metrics.traceabilityRatio) + "%")}`);
2185
2236
  console.log(` Maintainability: ${pc8.bold(String(result.metrics.avgMaintainability) + " / 100")}`);
2186
2237
  console.log(` Gate verdict: ${result.metrics.qualityVerdict === "PASS" ? pc8.green("PASS") : pc8.red("FAIL")}`);
2187
- const relPath = path2.relative(rootDir, result.outputPath);
2238
+ const relPath = path3.relative(rootDir, result.outputPath);
2188
2239
  console.log(pc8.green(`
2189
2240
  \u2714 Self-contained HTML dashboard successfully generated at: ${pc8.bold(relPath)}
2190
2241
  `));
@@ -2223,7 +2274,7 @@ function printQualityReportMetrics(result, rootDir) {
2223
2274
  ` Code coverage (L/B/F): ${result.coverage ? pc8.bold(`${result.coverage.linesPct}% / ${result.coverage.branchesPct}% / ${result.coverage.functionsPct}%`) : pc8.dim("N/A (Run test:coverage)")}`
2224
2275
  );
2225
2276
  console.log(` Release Gate verdict: ${result.verdict === "PASS" ? pc8.green("PASS") : pc8.red("FAIL")}`);
2226
- const reportRelPath = path2.relative(rootDir, path2.join(rootDir, "reports", "QUALITY_REPORT.md"));
2277
+ const reportRelPath = path3.relative(rootDir, path3.join(rootDir, "reports", "QUALITY_REPORT.md"));
2227
2278
  console.log(pc8.green(`
2228
2279
  \u2714 Report successfully generated at: ${pc8.bold(reportRelPath)}
2229
2280
  `));
@@ -2385,7 +2436,7 @@ async function runDoctor(opts = {}) {
2385
2436
  }
2386
2437
 
2387
2438
  // src/commands/migrate.ts
2388
- import * as path3 from "path";
2439
+ import * as path4 from "path";
2389
2440
  import pc10 from "picocolors";
2390
2441
  import {
2391
2442
  MigrationService,
@@ -2402,7 +2453,7 @@ function printConsoleSummary(result, reporter) {
2402
2453
  }
2403
2454
  }
2404
2455
  async function runMigrate(options) {
2405
- const root = path3.resolve(options.root || process.cwd());
2456
+ const root = path4.resolve(options.root || process.cwd());
2406
2457
  const service = new MigrationService();
2407
2458
  const reporter = new MigrationReporter();
2408
2459
  const migrationOptions = {
@@ -2425,7 +2476,7 @@ async function runMigrate(options) {
2425
2476
  }
2426
2477
 
2427
2478
  // src/commands/sdd.ts
2428
- import * as path4 from "path";
2479
+ import * as path5 from "path";
2429
2480
  import pc11 from "picocolors";
2430
2481
  import {
2431
2482
  depositProductHandoffSidecar,
@@ -2508,7 +2559,7 @@ function printHandoffEntry(isValid, id, relDir, reqCount) {
2508
2559
  }
2509
2560
  }
2510
2561
  function processHandoffEntry(handoff, changeDir, rootDir, isSilent) {
2511
- const relDir = path4.relative(rootDir, changeDir).replace(/\\/g, "/");
2562
+ const relDir = path5.relative(rootDir, changeDir).replace(/\\/g, "/");
2512
2563
  const reqCount = handoff.subgraph && Array.isArray(handoff.subgraph.requirements) ? handoff.subgraph.requirements.length : 0;
2513
2564
  const isValid = Boolean(handoff.id && handoff.id.startsWith("HOF-") && reqCount > 0);
2514
2565
  const id = handoff.id || "UNKNOWN";
@@ -2824,7 +2875,7 @@ function runChangeNew(options) {
2824
2875
 
2825
2876
  // src/index.ts
2826
2877
  var program = new Command();
2827
- program.name("aisdlc").description("AI-SDLC: Spec-Driven Development, Governance & Quality Gates for AI & Humans").version("4.3.1");
2878
+ program.name("aisdlc").description("AI-SDLC: Spec-Driven Development, Governance & Quality Gates for AI & Humans").version("4.5.0");
2828
2879
  program.command("doctor").description("Comprehensive environment, toolchain, git-hooks, and security health diagnostics").option("-r, --root <path>", "Project root directory").option("--fix", "Automatically repair broken or missing git hooks with backup").option("--json", "Emit diagnostics report in structured JSON format").option("--strict", "Fail with non-zero exit code on warnings as well as critical failures").option("--offline", "Skip remote external network probes (e.g. for air-gapped environments)").option("--timeout <ms>", "Maximum timeout in milliseconds for subprocess execution", parseInt).action(async (opts) => {
2829
2880
  const exitCode = await runDoctor({
2830
2881
  rootDir: opts.root,