@openai/codex-security 0.3.0 → 0.5.0
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 +45 -9
- package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +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/permission-profile-preflight.mjs +13 -20
- 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/core-scan.md +2 -0
- package/_bundled_plugin/references/final-report.md +5 -1
- package/_bundled_plugin/references/investigation-time-budget.md +11 -0
- package/_bundled_plugin/references/sarif-adapter.md +1 -0
- package/_bundled_plugin/references/scan-prologue.md +2 -6
- package/_bundled_plugin/references/scan-runtime.md +15 -0
- package/_bundled_plugin/references/threat-model.md +2 -0
- package/_bundled_plugin/schemas/coverage.schema.json +45 -126
- package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
- package/_bundled_plugin/schemas/findings.schema.json +140 -427
- package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
- package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
- package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
- package/_bundled_plugin/scripts/finding_preview.py +5 -3
- package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
- package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
- package/_bundled_plugin/scripts/report_projection.py +35 -13
- package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
- package/_bundled_plugin/scripts/workbench_cli.py +9 -9
- package/_bundled_plugin/scripts/workbench_constants.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +103 -45
- package/_bundled_plugin/scripts/workbench_progress.py +0 -50
- package/_bundled_plugin/scripts/workbench_publication.py +216 -247
- package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
- package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
- package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
- package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
- package/_bundled_plugin/scripts/workbench_target.py +7 -5
- package/_bundled_plugin/scripts/workbench_validation.py +52 -2
- package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
- package/_bundled_plugin/shared/workbench-migrations.json +22 -0
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
- package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
- package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
- package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
- package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
- package/dist/api.d.ts +6 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +266 -39
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +2 -1
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +38 -23
- package/dist/artifact-export.js.map +1 -1
- package/dist/classify-severity-records.d.ts +76 -0
- package/dist/classify-severity-records.d.ts.map +1 -0
- package/dist/classify-severity-records.js +141 -0
- package/dist/classify-severity-records.js.map +1 -0
- package/dist/classify-severity.d.ts +1 -23
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +3 -24
- package/dist/classify-severity.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +2 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +4 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +148 -149
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +1 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/codex-sdk-environment.js +1 -1
- package/dist/codex-sdk-environment.js.map +1 -1
- package/dist/component-plan.js +1 -1
- package/dist/component-plan.js.map +1 -1
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +5 -4
- package/dist/component-scan.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -4
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +6 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +69 -20
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +7 -2
- package/dist/cost-model.js.map +1 -1
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +1 -5
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +2 -2
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +2 -2
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts +3 -8
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +11 -171
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.js +1 -1
- package/dist/deduplication/records.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +10 -9
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/deep-config.d.ts +4 -1
- package/dist/deep-config.d.ts.map +1 -1
- package/dist/deep-config.js +21 -1
- package/dist/deep-config.js.map +1 -1
- package/dist/deep-progress.d.ts +15 -1
- package/dist/deep-progress.d.ts.map +1 -1
- package/dist/deep-progress.js +15 -16
- package/dist/deep-progress.js.map +1 -1
- package/dist/executable-path.d.ts +2 -0
- package/dist/executable-path.d.ts.map +1 -0
- package/dist/executable-path.js +12 -0
- package/dist/executable-path.js.map +1 -0
- package/dist/feedback.d.ts +1 -4
- package/dist/feedback.d.ts.map +1 -1
- package/dist/feedback.js +1 -1
- package/dist/feedback.js.map +1 -1
- package/dist/findings-import.d.ts +1 -1
- package/dist/findings-import.d.ts.map +1 -1
- package/dist/findings-import.js +3 -3
- package/dist/findings-import.js.map +1 -1
- package/dist/git-remote.d.ts +10 -0
- package/dist/git-remote.d.ts.map +1 -0
- package/dist/git-remote.js +24 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +5 -7
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +19 -0
- package/dist/host-protocol.d.ts.map +1 -0
- package/dist/host-protocol.js +270 -0
- package/dist/host-protocol.js.map +1 -0
- package/dist/host-records-protocol.d.ts +15 -0
- package/dist/host-records-protocol.d.ts.map +1 -0
- package/dist/host-records-protocol.js +15 -0
- package/dist/host-records-protocol.js.map +1 -0
- package/dist/hosted-scan-protocol.d.ts +4 -0
- package/dist/hosted-scan-protocol.d.ts.map +1 -0
- package/dist/hosted-scan-protocol.js +25 -0
- package/dist/hosted-scan-protocol.js.map +1 -0
- package/dist/hosted-scan.d.ts +112 -0
- package/dist/hosted-scan.d.ts.map +1 -0
- package/dist/hosted-scan.js +260 -0
- package/dist/hosted-scan.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +87 -7
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +108 -36
- package/dist/multiscan.js.map +1 -1
- package/dist/patch-publication.d.ts +26 -0
- package/dist/patch-publication.d.ts.map +1 -0
- package/dist/patch-publication.js +105 -0
- package/dist/patch-publication.js.map +1 -0
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +16 -6
- package/dist/project-config.js.map +1 -1
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +73 -63
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +0 -2
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +135 -24
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +39 -25
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +5 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +86 -58
- package/dist/runtime.js.map +1 -1
- package/dist/scan-executor.d.ts +104 -0
- package/dist/scan-executor.d.ts.map +1 -0
- package/dist/scan-executor.js +62 -0
- package/dist/scan-executor.js.map +1 -0
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +7 -1
- package/dist/scan-settings.js.map +1 -1
- package/dist/scan-time-budget.d.ts +9 -0
- package/dist/scan-time-budget.d.ts.map +1 -0
- package/dist/scan-time-budget.js +16 -0
- package/dist/scan-time-budget.js.map +1 -0
- package/dist/severity-review.d.ts +29 -0
- package/dist/severity-review.d.ts.map +1 -0
- package/dist/severity-review.js +47 -0
- package/dist/severity-review.js.map +1 -0
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +17 -25
- package/dist/targets.js.map +1 -1
- package/dist/validation-records.d.ts +38 -0
- package/dist/validation-records.d.ts.map +1 -0
- package/dist/validation-records.js +76 -0
- package/dist/validation-records.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +4 -2
- package/dist/version.js.map +1 -1
- package/dist/worker-progress.d.ts +43 -15
- package/dist/worker-progress.d.ts.map +1 -1
- package/dist/worker-progress.js +22 -80
- package/dist/worker-progress.js.map +1 -1
- package/docs/classify-severity-records.md +89 -0
- package/docs/cli.md +281 -35
- package/docs/hosted-scans.md +242 -0
- package/docs/validate-records.md +69 -0
- package/package.json +18 -14
- package/schemas/hosted-scan-v2.fixture.json +145 -0
- package/schemas/project-config.schema.json +7 -1
- package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
- package/_bundled_plugin/references/config-preflight.md +0 -93
- package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
- package/_bundled_plugin/scripts/config_preflight.py +0 -911
package/dist/runtime.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { executablePathForSpawn } from "./executable-path.js";
|
|
2
|
+
export { executablePathForSpawn } from "./executable-path.js";
|
|
1
3
|
import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
|
|
2
4
|
import { gitProtectionRoots } from "./targets.js";
|
|
3
5
|
import { isNonEmptyString, notify } from "./value.js";
|
|
4
|
-
import { execFile as execFileCallback, spawn } from "node:child_process";
|
|
6
|
+
import { execFile as execFileCallback, spawn, } from "node:child_process";
|
|
5
7
|
import { randomUUID } from "node:crypto";
|
|
6
8
|
import { chmodSync, constants, createWriteStream, } from "node:fs";
|
|
7
9
|
import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
|
|
@@ -53,6 +55,7 @@ const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
|
|
|
53
55
|
"CODEX_API_KEY",
|
|
54
56
|
"OPENROUTER_API_KEY",
|
|
55
57
|
"FIREWORKS_API_KEY",
|
|
58
|
+
"CHEAPER_INFERENCE_API_KEY",
|
|
56
59
|
]);
|
|
57
60
|
const PREPARE_SCAN_ARTIFACT_RESTORER_PROGRAM = `
|
|
58
61
|
from pathlib import Path
|
|
@@ -215,10 +218,7 @@ function windowsCredentialAclFailure(error) {
|
|
|
215
218
|
const detail = typeof stderr === "string" && stderr.trim() !== ""
|
|
216
219
|
? stderr
|
|
217
220
|
: errorMessage(error);
|
|
218
|
-
const normalized = errorMessage(detail)
|
|
219
|
-
.replace(/\s+/gu, " ")
|
|
220
|
-
.trim()
|
|
221
|
-
.slice(0, 512);
|
|
221
|
+
const normalized = errorMessage(detail).replace(/\s+/gu, " ").trim();
|
|
222
222
|
return normalized === "" ? "" : `. ${normalized}`;
|
|
223
223
|
}
|
|
224
224
|
const WINDOWS_SYSTEM_SID = "S-1-5-18";
|
|
@@ -523,9 +523,9 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
|
|
526
|
-
|
|
526
|
+
const ancestors = [];
|
|
527
527
|
for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
|
|
528
|
-
ancestors
|
|
528
|
+
ancestors.push(ancestor);
|
|
529
529
|
if (ancestor === dirname(ancestor))
|
|
530
530
|
break;
|
|
531
531
|
}
|
|
@@ -550,17 +550,26 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
550
550
|
const index = inspected;
|
|
551
551
|
inspected += 1;
|
|
552
552
|
await options.resolveDescriptorAliases?.(descriptor);
|
|
553
|
-
if (index < ancestors) {
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
553
|
+
if (index < ancestors.length) {
|
|
554
|
+
const ancestorPath = ancestors[index];
|
|
555
|
+
try {
|
|
556
|
+
const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
557
|
+
resolvedAliases: options.resolvedAliases,
|
|
558
|
+
scope: "ancestor",
|
|
559
|
+
});
|
|
560
|
+
if (ancestor.untrustedPrincipals.length !== 0) {
|
|
561
|
+
throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
const guidance = ancestorPath === dirname(ancestorPath)
|
|
566
|
+
? "This volume root is unsupported. Choose a location on a volume with trusted ancestry; another directory on the same volume will not resolve this."
|
|
567
|
+
: "Choose a location outside this ancestor with trusted ownership and permissions.";
|
|
568
|
+
throw new Error(`Windows private-directory ancestor could not be trusted: ${ancestorPath}. ${errorMessage(error)}. ${guidance}`, { cause: error });
|
|
560
569
|
}
|
|
561
570
|
return;
|
|
562
571
|
}
|
|
563
|
-
if (index === ancestors) {
|
|
572
|
+
if (index === ancestors.length) {
|
|
564
573
|
try {
|
|
565
574
|
home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
|
|
566
575
|
resolvedAliases: options.resolvedAliases,
|
|
@@ -589,7 +598,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
|
|
|
589
598
|
continue;
|
|
590
599
|
throw error;
|
|
591
600
|
}
|
|
592
|
-
if (inspected <= ancestors) {
|
|
601
|
+
if (inspected <= ancestors.length) {
|
|
593
602
|
throw new Error("Windows credential-home ancestry could not be verified");
|
|
594
603
|
}
|
|
595
604
|
if (!completed) {
|
|
@@ -1145,21 +1154,6 @@ def before_archive():
|
|
|
1145
1154
|
raise SystemExit("Scan registration canceled before archival.")
|
|
1146
1155
|
workbench["main"](before_archive=before_archive)
|
|
1147
1156
|
`;
|
|
1148
|
-
// Internal publication callers use only the SDK's bundled workbench.
|
|
1149
|
-
const PUBLICATION_PROGRAM = String.raw `
|
|
1150
|
-
import json, runpy, sys
|
|
1151
|
-
from contextlib import closing
|
|
1152
|
-
workbench = runpy.run_path(sys.argv[1])
|
|
1153
|
-
context = workbench["_WORKBENCH_PUBLICATION_CONTEXT"]
|
|
1154
|
-
payload = json.load(sys.stdin, parse_constant=workbench["reject_non_finite_json"])
|
|
1155
|
-
handler = getattr(workbench["publication"], sys.argv[2].replace("-", "_"))
|
|
1156
|
-
if sys.argv[2] == "inspect-linear-publication":
|
|
1157
|
-
result = handler(context, payload)
|
|
1158
|
-
else:
|
|
1159
|
-
with closing(workbench["connect"]()) as connection:
|
|
1160
|
-
result = handler(context, connection, payload)
|
|
1161
|
-
print(json.dumps(result, allow_nan=False, sort_keys=True))
|
|
1162
|
-
`;
|
|
1163
1157
|
export async function runWorkbench(options, args, input) {
|
|
1164
1158
|
const script = join(options.pluginRoot, "scripts", "workbench_db.py");
|
|
1165
1159
|
const signal = options.signal;
|
|
@@ -1199,20 +1193,9 @@ export async function runWorkbench(options, args, input) {
|
|
|
1199
1193
|
? (options.stateDirectory ??
|
|
1200
1194
|
codexSecurityStateDirectory(options.environment))
|
|
1201
1195
|
: undefined;
|
|
1202
|
-
const publicationInput = input !== undefined &&
|
|
1203
|
-
arguments_.length === 1 &&
|
|
1204
|
-
[
|
|
1205
|
-
"inspect-linear-publication",
|
|
1206
|
-
"prepare-linear-publication",
|
|
1207
|
-
"record-linear-publications",
|
|
1208
|
-
].includes(arguments_[0]);
|
|
1209
1196
|
// OS argv cannot carry NUL, but workbench text fields can.
|
|
1210
1197
|
const framedArguments = !native && arguments_.some((argument) => argument.includes("\0"));
|
|
1211
|
-
let program = archiveHandshake
|
|
1212
|
-
? ARCHIVE_REGISTRATION_PROGRAM
|
|
1213
|
-
: publicationInput
|
|
1214
|
-
? PUBLICATION_PROGRAM
|
|
1215
|
-
: undefined;
|
|
1198
|
+
let program = archiveHandshake ? ARCHIVE_REGISTRATION_PROGRAM : undefined;
|
|
1216
1199
|
if (framedArguments)
|
|
1217
1200
|
program =
|
|
1218
1201
|
WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
|
|
@@ -1413,7 +1396,10 @@ export async function planOutputArchive(outputDirectory) {
|
|
|
1413
1396
|
const entries = await readdir(outputDirectory).catch(nullIfMissingFileError);
|
|
1414
1397
|
if (entries === null || entries.length === 0)
|
|
1415
1398
|
return null;
|
|
1416
|
-
return `${outputDirectory}
|
|
1399
|
+
return `${outputDirectory}${outputArchiveSuffix()}`;
|
|
1400
|
+
}
|
|
1401
|
+
function outputArchiveSuffix() {
|
|
1402
|
+
return `.previous-${new Date()
|
|
1417
1403
|
.toISOString()
|
|
1418
1404
|
.replaceAll(/[-:]/g, "")
|
|
1419
1405
|
.replace(/\.\d{3}Z$/, "")}-${randomUUID().slice(0, 8)}`;
|
|
@@ -1466,10 +1452,22 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1466
1452
|
const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
|
|
1467
1453
|
validateLocation?.(path ?? (await realpath(temporaryRoot)));
|
|
1468
1454
|
if (path === null) {
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1471
|
-
|
|
1455
|
+
const prefix = `codex-security-${safePrefix(repositoryName)}`;
|
|
1456
|
+
let created;
|
|
1457
|
+
if (process.platform === "win32") {
|
|
1458
|
+
const suffix = `-${randomUUID()}`;
|
|
1459
|
+
// Reserve room within NTFS's 255-unit component limit for later archival.
|
|
1460
|
+
// The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
|
|
1461
|
+
const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
|
|
1462
|
+
created = join(temporaryRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
|
|
1463
|
+
await createWindowsOutputDirectory(created, false);
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
created = await mkdtemp(join(temporaryRoot, `${prefix}-`));
|
|
1467
|
+
}
|
|
1472
1468
|
try {
|
|
1469
|
+
if ((process.umask() & 0o700) !== 0)
|
|
1470
|
+
await chmod(created, 0o700);
|
|
1473
1471
|
return await validatePreparedOutputDir(created, validateLocation);
|
|
1474
1472
|
}
|
|
1475
1473
|
catch (error) {
|
|
@@ -1489,7 +1487,10 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1489
1487
|
}
|
|
1490
1488
|
}
|
|
1491
1489
|
if (existing === null) {
|
|
1492
|
-
createdRoot =
|
|
1490
|
+
createdRoot =
|
|
1491
|
+
process.platform === "win32"
|
|
1492
|
+
? await createWindowsOutputDirectory(path, true)
|
|
1493
|
+
: await mkdir(path, { recursive: true, mode: 0o700 });
|
|
1493
1494
|
if ((process.umask() & 0o700) !== 0)
|
|
1494
1495
|
await chmod(path, 0o700);
|
|
1495
1496
|
}
|
|
@@ -1506,6 +1507,26 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
|
|
|
1506
1507
|
});
|
|
1507
1508
|
}
|
|
1508
1509
|
}
|
|
1510
|
+
async function createWindowsOutputDirectory(path, recursive) {
|
|
1511
|
+
const native = createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
|
|
1512
|
+
const create = async (target) => {
|
|
1513
|
+
const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
|
|
1514
|
+
let error = createOne();
|
|
1515
|
+
let firstCreated;
|
|
1516
|
+
if (recursive &&
|
|
1517
|
+
(error === 2 || error === 3) &&
|
|
1518
|
+
dirname(target) !== target) {
|
|
1519
|
+
firstCreated = await create(dirname(target));
|
|
1520
|
+
error = createOne();
|
|
1521
|
+
}
|
|
1522
|
+
if (error === 0)
|
|
1523
|
+
return firstCreated ?? target;
|
|
1524
|
+
if (recursive && error === 183 && (await stat(target)).isDirectory())
|
|
1525
|
+
return firstCreated;
|
|
1526
|
+
throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
|
|
1527
|
+
};
|
|
1528
|
+
return create(path);
|
|
1529
|
+
}
|
|
1509
1530
|
export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
|
|
1510
1531
|
const metadata = await lstat(path);
|
|
1511
1532
|
if (!metadata.isDirectory()) {
|
|
@@ -1973,15 +1994,6 @@ export async function codexExecutableReadPaths(command) {
|
|
|
1973
1994
|
await realpath(resolveBundledCodexExecutable(packageJson)),
|
|
1974
1995
|
];
|
|
1975
1996
|
}
|
|
1976
|
-
export function executablePathForSpawn(command) {
|
|
1977
|
-
if (process.platform !== "win32" || !win32.isAbsolute(command))
|
|
1978
|
-
return command;
|
|
1979
|
-
// Root-relative paths still depend on the child's drive and working directory.
|
|
1980
|
-
const root = win32.parse(command).root;
|
|
1981
|
-
return root === "\\" || root === "/"
|
|
1982
|
-
? command
|
|
1983
|
-
: win32.toNamespacedPath(command);
|
|
1984
|
-
}
|
|
1985
1997
|
export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
|
|
1986
1998
|
const root = await realpath(pluginRoot);
|
|
1987
1999
|
const { name, version } = await pluginMetadata(root);
|
|
@@ -2272,12 +2284,13 @@ export async function cleanupSdkDirectory(path) {
|
|
|
2272
2284
|
export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
|
|
2273
2285
|
const cancellation = archiveHandshake ? new AbortController() : undefined;
|
|
2274
2286
|
const abort = () => cancellation?.abort(signal?.reason);
|
|
2287
|
+
const commandSignal = cancellation?.signal ?? signal;
|
|
2275
2288
|
let awaitingArchive = archiveHandshake;
|
|
2276
2289
|
const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
|
|
2277
2290
|
env: environment,
|
|
2278
2291
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2279
2292
|
windowsHide: true,
|
|
2280
|
-
signal:
|
|
2293
|
+
signal: commandSignal,
|
|
2281
2294
|
});
|
|
2282
2295
|
let stdout = "";
|
|
2283
2296
|
let stderr = "";
|
|
@@ -2313,6 +2326,19 @@ export async function runCodexCommand(command, args, environment, input, signal,
|
|
|
2313
2326
|
? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
|
|
2314
2327
|
: reject(processError));
|
|
2315
2328
|
});
|
|
2329
|
+
const releaseCanceledPipes = () => {
|
|
2330
|
+
if (!commandSignal?.aborted)
|
|
2331
|
+
return;
|
|
2332
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
2333
|
+
return;
|
|
2334
|
+
child.stdin.destroy();
|
|
2335
|
+
child.stdout.destroy();
|
|
2336
|
+
child.stderr.destroy();
|
|
2337
|
+
};
|
|
2338
|
+
commandSignal?.addEventListener("abort", releaseCanceledPipes, {
|
|
2339
|
+
once: true,
|
|
2340
|
+
});
|
|
2341
|
+
child.once("exit", releaseCanceledPipes);
|
|
2316
2342
|
if (archiveHandshake) {
|
|
2317
2343
|
signal?.addEventListener("abort", abort, { once: true });
|
|
2318
2344
|
if (signal?.aborted)
|
|
@@ -2330,6 +2356,8 @@ export async function runCodexCommand(command, args, environment, input, signal,
|
|
|
2330
2356
|
finally {
|
|
2331
2357
|
if (archiveHandshake)
|
|
2332
2358
|
signal?.removeEventListener("abort", abort);
|
|
2359
|
+
commandSignal?.removeEventListener("abort", releaseCanceledPipes);
|
|
2360
|
+
child.removeListener("exit", releaseCanceledPipes);
|
|
2333
2361
|
}
|
|
2334
2362
|
}
|
|
2335
2363
|
export async function probeCodexSandbox(command, environment, signal) {
|