@dataparade/cli 0.0.19 → 0.0.21
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.
- package/README.md +12 -10
- package/dist/package.json +2 -1
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +4 -1
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +44 -18
- package/dist/src/cli.js +100 -52
- package/dist/src/config/scan-env.d.ts +5 -0
- package/dist/src/config/scan-env.js +12 -1
- package/dist/src/core/pipeline/scan-pipeline.d.ts +2 -1
- package/dist/src/core/pipeline/scan-pipeline.js +7 -4
- package/dist/src/platform-api/fetch-failure.d.ts +11 -0
- package/dist/src/platform-api/fetch-failure.js +85 -0
- package/dist/src/ui/brand.d.ts +28 -0
- package/dist/src/ui/brand.js +72 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +69 -0
- package/dist/src/ui/scan-progress-renderer.js +386 -0
- package/dist/src/ui/teaching-lines.d.ts +9 -0
- package/dist/src/ui/teaching-lines.js +144 -0
- package/dist/src/ui/types.d.ts +33 -0
- package/dist/src/ui/types.js +2 -0
- package/dist/src/upload/run-upload.d.ts +1 -1
- package/dist/src/upload/run-upload.js +21 -16
- package/dist/src/upload/types.d.ts +4 -0
- package/dist/tests/cli/cli.spec.js +77 -40
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +118 -47
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +9 -0
- package/dist/tests/unit/config/scan-env-debug.spec.js +17 -8
- package/dist/tests/unit/platform-api/fetch-failure.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/fetch-failure.spec.js +16 -0
- package/dist/tests/unit/ui/brand.spec.d.ts +1 -0
- package/dist/tests/unit/ui/brand.spec.js +52 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.d.ts +1 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +275 -0
- package/dist/tests/unit/ui/teaching-lines.spec.d.ts +1 -0
- package/dist/tests/unit/ui/teaching-lines.spec.js +62 -0
- package/dist/tests/unit/upload/run-upload.spec.js +29 -27
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -24,8 +24,10 @@ pnpm dlx @dataparade/cli scan .
|
|
|
24
24
|
|
|
25
25
|
**What to expect:**
|
|
26
26
|
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- 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
|
+
- In CI / non-TTY (or with `NO_COLOR`): the same content as plain logs — no spinners or ANSI.
|
|
29
|
+
- On success: `[scan] dataflow.json written to /absolute/path/to/dataflow.json` (always printed for scripts/tests).
|
|
30
|
+
- When auto-upload runs: `[scan] Preview ready: <URL>` (plus a friendly next-step note with the same URL).
|
|
29
31
|
- By default, `dataflow.json` is created in the **current working directory** (override with `-o` / `--output`).
|
|
30
32
|
|
|
31
33
|
```bash
|
|
@@ -67,14 +69,14 @@ By default, the CLI writes `./dataflow.json` in the current working directory.
|
|
|
67
69
|
|
|
68
70
|
## Documentation
|
|
69
71
|
|
|
70
|
-
| Topic
|
|
71
|
-
|
|
72
|
-
| CLI hub (all topics)
|
|
73
|
-
| Scan arguments & flags
|
|
74
|
-
| `dataparade.config.json` | [Config file](https://app.dataparade.io/docs/cli-import-and-zip/config-file)
|
|
75
|
-
| Environment variables
|
|
76
|
-
| AI inference
|
|
77
|
-
| Scan patterns (YAML)
|
|
72
|
+
| Topic | Link |
|
|
73
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------ |
|
|
74
|
+
| CLI hub (all topics) | [CLI Run and Export](https://app.dataparade.io/docs/cli-import-and-zip) |
|
|
75
|
+
| Scan arguments & flags | [Scan arguments](https://app.dataparade.io/docs/cli-import-and-zip/scan-arguments) |
|
|
76
|
+
| `dataparade.config.json` | [Config file](https://app.dataparade.io/docs/cli-import-and-zip/config-file) |
|
|
77
|
+
| Environment variables | [Environment variables](https://app.dataparade.io/docs/cli-import-and-zip/environment-variables) |
|
|
78
|
+
| AI inference | [AI inference](https://app.dataparade.io/docs/cli-import-and-zip/ai-inference) |
|
|
79
|
+
| Scan patterns (YAML) | [Scan patterns](https://app.dataparade.io/docs/cli-import-and-zip/scan-patterns) |
|
|
78
80
|
|
|
79
81
|
---
|
|
80
82
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"@clack/prompts": "^1.8.1",
|
|
57
58
|
"@dataparade/scanner": "github:DataParade-io/scanner#e66e1bcaef55b61214d170c617df529bd300fc89",
|
|
58
59
|
"@sentry/node": "^10.38.0",
|
|
59
60
|
"commander": "^12.1.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AiProvider, AiProviderRequest, AiProviderResult } from
|
|
1
|
+
import type { AiProvider, AiProviderRequest, AiProviderResult } from './types';
|
|
2
2
|
export type PlatformProxyProviderConfig = {
|
|
3
3
|
apiBaseUrl: string;
|
|
4
4
|
workspaceApiKey: string;
|
|
@@ -9,6 +9,8 @@ export type PlatformProxyProviderConfig = {
|
|
|
9
9
|
pollTimeoutMs?: number;
|
|
10
10
|
/** Backoff delays when a task fails because the helper Lambda is still INIT. */
|
|
11
11
|
lambdaInitRetryDelaysMs?: number[];
|
|
12
|
+
/** Backoff delays after a dropped connection. Each entry is one retry. */
|
|
13
|
+
networkRetryDelaysMs?: number[];
|
|
12
14
|
sleep?: (ms: number) => Promise<void>;
|
|
13
15
|
};
|
|
14
16
|
export declare class PlatformProxyProvider implements AiProvider {
|
|
@@ -21,5 +23,6 @@ export declare class PlatformProxyProvider implements AiProvider {
|
|
|
21
23
|
private wait;
|
|
22
24
|
private throwPlatformError;
|
|
23
25
|
infer(request: AiProviderRequest): Promise<AiProviderResult>;
|
|
26
|
+
private fetchPlatform;
|
|
24
27
|
private inferOnce;
|
|
25
28
|
}
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformProxyProvider = void 0;
|
|
4
4
|
const lambda_init_error_1 = require("../lambda-init-error");
|
|
5
|
+
const fetch_failure_1 = require("../../platform-api/fetch-failure");
|
|
6
|
+
const DEFAULT_NETWORK_RETRY_DELAYS_MS = [1000, 2000];
|
|
5
7
|
function resolvePollTimeoutMs(configured) {
|
|
6
|
-
if (typeof configured ===
|
|
8
|
+
if (typeof configured === 'number' &&
|
|
9
|
+
Number.isFinite(configured) &&
|
|
10
|
+
configured > 0) {
|
|
7
11
|
return Math.floor(configured);
|
|
8
12
|
}
|
|
9
|
-
const fromEnv = Number(process.env.SCAN_AI_HTTP_TIMEOUT_MS ??
|
|
13
|
+
const fromEnv = Number(process.env.SCAN_AI_HTTP_TIMEOUT_MS ?? '');
|
|
10
14
|
if (Number.isFinite(fromEnv) && fromEnv > 0)
|
|
11
15
|
return Math.floor(fromEnv);
|
|
12
16
|
return 180_000;
|
|
@@ -17,25 +21,25 @@ function sleep(ms) {
|
|
|
17
21
|
class PlatformProxyProvider {
|
|
18
22
|
constructor(config) {
|
|
19
23
|
this.config = config;
|
|
20
|
-
this.id =
|
|
24
|
+
this.id = 'openai';
|
|
21
25
|
}
|
|
22
26
|
authHeaders() {
|
|
23
27
|
return {
|
|
24
28
|
Authorization: `Bearer ${this.config.workspaceApiKey}`,
|
|
25
|
-
|
|
29
|
+
'Content-Type': 'application/json',
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
32
|
apiBase() {
|
|
29
|
-
return this.config.apiBaseUrl.replace(/\/$/,
|
|
33
|
+
return this.config.apiBaseUrl.replace(/\/$/, '');
|
|
30
34
|
}
|
|
31
35
|
async readErrorMessage(res) {
|
|
32
36
|
let message = `Platform AI infer failed (${res.status})`;
|
|
33
37
|
try {
|
|
34
38
|
const body = (await res.json());
|
|
35
|
-
if (typeof body.message ===
|
|
39
|
+
if (typeof body.message === 'string')
|
|
36
40
|
message = body.message;
|
|
37
41
|
else if (Array.isArray(body.message))
|
|
38
|
-
message = body.message.join(
|
|
42
|
+
message = body.message.join(', ');
|
|
39
43
|
}
|
|
40
44
|
catch {
|
|
41
45
|
// ignore
|
|
@@ -51,7 +55,7 @@ class PlatformProxyProvider {
|
|
|
51
55
|
}
|
|
52
56
|
if (res.status >= 500) {
|
|
53
57
|
const detail = message === `Platform AI infer failed (${res.status})`
|
|
54
|
-
?
|
|
58
|
+
? 'Internal server error'
|
|
55
59
|
: message;
|
|
56
60
|
throw new Error(`Platform AI service error (${res.status}): ${detail}. If this persists, redeploy the API with the CLI bundle and verify SCAN_WORKER_LLM_API_KEY.`);
|
|
57
61
|
}
|
|
@@ -76,9 +80,31 @@ class PlatformProxyProvider {
|
|
|
76
80
|
}
|
|
77
81
|
throw (0, lambda_init_error_1.toUserFacingLambdaInitError)(lastErr);
|
|
78
82
|
}
|
|
83
|
+
async fetchPlatform(url, init) {
|
|
84
|
+
const delays = this.config.networkRetryDelaysMs ?? [
|
|
85
|
+
...DEFAULT_NETWORK_RETRY_DELAYS_MS,
|
|
86
|
+
];
|
|
87
|
+
const method = init.method ?? 'GET';
|
|
88
|
+
let lastErr;
|
|
89
|
+
for (let attempt = 0; attempt <= delays.length; attempt += 1) {
|
|
90
|
+
try {
|
|
91
|
+
return await fetch(url, init);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
lastErr = err;
|
|
95
|
+
if (attempt >= delays.length || !(0, fetch_failure_1.isTransientFetchError)(err)) {
|
|
96
|
+
throw (0, fetch_failure_1.toApiReachabilityError)(err, url, method, attempt + 1);
|
|
97
|
+
}
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.warn(`[dataparade-ai] ${(0, fetch_failure_1.describeRequestTarget)(url, method)} failed (${(0, fetch_failure_1.fetchFailureDetail)(err)}). Retrying (${attempt + 1}/${delays.length}).`);
|
|
100
|
+
await this.wait(delays[attempt] ?? 0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw (0, fetch_failure_1.toApiReachabilityError)(lastErr, url, method, delays.length + 1);
|
|
104
|
+
}
|
|
79
105
|
async inferOnce(request) {
|
|
80
|
-
const submitRes = await
|
|
81
|
-
method:
|
|
106
|
+
const submitRes = await this.fetchPlatform(`${this.apiBase()}/api/scans/cli/ai/infer/tasks`, {
|
|
107
|
+
method: 'POST',
|
|
82
108
|
headers: this.authHeaders(),
|
|
83
109
|
body: JSON.stringify({
|
|
84
110
|
jobId: this.config.jobId,
|
|
@@ -98,13 +124,13 @@ class PlatformProxyProvider {
|
|
|
98
124
|
const submitBody = (await submitRes.json());
|
|
99
125
|
const task = submitBody.tasks?.[0];
|
|
100
126
|
if (!task?.taskId) {
|
|
101
|
-
throw new Error(
|
|
127
|
+
throw new Error('Platform AI infer submit returned no task id');
|
|
102
128
|
}
|
|
103
129
|
const pollIntervalMs = Math.max(500, Math.floor(this.config.pollIntervalMs ?? 1500));
|
|
104
130
|
const deadline = Date.now() + resolvePollTimeoutMs(this.config.pollTimeoutMs);
|
|
105
131
|
while (Date.now() < deadline) {
|
|
106
|
-
const pollRes = await
|
|
107
|
-
method:
|
|
132
|
+
const pollRes = await this.fetchPlatform(`${this.apiBase()}/api/scans/cli/ai/infer/tasks?jobId=${encodeURIComponent(this.config.jobId)}&taskIds=${encodeURIComponent(task.taskId)}`, {
|
|
133
|
+
method: 'GET',
|
|
108
134
|
headers: this.authHeaders(),
|
|
109
135
|
});
|
|
110
136
|
if (!pollRes.ok) {
|
|
@@ -114,14 +140,14 @@ class PlatformProxyProvider {
|
|
|
114
140
|
const pollBody = (await pollRes.json());
|
|
115
141
|
const current = pollBody.tasks?.[0];
|
|
116
142
|
if (!current) {
|
|
117
|
-
throw new Error(
|
|
143
|
+
throw new Error('Platform AI infer poll returned no task');
|
|
118
144
|
}
|
|
119
|
-
if (current.status ===
|
|
145
|
+
if (current.status === 'completed') {
|
|
120
146
|
const proposals = (Array.isArray(current.proposals) ? current.proposals : []);
|
|
121
147
|
const usage = current.usage;
|
|
122
148
|
return {
|
|
123
149
|
proposals,
|
|
124
|
-
usage: usage && typeof usage.totalTokens ===
|
|
150
|
+
usage: usage && typeof usage.totalTokens === 'number'
|
|
125
151
|
? {
|
|
126
152
|
inputTokens: Math.max(0, usage.inputTokens ?? 0),
|
|
127
153
|
outputTokens: Math.max(0, usage.outputTokens ?? 0),
|
|
@@ -130,9 +156,9 @@ class PlatformProxyProvider {
|
|
|
130
156
|
: undefined,
|
|
131
157
|
};
|
|
132
158
|
}
|
|
133
|
-
if (current.status ===
|
|
159
|
+
if (current.status === 'failed') {
|
|
134
160
|
throw new Error(current.errorMessage?.trim() ||
|
|
135
|
-
|
|
161
|
+
'Platform AI infer task failed without details');
|
|
136
162
|
}
|
|
137
163
|
await this.wait(pollIntervalMs);
|
|
138
164
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -52,10 +52,12 @@ const resolve_1 = require("./config/resolve");
|
|
|
52
52
|
const scan_env_1 = require("./config/scan-env");
|
|
53
53
|
const validate_scan_ai_1 = require("./config/validate-scan-ai");
|
|
54
54
|
const scan_sentry_1 = require("./observability/scan-sentry");
|
|
55
|
+
const fetch_failure_1 = require("./platform-api/fetch-failure");
|
|
55
56
|
const telemetry_client_1 = require("./platform-api/telemetry-client");
|
|
56
57
|
const cli_scan_failure_report_1 = require("./platform-api/cli-scan-failure-report");
|
|
57
58
|
const scan_config_schema_1 = require("./core/schema/scan-config.schema");
|
|
58
59
|
const scanner_1 = require("@dataparade/scanner");
|
|
60
|
+
const scan_progress_renderer_1 = require("./ui/scan-progress-renderer");
|
|
59
61
|
function formatEvidence(detail) {
|
|
60
62
|
const evidence = detail.evidence;
|
|
61
63
|
if (!evidence || evidence.length === 0) {
|
|
@@ -80,25 +82,17 @@ function formatProposalTarget(detail) {
|
|
|
80
82
|
}
|
|
81
83
|
return 'unknown';
|
|
82
84
|
}
|
|
83
|
-
function
|
|
85
|
+
function formatAiInferenceVerbose(details) {
|
|
84
86
|
if (details.length === 0) {
|
|
85
|
-
|
|
86
|
-
console.log('[scan] ai-inference details: no proposals generated');
|
|
87
|
-
return;
|
|
87
|
+
return ['[scan] ai-inference details: no proposals generated'];
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
console.log('[scan] ai-inference details:');
|
|
89
|
+
const lines = ['[scan] ai-inference details:'];
|
|
91
90
|
for (const detail of details) {
|
|
92
91
|
const status = detail.status === 'applied'
|
|
93
92
|
? 'applied'
|
|
94
93
|
: `rejected (${detail.rejectionReason})`;
|
|
95
94
|
const confidence = detail.confidence.toFixed(2);
|
|
96
|
-
|
|
97
|
-
console.log(`[scan] - ${detail.id}: ${status} | ${detail.source} | ${detail.kind} | target=${formatProposalTarget(detail)} | confidence=${confidence} (${detail.confidenceBand})`);
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.log(`[scan] candidate=${detail.candidateType} agent=${detail.agent} provider=${detail.provider}/${detail.model}`);
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
|
-
console.log(`[scan] evidence=${formatEvidence(detail)}`);
|
|
95
|
+
lines.push(`[scan] - ${detail.id}: ${status} | ${detail.source} | ${detail.kind} | target=${formatProposalTarget(detail)} | confidence=${confidence} (${detail.confidenceBand})`, `[scan] candidate=${detail.candidateType} agent=${detail.agent} provider=${detail.provider}/${detail.model}`, `[scan] evidence=${formatEvidence(detail)}`);
|
|
102
96
|
if (detail.status === 'applied' &&
|
|
103
97
|
detail.propertyChanges &&
|
|
104
98
|
detail.propertyChanges.length) {
|
|
@@ -108,11 +102,11 @@ function printAiInferenceVerbose(details) {
|
|
|
108
102
|
return `${change.key}: ${from} -> ${to}`;
|
|
109
103
|
});
|
|
110
104
|
for (const line of formatted) {
|
|
111
|
-
|
|
112
|
-
console.log(`[scan] changes=${line}`);
|
|
105
|
+
lines.push(`[scan] changes=${line}`);
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
}
|
|
109
|
+
return lines;
|
|
116
110
|
}
|
|
117
111
|
function formatUsd(value) {
|
|
118
112
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
@@ -168,6 +162,9 @@ function createProgram() {
|
|
|
168
162
|
let sentryAiMode;
|
|
169
163
|
let sentryAiProvider;
|
|
170
164
|
const isInteractive = process.stdout.isTTY;
|
|
165
|
+
// True once Clack owns the terminal: raw `[scan]` lines would break its
|
|
166
|
+
// guide rail, so they go through the renderer or are skipped.
|
|
167
|
+
let friendlyTty = false;
|
|
171
168
|
// Parse and validate --git-context if provided
|
|
172
169
|
let parsedGitContext;
|
|
173
170
|
if (options.gitContext) {
|
|
@@ -238,10 +235,19 @@ function createProgram() {
|
|
|
238
235
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/scan-pipeline'))),
|
|
239
236
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/graph-mapping'))),
|
|
240
237
|
]);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
const progressUi = await (0, scan_progress_renderer_1.createScanProgressRenderer)({
|
|
239
|
+
isTTY: Boolean(isInteractive),
|
|
240
|
+
noColor: Boolean(typeof process.env.NO_COLOR === 'string' &&
|
|
241
|
+
process.env.NO_COLOR.length > 0),
|
|
242
|
+
projectLabel: resolvedScanRoot,
|
|
243
|
+
version: package_json_1.default.version,
|
|
244
|
+
});
|
|
245
|
+
progressUi.start();
|
|
246
|
+
friendlyTty = progressUi.usesClackChrome;
|
|
247
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(friendlyTty && !options.aiVerbose);
|
|
248
|
+
// Technical meters, shown as one block after the scan (TTY) or
|
|
249
|
+
// printed as before (non-TTY).
|
|
250
|
+
const technicalLines = [];
|
|
245
251
|
const flags = {
|
|
246
252
|
exclude: options.exclude,
|
|
247
253
|
minimumConfidence: typeof options.minimumConfidence === 'string'
|
|
@@ -326,8 +332,14 @@ function createProgram() {
|
|
|
326
332
|
config.aiMode = 'platform';
|
|
327
333
|
}
|
|
328
334
|
if (isInteractive) {
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
const quotaLine = `[scan] quota: scans_remaining=${preflight.scansRemaining} ai_tokens_remaining=${preflight.aiTokensRemaining} job_id=${preflight.jobId} working_budget=${config.aiBudgetTokens ?? 0}`;
|
|
336
|
+
if (friendlyTty) {
|
|
337
|
+
technicalLines.push(quotaLine);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
// eslint-disable-next-line no-console
|
|
341
|
+
console.log(quotaLine);
|
|
342
|
+
}
|
|
331
343
|
}
|
|
332
344
|
}
|
|
333
345
|
else if (!workspaceApiKey &&
|
|
@@ -351,8 +363,14 @@ function createProgram() {
|
|
|
351
363
|
config.aiMode = 'platform';
|
|
352
364
|
}
|
|
353
365
|
if (isInteractive) {
|
|
354
|
-
|
|
355
|
-
|
|
366
|
+
const sessionLine = `[scan] anonymous platform AI: job_id=${session.jobId} working_budget=${config.aiBudgetTokens ?? 0} server_cap=${session.suggestedAiBudgetTokens} (claim debits actual tokens used)`;
|
|
367
|
+
if (friendlyTty) {
|
|
368
|
+
technicalLines.push(sessionLine);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
// eslint-disable-next-line no-console
|
|
372
|
+
console.log(sessionLine);
|
|
373
|
+
}
|
|
356
374
|
}
|
|
357
375
|
}
|
|
358
376
|
catch (anonSessionError) {
|
|
@@ -392,33 +410,50 @@ function createProgram() {
|
|
|
392
410
|
return;
|
|
393
411
|
}
|
|
394
412
|
if (isInteractive && warnings.length > 0) {
|
|
395
|
-
|
|
396
|
-
|
|
413
|
+
if (friendlyTty) {
|
|
414
|
+
for (const w of warnings)
|
|
415
|
+
progressUi.warn(w);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
// eslint-disable-next-line no-console
|
|
419
|
+
console.warn(`[scan] warnings:\n${warnings.map((w) => ` - ${w}`).join('\n')}`);
|
|
420
|
+
}
|
|
397
421
|
}
|
|
398
422
|
const { scanResult, redFlags } = await runScanPipeline(resolvedScanRoot, config, (progress) => {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
console.log(`[scan] ${progress.phase}: ${progress.message ?? ''}`.trim());
|
|
423
|
+
progressUi.onProgress(progress);
|
|
424
|
+
}, (recognition) => {
|
|
425
|
+
progressUi.onRecognition(recognition);
|
|
403
426
|
});
|
|
404
|
-
if (scanResult.
|
|
427
|
+
if (scanResult.aiInferenceSummary) {
|
|
428
|
+
progressUi.onAiResult({
|
|
429
|
+
proposalsApplied: scanResult.aiInferenceSummary.proposalsApplied,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
// Keep technical enrichment/AI meter lines out of the friendly TTY
|
|
433
|
+
// progress UI; still print in CI / non-TTY, or with --ai-verbose.
|
|
434
|
+
const showTechnicalScanMeters = !isInteractive || Boolean(options.aiVerbose);
|
|
435
|
+
if (showTechnicalScanMeters &&
|
|
436
|
+
scanResult.structuralEnrichmentSummary) {
|
|
405
437
|
const st = scanResult.structuralEnrichmentSummary;
|
|
406
|
-
|
|
407
|
-
console.log(`[scan] structural enrichment: proposals=${st.proposalsGenerated} applied=${st.proposalsApplied} rejected=${st.proposalsRejected}`);
|
|
438
|
+
technicalLines.push(`[scan] structural enrichment: proposals=${st.proposalsGenerated} applied=${st.proposalsApplied} rejected=${st.proposalsRejected}`);
|
|
408
439
|
}
|
|
409
|
-
if (scanResult.aiInferenceSummary) {
|
|
440
|
+
if (showTechnicalScanMeters && scanResult.aiInferenceSummary) {
|
|
410
441
|
const s = scanResult.aiInferenceSummary;
|
|
411
|
-
|
|
412
|
-
console.log(`[scan] llm-inference summary: candidates=${s.candidatesConsidered} proposals=${s.proposalsGenerated} (provider=${s.proposalsGeneratedProvider}) applied=${s.proposalsApplied} (provider=${s.proposalsAppliedProvider}) rejected=${s.proposalsRejected} (${s.aiProvider}/${s.aiModel})`);
|
|
442
|
+
technicalLines.push(`[scan] llm-inference summary: candidates=${s.candidatesConsidered} proposals=${s.proposalsGenerated} (provider=${s.proposalsGeneratedProvider}) applied=${s.proposalsApplied} (provider=${s.proposalsAppliedProvider}) rejected=${s.proposalsRejected} (${s.aiProvider}/${s.aiModel})`,
|
|
413
443
|
// Always show real provider token usage (budget_cap is only a ceiling, not cost).
|
|
414
|
-
|
|
415
|
-
console.log(`[scan] ai-usage: provider_calls=${s.providerCalls} tokens_in=${s.inputTokens} tokens_out=${s.outputTokens} tokens_total=${s.totalTokens}` +
|
|
444
|
+
`[scan] ai-usage: provider_calls=${s.providerCalls} tokens_in=${s.inputTokens} tokens_out=${s.outputTokens} tokens_total=${s.totalTokens}` +
|
|
416
445
|
(typeof s.estimatedCostUsd === 'number'
|
|
417
446
|
? ` estimated_cost_usd=${formatUsd(s.estimatedCostUsd)}`
|
|
418
447
|
: ''));
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
448
|
+
}
|
|
449
|
+
if (options.aiVerbose &&
|
|
450
|
+
scanResult.aiInferenceSummary &&
|
|
451
|
+
scanResult.aiInferenceProposalDetails) {
|
|
452
|
+
technicalLines.push(...formatAiInferenceVerbose(scanResult.aiInferenceProposalDetails));
|
|
453
|
+
}
|
|
454
|
+
// Friendly TTY only shows the block on request (--ai-verbose).
|
|
455
|
+
if (!friendlyTty || options.aiVerbose) {
|
|
456
|
+
progressUi.showTechnicalDetails('Scan details', technicalLines);
|
|
422
457
|
}
|
|
423
458
|
for (const w of scanResult.warnings ?? []) {
|
|
424
459
|
if (w.startsWith('ai-provider:')) {
|
|
@@ -431,12 +466,10 @@ function createProgram() {
|
|
|
431
466
|
failurePhase: 'ai_provider',
|
|
432
467
|
failureCode: 'ai_provider_warning',
|
|
433
468
|
});
|
|
434
|
-
|
|
435
|
-
console.warn(`[scan] ${w}`);
|
|
469
|
+
progressUi.warn(w);
|
|
436
470
|
}
|
|
437
471
|
else if (w.startsWith('red-flag:')) {
|
|
438
|
-
|
|
439
|
-
console.warn(`[scan] ${w}`);
|
|
472
|
+
progressUi.warn(w);
|
|
440
473
|
}
|
|
441
474
|
}
|
|
442
475
|
if (scanResult.errors?.length) {
|
|
@@ -498,10 +531,14 @@ function createProgram() {
|
|
|
498
531
|
redFlags,
|
|
499
532
|
gitContext: parsedGitContext,
|
|
500
533
|
});
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
//
|
|
504
|
-
|
|
534
|
+
// Friendly TTY/plain progress line (additive).
|
|
535
|
+
progressUi.onWroteDataflow(dataflowOutputPath);
|
|
536
|
+
// Machine line for scripts / CI (non-TTY). The friendly TTY UI
|
|
537
|
+
// shows the path in its own success line instead.
|
|
538
|
+
if (!friendlyTty) {
|
|
539
|
+
// eslint-disable-next-line no-console
|
|
540
|
+
console.log(`[scan] dataflow.json written to ${dataflowOutputPath}`);
|
|
541
|
+
}
|
|
505
542
|
const skipAutoUpload = Boolean(options.skipAutoUpload) ||
|
|
506
543
|
(0, upload_env_1.resolveSkipAutoUpload)(process.env);
|
|
507
544
|
if (!skipAutoUpload) {
|
|
@@ -512,7 +549,7 @@ function createProgram() {
|
|
|
512
549
|
redFlags,
|
|
513
550
|
gitContext: parsedGitContext,
|
|
514
551
|
});
|
|
515
|
-
await runDataflowUpload({
|
|
552
|
+
const uploadResult = await runDataflowUpload({
|
|
516
553
|
apiKey: workspaceApiKey,
|
|
517
554
|
dataflow: dataflowWrapper,
|
|
518
555
|
projectName: resolvedProjectName,
|
|
@@ -520,16 +557,26 @@ function createProgram() {
|
|
|
520
557
|
logPrefix: '[scan]',
|
|
521
558
|
cliUsageSessionId: usageSessionId,
|
|
522
559
|
command: 'scan',
|
|
560
|
+
quiet: friendlyTty,
|
|
523
561
|
});
|
|
562
|
+
if (uploadResult.previewUrl) {
|
|
563
|
+
progressUi.onPreviewUrl(uploadResult.previewUrl, uploadResult.notice);
|
|
564
|
+
}
|
|
524
565
|
}
|
|
525
566
|
catch (uploadError) {
|
|
526
567
|
const uploadMessage = uploadError instanceof Error
|
|
527
568
|
? uploadError.message
|
|
528
569
|
: 'Unknown upload error.';
|
|
529
|
-
|
|
530
|
-
|
|
570
|
+
if (friendlyTty) {
|
|
571
|
+
progressUi.warn(`Auto-upload failed: ${uploadMessage}`);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
// eslint-disable-next-line no-console
|
|
575
|
+
console.error(`[scan] Auto-upload failed: ${uploadMessage}`);
|
|
576
|
+
}
|
|
531
577
|
}
|
|
532
578
|
}
|
|
579
|
+
progressUi.finish();
|
|
533
580
|
}
|
|
534
581
|
catch (dataflowError) {
|
|
535
582
|
reportedFailure = {
|
|
@@ -574,14 +621,15 @@ function createProgram() {
|
|
|
574
621
|
: undefined,
|
|
575
622
|
});
|
|
576
623
|
quotaCompletionReported = true;
|
|
577
|
-
|
|
624
|
+
// The Clack outro already closes the run in friendly TTY.
|
|
625
|
+
if (isInteractive && !friendlyTty) {
|
|
578
626
|
// eslint-disable-next-line no-console
|
|
579
627
|
console.log('[scan] Scan finished — you can start a new scan now.');
|
|
580
628
|
}
|
|
581
629
|
}
|
|
582
630
|
}
|
|
583
631
|
catch (err) {
|
|
584
|
-
const message =
|
|
632
|
+
const message = (0, fetch_failure_1.describeThrownError)(err);
|
|
585
633
|
fallbackFailureMessage = message;
|
|
586
634
|
const { CliScanQuotaExceededError, CliScanAlreadyRunningError } = await Promise.resolve().then(() => __importStar(require('./platform-api/scan-quota-client')));
|
|
587
635
|
const quotaBlocked = err instanceof CliScanQuotaExceededError;
|
|
@@ -4,5 +4,10 @@ export declare function resolveByokProvider(env: NodeJS.ProcessEnv): string | un
|
|
|
4
4
|
export declare function resolveByokModel(env: NodeJS.ProcessEnv): string | undefined;
|
|
5
5
|
export declare function resolveScanAiInference(env: NodeJS.ProcessEnv): string | undefined;
|
|
6
6
|
export declare function resolveHostedInferProxyUrl(env: NodeJS.ProcessEnv): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Mute SCAN_AI_DEBUG logs for this run. The interactive progress UI sets this:
|
|
9
|
+
* raw `[dataparade-ai]` lines written mid-spinner break its layout.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setScanAiDebugSuppressed(suppressed: boolean): void;
|
|
7
12
|
/** Extra provider HTTP / normalization logging (all providers, not OpenAI-only). */
|
|
8
13
|
export declare function isScanAiDebugEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
@@ -6,6 +6,7 @@ exports.resolveByokProvider = resolveByokProvider;
|
|
|
6
6
|
exports.resolveByokModel = resolveByokModel;
|
|
7
7
|
exports.resolveScanAiInference = resolveScanAiInference;
|
|
8
8
|
exports.resolveHostedInferProxyUrl = resolveHostedInferProxyUrl;
|
|
9
|
+
exports.setScanAiDebugSuppressed = setScanAiDebugSuppressed;
|
|
9
10
|
exports.isScanAiDebugEnabled = isScanAiDebugEnabled;
|
|
10
11
|
function resolveWorkspaceApiKey(env) {
|
|
11
12
|
const value = env.DATAPARADE_WORKSPACE_API_KEY?.trim();
|
|
@@ -35,9 +36,19 @@ function parseTruthyEnvFlag(value) {
|
|
|
35
36
|
if (!value)
|
|
36
37
|
return false;
|
|
37
38
|
const normalized = value.trim().toLowerCase();
|
|
38
|
-
return normalized ===
|
|
39
|
+
return normalized === 'true';
|
|
40
|
+
}
|
|
41
|
+
let scanAiDebugSuppressed = false;
|
|
42
|
+
/**
|
|
43
|
+
* Mute SCAN_AI_DEBUG logs for this run. The interactive progress UI sets this:
|
|
44
|
+
* raw `[dataparade-ai]` lines written mid-spinner break its layout.
|
|
45
|
+
*/
|
|
46
|
+
function setScanAiDebugSuppressed(suppressed) {
|
|
47
|
+
scanAiDebugSuppressed = suppressed;
|
|
39
48
|
}
|
|
40
49
|
/** Extra provider HTTP / normalization logging (all providers, not OpenAI-only). */
|
|
41
50
|
function isScanAiDebugEnabled(env = process.env) {
|
|
51
|
+
if (scanAiDebugSuppressed)
|
|
52
|
+
return false;
|
|
42
53
|
return parseTruthyEnvFlag(env.SCAN_AI_DEBUG);
|
|
43
54
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ScanConfiguration, ScanProgress } from '../types';
|
|
2
2
|
import type { OrchestratorScanResult } from './orchestrator-result';
|
|
3
|
+
import type { ScanRecognitionPayload } from '../../ui/types';
|
|
3
4
|
/**
|
|
4
5
|
* Full CLI scan pipeline: deterministic structural scan, optional structural enrichment,
|
|
5
6
|
* optional LLM inference, and LangSmith tracing when enabled.
|
|
6
7
|
*/
|
|
7
|
-
export declare function runScanPipeline(rootPath: string, config: ScanConfiguration, onProgress?: (progress: ScanProgress) => void): Promise<OrchestratorScanResult>;
|
|
8
|
+
export declare function runScanPipeline(rootPath: string, config: ScanConfiguration, onProgress?: (progress: ScanProgress) => void, onRecognition?: (payload: ScanRecognitionPayload) => void): Promise<OrchestratorScanResult>;
|
|
@@ -106,7 +106,7 @@ function buildThirdPartyCoverage(input) {
|
|
|
106
106
|
}
|
|
107
107
|
return { autofilled, suggested, unknown };
|
|
108
108
|
}
|
|
109
|
-
async function runScanPipelineInner(rootPath, config, onProgress) {
|
|
109
|
+
async function runScanPipelineInner(rootPath, config, onProgress, onRecognition) {
|
|
110
110
|
const start = Date.now();
|
|
111
111
|
const warnings = [];
|
|
112
112
|
const errors = [];
|
|
@@ -120,6 +120,9 @@ async function runScanPipelineInner(rootPath, config, onProgress) {
|
|
|
120
120
|
const components = work.components;
|
|
121
121
|
const dataFlows = work.dataFlows;
|
|
122
122
|
const { files, findings, sections, filesScanned } = work;
|
|
123
|
+
// Stable recognition surface for teaching lines (findings + components after
|
|
124
|
+
// deterministic phases). No scanner-internal coupling beyond this payload.
|
|
125
|
+
onRecognition?.({ findings, components });
|
|
123
126
|
const subTypesFilledEarly = (0, third_party_subtype_1.ensureThirdPartySubTypes)(components);
|
|
124
127
|
if (subTypesFilledEarly > 0) {
|
|
125
128
|
warnings.push(`third-party-subtype: inferred subType for ${subTypesFilledEarly} third-party component(s) from vendor/name heuristics.`);
|
|
@@ -171,7 +174,7 @@ async function runScanPipelineInner(rootPath, config, onProgress) {
|
|
|
171
174
|
...component,
|
|
172
175
|
properties: { ...component.properties },
|
|
173
176
|
}));
|
|
174
|
-
(0, scanner_1.emitScanProgress)(onProgress, '
|
|
177
|
+
(0, scanner_1.emitScanProgress)(onProgress, 'ai_enrichment', 0.85, filesScanned, 'Running LLM inference...');
|
|
175
178
|
const orchOptions = (0, ai_orchestrator_options_1.buildAgentOrchestratorOptions)(config, {
|
|
176
179
|
llmEnabled: true,
|
|
177
180
|
skipStructuralHeuristics: true,
|
|
@@ -308,11 +311,11 @@ async function runScanPipelineInner(rootPath, config, onProgress) {
|
|
|
308
311
|
* Full CLI scan pipeline: deterministic structural scan, optional structural enrichment,
|
|
309
312
|
* optional LLM inference, and LangSmith tracing when enabled.
|
|
310
313
|
*/
|
|
311
|
-
async function runScanPipeline(rootPath, config, onProgress) {
|
|
314
|
+
async function runScanPipeline(rootPath, config, onProgress, onRecognition) {
|
|
312
315
|
return (0, langsmith_tracing_1.traceDataparadeScan)({
|
|
313
316
|
rootPath: rootPath.toString(),
|
|
314
317
|
projectName: config.projectName,
|
|
315
318
|
enableAiInference: config.enableAiInference,
|
|
316
|
-
run: () => runScanPipelineInner(rootPath, config, onProgress),
|
|
319
|
+
run: () => runScanPipelineInner(rootPath, config, onProgress, onRecognition),
|
|
317
320
|
});
|
|
318
321
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Socket-level fetch failures (no HTTP response), including Node's "fetch failed". */
|
|
2
|
+
export declare function isTransientFetchError(err: unknown): boolean;
|
|
3
|
+
/** Code plus cause text, without repeating the generic "fetch failed" wrapper. */
|
|
4
|
+
export declare function fetchFailureDetail(err: unknown): string;
|
|
5
|
+
export declare function describeRequestTarget(url: string, method: string): string;
|
|
6
|
+
export declare function toApiReachabilityError(err: unknown, url: string, method: string, attempts: number): Error;
|
|
7
|
+
/**
|
|
8
|
+
* Scan-command message. Unwraps a bare "fetch failed" when a caller did not
|
|
9
|
+
* already attach the request target.
|
|
10
|
+
*/
|
|
11
|
+
export declare function describeThrownError(err: unknown): string;
|