@openai/codex-security 0.8.3 → 0.10.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 (658) hide show
  1. package/README.md +36 -746
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +7 -1
  4. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  5. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  6. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  7. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  8. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  9. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/package.json +1 -0
  20. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
  21. package/_bundled_plugin/mcp/server.mjs +2 -11
  22. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  23. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  24. package/_bundled_plugin/references/artifact-storage.md +1 -1
  25. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  26. package/_bundled_plugin/references/core-scan.md +5 -42
  27. package/_bundled_plugin/references/default-severity-rubric.md +9 -4
  28. package/_bundled_plugin/references/final-report.md +5 -3
  29. package/_bundled_plugin/references/finding-detail-fields.md +18 -18
  30. package/_bundled_plugin/references/focused-investigator.md +13 -0
  31. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  32. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  33. package/_bundled_plugin/references/scan-contract.md +27 -33
  34. package/_bundled_plugin/references/scan-prologue.md +2 -2
  35. package/_bundled_plugin/references/scan-runtime.md +4 -2
  36. package/_bundled_plugin/references/security-guidance.md +14 -1
  37. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  38. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  39. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  40. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  41. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  42. package/_bundled_plugin/scripts/deep_scan_workbench.py +192 -352
  43. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  44. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  45. package/_bundled_plugin/scripts/finalize_scan_contract.py +182 -230
  46. package/_bundled_plugin/scripts/finding_preview.py +20 -0
  47. package/_bundled_plugin/scripts/launch_codex_security_mcp +55 -16
  48. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  49. package/_bundled_plugin/scripts/posix_scan_local_files.py +37 -1
  50. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  51. package/_bundled_plugin/scripts/report_projection.py +81 -43
  52. package/_bundled_plugin/scripts/review_state.py +8 -2
  53. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  54. package/_bundled_plugin/scripts/snapshot_sqlite.py +9 -2
  55. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  56. package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
  57. package/_bundled_plugin/scripts/windows_scan_local_files.py +582 -20
  58. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  59. package/_bundled_plugin/scripts/workbench/handoff.py +100 -23
  60. package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
  61. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  62. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  63. package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
  64. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  65. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  66. package/_bundled_plugin/scripts/workbench/storage.py +91 -7
  67. package/_bundled_plugin/scripts/workbench_cli.py +54 -14
  68. package/_bundled_plugin/scripts/workbench_constants.py +12 -0
  69. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  70. package/_bundled_plugin/scripts/workbench_db.py +562 -303
  71. package/_bundled_plugin/scripts/workbench_feedback.py +57 -11
  72. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  73. package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
  74. package/_bundled_plugin/scripts/workbench_native_indexes.py +238 -41
  75. package/_bundled_plugin/scripts/workbench_progress.py +169 -4
  76. package/_bundled_plugin/scripts/workbench_publication.py +16 -13
  77. package/_bundled_plugin/scripts/workbench_remediation.py +155 -2
  78. package/_bundled_plugin/scripts/workbench_saved_results.py +176 -81
  79. package/_bundled_plugin/scripts/workbench_scan_history.py +398 -174
  80. package/_bundled_plugin/scripts/workbench_scan_start.py +224 -31
  81. package/_bundled_plugin/scripts/workbench_scan_usage.py +675 -73
  82. package/_bundled_plugin/scripts/workbench_schema.py +258 -63
  83. package/_bundled_plugin/scripts/workbench_setup.py +14 -2
  84. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  85. package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
  86. package/_bundled_plugin/scripts/workbench_target.py +594 -136
  87. package/_bundled_plugin/scripts/workbench_target_state.py +1110 -21
  88. package/_bundled_plugin/scripts/workbench_validation.py +43 -3
  89. package/_bundled_plugin/shared/workbench-history-repairs.json +77 -35
  90. package/_bundled_plugin/shared/workbench-migrations.json +100 -0
  91. package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
  92. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  93. package/_bundled_plugin/skills/fix-finding/SKILL.md +2 -1
  94. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -153
  95. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  96. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  97. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
  98. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +409 -0
  99. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  100. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  101. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  102. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  103. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  104. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  105. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  106. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  107. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  108. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
  109. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
  110. package/bin/codex-security.mjs +2 -2
  111. package/dist/api.d.ts +45 -5
  112. package/dist/api.d.ts.map +1 -1
  113. package/dist/api.js +1192 -427
  114. package/dist/api.js.map +1 -1
  115. package/dist/armorcode-findings.d.ts +9 -0
  116. package/dist/armorcode-findings.d.ts.map +1 -0
  117. package/dist/armorcode-findings.js +145 -0
  118. package/dist/armorcode-findings.js.map +1 -0
  119. package/dist/artifact-export.d.ts +2 -0
  120. package/dist/artifact-export.d.ts.map +1 -1
  121. package/dist/artifact-export.js +29 -13
  122. package/dist/artifact-export.js.map +1 -1
  123. package/dist/auth.d.ts +6 -2
  124. package/dist/auth.d.ts.map +1 -1
  125. package/dist/auth.js +37 -18
  126. package/dist/auth.js.map +1 -1
  127. package/dist/batch-cost.d.ts +18 -0
  128. package/dist/batch-cost.d.ts.map +1 -0
  129. package/dist/batch-cost.js +41 -0
  130. package/dist/batch-cost.js.map +1 -0
  131. package/dist/bedrock-oss-pricing.d.ts +6 -0
  132. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  133. package/dist/bedrock-oss-pricing.js +58 -0
  134. package/dist/bedrock-oss-pricing.js.map +1 -0
  135. package/dist/bedrock-pricing.d.ts +15 -0
  136. package/dist/bedrock-pricing.d.ts.map +1 -0
  137. package/dist/bedrock-pricing.js +117 -0
  138. package/dist/bedrock-pricing.js.map +1 -0
  139. package/dist/blackduck-findings.d.ts +1 -1
  140. package/dist/blackduck-findings.d.ts.map +1 -1
  141. package/dist/blackduck-findings.js +24 -22
  142. package/dist/blackduck-findings.js.map +1 -1
  143. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  144. package/dist/bulk-scan-discovery.js +4 -4
  145. package/dist/bulk-scan-discovery.js.map +1 -1
  146. package/dist/bundled-plugin.d.ts +4 -0
  147. package/dist/bundled-plugin.d.ts.map +1 -0
  148. package/dist/bundled-plugin.js +23 -0
  149. package/dist/bundled-plugin.js.map +1 -0
  150. package/dist/checkmarx-evidence.d.ts +19 -0
  151. package/dist/checkmarx-evidence.d.ts.map +1 -0
  152. package/dist/checkmarx-evidence.js +36 -0
  153. package/dist/checkmarx-evidence.js.map +1 -0
  154. package/dist/checkmarx-findings.d.ts +4 -0
  155. package/dist/checkmarx-findings.d.ts.map +1 -0
  156. package/dist/checkmarx-findings.js +27 -0
  157. package/dist/checkmarx-findings.js.map +1 -0
  158. package/dist/checkmarx-one.d.ts +4 -0
  159. package/dist/checkmarx-one.d.ts.map +1 -0
  160. package/dist/checkmarx-one.js +53 -0
  161. package/dist/checkmarx-one.js.map +1 -0
  162. package/dist/checkmarx-repository.d.ts +12 -0
  163. package/dist/checkmarx-repository.d.ts.map +1 -0
  164. package/dist/checkmarx-repository.js +181 -0
  165. package/dist/checkmarx-repository.js.map +1 -0
  166. package/dist/checkmarx-xml.d.ts +12 -0
  167. package/dist/checkmarx-xml.d.ts.map +1 -0
  168. package/dist/checkmarx-xml.js +196 -0
  169. package/dist/checkmarx-xml.js.map +1 -0
  170. package/dist/classify-scan-severity.d.ts +1 -1
  171. package/dist/classify-scan-severity.d.ts.map +1 -1
  172. package/dist/classify-scan-severity.js +11 -3
  173. package/dist/classify-scan-severity.js.map +1 -1
  174. package/dist/classify-severity-records.d.ts +1 -9
  175. package/dist/classify-severity-records.d.ts.map +1 -1
  176. package/dist/classify-severity-records.js +3 -13
  177. package/dist/classify-severity-records.js.map +1 -1
  178. package/dist/classify-severity.d.ts.map +1 -1
  179. package/dist/classify-severity.js +11 -10
  180. package/dist/classify-severity.js.map +1 -1
  181. package/dist/cli-argument.d.ts +4 -0
  182. package/dist/cli-argument.d.ts.map +1 -0
  183. package/dist/cli-argument.js +17 -0
  184. package/dist/cli-argument.js.map +1 -0
  185. package/dist/cli-help.d.ts +1 -1
  186. package/dist/cli-help.d.ts.map +1 -1
  187. package/dist/cli-help.js +71 -29
  188. package/dist/cli-help.js.map +1 -1
  189. package/dist/cli-hook.d.ts +3 -0
  190. package/dist/cli-hook.d.ts.map +1 -0
  191. package/dist/cli-hook.js +87 -0
  192. package/dist/cli-hook.js.map +1 -0
  193. package/dist/cli-integrations.d.ts +13 -0
  194. package/dist/cli-integrations.d.ts.map +1 -0
  195. package/dist/cli-integrations.js +333 -0
  196. package/dist/cli-integrations.js.map +1 -0
  197. package/dist/cli-mcp.d.ts +15 -0
  198. package/dist/cli-mcp.d.ts.map +1 -0
  199. package/dist/cli-mcp.js +178 -0
  200. package/dist/cli-mcp.js.map +1 -0
  201. package/dist/cli-token-view.d.ts +10 -0
  202. package/dist/cli-token-view.d.ts.map +1 -0
  203. package/dist/cli-token-view.js +41 -0
  204. package/dist/cli-token-view.js.map +1 -0
  205. package/dist/cli.d.ts +16 -8
  206. package/dist/cli.d.ts.map +1 -1
  207. package/dist/cli.js +3382 -2017
  208. package/dist/cli.js.map +1 -1
  209. package/dist/cloud-publish.d.ts.map +1 -1
  210. package/dist/cloud-publish.js +35 -33
  211. package/dist/cloud-publish.js.map +1 -1
  212. package/dist/codex-sdk-environment.d.ts +6 -0
  213. package/dist/codex-sdk-environment.d.ts.map +1 -1
  214. package/dist/codex-sdk-environment.js +19 -0
  215. package/dist/codex-sdk-environment.js.map +1 -1
  216. package/dist/command-words.d.ts +3 -0
  217. package/dist/command-words.d.ts.map +1 -0
  218. package/dist/command-words.js +46 -0
  219. package/dist/command-words.js.map +1 -0
  220. package/dist/component-scan.d.ts +19 -4
  221. package/dist/component-scan.d.ts.map +1 -1
  222. package/dist/component-scan.js +67 -9
  223. package/dist/component-scan.js.map +1 -1
  224. package/dist/config.d.ts +1 -1
  225. package/dist/config.d.ts.map +1 -1
  226. package/dist/config.js +130 -67
  227. package/dist/config.js.map +1 -1
  228. package/dist/continuum-findings.d.ts +1 -1
  229. package/dist/continuum-findings.d.ts.map +1 -1
  230. package/dist/continuum-findings.js +149 -19
  231. package/dist/continuum-findings.js.map +1 -1
  232. package/dist/contract-values.d.ts +2 -0
  233. package/dist/contract-values.d.ts.map +1 -1
  234. package/dist/contract-values.js +12 -9
  235. package/dist/contract-values.js.map +1 -1
  236. package/dist/cost-model.d.ts +13 -1
  237. package/dist/cost-model.d.ts.map +1 -1
  238. package/dist/cost-model.js +66 -112
  239. package/dist/cost-model.js.map +1 -1
  240. package/dist/cost.d.ts +42 -3
  241. package/dist/cost.d.ts.map +1 -1
  242. package/dist/cost.js +484 -149
  243. package/dist/cost.js.map +1 -1
  244. package/dist/custom-publish.d.ts +4 -0
  245. package/dist/custom-publish.d.ts.map +1 -1
  246. package/dist/custom-publish.js +40 -3
  247. package/dist/custom-publish.js.map +1 -1
  248. package/dist/custom-validation-prompt.d.ts +1 -1
  249. package/dist/custom-validation-prompt.d.ts.map +1 -1
  250. package/dist/custom-validation-prompt.js +29 -19
  251. package/dist/custom-validation-prompt.js.map +1 -1
  252. package/dist/deduplication/local.d.ts +4 -2
  253. package/dist/deduplication/local.d.ts.map +1 -1
  254. package/dist/deduplication/local.js +9 -2
  255. package/dist/deduplication/local.js.map +1 -1
  256. package/dist/deduplication/refusal.d.ts.map +1 -1
  257. package/dist/deduplication/refusal.js +26 -5
  258. package/dist/deduplication/refusal.js.map +1 -1
  259. package/dist/deduplication/scan.d.ts +5 -0
  260. package/dist/deduplication/scan.d.ts.map +1 -1
  261. package/dist/deduplication/scan.js +24 -7
  262. package/dist/deduplication/scan.js.map +1 -1
  263. package/dist/deep-config.d.ts +0 -1
  264. package/dist/deep-config.d.ts.map +1 -1
  265. package/dist/deep-config.js +22 -33
  266. package/dist/deep-config.js.map +1 -1
  267. package/dist/deep-scan-defaults.d.ts +2 -0
  268. package/dist/deep-scan-defaults.d.ts.map +1 -1
  269. package/dist/deep-scan-defaults.js +28 -1
  270. package/dist/deep-scan-defaults.js.map +1 -1
  271. package/dist/deep-scan.d.ts +2 -0
  272. package/dist/deep-scan.d.ts.map +1 -1
  273. package/dist/deep-scan.js +44 -19
  274. package/dist/deep-scan.js.map +1 -1
  275. package/dist/default-severity-rubric.d.ts +1 -1
  276. package/dist/default-severity-rubric.d.ts.map +1 -1
  277. package/dist/default-severity-rubric.js +1 -1
  278. package/dist/default-severity-rubric.js.map +1 -1
  279. package/dist/endor-findings.d.ts +3 -1
  280. package/dist/endor-findings.d.ts.map +1 -1
  281. package/dist/endor-findings.js +86 -45
  282. package/dist/endor-findings.js.map +1 -1
  283. package/dist/errors.d.ts +4 -2
  284. package/dist/errors.d.ts.map +1 -1
  285. package/dist/errors.js +15 -4
  286. package/dist/errors.js.map +1 -1
  287. package/dist/executable-path.d.ts +3 -0
  288. package/dist/executable-path.d.ts.map +1 -1
  289. package/dist/executable-path.js +26 -0
  290. package/dist/executable-path.js.map +1 -1
  291. package/dist/external-findings-import.d.ts +5 -3
  292. package/dist/external-findings-import.d.ts.map +1 -1
  293. package/dist/external-findings-import.js +19 -7
  294. package/dist/external-findings-import.js.map +1 -1
  295. package/dist/external-findings-local.d.ts +69 -5
  296. package/dist/external-findings-local.d.ts.map +1 -1
  297. package/dist/external-findings-local.js +537 -108
  298. package/dist/external-findings-local.js.map +1 -1
  299. package/dist/external-findings-publish.d.ts +13 -6
  300. package/dist/external-findings-publish.d.ts.map +1 -1
  301. package/dist/external-findings-publish.js +895 -1142
  302. package/dist/external-findings-publish.js.map +1 -1
  303. package/dist/external-findings-read.d.ts +21 -2
  304. package/dist/external-findings-read.d.ts.map +1 -1
  305. package/dist/external-findings-read.js +130 -68
  306. package/dist/external-findings-read.js.map +1 -1
  307. package/dist/external-findings.d.ts +15 -3
  308. package/dist/external-findings.d.ts.map +1 -1
  309. package/dist/external-findings.js +54 -2
  310. package/dist/external-findings.js.map +1 -1
  311. package/dist/external-import-contract.d.ts +8 -12
  312. package/dist/external-import-contract.d.ts.map +1 -1
  313. package/dist/external-import-contract.js +51 -184
  314. package/dist/external-import-contract.js.map +1 -1
  315. package/dist/external-import-models.d.ts +1 -1
  316. package/dist/external-import-models.d.ts.map +1 -1
  317. package/dist/external-import-models.js.map +1 -1
  318. package/dist/feedback.d.ts.map +1 -1
  319. package/dist/feedback.js +5 -4
  320. package/dist/feedback.js.map +1 -1
  321. package/dist/finding-prompt.d.ts +5 -0
  322. package/dist/finding-prompt.d.ts.map +1 -0
  323. package/dist/finding-prompt.js +32 -0
  324. package/dist/finding-prompt.js.map +1 -0
  325. package/dist/findings-client.d.ts +1 -0
  326. package/dist/findings-client.d.ts.map +1 -1
  327. package/dist/findings-client.js +27 -3
  328. package/dist/findings-client.js.map +1 -1
  329. package/dist/github-advisories.d.ts.map +1 -1
  330. package/dist/github-advisories.js +0 -2
  331. package/dist/github-advisories.js.map +1 -1
  332. package/dist/github-dependabot-findings.d.ts.map +1 -1
  333. package/dist/github-dependabot-findings.js +18 -8
  334. package/dist/github-dependabot-findings.js.map +1 -1
  335. package/dist/github-findings.d.ts +4 -1
  336. package/dist/github-findings.d.ts.map +1 -1
  337. package/dist/github-findings.js +73 -316
  338. package/dist/github-findings.js.map +1 -1
  339. package/dist/hosted-git-remotes.d.ts +5 -0
  340. package/dist/hosted-git-remotes.d.ts.map +1 -0
  341. package/dist/hosted-git-remotes.js +285 -0
  342. package/dist/hosted-git-remotes.js.map +1 -0
  343. package/dist/hosted-git-repository.d.ts +28 -0
  344. package/dist/hosted-git-repository.d.ts.map +1 -0
  345. package/dist/hosted-git-repository.js +222 -0
  346. package/dist/hosted-git-repository.js.map +1 -0
  347. package/dist/hosted-remediation.d.ts +1 -0
  348. package/dist/hosted-remediation.d.ts.map +1 -1
  349. package/dist/hosted-remediation.js +23 -3
  350. package/dist/hosted-remediation.js.map +1 -1
  351. package/dist/hosted-scan-protocol.js +2 -2
  352. package/dist/hosted-scan-protocol.js.map +1 -1
  353. package/dist/hosted-scan.d.ts.map +1 -1
  354. package/dist/hosted-scan.js +16 -11
  355. package/dist/hosted-scan.js.map +1 -1
  356. package/dist/hosted-scanner-http.d.ts +21 -0
  357. package/dist/hosted-scanner-http.d.ts.map +1 -0
  358. package/dist/hosted-scanner-http.js +204 -0
  359. package/dist/hosted-scanner-http.js.map +1 -0
  360. package/dist/import-scan.d.ts.map +1 -1
  361. package/dist/import-scan.js +3 -0
  362. package/dist/import-scan.js.map +1 -1
  363. package/dist/index.d.ts +21 -9
  364. package/dist/index.d.ts.map +1 -1
  365. package/dist/index.js +12 -3
  366. package/dist/index.js.map +1 -1
  367. package/dist/inspector-findings.d.ts.map +1 -1
  368. package/dist/inspector-findings.js +52 -86
  369. package/dist/inspector-findings.js.map +1 -1
  370. package/dist/knowledge-base.d.ts +1 -1
  371. package/dist/knowledge-base.d.ts.map +1 -1
  372. package/dist/knowledge-base.js +102 -32
  373. package/dist/knowledge-base.js.map +1 -1
  374. package/dist/linear.d.ts +11 -0
  375. package/dist/linear.d.ts.map +1 -1
  376. package/dist/linear.js.map +1 -1
  377. package/dist/local-git-metadata.d.ts +5 -2
  378. package/dist/local-git-metadata.d.ts.map +1 -1
  379. package/dist/local-git-metadata.js +8 -5
  380. package/dist/local-git-metadata.js.map +1 -1
  381. package/dist/multiscan.d.ts +10 -4
  382. package/dist/multiscan.d.ts.map +1 -1
  383. package/dist/multiscan.js +217 -102
  384. package/dist/multiscan.js.map +1 -1
  385. package/dist/native-json-findings.d.ts +2 -1
  386. package/dist/native-json-findings.d.ts.map +1 -1
  387. package/dist/native-json-findings.js +12 -2
  388. package/dist/native-json-findings.js.map +1 -1
  389. package/dist/opengrep-findings.d.ts +5 -2
  390. package/dist/opengrep-findings.d.ts.map +1 -1
  391. package/dist/opengrep-findings.js +54 -33
  392. package/dist/opengrep-findings.js.map +1 -1
  393. package/dist/operation-telemetry.d.ts +104 -0
  394. package/dist/operation-telemetry.d.ts.map +1 -0
  395. package/dist/operation-telemetry.js +293 -0
  396. package/dist/operation-telemetry.js.map +1 -0
  397. package/dist/plugin-python-probe.d.ts +4 -0
  398. package/dist/plugin-python-probe.d.ts.map +1 -0
  399. package/dist/plugin-python-probe.js +10 -0
  400. package/dist/plugin-python-probe.js.map +1 -0
  401. package/dist/private-finding-import.d.ts +99 -9
  402. package/dist/private-finding-import.d.ts.map +1 -1
  403. package/dist/private-finding-import.js +116 -152
  404. package/dist/private-finding-import.js.map +1 -1
  405. package/dist/project-config.d.ts.map +1 -1
  406. package/dist/project-config.js +53 -13
  407. package/dist/project-config.js.map +1 -1
  408. package/dist/prompt-files.d.ts +7 -2
  409. package/dist/prompt-files.d.ts.map +1 -1
  410. package/dist/prompt-files.js +42 -20
  411. package/dist/prompt-files.js.map +1 -1
  412. package/dist/provider-profile.d.ts +1 -1
  413. package/dist/provider-profile.d.ts.map +1 -1
  414. package/dist/provider-profile.js +12 -10
  415. package/dist/provider-profile.js.map +1 -1
  416. package/dist/publication-telemetry.d.ts +45 -0
  417. package/dist/publication-telemetry.d.ts.map +1 -0
  418. package/dist/publication-telemetry.js +50 -0
  419. package/dist/publication-telemetry.js.map +1 -0
  420. package/dist/publication.d.ts +1 -1
  421. package/dist/publication.d.ts.map +1 -1
  422. package/dist/publication.js.map +1 -1
  423. package/dist/publish.d.ts +4 -0
  424. package/dist/publish.d.ts.map +1 -1
  425. package/dist/publish.js +42 -2
  426. package/dist/publish.js.map +1 -1
  427. package/dist/record.d.ts +1 -5
  428. package/dist/record.d.ts.map +1 -1
  429. package/dist/record.js +3 -51
  430. package/dist/record.js.map +1 -1
  431. package/dist/remediation.d.ts +1 -4
  432. package/dist/remediation.d.ts.map +1 -1
  433. package/dist/remediation.js +6 -8
  434. package/dist/remediation.js.map +1 -1
  435. package/dist/request-metadata.d.ts +3 -0
  436. package/dist/request-metadata.d.ts.map +1 -1
  437. package/dist/request-metadata.js +9 -0
  438. package/dist/request-metadata.js.map +1 -1
  439. package/dist/result.d.ts +4 -0
  440. package/dist/result.d.ts.map +1 -1
  441. package/dist/result.js +1 -1
  442. package/dist/result.js.map +1 -1
  443. package/dist/retry-windows-rename.d.ts +8 -0
  444. package/dist/retry-windows-rename.d.ts.map +1 -0
  445. package/dist/retry-windows-rename.js +24 -0
  446. package/dist/retry-windows-rename.js.map +1 -0
  447. package/dist/runtime.d.ts +54 -6
  448. package/dist/runtime.d.ts.map +1 -1
  449. package/dist/runtime.js +1084 -256
  450. package/dist/runtime.js.map +1 -1
  451. package/dist/saved-scan-bootstrap.d.ts +7 -1
  452. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  453. package/dist/saved-scan-bootstrap.js +269 -114
  454. package/dist/saved-scan-bootstrap.js.map +1 -1
  455. package/dist/scan-activity.d.ts.map +1 -1
  456. package/dist/scan-activity.js +141 -56
  457. package/dist/scan-activity.js.map +1 -1
  458. package/dist/scan-archive-path.d.ts +2 -0
  459. package/dist/scan-archive-path.d.ts.map +1 -0
  460. package/dist/scan-archive-path.js +5 -0
  461. package/dist/scan-archive-path.js.map +1 -0
  462. package/dist/scan-comparison.d.ts +10 -5
  463. package/dist/scan-comparison.d.ts.map +1 -1
  464. package/dist/scan-comparison.js +66 -17
  465. package/dist/scan-comparison.js.map +1 -1
  466. package/dist/scan-dashboard.d.ts +7 -6
  467. package/dist/scan-dashboard.d.ts.map +1 -1
  468. package/dist/scan-dashboard.js +92 -43
  469. package/dist/scan-dashboard.js.map +1 -1
  470. package/dist/scan-executor.d.ts +10 -1
  471. package/dist/scan-executor.d.ts.map +1 -1
  472. package/dist/scan-executor.js +24 -2
  473. package/dist/scan-executor.js.map +1 -1
  474. package/dist/scan-history-renderer.d.ts +1 -0
  475. package/dist/scan-history-renderer.d.ts.map +1 -1
  476. package/dist/scan-history-renderer.js +34 -28
  477. package/dist/scan-history-renderer.js.map +1 -1
  478. package/dist/scan-logs.d.ts +12 -0
  479. package/dist/scan-logs.d.ts.map +1 -1
  480. package/dist/scan-logs.js +131 -78
  481. package/dist/scan-logs.js.map +1 -1
  482. package/dist/scan-measurement.d.ts +26 -0
  483. package/dist/scan-measurement.d.ts.map +1 -0
  484. package/dist/scan-measurement.js +77 -0
  485. package/dist/scan-measurement.js.map +1 -0
  486. package/dist/scan-progress.d.ts +1 -0
  487. package/dist/scan-progress.d.ts.map +1 -1
  488. package/dist/scan-progress.js +3 -0
  489. package/dist/scan-progress.js.map +1 -1
  490. package/dist/scan-sessions.d.ts.map +1 -1
  491. package/dist/scan-sessions.js +4 -1
  492. package/dist/scan-sessions.js.map +1 -1
  493. package/dist/scan-settings.d.ts +1 -1
  494. package/dist/scan-settings.d.ts.map +1 -1
  495. package/dist/scan-settings.js +1 -24
  496. package/dist/scan-settings.js.map +1 -1
  497. package/dist/scanner-import.d.ts +25 -13
  498. package/dist/scanner-import.d.ts.map +1 -1
  499. package/dist/scanner-import.js +216 -97
  500. package/dist/scanner-import.js.map +1 -1
  501. package/dist/scanner-repository-url.d.ts +4 -1
  502. package/dist/scanner-repository-url.d.ts.map +1 -1
  503. package/dist/scanner-repository-url.js +10 -6
  504. package/dist/scanner-repository-url.js.map +1 -1
  505. package/dist/security-policy.d.ts +1 -1
  506. package/dist/security-policy.d.ts.map +1 -1
  507. package/dist/security-policy.js +26 -6
  508. package/dist/security-policy.js.map +1 -1
  509. package/dist/semgrep-findings.d.ts +6 -3
  510. package/dist/semgrep-findings.d.ts.map +1 -1
  511. package/dist/semgrep-findings.js +72 -42
  512. package/dist/semgrep-findings.js.map +1 -1
  513. package/dist/semgrep-guardian-findings.d.ts +38 -0
  514. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  515. package/dist/semgrep-guardian-findings.js +165 -0
  516. package/dist/semgrep-guardian-findings.js.map +1 -0
  517. package/dist/semgrep-platform-collector.d.ts +26 -0
  518. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  519. package/dist/semgrep-platform-collector.js +108 -0
  520. package/dist/semgrep-platform-collector.js.map +1 -0
  521. package/dist/semgrep-platform-findings.d.ts +157 -6
  522. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  523. package/dist/semgrep-platform-findings.js +766 -103
  524. package/dist/semgrep-platform-findings.js.map +1 -1
  525. package/dist/server/api.d.ts +1 -1
  526. package/dist/server/api.d.ts.map +1 -1
  527. package/dist/server/api.js.map +1 -1
  528. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  529. package/dist/server/embedding-tokenizer.d.ts +2 -0
  530. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  531. package/dist/server/embedding-tokenizer.js +322 -0
  532. package/dist/server/embedding-tokenizer.js.map +6 -0
  533. package/dist/server/embeddings.d.ts +16 -2
  534. package/dist/server/embeddings.d.ts.map +1 -1
  535. package/dist/server/embeddings.js +35 -5
  536. package/dist/server/embeddings.js.map +1 -1
  537. package/dist/session-lines.d.ts +5 -0
  538. package/dist/session-lines.d.ts.map +1 -0
  539. package/dist/session-lines.js +60 -0
  540. package/dist/session-lines.js.map +1 -0
  541. package/dist/severity-review.d.ts +3 -1
  542. package/dist/severity-review.d.ts.map +1 -1
  543. package/dist/severity-review.js +3 -2
  544. package/dist/severity-review.js.map +1 -1
  545. package/dist/skill-authentication.d.ts +1 -0
  546. package/dist/skill-authentication.d.ts.map +1 -1
  547. package/dist/skill-authentication.js +1 -0
  548. package/dist/skill-authentication.js.map +1 -1
  549. package/dist/snyk-findings.d.ts +9 -2
  550. package/dist/snyk-findings.d.ts.map +1 -1
  551. package/dist/snyk-findings.js +90 -70
  552. package/dist/snyk-findings.js.map +1 -1
  553. package/dist/snyk-rest-findings.d.ts +59 -0
  554. package/dist/snyk-rest-findings.d.ts.map +1 -0
  555. package/dist/snyk-rest-findings.js +879 -0
  556. package/dist/snyk-rest-findings.js.map +1 -0
  557. package/dist/snyk-token-origin.d.ts +4 -0
  558. package/dist/snyk-token-origin.d.ts.map +1 -0
  559. package/dist/snyk-token-origin.js +82 -0
  560. package/dist/snyk-token-origin.js.map +1 -0
  561. package/dist/sonar-collector.d.ts.map +1 -1
  562. package/dist/sonar-collector.js +0 -3
  563. package/dist/sonar-collector.js.map +1 -1
  564. package/dist/sonar-findings.d.ts +1 -1
  565. package/dist/sonar-findings.d.ts.map +1 -1
  566. package/dist/sonar-findings.js +2 -4
  567. package/dist/sonar-findings.js.map +1 -1
  568. package/dist/sonar-import.d.ts +3 -0
  569. package/dist/sonar-import.d.ts.map +1 -1
  570. package/dist/sonar-import.js +30 -34
  571. package/dist/sonar-import.js.map +1 -1
  572. package/dist/stored-finding-projection.d.ts +6 -0
  573. package/dist/stored-finding-projection.d.ts.map +1 -0
  574. package/dist/stored-finding-projection.js +104 -0
  575. package/dist/stored-finding-projection.js.map +1 -0
  576. package/dist/stored-findings-publication.d.ts +23 -0
  577. package/dist/stored-findings-publication.d.ts.map +1 -0
  578. package/dist/stored-findings-publication.js +169 -0
  579. package/dist/stored-findings-publication.js.map +1 -0
  580. package/dist/target-drift.d.ts +9 -0
  581. package/dist/target-drift.d.ts.map +1 -0
  582. package/dist/target-drift.js +27 -0
  583. package/dist/target-drift.js.map +1 -0
  584. package/dist/targets.d.ts +8 -1
  585. package/dist/targets.d.ts.map +1 -1
  586. package/dist/targets.js +131 -42
  587. package/dist/targets.js.map +1 -1
  588. package/dist/tenable-findings.d.ts +6 -0
  589. package/dist/tenable-findings.d.ts.map +1 -0
  590. package/dist/tenable-findings.js +122 -0
  591. package/dist/tenable-findings.js.map +1 -0
  592. package/dist/terminal-stream.d.ts +13 -0
  593. package/dist/terminal-stream.d.ts.map +1 -0
  594. package/dist/terminal-stream.js +35 -0
  595. package/dist/terminal-stream.js.map +1 -0
  596. package/dist/trivy-findings.d.ts +19 -0
  597. package/dist/trivy-findings.d.ts.map +1 -0
  598. package/dist/trivy-findings.js +424 -0
  599. package/dist/trivy-findings.js.map +1 -0
  600. package/dist/trivy-import.d.ts +19 -0
  601. package/dist/trivy-import.d.ts.map +1 -0
  602. package/dist/trivy-import.js +151 -0
  603. package/dist/trivy-import.js.map +1 -0
  604. package/dist/trusted-executable.d.ts +6 -0
  605. package/dist/trusted-executable.d.ts.map +1 -1
  606. package/dist/trusted-executable.js +140 -37
  607. package/dist/trusted-executable.js.map +1 -1
  608. package/dist/validation-records.js +1 -1
  609. package/dist/validation-records.js.map +1 -1
  610. package/dist/veracode-findings.d.ts +1 -1
  611. package/dist/veracode-findings.d.ts.map +1 -1
  612. package/dist/veracode-findings.js +19 -6
  613. package/dist/veracode-findings.js.map +1 -1
  614. package/dist/version.d.ts +3 -1
  615. package/dist/version.d.ts.map +1 -1
  616. package/dist/version.js +184 -32
  617. package/dist/version.js.map +1 -1
  618. package/dist/vertex-pricing.d.ts +8 -0
  619. package/dist/vertex-pricing.d.ts.map +1 -0
  620. package/dist/vertex-pricing.js +20 -0
  621. package/dist/vertex-pricing.js.map +1 -0
  622. package/dist/windows-path.d.ts +1 -0
  623. package/dist/windows-path.d.ts.map +1 -1
  624. package/dist/windows-path.js +26 -1
  625. package/dist/windows-path.js.map +1 -1
  626. package/dist/wiz-findings.d.ts +6 -2
  627. package/dist/wiz-findings.d.ts.map +1 -1
  628. package/dist/wiz-findings.js +65 -89
  629. package/dist/wiz-findings.js.map +1 -1
  630. package/docs/classify-severity-records.md +27 -12
  631. package/docs/cli.md +853 -639
  632. package/docs/dedupe-records.md +44 -24
  633. package/docs/findings-service.md +84 -44
  634. package/docs/hosted-remediation.md +27 -11
  635. package/docs/hosted-scans.md +50 -42
  636. package/docs/sdk.md +903 -0
  637. package/docs/telemetry.md +236 -0
  638. package/docs/validate-records.md +78 -44
  639. package/package.json +23 -16
  640. package/schemas/external-findings.schema.json +4 -1
  641. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  642. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  643. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  644. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  645. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  646. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  647. package/dist/external-imports-feature.d.ts +0 -6
  648. package/dist/external-imports-feature.d.ts.map +0 -1
  649. package/dist/external-imports-feature.js +0 -51
  650. package/dist/external-imports-feature.js.map +0 -1
  651. package/dist/finding-normalization.d.ts +0 -5
  652. package/dist/finding-normalization.d.ts.map +0 -1
  653. package/dist/finding-normalization.js +0 -155
  654. package/dist/finding-normalization.js.map +0 -1
  655. package/dist/reader-selection.d.ts +0 -13
  656. package/dist/reader-selection.d.ts.map +0 -1
  657. package/dist/reader-selection.js +0 -81
  658. package/dist/reader-selection.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import type { Finding } from "./models.js";
2
+ import { type PublicationTelemetry, type PublicationTelemetryObserver } from "./publication-telemetry.js";
2
3
  export interface PublishScanToCustomOptions {
3
4
  /** Resume publication within the named local findings workflow. */
4
5
  workflowId?: string;
@@ -8,6 +9,8 @@ export interface PublishScanToCustomOptions {
8
9
  dryRun?: boolean;
9
10
  expectedScanId?: string;
10
11
  signal?: AbortSignal;
12
+ /** Best-effort content-free outcome accounting, including preparation failures. */
13
+ onTelemetry?: PublicationTelemetryObserver;
11
14
  }
12
15
  export interface CustomPublicationResult {
13
16
  scanId: string;
@@ -16,6 +19,7 @@ export interface CustomPublicationResult {
16
19
  findingCount: number;
17
20
  dryRun?: true;
18
21
  findings?: Finding[];
22
+ telemetry?: PublicationTelemetry;
19
23
  }
20
24
  /** Publish complete, sealed findings to a findings API without changing scan artifacts. */
21
25
  export declare function publishScanToCustom(scanDirectory: string, options: PublishScanToCustomOptions): Promise<CustomPublicationResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"custom-publish.d.ts","sourceRoot":"","sources":["../src/custom-publish.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,WAAW,0BAA0B;IACzC,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,2FAA2F;AAC3F,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
1
+ {"version":3,"file":"custom-publish.d.ts","sourceRoot":"","sources":["../src/custom-publish.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAO3C,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAClC,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,0BAA0B;IACzC,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mFAAmF;IACnF,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAQD,2FAA2F;AAC3F,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,uBAAuB,CAAC,CAElC"}
@@ -3,32 +3,65 @@ import { CodexSecurityError } from "./errors.js";
3
3
  import { FindingsClient } from "./findings-client.js";
4
4
  import { bundledPluginRoot } from "./runtime.js";
5
5
  import { FindingWorkflow, scanArtifactDigest, workflowDestination, } from "./finding-workflow.js";
6
+ import { PublicationTelemetryRecorder, } from "./publication-telemetry.js";
6
7
  /** Publish complete, sealed findings to a findings API without changing scan artifacts. */
7
8
  export async function publishScanToCustom(scanDirectory, options) {
8
9
  return await publishScanToCustomInternal(scanDirectory, options);
9
10
  }
10
11
  /** @internal */
11
12
  export async function publishScanToCustomInternal(scanDirectory, options, dependencies = {}) {
13
+ const telemetry = new PublicationTelemetryRecorder("custom", options.onTelemetry);
14
+ try {
15
+ const result = await publishScanToCustomAttempt(scanDirectory, options, dependencies, telemetry);
16
+ telemetry.notify(result.telemetry);
17
+ return result;
18
+ }
19
+ catch (error) {
20
+ telemetry.notifyFailure(options);
21
+ throw error;
22
+ }
23
+ }
24
+ async function publishScanToCustomAttempt(scanDirectory, options, dependencies, telemetry) {
12
25
  const { contract, scanDirectory: canonicalDirectory } = await loadContractWithScanDirectory(scanDirectory, {
13
26
  pluginRoot: await bundledPluginRoot(),
14
27
  signal: options.signal,
15
28
  expectedScanId: options.expectedScanId,
16
29
  });
17
30
  const { manifest, findings } = contract;
31
+ telemetry.counts.selected = findings.findings.length;
18
32
  if (findings.findings.length === 0 && options.workflowId === undefined) {
19
33
  throw new CodexSecurityError("The completed scan has no findings to publish.");
20
34
  }
21
35
  const repositoryId = manifest.scan.target.targetId;
36
+ let invoked = false;
22
37
  const publish = async () => {
23
- const findingIds = options.dryRun
38
+ invoked = true;
39
+ const client = options.dryRun
40
+ ? null
41
+ : new FindingsClient(options.findingsUrl, options.signal, dependencies.fetch);
42
+ if (client !== null) {
43
+ telemetry.attempted = true;
44
+ telemetry.counts.submitted = findings.findings.length;
45
+ // The bulk API acknowledges IDs; it does not distinguish inserts from upserts.
46
+ telemetry.counts.created = null;
47
+ telemetry.counts.reused = null;
48
+ telemetry.counts.acknowledged = null;
49
+ telemetry.counts.failed = null;
50
+ telemetry.outcome = "indeterminate";
51
+ }
52
+ const findingIds = client === null
24
53
  ? findings.findings.map((finding) => finding.findingId)
25
- : await new FindingsClient(options.findingsUrl, options.signal, dependencies.fetch).publish(findings.findings, repositoryId);
54
+ : await client.publish(findings.findings, repositoryId);
55
+ telemetry.outcome = options.dryRun ? "preview" : "completed";
56
+ telemetry.counts.acknowledged = options.dryRun ? 0 : findingIds.length;
57
+ telemetry.counts.failed = 0;
26
58
  return {
27
59
  scanId: manifest.scan.id,
28
60
  repositoryId,
29
61
  findingIds,
30
62
  findingCount: findingIds.length,
31
63
  ...(options.dryRun ? { dryRun: true, findings: findings.findings } : {}),
64
+ telemetry: telemetry.snapshot(),
32
65
  };
33
66
  };
34
67
  if (options.workflowId === undefined || options.dryRun)
@@ -42,6 +75,10 @@ export async function publishScanToCustomInternal(scanDirectory, options, depend
42
75
  destination: workflowDestination(options.findingsUrl),
43
76
  });
44
77
  await workflow.complete("scan", null);
45
- return await workflow.run("publish", publish);
78
+ const result = await workflow.run("publish", publish);
79
+ if (invoked)
80
+ return result;
81
+ telemetry.counts.reused = result.findingCount;
82
+ return { ...result, telemetry: telemetry.snapshot("completed") };
46
83
  }
47
84
  //# sourceMappingURL=custom-publish.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-publish.js","sourceRoot":"","sources":["../src/custom-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAsB/B,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,aAAqB,EACrB,OAAmC;IAEnC,OAAO,MAAM,2BAA2B,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,aAAqB,EACrB,OAAmC,EACnC,YAAY,GAIR,EAAE;IAEN,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,kBAAkB,EAAE,GACnD,MAAM,6BAA6B,CAAC,aAAa,EAAE;QACjD,UAAU,EAAE,MAAM,iBAAiB,EAAE;QACrC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC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M,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IACpD,MAAM,QAAQ,CAAC,IAAI,CAAC;QAClB,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;QACxB,OAAO,EAAE,kBAAkB;QAC3B,cAAc,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QAC5C,WAAW,EAAE,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC;KACtD,CAAC,CAAC;IACH,MAAM,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,OAAO,MAAM,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"./contract.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { FindingsClient, type FindingsRequest } from \"./findings-client.js\";\nimport type { Finding } from \"./models.js\";\nimport { bundledPluginRoot, type runWorkbench } from \"./runtime.js\";\nimport {\n FindingWorkflow,\n scanArtifactDigest,\n workflowDestination,\n} from \"./finding-workflow.js\";\n\nexport interface PublishScanToCustomOptions {\n /** Resume publication within the named local findings workflow. */\n workflowId?: string;\n /** Findings API base URL, such as http://localhost:3000. */\n findingsUrl: string;\n /** Validate and preview the upload without making an HTTP request. */\n dryRun?: boolean;\n expectedScanId?: string;\n signal?: AbortSignal;\n}\n\nexport interface CustomPublicationResult {\n scanId: string;\n repositoryId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\n/** Publish complete, sealed findings to a findings API without changing scan artifacts. */\nexport async function publishScanToCustom(\n scanDirectory: string,\n options: PublishScanToCustomOptions,\n): Promise<CustomPublicationResult> {\n return await publishScanToCustomInternal(scanDirectory, options);\n}\n\n/** @internal */\nexport async function publishScanToCustomInternal(\n scanDirectory: string,\n options: PublishScanToCustomOptions,\n dependencies: {\n fetch?: FindingsRequest;\n environment?: NodeJS.ProcessEnv;\n runWorkbench?: typeof runWorkbench;\n } = {},\n): Promise<CustomPublicationResult> {\n const { contract, scanDirectory: canonicalDirectory } =\n await loadContractWithScanDirectory(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: options.signal,\n expectedScanId: options.expectedScanId,\n });\n const { manifest, findings } = contract;\n if (findings.findings.length === 0 && options.workflowId === undefined) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n const repositoryId = manifest.scan.target.targetId;\n const publish = async (): Promise<CustomPublicationResult> => {\n const findingIds = options.dryRun\n ? findings.findings.map((finding) => finding.findingId)\n : await new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n ).publish(findings.findings, repositoryId);\n return {\n scanId: manifest.scan.id,\n repositoryId,\n findingIds,\n findingCount: findingIds.length,\n ...(options.dryRun ? { dryRun: true, findings: findings.findings } : {}),\n };\n };\n if (options.workflowId === undefined || options.dryRun)\n return await publish();\n const workflow = new FindingWorkflow(\n options.workflowId,\n dependencies.environment,\n dependencies.runWorkbench,\n );\n await workflow.protectArtifacts(canonicalDirectory);\n await workflow.bind({\n scanId: manifest.scan.id,\n scanDir: canonicalDirectory,\n artifactDigest: scanArtifactDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n });\n await workflow.complete(\"scan\", null);\n return await workflow.run(\"publish\", publish);\n}\n"]}
1
+ {"version":3,"file":"custom-publish.js","sourceRoot":"","sources":["../src/custom-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAwB,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAqB,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,4BAA4B,GAG7B,MAAM,4BAA4B,CAAC;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AAM,CAAC;IAC3B,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;IAC9C,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AACnE,CAAC","sourcesContent":["import { loadContractWithScanDirectory } from \"./contract.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { FindingsClient, type FindingsRequest } from \"./findings-client.js\";\nimport type { Finding } from \"./models.js\";\nimport { bundledPluginRoot, type runWorkbench } from \"./runtime.js\";\nimport {\n FindingWorkflow,\n scanArtifactDigest,\n workflowDestination,\n} from \"./finding-workflow.js\";\nimport {\n PublicationTelemetryRecorder,\n type PublicationTelemetry,\n type PublicationTelemetryObserver,\n} from \"./publication-telemetry.js\";\n\nexport interface PublishScanToCustomOptions {\n /** Resume publication within the named local findings workflow. */\n workflowId?: string;\n /** Findings API base URL, such as http://localhost:3000. */\n findingsUrl: string;\n /** Validate and preview the upload without making an HTTP request. */\n dryRun?: boolean;\n expectedScanId?: string;\n signal?: AbortSignal;\n /** Best-effort content-free outcome accounting, including preparation failures. */\n onTelemetry?: PublicationTelemetryObserver;\n}\n\nexport interface CustomPublicationResult {\n scanId: string;\n repositoryId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n telemetry?: PublicationTelemetry;\n}\n\ninterface CustomPublicationDependencies {\n fetch?: FindingsRequest;\n environment?: NodeJS.ProcessEnv;\n runWorkbench?: typeof runWorkbench;\n}\n\n/** Publish complete, sealed findings to a findings API without changing scan artifacts. */\nexport async function publishScanToCustom(\n scanDirectory: string,\n options: PublishScanToCustomOptions,\n): Promise<CustomPublicationResult> {\n return await publishScanToCustomInternal(scanDirectory, options);\n}\n\n/** @internal */\nexport async function publishScanToCustomInternal(\n scanDirectory: string,\n options: PublishScanToCustomOptions,\n dependencies: CustomPublicationDependencies = {},\n): Promise<CustomPublicationResult> {\n const telemetry = new PublicationTelemetryRecorder(\n \"custom\",\n options.onTelemetry,\n );\n try {\n const result = await publishScanToCustomAttempt(\n scanDirectory,\n options,\n dependencies,\n telemetry,\n );\n telemetry.notify(result.telemetry!);\n return result;\n } catch (error) {\n telemetry.notifyFailure(options);\n throw error;\n }\n}\n\nasync function publishScanToCustomAttempt(\n scanDirectory: string,\n options: PublishScanToCustomOptions,\n dependencies: CustomPublicationDependencies,\n telemetry: PublicationTelemetryRecorder,\n): Promise<CustomPublicationResult> {\n const { contract, scanDirectory: canonicalDirectory } =\n await loadContractWithScanDirectory(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: options.signal,\n expectedScanId: options.expectedScanId,\n });\n const { manifest, findings } = contract;\n telemetry.counts.selected = findings.findings.length;\n if (findings.findings.length === 0 && options.workflowId === undefined) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n const repositoryId = manifest.scan.target.targetId;\n let invoked = false;\n const publish = async (): Promise<CustomPublicationResult> => {\n invoked = true;\n const client = options.dryRun\n ? null\n : new FindingsClient(\n options.findingsUrl,\n options.signal,\n dependencies.fetch,\n );\n if (client !== null) {\n telemetry.attempted = true;\n telemetry.counts.submitted = findings.findings.length;\n // The bulk API acknowledges IDs; it does not distinguish inserts from upserts.\n telemetry.counts.created = null;\n telemetry.counts.reused = null;\n telemetry.counts.acknowledged = null;\n telemetry.counts.failed = null;\n telemetry.outcome = \"indeterminate\";\n }\n const findingIds =\n client === null\n ? findings.findings.map((finding) => finding.findingId)\n : await client.publish(findings.findings, repositoryId);\n telemetry.outcome = options.dryRun ? \"preview\" : \"completed\";\n telemetry.counts.acknowledged = options.dryRun ? 0 : findingIds.length;\n telemetry.counts.failed = 0;\n return {\n scanId: manifest.scan.id,\n repositoryId,\n findingIds,\n findingCount: findingIds.length,\n ...(options.dryRun ? { dryRun: true, findings: findings.findings } : {}),\n telemetry: telemetry.snapshot(),\n };\n };\n if (options.workflowId === undefined || options.dryRun)\n return await publish();\n const workflow = new FindingWorkflow(\n options.workflowId,\n dependencies.environment,\n dependencies.runWorkbench,\n );\n await workflow.protectArtifacts(canonicalDirectory);\n await workflow.bind({\n scanId: manifest.scan.id,\n scanDir: canonicalDirectory,\n artifactDigest: scanArtifactDigest(contract),\n destination: workflowDestination(options.findingsUrl),\n });\n await workflow.complete(\"scan\", null);\n const result = await workflow.run(\"publish\", publish);\n if (invoked) return result;\n telemetry.counts.reused = result.findingCount;\n return { ...result, telemetry: telemetry.snapshot(\"completed\") };\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import { type JsonObject } from "./config.js";
2
- export declare function customDiscoveryPrompt(pluginRoot: string, skillName: string): Promise<string>;
2
+ export declare function customDiscoveryPrompt(pluginRoot: string, skillName: string, standardHandoff: boolean): Promise<string>;
3
3
  export declare function customValidationConfig(config: JsonObject, pluginRoot: string): Promise<JsonObject>;
4
4
  //# sourceMappingURL=custom-validation-prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-validation-prompt.d.ts","sourceRoot":"","sources":["../src/custom-validation-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAoDnE,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAmDjB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CA+BrB"}
1
+ {"version":3,"file":"custom-validation-prompt.d.ts","sourceRoot":"","sources":["../src/custom-validation-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAsFnE,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,GACvB,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CA+BrB"}
@@ -8,6 +8,7 @@ import { PLUGIN_NAME } from "./runtime.js";
8
8
  // the ordinary validation sequence with a custom-validation request.
9
9
  const SOURCES = {
10
10
  "references/core-scan.md": [
11
+ "07abac7382a66338bfbe3def9a0e89e715a89561332c88ccb4477f97b6e84fe5",
11
12
  "0e301a70d9f20acbb797f5eafcac84c09dd0513991714812d5c4f7b1f64a4a89",
12
13
  "7690b6c854de07ff15984f6d2c25ddfa1f6ae65f65876cadf2f904054b4f0679",
13
14
  "83bafdc4089803e631eaaa86ec57167c7da3f51794514d0dcdb62c5afdced8a7",
@@ -41,27 +42,36 @@ async function source(pluginRoot, name) {
41
42
  function step(text, number) {
42
43
  return text.match(new RegExp(`^${number}\\. (.+)$`, "m"))[1];
43
44
  }
44
- export async function customDiscoveryPrompt(pluginRoot, skillName) {
45
+ async function legacyDiscoveryPrompt(pluginRoot) {
46
+ const [skill, core] = await Promise.all([
47
+ source(pluginRoot, "skills/security-scan/SKILL.md"),
48
+ source(pluginRoot, "references/core-scan.md"),
49
+ ]);
50
+ const discovery = core
51
+ .replace(/^7\. .+$/m, "7. Retain the combined source-backed candidates and their existing evidence. The SDK will run independent final validation in a separate turn.")
52
+ .replace(/^Keep discovery, validation, and attack-path reasoning.+$/m, "Keep source-evidence and counterevidence checks within discovery. Do not run an independent final validation pass or invoke separate phase skills.")
53
+ .replace("reconcile their evidence and submit the result;", "reconcile their evidence and preserve provisional candidates through the SDK-owned discovery handoff;");
54
+ return [
55
+ skill.slice(skill.indexOf("## Host And Setup"), skill.indexOf("## Workflow")),
56
+ "## Discovery workflow",
57
+ `1. ${step(skill, 1)}`,
58
+ "2. Perform the embedded core discovery workflow below. Do not reload the ordinary core-scan.md or top-level security-scan skill.",
59
+ `3. ${step(skill, 3).slice(step(skill, 3).indexOf("For an SDK-owned scan with a bound semantic draft tool,"))}`,
60
+ `4. ${HANDOFF}`,
61
+ "## Embedded core discovery workflow",
62
+ discovery,
63
+ ].join("\n\n");
64
+ }
65
+ export async function customDiscoveryPrompt(pluginRoot, skillName, standardHandoff) {
45
66
  let workflow;
46
67
  if (skillName === "security-scan") {
47
- const [skill, core] = await Promise.all([
48
- source(pluginRoot, "skills/security-scan/SKILL.md"),
49
- source(pluginRoot, "references/core-scan.md"),
50
- ]);
51
- const discovery = core
52
- .replace(/^7\. .+$/m, "7. Retain the combined source-backed candidates and their existing evidence. The SDK will run independent final validation in a separate turn.")
53
- .replace(/^Keep discovery, validation, and attack-path reasoning.+$/m, "Keep source-evidence and counterevidence checks within discovery. Do not run an independent final validation pass or invoke separate phase skills.")
54
- .replace("reconcile their evidence and submit the result;", "reconcile their evidence and preserve provisional candidates through the SDK-owned discovery handoff;");
55
- workflow = [
56
- skill.slice(skill.indexOf("## Host And Setup"), skill.indexOf("## Workflow")),
57
- "## Discovery workflow",
58
- `1. ${step(skill, 1)}`,
59
- "2. Perform the embedded core discovery workflow below. Do not reload the ordinary core-scan.md or top-level security-scan skill.",
60
- `3. ${step(skill, 3).slice(step(skill, 3).indexOf("For an SDK-owned scan with a bound semantic draft tool,"))}`,
61
- `4. ${HANDOFF}`,
62
- "## Embedded core discovery workflow",
63
- discovery,
64
- ].join("\n\n");
68
+ workflow = standardHandoff
69
+ ? [
70
+ "Use <plugin_dir>/references/core-scan.md for source discovery. This caller supplies the validation handoff: the SDK runs independent final validation in a separate turn. Check source evidence and counterevidence now, but do not run the default validation pass.",
71
+ "Keep any supplied investigation time allowance unchanged. Only for an explicit time request with no existing allowance, render <plugin_dir>/references/investigation-time-budget.md once before source review.",
72
+ HANDOFF,
73
+ ].join("\n\n")
74
+ : await legacyDiscoveryPrompt(pluginRoot);
65
75
  }
66
76
  else if (skillName === "security-diff-scan") {
67
77
  const skill = await source(pluginRoot, "skills/security-diff-scan/SKILL.md");
@@ -1 +1 @@
1
- {"version":3,"file":"custom-validation-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C,GAAG,IAAI,GAAG,CAC/D;gBACD,cAAc,EAAE;oBACd,GAAG,IAAI,GAAG,CAAC;wBACT,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;wBAChC,GAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAc;wBACrD,GAAG,cAAc;qBAClB,CAAC;iBACH;aACF;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { resolveCodexProfile, type JsonObject } from \"./config.js\";\nimport { IncompleteScanError } from \"./errors.js\";\nimport { PLUGIN_NAME } from \"./runtime.js\";\n\n// Review this adapter when the bundled workflows change. Never silently run\n// the ordinary validation sequence with a custom-validation request.\nconst SOURCES = {\n \"references/core-scan.md\": [\n \"0e301a70d9f20acbb797f5eafcac84c09dd0513991714812d5c4f7b1f64a4a89\",\n \"7690b6c854de07ff15984f6d2c25ddfa1f6ae65f65876cadf2f904054b4f0679\",\n \"83bafdc4089803e631eaaa86ec57167c7da3f51794514d0dcdb62c5afdced8a7\",\n \"848eb40d42b0bf9cf21748b9927d031b0461a4443f63e3954139f9801f41c3f6\",\n ],\n \"skills/security-scan/SKILL.md\": [\n \"b6a69658d48fff6979d6690e95d2096da236bb7e51b96ebb4f92102a9863d66c\",\n \"99cfcbbaa9d5b0450881ec752a116888b05b7fe21ea7af28fd22d088882dcd46\",\n ],\n \"skills/security-diff-scan/SKILL.md\": [\n \"09232fd5d96cfed2a5bdccd176c09b7e9ca53ebd7ac136d283bec884fde94b0d\",\n ],\n};\n\nconst DISABLED_TOOLS = [\n \"start_codex_security_standard_scan\",\n \"start_codex_security_prompt_only_scan\",\n \"start_codex_security_deep_scan\",\n \"complete_codex_security_scan\",\n \"record_codex_security_candidate_validations\",\n \"record_candidate_attack_paths\",\n];\n\nconst HANDOFF =\n \"Preserve every surviving source-backed candidate as a provisional finding, including its identity, source locations, evidence, counterevidence, and preliminary assessments. Assemble unsealed scan-manifest.json and findings.json using <plugin_dir>/examples/completed-scan/ and <plugin_dir>/schemas/ as shape references. Put candidate dispositions and pending work in scan.reviewState. Set scan.scope.validationMode to custom_pending and put each finding's matching review-state surface IDs in extensions.customValidationSurfaceIds. Every reported review-state surface must have a candidate. When source discovery finishes and a bound semantic draft tool is available, submit an accepted final source-discovery draft with complete: true, preserving the provisional findings, reviewState, threat model, and custom_pending validation mode. This marks source discovery finished; it does not claim custom validation has occurred or seal the scan. Keep complete: false when requested source review remains unfinished. Verify both files exist, then return control to the SDK without invoking validation or attack-path skills, running application code, sealing files, generating a report, or calling a scan completion tool or helper.\";\n\nasync function source(pluginRoot: string, name: keyof typeof SOURCES) {\n const text = (await readFile(join(pluginRoot, name), \"utf8\")).replaceAll(\n \"\\r\\n\",\n \"\\n\",\n );\n const digest = createHash(\"sha256\").update(text).digest(\"hex\");\n if (!SOURCES[name].includes(digest)) {\n throw new IncompleteScanError(\n `Custom validation is incompatible with the installed plugin workflow (${name}). Update the SDK and plugin together. Default validation was not started.`,\n );\n }\n return text;\n}\n\nfunction step(text: string, number: number): string {\n return text.match(new RegExp(`^${number}\\\\. (.+)$`, \"m\"))![1]!;\n}\n\nexport async function customDiscoveryPrompt(\n pluginRoot: string,\n skillName: string,\n): Promise<string> {\n let workflow: string;\n if (skillName === \"security-scan\") {\n const [skill, core] = await Promise.all([\n source(pluginRoot, \"skills/security-scan/SKILL.md\"),\n source(pluginRoot, \"references/core-scan.md\"),\n ]);\n const discovery = core\n .replace(\n /^7\\. .+$/m,\n \"7. Retain the combined source-backed candidates and their existing evidence. The SDK will run independent final validation in a separate turn.\",\n )\n .replace(\n /^Keep discovery, validation, and attack-path reasoning.+$/m,\n \"Keep source-evidence and counterevidence checks within discovery. Do not run an independent final validation pass or invoke separate phase skills.\",\n )\n .replace(\n \"reconcile their evidence and submit the result;\",\n \"reconcile their evidence and preserve provisional candidates through the SDK-owned discovery handoff;\",\n );\n workflow = [\n skill.slice(\n skill.indexOf(\"## Host And Setup\"),\n skill.indexOf(\"## Workflow\"),\n ),\n \"## Discovery workflow\",\n `1. ${step(skill, 1)}`,\n \"2. Perform the embedded core discovery workflow below. Do not reload the ordinary core-scan.md or top-level security-scan skill.\",\n `3. ${step(skill, 3).slice(step(skill, 3).indexOf(\"For an SDK-owned scan with a bound semantic draft tool,\"))}`,\n `4. ${HANDOFF}`,\n \"## Embedded core discovery workflow\",\n discovery,\n ].join(\"\\n\\n\");\n } else if (skillName === \"security-diff-scan\") {\n const skill = await source(\n pluginRoot,\n \"skills/security-diff-scan/SKILL.md\",\n );\n workflow = [\n skill.slice(skill.indexOf(\"## Setup\"), skill.indexOf(\"\\n4. \")),\n `4. ${HANDOFF} Use diff for scan.mode.`,\n ].join(\"\\n\\n\");\n } else {\n throw new IncompleteScanError(\n \"Custom validation is not supported for this scan workflow.\",\n );\n }\n return [\n \"Follow this SDK-owned discovery workflow, derived from the installed plugin. It replaces the ordinary top-level scan skill for this turn. The SDK owns the separate custom validation pass and all completion. <plugin_dir> is CODEX_SECURITY_PLUGIN_ROOT; other bare reference filenames are relative to its references directory.\",\n workflow.replaceAll(\"../../references/\", \"<plugin_dir>/references/\"),\n ].join(\"\\n\\n\");\n}\n\nexport async function customValidationConfig(\n config: JsonObject,\n pluginRoot: string,\n): Promise<JsonObject> {\n config = resolveCodexProfile(config);\n const manifest = JSON.parse(\n await readFile(join(pluginRoot, \".mcp.json\"), \"utf8\"),\n );\n const server = manifest.mcpServers[PLUGIN_NAME];\n const servers = (config[\"mcp_servers\"] ?? {}) as JsonObject;\n const configured = (servers[PLUGIN_NAME] ?? {}) as JsonObject;\n // The pinned Codex applies this per-invocation server entry ahead of the\n // installed plugin. Plugin-specific command-line policy overrides do not.\n return {\n ...config,\n mcp_servers: {\n ...servers,\n [PLUGIN_NAME]: {\n ...server,\n ...configured,\n cwd: resolve(\n pluginRoot,\n (configured[\"cwd\"] as string | undefined) ?? server.cwd ?? \".\",\n ),\n disabled_tools: [\n ...new Set([\n ...(server.disabled_tools ?? []),\n ...((configured[\"disabled_tools\"] ?? []) as string[]),\n ...DISABLED_TOOLS,\n ]),\n ],\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"custom-validation-prompt.js","sourceRoot":"","sources":["../src/custom-validation-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAmB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,4EAA4E;AAC5E,qEAAqE;AACrE,MAAM,OAAO,GAAG;IACd,yBAAyB,EAAE;QACzB,kEAAkE;QAClE,kEAAkE;QAClE,kEAAkE;QAClE,kEAAkE;QAClE,kEAAkE;KACnE;IACD,+BAA+B,EAAE;QAC/B,kEAAkE;QAClE,kEAAkE;KACnE;IACD,oCAAoC,EAAE;QACpC,kEAAkE;KACnE;CACF,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,oCAAoC;IACpC,uCAAuC;IACvC,gCAAgC;IAChC,8BAA8B;IAC9B,6CAA6C;IAC7C,+BAA+B;CAChC,CAAC;AAEF,MAAM,OAAO,GACX,0sCAA0sC,CAAC;AAE7sC,KAAK,UAAU,MAAM,CAAC,UAAkB,EAAE,IAA0B;IAClE,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CACtE,MAAM,EACN,IAAI,CACL,CAAC;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CA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AAC;IAChD,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAe,CAAC;IAC5D,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAe,CAAC;IAC9D,yEAAyE;IACzE,0EAA0E;IAC1E,OAAO;QACL,GAAG,MAAM;QACT,WAAW,EAAE;YACX,GAAG,OAAO;YACV,CAAC,WAAW,CAAC,EAAE;gBACb,GAAG,MAAM;gBACT,GAAG,UAAU;gBACb,GAAG,EAAE,OAAO,CACV,UAAU,EACT,UAAU,CAAC,KAAK,CAAwB,IAAI,MAAM,CAAC,GAAG,IAAI,GAAG,CAC/D;gBACD,cAAc,EAAE;oBACd,GAAG,IAAI,GAAG,CAAC;wBACT,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;wBAChC,GAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAc;wBACrD,GAAG,cAAc;qBAClB,CAAC;iBACH;aACF;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { resolveCodexProfile, type JsonObject } from \"./config.js\";\nimport { IncompleteScanError } from \"./errors.js\";\nimport { PLUGIN_NAME } from \"./runtime.js\";\n\n// Review this adapter when the bundled workflows change. Never silently run\n// the ordinary validation sequence with a custom-validation request.\nconst SOURCES = {\n \"references/core-scan.md\": [\n \"07abac7382a66338bfbe3def9a0e89e715a89561332c88ccb4477f97b6e84fe5\",\n \"0e301a70d9f20acbb797f5eafcac84c09dd0513991714812d5c4f7b1f64a4a89\",\n \"7690b6c854de07ff15984f6d2c25ddfa1f6ae65f65876cadf2f904054b4f0679\",\n \"83bafdc4089803e631eaaa86ec57167c7da3f51794514d0dcdb62c5afdced8a7\",\n \"848eb40d42b0bf9cf21748b9927d031b0461a4443f63e3954139f9801f41c3f6\",\n ],\n \"skills/security-scan/SKILL.md\": [\n \"b6a69658d48fff6979d6690e95d2096da236bb7e51b96ebb4f92102a9863d66c\",\n \"99cfcbbaa9d5b0450881ec752a116888b05b7fe21ea7af28fd22d088882dcd46\",\n ],\n \"skills/security-diff-scan/SKILL.md\": [\n \"09232fd5d96cfed2a5bdccd176c09b7e9ca53ebd7ac136d283bec884fde94b0d\",\n ],\n};\n\nconst DISABLED_TOOLS = [\n \"start_codex_security_standard_scan\",\n \"start_codex_security_prompt_only_scan\",\n \"start_codex_security_deep_scan\",\n \"complete_codex_security_scan\",\n \"record_codex_security_candidate_validations\",\n \"record_candidate_attack_paths\",\n];\n\nconst HANDOFF =\n \"Preserve every surviving source-backed candidate as a provisional finding, including its identity, source locations, evidence, counterevidence, and preliminary assessments. Assemble unsealed scan-manifest.json and findings.json using <plugin_dir>/examples/completed-scan/ and <plugin_dir>/schemas/ as shape references. Put candidate dispositions and pending work in scan.reviewState. Set scan.scope.validationMode to custom_pending and put each finding's matching review-state surface IDs in extensions.customValidationSurfaceIds. Every reported review-state surface must have a candidate. When source discovery finishes and a bound semantic draft tool is available, submit an accepted final source-discovery draft with complete: true, preserving the provisional findings, reviewState, threat model, and custom_pending validation mode. This marks source discovery finished; it does not claim custom validation has occurred or seal the scan. Keep complete: false when requested source review remains unfinished. Verify both files exist, then return control to the SDK without invoking validation or attack-path skills, running application code, sealing files, generating a report, or calling a scan completion tool or helper.\";\n\nasync function source(pluginRoot: string, name: keyof typeof SOURCES) {\n const text = (await readFile(join(pluginRoot, name), \"utf8\")).replaceAll(\n \"\\r\\n\",\n \"\\n\",\n );\n const digest = createHash(\"sha256\").update(text).digest(\"hex\");\n if (!SOURCES[name].includes(digest)) {\n throw new IncompleteScanError(\n `Custom validation is incompatible with the installed plugin workflow (${name}). Update the SDK and plugin together. Default validation was not started.`,\n );\n }\n return text;\n}\n\nfunction step(text: string, number: number): string {\n return text.match(new RegExp(`^${number}\\\\. (.+)$`, \"m\"))![1]!;\n}\n\nasync function legacyDiscoveryPrompt(pluginRoot: string) {\n const [skill, core] = await Promise.all([\n source(pluginRoot, \"skills/security-scan/SKILL.md\"),\n source(pluginRoot, \"references/core-scan.md\"),\n ]);\n const discovery = core\n .replace(\n /^7\\. .+$/m,\n \"7. Retain the combined source-backed candidates and their existing evidence. The SDK will run independent final validation in a separate turn.\",\n )\n .replace(\n /^Keep discovery, validation, and attack-path reasoning.+$/m,\n \"Keep source-evidence and counterevidence checks within discovery. Do not run an independent final validation pass or invoke separate phase skills.\",\n )\n .replace(\n \"reconcile their evidence and submit the result;\",\n \"reconcile their evidence and preserve provisional candidates through the SDK-owned discovery handoff;\",\n );\n return [\n skill.slice(\n skill.indexOf(\"## Host And Setup\"),\n skill.indexOf(\"## Workflow\"),\n ),\n \"## Discovery workflow\",\n `1. ${step(skill, 1)}`,\n \"2. Perform the embedded core discovery workflow below. Do not reload the ordinary core-scan.md or top-level security-scan skill.\",\n `3. ${step(skill, 3).slice(step(skill, 3).indexOf(\"For an SDK-owned scan with a bound semantic draft tool,\"))}`,\n `4. ${HANDOFF}`,\n \"## Embedded core discovery workflow\",\n discovery,\n ].join(\"\\n\\n\");\n}\n\nexport async function customDiscoveryPrompt(\n pluginRoot: string,\n skillName: string,\n standardHandoff: boolean,\n): Promise<string> {\n let workflow: string;\n if (skillName === \"security-scan\") {\n workflow = standardHandoff\n ? [\n \"Use <plugin_dir>/references/core-scan.md for source discovery. This caller supplies the validation handoff: the SDK runs independent final validation in a separate turn. Check source evidence and counterevidence now, but do not run the default validation pass.\",\n \"Keep any supplied investigation time allowance unchanged. Only for an explicit time request with no existing allowance, render <plugin_dir>/references/investigation-time-budget.md once before source review.\",\n HANDOFF,\n ].join(\"\\n\\n\")\n : await legacyDiscoveryPrompt(pluginRoot);\n } else if (skillName === \"security-diff-scan\") {\n const skill = await source(\n pluginRoot,\n \"skills/security-diff-scan/SKILL.md\",\n );\n workflow = [\n skill.slice(skill.indexOf(\"## Setup\"), skill.indexOf(\"\\n4. \")),\n `4. ${HANDOFF} Use diff for scan.mode.`,\n ].join(\"\\n\\n\");\n } else {\n throw new IncompleteScanError(\n \"Custom validation is not supported for this scan workflow.\",\n );\n }\n return [\n \"Follow this SDK-owned discovery workflow, derived from the installed plugin. It replaces the ordinary top-level scan skill for this turn. The SDK owns the separate custom validation pass and all completion. <plugin_dir> is CODEX_SECURITY_PLUGIN_ROOT; other bare reference filenames are relative to its references directory.\",\n workflow.replaceAll(\"../../references/\", \"<plugin_dir>/references/\"),\n ].join(\"\\n\\n\");\n}\n\nexport async function customValidationConfig(\n config: JsonObject,\n pluginRoot: string,\n): Promise<JsonObject> {\n config = resolveCodexProfile(config);\n const manifest = JSON.parse(\n await readFile(join(pluginRoot, \".mcp.json\"), \"utf8\"),\n );\n const server = manifest.mcpServers[PLUGIN_NAME];\n const servers = (config[\"mcp_servers\"] ?? {}) as JsonObject;\n const configured = (servers[PLUGIN_NAME] ?? {}) as JsonObject;\n // The pinned Codex applies this per-invocation server entry ahead of the\n // installed plugin. Plugin-specific command-line policy overrides do not.\n return {\n ...config,\n mcp_servers: {\n ...servers,\n [PLUGIN_NAME]: {\n ...server,\n ...configured,\n cwd: resolve(\n pluginRoot,\n (configured[\"cwd\"] as string | undefined) ?? server.cwd ?? \".\",\n ),\n disabled_tools: [\n ...new Set([\n ...(server.disabled_tools ?? []),\n ...((configured[\"disabled_tools\"] ?? []) as string[]),\n ...DISABLED_TOOLS,\n ]),\n ],\n },\n },\n };\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { Finding } from "../models.js";
2
2
  import type { FindingNeighborhood, FindingSearchScope } from "../finding-retrieval.js";
3
+ import type { SavedToolDiscovery } from "../saved-scan-bootstrap.js";
3
4
  import { runWorkbench } from "../runtime.js";
4
- import { type FindingEmbedder } from "../server/embeddings.js";
5
+ import { type FindingEmbedder, type EmbeddingUsageObserver } from "../server/embeddings.js";
5
6
  /** One vector space and the adapter that produces its embeddings. */
6
7
  export interface FindingEmbeddingBinding {
7
8
  readonly embedder: FindingEmbedder;
@@ -17,11 +18,12 @@ export declare class LocalDeduplication {
17
18
  private readonly repositoryPath;
18
19
  private readonly signal?;
19
20
  private readonly workbench;
21
+ private readonly nodeDiscovery?;
20
22
  private options?;
21
23
  private cacheKeys;
22
24
  private readonly space;
23
25
  private readonly embedding;
24
- constructor(environment: NodeJS.ProcessEnv, scope: FindingSearchScope, repositoryPath: string, signal?: AbortSignal | undefined, workbench?: typeof runWorkbench, embedding?: FindingEmbeddingBinding);
26
+ constructor(environment: NodeJS.ProcessEnv, scope: FindingSearchScope, repositoryPath: string, signal?: AbortSignal | undefined, workbench?: typeof runWorkbench, embedding?: FindingEmbeddingBinding, onEmbeddingUsage?: EmbeddingUsageObserver, nodeDiscovery?: SavedToolDiscovery | undefined);
25
27
  get inputDigest(): string;
26
28
  prepare(findings: readonly Finding[], repositoryId: string): Promise<void>;
27
29
  potentialDuplicates(findingId: string): Promise<FindingNeighborhood>;
@@ -1 +1 @@
1
- {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/deduplication/local.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAGL,YAAY,EAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAMjC,qEAAqE;AACrE,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,2FAA2F;IAC3F,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,2EAA2E;AAC3E,qBAAa,kBAAkB;IAO3B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAA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,OAAO,CAAC,IAAI,CAAC,CAElE;YAEa,OAAO;CA6DtB"}
@@ -14,16 +14,18 @@ export class LocalDeduplication {
14
14
  repositoryPath;
15
15
  signal;
16
16
  workbench;
17
+ nodeDiscovery;
17
18
  options;
18
19
  cacheKeys = {};
19
20
  space;
20
21
  embedding;
21
- constructor(environment, scope, repositoryPath, signal, workbench = runWorkbench, embedding) {
22
+ constructor(environment, scope, repositoryPath, signal, workbench = runWorkbench, embedding, onEmbeddingUsage, nodeDiscovery) {
22
23
  this.environment = environment;
23
24
  this.scope = scope;
24
25
  this.repositoryPath = repositoryPath;
25
26
  this.signal = signal;
26
27
  this.workbench = workbench;
28
+ this.nodeDiscovery = nodeDiscovery;
27
29
  const endpoint = environmentEntry(environment, "CODEX_SECURITY_EMBEDDINGS_URL") ||
28
30
  EMBEDDINGS_URL;
29
31
  this.embedding = embedding ?? {
@@ -33,7 +35,7 @@ export class LocalDeduplication {
33
35
  embedder: new OpenAiFindingEmbedder([
34
36
  environmentEntry(environment, "OPENAI_API_KEY"),
35
37
  environmentEntry(environment, "CODEX_API_KEY"),
36
- ].find((value) => value?.trim()), embeddingRequest, endpoint, signal),
38
+ ].find((value) => value?.trim()), embeddingRequest, endpoint, signal, onEmbeddingUsage),
37
39
  };
38
40
  // The digest keeps endpoint/namespace details out of persisted cache keys.
39
41
  this.space = workflowDigest({
@@ -88,6 +90,10 @@ export class LocalDeduplication {
88
90
  async command(payload) {
89
91
  this.signal?.throwIfAborted();
90
92
  this.options ??= (async () => {
93
+ // Bun finds Node on PATH. Native Node helpers use the running process executable.
94
+ if (process.versions["bun"] &&
95
+ this.nodeDiscovery?.allowPathLookup === false)
96
+ throw new CodexSecurityError("Could not establish the saved checkout boundary for Node.js discovery. Run local deduplication with Node.js.");
91
97
  const environment = workbenchEnvironment(this.environment);
92
98
  return {
93
99
  pluginRoot: await bundledPluginRoot(),
@@ -95,6 +101,7 @@ export class LocalDeduplication {
95
101
  environment,
96
102
  signal: this.signal,
97
103
  protectedRoot: [
104
+ ...(this.nodeDiscovery?.protectedRoots ?? []),
98
105
  this.repositoryPath,
99
106
  ...(await gitProtectionRoots(this.repositoryPath, this.signal)),
100
107
  ...(await gitProtectionRoots(process.cwd(), this.signal)),
@@ -1 +1 @@
1
- {"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/deduplication/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAM9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtD,8FAA8F;AAC9F,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAWhC,2EAA2E;AAC3E,MAAM,OAAO,kBAAkB;IAOV,WAAW;IACX,KAAK;IACL,cAAc;IACd,MAAM;IACN,SAAS;IAVpB,OAAO,CAAoD;IAC3D,SAAS,GAA2B,EAAE,CAAC;IAC9B,KAAK,CAAS;IACd,SAAS,CAA0B;IAEpD,YACmB,WAA8B,EAC9B,KAAyB,EACzB,cAAsB,EACtB,MAAoB,EACpB,SAAS,GAAwB,YAAY,EAC9D,SAAmC;2BALlB,WAAW;qBACX,KAAK;8BACL,cAAc;sBACd,MAAM;yBACN,SAAS;QAG1B,MAAM,QAAQ,GACZ,gBAAgB,CAAC,WAAW,EAAE,+BAA+B,CAAC;YAC9D,cAAc,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI;YAC5B,KAAK,EAAE,eAAe;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AG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;oBACtC,CAAC,CAAC,OAAO,GAAG,IAAI;oBAChB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACxC,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;oBAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YAC9B,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,SAAS,CAAC;gBAAE,MAAM,KAAK,CAAC;QAClE,CAAC;QACD,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["import { environmentEntry } from \"../auth.js\";\nimport { abortable, gitProtectionRoots } from \"../targets.js\";\nimport type { Finding } from \"../models.js\";\nimport type {\n FindingNeighborhood,\n FindingSearchScope,\n} from \"../finding-retrieval.js\";\nimport { CodexSecurityError } from \"../errors.js\";\nimport { workflowDigest } from \"../finding-workflow.js\";\nimport {\n bundledPluginRoot,\n workbenchEnvironment,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"../runtime.js\";\nimport {\n OpenAiFindingEmbedder,\n EMBEDDING_MODEL,\n EMBEDDING_DIMENSIONS,\n EMBEDDINGS_URL,\n type FindingEmbedder,\n} from \"../server/embeddings.js\";\nimport { retryDelay, waitForRetry } from \"./retry.js\";\n\n// Checkpoint bounded batches so a retry keeps completed work without one process per finding.\nconst EMBEDDING_BATCH_SIZE = 64;\n\n/** One vector space and the adapter that produces its embeddings. */\nexport interface FindingEmbeddingBinding {\n readonly embedder: FindingEmbedder;\n readonly model: string;\n readonly dimensions: number;\n /** Identifies the provider/vector space and preprocessing version; exclude credentials. */\n readonly cacheNamespace: string;\n}\n\n/** Direct workbench adapter. Importing it starts no HTTP or MCP server. */\nexport class LocalDeduplication {\n private options?: Promise<Omit<WorkbenchCommandOptions, \"python\">>;\n private cacheKeys: Record<string, string> = {};\n private readonly space: string;\n private readonly embedding: FindingEmbeddingBinding;\n\n constructor(\n private readonly environment: NodeJS.ProcessEnv,\n private readonly scope: FindingSearchScope,\n private readonly repositoryPath: string,\n private readonly signal?: AbortSignal,\n private readonly workbench: typeof runWorkbench = runWorkbench,\n embedding?: FindingEmbeddingBinding,\n ) {\n const endpoint =\n environmentEntry(environment, \"CODEX_SECURITY_EMBEDDINGS_URL\") ||\n EMBEDDINGS_URL;\n this.embedding = embedding ?? {\n model: EMBEDDING_MODEL,\n dimensions: EMBEDDING_DIMENSIONS,\n cacheNamespace: endpoint,\n embedder: new OpenAiFindingEmbedder(\n [\n environmentEntry(environment, \"OPENAI_API_KEY\"),\n environmentEntry(environment, \"CODEX_API_KEY\"),\n ].find((value) => value?.trim()),\n embeddingRequest,\n endpoint,\n signal,\n ),\n };\n // The digest keeps endpoint/namespace details out of persisted cache keys.\n this.space = workflowDigest({\n version: 1,\n model: this.embedding.model,\n dimensions: this.embedding.dimensions,\n namespace: this.embedding.cacheNamespace,\n });\n }\n\n get inputDigest(): string {\n return workflowDigest(this.cacheKeys);\n }\n\n async prepare(\n findings: readonly Finding[],\n repositoryId: string,\n ): Promise<void> {\n const result = await this.command({\n action: \"prepare\",\n findings,\n anchorRepositoryId: repositoryId,\n repositoryPath: this.repositoryPath,\n });\n this.cacheKeys = result[\"cacheKeys\"] as Record<string, string>;\n const findingsToEmbed = result[\"findingsToEmbed\"] as unknown as Finding[];\n for (\n let offset = 0;\n offset < findingsToEmbed.length;\n offset += EMBEDDING_BATCH_SIZE\n ) {\n this.signal?.throwIfAborted();\n const batch = findingsToEmbed.slice(\n offset,\n offset + EMBEDDING_BATCH_SIZE,\n );\n const embeddings = await abortable(() => {\n this.signal?.throwIfAborted();\n return this.embedding.embedder.embed(batch);\n }, this.signal);\n this.signal?.throwIfAborted();\n if (embeddings.length !== batch.length)\n throw new CodexSecurityError(\n \"Embedding provider returned an invalid number of vectors.\",\n );\n await this.command({\n action: \"embed\",\n entries: batch.map((finding, index) => ({\n findingId: finding.findingId,\n cacheKey: this.cacheKeys[finding.findingId],\n embedding: embeddings[index],\n })),\n });\n }\n }\n\n async potentialDuplicates(findingId: string): Promise<FindingNeighborhood> {\n return (await this.command({\n action: \"neighbors\",\n findingId,\n cacheKeys: this.cacheKeys,\n })) as unknown as FindingNeighborhood;\n }\n\n async storeDedupeGroups(groups: readonly string[][]): Promise<void> {\n await this.command({ action: \"commit\", groups, cacheKeys: this.cacheKeys });\n }\n\n private async command(payload: { action: string; [key: string]: unknown }) {\n this.signal?.throwIfAborted();\n this.options ??= (async () => {\n const environment = workbenchEnvironment(this.environment);\n return {\n pluginRoot: await bundledPluginRoot(),\n stateDirectory: environment.CODEX_SECURITY_STATE_DIR,\n environment,\n signal: this.signal,\n protectedRoot: [\n this.repositoryPath,\n ...(await gitProtectionRoots(this.repositoryPath, this.signal)),\n ...(await gitProtectionRoots(process.cwd(), this.signal)),\n ],\n failureMessage: \"Could not access local deduplication state\",\n };\n })();\n const result = await this.workbench(\n await this.options,\n [\n payload.action === \"neighbors\"\n ? \"find-potential-duplicates\"\n : payload.action === \"commit\"\n ? \"store-dedupe-groups\"\n : \"local-dedupe\",\n ],\n JSON.stringify({\n ...payload,\n scope: this.scope,\n space: this.space,\n model: this.embedding.model,\n dimensions: this.embedding.dimensions,\n ...(this.scope.allRepositories\n ? {}\n : { repositoryId: this.scope.repositoryId }),\n }),\n );\n this.signal?.throwIfAborted();\n const code = result[\"error\"];\n if (code !== undefined) {\n const message =\n code === \"finding_changed\"\n ? \"Findings changed during local deduplication. Retry with a new workflow ID if resuming.\"\n : code === \"target_mismatch\"\n ? \"The scan target does not match the approved local checkout. Use its original checkout or an explicitly configured findings service.\"\n : code === \"finding_not_indexed\"\n ? \"A local finding has no complete document. Reimport its scan before deduplicating.\"\n : `Local deduplication failed: ${String(code)}.`;\n throw new CodexSecurityError(message);\n }\n return result;\n }\n}\n\nasync function embeddingRequest(\n url: string,\n init: RequestInit,\n): Promise<Response> {\n for (let attempt = 1; ; attempt++) {\n init.signal?.throwIfAborted();\n let delay = retryDelay(attempt);\n try {\n const response = await fetch(url, init);\n if (\n attempt === 3 ||\n ![408, 429, 500, 502, 503, 504].includes(response.status)\n )\n return response;\n const retryAfter = response.headers.get(\"Retry-After\");\n if (retryAfter !== null) {\n const seconds = Number(retryAfter);\n const retryAt = Number.isFinite(seconds)\n ? seconds * 1000\n : Date.parse(retryAfter) - Date.now();\n if (Number.isFinite(retryAt)) delay = Math.max(delay, retryAt);\n }\n await response.body?.cancel().catch(() => undefined);\n } catch (error) {\n init.signal?.throwIfAborted();\n if (attempt === 3 || !(error instanceof TypeError)) throw error;\n }\n await waitForRetry(delay, init.signal ?? undefined);\n }\n}\n"]}
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/deduplication/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAM9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,cAAc,GAGf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;A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CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YAC9B,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,SAAS,CAAC;gBAAE,MAAM,KAAK,CAAC;QAClE,CAAC;QACD,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["import { environmentEntry } from \"../auth.js\";\nimport { abortable, gitProtectionRoots } from \"../targets.js\";\nimport type { Finding } from \"../models.js\";\nimport type {\n FindingNeighborhood,\n FindingSearchScope,\n} from \"../finding-retrieval.js\";\nimport { CodexSecurityError } from \"../errors.js\";\nimport type { SavedToolDiscovery } from \"../saved-scan-bootstrap.js\";\nimport { workflowDigest } from \"../finding-workflow.js\";\nimport {\n bundledPluginRoot,\n workbenchEnvironment,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"../runtime.js\";\nimport {\n OpenAiFindingEmbedder,\n EMBEDDING_MODEL,\n EMBEDDING_DIMENSIONS,\n EMBEDDINGS_URL,\n type FindingEmbedder,\n type EmbeddingUsageObserver,\n} from \"../server/embeddings.js\";\nimport { retryDelay, waitForRetry } from \"./retry.js\";\n\n// Checkpoint bounded batches so a retry keeps completed work without one process per finding.\nconst EMBEDDING_BATCH_SIZE = 64;\n\n/** One vector space and the adapter that produces its embeddings. */\nexport interface FindingEmbeddingBinding {\n readonly embedder: FindingEmbedder;\n readonly model: string;\n readonly dimensions: number;\n /** Identifies the provider/vector space and preprocessing version; exclude credentials. */\n readonly cacheNamespace: string;\n}\n\n/** Direct workbench adapter. Importing it starts no HTTP or MCP server. */\nexport class LocalDeduplication {\n private options?: Promise<Omit<WorkbenchCommandOptions, \"python\">>;\n private cacheKeys: Record<string, string> = {};\n private readonly space: string;\n private readonly embedding: FindingEmbeddingBinding;\n\n constructor(\n private readonly environment: NodeJS.ProcessEnv,\n private readonly scope: FindingSearchScope,\n private readonly repositoryPath: string,\n private readonly signal?: AbortSignal,\n private readonly workbench: typeof runWorkbench = runWorkbench,\n embedding?: FindingEmbeddingBinding,\n onEmbeddingUsage?: EmbeddingUsageObserver,\n private readonly nodeDiscovery?: SavedToolDiscovery,\n ) {\n const endpoint =\n environmentEntry(environment, \"CODEX_SECURITY_EMBEDDINGS_URL\") ||\n EMBEDDINGS_URL;\n this.embedding = embedding ?? {\n model: EMBEDDING_MODEL,\n dimensions: EMBEDDING_DIMENSIONS,\n cacheNamespace: endpoint,\n embedder: new OpenAiFindingEmbedder(\n [\n environmentEntry(environment, \"OPENAI_API_KEY\"),\n environmentEntry(environment, \"CODEX_API_KEY\"),\n ].find((value) => value?.trim()),\n embeddingRequest,\n endpoint,\n signal,\n onEmbeddingUsage,\n ),\n };\n // The digest keeps endpoint/namespace details out of persisted cache keys.\n this.space = workflowDigest({\n version: 1,\n model: this.embedding.model,\n dimensions: this.embedding.dimensions,\n namespace: this.embedding.cacheNamespace,\n });\n }\n\n get inputDigest(): string {\n return workflowDigest(this.cacheKeys);\n }\n\n async prepare(\n findings: readonly Finding[],\n repositoryId: string,\n ): Promise<void> {\n const result = await this.command({\n action: \"prepare\",\n findings,\n anchorRepositoryId: repositoryId,\n repositoryPath: this.repositoryPath,\n });\n this.cacheKeys = result[\"cacheKeys\"] as Record<string, string>;\n const findingsToEmbed = result[\"findingsToEmbed\"] as unknown as Finding[];\n for (\n let offset = 0;\n offset < findingsToEmbed.length;\n offset += EMBEDDING_BATCH_SIZE\n ) {\n this.signal?.throwIfAborted();\n const batch = findingsToEmbed.slice(\n offset,\n offset + EMBEDDING_BATCH_SIZE,\n );\n const embeddings = await abortable(() => {\n this.signal?.throwIfAborted();\n return this.embedding.embedder.embed(batch);\n }, this.signal);\n this.signal?.throwIfAborted();\n if (embeddings.length !== batch.length)\n throw new CodexSecurityError(\n \"Embedding provider returned an invalid number of vectors.\",\n );\n await this.command({\n action: \"embed\",\n entries: batch.map((finding, index) => ({\n findingId: finding.findingId,\n cacheKey: this.cacheKeys[finding.findingId],\n embedding: embeddings[index],\n })),\n });\n }\n }\n\n async potentialDuplicates(findingId: string): Promise<FindingNeighborhood> {\n return (await this.command({\n action: \"neighbors\",\n findingId,\n cacheKeys: this.cacheKeys,\n })) as unknown as FindingNeighborhood;\n }\n\n async storeDedupeGroups(groups: readonly string[][]): Promise<void> {\n await this.command({ action: \"commit\", groups, cacheKeys: this.cacheKeys });\n }\n\n private async command(payload: { action: string; [key: string]: unknown }) {\n this.signal?.throwIfAborted();\n this.options ??= (async () => {\n // Bun finds Node on PATH. Native Node helpers use the running process executable.\n if (\n process.versions[\"bun\"] &&\n this.nodeDiscovery?.allowPathLookup === false\n )\n throw new CodexSecurityError(\n \"Could not establish the saved checkout boundary for Node.js discovery. Run local deduplication with Node.js.\",\n );\n const environment = workbenchEnvironment(this.environment);\n return {\n pluginRoot: await bundledPluginRoot(),\n stateDirectory: environment.CODEX_SECURITY_STATE_DIR,\n environment,\n signal: this.signal,\n protectedRoot: [\n ...(this.nodeDiscovery?.protectedRoots ?? []),\n this.repositoryPath,\n ...(await gitProtectionRoots(this.repositoryPath, this.signal)),\n ...(await gitProtectionRoots(process.cwd(), this.signal)),\n ],\n failureMessage: \"Could not access local deduplication state\",\n };\n })();\n const result = await this.workbench(\n await this.options,\n [\n payload.action === \"neighbors\"\n ? \"find-potential-duplicates\"\n : payload.action === \"commit\"\n ? \"store-dedupe-groups\"\n : \"local-dedupe\",\n ],\n JSON.stringify({\n ...payload,\n scope: this.scope,\n space: this.space,\n model: this.embedding.model,\n dimensions: this.embedding.dimensions,\n ...(this.scope.allRepositories\n ? {}\n : { repositoryId: this.scope.repositoryId }),\n }),\n );\n this.signal?.throwIfAborted();\n const code = result[\"error\"];\n if (code !== undefined) {\n const message =\n code === \"finding_changed\"\n ? \"Findings changed during local deduplication. Retry with a new workflow ID if resuming.\"\n : code === \"target_mismatch\"\n ? \"The scan target does not match the approved local checkout. Use its original checkout or an explicitly configured findings service.\"\n : code === \"finding_not_indexed\"\n ? \"A local finding has no complete document. Reimport its scan before deduplicating.\"\n : `Local deduplication failed: ${String(code)}.`;\n throw new CodexSecurityError(message);\n }\n return result;\n }\n}\n\nasync function embeddingRequest(\n url: string,\n init: RequestInit,\n): Promise<Response> {\n for (let attempt = 1; ; attempt++) {\n init.signal?.throwIfAborted();\n let delay = retryDelay(attempt);\n try {\n const response = await fetch(url, init);\n if (\n attempt === 3 ||\n ![408, 429, 500, 502, 503, 504].includes(response.status)\n )\n return response;\n const retryAfter = response.headers.get(\"Retry-After\");\n if (retryAfter !== null) {\n const seconds = Number(retryAfter);\n const retryAt = Number.isFinite(seconds)\n ? seconds * 1000\n : Date.parse(retryAfter) - Date.now();\n if (Number.isFinite(retryAt)) delay = Math.max(delay, retryAt);\n }\n await response.body?.cancel().catch(() => undefined);\n } catch (error) {\n init.signal?.throwIfAborted();\n if (attempt === 3 || !(error instanceof TypeError)) throw error;\n }\n await waitForRetry(delay, init.signal ?? undefined);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../../src/deduplication/refusal.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAeT"}
1
+ {"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../../src/deduplication/refusal.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CA2CT"}
@@ -3,14 +3,35 @@ export function isReviewRefusal(message, codexErrorInfo) {
3
3
  if (codexErrorInfo === "cyberPolicy" ||
4
4
  codexErrorInfo === "misalignmentPolicyViolation")
5
5
  return true;
6
+ // Structured transport failures take precedence over fallback refusal wording.
7
+ if (codexErrorInfo !== null &&
8
+ typeof codexErrorInfo === "object" &&
9
+ [
10
+ "httpConnectionFailed",
11
+ "responseStreamConnectionFailed",
12
+ "responseStreamDisconnected",
13
+ "responseTooManyFailedAttempts",
14
+ ].some((variant) => Object.hasOwn(codexErrorInfo, variant)))
15
+ return false;
16
+ const text = message.trim();
17
+ const policyRefusal = /\b(?:cybersecurity|cyber|content|safety)[ _-]*policy\s*:\s*(?:(?:this|the|your)\s+)?(?:request|review)\s+(?:(?:is|was|has been)\s+)?(?:refused|blocked)\b([\s\S]*)$/iu.exec(text);
18
+ if (policyRefusal) {
19
+ // The explicit refusal predicate decides; its explanation has no controlled vocabulary.
20
+ // A leading service-outage cause still describes an operational failure.
21
+ return !/^\s*(?:(?:(?:because|as|due to)\s+|[.!:]\s*)(?:the\s+)?(?:upstream\s+)?service\s+(?:is\s+)?(?:unavailable|unavailability|timed? out|timeout)\b|by\s+upstream\s+with\s+[45]\d{2}\b|(?:because|as)\s+(?:the\s+)?upstream(?:\s+service)?\s+returned\s+(?:HTTP\s+)?[45]\d{2}\b)/iu.test(policyRefusal[1] ?? "");
22
+ }
6
23
  return [
7
24
  /\bflagged for possible cybersecurity risk\b/iu,
8
25
  /\bflagged for potentially high-risk cyber activity\b/iu,
9
26
  /\bcyber[_\s-]?policy\b/iu,
10
- /\b(?:cybersecurity|cyber|content|safety)[ _-]*policy[ _-]*(?:violation|refusal|refused)\b/iu,
11
- /\b(?:refusal|refused)\b[^\n]*\b(?:cybersecurity|cyber|safety policy)\b/iu,
12
- /\b(?:cybersecurity|cyber|safety policy)\b[^\n]*\b(?:refusal|refused)\b/iu,
13
- /^(?:I(?:['’]m| am) sorry[,.:]?\s*(?:but\s+)?|Sorry[,.:]?\s*)?I(?:\s+(?:cannot|can['’]t|won['’]t|am unable to)|['’]m unable to)\s+(?:help|assist|comply)\b/iu,
14
- ].some((pattern) => pattern.test(message.trim()));
27
+ /\b(?:cybersecurity|cyber)[ _-]*policy[ _-]*(?:violation|refusal|refused)\b/iu,
28
+ /^(?:content|safety) policy (?:violation|refusal)[.!]?$/iu,
29
+ /(?:^(?:refusal|refused)|\b(?:request|review)\s+(?:refusal|(?:(?:is|was|has been)\s+)?(?:refused|blocked)))\s+(?:under|by|due to|because of|because (?:it|this request) violates|for violating|in accordance with)\s+(?:(?:the|a)\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy\b/iu,
30
+ /^(?:(?:this|the|your)\s+)?(?:request|review)(?:\s+(?:is|was|has been))?\s+(?:refusal|refused|blocked)\s*:\s*(?:(?:the|a)\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy(?:[.!](?:\s+(?:I can offer|Please ask)\b[^\n]*)?)?$/iu,
31
+ /\b(?:cybersecurity|cyber|content|safety)[ _-]*policy\s+requires\s+(?:a\s+)?refusal\s+of\s+(?:(?:this|the|your)\s+)?(?:request|review)\b/iu,
32
+ /^(?:cybersecurity|cyber|content|safety)[ _-]*policy\s*:\s*(?:(?:(?:this|the|your)\s+)?(?:request|review)\s+)?(?:(?:is|was|has been)\s+)?(?:violation|refusal|refused|blocked)(?:[.!](?:\s+(?:I can offer|Please ask)\b[^\n]*)?)?$/iu,
33
+ /\bunder\s+(?:(?:the|a)\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy[, :]\s*(?:this|the|your) request (?:is|was|has been) (?:refused|blocked)\b/iu,
34
+ /^(?:I(?:['’]m| am) sorry[,.:]?\s*(?:but\s+)?|Sorry[,.:]?\s*)?I(?:\s+(?:cannot|can['’]t|won['’]t|am (?:unable|not able) to)|['’]m (?:unable|not able) to)\s+(?:help|assist|comply)\b/iu,
35
+ ].some((pattern) => pattern.test(text));
15
36
  }
16
37
  //# sourceMappingURL=refusal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"refusal.js","sourceRoot":"","sources":["../../src/deduplication/refusal.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,cAAwB;IAExB,IACE,cAAc,KAAK,aAAa;QAChC,cAAc,KAAK,6BAA6B;QAEhD,OAAO,IAAI,CAAC;IACd,OAAO;QACL,+CAA+C;QAC/C,wDAAwD;QACxD,0BAA0B;QAC1B,6FAA6F;QAC7F,0EAA0E;QAC1E,0EAA0E;QAC1E,6JAA6J;KAC9J,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/** Recognize policy blocks and explicit refusal responses, not ordinary review failures. */\nexport function isReviewRefusal(\n message: string,\n codexErrorInfo?: unknown,\n): boolean {\n if (\n codexErrorInfo === \"cyberPolicy\" ||\n codexErrorInfo === \"misalignmentPolicyViolation\"\n )\n return true;\n return [\n /\\bflagged for possible cybersecurity risk\\b/iu,\n /\\bflagged for potentially high-risk cyber activity\\b/iu,\n /\\bcyber[_\\s-]?policy\\b/iu,\n /\\b(?:cybersecurity|cyber|content|safety)[ _-]*policy[ _-]*(?:violation|refusal|refused)\\b/iu,\n /\\b(?:refusal|refused)\\b[^\\n]*\\b(?:cybersecurity|cyber|safety policy)\\b/iu,\n /\\b(?:cybersecurity|cyber|safety policy)\\b[^\\n]*\\b(?:refusal|refused)\\b/iu,\n /^(?:I(?:['’]m| am) sorry[,.:]?\\s*(?:but\\s+)?|Sorry[,.:]?\\s*)?I(?:\\s+(?:cannot|can['’]t|won['’]t|am unable to)|['’]m unable to)\\s+(?:help|assist|comply)\\b/iu,\n ].some((pattern) => pattern.test(message.trim()));\n}\n"]}
1
+ {"version":3,"file":"refusal.js","sourceRoot":"","sources":["../../src/deduplication/refusal.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,cAAwB;IAExB,IACE,cAAc,KAAK,aAAa;QAChC,cAAc,KAAK,6BAA6B;QAEhD,OAAO,IAAI,CAAC;IACd,+EAA+E;IAC/E,IACE,cAAc,KAAK,IAAI;QACvB,OAAO,cAAc,KAAK,QAAQ;QAClC;YACE,sBAAsB;YACtB,gCAAgC;YAChC,4BAA4B;YAC5B,+BAA+B;SAChC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAE3D,OAAO,KAAK,CAAC;IACf,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,aAAa,GACjB,uKAAuK,CAAC,IAAI,CAC1K,IAAI,CACL,CAAC;IACJ,IAAI,aAAa,EAAE,CAAC;QAClB,wFAAwF;QACxF,yEAAyE;QACzE,OAAO,CAAC,+QAA+Q,CAAC,IAAI,CAC1R,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CACvB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,+CAA+C;QAC/C,wDAAwD;QACxD,0BAA0B;QAC1B,8EAA8E;QAC9E,0DAA0D;QAC1D,6RAA6R;QAC7R,uOAAuO;QACvO,2IAA2I;QAC3I,qOAAqO;QACrO,4JAA4J;QAC5J,uLAAuL;KACxL,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/** Recognize policy blocks and explicit refusal responses, not ordinary review failures. */\nexport function isReviewRefusal(\n message: string,\n codexErrorInfo?: unknown,\n): boolean {\n if (\n codexErrorInfo === \"cyberPolicy\" ||\n codexErrorInfo === \"misalignmentPolicyViolation\"\n )\n return true;\n // Structured transport failures take precedence over fallback refusal wording.\n if (\n codexErrorInfo !== null &&\n typeof codexErrorInfo === \"object\" &&\n [\n \"httpConnectionFailed\",\n \"responseStreamConnectionFailed\",\n \"responseStreamDisconnected\",\n \"responseTooManyFailedAttempts\",\n ].some((variant) => Object.hasOwn(codexErrorInfo, variant))\n )\n return false;\n const text = message.trim();\n const policyRefusal =\n /\\b(?:cybersecurity|cyber|content|safety)[ _-]*policy\\s*:\\s*(?:(?:this|the|your)\\s+)?(?:request|review)\\s+(?:(?:is|was|has been)\\s+)?(?:refused|blocked)\\b([\\s\\S]*)$/iu.exec(\n text,\n );\n if (policyRefusal) {\n // The explicit refusal predicate decides; its explanation has no controlled vocabulary.\n // A leading service-outage cause still describes an operational failure.\n return !/^\\s*(?:(?:(?:because|as|due to)\\s+|[.!:]\\s*)(?:the\\s+)?(?:upstream\\s+)?service\\s+(?:is\\s+)?(?:unavailable|unavailability|timed? out|timeout)\\b|by\\s+upstream\\s+with\\s+[45]\\d{2}\\b|(?:because|as)\\s+(?:the\\s+)?upstream(?:\\s+service)?\\s+returned\\s+(?:HTTP\\s+)?[45]\\d{2}\\b)/iu.test(\n policyRefusal[1] ?? \"\",\n );\n }\n return [\n /\\bflagged for possible cybersecurity risk\\b/iu,\n /\\bflagged for potentially high-risk cyber activity\\b/iu,\n /\\bcyber[_\\s-]?policy\\b/iu,\n /\\b(?:cybersecurity|cyber)[ _-]*policy[ _-]*(?:violation|refusal|refused)\\b/iu,\n /^(?:content|safety) policy (?:violation|refusal)[.!]?$/iu,\n /(?:^(?:refusal|refused)|\\b(?:request|review)\\s+(?:refusal|(?:(?:is|was|has been)\\s+)?(?:refused|blocked)))\\s+(?:under|by|due to|because of|because (?:it|this request) violates|for violating|in accordance with)\\s+(?:(?:the|a)\\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy\\b/iu,\n /^(?:(?:this|the|your)\\s+)?(?:request|review)(?:\\s+(?:is|was|has been))?\\s+(?:refusal|refused|blocked)\\s*:\\s*(?:(?:the|a)\\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy(?:[.!](?:\\s+(?:I can offer|Please ask)\\b[^\\n]*)?)?$/iu,\n /\\b(?:cybersecurity|cyber|content|safety)[ _-]*policy\\s+requires\\s+(?:a\\s+)?refusal\\s+of\\s+(?:(?:this|the|your)\\s+)?(?:request|review)\\b/iu,\n /^(?:cybersecurity|cyber|content|safety)[ _-]*policy\\s*:\\s*(?:(?:(?:this|the|your)\\s+)?(?:request|review)\\s+)?(?:(?:is|was|has been)\\s+)?(?:violation|refusal|refused|blocked)(?:[.!](?:\\s+(?:I can offer|Please ask)\\b[^\\n]*)?)?$/iu,\n /\\bunder\\s+(?:(?:the|a)\\s+)?(?:cybersecurity|cyber|content|safety)[ _-]*policy[, :]\\s*(?:this|the|your) request (?:is|was|has been) (?:refused|blocked)\\b/iu,\n /^(?:I(?:['’]m| am) sorry[,.:]?\\s*(?:but\\s+)?|Sorry[,.:]?\\s*)?I(?:\\s+(?:cannot|can['’]t|won['’]t|am (?:unable|not able) to)|['’]m (?:unable|not able) to)\\s+(?:help|assist|comply)\\b/iu,\n ].some((pattern) => pattern.test(text));\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { type DeduplicationResult } from "./deduplication.js";
2
2
  import { type FindingEmbeddingBinding } from "./local.js";
3
+ import type { EmbeddingUsageObserver } from "../server/embeddings.js";
3
4
  import { type DeduplicationDiagnosticObserver } from "./diagnostics.js";
4
5
  export interface DeduplicateScanOptions {
5
6
  /** Resume the named findings workflow; remote mode includes custom publication. */
@@ -14,6 +15,8 @@ export interface DeduplicateScanOptions {
14
15
  concurrency?: number;
15
16
  /** Best-effort progress and native review diagnostics; observer failures are ignored. */
16
17
  onDiagnostic?: DeduplicationDiagnosticObserver;
18
+ /** Built-in local embedding batch usage; excluded from scan model-token totals. */
19
+ onEmbeddingUsage?: EmbeddingUsageObserver;
17
20
  signal?: AbortSignal;
18
21
  }
19
22
  export interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions {
@@ -24,6 +27,8 @@ export interface DeduplicateScanDirectoryOptions extends DeduplicateScanOptions
24
27
  }
25
28
  export interface DeduplicateScanResult extends DeduplicationResult {
26
29
  scanId: string;
30
+ /** One finding from this scan for each entry in uniqueFindingIds, in the same order. */
31
+ scanRepresentativeFindingIds: string[];
27
32
  }
28
33
  /** Review a saved scan against embedding candidates and persist accepted duplicate groups. */
29
34
  export declare function deduplicateScan(scanId: string, options: DeduplicateScanOptions): Promise<DeduplicateScanResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/deduplication/scan.ts"],"names":[],"mappings":"AAkBA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAuB5B,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAQ9E,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wFAAwF;IACxF,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC,iFAAiF;IACjF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,YAAY,CAAC,EAAE,+BAA+B,CAAC;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,+BAAgC,SAAQ,sBAAsB;IAC7E,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,8FAA8F;AAC9F,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAEhC;AAED,qFAAqF;AACrF,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,qBAAqB,CAAC,CAEhC"}
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