@mitre/hdf-diff 2.0.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.
Files changed (91) hide show
  1. package/LICENSE.md +55 -0
  2. package/README.md +87 -0
  3. package/dist/diff.d.ts +49 -0
  4. package/dist/diff.d.ts.map +1 -0
  5. package/dist/diff.js +791 -0
  6. package/dist/diff.js.map +1 -0
  7. package/dist/exit-codes.d.ts +42 -0
  8. package/dist/exit-codes.d.ts.map +1 -0
  9. package/dist/exit-codes.js +74 -0
  10. package/dist/exit-codes.js.map +1 -0
  11. package/dist/index.d.ts +17 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +19 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/matching/cci-match.d.ts +14 -0
  16. package/dist/matching/cci-match.d.ts.map +1 -0
  17. package/dist/matching/cci-match.js +102 -0
  18. package/dist/matching/cci-match.js.map +1 -0
  19. package/dist/matching/exact-id.d.ts +9 -0
  20. package/dist/matching/exact-id.d.ts.map +1 -0
  21. package/dist/matching/exact-id.js +88 -0
  22. package/dist/matching/exact-id.js.map +1 -0
  23. package/dist/matching/fuzzy-match.d.ts +26 -0
  24. package/dist/matching/fuzzy-match.d.ts.map +1 -0
  25. package/dist/matching/fuzzy-match.js +145 -0
  26. package/dist/matching/fuzzy-match.js.map +1 -0
  27. package/dist/matching/index.d.ts +36 -0
  28. package/dist/matching/index.d.ts.map +1 -0
  29. package/dist/matching/index.js +71 -0
  30. package/dist/matching/index.js.map +1 -0
  31. package/dist/matching/mapped-id.d.ts +13 -0
  32. package/dist/matching/mapped-id.d.ts.map +1 -0
  33. package/dist/matching/mapped-id.js +101 -0
  34. package/dist/matching/mapped-id.js.map +1 -0
  35. package/dist/matching/types.d.ts +34 -0
  36. package/dist/matching/types.d.ts.map +1 -0
  37. package/dist/matching/types.js +2 -0
  38. package/dist/matching/types.js.map +1 -0
  39. package/dist/normalize.d.ts +20 -0
  40. package/dist/normalize.d.ts.map +1 -0
  41. package/dist/normalize.js +120 -0
  42. package/dist/normalize.js.map +1 -0
  43. package/dist/renderers/csv.d.ts +15 -0
  44. package/dist/renderers/csv.d.ts.map +1 -0
  45. package/dist/renderers/csv.js +77 -0
  46. package/dist/renderers/csv.js.map +1 -0
  47. package/dist/renderers/filter.d.ts +11 -0
  48. package/dist/renderers/filter.d.ts.map +1 -0
  49. package/dist/renderers/filter.js +29 -0
  50. package/dist/renderers/filter.js.map +1 -0
  51. package/dist/renderers/index.d.ts +17 -0
  52. package/dist/renderers/index.d.ts.map +1 -0
  53. package/dist/renderers/index.js +29 -0
  54. package/dist/renderers/index.js.map +1 -0
  55. package/dist/renderers/json.d.ts +13 -0
  56. package/dist/renderers/json.d.ts.map +1 -0
  57. package/dist/renderers/json.js +41 -0
  58. package/dist/renderers/json.js.map +1 -0
  59. package/dist/renderers/markdown.d.ts +13 -0
  60. package/dist/renderers/markdown.d.ts.map +1 -0
  61. package/dist/renderers/markdown.js +133 -0
  62. package/dist/renderers/markdown.js.map +1 -0
  63. package/dist/renderers/terminal.d.ts +14 -0
  64. package/dist/renderers/terminal.d.ts.map +1 -0
  65. package/dist/renderers/terminal.js +173 -0
  66. package/dist/renderers/terminal.js.map +1 -0
  67. package/dist/renderers/types.d.ts +12 -0
  68. package/dist/renderers/types.d.ts.map +1 -0
  69. package/dist/renderers/types.js +2 -0
  70. package/dist/renderers/types.js.map +1 -0
  71. package/dist/sbom.d.ts +42 -0
  72. package/dist/sbom.d.ts.map +1 -0
  73. package/dist/sbom.js +203 -0
  74. package/dist/sbom.js.map +1 -0
  75. package/dist/status.d.ts +27 -0
  76. package/dist/status.d.ts.map +1 -0
  77. package/dist/status.js +137 -0
  78. package/dist/status.js.map +1 -0
  79. package/dist/summary.d.ts +6 -0
  80. package/dist/summary.d.ts.map +1 -0
  81. package/dist/summary.js +47 -0
  82. package/dist/summary.js.map +1 -0
  83. package/dist/types.d.ts +208 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +2 -0
  86. package/dist/types.js.map +1 -0
  87. package/dist/validate.d.ts +20 -0
  88. package/dist/validate.d.ts.map +1 -0
  89. package/dist/validate.js +108 -0
  90. package/dist/validate.js.map +1 -0
  91. package/package.json +54 -0
package/LICENSE.md ADDED
@@ -0,0 +1,55 @@
1
+ # License
2
+
3
+ Copyright © 2025 The MITRE Corporation.
4
+
5
+ Approved for Public Release; Distribution Unlimited. Case Number 18-3678.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
8
+ not use this file except in compliance with the License. You may obtain a
9
+ copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ License for the specific language governing permissions and limitations
17
+ under the License.
18
+
19
+ ## Redistribution Terms
20
+
21
+ Redistribution and use in source and binary forms, with or without
22
+ modification, are permitted provided that the following conditions are
23
+ met:
24
+
25
+ - Redistributions of source code must retain the above copyright/digital
26
+ rights legend, this list of conditions and the following Notice.
27
+ - Redistributions in binary form must reproduce the above
28
+ copyright/digital rights legend, this list of conditions and the
29
+ following Notice in the documentation and/or other materials provided
30
+ with the distribution.
31
+ - Neither the name of The MITRE Corporation nor the names of its contributors
32
+ may be used to endorse or promote products derived from this software
33
+ without specific prior written permission.
34
+
35
+ ## Notice
36
+
37
+ The MITRE Corporation grants permission to reproduce, distribute, modify, and
38
+ otherwise use this software to the extent permitted by the licensed terms
39
+ provided in the LICENSE file included with this project.
40
+
41
+ This software was produced by The MITRE Corporation for the U.S. Government
42
+ under contract. As such the U.S. Government has certain use and data
43
+ rights in this software. No use other than those granted to the U.S.
44
+ Government, or to those acting on behalf of the U.S. Government, under
45
+ these contract arrangements is authorized without the express written
46
+ permission of The MITRE Corporation.
47
+
48
+ Some files in this codebase were generated by generative AI, under the
49
+ direction and review of The MITRE Corporation employees, for the purpose of
50
+ development efficiency. All AI-generated code functionality was validated
51
+ by standard quality and assurance testing.
52
+
53
+ For further information, please contact The MITRE Corporation,
54
+ Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539,
55
+ (703) 983-6000.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @mitre/hdf-diff
2
+
3
+ Structured comparison of HDF evaluation results — tracks what changed, why, and by how much.
4
+
5
+ ## What it does
6
+
7
+ Compares two HDF results documents and produces a structured diff showing:
8
+ - Requirements added, removed, or changed between evaluations
9
+ - Status transitions (passed→failed, failed→passed, etc.) with change reasons
10
+ - Field-level changes (impact, title, severity)
11
+ - Per-baseline and per-component compliance summaries
12
+ - SBOM (CycloneDX/SPDX) package-level diffs
13
+
14
+ Output formats: JSON, Markdown, CSV, terminal (ANSI-colored).
15
+
16
+ ## Relationship to other packages
17
+
18
+ | Package | Relationship |
19
+ |---------|-------------|
20
+ | **hdf-schema** | Provides the `HDFResults` types that hdf-diff consumes |
21
+ | **hdf-validators** | Used to validate comparison output against the HDF comparison schema |
22
+ | **hdf-cli** | `hdf diff` command wraps this library for CLI use |
23
+ | **hdf-parsers** | Not used — hdf-diff operates on typed structs, not raw JSON |
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install @mitre/hdf-diff
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import { diffHdf, render } from '@mitre/hdf-diff';
35
+
36
+ // Compare two evaluation results
37
+ const comparison = diffHdf(oldResults, newResults);
38
+
39
+ // Render as markdown
40
+ const md = render(comparison, { format: 'markdown', detail: 'full' });
41
+
42
+ // Render as JSON
43
+ const json = render(comparison, { format: 'json' });
44
+
45
+ // Check exit codes for CI
46
+ import { computeExitCode, EXIT_IDENTICAL } from '@mitre/hdf-diff';
47
+ const code = computeExitCode(comparison);
48
+ if (code !== EXIT_IDENTICAL) process.exit(code);
49
+ ```
50
+
51
+ ### Requirement matching
52
+
53
+ hdf-diff supports multiple strategies for matching requirements across evaluations:
54
+ - **Exact ID** (default) — match by requirement ID
55
+ - **Mapped ID** — match via a user-provided ID mapping
56
+ - **CCI match** — match by shared CCI identifiers
57
+ - **Fuzzy title** — Jaccard similarity on tokenized titles
58
+
59
+ ```typescript
60
+ import { diffHdf, createFuzzyTitleStrategy } from '@mitre/hdf-diff';
61
+
62
+ const comparison = diffHdf(oldResults, newResults, {
63
+ matchStrategy: createFuzzyTitleStrategy(0.8), // 80% similarity threshold
64
+ });
65
+ ```
66
+
67
+ ### SBOM comparison
68
+
69
+ ```typescript
70
+ import { diffSboms } from '@mitre/hdf-diff';
71
+
72
+ const sbomDiff = diffSboms(oldSbom, newSbom);
73
+ // Shows packages added, removed, updated, or unchanged
74
+ ```
75
+
76
+ ## CLI usage
77
+
78
+ ```bash
79
+ hdf diff old-results.json new-results.json
80
+ hdf diff old-results.json new-results.json --format markdown
81
+ hdf diff old-results.json new-results.json --json
82
+ hdf diff --sbom old-sbom.json new-sbom.json
83
+ ```
84
+
85
+ ## License
86
+
87
+ Apache-2.0 © MITRE Corporation
package/dist/diff.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { HdfComparison } from './types.js';
2
+ /**
3
+ * Options for configuring the diff behavior.
4
+ */
5
+ export interface DiffOptions {
6
+ /** Fields to track for field-level diffs (default: ['impact', 'severity', 'tags']) */
7
+ trackedFields?: string[];
8
+ /** Comparison mode (default: 'temporal') */
9
+ comparisonMode?: 'temporal' | 'baseline' | 'fleet' | 'multiSource' | 'baselineEvolution' | 'systemDrift';
10
+ /** Primary matching strategy name (default: 'exactId') */
11
+ matchStrategy?: string;
12
+ /** Fallback strategy names, applied in order to remaining unmatched requirements */
13
+ fallbackStrategies?: string[];
14
+ /** Mapping table for the 'mappedId' strategy (old ID -> new ID) */
15
+ mappingTable?: Record<string, string>;
16
+ /** Minimum confidence threshold for fuzzy matching (default: 0.6) */
17
+ minConfidence?: number;
18
+ /** Validate output against hdf-comparison schema. Default: false (performance). */
19
+ validateOutput?: boolean;
20
+ }
21
+ /**
22
+ * Compare two HDF results documents and produce a structured comparison.
23
+ *
24
+ * Requirements are matched using a configurable matching strategy (default: exact ID).
25
+ * Baselines are matched by `name`.
26
+ *
27
+ * For fleet mode, `newResults` can be an array of documents, each compared
28
+ * pairwise against `oldResults` (the reference).
29
+ */
30
+ export declare function diffHdf(oldResults: Record<string, unknown>, newResults: Record<string, unknown> | Record<string, unknown>[], options?: DiffOptions): HdfComparison;
31
+ /**
32
+ * Compare two HDF baseline documents and produce a structured comparison
33
+ * showing requirement changes between baseline versions.
34
+ *
35
+ * Unlike diffHdf (which compares results/evaluations), this compares baseline
36
+ * definitions — requirements without results. There is no status-based classification
37
+ * (fixed/regressed); only metadata changes (title, impact, descriptions, tags) are tracked.
38
+ */
39
+ export declare function diffBaselines(oldBaseline: Record<string, unknown>, newBaseline: Record<string, unknown>, options?: DiffOptions): HdfComparison;
40
+ /**
41
+ * Compare two HDF system documents and produce a structured comparison
42
+ * showing component-level changes between system versions.
43
+ *
44
+ * Components are matched by componentId (UUID) when available, falling back
45
+ * to exact name matching. Top-level system fields, data flows, and embedded
46
+ * SBOMs are also compared.
47
+ */
48
+ export declare function diffSystems(oldSystem: Record<string, unknown>, newSystem: Record<string, unknown>, options?: DiffOptions): HdfComparison;
49
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAMd,MAAM,YAAY,CAAC;AAUpB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,4CAA4C;IAC5C,cAAc,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,aAAa,GAAG,mBAAmB,GAAG,aAAa,CAAC;IACzG,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,kBAAkB,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