@dataparade/cli 0.0.28 → 0.0.30
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 +4 -1
- package/dist/package.json +2 -2
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +6 -1
- package/dist/src/cli/scan-interrupt-handlers.d.ts +34 -0
- package/dist/src/cli/scan-interrupt-handlers.js +105 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +163 -58
- package/dist/src/config/scan-env.d.ts +5 -2
- package/dist/src/config/scan-env.js +8 -2
- package/dist/src/platform-api/fetch-failure.d.ts +5 -0
- package/dist/src/platform-api/fetch-failure.js +13 -0
- package/dist/src/platform-api/scan-quota-client.d.ts +3 -1
- package/dist/src/platform-api/scan-quota-client.js +41 -28
- package/dist/src/platform-api/upload-client.d.ts +5 -0
- package/dist/src/platform-api/upload-client.js +11 -1
- package/dist/src/ui/scan-progress-renderer.d.ts +38 -0
- package/dist/src/ui/scan-progress-renderer.js +110 -3
- package/dist/src/ui/types.d.ts +5 -0
- package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +26 -0
- package/dist/tests/unit/cli/scan-ai-session-fallback.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-ai-session-fallback.spec.js +156 -0
- package/dist/tests/unit/cli/scan-interrupt-handlers.spec.d.ts +1 -0
- package/dist/tests/unit/cli/scan-interrupt-handlers.spec.js +154 -0
- package/dist/tests/unit/cli/scan-quota-flow.spec.js +2 -2
- package/dist/tests/unit/platform-api/read-cli-api-error-message.spec.js +2 -2
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +155 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +24 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +19 -6
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +5 -2
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +5 -2
- package/package.json +2 -2
|
@@ -7,6 +7,7 @@ exports.resolveByokModel = resolveByokModel;
|
|
|
7
7
|
exports.resolveScanAiInference = resolveScanAiInference;
|
|
8
8
|
exports.resolveHostedInferProxyUrl = resolveHostedInferProxyUrl;
|
|
9
9
|
exports.setScanAiDebugSuppressed = setScanAiDebugSuppressed;
|
|
10
|
+
exports.isScanAiDebugSuppressed = isScanAiDebugSuppressed;
|
|
10
11
|
exports.isScanAiDebugEnabled = isScanAiDebugEnabled;
|
|
11
12
|
function resolveWorkspaceApiKey(env) {
|
|
12
13
|
const value = env.DATAPARADE_WORKSPACE_API_KEY?.trim();
|
|
@@ -40,12 +41,17 @@ function parseTruthyEnvFlag(value) {
|
|
|
40
41
|
}
|
|
41
42
|
let scanAiDebugSuppressed = false;
|
|
42
43
|
/**
|
|
43
|
-
* Mute SCAN_AI_DEBUG logs
|
|
44
|
-
* raw `[dataparade-ai]` lines
|
|
44
|
+
* Mute SCAN_AI_DEBUG logs and transient AI notices (e.g. network retries) for
|
|
45
|
+
* this run. The interactive progress UI sets this: raw `[dataparade-ai]` lines
|
|
46
|
+
* written mid-spinner break its layout.
|
|
45
47
|
*/
|
|
46
48
|
function setScanAiDebugSuppressed(suppressed) {
|
|
47
49
|
scanAiDebugSuppressed = suppressed;
|
|
48
50
|
}
|
|
51
|
+
/** True while the interactive UI owns the terminal (see setScanAiDebugSuppressed). */
|
|
52
|
+
function isScanAiDebugSuppressed() {
|
|
53
|
+
return scanAiDebugSuppressed;
|
|
54
|
+
}
|
|
49
55
|
/** Extra provider HTTP / normalization logging (all providers, not OpenAI-only). */
|
|
50
56
|
function isScanAiDebugEnabled(env = process.env) {
|
|
51
57
|
if (scanAiDebugSuppressed)
|
|
@@ -9,3 +9,8 @@ export declare function toApiReachabilityError(err: unknown, url: string, method
|
|
|
9
9
|
* already attach the request target.
|
|
10
10
|
*/
|
|
11
11
|
export declare function describeThrownError(err: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
* Short reason for an optional platform step (AI session, upload) that failed,
|
|
14
|
+
* for a one-line "… unavailable (<reason>)" message.
|
|
15
|
+
*/
|
|
16
|
+
export declare function describeUnavailableReason(err: unknown): string;
|
|
@@ -5,6 +5,7 @@ exports.fetchFailureDetail = fetchFailureDetail;
|
|
|
5
5
|
exports.describeRequestTarget = describeRequestTarget;
|
|
6
6
|
exports.toApiReachabilityError = toApiReachabilityError;
|
|
7
7
|
exports.describeThrownError = describeThrownError;
|
|
8
|
+
exports.describeUnavailableReason = describeUnavailableReason;
|
|
8
9
|
const TRANSIENT_CAUSE_CODES = new Set([
|
|
9
10
|
'ECONNRESET',
|
|
10
11
|
'ECONNREFUSED',
|
|
@@ -83,3 +84,15 @@ function describeThrownError(err) {
|
|
|
83
84
|
}
|
|
84
85
|
return `Could not reach the DataParade API: ${detail}. Run the scan again.`;
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Short reason for an optional platform step (AI session, upload) that failed,
|
|
89
|
+
* for a one-line "… unavailable (<reason>)" message.
|
|
90
|
+
*/
|
|
91
|
+
function describeUnavailableReason(err) {
|
|
92
|
+
if (!(err instanceof Error))
|
|
93
|
+
return 'unknown error';
|
|
94
|
+
if (isTransientFetchError(err)) {
|
|
95
|
+
return `could not reach the DataParade API: ${fetchFailureDetail(err)}`;
|
|
96
|
+
}
|
|
97
|
+
return err.message.trim().replace(/\.$/, '') || 'unknown error';
|
|
98
|
+
}
|
|
@@ -26,8 +26,10 @@ export declare function cliScanPreflight(input: {
|
|
|
26
26
|
export declare function cliScanComplete(input: {
|
|
27
27
|
apiKey: string;
|
|
28
28
|
jobId: string;
|
|
29
|
-
status:
|
|
29
|
+
status: 'completed' | 'failed';
|
|
30
30
|
aiTokensUsed?: number;
|
|
31
31
|
failureCode?: string;
|
|
32
32
|
failureMessage?: string;
|
|
33
|
+
/** Optional fetch abort timeout (e.g. interrupt path). */
|
|
34
|
+
timeoutMs?: number;
|
|
33
35
|
}): Promise<void>;
|
|
@@ -9,8 +9,8 @@ const read_cli_api_error_message_1 = require("./read-cli-api-error-message");
|
|
|
9
9
|
class CliScanQuotaExceededError extends Error {
|
|
10
10
|
constructor(message) {
|
|
11
11
|
super(message);
|
|
12
|
-
this.code =
|
|
13
|
-
this.name =
|
|
12
|
+
this.code = 'scan_quota_exceeded';
|
|
13
|
+
this.name = 'CliScanQuotaExceededError';
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
exports.CliScanQuotaExceededError = CliScanQuotaExceededError;
|
|
@@ -18,20 +18,20 @@ exports.CliScanQuotaExceededError = CliScanQuotaExceededError;
|
|
|
18
18
|
class CliScanAlreadyRunningError extends Error {
|
|
19
19
|
constructor(message) {
|
|
20
20
|
super(message);
|
|
21
|
-
this.code =
|
|
22
|
-
this.name =
|
|
21
|
+
this.code = 'scan_already_running';
|
|
22
|
+
this.name = 'CliScanAlreadyRunningError';
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.CliScanAlreadyRunningError = CliScanAlreadyRunningError;
|
|
26
26
|
function buildHeaders(apiKey) {
|
|
27
27
|
return {
|
|
28
28
|
Authorization: `Bearer ${apiKey}`,
|
|
29
|
-
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
async function cliScanPreflight(input) {
|
|
33
33
|
const res = await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/preflight`, {
|
|
34
|
-
method:
|
|
34
|
+
method: 'POST',
|
|
35
35
|
headers: buildHeaders(input.apiKey),
|
|
36
36
|
body: JSON.stringify({
|
|
37
37
|
enableAi: input.enableAi,
|
|
@@ -53,10 +53,10 @@ async function cliScanPreflight(input) {
|
|
|
53
53
|
catch {
|
|
54
54
|
// ignore
|
|
55
55
|
}
|
|
56
|
-
if (res.status === 403 && code ===
|
|
56
|
+
if (res.status === 403 && code === 'scan_quota_exceeded') {
|
|
57
57
|
throw new CliScanQuotaExceededError(message);
|
|
58
58
|
}
|
|
59
|
-
if (res.status === 409 && code ===
|
|
59
|
+
if (res.status === 409 && code === 'scan_already_running') {
|
|
60
60
|
throw new CliScanAlreadyRunningError(message);
|
|
61
61
|
}
|
|
62
62
|
throw new Error(message);
|
|
@@ -64,26 +64,39 @@ async function cliScanPreflight(input) {
|
|
|
64
64
|
return (await res.json());
|
|
65
65
|
}
|
|
66
66
|
async function cliScanComplete(input) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
const controller = typeof input.timeoutMs === 'number' && input.timeoutMs > 0
|
|
68
|
+
? new AbortController()
|
|
69
|
+
: undefined;
|
|
70
|
+
const timer = controller
|
|
71
|
+
? setTimeout(() => controller.abort(), input.timeoutMs)
|
|
72
|
+
: undefined;
|
|
73
|
+
try {
|
|
74
|
+
const res = await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/${encodeURIComponent(input.jobId)}/complete`, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: buildHeaders(input.apiKey),
|
|
77
|
+
signal: controller?.signal,
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
status: input.status,
|
|
80
|
+
aiTokensUsed: input.aiTokensUsed,
|
|
81
|
+
failureCode: input.failureCode,
|
|
82
|
+
failureMessage: input.failureMessage,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const fallback = `Scan complete report failed (${res.status})`;
|
|
87
|
+
let message = fallback;
|
|
88
|
+
try {
|
|
89
|
+
const body = await res.json();
|
|
90
|
+
message = (0, read_cli_api_error_message_1.readCliApiErrorMessage)(body, fallback).message;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// ignore
|
|
94
|
+
}
|
|
95
|
+
throw new Error(message);
|
|
86
96
|
}
|
|
87
|
-
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (timer)
|
|
100
|
+
clearTimeout(timer);
|
|
88
101
|
}
|
|
89
102
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ScanUploadFile } from '../upload/collect-scan-sidecars';
|
|
2
2
|
import type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse } from './upload.types';
|
|
3
3
|
export type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse, } from './upload.types';
|
|
4
|
+
/** Upload rejected by the API; `status` is the HTTP status (429 = rate limit). */
|
|
5
|
+
export declare class CliUploadError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
constructor(message: string, status: number);
|
|
8
|
+
}
|
|
4
9
|
export declare function cliUploadAnonymousPreview(input: {
|
|
5
10
|
dataflow: unknown;
|
|
6
11
|
projectName?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliUploadError = void 0;
|
|
3
4
|
exports.cliUploadAnonymousPreview = cliUploadAnonymousPreview;
|
|
4
5
|
exports.cliUploadPreview = cliUploadPreview;
|
|
5
6
|
const pack_scan_upload_1 = require("../upload/pack-scan-upload");
|
|
@@ -10,6 +11,15 @@ function buildAuthHeaders(apiKey) {
|
|
|
10
11
|
'Content-Type': 'application/json',
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
/** Upload rejected by the API; `status` is the HTTP status (429 = rate limit). */
|
|
15
|
+
class CliUploadError extends Error {
|
|
16
|
+
constructor(message, status) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.name = 'CliUploadError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CliUploadError = CliUploadError;
|
|
13
23
|
async function parseUploadError(res) {
|
|
14
24
|
let message = `Upload failed (${res.status})`;
|
|
15
25
|
try {
|
|
@@ -24,7 +34,7 @@ async function parseUploadError(res) {
|
|
|
24
34
|
catch {
|
|
25
35
|
// ignore
|
|
26
36
|
}
|
|
27
|
-
throw new
|
|
37
|
+
throw new CliUploadError(message, res.status);
|
|
28
38
|
}
|
|
29
39
|
async function cliUploadAnonymousPreview(input) {
|
|
30
40
|
const res = await fetch(`${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/preview`, {
|
|
@@ -12,6 +12,14 @@ export declare function formatAiStepResult(result: ScanAiStepResult): string;
|
|
|
12
12
|
export declare function formatOutputPath(outputPath: string): string;
|
|
13
13
|
/** Prefer a short, human path in the header (home → ~). */
|
|
14
14
|
export declare function formatProjectLabel(projectPath: string): string;
|
|
15
|
+
export type ScanUploadFailure = {
|
|
16
|
+
/** Why the upload failed, without a trailing period. */
|
|
17
|
+
reason: string;
|
|
18
|
+
/** Exact command to retry the upload. */
|
|
19
|
+
retryCommand: string;
|
|
20
|
+
/** Optional extra advice, e.g. how to avoid the anonymous per-IP cap. */
|
|
21
|
+
hint?: string;
|
|
22
|
+
};
|
|
15
23
|
/**
|
|
16
24
|
* Staged scan progress for TTY (Clack) and plain logs for non-TTY / NO_COLOR.
|
|
17
25
|
*/
|
|
@@ -25,8 +33,15 @@ export declare class ScanProgressRenderer {
|
|
|
25
33
|
private readonly version?;
|
|
26
34
|
private readonly columns?;
|
|
27
35
|
private readonly colorDepth?;
|
|
36
|
+
private readonly stdin?;
|
|
28
37
|
private readonly clack;
|
|
29
38
|
private started;
|
|
39
|
+
/**
|
|
40
|
+
* Set once the run is closed (finish/abort/fail). The scan keeps running
|
|
41
|
+
* while the interrupt handler reports to the API, and work queued behind a
|
|
42
|
+
* blocking phase must not draw new steps under "Scan cancelled".
|
|
43
|
+
*/
|
|
44
|
+
private closed;
|
|
30
45
|
private recognitionHandled;
|
|
31
46
|
private activeStep;
|
|
32
47
|
private spinner;
|
|
@@ -34,6 +49,7 @@ export declare class ScanProgressRenderer {
|
|
|
34
49
|
private teachingSummaryLines;
|
|
35
50
|
private previewUrl;
|
|
36
51
|
private previewNotice;
|
|
52
|
+
private uploadFailure;
|
|
37
53
|
constructor(options: ScanProgressRendererOptions, clack: ClackPrompts | null);
|
|
38
54
|
/** Test helper: true when Clack chrome is active. */
|
|
39
55
|
get usesClackChrome(): boolean;
|
|
@@ -45,6 +61,11 @@ export declare class ScanProgressRenderer {
|
|
|
45
61
|
onWroteDataflow(outputPath?: string): void;
|
|
46
62
|
/** Store preview URL for the "What to do next" note. Machine line stays in upload. */
|
|
47
63
|
onPreviewUrl(previewUrl: string, notice?: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Auto-upload failed after the local output was written. finish() then
|
|
66
|
+
* says so and prints the retry command instead of the success closing.
|
|
67
|
+
*/
|
|
68
|
+
onUploadFailed(failure: ScanUploadFailure): void;
|
|
48
69
|
/** One plain informational line, e.g. how many files the scan walks. */
|
|
49
70
|
info(message: string): void;
|
|
50
71
|
/**
|
|
@@ -58,7 +79,24 @@ export declare class ScanProgressRenderer {
|
|
|
58
79
|
*/
|
|
59
80
|
showTechnicalDetails(title: string, lines: string[]): void;
|
|
60
81
|
finish(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Cancel an in-flight scan UI (Ctrl+C). Stops the spinner with a red mark
|
|
84
|
+
* in Clack mode; prints a short line in plain mode. Does not run finish().
|
|
85
|
+
*/
|
|
86
|
+
abort(message?: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* End the scan UI on an error: closes the active spinner with the error
|
|
89
|
+
* mark (or logs an error line between steps). Does not run finish().
|
|
90
|
+
*/
|
|
91
|
+
fail(message: string): void;
|
|
61
92
|
private transitionTo;
|
|
93
|
+
/**
|
|
94
|
+
* Clack's spinner puts stdin in raw mode, where Ctrl+C is a keypress it
|
|
95
|
+
* answers with process.exit(0) — skipping our SIGINT handler and leaving
|
|
96
|
+
* the scan job running. The spinner only writes, so hand Ctrl+C back to
|
|
97
|
+
* the terminal as a real signal.
|
|
98
|
+
*/
|
|
99
|
+
private restoreSignalKeys;
|
|
62
100
|
private completeActiveStep;
|
|
63
101
|
private runTeachingStep;
|
|
64
102
|
private prompts;
|
|
@@ -86,6 +86,12 @@ function formatProjectLabel(projectPath) {
|
|
|
86
86
|
class ScanProgressRenderer {
|
|
87
87
|
constructor(options, clack) {
|
|
88
88
|
this.started = false;
|
|
89
|
+
/**
|
|
90
|
+
* Set once the run is closed (finish/abort/fail). The scan keeps running
|
|
91
|
+
* while the interrupt handler reports to the API, and work queued behind a
|
|
92
|
+
* blocking phase must not draw new steps under "Scan cancelled".
|
|
93
|
+
*/
|
|
94
|
+
this.closed = false;
|
|
89
95
|
this.recognitionHandled = false;
|
|
90
96
|
this.activeStep = null;
|
|
91
97
|
this.spinner = null;
|
|
@@ -102,6 +108,7 @@ class ScanProgressRenderer {
|
|
|
102
108
|
this.version = options.version;
|
|
103
109
|
this.columns = options.columns;
|
|
104
110
|
this.colorDepth = options.colorDepth;
|
|
111
|
+
this.stdin = options.stdin;
|
|
105
112
|
this.writeLine =
|
|
106
113
|
options.writeLine ??
|
|
107
114
|
((line) => {
|
|
@@ -145,6 +152,8 @@ class ScanProgressRenderer {
|
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
onProgress(progress) {
|
|
155
|
+
if (this.closed)
|
|
156
|
+
return;
|
|
148
157
|
this.start();
|
|
149
158
|
switch (progress.phase) {
|
|
150
159
|
case 'ingest':
|
|
@@ -169,6 +178,8 @@ class ScanProgressRenderer {
|
|
|
169
178
|
}
|
|
170
179
|
}
|
|
171
180
|
onRecognition(payload) {
|
|
181
|
+
if (this.closed)
|
|
182
|
+
return;
|
|
172
183
|
if (this.recognitionHandled)
|
|
173
184
|
return;
|
|
174
185
|
this.recognitionHandled = true;
|
|
@@ -196,6 +207,8 @@ class ScanProgressRenderer {
|
|
|
196
207
|
}
|
|
197
208
|
/** Close the AI step with one plain-language result line. */
|
|
198
209
|
onAiResult(result) {
|
|
210
|
+
if (this.closed)
|
|
211
|
+
return;
|
|
199
212
|
if (this.activeStep !== 'ai_enrichment')
|
|
200
213
|
return;
|
|
201
214
|
this.completeActiveStep();
|
|
@@ -208,6 +221,8 @@ class ScanProgressRenderer {
|
|
|
208
221
|
}
|
|
209
222
|
}
|
|
210
223
|
onWroteDataflow(outputPath) {
|
|
224
|
+
if (this.closed)
|
|
225
|
+
return;
|
|
211
226
|
this.start();
|
|
212
227
|
this.completeActiveStep();
|
|
213
228
|
const label = 'Saved your data-flow map';
|
|
@@ -225,9 +240,18 @@ class ScanProgressRenderer {
|
|
|
225
240
|
}
|
|
226
241
|
/** Store preview URL for the "What to do next" note. Machine line stays in upload. */
|
|
227
242
|
onPreviewUrl(previewUrl, notice) {
|
|
243
|
+
if (this.closed)
|
|
244
|
+
return;
|
|
228
245
|
this.previewUrl = previewUrl;
|
|
229
246
|
this.previewNotice = notice;
|
|
230
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Auto-upload failed after the local output was written. finish() then
|
|
250
|
+
* says so and prints the retry command instead of the success closing.
|
|
251
|
+
*/
|
|
252
|
+
onUploadFailed(failure) {
|
|
253
|
+
this.uploadFailure = failure;
|
|
254
|
+
}
|
|
231
255
|
/** One plain informational line, e.g. how many files the scan walks. */
|
|
232
256
|
info(message) {
|
|
233
257
|
this.start();
|
|
@@ -243,6 +267,8 @@ class ScanProgressRenderer {
|
|
|
243
267
|
* keeps the `[scan] …` stderr line scripts may grep for.
|
|
244
268
|
*/
|
|
245
269
|
warn(message) {
|
|
270
|
+
if (this.closed)
|
|
271
|
+
return;
|
|
246
272
|
if (this.useClack) {
|
|
247
273
|
this.prompts().log.warn(message);
|
|
248
274
|
}
|
|
@@ -255,6 +281,8 @@ class ScanProgressRenderer {
|
|
|
255
281
|
* Clack folds them into one dimmed note so they don't break the guide rail.
|
|
256
282
|
*/
|
|
257
283
|
showTechnicalDetails(title, lines) {
|
|
284
|
+
if (this.closed)
|
|
285
|
+
return;
|
|
258
286
|
if (lines.length === 0)
|
|
259
287
|
return;
|
|
260
288
|
if (this.useClack) {
|
|
@@ -271,9 +299,21 @@ class ScanProgressRenderer {
|
|
|
271
299
|
}
|
|
272
300
|
}
|
|
273
301
|
finish() {
|
|
302
|
+
if (this.closed)
|
|
303
|
+
return;
|
|
304
|
+
this.closed = true;
|
|
274
305
|
this.completeActiveStep();
|
|
275
306
|
const nextSteps = [];
|
|
276
|
-
|
|
307
|
+
let closing = 'All done — nice work.';
|
|
308
|
+
if (this.uploadFailure) {
|
|
309
|
+
const { reason, retryCommand, hint } = this.uploadFailure;
|
|
310
|
+
nextSteps.push(`The upload did not complete: ${reason}.`);
|
|
311
|
+
nextSteps.push(`Your scan is saved locally. To upload it, run:\n ${retryCommand}`);
|
|
312
|
+
if (hint)
|
|
313
|
+
nextSteps.push(hint);
|
|
314
|
+
closing = 'Scan finished. The upload did not complete.';
|
|
315
|
+
}
|
|
316
|
+
else if (this.previewUrl) {
|
|
277
317
|
nextSteps.push(`Open your diagram:\n${formatPreviewLink(this.previewUrl, this.colorEnabled)}`);
|
|
278
318
|
// Plain mode already got the notice from the upload's own log line.
|
|
279
319
|
if (this.useClack && this.previewNotice) {
|
|
@@ -288,7 +328,7 @@ class ScanProgressRenderer {
|
|
|
288
328
|
// preview URLs and breaks click-to-open.
|
|
289
329
|
this.prompts().log.step('What to do next');
|
|
290
330
|
this.prompts().log.message(nextSteps.join('\n\n'));
|
|
291
|
-
this.prompts().outro(
|
|
331
|
+
this.prompts().outro(closing);
|
|
292
332
|
}
|
|
293
333
|
else {
|
|
294
334
|
this.writePlain('What to do next');
|
|
@@ -301,9 +341,62 @@ class ScanProgressRenderer {
|
|
|
301
341
|
this.writePlain(` ${line}`);
|
|
302
342
|
}
|
|
303
343
|
}
|
|
304
|
-
this.writePlain(
|
|
344
|
+
this.writePlain(closing);
|
|
305
345
|
}
|
|
306
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Cancel an in-flight scan UI (Ctrl+C). Stops the spinner with a red mark
|
|
349
|
+
* in Clack mode; prints a short line in plain mode. Does not run finish().
|
|
350
|
+
*/
|
|
351
|
+
abort(message = 'Scan cancelled') {
|
|
352
|
+
if (this.closed)
|
|
353
|
+
return;
|
|
354
|
+
this.closed = true;
|
|
355
|
+
if (this.useClack && this.spinner) {
|
|
356
|
+
if (typeof this.spinner.cancel === 'function') {
|
|
357
|
+
this.spinner.cancel(message);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.spinner.stop(message);
|
|
361
|
+
}
|
|
362
|
+
this.spinner = null;
|
|
363
|
+
this.activeStep = null;
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this.activeStep = null;
|
|
367
|
+
if (this.useClack) {
|
|
368
|
+
// Between steps: a raw line would break Clack's guide rail.
|
|
369
|
+
this.prompts().log.warn(message);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
this.writePlain(message);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* End the scan UI on an error: closes the active spinner with the error
|
|
376
|
+
* mark (or logs an error line between steps). Does not run finish().
|
|
377
|
+
*/
|
|
378
|
+
fail(message) {
|
|
379
|
+
if (this.closed)
|
|
380
|
+
return;
|
|
381
|
+
this.closed = true;
|
|
382
|
+
if (this.useClack && this.spinner) {
|
|
383
|
+
if (typeof this.spinner.error === 'function') {
|
|
384
|
+
this.spinner.error(message);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
this.spinner.stop(message);
|
|
388
|
+
}
|
|
389
|
+
this.spinner = null;
|
|
390
|
+
this.activeStep = null;
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.activeStep = null;
|
|
394
|
+
if (this.useClack) {
|
|
395
|
+
this.prompts().log.error(message);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
this.writePlain(message);
|
|
399
|
+
}
|
|
307
400
|
transitionTo(step) {
|
|
308
401
|
if (this.activeStep === step || this.completedSteps.has(step)) {
|
|
309
402
|
return;
|
|
@@ -314,11 +407,24 @@ class ScanProgressRenderer {
|
|
|
314
407
|
if (this.useClack) {
|
|
315
408
|
this.spinner = this.prompts().spinner({ withGuide: true });
|
|
316
409
|
this.spinner.start(label);
|
|
410
|
+
this.restoreSignalKeys();
|
|
317
411
|
}
|
|
318
412
|
else {
|
|
319
413
|
this.writePlain(`… ${label}`);
|
|
320
414
|
}
|
|
321
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Clack's spinner puts stdin in raw mode, where Ctrl+C is a keypress it
|
|
418
|
+
* answers with process.exit(0) — skipping our SIGINT handler and leaving
|
|
419
|
+
* the scan job running. The spinner only writes, so hand Ctrl+C back to
|
|
420
|
+
* the terminal as a real signal.
|
|
421
|
+
*/
|
|
422
|
+
restoreSignalKeys() {
|
|
423
|
+
const stdin = this.stdin;
|
|
424
|
+
if (stdin?.isTTY && typeof stdin.setRawMode === 'function') {
|
|
425
|
+
stdin.setRawMode(false);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
322
428
|
completeActiveStep() {
|
|
323
429
|
if (!this.activeStep)
|
|
324
430
|
return;
|
|
@@ -380,6 +486,7 @@ async function createScanProgressRenderer(options) {
|
|
|
380
486
|
projectLabel: options?.projectLabel,
|
|
381
487
|
version: options?.version,
|
|
382
488
|
columns: options?.columns ?? process.stdout.columns,
|
|
489
|
+
stdin: options?.stdin ?? process.stdin,
|
|
383
490
|
colorDepth: options?.colorDepth ??
|
|
384
491
|
(typeof process.stdout.getColorDepth === 'function'
|
|
385
492
|
? process.stdout.getColorDepth()
|
package/dist/src/ui/types.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface ScanProgressRendererOptions {
|
|
|
25
25
|
writeLine?: (line: string) => void;
|
|
26
26
|
/** Injected Clack module. Tests pass a mock; production loads the ESM package. */
|
|
27
27
|
prompts?: typeof import('@clack/prompts');
|
|
28
|
+
/** Terminal input whose raw mode the spinner toggles. Defaults to process.stdin. */
|
|
29
|
+
stdin?: {
|
|
30
|
+
isTTY?: boolean;
|
|
31
|
+
setRawMode?: (mode: boolean) => unknown;
|
|
32
|
+
};
|
|
28
33
|
}
|
|
29
34
|
export interface TeachingLineGroups {
|
|
30
35
|
routes: string[];
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const platform_proxy_provider_1 = require("../../../src/ai-enrichment/providers/platform-proxy-provider");
|
|
4
|
+
const scan_env_1 = require("../../../src/config/scan-env");
|
|
4
5
|
describe('PlatformProxyProvider', () => {
|
|
5
6
|
const originalFetch = global.fetch;
|
|
6
7
|
afterEach(() => {
|
|
7
8
|
global.fetch = originalFetch;
|
|
9
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
10
|
+
jest.restoreAllMocks();
|
|
8
11
|
});
|
|
9
12
|
it('submits a task and polls until completed', async () => {
|
|
10
13
|
const calls = [];
|
|
@@ -199,4 +202,27 @@ describe('PlatformProxyProvider', () => {
|
|
|
199
202
|
});
|
|
200
203
|
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Could not reach the DataParade API (POST http://localhost:3000/api/scans/cli/ai/infer/tasks): ECONNRESET: other side closed. Tried 3 times. Run the scan again.');
|
|
201
204
|
});
|
|
205
|
+
it('keeps retry notices out of the terminal while the progress UI owns it', async () => {
|
|
206
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
207
|
+
global.fetch = jest.fn(async () => {
|
|
208
|
+
const err = new TypeError('fetch failed');
|
|
209
|
+
err.cause = Object.assign(new Error('other side closed'), {
|
|
210
|
+
code: 'ECONNRESET',
|
|
211
|
+
});
|
|
212
|
+
throw err;
|
|
213
|
+
});
|
|
214
|
+
const provider = new platform_proxy_provider_1.PlatformProxyProvider({
|
|
215
|
+
apiBaseUrl: 'http://localhost:3000',
|
|
216
|
+
workspaceApiKey: 'dp_anon_test',
|
|
217
|
+
jobId: 'job-1',
|
|
218
|
+
networkRetryDelaysMs: [0],
|
|
219
|
+
sleep: async () => undefined,
|
|
220
|
+
});
|
|
221
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(true);
|
|
222
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Tried 2 times');
|
|
223
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
224
|
+
(0, scan_env_1.setScanAiDebugSuppressed)(false);
|
|
225
|
+
await expect(provider.infer({ prompt: 'test', model: 'gpt-4o-mini' })).rejects.toThrow('Tried 2 times');
|
|
226
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Retrying (1/1)'));
|
|
227
|
+
});
|
|
202
228
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|