@openai/codex-security 0.1.31 → 0.3.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 (514) hide show
  1. package/README.md +442 -2434
  2. package/_bundled_plugin/.app.json +5 -1
  3. package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
  4. package/_bundled_plugin/.mcp.json +3 -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 +7 -214
  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 +563 -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 +5 -5
  25. package/_bundled_plugin/references/config-preflight.md +1 -5
  26. package/_bundled_plugin/references/core-scan.md +34 -10
  27. package/_bundled_plugin/references/final-report.md +13 -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 +3 -4
  31. package/_bundled_plugin/references/scan-contract.md +11 -6
  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 +2 -2
  36. package/_bundled_plugin/schemas/coverage.schema.json +23 -47
  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 +71 -192
  40. package/_bundled_plugin/schemas/scan-manifest.schema.json +83 -95
  41. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
  42. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
  43. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
  44. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
  45. package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
  46. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +245 -356
  47. package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
  48. package/_bundled_plugin/scripts/codex_session.mjs +53 -0
  49. package/_bundled_plugin/scripts/config_preflight.py +29 -69
  50. package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
  51. package/_bundled_plugin/scripts/deep_scan_workbench.py +208 -363
  52. package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
  53. package/_bundled_plugin/scripts/finalize_scan_contract.py +733 -375
  54. package/_bundled_plugin/scripts/finding_preview.py +81 -91
  55. package/_bundled_plugin/scripts/generate_in_scope_files.py +48 -102
  56. package/_bundled_plugin/scripts/generate_rank_input.py +117 -888
  57. package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -6
  58. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
  59. package/_bundled_plugin/scripts/rank_preview.py +43 -902
  60. package/_bundled_plugin/scripts/report_projection.py +143 -219
  61. package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
  62. package/_bundled_plugin/scripts/threat_model_projection.py +161 -0
  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 +59 -9
  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 +21 -6
  69. package/_bundled_plugin/scripts/workbench_cli.py +99 -190
  70. package/_bundled_plugin/scripts/workbench_constants.py +6 -14
  71. package/_bundled_plugin/scripts/workbench_db.py +524 -672
  72. package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
  73. package/_bundled_plugin/scripts/workbench_finding_index.py +20 -7
  74. package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
  75. package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
  76. package/_bundled_plugin/scripts/workbench_native_indexes.py +28 -18
  77. package/_bundled_plugin/scripts/workbench_progress.py +26 -92
  78. package/_bundled_plugin/scripts/workbench_publication.py +77 -116
  79. package/_bundled_plugin/scripts/workbench_remediation.py +14 -20
  80. package/_bundled_plugin/scripts/workbench_saved_results.py +1402 -263
  81. package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
  82. package/_bundled_plugin/scripts/workbench_scan_start.py +109 -52
  83. package/_bundled_plugin/scripts/workbench_scan_usage.py +30 -49
  84. package/_bundled_plugin/scripts/workbench_schema.py +71 -1370
  85. package/_bundled_plugin/scripts/workbench_source_excerpt.py +16 -7
  86. package/_bundled_plugin/scripts/workbench_target.py +526 -150
  87. package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
  88. package/_bundled_plugin/scripts/workbench_validation.py +19 -44
  89. package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
  90. package/_bundled_plugin/shared/workbench-migrations.json +397 -0
  91. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
  92. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
  93. package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
  94. package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
  95. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +6 -6
  96. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  97. package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
  98. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
  99. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
  100. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  101. package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
  102. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  103. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  104. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
  105. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  106. package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
  107. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  108. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
  109. package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
  110. package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
  111. package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
  112. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
  113. package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
  114. package/bin/codex-security.mjs +9 -2
  115. package/dist/api.d.ts +63 -15
  116. package/dist/api.d.ts.map +1 -1
  117. package/dist/api.js +970 -553
  118. package/dist/api.js.map +1 -1
  119. package/dist/artifact-export.d.ts +70 -0
  120. package/dist/artifact-export.d.ts.map +1 -0
  121. package/dist/artifact-export.js +292 -0
  122. package/dist/artifact-export.js.map +1 -0
  123. package/dist/auth.d.ts +2 -6
  124. package/dist/auth.d.ts.map +1 -1
  125. package/dist/auth.js +27 -12
  126. package/dist/auth.js.map +1 -1
  127. package/dist/bulk-scan-discovery.d.ts +1 -0
  128. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  129. package/dist/bulk-scan-discovery.js +9 -9
  130. package/dist/bulk-scan-discovery.js.map +1 -1
  131. package/dist/classify-scan-severity.d.ts.map +1 -1
  132. package/dist/classify-scan-severity.js +2 -5
  133. package/dist/classify-scan-severity.js.map +1 -1
  134. package/dist/classify-severity.d.ts +28 -17
  135. package/dist/classify-severity.d.ts.map +1 -1
  136. package/dist/classify-severity.js +16 -35
  137. package/dist/classify-severity.js.map +1 -1
  138. package/dist/cli-help.d.ts +3 -0
  139. package/dist/cli-help.d.ts.map +1 -0
  140. package/dist/cli-help.js +285 -0
  141. package/dist/cli-help.js.map +1 -0
  142. package/dist/cli-signals.d.ts +8 -0
  143. package/dist/cli-signals.d.ts.map +1 -0
  144. package/dist/cli-signals.js +28 -0
  145. package/dist/cli-signals.js.map +1 -0
  146. package/dist/cli.d.ts +22 -24
  147. package/dist/cli.d.ts.map +1 -1
  148. package/dist/cli.js +1660 -1556
  149. package/dist/cli.js.map +1 -1
  150. package/dist/cloud-publish.d.ts.map +1 -1
  151. package/dist/cloud-publish.js +11 -17
  152. package/dist/cloud-publish.js.map +1 -1
  153. package/dist/codeowners.d.ts +19 -0
  154. package/dist/codeowners.d.ts.map +1 -0
  155. package/dist/codeowners.js +138 -0
  156. package/dist/codeowners.js.map +1 -0
  157. package/dist/codex-prompt.d.ts.map +1 -1
  158. package/dist/codex-prompt.js +1 -2
  159. package/dist/codex-prompt.js.map +1 -1
  160. package/dist/codex-sdk-environment.d.ts +3 -0
  161. package/dist/codex-sdk-environment.d.ts.map +1 -0
  162. package/dist/codex-sdk-environment.js +68 -0
  163. package/dist/codex-sdk-environment.js.map +1 -0
  164. package/dist/component-plan.d.ts +2 -5
  165. package/dist/component-plan.d.ts.map +1 -1
  166. package/dist/component-plan.js +38 -34
  167. package/dist/component-plan.js.map +1 -1
  168. package/dist/component-scan.d.ts +7 -5
  169. package/dist/component-scan.d.ts.map +1 -1
  170. package/dist/component-scan.js +54 -44
  171. package/dist/component-scan.js.map +1 -1
  172. package/dist/config.d.ts.map +1 -1
  173. package/dist/config.js +93 -104
  174. package/dist/config.js.map +1 -1
  175. package/dist/contract.d.ts +15 -2
  176. package/dist/contract.d.ts.map +1 -1
  177. package/dist/contract.js +124 -348
  178. package/dist/contract.js.map +1 -1
  179. package/dist/cost-model.d.ts +13 -6
  180. package/dist/cost-model.d.ts.map +1 -1
  181. package/dist/cost-model.js +75 -34
  182. package/dist/cost-model.js.map +1 -1
  183. package/dist/cost.d.ts +10 -2
  184. package/dist/cost.d.ts.map +1 -1
  185. package/dist/cost.js +116 -134
  186. package/dist/cost.js.map +1 -1
  187. package/dist/custom-validation-prompt.d.ts.map +1 -1
  188. package/dist/custom-validation-prompt.js +7 -6
  189. package/dist/custom-validation-prompt.js.map +1 -1
  190. package/dist/custom-validation.d.ts +1 -2
  191. package/dist/custom-validation.d.ts.map +1 -1
  192. package/dist/custom-validation.js +23 -16
  193. package/dist/custom-validation.js.map +1 -1
  194. package/dist/deduplication/checkpointed-review.d.ts +4 -2
  195. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  196. package/dist/deduplication/checkpointed-review.js +33 -20
  197. package/dist/deduplication/checkpointed-review.js.map +1 -1
  198. package/dist/deduplication/codex-review.d.ts +9 -1
  199. package/dist/deduplication/codex-review.d.ts.map +1 -1
  200. package/dist/deduplication/codex-review.js +129 -20
  201. package/dist/deduplication/codex-review.js.map +1 -1
  202. package/dist/deduplication/deduplication-prompts.d.ts +5 -2
  203. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  204. package/dist/deduplication/deduplication-prompts.js +18 -4
  205. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  206. package/dist/deduplication/deduplication-reviewer.d.ts +26 -4
  207. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  208. package/dist/deduplication/deduplication-reviewer.js +59 -47
  209. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  210. package/dist/deduplication/deduplication.d.ts.map +1 -1
  211. package/dist/deduplication/deduplication.js +59 -113
  212. package/dist/deduplication/deduplication.js.map +1 -1
  213. package/dist/deduplication/diagnostics.d.ts +17 -0
  214. package/dist/deduplication/diagnostics.d.ts.map +1 -0
  215. package/dist/deduplication/diagnostics.js +5 -0
  216. package/dist/deduplication/diagnostics.js.map +1 -0
  217. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  218. package/dist/deduplication/finding-schema.js +7 -1
  219. package/dist/deduplication/finding-schema.js.map +1 -1
  220. package/dist/deduplication/local.d.ts +31 -0
  221. package/dist/deduplication/local.d.ts.map +1 -0
  222. package/dist/deduplication/local.js +166 -0
  223. package/dist/deduplication/local.js.map +1 -0
  224. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  225. package/dist/deduplication/records-protocol.js +12 -28
  226. package/dist/deduplication/records-protocol.js.map +1 -1
  227. package/dist/deduplication/records.d.ts +188 -12
  228. package/dist/deduplication/records.d.ts.map +1 -1
  229. package/dist/deduplication/records.js +34 -24
  230. package/dist/deduplication/records.js.map +1 -1
  231. package/dist/deduplication/review.d.ts +7 -0
  232. package/dist/deduplication/review.d.ts.map +1 -1
  233. package/dist/deduplication/review.js.map +1 -1
  234. package/dist/deduplication/scan.d.ts +9 -3
  235. package/dist/deduplication/scan.d.ts.map +1 -1
  236. package/dist/deduplication/scan.js +159 -44
  237. package/dist/deduplication/scan.js.map +1 -1
  238. package/dist/deep-config.d.ts +2 -1
  239. package/dist/deep-config.d.ts.map +1 -1
  240. package/dist/deep-config.js +7 -23
  241. package/dist/deep-config.js.map +1 -1
  242. package/dist/deep-progress.d.ts +2 -1
  243. package/dist/deep-progress.d.ts.map +1 -1
  244. package/dist/deep-progress.js +32 -47
  245. package/dist/deep-progress.js.map +1 -1
  246. package/dist/deep-scan.d.ts +20 -0
  247. package/dist/deep-scan.d.ts.map +1 -0
  248. package/dist/deep-scan.js +113 -0
  249. package/dist/deep-scan.js.map +1 -0
  250. package/dist/errors.d.ts +5 -2
  251. package/dist/errors.d.ts.map +1 -1
  252. package/dist/errors.js +7 -7
  253. package/dist/errors.js.map +1 -1
  254. package/dist/feedback.d.ts.map +1 -1
  255. package/dist/feedback.js +53 -21
  256. package/dist/feedback.js.map +1 -1
  257. package/dist/finding-catalogue.d.ts.map +1 -1
  258. package/dist/finding-catalogue.js +26 -30
  259. package/dist/finding-catalogue.js.map +1 -1
  260. package/dist/finding-normalization.d.ts +5 -0
  261. package/dist/finding-normalization.d.ts.map +1 -0
  262. package/dist/finding-normalization.js +120 -0
  263. package/dist/finding-normalization.js.map +1 -0
  264. package/dist/finding-retrieval.d.ts +9 -0
  265. package/dist/finding-retrieval.d.ts.map +1 -1
  266. package/dist/finding-retrieval.js.map +1 -1
  267. package/dist/finding-workflow.d.ts +13 -8
  268. package/dist/finding-workflow.d.ts.map +1 -1
  269. package/dist/finding-workflow.js +18 -13
  270. package/dist/finding-workflow.js.map +1 -1
  271. package/dist/findings-client.d.ts +2 -1
  272. package/dist/findings-client.d.ts.map +1 -1
  273. package/dist/findings-client.js +36 -9
  274. package/dist/findings-client.js.map +1 -1
  275. package/dist/findings-errors.d.ts +16 -0
  276. package/dist/findings-errors.d.ts.map +1 -0
  277. package/dist/findings-errors.js +24 -0
  278. package/dist/findings-errors.js.map +1 -0
  279. package/dist/findings-import.d.ts +1 -1
  280. package/dist/findings-import.d.ts.map +1 -1
  281. package/dist/findings-import.js +16 -44
  282. package/dist/findings-import.js.map +1 -1
  283. package/dist/github.d.ts.map +1 -1
  284. package/dist/github.js +9 -4
  285. package/dist/github.js.map +1 -1
  286. package/dist/import-scan.d.ts.map +1 -1
  287. package/dist/import-scan.js +49 -39
  288. package/dist/import-scan.js.map +1 -1
  289. package/dist/index.d.ts +11 -5
  290. package/dist/index.d.ts.map +1 -1
  291. package/dist/index.js +2 -1
  292. package/dist/index.js.map +1 -1
  293. package/dist/knowledge-base.d.ts +7 -1
  294. package/dist/knowledge-base.d.ts.map +1 -1
  295. package/dist/knowledge-base.js +115 -47
  296. package/dist/knowledge-base.js.map +1 -1
  297. package/dist/linear.d.ts.map +1 -1
  298. package/dist/linear.js +4 -10
  299. package/dist/linear.js.map +1 -1
  300. package/dist/mock-scan.d.ts.map +1 -1
  301. package/dist/mock-scan.js +0 -1
  302. package/dist/mock-scan.js.map +1 -1
  303. package/dist/models.d.ts +24 -2
  304. package/dist/models.d.ts.map +1 -1
  305. package/dist/models.js.map +1 -1
  306. package/dist/multiscan.d.ts +9 -3
  307. package/dist/multiscan.d.ts.map +1 -1
  308. package/dist/multiscan.js +225 -153
  309. package/dist/multiscan.js.map +1 -1
  310. package/dist/owner-evidence.d.ts +10 -2
  311. package/dist/owner-evidence.d.ts.map +1 -1
  312. package/dist/owner-evidence.js +69 -14
  313. package/dist/owner-evidence.js.map +1 -1
  314. package/dist/patch-tui.d.ts.map +1 -1
  315. package/dist/patch-tui.js +5 -6
  316. package/dist/patch-tui.js.map +1 -1
  317. package/dist/project-config-schema.d.ts +10 -0
  318. package/dist/project-config-schema.d.ts.map +1 -1
  319. package/dist/project-config-schema.js +1 -0
  320. package/dist/project-config-schema.js.map +1 -1
  321. package/dist/project-config.d.ts +1 -0
  322. package/dist/project-config.d.ts.map +1 -1
  323. package/dist/project-config.js +5 -3
  324. package/dist/project-config.js.map +1 -1
  325. package/dist/prompt-files.d.ts +0 -1
  326. package/dist/prompt-files.d.ts.map +1 -1
  327. package/dist/prompt-files.js +2 -4
  328. package/dist/prompt-files.js.map +1 -1
  329. package/dist/provider-profile.d.ts +21 -0
  330. package/dist/provider-profile.d.ts.map +1 -0
  331. package/dist/provider-profile.js +133 -0
  332. package/dist/provider-profile.js.map +1 -0
  333. package/dist/publication-events.d.ts +6 -8
  334. package/dist/publication-events.d.ts.map +1 -1
  335. package/dist/publication-events.js +40 -79
  336. package/dist/publication-events.js.map +1 -1
  337. package/dist/publication-store.d.ts.map +1 -1
  338. package/dist/publication-store.js +48 -76
  339. package/dist/publication-store.js.map +1 -1
  340. package/dist/publication.d.ts +1 -2
  341. package/dist/publication.d.ts.map +1 -1
  342. package/dist/publication.js +7 -16
  343. package/dist/publication.js.map +1 -1
  344. package/dist/publish.d.ts +1 -5
  345. package/dist/publish.d.ts.map +1 -1
  346. package/dist/publish.js +138 -199
  347. package/dist/publish.js.map +1 -1
  348. package/dist/record.d.ts +2 -0
  349. package/dist/record.d.ts.map +1 -0
  350. package/dist/record.js +4 -0
  351. package/dist/record.js.map +1 -0
  352. package/dist/request-metadata.d.ts +9 -0
  353. package/dist/request-metadata.d.ts.map +1 -0
  354. package/dist/request-metadata.js +13 -0
  355. package/dist/request-metadata.js.map +1 -0
  356. package/dist/result.d.ts +4 -1
  357. package/dist/result.d.ts.map +1 -1
  358. package/dist/result.js +7 -0
  359. package/dist/result.js.map +1 -1
  360. package/dist/runtime.d.ts +25 -17
  361. package/dist/runtime.d.ts.map +1 -1
  362. package/dist/runtime.js +619 -255
  363. package/dist/runtime.js.map +1 -1
  364. package/dist/saved-scan-bootstrap.d.ts +14 -0
  365. package/dist/saved-scan-bootstrap.d.ts.map +1 -0
  366. package/dist/saved-scan-bootstrap.js +261 -0
  367. package/dist/saved-scan-bootstrap.js.map +1 -0
  368. package/dist/saved-scan.d.ts +1 -1
  369. package/dist/saved-scan.d.ts.map +1 -1
  370. package/dist/saved-scan.js +16 -32
  371. package/dist/saved-scan.js.map +1 -1
  372. package/dist/scan-activity.d.ts.map +1 -1
  373. package/dist/scan-activity.js +19 -30
  374. package/dist/scan-activity.js.map +1 -1
  375. package/dist/scan-comparison.d.ts +31 -18
  376. package/dist/scan-comparison.d.ts.map +1 -1
  377. package/dist/scan-comparison.js +307 -347
  378. package/dist/scan-comparison.js.map +1 -1
  379. package/dist/scan-dashboard.d.ts +3 -1
  380. package/dist/scan-dashboard.d.ts.map +1 -1
  381. package/dist/scan-dashboard.js +351 -92
  382. package/dist/scan-dashboard.js.map +1 -1
  383. package/dist/scan-history-renderer.d.ts.map +1 -1
  384. package/dist/scan-history-renderer.js +55 -15
  385. package/dist/scan-history-renderer.js.map +1 -1
  386. package/dist/scan-inputs.d.ts +6 -0
  387. package/dist/scan-inputs.d.ts.map +1 -0
  388. package/dist/scan-inputs.js +71 -0
  389. package/dist/scan-inputs.js.map +1 -0
  390. package/dist/scan-logs.d.ts +2 -3
  391. package/dist/scan-logs.d.ts.map +1 -1
  392. package/dist/scan-logs.js +14 -12
  393. package/dist/scan-logs.js.map +1 -1
  394. package/dist/scan-sessions.d.ts +4 -0
  395. package/dist/scan-sessions.d.ts.map +1 -1
  396. package/dist/scan-sessions.js +18 -3
  397. package/dist/scan-sessions.js.map +1 -1
  398. package/dist/scan-settings.d.ts +5 -0
  399. package/dist/scan-settings.d.ts.map +1 -1
  400. package/dist/scan-settings.js +4 -0
  401. package/dist/scan-settings.js.map +1 -1
  402. package/dist/scan-skill-paths.d.ts +8 -0
  403. package/dist/scan-skill-paths.d.ts.map +1 -0
  404. package/dist/scan-skill-paths.js +47 -0
  405. package/dist/scan-skill-paths.js.map +1 -0
  406. package/dist/security-policy-cli.d.ts.map +1 -1
  407. package/dist/security-policy-cli.js +15 -33
  408. package/dist/security-policy-cli.js.map +1 -1
  409. package/dist/security-policy.d.ts +17 -9
  410. package/dist/security-policy.d.ts.map +1 -1
  411. package/dist/security-policy.js +131 -98
  412. package/dist/security-policy.js.map +1 -1
  413. package/dist/server/api.d.ts +0 -1
  414. package/dist/server/api.d.ts.map +1 -1
  415. package/dist/server/api.js +0 -1
  416. package/dist/server/api.js.map +1 -1
  417. package/dist/server/embeddings.d.ts +3 -1
  418. package/dist/server/embeddings.d.ts.map +1 -1
  419. package/dist/server/embeddings.js +11 -3
  420. package/dist/server/embeddings.js.map +1 -1
  421. package/dist/server/errors.d.ts +5 -2
  422. package/dist/server/errors.d.ts.map +1 -1
  423. package/dist/server/errors.js +7 -0
  424. package/dist/server/errors.js.map +1 -1
  425. package/dist/server/sqlite-store.d.ts +0 -2
  426. package/dist/server/sqlite-store.d.ts.map +1 -1
  427. package/dist/server/sqlite-store.js +55 -55
  428. package/dist/server/sqlite-store.js.map +1 -1
  429. package/dist/server/storage.d.ts +0 -2
  430. package/dist/server/storage.d.ts.map +1 -1
  431. package/dist/server/storage.js.map +1 -1
  432. package/dist/severity-store.js +20 -32
  433. package/dist/severity-store.js.map +1 -1
  434. package/dist/standalone-validation-prompt.d.ts +2 -0
  435. package/dist/standalone-validation-prompt.d.ts.map +1 -0
  436. package/dist/standalone-validation-prompt.js +10 -0
  437. package/dist/standalone-validation-prompt.js.map +1 -0
  438. package/dist/suggest-owners.d.ts +6 -5
  439. package/dist/suggest-owners.d.ts.map +1 -1
  440. package/dist/suggest-owners.js +15 -10
  441. package/dist/suggest-owners.js.map +1 -1
  442. package/dist/targets.d.ts +12 -0
  443. package/dist/targets.d.ts.map +1 -1
  444. package/dist/targets.js +124 -62
  445. package/dist/targets.js.map +1 -1
  446. package/dist/trusted-executable.d.ts +6 -1
  447. package/dist/trusted-executable.d.ts.map +1 -1
  448. package/dist/trusted-executable.js +28 -9
  449. package/dist/trusted-executable.js.map +1 -1
  450. package/dist/value.d.ts +2 -0
  451. package/dist/value.d.ts.map +1 -0
  452. package/dist/value.js +27 -0
  453. package/dist/value.js.map +1 -0
  454. package/dist/version.d.ts.map +1 -1
  455. package/dist/version.js +3 -6
  456. package/dist/version.js.map +1 -1
  457. package/dist/windows-path.d.ts.map +1 -1
  458. package/dist/windows-path.js +1 -2
  459. package/dist/windows-path.js.map +1 -1
  460. package/dist/workbench-arguments.d.ts +3 -0
  461. package/dist/workbench-arguments.d.ts.map +1 -0
  462. package/dist/workbench-arguments.js +15 -0
  463. package/dist/workbench-arguments.js.map +1 -0
  464. package/dist/worker-progress.d.ts +2 -0
  465. package/dist/worker-progress.d.ts.map +1 -1
  466. package/dist/worker-progress.js +40 -46
  467. package/dist/worker-progress.js.map +1 -1
  468. package/docs/cli.md +1778 -0
  469. package/docs/dedupe-records.md +24 -0
  470. package/docs/findings-service.md +402 -0
  471. package/package.json +23 -23
  472. package/schemas/project-config.schema.json +5 -0
  473. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
  474. package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
  475. package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
  476. package/_bundled_plugin/scripts/workbench_findings.py +0 -221
  477. package/_bundled_plugin/scripts/workbench_severity.py +0 -119
  478. package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
  479. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
  480. package/dist/server/dashboard/app.css +0 -2
  481. package/dist/server/dashboard/app.js +0 -66
  482. package/dist/server/dashboard/index.html +0 -18
  483. package/dist/server/dashboard-types.d.ts +0 -48
  484. package/dist/server/dashboard-types.d.ts.map +0 -1
  485. package/dist/server/dashboard-types.js +0 -2
  486. package/dist/server/dashboard-types.js.map +0 -1
  487. package/dist/server/dashboard.d.ts +0 -6
  488. package/dist/server/dashboard.d.ts.map +0 -1
  489. package/dist/server/dashboard.js +0 -59
  490. package/dist/server/dashboard.js.map +0 -1
  491. package/dist/server/findings-service.d.ts +0 -20
  492. package/dist/server/findings-service.d.ts.map +0 -1
  493. package/dist/server/findings-service.js +0 -31
  494. package/dist/server/findings-service.js.map +0 -1
  495. package/dist/server/index.d.ts +0 -2
  496. package/dist/server/index.d.ts.map +0 -1
  497. package/dist/server/index.js +0 -6
  498. package/dist/server/index.js.map +0 -1
  499. package/dist/server/routes.d.ts +0 -6
  500. package/dist/server/routes.d.ts.map +0 -1
  501. package/dist/server/routes.js +0 -86
  502. package/dist/server/routes.js.map +0 -1
  503. package/dist/server/serve.d.ts +0 -2
  504. package/dist/server/serve.d.ts.map +0 -1
  505. package/dist/server/serve.js +0 -28
  506. package/dist/server/serve.js.map +0 -1
  507. package/dist/server/server.d.ts +0 -10
  508. package/dist/server/server.d.ts.map +0 -1
  509. package/dist/server/server.js +0 -17
  510. package/dist/server/server.js.map +0 -1
  511. package/dist/server/validation.d.ts +0 -17
  512. package/dist/server/validation.d.ts.map +0 -1
  513. package/dist/server/validation.js +0 -53
  514. package/dist/server/validation.js.map +0 -1
@@ -1,72 +1,67 @@
1
+ import { isRecord } from "./record.js";
2
+ import { isSafeNonNegativeInteger } from "./value.js";
1
3
  const DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;
2
4
  export class DeepScanProgressTracker {
3
5
  #options;
4
6
  #timer = null;
5
7
  #pending = null;
6
- #abortController = null;
8
+ #abortController = new AbortController();
7
9
  #lastProgress = null;
8
- #stopped = false;
9
10
  constructor(options) {
10
11
  this.#options = options;
11
12
  }
12
13
  start() {
13
- if (this.#timer !== null || this.#stopped)
14
+ if (this.#timer !== null || this.#abortController.signal.aborted)
14
15
  return;
15
16
  const poll = () => {
16
17
  void this.refresh().catch((error) => {
17
18
  this.#options.onError?.(error);
18
19
  });
19
20
  };
20
- this.#timer = setInterval(poll, this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS);
21
+ this.#timer = setInterval(poll, DEEP_PROGRESS_POLL_INTERVAL_MS);
21
22
  this.#timer.unref();
22
23
  poll();
23
24
  }
24
25
  async refresh() {
25
- if (this.#stopped)
26
+ if (this.#abortController.signal.aborted)
26
27
  return;
27
28
  if (this.#pending !== null)
28
29
  return await this.#pending;
29
- const abortController = new AbortController();
30
- this.#abortController = abortController;
30
+ const abortController = this.#abortController;
31
31
  let update = null;
32
32
  update = (async () => {
33
33
  try {
34
34
  const progress = deepScanProgressFromWorkbench(await this.#options.read(abortController.signal));
35
- if (this.#stopped ||
36
- abortController.signal.aborted ||
35
+ if (abortController.signal.aborted ||
37
36
  progress === null ||
38
- sameProgress(progress, this.#lastProgress)) {
37
+ (progress.completed === this.#lastProgress?.completed &&
38
+ progress.active === this.#lastProgress?.active &&
39
+ progress.maximum === this.#lastProgress?.maximum &&
40
+ progress.consolidating === this.#lastProgress?.consolidating)) {
39
41
  return;
40
42
  }
41
43
  this.#lastProgress = progress;
42
44
  this.#options.onProgress(progress);
43
45
  }
44
46
  catch (error) {
45
- if (this.#stopped || abortController.signal.aborted)
47
+ if (abortController.signal.aborted)
46
48
  return;
47
49
  throw error;
48
50
  }
49
51
  finally {
50
52
  if (this.#pending === update)
51
53
  this.#pending = null;
52
- if (this.#abortController === abortController) {
53
- this.#abortController = null;
54
- }
55
54
  }
56
55
  })();
57
56
  this.#pending = update;
58
57
  await update;
59
58
  }
60
59
  stop() {
61
- if (this.#stopped)
60
+ if (this.#abortController.signal.aborted)
62
61
  return;
63
- this.#stopped = true;
64
- if (this.#timer !== null) {
65
- clearInterval(this.#timer);
66
- this.#timer = null;
67
- }
68
- this.#abortController?.abort();
69
- this.#abortController = null;
62
+ clearInterval(this.#timer ?? undefined);
63
+ this.#timer = null;
64
+ this.#abortController.abort();
70
65
  }
71
66
  }
72
67
  export function deepScanProgressFromWorkbench(result) {
@@ -78,31 +73,21 @@ export function deepScanProgressFromWorkbench(result) {
78
73
  const independentReviews = progress["independentReviews"];
79
74
  if (independentReviews === undefined)
80
75
  return null;
81
- if (!isRecord(independentReviews) ||
82
- !isCount(independentReviews["completed"]) ||
83
- !isCount(independentReviews["active"]) ||
84
- !isPositiveCount(independentReviews["maximum"])) {
85
- throw new Error("Codex Security workbench returned invalid Deep Scan progress.");
76
+ if (isRecord(independentReviews)) {
77
+ const { completed, active, maximum, consolidating } = independentReviews;
78
+ if (isSafeNonNegativeInteger(completed) &&
79
+ isSafeNonNegativeInteger(active) &&
80
+ isSafeNonNegativeInteger(maximum) &&
81
+ maximum > 0 &&
82
+ (consolidating === undefined || typeof consolidating === "boolean")) {
83
+ return {
84
+ completed,
85
+ active,
86
+ maximum,
87
+ ...(typeof consolidating === "boolean" ? { consolidating } : {}),
88
+ };
89
+ }
86
90
  }
87
- return {
88
- completed: independentReviews["completed"],
89
- active: independentReviews["active"],
90
- maximum: independentReviews["maximum"],
91
- };
92
- }
93
- function sameProgress(left, right) {
94
- return (right !== null &&
95
- left.completed === right.completed &&
96
- left.active === right.active &&
97
- left.maximum === right.maximum);
98
- }
99
- function isCount(value) {
100
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
101
- }
102
- function isPositiveCount(value) {
103
- return isCount(value) && value > 0;
104
- }
105
- function isRecord(value) {
106
- return value !== null && typeof value === "object" && !Array.isArray(value);
91
+ throw new Error("Codex Security workbench returned invalid Deep Scan progress.");
107
92
  }
108
93
  //# sourceMappingURL=deep-progress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAaA,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IACtC,gBAAgB,GAA2B,IAAI,CAAC;IAChD,aAAa,GAA4B,IAAI,CAAC;IAC9C,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAClD,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,MAA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,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC;QAC1C,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QACpC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC;KACvC,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;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["export 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 pollIntervalMs?: number;\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 #abortController: AbortController | null = null;\n #lastProgress: DeepScanProgress | null = null;\n #stopped = false;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#stopped) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(\n poll,\n this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS,\n );\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#stopped) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = new AbortController();\n this.#abortController = 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 this.#stopped ||\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 (this.#stopped || abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n if (this.#abortController === abortController) {\n this.#abortController = null;\n }\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#stopped) return;\n this.#stopped = true;\n if (this.#timer !== null) {\n clearInterval(this.#timer);\n this.#timer = null;\n }\n this.#abortController?.abort();\n this.#abortController = null;\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 (\n !isRecord(independentReviews) ||\n !isCount(independentReviews[\"completed\"]) ||\n !isCount(independentReviews[\"active\"]) ||\n !isPositiveCount(independentReviews[\"maximum\"])\n ) {\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n }\n return {\n completed: independentReviews[\"completed\"],\n active: independentReviews[\"active\"],\n maximum: independentReviews[\"maximum\"],\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\nfunction isCount(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction isPositiveCount(value: unknown): value is number {\n return isCount(value) && value > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\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,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAgBtD,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,IAA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CAAC,OAAO,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACjE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,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 /** 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 if (isRecord(independentReviews)) {\n const { completed, active, maximum, consolidating } = independentReviews;\n if (\n isSafeNonNegativeInteger(completed) &&\n isSafeNonNegativeInteger(active) &&\n isSafeNonNegativeInteger(maximum) &&\n maximum > 0 &&\n (consolidating === undefined || typeof consolidating === \"boolean\")\n ) {\n return {\n completed,\n active,\n maximum,\n ...(typeof consolidating === \"boolean\" ? { consolidating } : {}),\n };\n }\n }\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;A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AAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,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
@@ -1,8 +1,7 @@
1
1
  import { type ScanCost } from "./cost-model.js";
2
2
  /** Returns the original error message without altering its contents. */
3
3
  export declare function errorMessage(error: unknown): string;
4
- /** Omit credential-bearing messages at persistence and display boundaries. */
5
- export declare function safeErrorMessage(error: unknown): string;
4
+ export declare function abortReason(signal: AbortSignal): unknown;
6
5
  /** Base error for Codex Security SDK failures. */
7
6
  export declare class CodexSecurityError extends Error {
8
7
  constructor(message: string, options?: ErrorOptions);
@@ -26,8 +25,12 @@ export declare class AuthenticationRequiredError extends CodexSecurityError {
26
25
  }
27
26
  export declare class PluginBootstrapError extends CodexSecurityError {
28
27
  }
28
+ export declare class LocalPluginBootstrapError extends PluginBootstrapError {
29
+ }
29
30
  export declare class PluginPythonUnavailableError extends PluginBootstrapError {
30
31
  }
32
+ export declare class SandboxUnavailableError extends CodexSecurityError {
33
+ }
31
34
  export declare class InvalidTargetError extends CodexSecurityError {
32
35
  }
33
36
  export declare class OutputDirectoryError 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,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAevD;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,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U,EAAE,MAAM,EAClB,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACxB,OAAO,EAAE,MAAM,EAQhB;CACF"}
package/dist/errors.js CHANGED
@@ -3,13 +3,9 @@ import { formatScanCost, formatUsd } from "./cost-model.js";
3
3
  export function errorMessage(error) {
4
4
  return error instanceof Error ? error.message : String(error);
5
5
  }
6
- /** Omit credential-bearing messages at persistence and display boundaries. */
7
- export function safeErrorMessage(error) {
8
- const message = errorMessage(error);
9
- const recognizableCredential = /(?:\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\S+|\b(?:bearer|basic|token)(?:\s|%20|\+)+\S+|:\/\/[^\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(message);
10
- const assignments = message.matchAll(/(?<![\w%.-])[\w%.-]+(?:\\*["']|\]|%5d)*\s*(?:[:=]|%3[ad])/giu);
11
- const sensitiveField = Array.from(assignments).some(([field]) => /(?:api(?:[_-]|%5f|%2d)?key|access(?:[_-]|%5f|%2d)?key|private(?:[_-]|%5f|%2d)?key|authorization|auth(?!or)|token|secret|credential|signature|sig(?=[^A-Za-z0-9]|value|data|token|secret|credential|password|header|field|id|key|$)|password|passwd)/iu.test(field));
12
- return recognizableCredential || sensitiveField ? "[redacted]" : message;
6
+ export function abortReason(signal) {
7
+ return (signal.reason ??
8
+ new DOMException("The operation was aborted.", "AbortError"));
13
9
  }
14
10
  /** Base error for Codex Security SDK failures. */
15
11
  export class CodexSecurityError extends Error {
@@ -31,8 +27,12 @@ export class AuthenticationRequiredError extends CodexSecurityError {
31
27
  }
32
28
  export class PluginBootstrapError extends CodexSecurityError {
33
29
  }
30
+ export class LocalPluginBootstrapError extends PluginBootstrapError {
31
+ }
34
32
  export class PluginPythonUnavailableError extends PluginBootstrapError {
35
33
  }
34
+ export class SandboxUnavailableError extends CodexSecurityError {
35
+ }
36
36
  export class InvalidTargetError extends CodexSecurityError {
37
37
  }
38
38
  export class OutputDirectoryError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;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\n/** Omit credential-bearing messages at persistence and display boundaries. */\nexport function safeErrorMessage(error: unknown): string {\n const message = errorMessage(error);\n const recognizableCredential =\n /(?:\\b(?:sk-(?:proj-)?|github_pat_|gh[pousr]_|npm_)\\S+|\\b(?:bearer|basic|token)(?:\\s|%20|\\+)+\\S+|:\\/\\/[^\\s/@]+@|-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----)/iu.test(\n message,\n );\n const assignments = message.matchAll(\n /(?<![\\w%.-])[\\w%.-]+(?:\\\\*[\"']|\\]|%5d)*\\s*(?:[:=]|%3[ad])/giu,\n );\n const sensitiveField = Array.from(assignments).some(([field]) =>\n /(?:api(?:[_-]|%5f|%2d)?key|access(?:[_-]|%5f|%2d)?key|private(?:[_-]|%5f|%2d)?key|authorization|auth(?!or)|token|secret|credential|signature|sig(?=[^A-Za-z0-9]|value|data|token|secret|credential|password|header|field|id|key|$)|password|passwd)/iu.test(\n field,\n ),\n );\n return recognizableCredential || sensitiveField ? \"[redacted]\" : message;\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 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;IAC9B,CAAC;CACF;AAcD,MAAM,OAAO,wBAAyB,SAAQ,kBAAkB;IAE5C,QAAQ;IAD1B,YACkB,QAAsD,EACtE,aAAa,GAAW,QAAQ,CAAC,MAAM;QAEvC,KAAK,CACH,+GAA+G,aAAa,EAAE,CAC/H,CAAC;wBALc,QAAQ;IAM1B,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;CAAG;AAC7D,MAAM,OAAO,2BAA4B,SAAQ,kBAAkB;CAAG;AACtE,MAAM,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Ae;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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQvE,UAAU,eAAe;IACvB,MAAM,EAA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back.js CHANGED
@@ -45,17 +45,39 @@ export async function sendFeedback(options, startCodex = spawn) {
45
45
  signal: options.signal,
46
46
  });
47
47
  const uploaded = Promise.withResolvers();
48
+ let stderr = "";
49
+ let stdinError;
48
50
  const closed = new Promise((resolve) => {
49
51
  child.once("close", () => {
50
- uploaded.reject(new CodexSecurityError("Codex exited before feedback was uploaded."));
52
+ uploaded.reject(new CodexSecurityError(stderr || "Codex exited before feedback was uploaded."));
51
53
  resolve();
52
54
  });
53
55
  });
54
56
  child.once("error", uploaded.reject);
55
- child.stdin.on("error", uploaded.reject);
56
- child.stderr.resume();
57
+ child.stdin.on("error", (error) => {
58
+ stdinError ??= error;
59
+ uploaded.reject(error);
60
+ });
61
+ child.stderr.setEncoding("utf8").on("data", (chunk) => {
62
+ stderr += chunk;
63
+ });
57
64
  const send = (message) => child.stdin.write(`${JSON.stringify(message)}\n`);
58
65
  const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
66
+ const releaseCanceledPipes = () => {
67
+ if (!options.signal?.aborted)
68
+ return;
69
+ uploaded.reject(options.signal.reason);
70
+ if (child.exitCode === null && child.signalCode === null)
71
+ return;
72
+ lines.close();
73
+ child.stdin.destroy();
74
+ child.stdout.destroy();
75
+ child.stderr.destroy();
76
+ };
77
+ options.signal?.addEventListener("abort", releaseCanceledPipes, {
78
+ once: true,
79
+ });
80
+ child.once("exit", releaseCanceledPipes);
59
81
  lines.on("line", (line) => {
60
82
  try {
61
83
  const message = JSON.parse(line);
@@ -103,29 +125,39 @@ export async function sendFeedback(options, startCodex = spawn) {
103
125
  }
104
126
  });
105
127
  try {
106
- send({
107
- id: 1,
108
- method: "initialize",
109
- params: { clientInfo: { name: "codex-security", version: VERSION } },
110
- });
111
- return {
112
- feedbackId: await uploaded.promise,
113
- scanId: scan?.scanId ?? null,
114
- includedLogs: includeLogs,
115
- };
116
- }
117
- finally {
118
- lines.close();
119
- child.stdin.end();
120
- child.kill();
121
- const timer = setTimeout(() => child.kill("SIGKILL"), 1_000);
122
128
  try {
123
- await closed;
129
+ send({
130
+ id: 1,
131
+ method: "initialize",
132
+ params: { clientInfo: { name: "codex-security", version: VERSION } },
133
+ });
134
+ return {
135
+ feedbackId: await uploaded.promise,
136
+ scanId: scan?.scanId ?? null,
137
+ includedLogs: includeLogs,
138
+ };
124
139
  }
125
140
  finally {
126
- clearTimeout(timer);
141
+ lines.close();
142
+ child.stdin.end();
143
+ child.kill();
144
+ const timer = setTimeout(() => child.kill("SIGKILL"), 1_000);
145
+ try {
146
+ await closed;
147
+ }
148
+ finally {
149
+ clearTimeout(timer);
150
+ options.signal?.removeEventListener("abort", releaseCanceledPipes);
151
+ child.removeListener("exit", releaseCanceledPipes);
152
+ }
127
153
  }
128
154
  }
155
+ catch (error) {
156
+ options.signal?.throwIfAborted();
157
+ if (error === stdinError && stderr)
158
+ throw new CodexSecurityError(stderr, { cause: error });
159
+ throw error;
160
+ }
129
161
  }
130
162
  finally {
131
163
  if (directory !== undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"feedback.js","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAGN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACL,sBAAsB,EACtB,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T,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import {\n spawn,\n type ChildProcessWithoutNullStreams,\n type SpawnOptionsWithoutStdio,\n} from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n codexSecurityCredentialHome,\n executablePathForSpawn,\n resolveCodexCommand,\n} from \"./runtime.js\";\nimport { readSavedScanLogs, type ScanLogSource } from \"./scan-logs.js\";\nimport {\n BUNDLED_PLUGIN_VERSION,\n CODEX_EXECUTABLE_VERSION,\n CODEX_SDK_VERSION,\n VERSION,\n} from \"./version.js\";\n\ninterface FeedbackOptions {\n reason: string;\n includeLogs: boolean;\n scan?: ScanLogSource;\n environment: NodeJS.ProcessEnv;\n workingDirectory: string;\n signal?: AbortSignal;\n}\n\ntype StartCodex = (\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithoutStdio & { stdio: [\"pipe\", \"pipe\", \"pipe\"] },\n) => ChildProcessWithoutNullStreams;\n\nexport async function sendFeedback(\n options: FeedbackOptions,\n startCodex: StartCodex = spawn,\n) {\n const { scan, environment, includeLogs } = options;\n options.signal?.throwIfAborted();\n const codexHome = codexSecurityCredentialHome(environment);\n const config = await readCodexHomeConfig(environment);\n const feedback = config[\"feedback\"] as { enabled?: boolean } | undefined;\n if (feedback?.enabled === false) {\n throw new CodexSecurityError(\n \"Sending feedback is disabled by configuration.\",\n );\n }\n\n let directory: string | undefined;\n try {\n const extraLogFiles: string[] = [];\n if (includeLogs && scan !== undefined) {\n try {\n const logs = await readSavedScanLogs(\n scan,\n [codexHome, configuredCodexHome(environment)],\n { allowMissingRoot: true },\n );\n if (logs.sessions.length > 0) {\n directory = await mkdtemp(join(tmpdir(), \"codex-security-feedback-\"));\n const path = join(directory, \"scan-logs.json\");\n await writeFile(path, JSON.stringify(logs), { mode: 0o600 });\n extraLogFiles.push(path);\n }\n } catch {\n options.signal?.throwIfAborted();\n console.warn(\n \"Codex Security could not attach saved scan logs; sending feedback with available Codex logs.\",\n );\n }\n }\n\n options.signal?.throwIfAborted();\n const command = resolveCodexCommand(environment);\n const child = startCodex(\n executablePathForSpawn(command.command),\n [\"app-server\", \"--stdio\"],\n {\n cwd: options.workingDirectory,\n env: { ...environment, CODEX_HOME: codexHome },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n const uploaded = Promise.withResolvers<string>();\n const closed = new Promise<void>((resolve) => {\n child.once(\"close\", () => {\n uploaded.reject(\n new CodexSecurityError(\"Codex exited before feedback was uploaded.\"),\n );\n resolve();\n });\n });\n child.once(\"error\", uploaded.reject);\n child.stdin.on(\"error\", uploaded.reject);\n child.stderr.resume();\n const send = (message: object) =>\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });\n lines.on(\"line\", (line) => {\n try {\n const message = JSON.parse(line) as {\n id?: number;\n method?: string;\n error?: { message: string };\n result?: { threadId?: string };\n };\n if (message.method !== undefined || message.id === undefined) return;\n if (message.error) throw new CodexSecurityError(message.error.message);\n if (message.id === 1) {\n send({ method: \"initialized\" });\n send({\n id: 2,\n method: \"feedback/upload\",\n params: {\n classification: \"bug\",\n reason: options.reason,\n // Codex also collects this thread's descendants. Shared owners\n // belong only in the explicit attachment, not in that subtree.\n threadId:\n !includeLogs ||\n scan?.executionThreadIds?.includes(\n scan.continuationThreadId ?? \"\",\n )\n ? scan?.continuationThreadId\n : undefined,\n includeLogs,\n extraLogFiles,\n tags: {\n codex_security_version: VERSION,\n codex_security_plugin_version: BUNDLED_PLUGIN_VERSION,\n codex_security_codex_version: CODEX_EXECUTABLE_VERSION,\n codex_security_sdk_version: CODEX_SDK_VERSION,\n ...(scan === undefined\n ? {}\n : { codex_security_scan_id: scan.scanId }),\n },\n },\n });\n } else if (message.id === 2) {\n const feedbackId = message.result?.threadId;\n if (!feedbackId)\n throw new CodexSecurityError(\"Codex did not return a feedback ID.\");\n uploaded.resolve(feedbackId);\n }\n } catch (error) {\n uploaded.reject(error);\n }\n });\n try {\n send({\n id: 1,\n method: \"initialize\",\n params: { clientInfo: { name: \"codex-security\", version: VERSION } },\n });\n return {\n feedbackId: await uploaded.promise,\n scanId: scan?.scanId ?? null,\n includedLogs: includeLogs,\n };\n } finally {\n lines.close();\n child.stdin.end();\n child.kill();\n const timer = setTimeout(() => child.kill(\"SIGKILL\"), 1_000);\n try {\n await closed;\n } finally {\n clearTimeout(timer);\n }\n }\n } finally {\n if (directory !== undefined)\n await rm(directory, { recursive: true, force: true });\n }\n}\n"]}
1
+ {"version":3,"file":"feedback.js","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAGN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,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,EAAE,CAAC;YACf,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YACjC,IAAI,KAAK,KAAK,UAAU,IAAI,MAAM;gBAChC,MAAM,IAAI,kBAAkB,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACzD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import {\n spawn,\n type ChildProcessWithoutNullStreams,\n type SpawnOptionsWithoutStdio,\n} from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n codexSecurityCredentialHome,\n executablePathForSpawn,\n resolveCodexCommand,\n} from \"./runtime.js\";\nimport { readSavedScanLogs, type ScanLogSource } from \"./scan-logs.js\";\nimport {\n BUNDLED_PLUGIN_VERSION,\n CODEX_EXECUTABLE_VERSION,\n CODEX_SDK_VERSION,\n VERSION,\n} from \"./version.js\";\n\ninterface FeedbackOptions {\n reason: string;\n includeLogs: boolean;\n scan?: ScanLogSource;\n environment: NodeJS.ProcessEnv;\n workingDirectory: string;\n signal?: AbortSignal;\n}\n\ntype StartCodex = (\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithoutStdio & { stdio: [\"pipe\", \"pipe\", \"pipe\"] },\n) => ChildProcessWithoutNullStreams;\n\nexport async function sendFeedback(\n options: FeedbackOptions,\n startCodex: StartCodex = spawn,\n) {\n const { scan, environment, includeLogs } = options;\n options.signal?.throwIfAborted();\n const codexHome = codexSecurityCredentialHome(environment);\n const config = await readCodexHomeConfig(environment);\n const feedback = config[\"feedback\"] as { enabled?: boolean } | undefined;\n if (feedback?.enabled === false) {\n throw new CodexSecurityError(\n \"Sending feedback is disabled by configuration.\",\n );\n }\n\n let directory: string | undefined;\n try {\n const extraLogFiles: string[] = [];\n if (includeLogs && scan !== undefined) {\n try {\n const logs = await readSavedScanLogs(\n scan,\n [codexHome, configuredCodexHome(environment)],\n { allowMissingRoot: true },\n );\n if (logs.sessions.length > 0) {\n directory = await mkdtemp(join(tmpdir(), \"codex-security-feedback-\"));\n const path = join(directory, \"scan-logs.json\");\n await writeFile(path, JSON.stringify(logs), { mode: 0o600 });\n extraLogFiles.push(path);\n }\n } catch {\n options.signal?.throwIfAborted();\n console.warn(\n \"Codex Security could not attach saved scan logs; sending feedback with available Codex logs.\",\n );\n }\n }\n\n options.signal?.throwIfAborted();\n const command = resolveCodexCommand(environment);\n const child = startCodex(\n executablePathForSpawn(command.command),\n [\"app-server\", \"--stdio\"],\n {\n cwd: options.workingDirectory,\n env: { ...environment, CODEX_HOME: codexHome },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n const uploaded = Promise.withResolvers<string>();\n let stderr = \"\";\n let stdinError: Error | undefined;\n const closed = new Promise<void>((resolve) => {\n child.once(\"close\", () => {\n uploaded.reject(\n new CodexSecurityError(\n stderr || \"Codex exited before feedback was uploaded.\",\n ),\n );\n resolve();\n });\n });\n child.once(\"error\", uploaded.reject);\n child.stdin.on(\"error\", (error: Error) => {\n stdinError ??= error;\n uploaded.reject(error);\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n const send = (message: object) =>\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });\n const releaseCanceledPipes = () => {\n if (!options.signal?.aborted) return;\n uploaded.reject(options.signal.reason);\n if (child.exitCode === null && child.signalCode === null) return;\n lines.close();\n child.stdin.destroy();\n child.stdout.destroy();\n child.stderr.destroy();\n };\n options.signal?.addEventListener(\"abort\", releaseCanceledPipes, {\n once: true,\n });\n child.once(\"exit\", releaseCanceledPipes);\n lines.on(\"line\", (line) => {\n try {\n const message = JSON.parse(line) as {\n id?: number;\n method?: string;\n error?: { message: string };\n result?: { threadId?: string };\n };\n if (message.method !== undefined || message.id === undefined) return;\n if (message.error) throw new CodexSecurityError(message.error.message);\n if (message.id === 1) {\n send({ method: \"initialized\" });\n send({\n id: 2,\n method: \"feedback/upload\",\n params: {\n classification: \"bug\",\n reason: options.reason,\n // Codex also collects this thread's descendants. Shared owners\n // belong only in the explicit attachment, not in that subtree.\n threadId:\n !includeLogs ||\n scan?.executionThreadIds?.includes(\n scan.continuationThreadId ?? \"\",\n )\n ? scan?.continuationThreadId\n : undefined,\n includeLogs,\n extraLogFiles,\n tags: {\n codex_security_version: VERSION,\n codex_security_plugin_version: BUNDLED_PLUGIN_VERSION,\n codex_security_codex_version: CODEX_EXECUTABLE_VERSION,\n codex_security_sdk_version: CODEX_SDK_VERSION,\n ...(scan === undefined\n ? {}\n : { codex_security_scan_id: scan.scanId }),\n },\n },\n });\n } else if (message.id === 2) {\n const feedbackId = message.result?.threadId;\n if (!feedbackId)\n throw new CodexSecurityError(\"Codex did not return a feedback ID.\");\n uploaded.resolve(feedbackId);\n }\n } catch (error) {\n uploaded.reject(error);\n }\n });\n try {\n try {\n send({\n id: 1,\n method: \"initialize\",\n params: { clientInfo: { name: \"codex-security\", version: VERSION } },\n });\n return {\n feedbackId: await uploaded.promise,\n scanId: scan?.scanId ?? null,\n includedLogs: includeLogs,\n };\n } finally {\n lines.close();\n child.stdin.end();\n child.kill();\n const timer = setTimeout(() => child.kill(\"SIGKILL\"), 1_000);\n try {\n await closed;\n } finally {\n clearTimeout(timer);\n options.signal?.removeEventListener(\"abort\", releaseCanceledPipes);\n child.removeListener(\"exit\", releaseCanceledPipes);\n }\n }\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error === stdinError && stderr)\n throw new CodexSecurityError(stderr, { cause: error });\n throw error;\n }\n } finally {\n if (directory !== undefined)\n await rm(directory, { recursive: true, force: true });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"finding-catalogue.d.ts","sourceRoot":"","sources":["../src/finding-catalogue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAC/D,MAAM,EACN,OAAO,CACR,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC3C;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,kBAAkB,GAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAO,EACvD,gBAAgB,GAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAO,GACpD,iBAAiB,EAAE,EAAE,CAiDvB;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,kBAAkB,GAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAO,GACtD,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAqC7B;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAoD5E"}
1
+ {"version":3,"file":"finding-catalogue.d.ts","sourceRoot":"","sources":["../src/finding-catalogue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAC/D,MAAM,EACN,OAAO,CACR,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC3C;AAED,wBAAgB,aAAa,CAC3B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