@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":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,GAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAwB,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,GACf,MAAM,wBAAwB,CAAC;A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MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,CACrC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAC/D,CAAC;QACF,MAAM,WAAW,EAAE,qBAAqB,EAAE,CAAC;QAC3C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;QACjC,MAAM,MAAM,GAA0B,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC9D,MAAM,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport {\n bundledPluginRoot,\n workbenchEnvironment,\n resolvePluginPython,\n runWorkbench,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { CodexReviewRunner } from \"./codex-review.js\";\nimport {\n FindingDeduplicator,\n deduplicationConcurrency,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexDeduplicationReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type { FindingSearchScope } from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\nimport { normalizeRepository } from \"../targets.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named local findings workflow, including custom publication. */\n workflowId?: string;\n /** Findings API base URL. The scan's findings must already be indexed there. */\n findingsUrl: string;\n /** Search all repositories instead of the scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n /** Shared concurrency limit for deduplication jobs. Defaults to 8. */\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {\n /** Local repository checkout used to review duplicate candidates. */\n repository: string;\n /** Require the sealed artifacts to belong to this scan. */\n expectedScanId?: string;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** Review a complete, sealed scan directory without resolving local scan history. */\nexport async function deduplicateScanDirectory(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanDirectoryInternal(scanDirectory, options);\n}\n\ntype DeduplicateScanDependencies = Partial<SavedScanDependencies> & {\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n fetch?: FindingsRequest;\n};\n\n/** @internal */\nexport async function deduplicateScanDirectoryInternal(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n return await deduplicateResolvedScan(\n scanDirectory,\n await normalizeRepository(options.repository, options.signal),\n options.expectedScanId,\n options,\n dependencies,\n await bundledPluginRoot(),\n true,\n );\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n dependencies.runWorkbench ??\n (async (args) => {\n const stateEnvironment = workbenchEnvironment(environment);\n return await runWorkbench(\n {\n environment: stateEnvironment,\n pluginRoot,\n python: await resolvePluginPython({\n environment: stateEnvironment,\n }),\n signal: options.signal,\n failureMessage: \"Could not read Codex Security scan history\",\n },\n args,\n );\n }),\n });\n return await deduplicateResolvedScan(\n scan.scanDir,\n scan[\"targetPath\"] as string,\n scan.scanId,\n options,\n dependencies,\n pluginRoot,\n false,\n );\n}\n\nasync function deduplicateResolvedScan(\n selectedDirectory: string,\n repositoryPath: string,\n expectedScanId: string | undefined,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies,\n pluginRoot: string,\n bindRepository: boolean,\n): Promise<DeduplicateScanResult> {\n const environment = dependencies.environment ?? process.env;\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n selectedDirectory,\n {\n pluginRoot,\n expectedScanId,\n signal: options.signal,\n },\n );\n const scanId = contract.manifest.scan.id;\n const client = new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n );\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n ...(bindRepository ? { repositoryPath } : {}),\n scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n scope,\n });\n await workflow.complete(\"scan\", null);\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl,\n workflowId: options.workflowId,\n expectedScanId: scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench:\n dependencies.runWorkbench === undefined\n ? undefined\n : (_options, args, input) =>\n dependencies.runWorkbench!(args, input),\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n environment,\n undefined,\n options.signal,\n repositoryPath,\n );\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n await workflow.sourceSnapshot(repositoryPath),\n scope,\n await reviewSettingsDigest(environment),\n )\n : undefined;\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: (findingId) =>\n client.potentialDuplicates(findingId, scope),\n },\n dependencies.reviewer ??\n new CodexDeduplicationReviewer(checkpoints ?? runner),\n options.signal,\n options.concurrency,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId, ...reviewed };\n await workflow?.prepareDedupe(result, { groups: result.duplicateGroups });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n"]}
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EAEjB,2BA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AC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"../contract.js\";\nimport type { CodexSecuritySurface } from \"../api.js\";\nimport { environmentEntry } from \"../auth.js\";\nimport {\n bundledPluginRoot,\n runWorkbench,\n codexSecurityStateDirectory,\n canonicalizeModelSafePath,\n} from \"../runtime.js\";\nimport {\n resolveCompletedScan,\n type SavedScanDependencies,\n} from \"../saved-scan.js\";\nimport { savedScanWorkbench } from \"../saved-scan-bootstrap.js\";\nimport { CodexReviewRunner, reviewSqliteHome } from \"./codex-review.js\";\nimport { mkdir } from \"node:fs/promises\";\nimport { isWithin } from \"../trusted-executable.js\";\nimport {\n FindingDeduplicator,\n deduplicationConcurrency,\n type DeduplicationResult,\n} from \"./deduplication.js\";\nimport {\n CodexGroupingReviewer,\n type DeduplicationReviewer,\n} from \"./deduplication-reviewer.js\";\nimport { FindingsClient, type FindingsRequest } from \"../findings-client.js\";\nimport type {\n FindingSearchScope,\n FindingSourceSnapshot,\n} from \"../finding-retrieval.js\";\nimport {\n FindingWorkflow,\n workflowDestination,\n workflowDigest,\n} from \"../finding-workflow.js\";\nimport { publishScanToCustomInternal } from \"../custom-publish.js\";\nimport {\n CheckpointedReviewRunner,\n reviewSettingsDigest,\n} from \"./checkpointed-review.js\";\nimport { normalizeRepository } from \"../targets.js\";\nimport { LocalDeduplication, type FindingEmbeddingBinding } from \"./local.js\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"../auth.js\";\nimport { CodexSecurityError } from \"../errors.js\";\nimport { comparisonEnvironment } from \"../scan-comparison.js\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isRecord } from \"../record.js\";\nimport { resolveCodexProfile, type JsonObject } from \"../config.js\";\nimport { savedSourceContext } from \"./deduplication-prompts.js\";\nimport {\n emitDiagnostic,\n type DeduplicationDiagnosticObserver,\n} from \"./diagnostics.js\";\n\nexport interface DeduplicateScanOptions {\n /** Resume the named findings workflow; remote mode includes custom publication. */\n workflowId?: string;\n /** Optional Findings API. Omit to prepare and deduplicate findings in local SQLite. */\n findingsUrl?: string;\n /** Custom vector space for local deduplication; cannot be combined with findingsUrl. */\n embedding?: FindingEmbeddingBinding;\n /** Search all repositories instead of the scan's targetId. Defaults to false. */\n allRepositories?: boolean;\n /** Shared concurrency limit for deduplication jobs. Defaults to 8. */\n concurrency?: number;\n /** Best-effort progress and native review diagnostics; observer failures are ignored. */\n onDiagnostic?: DeduplicationDiagnosticObserver;\n signal?: AbortSignal;\n}\n\nexport interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {\n /** Local repository checkout used to review duplicate candidates. */\n repository: string;\n /** Require the sealed artifacts to belong to this scan. */\n expectedScanId?: string;\n}\n\nexport interface DeduplicateScanResult extends DeduplicationResult {\n scanId: string;\n}\n\n/** Review a saved scan against embedding candidates and persist accepted duplicate groups. */\nexport async function deduplicateScan(\n scanId: string,\n options: DeduplicateScanOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanInternal(scanId, options);\n}\n\n/** Review a complete, sealed scan directory without resolving local scan history. */\nexport async function deduplicateScanDirectory(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n): Promise<DeduplicateScanResult> {\n return await deduplicateScanDirectoryInternal(scanDirectory, options);\n}\n\ntype DeduplicateScanDependencies = Partial<SavedScanDependencies> & {\n surface?: CodexSecuritySurface;\n environment?: NodeJS.ProcessEnv;\n reviewer?: DeduplicationReviewer;\n reviewRunner?: Pick<CodexReviewRunner, \"run\">;\n resolveReviewEnvironment?: typeof comparisonEnvironment;\n fetch?: FindingsRequest;\n};\n\n/** @internal */\nexport async function deduplicateScanDirectoryInternal(\n scanDirectory: string,\n options: DeduplicateScanDirectoryOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n return await deduplicateResolvedScan(\n scanDirectory,\n await normalizeRepository(options.repository, options.signal),\n options.expectedScanId,\n options,\n dependencies,\n await bundledPluginRoot(),\n true,\n );\n}\n\n/** @internal */\nexport async function deduplicateScanInternal(\n scanId: string,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies = {},\n): Promise<DeduplicateScanResult> {\n options.signal?.throwIfAborted();\n deduplicationConcurrency(options.concurrency);\n const environment = dependencies.environment ?? process.env;\n const pluginRoot = await bundledPluginRoot();\n const bootstrap = dependencies.runWorkbench\n ? undefined\n : await savedScanWorkbench(scanId, {\n environment,\n pluginRoot,\n currentDirectory: dependencies.currentDirectory?.() ?? process.cwd(),\n signal: options.signal,\n });\n const scan = await resolveCompletedScan(scanId, {\n currentDirectory: dependencies.currentDirectory ?? (() => process.cwd()),\n runWorkbench:\n bootstrap ??\n ((args, input) =>\n dependencies.runWorkbench!(args, input, options.signal)),\n });\n return await deduplicateResolvedScan(\n scan.scanDir,\n scan[\"targetPath\"] as string,\n scan.scanId,\n options,\n bootstrap\n ? { ...dependencies, environment: bootstrap.environment }\n : dependencies,\n pluginRoot,\n false,\n );\n}\n\nasync function deduplicateResolvedScan(\n selectedDirectory: string,\n repositoryPath: string,\n expectedScanId: string | undefined,\n options: DeduplicateScanOptions,\n dependencies: DeduplicateScanDependencies,\n pluginRoot: string,\n bindRepository: boolean,\n): Promise<DeduplicateScanResult> {\n const environment = dependencies.environment ?? process.env;\n if (options.embedding !== undefined && options.findingsUrl !== undefined)\n throw new CodexSecurityError(\n \"Custom embeddings are only supported for local deduplication.\",\n );\n const { contract, scanDirectory } = await loadContractWithScanDirectory(\n selectedDirectory,\n {\n pluginRoot,\n expectedScanId,\n signal: options.signal,\n },\n );\n const scanId = contract.manifest.scan.id;\n const scope: FindingSearchScope =\n options.allRepositories === true\n ? { allRepositories: true }\n : { repositoryId: contract.manifest.scan.target.targetId };\n const injectedWorkbench = dependencies.runWorkbench;\n const workbench: typeof runWorkbench | undefined =\n injectedWorkbench &&\n (({ signal }, args, input) =>\n injectedWorkbench(args, input, signal ?? options.signal));\n const local =\n options.findingsUrl === undefined\n ? new LocalDeduplication(\n environment,\n scope,\n repositoryPath,\n options.signal,\n workbench,\n options.embedding,\n )\n : undefined;\n const client =\n local ??\n new FindingsClient(\n options.findingsUrl!,\n options.signal,\n dependencies.fetch,\n );\n const workflow =\n options.workflowId === undefined\n ? undefined\n : new FindingWorkflow(\n options.workflowId,\n environment,\n workbench,\n undefined,\n repositoryPath,\n );\n if (workflow) {\n await workflow.protectArtifacts(scanDirectory);\n await workflow.bind({\n ...(bindRepository ? { repositoryPath } : {}),\n scanId,\n scanDir: scanDirectory,\n artifactDigest: workflowDigest(contract),\n destination: local\n ? `sqlite:${codexSecurityStateDirectory(environment)}`\n : workflowDestination(options.findingsUrl!),\n scope,\n });\n await workflow.complete(\"scan\", null);\n if (!local)\n await publishScanToCustomInternal(\n scanDirectory,\n {\n findingsUrl: options.findingsUrl!,\n workflowId: options.workflowId,\n expectedScanId: scanId,\n signal: options.signal,\n },\n {\n environment,\n fetch: dependencies.fetch,\n runWorkbench: workbench,\n },\n );\n }\n const dedupe = async (): Promise<DeduplicateScanResult> => {\n if (local) {\n await (\n workflow ?? new FindingWorkflow(scanId, environment)\n ).protectArtifacts(scanDirectory);\n emitDiagnostic(options.onDiagnostic, { event: \"preparation.started\" });\n await local.prepare(\n contract.findings.findings,\n contract.manifest.scan.target.targetId,\n );\n emitDiagnostic(options.onDiagnostic, { event: \"preparation.completed\" });\n }\n const saved = (await workflow?.get())?.stages.dedupe;\n if (saved?.pendingWrite) {\n if (\n local &&\n (saved.pendingWrite.local?.inputDigest !== local.inputDigest ||\n workflowDigest(saved.pendingWrite.local.source) !==\n workflowDigest(\n await workflow!.sourceSnapshot(\n repositoryPath,\n saved.pendingWrite.local.gitDisabled,\n (saved.pendingWrite.local.source[\"privateStatePaths\"] ??\n []) as string[],\n ),\n ))\n ) {\n throw new CodexSecurityError(\n \"Local deduplication inputs changed. Use a new workflow ID to review them.\",\n );\n }\n await client.storeDedupeGroups(saved.pendingWrite.groups);\n return saved.result as DeduplicateScanResult;\n }\n const reviewEnvironment = dependencies.reviewer\n ? environment\n : await (dependencies.resolveReviewEnvironment ?? comparisonEnvironment)(\n environment,\n undefined,\n options.signal,\n );\n const reviewConfiguration = dependencies.reviewer\n ? {}\n : await modelConfigurationForReview(\n environment,\n reviewEnvironment,\n options.signal,\n );\n const runner =\n dependencies.reviewRunner ??\n new CodexReviewRunner(\n reviewEnvironment,\n undefined,\n options.signal,\n repositoryPath,\n undefined,\n options.onDiagnostic,\n dependencies.surface ?? \"sdk\",\n );\n const privateStatePaths: string[] = [];\n if (workflow && !dependencies.reviewer) {\n const root = await canonicalizeModelSafePath(repositoryPath);\n const sqliteHome = await canonicalizeModelSafePath(\n reviewSqliteHome(reviewEnvironment, reviewConfiguration),\n );\n if (isWithin(root, sqliteHome)) {\n if (isWithin(sqliteHome, root))\n throw new CodexSecurityError(\n \"Native SQLite storage must not be the reviewed repository root when checkpointing deduplication.\",\n );\n // Create missing private parents before capturing source; native startup owns the database files.\n await mkdir(sqliteHome, { recursive: true, mode: 0o700 });\n privateStatePaths.push(sqliteHome);\n }\n }\n const source = workflow\n ? await workflow.sourceSnapshot(repositoryPath, false, privateStatePaths)\n : undefined;\n const checkpoints = workflow\n ? new CheckpointedReviewRunner(\n workflow,\n runner,\n source!,\n scope,\n await reviewSettingsDigest(reviewEnvironment, reviewConfiguration),\n options.onDiagnostic,\n )\n : undefined;\n const sourceRepositories = new Map<string, readonly string[]>(\n contract.findings.findings.map((finding) => [\n finding.findingId,\n [contract.manifest.scan.target.targetId],\n ]),\n );\n const sourceSnapshots = new Map<string, FindingSourceSnapshot>();\n const deduplicator = new FindingDeduplicator(\n {\n potentialDuplicates: async (findingId) => {\n const neighborhood = await client.potentialDuplicates(\n findingId,\n scope,\n );\n for (const finding of [\n neighborhood.finding,\n ...neighborhood.potentialDuplicates,\n ]) {\n const repositories = Object.hasOwn(\n neighborhood.repositoryIds ?? {},\n finding.findingId,\n )\n ? neighborhood.repositoryIds![finding.findingId]\n : undefined;\n if (repositories !== undefined)\n sourceRepositories.set(finding.findingId, repositories);\n else if (scope.repositoryId !== undefined)\n sourceRepositories.set(finding.findingId, [scope.repositoryId]);\n const snapshot = Object.hasOwn(\n neighborhood.sourceSnapshots ?? {},\n finding.findingId,\n )\n ? neighborhood.sourceSnapshots![finding.findingId]\n : undefined;\n if (snapshot !== undefined)\n sourceSnapshots.set(finding.findingId, snapshot);\n }\n return neighborhood;\n },\n },\n dependencies.reviewer ??\n new CodexGroupingReviewer(\n checkpoints ?? runner,\n reviewConfiguration,\n (findings) =>\n savedSourceContext(\n contract.manifest.scan.target.targetId,\n findings,\n sourceRepositories,\n sourceSnapshots,\n ),\n ),\n options.signal,\n options.concurrency,\n );\n const reviewed = await deduplicator.run(\n contract.findings.findings.map((finding) => finding.findingId),\n );\n await checkpoints?.assertSourceUnchanged();\n options.signal?.throwIfAborted();\n const result: DeduplicateScanResult = { scanId, ...reviewed };\n await workflow?.prepareDedupe(result, {\n groups: result.duplicateGroups,\n ...(local\n ? {\n local: {\n inputDigest: local.inputDigest,\n source: source!,\n gitDisabled:\n environmentEntry(environment, \"CODEX_SECURITY_GIT\") === \"\",\n },\n }\n : {}),\n });\n await client.storeDedupeGroups(result.duplicateGroups);\n return result;\n };\n return workflow ? await workflow.run(\"dedupe\", dedupe) : await dedupe();\n}\n\nasync function modelConfigurationForReview(\n source: NodeJS.ProcessEnv,\n effective: NodeJS.ProcessEnv,\n signal?: AbortSignal,\n): Promise<JsonObject> {\n const selected = resolveCodexProfile(\n await readCodexHomeConfig(effective, signal),\n );\n if (configuredCodexHome(source) === configuredCodexHome(effective))\n return selected;\n const ambient = resolveCodexProfile(\n await readCodexHomeConfig(source, signal),\n );\n const providerIdentity = (config: JsonObject) => {\n const provider = config[\"model_provider\"] ?? \"openai\";\n const definitions = config[\"model_providers\"];\n const definition =\n typeof provider === \"string\" &&\n isRecord(definitions) &&\n isRecord(definitions[provider])\n ? definitions[provider]\n : undefined;\n return {\n provider,\n baseUrl: definition?.[\"base_url\"],\n wireApi: definition?.[\"wire_api\"] ?? \"responses\",\n openaiBaseUrl:\n provider === \"openai\" ? config[\"openai_base_url\"] : undefined,\n };\n };\n // A managed sign-in home can contain only authentication/runtime settings.\n // Keep compatible caller model choices without crossing provider namespaces.\n if (\n isDeepStrictEqual(providerIdentity(ambient), providerIdentity(selected))\n ) {\n for (const key of [\"model\", \"model_reasoning_effort\"])\n if (selected[key] === undefined && ambient[key] !== undefined)\n selected[key] = ambient[key];\n }\n return selected;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { type TomlTable } from "smol-toml";
2
+ import { type JsonObject } from "./config.js";
2
3
  import { type DeepScanOptions } from "./scan-settings.js";
3
4
  import type { ScanMode } from "./scan-modes.js";
4
5
  export type DeepScanSources = Record<keyof DeepScanOptions, "default" | "legacy" | "override">;
@@ -13,5 +14,5 @@ export declare function deepScanOptions(options: DeepScanOptions & {
13
14
  mode?: ScanMode;
14
15
  }): DeepScanOptions;
15
16
  export declare function resolveDeepScanConfig(options: DeepScanOptions, source: string, signal?: AbortSignal): Promise<ResolvedDeepScanConfig>;
16
- export declare function writeDeepScanConfig(destination: string, resolved: ResolvedDeepScanConfig): Promise<void>;
17
+ export declare function writeDeepScanConfig(destination: string, resolved: ResolvedDeepScanConfig, workerRuntime?: JsonObject): Promise<void>;
17
18
  //# sourceMappingURL=deep-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-config.d.ts","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAK/D,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,CAClC,MAAM,eAAe,EACrB,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wBAAgB,eAAe,CAC7B,OAAO,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAA;CAAE,GAC7C,eAAe,CAWjB;AAgBD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAuDjC;AAED,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,UAAU,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "./record.js";
1
2
  import { lstat, readFile } from "node:fs/promises";
2
3
  import { basename, dirname, join } from "node:path";
3
4
  import { parse as parseToml } from "smol-toml";
@@ -35,9 +36,7 @@ export async function resolveDeepScanConfig(options, source, signal) {
35
36
  }
36
37
  const existing = document["deep_scan"];
37
38
  if (existing !== undefined &&
38
- (typeof existing !== "object" ||
39
- existing === null ||
40
- Array.isArray(existing) ||
39
+ (!isRecord(existing) ||
41
40
  ![Object.prototype, null].includes(Object.getPrototypeOf(existing)))) {
42
41
  throw new CodexSecurityError(`Codex Security configuration [deep_scan] at ${source} must be a TOML table.`);
43
42
  }
@@ -75,7 +74,7 @@ export async function resolveDeepScanConfig(options, source, signal) {
75
74
  overrides: explicit,
76
75
  };
77
76
  }
78
- export async function writeDeepScanConfig(destination, resolved) {
77
+ export async function writeDeepScanConfig(destination, resolved, workerRuntime) {
79
78
  const [source, target] = await Promise.all([
80
79
  canonicalConfigPath(resolved.source),
81
80
  runtimeConfigPath(destination),
@@ -94,6 +93,7 @@ export async function writeDeepScanConfig(destination, resolved) {
94
93
  DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);
95
94
  await writeCodexConfig(destination, {
96
95
  ...document,
96
+ ...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),
97
97
  deep_scan: {
98
98
  ...(retainAmbientSettings
99
99
  ? document["deep_scan"]
@@ -1 +1 @@
1
- {"version":3,"file":"deep-config.js","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAe5B,MAAM,UAAU,eAAe,CAC7B,OAA8C;IAE9C,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,iBAAiB,CAAC,KAAK,MAAM,EAAE,CAAC;YACnD,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;QACxE,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oBAAoB,CAC3B,IAA2B,EAC3B,KAAc,EACd,KAAa;IAEb,MAAM,MAAM,GAAG,sBAAsB,CAA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,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import { lstat, readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { parse as parseToml, type TomlTable } from \"smol-toml\";\nimport { writeCodexConfig, type JsonObject } from \"./config.js\";\nimport { canonicalConfigPath } from \"./runtime.js\";\nimport { DEFAULT_DEEP_SCAN_SETTINGS } from \"./deep-scan-defaults.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n DEFAULT_SCAN_MODE,\n DEEP_SCAN_SETTINGS,\n DeepScanSettingsSchema,\n type DeepScanOptions,\n} from \"./scan-settings.js\";\nimport type { ScanMode } from \"./scan-modes.js\";\n\nexport type DeepScanSources = Record<\n keyof DeepScanOptions,\n \"default\" | \"legacy\" | \"override\"\n>;\nexport interface ResolvedDeepScanConfig {\n settings: Required<DeepScanOptions>;\n sources: DeepScanSources;\n source: string;\n document: TomlTable;\n overrides: DeepScanOptions;\n}\n\nexport function deepScanOptions(\n options: DeepScanOptions & { mode?: ScanMode },\n): DeepScanOptions {\n const selected: DeepScanOptions = {};\n for (const [name] of DEEP_SCAN_SETTINGS) {\n const value = options[name];\n if (value === undefined) continue;\n if ((options.mode ?? DEFAULT_SCAN_MODE) !== \"deep\") {\n throw new CodexSecurityError(\"Deep scan settings require deep mode.\");\n }\n selected[name] = requireDeepScanValue(name, value, name);\n }\n return selected;\n}\n\nfunction requireDeepScanValue(\n name: keyof DeepScanOptions,\n value: unknown,\n label: string,\n): number {\n const parsed = DeepScanSettingsSchema.shape[name].unwrap().safeParse(value);\n if (!parsed.success) {\n throw new CodexSecurityError(\n `Deep scan ${label} ${parsed.error.issues[0]!.message}.`,\n );\n }\n return parsed.data;\n}\n\nexport async function resolveDeepScanConfig(\n options: DeepScanOptions,\n source: string,\n signal?: AbortSignal,\n): Promise<ResolvedDeepScanConfig> {\n const explicit = deepScanOptions({ ...options, mode: \"deep\" });\n let document: TomlTable = {};\n // Complete saved settings do not depend on today's ambient configuration.\n if (!DEEP_SCAN_SETTINGS.every(([name]) => explicit[name] !== undefined)) {\n document = await readDeepScanDocument(source, signal);\n }\n const existing = document[\"deep_scan\"];\n if (\n existing !== undefined &&\n (typeof existing !== \"object\" ||\n existing === null ||\n Array.isArray(existing) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(existing)))\n ) {\n throw new CodexSecurityError(\n `Codex Security configuration [deep_scan] at ${source} must be a TOML table.`,\n );\n }\n const configured = (existing ?? {}) as TomlTable;\n const keys = new Set<string>(DEEP_SCAN_SETTINGS.map(([, key]) => key));\n const unknown = Object.keys(configured).filter((key) => !keys.has(key));\n if (unknown.length > 0) {\n throw new CodexSecurityError(\n `Unknown Codex Security Deep Scan configuration ${unknown.join(\", \")} in ${source}.`,\n );\n }\n const settings = {\n ...DEFAULT_DEEP_SCAN_SETTINGS,\n } as Required<DeepScanOptions>;\n const sources = {} as DeepScanSources;\n for (const [name, key] of DEEP_SCAN_SETTINGS) {\n let value = Object.hasOwn(configured, key)\n ? configured[key]\n : DEFAULT_DEEP_SCAN_SETTINGS[name];\n if (name === \"workers\" && value === \"auto\")\n value = DEFAULT_DEEP_SCAN_SETTINGS.workers;\n if (explicit[name] !== undefined) value = explicit[name];\n sources[name] =\n explicit[name] !== undefined\n ? \"override\"\n : Object.hasOwn(configured, key)\n ? \"legacy\"\n : \"default\";\n settings[name] = requireDeepScanValue(\n name,\n value,\n sources[name] === \"legacy\" ? `${key} in ${source}` : name,\n );\n }\n return {\n settings,\n sources,\n source,\n document,\n overrides: explicit,\n };\n}\n\nexport async function writeDeepScanConfig(\n destination: string,\n resolved: ResolvedDeepScanConfig,\n): Promise<void> {\n const [source, target] = await Promise.all([\n canonicalConfigPath(resolved.source),\n runtimeConfigPath(destination),\n ]);\n let document = resolved.document;\n const sameFile = source === target;\n if (sameFile) {\n if (Object.keys(resolved.overrides).length === 0) return;\n document = await readDeepScanDocument(destination);\n }\n // An isolated runtime needs a complete snapshot. An ambient file keeps\n // inherited defaults unset so future releases can still update them.\n const settings = sameFile ? resolved.overrides : resolved.settings;\n const retainAmbientSettings =\n sameFile &&\n DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);\n await writeCodexConfig(destination, {\n ...document,\n deep_scan: {\n ...(retainAmbientSettings\n ? (document[\"deep_scan\"] as TomlTable | undefined)\n : {}),\n ...Object.fromEntries(\n DEEP_SCAN_SETTINGS.filter(([name]) => settings[name] !== undefined).map(\n ([name, key]) => [key, settings[name]],\n ),\n ),\n },\n } as JsonObject);\n}\n\nasync function runtimeConfigPath(path: string): Promise<string> {\n try {\n return await canonicalConfigPath(path);\n } catch (error) {\n if (\n (error as NodeJS.ErrnoException).code !== \"ELOOP\" ||\n !(await lstat(path)).isSymbolicLink()\n )\n throw error;\n // A stale cyclic file link is replaced by writeCodexConfig's atomic rename.\n // Errors resolving its parent (or the ambient source) still fail the write.\n return join(await canonicalConfigPath(dirname(path)), basename(path));\n }\n}\n\nasync function readDeepScanDocument(\n source: string,\n signal?: AbortSignal,\n): Promise<TomlTable> {\n try {\n return parseToml(await readFile(source, { encoding: \"utf8\", signal }));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new CodexSecurityError(\n `Cannot read Codex Security configuration at ${source}.`,\n { cause: error },\n );\n }\n return {};\n }\n}\n"]}
1
+ {"version":3,"file":"deep-config.js","sourceRoot":"","sources":["../src/deep-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAChE,O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AAC,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CACvC,CACF;SACF;KACY,CAAC,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAC3C,IAAI,CAAC;QACH,OAAO,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACG,KAA+B,CAAC,IAAI,KAAK,OAAO;YACjD,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE;YAErC,MAAM,KAAK,CAAC;QACd,4EAA4E;QAC5E,4EAA4E;QAC5E,OAAO,IAAI,CAAC,MAAM,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACxE,CAAC;AACH,CAAC;AAED,KAAK,UAAU,oBAAoB,CACjC,MAAc,EACd,MAAoB;IAEpB,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,MAAM,QAAQ,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,kBAAkB,CAC1B,+CAA+C,MAAM,GAAG,EACxD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { lstat, readFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\nimport { parse as parseToml, type TomlTable } from \"smol-toml\";\nimport { writeCodexConfig, type JsonObject } from \"./config.js\";\nimport { canonicalConfigPath } from \"./runtime.js\";\nimport { DEFAULT_DEEP_SCAN_SETTINGS } from \"./deep-scan-defaults.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n DEFAULT_SCAN_MODE,\n DEEP_SCAN_SETTINGS,\n DeepScanSettingsSchema,\n type DeepScanOptions,\n} from \"./scan-settings.js\";\nimport type { ScanMode } from \"./scan-modes.js\";\n\nexport type DeepScanSources = Record<\n keyof DeepScanOptions,\n \"default\" | \"legacy\" | \"override\"\n>;\nexport interface ResolvedDeepScanConfig {\n settings: Required<DeepScanOptions>;\n sources: DeepScanSources;\n source: string;\n document: TomlTable;\n overrides: DeepScanOptions;\n}\n\nexport function deepScanOptions(\n options: DeepScanOptions & { mode?: ScanMode },\n): DeepScanOptions {\n const selected: DeepScanOptions = {};\n for (const [name] of DEEP_SCAN_SETTINGS) {\n const value = options[name];\n if (value === undefined) continue;\n if ((options.mode ?? DEFAULT_SCAN_MODE) !== \"deep\") {\n throw new CodexSecurityError(\"Deep scan settings require deep mode.\");\n }\n selected[name] = requireDeepScanValue(name, value, name);\n }\n return selected;\n}\n\nfunction requireDeepScanValue(\n name: keyof DeepScanOptions,\n value: unknown,\n label: string,\n): number {\n const parsed = DeepScanSettingsSchema.shape[name].unwrap().safeParse(value);\n if (!parsed.success) {\n throw new CodexSecurityError(\n `Deep scan ${label} ${parsed.error.issues[0]!.message}.`,\n );\n }\n return parsed.data;\n}\n\nexport async function resolveDeepScanConfig(\n options: DeepScanOptions,\n source: string,\n signal?: AbortSignal,\n): Promise<ResolvedDeepScanConfig> {\n const explicit = deepScanOptions({ ...options, mode: \"deep\" });\n let document: TomlTable = {};\n // Complete saved settings do not depend on today's ambient configuration.\n if (!DEEP_SCAN_SETTINGS.every(([name]) => explicit[name] !== undefined)) {\n document = await readDeepScanDocument(source, signal);\n }\n const existing = document[\"deep_scan\"];\n if (\n existing !== undefined &&\n (!isRecord(existing) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(existing)))\n ) {\n throw new CodexSecurityError(\n `Codex Security configuration [deep_scan] at ${source} must be a TOML table.`,\n );\n }\n const configured = (existing ?? {}) as TomlTable;\n const keys = new Set<string>(DEEP_SCAN_SETTINGS.map(([, key]) => key));\n const unknown = Object.keys(configured).filter((key) => !keys.has(key));\n if (unknown.length > 0) {\n throw new CodexSecurityError(\n `Unknown Codex Security Deep Scan configuration ${unknown.join(\", \")} in ${source}.`,\n );\n }\n const settings = {\n ...DEFAULT_DEEP_SCAN_SETTINGS,\n } as Required<DeepScanOptions>;\n const sources = {} as DeepScanSources;\n for (const [name, key] of DEEP_SCAN_SETTINGS) {\n let value = Object.hasOwn(configured, key)\n ? configured[key]\n : DEFAULT_DEEP_SCAN_SETTINGS[name];\n if (name === \"workers\" && value === \"auto\")\n value = DEFAULT_DEEP_SCAN_SETTINGS.workers;\n if (explicit[name] !== undefined) value = explicit[name];\n sources[name] =\n explicit[name] !== undefined\n ? \"override\"\n : Object.hasOwn(configured, key)\n ? \"legacy\"\n : \"default\";\n settings[name] = requireDeepScanValue(\n name,\n value,\n sources[name] === \"legacy\" ? `${key} in ${source}` : name,\n );\n }\n return {\n settings,\n sources,\n source,\n document,\n overrides: explicit,\n };\n}\n\nexport async function writeDeepScanConfig(\n destination: string,\n resolved: ResolvedDeepScanConfig,\n workerRuntime?: JsonObject,\n): Promise<void> {\n const [source, target] = await Promise.all([\n canonicalConfigPath(resolved.source),\n runtimeConfigPath(destination),\n ]);\n let document = resolved.document;\n const sameFile = source === target;\n if (sameFile) {\n if (Object.keys(resolved.overrides).length === 0) return;\n document = await readDeepScanDocument(destination);\n }\n // An isolated runtime needs a complete snapshot. An ambient file keeps\n // inherited defaults unset so future releases can still update them.\n const settings = sameFile ? resolved.overrides : resolved.settings;\n const retainAmbientSettings =\n sameFile &&\n DEEP_SCAN_SETTINGS.some(([name]) => settings[name] === undefined);\n await writeCodexConfig(destination, {\n ...document,\n ...(workerRuntime === undefined ? {} : { worker_runtime: workerRuntime }),\n deep_scan: {\n ...(retainAmbientSettings\n ? (document[\"deep_scan\"] as TomlTable | undefined)\n : {}),\n ...Object.fromEntries(\n DEEP_SCAN_SETTINGS.filter(([name]) => settings[name] !== undefined).map(\n ([name, key]) => [key, settings[name]],\n ),\n ),\n },\n } as JsonObject);\n}\n\nasync function runtimeConfigPath(path: string): Promise<string> {\n try {\n return await canonicalConfigPath(path);\n } catch (error) {\n if (\n (error as NodeJS.ErrnoException).code !== \"ELOOP\" ||\n !(await lstat(path)).isSymbolicLink()\n )\n throw error;\n // A stale cyclic file link is replaced by writeCodexConfig's atomic rename.\n // Errors resolving its parent (or the ambient source) still fail the write.\n return join(await canonicalConfigPath(dirname(path)), basename(path));\n }\n}\n\nasync function readDeepScanDocument(\n source: string,\n signal?: AbortSignal,\n): Promise<TomlTable> {\n try {\n return parseToml(await readFile(source, { encoding: \"utf8\", signal }));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new CodexSecurityError(\n `Cannot read Codex Security configuration at ${source}.`,\n { cause: error },\n );\n }\n return {};\n }\n}\n"]}
@@ -1,7 +1,23 @@
1
- export interface DeepScanProgress {
1
+ import { z } from "zod";
2
+ declare const progressSchema: z.ZodPipe<z.ZodObject<{
3
+ completed: z.ZodInt;
4
+ active: z.ZodInt;
5
+ maximum: z.ZodInt;
6
+ consolidating: z.ZodOptional<z.ZodBoolean>;
7
+ }, z.core.$strip>, z.ZodTransform<{
2
8
  completed: number;
3
9
  active: number;
4
10
  maximum: number;
11
+ consolidating?: boolean | undefined;
12
+ }, {
13
+ completed: number;
14
+ active: number;
15
+ maximum: number;
16
+ consolidating?: boolean | undefined;
17
+ }>>;
18
+ export interface DeepScanProgress extends z.output<typeof progressSchema> {
19
+ /** Whether the coordinator is reducing results or has finished. */
20
+ consolidating?: boolean;
5
21
  }
6
22
  interface DeepScanProgressTrackerOptions {
7
23
  read: (signal: AbortSignal) => Promise<unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"deep-progress.d.ts","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/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AAO,IAAI,OAAO,CAAC,IAAI,CAAC,CA+BpC;IAEM,IAAI,IAAI,IAAI,CAKlB;CACF;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,OAAO,GACd,gBAAgB,GAAG,IAAI,CAWzB"}
@@ -1,5 +1,16 @@
1
1
  import { isRecord } from "./record.js";
2
- import { isSafeNonNegativeInteger } from "./value.js";
2
+ import { z } from "zod";
3
+ const progressSchema = z
4
+ .object({
5
+ completed: z.int().nonnegative(),
6
+ active: z.int().nonnegative(),
7
+ maximum: z.int().positive(),
8
+ consolidating: z.boolean().optional(),
9
+ })
10
+ .transform(({ consolidating, ...counts }) => ({
11
+ ...counts,
12
+ ...(consolidating === undefined ? {} : { consolidating }),
13
+ }));
3
14
  const DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;
4
15
  export class DeepScanProgressTracker {
5
16
  #options;
@@ -34,7 +45,10 @@ export class DeepScanProgressTracker {
34
45
  const progress = deepScanProgressFromWorkbench(await this.#options.read(abortController.signal));
35
46
  if (abortController.signal.aborted ||
36
47
  progress === null ||
37
- sameProgress(progress, this.#lastProgress)) {
48
+ (progress.completed === this.#lastProgress?.completed &&
49
+ progress.active === this.#lastProgress?.active &&
50
+ progress.maximum === this.#lastProgress?.maximum &&
51
+ progress.consolidating === this.#lastProgress?.consolidating)) {
38
52
  return;
39
53
  }
40
54
  this.#lastProgress = progress;
@@ -70,21 +84,9 @@ export function deepScanProgressFromWorkbench(result) {
70
84
  const independentReviews = progress["independentReviews"];
71
85
  if (independentReviews === undefined)
72
86
  return null;
73
- if (isRecord(independentReviews)) {
74
- const { completed, active, maximum } = independentReviews;
75
- if (isSafeNonNegativeInteger(completed) &&
76
- isSafeNonNegativeInteger(active) &&
77
- isSafeNonNegativeInteger(maximum) &&
78
- maximum > 0) {
79
- return { completed, active, maximum };
80
- }
81
- }
87
+ const parsed = progressSchema.safeParse(independentReviews);
88
+ if (parsed.success)
89
+ return parsed.data;
82
90
  throw new Error("Codex Security workbench returned invalid Deep Scan progress.");
83
91
  }
84
- function sameProgress(left, right) {
85
- return (right !== null &&
86
- left.completed === right.completed &&
87
- left.active === right.active &&
88
- left.maximum === right.maximum);
89
- }
90
92
  //# sourceMappingURL=deep-progress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AActD,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IAC7B,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;IAClD,aAAa,GAA4B,IAAI,CAAC;IAE9C,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO;QACzE,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,EAAE,CAAC;IACT,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO;QACjD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AM,UAAU,6BAA6B,CAC3C,MAAe;IAEf,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC;IAC5C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAC1D,IAAI,kBAAkB,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAClD,IAAI,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACjC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC;QAC1D,IACE,wBAAwB,CAAC,SAAS,CAAC;YACnC,wBAAwB,CAAC,MAAM,CAAC;YAChC,wBAAwB,CAAC,OAAO,CAAC;YACjC,OAAO,GAAG,CAAC,EACX,CAAC;YACD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QACxC,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAAsB,EACtB,KAA8B;IAE9B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;QAClC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAC/B,CAAC;AACJ,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { isSafeNonNegativeInteger } from \"./value.js\";\n\nexport interface DeepScanProgress {\n completed: number;\n active: number;\n maximum: number;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n readonly #abortController = new AbortController();\n #lastProgress: DeepScanProgress | null = null;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#abortController.signal.aborted) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(poll, DEEP_PROGRESS_POLL_INTERVAL_MS);\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#abortController.signal.aborted) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = this.#abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n abortController.signal.aborted ||\n progress === null ||\n sameProgress(progress, this.#lastProgress)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#abortController.signal.aborted) return;\n clearInterval(this.#timer ?? undefined);\n this.#timer = null;\n this.#abortController.abort();\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n if (isRecord(independentReviews)) {\n const { completed, active, maximum } = independentReviews;\n if (\n isSafeNonNegativeInteger(completed) &&\n isSafeNonNegativeInteger(active) &&\n isSafeNonNegativeInteger(maximum) &&\n maximum > 0\n ) {\n return { completed, active, maximum };\n }\n }\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n}\n\nfunction sameProgress(\n left: DeepScanProgress,\n right: DeepScanProgress | null,\n): boolean {\n return (\n right !== null &&\n left.completed === right.completed &&\n left.active === right.active &&\n left.maximum === right.maximum\n );\n}\n"]}
1
+ {"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IAChC,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAC3B,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC;KACD,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,GAAG,MAAM;IACT,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1D,CAAC,CAAC,CAAC;AAaN,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IAC7B,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;IAClD,aAAa,GAA4B,IAAI,CAAC;IAE9C,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,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AC;IAClD,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACvC,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;AACJ,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { z } from \"zod\";\n\nconst progressSchema = z\n .object({\n completed: z.int().nonnegative(),\n active: z.int().nonnegative(),\n maximum: z.int().positive(),\n consolidating: z.boolean().optional(),\n })\n .transform(({ consolidating, ...counts }) => ({\n ...counts,\n ...(consolidating === undefined ? {} : { consolidating }),\n }));\n\nexport interface DeepScanProgress extends z.output<typeof progressSchema> {\n /** Whether the coordinator is reducing results or has finished. */\n consolidating?: boolean;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n readonly #abortController = new AbortController();\n #lastProgress: DeepScanProgress | null = null;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#abortController.signal.aborted) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(poll, DEEP_PROGRESS_POLL_INTERVAL_MS);\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#abortController.signal.aborted) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = this.#abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n abortController.signal.aborted ||\n progress === null ||\n (progress.completed === this.#lastProgress?.completed &&\n progress.active === this.#lastProgress?.active &&\n progress.maximum === this.#lastProgress?.maximum &&\n progress.consolidating === this.#lastProgress?.consolidating)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#abortController.signal.aborted) return;\n clearInterval(this.#timer ?? undefined);\n this.#timer = null;\n this.#abortController.abort();\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n const parsed = progressSchema.safeParse(independentReviews);\n if (parsed.success) return parsed.data;\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { CodexOptions } from "@openai/codex-sdk";
2
+ import { type CodexCommand } from "./runtime.js";
3
+ export interface DirectDeepScanOptions {
4
+ codexOptions: CodexOptions & {
5
+ nativeProfile?: string;
6
+ };
7
+ preflightCommand: CodexCommand;
8
+ pluginRoot: string;
9
+ repository: string;
10
+ scanDir: string;
11
+ scanId: string;
12
+ prompt: string;
13
+ signal: AbortSignal;
14
+ }
15
+ /** Run the same coordinator as the plugin, without a parent model turn. */
16
+ export declare function runDeepScan(options: DirectDeepScanOptions): AsyncGenerator<{
17
+ type: string;
18
+ [key: string]: unknown;
19
+ }>;
20
+ //# sourceMappingURL=deep-scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-scan.d.ts","sourceRoot":"","sources":["../src/deep-scan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAIzE,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,YAAY,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,gBAAgB,EAAE,YAAY,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,2EAA2E;AAC3E,wBAAuB,WAAW,CAChC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC,CA6ED"}
@@ -0,0 +1,113 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { spawn } from "node:child_process";
10
+ import { join } from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+ import { bundledCodexSdkEnvironment } from "./codex-sdk-environment.js";
13
+ import { CodexSecurityError } from "./errors.js";
14
+ import { executablePathForSpawn } from "./runtime.js";
15
+ import { resolveTrustedExecutable } from "./trusted-executable.js";
16
+ import { withCodexPreflightLock } from "./provider-profile.js";
17
+ /** Run the same coordinator as the plugin, without a parent model turn. */
18
+ export async function* runDeepScan(options) {
19
+ const native = await import(__rewriteRelativeImportExtension(pathToFileURL(join(options.pluginRoot, "mcp", "permission-profile-preflight.mjs")).href));
20
+ const profile = await import(__rewriteRelativeImportExtension(pathToFileURL(join(options.pluginRoot, "scripts", "codex_profile.mjs")).href));
21
+ const configured = options.codexOptions;
22
+ const command = options.preflightCommand;
23
+ const environment = bundledCodexSdkEnvironment(command.command, {
24
+ ...configured.env,
25
+ ...(configured.apiKey === undefined
26
+ ? {}
27
+ : { CODEX_API_KEY: configured.apiKey }),
28
+ });
29
+ const session = (await withCodexPreflightLock(environment, options.signal, () => native.prepareCliDeepScanSession({
30
+ codexPath: command.command,
31
+ commandArgs: command.args,
32
+ cwd: options.scanDir,
33
+ env: environment,
34
+ configOverrides: [
35
+ ...profile.profileConfigOverrides(configured.config ?? {}),
36
+ ...(configured.configOverrides ?? []),
37
+ // This session only records native context; workers keep their own snapshot.
38
+ "features.plugins=false",
39
+ ],
40
+ signal: options.signal,
41
+ prompt: options.prompt +
42
+ "\n\nThe host runs this Deep Scan coordinator directly and owns finalization. This saved request supplies context for later follow-up; do not start a replacement scan.",
43
+ })));
44
+ yield { type: "thread.started", thread_id: session.threadId };
45
+ options.signal.throwIfAborted();
46
+ const node = process.versions["bun"]
47
+ ? await resolveTrustedExecutable("node", environment, [options.repository])
48
+ : undefined;
49
+ if (node === null)
50
+ throw new CodexSecurityError("Node.js is not available on PATH.");
51
+ const output = await runEngine(node?.executable ?? process.execPath, [join(options.pluginRoot, "mcp", "server.mjs"), "--deep-scan-engine"], node?.environment ?? environment, JSON.stringify({ scanId: options.scanId, ...session }), options.signal);
52
+ const completed = JSON.parse(output);
53
+ if (completed.scanId !== options.scanId ||
54
+ completed.manifestPath !== join(options.scanDir, "scan-manifest.json")) {
55
+ throw new CodexSecurityError("Deep Scan engine returned results for a different scan.");
56
+ }
57
+ // The control session makes no model calls. Worker usage is read by the
58
+ // existing scan tracker from the native sessions below this scan directory.
59
+ yield {
60
+ type: "turn.completed",
61
+ usage: {
62
+ input_tokens: 0,
63
+ cached_input_tokens: 0,
64
+ cache_write_input_tokens: 0,
65
+ output_tokens: 0,
66
+ },
67
+ };
68
+ }
69
+ function runEngine(command, args, env, request, signal) {
70
+ signal.throwIfAborted();
71
+ const child = spawn(executablePathForSpawn(command), args, {
72
+ env,
73
+ windowsHide: true,
74
+ });
75
+ // EOF requests graceful coordinator/worker cleanup on Windows as well as Unix.
76
+ // Keep the control pipe open until completion or explicit cancellation.
77
+ const cancel = () => child.stdin.end();
78
+ let stdout = "";
79
+ let stderr = "";
80
+ let processError;
81
+ child.stdout.setEncoding("utf8").on("data", (chunk) => {
82
+ stdout += chunk;
83
+ });
84
+ child.stderr.setEncoding("utf8").on("data", (chunk) => {
85
+ stderr += chunk;
86
+ });
87
+ child.once("error", (error) => {
88
+ processError = error;
89
+ });
90
+ child.stdin.on("error", (error) => {
91
+ if (!["EPIPE", "ECONNRESET", "EOF", "ERR_STREAM_DESTROYED"].includes(error.code ?? ""))
92
+ processError = error;
93
+ });
94
+ const result = new Promise((resolve, reject) => {
95
+ child.once("close", (code) => {
96
+ signal.removeEventListener("abort", cancel);
97
+ if (signal.aborted)
98
+ reject(signal.reason);
99
+ else if (processError)
100
+ reject(processError);
101
+ else if (code !== 0)
102
+ reject(new CodexSecurityError(stderr.trim() || `Deep Scan engine exited with code ${code}.`));
103
+ else
104
+ resolve(stdout);
105
+ });
106
+ });
107
+ child.stdin.write(request + "\n");
108
+ signal.addEventListener("abort", cancel, { once: true });
109
+ if (signal.aborted)
110
+ cancel();
111
+ return result;
112
+ }
113
+ //# sourceMappingURL=deep-scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-scan.js","sourceRoot":"","sources":["../src/deep-scan.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAA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C,KAA4B,EAAE,EAAE;QACvD,IACE,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAC9D,KAAK,CAAC,IAAI,IAAI,EAAE,CACjB;YAED,YAAY,GAAG,KAAK,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC3B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,MAAM,CAAC,OAAO;gBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBACrC,IAAI,YAAY;gBAAE,MAAM,CAAC,YAAY,CAAC,CAAC;iBACvC,IAAI,IAAI,KAAK,CAAC;gBACjB,MAAM,CACJ,IAAI,kBAAkB,CACpB,MAAM,CAAC,IAAI,EAAE,IAAI,qCAAqC,IAAI,GAAG,CAC9D,CACF,CAAC;;gBACC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,OAAO;QAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { CodexOptions } from \"@openai/codex-sdk\";\nimport { bundledCodexSdkEnvironment } from \"./codex-sdk-environment.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { executablePathForSpawn, type CodexCommand } from \"./runtime.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\nimport { withCodexPreflightLock } from \"./provider-profile.js\";\n\nexport interface DirectDeepScanOptions {\n codexOptions: CodexOptions & { nativeProfile?: string };\n preflightCommand: CodexCommand;\n pluginRoot: string;\n repository: string;\n scanDir: string;\n scanId: string;\n prompt: string;\n signal: AbortSignal;\n}\n\n/** Run the same coordinator as the plugin, without a parent model turn. */\nexport async function* runDeepScan(\n options: DirectDeepScanOptions,\n): AsyncGenerator<{\n type: string;\n [key: string]: unknown;\n}> {\n const native = await import(\n pathToFileURL(\n join(options.pluginRoot, \"mcp\", \"permission-profile-preflight.mjs\"),\n ).href\n );\n const profile = await import(\n pathToFileURL(join(options.pluginRoot, \"scripts\", \"codex_profile.mjs\")).href\n );\n const configured = options.codexOptions;\n const command = options.preflightCommand;\n const environment = bundledCodexSdkEnvironment(command.command, {\n ...configured.env,\n ...(configured.apiKey === undefined\n ? {}\n : { CODEX_API_KEY: configured.apiKey }),\n });\n const session = (await withCodexPreflightLock(\n environment,\n options.signal,\n () =>\n native.prepareCliDeepScanSession({\n codexPath: command.command,\n commandArgs: command.args,\n cwd: options.scanDir,\n env: environment,\n configOverrides: [\n ...profile.profileConfigOverrides(configured.config ?? {}),\n ...(configured.configOverrides ?? []),\n // This session only records native context; workers keep their own snapshot.\n \"features.plugins=false\",\n ],\n signal: options.signal,\n prompt:\n options.prompt +\n \"\\n\\nThe host runs this Deep Scan coordinator directly and owns finalization. This saved request supplies context for later follow-up; do not start a replacement scan.\",\n }),\n )) as {\n threadId: string;\n model: string;\n reasoningEffort?: string;\n permissionProfile: unknown;\n };\n yield { type: \"thread.started\", thread_id: session.threadId };\n options.signal.throwIfAborted();\n const node = process.versions[\"bun\"]\n ? await resolveTrustedExecutable(\"node\", environment, [options.repository])\n : undefined;\n if (node === null)\n throw new CodexSecurityError(\"Node.js is not available on PATH.\");\n const output = await runEngine(\n node?.executable ?? process.execPath,\n [join(options.pluginRoot, \"mcp\", \"server.mjs\"), \"--deep-scan-engine\"],\n node?.environment ?? environment,\n JSON.stringify({ scanId: options.scanId, ...session }),\n options.signal,\n );\n const completed = JSON.parse(output);\n if (\n completed.scanId !== options.scanId ||\n completed.manifestPath !== join(options.scanDir, \"scan-manifest.json\")\n ) {\n throw new CodexSecurityError(\n \"Deep Scan engine returned results for a different scan.\",\n );\n }\n // The control session makes no model calls. Worker usage is read by the\n // existing scan tracker from the native sessions below this scan directory.\n yield {\n type: \"turn.completed\",\n usage: {\n input_tokens: 0,\n cached_input_tokens: 0,\n cache_write_input_tokens: 0,\n output_tokens: 0,\n },\n };\n}\n\nfunction runEngine(\n command: string,\n args: string[],\n env: NodeJS.ProcessEnv,\n request: string,\n signal: AbortSignal,\n): Promise<string> {\n signal.throwIfAborted();\n const child = spawn(executablePathForSpawn(command), args, {\n env,\n windowsHide: true,\n });\n // EOF requests graceful coordinator/worker cleanup on Windows as well as Unix.\n // Keep the control pipe open until completion or explicit cancellation.\n const cancel = () => child.stdin.end();\n let stdout = \"\";\n let stderr = \"\";\n let processError: Error | undefined;\n child.stdout.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stdout += chunk;\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk) => {\n stderr += chunk;\n });\n child.once(\"error\", (error) => {\n processError = error;\n });\n child.stdin.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (\n ![\"EPIPE\", \"ECONNRESET\", \"EOF\", \"ERR_STREAM_DESTROYED\"].includes(\n error.code ?? \"\",\n )\n )\n processError = error;\n });\n const result = new Promise<string>((resolve, reject) => {\n child.once(\"close\", (code) => {\n signal.removeEventListener(\"abort\", cancel);\n if (signal.aborted) reject(signal.reason);\n else if (processError) reject(processError);\n else if (code !== 0)\n reject(\n new CodexSecurityError(\n stderr.trim() || `Deep Scan engine exited with code ${code}.`,\n ),\n );\n else resolve(stdout);\n });\n });\n child.stdin.write(request + \"\\n\");\n signal.addEventListener(\"abort\", cancel, { once: true });\n if (signal.aborted) cancel();\n return result;\n}\n"]}
package/dist/errors.d.ts CHANGED
@@ -25,6 +25,8 @@ export declare class AuthenticationRequiredError extends CodexSecurityError {
25
25
  }
26
26
  export declare class PluginBootstrapError extends CodexSecurityError {
27
27
  }
28
+ export declare class LocalPluginBootstrapError extends PluginBootstrapError {
29
+ }
28
30
  export declare class PluginPythonUnavailableError extends PluginBootstrapError {
29
31
  }
30
32
  export declare class SandboxUnavailableError extends CodexSecurityError {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3E,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAKxD;AAED,kDAAkD;AAClD,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAmB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAGzD;CACF;AAED,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,aAAa,CAAC;AACnE,MAAM,MAAM,kCAAkC,GAC5C,YAAY,GAAG,eAAe,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,kCAAkC;IACjD,KAAK,EAAE,wBAAwB,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,kCAAkC,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,wBAAyB,SAAQ,kBAAkB;aAE5C,QAAQ,EAAE,QAAQ,CAAC,kCAAkC,CAAC;IADxE,YACkB,QAAQ,EAAE,QAAQ,CAAC,kCAAkC,CAAC,EACtE,aAAa,GAAE,MAAwB,EAKxC;CACF;AAED,qBAAa,kBAAmB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G;AAC/D,qBAAa,4BAA6B,SAAQ,oBAAoB;aAElD,SAAS,EAAE,MAAM;IADnC,YACkB,SAAS,EAAE,MAAM,EACjC,SAAS,GAAE,MAAM,GAAG,QAAiB,EAOtC;CACF;AACD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAEvE,qBAAa,8BAA+B,SAAQ,oBAAoB;aAEpD,eAAe,EAAE,MAAM;aACvB,aAAa,EAAE,MAAM;aACrB,QAAQ,EAAE,qBAAqB;IAHjD,YACkB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,QAAQ,GAAE,qBAAgC,EAK3D;CACF;AACD,qBAAa,mBAAoB,SAAQ,kBAAkB;CAAG;AAC9D,qBAAa,uBAAwB,SAAQ,kBAAkB;CAAG;AAClE,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC,YAAmB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAG1E;CACF;AAED,qBAAa,0BAA2B,SAAQ,oBAAoB;IAClE,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEzC,YACE,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACxB,OAAO,EAAE,MAAM,EAQhB;CACF"}
package/dist/errors.js CHANGED
@@ -27,6 +27,8 @@ export class AuthenticationRequiredError extends CodexSecurityError {
27
27
  }
28
28
  export class PluginBootstrapError extends CodexSecurityError {
29
29
  }
30
+ export class LocalPluginBootstrapError extends PluginBootstrapError {
31
+ }
30
32
  export class PluginPythonUnavailableError extends PluginBootstrapError {
31
33
  }
32
34
  export class SandboxUnavailableError extends CodexSecurityError {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.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EACjC,SAAS,GAAsB,MAAM;QAErC,KAAK,CACH,SAAS,KAAK,QAAQ;YACpB,CAAC,CAAC,yCAAyC,SAAS,oCAAoC;YACxF,CAAC,CAAC,uCAAuC,SAAS,8EAA8E,CACnI,CAAC;yBAPc,SAAS;IAQ3B,CAAC;CACF;AAGD,MAAM,OAAO,8BAA+B,SAAQ,oBAAoB;IAEpD,eAAe;IACf,aAAa;IACb,QAAQ;IAH1B,YACkB,eAAuB,EACvB,aAAqB,EACrB,QAAQ,GAA0B,QAAQ;QAE1D,KAAK,CACH,QAAQ,QAAQ,uDAAuD,eAAe,EAAE,CACzF,CAAC;+BANc,eAAe;6BACf,aAAa;wBACb,QAAQ;IAK1B,CAAC;CACF;AACD,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;CAAG;AAC9D,MAAM,OAAO,uBAAwB,SAAQ,kBAAkB;CAAG;AAClE,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1C,OAAO,CAAS;IAEhC,YAAmB,OAAe,EAAE,OAAe,EAAE,OAAsB;QACzE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,oBAAoB;IAClD,UAAU,CAAS;IACnB,IAAI,CAAqB;IAEzC,YACE,UAAkB,EAClB,IAAwB,EACxB,OAAe;QAEf,KAAK,CACH,+CAA+C,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,SAAS,CAAC,UAAU,CAAC,0BAA0B,cAAc,CAAC,IAAI,CAAC,+BAA+B,OAAO,GAAG,EACxM,OAAO,CACR,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { formatScanCost, formatUsd, type ScanCost } from \"./cost-model.js\";\n\n/** Returns the original error message without altering its contents. */\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nexport function abortReason(signal: AbortSignal): unknown {\n return (\n signal.reason ??\n new DOMException(\"The operation was aborted.\", \"AbortError\")\n );\n}\n\n/** Base error for Codex Security SDK failures. */\nexport class CodexSecurityError extends Error {\n public constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport type DeduplicationReviewStage = \"screening\" | \"pair-review\";\nexport type DeduplicationReviewFailureCategory =\n \"validation\" | \"no-submission\" | \"model\" | \"transport\" | \"refusal\";\n\nexport interface DeduplicationReviewFailureMetadata {\n stage: DeduplicationReviewStage;\n model: string;\n category: DeduplicationReviewFailureCategory;\n attempts: number;\n reason: string;\n}\n\nexport class DeduplicationReviewError extends CodexSecurityError {\n public constructor(\n public readonly metadata: Readonly<DeduplicationReviewFailureMetadata>,\n displayReason: string = metadata.reason,\n ) {\n super(\n `Codex did not complete a validated deduplication review. Findings are unchanged; retry the command. Reason: ${displayReason}`,\n );\n }\n}\n\nexport class ConfigurationError extends CodexSecurityError {}\nexport class AuthenticationRequiredError extends CodexSecurityError {}\nexport class PluginBootstrapError extends CodexSecurityError {}\nexport class PluginPythonUnavailableError extends PluginBootstrapError {}\nexport class SandboxUnavailableError extends CodexSecurityError {}\nexport class InvalidTargetError extends CodexSecurityError {}\nexport class OutputDirectoryError extends CodexSecurityError {}\nexport class OutputDirectoryNotEmptyError extends OutputDirectoryError {\n public constructor(\n public readonly directory: string,\n operation: \"scan\" | \"policy\" = \"scan\",\n ) {\n super(\n operation === \"policy\"\n ? `Policy output directory is not empty: ${directory}. Choose a new or empty directory.`\n : `Scan output directory is not empty: ${directory}. To keep the existing results and start a new scan, add --archive-existing.`,\n );\n }\n}\nexport type ProtectedScanPathKind = \"output\" | \"temporary\" | \"runtime\";\n\nexport class OutputInsideProtectedRootError extends OutputDirectoryError {\n public constructor(\n public readonly outputDirectory: string,\n public readonly protectedRoot: string,\n public readonly pathKind: ProtectedScanPathKind = \"output\",\n ) {\n super(\n `Scan ${pathKind} directory must be outside the protected scan root: ${outputDirectory}`,\n );\n }\n}\nexport class IncompleteScanError extends CodexSecurityError {}\nexport class ContractValidationError extends CodexSecurityError {}\nexport class ScanInterruptedError extends CodexSecurityError {\n public readonly scanDir: string;\n\n public constructor(message: string, scanDir: string, options?: ErrorOptions) {\n super(message, options);\n this.scanDir = scanDir;\n }\n}\n\nexport class ScanCostLimitExceededError extends ScanInterruptedError {\n public readonly maxCostUsd: number;\n public readonly cost: Readonly<ScanCost>;\n\n public constructor(\n maxCostUsd: number,\n cost: Readonly<ScanCost>,\n scanDir: string,\n ) {\n super(\n `Scan stopped: short-context budget baseline ${formatUsd(cost.estimatedUsd)} exceeded the ${formatUsd(maxCostUsd)} limit; estimated cost ${formatScanCost(cost)}; partial output remains at ${scanDir}.`,\n scanDir,\n );\n this.maxCostUsd = maxCostUsd;\n this.cost = cost;\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAE3E,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,OAAO,CACL,MAAM,CAAC,MAAM;QACb,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED,kDAAkD;AAClD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAmB,OAAe,EAAE,OAAsB;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;I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,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1C,OAAO,CAAS;IAEhC,YAAmB,OAAe,EAAE,OAAe,EAAE,OAAsB;QACzE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,oBAAoB;IAClD,UAAU,CAAS;IACnB,IAAI,CAAqB;IAEzC,YACE,UAAkB,EAClB,IAAwB,EACxB,OAAe;QAEf,KAAK,CACH,+CAA+C,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,SAAS,CAAC,UAAU,CAAC,0BAA0B,cAAc,CAAC,IAAI,CAAC,+BAA+B,OAAO,GAAG,EACxM,OAAO,CACR,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { formatScanCost, formatUsd, type ScanCost } from \"./cost-model.js\";\n\n/** Returns the original error message without altering its contents. */\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nexport function abortReason(signal: AbortSignal): unknown {\n return (\n signal.reason ??\n new DOMException(\"The operation was aborted.\", \"AbortError\")\n );\n}\n\n/** Base error for Codex Security SDK failures. */\nexport class CodexSecurityError extends Error {\n public constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport type DeduplicationReviewStage = \"screening\" | \"pair-review\";\nexport type DeduplicationReviewFailureCategory =\n \"validation\" | \"no-submission\" | \"model\" | \"transport\" | \"refusal\";\n\nexport interface DeduplicationReviewFailureMetadata {\n stage: DeduplicationReviewStage;\n model: string;\n category: DeduplicationReviewFailureCategory;\n attempts: number;\n reason: string;\n}\n\nexport class DeduplicationReviewError extends CodexSecurityError {\n public constructor(\n public readonly metadata: Readonly<DeduplicationReviewFailureMetadata>,\n displayReason: string = metadata.reason,\n ) {\n super(\n `Codex did not complete a validated deduplication review. Findings are unchanged; retry the command. Reason: ${displayReason}`,\n );\n }\n}\n\nexport class ConfigurationError extends CodexSecurityError {}\nexport class AuthenticationRequiredError extends CodexSecurityError {}\nexport class PluginBootstrapError extends CodexSecurityError {}\nexport class LocalPluginBootstrapError extends PluginBootstrapError {}\nexport class PluginPythonUnavailableError extends PluginBootstrapError {}\nexport class SandboxUnavailableError extends CodexSecurityError {}\nexport class InvalidTargetError extends CodexSecurityError {}\nexport class OutputDirectoryError extends CodexSecurityError {}\nexport class OutputDirectoryNotEmptyError extends OutputDirectoryError {\n public constructor(\n public readonly directory: string,\n operation: \"scan\" | \"policy\" = \"scan\",\n ) {\n super(\n operation === \"policy\"\n ? `Policy output directory is not empty: ${directory}. Choose a new or empty directory.`\n : `Scan output directory is not empty: ${directory}. To keep the existing results and start a new scan, add --archive-existing.`,\n );\n }\n}\nexport type ProtectedScanPathKind = \"output\" | \"temporary\" | \"runtime\";\n\nexport class OutputInsideProtectedRootError extends OutputDirectoryError {\n public constructor(\n public readonly outputDirectory: string,\n public readonly protectedRoot: string,\n public readonly pathKind: ProtectedScanPathKind = \"output\",\n ) {\n super(\n `Scan ${pathKind} directory must be outside the protected scan root: ${outputDirectory}`,\n );\n }\n}\nexport class IncompleteScanError extends CodexSecurityError {}\nexport class ContractValidationError extends CodexSecurityError {}\nexport class ScanInterruptedError extends CodexSecurityError {\n public readonly scanDir: string;\n\n public constructor(message: string, scanDir: string, options?: ErrorOptions) {\n super(message, options);\n this.scanDir = scanDir;\n }\n}\n\nexport class ScanCostLimitExceededError extends ScanInterruptedError {\n public readonly maxCostUsd: number;\n public readonly cost: Readonly<ScanCost>;\n\n public constructor(\n maxCostUsd: number,\n cost: Readonly<ScanCost>,\n scanDir: string,\n ) {\n super(\n `Scan stopped: short-context budget baseline ${formatUsd(cost.estimatedUsd)} exceeded the ${formatUsd(maxCostUsd)} limit; estimated cost ${formatScanCost(cost)}; partial output remains at ${scanDir}.`,\n scanDir,\n );\n this.maxCostUsd = maxCostUsd;\n this.cost = cost;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function executablePathForSpawn(command: string): string;
2
+ //# sourceMappingURL=executable-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-path.d.ts","sourceRoot":"","sources":["../src/executable-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ9D"}
@@ -0,0 +1,12 @@
1
+ /* Generated from plugin executable-path.ts. Run `pnpm generate:models`. */
2
+ import { win32 } from "node:path";
3
+ export function executablePathForSpawn(command) {
4
+ if (process.platform !== "win32" || !win32.isAbsolute(command))
5
+ return command;
6
+ // Root-relative paths still depend on the child's drive and working directory.
7
+ const root = win32.parse(command).root;
8
+ return root === "\\" || root === "/"
9
+ ? command
10
+ : win32.toNamespacedPath(command);
11
+ }
12
+ //# sourceMappingURL=executable-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-path.js","sourceRoot":"","sources":["../src/executable-path.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;QAC5D,OAAO,OAAO,CAAC;IACjB,+EAA+E;IAC/E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IACvC,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,GAAG;QAClC,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/* Generated from plugin executable-path.ts. Run `pnpm generate:models`. */\nimport { win32 } from \"node:path\";\n\nexport function executablePathForSpawn(command: string): string {\n if (process.platform !== \"win32\" || !win32.isAbsolute(command))\n return command;\n // Root-relative paths still depend on the child's drive and working directory.\n const root = win32.parse(command).root;\n return root === \"\\\\\" || root === \"/\"\n ? command\n : win32.toNamespacedPath(command);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type ChildProcessWithoutNullStreams, type SpawnOptionsWithoutStdio } from "node:child_process";
1
+ import { type StartCodex } from "./runtime.js";
2
2
  import { type ScanLogSource } from "./scan-logs.js";
3
3
  interface FeedbackOptions {
4
4
  reason: string;
@@ -8,9 +8,6 @@ interface FeedbackOptions {
8
8
  workingDirectory: string;
9
9
  signal?: AbortSignal;
10
10
  }
11
- type StartCodex = (command: string, args: readonly string[], options: SpawnOptionsWithoutStdio & {
12
- stdio: ["pipe", "pipe", "pipe"];
13
- }) => ChildProcessWithoutNullStreams;
14
11
  export declare function sendFeedback(options: FeedbackOptions, startCodex?: StartCodex): Promise<{
15
12
  feedbackId: string;
16
13
  scanId: string | null;