@ipation/specbridge 2.4.5 → 2.4.7

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.d.ts CHANGED
@@ -5,6 +5,43 @@ import { Logger as Logger$1 } from 'pino';
5
5
  import { Application } from 'express';
6
6
  export { minimatch } from 'minimatch';
7
7
 
8
+ /**
9
+ * Shared execution context contract for CLI commands.
10
+ */
11
+ type CommandOutputFormat = 'console' | 'json' | 'markdown';
12
+ interface CommandContext {
13
+ cwd: string;
14
+ outputFormat: CommandOutputFormat;
15
+ }
16
+ interface ConfiguredCommandContext<TConfig> {
17
+ context: CommandContext;
18
+ config: TConfig;
19
+ }
20
+
21
+ /**
22
+ * Normalized verification request/response contracts shared across modules.
23
+ */
24
+
25
+ interface VerificationRunRequest {
26
+ level?: VerificationLevel;
27
+ files?: string[];
28
+ decisions?: string[];
29
+ severity?: Severity[];
30
+ timeout?: number;
31
+ cwd?: string;
32
+ }
33
+ interface VerificationRunResult {
34
+ success: boolean;
35
+ violations: Violation[];
36
+ checked: number;
37
+ passed: number;
38
+ failed: number;
39
+ skipped: number;
40
+ duration: number;
41
+ warnings?: VerificationWarning[];
42
+ errors?: VerificationIssue[];
43
+ }
44
+
8
45
  /**
9
46
  * Core type definitions for SpecBridge
10
47
  */
@@ -572,8 +609,8 @@ declare const SpecBridgeConfigSchema: z.ZodObject<{
572
609
  }, z.core.$strip>>;
573
610
  agent: z.ZodOptional<z.ZodObject<{
574
611
  format: z.ZodOptional<z.ZodEnum<{
575
- markdown: "markdown";
576
612
  json: "json";
613
+ markdown: "markdown";
577
614
  mcp: "mcp";
578
615
  }>>;
579
616
  includeRationale: z.ZodOptional<z.ZodBoolean>;
@@ -1110,13 +1147,7 @@ declare class ExplainReporter {
1110
1147
  clear(): void;
1111
1148
  }
1112
1149
 
1113
- interface VerificationOptions {
1114
- level?: VerificationLevel;
1115
- files?: string[];
1116
- decisions?: string[];
1117
- severity?: Severity[];
1118
- timeout?: number;
1119
- cwd?: string;
1150
+ interface VerificationOptions extends VerificationRunRequest {
1120
1151
  reporter?: ExplainReporter;
1121
1152
  }
1122
1153
  /**
@@ -1133,7 +1164,7 @@ declare class VerificationEngine {
1133
1164
  /**
1134
1165
  * Run verification
1135
1166
  */
1136
- verify(config: SpecBridgeConfig, options?: VerificationOptions): Promise<VerificationResult>;
1167
+ verify(config: SpecBridgeConfig, options?: VerificationOptions): Promise<VerificationRunResult>;
1137
1168
  /**
1138
1169
  * Verify a single file
1139
1170
  */
@@ -1489,8 +1520,7 @@ interface ReportOptions {
1489
1520
  * Generic verification result shape for Reporter class
1490
1521
  * Supports various result formats from different verification engines
1491
1522
  */
1492
- interface ReporterResult {
1493
- violations?: Violation[];
1523
+ interface ReporterResult extends Partial<VerificationRunResult> {
1494
1524
  summary?: {
1495
1525
  totalViolations?: number;
1496
1526
  decisionsChecked?: number;
@@ -2014,4 +2044,4 @@ interface GitHubPrCommentOptions {
2014
2044
  declare function formatViolationsForGitHub(violations: Violation[], limit?: number): string;
2015
2045
  declare function postPrComment(violations: Violation[], options: GitHubPrCommentOptions): Promise<void>;
2016
2046
 
2017
- export { type AffectedFile, type AgentContext, AgentContextGenerator, AlreadyInitializedError, AnalyticsEngine, type AnalyticsSummary, type Analyzer, AnalyzerNotFoundError, ApiVerifier, type ApplicableConstraint, type ApplicableDecision, AstCache, AutofixEngine, type AutofixPatch, type AutofixResult, type BuildDependencyGraphOptions, CodeScanner, ComplexityVerifier, type ComplianceReport, ConfigError, type Constraint, type ConstraintCheck, ConstraintCheckSchema, type ConstraintCheckSchema_, type ConstraintException, ConstraintExceptionSchema, type ConstraintExceptionSchema_, ConstraintSchema, type ConstraintSchema_, type ConstraintType, ConstraintTypeSchema, type ConstraintTypeSchema_, type ContextOptions, DashboardServer, type Decision, type DecisionCompliance, type DecisionContent, DecisionContentSchema, type DecisionContentSchema_, type DecisionFilter, type DecisionMetadata, DecisionMetadataSchema, type DecisionMetadataSchema_, type DecisionMetrics, DecisionNotFoundError, DecisionSchema, type DecisionStatus, DecisionStatusSchema, type DecisionStatusSchema_, type DecisionTypeSchema, DecisionValidationError, type DependencyGraph, DependencyVerifier, type DriftAnalysis, ErrorsAnalyzer, ErrorsVerifier, FileSystemError, type GitHubPrCommentOptions, type GlobOptions, type GraphNode, HookError, type ImpactAnalysis, ImportsAnalyzer, ImportsVerifier, InferenceEngine, InferenceError, type InferenceOptions, type InferenceResult, type Insight, type LevelConfig, LinksSchema, type LoadError, type LoadResult, type LoadedDecision, type Logger, type McpServerOptions, type MigrationStep, NamingAnalyzer, NamingVerifier, NotInitializedError, type OverallDrift, type Pattern, type PatternExample, type PromptTemplate, PropagationEngine, type PropagationOptions, RegexVerifier, Registry, type RegistryConstraintMatch, RegistryError, type RegistryOptions, type ReportOptions, ReportStorage, Reporter, type ReporterResult, type ScanOptions, type ScanResult, type ScannedFile, SecurityVerifier, type Severity, SeveritySchema, type SeveritySchema_, type SpecBridgeConfig, SpecBridgeConfigSchema, type SpecBridgeConfigType, SpecBridgeError, SpecBridgeMcpServer, type StoredReport, StructureAnalyzer, type TextEdit, type TrendAnalysis, type TrendData, type TrendDirection, type VerificationConfig, VerificationConfigSchema, type VerificationConfigSchema_, type VerificationContext, VerificationEngine, VerificationError, type VerificationFrequency, VerificationFrequencySchema, type VerificationFrequencySchema_, type VerificationIssue, type VerificationLevel, type VerificationOptions, type VerificationResult, type VerificationWarning, type Verifier, VerifierNotFoundError, type VerifierPlugin, type VerifierPluginMetadata, type Violation, type ViolationFix, analyzeTrend, buildDependencyGraph, builtinAnalyzers, builtinVerifiers, calculateConfidence, checkDegradation, clearVerifierPool, createDashboardServer, createInferenceEngine, createPattern, createPropagationEngine, createRegistry, createScannerFromConfig, createVerificationEngine, createViolation, defaultConfig, defineVerifierPlugin, detectDrift, ensureDir, extractSnippet, formatConsoleReport, formatContextAsJson, formatContextAsMarkdown, formatContextAsMcp, formatError, formatMarkdownReport, formatValidationErrors, formatViolationsForGitHub, generateContext, generateFormattedContext, generateReport, getAffectedFiles, getAffectingDecisions, getAnalyzer, getAnalyzerIds, getChangedFiles, getConfigPath, getDecisionsDir, getInferredDir, getLogger, getReportsDir, getSpecBridgeDir, getTransitiveDependencies, getVerifier, getVerifierIds, getVerifiersDir, glob, isConstraintExcepted, isDirectory, loadConfig, loadDecisionFile, loadDecisionsFromDir, logger, matchesAnyPattern, matchesPattern, mergeWithDefaults, normalizePath, parseYaml, parseYamlDocument, pathExists, postPrComment, readFilesInDir, readTextFile, runInference, selectVerifierForConstraint, shouldApplyConstraintToFile, startLspServer, stringifyYaml, templates, updateYamlDocument, validateConfig, validateDecision, validateDecisionFile, writeTextFile };
2047
+ export { type AffectedFile, type AgentContext, AgentContextGenerator, AlreadyInitializedError, AnalyticsEngine, type AnalyticsSummary, type Analyzer, AnalyzerNotFoundError, ApiVerifier, type ApplicableConstraint, type ApplicableDecision, AstCache, AutofixEngine, type AutofixPatch, type AutofixResult, type BuildDependencyGraphOptions, CodeScanner, type CommandContext, type CommandOutputFormat, ComplexityVerifier, type ComplianceReport, ConfigError, type ConfiguredCommandContext, type Constraint, type ConstraintCheck, ConstraintCheckSchema, type ConstraintCheckSchema_, type ConstraintException, ConstraintExceptionSchema, type ConstraintExceptionSchema_, ConstraintSchema, type ConstraintSchema_, type ConstraintType, ConstraintTypeSchema, type ConstraintTypeSchema_, type ContextOptions, DashboardServer, type Decision, type DecisionCompliance, type DecisionContent, DecisionContentSchema, type DecisionContentSchema_, type DecisionFilter, type DecisionMetadata, DecisionMetadataSchema, type DecisionMetadataSchema_, type DecisionMetrics, DecisionNotFoundError, DecisionSchema, type DecisionStatus, DecisionStatusSchema, type DecisionStatusSchema_, type DecisionTypeSchema, DecisionValidationError, type DependencyGraph, DependencyVerifier, type DriftAnalysis, ErrorsAnalyzer, ErrorsVerifier, ExplainReporter, type ExplanationEntry, FileSystemError, type GitHubPrCommentOptions, type GlobOptions, type GraphNode, HookError, type ImpactAnalysis, ImportsAnalyzer, ImportsVerifier, InferenceEngine, InferenceError, type InferenceOptions, type InferenceResult, type Insight, type LevelConfig, LinksSchema, type LoadError, type LoadResult, type LoadedDecision, type Logger, type McpServerOptions, type MigrationStep, NamingAnalyzer, NamingVerifier, NotInitializedError, type OverallDrift, type Pattern, type PatternExample, type PromptTemplate, PropagationEngine, type PropagationOptions, RegexVerifier, Registry, type RegistryConstraintMatch, RegistryError, type RegistryOptions, type ReportOptions, ReportStorage, Reporter, type ReporterResult, type ScanOptions, type ScanResult, type ScannedFile, SecurityVerifier, type Severity, SeveritySchema, type SeveritySchema_, type SpecBridgeConfig, SpecBridgeConfigSchema, type SpecBridgeConfigType, SpecBridgeError, SpecBridgeMcpServer, type StoredReport, StructureAnalyzer, type TextEdit, type TrendAnalysis, type TrendData, type TrendDirection, type VerificationConfig, VerificationConfigSchema, type VerificationConfigSchema_, type VerificationContext, VerificationEngine, VerificationError, type VerificationFrequency, VerificationFrequencySchema, type VerificationFrequencySchema_, type VerificationIssue, type VerificationLevel, type VerificationOptions, type VerificationResult, type VerificationRunRequest, type VerificationRunResult, type VerificationWarning, type Verifier, VerifierNotFoundError, type VerifierPlugin, type VerifierPluginMetadata, type Violation, type ViolationFix, analyzeTrend, buildDependencyGraph, builtinAnalyzers, builtinVerifiers, calculateConfidence, checkDegradation, clearVerifierPool, createDashboardServer, createInferenceEngine, createPattern, createPropagationEngine, createRegistry, createScannerFromConfig, createVerificationEngine, createViolation, defaultConfig, defineVerifierPlugin, detectDrift, ensureDir, extractSnippet, formatConsoleReport, formatContextAsJson, formatContextAsMarkdown, formatContextAsMcp, formatError, formatMarkdownReport, formatValidationErrors, formatViolationsForGitHub, generateContext, generateFormattedContext, generateReport, getAffectedFiles, getAffectingDecisions, getAnalyzer, getAnalyzerIds, getChangedFiles, getConfigPath, getDecisionsDir, getInferredDir, getLogger, getReportsDir, getSpecBridgeDir, getTransitiveDependencies, getVerifier, getVerifierIds, getVerifiersDir, glob, isConstraintExcepted, isDirectory, loadConfig, loadDecisionFile, loadDecisionsFromDir, logger, matchesAnyPattern, matchesPattern, mergeWithDefaults, normalizePath, parseYaml, parseYamlDocument, pathExists, postPrComment, readFilesInDir, readTextFile, runInference, selectVerifierForConstraint, shouldApplyConstraintToFile, startLspServer, stringifyYaml, templates, updateYamlDocument, validateConfig, validateDecision, validateDecisionFile, writeTextFile };
package/dist/index.js CHANGED
@@ -3529,6 +3529,75 @@ async function getChangedFiles(cwd) {
3529
3529
  }
3530
3530
  }
3531
3531
 
3532
+ // src/verification/explain.ts
3533
+ import chalk from "chalk";
3534
+ var ExplainReporter = class {
3535
+ entries = [];
3536
+ /**
3537
+ * Add an entry to the explanation trace
3538
+ */
3539
+ add(entry) {
3540
+ this.entries.push(entry);
3541
+ }
3542
+ /**
3543
+ * Print the explanation trace
3544
+ */
3545
+ print() {
3546
+ if (this.entries.length === 0) {
3547
+ console.log(chalk.dim("No constraints were evaluated."));
3548
+ return;
3549
+ }
3550
+ console.log(chalk.bold("\n=== Verification Explanation ===\n"));
3551
+ const byFile = /* @__PURE__ */ new Map();
3552
+ for (const entry of this.entries) {
3553
+ const existing = byFile.get(entry.file) || [];
3554
+ existing.push(entry);
3555
+ byFile.set(entry.file, existing);
3556
+ }
3557
+ for (const [file, entries] of byFile) {
3558
+ console.log(chalk.underline(file));
3559
+ for (const entry of entries) {
3560
+ const icon = entry.applied ? chalk.green("\u2713") : chalk.dim("\u2298");
3561
+ const constraintId = `${entry.decision.metadata.id}/${entry.constraint.id}`;
3562
+ console.log(` ${icon} ${constraintId}`);
3563
+ console.log(chalk.dim(` ${entry.reason}`));
3564
+ if (entry.applied && entry.selectedVerifier) {
3565
+ console.log(chalk.dim(` Verifier: ${entry.selectedVerifier}`));
3566
+ if (entry.verifierOutput) {
3567
+ if (entry.verifierOutput.error) {
3568
+ console.log(chalk.red(` Error: ${entry.verifierOutput.error}`));
3569
+ } else {
3570
+ const violationText = entry.verifierOutput.violations === 1 ? "1 violation" : `${entry.verifierOutput.violations} violations`;
3571
+ const resultColor = entry.verifierOutput.violations > 0 ? chalk.red : chalk.green;
3572
+ console.log(
3573
+ chalk.dim(` Result: `) + resultColor(violationText) + chalk.dim(` in ${entry.verifierOutput.duration}ms`)
3574
+ );
3575
+ }
3576
+ }
3577
+ }
3578
+ console.log("");
3579
+ }
3580
+ }
3581
+ const applied = this.entries.filter((e) => e.applied).length;
3582
+ const skipped = this.entries.filter((e) => !e.applied).length;
3583
+ console.log(chalk.bold("Summary:"));
3584
+ console.log(` Constraints Applied: ${chalk.green(applied)}`);
3585
+ console.log(` Constraints Skipped: ${chalk.dim(skipped)}`);
3586
+ }
3587
+ /**
3588
+ * Get all entries
3589
+ */
3590
+ getEntries() {
3591
+ return [...this.entries];
3592
+ }
3593
+ /**
3594
+ * Clear all entries
3595
+ */
3596
+ clear() {
3597
+ this.entries = [];
3598
+ }
3599
+ };
3600
+
3532
3601
  // src/verification/autofix/engine.ts
3533
3602
  import { readFile as readFile4, writeFile as writeFile2 } from "fs/promises";
3534
3603
  import readline from "readline/promises";
@@ -4116,58 +4185,58 @@ var Reporter = class {
4116
4185
  };
4117
4186
 
4118
4187
  // src/reporting/formats/console.ts
4119
- import chalk from "chalk";
4188
+ import chalk2 from "chalk";
4120
4189
  import { table } from "table";
4121
4190
  function formatConsoleReport(report) {
4122
4191
  const lines = [];
4123
4192
  lines.push("");
4124
- lines.push(chalk.bold.blue("SpecBridge Compliance Report"));
4125
- lines.push(chalk.dim(`Generated: ${new Date(report.timestamp).toLocaleString()}`));
4126
- lines.push(chalk.dim(`Project: ${report.project}`));
4193
+ lines.push(chalk2.bold.blue("SpecBridge Compliance Report"));
4194
+ lines.push(chalk2.dim(`Generated: ${new Date(report.timestamp).toLocaleString()}`));
4195
+ lines.push(chalk2.dim(`Project: ${report.project}`));
4127
4196
  lines.push("");
4128
4197
  const complianceColor = getComplianceColor(report.summary.compliance);
4129
- lines.push(chalk.bold("Overall Compliance"));
4198
+ lines.push(chalk2.bold("Overall Compliance"));
4130
4199
  lines.push(
4131
4200
  ` ${complianceColor(formatComplianceBar(report.summary.compliance))} ${complianceColor(`${report.summary.compliance}%`)}`
4132
4201
  );
4133
4202
  lines.push("");
4134
- lines.push(chalk.bold("Summary"));
4203
+ lines.push(chalk2.bold("Summary"));
4135
4204
  lines.push(
4136
4205
  ` Decisions: ${report.summary.activeDecisions} active / ${report.summary.totalDecisions} total`
4137
4206
  );
4138
4207
  lines.push(` Constraints: ${report.summary.totalConstraints}`);
4139
4208
  lines.push("");
4140
- lines.push(chalk.bold("Violations"));
4209
+ lines.push(chalk2.bold("Violations"));
4141
4210
  const { violations } = report.summary;
4142
4211
  const violationParts = [];
4143
4212
  if (violations.critical > 0) {
4144
- violationParts.push(chalk.red(`${violations.critical} critical`));
4213
+ violationParts.push(chalk2.red(`${violations.critical} critical`));
4145
4214
  }
4146
4215
  if (violations.high > 0) {
4147
- violationParts.push(chalk.yellow(`${violations.high} high`));
4216
+ violationParts.push(chalk2.yellow(`${violations.high} high`));
4148
4217
  }
4149
4218
  if (violations.medium > 0) {
4150
- violationParts.push(chalk.cyan(`${violations.medium} medium`));
4219
+ violationParts.push(chalk2.cyan(`${violations.medium} medium`));
4151
4220
  }
4152
4221
  if (violations.low > 0) {
4153
- violationParts.push(chalk.dim(`${violations.low} low`));
4222
+ violationParts.push(chalk2.dim(`${violations.low} low`));
4154
4223
  }
4155
4224
  if (violationParts.length > 0) {
4156
4225
  lines.push(` ${violationParts.join(" | ")}`);
4157
4226
  } else {
4158
- lines.push(chalk.green(" No violations"));
4227
+ lines.push(chalk2.green(" No violations"));
4159
4228
  }
4160
4229
  lines.push("");
4161
4230
  if (report.byDecision.length > 0) {
4162
- lines.push(chalk.bold("By Decision"));
4231
+ lines.push(chalk2.bold("By Decision"));
4163
4232
  lines.push("");
4164
4233
  const tableData = [
4165
4234
  [
4166
- chalk.bold("Decision"),
4167
- chalk.bold("Status"),
4168
- chalk.bold("Constraints"),
4169
- chalk.bold("Violations"),
4170
- chalk.bold("Compliance")
4235
+ chalk2.bold("Decision"),
4236
+ chalk2.bold("Status"),
4237
+ chalk2.bold("Constraints"),
4238
+ chalk2.bold("Violations"),
4239
+ chalk2.bold("Compliance")
4171
4240
  ]
4172
4241
  ];
4173
4242
  for (const dec of report.byDecision) {
@@ -4177,7 +4246,7 @@ function formatConsoleReport(report) {
4177
4246
  truncate(dec.title, 40),
4178
4247
  statusColor(dec.status),
4179
4248
  String(dec.constraints),
4180
- dec.violations > 0 ? chalk.red(String(dec.violations)) : chalk.green("0"),
4249
+ dec.violations > 0 ? chalk2.red(String(dec.violations)) : chalk2.green("0"),
4181
4250
  compColor(`${dec.compliance}%`)
4182
4251
  ]);
4183
4252
  }
@@ -4211,23 +4280,23 @@ function formatComplianceBar(compliance) {
4211
4280
  return "\u2588".repeat(filled) + "\u2591".repeat(empty);
4212
4281
  }
4213
4282
  function getComplianceColor(compliance) {
4214
- if (compliance >= 90) return chalk.green;
4215
- if (compliance >= 70) return chalk.yellow;
4216
- if (compliance >= 50) return chalk.hex("#FFA500");
4217
- return chalk.red;
4283
+ if (compliance >= 90) return chalk2.green;
4284
+ if (compliance >= 70) return chalk2.yellow;
4285
+ if (compliance >= 50) return chalk2.hex("#FFA500");
4286
+ return chalk2.red;
4218
4287
  }
4219
4288
  function getStatusColor(status) {
4220
4289
  switch (status) {
4221
4290
  case "active":
4222
- return chalk.green;
4291
+ return chalk2.green;
4223
4292
  case "draft":
4224
- return chalk.yellow;
4293
+ return chalk2.yellow;
4225
4294
  case "deprecated":
4226
- return chalk.gray;
4295
+ return chalk2.gray;
4227
4296
  case "superseded":
4228
- return chalk.blue;
4297
+ return chalk2.blue;
4229
4298
  default:
4230
- return chalk.white;
4299
+ return chalk2.white;
4231
4300
  }
4232
4301
  }
4233
4302
  function truncate(str, length) {
@@ -5560,7 +5629,7 @@ import { TextDocument } from "vscode-languageserver-textdocument";
5560
5629
  import { fileURLToPath as fileURLToPath2 } from "url";
5561
5630
  import path3 from "path";
5562
5631
  import { Project as Project3 } from "ts-morph";
5563
- import chalk2 from "chalk";
5632
+ import chalk3 from "chalk";
5564
5633
  function severityToDiagnostic(severity) {
5565
5634
  switch (severity) {
5566
5635
  case "critical":
@@ -5671,7 +5740,7 @@ var SpecBridgeLspServer = class {
5671
5740
  if (!await pathExists(getSpecBridgeDir(this.cwd))) {
5672
5741
  const err = new NotInitializedError();
5673
5742
  this.initError = err.message;
5674
- if (this.options.verbose) this.connection.console.error(chalk2.red(this.initError));
5743
+ if (this.options.verbose) this.connection.console.error(chalk3.red(this.initError));
5675
5744
  return;
5676
5745
  }
5677
5746
  try {
@@ -5681,7 +5750,7 @@ var SpecBridgeLspServer = class {
5681
5750
  } catch (error) {
5682
5751
  const msg = error instanceof Error ? error.message : String(error);
5683
5752
  if (this.options.verbose)
5684
- this.connection.console.error(chalk2.red(`Plugin load failed: ${msg}`));
5753
+ this.connection.console.error(chalk3.red(`Plugin load failed: ${msg}`));
5685
5754
  }
5686
5755
  this.registry = createRegistry({ basePath: this.cwd });
5687
5756
  await this.registry.load();
@@ -5695,12 +5764,12 @@ var SpecBridgeLspServer = class {
5695
5764
  }
5696
5765
  if (this.options.verbose) {
5697
5766
  this.connection.console.log(
5698
- chalk2.dim(`Loaded ${this.decisions.length} active decision(s)`)
5767
+ chalk3.dim(`Loaded ${this.decisions.length} active decision(s)`)
5699
5768
  );
5700
5769
  }
5701
5770
  } catch (error) {
5702
5771
  this.initError = error instanceof Error ? error.message : String(error);
5703
- if (this.options.verbose) this.connection.console.error(chalk2.red(this.initError));
5772
+ if (this.options.verbose) this.connection.console.error(chalk3.red(this.initError));
5704
5773
  }
5705
5774
  }
5706
5775
  async verifyTextDocument(doc) {
@@ -5855,6 +5924,7 @@ export {
5855
5924
  DependencyVerifier,
5856
5925
  ErrorsAnalyzer,
5857
5926
  ErrorsVerifier,
5927
+ ExplainReporter,
5858
5928
  FileSystemError,
5859
5929
  HookError,
5860
5930
  ImportsAnalyzer,