@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
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-publish.d.ts","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAmCzD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,UAAU,4BAA4B;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,MAAM,EACrB,YAAY,GAAE,4BAA4B,GAAG;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,sBAAsB,CAAC,CAYjC;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,4BAAiC,GAC9C,OAAO,CAAC,sBAAsB,CAAC,CAiFjC"}
1
+ {"version":3,"file":"cloud-publish.d.ts","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAoCzD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,UAAU,4BAA4B;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,MAAM,EACrB,YAAY,GAAE,4BAA4B,GAAG;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;CACpB,GACL,OAAO,CAAC,sBAAsB,CAAC,CAYjC;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,4BAAiC,GAC9C,OAAO,CAAC,sBAAsB,CAAC,CA6FjC"}
@@ -4,8 +4,8 @@ import { join } from "node:path";
4
4
  import { z } from "incur";
5
5
  import { parse as parseToml } from "smol-toml";
6
6
  import { loadContract, sha256Text as sha256 } from "./contract.js";
7
- import { AuthenticationRequiredError, CodexSecurityError } from "./errors.js";
8
- import { CSV_TARGET_ID, csvRowFinding, parseFindingsCsv, } from "./findings-import.js";
7
+ import { AuthenticationRequiredError, CodexSecurityError, errorMessage, } from "./errors.js";
8
+ import { CSV_TARGET_ID, bindImportedFindings, csvRowFinding, parseFindingsCsv, } from "./findings-import.js";
9
9
  import { bundledPluginRoot, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, expandHome, } from "./runtime.js";
10
10
  import { VERSION } from "./version.js";
11
11
  const CLOUD_PUBLISH_URL = "https://chatgpt.com/backend-api/aardvark/cli/findings";
@@ -38,18 +38,19 @@ export async function publishFindingsCsvToCloud(csvPath, dependencies = {}) {
38
38
  dependencies.signal?.throwIfAborted();
39
39
  let source;
40
40
  try {
41
- source = await readFile(csvPath, "utf8");
41
+ source = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(await readFile(csvPath));
42
42
  }
43
43
  catch (error) {
44
- throw new CodexSecurityError("Could not read findings CSV.", {
45
- cause: error,
46
- });
44
+ throw new CodexSecurityError(`Could not read findings CSV. ${errorMessage(error)}`, { cause: error });
47
45
  }
48
46
  dependencies.signal?.throwIfAborted();
49
47
  const rows = parseFindingsCsv(source);
48
+ if (rows.length === 0) {
49
+ throw new CodexSecurityError("Findings CSV must contain at least one finding.");
50
+ }
50
51
  const digest = sha256(source);
51
52
  const scanId = `scan_csv_${sha256(["codex-security-csv-import/v1", VERSION, source].join("\0")).slice(0, 24)}`;
52
- const findings = rows.map((row) => csvRowFinding(row, scanId));
53
+ const findings = bindImportedFindings(rows.map(csvRowFinding), "csv", scanId, CSV_TARGET_ID);
53
54
  const timestamp = "1970-01-01T00:00:00.000Z";
54
55
  const findingsDocument = JSON.stringify({
55
56
  documentType: "codex-security.findings",
@@ -62,7 +63,6 @@ export async function publishFindingsCsvToCloud(csvPath, dependencies = {}) {
62
63
  schemaVersion: "1.0",
63
64
  scanId,
64
65
  mode: "repository",
65
- completeness: "unknown",
66
66
  inventoryStrategy: "custom",
67
67
  includePaths: ["."],
68
68
  excludePaths: [],
@@ -189,7 +189,8 @@ async function publishCloudPayload(scan, findings, dependencies) {
189
189
  };
190
190
  }
191
191
  async function readCloudCredentials(environment) {
192
- let home = expandHome(environment["CODEX_HOME"]?.trim() || "~/.codex", environment);
192
+ const configuredHome = environment["CODEX_HOME"];
193
+ let home = expandHome(configuredHome?.trim() ? configuredHome : "~/.codex", environment);
193
194
  let requireFileStorage = true;
194
195
  const dedicatedHome = codexSecurityCredentialHome(environment);
195
196
  if (existsSync(dedicatedHome)) {
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,0CAA0C,EAC1C,2BAA2B,EAC3B,qCAAqC,EACrC,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,iBAAiB,GACrB,uDAAuD,CAAC;AAC1D,MAAM,sBAAsB,GAC1B,q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C/B,IAAI,CAAC;YACH,iBAAiB,GAAG,SAAS,CAC3B,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAClD,CAAC,4BAA4B,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;QAChE,CAAC;QACD,kEAAkE;QAClE,wEAAwE;QACxE,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;YACjC,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract, sha256Text as sha256 } from \"./contract.js\";\nimport { AuthenticationRequiredError, CodexSecurityError } from \"./errors.js\";\nimport type { Finding, ScanManifest } from \"./models.js\";\nimport {\n CSV_TARGET_ID,\n csvRowFinding,\n parseFindingsCsv,\n} from \"./findings-import.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\nimport { VERSION } from \"./version.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n \"Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.\";\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\ninterface CloudPublicationDependencies {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: CloudPublicationDependencies & {\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n return publishCloudPayload(manifest.scan, findings.findings, dependencies);\n}\n\nexport async function publishFindingsCsvToCloud(\n csvPath: string,\n dependencies: CloudPublicationDependencies = {},\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n let source: string;\n try {\n source = await readFile(csvPath, \"utf8\");\n } catch (error) {\n throw new CodexSecurityError(\"Could not read findings CSV.\", {\n cause: error,\n });\n }\n dependencies.signal?.throwIfAborted();\n const rows = parseFindingsCsv(source);\n const digest = sha256(source);\n const scanId = `scan_csv_${sha256(\n [\"codex-security-csv-import/v1\", VERSION, source].join(\"\\0\"),\n ).slice(0, 24)}`;\n const findings = rows.map((row) => csvRowFinding(row, scanId));\n const timestamp = \"1970-01-01T00:00:00.000Z\";\n const findingsDocument = JSON.stringify({\n documentType: \"codex-security.findings\",\n schemaVersion: \"1.0\",\n scanId,\n findings,\n });\n const coverageDocument = JSON.stringify({\n documentType: \"codex-security.coverage\",\n schemaVersion: \"1.0\",\n scanId,\n mode: \"repository\",\n completeness: \"unknown\",\n inventoryStrategy: \"custom\",\n includePaths: [\".\"],\n excludePaths: [],\n surfaces: findings.map((finding) => ({\n id: finding.occurrenceId,\n label: finding.title,\n disposition: \"reported\",\n receiptRefs: [],\n })),\n explicitExclusions: [],\n deferred: [],\n });\n const scan: ScanManifest[\"scan\"] = {\n id: scanId,\n producer: { name: \"codex-security-cli\", version: VERSION },\n status: \"completed\",\n startedAt: timestamp,\n completedAt: timestamp,\n sealedAt: timestamp,\n target: {\n kind: \"directory_snapshot\",\n targetId: CSV_TARGET_ID,\n displayName: \"findings.csv\",\n snapshotDigest: `codex-security-snapshot/v1:sha256:${digest}`,\n },\n scope: {\n includePaths: [\".\"],\n excludePaths: [],\n summary: \"Findings imported from a Codex Security CSV export.\",\n },\n coverageRef: \"coverage.json\",\n findingsRef: \"findings.json\",\n artifacts: [\n {\n path: \"findings.json\",\n sha256: sha256(findingsDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"coverage.json\",\n sha256: sha256(coverageDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"findings.csv\",\n sha256: digest,\n mediaType: \"text/csv\",\n },\n ],\n };\n return publishCloudPayload(scan, findings, dependencies);\n}\n\nasync function publishCloudPayload(\n scan: ScanManifest[\"scan\"],\n findings: Finding[],\n dependencies: CloudPublicationDependencies,\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: scan.id,\n findingIds: [],\n findingCount: findings.length,\n dryRun: true,\n findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan,\n findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n dependencies.signal?.throwIfAborted();\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => {\n dependencies.signal?.throwIfAborted();\n return undefined;\n }),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.length ||\n receipt.data.finding_ids.length !== findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n let home = expandHome(\n environment[\"CODEX_HOME\"]?.trim() || \"~/.codex\",\n environment,\n );\n let requireFileStorage = true;\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n requireFileStorage = false;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n if (requireFileStorage) {\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active ambient login:\n // automatic or keyring storage can leave auth.json for another account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
1
+ {"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,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,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract, sha256Text as sha256 } from \"./contract.js\";\nimport {\n AuthenticationRequiredError,\n CodexSecurityError,\n errorMessage,\n} from \"./errors.js\";\nimport type { Finding, ScanManifest } from \"./models.js\";\nimport {\n CSV_TARGET_ID,\n bindImportedFindings,\n csvRowFinding,\n parseFindingsCsv,\n} from \"./findings-import.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\nimport { VERSION } from \"./version.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n \"Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.\";\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\ninterface CloudPublicationDependencies {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: CloudPublicationDependencies & {\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n return publishCloudPayload(manifest.scan, findings.findings, dependencies);\n}\n\nexport async function publishFindingsCsvToCloud(\n csvPath: string,\n dependencies: CloudPublicationDependencies = {},\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n let source: string;\n try {\n source = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(\n await readFile(csvPath),\n );\n } catch (error) {\n throw new CodexSecurityError(\n `Could not read findings CSV. ${errorMessage(error)}`,\n { cause: error },\n );\n }\n dependencies.signal?.throwIfAborted();\n const rows = parseFindingsCsv(source);\n if (rows.length === 0) {\n throw new CodexSecurityError(\n \"Findings CSV must contain at least one finding.\",\n );\n }\n const digest = sha256(source);\n const scanId = `scan_csv_${sha256(\n [\"codex-security-csv-import/v1\", VERSION, source].join(\"\\0\"),\n ).slice(0, 24)}`;\n const findings = bindImportedFindings(\n rows.map(csvRowFinding),\n \"csv\",\n scanId,\n CSV_TARGET_ID,\n );\n const timestamp = \"1970-01-01T00:00:00.000Z\";\n const findingsDocument = JSON.stringify({\n documentType: \"codex-security.findings\",\n schemaVersion: \"1.0\",\n scanId,\n findings,\n });\n const coverageDocument = JSON.stringify({\n documentType: \"codex-security.coverage\",\n schemaVersion: \"1.0\",\n scanId,\n mode: \"repository\",\n inventoryStrategy: \"custom\",\n includePaths: [\".\"],\n excludePaths: [],\n surfaces: findings.map((finding) => ({\n id: finding.occurrenceId,\n label: finding.title,\n disposition: \"reported\",\n receiptRefs: [],\n })),\n explicitExclusions: [],\n deferred: [],\n });\n const scan: ScanManifest[\"scan\"] = {\n id: scanId,\n producer: { name: \"codex-security-cli\", version: VERSION },\n status: \"completed\",\n startedAt: timestamp,\n completedAt: timestamp,\n sealedAt: timestamp,\n target: {\n kind: \"directory_snapshot\",\n targetId: CSV_TARGET_ID,\n displayName: \"findings.csv\",\n snapshotDigest: `codex-security-snapshot/v1:sha256:${digest}`,\n },\n scope: {\n includePaths: [\".\"],\n excludePaths: [],\n summary: \"Findings imported from a Codex Security CSV export.\",\n },\n coverageRef: \"coverage.json\",\n findingsRef: \"findings.json\",\n artifacts: [\n {\n path: \"findings.json\",\n sha256: sha256(findingsDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"coverage.json\",\n sha256: sha256(coverageDocument),\n mediaType: \"application/json\",\n },\n {\n path: \"findings.csv\",\n sha256: digest,\n mediaType: \"text/csv\",\n },\n ],\n };\n return publishCloudPayload(scan, findings, dependencies);\n}\n\nasync function publishCloudPayload(\n scan: ScanManifest[\"scan\"],\n findings: Finding[],\n dependencies: CloudPublicationDependencies,\n): Promise<CloudPublicationResult> {\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: scan.id,\n findingIds: [],\n findingCount: findings.length,\n dryRun: true,\n findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan,\n findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n dependencies.signal?.throwIfAborted();\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => {\n dependencies.signal?.throwIfAborted();\n return undefined;\n }),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.length ||\n receipt.data.finding_ids.length !== findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n const configuredHome = environment[\"CODEX_HOME\"];\n let home = expandHome(\n configuredHome?.trim() ? configuredHome : \"~/.codex\",\n environment,\n );\n let requireFileStorage = true;\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n requireFileStorage = false;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n if (requireFileStorage) {\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active ambient login:\n // automatic or keyring storage can leave auth.json for another account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ export type CodeownerIdentity = {
2
+ kind: "person" | "group";
3
+ provider: "github";
4
+ handle: string;
5
+ } | {
6
+ kind: "person";
7
+ email: string;
8
+ };
9
+ export interface CodeownersRule {
10
+ pattern: string;
11
+ line: number;
12
+ rule: string;
13
+ owners: CodeownerIdentity[];
14
+ matches: (path: string) => boolean;
15
+ }
16
+ /** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */
17
+ export declare function parseCodeowners(source: string): CodeownersRule[];
18
+ export declare function codeownersForPath(rules: readonly CodeownersRule[], path: string): CodeownersRule | undefined;
19
+ //# sourceMappingURL=codeowners.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeowners.d.ts","sourceRoot":"","sources":["../src/codeowners.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAwChE;AAmFD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,IAAI,EAAE,MAAM,GACX,cAAc,GAAG,SAAS,CAE5B"}
@@ -0,0 +1,138 @@
1
+ /** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */
2
+ export function parseCodeowners(source) {
3
+ const rules = [];
4
+ for (const [index, line] of source.split(/\r?\n/u).entries()) {
5
+ const value = line.trim();
6
+ if (!value || value.startsWith("#"))
7
+ continue;
8
+ const token = /^(?:\\.|[^\s])+/u.exec(value)[0];
9
+ const matches = codeownersPattern(token);
10
+ if (matches === null)
11
+ continue;
12
+ const handles = value
13
+ .slice(token.length)
14
+ .split("#", 1)[0]
15
+ .trim()
16
+ .split(/\s+/u)
17
+ .filter(Boolean);
18
+ const owners = [];
19
+ let valid = true;
20
+ for (const handle of handles) {
21
+ if (/^@[a-z\d](?:[a-z\d_-]*[a-z\d])?(?:\/[a-z\d_.-]+)?$/iu.test(handle)) {
22
+ owners.push(handle.includes("/")
23
+ ? { kind: "group", provider: "github", handle: handle.slice(1) }
24
+ : { kind: "person", provider: "github", handle: handle.slice(1) });
25
+ }
26
+ else if (/^[^@\s]+@[^@\s]+$/u.test(handle)) {
27
+ owners.push({ kind: "person", email: handle });
28
+ }
29
+ else {
30
+ valid = false;
31
+ break;
32
+ }
33
+ }
34
+ if (valid)
35
+ rules.push({
36
+ pattern: token,
37
+ line: index + 1,
38
+ rule: line,
39
+ owners,
40
+ matches,
41
+ });
42
+ }
43
+ return rules;
44
+ }
45
+ function codeownersPattern(pattern) {
46
+ if (pattern.startsWith("!") || pattern.startsWith("\\#"))
47
+ return null;
48
+ const anchored = pattern.startsWith("/");
49
+ if (anchored)
50
+ pattern = pattern.slice(1);
51
+ const directory = pattern.endsWith("/");
52
+ if (directory)
53
+ pattern = pattern.slice(0, -1);
54
+ const rooted = anchored || pattern.includes("/");
55
+ const immediate = /(?:^|\/)[*?]$/u.test(pattern);
56
+ const characters = Array.from(pattern);
57
+ const tokens = [];
58
+ for (let index = 0; index < characters.length; index++) {
59
+ const character = characters[index];
60
+ if (character === "\\" && index + 1 < characters.length) {
61
+ tokens.push({ literal: characters[++index] });
62
+ }
63
+ else if (character === "[" ||
64
+ character === "]" ||
65
+ (character === "*" &&
66
+ characters[index + 1] === "*" &&
67
+ characters[index + 2] === "*")) {
68
+ return null;
69
+ }
70
+ else if (character === "*" &&
71
+ characters[index + 1] === "*" &&
72
+ (index === 0 || characters[index - 1] === "/") &&
73
+ (index + 2 === characters.length || characters[index + 2] === "/")) {
74
+ if (characters[index + 2] === "/") {
75
+ tokens.push("**/");
76
+ index += 2;
77
+ }
78
+ else {
79
+ tokens.push("**");
80
+ index++;
81
+ }
82
+ }
83
+ else if (character === "*" || character === "?")
84
+ tokens.push(character);
85
+ else
86
+ tokens.push({ literal: character });
87
+ }
88
+ return (path) => {
89
+ let active = new Set([0]);
90
+ let next = new Set();
91
+ // Deduplicate reachable positions: O(pattern * path) work and O(pattern)
92
+ // space, including when several wildcards can consume the same character.
93
+ for (let offset = 0;;) {
94
+ const boundary = offset === 0 || path[offset - 1] === "/";
95
+ if (!rooted && boundary)
96
+ active.add(0);
97
+ for (const index of active) {
98
+ const token = tokens[index];
99
+ if (token === "*" || token === "**" || (token === "**/" && boundary))
100
+ active.add(index + 1);
101
+ }
102
+ const end = offset === path.length;
103
+ // docs/* ends at the immediate child; service* may own a directory.
104
+ if (active.has(tokens.length) &&
105
+ (directory
106
+ ? path[offset] === "/"
107
+ : end || (!immediate && path[offset] === "/")))
108
+ return true;
109
+ if (end)
110
+ return false;
111
+ const character = String.fromCodePoint(path.codePointAt(offset));
112
+ next.clear();
113
+ for (const index of active) {
114
+ const token = tokens[index];
115
+ if (token === undefined)
116
+ continue;
117
+ if (typeof token === "object") {
118
+ if (token.literal === character)
119
+ next.add(index + 1);
120
+ }
121
+ else if (token === "?") {
122
+ if (character !== "/")
123
+ next.add(index + 1);
124
+ }
125
+ else if (token !== "*" || character !== "/")
126
+ next.add(index);
127
+ }
128
+ if (rooted && next.size === 0)
129
+ return false;
130
+ [active, next] = [next, active];
131
+ offset += character.length;
132
+ }
133
+ };
134
+ }
135
+ export function codeownersForPath(rules, path) {
136
+ return rules.findLast(({ matches }) => matches(path));
137
+ }
138
+ //# sourceMappingURL=codeowners.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeowners.js","sourceRoot":"","sources":["../src/codeowners.ts"],"names":[],"mappings":"AAYA,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAC9C,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC,CAA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,CAAC;qBAAM,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;oBACzB,IAAI,SAAS,KAAK,GAAG;wBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBAC7C,CAAC;qBAAM,IAAI,KAAK,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG;oBAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YACD,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC5C,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAgC,EAChC,IAAY;IAEZ,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["export type CodeownerIdentity =\n | { kind: \"person\" | \"group\"; provider: \"github\"; handle: string }\n | { kind: \"person\"; email: string };\n\nexport interface CodeownersRule {\n pattern: string;\n line: number;\n rule: string;\n owners: CodeownerIdentity[];\n matches: (path: string) => boolean;\n}\n\n/** GitHub CODEOWNERS uses the last matching rule, including ownerless rules. */\nexport function parseCodeowners(source: string): CodeownersRule[] {\n const rules: CodeownersRule[] = [];\n for (const [index, line] of source.split(/\\r?\\n/u).entries()) {\n const value = line.trim();\n if (!value || value.startsWith(\"#\")) continue;\n const token = /^(?:\\\\.|[^\\s])+/u.exec(value)![0];\n const matches = codeownersPattern(token);\n if (matches === null) continue;\n const handles = value\n .slice(token.length)\n .split(\"#\", 1)[0]!\n .trim()\n .split(/\\s+/u)\n .filter(Boolean);\n const owners: CodeownerIdentity[] = [];\n let valid = true;\n for (const handle of handles) {\n if (/^@[a-z\\d](?:[a-z\\d_-]*[a-z\\d])?(?:\\/[a-z\\d_.-]+)?$/iu.test(handle)) {\n owners.push(\n handle.includes(\"/\")\n ? { kind: \"group\", provider: \"github\", handle: handle.slice(1) }\n : { kind: \"person\", provider: \"github\", handle: handle.slice(1) },\n );\n } else if (/^[^@\\s]+@[^@\\s]+$/u.test(handle)) {\n owners.push({ kind: \"person\", email: handle });\n } else {\n valid = false;\n break;\n }\n }\n if (valid)\n rules.push({\n pattern: token,\n line: index + 1,\n rule: line,\n owners,\n matches,\n });\n }\n return rules;\n}\n\ntype PatternToken = { literal: string } | \"*\" | \"?\" | \"**\" | \"**/\";\n\nfunction codeownersPattern(pattern: string): CodeownersRule[\"matches\"] | null {\n if (pattern.startsWith(\"!\") || pattern.startsWith(\"\\\\#\")) return null;\n const anchored = pattern.startsWith(\"/\");\n if (anchored) pattern = pattern.slice(1);\n const directory = pattern.endsWith(\"/\");\n if (directory) pattern = pattern.slice(0, -1);\n const rooted = anchored || pattern.includes(\"/\");\n const immediate = /(?:^|\\/)[*?]$/u.test(pattern);\n const characters = Array.from(pattern);\n const tokens: PatternToken[] = [];\n for (let index = 0; index < characters.length; index++) {\n const character = characters[index]!;\n if (character === \"\\\\\" && index + 1 < characters.length) {\n tokens.push({ literal: characters[++index]! });\n } else if (\n character === \"[\" ||\n character === \"]\" ||\n (character === \"*\" &&\n characters[index + 1] === \"*\" &&\n characters[index + 2] === \"*\")\n ) {\n return null;\n } else if (\n character === \"*\" &&\n characters[index + 1] === \"*\" &&\n (index === 0 || characters[index - 1] === \"/\") &&\n (index + 2 === characters.length || characters[index + 2] === \"/\")\n ) {\n if (characters[index + 2] === \"/\") {\n tokens.push(\"**/\");\n index += 2;\n } else {\n tokens.push(\"**\");\n index++;\n }\n } else if (character === \"*\" || character === \"?\") tokens.push(character);\n else tokens.push({ literal: character });\n }\n return (path) => {\n let active = new Set([0]);\n let next = new Set<number>();\n // Deduplicate reachable positions: O(pattern * path) work and O(pattern)\n // space, including when several wildcards can consume the same character.\n for (let offset = 0; ;) {\n const boundary = offset === 0 || path[offset - 1] === \"/\";\n if (!rooted && boundary) active.add(0);\n for (const index of active) {\n const token = tokens[index];\n if (token === \"*\" || token === \"**\" || (token === \"**/\" && boundary))\n active.add(index + 1);\n }\n const end = offset === path.length;\n // docs/* ends at the immediate child; service* may own a directory.\n if (\n active.has(tokens.length) &&\n (directory\n ? path[offset] === \"/\"\n : end || (!immediate && path[offset] === \"/\"))\n )\n return true;\n if (end) return false;\n const character = String.fromCodePoint(path.codePointAt(offset)!);\n next.clear();\n for (const index of active) {\n const token = tokens[index];\n if (token === undefined) continue;\n if (typeof token === \"object\") {\n if (token.literal === character) next.add(index + 1);\n } else if (token === \"?\") {\n if (character !== \"/\") next.add(index + 1);\n } else if (token !== \"*\" || character !== \"/\") next.add(index);\n }\n if (rooted && next.size === 0) return false;\n [active, next] = [next, active];\n offset += character.length;\n }\n };\n}\n\nexport function codeownersForPath(\n rules: readonly CodeownersRule[],\n path: string,\n): CodeownersRule | undefined {\n return rules.findLast(({ matches }) => matches(path));\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  export declare function bundledCodexSdkEnvironment(command: string, environment: Record<string, string>): Record<string, string>;
2
+ export declare function resolveBundledCodexExecutable(codexPackageJson?: string): string;
2
3
  //# sourceMappingURL=codex-sdk-environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codex-sdk-environment.d.ts","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAGA,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxB"}
1
+ {"version":3,"file":"codex-sdk-environment.d.ts","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAKA,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6BxB;AAED,wBAAgB,6BAA6B,CAC3C,gBAAgB,CAAC,EAAE,MAAM,GACxB,MAAM,CA0CR"}
@@ -1,9 +1,12 @@
1
- import { statSync } from "node:fs";
1
+ import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { createRequire } from "node:module";
2
3
  import { delimiter, dirname, join } from "node:path";
4
+ import { PluginBootstrapError } from "./errors.js";
3
5
  export function bundledCodexSdkEnvironment(command, environment) {
4
6
  // An SDK executable override disables its bundled-tool PATH setup.
5
- const toolsDirectory = join(dirname(dirname(command)), "codex-path");
7
+ let toolsDirectory;
6
8
  try {
9
+ toolsDirectory = join(dirname(realpathSync.native(dirname(command))), "codex-path");
7
10
  if (!statSync(toolsDirectory).isDirectory())
8
11
  return environment;
9
12
  }
@@ -27,4 +30,39 @@ export function bundledCodexSdkEnvironment(command, environment) {
27
30
  result[pathKey] = [toolsDirectory, ...entries].join(delimiter);
28
31
  return result;
29
32
  }
33
+ export function resolveBundledCodexExecutable(codexPackageJson) {
34
+ const platform = process.platform === "android" ? "linux" : process.platform;
35
+ const packageName = `@openai/codex-${platform}-${process.arch}`;
36
+ let packageJson;
37
+ let legacyVendor = false;
38
+ try {
39
+ const selectedPackageJson = codexPackageJson ??
40
+ createRequire(import.meta.url).resolve("@openai/codex/package.json");
41
+ try {
42
+ packageJson = createRequire(selectedPackageJson).resolve(`${packageName}/package.json`);
43
+ }
44
+ catch (error) {
45
+ if (codexPackageJson === undefined)
46
+ throw error;
47
+ packageJson = selectedPackageJson;
48
+ legacyVendor = true;
49
+ }
50
+ }
51
+ catch (error) {
52
+ 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 });
53
+ }
54
+ const vendor = join(dirname(packageJson), "vendor");
55
+ const architecture = process.arch === "arm64" ? "aarch64" : "x86_64";
56
+ const legacyTarget = `${architecture}-${platform === "darwin" ? "apple-darwin" : platform === "win32" ? "pc-windows-msvc" : "unknown-linux-musl"}`;
57
+ const target = readdirSync(vendor, { withFileTypes: true }).find((entry) => entry.isDirectory() && (!legacyVendor || entry.name === legacyTarget));
58
+ const targetRoot = join(vendor, target?.name ?? "");
59
+ const binaryName = process.platform === "win32" ? "codex.exe" : "codex";
60
+ let command = join(targetRoot, "bin", binaryName);
61
+ if (codexPackageJson !== undefined && !existsSync(command))
62
+ command = join(targetRoot, "codex", binaryName);
63
+ if (target === undefined || !existsSync(command)) {
64
+ 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.`);
65
+ }
66
+ return command;
67
+ }
30
68
  //# sourceMappingURL=codex-sdk-environment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codex-sdk-environment.js","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAErD,MAAM,UAAU,0BAA0B,CACxC,OAAe,EACf,WAAmC;IAEnC,mEAAmE;IACnE,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IACrE,IAAI,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE;YAAE,OAAO,WAAW,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAClD,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC1B,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM;QAC9B,CAAC,CAAC,GAAG,KAAK,MAAM,CACnB,CAAC;IACF,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;IAChC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,GAAG,KAAK,OAAO;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SACpC,KAAK,CAAC,SAAS,CAAC;SAChB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,KAAK,cAAc,CAAC,CAAC;IACnE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { statSync } from \"node:fs\";\nimport { delimiter, dirname, join } from \"node:path\";\n\nexport function bundledCodexSdkEnvironment(\n command: string,\n environment: Record<string, string>,\n): Record<string, string> {\n // An SDK executable override disables its bundled-tool PATH setup.\n const toolsDirectory = join(dirname(dirname(command)), \"codex-path\");\n try {\n if (!statSync(toolsDirectory).isDirectory()) return environment;\n } catch {\n return environment;\n }\n const result = { ...environment };\n const pathKeys = Object.keys(result).filter((key) =>\n process.platform === \"win32\"\n ? key.toLowerCase() === \"path\"\n : key === \"PATH\",\n );\n const pathKey = pathKeys.includes(\"Path\")\n ? \"Path\"\n : (pathKeys.at(-1) ?? \"PATH\");\n for (const key of pathKeys) {\n if (key !== pathKey) delete result[key];\n }\n const entries = (result[pathKey] ?? \"\")\n .split(delimiter)\n .filter((entry) => entry.length > 0 && entry !== toolsDirectory);\n result[pathKey] = [toolsDirectory, ...entries].join(delimiter);\n return result;\n}\n"]}
1
+ {"version":3,"file":"codex-sdk-environment.js","sourceRoot":"","sources":["../src/codex-sdk-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,UAAU,0BAA0B,CACxC,OAAe,EACf,WAAmC;IAEnC,mEAAmE;IACnE,IAAI,cAAsB,CAAC;IAC3B,IAAI,CAAC;QACH,cAAc,GAAG,IAAI,CACnB,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAC9C,YAAY,CACb,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE;YAAE,OAAO,WAAW,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAClD,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC1B,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM;QAC9B,CAAC,CAAC,GAAG,KAAK,MAAM,C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AClD,IAAI,gBAAgB,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACxD,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,oBAAoB,CAC5B,OAAO,WAAW,qKAAqK,CACxL,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { existsSync, readdirSync, realpathSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { delimiter, dirname, join } from \"node:path\";\nimport { PluginBootstrapError } from \"./errors.js\";\n\nexport function bundledCodexSdkEnvironment(\n command: string,\n environment: Record<string, string>,\n): Record<string, string> {\n // An SDK executable override disables its bundled-tool PATH setup.\n let toolsDirectory: string;\n try {\n toolsDirectory = join(\n dirname(realpathSync.native(dirname(command))),\n \"codex-path\",\n );\n if (!statSync(toolsDirectory).isDirectory()) return environment;\n } catch {\n return environment;\n }\n const result = { ...environment };\n const pathKeys = Object.keys(result).filter((key) =>\n process.platform === \"win32\"\n ? key.toLowerCase() === \"path\"\n : key === \"PATH\",\n );\n const pathKey = pathKeys.includes(\"Path\")\n ? \"Path\"\n : (pathKeys.at(-1) ?? \"PATH\");\n for (const key of pathKeys) {\n if (key !== pathKey) delete result[key];\n }\n const entries = (result[pathKey] ?? \"\")\n .split(delimiter)\n .filter((entry) => entry.length > 0 && entry !== toolsDirectory);\n result[pathKey] = [toolsDirectory, ...entries].join(delimiter);\n return result;\n}\n\nexport function resolveBundledCodexExecutable(\n codexPackageJson?: string,\n): string {\n const platform = process.platform === \"android\" ? \"linux\" : process.platform;\n const packageName = `@openai/codex-${platform}-${process.arch}`;\n let packageJson: string;\n let legacyVendor = false;\n try {\n const selectedPackageJson =\n codexPackageJson ??\n createRequire(import.meta.url).resolve(\"@openai/codex/package.json\");\n try {\n packageJson = createRequire(selectedPackageJson).resolve(\n `${packageName}/package.json`,\n );\n } catch (error) {\n if (codexPackageJson === undefined) throw error;\n packageJson = selectedPackageJson;\n legacyVendor = true;\n }\n } catch (error) {\n throw new PluginBootstrapError(\n `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.`,\n { cause: error },\n );\n }\n const vendor = join(dirname(packageJson), \"vendor\");\n const architecture = process.arch === \"arm64\" ? \"aarch64\" : \"x86_64\";\n const legacyTarget = `${architecture}-${platform === \"darwin\" ? \"apple-darwin\" : platform === \"win32\" ? \"pc-windows-msvc\" : \"unknown-linux-musl\"}`;\n const target = readdirSync(vendor, { withFileTypes: true }).find(\n (entry) =>\n entry.isDirectory() && (!legacyVendor || entry.name === legacyTarget),\n );\n const targetRoot = join(vendor, target?.name ?? \"\");\n const binaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\n let command = join(targetRoot, \"bin\", binaryName);\n if (codexPackageJson !== undefined && !existsSync(command))\n command = join(targetRoot, \"codex\", binaryName);\n if (target === undefined || !existsSync(command)) {\n throw new PluginBootstrapError(\n `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.`,\n );\n }\n return command;\n}\n"]}
@@ -1,14 +1,11 @@
1
- import type { CodexSecurityConfig } from "./config.js";
1
+ import { type ReadOnlyCodexOptions } from "./scan-comparison.js";
2
2
  export interface ComponentPlan {
3
3
  components: Array<{
4
4
  name: string;
5
5
  paths: string[];
6
6
  }>;
7
7
  }
8
- export interface ComponentPlanningOptions {
9
- config?: CodexSecurityConfig;
10
- environment?: NodeJS.ProcessEnv;
11
- signal?: AbortSignal;
8
+ export interface ComponentPlanningOptions extends Pick<ReadOnlyCodexOptions, "config" | "environment" | "signal"> {
12
9
  }
13
10
  export declare function normalizeComponentPlan(repository: string, value: unknown, signal?: AbortSignal): Promise<ComponentPlan>;
14
11
  export declare function planComponents(repository: string, options?: ComponentPlanningOptions): Promise<ComponentPlan>;
@@ -1 +1 @@
1
- {"version":3,"file":"component-plan.d.ts","sourceRoot":"","sources":["../src/component-plan.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAgCvD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,wBAAwB;IAKvC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CAGtB;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,aAAa,CAAC,CA8DxB"}
1
+ {"version":3,"file":"component-plan.d.ts","sourceRoot":"","sources":["../src/component-plan.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAuB9B,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,oBAAoB,EACpB,QAAQ,GAAG,aAAa,GAAG,QAAQ,CACpC;CASA;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,aAAa,CAAC,CA+DxB"}
@@ -1,27 +1,19 @@
1
- import { execFile as execFileCallback } from "node:child_process";
2
1
  import { lstat, readdir } from "node:fs/promises";
3
2
  import { tmpdir } from "node:os";
4
3
  import { join, posix } from "node:path";
5
- import { promisify } from "node:util";
6
- import { z } from "incur";
4
+ import { z } from "zod";
7
5
  import { runReadOnlyCodex, } from "./scan-comparison.js";
8
6
  import { CODEX_SECURITY_THREAD_SOURCES } from "./thread-source.js";
9
- import { nullIfMissingFile, enclosingGitWorktreeRoot, normalizeRepository, normalizeTarget, validatedGitEnvironment, } from "./targets.js";
10
- import { resolveTrustedExecutable } from "./trusted-executable.js";
11
- const execFile = promisify(execFileCallback);
7
+ import { nullIfMissingFile, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, normalizeTarget, validatedGitEnvironment, } from "./targets.js";
12
8
  /** @internal */
13
- export const componentPlanSchema = z
14
- .object({
9
+ export const componentPlanSchema = z.strictObject({
15
10
  components: z
16
- .array(z
17
- .object({
11
+ .array(z.strictObject({
18
12
  name: z.string().trim().min(1),
19
13
  paths: z.array(z.string().min(1)).min(1),
20
- })
21
- .strict())
14
+ }))
22
15
  .min(1),
23
- })
24
- .strict();
16
+ });
25
17
  export async function normalizeComponentPlan(repository, value, signal) {
26
18
  const plan = componentPlanSchema.parse(value);
27
19
  for (const component of plan.components) {
@@ -40,7 +32,8 @@ export async function planComponents(repository, options = {}) {
40
32
  for (const batch of componentPlanningBatches(files, options.signal)) {
41
33
  options.signal?.throwIfAborted();
42
34
  const response = await runReadOnlyCodex(batch.prompt, z.toJSONSchema(componentPlanSchema, { target: "openapi-3.0" }), { ...options, config: options.config ?? {}, workingDirectory: tmpdir() }, {
43
- surface: "cli",
35
+ surface: options.surface ?? "sdk",
36
+ command: "scan-components",
44
37
  threadSource: CODEX_SECURITY_THREAD_SOURCES.scan,
45
38
  });
46
39
  const proposed = await normalizeComponentPlan(repository, JSON.parse(response), options.signal);
@@ -181,14 +174,12 @@ function directoryCounts(files) {
181
174
  }
182
175
  async function inventoryFiles(repository, signal) {
183
176
  signal?.throwIfAborted();
184
- if (await enclosingGitWorktreeRoot(repository, signal)) {
177
+ const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
178
+ if (await enclosingGitWorktreeRoot(repository, signal, {
179
+ requireIfPresent: true,
180
+ })) {
185
181
  validatedGitEnvironment();
186
- const git = await resolveTrustedExecutable("git", process.env, repository);
187
- if (git === null)
188
- throw new Error("Git is required to inventory this repository.");
189
- const { stdout } = await execFile(git.executable, [
190
- "-C",
191
- repository,
182
+ const stdout = await gitOutput(repository, [
192
183
  "ls-files",
193
184
  "--cached",
194
185
  "--others",
@@ -197,13 +188,14 @@ async function inventoryFiles(repository, signal) {
197
188
  "-z",
198
189
  "--",
199
190
  ".",
200
- ], { env: git.environment, signal, maxBuffer: Infinity });
191
+ ], signal, undefined, undefined, "buffer");
201
192
  const files = [];
202
- for (const path of stdout.split("\0").filter(Boolean)) {
193
+ for (const path of stdout.toString("latin1").split("\0").filter(Boolean)) {
203
194
  signal?.throwIfAborted();
204
- const metadata = await lstat(join(repository, path)).catch(nullIfMissingFile);
195
+ const bytes = Buffer.from(path, "latin1");
196
+ const metadata = await lstat(Buffer.from(join(Buffer.from(repository).toString("latin1"), path), "latin1")).catch(nullIfMissingFile);
205
197
  if (metadata?.isFile())
206
- files.push(join(repository, path));
198
+ files.push(join(repository, utf8.decode(bytes)));
207
199
  }
208
200
  return files.length === 0
209
201
  ? []
@@ -214,12 +206,28 @@ async function inventoryFiles(repository, signal) {
214
206
  while (pending.length > 0) {
215
207
  signal?.throwIfAborted();
216
208
  const directory = pending.pop();
217
- for (const entry of await readdir(join(repository, directory), {
218
- withFileTypes: true,
219
- })) {
220
- if (entry.name === ".git")
209
+ const directoryPath = join(repository, directory);
210
+ // Bun's buffer encoding omits Dirent metadata even with withFileTypes.
211
+ const entries = process.versions["bun"]
212
+ ? await readdir(directoryPath, {
213
+ withFileTypes: true,
214
+ encoding: process.platform === "win32" ? "utf8" : "latin1",
215
+ })
216
+ : await readdir(directoryPath, {
217
+ withFileTypes: true,
218
+ encoding: "buffer",
219
+ });
220
+ for (const entry of entries) {
221
+ if (!entry.isDirectory() && !entry.isFile())
222
+ continue;
223
+ const name = typeof entry.name === "string"
224
+ ? process.platform === "win32"
225
+ ? entry.name
226
+ : utf8.decode(Buffer.from(entry.name, "latin1"))
227
+ : utf8.decode(entry.name);
228
+ if (name === ".git")
221
229
  continue;
222
- const path = directory ? `${directory}/${entry.name}` : entry.name;
230
+ const path = directory ? `${directory}/${name}` : name;
223
231
  if (entry.isDirectory())
224
232
  pending.push(path);
225
233
  else if (entry.isFile())