@openai/codex-security 0.8.2 → 0.9.1

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 (649) hide show
  1. package/README.md +201 -178
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +6 -1
  4. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  5. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  6. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  7. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  8. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  9. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  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/package.json +1 -0
  20. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +51 -14
  21. package/_bundled_plugin/mcp/server.mjs +2 -11
  22. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  23. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  24. package/_bundled_plugin/references/artifact-storage.md +1 -1
  25. package/_bundled_plugin/references/core-scan.md +14 -5
  26. package/_bundled_plugin/references/default-severity-rubric.md +33 -0
  27. package/_bundled_plugin/references/final-report.md +5 -3
  28. package/_bundled_plugin/references/finding-detail-fields.md +19 -18
  29. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  30. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  31. package/_bundled_plugin/references/scan-contract.md +27 -33
  32. package/_bundled_plugin/references/threat-model.md +1 -0
  33. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  34. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  35. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  36. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  37. package/_bundled_plugin/scripts/deep_scan_workbench.py +188 -454
  38. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  39. package/_bundled_plugin/scripts/finalize_scan_contract.py +317 -377
  40. package/_bundled_plugin/scripts/finding_preview.py +25 -29
  41. package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
  42. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  43. package/_bundled_plugin/scripts/posix_scan_local_files.py +198 -0
  44. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  45. package/_bundled_plugin/scripts/report_projection.py +167 -178
  46. package/_bundled_plugin/scripts/review_state.py +8 -2
  47. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  48. package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
  49. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  50. package/_bundled_plugin/scripts/validate_scan_contract.py +9 -7
  51. package/_bundled_plugin/scripts/windows_scan_local_files.py +600 -72
  52. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  53. package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
  54. package/_bundled_plugin/scripts/workbench/retained_coverage.py +38 -75
  55. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  56. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  57. package/_bundled_plugin/scripts/workbench/saved_coverage.py +152 -248
  58. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  59. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  60. package/_bundled_plugin/scripts/workbench/storage.py +71 -7
  61. package/_bundled_plugin/scripts/workbench_cli.py +121 -14
  62. package/_bundled_plugin/scripts/workbench_constants.py +19 -0
  63. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  64. package/_bundled_plugin/scripts/workbench_db.py +550 -492
  65. package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
  66. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  67. package/_bundled_plugin/scripts/workbench_finding_workflows.py +90 -4
  68. package/_bundled_plugin/scripts/workbench_native_indexes.py +29 -33
  69. package/_bundled_plugin/scripts/workbench_progress.py +10 -1
  70. package/_bundled_plugin/scripts/workbench_publication.py +14 -10
  71. package/_bundled_plugin/scripts/workbench_remediation.py +508 -11
  72. package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
  73. package/_bundled_plugin/scripts/workbench_scan_history.py +139 -80
  74. package/_bundled_plugin/scripts/workbench_scan_start.py +84 -25
  75. package/_bundled_plugin/scripts/workbench_scan_usage.py +666 -117
  76. package/_bundled_plugin/scripts/workbench_schema.py +44 -55
  77. package/_bundled_plugin/scripts/workbench_setup.py +251 -0
  78. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  79. package/_bundled_plugin/scripts/workbench_source_scopes.py +33 -23
  80. package/_bundled_plugin/scripts/workbench_target.py +330 -66
  81. package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
  82. package/_bundled_plugin/scripts/workbench_validation.py +44 -12
  83. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -16
  84. package/_bundled_plugin/shared/workbench-migrations.json +53 -0
  85. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  86. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  87. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  88. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  89. package/_bundled_plugin/skills/cloud-findings/SKILL.md +6 -4
  90. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  91. package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -2
  92. package/_bundled_plugin/skills/publish-findings/SKILL.md +81 -45
  93. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  94. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +5 -24
  95. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
  96. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +36 -9
  97. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  98. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  99. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +12 -6
  100. package/dist/api.d.ts +45 -5
  101. package/dist/api.d.ts.map +1 -1
  102. package/dist/api.js +1144 -411
  103. package/dist/api.js.map +1 -1
  104. package/dist/auth.d.ts.map +1 -1
  105. package/dist/auth.js +10 -7
  106. package/dist/auth.js.map +1 -1
  107. package/dist/bedrock-oss-pricing.d.ts +6 -0
  108. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  109. package/dist/bedrock-oss-pricing.js +58 -0
  110. package/dist/bedrock-oss-pricing.js.map +1 -0
  111. package/dist/bedrock-pricing.d.ts +15 -0
  112. package/dist/bedrock-pricing.d.ts.map +1 -0
  113. package/dist/bedrock-pricing.js +117 -0
  114. package/dist/bedrock-pricing.js.map +1 -0
  115. package/dist/blackduck-findings.d.ts +8 -0
  116. package/dist/blackduck-findings.d.ts.map +1 -0
  117. package/dist/blackduck-findings.js +320 -0
  118. package/dist/blackduck-findings.js.map +1 -0
  119. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  120. package/dist/bulk-scan-discovery.js +51 -36
  121. package/dist/bulk-scan-discovery.js.map +1 -1
  122. package/dist/checkmarx-evidence.d.ts +19 -0
  123. package/dist/checkmarx-evidence.d.ts.map +1 -0
  124. package/dist/checkmarx-evidence.js +36 -0
  125. package/dist/checkmarx-evidence.js.map +1 -0
  126. package/dist/checkmarx-findings.d.ts +4 -0
  127. package/dist/checkmarx-findings.d.ts.map +1 -0
  128. package/dist/checkmarx-findings.js +27 -0
  129. package/dist/checkmarx-findings.js.map +1 -0
  130. package/dist/checkmarx-one.d.ts +4 -0
  131. package/dist/checkmarx-one.d.ts.map +1 -0
  132. package/dist/checkmarx-one.js +53 -0
  133. package/dist/checkmarx-one.js.map +1 -0
  134. package/dist/checkmarx-repository.d.ts +12 -0
  135. package/dist/checkmarx-repository.d.ts.map +1 -0
  136. package/dist/checkmarx-repository.js +181 -0
  137. package/dist/checkmarx-repository.js.map +1 -0
  138. package/dist/checkmarx-xml.d.ts +12 -0
  139. package/dist/checkmarx-xml.d.ts.map +1 -0
  140. package/dist/checkmarx-xml.js +196 -0
  141. package/dist/checkmarx-xml.js.map +1 -0
  142. package/dist/classify-severity-records.d.ts +6 -9
  143. package/dist/classify-severity-records.d.ts.map +1 -1
  144. package/dist/classify-severity-records.js +9 -21
  145. package/dist/classify-severity-records.js.map +1 -1
  146. package/dist/classify-severity.d.ts +4 -1
  147. package/dist/classify-severity.d.ts.map +1 -1
  148. package/dist/classify-severity.js +30 -13
  149. package/dist/classify-severity.js.map +1 -1
  150. package/dist/cli.d.ts +14 -5
  151. package/dist/cli.d.ts.map +1 -1
  152. package/dist/cli.js +2112 -1266
  153. package/dist/cli.js.map +1 -1
  154. package/dist/cloud-publish.js +2 -2
  155. package/dist/cloud-publish.js.map +1 -1
  156. package/dist/codex-prompt.d.ts +2 -0
  157. package/dist/codex-prompt.d.ts.map +1 -1
  158. package/dist/codex-prompt.js +6 -0
  159. package/dist/codex-prompt.js.map +1 -1
  160. package/dist/component-scan.d.ts +16 -3
  161. package/dist/component-scan.d.ts.map +1 -1
  162. package/dist/component-scan.js +32 -6
  163. package/dist/component-scan.js.map +1 -1
  164. package/dist/config.d.ts +2 -1
  165. package/dist/config.d.ts.map +1 -1
  166. package/dist/config.js +221 -65
  167. package/dist/config.js.map +1 -1
  168. package/dist/continuum-findings.d.ts +7 -0
  169. package/dist/continuum-findings.d.ts.map +1 -0
  170. package/dist/continuum-findings.js +225 -0
  171. package/dist/continuum-findings.js.map +1 -0
  172. package/dist/contract-values.d.ts +30 -0
  173. package/dist/contract-values.d.ts.map +1 -0
  174. package/dist/contract-values.js +78 -0
  175. package/dist/contract-values.js.map +1 -0
  176. package/dist/contract.d.ts +2 -20
  177. package/dist/contract.d.ts.map +1 -1
  178. package/dist/contract.js +58 -669
  179. package/dist/contract.js.map +1 -1
  180. package/dist/cost-model.d.ts +13 -1
  181. package/dist/cost-model.d.ts.map +1 -1
  182. package/dist/cost-model.js +66 -115
  183. package/dist/cost-model.js.map +1 -1
  184. package/dist/cost.d.ts +61 -4
  185. package/dist/cost.d.ts.map +1 -1
  186. package/dist/cost.js +2560 -100
  187. package/dist/cost.js.map +1 -1
  188. package/dist/custom-publish.d.ts +4 -0
  189. package/dist/custom-publish.d.ts.map +1 -1
  190. package/dist/custom-publish.js +40 -3
  191. package/dist/custom-publish.js.map +1 -1
  192. package/dist/custom-validation-prompt.d.ts +1 -1
  193. package/dist/custom-validation-prompt.d.ts.map +1 -1
  194. package/dist/custom-validation-prompt.js +5 -0
  195. package/dist/custom-validation-prompt.js.map +1 -1
  196. package/dist/custom-validation.d.ts +2 -0
  197. package/dist/custom-validation.d.ts.map +1 -1
  198. package/dist/custom-validation.js +4 -0
  199. package/dist/custom-validation.js.map +1 -1
  200. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  201. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  202. package/dist/deduplication/deduplication-prompts.js +2 -2
  203. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  204. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  205. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  206. package/dist/deduplication/deduplication-reviewer.js +11 -4
  207. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  208. package/dist/deduplication/deduplication.js.map +1 -1
  209. package/dist/deduplication/finding-schema.d.ts +19 -1
  210. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  211. package/dist/deduplication/finding-schema.js +25 -0
  212. package/dist/deduplication/finding-schema.js.map +1 -1
  213. package/dist/deduplication/local.d.ts +2 -2
  214. package/dist/deduplication/local.d.ts.map +1 -1
  215. package/dist/deduplication/local.js +5 -10
  216. package/dist/deduplication/local.js.map +1 -1
  217. package/dist/deduplication/records.d.ts +8 -2
  218. package/dist/deduplication/records.d.ts.map +1 -1
  219. package/dist/deduplication/records.js +36 -8
  220. package/dist/deduplication/records.js.map +1 -1
  221. package/dist/deduplication/refusal.d.ts.map +1 -1
  222. package/dist/deduplication/refusal.js +25 -5
  223. package/dist/deduplication/refusal.js.map +1 -1
  224. package/dist/deduplication/scan.d.ts +3 -0
  225. package/dist/deduplication/scan.d.ts.map +1 -1
  226. package/dist/deduplication/scan.js +1 -1
  227. package/dist/deduplication/scan.js.map +1 -1
  228. package/dist/deep-config.d.ts +0 -1
  229. package/dist/deep-config.d.ts.map +1 -1
  230. package/dist/deep-config.js +22 -33
  231. package/dist/deep-config.js.map +1 -1
  232. package/dist/deep-scan-defaults.d.ts +2 -0
  233. package/dist/deep-scan-defaults.d.ts.map +1 -1
  234. package/dist/deep-scan-defaults.js +28 -1
  235. package/dist/deep-scan-defaults.js.map +1 -1
  236. package/dist/deep-scan.d.ts +13 -0
  237. package/dist/deep-scan.d.ts.map +1 -1
  238. package/dist/deep-scan.js +262 -7
  239. package/dist/deep-scan.js.map +1 -1
  240. package/dist/default-severity-rubric.d.ts +1 -2
  241. package/dist/default-severity-rubric.d.ts.map +1 -1
  242. package/dist/default-severity-rubric.js +2 -66
  243. package/dist/default-severity-rubric.js.map +1 -1
  244. package/dist/endor-findings.d.ts +3 -1
  245. package/dist/endor-findings.d.ts.map +1 -1
  246. package/dist/endor-findings.js +108 -80
  247. package/dist/endor-findings.js.map +1 -1
  248. package/dist/errors.d.ts +1 -1
  249. package/dist/errors.d.ts.map +1 -1
  250. package/dist/errors.js +9 -2
  251. package/dist/errors.js.map +1 -1
  252. package/dist/external-findings-import.d.ts +5 -3
  253. package/dist/external-findings-import.d.ts.map +1 -1
  254. package/dist/external-findings-import.js +11 -16
  255. package/dist/external-findings-import.js.map +1 -1
  256. package/dist/external-findings-local.d.ts +15 -4
  257. package/dist/external-findings-local.d.ts.map +1 -1
  258. package/dist/external-findings-local.js +619 -225
  259. package/dist/external-findings-local.js.map +1 -1
  260. package/dist/external-findings-publish.d.ts +20 -6
  261. package/dist/external-findings-publish.d.ts.map +1 -1
  262. package/dist/external-findings-publish.js +2356 -308
  263. package/dist/external-findings-publish.js.map +1 -1
  264. package/dist/external-findings-read.d.ts +28 -2
  265. package/dist/external-findings-read.d.ts.map +1 -1
  266. package/dist/external-findings-read.js +174 -81
  267. package/dist/external-findings-read.js.map +1 -1
  268. package/dist/external-findings.d.ts +17 -3
  269. package/dist/external-findings.d.ts.map +1 -1
  270. package/dist/external-findings.js +153 -1
  271. package/dist/external-findings.js.map +1 -1
  272. package/dist/external-import-contract.d.ts +33 -1
  273. package/dist/external-import-contract.d.ts.map +1 -1
  274. package/dist/external-import-contract.js +335 -51
  275. package/dist/external-import-contract.js.map +1 -1
  276. package/dist/external-import-models.d.ts +1 -1
  277. package/dist/external-import-models.d.ts.map +1 -1
  278. package/dist/external-import-models.js.map +1 -1
  279. package/dist/feedback.d.ts.map +1 -1
  280. package/dist/feedback.js +5 -4
  281. package/dist/feedback.js.map +1 -1
  282. package/dist/finding-prompt.d.ts +5 -0
  283. package/dist/finding-prompt.d.ts.map +1 -0
  284. package/dist/finding-prompt.js +32 -0
  285. package/dist/finding-prompt.js.map +1 -0
  286. package/dist/finding-retrieval.d.ts +3 -3
  287. package/dist/finding-retrieval.d.ts.map +1 -1
  288. package/dist/finding-retrieval.js.map +1 -1
  289. package/dist/finding-workflow.d.ts +6 -1
  290. package/dist/finding-workflow.d.ts.map +1 -1
  291. package/dist/finding-workflow.js +2 -2
  292. package/dist/finding-workflow.js.map +1 -1
  293. package/dist/findings-client.d.ts +1 -0
  294. package/dist/findings-client.d.ts.map +1 -1
  295. package/dist/findings-client.js +27 -3
  296. package/dist/findings-client.js.map +1 -1
  297. package/dist/git-remote.d.ts +4 -0
  298. package/dist/git-remote.d.ts.map +1 -1
  299. package/dist/git-remote.js +20 -0
  300. package/dist/git-remote.js.map +1 -1
  301. package/dist/github-advisories.d.ts +3 -12
  302. package/dist/github-advisories.d.ts.map +1 -1
  303. package/dist/github-advisories.js +9 -31
  304. package/dist/github-advisories.js.map +1 -1
  305. package/dist/github-dependabot-findings.d.ts.map +1 -1
  306. package/dist/github-dependabot-findings.js +22 -20
  307. package/dist/github-dependabot-findings.js.map +1 -1
  308. package/dist/github-findings.d.ts +4 -1
  309. package/dist/github-findings.d.ts.map +1 -1
  310. package/dist/github-findings.js +392 -79
  311. package/dist/github-findings.js.map +1 -1
  312. package/dist/github.d.ts +17 -7
  313. package/dist/github.d.ts.map +1 -1
  314. package/dist/github.js +43 -30
  315. package/dist/github.js.map +1 -1
  316. package/dist/host-protocol.d.ts +2 -2
  317. package/dist/host-protocol.d.ts.map +1 -1
  318. package/dist/host-protocol.js.map +1 -1
  319. package/dist/host-records-protocol.d.ts +10 -11
  320. package/dist/host-records-protocol.d.ts.map +1 -1
  321. package/dist/host-records-protocol.js +69 -9
  322. package/dist/host-records-protocol.js.map +1 -1
  323. package/dist/hosted-git-remotes.d.ts +5 -0
  324. package/dist/hosted-git-remotes.d.ts.map +1 -0
  325. package/dist/hosted-git-remotes.js +285 -0
  326. package/dist/hosted-git-remotes.js.map +1 -0
  327. package/dist/hosted-git-repository.d.ts +28 -0
  328. package/dist/hosted-git-repository.d.ts.map +1 -0
  329. package/dist/hosted-git-repository.js +222 -0
  330. package/dist/hosted-git-repository.js.map +1 -0
  331. package/dist/hosted-scan-protocol.js +2 -2
  332. package/dist/hosted-scan-protocol.js.map +1 -1
  333. package/dist/hosted-scan.d.ts +15 -0
  334. package/dist/hosted-scan.d.ts.map +1 -1
  335. package/dist/hosted-scan.js +71 -44
  336. package/dist/hosted-scan.js.map +1 -1
  337. package/dist/hosted-scanner-http.d.ts +21 -0
  338. package/dist/hosted-scanner-http.d.ts.map +1 -0
  339. package/dist/hosted-scanner-http.js +204 -0
  340. package/dist/hosted-scanner-http.js.map +1 -0
  341. package/dist/hosted-scanner-v1.d.ts +6 -0
  342. package/dist/hosted-scanner-v1.d.ts.map +1 -0
  343. package/dist/hosted-scanner-v1.js +60 -0
  344. package/dist/hosted-scanner-v1.js.map +1 -0
  345. package/dist/import-scan.d.ts.map +1 -1
  346. package/dist/import-scan.js +3 -0
  347. package/dist/import-scan.js.map +1 -1
  348. package/dist/index.d.ts +24 -6
  349. package/dist/index.d.ts.map +1 -1
  350. package/dist/index.js +15 -1
  351. package/dist/index.js.map +1 -1
  352. package/dist/inspector-findings.d.ts.map +1 -1
  353. package/dist/inspector-findings.js +58 -81
  354. package/dist/inspector-findings.js.map +1 -1
  355. package/dist/knowledge-base.d.ts.map +1 -1
  356. package/dist/knowledge-base.js +86 -10
  357. package/dist/knowledge-base.js.map +1 -1
  358. package/dist/local-git-metadata.d.ts +5 -0
  359. package/dist/local-git-metadata.d.ts.map +1 -0
  360. package/dist/local-git-metadata.js +130 -0
  361. package/dist/local-git-metadata.js.map +1 -0
  362. package/dist/multiscan.d.ts +6 -4
  363. package/dist/multiscan.d.ts.map +1 -1
  364. package/dist/multiscan.js +160 -77
  365. package/dist/multiscan.js.map +1 -1
  366. package/dist/native-json-findings.d.ts +2 -1
  367. package/dist/native-json-findings.d.ts.map +1 -1
  368. package/dist/native-json-findings.js +12 -2
  369. package/dist/native-json-findings.js.map +1 -1
  370. package/dist/opengrep-findings.d.ts +1 -0
  371. package/dist/opengrep-findings.d.ts.map +1 -1
  372. package/dist/opengrep-findings.js +49 -31
  373. package/dist/opengrep-findings.js.map +1 -1
  374. package/dist/operation-telemetry.d.ts +104 -0
  375. package/dist/operation-telemetry.d.ts.map +1 -0
  376. package/dist/operation-telemetry.js +293 -0
  377. package/dist/operation-telemetry.js.map +1 -0
  378. package/dist/patch-tui.d.ts.map +1 -1
  379. package/dist/patch-tui.js +90 -35
  380. package/dist/patch-tui.js.map +1 -1
  381. package/dist/plugin-python-probe.d.ts +4 -0
  382. package/dist/plugin-python-probe.d.ts.map +1 -0
  383. package/dist/plugin-python-probe.js +10 -0
  384. package/dist/plugin-python-probe.js.map +1 -0
  385. package/dist/private-finding-import.d.ts +341 -0
  386. package/dist/private-finding-import.d.ts.map +1 -0
  387. package/dist/private-finding-import.js +411 -0
  388. package/dist/private-finding-import.js.map +1 -0
  389. package/dist/project-config.d.ts.map +1 -1
  390. package/dist/project-config.js +2 -2
  391. package/dist/project-config.js.map +1 -1
  392. package/dist/provider-profile.d.ts +11 -3
  393. package/dist/provider-profile.d.ts.map +1 -1
  394. package/dist/provider-profile.js +80 -11
  395. package/dist/provider-profile.js.map +1 -1
  396. package/dist/publication-telemetry.d.ts +45 -0
  397. package/dist/publication-telemetry.d.ts.map +1 -0
  398. package/dist/publication-telemetry.js +50 -0
  399. package/dist/publication-telemetry.js.map +1 -0
  400. package/dist/publication.js +7 -1
  401. package/dist/publication.js.map +1 -1
  402. package/dist/publish.d.ts +4 -0
  403. package/dist/publish.d.ts.map +1 -1
  404. package/dist/publish.js +42 -2
  405. package/dist/publish.js.map +1 -1
  406. package/dist/reader-selection.d.ts +15 -0
  407. package/dist/reader-selection.d.ts.map +1 -0
  408. package/dist/reader-selection.js +89 -0
  409. package/dist/reader-selection.js.map +1 -0
  410. package/dist/record.d.ts +6 -1
  411. package/dist/record.d.ts.map +1 -1
  412. package/dist/record.js +53 -2
  413. package/dist/record.js.map +1 -1
  414. package/dist/remediation.d.ts +3 -1
  415. package/dist/remediation.d.ts.map +1 -1
  416. package/dist/remediation.js +28 -2
  417. package/dist/remediation.js.map +1 -1
  418. package/dist/request-metadata.d.ts +3 -0
  419. package/dist/request-metadata.d.ts.map +1 -1
  420. package/dist/request-metadata.js +9 -0
  421. package/dist/request-metadata.js.map +1 -1
  422. package/dist/result.d.ts +6 -0
  423. package/dist/result.d.ts.map +1 -1
  424. package/dist/result.js +3 -1
  425. package/dist/result.js.map +1 -1
  426. package/dist/retry-windows-rename.d.ts +8 -0
  427. package/dist/retry-windows-rename.d.ts.map +1 -0
  428. package/dist/retry-windows-rename.js +24 -0
  429. package/dist/retry-windows-rename.js.map +1 -0
  430. package/dist/runtime.d.ts +22 -1
  431. package/dist/runtime.d.ts.map +1 -1
  432. package/dist/runtime.js +408 -162
  433. package/dist/runtime.js.map +1 -1
  434. package/dist/saved-scan-bootstrap.d.ts +1 -0
  435. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  436. package/dist/saved-scan-bootstrap.js +18 -15
  437. package/dist/saved-scan-bootstrap.js.map +1 -1
  438. package/dist/scan-activity.d.ts.map +1 -1
  439. package/dist/scan-activity.js +172 -64
  440. package/dist/scan-activity.js.map +1 -1
  441. package/dist/scan-comparison.d.ts +10 -5
  442. package/dist/scan-comparison.d.ts.map +1 -1
  443. package/dist/scan-comparison.js +68 -25
  444. package/dist/scan-comparison.js.map +1 -1
  445. package/dist/scan-dashboard.d.ts +7 -6
  446. package/dist/scan-dashboard.d.ts.map +1 -1
  447. package/dist/scan-dashboard.js +91 -79
  448. package/dist/scan-dashboard.js.map +1 -1
  449. package/dist/scan-executor.d.ts +12 -1
  450. package/dist/scan-executor.d.ts.map +1 -1
  451. package/dist/scan-executor.js +22 -2
  452. package/dist/scan-executor.js.map +1 -1
  453. package/dist/scan-history-renderer.d.ts.map +1 -1
  454. package/dist/scan-history-renderer.js +31 -28
  455. package/dist/scan-history-renderer.js.map +1 -1
  456. package/dist/scan-logs.d.ts +12 -0
  457. package/dist/scan-logs.d.ts.map +1 -1
  458. package/dist/scan-logs.js +106 -77
  459. package/dist/scan-logs.js.map +1 -1
  460. package/dist/scan-measurement.d.ts +26 -0
  461. package/dist/scan-measurement.d.ts.map +1 -0
  462. package/dist/scan-measurement.js +77 -0
  463. package/dist/scan-measurement.js.map +1 -0
  464. package/dist/scan-progress.d.ts +1 -0
  465. package/dist/scan-progress.d.ts.map +1 -1
  466. package/dist/scan-progress.js +3 -0
  467. package/dist/scan-progress.js.map +1 -1
  468. package/dist/scan-sessions.d.ts.map +1 -1
  469. package/dist/scan-sessions.js +4 -1
  470. package/dist/scan-sessions.js.map +1 -1
  471. package/dist/scan-settings.d.ts +1 -1
  472. package/dist/scan-settings.d.ts.map +1 -1
  473. package/dist/scan-settings.js +1 -24
  474. package/dist/scan-settings.js.map +1 -1
  475. package/dist/scanner-import.d.ts +64 -6
  476. package/dist/scanner-import.d.ts.map +1 -1
  477. package/dist/scanner-import.js +406 -48
  478. package/dist/scanner-import.js.map +1 -1
  479. package/dist/scanner-repository-url.d.ts +17 -0
  480. package/dist/scanner-repository-url.d.ts.map +1 -0
  481. package/dist/scanner-repository-url.js +71 -0
  482. package/dist/scanner-repository-url.js.map +1 -0
  483. package/dist/security-policy.d.ts +1 -1
  484. package/dist/security-policy.d.ts.map +1 -1
  485. package/dist/security-policy.js.map +1 -1
  486. package/dist/semgrep-findings.d.ts +6 -3
  487. package/dist/semgrep-findings.d.ts.map +1 -1
  488. package/dist/semgrep-findings.js +124 -88
  489. package/dist/semgrep-findings.js.map +1 -1
  490. package/dist/semgrep-guardian-findings.d.ts +38 -0
  491. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  492. package/dist/semgrep-guardian-findings.js +165 -0
  493. package/dist/semgrep-guardian-findings.js.map +1 -0
  494. package/dist/semgrep-platform-collector.d.ts +26 -0
  495. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  496. package/dist/semgrep-platform-collector.js +108 -0
  497. package/dist/semgrep-platform-collector.js.map +1 -0
  498. package/dist/semgrep-platform-findings.d.ts +213 -0
  499. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  500. package/dist/semgrep-platform-findings.js +1078 -0
  501. package/dist/semgrep-platform-findings.js.map +1 -0
  502. package/dist/semgrep-platform-v1.d.ts +6 -0
  503. package/dist/semgrep-platform-v1.d.ts.map +1 -0
  504. package/dist/semgrep-platform-v1.js +83 -0
  505. package/dist/semgrep-platform-v1.js.map +1 -0
  506. package/dist/server/api.d.ts +1 -1
  507. package/dist/server/api.d.ts.map +1 -1
  508. package/dist/server/api.js.map +1 -1
  509. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  510. package/dist/server/embedding-tokenizer.d.ts +2 -0
  511. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  512. package/dist/server/embedding-tokenizer.js +322 -0
  513. package/dist/server/embedding-tokenizer.js.map +6 -0
  514. package/dist/server/embeddings.d.ts +16 -2
  515. package/dist/server/embeddings.d.ts.map +1 -1
  516. package/dist/server/embeddings.js +35 -5
  517. package/dist/server/embeddings.js.map +1 -1
  518. package/dist/session-lines.d.ts +5 -0
  519. package/dist/session-lines.d.ts.map +1 -0
  520. package/dist/session-lines.js +60 -0
  521. package/dist/session-lines.js.map +1 -0
  522. package/dist/severity-review.d.ts +3 -1
  523. package/dist/severity-review.d.ts.map +1 -1
  524. package/dist/severity-review.js +3 -2
  525. package/dist/severity-review.js.map +1 -1
  526. package/dist/severity-rubric.d.ts +20 -0
  527. package/dist/severity-rubric.d.ts.map +1 -0
  528. package/dist/severity-rubric.js +73 -0
  529. package/dist/severity-rubric.js.map +1 -0
  530. package/dist/severity-store.js +15 -5
  531. package/dist/severity-store.js.map +1 -1
  532. package/dist/skill-authentication.d.ts +1 -0
  533. package/dist/skill-authentication.d.ts.map +1 -1
  534. package/dist/skill-authentication.js +1 -0
  535. package/dist/skill-authentication.js.map +1 -1
  536. package/dist/snyk-findings.d.ts +7 -2
  537. package/dist/snyk-findings.d.ts.map +1 -1
  538. package/dist/snyk-findings.js +108 -84
  539. package/dist/snyk-findings.js.map +1 -1
  540. package/dist/snyk-rest-findings.d.ts +76 -0
  541. package/dist/snyk-rest-findings.d.ts.map +1 -0
  542. package/dist/snyk-rest-findings.js +1051 -0
  543. package/dist/snyk-rest-findings.js.map +1 -0
  544. package/dist/snyk-rest-v1.d.ts +28 -0
  545. package/dist/snyk-rest-v1.d.ts.map +1 -0
  546. package/dist/snyk-rest-v1.js +132 -0
  547. package/dist/snyk-rest-v1.js.map +1 -0
  548. package/dist/snyk-token-origin.d.ts +4 -0
  549. package/dist/snyk-token-origin.d.ts.map +1 -0
  550. package/dist/snyk-token-origin.js +82 -0
  551. package/dist/snyk-token-origin.js.map +1 -0
  552. package/dist/sonar-collector.d.ts +16 -0
  553. package/dist/sonar-collector.d.ts.map +1 -0
  554. package/dist/sonar-collector.js +380 -0
  555. package/dist/sonar-collector.js.map +1 -0
  556. package/dist/sonar-findings.d.ts +49 -0
  557. package/dist/sonar-findings.d.ts.map +1 -0
  558. package/dist/sonar-findings.js +288 -0
  559. package/dist/sonar-findings.js.map +1 -0
  560. package/dist/sonar-import.d.ts +111 -0
  561. package/dist/sonar-import.d.ts.map +1 -0
  562. package/dist/sonar-import.js +277 -0
  563. package/dist/sonar-import.js.map +1 -0
  564. package/dist/suggest-owners.d.ts.map +1 -1
  565. package/dist/suggest-owners.js +2 -1
  566. package/dist/suggest-owners.js.map +1 -1
  567. package/dist/target-drift.d.ts +9 -0
  568. package/dist/target-drift.d.ts.map +1 -0
  569. package/dist/target-drift.js +27 -0
  570. package/dist/target-drift.js.map +1 -0
  571. package/dist/targets.d.ts +5 -0
  572. package/dist/targets.d.ts.map +1 -1
  573. package/dist/targets.js +73 -31
  574. package/dist/targets.js.map +1 -1
  575. package/dist/tenable-findings.d.ts +9 -0
  576. package/dist/tenable-findings.d.ts.map +1 -0
  577. package/dist/tenable-findings.js +122 -0
  578. package/dist/tenable-findings.js.map +1 -0
  579. package/dist/terminal-columns.d.ts +4 -0
  580. package/dist/terminal-columns.d.ts.map +1 -0
  581. package/dist/terminal-columns.js +19 -0
  582. package/dist/terminal-columns.js.map +1 -0
  583. package/dist/terminal-stream.d.ts +13 -0
  584. package/dist/terminal-stream.d.ts.map +1 -0
  585. package/dist/terminal-stream.js +35 -0
  586. package/dist/terminal-stream.js.map +1 -0
  587. package/dist/trivy-findings.d.ts +19 -0
  588. package/dist/trivy-findings.d.ts.map +1 -0
  589. package/dist/trivy-findings.js +435 -0
  590. package/dist/trivy-findings.js.map +1 -0
  591. package/dist/trivy-import.d.ts +19 -0
  592. package/dist/trivy-import.d.ts.map +1 -0
  593. package/dist/trivy-import.js +151 -0
  594. package/dist/trivy-import.js.map +1 -0
  595. package/dist/validation-records.d.ts +0 -3
  596. package/dist/validation-records.d.ts.map +1 -1
  597. package/dist/validation-records.js +1 -17
  598. package/dist/validation-records.js.map +1 -1
  599. package/dist/veracode-findings.d.ts +9 -0
  600. package/dist/veracode-findings.d.ts.map +1 -0
  601. package/dist/veracode-findings.js +409 -0
  602. package/dist/veracode-findings.js.map +1 -0
  603. package/dist/vertex-pricing.d.ts +8 -0
  604. package/dist/vertex-pricing.d.ts.map +1 -0
  605. package/dist/vertex-pricing.js +20 -0
  606. package/dist/vertex-pricing.js.map +1 -0
  607. package/dist/windows-path.d.ts +1 -0
  608. package/dist/windows-path.d.ts.map +1 -1
  609. package/dist/windows-path.js +27 -1
  610. package/dist/windows-path.js.map +1 -1
  611. package/dist/wiz-csv.d.ts +2 -2
  612. package/dist/wiz-csv.d.ts.map +1 -1
  613. package/dist/wiz-csv.js +1 -3
  614. package/dist/wiz-csv.js.map +1 -1
  615. package/dist/wiz-findings.d.ts +14 -2
  616. package/dist/wiz-findings.d.ts.map +1 -1
  617. package/dist/wiz-findings.js +143 -50
  618. package/dist/wiz-findings.js.map +1 -1
  619. package/docs/classify-severity-records.md +28 -13
  620. package/docs/cli.md +623 -843
  621. package/docs/dedupe-records.md +54 -24
  622. package/docs/findings-service.md +87 -47
  623. package/docs/hosted-remediation.md +14 -7
  624. package/docs/hosted-scans.md +64 -41
  625. package/docs/telemetry.md +236 -0
  626. package/docs/validate-records.md +78 -44
  627. package/package.json +19 -17
  628. package/schemas/external-findings.schema.json +14 -1
  629. package/schemas/hosted-scan-v2.fixture.json +16 -1
  630. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  631. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  632. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  633. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  634. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  635. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  636. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  637. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  638. package/dist/deduplication/records-protocol.d.ts +0 -4
  639. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  640. package/dist/deduplication/records-protocol.js +0 -49
  641. package/dist/deduplication/records-protocol.js.map +0 -1
  642. package/dist/external-imports-feature.d.ts +0 -6
  643. package/dist/external-imports-feature.d.ts.map +0 -1
  644. package/dist/external-imports-feature.js +0 -51
  645. package/dist/external-imports-feature.js.map +0 -1
  646. package/dist/finding-normalization.d.ts +0 -5
  647. package/dist/finding-normalization.d.ts.map +0 -1
  648. package/dist/finding-normalization.js +0 -120
  649. package/dist/finding-normalization.js.map +0 -1
package/dist/runtime.js CHANGED
@@ -1,6 +1,7 @@
1
- import { forwardExternalImportSetting } from "./external-imports-feature.js";
2
1
  import { executablePathForSpawn } from "./executable-path.js";
2
+ import { retryWindowsRename } from "./retry-windows-rename.js";
3
3
  export { executablePathForSpawn } from "./executable-path.js";
4
+ import { PLUGIN_PYTHON_PROBE, PLUGIN_PYTHON_PROBE_TIMEOUT_MS, PLUGIN_PYTHON_READY, } from "./plugin-python-probe.js";
4
5
  import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
5
6
  import { gitProtectionRoots } from "./targets.js";
6
7
  import { isNonEmptyString, notify } from "./value.js";
@@ -21,7 +22,7 @@ import { parse } from "smol-toml";
21
22
  import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
22
23
  import { isRecord } from "./record.js";
23
24
  import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
24
- import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
25
+ import { isWindowsUnsafePathComponent, sqliteFilename, windowsUnsafePathComponent, } from "./windows-path.js";
25
26
  const execFile = promisify(execFileCallback);
26
27
  export const MARKETPLACE_NAME = "codex-security-sdk";
27
28
  export const PLUGIN_NAME = "codex-security";
@@ -56,6 +57,7 @@ const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
56
57
  "OPENROUTER_API_KEY",
57
58
  "FIREWORKS_API_KEY",
58
59
  "CHEAPER_INFERENCE_API_KEY",
60
+ "HF_TOKEN",
59
61
  ]);
60
62
  const PREPARE_SCAN_ARTIFACT_RESTORER_PROGRAM = `
61
63
  from pathlib import Path
@@ -139,7 +141,11 @@ export async function prepareCodexSecurityCredentialHome(environment = process.e
139
141
  catch (error) {
140
142
  if (error instanceof OutputDirectoryError)
141
143
  throw error;
142
- throw new OutputDirectoryError(`Unable to prepare the Codex Security credential home: ${path}`, { cause: error });
144
+ const code = nodeErrorCode(error);
145
+ const recovery = code === "EACCES" || code === "EPERM" || code === "EROFS"
146
+ ? "\nCheck permissions or set CODEX_SECURITY_STATE_DIR to a private, writable directory outside the repository."
147
+ : "";
148
+ throw new OutputDirectoryError(`Unable to prepare the Codex Security credential home: ${path}\n${errorMessage(error)}${recovery}`, { cause: error });
143
149
  }
144
150
  }
145
151
  /**
@@ -203,7 +209,7 @@ export async function preparePolicyOutputDirectory(path, options = {}) {
203
209
  }
204
210
  await requirePrivateDirectory(metadata, path, "policy output directory", options);
205
211
  }
206
- async function requirePrivateDirectory(metadata, path, description, options) {
212
+ export async function requirePrivateDirectory(metadata, path, description, options = {}) {
207
213
  if ((options.platform ?? process.platform) !== "win32") {
208
214
  requirePrivateOutputDirectory(metadata, path);
209
215
  return;
@@ -277,6 +283,7 @@ const WINDOWS_PRINCIPAL_ALIASES = {
277
283
  HA: "S-1-5-32-578",
278
284
  AA: "S-1-5-32-579",
279
285
  };
286
+ const WINDOWS_ACCOUNT_SID = /^S-1-5-21-(?:\d+-){3}\d+$/u;
280
287
  const WINDOWS_SID = /^S-1-(?:\d+-)*\d+$/u;
281
288
  const WINDOWS_GUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
282
289
  const WINDOWS_SDDL_SID = "(?:S-1-(?:\\d+-)*\\d+|[A-Z]{2})";
@@ -363,7 +370,10 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
363
370
  if (type === "A" || type === "OA" || type === "XA" || type === "ZA") {
364
371
  if (!trustedPrincipal(principal)) {
365
372
  if (options.scope !== "ancestor" ||
366
- windowsAceAllowsAncestorReplacement(rights, inheritanceFlags)) {
373
+ // OWNER RIGHTS applies to the owner already verified above. Every
374
+ // descendant is inspected with its own security descriptor.
375
+ (principal !== WINDOWS_OWNER_RIGHTS_SID &&
376
+ windowsAceAllowsAncestorReplacement(rights, inheritanceFlags))) {
367
377
  untrustedPrincipals.add(principal);
368
378
  }
369
379
  }
@@ -383,7 +393,9 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
383
393
  }
384
394
  }
385
395
  }
386
- else {
396
+ else if (principal === currentUserSid ||
397
+ !WINDOWS_ACCOUNT_SID.test(principal) ||
398
+ (options.currentGroupSids?.has(principal) ?? true)) {
387
399
  deniedPrincipals.add(principal);
388
400
  }
389
401
  remaining = rest;
@@ -525,13 +537,36 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
525
537
  throw new WindowsCredentialDescendantsChangedError("Windows credential descendants changed during ACL inspection");
526
538
  }
527
539
  }
540
+ // win32.parse stops at the UNC marker for extended-length share paths.
541
+ const WINDOWS_CREDENTIAL_UNC_ROOT = /^[\\/]{2}[?.][\\/]UNC[\\/][^\\/]+[\\/][^\\/]+[\\/]?/iu;
542
+ function windowsCredentialRootLength(path) {
543
+ const root = WINDOWS_CREDENTIAL_UNC_ROOT.exec(path)?.[0] ?? win32.parse(path).root;
544
+ if (win32.isAbsolute(path) && win32.relative(root, path) === "") {
545
+ throw new Error("A private Windows directory must be below a volume or share root");
546
+ }
547
+ return root.length;
548
+ }
549
+ export function windowsCredentialAncestorAclScript(path) {
550
+ const rootLength = windowsCredentialRootLength(path);
551
+ return [
552
+ "$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
553
+ // Stop at the drive or UNC share root, then inspect the outermost ancestor first.
554
+ `$ancestors = @(while ($path.Length -gt ${rootLength}) { $parent = Microsoft.PowerShell.Management\\Split-Path -Path $path -Parent; if (-not $parent -or $parent -eq $path) { break }; $parent; $path = $parent })`,
555
+ "for ($i = $ancestors.Count - 1; $i -ge 0; $i--) { Write-CredentialAcl $ancestors[$i] }",
556
+ ].join("\n");
557
+ }
528
558
  export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
559
+ const rootLength = windowsCredentialRootLength(path);
529
560
  const ancestors = [];
530
- for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
561
+ let ancestor = win32.dirname(path);
562
+ while (true) {
531
563
  ancestors.push(ancestor);
532
- if (ancestor === dirname(ancestor))
564
+ const parent = win32.dirname(ancestor);
565
+ if (ancestor.length <= rootLength || ancestor === parent)
533
566
  break;
567
+ ancestor = parent;
534
568
  }
569
+ ancestors.reverse();
535
570
  for (let attempt = 0; attempt < 3; attempt += 1) {
536
571
  let home;
537
572
  let descendantsArePrivate = true;
@@ -557,6 +592,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
557
592
  const ancestorPath = ancestors[index];
558
593
  try {
559
594
  const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
595
+ currentGroupSids: options.currentGroupSids,
560
596
  resolvedAliases: options.resolvedAliases,
561
597
  scope: "ancestor",
562
598
  });
@@ -565,9 +601,12 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
565
601
  }
566
602
  }
567
603
  catch (error) {
568
- const guidance = ancestorPath === dirname(ancestorPath)
569
- ? "This volume root is unsupported. Choose a location on a volume with trusted ancestry; another directory on the same volume will not resolve this."
570
- : "Choose a location outside this ancestor with trusted ownership and permissions.";
604
+ let guidance = "Choose a location outside this ancestor with trusted ownership and permissions.";
605
+ if (index === 0) {
606
+ guidance = WINDOWS_CREDENTIAL_UNC_ROOT.test(win32.toNamespacedPath(ancestorPath))
607
+ ? "This share root is unsupported. Choose a location outside this share with trusted ownership and permissions."
608
+ : "This volume root is unsupported. Choose a location on a volume with trusted ancestry; another directory on the same volume will not resolve this.";
609
+ }
571
610
  throw new Error(`Windows private-directory ancestor could not be trusted: ${ancestorPath}. ${errorMessage(error)}. ${guidance}`, { cause: error });
572
611
  }
573
612
  return;
@@ -575,6 +614,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
575
614
  if (index === ancestors.length) {
576
615
  try {
577
616
  home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
617
+ currentGroupSids: options.currentGroupSids,
578
618
  resolvedAliases: options.resolvedAliases,
579
619
  });
580
620
  }
@@ -587,6 +627,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
587
627
  return;
588
628
  }
589
629
  const descendant = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
630
+ currentGroupSids: options.currentGroupSids,
590
631
  resolvedAliases: options.resolvedAliases,
591
632
  scope: "file",
592
633
  });
@@ -614,16 +655,45 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
614
655
  }
615
656
  throw new Error("Windows credential descendants could not be verified");
616
657
  }
658
+ /** A file server may add its own groups to the client's token. */
659
+ export async function isLocalWindowsCredentialVolume(path, readDriveType) {
660
+ const drive = /^\\\\[?.]\\([A-Z]:)\\/iu.exec(win32.toNamespacedPath(path))?.[1];
661
+ if (!drive)
662
+ return false;
663
+ // Win32_LogicalDisk reports removable, local disk, and RAM disk as 2, 3, 6.
664
+ return ["2", "3", "6"].includes((await readDriveType(drive)).trim());
665
+ }
666
+ /** Keep every token group, including groups used only for deny ACEs. */
667
+ export function parseWindowsTokenGroupSids(output) {
668
+ const groups = new Set();
669
+ for (const row of output.trim().split(/\r?\n/u)) {
670
+ const sid = /^"(?:[^"]|"")*","(?:[^"]|"")*","(S-1-(?:\d+-)*\d+)","(?:[^"]|"")*"$/u.exec(row)?.[1];
671
+ if (!sid)
672
+ throw new Error("Unable to identify Windows token group SIDs");
673
+ groups.add(sid);
674
+ }
675
+ return groups;
676
+ }
617
677
  async function secureWindowsCredentialHome(path) {
678
+ const ancestorAclScript = windowsCredentialAncestorAclScript(path);
679
+ const treePath = win32.toNamespacedPath(path);
618
680
  const systemRoot = process.env["SystemRoot"] ?? "C:\\Windows";
619
681
  const systemDirectory = join(systemRoot, "System32");
620
- const powershell = join(systemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
682
+ const powershellDirectory = join(systemDirectory, "WindowsPowerShell", "v1.0");
683
+ const powershell = join(powershellDirectory, "powershell.exe");
684
+ const powershellArgs = [
685
+ "-NoLogo",
686
+ "-NoProfile",
687
+ "-NonInteractive",
688
+ "-Command",
689
+ ];
621
690
  const inheritedEnvironment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "PSMODULEPATH"));
622
691
  const processOptions = {
623
692
  env: {
624
693
  ...inheritedEnvironment,
625
694
  CODEX_SECURITY_CREDENTIAL_ACL_PATH: path,
626
- PSModulePath: join(systemDirectory, "WindowsPowerShell", "v1.0", "Modules"),
695
+ CODEX_SECURITY_CREDENTIAL_TREE_PATH: treePath,
696
+ PSModulePath: join(powershellDirectory, "Modules"),
627
697
  },
628
698
  encoding: "utf8",
629
699
  windowsHide: true,
@@ -641,31 +711,47 @@ async function secureWindowsCredentialHome(path) {
641
711
  const script = [
642
712
  "$ErrorActionPreference = 'Stop'",
643
713
  "$script:descriptorCount = 0",
644
- "function Write-CredentialAcl($path) { $descriptor = Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $path | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl; if (-not $descriptor) { throw 'Windows credential ACL could not be verified' }; $script:descriptorCount += 1; $descriptor }",
714
+ "function Write-CredentialAcl($path) {",
715
+ " $descriptors = @(Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $path | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl)",
716
+ " if ($descriptors.Count -ne @($path).Count) { throw 'Windows credential ACL could not be verified' }",
717
+ " foreach ($descriptor in $descriptors) { if (-not $descriptor) { throw 'Windows credential ACL could not be verified' }; $script:descriptorCount += 1; $descriptor }",
718
+ "}",
645
719
  "function Read-CredentialDescendants($path) {",
646
720
  " try { $entries = @(Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $path -Force) } catch {",
647
721
  // A child can disappear while an existing directory is being enumerated.
648
722
  // Retry that incomplete listing before accepting a vanished descendant.
649
723
  ` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetChildItemCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
650
- " if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
724
+ " if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
651
725
  " throw",
652
726
  " }",
653
- " foreach ($entry in $entries) {",
727
+ " $children = @(foreach ($entry in $entries) {",
654
728
  " if (($entry.Attributes -band 1024) -and ($entry.LinkType -in @('SymbolicLink', 'Junction'))) { throw 'Windows credential home contains a symbolic link or junction' }",
655
729
  " if ($entry.PSObject.TypeNames -notcontains 'System.IO.DirectoryInfo' -and $entry.PSObject.TypeNames -notcontains 'System.IO.FileInfo') { throw 'Windows credential home contains an unsafe entry' }",
656
- " try { Write-CredentialAcl $entry.FullName } catch {",
657
- // A descendant can disappear inside Get-Acl after it was enumerated.
658
- ` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand' -or $_.FullyQualifiedErrorId -eq 'GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
659
- " if ($_.FullyQualifiedErrorId -like 'GetAcl_PathNotFound,*') { continue }",
660
- " throw",
730
+ // Keep the extended-length path when Windows PowerShell returns child names.
731
+ ' "$path\\$($entry.Name)"',
732
+ " })",
733
+ " if ($children.Count -eq 0) { return }",
734
+ " try { Write-CredentialAcl $children } catch {",
735
+ // A vanished path is the only reason to retry the batch one child at a time.
736
+ " if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
737
+ " for ($i = 0; $i -lt $children.Count; $i++) {",
738
+ " try { Write-CredentialAcl $children[$i] } catch {",
739
+ " if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
740
+ " $children[$i] = $null",
741
+ " }",
661
742
  " }",
662
- " if ($entry.PSIsContainer) { Read-CredentialDescendants $entry.FullName }",
743
+ " }",
744
+ " for ($i = 0; $i -lt $children.Count; $i++) {",
745
+ " if ($children[$i] -and $entries[$i].PSIsContainer) { Read-CredentialDescendants $children[$i] }",
663
746
  " }",
664
747
  "}",
665
- "$path = $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
666
- "while ($true) { $parent = Microsoft.PowerShell.Management\\Split-Path -Path $path -Parent; if (-not $parent -or $parent -eq $path) { break }; Write-CredentialAcl $parent; $path = $parent }",
748
+ ancestorAclScript,
667
749
  "Write-CredentialAcl $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
668
- "Read-CredentialDescendants $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
750
+ "try { Read-CredentialDescendants $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH } catch {",
751
+ // Either a batch or a single-child Get-Acl may report an incomplete listing.
752
+ ` if ($_.FullyQualifiedErrorId -in @('System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand', 'GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand')) { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
753
+ " throw",
754
+ "}",
669
755
  `"${WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX}$script:descriptorCount"`,
670
756
  ].join("\n");
671
757
  const resolvePrincipalScript = [
@@ -674,31 +760,40 @@ async function secureWindowsCredentialHome(path) {
674
760
  "Microsoft.PowerShell.Utility\\ConvertFrom-SddlString -Sddl $descriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty RawDescriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Owner | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Value",
675
761
  ].join("; ");
676
762
  const resolvedAliases = {};
763
+ function requireNumericSid(value) {
764
+ if (!WINDOWS_SID.test(value))
765
+ throw new Error("Windows credential ACL contains an unresolvable identity");
766
+ return value;
767
+ }
677
768
  const resolvePrincipal = async (principal) => {
678
769
  if (!/^[A-Z]{2}$/u.test(principal) ||
679
770
  WINDOWS_PRINCIPAL_ALIASES[principal] !== undefined ||
680
771
  resolvedAliases[principal] !== undefined) {
681
772
  return;
682
773
  }
683
- const resolved = await execFile(powershell, [
684
- "-NoLogo",
685
- "-NoProfile",
686
- "-NonInteractive",
687
- "-Command",
688
- resolvePrincipalScript,
689
- ], {
774
+ const resolved = await execFile(powershell, [...powershellArgs, resolvePrincipalScript], {
690
775
  ...processOptions,
691
776
  env: {
692
777
  ...processOptions.env,
693
778
  CODEX_SECURITY_CREDENTIAL_PRINCIPAL: principal,
694
779
  },
695
780
  });
696
- const numeric = resolved.stdout.trim();
697
- if (!WINDOWS_SID.test(numeric)) {
698
- throw new Error("Windows credential ACL contains an unresolvable identity");
699
- }
700
- resolvedAliases[principal] = numeric;
781
+ resolvedAliases[principal] = requireNumericSid(resolved.stdout.trim());
701
782
  };
783
+ const loadLocalGroupSids = async () => {
784
+ const local = await isLocalWindowsCredentialVolume(treePath, async (drive) => {
785
+ const volume = await execFile(powershell, [
786
+ ...powershellArgs,
787
+ `$ErrorActionPreference = 'Stop'; (CimCmdlets\\Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = '${drive}'").DriveType`,
788
+ ], processOptions);
789
+ return volume.stdout;
790
+ });
791
+ if (!local)
792
+ return null;
793
+ const groups = await execFile(join(systemDirectory, "whoami.exe"), ["/groups", "/fo", "csv", "/nh"], processOptions);
794
+ return parseWindowsTokenGroupSids(groups.stdout);
795
+ };
796
+ let currentGroupSids;
702
797
  const resolveDescriptorAliases = async (descriptor) => {
703
798
  const header = WINDOWS_SECURITY_DESCRIPTOR.exec(descriptor.trim());
704
799
  if (header === null)
@@ -707,9 +802,18 @@ async function secureWindowsCredentialHome(path) {
707
802
  let remaining = header[3];
708
803
  while (remaining.startsWith("(")) {
709
804
  const { rule, rest } = windowsSecurityDescriptorRule(remaining);
710
- const principal = rule.split(";")[5];
711
- if (principal !== undefined)
805
+ const fields = rule.split(";");
806
+ const principal = fields[5];
807
+ if (principal !== undefined) {
712
808
  await resolvePrincipal(principal);
809
+ const trustee = resolvedAliases[principal] ?? principal;
810
+ if (currentGroupSids === undefined &&
811
+ ["D", "OD", "XD"].includes(fields[0]) &&
812
+ trustee !== sid &&
813
+ WINDOWS_ACCOUNT_SID.test(trustee)) {
814
+ currentGroupSids = await loadLocalGroupSids();
815
+ }
816
+ }
713
817
  remaining = rest;
714
818
  }
715
819
  };
@@ -717,25 +821,19 @@ async function secureWindowsCredentialHome(path) {
717
821
  const readAcl = async () => {
718
822
  const snapshot = await inspectWindowsCredentialAclSnapshot(path, sid, {
719
823
  command: powershell,
720
- args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script],
824
+ args: [...powershellArgs, script],
721
825
  environment: processOptions.env,
826
+ get currentGroupSids() {
827
+ return currentGroupSids ?? undefined;
828
+ },
722
829
  resolvedAliases,
723
830
  resolveDescriptorAliases,
724
831
  });
725
832
  descendantsArePrivate = snapshot.descendantsArePrivate;
726
833
  return snapshot.home;
727
834
  };
728
- const icacls = join(systemDirectory, "icacls.exe");
729
- const installTrustedAcl = async (target = path) => {
730
- await execFile(icacls, [
731
- target,
732
- "/inheritance:r",
733
- "/grant:r",
734
- `*${sid}:(OI)(CI)F`,
735
- `*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`,
736
- `*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`,
737
- ], processOptions);
738
- };
835
+ const icacls = (target, ...args) => execFile(join(systemDirectory, "icacls.exe"), [target, ...args], processOptions);
836
+ const installTrustedAcl = () => icacls(path, "/inheritance:r", "/grant:r", `*${sid}:(OI)(CI)F`, `*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`, `*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`);
739
837
  let existing;
740
838
  for (let attempt = 0; existing === undefined && attempt < 3; attempt += 1) {
741
839
  try {
@@ -743,7 +841,7 @@ async function secureWindowsCredentialHome(path) {
743
841
  }
744
842
  catch (error) {
745
843
  if (error instanceof RepairableWindowsCredentialOwnerError) {
746
- await execFile(icacls, [path, "/setowner", `*${sid}`], processOptions);
844
+ await icacls(path, "/setowner", `*${sid}`);
747
845
  }
748
846
  else if (error instanceof RepairableWindowsCredentialAclError) {
749
847
  await installTrustedAcl();
@@ -759,7 +857,7 @@ async function secureWindowsCredentialHome(path) {
759
857
  if (existing.grantsCurrentUserAccess &&
760
858
  existing.untrustedPrincipals.length === 0 &&
761
859
  !existing.protected) {
762
- await execFile(icacls, [path, "/inheritance:d"], processOptions);
860
+ await icacls(path, "/inheritance:d");
763
861
  existing = await readAcl();
764
862
  }
765
863
  let verified = existing;
@@ -768,17 +866,12 @@ async function secureWindowsCredentialHome(path) {
768
866
  verified.untrustedPrincipals.length !== 0) {
769
867
  await installTrustedAcl();
770
868
  verified = await readAcl();
771
- for (const principal of verified.untrustedPrincipals) {
772
- if (!WINDOWS_SID.test(principal)) {
773
- throw new Error("Windows credential ACL contains an unresolvable identity");
774
- }
775
- await execFile(icacls, [path, "/remove:g", `*${principal}`], processOptions);
776
- }
777
- for (const principal of verified.deniedPrincipals) {
778
- if (!WINDOWS_SID.test(principal)) {
779
- throw new Error("Windows credential ACL contains an unresolvable identity");
780
- }
781
- await execFile(icacls, [path, "/remove:d", `*${principal}`], processOptions);
869
+ for (const [remove, principals] of [
870
+ ["/remove:g", verified.untrustedPrincipals],
871
+ ["/remove:d", verified.deniedPrincipals],
872
+ ]) {
873
+ for (const principal of principals)
874
+ await icacls(path, remove, `*${requireNumericSid(principal)}`);
782
875
  }
783
876
  if (verified.untrustedPrincipals.length !== 0 ||
784
877
  verified.deniedPrincipals.length !== 0) {
@@ -795,13 +888,32 @@ async function secureWindowsCredentialHome(path) {
795
888
  throw new Error("Windows credential ACL grants access to another identity");
796
889
  }
797
890
  if (!descendantsArePrivate) {
798
- await execFile(icacls, [join(path, "*"), "/reset", "/t", "/q"], processOptions);
891
+ await icacls(join(treePath, "*"), "/reset", "/t", "/q");
799
892
  await readAcl();
800
893
  if (!descendantsArePrivate) {
801
894
  throw new Error("Windows credential descendants remain accessible");
802
895
  }
803
896
  }
804
897
  }
898
+ export function sqliteDatabaseOpener(access = "read-write") {
899
+ const require = createRequire(import.meta.url);
900
+ const bun = process.versions["bun"] !== undefined;
901
+ const Database = (bun ? require("bun:sqlite").Database : require("node:sqlite").DatabaseSync);
902
+ return (path) => {
903
+ const filename = sqliteFilename(path);
904
+ if (access === "read-write")
905
+ return new Database(filename);
906
+ // Apple's SQLite requires write access to initialize missing WAL sidecars.
907
+ // The history reader sets PRAGMA query_only on this existing-file connection.
908
+ return new Database(filename, bun
909
+ ? {
910
+ readonly: process.platform !== "darwin",
911
+ readwrite: process.platform === "darwin",
912
+ create: false,
913
+ }
914
+ : { readOnly: true });
915
+ };
916
+ }
805
917
  export async function withCredentialHomeLock(codexHome, operation, signal) {
806
918
  const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
807
919
  try {
@@ -824,17 +936,11 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
824
936
  if (existingDatabaseMetadata !== null) {
825
937
  requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
826
938
  }
827
- const require = createRequire(import.meta.url);
828
- // Both supported runtimes bundle SQLite. Keep the transaction in the process
829
- // doing the protected work, so pausing it cannot expire its lock.
830
- const Database = process.versions["bun"]
831
- ? require("bun:sqlite")
832
- .Database
833
- : require("node:sqlite").DatabaseSync;
939
+ const openDatabase = sqliteDatabaseOpener();
834
940
  // Let SQLite create a missing guard so no separate descriptor can close after
835
941
  // another connection acquires its process-owned POSIX lock. Keep the guard
836
942
  // across releases so every contender locks the same inode.
837
- const database = new Database(databasePath);
943
+ const database = openDatabase(databasePath);
838
944
  let databaseLocked = false;
839
945
  try {
840
946
  // SQLite creates new databases with the process umask. Tighten or repair
@@ -1005,6 +1111,51 @@ async function recoverStaleCredentialHomeLock(lock) {
1005
1111
  await rm(quarantine, { recursive: true, force: true });
1006
1112
  return true;
1007
1113
  }
1114
+ function sameInode(left, right) {
1115
+ return left.dev === right.dev && left.ino === right.ino;
1116
+ }
1117
+ /** Distinguish two hard links from two paths to the same directory entry. */
1118
+ async function hasSeparateAmbientLink(localPath, ambientHome) {
1119
+ try {
1120
+ const local = await lstat(localPath, { bigint: true });
1121
+ if (!local.isFile() || local.nlink < 2n || local.ino === 0n)
1122
+ return false;
1123
+ const ambient = await lstat(join(ambientHome, "auth.json"), {
1124
+ bigint: true,
1125
+ });
1126
+ if (!ambient.isFile() || !sameInode(local, ambient))
1127
+ return false;
1128
+ const [localDir, ambientDir] = await Promise.all([
1129
+ stat(dirname(localPath), { bigint: true }),
1130
+ stat(ambientHome, { bigint: true }),
1131
+ ]);
1132
+ return (localDir.ino !== 0n &&
1133
+ ambientDir.ino !== 0n &&
1134
+ !sameInode(localDir, ambientDir));
1135
+ }
1136
+ catch {
1137
+ // Without a verified second link, leave logout to the configured native store.
1138
+ return false;
1139
+ }
1140
+ }
1141
+ /** Run under the credential-home lock so status cannot reimport the sign-in during logout. */
1142
+ export async function logoutCredentialHome(home, ambientHome, nativeLogout, onLoggedOut) {
1143
+ const localPath = join(home, "auth.json");
1144
+ const shared = await hasSeparateAmbientLink(localPath, ambientHome);
1145
+ const recordLogout = async () => {
1146
+ await setCodexSecurityCredentialLogout(home, true);
1147
+ if (shared)
1148
+ await rm(localPath);
1149
+ onLoggedOut?.();
1150
+ };
1151
+ // Detach before native logout can revoke a shared token, even if native cleanup fails.
1152
+ if (shared)
1153
+ await recordLogout();
1154
+ const status = await nativeLogout();
1155
+ if (!shared && (status === undefined || status === 0))
1156
+ await recordLogout();
1157
+ return status;
1158
+ }
1008
1159
  export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
1009
1160
  await requireSecureCredentialHome(codexHome);
1010
1161
  const marker = join(codexHome, CREDENTIAL_LOGOUT_MARKER);
@@ -1112,7 +1263,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
1112
1263
  }
1113
1264
  export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
1114
1265
  if (isWithin(repository, outputDirectory) ||
1115
- (pathKind === "output" && isWithin(outputDirectory, repository))) {
1266
+ ((pathKind === "output" || pathKind === "state") &&
1267
+ isWithin(outputDirectory, repository))) {
1116
1268
  throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
1117
1269
  }
1118
1270
  }
@@ -1160,20 +1312,24 @@ workbench["main"](before_archive=before_archive)
1160
1312
  export async function runWorkbench(options, args, input) {
1161
1313
  const script = join(options.pluginRoot, "scripts", "workbench_db.py");
1162
1314
  const signal = options.signal;
1315
+ // Explicitly selected external plugins retain their own workbench protocol.
1316
+ const nativeLocalDedupe = args[0] === "local-dedupe" &&
1317
+ (await sameFile(options.pluginRoot, await bundledPluginRoot()));
1163
1318
  const run = async (arguments_, input, archiveHandshake = false) => {
1164
- const native = [
1165
- "database-info",
1166
- "store-findings",
1167
- "list-stored-findings",
1168
- "store-external-findings",
1169
- "list-external-findings",
1170
- "find-potential-duplicates",
1171
- "store-dedupe-groups",
1172
- "list-dedupe-groups",
1173
- "dashboard",
1174
- "severity-classification",
1175
- "read-severity-classification",
1176
- ].includes(arguments_[0] ?? "");
1319
+ const native = nativeLocalDedupe ||
1320
+ [
1321
+ "database-info",
1322
+ "store-findings",
1323
+ "list-stored-findings",
1324
+ "store-external-findings",
1325
+ "list-external-findings",
1326
+ "find-potential-duplicates",
1327
+ "store-dedupe-groups",
1328
+ "list-dedupe-groups",
1329
+ "dashboard",
1330
+ "severity-classification",
1331
+ "read-severity-classification",
1332
+ ].includes(arguments_[0] ?? "");
1177
1333
  const node = native && process.versions["bun"]
1178
1334
  ? await resolveTrustedExecutable("node", options.environment, [
1179
1335
  process.cwd(),
@@ -1198,12 +1354,9 @@ export async function runWorkbench(options, args, input) {
1198
1354
  ? (options.stateDirectory ??
1199
1355
  codexSecurityStateDirectory(options.environment))
1200
1356
  : undefined;
1201
- // Workbench text fields can contain NUL or exceed OS command-line limits.
1202
- const framedArguments = !native;
1203
- let program = archiveHandshake ? ARCHIVE_REGISTRATION_PROGRAM : undefined;
1204
- if (framedArguments)
1205
- program =
1206
- WORKBENCH_ARGUMENTS_PROGRAM + (program ?? WORKBENCH_SCRIPT_PROGRAM);
1357
+ // Validate one JSON document before framing its unchanged source as payload.
1358
+ if (nativeLocalDedupe && input !== undefined)
1359
+ JSON.parse(input);
1207
1360
  const result = await runCodexCommand({ command }, native
1208
1361
  ? [join(options.pluginRoot, "mcp", "helpers.mjs"), ...arguments_]
1209
1362
  : [
@@ -1211,23 +1364,38 @@ export async function runWorkbench(options, args, input) {
1211
1364
  "-X",
1212
1365
  "utf8",
1213
1366
  "-B",
1214
- ...(program === undefined ? [] : ["-c", program]),
1367
+ "-c",
1368
+ WORKBENCH_ARGUMENTS_PROGRAM +
1369
+ (archiveHandshake
1370
+ ? ARCHIVE_REGISTRATION_PROGRAM
1371
+ : WORKBENCH_SCRIPT_PROGRAM),
1215
1372
  script,
1216
- ...(framedArguments ? [] : arguments_),
1217
- ], pluginHelperEnvironment(node?.environment ?? options.environment),
1373
+ ], pluginHelperEnvironment({
1374
+ ...(node?.environment ?? options.environment),
1375
+ // Python's compressed-rollout reader needs the selected Node even when
1376
+ // this SDK was launched by absolute path without Node on PATH.
1377
+ ...(!native &&
1378
+ !process.versions["bun"] &&
1379
+ environmentValue(options.environment, "CODEX_MCP_NODE_PATH") ===
1380
+ undefined
1381
+ ? { CODEX_MCP_NODE_PATH: process.execPath }
1382
+ : {}),
1383
+ }),
1218
1384
  // The SDK owns configuration normalization; the helper receives its resolved location.
1385
+ nativeLocalDedupe
1386
+ ? `{"stateDirectory":${JSON.stringify(stateDirectory)},"payload":${input ?? "null"}}`
1387
+ : native
1388
+ ? JSON.stringify(arguments_[0] === "database-info"
1389
+ ? stateDirectory
1390
+ : {
1391
+ stateDirectory,
1392
+ payload: input === undefined ? undefined : JSON.parse(input),
1393
+ })
1394
+ : input, signal, archiveHandshake,
1395
+ // Frame Python arguments on stdin to preserve NUL and long diagnostics.
1219
1396
  native
1220
- ? JSON.stringify(arguments_[0] === "database-info"
1221
- ? stateDirectory
1222
- : {
1223
- stateDirectory,
1224
- payload: input === undefined ? undefined : JSON.parse(input),
1225
- })
1226
- : input, signal, archiveHandshake,
1227
- // Match native argv's UTF-8 encoding for the private argument frame.
1228
- framedArguments
1229
- ? `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`
1230
- : undefined);
1397
+ ? undefined
1398
+ : `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`);
1231
1399
  if (!result.success) {
1232
1400
  throw new Error(result.stderr.trim() ||
1233
1401
  result.stdout.trim() ||
@@ -1293,8 +1461,9 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
1293
1461
  throw new OutputDirectoryNotEmptyError(path);
1294
1462
  }
1295
1463
  requireOutputDirectoryOwnership(metadata, path);
1296
- await requireSecureOutputAncestry(path);
1297
- const canonical = await realpath(path);
1464
+ const writableLeaf = !archiveExisting ||
1465
+ (process.platform === "win32" && (await readdir(path)).length === 0);
1466
+ const canonical = await checkedOutputPath(path, writableLeaf);
1298
1467
  requireModelSafeOutputDir(canonical);
1299
1468
  return canonical;
1300
1469
  }
@@ -1450,13 +1619,12 @@ export async function prepareScanRegistrationOutput(outputDirectory, repositoryN
1450
1619
  return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
1451
1620
  }
1452
1621
  async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
1453
- if (outputDirectory === undefined) {
1454
- requireModelSafeOutputDir(temporaryRoot);
1455
- requireModelSafeOutputDir(await realpath(temporaryRoot));
1456
- }
1457
1622
  const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
1458
- validateLocation?.(path ?? (await realpath(temporaryRoot)));
1459
1623
  if (path === null) {
1624
+ requireModelSafeOutputDir(temporaryRoot);
1625
+ const canonicalRoot = await realpath(temporaryRoot);
1626
+ requireModelSafeOutputDir(canonicalRoot);
1627
+ validateLocation?.(canonicalRoot);
1460
1628
  const prefix = `codex-security-${safePrefix(repositoryName)}`;
1461
1629
  let created;
1462
1630
  if (process.platform === "win32") {
@@ -1464,11 +1632,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1464
1632
  // Reserve room within NTFS's 255-unit component limit for later archival.
1465
1633
  // The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
1466
1634
  const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
1467
- created = join(temporaryRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
1635
+ created = join(canonicalRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
1468
1636
  await createWindowsOutputDirectory(created, false);
1469
1637
  }
1470
1638
  else {
1471
- created = await mkdtemp(join(temporaryRoot, `${prefix}-`));
1639
+ created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
1472
1640
  }
1473
1641
  try {
1474
1642
  if ((process.umask() & 0o700) !== 0)
@@ -1480,6 +1648,7 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1480
1648
  throw error;
1481
1649
  }
1482
1650
  }
1651
+ validateLocation?.(path);
1483
1652
  let createdRoot;
1484
1653
  try {
1485
1654
  let existing = await lstat(path).catch(nullIfMissingFileError);
@@ -1499,7 +1668,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1499
1668
  if ((process.umask() & 0o700) !== 0)
1500
1669
  await chmod(path, 0o700);
1501
1670
  }
1502
- return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
1671
+ // Registration retains a populated scan for archival. An empty Windows
1672
+ // directory must still satisfy the checks for a writable scan output.
1673
+ const preserveContents = existingOutput === "preserve" &&
1674
+ (process.platform !== "win32" || (await readdir(path)).length !== 0);
1675
+ return await validatePreparedOutputDir(path, validateLocation, preserveContents);
1503
1676
  }
1504
1677
  catch (error) {
1505
1678
  if (createdRoot !== undefined) {
@@ -1512,10 +1685,19 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1512
1685
  });
1513
1686
  }
1514
1687
  }
1688
+ async function windowsOutputBinding() {
1689
+ return createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
1690
+ }
1691
+ export async function requireWindowsOutputPath(path, writableLeaf, retainedDirectory) {
1692
+ const native = await windowsOutputBinding();
1693
+ const error = native.validateWindowsOutputPath(Buffer.from(win32.toNamespacedPath(path), "utf16le"), writableLeaf, retainedDirectory);
1694
+ if (error !== 0)
1695
+ throw new OutputDirectoryError(`Scan output directory or its parent could not be trusted (Windows error ${error}): ${path}`);
1696
+ }
1515
1697
  export async function createWindowsOutputDirectory(path, recursive) {
1516
- const native = createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
1698
+ const native = await windowsOutputBinding();
1517
1699
  const create = async (target) => {
1518
- const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
1700
+ const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"), true);
1519
1701
  let error = createOne();
1520
1702
  let firstCreated;
1521
1703
  if (recursive &&
@@ -1526,8 +1708,10 @@ export async function createWindowsOutputDirectory(path, recursive) {
1526
1708
  }
1527
1709
  if (error === 0)
1528
1710
  return firstCreated ?? target;
1529
- if (recursive && error === 183 && (await stat(target)).isDirectory())
1711
+ if (recursive && error === 183 && (await stat(target)).isDirectory()) {
1712
+ await requireWindowsOutputPath(target, target === path);
1530
1713
  return firstCreated;
1714
+ }
1531
1715
  throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
1532
1716
  };
1533
1717
  return create(path);
@@ -1537,15 +1721,42 @@ export async function validatePreparedOutputDir(path, validateLocation, allowNon
1537
1721
  if (!metadata.isDirectory()) {
1538
1722
  throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
1539
1723
  }
1540
- const canonical = await realpath(path);
1724
+ const canonical = await checkedOutputPath(path, !allowNonempty);
1541
1725
  requireModelSafeOutputDir(canonical);
1542
1726
  validateLocation?.(canonical);
1543
- const entries = await readdir(canonical);
1544
- if (!allowNonempty && entries.length !== 0) {
1727
+ if (!allowNonempty && (await readdir(canonical)).length !== 0) {
1545
1728
  throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
1546
1729
  }
1547
1730
  requireOutputDirectoryOwnership(metadata, path);
1548
- await requireSecureOutputAncestry(canonical);
1731
+ return canonical;
1732
+ }
1733
+ async function checkedOutputPath(path, writableLeaf) {
1734
+ if (process.platform === "win32") {
1735
+ // Keep the selected leaf for the no-follow check, including across an
1736
+ // in-place directory change between lstat and canonicalization.
1737
+ const directory = dirname(path);
1738
+ const parent = await realpath(directory);
1739
+ const selected = join(parent, relative(directory, path));
1740
+ await requireWindowsOutputPath(selected, writableLeaf);
1741
+ const canonical = await realpath(selected);
1742
+ if (canonical === selected)
1743
+ return selected;
1744
+ // Accept a canonical leaf spelling (case or short name) within the checked parent.
1745
+ if (dirname(canonical) === parent) {
1746
+ const [leaf, resolved] = await Promise.all([
1747
+ lstat(selected, { bigint: true }),
1748
+ lstat(canonical, { bigint: true }),
1749
+ ]);
1750
+ if (leaf.isDirectory() && leaf.ino !== 0n && sameInode(leaf, resolved)) {
1751
+ return canonical;
1752
+ }
1753
+ }
1754
+ throw new OutputDirectoryError(`Scan output directory changed during preparation: ${path}`);
1755
+ }
1756
+ await requireSecureOutputAncestry(path);
1757
+ const canonical = await realpath(path);
1758
+ if (canonical !== path)
1759
+ await requireSecureOutputAncestry(canonical);
1549
1760
  return canonical;
1550
1761
  }
1551
1762
  export function requirePrivateOutputDirectory(metadata, path, effectiveUid = process.geteuid?.()) {
@@ -1566,7 +1777,7 @@ export function requireOutputDirectoryOwnership(metadata, path, effectiveUid = p
1566
1777
  /** Reject shared parents whose owner can rename or replace scan output. */
1567
1778
  export async function requireSecureOutputAncestry(path, effectiveUid = process.geteuid?.()) {
1568
1779
  if (process.platform === "win32")
1569
- return;
1780
+ return requireWindowsOutputPath(path);
1570
1781
  let current = dirname(resolve(path));
1571
1782
  while (true) {
1572
1783
  try {
@@ -1701,6 +1912,7 @@ export async function extractPluginZip(archive, destination, signal) {
1701
1912
  const archivePath = resolve(expandHome(archive));
1702
1913
  await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
1703
1914
  const staging = await realpath(await mkdtemp(join(dirname(destination), ".codex-security-plugin-")));
1915
+ let publishingOnWindows = false;
1704
1916
  try {
1705
1917
  throwIfSignalAborted(signal);
1706
1918
  let expandedSize = 0;
@@ -1763,12 +1975,29 @@ export async function extractPluginZip(archive, destination, signal) {
1763
1975
  const pluginRoot = await discoverPluginRoot(staging);
1764
1976
  throwIfSignalAborted(signal);
1765
1977
  const relativeRoot = relative(staging, pluginRoot);
1766
- await rename(staging, destination);
1978
+ if (process.platform === "win32") {
1979
+ publishingOnWindows = true;
1980
+ await retryWindowsRename(async () => {
1981
+ throwIfSignalAborted(signal);
1982
+ if (await lstat(destination).catch(nullIfMissingFileError))
1983
+ throw new Error(`Destination already exists: ${destination}`);
1984
+ await rename(staging, destination);
1985
+ }, undefined, signal);
1986
+ publishingOnWindows = false;
1987
+ }
1988
+ else {
1989
+ await rename(staging, destination);
1990
+ }
1767
1991
  return await validatePluginRoot(join(destination, relativeRoot));
1768
1992
  }
1769
1993
  catch (error) {
1770
- await rm(staging, { recursive: true, force: true }).catch(() => undefined);
1994
+ let cleanupDiagnostic = "";
1995
+ await rm(staging, { recursive: true, force: true }).catch((cleanupError) => {
1996
+ cleanupDiagnostic = `\nCould not remove staging directory ${staging}: ${errorMessage(cleanupError)}`;
1997
+ });
1771
1998
  throwIfSignalAborted(signal);
1999
+ if (publishingOnWindows)
2000
+ throw new PluginBootstrapError(`Could not publish extracted plugin ZIP: ${errorMessage(error)}${cleanupDiagnostic}`, { cause: error });
1772
2001
  if (error instanceof PluginBootstrapError)
1773
2002
  throw error;
1774
2003
  throw new PluginBootstrapError(`Invalid plugin ZIP: ${archivePath}`, {
@@ -2068,9 +2297,18 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
2068
2297
  const previous = await readFile(installRecord, "utf8")
2069
2298
  .then((value) => JSON.parse(value))
2070
2299
  .catch((error) => {
2071
- if (nodeErrorCode(error) === "ENOENT" || error instanceof SyntaxError) {
2300
+ const code = nodeErrorCode(error);
2301
+ if (code === "ENOENT" || error instanceof SyntaxError) {
2072
2302
  return null;
2073
2303
  }
2304
+ if (process.platform === "win32" &&
2305
+ error instanceof Error &&
2306
+ (code === "EACCES" || code === "EPERM")) {
2307
+ // Keep the original system error, including its path, code and syscall.
2308
+ error.message +=
2309
+ " If the SDK created this plugin installation receipt but cannot reopen it, " +
2310
+ "check its read permissions and the permissions new files inherit from the sdk-marketplace directory.";
2311
+ }
2074
2312
  throw error;
2075
2313
  });
2076
2314
  const plugins = configuration["plugins"];
@@ -2226,11 +2464,9 @@ export async function resolvePluginPython(options = {}) {
2226
2464
  if (inherited) {
2227
2465
  return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
2228
2466
  }
2229
- const home = options.homeDirectory ?? homedir();
2230
- const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
2231
- join(home, ".cache");
2232
2467
  const managedRoots = options.managedRuntimeRoots ?? [
2233
- join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
2468
+ join(environmentValue(environment, "XDG_CACHE_HOME", true) ||
2469
+ join(options.homeDirectory ?? homedir(), ".cache"), "codex-runtimes", "codex-primary-runtime"),
2234
2470
  ];
2235
2471
  const relativeCandidates = process.platform === "win32"
2236
2472
  ? [
@@ -2261,14 +2497,12 @@ export async function resolvePluginPython(options = {}) {
2261
2497
  "Set pythonPath, --python, or PYTHON, install the Codex managed runtime, or add python3/python (py on Windows) to PATH.");
2262
2498
  }
2263
2499
  export function pluginExecutionEnvironment(python, environment = process.env) {
2264
- const child = {
2500
+ return {
2265
2501
  ...pythonUtf8Environment(environment),
2266
2502
  PYTHON: python,
2267
2503
  CODEX_SECURITY_PYTHON_COMMAND: python,
2268
2504
  CODEX_CLI_PATH: resolveCodexCommand(environment).command,
2269
2505
  };
2270
- forwardExternalImportSetting(environment, child);
2271
- return child;
2272
2506
  }
2273
2507
  export function environmentWithGit(environment, git) {
2274
2508
  if (git === undefined)
@@ -2299,6 +2533,16 @@ function pluginHelperEnvironment(environment) {
2299
2533
  export async function cleanupSdkDirectory(path) {
2300
2534
  await rm(path, { recursive: true, force: true });
2301
2535
  }
2536
+ // A child can finish or reject a request before the parent finishes writing it.
2537
+ export function isDisconnectedChildStdin(error) {
2538
+ return [
2539
+ "EPIPE",
2540
+ "ECONNRESET",
2541
+ "ENOTCONN",
2542
+ "EOF",
2543
+ "ERR_STREAM_DESTROYED",
2544
+ ].includes(error.code ?? "");
2545
+ }
2302
2546
  export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
2303
2547
  const cancellation = archiveHandshake ? new AbortController() : undefined;
2304
2548
  const abort = () => cancellation?.abort(signal?.reason);
@@ -2337,26 +2581,30 @@ export async function runCodexCommand(command, args, environment, input, signal,
2337
2581
  processError = error;
2338
2582
  });
2339
2583
  child.stdin.on("error", (error) => {
2340
- if (!["EPIPE", "ECONNRESET", "EOF", "ERR_STREAM_DESTROYED"].includes(error.code ?? ""))
2584
+ if (!isDisconnectedChildStdin(error))
2341
2585
  processError = error;
2342
2586
  });
2343
2587
  child.once("close", (exitCode) => processError === undefined
2344
2588
  ? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
2345
2589
  : reject(processError));
2346
2590
  });
2347
- const releaseCanceledPipes = () => {
2591
+ let forceTermination;
2592
+ const settleCanceledChild = () => {
2348
2593
  if (!commandSignal?.aborted)
2349
2594
  return;
2350
- if (child.exitCode === null && child.signalCode === null)
2595
+ if (child.exitCode === null && child.signalCode === null) {
2596
+ // spawn already sent SIGTERM. Give the command time to exit cleanly.
2597
+ forceTermination ??= setTimeout(() => child.kill("SIGKILL"), 1_000);
2351
2598
  return;
2599
+ }
2352
2600
  child.stdin.destroy();
2353
2601
  child.stdout.destroy();
2354
2602
  child.stderr.destroy();
2355
2603
  };
2356
- commandSignal?.addEventListener("abort", releaseCanceledPipes, {
2357
- once: true,
2358
- });
2359
- child.once("exit", releaseCanceledPipes);
2604
+ commandSignal?.addEventListener("abort", settleCanceledChild, { once: true });
2605
+ child.once("exit", settleCanceledChild);
2606
+ if (commandSignal?.aborted)
2607
+ settleCanceledChild();
2360
2608
  if (archiveHandshake) {
2361
2609
  signal?.addEventListener("abort", abort, { once: true });
2362
2610
  if (signal?.aborted)
@@ -2374,8 +2622,9 @@ export async function runCodexCommand(command, args, environment, input, signal,
2374
2622
  finally {
2375
2623
  if (archiveHandshake)
2376
2624
  signal?.removeEventListener("abort", abort);
2377
- commandSignal?.removeEventListener("abort", releaseCanceledPipes);
2378
- child.removeListener("exit", releaseCanceledPipes);
2625
+ clearTimeout(forceTermination);
2626
+ commandSignal?.removeEventListener("abort", settleCanceledChild);
2627
+ child.removeListener("exit", settleCanceledChild);
2379
2628
  }
2380
2629
  }
2381
2630
  export async function probeCodexSandbox(command, environment, signal) {
@@ -2397,9 +2646,14 @@ export async function probeCodexSandbox(command, environment, signal) {
2397
2646
  }
2398
2647
  catch (error) {
2399
2648
  signal?.throwIfAborted();
2649
+ if (timeout.aborted)
2650
+ throw new SandboxUnavailableError(`Codex sandbox probe timed out after ${SANDBOX_PROBE_TIMEOUT_MILLISECONDS / 1000} seconds.`, { cause: error });
2400
2651
  detail = processErrorDetail(error);
2401
2652
  }
2402
- throw new SandboxUnavailableError(`Codex could not run a command in its sandbox; reproduce with '${command.command} ${args.join(" ")}'. On Linux this usually means unprivileged user namespaces are restricted (kernel.apparmor_restrict_unprivileged_userns=1 on Ubuntu 24.04 and later), which Bubblewrap needs; inside the container image, use the AppArmor profile and Compose override from the SDK README. Codex reported: ${detail}`);
2653
+ const guidance = process.platform === "linux"
2654
+ ? "\nOn Linux this usually means unprivileged user namespaces are restricted (kernel.apparmor_restrict_unprivileged_userns=1 on Ubuntu 24.04 and later), which Bubblewrap needs; inside the container image, use the AppArmor profile and Compose override from the SDK README."
2655
+ : "";
2656
+ throw new SandboxUnavailableError(`Codex could not run a command in its sandbox: ${detail}\nTo reproduce, run '${command.command} ${args.join(" ")}'.${guidance}`);
2403
2657
  }
2404
2658
  async function runPluginCommand(command, args, environment, signal) {
2405
2659
  try {
@@ -2433,7 +2687,7 @@ async function validatePluginRoot(root) {
2433
2687
  await pluginMetadata(root);
2434
2688
  return await realpath(root);
2435
2689
  }
2436
- async function copyPluginTree(source, destination, signal) {
2690
+ export async function copyPluginTree(source, destination, signal) {
2437
2691
  await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
2438
2692
  try {
2439
2693
  await cp(source, destination, {
@@ -2500,21 +2754,14 @@ async function usablePython(candidate, environment = process.env, protectedRoot
2500
2754
  if (command === null)
2501
2755
  return null;
2502
2756
  try {
2503
- const { stdout } = await execFile(command.executable, [
2504
- "-I",
2505
- "-c",
2506
- "import importlib.util,sys\nif sys.version_info < (3, 10): raise SystemExit(1)\nif sys.version_info < (3, 11) and importlib.util.find_spec('tomli') is None: raise SystemExit(1)\nprint('codex-security-python-ok')",
2507
- ], {
2757
+ const { stdout } = await execFile(command.executable, ["-I", "-c", PLUGIN_PYTHON_PROBE], {
2508
2758
  env: command.environment,
2509
2759
  encoding: "utf8",
2510
- // Cold Python startup can exceed five seconds on busy Windows hosts.
2511
- timeout: 30_000,
2760
+ timeout: PLUGIN_PYTHON_PROBE_TIMEOUT_MS,
2512
2761
  windowsHide: true,
2513
2762
  signal,
2514
2763
  });
2515
- return stdout.trim() === "codex-security-python-ok"
2516
- ? command.executable
2517
- : null;
2764
+ return stdout.trim() === PLUGIN_PYTHON_READY ? command.executable : null;
2518
2765
  }
2519
2766
  catch (error) {
2520
2767
  if (signal?.aborted)
@@ -2534,8 +2781,7 @@ export function sameFile(left, right) {
2534
2781
  return Promise.all([
2535
2782
  stat(left, { bigint: true }),
2536
2783
  stat(right, { bigint: true }),
2537
- ]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
2538
- leftMetadata.ino === rightMetadata.ino, () => false);
2784
+ ]).then(([leftMetadata, rightMetadata]) => sameInode(leftMetadata, rightMetadata), () => false);
2539
2785
  }
2540
2786
  function expandExecutableHome(value, environment) {
2541
2787
  const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
@@ -2545,17 +2791,17 @@ function expandExecutableHome(value, environment) {
2545
2791
  : expandHome(path, environment);
2546
2792
  }
2547
2793
  export function expandHome(value, environment = process.env) {
2548
- const home = (process.platform === "win32"
2794
+ const home = () => (process.platform === "win32"
2549
2795
  ? (environmentValue(environment, "USERPROFILE") ??
2550
2796
  environmentValue(environment, "HOME"))
2551
2797
  : (environmentValue(environment, "HOME") ??
2552
2798
  environmentValue(environment, "USERPROFILE"))) ?? homedir();
2553
2799
  if (value === "~")
2554
- return home;
2800
+ return home();
2555
2801
  if (value.startsWith("~/"))
2556
- return join(home, value.slice(2));
2802
+ return join(home(), value.slice(2));
2557
2803
  if (value.startsWith("~\\")) {
2558
- return join(home, ...value.slice(2).split("\\"));
2804
+ return join(home(), ...value.slice(2).split("\\"));
2559
2805
  }
2560
2806
  return value;
2561
2807
  }