@openai/codex-security 0.1.25 → 0.1.27
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 +616 -34
- package/_bundled_plugin/.app.json +0 -5
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +2 -0
- package/_bundled_plugin/mcp/helpers.mjs +24 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/COPYRIGHT-library.html +5556 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +5989 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/licenses/Apache-2.0.txt +73 -0
- package/_bundled_plugin/mcp/native/licenses/BSD-2-Clause.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/MIT.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/Unicode-3.0.txt +39 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -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 +4 -2
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +5 -3
- package/_bundled_plugin/references/scan-artifacts.md +5 -1
- package/_bundled_plugin/references/scan-contract.md +42 -38
- package/_bundled_plugin/references/security-guidance.md +7 -1
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +27 -1
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +2 -5
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -2
- package/_bundled_plugin/scripts/generate_rank_input.py +8 -1
- package/_bundled_plugin/scripts/launch_codex_security_mcp +6 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +43 -9
- package/_bundled_plugin/scripts/rank_preview.py +4 -1
- package/_bundled_plugin/scripts/report_projection.py +1 -1
- package/_bundled_plugin/scripts/workbench_cli.py +7 -0
- package/_bundled_plugin/scripts/workbench_db.py +44 -31
- package/_bundled_plugin/scripts/workbench_saved_results.py +41 -22
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +7 -6
- package/_bundled_plugin/scripts/workbench_schema.py +31 -0
- package/_bundled_plugin/scripts/workbench_severity.py +119 -0
- package/_bundled_plugin/scripts/workbench_validation.py +4 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +5 -3
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +3 -3
- package/_bundled_plugin/skills/verify-fix/SKILL.md +5 -1
- package/dist/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +485 -65
- package/dist/api.js.map +1 -1
- package/dist/auth.js +10 -0
- package/dist/auth.js.map +1 -1
- package/dist/classify-scan-severity.d.ts +16 -0
- package/dist/classify-scan-severity.d.ts.map +1 -0
- package/dist/classify-scan-severity.js +96 -0
- package/dist/classify-scan-severity.js.map +1 -0
- package/dist/classify-severity.d.ts +38 -0
- package/dist/classify-severity.d.ts.map +1 -0
- package/dist/classify-severity.js +185 -0
- package/dist/classify-severity.js.map +1 -0
- package/dist/cli.d.ts +23 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +1277 -357
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +2 -207
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +116 -32
- package/dist/component-plan.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -10
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +16 -0
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +57 -3
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +38 -9
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +6 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +72 -17
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts +2 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +99 -26
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/retry.d.ts +3 -0
- package/dist/deduplication/retry.d.ts.map +1 -0
- package/dist/deduplication/retry.js +15 -0
- package/dist/deduplication/retry.js.map +1 -0
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +4 -2
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/feedback.d.ts +20 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +121 -0
- package/dist/feedback.js.map +1 -0
- package/dist/finding-catalogue.d.ts +11 -0
- package/dist/finding-catalogue.d.ts.map +1 -0
- package/dist/finding-catalogue.js +150 -0
- package/dist/finding-catalogue.js.map +1 -0
- package/dist/findings-client.d.ts +7 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +55 -10
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-import.d.ts +44 -0
- package/dist/findings-import.d.ts.map +1 -0
- package/dist/findings-import.js +302 -0
- package/dist/findings-import.js.map +1 -0
- package/dist/import-scan.d.ts +27 -0
- package/dist/import-scan.d.ts.map +1 -0
- package/dist/import-scan.js +236 -0
- package/dist/import-scan.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +2 -2
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +2 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +144 -52
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-tui.js +1 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +7 -2
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +9 -4
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +9 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +45 -5
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +4 -2
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +2 -2
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +8 -2
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +42 -37
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +535 -161
- package/dist/scan-comparison.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +19 -6
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +5 -0
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-logs.d.ts +29 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +36 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/security-policy-cli.d.ts +39 -0
- package/dist/security-policy-cli.d.ts.map +1 -0
- package/dist/security-policy-cli.js +193 -0
- package/dist/security-policy-cli.js.map +1 -0
- package/dist/security-policy.d.ts +80 -0
- package/dist/security-policy.d.ts.map +1 -0
- package/dist/security-policy.js +672 -0
- package/dist/security-policy.js.map +1 -0
- package/dist/severity-store.d.ts +2 -0
- package/dist/severity-store.d.ts.map +1 -0
- package/dist/severity-store.js +111 -0
- package/dist/severity-store.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +243 -14
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +1 -0
- package/dist/thread-source.d.ts.map +1 -1
- package/dist/thread-source.js +1 -0
- package/dist/thread-source.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 +10 -6
- package/_bundled_plugin/scripts/resolve_security_md.py +0 -158
package/dist/cli.js
CHANGED
|
@@ -13,31 +13,38 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
13
13
|
import { promisify, stripVTControlCharacters } from "node:util";
|
|
14
14
|
import { Cli, z } from "incur";
|
|
15
15
|
import { parse as parseToml } from "smol-toml";
|
|
16
|
-
import { classifyConnectionFailure, createSecurityInternal, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
|
|
17
|
-
import { accountStatus } from "./auth.js";
|
|
16
|
+
import { classifyConnectionFailure, createSecurityInternal, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, runtimeScanAuthentication, selectedScanEnvironment, } from "./api.js";
|
|
17
|
+
import { accountStatus, CODEX_AUTH_CONFIG_KEYS, NO_CREDENTIALS_MESSAGE, configuredCodexHome, readCodexHomeConfig, } from "./auth.js";
|
|
18
|
+
import { loadContract } from "./contract.js";
|
|
18
19
|
import { publishScanToCustom } from "./custom-publish.js";
|
|
20
|
+
import { DEFAULT_DEDUPE_CONCURRENCY } from "./deduplication/deduplication.js";
|
|
19
21
|
import { deduplicateScanInternal } from "./deduplication/scan.js";
|
|
22
|
+
import { classifyScanSeverityInternal, classifyScanDirectorySeverityInternal, } from "./classify-scan-severity.js";
|
|
20
23
|
import { resolveCompletedScan, resolveWorkflowScan, } from "./saved-scan.js";
|
|
21
24
|
import { publishFindingsCsvToCloud, publishScanToCloud, } from "./cloud-publish.js";
|
|
22
25
|
import { createBulkScanDiscoveryDependencies, runBulkScanWizard, } from "./bulk-scan-discovery.js";
|
|
23
|
-
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergedCodexConfig, scanModelConfiguration, scanModelProvider, } from "./config.js";
|
|
26
|
+
import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, hasCommandAuth, inlineToml, modelProviderConfigOverride, resolveCommandAuthConfig, mergedCodexConfig, scanModelConfiguration, scanModelProvider, writeCodexConfig, } from "./config.js";
|
|
24
27
|
import { formatUsd } from "./cost.js";
|
|
25
|
-
import {
|
|
28
|
+
import { formatScanCostTokens, formatTokenUsage } from "./cost-model.js";
|
|
29
|
+
import { CodexSecurityError, AuthenticationRequiredError, ConfigurationError, InvalidTargetError, OutputDirectoryError, OutputInsideProtectedRootError, PluginPythonUnavailableError, errorMessage, safeErrorMessage, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
26
30
|
import { GITHUB_ALERT_STATES, importGitHubCodeScanningAlerts, } from "./github.js";
|
|
27
31
|
import { importLinearIssues, isLinearIssueIdentifier, resolveLinearApiKey, } from "./linear.js";
|
|
28
32
|
import { runMultiscan } from "./multiscan.js";
|
|
29
33
|
import { componentPlanSchema } from "./component-plan.js";
|
|
30
|
-
import { runComponentScans } from "./component-scan.js";
|
|
34
|
+
import { runComponentScans, } from "./component-scan.js";
|
|
31
35
|
import { checkScanPublication, forceTerminatePublicationProcesses as terminatePublishers, publishScan, } from "./publish.js";
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
36
|
+
import { importScan } from "./import-scan.js";
|
|
37
|
+
import { bundledPluginRoot, acquireCodexSecurityCredentialHomeLock, requireOutputOutsideRepositories, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome, pythonUtf8Environment, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
|
|
38
|
+
import { comparisonFindingGroups, comparisonForScan, matchScanFindingsInternal, unionFindingGroups, } from "./scan-comparison.js";
|
|
34
39
|
import { scanActivitiesFromEvent } from "./scan-activity.js";
|
|
35
40
|
import { CODEX_SECURITY_THREAD_SOURCES, } from "./thread-source.js";
|
|
36
|
-
import {
|
|
41
|
+
import { findScanSession, readSavedScanLogs, } from "./scan-logs.js";
|
|
42
|
+
import { sendFeedback } from "./feedback.js";
|
|
37
43
|
import { renderScanHistory, } from "./scan-history-renderer.js";
|
|
38
44
|
import { ScanDashboard } from "./scan-dashboard.js";
|
|
45
|
+
import { policyDisplayData, runPolicyCommand, } from "./security-policy-cli.js";
|
|
39
46
|
import { scanPhaseLabel as scanPhase, } from "./worker-progress.js";
|
|
40
|
-
import { abortable, DiffTarget, } from "./targets.js";
|
|
47
|
+
import { abortable, DiffTarget, enclosingGitWorktreeRoots, } from "./targets.js";
|
|
41
48
|
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
42
49
|
import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
|
|
43
50
|
const PROGRESS_REFRESH_MILLISECONDS = 1_000;
|
|
@@ -48,6 +55,7 @@ const OUTPUT_OPTION = /^--(?:format|filter-output|full-output|token-count|token-
|
|
|
48
55
|
const HIDE_CURSOR = "\u001B[?25l";
|
|
49
56
|
const SHOW_CURSOR = "\u001B[?25h";
|
|
50
57
|
const CHILD_TERMINATION_GRACE_MS = 1_000;
|
|
58
|
+
const DUPLICATE_SIGNAL_WINDOW_MS = 500;
|
|
51
59
|
const PUBLICATION_GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, {
|
|
52
60
|
granularity: "grapheme",
|
|
53
61
|
});
|
|
@@ -81,12 +89,15 @@ const EXPORT_DEFAULT_OUTPUTS = {
|
|
|
81
89
|
const VALUE_OPTIONS = new Set([
|
|
82
90
|
"--port",
|
|
83
91
|
"--workflow-id",
|
|
92
|
+
"--concurrency",
|
|
84
93
|
"--auth",
|
|
85
94
|
"--safety-identifier",
|
|
86
95
|
"--path",
|
|
87
96
|
"--component",
|
|
88
97
|
"--components-file",
|
|
89
98
|
"--knowledge-base",
|
|
99
|
+
"--rubric",
|
|
100
|
+
"--finding-id",
|
|
90
101
|
"--scan-prompt-file",
|
|
91
102
|
"--validation-prompt-file",
|
|
92
103
|
"--post-scan-prompt-file",
|
|
@@ -144,7 +155,7 @@ const PROVIDER_OPTION = z
|
|
|
144
155
|
const CREATE_PR_OPTION = z
|
|
145
156
|
.boolean()
|
|
146
157
|
.default(false)
|
|
147
|
-
.describe("Create a draft GitHub pull request after verified patches.");
|
|
158
|
+
.describe("Create a draft GitHub pull request or GitLab merge request after verified patches.");
|
|
148
159
|
const ASSESS_PATCH_RISK_OPTION = z
|
|
149
160
|
.boolean()
|
|
150
161
|
.default(false)
|
|
@@ -799,160 +810,285 @@ const DEFAULT_DEPENDENCIES = {
|
|
|
799
810
|
}
|
|
800
811
|
return undefined;
|
|
801
812
|
},
|
|
802
|
-
runWorkbench: async (args, input) => {
|
|
813
|
+
runWorkbench: async (args, input, signal) => {
|
|
803
814
|
const environment = {
|
|
804
815
|
...exportEnvironment(),
|
|
805
816
|
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(),
|
|
806
817
|
};
|
|
807
|
-
const python = await resolvePluginPython({ environment });
|
|
818
|
+
const python = await resolvePluginPython({ environment, signal });
|
|
808
819
|
return await runWorkbench({
|
|
809
820
|
python,
|
|
810
821
|
pluginRoot: await bundledPluginRoot(),
|
|
811
822
|
environment,
|
|
823
|
+
signal,
|
|
812
824
|
failureMessage: "Could not read Codex Security scan history",
|
|
813
825
|
}, args, input);
|
|
814
826
|
},
|
|
815
827
|
matchFindings: (input, options) => matchScanFindingsInternal(input, options, { surface: "cli" }),
|
|
816
828
|
};
|
|
817
829
|
export async function runCodexSkillCommand(args, output, command = resolveCodexCommand(), processEnvironment = process.env, input) {
|
|
818
|
-
|
|
819
|
-
? environmentValue(processEnvironment, "CODEX_HOME")
|
|
820
|
-
: processEnvironment["CODEX_HOME"];
|
|
821
|
-
const environment = { ...processEnvironment };
|
|
822
|
-
for (const name of Object.keys(environment)) {
|
|
823
|
-
if (name.toUpperCase() === "CODEX_HOME")
|
|
824
|
-
delete environment[name];
|
|
825
|
-
}
|
|
826
|
-
if (configuredHome?.trim()) {
|
|
827
|
-
environment["CODEX_HOME"] = resolve(expandHome(configuredHome, processEnvironment));
|
|
828
|
-
}
|
|
829
|
-
const invocation = spawn(executablePathForSpawn(command.command), [...args], {
|
|
830
|
-
env: environment,
|
|
831
|
-
cwd: output?.appServer?.directory ?? parse(process.execPath).root,
|
|
832
|
-
stdio: output === undefined
|
|
833
|
-
? input === undefined
|
|
834
|
-
? "inherit"
|
|
835
|
-
: ["pipe", "inherit", "inherit"]
|
|
836
|
-
: [
|
|
837
|
-
output.appServer !== undefined || input !== undefined
|
|
838
|
-
? "pipe"
|
|
839
|
-
: "ignore",
|
|
840
|
-
"pipe",
|
|
841
|
-
"pipe",
|
|
842
|
-
],
|
|
843
|
-
windowsHide: true,
|
|
844
|
-
});
|
|
845
|
-
if (input !== undefined) {
|
|
846
|
-
invocation.stdin?.on("error", () => { });
|
|
847
|
-
invocation.stdin?.end(input);
|
|
848
|
-
}
|
|
849
|
-
let requestedSignal = null;
|
|
850
|
-
let forcedTermination;
|
|
851
|
-
let forceStatusCompletion = null;
|
|
852
|
-
let forceCaptureCompletion = null;
|
|
853
|
-
let invocationStatus;
|
|
854
|
-
const requestTermination = (signal) => {
|
|
855
|
-
requestedSignal = signal;
|
|
856
|
-
invocation.kill(signal);
|
|
857
|
-
if (forcedTermination !== undefined)
|
|
858
|
-
return;
|
|
859
|
-
forcedTermination = setTimeout(() => {
|
|
860
|
-
forcedTermination = undefined;
|
|
861
|
-
if (invocation.exitCode === null && invocation.signalCode === null) {
|
|
862
|
-
invocation.kill("SIGKILL");
|
|
863
|
-
}
|
|
864
|
-
forceCaptureCompletion?.();
|
|
865
|
-
invocation.stdout?.destroy();
|
|
866
|
-
invocation.stderr?.destroy();
|
|
867
|
-
forceStatusCompletion?.();
|
|
868
|
-
}, CHILD_TERMINATION_GRACE_MS);
|
|
869
|
-
};
|
|
870
|
-
const onInterrupt = () => {
|
|
871
|
-
requestTermination("SIGINT");
|
|
872
|
-
};
|
|
873
|
-
const onTerminate = () => {
|
|
874
|
-
requestTermination("SIGTERM");
|
|
875
|
-
};
|
|
876
|
-
process.on("SIGINT", onInterrupt);
|
|
877
|
-
process.on("SIGTERM", onTerminate);
|
|
830
|
+
let releaseCredentialHome;
|
|
878
831
|
try {
|
|
879
|
-
let
|
|
880
|
-
|
|
881
|
-
|
|
832
|
+
let apiKey;
|
|
833
|
+
let authentication = null;
|
|
834
|
+
let modelProvider;
|
|
835
|
+
// runSkill selects auth; other process callers supply their own environment.
|
|
836
|
+
if (output?.auth !== undefined) {
|
|
837
|
+
const config = output.modelProvider !== undefined
|
|
838
|
+
? {
|
|
839
|
+
model_provider: output.modelProvider,
|
|
840
|
+
...(output.providerConfiguration === undefined
|
|
841
|
+
? {}
|
|
842
|
+
: {
|
|
843
|
+
model_providers: {
|
|
844
|
+
[output.modelProvider]: output.providerConfiguration,
|
|
845
|
+
},
|
|
846
|
+
}),
|
|
847
|
+
}
|
|
848
|
+
: output.appServer === undefined
|
|
849
|
+
? {}
|
|
850
|
+
: await readCodexHomeConfig(processEnvironment);
|
|
851
|
+
const provider = scanModelProvider(config);
|
|
852
|
+
const providerConfiguration = typeof provider === "string"
|
|
853
|
+
? config["model_providers"]?.[provider]
|
|
854
|
+
: undefined;
|
|
855
|
+
const requiresOpenAiAuth = provider === undefined ||
|
|
856
|
+
provider === "openai" ||
|
|
857
|
+
providerConfiguration?.["requires_openai_auth"] === true;
|
|
858
|
+
modelProvider = output.modelProvider;
|
|
859
|
+
let credentialConfig;
|
|
860
|
+
authentication = scanAuthentication(processEnvironment, output.auth, provider, hasCommandAuth(config));
|
|
861
|
+
if (authentication.method === "stored_credentials" &&
|
|
862
|
+
isExternalModelProvider(provider)) {
|
|
863
|
+
const externalProvider = EXTERNAL_CODEX_PROVIDERS[provider];
|
|
864
|
+
throw new AuthenticationRequiredError(`Set ${externalProvider.env_key} to run ${output.command} through ${externalProvider.name}.`);
|
|
865
|
+
}
|
|
866
|
+
let selected = selectedScanEnvironment(processEnvironment, authentication.method === "command" ? "chatgpt" : output.auth, provider);
|
|
867
|
+
if (authentication.method === "stored_credentials" &&
|
|
868
|
+
requiresOpenAiAuth) {
|
|
869
|
+
const directory = await realpath(output.directory ?? output.appServer?.directory ?? process.cwd());
|
|
870
|
+
const protectedRoots = [
|
|
871
|
+
directory,
|
|
872
|
+
...(await enclosingGitWorktreeRoots(directory)),
|
|
873
|
+
];
|
|
874
|
+
const codexHome = await prepareCodexSecurityCredentialHome(selected, (path) => requireOutputOutsideRepositories(protectedRoots, path, "runtime"));
|
|
875
|
+
releaseCredentialHome =
|
|
876
|
+
await acquireCodexSecurityCredentialHomeLock(codexHome);
|
|
877
|
+
let credentialsAvailable;
|
|
878
|
+
const ambientConfig = await readCodexHomeConfig(selected);
|
|
879
|
+
credentialConfig = await readCodexHomeConfig({
|
|
880
|
+
...selected,
|
|
881
|
+
CODEX_HOME: codexHome,
|
|
882
|
+
});
|
|
883
|
+
// Let native Codex apply the ambient home's project-trust decisions.
|
|
884
|
+
for (const key of [
|
|
885
|
+
...CODEX_AUTH_CONFIG_KEYS,
|
|
886
|
+
"projects",
|
|
887
|
+
"project_root_markers",
|
|
888
|
+
]) {
|
|
889
|
+
const value = ambientConfig[key];
|
|
890
|
+
if (value === undefined)
|
|
891
|
+
delete credentialConfig[key];
|
|
892
|
+
else
|
|
893
|
+
credentialConfig[key] = value;
|
|
894
|
+
}
|
|
895
|
+
if (typeof provider === "string")
|
|
896
|
+
credentialConfig["model_provider"] = provider;
|
|
897
|
+
else
|
|
898
|
+
delete credentialConfig["model_provider"];
|
|
899
|
+
delete credentialConfig["profile"];
|
|
900
|
+
if (typeof provider !== "string" || providerConfiguration === undefined)
|
|
901
|
+
delete credentialConfig["model_providers"];
|
|
902
|
+
else
|
|
903
|
+
credentialConfig["model_providers"] = {
|
|
904
|
+
[provider]: providerConfiguration,
|
|
905
|
+
};
|
|
906
|
+
await writeCodexConfig(join(codexHome, "config.toml"), credentialConfig);
|
|
907
|
+
credentialsAvailable = await initialCredentialsAvailable(selected, configuredCodexHome(selected), codexHome);
|
|
908
|
+
selected = {
|
|
909
|
+
...selected,
|
|
910
|
+
CODEX_HOME: codexHome,
|
|
911
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(selected),
|
|
912
|
+
};
|
|
913
|
+
if (!credentialsAvailable &&
|
|
914
|
+
!(await accountStatus(command, selected)).authenticated) {
|
|
915
|
+
throw new AuthenticationRequiredError(NO_CREDENTIALS_MESSAGE);
|
|
916
|
+
}
|
|
917
|
+
authentication = await runtimeScanAuthentication(selected, codexHome, output.auth, provider);
|
|
918
|
+
}
|
|
919
|
+
else if (authentication.method === "api_key" && requiresOpenAiAuth) {
|
|
920
|
+
apiKey = environmentValue(selected, authentication.source)?.trim();
|
|
921
|
+
// Match the SDK's key selection for native and nested plugin workers.
|
|
922
|
+
selected = {
|
|
923
|
+
...selectedScanEnvironment(selected, "chatgpt"),
|
|
924
|
+
CODEX_API_KEY: apiKey,
|
|
925
|
+
};
|
|
926
|
+
if (output.appServer !== undefined) {
|
|
927
|
+
args = [
|
|
928
|
+
...args,
|
|
929
|
+
"--config",
|
|
930
|
+
'cli_auth_credentials_store="ephemeral"',
|
|
931
|
+
];
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (output.appServer === undefined) {
|
|
935
|
+
const authConfig = credentialConfig ?? (await readCodexHomeConfig(selected));
|
|
936
|
+
args = [
|
|
937
|
+
...args,
|
|
938
|
+
...CODEX_AUTH_CONFIG_KEYS.flatMap((key) => authConfig[key] === undefined
|
|
939
|
+
? []
|
|
940
|
+
: ["--config", `${key}=${inlineToml(authConfig[key])}`]),
|
|
941
|
+
];
|
|
942
|
+
}
|
|
943
|
+
if (output.appServer === undefined)
|
|
944
|
+
await releaseCredentialHome?.();
|
|
945
|
+
processEnvironment = selected;
|
|
946
|
+
}
|
|
947
|
+
const configuredHome = process.platform === "win32"
|
|
948
|
+
? environmentValue(processEnvironment, "CODEX_HOME")
|
|
949
|
+
: processEnvironment["CODEX_HOME"];
|
|
950
|
+
const environment = { ...processEnvironment };
|
|
951
|
+
for (const name of Object.keys(environment)) {
|
|
952
|
+
if (name.toUpperCase() === "CODEX_HOME")
|
|
953
|
+
delete environment[name];
|
|
954
|
+
}
|
|
955
|
+
if (configuredHome?.trim()) {
|
|
956
|
+
environment["CODEX_HOME"] = resolve(expandHome(configuredHome, processEnvironment));
|
|
957
|
+
}
|
|
958
|
+
const invocation = spawn(executablePathForSpawn(command.command), [...args], {
|
|
959
|
+
env: environment,
|
|
960
|
+
cwd: output?.appServer?.directory ?? parse(process.execPath).root,
|
|
961
|
+
stdio: output === undefined
|
|
962
|
+
? input === undefined
|
|
963
|
+
? "inherit"
|
|
964
|
+
: ["pipe", "inherit", "inherit"]
|
|
965
|
+
: [
|
|
966
|
+
output.appServer !== undefined || input !== undefined
|
|
967
|
+
? "pipe"
|
|
968
|
+
: "ignore",
|
|
969
|
+
"pipe",
|
|
970
|
+
"pipe",
|
|
971
|
+
],
|
|
972
|
+
windowsHide: true,
|
|
882
973
|
});
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
974
|
+
if (input !== undefined) {
|
|
975
|
+
invocation.stdin?.on("error", () => { });
|
|
976
|
+
invocation.stdin?.end(input);
|
|
977
|
+
}
|
|
978
|
+
let requestedSignal = null;
|
|
979
|
+
let forcedTermination;
|
|
980
|
+
let forceStatusCompletion = null;
|
|
981
|
+
let forceCaptureCompletion = null;
|
|
982
|
+
let invocationStatus;
|
|
983
|
+
const requestTermination = (signal) => {
|
|
984
|
+
requestedSignal = signal;
|
|
985
|
+
invocation.kill(signal);
|
|
986
|
+
if (forcedTermination !== undefined)
|
|
987
|
+
return;
|
|
988
|
+
forcedTermination = setTimeout(() => {
|
|
989
|
+
forcedTermination = undefined;
|
|
990
|
+
if (invocation.exitCode === null && invocation.signalCode === null) {
|
|
991
|
+
invocation.kill("SIGKILL");
|
|
992
|
+
}
|
|
993
|
+
forceCaptureCompletion?.();
|
|
994
|
+
invocation.stdout?.destroy();
|
|
995
|
+
invocation.stderr?.destroy();
|
|
996
|
+
forceStatusCompletion?.();
|
|
997
|
+
}, CHILD_TERMINATION_GRACE_MS);
|
|
998
|
+
};
|
|
999
|
+
const onInterrupt = () => {
|
|
1000
|
+
requestTermination("SIGINT");
|
|
1001
|
+
};
|
|
1002
|
+
const onTerminate = () => {
|
|
1003
|
+
requestTermination("SIGTERM");
|
|
1004
|
+
};
|
|
1005
|
+
process.on("SIGINT", onInterrupt);
|
|
1006
|
+
process.on("SIGTERM", onTerminate);
|
|
1007
|
+
try {
|
|
1008
|
+
let diagnostic = "";
|
|
1009
|
+
invocation.stderr?.on("data", (chunk) => {
|
|
1010
|
+
diagnostic = `${diagnostic}${chunk.toString("utf8")}`.slice(-64 * 1_024);
|
|
1011
|
+
});
|
|
1012
|
+
const captured = output === undefined || invocation.stdout === null
|
|
1013
|
+
? Promise.resolve(undefined)
|
|
1014
|
+
: Promise.race([
|
|
1015
|
+
readSkillCommandOutput(invocation.stdout, output.appServer === undefined
|
|
1016
|
+
? undefined
|
|
1017
|
+
: {
|
|
1018
|
+
apiKey,
|
|
1019
|
+
modelProvider,
|
|
1020
|
+
onThreadStarted: releaseCredentialHome,
|
|
1021
|
+
directory: output.appServer.directory,
|
|
1022
|
+
prompt: output.appServer.prompt,
|
|
1023
|
+
threadSource: output.appServer.threadSource,
|
|
1024
|
+
input: invocation.stdin,
|
|
1025
|
+
sandbox: output.appServer.sandbox,
|
|
1026
|
+
onEvent: output.appServer.onEvent,
|
|
1027
|
+
}),
|
|
1028
|
+
new Promise((resolve) => {
|
|
1029
|
+
forceCaptureCompletion = () => resolve(undefined);
|
|
895
1030
|
}),
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
reject(error);
|
|
1031
|
+
]);
|
|
1032
|
+
invocationStatus = new Promise((resolve, reject) => {
|
|
1033
|
+
let completed = false;
|
|
1034
|
+
const complete = (code, signal) => {
|
|
1035
|
+
if (completed)
|
|
1036
|
+
return;
|
|
1037
|
+
completed = true;
|
|
1038
|
+
forceStatusCompletion = null;
|
|
1039
|
+
resolve(requestedSignal === "SIGINT" || signal === "SIGINT"
|
|
1040
|
+
? 130
|
|
1041
|
+
: requestedSignal === "SIGTERM" || signal === "SIGTERM"
|
|
1042
|
+
? 143
|
|
1043
|
+
: code ?? 1);
|
|
1044
|
+
};
|
|
1045
|
+
forceStatusCompletion = () => complete(null, null);
|
|
1046
|
+
invocation.once("error", (error) => {
|
|
1047
|
+
if (completed)
|
|
1048
|
+
return;
|
|
1049
|
+
completed = true;
|
|
1050
|
+
forceStatusCompletion = null;
|
|
1051
|
+
reject(error);
|
|
1052
|
+
});
|
|
1053
|
+
invocation.once(output === undefined ? "exit" : "close", complete);
|
|
920
1054
|
});
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
status
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1055
|
+
let [status, events] = await Promise.all([invocationStatus, captured]);
|
|
1056
|
+
if (status === 0 && output?.appServer !== undefined && events?.error) {
|
|
1057
|
+
status = 1;
|
|
1058
|
+
}
|
|
1059
|
+
if (output === undefined || status === 130 || status === 143)
|
|
1060
|
+
return status;
|
|
1061
|
+
if (status !== 0) {
|
|
1062
|
+
await writeCliOutput(output.stderr, `codex-security: ${skillCommandFailure(output.command, status, events?.error ?? diagnostic, authentication)}\n`);
|
|
1063
|
+
return status;
|
|
1064
|
+
}
|
|
1065
|
+
if ((output.appServer !== undefined && events?.completed !== true) ||
|
|
1066
|
+
events?.message === undefined ||
|
|
1067
|
+
events.message.trim().length === 0) {
|
|
1068
|
+
await writeCliOutput(output.stderr, `codex-security: Codex did not return a completed ${output.command} response.\n`);
|
|
1069
|
+
return 2;
|
|
1070
|
+
}
|
|
1071
|
+
await writeCliOutput(output.stdout, `${events.message.trimEnd()}\n`);
|
|
931
1072
|
return status;
|
|
932
1073
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1074
|
+
catch (error) {
|
|
1075
|
+
invocation.stdout?.destroy();
|
|
1076
|
+
invocation.stderr?.destroy();
|
|
1077
|
+
requestTermination("SIGTERM");
|
|
1078
|
+
await invocationStatus?.catch(() => undefined);
|
|
1079
|
+
throw error;
|
|
1080
|
+
}
|
|
1081
|
+
finally {
|
|
1082
|
+
if (forcedTermination !== undefined)
|
|
1083
|
+
clearTimeout(forcedTermination);
|
|
1084
|
+
forceStatusCompletion = null;
|
|
1085
|
+
forceCaptureCompletion = null;
|
|
1086
|
+
process.off("SIGINT", onInterrupt);
|
|
1087
|
+
process.off("SIGTERM", onTerminate);
|
|
938
1088
|
}
|
|
939
|
-
await writeCliOutput(output.stdout, `${events.message.trimEnd()}\n`);
|
|
940
|
-
return status;
|
|
941
|
-
}
|
|
942
|
-
catch (error) {
|
|
943
|
-
invocation.stdout?.destroy();
|
|
944
|
-
invocation.stderr?.destroy();
|
|
945
|
-
requestTermination("SIGTERM");
|
|
946
|
-
await invocationStatus?.catch(() => undefined);
|
|
947
|
-
throw error;
|
|
948
1089
|
}
|
|
949
1090
|
finally {
|
|
950
|
-
|
|
951
|
-
clearTimeout(forcedTermination);
|
|
952
|
-
forceStatusCompletion = null;
|
|
953
|
-
forceCaptureCompletion = null;
|
|
954
|
-
process.off("SIGINT", onInterrupt);
|
|
955
|
-
process.off("SIGTERM", onTerminate);
|
|
1091
|
+
await releaseCredentialHome?.();
|
|
956
1092
|
}
|
|
957
1093
|
}
|
|
958
1094
|
async function writeCliOutput(output, value) {
|
|
@@ -1010,10 +1146,11 @@ export function exportEnvironment(environment = process.env) {
|
|
|
1010
1146
|
.map((key) => [key, environment[key]])));
|
|
1011
1147
|
}
|
|
1012
1148
|
export async function main(argv = process.argv.slice(2), output = process.stdout, errorOutput = process.stderr, dependencies = DEFAULT_DEPENDENCIES) {
|
|
1013
|
-
argv = defaultListCommand(argv);
|
|
1149
|
+
argv = normalizeScanImportArguments(defaultListCommand(argv));
|
|
1150
|
+
const policyFullOutput = argv[cliCommandIndex(argv)] === "policy" && argv.includes("--full-output");
|
|
1014
1151
|
const positionals = [];
|
|
1015
1152
|
const argumentError = validateCliArguments(argv, positionals);
|
|
1016
|
-
if (argumentError !== undefined) {
|
|
1153
|
+
if (argumentError !== undefined && !policyFullOutput) {
|
|
1017
1154
|
errorOutput.write(`codex-security: ${argumentError}\n`);
|
|
1018
1155
|
return 2;
|
|
1019
1156
|
}
|
|
@@ -1040,6 +1177,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1040
1177
|
let frameworkOutput = "";
|
|
1041
1178
|
let renderedHistory;
|
|
1042
1179
|
let renderedPublication;
|
|
1180
|
+
let renderedPolicy;
|
|
1181
|
+
const runImport = (options) => runScanImport(options, errorOutput, dependencies);
|
|
1043
1182
|
const history = async (args, select = (value) => value) => {
|
|
1044
1183
|
try {
|
|
1045
1184
|
return await select(await dependencies.runWorkbench(args));
|
|
@@ -1069,16 +1208,82 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1069
1208
|
});
|
|
1070
1209
|
return result?.["scans"];
|
|
1071
1210
|
};
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1211
|
+
const runMatching = async (operation) => {
|
|
1212
|
+
const controller = new AbortController();
|
|
1213
|
+
let firstSignalAt = 0;
|
|
1214
|
+
const cancel = (signal) => {
|
|
1215
|
+
if (controller.signal.aborted) {
|
|
1216
|
+
if (signal === controller.signal.reason &&
|
|
1217
|
+
dependencies.now() - firstSignalAt < DUPLICATE_SIGNAL_WINDOW_MS) {
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
removeListeners();
|
|
1221
|
+
dependencies.forceExit(signal);
|
|
1222
|
+
}
|
|
1223
|
+
else {
|
|
1224
|
+
firstSignalAt = dependencies.now();
|
|
1225
|
+
controller.abort(signal);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
const onInterrupt = () => cancel("SIGINT");
|
|
1229
|
+
const onTerminate = () => cancel("SIGTERM");
|
|
1230
|
+
const removeListeners = () => {
|
|
1231
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
1232
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
1233
|
+
};
|
|
1234
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
1235
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
1236
|
+
let previousProgress = "";
|
|
1237
|
+
try {
|
|
1238
|
+
const result = await operation({
|
|
1239
|
+
environment: dependencies.environment,
|
|
1240
|
+
workingDirectory: dependencies.currentDirectory(),
|
|
1241
|
+
signal: controller.signal,
|
|
1242
|
+
onProgress(progress) {
|
|
1243
|
+
if (errorOutput.isTTY !== true || progress.phase === "complete")
|
|
1244
|
+
return;
|
|
1245
|
+
const message = progress.phase === "evidence"
|
|
1246
|
+
? "Reading selected finding evidence."
|
|
1247
|
+
: `Matching ${progress.afterFindings} findings against ${progress.beforeIssues} known issues${(progress.pages ?? 1) > 1 ? ` (catalogue page ${progress.page}/${progress.pages})` : ""}.`;
|
|
1248
|
+
if (message === previousProgress)
|
|
1249
|
+
return;
|
|
1250
|
+
previousProgress = message;
|
|
1251
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
1252
|
+
},
|
|
1253
|
+
});
|
|
1254
|
+
controller.signal.throwIfAborted();
|
|
1255
|
+
return result;
|
|
1256
|
+
}
|
|
1257
|
+
catch (error) {
|
|
1258
|
+
const interrupted = controller.signal.reason;
|
|
1259
|
+
exitCode =
|
|
1260
|
+
interrupted === "SIGINT" ? 130 : interrupted === "SIGTERM" ? 143 : 2;
|
|
1261
|
+
const message = interrupted === "SIGINT"
|
|
1262
|
+
? "Finding matching canceled by Ctrl-C. Saved comparisons are preserved."
|
|
1263
|
+
: interrupted === "SIGTERM"
|
|
1264
|
+
? "Finding matching terminated by SIGTERM. Saved comparisons are preserved."
|
|
1265
|
+
: errorMessage(error);
|
|
1266
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
1267
|
+
throw error;
|
|
1268
|
+
}
|
|
1269
|
+
finally {
|
|
1270
|
+
removeListeners();
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
const matchScanPair = async (beforeId, afterId, force = false) => runMatching(async (options) => {
|
|
1274
|
+
const { matchingCached, matchingInputs, ...comparison } = await dependencies.runWorkbench([
|
|
1275
|
+
"compare-scans",
|
|
1276
|
+
"--before-scan-id",
|
|
1277
|
+
beforeId,
|
|
1278
|
+
"--after-scan-id",
|
|
1279
|
+
afterId,
|
|
1280
|
+
"--include-matching-inputs",
|
|
1281
|
+
], undefined, options.signal);
|
|
1080
1282
|
if (matchingCached && !force)
|
|
1081
1283
|
return comparison;
|
|
1284
|
+
const input = matchingInputs;
|
|
1285
|
+
const matching = await dependencies.matchFindings(input, options);
|
|
1286
|
+
options.signal?.throwIfAborted();
|
|
1082
1287
|
return await dependencies.runWorkbench([
|
|
1083
1288
|
"save-scan-comparison",
|
|
1084
1289
|
"--before-scan-id",
|
|
@@ -1086,7 +1291,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1086
1291
|
"--after-scan-id",
|
|
1087
1292
|
afterId,
|
|
1088
1293
|
"--matches-json-stdin",
|
|
1089
|
-
], JSON.stringify(
|
|
1294
|
+
], JSON.stringify(matching), options.signal);
|
|
1090
1295
|
});
|
|
1091
1296
|
const presentHistory = (result, command, format, settings = {}) => {
|
|
1092
1297
|
if (result === undefined ||
|
|
@@ -1249,26 +1454,62 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1249
1454
|
const scanId = args.scanId ?? (await latestScans(1, "any"))?.[0]?.scanId;
|
|
1250
1455
|
if (scanId === undefined)
|
|
1251
1456
|
return;
|
|
1252
|
-
return await history(["get-scan", "--scan-id", scanId], async (value) =>
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1457
|
+
return await history(["get-scan", "--scan-id", scanId], async (value) => (await readSavedScanLogs(value["scan"], codexSecurityCredentialHome(dependencies.environment))));
|
|
1458
|
+
},
|
|
1459
|
+
})
|
|
1460
|
+
.command("resume", {
|
|
1461
|
+
description: "Resume an interrupted Deep Scan in its original session.",
|
|
1462
|
+
mcp: false,
|
|
1463
|
+
args: z.object({
|
|
1464
|
+
scanId: z.string().min(1).describe("Interrupted Deep Scan identifier."),
|
|
1465
|
+
}),
|
|
1466
|
+
options: z.object({
|
|
1467
|
+
verbose: z
|
|
1468
|
+
.boolean()
|
|
1469
|
+
.default(false)
|
|
1470
|
+
.describe("Print scan diagnostics to stderr."),
|
|
1471
|
+
}),
|
|
1472
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
1473
|
+
async run({ args, error: incurError, options }) {
|
|
1474
|
+
let scanArguments;
|
|
1475
|
+
try {
|
|
1476
|
+
const saved = await dependencies.runWorkbench([
|
|
1477
|
+
"get-cli-scan-resume",
|
|
1478
|
+
"--scan-id",
|
|
1479
|
+
args.scanId,
|
|
1480
|
+
]);
|
|
1481
|
+
if (typeof saved["scanId"] !== "string" ||
|
|
1482
|
+
typeof saved["scanDir"] !== "string") {
|
|
1483
|
+
throw new CodexSecurityError("The workbench returned invalid scan resume context.");
|
|
1257
1484
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1485
|
+
scanArguments = scanArgumentsFromRecipe(saved["recipe"], saved["scanId"]);
|
|
1486
|
+
scanArguments.resumeScanId = saved["scanId"];
|
|
1487
|
+
scanArguments.outputDir = saved["scanDir"];
|
|
1488
|
+
scanArguments.parentScanId = undefined;
|
|
1489
|
+
// Resume uses the installed engine with the saved recipe and checkpoints.
|
|
1490
|
+
scanArguments.expectedPluginVersion = undefined;
|
|
1491
|
+
scanArguments.verbose = options.verbose;
|
|
1492
|
+
}
|
|
1493
|
+
catch (error) {
|
|
1494
|
+
const message = errorMessage(error);
|
|
1495
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
1496
|
+
exitCode = 2;
|
|
1497
|
+
return incurError({
|
|
1498
|
+
code: "SCAN_RESUME_UNAVAILABLE",
|
|
1499
|
+
message,
|
|
1500
|
+
exitCode,
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
const outcome = await runScan(scanArguments, errorOutput, dependencies);
|
|
1504
|
+
exitCode = outcome.exitCode;
|
|
1505
|
+
if (outcome.error !== undefined) {
|
|
1506
|
+
return incurError({
|
|
1507
|
+
code: "SCAN_FAILED",
|
|
1508
|
+
message: outcome.error,
|
|
1509
|
+
exitCode,
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
return outcome.data;
|
|
1272
1513
|
},
|
|
1273
1514
|
})
|
|
1274
1515
|
.command("rerun", {
|
|
@@ -1303,6 +1544,36 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1303
1544
|
"--scan-id",
|
|
1304
1545
|
scanId,
|
|
1305
1546
|
]);
|
|
1547
|
+
if (recipe !== undefined &&
|
|
1548
|
+
isJsonObject(recipe) &&
|
|
1549
|
+
recipe["import"] !== undefined &&
|
|
1550
|
+
isJsonObject(recipe["import"])) {
|
|
1551
|
+
if (options.validationPromptFile !== undefined) {
|
|
1552
|
+
throw new CodexSecurityError("--validation-prompt-file is not supported when rerunning an imported scan; imports do not perform security analysis.");
|
|
1553
|
+
}
|
|
1554
|
+
const imported = recipe["import"];
|
|
1555
|
+
const sourcePath = imported["sourcePath"];
|
|
1556
|
+
const format = imported["format"];
|
|
1557
|
+
if (typeof sourcePath !== "string" ||
|
|
1558
|
+
sourcePath.length === 0 ||
|
|
1559
|
+
(format !== "csv" && format !== "json")) {
|
|
1560
|
+
throw new CodexSecurityError("The saved scan recipe contains invalid import settings.");
|
|
1561
|
+
}
|
|
1562
|
+
const outcome = await runImport({
|
|
1563
|
+
sourcePath,
|
|
1564
|
+
format,
|
|
1565
|
+
parentScanId: scanId,
|
|
1566
|
+
});
|
|
1567
|
+
exitCode = outcome.exitCode;
|
|
1568
|
+
if (outcome.error !== undefined) {
|
|
1569
|
+
return incurError({
|
|
1570
|
+
code: "SCAN_IMPORT_FAILED",
|
|
1571
|
+
message: outcome.error,
|
|
1572
|
+
exitCode,
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
return outcome.data;
|
|
1576
|
+
}
|
|
1306
1577
|
scanArguments = scanArgumentsFromRecipe(recipe, scanId, options.validationPromptFile);
|
|
1307
1578
|
scanArguments.verbose = options.verbose;
|
|
1308
1579
|
}
|
|
@@ -1356,17 +1627,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1356
1627
|
}),
|
|
1357
1628
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
1358
1629
|
async run({ args, format, options }) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
return presentHistory(await matchAllScans(dependencies, options.force), "match-all", format);
|
|
1362
|
-
}
|
|
1363
|
-
return presentHistory(await matchScanPair(args.beforeId, args.afterId, options.force), "compare", format);
|
|
1364
|
-
}
|
|
1365
|
-
catch (error) {
|
|
1366
|
-
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
1367
|
-
exitCode = 2;
|
|
1368
|
-
throw error;
|
|
1630
|
+
if (options.all) {
|
|
1631
|
+
return presentHistory(await runMatching((matchingOptions) => matchAllScans(dependencies, options.force, matchingOptions)), "match-all", format);
|
|
1369
1632
|
}
|
|
1633
|
+
return presentHistory(await matchScanPair(args.beforeId, args.afterId, options.force), "compare", format);
|
|
1370
1634
|
},
|
|
1371
1635
|
})
|
|
1372
1636
|
.command("compare", {
|
|
@@ -1430,6 +1694,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1430
1694
|
.describe("Completed scan directory; omit to select a saved scan."),
|
|
1431
1695
|
}),
|
|
1432
1696
|
options: PUBLICATION_DESTINATION_OPTIONS.extend({
|
|
1697
|
+
findingId: z
|
|
1698
|
+
.array(optionValue("--finding-id"))
|
|
1699
|
+
.default([])
|
|
1700
|
+
.describe("Publish only this finding ID; repeat to select deduplicated findings (Linear only)."),
|
|
1433
1701
|
workflowId: optionValue("--workflow-id")
|
|
1434
1702
|
.optional()
|
|
1435
1703
|
.describe("Resume the named local scan, custom publication, and dedupe workflow."),
|
|
@@ -1517,6 +1785,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1517
1785
|
};
|
|
1518
1786
|
try {
|
|
1519
1787
|
const currentDirectory = dependencies.currentDirectory();
|
|
1788
|
+
if (options.findingId.length > 0 && options.to !== "linear") {
|
|
1789
|
+
throw new CodexSecurityError("--finding-id is only supported with --to linear.");
|
|
1790
|
+
}
|
|
1520
1791
|
const csvPath = options.csv === undefined
|
|
1521
1792
|
? undefined
|
|
1522
1793
|
: resolveCliPath(currentDirectory, options.csv);
|
|
@@ -1826,6 +2097,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1826
2097
|
try {
|
|
1827
2098
|
result = await (dependencies.publishScan ?? publishScan)(resolveCliPath(currentDirectory, scanDir), {
|
|
1828
2099
|
...destination,
|
|
2100
|
+
...(options.findingId.length === 0
|
|
2101
|
+
? {}
|
|
2102
|
+
: { findingIds: options.findingId }),
|
|
1829
2103
|
...(selectedScans[0]?.scanId === undefined
|
|
1830
2104
|
? {}
|
|
1831
2105
|
: { expectedScanId: selectedScans[0].scanId }),
|
|
@@ -1977,15 +2251,171 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1977
2251
|
},
|
|
1978
2252
|
});
|
|
1979
2253
|
const cli = Cli.create("codex-security", {
|
|
1980
|
-
description: "
|
|
2254
|
+
description: "Draft security policies; run, import, validate, patch, verify fixes, export, and publish Codex Security findings.",
|
|
1981
2255
|
version: VERSION,
|
|
1982
2256
|
mcp: {
|
|
1983
2257
|
command: "npx --yes @openai/codex-security --mcp",
|
|
1984
2258
|
instructions: "Use info for read-only SDK metadata. Scans and other state-changing commands are CLI-only because the MCP transport cannot cancel active commands.",
|
|
1985
2259
|
},
|
|
2260
|
+
})
|
|
2261
|
+
.command("policy", {
|
|
2262
|
+
description: "Draft SECURITY.md guidance for future scans and owner review.",
|
|
2263
|
+
destructive: true,
|
|
2264
|
+
mcp: false,
|
|
2265
|
+
args: z.object({
|
|
2266
|
+
repository: z
|
|
2267
|
+
.string()
|
|
2268
|
+
.optional()
|
|
2269
|
+
.describe("Repository or component directory (default: current directory)."),
|
|
2270
|
+
}),
|
|
2271
|
+
options: z.object({
|
|
2272
|
+
path: optionValue("--path")
|
|
2273
|
+
.optional()
|
|
2274
|
+
.describe("Generate SECURITY.md for this repository-relative component directory."),
|
|
2275
|
+
knowledgeBase: z
|
|
2276
|
+
.array(optionValue("--knowledge-base"))
|
|
2277
|
+
.default([])
|
|
2278
|
+
.describe("Add architecture or security-context files; repeat for multiple paths."),
|
|
2279
|
+
outputDir: optionValue("--output-dir")
|
|
2280
|
+
.optional()
|
|
2281
|
+
.describe("Private artifact directory outside the repository (default: Codex Security state)."),
|
|
2282
|
+
headless: z
|
|
2283
|
+
.boolean()
|
|
2284
|
+
.default(false)
|
|
2285
|
+
.describe("Skip owner questions and authentication prompts."),
|
|
2286
|
+
dryRun: z
|
|
2287
|
+
.boolean()
|
|
2288
|
+
.default(false)
|
|
2289
|
+
.describe("Validate local generation inputs without starting Codex."),
|
|
2290
|
+
auth: z
|
|
2291
|
+
.enum(["auto", "chatgpt", "api-key"])
|
|
2292
|
+
.default("auto")
|
|
2293
|
+
.describe("Select ChatGPT, API-key, or automatic authentication."),
|
|
2294
|
+
model: optionValue("--model")
|
|
2295
|
+
.optional()
|
|
2296
|
+
.describe(`Model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
|
|
2297
|
+
effort: effortOption(),
|
|
2298
|
+
provider: PROVIDER_OPTION.describe("Inference provider for policy generation."),
|
|
2299
|
+
maxCost: z
|
|
2300
|
+
.number()
|
|
2301
|
+
.positive()
|
|
2302
|
+
.optional()
|
|
2303
|
+
.describe("Stop when estimated total USD cost across all three stages exceeds AMOUNT."),
|
|
2304
|
+
pluginPath: optionValue("--plugin-path")
|
|
2305
|
+
.optional()
|
|
2306
|
+
.describe(PLUGIN_PATH_DESCRIPTION),
|
|
2307
|
+
python: optionValue("--python")
|
|
2308
|
+
.optional()
|
|
2309
|
+
.describe(PYTHON_PATH_DESCRIPTION),
|
|
2310
|
+
codex: z
|
|
2311
|
+
.array(optionValue("--codex"))
|
|
2312
|
+
.default([])
|
|
2313
|
+
.describe(CODEX_OVERRIDE_DESCRIPTION),
|
|
2314
|
+
}),
|
|
2315
|
+
examples: [
|
|
2316
|
+
{ args: { repository: "." } },
|
|
2317
|
+
{ args: { repository: "." }, options: { path: "services/api" } },
|
|
2318
|
+
],
|
|
2319
|
+
hint: "Save a draft for review:\n" +
|
|
2320
|
+
" codex-security policy . --headless --output-dir /path/outside/repository/policy --json",
|
|
2321
|
+
output: z
|
|
2322
|
+
.union([z.record(z.string(), z.unknown()), z.string()])
|
|
2323
|
+
.optional(),
|
|
2324
|
+
async run({ args, error: incurError, options, format, formatExplicit }) {
|
|
2325
|
+
const outputOptions = argv.filter((argument) => OUTPUT_OPTION.test(argument));
|
|
2326
|
+
const explicitOutput = formatExplicit || outputOptions.length > 0;
|
|
2327
|
+
const transformOutput = outputOptions.some((argument) => !argument.startsWith("--format"));
|
|
2328
|
+
const filterOutput = outputOptions.some((argument) => argument.startsWith("--filter-output"));
|
|
2329
|
+
const fail = (message, failureExitCode) => {
|
|
2330
|
+
exitCode = failureExitCode;
|
|
2331
|
+
return incurError({
|
|
2332
|
+
code: "POLICY_FAILED",
|
|
2333
|
+
message,
|
|
2334
|
+
exitCode: failureExitCode,
|
|
2335
|
+
});
|
|
2336
|
+
};
|
|
2337
|
+
try {
|
|
2338
|
+
if (argumentError !== undefined)
|
|
2339
|
+
return fail(argumentError, 2);
|
|
2340
|
+
const directory = dependencies.currentDirectory();
|
|
2341
|
+
const outcome = await withTerminalErrorsHandled(errorOutput, () => runPolicyCommand({
|
|
2342
|
+
repository: resolveCliPath(directory, args.repository ?? "."),
|
|
2343
|
+
config: {
|
|
2344
|
+
pluginPath: options.pluginPath,
|
|
2345
|
+
pythonPath: options.python,
|
|
2346
|
+
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider),
|
|
2347
|
+
},
|
|
2348
|
+
generation: {
|
|
2349
|
+
auth: options.auth,
|
|
2350
|
+
path: options.path,
|
|
2351
|
+
knowledgeBasePaths: options.knowledgeBase.map((path) => resolveCliPath(directory, path)),
|
|
2352
|
+
outputDir: options.outputDir === undefined
|
|
2353
|
+
? undefined
|
|
2354
|
+
: resolveCliPath(directory, options.outputDir),
|
|
2355
|
+
maxCostUsd: options.maxCost,
|
|
2356
|
+
},
|
|
2357
|
+
headless: options.headless || explicitOutput,
|
|
2358
|
+
dryRun: options.dryRun,
|
|
2359
|
+
format,
|
|
2360
|
+
explicitOutput,
|
|
2361
|
+
}, {
|
|
2362
|
+
createSecurity: dependencies.createPolicySecurity ??
|
|
2363
|
+
((config) => createSecurityInternal(config, { surface: "cli" })),
|
|
2364
|
+
chooseAuthentication: (config, auth, signal) => chooseInteractiveAuthentication({
|
|
2365
|
+
auth,
|
|
2366
|
+
provider: scanModelProvider({
|
|
2367
|
+
...DEFAULT_CODEX_CONFIG,
|
|
2368
|
+
...config.codexOverrides,
|
|
2369
|
+
}),
|
|
2370
|
+
command: "policy",
|
|
2371
|
+
signal,
|
|
2372
|
+
}, errorOutput, dependencies),
|
|
2373
|
+
prompt: dependencies.policyPrompt ??
|
|
2374
|
+
createBulkScanDiscoveryDependencies({
|
|
2375
|
+
output: errorOutput,
|
|
2376
|
+
now: dependencies.now,
|
|
2377
|
+
currentDirectory: dependencies.currentDirectory,
|
|
2378
|
+
}).prompt,
|
|
2379
|
+
environment: dependencies.environment,
|
|
2380
|
+
errorOutput,
|
|
2381
|
+
now: dependencies.now,
|
|
2382
|
+
addSignalListener: dependencies.addSignalListener,
|
|
2383
|
+
removeSignalListener: dependencies.removeSignalListener,
|
|
2384
|
+
forceExit: dependencies.forceExit,
|
|
2385
|
+
}));
|
|
2386
|
+
exitCode = outcome.exitCode;
|
|
2387
|
+
if (exitCode !== 0) {
|
|
2388
|
+
return fail(outcome.error ?? "Policy command failed.", exitCode);
|
|
2389
|
+
}
|
|
2390
|
+
if (format === "md" &&
|
|
2391
|
+
outcome.markdown !== undefined &&
|
|
2392
|
+
!filterOutput) {
|
|
2393
|
+
if (!transformOutput)
|
|
2394
|
+
renderedPolicy = outcome.markdown;
|
|
2395
|
+
return outcome.markdown;
|
|
2396
|
+
}
|
|
2397
|
+
return format === "toon" && !explicitOutput && !options.dryRun
|
|
2398
|
+
? undefined
|
|
2399
|
+
: format === "toon"
|
|
2400
|
+
? policyDisplayData(outcome.data)
|
|
2401
|
+
: outcome.data;
|
|
2402
|
+
}
|
|
2403
|
+
catch (error) {
|
|
2404
|
+
const message = safeErrorMessage(error);
|
|
2405
|
+
try {
|
|
2406
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
2407
|
+
}
|
|
2408
|
+
catch { }
|
|
2409
|
+
return fail(message, 2);
|
|
2410
|
+
}
|
|
2411
|
+
},
|
|
1986
2412
|
})
|
|
1987
2413
|
.command("scan", {
|
|
1988
2414
|
description: "Run a Codex Security scan.",
|
|
2415
|
+
hint: "Import existing findings without security analysis:\n" +
|
|
2416
|
+
" codex-security scan import --csv findings.csv\n" +
|
|
2417
|
+
" codex-security scan import --json findings.json\n" +
|
|
2418
|
+
"Use ./import to scan a repository named import.",
|
|
1989
2419
|
destructive: true,
|
|
1990
2420
|
mcp: false,
|
|
1991
2421
|
args: z.object({
|
|
@@ -2274,11 +2704,93 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2274
2704
|
.command(scanHistory)
|
|
2275
2705
|
.command(findingFeedback)
|
|
2276
2706
|
.command(publication)
|
|
2707
|
+
.command("classify-severity", {
|
|
2708
|
+
description: "Classify saved findings using an optional rubric and save a separate severity assessment.",
|
|
2709
|
+
destructive: true,
|
|
2710
|
+
mcp: false,
|
|
2711
|
+
options: z.object({
|
|
2712
|
+
reprocess: z
|
|
2713
|
+
.boolean()
|
|
2714
|
+
.default(false)
|
|
2715
|
+
.describe("Reclassify selected findings even when a matching assessment is saved."),
|
|
2716
|
+
scan: optionValue("--scan")
|
|
2717
|
+
.optional()
|
|
2718
|
+
.describe("Saved scan ID, unique prefix, or latest."),
|
|
2719
|
+
scanDir: optionValue("--scan-dir")
|
|
2720
|
+
.optional()
|
|
2721
|
+
.describe("External completed scan directory."),
|
|
2722
|
+
rubric: optionValue("--rubric")
|
|
2723
|
+
.optional()
|
|
2724
|
+
.describe("Classification policy document; omit to inherit existing severity without a model call."),
|
|
2725
|
+
knowledgeBase: z
|
|
2726
|
+
.array(optionValue("--knowledge-base"))
|
|
2727
|
+
.default([])
|
|
2728
|
+
.describe("Supporting security context; repeat for more files or directories."),
|
|
2729
|
+
findingId: z
|
|
2730
|
+
.array(optionValue("--finding-id"))
|
|
2731
|
+
.default([])
|
|
2732
|
+
.describe("Classify only this finding ID; repeat to select deduplicated findings."),
|
|
2733
|
+
model: optionValue("--model")
|
|
2734
|
+
.optional()
|
|
2735
|
+
.describe("Model for rubric classification."),
|
|
2736
|
+
effort: effortOption().describe("Classification reasoning effort (default: medium)."),
|
|
2737
|
+
}),
|
|
2738
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
2739
|
+
async run({ options }) {
|
|
2740
|
+
const controller = new AbortController();
|
|
2741
|
+
const onInterrupt = () => controller.abort("SIGINT");
|
|
2742
|
+
const onTerminate = () => controller.abort("SIGTERM");
|
|
2743
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
2744
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2745
|
+
try {
|
|
2746
|
+
if ((options.scan === undefined) ===
|
|
2747
|
+
(options.scanDir === undefined)) {
|
|
2748
|
+
throw new CodexSecurityError("Severity classification requires exactly one of --scan or --scan-dir.");
|
|
2749
|
+
}
|
|
2750
|
+
const currentDirectory = dependencies.currentDirectory();
|
|
2751
|
+
const settings = {
|
|
2752
|
+
environment: dependencies.environment,
|
|
2753
|
+
workingDirectory: currentDirectory,
|
|
2754
|
+
signal: controller.signal,
|
|
2755
|
+
rubricPath: options.rubric === undefined
|
|
2756
|
+
? undefined
|
|
2757
|
+
: resolveCliPath(currentDirectory, options.rubric),
|
|
2758
|
+
knowledgeBasePaths: options.knowledgeBase.map((path) => resolveCliPath(currentDirectory, path)),
|
|
2759
|
+
findingIds: options.findingId.length === 0 ? undefined : options.findingId,
|
|
2760
|
+
reprocess: options.reprocess,
|
|
2761
|
+
model: options.model,
|
|
2762
|
+
reasoningEffort: options.effort,
|
|
2763
|
+
};
|
|
2764
|
+
const result = options.scan !== undefined
|
|
2765
|
+
? await (dependencies.classifyScanSeverity ??
|
|
2766
|
+
classifyScanSeverityInternal)(options.scan, settings, dependencies, "cli")
|
|
2767
|
+
: await (dependencies.classifyScanDirectorySeverity ??
|
|
2768
|
+
classifyScanDirectorySeverityInternal)(resolveCliPath(currentDirectory, options.scanDir), settings, "cli");
|
|
2769
|
+
return { ...result };
|
|
2770
|
+
}
|
|
2771
|
+
catch (error) {
|
|
2772
|
+
const signal = controller.signal.reason;
|
|
2773
|
+
errorOutput.write(`codex-security: ${signal === "SIGINT" || signal === "SIGTERM" ? "Severity classification canceled." : safeErrorMessage(error)}\n`);
|
|
2774
|
+
exitCode = signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 2;
|
|
2775
|
+
return undefined;
|
|
2776
|
+
}
|
|
2777
|
+
finally {
|
|
2778
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
2779
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
2780
|
+
}
|
|
2781
|
+
},
|
|
2782
|
+
})
|
|
2277
2783
|
.command("dedupe", {
|
|
2278
2784
|
description: "Review a saved scan with local Codex and save duplicate groups to the findings API.",
|
|
2279
2785
|
destructive: true,
|
|
2280
2786
|
mcp: false,
|
|
2281
2787
|
options: z.object({
|
|
2788
|
+
concurrency: z
|
|
2789
|
+
.number()
|
|
2790
|
+
.int()
|
|
2791
|
+
.positive()
|
|
2792
|
+
.default(DEFAULT_DEDUPE_CONCURRENCY)
|
|
2793
|
+
.describe("Maximum concurrent dedupe jobs across Luna and Sol; use 1 for serial execution."),
|
|
2282
2794
|
workflowId: optionValue("--workflow-id")
|
|
2283
2795
|
.optional()
|
|
2284
2796
|
.describe("Resume the named local findings workflow; reuses its saved scan."),
|
|
@@ -2318,6 +2830,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2318
2830
|
throw new CodexSecurityError("Deduplication requires --scan or --workflow-id.");
|
|
2319
2831
|
return await (dependencies.deduplicateScan ?? deduplicateScanInternal)(scanId, {
|
|
2320
2832
|
findingsUrl: options.findingsUrl,
|
|
2833
|
+
concurrency: options.concurrency,
|
|
2321
2834
|
...(options.workflowId === undefined
|
|
2322
2835
|
? {}
|
|
2323
2836
|
: { workflowId: options.workflowId }),
|
|
@@ -2428,6 +2941,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2428
2941
|
async run({ args, options }) {
|
|
2429
2942
|
const controller = new AbortController();
|
|
2430
2943
|
let dashboard = null;
|
|
2944
|
+
const componentNames = new Map();
|
|
2431
2945
|
const stopDashboard = () => {
|
|
2432
2946
|
try {
|
|
2433
2947
|
dashboard?.stop();
|
|
@@ -2500,9 +3014,19 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2500
3014
|
createSecurity: dependencies.createSecurity,
|
|
2501
3015
|
planComponents: dependencies.planComponents,
|
|
2502
3016
|
matchFindings: dependencies.matchFindings,
|
|
2503
|
-
onPlan: (components) =>
|
|
3017
|
+
onPlan: (components) => {
|
|
3018
|
+
for (const component of components)
|
|
3019
|
+
componentNames.set(component.id, component.name);
|
|
3020
|
+
dashboard?.setComponents(components);
|
|
3021
|
+
},
|
|
2504
3022
|
onScanEvent: dashboard === null
|
|
2505
|
-
?
|
|
3023
|
+
? (event) => {
|
|
3024
|
+
const componentName = componentNames.get(event.componentId) ??
|
|
3025
|
+
event.componentId;
|
|
3026
|
+
const line = componentScanEventLine(componentName, event);
|
|
3027
|
+
if (line !== null)
|
|
3028
|
+
errorOutput.write(line);
|
|
3029
|
+
}
|
|
2506
3030
|
: (event) => dashboard?.recordComponentEvent(event),
|
|
2507
3031
|
onDeduplicationStarted: () => {
|
|
2508
3032
|
if (dashboard !== null)
|
|
@@ -2559,6 +3083,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2559
3083
|
.describe("CSV repository list; omit to discover repositories interactively."),
|
|
2560
3084
|
}),
|
|
2561
3085
|
options: z.object({
|
|
3086
|
+
recover: z
|
|
3087
|
+
.boolean()
|
|
3088
|
+
.default(false)
|
|
3089
|
+
.describe("Recover failed or interrupted attempts in an existing campaign, preserving their artifacts and checkouts."),
|
|
2562
3090
|
outputDir: z
|
|
2563
3091
|
.string()
|
|
2564
3092
|
.min(1, "--output-dir must not be empty.")
|
|
@@ -2638,6 +3166,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2638
3166
|
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
2639
3167
|
try {
|
|
2640
3168
|
const currentDirectory = dependencies.currentDirectory();
|
|
3169
|
+
if (options.recover && args.input === undefined) {
|
|
3170
|
+
throw new Error("Bulk recovery requires the original repository CSV and --output-dir.");
|
|
3171
|
+
}
|
|
2641
3172
|
const prompts = await readPromptFiles(currentDirectory, options.scanPromptFile, options.postScanPromptFile, currentDirectory, options.validationPromptFile);
|
|
2642
3173
|
let inputPath;
|
|
2643
3174
|
let outputDir;
|
|
@@ -2683,6 +3214,76 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2683
3214
|
codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort, options.provider),
|
|
2684
3215
|
},
|
|
2685
3216
|
createSecurity: dependencies.createSecurity,
|
|
3217
|
+
...(options.recover
|
|
3218
|
+
? {
|
|
3219
|
+
recoverScan: async (scanDir) => {
|
|
3220
|
+
const history = await dependencies.runWorkbench(["list-scans", "--scan-root", scanDir], undefined, controller.signal);
|
|
3221
|
+
const scan = history["scans"].find((scan) => resolve(scan.scanDir) === scanDir);
|
|
3222
|
+
if (scan === undefined)
|
|
3223
|
+
return undefined;
|
|
3224
|
+
const status = scan["progress"]["status"];
|
|
3225
|
+
if (status === "complete") {
|
|
3226
|
+
const contract = await loadContract(scanDir, {
|
|
3227
|
+
pluginRoot: await bundledPluginRoot(),
|
|
3228
|
+
expectedScanId: scan.scanId,
|
|
3229
|
+
signal: controller.signal,
|
|
3230
|
+
});
|
|
3231
|
+
return {
|
|
3232
|
+
coverage: contract.coverage,
|
|
3233
|
+
cost: scan["cost"] ??
|
|
3234
|
+
null,
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
if (status !== "running" || scan["mode"] !== "deep")
|
|
3238
|
+
return undefined;
|
|
3239
|
+
const saved = await dependencies.runWorkbench([
|
|
3240
|
+
"get-cli-scan-resume",
|
|
3241
|
+
"--scan-id",
|
|
3242
|
+
scan.scanId,
|
|
3243
|
+
"--allow-unavailable",
|
|
3244
|
+
], undefined, controller.signal);
|
|
3245
|
+
if (typeof saved["unavailable"] === "string") {
|
|
3246
|
+
errorOutput.write(`codex-security: ${scan.scanId}: ${saved["unavailable"]} Preserving this attempt and starting a new one.\n`);
|
|
3247
|
+
return undefined;
|
|
3248
|
+
}
|
|
3249
|
+
const session = typeof saved["threadId"] === "string"
|
|
3250
|
+
? await findScanSession(codexSecurityCredentialHome(dependencies.environment), saved["threadId"])
|
|
3251
|
+
: null;
|
|
3252
|
+
if (session?.workingDirectory !== scanDir) {
|
|
3253
|
+
errorOutput.write(`codex-security: ${scan.scanId}: Original session logs are unavailable. Preserving this attempt and starting a new one.\n`);
|
|
3254
|
+
return undefined;
|
|
3255
|
+
}
|
|
3256
|
+
const recipe = scanArgumentsFromRecipe(saved["recipe"], scan.scanId);
|
|
3257
|
+
const security = dependencies.createSecurity({
|
|
3258
|
+
pluginPath: options.pluginPath,
|
|
3259
|
+
pythonPath: options.python,
|
|
3260
|
+
codexOverrides: recipe.codexOverrides,
|
|
3261
|
+
});
|
|
3262
|
+
try {
|
|
3263
|
+
return await security.run(recipe.repository, {
|
|
3264
|
+
resumeScanId: scan.scanId,
|
|
3265
|
+
outputDir: scanDir,
|
|
3266
|
+
mode: recipe.mode,
|
|
3267
|
+
target: targetFromArguments(recipe),
|
|
3268
|
+
knowledgeBasePaths: recipe.knowledgeBasePaths,
|
|
3269
|
+
workers: recipe.workers,
|
|
3270
|
+
subagents: recipe.subagents,
|
|
3271
|
+
stopAfterNoNew: recipe.stopAfterNoNew,
|
|
3272
|
+
maxDiscoveryRuns: recipe.maxDiscoveryRuns,
|
|
3273
|
+
maxTimeHours: recipe.maxTimeHours,
|
|
3274
|
+
maxCostUsd: recipe.maxCostUsd,
|
|
3275
|
+
failureSeverity: recipe.failOnSeverity,
|
|
3276
|
+
safetyIdentifier: recipe.safetyIdentifier,
|
|
3277
|
+
postScanPrompt: recipe.postScanPrompt ?? prompts.postScanPrompt,
|
|
3278
|
+
signal: controller.signal,
|
|
3279
|
+
});
|
|
3280
|
+
}
|
|
3281
|
+
finally {
|
|
3282
|
+
await security.close();
|
|
3283
|
+
}
|
|
3284
|
+
},
|
|
3285
|
+
}
|
|
3286
|
+
: {}),
|
|
2686
3287
|
signal: controller.signal,
|
|
2687
3288
|
onProgress: ({ repository, status, attempt, error, warning }) => {
|
|
2688
3289
|
const detail = error ?? warning;
|
|
@@ -2768,15 +3369,19 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2768
3369
|
.describe("Finding text or a file containing findings."),
|
|
2769
3370
|
}),
|
|
2770
3371
|
options: z.object({
|
|
3372
|
+
auth: z
|
|
3373
|
+
.enum(SCAN_AUTH_MODES)
|
|
3374
|
+
.default("auto")
|
|
3375
|
+
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
2771
3376
|
effort: effortOption(),
|
|
2772
3377
|
codex: z
|
|
2773
3378
|
.array(optionValue("--codex"))
|
|
2774
3379
|
.default([])
|
|
2775
|
-
.describe('Repeat TOML model="gpt-5.6-terra"
|
|
3380
|
+
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
2776
3381
|
}),
|
|
2777
3382
|
async run({ options }) {
|
|
2778
3383
|
try {
|
|
2779
|
-
exitCode = await runSkill("validation", positionals, options.codex, options.effort, output, errorOutput, dependencies);
|
|
3384
|
+
exitCode = await runSkill("validation", positionals, options.codex, options.effort, output, errorOutput, dependencies, { auth: options.auth });
|
|
2780
3385
|
}
|
|
2781
3386
|
catch (error) {
|
|
2782
3387
|
exitCode = 2;
|
|
@@ -2796,6 +3401,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2796
3401
|
.describe("Finding text, a file, or a saved finding identifier."),
|
|
2797
3402
|
}),
|
|
2798
3403
|
options: z.object({
|
|
3404
|
+
auth: z
|
|
3405
|
+
.enum(SCAN_AUTH_MODES)
|
|
3406
|
+
.default("auto")
|
|
3407
|
+
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
2799
3408
|
effort: effortOption(),
|
|
2800
3409
|
scan: optionValue("--scan")
|
|
2801
3410
|
.optional()
|
|
@@ -2818,7 +3427,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2818
3427
|
codex: z
|
|
2819
3428
|
.array(optionValue("--codex"))
|
|
2820
3429
|
.default([])
|
|
2821
|
-
.describe('Repeat TOML model="gpt-5.6-terra"
|
|
3430
|
+
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
2822
3431
|
}),
|
|
2823
3432
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
2824
3433
|
async run({ format, options }) {
|
|
@@ -2887,6 +3496,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2887
3496
|
...(selected === undefined
|
|
2888
3497
|
? {}
|
|
2889
3498
|
: { findings: selected.findings }),
|
|
3499
|
+
auth: options.auth,
|
|
2890
3500
|
verificationIds: identifiers,
|
|
2891
3501
|
environment,
|
|
2892
3502
|
onEvent: progress.observe.bind(progress),
|
|
@@ -2954,6 +3564,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2954
3564
|
.describe("Issue text or a file containing issues."),
|
|
2955
3565
|
}),
|
|
2956
3566
|
options: z.object({
|
|
3567
|
+
auth: z
|
|
3568
|
+
.enum(SCAN_AUTH_MODES)
|
|
3569
|
+
.default("auto")
|
|
3570
|
+
.describe("Credential source: auto, chatgpt, or api-key."),
|
|
2957
3571
|
effort: effortOption(),
|
|
2958
3572
|
scan: optionValue("--scan")
|
|
2959
3573
|
.optional()
|
|
@@ -2981,7 +3595,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2981
3595
|
codex: z
|
|
2982
3596
|
.array(optionValue("--codex"))
|
|
2983
3597
|
.default([])
|
|
2984
|
-
.describe('Repeat TOML model="gpt-5.6-terra"
|
|
3598
|
+
.describe('Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.'),
|
|
2985
3599
|
}),
|
|
2986
3600
|
output: z.record(z.string(), z.unknown()).optional(),
|
|
2987
3601
|
async run({ format, options }) {
|
|
@@ -2997,6 +3611,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
2997
3611
|
options.linearFilter !== undefined ||
|
|
2998
3612
|
options.linearApiKey !== undefined ||
|
|
2999
3613
|
options.effort !== undefined ||
|
|
3614
|
+
options.auth !== "auto" ||
|
|
3000
3615
|
options.codex.length > 0) {
|
|
3001
3616
|
throw new CodexSecurityError("--resume-pr cannot be combined with patch inputs or options.");
|
|
3002
3617
|
}
|
|
@@ -3025,7 +3640,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3025
3640
|
const patchRiskBase = options.assessPatchRisk
|
|
3026
3641
|
? await snapshotPatchTree(selected.repository, dependencies)
|
|
3027
3642
|
: undefined;
|
|
3028
|
-
const patches = await runFindingPatches(selected, options.codex, options.effort, errorOutput, dependencies);
|
|
3643
|
+
const patches = await runFindingPatches(selected, options.codex, options.effort, errorOutput, dependencies, { auth: options.auth });
|
|
3029
3644
|
exitCode = patchExitCode(patches);
|
|
3030
3645
|
let patchRisk;
|
|
3031
3646
|
if (options.assessPatchRisk && exitCode === 0) {
|
|
@@ -3037,6 +3652,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3037
3652
|
files,
|
|
3038
3653
|
codexOverrides: options.codex,
|
|
3039
3654
|
effort: options.effort,
|
|
3655
|
+
auth: options.auth,
|
|
3040
3656
|
}, errorOutput, dependencies);
|
|
3041
3657
|
}
|
|
3042
3658
|
}
|
|
@@ -3085,16 +3701,18 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3085
3701
|
if (options.createPr) {
|
|
3086
3702
|
await requireCleanPatchPullRequestBase(repository, patchBase, dependencies);
|
|
3087
3703
|
}
|
|
3088
|
-
exitCode = await runSkill("fix-finding", [...positionals, ...imports], options.codex, options.effort, output, errorOutput, dependencies, { environment });
|
|
3704
|
+
exitCode = await runSkill("fix-finding", [...positionals, ...imports], options.codex, options.effort, output, errorOutput, dependencies, { environment, auth: options.auth });
|
|
3089
3705
|
if (patchBase !== undefined && exitCode === 0) {
|
|
3090
3706
|
const files = await changedPatchFiles(repository, patchBase, dependencies);
|
|
3091
3707
|
const patchRisk = options.assessPatchRisk
|
|
3092
3708
|
? await runPatchRiskAssessment({
|
|
3093
3709
|
repository,
|
|
3710
|
+
environment,
|
|
3094
3711
|
base: patchBase,
|
|
3095
3712
|
files,
|
|
3096
3713
|
codexOverrides: options.codex,
|
|
3097
3714
|
effort: options.effort,
|
|
3715
|
+
auth: options.auth,
|
|
3098
3716
|
}, errorOutput, dependencies)
|
|
3099
3717
|
: undefined;
|
|
3100
3718
|
if (options.createPr) {
|
|
@@ -3232,6 +3850,70 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3232
3850
|
exitCode = 1;
|
|
3233
3851
|
}
|
|
3234
3852
|
},
|
|
3853
|
+
})
|
|
3854
|
+
.command("feedback", {
|
|
3855
|
+
description: "Send feedback to OpenAI and return a feedback ID.",
|
|
3856
|
+
destructive: true,
|
|
3857
|
+
mcp: false,
|
|
3858
|
+
args: z.object({
|
|
3859
|
+
scanId: z
|
|
3860
|
+
.string()
|
|
3861
|
+
.min(1)
|
|
3862
|
+
.optional()
|
|
3863
|
+
.describe("Scan ID or unique prefix (default: most recently started scan in the current repository)."),
|
|
3864
|
+
}),
|
|
3865
|
+
options: z.object({
|
|
3866
|
+
reason: z.string().trim().min(1).describe("Describe the problem."),
|
|
3867
|
+
includeLogs: z
|
|
3868
|
+
.boolean()
|
|
3869
|
+
.default(false)
|
|
3870
|
+
.describe("Upload diagnostic logs, including scan and worker conversations and tool output. Defaults to off."),
|
|
3871
|
+
}),
|
|
3872
|
+
output: z.object({
|
|
3873
|
+
feedbackId: z.string(),
|
|
3874
|
+
scanId: z.string().nullable(),
|
|
3875
|
+
includedLogs: z.boolean(),
|
|
3876
|
+
}),
|
|
3877
|
+
async run({ args, options }) {
|
|
3878
|
+
let scanId = args.scanId;
|
|
3879
|
+
if (scanId === undefined) {
|
|
3880
|
+
const value = await history([
|
|
3881
|
+
"list-scans",
|
|
3882
|
+
"--repository",
|
|
3883
|
+
dependencies.currentDirectory(),
|
|
3884
|
+
]);
|
|
3885
|
+
const scans = value["scans"];
|
|
3886
|
+
scanId = scans.toSorted((a, b) => b.startedAt.localeCompare(a.startedAt))[0]?.scanId;
|
|
3887
|
+
}
|
|
3888
|
+
const scan = scanId === undefined
|
|
3889
|
+
? undefined
|
|
3890
|
+
: (await history(["get-scan", "--scan-id", scanId]))["scan"];
|
|
3891
|
+
const controller = new AbortController();
|
|
3892
|
+
const onInterrupt = () => controller.abort("SIGINT");
|
|
3893
|
+
const onTerminate = () => controller.abort("SIGTERM");
|
|
3894
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
3895
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
3896
|
+
try {
|
|
3897
|
+
return await (dependencies.sendFeedback ?? sendFeedback)({
|
|
3898
|
+
...options,
|
|
3899
|
+
scan,
|
|
3900
|
+
environment: dependencies.environment,
|
|
3901
|
+
workingDirectory: dependencies.currentDirectory(),
|
|
3902
|
+
signal: controller.signal,
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
catch (error) {
|
|
3906
|
+
if (controller.signal.aborted) {
|
|
3907
|
+
exitCode = controller.signal.reason === "SIGINT" ? 130 : 143;
|
|
3908
|
+
errorOutput.write("codex-security: Feedback upload canceled.\n");
|
|
3909
|
+
}
|
|
3910
|
+
throw error;
|
|
3911
|
+
}
|
|
3912
|
+
finally {
|
|
3913
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
3914
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
3915
|
+
}
|
|
3916
|
+
},
|
|
3235
3917
|
})
|
|
3236
3918
|
.command("info", {
|
|
3237
3919
|
description: "Show read-only SDK and bundled-plugin metadata.",
|
|
@@ -3269,6 +3951,73 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3269
3951
|
};
|
|
3270
3952
|
},
|
|
3271
3953
|
});
|
|
3954
|
+
// Incur cannot mount a command with both a handler and subcommands.
|
|
3955
|
+
// Select the nested import route while preserving scan [repository].
|
|
3956
|
+
if (isScanImportCommand(argv)) {
|
|
3957
|
+
cli.command(Cli.create("scan", {
|
|
3958
|
+
description: "Run or import a saved scan.",
|
|
3959
|
+
}).command("import", {
|
|
3960
|
+
description: "Save CSV or JSON findings as a completed scan without security analysis.",
|
|
3961
|
+
destructive: true,
|
|
3962
|
+
mcp: false,
|
|
3963
|
+
options: z
|
|
3964
|
+
.object({
|
|
3965
|
+
csv: optionValue("--csv")
|
|
3966
|
+
.optional()
|
|
3967
|
+
.describe("Findings CSV in the codex-security export format."),
|
|
3968
|
+
json: optionValue("--json")
|
|
3969
|
+
.optional()
|
|
3970
|
+
.describe("Findings JSON document or object with a findings array."),
|
|
3971
|
+
outputDir: optionValue("--output-dir")
|
|
3972
|
+
.optional()
|
|
3973
|
+
.describe("Artifact directory (default: Codex Security state; CODEX_SECURITY_STATE_DIR)."),
|
|
3974
|
+
archiveExisting: z
|
|
3975
|
+
.boolean()
|
|
3976
|
+
.default(false)
|
|
3977
|
+
.describe("Archive existing results; requires --output-dir."),
|
|
3978
|
+
dryRun: z
|
|
3979
|
+
.boolean()
|
|
3980
|
+
.default(false)
|
|
3981
|
+
.describe("Validate the input without saving a scan."),
|
|
3982
|
+
})
|
|
3983
|
+
.refine((options) => Number(options.csv !== undefined) +
|
|
3984
|
+
Number(options.json !== undefined) ===
|
|
3985
|
+
1, { message: "Provide exactly one of --csv FILE or --json FILE." })
|
|
3986
|
+
.refine((options) => !options.archiveExisting || options.outputDir !== undefined, { message: "--archive-existing requires --output-dir." }),
|
|
3987
|
+
examples: [
|
|
3988
|
+
{ options: { csv: "findings.csv" } },
|
|
3989
|
+
{ options: { json: "findings.json" } },
|
|
3990
|
+
],
|
|
3991
|
+
hint: "Each input row is retained, including duplicates. --json selects the input file; use --format json for JSON output.",
|
|
3992
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
3993
|
+
async run({ options, format, error: incurError }) {
|
|
3994
|
+
const directory = dependencies.currentDirectory();
|
|
3995
|
+
const outcome = await runImport({
|
|
3996
|
+
sourcePath: resolveCliPath(directory, options.csv ?? options.json),
|
|
3997
|
+
format: options.csv === undefined ? "json" : "csv",
|
|
3998
|
+
outputDir: options.outputDir === undefined
|
|
3999
|
+
? undefined
|
|
4000
|
+
: resolveCliPath(directory, options.outputDir),
|
|
4001
|
+
archiveExisting: options.archiveExisting,
|
|
4002
|
+
dryRun: options.dryRun,
|
|
4003
|
+
});
|
|
4004
|
+
exitCode = outcome.exitCode;
|
|
4005
|
+
if (outcome.error !== undefined) {
|
|
4006
|
+
return incurError({
|
|
4007
|
+
code: "SCAN_IMPORT_FAILED",
|
|
4008
|
+
message: outcome.error,
|
|
4009
|
+
exitCode,
|
|
4010
|
+
});
|
|
4011
|
+
}
|
|
4012
|
+
if (!options.dryRun &&
|
|
4013
|
+
format === "toon" &&
|
|
4014
|
+
!argv.some((argument) => OUTPUT_OPTION.test(argument))) {
|
|
4015
|
+
return;
|
|
4016
|
+
}
|
|
4017
|
+
return outcome.data;
|
|
4018
|
+
},
|
|
4019
|
+
}));
|
|
4020
|
+
}
|
|
3272
4021
|
let notice;
|
|
3273
4022
|
try {
|
|
3274
4023
|
await cli.serve(argv.flatMap((argument) => argument.startsWith("--format=")
|
|
@@ -3291,15 +4040,24 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3291
4040
|
if (notice !== undefined)
|
|
3292
4041
|
errorOutput.write(formatUpdateNotice(notice));
|
|
3293
4042
|
if (frameworkExit !== undefined) {
|
|
3294
|
-
if (
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
4043
|
+
if (policyFullOutput) {
|
|
4044
|
+
if (exitCode === 0)
|
|
4045
|
+
exitCode = 2;
|
|
4046
|
+
}
|
|
4047
|
+
else {
|
|
4048
|
+
if (exitCode !== 0)
|
|
4049
|
+
return exitCode;
|
|
4050
|
+
errorOutput.write(`codex-security: ${errorMessage(incurErrorMessage(frameworkOutput))}\n`);
|
|
4051
|
+
return 2;
|
|
4052
|
+
}
|
|
3298
4053
|
}
|
|
3299
4054
|
if (frameworkOutput.length === 0)
|
|
3300
4055
|
return exitCode;
|
|
3301
4056
|
try {
|
|
3302
|
-
await writeCliOutput(output,
|
|
4057
|
+
await writeCliOutput(output, renderedPolicy ??
|
|
4058
|
+
renderedPublication ??
|
|
4059
|
+
renderedHistory ??
|
|
4060
|
+
frameworkOutput);
|
|
3303
4061
|
return exitCode;
|
|
3304
4062
|
}
|
|
3305
4063
|
catch (error) {
|
|
@@ -3307,12 +4065,75 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
3307
4065
|
return 2;
|
|
3308
4066
|
}
|
|
3309
4067
|
}
|
|
3310
|
-
function
|
|
3311
|
-
const
|
|
4068
|
+
async function runScanImport(options, errorOutput, dependencies) {
|
|
4069
|
+
const controller = new AbortController();
|
|
4070
|
+
const onInterrupt = () => controller.abort("SIGINT");
|
|
4071
|
+
const onTerminate = () => controller.abort("SIGTERM");
|
|
4072
|
+
dependencies.addSignalListener("SIGINT", onInterrupt);
|
|
4073
|
+
dependencies.addSignalListener("SIGTERM", onTerminate);
|
|
4074
|
+
try {
|
|
4075
|
+
const result = await (dependencies.importScan ?? importScan)({ ...options, signal: controller.signal }, { environment: dependencies.environment });
|
|
4076
|
+
if ("dryRun" in result)
|
|
4077
|
+
return { exitCode: 0, data: { ...result } };
|
|
4078
|
+
try {
|
|
4079
|
+
errorOutput.write(`Imported ${result.findings.findings.length} findings as scan ${result.manifest.scan.id}.\n` +
|
|
4080
|
+
`Artifacts: ${result.scanDir}\n`);
|
|
4081
|
+
}
|
|
4082
|
+
catch { }
|
|
4083
|
+
return { exitCode: 0, data: result.toJSON() };
|
|
4084
|
+
}
|
|
4085
|
+
catch (error) {
|
|
4086
|
+
const signal = controller.signal.reason;
|
|
4087
|
+
const message = signal === "SIGINT" || signal === "SIGTERM"
|
|
4088
|
+
? "Scan import canceled."
|
|
4089
|
+
: safeErrorMessage(error);
|
|
4090
|
+
errorOutput.write(`codex-security: ${message}\n`);
|
|
4091
|
+
return {
|
|
4092
|
+
exitCode: signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 2,
|
|
4093
|
+
error: message,
|
|
4094
|
+
};
|
|
4095
|
+
}
|
|
4096
|
+
finally {
|
|
4097
|
+
dependencies.removeSignalListener("SIGINT", onInterrupt);
|
|
4098
|
+
dependencies.removeSignalListener("SIGTERM", onTerminate);
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
function isScanImportCommand(argv) {
|
|
4102
|
+
const commandIndex = cliCommandIndex(argv);
|
|
4103
|
+
return argv[commandIndex] === "scan" && argv[commandIndex + 1] === "import";
|
|
4104
|
+
}
|
|
4105
|
+
function normalizeScanImportArguments(argv) {
|
|
4106
|
+
if (!isScanImportCommand(argv))
|
|
4107
|
+
return argv;
|
|
4108
|
+
const normalized = [];
|
|
4109
|
+
const subcommandIndex = cliCommandIndex(argv) + 1;
|
|
4110
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
4111
|
+
const argument = argv[index];
|
|
4112
|
+
const next = argv[index + 1];
|
|
4113
|
+
// Incur reserves bare --json for output, but parses --json=FILE normally.
|
|
4114
|
+
if (index > subcommandIndex &&
|
|
4115
|
+
argument === "--json" &&
|
|
4116
|
+
next !== undefined &&
|
|
4117
|
+
!next.startsWith("--") &&
|
|
4118
|
+
next !== "-h") {
|
|
4119
|
+
normalized.push(`--json=${next}`);
|
|
4120
|
+
index += 1;
|
|
4121
|
+
}
|
|
4122
|
+
else {
|
|
4123
|
+
normalized.push(argument);
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
return normalized;
|
|
4127
|
+
}
|
|
4128
|
+
function cliCommandIndex(argv) {
|
|
4129
|
+
return argv.findIndex((value, index) => {
|
|
3312
4130
|
if (value.startsWith("-"))
|
|
3313
4131
|
return false;
|
|
3314
4132
|
return index === 0 || !VALUE_OPTIONS.has(argv[index - 1]);
|
|
3315
4133
|
});
|
|
4134
|
+
}
|
|
4135
|
+
function defaultListCommand(argv) {
|
|
4136
|
+
const commandIndex = cliCommandIndex(argv);
|
|
3316
4137
|
if (commandIndex < 0 ||
|
|
3317
4138
|
!["scans", "findings"].includes(argv[commandIndex]) ||
|
|
3318
4139
|
argv.includes("--help") ||
|
|
@@ -3403,11 +4224,19 @@ function scanArgumentsFromRecipe(recipe, parentScanId, validationPromptFile) {
|
|
|
3403
4224
|
Object.keys(deepScan.data).length > 0) {
|
|
3404
4225
|
throw new CodexSecurityError("The saved scan recipe contains deep scan settings for a standard scan.");
|
|
3405
4226
|
}
|
|
4227
|
+
const safetyIdentifier = recipe["safetyIdentifier"];
|
|
4228
|
+
const postScanPrompt = recipe["postScanPrompt"];
|
|
4229
|
+
if ((safetyIdentifier !== undefined && typeof safetyIdentifier !== "string") ||
|
|
4230
|
+
(postScanPrompt !== undefined && typeof postScanPrompt !== "string")) {
|
|
4231
|
+
throw new CodexSecurityError("The saved scan recipe contains invalid launch settings.");
|
|
4232
|
+
}
|
|
3406
4233
|
return {
|
|
3407
4234
|
repository,
|
|
3408
4235
|
paths,
|
|
3409
4236
|
knowledgeBasePaths,
|
|
3410
4237
|
validationPromptFile,
|
|
4238
|
+
safetyIdentifier,
|
|
4239
|
+
postScanPrompt,
|
|
3411
4240
|
diff: kind === "refs" ? reference : undefined,
|
|
3412
4241
|
workingTree: kind === "working_tree",
|
|
3413
4242
|
head: kind === "refs" ? head ?? "HEAD" : undefined,
|
|
@@ -3432,27 +4261,31 @@ function scanArgumentsFromRecipe(recipe, parentScanId, validationPromptFile) {
|
|
|
3432
4261
|
function validateCliArguments(argv, positionals) {
|
|
3433
4262
|
if (argv.includes("--help") || argv.includes("-h"))
|
|
3434
4263
|
return undefined;
|
|
3435
|
-
const commandIndex = argv
|
|
3436
|
-
"scan",
|
|
3437
|
-
"install-hook",
|
|
3438
|
-
"bulk-scan",
|
|
3439
|
-
"scan-components",
|
|
3440
|
-
"scans",
|
|
3441
|
-
"findings",
|
|
3442
|
-
"export",
|
|
3443
|
-
"publish",
|
|
3444
|
-
"import",
|
|
3445
|
-
"validate",
|
|
3446
|
-
"verify-fix",
|
|
3447
|
-
"patch",
|
|
3448
|
-
"login",
|
|
3449
|
-
"logout",
|
|
3450
|
-
"serve",
|
|
3451
|
-
"info",
|
|
3452
|
-
].includes(value));
|
|
3453
|
-
if (commandIndex < 0)
|
|
3454
|
-
return undefined;
|
|
4264
|
+
const commandIndex = cliCommandIndex(argv);
|
|
3455
4265
|
const command = argv[commandIndex];
|
|
4266
|
+
if (command === undefined ||
|
|
4267
|
+
![
|
|
4268
|
+
"scan",
|
|
4269
|
+
"policy",
|
|
4270
|
+
"install-hook",
|
|
4271
|
+
"bulk-scan",
|
|
4272
|
+
"scan-components",
|
|
4273
|
+
"scans",
|
|
4274
|
+
"findings",
|
|
4275
|
+
"export",
|
|
4276
|
+
"publish",
|
|
4277
|
+
"import",
|
|
4278
|
+
"validate",
|
|
4279
|
+
"verify-fix",
|
|
4280
|
+
"patch",
|
|
4281
|
+
"login",
|
|
4282
|
+
"logout",
|
|
4283
|
+
"serve",
|
|
4284
|
+
"feedback",
|
|
4285
|
+
"info",
|
|
4286
|
+
].includes(command)) {
|
|
4287
|
+
return undefined;
|
|
4288
|
+
}
|
|
3456
4289
|
const structuredOutput = argv.some((value, index) => value === "--json" ||
|
|
3457
4290
|
((value === "--format" ||
|
|
3458
4291
|
value === "--format=json" ||
|
|
@@ -3483,7 +4316,9 @@ function validateCliArguments(argv, positionals) {
|
|
|
3483
4316
|
return "Markdown output is not supported for scan results.";
|
|
3484
4317
|
}
|
|
3485
4318
|
}
|
|
3486
|
-
const
|
|
4319
|
+
const scanImport = isScanImportCommand(argv);
|
|
4320
|
+
const nestedCommand = scanImport ||
|
|
4321
|
+
command === "scans" ||
|
|
3487
4322
|
command === "findings" ||
|
|
3488
4323
|
command === "publish" ||
|
|
3489
4324
|
command === "import";
|
|
@@ -3524,7 +4359,8 @@ function validateCliArguments(argv, positionals) {
|
|
|
3524
4359
|
}
|
|
3525
4360
|
const equals = value.indexOf("=");
|
|
3526
4361
|
const option = equals < 0 ? value : value.slice(0, equals);
|
|
3527
|
-
if (equals >= 0 ||
|
|
4362
|
+
if (equals >= 0 ||
|
|
4363
|
+
(!VALUE_OPTIONS.has(option) && !(scanImport && option === "--json")))
|
|
3528
4364
|
continue;
|
|
3529
4365
|
const next = argv[index + 1];
|
|
3530
4366
|
if (next === undefined || next.startsWith("--") || next === "-h") {
|
|
@@ -3545,7 +4381,10 @@ function validateCliArguments(argv, positionals) {
|
|
|
3545
4381
|
command !== "verify-fix" &&
|
|
3546
4382
|
command !== "patch" &&
|
|
3547
4383
|
positionals.length >
|
|
3548
|
-
(
|
|
4384
|
+
(scanImport ||
|
|
4385
|
+
command === "logout" ||
|
|
4386
|
+
command === "info" ||
|
|
4387
|
+
command === "serve"
|
|
3549
4388
|
? 0
|
|
3550
4389
|
: subcommand === "compare" || subcommand === "match"
|
|
3551
4390
|
? 2
|
|
@@ -3553,18 +4392,21 @@ function validateCliArguments(argv, positionals) {
|
|
|
3553
4392
|
return `Unexpected positional argument for ${command}${subcommand === undefined ? "" : ` ${subcommand}`}.`;
|
|
3554
4393
|
}
|
|
3555
4394
|
}
|
|
3556
|
-
async function matchAllScans(dependencies, force) {
|
|
4395
|
+
async function matchAllScans(dependencies, force, options = {}) {
|
|
3557
4396
|
const result = (await dependencies.runWorkbench([
|
|
3558
4397
|
"list-unmatched-scan-pairs",
|
|
3559
4398
|
"--repository",
|
|
3560
4399
|
dependencies.currentDirectory(),
|
|
3561
4400
|
...(force ? ["--force"] : []),
|
|
3562
|
-
]));
|
|
4401
|
+
], undefined, options.signal));
|
|
3563
4402
|
const { repository, scanCount, unavailableScans, skippedPairs, batches } = result;
|
|
3564
4403
|
let matchedPairs = 0;
|
|
3565
4404
|
let findingMatches = 0;
|
|
4405
|
+
let relatedPairs = 0;
|
|
4406
|
+
let uncertainPairs = 0;
|
|
3566
4407
|
const newlyMatchedGroups = [];
|
|
3567
4408
|
for (const { afterScanId, afterFindings, beforeScans, knownFindingGroups = [], } of batches) {
|
|
4409
|
+
options.signal?.throwIfAborted();
|
|
3568
4410
|
const before = beforeScans.flatMap(({ findings }) => findings);
|
|
3569
4411
|
const knownGroups = unionFindingGroups([
|
|
3570
4412
|
...knownFindingGroups,
|
|
@@ -3578,25 +4420,15 @@ async function matchAllScans(dependencies, force) {
|
|
|
3578
4420
|
const matching = before.length === 0 || afterFindings.length === 0
|
|
3579
4421
|
? { matches: [], uncertain: [] }
|
|
3580
4422
|
: await dependencies.matchFindings(input, {
|
|
4423
|
+
...options,
|
|
3581
4424
|
allowHistoricalUncertainty: true,
|
|
3582
4425
|
});
|
|
3583
|
-
const comparisons = beforeScans.map(({ scanId, findings }) => {
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
: [{ ...match, beforeOccurrenceIds }];
|
|
3590
|
-
});
|
|
3591
|
-
const uncertain = matching.uncertain.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
|
|
3592
|
-
const related = matching.related?.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
|
|
3593
|
-
const matchedAfter = new Set(matches.flatMap(({ afterOccurrenceIds }) => afterOccurrenceIds));
|
|
3594
|
-
if (uncertain.some(({ afterOccurrenceId }) => matchedAfter.has(afterOccurrenceId))) {
|
|
3595
|
-
throw new CodexSecurityError("Scan matching returned conflicting confirmed and uncertain findings.");
|
|
3596
|
-
}
|
|
3597
|
-
return { scanId, matches, uncertain, related };
|
|
3598
|
-
});
|
|
3599
|
-
for (const { scanId, matches, uncertain, related } of comparisons) {
|
|
4426
|
+
const comparisons = beforeScans.map(({ scanId, findings }) => ({
|
|
4427
|
+
scanId,
|
|
4428
|
+
comparison: comparisonForScan(matching, findings),
|
|
4429
|
+
}));
|
|
4430
|
+
for (const { scanId, comparison } of comparisons) {
|
|
4431
|
+
options.signal?.throwIfAborted();
|
|
3600
4432
|
await dependencies.runWorkbench([
|
|
3601
4433
|
"save-scan-comparison",
|
|
3602
4434
|
"--before-scan-id",
|
|
@@ -3604,9 +4436,11 @@ async function matchAllScans(dependencies, force) {
|
|
|
3604
4436
|
"--after-scan-id",
|
|
3605
4437
|
afterScanId,
|
|
3606
4438
|
"--matches-json-stdin",
|
|
3607
|
-
], JSON.stringify(
|
|
4439
|
+
], JSON.stringify(comparison), options.signal);
|
|
3608
4440
|
matchedPairs += 1;
|
|
3609
|
-
findingMatches += matches.reduce((count, { beforeOccurrenceIds, afterOccurrenceIds }) => count + beforeOccurrenceIds.length * afterOccurrenceIds.length, 0);
|
|
4441
|
+
findingMatches += comparison.matches.reduce((count, { beforeOccurrenceIds, afterOccurrenceIds }) => count + beforeOccurrenceIds.length * afterOccurrenceIds.length, 0);
|
|
4442
|
+
relatedPairs += comparison.related?.length ?? 0;
|
|
4443
|
+
uncertainPairs += comparison.uncertain.length;
|
|
3610
4444
|
}
|
|
3611
4445
|
newlyMatchedGroups.push(...comparisonFindingGroups(input, matching));
|
|
3612
4446
|
}
|
|
@@ -3617,6 +4451,8 @@ async function matchAllScans(dependencies, force) {
|
|
|
3617
4451
|
matchedPairs,
|
|
3618
4452
|
skippedPairs,
|
|
3619
4453
|
findingMatches,
|
|
4454
|
+
relatedPairs,
|
|
4455
|
+
uncertainPairs,
|
|
3620
4456
|
};
|
|
3621
4457
|
}
|
|
3622
4458
|
function staysWithinWindowsDeviceRoot(input, root) {
|
|
@@ -3776,33 +4612,75 @@ function directPatchDigest(positionals, imports) {
|
|
|
3776
4612
|
async function publishPatchBranch(repository, branch, body, stderr, dependencies) {
|
|
3777
4613
|
const run = (command, args) => dependencies.runRepositoryCommand(command, args, repository);
|
|
3778
4614
|
try {
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
"
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
4615
|
+
const remote = await run("git", ["remote", "get-url", "--push", "origin"]);
|
|
4616
|
+
const host = patchRemoteHost(remote);
|
|
4617
|
+
const gitlabHost = dependencies.environment["GITLAB_HOST"] ||
|
|
4618
|
+
dependencies.environment["GITLAB_URI"] ||
|
|
4619
|
+
dependencies.environment["GL_HOST"];
|
|
4620
|
+
const gitlab = host === "gitlab.com" ||
|
|
4621
|
+
(host !== undefined &&
|
|
4622
|
+
gitlabHost !== undefined &&
|
|
4623
|
+
host ===
|
|
4624
|
+
patchRemoteHost(gitlabHost.includes("://") ? gitlabHost : `https://${gitlabHost}`));
|
|
4625
|
+
const command = gitlab ? "glab" : "gh";
|
|
4626
|
+
let url = await run(command, gitlab
|
|
4627
|
+
? [
|
|
4628
|
+
"mr",
|
|
4629
|
+
"list",
|
|
4630
|
+
"--all",
|
|
4631
|
+
"--source-branch",
|
|
4632
|
+
branch,
|
|
4633
|
+
"--output",
|
|
4634
|
+
"json",
|
|
4635
|
+
"--jq",
|
|
4636
|
+
".[0].web_url // empty",
|
|
4637
|
+
"--repo",
|
|
4638
|
+
remote,
|
|
4639
|
+
]
|
|
4640
|
+
: [
|
|
3794
4641
|
"pr",
|
|
3795
|
-
"
|
|
3796
|
-
"--draft",
|
|
4642
|
+
"list",
|
|
3797
4643
|
"--head",
|
|
3798
4644
|
branch,
|
|
3799
|
-
"--
|
|
3800
|
-
|
|
3801
|
-
"--
|
|
3802
|
-
|
|
4645
|
+
"--state",
|
|
4646
|
+
"all",
|
|
4647
|
+
"--json",
|
|
4648
|
+
"url",
|
|
4649
|
+
"--jq",
|
|
4650
|
+
".[0].url // empty",
|
|
3803
4651
|
]);
|
|
4652
|
+
if (!url) {
|
|
4653
|
+
await run("git", ["push", "--set-upstream", "origin", branch]);
|
|
4654
|
+
url = await run(command, gitlab
|
|
4655
|
+
? [
|
|
4656
|
+
"mr",
|
|
4657
|
+
"create",
|
|
4658
|
+
"--draft",
|
|
4659
|
+
"--head",
|
|
4660
|
+
remote,
|
|
4661
|
+
"--source-branch",
|
|
4662
|
+
branch,
|
|
4663
|
+
"--title",
|
|
4664
|
+
PATCH_PR_TITLE,
|
|
4665
|
+
"--description",
|
|
4666
|
+
body,
|
|
4667
|
+
"--yes",
|
|
4668
|
+
"--repo",
|
|
4669
|
+
remote,
|
|
4670
|
+
]
|
|
4671
|
+
: [
|
|
4672
|
+
"pr",
|
|
4673
|
+
"create",
|
|
4674
|
+
"--draft",
|
|
4675
|
+
"--head",
|
|
4676
|
+
branch,
|
|
4677
|
+
"--title",
|
|
4678
|
+
PATCH_PR_TITLE,
|
|
4679
|
+
"--body",
|
|
4680
|
+
body,
|
|
4681
|
+
]);
|
|
3804
4682
|
}
|
|
3805
|
-
stderr.write(
|
|
4683
|
+
stderr.write(`${gitlab ? "Merge" : "Pull"} request: ${safePatchText(url)}\n`);
|
|
3806
4684
|
return { branch, url };
|
|
3807
4685
|
}
|
|
3808
4686
|
catch (error) {
|
|
@@ -3810,6 +4688,11 @@ async function publishPatchBranch(repository, branch, body, stderr, dependencies
|
|
|
3810
4688
|
throw error;
|
|
3811
4689
|
}
|
|
3812
4690
|
}
|
|
4691
|
+
function patchRemoteHost(remote) {
|
|
4692
|
+
if (remote.includes("://"))
|
|
4693
|
+
return new URL(remote).hostname.toLowerCase();
|
|
4694
|
+
return /^(?:[^@/]+@)?([^:/]+):[^/]/u.exec(remote)?.[1]?.toLowerCase();
|
|
4695
|
+
}
|
|
3813
4696
|
async function resumePatchPullRequest(repository, branch, stderr, dependencies) {
|
|
3814
4697
|
const run = (args) => dependencies.runRepositoryCommand("git", args, repository);
|
|
3815
4698
|
const commit = await run([
|
|
@@ -3855,11 +4738,11 @@ async function createPatchPullRequest(repository, patchId, files, stderr, depend
|
|
|
3855
4738
|
}
|
|
3856
4739
|
const branch = `codex-security/patch-${patchId.replaceAll(/[^a-z\d._-]/giu, "-")}`;
|
|
3857
4740
|
const body = patchPullRequestBody(patchRiskSummary, introduction);
|
|
3858
|
-
const run = (
|
|
3859
|
-
stderr.write("Creating a draft
|
|
3860
|
-
await run(
|
|
3861
|
-
await run(
|
|
3862
|
-
await run(
|
|
4741
|
+
const run = (args) => dependencies.runRepositoryCommand("git", args, repository);
|
|
4742
|
+
stderr.write("Creating a draft pull request or merge request for verified patches...\n");
|
|
4743
|
+
await run(["switch", "-c", branch]);
|
|
4744
|
+
await run(["--literal-pathspecs", "add", "--", ...files]);
|
|
4745
|
+
await run([
|
|
3863
4746
|
"--literal-pathspecs",
|
|
3864
4747
|
"commit",
|
|
3865
4748
|
"--only",
|
|
@@ -3868,14 +4751,9 @@ async function createPatchPullRequest(repository, patchId, files, stderr, depend
|
|
|
3868
4751
|
"--",
|
|
3869
4752
|
...files,
|
|
3870
4753
|
]);
|
|
3871
|
-
const commit = await run(
|
|
3872
|
-
await run(
|
|
3873
|
-
await run("
|
|
3874
|
-
"config",
|
|
3875
|
-
"--local",
|
|
3876
|
-
patchPullRequestBodyKey(branch),
|
|
3877
|
-
body,
|
|
3878
|
-
]);
|
|
4754
|
+
const commit = await run(["rev-parse", "HEAD"]);
|
|
4755
|
+
await run(["config", "--local", patchCommitKey(branch), commit]);
|
|
4756
|
+
await run(["config", "--local", patchPullRequestBodyKey(branch), body]);
|
|
3879
4757
|
return publishPatchBranch(repository, branch, body, stderr, dependencies);
|
|
3880
4758
|
}
|
|
3881
4759
|
async function requireCleanPatchPullRequestBase(repository, base, dependencies) {
|
|
@@ -3974,6 +4852,8 @@ async function assessPatchRisk(request, stderr, dependencies) {
|
|
|
3974
4852
|
};
|
|
3975
4853
|
const status = await runSkill("assess-patch-risk", [], request.codexOverrides, request.effort, stdout, stderr, dependencies, {
|
|
3976
4854
|
directory: request.repository,
|
|
4855
|
+
auth: request.auth,
|
|
4856
|
+
environment: request.environment,
|
|
3977
4857
|
patchArtifact: {
|
|
3978
4858
|
path: patchPath,
|
|
3979
4859
|
repository: basename(resolve(request.repository)),
|
|
@@ -4080,8 +4960,12 @@ async function runFindingPatches(selected, codexOverrides, effort, stderr, depen
|
|
|
4080
4960
|
}
|
|
4081
4961
|
async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, dependencies, options = {}) {
|
|
4082
4962
|
const overrides = parseCodexOverrides(codexOverrides, undefined, effort);
|
|
4083
|
-
if (Object.
|
|
4084
|
-
|
|
4963
|
+
if (Object.entries(overrides).some(([key, value]) => key !== "model" &&
|
|
4964
|
+
key !== "model_reasoning_effort" &&
|
|
4965
|
+
!(key === "analytics" &&
|
|
4966
|
+
isJsonObject(value) &&
|
|
4967
|
+
Object.keys(value).every((key) => key === "enabled")))) {
|
|
4968
|
+
throw new CodexSecurityError("Skill commands only support model, model_reasoning_effort, and analytics.enabled overrides.");
|
|
4085
4969
|
}
|
|
4086
4970
|
const { model, reasoningEffort } = scanModelConfiguration(await mergedCodexConfig({ codexOverrides: overrides }));
|
|
4087
4971
|
const directory = options.directory ?? dependencies.currentDirectory();
|
|
@@ -4201,13 +5085,20 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
4201
5085
|
`model=${JSON.stringify(model)}`,
|
|
4202
5086
|
"--config",
|
|
4203
5087
|
`model_reasoning_effort=${JSON.stringify(reasoningEffort)}`,
|
|
5088
|
+
...codexOverrides
|
|
5089
|
+
.filter((value) => value.startsWith("analytics.") || value.startsWith("analytics="))
|
|
5090
|
+
.flatMap((value) => ["--config", value]),
|
|
4204
5091
|
...(options.provider === undefined
|
|
4205
5092
|
? []
|
|
4206
5093
|
: ["--config", `model_provider=${JSON.stringify(options.provider)}`]),
|
|
4207
|
-
...
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
5094
|
+
...(options.provider === undefined ||
|
|
5095
|
+
options.providerConfiguration === undefined
|
|
5096
|
+
? []
|
|
5097
|
+
: modelProviderConfigOverride(resolveCommandAuthConfig({
|
|
5098
|
+
model_providers: {
|
|
5099
|
+
[options.provider]: options.providerConfiguration,
|
|
5100
|
+
},
|
|
5101
|
+
}, configuredCodexHome(options.environment ?? dependencies.environment))).flatMap((value) => ["--config", value])),
|
|
4211
5102
|
"--config",
|
|
4212
5103
|
verify || assess
|
|
4213
5104
|
? 'approval_policy="on-request"'
|
|
@@ -4235,6 +5126,10 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
4235
5126
|
]),
|
|
4236
5127
|
], {
|
|
4237
5128
|
command: verify ? "verify-fix" : patch || assess ? "patch" : "validate",
|
|
5129
|
+
auth: options.auth ?? "auto",
|
|
5130
|
+
directory,
|
|
5131
|
+
modelProvider: options.provider,
|
|
5132
|
+
providerConfiguration: options.providerConfiguration,
|
|
4238
5133
|
stdout,
|
|
4239
5134
|
stderr,
|
|
4240
5135
|
...(appServer
|
|
@@ -4250,7 +5145,7 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
4250
5145
|
},
|
|
4251
5146
|
}
|
|
4252
5147
|
: {}),
|
|
4253
|
-
}, options.environment, appServer ? undefined : prompt);
|
|
5148
|
+
}, options.environment ?? dependencies.environment, appServer ? undefined : prompt);
|
|
4254
5149
|
}
|
|
4255
5150
|
export async function readSkillCommandOutput(stream, appServer) {
|
|
4256
5151
|
let message;
|
|
@@ -4272,6 +5167,9 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
4272
5167
|
// Inherit the child process cwd and preserve the user's decision.
|
|
4273
5168
|
params: {
|
|
4274
5169
|
threadSource: appServer.threadSource,
|
|
5170
|
+
...(appServer.modelProvider === undefined
|
|
5171
|
+
? {}
|
|
5172
|
+
: { modelProvider: appServer.modelProvider }),
|
|
4275
5173
|
approvalPolicy: appServer?.sandbox === "read-only" ? "on-request" : "never",
|
|
4276
5174
|
sandbox: appServer?.sandbox ?? "workspace-write",
|
|
4277
5175
|
...(config === undefined ? {} : { config }),
|
|
@@ -4325,8 +5223,18 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
4325
5223
|
error = value["error"].message;
|
|
4326
5224
|
appServer.input.end();
|
|
4327
5225
|
}
|
|
4328
|
-
else if (value["id"] === 1) {
|
|
4329
|
-
|
|
5226
|
+
else if (value["id"] === 1 || value["id"] === "login") {
|
|
5227
|
+
if (value["id"] === 1) {
|
|
5228
|
+
send({ method: "notifications/initialized" });
|
|
5229
|
+
if (appServer.apiKey !== undefined) {
|
|
5230
|
+
send({
|
|
5231
|
+
id: "login",
|
|
5232
|
+
method: "account/login/start",
|
|
5233
|
+
params: { type: "apiKey", apiKey: appServer.apiKey },
|
|
5234
|
+
});
|
|
5235
|
+
continue;
|
|
5236
|
+
}
|
|
5237
|
+
}
|
|
4330
5238
|
if (appServer.sandbox === "read-only") {
|
|
4331
5239
|
if (appServer.directory === undefined) {
|
|
4332
5240
|
error =
|
|
@@ -4403,6 +5311,7 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
4403
5311
|
});
|
|
4404
5312
|
}
|
|
4405
5313
|
else if (value["id"] === 2) {
|
|
5314
|
+
await appServer.onThreadStarted?.();
|
|
4406
5315
|
threadId = value["result"].thread.id;
|
|
4407
5316
|
send({
|
|
4408
5317
|
id: 3,
|
|
@@ -4479,9 +5388,9 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
4479
5388
|
...(appServer === undefined ? {} : { completed }),
|
|
4480
5389
|
};
|
|
4481
5390
|
}
|
|
4482
|
-
export function skillCommandFailure(command, status, detail) {
|
|
5391
|
+
export function skillCommandFailure(command, status, detail, authentication = null) {
|
|
4483
5392
|
if (/401|invalid.api.key|token.expired|unauthori[sz]ed|authorizationrequired/iu.test(detail)) {
|
|
4484
|
-
return
|
|
5393
|
+
return authenticationFailureMessage(authentication);
|
|
4485
5394
|
}
|
|
4486
5395
|
if (/403|model.not.found|model.*access|access.*model|permission/iu.test(detail)) {
|
|
4487
5396
|
return "The selected model is unavailable for the current credentials.";
|
|
@@ -4677,7 +5586,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4677
5586
|
// Launchers and terminals can deliver the same initial signal twice.
|
|
4678
5587
|
// A later repeated signal intentionally restores the conventional escape hatch.
|
|
4679
5588
|
if (signal === requestedSignal &&
|
|
4680
|
-
dependencies.now() - firstSignalAt <
|
|
5589
|
+
dependencies.now() - firstSignalAt < DUPLICATE_SIGNAL_WINDOW_MS) {
|
|
4681
5590
|
return;
|
|
4682
5591
|
}
|
|
4683
5592
|
requestedSignal = signal;
|
|
@@ -4711,7 +5620,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4711
5620
|
let preflight = null;
|
|
4712
5621
|
let effectiveModel = DEFAULT_SCAN_MODEL_CONFIGURATION.model;
|
|
4713
5622
|
let effectiveReasoningEffort = DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort;
|
|
4714
|
-
let providerOptions = {};
|
|
5623
|
+
let providerOptions = { provider: "openai" };
|
|
5624
|
+
let auth = arguments_.auth;
|
|
5625
|
+
let patchAnalyticsOverride;
|
|
4715
5626
|
let selectedAuthentication = null;
|
|
4716
5627
|
let repository = "";
|
|
4717
5628
|
let failed = false;
|
|
@@ -4735,23 +5646,33 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4735
5646
|
({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
|
|
4736
5647
|
scanModelConfiguration(effectiveConfiguration));
|
|
4737
5648
|
const provider = scanModelProvider(effectiveConfiguration);
|
|
4738
|
-
const
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
5649
|
+
const analytics = effectiveConfiguration["analytics"];
|
|
5650
|
+
if (analytics !== undefined &&
|
|
5651
|
+
isJsonObject(analytics) &&
|
|
5652
|
+
analytics["enabled"] !== undefined) {
|
|
5653
|
+
patchAnalyticsOverride = `analytics.enabled=${JSON.stringify(analytics["enabled"])}`;
|
|
5654
|
+
}
|
|
5655
|
+
auth =
|
|
5656
|
+
!arguments_.dryRun && !arguments_.mock && interactive
|
|
5657
|
+
? await chooseInteractiveAuthentication({
|
|
5658
|
+
auth: arguments_.auth,
|
|
5659
|
+
provider,
|
|
5660
|
+
command: "scan",
|
|
5661
|
+
signal: preparationAbortController.signal,
|
|
5662
|
+
}, errorOutput, dependencies)
|
|
5663
|
+
: arguments_.auth;
|
|
5664
|
+
if (typeof provider === "string") {
|
|
4747
5665
|
providerOptions = {
|
|
4748
5666
|
provider,
|
|
4749
|
-
providerConfiguration: effectiveConfiguration["model_providers"]?.[provider]
|
|
5667
|
+
providerConfiguration: effectiveConfiguration["model_providers"]?.[provider] ??
|
|
5668
|
+
(isExternalModelProvider(provider)
|
|
5669
|
+
? EXTERNAL_CODEX_PROVIDERS[provider]
|
|
5670
|
+
: undefined),
|
|
4750
5671
|
};
|
|
4751
5672
|
}
|
|
4752
5673
|
selectedAuthentication = arguments_.mock
|
|
4753
5674
|
? null
|
|
4754
|
-
: scanAuthentication(dependencies.environment, auth, provider);
|
|
5675
|
+
: scanAuthentication(dependencies.environment, auth, provider, hasCommandAuth(effectiveConfiguration));
|
|
4755
5676
|
diagnostic("scan.configuration", {
|
|
4756
5677
|
cli_version: VERSION,
|
|
4757
5678
|
bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
|
|
@@ -4809,13 +5730,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4809
5730
|
details.push(`Files: ${fileProgress.filesCompleted.toLocaleString("en-US")}/${fileProgress.filesTotal.toLocaleString("en-US")}`);
|
|
4810
5731
|
}
|
|
4811
5732
|
if (runningCost !== null) {
|
|
4812
|
-
|
|
4813
|
-
input_tokens: runningCost.inputTokens,
|
|
4814
|
-
cached_input_tokens: runningCost.cachedInputTokens,
|
|
4815
|
-
output_tokens: runningCost.outputTokens,
|
|
4816
|
-
});
|
|
4817
|
-
if (tokens !== null)
|
|
4818
|
-
details.push(`Tokens: ${tokens}`);
|
|
5733
|
+
details.push(`Tokens: ${formatScanCostTokens(runningCost)}`);
|
|
4819
5734
|
details.push(`Cost: ${formatUsd(runningCost.estimatedUsd)}`);
|
|
4820
5735
|
}
|
|
4821
5736
|
return details.length === 0 ? stage : `${stage} | ${details.join(" | ")}`;
|
|
@@ -4838,6 +5753,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4838
5753
|
errorOutput.write("codex-security: Mock scan: generating synthetic findings; no security analysis or LLM calls.\n");
|
|
4839
5754
|
}
|
|
4840
5755
|
const options = {
|
|
5756
|
+
...(arguments_.resumeScanId === undefined
|
|
5757
|
+
? {}
|
|
5758
|
+
: { resumeScanId: arguments_.resumeScanId }),
|
|
4841
5759
|
...(arguments_.mock ? { mock: true } : {}),
|
|
4842
5760
|
...(arguments_.workflowId === undefined
|
|
4843
5761
|
? {}
|
|
@@ -4847,6 +5765,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4847
5765
|
target,
|
|
4848
5766
|
knowledgeBasePaths: arguments_.knowledgeBasePaths,
|
|
4849
5767
|
...prompts,
|
|
5768
|
+
postScanPrompt: arguments_.postScanPrompt ?? prompts.postScanPrompt,
|
|
4850
5769
|
mode: arguments_.mode,
|
|
4851
5770
|
workers: arguments_.workers,
|
|
4852
5771
|
subagents: arguments_.subagents,
|
|
@@ -4880,12 +5799,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
4880
5799
|
}
|
|
4881
5800
|
progress?.stopTimer();
|
|
4882
5801
|
if (maxCostUsd === undefined) {
|
|
4883
|
-
|
|
4884
|
-
input_tokens: cost.inputTokens,
|
|
4885
|
-
cached_input_tokens: cost.cachedInputTokens,
|
|
4886
|
-
output_tokens: cost.outputTokens,
|
|
4887
|
-
});
|
|
4888
|
-
progress?.stage(`${tokens === null ? "" : `Tokens: ${tokens}. `}Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
|
|
5802
|
+
progress?.stage(`Tokens: ${formatScanCostTokens(cost)}. Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
|
|
4889
5803
|
}
|
|
4890
5804
|
else {
|
|
4891
5805
|
progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(maxCostUsd)} limit`);
|
|
@@ -5249,20 +6163,16 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
|
|
|
5249
6163
|
(patchSelection === null ||
|
|
5250
6164
|
patchSelection.occurrenceIds.includes(finding.occurrenceId))),
|
|
5251
6165
|
};
|
|
5252
|
-
const environment = { ...dependencies.environment };
|
|
5253
|
-
if (selectedAuthentication?.method === "stored_credentials") {
|
|
5254
|
-
for (const name of Object.keys(environment)) {
|
|
5255
|
-
if (["OPENAI_API_KEY", "CODEX_API_KEY"].includes(name.toUpperCase())) {
|
|
5256
|
-
delete environment[name];
|
|
5257
|
-
}
|
|
5258
|
-
}
|
|
5259
|
-
environment["CODEX_HOME"] = codexSecurityCredentialHome(dependencies.environment);
|
|
5260
|
-
}
|
|
5261
6166
|
try {
|
|
5262
|
-
patches = await runFindingPatches(selected, [
|
|
6167
|
+
patches = await runFindingPatches(selected, [
|
|
6168
|
+
`model=${JSON.stringify(effectiveModel)}`,
|
|
6169
|
+
...(patchAnalyticsOverride === undefined
|
|
6170
|
+
? []
|
|
6171
|
+
: [patchAnalyticsOverride]),
|
|
6172
|
+
], effectiveReasoningEffort, errorOutput, dependencies, {
|
|
5263
6173
|
...providerOptions,
|
|
5264
6174
|
safetyIdentifier: arguments_.safetyIdentifier,
|
|
5265
|
-
|
|
6175
|
+
auth,
|
|
5266
6176
|
findingInstructions: patchSelection?.instructions,
|
|
5267
6177
|
});
|
|
5268
6178
|
scanData = { ...scanData, patchSeverity: patchThreshold, patches };
|
|
@@ -5326,6 +6236,36 @@ function isLocalScanFailure(error) {
|
|
|
5326
6236
|
typeof error.code === "string" &&
|
|
5327
6237
|
LOCAL_SYSCALL_CODES.has(error.code));
|
|
5328
6238
|
}
|
|
6239
|
+
function authenticationFailureMessage(authentication) {
|
|
6240
|
+
if (authentication?.method === "command") {
|
|
6241
|
+
return "Native Codex command authentication failed. Check the configured provider auth command.";
|
|
6242
|
+
}
|
|
6243
|
+
if (authentication?.method === "aws_credentials") {
|
|
6244
|
+
return (`Authentication failed using AWS credentials from ${authentication.source}. ` +
|
|
6245
|
+
"Check your Amazon Bedrock bearer token or AWS credential chain.");
|
|
6246
|
+
}
|
|
6247
|
+
if (authentication?.method === "stored_credentials" &&
|
|
6248
|
+
authentication.credentialType === "api_key") {
|
|
6249
|
+
return ("Authentication failed using a stored API key. " +
|
|
6250
|
+
"Sign in again with 'codex-security login --with-api-key' or provide a valid API key.");
|
|
6251
|
+
}
|
|
6252
|
+
if (authentication?.method === "api_key") {
|
|
6253
|
+
const openAiKey = authentication.source === "OPENAI_API_KEY" ||
|
|
6254
|
+
authentication.source === "CODEX_API_KEY";
|
|
6255
|
+
return (`Authentication failed using ${authentication.source}. ` +
|
|
6256
|
+
(openAiKey
|
|
6257
|
+
? "Retry with '--auth chatgpt' or provide a valid API key."
|
|
6258
|
+
: `Provide a valid ${authentication.source} for the selected provider.`));
|
|
6259
|
+
}
|
|
6260
|
+
if (authentication?.method === "stored_credentials") {
|
|
6261
|
+
return authentication.credentialType === "chatgpt"
|
|
6262
|
+
? "Authentication failed using stored ChatGPT credentials. " +
|
|
6263
|
+
"Sign in again with 'codex-security login' or provide a valid API key."
|
|
6264
|
+
: "Authentication failed using stored credentials. " +
|
|
6265
|
+
"Check 'codex-security login status' and refresh the stored login or provide a valid API key.";
|
|
6266
|
+
}
|
|
6267
|
+
return "Authentication failed. Check the selected provider's credentials and retry.";
|
|
6268
|
+
}
|
|
5329
6269
|
function scanFailureMessage(error, authentication) {
|
|
5330
6270
|
// A local failure keeps its own message. Classification matches bare words
|
|
5331
6271
|
// such as "permission denied" anywhere in the text, so an EACCES from a
|
|
@@ -5349,18 +6289,7 @@ function scanFailureMessage(error, authentication) {
|
|
|
5349
6289
|
}
|
|
5350
6290
|
switch (classifyConnectionFailure(error)) {
|
|
5351
6291
|
case "unauthorized":
|
|
5352
|
-
|
|
5353
|
-
return "Native Codex command authentication failed. Check the configured provider auth command.";
|
|
5354
|
-
}
|
|
5355
|
-
if (authentication?.method === "aws_credentials") {
|
|
5356
|
-
return (`Authentication failed using AWS credentials from ${authentication.source}. ` +
|
|
5357
|
-
"Check your Amazon Bedrock bearer token or AWS credential chain.");
|
|
5358
|
-
}
|
|
5359
|
-
return authentication?.method === "api_key"
|
|
5360
|
-
? `Authentication failed using ${authentication.source}. ` +
|
|
5361
|
-
"Retry with '--auth chatgpt' or provide a valid API key."
|
|
5362
|
-
: "Authentication failed using stored ChatGPT credentials. " +
|
|
5363
|
-
"Sign in again with 'codex-security login' or provide a valid API key.";
|
|
6292
|
+
return authenticationFailureMessage(authentication);
|
|
5364
6293
|
case "forbidden":
|
|
5365
6294
|
if (authentication?.method === "command") {
|
|
5366
6295
|
return "The configured Codex provider denied access. Check the command credentials and provider permissions.";
|
|
@@ -5494,33 +6423,24 @@ function printScanSummary(result, progress, errorOutput, color, deepScanStop) {
|
|
|
5494
6423
|
if (tokenSummary !== null) {
|
|
5495
6424
|
errorOutput.write(` ${paint("TOKENS", 1)} ${tokenSummary}\n`);
|
|
5496
6425
|
}
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
6426
|
+
const costSummary = result.cost === null
|
|
6427
|
+
? "unavailable (model pricing or usage missing)"
|
|
6428
|
+
: `${formatUsd(result.cost.estimatedUsd)} (standard, short context)`;
|
|
6429
|
+
errorOutput.write(` ${paint("COST", 1)} ${costSummary}\n`);
|
|
5500
6430
|
errorOutput.write(` ${paint("RESULTS", 1)} ${errorMessage(result.scanDir)}\n`);
|
|
5501
6431
|
if (deepScanStop?.nextStep !== undefined) {
|
|
5502
6432
|
errorOutput.write(`\n ${deepScanStop.nextStep}\n`);
|
|
5503
6433
|
}
|
|
5504
6434
|
}
|
|
5505
|
-
function
|
|
5506
|
-
if (
|
|
6435
|
+
function componentScanEventLine(componentName, event) {
|
|
6436
|
+
if (event.type === "progress") {
|
|
6437
|
+
const progress = event.value;
|
|
6438
|
+
return `codex-security: ${componentName} ${scanPhase(progress.phase)} | Files: ${progress.filesCompleted.toLocaleString("en-US")}/${progress.filesTotal.toLocaleString("en-US")}\n`;
|
|
6439
|
+
}
|
|
6440
|
+
if (event.type !== "cost")
|
|
5507
6441
|
return null;
|
|
5508
|
-
const
|
|
5509
|
-
return (
|
|
5510
|
-
["input_tokens", "input"],
|
|
5511
|
-
["cached_input_tokens", "cached"],
|
|
5512
|
-
["output_tokens", "output"],
|
|
5513
|
-
]
|
|
5514
|
-
.map(([key, label]) => {
|
|
5515
|
-
const value = values[key];
|
|
5516
|
-
return typeof value === "number" &&
|
|
5517
|
-
Number.isSafeInteger(value) &&
|
|
5518
|
-
value >= 0
|
|
5519
|
-
? `${value.toLocaleString("en-US")} ${label}`
|
|
5520
|
-
: null;
|
|
5521
|
-
})
|
|
5522
|
-
.filter((value) => value !== null)
|
|
5523
|
-
.join(", ") || null);
|
|
6442
|
+
const cost = event.value;
|
|
6443
|
+
return `codex-security: ${componentName} | Tokens: ${formatScanCostTokens(cost)} | Cost: ${formatUsd(cost.estimatedUsd)}\n`;
|
|
5524
6444
|
}
|
|
5525
6445
|
function protectedRootErrorMessage(error) {
|
|
5526
6446
|
const description = error.pathKind === "output"
|