@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.
Files changed (244) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  7. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
  8. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  9. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  10. package/_bundled_plugin/references/core-scan.md +2 -0
  11. package/_bundled_plugin/references/final-report.md +5 -1
  12. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  13. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  14. package/_bundled_plugin/references/scan-prologue.md +2 -6
  15. package/_bundled_plugin/references/scan-runtime.md +15 -0
  16. package/_bundled_plugin/references/threat-model.md +2 -0
  17. package/_bundled_plugin/schemas/coverage.schema.json +45 -126
  18. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  19. package/_bundled_plugin/schemas/findings.schema.json +140 -427
  20. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  21. package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
  22. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  23. package/_bundled_plugin/scripts/finalize_scan_contract.py +87 -49
  24. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  25. package/_bundled_plugin/scripts/generate_rank_input.py +26 -106
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  27. package/_bundled_plugin/scripts/report_projection.py +35 -13
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  30. package/_bundled_plugin/scripts/workbench_cli.py +9 -9
  31. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  32. package/_bundled_plugin/scripts/workbench_db.py +103 -45
  33. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  34. package/_bundled_plugin/scripts/workbench_publication.py +216 -247
  35. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  36. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  37. package/_bundled_plugin/scripts/workbench_scan_usage.py +360 -37
  38. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  39. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  40. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  41. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  42. package/_bundled_plugin/scripts/workbench_validation.py +52 -2
  43. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  44. package/_bundled_plugin/shared/workbench-migrations.json +22 -0
  45. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  46. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  47. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  48. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  49. package/_bundled_plugin/skills/security-scan/SKILL.md +4 -2
  50. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  51. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -3
  52. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
  53. package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
  54. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  55. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
  56. package/dist/api.d.ts +6 -2
  57. package/dist/api.d.ts.map +1 -1
  58. package/dist/api.js +266 -39
  59. package/dist/api.js.map +1 -1
  60. package/dist/artifact-export.d.ts +2 -1
  61. package/dist/artifact-export.d.ts.map +1 -1
  62. package/dist/artifact-export.js +38 -23
  63. package/dist/artifact-export.js.map +1 -1
  64. package/dist/classify-severity-records.d.ts +76 -0
  65. package/dist/classify-severity-records.d.ts.map +1 -0
  66. package/dist/classify-severity-records.js +141 -0
  67. package/dist/classify-severity-records.js.map +1 -0
  68. package/dist/classify-severity.d.ts +1 -23
  69. package/dist/classify-severity.d.ts.map +1 -1
  70. package/dist/classify-severity.js +3 -24
  71. package/dist/classify-severity.js.map +1 -1
  72. package/dist/cli-help.d.ts.map +1 -1
  73. package/dist/cli-help.js +2 -0
  74. package/dist/cli-help.js.map +1 -1
  75. package/dist/cli.d.ts +4 -2
  76. package/dist/cli.d.ts.map +1 -1
  77. package/dist/cli.js +148 -149
  78. package/dist/cli.js.map +1 -1
  79. package/dist/cloud-publish.js +1 -1
  80. package/dist/cloud-publish.js.map +1 -1
  81. package/dist/codex-sdk-environment.js +1 -1
  82. package/dist/codex-sdk-environment.js.map +1 -1
  83. package/dist/component-plan.js +1 -1
  84. package/dist/component-plan.js.map +1 -1
  85. package/dist/component-scan.d.ts.map +1 -1
  86. package/dist/component-scan.js +5 -4
  87. package/dist/component-scan.js.map +1 -1
  88. package/dist/config.d.ts +12 -0
  89. package/dist/config.d.ts.map +1 -1
  90. package/dist/config.js +10 -4
  91. package/dist/config.js.map +1 -1
  92. package/dist/contract.d.ts +6 -0
  93. package/dist/contract.d.ts.map +1 -1
  94. package/dist/contract.js +69 -20
  95. package/dist/contract.js.map +1 -1
  96. package/dist/cost-model.d.ts.map +1 -1
  97. package/dist/cost-model.js +7 -2
  98. package/dist/cost-model.js.map +1 -1
  99. package/dist/custom-validation-prompt.js +3 -3
  100. package/dist/custom-validation-prompt.js.map +1 -1
  101. package/dist/deduplication/codex-review.d.ts +1 -5
  102. package/dist/deduplication/codex-review.d.ts.map +1 -1
  103. package/dist/deduplication/codex-review.js +2 -2
  104. package/dist/deduplication/codex-review.js.map +1 -1
  105. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  106. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  107. package/dist/deduplication/deduplication-prompts.js +2 -2
  108. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  109. package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
  110. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  111. package/dist/deduplication/deduplication-reviewer.js +1 -1
  112. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  113. package/dist/deduplication/records-protocol.d.ts +3 -8
  114. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  115. package/dist/deduplication/records-protocol.js +11 -171
  116. package/dist/deduplication/records-protocol.js.map +1 -1
  117. package/dist/deduplication/records.js +1 -1
  118. package/dist/deduplication/records.js.map +1 -1
  119. package/dist/deduplication/scan.d.ts.map +1 -1
  120. package/dist/deduplication/scan.js +10 -9
  121. package/dist/deduplication/scan.js.map +1 -1
  122. package/dist/deep-config.d.ts +4 -1
  123. package/dist/deep-config.d.ts.map +1 -1
  124. package/dist/deep-config.js +21 -1
  125. package/dist/deep-config.js.map +1 -1
  126. package/dist/deep-progress.d.ts +15 -1
  127. package/dist/deep-progress.d.ts.map +1 -1
  128. package/dist/deep-progress.js +15 -16
  129. package/dist/deep-progress.js.map +1 -1
  130. package/dist/executable-path.d.ts +2 -0
  131. package/dist/executable-path.d.ts.map +1 -0
  132. package/dist/executable-path.js +12 -0
  133. package/dist/executable-path.js.map +1 -0
  134. package/dist/feedback.d.ts +1 -4
  135. package/dist/feedback.d.ts.map +1 -1
  136. package/dist/feedback.js +1 -1
  137. package/dist/feedback.js.map +1 -1
  138. package/dist/findings-import.d.ts +1 -1
  139. package/dist/findings-import.d.ts.map +1 -1
  140. package/dist/findings-import.js +3 -3
  141. package/dist/findings-import.js.map +1 -1
  142. package/dist/git-remote.d.ts +10 -0
  143. package/dist/git-remote.d.ts.map +1 -0
  144. package/dist/git-remote.js +24 -0
  145. package/dist/git-remote.js.map +1 -0
  146. package/dist/github.d.ts.map +1 -1
  147. package/dist/github.js +5 -7
  148. package/dist/github.js.map +1 -1
  149. package/dist/host-protocol.d.ts +19 -0
  150. package/dist/host-protocol.d.ts.map +1 -0
  151. package/dist/host-protocol.js +270 -0
  152. package/dist/host-protocol.js.map +1 -0
  153. package/dist/host-records-protocol.d.ts +15 -0
  154. package/dist/host-records-protocol.d.ts.map +1 -0
  155. package/dist/host-records-protocol.js +15 -0
  156. package/dist/host-records-protocol.js.map +1 -0
  157. package/dist/hosted-scan-protocol.d.ts +4 -0
  158. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  159. package/dist/hosted-scan-protocol.js +25 -0
  160. package/dist/hosted-scan-protocol.js.map +1 -0
  161. package/dist/hosted-scan.d.ts +112 -0
  162. package/dist/hosted-scan.d.ts.map +1 -0
  163. package/dist/hosted-scan.js +260 -0
  164. package/dist/hosted-scan.js.map +1 -0
  165. package/dist/index.d.ts +7 -0
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +3 -0
  168. package/dist/index.js.map +1 -1
  169. package/dist/knowledge-base.d.ts.map +1 -1
  170. package/dist/knowledge-base.js +87 -7
  171. package/dist/knowledge-base.js.map +1 -1
  172. package/dist/multiscan.d.ts.map +1 -1
  173. package/dist/multiscan.js +108 -36
  174. package/dist/multiscan.js.map +1 -1
  175. package/dist/patch-publication.d.ts +26 -0
  176. package/dist/patch-publication.d.ts.map +1 -0
  177. package/dist/patch-publication.js +105 -0
  178. package/dist/patch-publication.js.map +1 -0
  179. package/dist/patch-tui.d.ts.map +1 -1
  180. package/dist/patch-tui.js +4 -1
  181. package/dist/patch-tui.js.map +1 -1
  182. package/dist/project-config-schema.d.ts +2 -0
  183. package/dist/project-config-schema.d.ts.map +1 -1
  184. package/dist/project-config-schema.js +1 -0
  185. package/dist/project-config-schema.js.map +1 -1
  186. package/dist/project-config.d.ts +1 -0
  187. package/dist/project-config.d.ts.map +1 -1
  188. package/dist/project-config.js +16 -6
  189. package/dist/project-config.js.map +1 -1
  190. package/dist/publication-store.d.ts.map +1 -1
  191. package/dist/publication-store.js +73 -63
  192. package/dist/publication-store.js.map +1 -1
  193. package/dist/publication.d.ts +0 -2
  194. package/dist/publication.d.ts.map +1 -1
  195. package/dist/publication.js +135 -24
  196. package/dist/publication.js.map +1 -1
  197. package/dist/publish.d.ts.map +1 -1
  198. package/dist/publish.js +39 -25
  199. package/dist/publish.js.map +1 -1
  200. package/dist/runtime.d.ts +5 -2
  201. package/dist/runtime.d.ts.map +1 -1
  202. package/dist/runtime.js +86 -58
  203. package/dist/runtime.js.map +1 -1
  204. package/dist/scan-executor.d.ts +104 -0
  205. package/dist/scan-executor.d.ts.map +1 -0
  206. package/dist/scan-executor.js +62 -0
  207. package/dist/scan-executor.js.map +1 -0
  208. package/dist/scan-settings.d.ts +1 -0
  209. package/dist/scan-settings.d.ts.map +1 -1
  210. package/dist/scan-settings.js +7 -1
  211. package/dist/scan-settings.js.map +1 -1
  212. package/dist/scan-time-budget.d.ts +9 -0
  213. package/dist/scan-time-budget.d.ts.map +1 -0
  214. package/dist/scan-time-budget.js +16 -0
  215. package/dist/scan-time-budget.js.map +1 -0
  216. package/dist/severity-review.d.ts +29 -0
  217. package/dist/severity-review.d.ts.map +1 -0
  218. package/dist/severity-review.js +47 -0
  219. package/dist/severity-review.js.map +1 -0
  220. package/dist/targets.d.ts.map +1 -1
  221. package/dist/targets.js +17 -25
  222. package/dist/targets.js.map +1 -1
  223. package/dist/validation-records.d.ts +38 -0
  224. package/dist/validation-records.d.ts.map +1 -0
  225. package/dist/validation-records.js +76 -0
  226. package/dist/validation-records.js.map +1 -0
  227. package/dist/version.d.ts.map +1 -1
  228. package/dist/version.js +4 -2
  229. package/dist/version.js.map +1 -1
  230. package/dist/worker-progress.d.ts +43 -15
  231. package/dist/worker-progress.d.ts.map +1 -1
  232. package/dist/worker-progress.js +22 -80
  233. package/dist/worker-progress.js.map +1 -1
  234. package/docs/classify-severity-records.md +89 -0
  235. package/docs/cli.md +281 -35
  236. package/docs/hosted-scans.md +242 -0
  237. package/docs/validate-records.md +69 -0
  238. package/package.json +18 -14
  239. package/schemas/hosted-scan-v2.fixture.json +145 -0
  240. package/schemas/project-config.schema.json +7 -1
  241. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  242. package/_bundled_plugin/references/config-preflight.md +0 -93
  243. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  244. 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
- let ancestors = 0;
526
+ const ancestors = [];
527
527
  for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
528
- ancestors += 1;
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 ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
555
- resolvedAliases: options.resolvedAliases,
556
- scope: "ancestor",
557
- });
558
- if (ancestor.untrustedPrincipals.length !== 0) {
559
- throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
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}.previous-${new Date()
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 created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
1470
- if ((process.umask() & 0o700) !== 0)
1471
- await chmod(created, 0o700);
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 = await mkdir(path, { recursive: true, mode: 0o700 });
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: cancellation?.signal ?? 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) {