@openai/codex-security 0.1.21 → 0.1.24
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 +549 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +2 -30
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/finding-detail-fields.md +5 -10
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-contract.md +10 -0
- package/_bundled_plugin/scripts/config_preflight.py +2 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +115 -76
- package/_bundled_plugin/scripts/finding_preview.py +22 -4
- package/_bundled_plugin/scripts/generate_in_scope_files.py +29 -9
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
- package/_bundled_plugin/scripts/rank_preview.py +1 -0
- package/_bundled_plugin/scripts/report_projection.py +8 -14
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +90 -6
- package/_bundled_plugin/scripts/workbench_cli.py +27 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +138 -0
- package/_bundled_plugin/scripts/workbench_db.py +110 -539
- package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +208 -0
- package/_bundled_plugin/scripts/workbench_findings.py +221 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
- package/_bundled_plugin/scripts/workbench_publication.py +520 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +322 -89
- package/_bundled_plugin/scripts/workbench_scan_history.py +1 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
- package/_bundled_plugin/scripts/workbench_schema.py +276 -58
- package/_bundled_plugin/scripts/workbench_target.py +30 -6
- package/_bundled_plugin/scripts/workbench_validation.py +1 -5
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
- package/dist/api.d.ts +5 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +135 -27
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +158 -62
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +5 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -1
- package/dist/custom-publish.d.ts +22 -0
- package/dist/custom-publish.d.ts.map +1 -0
- package/dist/custom-publish.js +47 -0
- package/dist/custom-publish.js.map +1 -0
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +16 -0
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -0
- package/dist/deduplication/checkpointed-review.js +76 -0
- package/dist/deduplication/checkpointed-review.js.map +1 -0
- package/dist/deduplication/codex-review.d.ts +21 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -0
- package/dist/deduplication/codex-review.js +252 -0
- package/dist/deduplication/codex-review.js.map +1 -0
- package/dist/deduplication/deduplication-prompts.d.ts +8 -0
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -0
- package/dist/deduplication/deduplication-prompts.js +35 -0
- package/dist/deduplication/deduplication-prompts.js.map +1 -0
- package/dist/deduplication/deduplication-reviewer.d.ts +46 -0
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -0
- package/dist/deduplication/deduplication-reviewer.js +105 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -0
- package/dist/deduplication/deduplication.d.ts +6 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -0
- package/dist/deduplication/deduplication.js +85 -0
- package/dist/deduplication/deduplication.js.map +1 -0
- package/dist/deduplication/scan.d.ts +16 -0
- package/dist/deduplication/scan.d.ts.map +1 -0
- package/dist/deduplication/scan.js +101 -0
- package/dist/deduplication/scan.js.map +1 -0
- package/dist/deep-progress.d.ts +21 -0
- package/dist/deep-progress.d.ts.map +1 -0
- package/dist/deep-progress.js +108 -0
- package/dist/deep-progress.js.map +1 -0
- package/dist/finding-dedupe-groups.d.ts +7 -0
- package/dist/finding-dedupe-groups.d.ts.map +1 -0
- package/dist/finding-dedupe-groups.js +2 -0
- package/dist/finding-dedupe-groups.js.map +1 -0
- package/dist/finding-retrieval.d.ts +13 -0
- package/dist/finding-retrieval.d.ts.map +1 -0
- package/dist/finding-retrieval.js +2 -0
- package/dist/finding-retrieval.js.map +1 -0
- package/dist/finding-workflow.d.ts +53 -0
- package/dist/finding-workflow.d.ts.map +1 -0
- package/dist/finding-workflow.js +117 -0
- package/dist/finding-workflow.js.map +1 -0
- package/dist/findings-client.d.ts +15 -0
- package/dist/findings-client.d.ts.map +1 -0
- package/dist/findings-client.js +60 -0
- package/dist/findings-client.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.js +28 -40
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +119 -13
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts +15 -0
- package/dist/saved-scan.d.ts.map +1 -0
- package/dist/saved-scan.js +68 -0
- package/dist/saved-scan.js.map +1 -0
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +12 -2
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +3 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +1 -1
- package/dist/scan-comparison.js.map +1 -1
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +276 -0
- package/dist/server/dashboard/app.css +2 -0
- package/dist/server/dashboard/app.js +66 -0
- package/dist/server/dashboard/index.html +18 -0
- package/dist/server/dashboard-types.d.ts +45 -0
- package/dist/server/dashboard-types.d.ts.map +1 -0
- package/dist/server/dashboard-types.js +2 -0
- package/dist/server/dashboard-types.js.map +1 -0
- package/dist/server/dashboard.d.ts +6 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js +45 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/embeddings.d.ts +16 -0
- package/dist/server/embeddings.d.ts.map +1 -0
- package/dist/server/embeddings.js +114 -0
- package/dist/server/embeddings.js.map +1 -0
- package/dist/server/errors.d.ts +5 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +8 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/findings-service.d.ts +20 -0
- package/dist/server/findings-service.d.ts.map +1 -0
- package/dist/server/findings-service.js +31 -0
- package/dist/server/findings-service.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes.d.ts +6 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/routes.js +86 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server/serve.d.ts +2 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +28 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/sqlite-store.d.ts +22 -0
- package/dist/server/sqlite-store.d.ts.map +1 -0
- package/dist/server/sqlite-store.js +82 -0
- package/dist/server/sqlite-store.js.map +1 -0
- package/dist/server/storage.d.ts +32 -0
- package/dist/server/storage.d.ts.map +1 -0
- package/dist/server/storage.js +2 -0
- package/dist/server/storage.js.map +1 -0
- package/dist/server/validation.d.ts +17 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +53 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +2 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +17 -5
package/dist/api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
-
import { chmod, lstat, mkdir, readFile, realpath,
|
|
2
|
+
import { chmod, lstat, mkdir, readFile, realpath, rm, writeFile, } from "node:fs/promises";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
|
-
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
6
6
|
import { Codex, } from "@openai/codex-sdk";
|
|
7
7
|
import { parse as parseToml, stringify as stringifyToml, } from "smol-toml";
|
|
8
8
|
import { z } from "incur";
|
|
@@ -10,18 +10,20 @@ import { accountStatus, CodexLoginHandle, loginApiKey as persistApiKey, logout a
|
|
|
10
10
|
import { jsonForPrompt, pluginPythonCommand, shellEnvironmentReference, } from "./codex-prompt.js";
|
|
11
11
|
import { EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergedCodexConfig, scanApprovalPolicy, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
12
12
|
import { estimateScanCost, ScanCostTracker, sumTokenUsage, } from "./cost.js";
|
|
13
|
-
import {
|
|
13
|
+
import { DeepScanProgressTracker, } from "./deep-progress.js";
|
|
14
|
+
import { loadContract, readScanFile, requireScanFile, } from "./contract.js";
|
|
14
15
|
import { runCustomValidation, writeCustomValidationStatus, } from "./custom-validation.js";
|
|
15
16
|
import { customDiscoveryPrompt, customValidationConfig, } from "./custom-validation-prompt.js";
|
|
16
17
|
import { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, IncompleteScanError, OutputDirectoryError, errorMessage, safeErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
17
18
|
import { prepareKnowledgeBase, } from "./knowledge-base.js";
|
|
19
|
+
import { FindingWorkflow, workflowDigest } from "./finding-workflow.js";
|
|
18
20
|
import { ScanResult, } from "./result.js";
|
|
19
21
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
20
22
|
import { matchCompletedScan, matchScanFindingsInternal, } from "./scan-comparison.js";
|
|
21
23
|
import { scanProgressUpdatesFromEvent, workerStatusFromEvent, } from "./worker-progress.js";
|
|
22
24
|
import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
|
|
23
25
|
import { CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION } from "./version.js";
|
|
24
|
-
import { acquireCodexSecurityCredentialHomeLock, bootstrapPlugin, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, createIsolatedHome, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, planOutputArchive, prepareOutputDir, preparePersistentOutputRoot, requireModelSafeOutputDir, requireOutputOutsideRepository, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
|
|
26
|
+
import { acquireCodexSecurityCredentialHomeLock, bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, codexSecurityStateDirectory, createIsolatedHome, expandHome, importAmbientAuth, prepareCodexSecurityCredentialHome, preserveCodexSecurityPluginRegistration, pluginExecutionEnvironment, planOutputArchive, prepareScanArtifactRestorer, prepareOutputDir, preparePersistentOutputRoot, requireModelSafeOutputDir, requireOutputOutsideRepository, resolveCodexCommand, resolvePluginPath, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, validateOutputDir, } from "./runtime.js";
|
|
25
27
|
import { enclosingGitWorktreeRoot, normalizeRepository, normalizeTarget, repositoryRevision, resolveRepositoryPath, validatedGitEnvironment, validateCommittedDiffCheckout, validateMode, } from "./targets.js";
|
|
26
28
|
const DEEP_SCAN_CONFIG_PATH_ENVIRONMENT = "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH";
|
|
27
29
|
const VALIDATION_DISPOSITIONS = [
|
|
@@ -76,7 +78,94 @@ export class CodexSecurity {
|
|
|
76
78
|
this.#surface = runtimeOptions.surface;
|
|
77
79
|
}
|
|
78
80
|
async run(repository, options = {}) {
|
|
79
|
-
return await this.#trackOperation(() =>
|
|
81
|
+
return await this.#trackOperation(() => options.workflowId === undefined
|
|
82
|
+
? this.#run(repository, { ...options })
|
|
83
|
+
: this.#runWorkflow(repository, { ...options }, options.workflowId));
|
|
84
|
+
}
|
|
85
|
+
async #runWorkflow(repository, options, workflowId) {
|
|
86
|
+
this.#requireOpen();
|
|
87
|
+
const signal = AbortSignal.any([
|
|
88
|
+
this.#abortController.signal,
|
|
89
|
+
...(options.signal ? [options.signal] : []),
|
|
90
|
+
]);
|
|
91
|
+
const local = await this.#validateLocalInputs(repository, { ...options, outputDir: undefined, archiveExisting: false }, signal);
|
|
92
|
+
const workflow = new FindingWorkflow(workflowId, this.#dependencies.environment, this.#dependencies.runWorkbench, this.config.pythonPath);
|
|
93
|
+
if (options.outputDir !== undefined)
|
|
94
|
+
await workflow.protectArtifacts(options.outputDir);
|
|
95
|
+
const state = await workflow.bind({
|
|
96
|
+
repositoryPath: local.repository,
|
|
97
|
+
scanRequestDigest: workflowDigest({
|
|
98
|
+
config: this.config,
|
|
99
|
+
options: {
|
|
100
|
+
...options,
|
|
101
|
+
target: options.target ?? "repository",
|
|
102
|
+
mode: options.mode ?? "standard",
|
|
103
|
+
outputDir: options.outputDir === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: resolve(expandHome(options.outputDir)),
|
|
106
|
+
workflowId: undefined,
|
|
107
|
+
signal: undefined,
|
|
108
|
+
auth: undefined,
|
|
109
|
+
archiveExisting: undefined,
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
if (state.scanId && state.scanDir) {
|
|
114
|
+
await workflow.protectArtifacts(state.scanDir);
|
|
115
|
+
let metadata = state.stages.scan.result;
|
|
116
|
+
let completed = state.stages.scan.status === "completed";
|
|
117
|
+
if (!completed) {
|
|
118
|
+
const scan = await workflow.registeredScan(state.scanId);
|
|
119
|
+
completed =
|
|
120
|
+
scan["progress"]?.["status"] ===
|
|
121
|
+
"complete";
|
|
122
|
+
if (completed)
|
|
123
|
+
metadata = {
|
|
124
|
+
threadId: scan["continuationThreadId"] ?? "",
|
|
125
|
+
turnResult: { status: "completed" },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (completed) {
|
|
129
|
+
const contract = await loadContract(state.scanDir, {
|
|
130
|
+
pluginRoot: await bundledPluginRoot(),
|
|
131
|
+
expectedScanId: state.scanId,
|
|
132
|
+
signal,
|
|
133
|
+
});
|
|
134
|
+
await workflow.bind({ artifactDigest: workflowDigest(contract) });
|
|
135
|
+
metadata ??= { threadId: "", turnResult: { status: "completed" } };
|
|
136
|
+
await workflow.complete("scan", metadata);
|
|
137
|
+
return new ScanResult({
|
|
138
|
+
...contract,
|
|
139
|
+
scanDir: state.scanDir,
|
|
140
|
+
...metadata,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
await workflow.begin("scan");
|
|
145
|
+
try {
|
|
146
|
+
const result = await this.#run(repository, options);
|
|
147
|
+
await workflow.protectArtifacts(result.scanDir);
|
|
148
|
+
await workflow.bind({
|
|
149
|
+
scanId: result.manifest.scan.id,
|
|
150
|
+
scanDir: result.scanDir,
|
|
151
|
+
artifactDigest: workflowDigest({
|
|
152
|
+
manifest: result.manifest,
|
|
153
|
+
findings: result.findings,
|
|
154
|
+
coverage: result.coverage,
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
await workflow.complete("scan", {
|
|
158
|
+
threadId: result.threadId,
|
|
159
|
+
turnResult: result.turnResult,
|
|
160
|
+
sarifPath: result.sarifPath,
|
|
161
|
+
repositoryFindings: result.repositoryFindings,
|
|
162
|
+
});
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
await workflow.fail("scan", error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
80
169
|
}
|
|
81
170
|
async validate(options) {
|
|
82
171
|
return await this.#trackOperation(() => this.#validate(options));
|
|
@@ -210,6 +299,7 @@ export class CodexSecurity {
|
|
|
210
299
|
let targetPathsFile = null;
|
|
211
300
|
let knowledgeBase = null;
|
|
212
301
|
let costTracker = null;
|
|
302
|
+
let deepProgressTracker = null;
|
|
213
303
|
let releaseCredentialHome = null;
|
|
214
304
|
let scanFailure = false;
|
|
215
305
|
let customValidationComplete = false;
|
|
@@ -218,6 +308,8 @@ export class CodexSecurity {
|
|
|
218
308
|
let preparedTargetWarnings = [];
|
|
219
309
|
let runPostScan = null;
|
|
220
310
|
let activeScan = null;
|
|
311
|
+
const prepareArtifactRestorer = this.#dependencies.prepareScanArtifactRestorer ??
|
|
312
|
+
prepareScanArtifactRestorer;
|
|
221
313
|
const workbench = this.#dependencies.runWorkbench ?? runWorkbench;
|
|
222
314
|
try {
|
|
223
315
|
const checkOpen = () => {
|
|
@@ -374,7 +466,13 @@ export class CodexSecurity {
|
|
|
374
466
|
...(options.parentScanId === undefined
|
|
375
467
|
? []
|
|
376
468
|
: ["--parent-scan-id", options.parentScanId]),
|
|
377
|
-
], JSON.stringify({
|
|
469
|
+
], JSON.stringify({
|
|
470
|
+
recipe,
|
|
471
|
+
userContext: options.scanPrompt,
|
|
472
|
+
...(options.workflowId === undefined
|
|
473
|
+
? {}
|
|
474
|
+
: { workflowId: options.workflowId }),
|
|
475
|
+
}));
|
|
378
476
|
const scanId = registration["scanId"];
|
|
379
477
|
const targetId = registration["targetId"];
|
|
380
478
|
const contract = registration["contract"];
|
|
@@ -430,6 +528,23 @@ export class CodexSecurity {
|
|
|
430
528
|
});
|
|
431
529
|
}
|
|
432
530
|
activeScan = { id: scanId, options: workbenchOptions };
|
|
531
|
+
if (mode === "deep" && options.onDeepProgress !== undefined) {
|
|
532
|
+
let progressWarningReported = false;
|
|
533
|
+
deepProgressTracker = new DeepScanProgressTracker({
|
|
534
|
+
read: (progressSignal) => workbench({
|
|
535
|
+
...workbenchOptions,
|
|
536
|
+
signal: AbortSignal.any([signal, progressSignal]),
|
|
537
|
+
}, ["get-scan", "--scan-id", scanId]),
|
|
538
|
+
onProgress: (progress) => notifyObserver("onDeepProgress", options.onDeepProgress, options.onObserverError, progress),
|
|
539
|
+
onError: (error) => {
|
|
540
|
+
if (progressWarningReported)
|
|
541
|
+
return;
|
|
542
|
+
progressWarningReported = true;
|
|
543
|
+
notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not track Deep Scan progress: ${errorMessage(error)}`);
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
deepProgressTracker.start();
|
|
547
|
+
}
|
|
433
548
|
if (options.validationPrompt !== undefined) {
|
|
434
549
|
await writeCustomValidationStatus(scanDir, { scanId, status: "pending" }, signal);
|
|
435
550
|
}
|
|
@@ -699,9 +814,11 @@ export class CodexSecurity {
|
|
|
699
814
|
]),
|
|
700
815
|
].map(async (name) => ({
|
|
701
816
|
name,
|
|
702
|
-
contents: await
|
|
817
|
+
contents: await readScanFile(scanDir, name, name, signal),
|
|
703
818
|
})));
|
|
819
|
+
let artifactRestorer = null;
|
|
704
820
|
try {
|
|
821
|
+
artifactRestorer = await prepareArtifactRestorer(workbenchOptions, scanDir);
|
|
705
822
|
await runScanEvents({
|
|
706
823
|
thread,
|
|
707
824
|
events: (await followUp()).events,
|
|
@@ -719,26 +836,16 @@ export class CodexSecurity {
|
|
|
719
836
|
catch (error) {
|
|
720
837
|
if (signal.aborted || this.#closed)
|
|
721
838
|
throw error;
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
try {
|
|
733
|
-
await writeFile(temporary, artifact.contents, {
|
|
734
|
-
flag: "wx",
|
|
735
|
-
mode: 0o600,
|
|
736
|
-
signal,
|
|
737
|
-
});
|
|
738
|
-
await rename(temporary, path);
|
|
739
|
-
}
|
|
740
|
-
finally {
|
|
741
|
-
await rm(temporary, { force: true });
|
|
839
|
+
if (artifactRestorer !== null) {
|
|
840
|
+
for (const artifact of completedArtifacts) {
|
|
841
|
+
try {
|
|
842
|
+
await artifactRestorer.restore(artifact.name, artifact.contents);
|
|
843
|
+
}
|
|
844
|
+
catch (cause) {
|
|
845
|
+
if (signal.aborted || this.#closed)
|
|
846
|
+
throw cause;
|
|
847
|
+
throw new OutputDirectoryError("Cannot restore an artifact outside the scan directory.", { cause });
|
|
848
|
+
}
|
|
742
849
|
}
|
|
743
850
|
}
|
|
744
851
|
await collectResult(result.turnResult, result.threadId, scanDir, runtime.plugin.installedRoot, expectation, signal, true);
|
|
@@ -873,6 +980,7 @@ export class CodexSecurity {
|
|
|
873
980
|
throw failure;
|
|
874
981
|
}
|
|
875
982
|
finally {
|
|
983
|
+
deepProgressTracker?.stop();
|
|
876
984
|
// Removing the temporary scan inputs is best effort. A throw here would replace the
|
|
877
985
|
// outcome the try and catch blocks already produced, so these failures are reported
|
|
878
986
|
// as warnings: a scan that failed has to say why it failed, not why its temporary
|