@dataparade/cli 0.0.31 → 0.0.33

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 (141) hide show
  1. package/README.md +56 -1
  2. package/dist/package.json +4 -3
  3. package/dist/src/ai-enrichment/fallbacks.js +12 -1
  4. package/dist/src/cli.js +50 -4
  5. package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
  6. package/dist/src/diff/register-diff-command.d.ts +4 -0
  7. package/dist/src/diff/register-diff-command.js +79 -0
  8. package/dist/src/diff/run-diff.d.ts +80 -0
  9. package/dist/src/diff/run-diff.js +206 -0
  10. package/dist/src/diff/upload-diff.d.ts +26 -0
  11. package/dist/src/diff/upload-diff.js +69 -0
  12. package/dist/src/facts/apply-answers.js +1 -1
  13. package/dist/src/facts/build-facts.d.ts +3 -1
  14. package/dist/src/facts/build-facts.js +10 -1
  15. package/dist/src/facts/identity.d.ts +27 -0
  16. package/dist/src/facts/identity.js +203 -0
  17. package/dist/src/facts/io.d.ts +2 -0
  18. package/dist/src/facts/io.js +7 -0
  19. package/dist/src/facts/scan-stamps.d.ts +55 -0
  20. package/dist/src/facts/scan-stamps.js +165 -0
  21. package/dist/src/facts/schema.d.ts +243 -7
  22. package/dist/src/facts/schema.js +71 -1
  23. package/dist/src/kb/answer-fingerprint.d.ts +44 -0
  24. package/dist/src/kb/answer-fingerprint.js +173 -0
  25. package/dist/src/kb/brief.d.ts +8 -1
  26. package/dist/src/kb/brief.js +18 -2
  27. package/dist/src/kb/land.js +3 -0
  28. package/dist/src/kb/register-kb-commands.js +7 -1
  29. package/dist/src/output/git-context.d.ts +25 -0
  30. package/dist/src/output/git-context.js +122 -0
  31. package/dist/src/output/scan-output-excludes.js +5 -1
  32. package/dist/src/output/write-scan-knowledge.d.ts +2 -0
  33. package/dist/src/output/write-scan-knowledge.js +1 -0
  34. package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
  35. package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
  36. package/dist/src/platform-api/upload-client.d.ts +1 -1
  37. package/dist/src/platform-api/upload-client.js +32 -1
  38. package/dist/src/platform-api/upload.types.d.ts +55 -0
  39. package/dist/src/sensitive-scan/process.d.ts +5 -0
  40. package/dist/src/sensitive-scan/process.js +48 -0
  41. package/dist/src/sensitive-scan/project.d.ts +12 -0
  42. package/dist/src/sensitive-scan/project.js +177 -0
  43. package/dist/src/sensitive-scan/report.d.ts +50 -0
  44. package/dist/src/sensitive-scan/report.js +32 -0
  45. package/dist/src/sensitive-scan/sessions.d.ts +2 -0
  46. package/dist/src/sensitive-scan/sessions.js +120 -0
  47. package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
  48. package/dist/src/ui/scan-progress-renderer.js +8 -0
  49. package/dist/src/upload/build-preview-url.d.ts +2 -2
  50. package/dist/src/upload/build-preview-url.js +4 -4
  51. package/dist/src/upload/run-upload.js +6 -2
  52. package/dist/src/upload/types.d.ts +2 -0
  53. package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
  54. package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
  55. package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
  56. package/dist/tests/unit/diff/run-diff.spec.js +189 -0
  57. package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
  58. package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
  59. package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
  60. package/dist/tests/unit/facts/build-facts.spec.js +67 -1
  61. package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
  62. package/dist/tests/unit/facts/identity.spec.js +148 -0
  63. package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
  64. package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
  65. package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
  66. package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
  67. package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
  68. package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
  69. package/dist/tests/unit/output/git-context.spec.js +98 -0
  70. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
  71. package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
  72. package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
  73. package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
  74. package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
  75. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
  76. package/dist/tests/unit/upload/run-upload.spec.js +32 -0
  77. package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
  78. package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
  79. package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
  80. package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
  81. package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
  82. package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
  83. package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
  84. package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
  85. package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
  86. package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
  87. package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
  88. package/dist/vendor/kb-compare/dist/src/index.js +34 -0
  89. package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
  90. package/dist/vendor/kb-compare/dist/src/input.js +75 -0
  91. package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
  92. package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
  93. package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
  94. package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
  95. package/dist/vendor/kb-compare/package.json +6 -0
  96. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
  97. package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
  98. package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
  99. package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
  100. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
  101. package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
  102. package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
  103. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
  104. package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
  105. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
  106. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
  107. package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
  108. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
  109. package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
  110. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
  111. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
  112. package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
  113. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
  114. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
  115. package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
  116. package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
  117. package/dist/vendor/scanner/dist/src/index.js +4 -2
  118. package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
  119. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
  120. package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
  121. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
  122. package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
  123. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
  124. package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
  125. package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
  126. package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
  127. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
  128. package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
  129. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
  130. package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
  131. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
  132. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
  133. package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
  134. package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
  135. package/dist/vendor/scanner/package.json +3 -1
  136. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +198 -0
  137. package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
  138. package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
  139. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +271 -0
  140. package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
  141. package/package.json +4 -3
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.configHash = configHash;
7
+ exports.catalogHash = catalogHash;
8
+ exports.scannerBuildInfo = scannerBuildInfo;
9
+ exports.findCliPackageRoot = findCliPackageRoot;
10
+ exports.readGitStamps = readGitStamps;
11
+ exports.buildScanStamps = buildScanStamps;
12
+ const child_process_1 = require("child_process");
13
+ const crypto_1 = require("crypto");
14
+ const fs_1 = __importDefault(require("fs"));
15
+ const path_1 = __importDefault(require("path"));
16
+ /**
17
+ * Scan stamps (DATAP-876): what a comparison needs to know to decide whether two scans can be
18
+ * compared. Two scans of the same commit with the same CLI, scanner, catalog and configuration
19
+ * have equal stamps.
20
+ */
21
+ function sha256(text) {
22
+ return (0, crypto_1.createHash)("sha256").update(text).digest("hex");
23
+ }
24
+ /** JSON with sorted keys, so equal settings always hash the same. */
25
+ function canonical(value) {
26
+ if (Array.isArray(value))
27
+ return `[${value.map(canonical).join(",")}]`;
28
+ if (value && typeof value === "object") {
29
+ return `{${Object.entries(value)
30
+ .filter(([, v]) => v !== undefined)
31
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
32
+ .map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`)
33
+ .join(",")}}`;
34
+ }
35
+ return JSON.stringify(value ?? null);
36
+ }
37
+ function configHash(config) {
38
+ const sorted = (list) => (list ? [...list].sort() : undefined);
39
+ return `sha256:${sha256(canonical({
40
+ organizationDomains: sorted(config.organizationDomains?.map((d) => d.trim().toLowerCase())),
41
+ excludePaths: sorted(config.excludePaths),
42
+ enableAPIDetection: config.enableAPIDetection,
43
+ enableDatabaseDetection: config.enableDatabaseDetection,
44
+ enableDataFlowDetection: config.enableDataFlowDetection,
45
+ languages: sorted(config.languages),
46
+ minimumConfidence: config.minimumConfidence,
47
+ deepAnalysis: config.deepAnalysis,
48
+ terraformJsonPath: config.terraformJsonPath,
49
+ terraformPlanPath: config.terraformPlanPath,
50
+ terraformStackSectionPathDepth: config.terraformStackSectionPathDepth,
51
+ autoInferTerraformStackSectionPathDepth: config.autoInferTerraformStackSectionPathDepth,
52
+ monorepoPackageSectionPathDepth: config.monorepoPackageSectionPathDepth,
53
+ autoInferMonorepoPackageSectionPathDepth: config.autoInferMonorepoPackageSectionPathDepth,
54
+ })).slice(0, 16)}`;
55
+ }
56
+ /** Hash of every file under `patterns/`, by sorted relative path and content. */
57
+ function catalogHash(patternsDir) {
58
+ const files = [];
59
+ const walk = (dir) => {
60
+ for (const name of fs_1.default.readdirSync(dir)) {
61
+ const full = path_1.default.join(dir, name);
62
+ if (fs_1.default.statSync(full).isDirectory())
63
+ walk(full);
64
+ else
65
+ files.push(full);
66
+ }
67
+ };
68
+ walk(patternsDir);
69
+ const hash = (0, crypto_1.createHash)("sha256");
70
+ for (const file of files.map((f) => path_1.default.relative(patternsDir, f).split(path_1.default.sep).join("/")).sort()) {
71
+ hash.update(`${file}\0`);
72
+ hash.update(fs_1.default.readFileSync(path_1.default.join(patternsDir, file)));
73
+ hash.update("\0");
74
+ }
75
+ return `sha256:${hash.digest("hex").slice(0, 16)}`;
76
+ }
77
+ /**
78
+ * The bundled scanner (dist/vendor/scanner, written by scripts/vendor-scanner.mjs) records its
79
+ * commit and catalog hash. Running from source (tests), the installed scanner package is used.
80
+ */
81
+ function scannerBuildInfo(cliPackageRoot, pinnedCommit) {
82
+ // The build copies package.json into dist/, so the root found from dist/src may be dist/ itself.
83
+ for (const vendored of [path_1.default.join(cliPackageRoot, "dist", "vendor", "scanner"), path_1.default.join(cliPackageRoot, "vendor", "scanner")]) {
84
+ const manifest = path_1.default.join(vendored, "package.json");
85
+ if (!fs_1.default.existsSync(manifest))
86
+ continue;
87
+ const info = JSON.parse(fs_1.default.readFileSync(manifest, "utf8"));
88
+ if (info.gitHead && info.catalogHash)
89
+ return { scannerCommit: info.gitHead, catalogHash: info.catalogHash };
90
+ }
91
+ const installed = path_1.default.join(cliPackageRoot, "node_modules", "@dataparade", "scanner", "patterns");
92
+ return { scannerCommit: pinnedCommit, catalogHash: fs_1.default.existsSync(installed) ? catalogHash(installed) : "unknown" };
93
+ }
94
+ /** The @dataparade/cli package root, from a file inside it (src/ when run from source, dist/src/ when built). */
95
+ function findCliPackageRoot(start) {
96
+ let dir = start;
97
+ for (;;) {
98
+ const manifest = path_1.default.join(dir, "package.json");
99
+ if (fs_1.default.existsSync(manifest)) {
100
+ try {
101
+ if (JSON.parse(fs_1.default.readFileSync(manifest, "utf8")).name === "@dataparade/cli")
102
+ return dir;
103
+ }
104
+ catch {
105
+ // keep looking
106
+ }
107
+ }
108
+ const parent = path_1.default.dirname(dir);
109
+ if (parent === dir)
110
+ return start;
111
+ dir = parent;
112
+ }
113
+ }
114
+ /** realpath of a path that may not exist yet: the nearest existing ancestor, resolved, plus the rest. */
115
+ function realpathOfNearest(target) {
116
+ let dir = path_1.default.resolve(target);
117
+ const rest = [];
118
+ while (!fs_1.default.existsSync(dir)) {
119
+ rest.unshift(path_1.default.basename(dir));
120
+ const parent = path_1.default.dirname(dir);
121
+ if (parent === dir)
122
+ break;
123
+ dir = parent;
124
+ }
125
+ return path_1.default.join(fs_1.default.realpathSync(dir), ...rest);
126
+ }
127
+ function git(cwd, args) {
128
+ return (0, child_process_1.execFileSync)("git", ["-C", cwd, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
129
+ }
130
+ /**
131
+ * Git facts for the scanned folder, read before the scan writes anything. `outputDir` is left
132
+ * out of the dirty check, so the scan's own output never makes a checkout dirty. In a shallow
133
+ * clone the root commit is unknown (null); the repository is then matched by its remote URL.
134
+ * `fallbackCommitSha` comes from --git-context, for scans of archives that have no .git.
135
+ */
136
+ function readGitStamps(scanRoot, outputDir, fallbackCommitSha) {
137
+ try {
138
+ const top = git(scanRoot, ["rev-parse", "--show-toplevel"]);
139
+ const commitSha = git(top, ["rev-parse", "HEAD"]);
140
+ const realTop = fs_1.default.realpathSync(top);
141
+ const realOutput = outputDir ? realpathOfNearest(outputDir) : null;
142
+ const exclude = realOutput && realOutput.startsWith(`${realTop}${path_1.default.sep}`)
143
+ ? [`:(exclude)${path_1.default.relative(realTop, realOutput).split(path_1.default.sep).join("/")}`]
144
+ : [];
145
+ const dirty = git(top, ["status", "--porcelain", "--", ".", ...exclude]) !== "";
146
+ const shallow = git(top, ["rev-parse", "--is-shallow-repository"]) === "true";
147
+ const roots = shallow ? [] : git(top, ["rev-list", "--max-parents=0", "HEAD"]).split("\n").filter(Boolean);
148
+ const relative = path_1.default.relative(fs_1.default.realpathSync(top), fs_1.default.realpathSync(scanRoot)).split(path_1.default.sep).join("/");
149
+ return { commitSha, dirty, rootCommitSha: roots.length > 0 ? roots[roots.length - 1] : null, scanRoot: relative };
150
+ }
151
+ catch {
152
+ return { commitSha: fallbackCommitSha ?? null, dirty: fallbackCommitSha ? false : null, rootCommitSha: null, scanRoot: null };
153
+ }
154
+ }
155
+ function buildScanStamps(input) {
156
+ return {
157
+ scannerCommit: input.scanner.scannerCommit,
158
+ cliVersion: input.cliVersion,
159
+ catalogHash: input.scanner.catalogHash,
160
+ configHash: configHash(input.config),
161
+ aiInference: input.aiInference,
162
+ structureGraph: input.structureGraph,
163
+ ...input.git,
164
+ };
165
+ }
@@ -1,10 +1,3 @@
1
- /**
2
- * The DataParade knowledge base format, schema v1.
3
- *
4
- * A scan writes Facts: components, data flows, data items (with their groups and
5
- * occurrences). People's decisions are Answers, kept apart so a rescan never loses them.
6
- * See docs/cli/scan-output.md.
7
- */
8
1
  import { z } from "zod";
9
2
  export declare const SCHEMA_VERSION: 1;
10
3
  export declare const sourceLocationSchema: z.ZodObject<{
@@ -19,8 +12,54 @@ export declare const codeRefSchema: z.ZodObject<{
19
12
  filePath: z.ZodOptional<z.ZodString>;
20
13
  line: z.ZodOptional<z.ZodNumber>;
21
14
  }, z.core.$strip>;
15
+ /**
16
+ * What a Fact is, independent of the scan that found it (DATAP-842). Two scans of the
17
+ * same code give the same identity, so comparisons match Facts by it.
18
+ *
19
+ * - `key`: the canonical key. For components and flows it is the string the scanner hashes
20
+ * into the id (`cmp_`/`flow_` + 12 hex of sha256). For data items it is the name; for
21
+ * groups, the group id, except that a group named after a declaration
22
+ * (`email@src/a.js:12#email`) drops the line (`email@src/a.js#email`). Keys never contain
23
+ * the scan root or a line number.
24
+ * - `parts`: the values the key is made of, for display and for matching renamed Facts.
25
+ *
26
+ * Duplicate keys (DATAP-845). When several Facts of one kind share a key, the scanner
27
+ * orders them by source position, then by content. The first keeps the key and the plain
28
+ * id; the n-th gets `#n` on the key, `_n` on the id, and `duplicateIndex: n`. A name can
29
+ * itself end in `#<digits>`, so read the number from `duplicateIndex`, never from the key:
30
+ * the base key is the key without `#<duplicateIndex>`. Groups that share a key are
31
+ * numbered by declaration line. Because the order depends on source position, a
32
+ * duplicate's number can change when code moves. Comparisons must match Facts that share
33
+ * a base key as one group,
34
+ * never by their number. Measured on 10 Nov 2026: 0 duplicates in 73 scans of the
35
+ * DataParade monorepo, Saleor and synthetic edits (about 2,100 components, 2,000 flows).
36
+ *
37
+ * Optional only so knowledge bases from CLI 0.0.32 and earlier still read.
38
+ */
39
+ export declare const identitySchema: z.ZodObject<{
40
+ kind: z.ZodEnum<{
41
+ component: "component";
42
+ dataFlow: "dataFlow";
43
+ dataItem: "dataItem";
44
+ group: "group";
45
+ }>;
46
+ key: z.ZodString;
47
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
48
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
49
+ }, z.core.$strip>;
22
50
  export declare const componentFactSchema: z.ZodObject<{
23
51
  id: z.ZodString;
52
+ identity: z.ZodOptional<z.ZodObject<{
53
+ kind: z.ZodEnum<{
54
+ component: "component";
55
+ dataFlow: "dataFlow";
56
+ dataItem: "dataItem";
57
+ group: "group";
58
+ }>;
59
+ key: z.ZodString;
60
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
61
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
62
+ }, z.core.$strip>>;
24
63
  name: z.ZodString;
25
64
  type: z.ZodString;
26
65
  subType: z.ZodString;
@@ -39,6 +78,17 @@ export declare const componentFactSchema: z.ZodObject<{
39
78
  }, z.core.$strip>;
40
79
  export declare const dataFlowFactSchema: z.ZodObject<{
41
80
  id: z.ZodString;
81
+ identity: z.ZodOptional<z.ZodObject<{
82
+ kind: z.ZodEnum<{
83
+ component: "component";
84
+ dataFlow: "dataFlow";
85
+ dataItem: "dataItem";
86
+ group: "group";
87
+ }>;
88
+ key: z.ZodString;
89
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
90
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
91
+ }, z.core.$strip>>;
42
92
  sourceComponentId: z.ZodString;
43
93
  targetComponentId: z.ZodString;
44
94
  type: z.ZodString;
@@ -58,6 +108,17 @@ export declare const dataFlowFactSchema: z.ZodObject<{
58
108
  }, z.core.$strip>;
59
109
  export declare const dataItemGroupSchema: z.ZodObject<{
60
110
  id: z.ZodString;
111
+ identity: z.ZodOptional<z.ZodObject<{
112
+ kind: z.ZodEnum<{
113
+ component: "component";
114
+ dataFlow: "dataFlow";
115
+ dataItem: "dataItem";
116
+ group: "group";
117
+ }>;
118
+ key: z.ZodString;
119
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
120
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
121
+ }, z.core.$strip>>;
61
122
  label: z.ZodString;
62
123
  basis: z.ZodOptional<z.ZodString>;
63
124
  occurrenceCount: z.ZodNumber;
@@ -65,12 +126,34 @@ export declare const dataItemGroupSchema: z.ZodObject<{
65
126
  }, z.core.$strip>;
66
127
  export declare const dataItemSummarySchema: z.ZodObject<{
67
128
  id: z.ZodString;
129
+ identity: z.ZodOptional<z.ZodObject<{
130
+ kind: z.ZodEnum<{
131
+ component: "component";
132
+ dataFlow: "dataFlow";
133
+ dataItem: "dataItem";
134
+ group: "group";
135
+ }>;
136
+ key: z.ZodString;
137
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
138
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
139
+ }, z.core.$strip>>;
68
140
  name: z.ZodString;
69
141
  labels: z.ZodArray<z.ZodString>;
70
142
  occurrenceCount: z.ZodNumber;
71
143
  file: z.ZodString;
72
144
  groups: z.ZodArray<z.ZodObject<{
73
145
  id: z.ZodString;
146
+ identity: z.ZodOptional<z.ZodObject<{
147
+ kind: z.ZodEnum<{
148
+ component: "component";
149
+ dataFlow: "dataFlow";
150
+ dataItem: "dataItem";
151
+ group: "group";
152
+ }>;
153
+ key: z.ZodString;
154
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
155
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
156
+ }, z.core.$strip>>;
74
157
  label: z.ZodString;
75
158
  basis: z.ZodOptional<z.ZodString>;
76
159
  occurrenceCount: z.ZodNumber;
@@ -84,6 +167,29 @@ export declare const relationSchema: z.ZodObject<{
84
167
  confidence: z.ZodOptional<z.ZodString>;
85
168
  basis: z.ZodOptional<z.ZodNullable<z.ZodString>>;
86
169
  }, z.core.$strip>;
170
+ /**
171
+ * Scan stamps (DATAP-876). Two scans can be compared only when their tool stamps are equal,
172
+ * neither had AI enrichment, and neither checkout was dirty (DATAP-877). `structureGraph` says
173
+ * whether Graphify ran; it is information only, because Graphify is optional.
174
+ * - `scannerCommit`, `catalogHash`: the bundled scanner and its pattern catalog.
175
+ * - `configHash`: the settings that change the output (excludes, languages, depths, detection
176
+ * switches, organization domains, minimum confidence, Terraform inputs).
177
+ * - Git: `commitSha`, `dirty`, `rootCommitSha` (null in a shallow clone), and `scanRoot`, the scan
178
+ * root relative to the repository root. All null when the folder is not in Git and no
179
+ * --git-context was given.
180
+ */
181
+ export declare const scanStampsSchema: z.ZodObject<{
182
+ scannerCommit: z.ZodString;
183
+ cliVersion: z.ZodString;
184
+ catalogHash: z.ZodString;
185
+ configHash: z.ZodString;
186
+ aiInference: z.ZodBoolean;
187
+ structureGraph: z.ZodBoolean;
188
+ commitSha: z.ZodNullable<z.ZodString>;
189
+ dirty: z.ZodNullable<z.ZodBoolean>;
190
+ rootCommitSha: z.ZodNullable<z.ZodString>;
191
+ scanRoot: z.ZodNullable<z.ZodString>;
192
+ }, z.core.$strip>;
87
193
  export declare const factsFileSchema: z.ZodObject<{
88
194
  schemaVersion: z.ZodLiteral<1>;
89
195
  scan: z.ZodObject<{
@@ -91,9 +197,32 @@ export declare const factsFileSchema: z.ZodObject<{
91
197
  scannedAt: z.ZodString;
92
198
  cliVersion: z.ZodString;
93
199
  scannerVersion: z.ZodString;
200
+ stamps: z.ZodOptional<z.ZodObject<{
201
+ scannerCommit: z.ZodString;
202
+ cliVersion: z.ZodString;
203
+ catalogHash: z.ZodString;
204
+ configHash: z.ZodString;
205
+ aiInference: z.ZodBoolean;
206
+ structureGraph: z.ZodBoolean;
207
+ commitSha: z.ZodNullable<z.ZodString>;
208
+ dirty: z.ZodNullable<z.ZodBoolean>;
209
+ rootCommitSha: z.ZodNullable<z.ZodString>;
210
+ scanRoot: z.ZodNullable<z.ZodString>;
211
+ }, z.core.$strip>>;
94
212
  }, z.core.$strip>;
95
213
  components: z.ZodArray<z.ZodObject<{
96
214
  id: z.ZodString;
215
+ identity: z.ZodOptional<z.ZodObject<{
216
+ kind: z.ZodEnum<{
217
+ component: "component";
218
+ dataFlow: "dataFlow";
219
+ dataItem: "dataItem";
220
+ group: "group";
221
+ }>;
222
+ key: z.ZodString;
223
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
224
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
225
+ }, z.core.$strip>>;
97
226
  name: z.ZodString;
98
227
  type: z.ZodString;
99
228
  subType: z.ZodString;
@@ -112,6 +241,17 @@ export declare const factsFileSchema: z.ZodObject<{
112
241
  }, z.core.$strip>>;
113
242
  dataFlows: z.ZodArray<z.ZodObject<{
114
243
  id: z.ZodString;
244
+ identity: z.ZodOptional<z.ZodObject<{
245
+ kind: z.ZodEnum<{
246
+ component: "component";
247
+ dataFlow: "dataFlow";
248
+ dataItem: "dataItem";
249
+ group: "group";
250
+ }>;
251
+ key: z.ZodString;
252
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
253
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
254
+ }, z.core.$strip>>;
115
255
  sourceComponentId: z.ZodString;
116
256
  targetComponentId: z.ZodString;
117
257
  type: z.ZodString;
@@ -131,12 +271,34 @@ export declare const factsFileSchema: z.ZodObject<{
131
271
  }, z.core.$strip>>;
132
272
  dataItems: z.ZodArray<z.ZodObject<{
133
273
  id: z.ZodString;
274
+ identity: z.ZodOptional<z.ZodObject<{
275
+ kind: z.ZodEnum<{
276
+ component: "component";
277
+ dataFlow: "dataFlow";
278
+ dataItem: "dataItem";
279
+ group: "group";
280
+ }>;
281
+ key: z.ZodString;
282
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
283
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
284
+ }, z.core.$strip>>;
134
285
  name: z.ZodString;
135
286
  labels: z.ZodArray<z.ZodString>;
136
287
  occurrenceCount: z.ZodNumber;
137
288
  file: z.ZodString;
138
289
  groups: z.ZodArray<z.ZodObject<{
139
290
  id: z.ZodString;
291
+ identity: z.ZodOptional<z.ZodObject<{
292
+ kind: z.ZodEnum<{
293
+ component: "component";
294
+ dataFlow: "dataFlow";
295
+ dataItem: "dataItem";
296
+ group: "group";
297
+ }>;
298
+ key: z.ZodString;
299
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
300
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
301
+ }, z.core.$strip>>;
140
302
  label: z.ZodString;
141
303
  basis: z.ZodOptional<z.ZodString>;
142
304
  occurrenceCount: z.ZodNumber;
@@ -177,10 +339,32 @@ export declare const occurrenceFactSchema: z.ZodObject<{
177
339
  export declare const dataItemFileSchema: z.ZodObject<{
178
340
  schemaVersion: z.ZodLiteral<1>;
179
341
  id: z.ZodString;
342
+ identity: z.ZodOptional<z.ZodObject<{
343
+ kind: z.ZodEnum<{
344
+ component: "component";
345
+ dataFlow: "dataFlow";
346
+ dataItem: "dataItem";
347
+ group: "group";
348
+ }>;
349
+ key: z.ZodString;
350
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
351
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
352
+ }, z.core.$strip>>;
180
353
  name: z.ZodString;
181
354
  labels: z.ZodArray<z.ZodString>;
182
355
  groups: z.ZodArray<z.ZodObject<{
183
356
  id: z.ZodString;
357
+ identity: z.ZodOptional<z.ZodObject<{
358
+ kind: z.ZodEnum<{
359
+ component: "component";
360
+ dataFlow: "dataFlow";
361
+ dataItem: "dataItem";
362
+ group: "group";
363
+ }>;
364
+ key: z.ZodString;
365
+ parts: z.ZodRecord<z.ZodString, z.ZodString>;
366
+ duplicateIndex: z.ZodOptional<z.ZodNumber>;
367
+ }, z.core.$strip>>;
184
368
  label: z.ZodString;
185
369
  basis: z.ZodOptional<z.ZodString>;
186
370
  occurrenceCount: z.ZodNumber;
@@ -228,6 +412,31 @@ export declare const answerSchema: z.ZodObject<{
228
412
  evidence: z.ZodOptional<z.ZodString>;
229
413
  briefSha: z.ZodOptional<z.ZodString>;
230
414
  skillSha: z.ZodOptional<z.ZodString>;
415
+ identityKey: z.ZodOptional<z.ZodString>;
416
+ fingerprint: z.ZodOptional<z.ZodObject<{
417
+ version: z.ZodLiteral<1>;
418
+ subject: z.ZodEnum<{
419
+ component: "component";
420
+ dataFlow: "dataFlow";
421
+ dataItem: "dataItem";
422
+ group: "group";
423
+ }>;
424
+ key: z.ZodString;
425
+ shape: z.ZodObject<{
426
+ type: z.ZodNullable<z.ZodString>;
427
+ subType: z.ZodNullable<z.ZodString>;
428
+ targetScope: z.ZodNullable<z.ZodString>;
429
+ }, z.core.$strip>;
430
+ neighbours: z.ZodNullable<z.ZodObject<{
431
+ source: z.ZodString;
432
+ target: z.ZodString;
433
+ }, z.core.$strip>>;
434
+ handledGroups: z.ZodArray<z.ZodString>;
435
+ }, z.core.$strip>>;
436
+ fingerprintSource: z.ZodOptional<z.ZodEnum<{
437
+ landed: "landed";
438
+ migrated: "migrated";
439
+ }>>;
231
440
  }, z.core.$strip>;
232
441
  export declare const answersFileSchema: z.ZodObject<{
233
442
  schemaVersion: z.ZodLiteral<1>;
@@ -249,8 +458,35 @@ export declare const answersFileSchema: z.ZodObject<{
249
458
  evidence: z.ZodOptional<z.ZodString>;
250
459
  briefSha: z.ZodOptional<z.ZodString>;
251
460
  skillSha: z.ZodOptional<z.ZodString>;
461
+ identityKey: z.ZodOptional<z.ZodString>;
462
+ fingerprint: z.ZodOptional<z.ZodObject<{
463
+ version: z.ZodLiteral<1>;
464
+ subject: z.ZodEnum<{
465
+ component: "component";
466
+ dataFlow: "dataFlow";
467
+ dataItem: "dataItem";
468
+ group: "group";
469
+ }>;
470
+ key: z.ZodString;
471
+ shape: z.ZodObject<{
472
+ type: z.ZodNullable<z.ZodString>;
473
+ subType: z.ZodNullable<z.ZodString>;
474
+ targetScope: z.ZodNullable<z.ZodString>;
475
+ }, z.core.$strip>;
476
+ neighbours: z.ZodNullable<z.ZodObject<{
477
+ source: z.ZodString;
478
+ target: z.ZodString;
479
+ }, z.core.$strip>>;
480
+ handledGroups: z.ZodArray<z.ZodString>;
481
+ }, z.core.$strip>>;
482
+ fingerprintSource: z.ZodOptional<z.ZodEnum<{
483
+ landed: "landed";
484
+ migrated: "migrated";
485
+ }>>;
252
486
  }, z.core.$strip>>;
253
487
  }, z.core.$strip>;
488
+ export type Identity = z.infer<typeof identitySchema>;
489
+ export type ScanStamps = z.infer<typeof scanStampsSchema>;
254
490
  export type SourceLocation = z.infer<typeof sourceLocationSchema>;
255
491
  export type CodeRef = z.infer<typeof codeRefSchema>;
256
492
  export type ComponentFact = z.infer<typeof componentFactSchema>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.answersFileSchema = exports.answerSchema = exports.dataItemFileSchema = exports.occurrenceFactSchema = exports.factsFileSchema = exports.relationSchema = exports.dataItemSummarySchema = exports.dataItemGroupSchema = exports.dataFlowFactSchema = exports.componentFactSchema = exports.codeRefSchema = exports.sourceLocationSchema = exports.SCHEMA_VERSION = void 0;
3
+ exports.answersFileSchema = exports.answerSchema = exports.dataItemFileSchema = exports.occurrenceFactSchema = exports.factsFileSchema = exports.scanStampsSchema = exports.relationSchema = exports.dataItemSummarySchema = exports.dataItemGroupSchema = exports.dataFlowFactSchema = exports.componentFactSchema = exports.identitySchema = exports.codeRefSchema = exports.sourceLocationSchema = exports.SCHEMA_VERSION = void 0;
4
4
  /**
5
5
  * The DataParade knowledge base format, schema v1.
6
6
  *
@@ -8,6 +8,7 @@ exports.answersFileSchema = exports.answerSchema = exports.dataItemFileSchema =
8
8
  * occurrences). People's decisions are Answers, kept apart so a rescan never loses them.
9
9
  * See docs/cli/scan-output.md.
10
10
  */
11
+ const kb_compare_1 = require("../../vendor/kb-compare/dist/src/index.js");
11
12
  const zod_1 = require("zod");
12
13
  exports.SCHEMA_VERSION = 1;
13
14
  exports.sourceLocationSchema = zod_1.z.object({
@@ -22,8 +23,39 @@ exports.codeRefSchema = zod_1.z.object({
22
23
  filePath: zod_1.z.string().optional(),
23
24
  line: zod_1.z.number().optional(),
24
25
  });
26
+ /**
27
+ * What a Fact is, independent of the scan that found it (DATAP-842). Two scans of the
28
+ * same code give the same identity, so comparisons match Facts by it.
29
+ *
30
+ * - `key`: the canonical key. For components and flows it is the string the scanner hashes
31
+ * into the id (`cmp_`/`flow_` + 12 hex of sha256). For data items it is the name; for
32
+ * groups, the group id, except that a group named after a declaration
33
+ * (`email@src/a.js:12#email`) drops the line (`email@src/a.js#email`). Keys never contain
34
+ * the scan root or a line number.
35
+ * - `parts`: the values the key is made of, for display and for matching renamed Facts.
36
+ *
37
+ * Duplicate keys (DATAP-845). When several Facts of one kind share a key, the scanner
38
+ * orders them by source position, then by content. The first keeps the key and the plain
39
+ * id; the n-th gets `#n` on the key, `_n` on the id, and `duplicateIndex: n`. A name can
40
+ * itself end in `#<digits>`, so read the number from `duplicateIndex`, never from the key:
41
+ * the base key is the key without `#<duplicateIndex>`. Groups that share a key are
42
+ * numbered by declaration line. Because the order depends on source position, a
43
+ * duplicate's number can change when code moves. Comparisons must match Facts that share
44
+ * a base key as one group,
45
+ * never by their number. Measured on 10 Nov 2026: 0 duplicates in 73 scans of the
46
+ * DataParade monorepo, Saleor and synthetic edits (about 2,100 components, 2,000 flows).
47
+ *
48
+ * Optional only so knowledge bases from CLI 0.0.32 and earlier still read.
49
+ */
50
+ exports.identitySchema = zod_1.z.object({
51
+ kind: zod_1.z.enum(["component", "dataFlow", "dataItem", "group"]),
52
+ key: zod_1.z.string(),
53
+ parts: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
54
+ duplicateIndex: zod_1.z.number().int().min(2).optional(),
55
+ });
25
56
  exports.componentFactSchema = zod_1.z.object({
26
57
  id: zod_1.z.string(),
58
+ identity: exports.identitySchema.optional(),
27
59
  name: zod_1.z.string(),
28
60
  type: zod_1.z.string(),
29
61
  subType: zod_1.z.string(),
@@ -33,6 +65,7 @@ exports.componentFactSchema = zod_1.z.object({
33
65
  });
34
66
  exports.dataFlowFactSchema = zod_1.z.object({
35
67
  id: zod_1.z.string(),
68
+ identity: exports.identitySchema.optional(),
36
69
  sourceComponentId: zod_1.z.string(),
37
70
  targetComponentId: zod_1.z.string(),
38
71
  type: zod_1.z.string(),
@@ -43,6 +76,7 @@ exports.dataFlowFactSchema = zod_1.z.object({
43
76
  });
44
77
  exports.dataItemGroupSchema = zod_1.z.object({
45
78
  id: zod_1.z.string(),
79
+ identity: exports.identitySchema.optional(),
46
80
  label: zod_1.z.string(),
47
81
  /** The evidence that named the group (column, record-key, name, ...). */
48
82
  basis: zod_1.z.string().optional(),
@@ -51,6 +85,7 @@ exports.dataItemGroupSchema = zod_1.z.object({
51
85
  });
52
86
  exports.dataItemSummarySchema = zod_1.z.object({
53
87
  id: zod_1.z.string(),
88
+ identity: exports.identitySchema.optional(),
54
89
  name: zod_1.z.string(),
55
90
  labels: zod_1.z.array(zod_1.z.string()),
56
91
  occurrenceCount: zod_1.z.number(),
@@ -65,6 +100,29 @@ exports.relationSchema = zod_1.z.object({
65
100
  confidence: zod_1.z.string().optional(),
66
101
  basis: zod_1.z.string().nullable().optional(),
67
102
  });
103
+ /**
104
+ * Scan stamps (DATAP-876). Two scans can be compared only when their tool stamps are equal,
105
+ * neither had AI enrichment, and neither checkout was dirty (DATAP-877). `structureGraph` says
106
+ * whether Graphify ran; it is information only, because Graphify is optional.
107
+ * - `scannerCommit`, `catalogHash`: the bundled scanner and its pattern catalog.
108
+ * - `configHash`: the settings that change the output (excludes, languages, depths, detection
109
+ * switches, organization domains, minimum confidence, Terraform inputs).
110
+ * - Git: `commitSha`, `dirty`, `rootCommitSha` (null in a shallow clone), and `scanRoot`, the scan
111
+ * root relative to the repository root. All null when the folder is not in Git and no
112
+ * --git-context was given.
113
+ */
114
+ exports.scanStampsSchema = zod_1.z.object({
115
+ scannerCommit: zod_1.z.string(),
116
+ cliVersion: zod_1.z.string(),
117
+ catalogHash: zod_1.z.string(),
118
+ configHash: zod_1.z.string(),
119
+ aiInference: zod_1.z.boolean(),
120
+ structureGraph: zod_1.z.boolean(),
121
+ commitSha: zod_1.z.string().nullable(),
122
+ dirty: zod_1.z.boolean().nullable(),
123
+ rootCommitSha: zod_1.z.string().nullable(),
124
+ scanRoot: zod_1.z.string().nullable(),
125
+ });
68
126
  exports.factsFileSchema = zod_1.z.object({
69
127
  schemaVersion: zod_1.z.literal(exports.SCHEMA_VERSION),
70
128
  scan: zod_1.z.object({
@@ -72,6 +130,8 @@ exports.factsFileSchema = zod_1.z.object({
72
130
  scannedAt: zod_1.z.string(),
73
131
  cliVersion: zod_1.z.string(),
74
132
  scannerVersion: zod_1.z.string(),
133
+ /** Absent in scans from CLI 0.0.32 and earlier; such scans cannot be compared. */
134
+ stamps: exports.scanStampsSchema.optional(),
75
135
  }),
76
136
  components: zod_1.z.array(exports.componentFactSchema),
77
137
  dataFlows: zod_1.z.array(exports.dataFlowFactSchema),
@@ -96,6 +156,7 @@ exports.occurrenceFactSchema = zod_1.z.object({
96
156
  exports.dataItemFileSchema = zod_1.z.object({
97
157
  schemaVersion: zod_1.z.literal(exports.SCHEMA_VERSION),
98
158
  id: zod_1.z.string(),
159
+ identity: exports.identitySchema.optional(),
99
160
  name: zod_1.z.string(),
100
161
  labels: zod_1.z.array(zod_1.z.string()),
101
162
  groups: zod_1.z.array(exports.dataItemGroupSchema),
@@ -115,6 +176,15 @@ exports.answerSchema = zod_1.z.object({
115
176
  /** Interview answers: the KB snapshot the question was asked from, and the interview skill. */
116
177
  briefSha: zod_1.z.string().optional(),
117
178
  skillSha: zod_1.z.string().optional(),
179
+ /**
180
+ * The answer's element by identity (DATAP-873): its `identity.key`, or `dp:a0/system` for an
181
+ * answer about the whole system. Lets a later scan find the element after its id changes.
182
+ */
183
+ identityKey: zod_1.z.string().optional(),
184
+ /** The element's evidence fingerprint when the answer was given (kb-compare `fingerprintSchema`). */
185
+ fingerprint: kb_compare_1.fingerprintSchema.optional(),
186
+ /** `landed`: computed when the answer was landed. `migrated`: added later from the cited brief and a later scan. */
187
+ fingerprintSource: zod_1.z.enum(["landed", "migrated"]).optional(),
118
188
  });
119
189
  exports.answersFileSchema = zod_1.z.object({
120
190
  schemaVersion: zod_1.z.literal(exports.SCHEMA_VERSION),