@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
@@ -1,11 +1,62 @@
1
1
  export type CliUploadPreviewResponse = {
2
2
  draftId: string;
3
3
  projectName?: string | null;
4
+ /** The web app of the API that took the upload. Older backends leave it out. */
5
+ appUrl?: string;
6
+ /**
7
+ * What `POST upload/:draftId/complete` returned (DATAP-883): the stored scan, and for a
8
+ * `diff --upload` head the comparison with the base. Null when the call failed.
9
+ */
10
+ complete?: CliUploadCompleteResponse | null;
11
+ };
12
+ /** A comparison the backend ran (DATAP-891), or why it did not. */
13
+ export type CliUploadComparison = {
14
+ compared: true;
15
+ created: boolean;
16
+ comparison: {
17
+ id: string;
18
+ changeSet: {
19
+ renames?: string;
20
+ };
21
+ };
22
+ bindings: Array<{
23
+ answerId: string;
24
+ status: string;
25
+ reason: string;
26
+ }>;
27
+ summary: string;
28
+ } | {
29
+ compared: false;
30
+ reason: string;
31
+ message: string;
32
+ };
33
+ export type CliUploadCompleteResponse = {
34
+ stored: true;
35
+ scanId: string;
36
+ repositoryId: string;
37
+ created: boolean;
38
+ comparable: boolean;
39
+ comparison?: CliUploadComparison;
40
+ } | {
41
+ stored: false;
42
+ reason: string;
43
+ };
44
+ /** Sent with the head upload of `dataparade diff --upload` (DATAP-890). */
45
+ export type CliUploadCompareRequest = {
46
+ baseCommitSha: string;
47
+ rootCommitSha: string;
48
+ renames: Array<{
49
+ from: string;
50
+ to: string;
51
+ similarity?: number;
52
+ }>;
4
53
  };
5
54
  export type CliAnonymousUploadPreviewResponse = {
6
55
  claimToken: string;
7
56
  expiresAt: string;
8
57
  projectName: string;
58
+ /** The web app of the API that took the upload. Older backends leave it out. */
59
+ appUrl?: string;
9
60
  };
10
61
  export type CliUploadPreviewInput = {
11
62
  apiKey?: string;
@@ -22,4 +73,8 @@ export type CliUploadPreviewInput = {
22
73
  relativePath: string;
23
74
  content: string;
24
75
  }>;
76
+ /** Normalized origin remote, sent when the upload is completed (DATAP-883). */
77
+ remoteUrl?: string | null;
78
+ /** From `diff --upload` on the head scan: compare it with the base after it is stored. */
79
+ compare?: CliUploadCompareRequest;
25
80
  };
@@ -0,0 +1,5 @@
1
+ /** Scanner stderr may contain third-party diagnostics. Never forward it. */
2
+ export declare function runLocalScanner(executable: string, args: string[], input?: AsyncIterable<string>): Promise<{
3
+ code: number | null;
4
+ output: string;
5
+ }>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runLocalScanner = runLocalScanner;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const node_stream_1 = require("node:stream");
6
+ const promises_1 = require("node:stream/promises");
7
+ /** Scanner stderr may contain third-party diagnostics. Never forward it. */
8
+ async function runLocalScanner(executable, args, input) {
9
+ const child = (0, node_child_process_1.spawn)(executable, args, {
10
+ stdio: [input ? 'pipe' : 'ignore', 'pipe', 'ignore'],
11
+ windowsHide: true,
12
+ });
13
+ const output = [];
14
+ let size = 0;
15
+ const controller = new AbortController();
16
+ const timer = setTimeout(() => child.kill(), 300_000);
17
+ const completed = new Promise((resolve, reject) => {
18
+ child.once('error', reject);
19
+ child.once('close', resolve);
20
+ });
21
+ child.stdout?.on('data', (chunk) => {
22
+ size += chunk.length;
23
+ if (size > 64 * 1024 * 1024)
24
+ child.kill();
25
+ else
26
+ output.push(chunk);
27
+ });
28
+ const sending = input && child.stdin
29
+ ? (0, promises_1.pipeline)(node_stream_1.Readable.from(input), child.stdin, {
30
+ signal: controller.signal,
31
+ }).catch((error) => {
32
+ if (error.code !== 'EPIPE' &&
33
+ error.code !== 'ABORT_ERR' &&
34
+ error.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
35
+ child.kill();
36
+ throw error;
37
+ }
38
+ })
39
+ : Promise.resolve();
40
+ try {
41
+ const [code] = await Promise.all([completed, sending]);
42
+ return { code, output: Buffer.concat(output).toString('utf8') };
43
+ }
44
+ finally {
45
+ clearTimeout(timer);
46
+ controller.abort();
47
+ }
48
+ }
@@ -0,0 +1,12 @@
1
+ import { type ModelMode } from './report';
2
+ export declare const SENSITIVE_FINDINGS_BASENAME = "sensitive-findings.json";
3
+ type ProjectScan = {
4
+ root: string;
5
+ target: string;
6
+ excludes: string[];
7
+ modelMode: ModelMode;
8
+ enabled: boolean;
9
+ };
10
+ /** A separate local artifact. Nothing here is passed to the structural scanner. */
11
+ export declare function writeProjectSensitiveScan(dataflowOutputPath: string, options: ProjectScan, warn: (message: string) => void): Promise<number | undefined>;
12
+ export {};
@@ -0,0 +1,177 @@
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.SENSITIVE_FINDINGS_BASENAME = void 0;
7
+ exports.writeProjectSensitiveScan = writeProjectSensitiveScan;
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const node_util_1 = require("node:util");
11
+ const zod_1 = require("zod");
12
+ const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
13
+ const process_1 = require("./process");
14
+ const report_1 = require("./report");
15
+ const generated = /(?:\.min\.(?:js|mjs|css)|\.map|\.snap|\.lockb?|\.generated\.[^.]+|_pb2(?:_grpc)?\.py|\.pb\.go)$/i;
16
+ const skippedDirs = new Set([
17
+ 'vendored',
18
+ 'third_party',
19
+ 'sand-client-persistence',
20
+ '__pycache__',
21
+ ]);
22
+ const skippedFiles = new Set([
23
+ '.git',
24
+ 'package-lock.json',
25
+ 'pnpm-lock.yaml',
26
+ 'go.sum',
27
+ 'npm-shrinkwrap.json',
28
+ ]);
29
+ const maxFileBytes = 1024 * 1024;
30
+ const maxTotalBytes = 64 * 1024 * 1024;
31
+ const decoder = new node_util_1.TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
32
+ const fileFinding = report_1.findingFields.extend({ id: zod_1.z.string() });
33
+ const fileReport = report_1.reportFields.extend({ findings: fileFinding.array() });
34
+ exports.SENSITIVE_FINDINGS_BASENAME = 'sensitive-findings.json';
35
+ async function* projectRecords(options, coverage, selected) {
36
+ const patterns = options.excludes.map((p) => (0, scanner_1.toPosixPath)(p.trim().replace(/^\.\/+/, '')));
37
+ const globs = patterns.map((p) => ({
38
+ directory: (0, scanner_1.gitignorePatternToRegex)(p.endsWith('/**') ? p.slice(0, -3) : p, true),
39
+ file: (0, scanner_1.gitignorePatternToRegex)(p, false),
40
+ }));
41
+ let total = 0;
42
+ async function* walk(entryPath, inherited) {
43
+ if (coverage.byteLimitReached)
44
+ return;
45
+ const id = (0, scanner_1.toPosixPath)(node_path_1.default.relative(options.root, entryPath));
46
+ const stat = await node_fs_1.promises.lstat(entryPath);
47
+ if (id &&
48
+ globs.some((g) => (stat.isDirectory() ? g.directory : g.file).test(id)))
49
+ return;
50
+ if (id && (0, scanner_1.isPathIgnored)(entryPath, stat.isDirectory(), inherited))
51
+ return;
52
+ if (stat.isDirectory()) {
53
+ const name = node_path_1.default.basename(entryPath);
54
+ if (id && ((0, scanner_1.shouldSkipDirectoryName)(name) || skippedDirs.has(name)))
55
+ return;
56
+ const rules = await (0, scanner_1.gitignoreRulesForDir)(entryPath, inherited);
57
+ const children = await node_fs_1.promises.readdir(entryPath);
58
+ for (const name of children.sort())
59
+ yield* walk(node_path_1.default.join(entryPath, name), rules);
60
+ return;
61
+ }
62
+ if (!stat.isFile() ||
63
+ generated.test(id) ||
64
+ skippedFiles.has(node_path_1.default.basename(id)))
65
+ return;
66
+ if (/^project\/(?:issues|events|\.cache)\//.test(id))
67
+ return;
68
+ if (stat.size > maxFileBytes) {
69
+ coverage.filesOverSizeLimit++;
70
+ return;
71
+ }
72
+ const contents = await node_fs_1.promises.readFile(entryPath);
73
+ if (contents.includes(0))
74
+ return;
75
+ let text;
76
+ try {
77
+ text = decoder.decode(contents);
78
+ }
79
+ catch {
80
+ return;
81
+ }
82
+ if (contents.length > maxFileBytes) {
83
+ coverage.filesOverSizeLimit++;
84
+ return;
85
+ }
86
+ if (total + contents.length > maxTotalBytes) {
87
+ coverage.byteLimitReached = true;
88
+ return;
89
+ }
90
+ total += contents.length;
91
+ selected.add(id);
92
+ coverage.filesScanned++;
93
+ yield JSON.stringify({ id, text }) + '\n';
94
+ }
95
+ const rules = options.target === options.root
96
+ ? []
97
+ : await (0, scanner_1.gitignoreRulesForDir)(options.root, []);
98
+ yield* walk(options.target, rules);
99
+ }
100
+ /** A separate local artifact. Nothing here is passed to the structural scanner. */
101
+ async function writeProjectSensitiveScan(dataflowOutputPath, options, warn) {
102
+ const coverage = {
103
+ filesScanned: 0,
104
+ filesOverSizeLimit: 0,
105
+ byteLimitReached: false,
106
+ };
107
+ const selected = new Set();
108
+ const unavailable = {
109
+ schemaVersion: 1,
110
+ rules: { status: options.enabled ? 'error' : 'disabled' },
111
+ privacyFilter: { status: options.enabled ? 'not-run' : 'disabled' },
112
+ findings: [],
113
+ coverage,
114
+ };
115
+ let report = unavailable;
116
+ let findingCount;
117
+ if (options.enabled) {
118
+ try {
119
+ const { code, output } = await (0, process_1.runLocalScanner)(process.env.DATAPARADE_LEFTBLOCK || 'leftblock', [
120
+ 'scan',
121
+ '--jsonl',
122
+ '--format',
123
+ 'report',
124
+ '--privacy-filter',
125
+ options.modelMode,
126
+ ], projectRecords(options, coverage, selected));
127
+ const parsed = fileReport.parse(JSON.parse(output));
128
+ if ((code !== 0 && code !== 1) ||
129
+ parsed.rules.status !== 'completed' ||
130
+ parsed.findings.some((f) => !selected.has(f.id))) {
131
+ throw new Error('Incomplete sensitive scan');
132
+ }
133
+ const warning = (0, report_1.modelWarning)(parsed);
134
+ if (warning)
135
+ warn(warning);
136
+ if (coverage.byteLimitReached || coverage.filesOverSizeLimit > 0) {
137
+ warn('LeftBlock skipped some files because they exceeded the scan size limits.');
138
+ }
139
+ report = {
140
+ ...parsed,
141
+ findings: parsed.findings.map(({ id, ...finding }) => ({
142
+ ...finding,
143
+ file: id,
144
+ })),
145
+ coverage,
146
+ };
147
+ findingCount = parsed.findings.length;
148
+ }
149
+ catch {
150
+ warn('LeftBlock could not complete the sensitive scan. Check that compatible LeftBlock and Gitleaks are installed.');
151
+ }
152
+ }
153
+ if (node_path_1.default.basename(dataflowOutputPath).toLowerCase() ===
154
+ exports.SENSITIVE_FINDINGS_BASENAME) {
155
+ if (options.enabled)
156
+ warn('Choose a different --output name to save the local sensitive findings report.');
157
+ return findingCount;
158
+ }
159
+ try {
160
+ const outputDir = node_path_1.default.dirname(dataflowOutputPath);
161
+ const tempDir = await node_fs_1.promises.mkdtemp(node_path_1.default.join(outputDir, '.sensitive-'));
162
+ try {
163
+ const tempFile = node_path_1.default.join(tempDir, exports.SENSITIVE_FINDINGS_BASENAME);
164
+ await node_fs_1.promises.writeFile(tempFile, JSON.stringify(report, null, 2) + '\n', {
165
+ mode: 0o600,
166
+ });
167
+ await node_fs_1.promises.rename(tempFile, node_path_1.default.join(outputDir, exports.SENSITIVE_FINDINGS_BASENAME));
168
+ }
169
+ finally {
170
+ await node_fs_1.promises.rm(tempDir, { recursive: true, force: true });
171
+ }
172
+ }
173
+ catch {
174
+ warn('Could not write the local sensitive findings report.');
175
+ }
176
+ return findingCount;
177
+ }
@@ -0,0 +1,50 @@
1
+ import { z } from 'zod';
2
+ export declare const findingFields: z.ZodObject<{
3
+ rule: z.ZodString;
4
+ kind: z.ZodEnum<{
5
+ personal: "personal";
6
+ secret: "secret";
7
+ crypto: "crypto";
8
+ deep: "deep";
9
+ }>;
10
+ finding_id: z.ZodString;
11
+ line: z.ZodNumber;
12
+ start: z.ZodNumber;
13
+ end: z.ZodNumber;
14
+ score: z.ZodOptional<z.ZodNumber>;
15
+ }, z.core.$strip>;
16
+ export declare const reportFields: z.ZodObject<{
17
+ schemaVersion: z.ZodLiteral<1>;
18
+ rules: z.ZodObject<{
19
+ status: z.ZodEnum<{
20
+ error: "error";
21
+ completed: "completed";
22
+ disabled: "disabled";
23
+ "not-run": "not-run";
24
+ unavailable: "unavailable";
25
+ }>;
26
+ findingCount: z.ZodOptional<z.ZodNumber>;
27
+ reason: z.ZodOptional<z.ZodEnum<{
28
+ "missing-dependencies": "missing-dependencies";
29
+ timeout: "timeout";
30
+ "model-error": "model-error";
31
+ }>>;
32
+ }, z.core.$strip>;
33
+ privacyFilter: z.ZodObject<{
34
+ status: z.ZodEnum<{
35
+ error: "error";
36
+ completed: "completed";
37
+ disabled: "disabled";
38
+ "not-run": "not-run";
39
+ unavailable: "unavailable";
40
+ }>;
41
+ findingCount: z.ZodOptional<z.ZodNumber>;
42
+ reason: z.ZodOptional<z.ZodEnum<{
43
+ "missing-dependencies": "missing-dependencies";
44
+ timeout: "timeout";
45
+ "model-error": "model-error";
46
+ }>>;
47
+ }, z.core.$strip>;
48
+ }, z.core.$strip>;
49
+ export type ModelMode = 'auto' | 'off';
50
+ export declare function modelWarning(report: z.infer<typeof reportFields>): string | undefined;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportFields = exports.findingFields = void 0;
4
+ exports.modelWarning = modelWarning;
5
+ const zod_1 = require("zod");
6
+ const status = zod_1.z.object({
7
+ status: zod_1.z.enum(['completed', 'disabled', 'not-run', 'unavailable', 'error']),
8
+ findingCount: zod_1.z.number().int().nonnegative().optional(),
9
+ reason: zod_1.z.enum(['missing-dependencies', 'timeout', 'model-error']).optional(),
10
+ });
11
+ exports.findingFields = zod_1.z.object({
12
+ rule: zod_1.z.string(),
13
+ kind: zod_1.z.enum(['secret', 'personal', 'crypto', 'deep']),
14
+ finding_id: zod_1.z.string(),
15
+ line: zod_1.z.number().int().positive(),
16
+ start: zod_1.z.number().int().nonnegative(),
17
+ end: zod_1.z.number().int().nonnegative(),
18
+ score: zod_1.z.number().optional(),
19
+ });
20
+ exports.reportFields = zod_1.z.object({
21
+ schemaVersion: zod_1.z.literal(1),
22
+ rules: status,
23
+ privacyFilter: status,
24
+ });
25
+ function modelWarning(report) {
26
+ if (report.privacyFilter.status !== 'unavailable')
27
+ return;
28
+ const hint = report.privacyFilter.reason === 'timeout'
29
+ ? 'The model reached its time limit.'
30
+ : 'Check the local model installation and cache.';
31
+ return `Privacy Filter unavailable. LeftBlock rules completed (${report.rules.findingCount ?? 0} findings). ${hint}`;
32
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerSessionScan(program: Command): void;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSessionScan = registerSessionScan;
4
+ const commander_1 = require("commander");
5
+ const zod_1 = require("zod");
6
+ const process_1 = require("./process");
7
+ const report_1 = require("./report");
8
+ const auditReport = report_1.reportFields.extend({
9
+ sources: zod_1.z.array(zod_1.z.object({
10
+ source: zod_1.z.string(),
11
+ status: zod_1.z.enum(['completed', 'missing', 'partial', 'error']),
12
+ sessionsScanned: zod_1.z.number().int().nonnegative(),
13
+ sessionsWithoutProject: zod_1.z.number().int().nonnegative(),
14
+ readErrors: zod_1.z.number().int().nonnegative(),
15
+ })),
16
+ findings: zod_1.z.array(report_1.findingFields.extend({
17
+ agent: zod_1.z.string(),
18
+ sessionId: zod_1.z.string(),
19
+ message: zod_1.z.number().int().positive(),
20
+ part: zod_1.z.number().int().positive(),
21
+ source: zod_1.z
22
+ .object({
23
+ file: zod_1.z.string(),
24
+ line: zod_1.z.number().int().positive().nullable(),
25
+ row: zod_1.z.number().int().nonnegative().nullable(),
26
+ })
27
+ .nullable(),
28
+ score: zod_1.z.number().nullish(),
29
+ })),
30
+ });
31
+ // Escape control characters before displaying paths or IDs from local histories.
32
+ function printable(value) {
33
+ return JSON.stringify(value).slice(1, -1);
34
+ }
35
+ function registerSessionScan(program) {
36
+ const sessions = program
37
+ .command('sessions')
38
+ .description('Inspect local coding sessions');
39
+ sessions
40
+ .command('scan [path]')
41
+ .description('Scan the last seven days of coding sessions for this project with LeftBlock')
42
+ .option('--all', 'Include sessions across all projects')
43
+ .option('--source <source>', 'Select a BotSpy source (repeatable)', (source, sources) => [...sources, source], [])
44
+ .option('--session <id>', 'Scan one exact session ID across projects and dates')
45
+ .option('--since <time>', 'Select sessions active since a date, timestamp, or duration (default: 7d)')
46
+ .addOption(new commander_1.Option('--format <format>', 'Report format')
47
+ .choices(['text', 'json'])
48
+ .default('text'))
49
+ .addOption(new commander_1.Option('--privacy-filter <mode>', 'Use the local Privacy Filter when available')
50
+ .choices(['auto', 'off'])
51
+ .default('auto'))
52
+ .option('--fail-on-findings', 'Exit 1 if a completed audit reports findings')
53
+ .action(async (project, options) => {
54
+ if ((project && (options.all || options.session)) ||
55
+ (options.session && (options.all || options.since))) {
56
+ console.error('[sessions scan] Use a project path, --all, or --session. --since does not apply to --session.');
57
+ process.exitCode = 2;
58
+ return;
59
+ }
60
+ const args = ['privacy-audit', '--privacy-filter', options.privacyFilter];
61
+ if (project !== undefined)
62
+ args.push(`--project=${project}`);
63
+ if (options.all)
64
+ args.push('--all');
65
+ if (options.session !== undefined)
66
+ args.push(`--session=${options.session}`);
67
+ if (options.since !== undefined)
68
+ args.push(`--since=${options.since}`);
69
+ for (const source of options.source ?? [])
70
+ args.push(`--source=${source}`);
71
+ if (process.env.DATAPARADE_LEFTBLOCK)
72
+ args.push(`--leftblock=${process.env.DATAPARADE_LEFTBLOCK}`);
73
+ try {
74
+ const { code, output } = await (0, process_1.runLocalScanner)(process.env.DATAPARADE_BOTSPY || 'botspy', args);
75
+ if (code === 1) {
76
+ console.error('[sessions scan] The selected session was not found.');
77
+ process.exitCode = 2;
78
+ return;
79
+ }
80
+ if (code === 2) {
81
+ console.error('[sessions scan] Check the project path, source names, and date options. Use a BotSpy version with privacy-audit.');
82
+ process.exitCode = 2;
83
+ return;
84
+ }
85
+ if (code !== 0 && code !== 3)
86
+ throw new Error('BotSpy process failed');
87
+ const report = auditReport.parse(JSON.parse(output));
88
+ if (options.format === 'json') {
89
+ console.log(JSON.stringify(report, null, 2));
90
+ }
91
+ else {
92
+ for (const source of report.sources) {
93
+ console.log(`${printable(source.source)}: ${source.status}; ${source.sessionsScanned} sessions scanned, ${source.sessionsWithoutProject} without a project match, ${source.readErrors} read errors`);
94
+ }
95
+ for (const finding of report.findings) {
96
+ const source = finding.source;
97
+ const location = source
98
+ ? ` ${printable(source.file)}${source.line ? `:${source.line}` : source.row != null ? ` row ${source.row}` : ''}`
99
+ : '';
100
+ console.log(`${printable(finding.agent)} ${printable(finding.sessionId)} message ${finding.message} part ${finding.part}:${location} ${printable(finding.rule)} [id ${printable(finding.finding_id)}]`);
101
+ }
102
+ console.log(`${report.findings.length} sensitive information finding(s).`);
103
+ }
104
+ const warning = (0, report_1.modelWarning)(report);
105
+ if (warning)
106
+ console.warn(`[sessions scan] ${warning}`);
107
+ if (code === 3 || report.rules.status !== 'completed') {
108
+ console.error('[sessions scan] Audit incomplete. Check the source statuses and local scanner setup.');
109
+ process.exitCode = 2;
110
+ }
111
+ else if (options.failOnFindings && report.findings.length > 0) {
112
+ process.exitCode = 1;
113
+ }
114
+ }
115
+ catch {
116
+ console.error('[sessions scan] Could not run the local audit. Check that compatible BotSpy, LeftBlock, and Gitleaks are installed.');
117
+ process.exitCode = 2;
118
+ }
119
+ });
120
+ }
@@ -61,6 +61,7 @@ export declare class ScanProgressRenderer {
61
61
  onWroteDataflow(outputPath?: string): void;
62
62
  /** Store preview URL for the "What to do next" note. Machine line stays in upload. */
63
63
  onPreviewUrl(previewUrl: string, notice?: string): void;
64
+ sensitiveScanMessage(message: string): void;
64
65
  /**
65
66
  * Auto-upload failed after the local output was written. finish() then
66
67
  * says so and prints the retry command instead of the success closing.
@@ -245,6 +245,14 @@ class ScanProgressRenderer {
245
245
  this.previewUrl = previewUrl;
246
246
  this.previewNotice = notice;
247
247
  }
248
+ sensitiveScanMessage(message) {
249
+ if (this.useClack) {
250
+ this.prompts().log.message(message);
251
+ }
252
+ else {
253
+ this.writePlain(`[scan] ${message}`);
254
+ }
255
+ }
248
256
  /**
249
257
  * Auto-upload failed after the local output was written. finish() then
250
258
  * says so and prints the retry command instead of the success closing.
@@ -1,2 +1,2 @@
1
- export declare function buildImportPreviewUrl(draftId: string, cliSessionId?: string): string;
2
- export declare function buildAnonymousCliPreviewUrl(claimToken: string, cliSessionId?: string): string;
1
+ export declare function buildImportPreviewUrl(draftId: string, cliSessionId?: string, appUrl?: string): string;
2
+ export declare function buildAnonymousCliPreviewUrl(claimToken: string, cliSessionId?: string, appUrl?: string): string;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildImportPreviewUrl = buildImportPreviewUrl;
4
4
  exports.buildAnonymousCliPreviewUrl = buildAnonymousCliPreviewUrl;
5
5
  const dataparade_app_base_url_1 = require("../platform-api/dataparade-app-base-url");
6
- function buildImportPreviewUrl(draftId, cliSessionId) {
7
- const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
6
+ function buildImportPreviewUrl(draftId, cliSessionId, appUrl) {
7
+ const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)(process.env, appUrl);
8
8
  const url = new URL("/dashboard", `${base}/`);
9
9
  url.searchParams.set("importDraft", draftId);
10
10
  if (cliSessionId?.trim()) {
@@ -12,8 +12,8 @@ function buildImportPreviewUrl(draftId, cliSessionId) {
12
12
  }
13
13
  return url.toString();
14
14
  }
15
- function buildAnonymousCliPreviewUrl(claimToken, cliSessionId) {
16
- const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)();
15
+ function buildAnonymousCliPreviewUrl(claimToken, cliSessionId, appUrl) {
16
+ const base = (0, dataparade_app_base_url_1.getDataparadeAppBaseUrl)(process.env, appUrl);
17
17
  const encoded = encodeURIComponent(claimToken);
18
18
  const url = new URL(`/preview/cli/${encoded}`, `${base}/`);
19
19
  if (cliSessionId?.trim()) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runDataflowUpload = runDataflowUpload;
4
4
  const upload_client_1 = require("../platform-api/upload-client");
5
5
  const telemetry_client_1 = require("../platform-api/telemetry-client");
6
+ const git_context_1 = require("../output/git-context");
6
7
  const build_preview_url_1 = require("./build-preview-url");
7
8
  async function runDataflowUpload(input) {
8
9
  const prefix = input.logPrefix ?? '[upload]';
@@ -22,8 +23,11 @@ async function runDataflowUpload(input) {
22
23
  dataparadeGraph: input.dataparadeGraph,
23
24
  facts: input.facts,
24
25
  files: input.files,
26
+ remoteUrl: input.repositoryDir
27
+ ? (0, git_context_1.readOriginRemoteUrl)(input.repositoryDir)
28
+ : null,
25
29
  });
26
- const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId);
30
+ const previewUrl = (0, build_preview_url_1.buildImportPreviewUrl)(result.draftId, sessionId, result.appUrl);
27
31
  if (!input.quiet) {
28
32
  console.log(`${prefix} Preview ready: ${previewUrl}`);
29
33
  }
@@ -50,7 +54,7 @@ async function runDataflowUpload(input) {
50
54
  facts: input.facts,
51
55
  files: input.files,
52
56
  });
53
- const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId);
57
+ const previewUrl = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)(result.claimToken, sessionId, result.appUrl);
54
58
  const notice = 'You can view the diagram now. Claiming it to your account uses 1 scan slot' +
55
59
  (input.scanJobId
56
60
  ? ' and any platform AI tokens used during the scan.'
@@ -14,6 +14,8 @@ export type RunDataflowUploadInput = {
14
14
  relativePath: string;
15
15
  content: string;
16
16
  }>;
17
+ /** Folder in the scanned Git checkout; its origin remote goes with the upload. */
18
+ repositoryDir?: string;
17
19
  /** Skip the `[prefix] Preview ready` lines (TTY scan renders its own block). */
18
20
  quiet?: boolean;
19
21
  };
@@ -1379,4 +1379,34 @@ describe("ai-enrichment deterministic fallbacks", () => {
1379
1379
  expect(result.dataFlows.some((f) => f.sourceComponentId === "asset_scripts" &&
1380
1380
  f.targetComponentId === "tp_stripe")).toBe(true);
1381
1381
  });
1382
+ it("keeps the names of provider products such as Google Docs and Google Analytics", () => {
1383
+ const component = (id, name, serviceName) => ({
1384
+ id,
1385
+ name,
1386
+ type: "third_party",
1387
+ confidence: 1,
1388
+ detectedFrom: [],
1389
+ sourceLocations: [],
1390
+ properties: { serviceName, section_id: "backend" },
1391
+ });
1392
+ const components = [
1393
+ {
1394
+ id: "app_1",
1395
+ name: "Backend",
1396
+ type: "asset",
1397
+ confidence: 1,
1398
+ detectedFrom: [],
1399
+ sourceLocations: [],
1400
+ properties: { section_id: "backend" },
1401
+ },
1402
+ component("docs", "Google Docs", "google_docs"),
1403
+ component("ga", "Google Analytics", "google_analytics"),
1404
+ component("gai", "Google Ai", "google_ai"),
1405
+ ];
1406
+ const result = (0, fallbacks_1.applyDeterministicInferenceFallbacks)(components, []);
1407
+ const names = Object.fromEntries(result.components.map((c) => [c.id, c.name]));
1408
+ expect(names.docs).toBe("Google Docs");
1409
+ expect(names.ga).toBe("Google Analytics");
1410
+ expect(names.gai).toBe("Google");
1411
+ });
1382
1412
  });