@dataparade/cli 0.0.32 → 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 (100) hide show
  1. package/README.md +56 -1
  2. package/dist/package.json +4 -3
  3. package/dist/src/cli.js +47 -4
  4. package/dist/src/diff/register-diff-command.d.ts +4 -0
  5. package/dist/src/diff/register-diff-command.js +79 -0
  6. package/dist/src/diff/run-diff.d.ts +80 -0
  7. package/dist/src/diff/run-diff.js +206 -0
  8. package/dist/src/diff/upload-diff.d.ts +26 -0
  9. package/dist/src/diff/upload-diff.js +69 -0
  10. package/dist/src/facts/apply-answers.js +1 -1
  11. package/dist/src/facts/build-facts.d.ts +3 -1
  12. package/dist/src/facts/build-facts.js +10 -1
  13. package/dist/src/facts/identity.d.ts +27 -0
  14. package/dist/src/facts/identity.js +203 -0
  15. package/dist/src/facts/io.d.ts +2 -0
  16. package/dist/src/facts/io.js +7 -0
  17. package/dist/src/facts/scan-stamps.d.ts +55 -0
  18. package/dist/src/facts/scan-stamps.js +165 -0
  19. package/dist/src/facts/schema.d.ts +243 -7
  20. package/dist/src/facts/schema.js +71 -1
  21. package/dist/src/kb/answer-fingerprint.d.ts +44 -0
  22. package/dist/src/kb/answer-fingerprint.js +173 -0
  23. package/dist/src/kb/brief.d.ts +8 -1
  24. package/dist/src/kb/brief.js +18 -2
  25. package/dist/src/kb/land.js +3 -0
  26. package/dist/src/kb/register-kb-commands.js +7 -1
  27. package/dist/src/output/git-context.d.ts +8 -0
  28. package/dist/src/output/git-context.js +18 -0
  29. package/dist/src/output/scan-output-excludes.js +5 -1
  30. package/dist/src/output/write-scan-knowledge.d.ts +2 -0
  31. package/dist/src/output/write-scan-knowledge.js +1 -0
  32. package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
  33. package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
  34. package/dist/src/platform-api/upload-client.d.ts +1 -1
  35. package/dist/src/platform-api/upload-client.js +32 -1
  36. package/dist/src/platform-api/upload.types.d.ts +55 -0
  37. package/dist/src/sensitive-scan/process.d.ts +5 -0
  38. package/dist/src/sensitive-scan/process.js +48 -0
  39. package/dist/src/sensitive-scan/project.d.ts +12 -0
  40. package/dist/src/sensitive-scan/project.js +177 -0
  41. package/dist/src/sensitive-scan/report.d.ts +50 -0
  42. package/dist/src/sensitive-scan/report.js +32 -0
  43. package/dist/src/sensitive-scan/sessions.d.ts +2 -0
  44. package/dist/src/sensitive-scan/sessions.js +120 -0
  45. package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
  46. package/dist/src/ui/scan-progress-renderer.js +8 -0
  47. package/dist/src/upload/build-preview-url.d.ts +2 -2
  48. package/dist/src/upload/build-preview-url.js +4 -4
  49. package/dist/src/upload/run-upload.js +6 -2
  50. package/dist/src/upload/types.d.ts +2 -0
  51. package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
  52. package/dist/tests/unit/diff/run-diff.spec.js +189 -0
  53. package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
  54. package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
  55. package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
  56. package/dist/tests/unit/facts/build-facts.spec.js +67 -1
  57. package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
  58. package/dist/tests/unit/facts/identity.spec.js +148 -0
  59. package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
  60. package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
  61. package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
  62. package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
  63. package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
  64. package/dist/tests/unit/output/git-context.spec.js +19 -0
  65. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
  66. package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
  67. package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
  68. package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
  69. package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
  70. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
  71. package/dist/tests/unit/upload/run-upload.spec.js +32 -0
  72. package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
  73. package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
  74. package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
  75. package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
  76. package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
  77. package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
  78. package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
  79. package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
  80. package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
  81. package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
  82. package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
  83. package/dist/vendor/kb-compare/dist/src/index.js +34 -0
  84. package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
  85. package/dist/vendor/kb-compare/dist/src/input.js +75 -0
  86. package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
  87. package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
  88. package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
  89. package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
  90. package/dist/vendor/kb-compare/package.json +6 -0
  91. package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
  92. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
  93. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
  94. package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
  95. package/dist/vendor/scanner/dist/src/index.js +4 -2
  96. package/dist/vendor/scanner/package.json +3 -1
  97. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +10 -0
  98. package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
  99. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +25 -0
  100. package/package.json +4 -3
@@ -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),
@@ -0,0 +1,44 @@
1
+ import { type Fingerprint } from "../../vendor/kb-compare/dist/src/index.js";
2
+ import type { Answer, FactsFile } from "../facts/schema";
3
+ import { type KbPaths } from "./kb-store";
4
+ /**
5
+ * Identity keys and evidence fingerprints on answers (DATAP-873).
6
+ *
7
+ * Each answer records the identity key of its element and the element's fingerprint at the
8
+ * time of the answer, so the slot rules (DATAP-874) can find the element in a later scan and
9
+ * decide whether the answer still holds. Answers about the whole system (`dp:a0/system`) keep
10
+ * that URI as their key and have no fingerprint: no element change can make them stale.
11
+ */
12
+ export type AnswerSubject = Fingerprint["subject"];
13
+ export interface AnswerElement {
14
+ subject: AnswerSubject;
15
+ key: string;
16
+ }
17
+ /** The element a Fact id names in a scan, by its identity. Null when the scan has no such Fact or it has no identity. */
18
+ export declare function elementOfFact(facts: FactsFile, factId: string): AnswerElement | null;
19
+ /** Identity key and fingerprint fields for an answer about `factId`, from the scan it was given against. */
20
+ export declare function fingerprintFields(facts: FactsFile, factId: string): Pick<Answer, "identityKey" | "fingerprint" | "fingerprintSource">;
21
+ export type MigrationOutcome = "brief" | "scan" | "root" | "system" | "unresolved";
22
+ export interface MigrateFingerprintsResult {
23
+ /** Answers given an identity key (and a fingerprint where the element is in the current scan). */
24
+ migrated: number;
25
+ /** Answers that already had an identity key. */
26
+ alreadyKeyed: number;
27
+ /** How each migrated or unresolved answer found its element, by answer id. */
28
+ outcomes: Record<string, MigrationOutcome>;
29
+ /** Answers with a key whose element is not in the current scan: they keep the key and have no fingerprint. */
30
+ withoutFingerprint: string[];
31
+ /** Answers no brief or scan could key. */
32
+ unresolved: string[];
33
+ dryRun: boolean;
34
+ }
35
+ /**
36
+ * Give each answer without an identity key its key and a fingerprint (`fingerprintSource:
37
+ * migrated`). The key comes from the brief the answer cites; failing that, from the Fact with
38
+ * the same id in the current scan; failing that, for the root Application whose id changed
39
+ * once (DATAP-858), from the project-name token. The fingerprint is computed from the current
40
+ * scan. Answers on occurrences stay unkeyed: they are outside the carry rules (DATAP-862).
41
+ */
42
+ export declare function migrateAnswerFingerprints(paths: KbPaths, options?: {
43
+ dryRun?: boolean;
44
+ }): MigrateFingerprintsResult;