@aisdlc/cli 2.4.0 → 2.5.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.
package/dist/index.js CHANGED
@@ -26,9 +26,9 @@ import {
26
26
 
27
27
  // src/commands/verify.ts
28
28
  import pc from "picocolors";
29
- import * as fs from "fs";
30
29
  import * as path from "path";
31
30
  import {
31
+ writeReportFileIfChanged,
32
32
  checkGherkinInSync,
33
33
  verifyArtifactDuplicates,
34
34
  verifyArtifactsSchemas,
@@ -482,6 +482,29 @@ function runVerifyLicenses(options = {}) {
482
482
  }
483
483
  return result.success;
484
484
  }
485
+ function buildPdacViolations(result) {
486
+ const drifts = result.drifts.map((d) => ({
487
+ sourceId: d.sourceId,
488
+ targetId: d.targetId,
489
+ sourceFile: d.sourceFile,
490
+ expectedDigest: d.expectedDigest,
491
+ actualDigest: d.actualDigest,
492
+ message: `Cryptographic drift in ${d.sourceFile} citing ${d.targetId}`
493
+ }));
494
+ const unresolved = (result.unresolvedCitations || []).map((u) => ({
495
+ sourceId: u.sourceFile,
496
+ targetId: u.targetId,
497
+ sourceFile: u.sourceFile,
498
+ message: `Unresolved citation in ${u.sourceFile} citing non-existent artifact '${u.targetId}'`
499
+ }));
500
+ const anchors = (result.invalidAnchors || []).map((a) => ({
501
+ sourceId: a.sourceFile,
502
+ targetId: a.targetId,
503
+ sourceFile: a.sourceFile,
504
+ message: a.reason
505
+ }));
506
+ return [...drifts, ...unresolved, ...anchors];
507
+ }
485
508
  function emitPdacJson(result) {
486
509
  const payload = {
487
510
  gate: "pdac",
@@ -490,30 +513,49 @@ function emitPdacJson(result) {
490
513
  summary: {
491
514
  totalNodes: result.totalNodes,
492
515
  totalEdges: result.totalEdges,
493
- driftCount: result.drifts.length
516
+ driftCount: result.drifts.length,
517
+ unresolvedCount: result.unresolvedCount || 0,
518
+ invalidAnchorCount: result.invalidAnchors?.length || 0
494
519
  },
495
- violations: result.drifts.map((d) => ({
496
- sourceId: d.sourceId,
497
- targetId: d.targetId,
498
- sourceFile: d.sourceFile,
499
- expectedDigest: d.expectedDigest,
500
- actualDigest: d.actualDigest,
501
- message: `Cryptographic drift in ${d.sourceFile} citing ${d.targetId}`
502
- }))
520
+ violations: buildPdacViolations(result)
503
521
  };
504
522
  console.log(JSON.stringify(payload, null, 2));
505
523
  }
524
+ function printDrifts(drifts) {
525
+ if (drifts.length === 0) return;
526
+ console.log(pc.red("\n Detected drifts (Status: STALE):"));
527
+ for (const d of drifts) {
528
+ console.log(` ${pc.red("\u2716")} In ${d.sourceFile} citing ${d.targetId}: misaligned digest.`);
529
+ }
530
+ }
531
+ function printUnresolved(unresolved) {
532
+ if (!unresolved || unresolved.length === 0) return;
533
+ console.log(pc.red("\n Unresolved citations:"));
534
+ for (const u of unresolved) {
535
+ console.log(` ${pc.red("\u2716")} In ${u.sourceFile}: references non-existent artifact '${u.targetId}'.`);
536
+ }
537
+ }
538
+ function printInvalidAnchors(anchors) {
539
+ if (!anchors || anchors.length === 0) return;
540
+ console.log(pc.red("\n Invalid anchors:"));
541
+ for (const a of anchors) {
542
+ console.log(` ${pc.red("\u2716")} In ${a.sourceFile}: ${a.reason}`);
543
+ }
544
+ }
506
545
  function printPdacConsole(result) {
507
546
  console.log(` PDaC baseline nodes: ${pc.bold(String(result.totalNodes))}`);
508
547
  console.log(` Evaluated citations: ${pc.bold(String(result.totalEdges))}`);
509
548
  console.log(` Cryptographic drifts: ${result.drifts.length > 0 ? pc.red(String(result.drifts.length)) : pc.green("0")}`);
510
- if (result.drifts.length > 0) {
511
- console.log(pc.red("\n Detected drifts (Status: STALE):"));
512
- for (const d of result.drifts) {
513
- console.log(` ${pc.red("\u2716")} In ${d.sourceFile} citing ${d.targetId}: misaligned digest.`);
514
- }
549
+ if (result.unresolvedCount && result.unresolvedCount > 0) {
550
+ console.log(` Unresolved citations: ${pc.red(String(result.unresolvedCount))}`);
551
+ }
552
+ if (result.invalidAnchors && result.invalidAnchors.length > 0) {
553
+ console.log(` Invalid anchors: ${pc.red(String(result.invalidAnchors.length))}`);
515
554
  }
516
- console.log(result.success ? pc.green("\n\u2714 PDaC Graph Free of Drift\n") : pc.red("\n\u2716 Cryptographic Drift Detected\n"));
555
+ printDrifts(result.drifts);
556
+ printUnresolved(result.unresolvedCitations);
557
+ printInvalidAnchors(result.invalidAnchors);
558
+ console.log(result.success ? pc.green("\n\u2714 PDaC Graph Free of Drift and Fully Verified\n") : pc.red("\n\u2716 PDaC Verification Failed (Drift, Unresolved Citations, or Invalid Anchors)\n"));
517
559
  }
518
560
  function runVerifyPdac(options = {}) {
519
561
  const rootDir = options.root || process.cwd();
@@ -871,15 +913,8 @@ function emitSecurityJson(resultSecrets, resultSast, isOk) {
871
913
  console.log(JSON.stringify(payload, null, 2));
872
914
  }
873
915
  function writeSuppressionsAuditReport(rootDir, suppressions) {
874
- const reportsDir = path.join(rootDir, "reports");
875
- if (!fs.existsSync(reportsDir)) {
876
- fs.mkdirSync(reportsDir, { recursive: true });
877
- }
878
- fs.writeFileSync(
879
- path.join(reportsDir, "SUPPRESSIONS_AUDIT.md"),
880
- generateSuppressionsAuditReport(suppressions),
881
- "utf-8"
882
- );
916
+ const targetPath = path.join(rootDir, "reports", "SUPPRESSIONS_AUDIT.md");
917
+ writeReportFileIfChanged(targetPath, generateSuppressionsAuditReport(suppressions));
883
918
  }
884
919
  function executeSecurityVerifiers(rootDir, options) {
885
920
  const entropyThreshold = options.entropy !== void 0 ? Number(options.entropy) : void 0;
@@ -1760,6 +1795,7 @@ function emitInitJson(result, isSuccess, dryRun) {
1760
1795
  targetDir: result.targetDir,
1761
1796
  directoriesCreated: result.directoriesCreated,
1762
1797
  filesCreated: result.filesCreated,
1798
+ filesUpdated: result.filesUpdated || [],
1763
1799
  ciProvider: result.ciProvider,
1764
1800
  agentsConfigured: result.agentsConfigured,
1765
1801
  architectureGranularity: result.architectureGranularity,
@@ -1786,8 +1822,11 @@ function printGitHookStatus(dryRun, installed) {
1786
1822
  }
1787
1823
  function printCreatedItems(items, type, dryRun) {
1788
1824
  const isDir = type === "directory";
1825
+ const isUpdated = type === "updated-file";
1789
1826
  for (const item of items) {
1790
- const prefix = dryRun ? pc5.blue("DRY-RUN") + ` ${isDir ? "Create directory:" : "Create file:"}` : pc5.green("\u2714") + ` ${isDir ? "Directory created:" : "File generated:"}`;
1827
+ const actionLabel = isDir ? "Create directory:" : isUpdated ? "Update file:" : "Create file:";
1828
+ const doneLabel = isDir ? "Directory created:" : isUpdated ? "File updated:" : "File generated:";
1829
+ const prefix = dryRun ? pc5.blue("DRY-RUN") + ` ${actionLabel}` : pc5.green("\u2714") + ` ${doneLabel}`;
1791
1830
  console.log(` ${prefix} ${item}`);
1792
1831
  }
1793
1832
  }
@@ -1797,6 +1836,9 @@ function printInitSuccess(result, dryRun) {
1797
1836
  `)));
1798
1837
  printCreatedItems(result.directoriesCreated, "directory", dryRun);
1799
1838
  printCreatedItems(result.filesCreated, "file", dryRun);
1839
+ if (result.filesUpdated && result.filesUpdated.length > 0) {
1840
+ printCreatedItems(result.filesUpdated, "updated-file", dryRun);
1841
+ }
1800
1842
  if (result.ciProvider) {
1801
1843
  console.log(pc5.cyan(`
1802
1844
  \u2714 CI/CD configuration generated for provider: ${pc5.bold(result.ciProvider)}`));
@@ -1842,13 +1884,14 @@ function runInit(targetDir = ".", options = {}) {
1842
1884
  ci: options.ci,
1843
1885
  agents: options.agents === "none" ? false : options.agents,
1844
1886
  architecture: options.architecture,
1845
- dryRun
1887
+ dryRun,
1888
+ force: Boolean(options.force)
1846
1889
  });
1847
1890
  return handleInitResult(result, { isSilent, useJson, dryRun });
1848
1891
  }
1849
1892
 
1850
1893
  // src/commands/kpi.ts
1851
- import * as fs2 from "fs";
1894
+ import * as fs from "fs";
1852
1895
  import pc6 from "picocolors";
1853
1896
  import {
1854
1897
  aggregatePrKpis,
@@ -1860,15 +1903,15 @@ import {
1860
1903
  } from "@aisdlc/core";
1861
1904
  function applyKpiPrOutput(options, markdown) {
1862
1905
  if (options.updateFile) {
1863
- if (!fs2.existsSync(options.updateFile)) {
1906
+ if (!fs.existsSync(options.updateFile)) {
1864
1907
  console.error(pc6.red(`
1865
1908
  \u2716 [ERROR] Target file '${options.updateFile}' does not exist.
1866
1909
  `));
1867
1910
  return false;
1868
1911
  }
1869
- const original = fs2.readFileSync(options.updateFile, "utf-8");
1912
+ const original = fs.readFileSync(options.updateFile, "utf-8");
1870
1913
  const updated = injectKpisIntoPrBody(original, markdown);
1871
- fs2.writeFileSync(options.updateFile, updated, "utf-8");
1914
+ fs.writeFileSync(options.updateFile, updated, "utf-8");
1872
1915
  console.log(pc6.green(`\u2714 [UPDATED] KPI summary injected into '${options.updateFile}'.`));
1873
1916
  } else {
1874
1917
  console.log("\n" + markdown + "\n");
@@ -1952,10 +1995,15 @@ async function runMcpServer(options = {}) {
1952
1995
  const rootDir = options.root || process.cwd();
1953
1996
  if (!options.silent) {
1954
1997
  console.error(pc7.bold(pc7.cyan("\n\u{1F680} [AI-SDLC MCP] Starting native Model Context Protocol (MCP) server (stdio)...")));
1955
- console.error(pc7.gray(` Base directory: ${rootDir}
1998
+ console.error(pc7.gray(` Base directory: ${rootDir}`));
1999
+ if (options.role) {
2000
+ console.error(pc7.gray(` Role context: ${options.role}
1956
2001
  `));
2002
+ } else {
2003
+ console.error("");
2004
+ }
1957
2005
  }
1958
- await startMcpServer({ rootDir });
2006
+ await startMcpServer({ rootDir, role: options.role });
1959
2007
  }
1960
2008
 
1961
2009
  // src/commands/report.ts
@@ -2403,7 +2451,7 @@ function runChangeNew(options) {
2403
2451
 
2404
2452
  // src/index.ts
2405
2453
  var program = new Command();
2406
- program.name("aisdlc").description("AI-SDLC: Spec-Driven Development, Governance & Quality Gates for AI & Humans").version("2.4.0");
2454
+ program.name("aisdlc").description("AI-SDLC: Spec-Driven Development, Governance & Quality Gates for AI & Humans").version("2.5.1");
2407
2455
  program.command("check").description("Unified pre-flight command: validates Quality Gates with optional non-destructive auto-fix").option("--fix", "Automatically synchronize Gherkin scenarios (.feature) and cryptographic digests of PDaC citations").option("-r, --root <path>", "Project root directory").option("--vuln", "Scan for known vulnerabilities (CVE/GHSA) in dependencies").option("--json", "Emit verification results in structured JSON format").option("-F, --format <format>", "Output format: text or json").action((opts) => {
2408
2456
  const passed = runCheck({
2409
2457
  fix: opts.fix,
@@ -2690,7 +2738,7 @@ sddCommand.command("integrate").description("Integrate and synchronize implement
2690
2738
  });
2691
2739
  process.exit(passed ? 0 : 1);
2692
2740
  });
2693
- program.command("init [directory]").description("Initialize a new repository with AI-SDLC guidelines, schemas, and policies").option("-d, --dry-run", "Simulate file and directory creation without writing to disk").option("--ci <provider>", "CI/CD provider for pipeline generation (github, gitlab, azure, bitbucket)").option("--agents [targets]", "AI agent environments to configure (all, cursor, claude, antigravity, copilot, mcp, or comma-separated combination)").option("--arch, --architecture <granularity>", "Architecture templates granularity level (minimal, full, complete, none)").option("--json", "Structured JSON format output").option("-F, --format <format>", "Output format: text or json").action(async (directory, opts) => {
2741
+ program.command("init [directory]").description("Initialize a new repository with AI-SDLC guidelines, schemas, and policies").option("-d, --dry-run", "Simulate file and directory creation without writing to disk").option("-f, --force", "Force overwrite existing agent, rule, and policy configurations with canonical templates").option("--ci <provider>", "CI/CD provider for pipeline generation (github, gitlab, azure, bitbucket)").option("--agents [targets]", "AI agent environments to configure (all, cursor, claude, antigravity, copilot, mcp, or comma-separated combination)").option("--arch, --architecture <granularity>", "Architecture templates granularity level (minimal, full, complete, none)").option("--json", "Structured JSON format output").option("-F, --format <format>", "Output format: text or json").action(async (directory, opts) => {
2694
2742
  let agents = opts.agents;
2695
2743
  let arch = opts.architecture || opts.arch;
2696
2744
  let ci = opts.ci;
@@ -2706,6 +2754,7 @@ program.command("init [directory]").description("Initialize a new repository wit
2706
2754
  }
2707
2755
  const passed = runInit(directory, {
2708
2756
  dryRun: opts.dryRun,
2757
+ force: opts.force,
2709
2758
  ci,
2710
2759
  agents,
2711
2760
  architecture: arch,
@@ -2714,8 +2763,20 @@ program.command("init [directory]").description("Initialize a new repository wit
2714
2763
  });
2715
2764
  process.exit(passed ? 0 : 1);
2716
2765
  });
2717
- program.command("mcp").description("Start native AI-SDLC Model Context Protocol (MCP) server (stdio)").option("-r, --root <path>", "Project root directory").action(async (opts) => {
2718
- await runMcpServer({ root: opts.root });
2766
+ program.command("sync [directory]").description("Synchronize and refresh AI agent configurations, skills, and rules from canonical templates").option("-d, --dry-run", "Simulate file updates without writing to disk").option("--agents [targets]", "AI agent environments to configure (all, cursor, claude, antigravity, copilot, mcp, or comma-separated combination)").option("--json", "Structured JSON format output").option("-F, --format <format>", "Output format: text or json").action((directory, opts) => {
2767
+ const passed = runInit(directory, {
2768
+ dryRun: opts.dryRun,
2769
+ force: true,
2770
+ agents: opts.agents || "all",
2771
+ ci: "none",
2772
+ architecture: "none",
2773
+ json: opts.json,
2774
+ format: opts.format
2775
+ });
2776
+ process.exit(passed ? 0 : 1);
2777
+ });
2778
+ program.command("mcp").description("Start native AI-SDLC Model Context Protocol (MCP) server (stdio)").option("-r, --root <path>", "Project root directory").option("--role <role>", "Role context for MCP server authorization").action(async (opts) => {
2779
+ await runMcpServer({ root: opts.root, role: opts.role });
2719
2780
  });
2720
2781
  program.on("command:*", () => {
2721
2782
  console.error(pc10.red(`