@dataparade/cli 0.0.26 → 0.0.28

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 (108) hide show
  1. package/README.md +52 -12
  2. package/dist/package.json +7 -7
  3. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
  4. package/dist/src/cli.js +37 -37
  5. package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
  6. package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
  7. package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
  8. package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
  9. package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
  10. package/dist/src/evals/run-model-matrix.js +0 -1
  11. package/dist/src/export/export-ocsf.d.ts +18 -0
  12. package/dist/src/export/export-ocsf.js +104 -0
  13. package/dist/src/export/register-export-commands.d.ts +2 -0
  14. package/dist/src/export/register-export-commands.js +30 -0
  15. package/dist/src/facts/apply-answers.d.ts +29 -0
  16. package/dist/src/facts/apply-answers.js +202 -0
  17. package/dist/src/facts/build-facts.d.ts +24 -0
  18. package/dist/src/facts/build-facts.js +198 -0
  19. package/dist/src/facts/io.d.ts +17 -0
  20. package/dist/src/facts/io.js +67 -0
  21. package/dist/src/facts/layout.d.ts +29 -0
  22. package/dist/src/facts/layout.js +38 -0
  23. package/dist/src/facts/schema.d.ts +265 -0
  24. package/dist/src/facts/schema.js +122 -0
  25. package/dist/src/facts/slug.d.ts +7 -0
  26. package/dist/src/facts/slug.js +47 -0
  27. package/dist/src/kb/brief.d.ts +1 -2
  28. package/dist/src/kb/brief.js +2 -4
  29. package/dist/src/kb/interview-record.d.ts +18 -0
  30. package/dist/src/kb/interview-record.js +70 -0
  31. package/dist/src/kb/kb-store.d.ts +24 -18
  32. package/dist/src/kb/kb-store.js +89 -28
  33. package/dist/src/kb/land.d.ts +32 -12
  34. package/dist/src/kb/land.js +97 -90
  35. package/dist/src/kb/migrate.d.ts +23 -0
  36. package/dist/src/kb/migrate.js +91 -0
  37. package/dist/src/kb/project-diagram.js +4 -4
  38. package/dist/src/kb/register-kb-commands.js +71 -20
  39. package/dist/src/observability/scan-sentry.js +0 -1
  40. package/dist/src/output/scan-output-excludes.d.ts +1 -1
  41. package/dist/src/output/scan-output-excludes.js +14 -5
  42. package/dist/src/output/write-scan-knowledge.d.ts +33 -0
  43. package/dist/src/output/write-scan-knowledge.js +115 -0
  44. package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
  45. package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
  46. package/dist/src/ui/scan-progress-renderer.d.ts +2 -0
  47. package/dist/src/ui/scan-progress-renderer.js +10 -0
  48. package/dist/src/ui/teaching-lines.js +18 -6
  49. package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
  50. package/dist/src/upload/collect-scan-sidecars.js +25 -121
  51. package/dist/src/upload/run-upload.js +0 -3
  52. package/dist/tests/cli/cli.spec.js +30 -13
  53. package/dist/tests/helpers/facts-fixture.d.ts +9 -0
  54. package/dist/tests/helpers/facts-fixture.js +72 -0
  55. package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
  56. package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
  57. package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
  58. package/dist/tests/unit/facts/build-facts.spec.js +161 -0
  59. package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
  60. package/dist/tests/unit/facts/slug.spec.js +30 -0
  61. package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
  62. package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
  63. package/dist/tests/unit/kb/migrate.spec.js +108 -0
  64. package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
  65. package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
  66. package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
  67. package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
  68. package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
  69. package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
  70. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
  71. package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
  72. package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
  73. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
  74. package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
  75. package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
  76. package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
  77. package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
  78. package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
  79. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
  80. package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
  81. package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
  82. package/dist/vendor/scanner/dist/src/index.js +7 -2
  83. package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
  84. package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
  85. package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
  86. package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
  87. package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
  88. package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
  89. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
  90. package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
  91. package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
  92. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
  93. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
  94. package/package.json +7 -7
  95. package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
  96. package/dist/src/discoveries/project-collected-diagram.js +0 -182
  97. package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
  98. package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
  99. package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
  100. package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
  101. package/dist/src/output/write-knowledge-graph.d.ts +0 -20
  102. package/dist/src/output/write-knowledge-graph.js +0 -53
  103. package/dist/src/output/write-scan-discoveries.d.ts +0 -17
  104. package/dist/src/output/write-scan-discoveries.js +0 -61
  105. package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
  106. package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
  107. /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
  108. /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → facts/apply-answers.spec.d.ts} +0 -0
package/README.md CHANGED
@@ -12,35 +12,40 @@ The **dataPARADE CLI** (`@dataparade/cli`) scans a codebase and produces a **`da
12
12
 
13
13
  ## Quick start
14
14
 
15
+ Install the CLI and check that it runs:
16
+
15
17
  ```bash
16
- npx @dataparade/cli scan .
18
+ npm install -g @dataparade/cli
19
+ dataparade --help
17
20
  ```
18
21
 
19
- Or with pnpm:
22
+ Then scan your project from its root folder:
20
23
 
21
24
  ```bash
22
- pnpm dlx @dataparade/cli scan .
25
+ dataparade scan .
23
26
  ```
24
27
 
28
+ A scan reads the source and config files under the folder (skipping dependencies, build output and anything in `.gitignore`) and uploads the result to the dataPARADE web app unless you pass `--skip-auto-upload`.
29
+
25
30
  **What to expect:**
26
31
 
27
32
  - In a TTY: brand header, staged progress (spinner → checkmarks), a short **What we found** summary (routes, databases, outbound services), and a clear next-step note.
28
33
  - In CI / non-TTY (or with `NO_COLOR`): the same content as plain logs — no spinners or ANSI.
29
34
  - On success: `[scan] dataflow.json written to /absolute/path/to/dataflow.json` (always printed for scripts/tests).
30
35
  - When auto-upload runs: `[scan] Preview ready: <URL>` (plus a friendly next-step note with the same URL).
31
- - By default, `dataflow.json` is created in the **current working directory** (override with `-o` / `--output`).
36
+ - By default, the output goes to a **`.dataparade/`** folder in the current working directory (override the path of `dataflow.json` with `-o` / `--output`; the other files sit next to it).
32
37
 
33
38
  ```bash
34
- npx @dataparade/cli scan path/to/your/project --output scan-my-project-dataflow.json
39
+ dataparade scan path/to/your/project --output scan-my-project-dataflow.json
35
40
  ```
36
41
 
37
- List commands and options: `npx @dataparade/cli --help` and `npx @dataparade/cli scan --help`.
42
+ List commands and options: `dataparade --help` and `dataparade scan --help`.
38
43
 
39
44
  ---
40
45
 
41
46
  ## Upload to dashboard
42
47
 
43
- After a scan, the CLI **auto-uploads** `dataflow.json` by default (unless you opt out). This creates an **import preview draft** in the web app — not a finished assessment.
48
+ After a scan, the CLI **auto-uploads** `dataflow.json` and the Facts next to it by default (unless you opt out). This creates an **import preview draft** in the web app — not a finished assessment.
44
49
 
45
50
  - **With a workspace API key** (`DATAPARADE_WORKSPACE_API_KEY` from **Workspace → Access keys**): prints a dashboard link (`?importDraft=`) for that workspace.
46
51
  - **Without a workspace key**: prints a sign-up link (`/preview/cli/<token>`). Create an account to open **Preview & Edit** on your dashboard.
@@ -48,25 +53,60 @@ After a scan, the CLI **auto-uploads** `dataflow.json` by default (unless you op
48
53
  - Upload alone does **not** consume scan quota
49
54
 
50
55
  ```bash
51
- npx @dataparade/cli upload ./dataflow.json --project-name "My service"
56
+ npx @dataparade/cli upload .dataparade/dataflow.json --project-name "My service"
52
57
  ```
53
58
 
54
59
  **Full guide:** [Upload to dashboard](https://app.dataparade.io/docs/cli-import-and-zip/upload)
55
60
 
56
61
  ---
57
62
 
58
- ## Output: `dataflow.json`
63
+ ## Output: `.dataparade/`
64
+
65
+ By default, a scan writes these files to `./.dataparade/`:
66
+
67
+ | File | What it is |
68
+ | --- | --- |
69
+ | `dataflow.json` | The diagram the web app imports: a wrapper with `schemaVersion`, `graph` (`DiagramGraphJson`: nodes, edges, viewport) and `metadata` (files scanned, duration, C4 `hierarchy`, etc.). |
70
+ | `facts.json` | What the latest scan found: components, data flows, data items (with groups) and the links between them. Replaced on every scan. |
71
+ | `data-items/<name>.json` | One file per data item, with every place it occurs in the code. |
72
+ | `graphify.json` | The code-structure graph from [Graphify](https://github.com/Graphify-Labs/graphify), when it is installed. |
73
+ | `answers.json` | People's decisions (interview answers, reviews). A scan never writes or changes it. |
74
+
75
+ `-o` / `--output` is the path of `dataflow.json`; the other files go in the same folder. Scans skip this folder, so rescanning does not read old output. Commit `answers.json` with your code; the rest can be regenerated.
76
+
77
+ Graphify's cache lives outside the output, in `~/.cache/dataparade/graphify/` (set `DATAPARADE_CACHE_DIR` to move it).
78
+
79
+ Interview and review commands work on this folder:
80
+
81
+ ```bash
82
+ npx @dataparade/cli kb brief # open interview questions
83
+ npx @dataparade/cli kb land ... # save a confirmed answer to answers.json
84
+ npx @dataparade/cli kb migrate # import answers from an old ocsf-discoveries/ folder
85
+ npx @dataparade/cli export ocsf --out ocsf # write OCSF records from facts + answers
86
+ ```
59
87
 
60
- By default, the CLI writes `./dataflow.json` in the current working directory.
88
+ Formats, and how answers apply: [docs/cli/scan-output.md](../docs/cli/scan-output.md).
61
89
 
62
- - **Wrapper** with `schemaVersion`, `graph` (`DiagramGraphJson`: nodes, edges, viewport), and `metadata` (files scanned, duration, etc.)
63
- - The `graph` section is compatible with the DataParade import flow
90
+ - The `graph` section of `dataflow.json` is compatible with the DataParade import flow
64
91
  - Most node properties are emitted with `null` defaults; only a subset are filled from code patterns — complete the rest in Preview & Edit
65
92
 
66
93
  **Full guide:** [Output and results](https://app.dataparade.io/docs/cli-import-and-zip/output)
67
94
 
68
95
  ---
69
96
 
97
+ ## Troubleshooting
98
+
99
+ **The scan stops with `FATAL ERROR: ... JavaScript heap out of memory`.** Node ran out of memory on a very large tree. At the start of each scan the CLI prints how many files it will read and, for a large tree, names the biggest folders. Skip folders that hold no application code, and if needed give Node more memory:
100
+
101
+ ```bash
102
+ dataparade scan . --exclude 'public/**' 'generated/**'
103
+ NODE_OPTIONS=--max-old-space-size=8192 dataparade scan .
104
+ ```
105
+
106
+ Dependencies, build output and anything in `.gitignore` are skipped already.
107
+
108
+ ---
109
+
70
110
  ## Documentation
71
111
 
72
112
  | Topic | Link |
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataparade/cli",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "dataPARADE CLI — scan codebases for privacy and security data flows",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -56,9 +56,9 @@
56
56
  "dependencies": {
57
57
  "@clack/prompts": "^1.8.1",
58
58
  "@sentry/node": "^10.38.0",
59
- "commander": "^12.1.0",
59
+ "commander": "^14.0.3",
60
60
  "dotenv": "^16.4.7",
61
- "langsmith": "^0.3.14",
61
+ "langsmith": "^0.10.13",
62
62
  "tree-sitter-wasms": "^0.1.13",
63
63
  "typescript": "^5.7.3",
64
64
  "web-tree-sitter": "0.25.10",
@@ -66,14 +66,14 @@
66
66
  "zod": "^4.3.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@dataparade/scanner": "github:DataParade-io/scanner#0b1a31e7444acbf1e43d800e26a37746f11e7232",
69
+ "@dataparade/scanner": "github:DataParade-io/scanner#a08a57b046b7b6be0afd84b7866432e6242d216a",
70
70
  "@eslint/js": "^9.18.0",
71
- "@types/jest": "^29.5.14",
71
+ "@types/jest": "^30.0.0",
72
72
  "@types/node": "^22.0.0",
73
73
  "eslint": "^9.18.0",
74
74
  "globals": "^15.14.0",
75
- "jest": "^29.7.0",
76
- "ts-jest": "^29.2.5",
75
+ "jest": "^30.5.2",
76
+ "ts-jest": "^29.4.6",
77
77
  "typescript-eslint": "^8.20.0"
78
78
  },
79
79
  "files": [
@@ -95,7 +95,6 @@ class PlatformProxyProvider {
95
95
  if (attempt >= delays.length || !(0, fetch_failure_1.isTransientFetchError)(err)) {
96
96
  throw (0, fetch_failure_1.toApiReachabilityError)(err, url, method, attempt + 1);
97
97
  }
98
- // eslint-disable-next-line no-console
99
98
  console.warn(`[dataparade-ai] ${(0, fetch_failure_1.describeRequestTarget)(url, method)} failed (${(0, fetch_failure_1.fetchFailureDetail)(err)}). Retrying (${attempt + 1}/${delays.length}).`);
100
99
  await this.wait(delays[attempt] ?? 0);
101
100
  }
package/dist/src/cli.js CHANGED
@@ -43,9 +43,10 @@ const commander_1 = require("commander");
43
43
  const crypto_1 = require("crypto");
44
44
  const package_json_1 = __importDefault(require("../package.json"));
45
45
  const json_1 = require("./output/json");
46
- const write_scan_discoveries_1 = require("./output/write-scan-discoveries");
47
- const write_knowledge_graph_1 = require("./output/write-knowledge-graph");
46
+ const write_scan_knowledge_1 = require("./output/write-scan-knowledge");
47
+ const layout_1 = require("./facts/layout");
48
48
  const register_kb_commands_1 = require("./kb/register-kb-commands");
49
+ const register_export_commands_1 = require("./export/register-export-commands");
49
50
  const scan_output_excludes_1 = require("./output/scan-output-excludes");
50
51
  const dataflow_wrapper_schema_1 = require("./core/schema/dataflow-wrapper.schema");
51
52
  const upload_env_1 = require("./config/upload-env");
@@ -63,6 +64,16 @@ const cli_scan_failure_report_1 = require("./platform-api/cli-scan-failure-repor
63
64
  const scan_config_schema_1 = require("./core/schema/scan-config.schema");
64
65
  const scanner_1 = require("../vendor/scanner/dist/src/index.js");
65
66
  const scan_progress_renderer_1 = require("./ui/scan-progress-renderer");
67
+ /** The scanner is vendored into the CLI; its version is the commit the CLI depends on. */
68
+ function scannerVersionFromPackage() {
69
+ // Built from parts: the vendor step rewrites the scanner's package name in string literals.
70
+ const scannerPackage = ['@dataparade', 'scanner'].join('/');
71
+ const spec = package_json_1.default.devDependencies?.[scannerPackage];
72
+ if (!spec)
73
+ return 'unknown';
74
+ const ref = spec.split('#')[1];
75
+ return ref ? ref.slice(0, 12) : spec;
76
+ }
66
77
  function formatEvidence(detail) {
67
78
  const evidence = detail.evidence;
68
79
  if (!evidence || evidence.length === 0) {
@@ -127,7 +138,7 @@ function createProgram() {
127
138
  program
128
139
  .command('scan <path>')
129
140
  .description('Scan a directory (or a single supported source file) for data flow components')
130
- .option('-o, --output <file>', 'Write dataflow.json wrapper to the given file (default: ./dataflow.json)')
141
+ .option('-o, --output <file>', `Write dataflow.json to the given file; facts.json, data-items/ and graphify.json go next to it (default: ./${layout_1.DEFAULT_DATAFLOW_OUTPUT})`)
131
142
  .option('--exclude <pattern...>', 'One or more glob patterns to exclude from scanning')
132
143
  .option('--minimum-confidence <number>', 'Minimum confidence (0-1) for including detections')
133
144
  .option('--language <language...>', 'Limit scanning to specific languages (e.g. typescript, javascript, python, go, java, kotlin, cpp, csharp, terraform)')
@@ -157,7 +168,7 @@ function createProgram() {
157
168
  .option('--byok-model <model>', 'BYOK model name (env: SCAN_BYOK_MODEL)')
158
169
  .option('--skip-auto-upload', 'Do not upload dataflow.json to the dashboard after scan (env: DATAPARADE_SKIP_AUTO_UPLOAD)')
159
170
  .option('--git-context <json>', 'Git repository context for evidence linking (JSON: {"provider":"github"|"gitlab","repository":"owner/repo","commitSha":"...","baseUrl?":"..."})')
160
- .option('--no-structure-graph', 'Do not write the knowledge graph (graphify-out/graph.json from graphify, when installed, and dataparade-graph.json)')
171
+ .option('--no-structure-graph', 'Do not run graphify (graphify.json is not written, and Facts have no code references)')
161
172
  .action(async (path, options) => {
162
173
  let cliQuotaJobId;
163
174
  let platformQuotaApiKey;
@@ -181,7 +192,6 @@ function createProgram() {
181
192
  const errors = validated.error.issues
182
193
  .map((i) => `${i.path.join('.') || '<root>'}: ${i.message}`)
183
194
  .join('; ');
184
- // eslint-disable-next-line no-console
185
195
  console.error(`[scan] invalid --git-context: ${errors}`);
186
196
  process.exitCode = 2;
187
197
  return;
@@ -190,7 +200,6 @@ function createProgram() {
190
200
  }
191
201
  catch (parseErr) {
192
202
  const message = parseErr instanceof Error ? parseErr.message : 'Invalid JSON';
193
- // eslint-disable-next-line no-console
194
203
  console.error(`[scan] failed to parse --git-context: ${message}`);
195
204
  process.exitCode = 2;
196
205
  return;
@@ -231,7 +240,6 @@ function createProgram() {
231
240
  failurePhase: 'resolve_path',
232
241
  failureCode: 'path_not_found',
233
242
  });
234
- // eslint-disable-next-line no-console
235
243
  console.error(`[scan] error: ${message}`);
236
244
  process.exitCode = 2;
237
245
  return;
@@ -257,7 +265,7 @@ function createProgram() {
257
265
  const flags = {
258
266
  exclude: [
259
267
  ...(options.exclude ?? []),
260
- ...(0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ?? 'dataflow.json')),
268
+ ...(0, scan_output_excludes_1.scanOutputExcludes)(resolvedScanRoot, path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT)),
261
269
  ],
262
270
  minimumConfidence: typeof options.minimumConfidence === 'string'
263
271
  ? Number(options.minimumConfidence)
@@ -346,7 +354,6 @@ function createProgram() {
346
354
  technicalLines.push(quotaLine);
347
355
  }
348
356
  else {
349
- // eslint-disable-next-line no-console
350
357
  console.log(quotaLine);
351
358
  }
352
359
  }
@@ -377,7 +384,6 @@ function createProgram() {
377
384
  technicalLines.push(sessionLine);
378
385
  }
379
386
  else {
380
- // eslint-disable-next-line no-console
381
387
  console.log(sessionLine);
382
388
  }
383
389
  }
@@ -391,7 +397,6 @@ function createProgram() {
391
397
  code: 'anonymous_ai_session_failed',
392
398
  message: (0, cli_scan_failure_report_1.truncateFailureMessage)(message),
393
399
  };
394
- // eslint-disable-next-line no-console
395
400
  console.error(`[scan] ${message}`);
396
401
  process.exitCode =
397
402
  anonSessionError instanceof CliAnonymousIpLimitError ? 2 : 1;
@@ -413,7 +418,6 @@ function createProgram() {
413
418
  failurePhase: 'config_validation',
414
419
  failureCode: 'invalid_configuration',
415
420
  });
416
- // eslint-disable-next-line no-console
417
421
  console.error(`[scan] invalid configuration:\n${configValidation.errors.map((e) => ` - ${e}`).join('\n')}`);
418
422
  process.exitCode = 2;
419
423
  return;
@@ -424,10 +428,16 @@ function createProgram() {
424
428
  progressUi.warn(w);
425
429
  }
426
430
  else {
427
- // eslint-disable-next-line no-console
428
431
  console.warn(`[scan] warnings:\n${warnings.map((w) => ` - ${w}`).join('\n')}`);
429
432
  }
430
433
  }
434
+ {
435
+ const { summarizeScanTree, describeScanTree } = await Promise.resolve().then(() => __importStar(require('./platform-api/estimate-scan-footprint')));
436
+ const tree = describeScanTree(await summarizeScanTree(scanEntry.scanRootDir, config.excludePaths ?? []));
437
+ progressUi.info(tree.line);
438
+ if (tree.warning)
439
+ progressUi.warn(tree.warning);
440
+ }
431
441
  const orchestratorResult = await runScanPipeline(resolvedScanRoot, config, (progress) => {
432
442
  progressUi.onProgress(progress);
433
443
  }, (recognition) => {
@@ -523,16 +533,17 @@ function createProgram() {
523
533
  const message = graphError instanceof Error
524
534
  ? graphError.message
525
535
  : 'Unknown error while building diagram graph.';
526
- // eslint-disable-next-line no-console
527
536
  console.error(`[scan] warning: unable to build diagram graph: ${message}`);
528
537
  }
529
538
  process.exitCode = 1;
530
539
  }
531
540
  if (diagramGraph) {
532
- const dataflowOutputPath = path_1.default.resolve(process.cwd(), options.output ?? 'dataflow.json');
541
+ const dataflowOutputPath = path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT);
533
542
  const resolvedProjectName = config.projectName?.trim() ||
534
543
  path_1.default.basename(scanEntry.scanRootDir);
535
- const hierarchy = await (0, write_knowledge_graph_1.buildScanHierarchy)(orchestratorResult, diagramGraph.nodes.map((node) => node.id));
544
+ const layout = (0, layout_1.resolveOutputLayout)(dataflowOutputPath);
545
+ const knowledge = await (0, write_scan_knowledge_1.prepareScanKnowledge)(orchestratorResult, resolvedScanRoot, layout, { structureGraph: options.structureGraph !== false });
546
+ const hierarchy = (0, write_scan_knowledge_1.buildScanHierarchy)(knowledge.graph, diagramGraph.nodes.map((node) => node.id));
536
547
  try {
537
548
  (0, json_1.writeDataflowJson)({
538
549
  scanResult,
@@ -543,24 +554,21 @@ function createProgram() {
543
554
  gitContext: parsedGitContext,
544
555
  hierarchy,
545
556
  });
546
- const scanDiscoveriesPaths = (0, write_scan_discoveries_1.writeScanDiscoveriesArtifacts)(orchestratorResult, dataflowOutputPath, { scanRootDir: scanEntry.scanRootDir });
557
+ (0, write_scan_knowledge_1.writeScanFacts)(layout, {
558
+ knowledge,
559
+ scanRoot: scanEntry.scanRootDir,
560
+ projectName: resolvedProjectName,
561
+ cliVersion: package_json_1.default.version,
562
+ scannerVersion: scannerVersionFromPackage(),
563
+ });
547
564
  // Friendly TTY/plain progress line (additive).
548
565
  progressUi.onWroteDataflow(dataflowOutputPath);
549
566
  // Machine line for scripts / CI (non-TTY). The friendly TTY UI
550
567
  // shows the path in its own success line instead.
551
568
  if (!friendlyTty) {
552
- // eslint-disable-next-line no-console
553
569
  console.log(`[scan] dataflow.json written to ${dataflowOutputPath}`);
554
570
  }
555
- // eslint-disable-next-line no-console
556
- console.log(`[scan] OCSF discoveries written to ${scanDiscoveriesPaths.ocsfDiscoveriesDir}`);
557
- // eslint-disable-next-line no-console
558
- console.log(`[scan] dataparade.json written to ${scanDiscoveriesPaths.dataparadeJsonPath}`);
559
- // eslint-disable-next-line no-console
560
- console.log(`[scan] discoveries diagram written to ${scanDiscoveriesPaths.collectedDiagramJsonPath}`);
561
- if (options.structureGraph !== false) {
562
- await (0, write_knowledge_graph_1.writeScanKnowledgeGraph)(orchestratorResult, resolvedScanRoot, path_1.default.dirname(dataflowOutputPath));
563
- }
571
+ console.log(`[scan] facts.json and data-items/ written to ${layout.dir}`);
564
572
  const skipAutoUpload = Boolean(options.skipAutoUpload) ||
565
573
  (0, upload_env_1.resolveSkipAutoUpload)(process.env);
566
574
  if (!skipAutoUpload) {
@@ -596,7 +604,6 @@ function createProgram() {
596
604
  progressUi.warn(`Auto-upload failed: ${uploadMessage}`);
597
605
  }
598
606
  else {
599
- // eslint-disable-next-line no-console
600
607
  console.error(`[scan] Auto-upload failed: ${uploadMessage}`);
601
608
  }
602
609
  }
@@ -622,7 +629,6 @@ function createProgram() {
622
629
  const message = dataflowError instanceof Error
623
630
  ? dataflowError.message
624
631
  : 'Unknown error while writing dataflow.json.';
625
- // eslint-disable-next-line no-console
626
632
  console.error(`[scan] error: failed to write dataflow.json: ${message}`);
627
633
  process.exitCode = 1;
628
634
  }
@@ -648,7 +654,6 @@ function createProgram() {
648
654
  quotaCompletionReported = true;
649
655
  // The Clack outro already closes the run in friendly TTY.
650
656
  if (isInteractive && !friendlyTty) {
651
- // eslint-disable-next-line no-console
652
657
  console.log('[scan] Scan finished — you can start a new scan now.');
653
658
  }
654
659
  }
@@ -680,7 +685,6 @@ function createProgram() {
680
685
  ? 'scan_already_running'
681
686
  : 'scan_exception',
682
687
  });
683
- // eslint-disable-next-line no-console
684
688
  console.error(quotaBlocked
685
689
  ? `[scan] workspace quota: ${message}`
686
690
  : scanInProgress
@@ -718,7 +722,6 @@ function createProgram() {
718
722
  });
719
723
  quotaCompletionReported = true;
720
724
  if (isInteractive) {
721
- // eslint-disable-next-line no-console
722
725
  console.log('[scan] Scan finished — you can start a new scan now.');
723
726
  }
724
727
  }
@@ -739,7 +742,7 @@ function createProgram() {
739
742
  options.apiKey?.trim() ||
740
743
  (0, scan_env_1.resolveWorkspaceApiKey)(process.env);
741
744
  const usageSessionId = (0, crypto_1.randomUUID)();
742
- const filePath = path_1.default.resolve(process.cwd(), file || 'dataflow.json');
745
+ const filePath = path_1.default.resolve(process.cwd(), file || layout_1.DEFAULT_DATAFLOW_OUTPUT);
743
746
  let dataflow;
744
747
  try {
745
748
  const { readFileSync } = await Promise.resolve().then(() => __importStar(require('fs')));
@@ -747,7 +750,6 @@ function createProgram() {
747
750
  }
748
751
  catch (err) {
749
752
  const message = err instanceof Error ? err.message : 'Failed to read dataflow.json';
750
- // eslint-disable-next-line no-console
751
753
  console.error(`[upload] error: ${message}`);
752
754
  process.exitCode = 1;
753
755
  return;
@@ -775,7 +777,6 @@ function createProgram() {
775
777
  }
776
778
  catch (err) {
777
779
  const message = err instanceof Error ? err.message : 'Upload failed.';
778
- // eslint-disable-next-line no-console
779
780
  console.error(`[upload] error: ${message}`);
780
781
  process.exitCode = 1;
781
782
  }
@@ -805,19 +806,18 @@ function createProgram() {
805
806
  });
806
807
  const config = createDefaultScanConfiguration(overrides);
807
808
  const displayConfig = (0, redact_1.redactScanConfigurationForDisplay)(config);
808
- // eslint-disable-next-line no-console
809
809
  console.log(JSON.stringify(displayConfig, null, 2));
810
810
  }
811
811
  catch (err) {
812
812
  const message = err instanceof Error
813
813
  ? err.message
814
814
  : 'Unknown error while loading configuration.';
815
- // eslint-disable-next-line no-console
816
815
  console.error('Failed to read configuration:', message);
817
816
  process.exitCode = 1;
818
817
  }
819
818
  });
820
819
  (0, register_kb_commands_1.registerKbCommands)(program);
820
+ (0, register_export_commands_1.registerExportCommands)(program);
821
821
  return program;
822
822
  }
823
823
  async function run(argv) {
@@ -31,8 +31,8 @@ export declare const ocsfDiscoveryRecordSchema: z.ZodObject<{
31
31
  ontology_version: z.ZodLiteral<"0.3.0">;
32
32
  source: z.ZodEnum<{
33
33
  scan: "scan";
34
- cloud: "cloud";
35
34
  interview: "interview";
35
+ cloud: "cloud";
36
36
  }>;
37
37
  asserted_at: z.ZodString;
38
38
  asserts: z.ZodString;
@@ -16,11 +16,3 @@ export interface LoadOcsfDiscoveriesOptions {
16
16
  requiredBriefSha?: string;
17
17
  }
18
18
  export declare function loadOcsfDiscoveriesFromDir(directory: string, options?: LoadOcsfDiscoveriesOptions): LoadedOcsfDiscoveries;
19
- export type DiscoverySlotIndex = Map<string, Map<string, string>>;
20
- /**
21
- * Latest value per (asserts, slot). A record named in another record's
22
- * `supersedes` is a corrected answer and drops out; the rest apply in
23
- * `asserted_at` order (stable, so same-instant records keep load order).
24
- */
25
- export declare function indexDiscoverySlots(records: OcsfDiscoveryRecord[]): DiscoverySlotIndex;
26
- export declare function discoveryValue(index: DiscoverySlotIndex, asserts: string, slot: string): string | undefined;
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.OcsfDiscoveryLoadError = void 0;
7
7
  exports.loadOcsfDiscoveriesFromDir = loadOcsfDiscoveriesFromDir;
8
- exports.indexDiscoverySlots = indexDiscoverySlots;
9
- exports.discoveryValue = discoveryValue;
10
8
  const fs_1 = __importDefault(require("fs"));
11
9
  const path_1 = __importDefault(require("path"));
12
10
  const ocsf_discovery_record_1 = require("./contract/ocsf-discovery-record");
@@ -44,32 +42,3 @@ function loadOcsfDiscoveriesFromDir(directory, options = {}) {
44
42
  }
45
43
  return { directory: resolved, records };
46
44
  }
47
- /**
48
- * Latest value per (asserts, slot). A record named in another record's
49
- * `supersedes` is a corrected answer and drops out; the rest apply in
50
- * `asserted_at` order (stable, so same-instant records keep load order).
51
- */
52
- function indexDiscoverySlots(records) {
53
- const superseded = new Set(records.map((record) => record.dataparade.supersedes).filter((uid) => Boolean(uid)));
54
- const ordered = records
55
- .filter((record) => !superseded.has(record.metadata.uid))
56
- .map((record, position) => ({ record, position }))
57
- .sort((a, b) => Date.parse(a.record.dataparade.asserted_at) - Date.parse(b.record.dataparade.asserted_at) ||
58
- a.position - b.position)
59
- .map(({ record }) => record);
60
- const index = new Map();
61
- for (const record of ordered) {
62
- const slot = record.dataparade.asserted_slot;
63
- if (!slot) {
64
- continue;
65
- }
66
- const asserts = record.dataparade.asserts;
67
- const bySlot = index.get(asserts) ?? new Map();
68
- bySlot.set(slot, record.dataparade.asserted_value ?? "");
69
- index.set(asserts, bySlot);
70
- }
71
- return index;
72
- }
73
- function discoveryValue(index, asserts, slot) {
74
- return index.get(asserts)?.get(slot);
75
- }
@@ -1,11 +1,3 @@
1
1
  import type { OcsfDiscoveryRecord } from "./contract/ocsf-discovery-record";
2
2
  export declare function slugifyDiscoveryId(id: string): string;
3
3
  export declare function writeOcsfDiscoveryRecordsToDir(records: OcsfDiscoveryRecord[], outputDir: string): string[];
4
- /**
5
- * A re-scan replaces that scan path's earlier scan records: the scan is the
6
- * source of truth for what it found, and its records carry the land date in
7
- * their ids, so an append would collide on the same day and pile up across days.
8
- * Interview and cloud records, and scan records for other scan paths, are kept.
9
- * Returns the paths it removed.
10
- */
11
- export declare function removeScanRecordsForScanPath(outputDir: string, scanPath: string): string[];
@@ -5,12 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.slugifyDiscoveryId = slugifyDiscoveryId;
7
7
  exports.writeOcsfDiscoveryRecordsToDir = writeOcsfDiscoveryRecordsToDir;
8
- exports.removeScanRecordsForScanPath = removeScanRecordsForScanPath;
9
8
  const crypto_1 = require("crypto");
10
9
  const fs_1 = __importDefault(require("fs"));
11
10
  const path_1 = __importDefault(require("path"));
12
11
  const ocsf_discovery_record_1 = require("./contract/ocsf-discovery-record");
13
- const scan_entity_uri_1 = require("./scan-entity-uri");
14
12
  function slugifyDiscoveryId(id) {
15
13
  return id.replace(/[:/]/g, "_");
16
14
  }
@@ -45,39 +43,3 @@ function writeOcsfDiscoveryRecordsToDir(records, outputDir) {
45
43
  }
46
44
  return writtenPaths;
47
45
  }
48
- /**
49
- * A re-scan replaces that scan path's earlier scan records: the scan is the
50
- * source of truth for what it found, and its records carry the land date in
51
- * their ids, so an append would collide on the same day and pile up across days.
52
- * Interview and cloud records, and scan records for other scan paths, are kept.
53
- * Returns the paths it removed.
54
- */
55
- function removeScanRecordsForScanPath(outputDir, scanPath) {
56
- const resolved = path_1.default.resolve(outputDir);
57
- if (!fs_1.default.existsSync(resolved)) {
58
- return [];
59
- }
60
- const removed = [];
61
- for (const name of fs_1.default.readdirSync(resolved)) {
62
- if (!name.endsWith(".json")) {
63
- continue;
64
- }
65
- const filePath = path_1.default.join(resolved, name);
66
- let record;
67
- try {
68
- record = JSON.parse(fs_1.default.readFileSync(filePath, "utf8"));
69
- }
70
- catch {
71
- continue;
72
- }
73
- const asserts = record.dataparade?.asserts;
74
- if (record.dataparade?.source !== "scan" || !asserts) {
75
- continue;
76
- }
77
- if ((0, scan_entity_uri_1.parseScanEntityAsserts)(asserts)?.scanPath === scanPath) {
78
- fs_1.default.rmSync(filePath);
79
- removed.push(filePath);
80
- }
81
- }
82
- return removed;
83
- }
@@ -63,7 +63,6 @@ async function run() {
63
63
  ].join("\n")),
64
64
  ].join("\n");
65
65
  node_fs_1.default.writeFileSync(markdownPath, markdown, "utf8");
66
- // eslint-disable-next-line no-console
67
66
  console.log(`Model eval reports written:\n- ${jsonPath}\n- ${markdownPath}`);
68
67
  }
69
68
  void run();
@@ -0,0 +1,18 @@
1
+ import type { ScanDiscoveryInput } from "../discoveries/scan-discovery-input";
2
+ import type { AppliedState } from "../facts/apply-answers";
3
+ import { type KbPaths } from "../kb/kb-store";
4
+ /** The applied state in the shape the OCSF record builders read. */
5
+ export declare function appliedStateToScanInput(applied: AppliedState): ScanDiscoveryInput;
6
+ export interface ExportOcsfResult {
7
+ outDir: string;
8
+ records: number;
9
+ scanRecords: number;
10
+ interviewRecords: number;
11
+ }
12
+ /**
13
+ * Write the knowledge base as OCSF Architecture Discovery records: the scan's Facts with
14
+ * the answers applied, plus one interview record for each interview answer that is still
15
+ * current. This is the only producer of OCSF records; the folder it writes is an export,
16
+ * not storage.
17
+ */
18
+ export declare function exportOcsf(paths: KbPaths, outDir: string): ExportOcsfResult;