@openai/codex-security 0.2.0 → 0.4.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 (484) hide show
  1. package/README.md +437 -2692
  2. package/_bundled_plugin/.app.json +5 -1
  3. package/_bundled_plugin/.codex-plugin/plugin.json +4 -0
  4. package/_bundled_plugin/.mcp.json +2 -0
  5. package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
  6. package/_bundled_plugin/examples/completed-scan/report.md +28 -26
  7. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
  8. package/_bundled_plugin/mcp/helpers.mjs +1 -0
  9. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +6 -213
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +556 -0
  20. package/_bundled_plugin/mcp/server.mjs +1 -0
  21. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  22. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  23. package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
  24. package/_bundled_plugin/references/artifact-storage.md +2 -2
  25. package/_bundled_plugin/references/config-preflight.md +0 -4
  26. package/_bundled_plugin/references/core-scan.md +21 -9
  27. package/_bundled_plugin/references/final-report.md +11 -13
  28. package/_bundled_plugin/references/finding-detail-fields.md +90 -80
  29. package/_bundled_plugin/references/sarif-adapter.md +1 -1
  30. package/_bundled_plugin/references/scan-artifacts.md +1 -2
  31. package/_bundled_plugin/references/scan-contract.md +9 -4
  32. package/_bundled_plugin/references/scan-prologue.md +12 -0
  33. package/_bundled_plugin/references/security-guidance.md +2 -2
  34. package/_bundled_plugin/references/standalone-validation.md +11 -0
  35. package/_bundled_plugin/references/threat-model.md +1 -1
  36. package/_bundled_plugin/schemas/coverage.schema.json +43 -170
  37. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
  38. package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
  39. package/_bundled_plugin/schemas/findings.schema.json +159 -567
  40. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  41. package/_bundled_plugin/schemas/scan-manifest.schema.json +78 -220
  42. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
  43. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
  44. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
  45. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
  46. package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
  47. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +169 -294
  48. package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
  49. package/_bundled_plugin/scripts/codex_session.mjs +53 -0
  50. package/_bundled_plugin/scripts/config_preflight.py +26 -62
  51. package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
  52. package/_bundled_plugin/scripts/deep_scan_workbench.py +129 -150
  53. package/_bundled_plugin/scripts/finalize_scan_contract.py +321 -237
  54. package/_bundled_plugin/scripts/finding_preview.py +39 -9
  55. package/_bundled_plugin/scripts/generate_in_scope_files.py +27 -77
  56. package/_bundled_plugin/scripts/generate_rank_input.py +115 -926
  57. package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -10
  58. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
  59. package/_bundled_plugin/scripts/rank_preview.py +42 -918
  60. package/_bundled_plugin/scripts/report_projection.py +150 -183
  61. package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
  62. package/_bundled_plugin/scripts/threat_model_projection.py +4 -7
  63. package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
  64. package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
  65. package/_bundled_plugin/scripts/windows_scan_local_files.py +48 -3
  66. package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
  67. package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
  68. package/_bundled_plugin/scripts/workbench/storage.py +10 -6
  69. package/_bundled_plugin/scripts/workbench_cli.py +102 -184
  70. package/_bundled_plugin/scripts/workbench_db.py +463 -464
  71. package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
  72. package/_bundled_plugin/scripts/workbench_finding_index.py +19 -1
  73. package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
  74. package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
  75. package/_bundled_plugin/scripts/workbench_native_indexes.py +27 -14
  76. package/_bundled_plugin/scripts/workbench_progress.py +14 -58
  77. package/_bundled_plugin/scripts/workbench_publication.py +234 -289
  78. package/_bundled_plugin/scripts/workbench_remediation.py +12 -0
  79. package/_bundled_plugin/scripts/workbench_saved_results.py +172 -49
  80. package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
  81. package/_bundled_plugin/scripts/workbench_scan_start.py +105 -41
  82. package/_bundled_plugin/scripts/workbench_scan_usage.py +194 -42
  83. package/_bundled_plugin/scripts/workbench_schema.py +37 -1151
  84. package/_bundled_plugin/scripts/workbench_source_excerpt.py +11 -1
  85. package/_bundled_plugin/scripts/workbench_target.py +430 -142
  86. package/_bundled_plugin/scripts/workbench_validation.py +31 -28
  87. package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
  88. package/_bundled_plugin/shared/workbench-migrations.json +414 -0
  89. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
  90. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
  91. package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
  92. package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
  93. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +3 -3
  94. package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
  95. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
  96. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
  97. package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
  98. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  99. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +15 -1
  100. package/_bundled_plugin/skills/threat-model/SKILL.md +1 -1
  101. package/_bundled_plugin/skills/track-findings/SKILL.md +48 -176
  102. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
  103. package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
  104. package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
  105. package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
  106. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
  107. package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
  108. package/bin/codex-security.mjs +9 -2
  109. package/dist/api.d.ts +63 -10
  110. package/dist/api.d.ts.map +1 -1
  111. package/dist/api.js +1015 -383
  112. package/dist/api.js.map +1 -1
  113. package/dist/artifact-export.d.ts +1 -1
  114. package/dist/artifact-export.d.ts.map +1 -1
  115. package/dist/artifact-export.js +28 -13
  116. package/dist/artifact-export.js.map +1 -1
  117. package/dist/auth.d.ts +2 -6
  118. package/dist/auth.d.ts.map +1 -1
  119. package/dist/auth.js +19 -9
  120. package/dist/auth.js.map +1 -1
  121. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  122. package/dist/bulk-scan-discovery.js +1 -0
  123. package/dist/bulk-scan-discovery.js.map +1 -1
  124. package/dist/classify-severity.d.ts +26 -9
  125. package/dist/classify-severity.d.ts.map +1 -1
  126. package/dist/classify-severity.js +13 -30
  127. package/dist/classify-severity.js.map +1 -1
  128. package/dist/cli-help.d.ts.map +1 -1
  129. package/dist/cli-help.js +17 -13
  130. package/dist/cli-help.js.map +1 -1
  131. package/dist/cli-signals.d.ts +8 -0
  132. package/dist/cli-signals.d.ts.map +1 -0
  133. package/dist/cli-signals.js +28 -0
  134. package/dist/cli-signals.js.map +1 -0
  135. package/dist/cli.d.ts +4 -3
  136. package/dist/cli.d.ts.map +1 -1
  137. package/dist/cli.js +1102 -905
  138. package/dist/cli.js.map +1 -1
  139. package/dist/cloud-publish.d.ts.map +1 -1
  140. package/dist/cloud-publish.js +10 -9
  141. package/dist/cloud-publish.js.map +1 -1
  142. package/dist/codeowners.d.ts +19 -0
  143. package/dist/codeowners.d.ts.map +1 -0
  144. package/dist/codeowners.js +138 -0
  145. package/dist/codeowners.js.map +1 -0
  146. package/dist/codex-sdk-environment.d.ts +1 -0
  147. package/dist/codex-sdk-environment.d.ts.map +1 -1
  148. package/dist/codex-sdk-environment.js +40 -2
  149. package/dist/codex-sdk-environment.js.map +1 -1
  150. package/dist/component-plan.d.ts +2 -5
  151. package/dist/component-plan.d.ts.map +1 -1
  152. package/dist/component-plan.js +39 -31
  153. package/dist/component-plan.js.map +1 -1
  154. package/dist/component-scan.d.ts +6 -5
  155. package/dist/component-scan.d.ts.map +1 -1
  156. package/dist/component-scan.js +25 -36
  157. package/dist/component-scan.js.map +1 -1
  158. package/dist/config.d.ts.map +1 -1
  159. package/dist/config.js +64 -74
  160. package/dist/config.js.map +1 -1
  161. package/dist/contract.d.ts +16 -3
  162. package/dist/contract.d.ts.map +1 -1
  163. package/dist/contract.js +91 -255
  164. package/dist/contract.js.map +1 -1
  165. package/dist/cost-model.d.ts +13 -6
  166. package/dist/cost-model.d.ts.map +1 -1
  167. package/dist/cost-model.js +14 -4
  168. package/dist/cost-model.js.map +1 -1
  169. package/dist/cost.d.ts +10 -2
  170. package/dist/cost.d.ts.map +1 -1
  171. package/dist/cost.js +102 -104
  172. package/dist/cost.js.map +1 -1
  173. package/dist/custom-validation-prompt.d.ts.map +1 -1
  174. package/dist/custom-validation-prompt.js +6 -5
  175. package/dist/custom-validation-prompt.js.map +1 -1
  176. package/dist/custom-validation.d.ts +1 -2
  177. package/dist/custom-validation.d.ts.map +1 -1
  178. package/dist/custom-validation.js +9 -3
  179. package/dist/custom-validation.js.map +1 -1
  180. package/dist/deduplication/checkpointed-review.d.ts +4 -2
  181. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  182. package/dist/deduplication/checkpointed-review.js +23 -9
  183. package/dist/deduplication/checkpointed-review.js.map +1 -1
  184. package/dist/deduplication/codex-review.d.ts +8 -6
  185. package/dist/deduplication/codex-review.d.ts.map +1 -1
  186. package/dist/deduplication/codex-review.js +128 -19
  187. package/dist/deduplication/codex-review.js.map +1 -1
  188. package/dist/deduplication/deduplication-prompts.d.ts +5 -2
  189. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  190. package/dist/deduplication/deduplication-prompts.js +18 -4
  191. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  192. package/dist/deduplication/deduplication-reviewer.d.ts +27 -5
  193. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  194. package/dist/deduplication/deduplication-reviewer.js +58 -48
  195. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  196. package/dist/deduplication/deduplication.d.ts.map +1 -1
  197. package/dist/deduplication/deduplication.js +19 -51
  198. package/dist/deduplication/deduplication.js.map +1 -1
  199. package/dist/deduplication/diagnostics.d.ts +17 -0
  200. package/dist/deduplication/diagnostics.d.ts.map +1 -0
  201. package/dist/deduplication/diagnostics.js +5 -0
  202. package/dist/deduplication/diagnostics.js.map +1 -0
  203. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  204. package/dist/deduplication/finding-schema.js +7 -1
  205. package/dist/deduplication/finding-schema.js.map +1 -1
  206. package/dist/deduplication/local.d.ts +31 -0
  207. package/dist/deduplication/local.d.ts.map +1 -0
  208. package/dist/deduplication/local.js +166 -0
  209. package/dist/deduplication/local.js.map +1 -0
  210. package/dist/deduplication/records-protocol.d.ts +3 -8
  211. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  212. package/dist/deduplication/records-protocol.js +11 -184
  213. package/dist/deduplication/records-protocol.js.map +1 -1
  214. package/dist/deduplication/records.d.ts +186 -11
  215. package/dist/deduplication/records.d.ts.map +1 -1
  216. package/dist/deduplication/records.js +10 -18
  217. package/dist/deduplication/records.js.map +1 -1
  218. package/dist/deduplication/scan.d.ts +9 -3
  219. package/dist/deduplication/scan.d.ts.map +1 -1
  220. package/dist/deduplication/scan.js +158 -39
  221. package/dist/deduplication/scan.js.map +1 -1
  222. package/dist/deep-config.d.ts +2 -1
  223. package/dist/deep-config.d.ts.map +1 -1
  224. package/dist/deep-config.js +4 -4
  225. package/dist/deep-config.js.map +1 -1
  226. package/dist/deep-progress.d.ts +17 -1
  227. package/dist/deep-progress.d.ts.map +1 -1
  228. package/dist/deep-progress.js +19 -17
  229. package/dist/deep-progress.js.map +1 -1
  230. package/dist/deep-scan.d.ts +20 -0
  231. package/dist/deep-scan.d.ts.map +1 -0
  232. package/dist/deep-scan.js +113 -0
  233. package/dist/deep-scan.js.map +1 -0
  234. package/dist/errors.d.ts +2 -0
  235. package/dist/errors.d.ts.map +1 -1
  236. package/dist/errors.js +2 -0
  237. package/dist/errors.js.map +1 -1
  238. package/dist/executable-path.d.ts +2 -0
  239. package/dist/executable-path.d.ts.map +1 -0
  240. package/dist/executable-path.js +12 -0
  241. package/dist/executable-path.js.map +1 -0
  242. package/dist/feedback.d.ts +1 -4
  243. package/dist/feedback.d.ts.map +1 -1
  244. package/dist/feedback.js +54 -22
  245. package/dist/feedback.js.map +1 -1
  246. package/dist/finding-catalogue.d.ts.map +1 -1
  247. package/dist/finding-catalogue.js +4 -8
  248. package/dist/finding-catalogue.js.map +1 -1
  249. package/dist/finding-normalization.d.ts +5 -0
  250. package/dist/finding-normalization.d.ts.map +1 -0
  251. package/dist/finding-normalization.js +120 -0
  252. package/dist/finding-normalization.js.map +1 -0
  253. package/dist/finding-retrieval.d.ts +9 -0
  254. package/dist/finding-retrieval.d.ts.map +1 -1
  255. package/dist/finding-retrieval.js.map +1 -1
  256. package/dist/finding-workflow.d.ts +13 -8
  257. package/dist/finding-workflow.d.ts.map +1 -1
  258. package/dist/finding-workflow.js +14 -6
  259. package/dist/finding-workflow.js.map +1 -1
  260. package/dist/findings-client.d.ts +2 -1
  261. package/dist/findings-client.d.ts.map +1 -1
  262. package/dist/findings-client.js +36 -9
  263. package/dist/findings-client.js.map +1 -1
  264. package/dist/findings-errors.d.ts +16 -0
  265. package/dist/findings-errors.d.ts.map +1 -0
  266. package/dist/findings-errors.js +24 -0
  267. package/dist/findings-errors.js.map +1 -0
  268. package/dist/findings-import.d.ts +1 -1
  269. package/dist/findings-import.d.ts.map +1 -1
  270. package/dist/findings-import.js +12 -30
  271. package/dist/findings-import.js.map +1 -1
  272. package/dist/github.d.ts.map +1 -1
  273. package/dist/github.js +7 -1
  274. package/dist/github.js.map +1 -1
  275. package/dist/host-protocol.d.ts +19 -0
  276. package/dist/host-protocol.d.ts.map +1 -0
  277. package/dist/host-protocol.js +270 -0
  278. package/dist/host-protocol.js.map +1 -0
  279. package/dist/hosted-scan-protocol.d.ts +4 -0
  280. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  281. package/dist/hosted-scan-protocol.js +25 -0
  282. package/dist/hosted-scan-protocol.js.map +1 -0
  283. package/dist/hosted-scan.d.ts +117 -0
  284. package/dist/hosted-scan.d.ts.map +1 -0
  285. package/dist/hosted-scan.js +260 -0
  286. package/dist/hosted-scan.js.map +1 -0
  287. package/dist/import-scan.d.ts.map +1 -1
  288. package/dist/import-scan.js +48 -38
  289. package/dist/import-scan.js.map +1 -1
  290. package/dist/index.d.ts +11 -4
  291. package/dist/index.d.ts.map +1 -1
  292. package/dist/index.js +2 -1
  293. package/dist/index.js.map +1 -1
  294. package/dist/knowledge-base.d.ts +7 -1
  295. package/dist/knowledge-base.d.ts.map +1 -1
  296. package/dist/knowledge-base.js +114 -46
  297. package/dist/knowledge-base.js.map +1 -1
  298. package/dist/linear.d.ts.map +1 -1
  299. package/dist/linear.js +2 -7
  300. package/dist/linear.js.map +1 -1
  301. package/dist/mock-scan.d.ts.map +1 -1
  302. package/dist/mock-scan.js +0 -1
  303. package/dist/mock-scan.js.map +1 -1
  304. package/dist/models.d.ts +0 -2
  305. package/dist/models.d.ts.map +1 -1
  306. package/dist/models.js.map +1 -1
  307. package/dist/multiscan.d.ts +9 -3
  308. package/dist/multiscan.d.ts.map +1 -1
  309. package/dist/multiscan.js +240 -135
  310. package/dist/multiscan.js.map +1 -1
  311. package/dist/owner-evidence.d.ts +10 -2
  312. package/dist/owner-evidence.d.ts.map +1 -1
  313. package/dist/owner-evidence.js +67 -8
  314. package/dist/owner-evidence.js.map +1 -1
  315. package/dist/patch-tui.d.ts.map +1 -1
  316. package/dist/patch-tui.js +3 -2
  317. package/dist/patch-tui.js.map +1 -1
  318. package/dist/project-config.js +3 -3
  319. package/dist/project-config.js.map +1 -1
  320. package/dist/provider-profile.d.ts +21 -0
  321. package/dist/provider-profile.d.ts.map +1 -0
  322. package/dist/provider-profile.js +133 -0
  323. package/dist/provider-profile.js.map +1 -0
  324. package/dist/publication-events.d.ts +6 -8
  325. package/dist/publication-events.d.ts.map +1 -1
  326. package/dist/publication-events.js +25 -50
  327. package/dist/publication-events.js.map +1 -1
  328. package/dist/publication-store.d.ts.map +1 -1
  329. package/dist/publication-store.js +95 -109
  330. package/dist/publication-store.js.map +1 -1
  331. package/dist/publication.d.ts +1 -4
  332. package/dist/publication.d.ts.map +1 -1
  333. package/dist/publication.js +2 -13
  334. package/dist/publication.js.map +1 -1
  335. package/dist/publish.d.ts +1 -5
  336. package/dist/publish.d.ts.map +1 -1
  337. package/dist/publish.js +109 -160
  338. package/dist/publish.js.map +1 -1
  339. package/dist/request-metadata.d.ts +9 -0
  340. package/dist/request-metadata.d.ts.map +1 -0
  341. package/dist/request-metadata.js +13 -0
  342. package/dist/request-metadata.js.map +1 -0
  343. package/dist/runtime.d.ts +20 -6
  344. package/dist/runtime.d.ts.map +1 -1
  345. package/dist/runtime.js +407 -148
  346. package/dist/runtime.js.map +1 -1
  347. package/dist/saved-scan-bootstrap.d.ts +14 -0
  348. package/dist/saved-scan-bootstrap.d.ts.map +1 -0
  349. package/dist/saved-scan-bootstrap.js +261 -0
  350. package/dist/saved-scan-bootstrap.js.map +1 -0
  351. package/dist/saved-scan.d.ts +1 -1
  352. package/dist/saved-scan.d.ts.map +1 -1
  353. package/dist/saved-scan.js +6 -12
  354. package/dist/saved-scan.js.map +1 -1
  355. package/dist/scan-activity.js +11 -8
  356. package/dist/scan-activity.js.map +1 -1
  357. package/dist/scan-comparison.d.ts +28 -15
  358. package/dist/scan-comparison.d.ts.map +1 -1
  359. package/dist/scan-comparison.js +276 -281
  360. package/dist/scan-comparison.js.map +1 -1
  361. package/dist/scan-dashboard.d.ts +3 -0
  362. package/dist/scan-dashboard.d.ts.map +1 -1
  363. package/dist/scan-dashboard.js +345 -77
  364. package/dist/scan-dashboard.js.map +1 -1
  365. package/dist/scan-executor.d.ts +104 -0
  366. package/dist/scan-executor.d.ts.map +1 -0
  367. package/dist/scan-executor.js +62 -0
  368. package/dist/scan-executor.js.map +1 -0
  369. package/dist/scan-history-renderer.d.ts.map +1 -1
  370. package/dist/scan-history-renderer.js +54 -13
  371. package/dist/scan-history-renderer.js.map +1 -1
  372. package/dist/scan-inputs.d.ts +6 -0
  373. package/dist/scan-inputs.d.ts.map +1 -0
  374. package/dist/scan-inputs.js +71 -0
  375. package/dist/scan-inputs.js.map +1 -0
  376. package/dist/scan-logs.d.ts +2 -3
  377. package/dist/scan-logs.d.ts.map +1 -1
  378. package/dist/scan-logs.js +12 -6
  379. package/dist/scan-logs.js.map +1 -1
  380. package/dist/scan-sessions.d.ts +4 -0
  381. package/dist/scan-sessions.d.ts.map +1 -1
  382. package/dist/scan-sessions.js +17 -0
  383. package/dist/scan-sessions.js.map +1 -1
  384. package/dist/scan-skill-paths.d.ts +8 -0
  385. package/dist/scan-skill-paths.d.ts.map +1 -0
  386. package/dist/scan-skill-paths.js +47 -0
  387. package/dist/scan-skill-paths.js.map +1 -0
  388. package/dist/security-policy-cli.d.ts.map +1 -1
  389. package/dist/security-policy-cli.js +7 -27
  390. package/dist/security-policy-cli.js.map +1 -1
  391. package/dist/security-policy.d.ts +9 -5
  392. package/dist/security-policy.d.ts.map +1 -1
  393. package/dist/security-policy.js +33 -14
  394. package/dist/security-policy.js.map +1 -1
  395. package/dist/server/api.d.ts +0 -1
  396. package/dist/server/api.d.ts.map +1 -1
  397. package/dist/server/api.js +0 -1
  398. package/dist/server/api.js.map +1 -1
  399. package/dist/server/embeddings.d.ts +3 -1
  400. package/dist/server/embeddings.d.ts.map +1 -1
  401. package/dist/server/embeddings.js +10 -3
  402. package/dist/server/embeddings.js.map +1 -1
  403. package/dist/server/errors.d.ts +5 -2
  404. package/dist/server/errors.d.ts.map +1 -1
  405. package/dist/server/errors.js +7 -0
  406. package/dist/server/errors.js.map +1 -1
  407. package/dist/server/sqlite-store.d.ts +0 -2
  408. package/dist/server/sqlite-store.d.ts.map +1 -1
  409. package/dist/server/sqlite-store.js +54 -44
  410. package/dist/server/sqlite-store.js.map +1 -1
  411. package/dist/server/storage.d.ts +0 -2
  412. package/dist/server/storage.d.ts.map +1 -1
  413. package/dist/server/storage.js.map +1 -1
  414. package/dist/severity-store.js +19 -24
  415. package/dist/severity-store.js.map +1 -1
  416. package/dist/standalone-validation-prompt.d.ts +2 -0
  417. package/dist/standalone-validation-prompt.d.ts.map +1 -0
  418. package/dist/standalone-validation-prompt.js +10 -0
  419. package/dist/standalone-validation-prompt.js.map +1 -0
  420. package/dist/suggest-owners.d.ts +4 -2
  421. package/dist/suggest-owners.d.ts.map +1 -1
  422. package/dist/suggest-owners.js +11 -5
  423. package/dist/suggest-owners.js.map +1 -1
  424. package/dist/targets.d.ts +11 -0
  425. package/dist/targets.d.ts.map +1 -1
  426. package/dist/targets.js +123 -72
  427. package/dist/targets.js.map +1 -1
  428. package/dist/trusted-executable.d.ts +2 -2
  429. package/dist/trusted-executable.d.ts.map +1 -1
  430. package/dist/trusted-executable.js +8 -6
  431. package/dist/trusted-executable.js.map +1 -1
  432. package/dist/value.js +7 -0
  433. package/dist/value.js.map +1 -1
  434. package/dist/version.js.map +1 -1
  435. package/dist/workbench-arguments.d.ts +3 -0
  436. package/dist/workbench-arguments.d.ts.map +1 -0
  437. package/dist/workbench-arguments.js +15 -0
  438. package/dist/workbench-arguments.js.map +1 -0
  439. package/dist/worker-progress.d.ts +44 -11
  440. package/dist/worker-progress.d.ts.map +1 -1
  441. package/dist/worker-progress.js +48 -49
  442. package/dist/worker-progress.js.map +1 -1
  443. package/docs/cli.md +1788 -0
  444. package/docs/findings-service.md +402 -0
  445. package/docs/hosted-scans.md +242 -0
  446. package/package.json +23 -22
  447. package/schemas/hosted-scan-v2.fixture.json +145 -0
  448. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
  449. package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
  450. package/_bundled_plugin/scripts/workbench_findings.py +0 -221
  451. package/_bundled_plugin/scripts/workbench_severity.py +0 -122
  452. package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
  453. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
  454. package/dist/server/dashboard/app.css +0 -2
  455. package/dist/server/dashboard/app.js +0 -66
  456. package/dist/server/dashboard/index.html +0 -18
  457. package/dist/server/dashboard-types.d.ts +0 -48
  458. package/dist/server/dashboard-types.d.ts.map +0 -1
  459. package/dist/server/dashboard-types.js +0 -2
  460. package/dist/server/dashboard-types.js.map +0 -1
  461. package/dist/server/dashboard.d.ts +0 -6
  462. package/dist/server/dashboard.d.ts.map +0 -1
  463. package/dist/server/dashboard.js +0 -59
  464. package/dist/server/dashboard.js.map +0 -1
  465. package/dist/server/index.d.ts +0 -2
  466. package/dist/server/index.d.ts.map +0 -1
  467. package/dist/server/index.js +0 -6
  468. package/dist/server/index.js.map +0 -1
  469. package/dist/server/routes.d.ts +0 -7
  470. package/dist/server/routes.d.ts.map +0 -1
  471. package/dist/server/routes.js +0 -98
  472. package/dist/server/routes.js.map +0 -1
  473. package/dist/server/serve.d.ts +0 -2
  474. package/dist/server/serve.d.ts.map +0 -1
  475. package/dist/server/serve.js +0 -28
  476. package/dist/server/serve.js.map +0 -1
  477. package/dist/server/server.d.ts +0 -10
  478. package/dist/server/server.d.ts.map +0 -1
  479. package/dist/server/server.js +0 -16
  480. package/dist/server/server.js.map +0 -1
  481. package/dist/server/validation.d.ts +0 -17
  482. package/dist/server/validation.d.ts.map +0 -1
  483. package/dist/server/validation.js +0 -53
  484. package/dist/server/validation.js.map +0 -1
package/dist/runtime.js CHANGED
@@ -1,11 +1,15 @@
1
- import { isNonEmptyString } from "./value.js";
2
- import { execFile as execFileCallback, spawn } from "node:child_process";
1
+ import { executablePathForSpawn } from "./executable-path.js";
2
+ export { executablePathForSpawn } from "./executable-path.js";
3
+ import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
4
+ import { gitProtectionRoots } from "./targets.js";
5
+ import { isNonEmptyString, notify } from "./value.js";
6
+ import { execFile as execFileCallback, spawn, } from "node:child_process";
3
7
  import { randomUUID } from "node:crypto";
4
- import { chmodSync, constants, createWriteStream, existsSync, readdirSync, } from "node:fs";
8
+ import { chmodSync, constants, createWriteStream, } from "node:fs";
5
9
  import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
6
10
  import { homedir, tmpdir } from "node:os";
7
11
  import { createRequire } from "node:module";
8
- import { basename, dirname, extname, join, relative, resolve, win32, } from "node:path";
12
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
9
13
  import { fileURLToPath } from "node:url";
10
14
  import { promisify } from "node:util";
11
15
  import { pipeline } from "node:stream/promises";
@@ -13,13 +17,25 @@ import { crc32 } from "node:zlib";
13
17
  import { setTimeout as delay } from "node:timers/promises";
14
18
  import { openPromise as openZip } from "yauzl";
15
19
  import { parse } from "smol-toml";
16
- import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
20
+ import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
17
21
  import { isRecord } from "./record.js";
18
22
  import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
19
23
  import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
20
24
  const execFile = promisify(execFileCallback);
21
25
  export const MARKETPLACE_NAME = "codex-security-sdk";
22
26
  export const PLUGIN_NAME = "codex-security";
27
+ const MARKETPLACE_MANIFEST = `${JSON.stringify({
28
+ name: MARKETPLACE_NAME,
29
+ interface: { displayName: "Codex Security SDK" },
30
+ plugins: [
31
+ {
32
+ name: PLUGIN_NAME,
33
+ source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
34
+ policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
35
+ category: "Security",
36
+ },
37
+ ],
38
+ }, null, 2)}\n`;
23
39
  const MAX_ZIP_ENTRIES = 4_096;
24
40
  const MAX_ZIP_CENTRAL_DIRECTORY = 16 * 1024 * 1024;
25
41
  const MAX_ZIP_ENTRY_SIZE = 128 * 1024 * 1024;
@@ -72,19 +88,18 @@ except (module["ContractError"], OSError) as error:
72
88
  `.trim();
73
89
  const WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX = "CODEX_SECURITY_ACL_COMPLETE:";
74
90
  const WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE = 2;
75
- function environmentValue(environment, requested) {
76
- const exact = environment[requested]?.trim();
77
- if (exact)
78
- return exact;
79
- return Object.entries(environment)
80
- .find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1]
81
- ?.trim();
91
+ function environmentValue(environment, requested, preserveWhitespace = false) {
92
+ const exact = environment[requested];
93
+ const value = exact?.trim()
94
+ ? exact
95
+ : Object.entries(environment).find(([name, value]) => name.toUpperCase() === requested && value?.trim())?.[1];
96
+ return preserveWhitespace ? value : value?.trim();
82
97
  }
83
98
  export function codexSecurityStateDirectory(environment = process.env) {
84
99
  const configured = environmentValue(environment, "CODEX_SECURITY_STATE_DIR");
85
100
  const path = configured !== undefined
86
101
  ? resolve(expandHome(configured, environment))
87
- : resolve(expandHome(environmentValue(environment, "CODEX_HOME") ??
102
+ : resolve(expandHome(environmentValue(environment, "CODEX_HOME", true) ??
88
103
  join(homedir(), ".codex"), environment), "state", "plugins", "codex-security");
89
104
  requireModelSafeOutputDir(path);
90
105
  return path;
@@ -439,10 +454,10 @@ function windowsAceAllowsAncestorReplacement(rights, inheritanceFlags) {
439
454
  if (/^0x[\da-f]+$/iu.test(rights)) {
440
455
  return (BigInt(rights) & 0x100d0040n) !== 0n;
441
456
  }
442
- for (let index = 0; index < rights.length; index += 2) {
443
- if (["FA", "GA", "FW", "GW", "SD", "WD", "WO", "DC", "DT"].includes(rights.slice(index, index + 2))) {
457
+ // Rights tokens stay aligned to pairs of UTF-16 code units.
458
+ for (const [right] of rights.matchAll(/[\s\S]{2}/g)) {
459
+ if (["FA", "GA", "FW", "GW", "SD", "WD", "WO", "DC", "DT"].includes(right))
444
460
  return true;
445
- }
446
461
  }
447
462
  return false;
448
463
  }
@@ -777,6 +792,15 @@ async function secureWindowsCredentialHome(path) {
777
792
  }
778
793
  }
779
794
  }
795
+ export async function withCredentialHomeLock(codexHome, operation, signal) {
796
+ const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
797
+ try {
798
+ return await operation();
799
+ }
800
+ finally {
801
+ await release();
802
+ }
803
+ }
780
804
  export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal, securityOptions = {}) {
781
805
  throwIfSignalAborted(signal);
782
806
  const homeMetadata = await requireSecureCredentialHome(codexHome, securityOptions);
@@ -1099,11 +1123,99 @@ export async function preparePersistentOutputRoot(stateDirectory, category, repo
1099
1123
  }
1100
1124
  return root;
1101
1125
  }
1102
- const workbenchComparisonSupport = new Map();
1126
+ const WORKBENCH_ARGUMENTS_PROGRAM = String.raw `
1127
+ import json, sys
1128
+ sys.argv[2:] = json.loads(sys.stdin.buffer.readline())
1129
+ `;
1130
+ const WORKBENCH_SCRIPT_PROGRAM = String.raw `
1131
+ import runpy, sys
1132
+ sys.argv = sys.argv[1:]
1133
+ runpy.run_path(sys.argv[0], run_name="__main__")
1134
+ `;
1135
+ const ARCHIVE_READY = "codex-security-archive-ready\n";
1136
+ const ARCHIVE_REGISTRATION_PROGRAM = String.raw `
1137
+ import io, json, runpy, sys
1138
+ control = sys.stdin
1139
+ payload = json.loads(control.readline())
1140
+ sys.stdin = io.TextIOWrapper(io.BytesIO(payload.encode("utf-8")), encoding="utf-8")
1141
+ sys.argv = sys.argv[1:]
1142
+ workbench = runpy.run_path(sys.argv[0])
1143
+ def before_archive():
1144
+ sys.stdout.buffer.write(b"codex-security-archive-ready\n")
1145
+ sys.stdout.buffer.flush()
1146
+ if control.readline() != "\n":
1147
+ raise SystemExit("Scan registration canceled before archival.")
1148
+ workbench["main"](before_archive=before_archive)
1149
+ `;
1103
1150
  export async function runWorkbench(options, args, input) {
1104
1151
  const script = join(options.pluginRoot, "scripts", "workbench_db.py");
1105
- const run = async (arguments_, input) => {
1106
- const result = await runCodexCommand({ command: options.python }, ["-I", "-X", "utf8", "-B", script, ...arguments_], pluginHelperEnvironment(options.environment), input, options.signal);
1152
+ const signal = options.signal;
1153
+ const run = async (arguments_, input, archiveHandshake = false) => {
1154
+ const native = [
1155
+ "database-info",
1156
+ "store-findings",
1157
+ "list-stored-findings",
1158
+ "find-potential-duplicates",
1159
+ "store-dedupe-groups",
1160
+ "list-dedupe-groups",
1161
+ "dashboard",
1162
+ "severity-classification",
1163
+ "read-severity-classification",
1164
+ ].includes(arguments_[0] ?? "");
1165
+ const node = native && process.versions["bun"]
1166
+ ? await resolveTrustedExecutable("node", options.environment, [
1167
+ process.cwd(),
1168
+ options.currentDirectory ?? process.cwd(),
1169
+ ...(typeof options.protectedRoot === "string"
1170
+ ? [options.protectedRoot]
1171
+ : (options.protectedRoot ?? [])),
1172
+ ])
1173
+ : undefined;
1174
+ if (node === null) {
1175
+ throw new Error("Node.js is not available on a trusted PATH.");
1176
+ }
1177
+ const command = native
1178
+ ? (node?.executable ?? process.execPath)
1179
+ : (options.python ??= await resolvePluginPython({
1180
+ environment: options.environment,
1181
+ protectedRoot: options.protectedRoot,
1182
+ currentDirectory: options.currentDirectory,
1183
+ signal: options.signal,
1184
+ }));
1185
+ const stateDirectory = native
1186
+ ? (options.stateDirectory ??
1187
+ codexSecurityStateDirectory(options.environment))
1188
+ : undefined;
1189
+ // OS argv cannot carry NUL, but workbench text fields can.
1190
+ const framedArguments = !native && arguments_.some((argument) => argument.includes("\0"));
1191
+ let program = archiveHandshake ? ARCHIVE_REGISTRATION_PROGRAM : undefined;
1192
+ if (framedArguments)
1193
+ program =
1194
+ WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
1195
+ const result = await runCodexCommand({ command }, native
1196
+ ? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
1197
+ : [
1198
+ "-I",
1199
+ "-X",
1200
+ "utf8",
1201
+ "-B",
1202
+ ...(program === undefined ? [] : ["-c", program]),
1203
+ script,
1204
+ ...(framedArguments ? [] : arguments_),
1205
+ ], pluginHelperEnvironment(node?.environment ?? options.environment),
1206
+ // The SDK owns configuration normalization; the helper receives its resolved location.
1207
+ native
1208
+ ? JSON.stringify(arguments_[0] === "database-info"
1209
+ ? stateDirectory
1210
+ : {
1211
+ stateDirectory,
1212
+ payload: input === undefined ? undefined : JSON.parse(input),
1213
+ })
1214
+ : input, signal, archiveHandshake,
1215
+ // Match native argv's UTF-8 encoding for the private argument frame.
1216
+ framedArguments
1217
+ ? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
1218
+ : undefined);
1107
1219
  if (!result.success) {
1108
1220
  throw new Error(result.stderr.trim() ||
1109
1221
  result.stdout.trim() ||
@@ -1113,45 +1225,18 @@ export async function runWorkbench(options, args, input) {
1113
1225
  };
1114
1226
  let stdout;
1115
1227
  try {
1116
- const arguments_ = [...args];
1117
- const matchesStdinIndex = arguments_.indexOf("--matches-json-stdin");
1118
- if (arguments_[0] === "save-scan-comparison" &&
1119
- matchesStdinIndex !== -1 &&
1120
- input !== undefined) {
1121
- const key = JSON.stringify([options.python, script]);
1122
- let support = workbenchComparisonSupport.get(key);
1123
- if (support === undefined) {
1124
- const help = await run(["save-scan-comparison", "--help"]);
1125
- options.signal?.throwIfAborted();
1126
- support = {
1127
- stdin: help.includes("--matches-json-stdin"),
1128
- related: help
1129
- .replace(/\s+/gu, " ")
1130
- .includes("Comparison payload supports related findings."),
1131
- };
1132
- workbenchComparisonSupport.set(key, support);
1133
- }
1134
- const comparison = JSON.parse(input);
1135
- if (isRecord(comparison) && "related" in comparison && !support.related) {
1136
- delete comparison["related"];
1137
- input = JSON.stringify(comparison);
1138
- }
1139
- if (!support.stdin) {
1140
- arguments_.splice(matchesStdinIndex, 1, "--matches-json", input);
1141
- input = undefined;
1142
- }
1143
- }
1144
- stdout = await run(arguments_, input);
1228
+ const archiveHandshake = signal !== undefined &&
1229
+ args[0] === "register-cli-scan" &&
1230
+ args.includes("--archive-existing") &&
1231
+ !args.includes("--archived-scan-dir");
1232
+ stdout = await run(args, input, archiveHandshake);
1145
1233
  }
1146
1234
  catch (error) {
1147
1235
  if (options.signal?.aborted)
1148
1236
  throw error;
1149
1237
  const detail = processErrorDetail(error);
1150
- const databaseFailure = /\b(?:unable to open database file|attempt to write a readonly database|readonly database|disk i\/o error)\b/iu.test(detail);
1151
1238
  const failure = options.failureMessage ?? "Could not run the Codex Security workbench";
1152
- throw new CodexSecurityError(databaseFailure
1153
- ? `${failure}: cannot open the workbench database at ${join(codexSecurityStateDirectory(options.environment), "workbench.sqlite3")}. Ensure the state directory and SQLite journal files are writable, or set CODEX_SECURITY_STATE_DIR to a writable directory outside the scanned repository.`
1154
- : `${failure}: ${detail}`, { cause: error });
1239
+ throw new CodexSecurityError(`${failure}: ${detail}`, { cause: error });
1155
1240
  }
1156
1241
  let result;
1157
1242
  try {
@@ -1184,8 +1269,8 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
1184
1269
  if (outputDirectory === undefined) {
1185
1270
  return null;
1186
1271
  }
1187
- requireModelSafeOutputDir(outputDirectory);
1188
1272
  const path = resolve(expandHome(outputDirectory));
1273
+ requireModelSafeOutputDir(path);
1189
1274
  try {
1190
1275
  const metadata = await lstat(path).catch(nullIfMissingFileError);
1191
1276
  if (metadata !== null) {
@@ -1343,11 +1428,18 @@ export async function canonicalConfigPath(path) {
1343
1428
  }
1344
1429
  }
1345
1430
  export async function prepareOutputDir(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false, onOutputArchived) {
1431
+ return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "archive" : "reject", onOutputArchived);
1432
+ }
1433
+ /** Leave archival to the scan registration transaction. */
1434
+ export async function prepareScanRegistrationOutput(outputDirectory, repositoryName, temporaryRoot = tmpdir(), validateLocation, archiveExisting = false) {
1435
+ return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
1436
+ }
1437
+ async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
1346
1438
  if (outputDirectory === undefined) {
1347
1439
  requireModelSafeOutputDir(temporaryRoot);
1348
1440
  requireModelSafeOutputDir(await realpath(temporaryRoot));
1349
1441
  }
1350
- const path = await validateOutputDir(outputDirectory, archiveExisting);
1442
+ const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
1351
1443
  validateLocation?.(path ?? (await realpath(temporaryRoot)));
1352
1444
  if (path === null) {
1353
1445
  const created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
@@ -1364,11 +1456,11 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
1364
1456
  let createdRoot;
1365
1457
  try {
1366
1458
  let existing = await lstat(path).catch(nullIfMissingFileError);
1367
- if (existing !== null && archiveExisting) {
1459
+ if (existing !== null && existingOutput === "archive") {
1368
1460
  const archiveDir = await planOutputArchive(path);
1369
1461
  if (archiveDir !== null) {
1370
1462
  await rename(path, archiveDir);
1371
- onOutputArchived?.(archiveDir);
1463
+ notify(() => onOutputArchived?.(archiveDir));
1372
1464
  existing = null;
1373
1465
  }
1374
1466
  }
@@ -1377,7 +1469,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
1377
1469
  if ((process.umask() & 0o700) !== 0)
1378
1470
  await chmod(path, 0o700);
1379
1471
  }
1380
- return await validatePreparedOutputDir(path, validateLocation);
1472
+ return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
1381
1473
  }
1382
1474
  catch (error) {
1383
1475
  if (createdRoot !== undefined) {
@@ -1390,7 +1482,7 @@ export async function prepareOutputDir(outputDirectory, repositoryName, temporar
1390
1482
  });
1391
1483
  }
1392
1484
  }
1393
- export async function validatePreparedOutputDir(path, validateLocation) {
1485
+ export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
1394
1486
  const metadata = await lstat(path);
1395
1487
  if (!metadata.isDirectory()) {
1396
1488
  throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
@@ -1399,7 +1491,7 @@ export async function validatePreparedOutputDir(path, validateLocation) {
1399
1491
  requireModelSafeOutputDir(canonical);
1400
1492
  validateLocation?.(canonical);
1401
1493
  const entries = await readdir(canonical);
1402
- if (entries.length !== 0) {
1494
+ if (!allowNonempty && entries.length !== 0) {
1403
1495
  throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
1404
1496
  }
1405
1497
  requirePrivateOutputDirectory(metadata, path);
@@ -1694,88 +1786,179 @@ async function rejectBackslashZipNames(path, signal) {
1694
1786
  }
1695
1787
  }
1696
1788
  export async function resolvePluginPath(pluginPath, workspace, signal) {
1697
- if (pluginPath === undefined) {
1698
- return await bundledPluginRoot();
1789
+ try {
1790
+ if (pluginPath === undefined) {
1791
+ return await bundledPluginRoot();
1792
+ }
1793
+ const path = resolve(expandHome(pluginPath));
1794
+ const metadata = await lstat(path).catch(() => null);
1795
+ if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
1796
+ return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
1797
+ }
1798
+ if (metadata?.isDirectory()) {
1799
+ throwIfSignalAborted(signal);
1800
+ return await validatePluginRoot(path);
1801
+ }
1802
+ throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
1699
1803
  }
1700
- const path = resolve(expandHome(pluginPath));
1701
- const metadata = await lstat(path).catch(() => null);
1702
- if (metadata?.isFile() && extname(path).toLowerCase() === ".zip") {
1703
- return await extractPluginZip(path, join(workspace, "extracted-plugin"), signal);
1804
+ catch (error) {
1805
+ if (signal?.aborted || error instanceof LocalPluginBootstrapError)
1806
+ throw error;
1807
+ throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
1704
1808
  }
1705
- if (metadata?.isDirectory()) {
1809
+ }
1810
+ export async function createMarketplace(codexHome, pluginRoot, signal) {
1811
+ try {
1706
1812
  throwIfSignalAborted(signal);
1707
- return await validatePluginRoot(path);
1813
+ const root = await realpath(pluginRoot);
1814
+ const marketplace = join(codexHome, "sdk-marketplace");
1815
+ const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
1816
+ await copyPluginTree(root, pluginDestination, signal);
1817
+ const projection = await pluginRuntimeProjection(pluginDestination, signal);
1818
+ for (const [path, file] of projection?.files ?? []) {
1819
+ const destination = join(pluginDestination, path);
1820
+ await mkdir(dirname(destination), { recursive: true });
1821
+ await writeFile(destination, file.contents, { mode: file.mode, signal });
1822
+ if (file.mode !== undefined)
1823
+ await chmod(destination, file.mode);
1824
+ }
1825
+ await writeMarketplaceManifest(marketplace, signal);
1826
+ return marketplace;
1827
+ }
1828
+ catch (error) {
1829
+ if (signal?.aborted || error instanceof LocalPluginBootstrapError)
1830
+ throw error;
1831
+ throw new LocalPluginBootstrapError(errorMessage(error), { cause: error });
1708
1832
  }
1709
- throw new PluginBootstrapError(`Plugin path must be a directory or ZIP: ${path}`);
1710
1833
  }
1711
- export async function createMarketplace(codexHome, pluginRoot, signal) {
1834
+ async function writeMarketplaceManifest(marketplace, signal) {
1712
1835
  throwIfSignalAborted(signal);
1713
- const root = await realpath(pluginRoot);
1714
- const marketplace = join(codexHome, "sdk-marketplace");
1715
- const pluginDestination = join(marketplace, "plugins", PLUGIN_NAME);
1716
- await copyPluginTree(root, pluginDestination, signal);
1717
- throwIfSignalAborted(signal);
1718
- const manifest = {
1719
- name: MARKETPLACE_NAME,
1720
- interface: { displayName: "Codex Security SDK" },
1721
- plugins: [
1722
- {
1723
- name: PLUGIN_NAME,
1724
- source: { source: "local", path: `./plugins/${PLUGIN_NAME}` },
1725
- policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
1726
- category: "Security",
1727
- },
1728
- ],
1729
- };
1730
1836
  const manifestPath = join(marketplace, ".agents", "plugins", "marketplace.json");
1731
1837
  await mkdir(dirname(manifestPath), { recursive: true, mode: 0o700 });
1732
- await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, {
1733
- encoding: "utf8",
1734
- flag: "wx",
1735
- mode: 0o600,
1736
- signal,
1838
+ const temporary = `${manifestPath}.${randomUUID()}.tmp`;
1839
+ try {
1840
+ await writeFile(temporary, MARKETPLACE_MANIFEST, {
1841
+ encoding: "utf8",
1842
+ flag: "wx",
1843
+ mode: 0o600,
1844
+ signal,
1845
+ });
1846
+ throwIfSignalAborted(signal);
1847
+ try {
1848
+ await rename(temporary, manifestPath);
1849
+ }
1850
+ catch (error) {
1851
+ // Concurrent replacement can fail on Windows after another repair wins.
1852
+ const published = await readFile(manifestPath, "utf8").catch(() => null);
1853
+ if (published !== MARKETPLACE_MANIFEST)
1854
+ throw error;
1855
+ }
1856
+ throwIfSignalAborted(signal);
1857
+ }
1858
+ finally {
1859
+ await rm(temporary, { force: true });
1860
+ }
1861
+ }
1862
+ async function pluginRuntimeProjection(root, signal) {
1863
+ const path = join(root, ".mcp.json");
1864
+ // Keep the source link checks ahead of any configuration read.
1865
+ if (!(await lstat(path).catch(nullIfMissingFileError))?.isFile())
1866
+ return;
1867
+ const configuration = JSON.parse(await readFile(path, { encoding: "utf8", signal }));
1868
+ const servers = isRecord(configuration)
1869
+ ? configuration["mcpServers"]
1870
+ : undefined;
1871
+ const server = isRecord(servers) ? servers[PLUGIN_NAME] : undefined;
1872
+ if (!isRecord(server) ||
1873
+ (server["command"] !== "./scripts/launch_codex_security_mcp" &&
1874
+ server["command"] !== "./scripts/launch_codex_security_mcp.cmd")) {
1875
+ return;
1876
+ }
1877
+ const environment = server["env_vars"];
1878
+ if (environment !== undefined && !Array.isArray(environment))
1879
+ return;
1880
+ if (!Array.isArray(environment) ||
1881
+ !environment.includes("CODEX_SECURITY_PLUGIN_ROOT")) {
1882
+ server["env_vars"] = [
1883
+ ...(Array.isArray(environment) ? environment : []),
1884
+ "CODEX_SECURITY_PLUGIN_ROOT",
1885
+ ];
1886
+ }
1887
+ const files = new Map();
1888
+ server["command"] =
1889
+ server["command"] === "./scripts/launch_codex_security_mcp.cmd"
1890
+ ? "./scripts/launch_codex_security_mcp_sdk.cmd"
1891
+ : "./scripts/launch_codex_security_mcp_sdk";
1892
+ files.set("scripts/launch_codex_security_mcp_sdk", {
1893
+ contents: Buffer.from("#!/bin/sh\n" +
1894
+ 'if [ -n "${CODEX_SECURITY_PLUGIN_ROOT:-}" ]; then\n' +
1895
+ ' exec "$CODEX_SECURITY_PLUGIN_ROOT/scripts/launch_codex_security_mcp" "$@"\n' +
1896
+ "fi\n" +
1897
+ 'exec "$(dirname "$0")/launch_codex_security_mcp" "$@"\n'),
1898
+ mode: 0o755,
1737
1899
  });
1738
- throwIfSignalAborted(signal);
1739
- return marketplace;
1900
+ files.set("scripts/launch_codex_security_mcp_sdk.cmd", {
1901
+ contents: Buffer.from("@echo off\r\nsetlocal DisableDelayedExpansion\r\n" +
1902
+ "if not defined CODEX_SECURITY_PLUGIN_ROOT goto codex_security_sdk_original\r\n" +
1903
+ '"%CODEX_SECURITY_PLUGIN_ROOT%\\scripts\\launch_codex_security_mcp.cmd" %*\r\n' +
1904
+ "exit /b\r\n:codex_security_sdk_original\r\n" +
1905
+ '"%~dp0launch_codex_security_mcp.cmd" %*\r\n'),
1906
+ mode: 0o755,
1907
+ });
1908
+ files.set(".mcp.json", {
1909
+ contents: Buffer.from(`${JSON.stringify(configuration, null, 2)}\n`),
1910
+ });
1911
+ return { root, files };
1740
1912
  }
1741
1913
  export function resolveCodexCommand(environment = process.env) {
1742
1914
  const configured = environmentValue(environment, "CODEX_CLI_PATH");
1743
- const expanded = configured === undefined ? undefined : expandHome(configured, environment);
1915
+ const expanded = configured === undefined
1916
+ ? undefined
1917
+ : expandExecutableHome(configured, environment);
1744
1918
  if (expanded &&
1745
1919
  (process.platform !== "win32" || /\.(?:exe|com)$/iu.test(expanded))) {
1746
- return { command: resolve(expanded) };
1747
- }
1748
- const platform = process.platform === "android" ? "linux" : process.platform;
1749
- const packageName = `@openai/codex-${platform}-${process.arch}`;
1750
- let packageJson;
1751
- try {
1752
- const require = createRequire(import.meta.url);
1753
- const codexPackageJson = require.resolve("@openai/codex/package.json");
1754
- packageJson = createRequire(codexPackageJson).resolve(`${packageName}/package.json`);
1755
- }
1756
- catch (error) {
1757
- throw new PluginBootstrapError(`The bundled Codex executable could not be resolved from ${packageName}. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`, { cause: error });
1758
- }
1759
- const vendor = join(dirname(packageJson), "vendor");
1760
- const target = readdirSync(vendor, { withFileTypes: true }).find((entry) => entry.isDirectory());
1761
- const command = join(vendor, target?.name ?? "", "bin", process.platform === "win32" ? "codex.exe" : "codex");
1762
- if (target === undefined || !existsSync(command)) {
1763
- throw new PluginBootstrapError(`The ${packageName} package does not contain the Codex executable. Reinstall @openai/codex with optional dependencies enabled, or set CODEX_CLI_PATH to an installed Codex executable.`);
1920
+ return {
1921
+ command: process.platform === "win32"
1922
+ ? resolve(expanded)
1923
+ : isAbsolute(expanded)
1924
+ ? expanded
1925
+ : `${process.cwd()}${sep}${expanded}`,
1926
+ };
1764
1927
  }
1765
- return { command };
1928
+ return { command: resolveBundledCodexExecutable() };
1766
1929
  }
1767
- export function executablePathForSpawn(command) {
1768
- if (process.platform !== "win32" || !win32.isAbsolute(command))
1769
- return command;
1770
- // Root-relative paths still depend on the child's drive and working directory.
1771
- const root = win32.parse(command).root;
1772
- return root === "\\" || root === "/"
1773
- ? command
1774
- : win32.toNamespacedPath(command);
1930
+ export async function codexExecutableReadPaths(command) {
1931
+ const executable = await realpath(command);
1932
+ const packageJson = resolve(dirname(executable), "..", "package.json");
1933
+ try {
1934
+ const metadata = JSON.parse(await readFile(packageJson, "utf8"));
1935
+ if (metadata?.name !== "@openai/codex" ||
1936
+ typeof metadata.bin?.codex !== "string")
1937
+ return [executable];
1938
+ const launcher = await realpath(resolve(dirname(packageJson), metadata.bin.codex));
1939
+ if (launcher !== executable)
1940
+ return [executable];
1941
+ }
1942
+ catch {
1943
+ // A custom executable need not belong to a readable, valid npm package.
1944
+ return [executable];
1945
+ }
1946
+ // npm's entrypoint launches a native binary, which Linux re-executes in the sandbox.
1947
+ return [
1948
+ executable,
1949
+ await realpath(resolveBundledCodexExecutable(packageJson)),
1950
+ ];
1775
1951
  }
1776
1952
  export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
1777
1953
  const root = await realpath(pluginRoot);
1778
1954
  const { name, version } = await pluginMetadata(root);
1955
+ const projection = await pluginRuntimeProjection(root, options.signal).catch((error) => {
1956
+ if (options.signal?.aborted)
1957
+ throw error;
1958
+ throw new LocalPluginBootstrapError(errorMessage(error), {
1959
+ cause: error,
1960
+ });
1961
+ });
1779
1962
  const marketplace = join(codexHome, "sdk-marketplace");
1780
1963
  throwIfSignalAborted(options.signal);
1781
1964
  const command = options.codexCommand ?? resolveCodexCommand(options.environment);
@@ -1786,20 +1969,23 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
1786
1969
  const run = options.runCodex ?? runPluginCommand;
1787
1970
  const existing = await lstat(marketplace).catch(nullIfMissingFileError);
1788
1971
  if (existing !== null && !existing.isDirectory()) {
1789
- throw new PluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
1972
+ throw new LocalPluginBootstrapError(`Codex Security plugin marketplace path must be a directory: ${marketplace}`);
1790
1973
  }
1791
1974
  const staged = existing === null
1792
1975
  ? null
1793
1976
  : await pluginMetadata(join(marketplace, "plugins", PLUGIN_NAME)).catch(() => null);
1794
1977
  const stagedRoot = join(marketplace, "plugins", PLUGIN_NAME);
1795
1978
  const stagedMatches = staged?.version === version &&
1796
- (await pluginContentsMatch(root, stagedRoot, options.signal));
1979
+ (await pluginContentsMatch(root, stagedRoot, options.signal, false, projection));
1797
1980
  if (!stagedMatches) {
1798
1981
  if (existing !== null) {
1799
1982
  await rm(marketplace, { recursive: true, force: true });
1800
1983
  }
1801
1984
  await createMarketplace(codexHome, root, options.signal);
1802
1985
  }
1986
+ else if ((await readFile(join(marketplace, ".agents", "plugins", "marketplace.json"), "utf8").catch(nullIfMissingFileError)) !== MARKETPLACE_MANIFEST) {
1987
+ await writeMarketplaceManifest(marketplace, options.signal);
1988
+ }
1803
1989
  const config = await readFile(join(codexHome, "config.toml"), "utf8").catch((error) => {
1804
1990
  if (nodeErrorCode(error) === "ENOENT")
1805
1991
  return "";
@@ -1839,7 +2025,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
1839
2025
  isRecord(previous) &&
1840
2026
  typeof previous["installedPath"] === "string" &&
1841
2027
  previous["version"] === version &&
1842
- (await pluginContentsMatch(root, previous["installedPath"], options.signal, true))) {
2028
+ (await pluginContentsMatch(root, previous["installedPath"], options.signal, true, projection))) {
1843
2029
  return {
1844
2030
  pluginRoot: root,
1845
2031
  marketplaceRoot: marketplace,
@@ -1875,7 +2061,7 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
1875
2061
  version,
1876
2062
  };
1877
2063
  }
1878
- async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false) {
2064
+ async function pluginContentsMatch(source, destination, signal, allowExtraFiles = false, projection) {
1879
2065
  throwIfSignalAborted(signal);
1880
2066
  const sourceMetadata = await lstat(source);
1881
2067
  const destinationMetadata = await lstat(destination).catch((error) => {
@@ -1887,26 +2073,44 @@ async function pluginContentsMatch(source, destination, signal, allowExtraFiles
1887
2073
  if (destinationMetadata === null)
1888
2074
  return false;
1889
2075
  if (sourceMetadata.isFile() && destinationMetadata.isFile()) {
1890
- if (sourceMetadata.size !== destinationMetadata.size ||
1891
- (sourceMetadata.mode & 0o111) !== (destinationMetadata.mode & 0o111)) {
2076
+ const projected = projection?.files.get(relative(projection.root, source).split(sep).join("/"));
2077
+ if ((projected === undefined &&
2078
+ sourceMetadata.size !== destinationMetadata.size) ||
2079
+ ((projected?.mode === undefined || process.platform !== "win32") &&
2080
+ ((projected?.mode ?? sourceMetadata.mode) & 0o111) !==
2081
+ (destinationMetadata.mode & 0o111))) {
1892
2082
  return false;
1893
2083
  }
1894
2084
  const [sourceBytes, destinationBytes] = await Promise.all([
1895
2085
  readFile(source, { signal }),
1896
2086
  readFile(destination, { signal }),
1897
2087
  ]);
1898
- return sourceBytes.equals(destinationBytes);
2088
+ return (projected?.contents ?? sourceBytes).equals(destinationBytes);
1899
2089
  }
1900
2090
  if (!sourceMetadata.isDirectory() || !destinationMetadata.isDirectory()) {
1901
2091
  return false;
1902
2092
  }
1903
2093
  const entries = await readdir(source);
2094
+ const projectedDirectory = projection === undefined
2095
+ ? undefined
2096
+ : relative(projection.root, source).split(sep).join("/") || ".";
2097
+ const generated = [...(projection?.files ?? [])].filter(([path]) => dirname(path) === projectedDirectory && !entries.includes(basename(path)));
1904
2098
  if (!allowExtraFiles &&
1905
- entries.length !== (await readdir(destination)).length) {
2099
+ entries.length + generated.length !== (await readdir(destination)).length) {
1906
2100
  return false;
1907
2101
  }
2102
+ for (const [path, file] of generated) {
2103
+ const generatedPath = join(destination, basename(path));
2104
+ const metadata = await lstat(generatedPath).catch(nullIfMissingFileError);
2105
+ if (!metadata?.isFile() ||
2106
+ (process.platform !== "win32" &&
2107
+ (metadata.mode & 0o111) !== ((file.mode ?? 0o644) & 0o111)) ||
2108
+ !file.contents.equals(await readFile(generatedPath, { signal }))) {
2109
+ return false;
2110
+ }
2111
+ }
1908
2112
  for (const entry of entries) {
1909
- if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles))) {
2113
+ if (!(await pluginContentsMatch(join(source, entry), join(destination, entry), signal, allowExtraFiles, projection))) {
1910
2114
  return false;
1911
2115
  }
1912
2116
  }
@@ -1922,32 +2126,50 @@ export async function pluginMetadata(root) {
1922
2126
  manifest = JSON.parse(await readFile(manifestPath, "utf8"));
1923
2127
  }
1924
2128
  catch (error) {
1925
- throw new PluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
2129
+ throw new LocalPluginBootstrapError(`Invalid Codex plugin directory: ${root}`, {
1926
2130
  cause: error,
1927
2131
  });
1928
2132
  }
1929
2133
  if (!isRecord(manifest) || manifest["name"] !== PLUGIN_NAME) {
1930
- throw new PluginBootstrapError("Plugin manifest must have name 'codex-security'.");
2134
+ throw new LocalPluginBootstrapError("Plugin manifest must have name 'codex-security'.");
1931
2135
  }
1932
2136
  const version = manifest["version"];
1933
2137
  if (typeof version !== "string" || version.trim().length === 0) {
1934
- throw new PluginBootstrapError("Plugin manifest must have a non-empty version.");
2138
+ throw new LocalPluginBootstrapError("Plugin manifest must have a non-empty version.");
1935
2139
  }
1936
2140
  return { name: PLUGIN_NAME, version };
1937
2141
  }
1938
2142
  export async function resolvePluginPython(options = {}) {
1939
2143
  const environment = options.environment ?? process.env;
1940
- const protectedRoot = options.protectedRoot ?? process.cwd();
2144
+ const requestedRoots = options.protectedRoot ?? process.cwd();
2145
+ const protectedRoot = typeof requestedRoots === "string" ? [requestedRoots] : [...requestedRoots];
2146
+ const callerDirectories = [
2147
+ process.cwd(),
2148
+ options.currentDirectory ?? process.cwd(),
2149
+ ];
2150
+ // Preserve target and enclosing-checkout protection for every interpreter.
2151
+ for (const directory of new Set([...callerDirectories, ...protectedRoot])) {
2152
+ for (const checkout of await gitProtectionRoots(directory, options.signal))
2153
+ if (!protectedRoot.includes(checkout))
2154
+ protectedRoot.push(checkout);
2155
+ }
2156
+ // Named interpreters are ambient PATH discovery, even when PYTHON names one.
2157
+ // Explicit trusted paths and managed runtimes retain their existing precedence.
2158
+ const discoveryRoots = [...protectedRoot, ...callerDirectories];
1941
2159
  if (options.configuredPath !== undefined) {
1942
- return await requirePython(options.configuredPath, "configured plugin Python", environment, protectedRoot, options.signal);
2160
+ return await requirePython(options.configuredPath, "configured plugin Python", environment, isPythonPathCandidate(options.configuredPath)
2161
+ ? protectedRoot
2162
+ : discoveryRoots, options.signal);
1943
2163
  }
1944
2164
  const inherited = environmentValue(environment, "PYTHON");
1945
2165
  if (inherited) {
1946
- return await requirePython(inherited, "PYTHON", environment, protectedRoot, options.signal);
2166
+ return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
1947
2167
  }
1948
2168
  const home = options.homeDirectory ?? homedir();
2169
+ const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
2170
+ join(home, ".cache");
1949
2171
  const managedRoots = options.managedRuntimeRoots ?? [
1950
- join(home, ".cache", "codex-runtimes", "codex-primary-runtime"),
2172
+ join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
1951
2173
  ];
1952
2174
  const relativeCandidates = process.platform === "win32"
1953
2175
  ? [
@@ -1970,7 +2192,7 @@ export async function resolvePluginPython(options = {}) {
1970
2192
  for (const candidate of process.platform === "win32"
1971
2193
  ? ["python", "python3", "py"]
1972
2194
  : ["python3", "python"]) {
1973
- const resolved = await usablePython(candidate, environment, protectedRoot, options.signal);
2195
+ const resolved = await usablePython(candidate, environment, discoveryRoots, options.signal);
1974
2196
  if (resolved !== null)
1975
2197
  return resolved;
1976
2198
  }
@@ -1981,6 +2203,7 @@ export function pluginExecutionEnvironment(python, environment = process.env) {
1981
2203
  return {
1982
2204
  ...pythonUtf8Environment(environment),
1983
2205
  PYTHON: python,
2206
+ CODEX_SECURITY_PYTHON_COMMAND: python,
1984
2207
  CODEX_CLI_PATH: resolveCodexCommand(environment).command,
1985
2208
  };
1986
2209
  }
@@ -2013,12 +2236,15 @@ function pluginHelperEnvironment(environment) {
2013
2236
  export async function cleanupSdkDirectory(path) {
2014
2237
  await rm(path, { recursive: true, force: true });
2015
2238
  }
2016
- export async function runCodexCommand(command, args, environment, input, signal) {
2017
- const child = spawn(executablePathForSpawn(command.command), [...args], {
2239
+ export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
2240
+ const cancellation = archiveHandshake ? new AbortController() : undefined;
2241
+ const abort = () => cancellation?.abort(signal?.reason);
2242
+ let awaitingArchive = archiveHandshake;
2243
+ const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
2018
2244
  env: environment,
2019
2245
  stdio: ["pipe", "pipe", "pipe"],
2020
2246
  windowsHide: true,
2021
- signal,
2247
+ signal: cancellation?.signal ?? signal,
2022
2248
  });
2023
2249
  let stdout = "";
2024
2250
  let stderr = "";
@@ -2027,6 +2253,17 @@ export async function runCodexCommand(command, args, environment, input, signal)
2027
2253
  child.stderr.setEncoding("utf8");
2028
2254
  child.stdout.on("data", (chunk) => {
2029
2255
  stdout += chunk;
2256
+ if (awaitingArchive && stdout.startsWith(ARCHIVE_READY)) {
2257
+ awaitingArchive = false;
2258
+ stdout = stdout.slice(ARCHIVE_READY.length);
2259
+ signal?.removeEventListener("abort", abort);
2260
+ // The helper cannot rename until this acknowledgement. Detach and check
2261
+ // cancellation before allowing the filesystem/database transaction.
2262
+ if (signal?.aborted)
2263
+ abort();
2264
+ else
2265
+ child.stdin.end("\n");
2266
+ }
2030
2267
  });
2031
2268
  child.stderr.on("data", (chunk) => {
2032
2269
  stderr += chunk;
@@ -2043,8 +2280,24 @@ export async function runCodexCommand(command, args, environment, input, signal)
2043
2280
  ? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
2044
2281
  : reject(processError));
2045
2282
  });
2046
- child.stdin.end(input);
2047
- return await completion;
2283
+ if (archiveHandshake) {
2284
+ signal?.addEventListener("abort", abort, { once: true });
2285
+ if (signal?.aborted)
2286
+ abort();
2287
+ }
2288
+ try {
2289
+ if (stdinPrefix !== undefined)
2290
+ child.stdin.write(stdinPrefix);
2291
+ if (archiveHandshake)
2292
+ child.stdin.write(`${JSON.stringify(input ?? "")}\n`);
2293
+ else
2294
+ child.stdin.end(input);
2295
+ return await completion;
2296
+ }
2297
+ finally {
2298
+ if (archiveHandshake)
2299
+ signal?.removeEventListener("abort", abort);
2300
+ }
2048
2301
  }
2049
2302
  export async function probeCodexSandbox(command, environment, signal) {
2050
2303
  // This preflight covers the Unix sandbox backends.
@@ -2163,7 +2416,7 @@ async function requirePython(candidate, source, environment, protectedRoot, sign
2163
2416
  }
2164
2417
  async function usablePython(candidate, environment = process.env, protectedRoot = process.cwd(), signal) {
2165
2418
  const command = await resolveTrustedExecutable(isPythonPathCandidate(candidate)
2166
- ? expandHome(candidate, environment)
2419
+ ? expandExecutableHome(candidate, environment)
2167
2420
  : candidate, environment, protectedRoot);
2168
2421
  if (command === null)
2169
2422
  return null;
@@ -2190,14 +2443,13 @@ async function usablePython(candidate, environment = process.env, protectedRoot
2190
2443
  }
2191
2444
  }
2192
2445
  export function isPythonPathCandidate(candidate) {
2193
- return (candidate.includes("/") ||
2194
- candidate.includes("\\") ||
2195
- candidate.startsWith("."));
2446
+ return candidate.includes("/") || candidate.includes("\\");
2196
2447
  }
2197
2448
  async function hasPluginManifest(root) {
2198
2449
  return await lstat(join(root, ".codex-plugin", "plugin.json")).then((metadata) => metadata.isFile(), () => false);
2199
2450
  }
2200
- function sameFile(left, right) {
2451
+ /** @internal Compare filesystem identity without depending on path spelling. */
2452
+ export function sameFile(left, right) {
2201
2453
  // NTFS file IDs can exceed JavaScript's safe integer range.
2202
2454
  return Promise.all([
2203
2455
  stat(left, { bigint: true }),
@@ -2205,6 +2457,13 @@ function sameFile(left, right) {
2205
2457
  ]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
2206
2458
  leftMetadata.ino === rightMetadata.ino, () => false);
2207
2459
  }
2460
+ function expandExecutableHome(value, environment) {
2461
+ const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
2462
+ // Expand only the home prefix; joining the suffix would collapse symlink/.. paths.
2463
+ return path.startsWith("~/")
2464
+ ? `${expandHome("~", environment)}${sep}${path.slice(2)}`
2465
+ : expandHome(path, environment);
2466
+ }
2208
2467
  export function expandHome(value, environment = process.env) {
2209
2468
  const home = (process.platform === "win32"
2210
2469
  ? (environmentValue(environment, "USERPROFILE") ??